Browse Source

feat: the alarm details dialog makes the alarm the AI assistant's view, and a dialog's view now survives the table re-setting its context; labels, action details and review types for update_alarms, save_asset and save_relations; alarm and asset delete labels; welcome examples on the alarm list, an alarm and the asset list

pull/16833/head
Igor Kulikov 3 weeks ago
parent
commit
be8a13919e
  1. 28
      ui-ngx/src/app/core/services/ai-assistant-panel.service.ts
  2. 42
      ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts
  3. 6
      ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts
  4. 2
      ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts
  5. 5
      ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts
  6. 10
      ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts
  7. 1
      ui-ngx/src/app/shared/models/ai-chat.models.ts
  8. 66
      ui-ngx/src/assets/locale/locale.constant-en_US.json

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

@ -196,6 +196,7 @@ export class AiAssistantPanelService implements OnDestroy {
case AiAssistantViewType.ALARM_RULE:
case AiAssistantViewType.ALARM_RULE_LIST:
case AiAssistantViewType.ALARM_LIST:
case AiAssistantViewType.ALARM:
return 'ALARM_RULE';
case AiAssistantViewType.CALCULATED_FIELD:
case AiAssistantViewType.CALCULATED_FIELD_LIST:
@ -292,6 +293,10 @@ export class AiAssistantPanelService implements OnDestroy {
readonly viewName = this._viewName.asReadonly();
setViewName(name: string | null): void {
if (this._focus) {
this._focus.previousName = name?.trim() || null;
return;
}
this._viewName.set(name?.trim() || null);
}
@ -303,7 +308,14 @@ export class AiAssistantPanelService implements OnDestroy {
this._detailsOpen.set(open);
}
private _focus: {context: AiChatClientContext; previous: AiChatClientContext; previousName: string | null} | null = null;
setClientContext(ctx: AiChatClientContext | null): void {
if (this._focus && ctx) {
this._focus.previous = ctx;
return;
}
this._focus = null;
this._clientContext.set(ctx);
}
@ -317,14 +329,15 @@ export class AiAssistantPanelService implements OnDestroy {
if (!previous || !view.entityId?.id) {
return until;
}
const previousName = this._viewName();
const focused: AiChatClientContext = {view, timeZone: getDefaultTimezone()};
this._clientContext.set(focused);
this.setViewName(name ?? null);
const focus = {context: {view, timeZone: getDefaultTimezone()}, previous, previousName: this._viewName()};
this._focus = focus;
this._clientContext.set(focus.context);
this._viewName.set(name?.trim() || null);
return until.pipe(finalize(() => {
if (this._clientContext() === focused) {
this._clientContext.set(previous);
this._viewName.set(previousName);
if (this._focus === focus) {
this._focus = null;
this._clientContext.set(focus.previous);
this._viewName.set(focus.previousName);
}
}));
});
@ -349,6 +362,7 @@ export class AiAssistantPanelService implements OnDestroy {
teardown(): void {
this._enabled.set(false);
this._detailsOpen.set(false);
this._focus = null;
this._clientContext.set(null);
this._viewName.set(null);
this._sentClientContextByChat.clear();

42
ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts

@ -1105,6 +1105,7 @@ function describe(tool: string, values: Values, result: unknown, names: AiDetail
const kind = tool.replace(/^save_/, '').replace(/_/g, '-');
return {hood: text('save', {what: K + 'kind.' + kind, name: str(saved.name) ?? str(saved.title) ?? '—'}), blocks: [{type: 'facts', rows: savedFacts(saved, names)}]};
}
case 'save_asset':
case 'save_entity_view':
case 'save_asset_profile':
case 'save_secret':
@ -1125,10 +1126,51 @@ function describe(tool: string, values: Values, result: unknown, names: AiDetail
}
return {hood: text('save', {what: K + 'kind.' + kind, name}), blocks: rows.length ? [{type: 'facts', rows}] : generic(result, 'result')};
}
case 'save_relations': {
if (!isObject(result)) {
return {hood: text('save-relations'), blocks: generic(result, 'result')};
}
const blocks: AiDetailBlock[] = [];
for (const [field, label] of [['added', 'relations-added'], ['removed', 'relations-removed']] as const) {
const rows = Array.isArray(result[field]) ? result[field].map(String) : [];
if (rows.length) {
blocks.push({type: 'list', label: text(label), rows: rows.slice(0, MAX_ROWS)});
}
}
const failed = Array.isArray(result.failed) ? result.failed.filter(isObject) : [];
if (failed.length) {
blocks.push({type: 'list', label: text('relations-failed'), rows: failed.slice(0, MAX_ROWS).map(row => `${row.relation}: ${row.error}`)});
}
return {hood: text('save-relations'), blocks};
}
case 'read_platform_settings':
return {hood: text('read-platform-settings'), blocks: json('settings', result)};
case 'save_platform_settings':
return {hood: text('save-platform-settings'), blocks: json('settings', result)};
case 'update_alarms': {
const action = String(values.action ?? '').toLowerCase();
const count = Array.isArray(values.alarmIds) ? values.alarmIds.length : 0;
if (!isObject(result)) {
return {hood: text('update-alarms.' + action, {count}), blocks: generic(result, 'result')};
}
const blocks: AiDetailBlock[] = [];
const done = Array.isArray(result.done) ? result.done.map(String) : [];
const skipped = Array.isArray(result.skipped) ? result.skipped.map(String) : [];
const failed = Array.isArray(result.failed) ? result.failed.filter(isObject) : [];
if (done.length) {
blocks.push({type: 'list', label: text('alarms-done'), rows: done.slice(0, MAX_ROWS)});
}
if (skipped.length) {
blocks.push({type: 'list', label: text('alarms-skipped'), rows: skipped.slice(0, MAX_ROWS)});
}
if (failed.length) {
blocks.push({type: 'list', label: text('alarms-failed'), rows: failed.slice(0, MAX_ROWS).map(row => `${row.alarm}: ${row.error}`)});
}
if (str(values.comment)) {
blocks.push({type: 'facts', rows: [{label: K + 'fact.comment', value: values.comment}]});
}
return {hood: text('update-alarms.' + action, {count}), blocks};
}
case 'read_api_usage':
return {hood: text('read-api-usage'), blocks: apiUsageBlocks(result)};
case 'read_audit_logs':

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

@ -63,6 +63,7 @@ const TOOL_WORDS: Record<string, string> = {
read_tasks: 'read-tasks',
save_image: 'save-image',
read_platform_settings: 'read-platform-settings',
save_relations: 'save-relations',
save_platform_settings: 'save-platform-settings',
read_device_connect_commands: 'read-connection-settings',
search_web: 'search-web',
@ -91,6 +92,7 @@ const SAVED_KINDS: Record<string, [string, string]> = {
save_entity_group: ['entity-group', ''],
save_role: ['role', ''],
save_entity_view: ['entity-view', ''],
save_asset: ['asset', ''],
save_asset_profile: ['asset-profile', ''],
save_secret: ['secret', ''],
save_ai_model: ['ai-model', ''],
@ -124,6 +126,8 @@ const DELETED_TARGETS: Record<string, string> = {
ENTITY_GROUP: 'delete-entity-group',
ROLE: 'delete-role',
GROUP_PERMISSION: 'delete-grant',
ALARM: 'delete-alarm',
ASSET: 'delete-asset',
IMAGE: 'delete-image',
ENTITY_VIEW: 'delete-entity-view',
ASSET_PROFILE: 'delete-asset-profile',
@ -308,6 +312,8 @@ export function aiActionWords(tool: string, args: unknown): AiActionWords {
return {key: ACTION_PREFIX + (Array.isArray(values.widgets) && values.widgets.length === 1 ? 'add-widget' : 'add-widgets'), kind: 'think'};
case 'search_entities':
return {key: ACTION_PREFIX + searchedWords(values), kind: 'think'};
case 'update_alarms':
return {key: ACTION_PREFIX + 'update-alarms.' + String(values.action ?? 'other').toLowerCase(), kind: 'think'};
case 'read_timeseries':
return {key: ACTION_PREFIX + telemetryWords(values), kind: 'think'};
case 'delete':

2
ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts

@ -51,7 +51,7 @@ const VALUE_TOKENS: Record<string, string[]> = {
const CODE_FIELDS = new Set(['arguments', 'expression', 'output']);
const OWN_TYPE_LABELS = new Set(['DASHBOARD_WIDGET', 'DASHBOARD_STATE', 'DASHBOARD_ENTITY_ALIAS', 'DASHBOARD_FILTER', 'NOTIFICATION', 'NOTIFICATION_SETTINGS', 'NOTIFICATION_PREFERENCES', 'IMAGE', 'PLATFORM_SETTINGS']);
const OWN_TYPE_LABELS = new Set(['DASHBOARD_WIDGET', 'DASHBOARD_STATE', 'DASHBOARD_ENTITY_ALIAS', 'DASHBOARD_FILTER', 'NOTIFICATION', 'NOTIFICATION_SETTINGS', 'NOTIFICATION_PREFERENCES', 'IMAGE', 'PLATFORM_SETTINGS', 'RELATION']);
const PROFILE_TYPES = new Set<string>([EntityType.DEVICE_PROFILE, EntityType.ASSET_PROFILE]);

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

@ -27,10 +27,11 @@ const WELCOMES: Partial<Record<AiAssistantViewType, AiWelcomeKind>> = {
[AiAssistantViewType.DEVICE_GROUP]: {key: 'device-group', entity: true, examples: ['status']},
[AiAssistantViewType.ALARM_RULE_LIST]: {key: 'alarm-rules'},
[AiAssistantViewType.ALARM_RULE]: {key: 'alarm-rule', entity: true, examples: ['explain']},
[AiAssistantViewType.ALARM_LIST]: {key: 'alarms'},
[AiAssistantViewType.ALARM_LIST]: {key: 'alarms', examples: ['attention', 'triage']},
[AiAssistantViewType.ALARM]: {key: 'alarm', entity: true, examples: ['explain', 'acknowledge']},
[AiAssistantViewType.CALCULATED_FIELD_LIST]: {key: 'calculated-fields'},
[AiAssistantViewType.CALCULATED_FIELD]: {key: 'calculated-field', entity: true, examples: ['explain']},
[AiAssistantViewType.ASSET_LIST]: {key: 'assets', examples: ['find']},
[AiAssistantViewType.ASSET_LIST]: {key: 'assets', examples: ['find', 'hierarchy']},
[AiAssistantViewType.ASSET]: {key: 'asset', entity: true, examples: ['telemetry', 'metric', 'dashboard']},
[AiAssistantViewType.ASSET_GROUP_LIST]: {key: 'asset-groups', owned: true, examples: ['find']},
[AiAssistantViewType.ASSET_GROUP]: {key: 'asset-group', entity: true, examples: ['status']},

10
ui-ngx/src/app/modules/home/components/alarm/alarm-table-config.ts

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service';
import {
CellActionDescriptorType,
DateEntityTableColumn,
@ -209,7 +210,7 @@ export class AlarmTableConfig extends EntityTableConfig<AlarmInfo, TimePageLink>
}
showAlarmDetails(entity: AlarmInfo) {
this.dialog.open<AlarmDetailsDialogComponent, AlarmDetailsDialogData, boolean>
const dialog$ = this.dialog.open<AlarmDetailsDialogComponent, AlarmDetailsDialogData, boolean>
(AlarmDetailsDialogComponent,
{
disableClose: true,
@ -222,7 +223,12 @@ export class AlarmTableConfig extends EntityTableConfig<AlarmInfo, TimePageLink>
displayDetails: true,
allowAssign: true
}
}).afterClosed().subscribe(
}).afterClosed();
const closed$ = this.aiAssistantConfig
? this.viewContainerRef.injector.get(AiAssistantPanelService).focusWhile(
{type: AiAssistantViewType.ALARM, entityId: entity.id}, entity.type, dialog$)
: dialog$;
closed$.subscribe(
(res) => {
if (res) {
this.updateData();

1
ui-ngx/src/app/shared/models/ai-chat.models.ts

@ -254,6 +254,7 @@ export enum AiAssistantViewType {
ALARM_RULE = 'ALARM_RULE',
ALARM_RULE_LIST = 'ALARM_RULE_LIST',
ALARM_LIST = 'ALARM_LIST',
ALARM = 'ALARM',
CALCULATED_FIELD = 'CALCULATED_FIELD',
CALCULATED_FIELD_LIST = 'CALCULATED_FIELD_LIST',
DEVICE = 'DEVICE',

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

@ -866,6 +866,20 @@
"read-audit-logs-of": "Read the audit log of {{entity}}",
"read-tasks": "Read the task manager",
"save-image": "Added image {{name}} to the image gallery",
"update-alarms": {
"acknowledge": "{ count, plural, =1 {Acknowledged an alarm} other {Acknowledged # alarms} }",
"clear": "{ count, plural, =1 {Cleared an alarm} other {Cleared # alarms} }",
"assign": "{ count, plural, =1 {Assigned an alarm} other {Assigned # alarms} }",
"unassign": "{ count, plural, =1 {Unassigned an alarm} other {Unassigned # alarms} }",
"comment": "{ count, plural, =1 {Commented on an alarm} other {Commented on # alarms} }"
},
"alarms-done": "Done",
"alarms-skipped": "Already in that state",
"alarms-failed": "Failed",
"save-relations": "Changed relations",
"relations-added": "Added",
"relations-removed": "Removed",
"relations-failed": "Failed",
"read-platform-settings": "Read the platform settings",
"save-platform-settings": "Saved the platform settings",
"usage": {
@ -918,6 +932,7 @@
"kind": {
"calculated-field": "calculated field",
"entity-view": "entity view",
"asset": "asset",
"asset-profile": "asset profile",
"secret": "secret",
"ai-model": "AI model",
@ -960,6 +975,7 @@
"no": "No",
"fact": {
"link": "Link",
"comment": "Comment",
"reference": "Reference",
"tested": "Tested before saving",
"permissions": "Permissions",
@ -1230,6 +1246,34 @@
"run": "Adding the image",
"done": "Added the image"
},
"update-alarms": {
"acknowledge": {"run": "Acknowledging the alarms", "done": "Acknowledged the alarms"},
"clear": {"run": "Clearing the alarms", "done": "Cleared the alarms"},
"assign": {"run": "Assigning the alarms", "done": "Assigned the alarms"},
"unassign": {"run": "Unassigning the alarms", "done": "Unassigned the alarms"},
"comment": {"run": "Commenting on the alarms", "done": "Commented on the alarms"},
"other": {"run": "Updating the alarms", "done": "Updated the alarms"}
},
"delete-alarm": {
"run": "Deleting the alarm",
"done": "Deleted the alarm"
},
"create-asset": {
"run": "Creating the asset",
"done": "Created the asset"
},
"update-asset": {
"run": "Updating the asset",
"done": "Updated the asset"
},
"delete-asset": {
"run": "Deleting the asset",
"done": "Deleted the asset"
},
"save-relations": {
"run": "Changing the relations",
"done": "Changed the relations"
},
"create-entity-view": {
"run": "Creating the entity view",
"done": "Created the entity view"
@ -1546,6 +1590,8 @@
"ask-again-message": "Ask me again for the same change.",
"field": {
"source": "Source",
"assignee": "Assignee",
"comment": "Comment",
"timeseries": "Telemetry",
"attributes": "Attributes",
"window": "Time window",
@ -1619,6 +1665,7 @@
},
"type": {
"IMAGE": "Image",
"RELATION": "Relations",
"PLATFORM_SETTINGS": "Platform settings",
"ENTITY_GROUP": "Group",
"ROLE": "Role",
@ -1862,7 +1909,8 @@
"line": "Their telemetry and alarms, or a dashboard to watch them.",
"suggestion": "Build a dashboard for my assets.",
"example": {
"find": {"label": "Find assets with alarms", "message": "Which of my assets have active alarms?"}
"find": {"label": "Find assets with alarms", "message": "Which of my assets have active alarms?"},
"hierarchy": {"label": "Build a hierarchy", "message": "Create an asset for each of my buildings and put their devices under them."}
}
},
"asset": {
@ -2164,7 +2212,21 @@
"alarms": {
"title": "Ask about your alarms",
"line": "What is active, why it fired, or what to do about it.",
"suggestion": "Which alarms need attention?"
"suggestion": "Which alarms need attention?",
"example": {
"attention": {"label": "What needs attention", "message": "Which alarms need attention right now?"},
"triage": {"label": "Acknowledge the critical ones", "message": "Acknowledge all active critical alarms and tell me what caused them."}
}
},
"alarm": {
"title": "Ask about {{name}}",
"title-unnamed": "Ask about this alarm",
"line": "Why it fired, whether it still matters, and what to do with it.",
"suggestion": "Why was this alarm raised?",
"example": {
"explain": {"label": "Why it fired", "message": "Why was this alarm raised, and is the problem still there?"},
"acknowledge": {"label": "Acknowledge it", "message": "Acknowledge this alarm and comment that I'm looking into it."}
}
},
"calculated-fields": {
"title": "Ask about calculated fields",

Loading…
Cancel
Save