feat(confidence-engine): synthesize understanding from focused findings
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user