"use client"; import { useState, useEffect } from "react"; interface ExecutionLog { id: string; templateId: string; agent: string; taskTitle: string; startedAt: string; completedAt?: string; status: string; output?: string; error?: string; } const AGENT_COLORS: Record = { thoth: "#8b5cf6", "thoth-trading": "#f59e0b", ptah: "#10b981", seshat: "#ec4899", anubis: "#6366f1", sekhmet: "#ef4444" }; export default function ExecutionLogsPanel() { const [logs, setLogs] = useState([]); const [loading, setLoading] = useState(true); const [filterAgent, setFilterAgent] = useState("all"); const [selectedLog, setSelectedLog] = useState(null); useEffect(() => { fetchLogs(); const interval = setInterval(fetchLogs, 30000); // Refresh every 30s return () => clearInterval(interval); }, []); const fetchLogs = async () => { const res = await fetch("/api/execution-logs?limit=50"); const data = await res.json(); setLogs(data); setLoading(false); }; const getStatusColor = (status: string) => { switch (status) { case "running": return "text-yellow-400 bg-yellow-400/20"; case "completed": return "text-green-400 bg-green-400/20"; case "failed": return "text-red-400 bg-red-400/20"; default: return "text-white/50 bg-white/10"; } }; const filteredLogs = filterAgent === "all" ? logs : logs.filter(l => l.agent === filterAgent); const agents = [...new Set(logs.map(l => l.agent))]; if (loading) { return
Loading logs...
; } return (

📊 Execution Logs

{/* Log List */}
{filteredLogs.map((log) => (
setSelectedLog(log)} className={`p-3 rounded-lg cursor-pointer transition ${ selectedLog?.id === log.id ? "bg-brand-pink/20 border border-brand-pink" : "bg-white/5 border border-white/10 hover:bg-white/10" }`} >
{log.agent} {log.taskTitle}
{log.status}
{new Date(log.startedAt).toLocaleString()} {log.completedAt && ( Duration: {Math.round((new Date(log.completedAt).getTime() - new Date(log.startedAt).getTime()) / 1000)}s )}
))} {filteredLogs.length === 0 && (
No execution logs yet. Run a task to see logs here.
)}
{/* Log Detail */} {selectedLog && (

{selectedLog.taskTitle}

Agent:{" "} {selectedLog.agent}
Status:{" "} {selectedLog.status}
Started:{" "} {new Date(selectedLog.startedAt).toLocaleString()}
{selectedLog.completedAt && (
Completed:{" "} {new Date(selectedLog.completedAt).toLocaleString()}
)}
{selectedLog.output && (
Output:
                {selectedLog.output}
              
)} {selectedLog.error && (
Error:
                {selectedLog.error}
              
)}
)}
); }