gsd-pi 2.76.0-dev.4100bd590 → 2.76.0-dev.76f9a2dc5
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/resource-loader.d.ts +1 -1
- package/dist/resource-loader.js +2 -8
- package/dist/resources/extensions/gsd/auto/phases.js +4 -1
- package/dist/resources/extensions/gsd/auto/session.js +4 -0
- package/dist/resources/extensions/gsd/auto-model-selection.js +13 -2
- package/dist/resources/extensions/gsd/auto-start.js +12 -7
- package/dist/resources/extensions/gsd/auto.js +4 -1
- package/dist/resources/extensions/gsd/complexity-classifier.js +5 -3
- package/dist/resources/extensions/gsd/init-wizard.js +15 -1
- package/dist/resources/extensions/gsd/prompt-loader.js +22 -7
- package/dist/resources/extensions/gsd/safety/file-change-validator.js +1 -1
- package/dist/tsconfig.extensions.tsbuildinfo +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +20 -20
- 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 +1 -1
- 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/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 +20 -20
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/package.json +1 -1
- package/packages/pi-ai/dist/providers/openai-completions.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/openai-completions.js +60 -15
- package/packages/pi-ai/dist/providers/openai-completions.js.map +1 -1
- package/packages/pi-ai/dist/providers/think-tag-parser.d.ts +17 -0
- package/packages/pi-ai/dist/providers/think-tag-parser.d.ts.map +1 -0
- package/packages/pi-ai/dist/providers/think-tag-parser.js +75 -0
- package/packages/pi-ai/dist/providers/think-tag-parser.js.map +1 -0
- package/packages/pi-ai/dist/providers/think-tag-parser.test.d.ts +2 -0
- package/packages/pi-ai/dist/providers/think-tag-parser.test.d.ts.map +1 -0
- package/packages/pi-ai/dist/providers/think-tag-parser.test.js +41 -0
- package/packages/pi-ai/dist/providers/think-tag-parser.test.js.map +1 -0
- package/packages/pi-ai/src/providers/openai-completions.ts +57 -16
- package/packages/pi-ai/src/providers/think-tag-parser.test.ts +44 -0
- package/packages/pi-ai/src/providers/think-tag-parser.ts +94 -0
- package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-coding-agent/dist/core/model-discovery.d.ts +3 -1
- package/packages/pi-coding-agent/dist/core/model-discovery.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-discovery.js +92 -12
- package/packages/pi-coding-agent/dist/core/model-discovery.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-discovery.test.js +16 -1
- package/packages/pi-coding-agent/dist/core/model-discovery.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-registry-discovery.test.js +61 -1
- package/packages/pi-coding-agent/dist/core/model-registry-discovery.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-registry.d.ts +5 -0
- package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-registry.js +76 -10
- package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js +5 -4
- package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.js +13 -7
- package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts +7 -6
- package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js +29 -21
- package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/packages/pi-coding-agent/src/core/model-discovery.test.ts +19 -0
- package/packages/pi-coding-agent/src/core/model-discovery.ts +99 -12
- package/packages/pi-coding-agent/src/core/model-registry-discovery.test.ts +75 -0
- package/packages/pi-coding-agent/src/core/model-registry.ts +86 -10
- package/packages/pi-coding-agent/src/modes/interactive/components/chat-frame.ts +6 -6
- package/packages/pi-coding-agent/src/modes/interactive/components/provider-manager.ts +16 -7
- package/packages/pi-coding-agent/src/modes/interactive/components/skill-invocation-message.ts +36 -22
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
- package/scripts/link-workspace-packages.cjs +1 -0
- package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -0
- package/src/resources/extensions/gsd/auto/phases.ts +4 -0
- package/src/resources/extensions/gsd/auto/session.ts +7 -1
- package/src/resources/extensions/gsd/auto-model-selection.ts +16 -1
- package/src/resources/extensions/gsd/auto-start.ts +12 -7
- package/src/resources/extensions/gsd/auto.ts +4 -1
- package/src/resources/extensions/gsd/complexity-classifier.ts +5 -3
- package/src/resources/extensions/gsd/init-wizard.ts +15 -1
- package/src/resources/extensions/gsd/prompt-loader.ts +30 -7
- package/src/resources/extensions/gsd/safety/file-change-validator.ts +1 -1
- package/src/resources/extensions/gsd/tests/auto-model-selection.test.ts +12 -0
- package/src/resources/extensions/gsd/tests/auto-start-model-capture.test.ts +33 -3
- package/src/resources/extensions/gsd/tests/auto-thinking-restore.test.ts +38 -0
- package/src/resources/extensions/gsd/tests/complexity-classifier.test.ts +3 -3
- package/src/resources/extensions/gsd/tests/file-change-validator.test.ts +20 -0
- package/src/resources/extensions/gsd/tests/init-wizard.test.ts +27 -0
- package/src/resources/extensions/gsd/tests/prompt-loader-extension-dir.test.ts +49 -0
- /package/dist/web/standalone/.next/static/{YnUwu2WWaT0_hyTLUF4nq → UMCfv_sVnLXawpUAjvArc}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{YnUwu2WWaT0_hyTLUF4nq → UMCfv_sVnLXawpUAjvArc}/_ssgManifest.js +0 -0
|
@@ -9,7 +9,7 @@ import { existsSync, readFileSync } from "fs";
|
|
|
9
9
|
import { join } from "path";
|
|
10
10
|
import { getAgentDir } from "../config.js";
|
|
11
11
|
import { ModelDiscoveryCache } from "./discovery-cache.js";
|
|
12
|
-
import { getDiscoverableProviders, getDiscoveryAdapter } from "./model-discovery.js";
|
|
12
|
+
import { getDefaultTTL, getDiscoverableProviders, getDiscoveryAdapter, supportsDiscoveryForApi } from "./model-discovery.js";
|
|
13
13
|
import { resolveConfigValue, resolveHeaders } from "./resolve-config-value.js";
|
|
14
14
|
import { isLocalModel } from "./local-model-check.js";
|
|
15
15
|
const Ajv = AjvModule.default || AjvModule;
|
|
@@ -640,10 +640,11 @@ export class ModelRegistry {
|
|
|
640
640
|
* Results are cached and merged into the registry (never overrides existing models).
|
|
641
641
|
*/
|
|
642
642
|
async discoverModels(providers) {
|
|
643
|
-
const targetProviders = providers ??
|
|
643
|
+
const targetProviders = providers ?? this.getAutoDiscoverableProviders();
|
|
644
644
|
const results = [];
|
|
645
645
|
for (const providerName of targetProviders) {
|
|
646
|
-
const
|
|
646
|
+
const providerApis = this.getProviderApis(providerName);
|
|
647
|
+
const adapter = getDiscoveryAdapter(providerName, providerApis);
|
|
647
648
|
if (!adapter.supportsDiscovery)
|
|
648
649
|
continue;
|
|
649
650
|
// Skip if cache is still fresh
|
|
@@ -662,8 +663,10 @@ export class ModelRegistry {
|
|
|
662
663
|
const apiKey = await this.authStorage.getApiKey(providerName);
|
|
663
664
|
if (!apiKey && !this.isProviderRequestReady(providerName))
|
|
664
665
|
continue;
|
|
665
|
-
const
|
|
666
|
-
|
|
666
|
+
const baseUrl = this.getProviderBaseUrl(providerName);
|
|
667
|
+
const models = await adapter.fetchModels(apiKey ?? "", baseUrl);
|
|
668
|
+
const ttlMs = this.getDiscoveryTtl(providerName, providerApis);
|
|
669
|
+
this.discoveryCache.set(providerName, models, ttlMs);
|
|
667
670
|
results.push({
|
|
668
671
|
provider: providerName,
|
|
669
672
|
models,
|
|
@@ -712,23 +715,86 @@ export class ModelRegistry {
|
|
|
712
715
|
for (const result of results) {
|
|
713
716
|
if (result.error)
|
|
714
717
|
continue;
|
|
718
|
+
const providerDefaults = this.getDiscoveryProviderDefaults(result.provider);
|
|
715
719
|
for (const dm of result.models) {
|
|
716
720
|
converted.push({
|
|
717
721
|
id: dm.id,
|
|
718
722
|
name: dm.name ?? dm.id,
|
|
719
|
-
api:
|
|
723
|
+
api: providerDefaults.api,
|
|
720
724
|
provider: result.provider,
|
|
721
|
-
baseUrl:
|
|
725
|
+
baseUrl: providerDefaults.baseUrl,
|
|
722
726
|
reasoning: dm.reasoning ?? false,
|
|
723
|
-
input: dm.input ??
|
|
727
|
+
input: dm.input ?? providerDefaults.input,
|
|
724
728
|
cost: dm.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
725
|
-
contextWindow: dm.contextWindow ??
|
|
726
|
-
maxTokens: dm.maxTokens ??
|
|
729
|
+
contextWindow: dm.contextWindow ?? providerDefaults.contextWindow,
|
|
730
|
+
maxTokens: dm.maxTokens ?? providerDefaults.maxTokens,
|
|
727
731
|
});
|
|
728
732
|
}
|
|
729
733
|
}
|
|
730
734
|
return converted;
|
|
731
735
|
}
|
|
736
|
+
getProviderApis(provider) {
|
|
737
|
+
const apis = new Set();
|
|
738
|
+
for (const model of this.models) {
|
|
739
|
+
if (model.provider === provider && typeof model.api === "string" && model.api.length > 0) {
|
|
740
|
+
apis.add(model.api);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
const providerConfig = this.registeredProviders.get(provider);
|
|
744
|
+
if (providerConfig?.api)
|
|
745
|
+
apis.add(providerConfig.api);
|
|
746
|
+
for (const modelDef of providerConfig?.models ?? []) {
|
|
747
|
+
if (modelDef.api)
|
|
748
|
+
apis.add(modelDef.api);
|
|
749
|
+
}
|
|
750
|
+
return apis;
|
|
751
|
+
}
|
|
752
|
+
getAutoDiscoverableProviders() {
|
|
753
|
+
const discoverable = new Set(getDiscoverableProviders());
|
|
754
|
+
for (const provider of new Set(this.models.map((m) => m.provider))) {
|
|
755
|
+
const apis = this.getProviderApis(provider);
|
|
756
|
+
for (const api of apis) {
|
|
757
|
+
if (supportsDiscoveryForApi(api)) {
|
|
758
|
+
discoverable.add(provider);
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return [...discoverable];
|
|
764
|
+
}
|
|
765
|
+
getProviderBaseUrl(provider) {
|
|
766
|
+
const fromModels = this.models.find((m) => m.provider === provider && typeof m.baseUrl === "string" && m.baseUrl.length > 0);
|
|
767
|
+
if (fromModels?.baseUrl)
|
|
768
|
+
return fromModels.baseUrl;
|
|
769
|
+
return this.registeredProviders.get(provider)?.baseUrl;
|
|
770
|
+
}
|
|
771
|
+
getDiscoveryProviderDefaults(provider) {
|
|
772
|
+
const first = this.models.find((m) => m.provider === provider);
|
|
773
|
+
if (first) {
|
|
774
|
+
return {
|
|
775
|
+
api: first.api,
|
|
776
|
+
baseUrl: first.baseUrl,
|
|
777
|
+
input: first.input,
|
|
778
|
+
contextWindow: first.contextWindow,
|
|
779
|
+
maxTokens: first.maxTokens,
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
return {
|
|
783
|
+
api: "openai-completions",
|
|
784
|
+
baseUrl: this.registeredProviders.get(provider)?.baseUrl ?? "",
|
|
785
|
+
input: ["text"],
|
|
786
|
+
contextWindow: 128000,
|
|
787
|
+
maxTokens: 16384,
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
getDiscoveryTtl(provider, providerApis) {
|
|
791
|
+
for (const api of providerApis) {
|
|
792
|
+
if (supportsDiscoveryForApi(api)) {
|
|
793
|
+
return getDefaultTTL("openai");
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return getDefaultTTL(provider);
|
|
797
|
+
}
|
|
732
798
|
/**
|
|
733
799
|
* Check if a model's baseUrl points to a local endpoint.
|
|
734
800
|
* Delegates to standalone isLocalModel() function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-registry.js","sourceRoot":"","sources":["../../src/core/model-registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEN,sBAAsB,EAGtB,cAAc,EACd,YAAY,EACZ,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,CAAC;IAC9C,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC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E,QAAe;oBACpB,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,OAAO,EAAE,EAAE;oBACX,SAAS,EAAE,EAAE,CAAC,SAAS,IAAI,KAAK;oBAChC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC;oBAC3B,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE;oBACrE,aAAa,EAAE,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\tapplyCapabilityPatches,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tgetApiProvider,\n\tgetEnvApiKey,\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\treadonly 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 getEnvApiKey(provider);\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\t// Apply capability patches so custom/discovered/extension models get\n\t\t// capabilities (supportsXhigh, supportsServiceTier, etc.) that the\n\t\t// static pi-ai registry applies at module load for built-in models.\n\t\tthis.models = applyCapabilityPatches(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\t// Register custom providers so isProviderRequestReady() can find\n\t\t\t// them (#3531). Without this, models.json providers with apiKey\n\t\t\t// fail the auth check and are invisible to the fallback resolver.\n\t\t\tif (!this.registeredProviders.has(providerName)) {\n\t\t\t\tthis.registeredProviders.set(providerName, {\n\t\t\t\t\tauthMode: providerConfig.apiKey ? \"apiKey\" : \"none\",\n\t\t\t\t\tapiKey: providerConfig.apiKey,\n\t\t\t\t\tbaseUrl: providerConfig.baseUrl,\n\t\t\t\t\tisReady: providerConfig.apiKey ? () => true : undefined,\n\t\t\t\t} as any);\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\tproviderOptions: modelDef.providerOptions,\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\n\t\t\t// Ensure newly added extension models get capability patches\n\t\t\tthis.models = applyCapabilityPatches(this.models);\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, then apply capability patches\n\t\tthis.discoveredModels = applyCapabilityPatches(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\tproviderOptions?: Record<string, unknown>;\n\t}>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-registry.js","sourceRoot":"","sources":["../../src/core/model-registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OA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AAC,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\tapplyCapabilityPatches,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tgetApiProvider,\n\tgetEnvApiKey,\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, supportsDiscoveryForApi } 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\treadonly 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 getEnvApiKey(provider);\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\t// Apply capability patches so custom/discovered/extension models get\n\t\t// capabilities (supportsXhigh, supportsServiceTier, etc.) that the\n\t\t// static pi-ai registry applies at module load for built-in models.\n\t\tthis.models = applyCapabilityPatches(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\t// Register custom providers so isProviderRequestReady() can find\n\t\t\t// them (#3531). Without this, models.json providers with apiKey\n\t\t\t// fail the auth check and are invisible to the fallback resolver.\n\t\t\tif (!this.registeredProviders.has(providerName)) {\n\t\t\t\tthis.registeredProviders.set(providerName, {\n\t\t\t\t\tauthMode: providerConfig.apiKey ? \"apiKey\" : \"none\",\n\t\t\t\t\tapiKey: providerConfig.apiKey,\n\t\t\t\t\tbaseUrl: providerConfig.baseUrl,\n\t\t\t\t\tisReady: providerConfig.apiKey ? () => true : undefined,\n\t\t\t\t} as any);\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\tproviderOptions: modelDef.providerOptions,\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\n\t\t\t// Ensure newly added extension models get capability patches\n\t\t\tthis.models = applyCapabilityPatches(this.models);\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 ?? this.getAutoDiscoverableProviders();\n\t\tconst results: DiscoveryResult[] = [];\n\n\t\tfor (const providerName of targetProviders) {\n\t\t\tconst providerApis = this.getProviderApis(providerName);\n\t\t\tconst adapter = getDiscoveryAdapter(providerName, providerApis);\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 baseUrl = this.getProviderBaseUrl(providerName);\n\t\t\t\tconst models = await adapter.fetchModels(apiKey ?? \"\", baseUrl);\n\t\t\t\tconst ttlMs = this.getDiscoveryTtl(providerName, providerApis);\n\t\t\t\tthis.discoveryCache.set(providerName, models, ttlMs);\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, then apply capability patches\n\t\tthis.discoveredModels = applyCapabilityPatches(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\tconst providerDefaults = this.getDiscoveryProviderDefaults(result.provider);\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: providerDefaults.api,\n\t\t\t\t\tprovider: result.provider,\n\t\t\t\t\tbaseUrl: providerDefaults.baseUrl,\n\t\t\t\t\treasoning: dm.reasoning ?? false,\n\t\t\t\t\tinput: dm.input ?? providerDefaults.input,\n\t\t\t\t\tcost: dm.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\t\t\t\tcontextWindow: dm.contextWindow ?? providerDefaults.contextWindow,\n\t\t\t\t\tmaxTokens: dm.maxTokens ?? providerDefaults.maxTokens,\n\t\t\t\t} as Model<Api>);\n\t\t\t}\n\t\t}\n\t\treturn converted;\n\t}\n\n\tprivate getProviderApis(provider: string): Set<string> {\n\t\tconst apis = new Set<string>();\n\t\tfor (const model of this.models) {\n\t\t\tif (model.provider === provider && typeof model.api === \"string\" && model.api.length > 0) {\n\t\t\t\tapis.add(model.api);\n\t\t\t}\n\t\t}\n\n\t\tconst providerConfig = this.registeredProviders.get(provider);\n\t\tif (providerConfig?.api) apis.add(providerConfig.api);\n\t\tfor (const modelDef of providerConfig?.models ?? []) {\n\t\t\tif (modelDef.api) apis.add(modelDef.api);\n\t\t}\n\t\treturn apis;\n\t}\n\n\tprivate getAutoDiscoverableProviders(): string[] {\n\t\tconst discoverable = new Set<string>(getDiscoverableProviders());\n\t\tfor (const provider of new Set(this.models.map((m) => m.provider))) {\n\t\t\tconst apis = this.getProviderApis(provider);\n\t\t\tfor (const api of apis) {\n\t\t\t\tif (supportsDiscoveryForApi(api)) {\n\t\t\t\t\tdiscoverable.add(provider);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn [...discoverable];\n\t}\n\n\tprivate getProviderBaseUrl(provider: string): string | undefined {\n\t\tconst fromModels = this.models.find((m) => m.provider === provider && typeof m.baseUrl === \"string\" && m.baseUrl.length > 0);\n\t\tif (fromModels?.baseUrl) return fromModels.baseUrl;\n\t\treturn this.registeredProviders.get(provider)?.baseUrl;\n\t}\n\n\tprivate getDiscoveryProviderDefaults(provider: string): {\n\t\tapi: Api;\n\t\tbaseUrl: string;\n\t\tinput: (\"text\" | \"image\")[];\n\t\tcontextWindow: number;\n\t\tmaxTokens: number;\n\t} {\n\t\tconst first = this.models.find((m) => m.provider === provider);\n\t\tif (first) {\n\t\t\treturn {\n\t\t\t\tapi: first.api,\n\t\t\t\tbaseUrl: first.baseUrl,\n\t\t\t\tinput: first.input,\n\t\t\t\tcontextWindow: first.contextWindow,\n\t\t\t\tmaxTokens: first.maxTokens,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tapi: \"openai-completions\",\n\t\t\tbaseUrl: this.registeredProviders.get(provider)?.baseUrl ?? \"\",\n\t\t\tinput: [\"text\"],\n\t\t\tcontextWindow: 128000,\n\t\t\tmaxTokens: 16384,\n\t\t};\n\t}\n\n\tprivate getDiscoveryTtl(provider: string, providerApis: Set<string>): number {\n\t\tfor (const api of providerApis) {\n\t\t\tif (supportsDiscoveryForApi(api)) {\n\t\t\t\treturn getDefaultTTL(\"openai\");\n\t\t\t}\n\t\t}\n\t\treturn getDefaultTTL(provider);\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\tproviderOptions?: Record<string, unknown>;\n\t}>;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TimestampFormat } from "./timestamp.js";
|
|
2
|
-
type FrameTone = "assistant" | "user" | "compaction";
|
|
2
|
+
type FrameTone = "assistant" | "user" | "compaction" | "skill";
|
|
3
3
|
export declare function renderChatFrame(contentLines: string[], width: number, opts: {
|
|
4
4
|
label: string;
|
|
5
5
|
tone: FrameTone;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-frame.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-frame.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEvE,KAAK,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-frame.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-frame.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEvE,KAAK,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,YAAY,GAAG,OAAO,CAAC;AAU/D,wBAAgB,eAAe,CAC9B,YAAY,EAAE,MAAM,EAAE,EACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE;IACL,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB,GACC,MAAM,EAAE,CA8DV"}
|
|
@@ -13,12 +13,13 @@ function trimOuterBlankLines(lines) {
|
|
|
13
13
|
export function renderChatFrame(contentLines, width, opts) {
|
|
14
14
|
const outerWidth = Math.max(20, width);
|
|
15
15
|
const contentWidth = Math.max(1, outerWidth - 2); // "│ " + content
|
|
16
|
+
const isPurple = opts.tone === "compaction" || opts.tone === "skill";
|
|
16
17
|
const borderColor = opts.tone === "user"
|
|
17
18
|
? "border"
|
|
18
|
-
:
|
|
19
|
+
: isPurple
|
|
19
20
|
? "customMessageLabel"
|
|
20
21
|
: "borderAccent";
|
|
21
|
-
const borderMuted =
|
|
22
|
+
const borderMuted = isPurple ? "customMessageLabel" : "borderMuted";
|
|
22
23
|
const border = (s) => theme.fg(borderColor, s);
|
|
23
24
|
const leftRaw = `• ${opts.label}`;
|
|
24
25
|
const rightRaw = opts.showTimestamp === false || !opts.timestamp
|
|
@@ -30,7 +31,7 @@ export function renderChatFrame(contentLines, width, opts) {
|
|
|
30
31
|
const left = truncateToWidth(leftRaw, leftBudget, "");
|
|
31
32
|
const labelColor = opts.tone === "user"
|
|
32
33
|
? "border"
|
|
33
|
-
:
|
|
34
|
+
: isPurple
|
|
34
35
|
? "customMessageLabel"
|
|
35
36
|
: "borderAccent";
|
|
36
37
|
const dashIdx = left.indexOf(" - ");
|
|
@@ -47,7 +48,7 @@ export function renderChatFrame(contentLines, width, opts) {
|
|
|
47
48
|
const sourceLines = trimOuterBlankLines(contentLines);
|
|
48
49
|
const bodyColor = opts.tone === "user"
|
|
49
50
|
? "userMessageText"
|
|
50
|
-
:
|
|
51
|
+
: isPurple
|
|
51
52
|
? "customMessageText"
|
|
52
53
|
: "assistantMessageText";
|
|
53
54
|
const bodyLines = (sourceLines.length > 0 ? sourceLines : [""]).map((line) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-frame.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-frame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAwB,MAAM,gBAAgB,CAAC;AAIvE,SAAS,mBAAmB,CAAC,KAAe;IAC3C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IACvB,OAAO,KAAK,GAAG,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,KAAK,EAAE,CAAC;IAChE,OAAO,GAAG,GAAG,KAAK,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,GAAG,EAAE,CAAC;IAChE,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,eAAe,CAC9B,YAAsB,EACtB,KAAa,EACb,IA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CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5E,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,OAAO;QACN,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC7C,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC;QACjC,GAAG,SAAS;KACZ,CAAC;AACH,CAAC","sourcesContent":["import { truncateToWidth, visibleWidth } from \"@gsd/pi-tui\";\nimport { theme } from \"../theme/theme.js\";\nimport { formatTimestamp, type TimestampFormat } from \"./timestamp.js\";\n\ntype FrameTone = \"assistant\" | \"user\" | \"compaction\" | \"skill\";\n\nfunction trimOuterBlankLines(lines: string[]): string[] {\n\tlet start = 0;\n\tlet end = lines.length;\n\twhile (start < end && lines[start].trim().length === 0) start++;\n\twhile (end > start && lines[end - 1].trim().length === 0) end--;\n\treturn lines.slice(start, end);\n}\n\nexport function renderChatFrame(\n\tcontentLines: string[],\n\twidth: number,\n\topts: {\n\t\tlabel: string;\n\t\ttone: FrameTone;\n\t\ttimestamp?: number;\n\t\ttimestampFormat: TimestampFormat;\n\t\tshowTimestamp?: boolean;\n\t},\n): string[] {\n\tconst outerWidth = Math.max(20, width);\n\tconst contentWidth = Math.max(1, outerWidth - 2); // \"│ \" + content\n\tconst isPurple = opts.tone === \"compaction\" || opts.tone === \"skill\";\n\tconst borderColor =\n\t\topts.tone === \"user\"\n\t\t\t? \"border\"\n\t\t\t: isPurple\n\t\t\t\t? \"customMessageLabel\"\n\t\t\t\t: \"borderAccent\";\n\tconst borderMuted = isPurple ? \"customMessageLabel\" : \"borderMuted\";\n\tconst border = (s: string) => theme.fg(borderColor, s);\n\tconst leftRaw = `• ${opts.label}`;\n\tconst rightRaw =\n\t\topts.showTimestamp === false || !opts.timestamp\n\t\t\t? \"\"\n\t\t\t: formatTimestamp(opts.timestamp, opts.timestampFormat);\n\n\tconst leftBudget = rightRaw\n\t\t? Math.max(1, outerWidth - visibleWidth(rightRaw) - 1)\n\t\t: outerWidth;\n\tconst left = truncateToWidth(leftRaw, leftBudget, \"\");\n\tconst labelColor =\n\t\topts.tone === \"user\"\n\t\t\t? \"border\"\n\t\t\t: isPurple\n\t\t\t\t? \"customMessageLabel\"\n\t\t\t\t: \"borderAccent\";\n\tconst dashIdx = left.indexOf(\" - \");\n\tconst leftStyled =\n\t\tdashIdx >= 0\n\t\t\t? theme.fg(labelColor, theme.bold(left.slice(0, dashIdx))) +\n\t\t\t\ttheme.fg(\"dim\", left.slice(dashIdx))\n\t\t\t: theme.fg(labelColor, theme.bold(left));\n\tconst rightStyled = rightRaw ? theme.fg(\"dim\", rightRaw) : \"\";\n\tconst gap =\n\t\trightRaw.length > 0\n\t\t\t? Math.max(\n\t\t\t\t\t1,\n\t\t\t\t\touterWidth - visibleWidth(leftStyled) - visibleWidth(rightStyled),\n\t\t\t\t)\n\t\t\t: Math.max(0, outerWidth - visibleWidth(leftStyled));\n\tconst headerRow = `${leftStyled}${\" \".repeat(gap)}${rightStyled}`;\n\tconst headerPad = Math.max(0, outerWidth - visibleWidth(headerRow));\n\n\tconst sourceLines = trimOuterBlankLines(contentLines);\n\tconst bodyColor =\n\t\topts.tone === \"user\"\n\t\t\t? \"userMessageText\"\n\t\t\t: isPurple\n\t\t\t\t? \"customMessageText\"\n\t\t\t\t: \"assistantMessageText\";\n\tconst bodyLines = (sourceLines.length > 0 ? sourceLines : [\"\"]).map((line) => {\n\t\tconst clipped = truncateToWidth(line, contentWidth, \"\");\n\t\treturn border(\"│ \") + theme.fg(bodyColor, clipped);\n\t});\n\n\treturn [\n\t\ttheme.fg(borderMuted, \"─\".repeat(outerWidth)),\n\t\theaderRow + \" \".repeat(headerPad),\n\t\t...bodyLines,\n\t];\n}\n"]}
|
package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-manager.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/provider-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,SAAS,EACT,KAAK,SAAS,EAId,KAAK,GAAG,EACR,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAGjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAYrE,qBAAa,wBAAyB,SAAQ,SAAU,YAAW,SAAS;IAC3E,OAAO,CAAC,QAAQ,CAAS;IACzB,IAAI,OAAO,IAAI,OAAO,CAErB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAEzB;IAED,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,cAAc,CAAY;gBAGjC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,IAAI,EAClB,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EACtC,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI;IA8BzC,OAAO,CAAC,aAAa;
|
|
1
|
+
{"version":3,"file":"provider-manager.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/provider-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,SAAS,EACT,KAAK,SAAS,EAId,KAAK,GAAG,EACR,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAGjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAYrE,qBAAa,wBAAyB,SAAQ,SAAU,YAAW,SAAS;IAC3E,OAAO,CAAC,QAAQ,CAAS;IACzB,IAAI,OAAO,IAAI,OAAO,CAErB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAEzB;IAED,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,cAAc,CAAY;gBAGjC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,IAAI,EAClB,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EACtC,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI;IA8BzC,OAAO,CAAC,aAAa;IAoCrB,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,WAAW;IAmBnB,OAAO,CAAC,UAAU;IA0BlB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAoDlC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Shows providers with auth status, discovery support, and model counts.
|
|
4
4
|
*/
|
|
5
5
|
import { Container, getEditorKeybindings, Spacer, Text, } from "@gsd/pi-tui";
|
|
6
|
-
import { getDiscoverableProviders } from "../../../core/model-discovery.js";
|
|
6
|
+
import { getDiscoverableProviders, getDiscoveryAdapter } from "../../../core/model-discovery.js";
|
|
7
7
|
import { providerDisplayName } from "./model-selector.js";
|
|
8
8
|
import { ModelsJsonWriter } from "../../../core/models-json-writer.js";
|
|
9
9
|
import { theme } from "../theme/theme.js";
|
|
@@ -57,12 +57,18 @@ export class ProviderManagerComponent extends Container {
|
|
|
57
57
|
]);
|
|
58
58
|
this.providers = Array.from(providerNames)
|
|
59
59
|
.sort()
|
|
60
|
-
.map((name) =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
.map((name) => {
|
|
61
|
+
const providerApis = new Set(allModels
|
|
62
|
+
.filter((m) => m.provider === name)
|
|
63
|
+
.map((m) => m.api)
|
|
64
|
+
.filter((api) => typeof api === "string" && api.length > 0));
|
|
65
|
+
return {
|
|
66
|
+
name,
|
|
67
|
+
hasAuth: this.authStorage.hasAuth(name),
|
|
68
|
+
supportsDiscovery: discoverableSet.has(name) || getDiscoveryAdapter(name, providerApis).supportsDiscovery,
|
|
69
|
+
modelCount: providerModelCounts.get(name) ?? 0,
|
|
70
|
+
};
|
|
71
|
+
});
|
|
66
72
|
this.clampSelectedIndex();
|
|
67
73
|
}
|
|
68
74
|
clampSelectedIndex() {
|