import { type QueuedCommand } from "./queue-state.ts"; import { type QueueModes } from "./queue-policy.ts"; import { type DispatchOutcome, type QueueBoundary, type QueueCheckpoint, type QueueEvent, type QueueReply, type QueueRow, type QueueView } from "./protocol.ts"; export * from "./protocol.ts"; export { DeliveryQueue, QueueEditSession } from "./queue-state.ts"; export { headDeliveryBatch, itemCommand, laneIsHeld, type QueueModes } from "./queue-policy.ts"; export interface DispatchResult { outcome: DispatchOutcome; error?: string; } export interface QueuePorts { /** Resolve on native acceptance; reject/throw without proof of rejection means uncertain. */ send(row: QueueRow, context: { attemptId: string; boundary: QueueBoundary; signal: AbortSignal; }): Promise; /** Resolve completed only after the control/gate finishes. Acceptance alone is insufficient. */ command?(row: QueueRow, command: QueuedCommand, context: { attemptId: string; boundary: QueueBoundary; signal: AbortSignal; }): Promise; /** Must be implemented at the server tool boundary, not by a delayed client-side abort. */ gracefulPause?(): Promise; /** Awaited durable write before side effects; omit only for an ephemeral queue. */ persist?(checkpoint: QueueCheckpoint): void | Promise; } export type QueueLifecycle = { type: "agent-start"; } | { type: "tail"; phase: "turn" | "agent"; stopReason?: string; failed?: boolean; } | { type: "settled"; } | { type: "compaction-start"; reason: "manual" | "threshold" | "overflow"; } | { type: "compaction-end"; failed: boolean; }; /** Transport-independent owner of the existing two-depth FIFO queue machinery. */ export declare class QueueController { private readonly queue; private edit; private readonly hold; private revision; private persistence; private pendingWrites; private attempt; private readonly listeners; private readonly requests; private flight; private uncertain; private compaction; private graceful; private disposed; private idle; private agentBoundaryBlocked; private readonly modes; readonly sessionId: string; private readonly ports; constructor(options: { sessionId: string; ports: QueuePorts; modes?: QueueModes; checkpoint?: QueueCheckpoint; }); checkpoint(): QueueCheckpoint; snapshot(): QueueView; subscribe(listener: (event: QueueEvent) => void): () => void; private publish; /** Wait for all writes scheduled so far (including writes scheduled while awaiting). */ flush(): Promise; private changed; request(value: unknown): Promise; private row; private apply; observe(event: QueueLifecycle): void; /** One eligible batch per boundary. No timer, enqueue, save or restore sends on its own. */ dispatch(boundary: QueueBoundary): Promise; /** Cancel ownership, not the remote run. Late acknowledgments can never consume restored rows. */ dispose(): Promise; }