From 98740eadf760258bde7fdec4a1215fbd3fa32fd6 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Fri, 13 Nov 2026 13:19:38 +0200 Subject: [PATCH] feat: secret question answers are sent apart from the message, which carries only a placeholder; notification detail labels are translated; alarm search rows without a type fall back to the raw result --- .../home/components/ai/ai-action-detail.models.ts | 11 ++++++----- .../components/ai/ai-chat-messages.component.ts | 6 +++--- .../home/components/ai/ai-chat.component.html | 2 +- .../home/components/ai/ai-chat.component.ts | 7 +++++-- .../home/components/ai/ai-question.component.ts | 15 ++++++++++++++- ui-ngx/src/app/shared/models/ai-chat.models.ts | 2 ++ .../app/shared/models/solution-creator.models.ts | 1 + 7 files changed, 32 insertions(+), 12 deletions(-) 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 f85331915f..241c5f12d0 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 @@ -360,7 +360,8 @@ function alarmMeta(row: Values): string { function recordOf(row: Values, entityType: string): AiDetailRecord | null { if (entityType === 'ALARM') { - return {entityType, id: idOf(row.id), name: str(row.type) ?? str(row.name) ?? '—', meta: alarmMeta(row), severity: str(row.severity)}; + const alarmName = str(row.type) ?? str(row.name); + return alarmName ? {entityType, id: idOf(row.id), name: alarmName, meta: alarmMeta(row), severity: str(row.severity)} : null; } const name = str(row.name) ?? str(row.title) ?? str(row.email) ?? str(row.label); if (!name) { @@ -798,13 +799,13 @@ function sentNotification(result: unknown): AiDetailBlock[] { rows.push({label: K + 'fact.status', value: K + 'notification-status.' + String(result.status).toLowerCase()}); } if (str(result.sendsAt)) { - rows.push({label: K + 'fact.sends-at', raw: true, value: new Date(result.sendsAt).toLocaleString()}); + rows.push({label: K + 'fact.sends-at', value: new Date(result.sendsAt).toLocaleString()}); } if (str(result.usersTargetName)) { - rows.push({label: K + 'fact.recipients', raw: true, value: result.usersTargetName}); + rows.push({label: K + 'fact.recipients', value: result.usersTargetName}); } if (isObject(result.sent)) { - rows.push({label: K + 'fact.delivered', raw: true, + rows.push({label: K + 'fact.delivered', value: Object.entries(result.sent).map(([method, count]) => `${aiHumanize(method)} ${count}`).join(', ')}); } if (isObject(result.errors)) { @@ -813,7 +814,7 @@ function sentNotification(result: unknown): AiDetailBlock[] { rows.push({label: aiHumanize(method), raw: true, value: `${recipient}: ${aiValueText(error)}`}))); } if (str(result.error)) { - rows.push({label: K + 'fact.error', raw: true, value: result.error}); + rows.push({label: K + 'fact.error', value: result.error}); } return rows.length ? [{type: 'facts', rows}] : []; } 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 be0a18428f..88b07b7092 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 @@ -44,7 +44,7 @@ import { AiAttachmentPreviewDialogComponent, AiAttachmentPreviewDialogData } from '@home/components/ai/ai-attachment-preview-dialog.component'; -import { aiAnswersOf, aiAnswersText } from '@home/components/ai/ai-question.component'; +import { aiAnswersOf, aiAnswersPrompt } from '@home/components/ai/ai-question.component'; import { EntityId } from '@shared/models/id/entity-id'; export interface AnswerRatingEvent { @@ -112,7 +112,7 @@ export class AiChatMessagesComponent implements OnChanges, OnDestroy { @Output() prompt = new EventEmitter(); @Output() compose = new EventEmitter(); - @Output() answer = new EventEmitter(); + @Output() answer = new EventEmitter<{message: string; secrets?: Record}>(); @Output() resourceError = new EventEmitter(); waitApproval = false; @@ -608,7 +608,7 @@ export class AiChatMessagesComponent implements OnChanges, OnDestroy { } answerQuestions(answers: AiQuestionAnswer[]): void { - this.answer.emit(aiAnswersText(answers)); + this.answer.emit(aiAnswersPrompt(answers)); } get retryPrompt(): string { diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.html b/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.html index 1f87138ade..ffec69170a 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.html +++ b/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.html @@ -86,7 +86,7 @@ (openFile)="showFile($event)" (prompt)="ask($event)" (compose)="composeText($event)" - (answer)="ask($event)" + (answer)="ask($event.message, $event.secrets)" (editMessage)="promptInput?.setValue($event)"> } @else if (historyLoading()) { 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 a79b8d27c8..2b8df2dd37 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 @@ -480,8 +480,8 @@ export class AiChatComponent implements OnInit, OnDestroy { this.promptInput?.setValue(text); } - ask(message: string): void { - this.sendMsgFromUser({message, resources: []}); + ask(message: string, secrets?: Record): void { + this.sendMsgFromUser(secrets ? {message, resources: [], secrets} : {message, resources: []}); } showFile(file: AiFile): void { @@ -837,6 +837,9 @@ export class AiChatComponent implements OnInit, OnDestroy { if (this.clientContext()) { request.clientContext = this.clientContext(); } + if (prompt.secrets) { + request.secrets = prompt.secrets; + } return request; } diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-question.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-question.component.ts index 3afd0b2fac..2fff041fad 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-question.component.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-question.component.ts @@ -10,6 +10,19 @@ export function aiAnswersText(answers: AiQuestionAnswer[]): string { return answers.map(item => item.question.question.trim() + ' ' + item.answer.trim()).join('\n'); } +export function aiAnswersPrompt(answers: AiQuestionAnswer[]): {message: string; secrets?: Record} { + const secrets: Record = {}; + const lines = answers.map((item, index) => { + if (!item.secret || !item.answer) { + return item.question.question.trim() + ' ' + item.answer.trim(); + } + const name = (item.question.id || '').replace(/[^A-Za-z0-9_.-]/g, '_').slice(0, 64) || 'answer_' + (index + 1); + secrets[name] = item.answer; + return item.question.question.trim() + ' {{secret:' + name + '}}'; + }); + return Object.keys(secrets).length ? {message: lines.join('\n'), secrets} : {message: lines.join('\n')}; +} + export function aiAnswersOf(content: string | undefined, questions: AiQuestion[] | undefined): AiQuestionAnswer[] | null { if (!content || !questions?.length) { return null; @@ -183,7 +196,7 @@ export class AiQuestionComponent { } private answers(): AiQuestionAnswer[] { - return this.questions().map(question => ({question, answer: this.answerOf(question)})); + return this.questions().map(question => ({question, answer: this.answerOf(question), secret: !!question.secret && !question.options?.length})); } private answerOf(question: AiQuestion): string { diff --git a/ui-ngx/src/app/shared/models/ai-chat.models.ts b/ui-ngx/src/app/shared/models/ai-chat.models.ts index 640dd7f159..d6fa218242 100644 --- a/ui-ngx/src/app/shared/models/ai-chat.models.ts +++ b/ui-ngx/src/app/shared/models/ai-chat.models.ts @@ -308,6 +308,7 @@ export interface SendChatMessageRequest { message: string; clientContext?: AiChatClientContext; resources?: string[]; + secrets?: Record; } export interface AiResourceFacts { @@ -345,6 +346,7 @@ export interface AiPromptMessage { message: string; resources: AiResourceInfo[]; quote?: AiLinesQuote; + secrets?: Record; } const QUOTE_PATTERN = /^About lines? (\d+)(?:–(\d+))? of (.+?):\n```([\w+-]*)\n([\s\S]*?)\n```\n*/; diff --git a/ui-ngx/src/app/shared/models/solution-creator.models.ts b/ui-ngx/src/app/shared/models/solution-creator.models.ts index 7016ec7389..b0a7f63ad4 100644 --- a/ui-ngx/src/app/shared/models/solution-creator.models.ts +++ b/ui-ngx/src/app/shared/models/solution-creator.models.ts @@ -80,6 +80,7 @@ export interface AiQuestion { export interface AiQuestionAnswer { question: AiQuestion; answer: string; + secret?: boolean; } export interface DashboardsOverview {