/** * DefaultMailbox — append-only JSONL inter-agent mailbox (per-session). * * Stores messages under `/_mailbox.jsonl`. Every send appends * one line. Query reads and filters all lines. Ack rewrites changed * messages in-place via atomic write. * * For cross-session communication, use GlobalMailbox instead. * * @module DefaultMailbox */ import type { Logger } from '../types/logger.js'; import type { AgentHeartbeatInput, AgentRegistrationInput, AutoCompactOptions, AutoCompactResult, ClientHeartbeatInput, ClientRegistrationInput, ClientStatus, Mailbox, MailboxAckBatchInput, MailboxAckInput, MailboxAgentStatus, MailboxMessage, MailboxQuery, MailboxSendInput, PurgeOptions, PurgeResult } from './mailbox-types.js'; export declare class DefaultMailbox implements Mailbox { private readonly filePath; private _messageCache; private _messageCacheMtime; private _messageCacheSize; /** True when the cache is only the newest MESSAGE_CACHE_MAX_ENTRIES records. */ private _messageCacheTruncated; /** Primary index: recipient → Set of messages (points into _messageCache). */ private _byTo; /** Secondary index: sender → Set of messages (points into _messageCache). */ private _byFrom; /** Counts malformed JSONL lines skipped during parsing for observability. */ private _corruptionCount; private readonly logger; constructor(sessionDir: string, opts?: { logger?: Logger | undefined; }); get mailboxPath(): string; /** Returns the count of malformed JSONL lines encountered during reads. */ get corruptionCount(): number; send(input: MailboxSendInput): Promise; query(q: MailboxQuery): Promise; ack(input: MailboxAckInput): Promise; softDelete(_mailId: string, _by: string): Promise; restore(_mailId: string): Promise; ackMany(input: MailboxAckBatchInput): Promise; getAgentStatuses(): Promise; getOnlineAgents(): Promise; registerAgent(_input: AgentRegistrationInput): Promise; deregisterAgent(_agentId: string): Promise; heartbeat(_input: AgentHeartbeatInput): Promise; unreadCount(forAgentId: string, sessionId?: string): Promise; close(): Promise; clearAll(): Promise; purgeStale(opts?: PurgeOptions): Promise; autoCompact(_opts?: AutoCompactOptions): Promise; startAutoCompactTimer(_opts?: AutoCompactOptions): () => void; registerClient(_input: ClientRegistrationInput): Promise; clientHeartbeat(_input: ClientHeartbeatInput): Promise; deregisterClient(_clientId: string): Promise; getClientStatuses(): Promise; purgeClients(): Promise; private _readAll; /** * Read only newly-appended bytes from the file and append them to the * in-memory cache, avoiding a full re-read when the file only grew. * * Guards against a half-written tail: when the tail doesn't end with * LINE_SEPARATOR, another process may be mid-append. Parsing a partial * JSON line would throw (caught below), but worse: the NEXT incremental * read would skip that same line because the size tracker already advanced. */ private _readNewMessagesOnly; private _appendIncrementalLines; private _parseLine; /** Parse a JSONL string into MailboxMessage[], including migration. */ private _parseLines; /** * Stat the mailbox file under the assumption that we are holding the * file lock, and that a write to the file has just completed. Returns * the (mtimeMs, size) pair, or (-1, -1) if the file does not exist * (e.g. ackMany/purgeStale on a session that has never sent a message). */ private _statUnderLockOrAbsent; private _readAllCached; private _setMessageCache; private _pushToCache; /** Rebuild both indexes from a full message list. */ private _buildIndexes; /** Add a single message to both indexes. */ private _indexMsg; /** Remove an evicted message from both indexes without rebuilding them. */ private _unindexMsg; } //# sourceMappingURL=mailbox.d.ts.map