Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): enable Codex for Cindy gateway models (#422)
kl1f850c08973b
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.tsindex 62e0317f7f..ea3705c925 100644--- a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts@@ -452,8 +452,8 @@ describe('codex proxy host', () => {// upstream 是函数形态(每请求现取,model-access 下发可运行期换 endpoint);// 断言其当前求值 = 网关 base + /v1upstream: expect.any(Function),- // [encrypted activeStrip, image generation activeStrip, instructions 注入, 跨来源压缩块兼容, xAI Responses 兼容, ByteDance Seed tool 兼容, MiniMax effort 兼容, provider model rewrite, stripNonAnthropicFields]- transformRequest: [expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), mockState.stripNonAnthropicFields],+ // [encrypted activeStrip, image generation activeStrip, instructions 注入, 跨来源压缩块兼容, strict gateway history 兼容, xAI Responses 兼容, ByteDance Seed tool 兼容, MiniMax effort 兼容, provider model rewrite, stripNonAnthropicFields]+ transformRequest: [expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), mockState.stripNonAnthropicFields],routingTransform: expect.any(Function),recoveryRules: expect.arrayContaining([expect.objectContaining({ id: 'encrypted_content' }),@@ -662,6 +662,146 @@ describe('codex proxy host', () => {clearSessionProvider('session-openai-custom-tool');});+ it.each([+ 'moonshot/kimi-k3',+ 'deepseek/deepseek-v4-pro',+ 'deepseek/deepseek-v4-flash',+ ])('normalizes strict gateway history for model %s', async (model) => {+ const host = await freshCodexProxyHost();+ mockState.createAnthropicCompatProxy.mockResolvedValueOnce({+ url: 'http://127.0.0.1:43210',+ dispose: vi.fn(async () => undefined),+ });+ await host.ensureCodexProxyReady();++ const transforms = mockState.createAnthropicCompatProxy.mock.calls[0]?.[0]?.transformRequest ?? [];+ let current: unknown = {+ model,+ input: [+ { type: 'function_call', name: 'exec_command', call_id: 'call_1', arguments: '{"cmd":"pwd"}' },+ {+ type: 'message',+ role: 'assistant',+ content: [{ type: 'output_text', text: '我先检查项目目录。' }],+ },+ {+ type: 'message',+ role: 'assistant',+ content: [{ type: 'output_text', text: '' }],+ },+ { type: 'function_call', name: 'exec_command', call_id: 'call_2', arguments: '{"cmd":"git status"}' },+ { type: 'function_call_output', call_id: 'call_1', output: '/repo' },+ {+ type: 'message',+ role: 'assistant',+ content: [{ type: 'output_text', text: '接着检查工作区。' }],+ },+ { type: 'function_call_output', call_id: 'call_2', output: 'clean' },+ { type: 'message', role: 'user', content: [{ type: 'input_text', text: '继续' }] },+ ],+ };+ const ctx = { method: 'POST', url: '/responses', headers: {} };+ for (const transform of transforms) {+ const next = transform(current, ctx);+ if (next !== null && next !== undefined) current = next;+ }++ expect(current).toEqual({+ model,+ input: [+ { type: 'function_call', name: 'exec_command', call_id: 'call_1', arguments: '{"cmd":"pwd"}' },+ { type: 'function_call_output', call_id: 'call_1', output: '/repo' },+ {+ type: 'message',+ role: 'assistant',+ content: [{ type: 'output_text', text: '我先检查项目目录。' }],+ },+ { type: 'function_call', name: 'exec_command', call_id: 'call_2', arguments: '{"cmd":"git status"}' },+ { type: 'function_call_output', call_id: 'call_2', output: 'clean' },+ {+ type: 'message',+ role: 'assistant',+ content: [{ type: 'output_text', text: '接着检查工作区。' }],+ },+ { type: 'message', role: 'user', content: [{ type: 'input_text', text: '继续' }] },+ ],+ });+ });++ it('keeps parallel strict-gateway tool calls grouped before their matched outputs', async () => {+ const host = await freshCodexProxyHost();+ mockState.createAnthropicCompatProxy.mockResolvedValueOnce({+ url: 'http://127.0.0.1:43210',+ dispose: vi.fn(async () => undefined),+ });+ await host.ensureCodexProxyReady();++ const transforms = mockState.createAnthropicCompatProxy.mock.calls[0]?.[0]?.transformRequest ?? [];+ let current: unknown = {+ model: 'moonshot/kimi-k3',+ parallel_tool_calls: true,+ input: [+ { type: 'function_call', name: 'exec_command', call_id: 'call_1', arguments: '{"cmd":"pwd"}' },+ { type: 'function_call', name: 'exec_command', call_id: 'call_2', arguments: '{"cmd":"git status"}' },+ {+ type: 'message',+ role: 'assistant',+ content: [{ type: 'output_text', text: '两个命令都在执行。' }],+ },+ { type: 'function_call_output', call_id: 'call_1', output: '/repo' },+ { type: 'function_call_output', call_id: 'call_2', output: 'clean' },+ { type: 'message', role: 'user', content: [{ type: 'input_text', text: '继续' }] },+ ],+ };+ const ctx = { method: 'POST', url: '/responses', headers: {} };+ for (const transform of transforms) {+ const next = transform(current, ctx);+ if (next !== null && next !== undefined) current = next;+ }++ expect(current).toEqual({+ model: 'moonshot/kimi-k3',+ parallel_tool_calls: true,+ input: [+ { type: 'function_call', name: 'exec_command', call_id: 'call_1', arguments: '{"cmd":"pwd"}' },+ { type: 'function_call', name: 'exec_command', call_id: 'call_2', arguments: '{"cmd":"git status"}' },+ { type: 'function_call_output', call_id: 'call_1', output: '/repo' },+ { type: 'function_call_output', call_id: 'call_2', output: 'clean' },+ {+ type: 'message',+ role: 'assistant',+ content: [{ type: 'output_text', text: '两个命令都在执行。' }],+ },+ { type: 'message', role: 'user', content: [{ type: 'input_text', text: '继续' }] },+ ],+ });+ });++ it('keeps interleaved tool history unchanged for non-strict gateway models', async () => {+ const host = await freshCodexProxyHost();+ mockState.createAnthropicCompatProxy.mockResolvedValueOnce({+ url: 'http://127.0.0.1:43210',+ dispose: vi.fn(async () => undefined),+ });+ await host.ensureCodexProxyReady();++ const transforms = mockState.createAnthropicCompatProxy.mock.calls[0]?.[0]?.transformRequest ?? [];+ const input = [+ { type: 'function_call', name: 'exec_command', call_id: 'call_1', arguments: '{"cmd":"pwd"}' },+ { type: 'message', role: 'assistant', content: [{ type: 'output_text', text: 'checking' }] },+ { type: 'function_call_output', call_id: 'call_1', output: '/repo' },+ ];+ const original = { model: 'qwen/qwen3.7-max', input };+ let current: unknown = original;+ const ctx = { method: 'POST', url: '/responses', headers: {} };+ for (const transform of transforms) {+ const next = transform(current, ctx);+ if (next !== null && next !== undefined) current = next;+ }++ expect(current).toEqual(original);+ });+it('normalizes requests to ByteDance Seed Responses capabilities', async () => {const host = await freshCodexProxyHost();const { setSessionProvider, clearSessionProvider } = await import('../session-provider-store.js');@@ -688,6 +828,15 @@ describe('codex proxy host', () => {parallel_tool_calls: false,input: [{ type: 'message', role: 'assistant', content: [{ type: 'output_text', text: 'earlier answer' }] },+ { type: 'message', role: 'assistant', content: [{ type: 'output_text', text: '' }] },+ {+ type: 'message',+ role: 'assistant',+ content: [+ { type: 'output_text', text: '' },+ { type: 'output_text', text: 'non-empty remainder' },+ ],+ },{ type: 'reasoning', summary: [], content: null },{ type: 'message', role: 'user', content: [{ type: 'input_text', text: 'hello' }] },],@@ -719,6 +868,12 @@ describe('codex proxy host', () => {status: 'completed',content: [{ type: 'output_text', text: 'earlier answer' }],},+ {+ type: 'message',+ role: 'assistant',+ status: 'completed',+ content: [{ type: 'output_text', text: 'non-empty remainder' }],+ },{ type: 'reasoning', summary: [], content: null },{ type: 'message', role: 'user', content: [{ type: 'input_text', text: 'hello' }] },],@@ -1213,7 +1368,7 @@ describe('codex proxy host', () => {await host.ensureCodexProxyReady();const transforms = mockState.createAnthropicCompatProxy.mock.calls[0]?.[0]?.transformRequest ?? [];- expect(transforms).toHaveLength(10); // encrypted activeStrip, image generation activeStrip, instructions 注入, 跨来源压缩块兼容, xAI Responses 兼容, ByteDance Seed tool 兼容, MiniMax effort 兼容, provider model rewrite, stripNonAnthropicFields, dump+ expect(transforms).toHaveLength(11); // encrypted activeStrip, image generation activeStrip, instructions 注入, 跨来源压缩块兼容, strict gateway history 兼容, xAI Responses 兼容, ByteDance Seed tool 兼容, MiniMax effort 兼容, provider model rewrite, stripNonAnthropicFields, dumpconst ctx = {method: 'POST',url: '/v1/responses',diff --git a/apps/desktop/src/main/maker-host/codex-proxy-host.ts b/apps/desktop/src/main/maker-host/codex-proxy-host.tsindex 4824ba07c0..d4b41c5380 100644--- a/apps/desktop/src/main/maker-host/codex-proxy-host.ts+++ b/apps/desktop/src/main/maker-host/codex-proxy-host.ts@@ -641,26 +641,166 @@ function sanitizeByteDanceSeedTools(body: Record<string, unknown>): Record<strinreturn next;}-/** Volcengine requires replayed assistant messages to carry their output status. */+const STRICT_GATEWAY_TOOL_HISTORY_MODELS = new Set([+ 'moonshot/kimi-k3',+ 'deepseek/deepseek-v4-pro',+ 'deepseek/deepseek-v4-flash',+]);+const RESPONSE_TOOL_CALL_TYPES = new Set(['function_call', 'custom_tool_call']);+const RESPONSE_TOOL_OUTPUT_TYPES = new Set(['function_call_output', 'custom_tool_call_output']);++function responseToolCallId(item: unknown, output: boolean): string | null {+ if (!isPlainObject(item)) return null;+ const supportedTypes = output ? RESPONSE_TOOL_OUTPUT_TYPES : RESPONSE_TOOL_CALL_TYPES;+ if (!supportedTypes.has(typeof item.type === 'string' ? item.type : '')) return null;+ return typeof item.call_id === 'string' && item.call_id.length > 0 ? item.call_id : null;+}++function stripEmptyResponseMessage(item: unknown): { item: unknown; changed: boolean } | null {+ if (!isPlainObject(item) || item.type !== 'message') return { item, changed: false };+ if (item.content === '') return null;+ if (!Array.isArray(item.content)) return { item, changed: false };++ const content = item.content.filter((part) => !(+ isPlainObject(part) &&+ (part.type === 'input_text' || part.type === 'output_text') &&+ part.text === ''+ ));+ if (content.length === 0) return null;+ return content.length === item.content.length+ ? { item, changed: false }+ : { item: { ...item, content }, changed: true };+}++/** Volcengine requires replayed assistant messages to carry their output status and non-empty text. */function normalizeByteDanceSeedInput(body: Record<string, unknown>): Record<string, unknown> | null {if (!isByteDanceSeedModel(body.model) || !Array.isArray(body.input)) return null;let changed = false;- const input = body.input.map((item) => {+ const input: unknown[] = [];+ for (const item of body.input) {+ const normalized = stripEmptyResponseMessage(item);+ if (!normalized) {+ changed = true;+ continue;+ }+ if (normalized.changed) changed = true;++ const nextItem = normalized.item;if (- !isPlainObject(item) ||- item.type !== 'message' ||- item.role !== 'assistant' ||- typeof item.status === 'string'+ isPlainObject(nextItem) &&+ nextItem.type === 'message' &&+ nextItem.role === 'assistant' &&+ typeof nextItem.status !== 'string') {- return item;+ changed = true;+ input.push({ ...nextItem, status: 'completed' });+ continue;}- changed = true;- return { ...item, status: 'completed' };- });+ input.push(nextItem);+ }return changed ? { ...body, input } : null;}+/**+ * LiteLLM converts gateway Responses history to Chat Completions for these models.+ * Their native APIs require every assistant tool call to be followed immediately+ * by its tool result, while Codex may persist an assistant progress message between+ * the Responses function_call and function_call_output items. Codex may also persist+ * empty assistant output_text items, which Moonshot rejects after history conversion.+ * Consecutive calls form one parallel assistant group, so their matched outputs must+ * be moved after the whole group rather than inserted between calls.+ */+function normalizeStrictGatewayHistory(body: Record<string, unknown>): Record<string, unknown> | null {+ if (+ typeof body.model !== 'string' ||+ !STRICT_GATEWAY_TOOL_HISTORY_MODELS.has(body.model) ||+ !Array.isArray(body.input)+ ) {+ return null;+ }++ const originalInput = body.input;+ const normalizedInput: unknown[] = [];+ for (const item of originalInput) {+ const normalized = stripEmptyResponseMessage(item);+ if (normalized) normalizedInput.push(normalized.item);+ }++ const matchedOutputs = new Map<number, number>();+ const usedOutputIndexes = new Set<number>();+ const outputIndexesByCallId = new Map<string, number[]>();+ const outputCursorByCallId = new Map<string, number>();+ for (let index = 0; index < normalizedInput.length; index += 1) {+ const outputCallId = responseToolCallId(normalizedInput[index], true);+ if (!outputCallId) continue;+ const indexes = outputIndexesByCallId.get(outputCallId) ?? [];+ indexes.push(index);+ outputIndexesByCallId.set(outputCallId, indexes);+ }++ for (let callIndex = 0; callIndex < normalizedInput.length; callIndex += 1) {+ const callId = responseToolCallId(normalizedInput[callIndex], false);+ if (!callId) continue;++ const outputIndexes = outputIndexesByCallId.get(callId);+ if (!outputIndexes) continue;+ let cursor = outputCursorByCallId.get(callId) ?? 0;+ while (cursor < outputIndexes.length && outputIndexes[cursor] <= callIndex) cursor += 1;+ if (cursor >= outputIndexes.length) continue;++ const outputIndex = outputIndexes[cursor];+ outputCursorByCallId.set(callId, cursor + 1);+ matchedOutputs.set(callIndex, outputIndex);+ usedOutputIndexes.add(outputIndex);+ }++ const outputIndexesByGroupEnd = new Map<number, number[]>();+ for (let groupStart = 0; groupStart < normalizedInput.length;) {+ if (!responseToolCallId(normalizedInput[groupStart], false)) {+ groupStart += 1;+ continue;+ }+ let groupEnd = groupStart;+ while (+ groupEnd + 1 < normalizedInput.length &&+ responseToolCallId(normalizedInput[groupEnd + 1], false)+ ) {+ groupEnd += 1;+ }+ const outputIndexes: number[] = [];+ for (let callIndex = groupStart; callIndex <= groupEnd; callIndex += 1) {+ const outputIndex = matchedOutputs.get(callIndex);+ if (outputIndex !== undefined) outputIndexes.push(outputIndex);+ }+ if (outputIndexes.length > 0) {+ outputIndexesByGroupEnd.set(groupEnd, outputIndexes.sort((a, b) => a - b));+ }+ groupStart = groupEnd + 1;+ }++ const input: unknown[] = [];+ for (let index = 0; index < normalizedInput.length; index += 1) {+ if (usedOutputIndexes.has(index)) continue;+ input.push(normalizedInput[index]);+ const outputIndexes = outputIndexesByGroupEnd.get(index);+ if (outputIndexes) {+ for (const outputIndex of outputIndexes) input.push(normalizedInput[outputIndex]);+ }+ }+ const changed =+ input.length !== originalInput.length ||+ input.some((item, index) => item !== originalInput[index]);+ return changed ? { ...body, input } : null;+}++function createStrictGatewayHistoryCompatTransform(): RequestTransform {+ return (body) => {+ if (!isPlainObject(body)) return null;+ return normalizeStrictGatewayHistory(body);+ };+}+/** Seed accepts the reasoning effort, but rejects Responses' summary selector. */function sanitizeByteDanceSeedReasoning(body: Record<string, unknown>): Record<string, unknown> | null {if (!isByteDanceSeedModel(body.model) || !isPlainObject(body.reasoning) || !('summary' in body.reasoning)) {@@ -1164,6 +1304,7 @@ function createTransformRequestChain(): RequestTransform[] {// 必须先于 xAI/MiniMax 兼容改写:加密压缩块换成明文占位 message 后,后续// 针对具体供应商的 input 归一化才能按标准 message 处理它。createCrossProviderCompactionCompatTransform(),+ createStrictGatewayHistoryCompatTransform(),createXaiResponsesCompatTransform(),createByteDanceSeedResponsesCompatTransform(),createMiniMaxResponsesCompatTransform(),diff --git a/packages/model-providers/catalog/providers.json b/packages/model-providers/catalog/providers.jsonindex ace98fe720..54047fdb04 100644--- a/packages/model-providers/catalog/providers.json+++ b/packages/model-providers/catalog/providers.json@@ -1110,7 +1110,8 @@},"qwen/qwen3.7-max": {"agents": [- "claude-code"+ "claude-code",+ "codex"],"name": "Qwen 3.7 Max","group": "china",@@ -1148,7 +1149,8 @@},"z-ai/glm-5.2": {"agents": [- "claude-code"+ "claude-code",+ "codex"],"name": "GLM-5.2","group": "china",@@ -1164,7 +1166,8 @@},"deepseek/deepseek-v4-pro": {"agents": [- "claude-code"+ "claude-code",+ "codex"],"name": "DeepSeek V4 Pro","group": "china",@@ -1180,7 +1183,8 @@},"deepseek/deepseek-v4-flash": {"agents": [- "claude-code"+ "claude-code",+ "codex"],"name": "DeepSeek V4 Flash","group": "china",@@ -1226,7 +1230,8 @@},"moonshot/kimi-k3": {"agents": [- "claude-code"+ "claude-code",+ "codex"],"name": "Kimi K3","group": "china",diff --git a/packages/model-providers/src/__tests__/catalog.test.ts b/packages/model-providers/src/__tests__/catalog.test.tsindex 945bd835d2..523062d358 100644--- a/packages/model-providers/src/__tests__/catalog.test.ts+++ b/packages/model-providers/src/__tests__/catalog.test.ts@@ -147,20 +147,27 @@ describe('bundled catalog validity (dynamic-first contract)', () => {expect(presets.map((p) => p.id)).toContain('openrouter');});- it('ships product display names for newly discovered XD gateway models', () => {+ it('ships Codex support metadata for the current XD gateway model set', () => {const metadata = BUNDLED_CATALOG.cindyModelMeta as {version?: unknown;models?: Record<string, unknown>;};expect(metadata.version).toBe(1);- expect(metadata.models?.['bytedance-seed/seed-2.1-pro']).toMatchObject({- agents: ['claude-code', 'codex'],- name: 'Seed 2.1 Pro',- });- expect(metadata.models?.['qwen/qwen3.8-max-preview']).toMatchObject({- agents: ['claude-code', 'codex'],- name: 'Qwen 3.8 Max Preview',- });+ const expected = {+ 'qwen/qwen3.7-max': 'Qwen 3.7 Max',+ 'moonshot/kimi-k3': 'Kimi K3',+ 'z-ai/glm-5.2': 'GLM-5.2',+ 'deepseek/deepseek-v4-pro': 'DeepSeek V4 Pro',+ 'deepseek/deepseek-v4-flash': 'DeepSeek V4 Flash',+ 'bytedance-seed/seed-2.1-pro': 'Seed 2.1 Pro',+ 'qwen/qwen3.8-max-preview': 'Qwen 3.8 Max Preview',+ };+ for (const [id, name] of Object.entries(expected)) {+ expect(metadata.models?.[id], id).toMatchObject({+ agents: ['claude-code', 'codex'],+ name,+ });+ }});it('models are grouped per-agent (no flat array, no rogue agent keys)', () => {