Skip to content

Commit a210665

Browse files
hoonjicopybara-github
authored andcommitted
Removes unused ChatComponent code
No change in behavior. Cleans up unused variables. Most importantly, removes the `eventMessageIndexArray` variable and removes "index" params from methods like `processPart()` . PiperOrigin-RevId: 819459180
1 parent f481c13 commit a210665

File tree

1 file changed

+27
-61
lines changed

1 file changed

+27
-61
lines changed

src/app/components/chat/chat.component.ts

Lines changed: 27 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,23 @@
1515
* limitations under the License.
1616
*/
1717

18-
import {CdkTextareaAutosize} from '@angular/cdk/text-field';
19-
import {AsyncPipe, DOCUMENT, Location, NgClass, NgStyle} from '@angular/common';
18+
import {AsyncPipe, DOCUMENT, Location, NgClass} from '@angular/common';
2019
import {HttpErrorResponse} from '@angular/common/http';
21-
import {AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, computed, ElementRef, HostListener, Inject, inject, Injectable, OnDestroy, OnInit, Renderer2, signal, viewChild, WritableSignal} from '@angular/core';
20+
import {AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, Inject, inject, Injectable, OnDestroy, OnInit, Renderer2, signal, viewChild, WritableSignal} from '@angular/core';
2221
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
23-
import {MatButton, MatFabButton, MatIconButton, MatMiniFabButton} from '@angular/material/button';
22+
import {MatButton, MatFabButton} from '@angular/material/button';
2423
import {MatCard} from '@angular/material/card';
2524
import {MatOption} from '@angular/material/core';
26-
import {MatDialog, MatDialogModule} from '@angular/material/dialog';
25+
import {MatDialog} from '@angular/material/dialog';
2726
import {MatDivider} from '@angular/material/divider';
2827
import {MatIcon} from '@angular/material/icon';
29-
import {MatInput} from '@angular/material/input';
30-
import {MatPaginator, MatPaginatorIntl} from '@angular/material/paginator';
31-
import {MatProgressBar} from '@angular/material/progress-bar';
28+
import {MatPaginatorIntl} from '@angular/material/paginator';
3229
import {MatSelect} from '@angular/material/select';
3330
import {MatDrawer, MatDrawerContainer} from '@angular/material/sidenav';
3431
import {MatSlideToggle} from '@angular/material/slide-toggle';
3532
import {MatSnackBar} from '@angular/material/snack-bar';
3633
import {MatTooltip} from '@angular/material/tooltip';
37-
import {DomSanitizer, SafeHtml} from '@angular/platform-browser';
34+
import {SafeHtml} from '@angular/platform-browser';
3835
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
3936
import {NgxJsonViewerModule} from 'ngx-json-viewer';
4037
import {BehaviorSubject, combineLatest, Observable, of} from 'rxjs';
@@ -53,25 +50,22 @@ import {EVENT_SERVICE, EventService} from '../../core/services/event.service';
5350
import {FEATURE_FLAG_SERVICE, FeatureFlagService} from '../../core/services/feature-flag.service';
5451
import {GRAPH_SERVICE, GraphService} from '../../core/services/graph.service';
5552
import {LOCAL_FILE_SERVICE, LocalFileService} from '../../core/services/interfaces/localfile';
56-
import {SAFE_VALUES_SERVICE, SafeValuesService} from '../../core/services/interfaces/safevalues';
53+
import {SAFE_VALUES_SERVICE} from '../../core/services/interfaces/safevalues';
5754
import {STRING_TO_COLOR_SERVICE} from '../../core/services/interfaces/string-to-color';
5855
import {SESSION_SERVICE, SessionService} from '../../core/services/session.service';
5956
import {STREAM_CHAT_SERVICE, StreamChatService} from '../../core/services/stream-chat.service';
6057
import {TRACE_SERVICE, TraceService} from '../../core/services/trace.service';
6158
import {ResizableBottomDirective} from '../../directives/resizable-bottom.directive';
6259
import {ResizableDrawerDirective} from '../../directives/resizable-drawer.directive';
63-
import {ArtifactTabComponent, getMediaTypeFromMimetype, MediaType} from '../artifact-tab/artifact-tab.component';
64-
import {AudioPlayerComponent} from '../audio-player/audio-player.component';
60+
import {getMediaTypeFromMimetype, MediaType} from '../artifact-tab/artifact-tab.component';
6561
import {ChatPanelComponent} from '../chat-panel/chat-panel.component';
6662
import {EditJsonDialogComponent} from '../edit-json-dialog/edit-json-dialog.component';
6763
import {EvalTabComponent} from '../eval-tab/eval-tab.component';
6864
import {PendingEventDialogComponent} from '../pending-event-dialog/pending-event-dialog.component';
6965
import {DeleteSessionDialogComponent, DeleteSessionDialogData,} from '../session-tab/delete-session-dialog/delete-session-dialog.component';
7066
import {SessionTabComponent} from '../session-tab/session-tab.component';
7167
import {SidePanelComponent} from '../side-panel/side-panel.component';
72-
import {StateTabComponent} from '../state-tab/state-tab.component';
7368
import {TraceEventComponent} from '../trace-tab/trace-event/trace-event.component';
74-
import {TraceTabComponent} from '../trace-tab/trace-tab.component';
7569
import {ViewImageDialogComponent} from '../view-image-dialog/view-image-dialog.component';
7670

