UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

50 lines • 2.05 kB
const bindings = new WeakMap(); function admissionFor(capture, version) { return Object.freeze({ native: Object.freeze({ status: capture.status, reason: capture.reason, version, scope: 'root-log', persistence: 'memory-only', }), storage: Object.freeze({ status: 'adapter-acknowledged-history', scope: 'root-log', }), readSources: capture.readSources, }); } /** Internal issuer. This identity is intentionally not serializable or shared across module instances. */ export function bindStoredCause(graph, capture, history, version) { const frozenGraph = Object.freeze(graph); const frozenCapture = Object.freeze({ ...capture }); const admission = admissionFor(frozenCapture, version); // The display copy is separate from the authority retained by this module instance. const cause = Object.freeze({ graph: frozenGraph, admission: admissionFor(frozenCapture, version), }); bindings.set(cause, { graph: frozenGraph, capture: frozenCapture, admission, history }); return cause; } /** Read identity, never the value of a caller's assessment property or an attached getter. */ export function storedCauseAssessment(cause) { if (cause === null || typeof cause !== 'object') return { kind: 'none' }; try { const binding = bindings.get(cause); if (binding) { const graph = Object.getOwnPropertyDescriptor(cause, 'graph'); return graph && 'value' in graph && graph.value === binding.graph ? { kind: 'stored', capture: binding.capture, admission: binding.admission } : { kind: 'invalid' }; } // Inherited copies carry the same claim but not the issuing identity. `in` invokes no getter. return 'admission' in cause ? { kind: 'invalid' } : { kind: 'none' }; } catch { return { kind: 'invalid' }; } } //# sourceMappingURL=storedCauseBinding.js.map