import React, { ForwardedRef, useEffect, useRef } from 'react'; type Message = { role: string content: string } interface ConversationProps { messages: Message[]; onResendClick: () => void; onEditClick: () => void; onCopyClick: () => void; } const ConversationFrontend = React.forwardRef( ({ messages, onResendClick, onEditClick, onCopyClick }, ref: ForwardedRef) => { const endOfMessagesRef = useRef(null); // Auto-scroll to the bottom of the conversation whenever a new message is added useEffect(() => { if (endOfMessagesRef.current) { endOfMessagesRef.current.scrollIntoView({ behavior: 'smooth' }); } }, [messages]); // Triggers the effect whenever the 'messages' array changes return (
{messages.map((message, index) => { let isUserMessage if (message.role == "user") { isUserMessage = message } return (

{message.content}

); })} {/* Dummy div to mark the end of the conversation for auto-scrolling */}
); } ); export default ConversationFrontend;