Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/app/components/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
ngOnInit(): void {
this.syncSelectedAppFromUrl();
this.updateSelectedAppUrl();
this.validateAndFixSessionUrl();

this.webSocketService.onCloseReason().subscribe((closeReason) => {
const error =
Expand Down Expand Up @@ -1458,6 +1459,46 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
});
}

private validateAndFixSessionUrl() {
// Wait for app and URL query params
combineLatest([
this.agentService.getApp(),
this.router.events.pipe(
filter((e) => e instanceof NavigationEnd),
map(() => this.activatedRoute.snapshot.queryParams),
)
]).pipe(
filter(([appName, params]) => !!appName && !!params['session']),
take(1),
switchMap(([appName, params]) => {
const sessionId = params['session'];
// Validate current session id in URL
return this.sessionService.getSession(this.userId, appName, sessionId)
.pipe(
catchError((error) => {
// If invalid, try to use latest existing session
return this.sessionService.listSessions(this.userId, appName)
.pipe(
catchError(() => of([])),
switchMap((sessions: any[]) => {
if (sessions && sessions.length > 0) {
const latestSession = sessions.reduce((latest: any, current: any) =>
current.lastUpdateTime > latest.lastUpdateTime ? current : latest
);
this.updateWithSelectedSession(latestSession);
return of(latestSession);
} else {
this.createSessionAndReset();
return of(null);
}
})
);
})
);
})
).subscribe();
}

private syncSelectedAppFromUrl() {
combineLatest([
this.router.events.pipe(
Expand Down Expand Up @@ -1682,3 +1723,5 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
this.document.head, style); // Append to the head of the document
}
}


11 changes: 9 additions & 2 deletions src/app/components/session-tab/session-tab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import {Component, EventEmitter, Input, OnInit, Output, Inject} from '@angular/core';
import {Component, EventEmitter, Input, OnInit, Output, Inject, OnChanges, SimpleChanges} from '@angular/core';
import {MatDialog} from '@angular/material/dialog';
import {Subject, switchMap} from 'rxjs';
import {Session} from '../../core/models/Session';
Expand All @@ -28,7 +28,7 @@ import { NgClass } from '@angular/common';
styleUrl: './session-tab.component.scss',
imports: [NgClass],
})
export class SessionTabComponent implements OnInit {
export class SessionTabComponent implements OnInit, OnChanges {
@Input() userId: string = '';
@Input() appName: string = '';
@Input() sessionId: string = '';
Expand Down Expand Up @@ -66,6 +66,13 @@ export class SessionTabComponent implements OnInit {
}, 500);
}

ngOnChanges(changes: SimpleChanges): void {
if ((changes['appName'] && !changes['appName'].firstChange) ||
(changes['userId'] && !changes['userId'].firstChange)) {
this.refreshSessionsSubject.next();
}
}

getSession(sessionId: string) {
this.sessionService
.getSession(this.userId, this.appName, sessionId)
Expand Down
2 changes: 1 addition & 1 deletion src/assets/config/runtime-config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"backendUrl": "http://localhost:8000"
"backendUrl": "http://localhost:8080"
}