/** * Re-serialize a stream of raw JSON text fragments into the exact bytes * `JSON.stringify(JSON.parse(raw))` would produce, emitting each byte as soon * as it is guaranteed to match. * * Why this exists: a provider streams the argument JSON the model wrote, but * the AG-UI wire carries `JSON.stringify(args)` of the parsed object, and * consumers append deltas verbatim. The two texts differ in whitespace, escape * form, number form and, for two rare shapes, member order. Working token by * token keeps the emitted text a prefix of the canonical form: * * - whitespace between tokens is dropped and structural characters pass; * - string content is decoded as escapes complete and re-escaped with * `JSON.stringify` itself, per fragment, withholding a trailing high * surrogate until its pair arrives; object keys are held until complete; * - numbers and literals are held until a delimiter and re-serialized through * `JSON.parse`/`JSON.stringify`. * * Two shapes cannot be canonicalized before their object closes: a duplicate * key (the first position keeps the last value) and an array-index-like key * (`JSON.stringify` sorts those first). On either, and on malformed input, * the stream switches permanently to raw passthrough from that token onward. * The concatenation is then still valid JSON that parses to the same value; * only its byte form differs from the canonical one. */ export interface CanonicalJsonStream { /** Feed the next raw fragment; returns the text safe to emit now. */ push(fragment: string): string; /** Signal the end of the raw text; returns whatever was still held. */ flush(): string; } export declare function createCanonicalJsonStream(): CanonicalJsonStream; //# sourceMappingURL=canonical-json-stream.d.ts.map