From e23b9da36883222dbd23d2ec1e508f26cb2eacda Mon Sep 17 00:00:00 2001 From: Liet Blue <127093491+lietblue@users.noreply.github.com> Date: Tue, 3 Mar 2026 01:11:06 +0800 Subject: [PATCH] fix(shared-chat): handle empty tool call arguments in executeTool (#266) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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> --- packages/shared-chat/src/utils/execute-tool.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared-chat/src/utils/execute-tool.ts b/packages/shared-chat/src/utils/execute-tool.ts index c82791e..e7213e9 100644 --- a/packages/shared-chat/src/utils/execute-tool.ts +++ b/packages/shared-chat/src/utils/execute-tool.ts @@ -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 + const parsedArgs = JSON.parse(toolCall.function.arguments.trim() || '{}') as Record const result = wrapToolResult(await tool.execute(parsedArgs, { abortSignal, messages,