Browse Source

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

pull/16833/head
Igor Kulikov 2 weeks ago
parent
commit
b02ee9ac09
  1. 23
      ui-ngx/src/app/modules/home/components/ai/ai-chat-messages.component.ts
  2. 24
      ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts

23
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) {

24
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<ElementRef<HTMLElement>>('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<ReadonlySet<string>>(new Set());
unlisting = signal<string | null>(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':

Loading…
Cancel
Save