/** * STREAM ACCUMULATION * =================== * * The server streams text a piece at a time. * * It used to send the whole message again on every token, which is O(N²) bytes for an * N-token reply — slow everywhere, and fatal on a Link websocket, where the answer queues * ahead of the connection's own heartbeat until this SDK closes it mid-sentence. A * streamed value now arrives as one of two shapes, and never both: * * { messageId, message: "Good day to you", completed } // the whole value: replace * { messageId, delta: " to you", completed: false } // what was added: append * * Deltas are also sent bare: no metadata block, since it is the same on every frame of a * message and several times the size of the few characters a delta carries. The frame that * opens a message brings it, and the one that finishes it brings it again. * * Callers should not have to care about any of that. This puts the message back together, * so `payload.message` is the whole message so far exactly as it always was, restores the * metadata onto every event, and keeps `payload.delta` for anyone who would rather append * than re-render. * * Whole values arrive for the last event of a message and for anything replaying after a * reconnect, and they replace rather than extend. That is what makes a reconnect cheap and * a dropped delta harmless, and it is handled here so no caller has to know about it. */ /** * Rebuilds whole values from a stream of pieces. * * Stateful, and one per stream: it holds what every message the stream is still writing * has said so far, so a turn and a progress stream never see each other's. */ export declare function createStreamAccumulator(): (payload: unknown) => unknown;