/** * Per-Telegram-message streaming text state machine. * * Mirrors the Slack MessageStream + ChunkedMessageStream pattern but uses * numeric Telegram message IDs instead of Slack `ts` strings. * * ChunkedEditStream owns N underlying EditStream instances (one per Telegram * message). It accepts the full accumulated text on `append()`, decides where * the chunk boundaries are (frozen once a message has been posted — no reflow), * mints new Telegram messages via `postPlaceholder` as needed, and dispatches * the right slice to each chunk's stream. * * `transform` (e.g. telegramHtml) is applied just before every `editAt` call. */ export interface ChunkedEditStreamConfig { /** * Soft per-message raw char limit. Defaults to Math.floor(TELEGRAM_LIMITS.messageText / 2). * The headroom below the 4096 hard cap exists because `transform` (telegramHtml) can * expand raw chars significantly: `&`→`&` (5×), `<`/`>`→`<`/`>` (4×), * bold/link markdown → HTML tags. Halving the limit is a risk-reduction heuristic that * keeps the HTML-transformed slice under 4096 for typical prose/markdown content (which * expands modestly); it is NOT a hard guarantee against adversarial all-entity input * (e.g. 2048 raw `&` chars → ~10 240 transformed chars). */ limit?: number; /** Throttle floor (ms) between consecutive edits per message. Defaults to 1000. */ minIntervalMs?: number; /** Posts a new Telegram message with placeholder text; resolves with the message id. */ postPlaceholder: (text: string) => Promise; /** Edits the Telegram message with the given id to contain `text`. */ editAt: (messageId: number, text: string) => Promise; /** * Optional transformer applied to each chunk's text before `editAt` / * `postPlaceholder` — e.g. telegramHtml markdown→HTML conversion. */ transform?: (text: string) => string; } export declare class ChunkedEditStream { private buffer; /** Sorted character positions where a chunk ends (= where the next begins). */ private boundaries; private streams; /** Serialises new-chunk creation so async postPlaceholder calls don't race. */ private setupPromise; private finished; private readonly limit; private readonly minIntervalMs; private readonly postPlaceholder; private readonly editAt; private readonly transform; constructor(config: ChunkedEditStreamConfig); /** * Feed the FULL accumulated text so far. The stream will work out which * slice belongs to which Telegram message and throttle edits accordingly. */ append(fullText: string): void; /** Flush all pending edits and wait until every message reflects its final text. */ finish(): Promise; /** Number of Telegram messages posted so far. */ get chunkCount(): number; /** * Walk forward from the last frozen boundary, freezing new ones whenever * the active chunk's length exceeds the soft limit. Choose the break point * at the last newline (or last space) within the window; fall back to a hard * cut if neither is found. Boundaries never move once frozen. */ private refreezeBoundaries; private ensureStreamsAndDispatch; } //# sourceMappingURL=chunked-edit-stream.d.ts.map