Browse Source

feat: the solution chat says what a solution is in a band over the hero's foot, shows a failed step or install in the chat instead of a toast, lists installed items that need a look, opens the pane when a step's result arrives or waits, shades the pane's head and foot over scrolled content, and marks a solution running in the chats list

pull/16833/head
Igor Kulikov 4 weeks ago
parent
commit
db58069a77
  1. 22
      ui-ngx/src/app/core/services/ai-solutions.service.ts
  2. 48
      ui-ngx/src/app/modules/home/components/ai/solution/solution-chat.component.html
  3. 225
      ui-ngx/src/app/modules/home/components/ai/solution/solution-chat.component.scss
  4. 95
      ui-ngx/src/app/modules/home/components/ai/solution/solution-chat.component.ts
  5. 2
      ui-ngx/src/app/modules/home/pages/ai-assistant/ai-assistant.component.html
  6. 13
      ui-ngx/src/assets/locale/locale.constant-en_US.json

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

@ -17,6 +17,9 @@ export class AiSolutionsService {
private _loaded = signal(false); private _loaded = signal(false);
readonly loaded = this._loaded.asReadonly(); readonly loaded = this._loaded.asReadonly();
private _running = signal<ReadonlySet<string>>(new Set());
readonly running = this._running.asReadonly();
private api = inject(SolutionsCreatorService); private api = inject(SolutionsCreatorService);
private dialog = inject(DialogService); private dialog = inject(DialogService);
private translate = inject(TranslateService); private translate = inject(TranslateService);
@ -33,6 +36,25 @@ export class AiSolutionsService {
); );
} }
setRunning(solutionId: string | undefined, running: boolean): void {
if (!solutionId || this._running().has(solutionId) === running) {
return;
}
this._running.update(set => {
const next = new Set(set);
if (running) {
next.add(solutionId);
} else {
next.delete(solutionId);
}
return next;
});
}
isRunning(solutionId: string): boolean {
return this._running().has(solutionId);
}
find(solutionId: string | undefined): SolutionInfo | undefined { find(solutionId: string | undefined): SolutionInfo | undefined {
return solutionId ? this._solutions().find(solution => solution.id === solutionId) : undefined; return solutionId ? this._solutions().find(solution => solution.id === solutionId) : undefined;
} }

48
ui-ngx/src/app/modules/home/components/ai/solution/solution-chat.component.html

