agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
58 lines • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.storedCauseCancelled = exports.storedCauseOptions = void 0;
const boundedJson_js_1 = require("../lib/boundedJson.js");
const DEFAULT_READER_LIMITS = Object.freeze({
entries: 16_384,
missingCommits: 4096,
drillDepth: 64,
addressLength: 2048,
});
const READER_CEILINGS = { ...DEFAULT_READER_LIMITS, entries: 65_536 };
const LIMIT_KEYS = Object.keys(DEFAULT_READER_LIMITS);
/** Only the declared host settings; no coercion, getters, inherited overrides or mutable options bag. */
function storedCauseOptions(value) {
const data = (0, boundedJson_js_1.ownData)(value, ['runId', 'readerLimits', 'maxBytes', 'signal']);
if (typeof data.runId !== 'string' || data.runId.length === 0 || data.runId.length > 128)
throw Error('Invalid stored cause options.');
const maxBytes = data.maxBytes === undefined ? 1024 * 1024 : data.maxBytes;
if (!Number.isSafeInteger(maxBytes) ||
maxBytes < 1 ||
maxBytes > 8 * 1024 * 1024)
throw Error('Invalid stored cause options.');
const provided = data.readerLimits === undefined ? {} : (0, boundedJson_js_1.ownData)(data.readerLimits, LIMIT_KEYS);
for (const key of LIMIT_KEYS) {
const limit = provided[key];
if (limit !== undefined &&
(!Number.isSafeInteger(limit) ||
limit < 0 ||
limit > READER_CEILINGS[key]))
throw Error('Invalid stored cause options.');
}
// Bound the upstream reader before it can allocate gap rows or iterate its very large defaults.
const limits = {
...DEFAULT_READER_LIMITS,
...Object.fromEntries(Object.entries(provided).filter(([, limit]) => limit !== undefined)),
};
const signal = data.signal;
if (signal !== undefined && !(signal instanceof AbortSignal))
throw Error('Invalid stored cause options.');
return {
runId: data.runId,
maxBytes: maxBytes,
readerLimits: limits,
...(signal !== undefined && { signal: signal }),
};
}
exports.storedCauseOptions = storedCauseOptions;
/** Call the platform getter itself, so a host subclass cannot replace this observation with code. */
function storedCauseCancelled(signal) {
if (!signal)
return false;
const getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get;
if (!getter)
throw Error('Abort signal observation is unavailable.');
return getter.call(signal);
}
exports.storedCauseCancelled = storedCauseCancelled;
//# sourceMappingURL=storedCauseOptions.js.map