import { I as IdempotencyStore } from '../index-Bc40JWVl.js'; export { a as IdempotencyEntry, e as evictExpired, i as initStore, r as recall, b as remember, s as seen } from '../index-Bc40JWVl.js'; import { C as CmdOf, a as CmdDef } from '../core-sEWVgnpI.js'; import { Q as QueueItem } from '../index-DmoyvP-O.js'; import '@standard-schema/spec'; import '../runtime-types-f231H8Gq.js'; /** * A cached intake entry: either a key whose work is still in flight * (`pending`) or one whose work has finished and whose `result` is held for * replay to later duplicates (`done`). Discriminated on `phase` — `pending` * carries no payload, `done` carries the result `R`. * * Lives inside the `seen` half of the slice (`IdempotencyStore>`). * It is the dedupe ledger's *value*; the ledger's *key* is `keyOf(payload)`. */ type IntakeEntry = { readonly phase: "pending"; } | { readonly phase: "done"; readonly result: R; }; /** * The intake knob's config — `keyOf` derives the idempotency key from a * payload, `ttlMs` (optional) ages a *completed* cached key out so a webhook * replayed long after the work finished is treated as new and re-processed. * * **The TTL clock starts at `complete`, not at `receive`.** A `pending` entry * (work still in flight) NEVER ages out, no matter how slow the worker is — * ageing a pending key would let the duplicate re-enqueue the in-flight * payload and double-process it. Only a `done` entry expires, measured from * the `at` passed to `complete` (the moment the result was cached). Inside the * window a duplicate replays the cached result; at/after the window it is * re-accepted and re-processed. * * Omit `ttlMs` for a cache whose `done` entries never expire by age (keys live * forever — fine for a bounded universe of ids, unbounded growth otherwise). * * The TTL is owned HERE, not delegated to the composed `IdempotencyStore`: the * store's uniform per-entry TTL cannot tell `pending` from `done`, so intake * keeps the store TTL-free and applies the phase-aware rule itself (see * `liveEntry`). */ interface IntakeConfig

{ /** Derive the idempotency key from a payload. Must be pure + deterministic. */ readonly keyOf: (payload: P) => string; /** * Age a *completed* key out after this many ms, measured from the `at` * passed to `complete`. Pending keys never age out. */ readonly ttlMs?: number; } /** * The Model slice this knob owns. `seen` is the dedupe + last-result cache * (the `../idempotency` brick); `queue` is the pending-work list (the * `../work-queue` brick). Both are plain serializable values — the whole slice * round-trips through `JSON` so it survives eviction and replays exactly. */ interface IntakeState { readonly seen: IdempotencyStore>; readonly queue: readonly QueueItem

[]; } /** A genuinely-new payload was accepted and enqueued — go run the work. */ declare function intakeProcessDef

(): CmdDef<"intake:process", { /** The dedupe key the payload was filed under. */ readonly key: string; /** The enqueued queue-item id (the same `id` passed to `receive`). */ readonly itemId: string; /** The original payload, for the worker to process. */ readonly payload: P; }, undefined, never>; /** * The Cmd intake emits for a first-time request: process `payload` for the * queue item `itemId`. */ type IntakeProcessCmd

= CmdOf>>; /** * A duplicate of an already-completed key arrived — replay the cached result * to the caller instead of re-running the side effect. */ declare function intakeReplayDef(): CmdDef<"intake:replay", { /** The dedupe key whose cached result is being replayed. */ readonly key: string; /** The result the ORIGINAL request produced, recalled from the cache. */ readonly result: R; }, undefined, never>; /** * The Cmd intake emits for a duplicate of a completed request: hand back the * cached `result` instead of redoing the work. */ type IntakeReplayCmd = CmdOf>>; /** The Cmd union the intake verbs emit. */ type IntakeCmd = IntakeProcessCmd

| IntakeReplayCmd; /** * Build an idempotent-intake knob from `config`. Returns the uniform L2 * contract — `init()` + the verbs (`receive`, `complete`, `boot`, `claimNext`). * No `subs` / `handlers`: intake owns no timers and does no I/O of its own (the * composed bricks are pure-ops; the worker that runs `IntakeProcess` and the * responder that runs `IntakeReplay` live in the host's interpret map). */ declare function createIntake(config: IntakeConfig

): { init: () => IntakeState; receive: (state: IntakeState, payload: P, at: number, id: string) => readonly [IntakeState, readonly IntakeCmd[]]; complete: (state: IntakeState, key: string, result: R, at: number) => readonly [IntakeState, readonly IntakeCmd[]]; boot: (state: IntakeState) => readonly [IntakeState, readonly IntakeCmd[]]; claimNext: (state: IntakeState, at: number) => { readonly state: IntakeState; readonly claimed: QueueItem

; } | null; }; export { IdempotencyStore, type IntakeCmd, type IntakeConfig, type IntakeEntry, type IntakeProcessCmd, type IntakeReplayCmd, type IntakeState, createIntake, intakeProcessDef, intakeReplayDef };