diff --git a/ui-ngx/src/app/core/services/ai-chats.service.ts b/ui-ngx/src/app/core/services/ai-chats.service.ts index e57a2ea93a..84dcd63ea4 100644 --- a/ui-ngx/src/app/core/services/ai-chats.service.ts +++ b/ui-ngx/src/app/core/services/ai-chats.service.ts @@ -299,6 +299,16 @@ export class AiChatsService { ); } + addPrompt(chatId: string | undefined, text: string | undefined): void { + const prompt = text?.trim(); + if (!chatId || !prompt) { + return; + } + this._chats.update(list => list.map(chat => chat.id === chatId + ? {...chat, prompt: chat.prompt ?? prompt, prompts: [...(chat.prompts ?? (chat.prompt ? [chat.prompt] : [])), prompt]} + : chat)); + } + setTitle(chatId: string, title: string): void { this._chats.update(list => list.map(chat => chat.id === chatId ? {...chat, title} : chat)); } diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.scss b/ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.scss index 4bf26c3c6b..4ed410f75b 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.scss +++ b/ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.scss @@ -20,6 +20,10 @@ transition: none; } + &.resizing { + contain: layout style; + } + &.restored { transition: none; } diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.ts index 0d224800bb..b3c1d23bed 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.ts @@ -237,7 +237,8 @@ export class AiAssistantPanelComponent { this.resizing.set(true); const grip = event.target as HTMLElement; const host = this.elementRef.nativeElement as HTMLElement; - const root = document.documentElement; + const page = host.parentElement?.querySelector('.tb-site-main.openAiAssistant') ?? null; + const pageFollows = !!page && parseFloat(getComputedStyle(page).marginRight) > 0; const startX = event.clientX; const startWidth = this.width(); this.room.set(host.parentElement?.clientWidth ?? window.innerWidth); @@ -250,7 +251,9 @@ export class AiAssistantPanelComponent { const reflowPage = () => { pageTimer = undefined; pageAt = performance.now(); - root.style.setProperty('--tb-ai-panel-w', current + 'px'); + if (pageFollows) { + page.style.marginRight = current + 'px'; + } }; const paint = () => { frame = 0; @@ -261,6 +264,7 @@ export class AiAssistantPanelComponent { }; grip.setPointerCapture(event.pointerId); document.body.classList.add('tb-ai-resizing'); + host.classList.add('resizing'); this.zone.runOutsideAngular(() => { const move = (e: PointerEvent) => { const wanted = startWidth + (startX - e.clientX); @@ -281,8 +285,11 @@ export class AiAssistantPanelComponent { cancelAnimationFrame(frame); clearTimeout(pageTimer); document.body.classList.remove('tb-ai-resizing'); - host.classList.remove('closing'); + host.classList.remove('closing', 'resizing'); host.style.width = ''; + if (page) { + page.style.marginRight = ''; + } this.zone.run(() => { this.resizing.set(false); if (closing) { 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 7e914f5760..7e6158b149 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 @@ -1034,6 +1034,7 @@ export class AiChatComponent implements OnInit, OnDestroy { private sendWhileWorking(prompt: AiPromptMessage, userMessage: ChatMessage): void { const chatId = this.chatId(); let ownTurn = false; + this.chats.addPrompt(chatId, prompt.message); this.aiChat.sendChatMessage(chatId, this.chatRequest(prompt), {ignoreLoading: true, ignoreErrors: true}).pipe( takeUntil(this.cancelMessage$), concatMap(event => { @@ -1135,6 +1136,9 @@ export class AiChatComponent implements OnInit, OnDestroy { return startOrContinue$.pipe( tap(() => { this.chats.clearFailure(this.chatId()); + if (!again) { + this.chats.addPrompt(this.chatId(), prompt.message); + } this.startLoading(); }), switchMap(() => this.aiChat.sendChatMessage(this.chatId(), request, {ignoreLoading: true, ignoreErrors: true})), diff --git a/ui-ngx/src/app/modules/home/pages/ai-assistant/ai-assistant.component.ts b/ui-ngx/src/app/modules/home/pages/ai-assistant/ai-assistant.component.ts index 3c911e9422..f9f7c1bbb5 100644 --- a/ui-ngx/src/app/modules/home/pages/ai-assistant/ai-assistant.component.ts +++ b/ui-ngx/src/app/modules/home/pages/ai-assistant/ai-assistant.component.ts @@ -44,6 +44,7 @@ export interface AiRailRow { pinned: boolean; pinnedTime?: number; prompt?: string; + prompts?: string[]; chat?: ChatInfo; solution?: SolutionInfo; } @@ -104,7 +105,7 @@ export class AiAssistantComponent implements OnInit, OnDestroy { rows = computed(() => [ ...this.aiChats.chats().map(chat => ({ - id: chat.id, title: chat.title, createdTime: chat.createdTime, pinned: !!chat.pinned, pinnedTime: chat.pinnedTime, prompt: chat.prompt, chat + id: chat.id, title: chat.title, createdTime: chat.createdTime, pinned: !!chat.pinned, pinnedTime: chat.pinnedTime, prompt: chat.prompt, prompts: chat.prompts, chat })), ...this.aiSolutions.solutions().map(solution => ({ id: solution.id, title: this.aiSolutions.titleOf(solution), createdTime: solution.createdTime ?? 0, pinned: !!solution.pinned, solution @@ -115,7 +116,7 @@ export class AiAssistantComponent implements OnInit, OnDestroy { const query = this.query().trim().toLowerCase(); const chats = this.rows(); if (query) { - const found = chats.filter(chat => (chat.title ?? '').toLowerCase().includes(query) || (chat.prompt ?? '').toLowerCase().includes(query)); + const found = chats.filter(chat => (chat.title ?? '').toLowerCase().includes(query) || !!this.promptWith(chat, query)); return found.length ? [{label: this.translate.instant('ai-assistant.chats-found', {count: found.length}), chats: found}] : []; @@ -365,8 +366,8 @@ export class AiAssistantComponent implements OnInit, OnDestroy { snippetOf(row: AiRailRow): {text: string; hit: boolean}[] | null { const query = this.query().trim().toLowerCase(); - const prompt = row.prompt ?? ''; - const at = query ? prompt.toLowerCase().indexOf(query) : -1; + const prompt = query ? this.promptWith(row, query) ?? '' : ''; + const at = prompt.toLowerCase().indexOf(query); if (!query || (row.title ?? '').toLowerCase().includes(query) || at < 0) { return null; } @@ -382,6 +383,11 @@ export class AiAssistantComponent implements OnInit, OnDestroy { ].filter(part => part.text); } + private promptWith(row: AiRailRow, query: string): string | undefined { + const prompts = row.prompts?.length ? row.prompts : row.prompt ? [row.prompt] : []; + return prompts.find(prompt => prompt.toLowerCase().includes(query)); + } + runAgain(chat: ChatInfo): void { const start = (prompt: string | undefined) => { if (!prompt?.trim()) { 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 fadad8fb56..4e52595d58 100644 --- a/ui-ngx/src/app/shared/models/ai-chat.models.ts +++ b/ui-ngx/src/app/shared/models/ai-chat.models.ts @@ -40,6 +40,7 @@ export interface ChatInfo extends ChatConfiguration { pinned?: boolean; pinnedTime?: number; prompt?: string; + prompts?: string[]; status?: ChatStatus; statusReason?: string; updatedTime?: number;