UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

93 lines • 3.98 kB
"use strict"; /** * Row "You asked" — the question as the record holds it. * * `turn_start.userPrompt` is the text AFTER the input middleware chain * (`stages/seed.ts` · `buildSeedStage` seeds `verdict.content`). It is the * person's own words only when no input decision changed it; otherwise it is the * app's version (voucher `app`) and the raw words are said to be missing — never * reconstructed. A resumed leg has no `turn_start` (seed does not re-run); the * run's `userMessage` is then quoted, vouched by the library. A question the * record keeps out (a redaction policy's placeholder) is said to be kept out — * never "not recorded", which would deny it was asked. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.readAsked = void 0; const render_js_1 = require("../render.js"); const view_js_1 = require("../view.js"); const common_js_1 = require("./common.js"); function readAsked(ctx) { const start = ctx.view.first('agent.turn_start'); const prompt = (0, view_js_1.str)(start?.payload.userPrompt); if (start !== undefined && prompt !== undefined) { const rewrites = ctx.view .ofType('middleware.decision') .filter((e) => (e.payload.moment === 'input' || e.payload.phase === 'input') && e.payload.changed === true); const from = (0, common_js_1.at)(start, 'userPrompt'); if (rewrites.length === 0) { return { question: { value: prompt, source: 'person', status: 'recorded', pointers: [from] }, lines: [ctx.say('asked', { vars: { question: (0, render_js_1.v)(prompt, 'person', from) } })], }; } const deciders = rewrites.flatMap((e) => [(0, common_js_1.at)(e, 'middleware'), (0, common_js_1.at)(e, 'changed')]); return { question: { value: prompt, source: 'app', status: 'recorded', pointers: [from, ...deciders] }, lines: [ ctx.say('asked.rewritten', { vars: { question: (0, render_js_1.v)(prompt, 'app', from) }, pointers: deciders, }), ctx.say('asked.raw.notRecorded', { status: 'not-recorded', missing: 'no-event', pointers: [], }), ], }; } const keptOutAt = start !== undefined && (0, view_js_1.keptOut)(start, 'userPrompt') ? (0, common_js_1.at)(start, 'userPrompt') : start === undefined && ctx.resumedLeg && ctx.view.isStateKeptOut('userMessage') ? (0, common_js_1.stateAt)('userMessage') : undefined; if (keptOutAt !== undefined) { return { question: { value: null, source: 'library', status: 'not-recorded', pointers: [keptOutAt], missing: 'redacted', }, lines: [ ctx.say('asked.keptOut', { status: 'not-recorded', missing: 'redacted', pointers: [keptOutAt], }), ], }; } const held = (0, view_js_1.str)(ctx.view.state?.userMessage); if (ctx.resumedLeg && held !== undefined && held.length > 0) { const from = (0, common_js_1.stateAt)('userMessage'); return { question: { value: held, source: 'library', status: 'recorded', pointers: [from] }, lines: [ctx.say('asked.resumed', { vars: { question: (0, render_js_1.v)(held, 'library', from) } })], }; } return { question: { value: null, source: 'library', status: 'not-recorded', pointers: [], missing: 'no-event', }, lines: [ctx.say('asked.none', { status: 'not-recorded', missing: 'no-event' })], }; } exports.readAsked = readAsked; //# sourceMappingURL=asked.js.map