fix: normalise compatible live reconstruction responses

This commit is contained in:
2026-08-02 07:50:02 +01:00
parent 575b8fd971
commit 02a6ecd0da
5 changed files with 325 additions and 16 deletions
+40
View File
@@ -0,0 +1,40 @@
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.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 };
}