@asm-agent/coding-agent 0.8.7 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/_winjob.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/bash.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/harness.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/mcp.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/mcp_base.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/repl.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/test/__pycache__/test_agent_message_skill.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/test/__pycache__/test_bash.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/test/__pycache__/test_harness.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/test/__pycache__/test_mcp.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/test/__pycache__/test_mcp_base.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/test/__pycache__/test_repl.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/test/__pycache__/test_subagent_registry.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/test/__pycache__/test_winjob.cpython-313.pyc +0 -0
- package/dist/bundle/{anthropic-XSMQHGYB.js → anthropic-OFECORE7.js} +1 -1
- package/dist/bundle/{azure-openai-responses-XLQAIKKH.js → azure-openai-responses-AOVTLR6N.js} +2 -2
- package/dist/bundle/{bundled-modules-5OCN73BM.js → bundled-modules-JQCJDEIY.js} +3 -3
- package/dist/bundle/{chunk-2LPSALBF.js → chunk-7TB7CGPV.js} +11 -11
- package/dist/bundle/{chunk-YPNK4MRU.js → chunk-A65OM3TZ.js} +1 -1
- package/dist/bundle/{chunk-E3YE2Q7A.js → chunk-JC2TT4MZ.js} +33 -12
- package/dist/bundle/{chunk-IAQLPSMN.js → chunk-M67RGWDQ.js} +25 -6
- package/dist/bundle/{cli-main-QYX5R3LF.js → cli-main-FNHDQGQD.js} +3 -3
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/{google-ZXJEPWJA.js → google-RVJL6RIQ.js} +1 -1
- package/dist/bundle/{google-vertex-WAF3RIJ6.js → google-vertex-EZTRRRH6.js} +1 -1
- package/dist/bundle/{main-EOUAQCJH.js → main-IYXIIAJN.js} +3 -3
- package/dist/bundle/{mistral-GDZXSXRS.js → mistral-FSGKSMA7.js} +1 -1
- package/dist/bundle/{openai-codex-responses-7XMPW4LG.js → openai-codex-responses-VM5Y564D.js} +2 -2
- package/dist/bundle/{openai-completions-LNSVGDMF.js → openai-completions-X46FOQDN.js} +2 -2
- package/dist/bundle/{openai-responses-MFZOBMIT.js → openai-responses-SOQNEPBE.js} +2 -2
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +1 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/ollama-models.d.ts +3 -1
- package/dist/core/ollama-models.d.ts.map +1 -1
- package/dist/core/ollama-models.js +31 -10
- package/dist/core/ollama-models.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-registry.js","sourceRoot":"","sources":["../../src/core/model-registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MA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AAC,OAAQ;oBAC5C,SAAS,EAAE,QAAQ,CAAC,SAAS;oBAC7B,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;oBAC3C,KAAK,EAAE,QAAQ,CAAC,KAA6B;oBAC7C,IAAI,EAAE,QAAQ,CAAC,IAAI;oBACnB,aAAa,EAAE,QAAQ,CAAC,aAAa;oBACrC,SAAS,EAAE,QAAQ,CAAC,SAAS;oBAC7B,OAAO,EAAE,SAAS;oBAClB,MAAM,EAAE,QAAQ,CAAC,MAAM;iBACT,CAAC,CAAC;YAClB,CAAC;YACD,IAAI,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC;gBAChC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;gBAChD,IAAI,IAAI,EAAE,IAAI,KAAK,OAAO,EAAE,CAAC;oBAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAC5D,CAAC;YACF,CAAC;QACF,CAAC;aAAM,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YAC7C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;gBACpC,IAAI,CAAC,CAAC,QAAQ,KAAK,YAAY;oBAAE,OAAO,CAAC,CAAC;gBAC1C,OAAO;oBACN,GAAG,CAAC;oBACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO;iBACpC,CAAC;YAAA,CACF,CAAC,CAAC;QACJ,CAAC;IAAA,CACD;CACD","sourcesContent":["/**\n * Model registry - manages built-in and custom models, provides API key resolution.\n */\n\nimport { Buffer } from \"node:buffer\";\nimport { createHash } from \"node:crypto\";\nimport {\n\ttype AnthropicMessagesCompat,\n\ttype Api,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tgetModels,\n\tgetProviders,\n\ttype KnownProvider,\n\ttype Model,\n\ttype OAuthProviderInterface,\n\ttype OpenAICompletionsCompat,\n\ttype OpenAIResponsesCompat,\n\tregisterApiProvider,\n\tresetApiProviders,\n\ttype SimpleStreamOptions,\n} from \"@asm-agent/ai\";\nimport { registerBuiltinMcpOAuthProviders } from \"@asm-agent/ai/mcp\";\nimport { registerOAuthProvider, resetOAuthProviders } from \"@asm-agent/ai/oauth\";\nimport { existsSync, readFileSync, renameSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { type Static, type TProperties, Type } from \"typebox\";\nimport type { Validator } from \"typebox/compile\";\nimport type { TLocalizedValidationError } from \"typebox/error\";\nimport { getAgentDir } from \"../config.js\";\nimport type { AuthSourceToken, AuthStatus, AuthStorage } from \"./auth-storage.js\";\nimport { discoverOllamaModels } from \"./ollama-models.js\";\nimport { PRIME_INFERENCE_PROVIDER_ID } from \"./prime-inference-auth.js\";\nimport {\n\tfetchAuthorizedPrivatePrimeInferenceModelIds,\n\tgetPrivatePrimeInferenceModels,\n\tisPrivatePrimeInferenceModel,\n} from \"./prime-inference-models.js\";\nimport { BUILT_IN_PROVIDER_DISPLAY_NAMES } from \"./provider-display-names.js\";\nimport {\n\tclearConfigValueCache,\n\tresolveConfigValueOrThrow,\n\tresolveConfigValueUncached,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.js\";\n\nconst PercentileCutoffsSchema = Type.Object({\n\tp50: Type.Optional(Type.Number()),\n\tp75: Type.Optional(Type.Number()),\n\tp90: Type.Optional(Type.Number()),\n\tp99: Type.Optional(Type.Number()),\n});\n\nconst OpenRouterRoutingSchema = Type.Object({\n\tallow_fallbacks: Type.Optional(Type.Boolean()),\n\trequire_parameters: Type.Optional(Type.Boolean()),\n\tdata_collection: Type.Optional(Type.Union([Type.Literal(\"deny\"), Type.Literal(\"allow\")])),\n\tzdr: Type.Optional(Type.Boolean()),\n\tenforce_distillable_text: Type.Optional(Type.Boolean()),\n\torder: Type.Optional(Type.Array(Type.String())),\n\tonly: Type.Optional(Type.Array(Type.String())),\n\tignore: Type.Optional(Type.Array(Type.String())),\n\tquantizations: Type.Optional(Type.Array(Type.String())),\n\tsort: Type.Optional(\n\t\tType.Union([\n\t\t\tType.String(),\n\t\t\tType.Object({\n\t\t\t\tby: Type.Optional(Type.String()),\n\t\t\t\tpartition: Type.Optional(Type.Union([Type.String(), Type.Null()])),\n\t\t\t}),\n\t\t]),\n\t),\n\tmax_price: Type.Optional(\n\t\tType.Object({\n\t\t\tprompt: Type.Optional(Type.Union([Type.Number(), Type.String()])),\n\t\t\tcompletion: Type.Optional(Type.Union([Type.Number(), Type.String()])),\n\t\t\timage: Type.Optional(Type.Union([Type.Number(), Type.String()])),\n\t\t\taudio: Type.Optional(Type.Union([Type.Number(), Type.String()])),\n\t\t\trequest: Type.Optional(Type.Union([Type.Number(), Type.String()])),\n\t\t}),\n\t),\n\tpreferred_min_throughput: Type.Optional(Type.Union([Type.Number(), PercentileCutoffsSchema])),\n\tpreferred_max_latency: Type.Optional(Type.Union([Type.Number(), PercentileCutoffsSchema])),\n});\n\nconst VercelGatewayRoutingSchema = Type.Object({\n\tonly: Type.Optional(Type.Array(Type.String())),\n\torder: Type.Optional(Type.Array(Type.String())),\n});\n\nconst ThinkingLevelMapValueSchema = Type.Union([Type.String(), Type.Null()]);\nconst ThinkingLevelMapSchema = Type.Object({\n\toff: Type.Optional(ThinkingLevelMapValueSchema),\n\tminimal: Type.Optional(ThinkingLevelMapValueSchema),\n\tlow: Type.Optional(ThinkingLevelMapValueSchema),\n\tmedium: Type.Optional(ThinkingLevelMapValueSchema),\n\thigh: Type.Optional(ThinkingLevelMapValueSchema),\n\txhigh: Type.Optional(ThinkingLevelMapValueSchema),\n\tmax: Type.Optional(ThinkingLevelMapValueSchema),\n});\n\nconst OpenAICompletionsCompatSchema = Type.Object({\n\tsupportsStore: Type.Optional(Type.Boolean()),\n\tsupportsDeveloperRole: Type.Optional(Type.Boolean()),\n\tsupportsReasoningEffort: Type.Optional(Type.Boolean()),\n\tsupportsUsageInStreaming: Type.Optional(Type.Boolean()),\n\tmaxTokensField: Type.Optional(Type.Union([Type.Literal(\"max_completion_tokens\"), Type.Literal(\"max_tokens\")])),\n\trequiresToolResultName: Type.Optional(Type.Boolean()),\n\trequiresAssistantAfterToolResult: Type.Optional(Type.Boolean()),\n\trequiresThinkingAsText: Type.Optional(Type.Boolean()),\n\trequiresReasoningContentOnAssistantMessages: Type.Optional(Type.Boolean()),\n\tthinkingFormat: Type.Optional(\n\t\tType.Union([\n\t\t\tType.Literal(\"openai\"),\n\t\t\tType.Literal(\"openrouter\"),\n\t\t\tType.Literal(\"deepseek\"),\n\t\t\tType.Literal(\"zai\"),\n\t\t\tType.Literal(\"qwen\"),\n\t\t\tType.Literal(\"qwen-chat-template\"),\n\t\t]),\n\t),\n\tcacheControlFormat: Type.Optional(Type.Literal(\"anthropic\")),\n\topenRouterRouting: Type.Optional(OpenRouterRoutingSchema),\n\tvercelGatewayRouting: Type.Optional(VercelGatewayRoutingSchema),\n\tsupportsStrictMode: Type.Optional(Type.Boolean()),\n\tsupportsLongCacheRetention: Type.Optional(Type.Boolean()),\n});\n\nconst OpenAIResponsesCompatSchema = Type.Object({\n\tsendSessionIdHeader: Type.Optional(Type.Boolean()),\n\tsupportsLongCacheRetention: Type.Optional(Type.Boolean()),\n});\n\nconst AnthropicMessagesCompatSchema = Type.Object({\n\tsupportsEagerToolInputStreaming: Type.Optional(Type.Boolean()),\n\tsupportsLongCacheRetention: Type.Optional(Type.Boolean()),\n});\n\nconst ProviderCompatSchema = Type.Union([\n\tOpenAICompletionsCompatSchema,\n\tOpenAIResponsesCompatSchema,\n\tAnthropicMessagesCompatSchema,\n]);\n\n// Most fields are optional with sensible defaults for local models (Ollama, LM Studio, etc.)\nconst ModelDefinitionSchema = Type.Object({\n\tid: Type.String({ minLength: 1 }),\n\tname: Type.Optional(Type.String({ minLength: 1 })),\n\tapi: Type.Optional(Type.String({ minLength: 1 })),\n\tbaseUrl: Type.Optional(Type.String({ minLength: 1 })),\n\treasoning: Type.Optional(Type.Boolean()),\n\tthinkingLevelMap: Type.Optional(ThinkingLevelMapSchema),\n\tinput: Type.Optional(Type.Array(Type.Union([Type.Literal(\"text\"), Type.Literal(\"image\")]))),\n\tcost: Type.Optional(\n\t\tType.Object({\n\t\t\tinput: Type.Number(),\n\t\t\toutput: Type.Number(),\n\t\t\tcacheRead: Type.Number(),\n\t\t\tcacheWrite: Type.Number(),\n\t\t}),\n\t),\n\tcontextWindow: Type.Optional(Type.Number()),\n\tmaxTokens: Type.Optional(Type.Number()),\n\theaders: Type.Optional(Type.Record(Type.String(), Type.String())),\n\tcompat: Type.Optional(ProviderCompatSchema),\n});\n\nconst ModelOverrideSchema = Type.Object({\n\tname: Type.Optional(Type.String({ minLength: 1 })),\n\treasoning: Type.Optional(Type.Boolean()),\n\tthinkingLevelMap: Type.Optional(ThinkingLevelMapSchema),\n\tinput: Type.Optional(Type.Array(Type.Union([Type.Literal(\"text\"), Type.Literal(\"image\")]))),\n\tcost: Type.Optional(\n\t\tType.Object({\n\t\t\tinput: Type.Optional(Type.Number()),\n\t\t\toutput: Type.Optional(Type.Number()),\n\t\t\tcacheRead: Type.Optional(Type.Number()),\n\t\t\tcacheWrite: Type.Optional(Type.Number()),\n\t\t}),\n\t),\n\tcontextWindow: Type.Optional(Type.Number()),\n\tmaxTokens: Type.Optional(Type.Number()),\n\theaders: Type.Optional(Type.Record(Type.String(), Type.String())),\n\tcompat: Type.Optional(ProviderCompatSchema),\n});\n\ntype ModelOverride = Static<typeof ModelOverrideSchema>;\n\nconst ProviderConfigSchema = Type.Object({\n\tname: Type.Optional(Type.String({ minLength: 1 })),\n\tbaseUrl: Type.Optional(Type.String({ minLength: 1 })),\n\tapiKey: Type.Optional(Type.String({ minLength: 1 })),\n\tapi: Type.Optional(Type.String({ minLength: 1 })),\n\theaders: Type.Optional(Type.Record(Type.String(), Type.String())),\n\tcompat: Type.Optional(ProviderCompatSchema),\n\tauthHeader: Type.Optional(Type.Boolean()),\n\tmodels: Type.Optional(Type.Array(ModelDefinitionSchema)),\n\tmodelOverrides: Type.Optional(Type.Record(Type.String(), ModelOverrideSchema)),\n});\n\nconst ModelsConfigSchema = Type.Object({\n\tproviders: Type.Record(Type.String(), ProviderConfigSchema),\n});\n\n// typebox/compile costs ~300ms to import, so the models.json validator loads\n// lazily. The first load of an existing models.json proceeds on JSON parsing +\n// validateConfig() and reports schema errors asynchronously once the validator\n// is ready; subsequent refreshes validate synchronously.\nlet validateModelsConfig: Validator<TProperties, typeof ModelsConfigSchema> | undefined;\nlet modelsValidatorPromise: Promise<void> | undefined;\n\nfunction preloadModelsConfigValidator(): Promise<void> {\n\tmodelsValidatorPromise ??= import(\"typebox/compile\").then(({ Compile }) => {\n\t\tvalidateModelsConfig = Compile(ModelsConfigSchema);\n\t});\n\treturn modelsValidatorPromise;\n}\n\ntype ModelsConfig = Static<typeof ModelsConfigSchema>;\n\nfunction formatValidationPath(error: TLocalizedValidationError): string {\n\tif (error.keyword === \"required\") {\n\t\tconst requiredProperties = (error.params as { requiredProperties?: string[] }).requiredProperties;\n\t\tconst requiredProperty = requiredProperties?.[0];\n\t\tif (requiredProperty) {\n\t\t\tconst basePath = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\t\t\treturn basePath ? `${basePath}.${requiredProperty}` : requiredProperty;\n\t\t}\n\t}\n\tconst path = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\treturn path || \"root\";\n}\n\n/** Strip `//` line comments and trailing commas from JSON, leaving string literals untouched. */\nfunction stripJsonComments(input: string): string {\n\treturn input\n\t\t.replace(/\"(?:\\\\.|[^\"\\\\])*\"|\\/\\/[^\\n]*/g, (m) => (m[0] === '\"' ? m : \"\"))\n\t\t.replace(/\"(?:\\\\.|[^\"\\\\])*\"|,(\\s*[}\\]])/g, (m, tail) => tail ?? (m[0] === '\"' ? m : \"\"));\n}\n\n/** Provider override config (baseUrl, compat) without request auth/headers */\ninterface ProviderOverride {\n\tbaseUrl?: string;\n\tcompat?: Model<Api>[\"compat\"];\n}\n\ninterface ProviderRequestConfig {\n\tapiKey?: string;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n}\n\ntype ProviderRequestAuthSource = {\n\tsource: \"environment\" | \"models_json_key\" | \"models_json_command\";\n\tconfigured: true;\n\tlabel?: string;\n\tidentityFingerprint: string;\n\tvalueFingerprint?: string;\n\tresolveValueFingerprint?: () => string | undefined;\n};\n\nexport type ResolvedRequestAuth =\n\t| {\n\t\t\tok: true;\n\t\t\tapiKey?: string;\n\t\t\theaders?: Record<string, string>;\n\t }\n\t| {\n\t\t\tok: false;\n\t\t\terror: string;\n\t };\n\nexport interface ModelCatalogSnapshot {\n\tmodels: Model<Api>[];\n\tconfiguredProviders: string[];\n}\n\n/** Result of loading custom models from models.json */\ninterface CustomModelsResult {\n\tmodels: Model<Api>[];\n\t/** Providers with baseUrl/headers/apiKey overrides for built-in models */\n\toverrides: Map<string, ProviderOverride>;\n\t/** Per-model overrides: provider -> modelId -> override */\n\tmodelOverrides: Map<string, Map<string, ModelOverride>>;\n\terror: string | undefined;\n}\n\nfunction emptyCustomModelsResult(error?: string): CustomModelsResult {\n\treturn { models: [], overrides: new Map(), modelOverrides: new Map(), error };\n}\n\nfunction mergeCompat(\n\tbaseCompat: Model<Api>[\"compat\"],\n\toverrideCompat: ModelOverride[\"compat\"],\n): Model<Api>[\"compat\"] | undefined {\n\tif (!overrideCompat) return baseCompat;\n\n\tconst base = baseCompat as OpenAICompletionsCompat | OpenAIResponsesCompat | AnthropicMessagesCompat | undefined;\n\tconst override = overrideCompat as OpenAICompletionsCompat | OpenAIResponsesCompat | AnthropicMessagesCompat;\n\tconst merged = { ...base, ...override } as OpenAICompletionsCompat | OpenAIResponsesCompat | AnthropicMessagesCompat;\n\n\tconst baseCompletions = base as OpenAICompletionsCompat | undefined;\n\tconst overrideCompletions = override as OpenAICompletionsCompat;\n\tconst mergedCompletions = merged as OpenAICompletionsCompat;\n\n\tif (baseCompletions?.openRouterRouting || overrideCompletions.openRouterRouting) {\n\t\tmergedCompletions.openRouterRouting = {\n\t\t\t...baseCompletions?.openRouterRouting,\n\t\t\t...overrideCompletions.openRouterRouting,\n\t\t};\n\t}\n\n\tif (baseCompletions?.vercelGatewayRouting || overrideCompletions.vercelGatewayRouting) {\n\t\tmergedCompletions.vercelGatewayRouting = {\n\t\t\t...baseCompletions?.vercelGatewayRouting,\n\t\t\t...overrideCompletions.vercelGatewayRouting,\n\t\t};\n\t}\n\n\treturn merged as Model<Api>[\"compat\"];\n}\n\n/**\n * Deep merge a model override into a model.\n * Handles nested objects (cost, compat) by merging rather than replacing.\n */\nfunction applyModelOverride(model: Model<Api>, override: ModelOverride): Model<Api> {\n\tconst result = { ...model };\n\n\tif (override.name !== undefined) result.name = override.name;\n\tif (override.reasoning !== undefined) result.reasoning = override.reasoning;\n\tif (override.thinkingLevelMap !== undefined) {\n\t\tresult.thinkingLevelMap = { ...model.thinkingLevelMap, ...override.thinkingLevelMap };\n\t}\n\tif (override.input !== undefined) result.input = override.input as (\"text\" | \"image\")[];\n\tif (override.contextWindow !== undefined) result.contextWindow = override.contextWindow;\n\tif (override.maxTokens !== undefined) result.maxTokens = override.maxTokens;\n\n\tif (override.cost) {\n\t\tresult.cost = {\n\t\t\tinput: override.cost.input ?? model.cost.input,\n\t\t\toutput: override.cost.output ?? model.cost.output,\n\t\t\tcacheRead: override.cost.cacheRead ?? model.cost.cacheRead,\n\t\t\tcacheWrite: override.cost.cacheWrite ?? model.cost.cacheWrite,\n\t\t};\n\t}\n\n\tresult.compat = mergeCompat(model.compat, override.compat);\n\n\treturn result;\n}\n\n/** Clear the config value command cache. Exported for testing. */\nexport const clearApiKeyCache = clearConfigValueCache;\n\nfunction readOpenAICodexAccountId(token: string): string | undefined {\n\ttry {\n\t\tconst payload = JSON.parse(Buffer.from(token.split(\".\")[1] ?? \"\", \"base64url\").toString(\"utf8\")) as {\n\t\t\t\"https://api.openai.com/auth\"?: { chatgpt_account_id?: unknown };\n\t\t};\n\t\tconst accountId = payload[\"https://api.openai.com/auth\"]?.chatgpt_account_id;\n\t\treturn typeof accountId === \"string\" && accountId.length > 0 ? accountId : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * The Codex backend gates its model catalog on the reported client version: it answers HTTP 200 with a\n * catalog that grows as the version rises, so a low version yields a silently empty or partial list rather\n * than an error. ASM Agent's own package version is far below the Codex CLI's version line, so it must\n * report a supported Codex client version here instead.\n *\n * Shipping a new Codex model takes two edits, and both are required:\n * 1. Add the model to `codexModels` in `packages/ai/scripts/generate-models.ts` and regenerate. That list is\n * explicit, not fetched, so an unlisted model does not exist for ASM Agent at all.\n * 2. Raise this constant to a Codex CLI release whose catalog includes that model. `getExecutableModels()`\n * below intersects the registry with the discovered catalog, so a listed model the catalog omits is\n * dropped.\n *\n * Skipping step 2 fails silently and asymmetrically: `rlm` subagent delegation and `find_models()` resolve\n * through `getExecutableModels()` and lose the model, while `/model` reads the unfiltered `getAvailable()`\n * and keeps offering it.\n *\n * Catalog behaviour measured 2026-08-13; see #702.\n */\nconst OPENAI_CODEX_CLIENT_VERSION = \"0.147.0\";\n\nfunction openAICodexModelsUrl(baseUrl: string): string {\n\tconst normalized = baseUrl.replace(/\\/+$/, \"\");\n\tlet path: string;\n\tif (normalized.endsWith(\"/codex/responses\")) {\n\t\tpath = `${normalized.slice(0, -\"/responses\".length)}/models`;\n\t} else if (normalized.endsWith(\"/codex\")) {\n\t\tpath = `${normalized}/models`;\n\t} else {\n\t\tpath = `${normalized}/codex/models`;\n\t}\n\tconst url = new URL(path);\n\turl.searchParams.set(\"client_version\", OPENAI_CODEX_CLIENT_VERSION);\n\treturn url.toString();\n}\n\nfunction readOpenAICodexModelIds(value: unknown): Set<string> {\n\tif (!value || typeof value !== \"object\" || !(\"models\" in value) || !Array.isArray(value.models)) {\n\t\tthrow new Error(\"Invalid OpenAI Codex model catalog\");\n\t}\n\treturn new Set(\n\t\tvalue.models.flatMap((model) => {\n\t\t\tif (!model || typeof model !== \"object\" || !(\"slug\" in model) || typeof model.slug !== \"string\") {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\treturn [model.slug];\n\t\t}),\n\t);\n}\n\nconst PRIVATE_PRIME_AUTHORIZATION_CACHE_FILE = \"prime-inference-private-models.json\";\nconst PRIVATE_PRIME_AUTHORIZATION_CACHE_TTL_MS = 5 * 60_000;\nconst PRIVATE_PRIME_BACKGROUND_REFRESH_TIMEOUT_MS = 3_000;\n\ninterface PrivatePrimeAuthorizationCache {\n\tfingerprint: string;\n\tmodelIds: Set<string>;\n\trefreshedAt: number;\n}\n\nfunction privatePrimeAuthorizationFingerprint(apiKey: string, teamId: string): string {\n\treturn createHash(\"sha256\").update(apiKey).update(\"\\0\").update(teamId).digest(\"hex\");\n}\n\nfunction isOfflineModeEnabled(): boolean {\n\tconst value = process.env.PI_OFFLINE;\n\tif (!value) return false;\n\treturn value === \"1\" || value.toLowerCase() === \"true\" || value.toLowerCase() === \"yes\";\n}\n\n/**\n * Model registry - loads and manages models, resolves API keys via AuthStorage.\n */\nexport class ModelRegistry {\n\tprivate models: Model<Api>[] = [];\n\tprivate providerRequestConfigs: Map<string, ProviderRequestConfig> = new Map();\n\tprivate staleProviderRequestAuthSources: Map<string, AuthSourceToken[]> = new Map();\n\tprivate lastProviderAuthSourceTokens: Map<string, AuthSourceToken> = new Map();\n\tprivate modelRequestHeaders: Map<string, Record<string, string>> = new Map();\n\tprivate registeredProviders: Map<string, ProviderConfigInput> = new Map();\n\tprivate authorizedPrivatePrimeInferenceModelIds = new Set<string>();\n\tprivate authorizedPrivatePrimeInferenceTeamId: string | undefined;\n\tprivate explicitPrivatePrimeInferenceModelIds = new Set<string>();\n\tprivate openAICodexModelsCache: { authFingerprint: string; modelIds: Set<string>; refreshedAt: number } | undefined;\n\tprivate backgroundPrivatePrimeAuthorization: { fingerprint: string; promise: Promise<void> } | undefined;\n\tprivate loadError: string | undefined = undefined;\n\n\t/** Re-register dynamic OAuth providers (e.g. user MCP servers) after refresh() resets the registry. */\n\tprivate onOAuthProvidersReset?: () => void;\n\n\tprivate constructor(\n\t\treadonly authStorage: AuthStorage,\n\t\tprivate modelsJsonPath: string | undefined,\n\t) {\n\t\tthis.loadModels();\n\t}\n\n\tsetOnOAuthProvidersReset(hook: () => void): void {\n\t\tthis.onOAuthProvidersReset = hook;\n\t}\n\n\tstatic create(authStorage: AuthStorage, modelsJsonPath: string = join(getAgentDir(), \"models.json\")): ModelRegistry {\n\t\treturn new ModelRegistry(authStorage, modelsJsonPath);\n\t}\n\n\tstatic inMemory(authStorage: AuthStorage): ModelRegistry {\n\t\treturn new ModelRegistry(authStorage, undefined);\n\t}\n\n\t/**\n\t * Reload models from disk (built-in + custom from models.json).\n\t */\n\trefresh(): void {\n\t\tthis.providerRequestConfigs.clear();\n\t\tthis.modelRequestHeaders.clear();\n\t\tthis.lastProviderAuthSourceTokens.clear();\n\t\tthis.authorizedPrivatePrimeInferenceModelIds.clear();\n\t\tthis.authorizedPrivatePrimeInferenceTeamId = undefined;\n\t\tthis.explicitPrivatePrimeInferenceModelIds.clear();\n\t\tthis.loadError = undefined;\n\n\t\t// Credentials may have been written by another process (e.g. the UI\n\t\t// process saving a login while the session lives in the daemon).\n\t\tthis.authStorage.reload();\n\t\tresetApiProviders();\n\t\tresetOAuthProviders();\n\t\t// reset drops everything but model-provider built-ins; re-add MCP integrations\n\t\t// (built-in catalog + this session's user-declared servers via the hook).\n\t\t// NOTE: the OAuth registry is process-global. Built-in MCP providers are\n\t\t// identical across sessions so they always survive; a user-declared server\n\t\t// unique to another daemon session is dropped here and re-registered on that\n\t\t// session's next refresh. Fully isolating it would require a session-scoped\n\t\t// registry in pi-ai (out of scope here).\n\t\tregisterBuiltinMcpOAuthProviders();\n\t\tthis.onOAuthProvidersReset?.();\n\n\t\tthis.loadModels();\n\n\t\tfor (const [providerName, config] of this.registeredProviders.entries()) {\n\t\t\tthis.applyProviderConfig(providerName, config);\n\t\t}\n\t}\n\n\t/**\n\t * Get any error from loading models.json (undefined if no error).\n\t */\n\tgetError(): string | undefined {\n\t\treturn this.loadError;\n\t}\n\n\tprivate loadModels(): void {\n\t\tconst {\n\t\t\tmodels: customModels,\n\t\t\toverrides,\n\t\t\tmodelOverrides,\n\t\t\terror,\n\t\t} = this.modelsJsonPath ? this.loadCustomModels(this.modelsJsonPath) : emptyCustomModelsResult();\n\n\t\tif (error) {\n\t\t\tthis.loadError = error;\n\t\t}\n\n\t\tthis.explicitPrivatePrimeInferenceModelIds = new Set(\n\t\t\tcustomModels.filter(isPrivatePrimeInferenceModel).map((model) => model.id),\n\t\t);\n\t\tconst builtInModels = [...this.loadBuiltInModels(overrides, modelOverrides), ...getPrivatePrimeInferenceModels()];\n\t\tlet combined = this.mergeCustomModels(builtInModels, customModels);\n\n\t\tfor (const oauthProvider of this.authStorage.getOAuthProviders()) {\n\t\t\tconst cred = this.authStorage.get(oauthProvider.id);\n\t\t\tif (cred?.type === \"oauth\" && oauthProvider.modifyModels) {\n\t\t\t\tcombined = oauthProvider.modifyModels(combined, cred);\n\t\t\t}\n\t\t}\n\n\t\tthis.models = combined;\n\t}\n\n\t/** Load built-in models and apply provider/model overrides */\n\tprivate loadBuiltInModels(\n\t\toverrides: Map<string, ProviderOverride>,\n\t\tmodelOverrides: Map<string, Map<string, ModelOverride>>,\n\t): Model<Api>[] {\n\t\treturn getProviders().flatMap((provider) => {\n\t\t\tconst models = getModels(provider as KnownProvider) as Model<Api>[];\n\t\t\tconst providerOverride = overrides.get(provider);\n\t\t\tconst perModelOverrides = modelOverrides.get(provider);\n\n\t\t\treturn models.map((m) => {\n\t\t\t\tlet model = m;\n\n\t\t\t\tif (providerOverride) {\n\t\t\t\t\tmodel = {\n\t\t\t\t\t\t...model,\n\t\t\t\t\t\tbaseUrl: providerOverride.baseUrl ?? model.baseUrl,\n\t\t\t\t\t\tcompat: mergeCompat(model.compat, providerOverride.compat),\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst modelOverride = perModelOverrides?.get(m.id);\n\t\t\t\tif (modelOverride) {\n\t\t\t\t\tmodel = applyModelOverride(model, modelOverride);\n\t\t\t\t}\n\n\t\t\t\treturn model;\n\t\t\t});\n\t\t});\n\t}\n\n\t/** Merge custom models into built-in list by provider+id (custom wins on conflicts). */\n\tprivate mergeCustomModels(builtInModels: Model<Api>[], customModels: Model<Api>[]): Model<Api>[] {\n\t\tconst merged = [...builtInModels];\n\t\tfor (const customModel of customModels) {\n\t\t\tconst existingIndex = merged.findIndex((m) => m.provider === customModel.provider && m.id === customModel.id);\n\t\t\tif (existingIndex >= 0) {\n\t\t\t\tmerged[existingIndex] = customModel;\n\t\t\t} else {\n\t\t\t\tmerged.push(customModel);\n\t\t\t}\n\t\t}\n\t\treturn merged;\n\t}\n\n\tprivate loadCustomModels(modelsJsonPath: string): CustomModelsResult {\n\t\tif (!existsSync(modelsJsonPath)) {\n\t\t\treturn emptyCustomModelsResult();\n\t\t}\n\n\t\ttry {\n\t\t\tconst content = readFileSync(modelsJsonPath, \"utf-8\");\n\t\t\tconst parsed = JSON.parse(stripJsonComments(content)) as unknown;\n\n\t\t\tif (!validateModelsConfig) {\n\t\t\t\t// Validator not loaded yet (first refresh during startup): proceed on\n\t\t\t\t// validateConfig() below and report schema errors asynchronously once\n\t\t\t\t// the validator is ready. Later refreshes validate synchronously.\n\t\t\t\tvoid preloadModelsConfigValidator().then(() => {\n\t\t\t\t\tif (validateModelsConfig && !validateModelsConfig.Check(parsed)) {\n\t\t\t\t\t\tconst errors =\n\t\t\t\t\t\t\tvalidateModelsConfig\n\t\t\t\t\t\t\t\t.Errors(parsed)\n\t\t\t\t\t\t\t\t.map((error) => ` - ${formatValidationPath(error)}: ${error.message}`)\n\t\t\t\t\t\t\t\t.join(\"\\n\") || \"Unknown schema error\";\n\t\t\t\t\t\tconsole.error(`Invalid models.json schema:\\n${errors}\\n\\nFile: ${modelsJsonPath}`);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else if (!validateModelsConfig.Check(parsed)) {\n\t\t\t\tconst errors =\n\t\t\t\t\tvalidateModelsConfig\n\t\t\t\t\t\t.Errors(parsed)\n\t\t\t\t\t\t.map((error) => ` - ${formatValidationPath(error)}: ${error.message}`)\n\t\t\t\t\t\t.join(\"\\n\") || \"Unknown schema error\";\n\t\t\t\treturn emptyCustomModelsResult(`Invalid models.json schema:\\n${errors}\\n\\nFile: ${modelsJsonPath}`);\n\t\t\t}\n\n\t\t\tconst config = parsed as ModelsConfig;\n\n\t\t\tthis.validateConfig(config);\n\n\t\t\tconst overrides = new Map<string, ProviderOverride>();\n\t\t\tconst modelOverrides = new Map<string, Map<string, ModelOverride>>();\n\n\t\t\tfor (const [providerName, providerConfig] of Object.entries(config.providers)) {\n\t\t\t\tif (providerConfig.baseUrl || providerConfig.compat) {\n\t\t\t\t\toverrides.set(providerName, {\n\t\t\t\t\t\tbaseUrl: providerConfig.baseUrl,\n\t\t\t\t\t\tcompat: providerConfig.compat,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tthis.storeProviderRequestConfig(providerName, providerConfig);\n\n\t\t\t\tif (providerConfig.modelOverrides) {\n\t\t\t\t\tmodelOverrides.set(providerName, new Map(Object.entries(providerConfig.modelOverrides)));\n\t\t\t\t\tfor (const [modelId, modelOverride] of Object.entries(providerConfig.modelOverrides)) {\n\t\t\t\t\t\tthis.storeModelHeaders(providerName, modelId, modelOverride.headers);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { models: this.parseModels(config), overrides, modelOverrides, error: undefined };\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) {\n\t\t\t\treturn emptyCustomModelsResult(`Failed to parse models.json: ${error.message}\\n\\nFile: ${modelsJsonPath}`);\n\t\t\t}\n\t\t\treturn emptyCustomModelsResult(\n\t\t\t\t`Failed to load models.json: ${error instanceof Error ? error.message : error}\\n\\nFile: ${modelsJsonPath}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate validateConfig(config: ModelsConfig): void {\n\t\tconst builtInProviders = new Set<string>(getProviders());\n\n\t\tfor (const [providerName, providerConfig] of Object.entries(config.providers)) {\n\t\t\tconst isBuiltIn = builtInProviders.has(providerName);\n\t\t\tconst hasProviderApi = !!providerConfig.api;\n\t\t\tconst models = providerConfig.models ?? [];\n\t\t\tconst hasModelOverrides =\n\t\t\t\tproviderConfig.modelOverrides && Object.keys(providerConfig.modelOverrides).length > 0;\n\n\t\t\tif (models.length === 0) {\n\t\t\t\tif (!providerConfig.baseUrl && !providerConfig.headers && !providerConfig.compat && !hasModelOverrides) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Provider ${providerName}: must specify \"baseUrl\", \"headers\", \"compat\", \"modelOverrides\", or \"models\".`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (!isBuiltIn) {\n\t\t\t\tif (!providerConfig.baseUrl) {\n\t\t\t\t\tthrow new Error(`Provider ${providerName}: \"baseUrl\" is required when defining custom models.`);\n\t\t\t\t}\n\t\t\t\tif (!providerConfig.apiKey) {\n\t\t\t\t\tthrow new Error(`Provider ${providerName}: \"apiKey\" is required when defining custom models.`);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// inherited from built-in models. Auth comes from env vars / auth storage.\n\n\t\t\tfor (const modelDef of models) {\n\t\t\t\tconst hasModelApi = !!modelDef.api;\n\n\t\t\t\tif (!hasProviderApi && !hasModelApi && !isBuiltIn) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Provider ${providerName}, model ${modelDef.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (!modelDef.id) throw new Error(`Provider ${providerName}: model missing \"id\"`);\n\t\t\t\tif (modelDef.contextWindow !== undefined && modelDef.contextWindow <= 0)\n\t\t\t\t\tthrow new Error(`Provider ${providerName}, model ${modelDef.id}: invalid contextWindow`);\n\t\t\t\tif (modelDef.maxTokens !== undefined && modelDef.maxTokens <= 0)\n\t\t\t\t\tthrow new Error(`Provider ${providerName}, model ${modelDef.id}: invalid maxTokens`);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate parseModels(config: ModelsConfig): Model<Api>[] {\n\t\tconst models: Model<Api>[] = [];\n\t\tconst builtInProviders = new Set<string>(getProviders());\n\n\t\tconst builtInDefaultsCache = new Map<string, { api: string; baseUrl: string }>();\n\t\tconst getBuiltInDefaults = (providerName: string): { api: string; baseUrl: string } | undefined => {\n\t\t\tif (!builtInProviders.has(providerName)) return undefined;\n\t\t\tif (builtInDefaultsCache.has(providerName)) return builtInDefaultsCache.get(providerName);\n\t\t\tconst builtIn = getModels(providerName as KnownProvider) as Model<Api>[];\n\t\t\tif (builtIn.length === 0) return undefined;\n\t\t\tconst defaults = { api: builtIn[0].api, baseUrl: builtIn[0].baseUrl };\n\t\t\tbuiltInDefaultsCache.set(providerName, defaults);\n\t\t\treturn defaults;\n\t\t};\n\n\t\tfor (const [providerName, providerConfig] of Object.entries(config.providers)) {\n\t\t\tconst modelDefs = providerConfig.models ?? [];\n\t\t\tif (modelDefs.length === 0) continue; // Override-only, no custom models\n\n\t\t\tconst builtInDefaults = getBuiltInDefaults(providerName);\n\n\t\t\tfor (const modelDef of modelDefs) {\n\t\t\t\tconst api = modelDef.api ?? providerConfig.api ?? builtInDefaults?.api;\n\t\t\t\tif (!api) continue;\n\n\t\t\t\tconst baseUrl = modelDef.baseUrl ?? providerConfig.baseUrl ?? builtInDefaults?.baseUrl;\n\t\t\t\tif (!baseUrl) continue;\n\n\t\t\t\tconst compat = mergeCompat(providerConfig.compat, modelDef.compat);\n\t\t\t\tthis.storeModelHeaders(providerName, modelDef.id, modelDef.headers);\n\n\t\t\t\tconst defaultCost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };\n\t\t\t\tmodels.push({\n\t\t\t\t\tid: modelDef.id,\n\t\t\t\t\tname: modelDef.name ?? modelDef.id,\n\t\t\t\t\tapi: api as Api,\n\t\t\t\t\tprovider: providerName,\n\t\t\t\t\tbaseUrl,\n\t\t\t\t\treasoning: modelDef.reasoning ?? false,\n\t\t\t\t\tthinkingLevelMap: modelDef.thinkingLevelMap,\n\t\t\t\t\tinput: (modelDef.input ?? [\"text\"]) as (\"text\" | \"image\")[],\n\t\t\t\t\tcost: modelDef.cost ?? defaultCost,\n\t\t\t\t\tcontextWindow: modelDef.contextWindow ?? 128000,\n\t\t\t\t\tmaxTokens: modelDef.maxTokens ?? 16384,\n\t\t\t\t\theaders: undefined,\n\t\t\t\t\tcompat,\n\t\t\t\t} as Model<Api>);\n\t\t\t}\n\t\t}\n\n\t\treturn models;\n\t}\n\n\t/**\n\t * Get all models (built-in + custom).\n\t * If models.json had errors, returns only built-in models.\n\t */\n\tgetAll(): Model<Api>[] {\n\t\treturn this.models;\n\t}\n\n\t/**\n\t * Get only models that have auth configured.\n\t * This is a fast check that doesn't refresh OAuth tokens.\n\t */\n\tgetAvailable(): Model<Api>[] {\n\t\treturn this.models.filter((model) => {\n\t\t\tif (\n\t\t\t\tisPrivatePrimeInferenceModel(model) &&\n\t\t\t\t!this.explicitPrivatePrimeInferenceModelIds.has(model.id) &&\n\t\t\t\t!this.authorizedPrivatePrimeInferenceModelIds.has(model.id)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn this.hasConfiguredAuth(model);\n\t\t});\n\t}\n\n\tasync refreshAvailableModels(): Promise<Model<Api>[]> {\n\t\tconst previousPrivateModelIds = new Set(this.authorizedPrivatePrimeInferenceModelIds);\n\t\tconst previousTeamId = this.authorizedPrivatePrimeInferenceTeamId;\n\t\tthis.refresh();\n\t\tawait this.refreshPrivatePrimeInferenceAuthorization(previousPrivateModelIds, previousTeamId);\n\t\tconst ollamaModels = await discoverOllamaModels();\n\t\tif (ollamaModels.length > 0) {\n\t\t\tconst knownOllamaIds = new Set(\n\t\t\t\tthis.models.filter((model) => model.provider === \"ollama\").map((model) => model.id),\n\t\t\t);\n\t\t\tthis.models = [...this.models, ...ollamaModels.filter((model) => !knownOllamaIds.has(model.id))];\n\t\t}\n\t\treturn this.getAvailable();\n\t}\n\n\tprivate async refreshPrivatePrimeInferenceAuthorization(\n\t\tpreviousPrivateModelIds = new Set(this.authorizedPrivatePrimeInferenceModelIds),\n\t\tpreviousTeamId = this.authorizedPrivatePrimeInferenceTeamId,\n\t): Promise<void> {\n\t\tconst apiKey = await this.authStorage.getApiKey(PRIME_INFERENCE_PROVIDER_ID);\n\t\tconst teamHeaders = this.authStorage.getProviderHeaders(PRIME_INFERENCE_PROVIDER_ID);\n\t\tconst teamId = teamHeaders?.[\"X-Prime-Team-ID\"];\n\t\tif (!apiKey || !teamHeaders || !teamId) {\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds.clear();\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tconst fingerprint = privatePrimeAuthorizationFingerprint(apiKey, teamId);\n\t\tconst cached = this.readPrivatePrimeAuthorizationCache();\n\t\tif (cached?.fingerprint === fingerprint) {\n\t\t\t// Serve the persisted authorization decision so startup and model lists\n\t\t\t// don't block on the network. A stale cache refreshes in the background\n\t\t\t// and the updated ids apply to subsequent lookups in this process.\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds = new Set(cached.modelIds);\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = teamId;\n\t\t\tconst cacheIsFresh = Date.now() - cached.refreshedAt < PRIVATE_PRIME_AUTHORIZATION_CACHE_TTL_MS;\n\t\t\tif (cacheIsFresh || isOfflineModeEnabled()) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.startBackgroundPrivatePrimeAuthorizationRefresh(apiKey, teamHeaders, teamId, fingerprint);\n\t\t\treturn;\n\t\t}\n\t\tif (isOfflineModeEnabled()) {\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds.clear();\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tlet authorizedIds: Set<string> | undefined;\n\t\ttry {\n\t\t\tauthorizedIds = await fetchAuthorizedPrivatePrimeInferenceModelIds(apiKey, teamHeaders);\n\t\t} catch {\n\t\t\t// Fall back to the previous authorization below.\n\t\t}\n\t\t// Leave newer state untouched if the credentials changed while fetching.\n\t\tif ((await this.currentPrivatePrimeAuthorizationFingerprint()) !== fingerprint) {\n\t\t\treturn;\n\t\t}\n\t\tif (authorizedIds) {\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds = authorizedIds;\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = teamId;\n\t\t\tthis.writePrivatePrimeAuthorizationCache({ fingerprint, modelIds: authorizedIds, refreshedAt: Date.now() });\n\t\t} else if (teamId === previousTeamId) {\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds = previousPrivateModelIds;\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = teamId;\n\t\t} else {\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds.clear();\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Stale cache hits refresh in the background; failures keep the cached ids.\n\t * Refreshes for the same credentials are deduped, a changed-credentials\n\t * refresh is queued after the in-flight one, and a result is only applied\n\t * if the credentials it was fetched with are still current.\n\t */\n\tprivate startBackgroundPrivatePrimeAuthorizationRefresh(\n\t\tapiKey: string,\n\t\tteamHeaders: Record<string, string>,\n\t\tteamId: string,\n\t\tfingerprint: string,\n\t): void {\n\t\tif (this.backgroundPrivatePrimeAuthorization?.fingerprint === fingerprint) {\n\t\t\treturn;\n\t\t}\n\t\tconst run = async () => {\n\t\t\ttry {\n\t\t\t\tconst authorizedIds = await fetchAuthorizedPrivatePrimeInferenceModelIds(\n\t\t\t\t\tapiKey,\n\t\t\t\t\tteamHeaders,\n\t\t\t\t\tundefined,\n\t\t\t\t\tPRIVATE_PRIME_BACKGROUND_REFRESH_TIMEOUT_MS,\n\t\t\t\t);\n\t\t\t\tif ((await this.currentPrivatePrimeAuthorizationFingerprint()) !== fingerprint) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.authorizedPrivatePrimeInferenceModelIds = authorizedIds;\n\t\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = teamId;\n\t\t\t\tthis.writePrivatePrimeAuthorizationCache({ fingerprint, modelIds: authorizedIds, refreshedAt: Date.now() });\n\t\t\t} catch {\n\t\t\t\t// Keep the cached authorization.\n\t\t\t}\n\t\t};\n\t\tconst pending = this.backgroundPrivatePrimeAuthorization?.promise;\n\t\tconst promise = (pending ?? Promise.resolve()).then(run);\n\t\tthis.backgroundPrivatePrimeAuthorization = { fingerprint, promise };\n\t\tvoid promise.finally(() => {\n\t\t\tif (this.backgroundPrivatePrimeAuthorization?.promise === promise) {\n\t\t\t\tthis.backgroundPrivatePrimeAuthorization = undefined;\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async currentPrivatePrimeAuthorizationFingerprint(): Promise<string | undefined> {\n\t\tconst apiKey = await this.authStorage.getApiKey(PRIME_INFERENCE_PROVIDER_ID);\n\t\tconst teamId = this.authStorage.getProviderHeaders(PRIME_INFERENCE_PROVIDER_ID)?.[\"X-Prime-Team-ID\"];\n\t\treturn apiKey && teamId ? privatePrimeAuthorizationFingerprint(apiKey, teamId) : undefined;\n\t}\n\n\tprivate privatePrimeAuthorizationCachePath(): string | undefined {\n\t\tif (!this.modelsJsonPath) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn join(dirname(this.modelsJsonPath), PRIVATE_PRIME_AUTHORIZATION_CACHE_FILE);\n\t}\n\n\tprivate readPrivatePrimeAuthorizationCache(): PrivatePrimeAuthorizationCache | undefined {\n\t\tconst cachePath = this.privatePrimeAuthorizationCachePath();\n\t\tif (!cachePath) {\n\t\t\treturn undefined;\n\t\t}\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(readFileSync(cachePath, \"utf8\")) as Partial<\n\t\t\t\tOmit<PrivatePrimeAuthorizationCache, \"modelIds\"> & { modelIds: string[] }\n\t\t\t>;\n\t\t\tif (\n\t\t\t\ttypeof parsed.fingerprint !== \"string\" ||\n\t\t\t\t!Array.isArray(parsed.modelIds) ||\n\t\t\t\ttypeof parsed.refreshedAt !== \"number\"\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tfingerprint: parsed.fingerprint,\n\t\t\t\tmodelIds: new Set(parsed.modelIds),\n\t\t\t\trefreshedAt: parsed.refreshedAt,\n\t\t\t};\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate writePrivatePrimeAuthorizationCache(cache: PrivatePrimeAuthorizationCache): void {\n\t\tconst cachePath = this.privatePrimeAuthorizationCachePath();\n\t\tif (!cachePath) {\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tconst tmpPath = `${cachePath}.${process.pid}.tmp`;\n\t\t\twriteFileSync(tmpPath, JSON.stringify({ ...cache, modelIds: [...cache.modelIds] }), { mode: 0o600 });\n\t\t\trenameSync(tmpPath, cachePath);\n\t\t} catch {\n\t\t\t// A failed cache write only requires a later refetch.\n\t\t}\n\t}\n\n\tasync refreshModelCatalog(): Promise<ModelCatalogSnapshot> {\n\t\tconst availableModels = await this.refreshAvailableModels();\n\t\tconst availablePrivateModels = new Set(\n\t\t\tavailableModels.filter(isPrivatePrimeInferenceModel).map((model) => `${model.provider}/${model.id}`),\n\t\t);\n\t\treturn {\n\t\t\tmodels: this.models.filter(\n\t\t\t\t(model) =>\n\t\t\t\t\t!isPrivatePrimeInferenceModel(model) || availablePrivateModels.has(`${model.provider}/${model.id}`),\n\t\t\t),\n\t\t\tconfiguredProviders: [...new Set(availableModels.map((model) => model.provider))],\n\t\t};\n\t}\n\n\tasync canUseModel(model: Model<Api>): Promise<boolean> {\n\t\tif (!this.hasConfiguredAuth(model)) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!isPrivatePrimeInferenceModel(model)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst availableModels = await this.refreshAvailableModels();\n\t\treturn availableModels.some((candidate) => candidate.provider === model.provider && candidate.id === model.id);\n\t}\n\n\tasync getExecutableModels(): Promise<Model<Api>[]> {\n\t\tawait this.refreshPrivatePrimeInferenceAuthorization();\n\t\tconst availableModels = this.getAvailable();\n\t\tconst codexModels = availableModels.filter((model) => model.provider === \"openai-codex\");\n\t\tif (codexModels.length === 0) {\n\t\t\treturn availableModels;\n\t\t}\n\n\t\tconst auth = await this.getApiKeyAndHeaders(codexModels[0]!);\n\t\tif (!auth.ok || !auth.apiKey) {\n\t\t\treturn availableModels.filter((model) => model.provider !== \"openai-codex\");\n\t\t}\n\t\tconst authFingerprint = createHash(\"sha256\").update(auth.apiKey).digest(\"hex\");\n\t\tconst cached = this.openAICodexModelsCache;\n\t\tif (cached?.authFingerprint === authFingerprint && Date.now() - cached.refreshedAt < 300_000) {\n\t\t\treturn availableModels.filter((model) => model.provider !== \"openai-codex\" || cached.modelIds.has(model.id));\n\t\t}\n\n\t\tconst accountId = readOpenAICodexAccountId(auth.apiKey);\n\t\tif (!accountId) {\n\t\t\treturn availableModels.filter((model) => model.provider !== \"openai-codex\");\n\t\t}\n\t\ttry {\n\t\t\tconst response = await fetch(openAICodexModelsUrl(codexModels[0]!.baseUrl), {\n\t\t\t\theaders: {\n\t\t\t\t\t...auth.headers,\n\t\t\t\t\tAuthorization: `Bearer ${auth.apiKey}`,\n\t\t\t\t\t\"chatgpt-account-id\": accountId,\n\t\t\t\t\toriginator: \"pi\",\n\t\t\t\t},\n\t\t\t\tsignal: AbortSignal.timeout(5_000),\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`OpenAI Codex model discovery failed with HTTP ${response.status}`);\n\t\t\t}\n\t\t\tconst modelIds = readOpenAICodexModelIds(await response.json());\n\t\t\tthis.openAICodexModelsCache = { authFingerprint, modelIds, refreshedAt: Date.now() };\n\t\t\treturn availableModels.filter((model) => model.provider !== \"openai-codex\" || modelIds.has(model.id));\n\t\t} catch {\n\t\t\tif (cached?.authFingerprint === authFingerprint && Date.now() - cached.refreshedAt < 300_000) {\n\t\t\t\treturn availableModels.filter(\n\t\t\t\t\t(model) => model.provider !== \"openai-codex\" || cached.modelIds.has(model.id),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn availableModels.filter((model) => model.provider !== \"openai-codex\");\n\t\t}\n\t}\n\n\t/**\n\t * Find a model by provider and ID.\n\t */\n\tfind(provider: string, modelId: string): Model<Api> | undefined {\n\t\treturn this.models.find((m) => m.provider === provider && m.id === modelId);\n\t}\n\n\t/**\n\t * Get API key for a model.\n\t */\n\thasConfiguredAuth(model: Model<Api>): boolean {\n\t\tif (model.provider === \"ollama\") return true;\n\t\treturn this.authStorage.hasAuth(model.provider) || this.hasConfiguredProviderRequestAuth(model.provider);\n\t}\n\n\tprivate fingerprintProviderRequestAuthSource(source: ProviderRequestAuthSource[\"source\"], material: string): string {\n\t\tconst digest = createHash(\"sha256\").update(source).update(\"\\0\").update(material).digest(\"hex\");\n\t\treturn `${source}:${digest}`;\n\t}\n\n\tprivate createProviderRequestAuthSource(options: {\n\t\tsource: ProviderRequestAuthSource[\"source\"];\n\t\tidentityMaterial: string;\n\t\tvalueMaterial?: string;\n\t\tlabel?: string;\n\t\tresolveValueMaterial?: () => string | undefined;\n\t}): ProviderRequestAuthSource {\n\t\treturn {\n\t\t\tconfigured: true,\n\t\t\tsource: options.source,\n\t\t\t...(options.label ? { label: options.label } : {}),\n\t\t\tidentityFingerprint: this.fingerprintProviderRequestAuthSource(\n\t\t\t\toptions.source,\n\t\t\t\t`identity:${options.identityMaterial}`,\n\t\t\t),\n\t\t\t...(options.valueMaterial !== undefined\n\t\t\t\t? {\n\t\t\t\t\t\tvalueFingerprint: this.fingerprintProviderRequestAuthSource(\n\t\t\t\t\t\t\toptions.source,\n\t\t\t\t\t\t\t`value:${options.identityMaterial}\\0${options.valueMaterial}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...(options.resolveValueMaterial\n\t\t\t\t? {\n\t\t\t\t\t\tresolveValueFingerprint: () => {\n\t\t\t\t\t\t\tconst valueMaterial = options.resolveValueMaterial?.();\n\t\t\t\t\t\t\treturn valueMaterial === undefined\n\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t: this.fingerprintProviderRequestAuthSource(\n\t\t\t\t\t\t\t\t\t\toptions.source,\n\t\t\t\t\t\t\t\t\t\t`value:${options.identityMaterial}\\0${valueMaterial}`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t};\n\t}\n\n\tprivate getProviderRequestAuthSource(\n\t\tprovider: string,\n\t\toptions?: { resolvedApiKey?: string },\n\t): ProviderRequestAuthSource | undefined {\n\t\tconst providerApiKey = this.providerRequestConfigs.get(provider)?.apiKey;\n\t\tif (!providerApiKey) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (providerApiKey.startsWith(\"!\")) {\n\t\t\treturn this.createProviderRequestAuthSource({\n\t\t\t\tsource: \"models_json_command\",\n\t\t\t\tidentityMaterial: providerApiKey,\n\t\t\t\tvalueMaterial:\n\t\t\t\t\toptions?.resolvedApiKey === undefined ? undefined : `${providerApiKey}\\0${options.resolvedApiKey}`,\n\t\t\t\tresolveValueMaterial: () => {\n\t\t\t\t\tconst resolved = resolveConfigValueUncached(providerApiKey);\n\t\t\t\t\treturn resolved === undefined ? undefined : `${providerApiKey}\\0${resolved}`;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\tconst envValue = process.env[providerApiKey];\n\t\tif (envValue) {\n\t\t\treturn this.createProviderRequestAuthSource({\n\t\t\t\tsource: \"environment\",\n\t\t\t\tlabel: providerApiKey,\n\t\t\t\tidentityMaterial: providerApiKey,\n\t\t\t\tvalueMaterial: `${providerApiKey}\\0${envValue}`,\n\t\t\t});\n\t\t}\n\n\t\treturn this.createProviderRequestAuthSource({\n\t\t\tsource: \"models_json_key\",\n\t\t\tidentityMaterial: provider,\n\t\t\tvalueMaterial: providerApiKey,\n\t\t});\n\t}\n\n\tprivate isProviderRequestAuthStale(provider: string, source: ProviderRequestAuthSource): boolean {\n\t\tconst matchingStale = this.getMatchingStaleProviderRequestAuthSources(provider, source);\n\t\tif (matchingStale.length === 0) {\n\t\t\treturn false;\n\t\t}\n\t\tconst valueFingerprint = source.valueFingerprint ?? source.resolveValueFingerprint?.();\n\t\treturn Boolean(valueFingerprint && matchingStale.some((token) => token.valueFingerprint === valueFingerprint));\n\t}\n\n\tprivate isProviderRequestAuthStaleForStatus(provider: string, source: ProviderRequestAuthSource): boolean {\n\t\tconst matchingStale = this.getMatchingStaleProviderRequestAuthSources(provider, source);\n\t\tif (matchingStale.length === 0) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!source.valueFingerprint) {\n\t\t\treturn true;\n\t\t}\n\t\tconst isStale = matchingStale.some((token) => token.valueFingerprint === source.valueFingerprint);\n\t\tif (!isStale) {\n\t\t\tthis.clearStaleProviderRequestAuthSource(provider, source);\n\t\t}\n\t\treturn isStale;\n\t}\n\n\tprivate getMatchingStaleProviderRequestAuthSources(\n\t\tprovider: string,\n\t\tsource: ProviderRequestAuthSource,\n\t): AuthSourceToken[] {\n\t\tconst stale = this.staleProviderRequestAuthSources.get(provider);\n\t\tif (!stale) {\n\t\t\treturn [];\n\t\t}\n\t\treturn stale.filter(\n\t\t\t(token) => token.source === source.source && token.identityFingerprint === source.identityFingerprint,\n\t\t);\n\t}\n\n\tprivate clearStaleProviderRequestAuthSource(provider: string, source: ProviderRequestAuthSource): void {\n\t\tconst stale = this.staleProviderRequestAuthSources.get(provider);\n\t\tif (!stale) {\n\t\t\treturn;\n\t\t}\n\t\tconst next = stale.filter(\n\t\t\t(token) => token.source !== source.source || token.identityFingerprint !== source.identityFingerprint,\n\t\t);\n\t\tif (next.length === 0) {\n\t\t\tthis.staleProviderRequestAuthSources.delete(provider);\n\t\t} else {\n\t\t\tthis.staleProviderRequestAuthSources.set(provider, next);\n\t\t}\n\t}\n\n\tprivate getProviderRequestAuthSourceToken(\n\t\tprovider: string,\n\t\tsource: ProviderRequestAuthSource,\n\t): AuthSourceToken | undefined {\n\t\tconst valueFingerprint = source.valueFingerprint ?? source.resolveValueFingerprint?.();\n\t\tif (!valueFingerprint) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tprovider,\n\t\t\tsource: source.source,\n\t\t\tidentityFingerprint: source.identityFingerprint,\n\t\t\tvalueFingerprint,\n\t\t};\n\t}\n\n\tprivate setLastProviderAuthSourceToken(provider: string, token: AuthSourceToken | undefined): void {\n\t\tif (token) {\n\t\t\tthis.lastProviderAuthSourceTokens.set(provider, token);\n\t\t} else {\n\t\t\tthis.lastProviderAuthSourceTokens.delete(provider);\n\t\t}\n\t}\n\n\tprivate hasConfiguredProviderRequestAuth(provider: string): boolean {\n\t\tconst source = this.getProviderRequestAuthSource(provider);\n\t\treturn source !== undefined && !this.isProviderRequestAuthStaleForStatus(provider, source);\n\t}\n\n\tmarkProviderAuthStale(provider: string): boolean {\n\t\tif (this.authStorage.markAuthStale(provider)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst token = this.getCurrentProviderAuthSourceToken(provider);\n\t\treturn token ? this.markProviderAuthSourceStale(token) : false;\n\t}\n\n\tgetCurrentProviderAuthSourceToken(provider: string): AuthSourceToken | undefined {\n\t\tconst lastRequestToken = this.lastProviderAuthSourceTokens.get(provider);\n\t\tif (lastRequestToken) {\n\t\t\treturn lastRequestToken;\n\t\t}\n\n\t\tconst authStorageToken = this.authStorage.getCurrentAuthSourceToken(provider);\n\t\tif (authStorageToken) {\n\t\t\treturn authStorageToken;\n\t\t}\n\n\t\tconst providerApiKey = this.providerRequestConfigs.get(provider)?.apiKey;\n\t\tif (!providerApiKey) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst resolvedApiKey = resolveConfigValueUncached(providerApiKey);\n\t\tconst source = this.getProviderRequestAuthSource(provider, { resolvedApiKey });\n\t\tconst valueFingerprint = source?.valueFingerprint ?? source?.resolveValueFingerprint?.();\n\t\tif (!source || !valueFingerprint || this.isProviderRequestAuthStale(provider, source)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tprovider,\n\t\t\tsource: source.source,\n\t\t\tidentityFingerprint: source.identityFingerprint,\n\t\t\tvalueFingerprint,\n\t\t};\n\t}\n\n\tmarkProviderAuthSourceStale(token: AuthSourceToken): boolean {\n\t\tlet marked = false;\n\t\tconst providerRequestSource = this.getProviderRequestAuthSource(token.provider);\n\t\tif (\n\t\t\tproviderRequestSource?.source === token.source &&\n\t\t\tproviderRequestSource.identityFingerprint === token.identityFingerprint\n\t\t) {\n\t\t\tconst stale = this.staleProviderRequestAuthSources.get(token.provider) ?? [];\n\t\t\tif (\n\t\t\t\t!stale.some(\n\t\t\t\t\t(existing) =>\n\t\t\t\t\t\texisting.source === token.source &&\n\t\t\t\t\t\texisting.identityFingerprint === token.identityFingerprint &&\n\t\t\t\t\t\texisting.valueFingerprint === token.valueFingerprint,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tstale.push(token);\n\t\t\t}\n\t\t\tthis.staleProviderRequestAuthSources.set(token.provider, stale);\n\t\t\tmarked = true;\n\t\t}\n\n\t\tif (token.source !== \"models_json_key\" && token.source !== \"models_json_command\") {\n\t\t\tmarked = this.authStorage.markAuthSourceStale(token) || marked;\n\t\t}\n\n\t\treturn marked;\n\t}\n\n\tprivate getModelRequestKey(provider: string, modelId: string): string {\n\t\treturn `${provider}:${modelId}`;\n\t}\n\n\tprivate storeProviderRequestConfig(\n\t\tproviderName: string,\n\t\tconfig: {\n\t\t\tapiKey?: string;\n\t\t\theaders?: Record<string, string>;\n\t\t\tauthHeader?: boolean;\n\t\t},\n\t): void {\n\t\tif (!config.apiKey && !config.headers && !config.authHeader) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.providerRequestConfigs.set(providerName, {\n\t\t\tapiKey: config.apiKey,\n\t\t\theaders: config.headers,\n\t\t\tauthHeader: config.authHeader,\n\t\t});\n\t}\n\n\tprivate storeModelHeaders(providerName: string, modelId: string, headers?: Record<string, string>): void {\n\t\tconst key = this.getModelRequestKey(providerName, modelId);\n\t\tif (!headers || Object.keys(headers).length === 0) {\n\t\t\tthis.modelRequestHeaders.delete(key);\n\t\t\treturn;\n\t\t}\n\t\tthis.modelRequestHeaders.set(key, headers);\n\t}\n\n\t/**\n\t * Get API key and request headers for a model.\n\t */\n\tasync getApiKeyAndHeaders(model: Model<Api>): Promise<ResolvedRequestAuth> {\n\t\ttry {\n\t\t\tconst providerConfig = this.providerRequestConfigs.get(model.provider);\n\t\t\tconst authStorageAuth = await this.authStorage.getApiKeyWithSourceToken(model.provider, {\n\t\t\t\tincludeFallback: false,\n\t\t\t});\n\t\t\tlet apiKey = authStorageAuth.apiKey;\n\t\t\tlet authSourceToken = authStorageAuth.sourceToken;\n\t\t\tif (apiKey === undefined && providerConfig?.apiKey) {\n\t\t\t\tconst resolvedApiKey = resolveConfigValueOrThrow(\n\t\t\t\t\tproviderConfig.apiKey,\n\t\t\t\t\t`API key for provider \"${model.provider}\"`,\n\t\t\t\t);\n\t\t\t\tconst providerRequestAuthSource = this.getProviderRequestAuthSource(model.provider, { resolvedApiKey });\n\t\t\t\tif (\n\t\t\t\t\tproviderRequestAuthSource &&\n\t\t\t\t\t!this.isProviderRequestAuthStale(model.provider, providerRequestAuthSource)\n\t\t\t\t) {\n\t\t\t\t\tthis.clearStaleProviderRequestAuthSource(model.provider, providerRequestAuthSource);\n\t\t\t\t\tapiKey = resolvedApiKey;\n\t\t\t\t\tauthSourceToken = this.getProviderRequestAuthSourceToken(model.provider, providerRequestAuthSource);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.setLastProviderAuthSourceToken(model.provider, apiKey === undefined ? undefined : authSourceToken);\n\n\t\t\tconst providerHeaders = resolveHeadersOrThrow(providerConfig?.headers, `provider \"${model.provider}\"`);\n\t\t\tconst authStorageHeaders = this.authStorage.getProviderHeaders(model.provider);\n\t\t\tconst modelHeaders = resolveHeadersOrThrow(\n\t\t\t\tthis.modelRequestHeaders.get(this.getModelRequestKey(model.provider, model.id)),\n\t\t\t\t`model \"${model.provider}/${model.id}\"`,\n\t\t\t);\n\n\t\t\tlet headers =\n\t\t\t\tmodel.headers || authStorageHeaders || providerHeaders || modelHeaders\n\t\t\t\t\t? { ...model.headers, ...authStorageHeaders, ...providerHeaders, ...modelHeaders }\n\t\t\t\t\t: undefined;\n\n\t\t\tif (providerConfig?.authHeader) {\n\t\t\t\tif (!apiKey) {\n\t\t\t\t\treturn { ok: false, error: `No API key found for \"${model.provider}\"` };\n\t\t\t\t}\n\t\t\t\theaders = { ...headers, Authorization: `Bearer ${apiKey}` };\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tapiKey,\n\t\t\t\theaders: headers && Object.keys(headers).length > 0 ? headers : undefined,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Return auth status for a provider, including request auth configured in models.json.\n\t * This intentionally does not execute command-backed config values.\n\t */\n\tgetProviderAuthStatus(provider: string): AuthStatus {\n\t\tconst authStatus = this.authStorage.getAuthStatus(provider);\n\t\tif (authStatus.source && authStatus.source !== \"stale\") {\n\t\t\treturn authStatus;\n\t\t}\n\n\t\tconst source = this.getProviderRequestAuthSource(provider);\n\t\tif (!source) {\n\t\t\treturn authStatus;\n\t\t}\n\n\t\tif (this.isProviderRequestAuthStaleForStatus(provider, source)) {\n\t\t\treturn { configured: false, source: \"stale\", label: \"expired\" };\n\t\t}\n\n\t\treturn {\n\t\t\tconfigured: true,\n\t\t\tsource: source.source,\n\t\t\t...(source.label ? { label: source.label } : {}),\n\t\t};\n\t}\n\n\t/**\n\t * Get display name for a provider.\n\t */\n\tgetProviderDisplayName(provider: string): string {\n\t\tconst registeredProvider = this.registeredProviders.get(provider);\n\t\tconst oauthProvider = this.authStorage.getOAuthProviders().find((p) => p.id === provider);\n\n\t\treturn (\n\t\t\tregisteredProvider?.name ??\n\t\t\tregisteredProvider?.oauth?.name ??\n\t\t\toauthProvider?.name ??\n\t\t\tBUILT_IN_PROVIDER_DISPLAY_NAMES[provider] ??\n\t\t\tprovider\n\t\t);\n\t}\n\n\t/**\n\t * Get API key for a provider.\n\t */\n\tasync getApiKeyForProvider(provider: string): Promise<string | undefined> {\n\t\tconst authStorageAuth = await this.authStorage.getApiKeyWithSourceToken(provider, { includeFallback: false });\n\t\tif (authStorageAuth.apiKey !== undefined) {\n\t\t\tthis.setLastProviderAuthSourceToken(provider, authStorageAuth.sourceToken);\n\t\t\treturn authStorageAuth.apiKey;\n\t\t}\n\n\t\tconst providerApiKey = this.providerRequestConfigs.get(provider)?.apiKey;\n\t\tif (!providerApiKey) {\n\t\t\tthis.setLastProviderAuthSourceToken(provider, undefined);\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst resolvedApiKey = resolveConfigValueUncached(providerApiKey);\n\t\tif (resolvedApiKey === undefined) {\n\t\t\tthis.setLastProviderAuthSourceToken(provider, undefined);\n\t\t\treturn undefined;\n\t\t}\n\t\tconst source = this.getProviderRequestAuthSource(provider, { resolvedApiKey });\n\t\tif (!source || this.isProviderRequestAuthStale(provider, source)) {\n\t\t\tthis.setLastProviderAuthSourceToken(provider, undefined);\n\t\t\treturn undefined;\n\t\t}\n\t\tthis.clearStaleProviderRequestAuthSource(provider, source);\n\t\tthis.setLastProviderAuthSourceToken(provider, this.getProviderRequestAuthSourceToken(provider, source));\n\n\t\treturn resolvedApiKey;\n\t}\n\n\t/**\n\t * Check if a model is using OAuth credentials (subscription).\n\t */\n\tisUsingOAuth(model: Model<Api>): boolean {\n\t\tconst cred = this.authStorage.get(model.provider);\n\t\treturn cred?.type === \"oauth\";\n\t}\n\n\t/**\n\t * Register a provider dynamically (from extensions).\n\t *\n\t * If provider has models: replaces all existing models for this provider.\n\t * If provider has only baseUrl/headers: overrides existing models' URLs.\n\t * If provider has oauth: registers OAuth provider for /login support.\n\t */\n\tregisterProvider(providerName: string, config: ProviderConfigInput): void {\n\t\tthis.validateProviderConfig(providerName, config);\n\t\tthis.applyProviderConfig(providerName, config);\n\t\tthis.upsertRegisteredProvider(providerName, config);\n\t}\n\n\t/**\n\t * Unregister a previously registered provider.\n\t *\n\t * Removes the provider from the registry and reloads models from disk so that\n\t * built-in models overridden by this provider are restored to their original state.\n\t * Also resets dynamic OAuth and API stream registrations before reapplying\n\t * remaining dynamic providers.\n\t * Has no effect if the provider was never registered.\n\t */\n\tunregisterProvider(providerName: string): void {\n\t\tif (!this.registeredProviders.has(providerName)) return;\n\t\tthis.registeredProviders.delete(providerName);\n\t\tthis.refresh();\n\t}\n\n\t/**\n\t * Upsert a provider config into registeredProviders.\n\t * If the provider is already registered, defined values in the incoming config\n\t * override existing ones; undefined values are preserved from the stored config.\n\t * If the provider is not registered, the incoming config is stored as-is.\n\t */\n\tprivate upsertRegisteredProvider(providerName: string, config: ProviderConfigInput): void {\n\t\tconst existing = this.registeredProviders.get(providerName);\n\t\tif (!existing) {\n\t\t\tthis.registeredProviders.set(providerName, config);\n\t\t\treturn;\n\t\t}\n\t\tfor (const k of Object.keys(config) as (keyof ProviderConfigInput)[]) {\n\t\t\tif (config[k] !== undefined) {\n\t\t\t\t(existing as Record<string, unknown>)[k] = config[k];\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate validateProviderConfig(providerName: string, config: ProviderConfigInput): void {\n\t\tif (config.streamSimple && !config.api) {\n\t\t\tthrow new Error(`Provider ${providerName}: \"api\" is required when registering streamSimple.`);\n\t\t}\n\n\t\tif (!config.models || config.models.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (!config.baseUrl) {\n\t\t\tthrow new Error(`Provider ${providerName}: \"baseUrl\" is required when defining models.`);\n\t\t}\n\t\tif (!config.apiKey && !config.oauth) {\n\t\t\tthrow new Error(`Provider ${providerName}: \"apiKey\" or \"oauth\" is required when defining models.`);\n\t\t}\n\n\t\tfor (const modelDef of config.models) {\n\t\t\tconst api = modelDef.api || config.api;\n\t\t\tif (!api) {\n\t\t\t\tthrow new Error(`Provider ${providerName}, model ${modelDef.id}: no \"api\" specified.`);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate applyProviderConfig(providerName: string, config: ProviderConfigInput): void {\n\t\tif (config.oauth) {\n\t\t\tconst oauthProvider: OAuthProviderInterface = {\n\t\t\t\t...config.oauth,\n\t\t\t\tid: providerName,\n\t\t\t};\n\t\t\tregisterOAuthProvider(oauthProvider);\n\t\t}\n\n\t\tif (config.streamSimple) {\n\t\t\tconst streamSimple = config.streamSimple;\n\t\t\tregisterApiProvider(\n\t\t\t\t{\n\t\t\t\t\tapi: config.api!,\n\t\t\t\t\tstream: (model, context, options) => streamSimple(model, context, options as SimpleStreamOptions),\n\t\t\t\t\tstreamSimple,\n\t\t\t\t},\n\t\t\t\t`provider:${providerName}`,\n\t\t\t);\n\t\t}\n\n\t\tthis.storeProviderRequestConfig(providerName, config);\n\n\t\tif (config.models && config.models.length > 0) {\n\t\t\tthis.models = this.models.filter((m) => m.provider !== providerName);\n\n\t\t\tfor (const modelDef of config.models) {\n\t\t\t\tconst api = modelDef.api || config.api;\n\t\t\t\tthis.storeModelHeaders(providerName, modelDef.id, modelDef.headers);\n\n\t\t\t\tthis.models.push({\n\t\t\t\t\tid: modelDef.id,\n\t\t\t\t\tname: modelDef.name,\n\t\t\t\t\tapi: api as Api,\n\t\t\t\t\tprovider: providerName,\n\t\t\t\t\tbaseUrl: modelDef.baseUrl ?? config.baseUrl!,\n\t\t\t\t\treasoning: modelDef.reasoning,\n\t\t\t\t\tthinkingLevelMap: modelDef.thinkingLevelMap,\n\t\t\t\t\tinput: modelDef.input as (\"text\" | \"image\")[],\n\t\t\t\t\tcost: modelDef.cost,\n\t\t\t\t\tcontextWindow: modelDef.contextWindow,\n\t\t\t\t\tmaxTokens: modelDef.maxTokens,\n\t\t\t\t\theaders: undefined,\n\t\t\t\t\tcompat: modelDef.compat,\n\t\t\t\t} as Model<Api>);\n\t\t\t}\n\t\t\tif (config.oauth?.modifyModels) {\n\t\t\t\tconst cred = this.authStorage.get(providerName);\n\t\t\t\tif (cred?.type === \"oauth\") {\n\t\t\t\t\tthis.models = config.oauth.modifyModels(this.models, cred);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (config.baseUrl || config.headers) {\n\t\t\tthis.models = this.models.map((m) => {\n\t\t\t\tif (m.provider !== providerName) return m;\n\t\t\t\treturn {\n\t\t\t\t\t...m,\n\t\t\t\t\tbaseUrl: config.baseUrl ?? m.baseUrl,\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\t}\n}\n\n/**\n * Input type for registerProvider API.\n */\nexport interface ProviderConfigInput {\n\tname?: string;\n\tbaseUrl?: string;\n\tapiKey?: string;\n\tapi?: Api;\n\tstreamSimple?: (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n\t/** OAuth provider for /login support */\n\toauth?: Omit<OAuthProviderInterface, \"id\">;\n\tmodels?: Array<{\n\t\tid: string;\n\t\tname: string;\n\t\tapi?: Api;\n\t\tbaseUrl?: string;\n\t\treasoning: boolean;\n\t\tthinkingLevelMap?: Model<Api>[\"thinkingLevelMap\"];\n\t\tinput: (\"text\" | \"image\")[];\n\t\tcost: { input: number; output: number; cacheRead: number; cacheWrite: number };\n\t\tcontextWindow: number;\n\t\tmaxTokens: number;\n\t\theaders?: Record<string, string>;\n\t\tcompat?: Model<Api>[\"compat\"];\n\t}>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-registry.js","sourceRoot":"","sources":["../../src/core/model-registry.ts"],"names":[],"mappings":"AAAA;;GAEG;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} from \"node:buffer\";\nimport { createHash } from \"node:crypto\";\nimport {\n\ttype AnthropicMessagesCompat,\n\ttype Api,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tgetModels,\n\tgetProviders,\n\ttype KnownProvider,\n\ttype Model,\n\ttype OAuthProviderInterface,\n\ttype OpenAICompletionsCompat,\n\ttype OpenAIResponsesCompat,\n\tregisterApiProvider,\n\tresetApiProviders,\n\ttype SimpleStreamOptions,\n} from \"@asm-agent/ai\";\nimport { registerBuiltinMcpOAuthProviders } from \"@asm-agent/ai/mcp\";\nimport { registerOAuthProvider, resetOAuthProviders } from \"@asm-agent/ai/oauth\";\nimport { existsSync, readFileSync, renameSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { type Static, type TProperties, Type } from \"typebox\";\nimport type { Validator } from \"typebox/compile\";\nimport type { TLocalizedValidationError } from \"typebox/error\";\nimport { getAgentDir } from \"../config.js\";\nimport type { AuthSourceToken, AuthStatus, AuthStorage } from \"./auth-storage.js\";\nimport { discoverOllamaModels } from \"./ollama-models.js\";\nimport { PRIME_INFERENCE_PROVIDER_ID } from \"./prime-inference-auth.js\";\nimport {\n\tfetchAuthorizedPrivatePrimeInferenceModelIds,\n\tgetPrivatePrimeInferenceModels,\n\tisPrivatePrimeInferenceModel,\n} from \"./prime-inference-models.js\";\nimport { BUILT_IN_PROVIDER_DISPLAY_NAMES } from \"./provider-display-names.js\";\nimport {\n\tclearConfigValueCache,\n\tresolveConfigValueOrThrow,\n\tresolveConfigValueUncached,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.js\";\n\nconst PercentileCutoffsSchema = Type.Object({\n\tp50: Type.Optional(Type.Number()),\n\tp75: Type.Optional(Type.Number()),\n\tp90: Type.Optional(Type.Number()),\n\tp99: Type.Optional(Type.Number()),\n});\n\nconst OpenRouterRoutingSchema = Type.Object({\n\tallow_fallbacks: Type.Optional(Type.Boolean()),\n\trequire_parameters: Type.Optional(Type.Boolean()),\n\tdata_collection: Type.Optional(Type.Union([Type.Literal(\"deny\"), Type.Literal(\"allow\")])),\n\tzdr: Type.Optional(Type.Boolean()),\n\tenforce_distillable_text: Type.Optional(Type.Boolean()),\n\torder: Type.Optional(Type.Array(Type.String())),\n\tonly: Type.Optional(Type.Array(Type.String())),\n\tignore: Type.Optional(Type.Array(Type.String())),\n\tquantizations: Type.Optional(Type.Array(Type.String())),\n\tsort: Type.Optional(\n\t\tType.Union([\n\t\t\tType.String(),\n\t\t\tType.Object({\n\t\t\t\tby: Type.Optional(Type.String()),\n\t\t\t\tpartition: Type.Optional(Type.Union([Type.String(), Type.Null()])),\n\t\t\t}),\n\t\t]),\n\t),\n\tmax_price: Type.Optional(\n\t\tType.Object({\n\t\t\tprompt: Type.Optional(Type.Union([Type.Number(), Type.String()])),\n\t\t\tcompletion: Type.Optional(Type.Union([Type.Number(), Type.String()])),\n\t\t\timage: Type.Optional(Type.Union([Type.Number(), Type.String()])),\n\t\t\taudio: Type.Optional(Type.Union([Type.Number(), Type.String()])),\n\t\t\trequest: Type.Optional(Type.Union([Type.Number(), Type.String()])),\n\t\t}),\n\t),\n\tpreferred_min_throughput: Type.Optional(Type.Union([Type.Number(), PercentileCutoffsSchema])),\n\tpreferred_max_latency: Type.Optional(Type.Union([Type.Number(), PercentileCutoffsSchema])),\n});\n\nconst VercelGatewayRoutingSchema = Type.Object({\n\tonly: Type.Optional(Type.Array(Type.String())),\n\torder: Type.Optional(Type.Array(Type.String())),\n});\n\nconst ThinkingLevelMapValueSchema = Type.Union([Type.String(), Type.Null()]);\nconst ThinkingLevelMapSchema = Type.Object({\n\toff: Type.Optional(ThinkingLevelMapValueSchema),\n\tminimal: Type.Optional(ThinkingLevelMapValueSchema),\n\tlow: Type.Optional(ThinkingLevelMapValueSchema),\n\tmedium: Type.Optional(ThinkingLevelMapValueSchema),\n\thigh: Type.Optional(ThinkingLevelMapValueSchema),\n\txhigh: Type.Optional(ThinkingLevelMapValueSchema),\n\tmax: Type.Optional(ThinkingLevelMapValueSchema),\n});\n\nconst OpenAICompletionsCompatSchema = Type.Object({\n\tsupportsStore: Type.Optional(Type.Boolean()),\n\tsupportsDeveloperRole: Type.Optional(Type.Boolean()),\n\tsupportsReasoningEffort: Type.Optional(Type.Boolean()),\n\tsupportsUsageInStreaming: Type.Optional(Type.Boolean()),\n\tmaxTokensField: Type.Optional(Type.Union([Type.Literal(\"max_completion_tokens\"), Type.Literal(\"max_tokens\")])),\n\trequiresToolResultName: Type.Optional(Type.Boolean()),\n\trequiresAssistantAfterToolResult: Type.Optional(Type.Boolean()),\n\trequiresThinkingAsText: Type.Optional(Type.Boolean()),\n\trequiresReasoningContentOnAssistantMessages: Type.Optional(Type.Boolean()),\n\tthinkingFormat: Type.Optional(\n\t\tType.Union([\n\t\t\tType.Literal(\"openai\"),\n\t\t\tType.Literal(\"openrouter\"),\n\t\t\tType.Literal(\"deepseek\"),\n\t\t\tType.Literal(\"zai\"),\n\t\t\tType.Literal(\"qwen\"),\n\t\t\tType.Literal(\"qwen-chat-template\"),\n\t\t]),\n\t),\n\tcacheControlFormat: Type.Optional(Type.Literal(\"anthropic\")),\n\topenRouterRouting: Type.Optional(OpenRouterRoutingSchema),\n\tvercelGatewayRouting: Type.Optional(VercelGatewayRoutingSchema),\n\tsupportsStrictMode: Type.Optional(Type.Boolean()),\n\tsupportsLongCacheRetention: Type.Optional(Type.Boolean()),\n});\n\nconst OpenAIResponsesCompatSchema = Type.Object({\n\tsendSessionIdHeader: Type.Optional(Type.Boolean()),\n\tsupportsLongCacheRetention: Type.Optional(Type.Boolean()),\n});\n\nconst AnthropicMessagesCompatSchema = Type.Object({\n\tsupportsEagerToolInputStreaming: Type.Optional(Type.Boolean()),\n\tsupportsLongCacheRetention: Type.Optional(Type.Boolean()),\n});\n\nconst ProviderCompatSchema = Type.Union([\n\tOpenAICompletionsCompatSchema,\n\tOpenAIResponsesCompatSchema,\n\tAnthropicMessagesCompatSchema,\n]);\n\n// Most fields are optional with sensible defaults for local models (Ollama, LM Studio, etc.)\nconst ModelDefinitionSchema = Type.Object({\n\tid: Type.String({ minLength: 1 }),\n\tname: Type.Optional(Type.String({ minLength: 1 })),\n\tapi: Type.Optional(Type.String({ minLength: 1 })),\n\tbaseUrl: Type.Optional(Type.String({ minLength: 1 })),\n\treasoning: Type.Optional(Type.Boolean()),\n\tthinkingLevelMap: Type.Optional(ThinkingLevelMapSchema),\n\tinput: Type.Optional(Type.Array(Type.Union([Type.Literal(\"text\"), Type.Literal(\"image\")]))),\n\tcost: Type.Optional(\n\t\tType.Object({\n\t\t\tinput: Type.Number(),\n\t\t\toutput: Type.Number(),\n\t\t\tcacheRead: Type.Number(),\n\t\t\tcacheWrite: Type.Number(),\n\t\t}),\n\t),\n\tcontextWindow: Type.Optional(Type.Number()),\n\tmaxTokens: Type.Optional(Type.Number()),\n\theaders: Type.Optional(Type.Record(Type.String(), Type.String())),\n\tcompat: Type.Optional(ProviderCompatSchema),\n});\n\nconst ModelOverrideSchema = Type.Object({\n\tname: Type.Optional(Type.String({ minLength: 1 })),\n\treasoning: Type.Optional(Type.Boolean()),\n\tthinkingLevelMap: Type.Optional(ThinkingLevelMapSchema),\n\tinput: Type.Optional(Type.Array(Type.Union([Type.Literal(\"text\"), Type.Literal(\"image\")]))),\n\tcost: Type.Optional(\n\t\tType.Object({\n\t\t\tinput: Type.Optional(Type.Number()),\n\t\t\toutput: Type.Optional(Type.Number()),\n\t\t\tcacheRead: Type.Optional(Type.Number()),\n\t\t\tcacheWrite: Type.Optional(Type.Number()),\n\t\t}),\n\t),\n\tcontextWindow: Type.Optional(Type.Number()),\n\tmaxTokens: Type.Optional(Type.Number()),\n\theaders: Type.Optional(Type.Record(Type.String(), Type.String())),\n\tcompat: Type.Optional(ProviderCompatSchema),\n});\n\ntype ModelOverride = Static<typeof ModelOverrideSchema>;\n\nconst ProviderConfigSchema = Type.Object({\n\tname: Type.Optional(Type.String({ minLength: 1 })),\n\tbaseUrl: Type.Optional(Type.String({ minLength: 1 })),\n\tapiKey: Type.Optional(Type.String({ minLength: 1 })),\n\tapi: Type.Optional(Type.String({ minLength: 1 })),\n\theaders: Type.Optional(Type.Record(Type.String(), Type.String())),\n\tcompat: Type.Optional(ProviderCompatSchema),\n\tauthHeader: Type.Optional(Type.Boolean()),\n\tmodels: Type.Optional(Type.Array(ModelDefinitionSchema)),\n\tmodelOverrides: Type.Optional(Type.Record(Type.String(), ModelOverrideSchema)),\n});\n\nconst ModelsConfigSchema = Type.Object({\n\tproviders: Type.Record(Type.String(), ProviderConfigSchema),\n});\n\n// typebox/compile costs ~300ms to import, so the models.json validator loads\n// lazily. The first load of an existing models.json proceeds on JSON parsing +\n// validateConfig() and reports schema errors asynchronously once the validator\n// is ready; subsequent refreshes validate synchronously.\nlet validateModelsConfig: Validator<TProperties, typeof ModelsConfigSchema> | undefined;\nlet modelsValidatorPromise: Promise<void> | undefined;\n\nfunction preloadModelsConfigValidator(): Promise<void> {\n\tmodelsValidatorPromise ??= import(\"typebox/compile\").then(({ Compile }) => {\n\t\tvalidateModelsConfig = Compile(ModelsConfigSchema);\n\t});\n\treturn modelsValidatorPromise;\n}\n\ntype ModelsConfig = Static<typeof ModelsConfigSchema>;\n\nfunction formatValidationPath(error: TLocalizedValidationError): string {\n\tif (error.keyword === \"required\") {\n\t\tconst requiredProperties = (error.params as { requiredProperties?: string[] }).requiredProperties;\n\t\tconst requiredProperty = requiredProperties?.[0];\n\t\tif (requiredProperty) {\n\t\t\tconst basePath = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\t\t\treturn basePath ? `${basePath}.${requiredProperty}` : requiredProperty;\n\t\t}\n\t}\n\tconst path = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\treturn path || \"root\";\n}\n\n/** Strip `//` line comments and trailing commas from JSON, leaving string literals untouched. */\nfunction stripJsonComments(input: string): string {\n\treturn input\n\t\t.replace(/\"(?:\\\\.|[^\"\\\\])*\"|\\/\\/[^\\n]*/g, (m) => (m[0] === '\"' ? m : \"\"))\n\t\t.replace(/\"(?:\\\\.|[^\"\\\\])*\"|,(\\s*[}\\]])/g, (m, tail) => tail ?? (m[0] === '\"' ? m : \"\"));\n}\n\n/** Provider override config (baseUrl, compat) without request auth/headers */\ninterface ProviderOverride {\n\tbaseUrl?: string;\n\tcompat?: Model<Api>[\"compat\"];\n}\n\ninterface ProviderRequestConfig {\n\tapiKey?: string;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n}\n\ntype ProviderRequestAuthSource = {\n\tsource: \"environment\" | \"models_json_key\" | \"models_json_command\";\n\tconfigured: true;\n\tlabel?: string;\n\tidentityFingerprint: string;\n\tvalueFingerprint?: string;\n\tresolveValueFingerprint?: () => string | undefined;\n};\n\nexport type ResolvedRequestAuth =\n\t| {\n\t\t\tok: true;\n\t\t\tapiKey?: string;\n\t\t\theaders?: Record<string, string>;\n\t }\n\t| {\n\t\t\tok: false;\n\t\t\terror: string;\n\t };\n\nexport interface ModelCatalogSnapshot {\n\tmodels: Model<Api>[];\n\tconfiguredProviders: string[];\n}\n\n/** Result of loading custom models from models.json */\ninterface CustomModelsResult {\n\tmodels: Model<Api>[];\n\t/** Providers with baseUrl/headers/apiKey overrides for built-in models */\n\toverrides: Map<string, ProviderOverride>;\n\t/** Per-model overrides: provider -> modelId -> override */\n\tmodelOverrides: Map<string, Map<string, ModelOverride>>;\n\terror: string | undefined;\n}\n\nfunction emptyCustomModelsResult(error?: string): CustomModelsResult {\n\treturn { models: [], overrides: new Map(), modelOverrides: new Map(), error };\n}\n\nfunction mergeCompat(\n\tbaseCompat: Model<Api>[\"compat\"],\n\toverrideCompat: ModelOverride[\"compat\"],\n): Model<Api>[\"compat\"] | undefined {\n\tif (!overrideCompat) return baseCompat;\n\n\tconst base = baseCompat as OpenAICompletionsCompat | OpenAIResponsesCompat | AnthropicMessagesCompat | undefined;\n\tconst override = overrideCompat as OpenAICompletionsCompat | OpenAIResponsesCompat | AnthropicMessagesCompat;\n\tconst merged = { ...base, ...override } as OpenAICompletionsCompat | OpenAIResponsesCompat | AnthropicMessagesCompat;\n\n\tconst baseCompletions = base as OpenAICompletionsCompat | undefined;\n\tconst overrideCompletions = override as OpenAICompletionsCompat;\n\tconst mergedCompletions = merged as OpenAICompletionsCompat;\n\n\tif (baseCompletions?.openRouterRouting || overrideCompletions.openRouterRouting) {\n\t\tmergedCompletions.openRouterRouting = {\n\t\t\t...baseCompletions?.openRouterRouting,\n\t\t\t...overrideCompletions.openRouterRouting,\n\t\t};\n\t}\n\n\tif (baseCompletions?.vercelGatewayRouting || overrideCompletions.vercelGatewayRouting) {\n\t\tmergedCompletions.vercelGatewayRouting = {\n\t\t\t...baseCompletions?.vercelGatewayRouting,\n\t\t\t...overrideCompletions.vercelGatewayRouting,\n\t\t};\n\t}\n\n\treturn merged as Model<Api>[\"compat\"];\n}\n\n/**\n * Deep merge a model override into a model.\n * Handles nested objects (cost, compat) by merging rather than replacing.\n */\nfunction applyModelOverride(model: Model<Api>, override: ModelOverride): Model<Api> {\n\tconst result = { ...model };\n\n\tif (override.name !== undefined) result.name = override.name;\n\tif (override.reasoning !== undefined) result.reasoning = override.reasoning;\n\tif (override.thinkingLevelMap !== undefined) {\n\t\tresult.thinkingLevelMap = { ...model.thinkingLevelMap, ...override.thinkingLevelMap };\n\t}\n\tif (override.input !== undefined) result.input = override.input as (\"text\" | \"image\")[];\n\tif (override.contextWindow !== undefined) result.contextWindow = override.contextWindow;\n\tif (override.maxTokens !== undefined) result.maxTokens = override.maxTokens;\n\n\tif (override.cost) {\n\t\tresult.cost = {\n\t\t\tinput: override.cost.input ?? model.cost.input,\n\t\t\toutput: override.cost.output ?? model.cost.output,\n\t\t\tcacheRead: override.cost.cacheRead ?? model.cost.cacheRead,\n\t\t\tcacheWrite: override.cost.cacheWrite ?? model.cost.cacheWrite,\n\t\t};\n\t}\n\n\tresult.compat = mergeCompat(model.compat, override.compat);\n\n\treturn result;\n}\n\n/** Clear the config value command cache. Exported for testing. */\nexport const clearApiKeyCache = clearConfigValueCache;\n\nfunction readOpenAICodexAccountId(token: string): string | undefined {\n\ttry {\n\t\tconst payload = JSON.parse(Buffer.from(token.split(\".\")[1] ?? \"\", \"base64url\").toString(\"utf8\")) as {\n\t\t\t\"https://api.openai.com/auth\"?: { chatgpt_account_id?: unknown };\n\t\t};\n\t\tconst accountId = payload[\"https://api.openai.com/auth\"]?.chatgpt_account_id;\n\t\treturn typeof accountId === \"string\" && accountId.length > 0 ? accountId : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * The Codex backend gates its model catalog on the reported client version: it answers HTTP 200 with a\n * catalog that grows as the version rises, so a low version yields a silently empty or partial list rather\n * than an error. ASM Agent's own package version is far below the Codex CLI's version line, so it must\n * report a supported Codex client version here instead.\n *\n * Shipping a new Codex model takes two edits, and both are required:\n * 1. Add the model to `codexModels` in `packages/ai/scripts/generate-models.ts` and regenerate. That list is\n * explicit, not fetched, so an unlisted model does not exist for ASM Agent at all.\n * 2. Raise this constant to a Codex CLI release whose catalog includes that model. `getExecutableModels()`\n * below intersects the registry with the discovered catalog, so a listed model the catalog omits is\n * dropped.\n *\n * Skipping step 2 fails silently and asymmetrically: `rlm` subagent delegation and `find_models()` resolve\n * through `getExecutableModels()` and lose the model, while `/model` reads the unfiltered `getAvailable()`\n * and keeps offering it.\n *\n * Catalog behaviour measured 2026-08-13; see #702.\n */\nconst OPENAI_CODEX_CLIENT_VERSION = \"0.147.0\";\n\nfunction openAICodexModelsUrl(baseUrl: string): string {\n\tconst normalized = baseUrl.replace(/\\/+$/, \"\");\n\tlet path: string;\n\tif (normalized.endsWith(\"/codex/responses\")) {\n\t\tpath = `${normalized.slice(0, -\"/responses\".length)}/models`;\n\t} else if (normalized.endsWith(\"/codex\")) {\n\t\tpath = `${normalized}/models`;\n\t} else {\n\t\tpath = `${normalized}/codex/models`;\n\t}\n\tconst url = new URL(path);\n\turl.searchParams.set(\"client_version\", OPENAI_CODEX_CLIENT_VERSION);\n\treturn url.toString();\n}\n\nfunction readOpenAICodexModelIds(value: unknown): Set<string> {\n\tif (!value || typeof value !== \"object\" || !(\"models\" in value) || !Array.isArray(value.models)) {\n\t\tthrow new Error(\"Invalid OpenAI Codex model catalog\");\n\t}\n\treturn new Set(\n\t\tvalue.models.flatMap((model) => {\n\t\t\tif (!model || typeof model !== \"object\" || !(\"slug\" in model) || typeof model.slug !== \"string\") {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\treturn [model.slug];\n\t\t}),\n\t);\n}\n\nconst PRIVATE_PRIME_AUTHORIZATION_CACHE_FILE = \"prime-inference-private-models.json\";\nconst PRIVATE_PRIME_AUTHORIZATION_CACHE_TTL_MS = 5 * 60_000;\nconst PRIVATE_PRIME_BACKGROUND_REFRESH_TIMEOUT_MS = 3_000;\n\ninterface PrivatePrimeAuthorizationCache {\n\tfingerprint: string;\n\tmodelIds: Set<string>;\n\trefreshedAt: number;\n}\n\nfunction privatePrimeAuthorizationFingerprint(apiKey: string, teamId: string): string {\n\treturn createHash(\"sha256\").update(apiKey).update(\"\\0\").update(teamId).digest(\"hex\");\n}\n\nfunction isOfflineModeEnabled(): boolean {\n\tconst value = process.env.PI_OFFLINE;\n\tif (!value) return false;\n\treturn value === \"1\" || value.toLowerCase() === \"true\" || value.toLowerCase() === \"yes\";\n}\n\n/**\n * Model registry - loads and manages models, resolves API keys via AuthStorage.\n */\nexport class ModelRegistry {\n\tprivate models: Model<Api>[] = [];\n\tprivate providerRequestConfigs: Map<string, ProviderRequestConfig> = new Map();\n\tprivate staleProviderRequestAuthSources: Map<string, AuthSourceToken[]> = new Map();\n\tprivate lastProviderAuthSourceTokens: Map<string, AuthSourceToken> = new Map();\n\tprivate modelRequestHeaders: Map<string, Record<string, string>> = new Map();\n\tprivate registeredProviders: Map<string, ProviderConfigInput> = new Map();\n\tprivate authorizedPrivatePrimeInferenceModelIds = new Set<string>();\n\tprivate authorizedPrivatePrimeInferenceTeamId: string | undefined;\n\tprivate explicitPrivatePrimeInferenceModelIds = new Set<string>();\n\tprivate openAICodexModelsCache: { authFingerprint: string; modelIds: Set<string>; refreshedAt: number } | undefined;\n\tprivate backgroundPrivatePrimeAuthorization: { fingerprint: string; promise: Promise<void> } | undefined;\n\tprivate loadError: string | undefined = undefined;\n\n\t/** Re-register dynamic OAuth providers (e.g. user MCP servers) after refresh() resets the registry. */\n\tprivate onOAuthProvidersReset?: () => void;\n\n\tprivate constructor(\n\t\treadonly authStorage: AuthStorage,\n\t\tprivate modelsJsonPath: string | undefined,\n\t) {\n\t\tthis.loadModels();\n\t}\n\n\tsetOnOAuthProvidersReset(hook: () => void): void {\n\t\tthis.onOAuthProvidersReset = hook;\n\t}\n\n\tstatic create(authStorage: AuthStorage, modelsJsonPath: string = join(getAgentDir(), \"models.json\")): ModelRegistry {\n\t\treturn new ModelRegistry(authStorage, modelsJsonPath);\n\t}\n\n\tstatic inMemory(authStorage: AuthStorage): ModelRegistry {\n\t\treturn new ModelRegistry(authStorage, undefined);\n\t}\n\n\t/**\n\t * Reload models from disk (built-in + custom from models.json).\n\t */\n\trefresh(): void {\n\t\tthis.providerRequestConfigs.clear();\n\t\tthis.modelRequestHeaders.clear();\n\t\tthis.lastProviderAuthSourceTokens.clear();\n\t\tthis.authorizedPrivatePrimeInferenceModelIds.clear();\n\t\tthis.authorizedPrivatePrimeInferenceTeamId = undefined;\n\t\tthis.explicitPrivatePrimeInferenceModelIds.clear();\n\t\tthis.loadError = undefined;\n\n\t\t// Credentials may have been written by another process (e.g. the UI\n\t\t// process saving a login while the session lives in the daemon).\n\t\tthis.authStorage.reload();\n\t\tresetApiProviders();\n\t\tresetOAuthProviders();\n\t\t// reset drops everything but model-provider built-ins; re-add MCP integrations\n\t\t// (built-in catalog + this session's user-declared servers via the hook).\n\t\t// NOTE: the OAuth registry is process-global. Built-in MCP providers are\n\t\t// identical across sessions so they always survive; a user-declared server\n\t\t// unique to another daemon session is dropped here and re-registered on that\n\t\t// session's next refresh. Fully isolating it would require a session-scoped\n\t\t// registry in pi-ai (out of scope here).\n\t\tregisterBuiltinMcpOAuthProviders();\n\t\tthis.onOAuthProvidersReset?.();\n\n\t\tthis.loadModels();\n\n\t\tfor (const [providerName, config] of this.registeredProviders.entries()) {\n\t\t\tthis.applyProviderConfig(providerName, config);\n\t\t}\n\t}\n\n\t/**\n\t * Get any error from loading models.json (undefined if no error).\n\t */\n\tgetError(): string | undefined {\n\t\treturn this.loadError;\n\t}\n\n\tprivate loadModels(): void {\n\t\tconst {\n\t\t\tmodels: customModels,\n\t\t\toverrides,\n\t\t\tmodelOverrides,\n\t\t\terror,\n\t\t} = this.modelsJsonPath ? this.loadCustomModels(this.modelsJsonPath) : emptyCustomModelsResult();\n\n\t\tif (error) {\n\t\t\tthis.loadError = error;\n\t\t}\n\n\t\tthis.explicitPrivatePrimeInferenceModelIds = new Set(\n\t\t\tcustomModels.filter(isPrivatePrimeInferenceModel).map((model) => model.id),\n\t\t);\n\t\tconst builtInModels = [...this.loadBuiltInModels(overrides, modelOverrides), ...getPrivatePrimeInferenceModels()];\n\t\tlet combined = this.mergeCustomModels(builtInModels, customModels);\n\n\t\tfor (const oauthProvider of this.authStorage.getOAuthProviders()) {\n\t\t\tconst cred = this.authStorage.get(oauthProvider.id);\n\t\t\tif (cred?.type === \"oauth\" && oauthProvider.modifyModels) {\n\t\t\t\tcombined = oauthProvider.modifyModels(combined, cred);\n\t\t\t}\n\t\t}\n\n\t\tthis.models = combined;\n\t}\n\n\t/** Load built-in models and apply provider/model overrides */\n\tprivate loadBuiltInModels(\n\t\toverrides: Map<string, ProviderOverride>,\n\t\tmodelOverrides: Map<string, Map<string, ModelOverride>>,\n\t): Model<Api>[] {\n\t\treturn getProviders().flatMap((provider) => {\n\t\t\tconst models = getModels(provider as KnownProvider) as Model<Api>[];\n\t\t\tconst providerOverride = overrides.get(provider);\n\t\t\tconst perModelOverrides = modelOverrides.get(provider);\n\n\t\t\treturn models.map((m) => {\n\t\t\t\tlet model = m;\n\n\t\t\t\tif (providerOverride) {\n\t\t\t\t\tmodel = {\n\t\t\t\t\t\t...model,\n\t\t\t\t\t\tbaseUrl: providerOverride.baseUrl ?? model.baseUrl,\n\t\t\t\t\t\tcompat: mergeCompat(model.compat, providerOverride.compat),\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst modelOverride = perModelOverrides?.get(m.id);\n\t\t\t\tif (modelOverride) {\n\t\t\t\t\tmodel = applyModelOverride(model, modelOverride);\n\t\t\t\t}\n\n\t\t\t\treturn model;\n\t\t\t});\n\t\t});\n\t}\n\n\t/** Merge custom models into built-in list by provider+id (custom wins on conflicts). */\n\tprivate mergeCustomModels(builtInModels: Model<Api>[], customModels: Model<Api>[]): Model<Api>[] {\n\t\tconst merged = [...builtInModels];\n\t\tfor (const customModel of customModels) {\n\t\t\tconst existingIndex = merged.findIndex((m) => m.provider === customModel.provider && m.id === customModel.id);\n\t\t\tif (existingIndex >= 0) {\n\t\t\t\tmerged[existingIndex] = customModel;\n\t\t\t} else {\n\t\t\t\tmerged.push(customModel);\n\t\t\t}\n\t\t}\n\t\treturn merged;\n\t}\n\n\tprivate loadCustomModels(modelsJsonPath: string): CustomModelsResult {\n\t\tif (!existsSync(modelsJsonPath)) {\n\t\t\treturn emptyCustomModelsResult();\n\t\t}\n\n\t\ttry {\n\t\t\tconst content = readFileSync(modelsJsonPath, \"utf-8\");\n\t\t\tconst parsed = JSON.parse(stripJsonComments(content)) as unknown;\n\n\t\t\tif (!validateModelsConfig) {\n\t\t\t\t// Validator not loaded yet (first refresh during startup): proceed on\n\t\t\t\t// validateConfig() below and report schema errors asynchronously once\n\t\t\t\t// the validator is ready. Later refreshes validate synchronously.\n\t\t\t\tvoid preloadModelsConfigValidator().then(() => {\n\t\t\t\t\tif (validateModelsConfig && !validateModelsConfig.Check(parsed)) {\n\t\t\t\t\t\tconst errors =\n\t\t\t\t\t\t\tvalidateModelsConfig\n\t\t\t\t\t\t\t\t.Errors(parsed)\n\t\t\t\t\t\t\t\t.map((error) => ` - ${formatValidationPath(error)}: ${error.message}`)\n\t\t\t\t\t\t\t\t.join(\"\\n\") || \"Unknown schema error\";\n\t\t\t\t\t\tconsole.error(`Invalid models.json schema:\\n${errors}\\n\\nFile: ${modelsJsonPath}`);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else if (!validateModelsConfig.Check(parsed)) {\n\t\t\t\tconst errors =\n\t\t\t\t\tvalidateModelsConfig\n\t\t\t\t\t\t.Errors(parsed)\n\t\t\t\t\t\t.map((error) => ` - ${formatValidationPath(error)}: ${error.message}`)\n\t\t\t\t\t\t.join(\"\\n\") || \"Unknown schema error\";\n\t\t\t\treturn emptyCustomModelsResult(`Invalid models.json schema:\\n${errors}\\n\\nFile: ${modelsJsonPath}`);\n\t\t\t}\n\n\t\t\tconst config = parsed as ModelsConfig;\n\n\t\t\tthis.validateConfig(config);\n\n\t\t\tconst overrides = new Map<string, ProviderOverride>();\n\t\t\tconst modelOverrides = new Map<string, Map<string, ModelOverride>>();\n\n\t\t\tfor (const [providerName, providerConfig] of Object.entries(config.providers)) {\n\t\t\t\tif (providerConfig.baseUrl || providerConfig.compat) {\n\t\t\t\t\toverrides.set(providerName, {\n\t\t\t\t\t\tbaseUrl: providerConfig.baseUrl,\n\t\t\t\t\t\tcompat: providerConfig.compat,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tthis.storeProviderRequestConfig(providerName, providerConfig);\n\n\t\t\t\tif (providerConfig.modelOverrides) {\n\t\t\t\t\tmodelOverrides.set(providerName, new Map(Object.entries(providerConfig.modelOverrides)));\n\t\t\t\t\tfor (const [modelId, modelOverride] of Object.entries(providerConfig.modelOverrides)) {\n\t\t\t\t\t\tthis.storeModelHeaders(providerName, modelId, modelOverride.headers);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { models: this.parseModels(config), overrides, modelOverrides, error: undefined };\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) {\n\t\t\t\treturn emptyCustomModelsResult(`Failed to parse models.json: ${error.message}\\n\\nFile: ${modelsJsonPath}`);\n\t\t\t}\n\t\t\treturn emptyCustomModelsResult(\n\t\t\t\t`Failed to load models.json: ${error instanceof Error ? error.message : error}\\n\\nFile: ${modelsJsonPath}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate validateConfig(config: ModelsConfig): void {\n\t\tconst builtInProviders = new Set<string>(getProviders());\n\n\t\tfor (const [providerName, providerConfig] of Object.entries(config.providers)) {\n\t\t\tconst isBuiltIn = builtInProviders.has(providerName);\n\t\t\tconst hasProviderApi = !!providerConfig.api;\n\t\t\tconst models = providerConfig.models ?? [];\n\t\t\tconst hasModelOverrides =\n\t\t\t\tproviderConfig.modelOverrides && Object.keys(providerConfig.modelOverrides).length > 0;\n\n\t\t\tif (models.length === 0) {\n\t\t\t\tif (!providerConfig.baseUrl && !providerConfig.headers && !providerConfig.compat && !hasModelOverrides) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Provider ${providerName}: must specify \"baseUrl\", \"headers\", \"compat\", \"modelOverrides\", or \"models\".`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (!isBuiltIn) {\n\t\t\t\tif (!providerConfig.baseUrl) {\n\t\t\t\t\tthrow new Error(`Provider ${providerName}: \"baseUrl\" is required when defining custom models.`);\n\t\t\t\t}\n\t\t\t\tif (!providerConfig.apiKey) {\n\t\t\t\t\tthrow new Error(`Provider ${providerName}: \"apiKey\" is required when defining custom models.`);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// inherited from built-in models. Auth comes from env vars / auth storage.\n\n\t\t\tfor (const modelDef of models) {\n\t\t\t\tconst hasModelApi = !!modelDef.api;\n\n\t\t\t\tif (!hasProviderApi && !hasModelApi && !isBuiltIn) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Provider ${providerName}, model ${modelDef.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (!modelDef.id) throw new Error(`Provider ${providerName}: model missing \"id\"`);\n\t\t\t\tif (modelDef.contextWindow !== undefined && modelDef.contextWindow <= 0)\n\t\t\t\t\tthrow new Error(`Provider ${providerName}, model ${modelDef.id}: invalid contextWindow`);\n\t\t\t\tif (modelDef.maxTokens !== undefined && modelDef.maxTokens <= 0)\n\t\t\t\t\tthrow new Error(`Provider ${providerName}, model ${modelDef.id}: invalid maxTokens`);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate parseModels(config: ModelsConfig): Model<Api>[] {\n\t\tconst models: Model<Api>[] = [];\n\t\tconst builtInProviders = new Set<string>(getProviders());\n\n\t\tconst builtInDefaultsCache = new Map<string, { api: string; baseUrl: string }>();\n\t\tconst getBuiltInDefaults = (providerName: string): { api: string; baseUrl: string } | undefined => {\n\t\t\tif (!builtInProviders.has(providerName)) return undefined;\n\t\t\tif (builtInDefaultsCache.has(providerName)) return builtInDefaultsCache.get(providerName);\n\t\t\tconst builtIn = getModels(providerName as KnownProvider) as Model<Api>[];\n\t\t\tif (builtIn.length === 0) return undefined;\n\t\t\tconst defaults = { api: builtIn[0].api, baseUrl: builtIn[0].baseUrl };\n\t\t\tbuiltInDefaultsCache.set(providerName, defaults);\n\t\t\treturn defaults;\n\t\t};\n\n\t\tfor (const [providerName, providerConfig] of Object.entries(config.providers)) {\n\t\t\tconst modelDefs = providerConfig.models ?? [];\n\t\t\tif (modelDefs.length === 0) continue; // Override-only, no custom models\n\n\t\t\tconst builtInDefaults = getBuiltInDefaults(providerName);\n\n\t\t\tfor (const modelDef of modelDefs) {\n\t\t\t\tconst api = modelDef.api ?? providerConfig.api ?? builtInDefaults?.api;\n\t\t\t\tif (!api) continue;\n\n\t\t\t\tconst baseUrl = modelDef.baseUrl ?? providerConfig.baseUrl ?? builtInDefaults?.baseUrl;\n\t\t\t\tif (!baseUrl) continue;\n\n\t\t\t\tconst compat = mergeCompat(providerConfig.compat, modelDef.compat);\n\t\t\t\tthis.storeModelHeaders(providerName, modelDef.id, modelDef.headers);\n\n\t\t\t\tconst defaultCost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };\n\t\t\t\tmodels.push({\n\t\t\t\t\tid: modelDef.id,\n\t\t\t\t\tname: modelDef.name ?? modelDef.id,\n\t\t\t\t\tapi: api as Api,\n\t\t\t\t\tprovider: providerName,\n\t\t\t\t\tbaseUrl,\n\t\t\t\t\treasoning: modelDef.reasoning ?? false,\n\t\t\t\t\tthinkingLevelMap: modelDef.thinkingLevelMap,\n\t\t\t\t\tinput: (modelDef.input ?? [\"text\"]) as (\"text\" | \"image\")[],\n\t\t\t\t\tcost: modelDef.cost ?? defaultCost,\n\t\t\t\t\tcontextWindow: modelDef.contextWindow ?? 128000,\n\t\t\t\t\tmaxTokens: modelDef.maxTokens ?? 16384,\n\t\t\t\t\theaders: undefined,\n\t\t\t\t\tcompat,\n\t\t\t\t} as Model<Api>);\n\t\t\t}\n\t\t}\n\n\t\treturn models;\n\t}\n\n\t/**\n\t * Get all models (built-in + custom).\n\t * If models.json had errors, returns only built-in models.\n\t */\n\tgetAll(): Model<Api>[] {\n\t\treturn this.models;\n\t}\n\n\t/**\n\t * Get only models that have auth configured.\n\t * This is a fast check that doesn't refresh OAuth tokens.\n\t */\n\tgetAvailable(): Model<Api>[] {\n\t\treturn this.models.filter((model) => {\n\t\t\tif (\n\t\t\t\tisPrivatePrimeInferenceModel(model) &&\n\t\t\t\t!this.explicitPrivatePrimeInferenceModelIds.has(model.id) &&\n\t\t\t\t!this.authorizedPrivatePrimeInferenceModelIds.has(model.id)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn this.hasConfiguredAuth(model);\n\t\t});\n\t}\n\n\tasync refreshAvailableModels(): Promise<Model<Api>[]> {\n\t\tconst previousPrivateModelIds = new Set(this.authorizedPrivatePrimeInferenceModelIds);\n\t\tconst previousTeamId = this.authorizedPrivatePrimeInferenceTeamId;\n\t\tthis.refresh();\n\t\tawait this.refreshPrivatePrimeInferenceAuthorization(previousPrivateModelIds, previousTeamId);\n\t\tconst ollamaModels = await discoverOllamaModels();\n\t\tif (ollamaModels.length > 0) {\n\t\t\tconst knownOllamaIds = new Set(\n\t\t\t\tthis.models.filter((model) => model.provider === \"ollama\").map((model) => model.id),\n\t\t\t);\n\t\t\tthis.models = [...this.models, ...ollamaModels.filter((model) => !knownOllamaIds.has(model.id))];\n\t\t}\n\t\treturn this.getAvailable();\n\t}\n\n\tprivate async refreshPrivatePrimeInferenceAuthorization(\n\t\tpreviousPrivateModelIds = new Set(this.authorizedPrivatePrimeInferenceModelIds),\n\t\tpreviousTeamId = this.authorizedPrivatePrimeInferenceTeamId,\n\t): Promise<void> {\n\t\tconst apiKey = await this.authStorage.getApiKey(PRIME_INFERENCE_PROVIDER_ID);\n\t\tconst teamHeaders = this.authStorage.getProviderHeaders(PRIME_INFERENCE_PROVIDER_ID);\n\t\tconst teamId = teamHeaders?.[\"X-Prime-Team-ID\"];\n\t\tif (!apiKey || !teamHeaders || !teamId) {\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds.clear();\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tconst fingerprint = privatePrimeAuthorizationFingerprint(apiKey, teamId);\n\t\tconst cached = this.readPrivatePrimeAuthorizationCache();\n\t\tif (cached?.fingerprint === fingerprint) {\n\t\t\t// Serve the persisted authorization decision so startup and model lists\n\t\t\t// don't block on the network. A stale cache refreshes in the background\n\t\t\t// and the updated ids apply to subsequent lookups in this process.\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds = new Set(cached.modelIds);\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = teamId;\n\t\t\tconst cacheIsFresh = Date.now() - cached.refreshedAt < PRIVATE_PRIME_AUTHORIZATION_CACHE_TTL_MS;\n\t\t\tif (cacheIsFresh || isOfflineModeEnabled()) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.startBackgroundPrivatePrimeAuthorizationRefresh(apiKey, teamHeaders, teamId, fingerprint);\n\t\t\treturn;\n\t\t}\n\t\tif (isOfflineModeEnabled()) {\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds.clear();\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tlet authorizedIds: Set<string> | undefined;\n\t\ttry {\n\t\t\tauthorizedIds = await fetchAuthorizedPrivatePrimeInferenceModelIds(apiKey, teamHeaders);\n\t\t} catch {\n\t\t\t// Fall back to the previous authorization below.\n\t\t}\n\t\t// Leave newer state untouched if the credentials changed while fetching.\n\t\tif ((await this.currentPrivatePrimeAuthorizationFingerprint()) !== fingerprint) {\n\t\t\treturn;\n\t\t}\n\t\tif (authorizedIds) {\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds = authorizedIds;\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = teamId;\n\t\t\tthis.writePrivatePrimeAuthorizationCache({ fingerprint, modelIds: authorizedIds, refreshedAt: Date.now() });\n\t\t} else if (teamId === previousTeamId) {\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds = previousPrivateModelIds;\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = teamId;\n\t\t} else {\n\t\t\tthis.authorizedPrivatePrimeInferenceModelIds.clear();\n\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Stale cache hits refresh in the background; failures keep the cached ids.\n\t * Refreshes for the same credentials are deduped, a changed-credentials\n\t * refresh is queued after the in-flight one, and a result is only applied\n\t * if the credentials it was fetched with are still current.\n\t */\n\tprivate startBackgroundPrivatePrimeAuthorizationRefresh(\n\t\tapiKey: string,\n\t\tteamHeaders: Record<string, string>,\n\t\tteamId: string,\n\t\tfingerprint: string,\n\t): void {\n\t\tif (this.backgroundPrivatePrimeAuthorization?.fingerprint === fingerprint) {\n\t\t\treturn;\n\t\t}\n\t\tconst run = async () => {\n\t\t\ttry {\n\t\t\t\tconst authorizedIds = await fetchAuthorizedPrivatePrimeInferenceModelIds(\n\t\t\t\t\tapiKey,\n\t\t\t\t\tteamHeaders,\n\t\t\t\t\tundefined,\n\t\t\t\t\tPRIVATE_PRIME_BACKGROUND_REFRESH_TIMEOUT_MS,\n\t\t\t\t);\n\t\t\t\tif ((await this.currentPrivatePrimeAuthorizationFingerprint()) !== fingerprint) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.authorizedPrivatePrimeInferenceModelIds = authorizedIds;\n\t\t\t\tthis.authorizedPrivatePrimeInferenceTeamId = teamId;\n\t\t\t\tthis.writePrivatePrimeAuthorizationCache({ fingerprint, modelIds: authorizedIds, refreshedAt: Date.now() });\n\t\t\t} catch {\n\t\t\t\t// Keep the cached authorization.\n\t\t\t}\n\t\t};\n\t\tconst pending = this.backgroundPrivatePrimeAuthorization?.promise;\n\t\tconst promise = (pending ?? Promise.resolve()).then(run);\n\t\tthis.backgroundPrivatePrimeAuthorization = { fingerprint, promise };\n\t\tvoid promise.finally(() => {\n\t\t\tif (this.backgroundPrivatePrimeAuthorization?.promise === promise) {\n\t\t\t\tthis.backgroundPrivatePrimeAuthorization = undefined;\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async currentPrivatePrimeAuthorizationFingerprint(): Promise<string | undefined> {\n\t\tconst apiKey = await this.authStorage.getApiKey(PRIME_INFERENCE_PROVIDER_ID);\n\t\tconst teamId = this.authStorage.getProviderHeaders(PRIME_INFERENCE_PROVIDER_ID)?.[\"X-Prime-Team-ID\"];\n\t\treturn apiKey && teamId ? privatePrimeAuthorizationFingerprint(apiKey, teamId) : undefined;\n\t}\n\n\tprivate privatePrimeAuthorizationCachePath(): string | undefined {\n\t\tif (!this.modelsJsonPath) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn join(dirname(this.modelsJsonPath), PRIVATE_PRIME_AUTHORIZATION_CACHE_FILE);\n\t}\n\n\tprivate readPrivatePrimeAuthorizationCache(): PrivatePrimeAuthorizationCache | undefined {\n\t\tconst cachePath = this.privatePrimeAuthorizationCachePath();\n\t\tif (!cachePath) {\n\t\t\treturn undefined;\n\t\t}\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(readFileSync(cachePath, \"utf8\")) as Partial<\n\t\t\t\tOmit<PrivatePrimeAuthorizationCache, \"modelIds\"> & { modelIds: string[] }\n\t\t\t>;\n\t\t\tif (\n\t\t\t\ttypeof parsed.fingerprint !== \"string\" ||\n\t\t\t\t!Array.isArray(parsed.modelIds) ||\n\t\t\t\ttypeof parsed.refreshedAt !== \"number\"\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tfingerprint: parsed.fingerprint,\n\t\t\t\tmodelIds: new Set(parsed.modelIds),\n\t\t\t\trefreshedAt: parsed.refreshedAt,\n\t\t\t};\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate writePrivatePrimeAuthorizationCache(cache: PrivatePrimeAuthorizationCache): void {\n\t\tconst cachePath = this.privatePrimeAuthorizationCachePath();\n\t\tif (!cachePath) {\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tconst tmpPath = `${cachePath}.${process.pid}.tmp`;\n\t\t\twriteFileSync(tmpPath, JSON.stringify({ ...cache, modelIds: [...cache.modelIds] }), { mode: 0o600 });\n\t\t\trenameSync(tmpPath, cachePath);\n\t\t} catch {\n\t\t\t// A failed cache write only requires a later refetch.\n\t\t}\n\t}\n\n\tasync refreshModelCatalog(): Promise<ModelCatalogSnapshot> {\n\t\tconst availableModels = await this.refreshAvailableModels();\n\t\tconst availablePrivateModels = new Set(\n\t\t\tavailableModels.filter(isPrivatePrimeInferenceModel).map((model) => `${model.provider}/${model.id}`),\n\t\t);\n\t\treturn {\n\t\t\tmodels: this.models.filter(\n\t\t\t\t(model) =>\n\t\t\t\t\t!isPrivatePrimeInferenceModel(model) || availablePrivateModels.has(`${model.provider}/${model.id}`),\n\t\t\t),\n\t\t\tconfiguredProviders: [...new Set(availableModels.map((model) => model.provider))],\n\t\t};\n\t}\n\n\tasync canUseModel(model: Model<Api>): Promise<boolean> {\n\t\tif (!this.hasConfiguredAuth(model)) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!isPrivatePrimeInferenceModel(model)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst availableModels = await this.refreshAvailableModels();\n\t\treturn availableModels.some((candidate) => candidate.provider === model.provider && candidate.id === model.id);\n\t}\n\n\tasync getExecutableModels(): Promise<Model<Api>[]> {\n\t\tawait this.refreshPrivatePrimeInferenceAuthorization();\n\t\tconst availableModels = this.getAvailable();\n\t\tconst codexModels = availableModels.filter((model) => model.provider === \"openai-codex\");\n\t\tif (codexModels.length === 0) {\n\t\t\treturn availableModels;\n\t\t}\n\n\t\tconst auth = await this.getApiKeyAndHeaders(codexModels[0]!);\n\t\tif (!auth.ok || !auth.apiKey) {\n\t\t\treturn availableModels.filter((model) => model.provider !== \"openai-codex\");\n\t\t}\n\t\tconst authFingerprint = createHash(\"sha256\").update(auth.apiKey).digest(\"hex\");\n\t\tconst cached = this.openAICodexModelsCache;\n\t\tif (cached?.authFingerprint === authFingerprint && Date.now() - cached.refreshedAt < 300_000) {\n\t\t\treturn availableModels.filter((model) => model.provider !== \"openai-codex\" || cached.modelIds.has(model.id));\n\t\t}\n\n\t\tconst accountId = readOpenAICodexAccountId(auth.apiKey);\n\t\tif (!accountId) {\n\t\t\treturn availableModels.filter((model) => model.provider !== \"openai-codex\");\n\t\t}\n\t\ttry {\n\t\t\tconst response = await fetch(openAICodexModelsUrl(codexModels[0]!.baseUrl), {\n\t\t\t\theaders: {\n\t\t\t\t\t...auth.headers,\n\t\t\t\t\tAuthorization: `Bearer ${auth.apiKey}`,\n\t\t\t\t\t\"chatgpt-account-id\": accountId,\n\t\t\t\t\toriginator: \"pi\",\n\t\t\t\t},\n\t\t\t\tsignal: AbortSignal.timeout(5_000),\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`OpenAI Codex model discovery failed with HTTP ${response.status}`);\n\t\t\t}\n\t\t\tconst modelIds = readOpenAICodexModelIds(await response.json());\n\t\t\tthis.openAICodexModelsCache = { authFingerprint, modelIds, refreshedAt: Date.now() };\n\t\t\treturn availableModels.filter((model) => model.provider !== \"openai-codex\" || modelIds.has(model.id));\n\t\t} catch {\n\t\t\tif (cached?.authFingerprint === authFingerprint && Date.now() - cached.refreshedAt < 300_000) {\n\t\t\t\treturn availableModels.filter(\n\t\t\t\t\t(model) => model.provider !== \"openai-codex\" || cached.modelIds.has(model.id),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn availableModels.filter((model) => model.provider !== \"openai-codex\");\n\t\t}\n\t}\n\n\t/**\n\t * Find a model by provider and ID.\n\t */\n\tfind(provider: string, modelId: string): Model<Api> | undefined {\n\t\treturn this.models.find((m) => m.provider === provider && m.id === modelId);\n\t}\n\n\t/**\n\t * Get API key for a model.\n\t */\n\thasConfiguredAuth(model: Model<Api>): boolean {\n\t\tif (model.provider === \"ollama\") return true;\n\t\treturn this.authStorage.hasAuth(model.provider) || this.hasConfiguredProviderRequestAuth(model.provider);\n\t}\n\n\tprivate fingerprintProviderRequestAuthSource(source: ProviderRequestAuthSource[\"source\"], material: string): string {\n\t\tconst digest = createHash(\"sha256\").update(source).update(\"\\0\").update(material).digest(\"hex\");\n\t\treturn `${source}:${digest}`;\n\t}\n\n\tprivate createProviderRequestAuthSource(options: {\n\t\tsource: ProviderRequestAuthSource[\"source\"];\n\t\tidentityMaterial: string;\n\t\tvalueMaterial?: string;\n\t\tlabel?: string;\n\t\tresolveValueMaterial?: () => string | undefined;\n\t}): ProviderRequestAuthSource {\n\t\treturn {\n\t\t\tconfigured: true,\n\t\t\tsource: options.source,\n\t\t\t...(options.label ? { label: options.label } : {}),\n\t\t\tidentityFingerprint: this.fingerprintProviderRequestAuthSource(\n\t\t\t\toptions.source,\n\t\t\t\t`identity:${options.identityMaterial}`,\n\t\t\t),\n\t\t\t...(options.valueMaterial !== undefined\n\t\t\t\t? {\n\t\t\t\t\t\tvalueFingerprint: this.fingerprintProviderRequestAuthSource(\n\t\t\t\t\t\t\toptions.source,\n\t\t\t\t\t\t\t`value:${options.identityMaterial}\\0${options.valueMaterial}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...(options.resolveValueMaterial\n\t\t\t\t? {\n\t\t\t\t\t\tresolveValueFingerprint: () => {\n\t\t\t\t\t\t\tconst valueMaterial = options.resolveValueMaterial?.();\n\t\t\t\t\t\t\treturn valueMaterial === undefined\n\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t: this.fingerprintProviderRequestAuthSource(\n\t\t\t\t\t\t\t\t\t\toptions.source,\n\t\t\t\t\t\t\t\t\t\t`value:${options.identityMaterial}\\0${valueMaterial}`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t};\n\t}\n\n\tprivate getProviderRequestAuthSource(\n\t\tprovider: string,\n\t\toptions?: { resolvedApiKey?: string },\n\t): ProviderRequestAuthSource | undefined {\n\t\tconst providerApiKey = this.providerRequestConfigs.get(provider)?.apiKey;\n\t\tif (!providerApiKey) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (providerApiKey.startsWith(\"!\")) {\n\t\t\treturn this.createProviderRequestAuthSource({\n\t\t\t\tsource: \"models_json_command\",\n\t\t\t\tidentityMaterial: providerApiKey,\n\t\t\t\tvalueMaterial:\n\t\t\t\t\toptions?.resolvedApiKey === undefined ? undefined : `${providerApiKey}\\0${options.resolvedApiKey}`,\n\t\t\t\tresolveValueMaterial: () => {\n\t\t\t\t\tconst resolved = resolveConfigValueUncached(providerApiKey);\n\t\t\t\t\treturn resolved === undefined ? undefined : `${providerApiKey}\\0${resolved}`;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\tconst envValue = process.env[providerApiKey];\n\t\tif (envValue) {\n\t\t\treturn this.createProviderRequestAuthSource({\n\t\t\t\tsource: \"environment\",\n\t\t\t\tlabel: providerApiKey,\n\t\t\t\tidentityMaterial: providerApiKey,\n\t\t\t\tvalueMaterial: `${providerApiKey}\\0${envValue}`,\n\t\t\t});\n\t\t}\n\n\t\treturn this.createProviderRequestAuthSource({\n\t\t\tsource: \"models_json_key\",\n\t\t\tidentityMaterial: provider,\n\t\t\tvalueMaterial: providerApiKey,\n\t\t});\n\t}\n\n\tprivate isProviderRequestAuthStale(provider: string, source: ProviderRequestAuthSource): boolean {\n\t\tconst matchingStale = this.getMatchingStaleProviderRequestAuthSources(provider, source);\n\t\tif (matchingStale.length === 0) {\n\t\t\treturn false;\n\t\t}\n\t\tconst valueFingerprint = source.valueFingerprint ?? source.resolveValueFingerprint?.();\n\t\treturn Boolean(valueFingerprint && matchingStale.some((token) => token.valueFingerprint === valueFingerprint));\n\t}\n\n\tprivate isProviderRequestAuthStaleForStatus(provider: string, source: ProviderRequestAuthSource): boolean {\n\t\tconst matchingStale = this.getMatchingStaleProviderRequestAuthSources(provider, source);\n\t\tif (matchingStale.length === 0) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!source.valueFingerprint) {\n\t\t\treturn true;\n\t\t}\n\t\tconst isStale = matchingStale.some((token) => token.valueFingerprint === source.valueFingerprint);\n\t\tif (!isStale) {\n\t\t\tthis.clearStaleProviderRequestAuthSource(provider, source);\n\t\t}\n\t\treturn isStale;\n\t}\n\n\tprivate getMatchingStaleProviderRequestAuthSources(\n\t\tprovider: string,\n\t\tsource: ProviderRequestAuthSource,\n\t): AuthSourceToken[] {\n\t\tconst stale = this.staleProviderRequestAuthSources.get(provider);\n\t\tif (!stale) {\n\t\t\treturn [];\n\t\t}\n\t\treturn stale.filter(\n\t\t\t(token) => token.source === source.source && token.identityFingerprint === source.identityFingerprint,\n\t\t);\n\t}\n\n\tprivate clearStaleProviderRequestAuthSource(provider: string, source: ProviderRequestAuthSource): void {\n\t\tconst stale = this.staleProviderRequestAuthSources.get(provider);\n\t\tif (!stale) {\n\t\t\treturn;\n\t\t}\n\t\tconst next = stale.filter(\n\t\t\t(token) => token.source !== source.source || token.identityFingerprint !== source.identityFingerprint,\n\t\t);\n\t\tif (next.length === 0) {\n\t\t\tthis.staleProviderRequestAuthSources.delete(provider);\n\t\t} else {\n\t\t\tthis.staleProviderRequestAuthSources.set(provider, next);\n\t\t}\n\t}\n\n\tprivate getProviderRequestAuthSourceToken(\n\t\tprovider: string,\n\t\tsource: ProviderRequestAuthSource,\n\t): AuthSourceToken | undefined {\n\t\tconst valueFingerprint = source.valueFingerprint ?? source.resolveValueFingerprint?.();\n\t\tif (!valueFingerprint) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tprovider,\n\t\t\tsource: source.source,\n\t\t\tidentityFingerprint: source.identityFingerprint,\n\t\t\tvalueFingerprint,\n\t\t};\n\t}\n\n\tprivate setLastProviderAuthSourceToken(provider: string, token: AuthSourceToken | undefined): void {\n\t\tif (token) {\n\t\t\tthis.lastProviderAuthSourceTokens.set(provider, token);\n\t\t} else {\n\t\t\tthis.lastProviderAuthSourceTokens.delete(provider);\n\t\t}\n\t}\n\n\tprivate hasConfiguredProviderRequestAuth(provider: string): boolean {\n\t\tconst source = this.getProviderRequestAuthSource(provider);\n\t\treturn source !== undefined && !this.isProviderRequestAuthStaleForStatus(provider, source);\n\t}\n\n\tmarkProviderAuthStale(provider: string): boolean {\n\t\tif (this.authStorage.markAuthStale(provider)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst token = this.getCurrentProviderAuthSourceToken(provider);\n\t\treturn token ? this.markProviderAuthSourceStale(token) : false;\n\t}\n\n\tgetCurrentProviderAuthSourceToken(provider: string): AuthSourceToken | undefined {\n\t\tconst lastRequestToken = this.lastProviderAuthSourceTokens.get(provider);\n\t\tif (lastRequestToken) {\n\t\t\treturn lastRequestToken;\n\t\t}\n\n\t\tconst authStorageToken = this.authStorage.getCurrentAuthSourceToken(provider);\n\t\tif (authStorageToken) {\n\t\t\treturn authStorageToken;\n\t\t}\n\n\t\tconst providerApiKey = this.providerRequestConfigs.get(provider)?.apiKey;\n\t\tif (!providerApiKey) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst resolvedApiKey = resolveConfigValueUncached(providerApiKey);\n\t\tconst source = this.getProviderRequestAuthSource(provider, { resolvedApiKey });\n\t\tconst valueFingerprint = source?.valueFingerprint ?? source?.resolveValueFingerprint?.();\n\t\tif (!source || !valueFingerprint || this.isProviderRequestAuthStale(provider, source)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tprovider,\n\t\t\tsource: source.source,\n\t\t\tidentityFingerprint: source.identityFingerprint,\n\t\t\tvalueFingerprint,\n\t\t};\n\t}\n\n\tmarkProviderAuthSourceStale(token: AuthSourceToken): boolean {\n\t\tlet marked = false;\n\t\tconst providerRequestSource = this.getProviderRequestAuthSource(token.provider);\n\t\tif (\n\t\t\tproviderRequestSource?.source === token.source &&\n\t\t\tproviderRequestSource.identityFingerprint === token.identityFingerprint\n\t\t) {\n\t\t\tconst stale = this.staleProviderRequestAuthSources.get(token.provider) ?? [];\n\t\t\tif (\n\t\t\t\t!stale.some(\n\t\t\t\t\t(existing) =>\n\t\t\t\t\t\texisting.source === token.source &&\n\t\t\t\t\t\texisting.identityFingerprint === token.identityFingerprint &&\n\t\t\t\t\t\texisting.valueFingerprint === token.valueFingerprint,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tstale.push(token);\n\t\t\t}\n\t\t\tthis.staleProviderRequestAuthSources.set(token.provider, stale);\n\t\t\tmarked = true;\n\t\t}\n\n\t\tif (token.source !== \"models_json_key\" && token.source !== \"models_json_command\") {\n\t\t\tmarked = this.authStorage.markAuthSourceStale(token) || marked;\n\t\t}\n\n\t\treturn marked;\n\t}\n\n\tprivate getModelRequestKey(provider: string, modelId: string): string {\n\t\treturn `${provider}:${modelId}`;\n\t}\n\n\tprivate storeProviderRequestConfig(\n\t\tproviderName: string,\n\t\tconfig: {\n\t\t\tapiKey?: string;\n\t\t\theaders?: Record<string, string>;\n\t\t\tauthHeader?: boolean;\n\t\t},\n\t): void {\n\t\tif (!config.apiKey && !config.headers && !config.authHeader) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.providerRequestConfigs.set(providerName, {\n\t\t\tapiKey: config.apiKey,\n\t\t\theaders: config.headers,\n\t\t\tauthHeader: config.authHeader,\n\t\t});\n\t}\n\n\tprivate storeModelHeaders(providerName: string, modelId: string, headers?: Record<string, string>): void {\n\t\tconst key = this.getModelRequestKey(providerName, modelId);\n\t\tif (!headers || Object.keys(headers).length === 0) {\n\t\t\tthis.modelRequestHeaders.delete(key);\n\t\t\treturn;\n\t\t}\n\t\tthis.modelRequestHeaders.set(key, headers);\n\t}\n\n\t/**\n\t * Get API key and request headers for a model.\n\t */\n\tasync getApiKeyAndHeaders(model: Model<Api>): Promise<ResolvedRequestAuth> {\n\t\ttry {\n\t\t\tconst providerConfig = this.providerRequestConfigs.get(model.provider);\n\t\t\tconst authStorageAuth = await this.authStorage.getApiKeyWithSourceToken(model.provider, {\n\t\t\t\tincludeFallback: false,\n\t\t\t});\n\t\t\tlet apiKey = model.provider === \"ollama\" ? \"ollama\" : authStorageAuth.apiKey;\n\t\t\tlet authSourceToken = authStorageAuth.sourceToken;\n\t\t\tif (apiKey === undefined && providerConfig?.apiKey) {\n\t\t\t\tconst resolvedApiKey = resolveConfigValueOrThrow(\n\t\t\t\t\tproviderConfig.apiKey,\n\t\t\t\t\t`API key for provider \"${model.provider}\"`,\n\t\t\t\t);\n\t\t\t\tconst providerRequestAuthSource = this.getProviderRequestAuthSource(model.provider, { resolvedApiKey });\n\t\t\t\tif (\n\t\t\t\t\tproviderRequestAuthSource &&\n\t\t\t\t\t!this.isProviderRequestAuthStale(model.provider, providerRequestAuthSource)\n\t\t\t\t) {\n\t\t\t\t\tthis.clearStaleProviderRequestAuthSource(model.provider, providerRequestAuthSource);\n\t\t\t\t\tapiKey = resolvedApiKey;\n\t\t\t\t\tauthSourceToken = this.getProviderRequestAuthSourceToken(model.provider, providerRequestAuthSource);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.setLastProviderAuthSourceToken(model.provider, apiKey === undefined ? undefined : authSourceToken);\n\n\t\t\tconst providerHeaders = resolveHeadersOrThrow(providerConfig?.headers, `provider \"${model.provider}\"`);\n\t\t\tconst authStorageHeaders = this.authStorage.getProviderHeaders(model.provider);\n\t\t\tconst modelHeaders = resolveHeadersOrThrow(\n\t\t\t\tthis.modelRequestHeaders.get(this.getModelRequestKey(model.provider, model.id)),\n\t\t\t\t`model \"${model.provider}/${model.id}\"`,\n\t\t\t);\n\n\t\t\tlet headers =\n\t\t\t\tmodel.headers || authStorageHeaders || providerHeaders || modelHeaders\n\t\t\t\t\t? { ...model.headers, ...authStorageHeaders, ...providerHeaders, ...modelHeaders }\n\t\t\t\t\t: undefined;\n\n\t\t\tif (providerConfig?.authHeader) {\n\t\t\t\tif (!apiKey) {\n\t\t\t\t\treturn { ok: false, error: `No API key found for \"${model.provider}\"` };\n\t\t\t\t}\n\t\t\t\theaders = { ...headers, Authorization: `Bearer ${apiKey}` };\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\tapiKey,\n\t\t\t\theaders: headers && Object.keys(headers).length > 0 ? headers : undefined,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Return auth status for a provider, including request auth configured in models.json.\n\t * This intentionally does not execute command-backed config values.\n\t */\n\tgetProviderAuthStatus(provider: string): AuthStatus {\n\t\tconst authStatus = this.authStorage.getAuthStatus(provider);\n\t\tif (authStatus.source && authStatus.source !== \"stale\") {\n\t\t\treturn authStatus;\n\t\t}\n\n\t\tconst source = this.getProviderRequestAuthSource(provider);\n\t\tif (!source) {\n\t\t\treturn authStatus;\n\t\t}\n\n\t\tif (this.isProviderRequestAuthStaleForStatus(provider, source)) {\n\t\t\treturn { configured: false, source: \"stale\", label: \"expired\" };\n\t\t}\n\n\t\treturn {\n\t\t\tconfigured: true,\n\t\t\tsource: source.source,\n\t\t\t...(source.label ? { label: source.label } : {}),\n\t\t};\n\t}\n\n\t/**\n\t * Get display name for a provider.\n\t */\n\tgetProviderDisplayName(provider: string): string {\n\t\tconst registeredProvider = this.registeredProviders.get(provider);\n\t\tconst oauthProvider = this.authStorage.getOAuthProviders().find((p) => p.id === provider);\n\n\t\treturn (\n\t\t\tregisteredProvider?.name ??\n\t\t\tregisteredProvider?.oauth?.name ??\n\t\t\toauthProvider?.name ??\n\t\t\tBUILT_IN_PROVIDER_DISPLAY_NAMES[provider] ??\n\t\t\tprovider\n\t\t);\n\t}\n\n\t/**\n\t * Get API key for a provider.\n\t */\n\tasync getApiKeyForProvider(provider: string): Promise<string | undefined> {\n\t\tconst authStorageAuth = await this.authStorage.getApiKeyWithSourceToken(provider, { includeFallback: false });\n\t\tif (authStorageAuth.apiKey !== undefined) {\n\t\t\tthis.setLastProviderAuthSourceToken(provider, authStorageAuth.sourceToken);\n\t\t\treturn authStorageAuth.apiKey;\n\t\t}\n\n\t\tconst providerApiKey = this.providerRequestConfigs.get(provider)?.apiKey;\n\t\tif (!providerApiKey) {\n\t\t\tthis.setLastProviderAuthSourceToken(provider, undefined);\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst resolvedApiKey = resolveConfigValueUncached(providerApiKey);\n\t\tif (resolvedApiKey === undefined) {\n\t\t\tthis.setLastProviderAuthSourceToken(provider, undefined);\n\t\t\treturn undefined;\n\t\t}\n\t\tconst source = this.getProviderRequestAuthSource(provider, { resolvedApiKey });\n\t\tif (!source || this.isProviderRequestAuthStale(provider, source)) {\n\t\t\tthis.setLastProviderAuthSourceToken(provider, undefined);\n\t\t\treturn undefined;\n\t\t}\n\t\tthis.clearStaleProviderRequestAuthSource(provider, source);\n\t\tthis.setLastProviderAuthSourceToken(provider, this.getProviderRequestAuthSourceToken(provider, source));\n\n\t\treturn resolvedApiKey;\n\t}\n\n\t/**\n\t * Check if a model is using OAuth credentials (subscription).\n\t */\n\tisUsingOAuth(model: Model<Api>): boolean {\n\t\tconst cred = this.authStorage.get(model.provider);\n\t\treturn cred?.type === \"oauth\";\n\t}\n\n\t/**\n\t * Register a provider dynamically (from extensions).\n\t *\n\t * If provider has models: replaces all existing models for this provider.\n\t * If provider has only baseUrl/headers: overrides existing models' URLs.\n\t * If provider has oauth: registers OAuth provider for /login support.\n\t */\n\tregisterProvider(providerName: string, config: ProviderConfigInput): void {\n\t\tthis.validateProviderConfig(providerName, config);\n\t\tthis.applyProviderConfig(providerName, config);\n\t\tthis.upsertRegisteredProvider(providerName, config);\n\t}\n\n\t/**\n\t * Unregister a previously registered provider.\n\t *\n\t * Removes the provider from the registry and reloads models from disk so that\n\t * built-in models overridden by this provider are restored to their original state.\n\t * Also resets dynamic OAuth and API stream registrations before reapplying\n\t * remaining dynamic providers.\n\t * Has no effect if the provider was never registered.\n\t */\n\tunregisterProvider(providerName: string): void {\n\t\tif (!this.registeredProviders.has(providerName)) return;\n\t\tthis.registeredProviders.delete(providerName);\n\t\tthis.refresh();\n\t}\n\n\t/**\n\t * Upsert a provider config into registeredProviders.\n\t * If the provider is already registered, defined values in the incoming config\n\t * override existing ones; undefined values are preserved from the stored config.\n\t * If the provider is not registered, the incoming config is stored as-is.\n\t */\n\tprivate upsertRegisteredProvider(providerName: string, config: ProviderConfigInput): void {\n\t\tconst existing = this.registeredProviders.get(providerName);\n\t\tif (!existing) {\n\t\t\tthis.registeredProviders.set(providerName, config);\n\t\t\treturn;\n\t\t}\n\t\tfor (const k of Object.keys(config) as (keyof ProviderConfigInput)[]) {\n\t\t\tif (config[k] !== undefined) {\n\t\t\t\t(existing as Record<string, unknown>)[k] = config[k];\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate validateProviderConfig(providerName: string, config: ProviderConfigInput): void {\n\t\tif (config.streamSimple && !config.api) {\n\t\t\tthrow new Error(`Provider ${providerName}: \"api\" is required when registering streamSimple.`);\n\t\t}\n\n\t\tif (!config.models || config.models.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (!config.baseUrl) {\n\t\t\tthrow new Error(`Provider ${providerName}: \"baseUrl\" is required when defining models.`);\n\t\t}\n\t\tif (!config.apiKey && !config.oauth) {\n\t\t\tthrow new Error(`Provider ${providerName}: \"apiKey\" or \"oauth\" is required when defining models.`);\n\t\t}\n\n\t\tfor (const modelDef of config.models) {\n\t\t\tconst api = modelDef.api || config.api;\n\t\t\tif (!api) {\n\t\t\t\tthrow new Error(`Provider ${providerName}, model ${modelDef.id}: no \"api\" specified.`);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate applyProviderConfig(providerName: string, config: ProviderConfigInput): void {\n\t\tif (config.oauth) {\n\t\t\tconst oauthProvider: OAuthProviderInterface = {\n\t\t\t\t...config.oauth,\n\t\t\t\tid: providerName,\n\t\t\t};\n\t\t\tregisterOAuthProvider(oauthProvider);\n\t\t}\n\n\t\tif (config.streamSimple) {\n\t\t\tconst streamSimple = config.streamSimple;\n\t\t\tregisterApiProvider(\n\t\t\t\t{\n\t\t\t\t\tapi: config.api!,\n\t\t\t\t\tstream: (model, context, options) => streamSimple(model, context, options as SimpleStreamOptions),\n\t\t\t\t\tstreamSimple,\n\t\t\t\t},\n\t\t\t\t`provider:${providerName}`,\n\t\t\t);\n\t\t}\n\n\t\tthis.storeProviderRequestConfig(providerName, config);\n\n\t\tif (config.models && config.models.length > 0) {\n\t\t\tthis.models = this.models.filter((m) => m.provider !== providerName);\n\n\t\t\tfor (const modelDef of config.models) {\n\t\t\t\tconst api = modelDef.api || config.api;\n\t\t\t\tthis.storeModelHeaders(providerName, modelDef.id, modelDef.headers);\n\n\t\t\t\tthis.models.push({\n\t\t\t\t\tid: modelDef.id,\n\t\t\t\t\tname: modelDef.name,\n\t\t\t\t\tapi: api as Api,\n\t\t\t\t\tprovider: providerName,\n\t\t\t\t\tbaseUrl: modelDef.baseUrl ?? config.baseUrl!,\n\t\t\t\t\treasoning: modelDef.reasoning,\n\t\t\t\t\tthinkingLevelMap: modelDef.thinkingLevelMap,\n\t\t\t\t\tinput: modelDef.input as (\"text\" | \"image\")[],\n\t\t\t\t\tcost: modelDef.cost,\n\t\t\t\t\tcontextWindow: modelDef.contextWindow,\n\t\t\t\t\tmaxTokens: modelDef.maxTokens,\n\t\t\t\t\theaders: undefined,\n\t\t\t\t\tcompat: modelDef.compat,\n\t\t\t\t} as Model<Api>);\n\t\t\t}\n\t\t\tif (config.oauth?.modifyModels) {\n\t\t\t\tconst cred = this.authStorage.get(providerName);\n\t\t\t\tif (cred?.type === \"oauth\") {\n\t\t\t\t\tthis.models = config.oauth.modifyModels(this.models, cred);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (config.baseUrl || config.headers) {\n\t\t\tthis.models = this.models.map((m) => {\n\t\t\t\tif (m.provider !== providerName) return m;\n\t\t\t\treturn {\n\t\t\t\t\t...m,\n\t\t\t\t\tbaseUrl: config.baseUrl ?? m.baseUrl,\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\t}\n}\n\n/**\n * Input type for registerProvider API.\n */\nexport interface ProviderConfigInput {\n\tname?: string;\n\tbaseUrl?: string;\n\tapiKey?: string;\n\tapi?: Api;\n\tstreamSimple?: (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n\t/** OAuth provider for /login support */\n\toauth?: Omit<OAuthProviderInterface, \"id\">;\n\tmodels?: Array<{\n\t\tid: string;\n\t\tname: string;\n\t\tapi?: Api;\n\t\tbaseUrl?: string;\n\t\treasoning: boolean;\n\t\tthinkingLevelMap?: Model<Api>[\"thinkingLevelMap\"];\n\t\tinput: (\"text\" | \"image\")[];\n\t\tcost: { input: number; output: number; cacheRead: number; cacheWrite: number };\n\t\tcontextWindow: number;\n\t\tmaxTokens: number;\n\t\theaders?: Record<string, string>;\n\t\tcompat?: Model<Api>[\"compat\"];\n\t}>;\n}\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Model } from "@asm-agent/ai";
|
|
2
|
+
type JsonRequest = (url: string, timeoutMs: number) => Promise<unknown>;
|
|
2
3
|
export declare function getOllamaBaseUrl(): string;
|
|
3
|
-
export declare function discoverOllamaModels(): Promise<Model<"openai-completions">[]>;
|
|
4
|
+
export declare function discoverOllamaModels(request?: JsonRequest): Promise<Model<"openai-completions">[]>;
|
|
5
|
+
export {};
|
|
4
6
|
//# sourceMappingURL=ollama-models.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ollama-models.d.ts","sourceRoot":"","sources":["../../src/core/ollama-models.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ollama-models.d.ts","sourceRoot":"","sources":["../../src/core/ollama-models.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAK3C,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAExE,wBAAgB,gBAAgB,IAAI,MAAM,CAIzC;AA8DD,wBAAsB,oBAAoB,CAAC,OAAO,GAAE,WAAyB,GAAG,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAWrH","sourcesContent":["import { get as httpGet } from \"node:http\";\nimport { get as httpsGet } from \"node:https\";\nimport type { Model } from \"@asm-agent/ai\";\n\nconst DEFAULT_OLLAMA_HOST = \"http://127.0.0.1:11434\";\nconst OLLAMA_DISCOVERY_TIMEOUT_MS = 1500;\n\ntype JsonRequest = (url: string, timeoutMs: number) => Promise<unknown>;\n\nexport function getOllamaBaseUrl(): string {\n\tconst configured = process.env.OLLAMA_HOST?.trim() || DEFAULT_OLLAMA_HOST;\n\tconst host = configured.replace(/\\/$/, \"\");\n\treturn host.endsWith(\"/v1\") ? host : `${host}/v1`;\n}\n\nfunction getOllamaTagsUrl(baseUrl: string): string {\n\treturn `${baseUrl.replace(/\\/v1$/, \"\")}/api/tags`;\n}\n\nfunction requestJson(url: string, timeoutMs: number): Promise<unknown> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst parsed = new URL(url);\n\t\tconst get = parsed.protocol === \"https:\" ? httpsGet : httpGet;\n\t\tconst request = get(parsed, { timeout: timeoutMs }, (response) => {\n\t\t\tlet body = \"\";\n\t\t\tresponse.setEncoding(\"utf8\");\n\t\t\tresponse.on(\"data\", (chunk: string) => {\n\t\t\t\tbody += chunk;\n\t\t\t});\n\t\t\tresponse.on(\"end\", () => {\n\t\t\t\tif (response.statusCode !== 200) {\n\t\t\t\t\treject(new Error(`Ollama returned HTTP ${response.statusCode ?? \"unknown\"}`));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tresolve(JSON.parse(body) as unknown);\n\t\t\t\t} catch (error) {\n\t\t\t\t\treject(error);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\trequest.on(\"error\", reject);\n\t\trequest.on(\"timeout\", () => request.destroy(new Error(\"Ollama discovery timed out\")));\n\t});\n}\n\ninterface OllamaTag {\n\tname?: unknown;\n}\n\nfunction modelFromTag(tag: OllamaTag, baseUrl: string): Model<\"openai-completions\"> | undefined {\n\tif (typeof tag.name !== \"string\" || !tag.name.trim()) return undefined;\n\tconst name = tag.name.trim();\n\treturn {\n\t\tid: name,\n\t\tname,\n\t\tapi: \"openai-completions\",\n\t\tprovider: \"ollama\",\n\t\tbaseUrl,\n\t\treasoning: false,\n\t\tinput: [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: 131072,\n\t\tmaxTokens: 8192,\n\t\tcompat: {\n\t\t\tsupportsStore: false,\n\t\t\tsupportsDeveloperRole: false,\n\t\t\tsupportsReasoningEffort: false,\n\t\t\tmaxTokensField: \"max_tokens\",\n\t\t\tsupportsUsageInStreaming: false,\n\t\t\tsupportsStrictMode: false,\n\t\t},\n\t};\n}\n\nexport async function discoverOllamaModels(request: JsonRequest = requestJson): Promise<Model<\"openai-completions\">[]> {\n\tconst baseUrl = getOllamaBaseUrl();\n\ttry {\n\t\tconst payload = (await request(getOllamaTagsUrl(baseUrl), OLLAMA_DISCOVERY_TIMEOUT_MS)) as { models?: unknown };\n\t\tif (!Array.isArray(payload.models)) return [];\n\t\treturn payload.models.flatMap((tag) =>\n\t\t\ttag && typeof tag === \"object\" ? [modelFromTag(tag as OllamaTag, baseUrl)].filter(Boolean) : [],\n\t\t) as Model<\"openai-completions\">[];\n\t} catch {\n\t\treturn [];\n\t}\n}\n"]}
|