Browse Source

feat: leaving a solution while it is being designed keeps it running in the chats list, which refreshes until the design is done, and coming back resumes its progress instead of showing it idle

pull/16833/head
Igor Kulikov 2 weeks ago
parent
commit
31241961bf
  1. 28
      ui-ngx/src/app/core/services/ai-solutions.service.ts
  2. 8
      ui-ngx/src/app/modules/home/components/ai/solution/solution-chat.component.ts

28
ui-ngx/src/app/core/services/ai-solutions.service.ts

@ -1,8 +1,8 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { inject, Injectable, signal } from '@angular/core';
import { Observable, of } from 'rxjs';
import { map, switchMap, tap } from 'rxjs/operators';
import { EMPTY, Observable, of, Subscription, timer } from 'rxjs';
import { catchError, finalize, map, switchMap, takeWhile, tap } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';
import { ChatLevel } from '@shared/models/ai-chat.models';
import { SolutionsCreatorService } from '@core/http/solutions-creator.service';
@ -15,9 +15,13 @@ import {
SolutionUpdateRequest
} from '@shared/models/solution-creator.models';
const SOLUTIONS_POLL_MS = 5000;
@Injectable({providedIn: 'root'})
export class AiSolutionsService {
private following: Subscription | null = null;
private _solutions = signal<SolutionInfo[]>([]);
readonly solutions = this._solutions.asReadonly();
@ -38,12 +42,32 @@ export class AiSolutionsService {
next: solutions => {
this._solutions.set(solutions);
this._loaded.set(true);
this.followRunning();
},
error: () => this._loaded.set(true)
})
);
}
keepRunning(solutionId: string | undefined): void {
if (!solutionId) {
return;
}
this.update(solutionId, {status: 'RUNNING', statusReason: undefined});
this.followRunning();
}
followRunning(): void {
if (this.following) {
return;
}
this.following = timer(SOLUTIONS_POLL_MS, SOLUTIONS_POLL_MS).pipe(
takeWhile(() => this._solutions().some(solution => solution.status === 'RUNNING' && !this._running().has(solution.id))),
switchMap(() => this.load().pipe(catchError(() => EMPTY))),
finalize(() => this.following = null)
).subscribe();
}
setRunning(solutionId: string | undefined, running: boolean): void {
if (!solutionId || this._running().has(solutionId) === running) {
return;

8
ui-ngx/src/app/modules/home/components/ai/solution/solution-chat.component.ts

@ -829,6 +829,7 @@ export class SolutionChatComponent extends PageComponent implements OnInit, OnDe
}
ngOnDestroy(): void {
this.keepRunningListed();
this.clearWork();
this.cancelPending$.next();
this.cancelPending$.complete();
@ -1448,7 +1449,14 @@ export class SolutionChatComponent extends PageComponent implements OnInit, OnDe
}));
}
private keepRunningListed(): void {
if (this.solutionId && this.solutionId !== NEW_SOLUTION_ID && (this.loading() || this.isGenerating())) {
this.aiSolutions.keepRunning(this.solutionId);
}
}
private resetSolution(): void {
this.keepRunningListed();
this.clearWork();
this.pickedView.set(null);
this.json.set(false);

Loading…
Cancel
Save