"use client" import { useEffect, useState } from "react" import RunbookHint from "./RunbookHint" import { hintByKey } from "@/app/lib/fleet/runbookHints" /** * 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([]) const [rej, setRej] = useState([]) const [error, setError] = useState(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") => (
{l.time_epoch ? new Date(l.time_epoch * 1000).toLocaleString("de-DE") : "--"} {l.from || "system"} → {l.to || "-"} {l.priority || ""} {l.task_id?.slice(0, 8) || l.errors || ""}
) if (error) { return (

Journal nicht erreichbar

{error}

) } return (

ESCALATIONS

{esc.length} Alarme · {rej.length} Quarantaene

HITL-Alarme (type=escalation)

{esc.length === 0 ? (

Keine Alarme — alles ruhig

) : ( esc.map((l) => row(l, "esc")) )}

Quarantaene (rejected/invalid)

{rej.length === 0 ? (

Keine abgelehnten Envelopes

) : ( rej.map((l) => row(l, "rej")) )}
) }