56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
import { formulateQuestionForTarget } from "@/lib/graph/focused-investigation";
|
|
import { withAuthenticatedApi } from "@/lib/supabase/api-auth.js";
|
|
|
|
async function post(request) {
|
|
try {
|
|
const body = await request.json();
|
|
|
|
if (!body.targetNodeId || typeof body.targetNodeId !== "string") {
|
|
return Response.json(
|
|
{ error: "Request must include a 'targetNodeId' string field" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
if (!body.situationGraph || typeof body.situationGraph !== "object") {
|
|
return Response.json(
|
|
{ error: "Request must include a 'situationGraph' object field" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
const result = formulateQuestionForTarget({
|
|
situationGraph: body.situationGraph,
|
|
targetNodeId: body.targetNodeId,
|
|
});
|
|
|
|
if (!result.success) {
|
|
return Response.json(
|
|
{ success: false, error: result.error },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
return Response.json({
|
|
success: true,
|
|
targetNodeId: result.targetNodeId,
|
|
question: result.question,
|
|
strategy: result.strategy,
|
|
reasoningPattern: result.reasoningPattern,
|
|
reasoningPatternReason: result.reasoningPatternReason,
|
|
reason: result.reason,
|
|
questionFamily: result.questionFamily,
|
|
selectedQuestionTemplate: result.selectedQuestionTemplate,
|
|
allowedQuestionFamilies: result.allowedQuestionFamilies,
|
|
rejectedQuestionFamilies: result.rejectedQuestionFamilies,
|
|
});
|
|
} catch (e) {
|
|
return Response.json(
|
|
{ error: e.message || "Unknown server error" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|
|
|
|
export const POST = withAuthenticatedApi(post);
|