@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/dist/mcp/index.js CHANGED
@@ -69,7 +69,7 @@ function canonicalPolicyJSON(value) {
69
69
  }
70
70
 
71
71
  // src/domain.ts
72
- var VERSION = "0.2.0";
72
+ var VERSION = "0.2.2";
73
73
  var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
74
74
  var protocolSchema = z3.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
75
75
  var idSchema = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
@@ -94,6 +94,8 @@ var urlSchema = z3.string().max(2000).superRefine((v, ctx) => {
94
94
  ctx.addIssue({ code: "custom", message: "Invalid endpoint URL" });
95
95
  }
96
96
  }).transform(endpoint);
97
+ var credentialCheckPath = z3.string().min(1).max(200).regex(/^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$/).refine((value) => !value.startsWith("/") && !value.split("/").some((part) => part === "." || part === ".."), "credentialCheck.path must be relative without dot segments");
98
+ var credentialCheckSchema = z3.object({ method: z3.enum(["GET", "HEAD"]).default("GET"), path: credentialCheckPath }).strict();
97
99
  var expiresOnSchema = z3.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value) => {
98
100
  const day = new Date(`${value}T00:00:00.000Z`);
99
101
  return Number.isFinite(day.getTime()) && day.toISOString().slice(0, 10) === value;
@@ -119,6 +121,7 @@ var providerInputSchema = z3.object({
119
121
  protocol: protocolSchema,
120
122
  credentialEnv: envRef.optional(),
121
123
  authStyle: z3.enum(["bearer", "x-api-key", "api-key"]).default("bearer"),
124
+ credentialCheck: credentialCheckSchema.optional(),
122
125
  catalogBaseUrl: urlSchema.optional(),
123
126
  catalogFormat: z3.enum(["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "gemini", "none"]).optional(),
124
127
  catalogAuthStyle: z3.enum(["bearer", "x-api-key", "api-key", "none"]).optional(),
@@ -137,6 +140,7 @@ var providerPresetSchema = z3.object({
137
140
  protocol: protocolSchema,
138
141
  baseUrl: urlSchema.optional(),
139
142
  authStyle: z3.enum(["bearer", "x-api-key", "api-key"]),
143
+ credentialCheck: credentialCheckSchema.optional(),
140
144
  catalogBaseUrl: urlSchema.optional(),
141
145
  catalogFormat: z3.enum(["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "gemini", "none"]),
142
146
  catalogAuthStyle: z3.enum(["bearer", "x-api-key", "api-key", "none"]).optional(),
@@ -268,12 +272,17 @@ var preset = (id, name, protocols, sources, alias) => parse(providerPresetSchema
268
272
  verification: "documented"
269
273
  });
270
274
  var providerPresets = [
275
+ ...["opencode", "opencode-go"].map((id) => preset(id, id === "opencode" ? "OpenCode Zen" : "OpenCode Go", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, id === "opencode" ? "https://opencode.ai/zen/v1" : "https://opencode.ai/zen/go/v1", {
276
+ authStyle: protocol === "anthropic-messages" ? "x-api-key" : "bearer",
277
+ catalogAuthStyle: "none",
278
+ notes: ["Discovers the full live catalog. Claude requests are adapted to each model's documented native endpoint. Other harnesses require models compatible with their selected protocol. Go requires an active subscription and coding-agent session headers."]
279
+ })), ["https://opencode.ai/docs/zen/", "https://opencode.ai/docs/go/"], "OPENCODE_API_KEY")),
271
280
  preset("deepseek", "DeepSeek", [
272
281
  route("openai-chat", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
273
282
  route("openai-responses", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
274
283
  route("anthropic-messages", "https://api.deepseek.com/anthropic/v1", { catalogBaseUrl: "https://api.deepseek.com" })
275
284
  ], ["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"),
276
- 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"),
285
+ preset("openrouter", "OpenRouter", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, "https://openrouter.ai/api/v1", { catalogAuthStyle: "none", credentialCheck: { method: "GET", path: "key" } })), ["https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties", "https://openrouter.ai/docs/guides/overview"], "OPENROUTER_API_KEY"),
277
286
  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"),
278
287
  preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
279
288
  authStyle: "x-api-key",
@@ -830,7 +839,7 @@ async function discoverBase(provider, env = process.env, resolveCredential) {
830
839
  return { models: provider.manualModels, source: "manual", refreshedAt };
831
840
  if (provider.catalogFormat === "none")
832
841
  throw new Fault(422, "catalog_unsupported", "This provider has no documented model-list contract; configure manual models or an explicit catalog URL and parser.");
833
- const headers = { accept: "application/json" };
842
+ const headers = { accept: "application/json", "user-agent": `hasna-switcher/${VERSION}` };
834
843
  if (provider.catalogFormat === "fireworks" && !provider.catalogBaseUrl && !provider.catalogAccountId)
835
844
  throw new Fault(422, "catalog_account_required", "Fireworks model discovery requires a catalog account ID or an explicit catalog URL.");
836
845
  if (provider.catalogFormat === "fireworks" && !provider.catalogBaseUrl && new URL(provider.baseUrl).origin !== "https://api.fireworks.ai")
@@ -889,6 +898,7 @@ async function discoverBase(provider, env = process.env, resolveCredential) {
889
898
  inputModalities: strings(row.architecture?.input_modalities ?? row.input_modalities) ?? modalities(row.inference_metadata?.request_modality),
890
899
  outputModalities: strings(row.architecture?.output_modalities ?? row.output_modalities) ?? modalities(row.inference_metadata?.response_modality),
891
900
  supportedParameters: strings(row.supported_parameters),
901
+ reasoningEfforts: row.reasoning?.supported_efforts,
892
902
  ...provider.catalogFormat === "gemini" && row.supportedGenerationMethods !== undefined ? { supportedGenerationMethods: row.supportedGenerationMethods } : {}
893
903
  };
894
904
  if (provider.catalogFormat === "mistral") {
@@ -1089,7 +1099,7 @@ var openapi_default = {
1089
1099
  openapi: "3.0.3",
1090
1100
  info: {
1091
1101
  title: "Switcher API",
1092
- version: "0.2.0",
1102
+ version: "0.2.2",
1093
1103
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
1094
1104
  },
1095
1105
  security: [
@@ -2319,6 +2329,29 @@ var openapi_default = {
2319
2329
  "api-key"
2320
2330
  ]
2321
2331
  },
2332
+ credentialCheck: {
2333
+ type: "object",
2334
+ properties: {
2335
+ method: {
2336
+ type: "string",
2337
+ enum: [
2338
+ "GET",
2339
+ "HEAD"
2340
+ ],
2341
+ default: "GET"
2342
+ },
2343
+ path: {
2344
+ type: "string",
2345
+ minLength: 1,
2346
+ maxLength: 200,
2347
+ pattern: "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
2348
+ }
2349
+ },
2350
+ required: [
2351
+ "path"
2352
+ ],
2353
+ additionalProperties: false
2354
+ },
2322
2355
  catalogBaseUrl: {
2323
2356
  type: "string",
2324
2357
  maxLength: 2000
@@ -2428,6 +2461,29 @@ var openapi_default = {
2428
2461
  ],
2429
2462
  default: "bearer"
2430
2463
  },
2464
+ credentialCheck: {
2465
+ type: "object",
2466
+ properties: {
2467
+ method: {
2468
+ type: "string",
2469
+ enum: [
2470
+ "GET",
2471
+ "HEAD"
2472
+ ],
2473
+ default: "GET"
2474
+ },
2475
+ path: {
2476
+ type: "string",
2477
+ minLength: 1,
2478
+ maxLength: 200,
2479
+ pattern: "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
2480
+ }
2481
+ },
2482
+ required: [
2483
+ "path"
2484
+ ],
2485
+ additionalProperties: false
2486
+ },
2431
2487
  catalogBaseUrl: {
2432
2488
  type: "string",
2433
2489
  maxLength: 2000
@@ -2706,6 +2762,29 @@ var openapi_default = {
2706
2762
  ],
2707
2763
  default: "bearer"
2708
2764
  },
2765
+ credentialCheck: {
2766
+ type: "object",
2767
+ properties: {
2768
+ method: {
2769
+ type: "string",
2770
+ enum: [
2771
+ "GET",
2772
+ "HEAD"
2773
+ ],
2774
+ default: "GET"
2775
+ },
2776
+ path: {
2777
+ type: "string",
2778
+ minLength: 1,
2779
+ maxLength: 200,
2780
+ pattern: "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
2781
+ }
2782
+ },
2783
+ required: [
2784
+ "path"
2785
+ ],
2786
+ additionalProperties: false
2787
+ },
2709
2788
  catalogBaseUrl: {
2710
2789
  type: "string",
2711
2790
  maxLength: 2000
@@ -3828,6 +3907,29 @@ var openapi_default = {
3828
3907
  ],
3829
3908
  default: "bearer"
3830
3909
  },
3910
+ credentialCheck: {
3911
+ type: "object",
3912
+ properties: {
3913
+ method: {
3914
+ type: "string",
3915
+ enum: [
3916
+ "GET",
3917
+ "HEAD"
3918
+ ],
3919
+ default: "GET"
3920
+ },
3921
+ path: {
3922
+ type: "string",
3923
+ minLength: 1,
3924
+ maxLength: 200,
3925
+ pattern: "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
3926
+ }
3927
+ },
3928
+ required: [
3929
+ "path"
3930
+ ],
3931
+ additionalProperties: false
3932
+ },
3831
3933
  catalogBaseUrl: {
3832
3934
  type: "string",
3833
3935
  maxLength: 2000
@@ -0,0 +1,30 @@
1
+ type Wire = "messages" | "chat" | "responses" | "gemini";
2
+ type Json = Record<string, any>;
3
+ export type OpenCodeTranslationState = Map<string, string>;
4
+ /** OpenCode owns these two prefixes; custom URLs never inherit this adapter. */
5
+ export declare function openCodeLane(baseUrl: string): "zen" | "go" | undefined;
6
+ /** Native endpoint families documented by OpenCode, not a frozen model list.
7
+ * Their default OpenAI-compatible adapter serves the remaining model families.
8
+ * https://opencode.ai/docs/zen/ and https://opencode.ai/docs/go/
9
+ */
10
+ export declare function openCodeWire(model: string, lane: "zen" | "go"): Wire;
11
+ /** Forward only conversation identifiers, never arbitrary client headers.
12
+ * Switcher identifies itself honestly even when a native user agent is absent.
13
+ */
14
+ export declare function openCodeHeaders(baseUrl: string, source: Headers, body: Json, launchSession: string): Record<string, string>;
15
+ export declare function prepareOpenCodeMessages(baseUrl: string, body: Json, suffix: string, credential?: string, state?: OpenCodeTranslationState): {
16
+ path: string;
17
+ body: Json;
18
+ auth: {
19
+ "x-goog-api-key": string;
20
+ authorization?: undefined;
21
+ } | {
22
+ authorization: string;
23
+ "x-goog-api-key"?: undefined;
24
+ } | {
25
+ "x-goog-api-key"?: undefined;
26
+ authorization?: undefined;
27
+ };
28
+ response(response: Response): Promise<Response>;
29
+ } | undefined;
30
+ export {};
package/dist/presets.d.ts CHANGED
@@ -12,6 +12,10 @@ export declare function getProviderPreset(id: string): {
12
12
  modelsPath: string;
13
13
  notes: string[];
14
14
  baseUrl?: string | undefined;
15
+ credentialCheck?: {
16
+ path: string;
17
+ method: "GET" | "HEAD";
18
+ } | undefined;
15
19
  catalogBaseUrl?: string | undefined;
16
20
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none" | undefined;
17
21
  }[];
@@ -55,6 +59,10 @@ export declare function providerFromPreset(presetId: string, options?: PresetOpt
55
59
  supportedGenerationMethods?: string[] | undefined;
56
60
  }[];
57
61
  credentialEnv?: string | undefined;
62
+ credentialCheck?: {
63
+ path: string;
64
+ method: "GET" | "HEAD";
65
+ } | undefined;
58
66
  catalogBaseUrl?: string | undefined;
59
67
  catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none" | undefined;
60
68
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none" | undefined;
package/dist/sdk.d.ts CHANGED
@@ -73,6 +73,10 @@ export declare class SwitcherClient {
73
73
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
74
74
  baseUrl?: string;
75
75
  authStyle: "bearer" | "x-api-key" | "api-key";
76
+ credentialCheck?: {
77
+ method: "GET" | "HEAD";
78
+ path: string;
79
+ };
76
80
  catalogBaseUrl?: string;
77
81
  catalogFormat: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
78
82
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
@@ -89,6 +93,10 @@ export declare class SwitcherClient {
89
93
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
90
94
  credentialEnv?: string;
91
95
  authStyle: "bearer" | "x-api-key" | "api-key";
96
+ credentialCheck?: {
97
+ method: "GET" | "HEAD";
98
+ path: string;
99
+ };
92
100
  catalogBaseUrl?: string;
93
101
  catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
94
102
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
@@ -133,6 +141,10 @@ export declare class SwitcherClient {
133
141
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
134
142
  credentialEnv?: string;
135
143
  authStyle: "bearer" | "x-api-key" | "api-key";
144
+ credentialCheck?: {
145
+ method: "GET" | "HEAD";
146
+ path: string;
147
+ };
136
148
  catalogBaseUrl?: string;
137
149
  catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
138
150
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
@@ -177,6 +189,10 @@ export declare class SwitcherClient {
177
189
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
178
190
  credentialEnv?: string;
179
191
  authStyle: "bearer" | "x-api-key" | "api-key";
192
+ credentialCheck?: {
193
+ method: "GET" | "HEAD";
194
+ path: string;
195
+ };
180
196
  catalogBaseUrl?: string;
181
197
  catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
182
198
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
@@ -221,6 +237,10 @@ export declare class SwitcherClient {
221
237
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
222
238
  credentialEnv?: string;
223
239
  authStyle: "bearer" | "x-api-key" | "api-key";
240
+ credentialCheck?: {
241
+ method: "GET" | "HEAD";
242
+ path: string;
243
+ };
224
244
  catalogBaseUrl?: string;
225
245
  catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
226
246
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
@@ -272,6 +292,10 @@ export declare class SwitcherClient {
272
292
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
273
293
  credentialEnv?: string;
274
294
  authStyle: "bearer" | "x-api-key" | "api-key";
295
+ credentialCheck?: {
296
+ method: "GET" | "HEAD";
297
+ path: string;
298
+ };
275
299
  catalogBaseUrl?: string;
276
300
  catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
277
301
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
@@ -317,6 +341,10 @@ export declare class SwitcherClient {
317
341
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
318
342
  credentialEnv?: string;
319
343
  authStyle: "bearer" | "x-api-key" | "api-key";
344
+ credentialCheck?: {
345
+ method: "GET" | "HEAD";
346
+ path: string;
347
+ };
320
348
  catalogBaseUrl?: string;
321
349
  catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
322
350
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
@@ -361,6 +389,10 @@ export declare class SwitcherClient {
361
389
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
362
390
  credentialEnv?: string;
363
391
  authStyle: "bearer" | "x-api-key" | "api-key";
392
+ credentialCheck?: {
393
+ method: "GET" | "HEAD";
394
+ path: string;
395
+ };
364
396
  catalogBaseUrl?: string;
365
397
  catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
366
398
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
@@ -566,6 +598,10 @@ export declare class SwitcherClient {
566
598
  protocol: "anthropic-messages" | "openai-responses" | "openai-chat" | "gemini-generate-content";
567
599
  credentialEnv?: string;
568
600
  authStyle: "bearer" | "x-api-key" | "api-key";
601
+ credentialCheck?: {
602
+ method: "GET" | "HEAD";
603
+ path: string;
604
+ };
569
605
  catalogBaseUrl?: string;
570
606
  catalogFormat?: "openai" | "ollama" | "mistral" | "together" | "fireworks" | "dashscope" | "gemini" | "none";
571
607
  catalogAuthStyle?: "bearer" | "x-api-key" | "api-key" | "none";
package/dist/sdk.js CHANGED
@@ -75,6 +75,8 @@ var urlSchema = z3.string().max(2000).superRefine((v, ctx) => {
75
75
  ctx.addIssue({ code: "custom", message: "Invalid endpoint URL" });
76
76
  }
77
77
  }).transform(endpoint);
78
+ var credentialCheckPath = z3.string().min(1).max(200).regex(/^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$/).refine((value) => !value.startsWith("/") && !value.split("/").some((part) => part === "." || part === ".."), "credentialCheck.path must be relative without dot segments");
79
+ var credentialCheckSchema = z3.object({ method: z3.enum(["GET", "HEAD"]).default("GET"), path: credentialCheckPath }).strict();
78
80
  var expiresOnSchema = z3.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value) => {
79
81
  const day = new Date(`${value}T00:00:00.000Z`);
80
82
  return Number.isFinite(day.getTime()) && day.toISOString().slice(0, 10) === value;
@@ -100,6 +102,7 @@ var providerInputSchema = z3.object({
100
102
  protocol: protocolSchema,
101
103
  credentialEnv: envRef.optional(),
102
104
  authStyle: z3.enum(["bearer", "x-api-key", "api-key"]).default("bearer"),
105
+ credentialCheck: credentialCheckSchema.optional(),
103
106
  catalogBaseUrl: urlSchema.optional(),
104
107
  catalogFormat: z3.enum(["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "gemini", "none"]).optional(),
105
108
  catalogAuthStyle: z3.enum(["bearer", "x-api-key", "api-key", "none"]).optional(),
@@ -118,6 +121,7 @@ var providerPresetSchema = z3.object({
118
121
  protocol: protocolSchema,
119
122
  baseUrl: urlSchema.optional(),
120
123
  authStyle: z3.enum(["bearer", "x-api-key", "api-key"]),
124
+ credentialCheck: credentialCheckSchema.optional(),
121
125
  catalogBaseUrl: urlSchema.optional(),
122
126
  catalogFormat: z3.enum(["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "gemini", "none"]),
123
127
  catalogAuthStyle: z3.enum(["bearer", "x-api-key", "api-key", "none"]).optional(),
@@ -234,12 +238,17 @@ var preset = (id, name, protocols, sources, alias) => parse(providerPresetSchema
234
238
  verification: "documented"
235
239
  });
236
240
  var providerPresets = [
241
+ ...["opencode", "opencode-go"].map((id) => preset(id, id === "opencode" ? "OpenCode Zen" : "OpenCode Go", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, id === "opencode" ? "https://opencode.ai/zen/v1" : "https://opencode.ai/zen/go/v1", {
242
+ authStyle: protocol === "anthropic-messages" ? "x-api-key" : "bearer",
243
+ catalogAuthStyle: "none",
244
+ notes: ["Discovers the full live catalog. Claude requests are adapted to each model's documented native endpoint. Other harnesses require models compatible with their selected protocol. Go requires an active subscription and coding-agent session headers."]
245
+ })), ["https://opencode.ai/docs/zen/", "https://opencode.ai/docs/go/"], "OPENCODE_API_KEY")),
237
246
  preset("deepseek", "DeepSeek", [
238
247
  route("openai-chat", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
239
248
  route("openai-responses", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
240
249
  route("anthropic-messages", "https://api.deepseek.com/anthropic/v1", { catalogBaseUrl: "https://api.deepseek.com" })
241
250
  ], ["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"),
242
- 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"),
251
+ preset("openrouter", "OpenRouter", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, "https://openrouter.ai/api/v1", { catalogAuthStyle: "none", credentialCheck: { method: "GET", path: "key" } })), ["https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties", "https://openrouter.ai/docs/guides/overview"], "OPENROUTER_API_KEY"),
243
252
  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"),
244
253
  preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
245
254
  authStyle: "x-api-key",
@@ -330,6 +339,7 @@ function providerFromPreset(presetId, options = {}) {
330
339
  protocol: selected.protocol,
331
340
  credentialEnv: options.credentialEnv ?? preset2.credentialEnv,
332
341
  authStyle: options.authStyle ?? selected.authStyle,
342
+ credentialCheck: selected.credentialCheck,
333
343
  catalogBaseUrl,
334
344
  catalogCredentialEnv: options.catalogCredentialEnv,
335
345
  catalogAuthStyle: options.catalogAuthStyle ?? selected.catalogAuthStyle,
@@ -67,7 +67,7 @@ function canonicalPolicyJSON(value) {
67
67
  }
68
68
 
69
69
  // src/domain.ts
70
- var VERSION = "0.2.0";
70
+ var VERSION = "0.2.2";
71
71
  var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
72
72
  var protocolSchema = z3.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
73
73
  var idSchema = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
@@ -92,6 +92,8 @@ var urlSchema = z3.string().max(2000).superRefine((v, ctx) => {
92
92
  ctx.addIssue({ code: "custom", message: "Invalid endpoint URL" });
93
93
  }
94
94
  }).transform(endpoint);
95
+ var credentialCheckPath = z3.string().min(1).max(200).regex(/^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$/).refine((value) => !value.startsWith("/") && !value.split("/").some((part) => part === "." || part === ".."), "credentialCheck.path must be relative without dot segments");
96
+ var credentialCheckSchema = z3.object({ method: z3.enum(["GET", "HEAD"]).default("GET"), path: credentialCheckPath }).strict();
95
97
  var expiresOnSchema = z3.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value) => {
96
98
  const day = new Date(`${value}T00:00:00.000Z`);
97
99
  return Number.isFinite(day.getTime()) && day.toISOString().slice(0, 10) === value;
@@ -117,6 +119,7 @@ var providerInputSchema = z3.object({
117
119
  protocol: protocolSchema,
118
120
  credentialEnv: envRef.optional(),
119
121
  authStyle: z3.enum(["bearer", "x-api-key", "api-key"]).default("bearer"),
122
+ credentialCheck: credentialCheckSchema.optional(),
120
123
  catalogBaseUrl: urlSchema.optional(),
121
124
  catalogFormat: z3.enum(["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "gemini", "none"]).optional(),
122
125
  catalogAuthStyle: z3.enum(["bearer", "x-api-key", "api-key", "none"]).optional(),
@@ -135,6 +138,7 @@ var providerPresetSchema = z3.object({
135
138
  protocol: protocolSchema,
136
139
  baseUrl: urlSchema.optional(),
137
140
  authStyle: z3.enum(["bearer", "x-api-key", "api-key"]),
141
+ credentialCheck: credentialCheckSchema.optional(),
138
142
  catalogBaseUrl: urlSchema.optional(),
139
143
  catalogFormat: z3.enum(["openai", "ollama", "mistral", "together", "fireworks", "dashscope", "gemini", "none"]),
140
144
  catalogAuthStyle: z3.enum(["bearer", "x-api-key", "api-key", "none"]).optional(),
@@ -486,7 +490,7 @@ async function discoverBase(provider, env = process.env, resolveCredential) {
486
490
  return { models: provider.manualModels, source: "manual", refreshedAt };
487
491
  if (provider.catalogFormat === "none")
488
492
  throw new Fault(422, "catalog_unsupported", "This provider has no documented model-list contract; configure manual models or an explicit catalog URL and parser.");
489
- const headers = { accept: "application/json" };
493
+ const headers = { accept: "application/json", "user-agent": `hasna-switcher/${VERSION}` };
490
494
  if (provider.catalogFormat === "fireworks" && !provider.catalogBaseUrl && !provider.catalogAccountId)
491
495
  throw new Fault(422, "catalog_account_required", "Fireworks model discovery requires a catalog account ID or an explicit catalog URL.");
492
496
  if (provider.catalogFormat === "fireworks" && !provider.catalogBaseUrl && new URL(provider.baseUrl).origin !== "https://api.fireworks.ai")
@@ -545,6 +549,7 @@ async function discoverBase(provider, env = process.env, resolveCredential) {
545
549
  inputModalities: strings(row.architecture?.input_modalities ?? row.input_modalities) ?? modalities(row.inference_metadata?.request_modality),
546
550
  outputModalities: strings(row.architecture?.output_modalities ?? row.output_modalities) ?? modalities(row.inference_metadata?.response_modality),
547
551
  supportedParameters: strings(row.supported_parameters),
552
+ reasoningEfforts: row.reasoning?.supported_efforts,
548
553
  ...provider.catalogFormat === "gemini" && row.supportedGenerationMethods !== undefined ? { supportedGenerationMethods: row.supportedGenerationMethods } : {}
549
554
  };
550
555
  if (provider.catalogFormat === "mistral") {
@@ -761,12 +766,17 @@ var preset = (id2, name, protocols, sources, alias) => parse(providerPresetSchem
761
766
  verification: "documented"
762
767
  });
763
768
  var providerPresets = [
769
+ ...["opencode", "opencode-go"].map((id2) => preset(id2, id2 === "opencode" ? "OpenCode Zen" : "OpenCode Go", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, id2 === "opencode" ? "https://opencode.ai/zen/v1" : "https://opencode.ai/zen/go/v1", {
770
+ authStyle: protocol === "anthropic-messages" ? "x-api-key" : "bearer",
771
+ catalogAuthStyle: "none",
772
+ notes: ["Discovers the full live catalog. Claude requests are adapted to each model's documented native endpoint. Other harnesses require models compatible with their selected protocol. Go requires an active subscription and coding-agent session headers."]
773
+ })), ["https://opencode.ai/docs/zen/", "https://opencode.ai/docs/go/"], "OPENCODE_API_KEY")),
764
774
  preset("deepseek", "DeepSeek", [
765
775
  route("openai-chat", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
766
776
  route("openai-responses", "https://api.deepseek.com", { catalogBaseUrl: "https://api.deepseek.com" }),
767
777
  route("anthropic-messages", "https://api.deepseek.com/anthropic/v1", { catalogBaseUrl: "https://api.deepseek.com" })
768
778
  ], ["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"),
769
- 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"),
779
+ preset("openrouter", "OpenRouter", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, "https://openrouter.ai/api/v1", { catalogAuthStyle: "none", credentialCheck: { method: "GET", path: "key" } })), ["https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties", "https://openrouter.ai/docs/guides/overview"], "OPENROUTER_API_KEY"),
770
780
  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"),
771
781
  preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
772
782
  authStyle: "x-api-key",
@@ -837,7 +847,7 @@ var openapi_default = {
837
847
  openapi: "3.0.3",
838
848
  info: {
839
849
  title: "Switcher API",
840
- version: "0.2.0",
850
+ version: "0.2.2",
841
851
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
842
852
  },
843
853
  security: [
@@ -2067,6 +2077,29 @@ var openapi_default = {
2067
2077
  "api-key"
2068
2078
  ]
2069
2079
  },
2080
+ credentialCheck: {
2081
+ type: "object",
2082
+ properties: {
2083
+ method: {
2084
+ type: "string",
2085
+ enum: [
2086
+ "GET",
2087
+ "HEAD"
2088
+ ],
2089
+ default: "GET"
2090
+ },
2091
+ path: {
2092
+ type: "string",
2093
+ minLength: 1,
2094
+ maxLength: 200,
2095
+ pattern: "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
2096
+ }
2097
+ },
2098
+ required: [
2099
+ "path"
2100
+ ],
2101
+ additionalProperties: false
2102
+ },
2070
2103
  catalogBaseUrl: {
2071
2104
  type: "string",
2072
2105
  maxLength: 2000
@@ -2176,6 +2209,29 @@ var openapi_default = {
2176
2209
  ],
2177
2210
  default: "bearer"
2178
2211
  },
2212
+ credentialCheck: {
2213
+ type: "object",
2214
+ properties: {
2215
+ method: {
2216
+ type: "string",
2217
+ enum: [
2218
+ "GET",
2219
+ "HEAD"
2220
+ ],
2221
+ default: "GET"
2222
+ },
2223
+ path: {
2224
+ type: "string",
2225
+ minLength: 1,
2226
+ maxLength: 200,
2227
+ pattern: "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
2228
+ }
2229
+ },
2230
+ required: [
2231
+ "path"
2232
+ ],
2233
+ additionalProperties: false
2234
+ },
2179
2235
  catalogBaseUrl: {
2180
2236
  type: "string",
2181
2237
  maxLength: 2000
@@ -2454,6 +2510,29 @@ var openapi_default = {
2454
2510
  ],
2455
2511
  default: "bearer"
2456
2512
  },
2513
+ credentialCheck: {
2514
+ type: "object",
2515
+ properties: {
2516
+ method: {
2517
+ type: "string",
2518
+ enum: [
2519
+ "GET",
2520
+ "HEAD"
2521
+ ],
2522
+ default: "GET"
2523
+ },
2524
+ path: {
2525
+ type: "string",
2526
+ minLength: 1,
2527
+ maxLength: 200,
2528
+ pattern: "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
2529
+ }
2530
+ },
2531
+ required: [
2532
+ "path"
2533
+ ],
2534
+ additionalProperties: false
2535
+ },
2457
2536
  catalogBaseUrl: {
2458
2537
  type: "string",
2459
2538
  maxLength: 2000
@@ -3576,6 +3655,29 @@ var openapi_default = {
3576
3655
  ],
3577
3656
  default: "bearer"
3578
3657
  },
3658
+ credentialCheck: {
3659
+ type: "object",
3660
+ properties: {
3661
+ method: {
3662
+ type: "string",
3663
+ enum: [
3664
+ "GET",
3665
+ "HEAD"
3666
+ ],
3667
+ default: "GET"
3668
+ },
3669
+ path: {
3670
+ type: "string",
3671
+ minLength: 1,
3672
+ maxLength: 200,
3673
+ pattern: "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
3674
+ }
3675
+ },
3676
+ required: [
3677
+ "path"
3678
+ ],
3679
+ additionalProperties: false
3680
+ },
3579
3681
  catalogBaseUrl: {
3580
3682
  type: "string",
3581
3683
  maxLength: 2000