@@ -707,6 +707,12 @@ export class ModelResult<
707707 > | null = null ;
708708 private uiBroadcaster : ToolEventBroadcaster < ToolUiFragmentEvent > | null = null ;
709709 private pendingUiFragments = new Set < Promise < void > > ( ) ;
710+ private queuedUiToolResults : Array < {
711+ callId : string ;
712+ name : string ;
713+ input : Record < string , unknown > ;
714+ output : unknown ;
715+ } > = [ ] ;
710716 private uiBroadcasterCompletionPromise : Promise < void > | null = null ;
711717 private turnBroadcasterCompletionPromise : Promise < void > | null = null ;
712718 private initialStreamPipeStarted = false ;
@@ -2775,10 +2781,12 @@ export class ModelResult<
27752781 }
27762782
27772783 const registry = this . ensureAsyncToolRegistry ( ) ;
2784+ const input = ( tc . arguments ?? { } ) as Record < string , unknown > ;
27782785 const liveTask = registry . trackDeferred ( {
27792786 callId : tc . id ,
27802787 taskId : invocation . taskId ,
27812788 name : String ( tc . name ) ,
2789+ input,
27822790 ...( invocation . pollAfterMs !== undefined && {
27832791 pollAfterMs : invocation . pollAfterMs ,
27842792 } ) ,
@@ -2793,6 +2801,7 @@ export class ModelResult<
27932801 mode : 'defer' ,
27942802 status : 'working' ,
27952803 startedAt : liveTask . startedAt ,
2804+ input,
27962805 ...( invocation . pollAfterMs !== undefined && {
27972806 pollAfterMs : invocation . pollAfterMs ,
27982807 } ) ,
@@ -3797,10 +3806,12 @@ export class ModelResult<
37973806 if ( collision ) {
37983807 return collision ;
37993808 }
3809+ const input = ( toolCall . arguments ?? { } ) as Record < string , unknown > ;
38003810 const liveTask = registry . trackDeferred ( {
38013811 callId : toolCall . id ,
38023812 taskId : invocation . taskId ,
38033813 name : String ( toolCall . name ) ,
3814+ input,
38043815 ...( invocation . expiresAt !== undefined && {
38053816 expiresAt : invocation . expiresAt ,
38063817 } ) ,
@@ -3816,6 +3827,7 @@ export class ModelResult<
38163827 mode : 'defer' ,
38173828 status : 'working' ,
38183829 startedAt : liveTask . startedAt ,
3830+ input,
38193831 ...( invocation . pollAfterMs !== undefined && {
38203832 pollAfterMs : invocation . pollAfterMs ,
38213833 } ) ,
@@ -4422,6 +4434,41 @@ export class ModelResult<
44224434 } ;
44234435 }
44244436
4437+ /** @internal Queue externally resumed tool results for the UI lifecycle. */
4438+ queueUiToolResults (
4439+ results : Array < {
4440+ callId : string ;
4441+ name : string ;
4442+ input : Record < string , unknown > ;
4443+ output : unknown ;
4444+ } > ,
4445+ ) : void {
4446+ this . queuedUiToolResults . push ( ...results ) ;
4447+ }
4448+
4449+ private dispatchQueuedUiToolResults ( ) : void {
4450+ const queued = this . queuedUiToolResults ;
4451+ this . queuedUiToolResults = [ ] ;
4452+ for ( const result of queued ) {
4453+ const tool = this . options . tools ?. find (
4454+ ( candidate ) => isClientTool ( candidate ) && candidate . function . name === result . name ,
4455+ ) ;
4456+ if ( tool ) {
4457+ this . dispatchUiFragment ( {
4458+ toolCall : {
4459+ id : result . callId ,
4460+ name : result . name ,
4461+ arguments : result . input ,
4462+ } as ParsedToolCall < Tool > ,
4463+ tool,
4464+ result : {
4465+ result : result . output ,
4466+ } ,
4467+ } ) ;
4468+ }
4469+ }
4470+ }
4471+
44254472 private dispatchUiFragment ( value : {
44264473 toolCall : ParsedToolCall < Tool > ;
44274474 tool : Tool ;
@@ -6945,9 +6992,8 @@ export class ModelResult<
69456992 */
69466993 getUiStream ( ) : AsyncIterableIterator < UiStreamEvent > {
69476994 return async function * ( this : ModelResult < TTools , TShared > ) {
6948- await this . initStreamGuarded ( ) ;
6949-
69506995 if ( ! this . options . tools ?. length ) {
6996+ await this . initStreamGuarded ( ) ;
69516997 let streamFailed = false ;
69526998 try {
69536999 if ( this . reusableStream ) {
@@ -6973,6 +7019,8 @@ export class ModelResult<
69737019 const uiBroadcaster = this . uiBroadcaster ;
69747020 const uiConsumer = uiBroadcaster . createConsumer ( ) ;
69757021 try {
7022+ this . dispatchQueuedUiToolResults ( ) ;
7023+ await this . initStreamGuarded ( ) ;
69767024 const { consumer, executionPromise } = this . startTurnBroadcasterExecution ( ) ;
69777025 if ( ! this . uiBroadcasterCompletionPromise ) {
69787026 this . uiBroadcasterCompletionPromise = executionPromise . finally ( async ( ) => {
0 commit comments