@@ -34,6 +34,7 @@ import {
34
34
} from "@/agent/subscriber" ;
35
35
import { Observable } from "rxjs" ;
36
36
import { AbstractAgent } from "@/agent/agent" ;
37
+ import untruncateJson from "untruncate-json" ;
37
38
38
39
export const defaultApplyEvents = (
39
40
input : RunAgentInput ,
@@ -218,6 +219,12 @@ export const defaultApplyEvents = (
218
219
toolCalls . length > 0 ? toolCalls [ toolCalls . length - 1 ] . function . arguments : "" ;
219
220
const toolCallName =
220
221
toolCalls . length > 0 ? toolCalls [ toolCalls . length - 1 ] . function . name : "" ;
222
+ let partialToolCallArgs = { } ;
223
+ try {
224
+ partialToolCallArgs = untruncateJson (
225
+ toolCallBuffer + ( event as ToolCallArgsEvent ) . delta ,
226
+ ) ;
227
+ } catch ( error ) { }
221
228
222
229
return subscriber . onToolCallArgsEvent ?.( {
223
230
event : event as ToolCallArgsEvent ,
@@ -227,6 +234,7 @@ export const defaultApplyEvents = (
227
234
input,
228
235
toolCallBuffer,
229
236
toolCallName,
237
+ partialToolCallArgs,
230
238
} ) ;
231
239
} ,
232
240
) ;
@@ -258,18 +266,22 @@ export const defaultApplyEvents = (
258
266
( subscriber , messages , state ) => {
259
267
const toolCalls =
260
268
( messages [ messages . length - 1 ] as AssistantMessage ) ?. toolCalls ?? [ ] ;
261
- const toolCallBuffer =
269
+ const toolCallArgsString =
262
270
toolCalls . length > 0 ? toolCalls [ toolCalls . length - 1 ] . function . arguments : "" ;
263
271
const toolCallName =
264
272
toolCalls . length > 0 ? toolCalls [ toolCalls . length - 1 ] . function . name : "" ;
273
+ let toolCallArgs = { } ;
274
+ try {
275
+ toolCallArgs = JSON . parse ( toolCallArgsString ) ;
276
+ } catch ( error ) { }
265
277
return subscriber . onToolCallEndEvent ?.( {
266
278
event : event as ToolCallEndEvent ,
267
279
messages,
268
280
state,
269
281
agent,
270
282
input,
271
- toolCallBuffer,
272
283
toolCallName,
284
+ toolCallArgs,
273
285
} ) ;
274
286
} ,
275
287
) ;
0 commit comments