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
12 changes: 11 additions & 1 deletion src/app/components/chat/chat.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,17 @@
}"
>
@if (message.isLoading) {
<mat-progress-bar class="loading-bar" mode="buffer"></mat-progress-bar>
<div class="loading-container">
<mat-progress-bar class="loading-bar" mode="buffer"></mat-progress-bar>
<button
mat-fab-button
class="stop-button"
(click)="stop()"
matTooltip="Stop execution"
>
<mat-icon>stop</mat-icon>
</button>
</div>
}
@if (message.attachments) {
<div class="attachments">
Expand Down
20 changes: 20 additions & 0 deletions src/app/components/chat/chat.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,31 @@
background-color: #131314;
}

.loading-container {
display: flex;
align-items: center;
width: 150px;
justify-content: space-between;
}

.loading-bar {
width: 100px;
margin: 15px;
}

.stop-button {
width: 30px;
height: 30px;
background-color: #303030;

.mat-icon {
font-size: 18px;
color: white;
margin-left: -20px;
margin-top: -10px;
}
}

.chat-messages {
flex-grow: 1;
overflow-y: auto;
Expand Down
4 changes: 4 additions & 0 deletions src/app/components/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,10 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
this.currentSessionState = session.state;
}

stop() {
this.agentService.stopSse();
}

onNewSessionClick() {
this.createSession();
this.eventData.clear();
Expand Down
21 changes: 20 additions & 1 deletion src/app/core/services/agent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class AgentService {
private _currentApp = new BehaviorSubject<string>('');
currentApp = this._currentApp.asObservable();
private isLoading = new BehaviorSubject<boolean>(false);
private abortController: AbortController | null = null;

constructor(
private http: HttpClient,
Expand All @@ -49,9 +50,19 @@ export class AgentService {
return this.isLoading;
}

stopSse() {
if (this.abortController) {
this.abortController.abort();
this.abortController = null;
}
}

runSse(req: AgentRunRequest) {
const url = this.apiServerDomain + `/run_sse`;
this.isLoading.next(true);
this.abortController = new AbortController();
const signal = this.abortController.signal;

return new Observable<string>((observer) => {
const self = this;
fetch(url, {
Expand All @@ -61,6 +72,7 @@ export class AgentService {
'Accept': 'text/event-stream',
},
body: JSON.stringify(req),
signal,
})
.then((response) => {
const reader = response.body?.getReader();
Expand Down Expand Up @@ -97,13 +109,20 @@ export class AgentService {
})
.catch((err) => {
self.zone.run(() => observer.error(err));
this.isLoading.next(false);
});
};

read();
})
.catch((err) => {
self.zone.run(() => observer.error(err));
if (err.name === 'AbortError') {
// Fetch was aborted
this.isLoading.next(false);
observer.complete();
} else {
self.zone.run(() => observer.error(err));
}
});
});
}
Expand Down