"use client" import { useEffect, useState } from "react" /** * SandboxFleetView — fleet-native Sandboxes-View (ersetzt die tote Upstream- * "Sandboxes"-View, die den openshell-CLI auf dem Tower-HOST brauchte — unser * Tower ist ein K8s-Container ohne Host-CLI). * * Datenquelle: /api/fleet/sandboxes (kube-state-metrics via Prometheus, * read-only PromQL; KEIN kubectl, KEINE Host-CLI). Zeigt die 9 Agenten-Sandboxes: * Phase/Ready, Restarts, Pod-Age, Node, CPU/Mem-Requests, Image-Digest, * Heartbeat-Age. Poll 5 s, Fehler fail-loud sichtbar (kein stilles Leeren). */ type SandboxAgent = { agent_id: string role: string title: string | null exists: boolean phase: string | null ready: boolean | null restarts: number | null pod_age_s: number | null node: string | null cpu_request_milli: number | null mem_request_mb: number | null image_digest: string | null heartbeat_age_s: number | null } type SandboxesData = { agents: SandboxAgent[] fleet_image_digest: string | null all_running: boolean generated_at: string } function phaseColor(agent: SandboxAgent): { color: string; label: string } { if (!agent.exists || !agent.phase) return { color: "var(--foreground-dim)", label: "kein Pod" } if (agent.phase === "Running" && agent.ready) return { color: "var(--status-running)", label: "Running" } if (agent.phase === "Running") return { color: "#e6b450", label: "Running/NotReady" } return { color: "var(--status-stopped)", label: agent.phase } } function hbColor(age: number | null): { color: string; label: string } { if (age === null) return { color: "var(--foreground-dim)", label: "pending" } if (age < 120) return { color: "var(--status-running)", label: `${Math.round(age)}s` } if (age < 300) return { color: "#e6b450", label: `${Math.round(age)}s` } return { color: "var(--status-stopped)", label: `${Math.round(age)}s` } } function fmtAge(sec: number): string { if (sec < 60) return `${sec}s` if (sec < 3600) return `${Math.floor(sec / 60)}m` if (sec < 86400) return `${Math.floor(sec / 3600)}h ${Math.floor((sec % 3600) / 60)}m` return `${Math.floor(sec / 86400)}d ${Math.floor((sec % 86400) / 3600)}h` } function fmtDigest(d: string | null): string { if (!d) return "—" return d.length > 19 ? `${d.slice(0, 19)}…` : d } export default function SandboxFleetView() { const [data, setData] = useState(null) const [error, setError] = useState(null) useEffect(() => { let cancelled = false const load = () => { fetch("/api/fleet/sandboxes", { cache: "no-store" }) .then(async (res) => { if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`) return res.json() }) .then((d: SandboxesData) => { if (!cancelled) { setData(d) setError(null) } }) .catch((e: Error) => { if (!cancelled) setError(e.message) }) } load() const timer = setInterval(load, 5000) return () => { cancelled = true clearInterval(timer) } }, []) if (error) { return (

Fleet-Datenquelle nicht erreichbar

{error}

) } if (!data) { return (
Lade Sandboxes…
) } const running = data.agents.filter((a) => a.phase === "Running" && a.ready).length return (

Sandboxes

{running}/{data.agents.length} running {data.all_running ? "ALLE GRÜN" : "DEGRADED"}
Fleet Image (digest-gepinnt)
{fmtDigest(data.fleet_image_digest)}
{data.agents.map((agent) => { const ph = phaseColor(agent) const hb = hbColor(agent.heartbeat_age_s) return (
{agent.agent_id}
{agent.role}
{ph.label}
Node {agent.node || "—"} Pod-Age {agent.pod_age_s === null ? "—" : fmtAge(agent.pod_age_s)} Restarts 0 ? "#e6b450" : "var(--foreground)" }} > {agent.restarts ?? "—"} Requests {agent.cpu_request_milli ? `${agent.cpu_request_milli}m / ${agent.mem_request_mb}Mi` : "—"} Heartbeat {hb.label} Image {fmtDigest(agent.image_digest)}
) })}
Stand: {new Date(data.generated_at).toLocaleTimeString("de-DE")} · Quelle: kube-state-metrics via Prometheus (read-only)
) }