/** * Bounded prompt evidence. * * A workflow agent prompt is one model request. The external interface that requires a limit here is * the model context window: the request must fit the window together with the session context and * the reserved answer. One prompt therefore has a ceiling, and every step result that reaches a * prompt is projected to fit it. * * Projection never replaces the durable record. The complete step result stays in run state. The * projection only builds the bounded copy that a prompt shows, and every value it removes leaves a * digest and a size behind. * * Two rules keep the walk finite and predictable. A registered view runs once per schema on a path, * and the generic rules bound whatever the view returns. A view result also opens a fresh depth * budget, because a view is a bounded replacement for a whole subtree and its fields must not depend * on how deeply the prompt happens to nest the result. */ /** Ceiling for one authored agent prompt, in characters. Shared by every prompt builder. */ export declare const PROMPT_CEILING_CHARS = 96000; /** Schema identifier of a collapsed value. */ export declare const EVIDENCE_REF_SCHEMA = "pi-workflows.evidence-ref.v1"; /** Longest string kept verbatim. Longer strings become a ref with a head and tail excerpt. */ export declare const EVIDENCE_TEXT_CHARS = 4000; /** * Longest array kept in full. Extra items become one ref that names the count. * * The largest list that a registered view carries whole is a command batch, whose own limit is * `MAX_COMMAND_BATCH_ITEMS`. A smaller cap here would drop checks that a view already named, and the * size budget, not this cap, is what bounds one prompt. The cap therefore follows that limit. */ export declare const EVIDENCE_MAX_ITEMS = 64; /** Most fields kept per object. Extra fields become one ref that names the count. */ export declare const EVIDENCE_MAX_FIELDS = 200; /** Deepest structured value kept in full. Deeper subtrees become one ref. */ export declare const EVIDENCE_MAX_DEPTH = 8; /** A bounded stand-in for a value that was collapsed out of a prompt. */ export type EvidenceRef = { schema: typeof EVIDENCE_REF_SCHEMA; /** * Digest of the collapsed prompt value. A projection that collapsed a recorded subtree directly * digests that recorded value, which is the payload a durable blob holds. */ digest: string; /** Character count of the collapsed value, or of the name of a value JSON cannot represent. */ chars: number; /** Head and tail excerpt, set only when the collapsed value was a long string. */ text?: string; /** Number of array items dropped, set only when the collapsed value was an array. */ omitted?: number; }; /** A pure function from a typed result to the bounded evidence a prompt needs. */ export type EvidenceView = (value: Record) => unknown; /** Registered views, keyed by the versioned schema identifier of the result. */ export type EvidenceViews = ReadonlyMap; /** One projected step result, as a prompt lists it. */ export type EvidenceLedgerEntry = { attemptId: string; nodeId: string; outcome: string; error?: string; output: unknown; }; /** Project a value into a bounded copy. Total: it never throws and never mutates its input. */ export declare function projectEvidence(value: unknown, views: EvidenceViews): unknown; /** Build the bounded stand-in for one value. */ export declare function evidenceRef(value: unknown): EvidenceRef; /** Whether a value is already a bounded stand-in. */ export declare function isEvidenceRef(value: unknown): value is EvidenceRef; /** * Serialized size of one value in characters. A value JSON cannot represent reads as unbounded. */ export declare function evidenceChars(value: unknown): number; /** * Collapse the largest fields of one projected object until it fits the budget. * * The projection bounds every string, array, object width, and depth, but a value can still be large * overall. This bounds the whole value, which is what one prompt line needs. It collapses the largest * field first, so the small fields, which are the decisive ones, stay readable. A value that is not * a plain object is returned unchanged. */ export declare function boundEvidence(value: unknown, budgetChars: number): unknown; /** Project every entry of a ledger. */ export declare function projectLedger(entries: readonly EvidenceLedgerEntry[], views: EvidenceViews): EvidenceLedgerEntry[]; /** Serialized size of a ledger in characters. */ export declare function ledgerChars(entries: readonly EvidenceLedgerEntry[]): number; /** * Collapse the oldest entries until the ledger fits the budget. * * The newest entries stay whole, because they are the ones a decision depends on. When no shape fits, * the smallest one this walk built is returned, and the caller reports the remaining overflow. * * Collapsing one entry adds a digest and a size in place of its output, so a reference to a tiny * output is larger than the output itself. The smallest shape is therefore not always the fully * collapsed one, and callers read this result as the room the ledger needs at least. */ export declare function boundLedger(entries: EvidenceLedgerEntry[], budgetChars: number): EvidenceLedgerEntry[];