"use client"; import { Button } from "@/components/ui/button"; import type { Message } from "@/lib/types"; import { cn } from "@/lib/utils"; import { Bot, FileText, Star, User, Copy, Check } from "lucide-react"; import { useState } from "react"; import ReactMarkdown from "react-markdown"; import { useToast } from "@/hooks/use-toast"; type Props = { message: Message; handleTranscriptClick: (transcript: Message["transcripts"][0]) => void; onEvaluate: () => void; }; const MessageBlock = ({ message, handleTranscriptClick, onEvaluate, }: Props) => { const Icon = message.role === "user" ? User : Bot; const role = message.role === "user" ? "You" : "AI Assistant"; const [copied, setCopied] = useState(false); const { toast } = useToast(); const handleCopy = async () => { await navigator.clipboard.writeText(message.content); setCopied(true); setTimeout(() => setCopied(false), 2000); toast({ title: "Copied to clipboard", description: "The response has been copied successfully.", }); }; return (
{role} {message.timestamp.toLocaleTimeString()}
( {children} ), }} > {message.content}
{message.transcripts.length > 0 && (
{message.transcripts.map((transcript) => ( ))}
)} {message.role === "assistant" && (
{/* */}
)}
); }; export default MessageBlock;