@@ -369,6 +369,11 @@ export async function handleToolExecutionStart(
369369 ) ;
370370
371371 const shouldEmitToolEvents = ctx . shouldEmitToolResult ( ) ;
372+ // Best-effort typing signal; do not block tool summaries on slow emitters.
373+ void ctx . params . onAgentEvent ?.( {
374+ stream : "tool" ,
375+ data : { phase : "start" , name : toolName , toolCallId } ,
376+ } ) ;
372377 emitAgentEvent ( {
373378 runId : ctx . params . runId ,
374379 stream : "tool" ,
@@ -379,11 +384,6 @@ export async function handleToolExecutionStart(
379384 args : args as Record < string , unknown > ,
380385 } ,
381386 } ) ;
382- // Best-effort typing signal; do not block tool summaries on slow emitters.
383- void ctx . params . onAgentEvent ?.( {
384- stream : "tool" ,
385- data : { phase : "start" , name : toolName , toolCallId } ,
386- } ) ;
387387
388388 if (
389389 ctx . params . onToolResult &&
@@ -430,22 +430,22 @@ export function handleToolExecutionUpdate(
430430 const toolCallId = String ( evt . toolCallId ) ;
431431 const partial = evt . partialResult ;
432432 const sanitized = sanitizeToolResult ( partial ) ;
433- emitAgentEvent ( {
434- runId : ctx . params . runId ,
433+ void ctx . params . onAgentEvent ?.( {
435434 stream : "tool" ,
436435 data : {
437436 phase : "update" ,
438437 name : toolName ,
439438 toolCallId,
440- partialResult : sanitized ,
441439 } ,
442440 } ) ;
443- void ctx . params . onAgentEvent ?.( {
441+ emitAgentEvent ( {
442+ runId : ctx . params . runId ,
444443 stream : "tool" ,
445444 data : {
446445 phase : "update" ,
447446 name : toolName ,
448447 toolCallId,
448+ partialResult : sanitized ,
449449 } ,
450450 } ) ;
451451}
@@ -549,26 +549,26 @@ export async function handleToolExecutionEnd(
549549 ctx . state . successfulCronAdds += 1 ;
550550 }
551551
552- emitAgentEvent ( {
553- runId : ctx . params . runId ,
552+ void ctx . params . onAgentEvent ?.( {
554553 stream : "tool" ,
555554 data : {
556555 phase : "result" ,
557556 name : toolName ,
558557 toolCallId,
559558 meta,
560559 isError : isToolError ,
561- result : sanitizedResult ,
562560 } ,
563561 } ) ;
564- void ctx . params . onAgentEvent ?.( {
562+ emitAgentEvent ( {
563+ runId : ctx . params . runId ,
565564 stream : "tool" ,
566565 data : {
567566 phase : "result" ,
568567 name : toolName ,
569568 toolCallId,
570569 meta,
571570 isError : isToolError ,
571+ result : sanitizedResult ,
572572 } ,
573573 } ) ;
574574
0 commit comments