From b02ee9ac09945fb3d0ff52c141c5a1d714604a76 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Tue, 17 Nov 2026 19:14:06 +0200 Subject: [PATCH] fix: AI chat scrolling: an approval card that needs a review scrolls fully into view, the status line shows the working tool again after a streamed reply instead of 'Thinking', and the jump-to-latest button hides when expanding or collapsing details brings the last message into view --- .../ai/ai-chat-messages.component.ts | 23 ++++++++++++++++-- .../home/components/ai/ai-chat.component.ts | 24 +++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) 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 f790429c94..b935a5807c 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 @@ -461,6 +461,8 @@ export class AiChatMessagesComponent implements OnChanges, OnDestroy { if (wasNearBottom) { setTimeout(() => this.scrollToBottom('smooth'), 0); } + } else if (lastMsg?.from === 'APPROVAL' && this.waitApproval) { + setTimeout(() => this.revealLastApproval(), 0); } else if (lastMsg?.from === 'APPROVAL') { if (prevLastMsg?.from === 'USER') { setTimeout(() => this.scrollToLastUserMessage(), 0); @@ -869,9 +871,10 @@ export class AiChatMessagesComponent implements OnChanges, OnDestroy { this.releaseAsk?.(); } - private pinToBottom(): void { + private pinToBottom(place?: () => void): void { + this.releaseBottom?.(); const scroller = this.scroller; - const stick = () => scroller.scrollTop = scroller.scrollHeight; + const stick = place ?? (() => scroller.scrollTop = scroller.scrollHeight); const observer = new ResizeObserver(stick); observer.observe(this.elementRef.nativeElement); const release = () => { @@ -897,6 +900,22 @@ export class AiChatMessagesComponent implements OnChanges, OnDestroy { el.scrollTo({top: el.scrollHeight, behavior: this.motion(behavior)}); } + private revealLastApproval(): void { + const cards = this.elementRef.nativeElement.querySelectorAll('tb-ai-approval-card'); + const card = cards[cards.length - 1] as HTMLElement | undefined; + if (!card) { + return; + } + const scroller = this.scroller; + this.pinToBottom(() => { + scroller.scrollTop = scroller.scrollHeight; + const top = card.getBoundingClientRect().top - scroller.getBoundingClientRect().top; + if (top < 0) { + scroller.scrollTop += top - 8; + } + }); + } + scrollToLastUserMessage(): void { const userMessages = this.elementRef.nativeElement.querySelectorAll('.user'); if (userMessages.length) { 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 fe2618f3b9..8f86fa70f5 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 @@ -67,7 +67,7 @@ import { AiPlanRun } from '@home/components/ai/ai-plan.component'; import { AiFile, aiFileMark, aiFileName, aiFileOf, downloadAiFile, downloadAiFileAsPng, WRITE_FILE_TOOL } from '@home/components/ai/ai-file.models'; import { AiFileBodyComponent, AiFileMarks, AiFileSaver } from '@home/components/ai/ai-file-body.component'; import { ClipboardService } from 'ngx-clipboard'; -import { AnswerRatingEvent, AnswerReportEvent } from '@home/components/ai/ai-chat-messages.component'; +import { AiChatMessagesComponent, AnswerRatingEvent, AnswerReportEvent } from '@home/components/ai/ai-chat-messages.component'; import { EntityId } from '@shared/models/id/entity-id'; import { EntityType } from '@shared/models/entity-type.models'; import { AiAssistantViewType } from '@shared/models/ai-chat.models'; @@ -186,6 +186,24 @@ export class AiChatComponent implements OnInit, OnDestroy { fileBody = viewChild(AiFileBodyComponent); + private chatArea = viewChild>('chatArea'); + + private chatLog = viewChild(AiChatMessagesComponent, {read: ElementRef}); + + private logSizeEffect = effect(onCleanup => { + const area = this.chatArea()?.nativeElement; + const log = this.chatLog()?.nativeElement; + if (!area) { + return; + } + const observer = new ResizeObserver(() => this.onLogScroll(area)); + observer.observe(area); + if (log) { + observer.observe(log); + } + onCleanup(() => observer.disconnect()); + }); + unlisted = signal>(new Set()); unlisting = signal(null); @@ -961,7 +979,9 @@ export class AiChatComponent implements OnInit, OnDestroy { break; case 'thinking': { const headline = this.thinkingHeadline(event.data); - this.work.update(work => work && headline ? {...work, headline} : work); + if (headline) { + this.work.update(work => ({...(work ?? {moment: 'going-through-results' as AiWorkMoment, since: Date.now()}), headline})); + } break; } case 'assistantMessage':