/** * Telegram HITL inline keyboard rendering and compact callback decode helpers. * * Telegram limits `InlineKeyboardButton.callback_data` to 64 bytes, so * eve stores compact callback ids in durable channel state and remaps * them back to full input responses inside the channel deliver hook. */ import type { UserContent } from "ai"; import type { InputResolution } from "#protocol/message.js"; import { type InputOption, type InputRequest, type InputResponse, type ValidatedInputResponse } from "#shared/input.js"; /** Prefix used in Telegram callback_data values generated by eve. */ export declare const TELEGRAM_HITL_CALLBACK_PREFIX = "eve:"; /** Synthetic request id prefix sent through `send()` for callback queries. */ export declare const TELEGRAM_CALLBACK_RESPONSE_PREFIX = "telegram_callback:"; /** Synthetic request id prefix the deliver hook uses for replies to ForceReply prompts. */ export declare const TELEGRAM_REPLY_RESPONSE_PREFIX = "telegram_reply:"; /** * Durable HITL state. `hitlCallbacks` maps compact callback ids to their stored * `InputResponse`. `nextHitlCallbackId` is the monotonic id counter. * `pendingFreeformReplies` maps a posted prompt's message id to the awaiting * requestId. */ export interface TelegramHitlState { hitlCallbacks?: Record; nextHitlCallbackId?: number; pendingFreeformReplies?: Record; /** Posted prompts with inline keyboards, keyed by requestId, until eve resolves them. */ hitlPrompts?: Record; } /** What a posted prompt needs so its message can be edited once eve resolves it. */ export interface TelegramHitlPrompt { readonly messageId: string; readonly options: readonly Pick[]; readonly text: string; } /** * Rendered Telegram message body for one pending input request. * `freeformRequestId` is set only for ForceReply prompts (option-less requests). * After posting such a prompt, call {@link registerTelegramFreeformPrompt}. * Option requests instead carry an inline-keyboard `replyMarkup`. */ export interface TelegramInputRequestMessage { readonly freeformRequestId?: string; readonly replyMarkup?: Readonly>; readonly text: string; } /** Renders one `InputRequest` as Telegram inline keyboard or ForceReply markup. */ export declare function renderTelegramInputRequest(request: InputRequest, state: TelegramHitlState): TelegramInputRequestMessage; /** Records the Telegram message id that a freeform answer should reply to. */ export declare function registerTelegramFreeformPrompt(state: TelegramHitlState, input: { readonly messageId: string; readonly requestId: string; }): void; /** Records a posted inline-keyboard prompt so {@link takeTelegramResolvedPrompt} can edit it. */ export declare function registerTelegramHitlPrompt(state: TelegramHitlState, request: InputRequest, posted: { readonly messageId: string; readonly text: string; }): void; /** * Forgets a resolved prompt, returning the edit that * replaces its keyboard with the outcome, or `undefined` when eve never posted it. */ export declare function takeTelegramResolvedPrompt(state: TelegramHitlState, resolution: InputResolution): { readonly messageId: string; readonly text: string; } | undefined; /** * Wraps Telegram callback data as a synthetic `InputResponse` (requestId prefixed * with `telegram_callback:`, optionId hardcoded to `"selected"`). It is a * placeholder; {@link resolveTelegramInputResponses} resolves it back to the real * stored response. */ export declare function telegramCallbackInputResponse(callbackData: string): ValidatedInputResponse; /** Wraps a reply-to-message id in an `InputResponse` shape for delivery. */ export declare function telegramReplyInputResponse(input: { readonly messageId: string; readonly text: string; }): ValidatedInputResponse; /** * Wraps a text message that replied to a bot message as a synthetic response, * so the deliver hook can match it to a pending ForceReply prompt. */ export declare function telegramReplyInputResponses(replyToBotMessageId: unknown, message: string | UserContent | undefined): ValidatedInputResponse[]; /** True when an input response needs Telegram-specific durable-state remapping. */ export declare function isTelegramSyntheticResponse(response: InputResponse): boolean; /** Remaps compact Telegram callback/reply ids into real eve input responses. */ export declare function resolveTelegramInputResponses(state: TelegramHitlState, responses: readonly InputResponse[]): ValidatedInputResponse[];