import clsx from "clsx"; import { useTranslation } from "next-i18next"; import type { ReactNode } from "react"; import React, { useEffect, useRef, useState } from "react"; import { FaArrowCircleDown, FaCommentDots } from "react-icons/fa"; import { ImSpinner2 } from "react-icons/im"; import type { HeaderProps } from "./MacWindowHeader"; import { MacWindowHeader, messageListId } from "./MacWindowHeader"; import { useAgentStore } from "../../stores"; import Button from "../Button"; import Input from "../Input"; import HideShow from "../motions/HideShow"; interface ChatControls { value: string; onChange: (string) => void; handleChat: () => Promise; loading?: boolean; } interface ChatWindowProps extends HeaderProps { children?: ReactNode; setAgentRun?: (name: string, goal: string) => void; visibleOnMobile?: boolean; chatControls?: ChatControls; } const ChatWindow = ({ messages, children, title, chatControls }: ChatWindowProps) => { const [t] = useTranslation(); const [hasUserScrolled, setHasUserScrolled] = useState(false); const isThinking = useAgentStore.use.isAgentThinking(); const isStopped = useAgentStore.use.lifecycle() === "stopped"; const scrollRef = useRef(null); const handleScroll = (event: React.UIEvent) => { const { scrollTop, scrollHeight, clientHeight } = event.currentTarget; // Use has scrolled if we have scrolled up at all from the bottom const hasUserScrolled = scrollTop < scrollHeight - clientHeight - 10; setHasUserScrolled(hasUserScrolled); }; const handleScrollToBottom = (behaviour: "instant" | "smooth") => { if (!scrollRef || !scrollRef.current) return; scrollRef.current.scrollTo({ top: scrollRef.current.scrollHeight, behavior: behaviour, }); }; useEffect(() => { if (!hasUserScrolled) { handleScrollToBottom("instant"); } }); return (
handleScrollToBottom("smooth")} className="h-6 w-6 animate-bounce md:h-7 md:w-7" />
{children}

🧠 Thinking

{chatControls && (
chatControls?.onChange(e.target.value)} />
)}
); }; export default ChatWindow;