import React, { useState } from 'react'; import { Users, Brain, MessageSquare, Activity, ChevronDown, ChevronUp, } from 'lucide-react'; import { Card, CardHeader, CardContent } from '@/components/ui/Card'; import { Badge, StatusBadge } from '@/components/ui/Badge'; import { useAgents, getAgentRoleIcon, getAgentRoleColor } from '@/hooks/useAgents'; import { useCurrentEpisode } from '@/hooks/useEpisode'; import { formatTimestamp, truncateText } from '@/utils/helpers'; import type { Agent, AgentThought } from '@/types'; interface AgentViewProps { className?: string; } interface AgentCardProps { agent: Agent; isExpanded: boolean; onToggle: () => void; } const ThoughtBubble: React.FC<{ thought: AgentThought }> = ({ thought }) => { const typeColors: Record = { reasoning: 'border-l-blue-400', planning: 'border-l-purple-400', observation: 'border-l-green-400', decision: 'border-l-orange-400', }; return (
{thought.type} {formatTimestamp(thought.timestamp)}

{thought.content}

); }; const AgentCard: React.FC = ({ agent, isExpanded, onToggle, }) => { const roleIcon = getAgentRoleIcon(agent.role); const roleColor = getAgentRoleColor(agent.role); return (
{isExpanded && (
{/* Current Task */} {agent.currentTask && (
Current Task
{agent.currentTask}
)} {/* Last Action */} {agent.lastAction && (
Last Action
{agent.lastAction.type} {agent.lastAction.reasoning && ( {truncateText(agent.lastAction.reasoning, 50)} )}
)} {/* Thought Stream */} {agent.thoughts.length > 0 && (
Thought Stream
{agent.thoughts.slice(-5).map((thought, i) => ( ))}
)}
)}
); }; export const AgentView: React.FC = ({ className }) => { const { data: episode } = useCurrentEpisode(); const { data: agents, isLoading } = useAgents(episode?.id); const [expandedAgents, setExpandedAgents] = useState>(new Set()); const toggleAgent = (agentId: string) => { setExpandedAgents((prev) => { const next = new Set(prev); if (next.has(agentId)) { next.delete(agentId); } else { next.add(agentId); } return next; }); }; const activeAgents = agents?.filter((a) => a.status !== 'idle') ?? []; const idleAgents = agents?.filter((a) => a.status === 'idle') ?? []; return ( } action={ activeAgents.length > 0 && ( {activeAgents.length} active ) } /> {isLoading ? (
) : !agents || agents.length === 0 ? (

No agents active

) : (
{/* Active Agents */} {activeAgents.map((agent) => ( toggleAgent(agent.id)} /> ))} {/* Idle Agents */} {idleAgents.length > 0 && activeAgents.length > 0 && (
Idle Agents
)} {idleAgents.map((agent) => ( toggleAgent(agent.id)} /> ))}
)} {/* Thought Feed */} {agents && agents.some((a) => a.thoughts.length > 0) && (
Latest Thoughts
{agents .flatMap((a) => a.thoughts.map((t) => ({ ...t, agentId: a.id, role: a.role })) ) .sort( (a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime() ) .slice(0, 5) .map((thought, i) => (
{getAgentRoleIcon(thought.role)} {thought.role} {formatTimestamp(thought.timestamp)}

{truncateText(thought.content, 100)}

))}
)}
); }; export default AgentView;