Skip to content

feat(deeplink): allow overriding OpenCode npm package via URL param#2187

Open
oaker-io wants to merge 1 commit into
farion1231:mainfrom
oaker-io:feature/opencode-npm-deeplink-param
Open

feat(deeplink): allow overriding OpenCode npm package via URL param#2187
oaker-io wants to merge 1 commit into
farion1231:mainfrom
oaker-io:feature/opencode-npm-deeplink-param

Conversation

@oaker-io
Copy link
Copy Markdown

Summary

  • Adds an npm parameter to the ccswitch:// provider deeplink so callers can pick which @ai-sdk/* package the OpenCode provider should use.
  • Fixes the case where a relay exposes both OpenAI-compatible and Gemini-native endpoints: today a Gemini import lands as @ai-sdk/openai-compatible, and the user has to open the provider config and hand-edit npm to @ai-sdk/google before chat works.
  • Default stays @ai-sdk/openai-compatible, so existing deeplinks are unaffected.

What changed

  • DeepLinkImportRequest gains npm: Option<String> (camelCase npm in the URL).
  • parse_deeplink_url reads npm from the query string for the provider resource.
  • merge_additive_config (OpenCode / OpenClaw JSON config pass-through) now carries npm from the Base64 config when the URL param is absent.
  • build_opencode_settings uses the override and falls back to @ai-sdk/openai-compatible.
  • Docs: all three locales of 5.3-deeplink.md get a new row for npm.

Context

Example deeplink from a relay that routes Gemini under /v1beta:

ccswitch://v1/import?resource=provider&app=opencode&name=Relay
  &endpoint=https%3A%2F%2Frelay.example.com%2Fv1beta
  &apiKey=sk-...
  &model=gemini-3-flash
  &npm=%40ai-sdk%2Fgoogle

Without this change the imported provider is usable for discovery but fails on the first chat because the openai-compatible SDK can't speak Gemini-native. With the change, one click lands a working config.

Tests

  • test_parse_opencode_deeplink_with_npm_param — URL param survives parsing.
  • test_build_opencode_provider_defaults_npm_when_absent — default unchanged.
  • test_build_opencode_provider_honors_npm_override — override wins.

All 24 deeplink::tests::* pass locally (cargo test deeplink). cargo fmt --check and cargo clippy -- -D warnings clean.

Test plan

  • cargo fmt --check passes
  • cargo clippy --manifest-path src-tauri/Cargo.toml -- -D warnings passes
  • cargo test --manifest-path src-tauri/Cargo.toml passes (24 deeplink tests + 2 integration tests)
  • Manual: trigger an OpenCode deeplink with npm=@ai-sdk/google and confirm the provider config in CC Switch shows the overridden package

🤖 Generated with Claude Code

OpenCode providers currently hard-wire `npm=@ai-sdk/openai-compatible`, which
breaks imports that need a provider-specific SDK — notably Gemini-native
routing, which requires `@ai-sdk/google` and can't be fixed post-import
without manual JSON editing.

- Add `npm: Option<String>` to `DeepLinkImportRequest` (URL param + Base64
  config pass-through via `merge_additive_config`).
- `build_opencode_settings` now honors the override and falls back to
  `@ai-sdk/openai-compatible` when absent.
- Covered by three new tests (parser, default fallback, explicit override).
- Documented in en / zh / ja manuals.

No behavior change for existing deeplinks that don't pass `npm`.
@farion1231
Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants