From 5e5e6924b6da2ea8aff6a9ae2eb15a48a8d32553 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 3 Dec 2026 15:56:04 +0200 Subject: [PATCH] AI Assistant menu badge and Home Waiting for you count the solutions that need you, not only chats; Home's two pills are the loudest and then the most recent of chats and solutions, and a solution's pill opens the solution --- .../app/core/services/ai-solutions.service.ts | 9 ++- .../modules/home/menu/menu-link.component.ts | 6 +- .../waiting-ai-chats-home.component.ts | 63 ++++++++++++++----- 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/ui-ngx/src/app/core/services/ai-solutions.service.ts b/ui-ngx/src/app/core/services/ai-solutions.service.ts index 7e7888876b..96022d9497 100644 --- a/ui-ngx/src/app/core/services/ai-solutions.service.ts +++ b/ui-ngx/src/app/core/services/ai-solutions.service.ts @@ -1,6 +1,6 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 -import { DestroyRef, inject, Injectable, signal } from '@angular/core'; +import { computed, DestroyRef, inject, Injectable, signal } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; @@ -182,6 +182,13 @@ export class AiSolutionsService { return solution.status === 'NEEDS_YOU' ? 'needs' : solution.status === 'RUNNING' ? 'running' : solution.status === 'FAILED' ? 'error' : null; } + needsAttention(solution: SolutionInfo): boolean { + const level = this.levelOf(solution); + return level === 'needs' || level === 'error'; + } + + readonly attention = computed(() => this._solutions().filter(solution => this.needsAttention(solution))); + tipOf(solution: SolutionInfo, open = false): string { const level = this.levelOf(solution, open); if (!level) { diff --git a/ui-ngx/src/app/modules/home/menu/menu-link.component.ts b/ui-ngx/src/app/modules/home/menu/menu-link.component.ts index ee6a600a13..658386fdd1 100644 --- a/ui-ngx/src/app/modules/home/menu/menu-link.component.ts +++ b/ui-ngx/src/app/modules/home/menu/menu-link.component.ts @@ -4,6 +4,7 @@ import { ChangeDetectionStrategy, Component, computed, inject, Input, OnInit, signal } from '@angular/core'; import { MenuId, MenuSection } from '@core/services/menu.models'; import { AiChatsService } from '@core/services/ai-chats.service'; +import { AiSolutionsService } from '@core/services/ai-solutions.service'; import { coerceBoolean } from '@shared/decorators/coercion'; @Component({ @@ -27,13 +28,16 @@ export class MenuLinkComponent implements OnInit { private countsChats = signal(false); + private solutions = inject(AiSolutionsService); + readonly needYou = computed(() => this.countsChats() - ? this.chats.statusChats().filter(chat => this.chats.needsAttention(chat)).length : 0); + ? this.chats.statusChats().filter(chat => this.chats.needsAttention(chat)).length + this.solutions.attention().length : 0); ngOnInit(): void { if (this.section?.id === MenuId.ai_assistant) { this.countsChats.set(true); this.chats.watchStatus(); + this.solutions.ensureLoaded(); } } diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/waiting-ai-chats-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-page/components/waiting-ai-chats-home.component.ts index e01fbb844d..fc3cae5766 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/waiting-ai-chats-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/waiting-ai-chats-home.component.ts @@ -4,13 +4,24 @@ import { ChangeDetectionStrategy, Component, computed, effect, inject, signal } import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { TranslateService } from '@ngx-translate/core'; import { interval } from 'rxjs'; -import { ChatInfo } from '@shared/models/ai-chat.models'; +import { ChatLevel } from '@shared/models/ai-chat.models'; import { homeAgo, homeElapsed } from '@home/pages/home-page/home-list.models'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { getCurrentAuthUser } from '@core/auth/auth.selectors'; import { readStored, writeStored } from '@core/local-storage/stored'; import { AiChatsService } from '@core/services/ai-chats.service'; +import { AiSolutionsService } from '@core/services/ai-solutions.service'; + +interface WaitingItem { + id: string; + title: string; + level: ChatLevel; + tip: string; + updatedTime?: number; + recency: number; + queryParams: {chatId?: string; solutionId?: string}; +} const SHOWN = 2; @@ -19,7 +30,7 @@ const TICK_MS = 60_000; @Component({ selector: 'tb-waiting-ai-chats-home', template: ` - @if (!chats.statusResolved()) { + @if (!resolved()) { @if (reserved) {