"use client" import { useCallback, useEffect, useState } from "react" import type { SandboxInventoryItem } from "../hooks/useSandboxInventory" type HealthCheck = { key: string label: string ok: boolean detail: string } type HealthResponse = { ok: boolean error?: string sandbox?: { id: string | null name: string phase: string } checks: HealthCheck[] backupCount?: number durationMs: number checkedAt: string } export default function SandboxHealthPanel({ sandbox }: { sandbox: SandboxInventoryItem }) { const [health, setHealth] = useState(null) const [loading, setLoading] = useState(false) const loadHealth = useCallback(async () => { try { setLoading(true) const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/health`, { cache: "no-store" }) const data = await response.json() setHealth(data) } catch (error) { setHealth({ ok: false, error: error instanceof Error ? error.message : "Health check failed", checks: [], durationMs: 0, checkedAt: new Date().toISOString(), }) } finally { setLoading(false) } }, [sandbox.id]) useEffect(() => { loadHealth() }, [loadHealth]) const checks = health?.checks || [] return (
Sandbox Health

Quick checks for OpenShell resolution, runtime phase, SSH config, and saved backups.

{(checks.length ? checks : [{ key: "loading", label: "Health", ok: false, detail: loading ? "Checking..." : "No health data yet." }]).map((check) => (
{check.label}
{check.ok ? "ok" : "check"}

{check.detail}

))}
{health && (
Checked {new Date(health.checkedAt).toLocaleString()} in {health.durationMs} ms {health.sandbox ? ` / ${health.sandbox.name} / ${health.sandbox.phase}` : ""} {health.error ? ` / ${health.error}` : ""}
)}
) }