Browse Source

feat: the AI button is the AI's mark, one component with the chat's welcome and header marks: its colour held back at rest and coming up under the pointer, on focus and while a closed chat works, a dot when a chat waits or failed, readable on a primary-coloured bar; the first time, the button glows and a popup introduces the docked chat in the page's own words, with its first suggestion and the / shortcut, shown on every page until the person answers it; the introduction's steps (welcome, assistant tour, AI button, Home) are kept per user in the user settings

pull/16833/head
Igor Kulikov 2 weeks ago
parent
commit
b8e623adf1
  1. 11
      ui-ngx/src/app/core/auth/auth.actions.ts
  2. 11
      ui-ngx/src/app/core/auth/auth.effects.ts
  3. 10
      ui-ngx/src/app/core/auth/auth.reducer.ts
  4. 14
      ui-ngx/src/app/core/auth/auth.selectors.ts
  5. 176
      ui-ngx/src/app/modules/home/components/ai/ai-assistant-button.component.ts
  6. 58
      ui-ngx/src/app/modules/home/components/ai/ai-assistant-context.service.ts
  7. 55
      ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.ts
  8. 39
      ui-ngx/src/app/modules/home/components/ai/ai-button-intro.component.ts
  9. 2
      ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.html
  10. 106
      ui-ngx/src/app/modules/home/components/ai/ai-chat.component.html
  11. 74
      ui-ngx/src/app/modules/home/components/ai/ai-mark.component.ts
  12. 6
      ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts
  13. 6
      ui-ngx/src/app/modules/home/components/ai/ai.module.ts
  14. 2
      ui-ngx/src/app/modules/home/components/ai/solution/pane/solution-installed.component.html
  15. 4
      ui-ngx/src/app/modules/home/components/ai/solution/solution-chat.component.html
  16. 10
      ui-ngx/src/app/shared/models/user-settings.models.ts
  17. 12
      ui-ngx/src/assets/locale/locale.constant-en_US.json
  18. 268
      ui-ngx/src/theme/ai-theme.scss

11
ui-ngx/src/app/core/auth/auth.actions.ts

