Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): honor Pi Anthropic utility routes
tiammomo7a35ce9fb9fc
diff --git a/apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.ts b/apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.tsindex 7bfac0bfed..6ac57261db 100644--- a/apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.ts+++ b/apps/desktop/src/main/utility-model/__tests__/oneShotCandidates.test.ts@@ -498,6 +498,68 @@ describe('utility one-shot candidates', () => {});});+ it('uses Anthropic Messages for an explicitly selected pi anthropic-messages provider', async () => {+ activeCatalog.mockReturnValue({+ providers: [+ {+ id: 'pi-anthropic-only',+ name: 'Pi Anthropic Only',+ source: 'user',+ agents: ['pi'],+ auth: { method: 'apiKey' },+ routing: {+ pi: {+ upstream: 'https://anthropic-only.example/v1',+ wireProtocol: 'anthropic-messages',+ authStrategy: 'api-key-header',+ },+ },+ models: {+ pi: [{ id: 'pi-anthropic-model', name: 'Pi Anthropic Model', contextWindow: 100_000 }],+ },+ },+ ],+ } as never);+ readCustomKey.mockReturnValue('pi-secret');+ fetchMock.mockResolvedValueOnce({+ ok: true,+ text: async () =>+ JSON.stringify({+ content: [{ type: 'text', text: 'review decision' }],+ }),+ } as never);++ const result = await requestUtilityText(makerMock(false), 'review this action', {+ providerId: 'pi-anthropic-only',+ agentKind: 'pi',+ model: 'pi-anthropic-model',+ maxTokens: 256,+ });++ expect(result).toMatchObject({+ ok: true,+ text: 'review decision',+ providerId: 'pi-anthropic-only',+ });+ expect(fetchMock).toHaveBeenCalledWith(+ 'https://anthropic-only.example/v1/messages',+ expect.anything(),+ );+ expect(fetchMock).toHaveBeenCalledTimes(1);+ const init = fetchMock.mock.calls[0]?.[1] as { body: string; headers: Record<string, string> };+ expect(init.headers).toMatchObject({+ Authorization: 'Bearer pi-secret',+ 'Content-Type': 'application/json',+ 'anthropic-version': '2023-06-01',+ 'x-api-key': 'pi-secret',+ });+ expect(JSON.parse(init.body)).toEqual({+ model: 'pi-anthropic-model',+ max_tokens: 256,+ messages: [{ role: 'user', content: 'review this action' }],+ });+ });+it.each([{wireProtocol: 'openai-chat' as const,diff --git a/apps/desktop/src/main/utility-model/oneShotCandidates.ts b/apps/desktop/src/main/utility-model/oneShotCandidates.tsindex 3462bcc59b..08b09e59df 100644--- a/apps/desktop/src/main/utility-model/oneShotCandidates.ts+++ b/apps/desktop/src/main/utility-model/oneShotCandidates.ts@@ -1141,6 +1141,12 @@ async function requestCustomProviderText(input: {...(input.headers ?? {}),'Content-Type': 'application/json',};+ const wire: ProviderWire =+ input.agentKind === 'claude-code' || input.wireProtocol === 'anthropic-messages'+ ? 'anthropic-messages'+ : input.wireProtocol === 'openai-chat'+ ? 'chat-completions'+ : 'responses';// safeStorage 有当前凭证时覆盖历史 header;没有时仅 api-key 策略允许保留旧版// header-only 配置,以便用户升级后继续可用。OAuth 与 none 仍必须清掉复制进来的凭证头。const preserveLegacyApiKeyHeaders =@@ -1153,19 +1159,13 @@ async function requestCustomProviderText(input: {}if (input.credential) {headers.Authorization = `Bearer ${input.credential}`;- if (input.agentKind === 'claude-code' && input.authStrategy === 'api-key-header') {+ if (wire === 'anthropic-messages' && input.authStrategy === 'api-key-header') {headers['x-api-key'] = input.credential;}}- if (input.agentKind === 'claude-code') {+ if (wire === 'anthropic-messages') {headers['anthropic-version'] = headers['anthropic-version'] ?? '2023-06-01';}- const wire: ProviderWire =- input.agentKind === 'claude-code'- ? 'anthropic-messages'- : input.wireProtocol === 'openai-chat'- ? 'chat-completions'- : 'responses';return requestProviderHttpText({wire,endpoint: input.requestPath