UNPKG

agentfootprint

Version:

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

75 lines • 4.29 kB
/** * Fill and grammar — how a template id and its vars become a typed sentence. * * `fillParts` substitutes placeholders NON-recursively (the `renderCommentary` * precedent): a var's value is never read as a template, so a tool that * declares "{{x}}" in its own words gets "{{x}}" printed, not substituted. * A missing var is a programming error and throws — `account.ts` catches it * per sentence and writes `unreadable.line@1` instead. * * English-only surfaces (named for the later locale map): the `count` pairs * inside the table, `allOf`, `joinAnd`, `distance` (all table-driven except * `joinAnd`'s ", " / " and "). */ import { type TemplateId } from './templates.js'; import { answerAccountPointerKey as pointerKey } from './pointerKey.js'; import type { AccountSource, Chip, ChipMark, FactStatus, MissingReason, RecordPointer, Sentence, SentencePart, SentenceVar } from './types.js'; /** Pointers one sentence carries at most (its printed vars' leaves come first). */ export declare const MAX_POINTERS = 12; /** A string var longer than this is clipped, with `part.clipped@1` after it. */ export declare const MAX_VAR_CHARS = 2000; type Vars = Readonly<Record<string, SentenceVar>>; /** The weakest of the given sources (library > tool > model > app; person strongest). */ export declare function weakest(sources: readonly AccountSource[]): AccountSource; /** A var is presentation, not truth, when it is a skill's LABEL (`<name>Label`). */ export declare const isPresentationVar: (name: string) => boolean; /** A var read from the record (or a declaration). Long strings are clipped. */ export declare function v(value: string | number, source: AccountSource, from?: RecordPointer, max?: number): SentenceVar; /** A fact's text value, cut at `max` characters with `clipped: true` — the size bound. */ export declare function clipFact(value: string, max: number): { value: string; clipped?: true; }; /** A number the account computed (a count) — no pointer of its own. */ export declare const n: (value: number, source?: AccountSource) => SentenceVar; /** "n one" / "n many" — an explicit pair, never a suffix. */ export declare const count: (count: number, one: string, many: string) => string; /** "was" / "were" by count. */ export declare const verb: (count: number, one: string, many: string) => string; /** ≤ 3 values inline: "a", "a and b", "a, b and c". Longer lists are the caller's bulleted list. */ export declare function joinAnd(values: readonly string[]): string; /** * Fill one template. Returns the plain text and the same text as typed parts. * Throws on a missing var or an unknown placeholder kind (a programming error). */ export declare function fillParts(id: TemplateId, vars: Vars): { text: string; parts: SentencePart[]; }; export interface SentenceSpec { readonly vars?: Vars; readonly pointers?: readonly RecordPointer[]; /** Sources that decide the sentence's truth but are not printed (e.g. the `rowsAt` that made a result "empty"). */ readonly basis?: readonly AccountSource[]; readonly status?: FactStatus; readonly missing?: MissingReason; readonly chips?: readonly Chip[]; readonly item?: true; } /** The weakest-voucher rule over a sentence's inputs (labels excluded — presentation). */ export declare function sentenceSource(id: TemplateId, vars: Vars, basis?: readonly AccountSource[]): AccountSource; /** Build one sentence. Throws only on a programming error (see `fillParts`). */ export declare function sentence(id: TemplateId, spec?: SentenceSpec): Sentence; /** A fixed-word chip. */ export declare function chip(mark: ChipMark, id: TemplateId, tone?: Chip['tone'], vars?: Vars): Chip; /** "said by: …" for one source. */ export declare function saidBy(source: AccountSource): Chip; /** A stable identity for a pointer — the `shown` map's key (owned by `./pointerKey.ts`). */ export { pointerKey }; export declare function dedupePointers(pointers: readonly RecordPointer[]): RecordPointer[]; /** * Two signal sentences as one line (`summary.signals@1`): the parts of both, * the vars of both (prefixed), the weakest voucher of both. */ export declare function joinSentences(first: Sentence, second?: Sentence): Sentence; //# sourceMappingURL=render.d.ts.map