function cloneJsonSafe(value) { if (value == null) return value; return JSON.parse(JSON.stringify(value)); } export function normaliseAnalysisResponse(input) { const normalised = cloneJsonSafe(input); const changesApplied = []; const warnings = []; if (!normalised || typeof normalised !== "object") { return { normalised: input, changesApplied, warnings }; } if (Array.isArray(normalised.evidence)) { normalised.evidence = normalised.evidence.map((record, index) => { if (!record || typeof record !== "object") return record; if (record.evidenceType === "reported_claim") { changesApplied.push({ path: ["evidence", index, "evidenceType"], change: "Converted reported_claim to reported_statement", }); record = { ...record, evidenceType: "reported_statement", }; } if (record.source === null) { changesApplied.push({ path: ["evidence", index, "source"], change: "Converted null source to undefined", }); const { source: _removed, ...rest } = record; return rest; } return record; }); } if (changesApplied.length > 0) { warnings.push( "Applied deterministic reconstruction compatibility normalisation", ); } return { normalised, changesApplied, warnings }; }