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(bridge): fail closed when Chat bridge drops web_search (#2239)

mengfanyu9410-hub0863bd06406f
diff --git a/packages/responses-chat-bridge/src/__tests__/handler.test.ts b/packages/responses-chat-bridge/src/__tests__/handler.test.ts
index 3931015a38..fabd4cd1f2 100644
--- a/packages/responses-chat-bridge/src/__tests__/handler.test.ts
+++ b/packages/responses-chat-bridge/src/__tests__/handler.test.ts
@@ -73,6 +73,36 @@ describe('createResponsesChatHandler', () => {
expect(res.ended).toBe(true);
});
+ it('rejects a built-in web_search tool instead of silently dropping it', async () => {
+ const fetchImpl = vi.fn() as unknown as typeof fetch;
+ const warn = vi.fn();
+ const handler = createResponsesChatHandler({
+ upstreamBase: 'https://provider.example/v1',
+ buildHeaders: async () => ({}),
+ }, { fetchImpl, logger: { warn } });
+ const res = new FakeResponse();
+
+ await handler.handle({
+ parsedBody: {
+ model: 'custom-model',
+ input: [{ type: 'message', role: 'user', content: 'search' }],
+ tools: [{ type: 'web_search' }],
+ },
+ res: res as never,
+ });
+
+ expect(res.status).toBe(400);
+ expect(res.chunks.join('')).toContain('unsupported_feature');
+ expect(res.chunks.join('')).toContain('tools[0]');
+ expect(res.chunks.join('')).toContain('web_search');
+ expect(fetchImpl).not.toHaveBeenCalled();
+ expect(warn).toHaveBeenCalledTimes(1);
+ expect(warn).toHaveBeenCalledWith('responses-chat bridge rejected unsupported feature', {
+ model: 'custom-model',
+ feature: 'tools[0].web_search',
+ });
+ });
+
it('preserves the upstream base query when applying the chat path', async () => {
const fetchImpl = vi.fn(async () =>
streamResponse([
diff --git a/packages/responses-chat-bridge/src/handler.ts b/packages/responses-chat-bridge/src/handler.ts
index 5c214d9536..7556a1975b 100644
--- a/packages/responses-chat-bridge/src/handler.ts
+++ b/packages/responses-chat-bridge/src/handler.ts
@@ -165,6 +165,9 @@ export function createResponsesChatHandler(
model: realModel,
capabilities: provider.capabilities,
onDroppedTool: (type, index) => {
+ if (type === 'web_search') {
+ throw new UnsupportedResponsesFeatureError(`tools[${index}].web_search`);
+ }
log.warn?.('responses-chat bridge dropped non-function tool', { type, index });
},
});