fix: support object-type arguments in tool call parsing

Add type check in safeParseToolCallArgs to handle cases where
toolCall.function.arguments is already an object instead of a JSON string.
This prevents parameter loss and 'argument is required' errors in tool calls.
This commit is contained in:
silencezhoudev 2026-01-21 18:16:12 +08:00
parent d95384f612
commit 82f6f69522

View file

@ -3,6 +3,17 @@ import { ToolCallDelta } from "..";
export function safeParseToolCallArgs(
toolCall: ToolCallDelta,
): Record<string, any> {
const args = toolCall.function?.arguments;
if (
args &&
typeof args === "object" &&
!Array.isArray(args) &&
Object.keys(args).length > 0
) {
return args;
}
try {
return JSON.parse(toolCall.function?.arguments?.trim() || "{}");
} catch (e) {