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 • 1.82 kB
JavaScript
/**
* search/inEffect — what ONE classified argument was, for the call that ran.
*
* Pattern: one pure reader, the first step of composition. Every other step
* asks it, so "sent", "defaulted", "no narrowing" and "unsent" have
* one meaning.
* Role: semantics/ layer, pure.
* Emits: N/A.
*
* The arguments are the ones the tool RAN with: after the inputs layer's fill
* and any before-tool rewrite. A host-filled argument never appears there —
* `hostFilled` fills it inside `execute` — so the caller names those from the
* wrapper's own declaration (`tools/hostFilled.ts` · `hostFillsOf`).
*/
import { isAnyValue } from './declaration.js';
/**
* Read one argument against the arguments the call ran with.
*
* @example
* ```ts
* readArgument({ name: 'window', role: 'period', whenOmitted: '2h' }, {});
* // { kind: 'default', value: '2h' }
* ```
*/
export function readArgument(arg, args, hostFilled) {
if (hostFilled !== undefined) {
if (hostFilled.credential.includes(arg.name))
return { kind: 'credential' };
const identity = Object.hasOwn(hostFilled.identity, arg.name)
? hostFilled.identity[arg.name]
: undefined;
if (identity !== undefined)
return { kind: 'host', identity };
}
if (Object.hasOwn(args, arg.name) && args[arg.name] !== undefined) {
const value = args[arg.name];
if (Array.isArray(value) && value.length === 0)
return { kind: 'empty' };
return { kind: 'sent', value };
}
const omitted = arg.whenOmitted;
if (omitted === undefined)
return { kind: 'unsent' };
if (isAnyValue(omitted))
return { kind: 'any' };
return { kind: 'default', value: omitted };
}
//# sourceMappingURL=inEffect.js.map