diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx
index ff19b3515..9efee1697 100644
--- a/gui/src/pages/gui/Chat.tsx
+++ b/gui/src/pages/gui/Chat.tsx
@@ -134,6 +134,8 @@ export function Chat() {
return isJetBrains();
}, []);
+ useAutoScroll(stepsDivRef, history);
+
useEffect(() => {
// Cmd + Backspace to delete current step
const listener = (e: any) => {
@@ -284,8 +286,6 @@ export function Chat() {
const showScrollbar = showChatScrollbar ?? window.innerHeight > 5000;
- useAutoScroll(stepsDivRef, history);
-
return (
<>
{widget}
@@ -301,7 +301,7 @@ export function Chat() {
msg.message.role === "user").length;
+}
export const useAutoScroll = (
ref: React.RefObject,
- history: unknown[],
+ history: ChatHistoryItemWithMessageId[],
) => {
const [userHasScrolled, setUserHasScrolled] = useState(false);
+ const numUserMsgs = useMemo(() => getNumUserMsgs(history), [history.length]);
useEffect(() => {
- if (history.length) {
- setUserHasScrolled(false);
- }
- }, [history.length]);
+ setUserHasScrolled(false);
+ }, [numUserMsgs]);
useEffect(() => {
if (!ref.current || history.length === 0) return;
diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts
index 3fe15881c..627829da4 100644
--- a/gui/src/redux/slices/sessionSlice.ts
+++ b/gui/src/redux/slices/sessionSlice.ts
@@ -32,7 +32,7 @@ import { findCurrentToolCall, findToolCall } from "../util";
// We need this to handle reorderings (e.g. a mid-array deletion) of the messages array.
// The proper fix is adding a UUID to all chat messages, but this is the temp workaround.
-type ChatHistoryItemWithMessageId = ChatHistoryItem & {
+export type ChatHistoryItemWithMessageId = ChatHistoryItem & {
message: ChatMessage & { id: string };
};