UNPKG

agentfootprint

Version:

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

44 lines • 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.requestAttempt = exports.observeRequests = void 0; // 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. */ function observeRequests(hooks, observer) { return { ...hooks, [REQUEST_OBSERVER]: observer }; } exports.observeRequests = observeRequests; /** A leaf owns these hooks only until its promise/iterator settles. */ 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; }, }; } exports.requestAttempt = requestAttempt; //# sourceMappingURL=requestObserver.js.map