eve 0.31.1 → 0.31.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/src/compiled/.vendor-stamp.json +6 -6
  3. package/dist/src/compiled/@workflow/core/_quickjs-wasi.d.ts +8 -0
  4. package/dist/src/compiled/@workflow/core/correlation-id.d.ts +109 -0
  5. package/dist/src/compiled/@workflow/core/events-consumer.d.ts +1 -0
  6. package/dist/src/compiled/@workflow/core/index.js +2 -2
  7. package/dist/src/compiled/@workflow/core/private.d.ts +17 -1
  8. package/dist/src/compiled/@workflow/core/private.js +1 -1
  9. package/dist/src/compiled/@workflow/core/runtime/constants.d.ts +19 -0
  10. package/dist/src/compiled/@workflow/core/runtime/deployment-guard.d.ts +99 -0
  11. package/dist/src/compiled/@workflow/core/runtime/quickjs-assets.generated.d.ts +14 -0
  12. package/dist/src/compiled/@workflow/core/runtime/quickjs-entrypoint.d.ts +124 -0
  13. package/dist/src/compiled/@workflow/core/runtime/quickjs-runtime.d.ts +193 -0
  14. package/dist/src/compiled/@workflow/core/runtime/run.d.ts +2 -0
  15. package/dist/src/compiled/@workflow/core/runtime/runs.d.ts +18 -1
  16. package/dist/src/compiled/@workflow/core/runtime/suspension-handler.d.ts +7 -0
  17. package/dist/src/compiled/@workflow/core/runtime/vm-mode.d.ts +44 -0
  18. package/dist/src/compiled/@workflow/core/runtime/vm-serde-bundle.generated.d.ts +14 -0
  19. package/dist/src/compiled/@workflow/core/runtime.d.ts +1 -1
  20. package/dist/src/compiled/@workflow/core/runtime.js +3 -3
  21. package/dist/src/compiled/@workflow/core/serialization/codec-devalue-vm.d.ts +9 -0
  22. package/dist/src/compiled/@workflow/core/serialization/reducers/class-vm.d.ts +20 -0
  23. package/dist/src/compiled/@workflow/core/serialization/reducers/common-vm.d.ts +15 -0
  24. package/dist/src/compiled/@workflow/core/serialization/reducers/step-function-vm.d.ts +44 -0
  25. package/dist/src/compiled/@workflow/core/serialization/vm-bundle-entry.d.ts +12 -0
  26. package/dist/src/compiled/@workflow/core/serialization/workflow-vm.d.ts +24 -0
  27. package/dist/src/compiled/@workflow/core/serialization.d.ts +2 -1
  28. package/dist/src/compiled/@workflow/core/source-map.d.ts +20 -0
  29. package/dist/src/compiled/@workflow/core/telemetry/semantic-conventions.d.ts +78 -0
  30. package/dist/src/compiled/@workflow/core/telemetry.d.ts +5 -0
  31. package/dist/src/compiled/@workflow/core/version.d.ts +1 -1
  32. package/dist/src/compiled/@workflow/core/workflow.js +1 -1
  33. package/dist/src/compiled/@workflow/errors/error-codes.d.ts +2 -0
  34. package/dist/src/compiled/@workflow/errors/index.d.ts +24 -0
  35. package/dist/src/compiled/@workflow/errors/index.js +1 -1
  36. package/dist/src/compiled/@workflow/world/analytics.d.ts +2 -0
  37. package/dist/src/compiled/@workflow/world/events.d.ts +51 -1
  38. package/dist/src/compiled/@workflow/world/hooks.d.ts +1 -0
  39. package/dist/src/compiled/@workflow/world/index.d.ts +1 -1
  40. package/dist/src/compiled/@workflow/world/interfaces.d.ts +28 -1
  41. package/dist/src/compiled/@workflow/world/queue.d.ts +8 -0
  42. package/dist/src/compiled/@workflow/world/runs.d.ts +83 -0
  43. package/dist/src/compiled/@workflow/world-local/index.js +5 -4
  44. package/dist/src/compiled/@workflow/world-vercel/index.js +15 -15
  45. package/dist/src/compiled/_chunks/workflow/_eve-core-quickjs-entrypoint-stub-qIV0OaFz.js +1 -0
  46. package/dist/src/compiled/_chunks/workflow/{attribute-changes-DROfGk6l.js → attribute-changes-Du5ztewf.js} +2 -2
  47. package/dist/src/compiled/_chunks/workflow/{dist-D5bR13zs.js → dist-CNXUKQCp.js} +1 -1
  48. package/dist/src/compiled/_chunks/workflow/dist-CRTn4Sg8.js +3 -0
  49. package/dist/src/compiled/_chunks/workflow/dist-tJoQXAF6.js +1 -0
  50. package/dist/src/compiled/_chunks/workflow/functions-ClJbpZhR.js +1 -0
  51. package/dist/src/compiled/_chunks/workflow/{private-BcwCGTV5.js → private-CiWVdS5v.js} +1 -1
  52. package/dist/src/compiled/_chunks/workflow/resume-hook-CT0keOww.js +1 -0
  53. package/dist/src/compiled/_chunks/workflow/run-DBheaFhH.js +1 -0
  54. package/dist/src/compiled/_chunks/workflow/signal-exit-C8vsI6zj.js +1 -0
  55. package/dist/src/compiled/_chunks/workflow/sleep-BeH4B0Cd.js +1 -0
  56. package/dist/src/compiled/_chunks/workflow/{token-hiUWkDKe.js → token-DtCUEpJs.js} +1 -1
  57. package/dist/src/compiled/_chunks/workflow/{token-util-DURSL1l8.js → token-util-DNwIAn_u.js} +9 -9
  58. package/dist/src/compiled/_chunks/workflow/undici-CUIybhQ2.js +95 -0
  59. package/dist/src/compiled/_chunks/workflow/wait-until-CMX5LUWJ.js +15 -0
  60. package/dist/src/internal/application/package.js +1 -1
  61. package/dist/src/setup/scaffold/create/project.js +1 -1
  62. package/package.json +6 -6
  63. package/dist/src/compiled/_chunks/workflow/dist-B-vbuNqP.js +0 -1
  64. package/dist/src/compiled/_chunks/workflow/dist-dNxTT6nO.js +0 -3
  65. package/dist/src/compiled/_chunks/workflow/functions-CiVUVDNB.js +0 -1
  66. package/dist/src/compiled/_chunks/workflow/resume-hook-bc-OQVI0.js +0 -1
  67. package/dist/src/compiled/_chunks/workflow/run-DM3ouA3U.js +0 -1
  68. package/dist/src/compiled/_chunks/workflow/sleep-D5iWly6-.js +0 -1
  69. package/dist/src/compiled/_chunks/workflow/undici-DWL_MYmT.js +0 -95
  70. package/dist/src/compiled/_chunks/workflow/wait-until-DoW76jdb.js +0 -15