7771
const ROOT_AGENT = 'root_agent';
@@ -178,17 +172,13 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
178172
currentSessionState: SessionState|undefined = {};
179173
root_agent = ROOT_AGENT;
180174
updatedSessionState: WritableSignal<any> = signal(null);
181-
private readonly streamingTextMessageSubject =
182-
new BehaviorSubject<any|null>(null);
183175
private readonly isModelThinkingSubject = new BehaviorSubject(false);
184-
private readonly scrollInterruptedSubject = new BehaviorSubject(false);
185176

186177
// TODO: Remove this once backend supports restarting bidi streaming.
187178
sessionHasUsedBidi = new Set<string>();
188179

189180
eventData = new Map<string, any>();
190181
traceData: any[] = [];
191-
eventMessageIndexArray: any[] = [];
192182
renderedEventGraph: SafeHtml | undefined;
193183
rawSvgString: string | null = null;
194184

@@ -202,7 +192,6 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
202192
getMediaTypeFromMimetype = getMediaTypeFromMimetype;
203193

204194
selectedFiles: { file: File; url: string }[] = [];
205-
private previousMessageCount = 0;
206195

207196
protected MediaType = MediaType;
208197

@@ -384,7 +373,6 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
384373
private createSessionAndReset() {
385374
this.createSession();
386375
this.eventData = new Map<string, any>();
387-
this.eventMessageIndexArray = [];
388376
this.messages.set([]);
389377
this.artifacts = [];
390378
this.userInput = '';
@@ -446,7 +434,6 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
446434
stateDelta: this.updatedSessionState(),
447435
};
448436
this.selectedFiles = [];
449-
let index = this.eventMessageIndexArray.length - 1;
450437
this.streamingTextMessage = null;
451438
this.agentService.runSse(req).subscribe({
452439
next: async (chunkJson: AdkEvent) => {
@@ -456,12 +443,11 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
456443
}
457444
if (chunkJson.content) {
458445
for (let part of chunkJson.content.parts) {
459-
index += 1;
460-
this.processPart(chunkJson, part, index);
446+
this.processPart(chunkJson, part);
461447
this.traceService.setEventData(this.eventData);
462448
}
463449
} else if (chunkJson.errorMessage) {
464-
this.processErrorMessage(chunkJson, index)
450+
this.processErrorMessage(chunkJson)
465451
}
466452
this.changeDetectorRef.detectChanges();
467453
},
@@ -492,13 +478,13 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
492478
this.changeDetectorRef.detectChanges();
493479
}
494480

