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(codex): 搜索工具转换沿用代理冻结认证上下文 (#4579)

FicoWang3f8ce4cc8c2c
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 070863c380..b1267d5e9d 100644
--- a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
@@ -3884,6 +3884,30 @@ describe('codex proxy host', () => {
setCustomProviders([]);
});
+ it.each([
+ { frozen: 'oauth-bearer' as const, global: 'env-key' as const, search: false },
+ { frozen: 'env-key' as const, global: 'oauth-bearer' as const, search: true },
+ ])('uses frozen $frozen auth for native search despite global $global auth', async ({ frozen, global, search }) => {
+ const host = await freshCodexProxyHost();
+ mockState.createAnthropicCompatProxy.mockResolvedValueOnce({
+ url: 'http://127.0.0.1:43210',
+ dispose: vi.fn(async () => undefined),
+ });
+ host.setCodexProxyAuthInjection(global);
+ await host.ensureCodexControlPlaneProxyReady(frozen);
+ const transforms = mockState.createAnthropicCompatProxy.mock.calls[0]?.[0]?.transformRequest ?? [];
+ const input = [{ role: 'user', content: 'First message?' }];
+ const tools = [{ type: 'function', name: 'read_file', parameters: { type: 'object', properties: {} } }];
+ let current: unknown = { model: 'gpt-5.6-luna', input, tools };
+ const ctx = { method: 'POST', url: '/responses', headers: { 'thread-id': 'frozen-search-thread' } };
+ for (const transform of transforms) {
+ const next = transform(current, ctx);
+ if (next !== null && next !== undefined) current = next;
+ }
+ expect(current).toMatchObject({ input, tools: search ? [...tools, { type: 'web_search' }] : tools });
+ expect((current as { tools: unknown[] }).tools).toHaveLength(search ? 2 : 1);
+ });
+
it('restores native web_search for Gateway GPT-5.6 when Codex omitted the declaration', async () => {
const host = await freshCodexProxyHost();
const { setSessionProvider, clearSessionProvider } = await import('../session-provider-store.js');
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 582cbdf9d8..326ef75a04 100644
--- a/apps/desktop/src/main/maker-host/codex-proxy-host.ts
+++ b/apps/desktop/src/main/maker-host/codex-proxy-host.ts
@@ -789,7 +789,7 @@ function createProviderAwareGuardianReviewerTransform(
* 请求的 `tools`。插件搜索是增强项,不能作为该基础能力的前置条件,因此在明确走
* Cindy Gateway 的 GPT-5.6 请求中补回标准 `web_search` 工具;已有声明保持原样。
*/
-function createGatewayNativeWebSearchTransform(): RequestTransform {
+function createGatewayNativeWebSearchTransform(frozenAuthInjection?: CodexProxyAuthInjection): RequestTransform {
return (body, ctx) => {
if (!isPlainObject(body) || typeof body.model !== 'string') return null;
if (guardianParentThreadIdFromHeaders(ctx.headers)) return null;
@@ -807,7 +807,9 @@ function createGatewayNativeWebSearchTransform(): RequestTransform {
const gatewayModel = model.startsWith('codex/') ? model.slice('codex/'.length) : model;
if (!/^gpt-5\.6(?:$|[-.])/.test(gatewayModel)) return null;
- const authInjection = getCodexProxyAuthInjection();
+ // Match the effective auth context used by this proxy's routing transform. Another
+ // app-server may change the global mode while a frozen OAuth proxy is still active.
+ const authInjection = frozenAuthInjection ?? getCodexProxyAuthInjection();
const canUseExplicitSessionRoute = Boolean(sessionId && !subagentRoute && (
authInjection === 'oauth-bearer' ||
isUserProviderSession(sessionId) ||
@@ -2885,7 +2887,7 @@ function createTransformRequestChain(
createForcedSubagentRequestTransform(),
createCodexTransform(),
createLockedSubagentExecGuardTransform(),
- createGatewayNativeWebSearchTransform(),
+ createGatewayNativeWebSearchTransform(frozenAuthInjection),
// 必须先于 xAI/MiniMax 兼容改写:先把供应商绑定的历史项降级成标准 message,
// 后续针对具体供应商的 input 归一化才能稳定处理。
createCrossProviderCompactionCompatTransform(),