@hasna/switcher 0.2.5 → 0.2.7
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 +31 -2
- package/dist/antigravity-config.d.ts +7 -0
- package/dist/bedrock.d.ts +2 -0
- package/dist/cli/index.js +508 -230
- package/dist/domain.d.ts +18 -8
- package/dist/generated/api.d.ts +17 -5
- package/dist/harnesses.d.ts +2 -2
- package/dist/index.js +23 -4
- package/dist/junie-config.d.ts +8 -0
- package/dist/launcher.d.ts +1 -1
- package/dist/mcp/index.js +84 -10
- package/dist/model-policy-schema.d.ts +3 -0
- package/dist/model-policy.d.ts +1 -0
- package/dist/native-cli-settings.d.ts +6 -0
- package/dist/native-model-policy.d.ts +1 -1
- package/dist/sdk.d.ts +18 -9
- package/dist/sdk.js +23 -4
- package/dist/serve/index.js +80 -9
- package/docs/MODEL-POLICY.md +6 -2
- package/openapi.json +53 -1
- package/package.json +1 -1
package/dist/model-policy.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare const MODEL_POLICY_VERSION: 1;
|
|
|
3
3
|
export type ModelRole = "subagent" | "fast" | "planning" | "review" | "summary" | "compaction" | "weak" | "editor";
|
|
4
4
|
export type ModelPolicy = {
|
|
5
5
|
version?: 1;
|
|
6
|
+
selection?: "restricted" | "catalog";
|
|
6
7
|
roles?: Partial<Record<ModelRole, string>>;
|
|
7
8
|
allowedModels?: string[];
|
|
8
9
|
aliases?: Record<string, string>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function nativeHome(env: NodeJS.ProcessEnv): string;
|
|
2
|
+
export declare function readNativeSettings(path: string): Promise<Record<string, any>>;
|
|
3
|
+
export declare function rejectNativeRouting(value: unknown, keys: ReadonlySet<string>): void;
|
|
4
|
+
export declare function writeNativeSettings(path: string, value: unknown): Promise<string>;
|
|
5
|
+
export declare function durableNativeDirectory(root: string, target: string, name: string): Promise<void>;
|
|
6
|
+
export declare function readNativeText(path: string): Promise<string | undefined>;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const nativeRoles: readonly ["main", "subagent", "fast", "planning", "review", "summary", "compaction", "weak", "editor"];
|
|
8
8
|
export type NativeRole = typeof nativeRoles[number];
|
|
9
|
-
export type NativePolicyHarness = "claude" | "codex" | "grok" | "opencode" | "opencode2" | "omp" | "hermes" | "aider" | "kilo" | "gemini" | "cline" | "dsh" | "pi" | "prime-agent";
|
|
9
|
+
export type NativePolicyHarness = "claude" | "codex" | "grok" | "opencode" | "opencode2" | "omp" | "hermes" | "aider" | "kilo" | "gemini" | "cline" | "dsh" | "pi" | "prime-agent" | "antigravity" | "junie";
|
|
10
10
|
export type NativeModelPolicyInput = {
|
|
11
11
|
harness: NativePolicyHarness;
|
|
12
12
|
mainModel: string;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -495,10 +495,11 @@ export declare class SwitcherClient {
|
|
|
495
495
|
id: string;
|
|
496
496
|
name: string;
|
|
497
497
|
providerId: string;
|
|
498
|
-
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
498
|
+
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "antigravity" | "junie" | "aider" | "kilo";
|
|
499
499
|
model: string;
|
|
500
500
|
modelPolicy?: {
|
|
501
501
|
version: 1;
|
|
502
|
+
selection?: "restricted" | "catalog";
|
|
502
503
|
roles?: {
|
|
503
504
|
subagent?: string;
|
|
504
505
|
fast?: string;
|
|
@@ -524,10 +525,11 @@ export declare class SwitcherClient {
|
|
|
524
525
|
id: string;
|
|
525
526
|
name: string;
|
|
526
527
|
providerId: string;
|
|
527
|
-
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
528
|
+
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "antigravity" | "junie" | "aider" | "kilo";
|
|
528
529
|
model: string;
|
|
529
530
|
modelPolicy?: {
|
|
530
531
|
version: 1;
|
|
532
|
+
selection?: "restricted" | "catalog";
|
|
531
533
|
roles?: {
|
|
532
534
|
subagent?: string;
|
|
533
535
|
fast?: string;
|
|
@@ -553,10 +555,11 @@ export declare class SwitcherClient {
|
|
|
553
555
|
id: string;
|
|
554
556
|
name: string;
|
|
555
557
|
providerId: string;
|
|
556
|
-
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
558
|
+
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "antigravity" | "junie" | "aider" | "kilo";
|
|
557
559
|
model: string;
|
|
558
560
|
modelPolicy?: {
|
|
559
561
|
version: 1;
|
|
562
|
+
selection?: "restricted" | "catalog";
|
|
560
563
|
roles?: {
|
|
561
564
|
subagent?: string;
|
|
562
565
|
fast?: string;
|
|
@@ -582,10 +585,11 @@ export declare class SwitcherClient {
|
|
|
582
585
|
id: string;
|
|
583
586
|
name: string;
|
|
584
587
|
providerId: string;
|
|
585
|
-
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
588
|
+
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "antigravity" | "junie" | "aider" | "kilo";
|
|
586
589
|
model: string;
|
|
587
590
|
modelPolicy?: {
|
|
588
591
|
version: 1;
|
|
592
|
+
selection?: "restricted" | "catalog";
|
|
589
593
|
roles?: {
|
|
590
594
|
subagent?: string;
|
|
591
595
|
fast?: string;
|
|
@@ -663,10 +667,11 @@ export declare class SwitcherClient {
|
|
|
663
667
|
id: string;
|
|
664
668
|
name: string;
|
|
665
669
|
providerId: string;
|
|
666
|
-
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
670
|
+
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "antigravity" | "junie" | "aider" | "kilo";
|
|
667
671
|
model: string;
|
|
668
672
|
modelPolicy?: {
|
|
669
673
|
version: 1;
|
|
674
|
+
selection?: "restricted" | "catalog";
|
|
670
675
|
roles?: {
|
|
671
676
|
subagent?: string;
|
|
672
677
|
fast?: string;
|
|
@@ -712,10 +717,11 @@ export declare class SwitcherClient {
|
|
|
712
717
|
listRuns(options?: {}): Promise<Page<{
|
|
713
718
|
modelPolicyVersion?: 1;
|
|
714
719
|
profileId: string;
|
|
715
|
-
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
720
|
+
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "antigravity" | "junie" | "aider" | "kilo";
|
|
716
721
|
model: string;
|
|
717
722
|
modelPolicy?: {
|
|
718
723
|
version: 1;
|
|
724
|
+
selection?: "restricted" | "catalog";
|
|
719
725
|
roles?: {
|
|
720
726
|
subagent?: string;
|
|
721
727
|
fast?: string;
|
|
@@ -762,10 +768,11 @@ export declare class SwitcherClient {
|
|
|
762
768
|
getRun(id: string): Promise<{
|
|
763
769
|
modelPolicyVersion?: 1;
|
|
764
770
|
profileId: string;
|
|
765
|
-
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
771
|
+
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "antigravity" | "junie" | "aider" | "kilo";
|
|
766
772
|
model: string;
|
|
767
773
|
modelPolicy?: {
|
|
768
774
|
version: 1;
|
|
775
|
+
selection?: "restricted" | "catalog";
|
|
769
776
|
roles?: {
|
|
770
777
|
subagent?: string;
|
|
771
778
|
fast?: string;
|
|
@@ -814,10 +821,11 @@ export declare class SwitcherClient {
|
|
|
814
821
|
}, idempotencyKey?: string): Promise<{
|
|
815
822
|
modelPolicyVersion?: 1;
|
|
816
823
|
profileId: string;
|
|
817
|
-
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
824
|
+
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "antigravity" | "junie" | "aider" | "kilo";
|
|
818
825
|
model: string;
|
|
819
826
|
modelPolicy?: {
|
|
820
827
|
version: 1;
|
|
828
|
+
selection?: "restricted" | "catalog";
|
|
821
829
|
roles?: {
|
|
822
830
|
subagent?: string;
|
|
823
831
|
fast?: string;
|
|
@@ -864,10 +872,11 @@ export declare class SwitcherClient {
|
|
|
864
872
|
finishRun(id: string, version: number, input: components["schemas"]["RunUpdate"], idempotencyKey?: string): Promise<{
|
|
865
873
|
modelPolicyVersion?: 1;
|
|
866
874
|
profileId: string;
|
|
867
|
-
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "aider" | "kilo";
|
|
875
|
+
harness: "claude" | "codex" | "grok" | "opencode" | "opencode2" | "pi" | "omp" | "dsh" | "cline" | "hermes" | "prime-agent" | "gemini" | "antigravity" | "junie" | "aider" | "kilo";
|
|
868
876
|
model: string;
|
|
869
877
|
modelPolicy?: {
|
|
870
878
|
version: 1;
|
|
879
|
+
selection?: "restricted" | "catalog";
|
|
871
880
|
roles?: {
|
|
872
881
|
subagent?: string;
|
|
873
882
|
fast?: string;
|
package/dist/sdk.js
CHANGED
|
@@ -21,6 +21,7 @@ var fallbacksSchema = z2.record(policyModelIdSchema, z2.array(policyModelIdSchem
|
|
|
21
21
|
});
|
|
22
22
|
var modelPolicySchema = z2.object({
|
|
23
23
|
version: z2.literal(1).default(1),
|
|
24
|
+
selection: z2.enum(["restricted", "catalog"]).optional(),
|
|
24
25
|
roles: z2.object({
|
|
25
26
|
subagent: policyModelIdSchema.optional(),
|
|
26
27
|
fast: policyModelIdSchema.optional(),
|
|
@@ -51,7 +52,7 @@ var routingEventSchema = z2.object({
|
|
|
51
52
|
}).strict();
|
|
52
53
|
var routingEventsSchema = z2.array(routingEventSchema).max(1000);
|
|
53
54
|
// src/domain.ts
|
|
54
|
-
var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
|
|
55
|
+
var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "antigravity", "junie", "aider", "kilo"]);
|
|
55
56
|
var protocolSchema = z3.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
|
|
56
57
|
var idSchema = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
|
|
57
58
|
var label = z3.string().min(1).max(200);
|
|
@@ -175,7 +176,7 @@ function compatible(harness, protocol) {
|
|
|
175
176
|
return protocol === "anthropic-messages";
|
|
176
177
|
if (harness === "codex")
|
|
177
178
|
return protocol === "openai-responses";
|
|
178
|
-
if (harness === "gemini")
|
|
179
|
+
if (harness === "gemini" || harness === "antigravity")
|
|
179
180
|
return protocol === "gemini-generate-content";
|
|
180
181
|
if (protocol === "gemini-generate-content")
|
|
181
182
|
return false;
|
|
@@ -219,6 +220,19 @@ async function boundedJson(response, maxBytes = MAX_BYTES) {
|
|
|
219
220
|
// src/sdk.ts
|
|
220
221
|
import { createClientTransport } from "@hasna/contracts/client";
|
|
221
222
|
|
|
223
|
+
// src/bedrock.ts
|
|
224
|
+
function bedrockMantleOrigin(value) {
|
|
225
|
+
let url;
|
|
226
|
+
try {
|
|
227
|
+
url = new URL(value);
|
|
228
|
+
} catch {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (url.protocol !== "https:" || url.port || url.username || url.password || url.search || url.hash || url.pathname.replace(/\/+$/, "") !== "/anthropic/v1")
|
|
232
|
+
return;
|
|
233
|
+
return /^bedrock-mantle\.[a-z]{2}(?:-[a-z]+)+-\d+\.api\.aws$/.test(url.hostname) ? url.origin : undefined;
|
|
234
|
+
}
|
|
235
|
+
|
|
222
236
|
// src/presets.ts
|
|
223
237
|
var route = (protocol, baseUrl, options = {}) => ({
|
|
224
238
|
protocol,
|
|
@@ -251,8 +265,10 @@ var providerPresets = [
|
|
|
251
265
|
], ["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"),
|
|
252
266
|
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"),
|
|
253
267
|
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"),
|
|
268
|
+
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"),
|
|
254
269
|
preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
|
|
255
270
|
authStyle: "x-api-key",
|
|
271
|
+
credentialCheck: { method: "GET", path: "models" },
|
|
256
272
|
catalogBaseUrl: "https://generativelanguage.googleapis.com/v1beta",
|
|
257
273
|
catalogFormat: "gemini",
|
|
258
274
|
catalogAuthStyle: "x-api-key",
|
|
@@ -323,16 +339,19 @@ function providerFromPreset(presetId, options = {}) {
|
|
|
323
339
|
const baseUrl = options.baseUrl ?? selected.baseUrl;
|
|
324
340
|
if (!baseUrl)
|
|
325
341
|
throw new Fault(400, "endpoint_required", "This preset requires an explicit --url for its inference endpoint.");
|
|
342
|
+
const bedrockOrigin = presetId === "bedrock" ? bedrockMantleOrigin(endpoint(baseUrl)) : undefined;
|
|
343
|
+
if (presetId === "bedrock" && !bedrockOrigin)
|
|
344
|
+
throw new Fault(400, "invalid_url", "Bedrock requires a regional HTTPS Mantle endpoint ending in /anthropic/v1.");
|
|
326
345
|
if (presetId === "azure-openai" && !/\/openai\/v1$/.test(endpoint(baseUrl)))
|
|
327
346
|
throw new Fault(400, "invalid_url", "Azure OpenAI v1 requires an explicit endpoint ending in /openai/v1; deployment and api-version URLs are unsupported.");
|
|
328
347
|
if (options.baseUrl && selected.baseUrl && new URL(endpoint(options.baseUrl)).origin !== new URL(selected.baseUrl).origin && preset2.credentialEnv && !options.credentialEnv)
|
|
329
348
|
throw new Fault(422, "credential_authority", "An endpoint on another origin requires an explicit --credential-env reference.");
|
|
330
|
-
const suffix = selected.protocol === "anthropic-messages" ? "messages" : selected.protocol === "openai-responses" ? "responses" : "chat";
|
|
349
|
+
const suffix = selected.protocol === "anthropic-messages" ? "messages" : selected.protocol === "openai-responses" ? "responses" : selected.protocol === "gemini-generate-content" ? "generate-content" : "chat";
|
|
331
350
|
if (presetId === "fireworks" && !options.catalogBaseUrl && !options.catalogAccountId)
|
|
332
351
|
throw new Fault(400, "catalog_account_required", "Fireworks model discovery requires --catalog-account-id or an explicit --catalog-url.");
|
|
333
352
|
if (selected.catalogFormat === "none" && options.catalogFormat && options.catalogFormat !== "none" && !options.catalogBaseUrl)
|
|
334
353
|
throw new Fault(400, "catalog_url_required", "This preset requires an explicit --catalog-url when enabling a catalog parser.");
|
|
335
|
-
const catalogBaseUrl = options.catalogBaseUrl ?? (presetId === "fireworks" && options.catalogAccountId ? `https://api.fireworks.ai/v1/accounts/${encodeURIComponent(options.catalogAccountId)}` : options.baseUrl ? undefined : selected.catalogBaseUrl);
|
|
354
|
+
const catalogBaseUrl = options.catalogBaseUrl ?? (bedrockOrigin ? `${bedrockOrigin}/v1` : presetId === "fireworks" && options.catalogAccountId ? `https://api.fireworks.ai/v1/accounts/${encodeURIComponent(options.catalogAccountId)}` : options.baseUrl ? undefined : selected.catalogBaseUrl);
|
|
336
355
|
return parse(providerInputSchema, {
|
|
337
356
|
id: options.id ?? `${preset2.id}-${suffix}`,
|
|
338
357
|
name: preset2.name,
|
package/dist/serve/index.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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: {
|
|
@@ -5197,7 +5268,7 @@ function createHandler(store, authentication, providerEnv = process.env, resolve
|
|
|
5197
5268
|
}
|
|
5198
5269
|
if (resource === "providers" && id2 && parts[3] === "refresh" && parts.length === 4 && request.method === "POST") {
|
|
5199
5270
|
if (store.engine === "postgresql")
|
|
5200
|
-
await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR
|
|
5271
|
+
await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR UPDATE", [id2]);
|
|
5201
5272
|
const provider = await store.get("providers", id2, db);
|
|
5202
5273
|
if (!refreshed || provider.version !== refreshed.provider.version)
|
|
5203
5274
|
throw new Fault(409, "provider_changed", "Provider changed during discovery; refresh again.");
|
|
@@ -5214,7 +5285,7 @@ function createHandler(store, authentication, providerEnv = process.env, resolve
|
|
|
5214
5285
|
}
|
|
5215
5286
|
if (resource === "providers" && id2 && parts[3] === "catalog" && parts.length === 4 && request.method === "PUT") {
|
|
5216
5287
|
if (store.engine === "postgresql")
|
|
5217
|
-
await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR
|
|
5288
|
+
await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR UPDATE", [id2]);
|
|
5218
5289
|
const provider = await store.get("providers", id2, db);
|
|
5219
5290
|
if (provider.version !== version())
|
|
5220
5291
|
throw new Fault(409, "provider_changed", "Provider changed during local discovery; refresh again.");
|
package/docs/MODEL-POLICY.md
CHANGED
|
@@ -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.
|
|
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
|
|
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.
|
|
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": {
|