import type { MsgSchemaShape } from '../factory.js'; /** * Schema-driven payload validation for agent-dispatched Msgs. Walks * the compiler-emitted schema against a candidate Msg and reports * structural errors with a path-keyed list — the kind of feedback an * LLM can act on in a single round trip ("set kind to one of: 'exact', * 'range', 'compound'") instead of probing one field at a time. * * **What this is not.** This is not a TS type-checker. The schema is * best-effort: cross-file types, generics, complex unions, and * conditional types still surface as `'unknown'` and the validator * accepts anything for those. The validator's job is to catch the * mistakes a schema-aware LLM makes — wrong enum values, missing * discriminants, primitive type mismatches — not to mirror the entire * TypeScript surface area. * * **Tolerance for `'unknown'`.** Treat `'unknown'` as "any goes." Don't * report errors against fields whose schema we don't know — those are * the schema's gaps, not the agent's. */ export type ValidationError = { /** * Dot-bracket path rooted at the Msg payload (NOT including `type`). * - top-level field: `'cells'` * - nested object property: `'cells.value'` * - array element: `'cells[0]'` (concrete index from the input) * - discriminated-union branch: `'format(kind=range).max'` — the * parenthesised `=` segment names which branch * the error applies to, distinguishing the same field name across * branches. */ path: string; code: 'unknown-variant' | 'missing' | 'wrong-type' | 'not-in-enum' | 'not-array' | 'not-object' | 'missing-discriminant' | 'unknown-discriminant-value' | 'unexpected-field' | 'validates-failed'; message: string; }; export type ValidationWarning = { path: string; code: 'untyped-field'; message: string; }; export type ValidationResult = { ok: true; warnings?: ValidationWarning[]; } | { ok: false; errors: ValidationError[]; warnings?: ValidationWarning[]; }; export type ValidationOptions = { /** * `'strict'` rejects fields that aren't declared in the schema (typos, * extra keys, fields the LLM hallucinated). Also emits warnings when * the agent provides a value for a field whose schema is `'unknown'` * — the validator can't structurally check the value, so the warning * surfaces the gap to the LLM ("we accepted this but didn't validate * it"). `'lenient'` (default) accepts extras silently and treats * `'unknown'` as a passthrough. * * Strict mode pairs with the cross-file schema fidelity in * `@llui/vite-plugin`@0.0.36+: with most fields fully resolved, strict * is rarely surprising. Apps that haven't migrated yet may find * strict overzealous and should stay on lenient. */ policy?: 'strict' | 'lenient'; }; export declare function validatePayload(msg: unknown, schema: MsgSchemaShape | null, opts?: ValidationOptions): ValidationResult; //# sourceMappingURL=validate-payload.d.ts.map