fix(ai): tolerate malformed trailing tool-call JSON in OpenAI streams closes #1424

This commit is contained in:
Mario Zechner 2026-02-12 21:09:33 +01:00
parent 5ddb04f74a
commit ed0cfcbda2
2 changed files with 3 additions and 3 deletions

View file

@ -129,7 +129,7 @@ export const streamOpenAICompletions: StreamFunction<"openai-completions", OpenA
partial: output,
});
} else if (block.type === "toolCall") {
block.arguments = JSON.parse(block.partialArgs || "{}");
block.arguments = parseStreamingJson(block.partialArgs);
delete block.partialArgs;
stream.push({
type: "toolcall_end",

View file

@ -414,8 +414,8 @@ export async function processResponsesStream<TApi extends Api>(
} else if (item.type === "function_call") {
const args =
currentBlock?.type === "toolCall" && currentBlock.partialJson
? JSON.parse(currentBlock.partialJson)
: JSON.parse(item.arguments);
? parseStreamingJson(currentBlock.partialJson)
: parseStreamingJson(item.arguments || "{}");
const toolCall: ToolCall = {
type: "toolCall",
id: `${item.call_id}|${item.id}`,