UNPKG

agentfootprint

Version:

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

64 lines • 2.67 kB
"use strict"; /** * applyCachePolicy — internal helper for injection factories. * * The injection factories (`defineSkill`, `defineSteering`, `defineFact`, * `defineInstruction`) call this to merge the * consumer-supplied `cache` option with the flavor-specific default. * The merged policy lands in `Injection.metadata.cache` for the * CacheDecision subflow (Phase 4) to read back. * * Why it lives in src/cache/ (not co-located with each factory): * - Single source of truth for per-flavor defaults * - Tests for the defaults live in one place (test/cache/) * - Adding a new factory means adding one entry to the map below; * not duplicating the default-resolution logic five times */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getFlavorDefault = exports.cachePolicyMetadata = exports.resolveCachePolicy = void 0; /** * Per-flavor default `cache` values when consumer doesn't specify. * These match the documentation in `CachePolicy`'s JSDoc — keep * synchronized. */ const FLAVOR_DEFAULTS = Object.freeze({ steering: 'always', fact: 'always', skill: 'while-active', instruction: 'never', memory: 'while-active', }); /** * Resolve the effective `cache` policy for an injection. * * @param flavor - The injection flavor (drives the default if `consumerValue` undefined) * @param consumerValue - What the consumer wrote in `cache:` (or undefined) * @returns The effective CachePolicy. Always defined. */ function resolveCachePolicy(flavor, consumerValue) { if (consumerValue !== undefined) return consumerValue; // Fall back to per-flavor default; if flavor unknown, default is 'never' // (conservative — unfamiliar injections shouldn't accidentally cache). return FLAVOR_DEFAULTS[flavor] ?? 'never'; } exports.resolveCachePolicy = resolveCachePolicy; /** Preserve whether the caller supplied the policy before resolving its * flavor default. Only configuration metadata; never projected into a request. */ function cachePolicyMetadata(flavor, consumerValue) { return { cache: resolveCachePolicy(flavor, consumerValue), cachePolicySource: consumerValue === undefined ? 'default' : 'explicit', }; } exports.cachePolicyMetadata = cachePolicyMetadata; /** * Read-only access to the per-flavor default table. Exported for * tests asserting the documented defaults are wired correctly. Not * intended for runtime use — callers should use `resolveCachePolicy`. */ function getFlavorDefault(flavor) { return FLAVOR_DEFAULTS[flavor] ?? 'never'; } exports.getFlavorDefault = getFlavorDefault; //# sourceMappingURL=applyCachePolicy.js.map