153 lines
5.4 KiB
TypeScript
153 lines
5.4 KiB
TypeScript
"use client"
|
|
|
|
import { useEffect, useState } from "react"
|
|
|
|
/**
|
|
* OrgChart — Kernfeature 1: Live-Org-Chart aus /api/fleet/overview.
|
|
* 9 Agenten-Karten (parent-Hierarchie), je Karte tok/s (in/out), Inbox-Size,
|
|
* Heartbeat-Status (gruen < 300 s, gelb < 900 s, rot sonst/null=pending).
|
|
* Poll 5 s; Fehler fail-loud sichtbar (kein leeres UI).
|
|
*/
|
|
|
|
type OverviewAgent = {
|
|
agent_id: string
|
|
role: string
|
|
al: number
|
|
parent: string | null
|
|
wave: number
|
|
function: string
|
|
title?: string
|
|
vk_name: string | null
|
|
model: string | null
|
|
tok_in_per_s: number
|
|
tok_out_per_s: number
|
|
inbox: number
|
|
heartbeat_age_s: number | null
|
|
}
|
|
|
|
type Overview = { agents: OverviewAgent[]; generated_at: string }
|
|
|
|
function hbColor(age: number | null): { color: string; label: string } {
|
|
if (age === null) return { color: "var(--foreground-dim)", label: "pending" }
|
|
if (age < 300) return { color: "var(--status-running)", label: `${Math.round(age)}s` }
|
|
if (age < 900) return { color: "#e6b450", label: `${Math.round(age)}s` }
|
|
return { color: "var(--status-stopped)", label: `${Math.round(age)}s` }
|
|
}
|
|
|
|
export default function OrgChart() {
|
|
const [data, setData] = useState<Overview | null>(null)
|
|
const [error, setError] = useState<string | null>(null)
|
|
|
|
useEffect(() => {
|
|
let cancelled = false
|
|
const load = () => {
|
|
fetch("/api/fleet/overview", { cache: "no-store" })
|
|
.then(async (res) => {
|
|
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
|
return res.json()
|
|
})
|
|
.then((d: Overview) => {
|
|
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 (
|
|
<div className="panel p-8 text-center" data-testid="fleet-org-error">
|
|
<h3 className="text-sm font-semibold text-[var(--status-stopped)] uppercase tracking-wider">
|
|
Fleet-Datenquelle nicht erreichbar
|
|
</h3>
|
|
<p className="text-xs text-[var(--foreground-dim)] mt-2 font-mono break-all">{error}</p>
|
|
</div>
|
|
)
|
|
}
|
|
if (!data) {
|
|
return (
|
|
<div className="flex items-center justify-center h-64" data-testid="fleet-org-loading">
|
|
<div className="text-xs text-[var(--foreground-dim)] font-mono uppercase tracking-wider">
|
|
LADEN...
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const ceo = data.agents.filter((a) => a.parent === null)
|
|
const byParent = new Map<string, OverviewAgent[]>()
|
|
for (const a of data.agents) {
|
|
if (a.parent === null) continue
|
|
const list = byParent.get(a.parent) || []
|
|
list.push(a)
|
|
byParent.set(a.parent, list)
|
|
}
|
|
|
|
const renderCard = (a: OverviewAgent) => {
|
|
const hb = hbColor(a.heartbeat_age_s)
|
|
const children = byParent.get(a.agent_id) || []
|
|
return (
|
|
<div key={a.agent_id} className="flex flex-col items-center gap-4" data-testid={`fleet-agent-card-${a.agent_id}`}>
|
|
<div className="panel p-4 min-w-[220px]" data-fleet-agent-card={a.agent_id}>
|
|
<div className="flex items-center justify-between gap-3">
|
|
<span className="text-sm font-semibold">{a.agent_id}</span>
|
|
<span className="text-[10px] text-[var(--foreground-dim)] uppercase">AL{a.al}</span>
|
|
</div>
|
|
<div className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">{a.function}</div>
|
|
<div className="mt-3 grid grid-cols-3 gap-2 text-center" data-fleet-status-elements="3">
|
|
<div>
|
|
<div className="text-[9px] uppercase text-[var(--foreground-dim)]">tok/s in</div>
|
|
<div className="text-sm font-mono text-[var(--nvidia-green)]">{a.tok_in_per_s.toFixed(1)}</div>
|
|
</div>
|
|
<div>
|
|
<div className="text-[9px] uppercase text-[var(--foreground-dim)]">tok/s out</div>
|
|
<div className="text-sm font-mono text-[var(--nvidia-green)]">{a.tok_out_per_s.toFixed(1)}</div>
|
|
</div>
|
|
<div>
|
|
<div className="text-[9px] uppercase text-[var(--foreground-dim)]">Inbox</div>
|
|
<div className="text-sm font-mono" data-fleet-inbox={a.agent_id}>{a.inbox}</div>
|
|
</div>
|
|
</div>
|
|
<div className="mt-3 flex items-center gap-2">
|
|
<span className="text-[9px] uppercase text-[var(--foreground-dim)]">Heartbeat</span>
|
|
<span className="text-xs font-mono" style={{ color: hb.color }} data-fleet-heartbeat={a.agent_id}>
|
|
{hb.label}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
{children.length > 0 && (
|
|
<div className="flex flex-wrap justify-center gap-4 border-t border-[var(--border)] pt-4">
|
|
{children.map(renderCard)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<div className="panel p-6">
|
|
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mb-2">
|
|
FLEET ORG
|
|
</h1>
|
|
<p className="text-xs text-[var(--foreground-dim)] font-mono">
|
|
{data.agents.length} Agenten · Stand {new Date(data.generated_at).toLocaleTimeString("de-DE")}
|
|
</p>
|
|
</div>
|
|
<div className="flex flex-col items-center gap-8" data-testid="fleet-org-chart">
|
|
{ceo.map(renderCard)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|