import { type MachineRuntime, RUNTIME_LABELS, type UsageWindow } from "@vtit-agent-coding/shared"; import dayjs from "dayjs"; import { cn } from "../lib/utils"; const runtimeStatusStyles: Record = { ready: { dot: "bg-success", label: "Ready", }, limited: { dot: "bg-warning", label: "Limited", }, unauthorized: { dot: "bg-error", label: "Unauthorized", }, unhealthy: { dot: "bg-error", label: "Unhealthy", }, missing: { dot: "bg-content-tertiary", label: "Missing", }, }; const RUNTIME_SHORT_LABELS: Record = { claude: "Claude", codex: "Codex", gemini: "Gemini", copilot: "Copilot", hermes: "Hermes", antigravity: "Antigravity", ama: "AMA", }; const runtimeBadgeStyles: Record = { ready: "text-content-secondary", limited: "bg-warning/10 text-warning", unauthorized: "bg-error/10 text-error", unhealthy: "bg-error/10 text-error", missing: "text-content-tertiary", }; function RuntimeStatus({ runtime }: { runtime: MachineRuntime }) { const style = runtimeStatusStyles[runtime.status]; return ( {style.label} ); } function runtimeTooltip(runtime: MachineRuntime): string { const status = runtimeStatusStyles[runtime.status].label; const label = RUNTIME_LABELS[runtime.name] ?? runtime.name; return runtime.detail ? `${label} · ${status} · ${runtime.detail}` : `${label} · ${status}`; } function usageBarColor(pct: number): string { if (pct >= 75) return "bg-error"; if (pct >= 40) return "bg-warning"; return "bg-success"; } function usagePercent(window: UsageWindow): number { return Math.round(window.utilization < 1 ? window.utilization * 100 : window.utilization); } function formatResetTime(resetsAt: string): string { return dayjs(resetsAt).format("MMM D, YYYY h:mm A"); } function isPendingReset(window: UsageWindow): boolean { return new Date(window.resets_at).getTime() > Date.now(); } export function MachineRuntimeBadges({ runtimes, maxVisible = runtimes.length }: { runtimes: MachineRuntime[]; maxVisible?: number }) { if (runtimes.length === 0) { return No runtimes; } const visible = runtimes.slice(0, maxVisible); const hiddenCount = runtimes.length - visible.length; return (
{visible.map((runtime) => ( {RUNTIME_SHORT_LABELS[runtime.name] ?? runtime.name} ))} {hiddenCount > 0 && ( +{hiddenCount} )}
); } export function MachineRuntimeList({ runtimes }: { runtimes: MachineRuntime[] }) { if (runtimes.length === 0) { return No runtimes detected; } return (
{runtimes.map((runtime) => (
{RUNTIME_LABELS[runtime.name] ?? runtime.name}
{runtime.detail &&
{runtime.detail}
}
))}
); } function RuntimeUsageWindows({ windows }: { windows: UsageWindow[] }) { return (
{windows.map((window) => { const pct = usagePercent(window); return (
{window.label}
{pct}% · {formatResetTime(window.resets_at)}
); })}
); } export function MachineRuntimeAvailability({ runtimes, windows }: { runtimes: MachineRuntime[]; windows: UsageWindow[] }) { if (runtimes.length === 0) { return No runtimes detected; } const activeWindows = windows.filter(isPendingReset); return (
{runtimes.map((runtime) => { const runtimeWindows = activeWindows.filter((window) => window.runtime === runtime.name); return (
{RUNTIME_LABELS[runtime.name] ?? runtime.name}
{runtime.detail &&
{runtime.detail}
}
{runtimeWindows.length > 0 && (
)}
); })}
); }