agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
48 lines • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.readsItsOwnOutcome = exports.terminalErrorOf = void 0;
/**
* A run's TERMINAL VERDICT: the way an agent's run ended that its caller must
* receive as a typed error, held as a plain value a chart's state can carry.
*
* An agent ends some runs on a record in its state instead of a throw — a
* reliability fail-fast, a policy halt, a denied message, a refused answer —
* and only its run boundary (`Agent · finalizeResult`) turns that record into
* the error. A composition mounts the agent's CHART, so that boundary never
* runs: the composition asks the agent what the mount handed back
* (`outcomeOf`, duck-typed — `core-flow/` imports no runner): its answer, or
* the verdict read off the state its chart ended with. It carries the verdict
* and raises the SAME error (`terminalErrorOf`). One translation, used by the
* agent's own boundary and by every composition.
*
* Leaf module: the error classes only, no runner.
*/
const types_js_1 = require("../answer-validation/types.js");
const failFastRecord_js_1 = require("../reliability/failFastRecord.js");
const PolicyHaltError_js_1 = require("../security/PolicyHaltError.js");
const errors_js_1 = require("./agent/evidence/errors.js");
const errors_js_2 = require("./agent/middleware/errors.js");
/** The typed error a verdict is raised as — the same one the agent's own run raises. */
function terminalErrorOf(verdict, snapshot) {
switch (verdict.kind) {
case 'reliability-fail-fast':
return (0, failFastRecord_js_1.failFastErrorOf)(verdict.record, snapshot);
case 'policy-halt':
return new PolicyHaltError_js_1.PolicyHaltError(verdict.halt);
case 'message-denied':
return new errors_js_2.MessageDeniedError(verdict.denial);
case 'unsupported-values':
return new errors_js_1.UnsupportedValuesError(verdict.refusal);
case 'answer-validation':
return new types_js_1.AnswerValidationError(verdict.report);
}
}
exports.terminalErrorOf = terminalErrorOf;
/** Whether a runner reads its own chart's outcome. */
function readsItsOwnOutcome(runner) {
return (typeof runner === 'object' &&
runner !== null &&
typeof runner.outcomeOf === 'function');
}
exports.readsItsOwnOutcome = readsItsOwnOutcome;
//# sourceMappingURL=terminalVerdict.js.map