@@ -0,0 +1,44 @@
1
+ /**
2
+ * VM-compatible copy: identical semantics to step-function.ts before the host-side
3
+ * hardening (#3257) made that module depend on `serialization/hardened.ts`
4
+ * (which imports `node:util` and captures host intrinsics — meaningless
5
+ * and unbundleable inside the QuickJS VM, where the codec already runs in
6
+ * the guest realm). The host/guest boundary hardening for the QuickJS
7
+ * engine lands with the host-side serde (#3263), which retires this
8
+ * bundle entirely. Wire format is identical to the hardened host version.
9
+ */
10
+ /**
11
+ * Reducer and reviver for step function references.
12
+ *
13
+ * In workflow mode, step functions are replaced by the SWC plugin with
14
+ * proxies created by `globalThis[Symbol.for("WORKFLOW_USE_STEP")]("stepId")`.
15
+ * These proxies have a `.stepId` property and optionally a `.__closureVarsFn`
16
+ * for captured closure variables. They may additionally have `.__boundThis`
17
+ * (and rarely `.__boundArgs`) when the SWC plugin emitted
18
+ * `useStep(...).bind(this)` for a nested arrow step that lexically
19
+ * captured `this` (see `packages/swc-plugin-workflow/spec.md` → "Lexical
20
+ * `this` Capture in Nested Arrow Steps").
21
+ *
22
+ * The reducer serializes them as
23
+ * `{ stepId, closureVars?, boundThis?, boundArgs? }`.
24
+ * The reviver reconstructs them by calling WORKFLOW_USE_STEP and, when
25
+ * `boundThis` (or `boundArgs`) is present, re-binding the resulting
26
+ * proxy so the caller's captured `this` (and prefilled args) survive the
27
+ * round trip.
28
+ */
29
+ import type { Reducers, Revivers } from '../types.js';
30
+ export declare function getStepFunctionReducer(): Partial<Reducers>;
31
+ /**
32
+ * Create the StepFunction reviver for workflow context.
33
+ *
34
+ * The reviver calls WORKFLOW_USE_STEP to create the step proxy,
35
+ * restoring the ability to call the step from workflow code. If the
36
+ * serialized payload includes `boundThis` (and optionally `boundArgs`),
37
+ * the reviver also re-binds the freshly-created proxy so a step proxy
38
+ * that was constructed with `.bind(this, …)` in the workflow bundle
39
+ * continues to carry that receiver and any prefilled arguments after
40
+ * being deserialized in another bundle (e.g. when passed as a step
41
+ * argument).
42
+ */
43
+ export declare function getStepFunctionReviver(global?: Record<string, any>): Partial<Revivers>;
44
+ //# sourceMappingURL=step-function-vm.d.ts.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Entry point for the VM serialization bundle.
3
+ *
4
+ * This file is bundled by esbuild into a self-contained IIFE that
5
+ * sets up serialize/deserialize on globalThis. The bundled output
6
+ * is evaluated inside the QuickJS VM during bootstrap.
7
+ *
8
+ * TextEncoder, TextDecoder, and Headers are provided by native C
9
+ * extensions in quickjs-wasi, so no polyfills are needed.
10
+ */
11
+ export {};
12
+ //# sourceMappingURL=vm-bundle-entry.d.ts.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * VM-compatible workflow mode serialization.
3
+ *
4
+ * This module is designed to be bundled into the QuickJS WASM VM.
5
+ * It has NO Node.js dependencies (no Buffer, no node:util).
6
+ *
7
+ * Produces and consumes the same wire format as the Node.js workflow.ts —
8
+ * format-prefixed devalue data ("devl" + devalue.stringify output).
9
+ */
10
+ /**
11
+ * Serialize a value to format-prefixed bytes.
12
+ *
13
+ * @param value - The value to serialize
14
+ * @returns Uint8Array with "devl" prefix + devalue payload
15
+ */
16
+ export declare function serialize(value: unknown): Uint8Array;
17
+ /**
18
+ * Deserialize format-prefixed bytes back to a value.
19
+ *
20
+ * @param data - Uint8Array with format prefix, or legacy non-binary data
21
+ * @returns The deserialized value
22
+ */
23
+ export declare function deserialize(data: Uint8Array | unknown): unknown;
24
+ //# sourceMappingURL=workflow-vm.d.ts.map
@@ -394,7 +394,8 @@ export declare function dehydrateWorkflowReturnValue(value: unknown, _runId: str
394
394
  * not avoid, for callers that need them programmatically (e.g. a
395
395
  * retained-VM gate deciding whether the VM is still reusable). The
396
396
  * executions are emitted as span attributes either way, so omitting this
397
- * loses nothing observability-wise. No runtime caller passes one yet.
397
+ * loses nothing observability-wise. The retained-VM gate in
398
+ * runtime/suspension-handler.ts passes one for step-input dehydration.
398
399
  */
399
400
  guestCodeStatsOut?: GuestCodeStats): Promise<Uint8Array | unknown>;
