import type { AgentMessageFinishOptions, AgentMessageStream as AgentMessageStreamBase, AgentStreamEvent } from "@mono-agent/agent-contracts"; import { ChannelDeliveryError } from "@mono-agent/agent-contracts"; import type { TelegramChatId, TelegramMessageSender } from "./types.js"; export interface AgentMessageStream extends AgentMessageStreamBase { status(text: string): Promise; append(delta: string): Promise; replace(text: string): Promise; event(event: AgentStreamEvent): Promise; finish(finalText?: string, options?: TelegramMessageFinishOptions): Promise; } export interface TelegramMessageFinishOptions extends AgentMessageFinishOptions { readonly format?: boolean; } export interface TelegramMessageStreamOptions { api: TelegramMessageSender; chatId: TelegramChatId; initialStatusText?: string; editDebounceMs?: number; maxMessageChars?: number; replyToMessageId?: number; /** Maximum retries for a *final* delivery before giving up. Default 3. */ maxSendRetries?: number; /** Upper bound on any honored `retry_after`/backoff wait, in ms. Default 60000. */ retryCapMs?: number; /** Base delay for exponential backoff between final-delivery retries. Default 500. */ retryBaseDelayMs?: number; /** * Show lightweight, friendly activity hints (e.g. "Searching the web…") while * the agent works, before any answer text has arrived. Default true. */ showHints?: boolean; /** Render the final answer as Telegram MarkdownV2 (plain fallback). Default true. */ formatMarkdown?: boolean; /** * Deliver only the final answer: suppress streaming interim edits and show a * "typing…" chat action while the agent works. Default false. */ finalOnly?: boolean; /** * Post messages silently — `disable_notification` is set so the message arrives * without a push sound. Used by proactive notify during quiet hours. Default false. */ silent?: boolean; /** Aborts in-flight retry waits (e.g. on /cancel). */ abortSignal?: AbortSignal; logger?: TelegramMessageStreamLogger; } export interface TelegramMessageStreamLogger { debug?(message: string, metadata?: Record): void; warn?(message: string, metadata?: Record): void; error?(message: string, metadata?: Record): void; } /** * Raised only when a *final* delivery cannot reach Telegram after retries and * the last-resort fresh send. The AI request itself already succeeded, so the * adapter treats this as a degraded delivery — never as an agent failure. * * A thin specialization of the shared {@link ChannelDeliveryError}: the substrate * throws the shared base type, and the wrapper's `finish()` normalizes it to this * Telegram type (preserving `{ cause, attempts }`) so callers catching * `TelegramDeliveryError` keep working and the base type never escapes — parity * with how the Slack adapter wraps delivery failures. */ export declare class TelegramDeliveryError extends ChannelDeliveryError { constructor(message: string, details: { cause: unknown; attempts: number; }); } /** How a failed Telegram send/edit should be handled. */ export type TelegramSendOutcome = { kind: "not_modified"; } | { kind: "recreate"; } | { kind: "reformat_plain"; } | { kind: "retry"; retryAfterMs?: number; } | { kind: "fatal"; }; /** * Thin wrapper over the shared {@link ResilientMessageStream}: builds a Telegram * {@link ChannelTransport} and delegates all streaming/finish behavior to the * substrate, preserving this adapter's public API and no-labels + activity-hints * behavior. Telegram additionally keeps final-only tool ledgers transient by * posting the completed answer separately and deleting the ledger. The per-call * `finish(text, { format })` toggle lets fixed system copy bypass MarkdownV2. */ export declare class TelegramMessageStream implements AgentMessageStream { private readonly transport; private readonly inner; private readonly formatMarkdown; private readonly finalOnly; constructor(options: TelegramMessageStreamOptions); status(text: string): Promise; append(delta: string): Promise; replace(text: string): Promise; event(event: AgentStreamEvent): Promise; dismissTransient(): Promise; finish(finalText?: string, options?: TelegramMessageFinishOptions): Promise; } /** * Classify a Telegram send/edit failure into a recovery strategy. Pure and * exported so the recovery policy can be unit-tested directly. */ export declare function classifyTelegramError(error: unknown): TelegramSendOutcome; export declare function splitTelegramText(text: string, maxChars: number): string[]; //# sourceMappingURL=message-stream.d.ts.map