| // src/components/agents/AgentConversationView.tsx | |
| import { useRef, useEffect, useState } from "react"; | |
| import { MessageSquare, Bot, User, ChevronDown, ChevronUp, Copy, Check } from "lucide-react"; | |
| import { AgentConversation, AgentDefinition } from "@/types/multi-agent"; | |
| import { motion, AnimatePresence } from "framer-motion"; | |
| import { toast } from "react-toastify"; | |
| interface AgentConversationViewProps { | |
| conversation: AgentConversation; | |
| agents: AgentDefinition[]; | |
| isExpanded?: boolean; | |
| onToggleExpand?: () => void; | |
| } | |
| export function AgentConversationView({ | |
| conversation, | |
| agents, | |
| isExpanded = true, | |
| onToggleExpand | |
| }: AgentConversationViewProps) { | |
| const scrollRef = useRef<HTMLDivElement>(null); | |
| const [copiedId, setCopiedId] = useState<string | null>(null); | |
| useEffect(() => { | |
| if (scrollRef.current && isExpanded) { | |
| scrollRef.current.scrollTo({ top: scrollRef.current.scrollHeight, behavior: "smooth" }); | |
| } | |
| }, [conversation.messages.length, isExpanded]); | |
| const getAgentName = (role: string) => { | |
| const agent = agents.find(a => a.role === role); | |
| return agent?.name ?? role.replace(/_/g, " "); | |
| }; | |
| const getAgentIcon = (role: string) => { | |
| const agent = agents.find(a => a.role === role); | |
| return agent?.icon || (role === "orchestrator" ? "🎯" : "🤖"); | |
| }; | |
| const copyMessage = async (content: string, id: string) => { | |
| await navigator.clipboard.writeText(content); | |
| setCopiedId(id); | |
| toast.success("Copied to clipboard"); | |
| setTimeout(() => setCopiedId(null), 2000); | |
| }; | |
| const formatTime = (timestamp: number) => { | |
| return new Date(timestamp).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" }); | |
| }; | |
| const messageVariants = { | |
| hidden: { opacity: 0, y: 10 }, | |
| visible: { opacity: 1, y: 0 }, | |
| }; | |
| return ( | |
| <div className="bg-white dark:bg-gray-800 rounded-2xl border border-gray-200 dark:border-gray-700 overflow-hidden"> | |
| {/* Header */} | |
| <div | |
| className="flex items-center justify-between px-4 py-3 bg-gray-50 dark:bg-gray-700/50 border-b border-gray-200 dark:border-gray-700 cursor-pointer" | |
| onClick={onToggleExpand} | |
| > | |
| <div className="flex items-center gap-2"> | |
| <MessageSquare className="w-4 h-4 text-primary" /> | |
| <h3 className="text-sm font-semibold">Agent Communication</h3> | |
| <span className="text-xs text-gray-500 bg-gray-200 dark:bg-gray-600 px-1.5 py-0.5 rounded-full"> | |
| {conversation.messages.length} | |
| </span> | |
| </div> | |
| <button className="p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-600 transition"> | |
| {isExpanded ? <ChevronUp className="w-4 h-4" /> : <ChevronDown className="w-4 h-4" />} | |
| </button> | |
| </div> | |
| {/* Messages */} | |
| <AnimatePresence> | |
| {isExpanded && ( | |
| <motion.div | |
| initial={{ height: 0 }} | |
| animate={{ height: "auto" }} | |
| exit={{ height: 0 }} | |
| transition={{ duration: 0.2 }} | |
| > | |
| <div ref={scrollRef} className="space-y-3 p-4 max-h-96 overflow-y-auto"> | |
| {conversation.messages.length === 0 ? ( | |
| <div className="text-center py-8 text-gray-400"> | |
| <MessageSquare className="w-8 h-8 mx-auto mb-2 opacity-30" /> | |
| <p className="text-sm">No messages yet</p> | |
| </div> | |
| ) : ( | |
| conversation.messages.map((msg, i) => ( | |
| <motion.div | |
| key={msg.id || i} | |
| variants={messageVariants} | |
| initial="hidden" | |
| animate="visible" | |
| transition={{ delay: i * 0.05 }} | |
| className={`p-3 rounded-xl text-sm ${ | |
| msg.messageType === "error" | |
| ? "bg-red-50 dark:bg-red-900/10 border border-red-200 dark:border-red-800" | |
| : msg.fromAgent === "orchestrator" | |
| ? "bg-primary/5 border border-primary/20" | |
| : "bg-gray-50 dark:bg-gray-700/30 border border-gray-100 dark:border-gray-700" | |
| }`} | |
| > | |
| <div className="flex items-center gap-2 mb-2"> | |
| <span className="text-lg">{getAgentIcon(msg.fromAgent)}</span> | |
| <span className="font-semibold text-gray-700 dark:text-gray-300 text-xs"> | |
| {getAgentName(msg.fromAgent)} | |
| </span> | |
| <span className="text-gray-400 text-xs">→</span> | |
| <span className="text-lg">{getAgentIcon(msg.toAgent)}</span> | |
| <span className="font-semibold text-gray-700 dark:text-gray-300 text-xs"> | |
| {getAgentName(msg.toAgent)} | |
| </span> | |
| <span className="ml-auto text-[10px] text-gray-400"> | |
| {formatTime(msg.timestamp)} | |
| </span> | |
| <button | |
| onClick={() => copyMessage(msg.content, msg.id)} | |
| className="p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-600 transition" | |
| > | |
| {copiedId === msg.id ? ( | |
| <Check className="w-3 h-3 text-green-500" /> | |
| ) : ( | |
| <Copy className="w-3 h-3 text-gray-400" /> | |
| )} | |
| </button> | |
| </div> | |
| <div className="text-gray-700 dark:text-gray-300 whitespace-pre-wrap text-xs leading-relaxed"> | |
| {msg.content} | |
| </div> | |
| {msg.metadata && ( | |
| <div className="mt-2 text-[10px] text-gray-400 border-t border-gray-200 dark:border-gray-700 pt-1"> | |
| {Object.entries(msg.metadata).map(([key, value]) => ( | |
| <span key={key} className="mr-2"> | |
| {key}: {String(value)} | |
| </span> | |
| ))} | |
| </div> | |
| )} | |
| </motion.div> | |
| )) | |
| )} | |
| </div> | |
| </motion.div> | |
| )} | |
| </AnimatePresence> | |
| </div> | |
| ); | |
| } |
Xet Storage Details
- Size:
- 6.37 kB
- Xet hash:
- 7bb939c75cc9a277936c2466dc0ff59a600ef2f26cb273f540a28045f876f824
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.