/** Shape the SDK expects for streaming-input user messages. */ export interface OrgUserMessage { type: 'user'; message: { role: 'user'; content: string; }; parent_tool_use_id: null; session_id: string; } export declare function isRecoverableCloseReason(reason: string | undefined): boolean; /** * Async message queue feeding one persistent SDK session. * push() from the daemon (deliveries from other agents / the user); * stream() is passed as the `prompt` of query() to keep the session open. */ export declare class Mailbox { private static readonly MAX_QUEUE; /** Prefix tagging self-continuation pushes (turn-limit resume) so stream() can * tell them apart from real deliveries and the restart loop can detect a role * that is spinning on its own continuations without making progress. */ static readonly CONTINUE_PREFIX = "[system:turn-continue]"; private queue; private wake; private closed; /** Why close() was called — e.g. 'token-budget' / 'usd-budget' — distinct * from a crash/terminal close (undefined). Lets callers like the idle * watchdog tell a recoverable budget pause from genuine unreachability. */ private closeReasonValue?; /** Bumped when a new stream() starts; stale generators see the mismatch and exit. */ private generation; /** Monotonic count of REAL (non-continuation) messages consumed by stream(). * The restart loop snapshots this around a session to tell progress from spin. */ private consumedReal; /** The most recently shift()ed-but-not-yet-confirmed-processed message: set * right before stream() yields it, cleared once the generator is resumed * for the next pull (proof the runner asked for more, i.e. the prior turn * finished). If a session dies with this still set, the generator was * abandoned mid-yield — see reclaimInFlight(). */ private inFlight; /** Number of real (non-continuation) messages consumed so far across all sessions. */ get consumedRealCount(): number; push(text: string): void; close(reason?: string): void; get isClosed(): boolean; /** Why close() was called, if given a reason — undefined for a plain crash/ * terminal close. See the closeReasonValue field doc for intent. */ get closeReason(): string | undefined; /** * Detach the current waker WITHOUT resolving it. Called between sessions * (maxTurns restart, crash backoff): the dead session's generator may still * be parked on `wake` inside an abandoned next() — if a push() during that * window resolved it, the stale generator would shift() the message and * yield it into a promise nobody reads (silent loss, after deliver() * already returned a "delivered" receipt). With the waker dropped, such a * push only queues; the replacement session's stream() drains it. The * parked stale generator is never resumed and becomes garbage with its * session. */ detach(): void; /** * One live generator at a time: each stream() call bumps `generation`, and * a stale generator that ever resumes exits immediately without touching * the queue. Values are shift()ed at yield time — once the consumer's * next() resolves with a message it counts as delivered (matching SDK * behavior: a session may consume a message and end without ever resuming * the generator; redelivering would duplicate work and can livelock the * restart loop). */ stream(sessionId?: string): AsyncGenerator; /** Called by the crash-retry path right after a session dies abnormally. If * a message was mid-flight — shifted for the crashed generator's yield but * never confirmed processed, because the generator was abandoned at that * yield rather than resumed for another pull — put it back at the front of * the queue so the replacement session (built by the next stream() call) * gets it first instead of the queue staying empty and the new session * parking on the mailbox forever. A no-op when nothing was in flight * (clean session end, or nothing was ever pulled). */ reclaimInFlight(): void; /** Serialize mailbox state for checkpoint/resume - Pattern 3 */ serialize(): { queue: string[]; closed: boolean; consumedReal: number; closeReason?: string; }; /** Deserialize mailbox state from checkpoint - Pattern 3 */ deserialize(state: { queue: string[]; closed: boolean; consumedReal: number; closeReason?: string; }): void; } //# sourceMappingURL=mailbox.d.ts.map