@hasna/switcher 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -6
- package/dist/cli/index.js +2034 -1169
- package/dist/credentials.d.ts +96 -7
- package/dist/direct-launch.d.ts +2 -1
- package/dist/domain.d.ts +63 -1
- package/dist/generated/api.d.ts +32 -0
- package/dist/index.js +11 -1
- package/dist/launcher.d.ts +1 -0
- package/dist/mcp/index.js +106 -4
- package/dist/opencode.d.ts +30 -0
- package/dist/presets.d.ts +8 -0
- package/dist/sdk.d.ts +36 -0
- package/dist/sdk.js +11 -1
- package/dist/serve/index.js +106 -4
- package/openapi.json +93 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -168,7 +168,8 @@ launching the terminal CLI. `detectClaudeDesktopApp()` is available in the SDK.
|
|
|
168
168
|
The provider must implement Anthropic Messages, including streaming and tool
|
|
169
169
|
calling for the chosen model. DeepSeek and compatible gateway presets select
|
|
170
170
|
the Messages endpoint automatically. Saved provider IDs retain their explicit
|
|
171
|
-
protocol.
|
|
171
|
+
protocol. OpenCode Zen and Go additionally use the Claude translation adapter
|
|
172
|
+
described below for models served on another native wire.
|
|
172
173
|
A configured provider works in both desktop apps when it offers both required
|
|
173
174
|
APIs; a preset's existence is not proof that every model supports every feature.
|
|
174
175
|
|
|
@@ -229,7 +230,60 @@ With no Switcher API credential configured, the CLI and `switcher-mcp` exit non-
|
|
|
229
230
|
|
|
230
231
|
Remote API configuration is resolved through Contracts, including canonical credential stores and the default gateway URL. Invalid, unavailable or unauthorized remote services fail without opening local SQLite.
|
|
231
232
|
|
|
232
|
-
The registry contains DeepSeek, OpenRouter, Anthropic, OpenAI, xAI, Ollama, LM Studio, Groq, Cerebras, Mistral, Together AI, Fireworks, Moonshot/Kimi, DashScope, Z.AI, MiniMax, SiliconFlow, and generic protocol entries. `switcher providers presets ID` exposes documented routes, aliases and limitations; this is not a claim that every combination has passed live tests. Remaining adapters and acceptance gates are tracked in [TODOS.md](TODOS.md).
|
|
233
|
+
The registry contains DeepSeek, OpenCode Zen, OpenCode Go, OpenRouter, Anthropic, OpenAI, xAI, Ollama, LM Studio, Groq, Cerebras, Mistral, Together AI, Fireworks, Moonshot/Kimi, DashScope, Z.AI, MiniMax, SiliconFlow, and generic protocol entries. `switcher providers presets ID` exposes documented routes, aliases and limitations; this is not a claim that every combination has passed live tests. Remaining adapters and acceptance gates are tracked in [TODOS.md](TODOS.md).
|
|
234
|
+
|
|
235
|
+
### OpenCode and OpenRouter providers
|
|
236
|
+
|
|
237
|
+
From 0.2.1, `opencode` selects OpenCode Zen and `opencode-go` selects its Go
|
|
238
|
+
subscription. Both discover their complete live `/models` catalogs. Supply
|
|
239
|
+
`OPENCODE_API_KEY` through environment injection or bind each preset to your
|
|
240
|
+
existing vault/keychain reference. Go requires an active Go subscription.
|
|
241
|
+
`SWITCHER_PROVIDER_OPENCODE` and `SWITCHER_PROVIDER_OPENCODE_GO` can bind
|
|
242
|
+
different accounts explicitly. OpenRouter uses `OPENROUTER_API_KEY` or its
|
|
243
|
+
`SWITCHER_PROVIDER_OPENROUTER` binding.
|
|
244
|
+
|
|
245
|
+
```sh
|
|
246
|
+
switcher models opencode --limit 1000
|
|
247
|
+
switcher models opencode-go --limit 1000
|
|
248
|
+
switcher models openrouter --limit 1000
|
|
249
|
+
switcher launch claude --provider opencode --model big-pickle
|
|
250
|
+
switcher launch claude --provider opencode-go --model kimi-k3
|
|
251
|
+
switcher launch claude --provider openrouter --model deepseek/deepseek-v4-flash
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Use the exact API model ID from the catalog. OpenCode IDs are unprefixed;
|
|
255
|
+
OpenRouter IDs include their provider prefix. `--limit` controls the displayed
|
|
256
|
+
page, and `--offset` accesses subsequent pages. The stored catalog includes all
|
|
257
|
+
pages and modalities; coding selections exclude models explicitly lacking text
|
|
258
|
+
output or tools. OpenRouter's declared reasoning efforts are retained.
|
|
259
|
+
|
|
260
|
+
Claude Code and `claude-desktop` speak Messages to Switcher. For OpenCode,
|
|
261
|
+
Switcher forwards Claude/Qwen Messages requests natively, uses Messages for
|
|
262
|
+
Go's MiniMax models, and translates the other documented model families to
|
|
263
|
+
Chat Completions, Responses, or Gemini generateContent. Translation preserves
|
|
264
|
+
streaming text, tool arguments/results, images, reasoning text, and token usage.
|
|
265
|
+
It keeps Gemini tool signatures within the current launch. Restarting a launch
|
|
266
|
+
does not restore that transient signature cache, so start a fresh conversation
|
|
267
|
+
for Gemini tool workflows. Token counting on translated routes and provider
|
|
268
|
+
server tools are rejected explicitly; model capabilities and entitlements still
|
|
269
|
+
apply. Other harnesses use the preset's selected native protocol and require a
|
|
270
|
+
model compatible with it. OpenRouter provides its own Messages translation.
|
|
271
|
+
|
|
272
|
+
OpenCode inference receives Switcher's own user agent and a stable conversation
|
|
273
|
+
identifier. Native session headers are preserved from an explicit allowlist;
|
|
274
|
+
Claude's session metadata is used when available, with a per-launch fallback.
|
|
275
|
+
Credential and session handling is scoped to the exact OpenCode service URLs.
|
|
276
|
+
|
|
277
|
+
`bun run test:native-claude-providers` uses installed Claude Code with controlled
|
|
278
|
+
upstream fixtures and verifies actual file reads through Chat Completions,
|
|
279
|
+
Responses, Gemini, Go Messages, and OpenRouter Messages. This is separate from
|
|
280
|
+
paid-provider acceptance. Development live checks discovered all three catalogs
|
|
281
|
+
and received answers from OpenCode's free Chat endpoint; the saved paid keys
|
|
282
|
+
were rejected and the free endpoint subsequently rate-limited native testing.
|
|
283
|
+
|
|
284
|
+
Sources: [OpenCode Zen](https://opencode.ai/docs/zen/),
|
|
285
|
+
[OpenCode Go](https://opencode.ai/docs/go/), and
|
|
286
|
+
[OpenRouter Claude Code integration](https://openrouter.ai/docs/cookbook/coding-agents/claude-code-integration).
|
|
233
287
|
|
|
234
288
|
## Canonical API configuration
|
|
235
289
|
|
|
@@ -243,16 +297,41 @@ Configured but missing, unsafe, conflicting or inaccessible remote credentials f
|
|
|
243
297
|
|
|
244
298
|
## Credential bindings
|
|
245
299
|
|
|
246
|
-
Bind an existing vault key once, then launch without an external wrapper. New bindings
|
|
300
|
+
Bind an existing vault key once, then launch without an external wrapper. New bindings resolve the Secrets operator key and API URL through `@hasna/contracts/client`. A configured Keychain item or canonical `~/.hasna/secrets/config/credentials` supplies the operator without shell exports. The default Secrets API URL is `https://api.hasna.com/secrets`; `--vault-url` can select a custom vault but must agree with any configured Secrets authority.
|
|
301
|
+
|
|
302
|
+
Real launches now preflight the local inference credential before catalog refresh and before an interactive model picker. An existing environment credential is preserved without creating a binding. An existing binding remains authoritative, including its exact Secrets operator account and allowed provider origins; a locked source, an unauthorized destination, or rejected provider credential is terminal and never falls through to another account.
|
|
303
|
+
|
|
304
|
+
When a provider credential is missing in an interactive terminal, Switcher uses the trusted `secrets` executable on `PATH` to search metadata only. It displays the selected Secrets account/source and matching vault key references, asks which reference to bind, saves that reference through the existing immutable binding store, resolves the value through the authenticated loopback delivery path, and performs a bounded, non-inference provider authentication check before continuing the original launch. OpenRouter uses its authenticated `GET /api/v1/key` metadata endpoint; its public model catalog is never treated as proof that a key works. Custom providers may declare a relative `credentialCheck` (`GET` or `HEAD`) in provider JSON. Catalog configuration alone is never inferred to validate a credential because a catalog may be public or ignore invalid authorization.
|
|
305
|
+
|
|
306
|
+
If no matching key exists, Secrets is unavailable, the selected Keychain/vault cannot be read, or the provider rejects the credential, the structured error names the exact recovery without changing accounts. The first-run binding pins the exact Contracts source and vault authority that were displayed; if that Keychain account, environment tier, profile, or canonical file changes, later launches stop rather than selecting another account. First-run bindings also retain a requirement for a supported provider authentication check, so an unsupported check cannot be bypassed by retrying. Older explicit bindings remain compatible when no safe check is declared; adding `credentialCheck` upgrades them to authenticated preflight without changing their account or origins. Noninteractive launches never prompt and return `credential_setup_required` with explicit binding syntax or the provider environment reference. `--dry-run` preserves its planning contract: it does not search Secrets, create a binding, retrieve a provider credential, or perform provider authentication merely to describe a launch plan. Public and credentialless catalogs may refresh. Authenticated catalogs are read from the saved Switcher snapshot; if none exists, the error names the explicit `switcher models PROVIDER --refresh` command that performs the credential-consuming refresh.
|
|
307
|
+
|
|
308
|
+
For stations that update global tools with Bun, give the vault binding a private, version-pinned npm installation. A later global Bun installation can reset the permissions of its `secrets` executable, including one already repaired, and break every provider using it. The private installation keeps that update path separate. This example uses Secrets `0.4.2`; choose an exact verified release and a **new, unused prefix** for each upgrade:
|
|
309
|
+
|
|
310
|
+
```sh
|
|
311
|
+
SWITCHER_VAULT_PREFIX="$HOME/.hasna/switcher/vault-runtimes/secrets-0.4.2-private"
|
|
312
|
+
(
|
|
313
|
+
set -e
|
|
314
|
+
umask 077
|
|
315
|
+
test ! -e "$SWITCHER_VAULT_PREFIX"
|
|
316
|
+
mkdir -p "$SWITCHER_VAULT_PREFIX"
|
|
317
|
+
npm install --prefix "$SWITCHER_VAULT_PREFIX" --save-exact \
|
|
318
|
+
--ignore-scripts --no-audit --no-fund --umask=077 @hasna/secrets@0.4.2
|
|
319
|
+
)
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Both the shell and npm umasks matter: a shell umask of `0002` can leave npm package directories group-writable, which the vault guard also rejects. `--ignore-scripts` prevents lifecycle scripts from running during this installation. Verify the installed package against its integrity-checked release archive before binding it, as described below. Do not run Bun installs inside this prefix. Preserve the previous runtime until the new binding passes a real provider launch.
|
|
323
|
+
|
|
324
|
+
To migrate an existing binding, record its locator with `credentials list`, then explicitly remove and recreate that same reference with the new `--vault-cli`. Preserve its vault key, URL, operator/account and authorized origins; only the executable path should change. Keep the original locator available to restore if verification fails.
|
|
247
325
|
|
|
248
326
|
```sh
|
|
249
327
|
switcher credentials bind deepseek \
|
|
250
|
-
--vault-key providers/deepseek/live/api_key
|
|
328
|
+
--vault-key providers/deepseek/live/api_key \
|
|
329
|
+
--vault-cli "$SWITCHER_VAULT_PREFIX/node_modules/@hasna/secrets/dist/index.js"
|
|
251
330
|
switcher credentials check deepseek
|
|
252
331
|
switcher launch claude --provider deepseek --model deepseek-v4-pro
|
|
253
332
|
```
|
|
254
333
|
|
|
255
|
-
`--vault-cli /absolute/path/to/secrets` selects a particular installation. Vault lookup uses `secrets exec` to inject the value into a short-lived receiver, which delivers it over an authenticated loopback connection. Values stay in process memory. The lookup has a 20-second deadline and owns a separate process group; it finishes before the native harness starts. Each lookup reads the vault again. Conflicting Secrets service URL configuration fails explicitly. Vault CLI bindings currently require POSIX; Windows callers can inject provider environment variables.
|
|
334
|
+
`--vault-cli /absolute/path/to/secrets` selects a particular installation; omitting it binds the current `secrets` on `PATH`, which may be replaced by a global tool update. Vault lookup uses `secrets exec` to inject the value into a short-lived receiver, which delivers it over an authenticated loopback connection. Values stay in process memory. The lookup has a 20-second deadline and owns a separate process group; it finishes before the native harness starts. Each lookup reads the vault again. Conflicting Secrets service URL configuration fails explicitly. Vault CLI bindings currently require POSIX; Windows callers can inject provider environment variables.
|
|
256
335
|
|
|
257
336
|
If launch reports `vault_exec_permissions`, verify the installed Secrets package against its trusted release artifact before repairing it. Bun 1.3.14's [bin-link installer](https://github.com/oven-sh/bun/blob/bun-v1.3.14/src/install/bin.zig#L731-L735) can change an executable member from mode `0755` to `0777`, including with `--ignore-scripts`. Changing the shell umask does not correct that installer behavior.
|
|
258
337
|
|
|
@@ -277,7 +356,7 @@ secrets exec providers/deepseek/live/api_key --as DEEPSEEK_API_KEY -- \
|
|
|
277
356
|
switcher launch claude --provider deepseek --model deepseek-v4-flash --dry-run
|
|
278
357
|
```
|
|
279
358
|
|
|
280
|
-
Authenticate that Secrets process through your existing secret manager or service environment. `--dry-run`
|
|
359
|
+
Authenticate that Secrets process through your existing secret manager or service environment. `--dry-run` refreshes public/credentialless catalogs, reuses saved authenticated catalog snapshots, creates provider/profile records as needed and returns a launch plan without starting the native harness or inference. It never retrieves a provider credential solely for planning. Every new process needs its own runtime injection. `credentials check` inspects configured bindings, not environment aliases. Keychain bindings are macOS-only; on Linux they fail with `keychain_unavailable` and recommend a vault binding or runtime environment. Native subscription/OAuth login is separate from Switcher's provider-key mode; Switcher does not import or reuse it.
|
|
281
360
|
|
|
282
361
|
## OpenCode 2 configuration
|
|
283
362
|
|