400
401
  /**
@@ -1,3 +1,23 @@
1
+ /**
2
+ * Strip the trailing `//# sourceMappingURL=data:…` comment from a JS
3
+ * bundle. Returns the input unchanged if no trailing inline map is
4
+ * present.
5
+ *
6
+ * Use this on the host side before evaluating workflow bundles inside
7
+ * the QuickJS VM — the inline map can account for several MB of bundle
8
+ * text (measured ~30%+ of VM heap bytes on the example workbench's
9
+ * bundle), and the VM never needs it; only host-side `remapErrorStack`
10
+ * reads the map (and it can do so against the original, unstripped
11
+ * string).
12
+ *
13
+ * Implemented as a linear `lastIndexOf` + character scan rather than a
14
+ * regex: on webpack dev-server bundles (tens of MB, with hundreds of
15
+ * per-module inline map comments embedded in eval strings) a
16
+ * `String.replace` regex over the bundle blows V8's call stack
17
+ * ("RangeError: Maximum call stack size exceeded"), wedging every
18
+ * workflow invocation on that framework.
19
+ */
20
+ export declare function stripInlineSourceMap(workflowCode: string): string;
1
21
  /**
2
22
  * Remaps an error stack trace using inline source maps to show original source locations.
3
23
  *
@@ -60,6 +60,10 @@ export declare const WorkflowStartedAt: (value: number) => {
60
60
  export declare const WorkflowEventsCount: (value: number) => {
61
61
  [k: string]: number;
62
62
  };
63
+ /** Whether workflow execution starts with replay or resumes a retained VM */
64
+ export declare const WorkflowExecutionMode: (value: "replay" | "retained") => {
65
+ [k: string]: "replay" | "retained";
66
+ };
63
67
  /** Number of arguments passed to the workflow */
