import { A as LiveMessageState, P as MessageReceipt, z as RenderedMessageBatch } from "./types-D77zZaVv.js"; //#region src/channels/message/live.d.ts /** Mutable draft preview handle used before a live message is finalized or discarded. */ type LivePreviewFinalizerDraft = { flush: () => Promise; id: () => TId | undefined; seal?: () => Promise; discardPending?: () => Promise; clear: () => Promise; }; /** Outcome kind returned after attempting to finalize or fall back from a live preview. */ type LivePreviewFinalizerResultKind = "normal-delivered" | "normal-skipped" | "preview-finalized" | "preview-retained"; /** Result of a live preview finalization attempt plus the latest live state. */ type LivePreviewFinalizerResult = { kind: LivePreviewFinalizerResultKind; liveState?: LiveMessageState; }; /** Adapter contract for channels that can edit a draft preview into the final message. */ type FinalizableLivePreviewAdapter = { draft?: LivePreviewFinalizerDraft; buildFinalEdit: (payload: TPayload) => TEdit | undefined; editFinal: (id: TId, edit: TEdit) => Promise; resolveFinalizedId?: (id: TId, edit: TEdit) => TId | undefined; createPreviewReceipt?: (id: TId, edit: TEdit) => MessageReceipt; onPreviewFinalized?: (id: TId, receipt: MessageReceipt, liveState: LiveMessageState) => Promise | void; buildSupplementalPayload?: (payload: TPayload) => TPayload | undefined; deliverSupplemental?: (payload: TPayload) => Promise; handlePreviewEditError?: (params: { error: unknown; id: TId; edit: TEdit; payload: TPayload; liveState: LiveMessageState; }) => "fallback" | "retain" | Promise<"fallback" | "retain">; logPreviewEditFailure?: (error: unknown) => void; }; /** Defines a finalizable live-preview adapter while preserving its generic payload/id/edit types. */ declare function defineFinalizableLivePreviewAdapter(adapter: FinalizableLivePreviewAdapter): FinalizableLivePreviewAdapter; /** Creates the initial live-message state, optionally seeded with an existing preview receipt. */ declare function createLiveMessageState(params?: { receipt?: MessageReceipt; lastRendered?: RenderedMessageBatch; canFinalizeInPlace?: boolean; }): LiveMessageState; /** Marks a live message as finalized and disables further in-place preview edits. */ declare function markLiveMessageFinalized(state: LiveMessageState, receipt: MessageReceipt): LiveMessageState; /** Creates a receipt for a draft/preview platform message. */ declare function createPreviewMessageReceipt(params: { id: unknown; threadId?: string; replyToId?: string; sentAt?: number; raw?: unknown; }): MessageReceipt; /** Finalizes a live preview in place when possible, otherwise falls back to normal delivery. */ declare function deliverFinalizableLivePreview(params: { kind: "tool" | "block" | "final"; payload: TPayload; liveState?: LiveMessageState; draft?: LivePreviewFinalizerDraft; buildFinalEdit: (payload: TPayload) => TEdit | undefined; editFinal: (id: TId, edit: TEdit) => Promise; resolveFinalizedId?: (id: TId, edit: TEdit) => TId | undefined; deliverNormally: (payload: TPayload) => Promise; createPreviewReceipt?: (id: TId, edit: TEdit) => MessageReceipt; onPreviewFinalized?: (id: TId, receipt: MessageReceipt, liveState: LiveMessageState) => Promise | void; buildSupplementalPayload?: (payload: TPayload) => TPayload | undefined; deliverSupplemental?: (payload: TPayload) => Promise; handlePreviewEditError?: (params: { error: unknown; id: TId; edit: TEdit; payload: TPayload; liveState: LiveMessageState; }) => "fallback" | "retain" | Promise<"fallback" | "retain">; onNormalDelivered?: () => Promise | void; logPreviewEditFailure?: (error: unknown) => void; }): Promise>; /** Runs live-preview finalization through an optional adapter, falling back to normal delivery. */ declare function deliverWithFinalizableLivePreviewAdapter(params: { kind: "tool" | "block" | "final"; payload: TPayload; liveState?: LiveMessageState; adapter?: FinalizableLivePreviewAdapter; deliverNormally: (payload: TPayload) => Promise; onNormalDelivered?: () => Promise | void; }): Promise>; /** Records the latest rendered preview batch and moves the live message into previewing state. */ declare function markLiveMessagePreviewUpdated(state: LiveMessageState, rendered: RenderedMessageBatch): LiveMessageState; /** Marks a live message cancelled and prevents later in-place finalization. */ declare function markLiveMessageCancelled(state: LiveMessageState): LiveMessageState; //#endregion //#region src/channels/draft-stream-loop.d.ts /** Throttled draft-stream sender used by channels that edit in-progress replies. */ type DraftStreamLoop = { update: (text: string) => void; flush: () => Promise; stop: () => void; resetPending: () => void; resetThrottleWindow: () => void; waitForInFlight: () => Promise; }; /** Creates a single-flight draft stream loop that preserves the newest pending text. */ declare function createDraftStreamLoop(params: { throttleMs: number; isStopped: () => boolean; sendOrEditStreamMessage: (text: string) => Promise; onBackgroundFlushError?: (err: unknown) => void; }): DraftStreamLoop; //#endregion //#region src/channels/draft-stream-controls.d.ts /** * Mutable finalization flags shared by draft stream controls and channel adapters. */ type FinalizableDraftStreamState = { stopped: boolean; final: boolean; }; type StopAndClearMessageIdParams = { stopForClear: () => Promise; readMessageId: () => T | undefined; clearMessageId: () => void; }; type ClearFinalizableDraftMessageParams = StopAndClearMessageIdParams & { isValidMessageId: (value: unknown) => value is T; deleteMessage: (messageId: T) => Promise; onDeleteSuccess?: (messageId: T) => void; warn?: (message: string) => void; warnPrefix: string; }; type FinalizableDraftLifecycleParams = Omit, "stopForClear"> & { throttleMs: number; state: FinalizableDraftStreamState; sendOrEditStreamMessage: (text: string) => Promise; }; /** * Creates controls for streaming preview messages that can be finalized, sealed, or cleared. */ declare function createFinalizableDraftStreamControls(params: { throttleMs: number; isStopped: () => boolean; isFinal: () => boolean; markStopped: () => void; markFinal: () => void; sendOrEditStreamMessage: (text: string) => Promise; }): { loop: DraftStreamLoop; update: (text: string) => void; stop: () => Promise; seal: () => Promise; discardPending: () => Promise; stopForClear: () => Promise; }; /** * Creates finalizable draft controls backed by a shared mutable state object. */ declare function createFinalizableDraftStreamControlsForState(params: { throttleMs: number; state: FinalizableDraftStreamState; sendOrEditStreamMessage: (text: string) => Promise; }): { loop: DraftStreamLoop; update: (text: string) => void; stop: () => Promise; seal: () => Promise; discardPending: () => Promise; stopForClear: () => Promise; }; /** * Stops a draft stream, reads the current preview message id, then clears the stored id. */ declare function takeMessageIdAfterStop(params: StopAndClearMessageIdParams): Promise; /** * Stops a draft stream and deletes its preview message when the stored id is valid. */ declare function clearFinalizableDraftMessage(params: ClearFinalizableDraftMessageParams): Promise; /** * Builds the standard draft lifecycle used by channel streaming preview implementations. */ declare function createFinalizableDraftLifecycle(params: FinalizableDraftLifecycleParams): { clear: () => Promise; loop: DraftStreamLoop; update: (text: string) => void; stop: () => Promise; seal: () => Promise; discardPending: () => Promise; stopForClear: () => Promise; }; //#endregion export { deliverWithFinalizableLivePreviewAdapter as _, createFinalizableDraftStreamControlsForState as a, markLiveMessagePreviewUpdated as b, createDraftStreamLoop as c, LivePreviewFinalizerResult as d, LivePreviewFinalizerResultKind as f, deliverFinalizableLivePreview as g, defineFinalizableLivePreviewAdapter as h, createFinalizableDraftStreamControls as i, FinalizableLivePreviewAdapter as l, createPreviewMessageReceipt as m, clearFinalizableDraftMessage as n, takeMessageIdAfterStop as o, createLiveMessageState as p, createFinalizableDraftLifecycle as r, DraftStreamLoop as s, FinalizableDraftStreamState as t, LivePreviewFinalizerDraft as u, markLiveMessageCancelled as v, markLiveMessageFinalized as y };