'use client' import { useAgentStore } from '@/hooks/useAgentStore' import { formatDistanceToNow } from 'date-fns' import { Zap, Code2, Bug, Brain, Plug, Rocket, Workflow, Terminal, MessageSquare, CheckCircle2, XCircle, Clock, RefreshCw, ChevronDown, Trash2, Activity, Bot, Palette } from 'lucide-react' import { useState } from 'react' import type { AgentName } from '@/hooks/useAgentStore' const AGENT_META: Record = { chat: { icon: MessageSquare, color: '#22d3ee' }, planner: { icon: Zap, color: '#a78bfa' }, coding: { icon: Code2, color: '#34d399' }, debug: { icon: Bug, color: '#f87171' }, memory: { icon: Brain, color: '#fbbf24' }, connector: { icon: Plug, color: '#60a5fa' }, deploy: { icon: Rocket, color: '#f472b6' }, workflow: { icon: Workflow, color: '#fb923c' }, sandbox: { icon: Terminal, color: '#4ade80' }, ui: { icon: Palette, color: '#e879f9' }, } const EVENT_DISPLAY: Record = { task_created: { label: 'Task Created', icon: Zap, color: '#6366f1' }, task_submitted: { label: 'Task Submitted', icon: Zap, color: '#6366f1' }, task_queued: { label: 'Task Queued', icon: Clock, color: '#94a3b8' }, task_started: { label: 'Task Started', icon: Activity, color: '#22d3ee' }, task_completed: { label: 'Task Complete', icon: CheckCircle2, color: '#22c55e' }, task_failed: { label: 'Task Failed', icon: XCircle, color: '#ef4444' }, orchestrator_start: { label: 'Orchestrator Start', icon: Bot, color: '#6366f1' }, orchestrator_complete:{ label: 'Orchestrator Done', icon: CheckCircle2, color: '#22c55e' }, intent_classified: { label: 'Intent Classified', icon: Brain, color: '#a78bfa' }, agent_start: { label: 'Agent Started', icon: Zap, color: '#818cf8' }, agent_called: { label: 'Agent Called', icon: Bot, color: '#818cf8' }, plan_ready: { label: 'Plan Ready', icon: Zap, color: '#a78bfa' }, tool_called: { label: 'Tool Called', icon: Code2, color: '#34d399' }, tool_result: { label: 'Tool Result', icon: CheckCircle2, color: '#34d399' }, code_generated: { label: 'Code Generated', icon: Code2, color: '#34d399' }, file_written: { label: 'File Written', icon: Terminal, color: '#4ade80' }, sandbox_exec: { label: 'Sandbox Exec', icon: Terminal, color: '#4ade80' }, sandbox_result: { label: 'Sandbox Result', icon: CheckCircle2, color: '#4ade80' }, workflow_generated: { label: 'Workflow Generated', icon: Workflow, color: '#fb923c' }, deploy_plan_ready: { label: 'Deploy Plan Ready', icon: Rocket, color: '#f472b6' }, connector_result: { label: 'Connector Result', icon: Plug, color: '#60a5fa' }, self_heal_attempt: { label: 'Self-Healing', icon: RefreshCw, color: '#f87171' }, self_heal_success: { label: 'Healed ✓', icon: CheckCircle2, color: '#22c55e' }, self_heal_failed: { label: 'Heal Failed', icon: XCircle, color: '#ef4444' }, retry_attempt: { label: 'Retry', icon: RefreshCw, color: '#f59e0b' }, llm_chunk: { label: 'Streaming', icon: Activity, color: '#6366f1' }, stream_start: { label: 'Stream Start', icon: Activity, color: '#22d3ee' }, stream_end: { label: 'Stream End', icon: CheckCircle2, color: '#22c55e' }, debug_complete: { label: 'Debug Complete', icon: Bug, color: '#f87171' }, ui_generated: { label: 'UI Generated', icon: Palette, color: '#e879f9' }, installing_packages: { label: 'Installing Packages', icon: Terminal, color: '#4ade80' }, github_op: { label: 'GitHub Op', icon: Plug, color: '#60a5fa' }, } function EventCard({ event, index }: { event: any; index: number }) { const [expanded, setExpanded] = useState(false) const meta = EVENT_DISPLAY[event.type] || { label: event.type, icon: Activity, color: '#6366f1' } const Icon = meta.icon const agentMeta = event.agent ? AGENT_META[event.agent] : null const AgentIcon = agentMeta?.icon // Skip raw llm_chunk events (too noisy) if (event.type === 'llm_chunk') return null const hasData = event.data && Object.keys(event.data).length > 0 const dataStr = hasData ? JSON.stringify(event.data, null, 2) : null return (
{/* Line */}
{/* Dot */}
{/* Card */}
{/* Data preview (collapsed) */} {!expanded && hasData && (

{Object.entries(event.data).filter(([k]) => k !== 'chunk').slice(0, 3).map(([k, v]) => `${k}: ${typeof v === 'string' ? v.slice(0, 30) : JSON.stringify(v)}` ).join(' · ')}

)} {/* Expanded data */} {expanded && dataStr && (
              {dataStr}
            
)}
) } export default function ExecutionTimeline() { const { events, clearEvents, agents, locale } = useAgentStore() const visibleEvents = events.filter(e => e.type !== 'llm_chunk') const activeAgents = Object.values(agents).filter(a => a.status === 'executing' || a.status === 'thinking') return (
{/* Header */}
{locale === 'my' ? 'အချိန်ဇယား' : 'Execution Timeline'} {visibleEvents.length > 0 && ( {visibleEvents.length} )}
{visibleEvents.length > 0 && ( )}
{/* Active Agents Banner */} {activeAgents.length > 0 && (
{locale === 'my' ? 'အသုံးပြုနေသော Agent များ:' : 'Active:'} {activeAgents.map(a => { const meta = AGENT_META[a.name] const Icon = meta?.icon return Icon ? (
{a.name}
) : null })}
)} {/* Events */}
{visibleEvents.length === 0 ? (

{locale === 'my' ? 'အချိန်ဇယားအလွတ်' : 'No events yet'}

{locale === 'my' ? 'Task တစ်ခုဖန်တီးပါ — Real-time events တွေ့ရမည်' : 'Create a task to see real-time execution events'}

) : (
{[...visibleEvents].reverse().map((ev, i) => ( ))}
)}
{/* Agent Grid */}

{locale === 'my' ? 'Agent အားလုံး' : 'All Agents'}

{Object.entries(AGENT_META).map(([name, meta]) => { const Icon = meta.icon const agent = useAgentStore.getState().agents[name as AgentName] const isActive = agent?.status === 'executing' || agent?.status === 'thinking' return (
{name} {isActive &&
}
) })}
) }