fleet(tower): 0.18 — Tasks-View (Spool/Dead-Letter/Alarm) + Task-Detail-Modal + /healthz + /api/status; Fleet-Views 0.13-0.18 erstmals versioniert
This commit is contained in:
+113
-1
@@ -14,7 +14,7 @@ type ControllerNodeRecord = {
|
||||
interface SidebarProps {
|
||||
sandboxesRunning: number
|
||||
sandboxesTotal: number
|
||||
activeView: 'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp'
|
||||
activeView: 'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp' | 'org' | 'messages' | 'board' | 'owner' | 'escalations' | 'approvals' | 'fleet-sandboxes' | 'tasks'
|
||||
isCreateMode: boolean
|
||||
isDestroyMode: boolean
|
||||
onSandboxesClick: () => void
|
||||
@@ -25,6 +25,14 @@ interface SidebarProps {
|
||||
onMcpClick: () => void
|
||||
onWizardsClick: () => void
|
||||
onHelpClick: () => void
|
||||
onFleetOrgClick: () => void
|
||||
onFleetMessagesClick: () => void
|
||||
onFleetBoardClick: () => void
|
||||
onFleetOwnerClick: () => void
|
||||
onFleetApprovalsClick: () => void
|
||||
onFleetEscalationsClick: () => void
|
||||
onFleetSandboxesClick: () => void
|
||||
onFleetTasksClick: () => void
|
||||
onExitMode: () => void
|
||||
onLogout: () => void
|
||||
terminalDisabled?: boolean
|
||||
@@ -46,6 +54,14 @@ export default function Sidebar({
|
||||
onMcpClick,
|
||||
onWizardsClick,
|
||||
onHelpClick,
|
||||
onFleetOrgClick,
|
||||
onFleetMessagesClick,
|
||||
onFleetBoardClick,
|
||||
onFleetOwnerClick,
|
||||
onFleetApprovalsClick,
|
||||
onFleetEscalationsClick,
|
||||
onFleetSandboxesClick,
|
||||
onFleetTasksClick,
|
||||
onExitMode,
|
||||
onLogout,
|
||||
terminalDisabled = false,
|
||||
@@ -216,6 +232,102 @@ export default function Sidebar({
|
||||
</div>
|
||||
|
||||
<nav className="flex-1 p-2 max-lg:flex max-lg:gap-1 max-lg:overflow-x-auto max-lg:[scrollbar-width:none]">
|
||||
<button
|
||||
onClick={onFleetOrgClick}
|
||||
className={navItemClass(activeView === 'org')}
|
||||
aria-current={activeView === 'org' ? 'page' : undefined}
|
||||
data-testid="fleet-nav-org"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 4v4m0 4v4m-6-8h4m8 0h-4M6 16h12" />
|
||||
</svg>
|
||||
<span className="text-sm max-lg:text-[11px]">Fleet Org</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onFleetSandboxesClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'fleet-sandboxes')}`}
|
||||
aria-current={activeView === 'fleet-sandboxes' ? 'page' : undefined}
|
||||
data-testid="fleet-nav-sandboxes"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M3 8l9-5 9 5-9 5-9-5zM3 8v8l9 5 9-5V8M12 13v8" />
|
||||
</svg>
|
||||
<span className="text-sm max-lg:text-[11px]">Sandboxes</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onFleetTasksClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'tasks')}`}
|
||||
aria-current={activeView === 'tasks' ? 'page' : undefined}
|
||||
data-testid="fleet-nav-tasks"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M4 6h16M4 12h16M4 18h10" />
|
||||
</svg>
|
||||
<span className="text-sm max-lg:text-[11px]">Tasks</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onFleetMessagesClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'messages')}`}
|
||||
aria-current={activeView === 'messages' ? 'page' : undefined}
|
||||
data-testid="fleet-nav-messages"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M4 6h16v10H8l-4 4V6z" />
|
||||
</svg>
|
||||
<span className="text-sm max-lg:text-[11px]">Messages</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onFleetBoardClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'board')}`}
|
||||
aria-current={activeView === 'board' ? 'page' : undefined}
|
||||
data-testid="fleet-nav-board"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M4 5h5v5H4V5zm11 0h5v5h-5V5zM4 14h5v5H4v-5zm11 0h5v5h-5v-5z" />
|
||||
</svg>
|
||||
<span className="text-sm max-lg:text-[11px]">Kanban</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onFleetOwnerClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'owner')}`}
|
||||
aria-current={activeView === 'owner' ? 'page' : undefined}
|
||||
data-testid="fleet-nav-owner"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M5 12h14M12 5v14" />
|
||||
</svg>
|
||||
<span className="text-sm max-lg:text-[11px]">Owner</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onFleetApprovalsClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'approvals', true)}`}
|
||||
aria-current={activeView === 'approvals' ? 'page' : undefined}
|
||||
data-testid="fleet-nav-approvals"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M9 12l2 2 4-4m-8-5h10a2 2 0 012 2v10a2 2 0 01-2 2H7a2 2 0 01-2-2V7a2 2 0 012-2z" />
|
||||
</svg>
|
||||
<span className="text-sm max-lg:text-[11px]">Freigaben</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onFleetEscalationsClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'escalations', true)}`}
|
||||
aria-current={activeView === 'escalations' ? 'page' : undefined}
|
||||
data-testid="fleet-nav-escalations"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 3l9 16H3l9-16z M12 10v4m0 2v1" />
|
||||
</svg>
|
||||
<span className="text-sm max-lg:text-[11px]">Escalations</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onSandboxesClick}
|
||||
className={navItemClass(activeView === 'sandboxes' && !isCreateMode && !isDestroyMode)}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
/**
|
||||
* EscalationHistory — Kernfeature 4: HITL-/Escalation-Historie.
|
||||
* Journal-Filter type=escalation (Deadman-Alarm, Agent-Escalations) plus
|
||||
* rejected-Quarantine-Events. Poll 5 s. Kein psql — Spool ist die Wahrheit.
|
||||
*/
|
||||
|
||||
type JournalLine = {
|
||||
event?: string
|
||||
task_id?: string
|
||||
from?: string
|
||||
to?: string
|
||||
type?: string
|
||||
priority?: string
|
||||
time_epoch?: number
|
||||
errors?: string
|
||||
[k: string]: unknown
|
||||
}
|
||||
|
||||
export default function EscalationHistory() {
|
||||
const [esc, setEsc] = useState<JournalLine[]>([])
|
||||
const [rej, setRej] = useState<JournalLine[]>([])
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
const load = () => {
|
||||
fetch("/api/fleet/escalations", { cache: "no-store" })
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||
return res.json()
|
||||
})
|
||||
.then((d: { escalations: JournalLine[]; rejected: JournalLine[] }) => {
|
||||
if (cancelled) return
|
||||
setEsc(d.escalations)
|
||||
setRej(d.rejected)
|
||||
setError(null)
|
||||
})
|
||||
.catch((e: Error) => {
|
||||
if (!cancelled) setError(e.message)
|
||||
})
|
||||
}
|
||||
load()
|
||||
const timer = setInterval(load, 5000)
|
||||
return () => {
|
||||
cancelled = true
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const row = (l: JournalLine, kind: "esc" | "rej") => (
|
||||
<div
|
||||
key={`${l.task_id}-${l.time_epoch}-${kind}`}
|
||||
className="border-b border-[var(--border)] py-2 font-mono text-xs flex gap-3 items-baseline"
|
||||
data-fleet-escalation={kind}
|
||||
>
|
||||
<span className="text-[var(--foreground-dim)] w-36 shrink-0">
|
||||
{l.time_epoch ? new Date(l.time_epoch * 1000).toLocaleString("de-DE") : "--"}
|
||||
</span>
|
||||
<span className="w-20 shrink-0">{l.from || "system"}</span>
|
||||
<span className="text-[var(--foreground-dim)] w-4 shrink-0">→</span>
|
||||
<span className="w-16 shrink-0">{l.to || "-"}</span>
|
||||
<span className="w-8 shrink-0 text-[var(--status-stopped)]">{l.priority || ""}</span>
|
||||
<span className="truncate text-[var(--foreground-dim)]">{l.task_id?.slice(0, 8) || l.errors || ""}</span>
|
||||
</div>
|
||||
)
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="panel p-8 text-center" data-testid="fleet-escalations-error">
|
||||
<h3 className="text-sm font-semibold text-[var(--status-stopped)] uppercase tracking-wider">
|
||||
Journal nicht erreichbar
|
||||
</h3>
|
||||
<p className="text-xs text-[var(--foreground-dim)] mt-2 font-mono break-all">{error}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="panel p-4 flex items-center gap-4">
|
||||
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mr-auto">
|
||||
ESCALATIONS
|
||||
</h1>
|
||||
<span className="text-[10px] font-mono text-[var(--foreground-dim)]">
|
||||
{esc.length} Alarme · {rej.length} Quarantaene
|
||||
</span>
|
||||
</div>
|
||||
<div className="panel p-4">
|
||||
<h2 className="text-[10px] uppercase tracking-wider text-[var(--status-stopped)] mb-3">
|
||||
HITL-Alarme (type=escalation)
|
||||
</h2>
|
||||
{esc.length === 0 ? (
|
||||
<p className="text-xs text-[var(--foreground-dim)] font-mono py-4 text-center">
|
||||
Keine Alarme — alles ruhig
|
||||
</p>
|
||||
) : (
|
||||
esc.map((l) => row(l, "esc"))
|
||||
)}
|
||||
</div>
|
||||
<div className="panel p-4">
|
||||
<h2 className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] mb-3">
|
||||
Quarantaene (rejected/invalid)
|
||||
</h2>
|
||||
{rej.length === 0 ? (
|
||||
<p className="text-xs text-[var(--foreground-dim)] font-mono py-4 text-center">
|
||||
Keine abgelehnten Envelopes
|
||||
</p>
|
||||
) : (
|
||||
rej.map((l) => row(l, "rej"))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
/**
|
||||
* KanbanBoard — Kernfeature 3: VS-Auswahl, Spalten Neu/Bewertet/In Bau/Fertig
|
||||
* aus board-service (via /api/fleet/kanban), Poll 5 s (Statuswechsel <=10 s).
|
||||
*/
|
||||
|
||||
type Card = { id: string; titel: string; score: number; status: string; ursprung: string; erstellt: string }
|
||||
type KanbanData = {
|
||||
value_streams: string[]
|
||||
boards: Array<{ vs: string; board: { kanban: Record<string, Card[]> } }>
|
||||
generated_at: string
|
||||
}
|
||||
|
||||
const COLUMNS = ["Neu", "Bewertet", "In Bau", "Fertig"] as const
|
||||
|
||||
export default function KanbanBoard() {
|
||||
const [data, setData] = useState<KanbanData | null>(null)
|
||||
const [selectedVs, setSelectedVs] = useState<string>("")
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
const load = () => {
|
||||
fetch("/api/fleet/kanban", { cache: "no-store" })
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||
return res.json()
|
||||
})
|
||||
.then((d: KanbanData) => {
|
||||
if (cancelled) return
|
||||
setData(d)
|
||||
setError(null)
|
||||
if (!selectedVs && d.value_streams.length > 0) setSelectedVs(d.value_streams[0])
|
||||
})
|
||||
.catch((e: Error) => {
|
||||
if (!cancelled) setError(e.message)
|
||||
})
|
||||
}
|
||||
load()
|
||||
const timer = setInterval(load, 5000)
|
||||
return () => {
|
||||
cancelled = true
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, [selectedVs])
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="panel p-8 text-center" data-testid="fleet-kanban-error">
|
||||
<h3 className="text-sm font-semibold text-[var(--status-stopped)] uppercase tracking-wider">
|
||||
Board-Service 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-kanban-loading">
|
||||
<div className="text-xs text-[var(--foreground-dim)] font-mono uppercase tracking-wider">LADEN...</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const board = data.boards.find((b) => b.vs === selectedVs)
|
||||
const kanban = board?.board.kanban || { Neu: [], Bewertet: [], "In Bau": [], Fertig: [] }
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="panel p-4 flex flex-wrap gap-3 items-center">
|
||||
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mr-auto">
|
||||
KANBAN
|
||||
</h1>
|
||||
<select
|
||||
value={selectedVs}
|
||||
onChange={(e) => setSelectedVs(e.target.value)}
|
||||
className="bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||
data-testid="fleet-kanban-vs-select"
|
||||
>
|
||||
{data.value_streams.map((vs) => (
|
||||
<option key={vs} value={vs}>
|
||||
{vs}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="grid grid-cols-4 gap-4" data-testid="fleet-kanban-board">
|
||||
{COLUMNS.map((col) => (
|
||||
<div key={col} className="panel p-3 min-h-[300px]" data-fleet-kanban-column={col}>
|
||||
<div className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] mb-3 flex justify-between">
|
||||
<span>{col}</span>
|
||||
<span>{kanban[col]?.length || 0}</span>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
{(kanban[col] || []).map((c) => (
|
||||
<div key={c.id} className="bg-[var(--background-tertiary)] p-2 rounded-sm" data-fleet-kanban-card={c.id}>
|
||||
<div className="text-xs font-semibold truncate">{c.id}</div>
|
||||
<div className="text-[10px] text-[var(--foreground-dim)] truncate">{c.titel}</div>
|
||||
<div className="text-[10px] font-mono text-[var(--nvidia-green)] mt-1">
|
||||
score {c.score} · {c.ursprung}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useRef, useState } from "react"
|
||||
|
||||
/**
|
||||
* MessageFeed — Kernfeature 2: rollierendes Spool-Journal.
|
||||
* Zeigt from/to/priority/status je Eintrag; escalations rot hervorgehoben;
|
||||
* Filter nach type und agent. Poll 5 s mit Epoch-Cursor (nur neue Eintraege).
|
||||
*/
|
||||
|
||||
type JournalLine = {
|
||||
event?: string
|
||||
task_id?: string
|
||||
from?: string
|
||||
to?: string
|
||||
type?: string
|
||||
priority?: string
|
||||
status?: string
|
||||
file?: string
|
||||
time_epoch?: number
|
||||
errors?: string
|
||||
raw?: string
|
||||
[k: string]: unknown
|
||||
}
|
||||
|
||||
const EVENT_COLOR: Record<string, string> = {
|
||||
accepted: "var(--status-running)",
|
||||
rejected: "var(--status-stopped)",
|
||||
run_finished: "var(--nvidia-green)",
|
||||
escalation: "#e5534b",
|
||||
}
|
||||
|
||||
export default function MessageFeed() {
|
||||
const [lines, setLines] = useState<JournalLine[]>([])
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [typeFilter, setTypeFilter] = useState<string>("all")
|
||||
const [agentFilter, setAgentFilter] = useState<string>("all")
|
||||
const cursorRef = useRef(0)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
const load = () => {
|
||||
const url = `/api/fleet/messages?limit=200${cursorRef.current > 0 ? `&cursor=${cursorRef.current}` : ""}`
|
||||
fetch(url, { cache: "no-store" })
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||
return res.json()
|
||||
})
|
||||
.then((d: { messages: JournalLine[] }) => {
|
||||
if (cancelled) return
|
||||
if (d.messages.length > 0) {
|
||||
const maxEpoch = Math.max(...d.messages.map((m) => Number(m.time_epoch || 0)))
|
||||
if (maxEpoch > cursorRef.current) cursorRef.current = maxEpoch
|
||||
setLines((prev) => {
|
||||
const seen = new Set(prev.map((l) => `${l.task_id}:${l.event}:${l.time_epoch}`))
|
||||
const fresh = d.messages.filter((l) => !seen.has(`${l.task_id}:${l.event}:${l.time_epoch}`))
|
||||
return [...prev, ...fresh].slice(-500)
|
||||
})
|
||||
}
|
||||
setError(null)
|
||||
})
|
||||
.catch((e: Error) => {
|
||||
if (!cancelled) setError(e.message)
|
||||
})
|
||||
}
|
||||
load()
|
||||
const timer = setInterval(load, 5000)
|
||||
return () => {
|
||||
cancelled = true
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const visible = lines.filter((l) => {
|
||||
if (typeFilter !== "all" && l.type !== typeFilter && l.event !== typeFilter) return false
|
||||
if (agentFilter !== "all" && l.from !== agentFilter && l.to !== agentFilter) return false
|
||||
return true
|
||||
})
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="panel p-8 text-center" data-testid="fleet-messages-error">
|
||||
<h3 className="text-sm font-semibold text-[var(--status-stopped)] uppercase tracking-wider">
|
||||
Spool-Journal nicht erreichbar
|
||||
</h3>
|
||||
<p className="text-xs text-[var(--foreground-dim)] mt-2 font-mono break-all">{error}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="panel p-4 flex flex-wrap gap-3 items-center">
|
||||
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mr-auto">
|
||||
MESSAGES
|
||||
</h1>
|
||||
<select
|
||||
value={typeFilter}
|
||||
onChange={(e) => setTypeFilter(e.target.value)}
|
||||
className="bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||
data-testid="fleet-msg-type-filter"
|
||||
>
|
||||
{["all", "escalation", "chat", "build", "review", "vote", "fyi", "accepted", "rejected", "run_finished"].map(
|
||||
(t) => (
|
||||
<option key={t} value={t}>
|
||||
{t}
|
||||
</option>
|
||||
)
|
||||
)}
|
||||
</select>
|
||||
<select
|
||||
value={agentFilter}
|
||||
onChange={(e) => setAgentFilter(e.target.value)}
|
||||
className="bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||
data-testid="fleet-msg-agent-filter"
|
||||
>
|
||||
{["all", "ceo", "cto", "ciso", "chro", "coo", "cmo", "agile-coach", "research", "devops"].map((a) => (
|
||||
<option key={a} value={a}>
|
||||
{a}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] font-mono">{visible.length} Eintraege</span>
|
||||
</div>
|
||||
<div className="panel p-4 max-h-[70vh] overflow-y-auto" data-testid="fleet-message-feed">
|
||||
{visible.length === 0 && (
|
||||
<p className="text-xs text-[var(--foreground-dim)] font-mono py-8 text-center">
|
||||
Keine Eintraege (Filter oder wartet auf ersten Task)
|
||||
</p>
|
||||
)}
|
||||
{visible.map((l, i) => {
|
||||
const key = `${l.task_id}-${l.event}-${l.time_epoch}-${i}`
|
||||
const isEsc = l.type === "escalation" || l.event === "rejected"
|
||||
return (
|
||||
<div
|
||||
key={key}
|
||||
className="border-b border-[var(--border)] py-2 font-mono text-xs flex gap-3 items-baseline"
|
||||
data-fleet-message={l.event}
|
||||
style={isEsc ? { borderLeft: "3px solid #e5534b", paddingLeft: "8px" } : undefined}
|
||||
>
|
||||
<span className="text-[var(--foreground-dim)] w-20 shrink-0">
|
||||
{l.time_epoch ? new Date(l.time_epoch * 1000).toLocaleTimeString("de-DE") : "--:--"}
|
||||
</span>
|
||||
<span style={{ color: EVENT_COLOR[l.event || ""] || "var(--foreground)" }} className="w-24 shrink-0">
|
||||
{l.event || "?"}
|
||||
</span>
|
||||
<span className="w-16 shrink-0">{l.from || "system"}</span>
|
||||
<span className="text-[var(--foreground-dim)] w-4 shrink-0">→</span>
|
||||
<span className="w-16 shrink-0">{l.to || "-"}</span>
|
||||
<span className="w-10 shrink-0 text-[var(--foreground-dim)]">{l.priority || ""}</span>
|
||||
<span className="w-16 shrink-0 text-[var(--foreground-dim)]">{l.type || ""}</span>
|
||||
<span className="w-20 shrink-0 text-[var(--foreground-dim)]">{l.status || ""}</span>
|
||||
<span className="truncate text-[var(--foreground-dim)]">{l.task_id?.slice(0, 8) || l.file || l.raw || ""}</span>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
"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>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
/**
|
||||
* OwnerApprovals — NAR-Freigaben (Kernfeature 5 / NAR-Verfahren §1.3).
|
||||
* Liste der Owner-Inbox-Tasks (an tower-owner), Detail-Ansicht je Antrag mit
|
||||
* geparsten Pflichtfeldern (Antragsteller / Ziel / Protokoll / Zweck / Dauer /
|
||||
* Alternativen) + CISO-Bewertung, Approve/Decline mit Notizfeld.
|
||||
* Bescheid geht via board-service decide_owner_task an den Antragsteller.
|
||||
* Poll 5 s, fail loud.
|
||||
*/
|
||||
|
||||
type OwnerTask = {
|
||||
task_id: string
|
||||
from: string
|
||||
type: string
|
||||
priority: string
|
||||
status: string
|
||||
created?: number
|
||||
topic?: string
|
||||
body?: string
|
||||
}
|
||||
|
||||
type ParsedNar = {
|
||||
antragsteller: string
|
||||
ziel: string
|
||||
protokoll: string
|
||||
zweck: string
|
||||
dauer: string
|
||||
alternativen: string
|
||||
bewertung: string
|
||||
empfehlung: string
|
||||
}
|
||||
|
||||
function section(body: string, startMark: string, endMarks: string[]): string {
|
||||
const s = body.indexOf(startMark)
|
||||
if (s === -1) return ""
|
||||
let end = body.length
|
||||
for (const m of endMarks) {
|
||||
const i = body.indexOf(m, s + startMark.length)
|
||||
if (i !== -1 && i < end) end = i
|
||||
}
|
||||
return body.slice(s, end).trim()
|
||||
}
|
||||
|
||||
function field(src: string, label: string): string {
|
||||
const re = new RegExp(`${label}:\\s*(.*)`)
|
||||
const m = src.match(re)
|
||||
return (m ? m[1] : "").trim()
|
||||
}
|
||||
|
||||
function parseNar(body: string, from: string): ParsedNar {
|
||||
const antrag = section(body, "Antragsteller:", [
|
||||
"\nZiel:", "\nProtokoll:", "\nZweck:", "\nDauer:", "\nAlternativen:",
|
||||
])
|
||||
const ziel = section(body, "Ziel:", ["\nProtokoll:", "\nZweck:", "\nDauer:", "\nAlternativen:"])
|
||||
const protokoll = section(body, "Protokoll:", ["\nZweck:", "\nDauer:", "\nAlternativen:"])
|
||||
const zweck = section(body, "Zweck:", ["\nDauer:", "\nAlternativen:"])
|
||||
const dauer = section(body, "Dauer:", ["\nAlternativen:"])
|
||||
const alternativen = section(body, "Alternativen:", ["\n---"])
|
||||
const bewertung = section(body, "--- CISO-BEWERTUNG ---", ["\n--- EMPFEHLUNG"])
|
||||
const empfehlung = body.includes("--- EMPFEHLUNG")
|
||||
? body.slice(body.indexOf("--- EMPFEHLUNG")).trim()
|
||||
: ""
|
||||
return {
|
||||
antragsteller: field(antrag, "Antragsteller") || from,
|
||||
ziel: field(ziel, "Ziel"),
|
||||
protokoll: field(protokoll, "Protokoll"),
|
||||
zweck: zweck.replace(/^Zweck:\s*/, "").trim(),
|
||||
dauer: field(dauer, "Dauer"),
|
||||
alternativen: alternativen.replace(/^Alternativen:\s*/, "").trim(),
|
||||
bewertung,
|
||||
empfehlung,
|
||||
}
|
||||
}
|
||||
|
||||
const InfoRow = ({ label, value }: { label: string; value: string }) => (
|
||||
<div className="flex gap-3 items-baseline">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] w-28 shrink-0">
|
||||
{label}
|
||||
</span>
|
||||
<span className="text-xs font-mono break-all">{value || "—"}</span>
|
||||
</div>
|
||||
)
|
||||
|
||||
export default function OwnerApprovals() {
|
||||
const [tasks, setTasks] = useState<OwnerTask[]>([])
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [selected, setSelected] = useState<string | null>(null)
|
||||
const [note, setNote] = useState("")
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [feedback, setFeedback] = useState<{ ok: boolean; msg: string } | null>(null)
|
||||
|
||||
const load = () => {
|
||||
fetch("/api/fleet/owner/inbox", { cache: "no-store" })
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||
return res.json()
|
||||
})
|
||||
.then((d: { tasks: OwnerTask[] }) => {
|
||||
setTasks(d.tasks || [])
|
||||
setError(null)
|
||||
})
|
||||
.catch((e: Error) => setError(e.message))
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load()
|
||||
const timer = setInterval(load, 5000)
|
||||
return () => clearInterval(timer)
|
||||
}, [])
|
||||
|
||||
const decide = (decision: "approve" | "decline") => {
|
||||
if (!selected || busy) return
|
||||
setBusy(true)
|
||||
setFeedback(null)
|
||||
fetch("/api/fleet/owner/decide", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ task_id: selected, decision, note }),
|
||||
})
|
||||
.then(async (res) => {
|
||||
const body = await res.json()
|
||||
if (!res.ok) throw new Error(body.error || `HTTP ${res.status}`)
|
||||
return body
|
||||
})
|
||||
.then((d) => {
|
||||
const ft = d.folge_task?.task?.task_id || d.folge_task?.task_id || "?"
|
||||
setFeedback({
|
||||
ok: true,
|
||||
msg: `${decision === "approve" ? "Freigegeben" : "Abgelehnt"} — Bescheid-Task ${String(ft).slice(0, 8)} an ${d.antragsteller}`,
|
||||
})
|
||||
setNote("")
|
||||
setSelected(null)
|
||||
setTimeout(load, 500)
|
||||
})
|
||||
.catch((e: Error) => setFeedback({ ok: false, msg: e.message }))
|
||||
.finally(() => setBusy(false))
|
||||
}
|
||||
|
||||
const open = tasks.filter((t) => t.status === "submitted")
|
||||
const done = tasks.filter((t) => t.status !== "submitted")
|
||||
const current = tasks.find((t) => t.task_id === selected)
|
||||
const nar = current ? parseNar(current.body || "", current.from) : null
|
||||
|
||||
const row = (t: OwnerTask, isDone: boolean) => (
|
||||
<button
|
||||
key={t.task_id}
|
||||
onClick={() => {
|
||||
setSelected(t.task_id)
|
||||
setFeedback(null)
|
||||
}}
|
||||
className={`w-full text-left px-3 py-2 rounded-sm border-b border-[var(--border)] text-xs font-mono ${
|
||||
selected === t.task_id ? "bg-[var(--background-panel)]" : "hover:bg-[var(--background-tertiary)]"
|
||||
}`}
|
||||
data-testid="fleet-approval-row"
|
||||
data-status={t.status}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className="w-8 shrink-0"
|
||||
style={{ color: isDone ? "var(--foreground-dim)" : "var(--status-stopped)" }}
|
||||
>
|
||||
{t.priority}
|
||||
</span>
|
||||
<span className="w-20 shrink-0 truncate">{t.from}</span>
|
||||
<span className="flex-1 truncate text-[var(--foreground-dim)]">{t.topic}</span>
|
||||
<span className="shrink-0 text-[10px] text-[var(--foreground-dim)]">
|
||||
{t.status === "submitted" ? "OFFEN" : t.status}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="panel p-4 flex items-center gap-4">
|
||||
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mr-auto">
|
||||
FREIGABEN
|
||||
</h1>
|
||||
<span className="text-[10px] font-mono text-[var(--foreground-dim)]">
|
||||
{open.length} offen · {done.length} entschieden
|
||||
</span>
|
||||
{feedback && (
|
||||
<span
|
||||
className="text-xs font-mono"
|
||||
style={{ color: feedback.ok ? "var(--status-running)" : "var(--status-stopped)" }}
|
||||
data-testid="fleet-approval-feedback"
|
||||
>
|
||||
{feedback.msg}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{error && (
|
||||
<div className="panel p-4 border-l-4 border-[var(--status-stopped)]">
|
||||
<p className="text-xs font-mono text-[var(--status-stopped)] break-all">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid grid-cols-[400px_1fr] gap-4 max-lg:grid-cols-1">
|
||||
<div className="panel p-2" data-testid="fleet-approval-list">
|
||||
<h2 className="text-[10px] uppercase tracking-wider text-[var(--status-stopped)] px-2 py-1">
|
||||
Offene Anträge
|
||||
</h2>
|
||||
{open.length === 0 ? (
|
||||
<p className="text-xs text-[var(--foreground-dim)] font-mono py-4 text-center">
|
||||
Keine offenen Anträge
|
||||
</p>
|
||||
) : (
|
||||
open.map((t) => row(t, false))
|
||||
)}
|
||||
{done.length > 0 && (
|
||||
<h2 className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] px-2 py-1 mt-2">
|
||||
Entscheidungs-Historie
|
||||
</h2>
|
||||
)}
|
||||
{done.map((t) => row(t, true))}
|
||||
</div>
|
||||
<div className="panel p-4 min-h-[400px]" data-testid="fleet-approval-detail">
|
||||
{current && nar ? (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||
{current.type} · {current.priority}
|
||||
</span>
|
||||
<span className="text-xs font-mono font-semibold">{current.topic}</span>
|
||||
{current.status !== "submitted" && (
|
||||
<span className="text-[10px] font-mono text-[var(--foreground-dim)] ml-auto">
|
||||
{current.status}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-2 border-l-2 border-[var(--border)] pl-4">
|
||||
<h3 className="text-[10px] uppercase tracking-wider text-[var(--nvidia-green)]">
|
||||
Wer braucht Zugriff worauf?
|
||||
</h3>
|
||||
<InfoRow label="Antragsteller" value={nar.antragsteller} />
|
||||
<InfoRow label="Ziel" value={nar.ziel} />
|
||||
<InfoRow label="Protokoll" value={nar.protokoll} />
|
||||
<h3 className="text-[10px] uppercase tracking-wider text-[var(--nvidia-green)] pt-2">
|
||||
Wofür / Wie lange?
|
||||
</h3>
|
||||
<InfoRow label="Zweck" value={nar.zweck} />
|
||||
<InfoRow label="Dauer" value={nar.dauer} />
|
||||
<InfoRow label="Alternativen" value={nar.alternativen} />
|
||||
</div>
|
||||
{nar.bewertung && (
|
||||
<div className="border-l-2 border-[var(--status-stopped)] pl-4 space-y-1">
|
||||
<h3 className="text-[10px] uppercase tracking-wider text-[var(--status-stopped)]">
|
||||
CISO-Bewertung
|
||||
</h3>
|
||||
<pre className="text-[11px] font-mono whitespace-pre-wrap text-[var(--foreground-dim)] max-h-48 overflow-y-auto">
|
||||
{nar.bewertung}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
{nar.empfehlung && (
|
||||
<div className="border-l-2 border-[var(--nvidia-green)] pl-4 space-y-1">
|
||||
<h3 className="text-[10px] uppercase tracking-wider text-[var(--nvidia-green)]">
|
||||
Empfehlung des CISO
|
||||
</h3>
|
||||
<pre className="text-[11px] font-mono whitespace-pre-wrap text-[var(--foreground-dim)] max-h-56 overflow-y-auto">
|
||||
{nar.empfehlung}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
{current.status === "submitted" ? (
|
||||
<div className="space-y-3 pt-2" data-testid="fleet-approval-actions">
|
||||
<textarea
|
||||
value={note}
|
||||
onChange={(e) => setNote(e.target.value)}
|
||||
placeholder="Bedingungen / Begründung (optional, geht an den Antragsteller)..."
|
||||
className="w-full bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm min-h-[60px]"
|
||||
/>
|
||||
<div className="flex gap-2 justify-end">
|
||||
<button
|
||||
onClick={() => decide("decline")}
|
||||
disabled={busy}
|
||||
className="px-4 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--status-stopped)] text-black font-semibold disabled:opacity-50"
|
||||
data-testid="fleet-approval-decline"
|
||||
>
|
||||
Ablehnen
|
||||
</button>
|
||||
<button
|
||||
onClick={() => decide("approve")}
|
||||
disabled={busy}
|
||||
className="px-4 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--nvidia-green)] text-black font-semibold disabled:opacity-50"
|
||||
data-testid="fleet-approval-approve"
|
||||
>
|
||||
Freigeben
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs font-mono text-[var(--foreground-dim)]">
|
||||
Entscheidung getroffen — Bescheid ist an den Antragsteller gegangen.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs text-[var(--foreground-dim)] font-mono m-auto">
|
||||
Antrag auswählen
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useRef, useState } from "react"
|
||||
|
||||
/**
|
||||
* OwnerPanel — Kernfeature 5 (E-V3): Owner-Eingabekanaele.
|
||||
* 1) Ideen-Formular -> add_backlog_card (ursprung=owner)
|
||||
* 2) "Neuer Value Stream" -> CEO-Task (type=build, P2)
|
||||
* 3) CEO-Chat mit Threads (type=chat, thread_id) — Chat verdraengt nie Task-Flow.
|
||||
* Fail loud: Fehler des board-service/Spool als Klartext im Panel.
|
||||
*/
|
||||
|
||||
type Thread = {
|
||||
thread_id: string
|
||||
topic: string
|
||||
messages: Array<{ task_id: string; from: string; to: string; body: string; created: number }>
|
||||
}
|
||||
|
||||
export default function OwnerPanel() {
|
||||
const [threads, setThreads] = useState<Thread[]>([])
|
||||
const [vsList, setVsList] = useState<string[]>([])
|
||||
const [activeThread, setActiveThread] = useState<string | null>(null)
|
||||
const [feedback, setFeedback] = useState<{ ok: boolean; msg: string } | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
// Idee-Formular
|
||||
const [ideaVs, setIdeaVs] = useState("")
|
||||
const [ideaTitle, setIdeaTitle] = useState("")
|
||||
const [ideaWert, setIdeaWert] = useState("7")
|
||||
const [ideaMach, setIdeaMach] = useState("7")
|
||||
// VS-Formular
|
||||
const [vsTopic, setVsTopic] = useState("")
|
||||
const [vsZiel, setVsZiel] = useState("")
|
||||
// Chat
|
||||
const [chatMsg, setChatMsg] = useState("")
|
||||
const chatBottomRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const loadThreads = () => {
|
||||
fetch("/api/fleet/owner/chat", { cache: "no-store" })
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||
return res.json()
|
||||
})
|
||||
.then((d: { threads: Thread[] }) => {
|
||||
setThreads(d.threads)
|
||||
setError(null)
|
||||
})
|
||||
.catch((e: Error) => setError(e.message))
|
||||
}
|
||||
const loadVs = () => {
|
||||
fetch("/api/fleet/kanban", { cache: "no-store" })
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||
return res.json()
|
||||
})
|
||||
.then((d: { value_streams: string[] }) => setVsList(d.value_streams))
|
||||
.catch((e: Error) => setError(e.message))
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
loadThreads()
|
||||
loadVs()
|
||||
const timer = setInterval(() => {
|
||||
loadThreads()
|
||||
}, 5000)
|
||||
return () => clearInterval(timer)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
chatBottomRef.current?.scrollIntoView({ behavior: "smooth" })
|
||||
}, [threads, activeThread])
|
||||
|
||||
const post = (url: string, payload: unknown, okMsg: (d: unknown) => string) => {
|
||||
setFeedback(null)
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
.then(async (res) => {
|
||||
const body = await res.json()
|
||||
if (!res.ok) throw new Error(body.error || `HTTP ${res.status}`)
|
||||
return body
|
||||
})
|
||||
.then((d) => setFeedback({ ok: true, msg: okMsg(d) }))
|
||||
.catch((e: Error) => setFeedback({ ok: false, msg: e.message }))
|
||||
}
|
||||
|
||||
const submitIdea = () => {
|
||||
if (!ideaVs || !ideaTitle.trim()) {
|
||||
setFeedback({ ok: false, msg: "VS und Titel sind Pflicht" })
|
||||
return
|
||||
}
|
||||
const id = `owner-${Date.now().toString(36)}`
|
||||
post(
|
||||
"/api/fleet/owner/idea",
|
||||
{ vs: ideaVs, karte_id: id, titel: ideaTitle, wert: Number(ideaWert), machbarkeit: Number(ideaMach) },
|
||||
() => `Idee als Backlog-Karte '${id}' angelegt (Neu)`
|
||||
)
|
||||
setIdeaTitle("")
|
||||
}
|
||||
|
||||
const submitNewVs = () => {
|
||||
if (!vsTopic.trim()) {
|
||||
setFeedback({ ok: false, msg: "Topic ist Pflicht" })
|
||||
return
|
||||
}
|
||||
post(
|
||||
"/api/fleet/owner/new-vs",
|
||||
{ topic: vsTopic, ziel: vsZiel },
|
||||
(d) => `VS-Gruendung als CEO-Task eingelegt (task_id ${(d as { task?: { task_id?: string } }).task?.task_id?.slice(0, 8) || "ok"})`
|
||||
)
|
||||
setVsTopic("")
|
||||
setVsZiel("")
|
||||
}
|
||||
|
||||
const startThread = () => {
|
||||
const tid = `owner-chat-${Date.now().toString(36)}`
|
||||
setActiveThread(tid)
|
||||
setThreads((prev) => [
|
||||
...prev,
|
||||
{ thread_id: tid, topic: `Owner-Chat ${new Date().toLocaleString("de-DE")}`, messages: [] },
|
||||
])
|
||||
}
|
||||
|
||||
const sendChat = () => {
|
||||
if (!activeThread || !chatMsg.trim()) return
|
||||
post(
|
||||
"/api/fleet/owner/chat",
|
||||
{ thread_id: activeThread, topic: threads.find((t) => t.thread_id === activeThread)?.topic, message: chatMsg },
|
||||
() => "gesendet"
|
||||
)
|
||||
setChatMsg("")
|
||||
setTimeout(loadThreads, 800)
|
||||
}
|
||||
|
||||
const current = threads.find((t) => t.thread_id === activeThread)
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="panel p-4 flex items-center gap-4">
|
||||
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mr-auto">
|
||||
OWNER KANAELE
|
||||
</h1>
|
||||
{feedback && (
|
||||
<span
|
||||
className="text-xs font-mono"
|
||||
style={{ color: feedback.ok ? "var(--status-running)" : "var(--status-stopped)" }}
|
||||
data-testid="fleet-owner-feedback"
|
||||
>
|
||||
{feedback.msg}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{error && (
|
||||
<div className="panel p-4 border-l-4 border-[var(--status-stopped)]">
|
||||
<p className="text-xs font-mono text-[var(--status-stopped)] break-all">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="panel p-4 space-y-3" data-testid="fleet-owner-idea-form">
|
||||
<h2 className="text-xs uppercase tracking-wider text-[var(--foreground-dim)]">Idee ins VS-Backlog</h2>
|
||||
<select
|
||||
value={ideaVs}
|
||||
onChange={(e) => setIdeaVs(e.target.value)}
|
||||
className="w-full bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||
>
|
||||
<option value="">Value Stream...</option>
|
||||
{vsList.map((v) => (
|
||||
<option key={v} value={v}>
|
||||
{v}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
value={ideaTitle}
|
||||
onChange={(e) => setIdeaTitle(e.target.value)}
|
||||
placeholder="Titel der Idee"
|
||||
className="w-full bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||
/>
|
||||
<div className="flex gap-2">
|
||||
<label className="text-[10px] text-[var(--foreground-dim)] flex items-center gap-1">
|
||||
Wert
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={10}
|
||||
value={ideaWert}
|
||||
onChange={(e) => setIdeaWert(e.target.value)}
|
||||
className="w-14 bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="text-[10px] text-[var(--foreground-dim)] flex items-center gap-1">
|
||||
Machbarkeit
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={10}
|
||||
value={ideaMach}
|
||||
onChange={(e) => setIdeaMach(e.target.value)}
|
||||
className="w-14 bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
onClick={submitIdea}
|
||||
className="ml-auto px-3 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--nvidia-green)] text-black font-semibold"
|
||||
data-testid="fleet-owner-idea-submit"
|
||||
>
|
||||
Anlegen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="panel p-4 space-y-3" data-testid="fleet-owner-newvs-form">
|
||||
<h2 className="text-xs uppercase tracking-wider text-[var(--foreground-dim)]">Neuer Value Stream</h2>
|
||||
<input
|
||||
value={vsTopic}
|
||||
onChange={(e) => setVsTopic(e.target.value)}
|
||||
placeholder="Topic (z.B. 'Imkerei-Website 2.0')"
|
||||
className="w-full bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||
/>
|
||||
<input
|
||||
value={vsZiel}
|
||||
onChange={(e) => setVsZiel(e.target.value)}
|
||||
placeholder="Ziel (optional)"
|
||||
className="w-full bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||
/>
|
||||
<button
|
||||
onClick={submitNewVs}
|
||||
className="px-3 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--nvidia-green)] text-black font-semibold"
|
||||
data-testid="fleet-owner-newvs-submit"
|
||||
>
|
||||
CEO-Task anlegen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-[280px_1fr] gap-4">
|
||||
<div className="panel p-3 space-y-2" data-testid="fleet-owner-thread-list">
|
||||
<button
|
||||
onClick={startThread}
|
||||
className="w-full px-3 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--nvidia-green)] text-black font-semibold"
|
||||
>
|
||||
Neuer Chat-Thread
|
||||
</button>
|
||||
{threads.map((t) => (
|
||||
<button
|
||||
key={t.thread_id}
|
||||
onClick={() => setActiveThread(t.thread_id)}
|
||||
className={`w-full text-left px-2 py-1 rounded-sm text-xs font-mono truncate ${
|
||||
activeThread === t.thread_id ? "bg-[var(--background-panel)]" : "hover:bg-[var(--background-tertiary)]"
|
||||
}`}
|
||||
>
|
||||
{t.topic || t.thread_id}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="panel p-4 flex flex-col min-h-[360px]" data-testid="fleet-owner-chat-panel">
|
||||
{current ? (
|
||||
<>
|
||||
<div className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] mb-3">
|
||||
{current.topic || current.thread_id}
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto space-y-2">
|
||||
{current.messages.map((m) => (
|
||||
<div
|
||||
key={m.task_id}
|
||||
className="flex"
|
||||
data-fleet-chat-message={m.from}
|
||||
style={{ justifyContent: m.from === "tower-owner" ? "flex-end" : "flex-start" }}
|
||||
>
|
||||
<div
|
||||
className="max-w-[70%] p-2 rounded-sm text-xs font-mono"
|
||||
style={{
|
||||
background:
|
||||
m.from === "tower-owner" ? "var(--background-panel)" : "var(--background-tertiary)",
|
||||
}}
|
||||
>
|
||||
<div className="text-[9px] text-[var(--foreground-dim)] mb-1">{m.from}</div>
|
||||
{m.body}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div ref={chatBottomRef} />
|
||||
</div>
|
||||
<div className="flex gap-2 mt-3">
|
||||
<input
|
||||
value={chatMsg}
|
||||
onChange={(e) => setChatMsg(e.target.value)}
|
||||
onKeyDown={(e) => e.key === "Enter" && sendChat()}
|
||||
placeholder="Nachricht an CEO..."
|
||||
className="flex-1 bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||
/>
|
||||
<button
|
||||
onClick={sendChat}
|
||||
className="px-3 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--nvidia-green)] text-black font-semibold"
|
||||
data-testid="fleet-owner-chat-send"
|
||||
>
|
||||
Senden
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-xs text-[var(--foreground-dim)] font-mono m-auto">
|
||||
Thread auswaehlen oder neu anlegen
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
"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<SandboxesData | null>(null)
|
||||
const [error, setError] = useState<string | null>(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 (
|
||||
<div className="panel p-8 text-center" data-testid="fleet-sandboxes-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-sandboxes-loading">
|
||||
<div className="text-xs text-[var(--foreground-dim)] font-mono uppercase tracking-wider">Lade Sandboxes…</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const running = data.agents.filter((a) => a.phase === "Running" && a.ready).length
|
||||
|
||||
return (
|
||||
<div className="space-y-4" data-testid="fleet-sandboxes-view">
|
||||
<div className="flex items-center justify-between flex-wrap gap-2">
|
||||
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider">Sandboxes</h1>
|
||||
<div className="flex items-center gap-3 text-xs font-mono text-[var(--foreground-dim)]">
|
||||
<span data-testid="fleet-sandboxes-count">
|
||||
{running}/{data.agents.length} running
|
||||
</span>
|
||||
<span
|
||||
className="px-2 py-0.5 rounded"
|
||||
style={{
|
||||
backgroundColor: data.all_running ? "rgba(118,185,0,0.15)" : "rgba(255,107,107,0.15)",
|
||||
color: data.all_running ? "var(--status-running)" : "var(--status-stopped)",
|
||||
}}
|
||||
>
|
||||
{data.all_running ? "ALLE GRÜN" : "DEGRADED"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel p-4">
|
||||
<div className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">Fleet Image (digest-gepinnt)</div>
|
||||
<div className="text-xs font-mono text-[var(--foreground)] mt-1" data-testid="fleet-sandboxes-image">
|
||||
{fmtDigest(data.fleet_image_digest)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4">
|
||||
{data.agents.map((agent) => {
|
||||
const ph = phaseColor(agent)
|
||||
const hb = hbColor(agent.heartbeat_age_s)
|
||||
return (
|
||||
<div key={agent.agent_id} className="panel p-4" data-testid={`fleet-sandbox-${agent.agent_id}`}>
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<div className="text-sm font-semibold text-[var(--foreground)] font-mono">{agent.agent_id}</div>
|
||||
<div className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">{agent.role}</div>
|
||||
</div>
|
||||
<span
|
||||
className="text-[10px] font-mono px-2 py-0.5 rounded uppercase"
|
||||
style={{ backgroundColor: "rgba(255,255,255,0.06)", color: ph.color }}
|
||||
data-testid={`fleet-sandbox-phase-${agent.agent_id}`}
|
||||
>
|
||||
{ph.label}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-x-4 gap-y-1 mt-3 text-xs">
|
||||
<span className="text-[var(--foreground-dim)]">Node</span>
|
||||
<span className="font-mono text-right text-[var(--foreground)]">{agent.node || "—"}</span>
|
||||
|
||||
<span className="text-[var(--foreground-dim)]">Pod-Age</span>
|
||||
<span className="font-mono text-right text-[var(--foreground)]">
|
||||
{agent.pod_age_s === null ? "—" : fmtAge(agent.pod_age_s)}
|
||||
</span>
|
||||
|
||||
<span className="text-[var(--foreground-dim)]">Restarts</span>
|
||||
<span
|
||||
className="font-mono text-right"
|
||||
style={{ color: agent.restarts && agent.restarts > 0 ? "#e6b450" : "var(--foreground)" }}
|
||||
>
|
||||
{agent.restarts ?? "—"}
|
||||
</span>
|
||||
|
||||
<span className="text-[var(--foreground-dim)]">Requests</span>
|
||||
<span className="font-mono text-right text-[var(--foreground)]">
|
||||
{agent.cpu_request_milli ? `${agent.cpu_request_milli}m / ${agent.mem_request_mb}Mi` : "—"}
|
||||
</span>
|
||||
|
||||
<span className="text-[var(--foreground-dim)]">Heartbeat</span>
|
||||
<span className="font-mono text-right" style={{ color: hb.color }} data-testid={`fleet-sandbox-hb-${agent.agent_id}`}>
|
||||
{hb.label}
|
||||
</span>
|
||||
|
||||
<span className="text-[var(--foreground-dim)]">Image</span>
|
||||
<span className="font-mono text-right text-[var(--foreground-dim)]">{fmtDigest(agent.image_digest)}</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="text-[10px] text-[var(--foreground-dim)] font-mono">
|
||||
Stand: {new Date(data.generated_at).toLocaleTimeString("de-DE")} · Quelle: kube-state-metrics via Prometheus (read-only)
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,396 @@
|
||||
"use client"
|
||||
|
||||
/**
|
||||
* TaskBrowser — Task-Detail-Ansicht im Tower (Karte tower-task-detail).
|
||||
*
|
||||
* Drei Listen aus /api/fleet/tasks:
|
||||
* - Spool-Reifegrad (offene submitted/working, Alter)
|
||||
* - Dead-Letter (failed der letzten 7 Tage)
|
||||
* - Alarm-Feed (Stoerungsereignisse aus dem Journal)
|
||||
* Klick auf eine Zeile -> /api/fleet/task-detail?id=... -> Modal mit vollem
|
||||
* Envelope (from/to/type/status/priority/created/Alter/topic/thread/karte/body).
|
||||
* Body unredigiert (Change-Order Abnahme 3; React escaped beim Rendern).
|
||||
* Polt 30 s; degradierte Quelle -> Banner statt Leeranzeige.
|
||||
*/
|
||||
import { useCallback, useEffect, useRef, useState } from "react"
|
||||
|
||||
type TaskEnvelope = {
|
||||
task_id: string
|
||||
from: string
|
||||
to: string
|
||||
type: string
|
||||
status: string
|
||||
priority: string
|
||||
created: number | null
|
||||
created_iso: string
|
||||
age_seconds: number | null
|
||||
age_human: string
|
||||
topic: string
|
||||
body: string
|
||||
thread_id: string
|
||||
karte_id: string
|
||||
reply_to: string
|
||||
vs: string
|
||||
claimed_at: string
|
||||
status_label: string
|
||||
file: string
|
||||
}
|
||||
|
||||
type AlarmRow = {
|
||||
time_epoch: number | null
|
||||
time_iso: string
|
||||
age_human: string
|
||||
event: string
|
||||
ref: string
|
||||
from: string
|
||||
to: string
|
||||
task_id: string
|
||||
note: string
|
||||
}
|
||||
|
||||
type TaskOverview = {
|
||||
generated_at: string
|
||||
spool: TaskEnvelope[]
|
||||
dead_letter: TaskEnvelope[]
|
||||
alarm: AlarmRow[]
|
||||
counts: { spool: number; dead_letter: number; alarm: number }
|
||||
degraded: boolean
|
||||
degraded_reason: string
|
||||
}
|
||||
|
||||
type TaskDetail = {
|
||||
generated_at: string
|
||||
found: boolean
|
||||
query_task_id: string
|
||||
entry_kind: string
|
||||
task: Record<string, string | number | null>
|
||||
missing_fields: string[]
|
||||
raw_keys: string[]
|
||||
body_note: string
|
||||
degraded: boolean
|
||||
degraded_reason: string
|
||||
error: string
|
||||
}
|
||||
|
||||
type Tab = "spool" | "dead-letter" | "alarm"
|
||||
|
||||
const REFRESH_MS = 30000
|
||||
const AGING_ALERT_S = 5400
|
||||
|
||||
const DETAIL_FIELDS: Array<[string, string]> = [
|
||||
["task_id", "Task-ID"],
|
||||
["status_label", "Status"],
|
||||
["from", "Von"],
|
||||
["to", "An"],
|
||||
["type", "Typ"],
|
||||
["priority", "Prio"],
|
||||
["created_iso", "Erstellt (ISO)"],
|
||||
["age_human", "Alter"],
|
||||
["topic", "Thema"],
|
||||
["thread_id", "Thread-ID"],
|
||||
["karte_id", "Karte"],
|
||||
["reply_to", "Antwort an"],
|
||||
["vs", "Value-Stream"],
|
||||
["claimed_at", "Geclaimt"],
|
||||
]
|
||||
|
||||
function ageClass(seconds: number | null): string {
|
||||
if (seconds === null) return "text-[var(--foreground-dim)]"
|
||||
if (seconds > AGING_ALERT_S) return "text-[var(--status-stopped)] font-semibold"
|
||||
if (seconds > 900) return "text-amber-400"
|
||||
return "text-[var(--foreground-dim)]"
|
||||
}
|
||||
|
||||
function prioClass(p: string): string {
|
||||
switch (p) {
|
||||
case "P1": return "text-[var(--status-stopped)] font-semibold"
|
||||
case "P2": return "text-amber-400"
|
||||
default: return "text-[var(--foreground-dim)]"
|
||||
}
|
||||
}
|
||||
|
||||
export default function TaskBrowser() {
|
||||
const [data, setData] = useState<TaskOverview | null>(null)
|
||||
const [loadError, setLoadError] = useState("")
|
||||
const [tab, setTab] = useState<Tab>("spool")
|
||||
const [detail, setDetail] = useState<TaskDetail | null>(null)
|
||||
const [detailLoading, setDetailLoading] = useState(false)
|
||||
const [detailError, setDetailError] = useState("")
|
||||
const modalRef = useRef<HTMLDivElement | null>(null)
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
const res = await fetch("/api/fleet/tasks", { cache: "no-store" })
|
||||
const body = (await res.json()) as TaskOverview & { error?: string }
|
||||
if (!res.ok || body.error) {
|
||||
setLoadError(body.error || `HTTP ${res.status}`)
|
||||
return
|
||||
}
|
||||
setData(body)
|
||||
setLoadError("")
|
||||
} catch (e) {
|
||||
setLoadError(e instanceof Error ? e.message : String(e))
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
void load()
|
||||
const t = setInterval(() => void load(), REFRESH_MS)
|
||||
return () => clearInterval(t)
|
||||
}, [load])
|
||||
|
||||
const openDetail = useCallback(async (id: string, kind: string) => {
|
||||
setDetailLoading(true)
|
||||
setDetailError("")
|
||||
setDetail(null)
|
||||
try {
|
||||
const res = await fetch(
|
||||
`/api/fleet/task-detail?id=${encodeURIComponent(id)}&kind=${encodeURIComponent(kind)}`,
|
||||
{ cache: "no-store" }
|
||||
)
|
||||
const body = (await res.json()) as TaskDetail & { error?: string }
|
||||
if (!res.ok || body.error) {
|
||||
setDetailError(body.error || `HTTP ${res.status}`)
|
||||
} else {
|
||||
setDetail(body)
|
||||
}
|
||||
} catch (e) {
|
||||
setDetailError(e instanceof Error ? e.message : String(e))
|
||||
} finally {
|
||||
setDetailLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") setDetail(null)
|
||||
}
|
||||
document.addEventListener("keydown", onKey)
|
||||
return () => document.removeEventListener("keydown", onKey)
|
||||
}, [])
|
||||
|
||||
const counts = data?.counts
|
||||
const tabBtn = (id: Tab, label: string, n: number | undefined) => (
|
||||
<button
|
||||
onClick={() => setTab(id)}
|
||||
data-testid={`task-tab-${id}`}
|
||||
className={`px-3 py-1.5 text-[11px] font-mono uppercase tracking-wider border ${
|
||||
tab === id
|
||||
? "border-[var(--nvidia-green)] text-[var(--nvidia-green)] bg-[var(--background-tertiary)]"
|
||||
: "border-[var(--border)] text-[var(--foreground-dim)] hover:text-[var(--foreground)]"
|
||||
}`}
|
||||
>
|
||||
{label} <span className="ml-1 opacity-70">{n ?? 0}</span>
|
||||
</button>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="space-y-4" data-testid="fleet-task-browser">
|
||||
<div className="panel p-6">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider">
|
||||
Tasks
|
||||
</h1>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">
|
||||
Spool-Reifegrad, Dead-Letter und Alarm-Feed — Klick auf eine Zeile zeigt den vollen
|
||||
Task-Envelope (Body unveraendert). Refresh alle 30 s
|
||||
{data ? ` · Stand ${new Date(data.generated_at).toLocaleTimeString()}` : ""}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2" data-testid="task-tabs">
|
||||
{tabBtn("spool", "Spool-Reife", counts?.spool)}
|
||||
{tabBtn("dead-letter", "Dead-Letter", counts?.dead_letter)}
|
||||
{tabBtn("alarm", "Alarm-Feed", counts?.alarm)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{loadError && (
|
||||
<div className="mt-4 border border-[var(--status-stopped)] bg-[var(--background-tertiary)] p-3 text-xs text-[var(--status-stopped)]">
|
||||
Tasks nicht ladbar: {loadError}
|
||||
</div>
|
||||
)}
|
||||
{data?.degraded && (
|
||||
<div className="mt-4 border border-amber-500 bg-[var(--background-tertiary)] p-3 text-xs text-amber-400">
|
||||
DEGRADED: {data.degraded_reason || "Quelle gestoert"} — Anzeige evtl. unvollstaendig.
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-4 overflow-x-auto">
|
||||
{tab === "alarm" ? (
|
||||
<table className="w-full text-left text-xs" data-testid="task-table-alarm">
|
||||
<thead className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||
<tr>
|
||||
<th className="py-2 pr-3">Alter</th>
|
||||
<th className="py-2 pr-3">Event</th>
|
||||
<th className="py-2 pr-3">Ref</th>
|
||||
<th className="py-2 pr-3">Von</th>
|
||||
<th className="py-2 pr-3">An</th>
|
||||
<th className="py-2">Notiz</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="font-mono">
|
||||
{(data?.alarm || []).map((row, i) => (
|
||||
<tr
|
||||
key={`${row.event}-${row.ref}-${i}`}
|
||||
data-tid={row.ref}
|
||||
data-kind="alarm"
|
||||
onClick={() => void openDetail(row.ref, "alarm")}
|
||||
className="cursor-pointer border-t border-[var(--border)] hover:bg-[var(--background-tertiary)]"
|
||||
>
|
||||
<td className={`py-1.5 pr-3 whitespace-nowrap ${ageClass(null)}`}>{row.age_human}</td>
|
||||
<td className="py-1.5 pr-3">{row.event}</td>
|
||||
<td className="py-1.5 pr-3">{row.ref}</td>
|
||||
<td className="py-1.5 pr-3">{row.from}</td>
|
||||
<td className="py-1.5 pr-3">{row.to}</td>
|
||||
<td className="py-1.5 max-w-[28rem] truncate" title={row.note}>
|
||||
{row.note || "-"}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{data && data.alarm.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={6} className="py-4 text-[var(--foreground-dim)]">
|
||||
Keine Stoerungsereignisse in den letzten 24 h.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
) : (
|
||||
<table className="w-full text-left text-xs" data-testid={`task-table-${tab}`}>
|
||||
<thead className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||
<tr>
|
||||
<th className="py-2 pr-3">Alter</th>
|
||||
<th className="py-2 pr-3">Task-ID</th>
|
||||
<th className="py-2 pr-3">Von -> An</th>
|
||||
<th className="py-2 pr-3">Typ</th>
|
||||
<th className="py-2 pr-3">Prio</th>
|
||||
<th className="py-2 pr-3">Status</th>
|
||||
<th className="py-2">Thema</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="font-mono">
|
||||
{(tab === "spool" ? data?.spool : data?.dead_letter)?.map((t) => (
|
||||
<tr
|
||||
key={t.task_id}
|
||||
data-tid={t.task_id}
|
||||
data-kind={tab}
|
||||
onClick={() => void openDetail(t.task_id, tab)}
|
||||
className="cursor-pointer border-t border-[var(--border)] hover:bg-[var(--background-tertiary)]"
|
||||
>
|
||||
<td className={`py-1.5 pr-3 whitespace-nowrap ${ageClass(t.age_seconds)}`}>
|
||||
{t.age_human}
|
||||
</td>
|
||||
<td className="py-1.5 pr-3 whitespace-nowrap">{t.task_id.slice(0, 8)}</td>
|
||||
<td className="py-1.5 pr-3 whitespace-nowrap">
|
||||
{t.from} -> {t.to}
|
||||
</td>
|
||||
<td className="py-1.5 pr-3">{t.type}</td>
|
||||
<td className={`py-1.5 pr-3 ${prioClass(t.priority)}`}>{t.priority}</td>
|
||||
<td className="py-1.5 pr-3">{t.status_label}</td>
|
||||
<td className="py-1.5 max-w-[26rem] truncate" title={t.topic}>
|
||||
{t.topic}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{data && ((tab === "spool" ? data.spool : data.dead_letter).length === 0) && (
|
||||
<tr>
|
||||
<td colSpan={7} className="py-4 text-[var(--foreground-dim)]">
|
||||
{tab === "spool"
|
||||
? "Keine offenen Tasks — Spool leer."
|
||||
: "Keine fehlgeschlagenen Tasks in den letzten 7 Tagen."}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{(detail || detailLoading || detailError) && (
|
||||
<div
|
||||
ref={modalRef}
|
||||
className="fixed inset-0 z-50 flex items-start justify-center bg-black/70 p-4 overflow-y-auto"
|
||||
onClick={(e) => {
|
||||
if (e.target === modalRef.current) setDetail(null)
|
||||
}}
|
||||
data-testid="task-detail-modal"
|
||||
>
|
||||
<div className="panel w-full max-w-3xl p-6 my-8">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h2 className="text-sm font-semibold text-[var(--nvidia-green)] uppercase tracking-wider">
|
||||
Task-Detail
|
||||
</h2>
|
||||
<p className="mt-1 text-[11px] text-[var(--foreground-dim)] font-mono">
|
||||
{(detail?.task.task_id as string) || "…"}
|
||||
{detail?.entry_kind ? ` · Quelle: ${detail.entry_kind}` : ""}
|
||||
{detail && !detail.found ? " · kein Envelope gefunden (synthetisches Ereignis)" : ""}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setDetail(null)}
|
||||
className="px-3 py-1 text-xs font-mono border border-[var(--border)] text-[var(--foreground-dim)] hover:text-[var(--foreground)]"
|
||||
data-testid="task-detail-close"
|
||||
>
|
||||
Schliessen (Esc)
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{detailLoading && <p className="mt-4 text-xs text-[var(--foreground-dim)]">Lade Envelope…</p>}
|
||||
{detailError && (
|
||||
<p className="mt-4 text-xs text-[var(--status-stopped)]">Detail nicht ladbar: {detailError}</p>
|
||||
)}
|
||||
{detail?.degraded && (
|
||||
<p className="mt-4 text-xs text-amber-400">
|
||||
DEGRADED: {detail.degraded_reason || "Quelle gestoert"}
|
||||
{detail.error ? ` — ${detail.error}` : ""}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{detail && (
|
||||
<>
|
||||
<dl className="mt-4 grid grid-cols-2 gap-x-4 gap-y-2 text-xs" data-testid="task-detail-grid">
|
||||
{DETAIL_FIELDS.map(([key, label]) => (
|
||||
<div key={key} className="contents">
|
||||
<dt className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||
{label}
|
||||
</dt>
|
||||
<dd className="font-mono break-all">{String(detail.task[key] ?? "-")}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
{detail.missing_fields.length > 0 && (
|
||||
<p className="mt-3 text-[10px] text-[var(--foreground-dim)]">
|
||||
Fehlende Felder: {detail.missing_fields.join(", ")}
|
||||
</p>
|
||||
)}
|
||||
<div className="mt-4">
|
||||
<p className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||
Body (unveraendert aus dem Spool)
|
||||
</p>
|
||||
<pre
|
||||
className="mt-1 max-h-72 overflow-auto whitespace-pre-wrap break-words border border-[var(--border)] bg-[var(--background-tertiary)] p-3 text-[11px] font-mono"
|
||||
data-testid="task-detail-body"
|
||||
>
|
||||
{String(detail.task.body ?? "-")}
|
||||
</pre>
|
||||
</div>
|
||||
{detail.raw_keys.length > 0 && (
|
||||
<p className="mt-3 text-[10px] text-[var(--foreground-dim)]">
|
||||
Envelope-Keys: {detail.raw_keys.join(", ")}
|
||||
</p>
|
||||
)}
|
||||
{Object.keys(detail.task).length === 0 && (
|
||||
<p className="mt-3 text-xs text-[var(--foreground-dim)]">Keine Daten.</p>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user