495-
private processErrorMessage(chunkJson: any, index: number) {
496-
this.storeEvents(chunkJson, chunkJson, index);
481+
private processErrorMessage(chunkJson: any) {
482+
this.storeEvents(chunkJson, chunkJson);
497483
this.insertMessageBeforeLoadingMessage(
498484
{text: chunkJson.errorMessage, role: 'bot'})
499485
}
500486

501-
private processPart(chunkJson: any, part: any, index: number) {
487+
private processPart(chunkJson: any, part: any) {
502488
const renderedContent =
503489
chunkJson.groundingMetadata?.searchEntryPoint?.renderedContent;
504490

@@ -507,7 +493,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
507493
const newChunk = part.text;
508494
if (part.thought) {
509495
if (newChunk !== this.latestThought) {
510-
this.storeEvents(part, chunkJson, index);
496+
this.storeEvents(part, chunkJson);
511497
let thoughtMessage = {
512498
role: 'bot',
513499
text: this.processThoughtText(newChunk),
@@ -534,8 +520,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
534520
this.insertMessageBeforeLoadingMessage(this.streamingTextMessage);
535521

536522
if (!this.useSse) {
537-
this.storeEvents(part, chunkJson, index);
538-
this.eventMessageIndexArray[index] = newChunk;
523+
this.storeEvents(part, chunkJson);
539524
this.streamingTextMessage = null;
540525
return;
541526
}
@@ -546,19 +531,17 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
546531
}
547532

548533
if (newChunk == this.streamingTextMessage.text) {
549-
this.storeEvents(part, chunkJson, index);
550-
this.eventMessageIndexArray[index] = newChunk;
534+
this.storeEvents(part, chunkJson);
551535
this.streamingTextMessage = null;
552536
return;
553537
}
554538
this.streamingTextMessage.text += newChunk;
555-
this.streamingTextMessageSubject.next(this.streamingTextMessage);
556539
}
557540
} else if (!part.thought) {
558541
this.isModelThinkingSubject.next(false);
559-
this.storeEvents(part, chunkJson, index);
542+
this.storeEvents(part, chunkJson);
560543
this.storeMessage(
561-
part, chunkJson, index, chunkJson.author === 'user' ? 'user' : 'bot');
544+
part, chunkJson, chunkJson.author === 'user' ? 'user' : 'bot');
562545
} else {
563546
this.isModelThinkingSubject.next(true);
564547
}
@@ -593,7 +576,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
593576
}
594577

595578
private storeMessage(
596-
part: any, e: any, index: number, role: string, invocationIndex?: number,
579+
part: any, e: any, role: string, invocationIndex?: number,
597580
additionalIndeces?: any) {
598581
if (e?.author) {
599582
this.createAgentIconColorClass(e.author);
@@ -664,7 +647,6 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
664647
data: base64Data,
665648
mimeType: part.inlineData.mimeType,
666649
};
667-
this.eventMessageIndexArray[index] = part.inlineData;
668650
} else if (part.text) {
669651
message.text = part.text;
670652
message.thought = part.thought ? true : false;
@@ -674,21 +656,16 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
674656
e.groundingMetadata.searchEntryPoint.renderedContent;
675657
}
676658
message.eventId = e?.id;
677-
this.eventMessageIndexArray[index] = part.text;
678659
} else if (part.functionCall) {
679660
message.functionCall = part.functionCall;
680661
message.eventId = e?.id;
681-
this.eventMessageIndexArray[index] = part.functionCall;
682662
} else if (part.functionResponse) {
683663
message.functionResponse = part.functionResponse;
684664
message.eventId = e?.id;
685-
this.eventMessageIndexArray[index] = part.functionResponse;
686665
} else if (part.executableCode) {
687666
message.executableCode = part.executableCode;
688-
this.eventMessageIndexArray[index] = part.executableCode;
689667
} else if (part.codeExecutionResult) {
690668
message.codeExecutionResult = part.codeExecutionResult;
691-
this.eventMessageIndexArray[index] = part.codeExecutionResult;
692669
if (e.actions && e.actions.artifact_delta) {
693670
for (const key in e.actions.artifact_delta) {
694671
if (e.actions.artifact_delta.hasOwnProperty(key)) {
@@ -781,7 +758,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
781758
});
782759
}
783760

784-
private storeEvents(part: any, e: any, index: number) {
761+
private storeEvents(part: any, e: any) {
785762
let title = '';
786763
if (part.text) {
787764
title += 'text:' + part.text;
@@ -844,12 +821,10 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
844821
}
845822

846823
private processRunSseResponse(response: any) {
847-
let index = this.eventMessageIndexArray.length - 1;
848824
for (const e of response) {
849825
if (e.content) {
850826
for (let part of e.content.parts) {
851-
index += 1;
852-
this.processPart(e, part, index);
827+
this.processPart(e, part);
853828
}
854829
}
855830
}
@@ -1081,7 +1056,6 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
10811056

10821057
private resetEventsAndMessages() {
10831058
this.eventData.clear();
1084-
this.eventMessageIndexArray = [];
10851059
this.messages.set([]);
10861060
this.artifacts = [];
10871061
}
@@ -1103,15 +1077,13 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
11031077
});
11041078

11051079
this.resetEventsAndMessages();
1106-
let index = 0;
11071080

11081081
session.events.forEach((event: any) => {
11091082
event.content?.parts?.forEach((part: any) => {
11101083
this.storeMessage(
1111-
part, event, index, event.author === 'user' ? 'user' : 'bot');
1112-
index += 1;
1084+
part, event, event.author === 'user' ? 'user' : 'bot');
11131085
if (event.author && event.author !== 'user') {
1114-
this.storeEvents(part, event, index);
1086+
this.storeEvents(part, event);
11151087
}
11161088
});
11171089
});
@@ -1131,14 +1103,12 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
11311103
this.isChatMode.set(false);
11321104

11331105
this.resetEventsAndMessages();
1134-
let index = 0;
11351106
let invocationIndex = 0;
11361107

11371108
for (const invocation of evalCase.conversation) {
11381109
if (invocation.userContent?.parts) {
11391110
for (const part of invocation.userContent.parts) {
1140-
this.storeMessage(part, null, index, 'user');
1141-
index++;
1111+
this.storeMessage(part, null, 'user');
11421112
}
11431113
}
11441114

@@ -1149,24 +1119,21 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
11491119
functionCall: {name: toolUse.name, args: toolUse.args}
11501120
};
11511121
this.storeMessage(
1152-
functionCallPart, null, index, 'bot', invocationIndex,
1122+
functionCallPart, null, 'bot', invocationIndex,
11531123
{toolUseIndex});
1154-
index++;
11551124
toolUseIndex++;
11561125

11571126
const functionResponsePart = { functionResponse: { name: toolUse.name } };
1158-
this.storeMessage(functionResponsePart, null, index, 'bot');
1159-
index++;
1127+
this.storeMessage(functionResponsePart, null, 'bot');
11601128
}
11611129
}
11621130

11631131
if (invocation.finalResponse?.parts) {
11641132
let finalResponsePartIndex = 0;
11651133
for (const part of invocation.finalResponse.parts) {
11661134
this.storeMessage(
1167-
part, null, index, 'bot', invocationIndex,
1135+
part, null, 'bot', invocationIndex,
11681136
{finalResponsePartIndex});
1169-
index++;
11701137
finalResponsePartIndex++;
11711138
}
11721139
}
@@ -1316,7 +1283,6 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
13161283
onNewSessionClick() {
13171284
this.createSession();
13181285
this.eventData.clear();
1319-
this.eventMessageIndexArray = [];
13201286
this.messages.set([]);
13211287
this.artifacts = [];
13221288
this.traceData = [];

0 commit comments

Comments
 (0)