import React, { useCallback, useEffect, useState } from 'react'; import { Activity, AlertTriangle, Database, RefreshCw, Server, ShieldCheck } from 'lucide-react'; import { motion } from 'framer-motion'; import { supabase } from '../services/supabase'; import { getApiUrl } from '../services/runtimeConfig'; interface MonitoringSummary { status: string; checks: Record; counts: Record; timestamp: string; error?: string; } const emptySummary: MonitoringSummary = { status: 'loading', checks: { api: 'checking', database: 'checking' }, counts: { projects: 0, tasks: 0, agents: 0, task_runs: 0, failed_tasks: 0, pending_reviews: 0 }, timestamp: new Date().toISOString() }; const MonitoringView: React.FC = () => { const [summary, setSummary] = useState(emptySummary); const [loading, setLoading] = useState(false); const fetchFallbackSummary = useCallback(async (): Promise => { const [projects, tasks, agents, runs, failed, reviews] = await Promise.all([ supabase.from('projects').select('id', { count: 'exact', head: true }), supabase.from('tasks').select('id', { count: 'exact', head: true }), supabase.from('agents').select('id', { count: 'exact', head: true }), supabase.from('task_runs').select('id', { count: 'exact', head: true }), supabase.from('tasks').select('id', { count: 'exact', head: true }).eq('status', 'failed'), supabase.from('tasks').select('id', { count: 'exact', head: true }).eq('status', 'awaiting_approval') ]); return { status: 'ok', checks: { api: 'unreachable', database: 'ok' }, counts: { projects: projects.count ?? 0, tasks: tasks.count ?? 0, agents: agents.count ?? 0, task_runs: runs.count ?? 0, failed_tasks: failed.count ?? 0, pending_reviews: reviews.count ?? 0 }, timestamp: new Date().toISOString(), error: 'Backend monitoring endpoint unavailable; using Supabase fallback.' }; }, []); const refresh = useCallback(async () => { setLoading(true); const apiUrl = getApiUrl(); try { const response = await fetch(`${apiUrl}/monitoring/summary`); if (!response.ok) throw new Error(`Backend returned ${response.status}`); setSummary(await response.json()); } catch { setSummary(await fetchFallbackSummary()); } finally { setLoading(false); } }, [fetchFallbackSummary]); useEffect(() => { refresh(); }, [refresh]); const degraded = summary.status !== 'ok' || Object.values(summary.checks).some((check) => check === 'error'); return (

Operations Monitor

Track platform health and workflow volume.

{degraded ? : }
System Status {degraded ? 'Degraded' : 'Operational'} {summary.error &&

{summary.error}

}
} label="Projects" value={summary.counts.projects} /> } label="Tasks" value={summary.counts.tasks} /> } label="Agents" value={summary.counts.agents} /> } label="Runs" value={summary.counts.task_runs} /> } label="Failed" value={summary.counts.failed_tasks} danger /> } label="Reviews" value={summary.counts.pending_reviews} />

Checks

{Object.entries(summary.checks).map(([name, value]) => (
{name} {value}
))} Updated {new Date(summary.timestamp).toLocaleString()}
); }; const MetricCard: React.FC<{ icon: React.ReactNode; label: string; value: number; danger?: boolean }> = ({ icon, label, value, danger }) => ( {icon}
{value} {label}
); export default MonitoringView;