import { NextResponse } from "next/server" import { mcpCallTool, FLEET_BOARD_MCP_URL } from "@/app/lib/fleet/fleetSource" export const dynamic = "force-dynamic" /** * POST /api/fleet/owner/decide — Owner-Entscheidung über einen NAR/Owner-Inbox-Task * via board-service decide_owner_task (approve|decline). Der Tower schreibt nie * direkt in den Spool — alles läuft über den board-service (Single-Writer). * Response enthält folge_task (an den Antragsteller). */ export async function POST(request: Request) { try { const body = (await request.json()) as { task_id?: string; decision?: string; note?: string } const task_id = String(body.task_id || "").trim() const decision = String(body.decision || "").trim() const note = String(body.note || "") if (!task_id || !decision) { return NextResponse.json({ error: "task_id und decision sind Pflicht" }, { status: 400 }) } const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "decide_owner_task", { task_id, decision, note, }) if (!res.ok) { return NextResponse.json({ error: `decide_owner_task: ${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: `OWNER_DECIDE_FAILED: ${err instanceof Error ? err.message : String(err)}` }, { status: 500 } ) } }