@hasna/switcher 0.1.7 → 0.1.8
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 +33 -4
- package/dist/cli/index.js +96 -24
- package/dist/domain.d.ts +4 -4
- package/dist/index.js +36 -6
- package/dist/mcp/index.js +34 -3
- package/dist/sdk.d.ts +131 -0
- package/dist/sdk.js +36 -6
- package/dist/serve/index.js +5 -4
- package/openapi.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -291,16 +291,45 @@ Claude Code with a non-Claude model is experimental and unsupported by Anthropic
|
|
|
291
291
|
|
|
292
292
|
For Claude Code using the official DeepSeek Messages endpoint, Switcher defaults `CLAUDE_CODE_AUTO_COMPACT_WINDOW` to `786432`, following [DeepSeek's integration guidance](https://api-docs.deepseek.com/quick_start/agent_integrations/claude_code/). An explicitly set environment value takes precedence. Recognized provider context-overflow errors become a sanitized `prompt is too long` error so the native client can compact or guide recovery; unrelated errors retain the sanitized upstream status. Existing launches must pick up the compaction setting or start a new launch to use this default.
|
|
293
293
|
|
|
294
|
-
|
|
294
|
+
DeepSeek officially released V4.1 Flash on 2026-09-10. Its API model ID is `deepseek-flash`, as documented in the [official release notes](https://api-docs.deepseek.com/updates/) and [API quick start](https://api-docs.deepseek.com/). New DeepSeek presets include that model with text/image input and tool support, and support Chat Completions, Anthropic Messages, and Responses (for Codex). Saved providers and profiles keep their existing model selections. Configure an existing provider explicitly to adopt the new model:
|
|
295
295
|
|
|
296
296
|
```sh
|
|
297
|
-
switcher models add
|
|
297
|
+
switcher models add deepseek-messages deepseek-flash --name "DeepSeek V4.1 Flash"
|
|
298
|
+
switcher launch claude --provider deepseek-messages --model deepseek-flash
|
|
299
|
+
# Or create the documented Responses preset and select the model directly:
|
|
300
|
+
switcher launch codex --provider deepseek --model deepseek-flash
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Configure a new model on any saved provider without editing the provider's JSON:
|
|
304
|
+
|
|
305
|
+
```sh
|
|
306
|
+
switcher models add my-provider vendor/new-model --name "New model"
|
|
307
|
+
switcher models add my-provider vendor/detailed-model --file model.json
|
|
308
|
+
switcher models config my-provider
|
|
309
|
+
switcher models list my-provider --refresh
|
|
310
|
+
switcher models update my-provider vendor/new-model --name "Preview" --expires-on 2027-01-01
|
|
311
|
+
switcher models remove my-provider vendor/new-model
|
|
298
312
|
switcher models my-provider --refresh
|
|
299
313
|
```
|
|
300
314
|
|
|
301
|
-
|
|
315
|
+
A model JSON object needs `id` and `name`; it can also carry `contextWindow`, `maxOutputTokens`, `inputModalities`, `outputModalities`, `supportedParameters`, `supportedGenerationMethods`, `available`, `description`, and `expiresOn`. The file ID must match the command. Unknown fields, raw credential fields, invalid dates and blank/control-character model IDs are rejected. `models update` replaces that model's saved metadata: omit an optional field from the replacement to clear it. `models config` reads only saved settings and makes no provider request. SDK clients expose `addModel`, `updateModel`, and `removeModel`; MCP exposes `models_add`, `models_update`, and `models_remove` with the same behavior.
|
|
316
|
+
|
|
317
|
+
For providers using discovery, configured models live in `additionalModels`; discovery still runs and its errors still block launch. Additions merge by ID and override only supplied remote metadata. Removing an addition reveals any upstream entry with the same ID. For manual catalogs, model commands edit `manualModels`. Edits use the provider's current version and fail on concurrent changes rather than overwriting them. Existing profiles are not silently repointed when a model is removed or replaced.
|
|
318
|
+
|
|
319
|
+
`--expires-on` is optional and accepts a real `YYYY-MM-DD` date, inclusive in UTC. Expired models remain visible with `expired: true` and `codingEligible: false`; new launches, policy roles, native picker catalogs and subsequent gateway requests reject them. Existing processes are not stopped. Expiry is operator metadata, not a guarantee of upstream availability.
|
|
320
|
+
|
|
321
|
+
Create an arbitrary provider with a starter model or a JSON array of model objects:
|
|
322
|
+
|
|
323
|
+
```sh
|
|
324
|
+
switcher providers add deployment --url https://inference.example/v1 --protocol openai-responses \
|
|
325
|
+
--credential-env SWITCHER_PROVIDER_DEPLOYMENT --catalog-format none --model team/deployment
|
|
326
|
+
switcher providers add catalog-provider --url https://inference.example/v1 --protocol openai-chat \
|
|
327
|
+
--credential-env SWITCHER_PROVIDER_CUSTOM --models-file models.json
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
`--catalog-format none` explicitly selects a manual catalog and avoids model discovery. Without it, starter models supplement discovery. Credential flags store reference names only; use the existing credential binding commands to configure their source.
|
|
302
331
|
|
|
303
|
-
For
|
|
332
|
+
For advanced provider settings, use `providers add ID --file provider.json` with `manualModels` when discovery is unavailable. Each model needs `id` and `name`; optional fields are `contextWindow`, `maxOutputTokens`, `inputModalities`, `outputModalities`, `supportedParameters`, and `available`. Use `catalogBaseUrl` and `modelsPath` for a separate discovery root/path; CLI equivalents are `--catalog-url` and `--models-path`. Use `catalogFormat: "ollama"` for `/api/tags`. Mistral presets select a capability-aware parser, including archived status. Together presets select its native bare-array parser. Fireworks requires `--catalog-account-id ID` or an explicit catalog URL and retains count evidence across its paginated account catalog. DashScope requires an explicit region/workspace `--catalog-url` with `--catalog-format dashscope`. Z.AI currently requires an explicit catalog or manual models because its documented API has no model-list contract. MiniMax defaults to its `.cn` Open Platform endpoints; use an explicit authority and credential reference for another product or region. A different authenticated catalog origin requires an explicit `catalogCredentialEnv`; a public catalog can declare `catalogAuthStyle: "none"`. Standard credential aliases are resolved only for the matching built-in provider origin. The default parser follows Anthropic-style `has_more/last_id` pagination and otherwise expects an OpenAI-style `data` array. HTTP redirects are rejected.
|
|
304
333
|
|
|
305
334
|
Grok uses a per-launch authenticated loopback bridge because its environment overlay cannot define providers. The bridge serves model metadata and forwards the selected protocol unchanged. It holds upstream credentials only in memory; Grok receives an ephemeral local token. The same bridge handles credentialless endpoints and OpenCode auth-header mismatches. Bridged requests are limited to 4 MiB and four minutes. Grok resumes retain the selected profile model. Use `-- --resume SESSION_ID -p PROMPT` for headless continuation, or omit the prompt and type after the interactive session loads. Interactive resume with an inline positional prompt is rejected because the native client can send it before applying the selected model. Grok 1.0.13 passed source and installed development CLI resume checks against a controlled Messages fixture and live DeepSeek Flash. OpenCode's provider identity stays stable across temporary bridge ports; `-- run --session SESSION_ID PROMPT` resumes with fresh launch settings. The installed beta-19157 passed two-process Messages resume checks against a controlled local upstream and live DeepSeek Flash, including a proof-file read and preserved history. Other provider/protocol and registry-release cells remain tracked separately in COMPATIBILITY.md.
|
|
306
335
|
|
package/dist/cli/index.js
CHANGED
|
@@ -499,7 +499,7 @@ function canonicalPolicyJSON(value) {
|
|
|
499
499
|
}
|
|
500
500
|
|
|
501
501
|
// src/domain.ts
|
|
502
|
-
var VERSION = "0.1.
|
|
502
|
+
var VERSION = "0.1.8";
|
|
503
503
|
var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
|
|
504
504
|
var protocolSchema = z3.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
|
|
505
505
|
var idSchema = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
|
|
@@ -529,7 +529,7 @@ var expiresOnSchema = z3.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value) =>
|
|
|
529
529
|
return Number.isFinite(day.getTime()) && day.toISOString().slice(0, 10) === value;
|
|
530
530
|
}, "Use a real calendar date in YYYY-MM-DD format.");
|
|
531
531
|
var modelSchema = z3.object({
|
|
532
|
-
id: z3.string().min(1).max(300),
|
|
532
|
+
id: z3.string().min(1).max(300).refine((value) => value === value.trim() && !/[\x00-\x1f\x7f-\x9f]/.test(value), "Use a nonblank model ID without surrounding whitespace or control characters."),
|
|
533
533
|
name: label,
|
|
534
534
|
description: z3.string().max(8000).optional(),
|
|
535
535
|
available: z3.boolean().optional(),
|
|
@@ -1066,8 +1066,9 @@ var preset = (id, name, protocols, sources, alias) => parse2(providerPresetSchem
|
|
|
1066
1066
|
var providerPresets = [
|
|
1067
1067
|
preset("deepseek", "DeepSeek", [
|
|
1068
1068
|
route("openai-chat", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
|
|
1069
|
+
route("openai-responses", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
|
|
1069
1070
|
route("anthropic-messages", "https://api.deepseek.com/anthropic/v1", { catalogBaseUrl: "https://api.deepseek.com" })
|
|
1070
|
-
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models"], "DEEPSEEK_API_KEY"),
|
|
1071
|
+
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models", "https://api-docs.deepseek.com/updates/", "https://api-docs.deepseek.com/guides/responses_api/"], "DEEPSEEK_API_KEY"),
|
|
1071
1072
|
preset("openrouter", "OpenRouter", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, "https://openrouter.ai/api/v1", { catalogAuthStyle: "none" })), ["https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties", "https://openrouter.ai/docs/guides/overview"], "OPENROUTER_API_KEY"),
|
|
1072
1073
|
preset("anthropic", "Anthropic", [route("anthropic-messages", "https://api.anthropic.com/v1", { authStyle: "x-api-key" })], ["https://platform.claude.com/docs/en/api/overview", "https://platform.claude.com/docs/en/api/models/list"], "ANTHROPIC_API_KEY"),
|
|
1073
1074
|
preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
|
|
@@ -1149,7 +1150,7 @@ function providerFromPreset(presetId, options = {}) {
|
|
|
1149
1150
|
const suffix = selected.protocol === "anthropic-messages" ? "messages" : selected.protocol === "openai-responses" ? "responses" : "chat";
|
|
1150
1151
|
if (presetId === "fireworks" && !options.catalogBaseUrl && !options.catalogAccountId)
|
|
1151
1152
|
throw new Fault(400, "catalog_account_required", "Fireworks model discovery requires --catalog-account-id or an explicit --catalog-url.");
|
|
1152
|
-
if (selected.catalogFormat === "none" && options.catalogFormat && !options.catalogBaseUrl)
|
|
1153
|
+
if (selected.catalogFormat === "none" && options.catalogFormat && options.catalogFormat !== "none" && !options.catalogBaseUrl)
|
|
1153
1154
|
throw new Fault(400, "catalog_url_required", "This preset requires an explicit --catalog-url when enabling a catalog parser.");
|
|
1154
1155
|
const catalogBaseUrl = options.catalogBaseUrl ?? (presetId === "fireworks" && options.catalogAccountId ? `https://api.fireworks.ai/v1/accounts/${encodeURIComponent(options.catalogAccountId)}` : options.baseUrl ? undefined : selected.catalogBaseUrl);
|
|
1155
1156
|
return parse2(providerInputSchema, {
|
|
@@ -1166,9 +1167,11 @@ function providerFromPreset(presetId, options = {}) {
|
|
|
1166
1167
|
catalogAccountId: options.catalogAccountId,
|
|
1167
1168
|
modelsPath: options.modelsPath ?? selected.modelsPath,
|
|
1168
1169
|
additionalModels: presetId === "deepseek" && new URL(baseUrl).origin === "https://api.deepseek.com" ? [{
|
|
1169
|
-
id: "deepseek-
|
|
1170
|
-
name: "DeepSeek V4.1 Flash
|
|
1171
|
-
|
|
1170
|
+
id: "deepseek-flash",
|
|
1171
|
+
name: "DeepSeek V4.1 Flash",
|
|
1172
|
+
inputModalities: ["text", "image"],
|
|
1173
|
+
outputModalities: ["text"],
|
|
1174
|
+
supportedParameters: ["tools"]
|
|
1172
1175
|
}] : []
|
|
1173
1176
|
});
|
|
1174
1177
|
}
|
|
@@ -1331,6 +1334,33 @@ class SwitcherClient {
|
|
|
1331
1334
|
deleteProvider(id, version, idempotencyKey) {
|
|
1332
1335
|
return this.request("DELETE", `/v1/providers/${encodeURIComponent(id)}`, undefined, { version, idempotencyKey });
|
|
1333
1336
|
}
|
|
1337
|
+
async editModel(providerId, operation, value) {
|
|
1338
|
+
const model = typeof value === "string" ? undefined : parse2(modelSchema, value);
|
|
1339
|
+
const id = model?.id ?? parse2(modelSchema.shape.id, value);
|
|
1340
|
+
const provider = await this.getProvider(providerId);
|
|
1341
|
+
const { version, updatedAt, ...input } = provider;
|
|
1342
|
+
const manual = provider.manualModels.some((item) => item.id === id);
|
|
1343
|
+
const additional = (provider.additionalModels ?? []).some((item) => item.id === id);
|
|
1344
|
+
if (operation === "add" && (manual || additional))
|
|
1345
|
+
throw new SwitcherError(409, "model_exists", "This model is already configured. Use models update to replace its metadata.");
|
|
1346
|
+
if (operation !== "add" && !manual && !additional)
|
|
1347
|
+
throw new SwitcherError(404, "model_not_configured", "This model has no saved metadata. Use models add to configure a catalog model; remote catalog entries cannot be deleted locally.");
|
|
1348
|
+
const useManual = manual || !additional && (provider.manualModels.length > 0 || provider.catalogFormat === "none");
|
|
1349
|
+
const manualModels = provider.manualModels.filter((item) => item.id !== id);
|
|
1350
|
+
const additionalModels = (provider.additionalModels ?? []).filter((item) => item.id !== id);
|
|
1351
|
+
if (operation !== "remove")
|
|
1352
|
+
(useManual ? manualModels : additionalModels).push(model);
|
|
1353
|
+
return this.updateProvider({ ...input, manualModels, additionalModels }, version);
|
|
1354
|
+
}
|
|
1355
|
+
addModel(providerId, model) {
|
|
1356
|
+
return this.editModel(providerId, "add", model);
|
|
1357
|
+
}
|
|
1358
|
+
updateModel(providerId, model) {
|
|
1359
|
+
return this.editModel(providerId, "update", model);
|
|
1360
|
+
}
|
|
1361
|
+
removeModel(providerId, modelId) {
|
|
1362
|
+
return this.editModel(providerId, "remove", modelId);
|
|
1363
|
+
}
|
|
1334
1364
|
refreshModels(id, idempotencyKey) {
|
|
1335
1365
|
return this.request("POST", `/v1/providers/${encodeURIComponent(id)}/refresh`, {}, { idempotencyKey });
|
|
1336
1366
|
}
|
|
@@ -2178,7 +2208,7 @@ var openapi_default = {
|
|
|
2178
2208
|
openapi: "3.0.3",
|
|
2179
2209
|
info: {
|
|
2180
2210
|
title: "Switcher API",
|
|
2181
|
-
version: "0.1.
|
|
2211
|
+
version: "0.1.8",
|
|
2182
2212
|
description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
|
|
2183
2213
|
},
|
|
2184
2214
|
security: [
|
|
@@ -11098,12 +11128,16 @@ var HELP = `switcher \u2014 launch a coding harness with a provider and its mode
|
|
|
11098
11128
|
switcher providers presets [ID]
|
|
11099
11129
|
switcher providers list [--search TEXT] [--limit N] [--offset N]
|
|
11100
11130
|
switcher providers add ID --url URL --protocol PROTOCOL [--credential-env NAME]
|
|
11131
|
+
[--model MODEL | --models-file FILE] [--catalog-format none]
|
|
11101
11132
|
switcher providers add ID --preset PRESET [--protocol PROTOCOL] [--catalog-account-id ID]
|
|
11102
11133
|
switcher providers get|refresh ID
|
|
11103
11134
|
switcher providers update ID --file provider.json --version N
|
|
11104
11135
|
switcher providers delete ID --version N
|
|
11105
11136
|
switcher models PROVIDER [--refresh] [--search TEXT] [--limit N]
|
|
11106
|
-
switcher models
|
|
11137
|
+
switcher models list PROVIDER [--refresh] [--search TEXT] [--limit N]
|
|
11138
|
+
switcher models add|update PROVIDER MODEL [--file model.json | --name NAME --expires-on YYYY-MM-DD]
|
|
11139
|
+
switcher models remove PROVIDER MODEL
|
|
11140
|
+
switcher models config PROVIDER
|
|
11107
11141
|
switcher profiles list|get [ID]
|
|
11108
11142
|
switcher profiles add ID --provider ID --harness HARNESS --model MODEL [--model-policy-file FILE] [--role-model ROLE=MODEL]
|
|
11109
11143
|
switcher profiles update ID --file profile.json --version N
|
|
@@ -11129,6 +11163,10 @@ Remote API URL/key resolve through @hasna/contracts: overrides, Keychain,
|
|
|
11129
11163
|
~/.hasna/switcher/config/credentials, then environment. A key alone uses the gateway.
|
|
11130
11164
|
A configured remote API never falls back to local data.
|
|
11131
11165
|
Provider credential references must start SWITCHER_PROVIDER_.
|
|
11166
|
+
--models-file accepts a JSON array of model metadata; --model adds one starter.
|
|
11167
|
+
Use --catalog-format none for a manual catalog; otherwise discovery stays active.
|
|
11168
|
+
models update replaces saved metadata; omit expiry in its JSON to clear it.
|
|
11169
|
+
models remove removes saved metadata, not entries in an upstream catalog.
|
|
11132
11170
|
Credential bindings contain references only. Custom destinations require --origin URL.
|
|
11133
11171
|
Vault bindings use the installed secrets CLI and its canonical Contracts URL/key
|
|
11134
11172
|
by default. --vault-account pins a Keychain account; --vault-operator env requires
|
|
@@ -11185,6 +11223,7 @@ async function main(args = process.argv.slice(2)) {
|
|
|
11185
11223
|
preset: { type: "string" },
|
|
11186
11224
|
name: { type: "string" },
|
|
11187
11225
|
file: { type: "string" },
|
|
11226
|
+
"models-file": { type: "string" },
|
|
11188
11227
|
"credential-env": { type: "string" },
|
|
11189
11228
|
"auth-style": { type: "string" },
|
|
11190
11229
|
"catalog-url": { type: "string" },
|
|
@@ -11229,12 +11268,37 @@ async function main(args = process.argv.slice(2)) {
|
|
|
11229
11268
|
throw new Error("Unknown command. Run switcher --help.");
|
|
11230
11269
|
const providerFlags = ["url", "protocol", "preset", "credential-env", "auth-style", "catalog-url", "catalog-format", "catalog-auth-style", "catalog-credential-env", "catalog-account-id", "models-path"];
|
|
11231
11270
|
const provided = (names) => names.some((name) => values2[name] !== undefined);
|
|
11232
|
-
const
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
if (
|
|
11236
|
-
throw new Fault(400, "invalid_request", "Use models
|
|
11237
|
-
|
|
11271
|
+
const editingModel = command === "models" && positionals.length > 2 && ["add", "update", "remove"].includes(action2);
|
|
11272
|
+
const configuringModels = command === "models" && positionals.length > 2 && action2 === "config";
|
|
11273
|
+
const listingModels = command === "models" && positionals.length > 2 && action2 === "list";
|
|
11274
|
+
if (listingModels && (positionals.length !== 3 || nativeArgs.length || Object.keys(values2).some((name) => !["refresh", "search", "limit", "offset", "json"].includes(name))))
|
|
11275
|
+
throw new Fault(400, "invalid_request", "Use models list PROVIDER with optional --refresh, --search, --limit and --offset.");
|
|
11276
|
+
if (values2["expires-on"] !== undefined && (!editingModel || action2 === "remove"))
|
|
11277
|
+
throw new Fault(400, "conflicting_options", "--expires-on belongs to models add/update.");
|
|
11278
|
+
if (editingModel && (positionals.length !== 4 || nativeArgs.length || Object.keys(values2).some((name) => !(action2 === "remove" ? ["json"] : ["name", "expires-on", "file", "json"]).includes(name))))
|
|
11279
|
+
throw new Fault(400, "invalid_request", "Use models add/update PROVIDER MODEL with --file or --name/--expires-on; models remove accepts only PROVIDER MODEL.");
|
|
11280
|
+
if (configuringModels && (positionals.length !== 3 || nativeArgs.length || Object.keys(values2).some((name) => name !== "json")))
|
|
11281
|
+
throw new Fault(400, "invalid_request", "Use models config PROVIDER without other settings.");
|
|
11282
|
+
if (editingModel && values2.file !== undefined && (values2.name !== undefined || values2["expires-on"] !== undefined))
|
|
11283
|
+
throw new Fault(400, "conflicting_options", "Use --file by itself for model metadata.");
|
|
11284
|
+
const modelInput = editingModel && action2 !== "remove" ? parse2(modelSchema, values2.file !== undefined ? await readInput(values2.file) : { id: positionals[3], name: values2.name ?? positionals[3], expiresOn: values2["expires-on"] }) : undefined;
|
|
11285
|
+
if (modelInput && modelInput.id !== positionals[3])
|
|
11286
|
+
throw new Fault(400, "id_mismatch", "Model file id must match the command model ID.");
|
|
11287
|
+
if (editingModel && action2 === "remove")
|
|
11288
|
+
parse2(modelSchema.shape.id, positionals[3]);
|
|
11289
|
+
const seedingProvider = command === "providers" && action2 === "add";
|
|
11290
|
+
if (values2["models-file"] !== undefined && !seedingProvider)
|
|
11291
|
+
throw new Fault(400, "conflicting_options", "--models-file belongs to providers add.");
|
|
11292
|
+
if (command === "providers" && values2.model !== undefined && !seedingProvider)
|
|
11293
|
+
throw new Fault(400, "conflicting_options", "Provider --model belongs to providers add. Use models add/update/remove for saved providers.");
|
|
11294
|
+
if (seedingProvider && values2["models-file"] !== undefined && values2.model !== undefined)
|
|
11295
|
+
throw new Fault(400, "conflicting_options", "Use --model or --models-file, not both.");
|
|
11296
|
+
let starterModels;
|
|
11297
|
+
if (seedingProvider && (values2.model !== undefined || values2["models-file"] !== undefined)) {
|
|
11298
|
+
starterModels = parse2(modelSchema.array().min(1).max(1e4), values2["models-file"] !== undefined ? await readInput(values2["models-file"]) : [{ id: values2.model, name: values2.model }]);
|
|
11299
|
+
if (new Set(starterModels.map((model3) => model3.id)).size !== starterModels.length)
|
|
11300
|
+
throw new Fault(400, "duplicate_model", "Model IDs must be unique.");
|
|
11301
|
+
}
|
|
11238
11302
|
const credentialFlags = ["vault-key", "vault-url", "vault-cli", "vault-account", "vault-operator", "keychain-service", "keychain-account", "origin"];
|
|
11239
11303
|
const credentials = new CredentialResolver;
|
|
11240
11304
|
if (values2.sha256 !== undefined && !(command === "credentials" && action2 === "repair-executable"))
|
|
@@ -11303,7 +11367,7 @@ async function main(args = process.argv.slice(2)) {
|
|
|
11303
11367
|
if (command === "launch" && backend === "direct" && values2["ori-executable"] !== undefined)
|
|
11304
11368
|
throw new Fault(400, "conflicting_options", "--ori-executable requires --backend ori.");
|
|
11305
11369
|
const mutation = (command === "providers" || command === "profiles") && ["add", "update"].includes(action2);
|
|
11306
|
-
if (values2.file && (!mutation || provided([...providerFlags, "name", "provider", "harness", "model", "model-policy-file", "role-model"])))
|
|
11370
|
+
if (values2.file && !editingModel && (!mutation || provided([...providerFlags, "name", "provider", "harness", "model", "models-file", "model-policy-file", "role-model"])))
|
|
11307
11371
|
throw new Fault(400, "conflicting_options", "Use --file by itself for provider/profile settings; inline settings cannot override an input file.");
|
|
11308
11372
|
if (command === "launch" && !values2.provider && provided([...providerFlags, "name", "harness", "model", "search", "model-policy-file", "role-model"]))
|
|
11309
11373
|
throw new Fault(400, "conflicting_options", "Use --provider PROVIDER for direct launch settings, or update the saved profile explicitly.");
|
|
@@ -11399,17 +11463,18 @@ async function main(args = process.argv.slice(2)) {
|
|
|
11399
11463
|
process.exitCode = await launch(client, profileId, { backend, oriExecutable: values2["ori-executable"], cwd: values2.cwd, executable: values2.executable, stateDir: values2["state-dir"], args: nativeArgs, timeoutMs, refresh: false, resolveCredential: (provider) => credentials.resolve(provider) });
|
|
11400
11464
|
return;
|
|
11401
11465
|
}
|
|
11402
|
-
if (
|
|
11466
|
+
if (editingModel) {
|
|
11467
|
+
const saved = action2 === "add" ? await client.addModel(id2, modelInput) : action2 === "update" ? await client.updateModel(id2, modelInput) : await client.removeModel(id2, positionals[3]);
|
|
11468
|
+
output({ providerId: saved.id, version: saved.version, ...modelInput ? { model: modelInput, expired: modelExpired(modelInput) } : { removed: positionals[3] } });
|
|
11469
|
+
return;
|
|
11470
|
+
}
|
|
11471
|
+
if (configuringModels) {
|
|
11403
11472
|
const provider = await client.getProvider(id2);
|
|
11404
|
-
|
|
11405
|
-
if ((provider.additionalModels ?? []).some((model3) => model3.id === modelAddition.id))
|
|
11406
|
-
throw new Fault(409, "model_exists", "This additional model already exists. Use providers update --file to edit its metadata.");
|
|
11407
|
-
await client.updateProvider({ ...input, additionalModels: [...provider.additionalModels ?? [], modelAddition] }, version);
|
|
11408
|
-
output({ providerId: provider.id, model: modelAddition, expired: modelExpired(modelAddition) });
|
|
11473
|
+
output({ providerId: provider.id, version: provider.version, manualModels: provider.manualModels, additionalModels: provider.additionalModels ?? [] });
|
|
11409
11474
|
return;
|
|
11410
11475
|
}
|
|
11411
11476
|
if (command === "models" && action2) {
|
|
11412
|
-
const provider = await resolveLaunchProvider(client, action2, presetOptions());
|
|
11477
|
+
const provider = await resolveLaunchProvider(client, listingModels ? id2 : action2, presetOptions());
|
|
11413
11478
|
if (values2.refresh)
|
|
11414
11479
|
await client.refreshModels(provider.id);
|
|
11415
11480
|
try {
|
|
@@ -11450,7 +11515,7 @@ async function main(args = process.argv.slice(2)) {
|
|
|
11450
11515
|
return;
|
|
11451
11516
|
}
|
|
11452
11517
|
if (["add", "update"].includes(action2) && id2) {
|
|
11453
|
-
|
|
11518
|
+
let input = parse2(providerInputSchema, values2.file ? await readInput(values2.file) : values2.preset ? { ...providerFromPreset(values2.preset, { ...presetOptions(), id: id2 }), ...values2.name ? { name: values2.name } : {} } : {
|
|
11454
11519
|
id: id2,
|
|
11455
11520
|
name: values2.name ?? id2,
|
|
11456
11521
|
baseUrl: values2.url,
|
|
@@ -11464,6 +11529,13 @@ async function main(args = process.argv.slice(2)) {
|
|
|
11464
11529
|
catalogAccountId: values2["catalog-account-id"],
|
|
11465
11530
|
modelsPath: values2["models-path"]
|
|
11466
11531
|
});
|
|
11532
|
+
if (starterModels) {
|
|
11533
|
+
const field = input.catalogFormat === "none" ? "manualModels" : "additionalModels";
|
|
11534
|
+
const models = new Map((input[field] ?? []).map((model3) => [model3.id, model3]));
|
|
11535
|
+
for (const model3 of starterModels)
|
|
11536
|
+
models.set(model3.id, model3);
|
|
11537
|
+
input = parse2(providerInputSchema, { ...input, [field]: [...models.values()] });
|
|
11538
|
+
}
|
|
11467
11539
|
if (input.id !== id2)
|
|
11468
11540
|
throw new Error("File id must match the command id.");
|
|
11469
11541
|
output(action2 === "add" ? await client.createProvider(input) : await client.updateProvider(input, currentVersion()));
|
package/dist/domain.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { type RoutingEvent } from "./model-policy-schema";
|
|
|
3
3
|
export { modelPolicySchema, routingEventSchema, routingEventsSchema } from "./model-policy-schema";
|
|
4
4
|
export type { ModelPolicy, RoutingEvent } from "./model-policy-schema";
|
|
5
5
|
export type { AuthStyle } from "./auth";
|
|
6
|
-
export declare const VERSION = "0.1.
|
|
6
|
+
export declare const VERSION = "0.1.8";
|
|
7
7
|
export declare const harnessSchema: z.ZodEnum<["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]>;
|
|
8
8
|
export declare const protocolSchema: z.ZodEnum<["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]>;
|
|
9
9
|
export declare const idSchema: z.ZodString;
|
|
10
10
|
export declare function endpoint(value: string): string;
|
|
11
11
|
export declare const expiresOnSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
12
12
|
export declare const modelSchema: z.ZodObject<{
|
|
13
|
-
id: z.ZodString
|
|
13
|
+
id: z.ZodEffects<z.ZodString, string, string>;
|
|
14
14
|
name: z.ZodString;
|
|
15
15
|
description: z.ZodOptional<z.ZodString>;
|
|
16
16
|
available: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -60,7 +60,7 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
60
60
|
catalogAccountId: z.ZodOptional<z.ZodString>;
|
|
61
61
|
modelsPath: z.ZodDefault<z.ZodString>;
|
|
62
62
|
manualModels: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
63
|
-
id: z.ZodString
|
|
63
|
+
id: z.ZodEffects<z.ZodString, string, string>;
|
|
64
64
|
name: z.ZodString;
|
|
65
65
|
description: z.ZodOptional<z.ZodString>;
|
|
66
66
|
available: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -97,7 +97,7 @@ export declare const providerInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
97
97
|
supportedGenerationMethods?: string[] | undefined;
|
|
98
98
|
}>, "many">>;
|
|
99
99
|
additionalModels: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
100
|
-
id: z.ZodString
|
|
100
|
+
id: z.ZodEffects<z.ZodString, string, string>;
|
|
101
101
|
name: z.ZodString;
|
|
102
102
|
description: z.ZodOptional<z.ZodString>;
|
|
103
103
|
available: z.ZodOptional<z.ZodBoolean>;
|
package/dist/index.js
CHANGED
|
@@ -75,7 +75,7 @@ var expiresOnSchema = z2.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value) =>
|
|
|
75
75
|
return Number.isFinite(day.getTime()) && day.toISOString().slice(0, 10) === value;
|
|
76
76
|
}, "Use a real calendar date in YYYY-MM-DD format.");
|
|
77
77
|
var modelSchema = z2.object({
|
|
78
|
-
id: z2.string().min(1).max(300),
|
|
78
|
+
id: z2.string().min(1).max(300).refine((value) => value === value.trim() && !/[\x00-\x1f\x7f-\x9f]/.test(value), "Use a nonblank model ID without surrounding whitespace or control characters."),
|
|
79
79
|
name: label,
|
|
80
80
|
description: z2.string().max(8000).optional(),
|
|
81
81
|
available: z2.boolean().optional(),
|
|
@@ -230,8 +230,9 @@ var preset = (id, name, protocols, sources, alias) => parse(providerPresetSchema
|
|
|
230
230
|
var providerPresets = [
|
|
231
231
|
preset("deepseek", "DeepSeek", [
|
|
232
232
|
route("openai-chat", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
|
|
233
|
+
route("openai-responses", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
|
|
233
234
|
route("anthropic-messages", "https://api.deepseek.com/anthropic/v1", { catalogBaseUrl: "https://api.deepseek.com" })
|
|
234
|
-
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models"], "DEEPSEEK_API_KEY"),
|
|
235
|
+
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models", "https://api-docs.deepseek.com/updates/", "https://api-docs.deepseek.com/guides/responses_api/"], "DEEPSEEK_API_KEY"),
|
|
235
236
|
preset("openrouter", "OpenRouter", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, "https://openrouter.ai/api/v1", { catalogAuthStyle: "none" })), ["https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties", "https://openrouter.ai/docs/guides/overview"], "OPENROUTER_API_KEY"),
|
|
236
237
|
preset("anthropic", "Anthropic", [route("anthropic-messages", "https://api.anthropic.com/v1", { authStyle: "x-api-key" })], ["https://platform.claude.com/docs/en/api/overview", "https://platform.claude.com/docs/en/api/models/list"], "ANTHROPIC_API_KEY"),
|
|
237
238
|
preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
|
|
@@ -313,7 +314,7 @@ function providerFromPreset(presetId, options = {}) {
|
|
|
313
314
|
const suffix = selected.protocol === "anthropic-messages" ? "messages" : selected.protocol === "openai-responses" ? "responses" : "chat";
|
|
314
315
|
if (presetId === "fireworks" && !options.catalogBaseUrl && !options.catalogAccountId)
|
|
315
316
|
throw new Fault(400, "catalog_account_required", "Fireworks model discovery requires --catalog-account-id or an explicit --catalog-url.");
|
|
316
|
-
if (selected.catalogFormat === "none" && options.catalogFormat && !options.catalogBaseUrl)
|
|
317
|
+
if (selected.catalogFormat === "none" && options.catalogFormat && options.catalogFormat !== "none" && !options.catalogBaseUrl)
|
|
317
318
|
throw new Fault(400, "catalog_url_required", "This preset requires an explicit --catalog-url when enabling a catalog parser.");
|
|
318
319
|
const catalogBaseUrl = options.catalogBaseUrl ?? (presetId === "fireworks" && options.catalogAccountId ? `https://api.fireworks.ai/v1/accounts/${encodeURIComponent(options.catalogAccountId)}` : options.baseUrl ? undefined : selected.catalogBaseUrl);
|
|
319
320
|
return parse(providerInputSchema, {
|
|
@@ -330,9 +331,11 @@ function providerFromPreset(presetId, options = {}) {
|
|
|
330
331
|
catalogAccountId: options.catalogAccountId,
|
|
331
332
|
modelsPath: options.modelsPath ?? selected.modelsPath,
|
|
332
333
|
additionalModels: presetId === "deepseek" && new URL(baseUrl).origin === "https://api.deepseek.com" ? [{
|
|
333
|
-
id: "deepseek-
|
|
334
|
-
name: "DeepSeek V4.1 Flash
|
|
335
|
-
|
|
334
|
+
id: "deepseek-flash",
|
|
335
|
+
name: "DeepSeek V4.1 Flash",
|
|
336
|
+
inputModalities: ["text", "image"],
|
|
337
|
+
outputModalities: ["text"],
|
|
338
|
+
supportedParameters: ["tools"]
|
|
336
339
|
}] : []
|
|
337
340
|
});
|
|
338
341
|
}
|
|
@@ -483,6 +486,33 @@ class SwitcherClient {
|
|
|
483
486
|
deleteProvider(id, version, idempotencyKey) {
|
|
484
487
|
return this.request("DELETE", `/v1/providers/${encodeURIComponent(id)}`, undefined, { version, idempotencyKey });
|
|
485
488
|
}
|
|
489
|
+
async editModel(providerId, operation, value) {
|
|
490
|
+
const model = typeof value === "string" ? undefined : parse(modelSchema, value);
|
|
491
|
+
const id = model?.id ?? parse(modelSchema.shape.id, value);
|
|
492
|
+
const provider = await this.getProvider(providerId);
|
|
493
|
+
const { version, updatedAt, ...input } = provider;
|
|
494
|
+
const manual = provider.manualModels.some((item) => item.id === id);
|
|
495
|
+
const additional = (provider.additionalModels ?? []).some((item) => item.id === id);
|
|
496
|
+
if (operation === "add" && (manual || additional))
|
|
497
|
+
throw new SwitcherError(409, "model_exists", "This model is already configured. Use models update to replace its metadata.");
|
|
498
|
+
if (operation !== "add" && !manual && !additional)
|
|
499
|
+
throw new SwitcherError(404, "model_not_configured", "This model has no saved metadata. Use models add to configure a catalog model; remote catalog entries cannot be deleted locally.");
|
|
500
|
+
const useManual = manual || !additional && (provider.manualModels.length > 0 || provider.catalogFormat === "none");
|
|
501
|
+
const manualModels = provider.manualModels.filter((item) => item.id !== id);
|
|
502
|
+
const additionalModels = (provider.additionalModels ?? []).filter((item) => item.id !== id);
|
|
503
|
+
if (operation !== "remove")
|
|
504
|
+
(useManual ? manualModels : additionalModels).push(model);
|
|
505
|
+
return this.updateProvider({ ...input, manualModels, additionalModels }, version);
|
|
506
|
+
}
|
|
507
|
+
addModel(providerId, model) {
|
|
508
|
+
return this.editModel(providerId, "add", model);
|
|
509
|
+
}
|
|
510
|
+
updateModel(providerId, model) {
|
|
511
|
+
return this.editModel(providerId, "update", model);
|
|
512
|
+
}
|
|
513
|
+
removeModel(providerId, modelId) {
|
|
514
|
+
return this.editModel(providerId, "remove", modelId);
|
|
515
|
+
}
|
|
486
516
|
refreshModels(id, idempotencyKey) {
|
|
487
517
|
return this.request("POST", `/v1/providers/${encodeURIComponent(id)}/refresh`, {}, { idempotencyKey });
|
|
488
518
|
}
|
package/dist/mcp/index.js
CHANGED
|
@@ -55,7 +55,7 @@ var routingEventSchema = z.object({
|
|
|
55
55
|
var routingEventsSchema = z.array(routingEventSchema).max(1000);
|
|
56
56
|
|
|
57
57
|
// src/domain.ts
|
|
58
|
-
var VERSION = "0.1.
|
|
58
|
+
var VERSION = "0.1.8";
|
|
59
59
|
var harnessSchema = z2.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
|
|
60
60
|
var protocolSchema = z2.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
|
|
61
61
|
var idSchema = z2.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
|
|
@@ -85,7 +85,7 @@ var expiresOnSchema = z2.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value) =>
|
|
|
85
85
|
return Number.isFinite(day.getTime()) && day.toISOString().slice(0, 10) === value;
|
|
86
86
|
}, "Use a real calendar date in YYYY-MM-DD format.");
|
|
87
87
|
var modelSchema = z2.object({
|
|
88
|
-
id: z2.string().min(1).max(300),
|
|
88
|
+
id: z2.string().min(1).max(300).refine((value) => value === value.trim() && !/[\x00-\x1f\x7f-\x9f]/.test(value), "Use a nonblank model ID without surrounding whitespace or control characters."),
|
|
89
89
|
name: label,
|
|
90
90
|
description: z2.string().max(8000).optional(),
|
|
91
91
|
available: z2.boolean().optional(),
|
|
@@ -229,8 +229,9 @@ var preset = (id, name, protocols, sources, alias) => parse(providerPresetSchema
|
|
|
229
229
|
var providerPresets = [
|
|
230
230
|
preset("deepseek", "DeepSeek", [
|
|
231
231
|
route("openai-chat", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
|
|
232
|
+
route("openai-responses", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
|
|
232
233
|
route("anthropic-messages", "https://api.deepseek.com/anthropic/v1", { catalogBaseUrl: "https://api.deepseek.com" })
|
|
233
|
-
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models"], "DEEPSEEK_API_KEY"),
|
|
234
|
+
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models", "https://api-docs.deepseek.com/updates/", "https://api-docs.deepseek.com/guides/responses_api/"], "DEEPSEEK_API_KEY"),
|
|
234
235
|
preset("openrouter", "OpenRouter", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, "https://openrouter.ai/api/v1", { catalogAuthStyle: "none" })), ["https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties", "https://openrouter.ai/docs/guides/overview"], "OPENROUTER_API_KEY"),
|
|
235
236
|
preset("anthropic", "Anthropic", [route("anthropic-messages", "https://api.anthropic.com/v1", { authStyle: "x-api-key" })], ["https://platform.claude.com/docs/en/api/overview", "https://platform.claude.com/docs/en/api/models/list"], "ANTHROPIC_API_KEY"),
|
|
236
237
|
preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
|
|
@@ -438,6 +439,33 @@ class SwitcherClient {
|
|
|
438
439
|
deleteProvider(id, version, idempotencyKey) {
|
|
439
440
|
return this.request("DELETE", `/v1/providers/${encodeURIComponent(id)}`, undefined, { version, idempotencyKey });
|
|
440
441
|
}
|
|
442
|
+
async editModel(providerId, operation, value) {
|
|
443
|
+
const model = typeof value === "string" ? undefined : parse(modelSchema, value);
|
|
444
|
+
const id = model?.id ?? parse(modelSchema.shape.id, value);
|
|
445
|
+
const provider = await this.getProvider(providerId);
|
|
446
|
+
const { version, updatedAt, ...input } = provider;
|
|
447
|
+
const manual = provider.manualModels.some((item) => item.id === id);
|
|
448
|
+
const additional = (provider.additionalModels ?? []).some((item) => item.id === id);
|
|
449
|
+
if (operation === "add" && (manual || additional))
|
|
450
|
+
throw new SwitcherError(409, "model_exists", "This model is already configured. Use models update to replace its metadata.");
|
|
451
|
+
if (operation !== "add" && !manual && !additional)
|
|
452
|
+
throw new SwitcherError(404, "model_not_configured", "This model has no saved metadata. Use models add to configure a catalog model; remote catalog entries cannot be deleted locally.");
|
|
453
|
+
const useManual = manual || !additional && (provider.manualModels.length > 0 || provider.catalogFormat === "none");
|
|
454
|
+
const manualModels = provider.manualModels.filter((item) => item.id !== id);
|
|
455
|
+
const additionalModels = (provider.additionalModels ?? []).filter((item) => item.id !== id);
|
|
456
|
+
if (operation !== "remove")
|
|
457
|
+
(useManual ? manualModels : additionalModels).push(model);
|
|
458
|
+
return this.updateProvider({ ...input, manualModels, additionalModels }, version);
|
|
459
|
+
}
|
|
460
|
+
addModel(providerId, model) {
|
|
461
|
+
return this.editModel(providerId, "add", model);
|
|
462
|
+
}
|
|
463
|
+
updateModel(providerId, model) {
|
|
464
|
+
return this.editModel(providerId, "update", model);
|
|
465
|
+
}
|
|
466
|
+
removeModel(providerId, modelId) {
|
|
467
|
+
return this.editModel(providerId, "remove", modelId);
|
|
468
|
+
}
|
|
441
469
|
refreshModels(id, idempotencyKey) {
|
|
442
470
|
return this.request("POST", `/v1/providers/${encodeURIComponent(id)}/refresh`, {}, { idempotencyKey });
|
|
443
471
|
}
|
|
@@ -500,6 +528,9 @@ tool("models_list", "List catalog with capability information.", { id: z3.string
|
|
|
500
528
|
const { id, ...rest } = p;
|
|
501
529
|
return clientFromEnv().listModels(id, rest);
|
|
502
530
|
});
|
|
531
|
+
tool("models_add", "Add saved model metadata; discovery stays active unless the provider uses a manual catalog.", { providerId: z3.string(), model: modelSchema }, (p) => clientFromEnv().addModel(p.providerId, p.model));
|
|
532
|
+
tool("models_update", "Replace all saved metadata for a configured model.", { providerId: z3.string(), model: modelSchema }, (p) => clientFromEnv().updateModel(p.providerId, p.model));
|
|
533
|
+
tool("models_remove", "Remove saved model metadata; upstream catalog entries remain.", { providerId: z3.string(), modelId: modelSchema.shape.id }, (p) => clientFromEnv().removeModel(p.providerId, p.modelId));
|
|
503
534
|
tool("models_refresh", "Discover provider models.", { id: z3.string() }, (p) => clientFromEnv().refreshModels(p.id));
|
|
504
535
|
tool("profiles_list", "List harness launch profiles.", page, (p) => clientFromEnv().listProfiles(p));
|
|
505
536
|
tool("profiles_get", "Get a harness profile.", { id: z3.string() }, (p) => clientFromEnv().getProfile(p.id));
|
package/dist/sdk.d.ts
CHANGED
|
@@ -251,6 +251,137 @@ export declare class SwitcherClient {
|
|
|
251
251
|
deleteProvider(id: string, version: number, idempotencyKey?: string): Promise<{
|
|
252
252
|
deleted: string;
|
|
253
253
|
}>;
|
|
254
|
+
/** Configure model metadata through the existing versioned provider API.
|
|
255
|
+
* Discovery stays active unless the provider explicitly uses a manual catalog.
|
|
256
|
+
* A concurrent edit returns 409; it is never silently overwritten or retried. */
|
|
257
|
+
private editModel;
|
|
258
|
+
addModel(providerId: string, model: Model): Promise<{
|
|
259
|
+
id: string;
|
|
260
|
+
name: string;
|
|
261
|
+
baseUrl: string;
|
|
262
|
+
protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
|
|
263
|
+
credentialEnv?: string;
|
|
264
|
+
authStyle: "bearer" | "x-api-key" | "api-key";
|
|
265
|
+
catalogBaseUrl?: string;
|
|
266
|
+
catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
|
|
267
|
+
catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
|
|
268
|
+
catalogCredentialEnv?: string;
|
|
269
|
+
catalogAccountId?: string;
|
|
270
|
+
modelsPath: string;
|
|
271
|
+
manualModels: {
|
|
272
|
+
id: string;
|
|
273
|
+
name: string;
|
|
274
|
+
description?: string;
|
|
275
|
+
available?: boolean;
|
|
276
|
+
expiresOn?: string;
|
|
277
|
+
contextWindow?: number;
|
|
278
|
+
maxOutputTokens?: number;
|
|
279
|
+
inputModalities?: string[];
|
|
280
|
+
outputModalities?: string[];
|
|
281
|
+
supportedParameters?: string[];
|
|
282
|
+
supportedGenerationMethods?: string[];
|
|
283
|
+
}[];
|
|
284
|
+
additionalModels?: {
|
|
285
|
+
id: string;
|
|
286
|
+
name: string;
|
|
287
|
+
description?: string;
|
|
288
|
+
available?: boolean;
|
|
289
|
+
expiresOn?: string;
|
|
290
|
+
contextWindow?: number;
|
|
291
|
+
maxOutputTokens?: number;
|
|
292
|
+
inputModalities?: string[];
|
|
293
|
+
outputModalities?: string[];
|
|
294
|
+
supportedParameters?: string[];
|
|
295
|
+
supportedGenerationMethods?: string[];
|
|
296
|
+
}[];
|
|
297
|
+
version: number;
|
|
298
|
+
updatedAt: string;
|
|
299
|
+
}>;
|
|
300
|
+
/** Replace all saved metadata for one model, including clearing omitted fields. */
|
|
301
|
+
updateModel(providerId: string, model: Model): Promise<{
|
|
302
|
+
id: string;
|
|
303
|
+
name: string;
|
|
304
|
+
baseUrl: string;
|
|
305
|
+
protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
|
|
306
|
+
credentialEnv?: string;
|
|
307
|
+
authStyle: "bearer" | "x-api-key" | "api-key";
|
|
308
|
+
catalogBaseUrl?: string;
|
|
309
|
+
catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
|
|
310
|
+
catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
|
|
311
|
+
catalogCredentialEnv?: string;
|
|
312
|
+
catalogAccountId?: string;
|
|
313
|
+
modelsPath: string;
|
|
314
|
+
manualModels: {
|
|
315
|
+
id: string;
|
|
316
|
+
name: string;
|
|
317
|
+
description?: string;
|
|
318
|
+
available?: boolean;
|
|
319
|
+
expiresOn?: string;
|
|
320
|
+
contextWindow?: number;
|
|
321
|
+
maxOutputTokens?: number;
|
|
322
|
+
inputModalities?: string[];
|
|
323
|
+
outputModalities?: string[];
|
|
324
|
+
supportedParameters?: string[];
|
|
325
|
+
supportedGenerationMethods?: string[];
|
|
326
|
+
}[];
|
|
327
|
+
additionalModels?: {
|
|
328
|
+
id: string;
|
|
329
|
+
name: string;
|
|
330
|
+
description?: string;
|
|
331
|
+
available?: boolean;
|
|
332
|
+
expiresOn?: string;
|
|
333
|
+
contextWindow?: number;
|
|
334
|
+
maxOutputTokens?: number;
|
|
335
|
+
inputModalities?: string[];
|
|
336
|
+
outputModalities?: string[];
|
|
337
|
+
supportedParameters?: string[];
|
|
338
|
+
supportedGenerationMethods?: string[];
|
|
339
|
+
}[];
|
|
340
|
+
version: number;
|
|
341
|
+
updatedAt: string;
|
|
342
|
+
}>;
|
|
343
|
+
removeModel(providerId: string, modelId: string): Promise<{
|
|
344
|
+
id: string;
|
|
345
|
+
name: string;
|
|
346
|
+
baseUrl: string;
|
|
347
|
+
protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
|
|
348
|
+
credentialEnv?: string;
|
|
349
|
+
authStyle: "bearer" | "x-api-key" | "api-key";
|
|
350
|
+
catalogBaseUrl?: string;
|
|
351
|
+
catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
|
|
352
|
+
catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
|
|
353
|
+
catalogCredentialEnv?: string;
|
|
354
|
+
catalogAccountId?: string;
|
|
355
|
+
modelsPath: string;
|
|
356
|
+
manualModels: {
|
|
357
|
+
id: string;
|
|
358
|
+
name: string;
|
|
359
|
+
description?: string;
|
|
360
|
+
available?: boolean;
|
|
361
|
+
expiresOn?: string;
|
|
362
|
+
contextWindow?: number;
|
|
363
|
+
maxOutputTokens?: number;
|
|
364
|
+
inputModalities?: string[];
|
|
365
|
+
outputModalities?: string[];
|
|
366
|
+
supportedParameters?: string[];
|
|
367
|
+
supportedGenerationMethods?: string[];
|
|
368
|
+
}[];
|
|
369
|
+
additionalModels?: {
|
|
370
|
+
id: string;
|
|
371
|
+
name: string;
|
|
372
|
+
description?: string;
|
|
373
|
+
available?: boolean;
|
|
374
|
+
expiresOn?: string;
|
|
375
|
+
contextWindow?: number;
|
|
376
|
+
maxOutputTokens?: number;
|
|
377
|
+
inputModalities?: string[];
|
|
378
|
+
outputModalities?: string[];
|
|
379
|
+
supportedParameters?: string[];
|
|
380
|
+
supportedGenerationMethods?: string[];
|
|
381
|
+
}[];
|
|
382
|
+
version: number;
|
|
383
|
+
updatedAt: string;
|
|
384
|
+
}>;
|
|
254
385
|
refreshModels(id: string, idempotencyKey?: string): Promise<{
|
|
255
386
|
models: {
|
|
256
387
|
id: string;
|
package/dist/sdk.js
CHANGED
|
@@ -75,7 +75,7 @@ var expiresOnSchema = z2.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value) =>
|
|
|
75
75
|
return Number.isFinite(day.getTime()) && day.toISOString().slice(0, 10) === value;
|
|
76
76
|
}, "Use a real calendar date in YYYY-MM-DD format.");
|
|
77
77
|
var modelSchema = z2.object({
|
|
78
|
-
id: z2.string().min(1).max(300),
|
|
78
|
+
id: z2.string().min(1).max(300).refine((value) => value === value.trim() && !/[\x00-\x1f\x7f-\x9f]/.test(value), "Use a nonblank model ID without surrounding whitespace or control characters."),
|
|
79
79
|
name: label,
|
|
80
80
|
description: z2.string().max(8000).optional(),
|
|
81
81
|
available: z2.boolean().optional(),
|
|
@@ -230,8 +230,9 @@ var preset = (id, name, protocols, sources, alias) => parse(providerPresetSchema
|
|
|
230
230
|
var providerPresets = [
|
|
231
231
|
preset("deepseek", "DeepSeek", [
|
|
232
232
|
route("openai-chat", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
|
|
233
|
+
route("openai-responses", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
|
|
233
234
|
route("anthropic-messages", "https://api.deepseek.com/anthropic/v1", { catalogBaseUrl: "https://api.deepseek.com" })
|
|
234
|
-
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models"], "DEEPSEEK_API_KEY"),
|
|
235
|
+
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models", "https://api-docs.deepseek.com/updates/", "https://api-docs.deepseek.com/guides/responses_api/"], "DEEPSEEK_API_KEY"),
|
|
235
236
|
preset("openrouter", "OpenRouter", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, "https://openrouter.ai/api/v1", { catalogAuthStyle: "none" })), ["https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties", "https://openrouter.ai/docs/guides/overview"], "OPENROUTER_API_KEY"),
|
|
236
237
|
preset("anthropic", "Anthropic", [route("anthropic-messages", "https://api.anthropic.com/v1", { authStyle: "x-api-key" })], ["https://platform.claude.com/docs/en/api/overview", "https://platform.claude.com/docs/en/api/models/list"], "ANTHROPIC_API_KEY"),
|
|
237
238
|
preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
|
|
@@ -313,7 +314,7 @@ function providerFromPreset(presetId, options = {}) {
|
|
|
313
314
|
const suffix = selected.protocol === "anthropic-messages" ? "messages" : selected.protocol === "openai-responses" ? "responses" : "chat";
|
|
314
315
|
if (presetId === "fireworks" && !options.catalogBaseUrl && !options.catalogAccountId)
|
|
315
316
|
throw new Fault(400, "catalog_account_required", "Fireworks model discovery requires --catalog-account-id or an explicit --catalog-url.");
|
|
316
|
-
if (selected.catalogFormat === "none" && options.catalogFormat && !options.catalogBaseUrl)
|
|
317
|
+
if (selected.catalogFormat === "none" && options.catalogFormat && options.catalogFormat !== "none" && !options.catalogBaseUrl)
|
|
317
318
|
throw new Fault(400, "catalog_url_required", "This preset requires an explicit --catalog-url when enabling a catalog parser.");
|
|
318
319
|
const catalogBaseUrl = options.catalogBaseUrl ?? (presetId === "fireworks" && options.catalogAccountId ? `https://api.fireworks.ai/v1/accounts/${encodeURIComponent(options.catalogAccountId)}` : options.baseUrl ? undefined : selected.catalogBaseUrl);
|
|
319
320
|
return parse(providerInputSchema, {
|
|
@@ -330,9 +331,11 @@ function providerFromPreset(presetId, options = {}) {
|
|
|
330
331
|
catalogAccountId: options.catalogAccountId,
|
|
331
332
|
modelsPath: options.modelsPath ?? selected.modelsPath,
|
|
332
333
|
additionalModels: presetId === "deepseek" && new URL(baseUrl).origin === "https://api.deepseek.com" ? [{
|
|
333
|
-
id: "deepseek-
|
|
334
|
-
name: "DeepSeek V4.1 Flash
|
|
335
|
-
|
|
334
|
+
id: "deepseek-flash",
|
|
335
|
+
name: "DeepSeek V4.1 Flash",
|
|
336
|
+
inputModalities: ["text", "image"],
|
|
337
|
+
outputModalities: ["text"],
|
|
338
|
+
supportedParameters: ["tools"]
|
|
336
339
|
}] : []
|
|
337
340
|
});
|
|
338
341
|
}
|
|
@@ -483,6 +486,33 @@ class SwitcherClient {
|
|
|
483
486
|
deleteProvider(id, version, idempotencyKey) {
|
|
484
487
|
return this.request("DELETE", `/v1/providers/${encodeURIComponent(id)}`, undefined, { version, idempotencyKey });
|
|
485
488
|
}
|
|
489
|
+
async editModel(providerId, operation, value) {
|
|
490
|
+
const model = typeof value === "string" ? undefined : parse(modelSchema, value);
|
|
491
|
+
const id = model?.id ?? parse(modelSchema.shape.id, value);
|
|
492
|
+
const provider = await this.getProvider(providerId);
|
|
493
|
+
const { version, updatedAt, ...input } = provider;
|
|
494
|
+
const manual = provider.manualModels.some((item) => item.id === id);
|
|
495
|
+
const additional = (provider.additionalModels ?? []).some((item) => item.id === id);
|
|
496
|
+
if (operation === "add" && (manual || additional))
|
|
497
|
+
throw new SwitcherError(409, "model_exists", "This model is already configured. Use models update to replace its metadata.");
|
|
498
|
+
if (operation !== "add" && !manual && !additional)
|
|
499
|
+
throw new SwitcherError(404, "model_not_configured", "This model has no saved metadata. Use models add to configure a catalog model; remote catalog entries cannot be deleted locally.");
|
|
500
|
+
const useManual = manual || !additional && (provider.manualModels.length > 0 || provider.catalogFormat === "none");
|
|
501
|
+
const manualModels = provider.manualModels.filter((item) => item.id !== id);
|
|
502
|
+
const additionalModels = (provider.additionalModels ?? []).filter((item) => item.id !== id);
|
|
503
|
+
if (operation !== "remove")
|
|
504
|
+
(useManual ? manualModels : additionalModels).push(model);
|
|
505
|
+
return this.updateProvider({ ...input, manualModels, additionalModels }, version);
|
|
506
|
+
}
|
|
507
|
+
addModel(providerId, model) {
|
|
508
|
+
return this.editModel(providerId, "add", model);
|
|
509
|
+
}
|
|
510
|
+
updateModel(providerId, model) {
|
|
511
|
+
return this.editModel(providerId, "update", model);
|
|
512
|
+
}
|
|
513
|
+
removeModel(providerId, modelId) {
|
|
514
|
+
return this.editModel(providerId, "remove", modelId);
|
|
515
|
+
}
|
|
486
516
|
refreshModels(id, idempotencyKey) {
|
|
487
517
|
return this.request("POST", `/v1/providers/${encodeURIComponent(id)}/refresh`, {}, { idempotencyKey });
|
|
488
518
|
}
|
package/dist/serve/index.js
CHANGED
|
@@ -62,7 +62,7 @@ function canonicalPolicyJSON(value) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// src/domain.ts
|
|
65
|
-
var VERSION = "0.1.
|
|
65
|
+
var VERSION = "0.1.8";
|
|
66
66
|
var harnessSchema = z2.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
|
|
67
67
|
var protocolSchema = z2.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
|
|
68
68
|
var idSchema = z2.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
|
|
@@ -92,7 +92,7 @@ var expiresOnSchema = z2.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value) =>
|
|
|
92
92
|
return Number.isFinite(day.getTime()) && day.toISOString().slice(0, 10) === value;
|
|
93
93
|
}, "Use a real calendar date in YYYY-MM-DD format.");
|
|
94
94
|
var modelSchema = z2.object({
|
|
95
|
-
id: z2.string().min(1).max(300),
|
|
95
|
+
id: z2.string().min(1).max(300).refine((value) => value === value.trim() && !/[\x00-\x1f\x7f-\x9f]/.test(value), "Use a nonblank model ID without surrounding whitespace or control characters."),
|
|
96
96
|
name: label,
|
|
97
97
|
description: z2.string().max(8000).optional(),
|
|
98
98
|
available: z2.boolean().optional(),
|
|
@@ -757,8 +757,9 @@ var preset = (id2, name, protocols, sources, alias) => parse(providerPresetSchem
|
|
|
757
757
|
var providerPresets = [
|
|
758
758
|
preset("deepseek", "DeepSeek", [
|
|
759
759
|
route("openai-chat", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
|
|
760
|
+
route("openai-responses", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
|
|
760
761
|
route("anthropic-messages", "https://api.deepseek.com/anthropic/v1", { catalogBaseUrl: "https://api.deepseek.com" })
|
|
761
|
-
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models"], "DEEPSEEK_API_KEY"),
|
|
762
|
+
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models", "https://api-docs.deepseek.com/updates/", "https://api-docs.deepseek.com/guides/responses_api/"], "DEEPSEEK_API_KEY"),
|
|
762
763
|
preset("openrouter", "OpenRouter", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, "https://openrouter.ai/api/v1", { catalogAuthStyle: "none" })), ["https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties", "https://openrouter.ai/docs/guides/overview"], "OPENROUTER_API_KEY"),
|
|
763
764
|
preset("anthropic", "Anthropic", [route("anthropic-messages", "https://api.anthropic.com/v1", { authStyle: "x-api-key" })], ["https://platform.claude.com/docs/en/api/overview", "https://platform.claude.com/docs/en/api/models/list"], "ANTHROPIC_API_KEY"),
|
|
764
765
|
preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
|
|
@@ -830,7 +831,7 @@ var openapi_default = {
|
|
|
830
831
|
openapi: "3.0.3",
|
|
831
832
|
info: {
|
|
832
833
|
title: "Switcher API",
|
|
833
|
-
version: "0.1.
|
|
834
|
+
version: "0.1.8",
|
|
834
835
|
description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
|
|
835
836
|
},
|
|
836
837
|
security: [
|
package/openapi.json
CHANGED
package/package.json
CHANGED