agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
49 lines • 2.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.capturedControl = void 0;
const causeCapture_js_1 = require("./causeCapture.js");
/** Read the public producer snapshot, never its class or live recorder internals. */
function capturedControl(snapshot) {
try {
const entries = (0, causeCapture_js_1.captureOwn)(snapshot, 'recorders');
if (!Array.isArray(entries) || entries.length > 32)
return undefined;
let control;
for (let index = 0; index < entries.length; index++) {
const entry = (0, causeCapture_js_1.captureOwn)(entries, String(index));
if ((0, causeCapture_js_1.captureOwn)(entry, 'name') !== 'control-dependencies')
continue;
if (control !== undefined)
return undefined; // Conflicting producers are not merged or guessed.
const acknowledgement = (0, causeCapture_js_1.captureOwn)(entry, 'capture');
if ((0, causeCapture_js_1.captureOwn)(acknowledgement, 'version') !== 1 ||
(0, causeCapture_js_1.captureOwn)(acknowledgement, 'runId') !== (0, causeCapture_js_1.captureOwn)(snapshot, 'runId') ||
(0, causeCapture_js_1.captureOwn)(acknowledgement, 'control') !== 'captured')
return undefined;
const data = (0, causeCapture_js_1.captureOwn)((0, causeCapture_js_1.captureOwn)(entry, 'data'), 'controlDeps');
if (data === null || typeof data !== 'object' || Array.isArray(data))
return undefined;
const prototype = Object.getPrototypeOf(data);
if (prototype !== null && prototype !== Object.prototype)
return undefined;
control = Object.create(null);
let count = 0;
for (const id in data) {
if (!Object.hasOwn(data, id))
continue;
if (++count > 4096 || id.length === 0 || id.length > 128)
return undefined;
const deciderId = (0, causeCapture_js_1.captureOwn)((0, causeCapture_js_1.captureOwn)(data, id), 'deciderId');
if (typeof deciderId !== 'string' || deciderId.length === 0 || deciderId.length > 128)
return undefined;
control[id] = { deciderId };
}
}
return control;
}
catch {
return undefined;
}
}
exports.capturedControl = capturedControl;
//# sourceMappingURL=causeControl.js.map