import type { MachineRuntime } from "@vtit-agent-coding/shared"; import { useEffect, useState } from "react"; import { formatRelative } from "../../components/TaskDetailFields"; import { Skeleton } from "../../components/ui/skeleton"; import { api } from "../../lib/api"; interface MachineMetrics { qps: number; error_rate: number; avg_latency_ms: number; total_requests: number; } interface AdminMachine { id: string; name: string; status: string; os: string; version: string; runtimes: MachineRuntime[]; owner_name: string | null; owner_email: string | null; session_count: number; active_session_count: number; last_heartbeat_at: string | null; metrics: MachineMetrics | null; } const statusDotColors: Record = { online: "bg-success", offline: "bg-content-tertiary", }; function MetricCell({ value, unit, muted }: { value: string; unit?: string; muted?: boolean }) { return ( {value} {unit && {unit}} ); } function SkeletonRows() { return ( <> {[0, 1, 2].map((i) => ( {Array.from({ length: 8 }).map((_, j) => ( ))} ))} ); } export function AdminMachinesPage() { const [machines, setMachines] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { let mounted = true; const load = () => { api.admin .getMachines() .then((data) => { if (!mounted) return; setMachines(data); setError(null); }) .catch((err) => mounted && setError(err.message ?? "Failed to load machines")) .finally(() => mounted && setLoading(false)); }; load(); const interval = setInterval(load, 15_000); return () => { mounted = false; clearInterval(interval); }; }, []); const onlineCount = machines.filter((m) => m.status === "online").length; return (

Machines

{onlineCount} online / {machines.length} total
{loading ? ( ) : error ? ( ) : machines.length === 0 ? ( ) : ( machines.map((m) => ( )) )}
Machine Owner Agents QPS Err % Latency Reqs (5m) Heartbeat
{error}
No machines registered

{m.name}

{[m.os, m.version].filter(Boolean).join(" · ") || "—"}

{m.owner_name || "—"}

{m.owner_email || ""}

{m.active_session_count} / {m.session_count} {m.metrics ? ( 5 ? "text-destructive" : m.metrics.error_rate > 0 ? "text-warning" : "text-content-primary"}`} > {m.metrics.error_rate}% ) : ( )} {m.last_heartbeat_at ? formatRelative(m.last_heartbeat_at) : "—"}
); }