diff --git a/open-sse/handlers/chatCore/sanitization.ts b/open-sse/handlers/chatCore/sanitization.ts index 62b43615ed..b93f3ac2c3 100644 --- a/open-sse/handlers/chatCore/sanitization.ts +++ b/open-sse/handlers/chatCore/sanitization.ts @@ -46,7 +46,7 @@ export function sanitizeChatRequestBody( } if (Array.isArray(body.tools)) { - body.tools = body.tools.filter((tool: Record) => { + const tools = body.tools.filter((tool: Record) => { const toolType = typeof tool.type === "string" ? tool.type : ""; if (toolType && toolType !== "function" && !tool.function && tool.name === undefined) { return true; @@ -56,7 +56,7 @@ export function sanitizeChatRequestBody( return name && String(name).trim().length > 0; }); - body.tools = body.tools.map((tool) => sanitizeOpenAITool(tool) as (typeof body.tools)[number]); + body.tools = tools.map((tool) => sanitizeOpenAITool(tool)); } return body; diff --git a/tests/unit/chatcore-extracted-modules-3821.test.ts b/tests/unit/chatcore-extracted-modules-3821.test.ts index 009412f98e..e8a689f6ca 100644 --- a/tests/unit/chatcore-extracted-modules-3821.test.ts +++ b/tests/unit/chatcore-extracted-modules-3821.test.ts @@ -49,6 +49,7 @@ test("sanitizeChatRequestBody: strips empty message name and filters nameless to ], tools: [ { type: "function", function: { name: "real_tool", parameters: {} } }, + { type: "web_search_preview" }, { type: "function", function: { name: "" } }, // dropped — empty name { type: "function", function: {} }, // dropped — no name ], @@ -62,8 +63,9 @@ test("sanitizeChatRequestBody: strips empty message name and filters nameless to assert.equal(messages[1].name, "keepme", "non-empty name kept"); const tools = out.tools as Array>; - assert.equal(tools.length, 1, "only the named tool survives"); + assert.equal(tools.length, 2, "the named function and built-in tool survive"); assert.equal((tools[0].function as Record).name, "real_tool"); + assert.deepEqual(tools[1], { type: "web_search_preview" }); }); test("checkIdempotencyCache returns { hit:null, idempotencyKey } on a miss", async () => {