diff --git a/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts b/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts index 6c24d2a87a..4a5e28bb20 100644 --- a/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts +++ b/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts @@ -355,6 +355,13 @@ export class AiAssistantPanelService implements OnDestroy { this._updatedData$.complete(); } + private _whiteLabelingSaved$ = new Subject<'GENERAL' | 'LOGIN'>(); + readonly whiteLabelingSaved$ = this._whiteLabelingSaved$.asObservable(); + + emitWhiteLabelingSaved(target: 'GENERAL' | 'LOGIN'): void { + this._whiteLabelingSaved$.next(target); + } + emitUpdatedData(affectedEntities: Array): void { this._updatedData$.next(affectedEntities); } 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 950b99544d..60ebe9f50a 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 @@ -30,6 +30,8 @@ import { AppState } from '@core/core.state'; import { AiChatService } from '@core/http/ai-chat.service'; import { AiChatsService } from '@core/services/ai-chats.service'; import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; +import { aiParse } from '@home/components/ai/ai-action-detail.models'; +import { WhiteLabelingService } from '@core/http/white-labeling.service'; import { ActionNotificationShow } from '@core/notification/notification.actions'; import { isNotEmptyStr, parseHttpErrorMessage } from '@core/utils'; import { ActionChatMessage, AiStartedFrom, ApprovalChatMessage, ChatMessage, GeneralChatMessage } from '@shared/models/solution-creator.models'; @@ -357,6 +359,7 @@ export class AiChatComponent implements OnInit, OnDestroy { private aiChat = inject(AiChatService); private chats = inject(AiChatsService); private panelService = inject(AiAssistantPanelService); + private whiteLabelingService = inject(WhiteLabelingService); private translate = inject(TranslateService); private clipboard = inject(ClipboardService); private store = inject(Store); @@ -947,6 +950,10 @@ export class AiChatComponent implements OnInit, OnDestroy { break; 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); + } if (event.data.affectedEntities?.length) { this.affectedEntities.push(...event.data.affectedEntities); this.emitDashboards(event.data.affectedEntities); @@ -1035,7 +1042,24 @@ export class AiChatComponent implements OnInit, OnDestroy { } } + private applySideEffects(tool: string | undefined, args: unknown): void { + if (tool !== 'save_white_labeling') { + return; + } + const target = (aiParse(args) as {target?: string})?.target === 'LOGIN' ? 'LOGIN' : 'GENERAL'; + if (target === 'GENERAL') { + this.whiteLabelingService.loadUserWhiteLabelingParams().subscribe(); + } + this.panelService.emitWhiteLabelingSaved(target); + } + private finishAction(finished: ToolFinished): void { + 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); + } + } if (finished.affectedEntities?.length) { this.affectedEntities.push(...finished.affectedEntities); this.emitDashboards(finished.affectedEntities); diff --git a/ui-ngx/src/app/modules/home/pages/admin/white-labeling.component.ts b/ui-ngx/src/app/modules/home/pages/admin/white-labeling.component.ts index 3e9eebd740..c2c6c50570 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/white-labeling.component.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/white-labeling.component.ts @@ -1,6 +1,6 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 -import { Component, DestroyRef, Inject, OnInit } from '@angular/core'; +import { Component, DestroyRef, Inject, inject, OnInit } from '@angular/core'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { PageComponent } from '@shared/components/page.component'; @@ -23,10 +23,11 @@ import { isDefined, isEqual, isUndefinedOrNull } from '@core/utils'; import { MatDialog } from '@angular/material/dialog'; import { CustomCssDialogComponent, CustomCssDialogData } from '@home/pages/admin/custom-css-dialog.component'; import { UiSettingsService } from '@core/http/ui-settings.service'; -import { share } from 'rxjs/operators'; +import { filter, share } from 'rxjs/operators'; import { WINDOW } from '@core/services/window.service'; import { EntityType } from '@shared/models/entity-type.models'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; import { EntityId } from '@shared/models/id/entity-id'; import { BaseData } from '@shared/models/base-data'; import { DomainDialogComponent } from '@home/pages/admin/oauth2/domains/domain-dialog.component'; @@ -54,6 +55,8 @@ export class WhiteLabelingComponent extends PageComponent implements OnInit, Has readonly = !this.userPermissionsService.hasGenericPermission(Resource.WHITE_LABELING, Operation.WRITE); isLoginWl: boolean = this.route.snapshot.data.isLoginWl; + private aiAssistantPanelService = inject(AiAssistantPanelService); + uiHelpBaseUrlPlaceholder$ = this.uiSettingsService.getHelpBaseUrl().pipe( share() ); @@ -116,6 +119,10 @@ export class WhiteLabelingComponent extends PageComponent implements OnInit, Has ngOnInit() { this.buildWhiteLabelingSettingsForm(); this.loadWhiteLabelingParams(); + this.aiAssistantPanelService.whiteLabelingSaved$.pipe( + filter(target => (target === 'LOGIN') === !!this.isLoginWl && !this.wlSettings.dirty), + takeUntilDestroyed(this.destroyRef) + ).subscribe(() => this.loadWhiteLabelingParams()); } onLogoHeightKeydown(event: KeyboardEvent): void {