agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
50 lines • 1.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.failFastErrorOf = exports.failFastRecordOf = exports.RELIABILITY_FAIL_KEYS = void 0;
const types_js_1 = require("./types.js");
/** The keys of the record, listed once and checked against `AgentState`. */
exports.RELIABILITY_FAIL_KEYS = [
'reliabilityFailKind',
'reliabilityFailPayload',
'reliabilityFailReason',
'reliabilityFailCauseMessage',
'reliabilityFailCauseName',
];
/**
* The fail-fast record a state holds: its present keys, or nothing when no
* fail-fast fired — so a boundary that spreads it crosses no new key otherwise.
*/
function failFastRecordOf(state) {
if (state.reliabilityFailKind === undefined)
return undefined;
const record = {};
for (const key of exports.RELIABILITY_FAIL_KEYS) {
if (state[key] !== undefined)
record[key] = state[key];
}
return record;
}
exports.failFastRecordOf = failFastRecordOf;
/**
* The error a fail-fast record becomes. The cause is rebuilt from the message
* and name the record keeps — an `Error` does not survive the state's
* `structuredClone`, so the record never held the original.
*/
function failFastErrorOf(record, snapshot) {
const kind = record.reliabilityFailKind ?? 'unknown';
let cause;
if (record.reliabilityFailCauseMessage !== undefined) {
cause = new Error(record.reliabilityFailCauseMessage);
if (record.reliabilityFailCauseName !== undefined)
cause.name = record.reliabilityFailCauseName;
}
return new types_js_1.ReliabilityFailFastError({
kind,
reason: record.reliabilityFailReason ?? kind,
...(cause !== undefined && { cause }),
...(record.reliabilityFailPayload !== undefined && { payload: record.reliabilityFailPayload }),
...(snapshot !== undefined && { snapshot }),
});
}
exports.failFastErrorOf = failFastErrorOf;
//# sourceMappingURL=failFastRecord.js.map