diff --git a/app/investigations/[id]/report/page.jsx b/app/investigations/[id]/report/page.jsx index 093b217..e2e4aee 100644 --- a/app/investigations/[id]/report/page.jsx +++ b/app/investigations/[id]/report/page.jsx @@ -9,6 +9,7 @@ export default function ReportPage() { const [hydrated, setHydrated] = useState(false); const [generationLoading, setGenerationLoading] = useState(false); const [generationError, setGenerationError] = useState(false); + const [updateLoading, setUpdateLoading] = useState(false); const generationAttempted = useRef(false); @@ -66,6 +67,48 @@ export default function ReportPage() { })(); }, [hydrated, existing]); + // Manual Report update (v0.59b — freshness manual update) + const handleUpdateReport = async () => { + if (updateLoading) return; + setUpdateLoading(true); + + const snap = loadInvestigation(); + const situationGraph = snap?.situationGraph; + const findings = snap?.findings ?? []; + const rev = snap?.investigationRevision ?? 0; + + if (!situationGraph) { + setUpdateLoading(false); + return; + } + + try { + const res = await fetch("/api/cases/overview", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ situationGraph, findings }), + }); + + if (!res.ok) { + setUpdateLoading(false); + return; + } + + const data = await res.json(); + if (data.success) { + const reportData = { understanding: data.understanding, plausibleInterpretations: data.plausibleInterpretations, hasPlausibleInterpretations: true, generatedFromRevision: rev }; + setExisting((p) => { + saveInvestigation({ ...p, investigationReport: reportData }); + return { ...p, investigationReport: reportData }; + }); + } + } catch { + /* failure: retain existing Report and updateAvailable state */ + } finally { + setUpdateLoading(false); + } + }; + const report = existing?.investigationReport || null; const scenario = hydrated ? (existing?.scenario || "") : null; @@ -79,6 +122,28 @@ export default function ReportPage() { Investigation Report + {/* Report freshness — only when a Report exists */} + {report ? ( +