feat(confidence-engine): add investigation overview synthesis seam

This commit is contained in:
2026-09-02 14:34:32 +01:00
parent 194a742772
commit 83818c0c71
4 changed files with 817 additions and 1 deletions
+68
View File
@@ -0,0 +1,68 @@
/**
* Investigation Overview synthesis API route.
*
* Route: POST /api/cases/overview
*
* Thin route pattern — no overview business logic here.
*/
import { getProvider } 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: process.env.OLLAMA_MODEL ?? null,
}
);
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 }
);
}
}