69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
/**
|
|
* 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";
|
|
|
|
export 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.message ?? "Overview synthesis failed",
|
|
},
|
|
{ status: error.statusCode }
|
|
);
|
|
}
|
|
|
|
return Response.json(
|
|
{ success: false, stage: "internal", error: "Internal server error" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|