Browse Source

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

pull/16833/head
Igor Kulikov 3 weeks ago
parent
commit
98740eadf7
  1. 11
      ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts
  2. 6
      ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.ts
  3. 2
      ui-ngx/src/app/modules/home/components/ai/ai-chat.component.html
  4. 7
      ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts
  5. 15
      ui-ngx/src/app/modules/home/components/ai/ai-question.component.ts
  6. 2
      ui-ngx/src/app/shared/models/ai-chat.models.ts
  7. 1
      ui-ngx/src/app/shared/models/solution-creator.models.ts

11
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}] : [];
}

6
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<string>();
@Output() compose = new EventEmitter<string>();
@Output() answer = new EventEmitter<string>();
@Output() answer = new EventEmitter<{message: string; secrets?: Record<string, string>}>();
@Output() resourceError = new EventEmitter<any>();
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 {

2
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)">
</tb-ai-chat-messages>
} @else if (historyLoading()) {

7
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<string, string>): 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;
}

15
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<string, string>} {
const secrets: Record<string, string> = {};
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 {

2
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<string, string>;
}
export interface AiResourceFacts {
@ -345,6 +346,7 @@ export interface AiPromptMessage {
message: string;
resources: AiResourceInfo[];
quote?: AiLinesQuote;
secrets?: Record<string, string>;
}
const QUOTE_PATTERN = /^About lines? (\d+)(?:–(\d+))? of (.+?):\n```([\w+-]*)\n([\s\S]*?)\n```\n*/;

1
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 {

Loading…
Cancel
Save