eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
60 lines (59 loc) • 3.16 kB
TypeScript
/**
* 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 { InputRequest, InputResponse } from "#runtime/input/types.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 sent through `send()` 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<string, InputResponse>;
nextHitlCallbackId?: number;
pendingFreeformReplies?: Record<string, 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<Record<string, unknown>>;
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;
/**
* 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): InputResponse;
/** Wraps a reply-to-message id in an `InputResponse` shape for delivery. */
export declare function telegramReplyInputResponse(input: {
readonly messageId: string;
readonly text: string;
}): InputResponse;
/** 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[]): InputResponse[];