64
68
  export declare const WorkflowArgumentsCount: (value: number) => {
65
69
  [k: string]: number;
@@ -72,6 +76,34 @@ export declare const WorkflowResultType: (value: string) => {
72
76
  export declare const WorkflowTracePropagated: (value: boolean) => {
73
77
  [k: string]: boolean;
74
78
  };
79
+ /** The VM engine executing the workflow function for this invocation */
80
+ export declare const WorkflowVm: (value: "node" | "quickjs") => {
81
+ [k: string]: "node" | "quickjs";
82
+ };
83
+ /** Outcome of a QuickJS VM workflow invocation */
84
+ export declare const QuickJSOutcome: (value: "completed" | "failed" | "suspended") => {
85
+ [k: string]: "completed" | "failed" | "suspended";
86
+ };
87
+ /** Whether preloaded events from `events.create('run_started')` were used */
88
+ export declare const QuickJSEventsPreloaded: (value: boolean) => {
89
+ [k: string]: boolean;
90
+ };
91
+ /** Total number of events fetched from the world for this invocation */
92
+ export declare const QuickJSEventsFetchedCount: (value: number) => {
93
+ [k: string]: number;
94
+ };
95
+ /** Number of pages required to fetch all events */
96
+ export declare const QuickJSEventsFetchedPages: (value: number) => {
97
+ [k: string]: number;
98
+ };
99
+ /** Number of pending VM operations captured at suspension */
100
+ export declare const QuickJSPendingOpsCount: (value: number) => {
101
+ [k: string]: number;
102
+ };
103
+ /** Number of steps executed inline (live-VM continuation) this invocation */
104
+ export declare const QuickJSInlineSteps: (value: number) => {
105
+ [k: string]: number;
106
+ };
75
107
  /** Active trace-correlation mode for this invocation (linked or continuous) */
76
108
  export declare const WorkflowTraceMode: (value: "linked" | "continuous") => {
77
109
  [k: string]: "linked" | "continuous";
@@ -286,6 +318,18 @@ export declare const QueueOverheadMs: (value: number) => {
286
318
  export declare const DeploymentId: (value: string) => {
287
319
  [k: string]: string;
288
320
  };
321
+ /** The deployment a run is pinned to, set only on a misrouted delivery. */
322
+ export declare const WorkflowRunPinnedDeploymentId: (value: string) => {
323
+ [k: string]: string;
324
+ };
325
+ /** Re-route attempts for this misrouted delivery, including this one. */
326
+ export declare const WorkflowDeploymentMismatchRetryCount: (value: number) => {
327
+ [k: string]: number;
328
+ };
329
+ /** Whether the misrouted delivery was re-routed instead of failing the run. */
330
+ export declare const WorkflowDeploymentMismatchRecovered: (value: boolean) => {
331
+ [k: string]: boolean;
332
+ };
289
333
  /** Token identifying a specific hook */
290
334
  export declare const HookToken: (value: string) => {
291
335
  [k: string]: string;
@@ -312,10 +356,44 @@ export declare const HookResilientResume: (value: boolean) => {
312
356
  * materialized the `hook_received` event from the queue message's `hookInput`
313
357
  * because the producer's direct write had not landed — the completion of the
314
358
  * recovery path {@link HookResilientResume} began.
359
+ *
360
+ * Legacy / non-atomic re-ensure signal only. Atomic lazy resumes
361
+ * (resumeId + digest) go through the hoisted preload write instead, whose
362
+ * response cannot tell whether the producer or the consumer won the
363
+ * `(runId, resumeId)` claim — so this attribute is deliberately NOT emitted
364
+ * for them (emitting `true` unconditionally would count every producer-won
365
+ * resume as a recovery). The producer-begin ({@link HookResilientResume}) /
366
+ * consumer-materialized pairing is therefore no longer complete for atomic
367
+ * lazy resumptions; use {@link HookResumeSetupSource} to observe that path.
315
368
  */
316
369
  export declare const HookResilientResumeMaterialized: (value: boolean) => {
317
370
  [k: string]: boolean;
318
371
  };
372
+ /**
373
+ * Consumer-side signal (on the workflow execution span) of how a lazy hook
374
+ * resume initialized its replay state:
375
+ *
376
+ * - `hook_received_stream` — the hoisted `hook_received` write returned a
377
+ * usable replay preload (run + complete event log), so the invocation
378
+ * skipped both the `run_started` write and the initial `events.list`.
379
+ * - `hook_received_fallback` — the hoisted write succeeded but returned no
380
+ * usable preload (a CBOR response from an older server, a World that
381
+ * ignored the opt-in, a bounded `hasMore` page, or a preload that failed
382
+ * validation); the invocation fell back to the `run_started` setup without
383
+ * re-posting the hook.
384
+ *
385
+ * Absent on legacy hook deliveries (no resumeId/digest) and on every other
386
+ * delivery kind, which take the `run_started` setup unconditionally.
387
+ *
388
+ * This is a latency/setup-path signal: it says which requests initialized
389
+ * the invocation, NOT that this consumer created the `hook_received` event
390
+ * (the hoisted write may equally have converged on the producer's — claim
391
+ * ownership is not observable client-side; cf.
392
+ * {@link HookResilientResumeMaterialized}).
393
+ */
394
+ export declare const HookResumeSetupSource: (value: string) => {
395
+ [k: string]: string;
396
+ };
319
397
  /** Number of webhook handlers triggered */
320
398
  export declare const WebhookHandlersTriggered: (value: number) => {
321
399
  [k: string]: number;
@@ -1,5 +1,6 @@
1
1
  import type * as api from '#compiled/@opentelemetry/api/index.js';
2
2
  import type { Span, SpanKind, SpanOptions } from '#compiled/@opentelemetry/api/index.js';
3
+ import { WorkflowSuspension } from './global.js';
3
4
  /**
4
5
  * Controls how workflow/step queue-handler spans relate to the run-origin
5
6
  * trace context carried in queue messages:
@@ -80,6 +81,10 @@ export declare function trace<T>(spanName: string, ...args: [fn: (span?: Span) =
80
81
  * callback. No-op when OpenTelemetry is not available.
81
82
  */
82
83
  export declare function recordElapsedSpan(spanName: string, startEpochMs: number, opts?: SpanOptions): Promise<void>;
84
+ /**
85
+ * Applies the workflow suspension algebraic effect to an active span.
86
+ */
87
+ export declare function applyWorkflowSuspensionToSpan(error: WorkflowSuspension, span: api.Span): void;
83
88
  export declare function getSpanContextForTraceCarrier(carrier: Record<string, string>): Promise<api.SpanContext | undefined>;
84
89
  export declare function getActiveSpan(): Promise<api.Span | undefined>;
85
90
  /**
@@ -1,2 +1,2 @@
1
- export declare const version = "5.0.0-beta.39";
1
+ export declare const version = "5.0.0-beta.40";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- import{Cn as e,Gn as t,Kn as n,Wn as r,wn as i,zn as a}from"../../_chunks/workflow/wait-until-DoW76jdb.js";import"../../_chunks/workflow/dist-B-vbuNqP.js";import{i as o}from"../../_chunks/workflow/workflow-routes-CwqB063q.js";import{i as s,u as c}from"../../_chunks/workflow/dist-dNxTT6nO.js";import{c as l,i as u,o as d,r as f,t as p}from"../../_chunks/workflow/attribute-changes-DROfGk6l.js";import{t as m}from"../../_chunks/workflow/sleep-D5iWly6-.js";import{t as h}from"../../_chunks/workflow/run-DM3ouA3U.js";i(e,h);function g(e){let t=globalThis[r];return t||u(`createHook()`,`https://workflow-sdk.dev/docs/api-reference/workflow/create-hook`,g),t(e)}function _(e){let{respondWith:t,token:n,...r}=e??{};if(n!==void 0)throw Error("`createWebhook()` does not accept a `token` option. Webhook tokens are always randomly generated. Use `createHook()` with `resumeHook()` for deterministic token patterns.");let i;t!==void 0&&(i={respondWith:t});let a=g({...r,metadata:i,isWebhook:!0}),{url:s}=l();return a.url=o(s,{type:`webhook`,token:a.token}),a}function v(){function e(t,n){d(`defineHook().resume()`,`https://workflow-sdk.dev/docs/api-reference/workflow-api/resume-hook`,e)}return{create(e){return g(e)},resume:e}}async function y(e,t={}){let r=p(e,t);if(r.length===0)return;let i=t.allowReservedAttributes===!0,a=globalThis[n];if(!a)throw new s("setAttributes() called outside a workflow runtime context. It must be called from within a workflow body (`use workflow`).");await a(r,i?{allowReservedAttributes:!0}:{})}function b(e={}){let{namespace:n}=e,r=globalThis[t](n);return Object.create(globalThis.WritableStream.prototype,{[a]:{value:r,writable:!1}})}function x(){f(`getStepMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-step-metadata`,x)}function S(){d(`resumeHook()`,`https://workflow-sdk.dev/docs/api-reference/workflow-api/resume-hook`,S)}export{s as FatalError,c as RetryableError,g as createHook,_ as createWebhook,v as defineHook,x as getStepMetadata,l as getWorkflowMetadata,b as getWritable,S as resumeHook,y as setAttributes,m as sleep};
1
+ import{An as e,Gn as t,Qn as n,Xn as r,Zn as i,kn as a}from"../../_chunks/workflow/wait-until-CMX5LUWJ.js";import{i as o,u as s}from"../../_chunks/workflow/dist-CRTn4Sg8.js";import"../../_chunks/workflow/dist-tJoQXAF6.js";import{i as c}from"../../_chunks/workflow/workflow-routes-CwqB063q.js";import{c as l,i as u,o as d,r as f,t as p}from"../../_chunks/workflow/attribute-changes-Du5ztewf.js";import{t as m}from"../../_chunks/workflow/sleep-BeH4B0Cd.js";import{t as h}from"../../_chunks/workflow/run-DBheaFhH.js";e(a,h);function g(e){let t=globalThis[r];return t||u(`createHook()`,`https://workflow-sdk.dev/docs/api-reference/workflow/create-hook`,g),t(e)}function _(e){let{respondWith:t,token:n,...r}=e??{};if(n!==void 0)throw Error("`createWebhook()` does not accept a `token` option. Webhook tokens are always randomly generated. Use `createHook()` with `resumeHook()` for deterministic token patterns.");let i;t!==void 0&&(i={respondWith:t});let a=g({...r,metadata:i,isWebhook:!0}),{url:o}=l();return a.url=c(o,{type:`webhook`,token:a.token}),a}function v(){function e(t,n){d(`defineHook().resume()`,`https://workflow-sdk.dev/docs/api-reference/workflow-api/resume-hook`,e)}return{create(e){return g(e)},resume:e}}async function y(e,t={}){let r=p(e,t);if(r.length===0)return;let i=t.allowReservedAttributes===!0,a=globalThis[n];if(!a)throw new o("setAttributes() called outside a workflow runtime context. It must be called from within a workflow body (`use workflow`).");await a(r,i?{allowReservedAttributes:!0}:{})}function b(e={}){let{namespace:n}=e,r=globalThis[i](n);return Object.create(globalThis.WritableStream.prototype,{[t]:{value:r,writable:!1}})}function x(){f(`getStepMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-step-metadata`,x)}function S(){d(`resumeHook()`,`https://workflow-sdk.dev/docs/api-reference/workflow-api/resume-hook`,S)}export{o as FatalError,s as RetryableError,g as createHook,_ as createWebhook,v as defineHook,x as getStepMetadata,l as getWorkflowMetadata,b as getWritable,S as resumeHook,y as setAttributes,m as sleep};
@@ -20,6 +20,8 @@ export declare const RUN_ERROR_CODES: {
20
20
  readonly REPLAY_TIMEOUT: "REPLAY_TIMEOUT";
21
21
  /** World response violated the SDK contract and cannot be retried safely */
22
22
  readonly WORLD_CONTRACT_ERROR: "WORLD_CONTRACT_ERROR";
23
+ /** Run was delivered to a deployment other than the one it is pinned to */
24
+ readonly DEPLOYMENT_MISMATCH: "DEPLOYMENT_MISMATCH";
23
25
  };
24
26
  export type RunErrorCode = (typeof RUN_ERROR_CODES)[keyof typeof RUN_ERROR_CODES];
25
27
  //# sourceMappingURL=error-codes.d.ts.map
@@ -17,6 +17,7 @@ export declare const ERROR_SLUGS: {
17
17
  readonly STEP_NOT_REGISTERED: "step-not-registered";
18
18
  readonly WORKFLOW_NOT_REGISTERED: "workflow-not-registered";
19
19
  readonly RUNTIME_DECRYPTION_FAILED: "runtime-decryption-failed";
20
+ readonly DEPLOYMENT_MISMATCH: "deployment-mismatch";
20
21
  };
21
22
  type ErrorSlug = (typeof ERROR_SLUGS)[keyof typeof ERROR_SLUGS];
22
23
  interface WorkflowErrorOptions extends ErrorOptions {
@@ -313,6 +314,29 @@ export declare class WorkflowNotRegisteredError extends WorkflowRuntimeError {
313
314
  constructor(workflowName: string);
314
315
  static is(value: unknown): value is WorkflowNotRegisteredError;
315
316
  }
317
+ /**
318
+ * Thrown when a workflow run is delivered to a deployment other than the one
319
+ * it is pinned to.
320
+ *
321
+ * A run is pinned to one deployment when it starts, and executing anywhere
322
+ * else is unsafe: that deployment's bundles may not match the run's history.
323
+ */
324
+ export declare class WorkflowDeploymentMismatchError extends WorkflowRuntimeError {
325
+ readonly runId: string;
326
+ readonly expectedDeploymentId: string;
327
+ readonly actualDeploymentId: string;
328
+ /**
329
+ * How many times the runtime re-routed the message before giving up. `0`
330
+ * means recovery was never attempted: the budget is disabled, or the
331
+ * re-route itself failed and `cause` holds the enqueue error.
332
+ */
333
+ readonly recoveryAttempts: number;
334
+ constructor(runId: string, expectedDeploymentId: string, actualDeploymentId: string, options?: {
335
+ recoveryAttempts?: number;
336
+ cause?: unknown;
337
+ });
338
+ static is(value: unknown): value is WorkflowDeploymentMismatchError;
339
+ }
316
340
  /**
317
341
  * Thrown when performing operations on a workflow run that does not exist.
318
342
  *
@@ -1 +1 @@
1
- import{C as e,D as t,E as n,O as r,S as i,T as a,_ as o,a as s,b as c,c as l,d as u,f as d,g as f,h as p,i as m,l as h,m as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C,v as w,w as T,x as E,y as D}from"../../_chunks/workflow/dist-dNxTT6nO.js";export{S as CorruptedEventLogError,_ as ERROR_SLUGS,b as EntityConflictError,m as FatalError,s as HookConflictError,v as HookNotFoundError,x as MaxEventsExceededError,l as PreconditionFailedError,r as RUN_ERROR_CODES,h as ReplayDivergenceError,C as RetryableError,u as RunExpiredError,d as RunNotSupportedError,y as RuntimeDecryptionError,g as SerializationError,p as StepNotRegisteredError,f as ThrottleError,o as TooEarlyError,w as VERCEL_403_ERROR_MESSAGE,D as WorkflowBuildError,c as WorkflowError,E as WorkflowNotRegisteredError,i as WorkflowRunCancelledError,e as WorkflowRunFailedError,T as WorkflowRunNotCompletedError,a as WorkflowRunNotFoundError,n as WorkflowRuntimeError,t as WorkflowWorldError};
1
+ import{C as e,D as t,E as n,O as r,S as i,T as a,_ as o,a as s,b as c,c as l,d as u,f as d,g as f,h as p,i as m,k as h,l as g,m as _,n as v,o as y,p as b,r as x,s as S,t as C,u as w,v as T,w as E,x as D,y as O}from"../../_chunks/workflow/dist-CRTn4Sg8.js";export{C as CorruptedEventLogError,v as ERROR_SLUGS,x as EntityConflictError,m as FatalError,s as HookConflictError,y as HookNotFoundError,S as MaxEventsExceededError,l as PreconditionFailedError,h as RUN_ERROR_CODES,g as ReplayDivergenceError,w as RetryableError,u as RunExpiredError,d as RunNotSupportedError,b as RuntimeDecryptionError,_ as SerializationError,p as StepNotRegisteredError,f as ThrottleError,o as TooEarlyError,T as VERCEL_403_ERROR_MESSAGE,O as WorkflowBuildError,c as WorkflowDeploymentMismatchError,D as WorkflowError,i as WorkflowNotRegisteredError,e as WorkflowRunCancelledError,E as WorkflowRunFailedError,a as WorkflowRunNotCompletedError,n as WorkflowRunNotFoundError,t as WorkflowRuntimeError,r as WorkflowWorldError};
@@ -174,6 +174,8 @@ export interface AnalyticsListEventsParams extends AnalyticsListRunScopedParams
174
174
  }
175
175
  export interface AnalyticsListEventsByCorrelationIdParams {
176
176
  correlationId: string;
177
+ /** The run the correlation id belongs to; see `ListEventsByCorrelationIdParams`. */
178
+ runId: string;
177
179
  pagination?: PaginationOptions;
178
180
  }
179
181
  export interface AnalyticsListHooksParams {
@@ -742,6 +742,42 @@ export interface CreateEventParams {
742
742
  * across the SDK and the backend.
743
743
  */
744
744
  skipPreload?: boolean;
745
+ /**
746
+ * Replay-log preload opt-in (advisory) — the `hook_received` dual of
747
+ * {@link skipPreload}. Set only by the queue consumer's idempotent
748
+ * `hook_received` re-ensure on a lazy hook resume (alongside
749
+ * {@link resumeId} + {@link resumePayloadDigest}). A World MAY return the
750
+ * run's current replay event log with the event creation
751
+ * (`events`/`cursor`/`hasMore`, plus `run` and `maxEvents`) so the runtime
752
+ * can initialize replay from this one request and skip both the
753
+ * `run_started` write and the initial `events.list`.
754
+ *
755
+ * The runtime trusts a returned preload as replay input ONLY when all of
756
+ * the following hold — a World that cannot guarantee them should return
757
+ * its normal {@link EventResult} instead:
758
+ *
759
+ * - `events` is the COMPLETE log with `hasMore: false` (the runtime has no
760
+ * cursor-continuation machinery on this path; a bounded page is
761
+ * rejected).
762
+ * - `cursor` is a valid non-null resume point matching `events.list`
763
+ * semantics (present even on the final page).
764
+ * - `run` (with `run.startedAt`) and `maxEvents` are present — this
765
+ * response plays `run_started`'s role, including the event-ceiling
766
+ * handshake.
767
+ * - The log contains `run_created`, `run_started`, and the canonical
768
+ * `hook_received` carrying the requested {@link resumeId}.
769
+ * - `events` uses the same ascending ordering semantics as `events.list`.
770
+ * - The log is read atomically/consistently WITH (i.e. no earlier than)
771
+ * the `hook_received` write, so no concurrently committed event can be
772
+ * omitted from the replay input.
773
+ *
774
+ * Anything less and the runtime observes that no usable replay preload
775
+ * came back and falls back to the existing `run_started` setup — a World
776
+ * that ignores the param entirely remains fully correct. Only meaningful
777
+ * for `hook_received`; ignored for other event types. Producer-side
778
+ * `resumeHook()` must not set it.
779
+ */
780
+ preloadEvents?: true;
745
781
  }
746
782
  /**
747
783
  * Result of creating an event. Includes the created event and optionally
@@ -761,7 +797,7 @@ export interface EventResult {
761
797
  /** The wait entity (for wait_created/wait_completed events) */
762
798
  wait?: import('./waits.js').Wait;
763
799
  /**
764
- * Events with data resolved. Two producers populate this:
800
+ * Events with data resolved. Three producers populate this:
765
801
  *
766
802
  * - On a `run_started` response: all events up to this point, so the
767
803
  * runtime can skip the initial `events.list` call and reduce TTFB.
@@ -769,6 +805,11 @@ export interface EventResult {
769
805
  * the caller passed {@link CreateEventParams.sinceCursor}: the delta
770
806
  * of events written strictly after that cursor, so the inline loop
771
807
  * can skip the per-step incremental `events.list` round-trip.
808
+ * - On a `hook_received` response when the caller passed
809
+ * {@link CreateEventParams.preloadEvents}: the run's current replay
810
+ * log through the canonical `hook_received`, so the lazy hook queue
811
+ * consumer can skip both the `run_started` write and the initial
812
+ * `events.list`.
772
813
  */
773
814
  events?: Event[];
774
815
  /** Pagination cursor for `events`, matching events.list semantics. */
@@ -800,6 +841,15 @@ export interface ListEventsParams {
800
841
  }
801
842
  export interface ListEventsByCorrelationIdParams {
802
843
  correlationId: string;
844
+ /**
845
+ * The run the correlation id belongs to. A correlation id is unique per
846
+ * run, not globally: a slot-numbered run counts its own steps and waits, so
847
+ * `step_…001` names the first step of *every* such run. Naming the run is
848
+ * what makes the answer that run's events, and it is what makes the
849
+ * pagination cursor unambiguous — `(runId, eventId)` is a key where an
850
+ * event id alone is not.
851
+ */
852
+ runId: string;
803
853
  pagination?: PaginationOptions;
804
854
  resolveData?: ResolveData;
805
855
  }
@@ -74,6 +74,7 @@ export declare const HookSchema: z.ZodObject<{
74
74
  specVersion: z.ZodOptional<z.ZodNumber>;
75
75
  isWebhook: z.ZodOptional<z.ZodBoolean>;
76
76
  isSystem: z.ZodOptional<z.ZodBoolean>;
77
+ tokenRetentionUntil: z.ZodOptional<z.ZodCoercedDate<unknown>>;
77
78
  resumeContext: z.ZodOptional<z.ZodObject<{
78
79
  deploymentId: z.ZodString;
79
80
  workflowName: z.ZodString;
@@ -12,7 +12,7 @@ export type * from './queue.js';
12
12
  export { getQueueTopicPrefix, HealthCheckPayloadSchema, MessageId, parseQueueName, QueuePayloadSchema, QueuePrefix, RunInputSchema, resolveQueueNamespace, ValidQueueName, WorkflowInvokePayloadSchema, } from './queue.js';
13
13
  export { reenqueueActiveRuns } from './recovery.js';
14
14
  export type * from './runs.js';
15
- export { isTerminalWorkflowRunStatus, TERMINAL_WORKFLOW_RUN_STATUSES, TerminalWorkflowRunStatusSchema, WorkflowRunBaseSchema, WorkflowRunSchema, WorkflowRunStatusSchema, } from './runs.js';
15
+ export { BULK_CANCEL_MAX_RUN_IDS, BulkCancelWorkflowRunResultSchema, BulkCancelWorkflowRunsRequestSchema, BulkCancelWorkflowRunsResultSchema, isTerminalWorkflowRunStatus, TERMINAL_WORKFLOW_RUN_STATUSES, TerminalWorkflowRunStatusSchema, WorkflowRunBaseSchema, WorkflowRunSchema, WorkflowRunStatusSchema, } from './runs.js';
16
16
  export type { SerializedData } from './serialization.js';
17
17
  export { LegacySerializedDataSchemaV1, SerializedDataSchema, } from './serialization.js';
18
18
  export type * from './shared.js';
@@ -3,7 +3,7 @@ import type { AttributeChange, ExperimentalSetAttributesResult } from './attribu
3
3
  import type { CreateEventParams, CreateEventRequest, Event, EventResult, GetEventParams, ListEventsByCorrelationIdParams, ListEventsParams, RunCreatedEventRequest } from './events.js';
4
4
  import type { GetHookParams, Hook, ListHooksParams } from './hooks.js';
5
5
  import type { Queue } from './queue.js';
6
- import type { GetWorkflowRunParams, ListWorkflowRunsParams, WorkflowRun, WorkflowRunWithoutData } from './runs.js';
6
+ import type { BulkCancelWorkflowRunsRequest, BulkCancelWorkflowRunsResult, GetWorkflowRunParams, ListWorkflowRunsParams, WorkflowRun, WorkflowRunWithoutData } from './runs.js';
7
7
  import type { GetChunksOptions, PaginatedResponse, StreamChunksResponse, StreamInfoResponse } from './shared.js';
8
8
  import type { GetStepParams, ListWorkflowRunStepsParams, Step, StepWithoutData } from './steps.js';
9
9
  export interface Streamer {
@@ -143,6 +143,14 @@ export interface Storage {
143
143
  experimentalSetAttributes?(runId: string, changes: AttributeChange[], options?: {
144
144
  allowReservedAttributes?: boolean;
145
145
  }): Promise<ExperimentalSetAttributesResult>;
146
+ /**
147
+ * Cancel many runs in a single operation, returning a per-run outcome
148
+ * for each requested ID (order preserved) plus an aggregate summary.
149
+ *
150
+ * OPTIONAL. The SDK helper `cancelRuns` in `@workflow/core` falls back to
151
+ * bounded-concurrency single-run cancellation when unavailable.
152
+ */
153
+ cancelMany?(request: BulkCancelWorkflowRunsRequest): Promise<BulkCancelWorkflowRunsResult>;
146
154
  };
147
155
  steps: {
148
156
  get(runId: string, stepId: string, params: GetStepParams & {
@@ -283,6 +291,20 @@ export interface WorldCapabilities {
283
291
  * `resumeCapabilities.hookResumeDedupVersion` on the by-token hook.
284
292
  */
285
293
  hookResumeDedup?: boolean;
294
+ /**
295
+ * Deployments are atomic and immutable: a deployment id names one fixed
296
+ * build for its whole lifetime, so a run pinned to one may only execute
297
+ * there. Worlds that declare this get the runtime's deployment-affinity
298
+ * guard, which re-routes a misrouted delivery to the run's own deployment
299
+ * and ultimately fails the run with `DEPLOYMENT_MISMATCH`.
300
+ *
301
+ * Worlds whose deployment id is synthetic or version-tagged (e.g.
302
+ * `dpl_local@<sdk-version>`, which legitimately differs across SDK versions
303
+ * within one logical environment) must leave this unset: there a
304
+ * "mismatch" is not a real cross-deployment delivery, and guarding would
305
+ * fail ordinary runs after a version bump.
306
+ */
307
+ deploymentAffinity?: boolean;
286
308
  }
287
309
  /**
288
310
  * The "World" interface represents how Workflows are able to communicate with the outside world.
@@ -331,6 +353,11 @@ export interface World extends Queue, Streamer, Storage {
331
353
  * `packages/core/src/runtime/replay-budget.ts`.
332
354
  */
333
355
  processExitTriggersQueueRedelivery?: boolean;
356
+ /**
357
+ * Absolute wall-clock time when the current function invocation will be
358
+ * terminated by the hosting platform, if known. Used to optimize runtime behavior.
359
+ */
360
+ getRuntimeDeadline?(): Promise<Date | undefined>;
334
361
  /**
335
362
  * A function that will be called to start any background tasks needed by the World implementation.
336
363
  * For example, in the case of a queue backed World, this would start the queue processing.
@@ -85,6 +85,7 @@ export declare const WorkflowInvokePayloadSchema: z.ZodObject<{
85
85
  }, z.core.$strip>>;
86
86
  preconditionReinvocations: z.ZodOptional<z.ZodNumber>;
87
87
  serverErrorRetryCount: z.ZodOptional<z.ZodNumber>;
88
+ deploymentMismatchRetryCount: z.ZodOptional<z.ZodNumber>;
88
89
  stepId: z.ZodOptional<z.ZodString>;
89
90
  stepName: z.ZodOptional<z.ZodString>;
90
91
  runInput: z.ZodOptional<z.ZodObject<{
@@ -147,6 +148,7 @@ export declare const QueuePayloadSchema: z.ZodUnion<readonly [z.ZodObject<{
147
148
  }, z.core.$strip>>;
148
149
  preconditionReinvocations: z.ZodOptional<z.ZodNumber>;
149
150
  serverErrorRetryCount: z.ZodOptional<z.ZodNumber>;
151
+ deploymentMismatchRetryCount: z.ZodOptional<z.ZodNumber>;
150
152
  stepId: z.ZodOptional<z.ZodString>;
151
153
  stepName: z.ZodOptional<z.ZodString>;
152
154
  runInput: z.ZodOptional<z.ZodObject<{
@@ -191,6 +193,12 @@ export interface QueueOptions {
191
193
  }
192
194
  export interface Queue {
193
195
  getDeploymentId(): Promise<string>;
196
+ /**
197
+ * Returns true only when a queue error definitively means the explicitly
198
+ * targeted deployment cannot receive the message. Unknown and transient
199
+ * errors must return false so the current delivery can be retried safely.
200
+ */
201
+ isDeploymentUnavailableError?(error: unknown): boolean;
194
202
  /**
195
203
  * Enqueues a message to the specified queue.
196
204
  *
@@ -156,4 +156,87 @@ export interface ListWorkflowRunsParams {
156
156
  export interface CancelWorkflowRunParams {
157
157
  resolveData?: ResolveData;
158
158
  }
159
+ /**
160
+ * Maximum number of run IDs that a single bulk cancellation request may
161
+ * carry. Kept small enough that the backend can process one request
162
+ * synchronously without an asynchronous job or cursor.
163
+ */
164
+ export declare const BULK_CANCEL_MAX_RUN_IDS = 500;
165
+ /**
166
+ * Request payload for cancelling many runs in a single operation.
167
+ *
168
+ * `runIds` must contain 1–{@link BULK_CANCEL_MAX_RUN_IDS} unique IDs.
169
+ * `cancelReason` (max 512 chars) is recorded on each run_cancelled event,
170
+ * mirroring the single-run {@link CancelRunOptions.cancelReason}.
171
+ */
172
+ export declare const BulkCancelWorkflowRunsRequestSchema: z.ZodObject<{
173
+ runIds: z.ZodArray<z.ZodString>;
174
+ cancelReason: z.ZodOptional<z.ZodString>;
175
+ }, z.core.$strip>;
176
+ export type BulkCancelWorkflowRunsRequest = z.infer<typeof BulkCancelWorkflowRunsRequestSchema>;
177
+ /**
178
+ * Per-run outcome of a bulk cancellation.
179
+ *
180
+ * - `cancelled`: the run was transitioned to cancelled by this request.
181
+ * - `already_cancelled`: the run was already cancelled (idempotent success).
182
+ * - `not_cancellable`: the run is in a terminal, non-cancellable state
183
+ * (e.g. `completed`/`failed`); `status` reports the observed status.
184
+ * - `not_found`: no run exists for this ID.
185
+ * - `failed`: cancellation failed; `code` is a machine-readable error code
186
+ * and `retryable` indicates whether retrying may succeed.
187
+ */
188
+ export declare const BulkCancelWorkflowRunResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
189
+ runId: z.ZodString;
190
+ outcome: z.ZodLiteral<"cancelled">;
191
+ }, z.core.$strip>, z.ZodObject<{
192
+ runId: z.ZodString;
193
+ outcome: z.ZodLiteral<"already_cancelled">;
194
+ }, z.core.$strip>, z.ZodObject<{
195
+ runId: z.ZodString;
196
+ outcome: z.ZodLiteral<"not_cancellable">;
197
+ status: z.ZodString;
198
+ }, z.core.$strip>, z.ZodObject<{
199
+ runId: z.ZodString;
200
+ outcome: z.ZodLiteral<"not_found">;
201
+ }, z.core.$strip>, z.ZodObject<{
202
+ runId: z.ZodString;
203
+ outcome: z.ZodLiteral<"failed">;
204
+ code: z.ZodString;
205
+ retryable: z.ZodBoolean;
206
+ }, z.core.$strip>], "outcome">;
207
+ export type BulkCancelWorkflowRunResult = z.infer<typeof BulkCancelWorkflowRunResultSchema>;
208
+ /**
209
+ * Aggregate result of a bulk cancellation. `results` preserves the order of
210
+ * the requested `runIds`; `summary` counts each outcome.
211
+ */
212
+ export declare const BulkCancelWorkflowRunsResultSchema: z.ZodObject<{
213
+ summary: z.ZodObject<{
214
+ requested: z.ZodNumber;
215
+ cancelled: z.ZodNumber;
216
+ alreadyCancelled: z.ZodNumber;
217
+ notCancellable: z.ZodNumber;
218
+ notFound: z.ZodNumber;
219
+ failed: z.ZodNumber;
220
+ }, z.core.$strip>;
221
+ results: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
222
+ runId: z.ZodString;
223
+ outcome: z.ZodLiteral<"cancelled">;
224
+ }, z.core.$strip>, z.ZodObject<{
225
+ runId: z.ZodString;
226
+ outcome: z.ZodLiteral<"already_cancelled">;
227
+ }, z.core.$strip>, z.ZodObject<{
228
+ runId: z.ZodString;
229
+ outcome: z.ZodLiteral<"not_cancellable">;
230
+ status: z.ZodString;
231
+ }, z.core.$strip>, z.ZodObject<{
232
+ runId: z.ZodString;
233
+ outcome: z.ZodLiteral<"not_found">;
234
+ }, z.core.$strip>, z.ZodObject<{
235
+ runId: z.ZodString;
236
+ outcome: z.ZodLiteral<"failed">;
237
+ code: z.ZodString;
238
+ retryable: z.ZodBoolean;
239
+ }, z.core.$strip>], "outcome">>;
240
+ }, z.core.$strip>;
241
+ export type BulkCancelWorkflowRunsResult = z.infer<typeof BulkCancelWorkflowRunsResultSchema>;
159
242
  //# sourceMappingURL=runs.d.ts.map