Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): 按链路裁剪 Anthropic Messages 的 Pi compat 能力位,网关与订阅直连的 Claude 不再被 400 拒绝(#4982 #4983) (#4984)
FicoWangb0cfcfecc6fd
diff --git a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.tsindex f7c6e28aa6..a74ce15ac4 100644--- a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts@@ -44,6 +44,7 @@ import {resolvePiBundledModelById,resolvePiCindyGatewayModelApi,resolvePiCindyGatewayModelSpec,+ pruneAnthropicCompatForLink,type PiBundledModelInfo,} from '../pi-host.js';import { getActiveCatalog, setActiveCatalog, setDiscoveredCodexModels, setXdGatewayModels, setXaiDiscoveredModels, setLocalCatalogOverrides } from '../active-catalog.js';@@ -927,10 +928,13 @@ describe('buildPiNativeProvidersFromConfigs', () => {{ id: 'google/gemini-3.7-flash', agents: ['pi'] },]);- expect(resolvePiCindyGatewayModelSpec('xd', 'claude-opus-5')).toMatchObject({+ const gatewayClaude = resolvePiCindyGatewayModelSpec('xd', 'claude-opus-5');+ expect(gatewayClaude).toMatchObject({api: 'anthropic-messages',- compat: { forceAdaptiveThinking: true, supportsStrictTools: true },+ compat: { forceAdaptiveThinking: true },});+ // #4982: xd 网关的 Anthropic-Messages schema 不认 tools[].strict / tool_removal,按链路裁掉。+ expect(gatewayClaude?.compat).not.toHaveProperty('supportsStrictTools');expect(resolvePiCindyGatewayModelSpec('xd', 'gpt-5.6-sol')).toMatchObject({api: 'openai-responses',compat: {@@ -2766,3 +2770,51 @@ it('serializes mixed-protocol enterprise models with their own gateway base URLs);}});++describe('Anthropic compat per-link pruning (#4982 / #4983)', () => {+ const probedClaude = (id: string): PiBundledModelInfo => ({+ ...piBundledModel(id, 'anthropic-messages'),+ compat: {+ forceAdaptiveThinking: true,+ supportsStrictTools: true,+ supportsMidConvoToolChanges: true,+ supportsMidConvoEffort: true,+ supportsMidConvoSystemMessages: true,+ },+ });++ it('subscription direct link drops the MidConvo flags but keeps strict and mid-conv system messages', () => {+ const catalog = JSON.parse(JSON.stringify(BUNDLED_CATALOG)) as Catalog;+ const bundled = probedClaude('claude-opus-5');+ const { providers } = buildPiSubscriptionNativeProviders(+ catalog,+ 'http://127.0.0.1:4567/',+ new Map([['anthropic', new Map([['claude-opus-5', bundled]])]]),+ );+ const anthropic = providers.find((provider) => provider.id === 'anthropic');+ const model = anthropic?.models.find((candidate) => candidate.wireId === 'claude-opus-5');+ expect(model?.compat).toEqual({+ forceAdaptiveThinking: true,+ supportsStrictTools: true,+ supportsMidConvoSystemMessages: true,+ });+ // The probe catalog shared with other links must not be mutated.+ expect(bundled.compat).toMatchObject({ supportsMidConvoToolChanges: true, supportsMidConvoEffort: true });+ });++ it('gateway link additionally drops strict tools and never touches non-Anthropic APIs', () => {+ expect(pruneAnthropicCompatForLink({+ forceAdaptiveThinking: true,+ supportsStrictTools: true,+ supportsMidConvoToolChanges: true,+ supportsMidConvoEffort: true,+ supportsMidConvoSystemMessages: true,+ }, 'gateway')).toEqual({ forceAdaptiveThinking: true, supportsMidConvoSystemMessages: true });+ // Nothing to prune → same reference (no needless clone) and undefined passthrough.+ const plain = { forceAdaptiveThinking: true };+ expect(pruneAnthropicCompatForLink(plain, 'gateway')).toBe(plain);+ expect(pruneAnthropicCompatForLink(undefined, 'subscription')).toBeUndefined();+ setXdGatewayModels([{ id: 'moonshot/kimi-k3', agents: ['pi'] }]);+ expect(resolvePiCindyGatewayModelSpec('xd', 'moonshot/kimi-k3')?.compat).toMatchObject({ thinkingFormat: 'openai' });+ });+});diff --git a/apps/desktop/src/main/maker-host/pi-host.ts b/apps/desktop/src/main/maker-host/pi-host.tsindex e2fbad3e79..7250f71cc7 100644--- a/apps/desktop/src/main/maker-host/pi-host.ts+++ b/apps/desktop/src/main/maker-host/pi-host.ts@@ -673,7 +673,9 @@ export function buildPiSubscriptionNativeProviders(const compatibleCorrection = correction?.api === api ? correction : null;const thinking = compatibleCorrection?.thinkingLevelMap?? officialThinking?.thinkingLevelMap ?? template?.thinkingLevelMap;- const compat = compatibleCorrection?.compat ?? officialThinking?.compat ?? template?.compat;+ const compat = sourceProviderId === 'anthropic'+ ? pruneAnthropicCompatForLink(template?.compat, 'subscription')+ : compatibleCorrection?.compat ?? officialThinking?.compat ?? template?.compat;const cost = catalogCostForPiNative(model.cost) ?? template?.cost;const listedIds = listedModelIdsByProvider?.get(piProviderId)?? listedPiModelIds(bundledModelsByProvider)?.get(piProviderId);@@ -1092,6 +1094,43 @@ function xaiOfficialCapabilityCorrection(};}+/**+ * 按链路裁剪 Anthropic Messages 的 Pi compat 能力位(#4982 / #4983)。+ * Pi 目录探测把 Anthropic 直连的新格式能力位(tool `strict`、消息内 `tool_removal` 块、+ * 逐轮 effort)原样带进每条链路的 models.json:+ * - xd 网关的 Anthropic-Messages schema 尚不接受 `tools[].strict` 与 `tool_removal`,+ * Opus 5 / 5.5 每条消息 400;+ * - Anthropic 订阅直连接受 `strict`,但 Pi 发出的 mid-conversation beta 名与 Anthropic+ * 现要求的 `inline-tools-2026-09-15` 不符,第二轮起 400。+ * `supportsMidConvoSystemMessages` 两条链路都被接受,保留。+ * 恢复条件:网关 schema 补齐 `strict` / `tool_removal` 后去掉网关侧 `supportsStrictTools`+ * 裁剪;Pi 上游补发正确 beta(或对不支持端点降级)并随内核更新进入 Cindy 后去掉两个+ * MidConvo 裁剪。只改客户端生成的 models.json,不改代理与上游。+ */+const GATEWAY_UNSUPPORTED_ANTHROPIC_COMPAT: readonly string[] = [+ 'supportsStrictTools',+ 'supportsMidConvoToolChanges',+ 'supportsMidConvoEffort',+];+const SUBSCRIPTION_UNSUPPORTED_ANTHROPIC_COMPAT: readonly string[] = [+ 'supportsMidConvoToolChanges',+ 'supportsMidConvoEffort',+];++export function pruneAnthropicCompatForLink(+ compat: Record<string, unknown> | undefined,+ link: 'gateway' | 'subscription',+): Record<string, unknown> | undefined {+ if (!compat) return compat;+ const unsupported = link === 'gateway'+ ? GATEWAY_UNSUPPORTED_ANTHROPIC_COMPAT+ : SUBSCRIPTION_UNSUPPORTED_ANTHROPIC_COMPAT;+ if (!unsupported.some((key) => key in compat)) return compat;+ const next = { ...compat };+ for (const key of unsupported) delete next[key];+ return next;+}+function officialPiModels(providerId: string): PiNativeModelSpec[] | null {const models = piModelCatalog.providers[providerId];if (!models) return null;@@ -1643,6 +1682,7 @@ export function resolvePiCindyGatewayModelSpec(const compatibleBundled = bundled?.api === api ? bundled : undefined;const compatibleProbed = probed?.api === api ? probed : undefined;let compat = compatibleProbed?.compat ?? compatibleBundled?.compat;+ if (api === 'anthropic-messages') compat = pruneAnthropicCompatForLink(compat, 'gateway');// Gateway routing needs Pi's native session identity on every Chat/Messages request.// This is a Gateway transport policy, not a change to direct BYOM/subscription providers.if (api === 'openai-completions' || api === 'anthropic-messages') {