From 57d16400cf394a3deda7384121dc3600ce7bc457 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Fri, 13 Nov 2026 19:55:12 +0200 Subject: [PATCH] feat: AI chat color questions show swatches and open the color picker for another color, image actions preview the saved images, the website brand read shows its colors and logo candidates, and a white labeling change from the chat always reloads the white labeling page, also after an auto-approved reset --- .../ai/ai-action-detail.component.html | 12 ++++ .../components/ai/ai-action-detail.models.ts | 52 ++++++++++++++-- .../home/components/ai/ai-action.models.ts | 1 + .../home/components/ai/ai-chat.component.ts | 15 +++-- .../components/ai/ai-question.component.html | 38 +++++++++--- .../components/ai/ai-question.component.ts | 62 ++++++++++++++++++- .../pages/admin/white-labeling.component.ts | 2 +- .../shared/models/solution-creator.models.ts | 1 + .../assets/locale/locale.constant-en_US.json | 16 +++++ ui-ngx/src/theme/ai-theme.scss | 50 +++++++++++++++ 10 files changed, 229 insertions(+), 20 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.component.html b/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.component.html index cf6146bb64..6ccc83afcf 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.component.html +++ b/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.component.html @@ -130,6 +130,18 @@ } + @case ('images') { +
+ @for (image of block.rows; track image.url) { +
+ + @if (image.label) { +
{{ say(image.label) }}
+ } +
+ } +
+ } @case ('note') {

{{ say(block.text) }}

} 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 f41f4e6b06..01bfb9783d 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 @@ -83,7 +83,13 @@ export type AiDetailBlock = | {type: 'code'; label: string; text: string} | {type: 'note'; text: AiDetailText} | {type: 'text'; text: string} - | {type: 'json'; label: string; text: string}; + | {type: 'json'; label: string; text: string} + | {type: 'images'; rows: AiDetailImage[]}; + +export interface AiDetailImage { + label?: AiDetailText; + url: string; +} export interface AiDetailView { hood?: AiDetailText; @@ -209,6 +215,16 @@ function entity(id: unknown, entityType: unknown, names: AiDetailNames): AiDetai return {id: key, entityType: type ?? known?.entityType, name: known?.name}; } +function galleryImage(value: unknown): string | undefined { + const url = str(value); + return url && /^(tb-image;)?\/api\/images\//.test(url) ? url : undefined; +} + +function images(rows: {label?: AiDetailText; value: unknown}[]): AiDetailBlock[] { + const found: AiDetailImage[] = rows.map(row => ({label: row.label, url: galleryImage(row.value)})).filter(row => !!row.url); + return found.length ? [{type: 'images', rows: found}] : []; +} + function text(key: string, params?: Record): AiDetailText { return {key: K + key, params}; } @@ -1124,7 +1140,8 @@ function describe(tool: string, values: Values, result: unknown, names: AiDetail if (saved.tested === true) { rows.push({label: K + 'fact.tested', value: K + 'yes'}); } - return {hood: text('save', {what: K + 'kind.' + kind, name}), blocks: rows.length ? [{type: 'facts', rows}] : generic(result, 'result')}; + const pictures = images([{value: values.image}]); + return {hood: text('save', {what: K + 'kind.' + kind, name}), blocks: rows.length ? [{type: 'facts', rows}, ...pictures] : [...generic(result, 'result'), ...pictures]}; } case 'save_relations': { if (!isObject(result)) { @@ -1171,12 +1188,38 @@ function describe(tool: string, values: Values, result: unknown, names: AiDetail } case 'read_white_labeling': return {hood: text('read-white-labeling'), blocks: json('settings', result)}; + case 'read_website_brand': { + const site = str(isObject(result) ? result.url : undefined) ?? str(values.url) ?? '—'; + if (!isObject(result)) { + return {hood: text('read-website-brand', {site}), blocks: generic(result, 'result')}; + } + const blocks: AiDetailBlock[] = []; + if (str(result.pageNotRead)) { + blocks.push({type: 'note', text: text('website-not-read')}); + } + const colors = [str(result.themeColor) ? `${result.themeColor} · theme-color` : undefined, + ...(Array.isArray(result.iconColors) ? result.iconColors.filter(isObject).map(color => `${color.color} · icon ${color.percent}%`) : []), + ...Object.entries(isObject(result.colorVariables) ? result.colorVariables : {}).map(([name, color]) => `${color} · ${name}`), + ...(Array.isArray(result.colors) ? result.colors.filter(isObject).map(color => `${color.color} · ×${color.uses}`) : [])] + .filter(Boolean).slice(0, MAX_ROWS); + if (colors.length) { + blocks.push({type: 'list', label: text('website-colors'), rows: colors}); + } + const logos = (Array.isArray(result.logos) ? result.logos.filter(isObject) : []) + .map(logo => str(logo.url) ?? ` · ${logo.source}`).slice(0, MAX_ROWS); + if (logos.length) { + blocks.push({type: 'list', label: text('website-logos'), rows: logos}); + } + return {hood: text('read-website-brand', {site}), blocks}; + } case 'save_white_labeling': { const {target, reset, ...changes} = values; if (reset) { return {hood: text(target === 'LOGIN' ? 'reset-white-labeling-login' : 'reset-white-labeling'), blocks: []}; } - return {hood: text(target === 'LOGIN' ? 'save-white-labeling-login' : 'save-white-labeling'), blocks: [{type: 'facts', rows: facts(changes)}]}; + return {hood: text(target === 'LOGIN' ? 'save-white-labeling-login' : 'save-white-labeling'), blocks: [{type: 'facts', rows: facts(changes)}, + ...images([{label: text('image-logo'), value: values.logoImage}, {label: text('image-collapsed-logo'), value: values.collapsedLogoImage}, + {label: text('image-favicon'), value: values.favicon}])]}; } case 'read_ota': { if (!isObject(result)) { @@ -1278,7 +1321,8 @@ function describe(tool: string, values: Values, result: unknown, names: AiDetail case 'save_image': { const saved = isObject(result) ? result : {}; const rows: AiDetailFact[] = str(saved.link) ? [{label: K + 'fact.link', value: saved.link, mono: true}] : []; - return {hood: text('save-image', {name: str(saved.title) ?? str(values.title) ?? '—'}), blocks: rows.length ? [{type: 'facts', rows}] : generic(result, 'result')}; + return {hood: text('save-image', {name: str(saved.title) ?? str(values.title) ?? '—'}), + blocks: rows.length ? [{type: 'facts', rows}, ...images([{value: saved.link}])] : generic(result, 'result')}; } case 'reprocess_calculated_field': return {hood: text('reprocess', {entity: of(values.calculatedFieldId, 'CALCULATED_FIELD'), from: dateText(values.startTime ?? values.startTs), to: endText(values.endTime ?? values.endTs)}), blocks: generic(result, 'result')}; diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts b/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts index c76df9d3af..724bee92b0 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts @@ -68,6 +68,7 @@ const TOOL_WORDS: Record = { read_gateway_status: 'read-gateway-status', read_ota: 'read-ota', read_white_labeling: 'read-white-labeling', + read_website_brand: 'read-website-brand', save_white_labeling: 'save-white-labeling', save_ota_package: 'save-ota-package', assign_ota_package: 'assign-ota-package', 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 60ebe9f50a..ff73273a81 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 @@ -376,6 +376,7 @@ export class AiChatComponent implements OnInit, OnDestroy { private shownChatId: string | undefined; private replyingChatId: string | undefined; private affectedEntities: EntityId[] = []; + private appliedEffects = new Set(); private logScrollBottom: number | undefined; private newTurnsEffect = effect(() => { @@ -951,8 +952,11 @@ export class AiChatComponent implements OnInit, OnDestroy { case 'toolExecutionResult': this.completedExecutions.update(map => ({...map, [event.data.executionId]: event.data})); if (event.data.executionStatus === 'SUCCESS') { - const approval = this.messages().find(message => message.from === 'APPROVAL' && message.data.executionId === event.data.executionId); - this.applySideEffects(approval?.from === 'APPROVAL' ? approval.data.tool : undefined, approval?.from === 'APPROVAL' ? approval.data.arguments : undefined); + const call = this.messages().find(message => (message.from === 'APPROVAL' || message.from === 'ACTION') + && message.data.executionId === event.data.executionId); + if (call?.from === 'APPROVAL' || call?.from === 'ACTION') { + this.applySideEffects(event.data.executionId, call.data.tool, call.data.arguments); + } } if (event.data.affectedEntities?.length) { this.affectedEntities.push(...event.data.affectedEntities); @@ -1042,10 +1046,11 @@ export class AiChatComponent implements OnInit, OnDestroy { } } - private applySideEffects(tool: string | undefined, args: unknown): void { - if (tool !== 'save_white_labeling') { + private applySideEffects(executionId: string, tool: string | undefined, args: unknown): void { + if (tool !== 'save_white_labeling' || this.appliedEffects.has(executionId)) { return; } + this.appliedEffects.add(executionId); const target = (aiParse(args) as {target?: string})?.target === 'LOGIN' ? 'LOGIN' : 'GENERAL'; if (target === 'GENERAL') { this.whiteLabelingService.loadUserWhiteLabelingParams().subscribe(); @@ -1057,7 +1062,7 @@ export class AiChatComponent implements OnInit, OnDestroy { if (finished.status === 'SUCCESS') { const started = this.messages().find(message => message.from === 'ACTION' && message.data.executionId === finished.executionId); if (started?.from === 'ACTION') { - this.applySideEffects(started.data.tool, started.data.arguments); + this.applySideEffects(finished.executionId, started.data.tool, started.data.arguments); } } if (finished.affectedEntities?.length) { diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-question.component.html b/ui-ngx/src/app/modules/home/components/ai/ai-question.component.html index 408c696d4f..05858aa02a 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-question.component.html +++ b/ui-ngx/src/app/modules/home/components/ai/ai-question.component.html @@ -15,7 +15,7 @@ @for (item of answers; track item.question.id) {
{{ item.question.question }} - +
} @@ -76,7 +76,18 @@ }
- @if (isFree(step)) { + @if (isFree(step) && isColor(step)) { +
+ +
+ } @else if (isFree(step)) {
@@ -100,7 +111,7 @@ } - @if (isOther(step)) { + @if (isOther(step) && !isColor(step)) {