import { useMemo, useState, useEffect } from 'react' import { Wifi, WifiOff, Brain, Sparkles } from 'lucide-react' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import type { AgentStatus } from '../lib/types' interface ProgressDashboardProps { passing: number total: number percentage: number isConnected: boolean logs?: Array<{ line: string; timestamp: string }> agentStatus?: AgentStatus } const IDLE_TIMEOUT = 30000 function isAgentThought(line: string): boolean { const trimmed = line.trim() if (/^\[Tool:/.test(trimmed)) return false if (/^\s*Input:\s*\{/.test(trimmed)) return false if (/^\[(Done|Error)\]/.test(trimmed)) return false if (/^Output:/.test(trimmed)) return false if (/^[[{]/.test(trimmed)) return false if (trimmed.length < 10) return false if (/^[A-Za-z]:\\/.test(trimmed)) return false if (/^\/[a-z]/.test(trimmed)) return false return true } function getLatestThought(logs: Array<{ line: string; timestamp: string }>): string | null { for (let i = logs.length - 1; i >= 0; i--) { if (isAgentThought(logs[i].line)) { return logs[i].line.trim() } } return null } export function ProgressDashboard({ passing, total, percentage, isConnected, logs = [], agentStatus, }: ProgressDashboardProps) { const thought = useMemo(() => getLatestThought(logs), [logs]) const [displayedThought, setDisplayedThought] = useState(null) const [textVisible, setTextVisible] = useState(true) const lastLogTimestamp = logs.length > 0 ? new Date(logs[logs.length - 1].timestamp).getTime() : 0 const showThought = useMemo(() => { if (!thought) return false if (agentStatus === 'running') return true if (agentStatus === 'paused') { return Date.now() - lastLogTimestamp < IDLE_TIMEOUT } return false }, [thought, agentStatus, lastLogTimestamp]) useEffect(() => { if (thought !== displayedThought && thought) { setTextVisible(false) const timeout = setTimeout(() => { setDisplayedThought(thought) setTextVisible(true) }, 150) return () => clearTimeout(timeout) } }, [thought, displayedThought]) const isRunning = agentStatus === 'running' return (
Progress {isConnected ? ( <> Live ) : ( <> Offline )}
{passing} / {total}
{/* Progress Bar */}
{/* Percentage */} {percentage.toFixed(1)}%
{/* Agent Thought */}
{isRunning && ( )}

{displayedThought?.replace(/:$/, '')}

) }