import { NextResponse } from "next/server" import { mcpCallTool, FLEET_BOARD_MCP_URL } from "@/app/lib/fleet/fleetSource" export const dynamic = "force-dynamic" /** * GET /api/fleet/attention — strukturierte Attention-Fragen. * Ruft attention_summary() im board-service: wie viele offene Tasks warten * wirklich auf einen MENSCHEN (Frage + Optionen), nicht nur "offen". */ export async function GET() { try { const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "attention_summary", {}) if (!res.ok) { return NextResponse.json({ error: `attention_summary: ${res.error}` }, { status: 500 }) } const payload = typeof res.data === "string" ? JSON.parse(res.data) : res.data return NextResponse.json(payload, { headers: { "Cache-Control": "no-store" } }) } catch (err) { return NextResponse.json( { error: `ATTENTION_FAILED: ${err instanceof Error ? err.message : String(err)}` }, { status: 500 } ) } } /** * POST /api/fleet/attention — Antwort des Owners auf eine Attention-Frage. * Geht ueber board-service answer_attention: setzt attention.answer am Task * und legt beim fragenden Agenten einen fyi-Reply-Task ab. */ export async function POST(request: Request) { try { const body = (await request.json()) as { task_id?: string; answer?: string } const task_id = String(body.task_id || "").trim() const answer = String(body.answer || "").trim() if (!task_id || !answer) { return NextResponse.json({ error: "task_id und answer sind Pflicht" }, { status: 400 }) } const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "answer_attention", { task_id, answer }) if (!res.ok) { return NextResponse.json({ error: `answer_attention: ${res.error}` }, { status: 500 }) } const payload = typeof res.data === "string" ? JSON.parse(res.data) : res.data return NextResponse.json(payload, { headers: { "Cache-Control": "no-store" } }) } catch (err) { return NextResponse.json( { error: `ATTENTION_ANSWER_FAILED: ${err instanceof Error ? err.message : String(err)}` }, { status: 500 } ) } }