import { Activity } from "lucide-react"; import type { Agent } from "../api"; import { useLiveTranscript } from "../hooks/useLiveTranscript"; interface LiveAgentCardProps { agent: Agent; projectId?: string; onSelect?: (agentId: string) => void; } function LiveAgentCard({ agent, projectId, onSelect }: LiveAgentCardProps) { const { entries, isConnected } = useLiveTranscript(agent.taskId, projectId); const elapsed = agent.lastHeartbeatAt ? Math.floor((Date.now() - new Date(agent.lastHeartbeatAt).getTime()) / 1000) : 0; const handleSelect = () => { if (onSelect) { onSelect(agent.id); } }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); handleSelect(); } }; return (
{agent.name}
{agent.taskId && ( {agent.taskId} )}
{entries.length === 0 ? (
{isConnected ? "Waiting for output..." : "Connecting..."}
) : ( entries.slice(0, 20).map((entry, i) => (
{entry.text}
)) )}
{formatElapsed(elapsed)} {isConnected && }
); } function formatElapsed(seconds: number): string { if (seconds < 60) return `${seconds}s`; if (seconds < 3600) return `${Math.floor(seconds / 60)}m ${seconds % 60}s`; return `${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m`; } interface ActiveAgentsPanelProps { agents: Agent[]; projectId?: string; onAgentSelect?: (agentId: string) => void; } export function ActiveAgentsPanel({ agents, projectId, onAgentSelect }: ActiveAgentsPanelProps) { if (agents.length === 0) return null; return (
Active Agents ({agents.length})
{agents.map(agent => ( ))}
); }