Fix savings chat autoscroll

This commit is contained in:
Matthias
2026-06-16 11:02:00 +02:00
parent 9f17d4d1e1
commit 15bf5d2036
4 changed files with 62 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import {
buildSourcesFromToolTrace,
buildReasoningSteps,
getToolTraceSummary,
scrollConversationToBottom,
} from "./agentChatModel";
const assistantMessage: AgentChatMessage = {
@@ -31,6 +32,17 @@ const assistantMessage: AgentChatMessage = {
};
describe("AgentChat phase 1 components", () => {
test("scrolls the conversation container directly to the bottom", () => {
const container = {
scrollTop: 0,
scrollHeight: 1200,
};
scrollConversationToBottom(container);
expect(container.scrollTop).toBe(1200);
});
test("summarizes tool traces for compact agent transparency", () => {
expect(getToolTraceSummary(undefined)).toBe("Keine Werkzeuge");
expect(getToolTraceSummary([])).toBe("Keine Werkzeuge");

View File

@@ -54,3 +54,10 @@ export function buildSourcesFromToolTrace(toolTrace: AgentToolTrace[] | undefine
description: tool.resultSummary,
}));
}
export function scrollConversationToBottom(
container: Pick<HTMLDivElement, "scrollHeight" | "scrollTop"> | null,
) {
if (!container) return;
container.scrollTop = container.scrollHeight;
}

View File

@@ -12,6 +12,7 @@ import {
AgentPromptInput,
type AgentChatMessage,
} from "@/components/chat/AgentChat";
import { scrollConversationToBottom } from "@/components/chat/agentChatModel";
import { ChatHistory, type ChatHistoryItem } from "@/components/chat/ChatHistory";
import { toast } from "sonner";
@@ -278,7 +279,7 @@ export function SavingsChatPage() {
};
useEffect(() => {
listRef.current?.lastElementChild?.scrollIntoView({ behavior: "smooth" });
scrollConversationToBottom(listRef.current);
}, [displayMessages.length, activeSessionId]);
useEffect(() => {