57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import { NextResponse } from "next/server"
|
|
import {
|
|
loadOrg,
|
|
loadVkMapping,
|
|
loadTokenRates,
|
|
loadHeartbeatAges,
|
|
countInbox,
|
|
cached,
|
|
} from "@/app/lib/fleet/fleetSource"
|
|
|
|
export const dynamic = "force-dynamic"
|
|
|
|
/**
|
|
* GET /api/fleet/overview — aggregierter Org-Chart-Datensatz (Kernfeature 1).
|
|
* Alle Quellen fail-loud: eine tote Quelle -> 500 mit Klartext (Design §5.5),
|
|
* KEIN teilweises Rendering mit stillen Nullen.
|
|
* Cache 2 s (Views pollen 5 s -> max 1 upstream call je Quelle je Zyklus).
|
|
*/
|
|
export async function GET() {
|
|
try {
|
|
const data = await cached("fleet-overview", 2000, async () => {
|
|
const [org, vks, rates, hearts] = await Promise.all([
|
|
loadOrg(),
|
|
loadVkMapping(),
|
|
loadTokenRates(),
|
|
loadHeartbeatAges(),
|
|
])
|
|
const inbox = countInbox()
|
|
const vkByAgent = new Map(vks.map((v) => [v.agent_id, v]))
|
|
const agents = org.members.map((m) => {
|
|
const vk = vkByAgent.get(m.agent_id)
|
|
const rate = vk ? rates[vk.vk_name] || { in: 0, out: 0 } : { in: 0, out: 0 }
|
|
const hbAge = hearts[m.agent_id]
|
|
return {
|
|
...m,
|
|
vk_name: vk?.vk_name || null,
|
|
model: vk?.model || null,
|
|
profile: vk?.profile || null,
|
|
tok_in_per_s: rate.in,
|
|
tok_out_per_s: rate.out,
|
|
inbox: inbox[m.agent_id] || 0,
|
|
heartbeat_age_s: typeof hbAge === "number" ? hbAge : null,
|
|
}
|
|
})
|
|
return { agents, generated_at: new Date().toISOString() }
|
|
})
|
|
return NextResponse.json(data, {
|
|
headers: { "Cache-Control": "no-store" },
|
|
})
|
|
} catch (err) {
|
|
return NextResponse.json(
|
|
{ error: `FLEET_OVERVIEW_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|