/** * File-based per-thread message broker. * * Incoming Telegram messages are written by the poller to per-thread JSONL * files under ~/.remote-copilot-mcp/threads/.jsonl. * Each MCP instance reads from its own thread file — contention-free. */ import type { SentMessageRepository } from "../../data/sent-message.repository.js"; export declare const OFFSET_FILE: string; export declare function setBrokerSentMessageRepository(repository: SentMessageRepository): void; export declare function resolveThreadForTopic(telegramTopicId: number): number; export interface StoredReaction { emoji: string; messageId: number; chatId: number; date: number; } export declare function writeReactionFile(reaction: StoredReaction): void; /** * Read and clear the pending reaction (if any). * When threadId is provided, reads from the per-thread file first, then falls * back to the global file — but only consumes a global reaction whose owner is * known to be exactly this thread (see readGlobalReactionGuarded). Unknown-owner * reactions are left for the general session and never stolen by a thread. * Returns null if no reaction is pending. */ export declare function readPendingReaction(threadId?: number): StoredReaction | null; export declare function ensureDirs(): void; export declare function readOffset(): number; export declare function writeOffset(offset: number): void; export interface StoredMessage { update_id: number; message: { message_id: number; chat_id: number; text?: string; caption?: string; /** * The excerpt the operator highlighted when replying (Telegram "quote"). * Optional — absent for every message that isn't a quoted reply, so older * JSONL lines and injected messages stay valid as-is. */ quote?: string; message_thread_id?: number; photo?: Array<{ file_id: string; width: number; height: number; }>; document?: { file_id: string; file_name?: string; mime_type?: string; }; voice?: { file_id: string; duration: number; mime_type?: string; }; video_note?: { file_id: string; length: number; duration: number; }; sticker?: { file_id: string; emoji?: string; set_name?: string; }; animation?: { file_id: string; duration?: number; thumbnail?: { file_id: string; }; }; date: number; }; } /** * Append a message to a thread's JSONL file. * Throws on write failure so the caller can track which messages were persisted. */ export declare function appendToThread(threadId: number | "general", msg: StoredMessage): void; /** * Inject operator-shaped text into a thread's message file so the agent's wait * loop delivers it exactly as if the operator had typed it. Shared by the * dashboard inject route and the poller's /prompts button handler. */ export declare function injectOperatorMessage(threadId: number | "general", text: string, options?: { topicId?: number; chatId?: number; }): void; /** * Read and clear all pending messages for a thread. * Uses rename for atomic read-and-clear to prevent message loss. */ export declare function readThreadMessages(threadId: number | undefined): StoredMessage[]; /** * Non-destructive peek at pending messages for a thread. * Unlike readThreadMessages, this does NOT consume the messages — they remain * in the thread file for the next readThreadMessages call. */ export declare function peekThreadMessages(threadId: number | undefined): StoredMessage[]; //# sourceMappingURL=broker.d.ts.map