/** * CronManagerPanel — displays and manages scheduled cron jobs. * Uses real JSON API endpoint /api/cron/:sessionId */ import { useState, useEffect, useCallback } from "react"; import { Timer, RefreshCw, Clock } from "lucide-react"; interface CronJob { id: string; schedule: string; command: string; description: string; status: "active" | "paused" | "deleted"; createdAt: number; lastRun?: number; runCount: number; output: string; } interface CronManagerPanelProps { sessionId: number; onSlashCommand: (command: string, args?: string) => Promise; } export function CronManagerPanel({ sessionId }: CronManagerPanelProps) { const [jobs, setJobs] = useState([]); const [loading, setLoading] = useState(false); const [expandedJob, setExpandedJob] = useState(null); const refreshJobs = useCallback(async () => { setLoading(true); try { const res = await fetch(`/api/cron/${sessionId}`); if (res.ok) { const data = await res.json(); if (Array.isArray(data)) setJobs(data); } } catch { // ignore fetch errors } finally { setLoading(false); } }, [sessionId]); useEffect(() => { refreshJobs(); // Auto-refresh every 5 seconds const interval = setInterval(refreshJobs, 5000); return () => clearInterval(interval); }, [refreshJobs]); const statusBadge = (status: string) => { const colors: Record = { active: "bg-green-500/10 text-green-400 border-green-500/20", paused: "bg-yellow-500/10 text-yellow-400 border-yellow-500/20", deleted: "bg-red-500/10 text-red-400 border-red-500/20", }; return ( {status} ); }; return (

Cron Jobs ({jobs.length})

{jobs.length === 0 ? (

No scheduled cron jobs

Jobs created via CronCreate tool will appear here

) : (
{jobs.map((job) => (
{expandedJob === job.id && (
                    {job.output || "(no output yet)"}
                  
)}
))}
)}
); }