fix(shared-chat): handle empty tool call arguments in executeTool (#266)
* fix(shared-chat): handle empty tool call arguments in executeTool
When an LLM calls a tool with no parameters (e.g. empty object schema),
some providers stream no argument deltas, leaving the accumulated
arguments as an empty string. `JSON.parse("")` then throws
"Unexpected end of JSON input". Fallback to `'{}'` for empty strings.
* refactor: apply review
---------
Co-authored-by: 藍+85CD <50108258+kwaa@users.noreply.github.com>
This commit is contained in:
1 parent
d9c6f75971
commit
e23b9da368
1 file changed
+1
-1
@@ -32,7 +32,7 @@ export const executeTool = async ({ abortSignal, messages, toolCall, tools }: Ex
|
||||
if (toolCall.function.arguments == null)
|
||||
throw new Error(`Missing toolCall.function.arguments: ${JSON.stringify(toolCall)}`)
|
||||
|
||||
const parsedArgs = JSON.parse(toolCall.function.arguments) as Record<string, unknown>
|
||||
const parsedArgs = JSON.parse(toolCall.function.arguments.trim() || '{}') as Record<string, unknown>
|
||||
const result = wrapToolResult(await tool.execute(parsedArgs, {
|
||||
abortSignal,
|
||||
messages,
|
||||
|
||||
Reference in new issue
Block a user