@hasna/switcher 0.2.6 → 0.2.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.
@@ -34,6 +34,7 @@ var fallbacksSchema = z2.record(policyModelIdSchema, z2.array(policyModelIdSchem
34
34
  });
35
35
  var modelPolicySchema = z2.object({
36
36
  version: z2.literal(1).default(1),
37
+ selection: z2.enum(["restricted", "catalog"]).optional(),
37
38
  roles: z2.object({
38
39
  subagent: policyModelIdSchema.optional(),
39
40
  fast: policyModelIdSchema.optional(),
@@ -68,8 +69,8 @@ function canonicalPolicyJSON(value) {
68
69
  }
69
70
 
70
71
  // src/domain.ts
71
- var VERSION = "0.2.6";
72
- var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
72
+ var VERSION = "0.2.7";
73
+ var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "antigravity", "junie", "aider", "kilo"]);
73
74
  var protocolSchema = z3.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
74
75
  var idSchema = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
75
76
  var label = z3.string().min(1).max(200);
@@ -193,7 +194,7 @@ function compatible(harness, protocol) {
193
194
  return protocol === "anthropic-messages";
194
195
  if (harness === "codex")
195
196
  return protocol === "openai-responses";
196
- if (harness === "gemini")
197
+ if (harness === "gemini" || harness === "antigravity")
197
198
  return protocol === "gemini-generate-content";
198
199
  if (protocol === "gemini-generate-content")
199
200
  return false;
@@ -202,7 +203,7 @@ function compatible(harness, protocol) {
202
203
  function validateHarnessProvider(harness, provider) {
203
204
  if (!compatible(harness, provider.protocol))
204
205
  throw new Fault(422, "protocol_mismatch", "Harness does not support this provider protocol.");
205
- if (harness === "gemini" && provider.authStyle !== "x-api-key")
206
+ if ((harness === "gemini" || harness === "antigravity") && provider.authStyle !== "x-api-key")
206
207
  throw new Fault(422, "auth_mismatch", "Gemini CLI requires x-api-key authentication for its native generateContent protocol.");
207
208
  }
208
209
  function modelExpired(model, now = new Date) {
@@ -468,6 +469,19 @@ function authHeader(style, credential) {
468
469
  return style === "bearer" ? ["authorization", `Bearer ${credential}`] : [style, credential];
469
470
  }
470
471
 
472
+ // src/bedrock.ts
473
+ function bedrockMantleOrigin(value) {
474
+ let url;
475
+ try {
476
+ url = new URL(value);
477
+ } catch {
478
+ return;
479
+ }
480
+ if (url.protocol !== "https:" || url.port || url.username || url.password || url.search || url.hash || url.pathname.replace(/\/+$/, "") !== "/anthropic/v1")
481
+ return;
482
+ return /^bedrock-mantle\.[a-z]{2}(?:-[a-z]+)+-\d+\.api\.aws$/.test(url.hostname) ? url.origin : undefined;
483
+ }
484
+
471
485
  // src/catalog.ts
472
486
  var positive = (v) => typeof v === "number" && Number.isInteger(v) && v > 0 ? v : undefined;
473
487
  var strings = (v) => Array.isArray(v) && v.every((i) => typeof i === "string") ? v : undefined;
@@ -604,6 +618,8 @@ async function discoverBase(provider, env = process.env, resolveCredential) {
604
618
  reasoningEfforts: row.reasoning?.supported_efforts,
605
619
  ...provider.catalogFormat === "gemini" && row.supportedGenerationMethods !== undefined ? { supportedGenerationMethods: row.supportedGenerationMethods } : {}
606
620
  };
621
+ if (provider.protocol === "anthropic-messages" && bedrockMantleOrigin(provider.baseUrl) && !id.startsWith("anthropic."))
622
+ candidate.available = false;
607
623
  if (provider.catalogFormat === "mistral") {
608
624
  const capabilities = row.capabilities;
609
625
  if (typeof capabilities?.function_calling === "boolean")
@@ -769,6 +785,7 @@ function compileModelPolicy(model, catalog, policy) {
769
785
  throw new Fault(400, "invalid_model_policy", "Model policy allowedModels is too large.");
770
786
  for (const value of explicitAllowed)
771
787
  requireAvailable(value, "An allowed model is not present in the eligible catalog.");
788
+ const catalogAllowed = p.selection === "catalog" ? [...available] : [];
772
789
  const aliases = Object.create(null);
773
790
  for (const [name, target] of Object.entries(p.aliases ?? {})) {
774
791
  if (Object.keys(aliases).length >= 200 || !/^[A-Za-z0-9._/-]{1,120}$/.test(name) || ["__proto__", "prototype", "constructor"].includes(name))
@@ -780,7 +797,7 @@ function compileModelPolicy(model, catalog, policy) {
780
797
  aliases[name] = canonical;
781
798
  }
782
799
  const fallbacks = Object.create(null);
783
- const allowedSources = new Set([selected, ...Object.values(compiledRoles), ...explicitAllowed]);
800
+ const allowedSources = new Set([selected, ...Object.values(compiledRoles), ...explicitAllowed, ...catalogAllowed]);
784
801
  for (const [source, targets] of Object.entries(p.fallbacks ?? {})) {
785
802
  if (!allowedSources.has(source) || !available.has(source) || !Array.isArray(targets) || Object.keys(fallbacks).length >= 200 || targets.length > 20)
786
803
  throw new Fault(400, "invalid_model_policy", "Fallback source or list is invalid.");
@@ -791,7 +808,7 @@ function compileModelPolicy(model, catalog, policy) {
791
808
  throw new Fault(400, "invalid_model_policy", "A model cannot fall back to itself.");
792
809
  fallbacks[source] = uniq(values);
793
810
  }
794
- const allowedModels = uniq([selected, ...Object.values(compiledRoles), ...explicitAllowed, ...Object.values(fallbacks).flat()]).sort();
811
+ const allowedModels = uniq([selected, ...Object.values(compiledRoles), ...explicitAllowed, ...catalogAllowed, ...Object.values(fallbacks).flat()]).sort();
795
812
  if (Object.values(aliases).some((value) => !allowedModels.includes(value)))
796
813
  throw new Fault(422, "model_not_allowed", "A model alias target must be explicitly allowed by the launch policy.");
797
814
  const result = { version: 1, model: selected, roles: compiledRoles, allowedModels, aliases, fallbacks };
@@ -830,8 +847,10 @@ var providerPresets = [
830
847
  ], ["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"),
831
848
  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"),
832
849
  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"),
850
+ preset("bedrock", "Amazon Bedrock (Mantle)", [route("anthropic-messages", undefined, { authStyle: "x-api-key", catalogAuthStyle: "bearer", notes: ["Pass the regional https://bedrock-mantle.<region>.api.aws/anthropic/v1 endpoint and a Bedrock API key. The authenticated catalog is /v1/models on that same origin. Model access and regional availability remain controlled by the AWS account; this route does not distribute or inherit AWS administrative credentials."] })], ["https://docs.aws.amazon.com/bedrock/latest/userguide/inference-messages-api.html", "https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys.html"], "AWS_BEARER_TOKEN_BEDROCK"),
833
851
  preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
834
852
  authStyle: "x-api-key",
853
+ credentialCheck: { method: "GET", path: "models" },
835
854
  catalogBaseUrl: "https://generativelanguage.googleapis.com/v1beta",
836
855
  catalogFormat: "gemini",
837
856
  catalogAuthStyle: "x-api-key",
@@ -899,7 +918,7 @@ var openapi_default = {
899
918
  openapi: "3.0.3",
900
919
  info: {
901
920
  title: "Switcher API",
902
- version: "0.2.6",
921
+ version: "0.2.7",
903
922
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
904
923
  },
905
924
  security: [
@@ -2972,6 +2991,8 @@ var openapi_default = {
2972
2991
  "hermes",
2973
2992
  "prime-agent",
2974
2993
  "gemini",
2994
+ "antigravity",
2995
+ "junie",
2975
2996
  "aider",
2976
2997
  "kilo"
2977
2998
  ]
@@ -2991,6 +3012,13 @@ var openapi_default = {
2991
3012
  ],
2992
3013
  default: 1
2993
3014
  },
3015
+ selection: {
3016
+ type: "string",
3017
+ enum: [
3018
+ "restricted",
3019
+ "catalog"
3020
+ ]
3021
+ },
2994
3022
  roles: {
2995
3023
  type: "object",
2996
3024
  properties: {
@@ -3121,6 +3149,8 @@ var openapi_default = {
3121
3149
  "hermes",
3122
3150
  "prime-agent",
3123
3151
  "gemini",
3152
+ "antigravity",
3153
+ "junie",
3124
3154
  "aider",
3125
3155
  "kilo"
3126
3156
  ]
@@ -3140,6 +3170,13 @@ var openapi_default = {
3140
3170
  ],
3141
3171
  default: 1
3142
3172
  },
3173
+ selection: {
3174
+ type: "string",
3175
+ enum: [
3176
+ "restricted",
3177
+ "catalog"
3178
+ ]
3179
+ },
3143
3180
  roles: {
3144
3181
  type: "object",
3145
3182
  properties: {
@@ -3350,6 +3387,13 @@ var openapi_default = {
3350
3387
  ],
3351
3388
  default: 1
3352
3389
  },
3390
+ selection: {
3391
+ type: "string",
3392
+ enum: [
3393
+ "restricted",
3394
+ "catalog"
3395
+ ]
3396
+ },
3353
3397
  roles: {
3354
3398
  type: "object",
3355
3399
  properties: {
@@ -4119,6 +4163,8 @@ var openapi_default = {
4119
4163
  "hermes",
4120
4164
  "prime-agent",
4121
4165
  "gemini",
4166
+ "antigravity",
4167
+ "junie",
4122
4168
  "aider",
4123
4169
  "kilo"
4124
4170
  ]
@@ -4138,6 +4184,13 @@ var openapi_default = {
4138
4184
  ],
4139
4185
  default: 1
4140
4186
  },
4187
+ selection: {
4188
+ type: "string",
4189
+ enum: [
4190
+ "restricted",
4191
+ "catalog"
4192
+ ]
4193
+ },
4141
4194
  roles: {
4142
4195
  type: "object",
4143
4196
  properties: {
@@ -4411,6 +4464,8 @@ var openapi_default = {
4411
4464
  "hermes",
4412
4465
  "prime-agent",
4413
4466
  "gemini",
4467
+ "antigravity",
4468
+ "junie",
4414
4469
  "aider",
4415
4470
  "kilo"
4416
4471
  ]
@@ -4430,6 +4485,13 @@ var openapi_default = {
4430
4485
  ],
4431
4486
  default: 1
4432
4487
  },
4488
+ selection: {
4489
+ type: "string",
4490
+ enum: [
4491
+ "restricted",
4492
+ "catalog"
4493
+ ]
4494
+ },
4433
4495
  roles: {
4434
4496
  type: "object",
4435
4497
  properties: {
@@ -4676,6 +4738,8 @@ var openapi_default = {
4676
4738
  "hermes",
4677
4739
  "prime-agent",
4678
4740
  "gemini",
4741
+ "antigravity",
4742
+ "junie",
4679
4743
  "aider",
4680
4744
  "kilo"
4681
4745
  ]
@@ -4695,6 +4759,13 @@ var openapi_default = {
4695
4759
  ],
4696
4760
  default: 1
4697
4761
  },
4762
+ selection: {
4763
+ type: "string",
4764
+ enum: [
4765
+ "restricted",
4766
+ "catalog"
4767
+ ]
4768
+ },
4698
4769
  roles: {
4699
4770
  type: "object",
4700
4771
  properties: {
@@ -19,7 +19,7 @@ switcher launch claude --provider deepseek --model deepseek-v4-flash
19
19
 
20
20
  The guidance identifies the main session model, the current request model, role assignments, permitted IDs, and the full catalog file. It tells the model to use exact provider IDs instead of remembered harness defaults such as Opus. Switcher appends its own block to native instructions; it preserves user messages, tool turns, media, and existing instruction metadata. It refreshes that block on resumed requests and supported token-count/compaction operations.
21
21
 
22
- Prompt following is probabilistic. Switcher also enforces the model policy at a per-launch authenticated loopback gateway. A request for an unapproved model fails before it reaches the provider. The default permitted set contains only the selected main model. Native child/utility model slots are pinned where supported, so ordinary launches do not require manual environment variables.
22
+ Prompt following is probabilistic. Switcher also enforces the model policy at a per-launch authenticated loopback gateway. A request for an unapproved model fails before it reaches the provider. New direct Codex launches use `selection: "catalog"`, which permits the authenticated eligible catalog snapshot for native model switching. Other launches default to the selected main model; existing saved policies keep their restrictions. Native child/utility model slots are pinned where supported, so ordinary launches do not require manual environment variables.
23
23
 
24
24
  # Assigning roles
25
25
 
@@ -46,7 +46,9 @@ A policy file has this shape; replace the example IDs with your provider's exact
46
46
 
47
47
  Unassigned roles default to the main model. The permitted set combines main, assigned roles, explicit allowed IDs, and fallback targets. All must be present in the eligible catalog. Aliases must point into that permitted set and cannot shadow another real model ID.
48
48
 
49
- The complete provider catalog remains visible in each supported native catalog interface. Visibility does not grant permission to use every entry: add intended alternatives to `allowedModels` or launch again with `--model`. This prevents an agent from choosing a familiar but unintended model from a large provider catalog.
49
+ The Codex picker contains exactly the models allowed by the launch policy. A policy with `"selection": "catalog"` permits all available, unexpired models in the eligible catalog snapshot. `"selection": "restricted"` (also the default for a policy that omits this field) permits main, role assignments and explicit allowed/fallback IDs. Native child and utility role defaults remain pinned to main even when session model switching is enabled.
50
+
51
+ Other native catalog interfaces may also show unavailable or built-in choices; visibility alone does not grant routing permission. Antigravity and Junie launch with one managed custom model profile; their built-in provider models do not inherit a provider credential.
50
52
 
51
53
  # Native controls
52
54
 
@@ -60,6 +62,8 @@ The complete provider catalog remains visible in each supported native catalog i
60
62
  | OMP | Fast (`smol`), planning (`slow` and `plan`). |
61
63
  | Hermes | Delegation plus verified auxiliary tasks: compression, title/profile description, review, planning triage, approval, skills, MCP, session search and web extraction. Auxiliary custom-provider settings use the selected protocol and loopback credential. |
62
64
  | Gemini CLI 0.58 | Codebase investigator, fast helpers, summarizers, compression, classifier and edit helpers; native default fallback chains terminate at the selected model. Existing generation/tool settings are retained. |
65
+ | Antigravity CLI 1.2.5 | Verified native Flash Lite helper requests route to `fast`, which defaults to main. The custom main model uses its exact Gemini API ID. |
66
+ | Junie build 3196.5 | Custom profile `primaryModel` and `fasterModel`; `fast` defaults to main. |
63
67
  | Aider | Weak and editor models. |
64
68
  | Kilo | Weak/small and subagent models. |
65
69
  | Pi, DeepSeek Harness, Cline, Prime Agent | Selected main model and gateway enforcement; no separate role assignments are advertised. |
package/openapi.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.0.3",
3
3
  "info": {
4
4
  "title": "Switcher API",
5
- "version": "0.2.6",
5
+ "version": "0.2.7",
6
6
  "description": "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
7
7
  },
8
8
  "security": [
@@ -2075,6 +2075,8 @@
2075
2075
  "hermes",
2076
2076
  "prime-agent",
2077
2077
  "gemini",
2078
+ "antigravity",
2079
+ "junie",
2078
2080
  "aider",
2079
2081
  "kilo"
2080
2082
  ]
@@ -2094,6 +2096,13 @@
2094
2096
  ],
2095
2097
  "default": 1
2096
2098
  },
2099
+ "selection": {
2100
+ "type": "string",
2101
+ "enum": [
2102
+ "restricted",
2103
+ "catalog"
2104
+ ]
2105
+ },
2097
2106
  "roles": {
2098
2107
  "type": "object",
2099
2108
  "properties": {
@@ -2224,6 +2233,8 @@
2224
2233
  "hermes",
2225
2234
  "prime-agent",
2226
2235
  "gemini",
2236
+ "antigravity",
2237
+ "junie",
2227
2238
  "aider",
2228
2239
  "kilo"
2229
2240
  ]
@@ -2243,6 +2254,13 @@
2243
2254
  ],
2244
2255
  "default": 1
2245
2256
  },
2257
+ "selection": {
2258
+ "type": "string",
2259
+ "enum": [
2260
+ "restricted",
2261
+ "catalog"
2262
+ ]
2263
+ },
2246
2264
  "roles": {
2247
2265
  "type": "object",
2248
2266
  "properties": {
@@ -2453,6 +2471,13 @@
2453
2471
  ],
2454
2472
  "default": 1
2455
2473
  },
2474
+ "selection": {
2475
+ "type": "string",
2476
+ "enum": [
2477
+ "restricted",
2478
+ "catalog"
2479
+ ]
2480
+ },
2456
2481
  "roles": {
2457
2482
  "type": "object",
2458
2483
  "properties": {
@@ -3222,6 +3247,8 @@
3222
3247
  "hermes",
3223
3248
  "prime-agent",
3224
3249
  "gemini",
3250
+ "antigravity",
3251
+ "junie",
3225
3252
  "aider",
3226
3253
  "kilo"
3227
3254
  ]
@@ -3241,6 +3268,13 @@
3241
3268
  ],
3242
3269
  "default": 1
3243
3270
  },
3271
+ "selection": {
3272
+ "type": "string",
3273
+ "enum": [
3274
+ "restricted",
3275
+ "catalog"
3276
+ ]
3277
+ },
3244
3278
  "roles": {
3245
3279
  "type": "object",
3246
3280
  "properties": {
@@ -3514,6 +3548,8 @@
3514
3548
  "hermes",
3515
3549
  "prime-agent",
3516
3550
  "gemini",
3551
+ "antigravity",
3552
+ "junie",
3517
3553
  "aider",
3518
3554
  "kilo"
3519
3555
  ]
@@ -3533,6 +3569,13 @@
3533
3569
  ],
3534
3570
  "default": 1
3535
3571
  },
3572
+ "selection": {
3573
+ "type": "string",
3574
+ "enum": [
3575
+ "restricted",
3576
+ "catalog"
3577
+ ]
3578
+ },
3536
3579
  "roles": {
3537
3580
  "type": "object",
3538
3581
  "properties": {
@@ -3779,6 +3822,8 @@
3779
3822
  "hermes",
3780
3823
  "prime-agent",
3781
3824
  "gemini",
3825
+ "antigravity",
3826
+ "junie",
3782
3827
  "aider",
3783
3828
  "kilo"
3784
3829
  ]
@@ -3798,6 +3843,13 @@
3798
3843
  ],
3799
3844
  "default": 1
3800
3845
  },
3846
+ "selection": {
3847
+ "type": "string",
3848
+ "enum": [
3849
+ "restricted",
3850
+ "catalog"
3851
+ ]
3852
+ },
3801
3853
  "roles": {
3802
3854
  "type": "object",
3803
3855
  "properties": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/switcher",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "type": "module",
5
5
  "description": "Universal provider and model switcher for coding harnesses with an API, SDK and self-hosted storage",
6
6
  "license": "Apache-2.0",