@hasna/switcher 0.2.21 → 0.2.22

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/cli/index.js CHANGED
@@ -514,7 +514,7 @@ function canonicalPolicyJSON(value) {
514
514
  return JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b))) : item);
515
515
  }
516
516
  // package.json
517
- var version = "0.2.21";
517
+ var version = "0.2.22";
518
518
 
519
519
  // src/version.ts
520
520
  var VERSION = version;
@@ -1836,6 +1836,17 @@ function claudeContextEnvironment(providerBaseUrl, environment = process.env) {
1836
1836
  return { CLAUDE_CODE_AUTO_COMPACT_WINDOW: "786432" };
1837
1837
  return {};
1838
1838
  }
1839
+ var CLAUDE_ONE_MILLION_CONTEXT = 1e6;
1840
+ function claudeNativeModelId(id, models) {
1841
+ if (/\[1m\]$/i.test(id))
1842
+ return id;
1843
+ const window = models.find((model) => model.id === id)?.contextWindow;
1844
+ return window !== undefined && window >= CLAUDE_ONE_MILLION_CONTEXT ? `${id}[1m]` : id;
1845
+ }
1846
+ var CLAUDE_MODEL_VARIABLES = new Set(["ANTHROPIC_MODEL", "ANTHROPIC_DEFAULT_MODEL", "CLAUDE_CODE_SUBAGENT_MODEL", "ANTHROPIC_DEFAULT_OPUS_MODEL", "ANTHROPIC_DEFAULT_SONNET_MODEL", "ANTHROPIC_DEFAULT_HAIKU_MODEL", "ANTHROPIC_DEFAULT_FABLE_MODEL"]);
1847
+ function claudeNativeModelEnvironment(env, models) {
1848
+ return Object.fromEntries(Object.entries(env ?? {}).map(([name, value]) => [name, CLAUDE_MODEL_VARIABLES.has(name) ? claudeNativeModelId(value, models) : value]));
1849
+ }
1839
1850
 
1840
1851
  // src/opencode-model-policy.ts
1841
1852
  var routeForAgent = (agent) => {
@@ -2570,7 +2581,7 @@ var openapi_default = {
2570
2581
  openapi: "3.0.3",
2571
2582
  info: {
2572
2583
  title: "Switcher API",
2573
- version: "0.2.21",
2584
+ version: "0.2.22",
2574
2585
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
2575
2586
  },
2576
2587
  security: [
@@ -11123,20 +11134,21 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
11123
11134
  return prepareAider(input);
11124
11135
  if (input.harness === "claude") {
11125
11136
  env.ANTHROPIC_BASE_URL = input.baseUrl.replace(/\/v1$/, "");
11126
- Object.assign(env, input.nativePolicy?.env);
11137
+ const nativeModel = (id2) => claudeNativeModelId(id2, input.models);
11138
+ Object.assign(env, claudeNativeModelEnvironment(input.nativePolicy?.env, input.models));
11127
11139
  Object.assign(env, claudeContextEnvironment(providerBaseUrl));
11128
- env.ANTHROPIC_MODEL = input.model;
11129
- env.ANTHROPIC_DEFAULT_MODEL = input.model;
11130
- env.CLAUDE_CODE_SUBAGENT_MODEL = input.compiledPolicy?.roles.subagent ?? input.model;
11140
+ env.ANTHROPIC_MODEL = nativeModel(input.model);
11141
+ env.ANTHROPIC_DEFAULT_MODEL = nativeModel(input.model);
11142
+ env.CLAUDE_CODE_SUBAGENT_MODEL = nativeModel(input.compiledPolicy?.roles.subagent ?? input.model);
11131
11143
  env.ANTHROPIC_API_KEY = "";
11132
11144
  env.ANTHROPIC_AUTH_TOKEN = "";
11133
11145
  env[input.authStyle === "x-api-key" ? "ANTHROPIC_API_KEY" : "ANTHROPIC_AUTH_TOKEN"] = input.credential ?? "switcher-local-no-auth";
11134
- const picker = { modelPicker: { replaceBuiltInOptions: true, options: input.models.map((m) => ({ model: m.id, label: m.name, description: m.description?.slice(0, 300) })) } };
11146
+ const picker = { modelPicker: { replaceBuiltInOptions: true, options: input.models.map((m) => ({ model: nativeModel(m.id), label: m.name, description: m.description?.slice(0, 300) })) } };
11135
11147
  const route2 = input.routeSettingsFile && input.credential ? { env: { ANTHROPIC_BASE_URL: env.ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY: "", ANTHROPIC_AUTH_TOKEN: "", [input.authStyle === "x-api-key" ? "ANTHROPIC_API_KEY" : "ANTHROPIC_AUTH_TOKEN"]: input.credential } } : undefined;
11136
11148
  const file2 = route2 ? await routeJsonFile(input.routeSettingsFile, { ...picker, ...route2 }) : input.sessionDir ? await durableJsonFile(claudeSettingsDirectory(input.sessionDir), "claude-settings", picker) : await jsonFile(input.stateDir, "claude-settings.json", picker);
11137
11149
  configPaths.push(file2);
11138
11150
  warnings.push("Claude managed settings and model allowlists can restrict the generated picker.");
11139
- return { executable, args: ["--settings", file2, "--model", input.model, ...args], env, configPaths, warnings };
11151
+ return { executable, args: ["--settings", file2, "--model", nativeModel(input.model), ...args], env, configPaths, warnings };
11140
11152
  }
11141
11153
  if (input.harness === "codex") {
11142
11154
  const rolePolicy2 = await prepareCodexModelPolicy({ home: input.sharedState?.home, cwd: input.cwd, stateDir: input.stateDir, model: input.model, policy: input.modelPolicy ? { version: 1, ...input.modelPolicy } : undefined, switcherProvider: "switcher", switcherBaseUrl: input.baseUrl });