diff --git a/packages/react-ai-sdk/src/ui/utils/useVercelAIThreadSync.tsx b/packages/react-ai-sdk/src/ui/utils/useVercelAIThreadSync.tsx index 18b8ee1a9..096c791cf 100644 --- a/packages/react-ai-sdk/src/ui/utils/useVercelAIThreadSync.tsx +++ b/packages/react-ai-sdk/src/ui/utils/useVercelAIThreadSync.tsx @@ -72,6 +72,7 @@ const vercelToThreadMessage = ( type: "tool-call", toolName: t.toolName, toolCallId: t.toolCallId, + argsText: JSON.stringify(t.args), args: t.args, result: "result" in t ? t.result : undefined, }) satisfies ToolCallContentPart, diff --git a/packages/react/src/runtimes/edge/streams/runResultStream.ts b/packages/react/src/runtimes/edge/streams/runResultStream.ts index ccc2120c8..91121b0c5 100644 --- a/packages/react/src/runtimes/edge/streams/runResultStream.ts +++ b/packages/react/src/runtimes/edge/streams/runResultStream.ts @@ -31,7 +31,7 @@ export function runResultStream() { message, toolCallId, toolName, - parsePartialJson(currentToolCall.argsText), + currentToolCall.argsText, ); controller.enqueue(message); break; @@ -85,7 +85,7 @@ const appendOrUpdateToolCall = ( message: ChatModelRunResult, toolCallId: string, toolName: string, - args: unknown, + argsText: string, ) => { let contentParts = message.content; let contentPart = message.content.at(-1); @@ -97,13 +97,15 @@ const appendOrUpdateToolCall = ( type: "tool-call", toolCallId, toolName, - args, + argsText, + args: parsePartialJson(argsText), }; } else { contentParts = contentParts.slice(0, -1); contentPart = { ...contentPart, - args, + argsText, + args: parsePartialJson(argsText), }; } return { diff --git a/packages/react/src/types/AssistantTypes.ts b/packages/react/src/types/AssistantTypes.ts index 011afef36..4db37879f 100644 --- a/packages/react/src/types/AssistantTypes.ts +++ b/packages/react/src/types/AssistantTypes.ts @@ -23,8 +23,10 @@ export type ToolCallContentPart = { type: "tool-call"; toolCallId: string; toolName: string; + argsText: string; args: TArgs; result?: TResult; + isError?: boolean; }; export type ThreadUserContentPart =