import type { ReactNode } from "react"; import React, { useEffect, useRef, useState } from "react"; import { FaBrain, FaListAlt, FaPlayCircle, FaStar } from "react-icons/fa"; import autoAnimate from "@formkit/auto-animate"; import PopIn from "./motions/popin"; import Expand from "./motions/expand"; interface ChatWindowProps { children?: ReactNode; className?: string; messages: Message[]; } const ChatWindow = ({ messages, children, className }: ChatWindowProps) => { const [hasUserScrolled, setHasUserScrolled] = useState(false); 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 if (scrollTop < scrollHeight - clientHeight - 10) { setHasUserScrolled(true); } else { setHasUserScrolled(false); } }; useEffect(() => { // Scroll to bottom on re-renders if (scrollRef && scrollRef.current) { if (!hasUserScrolled) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } } }); useEffect(() => { scrollRef.current && autoAnimate(scrollRef.current); }, [messages]); return (
{messages.map((message, index) => ( ))} {children} {messages.length === 0 ? ( Create an agent by adding a name / goal, and hitting deploy!", }} /> ) : ( "" )}
); }; const MacWindowHeader = () => { return (
); }; const ChatMessage = ({ message }: { message: Message }) => { return (
{getMessageIcon(message)}
{getMessagePrefix(message)} {message.type == "thinking" && ( (Restart if this takes more than 30 seconds) )} {message.value}
); }; const getMessageIcon = (message: Message) => { switch (message.type) { case "goal": return ; case "task": return ; case "thinking": return ; case "action": return ; } }; const getMessagePrefix = (message: Message) => { switch (message.type) { case "goal": return "Embarking on a new goal:"; case "task": return "Added task:"; case "thinking": return "Thinking..."; case "action": return message.info ? message.info : "Executing:"; } }; export interface Message { type: "goal" | "thinking" | "task" | "action" | "system"; info?: string; value: string; } export default ChatWindow; export { ChatMessage };