@ -4,7 +4,7 @@
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { AuthUser, User } from '@shared/models/user.model'; import { AuthUser, User } from '@shared/models/user.model';
import { AuthPayload } from '@core/auth/auth.models'; import { AuthPayload } from '@core/auth/auth.models';
import { UserSettings } from '@shared/models/user-settings.models'; import { AiTourStep, UserSettings } from '@shared/models/user-settings.models';
export enum AuthActionTypes { export enum AuthActionTypes {
AUTHENTICATED = '[Auth] Authenticated', AUTHENTICATED = '[Auth] Authenticated',
@ -16,6 +16,7 @@ export enum AuthActionTypes {
UPDATE_HAS_REPOSITORY = '[Auth] Change Has Repository', UPDATE_HAS_REPOSITORY = '[Auth] Change Has Repository',
UPDATE_MOBILE_QR_ENABLED = '[Auth] Update Mobile QR Enabled', UPDATE_MOBILE_QR_ENABLED = '[Auth] Update Mobile QR Enabled',
UPDATE_OPENED_MENU_SECTION = '[Preferences] Update Opened Menu Section', UPDATE_OPENED_MENU_SECTION = '[Preferences] Update Opened Menu Section',
UPDATE_AI_TOUR = '[Preferences] Update AI tour',
PUT_USER_SETTINGS = '[Preferences] Put user settings', PUT_USER_SETTINGS = '[Preferences] Put user settings',
DELETE_USER_SETTINGS = '[Preferences] Delete user settings', DELETE_USER_SETTINGS = '[Preferences] Delete user settings',
UPDATE_LICENSE_PARAMS = '[Auth] Update License Parameters', UPDATE_LICENSE_PARAMS = '[Auth] Update License Parameters',
@ -73,6 +74,12 @@ export class ActionPreferencesUpdateOpenedMenuSection implements Action {
constructor(readonly payload: { path: string; opened: boolean }) {} constructor(readonly payload: { path: string; opened: boolean }) {}
} }
export class ActionPreferencesUpdateAiTour implements Action {
readonly type = AuthActionTypes.UPDATE_AI_TOUR;
constructor(readonly payload: { step: AiTourStep; seen: boolean }) {}
}
export class ActionPreferencesPutUserSettings implements Action { export class ActionPreferencesPutUserSettings implements Action {
readonly type = AuthActionTypes.PUT_USER_SETTINGS; readonly type = AuthActionTypes.PUT_USER_SETTINGS;
@ -93,5 +100,5 @@ export class ActionUpdateLicenseParams implements Action {
export type AuthActions = ActionAuthAuthenticated | ActionAuthUnauthenticated | export type AuthActions = ActionAuthAuthenticated | ActionAuthUnauthenticated |
ActionAuthLoadUser | ActionAuthUpdateUserDetails | ActionAuthUpdateLastPublicDashboardId | ActionAuthUpdateHasRepository | ActionAuthLoadUser | ActionAuthUpdateUserDetails | ActionAuthUpdateLastPublicDashboardId | ActionAuthUpdateHasRepository |
ActionPreferencesUpdateOpenedMenuSection | ActionPreferencesPutUserSettings | ActionPreferencesDeleteUserSettings | ActionPreferencesUpdateOpenedMenuSection | ActionPreferencesUpdateAiTour | ActionPreferencesPutUserSettings | ActionPreferencesDeleteUserSettings |
ActionAuthUpdateAuthUser | ActionUpdateMobileQrCodeEnabled | ActionUpdateLicenseParams; ActionAuthUpdateAuthUser | ActionUpdateMobileQrCodeEnabled | ActionUpdateLicenseParams;

11
ui-ngx/src/app/core/auth/auth.effects.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects'; import { Actions, createEffect, ofType } from '@ngrx/effects';
import { select, Store } from '@ngrx/store'; import { select, Store } from '@ngrx/store';
@ -26,6 +27,14 @@ export class AuthEffects {
mergeMap(([action, state]) => this.userSettingsService.putUserSettings({ openedMenuSections: state.userSettings.openedMenuSections })) mergeMap(([action, state]) => this.userSettingsService.putUserSettings({ openedMenuSections: state.userSettings.openedMenuSections }))
), {dispatch: false}); ), {dispatch: false});
persistAiTour = createEffect(() => this.actions$.pipe(
ofType(
AuthActionTypes.UPDATE_AI_TOUR,
),
withLatestFrom(this.store.pipe(select(selectAuthState))),
mergeMap(([action, state]) => this.userSettingsService.putUserSettings({ aiTour: state.userSettings.aiTour ?? {} }))
), {dispatch: false});
putUserSettings = createEffect(() => this.actions$.pipe( putUserSettings = createEffect(() => this.actions$.pipe(
ofType( ofType(
AuthActionTypes.PUT_USER_SETTINGS, AuthActionTypes.PUT_USER_SETTINGS,

10
ui-ngx/src/app/core/auth/auth.reducer.ts

@ -97,6 +97,16 @@ export const authReducer = (
userSettings = {...state.userSettings, ...{ openedMenuSections: Array.from(openedMenuSections)}}; userSettings = {...state.userSettings, ...{ openedMenuSections: Array.from(openedMenuSections)}};
return { ...state, ...{ userSettings }}; return { ...state, ...{ userSettings }};
case AuthActionTypes.UPDATE_AI_TOUR:
const aiTour = {...state.userSettings.aiTour};
if (action.payload.seen) {
aiTour[action.payload.step] = Date.now();
} else {
delete aiTour[action.payload.step];
}
userSettings = {...state.userSettings, aiTour};
return { ...state, ...{ userSettings }};
case AuthActionTypes.PUT_USER_SETTINGS: case AuthActionTypes.PUT_USER_SETTINGS:
userSettings = {...state.userSettings, ...action.payload}; userSettings = {...state.userSettings, ...action.payload};
return { ...state, ...{ userSettings }}; return { ...state, ...{ userSettings }};

14
ui-ngx/src/app/core/auth/auth.selectors.ts

@ -1,12 +1,13 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { createFeatureSelector, createSelector, select, Store } from '@ngrx/store'; import { createFeatureSelector, createSelector, select, Store } from '@ngrx/store';
import { AppState } from '../core.state'; import { AppState } from '../core.state';
import { AuthState } from './auth.models'; import { AuthState } from './auth.models';
import { take } from 'rxjs/operators'; import { take } from 'rxjs/operators';
import { AuthUser } from '@shared/models/user.model'; import { AuthUser } from '@shared/models/user.model';
import { UserSettings } from '@shared/models/user-settings.models'; import { AiTourStep, UserSettings } from '@shared/models/user-settings.models';
import { getDescendantProp } from '@core/utils'; import { getDescendantProp } from '@core/utils';
export const selectAuthState = createFeatureSelector< AuthState>( export const selectAuthState = createFeatureSelector< AuthState>(
@ -90,6 +91,15 @@ export const selectOpenedMenuSections = createSelector(
(state: AuthState) => state.userSettings.openedMenuSections (state: AuthState) => state.userSettings.openedMenuSections
); );
export const selectAiTour = createSelector(
selectAuthState,
(state: AuthState) => state.userSettings?.aiTour ?? {}
);
export const selectAiTourStepSeen = (step: AiTourStep) => createSelector(
selectAiTour,
aiTour => !!aiTour[step]
);
export const getCurrentAuthState = (store: Store<AppState>): AuthState => { export const getCurrentAuthState = (store: Store<AppState>): AuthState => {
let state: AuthState; let state: AuthState;

176
ui-ngx/src/app/modules/home/components/ai/ai-assistant-button.component.ts

@ -1,31 +1,57 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1 // SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component, computed, HostListener, inject } from '@angular/core'; import {
ChangeDetectionStrategy,
Component,
computed,
DestroyRef,
effect,
ElementRef,
HostListener,
inject,
Renderer2,
signal,
untracked,
viewChild,
ViewContainerRef
} from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { NavigationEnd, NavigationStart, Router } from '@angular/router';
import { filter } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { AiChatsService } from '@core/services/ai-chats.service'; import { AiChatsService } from '@core/services/ai-chats.service';
import { ChatLevel } from '@shared/models/ai-chat.models'; import { ChatLevel } from '@shared/models/ai-chat.models';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { getCurrentAuthState } from '@core/auth/auth.selectors'; import { getCurrentAuthState, selectAiTourStepSeen } from '@core/auth/auth.selectors';
import { ActionPreferencesUpdateAiTour } from '@core/auth/auth.actions';
import { AiTourStep } from '@shared/models/user-settings.models';
import { Authority } from '@shared/models/authority.enum'; import { Authority } from '@shared/models/authority.enum';
import { UserPermissionsService } from '@core/http/user-permissions.service'; import { UserPermissionsService } from '@core/http/user-permissions.service';
import { Operation, Resource } from '@shared/models/security.models'; import { Operation, Resource } from '@shared/models/security.models';
import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service';
import { TbPopoverService } from '@shared/components/popover.service';
import { TbPopoverComponent } from '@shared/components/popover.component';
import { AiAssistantContextService } from '@home/components/ai/ai-assistant-context.service';
import { AiButtonIntroComponent } from '@home/components/ai/ai-button-intro.component';
import { AiMarkCue } from '@home/components/ai/ai-mark.component';
const INTRO_DELAY_MS = 900;
const intro: { owner: AiAssistantButtonComponent | null } = {owner: null};
@Component({ @Component({
selector: 'tb-ai-assistant-button', selector: 'tb-ai-assistant-button',
template: ` template: `
@if (available && !panelService.open() && !panelService.suppressed()) { @if (available && !panelService.open() && !panelService.suppressed()) {
@let status = cue(); @let status = cue();
<button mat-icon-button type="button" class="tb-ai-assistant-button" [attr.data-cue]="status?.level" <button #aiButton tb-ai-mark class="tb-ai-assistant-button" [cue]="markCue()"
tb-popover [tbAiTip]="buttonTip" [working]="status?.level === 'running'" [glow]="introOpen()" [pressed]="panelService.open()"
tb-popover [tbAiTip]="buttonTip" [tbPopoverTrigger]="introOpen() ? null : 'hover'"
[attr.aria-label]="status ? ('ai-assistant.ai-assistant-cue' | translate: {cue: status.tip}) : ('ai-assistant.ai-assistant' | translate)" [attr.aria-label]="status ? ('ai-assistant.ai-assistant-cue' | translate: {cue: status.tip}) : ('ai-assistant.ai-assistant' | translate)"
aria-keyshortcuts="/"
(click)="toggle($event)"> (click)="toggle($event)">
<mat-icon fontSet="material-icons-round">auto_awesome</mat-icon>
@if (status && status.level !== 'running') {
<span class="tb-ai-assistant-cue tb-ai-status-mark" [class]="status.level" aria-hidden="true"></span>
}
</button> </button>
<ng-template #buttonTip> <ng-template #buttonTip>
<div class="tb-ai-tip-body tip-mini"> <div class="tb-ai-tip-body tip-mini">
@ -49,7 +75,9 @@ export class AiAssistantButtonComponent {
panelService = inject(AiAssistantPanelService); panelService = inject(AiAssistantPanelService);
private readonly authState = getCurrentAuthState(inject(Store<AppState>)); private store = inject(Store<AppState>);
private readonly authState = getCurrentAuthState(this.store);
readonly available = this.authState.aiEnabled readonly available = this.authState.aiEnabled
&& this.authState.authUser?.authority === Authority.TENANT_ADMIN && this.authState.authUser?.authority === Authority.TENANT_ADMIN
@ -61,12 +89,30 @@ export class AiAssistantButtonComponent {
private translate = inject(TranslateService); private translate = inject(TranslateService);
private context = inject(AiAssistantContextService);
private popoverService = inject(TbPopoverService);
private renderer = inject(Renderer2);
private viewContainerRef = inject(ViewContainerRef);
private buttonRef = viewChild('aiButton', {read: ElementRef<HTMLElement>});
private introSeen = toSignal(this.store.select(selectAiTourStepSeen(AiTourStep.AI_BUTTON)), {initialValue: true});
readonly introOpen = signal(false);
private introPopover: TbPopoverComponent<AiButtonIntroComponent> | null = null;
private introTimer: ReturnType<typeof setTimeout> | null = null;
readonly cue = computed<{level: ChatLevel; tip: string} | null>(() => { readonly cue = computed<{level: ChatLevel; tip: string} | null>(() => {
const chats = this.chats.statusChats(); const chats = this.chats.statusChats();
const titleOf = (title: string) => title || this.translate.instant('ai-assistant.new-chat'); const titleOf = (title: string) => title || this.translate.instant('ai-assistant.new-chat');
const attention = chats.filter(chat => this.chats.needsAttention(chat)); const attention = chats.filter(chat => this.chats.needsAttention(chat));
if (attention.length) { if (attention.length) {
const level: ChatLevel = attention.some(chat => this.chats.levelOf(chat) === 'needs') ? 'needs' : 'error'; const level: AiMarkCue = attention.some(chat => this.chats.levelOf(chat) === 'needs') ? 'needs' : 'error';
return { return {
level, level,
tip: attention.length === 1 tip: attention.length === 1
@ -86,10 +132,45 @@ export class AiAssistantButtonComponent {
return null; return null;
}); });
readonly markCue = computed<AiMarkCue | null>(() => {
const level = this.cue()?.level;
return level === 'needs' || level === 'error' ? level : null;
});
private introWanted = computed(() => this.available && !this.introSeen() && this.cue()?.level !== 'running' && !this.panelService.open()
&& !this.panelService.suppressed() && !!this.buttonRef());
private introEffect = effect(() => {
const wanted = this.introWanted();
untracked(() => {
this.clearIntroTimer();
if (wanted && !this.introOpen()) {
this.introTimer = setTimeout(() => this.showIntro(), INTRO_DELAY_MS);
} else if (!wanted && this.introOpen()) {
this.hideIntro();
}
});
});
constructor() { constructor() {
if (this.available) { if (this.available) {
this.chats.watchStatus(); this.chats.watchStatus();
} }
inject(Router).events.pipe(
filter(event => event instanceof NavigationStart || event instanceof NavigationEnd),
takeUntilDestroyed()
).subscribe(event => {
this.clearIntroTimer();
if (event instanceof NavigationStart) {
this.hideIntro();
} else if (this.introWanted()) {
this.introTimer = setTimeout(() => this.showIntro(), INTRO_DELAY_MS);
}
});
inject(DestroyRef).onDestroy(() => {
this.clearIntroTimer();
this.hideIntro();
});
} }
@HostListener('document:keydown', ['$event']) @HostListener('document:keydown', ['$event'])
@ -101,11 +182,84 @@ export class AiAssistantButtonComponent {
return; return;
} }
event.preventDefault(); event.preventDefault();
this.panelService.openPanel(); this.openChat();
} }
toggle($event: Event): void { toggle($event: Event): void {
$event.stopPropagation(); $event.stopPropagation();
this.openChat();
}
private openChat(): void {
if (this.introOpen()) {
this.closeIntro();
}
this.panelService.openPanel(); this.panelService.openPanel();
} }
private showIntro(): void {
this.introTimer = null;
const trigger: HTMLElement | undefined = this.buttonRef()?.nativeElement;
if (!this.introWanted() || !trigger || intro.owner || this.dialog.openDialogs.length || !this.visible(trigger)) {
return;
}
intro.owner = this;
const welcome = this.context.welcome();
const example = welcome.examples[0]?.label?.trim();
this.introOpen.set(true);
this.introPopover = this.popoverService.displayPopover({
trigger,
renderer: this.renderer,
componentType: AiButtonIntroComponent,
hostView: this.viewContainerRef,
preferredPlacement: ['bottomRight', 'bottom', 'bottomLeft'],
hideOnClickOutside: false,
showCloseButton: false,
context: {
title: welcome.title || this.translate.instant('ai-assistant.panel-title'),
lead: this.translate.instant(`ai-assistant.intro.lead-${welcome.place}${example ? '-example' : ''}`, {example}),
keyboard: matchMedia('(hover: hover) and (pointer: fine)').matches
},
visibleFn: visible => {
if (!visible && this.introOpen()) {
this.introPopover = null;
this.hideIntro();
}
}
});
this.introPopover.tbOverlayClassName = 'tb-ai-intro-popover';
this.introPopover.updateStyles();
const instance = this.introPopover.tbComponentRef.instance;
instance.dismiss.subscribe(() => this.closeIntro());
instance.openChat.subscribe(() => this.openChat());
}
private closeIntro(): void {
this.hideIntro();
if (!this.introSeen()) {
this.store.dispatch(new ActionPreferencesUpdateAiTour({step: AiTourStep.AI_BUTTON, seen: true}));
}
}
private hideIntro(): void {
if (intro.owner === this) {
intro.owner = null;
}
this.introOpen.set(false);
const popover = this.introPopover;
this.introPopover = null;
popover?.hide();
}
private clearIntroTimer(): void {
if (this.introTimer) {
clearTimeout(this.introTimer);
this.introTimer = null;
}
}
private visible(element: HTMLElement): boolean {
const rect = element.getBoundingClientRect();
return rect.width > 0 && rect.height > 0 && (element.checkVisibility?.({visibilityProperty: true}) ?? element.offsetParent !== null);
}
} }

58
ui-ngx/src/app/modules/home/components/ai/ai-assistant-context.service.ts

@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { computed, inject, Injectable } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { NavigationEnd, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { filter, map, startWith } from 'rxjs/operators';
import { aiPageView, AiChatClientContext } from '@shared/models/ai-chat.models';
import { getDefaultTimezone } from '@shared/models/time/time.models';
import { BreadCrumb } from '@shared/components/breadcrumb';
import { BreadcrumbService } from '@core/services/breadcrumb.service';
import { UtilsService } from '@core/services/utils.service';
import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service';
import { aiWelcome } from '@home/components/ai/ai-welcome.models';
@Injectable({providedIn: 'root'})
export class AiAssistantContextService {
private panelService = inject(AiAssistantPanelService);
private translate = inject(TranslateService);
private utils = inject(UtilsService);
private router = inject(Router);
private pageTitle = toSignal(inject(BreadcrumbService).breadcrumbs$.pipe(
map(crumbs => crumbs.map(crumb => this.crumbLabel(crumb)).filter(label => !!label).join(' › '))
), {initialValue: ''});
readonly pagePath = toSignal(this.router.events.pipe(
filter((event): event is NavigationEnd => event instanceof NavigationEnd),
map(event => event.urlAfterRedirects),
startWith(this.router.url),
map(url => (url || '/').split(/[?#]/)[0])
), {initialValue: '/'});
readonly clientContext = computed<AiChatClientContext | undefined>(() => {
const context = this.panelService.clientContext();
if (context) {
const name = this.panelService.viewName();
return context.view?.entityId && name && !context.view.title ? {...context, view: {...context.view, title: name}} : context;
}
const title = this.pageTitle();
const path = this.pagePath();
const type = aiPageView(path);
return title || path !== '/' ? {view: {type, title, path}, timeZone: getDefaultTimezone()} : undefined;
});
readonly welcome = computed(() => aiWelcome(this.clientContext()?.view, this.panelService.viewName(), this.panelService.config(),
this.translate));
private crumbLabel(crumb: BreadCrumb): string {
try {
return crumb.labelFunction ? crumb.labelFunction() : crumb.customTranslate ? this.utils.customTranslation(crumb.label, crumb.label)
: this.translate.instant(crumb.label);
} catch {
return '';
}
}
}

55
ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.ts

@ -1,21 +1,11 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1 // SPDX-License-Identifier: BUSL-1.1
import { aiPageView, AiChatClientContext } from '@shared/models/ai-chat.models';
import { getDefaultTimezone } from '@shared/models/time/time.models';
import { BreadCrumb } from '@shared/components/breadcrumb';
import { UtilsService } from '@core/services/utils.service';
import { BreadcrumbService } from '@core/services/breadcrumb.service';
import { filter, map, startWith } from 'rxjs/operators';
import { toSignal } from '@angular/core/rxjs-interop';
import { Router, NavigationEnd } from '@angular/router';
import { aiWelcome } from '@home/components/ai/ai-welcome.models';
import { Component, computed, effect, ElementRef, inject, NgZone, signal, untracked, ViewChild } from '@angular/core'; import { Component, computed, effect, ElementRef, inject, NgZone, signal, untracked, ViewChild } from '@angular/core';
import { MatTooltip } from '@angular/material/tooltip'; import { MatTooltip } from '@angular/material/tooltip';
import { AiAssistantPromptExample } from '@shared/models/ai-chat.models';
import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service';
import { TranslateService } from '@ngx-translate/core';
import { AiChatsService } from '@core/services/ai-chats.service'; import { AiChatsService } from '@core/services/ai-chats.service';
import { AiChatComponent } from '@home/components/ai/ai-chat.component'; import { AiChatComponent } from '@home/components/ai/ai-chat.component';
import { AiAssistantContextService } from '@home/components/ai/ai-assistant-context.service';
@Component({ @Component({
selector: 'tb-ai-assistant-panel', selector: 'tb-ai-assistant-panel',
@ -38,8 +28,6 @@ export class AiAssistantPanelComponent {
panelService = inject(AiAssistantPanelService); panelService = inject(AiAssistantPanelService);
private translate = inject(TranslateService);
@ViewChild(AiChatComponent) chat: AiChatComponent; @ViewChild(AiChatComponent) chat: AiChatComponent;
@ViewChild('gripTip', {read: MatTooltip}) gripTip: MatTooltip; @ViewChild('gripTip', {read: MatTooltip}) gripTip: MatTooltip;
@ -83,37 +71,11 @@ export class AiAssistantPanelComponent {
chatId = signal<string | undefined>(undefined); chatId = signal<string | undefined>(undefined);
private router = inject(Router); private context = inject(AiAssistantContextService);
private utils = inject(UtilsService);
private pageTitle = toSignal(inject(BreadcrumbService).breadcrumbs$.pipe(
map(crumbs => crumbs.map(crumb => this.crumbLabel(crumb)).filter(label => !!label).join(' › '))
), {initialValue: ''});
private pagePath = toSignal(this.router.events.pipe(
filter((event): event is NavigationEnd => event instanceof NavigationEnd),
map(event => event.urlAfterRedirects),
startWith(this.router.url),
map(url => (url || '/').split(/[?#]/)[0])
), {initialValue: '/'});
clientContext = computed<AiChatClientContext | undefined>(() => {
const context = this.panelService.clientContext();
if (context) {
const name = this.panelService.viewName();
return context.view?.entityId && name && !context.view.title ? {...context, view: {...context.view, title: name}} : context;
}
const title = this.pageTitle();
const path = this.pagePath();
const type = aiPageView(path);
return title || path !== '/' ? {view: {type, title, path}, timeZone: getDefaultTimezone()} : undefined;
});
promptExamples = computed<AiAssistantPromptExample[]>(() => this.panelService.config()?.promptExamples ?? []); clientContext = this.context.clientContext;
welcome = computed(() => aiWelcome(this.clientContext()?.view, this.panelService.viewName(), this.panelService.config(), welcome = this.context.welcome;
this.translate));
private chats = inject(AiChatsService); private chats = inject(AiChatsService);
private elementRef = inject(ElementRef<HTMLElement>); private elementRef = inject(ElementRef<HTMLElement>);
@ -303,15 +265,6 @@ export class AiAssistantPanelComponent {
}); });
} }
private crumbLabel(crumb: BreadCrumb): string {
try {
return crumb.labelFunction ? crumb.labelFunction() : crumb.customTranslate ? this.utils.customTranslation(crumb.label, crumb.label)
: this.translate.instant(crumb.label);
} catch {
return '';
}
}
close(): void { close(): void {
this.panelService.close(); this.panelService.close();
} }

39
ui-ngx/src/app/modules/home/components/ai/ai-button-intro.component.ts

@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
@Component({
selector: 'tb-ai-button-intro',
template: `
<div class="tb-ai-intro" data-ai role="status" aria-labelledby="tb-ai-intro-title">
<h3 class="tb-ai-intro-title" id="tb-ai-intro-title">{{ title }}</h3>
<button mat-icon-button type="button" class="tb-ai-intro-x" [attr.aria-label]="'action.close' | translate" (click)="dismiss.emit()">
<mat-icon fontSet="material-icons-round">close</mat-icon>
</button>
<p class="tb-ai-intro-body">
{{ lead }}
@if (keyboard) {
{{ 'ai-assistant.intro.press' | translate }} <kbd>/</kbd> {{ 'ai-assistant.intro.on-any-page' | translate }}
}
</p>
<div class="tb-ai-intro-actions">
<button mat-button type="button" class="tb-ai-intro-skip" (click)="dismiss.emit()">{{ 'ai-assistant.intro.got-it' | translate }}</button>
<button mat-flat-button type="button" class="tb-ai-intro-go" (click)="openChat.emit()">{{ 'ai-assistant.intro.open-chat' | translate }}</button>
</div>
</div>
`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AiButtonIntroComponent {
@Input() title: string;
@Input() lead: string;
@Input() keyboard = false;
@Output() dismiss = new EventEmitter<void>();
@Output() openChat = new EventEmitter<void>();
}

2
ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.html

@ -268,7 +268,7 @@
} @else if (work) { } @else if (work) {
<tb-ai-work-line class="work" [words]="work.headline || ('ai-assistant.work.' + work.moment | translate)" [since]="work.since"></tb-ai-work-line> <tb-ai-work-line class="work" [words]="work.headline || ('ai-assistant.work.' + work.moment | translate)" [since]="work.since"></tb-ai-work-line>
} @else { } @else {
<span class="tb-ai-mark" aria-hidden="true"><mat-icon>auto_awesome</mat-icon></span> <tb-ai-mark></tb-ai-mark>
<div class="glow-container"> <div class="glow-container">
{{ 'ai-assistant.thinking' | translate }} {{ 'ai-assistant.thinking' | translate }}
</div> </div>

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

@ -10,7 +10,7 @@
(fullscreenChanged)="onFullscreenChanged($event)"> (fullscreenChanged)="onFullscreenChanged($event)">
<ng-content select="[aiChatLead]"></ng-content> <ng-content select="[aiChatLead]"></ng-content>
@if (variant() === 'panel') { @if (variant() === 'panel') {
<span class="tb-ai-mark m32" aria-hidden="true"><mat-icon>auto_awesome</mat-icon></span> <tb-ai-mark size="32"></tb-ai-mark>
} }
<tb-ai-chat-title [title]="chat()?.title" [placeholder]="historyLoading() ? '' : ('ai-assistant.new-chat' | translate)" [level]="level()" <tb-ai-chat-title [title]="chat()?.title" [placeholder]="historyLoading() ? '' : ('ai-assistant.new-chat' | translate)" [level]="level()"
[statusTip]="statusTip()" [compact]="variant() === 'panel'" (renamed)="rename($event)"></tb-ai-chat-title> [statusTip]="statusTip()" [compact]="variant() === 'panel'" (renamed)="rename($event)"></tb-ai-chat-title>
@ -96,7 +96,7 @@
</div> </div>
} @else if (!chatId() && docked()) { } @else if (!chatId() && docked()) {
<div class="k-newchat"> <div class="k-newchat">
<span class="tb-ai-mark m44" aria-hidden="true"><tb-ai-spark></tb-ai-spark></span> <tb-ai-mark size="44"></tb-ai-mark>
<h3>{{ startTitle() || ('ai-assistant.panel-title' | translate) }}</h3> <h3>{{ startTitle() || ('ai-assistant.panel-title' | translate) }}</h3>
<p>{{ startLine() || ('ai-assistant.panel-line' | translate) }}</p> <p>{{ startLine() || ('ai-assistant.panel-line' | translate) }}</p>
@if (prompts().length) { @if (prompts().length) {
@ -113,7 +113,7 @@
</div> </div>
} @else if (!chatId()) { } @else if (!chatId()) {
<div class="ai-chat-start"> <div class="ai-chat-start">
<span class="tb-ai-mark m64" aria-hidden="true"><tb-ai-spark></tb-ai-spark></span> <tb-ai-mark size="64"></tb-ai-mark>
@if (variant() === 'panel') { @if (variant() === 'panel') {
<h1 class="ai-chat-start-title">{{ startTitle() || ('ai-assistant.panel-title' | translate) }}</h1> <h1 class="ai-chat-start-title">{{ startTitle() || ('ai-assistant.panel-title' | translate) }}</h1>
<p class="ai-chat-start-line">{{ startLine() || ('ai-assistant.panel-line' | translate) }}</p> <p class="ai-chat-start-line">{{ startLine() || ('ai-assistant.panel-line' | translate) }}</p>
@ -238,60 +238,62 @@
</div> </div>
<tb-ai-file-body [file]="file" [wrap]="fileWrap()" [whitespace]="fileWhitespace()" [saver]="fileSaver" <tb-ai-file-body [file]="file" [wrap]="fileWrap()" [whitespace]="fileWhitespace()" [saver]="fileSaver"
[marks]="fileMarks()" (marksChange)="fileMarks.set($event)" (discarded)="onFileDiscarded($event)"></tb-ai-file-body> [marks]="fileMarks()" (marksChange)="fileMarks.set($event)" (discarded)="onFileDiscarded($event)"></tb-ai-file-body>
@if (fileMarks(); as marks) { <ng-container ngProjectAs="[artFoot]">
<footer artFoot class="art-pane-foot art-marks"> @if (fileMarks(); as marks) {
<span class="file-marked"> <footer artFoot class="art-pane-foot art-marks">
<span class="file-marked-n">{{ (marks.from === marks.to ? 'ai-assistant.file.line' : 'ai-assistant.file.lines-range') | translate: {from: marks.from, to: marks.to} }}</span> <span class="file-marked">
{{ 'ai-assistant.file.marked' | translate }} <span class="file-marked-n">{{ (marks.from === marks.to ? 'ai-assistant.file.line' : 'ai-assistant.file.lines-range') | translate: {from: marks.from, to: marks.to} }}</span>
</span> {{ 'ai-assistant.file.marked' | translate }}
<span class="art-spacer"></span> </span>
<button mat-button type="button" (click)="fileMarks.set(null)">{{ 'ai-assistant.file.clear' | translate }}</button> <span class="art-spacer"></span>
<button mat-stroked-button type="button" (click)="copyMarked(file)"><mat-icon>content_copy</mat-icon>{{ 'action.copy' | translate }}</button> <button mat-button type="button" (click)="fileMarks.set(null)">{{ 'ai-assistant.file.clear' | translate }}</button>
<button mat-flat-button type="button" class="art-ask" (click)="askAboutMarks(file)"><mat-icon>auto_awesome</mat-icon>{{ 'ai-assistant.file.ask-about' | translate }}</button> <button mat-stroked-button type="button" (click)="copyMarked(file)"><mat-icon>content_copy</mat-icon>{{ 'action.copy' | translate }}</button>
</footer> <button mat-flat-button type="button" class="art-ask" (click)="askAboutMarks(file)"><mat-icon>auto_awesome</mat-icon>{{ 'ai-assistant.file.ask-about' | translate }}</button>
} @else { </footer>
<footer artFoot class="art-pane-foot file-bar"> } @else {
<span class="file-bar-info"> <footer artFoot class="art-pane-foot file-bar">
@if (fileBody()?.editing()) { <span class="file-bar-info">
@if (fileBody()?.dirty()) { @if (fileBody()?.editing()) {
<span class="file-bar-state"><i class="file-bar-dot" aria-hidden="true"></i>{{ 'ai-assistant.file.unsaved' | translate }}</span> @if (fileBody()?.dirty()) {
<span class="file-bar-state"><i class="file-bar-dot" aria-hidden="true"></i>{{ 'ai-assistant.file.unsaved' | translate }}</span>
} @else {
<span class="file-bar-state">{{ 'ai-assistant.file.editing' | translate }}</span>
}
@if (fileBody()?.caret(); as caret) {
<i class="file-bar-sep" aria-hidden="true">·</i>
<span class="file-bar-pos">{{ 'ai-assistant.file.position' | translate: {line: caret.line, col: caret.col} }}@if (caret.selected) { ({{ 'ai-assistant.file.selected' | translate: {count: caret.selected} }})}</span>
}
} @else if (fileBody()?.saved()) {
<span class="file-bar-saved"><mat-icon aria-hidden="true">check</mat-icon>{{ 'ai-assistant.file.saved' | translate }}</span>
} @else { } @else {
<span class="file-bar-state">{{ 'ai-assistant.file.editing' | translate }}</span> <span>{{ 'ai-assistant.file.lines' | translate: {count: file.lines} }}</span>
}
@if (fileBody()?.caret(); as caret) {
<i class="file-bar-sep" aria-hidden="true">·</i> <i class="file-bar-sep" aria-hidden="true">·</i>
<span class="file-bar-pos">{{ 'ai-assistant.file.position' | translate: {line: caret.line, col: caret.col} }}@if (caret.selected) { ({{ 'ai-assistant.file.selected' | translate: {count: caret.selected} }})}</span> <span>{{ file.size }}</span>
@if (file.edited) {
<i class="file-bar-sep" aria-hidden="true">·</i>
<span class="file-bar-ed">{{ 'ai-assistant.file.edited-in-chat' | translate }}</span>
}
} }
} @else if (fileBody()?.saved()) { </span>
<span class="file-bar-saved"><mat-icon aria-hidden="true">check</mat-icon>{{ 'ai-assistant.file.saved' | translate }}</span> <span class="file-bar-acts">
} @else { @if (fileBody()?.editing()) {
<span>{{ 'ai-assistant.file.lines' | translate: {count: file.lines} }}</span> @if (fileBody()?.dirty()) {
<i class="file-bar-sep" aria-hidden="true">·</i> <button mat-stroked-button type="button" class="file-bar-b" (click)="fileBody()?.discard()">{{ 'ai-assistant.file.discard' | translate }}</button>
<span>{{ file.size }}</span> <button mat-flat-button type="button" class="file-bar-b file-bar-save" [disabled]="loading() || fileBody()?.saving()" (click)="fileBody()?.save()">
@if (file.edited) { {{ 'ai-assistant.file.save' | translate }}
<i class="file-bar-sep" aria-hidden="true">·</i> </button>
<span class="file-bar-ed">{{ 'ai-assistant.file.edited-in-chat' | translate }}</span> } @else {
} <button mat-stroked-button type="button" class="file-bar-b" (click)="fileBody()?.done()">{{ 'ai-assistant.file.done' | translate }}</button>
} }
</span> } @else if (chatId()) {
<span class="file-bar-acts"> <button mat-stroked-button type="button" class="file-bar-b" (click)="fileBody()?.startEdit()">
@if (fileBody()?.editing()) { <mat-icon>edit</mat-icon>{{ 'ai-assistant.file.edit' | translate }}
@if (fileBody()?.dirty()) {
<button mat-stroked-button type="button" class="file-bar-b" (click)="fileBody()?.discard()">{{ 'ai-assistant.file.discard' | translate }}</button>
<button mat-flat-button type="button" class="file-bar-b file-bar-save" [disabled]="loading() || fileBody()?.saving()" (click)="fileBody()?.save()">
{{ 'ai-assistant.file.save' | translate }}
</button> </button>
} @else {
<button mat-stroked-button type="button" class="file-bar-b" (click)="fileBody()?.done()">{{ 'ai-assistant.file.done' | translate }}</button>
} }
} @else if (chatId()) { </span>
<button mat-stroked-button type="button" class="file-bar-b" (click)="fileBody()?.startEdit()"> </footer>
<mat-icon>edit</mat-icon>{{ 'ai-assistant.file.edit' | translate }} }
</button> </ng-container>
}
</span>
</footer>
}
</tb-ai-artifact-pane> </tb-ai-artifact-pane>
<mat-menu #imageDownloads="matMenu" xPosition="before" class="tb-ai-chat-menu"> <mat-menu #imageDownloads="matMenu" xPosition="before" class="tb-ai-chat-menu">
<button mat-menu-item type="button" (click)="downloadFile(file)"> <button mat-menu-item type="button" (click)="downloadFile(file)">

74
ui-ngx/src/app/modules/home/components/ai/ai-mark.component.ts

@ -0,0 +1,74 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component, ElementRef, inject, input, numberAttribute, booleanAttribute } from '@angular/core';
export type AiMarkCue = 'needs' | 'error';
const MARK_CYCLE_MS = 16000;
const LARGE_MARK = 44;
@Component({
selector: 'tb-ai-mark, button[tb-ai-mark]',
template: `
<ng-template #glyph>
@if (icon()) {
<mat-icon fontSet="material-icons-round">{{ icon() }}</mat-icon>
} @else if (large()) {
<tb-ai-spark></tb-ai-spark>
} @else {
<mat-icon fontSet="material-icons-round">auto_awesome</mat-icon>
}
</ng-template>
@if (button) {
<span class="tb-ai-mark" [class.lg]="large()" [style.--m]="sizePx()" [style.animation-delay]="phase" aria-hidden="true">
<ng-container [ngTemplateOutlet]="glyph"></ng-container>
</span>
@if (cue()) {
<span class="tb-ai-mark-cue" [class]="cue()" aria-hidden="true"></span>
}
} @else {
<ng-container [ngTemplateOutlet]="glyph"></ng-container>
}
`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'[class.tb-ai-mark]': '!button',
'[class.lg]': '!button && large()',
'[style.--m]': 'button ? null : sizePx()',
'[style.animation-delay]': 'button ? null : phase',
'[attr.aria-hidden]': 'button ? null : "true"',
'[class.tb-ai-mark-button]': 'button',
'[attr.type]': 'button ? "button" : null',
'[attr.aria-pressed]': 'button ? pressed() : null',
'[class.working]': 'button && working()',
'[class.glow]': 'button && glow()'
}
})
export class AiMarkComponent {
readonly button = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement.tagName === 'BUTTON';
readonly phase = `-${Date.now() % MARK_CYCLE_MS}ms`;
size = input<number | undefined, unknown>(undefined, {transform: (value: unknown) => value == null || value === '' ? undefined : numberAttribute(value)});
icon = input<string>();
pressed = input(false, {transform: booleanAttribute});
working = input(false, {transform: booleanAttribute});
glow = input(false, {transform: booleanAttribute});
cue = input<AiMarkCue | null>(null);
large(): boolean {
return (this.size() ?? 0) >= LARGE_MARK;
}
sizePx(): string | null {
const size = this.size() ?? (this.button ? 36 : undefined);
return size ? `${size}px` : null;
}
}

6
ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts

@ -4,7 +4,10 @@ import { TranslateService } from '@ngx-translate/core';
import { EntityType } from '@shared/models/entity-type.models'; import { EntityType } from '@shared/models/entity-type.models';
import { AiAssistantPanelConfig, AiAssistantPromptExample, AiAssistantViewType, AiChatView } from '@shared/models/ai-chat.models'; import { AiAssistantPanelConfig, AiAssistantPromptExample, AiAssistantViewType, AiChatView } from '@shared/models/ai-chat.models';
export type AiWelcomePlace = 'dashboard' | 'list' | 'page';
export interface AiWelcome { export interface AiWelcome {
place: AiWelcomePlace;
title?: string; title?: string;
line?: string; line?: string;
examples: AiAssistantPromptExample[]; examples: AiAssistantPromptExample[];
@ -145,7 +148,7 @@ export function aiWelcome(view: AiChatView | undefined, name: string | null, con
const configExamples = config?.promptExamples ?? []; const configExamples = config?.promptExamples ?? [];
const kind = view ? WELCOMES[view.type] : undefined; const kind = view ? WELCOMES[view.type] : undefined;
if (!kind) { if (!kind) {
return {title: config?.title, line: config?.subTitle, examples: configExamples, suggestion: config?.suggestion ?? shortExample(configExamples)}; return {place: 'page', title: config?.title, line: config?.subTitle, examples: configExamples, suggestion: config?.suggestion ?? shortExample(configExamples)};
} }
const base = 'ai-assistant.welcome.' + (config?.welcomeKey ?? kind.key); const base = 'ai-assistant.welcome.' + (config?.welcomeKey ?? kind.key);
const own = (kind.examples ?? []).map(example => ({ const own = (kind.examples ?? []).map(example => ({
@ -154,6 +157,7 @@ export function aiWelcome(view: AiChatView | undefined, name: string | null, con
})); }));
const examples = kind.entity && own.length ? own : [...own, ...configExamples.filter(item => !own.some(mine => mine.message === item.message))]; const examples = kind.entity && own.length ? own : [...own, ...configExamples.filter(item => !own.some(mine => mine.message === item.message))];
return { return {
place: view.type === AiAssistantViewType.DASHBOARD ? 'dashboard' : kind.entity ? 'page' : 'list',
title: translate.instant(`${base}.${titleKey(kind, view, name)}`, {name}), title: translate.instant(`${base}.${titleKey(kind, view, name)}`, {name}),
line: translate.instant(`${base}.line`), line: translate.instant(`${base}.line`),
examples, examples,

6
ui-ngx/src/app/modules/home/components/ai/ai.module.ts

@ -37,6 +37,8 @@ import { AiPlanComponent } from '@home/components/ai/ai-plan.component';
import { AiArtifactPaneComponent } from '@home/components/ai/ai-artifact-pane.component'; import { AiArtifactPaneComponent } from '@home/components/ai/ai-artifact-pane.component';
import { AiFileBodyComponent } from '@home/components/ai/ai-file-body.component'; import { AiFileBodyComponent } from '@home/components/ai/ai-file-body.component';
import { AiSparkComponent } from '@home/components/ai/ai-spark.component'; import { AiSparkComponent } from '@home/components/ai/ai-spark.component';
import { AiMarkComponent } from '@home/components/ai/ai-mark.component';
import { AiButtonIntroComponent } from '@home/components/ai/ai-button-intro.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -66,6 +68,8 @@ import { AiSparkComponent } from '@home/components/ai/ai-spark.component';
AiCardActionsComponent, AiCardActionsComponent,
AiDisclosureComponent, AiDisclosureComponent,
AiSparkComponent, AiSparkComponent,
AiMarkComponent,
AiButtonIntroComponent,
AiQuestionComponent, AiQuestionComponent,
AiPlanComponent, AiPlanComponent,
AiArtifactPaneComponent, AiArtifactPaneComponent,
@ -88,6 +92,8 @@ import { AiSparkComponent } from '@home/components/ai/ai-spark.component';
AiWorkLineComponent, AiWorkLineComponent,
AiRunSummaryComponent, AiRunSummaryComponent,
AiSparkComponent, AiSparkComponent,
AiMarkComponent,
AiButtonIntroComponent,
AiPromptInputComponent, AiPromptInputComponent,
AiAssistantPanelComponent, AiAssistantPanelComponent,
AiChatComponent, AiChatComponent,

2
ui-ngx/src/app/modules/home/components/ai/solution/pane/solution-installed.component.html

@ -7,7 +7,7 @@
@if (creating()) { @if (creating()) {
} @else if (installed() && !bannerClosed()) { } @else if (installed() && !bannerClosed()) {
<div class="sol-done" role="status"> <div class="sol-done" role="status">
<span class="tb-ai-mark m44 sol-done-mark" aria-hidden="true"><mat-icon>check</mat-icon></span> <tb-ai-mark class="sol-done-mark" size="44" icon="check"></tb-ai-mark>
<div class="sol-done-t"> <div class="sol-done-t">
<b>{{ 'solution-creator.pane.installed' | translate }}</b> <b>{{ 'solution-creator.pane.installed' | translate }}</b>
<span>{{ 'solution-creator.pane.installed-line' | translate: {entities: entityCount(), dashboards: dashboardCount()} }}</span> <span>{{ 'solution-creator.pane.installed-line' | translate: {entities: entityCount(), dashboards: dashboardCount()} }}</span>

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

@ -34,7 +34,7 @@
<div class="sol-hero"> <div class="sol-hero">
<div class="sol-hero-scroll"> <div class="sol-hero-scroll">
<div class="sol-hero-in"> <div class="sol-hero-in">
<span class="tb-ai-mark m64 sol-mark" aria-hidden="true"><mat-icon>layers</mat-icon></span> <tb-ai-mark class="sol-mark" size="64" icon="layers"></tb-ai-mark>
<h1 class="sol-title">{{ 'solution-creator.what-should-it-do' | translate }}</h1> <h1 class="sol-title">{{ 'solution-creator.what-should-it-do' | translate }}</h1>
<p class="sol-lead">{{ 'solution-creator.what-it-becomes' | translate }}</p> <p class="sol-lead">{{ 'solution-creator.what-it-becomes' | translate }}</p>
<tb-ai-prompt-input class="sol-hero-input" <tb-ai-prompt-input class="sol-hero-input"
@ -251,7 +251,7 @@
<div class="art-loading k-mark sol-loading" role="status"> <div class="art-loading k-mark sol-loading" role="status">
<span class="art-load-markwrap"> <span class="art-load-markwrap">
<span class="art-load-glow" aria-hidden="true"></span> <span class="art-load-glow" aria-hidden="true"></span>
<span class="tb-ai-mark m64" aria-hidden="true"><tb-ai-spark></tb-ai-spark></span> <tb-ai-mark size="64"></tb-ai-mark>
</span> </span>
<tb-ai-load-lines [line]="work()?.words" [lines]="work()?.lines ?? []"></tb-ai-load-lines> <tb-ai-load-lines [line]="work()?.words" [lines]="work()?.lines ?? []"></tb-ai-load-lines>
<p class="art-load-note">{{ estimateOf(making()) }}</p> <p class="art-load-note">{{ estimateOf(making()) }}</p>

10
ui-ngx/src/app/shared/models/user-settings.models.ts

@ -12,8 +12,18 @@ export interface UserSettings {
includeResourcesInExportWidgetTypes?: boolean; includeResourcesInExportWidgetTypes?: boolean;
includeResourcesInExportDashboard?: boolean; includeResourcesInExportDashboard?: boolean;
isSolutionSidebarExpanded?: boolean; isSolutionSidebarExpanded?: boolean;
aiTour?: AiTourSettings;
} }
export enum AiTourStep {
WELCOME = 'welcome',
ASSISTANT_TOUR = 'assistantTour',
AI_BUTTON = 'aiButton',
HOME = 'home'
}
export type AiTourSettings = Partial<Record<AiTourStep, number>>;
export const initialUserSettings: UserSettings = { export const initialUserSettings: UserSettings = {
openedMenuSections: [] openedMenuSections: []
}; };

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

@ -2568,6 +2568,18 @@
"all-chats": "All chats", "all-chats": "All chats",
"panel-title": "Ask about this page", "panel-title": "Ask about this page",
"panel-line": "What is on it, what to change, or something new.", "panel-line": "What is on it, what to change, or something new.",
"intro": {
"lead-dashboard": "The chat opens beside the dashboard, already in context.",
"lead-dashboard-example": "The chat opens beside the dashboard, already in context: “{{example}}” needs no names.",
"lead-list": "The chat opens beside the list, already in context.",
"lead-list-example": "The chat opens beside the list, already in context: “{{example}}” needs no names.",
"lead-page": "The chat opens beside the page, already in context.",
"lead-page-example": "The chat opens beside the page, already in context: “{{example}}” needs no names.",
"press": "Press",
"on-any-page": "on any page to open the chat.",
"got-it": "Got it",
"open-chat": "Open the chat"
},
"started-from": "Started from", "started-from": "Started from",
"open-page": "Open {{name}}", "open-page": "Open {{name}}",
"page": { "page": {

268
ui-ngx/src/theme/ai-theme.scss

@ -340,13 +340,8 @@
} }
} }
&.m24 { --m: 24px; } &.lg {
&.m28 { --m: 28px; } --ai-spark: .74;
&.m32 { --m: 32px; }
&.m44 { --m: 44px; --ai-spark: .74; }
&.m64 { --m: 64px; --ai-spark: .74; }
&.m44, &.m64 {
box-shadow: var(--ai-mark-edge), 0 1px 2px rgb(16 24 40 / 0.06), 0 8px 24px color-mix(in oklab, var(--ai-light-teal) 26%, transparent); box-shadow: var(--ai-mark-edge), 0 1px 2px rgb(16 24 40 / 0.06), 0 8px 24px color-mix(in oklab, var(--ai-light-teal) 26%, transparent);
} }
@ -6271,39 +6266,256 @@ tb-ai-action-detail.k-detail .tb-codeblock pre.tb-code {
overflow: auto; overflow: auto;
} }
@property --ai-h { .tb-ai-mark-button {
syntax: '<number>'; position: relative;
inherits: true; isolation: isolate;
initial-value: 172; flex: none;
display: inline-flex;
align-items: center;
justify-content: center;
width: 44px;
height: 44px;
padding: 0;
border: 0;
border-radius: 12px;
background: none;
cursor: pointer;
outline: none;
-webkit-tap-highlight-color: transparent;
transition: background-color .16s ease, transform .16s cubic-bezier(.2, .8, .2, 1);
&:active {
transform: scale(.96);
}
> .tb-ai-mark {
position: relative;
isolation: isolate;
pointer-events: none;
animation-play-state: paused;
transition: box-shadow .25s ease, transform .25s cubic-bezier(.2, .8, .2, 1);
&::before {
content: '';
position: absolute;
inset: 0;
z-index: -1;
border-radius: inherit;
background: var(--tb-surface);
opacity: .62;
transition: opacity .25s ease;
}
}
&:hover, &:focus-visible, &[aria-pressed="true"], &.working, &.glow {
> .tb-ai-mark {
animation-play-state: running;
&::before {
opacity: 0;
}
}
}
&:hover > .tb-ai-mark {
transform: scale(1.05);
box-shadow: var(--ai-mark-edge), 0 3px 12px color-mix(in oklab, var(--ai-light-teal) 60%, transparent);
}
&[aria-pressed="true"] {
background: rgba(0, 0, 0, 0.08);
}
&:focus-visible {
outline: 2px solid var(--ai-focus);
outline-offset: 2px;
}
&.glow::after {
content: '';
position: absolute;
inset: -4px;
z-index: -1;
border-radius: 16px;
background: var(--ai-glow);
filter: blur(7px);
opacity: .7;
pointer-events: none;
animation: tb-ai-intro-breathe 1.8s ease-in-out 3 both;
}
.tb-ai-mark-cue {
position: absolute;
top: 2px;
right: 2px;
display: flex;
align-items: center;
justify-content: center;
width: 14px;
height: 14px;
pointer-events: none;
&::before {
content: '';
display: block;
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: 0 0 0 2px var(--tb-ai-cue-ring, var(--tb-primary-background-color, #fff));
}
&.needs::before {
background: var(--tb-caution);
}
&.error::before {
width: 8px;
height: 8px;
border-radius: 1.5px;
background: var(--tb-crit);
transform: rotate(45deg);
}
}
@media (prefers-reduced-motion: reduce) {
&, > .tb-ai-mark, > .tb-ai-mark::before {
transition: none;
}
&:active, &:hover > .tb-ai-mark {
transform: none;
}
&.glow::after {
animation: none;
}
}
} }
@keyframes tb-ai-mark-hue { .tb-primary-panels .mat-toolbar .tb-ai-mark-button {
from { --ai-h: calc(var(--ai-hue) - 8); } --tb-ai-cue-ring: var(--tb-primary-contrast-500, #fff);
to { --ai-h: calc(var(--ai-hue) + 120); }
&[aria-pressed="true"] {
background: color-mix(in srgb, var(--tb-primary-contrast-500, #fff) 18%, transparent);
}
&:focus-visible {
outline-color: var(--tb-primary-contrast-500, #fff);
}
} }
.tb-ai-assistant-button { @keyframes tb-ai-intro-breathe {
position: relative; 0%, 100% { opacity: .7; }
50% { opacity: .25; }
}
.tb-ai-assistant-cue { .tb-popover.tb-ai-intro-popover {
position: absolute; > .tb-popover-content > .tb-popover-arrow {
top: 5px;
right: 5px;
width: 12px; width: 12px;
height: 12px; height: 12px;
border: 0;
background: var(--tb-surface);
box-shadow: -1px -1px 0 rgba(0, 0, 0, 0.04);
}
&.tb-popover-placement-bottom, &.tb-popover-placement-bottomLeft, &.tb-popover-placement-bottomRight {
> .tb-popover-content > .tb-popover-arrow {
top: 4px;
}
}
.tb-popover-inner {
border-radius: 14px;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(16, 24, 40, 0.14), 0 24px 56px rgba(16, 24, 40, 0.16);
}
.tb-popover-inner-content {
padding: 20px 48px 16px 24px;
}
}
.tb-ai-intro {
display: flex;
flex-direction: column;
gap: 8px;
width: min(288px, calc(100vw - 88px));
.tb-ai-intro-title {
margin: 0;
font: 500 17px/24px var(--tb-font);
letter-spacing: 0;
color: var(--tb-ink);
}
.tb-ai-intro-x.mat-mdc-icon-button.mat-mdc-button-base {
--mdc-icon-button-state-layer-size: 32px;
--mat-icon-button-state-layer-size: 32px;
position: absolute;
top: 12px;
right: 12px;
display: inline-flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
padding: 4px;
border-radius: 50%; border-radius: 50%;
background: var(--tb-surface, #fff); color: var(--tb-ink-54);
pointer-events: none;
.mat-icon {
font-size: 24px;
width: 24px;
height: 24px;
}
.mat-mdc-button-touch-target {
width: 32px;
height: 32px;
}
} }
&[data-cue="running"] .mat-icon { .tb-ai-intro-body {
color: oklch(0.45 0.12 var(--ai-h)); margin: 0;
animation: tb-ai-mark-hue 1.6s ease-in-out infinite alternate; font: 400 14px/20px var(--tb-font);
letter-spacing: 0;
color: var(--tb-ink-76);
kbd {
display: inline-block;
min-width: 18px;
padding: 0 5px;
border-radius: 4px;
background: var(--chat-key);
box-shadow: inset 0 -1px 0 var(--tb-line);
font: 500 12px/18px var(--tb-font);
text-align: center;
color: var(--tb-ink);
}
} }
@media (prefers-reduced-motion: reduce) { .tb-ai-intro-actions {
&[data-cue="running"] .mat-icon { display: flex;
animation: none; justify-content: flex-end;
align-items: center;
gap: 8px;
margin: 4px -28px 0 0;
.mdc-button {
height: 36px;
padding: 0 14px;
border-radius: 8px;
} }
} }
.tb-ai-intro-go {
--mat-button-filled-container-color: var(--ai-action);
--mdc-filled-button-container-color: var(--ai-action);
--mat-button-filled-label-text-color: var(--ai-on-action);
--mdc-filled-button-label-text-color: var(--ai-on-action);
}
.tb-ai-intro-skip {
--mat-button-text-label-text-color: var(--tb-ink);
--mdc-text-button-label-text-color: var(--tb-ink);
}
} }

Loading…
Cancel
Save