import { NextRequest, NextResponse } from "next/server"; import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { recordToolVersion, toolPingSchema } from "@/lib/render-pipeline/tools"; // ── POST /api/ext/tools/ping ───────────────────────────────────────────────── // // A studio tool reporting its own version on startup. Fire-and-forget by // design: callers must not fail if this errors. export async function POST(req: NextRequest) { if (!isExtAuthorized(req)) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } let raw: unknown; try { raw = await req.json(); } catch { return NextResponse.json({ error: "Invalid JSON" }, { status: 400 }); } const parsed = toolPingSchema.safeParse(raw); if (!parsed.success) { return NextResponse.json({ error: "Invalid tool ping", details: parsed.error.issues }, { status: 422 }); } try { const result = await recordToolVersion(parsed.data); return NextResponse.json(result); } catch (err) { const { body, status } = toErrorResponse(err); return NextResponse.json(body, { status }); } }