//#region src/channels/pause.d.ts /** * Brand attached to the signal thrown by `pause(value)` so that the * workflow runtime can recognise it across realms (Worker threads, * sandboxes, …) without `instanceof`. * * @stable */ declare const PAUSE_SIGNAL_BRAND: unique symbol; /** * Thrown by `pause(value)` from inside a workflow node. The runtime * catches it, persists state with a pending pause, and suspends the * thread until `Workflow.resume(threadId, directive)` is called. * * Application code should never construct or catch this directly - * always go through `pause(...)`. * * @stable */ declare class PauseSignal extends Error { readonly [PAUSE_SIGNAL_BRAND]: true; readonly value: TValue; constructor(value: TValue); } /** * Brand attached to the signal thrown by `pause(value)` when the * positional replay diverges from the journaled pause identity. * Cross-realm safe like {@link PAUSE_SIGNAL_BRAND}. * * @stable */ declare const REPLAY_DIVERGENCE_BRAND: unique symbol; /** * Identity of one pause as recorded next to its satisfied resume value: * the durable-primitive `kind` (`timer` / `awakeable` / * `approval`) and the awakeable/approval `name`. A plain `pause()` has * neither - two plain pauses are indistinguishable BY DESIGN (no * false positives; the check is deliberately conservative). * * @stable */ interface PauseIdentity { readonly kind?: string; readonly name?: string; } /** * Thrown by `pause(value)` during replay when the CURRENT pause's * identity does not match what the journal recorded for this cursor * position: the node body's pause order depends on * time/state/LLM output, so a positional replay would silently hand a * resume value to the wrong pause. The workflow engine converts this * into a typed `pause-replay-divergence` WorkflowError. * * @stable */ declare class ReplayDivergenceSignal extends Error { readonly [REPLAY_DIVERGENCE_BRAND]: true; readonly expected: PauseIdentity; readonly actual: PauseIdentity; readonly cursor: number; constructor(expected: PauseIdentity, actual: PauseIdentity, cursor: number); } /** Cross-realm safe type guard for {@link ReplayDivergenceSignal}. @stable */ declare function isReplayDivergenceSignal(err: unknown): err is ReplayDivergenceSignal; /** * Resume-injection scope set by the workflow runtime around the second * (and later) invocations of a paused node body. When the scope is * present, `pause(...)` consults it to decide whether to throw a fresh * {@link PauseSignal} or return the injected value the runtime supplied * via `Workflow.resume(threadId, new Directive({ resume }))`. * * This is the storage mechanism that gives `pause()` its symmetric * pair semantics (`pause` ↔ `resume`) without forcing every node body * to be re-architected as a state machine. * * @internal */ interface PauseResumeScope { /** Ordered resume values replayed to successive `pause()` calls. */ readonly values: ReadonlyArray; /** * Per-value identity of the pause each value answered. * Absent (legacy checkpoints) or `null`/empty entries skip the check. */ readonly meta?: ReadonlyArray; cursor: number; } /** * Run `fn` inside a scope where successive `pause(...)` calls return the * supplied `values` in order instead of throwing a fresh * {@link PauseSignal} (a node body re-executes from the top on * every resume, so earlier pauses must replay their already-delivered * values and only the FIRST unsatisfied `pause()` suspends again). An * empty `values` array behaves exactly like no scope - every `pause()` * suspends - which is what a static-gate resume needs so a programmatic * `pause()` inside the node is never silently satisfied. * * This helper is the contract between the runtime and `pause(...)`. * Consumers of `pause(...)` never call it directly - only the workflow * engine wires it up around the resumed node body. * * @internal */ declare function runWithPauseResume(values: ReadonlyArray, fn: () => R | Promise, meta?: ReadonlyArray): Promise; /** * Programmatically suspend the current workflow node. The `value` is * surfaced to callers via the `WorkflowSuspendedEvent.value` field; the * eventual `Directive({ resume })` is delivered as the return value of * this call once the runtime resumes the thread. * * Implementation note: when the call is made outside a runtime-managed * resume scope, `pause(...)` throws a fresh {@link PauseSignal} so the * engine can catch it, persist state, and suspend. When the runtime * later resumes the node body, it wraps the second invocation in * {@link runWithPauseResume}, which causes the same `pause(...)` call to * return the operator-supplied resume value instead of throwing. * * @stable */ declare function pause(value: TValue): TResume; /** * Cross-realm safe type guard for `PauseSignal`. * * @stable */ declare function isPauseSignal(err: unknown): err is PauseSignal; //#endregion export { PAUSE_SIGNAL_BRAND, PauseIdentity, PauseResumeScope, PauseSignal, REPLAY_DIVERGENCE_BRAND, ReplayDivergenceSignal, isPauseSignal, isReplayDivergenceSignal, pause, runWithPauseResume }; //# sourceMappingURL=pause.d.ts.map