fleet(tower): 0.20-Features nachziehen — nar-history, release-feed, task-redispatch API + OpsPanels (live in 0.20 gebaut, bisher nur Working Tree)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { FLEET_BOARD_MCP_URL, mcpCallTool } from "@/app/lib/fleet/fleetSource"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
/**
|
||||
* POST /api/fleet/task-redispatch — Dead-Letter-Re-Dispatch (Karte
|
||||
* tower-deadletter-redispatch).
|
||||
*
|
||||
* Der Tower schreibt NIE selbst in den Spool (Single-Writer-Prinzip): der
|
||||
* Aufruf geht an das board-service-Tool redispatch_task, das den neuen
|
||||
* Envelope `redis-<original>` anlegt, das Original als re-dispatched markiert
|
||||
* und journalisiert. Fachliche Fehler (ERR_*) kommen als 200 mit result zurueck
|
||||
* (die Zeile zeigt sie an); nur Transport-/MCP-Fehler werden 502.
|
||||
*/
|
||||
export async function POST(req: Request) {
|
||||
let body: { id?: unknown; task_id?: unknown } = {}
|
||||
try {
|
||||
body = (await req.json()) as { id?: unknown; task_id?: unknown }
|
||||
} catch {
|
||||
return NextResponse.json(
|
||||
{ result: "ERR_INVALID", reason: "JSON-Body fehlt oder ist kaputt" },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
const id = String(body.id ?? body.task_id ?? "").trim()
|
||||
if (!id) {
|
||||
return NextResponse.json(
|
||||
{ result: "ERR_INVALID", reason: "Parameter id fehlt" },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
const call = await mcpCallTool(FLEET_BOARD_MCP_URL, "redispatch_task", { task_id: id }, 25000)
|
||||
if (!call.ok) {
|
||||
return NextResponse.json(
|
||||
{ result: "ERR_DISPATCH_FAILED", task_id: id, reason: call.error || "board-service nicht erreichbar" },
|
||||
{ status: 502 }
|
||||
)
|
||||
}
|
||||
// MCP liefert den Tool-Text als String-JSON (board-service json.dumps).
|
||||
let payload: Record<string, unknown>
|
||||
const data = call.data
|
||||
if (typeof data === "string") {
|
||||
try {
|
||||
payload = JSON.parse(data) as Record<string, unknown>
|
||||
} catch {
|
||||
payload = { result: "ERR_DISPATCH_FAILED", task_id: id, reason: data.slice(0, 300) }
|
||||
}
|
||||
} else if (data && typeof data === "object") {
|
||||
payload = data as Record<string, unknown>
|
||||
} else {
|
||||
payload = { result: "ERR_DISPATCH_FAILED", task_id: id, reason: "leere Antwort" }
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ ...payload, task_id: id, at: new Date().toISOString() },
|
||||
{ headers: { "Cache-Control": "no-store" } }
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user