fix(confidence-engine): keep episode reasoning server-side
This commit is contained in:
@@ -7,8 +7,6 @@ import ReasoningWorkspace, { LoadingOverlay, ContinueLaterBanner } from "@/compo
|
||||
import { mockFetch, AVAILABLE_SCENARIOS } from "@/lib/mocks/confidence-engine/mock-client";
|
||||
import { deriveFindingsFromContributions, normalizeFindings } from "@/lib/graph/finding-helpers";
|
||||
import { prepareCompletedEpisode } from "@/lib/graph/episode-preparation.js";
|
||||
import { reconsiderCompletedEpisode } from "@/lib/graph/orchestrator.js";
|
||||
import { applyValidatedProposal } from "@/lib/graph/apply-proposal.js";
|
||||
import { loadInvestigation, saveInvestigation, clearInvestigation } from "@/lib/storage/investigation-storage";
|
||||
|
||||
/* Compile-time env resolution — NEXT_PUBLIC_ vars are injected by Next.js at build */
|
||||
@@ -244,7 +242,7 @@ export function derivePrimarySurface(result, status, _showExperimentView, scenar
|
||||
|
||||
/**
|
||||
* Orchestrate the authoritative episode reconsideration flow.
|
||||
* Exported for deterministic testing — all domain functions accepted as parameters.
|
||||
* Exported for deterministic testing — domain functions and server endpoint accepted as parameters.
|
||||
*/
|
||||
export async function executeEpisodeDone({
|
||||
resultSituationGraph,
|
||||
@@ -252,8 +250,7 @@ export async function executeEpisodeDone({
|
||||
focusedContributions,
|
||||
findings,
|
||||
prepareCompletedEpisode: prepFn = prepareCompletedEpisode,
|
||||
reconsiderCompletedEpisode: reconsiderFn = reconsiderCompletedEpisode,
|
||||
applyValidatedProposal: applyFn = applyValidatedProposal,
|
||||
episodeDoneServer,
|
||||
synthesizeFn,
|
||||
setResult: setAppState,
|
||||
}) {
|
||||
@@ -268,25 +265,18 @@ export async function executeEpisodeDone({
|
||||
return { success: false, stage: "preparation", reason: "no_episodic_content" };
|
||||
}
|
||||
|
||||
const reasoning = await reconsiderFn(prepared);
|
||||
if (!reasoning.success) {
|
||||
return { success: false, stage: "reconsideration", error: reasoning.error };
|
||||
}
|
||||
|
||||
const application = await applyFn({
|
||||
const serverResult = await episodeDoneServer({
|
||||
situationGraph: resultSituationGraph,
|
||||
proposal: reasoning.proposal,
|
||||
evidenceContext: {
|
||||
isCompletedEpisode: true,
|
||||
episodeEvidence: prepared,
|
||||
},
|
||||
targetNodeId,
|
||||
contributions: focusedContributions ?? [],
|
||||
findings,
|
||||
});
|
||||
|
||||
if (!application.success) {
|
||||
return { success: false, stage: "application", error: application.error };
|
||||
if (!serverResult.success) {
|
||||
return { success: false, stage: "episode_done", error: serverResult.error };
|
||||
}
|
||||
|
||||
const nextGraph = application.updatedSituationGraph;
|
||||
const nextGraph = serverResult.updatedSituationGraph;
|
||||
setAppState(prev => ({ ...(prev ?? {}), situationGraph: nextGraph }));
|
||||
|
||||
const synthesisResult = await synthesizeFn(nextGraph, findings);
|
||||
@@ -393,6 +383,12 @@ export default function ScenarioForm() {
|
||||
targetNodeId,
|
||||
focusedContributions: focusedContributions ?? [],
|
||||
findings,
|
||||
episodeDoneServer: (payload) =>
|
||||
fetch("/api/cases/update", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ ...payload, episodeMode: true }),
|
||||
}).then((res) => res.json()),
|
||||
synthesizeFn: (graph, fn) => synthesizeFromFindings(fetch, { situationGraph: graph, findings: fn }),
|
||||
setResult,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user