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(agent-runtime): route OpenCode Go Claude through Anthropic
vastsae4ef8440370d
diff --git a/docs/spec/03-runtime/11-provider-model-system.md b/docs/spec/03-runtime/11-provider-model-system.mdindex 43877f798..87c439b1c 100644--- a/docs/spec/03-runtime/11-provider-model-system.md+++ b/docs/spec/03-runtime/11-provider-model-system.md@@ -711,6 +711,13 @@ adapter instead of Chat Completions. Foreign catalog wire APIs (such asrelay) do not replace the provider's configured wire style (issue #1310).Without a model-level pin the provider-wide style applies.+The built-in OpenCode Go row is a documented exception for catalog entries that+publish a distinct Anthropic Messages route. For a models.dev Claude entry whose+`api` is `anthropic_messages` and whose `baseUrl` is the OpenCode Anthropic root,+agent-runtime uses that catalog API/base URL pair and reaches `/v1/messages`.+This exception is limited to the named OpenCode Go preset; custom endpoints and+foreign relay matches continue to use their saved provider API and base URL.+This is the **universal escape hatch** guaranteeing market coverage beyond native integrations.### 16.1 Responses stream termination (pi-ai patch)diff --git a/docs/spec/03-runtime/13-model-catalog-and-selection.md b/docs/spec/03-runtime/13-model-catalog-and-selection.mdindex 5bc62ea30..1678ab13d 100644--- a/docs/spec/03-runtime/13-model-catalog-and-selection.md+++ b/docs/spec/03-runtime/13-model-catalog-and-selection.md@@ -77,6 +77,11 @@ entitled to it.API style is the selected gateway format and takes precedence over a model'spublished adapter; named and OAuth providers may keep a model-level wire APIpin when their catalog requires it.+- The built-in OpenCode Go preset also honors a models.dev Claude entry's+ explicit `anthropic_messages` API and distinct Anthropic `baseUrl` together;+ the runtime then reaches the catalog route's `/v1/messages` endpoint. Custom+ endpoints and foreign relay matches keep their saved provider API and base+ URL.- A custom model ID is always accepted, so a gateway without a `/models` routestays usable.diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex f5db95ea1..4277e004a 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -1359,6 +1359,27 @@ identify the platform validation still needed.- **Milestone**: M2- **Status**: Unit-covered (binding resolution and endpoint assertion)+#### E2E-005K: OpenCode Go Claude models use the published Anthropic route++- **Preconditions**: An OpenCode Go provider uses the built-in preset. The+ deterministic catalog fixture contains `claude-haiku-5-5` with+ `api: "anthropic_messages"` and an OpenCode Anthropic root `baseUrl`, plus a+ DeepSeek Chat Completions control model.+- **Steps**: 1) Select Claude Haiku and send a text turn through a capture+ fixture. 2) Capture the request URL and adapter payload. 3) Repeat with the+ DeepSeek control model. 4) Repeat with the same catalog metadata on a custom+ OpenAI-compatible provider.+- **Expected**: OpenCode Claude uses the Anthropic adapter and posts to+ `/zen/go/v1/messages`; it does not post Chat Completions and does not return+ `ModelProtocolUnsupported`. DeepSeek keeps `/chat/completions`. The custom+ provider keeps its saved wire style and base URL despite the foreign catalog+ API. Unit coverage lives in `packages/agent-runtime/src/provider-binding.test.ts`.+- **Specs linked**: `03-runtime/11-provider-model-system.md`,+ `03-runtime/13-model-catalog-and-selection.md`, issue #1728+- **Acceptance**: F (runtime provider requests)+- **Milestone**: M2+- **Status**: Unit-covered; live endpoint scenario Draft+#### E2E-005C: OpenAI-compatible system role fallback- **Preconditions**: A deterministic OpenAI-compatible Chat Completionsdiff --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 dec4160c9..31ea7fd85 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@@ -593,6 +593,8 @@ UI 可能会显示层级提示,但默认情况下不得硬阻止未知模型目录条目还可以额外固定模型级 wire API(例如 `api: "openai-responses"`)。当该 API 与 provider 的协议族兼容时,它优先于 provider 级 `apiStyle`(因此 `opencode_go` 下的 responses-only 模型会走 Responses adapter 而非 Chat Completions)。外部 catalog 的异构 wire API(例如 relay 端点上匹配到的 `google-generative-ai` 或 `anthropic-messages`)不会覆盖 OpenAI-compatible provider 配置的 wire style(issue #1310);没有模型级固定时保持 provider 级风格不变。+对于内置 OpenCode Go 行,目录条目若明确发布独立的 Anthropic Messages 路由,则有一个文档化例外:models.dev 的 Claude 条目同时声明 `api: "anthropic_messages"` 和 OpenCode Anthropic 根 `baseUrl` 时,agent-runtime 使用这组目录 API 与地址,最终访问 `/v1/messages`。该例外只适用于命名的 OpenCode Go 预设;自定义端点和外部 relay 匹配到的目录记录仍使用保存的 provider API 与 Base URL。+### 16.1 Responses 流终止(pi-ai 补丁)OpenAI Responses 适配器会把 `response.completed` 和diff --git a/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md b/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.mdindex e8a271b8b..25de1e960 100644--- a/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md+++ b/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md@@ -14,6 +14,11 @@3.兼容OpenAI的网关是一流的4. 搜索是跨启用的提供商的全局搜索+内置 OpenCode Go 预设还会同时遵循 models.dev Claude 条目明确声明的+`anthropic_messages` API 与独立 Anthropic `baseUrl`;运行时随后访问该目录线路的+`/v1/messages` 端点。自定义端点和外部 relay 匹配结果仍保留保存的 provider API 与+Base URL。+## 2. 选择用户体验### 模型选择器字段diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex a399bccf7..39a370cad 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -493,6 +493,24 @@ task-candidate E2E 从请求工作树运行,但使用主工作区已经准备- **里程碑**:M2- **状态**:单元覆盖(行级模型标头、请求上下文标头、Anthropic Messages Bearer 认证与令牌轮换);真实 Copilot 账户旅程待验证+#### E2E-005K:OpenCode Go Claude 模型使用目录发布的 Anthropic 线路++- **前提条件**:使用内置预设配置 OpenCode Go;确定性目录 fixture 包含+ `claude-haiku-5-5`,其声明 `api: "anthropic_messages"` 和 OpenCode Anthropic+ 根 `baseUrl`,另有一个 DeepSeek Chat Completions 对照模型。+- **步骤**:1)选择 Claude Haiku,通过捕获 fixture 发送文本回合。2)记录请求 URL+ 和适配器请求体。3)换成 DeepSeek 对照模型重复。4)将相同目录元数据放到自定义+ OpenAI 兼容提供商上重复。+- **预期**:OpenCode Claude 使用 Anthropic 适配器并访问 `/zen/go/v1/messages`,不再+ 发往 Chat Completions,也不返回 `ModelProtocolUnsupported`。DeepSeek 保持+ `/chat/completions`。自定义提供商即使匹配到外部目录 API,仍使用保存的 wire 格式与+ Base URL。单元覆盖位于 `packages/agent-runtime/src/provider-binding.test.ts`。+- **链接规格**:`03-runtime/11-provider-model-system.md`、+ `03-runtime/13-model-catalog-and-selection.md`、issue #1728+- **验收**:F(运行时提供商请求)+- **里程碑**:M2+- **状态**:单元覆盖;真实端点场景草稿+#### E2E-MODELS-list-layout:受限窗口中的模型列表可完整浏览- **前置条件:** 60 个已发现并配置的模型;隔离的 Electron 环境使用真实diff --git a/packages/agent-runtime/src/provider-binding.test.ts b/packages/agent-runtime/src/provider-binding.test.tsindex 77a28a332..d47396951 100644--- a/packages/agent-runtime/src/provider-binding.test.ts+++ b/packages/agent-runtime/src/provider-binding.test.ts@@ -1219,6 +1219,52 @@ describe("buildProviderModel model-level wire API", () => {expect(claudeRelay.api).toBe("openai-completions");});+ it("routes OpenCode Go Claude models through the catalog Anthropic endpoint (issue #1728)", async () => {+ const provider: RuntimeProviderConfig = {+ ...keyedProvider,+ id: "opencode-go",+ name: "OpenCode Go",+ vendorKey: "opencode-go",+ baseUrl: "https://opencode.ai/zen/go/v1",+ modelId: "claude-haiku-5-5",+ apiStyle: "opencode_go",+ modelConfig: {+ source: "models.dev",+ name: "Claude Haiku 5.5",+ baseUrl: "https://opencode.ai/zen/go",+ api: "anthropic_messages",+ reasoning: true,+ input: ["text"],+ contextWindow: 200_000,+ maxTokens: 64_000,+ },+ };+ const model = buildProviderModel(provider);+ expect(model.api).toBe("anthropic-messages");+ expect(model.baseUrl).toBe("https://opencode.ai/zen/go");++ const urls: string[] = [];+ const fetch = vi.fn(async (input: RequestInfo | URL) => {+ urls.push(input instanceof Request ? input.url : String(input));+ return new Response("bad gateway", { status: 502 });+ });+ const result = await createProviderModels(provider, model)+ .streamSimple(+ model,+ {+ systemPrompt: "system",+ messages: [{ role: "user", content: "hello", timestamp: Date.now() }],+ tools: [],+ },+ { fetch },+ )+ .result();++ expect(result.stopReason).toBe("error");+ expect(urls).toHaveLength(1);+ expect(new URL(urls[0]).pathname).toBe("/zen/go/v1/messages");+ });+it("posts responses models to the responses endpoint", async () => {const provider = responsesCatalogProvider;const model = buildProviderModel(provider);diff --git a/packages/agent-runtime/src/provider-binding.ts b/packages/agent-runtime/src/provider-binding.tsindex c847a5536..a7ef03a38 100644--- a/packages/agent-runtime/src/provider-binding.ts+++ b/packages/agent-runtime/src/provider-binding.ts@@ -231,6 +231,15 @@ function providerRequestTransport(provider: RuntimeProviderConfig) {const resolvedProviderStyle = resolveApiStyle(provider.apiStyle);const providerStyle = resolvedProviderStyle ?? (provider.apiStyle ? normalizeApiStyle(provider.apiStyle) : undefined);const customEndpoint = provider.vendorKey?.trim().toLowerCase() === "custom";+ const catalogBaseUrl =+ provider.modelConfig?.source === "models.dev" ? provider.modelConfig.baseUrl : undefined;+ const openCodeCatalogRoute =+ provider.vendorKey?.trim().toLowerCase() === "opencode-go" &&+ providerStyle === OPENCODE_GO_API_STYLE &&+ catalogBaseUrl !== undefined &&+ modelStyle === "anthropic_messages" &&+ catalogBaseUrl.trim().replace(/\/+$/, "").toLowerCase() !==+ provider.baseUrl?.trim().replace(/\/+$/, "").toLowerCase();const isOpenAiStyle = (style: string | undefined) =>style === "chat_completions" ||style === "responses" ||@@ -248,10 +257,13 @@ function providerRequestTransport(provider: RuntimeProviderConfig) {// but foreign catalog protocols must not replace the provider's wire style.const apiStyle = customEndpoint? provider.apiStyle ?? modelStyle- : (isCompatible ? modelStyle : undefined) ?? provider.apiStyle;+ : (openCodeCatalogRoute || isCompatible ? modelStyle : undefined) ?? provider.apiStyle;+ const baseUrl = openCodeCatalogRoute && catalogBaseUrl+ ? catalogBaseUrl+ : provider.baseUrl ?? provider.modelConfig?.baseUrl ?? apiBindingForStyle(apiStyle).defaultBaseUrl;return nativeWebSearchTransport({apiStyle,- baseUrl: provider.baseUrl ?? provider.modelConfig?.baseUrl ?? apiBindingForStyle(apiStyle).defaultBaseUrl,+ baseUrl,enabled: provider.modelConfig?.webSearch === true,});}