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:
parent
d95384f612
commit
82f6f69522
1 changed files with 11 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue