/** * UTF-8 encoded length of `text`, identical to * `new TextEncoder().encode(text).byteLength` (lone surrogates count as the * 3-byte replacement character) without allocating the encoded bytes. */ export declare function utf8ByteLength(text: string): number; /** * Returns `text` with every lone surrogate replaced by U+FFFD. Well-formed * input is returned as the same string instance (the native fast path scans * without allocating). */ export declare function toWellFormedUnicode(text: string): string; /** * `text.slice(0, maxLength)` that never splits a surrogate pair: when the cut * would end on a high surrogate (the lead half of an emoji), the boundary * backs off by one code unit. Pre-existing lone surrogates are preserved — * sanitizing malformed input is {@link toWellFormedUnicode}'s job. */ export declare function truncateWellFormed(text: string, maxLength: number): string; /** * Keeps the LAST `maxLength` code units of `text` without starting on the low * half of a split surrogate pair (the tail-side dual of * {@link truncateWellFormed}). */ export declare function tailWellFormed(text: string, maxLength: number): string; /** * Well-formed Unicode guarantees for text that is truncated at an arbitrary * UTF-16 index or serialized into a provider request body. A `.slice()` that * lands mid-emoji leaves a lone surrogate; `JSON.stringify` emits it as a * `\uD8xx` escape that strict JSON parsers (Cerebras/serde: "lone leading * surrogate in hex escape", code `wrong_api_format`) reject with HTTP 400. * Truncation helpers here never create a lone surrogate, and the sanitizers * replace any pre-existing lone surrogate with U+FFFD so a wire request is * always well-formed regardless of upstream text handling. * * `deepToWellFormedUnicode` is depth-, visit-, and cycle-bounded. OpenAI and * Anthropic text handlers call it on every request body; on origin a cyclic * object and a 20k-deep array both threw `RangeError: Maximum call stack` * and hung the turn. Over-budget input throws `ElizaError` `WELL_FORMED_UNBOUNDED`. */ /** Nesting ceiling. Honest provider bodies are a handful of objects deep. */ export declare const MAX_WELL_FORMED_DEPTH = 64; /** * Node/slot ceiling. Text length does not consume visits, so this still permits * very large transcripts while rejecting pathological object graphs and sparse * arrays before provider serialization must walk them. */ export declare const MAX_WELL_FORMED_VISITS = 65536; /** * Recursively applies {@link toWellFormedUnicode} to every string in a * JSON-shaped value — including **object keys**, which `Object.entries` * skips by default. A key containing a lone surrogate (e.g. * `{"bad\uD83D": "ok"}`) serializes to the same `\\uD8xx` escape that strict * provider JSON parsers reject. * * The clone is built on a null-prototype object with `Object.defineProperty` * so an own `__proto__` key from a JSON-parsed input is preserved as a data * member instead of mutating the clone's prototype chain. A collision policy * (first-write-wins) prevents two distinct keys from collapsing onto the same * sanitized form. Non-plain objects (typed arrays, URLs, class instances such * as AI SDK model handles) pass through untouched, and untouched subtrees keep * their original references so a clean input returns the same instance. * Intended for provider request bodies right before serialization. * * Depth, visit count, and cycles fail closed with {@link ElizaError} * `WELL_FORMED_UNBOUNDED` so a hostile nest cannot hang the model call. */ export declare function deepToWellFormedUnicode(value: T): T; /** * Well-formed-Unicode pass that follows ONLY the JSON-schema keyword structure. * * `deepToWellFormedUnicode` counts every intermediate container (`properties` * maps, array wrappers) toward its depth budget, so a legal schema at the * Cerebras walk boundary (~64 nested schema nodes) exceeds it long before the * provider contract does. This walker instead uses the SAME accounting as the * Cerebras normalizer: one depth unit per schema node reached through a * schema-bearing keyword, annotation subtrees skipped entirely (carried by * reference), string keys and values sanitized along the walked structure. * * Cycles, accessor properties on walked nodes, reflection failures on revoked * proxies, and exceeding `maxDepth` fail closed with the same typed errors as * {@link deepToWellFormedUnicode} (`WELL_FORMED_UNBOUNDED` / * `WELL_FORMED_UNSAFE_VALUE`) so callers keep one failure contract. */ export declare function wellFormedUnicodeSchemaStructure(value: T, options?: { maxDepth?: number; }): T; /** * Typed wire-boundary check for schema ANNOTATION data (`default`, `examples`, * `const`, `x-*`). * * The raw tools argument reaches this check WITHOUT a prior bounded walk on * every branch (the ToolSet path preserves wrapper metadata by descriptor), * so the traversal here is FULLY BOUNDED with UNIFORM charging: every node * pays one visit, EVERY edge — including keyword-named ones — charges one * depth unit against `maxDepth`, and cycles fail closed on path-local * ancestry. There are no name-based exemptions: a hostile wrapper can nest * arbitrarily deep under repeated "properties"/"items" keys, so key names * alone must never gate the budget. Callers that check a tool's schema * region pass a maxDepth sized for the schema walk's doubled unit cost * (`2 × MAX_WELL_FORMED_DEPTH + slack`) so an honest full-authority schema * still passes while wrapper depth stays bounded far below stack limits. * * Accessor policing is ANNOTATION-SCOPED: accessors inside an annotation * subtree are detected via `Object.getOwnPropertyDescriptor` and rejected * WITHOUT invocation; schema-region accessors are the walkers' job and * wrapper-region accessors (lazy AI SDK `jsonSchema` getters preserved by * the ToolSet branch) are a documented contract — both are skipped here, * never read or invoked. * * Reflection on a revoked proxy is translated into the same typed contract. */ export declare function assertSchemaAnnotationsSerializable(value: unknown, options?: { maxDepth?: number; }): void;