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:
Dominik Schön
2026-10-30 14:58:42 +00:00
parent e9c8b14ee6
commit adb2286929
7 changed files with 749 additions and 2 deletions
+61
View File
@@ -0,0 +1,61 @@
import { NextResponse } from "next/server"
import { loadNarHistory } from "@/app/lib/fleet/boardSource"
export const dynamic = "force-dynamic"
/**
* GET /api/fleet/nar-history — NAR-Historie (Karte tower-nar-historie).
*
* Vollzogene Rueckbauten (Datum, Grant, Ziel, Nachweis) chronologisch plus
* ausstehende Rueckbau-Karten mit Faelligkeit und Ueberfaelligkeits-Marke.
* Quelle: Board-PVC (ideen-register + release-notes), read-only.
* Nie 5xx: fehlende Daten -> leere Listen + degraded/error im Body.
*/
export async function GET() {
try {
const { history, ausstehend, today } = loadNarHistory()
const ueberfaellig = ausstehend.filter((e) => e.ueberfaellig)
const badgeCount = ueberfaellig.length || ausstehend.length
return NextResponse.json(
{
generated_at: new Date().toISOString(),
today,
refresh_seconds: 30,
degraded: false,
degraded_reason: "",
vollzogen_count: history.length,
ausstehend_count: ausstehend.length,
ueberfaellig_count: ueberfaellig.length,
badge: {
count: badgeCount,
level: ueberfaellig.length ? "red" : ausstehend.length ? "yellow" : "green",
label: ueberfaellig.length
? `${ueberfaellig.length} Rueckbau ueberfaellig`
: ausstehend.length
? `${ausstehend.length} Rueckbau ausstehend`
: "keine Rueckbauten offen",
},
history,
ausstehend,
},
{ headers: { "Cache-Control": "no-store" } }
)
} catch (e) {
return NextResponse.json(
{
generated_at: new Date().toISOString(),
today: new Date().toISOString().slice(0, 10),
refresh_seconds: 30,
degraded: true,
degraded_reason: e instanceof Error ? e.message : String(e),
vollzogen_count: 0,
ausstehend_count: 0,
ueberfaellig_count: 0,
badge: { count: 0, level: "yellow", label: "Quelle nicht lesbar" },
history: [],
ausstehend: [],
},
{ status: 200, headers: { "Cache-Control": "no-store" } }
)
}
}
+63
View File
@@ -0,0 +1,63 @@
import { NextResponse } from "next/server"
import { listBoardValueStreams, loadReleaseLines, type ReleaseLine } from "@/app/lib/fleet/boardSource"
export const dynamic = "force-dynamic"
/**
* GET /api/fleet/release-feed — Release-Notes-Feed (Karte tower-release-notes-feed).
*
* Chronologische Lieferliste (Release-Notes aller Wertstreams), optional
* gefiltert nach Agent (?agent=ciso) und begrenzt (?limit=50, max 500).
* Quelle: Board-PVC read-only. Nie 5xx — leere Liste + degraded im Body.
*/
export async function GET(req: Request) {
try {
const url = new URL(req.url)
const agent = (url.searchParams.get("agent") || "").trim()
const vsFilter = (url.searchParams.get("vs") || "").trim()
const limitRaw = Number(url.searchParams.get("limit") || "80")
const limit = Math.min(Math.max(Number.isFinite(limitRaw) ? limitRaw : 80, 1), 500)
let streams = listBoardValueStreams()
if (vsFilter) streams = streams.filter((s) => s === vsFilter)
let lines: ReleaseLine[] = []
for (const vs of streams) lines = lines.concat(loadReleaseLines(vs))
lines.sort((a, b) => (b.epoch ?? 0) - (a.epoch ?? 0))
const all = lines
const filtered = agent ? lines.filter((l) => l.agent === agent) : lines
const agents = [...new Set(all.map((l) => l.agent).filter(Boolean))].sort()
return NextResponse.json(
{
generated_at: new Date().toISOString(),
refresh_seconds: 30,
degraded: false,
degraded_reason: "",
total: all.length,
matching: filtered.length,
shown: Math.min(filtered.length, limit),
filter: { agent, vs: vsFilter, limit },
agents,
entries: filtered.slice(0, limit),
},
{ headers: { "Cache-Control": "no-store" } }
)
} catch (e) {
return NextResponse.json(
{
generated_at: new Date().toISOString(),
refresh_seconds: 30,
degraded: true,
degraded_reason: e instanceof Error ? e.message : String(e),
total: 0,
matching: 0,
shown: 0,
filter: { agent: "", vs: "", limit: 80 },
agents: [],
entries: [],
},
{ status: 200, headers: { "Cache-Control": "no-store" } }
)
}
}
+59
View File
@@ -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" } }
)
}