'use client'; import { useEffect, useState, useCallback } from 'react'; // ── types ───────────────────────────────────────────────────────────────────── interface Service { name: string; status: 'operational' | 'degraded' | 'down'; latencyMs: number; } interface StatusData { status: string; score: number; services: Service[]; summary: { operational: number; degraded: number; down: number; total: number }; platform: { workers: number; tunnel_routes: number; agent_capacity: number; orgs: number; repos: number }; timestamp: string; } interface Agent { id: string; name: string; role: string; status: string; node: string; color: string; skills: string[]; tasks: number; uptime: number; } interface AgentsData { agents: Agent[]; total: number; active: number; } // ── helpers ─────────────────────────────────────────────────────────────────── const PI_FLEET = [ { name: 'octavia', ip: '192.168.4.38', role: 'Primary — 22,500 agents', port: 8080 }, { name: 'lucidia', ip: '192.168.4.64', role: 'Secondary — 7,500 agents', port: 11434 }, { name: 'alice', ip: '192.168.4.49', role: 'Mesh node', port: 8001 }, { name: 'cecilia', ip: '192.168.4.89', role: 'Identity node', port: 80 }, ]; function statusColor(s?: string) { if (s === 'operational') return '#4ade80'; if (s === 'degraded') return '#F5A623'; return '#ef4444'; } function statusLabel(s?: string) { if (s === 'operational') return 'All Systems Operational'; if (s === 'partial_outage') return 'Partial Outage'; if (s === 'major_outage') return 'Major Outage'; return 'Checking…'; } function timeAgo(iso?: string) { if (!iso) return ''; const secs = Math.floor((Date.now() - new Date(iso).getTime()) / 1000); if (secs < 5) return 'just now'; if (secs < 60) return `${secs}s ago`; return `${Math.floor(secs / 60)}m ago`; } // ── sub-components ──────────────────────────────────────────────────────────── function MetricCard({ label, value, color }: { label: string; value: string | number; color: string }) { return (
{value}
{label}
); } function ServiceRow({ svc }: { svc: Service }) { const dot = statusColor(svc.status); return (
{svc.name}
{svc.latencyMs > 0 && ( {svc.latencyMs}ms )} {svc.status}
); } function AgentCard({ agent }: { agent: Agent }) { const active = agent.status === 'active' || agent.status === 'online'; return (
{agent.name}
{agent.role} · {agent.node}
{agent.status}
{agent.skills.map(s => ( {s} ))}
{agent.tasks.toLocaleString()} tasks {agent.uptime}% uptime
); } function PiNode({ node, online }: { node: typeof PI_FLEET[0]; online: boolean }) { return (
{node.name}
{node.ip}:{node.port}
{node.role}
); } // ── main dashboard ──────────────────────────────────────────────────────────── export default function DashboardPage() { const [status, setStatus] = useState(null); const [agents, setAgents] = useState(null); const [loading, setLoading] = useState(true); const [lastTick, setLastTick] = useState(''); const [countdown, setCountdown] = useState(30); const refresh = useCallback(async () => { const [s, a] = await Promise.allSettled([ fetch('/api/status').then(r => r.json()), fetch('/api/agents').then(r => r.json()), ]); if (s.status === 'fulfilled') setStatus(s.value); if (a.status === 'fulfilled') setAgents(a.value); setLoading(false); setLastTick(new Date().toISOString()); setCountdown(30); }, []); useEffect(() => { refresh(); const interval = setInterval(refresh, 30_000); return () => clearInterval(interval); }, [refresh]); // countdown ticker useEffect(() => { const t = setInterval(() => setCountdown(c => c > 0 ? c - 1 : 0), 1000); return () => clearInterval(t); }, []); const overallColor = statusColor(status?.status === 'operational' ? 'operational' : status?.status === 'partial_outage' ? 'degraded' : 'down'); // map Pi nodes to online status from services const piOnline = (name: string) => { if (!status?.services) return false; const svc = status.services.find(s => s.name.toLowerCase().includes(name.toLowerCase())); return svc?.status === 'operational'; }; return (
{/* header */}
B
BlackRoad OS Infrastructure
{loading ? 'Loading…' : statusLabel(status?.status)} · Updated {timeAgo(lastTick)} · refresh in {countdown}s
{/* key metrics */}

Platform Scale

{/* main grid: services + agents */}
{/* services */}

Service Health

{status?.summary.operational ?? '—'} up {status?.summary.degraded ?? '—'} degraded {status?.summary.down ?? '—'} down
{loading ? (
{[...Array(6)].map((_, i) => (
))}
) : (
{status?.services.map(s => )}
)}
{/* agent roster */}

Agent Roster

{agents?.active ?? '—'} active / {agents?.total ?? '—'} total
{loading ? (
{[...Array(4)].map((_, i) => (
))}
) : (
{(agents?.agents ?? []).map(a => )}
)}
{/* Pi fleet */}

Pi Fleet

{PI_FLEET.map(n => ( ))}
{/* footer */}
); }