agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
39 lines • 1.31 kB
JavaScript
// Symbol.for follows the private inner-run/tool-session seams: a CJS wrapper
// and an ESM caller in one process see the same hook, never a wire field.
const REQUEST_OBSERVER = Symbol.for('agentfootprint.requestObserver');
/** Attach a run-local observer without adding a public/model-facing hook. */
export function observeRequests(hooks, observer) {
return { ...hooks, [REQUEST_OBSERVER]: observer };
}
/** A leaf owns these hooks only until its promise/iterator settles. */
export function requestAttempt(hooks, request) {
const observer = hooks?.[REQUEST_OBSERVER];
// Off-mode keeps the original hook object and all its behavior unchanged.
if (observer === undefined)
return {
hooks,
close() {
/* No observer lifetime exists off-mode. */
},
};
observer(request);
let active = true;
const scoped = {
...hooks,
[REQUEST_OBSERVER]: (next) => {
if (active)
observer(next);
},
onReplayPrepared: (preparation) => {
if (active)
hooks?.onReplayPrepared?.(preparation);
},
};
return {
hooks: scoped,
close() {
active = false;
},
};
}
//# sourceMappingURL=requestObserver.js.map