import type { InboxItem } from '../../shared/inbox.js'; import { WakeQueueStore, type TakeNextRunnableInput } from '../storage/schema/wake-queue.store.js'; export type { InboxItem }; export interface WakeQueueEnqueueResult { duplicate: boolean; item: InboxItem; queued: boolean; /** True when the item is durable but not yet claimable (preflight publish path). */ staged?: boolean; } export interface WakeQueueMessageRecorder { hasInboxItem?(itemId: string): Promise; recordInboxItem(item: InboxItem): Promise<{ inserted: boolean; } | undefined>; } interface WakeQueueLogger { warn(message: string): void; } export declare const wakeQueueServiceForAgent: (agentId: string) => WakeQueueService; export declare class WakeQueueService { readonly agentId: string; private readonly store; private readonly messages; private readonly logger; constructor(agentId: string, store?: WakeQueueStore, messages?: WakeQueueMessageRecorder, logger?: WakeQueueLogger); /** * Enqueue with the wake-queue file as the dedupe authority: the insert * atomically checks active items plus settled seen markers, so a crash * between steps can no longer drop a wake. The message ledger is written * after the item is safely queued — it is conversation history, not dedupe * state — with one legacy exception: ids settled before seen markers * existed are only known to the ledger, so a ledger hit withdraws the * just-queued item (or, if a worker already claimed it, lets it run once). */ enqueue(event: InboxItem): Promise; /** * Durable insert that workers cannot claim yet (`handling.stagedAt` set). * No wake signal and no message-ledger write (uncommitted stages must not * create phantom history or seen tombstones). Pair with `publishQueued` * after CAS, or `abandonStaged` to drop without tombstoning. Reuses an * existing still-staged row for the same id (crash recovery mid path). */ enqueueStaged(event: InboxItem): Promise; /** * Publish a staged row for claim: clear stagedAt, write message ledger, signal. * Returns false when the item is missing, already published, or no longer queued. */ publishQueued(itemId: string): Promise; /** * Remove a still-queued (unclaimed) item and mark it seen (true settle/dedupe). */ withdrawQueued(itemId: string): Promise; /** * Atomically settle multiple still-claimable queued items to seen (one store * update). Cursor-delivery coalescing uses this so the selected same-surface * set cannot partially land. */ withdrawQueuedBatch(itemIds: string[]): Promise; /** * Drop an uncommitted staged wake without a seen tombstone so the same fire * id remains reusable after cancel/snooze CAS miss. */ abandonStaged(itemId: string): Promise; hasSeen(itemId: string): Promise; find(itemId: string): Promise; replaceItem(item: InboxItem): Promise; replaceQueuedItem(item: InboxItem): Promise; list(): Promise; takeNextRunnable(input: TakeNextRunnableInput): Promise; takeFollowupBatch(input: { activeItemId: string; excludedItemIds?: Iterable; limit: number; workerId: string; }): Promise; complete(itemId: string): Promise; completeAppendedTo(parentItemId: string): Promise; fail(itemId: string): Promise; failAppendedTo(parentItemId: string): Promise; requeue(itemId: string, options?: { resumeReason?: 'runtime_restart'; }): Promise; /** * Requeue without signalWake. Used when cursor-delivery prepare fails closed * mid-drain: a wake would set pendingWake and immediately reclaim the same * item in a hot loop. The regular poll timer retries later. */ requeueQuiet(itemId: string, options?: { resumeReason?: 'runtime_restart'; }): Promise; requeueBatch(itemIds: string[]): Promise; requeueAppendedTo(parentItemId: string, options?: { resumeReason?: 'runtime_restart'; }): Promise; requestStop(itemId: string): Promise; requestDrain(input: { itemId: string; timeoutMs: number; }): Promise; clearDrainRequest(itemId: string): Promise; markRunning(input: { itemId: string; startedAt?: string; workerId: string; }): Promise; markAppended(input: { itemId: string; parentItemId: string; workerId: string; }): Promise; markAppendedBatch(input: { itemIds: string[]; parentItemId: string; workerId: string; }): Promise; markSettled(input: { itemId: string; workerId: string; }): Promise; private recordMessage; } //# sourceMappingURL=wake-queue.service.d.ts.map