agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
63 lines • 2.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.readDetailArgs = exports.detailTokens = exports.DETAIL_LIMITS = void 0;
const boundedJson_js_1 = require("../lib/boundedJson.js");
const naming_js_1 = require("./naming.js");
const detailError_js_1 = require("./detailError.js");
exports.DETAIL_LIMITS = Object.freeze({
inputBytes: 1024 * 1024,
contextBytes: 4096,
path: 2048,
depth: 16,
page: 20,
offset: 1_000_000,
valueBytes: 8192,
outputBytes: 12 * 1024,
reserveBytes: 512,
});
const forbidden = new Set(['__proto__', 'prototype', 'constructor']);
/** Strict pointer tokens, shared by request admission and child actions. */
function detailTokens(path) {
if (path === '')
return [];
if (!path.startsWith('/') || path.length > exports.DETAIL_LIMITS.path)
return (0, detailError_js_1.invalidDetail)();
const parts = path.slice(1).split('/');
if (parts.length > exports.DETAIL_LIMITS.depth)
return (0, detailError_js_1.invalidDetail)();
return parts.map((part) => {
// eslint-disable-next-line no-control-regex -- A pointer must not carry C0 or DEL controls.
if (/~(?![01])/.test(part) || /[\u0000-\u001f\u007f]/.test(part))
return (0, detailError_js_1.invalidDetail)();
const key = part.replace(/~1/g, '/').replace(/~0/g, '~');
if (forbidden.has(key))
return (0, detailError_js_1.invalidDetail)();
return key;
});
}
exports.detailTokens = detailTokens;
function readDetailArgs(value) {
try {
const fields = (0, boundedJson_js_1.ownData)(value, ['ref', 'path', 'offset', 'limit']);
if (typeof fields.ref !== 'string' ||
!(0, naming_js_1.isArtifactRef)(fields.ref) ||
typeof fields.path !== 'string')
return (0, detailError_js_1.invalidDetail)();
detailTokens(fields.path);
const offset = fields.offset === undefined ? 0 : fields.offset;
const limit = fields.limit === undefined ? exports.DETAIL_LIMITS.page : fields.limit;
if (!Number.isSafeInteger(offset) ||
Number(offset) < 0 ||
Number(offset) > exports.DETAIL_LIMITS.offset ||
!Number.isSafeInteger(limit) ||
Number(limit) < 1 ||
Number(limit) > exports.DETAIL_LIMITS.page)
return (0, detailError_js_1.invalidDetail)();
return { ref: fields.ref, path: fields.path, offset: Number(offset), limit: Number(limit) };
}
catch {
return (0, detailError_js_1.invalidDetail)();
}
}
exports.readDetailArgs = readDetailArgs;
//# sourceMappingURL=detailRequest.js.map