Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): preserve GPT collaboration history
Lizi3b08946633fb
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.tsindex d3bc352872..58e2ccc847 100644--- a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts@@ -428,13 +428,13 @@ describe('createCrossProviderCompactionCompatTransform', () => {encrypted_content: 'REASONING_ENC',};- it('同时降级 compaction 与 agent 消息密文,保留可读正文和 reasoning(非 ChatGPT 上游)', async () => {+ it('同时降级 compaction 与 agent 消息密文,保留可读正文和 reasoning(非 GPT 模型)', async () => {const { createCrossProviderCompactionCompatTransform } = await import('../codex-proxy-host.js');const transform = createCrossProviderCompactionCompatTransform();const out = transform({- model: 'gpt-5.5',+ model: 'not-gpt-5',input: [compactionItem, contextCompactionItem, agentMessage, reasoningItem, userMessage],},{ ...CTX_BASE, upstreamBase: 'https://gateway.example.com/v1' },@@ -465,7 +465,7 @@ describe('createCrossProviderCompactionCompatTransform', () => {const out = transform({- model: 'gpt-5.5',+ model: 'codex/claude-sonnet-4-6',input: [{type: 'agent_message',@@ -487,16 +487,16 @@ describe('createCrossProviderCompactionCompatTransform', () => {const transform = createCrossProviderCompactionCompatTransform();expect(transform(- { model: 'gpt-5.5', input: [compactionItem, agentMessage, reasoningItem, userMessage] },+ { model: 'claude-sonnet-4-6', input: [compactionItem, agentMessage, reasoningItem, userMessage] },{ ...CTX_BASE, upstreamBase: 'https://chatgpt.com/backend-api/codex' },)).toBeNull();});- it('Cindy Provider codex/* 原样透传父子 Agent 协作密文', async () => {+ it('版本化 gpt-* 与任意 */gpt-* 在所有 Responses Provider 原样透传父子 Agent 协作密文(大小写不敏感)', async () => {const host = await freshCodexProxyHost();const { setSessionProvider, clearSessionProvider } = await import('../session-provider-store.js');- host.registerComposed('session-cindy-codex-parent', 'thread-cindy-codex-parent', 'PRODUCT_PROMPT');- setSessionProvider('session-cindy-codex-parent', 'xd');+ host.registerComposed('session-custom-gpt-parent', 'thread-custom-gpt-parent', 'PRODUCT_PROMPT');+ setSessionProvider('session-custom-gpt-parent', 'custom-gpt-pool');const parentToChildMessage = {type: 'agent_message',author: 'parent',@@ -506,24 +506,53 @@ describe('createCrossProviderCompactionCompatTransform', () => {try {const transform = host.createCrossProviderCompactionCompatTransform();- expect(transform(- {- model: 'codex/gpt-5.6-sol',- input: [compactionItem, parentToChildMessage, agentMessage, userMessage],- },- {- ...CTX_BASE,- upstreamBase: 'https://gateway.example.com/v1',- headers: {- 'thread-id': 'thread-cindy-codex-child',- 'x-openai-subagent': 'collab_spawn',- 'x-codex-parent-thread-id': 'thread-cindy-codex-parent',+ for (const model of [+ 'gpt-5.6-sol',+ 'GPT-5.6-TERRA',+ 'codex/gpt-5.6-sol',+ 'OPENAI/GPT-5.6-TERRA',+ 'custom/pool/gpt-5.6-sol',+ ]) {+ expect(transform(+ {+ model,+ input: [compactionItem, parentToChildMessage, agentMessage, userMessage],},- },- )).toBeNull();+ {+ ...CTX_BASE,+ upstreamBase: 'https://custom-pool.example.com/v1',+ headers: {+ 'thread-id': 'thread-custom-gpt-child',+ 'x-openai-subagent': 'collab_spawn',+ 'x-codex-parent-thread-id': 'thread-custom-gpt-parent',+ },+ },+ )).toBeNull();+ }} finally {- host.unregister('session-cindy-codex-parent');- clearSessionProvider('session-cindy-codex-parent');+ host.unregister('session-custom-gpt-parent');+ clearSessionProvider('session-custom-gpt-parent');+ }+ });++ it('gpt-oss 与非版本化 gpt 标签仍删除父子 Agent 协作密文', async () => {+ const { createCrossProviderCompactionCompatTransform } = await import('../codex-proxy-host.js');+ const transform = createCrossProviderCompactionCompatTransform();+ for (const model of ['gpt-oss:20b', 'codex/gpt-oss:20b', 'gpt-image-1']) {+ const out = transform(+ { model, input: [agentMessage, userMessage] },+ { ...CTX_BASE, upstreamBase: 'https://custom-pool.example.com/v1' },+ ) as { input: Array<Record<string, unknown>> };+ expect(out.input).toEqual([+ {+ type: 'agent_message',+ author: 'researcher',+ recipient: 'parent',+ content: [{ type: 'input_text', text: 'readable agent result' }],+ },+ userMessage,+ ]);+ expect(JSON.stringify(out.input)).not.toContain('AGENT_ENC');}});@@ -957,6 +986,75 @@ describe('chatBridgeCapabilitiesForRoute', () => {}});+ it('strips parent-to-child ciphertext when a versioned GPT model uses the Chat bridge', async () => {+ const host = await freshCodexProxyHost();+ const { buildUserProvider } = await import('@cindy/model-providers');+ const { setCustomProviders } = await import('../active-catalog.js');+ const { setCustomProviderKeyReader } = await import('../provider-route.js');+ const { setSessionProvider, clearSessionProvider } = await import('../session-provider-store.js');+ const model = 'OPENAI/GPT-5.6-SOL';+ setCustomProviders([+ buildUserProvider({+ id: 'gpt-history-chat-provider',+ name: 'GPT History Chat Provider',+ runtimes: {+ codex: {+ baseUrl: 'https://gpt-chat-provider.example/v1',+ wireProtocol: 'openai-chat',+ models: [{ id: model, name: 'Custom GPT' }],+ },+ },+ }),+ ]);+ setCustomProviderKeyReader(() => 'gpt-history-provider-key');+ host.registerComposed('session-gpt-history-chat', 'thread-gpt-history-chat', 'PRODUCT_PROMPT');+ setSessionProvider('session-gpt-history-chat', 'gpt-history-chat-provider');+ host.setCodexProxyAuthInjection('env-key');++ const parentToChildMessage = {+ type: 'agent_message',+ author: 'parent',+ recipient: 'researcher',+ content: [{ type: 'encrypted_content', encrypted_content: 'gAAAAA_PARENT_TO_CHILD_TASK' }],+ };+ const parsedBody = { model, input: [parentToChildMessage] };+ const ctx = {+ reqId: 1,+ method: 'POST',+ url: '/responses',+ headers: { 'thread-id': 'thread-gpt-history-chat' },+ };++ try {+ const decision = await Promise.resolve(host.createModelRoutingTransform()(parsedBody, ctx));+ expect(decision).toEqual(expect.objectContaining({ localHandler: expect.any(Function) }));+ if (!decision?.localHandler) throw new Error('expected GPT Chat bridge local handler');++ const res = {} as never;+ await decision.localHandler({+ rawBody: Buffer.from(JSON.stringify(parsedBody)),+ parsedBody,+ ctx,+ res,+ });+ const bridge = mockState.createResponsesChatHandler.mock.results.at(-1)?.value as+ | { handle: ReturnType<typeof vi.fn> }+ | undefined;+ expect(bridge?.handle).toHaveBeenCalledWith({+ parsedBody: {+ ...parsedBody,+ instructions: 'PRODUCT_PROMPT',+ input: [],+ },+ res,+ });+ } finally {+ clearSessionProvider('session-gpt-history-chat');+ setCustomProviderKeyReader(() => null);+ setCustomProviders([]);+ }+ });+it('routes a custom Codex Anthropic Messages runtime to the local bridge with provider-owned auth', async () => {const host = await freshCodexProxyHost();const { buildUserProvider } = await import('@cindy/model-providers');diff --git a/apps/desktop/src/main/maker-host/codex-proxy-host.ts b/apps/desktop/src/main/maker-host/codex-proxy-host.tsindex e4e64e2322..296295397e 100644--- a/apps/desktop/src/main/maker-host/codex-proxy-host.ts+++ b/apps/desktop/src/main/maker-host/codex-proxy-host.ts@@ -36,7 +36,6 @@ import {type RoutingDecision,type RoutingTransform,} from '@cindy/anthropic-compat-proxy';-import { isCindyProviderCodexRemoteCompactionRoute } from '@cindy/maker-core';import { buildVisionBridgeProxyTransform } from '../vision-bridge/vision-bridge-controller.js';import {createResponsesCustomToolFunctionAdapter,@@ -1051,9 +1050,9 @@ function prepareLocalBridgeBody(opts: PrepareLocalBridgeBodyOptions): unknown {: [existingText, opts.instructions].filter(Boolean).join('\n\n'),};}- const historySafe = isChatGptUpstreamBase(opts.upstreamBase)- ? null- : rewriteCrossProviderHistoryItems(body);+ // Responses encrypted collaboration items cannot survive either local wire+ // bridge: Chat Completions and Anthropic Messages have no equivalent field.+ const historySafe = rewriteCrossProviderHistoryItems(body);if (historySafe) {log.info('rewrote incompatible Codex history for local bridge upstream', {bridge: opts.bridge,@@ -2194,8 +2193,8 @@ function createGatewayGrokResponsesCompatTransform(/*** 跨来源恢复的加密压缩历史兼容(Greptile P1, PR #265):*- * 远端压缩会把早期历史替换成加密 compaction 块。ChatGPT 和 Cindy Provider- * codex/* 都需要原样回放;切到 xAI / 自定义供应商后仍按既有明文占位降级。+ * 远端压缩会把早期历史替换成加密 compaction 块。ChatGPT 和走 Responses+ * 协议的版本化 GPT 模型需要原样回放;非 GPT 模型仍按既有明文占位降级。* 判断去向用 ctx.upstreamBase(引擎按最终路由注入),不复刻路由逻辑。*/const COMPACTION_UNAVAILABLE_NOTE =@@ -2212,14 +2211,26 @@ function isChatGptUpstreamBase(upstreamBase: string | undefined): boolean {}}+const GPT_ENCRYPTED_HISTORY_MODEL_PATTERN = /(?:^|\/)gpt-\d[^/]*$/i;++/**+ * A final, versioned `gpt-<digit>*` model segment opts into the Responses+ * encrypted collaboration-history contract. Catalog namespaces (`codex/`,+ * `openai/`, or custom equivalents) are routing labels and do not affect the+ * match. Non-OpenAI families such as `gpt-oss` remain fail-closed.+ */+function isGptEncryptedHistoryModel(model: string | null | undefined): boolean {+ return GPT_ENCRYPTED_HISTORY_MODEL_PATTERN.test(model?.trim() ?? '');+}+/*** 把 body.input 里无法跨供应商重放的 Codex 历史降级成目标上游可接受的形态。* 返回 null = 无需改写。透明转发路径(transform 链)与 localHandler 路径共用。** - 加密 compaction 仍替换成明文上下文缺失提示。- * - 多 Agent 历史会在 agent_message.content 里夹带仅兼容上游可解的 encrypted_content;- * ChatGPT 与 Cindy Provider codex/* 原样透传。其它上游只删除这些嵌套密文,保留- * 可读正文与路由元数据;若消息只剩密文则整条丢弃。+ * - 多 Agent 历史会在 agent_message.content 里夹带仅兼容 GPT Responses 上游可解的+ * encrypted_content;ChatGPT 与版本化 gpt-* / namespace/gpt-* 模型原样透传。其它模型+ * 只删除这些嵌套密文,保留可读正文与路由元数据;若消息只剩密文则整条丢弃。* - reasoning.encrypted_content 不属于本故障;继续交给后续供应商兼容层判断,* 不在这里扩大删除面。*/@@ -2263,15 +2274,15 @@ export function createCrossProviderCompactionCompatTransform(): RequestTransformif (!ctx.upstreamBase) return null;const requestModel = isPlainObject(body) && typeof body.model === 'string' ? body.model : '';const providerContext = providerContextForRequest(ctx.headers, requestModel);- const isCindyCodexRoute = isCindyProviderCodexRemoteCompactionRoute({- providerId: providerContext.providerId,- model: providerContext.catalogModel,- });- if (isChatGptUpstreamBase(ctx.upstreamBase) || isCindyCodexRoute) return null;+ if (+ isChatGptUpstreamBase(ctx.upstreamBase) ||+ isGptEncryptedHistoryModel(providerContext.catalogModel)+ ) return null;const replaced = rewriteCrossProviderHistoryItems(body);if (!replaced) return null;- log.info('rewrote incompatible Codex history for non-ChatGPT upstream', {+ log.info('rewrote incompatible Codex history for non-GPT model', {reqId: ctx.reqId,+ model: providerContext.catalogModel,upstreamBase: ctx.upstreamBase,threadId: selectedThreadIdFromHeaders(ctx.headers),});