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): 补齐 GPT-6.1 网关搜索历史的工具声明 (#5992)

Tsai Yuan2c06c871bacb
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 dbaaf2ab8b..7588350e58 100644
--- a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
@@ -4169,6 +4169,66 @@ describe('codex proxy host', () => {
});
});
+ it.each(['search', 'open_page', 'find_in_page'])(
+ 'replays GPT-6.1 Sol %s history with native web_search on the Gateway route only',
+ async (actionType) => {
+ 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: 'web_search_call', status: 'completed', action: { type: actionType } },
+ { role: 'user', content: 'Continue' },
+ ];
+ const ctx = { method: 'POST', url: '/responses', headers: { 'thread-id': 'search-history-thread' } };
+ const apply = (request: unknown): unknown => {
+ let current = request;
+ for (const transform of transforms) {
+ const next = transform(current, ctx);
+ if (next !== null && next !== undefined) current = next;
+ }
+ return current;
+ };
+
+ expect(apply({ model: 'openai-codex/gpt-6.1-sol', input, tools: [{ type: 'function', name: 'read_file' }] }))
+ .toMatchObject({ input, tools: [{ type: 'function', name: 'read_file' }, { type: 'web_search' }] });
+ expect(apply({ model: 'openai-codex/gpt-6.1-sol', input, tools: [{ type: 'web_search', external_web_access: false }] }))
+ .toMatchObject({ input, tools: [{ type: 'web_search', external_web_access: false }] });
+ expect(apply({ model: 'openai-codex/gpt-6.1-sol', input: [{ role: 'user', content: 'Hello' }] }))
+ .not.toHaveProperty('tools');
+ for (const status of ['in_progress', 'failed']) {
+ expect(apply({
+ model: 'openai-codex/gpt-6.1-sol',
+ input: [{ type: 'web_search_call', status, action: { type: actionType } }],
+ })).not.toHaveProperty('tools');
+ }
+ expect(apply({ model: 'openai-codex/gpt-6.1-luna', input })).not.toHaveProperty('tools');
+ },
+ );
+
+ it('does not add GPT-6.1 search declaration to the subscription OAuth route', async () => {
+ const host = await freshCodexProxyHost();
+ mockState.createAnthropicCompatProxy.mockResolvedValueOnce({
+ url: 'http://127.0.0.1:43210',
+ dispose: vi.fn(async () => undefined),
+ });
+ await host.ensureCodexControlPlaneProxyReady('oauth-bearer');
+ const transforms = mockState.createAnthropicCompatProxy.mock.calls[0]?.[0]?.transformRequest ?? [];
+ let current: unknown = {
+ model: 'gpt-6.1-sol',
+ input: [{ type: 'web_search_call', status: 'completed', action: { type: 'search' } }],
+ };
+ const ctx = { method: 'POST', url: '/responses', headers: { 'thread-id': 'oauth-search-history-thread' } };
+ for (const transform of transforms) {
+ const next = transform(current, ctx);
+ if (next !== null && next !== undefined) current = next;
+ }
+ expect(current).not.toHaveProperty('tools');
+ });
+
it('keeps the codex/ budget prefix on the wire for an explicit Gateway session (no silent tier rewrite)', async () => {
const host = await freshCodexProxyHost();
const { BUNDLED_CATALOG } = 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.ts
index 56094828db..26810e4f29 100644
--- a/apps/desktop/src/main/maker-host/codex-proxy-host.ts
+++ b/apps/desktop/src/main/maker-host/codex-proxy-host.ts
@@ -864,10 +864,11 @@ function createProviderAwareGuardianReviewerTransform(
}
/**
- * Codex Code Mode 对部分 GPT-5.6 网关模型不会发出 Responses 原生搜索声明:
+ * Codex Code Mode 对部分网关模型不会发出 Responses 原生搜索声明:
* 目录里的 `supports_search_tool` / `webSearch` 能力虽为 true,但 Gateway 只看最终
* 请求的 `tools`。插件搜索是增强项,不能作为该基础能力的前置条件,因此在明确走
- * Cindy Gateway 的 GPT-5.6 请求中补回标准 `web_search` 工具;已有声明保持原样。
+ * Cindy Gateway 的 GPT-5.6 请求中补回标准 `web_search` 工具;GPT-6.1 Sol 仅在回放
+ * 已完成的搜索历史时补齐声明。已有声明保持原样。
*/
function createGatewayNativeWebSearchTransform(frozenAuthInjection?: CodexProxyAuthInjection): RequestTransform {
return (body, ctx) => {
@@ -885,7 +886,11 @@ function createGatewayNativeWebSearchTransform(frozenAuthInjection?: CodexProxyA
?? inferProviderIdForModel(model, 'codex')
?? rewrittenGatewayProviderId;
const gatewayModel = stripCodexGatewayWirePrefix(model);
- if (!/^gpt-5\.6(?:$|[-.])/.test(gatewayModel)) return null;
+ const replaysSearchHistory = Array.isArray(body.input) && body.input.some(
+ (item) => isPlainObject(item) && item.type === 'web_search_call' && item.status === 'completed',
+ );
+ if (!/^gpt-5\.6(?:$|[-.])/.test(gatewayModel)
+ && !(gatewayModel === 'gpt-6.1-sol' && replaysSearchHistory)) return null;
// 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.