diff --git a/gui/src/components/console/Details.tsx b/gui/src/components/console/Details.tsx index a9edfa8a6..2541fd8ba 100644 --- a/gui/src/components/console/Details.tsx +++ b/gui/src/components/console/Details.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef } from "react"; +import { useEffect, useRef, useState } from "react"; import { LLMInteraction } from "../../hooks/useLLMLog"; import useLLMSummary from "../../hooks/useLLMSummary"; import End from "./End"; @@ -50,6 +50,18 @@ export default function Details({ interaction }: DetailsProps) { const scrollTop = useRef(null); const lastResult = useRef(null); const summary = useLLMSummary(interaction); + const [isAtBottom, setIsAtBottom] = useState(true); + + // Handler to check if user is at the bottom + function handleScroll() { + const elt = scrollTop.current; + if (!elt) { + return; + } + // Allow a small threshold for floating point errors + const threshold = 5; + setIsAtBottom((elt.scrollHeight - elt.scrollTop - elt.clientHeight) < threshold); + } useEffect(() => { if (interaction.end) { @@ -59,15 +71,17 @@ export default function Details({ interaction }: DetailsProps) { const last = interaction.results[interaction.results.length - 1]; if (last != lastResult.current) { lastResult.current = last; - const lastChild = scrollTop.current?.lastChild; - if (lastChild) { - (lastChild as HTMLElement).scrollIntoView({ - behavior: "auto", - block: "end", - }); + if (isAtBottom) { + const lastChild = scrollTop.current?.lastChild; + if (lastChild) { + (lastChild as HTMLElement).scrollIntoView({ + behavior: "auto", + block: "end", + }); + } } } - }); + }, [interaction, isAtBottom]); return (
@@ -102,7 +116,11 @@ export default function Details({ interaction }: DetailsProps) { >
-
+
{interaction.start ? : ""}
{interaction.results.map((group, i) => {