Tower: View 'Wartet auf mich' — strukturierte Attention-Fragen
Der Rueckstau war bisher eine Zahl ('94 offene Tasks'). Diese View zeigt nur
Tasks mit attention-Block, also die, bei denen ein Agent ohne eine
Mensch-Entscheidung nicht weiterkommt.
- /api/fleet/attention: GET ruft attention_summary, POST ruft answer_attention.
- AttentionPanel: Frage, Optionen als Buttons, Freitextfeld, Rueckmeldung
(OK / OK_ALREADY / OK_JOURNAL_ONLY), Poll 10 s, fail loud.
- Sidebar-View 'attention' + Verdrahtung in page.tsx.
Die Antwort geht ueber board-service answer_attention: Frage wird am Task
geschlossen (answered_at) und der Agent bekommt einen fyi-Reply-Task mit
reply_to. Kein Chat, kein Bauauftrag.
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
"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<string, number>
|
||||
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<AttentionSummary | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [busy, setBusy] = useState<string | null>(null)
|
||||
const [feedback, setFeedback] = useState<{ ok: boolean; msg: string } | null>(null)
|
||||
const [draft, setDraft] = useState<Record<string, string>>({})
|
||||
|
||||
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 (
|
||||
<div className="space-y-6">
|
||||
<div className="panel p-6">
|
||||
<div className="flex flex-wrap items-baseline justify-between gap-3">
|
||||
<div>
|
||||
<h2 className="text-xl font-semibold">Wartet auf dich</h2>
|
||||
<p className="mt-1 text-sm text-neutral-400">
|
||||
Strukturierte Fragen mit Entscheidungsbedarf — der Rest des Rueckstaus ist Agentenarbeit.
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-3xl font-semibold tabular-nums">{waiting}</div>
|
||||
<div className="text-xs text-neutral-400">von {openTotal} offenen Tasks</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{Object.keys(data?.by_recipient ?? {}).length > 0 && (
|
||||
<div className="mt-4 flex flex-wrap gap-2 text-xs text-neutral-400">
|
||||
{Object.entries(data!.by_recipient).map(([who, n]) => (
|
||||
<span key={who} className="rounded border border-neutral-700 px-2 py-0.5">
|
||||
{who}: {n}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<div className="mt-4 rounded border border-red-800 bg-red-950/40 p-3 text-sm text-red-300">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{feedback && (
|
||||
<div
|
||||
className={`mt-4 rounded border p-3 text-sm ${
|
||||
feedback.ok
|
||||
? "border-emerald-800 bg-emerald-950/40 text-emerald-300"
|
||||
: "border-red-800 bg-red-950/40 text-red-300"
|
||||
}`}
|
||||
>
|
||||
{feedback.msg}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{items.length === 0 && !error && (
|
||||
<div className="panel p-6 text-sm text-neutral-400">
|
||||
Keine offene Frage braucht gerade eine menschliche Entscheidung. Wenn das dauerhaft so
|
||||
bleibt, obwohl Agenten haengen, fehlt ihnen das <code>attention</code>-Feld — dann ist
|
||||
die Skill-Seite dran, nicht die Anzeige.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{items.map((it) => (
|
||||
<div key={it.task_id} className="panel p-6">
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="text-sm text-neutral-400">
|
||||
{it.from} → {it.to} · {it.priority} · {it.status} · seit {age(it.age_s)}
|
||||
</div>
|
||||
<div className="mt-2 text-base font-medium">{it.question}</div>
|
||||
</div>
|
||||
<code className="shrink-0 text-xs text-neutral-500">{it.task_id.slice(0, 8)}</code>
|
||||
</div>
|
||||
|
||||
{it.options?.length > 0 && (
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{it.options.map((opt) => (
|
||||
<button
|
||||
key={opt}
|
||||
disabled={busy === it.task_id}
|
||||
onClick={() => answer(it.task_id, opt)}
|
||||
className="rounded border border-neutral-700 px-3 py-1.5 text-sm hover:border-neutral-500 hover:bg-neutral-800 disabled:opacity-50"
|
||||
>
|
||||
{opt}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
<input
|
||||
value={draft[it.task_id] ?? ""}
|
||||
onChange={(e) => 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"
|
||||
/>
|
||||
<button
|
||||
disabled={busy === it.task_id}
|
||||
onClick={() => answer(it.task_id, draft[it.task_id] ?? "")}
|
||||
className="rounded bg-neutral-100 px-4 py-1.5 text-sm font-medium text-neutral-900 hover:bg-white disabled:opacity-50"
|
||||
>
|
||||
{busy === it.task_id ? "sendet…" : "Antworten"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user