"use client" import { useEffect, useState } from "react" /** * AttentionPanel — der Rueckstau, der wirklich dich meint (02.11.2026). * * "73 offene Tasks" ist keine handlungsfaehige Zahl. Dieses Panel zeigt nur * Tasks mit strukturierter Frage (attention.question + options), also die, * bei denen ein Agent ohne eine Mensch-Entscheidung nicht weiterkommt. * * Antwort geht ueber board-service answer_attention: Frage wird am Task * geschlossen (answered_at) und der Agent bekommt einen fyi-Reply-Task. * Poll 10 s, fail loud. */ type AttentionItem = { task_id: string to: string from: string priority: string status: string age_s: number | null question: string options: string[] } type AttentionSummary = { open_total: number waiting_on_person: number by_recipient: Record items: AttentionItem[] } function age(seconds: number | null): string { if (seconds === null || seconds < 0) return "?" if (seconds < 3600) return `${Math.floor(seconds / 60)} min` if (seconds < 86400) return `${Math.floor(seconds / 3600)} h` return `${Math.floor(seconds / 86400)} d` } export default function AttentionPanel() { const [data, setData] = useState(null) const [error, setError] = useState(null) const [busy, setBusy] = useState(null) const [feedback, setFeedback] = useState<{ ok: boolean; msg: string } | null>(null) const [draft, setDraft] = useState>({}) const load = () => { fetch("/api/fleet/attention", { cache: "no-store" }) .then(async (res) => { if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`) return res.json() }) .then((d: AttentionSummary) => { setData(d) setError(null) }) .catch((e: Error) => setError(e.message)) } useEffect(() => { load() const t = setInterval(load, 10000) return () => clearInterval(t) }, []) const answer = async (taskId: string, text: string) => { if (!text.trim()) { setFeedback({ ok: false, msg: "Antwort ist leer — nichts gesendet." }) return } setBusy(taskId) setFeedback(null) try { const res = await fetch("/api/fleet/attention", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ task_id: taskId, answer: text.trim() }), }) const d = await res.json() if (!res.ok) throw new Error(d.error || `HTTP ${res.status}`) if (d.result === "OK_ALREADY") { setFeedback({ ok: true, msg: "Bereits beantwortet — nichts doppelt gesendet." }) } else if (d.result === "OK_JOURNAL_ONLY") { setFeedback({ ok: true, msg: `Frage geschlossen. Absender '${d.from}' ist ein Systemdienst — Antwort nur im Journal.`, }) } else { setFeedback({ ok: true, msg: `Beantwortet. Antwort-Task ${d.antwort_task?.slice(0, 8)} an ${d.an}.` }) } setDraft((p) => ({ ...p, [taskId]: "" })) load() } catch (e) { setFeedback({ ok: false, msg: e instanceof Error ? e.message : String(e) }) } finally { setBusy(null) } } const items = data?.items ?? [] const waiting = data?.waiting_on_person ?? 0 const openTotal = data?.open_total ?? 0 return (

Wartet auf dich

Strukturierte Fragen mit Entscheidungsbedarf — der Rest des Rueckstaus ist Agentenarbeit.

{waiting}
von {openTotal} offenen Tasks
{Object.keys(data?.by_recipient ?? {}).length > 0 && (
{Object.entries(data!.by_recipient).map(([who, n]) => ( {who}: {n} ))}
)} {error && (
{error}
)} {feedback && (
{feedback.msg}
)}
{items.length === 0 && !error && (
Keine offene Frage braucht gerade eine menschliche Entscheidung. Wenn das dauerhaft so bleibt, obwohl Agenten haengen, fehlt ihnen das attention-Feld — dann ist die Skill-Seite dran, nicht die Anzeige.
)} {items.map((it) => (
{it.from} → {it.to} · {it.priority} · {it.status} · seit {age(it.age_s)}
{it.question}
{it.task_id.slice(0, 8)}
{it.options?.length > 0 && (
{it.options.map((opt) => ( ))}
)}
setDraft((p) => ({ ...p, [it.task_id]: e.target.value }))} placeholder="Oder eigene Antwort…" className="min-w-0 flex-1 rounded border border-neutral-700 bg-neutral-900 px-3 py-1.5 text-sm" />
))}
) }