mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 10:02:23 +00:00
Merge pull request #917 from williballenthin/fix-call-arguments-done
fix(ai): handle call arguments done on OpenAI-compatible endpoints
This commit is contained in:
commit
72de8f26a1
1 changed files with 13 additions and 2 deletions
|
|
@ -231,6 +231,13 @@ export const streamOpenAIResponses: StreamFunction<"openai-responses"> = (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Handle function call arguments done (some providers send this instead of deltas)
|
||||||
|
else if (event.type === "response.function_call_arguments.done") {
|
||||||
|
if (currentItem?.type === "function_call" && currentBlock?.type === "toolCall") {
|
||||||
|
currentBlock.partialJson = event.arguments;
|
||||||
|
currentBlock.arguments = parseStreamingJson(currentBlock.partialJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Handle output item completion
|
// Handle output item completion
|
||||||
else if (event.type === "response.output_item.done") {
|
else if (event.type === "response.output_item.done") {
|
||||||
const item = event.item;
|
const item = event.item;
|
||||||
|
|
@ -256,13 +263,17 @@ export const streamOpenAIResponses: StreamFunction<"openai-responses"> = (
|
||||||
});
|
});
|
||||||
currentBlock = null;
|
currentBlock = null;
|
||||||
} else if (item.type === "function_call") {
|
} else if (item.type === "function_call") {
|
||||||
|
const args =
|
||||||
|
currentBlock?.type === "toolCall" && currentBlock.partialJson
|
||||||
|
? JSON.parse(currentBlock.partialJson)
|
||||||
|
: JSON.parse(item.arguments);
|
||||||
const toolCall: ToolCall = {
|
const toolCall: ToolCall = {
|
||||||
type: "toolCall",
|
type: "toolCall",
|
||||||
id: `${item.call_id}|${item.id}`,
|
id: `${item.call_id}|${item.id}`,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
arguments: JSON.parse(item.arguments),
|
arguments: args,
|
||||||
};
|
};
|
||||||
|
currentBlock = null;
|
||||||
stream.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });
|
stream.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue