fix: preserve falsy tool argument values

This commit is contained in:
Maxim Ivanov
2026-05-30 08:58:13 +00:00
parent bd1098de16
commit 3767e130ea
2 changed files with 21 additions and 1 deletions

View File

@@ -16,7 +16,7 @@ function stripEmptyOptionalToolArgs(value) {
try {
const parsed = JSON.parse(value);
const cleaned = stripEmptyOptionalToolArgs(parsed);
return JSON.stringify(cleaned || {});
return JSON.stringify(cleaned ?? {});
} catch {
return value;
}

View File

@@ -242,6 +242,26 @@ test("Responses -> OpenAI: empty-name tool call is deferred until output_item.do
);
});
test("Responses -> OpenAI: preserves falsy JSON-string tool arguments while cleaning", () => {
const state = {};
openaiResponsesToOpenAIResponse(
{
type: "response.output_item.added",
item: { type: "function_call", call_id: "call_flag", name: "set_flag" },
},
state
);
const done = openaiResponsesToOpenAIResponse(
{
type: "response.output_item.done",
item: { type: "function_call", call_id: "call_flag", name: "set_flag", arguments: "false" },
},
state
);
assert.equal(done.choices[0].delta.tool_calls[0].function.arguments, "false");
});
test("Responses -> OpenAI: strips empty optional args from JSON-string output_item.done arguments", () => {
const state = {};
openaiResponsesToOpenAIResponse(