feat(confidence-engine): synthesize understanding from focused findings

This commit is contained in:
2026-08-30 19:27:30 +01:00
parent ff1119b4d5
commit 75f7c6bafd
3 changed files with 210 additions and 4 deletions
+41
View File
@@ -67,6 +67,19 @@ export async function submitAnswerForUpdateCase(
};
}
export async function synthesizeFromFindings(fetchImpl, { situationGraph, findings }) {
const response = await fetchImpl("/api/cases/synthesis", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ situationGraph, findings }),
});
return {
ok: response.ok,
data: await response.json(),
};
}
function normaliseStartResult(data) {
return {
...data,
@@ -320,6 +333,34 @@ export default function ScenarioForm() {
return [...prev, storedContribution];
});
// ── Synthesis trigger: once per completed Finding transition ──
const newFindingsDelta = deriveFindingsFromContributions([
{
...contribution,
sequence: (focusedContributions?.length ?? 0) + 1,
id: `contrib-${String((focusedContributions?.length ?? 0) + 1).padStart(4, "0")}`,
},
]).findings;
if (newFindingsDelta.length === 0) return;
const currentGraph = result?.situationGraph;
if (!currentGraph) return;
const completeNextFindings = normalizeFindings([
...(findings ?? []),
...newFindingsDelta,
]);
void synthesizeFromFindings(fetch, {
situationGraph: currentGraph,
findings: completeNextFindings,
}).then((res) => {
if (res.ok && res.data?.currentUnderstanding) {
setCurrentUnderstanding(res.data.currentUnderstanding);
}
});
}
const textareaRef = useRef(null);