/** * state.ts — Transport-agnostic mutable state for the watcher subsystem. * * All shared runtime state lives here. No transport SDK imports. * Transport-specific state (Baileys socket, GramJS client, chat/message stores) * remains in the per-project packages. */ import type { RegisteredSession, QueuedMessage, ClientWaiter, ContactEntry, VoiceConfig } from "../types/index.js"; export declare const sessionRegistry: Map; export declare const managedSessions: Map; export declare const sessionTtyCache: Map; export declare let activeClientId: string | null; export declare let activeItermSessionId: string; export declare let lastRoutedSessionId: string; export declare function setLastRoutedSessionId(id: string): void; export declare function setActiveClientId(id: string | null): void; export declare function setActiveItermSessionId(id: string): void; export declare function updateSessionTtyCache(entries: Array<{ id: string; tty: string; }>): void; export declare let cachedSessionList: Array<{ id: string; name: string; path: string; type: "claude" | "terminal"; paiName: string | null; atPrompt: boolean; }> | null; export declare let cachedSessionListTime: number; export declare function setCachedSessionList(list: typeof cachedSessionList, time: number): void; export declare const clientQueues: Map; export declare const clientWaiters: Map; export declare const contactMessageQueues: Map; export declare const contactDirectory: Map; export declare let voiceConfig: VoiceConfig; export declare function setVoiceConfig(cfg: VoiceConfig): void; import type { AibpBridge } from "../aibp/bridge.js"; export declare function setAibpBridge(bridge: AibpBridge): void; export declare function getAibpBridge(): AibpBridge | null; export type CommandHandler = (text: string, timestamp: number) => void | Promise; export declare let commandHandler: CommandHandler | null; export declare function setCommandHandler(handler: CommandHandler | null): void; export type MessageSource = string; export declare let messageSource: MessageSource; export declare function setMessageSource(src: MessageSource): void; export declare const sentMessageIds: Set; export interface MailboxMessage { from: string; content: string; timestamp: number; /** * Set once this message has been reported as stale. * * "Queued" is an honest answer at the moment of sending and a false one four * hours later: a message nobody drained is undelivered, not pending. The flag * exists so the fault is reported once rather than every sweep. */ staleReported?: boolean; /** * Unix ms the drain-mailbox hook emitted this message. The hook's output does * not always reach the model (a message typed mid-turn lost its body live on * 2026-10-10), so the hook marks instead of deleting: aibroker_receive still * returns it, flagged, until it is read or SHOWN_RETAIN_MS passes. Absent on * entries that predate the flag, which therefore count as unshown. */ shownAt?: number; } /** * Deposit a message, returning anything the queue had to drop to fit it. * * The overflow used to be a bare `shift()`. A message evicted that way was * undelivered and left no trace anywhere — the same silent drop this mailbox * exists to prevent, one level down. The caller gets it back so it can be * recorded. */ export declare function depositToSessionMailbox(itermSessionId: string, from: string, content: string): MailboxMessage | undefined; /** * Read-only view of every mailbox, for anything that needs to age its contents. * * Returns the live message objects deliberately: a sweep marks what it has * already reported, and copying would lose that. */ export declare function listSessionMailboxes(): Array<{ sessionId: string; messages: MailboxMessage[]; }>; export declare function setAttachAlias(paneId: string, claudeSessionId: string | undefined): void; export declare function rememberIdSession(id: string, claudeSessionId: string | undefined): void; export declare function claudeSessionOfId(id: string): string | undefined; /** * The pane that actually serves an id. An id that is not a live Claude pane * (its session was moved into a background session, the old pane is gone or a * shell) maps to the `claude attach` pane of the same Claude session, when its * uuid was seen; every other id is returned unchanged. */ export declare function liveSessionFor(id: string, snaps: { id: string; isClaude?: boolean; attachUuid?: string; }[]): string; /** Whether an attach pane is already known for this Claude session uuid. */ export declare function hasAttachAlias(claudeSessionId: string): boolean; /** Every mailbox key a caller reads: its own id plus any pane viewing its session. */ export declare function mailboxKeys(id: string | undefined, claudeSessionId?: string): string[]; /** * Non-destructive read of one mailbox (or several, see mailboxKeys), for the * two-phase drain (peek → emit → ack) the drain-mailbox hook uses. Copy, not * the live queue, so the caller cannot mutate what a later ack will clear. */ export declare function peekSessionMailbox(ids: string | string[], now?: number): MailboxMessage[]; /** * Phase 2 of the hook's drain: mark the oldest `count` unshown messages as * shown instead of deleting them. A count (not "all") so a message deposited * after the peek stays unshown for the next one. */ export declare function markMailboxShown(ids: string | string[], count: number, now?: number): number; /** The explicit read (aibroker_receive): everything left, shown or not, then clear. */ export declare function drainSessionMailbox(ids: string | string[], now?: number): MailboxMessage[]; export declare function dispatchIncomingMessage(body: string, timestamp: number): void; export declare function enqueueContactMessage(contactId: string, body: string, timestamp: number): void; //# sourceMappingURL=state.d.ts.map