Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix: preserve built-in Responses API tool types in empty-name filter (#1014)
Randi3d9503658b8e
diff --git a/open-sse/handlers/chatCore.ts b/open-sse/handlers/chatCore.tsindex 3631f708d0..f024da8dbb 100644--- a/open-sse/handlers/chatCore.ts+++ b/open-sse/handlers/chatCore.ts@@ -851,6 +851,12 @@ export async function handleChatCore({// upstream providers to reject with 400 "Invalid 'tools[0].name': empty string."if (Array.isArray(body.tools)) {body.tools = body.tools.filter((tool: Record<string, unknown>) => {+ // Built-in Responses API tool types (web_search, file_search, computer, etc.)+ // are identified solely by their `type` field and carry no name — preserve them.+ const toolType = typeof tool.type === "string" ? tool.type : "";+ if (toolType && toolType !== "function" && !tool.function && tool.name === undefined) {+ return true;+ }const fn = tool.function as Record<string, unknown> | undefined;const name = fn?.name ?? tool.name;return name && String(name).trim().length > 0;diff --git a/tests/unit/tools-filter-anthropic-format.test.mjs b/tests/unit/tools-filter-anthropic-format.test.mjsindex 6d3c38769d..af2e4b79b4 100644--- a/tests/unit/tools-filter-anthropic-format.test.mjs+++ b/tests/unit/tools-filter-anthropic-format.test.mjs@@ -10,9 +10,15 @@import { describe, it } from "node:test";import assert from "node:assert/strict";-// Inline the filter logic from chatCore.ts (lines 225-231 after #397 fix)+// Inline the filter logic from chatCore.ts (after #397 fix + built-in tool type preservation)function filterEmptyNameTools(tools) {return tools.filter((tool) => {+ // Built-in Responses API tool types (web_search, file_search, computer, etc.)+ // are identified solely by their `type` field and carry no name — preserve them.+ const toolType = typeof tool.type === "string" ? tool.type : "";+ if (toolType && toolType !== "function" && !tool.function && tool.name === undefined) {+ return true;+ }const fn = tool.function;const name = fn?.name ?? tool.name;return name && String(name).trim().length > 0;@@ -90,4 +96,42 @@ describe("tools empty-name filter — #346 / PR #397", () => {];assert.equal(filterEmptyNameTools(tools).length, 0);});++ it("should preserve built-in Responses API web_search tool (no name field)", () => {+ const tools = [{ type: "web_search", external_web_access: true }];+ assert.equal(filterEmptyNameTools(tools).length, 1);+ });++ it("should preserve built-in Responses API tools without names (file_search, computer)", () => {+ const tools = [+ { type: "file_search" },+ { type: "computer", display_width: 1024, display_height: 768 },+ { type: "code_interpreter" },+ { type: "image_generation", output_format: "png" },+ ];+ assert.equal(filterEmptyNameTools(tools).length, 4);+ });++ it("should preserve web_search alongside function tools and still drop empty-name functions", () => {+ const tools = [+ { type: "web_search", external_web_access: true },+ { type: "function", function: { name: "exec_command", description: "Run a command" } },+ { type: "function", function: { name: "" } },+ { type: "custom", name: "apply_patch" },+ ];+ const result = filterEmptyNameTools(tools);+ assert.equal(result.length, 3, "Should keep web_search, exec_command, and apply_patch");+ assert.ok(+ result.some((t) => t.type === "web_search"),+ "web_search preserved"+ );+ assert.ok(+ result.some((t) => t.function?.name === "exec_command"),+ "exec_command preserved"+ );+ assert.ok(+ result.some((t) => t.name === "apply_patch"),+ "apply_patch preserved"+ );+ });});