"use client"; import { useState, useEffect } from "react"; import { RecurringTemplate, defaultRecurringTemplates } from "@/lib/mission-control/recurring"; const AGENT_COLORS: Record = { thoth: "#8b5cf6", "thoth-trading": "#f59e0b", ptah: "#10b981", seshat: "#ec4899", anubis: "#6366f1", sekhmet: "#ef4444" }; const AGENT_NAMES: Record = { thoth: "Thoth", "thoth-trading": "Thoth Trading", ptah: "Ptah", seshat: "Seshat", anubis: "Anubis", sekhmet: "Sekhmet" }; export default function AutoRunPanel() { const [templates, setTemplates] = useState([]); const [loading, setLoading] = useState(true); const [running, setRunning] = useState(null); useEffect(() => { fetchTemplates(); }, []); const fetchTemplates = async () => { const res = await fetch("/api/recurring"); const data = await res.json(); // Merge with defaults if empty if (data.length === 0) { await fetch("/api/recurring", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "save", template: defaultRecurringTemplates[0] }) }); setTemplates(defaultRecurringTemplates); } else { setTemplates(data); } setLoading(false); }; const toggleTemplate = async (templateId: string, enabled: boolean) => { await fetch("/api/recurring", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "toggle", templateId, enabled }) }); fetchTemplates(); }; const runNow = async (templateId: string) => { setRunning(templateId); await fetch("/api/recurring", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "run-now", templateId }) }); setRunning(null); fetchTemplates(); }; const formatSchedule = (template: RecurringTemplate) => { const { schedule } = template; switch (schedule.type) { case "hourly": return "Hourly"; case "daily": return `Daily @ ${schedule.time}`; case "weekly": const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; return `Weekly: ${days[schedule.dayOfWeek || 0]} @ ${schedule.time}`; case "monthly": return `Monthly: Day ${schedule.dayOfMonth}`; default: return schedule.type; } }; if (loading) { return
Loading templates...
; } return (

🔄 Auto-Run Templates

{templates.filter(t => t.enabled).length} active
{templates.map((template) => (
{AGENT_NAMES[template.agent] || template.agent} {formatSchedule(template)}

{template.name}

{template.description}

{template.preInstructions && (
View pre-instructions

{template.preInstructions}

)}
Run count: {template.runCount || 0} {template.lastRun && ( Last: {new Date(template.lastRun).toLocaleString()} )} {template.nextRun && ( Next: {new Date(template.nextRun).toLocaleString()} )}
))}
{templates.length === 0 && (
No recurring templates. Create one to automate your agents.
)}
); }