"use client"; import { cn } from "@/lib/utils"; import { AnimatePresence, motion } from "framer-motion"; import { FC, Ref, forwardRef, useEffect, useRef } from "react"; import ReactMarkdown from "react-markdown"; interface ChatMessagesProps { history: Array<[string, string]>; } const ChatMessages: FC = ({ history }) => { const lastChatRef = useRef(null); useEffect(() => { lastChatRef.current?.scrollIntoView({ behavior: "auto", block: "start" }); }, [history]); return (
{history.length === 0 ? (
Start a conversation with your brain
) : ( {history.map(([speaker, text], idx) => { if (idx % 2 === 0) return ( ); else { return ( ); } })} )}
); }; const ChatMessage = forwardRef( ( { speaker, text, left = false, }: { speaker: string; text: string; left?: boolean; }, ref ) => { return ( } initial={{ y: -24, opacity: 0 }} animate={{ y: 0, opacity: 1, transition: { duration: 0.2, ease: "easeOut" }, }} exit={{ y: -24, opacity: 0 }} className={cn( "py-3 px-3 rounded-lg border border-black/10 dark:border-white/25 flex flex-col max-w-4xl overflow-hidden scroll-pt-32", left ? "self-start mr-20" : "self-end ml-20" )} > {speaker} <> {text} ); } ); ChatMessage.displayName = 'ChatMessage'; export default ChatMessages;