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: handle deprecated function_call field and function role in Chat→Responses
AveryanAlex213e7b709320
diff --git a/open-sse/translator/request/openai-responses.ts b/open-sse/translator/request/openai-responses.tsindex 18fc18418a..7b8086b3c6 100644--- a/open-sse/translator/request/openai-responses.ts+++ b/open-sse/translator/request/openai-responses.ts@@ -405,6 +405,20 @@ export function openaiToOpenAIResponsesRequest(});}}++ // Handle deprecated function_call field (pre-tool_calls API)+ if (msg.function_call && !msg.tool_calls) {+ const fc = toRecord(msg.function_call);+ const fnName = toString(fc.name).trim();+ if (fnName) {+ input.push({+ type: "function_call",+ call_id: `call_${fnName}`,+ name: fnName,+ arguments: toString(fc.arguments, "{}"),+ });+ }+ }}// Convert tool results@@ -423,6 +437,15 @@ export function openaiToOpenAIResponsesRequest(: String(msg.content ?? ""),});}++ // Handle deprecated function role messages+ if (role === "function") {+ input.push({+ type: "function_call_output",+ call_id: `call_${toString(msg.name)}`,+ output: typeof msg.content === "string" ? msg.content : String(msg.content ?? ""),+ });+ }}// Filter orphaned function_call_output items (no matching function_call)diff --git a/tests/unit/responses-translation-fixes.test.mjs b/tests/unit/responses-translation-fixes.test.mjsindex 5f581af49f..e3f0850219 100644--- a/tests/unit/responses-translation-fixes.test.mjs+++ b/tests/unit/responses-translation-fixes.test.mjs@@ -299,3 +299,45 @@ test("Responses→Chat: function tool type passes through", () => {assert.equal(result.tools.length, 1);assert.equal(result.tools[0].type, "function");});++test("Chat→Responses: deprecated function_call field on assistant converted to function_call item", () => {+ const body = {+ model: "gpt-4",+ messages: [+ { role: "user", content: "weather?" },+ {+ role: "assistant",+ content: null,+ function_call: { name: "get_weather", arguments: '{"city":"NYC"}' },+ },+ ],+ };+ const result = openaiToOpenAIResponsesRequest("gpt-4", body, true, null);+ const fcItem = result.input.find((i) => i.type === "function_call");+ assert.ok(fcItem, "should have function_call input item");+ assert.equal(fcItem.name, "get_weather");+ assert.equal(fcItem.arguments, '{"city":"NYC"}');+ assert.ok(fcItem.call_id, "should have a call_id");+});++test("Chat→Responses: deprecated function role message converted to function_call_output", () => {+ const body = {+ model: "gpt-4",+ messages: [+ { role: "user", content: "weather?" },+ {+ role: "assistant",+ content: null,+ function_call: { name: "get_weather", arguments: '{"city":"NYC"}' },+ },+ { role: "function", name: "get_weather", content: '{"temp":72}' },+ ],+ };+ const result = openaiToOpenAIResponsesRequest("gpt-4", body, true, null);+ const fcOutput = result.input.find((i) => i.type === "function_call_output");+ assert.ok(fcOutput, "should have function_call_output item");+ assert.equal(fcOutput.output, '{"temp":72}');+ // The call_ids should match between function_call and function_call_output+ const fcItem = result.input.find((i) => i.type === "function_call");+ assert.equal(fcOutput.call_id, fcItem.call_id);+});