@workflow/core 5.0.0-beta.39 → 5.0.0-beta.40

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 (95) hide show
  1. package/dist/classify-error.d.ts.map +1 -1
  2. package/dist/classify-error.js +5 -2
  3. package/dist/correlation-id.d.ts +109 -0
  4. package/dist/correlation-id.d.ts.map +1 -0
  5. package/dist/correlation-id.js +139 -0
  6. package/dist/describe-error.d.ts.map +1 -1
  7. package/dist/describe-error.js +14 -1
  8. package/dist/events-consumer.d.ts +1 -0
  9. package/dist/events-consumer.d.ts.map +1 -1
  10. package/dist/events-consumer.js +11 -3
  11. package/dist/private.d.ts +17 -1
  12. package/dist/private.d.ts.map +1 -1
  13. package/dist/private.js +1 -1
  14. package/dist/runtime/constants.d.ts +19 -0
  15. package/dist/runtime/constants.d.ts.map +1 -1
  16. package/dist/runtime/constants.js +30 -1
  17. package/dist/runtime/deployment-guard.d.ts +99 -0
  18. package/dist/runtime/deployment-guard.d.ts.map +1 -0
  19. package/dist/runtime/deployment-guard.js +154 -0
  20. package/dist/runtime/quickjs-assets.generated.d.ts +14 -0
  21. package/dist/runtime/quickjs-assets.generated.d.ts.map +1 -0
  22. package/dist/runtime/quickjs-assets.generated.js +30 -0
  23. package/dist/runtime/quickjs-entrypoint.d.ts +124 -0
  24. package/dist/runtime/quickjs-entrypoint.d.ts.map +1 -0
  25. package/dist/runtime/quickjs-entrypoint.js +1429 -0
  26. package/dist/runtime/quickjs-runtime.d.ts +193 -0
  27. package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
  28. package/dist/runtime/quickjs-runtime.js +1944 -0
  29. package/dist/runtime/run.d.ts +2 -0
  30. package/dist/runtime/run.d.ts.map +1 -1
  31. package/dist/runtime/run.js +9 -4
  32. package/dist/runtime/runs.d.ts +18 -1
  33. package/dist/runtime/runs.d.ts.map +1 -1
  34. package/dist/runtime/runs.js +96 -2
  35. package/dist/runtime/start.d.ts.map +1 -1
  36. package/dist/runtime/start.js +9 -1
  37. package/dist/runtime/suspension-handler.d.ts +7 -0
  38. package/dist/runtime/suspension-handler.d.ts.map +1 -1
  39. package/dist/runtime/suspension-handler.js +29 -2
  40. package/dist/runtime/vm-mode.d.ts +44 -0
  41. package/dist/runtime/vm-mode.d.ts.map +1 -0
  42. package/dist/runtime/vm-mode.js +62 -0
  43. package/dist/runtime/vm-serde-bundle.generated.d.ts +14 -0
  44. package/dist/runtime/vm-serde-bundle.generated.d.ts.map +1 -0
  45. package/dist/runtime/vm-serde-bundle.generated.js +16 -0
  46. package/dist/runtime.d.ts +1 -1
  47. package/dist/runtime.d.ts.map +1 -1
  48. package/dist/runtime.js +484 -47
  49. package/dist/serialization/codec-devalue-vm.d.ts +9 -0
  50. package/dist/serialization/codec-devalue-vm.d.ts.map +1 -0
  51. package/dist/serialization/codec-devalue-vm.js +137 -0
  52. package/dist/serialization/reducers/class-vm.d.ts +20 -0
  53. package/dist/serialization/reducers/class-vm.d.ts.map +1 -0
  54. package/dist/serialization/reducers/class-vm.js +77 -0
  55. package/dist/serialization/reducers/common-vm.d.ts +15 -0
  56. package/dist/serialization/reducers/common-vm.d.ts.map +1 -0
  57. package/dist/serialization/reducers/common-vm.js +579 -0
  58. package/dist/serialization/reducers/common.d.ts.map +1 -1
  59. package/dist/serialization/reducers/common.js +28 -6
  60. package/dist/serialization/reducers/step-function-vm.d.ts +44 -0
  61. package/dist/serialization/reducers/step-function-vm.d.ts.map +1 -0
  62. package/dist/serialization/reducers/step-function-vm.js +97 -0
  63. package/dist/serialization/vm-bundle-entry.d.ts +12 -0
  64. package/dist/serialization/vm-bundle-entry.d.ts.map +1 -0
  65. package/dist/serialization/vm-bundle-entry.js +58 -0
  66. package/dist/serialization/workflow-vm.d.ts +24 -0
  67. package/dist/serialization/workflow-vm.d.ts.map +1 -0
  68. package/dist/serialization/workflow-vm.js +66 -0
  69. package/dist/serialization.d.ts +2 -1
  70. package/dist/serialization.d.ts.map +1 -1
  71. package/dist/serialization.js +26 -21
  72. package/dist/source-map.d.ts +20 -0
  73. package/dist/source-map.d.ts.map +1 -1
  74. package/dist/source-map.js +47 -1
  75. package/dist/step.d.ts.map +1 -1
  76. package/dist/step.js +7 -2
  77. package/dist/telemetry/semantic-conventions.d.ts +78 -0
  78. package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
  79. package/dist/telemetry/semantic-conventions.js +56 -1
  80. package/dist/telemetry.d.ts +5 -0
  81. package/dist/telemetry.d.ts.map +1 -1
  82. package/dist/telemetry.js +13 -13
  83. package/dist/version.d.ts +1 -1
  84. package/dist/version.js +2 -2
  85. package/dist/workflow/abort-controller.d.ts.map +1 -1
  86. package/dist/workflow/abort-controller.js +6 -4
  87. package/dist/workflow/attribute-dispatcher.js +2 -2
  88. package/dist/workflow/hook.js +2 -2
  89. package/dist/workflow/sleep.js +2 -2
  90. package/dist/workflow.d.ts +49 -2
  91. package/dist/workflow.d.ts.map +1 -1
  92. package/dist/workflow.js +723 -569
  93. package/docs/api-reference/create-hook.mdx +1 -1
  94. package/docs/foundations/starting-workflows.mdx +74 -1
  95. package/package.json +8 -7
