/** * Investigation Overview synthesis API route. * * Route: POST /api/cases/overview * * Thin route pattern — no overview business logic here. */ import { getProvider, getProviderModelName } from "@/lib/llm/provider.js"; import { synthesizeInvestigationOverview } from "@/lib/graph/investigation-overview-synthesis.js"; import { withAuthenticatedApi } from "@/lib/supabase/api-auth.js"; async function post(request) { try { const body = await request.json(); if (!body || typeof body !== "object") { return Response.json( { success: false, stage: "request_validation", error: "Invalid request body" }, { status: 400 } ); } const { situationGraph, findings, plausibleInterpretations } = body; if (!situationGraph) { return Response.json( { success: false, stage: "request_validation", error: "Missing situationGraph" }, { status: 400 } ); } const result = await synthesizeInvestigationOverview( { situationGraph, findings, plausibleInterpretations }, { provider: getProvider(), modelName: getProviderModelName(), } ); return Response.json( { success: true, understanding: result.understanding, plausibleInterpretations: result.plausibleInterpretations }, { status: 200 } ); } catch (error) { if (error instanceof SyntaxError) { return Response.json( { success: false, stage: "request_validation", error: "Invalid JSON request body" }, { status: 400 } ); } if (error.statusCode) { return Response.json( { success: false, stage: error.statusCode === 400 ? "request_validation" : "provider", error: error.statusCode === 400 ? "Invalid overview request" : "Reasoning request could not be completed.", }, { status: error.statusCode } ); } return Response.json( { success: false, stage: "internal", error: "Internal server error" }, { status: 500 } ); } } export const POST = withAuthenticatedApi(post);