Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- fix(translator): coerce the pending Responses tool-call id to a string before queueing it, restoring the API route typecheck gate that #16539 broke (`openai-responses.ts` TS2345)
2 changes: 1 addition & 1 deletion open-sse/translator/request/openai-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export function openaiResponsesToOpenAIRequest(
if (currentAssistantMsg) {
messages.push(currentAssistantMsg);
}
for (const toolCall of roleBasedToolCalls) pendingCallIds.push(toolCall.id);
for (const toolCall of roleBasedToolCalls) pendingCallIds.push(toString(toolCall.id));
currentAssistantMsg = {
role,
content,
Expand Down
82 changes: 82 additions & 0 deletions tests/unit/responses-role-tool-call-pending-ids.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import assert from "node:assert/strict";
import test from "node:test";
import { openaiResponsesToOpenAIRequest } from "../../open-sse/translator/request/openai-responses.ts";
import { toRecord } from "../../open-sse/translator/request/openai-responses/helpers.ts";

function translate(input: unknown[]) {
return toRecord(openaiResponsesToOpenAIRequest("gpt-4o", { input }, false, null)).messages;
}

function toolCall(id: unknown, name = "read") {
return { id, type: "function", function: { name, arguments: "{}" } };
}

test("role-based tool calls retain normalized string ids when pairing id-less outputs", () => {
assert.deepEqual(
translate([
{
role: "assistant",
content: null,
tool_calls: [toolCall(" call-first "), toolCall("call-second", "search")],
},
{ type: "function_call_output", output: "first result" },
{ type: "function_call_output", output: "second result" },
]),
[
{
role: "assistant",
content: null,
tool_calls: [toolCall("call-first"), toolCall("call-second", "search")],
},
{ role: "tool", tool_call_id: "call-first", content: "first result" },
{ role: "tool", tool_call_id: "call-second", content: "second result" },
]
);
});

test("invalid role-based call ids never enter the pending string-id queue", () => {
assert.deepEqual(
translate([
{
role: "assistant",
content: null,
tool_calls: [
toolCall(42),
toolCall(null),
toolCall({ id: "not-a-string" }),
toolCall(" "),
toolCall("invalid-name", ""),
toolCall("valid-call"),
],
},
{ type: "function_call_output", output: "valid result" },
]),
[
{ role: "assistant", content: null, tool_calls: [toolCall("valid-call")] },
{ role: "tool", tool_call_id: "valid-call", content: "valid result" },
]
);
});

test("an explicit role-tool result claims its id before the next id-less result", () => {
assert.deepEqual(
translate([
{
role: "assistant",
content: null,
tool_calls: [toolCall("call-first"), toolCall("call-second")],
},
{ role: "tool", tool_call_id: "call-second", content: "second result" },
{ role: "tool", content: "first result" },
]),
[
{
role: "assistant",
content: null,
tool_calls: [toolCall("call-first"), toolCall("call-second")],
},
{ role: "tool", tool_call_id: "call-second", content: "second result" },
{ role: "tool", tool_call_id: "call-first", content: "first result" },
]
);
});
Loading