11/**
22 * @license
3- * Copyright 2025 Google LLC
3+ * Copyright 2026 Google LLC
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
@@ -67,7 +67,6 @@ import {CanvasComponent} from '../canvas/canvas.component';
6767import { ChatPanelComponent } from '../chat-panel/chat-panel.component' ;
6868import { EditJsonDialogComponent } from '../edit-json-dialog/edit-json-dialog.component' ;
6969import { EvalTabComponent } from '../eval-tab/eval-tab.component' ;
70- import { PendingEventDialogComponent } from '../pending-event-dialog/pending-event-dialog.component' ;
7170import { DeleteSessionDialogComponent , DeleteSessionDialogData , } from '../session-tab/delete-session-dialog/delete-session-dialog.component' ;
7271import { SidePanelComponent } from '../side-panel/side-panel.component' ;
7372import { TraceEventComponent } from '../trace-tab/trace-event/trace-event.component' ;
@@ -929,29 +928,35 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
929928 }
930929
931930 if ( e ?. longRunningToolIds && e . longRunningToolIds . length > 0 ) {
931+ const startIndex = this . longRunningEvents . length ;
932932 this . getAsyncFunctionsFromParts (
933933 e . longRunningToolIds , e . content . parts , e . invocationId ) ;
934- const func = this . longRunningEvents [ 0 ] . function ;
935- if ( func . args . authConfig &&
936- func . args . authConfig . exchangedAuthCredential &&
937- func . args . authConfig . exchangedAuthCredential . oauth2 ) {
938- // for OAuth
939- const authUri =
940- func . args . authConfig . exchangedAuthCredential . oauth2 . authUri ;
941- const updatedAuthUri = this . updateRedirectUri (
942- authUri ,
943- this . redirectUri ,
944- ) ;
945- this . openOAuthPopup ( updatedAuthUri )
946- . then ( ( authResponseUrl ) => {
947- this . functionCallEventId = e . id ;
948- this . sendOAuthResponse ( func , authResponseUrl , this . redirectUri ) ;
949- } )
950- . catch ( ( error ) => {
951- console . error ( 'OAuth Error:' , error ) ;
952- } ) ;
953- } else {
954- this . functionCallEventId = e . id ;
934+
935+ // Store event ID for later reference
936+ this . functionCallEventId = e . id ;
937+
938+ // Check all newly added events for OAuth requirements
939+ for ( let i = startIndex ; i < this . longRunningEvents . length ; i ++ ) {
940+ const func = this . longRunningEvents [ i ] . function ;
941+ if ( func . args . authConfig &&
942+ func . args . authConfig . exchangedAuthCredential &&
943+ func . args . authConfig . exchangedAuthCredential . oauth2 ) {
944+ // for OAuth
945+ const authUri =
946+ func . args . authConfig . exchangedAuthCredential . oauth2 . authUri ;
947+ const updatedAuthUri = this . updateRedirectUri (
948+ authUri ,
949+ this . redirectUri ,
950+ ) ;
951+ this . openOAuthPopup ( updatedAuthUri )
952+ . then ( ( authResponseUrl ) => {
953+ this . sendOAuthResponse ( func , authResponseUrl , this . redirectUri ) ;
954+ } )
955+ . catch ( ( error ) => {
956+ console . error ( 'OAuth Error:' , error ) ;
957+ } ) ;
958+ break ; // Handle one OAuth at a time
959+ }
955960 }
956961 }
957962 if ( e ?. actions && e . actions . artifactDelta ) {
@@ -1009,7 +1014,21 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
10091014 }
10101015 message . eventId = e ?. id ;
10111016 } else if ( part . functionCall ) {
1012- message . functionCalls = [ part . functionCall ] ;
1017+ // Enrich function call with long-running metadata if applicable
1018+ const isLongRunning =
1019+ e ?. longRunningToolIds ?. includes ( part . functionCall . id ) ;
1020+ const enrichedFunctionCall = {
1021+ ...part . functionCall ,
1022+ ...( isLongRunning && {
1023+ isLongRunning : true ,
1024+ invocationId : e . invocationId ,
1025+ functionCallEventId : e . id ,
1026+ needsResponse : true ,
1027+ responseStatus : 'pending' ,
1028+ userResponse : '' ,
1029+ } ) ,
1030+ } ;
1031+ message . functionCalls = [ enrichedFunctionCall ] ;
10131032 message . eventId = e ?. id ;
10141033 } else if ( part . functionResponse ) {
10151034 message . functionResponses = [ part . functionResponse ] ;
@@ -1297,7 +1316,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
12971316 } ) ;
12981317 }
12991318
1300- private processRunSseResponse ( response : any ) {
1319+ protected processRunSseResponse ( response : any ) {
13011320 for ( const e of response ) {
13021321 if ( e . content ) {
13031322 for ( let part of e . content . parts ) {
@@ -1307,33 +1326,6 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
13071326 }
13081327 }
13091328
1310- openDialog ( ) : void {
1311- const dialogRef = this . dialog . open ( PendingEventDialogComponent , {
1312- width : '600px' ,
1313- data : {
1314- event : this . longRunningEvents [ 0 ] . function ,
1315- appName : this . appName ,
1316- userId : this . userId ,
1317- sessionId : this . sessionId ,
1318- functionCallEventId : this . functionCallEventId ,
1319- invocationId : this . longRunningEvents [ 0 ] . invocationId
1320- } ,
1321- } ) ;
1322-
1323- dialogRef . afterClosed ( ) . subscribe ( ( t ) => {
1324- if ( t ) {
1325- this . removeFinishedLongRunningEvents ( t . events ) ;
1326- this . processRunSseResponse ( t . response ) ;
1327- this . changeDetectorRef . detectChanges ( ) ;
1328- }
1329- } ) ;
1330- }
1331-
1332- removeFinishedLongRunningEvents ( finishedEvents : any [ ] ) {
1333- const idsToExclude = new Set ( finishedEvents . map ( ( obj : any ) => obj . id ) ) ;
1334- this . longRunningEvents =
1335- this . longRunningEvents . filter ( obj => ! idsToExclude . has ( obj . id ) ) ;
1336- }
13371329
13381330 createAgentIconColorClass ( agentName : string ) {
13391331 const agentIconColor = this . stringToColorService . stc ( agentName ) ;
0 commit comments