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/new-vs — "Neuer Value Stream" -> CEO-Task (type=build, P2) * via board-service submit_owner_task (neuer Tool, Phase 0.13). E-V3: * Owner-Chat verdraengt nie den Task-Flow; VS-Gruendung ist ein formaler Task. * Fail loud bei unbekanntem CEO oder Spool-Fehler. */ export async function POST(request: Request) { try { const body = (await request.json()) as { topic?: string; ziel?: string } const topic = String(body.topic || "").trim() const ziel = String(body.ziel || "").trim() if (!topic || topic.length > 200) { return NextResponse.json({ error: "topic Pflicht (max 200 Zeichen)" }, { status: 400 }) } const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "submit_owner_task", { to: "ceo", type: "build", priority: "P2", topic, body: ziel || topic, requires_ack: true, }) if (!res.ok) { return NextResponse.json({ error: `submit_owner_task: ${res.error}` }, { status: 500 }) } return NextResponse.json(res.data, { headers: { "Cache-Control": "no-store" } }) } catch (err) { return NextResponse.json( { error: `OWNER_NEW_VS_FAILED: ${err instanceof Error ? err.message : String(err)}` }, { status: 500 } ) } }