/** * `application/vnd.amazon.eventstream` decoder. * * Wire format (all integers big-endian): * * [total length u32] * [headers length u32] * [prelude CRC32 u32] <- CRC over the first 8 bytes * [headers headers_length] * [payload total_length - headers_length - 16] * [message CRC32 u32] <- CRC over the entire message minus the trailing 4 bytes * * Headers: a sequence of `[name_len u8][name utf8][value_type u8][value …]`. * We only need the typed values Bedrock emits (boolean true/false, byte, short, * integer, long, byte-array, string, timestamp, uuid). All are surfaced as * strings for ease of consumption — Bedrock only sets string-valued headers in * practice (`:event-type`, `:message-type`, `:content-type`, `:exception-type`). */ /** * Largest message we accept. aws-c-event-stream caps whole messages at 24 MiB * (smithy caps the payload alone at 16 MiB); taking the larger bound never * rejects a frame a conforming service may send, while still bounding what a * corrupt or hostile length prefix can make us allocate. */ export declare const MAX_MESSAGE_LEN: number; /** Encoded header-block limit from the Amazon Event Stream specification. */ export declare const MAX_HEADERS_LEN: number; export interface EventStreamMessage { /** Lower-cased copy is *not* applied — Bedrock uses casing like `:event-type` verbatim. */ headers: Record; payload: Uint8Array; } /** CRC32 (IEEE / zlib polynomial 0xEDB88320), matches `@aws-crypto/crc32`. */ export declare function crc32(bytes: Uint8Array): number; /** * Decode a single, fully buffered eventstream message. Throws if the framing is * malformed or either CRC mismatches. Used by both `decodeEventStream` (the * streaming entry point) and the unit tests, which exercise it with hand-built * frames. */ export declare function decodeMessage(frame: Uint8Array): EventStreamMessage; /** * Async generator that consumes a `ReadableStream` (e.g. a fetch * response body) and yields fully-framed messages. Handles arbitrary chunk * boundaries: messages may span multiple chunks, and a single chunk may carry * many messages. * * A message wholly inside one chunk is decoded in place (zero-copy). A message * spanning chunks is copied once into a buffer sized from its validated * prelude, so buffered memory never exceeds one bounded message and every byte * is copied at most once. Yielded payloads are never overwritten afterwards. * A body that ends inside a frame raises `EventStreamFrameError` with * `kind: "truncated"`. */ export declare function decodeEventStream(source: ReadableStream): AsyncGenerator;