@@ -0,0 +1,193 @@
1
+ /**
2
+ * QuickJS WASM workflow VM.
3
+ *
4
+ * An alternative engine for the event-replay execution model: the workflow
5
+ * code runs inside a QuickJS WASM VM (via quickjs-wasi) instead of a
6
+ * `node:vm` context. Every invocation creates a fresh VM, re-executes the
7
+ * workflow function from the top, and replays the recorded event log to
8
+ * resolve awaited primitives — the same replay semantics as the `node:vm`
9
+ * engine.
10
+ *
11
+ * The workflow primitives (useStep, sleep, createHook) are implemented as
12
+ * JavaScript code running inside the QuickJS VM. The host communicates with
13
+ * the VM by evaluating small JS snippets to read pending operations and
14
+ * resolve/reject promises.
15
+ *
16
+ * The VM bootstrap is deliberately split into two phases:
17
+ * 1. Static initialization (`initWorkflowVM`) — run-independent setup:
18
+ * VM creation, the serde bundle, and the workflow primitives.
19
+ * 2. Per-run initialization (inline in `runQuickJSWorkflow`) — seeded
20
+ * PRNG/ULID host functions, workflow bundle evaluation, run metadata,
21
+ * workflow input, and start.
22
+ * Keeping the phases separate is groundwork for VM-memory snapshotting:
23
+ * a follow-up can persist/restore the VM at the phase boundary (e.g. a
24
+ * build-time initial snapshot) without restructuring this module. Note
25
+ * that bundle evaluation currently sits in the per-run phase so that
26
+ * module-scope user code observes the seeded `Math.random`, matching the
27
+ * `node:vm` engine's replay determinism.
28
+ */
29
+ import type { Event, RunInput, WorkflowRun, WorldCapabilities } from '@workflow/world';
30
+ import type { DecryptionKey } from '../serialization/encryption.js';
31
+ export interface PendingStep {
32
+ type: 'step';
33
+ correlationId: string;
34
+ stepId: string;
35
+ /** Format-prefixed devalue-serialized step input (args + closureVars) */
36
+ input: Uint8Array;
37
+ /** Whether a step_created event already exists for this step */
38
+ hasCreatedEvent: boolean;
39
+ }
40
+ export interface PendingWait {
41
+ type: 'wait';
42
+ correlationId: string;
43
+ /** ISO string of when to resume */
44
+ resumeAt: string;
45
+ /** Whether a wait_created event already exists for this wait */
46
+ hasCreatedEvent: boolean;
47
+ }
48
+ export interface PendingHook {
49
+ type: 'hook';
50
+ correlationId: string;
51
+ token: string;
52
+ /** Earliest token reuse time, as milliseconds since the Unix epoch. */
53
+ tokenRetentionUntil?: number;
54
+ isWebhook: boolean;
55
+ metadata?: unknown;
56
+ hasCreatedEvent: boolean;
57
+ /**
58
+ * True for internal system hooks (e.g. AbortController's hook), which
59
+ * are exempt from user-hook token namespace conflict checks.
60
+ */
61
+ isSystem?: boolean;
62
+ /**
63
+ * Set when the workflow called AbortController.abort() during this
64
+ * invocation. The host must record the abort: create a hook_received
65
+ * event carrying `abortPayload` and write/close the abort stream.
66
+ */
67
+ abortRequested?: boolean;
68
+ /** VM-serialized `{ aborted: true, reason }` payload for the abort. */
69
+ abortPayload?: Uint8Array;
70
+ /** Set by the completion drain when a system hook is implicitly disposed. */
71
+ disposed?: boolean;
72
+ /**
73
+ * True when the workflow is awaiting hook.getConflict() for this hook.
74
+ * The entrypoint re-invokes the workflow right after writing
75
+ * hook_created so replay can confirm creation and resolve the awaiter.
76
+ */
77
+ hasGetConflictAwaiter?: boolean;
78
+ }
79
+ export interface PendingAttribute {
80
+ type: 'attribute';
81
+ correlationId: string;
82
+ /** Normalized attribute changes (plain JSON-able objects) */
83
+ changes: unknown[];
84
+ allowReservedAttributes?: boolean;
85
+ /** Whether an attr_set event already exists for this write */
86
+ hasCreatedEvent: boolean;
87
+ }
88
+ export interface PendingHookDispose {
89
+ type: 'hook_dispose';
90
+ correlationId: string;
91
+ /**
92
+ * Token of the hook being disposed. Used by the entrypoint to order
93
+ * same-token hook operations sequentially in code order.
94
+ */
95
+ token?: string;
96
+ hasCreatedEvent: boolean;
97
+ }
98
+ export type PendingOperation = PendingStep | PendingWait | PendingHook | PendingAttribute | PendingHookDispose;
99
+ export interface QuickJSRuntimeResult {
100
+ /** The workflow completed — result is format-prefixed devalue bytes */
101
+ completed?: {
102
+ result: Uint8Array;
103
+ /**
104
+ * Leftover pending operations that still need durable side effects at
105
+ * completion: abort recordings, system-hook disposals, fire-and-forget
106
+ * attribute/hook/step events. Mirrors the node:vm engine's
107
+ * drainPendingQueueItems. The entrypoint dispatches these WITHOUT
108
+ * queueing steps or requeuing the run.
109
+ */
110
+ drainOperations?: PendingOperation[];
111
+ };
112
+ /** The workflow suspended with pending operations */
113
+ suspended?: {
114
+ pendingOperations: PendingOperation[];
115
+ };
116
+ /** The workflow failed */
117
+ failed?: {
118
+ message: string;
119
+ stack?: string;
120
+ name?: string;
121
+ /** See completed.drainOperations — same semantics on failure. */
122
+ drainOperations?: PendingOperation[];
123
+ /**
124
+ * Format-prefixed devalue bytes of the original thrown value
125
+ * (Error subclass with cause chain, plain object, primitive, etc.).
126
+ * Set when the VM-side rejection handler successfully serializes
127
+ * the thrown value. The host uses these bytes to reconstruct the
128
+ * original value through the standard error hydration pipeline,
129
+ * preserving type identity (TypeError, FatalError) and non-Error
130
+ * throws verbatim. Falls back to the message/stack/name fields
131
+ * when this is undefined (e.g. extractError pseudo-failures).
132
+ */
133
+ valueBytes?: Uint8Array;
134
+ };
135
+ }
136
+ export interface QuickJSRuntimeOptions {
137
+ /** The compiled workflow bundle code (workflow mode output from SWC) */
138
+ workflowCode: string;
139
+ /** The workflow ID (e.g. "workflow//./workflows/1_simple//simple") */
140
+ workflowId: string;
141
+ /** The workflow run entity */
142
+ workflowRun: WorkflowRun;
143
+ /** Features supported by the World executing this workflow. */
144
+ worldCapabilities?: WorldCapabilities;
145
+ /**
146
+ * The full event log for the run. Every invocation replays the complete
147
+ * log from the start (same replay semantics as the `node:vm` engine).
148
+ */
149
+ events: Event[];
150
+ /** Encryption key for decrypting event payloads (undefined if unencrypted) */
151
+ encryptionKey?: DecryptionKey;
152
+ /**
153
+ * The local port the workflow server is listening on, used to populate
154
+ * `workflowMetadata.url`. Resolved at call time on the host side so the
155
+ * VM doesn't have to probe the filesystem. Ignored on Vercel — VERCEL_URL
156
+ * takes precedence there.
157
+ */
158
+ port?: number;
159
+ /**
160
+ * Fallback workflow input from the queue message's resilient-start
161
+ * payload. Used when the fetched event log lacks a `run_created` event
162
+ * (eventually-consistent read after the parent's start() wrote it).
163
+ */
164
+ runInput?: RunInput;
165
+ }
166
+ /**
167
+ * A live QuickJS workflow invocation. When the initial `result` is
168
+ * `suspended`, the VM is kept alive so the caller can feed newly recorded
169
+ * events (e.g. terminal events of inline-executed steps) into the SAME VM
170
+ * via `continueWithEvents` — resuming execution exactly where it left off
171
+ * without a fresh-VM re-replay. Terminal results dispose the VM
172
+ * automatically; `dispose()` must be called when abandoning a suspended
173
+ * session (idempotent).
174
+ */
175
+ export interface QuickJSWorkflowSession {
176
+ result: QuickJSRuntimeResult;
177
+ /**
178
+ * Process newly recorded events in the live VM and re-evaluate the
179
+ * workflow state. Only valid while the last result was `suspended`.
180
+ * Resets the VM's interrupt budget for the new execution burst.
181
+ */
182
+ continueWithEvents(newEvents: Event[]): Promise<QuickJSRuntimeResult>;
183
+ /** Dispose the VM if it is still alive. Safe to call multiple times. */
184
+ dispose(): void;
185
+ }
186
+ /**
187
+ * Run a workflow invocation to its first settled state and dispose the
188
+ * VM. Convenience wrapper over {@link startQuickJSWorkflow} for callers
189
+ * (and tests) that don't use live-VM continuation.
190
+ */
191
+ export declare function runQuickJSWorkflow(options: QuickJSRuntimeOptions): Promise<QuickJSRuntimeResult>;
192
+ export declare function startQuickJSWorkflow(options: QuickJSRuntimeOptions): Promise<QuickJSWorkflowSession>;
193
+ //# sourceMappingURL=quickjs-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickjs-runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/quickjs-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EACV,KAAK,EACL,QAAQ,EACR,WAAW,EACX,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAWzB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AA8BpE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,KAAK,EAAE,UAAU,CAAC;IAClB,gEAAgE;IAChE,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC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