Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): preserve Cindy Codex collaboration payloads

Lizi790554f15524
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
index b5603d4048..d3bc352872 100644
--- a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
@@ -492,25 +492,39 @@ describe('createCrossProviderCompactionCompatTransform', () => {
)).toBeNull();
});
- it('Cindy Provider codex/* 原样透传 compaction,同时清理 agent 消息密文', async () => {
- const { createCrossProviderCompactionCompatTransform } = await import('../codex-proxy-host.js');
- const transform = createCrossProviderCompactionCompatTransform();
-
- const out = transform(
- { model: 'codex/gpt-5.6-sol', input: [compactionItem, agentMessage, userMessage] },
- { ...CTX_BASE, upstreamBase: 'https://gateway.example.com/v1' },
- ) as { input: Array<Record<string, unknown>> };
+ it('Cindy Provider codex/* 原样透传父子 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');
+ const parentToChildMessage = {
+ type: 'agent_message',
+ author: 'parent',
+ recipient: 'researcher',
+ content: [{ type: 'encrypted_content', encrypted_content: 'gAAAAA_PARENT_TO_CHILD_TASK' }],
+ };
- expect(out.input).toEqual([
- compactionItem,
- {
- type: 'agent_message',
- author: 'researcher',
- recipient: 'parent',
- content: [{ type: 'input_text', text: 'readable agent result' }],
- },
- userMessage,
- ]);
+ 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',
+ },
+ },
+ )).toBeNull();
+ } finally {
+ host.unregister('session-cindy-codex-parent');
+ clearSessionProvider('session-cindy-codex-parent');
+ }
});
it('upstreamBase 缺失时不改写(保守方向:宁可维持现状,不误伤 ChatGPT 请求)', async () => {
diff --git a/apps/desktop/src/main/maker-host/codex-proxy-host.ts b/apps/desktop/src/main/maker-host/codex-proxy-host.ts
index 7d71a12dd4..e4e64e2322 100644
--- a/apps/desktop/src/main/maker-host/codex-proxy-host.ts
+++ b/apps/desktop/src/main/maker-host/codex-proxy-host.ts
@@ -2217,22 +2217,18 @@ function isChatGptUpstreamBase(upstreamBase: string | undefined): boolean {
* 返回 null = 无需改写。透明转发路径(transform 链)与 localHandler 路径共用。
*
* - 加密 compaction 仍替换成明文上下文缺失提示。
- * - 多 Agent 历史会在 agent_message.content 里夹带仅原供应商可解的 encrypted_content;
- * 非 ChatGPT 上游会直接拒绝整次请求。只删除这些嵌套密文,保留可读正文与路由元数据;
- * 若消息只剩密文则整条丢弃。
+ * - 多 Agent 历史会在 agent_message.content 里夹带仅兼容上游可解的 encrypted_content;
+ * ChatGPT 与 Cindy Provider codex/* 原样透传。其它上游只删除这些嵌套密文,保留
+ * 可读正文与路由元数据;若消息只剩密文则整条丢弃。
* - reasoning.encrypted_content 不属于本故障;继续交给后续供应商兼容层判断,
* 不在这里扩大删除面。
*/
-function rewriteCrossProviderHistoryItems(
- body: unknown,
- opts: { preserveCompaction?: boolean } = {},
-): Record<string, unknown> | null {
+function rewriteCrossProviderHistoryItems(body: unknown): Record<string, unknown> | null {
if (!isPlainObject(body) || !Array.isArray(body.input)) return null;
let changed = false;
const input: unknown[] = [];
for (const item of body.input) {
if (
- opts.preserveCompaction !== true &&
isPlainObject(item) &&
(item.type === 'compaction' || item.type === 'context_compaction') &&
typeof item.encrypted_content === 'string' &&
@@ -2271,10 +2267,8 @@ export function createCrossProviderCompactionCompatTransform(): RequestTransform
providerId: providerContext.providerId,
model: providerContext.catalogModel,
});
- if (isChatGptUpstreamBase(ctx.upstreamBase)) return null;
- const replaced = rewriteCrossProviderHistoryItems(body, {
- preserveCompaction: isCindyCodexRoute,
- });
+ if (isChatGptUpstreamBase(ctx.upstreamBase) || isCindyCodexRoute) return null;
+ const replaced = rewriteCrossProviderHistoryItems(body);
if (!replaced) return null;
log.info('rewrote incompatible Codex history for non-ChatGPT upstream', {
reqId: ctx.reqId,