From 4177912e5282ff3485745c55e541f844e6e62555 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Wed, 2 Dec 2026 18:51:37 +0200 Subject: [PATCH] feat: design sync of 2 Dec. Generate dashboard with AI opens the docked chat as a new chat with "Build a dashboard for {device}" in the composer (device row, device group row, device details, latest telemetry with its selected keys, check connectivity and the IoT Hub install finish), and the one-shot loading dialog, its images, steps and request are removed; the docked head has New chat as a button once the chat has a message, Open full screen in More under 500px, More with the chat's actions then On this page and Recent chats, a new chat named from its first ask, the status as its mark alone under 400px and the title's fade measured on render; one AI tooltip (500ms, the next at once, a fade alone, words per the tooltip audit: 12 dropped, 5 cut to one fact, names only when cut, no tooltip at the pointer); the suggestion's Tab key never takes a line of its own; entity names without a box are 400 but in a table's lead column and question options are 32px; the docked composer's auto-approve switch drops its word; dragging the docked chat past its minimum closes it; a card that waits on the first load hides the working line; the welcome sheet scrolls in a short window; the client words for the device dashboard tool --- ui-ngx/src/app/core/http/ai-chat.service.ts | 4 - .../services/ai-assistant-panel.service.ts | 52 +++++++++++++ .../components/ai/ai-action-detail.models.ts | 7 ++ .../home/components/ai/ai-action.models.ts | 1 + .../ai/ai-approval-card.component.ts | 2 +- .../ai/ai-artifact-pane.component.html | 2 +- .../ai/ai-assistant-panel.component.scss | 5 ++ .../ai/ai-assistant-panel.component.ts | 40 +++++++++- .../ai/ai-attachments.component.html | 4 +- .../ai/ai-chat-messages.component.scss | 4 + .../ai/ai-chat-messages.component.ts | 6 +- .../ai/ai-chat-title.component.html | 5 +- .../ai/ai-chat-title.component.scss | 6 ++ .../components/ai/ai-chat-title.component.ts | 24 +++++- .../home/components/ai/ai-chat.component.html | 64 +++++++++------- .../home/components/ai/ai-chat.component.scss | 1 + .../home/components/ai/ai-chat.component.ts | 51 +++++++++++-- .../home/components/ai/ai-core.module.ts | 12 +-- .../ai/ai-dashboard-generation.service.ts | 71 ++++++----------- .../ai/ai-loading-modal.component.html | 15 ---- .../ai/ai-loading-modal.component.scss | 34 --------- .../ai/ai-loading-modal.component.ts | 61 --------------- .../home/components/ai/ai-plan.component.html | 2 +- .../ai/ai-prompt-input.component.html | 2 +- .../ai/ai-prompt-input.component.ts | 36 +++++++++ .../components/ai/ai-record-card.component.ts | 2 +- .../home/components/ai/ai-record.component.ts | 4 +- .../ai/ai-started-from.component.ts | 2 +- .../app/modules/home/components/ai/ai-text.ts | 12 +++ .../modules/home/components/ai/ai-tooltip.ts | 70 +++++++++++++++++ .../modules/home/components/ai/ai.models.ts | 22 ------ .../pane/solution-installed.component.html | 12 +-- .../ai/solution/solution-chat.component.html | 6 +- .../ai/solution/solution-chat.component.ts | 4 +- .../attribute/attribute-table.component.ts | 9 ++- .../device-install-dialog.component.ts | 9 +-- .../ai-assistant/ai-assistant.component.html | 3 +- .../ai-assistant/ai-assistant.component.ts | 4 +- ...ice-check-connectivity-dialog.component.ts | 20 +++-- .../device/device-group-config.factory.ts | 7 +- .../home/pages/device/device.component.ts | 4 +- .../device/devices-table-config.resolver.ts | 7 +- .../tour/welcome-invitation.component.scss | 11 +++ .../assets/locale/locale.constant-ar_AE.json | 7 -- .../assets/locale/locale.constant-ca_ES.json | 7 -- .../assets/locale/locale.constant-cs_CZ.json | 7 -- .../assets/locale/locale.constant-da_DK.json | 7 -- .../assets/locale/locale.constant-de_DE.json | 7 -- .../assets/locale/locale.constant-el_GR.json | 7 -- .../assets/locale/locale.constant-en_US.json | 35 ++++----- .../assets/locale/locale.constant-es_ES.json | 7 -- .../assets/locale/locale.constant-fr_FR.json | 7 -- .../assets/locale/locale.constant-hi_IN.json | 7 -- .../assets/locale/locale.constant-it_IT.json | 7 -- .../assets/locale/locale.constant-ja_JP.json | 7 -- .../assets/locale/locale.constant-ka_GE.json | 7 -- .../assets/locale/locale.constant-ko_KR.json | 7 -- .../assets/locale/locale.constant-lt_LT.json | 7 -- .../assets/locale/locale.constant-lv_LV.json | 7 -- .../assets/locale/locale.constant-nl_BE.json | 7 -- .../assets/locale/locale.constant-nl_NL.json | 7 -- .../assets/locale/locale.constant-no_NO.json | 7 -- .../assets/locale/locale.constant-pl_PL.json | 7 -- .../assets/locale/locale.constant-pt_BR.json | 7 -- .../assets/locale/locale.constant-ro_RO.json | 7 -- .../assets/locale/locale.constant-sl_SI.json | 7 -- .../assets/locale/locale.constant-tr_TR.json | 7 -- .../assets/locale/locale.constant-uk_UA.json | 7 -- .../assets/locale/locale.constant-zh_CN.json | 7 -- .../assets/locale/locale.constant-zh_TW.json | 7 -- .../solution-creator/building-animated.webp | Bin 994292 -> 0 bytes .../solution-creator/catch-animated.webp | Bin 795756 -> 0 bytes .../solution-creator/dashboard-animated.webp | Bin 1190174 -> 0 bytes .../solution-creator/forest-animated.webp | Bin 2338232 -> 0 bytes .../solution-creator/parachute-animated.webp | Bin 2434214 -> 0 bytes .../solution-creator/rocket-animated.webp | Bin 2741776 -> 0 bytes ui-ngx/src/theme/ai-theme.scss | 72 ++++++++++++++++-- 77 files changed, 515 insertions(+), 493 deletions(-) delete mode 100644 ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.html delete mode 100644 ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.scss delete mode 100644 ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.ts create mode 100644 ui-ngx/src/app/modules/home/components/ai/ai-tooltip.ts delete mode 100644 ui-ngx/src/app/modules/home/components/ai/ai.models.ts delete mode 100644 ui-ngx/src/assets/solution-creator/building-animated.webp delete mode 100644 ui-ngx/src/assets/solution-creator/catch-animated.webp delete mode 100644 ui-ngx/src/assets/solution-creator/dashboard-animated.webp delete mode 100644 ui-ngx/src/assets/solution-creator/forest-animated.webp delete mode 100644 ui-ngx/src/assets/solution-creator/parachute-animated.webp delete mode 100644 ui-ngx/src/assets/solution-creator/rocket-animated.webp diff --git a/ui-ngx/src/app/core/http/ai-chat.service.ts b/ui-ngx/src/app/core/http/ai-chat.service.ts index 645ab4a114..3a91763c7f 100644 --- a/ui-ngx/src/app/core/http/ai-chat.service.ts +++ b/ui-ngx/src/app/core/http/ai-chat.service.ts @@ -50,10 +50,6 @@ export class AiChatService { return this.http.get>(`/api/ai/chats/${chatId}/messages`, defaultHttpOptionsFromConfig(config)) } - public generateDashboard(deviceId: string, timeseriesKeys?: string[], config?: RequestConfig): Observable { - return this.http.post(`/api/ai/devices/${deviceId}/dashboard`, { timeseriesKeys }, defaultHttpOptionsFromConfig(config)); - } - public resolveToolApproval(result: ApprovalResult, config?: RequestConfig): Observable { return this.http.post('/api/ai/tools/resolve-approval', result, defaultHttpOptionsFromConfig(config)) } diff --git a/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts b/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts index 4d5c631ab1..32d2b7fb33 100644 --- a/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts +++ b/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts @@ -320,6 +320,37 @@ export class AiAssistantPanelService implements OnDestroy { } }); + private static readonly STARTED_KEY = 'tb-ai-panel-started'; + private static readonly STARTED_MAX = 20; + + private _startedByContext = signal>(AiAssistantPanelService.readStarted()); + + private static readStarted(): Record { + try { + const stored = JSON.parse(AiAssistantPanelService.readSession(AiAssistantPanelService.STARTED_KEY) ?? '{}'); + return stored && typeof stored === 'object' ? stored : {}; + } catch { + return {}; + } + } + + noteStartedHere(chatId: string): void { + const key = this.contextKey(); + if (!key) { + return; + } + this._startedByContext.update(started => { + const next = {...started, [key]: [chatId, ...(started[key] ?? []).filter(id => id !== chatId)].slice(0, AiAssistantPanelService.STARTED_MAX)}; + AiAssistantPanelService.writeSession(AiAssistantPanelService.STARTED_KEY, JSON.stringify(next)); + return next; + }); + } + + chatsStartedHere(): string[] { + const key = this.contextKey(); + return key ? this._startedByContext()[key] ?? [] : []; + } + setLastChatId(id: string | undefined): void { const key = this.contextKey(); if (!key) { @@ -351,6 +382,27 @@ export class AiAssistantPanelService implements OnDestroy { this._open.set(true); } + private _composed = signal<{text: string; fresh: boolean} | null>(null); + readonly composed = this._composed.asReadonly(); + + compose(text: string): void { + if (this._suppressed()) { + return; + } + this._composed.set({text, fresh: !this._open()}); + this.openPanel(); + } + + composesFresh(): boolean { + return !!this._composed()?.fresh; + } + + takeComposed(): {text: string; fresh: boolean} | null { + const composed = this._composed(); + this._composed.set(null); + return composed; + } + setEnabled(enabled: boolean): void { this._enabled.set(enabled); if (enabled) { diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts b/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts index 3ca2b37366..0180665132 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts @@ -1295,6 +1295,10 @@ function describe(tool: string, values: Values, result: unknown, names: AiDetail }; case 'create_dashboard': return {hood: text('create-dashboard', {name: str(values.title) ?? '—'}), blocks: []}; + case 'generate_device_dashboard': { + const keys = Array.isArray(values.keys) ? values.keys.map(String) : []; + return {hood: text('generate-device-dashboard', {entity: of(values.deviceId, 'DEVICE')}), blocks: keys.length ? [{type: 'keys', keys}] : []}; + } case 'update_dashboard': return {hood: text('update-dashboard', {entity: dashboard}), blocks: changes(values, ['dashboardId'], names)}; case 'read_dashboard_overview': @@ -2360,6 +2364,9 @@ function namesOf(message: {from: string; data?: any; references?: Array<{id: str case 'create_dashboard': put(created, values.title, 'DASHBOARD'); break; + case 'generate_device_dashboard': + put(created, undefined, 'DASHBOARD'); + break; case 'save_device': put(created ?? savedObject(values).id, savedObject(values).name, 'DEVICE'); break; diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts b/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts index d2afdc3ec3..06f4f75667 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts @@ -40,6 +40,7 @@ const TOOL_WORDS: Record = { test_converter: 'test-converter', read_converter_library: 'read-converter-library', create_dashboard: 'create-dashboard', + generate_device_dashboard: 'generate-device-dashboard', update_dashboard: 'update-dashboard', add_dashboard_state: 'add-dashboard-state', update_dashboard_state: 'update-dashboard-state', diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts index 99eff53c56..b8d19aa09f 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts @@ -74,7 +74,7 @@ const CODE_FIELDS = new Set(['arguments', 'expression', 'output']); const HEAD_VERBS = new Set(['create', 'update', 'delete', 'install', 'acknowledge', 'clear', 'assign', 'unassign']); const REVIEW_VERBS = new Set(['install', 'restart', 'update', 'upgrade', 'upgrade-agent', 'delete', 'cancel', 'sync', 'acknowledge', 'clear', 'assign', 'unassign']); -const IMAGE_FIELDS = new Set(['widget-image', 'scada-symbol']); +const IMAGE_FIELDS = new Set(['widget-image', 'scada-symbol', 'dashboard-image']); const BLOCK_FIELDS = new Set(['script']); diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-artifact-pane.component.html b/ui-ngx/src/app/modules/home/components/ai/ai-artifact-pane.component.html index fff54110b0..11489f55ee 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-artifact-pane.component.html +++ b/ui-ngx/src/app/modules/home/components/ai/ai-artifact-pane.component.html @@ -6,7 +6,7 @@ -->
diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.scss b/ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.scss index 8680d28d7f..5583c127d2 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.scss +++ b/ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.scss @@ -561,6 +561,10 @@ padding: 0; background: none; box-shadow: none; + font-weight: 400; + } + + td:first-child code.k-ent { font-weight: 500; } diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.ts index 6b77a240c7..9540bfc852 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.ts @@ -508,6 +508,8 @@ export class AiChatMessagesComponent implements OnChanges, OnDestroy { this.runningLead = running.length ? running[0] : -1; this.runningCount = running.length; this.findReadGroups(); + const last = this.messages[this.messages.length - 1]; + this.waitApproval = last?.from === 'APPROVAL' && !this.autoApprove && !this.isAnswered(last as ApprovalChatMessage); if (changes.messages.firstChange) { if (this.initialScroll === 'bottom') { this.pinToBottom(); @@ -521,10 +523,6 @@ export class AiChatMessagesComponent implements OnChanges, OnDestroy { const prevLastMsg = prevMsgs?.[prevMsgs.length - 1]; const msgs = changes.messages.currentValue as ChatMessage[]; const lastMsg = msgs[msgs.length - 1]; - // In auto-approve we are not blocked on the user, so the assistant keeps working: the - // thinking indicator stays visible (waitApproval false), and the view follows the stream of - // auto-generated cards only while the reader is near the bottom. - this.waitApproval = lastMsg?.from === 'APPROVAL' && !this.autoApprove && !this.isAnswered(lastMsg as ApprovalChatMessage); if (this.autoApprove) { if (wasNearBottom) { setTimeout(() => this.scrollToBottom('auto'), 0); diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-chat-title.component.html b/ui-ngx/src/app/modules/home/components/ai/ai-chat-title.component.html index 01d3972043..35bd1082fd 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-chat-title.component.html +++ b/ui-ngx/src/app/modules/home/components/ai/ai-chat-title.component.html @@ -24,10 +24,7 @@ } @else { @if (renamable()) { + } - + @if (fullscreen() || !headNarrow()) { + + } @if (!fullscreen()) { - } @if (docked() && (split() || splitAvailable())) { @@ -415,9 +419,23 @@ {{ (split() ? 'ai-assistant.back-to-panel' : 'ai-assistant.split-view') | translate }} } - @if (recentChats().length) { -
{{ 'ai-assistant.recent-chats' | translate }}
- @for (other of recentChats(); track other.id) { + @if (chat()) { + + + + } + @for (group of otherChats(); track group.label) { +
{{ group.label | translate }}
+ @for (other of group.chats; track other.id) { - @if (chat()) { - - } diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.scss b/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.scss index 72fd4f050f..928d69fb9d 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.scss +++ b/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.scss @@ -23,6 +23,7 @@ .ai-chat-head { position: relative; + container: k-head / inline-size; flex: none; display: flex; align-items: center; diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts index 2ef5fab1d3..64371d66ff 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 +import { AI_TOOLTIP_PROVIDERS } from '@home/components/ai/ai-tooltip'; import { aiCreditsLimitOf, AiCreditsLimitType } from '@home/components/ai/ai-credits.models'; import { aiClientOs, aiPageView, isAiTitledView } from '@shared/models/ai-chat.models'; import { getDefaultTimezone } from '@shared/models/time/time.models'; @@ -46,6 +47,7 @@ import { getCurrentAuthUser } from '@core/auth/auth.selectors'; import { environment as env } from '@env/environment'; import { ActionNotificationShow } from '@core/notification/notification.actions'; import { isNotEmptyStr, parseHttpErrorMessage } from '@core/utils'; +import { aiChatNameOf } from '@home/components/ai/ai-text'; import { ActionChatMessage, AiStartedFrom, ApprovalChatMessage, ChatMessage, GeneralChatMessage } from '@shared/models/solution-creator.models'; import { AiAssistantPromptExample, @@ -110,14 +112,19 @@ interface AiRefusal { '[class.split]': 'split() && docked()', '[class.v-page]': '!docked()', '[class.v-panel]': 'docked()' - } + }, + providers: AI_TOOLTIP_PROVIDERS }) export class AiChatComponent implements OnInit, OnDestroy { private static readonly RESUME_ATTEMPTS = 4; private static readonly RESUME_DELAY_MS = 2000; private static readonly NOTICE_MS = 6000; - private static readonly RECENT_CHATS = 5; + private static readonly MENU_CHATS = 4; + + private static readonly NEW_CHAT_TITLE = 'New chat'; + + private static readonly NARROW_HEAD = 500; @ViewChild(AiPromptInputComponent) promptInput: AiPromptInputComponent; @ViewChild(AiChatTitleComponent) titleRef: AiChatTitleComponent; @@ -167,10 +174,29 @@ export class AiChatComponent implements OnInit, OnDestroy { {key: 'datasheet', icon: 'attach_file', file: true} ]; - recentChats = computed(() => this.chats.chats() - .filter(chat => chat.id !== this.chatId()) - .sort((a, b) => b.createdTime - a.createdTime) - .slice(0, AiChatComponent.RECENT_CHATS)); + otherChats = computed<{label: string; chats: ChatInfo[]}[]>(() => { + const others = this.chats.chats() + .filter(chat => chat.id !== this.chatId()) + .sort((a, b) => (b.updatedTime ?? b.createdTime) - (a.updatedTime ?? a.createdTime)); + const startedHere = new Set(this.panelService.chatsStartedHere()); + const here = others.filter(chat => startedHere.has(chat.id)).slice(0, AiChatComponent.MENU_CHATS - 1); + const recent = others.filter(chat => !startedHere.has(chat.id)).slice(0, Math.max(1, AiChatComponent.MENU_CHATS - here.length)); + return [ + ...(here.length ? [{label: 'ai-assistant.on-this-page', chats: here}] : []), + ...(recent.length ? [{label: 'ai-assistant.recent-chats', chats: recent}] : []) + ]; + }); + + headNarrow = signal(false); + + shownTitle = computed(() => { + const title = this.chat()?.title; + if (title && title !== AiChatComponent.NEW_CHAT_TITLE) { + return title; + } + const first = this.messages().find(message => message.from === 'USER') as GeneralChatMessage | undefined; + return typeof first?.content === 'string' && first.content.trim() ? aiChatNameOf(first.content) : title; + }); fullscreen = signal(false); @@ -549,6 +575,14 @@ export class AiChatComponent implements OnInit, OnDestroy { }); ngOnInit(): void { + if (typeof ResizeObserver !== 'undefined') { + const head = new ResizeObserver(() => { + const width = this.hostElement.querySelector('.ai-chat-head')?.clientWidth ?? 0; + this.headNarrow.set(width > 0 && width < AiChatComponent.NARROW_HEAD); + }); + head.observe(this.hostElement); + this.destroyRef.onDestroy(() => head.disconnect()); + } this.loadChat$.pipe( switchMap(id => this.aiChat.getChatMessages(id, {ignoreLoading: true, ignoreErrors: true}).pipe( catchError(err => { @@ -1054,8 +1088,11 @@ export class AiChatComponent implements OnInit, OnDestroy { this.messageCancelled = false; const startOrContinue$ = this.chatId() ? of(null) - : this.chats.create('New chat', this.newChatAutoApprove()).pipe( + : this.chats.create(AiChatComponent.NEW_CHAT_TITLE, this.newChatAutoApprove()).pipe( tap(chat => { + if (this.variant() === 'panel') { + this.panelService.noteStartedHere(chat.id); + } this.freshChatId = chat.id; this.shownChatId = chat.id; this.chatId.set(chat.id); diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-core.module.ts b/ui-ngx/src/app/modules/home/components/ai/ai-core.module.ts index aba2c626b3..e1915d1162 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-core.module.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-core.module.ts @@ -10,8 +10,8 @@ import { AiTipDirective } from '@home/components/ai/ai-tip.directive'; import { AiFadeInImageDirective } from '@home/components/ai/ai-fade-in-image.directive'; import { AiSpinComponent } from '@home/components/ai/ai-spin.component'; import { AiSevMarkComponent } from '@home/components/ai/ai-sev-mark.component'; -import { AiLoadingModalComponent } from '@home/components/ai/ai-loading-modal.component'; import { AiNoTelemetryModalComponent } from '@home/components/ai/ai-no-telemetry-modal.component'; +import { AiTipIfCutDirective, AiTooltipChainDirective } from '@home/components/ai/ai-tooltip'; @NgModule({ declarations: [ @@ -22,12 +22,13 @@ import { AiNoTelemetryModalComponent } from '@home/components/ai/ai-no-telemetry AiFadeInImageDirective, AiSpinComponent, AiSevMarkComponent, - AiLoadingModalComponent, AiNoTelemetryModalComponent ], imports: [ CommonModule, - SharedModule + SharedModule, + AiTooltipChainDirective, + AiTipIfCutDirective ], exports: [ AiAssistantButtonComponent, @@ -37,8 +38,9 @@ import { AiNoTelemetryModalComponent } from '@home/components/ai/ai-no-telemetry AiFadeInImageDirective, AiSpinComponent, AiSevMarkComponent, - AiLoadingModalComponent, - AiNoTelemetryModalComponent + AiNoTelemetryModalComponent, + AiTooltipChainDirective, + AiTipIfCutDirective ] }) export class AiCoreModule {} diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-dashboard-generation.service.ts b/ui-ngx/src/app/modules/home/components/ai/ai-dashboard-generation.service.ts index d86504ea90..96eb0771b6 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-dashboard-generation.service.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-dashboard-generation.service.ts @@ -1,11 +1,9 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 -import { DestroyRef, Injectable } from '@angular/core'; +import { Injectable } from '@angular/core'; import { createDefaultEntityDataPageLink, singleEntityFilterFromDeviceId } from '@shared/models/query/query.models'; -import { AiLoadingModalComponent, AiLoadingModalData } from '@home/components/ai/ai-loading-modal.component'; -import { dashboardGenerateImage, generateDashboardSteps } from '@home/components/ai/ai.models'; -import { finalize } from 'rxjs/operators'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { map } from 'rxjs/operators'; +import { forkJoin, of } from 'rxjs'; import { AiNoTelemetryModalComponent, AiNoTelemetryModalData @@ -13,21 +11,20 @@ import { import { Operation } from '@shared/models/security.models'; import { EntityType } from '@shared/models/entity-type.models'; import { EntityService } from '@core/http/entity.service'; +import { DeviceService } from '@core/http/device.service'; +import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; import { MatDialog } from '@angular/material/dialog'; -import { AiChatService } from '@core/http/ai-chat.service'; -import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; -import { DomSanitizer } from '@angular/platform-browser'; -import { Store } from '@ngrx/store'; -import { AppState } from '@core/core.state'; import { UserPermissionsService } from '@core/http/user-permissions.service'; import { EntityGroupInfo } from '@shared/models/entity-group.models'; interface GenerateDashboardOptions { deviceId: string; - destroyRef?: DestroyRef; - noTelemetry: AiNoTelemetryModalData; - beforeOpen?: () => void; + deviceName?: string; + keys?: string[]; + checkTelemetry?: boolean; + noTelemetry?: AiNoTelemetryModalData; + beforeCompose?: () => void; } interface AllowDashboardGenerateOptions { @@ -41,47 +38,29 @@ interface AllowDashboardGenerateOptions { export class AiDashboardGenerationService { constructor(private entityService: EntityService, + private deviceService: DeviceService, private dialog: MatDialog, - private aiChatService: AiChatService, - private router: Router, + private panelService: AiAssistantPanelService, private translate: TranslateService, - private sanitizer: DomSanitizer, - private store: Store, private userPermissionsService: UserPermissionsService) { } - generateWithTelemetryCheck(opts: GenerateDashboardOptions): void { - this.entityService.findEntityKeysByQueryV2({ + askInChat(opts: GenerateDashboardOptions): void { + const telemetry$ = opts.checkTelemetry === false ? of(true) : this.entityService.findEntityKeysByQueryV2({ entityFilter: singleEntityFilterFromDeviceId(opts.deviceId), pageLink: createDefaultEntityDataPageLink(1), - }, true, false).subscribe((res) => { - opts.beforeOpen?.(); - if (res.timeseries.length) { - this.generate(opts.deviceId, opts.destroyRef); - } else { - this.openNoTelemetryModal(opts.noTelemetry); + }, true, false).pipe(map(res => res.timeseries.length > 0)); + const name$ = opts.deviceName ? of(opts.deviceName) : this.deviceService.getDevice(opts.deviceId, {ignoreLoading: true}).pipe(map(device => device.name)); + forkJoin([telemetry$, name$]).subscribe(([hasTelemetry, name]) => { + if (!hasTelemetry) { + this.openNoTelemetryModal(opts.noTelemetry ?? {}); + return; } - }); - } - - generate(deviceId: string, destroyRef?: DestroyRef, timeseriesKeys: string[] = []): void { - const dialogRef = this.dialog.open(AiLoadingModalComponent, { - disableClose: true, - panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], - data: { - messages: generateDashboardSteps, - estimateWaitTime: 60000, - image: dashboardGenerateImage - } as AiLoadingModalData - }); - let request$ = this.aiChatService.generateDashboard(deviceId, timeseriesKeys).pipe( - finalize(() => dialogRef.close()) - ); - if (destroyRef) { - request$ = request$.pipe(takeUntilDestroyed(destroyRef)); - } - request$.subscribe({ - next: (response) => this.router.navigate(['/dashboards', response]) + opts.beforeCompose?.(); + const keys = (opts.keys ?? []).filter(Boolean); + this.panelService.compose(keys.length + ? this.translate.instant('ai-assistant.ask.device-dashboard-keys', {name, keys: keys.join(', ')}) + : this.translate.instant('ai-assistant.ask.device-dashboard', {name})); }); } diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.html b/ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.html deleted file mode 100644 index 59a00e96d0..0000000000 --- a/ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.html +++ /dev/null @@ -1,15 +0,0 @@ - -
-
- Loading -
- {{ statusMessage | translate }} - {{ 'solution-creator.estimate-wait-time' | translate: {time: (data.estimateWaitTime | milliSecondsToTimeString:true : true)} }} -
-
-
diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.scss b/ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.scss deleted file mode 100644 index b0786e00db..0000000000 --- a/ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.scss +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. -// SPDX-License-Identifier: BUSL-1.1 -.tb-generated { - z-index: 3; - .panel { - box-shadow: 0 6px 12px 0 rgba(0, 0, 0, 0.04), 0 12px 32px 0 rgba(0, 0, 0, 0.08); - background-color: #fff; - width: 500px; - } - img { - width: 200px; - } - .info { - white-space: pre-line; - text-align: center; - line-height: 1.5; - letter-spacing: 0.15px; - } - - .msg.text-changed { - animation: fadeInSlideUp 0.5s ease-out forwards; - } - - @keyframes fadeInSlideUp { - 0% { - opacity: 0; - transform: translateY(15px); - } - 100% { - opacity: 1; - transform: translateY(0); - } - } -} diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.ts deleted file mode 100644 index 3ab1c957eb..0000000000 --- a/ui-ngx/src/app/modules/home/components/ai/ai-loading-modal.component.ts +++ /dev/null @@ -1,61 +0,0 @@ -// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. -// SPDX-License-Identifier: BUSL-1.1 -import { Component, DestroyRef, Inject, OnInit, ViewEncapsulation } from '@angular/core'; -import { DialogComponent } from '@shared/components/dialog.component'; -import { Store } from '@ngrx/store'; -import { AppState } from '@core/core.state'; -import { Router } from '@angular/router'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; -import { from, of } from 'rxjs'; -import { concatMap, delay } from 'rxjs/operators'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { generatedStateImages } from '@home/components/ai/ai.models'; - -export interface AiLoadingModalData { - messages: Array<{text: string; delay: number}>; - estimateWaitTime: number; - image?: string; -} - -@Component({ - selector: 'tb-ai-loading-modal', - templateUrl: './ai-loading-modal.component.html', - styleUrl: './ai-loading-modal.component.scss', - encapsulation: ViewEncapsulation.None, - standalone: false, - host: { - style: 'width: 100%; height: 100%; min-height: 100%; display: flex; overflow: hidden;' - } -}) -export class AiLoadingModalComponent extends DialogComponent implements OnInit { - - generateImage: string = generatedStateImages[Math.floor(Math.random() * generatedStateImages.length)]; - statusMessage: string = ''; - statusMessageChanged = false; - - constructor(protected store: Store, - protected router: Router, - @Inject(MAT_DIALOG_DATA) public data: AiLoadingModalData, - public dialogRef: MatDialogRef, - private destroyRef: DestroyRef) { - super(store, router, dialogRef); - } - - ngOnInit() { - this.initGenerateState(); - } - - private initGenerateState(): void { - from(this.data.messages).pipe( - concatMap(message => of(message).pipe(delay(message.delay))), - takeUntilDestroyed(this.destroyRef) - ).subscribe((msg) => { - this.statusMessageChanged = true; - this.statusMessage = msg.text; - setTimeout(() => { - this.statusMessageChanged = false; - }, 500); - }); - } - -} diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-plan.component.html b/ui-ngx/src/app/modules/home/components/ai/ai-plan.component.html index ef9123b797..e750917182 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-plan.component.html +++ b/ui-ngx/src/app/modules/home/components/ai/ai-plan.component.html @@ -47,7 +47,7 @@ - } @else { diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.html b/ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.html index 628dd9989f..b01eee5cf8 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.html +++ b/ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.html @@ -53,7 +53,7 @@
@if (suggestion && !hasText()) { - + {{ 'ai-assistant.suggestion-sr' | translate: {text: suggestion} }} }