Feature/product platform foundation v0.62 #1
@@ -0,0 +1,136 @@
|
||||
const BASE_URL =
|
||||
process.env.CONFIDENCE_ENGINE_BASE_URL || "http://127.0.0.1:3000";
|
||||
|
||||
const scenario =
|
||||
"Should I relocate my engineering team from London to Manchester?";
|
||||
|
||||
const answers = [
|
||||
"We're looking at this mainly for cost reduction — roughly £2M annual savings on office overhead.",
|
||||
"We don't want to increase staff turnover or lose key engineers as part of the move.",
|
||||
];
|
||||
|
||||
async function postJson(path, body) {
|
||||
const response = await fetch(`${BASE_URL}${path}`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const json = await response.json();
|
||||
return { status: response.status, json };
|
||||
}
|
||||
|
||||
function nodeCount(g) {
|
||||
return g?.nodes?.length ?? 0;
|
||||
}
|
||||
|
||||
function edgeCount(g) {
|
||||
return g?.edges?.length ?? 0;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// ── Start ──────────────────────────────────────────────
|
||||
const startResult = await postJson("/api/cases/start", { scenario });
|
||||
|
||||
if (!startResult.json?.success) {
|
||||
console.log("=== START ===");
|
||||
console.log(`HTTP status: ${startResult.status}`);
|
||||
console.log(`errors: ${JSON.stringify(startResult.json?.errors ?? startResult.json?.message ?? null)}`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
const situationGraph = startResult.json.situationGraph;
|
||||
let selectedQuestion = startResult.json.selectedQuestion?.question ?? null;
|
||||
|
||||
console.log("=== START ===");
|
||||
console.log(`HTTP status: ${startResult.status}`);
|
||||
console.log(`stage: ${startResult.json.stage ?? "unknown"}`);
|
||||
console.log(`selected question: ${JSON.stringify(selectedQuestion)}`);
|
||||
console.log(`node count: ${nodeCount(situationGraph)}`);
|
||||
console.log(`edge count: ${edgeCount(situationGraph)}`);
|
||||
|
||||
if (!selectedQuestion) {
|
||||
console.log("ERROR: No selected question returned from start. Stopping.");
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
// ── Update 1 ───────────────────────────────────────────
|
||||
const prevQ1 = selectedQuestion;
|
||||
let update1Result = await postJson("/api/cases/update", {
|
||||
situationGraph,
|
||||
previousQuestion: prevQ1,
|
||||
answer: answers[0],
|
||||
});
|
||||
|
||||
if (!update1Result.json?.success) {
|
||||
console.log("\n=== UPDATE 1 ===");
|
||||
console.log(`HTTP status: ${update1Result.status}`);
|
||||
console.log(`stage: ${update1Result.json?.stage ?? "unknown"}`);
|
||||
console.log(`selected question: null`);
|
||||
console.log(`node count: ${nodeCount(situationGraph)}`);
|
||||
console.log(`edge count: ${edgeCount(situationGraph)}`);
|
||||
console.log(`error/validation summary: ${JSON.stringify(update1Result.json?.errors ?? update1Result.json?.proposalErrors ?? update1Result.json?.graphValidationErrors ?? update1Result.json?.validationErrors ?? update1Result.json?.message ?? null)}`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedGraph1 = update1Result.json.updatedSituationGraph;
|
||||
selectedQuestion = update1Result.json.selectedQuestion?.question ?? null;
|
||||
|
||||
console.log("\n=== UPDATE 1 ===");
|
||||
console.log(`HTTP status: ${update1Result.status}`);
|
||||
console.log(`stage: ${update1Result.json.stage ?? "unknown"}`);
|
||||
console.log(`proposal/apply success: ${update1Result.json.proposal?.success ?? update1Result.json.applySuccess ?? null}`);
|
||||
console.log(`selected question: ${JSON.stringify(selectedQuestion)}`);
|
||||
console.log(`node count: ${nodeCount(updatedGraph1)}`);
|
||||
console.log(`edge count: ${edgeCount(updatedGraph1)}`);
|
||||
console.log(
|
||||
`error/validation summary: ${JSON.stringify(update1Result.json?.errors ?? update1Result.json?.proposalErrors ?? update1Result.json?.graphValidationErrors ?? update1Result.json?.validationErrors ?? null)}`
|
||||
);
|
||||
|
||||
if (!selectedQuestion) {
|
||||
console.log("ERROR: No selected question returned from update 1. Stopping.");
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
// ── Update 2 ───────────────────────────────────────────
|
||||
const prevQ2 = selectedQuestion;
|
||||
let update2Result = await postJson("/api/cases/update", {
|
||||
situationGraph: updatedGraph1,
|
||||
previousQuestion: prevQ2,
|
||||
answer: answers[1],
|
||||
});
|
||||
|
||||
if (!update2Result.json?.success) {
|
||||
console.log("\n=== UPDATE 2 ===");
|
||||
console.log(`HTTP status: ${update2Result.status}`);
|
||||
console.log(`stage: ${update2Result.json?.stage ?? "unknown"}`);
|
||||
console.log(`selected question: null`);
|
||||
console.log(`node count: ${nodeCount(updatedGraph1)}`);
|
||||
console.log(`edge count: ${edgeCount(updatedGraph1)}`);
|
||||
console.log(`error/validation summary: ${JSON.stringify(update2Result.json?.errors ?? update2Result.json?.proposalErrors ?? update2Result.json?.graphValidationErrors ?? update2Result.json?.validationErrors ?? update2Result.json?.message ?? null)}`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedGraph2 = update2Result.json.updatedSituationGraph;
|
||||
selectedQuestion = update2Result.json.selectedQuestion?.question ?? null;
|
||||
|
||||
console.log("\n=== UPDATE 2 ===");
|
||||
console.log(`HTTP status: ${update2Result.status}`);
|
||||
console.log(`stage: ${update2Result.json.stage ?? "unknown"}`);
|
||||
console.log(`proposal/apply success: ${update2Result.json.proposal?.success ?? update2Result.json.applySuccess ?? null}`);
|
||||
console.log(`selected question: ${JSON.stringify(selectedQuestion)}`);
|
||||
console.log(`node count: ${nodeCount(updatedGraph2)}`);
|
||||
console.log(`edge count: ${edgeCount(updatedGraph2)}`);
|
||||
console.log(
|
||||
`error/validation summary: ${JSON.stringify(update2Result.json?.errors ?? update2Result.json?.proposalErrors ?? update2Result.json?.graphValidationErrors ?? update2Result.json?.validationErrors ?? null)}`
|
||||
);
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in New Issue
Block a user