gsd-pi 2.47.0-dev.04be8c9 → 2.47.0-dev.f2e721d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/resources/extensions/gsd/auto-start.js +8 -1
- package/dist/resources/extensions/gsd/forensics.js +292 -1
- package/dist/resources/extensions/gsd/guided-flow.js +85 -3
- package/dist/resources/extensions/gsd/prompts/forensics.md +37 -5
- package/dist/resources/extensions/gsd/session-forensics.js +10 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +17 -17
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/api/forensics/route.js +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +17 -17
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +2 -2
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/package.json +1 -1
- package/packages/pi-agent-core/dist/agent-loop.js +3 -2
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/src/agent-loop.ts +3 -2
- package/packages/pi-coding-agent/dist/core/model-registry-auth-mode.test.js +43 -0
- package/packages/pi-coding-agent/dist/core/model-registry-auth-mode.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-registry.js +26 -3
- package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
- package/packages/pi-coding-agent/src/core/model-registry-auth-mode.test.ts +70 -0
- package/packages/pi-coding-agent/src/core/model-registry.ts +29 -2
- package/packages/pi-tui/dist/components/box.d.ts +1 -0
- package/packages/pi-tui/dist/components/box.d.ts.map +1 -1
- package/packages/pi-tui/dist/components/box.js +10 -0
- package/packages/pi-tui/dist/components/box.js.map +1 -1
- package/packages/pi-tui/src/components/box.ts +10 -0
- package/src/resources/extensions/gsd/auto-start.ts +7 -1
- package/src/resources/extensions/gsd/forensics.ts +329 -2
- package/src/resources/extensions/gsd/guided-flow.ts +105 -3
- package/src/resources/extensions/gsd/prompts/forensics.md +37 -5
- package/src/resources/extensions/gsd/session-forensics.ts +11 -1
- package/src/resources/extensions/gsd/tests/discuss-queued-milestones.test.ts +241 -0
- package/src/resources/extensions/gsd/tests/forensics-error-filter.test.ts +121 -0
- package/src/resources/extensions/gsd/tests/forensics-journal.test.ts +162 -0
- package/src/resources/extensions/gsd/tests/preflight-context-draft-filter.test.ts +115 -0
- package/src/resources/extensions/gsd/tests/stale-milestone-id-reservation.test.ts +79 -0
- /package/dist/web/standalone/.next/static/{GR9tXQAPXXBL4AUugDPlJ → O3E7X3EJ2lEKs_0hIUzGd}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{GR9tXQAPXXBL4AUugDPlJ → O3E7X3EJ2lEKs_0hIUzGd}/_ssgManifest.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-registry-auth-mode.test.js","sourceRoot":"","sources":["../../src/core/model-registry-auth-mode.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,SAAS,cAAc,CAAC,SAAyC;IAChE,MAAM,WAAW,GAAG;QACnB,mBAAmB,EAAE,GAAG,EAAE,GAAE,CAAC;QAC7B,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;QAC5B,iBAAiB,EAAE,GAAG,EAAE,CAAC,EAAE;QAC3B,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS;QACpB,OAAO,EAAE,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC;QACnC,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,SAAS;KACN,CAAC;IAE5B,OAAO,IAAI,aAAa,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AACl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C,QAAQ,EAAE,aAAa;YACvB,OAAO,EAAE,mBAAmB;YAC5B,GAAG,EAAE,OAAc;YACnB,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,MAAM,EAAE,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;SAC3C,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAc,CAAC,CAAC;QAChD,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,6CAA6C,CAAC,CAAC;QAEnE,QAAQ,CAAC,YAAY,CACpB,SAAS,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,CAAC,EACrC,WAAW,EAAE,EACb,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAyB,CACjH,CAAC;QAEF,MAAM,QAAQ,GAAG,GAAG,CAAC,kBAAkB,EAAE,CAAC;QAC1C,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,oCAAoC,CAAC,CAAC;QAC1D,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,QAAQ,EAAE,KAAK,EAAE,yBAAyB,CAAC,CAAC;QACrE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,6BAA6B,CAAC,CAAC;QACtE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;QAClF,MAAM,CAAC,KAAK,CAAE,QAAoC,CAAC,SAAS,EAAE,MAAM,EAAE,6BAA6B,CAAC,CAAC;IACtG,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { describe, it } from \"node:test\";\nimport type { Api, Model, SimpleStreamOptions, Context, AssistantMessageEventStream } from \"@gsd/pi-ai\";\nimport { getApiProvider } from \"@gsd/pi-ai\";\nimport type { AuthStorage } from \"./auth-storage.js\";\nimport { ModelRegistry } from \"./model-registry.js\";\n\nfunction createRegistry(hasAuthFn?: (provider: string) => boolean): ModelRegistry {\n\tconst authStorage = {\n\t\tsetFallbackResolver: () => {},\n\t\tonCredentialChange: () => {},\n\t\tgetOAuthProviders: () => [],\n\t\tget: () => undefined,\n\t\thasAuth: hasAuthFn ?? (() => false),\n\t\tgetApiKey: async () => undefined,\n\t} as unknown as AuthStorage;\n\n\treturn new ModelRegistry(authStorage, undefined);\n}\n\nfunction createProviderModel(id: string, api?: string): NonNullable<Parameters<ModelRegistry[\"registerProvider\"]>[1][\"models\"]>[number] {\n\treturn {\n\t\tid,\n\t\tname: id,\n\t\tapi: (api ?? \"openai-completions\") as Api,\n\t\treasoning: false,\n\t\tinput: [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: 128000,\n\t\tmaxTokens: 16384,\n\t};\n}\n\nfunction findModel(registry: ModelRegistry, provider: string, id: string): Model<Api> | undefined {\n\treturn registry.getAvailable().find((m) => m.provider === provider && m.id === id);\n}\n\nfunction makeModel(provider: string, id: string, api: string): Model<Api> {\n\treturn {\n\t\tid,\n\t\tname: id,\n\t\tapi: api as Api,\n\t\tprovider,\n\t\tbaseUrl: `${provider}:`,\n\t\treasoning: false,\n\t\tinput: [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: 128000,\n\t\tmaxTokens: 16384,\n\t};\n}\n\nfunction makeContext(): Context {\n\treturn {\n\t\tsystemPrompt: \"test\",\n\t\tmessages: [{ role: \"user\", content: \"hello\", timestamp: Date.now() }],\n\t};\n}\n\n/** No-op streamSimple for tests that need one to pass validation but don't inspect it. */\nconst noopStreamSimple = (_model: Model<Api>, _context: Context, _options?: SimpleStreamOptions) => {\n\treturn {\n\t\t[Symbol.asyncIterator]() { return { next: async () => ({ value: undefined, done: true as const }) }; },\n\t\tresult: () => Promise.resolve({ role: \"assistant\" as const, content: [], api: \"test\" as Api, provider: \"test\", model: \"test\", usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } }, stopReason: \"stop\" as const, timestamp: Date.now() }),\n\t\tpush: () => {},\n\t\tend: () => {},\n\t} as unknown as AssistantMessageEventStream;\n};\n\n/** Create a spy streamSimple that captures the options it receives and returns a stub stream. */\nfunction createStreamSpy(): {\n\tstreamSimple: (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream;\n\tgetCapturedOptions: () => SimpleStreamOptions | undefined;\n} {\n\tlet capturedOptions: SimpleStreamOptions | undefined;\n\tconst streamSimple = (_model: Model<Api>, _context: Context, options?: SimpleStreamOptions) => {\n\t\tcapturedOptions = options;\n\t\t// Return a minimal stub that satisfies AssistantMessageEventStream\n\t\treturn {\n\t\t\t[Symbol.asyncIterator]() { return { next: async () => ({ value: undefined, done: true as const }) }; },\n\t\t\tresult: () => Promise.resolve({ role: \"assistant\" as const, content: [], api: \"test\" as Api, provider: \"test\", model: \"test\", usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } }, stopReason: \"stop\" as const, timestamp: Date.now() }),\n\t\t\tpush: () => {},\n\t\t\tend: () => {},\n\t\t} as unknown as AssistantMessageEventStream;\n\t};\n\treturn { streamSimple, getCapturedOptions: () => capturedOptions };\n}\n\n// ─── Registration ─────────────────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — registration\", () => {\n\tit(\"registers externalCli provider with streamSimple and without apiKey/oauth\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tassert.doesNotThrow(() => {\n\t\t\tregistry.registerProvider(\"cli-provider\", {\n\t\t\t\tauthMode: \"externalCli\",\n\t\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tstreamSimple: spy.streamSimple,\n\t\t\t\tmodels: [createProviderModel(\"cli-model\")],\n\t\t\t});\n\t\t});\n\t});\n\n\tit(\"registers none provider with streamSimple and without apiKey/oauth\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tassert.doesNotThrow(() => {\n\t\t\tregistry.registerProvider(\"none-provider\", {\n\t\t\t\tauthMode: \"none\",\n\t\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tstreamSimple: spy.streamSimple,\n\t\t\t\tmodels: [createProviderModel(\"local-model\")],\n\t\t\t});\n\t\t});\n\t});\n\n\tit(\"rejects apiKey provider without apiKey or oauth — message mentions authMode\", () => {\n\t\tconst registry = createRegistry();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"apikey-provider\", {\n\t\t\t\tauthMode: \"apiKey\",\n\t\t\t\tbaseUrl: \"https://api.local\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"authMode\"), \"error message must mention authMode\");\n\t\t\tassert.ok(err.message.includes(\"externalCli\"), \"error message must suggest externalCli\");\n\t\t\treturn true;\n\t\t});\n\t});\n\n\tit(\"rejects provider with no authMode and no apiKey/oauth (defaults to apiKey)\", () => {\n\t\tconst registry = createRegistry();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"bare-provider\", {\n\t\t\t\tbaseUrl: \"https://api.local\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"authMode\"), \"error message must mention authMode\");\n\t\t\treturn true;\n\t\t});\n\t});\n\n\tit(\"rejects externalCli provider without streamSimple\", () => {\n\t\tconst registry = createRegistry();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"cli-no-stream\", {\n\t\t\t\tauthMode: \"externalCli\",\n\t\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"streamSimple\"), \"error message must mention streamSimple\");\n\t\t\tassert.ok(err.message.includes(\"externalCli\"), \"error message must mention authMode\");\n\t\t\treturn true;\n\t\t});\n\t});\n\n\tit(\"rejects none provider without streamSimple\", () => {\n\t\tconst registry = createRegistry();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"none-no-stream\", {\n\t\t\t\tauthMode: \"none\",\n\t\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"streamSimple\"), \"error message must mention streamSimple\");\n\t\t\tassert.ok(err.message.includes(\"none\"), \"error message must mention authMode\");\n\t\t\treturn true;\n\t\t});\n\t});\n\n\tit(\"rejects externalCli provider that also sets apiKey\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"cli-with-key\", {\n\t\t\t\tauthMode: \"externalCli\",\n\t\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tapiKey: \"SHOULD_NOT_EXIST\",\n\t\t\t\tstreamSimple: spy.streamSimple,\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"apiKey\"), \"error message must mention apiKey\");\n\t\t\tassert.ok(err.message.includes(\"externalCli\"), \"error message must mention authMode\");\n\t\t\treturn true;\n\t\t});\n\t});\n\n\tit(\"rejects none provider that also sets apiKey\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"none-with-key\", {\n\t\t\t\tauthMode: \"none\",\n\t\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tapiKey: \"SHOULD_NOT_EXIST\",\n\t\t\t\tstreamSimple: spy.streamSimple,\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"apiKey\"), \"error message must mention apiKey\");\n\t\t\tassert.ok(err.message.includes(\"none\"), \"error message must mention authMode\");\n\t\t\treturn true;\n\t\t});\n\t});\n});\n\n// ─── getProviderAuthMode ──────────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — getProviderAuthMode\", () => {\n\tit(\"returns apiKey for unregistered (built-in) providers\", () => {\n\t\tconst registry = createRegistry();\n\t\tassert.equal(registry.getProviderAuthMode(\"anthropic\"), \"apiKey\");\n\t});\n\n\tit(\"returns explicit authMode when set\", () => {\n\t\tconst registry = createRegistry();\n\t\tregistry.registerProvider(\"cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.getProviderAuthMode(\"cli\"), \"externalCli\");\n\t});\n\n\tit(\"returns none when authMode is none\", () => {\n\t\tconst registry = createRegistry();\n\t\tregistry.registerProvider(\"local\", {\n\t\t\tauthMode: \"none\",\n\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.getProviderAuthMode(\"local\"), \"none\");\n\t});\n});\n\n// ─── isProviderRequestReady ───────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — isProviderRequestReady\", () => {\n\tit(\"returns true for externalCli without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.isProviderRequestReady(\"cli\"), true);\n\t});\n\n\tit(\"returns true for none without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"local\", {\n\t\t\tauthMode: \"none\",\n\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.isProviderRequestReady(\"local\"), true);\n\t});\n\n\tit(\"returns false for apiKey provider without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tassert.equal(registry.isProviderRequestReady(\"anthropic\"), false);\n\t});\n\n\tit(\"returns true for apiKey provider with stored auth\", () => {\n\t\tconst registry = createRegistry(() => true);\n\t\tassert.equal(registry.isProviderRequestReady(\"anthropic\"), true);\n\t});\n});\n\n// ─── isReady callback ─────────────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — isReady callback\", () => {\n\tit(\"calls isReady and returns its result for externalCli provider\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"cli-down\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tisReady: () => false,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.isProviderRequestReady(\"cli-down\"), false);\n\t});\n\n\tit(\"calls isReady for apiKey provider (overrides hasAuth)\", () => {\n\t\tconst registry = createRegistry(() => true);\n\t\tregistry.registerProvider(\"strict-provider\", {\n\t\t\tapiKey: \"MY_KEY\",\n\t\t\tbaseUrl: \"https://api.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tisReady: () => false,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.isProviderRequestReady(\"strict-provider\"), false);\n\t});\n\n\tit(\"isReady returning true makes provider available\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"healthy-cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tisReady: () => true,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.isProviderRequestReady(\"healthy-cli\"), true);\n\t});\n\n\tit(\"falls through to default behavior when isReady not provided\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"no-callback\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\t// externalCli without isReady → true (default)\n\t\tassert.equal(registry.isProviderRequestReady(\"no-callback\"), true);\n\t});\n});\n\n// ─── getAvailable ─────────────────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — getAvailable\", () => {\n\tit(\"includes externalCli models without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"cli-model\")],\n\t\t});\n\t\tassert.ok(findModel(registry, \"cli\", \"cli-model\"));\n\t});\n\n\tit(\"includes none models without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"local\", {\n\t\t\tauthMode: \"none\",\n\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"local-model\")],\n\t\t});\n\t\tassert.ok(findModel(registry, \"local\", \"local-model\"));\n\t});\n\n\tit(\"excludes externalCli models when isReady returns false\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"cli-down\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tisReady: () => false,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(findModel(registry, \"cli-down\", \"m\"), undefined);\n\t});\n\n\tit(\"excludes apiKey models without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tconst available = registry.getAvailable();\n\t\tassert.equal(available.length, 0);\n\t});\n});\n\n// ─── getApiKey ────────────────────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — getApiKey\", () => {\n\tit(\"returns undefined for externalCli provider\", async () => {\n\t\tconst registry = createRegistry();\n\t\tregistry.registerProvider(\"cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tconst model = registry.getAll().find((m) => m.provider === \"cli\")!;\n\t\tassert.equal(await registry.getApiKey(model), undefined);\n\t});\n\n\tit(\"returns undefined for none provider\", async () => {\n\t\tconst registry = createRegistry();\n\t\tregistry.registerProvider(\"local\", {\n\t\t\tauthMode: \"none\",\n\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tconst model = registry.getAll().find((m) => m.provider === \"local\")!;\n\t\tassert.equal(await registry.getApiKey(model), undefined);\n\t});\n\n\tit(\"delegates to authStorage for apiKey provider\", async () => {\n\t\tconst registry = createRegistry();\n\t\tconst key = await registry.getApiKeyForProvider(\"anthropic\");\n\t\tassert.equal(key, undefined);\n\t});\n});\n\n// ─── streamSimple apiKey stripping ────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — streamSimple apiKey boundary\", () => {\n\tit(\"strips apiKey from options for externalCli provider\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tconst apiType = `ext-cli-strip-${Date.now()}`;\n\n\t\tregistry.registerProvider(\"cli-strip\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: apiType as Api,\n\t\t\tstreamSimple: spy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"m\", apiType)],\n\t\t});\n\n\t\tconst provider = getApiProvider(apiType as Api);\n\t\tassert.ok(provider, \"provider must be registered in api registry\");\n\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"cli-strip\", \"m\", apiType),\n\t\t\tmakeContext(),\n\t\t\t{ apiKey: \"should-be-stripped\", maxTokens: 1024 } as SimpleStreamOptions,\n\t\t);\n\n\t\tconst captured = spy.getCapturedOptions();\n\t\tassert.ok(captured, \"streamSimple must have been called\");\n\t\tassert.equal(\"apiKey\" in captured, false, \"apiKey must not exist in options for externalCli provider\");\n\t\tassert.equal(captured.maxTokens, 1024, \"other options must pass through\");\n\t});\n\n\tit(\"strips apiKey from options for none provider\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tconst apiType = `none-strip-${Date.now()}`;\n\n\t\tregistry.registerProvider(\"none-strip\", {\n\t\t\tauthMode: \"none\",\n\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\tapi: apiType as Api,\n\t\t\tstreamSimple: spy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"m\", apiType)],\n\t\t});\n\n\t\tconst provider = getApiProvider(apiType as Api);\n\t\tassert.ok(provider, \"provider must be registered in api registry\");\n\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"none-strip\", \"m\", apiType),\n\t\t\tmakeContext(),\n\t\t\t{ apiKey: \"should-be-stripped\", maxTokens: 2048 } as SimpleStreamOptions,\n\t\t);\n\n\t\tconst captured = spy.getCapturedOptions();\n\t\tassert.ok(captured, \"streamSimple must have been called\");\n\t\tassert.equal(\"apiKey\" in captured, false, \"apiKey must not exist in options for none provider\");\n\t\tassert.equal(captured.maxTokens, 2048, \"other options must pass through\");\n\t});\n\n\tit(\"preserves apiKey in options for apiKey provider\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tconst apiType = `apikey-preserve-${Date.now()}`;\n\n\t\tregistry.registerProvider(\"apikey-preserve\", {\n\t\t\tapiKey: \"MY_KEY\",\n\t\t\tbaseUrl: \"https://api.local\",\n\t\t\tapi: apiType as Api,\n\t\t\tstreamSimple: spy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"m\", apiType)],\n\t\t});\n\n\t\tconst provider = getApiProvider(apiType as Api);\n\t\tassert.ok(provider, \"provider must be registered in api registry\");\n\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"apikey-preserve\", \"m\", apiType),\n\t\t\tmakeContext(),\n\t\t\t{ apiKey: \"sk-real-key\", maxTokens: 4096 } as SimpleStreamOptions,\n\t\t);\n\n\t\tconst captured = spy.getCapturedOptions();\n\t\tassert.ok(captured, \"streamSimple must have been called\");\n\t\tassert.equal(captured.apiKey, \"sk-real-key\", \"apiKey must be preserved for apiKey provider\");\n\t\tassert.equal(captured.maxTokens, 4096, \"other options must pass through\");\n\t});\n\n\tit(\"handles undefined options for externalCli provider\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tconst apiType = `ext-cli-undef-${Date.now()}`;\n\n\t\tregistry.registerProvider(\"cli-undef\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: apiType as Api,\n\t\t\tstreamSimple: spy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"m\", apiType)],\n\t\t});\n\n\t\tconst provider = getApiProvider(apiType as Api);\n\t\tassert.ok(provider, \"provider must be registered in api registry\");\n\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"cli-undef\", \"m\", apiType),\n\t\t\tmakeContext(),\n\t\t\tundefined,\n\t\t);\n\n\t\tconst captured = spy.getCapturedOptions();\n\t\tassert.ok(captured !== undefined, \"streamSimple must have been called\");\n\t\tassert.equal(\"apiKey\" in captured, false, \"apiKey must not exist even when options is undefined\");\n\t});\n\n\tit(\"strips apiKey but preserves signal and other fields for externalCli\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tconst apiType = `ext-cli-fields-${Date.now()}`;\n\t\tconst abortController = new AbortController();\n\n\t\tregistry.registerProvider(\"cli-fields\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: apiType as Api,\n\t\t\tstreamSimple: spy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"m\", apiType)],\n\t\t});\n\n\t\tconst provider = getApiProvider(apiType as Api);\n\t\tassert.ok(provider, \"provider must be registered in api registry\");\n\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"cli-fields\", \"m\", apiType),\n\t\t\tmakeContext(),\n\t\t\t{ apiKey: \"strip-me\", maxTokens: 8192, signal: abortController.signal, reasoning: \"high\" } as SimpleStreamOptions,\n\t\t);\n\n\t\tconst captured = spy.getCapturedOptions();\n\t\tassert.ok(captured, \"streamSimple must have been called\");\n\t\tassert.equal(\"apiKey\" in captured, false, \"apiKey must be stripped\");\n\t\tassert.equal(captured.maxTokens, 8192, \"maxTokens must pass through\");\n\t\tassert.equal(captured.signal, abortController.signal, \"signal must pass through\");\n\t\tassert.equal((captured as Record<string, unknown>).reasoning, \"high\", \"reasoning must pass through\");\n\t});\n});\n"]}
|
|
1
|
+
{"version":3,"file":"model-registry-auth-mode.test.js","sourceRoot":"","sources":["../../src/core/model-registry-auth-mode.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,SAAS,cAAc,CAAC,SAAyC;IAChE,MAAM,WAAW,GAAG;QACnB,mBAAmB,EAAE,GAAG,EAAE,GAAE,CAAC;QAC7B,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;QAC5B,iBAAiB,EAAE,GAAG,EAAE,CAAC,EAAE;QAC3B,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS;QACpB,OAAO,EAAE,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC;QACnC,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,SAAS;KACN,CAAC;IAE5B,OAAO,IAAI,aAAa,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,mBAAmB,CAAC,EAAU,EAAE,GAAY;IACpD,OAAO;QACN,EAAE;QACF,IAAI,EAAE,EAAE;QACR,GAAG,EAAE,CAAC,GAAG,IAAI,oBAAoB,CAAQ;QACzC,SAAS,EAAE,KAAK;QAChB,KAAK,EAAE,CAAC,MAAM,CAAC;QACf,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE;QAC1D,aAAa,EAAE,MAAM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AC,EAC7D,WAAW,EAAE,EACb,EAAE,SAAS,EAAE,IAAI,EAAyB,CAC1C,CAAC;QAEF,MAAM,QAAQ,GAAG,SAAS,CAAC,kBAAkB,EAAE,CAAC;QAChD,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,kEAAkE,CAAC,CAAC;QACxF,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { describe, it } from \"node:test\";\nimport type { Api, Model, SimpleStreamOptions, Context, AssistantMessageEventStream } from \"@gsd/pi-ai\";\nimport { getApiProvider } from \"@gsd/pi-ai\";\nimport type { AuthStorage } from \"./auth-storage.js\";\nimport { ModelRegistry } from \"./model-registry.js\";\n\nfunction createRegistry(hasAuthFn?: (provider: string) => boolean): ModelRegistry {\n\tconst authStorage = {\n\t\tsetFallbackResolver: () => {},\n\t\tonCredentialChange: () => {},\n\t\tgetOAuthProviders: () => [],\n\t\tget: () => undefined,\n\t\thasAuth: hasAuthFn ?? (() => false),\n\t\tgetApiKey: async () => undefined,\n\t} as unknown as AuthStorage;\n\n\treturn new ModelRegistry(authStorage, undefined);\n}\n\nfunction createProviderModel(id: string, api?: string): NonNullable<Parameters<ModelRegistry[\"registerProvider\"]>[1][\"models\"]>[number] {\n\treturn {\n\t\tid,\n\t\tname: id,\n\t\tapi: (api ?? \"openai-completions\") as Api,\n\t\treasoning: false,\n\t\tinput: [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: 128000,\n\t\tmaxTokens: 16384,\n\t};\n}\n\nfunction findModel(registry: ModelRegistry, provider: string, id: string): Model<Api> | undefined {\n\treturn registry.getAvailable().find((m) => m.provider === provider && m.id === id);\n}\n\nfunction makeModel(provider: string, id: string, api: string): Model<Api> {\n\treturn {\n\t\tid,\n\t\tname: id,\n\t\tapi: api as Api,\n\t\tprovider,\n\t\tbaseUrl: `${provider}:`,\n\t\treasoning: false,\n\t\tinput: [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: 128000,\n\t\tmaxTokens: 16384,\n\t};\n}\n\nfunction makeContext(): Context {\n\treturn {\n\t\tsystemPrompt: \"test\",\n\t\tmessages: [{ role: \"user\", content: \"hello\", timestamp: Date.now() }],\n\t};\n}\n\n/** No-op streamSimple for tests that need one to pass validation but don't inspect it. */\nconst noopStreamSimple = (_model: Model<Api>, _context: Context, _options?: SimpleStreamOptions) => {\n\treturn {\n\t\t[Symbol.asyncIterator]() { return { next: async () => ({ value: undefined, done: true as const }) }; },\n\t\tresult: () => Promise.resolve({ role: \"assistant\" as const, content: [], api: \"test\" as Api, provider: \"test\", model: \"test\", usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } }, stopReason: \"stop\" as const, timestamp: Date.now() }),\n\t\tpush: () => {},\n\t\tend: () => {},\n\t} as unknown as AssistantMessageEventStream;\n};\n\n/** Create a spy streamSimple that captures the options it receives and returns a stub stream. */\nfunction createStreamSpy(): {\n\tstreamSimple: (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream;\n\tgetCapturedOptions: () => SimpleStreamOptions | undefined;\n} {\n\tlet capturedOptions: SimpleStreamOptions | undefined;\n\tconst streamSimple = (_model: Model<Api>, _context: Context, options?: SimpleStreamOptions) => {\n\t\tcapturedOptions = options;\n\t\t// Return a minimal stub that satisfies AssistantMessageEventStream\n\t\treturn {\n\t\t\t[Symbol.asyncIterator]() { return { next: async () => ({ value: undefined, done: true as const }) }; },\n\t\t\tresult: () => Promise.resolve({ role: \"assistant\" as const, content: [], api: \"test\" as Api, provider: \"test\", model: \"test\", usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } }, stopReason: \"stop\" as const, timestamp: Date.now() }),\n\t\t\tpush: () => {},\n\t\t\tend: () => {},\n\t\t} as unknown as AssistantMessageEventStream;\n\t};\n\treturn { streamSimple, getCapturedOptions: () => capturedOptions };\n}\n\n// ─── Registration ─────────────────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — registration\", () => {\n\tit(\"registers externalCli provider with streamSimple and without apiKey/oauth\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tassert.doesNotThrow(() => {\n\t\t\tregistry.registerProvider(\"cli-provider\", {\n\t\t\t\tauthMode: \"externalCli\",\n\t\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tstreamSimple: spy.streamSimple,\n\t\t\t\tmodels: [createProviderModel(\"cli-model\")],\n\t\t\t});\n\t\t});\n\t});\n\n\tit(\"registers none provider with streamSimple and without apiKey/oauth\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tassert.doesNotThrow(() => {\n\t\t\tregistry.registerProvider(\"none-provider\", {\n\t\t\t\tauthMode: \"none\",\n\t\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tstreamSimple: spy.streamSimple,\n\t\t\t\tmodels: [createProviderModel(\"local-model\")],\n\t\t\t});\n\t\t});\n\t});\n\n\tit(\"rejects apiKey provider without apiKey or oauth — message mentions authMode\", () => {\n\t\tconst registry = createRegistry();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"apikey-provider\", {\n\t\t\t\tauthMode: \"apiKey\",\n\t\t\t\tbaseUrl: \"https://api.local\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"authMode\"), \"error message must mention authMode\");\n\t\t\tassert.ok(err.message.includes(\"externalCli\"), \"error message must suggest externalCli\");\n\t\t\treturn true;\n\t\t});\n\t});\n\n\tit(\"rejects provider with no authMode and no apiKey/oauth (defaults to apiKey)\", () => {\n\t\tconst registry = createRegistry();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"bare-provider\", {\n\t\t\t\tbaseUrl: \"https://api.local\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"authMode\"), \"error message must mention authMode\");\n\t\t\treturn true;\n\t\t});\n\t});\n\n\tit(\"rejects externalCli provider without streamSimple\", () => {\n\t\tconst registry = createRegistry();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"cli-no-stream\", {\n\t\t\t\tauthMode: \"externalCli\",\n\t\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"streamSimple\"), \"error message must mention streamSimple\");\n\t\t\tassert.ok(err.message.includes(\"externalCli\"), \"error message must mention authMode\");\n\t\t\treturn true;\n\t\t});\n\t});\n\n\tit(\"rejects none provider without streamSimple\", () => {\n\t\tconst registry = createRegistry();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"none-no-stream\", {\n\t\t\t\tauthMode: \"none\",\n\t\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"streamSimple\"), \"error message must mention streamSimple\");\n\t\t\tassert.ok(err.message.includes(\"none\"), \"error message must mention authMode\");\n\t\t\treturn true;\n\t\t});\n\t});\n\n\tit(\"rejects externalCli provider that also sets apiKey\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"cli-with-key\", {\n\t\t\t\tauthMode: \"externalCli\",\n\t\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tapiKey: \"SHOULD_NOT_EXIST\",\n\t\t\t\tstreamSimple: spy.streamSimple,\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"apiKey\"), \"error message must mention apiKey\");\n\t\t\tassert.ok(err.message.includes(\"externalCli\"), \"error message must mention authMode\");\n\t\t\treturn true;\n\t\t});\n\t});\n\n\tit(\"rejects none provider that also sets apiKey\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tassert.throws(() => {\n\t\t\tregistry.registerProvider(\"none-with-key\", {\n\t\t\t\tauthMode: \"none\",\n\t\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\t\tapi: \"openai-completions\",\n\t\t\t\tapiKey: \"SHOULD_NOT_EXIST\",\n\t\t\t\tstreamSimple: spy.streamSimple,\n\t\t\t\tmodels: [createProviderModel(\"model\")],\n\t\t\t});\n\t\t}, (err: Error) => {\n\t\t\tassert.ok(err.message.includes(\"apiKey\"), \"error message must mention apiKey\");\n\t\t\tassert.ok(err.message.includes(\"none\"), \"error message must mention authMode\");\n\t\t\treturn true;\n\t\t});\n\t});\n});\n\n// ─── getProviderAuthMode ──────────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — getProviderAuthMode\", () => {\n\tit(\"returns apiKey for unregistered (built-in) providers\", () => {\n\t\tconst registry = createRegistry();\n\t\tassert.equal(registry.getProviderAuthMode(\"anthropic\"), \"apiKey\");\n\t});\n\n\tit(\"returns explicit authMode when set\", () => {\n\t\tconst registry = createRegistry();\n\t\tregistry.registerProvider(\"cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.getProviderAuthMode(\"cli\"), \"externalCli\");\n\t});\n\n\tit(\"returns none when authMode is none\", () => {\n\t\tconst registry = createRegistry();\n\t\tregistry.registerProvider(\"local\", {\n\t\t\tauthMode: \"none\",\n\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.getProviderAuthMode(\"local\"), \"none\");\n\t});\n});\n\n// ─── isProviderRequestReady ───────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — isProviderRequestReady\", () => {\n\tit(\"returns true for externalCli without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.isProviderRequestReady(\"cli\"), true);\n\t});\n\n\tit(\"returns true for none without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"local\", {\n\t\t\tauthMode: \"none\",\n\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.isProviderRequestReady(\"local\"), true);\n\t});\n\n\tit(\"returns false for apiKey provider without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tassert.equal(registry.isProviderRequestReady(\"anthropic\"), false);\n\t});\n\n\tit(\"returns true for apiKey provider with stored auth\", () => {\n\t\tconst registry = createRegistry(() => true);\n\t\tassert.equal(registry.isProviderRequestReady(\"anthropic\"), true);\n\t});\n});\n\n// ─── isReady callback ─────────────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — isReady callback\", () => {\n\tit(\"calls isReady and returns its result for externalCli provider\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"cli-down\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tisReady: () => false,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.isProviderRequestReady(\"cli-down\"), false);\n\t});\n\n\tit(\"calls isReady for apiKey provider (overrides hasAuth)\", () => {\n\t\tconst registry = createRegistry(() => true);\n\t\tregistry.registerProvider(\"strict-provider\", {\n\t\t\tapiKey: \"MY_KEY\",\n\t\t\tbaseUrl: \"https://api.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tisReady: () => false,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.isProviderRequestReady(\"strict-provider\"), false);\n\t});\n\n\tit(\"isReady returning true makes provider available\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"healthy-cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tisReady: () => true,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(registry.isProviderRequestReady(\"healthy-cli\"), true);\n\t});\n\n\tit(\"falls through to default behavior when isReady not provided\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"no-callback\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\t// externalCli without isReady → true (default)\n\t\tassert.equal(registry.isProviderRequestReady(\"no-callback\"), true);\n\t});\n});\n\n// ─── getAvailable ─────────────────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — getAvailable\", () => {\n\tit(\"includes externalCli models without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"cli-model\")],\n\t\t});\n\t\tassert.ok(findModel(registry, \"cli\", \"cli-model\"));\n\t});\n\n\tit(\"includes none models without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"local\", {\n\t\t\tauthMode: \"none\",\n\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"local-model\")],\n\t\t});\n\t\tassert.ok(findModel(registry, \"local\", \"local-model\"));\n\t});\n\n\tit(\"excludes externalCli models when isReady returns false\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tregistry.registerProvider(\"cli-down\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tisReady: () => false,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tassert.equal(findModel(registry, \"cli-down\", \"m\"), undefined);\n\t});\n\n\tit(\"excludes apiKey models without stored auth\", () => {\n\t\tconst registry = createRegistry(() => false);\n\t\tconst available = registry.getAvailable();\n\t\tassert.equal(available.length, 0);\n\t});\n});\n\n// ─── getApiKey ────────────────────────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — getApiKey\", () => {\n\tit(\"returns undefined for externalCli provider\", async () => {\n\t\tconst registry = createRegistry();\n\t\tregistry.registerProvider(\"cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tconst model = registry.getAll().find((m) => m.provider === \"cli\")!;\n\t\tassert.equal(await registry.getApiKey(model), undefined);\n\t});\n\n\tit(\"returns undefined for none provider\", async () => {\n\t\tconst registry = createRegistry();\n\t\tregistry.registerProvider(\"local\", {\n\t\t\tauthMode: \"none\",\n\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\tapi: \"openai-completions\",\n\t\t\tstreamSimple: noopStreamSimple,\n\t\t\tmodels: [createProviderModel(\"m\")],\n\t\t});\n\t\tconst model = registry.getAll().find((m) => m.provider === \"local\")!;\n\t\tassert.equal(await registry.getApiKey(model), undefined);\n\t});\n\n\tit(\"delegates to authStorage for apiKey provider\", async () => {\n\t\tconst registry = createRegistry();\n\t\tconst key = await registry.getApiKeyForProvider(\"anthropic\");\n\t\tassert.equal(key, undefined);\n\t});\n});\n\n// ─── streamSimple apiKey stripping ────────────────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — streamSimple apiKey boundary\", () => {\n\tit(\"strips apiKey from options for externalCli provider\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tconst apiType = `ext-cli-strip-${Date.now()}`;\n\n\t\tregistry.registerProvider(\"cli-strip\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: apiType as Api,\n\t\t\tstreamSimple: spy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"m\", apiType)],\n\t\t});\n\n\t\tconst provider = getApiProvider(apiType as Api);\n\t\tassert.ok(provider, \"provider must be registered in api registry\");\n\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"cli-strip\", \"m\", apiType),\n\t\t\tmakeContext(),\n\t\t\t{ apiKey: \"should-be-stripped\", maxTokens: 1024 } as SimpleStreamOptions,\n\t\t);\n\n\t\tconst captured = spy.getCapturedOptions();\n\t\tassert.ok(captured, \"streamSimple must have been called\");\n\t\tassert.equal(\"apiKey\" in captured, false, \"apiKey must not exist in options for externalCli provider\");\n\t\tassert.equal(captured.maxTokens, 1024, \"other options must pass through\");\n\t});\n\n\tit(\"strips apiKey from options for none provider\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tconst apiType = `none-strip-${Date.now()}`;\n\n\t\tregistry.registerProvider(\"none-strip\", {\n\t\t\tauthMode: \"none\",\n\t\t\tbaseUrl: \"http://localhost:11434\",\n\t\t\tapi: apiType as Api,\n\t\t\tstreamSimple: spy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"m\", apiType)],\n\t\t});\n\n\t\tconst provider = getApiProvider(apiType as Api);\n\t\tassert.ok(provider, \"provider must be registered in api registry\");\n\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"none-strip\", \"m\", apiType),\n\t\t\tmakeContext(),\n\t\t\t{ apiKey: \"should-be-stripped\", maxTokens: 2048 } as SimpleStreamOptions,\n\t\t);\n\n\t\tconst captured = spy.getCapturedOptions();\n\t\tassert.ok(captured, \"streamSimple must have been called\");\n\t\tassert.equal(\"apiKey\" in captured, false, \"apiKey must not exist in options for none provider\");\n\t\tassert.equal(captured.maxTokens, 2048, \"other options must pass through\");\n\t});\n\n\tit(\"preserves apiKey in options for apiKey provider\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tconst apiType = `apikey-preserve-${Date.now()}`;\n\n\t\tregistry.registerProvider(\"apikey-preserve\", {\n\t\t\tapiKey: \"MY_KEY\",\n\t\t\tbaseUrl: \"https://api.local\",\n\t\t\tapi: apiType as Api,\n\t\t\tstreamSimple: spy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"m\", apiType)],\n\t\t});\n\n\t\tconst provider = getApiProvider(apiType as Api);\n\t\tassert.ok(provider, \"provider must be registered in api registry\");\n\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"apikey-preserve\", \"m\", apiType),\n\t\t\tmakeContext(),\n\t\t\t{ apiKey: \"sk-real-key\", maxTokens: 4096 } as SimpleStreamOptions,\n\t\t);\n\n\t\tconst captured = spy.getCapturedOptions();\n\t\tassert.ok(captured, \"streamSimple must have been called\");\n\t\tassert.equal(captured.apiKey, \"sk-real-key\", \"apiKey must be preserved for apiKey provider\");\n\t\tassert.equal(captured.maxTokens, 4096, \"other options must pass through\");\n\t});\n\n\tit(\"handles undefined options for externalCli provider\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tconst apiType = `ext-cli-undef-${Date.now()}`;\n\n\t\tregistry.registerProvider(\"cli-undef\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: apiType as Api,\n\t\t\tstreamSimple: spy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"m\", apiType)],\n\t\t});\n\n\t\tconst provider = getApiProvider(apiType as Api);\n\t\tassert.ok(provider, \"provider must be registered in api registry\");\n\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"cli-undef\", \"m\", apiType),\n\t\t\tmakeContext(),\n\t\t\tundefined,\n\t\t);\n\n\t\tconst captured = spy.getCapturedOptions();\n\t\tassert.ok(captured !== undefined, \"streamSimple must have been called\");\n\t\tassert.equal(\"apiKey\" in captured, false, \"apiKey must not exist even when options is undefined\");\n\t});\n\n\tit(\"strips apiKey but preserves signal and other fields for externalCli\", () => {\n\t\tconst registry = createRegistry();\n\t\tconst spy = createStreamSpy();\n\t\tconst apiType = `ext-cli-fields-${Date.now()}`;\n\t\tconst abortController = new AbortController();\n\n\t\tregistry.registerProvider(\"cli-fields\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"https://cli.local\",\n\t\t\tapi: apiType as Api,\n\t\t\tstreamSimple: spy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"m\", apiType)],\n\t\t});\n\n\t\tconst provider = getApiProvider(apiType as Api);\n\t\tassert.ok(provider, \"provider must be registered in api registry\");\n\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"cli-fields\", \"m\", apiType),\n\t\t\tmakeContext(),\n\t\t\t{ apiKey: \"strip-me\", maxTokens: 8192, signal: abortController.signal, reasoning: \"high\" } as SimpleStreamOptions,\n\t\t);\n\n\t\tconst captured = spy.getCapturedOptions();\n\t\tassert.ok(captured, \"streamSimple must have been called\");\n\t\tassert.equal(\"apiKey\" in captured, false, \"apiKey must be stripped\");\n\t\tassert.equal(captured.maxTokens, 8192, \"maxTokens must pass through\");\n\t\tassert.equal(captured.signal, abortController.signal, \"signal must pass through\");\n\t\tassert.equal((captured as Record<string, unknown>).reasoning, \"high\", \"reasoning must pass through\");\n\t});\n});\n\n// ─── Provider-scoped stream routing (#2533) ───────────────────────────────────\n\ndescribe(\"ModelRegistry authMode — provider-scoped stream routing\", () => {\n\tit(\"does not clobber built-in stream handler when custom provider uses same api\", () => {\n\t\tconst registry = createRegistry(() => true);\n\t\tconst customSpy = createStreamSpy();\n\n\t\t// Register a custom provider with the same API type as a built-in (anthropic-messages).\n\t\t// This simulates the claude-code-cli extension registering with api: \"anthropic-messages\".\n\t\tregistry.registerProvider(\"custom-cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"local://custom\",\n\t\t\tapi: \"anthropic-messages\",\n\t\t\tstreamSimple: customSpy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"custom-model\", \"anthropic-messages\")],\n\t\t});\n\n\t\t// The built-in anthropic-messages provider should still be accessible\n\t\t// when calling streamSimple with a model from the built-in provider.\n\t\tconst provider = getApiProvider(\"anthropic-messages\" as Api);\n\t\tassert.ok(provider, \"anthropic-messages provider must still be registered\");\n\n\t\t// Call with a built-in anthropic model — should NOT hit the custom spy.\n\t\t// The built-in handler will throw (no API key), which proves the routing\n\t\t// correctly delegates to the built-in instead of the custom handler.\n\t\tassert.throws(\n\t\t\t() => provider.streamSimple(\n\t\t\t\tmakeModel(\"anthropic\", \"claude-sonnet-4-6\", \"anthropic-messages\"),\n\t\t\t\tmakeContext(),\n\t\t\t\t{ maxTokens: 4096 } as SimpleStreamOptions,\n\t\t\t),\n\t\t\t(err: Error) => err.message.includes(\"API key\"),\n\t\t\t\"built-in Anthropic handler must be invoked (throws because no API key in tests)\",\n\t\t);\n\n\t\tassert.equal(\n\t\t\tcustomSpy.getCapturedOptions(),\n\t\t\tundefined,\n\t\t\t\"custom provider's streamSimple must NOT be called for anthropic provider models\",\n\t\t);\n\t});\n\n\tit(\"routes to custom provider when model.provider matches\", () => {\n\t\tconst registry = createRegistry(() => true);\n\t\tconst customSpy = createStreamSpy();\n\n\t\tregistry.registerProvider(\"custom-cli\", {\n\t\t\tauthMode: \"externalCli\",\n\t\t\tbaseUrl: \"local://custom\",\n\t\t\tapi: \"anthropic-messages\",\n\t\t\tstreamSimple: customSpy.streamSimple,\n\t\t\tmodels: [createProviderModel(\"custom-model\", \"anthropic-messages\")],\n\t\t});\n\n\t\tconst provider = getApiProvider(\"anthropic-messages\" as Api);\n\t\tassert.ok(provider);\n\n\t\t// Call with the custom provider's model — should hit the custom spy\n\t\tprovider.streamSimple(\n\t\t\tmakeModel(\"custom-cli\", \"custom-model\", \"anthropic-messages\"),\n\t\t\tmakeContext(),\n\t\t\t{ maxTokens: 2048 } as SimpleStreamOptions,\n\t\t);\n\n\t\tconst captured = customSpy.getCapturedOptions();\n\t\tassert.ok(captured, \"custom provider's streamSimple must be called for its own models\");\n\t\tassert.equal(captured.maxTokens, 2048);\n\t});\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-registry.d.ts","sourceRoot":"","sources":["../../src/core/model-registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAE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,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;KAC9B,CAAC,CAAC;CACH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Model registry - manages built-in and custom models, provides API key resolution.
|
|
3
3
|
*/
|
|
4
|
-
import { getModels, getProviders, registerApiProvider, resetApiProviders, } from "@gsd/pi-ai";
|
|
4
|
+
import { getApiProvider, getModels, getProviders, registerApiProvider, resetApiProviders, } from "@gsd/pi-ai";
|
|
5
5
|
import { registerOAuthProvider, resetOAuthProviders } from "@gsd/pi-ai/oauth";
|
|
6
6
|
import { Type } from "@sinclair/typebox";
|
|
7
7
|
import AjvModule from "ajv";
|
|
@@ -511,10 +511,33 @@ export class ModelRegistry {
|
|
|
511
511
|
return rawStreamSimple(model, context, opts);
|
|
512
512
|
})
|
|
513
513
|
: rawStreamSimple;
|
|
514
|
+
// Guard: if there's already a handler registered for this API, wrap
|
|
515
|
+
// the new one so it only fires for models from this provider and
|
|
516
|
+
// delegates to the previous handler for all other providers. Without
|
|
517
|
+
// this, a custom provider using api:"anthropic-messages" would clobber
|
|
518
|
+
// the built-in Anthropic stream handler (#2536).
|
|
519
|
+
const existingProvider = getApiProvider(config.api);
|
|
520
|
+
const scopedStream = existingProvider
|
|
521
|
+
? (model, context, options) => {
|
|
522
|
+
if (model.provider === providerName) {
|
|
523
|
+
return streamSimple(model, context, options);
|
|
524
|
+
}
|
|
525
|
+
return existingProvider.streamSimple(model, context, options);
|
|
526
|
+
}
|
|
527
|
+
: streamSimple;
|
|
528
|
+
const newFullStream = (model, context, options) => scopedStream(model, context, options);
|
|
529
|
+
const scopedFullStream = existingProvider
|
|
530
|
+
? (model, context, options) => {
|
|
531
|
+
if (model.provider === providerName) {
|
|
532
|
+
return newFullStream(model, context, options);
|
|
533
|
+
}
|
|
534
|
+
return existingProvider.stream(model, context, options);
|
|
535
|
+
}
|
|
536
|
+
: newFullStream;
|
|
514
537
|
registerApiProvider({
|
|
515
538
|
api: config.api,
|
|
516
|
-
stream:
|
|
517
|
-
streamSimple,
|
|
539
|
+
stream: scopedFullStream,
|
|
540
|
+
streamSimple: scopedStream,
|
|
518
541
|
}, `provider:${providerName}`);
|
|
519
542
|
}
|
|
520
543
|
// Store API key for auth resolution
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-registry.js","sourceRoot":"","sources":["../../src/core/model-registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAIN,SAAS,EACT,YAAY,EAMZ,mBAAmB,EACnB,iBAAiB,GAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,SAAS,MAAM,KAAK,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAiB,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAyB,kBAAkB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACtG,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,MAAM,GAAG,GAAI,SAAiB,CAAC,OAAO,IAAI,SAAS,CAAC;AACpD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AAEtB,4CAA4C;AAC5C,MAAM,uBAAuB,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAA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,IAAI,MAAM;oBACzC,SAAS,EAAE,EAAE,CAAC,SAAS,IAAI,KAAK;iBAClB,CAAC,CAAC;YAClB,CAAC;QACF,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,KAAiB;QACpC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,eAAe;QACd,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACtC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;CACD","sourcesContent":["/**\n * Model registry - manages built-in and custom models, provides API key resolution.\n */\n\nimport {\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 \"@gsd/pi-ai\";\nimport { registerOAuthProvider, resetOAuthProviders } from \"@gsd/pi-ai/oauth\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport AjvModule from \"ajv\";\nimport { existsSync, readFileSync } from \"fs\";\nimport { join } from \"path\";\nimport { getAgentDir } from \"../config.js\";\nimport type { AuthStorage } from \"./auth-storage.js\";\nimport { ModelDiscoveryCache } from \"./discovery-cache.js\";\nimport type { DiscoveredModel, DiscoveryResult } from \"./model-discovery.js\";\nimport { getDefaultTTL, getDiscoverableProviders, getDiscoveryAdapter } from \"./model-discovery.js\";\nimport { clearConfigValueCache, resolveConfigValue, resolveHeaders } from \"./resolve-config-value.js\";\nimport { isLocalModel } from \"./local-model-check.js\";\n\nconst Ajv = (AjvModule as any).default || AjvModule;\nconst ajv = new Ajv();\n\n// Schema for OpenRouter routing preferences\nconst OpenRouterRoutingSchema = Type.Object({\n\tonly: Type.Optional(Type.Array(Type.String())),\n\torder: Type.Optional(Type.Array(Type.String())),\n});\n\n// Schema for Vercel AI Gateway routing preferences\nconst VercelGatewayRoutingSchema = Type.Object({\n\tonly: Type.Optional(Type.Array(Type.String())),\n\torder: Type.Optional(Type.Array(Type.String())),\n});\n\n// Schema for OpenAI compatibility settings\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\trequiresMistralToolIds: Type.Optional(Type.Boolean()),\n\tthinkingFormat: Type.Optional(Type.Union([Type.Literal(\"openai\"), Type.Literal(\"zai\"), Type.Literal(\"qwen\")])),\n\topenRouterRouting: Type.Optional(OpenRouterRoutingSchema),\n\tvercelGatewayRouting: Type.Optional(VercelGatewayRoutingSchema),\n});\n\nconst OpenAIResponsesCompatSchema = Type.Object({\n\t// Reserved for future use\n});\n\nconst OpenAICompatSchema = Type.Union([OpenAICompletionsCompatSchema, OpenAIResponsesCompatSchema]);\n\n// Schema for custom model definition\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\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(OpenAICompatSchema),\n});\n\n// Schema for per-model overrides (all fields optional, merged with built-in model)\nconst ModelOverrideSchema = Type.Object({\n\tname: Type.Optional(Type.String({ minLength: 1 })),\n\treasoning: Type.Optional(Type.Boolean()),\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(OpenAICompatSchema),\n});\n\ntype ModelOverride = Static<typeof ModelOverrideSchema>;\n\nconst ProviderConfigSchema = Type.Object({\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\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\najv.addSchema(ModelsConfigSchema, \"ModelsConfig\");\n\ntype ModelsConfig = Static<typeof ModelsConfigSchema>;\n\nexport type ProviderAuthMode = \"apiKey\" | \"oauth\" | \"externalCli\" | \"none\";\n\n/** Provider override config (baseUrl, headers, apiKey) without custom models */\ninterface ProviderOverride {\n\tbaseUrl?: string;\n\theaders?: Record<string, string>;\n\tapiKey?: 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 | undefined;\n\tconst override = overrideCompat as OpenAICompletionsCompat | OpenAIResponsesCompat;\n\tconst merged = { ...base, ...override } as OpenAICompletionsCompat | OpenAIResponsesCompat;\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\t// Simple field overrides\n\tif (override.name !== undefined) result.name = override.name;\n\tif (override.reasoning !== undefined) result.reasoning = override.reasoning;\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\t// Merge cost (partial override)\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\t// Merge headers\n\tif (override.headers) {\n\t\tconst resolvedHeaders = resolveHeaders(override.headers);\n\t\tresult.headers = resolvedHeaders ? { ...model.headers, ...resolvedHeaders } : model.headers;\n\t}\n\n\t// Deep merge compat\n\tresult.compat = mergeCompat(model.compat, override.compat);\n\n\treturn result;\n}\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 discoveredModels: Model<Api>[] = [];\n\tprivate discoveryCache: ModelDiscoveryCache;\n\tprivate customProviderApiKeys: Map<string, string> = new Map();\n\tprivate registeredProviders: Map<string, ProviderConfigInput> = new Map();\n\tprivate loadError: string | undefined = undefined;\n\n\tconstructor(\n\t\treadonly authStorage: AuthStorage,\n\t\tprivate modelsJsonPath: string | undefined = join(getAgentDir(), \"models.json\"),\n\t) {\n\t\tthis.discoveryCache = new ModelDiscoveryCache();\n\n\t\t// Set up fallback resolver for custom provider API keys\n\t\tthis.authStorage.setFallbackResolver((provider) => {\n\t\t\tconst keyConfig = this.customProviderApiKeys.get(provider);\n\t\t\tif (keyConfig) {\n\t\t\t\treturn resolveConfigValue(keyConfig);\n\t\t\t}\n\t\t\treturn undefined;\n\t\t});\n\n\t\t// Refresh models when credentials change (e.g., OAuth token refresh with new model limits)\n\t\tthis.authStorage.onCredentialChange(() => this.refresh());\n\n\t\t// Load models\n\t\tthis.loadModels();\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.customProviderApiKeys.clear();\n\t\tthis.loadError = undefined;\n\n\t\t// Ensure dynamic API/OAuth registrations are rebuilt from current provider state.\n\t\tresetApiProviders();\n\t\tresetOAuthProviders();\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\t// Load custom models and overrides from models.json\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\t// Keep built-in models even if custom models failed to load\n\t\t}\n\n\t\tconst builtInModels = this.loadBuiltInModels(overrides, modelOverrides);\n\t\tlet combined = this.mergeCustomModels(builtInModels, customModels);\n\n\t\t// Let OAuth providers modify their models (e.g., update baseUrl)\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\t// Apply provider-level baseUrl/headers override\n\t\t\t\tif (providerOverride) {\n\t\t\t\t\tconst resolvedHeaders = resolveHeaders(providerOverride.headers);\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\theaders: resolvedHeaders ? { ...model.headers, ...resolvedHeaders } : model.headers,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// Apply per-model override\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 config: ModelsConfig = JSON.parse(content);\n\n\t\t\t// Validate schema\n\t\t\tconst validate = ajv.getSchema(\"ModelsConfig\")!;\n\t\t\tif (!validate(config)) {\n\t\t\t\tconst errors =\n\t\t\t\t\tvalidate.errors?.map((e: any) => ` - ${e.instancePath || \"root\"}: ${e.message}`).join(\"\\n\") ||\n\t\t\t\t\t\"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\t// Additional validation\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\t// Apply provider-level baseUrl/headers/apiKey override to built-in models when configured.\n\t\t\t\tif (providerConfig.baseUrl || providerConfig.headers || providerConfig.apiKey) {\n\t\t\t\t\toverrides.set(providerName, {\n\t\t\t\t\t\tbaseUrl: providerConfig.baseUrl,\n\t\t\t\t\t\theaders: providerConfig.headers,\n\t\t\t\t\t\tapiKey: providerConfig.apiKey,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Store API key for fallback resolver.\n\t\t\t\tif (providerConfig.apiKey) {\n\t\t\t\t\tthis.customProviderApiKeys.set(providerName, providerConfig.apiKey);\n\t\t\t\t}\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}\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\tfor (const [providerName, providerConfig] of Object.entries(config.providers)) {\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\t// Override-only config: needs baseUrl OR modelOverrides (or both)\n\t\t\t\tif (!providerConfig.baseUrl && !hasModelOverrides) {\n\t\t\t\t\tthrow new Error(`Provider ${providerName}: must specify \"baseUrl\", \"modelOverrides\", or \"models\".`);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Custom models are merged into provider models and require endpoint + auth.\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\n\t\t\tfor (const modelDef of models) {\n\t\t\t\tconst hasModelApi = !!modelDef.api;\n\n\t\t\t\tif (!hasProviderApi && !hasModelApi) {\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\t// Validate contextWindow/maxTokens only if provided (they have defaults)\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\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\t// Store API key config for fallback resolver\n\t\t\tif (providerConfig.apiKey) {\n\t\t\t\tthis.customProviderApiKeys.set(providerName, providerConfig.apiKey);\n\t\t\t}\n\n\t\t\tfor (const modelDef of modelDefs) {\n\t\t\t\tconst api = modelDef.api || providerConfig.api;\n\t\t\t\tif (!api) continue;\n\n\t\t\t\t// Merge headers: provider headers are base, model headers override\n\t\t\t\t// Resolve env vars and shell commands in header values\n\t\t\t\tconst providerHeaders = resolveHeaders(providerConfig.headers);\n\t\t\t\tconst modelHeaders = resolveHeaders(modelDef.headers);\n\t\t\t\tlet headers = providerHeaders || modelHeaders ? { ...providerHeaders, ...modelHeaders } : undefined;\n\n\t\t\t\t// If authHeader is true, add Authorization header with resolved API key\n\t\t\t\tif (providerConfig.authHeader && providerConfig.apiKey) {\n\t\t\t\t\tconst resolvedKey = resolveConfigValue(providerConfig.apiKey);\n\t\t\t\t\tif (resolvedKey) {\n\t\t\t\t\t\theaders = { ...headers, Authorization: `Bearer ${resolvedKey}` };\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Provider baseUrl is required when custom models are defined.\n\t\t\t\t// Individual models can override it with modelDef.baseUrl.\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: modelDef.baseUrl ?? providerConfig.baseUrl!,\n\t\t\t\t\treasoning: modelDef.reasoning ?? false,\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,\n\t\t\t\t\tcompat: modelDef.compat,\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((m) => this.isProviderRequestReady(m.provider));\n\t}\n\n\t/**\n\t * Get auth mode for a provider.\n\t * Defaults to \"apiKey\" for built-ins and providers without explicit mode.\n\t */\n\tgetProviderAuthMode(provider: string): ProviderAuthMode {\n\t\tconst config = this.registeredProviders.get(provider);\n\t\tif (!config) return \"apiKey\";\n\t\tif (config.authMode) return config.authMode;\n\t\tif (config.oauth) return \"oauth\";\n\t\tif (config.apiKey) return \"apiKey\";\n\t\treturn \"apiKey\";\n\t}\n\n\t/**\n\t * Whether a provider can be used for requests/fallback without hard auth gating.\n\t */\n\tisProviderRequestReady(provider: string): boolean {\n\t\tconst config = this.registeredProviders.get(provider);\n\t\tif (config?.isReady) return config.isReady();\n\t\tconst authMode = this.getProviderAuthMode(provider);\n\t\tif (authMode === \"externalCli\" || authMode === \"none\") return true;\n\t\treturn this.authStorage.hasAuth(provider);\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 * Returns undefined for externalCli/none providers (no key needed).\n\t * @param sessionId - Optional session ID for sticky credential selection\n\t */\n\tasync getApiKey(model: Model<Api>, sessionId?: string): Promise<string | undefined> {\n\t\tconst authMode = this.getProviderAuthMode(model.provider);\n\t\tif (authMode === \"externalCli\" || authMode === \"none\") return undefined;\n\t\treturn this.authStorage.getApiKey(model.provider, sessionId, { baseUrl: model.baseUrl });\n\t}\n\n\t/**\n\t * Get API key for a provider.\n\t * Returns undefined for externalCli/none providers (no key needed).\n\t * @param sessionId - Optional session ID for sticky credential selection\n\t */\n\tasync getApiKeyForProvider(provider: string, sessionId?: string): Promise<string | undefined> {\n\t\tconst authMode = this.getProviderAuthMode(provider);\n\t\tif (authMode === \"externalCli\" || authMode === \"none\") return undefined;\n\t\treturn this.authStorage.getApiKey(provider, sessionId);\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.registeredProviders.set(providerName, config);\n\t\tthis.applyProviderConfig(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.customProviderApiKeys.delete(providerName);\n\t\tthis.refresh();\n\t}\n\n\tprivate applyProviderConfig(providerName: string, config: ProviderConfigInput): void {\n\t\t// Register OAuth provider if provided\n\t\tif (config.oauth) {\n\t\t\t// Ensure the OAuth provider ID matches the provider name\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\tif (!config.api) {\n\t\t\t\tthrow new Error(`Provider ${providerName}: \"api\" is required when registering streamSimple.`);\n\t\t\t}\n\t\t\tconst rawStreamSimple = config.streamSimple;\n\t\t\tconst authMode = config.authMode ?? \"apiKey\";\n\n\t\t\t// Keyless providers never see apiKey in options — enforced at registration,\n\t\t\t// not by convention. Prevents undefined from reaching any handler.\n\t\t\tconst streamSimple = (authMode === \"externalCli\" || authMode === \"none\")\n\t\t\t\t? ((model: Model<Api>, context: Context, options?: SimpleStreamOptions) => {\n\t\t\t\t\t\tconst { apiKey: _, ...opts } = options ?? {};\n\t\t\t\t\t\treturn rawStreamSimple(model, context, opts as SimpleStreamOptions);\n\t\t\t\t\t})\n\t\t\t\t: rawStreamSimple;\n\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\t// Store API key for auth resolution\n\t\tif (config.apiKey) {\n\t\t\tthis.customProviderApiKeys.set(providerName, config.apiKey);\n\t\t}\n\n\t\tif (config.models && config.models.length > 0) {\n\t\t\t// Full replacement: remove existing models for this provider\n\t\t\tthis.models = this.models.filter((m) => m.provider !== providerName);\n\n\t\t\t// Validate required fields\n\t\t\tif (!config.baseUrl) {\n\t\t\t\tthrow new Error(`Provider ${providerName}: \"baseUrl\" is required when defining models.`);\n\t\t\t}\n\t\t\tconst authMode = config.authMode ?? (config.oauth ? \"oauth\" : config.apiKey ? \"apiKey\" : \"apiKey\");\n\t\t\tif (authMode === \"apiKey\" && !config.apiKey && !config.oauth) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Provider ${providerName}: \"apiKey\" or \"oauth\" is required when authMode is \"apiKey\" (the default). ` +\n\t\t\t\t\t`Set authMode to \"externalCli\" or \"none\" for keyless providers.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ((authMode === \"externalCli\" || authMode === \"none\") && !config.streamSimple) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Provider ${providerName}: \"streamSimple\" is required when authMode is \"${authMode}\". ` +\n\t\t\t\t\t`Keyless providers must supply their own stream handler.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ((authMode === \"externalCli\" || authMode === \"none\") && config.apiKey) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Provider ${providerName}: \"apiKey\" cannot be set when authMode is \"${authMode}\". ` +\n\t\t\t\t\t`Keyless providers should not provide API key credentials.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Parse and add new models\n\t\t\tfor (const modelDef of config.models) {\n\t\t\t\tconst api = modelDef.api || config.api;\n\t\t\t\tif (!api) {\n\t\t\t\t\tthrow new Error(`Provider ${providerName}, model ${modelDef.id}: no \"api\" specified.`);\n\t\t\t\t}\n\n\t\t\t\t// Merge headers\n\t\t\t\tconst providerHeaders = resolveHeaders(config.headers);\n\t\t\t\tconst modelHeaders = resolveHeaders(modelDef.headers);\n\t\t\t\tlet headers = providerHeaders || modelHeaders ? { ...providerHeaders, ...modelHeaders } : undefined;\n\n\t\t\t\t// If authHeader is true, add Authorization header\n\t\t\t\tif (config.authHeader && config.apiKey) {\n\t\t\t\t\tconst resolvedKey = resolveConfigValue(config.apiKey);\n\t\t\t\t\tif (resolvedKey) {\n\t\t\t\t\t\theaders = { ...headers, Authorization: `Bearer ${resolvedKey}` };\n\t\t\t\t\t}\n\t\t\t\t}\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: config.baseUrl,\n\t\t\t\t\treasoning: modelDef.reasoning,\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,\n\t\t\t\t\tcompat: modelDef.compat,\n\t\t\t\t} as Model<Api>);\n\t\t\t}\n\n\t\t\t// Apply OAuth modifyModels if credentials exist (e.g., to update baseUrl)\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) {\n\t\t\t// Override-only: update baseUrl/headers for existing models\n\t\t\tconst resolvedHeaders = resolveHeaders(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\theaders: resolvedHeaders ? { ...m.headers, ...resolvedHeaders } : m.headers,\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Discover models from all providers that support discovery.\n\t * Results are cached and merged into the registry (never overrides existing models).\n\t */\n\tasync discoverModels(providers?: string[]): Promise<DiscoveryResult[]> {\n\t\tconst targetProviders = providers ?? getDiscoverableProviders();\n\t\tconst results: DiscoveryResult[] = [];\n\n\t\tfor (const providerName of targetProviders) {\n\t\t\tconst adapter = getDiscoveryAdapter(providerName);\n\t\t\tif (!adapter.supportsDiscovery) continue;\n\n\t\t\t// Skip if cache is still fresh\n\t\t\tif (!this.discoveryCache.isStale(providerName)) {\n\t\t\t\tconst cached = this.discoveryCache.get(providerName);\n\t\t\t\tif (cached) {\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tprovider: providerName,\n\t\t\t\t\t\tmodels: cached.models,\n\t\t\t\t\t\tfetchedAt: cached.fetchedAt,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst apiKey = await this.authStorage.getApiKey(providerName);\n\t\t\t\tif (!apiKey && !this.isProviderRequestReady(providerName)) continue;\n\n\t\t\t\tconst models = await adapter.fetchModels(apiKey ?? \"\", undefined);\n\t\t\t\tthis.discoveryCache.set(providerName, models);\n\t\t\t\tresults.push({\n\t\t\t\t\tprovider: providerName,\n\t\t\t\t\tmodels,\n\t\t\t\t\tfetchedAt: Date.now(),\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tresults.push({\n\t\t\t\t\tprovider: providerName,\n\t\t\t\t\tmodels: [],\n\t\t\t\t\tfetchedAt: Date.now(),\n\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Convert and merge discovered models\n\t\tthis.discoveredModels = this.convertDiscoveredModels(results);\n\t\treturn results;\n\t}\n\n\t/**\n\t * Get all models including discovered ones.\n\t * Discovered models are appended but never override existing models.\n\t */\n\tgetAllWithDiscovered(): Model<Api>[] {\n\t\tconst existingIds = new Set(this.models.map((m) => `${m.provider}/${m.id}`));\n\t\tconst unique = this.discoveredModels.filter((m) => !existingIds.has(`${m.provider}/${m.id}`));\n\t\treturn [...this.models, ...unique];\n\t}\n\n\t/**\n\t * Check if a model was added via discovery (not built-in or custom).\n\t */\n\tisDiscovered(model: Model<Api>): boolean {\n\t\treturn this.discoveredModels.some((m) => m.provider === model.provider && m.id === model.id);\n\t}\n\n\t/**\n\t * Get the discovery cache instance.\n\t */\n\tgetDiscoveryCache(): ModelDiscoveryCache {\n\t\treturn this.discoveryCache;\n\t}\n\n\t/**\n\t * Convert DiscoveryResult[] into Model<Api>[] with default values.\n\t */\n\tprivate convertDiscoveredModels(results: DiscoveryResult[]): Model<Api>[] {\n\t\tconst converted: Model<Api>[] = [];\n\t\tfor (const result of results) {\n\t\t\tif (result.error) continue;\n\t\t\tfor (const dm of result.models) {\n\t\t\t\tconverted.push({\n\t\t\t\t\tid: dm.id,\n\t\t\t\t\tname: dm.name ?? dm.id,\n\t\t\t\t\tapi: \"openai\" as Api,\n\t\t\t\t\tprovider: result.provider,\n\t\t\t\t\tbaseUrl: \"\",\n\t\t\t\t\treasoning: dm.reasoning ?? false,\n\t\t\t\t\tinput: dm.input ?? [\"text\"],\n\t\t\t\t\tcost: dm.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\t\t\t\tcontextWindow: dm.contextWindow ?? 128000,\n\t\t\t\t\tmaxTokens: dm.maxTokens ?? 16384,\n\t\t\t\t} as Model<Api>);\n\t\t\t}\n\t\t}\n\t\treturn converted;\n\t}\n\n\t/**\n\t * Check if a model's baseUrl points to a local endpoint.\n\t * Delegates to standalone isLocalModel() function.\n\t */\n\tstatic isLocalModel(model: Model<Api>): boolean {\n\t\treturn isLocalModel(model);\n\t}\n\n\t/**\n\t * Check if all models in the registry are local.\n\t * Returns true only if every model passes isLocalModel().\n\t * Returns false if there are no models.\n\t */\n\tisAllLocalChain(): boolean {\n\t\tconst models = this.getAll();\n\t\tif (models.length === 0) return false;\n\t\treturn models.every((m) => isLocalModel(m));\n\t}\n}\n\n/**\n * Input type for registerProvider API.\n */\nexport interface ProviderConfigInput {\n\tauthMode?: ProviderAuthMode;\n\t/** Optional readiness check. Called by isProviderRequestReady() before default auth checks.\n\t * Trusted at the same level as extension code — extensions already have arbitrary code execution. */\n\tisReady?: () => boolean;\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\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;AAEH,OAAO,EAIN,cAAc,EACd,SAAS,EACT,YAAY,EAMZ,mBAAmB,EACnB,iBAAiB,GAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,SAAS,MAAM,KAAK,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAiB,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAyB,kBAAkB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACtG,OAAO,EAAE,YA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E,EAAE,CAAC,aAAa,IAAI,MAAM;oBACzC,SAAS,EAAE,EAAE,CAAC,SAAS,IAAI,KAAK;iBAClB,CAAC,CAAC;YAClB,CAAC;QACF,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,KAAiB;QACpC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,eAAe;QACd,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACtC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;CACD","sourcesContent":["/**\n * Model registry - manages built-in and custom models, provides API key resolution.\n */\n\nimport {\n\ttype Api,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tgetApiProvider,\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 \"@gsd/pi-ai\";\nimport { registerOAuthProvider, resetOAuthProviders } from \"@gsd/pi-ai/oauth\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport AjvModule from \"ajv\";\nimport { existsSync, readFileSync } from \"fs\";\nimport { join } from \"path\";\nimport { getAgentDir } from \"../config.js\";\nimport type { AuthStorage } from \"./auth-storage.js\";\nimport { ModelDiscoveryCache } from \"./discovery-cache.js\";\nimport type { DiscoveredModel, DiscoveryResult } from \"./model-discovery.js\";\nimport { getDefaultTTL, getDiscoverableProviders, getDiscoveryAdapter } from \"./model-discovery.js\";\nimport { clearConfigValueCache, resolveConfigValue, resolveHeaders } from \"./resolve-config-value.js\";\nimport { isLocalModel } from \"./local-model-check.js\";\n\nconst Ajv = (AjvModule as any).default || AjvModule;\nconst ajv = new Ajv();\n\n// Schema for OpenRouter routing preferences\nconst OpenRouterRoutingSchema = Type.Object({\n\tonly: Type.Optional(Type.Array(Type.String())),\n\torder: Type.Optional(Type.Array(Type.String())),\n});\n\n// Schema for Vercel AI Gateway routing preferences\nconst VercelGatewayRoutingSchema = Type.Object({\n\tonly: Type.Optional(Type.Array(Type.String())),\n\torder: Type.Optional(Type.Array(Type.String())),\n});\n\n// Schema for OpenAI compatibility settings\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\trequiresMistralToolIds: Type.Optional(Type.Boolean()),\n\tthinkingFormat: Type.Optional(Type.Union([Type.Literal(\"openai\"), Type.Literal(\"zai\"), Type.Literal(\"qwen\")])),\n\topenRouterRouting: Type.Optional(OpenRouterRoutingSchema),\n\tvercelGatewayRouting: Type.Optional(VercelGatewayRoutingSchema),\n});\n\nconst OpenAIResponsesCompatSchema = Type.Object({\n\t// Reserved for future use\n});\n\nconst OpenAICompatSchema = Type.Union([OpenAICompletionsCompatSchema, OpenAIResponsesCompatSchema]);\n\n// Schema for custom model definition\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\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(OpenAICompatSchema),\n});\n\n// Schema for per-model overrides (all fields optional, merged with built-in model)\nconst ModelOverrideSchema = Type.Object({\n\tname: Type.Optional(Type.String({ minLength: 1 })),\n\treasoning: Type.Optional(Type.Boolean()),\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(OpenAICompatSchema),\n});\n\ntype ModelOverride = Static<typeof ModelOverrideSchema>;\n\nconst ProviderConfigSchema = Type.Object({\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\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\najv.addSchema(ModelsConfigSchema, \"ModelsConfig\");\n\ntype ModelsConfig = Static<typeof ModelsConfigSchema>;\n\nexport type ProviderAuthMode = \"apiKey\" | \"oauth\" | \"externalCli\" | \"none\";\n\n/** Provider override config (baseUrl, headers, apiKey) without custom models */\ninterface ProviderOverride {\n\tbaseUrl?: string;\n\theaders?: Record<string, string>;\n\tapiKey?: 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 | undefined;\n\tconst override = overrideCompat as OpenAICompletionsCompat | OpenAIResponsesCompat;\n\tconst merged = { ...base, ...override } as OpenAICompletionsCompat | OpenAIResponsesCompat;\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\t// Simple field overrides\n\tif (override.name !== undefined) result.name = override.name;\n\tif (override.reasoning !== undefined) result.reasoning = override.reasoning;\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\t// Merge cost (partial override)\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\t// Merge headers\n\tif (override.headers) {\n\t\tconst resolvedHeaders = resolveHeaders(override.headers);\n\t\tresult.headers = resolvedHeaders ? { ...model.headers, ...resolvedHeaders } : model.headers;\n\t}\n\n\t// Deep merge compat\n\tresult.compat = mergeCompat(model.compat, override.compat);\n\n\treturn result;\n}\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 discoveredModels: Model<Api>[] = [];\n\tprivate discoveryCache: ModelDiscoveryCache;\n\tprivate customProviderApiKeys: Map<string, string> = new Map();\n\tprivate registeredProviders: Map<string, ProviderConfigInput> = new Map();\n\tprivate loadError: string | undefined = undefined;\n\n\tconstructor(\n\t\treadonly authStorage: AuthStorage,\n\t\tprivate modelsJsonPath: string | undefined = join(getAgentDir(), \"models.json\"),\n\t) {\n\t\tthis.discoveryCache = new ModelDiscoveryCache();\n\n\t\t// Set up fallback resolver for custom provider API keys\n\t\tthis.authStorage.setFallbackResolver((provider) => {\n\t\t\tconst keyConfig = this.customProviderApiKeys.get(provider);\n\t\t\tif (keyConfig) {\n\t\t\t\treturn resolveConfigValue(keyConfig);\n\t\t\t}\n\t\t\treturn undefined;\n\t\t});\n\n\t\t// Refresh models when credentials change (e.g., OAuth token refresh with new model limits)\n\t\tthis.authStorage.onCredentialChange(() => this.refresh());\n\n\t\t// Load models\n\t\tthis.loadModels();\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.customProviderApiKeys.clear();\n\t\tthis.loadError = undefined;\n\n\t\t// Ensure dynamic API/OAuth registrations are rebuilt from current provider state.\n\t\tresetApiProviders();\n\t\tresetOAuthProviders();\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\t// Load custom models and overrides from models.json\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\t// Keep built-in models even if custom models failed to load\n\t\t}\n\n\t\tconst builtInModels = this.loadBuiltInModels(overrides, modelOverrides);\n\t\tlet combined = this.mergeCustomModels(builtInModels, customModels);\n\n\t\t// Let OAuth providers modify their models (e.g., update baseUrl)\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\t// Apply provider-level baseUrl/headers override\n\t\t\t\tif (providerOverride) {\n\t\t\t\t\tconst resolvedHeaders = resolveHeaders(providerOverride.headers);\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\theaders: resolvedHeaders ? { ...model.headers, ...resolvedHeaders } : model.headers,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// Apply per-model override\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 config: ModelsConfig = JSON.parse(content);\n\n\t\t\t// Validate schema\n\t\t\tconst validate = ajv.getSchema(\"ModelsConfig\")!;\n\t\t\tif (!validate(config)) {\n\t\t\t\tconst errors =\n\t\t\t\t\tvalidate.errors?.map((e: any) => ` - ${e.instancePath || \"root\"}: ${e.message}`).join(\"\\n\") ||\n\t\t\t\t\t\"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\t// Additional validation\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\t// Apply provider-level baseUrl/headers/apiKey override to built-in models when configured.\n\t\t\t\tif (providerConfig.baseUrl || providerConfig.headers || providerConfig.apiKey) {\n\t\t\t\t\toverrides.set(providerName, {\n\t\t\t\t\t\tbaseUrl: providerConfig.baseUrl,\n\t\t\t\t\t\theaders: providerConfig.headers,\n\t\t\t\t\t\tapiKey: providerConfig.apiKey,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Store API key for fallback resolver.\n\t\t\t\tif (providerConfig.apiKey) {\n\t\t\t\t\tthis.customProviderApiKeys.set(providerName, providerConfig.apiKey);\n\t\t\t\t}\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}\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\tfor (const [providerName, providerConfig] of Object.entries(config.providers)) {\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\t// Override-only config: needs baseUrl OR modelOverrides (or both)\n\t\t\t\tif (!providerConfig.baseUrl && !hasModelOverrides) {\n\t\t\t\t\tthrow new Error(`Provider ${providerName}: must specify \"baseUrl\", \"modelOverrides\", or \"models\".`);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Custom models are merged into provider models and require endpoint + auth.\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\n\t\t\tfor (const modelDef of models) {\n\t\t\t\tconst hasModelApi = !!modelDef.api;\n\n\t\t\t\tif (!hasProviderApi && !hasModelApi) {\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\t// Validate contextWindow/maxTokens only if provided (they have defaults)\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\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\t// Store API key config for fallback resolver\n\t\t\tif (providerConfig.apiKey) {\n\t\t\t\tthis.customProviderApiKeys.set(providerName, providerConfig.apiKey);\n\t\t\t}\n\n\t\t\tfor (const modelDef of modelDefs) {\n\t\t\t\tconst api = modelDef.api || providerConfig.api;\n\t\t\t\tif (!api) continue;\n\n\t\t\t\t// Merge headers: provider headers are base, model headers override\n\t\t\t\t// Resolve env vars and shell commands in header values\n\t\t\t\tconst providerHeaders = resolveHeaders(providerConfig.headers);\n\t\t\t\tconst modelHeaders = resolveHeaders(modelDef.headers);\n\t\t\t\tlet headers = providerHeaders || modelHeaders ? { ...providerHeaders, ...modelHeaders } : undefined;\n\n\t\t\t\t// If authHeader is true, add Authorization header with resolved API key\n\t\t\t\tif (providerConfig.authHeader && providerConfig.apiKey) {\n\t\t\t\t\tconst resolvedKey = resolveConfigValue(providerConfig.apiKey);\n\t\t\t\t\tif (resolvedKey) {\n\t\t\t\t\t\theaders = { ...headers, Authorization: `Bearer ${resolvedKey}` };\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Provider baseUrl is required when custom models are defined.\n\t\t\t\t// Individual models can override it with modelDef.baseUrl.\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: modelDef.baseUrl ?? providerConfig.baseUrl!,\n\t\t\t\t\treasoning: modelDef.reasoning ?? false,\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,\n\t\t\t\t\tcompat: modelDef.compat,\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((m) => this.isProviderRequestReady(m.provider));\n\t}\n\n\t/**\n\t * Get auth mode for a provider.\n\t * Defaults to \"apiKey\" for built-ins and providers without explicit mode.\n\t */\n\tgetProviderAuthMode(provider: string): ProviderAuthMode {\n\t\tconst config = this.registeredProviders.get(provider);\n\t\tif (!config) return \"apiKey\";\n\t\tif (config.authMode) return config.authMode;\n\t\tif (config.oauth) return \"oauth\";\n\t\tif (config.apiKey) return \"apiKey\";\n\t\treturn \"apiKey\";\n\t}\n\n\t/**\n\t * Whether a provider can be used for requests/fallback without hard auth gating.\n\t */\n\tisProviderRequestReady(provider: string): boolean {\n\t\tconst config = this.registeredProviders.get(provider);\n\t\tif (config?.isReady) return config.isReady();\n\t\tconst authMode = this.getProviderAuthMode(provider);\n\t\tif (authMode === \"externalCli\" || authMode === \"none\") return true;\n\t\treturn this.authStorage.hasAuth(provider);\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 * Returns undefined for externalCli/none providers (no key needed).\n\t * @param sessionId - Optional session ID for sticky credential selection\n\t */\n\tasync getApiKey(model: Model<Api>, sessionId?: string): Promise<string | undefined> {\n\t\tconst authMode = this.getProviderAuthMode(model.provider);\n\t\tif (authMode === \"externalCli\" || authMode === \"none\") return undefined;\n\t\treturn this.authStorage.getApiKey(model.provider, sessionId, { baseUrl: model.baseUrl });\n\t}\n\n\t/**\n\t * Get API key for a provider.\n\t * Returns undefined for externalCli/none providers (no key needed).\n\t * @param sessionId - Optional session ID for sticky credential selection\n\t */\n\tasync getApiKeyForProvider(provider: string, sessionId?: string): Promise<string | undefined> {\n\t\tconst authMode = this.getProviderAuthMode(provider);\n\t\tif (authMode === \"externalCli\" || authMode === \"none\") return undefined;\n\t\treturn this.authStorage.getApiKey(provider, sessionId);\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.registeredProviders.set(providerName, config);\n\t\tthis.applyProviderConfig(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.customProviderApiKeys.delete(providerName);\n\t\tthis.refresh();\n\t}\n\n\tprivate applyProviderConfig(providerName: string, config: ProviderConfigInput): void {\n\t\t// Register OAuth provider if provided\n\t\tif (config.oauth) {\n\t\t\t// Ensure the OAuth provider ID matches the provider name\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\tif (!config.api) {\n\t\t\t\tthrow new Error(`Provider ${providerName}: \"api\" is required when registering streamSimple.`);\n\t\t\t}\n\t\t\tconst rawStreamSimple = config.streamSimple;\n\t\t\tconst authMode = config.authMode ?? \"apiKey\";\n\n\t\t\t// Keyless providers never see apiKey in options — enforced at registration,\n\t\t\t// not by convention. Prevents undefined from reaching any handler.\n\t\t\tconst streamSimple = (authMode === \"externalCli\" || authMode === \"none\")\n\t\t\t\t? ((model: Model<Api>, context: Context, options?: SimpleStreamOptions) => {\n\t\t\t\t\t\tconst { apiKey: _, ...opts } = options ?? {};\n\t\t\t\t\t\treturn rawStreamSimple(model, context, opts as SimpleStreamOptions);\n\t\t\t\t\t})\n\t\t\t\t: rawStreamSimple;\n\n\t\t\t// Guard: if there's already a handler registered for this API, wrap\n\t\t\t// the new one so it only fires for models from this provider and\n\t\t\t// delegates to the previous handler for all other providers. Without\n\t\t\t// this, a custom provider using api:\"anthropic-messages\" would clobber\n\t\t\t// the built-in Anthropic stream handler (#2536).\n\t\t\tconst existingProvider = getApiProvider(config.api as Api);\n\t\t\tconst scopedStream = existingProvider\n\t\t\t\t? (model: Model<Api>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream => {\n\t\t\t\t\t\tif (model.provider === providerName) {\n\t\t\t\t\t\t\treturn streamSimple(model, context, options);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn existingProvider.streamSimple(model, context, options);\n\t\t\t\t\t}\n\t\t\t\t: streamSimple;\n\n\t\t\tconst newFullStream = (model: Model<Api>, context: Context, options?: SimpleStreamOptions) =>\n\t\t\t\tscopedStream(model, context, options as SimpleStreamOptions);\n\t\t\tconst scopedFullStream = existingProvider\n\t\t\t\t? (model: Model<Api>, context: Context, options?: Record<string, unknown>) => {\n\t\t\t\t\t\tif (model.provider === providerName) {\n\t\t\t\t\t\t\treturn newFullStream(model, context, options as SimpleStreamOptions);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn existingProvider.stream(model, context, options);\n\t\t\t\t\t}\n\t\t\t\t: newFullStream;\n\n\t\t\tregisterApiProvider(\n\t\t\t\t{\n\t\t\t\t\tapi: config.api,\n\t\t\t\t\tstream: scopedFullStream as any,\n\t\t\t\t\tstreamSimple: scopedStream,\n\t\t\t\t},\n\t\t\t\t`provider:${providerName}`,\n\t\t\t);\n\t\t}\n\n\t\t// Store API key for auth resolution\n\t\tif (config.apiKey) {\n\t\t\tthis.customProviderApiKeys.set(providerName, config.apiKey);\n\t\t}\n\n\t\tif (config.models && config.models.length > 0) {\n\t\t\t// Full replacement: remove existing models for this provider\n\t\t\tthis.models = this.models.filter((m) => m.provider !== providerName);\n\n\t\t\t// Validate required fields\n\t\t\tif (!config.baseUrl) {\n\t\t\t\tthrow new Error(`Provider ${providerName}: \"baseUrl\" is required when defining models.`);\n\t\t\t}\n\t\t\tconst authMode = config.authMode ?? (config.oauth ? \"oauth\" : config.apiKey ? \"apiKey\" : \"apiKey\");\n\t\t\tif (authMode === \"apiKey\" && !config.apiKey && !config.oauth) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Provider ${providerName}: \"apiKey\" or \"oauth\" is required when authMode is \"apiKey\" (the default). ` +\n\t\t\t\t\t`Set authMode to \"externalCli\" or \"none\" for keyless providers.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ((authMode === \"externalCli\" || authMode === \"none\") && !config.streamSimple) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Provider ${providerName}: \"streamSimple\" is required when authMode is \"${authMode}\". ` +\n\t\t\t\t\t`Keyless providers must supply their own stream handler.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ((authMode === \"externalCli\" || authMode === \"none\") && config.apiKey) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Provider ${providerName}: \"apiKey\" cannot be set when authMode is \"${authMode}\". ` +\n\t\t\t\t\t`Keyless providers should not provide API key credentials.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Parse and add new models\n\t\t\tfor (const modelDef of config.models) {\n\t\t\t\tconst api = modelDef.api || config.api;\n\t\t\t\tif (!api) {\n\t\t\t\t\tthrow new Error(`Provider ${providerName}, model ${modelDef.id}: no \"api\" specified.`);\n\t\t\t\t}\n\n\t\t\t\t// Merge headers\n\t\t\t\tconst providerHeaders = resolveHeaders(config.headers);\n\t\t\t\tconst modelHeaders = resolveHeaders(modelDef.headers);\n\t\t\t\tlet headers = providerHeaders || modelHeaders ? { ...providerHeaders, ...modelHeaders } : undefined;\n\n\t\t\t\t// If authHeader is true, add Authorization header\n\t\t\t\tif (config.authHeader && config.apiKey) {\n\t\t\t\t\tconst resolvedKey = resolveConfigValue(config.apiKey);\n\t\t\t\t\tif (resolvedKey) {\n\t\t\t\t\t\theaders = { ...headers, Authorization: `Bearer ${resolvedKey}` };\n\t\t\t\t\t}\n\t\t\t\t}\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: config.baseUrl,\n\t\t\t\t\treasoning: modelDef.reasoning,\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,\n\t\t\t\t\tcompat: modelDef.compat,\n\t\t\t\t} as Model<Api>);\n\t\t\t}\n\n\t\t\t// Apply OAuth modifyModels if credentials exist (e.g., to update baseUrl)\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) {\n\t\t\t// Override-only: update baseUrl/headers for existing models\n\t\t\tconst resolvedHeaders = resolveHeaders(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\theaders: resolvedHeaders ? { ...m.headers, ...resolvedHeaders } : m.headers,\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Discover models from all providers that support discovery.\n\t * Results are cached and merged into the registry (never overrides existing models).\n\t */\n\tasync discoverModels(providers?: string[]): Promise<DiscoveryResult[]> {\n\t\tconst targetProviders = providers ?? getDiscoverableProviders();\n\t\tconst results: DiscoveryResult[] = [];\n\n\t\tfor (const providerName of targetProviders) {\n\t\t\tconst adapter = getDiscoveryAdapter(providerName);\n\t\t\tif (!adapter.supportsDiscovery) continue;\n\n\t\t\t// Skip if cache is still fresh\n\t\t\tif (!this.discoveryCache.isStale(providerName)) {\n\t\t\t\tconst cached = this.discoveryCache.get(providerName);\n\t\t\t\tif (cached) {\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tprovider: providerName,\n\t\t\t\t\t\tmodels: cached.models,\n\t\t\t\t\t\tfetchedAt: cached.fetchedAt,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst apiKey = await this.authStorage.getApiKey(providerName);\n\t\t\t\tif (!apiKey && !this.isProviderRequestReady(providerName)) continue;\n\n\t\t\t\tconst models = await adapter.fetchModels(apiKey ?? \"\", undefined);\n\t\t\t\tthis.discoveryCache.set(providerName, models);\n\t\t\t\tresults.push({\n\t\t\t\t\tprovider: providerName,\n\t\t\t\t\tmodels,\n\t\t\t\t\tfetchedAt: Date.now(),\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tresults.push({\n\t\t\t\t\tprovider: providerName,\n\t\t\t\t\tmodels: [],\n\t\t\t\t\tfetchedAt: Date.now(),\n\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Convert and merge discovered models\n\t\tthis.discoveredModels = this.convertDiscoveredModels(results);\n\t\treturn results;\n\t}\n\n\t/**\n\t * Get all models including discovered ones.\n\t * Discovered models are appended but never override existing models.\n\t */\n\tgetAllWithDiscovered(): Model<Api>[] {\n\t\tconst existingIds = new Set(this.models.map((m) => `${m.provider}/${m.id}`));\n\t\tconst unique = this.discoveredModels.filter((m) => !existingIds.has(`${m.provider}/${m.id}`));\n\t\treturn [...this.models, ...unique];\n\t}\n\n\t/**\n\t * Check if a model was added via discovery (not built-in or custom).\n\t */\n\tisDiscovered(model: Model<Api>): boolean {\n\t\treturn this.discoveredModels.some((m) => m.provider === model.provider && m.id === model.id);\n\t}\n\n\t/**\n\t * Get the discovery cache instance.\n\t */\n\tgetDiscoveryCache(): ModelDiscoveryCache {\n\t\treturn this.discoveryCache;\n\t}\n\n\t/**\n\t * Convert DiscoveryResult[] into Model<Api>[] with default values.\n\t */\n\tprivate convertDiscoveredModels(results: DiscoveryResult[]): Model<Api>[] {\n\t\tconst converted: Model<Api>[] = [];\n\t\tfor (const result of results) {\n\t\t\tif (result.error) continue;\n\t\t\tfor (const dm of result.models) {\n\t\t\t\tconverted.push({\n\t\t\t\t\tid: dm.id,\n\t\t\t\t\tname: dm.name ?? dm.id,\n\t\t\t\t\tapi: \"openai\" as Api,\n\t\t\t\t\tprovider: result.provider,\n\t\t\t\t\tbaseUrl: \"\",\n\t\t\t\t\treasoning: dm.reasoning ?? false,\n\t\t\t\t\tinput: dm.input ?? [\"text\"],\n\t\t\t\t\tcost: dm.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\t\t\t\tcontextWindow: dm.contextWindow ?? 128000,\n\t\t\t\t\tmaxTokens: dm.maxTokens ?? 16384,\n\t\t\t\t} as Model<Api>);\n\t\t\t}\n\t\t}\n\t\treturn converted;\n\t}\n\n\t/**\n\t * Check if a model's baseUrl points to a local endpoint.\n\t * Delegates to standalone isLocalModel() function.\n\t */\n\tstatic isLocalModel(model: Model<Api>): boolean {\n\t\treturn isLocalModel(model);\n\t}\n\n\t/**\n\t * Check if all models in the registry are local.\n\t * Returns true only if every model passes isLocalModel().\n\t * Returns false if there are no models.\n\t */\n\tisAllLocalChain(): boolean {\n\t\tconst models = this.getAll();\n\t\tif (models.length === 0) return false;\n\t\treturn models.every((m) => isLocalModel(m));\n\t}\n}\n\n/**\n * Input type for registerProvider API.\n */\nexport interface ProviderConfigInput {\n\tauthMode?: ProviderAuthMode;\n\t/** Optional readiness check. Called by isProviderRequestReady() before default auth checks.\n\t * Trusted at the same level as extension code — extensions already have arbitrary code execution. */\n\tisReady?: () => boolean;\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\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"]}
|