agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
68 lines • 3.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.referenceRefusalRowIsWellFormed = exports.referenceRefusalRow = void 0;
const DIAGNOSTIC_CHARS = 8192;
/** Serialized text is diagnostic only: a cut is explicit and never becomes an identifier. */
function referenceRefusalRow(declaredOn, iteration, malformed, attempted) {
let text;
if (attempted !== undefined) {
try {
text = typeof attempted === 'string' ? attempted : JSON.stringify(attempted);
}
catch {
text = '[attempted findings could not be serialized]';
}
}
return {
kind: 'reference-refusal',
declaredOn,
iteration,
reason: malformed ? 'malformed' : 'unidentified',
...(text !== undefined && { attempted: text.slice(0, DIAGNOSTIC_CHARS) }),
...(text !== undefined && text.length > DIAGNOSTIC_CHARS && { truncated: true }),
};
}
exports.referenceRefusalRow = referenceRefusalRow;
/** Closed saved-diagnostic shape; restoring it never grants a reference. */
function referenceRefusalRowIsWellFormed(value) {
if (value === null || typeof value !== 'object' || Array.isArray(value))
return false;
try {
const prototype = Object.getPrototypeOf(value);
if (prototype !== null && prototype !== Object.prototype)
return false;
if (Object.getOwnPropertySymbols(value).length !== 0)
return false;
const properties = Object.getOwnPropertyDescriptors(value);
const allowed = ['kind', 'declaredOn', 'iteration', 'reason', 'attempted', 'truncated', 'turn'];
if (Object.keys(properties).some((key) => !allowed.includes(key) || !('value' in properties[key])))
return false;
const field = (key) => properties[key]?.value;
const whole = (number) => typeof number === 'number' && Number.isSafeInteger(number) && number >= 1;
const on = field('declaredOn');
let validOn = on === 'answer';
if (on !== null && typeof on === 'object' && !Array.isArray(on)) {
const keys = Object.getOwnPropertyDescriptors(on);
validOn =
Object.keys(keys).length === 1 &&
keys.toolCallId !== undefined &&
'value' in keys.toolCallId &&
typeof keys.toolCallId.value === 'string';
}
return (field('kind') === 'reference-refusal' &&
validOn &&
whole(field('iteration')) &&
['malformed', 'unidentified'].includes(field('reason')) &&
(field('attempted') === undefined ||
(typeof field('attempted') === 'string' &&
field('attempted').length <= DIAGNOSTIC_CHARS)) &&
(field('truncated') === undefined ||
(field('truncated') === true && typeof field('attempted') === 'string')) &&
(field('turn') === undefined || whole(field('turn'))));
}
catch {
return false;
}
}
exports.referenceRefusalRowIsWellFormed = referenceRefusalRowIsWellFormed;
//# sourceMappingURL=refusal.js.map