@ -53,7 +53,30 @@
} }
</div> </div>
<p class="sol-hero-foot">{{ 'solution-creator.limits' | translate }}</p> <p class="sol-hero-foot">{{ 'solution-creator.limits' | translate }}</p>
<button type="button" class="sol-learn" [attr.aria-expanded]="aboutOpen()" (click)="aboutOpen.set(true)">
<mat-icon fontSet="material-icons-round" aria-hidden="true">info_outline</mat-icon>{{ 'solution-creator.what-is-solution' | translate }}
</button>
</div>
</div> </div>
<div class="sol-about" [class.open]="aboutOpen()" role="region" [attr.aria-hidden]="!aboutOpen()"
[attr.aria-label]="'solution-creator.what-is-solution' | translate">
<div class="sol-about-in">
<div class="sol-about-head">
<b><mat-icon fontSet="material-icons-round" aria-hidden="true">layers</mat-icon>{{ 'solution-creator.about-title' | translate }}</b>
<button type="button" class="sol-ib" (click)="aboutOpen.set(false)" [attr.tabindex]="aboutOpen() ? 0 : -1"
[matTooltip]="'action.close' | translate" matTooltipPosition="above" [attr.aria-label]="'action.close' | translate">
<mat-icon>close</mat-icon>
</button>
</div>
<div class="sol-feats" role="list">
@for (feature of aboutFeatures; track feature.icon) {
<div class="sol-feat" role="listitem">
<mat-icon aria-hidden="true">{{ feature.icon }}</mat-icon>
<div><b>{{ feature.title | translate }}</b><span>{{ feature.line | translate }}</span></div>
</div>
}
</div>
</div>
</div> </div>
</div> </div>
} @else if (creatorStep()) { } @else if (creatorStep()) {
@ -119,6 +142,26 @@
{{ 'solution-creator.installed-already-note' | translate }}</span> {{ 'solution-creator.installed-already-note' | translate }}</span>
</div> </div>
} }
@if (creatorStep() === 'result' && issues().length) {
<div class="sol-closing sol-issues">
<p>{{ 'solution-creator.issues-lead' | translate: {count: issues().length} }}</p>
<ul>
@for (issue of issues().slice(0, 6); track $index) {
<li><b>{{ issue.name }}</b> · {{ (issue.status === 'ERROR' ? 'solution-creator.pane.status-error' : 'solution-creator.pane.status-warn') | translate }}</li>
}
</ul>
<div class="k-hint tip sol-hint">
<mat-icon fontSet="material-icons-round" aria-hidden="true">lightbulb_outline</mat-icon>
<span><b>{{ 'solution-creator.issues-tip-lead' | translate }}</b> {{ 'solution-creator.issues-tip' | translate }}</span>
</div>
</div>
}
@if (failure(); as message) {
<div class="sol-failure" role="status">
<mat-icon fontSet="material-icons-round" aria-hidden="true">error_outline</mat-icon>
<span>{{ message }}</span>
</div>
}
@if (work(); as current) { @if (work(); as current) {
<tb-ai-work-line class="sol-work" [words]="current.words" [kind]="current.kind" [since]="current.since"></tb-ai-work-line> <tb-ai-work-line class="sol-work" [words]="current.words" [kind]="current.kind" [since]="current.since"></tb-ai-work-line>
} }
@ -152,7 +195,8 @@
</div> </div>
</div> </div>
@if (showPane() && paneOpen()) { @if (showPane() && paneOpen()) {
<aside class="sol-pane" [style.flex-basis]="paneWidth() ? paneWidth() + 'px' : null"> <aside class="sol-pane" [style.flex-basis]="paneWidth() ? paneWidth() + 'px' : null"
[class.scrolled]="paneScrolled()" [class.more]="paneMore()">
<div class="sol-pane-edge" role="separator" tabindex="0" aria-orientation="vertical" <div class="sol-pane-edge" role="separator" tabindex="0" aria-orientation="vertical"
[attr.aria-label]="'solution-creator.pane.resize' | translate" [attr.aria-label]="'solution-creator.pane.resize' | translate"
[matTooltip]="'solution-creator.pane.resize-hint' | translate" matTooltipPosition="left" matTooltipShowDelay="600" [matTooltip]="'solution-creator.pane.resize-hint' | translate" matTooltipPosition="left" matTooltipShowDelay="600"
@ -186,7 +230,7 @@
</button> </button>
} }
</div> </div>
<div class="sol-pane-body" [class.dark]="json()"> <div #paneBody class="sol-pane-body" [class.dark]="json()" (scroll)="onPaneScroll(paneBody)">
@if (making() && currentView() === making()) { @if (making() && currentView() === making()) {
<div class="sol-loading"> <div class="sol-loading">
<span class="sol-loading-glow" aria-hidden="true"></span> <span class="sol-loading-glow" aria-hidden="true"></span>

225
ui-ngx/src/app/modules/home/components/ai/solution/solution-chat.component.scss

@ -682,6 +682,7 @@
} }
.sol-pane-foot { .sol-pane-foot {
position: relative;
flex: none; flex: none;
display: flex; display: flex;
align-items: center; align-items: center;
@ -856,3 +857,227 @@
} }
} }
} }
.sol-pane-head::after, .sol-pane-foot::before {
content: '';
position: absolute;
left: 0;
right: 0;
height: 12px;
pointer-events: none;
opacity: 0;
transition: opacity .15s ease;
}
.sol-pane-head::after {
top: 100%;
opacity: .45;
background: linear-gradient(to bottom, color-mix(in srgb, var(--tb-ink) 9%, transparent), transparent);
}
.sol-pane-foot::before {
bottom: 100%;
background: linear-gradient(to top, color-mix(in srgb, var(--tb-ink) 9%, transparent), transparent);
}
.sol-pane.scrolled .sol-pane-head::after, .sol-pane.more .sol-pane-foot::before {
opacity: 1;
}
.sol-failure {
display: flex;
align-items: flex-start;
gap: 8px;
margin-top: 14px;
font-size: var(--chat-line);
line-height: var(--chat-line-lh);
color: var(--tb-crit);
.mat-icon {
flex: none;
font-size: 18px;
width: 18px;
height: 18px;
line-height: 18px;
margin-top: 1px;
}
}
.sol-issues {
ul {
margin: 8px 0 0;
padding-left: 20px;
font-size: var(--chat-line);
line-height: var(--chat-line-lh);
color: var(--tb-ink-76);
}
b {
font-weight: 500;
color: var(--tb-ink);
}
}
.sol-learn {
display: inline-flex;
align-items: center;
gap: 6px;
margin: 6px auto 0;
padding: 4px 10px 4px 8px;
border: 0;
border-radius: 8px;
background: none;
font: inherit;
font-size: var(--chat-line);
line-height: var(--chat-line-lh);
font-weight: 500;
color: var(--tb-ink-60);
cursor: pointer;
.mat-icon {
font-size: 18px;
width: 18px;
height: 18px;
line-height: 18px;
}
&:hover {
color: var(--tb-ink);
background: rgba(0, 0, 0, 0.05);
}
&:focus-visible {
outline: 2px solid var(--ai-focus);
outline-offset: 1px;
}
}
.sol-about {
position: absolute;
left: 0;
right: 0;
bottom: 0;
z-index: 2;
padding: 12px 24px 18px;
background: var(--tb-surface);
border-top: 1px solid var(--k-stroke, rgba(0, 0, 0, 0.1));
transform: translateY(100%);
opacity: 0;
visibility: hidden;
will-change: transform;
transition: transform .26s cubic-bezier(.2, 0, 0, 1), opacity .2s ease, visibility 0s linear .26s;
&::before {
content: '';
position: absolute;
left: 0;
right: 0;
bottom: 100%;
height: 18px;
background: linear-gradient(to top, color-mix(in srgb, var(--tb-ink) 5%, transparent), transparent);
pointer-events: none;
}
&.open {
transform: none;
opacity: 1;
visibility: visible;
transition-delay: 0s, 0s, 0s;
}
@media (prefers-reduced-motion: reduce) {
transition: none;
}
}
.sol-about-in {
max-width: 860px;
margin: 0 auto;
text-align: left;
}
.sol-about-head {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
b {
flex: 1;
display: inline-flex;
align-items: center;
gap: 8px;
font-size: var(--chat-line);
line-height: var(--chat-line-lh);
font-weight: 500;
color: var(--ai-action);
.mat-icon {
font-size: 18px;
width: 18px;
height: 18px;
line-height: 18px;
}
}
.sol-ib {
width: 32px;
height: 32px;
margin: -4px -8px -4px 0;
border-radius: 50%;
font-size: 14px;
line-height: 20px;
color: var(--tb-ink-60);
}
}
.sol-feats {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 14px 24px;
align-items: start;
@media (max-width: 860px) {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (max-width: 480px) {
grid-template-columns: minmax(0, 1fr);
}
}
.sol-feat {
display: flex;
gap: 10px;
min-width: 0;
> .mat-icon {
flex: none;
font-size: 20px;
width: 20px;
height: 20px;
line-height: 16px;
margin-top: 1px;
color: var(--k-grey);
}
> div {
display: grid;
gap: 2px;
align-content: start;
min-width: 0;
}
b {
font-size: var(--chat-line);
line-height: var(--chat-line-lh);
font-weight: 500;
color: var(--tb-ink);
}
span {
font-size: var(--chat-meta);
line-height: var(--chat-meta-lh);
color: var(--k-grey);
}
}

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

@ -1,6 +1,20 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1 // SPDX-License-Identifier: BUSL-1.1
import { Component, computed, DestroyRef, ElementRef, EventEmitter, OnDestroy, OnInit, Output, signal, ViewChild } from '@angular/core'; import {
Component,
computed,
DestroyRef,
effect,
ElementRef,
EventEmitter,
HostListener,
OnDestroy,
OnInit,
Output,
signal,
untracked,
ViewChild
} from '@angular/core';
import { AiChatMessagesComponent } from '@home/components/ai/ai-chat-messages.component'; import { AiChatMessagesComponent } from '@home/components/ai/ai-chat-messages.component';
import { PageComponent } from '@shared/components/page.component'; import { PageComponent } from '@shared/components/page.component';
import { DomSanitizer } from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';
@ -107,6 +121,49 @@ export class SolutionChatComponent extends PageComponent implements OnInit, OnDe
uninstalledAt = signal<number | null>(null); uninstalledAt = signal<number | null>(null);
failure = signal<string | null>(null);
readonly aboutFeatures = [
{icon: 'account_tree', title: 'solution-creator.about-design-title', line: 'solution-creator.about-design'},
{icon: 'fact_check', title: 'solution-creator.about-approve-title', line: 'solution-creator.about-approve'},
{icon: 'dashboard', title: 'solution-creator.about-dashboards-title', line: 'solution-creator.about-dashboards'},
{icon: 'layers', title: 'solution-creator.about-installed-title', line: 'solution-creator.about-installed'}
];
aboutOpen = signal(false);
paneScrolled = signal(false);
paneMore = signal(false);
issues = computed<Array<{name: string; status: string}>>(() => {
const results = this.info()?.metadata?.installResult?.entityResults;
if (!results || !this.info()?.metadata?.installed) {
return [];
}
return Object.values(results).flat()
.filter(entry => entry?.status === 'ERROR' || entry?.status === 'WARN')
.map(entry => ({name: entry.additionalData?.name ?? '', status: entry.status}));
});
private paneEdgeEffect = effect(() => {
this.currentView();
this.json();
this.paneOpen();
untracked(() => setTimeout(() => {
const body = this.elementRef.nativeElement.querySelector('.sol-pane-body') as HTMLElement;
if (body) {
this.onPaneScroll(body);
}
}, 50));
});
private runningEffect = effect(() => {
const id = this.info()?.id;
const running = this.loading() || this.isGenerating();
untracked(() => this.aiSolutions.setRunning(id, running));
});
mainUser = computed<{id: string; name: string} | null>(() => { mainUser = computed<{id: string; name: string} | null>(() => {
const result = this.info()?.metadata?.installResult; const result = this.info()?.metadata?.installResult;
const main = result?.mainDashboardId?.id; const main = result?.mainDashboardId?.id;
@ -464,6 +521,29 @@ export class SolutionChatComponent extends PageComponent implements OnInit, OnDe
}); });
} }
@HostListener('keydown.escape')
closeAbout(): void {
this.aboutOpen.set(false);
}
onPaneScroll(body: HTMLElement): void {
this.paneScrolled.set(body.scrollTop > 0);
this.paneMore.set(body.scrollTop + body.clientHeight < body.scrollHeight - 1);
}
private reportFailure(err: any): void {
const responseType = isNotEmptyStr(err?.error) ? 'text' : undefined;
this.failure.set(parseHttpErrorMessage(err, this.translate, responseType, this.sanitizer).message);
this.paneOpen.set(true);
setTimeout(() => this.scrollLogToEnd(true));
}
private openPaneForStep(): void {
if (window.innerWidth >= SolutionChatComponent.NARROW_WIDTH) {
this.paneOpen.set(true);
}
}
viewAsMainUser(): void { viewAsMainUser(): void {
const user = this.mainUser(); const user = this.mainUser();
const main = this.info()?.metadata?.installResult?.mainDashboardId?.id; const main = this.info()?.metadata?.installResult?.mainDashboardId?.id;
@ -553,7 +633,7 @@ export class SolutionChatComponent extends PageComponent implements OnInit, OnDe
} }
}, },
error: (err) => { error: (err) => {
this.showErrorMessage(err); this.reportFailure(err);
} }
}); });
} }
@ -589,7 +669,7 @@ export class SolutionChatComponent extends PageComponent implements OnInit, OnDe
error: (err) => { error: (err) => {
progressSubject.next(); progressSubject.next();
progressSubject.complete(); progressSubject.complete();
this.showErrorMessage(err); this.reportFailure(err);
} }
}); });
} }
@ -762,6 +842,9 @@ export class SolutionChatComponent extends PageComponent implements OnInit, OnDe
this.solutionInfo = solution; this.solutionInfo = solution;
this.rememberSolution(); this.rememberSolution();
this.updatedCurrentMsg(); this.updatedCurrentMsg();
if (this.isReadyStep()) {
this.openPaneForStep();
}
}), }),
catchError(err => { catchError(err => {
this.showErrorMessage(err); this.showErrorMessage(err);
@ -861,6 +944,7 @@ export class SolutionChatComponent extends PageComponent implements OnInit, OnDe
} }
private initPredefinedSolution(): void { private initPredefinedSolution(): void {
this.failure.set(null);
if (this.solutionInfo.metadata?.built) { if (this.solutionInfo.metadata?.built) {
if (this.solutionInfo.states[SolutionStep.DASHBOARDS_CONFIGURATION]) { if (this.solutionInfo.states[SolutionStep.DASHBOARDS_CONFIGURATION]) {
this.solutionStep.set(SolutionStep.DASHBOARDS_CONFIGURATION); this.solutionStep.set(SolutionStep.DASHBOARDS_CONFIGURATION);
@ -876,12 +960,16 @@ export class SolutionChatComponent extends PageComponent implements OnInit, OnDe
this.solutionStep.set(SolutionStep.DASHBOARDS_CONFIGURATION); this.solutionStep.set(SolutionStep.DASHBOARDS_CONFIGURATION);
} }
this.updatedCurrentMsg(); this.updatedCurrentMsg();
if (this.isReadyStep()) {
this.paneOpen.set(true);
}
if (this.solutionStep() === SolutionStep.DASHBOARDS_CONFIGURATION && dashboardState?.pendingChanges?.length) { if (this.solutionStep() === SolutionStep.DASHBOARDS_CONFIGURATION && dashboardState?.pendingChanges?.length) {
this.sendDashboardConfigurationMsg('<sync/>'); this.sendDashboardConfigurationMsg('<sync/>');
} }
} }
private initGenerateState() { private initGenerateState() {
this.failure.set(null);
this.isGenerating.set(true); this.isGenerating.set(true);
let messages: Array<{text: string; delay: number}>; let messages: Array<{text: string; delay: number}>;
let estimateWaitTime: number; let estimateWaitTime: number;
@ -1084,6 +1172,7 @@ export class SolutionChatComponent extends PageComponent implements OnInit, OnDe
} }
private initLoadingState(): void { private initLoadingState(): void {
this.failure.set(null);
this.loading.set(true); this.loading.set(true);
if (!this.workTimers.length) { if (!this.workTimers.length) {
this.startWork([{text: this.messages().length ? 'solution-creator.work-thinking' : 'solution-creator.work-reading', delay: 0}], 'think'); this.startWork([{text: this.messages().length ? 'solution-creator.work-thinking' : 'solution-creator.work-reading', delay: 0}], 'think');

2
ui-ngx/src/app/modules/home/pages/ai-assistant/ai-assistant.component.html

@ -69,6 +69,8 @@
}{{ chat.title }}</span> }{{ chat.title }}</span>
@if (chat.chat && aiChats.levelOf(chat.chat); as level) { @if (chat.chat && aiChats.levelOf(chat.chat); as level) {
<span [class]="'tb-ai-status-mark ' + level" [matTooltip]="aiChats.tipOf(chat.chat)" matTooltipPosition="above"></span> <span [class]="'tb-ai-status-mark ' + level" [matTooltip]="aiChats.tipOf(chat.chat)" matTooltipPosition="above"></span>
} @else if (chat.solution && aiSolutions.isRunning(chat.solution.id)) {
<span class="tb-ai-status-mark running" [matTooltip]="'ai-assistant.status-tip-running' | translate" matTooltipPosition="above"></span>
} }
<button type="button" class="ai-row-menu" [matMenuTriggerFor]="chat.solution ? solutionMenu : chatMenu" <button type="button" class="ai-row-menu" [matMenuTriggerFor]="chat.solution ? solutionMenu : chatMenu"
[matMenuTriggerData]="{chat: chat.chat, solution: chat.solution, row: chat}" (click)="$event.stopPropagation()" [matMenuTriggerData]="{chat: chat.chat, solution: chat.solution, row: chat}" (click)="$event.stopPropagation()"

13
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -11811,6 +11811,19 @@
"what-it-becomes": "A description becomes profiles, roles, calculated fields, alarm rules and dashboards, on simulated devices.", "what-it-becomes": "A description becomes profiles, roles, calculated fields, alarm rules and dashboards, on simulated devices.",
"example-tip": "Puts the example in the composer", "example-tip": "Puts the example in the composer",
"limits": "Nothing is created in your tenant until you approve the design and install it.", "limits": "Nothing is created in your tenant until you approve the design and install it.",
"what-is-solution": "What is a solution?",
"about-title": "ThingsBoard Solution Creator",
"about-design-title": "A description becomes a design",
"about-design": "The AI drafts the architecture: device and asset profiles, relations, roles, calculated fields and alarm rules.",
"about-approve-title": "You approve each step",
"about-approve": "Change anything in the chat, regenerate, then go on. Nothing is created until you say so.",
"about-dashboards-title": "Dashboards come with it",
"about-dashboards": "Every role gets its dashboard; simulated devices feed them until yours connect.",
"about-installed-title": "Installed in your tenant",
"about-installed": "Real entities, yours to keep: edit the design or uninstall it from the solution's chat.",
"issues-lead": "{ count, plural, =1 {One item needs a look} other {# items need a look} } after the install:",
"issues-tip-lead": "Tip:",
"issues-tip": "open the Solution view to see what went wrong with each, or ask about it here.",
"say-what-to-change": "Say what to change in the design…", "say-what-to-change": "Say what to change in the design…",
"ask-about-solution": "Ask about the solution…", "ask-about-solution": "Ask about the solution…",
"next-dashboards": "Next: dashboards", "next-dashboards": "Next: dashboards",

Loading…
Cancel
Save