experiment(confidence-engine): trace focused deconstruction failures
This commit is contained in:
@@ -6,8 +6,11 @@ import {
|
||||
} from "@/lib/graph/focused-investigation";
|
||||
|
||||
export async function POST(request) {
|
||||
let targetNodeId = null;
|
||||
let startedAt = null;
|
||||
try {
|
||||
const body = await request.json();
|
||||
targetNodeId = body.targetNodeId ?? null;
|
||||
|
||||
if (!body.targetNodeId || typeof body.targetNodeId !== "string") {
|
||||
return Response.json(
|
||||
@@ -55,20 +58,49 @@ export async function POST(request) {
|
||||
});
|
||||
|
||||
const provider = getProvider();
|
||||
const startedAt = Date.now();
|
||||
const modelName = getProviderModelName();
|
||||
startedAt = Date.now();
|
||||
console.info("[api/focused-investigation/deconstruct] start", {
|
||||
targetNodeId,
|
||||
modelName,
|
||||
providerMode: process.env.CONFIDENCE_ENGINE_EXPERIMENT_PROVIDER ?? "ollama",
|
||||
startedAt,
|
||||
});
|
||||
const wrapper = await provider.generateReconstruction(
|
||||
prompt,
|
||||
getProviderModelName(),
|
||||
modelName,
|
||||
focusedDeconstructJsonSchema,
|
||||
);
|
||||
const elapsedMs = Date.now() - startedAt;
|
||||
|
||||
// Unwrap the semantic deconstruction from the provider envelope.
|
||||
const deconstruction = wrapper.response;
|
||||
console.info("[api/focused-investigation/deconstruct] provider success", {
|
||||
targetNodeId,
|
||||
elapsedMs,
|
||||
providerApiPath: wrapper.providerApiPath ?? null,
|
||||
responsePresent: Boolean(deconstruction),
|
||||
responseKeys: deconstruction && typeof deconstruction === "object"
|
||||
? Object.keys(deconstruction)
|
||||
: [],
|
||||
});
|
||||
|
||||
// Validate schema (required fields present, no graph-mutation fields)
|
||||
const validationErrors = validateFocusedDeconstructSchema(deconstruction);
|
||||
console.info("[api/focused-investigation/deconstruct] validation", {
|
||||
targetNodeId,
|
||||
schemaValid: validationErrors.length === 0,
|
||||
responseKeys: deconstruction && typeof deconstruction === "object"
|
||||
? Object.keys(deconstruction)
|
||||
: [],
|
||||
validationErrors,
|
||||
});
|
||||
if (validationErrors.length > 0) {
|
||||
console.info("[api/focused-investigation/deconstruct] end", {
|
||||
targetNodeId,
|
||||
status: 502,
|
||||
elapsedMs,
|
||||
});
|
||||
return Response.json(
|
||||
{
|
||||
success: false,
|
||||
@@ -81,7 +113,7 @@ export async function POST(request) {
|
||||
);
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
const response = Response.json({
|
||||
success: true,
|
||||
targetNodeId: body.targetNodeId,
|
||||
observations: deconstruction.observations,
|
||||
@@ -91,7 +123,29 @@ export async function POST(request) {
|
||||
possibleFollowUpQuestions: deconstruction.possibleFollowUpQuestions,
|
||||
elapsedMs,
|
||||
});
|
||||
console.info("[api/focused-investigation/deconstruct] end", {
|
||||
targetNodeId,
|
||||
status: 200,
|
||||
elapsedMs,
|
||||
});
|
||||
return response;
|
||||
} catch (e) {
|
||||
const elapsedMs = startedAt == null ? null : Date.now() - startedAt;
|
||||
console.error("[api/focused-investigation/deconstruct] provider failure", {
|
||||
targetNodeId,
|
||||
elapsedMs,
|
||||
errorName: e?.name ?? "Error",
|
||||
errorMessage: e?.message ?? "Unknown server error",
|
||||
statusCode: e?.statusCode ?? e?.status ?? null,
|
||||
providerApiPath: e?.providerApiPath ?? null,
|
||||
errorCode: e?.code ?? null,
|
||||
errorParam: e?.param ?? null,
|
||||
});
|
||||
console.info("[api/focused-investigation/deconstruct] end", {
|
||||
targetNodeId,
|
||||
status: 500,
|
||||
elapsedMs,
|
||||
});
|
||||
return Response.json(
|
||||
{ error: e.message || "Unknown server error" },
|
||||
{ status: 500 },
|
||||
|
||||
Reference in New Issue
Block a user