import { S as Store } from './runtime-types-f231H8Gq.js'; /** * internal/work-queue — substrate-agnostic work-queue lifecycle on `Store`. * * Two public surfaces, one shape: * - `createQueue(store)` (this file) is the in-process adapter — it binds the * pure ops to an injected `Store` and runs `load → mutate → save`. * - `internal/work-queue/ops` (`./ops`) is the BLESSED, importable surface * of those same pure ops. L2 compositions that own their own Model slice * (`monitored-run`, `idempotent-intake`, …) import the ops directly and * delegate status flips to them instead of re-rolling the transitions. * Both routes call the identical ops, so the lifecycle rules live in exactly * one place. This mirrors `@demlik/tea/do`'s one-shape-per-package rule. * * The package is generic in the input payload `I` (audit-specific fields go * here in the extension host). `output` is a free-form side-channel correlation * token (a backend id, URL, trace id) — typed as `string` because that's its * only honest type. Consumers that need structured per-item data persist it in * their own store and put the foreign-key string in `output`. */ /** * Where a queue item is in its lifecycle: `pending`, `running`, `done`, * `failed` or `cancelled`. */ type QueueItemStatus = "pending" | "running" | "done" | "failed" | "cancelled"; /** * A single queue entry. Every field is `readonly`: a persisted slice is * immutable, so a transition returns a NEW item (the ops always spread — * `{ ...item, status: … }`) rather than mutating in place. This type-enforces * the durability invariant the consumers already honor by convention, and * keeps a slice round-trippable through JSON unchanged across a reload. */ interface QueueItem { readonly id: string; readonly status: QueueItemStatus; readonly input: I; readonly enqueuedAt: number; readonly startedAt?: number; readonly finishedAt?: number; readonly output?: string; readonly error?: string; } /** * Caller-facing enqueue payload. Just `I` today — kept named so future * variants (priority, deferUntil, …) can grow without breaking callers. */ type EnqueueInput = I; /** * Adapter that binds the pure ops to an injected `Store[]>`. * * `load → mutate → save` is the only durability discipline this package * imposes. The store decides what "save" means (chrome.storage, KV, DO * storage, in-memory) — that decision belongs at the caller. * * Ops that don't change the queue (e.g. `markDone` on an unknown id) skip the * save call so the underlying store doesn't observe a write churn. */ declare function createQueue(store: Store[]>): { enqueue: (input: EnqueueInput) => Promise>; claimNext: () => Promise | null>; markDone: (id: string) => Promise; markFailed: (id: string, error: string) => Promise; markCancelled: (id: string) => Promise; resetRunningToPending: () => Promise; removeItem: (id: string) => Promise; retryItem: (id: string) => Promise; bindOutput: (id: string, value: string) => Promise; list: () => Promise[]>; }; export { type EnqueueInput as E, type QueueItem as Q, type QueueItemStatus as a, createQueue as c };