Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): scope v3 wire validation to XD models
xd-boboa89580f0bc4a
diff --git a/apps/desktop/src/main/maker-host/__tests__/activeCatalogXdAvailability.test.ts b/apps/desktop/src/main/maker-host/__tests__/activeCatalogXdAvailability.test.tsindex b9a19824ab..02700014a1 100644--- a/apps/desktop/src/main/maker-host/__tests__/activeCatalogXdAvailability.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/activeCatalogXdAvailability.test.ts@@ -107,12 +107,18 @@ describe('XD 网关权威模型清单重建', () => {agents: ['claude-code', 'codex', 'pi'],perAgent: { pi: { wireProtocol: 'openai-responses' } },},+ {+ id: 'claude-only-model',+ agents: ['claude-code'],+ perAgent: { 'claude-code': { wireProtocol: 'anthropic-messages' } },+ },]);expect(resolveXdPiGatewayWireProtocol('invalid-messages-wire')).toBeNull();expect(resolveXdPiGatewayWireProtocol('responses-model')).toBe('openai-responses');expect(resolveXdPiGatewayWireProtocol('responses-model[1m]')).toBe('openai-responses');- expect(resolveXdPiGatewayWireProtocol('unknown-model')).toBeNull();+ expect(resolveXdPiGatewayWireProtocol('claude-only-model')).toBeUndefined();+ expect(resolveXdPiGatewayWireProtocol('unknown-model')).toBeUndefined();});it('显式登记 efforts=[] 表示不可调,不合成 3 档;fast 显式 false 尊重', () => {diff --git a/apps/desktop/src/main/maker-host/active-catalog.ts b/apps/desktop/src/main/maker-host/active-catalog.tsindex ff98ccae8d..52ebb14ed8 100644--- a/apps/desktop/src/main/maker-host/active-catalog.ts+++ b/apps/desktop/src/main/maker-host/active-catalog.ts@@ -164,15 +164,18 @@ function xdGatewayTargetAgents(model: XdGatewayModelInfo): AgentKind[] {* XD 下发模型给 Pi 时的真实 wire protocol。** Pi provider 始终叫 `cindy`;这里只读取 v3 服务端给该模型的 transport,供- * models.json 写入模型级 `api`。缺失返回 null,由 maker-core fail closed。+ * models.json 写入模型级 `api`。三态语义:非 XD Pi 模型返回 undefined;XD Pi 模型+ * 缺失或协议非法返回 null,由 maker-core fail closed;有效配置返回 Responses。*/export function resolveXdPiGatewayWireProtocol(modelId: string,-): Extract<ProviderWireProtocol, 'openai-responses'> | null {+): Extract<ProviderWireProtocol, 'openai-responses'> | null | undefined {const normalized = modelId.replace(/\[1m\]$/, '');- const wireProtocol = xdGatewayModels.find(+ const gatewayModel = xdGatewayModels.find((model) => model.id === normalized,- )?.perAgent?.pi?.wireProtocol;+ );+ if (!gatewayModel?.agents?.includes('pi')) return undefined;+ const wireProtocol = gatewayModel.perAgent?.pi?.wireProtocol;return wireProtocol === 'openai-responses' ? wireProtocol : null;}diff --git a/packages/maker-core/src/agents/base-agent.ts b/packages/maker-core/src/agents/base-agent.tsindex 6ac23a3ca8..0e67beee04 100644--- a/packages/maker-core/src/agents/base-agent.ts+++ b/packages/maker-core/src/agents/base-agent.ts@@ -439,8 +439,11 @@ export interface AgentDeps {/*** Pi-only:解析 `cindy` gateway 内某模型应使用的 PI API。provider 仍保持 `cindy`,- * 只在模型级落实 wire protocol。Cindy AI 模型必须由 Model Access v3 明确指定- * OpenAI Responses;缺失或不匹配时 Pi fail closed,不猜测或切换协议。+ * 只在模型级落实 wire protocol。三态语义:+ * - `openai-responses`:Model Access v3 明确指定的 Cindy AI Pi 路由;+ * - `null`:模型属于 Cindy AI Pi 目录,但协议缺失或不匹配,Pi fail closed;+ * - `undefined`:模型不属于 Cindy AI Pi 目录,保留非 XD compat proxy 的既有+ * Anthropic Messages 协议(不是 Model Access fallback)。*/resolvePiGatewayModelApi?: (modelId: string) => PiNativeApi | null | undefined;diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.tsindex 37bd788a42..d91908b361 100644--- a/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/pi-provider-routing.test.ts@@ -265,6 +265,103 @@ describe('Pi provider-aware model routing', () => {await handle.close();});+ it('keeps BYOM startup when the model is outside the XD v3 Pi catalog', async () => {+ const deps: AgentDeps = {+ auth: {+ getState: async () => ({ authenticated: true, identity: 'test', authSource: 'api-key' as const }),+ triggerLogin: async () => ({ authenticated: true }),+ logout: async () => {},+ getAuthEnv: async () => ({}),+ },+ runtimeConfig: { endpoint: 'http://127.0.0.1:9' },+ binaryPath: path.join(agentHome, 'pi'),+ logger: noopLogger,+ capabilityAdditions: {+ availableModels: [+ {+ id: 'byom-only-model',+ displayName: 'BYOM Only Model',+ contextWindow: 128_000,+ efforts: [],+ defaultEffort: null,+ },+ ],+ },+ resolvePiAgentHome: () => agentHome,+ // undefined = 该模型不受 XD v3 管理;不是 XD 协议缺失。+ resolvePiGatewayModelApi: () => undefined,+ resolvePiNativeProviders: async () => ({+ providers: [+ {+ id: 'my-local',+ name: 'My Local',+ baseUrl: 'http://127.0.0.1:11434/v1',+ api: 'openai-completions',+ models: [{ id: 'byom-only-model' }],+ },+ ],+ env: {},+ }),+ };++ const handle = await new PiAgent(deps).startSession({+ sessionId: 'byom-outside-xd-v3',+ workingDir: cwd,+ model: 'byom-only-model',+ providerId: 'my-local',+ });++ expect(captured.args.slice(captured.args.indexOf('--provider'), captured.args.indexOf('--provider') + 2))+ .toEqual(['--provider', 'my-local']);+ const models = JSON.parse(+ readFileSync(path.join(captured.env.PI_CODING_AGENT_DIR as string, 'models.json'), 'utf8'),+ ) as {+ providers: Record<string, {+ models: Array<{ id: string; api?: string }>;+ }>;+ };+ expect(models.providers.cindy?.models.find((model) => model.id === 'byom-only-model'))+ .toMatchObject({ api: 'anthropic-messages' });+ expect(models.providers['my-local']?.models.find((model) => model.id === 'byom-only-model'))+ .toMatchObject({ id: 'byom-only-model' });+ await handle.close();+ });++ it('still fails closed when an XD Pi model has no valid v3 wire protocol', async () => {+ const deps: AgentDeps = {+ auth: {+ getState: async () => ({ authenticated: true, identity: 'test', authSource: 'api-key' as const }),+ triggerLogin: async () => ({ authenticated: true }),+ logout: async () => {},+ getAuthEnv: async () => ({}),+ },+ runtimeConfig: { endpoint: 'http://127.0.0.1:9' },+ binaryPath: path.join(agentHome, 'pi'),+ logger: noopLogger,+ capabilityAdditions: {+ availableModels: [+ {+ id: 'invalid-xd-model',+ displayName: 'Invalid XD Model',+ contextWindow: 200_000,+ efforts: [],+ defaultEffort: null,+ },+ ],+ },+ resolvePiAgentHome: () => agentHome,+ resolvePiGatewayModelApi: () => null,+ };++ await expect(new PiAgent(deps).startSession({+ sessionId: 'invalid-xd-v3-wire',+ workingDir: cwd,+ model: 'invalid-xd-model',+ providerId: 'xd',+ })).rejects.toThrow(/Model Access v3 did not provide a Pi wire protocol/);+ expect(captured.args).toEqual([]);+ });+it('reconciles a stale persisted effort to the selected BYOM model default before startup', async () => {const resolver = vi.fn((providerId: string | null | undefined, modelId: string) => {if (providerId !== 'native-a' || modelId !== 'shared-model') return null;diff --git a/packages/maker-core/src/agents/pi/index.ts b/packages/maker-core/src/agents/pi/index.tsindex a22fdfd749..7f8a757a5c 100644--- a/packages/maker-core/src/agents/pi/index.ts+++ b/packages/maker-core/src/agents/pi/index.ts@@ -478,10 +478,19 @@ export class PiAgent extends BaseAgent {// provider-aware 描述符,不能被同名 non-reasoning BYOM 清空 reasoning。// host 未注入 resolver 或只有 BYOM 条目时保留旧 flat fallback。const m = this.deps.resolvePiGatewayModelDescriptor?.(publicModel.id) ?? publicModel;- const api = this.deps.resolvePiGatewayModelApi?.(m.id);- if (api !== 'anthropic-messages' && api !== 'openai-responses') {+ const resolvedApi = this.deps.resolvePiGatewayModelApi?.(m.id);+ if (+ resolvedApi === null ||+ (resolvedApi !== undefined &&+ resolvedApi !== 'anthropic-messages' &&+ resolvedApi !== 'openai-responses')+ ) {throw new Error(`Model Access v3 did not provide a Pi wire protocol for model: ${m.id}`);}+ // undefined 明确表示该模型不属于 XD Pi 目录。订阅直连及 BYOM-only 模型仍需出现在+ // cindy compat provider 的模型表中,沿用它们既有的 Messages 前门;只有 null 才是+ // “属于 XD 但 v3 配置不完整”,上面已 fail closed。+ const api = resolvedApi ?? 'anthropic-messages';const supportsImageInput = m.supportsImageInput === true;gatewayImageInputByModel.set(m.id, supportsImageInput);return {