@@ -170,14 +170,6 @@ export const streamText = async (options: StreamTextOptions): Promise<StreamText
170
170
return
171
171
}
172
172
173
- const toolCall = step . choices [ state . index ] . message . tool_calls ! [ id ]
174
- try {
175
- toolCall . function . parsed_arguments = JSON . parse ( toolCall . function . arguments ) as Record < string , unknown >
176
- }
177
- catch ( error ) {
178
- state . toolCallErrors [ id ] = error as Error
179
- }
180
-
181
173
state . endedToolCallIDs . add ( id )
182
174
state . currentToolID = null
183
175
}
@@ -343,24 +335,26 @@ export const streamText = async (options: StreamTextOptions): Promise<StreamText
343
335
}
344
336
345
337
try {
346
- const { result} = await executeTool ( {
338
+ const { parsedArgs , result, toolName } = await executeTool ( {
347
339
abortSignal :options . abortSignal ,
348
340
messages :options . messages ,
349
341
toolCall,
350
342
tools :options . tools ,
351
343
} )
352
344
345
+ toolCall . function . parsed_arguments = parsedArgs
346
+
353
347
state . toolCallResults [ id ] = result
354
348
step . messages . push ( {
355
349
content :result ,
356
350
role :'tool' ,
357
351
tool_call_id :id ,
358
352
} )
359
353
step . toolResults . push ( {
360
- args :toolCall . function . parsed_arguments , // TODO: use parsedArgs from executeTool
354
+ args :parsedArgs ,
361
355
result,
362
356
toolCallId :id ,
363
- toolName : toolCall . function . name , // TODO: use toolName from executeTool
357
+ toolName,
364
358
} )
365
359
}
366
360
catch ( error ) {