export { TAG, ACK_STATUS, encode, decode, decodeClientFrame, assertProtocol, peekTag, ProtocolViolationError, isChannelCtrlTag, isChannelDataFrame, isConnCtrlTag, encodePublishText, encodePublishBinary, payloadBytes, }; export type { AckResultStatus, DecodedFrame, ChannelFrame, ChannelCtrlFrame, ChannelDataFrame, ReconcilePayload, ReconcileOpenEntry, BarrierPayload, ReconciledPayload, PreparePayload, ReadyPayload, WirePublishInfo, }; import type { ChannelTransports } from './constants.js'; declare const payloadBytes: (frame: Uint8Array) => number; declare const TAG: { PING: 1; PONG: 2; /** Server → client on old transport after upgrade drain: signals last frame on this transport. */ FIN: 3; /** Client → server on every (re)connect. JSON payload (`ReconcilePayload`). */ RECONCILE: 4; /** Server → client after reconcile. JSON payload (`ReconciledPayload`). */ RECONCILED: 5; /** Server → client wire-probe ack. Sent over the SSE downstream after the long-lived * client→server stream-request POST's metadata has been parsed. The client awaits this * within `STREAM_REQUEST_HANDSHAKE_TIMEOUT_MS` before declaring the transport open — * confirms the half-duplex streaming wire round-trips end-to-end. */ STREAM_REQUEST_OPEN_ACK: 6; PREPARE: 7; READY: 8; /** Client → server on the OLD wire as its final frame: the same cursors as a RECONCILE, but * addressed to the staged probe. Its own tag so the size cap lands on the raw bytes. */ BARRIER: 9; TEXT: 16; BINARY: 17; TEXT_ACK_REQ: 18; BINARY_ACK_REQ: 19; /** ACK response — carries `ackedSeq` + serialized result. */ ACK_RES: 20; /** Replayable publish frame delivered to keyed-channel subscribers. */ PUBLISH: 21; /** Replayable keyed publish frame that requests an acknowledgement receipt. */ PUBLISH_ACK_REQ: 22; /** Replayable binary publish frame delivered to keyed-channel subscribers. */ PUBLISH_BINARY: 23; /** Replayable keyed binary publish frame that requests an acknowledgement receipt. */ PUBLISH_BINARY_ACK_REQ: 24; CLOSE: 48; CLOSE_ACK: 49; /** Server → client: channel closed with an abort value (analogous to `throw Abort()`). */ ABORT: 50; /** Server → client: channel closed due to an unhandled server error (no payload). */ ERROR: 51; /** Flow-control window update — sets the peer's send credit to the advertised value. */ WINDOW: 52; BROADCAST_SUB: 53; BROADCAST_UNSUB: 54; /** BDP probe — receiver→sender. Sender echoes `BDP_PING_ACK` immediately so the * receiver can measure bytes-in-flight during one RTT and grow `WINDOW` to BDP. */ BDP_PING: 55; BDP_PING_ACK: 56; /** Flow-control message-count update — sets the peer's send msg-credit to the * advertised value. Parallel to `WINDOW` but counted in messages, not bytes, * to bound receiver dispatch CPU regardless of message size. */ MSG_WINDOW: 57; }; declare function isConnCtrlTag(tag: number): boolean; declare function isChannelCtrlTag(tag: number): boolean; declare function isChannelDataFrame(frame: DecodedFrame): frame is ChannelDataFrame; type ReconcileOpenEntry = { id: string; ix: number; lastSeq: number; /** `initial: true` means this is the first reconcile for that channel — the server may * not have created it yet (late-creation race during request body parse), so the server * should wait up to `connectTtl` for it. Established channels (already reconciled at * least once) omit `initial`; the server fails them fast if they're missing rather than * stalling the entire reconcile. */ initial?: true; }; type ReconcilePayload = { sessionId?: string; open: ReconcileOpenEntry[]; }; /** A barrier names the session it retires and the upgrade it commits — both mandatory, where a * reconcile has neither. A malformed one can no longer fall through to ordinary reconciliation. */ type BarrierPayload = { sessionId: string; upgradeId: string; open: ReconcileOpenEntry[]; }; type PreparePayload = { upgradeId: string; sessionId: string; }; type ReadyPayload = { upgradeId: string; }; /** Per-channel acknowledgment: the server confirms each `ix` it attached and tells the * client which `lastSeq` it has on file, so the client can replay frames after that. */ type ReconciledPayload = { sessionId: string; open: { ix: number; lastSeq: number; }[]; reconnectTimeout: number; idleTimeout: number; pingInterval: number; clientReplayBuffer: number; clientReplayBufferBinary: number; sseFlushThrottle: number; ssePostIdleFlushDelay: number; transports: ChannelTransports; upgradeId?: string; }; /** Ack result outcome on the wire — same byte value in memory and on the wire. * - `OK`: `text` is the serialized ack value. * - `ERROR`: a generic listener/channel error; `text` is the user-facing message. * - `ABORT`: `text` is the serialized abort value. * - `SHIELD_ERROR`: a shield validator rejected the data/ack; `text` is the validator message. * Kept distinct from `ERROR` so the receiving side can throw `ShieldValidationError`. */ declare const ACK_STATUS: { OK: 0; ERROR: 1; ABORT: 2; SHIELD_ERROR: 3; }; type AckResultStatus = (typeof ACK_STATUS)[keyof typeof ACK_STATUS]; /** Ordering metadata embedded in PUBLISH frames on the wire. */ type WirePublishInfo = { seq: number; timestamp: number; }; type ChannelDataFrame = { tag: typeof TAG.TEXT; index: number; seq: number; text: string; bytes: number; } | { tag: typeof TAG.BINARY; index: number; seq: number; data: Uint8Array; } | { tag: typeof TAG.TEXT_ACK_REQ; index: number; seq: number; text: string; } | { tag: typeof TAG.BINARY_ACK_REQ; index: number; seq: number; data: Uint8Array; } | { tag: typeof TAG.ACK_RES; index: number; seq: number; ackedSeq: number; status: AckResultStatus; text: string; } | { tag: typeof TAG.PUBLISH; index: number; seq: number; text: string; info: WirePublishInfo; } | { tag: typeof TAG.PUBLISH_ACK_REQ; index: number; seq: number; text: string; } | { tag: typeof TAG.PUBLISH_BINARY; index: number; seq: number; data: Uint8Array; info: WirePublishInfo; } | { tag: typeof TAG.PUBLISH_BINARY_ACK_REQ; index: number; seq: number; data: Uint8Array; }; type ChannelCtrlFrame = { tag: typeof TAG.CLOSE; index: number; timeoutMs: number; } | { tag: typeof TAG.CLOSE_ACK; index: number; } | { tag: typeof TAG.ABORT; index: number; abortValue: string; } | { tag: typeof TAG.ERROR; index: number; } | { tag: typeof TAG.WINDOW; index: number; bytes: number; } | { tag: typeof TAG.MSG_WINDOW; index: number; count: number; } | { tag: typeof TAG.BROADCAST_SUB; index: number; binary: boolean; } | { tag: typeof TAG.BROADCAST_UNSUB; index: number; binary: boolean; } | { tag: typeof TAG.BDP_PING; index: number; } | { tag: typeof TAG.BDP_PING_ACK; index: number; }; /** Frames that carry an `index` (channel ix) — both data and per-channel ctrl. */ type ChannelFrame = ChannelDataFrame | ChannelCtrlFrame; type ConnCtrlFrame = { tag: typeof TAG.PING; } | { tag: typeof TAG.PONG; } | { tag: typeof TAG.FIN; } | { tag: typeof TAG.RECONCILE; payload: ReconcilePayload; } | { tag: typeof TAG.BARRIER; payload: BarrierPayload; } | { tag: typeof TAG.RECONCILED; payload: ReconciledPayload; } | { tag: typeof TAG.STREAM_REQUEST_OPEN_ACK; } | { tag: typeof TAG.PREPARE; payload: PreparePayload; } | { tag: typeof TAG.READY; payload: ReadyPayload; }; type DecodedFrame = ChannelFrame | ConnCtrlFrame; declare const encode: { text: (index: number, text: string, seq?: number) => Uint8Array; publish: (index: number, text: string, seq?: number) => Uint8Array; publishAckReq: (index: number, text: string, seq?: number) => Uint8Array; textAckReq: (index: number, text: string, seq?: number) => Uint8Array; binary: (index: number, data: Uint8Array, seq?: number) => Uint8Array; publishBinary: (index: number, data: Uint8Array, seq?: number) => Uint8Array; publishBinaryAckReq: (index: number, data: Uint8Array, seq?: number) => Uint8Array; binaryAckReq: (index: number, data: Uint8Array, seq?: number) => Uint8Array; /** Wire: [header][u32 ackedSeq][u8 status][result bytes...] * `ownSeq` — this frame's own replay sequence number. * `ackedSeq` — the seq of the ACK_REQ frame being acknowledged. */ ackRes(index: number, ownSeq: number, ackedSeq: number, result: string, status?: AckResultStatus): Uint8Array; ping: () => Uint8Array; pong: () => Uint8Array; fin: () => Uint8Array; reconcile: (payload: ReconcilePayload) => Uint8Array; barrier: (payload: BarrierPayload) => Uint8Array; reconciled: (payload: ReconciledPayload) => Uint8Array; streamRequestOpenAck: () => Uint8Array; prepare: (payload: PreparePayload) => Uint8Array; ready: (payload: ReadyPayload) => Uint8Array; close(index: number, timeoutMs: number): Uint8Array; closeAck: (index: number) => Uint8Array; abort(index: number, abortValue: string): Uint8Array; error: (index: number) => Uint8Array; window(index: number, bytes: number): Uint8Array; msgWindow(index: number, count: number): Uint8Array; bdpPing: (index: number) => Uint8Array; bdpPingAck: (index: number) => Uint8Array; broadcastSub(index: number, binary: boolean): Uint8Array; broadcastUnsub(index: number, binary: boolean): Uint8Array; }; /** Raised for every malformed-bytes path. Never `assert`: that one tells the user they found a * telefunc bug, and these bytes are the peer's. */ declare class ProtocolViolationError extends Error { readonly target?: unknown; constructor(debugInfo?: string, target?: unknown); } /** `assert` for peer input, `debugInfo` and all. `target` names the wire to terminate when it * isn't the sender. */ declare function assertProtocol(condition: unknown, debugInfo: string, target?: unknown): asserts condition; /** The tag is the first header byte — readable before the frame is known to be well-formed. */ declare function peekTag(raw: Uint8Array): number | undefined; declare function decode(frame: Uint8Array): DecodedFrame; /** Server ingress: `decode` owns the frame's shape, this owns its direction and the upgrade frames' * size cap. The cap is checked on the raw bytes because its job is to bound what an unauthenticated * peer can make us parse — after `decode` it would be bounding nothing. */ declare function decodeClientFrame(raw: Uint8Array, maxUpgradeFrameBytes: number): DecodedFrame; declare function encodePublishText(text: string, info: WirePublishInfo): string; declare function encodePublishBinary(data: Uint8Array, info: WirePublishInfo): Uint8Array;