Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(catalog): keep Anthropic thinking shape for unidentified gateways
renwangad174c625bbdf
diff --git a/apps/desktop/electron/main/index.ts b/apps/desktop/electron/main/index.tsindex f6e02fb1f..c581b1d63 100644--- a/apps/desktop/electron/main/index.ts+++ b/apps/desktop/electron/main/index.ts@@ -685,7 +685,6 @@ const providerCatalogRuntime = createProviderCatalogRuntime({});const {bindingForModel,- modelsDevModelFor,effectiveSubagentModelConfig,enrichProvider,enrichProviderList,@@ -709,7 +708,6 @@ const createdSessionLaunchRuntime = createSessionLaunchRuntime({getWorkspacePath: currentWorkspacePath,pluginActiveInProject,bindingForModel,- modelsDevModelFor,effectiveSubagentModelConfig,normalizeThinkingLevel,});diff --git a/apps/desktop/electron/main/models-dev-catalog.ts b/apps/desktop/electron/main/models-dev-catalog.tsindex df2875ebd..039dbbe8b 100644--- a/apps/desktop/electron/main/models-dev-catalog.ts+++ b/apps/desktop/electron/main/models-dev-catalog.ts@@ -13,7 +13,7 @@ import type {ModelReasoningOption,ThinkingLevel,} from "@pi-desktop/shared";-import type { ModelConfig } from "@pi-desktop/agent-runtime";+import { genericModelConfig, type ModelConfig } from "@pi-desktop/agent-runtime";export const MODELS_DEV_API_URL = "https://models.dev/api.json";export const MODELS_DEV_TIMEOUT_MS = 10_000;@@ -760,6 +760,32 @@ export function modelConfigFromModelsDev(if (model.modelApi !== undefined) config.api = model.modelApi;return config;}++/**+ * Sidecar model config for one provider row: the catalog record when the+ * lookup resolves one, otherwise the generic shape.+ *+ * An Anthropic Messages row the catalog cannot identify (a custom gateway URL+ * serving an id several publishers list) still needs the right thinking wire+ * shape: Opus 4.7+ and the Claude 5 family reject budget thinking with a 400.+ * Whether a Claude id takes adaptive or budget thinking is a property of the+ * model, which Anthropic's own record states, not of the deployment. So only+ * the exact Anthropic id's reasoning options transfer; limits and modalities+ * stay generic because they describe the deployment (#990).+ */+export function catalogModelConfigFor(+ catalog: Pick<ModelsDevCatalog, "findModel" | "anthropicThinkingFor">,+ input: { vendorKey?: string; baseUrl?: string; apiStyle?: string; modelId: string },+): ModelConfig {+ const model = catalog.findModel(input);+ if (model) return modelConfigFromModelsDev(model, input.baseUrl);+ const generic = genericModelConfig(input.modelId, input.baseUrl ?? "");+ const thinking = input.apiStyle === "anthropic_messages"+ ? catalog.anthropicThinkingFor(input.modelId)+ : undefined;+ return thinking ? { ...generic, ...thinking } : generic;+}+type IndexedModel = { model: ModelsDevModel; provider: ModelsDevProvider };/**@@ -1179,6 +1205,29 @@ export class ModelsDevCatalog {return borrowedModel(matches);}+ /**+ * Thinking wire metadata Anthropic publishes for exactly this id, or nothing.+ * Aliases and other publishers' copies never answer: only Anthropic's own+ * record states which thinking shape a Claude model accepts.+ */+ anthropicThinkingFor(+ modelId: string,+ ): Pick<ModelConfig, "reasoningOptions" | "thinkingLevelMap"> | undefined {+ const requested = normalizedModelId(modelId);+ const model = this.providers.get("anthropic")?.models.find(+ (candidate) => normalizedModelId(candidate.modelId) === requested,+ );+ if (!model?.reasoning || !model.reasoningOptions?.length) return undefined;+ const thinkingLevelMap = thinkingLevelMapFromModelsDev(+ model.reasoningOptions,+ model.thinkingLevels,+ );+ return {+ reasoningOptions: model.reasoningOptions,+ ...(thinkingLevelMap ? { thinkingLevelMap } : {}),+ };+ }+modelsForProvider(input: { vendorKey?: string; baseUrl?: string; providerId: string }): ModelInfo[] {const preferredProvider = this.providerFor(input);const providers = preferredProviderdiff --git a/apps/desktop/electron/main/runtime/session-launch.ts b/apps/desktop/electron/main/runtime/session-launch.tsindex c6dd83c0a..2409c687f 100644--- a/apps/desktop/electron/main/runtime/session-launch.ts+++ b/apps/desktop/electron/main/runtime/session-launch.ts@@ -33,7 +33,7 @@ import {import { builtinSkills } from "../builtin-skills";import { OAUTH_AUTH_KIND, type VendorOAuth } from "../oauth";import {- modelConfigFromModelsDev,+ catalogModelConfigFor,type ModelsDevCatalog,} from "../models-dev-catalog";import type { HostProcess } from "../host-process";@@ -69,10 +69,6 @@ export type SessionLaunchRuntimeDependencies = {provider: Pick<RuntimeProvider, "models">,modelId: string,) => ModelBinding | undefined;- modelsDevModelFor: (- provider: RuntimeProvider,- modelId: string,- ) => ReturnType<ModelsDevCatalog["findModel"]>;effectiveSubagentModelConfig: (provider: Pick<RuntimeProvider, "models">,modelId: string,@@ -96,7 +92,6 @@ export function createSessionLaunchRuntime({getWorkspacePath,pluginActiveInProject,bindingForModel,- modelsDevModelFor,effectiveSubagentModelConfig,normalizeThinkingLevel,}: SessionLaunchRuntimeDependencies) {@@ -354,11 +349,13 @@ export function createSessionLaunchRuntime({const storedModel = bindingForModel(provider, modelId);const apiStyle = vendorBinding?.apiStyle ?? provider.apiStyle;const baseUrl = vendorBinding?.baseUrl ?? provider.baseUrl;- const modelsDevModel = modelsDevModelFor(provider, modelId);const catalogModelConfig = vendorBinding?.modelConfig ??- (modelsDevModel- ? modelConfigFromModelsDev(modelsDevModel, baseUrl)- : genericModelConfig(modelId, baseUrl ?? ""));+ catalogModelConfigFor(modelsDevCatalog, {+ vendorKey: provider.vendorKey,+ baseUrl,+ apiStyle,+ modelId,+ });const resolvedLimits = resolveBindingContextWindow(catalogModelConfig, storedModel);const modelConfig = modelConfigWithBinding(resolvedLimits.catalogConfig,@@ -485,14 +482,12 @@ export function createSessionLaunchRuntime({resolveVendorBinding: (pinned, pinnedModelId) =>vendorOAuth.bindingFor(pinned.id, pinnedModelId),resolveModel: async (pinned, pinnedModelId) => {- const model = modelsDevCatalog.findModel({+ const catalogModelConfig = catalogModelConfigFor(modelsDevCatalog, {vendorKey: pinned.vendorKey,baseUrl: pinned.baseUrl,+ apiStyle: pinned.apiStyle,modelId: pinnedModelId,});- const catalogModelConfig = model- ? modelConfigFromModelsDev(model, pinned.baseUrl)- : genericModelConfig(pinnedModelId, pinned.baseUrl ?? "");const configuredProvider = providers.providers.find((candidate) => candidate.id === pinned.id,);@@ -550,14 +545,12 @@ export function createSessionLaunchRuntime({catalogModelConfig =vb.modelConfig ?? genericModelConfig(binding.id, vb.baseUrl ?? row.baseUrl ?? "");} else {- const model = modelsDevCatalog.findModel({+ catalogModelConfig = catalogModelConfigFor(modelsDevCatalog, {vendorKey: row.vendorKey,baseUrl: row.baseUrl,+ apiStyle: row.apiStyle,modelId: binding.id,});- catalogModelConfig = model- ? modelConfigFromModelsDev(model, row.baseUrl)- : genericModelConfig(binding.id, row.baseUrl ?? "");}const effective = effectiveSubagentModelConfig(row,diff --git a/apps/desktop/electron/main/runtime/sidecar.ts b/apps/desktop/electron/main/runtime/sidecar.tsindex d978656fd..4d7e26a3f 100644--- a/apps/desktop/electron/main/runtime/sidecar.ts+++ b/apps/desktop/electron/main/runtime/sidecar.ts@@ -10,7 +10,7 @@ import { loadBuiltinSkillBody } from "../builtin-skills";import { createImageGenerationTool } from "../services/image-generation-service";import { registerPluginDevTools } from "../plugin-dev-tools";import { resolveLocalFile } from "../browser-view";-import { modelConfigFromModelsDev } from "../models-dev-catalog";+import { catalogModelConfigFor } from "../models-dev-catalog";import { AgentSidecar } from "../agent-sidecar";import { relaxedNetworkPolicyEnabled } from "../endpoint-policy";import { OAUTH_AUTH_KIND, type VendorOAuth } from "../oauth";@@ -441,14 +441,12 @@ export function createSidecarRuntime({vendorBinding.modelConfig ??genericModelConfig(modelId, vendorBinding.baseUrl ?? provider.baseUrl ?? "");} else {- const model = modelsDevCatalog.findModel({+ catalogModelConfig = catalogModelConfigFor(modelsDevCatalog, {vendorKey: provider.vendorKey,baseUrl: provider.baseUrl,+ apiStyle: provider.apiStyle,modelId,});- catalogModelConfig = model- ? modelConfigFromModelsDev(model, provider.baseUrl)- : genericModelConfig(modelId, provider.baseUrl ?? "");}const { modelConfig, capabilities } = effectiveSubagentModelConfig(provider,diff --git a/apps/desktop/test/custom-system-prompt-launch.test.mjs b/apps/desktop/test/custom-system-prompt-launch.test.mjsindex edc4311da..593135e62 100644--- a/apps/desktop/test/custom-system-prompt-launch.test.mjs+++ b/apps/desktop/test/custom-system-prompt-launch.test.mjs@@ -47,7 +47,6 @@ function launchRuntime() {modelsDevCatalog: { ensureLoaded: async () => {}, findModel: () => undefined },getWorkspacePath: () => workspace, pluginActiveInProject: () => true,bindingForModel: (row, id) => row.models.find((m) => m.id === id),- modelsDevModelFor: () => undefined,effectiveSubagentModelConfig: () => ({}),normalizeThinkingLevel: () => "off",});diff --git a/apps/desktop/test/models-dev-catalog.test.mjs b/apps/desktop/test/models-dev-catalog.test.mjsindex 9554e141c..6ce44d51f 100644--- a/apps/desktop/test/models-dev-catalog.test.mjs+++ b/apps/desktop/test/models-dev-catalog.test.mjs@@ -9,6 +9,7 @@ import { apiStyleForAdapter, catalogModelIdsMatch, modelIdsMatch } from "@pi-desimport {MODELS_DEV_API_URL,ModelsDevCatalog,+ catalogModelConfigFor,modelConfigFromModelsDev,modelInfoFromModelsDev,parseModelsDevCatalog,@@ -1301,3 +1302,125 @@ test("the wire API style is derived from the published adapter package", () => {assert.equal(apiStyleForAdapter("@ai-sdk/openai-compatible"), "chat_completions");assert.equal(apiStyleForAdapter(undefined), "chat_completions");});++// A custom Anthropic Messages gateway (unknown base URL, vendorKey "custom")+// serving a Claude id that several catalog providers publish with differing+// reasoning options. The lookup refuses to pick one publisher, but the thinking+// wire shape of an exact Anthropic id is Anthropic's own (#990).+const ambiguousClaudeFixture = {+ anthropic: {+ name: "Anthropic",+ npm: "@ai-sdk/anthropic",+ models: {+ "claude-opus-5-5": {+ id: "claude-opus-5-5",+ name: "Claude Opus 5.5",+ reasoning: true,+ reasoning_options: [{ type: "effort", values: ["low", "medium", "high", "xhigh", "max"] }],+ tool_call: true,+ modalities: { input: ["text", "image"], output: ["text"] },+ limit: { context: 1_000_000, output: 128_000 },+ },+ },+ },+ requesty: {+ name: "Requesty",+ npm: "@ai-sdk/openai-compatible",+ api: "https://router.requesty.ai/v1",+ models: {+ "claude-opus-5-5": {+ id: "claude-opus-5-5",+ name: "Claude Opus 5.5",+ reasoning: true,+ reasoning_options: [+ { type: "effort", values: ["none", "low", "medium", "high", "max"] },+ { type: "budget_tokens" },+ ],+ tool_call: true,+ modalities: { input: ["text"], output: ["text"] },+ limit: { context: 200_000, output: 64_000 },+ },+ "glm-5": {+ id: "glm-5",+ name: "GLM 5",+ reasoning: true,+ reasoning_options: [{ type: "effort", values: ["low", "high"] }],+ tool_call: true,+ modalities: { input: ["text"], output: ["text"] },+ limit: { context: 200_000, output: 32_000 },+ },+ },+ },+};++const customGateway = {+ vendorKey: "custom",+ baseUrl: "https://gateway.example/v1",+};++test("a custom Anthropic gateway takes Anthropic's thinking options for an exact Claude id", async (t) => {+ const catalog = await loadFixtureCatalog(t, ambiguousClaudeFixture);+ const config = catalogModelConfigFor(catalog, {+ ...customGateway,+ apiStyle: "anthropic_messages",+ modelId: "claude-opus-5-5",+ });++ // The ambiguous record itself is still not borrowed: limits stay generic.+ assert.equal(config.source, "generic");+ assert.equal(config.contextWindow, 128_000);+ assert.equal(config.reasoning, false);+ // Only the thinking wire shape comes from the Anthropic record.+ assert.deepEqual(config.reasoningOptions, [+ { type: "effort", values: ["low", "medium", "high", "xhigh", "max"] },+ ]);+ assert.deepEqual(config.thinkingLevelMap, {+ low: "low",+ medium: "medium",+ high: "high",+ xhigh: "xhigh",+ max: "max",+ off: null,+ });+});++test("the Anthropic thinking fallback stays off other wire APIs and non-Claude ids", async (t) => {+ const catalog = await loadFixtureCatalog(t, ambiguousClaudeFixture);+ const completions = catalogModelConfigFor(catalog, {+ ...customGateway,+ apiStyle: "chat_completions",+ modelId: "claude-opus-5-5",+ });+ assert.equal(completions.reasoningOptions, undefined);+ assert.equal(completions.thinkingLevelMap, undefined);++ // Anthropic publishes no glm-5, so an Anthropic-protocol GLM row is unchanged.+ const glm = catalogModelConfigFor(catalog, {+ ...customGateway,+ apiStyle: "anthropic_messages",+ modelId: "glm-5",+ });+ assert.equal(glm.source, "models.dev");+ assert.deepEqual(glm.reasoningOptions, [{ type: "effort", values: ["low", "high"] }]);++ // Aliases of a Claude id are not an exact Anthropic id.+ const renamed = catalogModelConfigFor(catalog, {+ ...customGateway,+ apiStyle: "anthropic_messages",+ modelId: "my-claude-opus-5-5-thinking",+ });+ assert.equal(renamed.reasoningOptions, undefined);+});++test("a resolved catalog record still wins over the Anthropic thinking fallback", async (t) => {+ const catalog = await loadFixtureCatalog(t, ambiguousClaudeFixture);+ const config = catalogModelConfigFor(catalog, {+ vendorKey: "requesty",+ baseUrl: "https://router.requesty.ai/v1",+ apiStyle: "anthropic_messages",+ modelId: "claude-opus-5-5",+ });+ assert.equal(config.source, "models.dev");+ assert.equal(config.contextWindow, 200_000);+ assert.ok(config.reasoningOptions?.some((option) => option.type === "budget_tokens"));+});diff --git a/apps/desktop/test/subagent-model-launch.test.mjs b/apps/desktop/test/subagent-model-launch.test.mjsindex 539aa562f..108f08420 100644--- a/apps/desktop/test/subagent-model-launch.test.mjs+++ b/apps/desktop/test/subagent-model-launch.test.mjs@@ -43,7 +43,6 @@ test("launch resolves definition-only pins without granting Task.model selectionmodelsDevCatalog: { ensureLoaded: async () => {}, findModel: () => undefined },getWorkspacePath: () => root, pluginActiveInProject: () => true,bindingForModel: (row, id) => row.models.find((m) => m.id === id),- modelsDevModelFor: () => undefined,effectiveSubagentModelConfig: (row, id, catalog) => {const modelConfig = modelConfigWithBinding(catalog, row.models.find((m) => m.id === id));return { modelConfig, capabilities: capabilitiesFromModelConfig(modelConfig) };diff --git a/apps/desktop/test/thinking-ui.test.mjs b/apps/desktop/test/thinking-ui.test.mjsindex 911ccc290..63b481673 100644--- a/apps/desktop/test/thinking-ui.test.mjs+++ b/apps/desktop/test/thinking-ui.test.mjs@@ -310,7 +310,8 @@ test("provider settings persist model-local limits and thinking configuration",});test("main forwards the complete models.dev model record to the sidecar", () => {- assert.match(sessionLaunchSource, /modelConfigFromModelsDev/);+ // catalogModelConfigFor returns modelConfigFromModelsDev for a resolved record.+ assert.match(sessionLaunchSource, /catalogModelConfigFor/);assert.doesNotMatch(sessionLaunchSource, /resolvePiModelConfig/);assert.match(sessionLaunchSource, /\.\.\.\(modelConfig \? \{ modelConfig \} : \{\}\)/);assert.doesNotMatch(sessionLaunchSource, /modelCompat/);diff --git a/docs/spec/03-runtime/11-provider-model-system.md b/docs/spec/03-runtime/11-provider-model-system.mdindex 47fb8b15d..b91712eea 100644--- a/docs/spec/03-runtime/11-provider-model-system.md+++ b/docs/spec/03-runtime/11-provider-model-system.md@@ -115,6 +115,16 @@ compat record, so without the flag pi-ai would fall back to budget thinking.Models that still publish `budget_tokens` keep budget thinking, and anexplicit catalog `compat` record is preserved.+An Anthropic Messages row the catalog cannot identify (for example a custom+gateway URL serving an id several publishers list) still falls back to the+generic model shape, but takes `reasoning_options` and the derived+`thinkingLevelMap` from Anthropic's own models.dev record when that record+has exactly the same model id. Which thinking shape a Claude id accepts is a+property of the model, not of the deployment, so only those two fields+transfer; limits and modalities stay generic, and aliases, renamed ids, other+wire APIs, and non-Claude ids served over the Anthropic protocol are unchanged+(#990).+## 5. Built-in vendor matrix (ship intent)> Model metadata follows the bundled/in-memory models.dev catalog. Provider adapters remaindiff --git a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md b/docs/zh-CN/spec/03-runtime/11-provider-model-system.mdindex 1df70ce1d..3cc5c6a55 100644--- a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md+++ b/docs/zh-CN/spec/03-runtime/11-provider-model-system.md@@ -109,6 +109,13 @@ pi-ai 去发出 `x-opencode-session`。每个提供商行(AI 服务或 OAuthpi-ai 会回落到 budget 思考。仍发布 `budget_tokens` 的模型保持 budget 思考,显式的目录 `compat` 记录会被保留。+目录无法识别的 Anthropic Messages 行(例如某个自定义网关 URL 提供多家发布方都列出的+模型 ID)仍回退到通用模型形状,但当 Anthropic 自己的 models.dev 记录中存在完全相同的+模型 ID 时,会采用该记录的 `reasoning_options` 及派生的 `thinkingLevelMap`。Claude+模型接受哪种思考形状是模型本身的属性,而非部署的属性,因此只迁移这两个字段;上下文与+模态限制保持通用值,别名、改名后的 ID、其他 wire API,以及通过 Anthropic 协议提供的+非 Claude 模型均不受影响(#990)。+## 5. 内置供应商矩阵(发货意图)> 确切的可用性取决于引脚版本的 pi-ai 支持;产品必须公开所有受支持的产品,并为其余产品保持与 OpenAI 兼容的路径开放。