"use client" import { useEffect, useRef } from "react" import { ScrollArea } from "@/components/ui/scroll-area" import { Avatar, AvatarFallback } from "@/components/ui/avatar" import { Card } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Copy, User, Bot } from "lucide-react" import type { Message } from "@/types/chat" import { useToast } from "@/hooks/use-toast" interface ChatMessagesProps { messages: Message[] isLoading: boolean } export function ChatMessages({ messages, isLoading }: ChatMessagesProps) { const scrollRef = useRef(null) const { toast } = useToast() useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight } }, [messages]) const copyToClipboard = (text: string) => { navigator.clipboard.writeText(text) toast({ title: "Copied to clipboard", duration: 2000, }) } return (
{messages.map((message) => (
{message.role === "assistant" && ( )}
{message.content}
{message.provider &&
via {message.provider}
}
{message.role === "user" && ( )}
))} {isLoading && (
)}
) }