@hasna/switcher 0.1.9 → 0.2.0

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
@@ -4,7 +4,13 @@
4
4
  // src/mcp.ts
5
5
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
6
6
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
7
- import { z as z4 } from "zod";
7
+ import { z as z5 } from "zod";
8
+
9
+ // src/runtime.ts
10
+ import { randomBytes } from "crypto";
11
+ import { mkdir as mkdir2, lstat } from "fs/promises";
12
+ import { homedir as homedir2 } from "os";
13
+ import { isAbsolute, join, resolve as resolve2 } from "path";
8
14
 
9
15
  // src/domain.ts
10
16
  import { z as z3 } from "zod";
@@ -58,9 +64,12 @@ var routingEventSchema = z2.object({
58
64
  upstreamStatus: z2.number().int().min(100).max(599).optional()
59
65
  }).strict();
60
66
  var routingEventsSchema = z2.array(routingEventSchema).max(1000);
67
+ function canonicalPolicyJSON(value) {
68
+ 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);
69
+ }
61
70
 
62
71
  // src/domain.ts
63
- var VERSION = "0.1.9";
72
+ var VERSION = "0.2.0";
64
73
  var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
65
74
  var protocolSchema = z3.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
66
75
  var idSchema = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
@@ -175,6 +184,32 @@ function parse(schema, value) {
175
184
  throw new Fault(400, "invalid_request", result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; "));
176
185
  return result.data;
177
186
  }
187
+ function compatible(harness, protocol) {
188
+ if (harness === "claude")
189
+ return protocol === "anthropic-messages";
190
+ if (harness === "codex")
191
+ return protocol === "openai-responses";
192
+ if (harness === "gemini")
193
+ return protocol === "gemini-generate-content";
194
+ if (protocol === "gemini-generate-content")
195
+ return false;
196
+ return true;
197
+ }
198
+ function validateHarnessProvider(harness, provider) {
199
+ if (!compatible(harness, provider.protocol))
200
+ throw new Fault(422, "protocol_mismatch", "Harness does not support this provider protocol.");
201
+ if (harness === "gemini" && provider.authStyle !== "x-api-key")
202
+ throw new Fault(422, "auth_mismatch", "Gemini CLI requires x-api-key authentication for its native generateContent protocol.");
203
+ }
204
+ function modelExpired(model, now = new Date) {
205
+ return model.expiresOn !== undefined && now.toISOString().slice(0, 10) > model.expiresOn;
206
+ }
207
+ function codingEligible(model) {
208
+ return !modelExpired(model) && model.available !== false && (!model.supportedGenerationMethods || model.supportedGenerationMethods.includes("generateContent")) && (!model.outputModalities || model.outputModalities.includes("text")) && (!model.supportedParameters || model.supportedParameters.includes("tools"));
209
+ }
210
+ function harnessEligible(model, harness) {
211
+ return !modelExpired(model) && (harness === "aider" ? model.available !== false && (!model.supportedGenerationMethods || model.supportedGenerationMethods.includes("generateContent")) && (!model.inputModalities || model.inputModalities.includes("text")) && (!model.outputModalities || model.outputModalities.includes("text")) : codingEligible(model));
212
+ }
178
213
 
179
214
  // src/http.ts
180
215
  var MAX_BYTES = 16 * 1024 * 1024;
@@ -298,6 +333,12 @@ var providerPresets = [
298
333
  preset("siliconflow", "SiliconFlow", [route("openai-chat", "https://api.siliconflow.cn/v1", { catalogBaseUrl: "https://api.siliconflow.cn/v1", catalogFormat: "openai", notes: ["The official SiliconCloud OpenAPI contract defines GET /models with Bearer auth and data[] model rows; optional type and sub_type filters are available at the upstream endpoint."] })], ["https://github.com/siliconflow/siliconcloud/blob/main/openapi.yaml", "https://docs.siliconflow.cn/docs/userguide/quickstart", "https://docs.siliconflow.cn/docs/api/chat-completions-post"], "SILICONFLOW_API_KEY"),
299
334
  ...["anthropic-messages", "openai-responses", "openai-chat"].map((protocol) => preset(`generic-${protocol}`, `Custom ${protocol}`, [route(protocol)], []))
300
335
  ];
336
+ function getProviderPreset(id) {
337
+ const entry = providerPresets.find((p) => p.id === id);
338
+ if (!entry)
339
+ throw new Fault(404, "preset_not_found", "Unknown provider preset. Use switcher providers presets to list available presets.");
340
+ return structuredClone(entry);
341
+ }
301
342
  // src/desktop-apps.ts
302
343
  import { execFile } from "child_process";
303
344
  import { access, stat } from "fs/promises";
@@ -543,9 +584,4795 @@ function clientFromEnv(env = process.env, options = {}) {
543
584
  return SwitcherClient.fromEnvironment(env, options);
544
585
  }
545
586
 
587
+ // src/store.ts
588
+ var {SQL } = globalThis.Bun;
589
+ import { chmod, mkdir } from "fs/promises";
590
+ import { dirname, resolve } from "path";
591
+ class Store {
592
+ tail = Promise.resolve();
593
+ async exclusive(action) {
594
+ if (this.engine !== "sqlite")
595
+ return action();
596
+ const next = this.tail.then(action, action);
597
+ this.tail = next.catch(() => {});
598
+ return next;
599
+ }
600
+ sql;
601
+ engine;
602
+ constructor(sql, engine) {
603
+ this.sql = sql;
604
+ this.engine = engine;
605
+ }
606
+ static async open(config) {
607
+ if (!!config.databaseUrl === !!config.sqlitePath)
608
+ throw new Fault(500, "storage_config", "Choose exactly one PostgreSQL URL or SQLite path.");
609
+ const engine = config.databaseUrl ? "postgresql" : "sqlite";
610
+ if (config.databaseUrl && !/^postgres(ql)?:\/\//.test(config.databaseUrl))
611
+ throw new Fault(500, "storage_config", "Database URL must use PostgreSQL.");
612
+ const file = config.sqlitePath;
613
+ if (engine === "sqlite" && file !== ":memory:")
614
+ await mkdir(dirname(resolve(file)), { recursive: true, mode: 448 });
615
+ const deadline = Date.now() + 1e4;
616
+ for (let attempt = 0;; attempt++) {
617
+ let sql;
618
+ try {
619
+ sql = engine === "postgresql" ? new SQL(config.databaseUrl) : new SQL({ adapter: "sqlite", filename: file });
620
+ if (engine === "sqlite") {
621
+ await sql.unsafe("PRAGMA busy_timeout = 5000");
622
+ await sql.unsafe("PRAGMA foreign_keys = ON");
623
+ await sql.unsafe("PRAGMA journal_mode = WAL");
624
+ if (file !== ":memory:")
625
+ await chmod(file, 384);
626
+ }
627
+ const store = new Store(sql, engine);
628
+ await store.migrate();
629
+ return store;
630
+ } catch (error) {
631
+ await sql?.close().catch(() => {});
632
+ const code = error?.code;
633
+ if (engine === "sqlite" && ["SQLITE_BUSY", "SQLITE_BUSY_SNAPSHOT", "SQLITE_LOCKED"].includes(code ?? "") && Date.now() < deadline) {
634
+ await new Promise((resolve2) => setTimeout(resolve2, Math.min(200, 20 * (attempt + 1))));
635
+ continue;
636
+ }
637
+ throw new Fault(500, "storage_unavailable", "Database startup failed; check configuration, permissions and other database users.");
638
+ }
639
+ }
640
+ }
641
+ async migrate() {
642
+ await this.sql.begin(async (tx) => {
643
+ if (this.engine === "postgresql")
644
+ await tx.unsafe("SELECT pg_advisory_xact_lock(782034215)");
645
+ await tx.unsafe("CREATE TABLE IF NOT EXISTS switcher_migrations (version INTEGER PRIMARY KEY)");
646
+ const versions = await tx.unsafe("SELECT version FROM switcher_migrations ORDER BY version");
647
+ if (versions.some((v) => v.version > 1))
648
+ throw new Error("Newer database schema");
649
+ if (versions.length)
650
+ return;
651
+ await tx.unsafe("CREATE TABLE switcher_providers (id TEXT PRIMARY KEY, version INTEGER NOT NULL, updated_at TEXT NOT NULL, payload TEXT NOT NULL)");
652
+ await tx.unsafe("CREATE TABLE switcher_profiles (id TEXT PRIMARY KEY, provider_id TEXT NOT NULL REFERENCES switcher_providers(id), version INTEGER NOT NULL, updated_at TEXT NOT NULL, payload TEXT NOT NULL)");
653
+ await tx.unsafe("CREATE TABLE switcher_catalogs (id TEXT PRIMARY KEY REFERENCES switcher_providers(id) ON DELETE CASCADE, version INTEGER NOT NULL, updated_at TEXT NOT NULL, payload TEXT NOT NULL)");
654
+ await tx.unsafe("CREATE TABLE switcher_runs (id TEXT PRIMARY KEY, profile_id TEXT NOT NULL REFERENCES switcher_profiles(id), version INTEGER NOT NULL, updated_at TEXT NOT NULL, payload TEXT NOT NULL)");
655
+ await tx.unsafe("CREATE TABLE switcher_idempotency (key TEXT PRIMARY KEY, fingerprint TEXT NOT NULL, payload TEXT NOT NULL, created_at TEXT NOT NULL)");
656
+ await tx.unsafe("INSERT INTO switcher_migrations(version) VALUES (1)");
657
+ });
658
+ }
659
+ async ready() {
660
+ await this.exclusive(async () => {
661
+ await this.sql.unsafe("SELECT 1");
662
+ });
663
+ }
664
+ async close() {
665
+ await this.tail;
666
+ await this.sql.close();
667
+ }
668
+ async get(kind, id, db = this.sql) {
669
+ if (db === this.sql && this.engine === "sqlite")
670
+ return this.exclusive(() => this.read(kind, id, db));
671
+ return this.read(kind, id, db);
672
+ }
673
+ async read(kind, id, db) {
674
+ const rows = await db.unsafe(`SELECT payload FROM switcher_${kind} WHERE id = $1`, [id]);
675
+ if (!rows.length)
676
+ throw new Fault(404, "not_found", `${kind} entry was not found.`);
677
+ return JSON.parse(rows[0].payload);
678
+ }
679
+ async list(kind, { limit = 100, offset = 0, search = "" } = {}) {
680
+ return this.exclusive(async () => {
681
+ const name = this.engine === "sqlite" ? "json_extract(payload, '$.name')" : "payload::jsonb->>'name'";
682
+ const pattern = `%${search.toLowerCase().replace(/[!%_]/g, (c) => "!" + c)}%`;
683
+ const where = `LOWER(id) LIKE $1 ESCAPE '!' OR LOWER(COALESCE(${name}, '')) LIKE $1 ESCAPE '!'`;
684
+ const total = await this.sql.unsafe(`SELECT COUNT(*) AS total FROM switcher_${kind} WHERE ${where}`, [pattern]);
685
+ const rows = await this.sql.unsafe(`SELECT payload FROM switcher_${kind} WHERE ${where} ORDER BY id LIMIT $2 OFFSET $3`, [pattern, limit, offset]);
686
+ return { data: rows.map((r) => JSON.parse(r.payload)), total: Number(total[0].total), limit, offset };
687
+ });
688
+ }
689
+ async put(kind, input, expectedVersion, db) {
690
+ const now = new Date().toISOString();
691
+ const value = { ...input, version: expectedVersion === undefined ? 1 : expectedVersion + 1, updatedAt: now };
692
+ if (expectedVersion === undefined) {
693
+ const extraColumn = kind === "profiles" ? ", provider_id" : kind === "runs" ? ", profile_id" : "";
694
+ const extraValue = kind === "profiles" ? input.providerId : kind === "runs" ? input.profileId : undefined;
695
+ await db.unsafe(`INSERT INTO switcher_${kind} (id, version, updated_at, payload${extraColumn}) VALUES ($1, $2, $3, $4${extraColumn ? ", $5" : ""})`, [input.id, value.version, now, JSON.stringify(value), ...extraColumn ? [extraValue] : []]);
696
+ } else {
697
+ const extra = kind === "profiles" ? ", provider_id = $4" : "";
698
+ const rows = await db.unsafe(`UPDATE switcher_${kind} SET version = $1, updated_at = $2, payload = $3${extra} WHERE id = $${extra ? 5 : 4} AND version = $${extra ? 6 : 5} RETURNING id`, [value.version, now, JSON.stringify(value), ...extra ? [input.providerId] : [], input.id, expectedVersion]);
699
+ if (!rows.length)
700
+ throw new Fault(409, "version_conflict", "Entry changed or is missing; reload before retrying.");
701
+ }
702
+ return value;
703
+ }
704
+ async remove(kind, id, version, db) {
705
+ const rows = await db.unsafe(`DELETE FROM switcher_${kind} WHERE id = $1 AND version = $2 RETURNING id`, [id, version]);
706
+ if (!rows.length)
707
+ throw new Fault(409, "version_conflict", "Entry changed or is missing; reload before retrying.");
708
+ return { deleted: id };
709
+ }
710
+ async mutate(key, fingerprint, action) {
711
+ return this.exclusive(() => this.transaction(key, fingerprint, action));
712
+ }
713
+ async replay(key, fingerprint) {
714
+ return this.exclusive(async () => {
715
+ const rows = await this.sql.unsafe("SELECT fingerprint, payload FROM switcher_idempotency WHERE key = $1", [key]);
716
+ if (!rows.length)
717
+ return { found: false };
718
+ if (rows[0].fingerprint !== fingerprint)
719
+ throw new Fault(409, "idempotency_conflict", "Idempotency key was already used for a different request.");
720
+ return { found: true, value: JSON.parse(rows[0].payload) };
721
+ });
722
+ }
723
+ async transaction(key, fingerprint, action) {
724
+ try {
725
+ return await this.sql.begin(async (tx) => {
726
+ const inserted = await tx.unsafe("INSERT INTO switcher_idempotency (key, fingerprint, payload, created_at) VALUES ($1, $2, '', $3) ON CONFLICT (key) DO NOTHING RETURNING key", [key, fingerprint, new Date().toISOString()]);
727
+ if (!inserted.length) {
728
+ const rows = await tx.unsafe("SELECT fingerprint, payload FROM switcher_idempotency WHERE key = $1", [key]);
729
+ if (rows[0].fingerprint !== fingerprint)
730
+ throw new Fault(409, "idempotency_conflict", "Idempotency key was already used for a different request.");
731
+ return JSON.parse(rows[0].payload);
732
+ }
733
+ const value = await action(tx);
734
+ await tx.unsafe("UPDATE switcher_idempotency SET payload = $1 WHERE key = $2", [JSON.stringify(value), key]);
735
+ return value;
736
+ });
737
+ } catch (error) {
738
+ if (error instanceof Fault)
739
+ throw error;
740
+ const code = String(this.engine === "postgresql" ? error?.errno : error?.code);
741
+ if (["23505", "23503", "SQLITE_CONSTRAINT", "SQLITE_CONSTRAINT_PRIMARYKEY", "SQLITE_CONSTRAINT_FOREIGNKEY"].includes(code))
742
+ throw new Fault(409, "conflict", "Duplicate entry or an entry still referenced by another resource.");
743
+ throw new Fault(503, "storage_unavailable", "Storage operation failed.");
744
+ }
745
+ }
746
+ }
747
+
748
+ // src/service.ts
749
+ import { createHash as createHash2, timingSafeEqual } from "crypto";
750
+ import { z as z4 } from "zod";
751
+
752
+ // src/auth.ts
753
+ function authHeader(style, credential) {
754
+ if (/[^\x20-\x7e]/.test(credential))
755
+ throw new Error("Provider credential contains invalid header characters.");
756
+ return style === "bearer" ? ["authorization", `Bearer ${credential}`] : [style, credential];
757
+ }
758
+
759
+ // src/catalog.ts
760
+ var positive = (v) => typeof v === "number" && Number.isInteger(v) && v > 0 ? v : undefined;
761
+ var strings = (v) => Array.isArray(v) && v.every((i) => typeof i === "string") ? v : undefined;
762
+ var modalities = (v) => {
763
+ if (v === undefined)
764
+ return;
765
+ if (!Array.isArray(v) || !v.every((i) => typeof i === "string"))
766
+ throw new Fault(502, "invalid_catalog", "Provider returned malformed modality metadata.");
767
+ return v.map((i) => i.toLowerCase());
768
+ };
769
+ var CATALOG_REQUEST_TIMEOUT_MS = 20000;
770
+ var CATALOG_REFRESH_DEADLINE_MS = 60000;
771
+ var CATALOG_MAX_RETRIES = 2;
772
+ var TRANSIENT_CATALOG_STATUSES = new Set([408, 425, 429, 500, 502, 503, 504]);
773
+ function retryAfterMs(value) {
774
+ if (!value)
775
+ return;
776
+ const trimmed = value.trim();
777
+ if (/^\d+$/.test(trimmed)) {
778
+ try {
779
+ const milliseconds = BigInt(trimmed) * 1000n;
780
+ if (milliseconds > BigInt(Number.MAX_SAFE_INTEGER))
781
+ return Number.POSITIVE_INFINITY;
782
+ return Number(milliseconds);
783
+ } catch {
784
+ return Number.POSITIVE_INFINITY;
785
+ }
786
+ }
787
+ const date = Date.parse(trimmed);
788
+ return Number.isNaN(date) ? undefined : Math.max(0, date - Date.now());
789
+ }
790
+ function catalogDeadlineFault() {
791
+ return new Fault(502, "provider_unavailable", "Provider catalog refresh exceeded its bounded deadline.");
792
+ }
793
+ async function waitForCatalogRetry(delayMs, deadline) {
794
+ if (Date.now() + delayMs > deadline)
795
+ throw catalogDeadlineFault();
796
+ if (delayMs > 0)
797
+ await new Promise((resolve2) => setTimeout(resolve2, delayMs));
798
+ }
799
+ async function fetchCatalogPage(url, headers, deadline) {
800
+ for (let retry = 0;; retry++) {
801
+ const remaining = deadline - Date.now();
802
+ if (remaining <= 0)
803
+ throw catalogDeadlineFault();
804
+ let response;
805
+ try {
806
+ response = await fetch(url, {
807
+ headers,
808
+ redirect: "manual",
809
+ signal: AbortSignal.timeout(Math.max(1, Math.min(CATALOG_REQUEST_TIMEOUT_MS, remaining)))
810
+ });
811
+ } catch {
812
+ if (retry >= CATALOG_MAX_RETRIES)
813
+ throw new Fault(502, "provider_unavailable", "Provider catalog request failed.");
814
+ await waitForCatalogRetry(100 * 2 ** retry, deadline);
815
+ continue;
816
+ }
817
+ if (response.ok)
818
+ return response;
819
+ const retryable = TRANSIENT_CATALOG_STATUSES.has(response.status);
820
+ await response.body?.cancel().catch(() => {});
821
+ if (!retryable || retry >= CATALOG_MAX_RETRIES)
822
+ throw new Fault(502, "provider_rejected", `Provider catalog returned HTTP ${response.status}.`);
823
+ const delay = retryAfterMs(response.headers.get("retry-after"));
824
+ await waitForCatalogRetry(delay ?? 100 * 2 ** retry, deadline);
825
+ }
826
+ }
827
+ async function discoverBase(provider, env = process.env, resolveCredential) {
828
+ const refreshedAt = new Date().toISOString();
829
+ if (provider.manualModels.length)
830
+ return { models: provider.manualModels, source: "manual", refreshedAt };
831
+ if (provider.catalogFormat === "none")
832
+ 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" };
834
+ if (provider.catalogFormat === "fireworks" && !provider.catalogBaseUrl && !provider.catalogAccountId)
835
+ throw new Fault(422, "catalog_account_required", "Fireworks model discovery requires a catalog account ID or an explicit catalog URL.");
836
+ if (provider.catalogFormat === "fireworks" && !provider.catalogBaseUrl && new URL(provider.baseUrl).origin !== "https://api.fireworks.ai")
837
+ throw new Fault(422, "catalog_url_required", "A custom Fireworks inference authority requires an explicit catalog URL; its deployment prefix cannot be inferred.");
838
+ const catalogRoot = provider.catalogBaseUrl ?? (provider.catalogFormat === "fireworks" ? `https://api.fireworks.ai/v1/accounts/${encodeURIComponent(provider.catalogAccountId)}` : provider.baseUrl);
839
+ const url = new URL(`${catalogRoot}/${provider.modelsPath}`);
840
+ if (provider.catalogFormat === "fireworks")
841
+ url.searchParams.set("pageSize", "200");
842
+ const authStyle = provider.catalogAuthStyle ?? provider.authStyle;
843
+ const credentialEnv = provider.catalogCredentialEnv ?? provider.credentialEnv;
844
+ if (authStyle !== "none" && credentialEnv) {
845
+ if (url.origin !== new URL(provider.baseUrl).origin && !provider.catalogCredentialEnv)
846
+ throw new Fault(422, "catalog_credential_authority", "A different catalog origin requires an explicit catalog credential reference or catalogAuthStyle: none.");
847
+ const credential = resolveCredential ? await resolveCredential({ ...provider, baseUrl: provider.catalogBaseUrl ?? provider.baseUrl, credentialEnv }) : env[credentialEnv];
848
+ if (!credential)
849
+ throw new Fault(422, "credential_missing", "Provider credential environment variable is not available on the server.");
850
+ if (/[\r\n]/.test(credential))
851
+ throw new Fault(422, "credential_invalid", "Catalog credential contains invalid header characters.");
852
+ const [header, value] = authHeader(authStyle, credential);
853
+ headers[provider.catalogFormat === "gemini" && header === "x-api-key" ? "x-goog-api-key" : header] = value;
854
+ }
855
+ if (provider.protocol === "anthropic-messages" && url.hostname !== "openrouter.ai")
856
+ headers["anthropic-version"] = "2023-06-01";
857
+ if (url.hostname === "openrouter.ai")
858
+ url.searchParams.set("output_modalities", "all");
859
+ const models = new Map;
860
+ const seenCursors = new Set;
861
+ const seenPages = new Set([url.href]);
862
+ const deadline = Date.now() + CATALOG_REFRESH_DEADLINE_MS;
863
+ let fireworksTotal;
864
+ for (let page = 0;page < 100; page++) {
865
+ const response = await fetchCatalogPage(url, headers, deadline);
866
+ const data = await boundedJson(response);
867
+ if (provider.catalogFormat === "fireworks" && data?.totalSize !== undefined) {
868
+ if (typeof data.totalSize !== "number" || !Number.isInteger(data.totalSize) || data.totalSize < 0)
869
+ throw new Fault(502, "invalid_catalog", "Fireworks catalog count metadata is malformed.");
870
+ if (fireworksTotal !== undefined && fireworksTotal !== data.totalSize)
871
+ throw new Fault(502, "incomplete_catalog", "Provider catalog count changed during pagination; retry the refresh.");
872
+ fireworksTotal = data.totalSize;
873
+ }
874
+ const rows = provider.catalogFormat === "together" ? data : provider.catalogFormat === "ollama" ? data?.models : provider.catalogFormat === "fireworks" || provider.catalogFormat === "gemini" ? data?.models : provider.catalogFormat === "dashscope" ? data?.output?.models : data?.data;
875
+ if (!Array.isArray(rows))
876
+ throw new Fault(502, "invalid_catalog", "Expected a provider catalog with a model array matching its configured format.");
877
+ for (const row of rows) {
878
+ const id = provider.catalogFormat === "ollama" ? row?.model ?? row?.name : provider.catalogFormat === "fireworks" ? row?.name : provider.catalogFormat === "gemini" ? typeof row?.name === "string" ? row.name.replace(/^models\//, "") : undefined : provider.catalogFormat === "dashscope" ? row?.model : row?.id;
879
+ if (typeof id !== "string")
880
+ throw new Fault(502, "invalid_catalog", "Catalog entry is missing a model ID.");
881
+ const candidate = {
882
+ id,
883
+ name: row.displayName ?? row.name ?? row.display_name ?? id,
884
+ available: provider.catalogFormat === "mistral" && typeof row.archived === "boolean" ? !row.archived : undefined,
885
+ expiresOn: row.expiresOn ?? row.expires_on,
886
+ description: typeof row.description === "string" ? row.description.slice(0, 8000) : undefined,
887
+ contextWindow: positive(row.context_length ?? row.context_window ?? row.contextLength ?? row.inputTokenLimit ?? row.model_info?.context_window ?? (provider.catalogFormat === "mistral" ? row.max_context_length : undefined)),
888
+ maxOutputTokens: positive(row.top_provider?.max_completion_tokens ?? row.max_output_tokens ?? row.outputTokenLimit ?? row.model_info?.max_output_tokens),
889
+ inputModalities: strings(row.architecture?.input_modalities ?? row.input_modalities) ?? modalities(row.inference_metadata?.request_modality),
890
+ outputModalities: strings(row.architecture?.output_modalities ?? row.output_modalities) ?? modalities(row.inference_metadata?.response_modality),
891
+ supportedParameters: strings(row.supported_parameters),
892
+ ...provider.catalogFormat === "gemini" && row.supportedGenerationMethods !== undefined ? { supportedGenerationMethods: row.supportedGenerationMethods } : {}
893
+ };
894
+ if (provider.catalogFormat === "mistral") {
895
+ const capabilities = row.capabilities;
896
+ if (typeof capabilities?.function_calling === "boolean")
897
+ candidate.supportedParameters = capabilities.function_calling ? ["tools"] : [];
898
+ if (typeof capabilities?.vision === "boolean")
899
+ candidate.inputModalities = capabilities.vision ? ["text", "image"] : ["text"];
900
+ if (typeof capabilities?.completion_chat === "boolean")
901
+ candidate.outputModalities = capabilities.completion_chat ? ["text"] : [];
902
+ }
903
+ if (provider.catalogFormat === "together") {
904
+ const modalities2 = { chat: ["text"], language: ["text"], code: ["text"], image: ["image"], audio: ["audio"], video: ["video"], embedding: ["embedding"], rerank: ["rerank"], moderation: ["classification"] };
905
+ candidate.outputModalities = modalities2[row.type];
906
+ }
907
+ if (provider.catalogFormat === "fireworks") {
908
+ if (row.supportsImageInput === true)
909
+ candidate.inputModalities = ["text", "image"];
910
+ if (typeof row.supportsTools === "boolean")
911
+ candidate.supportedParameters = row.supportsTools ? ["tools"] : [];
912
+ }
913
+ if (provider.catalogFormat === "dashscope") {
914
+ if (row.features !== undefined && !Array.isArray(row.features))
915
+ throw new Fault(502, "invalid_catalog", "DashScope model features metadata is malformed.");
916
+ if (Array.isArray(row.features))
917
+ candidate.supportedParameters = row.features.includes("function-calling") ? ["tools"] : [];
918
+ }
919
+ const parsed = modelSchema.safeParse(candidate);
920
+ if (!parsed.success)
921
+ throw new Fault(502, "invalid_catalog", "Provider returned malformed model metadata.");
922
+ models.set(candidate.id, parsed.data);
923
+ if (models.size > 1e4)
924
+ throw new Fault(502, "catalog_too_large", "Catalog exceeds 10,000 models; configure a narrower endpoint.");
925
+ }
926
+ const next = data.links?.next;
927
+ if (next !== undefined && next !== null) {
928
+ if (typeof next !== "string" || !next || next.length > 2000)
929
+ throw new Fault(502, "invalid_catalog", "Provider returned an invalid catalog continuation link.");
930
+ let target;
931
+ try {
932
+ target = new URL(next, url);
933
+ } catch {
934
+ throw new Fault(502, "invalid_catalog", "Provider returned an invalid catalog continuation link.");
935
+ }
936
+ if (target.origin !== url.origin || target.pathname !== url.pathname || target.username || target.password || target.hash)
937
+ throw new Fault(502, "catalog_credential_authority", "Catalog pagination must stay on its original origin and path.");
938
+ if (url.searchParams.has("output_modalities"))
939
+ target.searchParams.set("output_modalities", url.searchParams.get("output_modalities"));
940
+ if (seenPages.has(target.href))
941
+ throw new Fault(502, "invalid_catalog", "Provider catalog pagination did not advance.");
942
+ seenPages.add(target.href);
943
+ url.href = target.href;
944
+ continue;
945
+ }
946
+ if (provider.catalogFormat === "fireworks" && data.nextPageToken !== undefined && data.nextPageToken !== null) {
947
+ if (typeof data.nextPageToken !== "string" || data.nextPageToken.length > 2000)
948
+ throw new Fault(502, "invalid_catalog", "Provider catalog pagination did not advance.");
949
+ if (data.nextPageToken) {
950
+ if (seenCursors.has(data.nextPageToken))
951
+ throw new Fault(502, "invalid_catalog", "Provider catalog pagination did not advance.");
952
+ seenCursors.add(data.nextPageToken);
953
+ url.searchParams.set("pageToken", data.nextPageToken);
954
+ url.searchParams.set("pageSize", "200");
955
+ continue;
956
+ }
957
+ }
958
+ if (provider.catalogFormat === "fireworks") {
959
+ if (fireworksTotal !== undefined && fireworksTotal !== models.size)
960
+ throw new Fault(502, "incomplete_catalog", "Provider catalog count does not match the collected models; retry the refresh.");
961
+ return { models: [...models.values()], source: "remote", refreshedAt };
962
+ }
963
+ if (provider.catalogFormat === "gemini") {
964
+ const nextPageToken = data.nextPageToken;
965
+ if (nextPageToken !== undefined && nextPageToken !== null) {
966
+ if (typeof nextPageToken !== "string" || nextPageToken.length > 2000)
967
+ throw new Fault(502, "invalid_catalog", "Gemini catalog pagination token is malformed.");
968
+ if (nextPageToken) {
969
+ if (seenCursors.has(nextPageToken))
970
+ throw new Fault(502, "invalid_catalog", "Provider catalog pagination did not advance.");
971
+ seenCursors.add(nextPageToken);
972
+ url.searchParams.set("pageToken", nextPageToken);
973
+ continue;
974
+ }
975
+ }
976
+ return { models: [...models.values()], source: "remote", refreshedAt };
977
+ }
978
+ if (provider.catalogFormat === "dashscope") {
979
+ const output = data.output;
980
+ const total = output?.total;
981
+ const pageNo = output?.page_no;
982
+ const pageSize = output?.page_size;
983
+ if (typeof total !== "number" || !Number.isInteger(total) || total < 0 || typeof pageNo !== "number" || !Number.isInteger(pageNo) || pageNo < 1 || typeof pageSize !== "number" || !Number.isInteger(pageSize) || pageSize < 1)
984
+ throw new Fault(502, "invalid_catalog", "DashScope catalog pagination metadata is malformed.");
985
+ if (models.size < total && pageNo * pageSize < total) {
986
+ const nextPage = pageNo + 1;
987
+ if (seenCursors.has(String(nextPage)))
988
+ throw new Fault(502, "invalid_catalog", "Provider catalog pagination did not advance.");
989
+ seenCursors.add(String(nextPage));
990
+ url.searchParams.set("page_no", String(nextPage));
991
+ url.searchParams.set("page_size", String(pageSize));
992
+ continue;
993
+ }
994
+ if (models.size !== total)
995
+ throw new Fault(502, "incomplete_catalog", "Provider catalog count does not match the collected models; retry the refresh.");
996
+ return { models: [...models.values()], source: "remote", refreshedAt };
997
+ }
998
+ if (provider.catalogFormat === "together" || !data.has_more) {
999
+ if (typeof data.total_count === "number" && data.total_count !== models.size)
1000
+ throw new Fault(502, "incomplete_catalog", "Provider catalog count does not match the collected models; retry the refresh.");
1001
+ return { models: [...models.values()], source: "remote", refreshedAt };
1002
+ }
1003
+ const cursor = data.last_id;
1004
+ if (typeof cursor !== "string" || seenCursors.has(cursor))
1005
+ throw new Fault(502, "invalid_catalog", "Provider catalog pagination did not advance.");
1006
+ seenCursors.add(cursor);
1007
+ url.searchParams.set("after_id", cursor);
1008
+ url.searchParams.set("limit", "1000");
1009
+ }
1010
+ throw new Fault(502, "catalog_too_large", "Provider catalog pagination exceeded 100 pages.");
1011
+ }
1012
+ async function discover(provider, env = process.env, resolveCredential) {
1013
+ const catalog = await discoverBase(provider, env, resolveCredential);
1014
+ const models = new Map(catalog.models.map((model) => [model.id, model]));
1015
+ for (const additional of provider.additionalModels ?? [])
1016
+ models.set(additional.id, { ...models.get(additional.id), ...additional });
1017
+ if (models.size > 1e4)
1018
+ throw new Fault(502, "catalog_too_large", "Combined catalog exceeds 10,000 models.");
1019
+ return { ...catalog, models: [...models.values()] };
1020
+ }
1021
+
1022
+ // src/model-policy.ts
1023
+ import { createHash } from "crypto";
1024
+ var roles = ["subagent", "fast", "planning", "review", "summary", "compaction", "weak", "editor"];
1025
+ var id = (v, label2) => {
1026
+ if (typeof v !== "string" || !v || v.length > 300 || /[\u0000-\u001f\u007f]/.test(v))
1027
+ throw new Fault(400, "invalid_model_policy", `${label2} is invalid.`);
1028
+ return v;
1029
+ };
1030
+ var uniq = (xs) => [...new Set(xs)];
1031
+ function stable(value) {
1032
+ return JSON.stringify(value, (_k, v) => v && typeof v === "object" && !Array.isArray(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a.localeCompare(b))) : v);
1033
+ }
1034
+ function compileModelPolicy(model, catalog, policy) {
1035
+ const selected = id(model, "model");
1036
+ const available = new Set(catalog.filter((m) => m.available !== false && !modelExpired(m)).map((m) => m.id));
1037
+ const expired = new Set(catalog.filter((m) => modelExpired(m)).map((m) => m.id));
1038
+ const requireAvailable = (value, message) => {
1039
+ if (expired.has(value))
1040
+ throw new Fault(422, "model_expired", "A selected model has passed its configured expiry date. Select an unexpired model.");
1041
+ if (!available.has(value))
1042
+ throw new Fault(422, "model_unavailable", message);
1043
+ };
1044
+ requireAvailable(selected, "Selected model is not present in the eligible catalog.");
1045
+ if (policy && policy.version !== undefined && policy.version !== 1)
1046
+ throw new Fault(400, "invalid_model_policy", "Unsupported model policy version.");
1047
+ const p = parse(modelPolicySchema, policy ?? {});
1048
+ const roleInput = p.roles ?? {};
1049
+ if (Object.keys(roleInput).some((k) => !roles.includes(k)))
1050
+ throw new Fault(400, "invalid_model_policy", "Unknown model policy role.");
1051
+ const compiledRoles = Object.fromEntries(roles.map((role) => [role, id(roleInput[role] ?? selected, `roles.${role}`)]));
1052
+ for (const value of Object.values(compiledRoles))
1053
+ requireAvailable(value, "A model policy role is not present in the eligible catalog.");
1054
+ const explicitAllowed = (p.allowedModels ?? []).map((v, i) => id(v, `allowedModels[${i}]`));
1055
+ if (explicitAllowed.length > 500)
1056
+ throw new Fault(400, "invalid_model_policy", "Model policy allowedModels is too large.");
1057
+ for (const value of explicitAllowed)
1058
+ requireAvailable(value, "An allowed model is not present in the eligible catalog.");
1059
+ const aliases = Object.create(null);
1060
+ for (const [name, target] of Object.entries(p.aliases ?? {})) {
1061
+ if (Object.keys(aliases).length >= 200 || !/^[A-Za-z0-9._/-]{1,120}$/.test(name) || ["__proto__", "prototype", "constructor"].includes(name))
1062
+ throw new Fault(400, "invalid_model_policy", "A model alias is invalid or too numerous.");
1063
+ const canonical = id(target, `aliases.${name}`);
1064
+ if (available.has(name) && name !== canonical)
1065
+ throw new Fault(400, "invalid_model_policy", "A model alias cannot shadow a real model ID.");
1066
+ requireAvailable(canonical, "A model alias target is not present in the eligible catalog.");
1067
+ aliases[name] = canonical;
1068
+ }
1069
+ const fallbacks = Object.create(null);
1070
+ const allowedSources = new Set([selected, ...Object.values(compiledRoles), ...explicitAllowed]);
1071
+ for (const [source, targets] of Object.entries(p.fallbacks ?? {})) {
1072
+ if (!allowedSources.has(source) || !available.has(source) || !Array.isArray(targets) || Object.keys(fallbacks).length >= 200 || targets.length > 20)
1073
+ throw new Fault(400, "invalid_model_policy", "Fallback source or list is invalid.");
1074
+ const values = targets.map((v, i) => id(v, `fallbacks.${source}[${i}]`));
1075
+ for (const value of values)
1076
+ requireAvailable(value, "A fallback model is not present in the eligible catalog.");
1077
+ if (values.includes(source))
1078
+ throw new Fault(400, "invalid_model_policy", "A model cannot fall back to itself.");
1079
+ fallbacks[source] = uniq(values);
1080
+ }
1081
+ const allowedModels = uniq([selected, ...Object.values(compiledRoles), ...explicitAllowed, ...Object.values(fallbacks).flat()]).sort();
1082
+ if (Object.values(aliases).some((value) => !allowedModels.includes(value)))
1083
+ throw new Fault(422, "model_not_allowed", "A model alias target must be explicitly allowed by the launch policy.");
1084
+ const result = { version: 1, model: selected, roles: compiledRoles, allowedModels, aliases, fallbacks };
1085
+ return { ...result, digest: createHash("sha256").update(stable(result)).digest("hex") };
1086
+ }
1087
+ // openapi.json
1088
+ var openapi_default = {
1089
+ openapi: "3.0.3",
1090
+ info: {
1091
+ title: "Switcher API",
1092
+ version: "0.2.0",
1093
+ description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
1094
+ },
1095
+ security: [
1096
+ {
1097
+ bearerAuth: []
1098
+ }
1099
+ ],
1100
+ paths: {
1101
+ "/v1/providers": {
1102
+ get: {
1103
+ operationId: "listProviders",
1104
+ parameters: [
1105
+ {
1106
+ name: "limit",
1107
+ in: "query",
1108
+ schema: {
1109
+ type: "integer",
1110
+ minimum: 1,
1111
+ maximum: 1000,
1112
+ default: 100
1113
+ }
1114
+ },
1115
+ {
1116
+ name: "offset",
1117
+ in: "query",
1118
+ schema: {
1119
+ type: "integer",
1120
+ minimum: 0,
1121
+ default: 0
1122
+ }
1123
+ },
1124
+ {
1125
+ name: "search",
1126
+ in: "query",
1127
+ schema: {
1128
+ type: "string"
1129
+ }
1130
+ }
1131
+ ],
1132
+ responses: {
1133
+ "200": {
1134
+ description: "Success",
1135
+ content: {
1136
+ "application/json": {
1137
+ schema: {
1138
+ type: "object",
1139
+ required: [
1140
+ "data",
1141
+ "total",
1142
+ "limit",
1143
+ "offset"
1144
+ ],
1145
+ properties: {
1146
+ data: {
1147
+ type: "array",
1148
+ items: {
1149
+ $ref: "#/components/schemas/Provider"
1150
+ }
1151
+ },
1152
+ total: {
1153
+ type: "integer"
1154
+ },
1155
+ limit: {
1156
+ type: "integer"
1157
+ },
1158
+ offset: {
1159
+ type: "integer"
1160
+ }
1161
+ }
1162
+ }
1163
+ }
1164
+ }
1165
+ },
1166
+ default: {
1167
+ description: "Structured error",
1168
+ content: {
1169
+ "application/json": {
1170
+ schema: {
1171
+ $ref: "#/components/schemas/Error"
1172
+ }
1173
+ }
1174
+ }
1175
+ }
1176
+ }
1177
+ },
1178
+ post: {
1179
+ operationId: "createProvider",
1180
+ parameters: [
1181
+ {
1182
+ name: "Idempotency-Key",
1183
+ in: "header",
1184
+ required: true,
1185
+ schema: {
1186
+ type: "string",
1187
+ minLength: 8,
1188
+ maxLength: 128
1189
+ }
1190
+ }
1191
+ ],
1192
+ requestBody: {
1193
+ required: true,
1194
+ content: {
1195
+ "application/json": {
1196
+ schema: {
1197
+ $ref: "#/components/schemas/ProviderInput"
1198
+ }
1199
+ }
1200
+ }
1201
+ },
1202
+ responses: {
1203
+ "201": {
1204
+ description: "Success",
1205
+ content: {
1206
+ "application/json": {
1207
+ schema: {
1208
+ $ref: "#/components/schemas/Provider"
1209
+ }
1210
+ }
1211
+ }
1212
+ },
1213
+ default: {
1214
+ description: "Structured error",
1215
+ content: {
1216
+ "application/json": {
1217
+ schema: {
1218
+ $ref: "#/components/schemas/Error"
1219
+ }
1220
+ }
1221
+ }
1222
+ }
1223
+ }
1224
+ }
1225
+ },
1226
+ "/v1/providers/{id}": {
1227
+ get: {
1228
+ operationId: "getProvider",
1229
+ parameters: [
1230
+ {
1231
+ name: "id",
1232
+ in: "path",
1233
+ required: true,
1234
+ schema: {
1235
+ type: "string"
1236
+ }
1237
+ }
1238
+ ],
1239
+ responses: {
1240
+ "200": {
1241
+ description: "Success",
1242
+ content: {
1243
+ "application/json": {
1244
+ schema: {
1245
+ $ref: "#/components/schemas/Provider"
1246
+ }
1247
+ }
1248
+ }
1249
+ },
1250
+ default: {
1251
+ description: "Structured error",
1252
+ content: {
1253
+ "application/json": {
1254
+ schema: {
1255
+ $ref: "#/components/schemas/Error"
1256
+ }
1257
+ }
1258
+ }
1259
+ }
1260
+ }
1261
+ },
1262
+ put: {
1263
+ operationId: "updateProvider",
1264
+ parameters: [
1265
+ {
1266
+ name: "id",
1267
+ in: "path",
1268
+ required: true,
1269
+ schema: {
1270
+ type: "string"
1271
+ }
1272
+ },
1273
+ {
1274
+ name: "Idempotency-Key",
1275
+ in: "header",
1276
+ required: true,
1277
+ schema: {
1278
+ type: "string",
1279
+ minLength: 8,
1280
+ maxLength: 128
1281
+ }
1282
+ },
1283
+ {
1284
+ name: "If-Match",
1285
+ in: "header",
1286
+ required: true,
1287
+ schema: {
1288
+ type: "integer",
1289
+ minimum: 1
1290
+ }
1291
+ }
1292
+ ],
1293
+ requestBody: {
1294
+ required: true,
1295
+ content: {
1296
+ "application/json": {
1297
+ schema: {
1298
+ $ref: "#/components/schemas/ProviderInput"
1299
+ }
1300
+ }
1301
+ }
1302
+ },
1303
+ responses: {
1304
+ "200": {
1305
+ description: "Success",
1306
+ content: {
1307
+ "application/json": {
1308
+ schema: {
1309
+ $ref: "#/components/schemas/Provider"
1310
+ }
1311
+ }
1312
+ }
1313
+ },
1314
+ default: {
1315
+ description: "Structured error",
1316
+ content: {
1317
+ "application/json": {
1318
+ schema: {
1319
+ $ref: "#/components/schemas/Error"
1320
+ }
1321
+ }
1322
+ }
1323
+ }
1324
+ }
1325
+ },
1326
+ delete: {
1327
+ operationId: "deleteProvider",
1328
+ parameters: [
1329
+ {
1330
+ name: "id",
1331
+ in: "path",
1332
+ required: true,
1333
+ schema: {
1334
+ type: "string"
1335
+ }
1336
+ },
1337
+ {
1338
+ name: "Idempotency-Key",
1339
+ in: "header",
1340
+ required: true,
1341
+ schema: {
1342
+ type: "string",
1343
+ minLength: 8,
1344
+ maxLength: 128
1345
+ }
1346
+ },
1347
+ {
1348
+ name: "If-Match",
1349
+ in: "header",
1350
+ required: true,
1351
+ schema: {
1352
+ type: "integer",
1353
+ minimum: 1
1354
+ }
1355
+ }
1356
+ ],
1357
+ responses: {
1358
+ "200": {
1359
+ description: "Success",
1360
+ content: {
1361
+ "application/json": {
1362
+ schema: {
1363
+ type: "object",
1364
+ properties: {
1365
+ deleted: {
1366
+ type: "string"
1367
+ }
1368
+ },
1369
+ required: [
1370
+ "deleted"
1371
+ ]
1372
+ }
1373
+ }
1374
+ }
1375
+ },
1376
+ default: {
1377
+ description: "Structured error",
1378
+ content: {
1379
+ "application/json": {
1380
+ schema: {
1381
+ $ref: "#/components/schemas/Error"
1382
+ }
1383
+ }
1384
+ }
1385
+ }
1386
+ }
1387
+ }
1388
+ },
1389
+ "/v1/profiles": {
1390
+ get: {
1391
+ operationId: "listProfiles",
1392
+ parameters: [
1393
+ {
1394
+ name: "limit",
1395
+ in: "query",
1396
+ schema: {
1397
+ type: "integer",
1398
+ minimum: 1,
1399
+ maximum: 1000,
1400
+ default: 100
1401
+ }
1402
+ },
1403
+ {
1404
+ name: "offset",
1405
+ in: "query",
1406
+ schema: {
1407
+ type: "integer",
1408
+ minimum: 0,
1409
+ default: 0
1410
+ }
1411
+ },
1412
+ {
1413
+ name: "search",
1414
+ in: "query",
1415
+ schema: {
1416
+ type: "string"
1417
+ }
1418
+ }
1419
+ ],
1420
+ responses: {
1421
+ "200": {
1422
+ description: "Success",
1423
+ content: {
1424
+ "application/json": {
1425
+ schema: {
1426
+ type: "object",
1427
+ required: [
1428
+ "data",
1429
+ "total",
1430
+ "limit",
1431
+ "offset"
1432
+ ],
1433
+ properties: {
1434
+ data: {
1435
+ type: "array",
1436
+ items: {
1437
+ $ref: "#/components/schemas/Profile"
1438
+ }
1439
+ },
1440
+ total: {
1441
+ type: "integer"
1442
+ },
1443
+ limit: {
1444
+ type: "integer"
1445
+ },
1446
+ offset: {
1447
+ type: "integer"
1448
+ }
1449
+ }
1450
+ }
1451
+ }
1452
+ }
1453
+ },
1454
+ default: {
1455
+ description: "Structured error",
1456
+ content: {
1457
+ "application/json": {
1458
+ schema: {
1459
+ $ref: "#/components/schemas/Error"
1460
+ }
1461
+ }
1462
+ }
1463
+ }
1464
+ }
1465
+ },
1466
+ post: {
1467
+ operationId: "createProfile",
1468
+ parameters: [
1469
+ {
1470
+ name: "Idempotency-Key",
1471
+ in: "header",
1472
+ required: true,
1473
+ schema: {
1474
+ type: "string",
1475
+ minLength: 8,
1476
+ maxLength: 128
1477
+ }
1478
+ }
1479
+ ],
1480
+ requestBody: {
1481
+ required: true,
1482
+ content: {
1483
+ "application/json": {
1484
+ schema: {
1485
+ $ref: "#/components/schemas/ProfileInput"
1486
+ }
1487
+ }
1488
+ }
1489
+ },
1490
+ responses: {
1491
+ "201": {
1492
+ description: "Success",
1493
+ content: {
1494
+ "application/json": {
1495
+ schema: {
1496
+ $ref: "#/components/schemas/Profile"
1497
+ }
1498
+ }
1499
+ }
1500
+ },
1501
+ default: {
1502
+ description: "Structured error",
1503
+ content: {
1504
+ "application/json": {
1505
+ schema: {
1506
+ $ref: "#/components/schemas/Error"
1507
+ }
1508
+ }
1509
+ }
1510
+ }
1511
+ }
1512
+ }
1513
+ },
1514
+ "/v1/profiles/{id}": {
1515
+ get: {
1516
+ operationId: "getProfile",
1517
+ parameters: [
1518
+ {
1519
+ name: "id",
1520
+ in: "path",
1521
+ required: true,
1522
+ schema: {
1523
+ type: "string"
1524
+ }
1525
+ }
1526
+ ],
1527
+ responses: {
1528
+ "200": {
1529
+ description: "Success",
1530
+ content: {
1531
+ "application/json": {
1532
+ schema: {
1533
+ $ref: "#/components/schemas/Profile"
1534
+ }
1535
+ }
1536
+ }
1537
+ },
1538
+ default: {
1539
+ description: "Structured error",
1540
+ content: {
1541
+ "application/json": {
1542
+ schema: {
1543
+ $ref: "#/components/schemas/Error"
1544
+ }
1545
+ }
1546
+ }
1547
+ }
1548
+ }
1549
+ },
1550
+ put: {
1551
+ operationId: "updateProfile",
1552
+ parameters: [
1553
+ {
1554
+ name: "id",
1555
+ in: "path",
1556
+ required: true,
1557
+ schema: {
1558
+ type: "string"
1559
+ }
1560
+ },
1561
+ {
1562
+ name: "Idempotency-Key",
1563
+ in: "header",
1564
+ required: true,
1565
+ schema: {
1566
+ type: "string",
1567
+ minLength: 8,
1568
+ maxLength: 128
1569
+ }
1570
+ },
1571
+ {
1572
+ name: "If-Match",
1573
+ in: "header",
1574
+ required: true,
1575
+ schema: {
1576
+ type: "integer",
1577
+ minimum: 1
1578
+ }
1579
+ }
1580
+ ],
1581
+ requestBody: {
1582
+ required: true,
1583
+ content: {
1584
+ "application/json": {
1585
+ schema: {
1586
+ $ref: "#/components/schemas/ProfileInput"
1587
+ }
1588
+ }
1589
+ }
1590
+ },
1591
+ responses: {
1592
+ "200": {
1593
+ description: "Success",
1594
+ content: {
1595
+ "application/json": {
1596
+ schema: {
1597
+ $ref: "#/components/schemas/Profile"
1598
+ }
1599
+ }
1600
+ }
1601
+ },
1602
+ default: {
1603
+ description: "Structured error",
1604
+ content: {
1605
+ "application/json": {
1606
+ schema: {
1607
+ $ref: "#/components/schemas/Error"
1608
+ }
1609
+ }
1610
+ }
1611
+ }
1612
+ }
1613
+ },
1614
+ delete: {
1615
+ operationId: "deleteProfile",
1616
+ parameters: [
1617
+ {
1618
+ name: "id",
1619
+ in: "path",
1620
+ required: true,
1621
+ schema: {
1622
+ type: "string"
1623
+ }
1624
+ },
1625
+ {
1626
+ name: "Idempotency-Key",
1627
+ in: "header",
1628
+ required: true,
1629
+ schema: {
1630
+ type: "string",
1631
+ minLength: 8,
1632
+ maxLength: 128
1633
+ }
1634
+ },
1635
+ {
1636
+ name: "If-Match",
1637
+ in: "header",
1638
+ required: true,
1639
+ schema: {
1640
+ type: "integer",
1641
+ minimum: 1
1642
+ }
1643
+ }
1644
+ ],
1645
+ responses: {
1646
+ "200": {
1647
+ description: "Success",
1648
+ content: {
1649
+ "application/json": {
1650
+ schema: {
1651
+ type: "object",
1652
+ properties: {
1653
+ deleted: {
1654
+ type: "string"
1655
+ }
1656
+ },
1657
+ required: [
1658
+ "deleted"
1659
+ ]
1660
+ }
1661
+ }
1662
+ }
1663
+ },
1664
+ default: {
1665
+ description: "Structured error",
1666
+ content: {
1667
+ "application/json": {
1668
+ schema: {
1669
+ $ref: "#/components/schemas/Error"
1670
+ }
1671
+ }
1672
+ }
1673
+ }
1674
+ }
1675
+ }
1676
+ },
1677
+ "/v1/provider-presets": {
1678
+ get: {
1679
+ operationId: "listProviderPresets",
1680
+ parameters: [],
1681
+ responses: {
1682
+ "200": {
1683
+ description: "Success",
1684
+ content: {
1685
+ "application/json": {
1686
+ schema: {
1687
+ type: "object",
1688
+ required: [
1689
+ "data"
1690
+ ],
1691
+ properties: {
1692
+ data: {
1693
+ type: "array",
1694
+ items: {
1695
+ $ref: "#/components/schemas/ProviderPreset"
1696
+ }
1697
+ }
1698
+ }
1699
+ }
1700
+ }
1701
+ }
1702
+ },
1703
+ default: {
1704
+ description: "Structured error",
1705
+ content: {
1706
+ "application/json": {
1707
+ schema: {
1708
+ $ref: "#/components/schemas/Error"
1709
+ }
1710
+ }
1711
+ }
1712
+ }
1713
+ }
1714
+ }
1715
+ },
1716
+ "/v1/provider-presets/{id}": {
1717
+ get: {
1718
+ operationId: "getProviderPreset",
1719
+ parameters: [
1720
+ {
1721
+ name: "id",
1722
+ in: "path",
1723
+ required: true,
1724
+ schema: {
1725
+ type: "string"
1726
+ }
1727
+ }
1728
+ ],
1729
+ responses: {
1730
+ "200": {
1731
+ description: "Success",
1732
+ content: {
1733
+ "application/json": {
1734
+ schema: {
1735
+ $ref: "#/components/schemas/ProviderPreset"
1736
+ }
1737
+ }
1738
+ }
1739
+ },
1740
+ default: {
1741
+ description: "Structured error",
1742
+ content: {
1743
+ "application/json": {
1744
+ schema: {
1745
+ $ref: "#/components/schemas/Error"
1746
+ }
1747
+ }
1748
+ }
1749
+ }
1750
+ }
1751
+ }
1752
+ },
1753
+ "/v1/providers/{id}/models": {
1754
+ get: {
1755
+ operationId: "listModels",
1756
+ parameters: [
1757
+ {
1758
+ name: "id",
1759
+ in: "path",
1760
+ required: true,
1761
+ schema: {
1762
+ type: "string"
1763
+ }
1764
+ },
1765
+ {
1766
+ name: "limit",
1767
+ in: "query",
1768
+ schema: {
1769
+ type: "integer",
1770
+ minimum: 1,
1771
+ maximum: 1000,
1772
+ default: 100
1773
+ }
1774
+ },
1775
+ {
1776
+ name: "offset",
1777
+ in: "query",
1778
+ schema: {
1779
+ type: "integer",
1780
+ minimum: 0,
1781
+ default: 0
1782
+ }
1783
+ },
1784
+ {
1785
+ name: "search",
1786
+ in: "query",
1787
+ schema: {
1788
+ type: "string"
1789
+ }
1790
+ }
1791
+ ],
1792
+ responses: {
1793
+ "200": {
1794
+ description: "Success",
1795
+ content: {
1796
+ "application/json": {
1797
+ schema: {
1798
+ $ref: "#/components/schemas/ModelPage"
1799
+ }
1800
+ }
1801
+ }
1802
+ },
1803
+ default: {
1804
+ description: "Structured error",
1805
+ content: {
1806
+ "application/json": {
1807
+ schema: {
1808
+ $ref: "#/components/schemas/Error"
1809
+ }
1810
+ }
1811
+ }
1812
+ }
1813
+ }
1814
+ }
1815
+ },
1816
+ "/v1/providers/{id}/refresh": {
1817
+ post: {
1818
+ operationId: "refreshModels",
1819
+ parameters: [
1820
+ {
1821
+ name: "id",
1822
+ in: "path",
1823
+ required: true,
1824
+ schema: {
1825
+ type: "string"
1826
+ }
1827
+ },
1828
+ {
1829
+ name: "Idempotency-Key",
1830
+ in: "header",
1831
+ required: true,
1832
+ schema: {
1833
+ type: "string",
1834
+ minLength: 8,
1835
+ maxLength: 128
1836
+ }
1837
+ }
1838
+ ],
1839
+ requestBody: {
1840
+ required: true,
1841
+ content: {
1842
+ "application/json": {
1843
+ schema: {
1844
+ $ref: "#/components/schemas/Empty"
1845
+ }
1846
+ }
1847
+ }
1848
+ },
1849
+ responses: {
1850
+ "200": {
1851
+ description: "Success",
1852
+ content: {
1853
+ "application/json": {
1854
+ schema: {
1855
+ $ref: "#/components/schemas/Catalog"
1856
+ }
1857
+ }
1858
+ }
1859
+ },
1860
+ default: {
1861
+ description: "Structured error",
1862
+ content: {
1863
+ "application/json": {
1864
+ schema: {
1865
+ $ref: "#/components/schemas/Error"
1866
+ }
1867
+ }
1868
+ }
1869
+ }
1870
+ }
1871
+ }
1872
+ },
1873
+ "/v1/launch-plans": {
1874
+ post: {
1875
+ operationId: "launchPlan",
1876
+ parameters: [
1877
+ {
1878
+ name: "Idempotency-Key",
1879
+ in: "header",
1880
+ required: true,
1881
+ schema: {
1882
+ type: "string",
1883
+ minLength: 8,
1884
+ maxLength: 128
1885
+ }
1886
+ }
1887
+ ],
1888
+ requestBody: {
1889
+ required: true,
1890
+ content: {
1891
+ "application/json": {
1892
+ schema: {
1893
+ $ref: "#/components/schemas/LaunchInput"
1894
+ }
1895
+ }
1896
+ }
1897
+ },
1898
+ responses: {
1899
+ "200": {
1900
+ description: "Success",
1901
+ content: {
1902
+ "application/json": {
1903
+ schema: {
1904
+ $ref: "#/components/schemas/LaunchPlan"
1905
+ }
1906
+ }
1907
+ }
1908
+ },
1909
+ default: {
1910
+ description: "Structured error",
1911
+ content: {
1912
+ "application/json": {
1913
+ schema: {
1914
+ $ref: "#/components/schemas/Error"
1915
+ }
1916
+ }
1917
+ }
1918
+ }
1919
+ }
1920
+ }
1921
+ },
1922
+ "/v1/runs": {
1923
+ get: {
1924
+ operationId: "listRuns",
1925
+ parameters: [
1926
+ {
1927
+ name: "limit",
1928
+ in: "query",
1929
+ schema: {
1930
+ type: "integer",
1931
+ minimum: 1,
1932
+ maximum: 1000,
1933
+ default: 100
1934
+ }
1935
+ },
1936
+ {
1937
+ name: "offset",
1938
+ in: "query",
1939
+ schema: {
1940
+ type: "integer",
1941
+ minimum: 0,
1942
+ default: 0
1943
+ }
1944
+ },
1945
+ {
1946
+ name: "search",
1947
+ in: "query",
1948
+ schema: {
1949
+ type: "string"
1950
+ }
1951
+ }
1952
+ ],
1953
+ responses: {
1954
+ "200": {
1955
+ description: "Success",
1956
+ content: {
1957
+ "application/json": {
1958
+ schema: {
1959
+ type: "object",
1960
+ required: [
1961
+ "data",
1962
+ "total",
1963
+ "limit",
1964
+ "offset"
1965
+ ],
1966
+ properties: {
1967
+ data: {
1968
+ type: "array",
1969
+ items: {
1970
+ $ref: "#/components/schemas/Run"
1971
+ }
1972
+ },
1973
+ total: {
1974
+ type: "integer"
1975
+ },
1976
+ limit: {
1977
+ type: "integer"
1978
+ },
1979
+ offset: {
1980
+ type: "integer"
1981
+ }
1982
+ }
1983
+ }
1984
+ }
1985
+ }
1986
+ },
1987
+ default: {
1988
+ description: "Structured error",
1989
+ content: {
1990
+ "application/json": {
1991
+ schema: {
1992
+ $ref: "#/components/schemas/Error"
1993
+ }
1994
+ }
1995
+ }
1996
+ }
1997
+ }
1998
+ },
1999
+ post: {
2000
+ operationId: "createRun",
2001
+ parameters: [
2002
+ {
2003
+ name: "Idempotency-Key",
2004
+ in: "header",
2005
+ required: true,
2006
+ schema: {
2007
+ type: "string",
2008
+ minLength: 8,
2009
+ maxLength: 128
2010
+ }
2011
+ }
2012
+ ],
2013
+ requestBody: {
2014
+ required: true,
2015
+ content: {
2016
+ "application/json": {
2017
+ schema: {
2018
+ $ref: "#/components/schemas/RunInput"
2019
+ }
2020
+ }
2021
+ }
2022
+ },
2023
+ responses: {
2024
+ "201": {
2025
+ description: "Success",
2026
+ content: {
2027
+ "application/json": {
2028
+ schema: {
2029
+ $ref: "#/components/schemas/Run"
2030
+ }
2031
+ }
2032
+ }
2033
+ },
2034
+ default: {
2035
+ description: "Structured error",
2036
+ content: {
2037
+ "application/json": {
2038
+ schema: {
2039
+ $ref: "#/components/schemas/Error"
2040
+ }
2041
+ }
2042
+ }
2043
+ }
2044
+ }
2045
+ }
2046
+ },
2047
+ "/v1/runs/{id}": {
2048
+ get: {
2049
+ operationId: "getRun",
2050
+ parameters: [
2051
+ {
2052
+ name: "id",
2053
+ in: "path",
2054
+ required: true,
2055
+ schema: {
2056
+ type: "string"
2057
+ }
2058
+ }
2059
+ ],
2060
+ responses: {
2061
+ "200": {
2062
+ description: "Success",
2063
+ content: {
2064
+ "application/json": {
2065
+ schema: {
2066
+ $ref: "#/components/schemas/Run"
2067
+ }
2068
+ }
2069
+ }
2070
+ },
2071
+ default: {
2072
+ description: "Structured error",
2073
+ content: {
2074
+ "application/json": {
2075
+ schema: {
2076
+ $ref: "#/components/schemas/Error"
2077
+ }
2078
+ }
2079
+ }
2080
+ }
2081
+ }
2082
+ },
2083
+ patch: {
2084
+ operationId: "finishRun",
2085
+ parameters: [
2086
+ {
2087
+ name: "id",
2088
+ in: "path",
2089
+ required: true,
2090
+ schema: {
2091
+ type: "string"
2092
+ }
2093
+ },
2094
+ {
2095
+ name: "Idempotency-Key",
2096
+ in: "header",
2097
+ required: true,
2098
+ schema: {
2099
+ type: "string",
2100
+ minLength: 8,
2101
+ maxLength: 128
2102
+ }
2103
+ },
2104
+ {
2105
+ name: "If-Match",
2106
+ in: "header",
2107
+ required: true,
2108
+ schema: {
2109
+ type: "integer",
2110
+ minimum: 1
2111
+ }
2112
+ }
2113
+ ],
2114
+ requestBody: {
2115
+ required: true,
2116
+ content: {
2117
+ "application/json": {
2118
+ schema: {
2119
+ $ref: "#/components/schemas/RunUpdate"
2120
+ }
2121
+ }
2122
+ }
2123
+ },
2124
+ responses: {
2125
+ "200": {
2126
+ description: "Success",
2127
+ content: {
2128
+ "application/json": {
2129
+ schema: {
2130
+ $ref: "#/components/schemas/Run"
2131
+ }
2132
+ }
2133
+ }
2134
+ },
2135
+ default: {
2136
+ description: "Structured error",
2137
+ content: {
2138
+ "application/json": {
2139
+ schema: {
2140
+ $ref: "#/components/schemas/Error"
2141
+ }
2142
+ }
2143
+ }
2144
+ }
2145
+ }
2146
+ }
2147
+ },
2148
+ "/health": {
2149
+ get: {
2150
+ operationId: "health",
2151
+ parameters: [],
2152
+ responses: {
2153
+ "200": {
2154
+ description: "Success",
2155
+ content: {
2156
+ "application/json": {
2157
+ schema: {
2158
+ $ref: "#/components/schemas/Health"
2159
+ }
2160
+ }
2161
+ }
2162
+ },
2163
+ default: {
2164
+ description: "Structured error",
2165
+ content: {
2166
+ "application/json": {
2167
+ schema: {
2168
+ $ref: "#/components/schemas/Error"
2169
+ }
2170
+ }
2171
+ }
2172
+ }
2173
+ },
2174
+ security: []
2175
+ }
2176
+ },
2177
+ "/ready": {
2178
+ get: {
2179
+ operationId: "ready",
2180
+ parameters: [],
2181
+ responses: {
2182
+ "200": {
2183
+ description: "Success",
2184
+ content: {
2185
+ "application/json": {
2186
+ schema: {
2187
+ $ref: "#/components/schemas/Ready"
2188
+ }
2189
+ }
2190
+ }
2191
+ },
2192
+ default: {
2193
+ description: "Structured error",
2194
+ content: {
2195
+ "application/json": {
2196
+ schema: {
2197
+ $ref: "#/components/schemas/Error"
2198
+ }
2199
+ }
2200
+ }
2201
+ }
2202
+ },
2203
+ security: []
2204
+ }
2205
+ },
2206
+ "/version": {
2207
+ get: {
2208
+ operationId: "version",
2209
+ parameters: [],
2210
+ responses: {
2211
+ "200": {
2212
+ description: "Success",
2213
+ content: {
2214
+ "application/json": {
2215
+ schema: {
2216
+ $ref: "#/components/schemas/Version"
2217
+ }
2218
+ }
2219
+ }
2220
+ },
2221
+ default: {
2222
+ description: "Structured error",
2223
+ content: {
2224
+ "application/json": {
2225
+ schema: {
2226
+ $ref: "#/components/schemas/Error"
2227
+ }
2228
+ }
2229
+ }
2230
+ }
2231
+ },
2232
+ security: []
2233
+ }
2234
+ },
2235
+ "/v1/openapi.json": {
2236
+ get: {
2237
+ operationId: "openApi",
2238
+ parameters: [],
2239
+ responses: {
2240
+ "200": {
2241
+ description: "Success",
2242
+ content: {
2243
+ "application/json": {
2244
+ schema: {
2245
+ type: "object",
2246
+ additionalProperties: true
2247
+ }
2248
+ }
2249
+ }
2250
+ },
2251
+ default: {
2252
+ description: "Structured error",
2253
+ content: {
2254
+ "application/json": {
2255
+ schema: {
2256
+ $ref: "#/components/schemas/Error"
2257
+ }
2258
+ }
2259
+ }
2260
+ }
2261
+ }
2262
+ }
2263
+ }
2264
+ },
2265
+ components: {
2266
+ securitySchemes: {
2267
+ bearerAuth: {
2268
+ type: "http",
2269
+ scheme: "bearer"
2270
+ }
2271
+ },
2272
+ schemas: {
2273
+ ProviderPreset: {
2274
+ type: "object",
2275
+ properties: {
2276
+ id: {
2277
+ type: "string",
2278
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
2279
+ },
2280
+ name: {
2281
+ type: "string",
2282
+ minLength: 1,
2283
+ maxLength: 200
2284
+ },
2285
+ credentialEnv: {
2286
+ type: "string",
2287
+ pattern: "^SWITCHER_PROVIDER_[A-Z0-9_]+$"
2288
+ },
2289
+ credentialAliases: {
2290
+ type: "array",
2291
+ items: {
2292
+ type: "string",
2293
+ pattern: "^[A-Z][A-Z0-9_]+$"
2294
+ }
2295
+ },
2296
+ protocols: {
2297
+ type: "array",
2298
+ items: {
2299
+ type: "object",
2300
+ properties: {
2301
+ protocol: {
2302
+ type: "string",
2303
+ enum: [
2304
+ "anthropic-messages",
2305
+ "openai-responses",
2306
+ "openai-chat",
2307
+ "gemini-generate-content"
2308
+ ]
2309
+ },
2310
+ baseUrl: {
2311
+ type: "string",
2312
+ maxLength: 2000
2313
+ },
2314
+ authStyle: {
2315
+ type: "string",
2316
+ enum: [
2317
+ "bearer",
2318
+ "x-api-key",
2319
+ "api-key"
2320
+ ]
2321
+ },
2322
+ catalogBaseUrl: {
2323
+ type: "string",
2324
+ maxLength: 2000
2325
+ },
2326
+ catalogFormat: {
2327
+ type: "string",
2328
+ enum: [
2329
+ "openai",
2330
+ "ollama",
2331
+ "mistral",
2332
+ "together",
2333
+ "fireworks",
2334
+ "dashscope",
2335
+ "gemini",
2336
+ "none"
2337
+ ]
2338
+ },
2339
+ catalogAuthStyle: {
2340
+ type: "string",
2341
+ enum: [
2342
+ "bearer",
2343
+ "x-api-key",
2344
+ "api-key",
2345
+ "none"
2346
+ ]
2347
+ },
2348
+ modelsPath: {
2349
+ type: "string"
2350
+ },
2351
+ notes: {
2352
+ type: "array",
2353
+ items: {
2354
+ type: "string"
2355
+ }
2356
+ }
2357
+ },
2358
+ required: [
2359
+ "protocol",
2360
+ "authStyle",
2361
+ "catalogFormat",
2362
+ "modelsPath",
2363
+ "notes"
2364
+ ],
2365
+ additionalProperties: false
2366
+ },
2367
+ minItems: 1
2368
+ },
2369
+ sources: {
2370
+ type: "array",
2371
+ items: {
2372
+ type: "string",
2373
+ format: "uri"
2374
+ }
2375
+ },
2376
+ verification: {
2377
+ type: "string",
2378
+ enum: [
2379
+ "documented"
2380
+ ]
2381
+ }
2382
+ },
2383
+ required: [
2384
+ "id",
2385
+ "name",
2386
+ "credentialAliases",
2387
+ "protocols",
2388
+ "sources",
2389
+ "verification"
2390
+ ],
2391
+ additionalProperties: false
2392
+ },
2393
+ ProviderInput: {
2394
+ type: "object",
2395
+ properties: {
2396
+ id: {
2397
+ type: "string",
2398
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
2399
+ },
2400
+ name: {
2401
+ type: "string",
2402
+ minLength: 1,
2403
+ maxLength: 200
2404
+ },
2405
+ baseUrl: {
2406
+ type: "string",
2407
+ maxLength: 2000
2408
+ },
2409
+ protocol: {
2410
+ type: "string",
2411
+ enum: [
2412
+ "anthropic-messages",
2413
+ "openai-responses",
2414
+ "openai-chat",
2415
+ "gemini-generate-content"
2416
+ ]
2417
+ },
2418
+ credentialEnv: {
2419
+ type: "string",
2420
+ pattern: "^SWITCHER_PROVIDER_[A-Z0-9_]+$"
2421
+ },
2422
+ authStyle: {
2423
+ type: "string",
2424
+ enum: [
2425
+ "bearer",
2426
+ "x-api-key",
2427
+ "api-key"
2428
+ ],
2429
+ default: "bearer"
2430
+ },
2431
+ catalogBaseUrl: {
2432
+ type: "string",
2433
+ maxLength: 2000
2434
+ },
2435
+ catalogFormat: {
2436
+ type: "string",
2437
+ enum: [
2438
+ "openai",
2439
+ "ollama",
2440
+ "mistral",
2441
+ "together",
2442
+ "fireworks",
2443
+ "dashscope",
2444
+ "gemini",
2445
+ "none"
2446
+ ]
2447
+ },
2448
+ catalogAuthStyle: {
2449
+ type: "string",
2450
+ enum: [
2451
+ "bearer",
2452
+ "x-api-key",
2453
+ "api-key",
2454
+ "none"
2455
+ ]
2456
+ },
2457
+ catalogCredentialEnv: {
2458
+ type: "string",
2459
+ pattern: "^SWITCHER_PROVIDER_[A-Z0-9_]+$"
2460
+ },
2461
+ catalogAccountId: {
2462
+ type: "string",
2463
+ pattern: "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$"
2464
+ },
2465
+ modelsPath: {
2466
+ type: "string",
2467
+ pattern: "^[a-zA-Z0-9_/-]+$",
2468
+ maxLength: 200,
2469
+ default: "models"
2470
+ },
2471
+ manualModels: {
2472
+ type: "array",
2473
+ items: {
2474
+ type: "object",
2475
+ properties: {
2476
+ id: {
2477
+ type: "string",
2478
+ minLength: 1,
2479
+ maxLength: 300
2480
+ },
2481
+ name: {
2482
+ type: "string",
2483
+ minLength: 1,
2484
+ maxLength: 200
2485
+ },
2486
+ description: {
2487
+ type: "string",
2488
+ maxLength: 8000
2489
+ },
2490
+ available: {
2491
+ type: "boolean"
2492
+ },
2493
+ expiresOn: {
2494
+ type: "string",
2495
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
2496
+ },
2497
+ contextWindow: {
2498
+ type: "integer",
2499
+ exclusiveMinimum: true,
2500
+ minimum: 0
2501
+ },
2502
+ maxOutputTokens: {
2503
+ type: "integer",
2504
+ exclusiveMinimum: true,
2505
+ minimum: 0
2506
+ },
2507
+ inputModalities: {
2508
+ type: "array",
2509
+ items: {
2510
+ type: "string",
2511
+ maxLength: 50
2512
+ },
2513
+ maxItems: 20
2514
+ },
2515
+ outputModalities: {
2516
+ type: "array",
2517
+ items: {
2518
+ type: "string",
2519
+ maxLength: 50
2520
+ },
2521
+ maxItems: 20
2522
+ },
2523
+ supportedParameters: {
2524
+ type: "array",
2525
+ items: {
2526
+ type: "string",
2527
+ maxLength: 100
2528
+ },
2529
+ maxItems: 100
2530
+ },
2531
+ reasoningEfforts: {
2532
+ type: "array",
2533
+ items: {
2534
+ type: "string",
2535
+ enum: [
2536
+ "none",
2537
+ "minimal",
2538
+ "low",
2539
+ "medium",
2540
+ "high",
2541
+ "xhigh",
2542
+ "max",
2543
+ "ultra"
2544
+ ]
2545
+ },
2546
+ maxItems: 8
2547
+ },
2548
+ supportedGenerationMethods: {
2549
+ type: "array",
2550
+ items: {
2551
+ type: "string",
2552
+ minLength: 1,
2553
+ maxLength: 100
2554
+ },
2555
+ maxItems: 100
2556
+ }
2557
+ },
2558
+ required: [
2559
+ "id",
2560
+ "name"
2561
+ ],
2562
+ additionalProperties: false
2563
+ },
2564
+ maxItems: 1e4,
2565
+ default: []
2566
+ },
2567
+ additionalModels: {
2568
+ type: "array",
2569
+ items: {
2570
+ type: "object",
2571
+ properties: {
2572
+ id: {
2573
+ type: "string",
2574
+ minLength: 1,
2575
+ maxLength: 300
2576
+ },
2577
+ name: {
2578
+ type: "string",
2579
+ minLength: 1,
2580
+ maxLength: 200
2581
+ },
2582
+ description: {
2583
+ type: "string",
2584
+ maxLength: 8000
2585
+ },
2586
+ available: {
2587
+ type: "boolean"
2588
+ },
2589
+ expiresOn: {
2590
+ type: "string",
2591
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
2592
+ },
2593
+ contextWindow: {
2594
+ type: "integer",
2595
+ exclusiveMinimum: true,
2596
+ minimum: 0
2597
+ },
2598
+ maxOutputTokens: {
2599
+ type: "integer",
2600
+ exclusiveMinimum: true,
2601
+ minimum: 0
2602
+ },
2603
+ inputModalities: {
2604
+ type: "array",
2605
+ items: {
2606
+ type: "string",
2607
+ maxLength: 50
2608
+ },
2609
+ maxItems: 20
2610
+ },
2611
+ outputModalities: {
2612
+ type: "array",
2613
+ items: {
2614
+ type: "string",
2615
+ maxLength: 50
2616
+ },
2617
+ maxItems: 20
2618
+ },
2619
+ supportedParameters: {
2620
+ type: "array",
2621
+ items: {
2622
+ type: "string",
2623
+ maxLength: 100
2624
+ },
2625
+ maxItems: 100
2626
+ },
2627
+ reasoningEfforts: {
2628
+ type: "array",
2629
+ items: {
2630
+ type: "string",
2631
+ enum: [
2632
+ "none",
2633
+ "minimal",
2634
+ "low",
2635
+ "medium",
2636
+ "high",
2637
+ "xhigh",
2638
+ "max",
2639
+ "ultra"
2640
+ ]
2641
+ },
2642
+ maxItems: 8
2643
+ },
2644
+ supportedGenerationMethods: {
2645
+ type: "array",
2646
+ items: {
2647
+ type: "string",
2648
+ minLength: 1,
2649
+ maxLength: 100
2650
+ },
2651
+ maxItems: 100
2652
+ }
2653
+ },
2654
+ required: [
2655
+ "id",
2656
+ "name"
2657
+ ],
2658
+ additionalProperties: false
2659
+ },
2660
+ maxItems: 1e4
2661
+ }
2662
+ },
2663
+ required: [
2664
+ "id",
2665
+ "name",
2666
+ "baseUrl",
2667
+ "protocol"
2668
+ ],
2669
+ additionalProperties: false
2670
+ },
2671
+ Provider: {
2672
+ type: "object",
2673
+ properties: {
2674
+ id: {
2675
+ type: "string",
2676
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
2677
+ },
2678
+ name: {
2679
+ type: "string",
2680
+ minLength: 1,
2681
+ maxLength: 200
2682
+ },
2683
+ baseUrl: {
2684
+ type: "string",
2685
+ maxLength: 2000
2686
+ },
2687
+ protocol: {
2688
+ type: "string",
2689
+ enum: [
2690
+ "anthropic-messages",
2691
+ "openai-responses",
2692
+ "openai-chat",
2693
+ "gemini-generate-content"
2694
+ ]
2695
+ },
2696
+ credentialEnv: {
2697
+ type: "string",
2698
+ pattern: "^SWITCHER_PROVIDER_[A-Z0-9_]+$"
2699
+ },
2700
+ authStyle: {
2701
+ type: "string",
2702
+ enum: [
2703
+ "bearer",
2704
+ "x-api-key",
2705
+ "api-key"
2706
+ ],
2707
+ default: "bearer"
2708
+ },
2709
+ catalogBaseUrl: {
2710
+ type: "string",
2711
+ maxLength: 2000
2712
+ },
2713
+ catalogFormat: {
2714
+ type: "string",
2715
+ enum: [
2716
+ "openai",
2717
+ "ollama",
2718
+ "mistral",
2719
+ "together",
2720
+ "fireworks",
2721
+ "dashscope",
2722
+ "gemini",
2723
+ "none"
2724
+ ]
2725
+ },
2726
+ catalogAuthStyle: {
2727
+ type: "string",
2728
+ enum: [
2729
+ "bearer",
2730
+ "x-api-key",
2731
+ "api-key",
2732
+ "none"
2733
+ ]
2734
+ },
2735
+ catalogCredentialEnv: {
2736
+ type: "string",
2737
+ pattern: "^SWITCHER_PROVIDER_[A-Z0-9_]+$"
2738
+ },
2739
+ catalogAccountId: {
2740
+ type: "string",
2741
+ pattern: "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$"
2742
+ },
2743
+ modelsPath: {
2744
+ type: "string",
2745
+ pattern: "^[a-zA-Z0-9_/-]+$",
2746
+ maxLength: 200,
2747
+ default: "models"
2748
+ },
2749
+ manualModels: {
2750
+ type: "array",
2751
+ items: {
2752
+ type: "object",
2753
+ properties: {
2754
+ id: {
2755
+ type: "string",
2756
+ minLength: 1,
2757
+ maxLength: 300
2758
+ },
2759
+ name: {
2760
+ type: "string",
2761
+ minLength: 1,
2762
+ maxLength: 200
2763
+ },
2764
+ description: {
2765
+ type: "string",
2766
+ maxLength: 8000
2767
+ },
2768
+ available: {
2769
+ type: "boolean"
2770
+ },
2771
+ expiresOn: {
2772
+ type: "string",
2773
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
2774
+ },
2775
+ contextWindow: {
2776
+ type: "integer",
2777
+ exclusiveMinimum: true,
2778
+ minimum: 0
2779
+ },
2780
+ maxOutputTokens: {
2781
+ type: "integer",
2782
+ exclusiveMinimum: true,
2783
+ minimum: 0
2784
+ },
2785
+ inputModalities: {
2786
+ type: "array",
2787
+ items: {
2788
+ type: "string",
2789
+ maxLength: 50
2790
+ },
2791
+ maxItems: 20
2792
+ },
2793
+ outputModalities: {
2794
+ type: "array",
2795
+ items: {
2796
+ type: "string",
2797
+ maxLength: 50
2798
+ },
2799
+ maxItems: 20
2800
+ },
2801
+ supportedParameters: {
2802
+ type: "array",
2803
+ items: {
2804
+ type: "string",
2805
+ maxLength: 100
2806
+ },
2807
+ maxItems: 100
2808
+ },
2809
+ reasoningEfforts: {
2810
+ type: "array",
2811
+ items: {
2812
+ type: "string",
2813
+ enum: [
2814
+ "none",
2815
+ "minimal",
2816
+ "low",
2817
+ "medium",
2818
+ "high",
2819
+ "xhigh",
2820
+ "max",
2821
+ "ultra"
2822
+ ]
2823
+ },
2824
+ maxItems: 8
2825
+ },
2826
+ supportedGenerationMethods: {
2827
+ type: "array",
2828
+ items: {
2829
+ type: "string",
2830
+ minLength: 1,
2831
+ maxLength: 100
2832
+ },
2833
+ maxItems: 100
2834
+ }
2835
+ },
2836
+ required: [
2837
+ "id",
2838
+ "name"
2839
+ ],
2840
+ additionalProperties: false
2841
+ },
2842
+ maxItems: 1e4,
2843
+ default: []
2844
+ },
2845
+ additionalModels: {
2846
+ type: "array",
2847
+ items: {
2848
+ type: "object",
2849
+ properties: {
2850
+ id: {
2851
+ type: "string",
2852
+ minLength: 1,
2853
+ maxLength: 300
2854
+ },
2855
+ name: {
2856
+ type: "string",
2857
+ minLength: 1,
2858
+ maxLength: 200
2859
+ },
2860
+ description: {
2861
+ type: "string",
2862
+ maxLength: 8000
2863
+ },
2864
+ available: {
2865
+ type: "boolean"
2866
+ },
2867
+ expiresOn: {
2868
+ type: "string",
2869
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
2870
+ },
2871
+ contextWindow: {
2872
+ type: "integer",
2873
+ exclusiveMinimum: true,
2874
+ minimum: 0
2875
+ },
2876
+ maxOutputTokens: {
2877
+ type: "integer",
2878
+ exclusiveMinimum: true,
2879
+ minimum: 0
2880
+ },
2881
+ inputModalities: {
2882
+ type: "array",
2883
+ items: {
2884
+ type: "string",
2885
+ maxLength: 50
2886
+ },
2887
+ maxItems: 20
2888
+ },
2889
+ outputModalities: {
2890
+ type: "array",
2891
+ items: {
2892
+ type: "string",
2893
+ maxLength: 50
2894
+ },
2895
+ maxItems: 20
2896
+ },
2897
+ supportedParameters: {
2898
+ type: "array",
2899
+ items: {
2900
+ type: "string",
2901
+ maxLength: 100
2902
+ },
2903
+ maxItems: 100
2904
+ },
2905
+ reasoningEfforts: {
2906
+ type: "array",
2907
+ items: {
2908
+ type: "string",
2909
+ enum: [
2910
+ "none",
2911
+ "minimal",
2912
+ "low",
2913
+ "medium",
2914
+ "high",
2915
+ "xhigh",
2916
+ "max",
2917
+ "ultra"
2918
+ ]
2919
+ },
2920
+ maxItems: 8
2921
+ },
2922
+ supportedGenerationMethods: {
2923
+ type: "array",
2924
+ items: {
2925
+ type: "string",
2926
+ minLength: 1,
2927
+ maxLength: 100
2928
+ },
2929
+ maxItems: 100
2930
+ }
2931
+ },
2932
+ required: [
2933
+ "id",
2934
+ "name"
2935
+ ],
2936
+ additionalProperties: false
2937
+ },
2938
+ maxItems: 1e4
2939
+ },
2940
+ version: {
2941
+ type: "integer",
2942
+ exclusiveMinimum: true,
2943
+ minimum: 0
2944
+ },
2945
+ updatedAt: {
2946
+ type: "string"
2947
+ }
2948
+ },
2949
+ required: [
2950
+ "id",
2951
+ "name",
2952
+ "baseUrl",
2953
+ "protocol",
2954
+ "version",
2955
+ "updatedAt"
2956
+ ],
2957
+ additionalProperties: false
2958
+ },
2959
+ ProfileInput: {
2960
+ type: "object",
2961
+ properties: {
2962
+ id: {
2963
+ type: "string",
2964
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
2965
+ },
2966
+ name: {
2967
+ type: "string",
2968
+ minLength: 1,
2969
+ maxLength: 200
2970
+ },
2971
+ providerId: {
2972
+ type: "string",
2973
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
2974
+ },
2975
+ harness: {
2976
+ type: "string",
2977
+ enum: [
2978
+ "claude",
2979
+ "codex",
2980
+ "grok",
2981
+ "opencode",
2982
+ "opencode2",
2983
+ "pi",
2984
+ "omp",
2985
+ "dsh",
2986
+ "cline",
2987
+ "hermes",
2988
+ "prime-agent",
2989
+ "gemini",
2990
+ "aider",
2991
+ "kilo"
2992
+ ]
2993
+ },
2994
+ model: {
2995
+ type: "string",
2996
+ minLength: 1,
2997
+ maxLength: 300
2998
+ },
2999
+ modelPolicy: {
3000
+ type: "object",
3001
+ properties: {
3002
+ version: {
3003
+ type: "number",
3004
+ enum: [
3005
+ 1
3006
+ ],
3007
+ default: 1
3008
+ },
3009
+ roles: {
3010
+ type: "object",
3011
+ properties: {
3012
+ subagent: {
3013
+ type: "string",
3014
+ minLength: 1,
3015
+ maxLength: 300,
3016
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3017
+ },
3018
+ fast: {
3019
+ type: "string",
3020
+ minLength: 1,
3021
+ maxLength: 300,
3022
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3023
+ },
3024
+ planning: {
3025
+ type: "string",
3026
+ minLength: 1,
3027
+ maxLength: 300,
3028
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3029
+ },
3030
+ review: {
3031
+ type: "string",
3032
+ minLength: 1,
3033
+ maxLength: 300,
3034
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3035
+ },
3036
+ summary: {
3037
+ type: "string",
3038
+ minLength: 1,
3039
+ maxLength: 300,
3040
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3041
+ },
3042
+ compaction: {
3043
+ type: "string",
3044
+ minLength: 1,
3045
+ maxLength: 300,
3046
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3047
+ },
3048
+ weak: {
3049
+ type: "string",
3050
+ minLength: 1,
3051
+ maxLength: 300,
3052
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3053
+ },
3054
+ editor: {
3055
+ type: "string",
3056
+ minLength: 1,
3057
+ maxLength: 300,
3058
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3059
+ }
3060
+ },
3061
+ additionalProperties: false
3062
+ },
3063
+ allowedModels: {
3064
+ type: "array",
3065
+ items: {
3066
+ type: "string",
3067
+ minLength: 1,
3068
+ maxLength: 300,
3069
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3070
+ },
3071
+ maxItems: 500
3072
+ },
3073
+ aliases: {
3074
+ type: "object",
3075
+ additionalProperties: {
3076
+ type: "string",
3077
+ minLength: 1,
3078
+ maxLength: 300,
3079
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3080
+ }
3081
+ },
3082
+ fallbacks: {
3083
+ type: "object",
3084
+ additionalProperties: {
3085
+ type: "array",
3086
+ items: {
3087
+ type: "string",
3088
+ minLength: 1,
3089
+ maxLength: 300,
3090
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3091
+ },
3092
+ maxItems: 20
3093
+ }
3094
+ }
3095
+ },
3096
+ additionalProperties: false
3097
+ }
3098
+ },
3099
+ required: [
3100
+ "id",
3101
+ "name",
3102
+ "providerId",
3103
+ "harness",
3104
+ "model"
3105
+ ],
3106
+ additionalProperties: false
3107
+ },
3108
+ Profile: {
3109
+ type: "object",
3110
+ properties: {
3111
+ id: {
3112
+ type: "string",
3113
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
3114
+ },
3115
+ name: {
3116
+ type: "string",
3117
+ minLength: 1,
3118
+ maxLength: 200
3119
+ },
3120
+ providerId: {
3121
+ type: "string",
3122
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
3123
+ },
3124
+ harness: {
3125
+ type: "string",
3126
+ enum: [
3127
+ "claude",
3128
+ "codex",
3129
+ "grok",
3130
+ "opencode",
3131
+ "opencode2",
3132
+ "pi",
3133
+ "omp",
3134
+ "dsh",
3135
+ "cline",
3136
+ "hermes",
3137
+ "prime-agent",
3138
+ "gemini",
3139
+ "aider",
3140
+ "kilo"
3141
+ ]
3142
+ },
3143
+ model: {
3144
+ type: "string",
3145
+ minLength: 1,
3146
+ maxLength: 300
3147
+ },
3148
+ modelPolicy: {
3149
+ type: "object",
3150
+ properties: {
3151
+ version: {
3152
+ type: "number",
3153
+ enum: [
3154
+ 1
3155
+ ],
3156
+ default: 1
3157
+ },
3158
+ roles: {
3159
+ type: "object",
3160
+ properties: {
3161
+ subagent: {
3162
+ type: "string",
3163
+ minLength: 1,
3164
+ maxLength: 300,
3165
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3166
+ },
3167
+ fast: {
3168
+ type: "string",
3169
+ minLength: 1,
3170
+ maxLength: 300,
3171
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3172
+ },
3173
+ planning: {
3174
+ type: "string",
3175
+ minLength: 1,
3176
+ maxLength: 300,
3177
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3178
+ },
3179
+ review: {
3180
+ type: "string",
3181
+ minLength: 1,
3182
+ maxLength: 300,
3183
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3184
+ },
3185
+ summary: {
3186
+ type: "string",
3187
+ minLength: 1,
3188
+ maxLength: 300,
3189
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3190
+ },
3191
+ compaction: {
3192
+ type: "string",
3193
+ minLength: 1,
3194
+ maxLength: 300,
3195
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3196
+ },
3197
+ weak: {
3198
+ type: "string",
3199
+ minLength: 1,
3200
+ maxLength: 300,
3201
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3202
+ },
3203
+ editor: {
3204
+ type: "string",
3205
+ minLength: 1,
3206
+ maxLength: 300,
3207
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3208
+ }
3209
+ },
3210
+ additionalProperties: false
3211
+ },
3212
+ allowedModels: {
3213
+ type: "array",
3214
+ items: {
3215
+ type: "string",
3216
+ minLength: 1,
3217
+ maxLength: 300,
3218
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3219
+ },
3220
+ maxItems: 500
3221
+ },
3222
+ aliases: {
3223
+ type: "object",
3224
+ additionalProperties: {
3225
+ type: "string",
3226
+ minLength: 1,
3227
+ maxLength: 300,
3228
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3229
+ }
3230
+ },
3231
+ fallbacks: {
3232
+ type: "object",
3233
+ additionalProperties: {
3234
+ type: "array",
3235
+ items: {
3236
+ type: "string",
3237
+ minLength: 1,
3238
+ maxLength: 300,
3239
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3240
+ },
3241
+ maxItems: 20
3242
+ }
3243
+ }
3244
+ },
3245
+ additionalProperties: false
3246
+ },
3247
+ version: {
3248
+ type: "integer",
3249
+ exclusiveMinimum: true,
3250
+ minimum: 0
3251
+ },
3252
+ updatedAt: {
3253
+ type: "string"
3254
+ }
3255
+ },
3256
+ required: [
3257
+ "id",
3258
+ "name",
3259
+ "providerId",
3260
+ "harness",
3261
+ "model",
3262
+ "version",
3263
+ "updatedAt"
3264
+ ],
3265
+ additionalProperties: false
3266
+ },
3267
+ Model: {
3268
+ type: "object",
3269
+ properties: {
3270
+ id: {
3271
+ type: "string",
3272
+ minLength: 1,
3273
+ maxLength: 300
3274
+ },
3275
+ name: {
3276
+ type: "string",
3277
+ minLength: 1,
3278
+ maxLength: 200
3279
+ },
3280
+ description: {
3281
+ type: "string",
3282
+ maxLength: 8000
3283
+ },
3284
+ available: {
3285
+ type: "boolean"
3286
+ },
3287
+ expiresOn: {
3288
+ type: "string",
3289
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
3290
+ },
3291
+ contextWindow: {
3292
+ type: "integer",
3293
+ exclusiveMinimum: true,
3294
+ minimum: 0
3295
+ },
3296
+ maxOutputTokens: {
3297
+ type: "integer",
3298
+ exclusiveMinimum: true,
3299
+ minimum: 0
3300
+ },
3301
+ inputModalities: {
3302
+ type: "array",
3303
+ items: {
3304
+ type: "string",
3305
+ maxLength: 50
3306
+ },
3307
+ maxItems: 20
3308
+ },
3309
+ outputModalities: {
3310
+ type: "array",
3311
+ items: {
3312
+ type: "string",
3313
+ maxLength: 50
3314
+ },
3315
+ maxItems: 20
3316
+ },
3317
+ supportedParameters: {
3318
+ type: "array",
3319
+ items: {
3320
+ type: "string",
3321
+ maxLength: 100
3322
+ },
3323
+ maxItems: 100
3324
+ },
3325
+ reasoningEfforts: {
3326
+ type: "array",
3327
+ items: {
3328
+ type: "string",
3329
+ enum: [
3330
+ "none",
3331
+ "minimal",
3332
+ "low",
3333
+ "medium",
3334
+ "high",
3335
+ "xhigh",
3336
+ "max",
3337
+ "ultra"
3338
+ ]
3339
+ },
3340
+ maxItems: 8
3341
+ },
3342
+ supportedGenerationMethods: {
3343
+ type: "array",
3344
+ items: {
3345
+ type: "string",
3346
+ minLength: 1,
3347
+ maxLength: 100
3348
+ },
3349
+ maxItems: 100
3350
+ }
3351
+ },
3352
+ required: [
3353
+ "id",
3354
+ "name"
3355
+ ],
3356
+ additionalProperties: false
3357
+ },
3358
+ ModelPolicy: {
3359
+ type: "object",
3360
+ properties: {
3361
+ version: {
3362
+ type: "number",
3363
+ enum: [
3364
+ 1
3365
+ ],
3366
+ default: 1
3367
+ },
3368
+ roles: {
3369
+ type: "object",
3370
+ properties: {
3371
+ subagent: {
3372
+ type: "string",
3373
+ minLength: 1,
3374
+ maxLength: 300,
3375
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3376
+ },
3377
+ fast: {
3378
+ type: "string",
3379
+ minLength: 1,
3380
+ maxLength: 300,
3381
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3382
+ },
3383
+ planning: {
3384
+ type: "string",
3385
+ minLength: 1,
3386
+ maxLength: 300,
3387
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3388
+ },
3389
+ review: {
3390
+ type: "string",
3391
+ minLength: 1,
3392
+ maxLength: 300,
3393
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3394
+ },
3395
+ summary: {
3396
+ type: "string",
3397
+ minLength: 1,
3398
+ maxLength: 300,
3399
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3400
+ },
3401
+ compaction: {
3402
+ type: "string",
3403
+ minLength: 1,
3404
+ maxLength: 300,
3405
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3406
+ },
3407
+ weak: {
3408
+ type: "string",
3409
+ minLength: 1,
3410
+ maxLength: 300,
3411
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3412
+ },
3413
+ editor: {
3414
+ type: "string",
3415
+ minLength: 1,
3416
+ maxLength: 300,
3417
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3418
+ }
3419
+ },
3420
+ additionalProperties: false
3421
+ },
3422
+ allowedModels: {
3423
+ type: "array",
3424
+ items: {
3425
+ type: "string",
3426
+ minLength: 1,
3427
+ maxLength: 300,
3428
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3429
+ },
3430
+ maxItems: 500
3431
+ },
3432
+ aliases: {
3433
+ type: "object",
3434
+ additionalProperties: {
3435
+ type: "string",
3436
+ minLength: 1,
3437
+ maxLength: 300,
3438
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3439
+ }
3440
+ },
3441
+ fallbacks: {
3442
+ type: "object",
3443
+ additionalProperties: {
3444
+ type: "array",
3445
+ items: {
3446
+ type: "string",
3447
+ minLength: 1,
3448
+ maxLength: 300,
3449
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3450
+ },
3451
+ maxItems: 20
3452
+ }
3453
+ }
3454
+ },
3455
+ additionalProperties: false
3456
+ },
3457
+ RoutingEvent: {
3458
+ type: "object",
3459
+ properties: {
3460
+ at: {
3461
+ type: "string",
3462
+ format: "date-time"
3463
+ },
3464
+ requestId: {
3465
+ type: "string",
3466
+ pattern: "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
3467
+ },
3468
+ requestedModel: {
3469
+ type: "string",
3470
+ minLength: 1,
3471
+ maxLength: 300,
3472
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3473
+ },
3474
+ resolvedModel: {
3475
+ type: "string",
3476
+ minLength: 1,
3477
+ maxLength: 300,
3478
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3479
+ },
3480
+ reportedModel: {
3481
+ type: "string",
3482
+ minLength: 1,
3483
+ maxLength: 300,
3484
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
3485
+ },
3486
+ reasoningEffort: {
3487
+ type: "string",
3488
+ enum: [
3489
+ "none",
3490
+ "minimal",
3491
+ "low",
3492
+ "medium",
3493
+ "high",
3494
+ "xhigh",
3495
+ "max",
3496
+ "ultra"
3497
+ ]
3498
+ },
3499
+ decision: {
3500
+ type: "string",
3501
+ enum: [
3502
+ "allow",
3503
+ "alias",
3504
+ "reject",
3505
+ "fallback"
3506
+ ]
3507
+ },
3508
+ role: {
3509
+ type: "string",
3510
+ enum: [
3511
+ "main",
3512
+ "subagent",
3513
+ "fast",
3514
+ "planning",
3515
+ "review",
3516
+ "summary",
3517
+ "compaction",
3518
+ "weak",
3519
+ "editor"
3520
+ ]
3521
+ },
3522
+ reason: {
3523
+ type: "string",
3524
+ pattern: "^[a-z][a-z0-9_]{0,63}$"
3525
+ },
3526
+ upstreamStatus: {
3527
+ type: "integer",
3528
+ minimum: 100,
3529
+ maximum: 599
3530
+ }
3531
+ },
3532
+ required: [
3533
+ "at",
3534
+ "requestId",
3535
+ "requestedModel",
3536
+ "decision"
3537
+ ],
3538
+ additionalProperties: false
3539
+ },
3540
+ ModelPage: {
3541
+ type: "object",
3542
+ properties: {
3543
+ data: {
3544
+ type: "array",
3545
+ items: {
3546
+ type: "object",
3547
+ properties: {
3548
+ id: {
3549
+ type: "string",
3550
+ minLength: 1,
3551
+ maxLength: 300
3552
+ },
3553
+ name: {
3554
+ type: "string",
3555
+ minLength: 1,
3556
+ maxLength: 200
3557
+ },
3558
+ description: {
3559
+ type: "string",
3560
+ maxLength: 8000
3561
+ },
3562
+ available: {
3563
+ type: "boolean"
3564
+ },
3565
+ expiresOn: {
3566
+ type: "string",
3567
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
3568
+ },
3569
+ contextWindow: {
3570
+ type: "integer",
3571
+ exclusiveMinimum: true,
3572
+ minimum: 0
3573
+ },
3574
+ maxOutputTokens: {
3575
+ type: "integer",
3576
+ exclusiveMinimum: true,
3577
+ minimum: 0
3578
+ },
3579
+ inputModalities: {
3580
+ type: "array",
3581
+ items: {
3582
+ type: "string",
3583
+ maxLength: 50
3584
+ },
3585
+ maxItems: 20
3586
+ },
3587
+ outputModalities: {
3588
+ type: "array",
3589
+ items: {
3590
+ type: "string",
3591
+ maxLength: 50
3592
+ },
3593
+ maxItems: 20
3594
+ },
3595
+ supportedParameters: {
3596
+ type: "array",
3597
+ items: {
3598
+ type: "string",
3599
+ maxLength: 100
3600
+ },
3601
+ maxItems: 100
3602
+ },
3603
+ reasoningEfforts: {
3604
+ type: "array",
3605
+ items: {
3606
+ type: "string",
3607
+ enum: [
3608
+ "none",
3609
+ "minimal",
3610
+ "low",
3611
+ "medium",
3612
+ "high",
3613
+ "xhigh",
3614
+ "max",
3615
+ "ultra"
3616
+ ]
3617
+ },
3618
+ maxItems: 8
3619
+ },
3620
+ supportedGenerationMethods: {
3621
+ type: "array",
3622
+ items: {
3623
+ type: "string",
3624
+ minLength: 1,
3625
+ maxLength: 100
3626
+ },
3627
+ maxItems: 100
3628
+ },
3629
+ codingEligible: {
3630
+ type: "boolean"
3631
+ },
3632
+ expired: {
3633
+ type: "boolean"
3634
+ }
3635
+ },
3636
+ required: [
3637
+ "id",
3638
+ "name",
3639
+ "codingEligible",
3640
+ "expired"
3641
+ ],
3642
+ additionalProperties: false
3643
+ }
3644
+ },
3645
+ total: {
3646
+ type: "integer"
3647
+ },
3648
+ limit: {
3649
+ type: "integer"
3650
+ },
3651
+ offset: {
3652
+ type: "integer"
3653
+ },
3654
+ refreshedAt: {
3655
+ type: "string"
3656
+ },
3657
+ source: {
3658
+ type: "string",
3659
+ enum: [
3660
+ "remote",
3661
+ "manual"
3662
+ ]
3663
+ }
3664
+ },
3665
+ required: [
3666
+ "data",
3667
+ "total",
3668
+ "limit",
3669
+ "offset",
3670
+ "refreshedAt",
3671
+ "source"
3672
+ ],
3673
+ additionalProperties: false
3674
+ },
3675
+ Catalog: {
3676
+ type: "object",
3677
+ properties: {
3678
+ models: {
3679
+ type: "array",
3680
+ items: {
3681
+ type: "object",
3682
+ properties: {
3683
+ id: {
3684
+ type: "string",
3685
+ minLength: 1,
3686
+ maxLength: 300
3687
+ },
3688
+ name: {
3689
+ type: "string",
3690
+ minLength: 1,
3691
+ maxLength: 200
3692
+ },
3693
+ description: {
3694
+ type: "string",
3695
+ maxLength: 8000
3696
+ },
3697
+ available: {
3698
+ type: "boolean"
3699
+ },
3700
+ expiresOn: {
3701
+ type: "string",
3702
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
3703
+ },
3704
+ contextWindow: {
3705
+ type: "integer",
3706
+ exclusiveMinimum: true,
3707
+ minimum: 0
3708
+ },
3709
+ maxOutputTokens: {
3710
+ type: "integer",
3711
+ exclusiveMinimum: true,
3712
+ minimum: 0
3713
+ },
3714
+ inputModalities: {
3715
+ type: "array",
3716
+ items: {
3717
+ type: "string",
3718
+ maxLength: 50
3719
+ },
3720
+ maxItems: 20
3721
+ },
3722
+ outputModalities: {
3723
+ type: "array",
3724
+ items: {
3725
+ type: "string",
3726
+ maxLength: 50
3727
+ },
3728
+ maxItems: 20
3729
+ },
3730
+ supportedParameters: {
3731
+ type: "array",
3732
+ items: {
3733
+ type: "string",
3734
+ maxLength: 100
3735
+ },
3736
+ maxItems: 100
3737
+ },
3738
+ reasoningEfforts: {
3739
+ type: "array",
3740
+ items: {
3741
+ type: "string",
3742
+ enum: [
3743
+ "none",
3744
+ "minimal",
3745
+ "low",
3746
+ "medium",
3747
+ "high",
3748
+ "xhigh",
3749
+ "max",
3750
+ "ultra"
3751
+ ]
3752
+ },
3753
+ maxItems: 8
3754
+ },
3755
+ supportedGenerationMethods: {
3756
+ type: "array",
3757
+ items: {
3758
+ type: "string",
3759
+ minLength: 1,
3760
+ maxLength: 100
3761
+ },
3762
+ maxItems: 100
3763
+ }
3764
+ },
3765
+ required: [
3766
+ "id",
3767
+ "name"
3768
+ ],
3769
+ additionalProperties: false
3770
+ }
3771
+ },
3772
+ refreshedAt: {
3773
+ type: "string"
3774
+ },
3775
+ source: {
3776
+ type: "string",
3777
+ enum: [
3778
+ "remote",
3779
+ "manual"
3780
+ ]
3781
+ }
3782
+ },
3783
+ required: [
3784
+ "models",
3785
+ "refreshedAt",
3786
+ "source"
3787
+ ],
3788
+ additionalProperties: false
3789
+ },
3790
+ LaunchPlan: {
3791
+ type: "object",
3792
+ properties: {
3793
+ provider: {
3794
+ type: "object",
3795
+ properties: {
3796
+ id: {
3797
+ type: "string",
3798
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
3799
+ },
3800
+ name: {
3801
+ type: "string",
3802
+ minLength: 1,
3803
+ maxLength: 200
3804
+ },
3805
+ baseUrl: {
3806
+ type: "string",
3807
+ maxLength: 2000
3808
+ },
3809
+ protocol: {
3810
+ type: "string",
3811
+ enum: [
3812
+ "anthropic-messages",
3813
+ "openai-responses",
3814
+ "openai-chat",
3815
+ "gemini-generate-content"
3816
+ ]
3817
+ },
3818
+ credentialEnv: {
3819
+ type: "string",
3820
+ pattern: "^SWITCHER_PROVIDER_[A-Z0-9_]+$"
3821
+ },
3822
+ authStyle: {
3823
+ type: "string",
3824
+ enum: [
3825
+ "bearer",
3826
+ "x-api-key",
3827
+ "api-key"
3828
+ ],
3829
+ default: "bearer"
3830
+ },
3831
+ catalogBaseUrl: {
3832
+ type: "string",
3833
+ maxLength: 2000
3834
+ },
3835
+ catalogFormat: {
3836
+ type: "string",
3837
+ enum: [
3838
+ "openai",
3839
+ "ollama",
3840
+ "mistral",
3841
+ "together",
3842
+ "fireworks",
3843
+ "dashscope",
3844
+ "gemini",
3845
+ "none"
3846
+ ]
3847
+ },
3848
+ catalogAuthStyle: {
3849
+ type: "string",
3850
+ enum: [
3851
+ "bearer",
3852
+ "x-api-key",
3853
+ "api-key",
3854
+ "none"
3855
+ ]
3856
+ },
3857
+ catalogCredentialEnv: {
3858
+ type: "string",
3859
+ pattern: "^SWITCHER_PROVIDER_[A-Z0-9_]+$"
3860
+ },
3861
+ catalogAccountId: {
3862
+ type: "string",
3863
+ pattern: "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$"
3864
+ },
3865
+ modelsPath: {
3866
+ type: "string",
3867
+ pattern: "^[a-zA-Z0-9_/-]+$",
3868
+ maxLength: 200,
3869
+ default: "models"
3870
+ },
3871
+ manualModels: {
3872
+ type: "array",
3873
+ items: {
3874
+ type: "object",
3875
+ properties: {
3876
+ id: {
3877
+ type: "string",
3878
+ minLength: 1,
3879
+ maxLength: 300
3880
+ },
3881
+ name: {
3882
+ type: "string",
3883
+ minLength: 1,
3884
+ maxLength: 200
3885
+ },
3886
+ description: {
3887
+ type: "string",
3888
+ maxLength: 8000
3889
+ },
3890
+ available: {
3891
+ type: "boolean"
3892
+ },
3893
+ expiresOn: {
3894
+ type: "string",
3895
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
3896
+ },
3897
+ contextWindow: {
3898
+ type: "integer",
3899
+ exclusiveMinimum: true,
3900
+ minimum: 0
3901
+ },
3902
+ maxOutputTokens: {
3903
+ type: "integer",
3904
+ exclusiveMinimum: true,
3905
+ minimum: 0
3906
+ },
3907
+ inputModalities: {
3908
+ type: "array",
3909
+ items: {
3910
+ type: "string",
3911
+ maxLength: 50
3912
+ },
3913
+ maxItems: 20
3914
+ },
3915
+ outputModalities: {
3916
+ type: "array",
3917
+ items: {
3918
+ type: "string",
3919
+ maxLength: 50
3920
+ },
3921
+ maxItems: 20
3922
+ },
3923
+ supportedParameters: {
3924
+ type: "array",
3925
+ items: {
3926
+ type: "string",
3927
+ maxLength: 100
3928
+ },
3929
+ maxItems: 100
3930
+ },
3931
+ reasoningEfforts: {
3932
+ type: "array",
3933
+ items: {
3934
+ type: "string",
3935
+ enum: [
3936
+ "none",
3937
+ "minimal",
3938
+ "low",
3939
+ "medium",
3940
+ "high",
3941
+ "xhigh",
3942
+ "max",
3943
+ "ultra"
3944
+ ]
3945
+ },
3946
+ maxItems: 8
3947
+ },
3948
+ supportedGenerationMethods: {
3949
+ type: "array",
3950
+ items: {
3951
+ type: "string",
3952
+ minLength: 1,
3953
+ maxLength: 100
3954
+ },
3955
+ maxItems: 100
3956
+ }
3957
+ },
3958
+ required: [
3959
+ "id",
3960
+ "name"
3961
+ ],
3962
+ additionalProperties: false
3963
+ },
3964
+ maxItems: 1e4,
3965
+ default: []
3966
+ },
3967
+ additionalModels: {
3968
+ type: "array",
3969
+ items: {
3970
+ type: "object",
3971
+ properties: {
3972
+ id: {
3973
+ type: "string",
3974
+ minLength: 1,
3975
+ maxLength: 300
3976
+ },
3977
+ name: {
3978
+ type: "string",
3979
+ minLength: 1,
3980
+ maxLength: 200
3981
+ },
3982
+ description: {
3983
+ type: "string",
3984
+ maxLength: 8000
3985
+ },
3986
+ available: {
3987
+ type: "boolean"
3988
+ },
3989
+ expiresOn: {
3990
+ type: "string",
3991
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
3992
+ },
3993
+ contextWindow: {
3994
+ type: "integer",
3995
+ exclusiveMinimum: true,
3996
+ minimum: 0
3997
+ },
3998
+ maxOutputTokens: {
3999
+ type: "integer",
4000
+ exclusiveMinimum: true,
4001
+ minimum: 0
4002
+ },
4003
+ inputModalities: {
4004
+ type: "array",
4005
+ items: {
4006
+ type: "string",
4007
+ maxLength: 50
4008
+ },
4009
+ maxItems: 20
4010
+ },
4011
+ outputModalities: {
4012
+ type: "array",
4013
+ items: {
4014
+ type: "string",
4015
+ maxLength: 50
4016
+ },
4017
+ maxItems: 20
4018
+ },
4019
+ supportedParameters: {
4020
+ type: "array",
4021
+ items: {
4022
+ type: "string",
4023
+ maxLength: 100
4024
+ },
4025
+ maxItems: 100
4026
+ },
4027
+ reasoningEfforts: {
4028
+ type: "array",
4029
+ items: {
4030
+ type: "string",
4031
+ enum: [
4032
+ "none",
4033
+ "minimal",
4034
+ "low",
4035
+ "medium",
4036
+ "high",
4037
+ "xhigh",
4038
+ "max",
4039
+ "ultra"
4040
+ ]
4041
+ },
4042
+ maxItems: 8
4043
+ },
4044
+ supportedGenerationMethods: {
4045
+ type: "array",
4046
+ items: {
4047
+ type: "string",
4048
+ minLength: 1,
4049
+ maxLength: 100
4050
+ },
4051
+ maxItems: 100
4052
+ }
4053
+ },
4054
+ required: [
4055
+ "id",
4056
+ "name"
4057
+ ],
4058
+ additionalProperties: false
4059
+ },
4060
+ maxItems: 1e4
4061
+ },
4062
+ version: {
4063
+ type: "integer",
4064
+ exclusiveMinimum: true,
4065
+ minimum: 0
4066
+ },
4067
+ updatedAt: {
4068
+ type: "string"
4069
+ }
4070
+ },
4071
+ required: [
4072
+ "id",
4073
+ "name",
4074
+ "baseUrl",
4075
+ "protocol",
4076
+ "version",
4077
+ "updatedAt"
4078
+ ],
4079
+ additionalProperties: false
4080
+ },
4081
+ profile: {
4082
+ type: "object",
4083
+ properties: {
4084
+ id: {
4085
+ type: "string",
4086
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
4087
+ },
4088
+ name: {
4089
+ type: "string",
4090
+ minLength: 1,
4091
+ maxLength: 200
4092
+ },
4093
+ providerId: {
4094
+ type: "string",
4095
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
4096
+ },
4097
+ harness: {
4098
+ type: "string",
4099
+ enum: [
4100
+ "claude",
4101
+ "codex",
4102
+ "grok",
4103
+ "opencode",
4104
+ "opencode2",
4105
+ "pi",
4106
+ "omp",
4107
+ "dsh",
4108
+ "cline",
4109
+ "hermes",
4110
+ "prime-agent",
4111
+ "gemini",
4112
+ "aider",
4113
+ "kilo"
4114
+ ]
4115
+ },
4116
+ model: {
4117
+ type: "string",
4118
+ minLength: 1,
4119
+ maxLength: 300
4120
+ },
4121
+ modelPolicy: {
4122
+ type: "object",
4123
+ properties: {
4124
+ version: {
4125
+ type: "number",
4126
+ enum: [
4127
+ 1
4128
+ ],
4129
+ default: 1
4130
+ },
4131
+ roles: {
4132
+ type: "object",
4133
+ properties: {
4134
+ subagent: {
4135
+ type: "string",
4136
+ minLength: 1,
4137
+ maxLength: 300,
4138
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4139
+ },
4140
+ fast: {
4141
+ type: "string",
4142
+ minLength: 1,
4143
+ maxLength: 300,
4144
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4145
+ },
4146
+ planning: {
4147
+ type: "string",
4148
+ minLength: 1,
4149
+ maxLength: 300,
4150
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4151
+ },
4152
+ review: {
4153
+ type: "string",
4154
+ minLength: 1,
4155
+ maxLength: 300,
4156
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4157
+ },
4158
+ summary: {
4159
+ type: "string",
4160
+ minLength: 1,
4161
+ maxLength: 300,
4162
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4163
+ },
4164
+ compaction: {
4165
+ type: "string",
4166
+ minLength: 1,
4167
+ maxLength: 300,
4168
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4169
+ },
4170
+ weak: {
4171
+ type: "string",
4172
+ minLength: 1,
4173
+ maxLength: 300,
4174
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4175
+ },
4176
+ editor: {
4177
+ type: "string",
4178
+ minLength: 1,
4179
+ maxLength: 300,
4180
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4181
+ }
4182
+ },
4183
+ additionalProperties: false
4184
+ },
4185
+ allowedModels: {
4186
+ type: "array",
4187
+ items: {
4188
+ type: "string",
4189
+ minLength: 1,
4190
+ maxLength: 300,
4191
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4192
+ },
4193
+ maxItems: 500
4194
+ },
4195
+ aliases: {
4196
+ type: "object",
4197
+ additionalProperties: {
4198
+ type: "string",
4199
+ minLength: 1,
4200
+ maxLength: 300,
4201
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4202
+ }
4203
+ },
4204
+ fallbacks: {
4205
+ type: "object",
4206
+ additionalProperties: {
4207
+ type: "array",
4208
+ items: {
4209
+ type: "string",
4210
+ minLength: 1,
4211
+ maxLength: 300,
4212
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4213
+ },
4214
+ maxItems: 20
4215
+ }
4216
+ }
4217
+ },
4218
+ additionalProperties: false
4219
+ },
4220
+ version: {
4221
+ type: "integer",
4222
+ exclusiveMinimum: true,
4223
+ minimum: 0
4224
+ },
4225
+ updatedAt: {
4226
+ type: "string"
4227
+ }
4228
+ },
4229
+ required: [
4230
+ "id",
4231
+ "name",
4232
+ "providerId",
4233
+ "harness",
4234
+ "model",
4235
+ "version",
4236
+ "updatedAt"
4237
+ ],
4238
+ additionalProperties: false
4239
+ },
4240
+ catalog: {
4241
+ type: "object",
4242
+ properties: {
4243
+ models: {
4244
+ type: "array",
4245
+ items: {
4246
+ type: "object",
4247
+ properties: {
4248
+ id: {
4249
+ type: "string",
4250
+ minLength: 1,
4251
+ maxLength: 300
4252
+ },
4253
+ name: {
4254
+ type: "string",
4255
+ minLength: 1,
4256
+ maxLength: 200
4257
+ },
4258
+ description: {
4259
+ type: "string",
4260
+ maxLength: 8000
4261
+ },
4262
+ available: {
4263
+ type: "boolean"
4264
+ },
4265
+ expiresOn: {
4266
+ type: "string",
4267
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
4268
+ },
4269
+ contextWindow: {
4270
+ type: "integer",
4271
+ exclusiveMinimum: true,
4272
+ minimum: 0
4273
+ },
4274
+ maxOutputTokens: {
4275
+ type: "integer",
4276
+ exclusiveMinimum: true,
4277
+ minimum: 0
4278
+ },
4279
+ inputModalities: {
4280
+ type: "array",
4281
+ items: {
4282
+ type: "string",
4283
+ maxLength: 50
4284
+ },
4285
+ maxItems: 20
4286
+ },
4287
+ outputModalities: {
4288
+ type: "array",
4289
+ items: {
4290
+ type: "string",
4291
+ maxLength: 50
4292
+ },
4293
+ maxItems: 20
4294
+ },
4295
+ supportedParameters: {
4296
+ type: "array",
4297
+ items: {
4298
+ type: "string",
4299
+ maxLength: 100
4300
+ },
4301
+ maxItems: 100
4302
+ },
4303
+ reasoningEfforts: {
4304
+ type: "array",
4305
+ items: {
4306
+ type: "string",
4307
+ enum: [
4308
+ "none",
4309
+ "minimal",
4310
+ "low",
4311
+ "medium",
4312
+ "high",
4313
+ "xhigh",
4314
+ "max",
4315
+ "ultra"
4316
+ ]
4317
+ },
4318
+ maxItems: 8
4319
+ },
4320
+ supportedGenerationMethods: {
4321
+ type: "array",
4322
+ items: {
4323
+ type: "string",
4324
+ minLength: 1,
4325
+ maxLength: 100
4326
+ },
4327
+ maxItems: 100
4328
+ }
4329
+ },
4330
+ required: [
4331
+ "id",
4332
+ "name"
4333
+ ],
4334
+ additionalProperties: false
4335
+ }
4336
+ },
4337
+ refreshedAt: {
4338
+ type: "string"
4339
+ },
4340
+ source: {
4341
+ type: "string",
4342
+ enum: [
4343
+ "remote",
4344
+ "manual"
4345
+ ]
4346
+ }
4347
+ },
4348
+ required: [
4349
+ "models",
4350
+ "refreshedAt",
4351
+ "source"
4352
+ ],
4353
+ additionalProperties: false
4354
+ },
4355
+ planToken: {
4356
+ type: "string"
4357
+ },
4358
+ warnings: {
4359
+ type: "array",
4360
+ items: {
4361
+ type: "string"
4362
+ }
4363
+ }
4364
+ },
4365
+ required: [
4366
+ "provider",
4367
+ "profile",
4368
+ "catalog",
4369
+ "planToken",
4370
+ "warnings"
4371
+ ],
4372
+ additionalProperties: false
4373
+ },
4374
+ RunInput: {
4375
+ type: "object",
4376
+ properties: {
4377
+ modelPolicyVersion: {
4378
+ type: "number",
4379
+ enum: [
4380
+ 1
4381
+ ]
4382
+ },
4383
+ profileId: {
4384
+ type: "string",
4385
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
4386
+ },
4387
+ harness: {
4388
+ type: "string",
4389
+ enum: [
4390
+ "claude",
4391
+ "codex",
4392
+ "grok",
4393
+ "opencode",
4394
+ "opencode2",
4395
+ "pi",
4396
+ "omp",
4397
+ "dsh",
4398
+ "cline",
4399
+ "hermes",
4400
+ "prime-agent",
4401
+ "gemini",
4402
+ "aider",
4403
+ "kilo"
4404
+ ]
4405
+ },
4406
+ model: {
4407
+ type: "string",
4408
+ minLength: 1,
4409
+ maxLength: 300
4410
+ },
4411
+ modelPolicy: {
4412
+ type: "object",
4413
+ properties: {
4414
+ version: {
4415
+ type: "number",
4416
+ enum: [
4417
+ 1
4418
+ ],
4419
+ default: 1
4420
+ },
4421
+ roles: {
4422
+ type: "object",
4423
+ properties: {
4424
+ subagent: {
4425
+ type: "string",
4426
+ minLength: 1,
4427
+ maxLength: 300,
4428
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4429
+ },
4430
+ fast: {
4431
+ type: "string",
4432
+ minLength: 1,
4433
+ maxLength: 300,
4434
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4435
+ },
4436
+ planning: {
4437
+ type: "string",
4438
+ minLength: 1,
4439
+ maxLength: 300,
4440
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4441
+ },
4442
+ review: {
4443
+ type: "string",
4444
+ minLength: 1,
4445
+ maxLength: 300,
4446
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4447
+ },
4448
+ summary: {
4449
+ type: "string",
4450
+ minLength: 1,
4451
+ maxLength: 300,
4452
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4453
+ },
4454
+ compaction: {
4455
+ type: "string",
4456
+ minLength: 1,
4457
+ maxLength: 300,
4458
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4459
+ },
4460
+ weak: {
4461
+ type: "string",
4462
+ minLength: 1,
4463
+ maxLength: 300,
4464
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4465
+ },
4466
+ editor: {
4467
+ type: "string",
4468
+ minLength: 1,
4469
+ maxLength: 300,
4470
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4471
+ }
4472
+ },
4473
+ additionalProperties: false
4474
+ },
4475
+ allowedModels: {
4476
+ type: "array",
4477
+ items: {
4478
+ type: "string",
4479
+ minLength: 1,
4480
+ maxLength: 300,
4481
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4482
+ },
4483
+ maxItems: 500
4484
+ },
4485
+ aliases: {
4486
+ type: "object",
4487
+ additionalProperties: {
4488
+ type: "string",
4489
+ minLength: 1,
4490
+ maxLength: 300,
4491
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4492
+ }
4493
+ },
4494
+ fallbacks: {
4495
+ type: "object",
4496
+ additionalProperties: {
4497
+ type: "array",
4498
+ items: {
4499
+ type: "string",
4500
+ minLength: 1,
4501
+ maxLength: 300,
4502
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4503
+ },
4504
+ maxItems: 20
4505
+ }
4506
+ }
4507
+ },
4508
+ additionalProperties: false
4509
+ },
4510
+ planToken: {
4511
+ type: "string",
4512
+ pattern: "^[a-f0-9]{64}$"
4513
+ }
4514
+ },
4515
+ required: [
4516
+ "modelPolicyVersion",
4517
+ "profileId",
4518
+ "harness",
4519
+ "model",
4520
+ "planToken"
4521
+ ],
4522
+ additionalProperties: false
4523
+ },
4524
+ RunUpdate: {
4525
+ type: "object",
4526
+ properties: {
4527
+ status: {
4528
+ type: "string",
4529
+ enum: [
4530
+ "exited",
4531
+ "failed",
4532
+ "interrupted"
4533
+ ]
4534
+ },
4535
+ exitCode: {
4536
+ type: "integer",
4537
+ minimum: 0,
4538
+ maximum: 255
4539
+ },
4540
+ routingEvents: {
4541
+ type: "array",
4542
+ items: {
4543
+ type: "object",
4544
+ properties: {
4545
+ at: {
4546
+ type: "string",
4547
+ format: "date-time"
4548
+ },
4549
+ requestId: {
4550
+ type: "string",
4551
+ pattern: "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
4552
+ },
4553
+ requestedModel: {
4554
+ type: "string",
4555
+ minLength: 1,
4556
+ maxLength: 300,
4557
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4558
+ },
4559
+ resolvedModel: {
4560
+ type: "string",
4561
+ minLength: 1,
4562
+ maxLength: 300,
4563
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4564
+ },
4565
+ reportedModel: {
4566
+ type: "string",
4567
+ minLength: 1,
4568
+ maxLength: 300,
4569
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4570
+ },
4571
+ reasoningEffort: {
4572
+ type: "string",
4573
+ enum: [
4574
+ "none",
4575
+ "minimal",
4576
+ "low",
4577
+ "medium",
4578
+ "high",
4579
+ "xhigh",
4580
+ "max",
4581
+ "ultra"
4582
+ ]
4583
+ },
4584
+ decision: {
4585
+ type: "string",
4586
+ enum: [
4587
+ "allow",
4588
+ "alias",
4589
+ "reject",
4590
+ "fallback"
4591
+ ]
4592
+ },
4593
+ role: {
4594
+ type: "string",
4595
+ enum: [
4596
+ "main",
4597
+ "subagent",
4598
+ "fast",
4599
+ "planning",
4600
+ "review",
4601
+ "summary",
4602
+ "compaction",
4603
+ "weak",
4604
+ "editor"
4605
+ ]
4606
+ },
4607
+ reason: {
4608
+ type: "string",
4609
+ pattern: "^[a-z][a-z0-9_]{0,63}$"
4610
+ },
4611
+ upstreamStatus: {
4612
+ type: "integer",
4613
+ minimum: 100,
4614
+ maximum: 599
4615
+ }
4616
+ },
4617
+ required: [
4618
+ "at",
4619
+ "requestId",
4620
+ "requestedModel",
4621
+ "decision"
4622
+ ],
4623
+ additionalProperties: false
4624
+ },
4625
+ maxItems: 1000
4626
+ },
4627
+ routingEventsDropped: {
4628
+ type: "integer",
4629
+ minimum: 0,
4630
+ maximum: 1e6
4631
+ }
4632
+ },
4633
+ required: [
4634
+ "status",
4635
+ "exitCode"
4636
+ ],
4637
+ additionalProperties: false
4638
+ },
4639
+ Run: {
4640
+ type: "object",
4641
+ properties: {
4642
+ modelPolicyVersion: {
4643
+ type: "number",
4644
+ enum: [
4645
+ 1
4646
+ ]
4647
+ },
4648
+ profileId: {
4649
+ type: "string",
4650
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
4651
+ },
4652
+ harness: {
4653
+ type: "string",
4654
+ enum: [
4655
+ "claude",
4656
+ "codex",
4657
+ "grok",
4658
+ "opencode",
4659
+ "opencode2",
4660
+ "pi",
4661
+ "omp",
4662
+ "dsh",
4663
+ "cline",
4664
+ "hermes",
4665
+ "prime-agent",
4666
+ "gemini",
4667
+ "aider",
4668
+ "kilo"
4669
+ ]
4670
+ },
4671
+ model: {
4672
+ type: "string",
4673
+ minLength: 1,
4674
+ maxLength: 300
4675
+ },
4676
+ modelPolicy: {
4677
+ type: "object",
4678
+ properties: {
4679
+ version: {
4680
+ type: "number",
4681
+ enum: [
4682
+ 1
4683
+ ],
4684
+ default: 1
4685
+ },
4686
+ roles: {
4687
+ type: "object",
4688
+ properties: {
4689
+ subagent: {
4690
+ type: "string",
4691
+ minLength: 1,
4692
+ maxLength: 300,
4693
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4694
+ },
4695
+ fast: {
4696
+ type: "string",
4697
+ minLength: 1,
4698
+ maxLength: 300,
4699
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4700
+ },
4701
+ planning: {
4702
+ type: "string",
4703
+ minLength: 1,
4704
+ maxLength: 300,
4705
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4706
+ },
4707
+ review: {
4708
+ type: "string",
4709
+ minLength: 1,
4710
+ maxLength: 300,
4711
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4712
+ },
4713
+ summary: {
4714
+ type: "string",
4715
+ minLength: 1,
4716
+ maxLength: 300,
4717
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4718
+ },
4719
+ compaction: {
4720
+ type: "string",
4721
+ minLength: 1,
4722
+ maxLength: 300,
4723
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4724
+ },
4725
+ weak: {
4726
+ type: "string",
4727
+ minLength: 1,
4728
+ maxLength: 300,
4729
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4730
+ },
4731
+ editor: {
4732
+ type: "string",
4733
+ minLength: 1,
4734
+ maxLength: 300,
4735
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4736
+ }
4737
+ },
4738
+ additionalProperties: false
4739
+ },
4740
+ allowedModels: {
4741
+ type: "array",
4742
+ items: {
4743
+ type: "string",
4744
+ minLength: 1,
4745
+ maxLength: 300,
4746
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4747
+ },
4748
+ maxItems: 500
4749
+ },
4750
+ aliases: {
4751
+ type: "object",
4752
+ additionalProperties: {
4753
+ type: "string",
4754
+ minLength: 1,
4755
+ maxLength: 300,
4756
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4757
+ }
4758
+ },
4759
+ fallbacks: {
4760
+ type: "object",
4761
+ additionalProperties: {
4762
+ type: "array",
4763
+ items: {
4764
+ type: "string",
4765
+ minLength: 1,
4766
+ maxLength: 300,
4767
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4768
+ },
4769
+ maxItems: 20
4770
+ }
4771
+ }
4772
+ },
4773
+ additionalProperties: false
4774
+ },
4775
+ planToken: {
4776
+ type: "string",
4777
+ pattern: "^[a-f0-9]{64}$"
4778
+ },
4779
+ version: {
4780
+ type: "integer",
4781
+ exclusiveMinimum: true,
4782
+ minimum: 0
4783
+ },
4784
+ updatedAt: {
4785
+ type: "string"
4786
+ },
4787
+ providerId: {
4788
+ type: "string",
4789
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
4790
+ },
4791
+ providerVersion: {
4792
+ type: "integer",
4793
+ exclusiveMinimum: true,
4794
+ minimum: 0
4795
+ },
4796
+ profileVersion: {
4797
+ type: "integer",
4798
+ exclusiveMinimum: true,
4799
+ minimum: 0
4800
+ },
4801
+ id: {
4802
+ type: "string",
4803
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
4804
+ },
4805
+ status: {
4806
+ type: "string",
4807
+ enum: [
4808
+ "running",
4809
+ "exited",
4810
+ "failed",
4811
+ "interrupted"
4812
+ ]
4813
+ },
4814
+ startedAt: {
4815
+ type: "string"
4816
+ },
4817
+ endedAt: {
4818
+ type: "string"
4819
+ },
4820
+ exitCode: {
4821
+ type: "integer"
4822
+ },
4823
+ routingEvents: {
4824
+ type: "array",
4825
+ items: {
4826
+ type: "object",
4827
+ properties: {
4828
+ at: {
4829
+ type: "string",
4830
+ format: "date-time"
4831
+ },
4832
+ requestId: {
4833
+ type: "string",
4834
+ pattern: "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
4835
+ },
4836
+ requestedModel: {
4837
+ type: "string",
4838
+ minLength: 1,
4839
+ maxLength: 300,
4840
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4841
+ },
4842
+ resolvedModel: {
4843
+ type: "string",
4844
+ minLength: 1,
4845
+ maxLength: 300,
4846
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4847
+ },
4848
+ reportedModel: {
4849
+ type: "string",
4850
+ minLength: 1,
4851
+ maxLength: 300,
4852
+ pattern: "^[^\\u0000-\\u001f\\u007f]+$"
4853
+ },
4854
+ reasoningEffort: {
4855
+ type: "string",
4856
+ enum: [
4857
+ "none",
4858
+ "minimal",
4859
+ "low",
4860
+ "medium",
4861
+ "high",
4862
+ "xhigh",
4863
+ "max",
4864
+ "ultra"
4865
+ ]
4866
+ },
4867
+ decision: {
4868
+ type: "string",
4869
+ enum: [
4870
+ "allow",
4871
+ "alias",
4872
+ "reject",
4873
+ "fallback"
4874
+ ]
4875
+ },
4876
+ role: {
4877
+ type: "string",
4878
+ enum: [
4879
+ "main",
4880
+ "subagent",
4881
+ "fast",
4882
+ "planning",
4883
+ "review",
4884
+ "summary",
4885
+ "compaction",
4886
+ "weak",
4887
+ "editor"
4888
+ ]
4889
+ },
4890
+ reason: {
4891
+ type: "string",
4892
+ pattern: "^[a-z][a-z0-9_]{0,63}$"
4893
+ },
4894
+ upstreamStatus: {
4895
+ type: "integer",
4896
+ minimum: 100,
4897
+ maximum: 599
4898
+ }
4899
+ },
4900
+ required: [
4901
+ "at",
4902
+ "requestId",
4903
+ "requestedModel",
4904
+ "decision"
4905
+ ],
4906
+ additionalProperties: false
4907
+ },
4908
+ maxItems: 1000
4909
+ },
4910
+ routingEventsDropped: {
4911
+ type: "integer",
4912
+ minimum: 0,
4913
+ maximum: 1e6
4914
+ }
4915
+ },
4916
+ required: [
4917
+ "profileId",
4918
+ "harness",
4919
+ "model",
4920
+ "planToken",
4921
+ "version",
4922
+ "updatedAt",
4923
+ "providerId",
4924
+ "providerVersion",
4925
+ "profileVersion",
4926
+ "id",
4927
+ "status",
4928
+ "startedAt"
4929
+ ],
4930
+ additionalProperties: false
4931
+ },
4932
+ Health: {
4933
+ type: "object",
4934
+ properties: {
4935
+ status: {
4936
+ type: "string",
4937
+ enum: [
4938
+ "ok",
4939
+ "degraded",
4940
+ "unavailable"
4941
+ ]
4942
+ },
4943
+ version: {
4944
+ type: "string"
4945
+ },
4946
+ backend: {
4947
+ type: "string",
4948
+ enum: [
4949
+ "sqlite",
4950
+ "postgresql"
4951
+ ]
4952
+ }
4953
+ },
4954
+ required: [
4955
+ "status",
4956
+ "version",
4957
+ "backend"
4958
+ ],
4959
+ additionalProperties: false
4960
+ },
4961
+ Ready: {
4962
+ type: "object",
4963
+ properties: {
4964
+ ready: {
4965
+ type: "boolean"
4966
+ },
4967
+ reason: {
4968
+ type: "string"
4969
+ }
4970
+ },
4971
+ required: [
4972
+ "ready"
4973
+ ],
4974
+ additionalProperties: false
4975
+ },
4976
+ Version: {
4977
+ type: "object",
4978
+ properties: {
4979
+ version: {
4980
+ type: "string"
4981
+ }
4982
+ },
4983
+ required: [
4984
+ "version"
4985
+ ],
4986
+ additionalProperties: false
4987
+ },
4988
+ LaunchInput: {
4989
+ type: "object",
4990
+ properties: {
4991
+ profileId: {
4992
+ type: "string",
4993
+ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
4994
+ }
4995
+ },
4996
+ required: [
4997
+ "profileId"
4998
+ ],
4999
+ additionalProperties: false
5000
+ },
5001
+ Empty: {
5002
+ type: "object",
5003
+ properties: {},
5004
+ additionalProperties: false
5005
+ },
5006
+ Error: {
5007
+ type: "object",
5008
+ properties: {
5009
+ error: {
5010
+ type: "object",
5011
+ properties: {
5012
+ code: {
5013
+ type: "string"
5014
+ },
5015
+ message: {
5016
+ type: "string"
5017
+ },
5018
+ requestId: {
5019
+ type: "string"
5020
+ }
5021
+ },
5022
+ required: [
5023
+ "code",
5024
+ "message",
5025
+ "requestId"
5026
+ ],
5027
+ additionalProperties: false
5028
+ }
5029
+ },
5030
+ required: [
5031
+ "error"
5032
+ ],
5033
+ additionalProperties: false
5034
+ }
5035
+ }
5036
+ }
5037
+ };
5038
+
5039
+ // src/service.ts
5040
+ var snapshot = (profile, provider, catalog) => createHash2("sha256").update(JSON.stringify([profile, provider, { models: catalog.models, source: catalog.source }])).digest("hex");
5041
+ var hash = (s) => createHash2("sha256").update(s).digest();
5042
+ function createHandler(store, apiKey, providerEnv = process.env, resolveCredential) {
5043
+ if (!apiKey || apiKey.length < 24)
5044
+ throw new Fault(500, "auth_config", "Set HASNA_SWITCHER_API_KEY to a random token of at least 24 characters.");
5045
+ const expected = hash(`Bearer ${apiKey}`);
5046
+ return async (request) => {
5047
+ const requestId = crypto.randomUUID();
5048
+ const json = (body, status = 200) => Response.json(body, { status, headers: { "x-request-id": requestId, "cache-control": "no-store", "x-content-type-options": "nosniff" } });
5049
+ try {
5050
+ const url = new URL(request.url);
5051
+ const route2 = url.pathname.replace(/\/$/, "");
5052
+ if (request.method === "GET" && route2 === "/health")
5053
+ return json({ status: "ok", version: VERSION, backend: store.engine });
5054
+ if (request.method === "GET" && route2 === "/version")
5055
+ return json({ version: VERSION });
5056
+ if (request.method === "GET" && route2 === "/ready") {
5057
+ try {
5058
+ await store.ready();
5059
+ return json({ ready: true });
5060
+ } catch {
5061
+ return json({ ready: false, reason: "Storage is unavailable." }, 503);
5062
+ }
5063
+ }
5064
+ if (!timingSafeEqual(expected, hash(request.headers.get("authorization") ?? "")))
5065
+ throw new Fault(401, "unauthorized", "A valid API bearer token is required.");
5066
+ if (request.method === "GET" && ["/v1/openapi.json", "/openapi.json"].includes(route2))
5067
+ return json(openapi_default);
5068
+ const parts = route2.split("/").filter(Boolean);
5069
+ if (parts[0] !== "v1")
5070
+ throw new Fault(404, "not_found", "Route was not found.");
5071
+ const resource = parts[1];
5072
+ const id2 = parts[2];
5073
+ if (id2)
5074
+ parse(idSchema, id2);
5075
+ const page = () => parse(z4.object({
5076
+ limit: z4.coerce.number().int().min(1).max(1000).default(100),
5077
+ offset: z4.coerce.number().int().min(0).max(1e6).default(0),
5078
+ search: z4.string().max(200).default("")
5079
+ }).strict(), Object.fromEntries(url.searchParams));
5080
+ if (request.method === "GET") {
5081
+ if (resource === "provider-presets" && parts.length <= 3)
5082
+ return json(id2 ? getProviderPreset(id2) : { data: providerPresets });
5083
+ if (["providers", "profiles", "runs"].includes(resource) && parts.length <= 3) {
5084
+ const kind = resource;
5085
+ return json(id2 ? await store.get(kind, id2) : await store.list(kind, page()));
5086
+ }
5087
+ if (resource === "providers" && id2 && parts[3] === "models" && parts.length === 4) {
5088
+ const catalog = await store.get("catalogs", id2);
5089
+ const p = page();
5090
+ const filtered = catalog.models.filter((m) => [m.id, m.name].some((s) => s.toLowerCase().includes(p.search.toLowerCase())));
5091
+ return json({ ...catalog, models: undefined, data: filtered.slice(p.offset, p.offset + p.limit).map((m) => ({ ...m, codingEligible: codingEligible(m), expired: modelExpired(m) })), total: filtered.length, ...p });
5092
+ }
5093
+ throw new Fault(404, "not_found", "Route was not found.");
5094
+ }
5095
+ if (!["POST", "PUT", "PATCH", "DELETE"].includes(request.method))
5096
+ throw new Fault(405, "method_not_allowed", "Method is not supported.");
5097
+ const key = request.headers.get("idempotency-key");
5098
+ if (!key || !/^[a-zA-Z0-9._:-]{8,128}$/.test(key))
5099
+ throw new Fault(400, "idempotency_required", "Supply an Idempotency-Key of 8\u2013128 ASCII letters, digits, dots, colons, underscores or dashes.");
5100
+ let body = {};
5101
+ if (request.method !== "DELETE") {
5102
+ if (!request.headers.get("content-type")?.startsWith("application/json"))
5103
+ throw new Fault(415, "content_type", "Send application/json.");
5104
+ try {
5105
+ body = await boundedJson(request, 1024 * 1024);
5106
+ } catch {
5107
+ throw new Fault(400, "invalid_json", "Request must contain valid JSON under 1 MiB.");
5108
+ }
5109
+ }
5110
+ const fingerprint = hash(JSON.stringify([request.method, route2, body, request.headers.get("if-match")])).toString("hex");
5111
+ const version = () => {
5112
+ const v = request.headers.get("if-match");
5113
+ if (!v || !/^[1-9]\d*$/.test(v))
5114
+ throw new Fault(428, "version_required", "Supply the current numeric version in If-Match.");
5115
+ return Number(v);
5116
+ };
5117
+ const replay = await store.replay(key, fingerprint);
5118
+ if (replay.found)
5119
+ return json(replay.value, request.method === "POST" && ["providers", "profiles", "runs"].includes(resource) && !id2 ? 201 : 200);
5120
+ let refreshed;
5121
+ if (resource === "providers" && id2 && parts[3] === "refresh" && parts.length === 4 && request.method === "POST") {
5122
+ parse(z4.object({}).strict(), body);
5123
+ const provider = await store.get("providers", id2);
5124
+ refreshed = { provider, catalog: await discover(provider, providerEnv, resolveCredential) };
5125
+ }
5126
+ const result = await store.mutate(key, fingerprint, async (db) => {
5127
+ if ((resource === "providers" || resource === "profiles") && parts.length <= 3) {
5128
+ if (request.method === "DELETE" && id2)
5129
+ return store.remove(resource, id2, version(), db);
5130
+ if (request.method === "POST" && !id2 || request.method === "PUT" && id2) {
5131
+ const value = resource === "providers" ? parse(providerInputSchema, body) : parse(profileInputSchema, body);
5132
+ if (id2 && value.id !== id2)
5133
+ throw new Fault(400, "id_mismatch", "Path and body IDs must match.");
5134
+ if (resource === "profiles") {
5135
+ const profile = value;
5136
+ const provider = await store.get("providers", profile.providerId, db);
5137
+ validateHarnessProvider(profile.harness, provider);
5138
+ }
5139
+ const saved = await store.put(resource, value, id2 ? version() : undefined, db);
5140
+ if (resource === "providers" && id2)
5141
+ await db.unsafe("DELETE FROM switcher_catalogs WHERE id = $1", [id2]);
5142
+ return saved;
5143
+ }
5144
+ }
5145
+ if (resource === "providers" && id2 && parts[3] === "refresh" && parts.length === 4 && request.method === "POST") {
5146
+ if (store.engine === "postgresql")
5147
+ await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR SHARE", [id2]);
5148
+ const provider = await store.get("providers", id2, db);
5149
+ if (!refreshed || provider.version !== refreshed.provider.version)
5150
+ throw new Fault(409, "provider_changed", "Provider changed during discovery; refresh again.");
5151
+ const catalog = refreshed.catalog;
5152
+ let old;
5153
+ try {
5154
+ old = await store.get("catalogs", id2, db);
5155
+ } catch (e) {
5156
+ if (!(e instanceof Fault && e.status === 404))
5157
+ throw e;
5158
+ }
5159
+ return store.put("catalogs", { id: id2, ...catalog }, old?.version, db);
5160
+ }
5161
+ if (resource === "launch-plans" && !id2 && request.method === "POST") {
5162
+ const { profileId } = parse(z4.object({ profileId: idSchema }).strict(), body);
5163
+ const profile = await store.get("profiles", profileId, db);
5164
+ const provider = await store.get("providers", profile.providerId, db);
5165
+ validateHarnessProvider(profile.harness, provider);
5166
+ let catalog;
5167
+ try {
5168
+ catalog = await store.get("catalogs", provider.id, db);
5169
+ } catch (e) {
5170
+ if (e instanceof Fault && e.status === 404)
5171
+ throw new Fault(422, "catalog_missing", "Refresh the provider catalog before launching.");
5172
+ throw e;
5173
+ }
5174
+ const selected = catalog.models.find((m) => m.id === profile.model);
5175
+ if (!selected)
5176
+ throw new Fault(422, "model_missing", "Selected model is not in the provider catalog.");
5177
+ if (modelExpired(selected))
5178
+ throw new Fault(422, "model_expired", "Selected model has passed its configured expiry date. Select an unexpired model.");
5179
+ if (!harnessEligible(selected, profile.harness))
5180
+ throw new Fault(422, "model_ineligible", "Selected model is unavailable or explicitly lacks a required generation method, text output or tool support.");
5181
+ compileModelPolicy(profile.model, catalog.models.filter((model) => modelExpired(model) || harnessEligible(model, profile.harness)), profile.modelPolicy);
5182
+ const warnings = [];
5183
+ if (profile.harness !== "aider" && !selected.supportedParameters)
5184
+ warnings.push("Provider does not declare tool capabilities; execution compatibility is unverified.");
5185
+ if (profile.harness === "claude" && !/claude/i.test(profile.model))
5186
+ warnings.push("Anthropic does not support non-Claude models in Claude Code; this combination is experimental.");
5187
+ if (Date.now() - Date.parse(catalog.refreshedAt) > 300000)
5188
+ warnings.push("Catalog snapshot is older than five minutes; refresh before launching.");
5189
+ return { profile, provider, catalog, warnings, planToken: snapshot(profile, provider, catalog) };
5190
+ }
5191
+ if (resource === "runs" && !id2 && request.method === "POST") {
5192
+ if (body?.modelPolicyVersion !== 1)
5193
+ throw new Fault(409, "launcher_upgrade_required", "This API requires a launcher with automatic model policy version 1; upgrade the Switcher CLI/SDK.");
5194
+ const input = parse(runInputSchema, body);
5195
+ if (store.engine === "postgresql")
5196
+ await db.unsafe("SELECT id FROM switcher_profiles WHERE id = $1 FOR SHARE", [input.profileId]);
5197
+ const profile = await store.get("profiles", input.profileId, db);
5198
+ if (store.engine === "postgresql") {
5199
+ await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR SHARE", [profile.providerId]);
5200
+ await db.unsafe("SELECT id FROM switcher_catalogs WHERE id = $1 FOR SHARE", [profile.providerId]);
5201
+ }
5202
+ const provider = await store.get("providers", profile.providerId, db);
5203
+ let catalog;
5204
+ try {
5205
+ catalog = await store.get("catalogs", profile.providerId, db);
5206
+ } catch (error) {
5207
+ if (error instanceof Fault && error.status === 404)
5208
+ throw new Fault(409, "plan_changed", "Catalog changed; request a fresh launch plan.");
5209
+ throw error;
5210
+ }
5211
+ if (profile.harness !== input.harness || profile.model !== input.model || canonicalPolicyJSON(profile.modelPolicy ?? null) !== canonicalPolicyJSON(input.modelPolicy ?? profile.modelPolicy ?? null) || snapshot(profile, provider, catalog) !== input.planToken)
5212
+ throw new Fault(409, "plan_changed", "Provider, profile, model policy or catalog changed; request a fresh launch plan.");
5213
+ compileModelPolicy(profile.model, catalog.models.filter((model) => modelExpired(model) || harnessEligible(model, profile.harness)), profile.modelPolicy);
5214
+ return store.put("runs", { ...input, modelPolicy: profile.modelPolicy, providerId: provider.id, providerVersion: provider.version, profileVersion: profile.version, id: crypto.randomUUID(), status: "running", startedAt: new Date().toISOString() }, undefined, db);
5215
+ }
5216
+ if (resource === "runs" && id2 && request.method === "PATCH" && parts.length === 3) {
5217
+ const input = parse(runUpdateSchema, body);
5218
+ const run = await store.get("runs", id2, db);
5219
+ if (run.status !== "running")
5220
+ throw new Fault(409, "run_finished", "Run has already finished.");
5221
+ return store.put("runs", { ...run, ...input, endedAt: new Date().toISOString() }, version(), db);
5222
+ }
5223
+ throw new Fault(404, "not_found", "Route was not found.");
5224
+ });
5225
+ return json(result, request.method === "POST" && ["providers", "profiles", "runs"].includes(resource) && !id2 ? 201 : 200);
5226
+ } catch (error) {
5227
+ const safe = error instanceof Fault ? error : new Fault(500, "internal_error", "Request failed.");
5228
+ return json({ error: { code: safe.code, message: safe.message, requestId } }, safe.status);
5229
+ }
5230
+ };
5231
+ }
5232
+
5233
+ // src/server.ts
5234
+ async function startServer(options) {
5235
+ const port = options.port ?? 0;
5236
+ if (!Number.isInteger(port) || port < 0 || port > 65535)
5237
+ throw new Fault(400, "invalid_port", "Port must be an integer between 0 and 65535.");
5238
+ if (options.apiKey.length < 24 || /[\r\n]/.test(options.apiKey))
5239
+ throw new Fault(500, "auth_config", "Use a random operator token of at least 24 characters.");
5240
+ const store = await Store.open({ databaseUrl: options.databaseUrl, sqlitePath: options.sqlitePath });
5241
+ let server;
5242
+ try {
5243
+ server = Bun.serve({
5244
+ hostname: options.hostname ?? "127.0.0.1",
5245
+ port,
5246
+ maxRequestBodySize: 1024 * 1024,
5247
+ idleTimeout: 60,
5248
+ fetch: createHandler(store, options.apiKey, options.providerEnv, options.resolveCredential)
5249
+ });
5250
+ await store.ready();
5251
+ } catch (error) {
5252
+ await server?.stop(true);
5253
+ await store.close();
5254
+ throw error;
5255
+ }
5256
+ const listener = server;
5257
+ let closing;
5258
+ return {
5259
+ url: listener.url.href,
5260
+ storage: store.engine,
5261
+ close() {
5262
+ return closing ??= (async () => {
5263
+ try {
5264
+ await listener.stop(true);
5265
+ } finally {
5266
+ await store.close();
5267
+ }
5268
+ })();
5269
+ }
5270
+ };
5271
+ }
5272
+
5273
+ // src/runtime.ts
5274
+ import { resolveCredential as resolveClientCredential, clientTransportEnvKeys as clientTransportEnvKeys2, appConfigDiskValue, keychainConfigValue } from "@hasna/contracts/client";
5275
+
5276
+ // src/lib/local-opt-in.ts
5277
+ import {
5278
+ clientTransportEnvKeys,
5279
+ credentialDiskSources,
5280
+ credentialOverrideEnvKey,
5281
+ credentialPointerEnvKey,
5282
+ CREDENTIAL_PROFILE_ENV_KEY
5283
+ } from "@hasna/contracts/client";
5284
+ var SWITCHER_LOCAL_OPT_IN_ENV_KEYS = ["HASNA_SWITCHER_LOCAL", "SWITCHER_LOCAL"];
5285
+ var SWITCHER_KEYCHAIN_ITEM = "hasna.credentials.switcher.api-key";
5286
+ var SWITCHER_CREDENTIALS_FILE = "~/.hasna/switcher/config/credentials";
5287
+ function isSwitcherLocalOptIn(env = process.env) {
5288
+ return SWITCHER_LOCAL_OPT_IN_ENV_KEYS.some((key) => (env[key] ?? "").trim() !== "");
5289
+ }
5290
+ function switcherAuthorityEnvKeys() {
5291
+ const keys = clientTransportEnvKeys("switcher");
5292
+ return [
5293
+ ...keys.apiUrlKeys,
5294
+ ...keys.apiKeyKeys,
5295
+ credentialOverrideEnvKey("switcher"),
5296
+ credentialPointerEnvKey("switcher"),
5297
+ CREDENTIAL_PROFILE_ENV_KEY
5298
+ ];
5299
+ }
5300
+ function hasSwitcherEnvAuthorityIntent(env = process.env) {
5301
+ return switcherAuthorityEnvKeys().some((key) => env[key] !== undefined);
5302
+ }
5303
+ function switcherCredentialSources(env = process.env) {
5304
+ const disk = credentialDiskSources("switcher", env)[0];
5305
+ return [
5306
+ `Keychain item ${SWITCHER_KEYCHAIN_ITEM}`,
5307
+ disk ? `${SWITCHER_CREDENTIALS_FILE} (${disk})` : SWITCHER_CREDENTIALS_FILE,
5308
+ `${clientTransportEnvKeys("switcher").apiKeyKeys[0] ?? "HASNA_SWITCHER_API_KEY"} in the environment`
5309
+ ];
5310
+ }
5311
+ function remoteConfigMissingMessage(env = process.env) {
5312
+ return `No Switcher API credential is configured; consulted ${switcherCredentialSources(env).join(", ")}. ` + `Configure one of them, or set ${SWITCHER_LOCAL_OPT_IN_ENV_KEYS[0]}=1 (alias ${SWITCHER_LOCAL_OPT_IN_ENV_KEYS[1]}=1) to deliberately use the on-box local store. Nothing was read or created locally.`;
5313
+ }
5314
+ var announced = false;
5315
+ function announceSwitcherLocalMode(home, write = (line) => {
5316
+ process.stderr.write(line);
5317
+ }) {
5318
+ if (announced)
5319
+ return;
5320
+ announced = true;
5321
+ write(`switcher: LOCAL mode \u2014 using the on-box store under ${home} behind an owned per-process loopback API, not a hosted Switcher API (${SWITCHER_LOCAL_OPT_IN_ENV_KEYS[0]} is set; a configured API URL or key would outrank it).
5322
+ `);
5323
+ }
5324
+
5325
+ // src/runtime.ts
5326
+ var REMOTE_API_CONFIG_MISSING = "remote_api_config_missing";
5327
+ function switcherHome(env = process.env) {
5328
+ const override = env.HASNA_HOME?.trim();
5329
+ const root = override && isAbsolute(override) ? override : join(env.HOME?.trim() || homedir2(), ".hasna");
5330
+ return resolve2(env.HASNA_SWITCHER_HOME ?? join(root, "switcher"));
5331
+ }
5332
+ async function privateDirectory(path) {
5333
+ await mkdir2(path, { recursive: true, mode: 448 });
5334
+ const info = await lstat(path);
5335
+ if (!info.isDirectory() || info.isSymbolicLink())
5336
+ throw new Fault(500, "home_permissions", "Switcher data directory must be a real directory.");
5337
+ if (process.platform !== "win32" && ((info.mode & 63) !== 0 || info.uid !== process.getuid?.()))
5338
+ throw new Fault(500, "home_permissions", "Switcher data directory must be owned by this user and accessible only to its owner (mode 0700).");
5339
+ }
5340
+ async function openCliRuntime(env = process.env, resolveCredential) {
5341
+ const providerEnv = Object.fromEntries(Object.entries(env).filter(([name]) => name.startsWith("SWITCHER_PROVIDER_")));
5342
+ const remote = () => ({ client: clientFromEnv(env), mode: "remote", providerEnv, close: async () => {} });
5343
+ if (hasSwitcherEnvAuthorityIntent(env))
5344
+ return remote();
5345
+ if (!isSwitcherLocalOptIn(env)) {
5346
+ const keys = clientTransportEnvKeys2("switcher");
5347
+ const configured = resolveClientCredential("switcher", env) || keychainConfigValue("switcher", env) || appConfigDiskValue("switcher", env, keys.apiUrlKeys);
5348
+ if (configured)
5349
+ return remote();
5350
+ throw new Fault(401, REMOTE_API_CONFIG_MISSING, remoteConfigMissingMessage(env));
5351
+ }
5352
+ const home = switcherHome(env);
5353
+ announceSwitcherLocalMode(home);
5354
+ if (!env.HASNA_SWITCHER_DATABASE_URL && !env.HASNA_SWITCHER_SQLITE_PATH)
5355
+ await privateDirectory(home);
5356
+ const apiKey = randomBytes(32).toString("base64url");
5357
+ const service = await startServer({
5358
+ apiKey,
5359
+ databaseUrl: env.HASNA_SWITCHER_DATABASE_URL,
5360
+ sqlitePath: env.HASNA_SWITCHER_SQLITE_PATH ?? (env.HASNA_SWITCHER_DATABASE_URL ? undefined : join(home, "switcher.db")),
5361
+ providerEnv,
5362
+ resolveCredential
5363
+ });
5364
+ return { client: new SwitcherClient({ baseUrl: service.url, apiKey }), mode: "local", providerEnv, close: service.close };
5365
+ }
5366
+
546
5367
  // src/mcp.ts
547
5368
  var server = new McpServer({ name: "switcher", version: VERSION });
548
- var page = { limit: z4.number().int().min(1).max(1000).optional(), offset: z4.number().int().nonnegative().optional(), search: z4.string().optional() };
5369
+ var runtime;
5370
+ var clientFromEnv2 = () => {
5371
+ if (!runtime)
5372
+ throw new Fault(503, "unavailable", "Switcher API runtime is not open.");
5373
+ return runtime.client;
5374
+ };
5375
+ var page = { limit: z5.number().int().min(1).max(1000).optional(), offset: z5.number().int().nonnegative().optional(), search: z5.string().optional() };
549
5376
  function tool(name, description, schema, run) {
550
5377
  server.tool(name, description, schema, async (input) => {
551
5378
  try {
@@ -555,30 +5382,38 @@ function tool(name, description, schema, run) {
555
5382
  }
556
5383
  });
557
5384
  }
558
- tool("providers_list", "List provider profiles.", page, (p) => clientFromEnv().listProviders(p));
559
- tool("providers_get", "Get a provider.", { id: z4.string() }, (p) => clientFromEnv().getProvider(p.id));
560
- tool("providers_create", "Create a provider using credential environment references only.", providerInputSchema.innerType().shape, (p) => clientFromEnv().createProvider(p));
561
- tool("providers_update", "Replace a provider at its current version.", { provider: providerInputSchema, version: z4.number().int() }, (p) => clientFromEnv().updateProvider(p.provider, p.version));
562
- tool("providers_delete", "Delete an unreferenced provider.", { id: z4.string(), version: z4.number().int() }, (p) => clientFromEnv().deleteProvider(p.id, p.version));
563
- tool("models_list", "List catalog with capability information.", { id: z4.string(), ...page }, (p) => {
564
- const { id, ...rest } = p;
565
- return clientFromEnv().listModels(id, rest);
5385
+ tool("providers_list", "List provider profiles.", page, (p) => clientFromEnv2().listProviders(p));
5386
+ tool("providers_get", "Get a provider.", { id: z5.string() }, (p) => clientFromEnv2().getProvider(p.id));
5387
+ tool("providers_create", "Create a provider using credential environment references only.", providerInputSchema.innerType().shape, (p) => clientFromEnv2().createProvider(p));
5388
+ tool("providers_update", "Replace a provider at its current version.", { provider: providerInputSchema, version: z5.number().int() }, (p) => clientFromEnv2().updateProvider(p.provider, p.version));
5389
+ tool("providers_delete", "Delete an unreferenced provider.", { id: z5.string(), version: z5.number().int() }, (p) => clientFromEnv2().deleteProvider(p.id, p.version));
5390
+ tool("models_list", "List catalog with capability information.", { id: z5.string(), ...page }, (p) => {
5391
+ const { id: id2, ...rest } = p;
5392
+ return clientFromEnv2().listModels(id2, rest);
566
5393
  });
567
- tool("models_add", "Add saved model metadata; discovery stays active unless the provider uses a manual catalog.", { providerId: z4.string(), model: modelSchema }, (p) => clientFromEnv().addModel(p.providerId, p.model));
568
- tool("models_update", "Replace all saved metadata for a configured model.", { providerId: z4.string(), model: modelSchema }, (p) => clientFromEnv().updateModel(p.providerId, p.model));
569
- tool("models_remove", "Remove saved model metadata; upstream catalog entries remain.", { providerId: z4.string(), modelId: modelSchema.shape.id }, (p) => clientFromEnv().removeModel(p.providerId, p.modelId));
570
- tool("models_refresh", "Discover provider models.", { id: z4.string() }, (p) => clientFromEnv().refreshModels(p.id));
571
- tool("profiles_list", "List harness launch profiles.", page, (p) => clientFromEnv().listProfiles(p));
572
- tool("profiles_get", "Get a harness profile.", { id: z4.string() }, (p) => clientFromEnv().getProfile(p.id));
573
- tool("profiles_create", "Create a harness launch profile.", profileInputSchema.shape, (p) => clientFromEnv().createProfile(p));
574
- tool("profiles_update", "Replace a harness profile at its version.", { profile: profileInputSchema, version: z4.number().int() }, (p) => clientFromEnv().updateProfile(p.profile, p.version));
575
- tool("profiles_delete", "Delete a profile without run history.", { id: z4.string(), version: z4.number().int() }, (p) => clientFromEnv().deleteProfile(p.id, p.version));
576
- tool("launch_plan", "Validate a local launch plan; does not execute a remote process.", { profileId: z4.string() }, (p) => clientFromEnv().launchPlan(p.profileId));
577
- tool("runs_list", "List launch metadata.", page, (p) => clientFromEnv().listRuns(p));
578
- tool("runs_get", "Get launch metadata.", { id: z4.string() }, (p) => clientFromEnv().getRun(p.id));
5394
+ tool("models_add", "Add saved model metadata; discovery stays active unless the provider uses a manual catalog.", { providerId: z5.string(), model: modelSchema }, (p) => clientFromEnv2().addModel(p.providerId, p.model));
5395
+ tool("models_update", "Replace all saved metadata for a configured model.", { providerId: z5.string(), model: modelSchema }, (p) => clientFromEnv2().updateModel(p.providerId, p.model));
5396
+ tool("models_remove", "Remove saved model metadata; upstream catalog entries remain.", { providerId: z5.string(), modelId: modelSchema.shape.id }, (p) => clientFromEnv2().removeModel(p.providerId, p.modelId));
5397
+ tool("models_refresh", "Discover provider models.", { id: z5.string() }, (p) => clientFromEnv2().refreshModels(p.id));
5398
+ tool("profiles_list", "List harness launch profiles.", page, (p) => clientFromEnv2().listProfiles(p));
5399
+ tool("profiles_get", "Get a harness profile.", { id: z5.string() }, (p) => clientFromEnv2().getProfile(p.id));
5400
+ tool("profiles_create", "Create a harness launch profile.", profileInputSchema.shape, (p) => clientFromEnv2().createProfile(p));
5401
+ tool("profiles_update", "Replace a harness profile at its version.", { profile: profileInputSchema, version: z5.number().int() }, (p) => clientFromEnv2().updateProfile(p.profile, p.version));
5402
+ tool("profiles_delete", "Delete a profile without run history.", { id: z5.string(), version: z5.number().int() }, (p) => clientFromEnv2().deleteProfile(p.id, p.version));
5403
+ tool("launch_plan", "Validate a local launch plan; does not execute a remote process.", { profileId: z5.string() }, (p) => clientFromEnv2().launchPlan(p.profileId));
5404
+ tool("runs_list", "List launch metadata.", page, (p) => clientFromEnv2().listRuns(p));
5405
+ tool("runs_get", "Get launch metadata.", { id: z5.string() }, (p) => clientFromEnv2().getRun(p.id));
579
5406
  if (process.argv.includes("--version"))
580
5407
  console.log(VERSION);
581
5408
  else if (process.argv.includes("--help"))
582
- console.log("switcher-mcp: authenticated Switcher API tools over MCP stdio. Resolves API URL/key through @hasna/contracts (Keychain, canonical config/credentials, or environment).");
583
- else
5409
+ console.log("switcher-mcp: authenticated Switcher API tools over MCP stdio. Resolves API URL/key through @hasna/contracts (Keychain, canonical config/credentials, or environment). With nothing configured it exits 1 before answering initialize and names those sources; HASNA_SWITCHER_LOCAL=1 deliberately serves the on-box store instead.");
5410
+ else {
5411
+ try {
5412
+ runtime = await openCliRuntime(process.env);
5413
+ } catch (error) {
5414
+ const code = error instanceof Fault ? error.code : "remote_api_config_error";
5415
+ console.error(`${code.toUpperCase()}: ${error instanceof Error ? error.message : "Switcher API configuration could not be resolved."}`);
5416
+ process.exit(1);
5417
+ }
584
5418
  await server.connect(new StdioServerTransport);
5419
+ }