@workflow/core 5.0.0-beta.9 → 5.0.1

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 (345) hide show
  1. package/README.md +41 -0
  2. package/dist/attribute-changes.d.ts +4 -5
  3. package/dist/attribute-changes.d.ts.map +1 -1
  4. package/dist/attribute-changes.js +12 -4
  5. package/dist/capabilities.d.ts +35 -2
  6. package/dist/capabilities.d.ts.map +1 -1
  7. package/dist/capabilities.js +74 -5
  8. package/dist/capture-stack.d.ts +1 -1
  9. package/dist/capture-stack.js +2 -2
  10. package/dist/class-serialization.d.ts +32 -0
  11. package/dist/class-serialization.d.ts.map +1 -1
  12. package/dist/class-serialization.js +37 -1
  13. package/dist/classify-error.d.ts +15 -0
  14. package/dist/classify-error.d.ts.map +1 -1
  15. package/dist/classify-error.js +72 -4
  16. package/dist/context-violation-error.d.ts +5 -5
  17. package/dist/context-violation-error.d.ts.map +1 -1
  18. package/dist/context-violation-error.js +8 -6
  19. package/dist/create-hook.d.ts +109 -7
  20. package/dist/create-hook.d.ts.map +1 -1
  21. package/dist/create-hook.js +1 -1
  22. package/dist/define-hook.js +2 -2
  23. package/dist/describe-error.d.ts +7 -7
  24. package/dist/describe-error.d.ts.map +1 -1
  25. package/dist/describe-error.js +46 -7
  26. package/dist/encryption.d.ts +32 -4
  27. package/dist/encryption.d.ts.map +1 -1
  28. package/dist/encryption.js +85 -10
  29. package/dist/events-consumer.d.ts +300 -0
  30. package/dist/events-consumer.d.ts.map +1 -1
  31. package/dist/events-consumer.js +672 -42
  32. package/dist/flushable-stream.d.ts +97 -1
  33. package/dist/flushable-stream.d.ts.map +1 -1
  34. package/dist/flushable-stream.js +286 -10
  35. package/dist/global.d.ts +38 -2
  36. package/dist/global.d.ts.map +1 -1
  37. package/dist/global.js +21 -6
  38. package/dist/index.d.ts +2 -2
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +3 -3
  41. package/dist/log-format.d.ts +6 -2
  42. package/dist/log-format.d.ts.map +1 -1
  43. package/dist/log-format.js +60 -15
  44. package/dist/logger.d.ts +1 -0
  45. package/dist/logger.d.ts.map +1 -1
  46. package/dist/logger.js +13 -7
  47. package/dist/private.d.ts +258 -9
  48. package/dist/private.d.ts.map +1 -1
  49. package/dist/private.js +640 -7
  50. package/dist/replay-divergence.d.ts +25 -0
  51. package/dist/replay-divergence.d.ts.map +1 -0
  52. package/dist/replay-divergence.js +61 -0
  53. package/dist/replay-payload-cache.d.ts +64 -0
  54. package/dist/replay-payload-cache.d.ts.map +1 -0
  55. package/dist/replay-payload-cache.js +158 -0
  56. package/dist/runtime/compute-instance.d.ts +13 -0
  57. package/dist/runtime/compute-instance.d.ts.map +1 -0
  58. package/dist/runtime/compute-instance.js +14 -0
  59. package/dist/runtime/constants.d.ts +298 -5
  60. package/dist/runtime/constants.d.ts.map +1 -1
  61. package/dist/runtime/constants.js +500 -17
  62. package/dist/runtime/count-step-started-events.d.ts +52 -0
  63. package/dist/runtime/count-step-started-events.d.ts.map +1 -0
  64. package/dist/runtime/count-step-started-events.js +72 -0
  65. package/dist/runtime/deployment-guard.d.ts +100 -0
  66. package/dist/runtime/deployment-guard.d.ts.map +1 -0
  67. package/dist/runtime/deployment-guard.js +159 -0
  68. package/dist/runtime/dynamic-workflow.d.ts +182 -0
  69. package/dist/runtime/dynamic-workflow.d.ts.map +1 -0
  70. package/dist/runtime/dynamic-workflow.js +382 -0
  71. package/dist/runtime/get-port-lazy.d.ts +15 -0
  72. package/dist/runtime/get-port-lazy.d.ts.map +1 -1
  73. package/dist/runtime/get-port-lazy.js +75 -6
  74. package/dist/runtime/get-world-lazy.d.ts +5 -14
  75. package/dist/runtime/get-world-lazy.d.ts.map +1 -1
  76. package/dist/runtime/get-world-lazy.js +19 -29
  77. package/dist/runtime/helpers.d.ts +445 -29
  78. package/dist/runtime/helpers.d.ts.map +1 -1
  79. package/dist/runtime/helpers.js +717 -62
  80. package/dist/runtime/hook-wake.d.ts +122 -0
  81. package/dist/runtime/hook-wake.d.ts.map +1 -0
  82. package/dist/runtime/hook-wake.js +225 -0
  83. package/dist/runtime/invocations.d.ts +35 -0
  84. package/dist/runtime/invocations.d.ts.map +1 -0
  85. package/dist/runtime/invocations.js +172 -0
  86. package/dist/runtime/lifecycle-hooks.d.ts +93 -0
  87. package/dist/runtime/lifecycle-hooks.d.ts.map +1 -0
  88. package/dist/runtime/lifecycle-hooks.js +178 -0
  89. package/dist/runtime/open-hook-wait-state.d.ts +55 -0
  90. package/dist/runtime/open-hook-wait-state.d.ts.map +1 -0
  91. package/dist/runtime/open-hook-wait-state.js +93 -0
  92. package/dist/runtime/quickjs-assets.generated.d.ts +21 -0
  93. package/dist/runtime/quickjs-assets.generated.d.ts.map +1 -0
  94. package/dist/runtime/quickjs-assets.generated.js +37 -0
  95. package/dist/runtime/quickjs-entrypoint.d.ts +130 -0
  96. package/dist/runtime/quickjs-entrypoint.d.ts.map +1 -0
  97. package/dist/runtime/quickjs-entrypoint.js +2411 -0
  98. package/dist/runtime/quickjs-log-view.d.ts +152 -0
  99. package/dist/runtime/quickjs-log-view.d.ts.map +1 -0
  100. package/dist/runtime/quickjs-log-view.js +266 -0
  101. package/dist/runtime/quickjs-runtime.d.ts +299 -0
  102. package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
  103. package/dist/runtime/quickjs-runtime.js +2844 -0
  104. package/dist/runtime/quickjs-serde.d.ts +107 -0
  105. package/dist/runtime/quickjs-serde.d.ts.map +1 -0
  106. package/dist/runtime/quickjs-serde.js +2234 -0
  107. package/dist/runtime/quickjs-snapshot-codec.d.ts +74 -0
  108. package/dist/runtime/quickjs-snapshot-codec.d.ts.map +1 -0
  109. package/dist/runtime/quickjs-snapshot-codec.js +159 -0
  110. package/dist/runtime/replay-budget.d.ts +17 -18
  111. package/dist/runtime/replay-budget.d.ts.map +1 -1
  112. package/dist/runtime/replay-budget.js +33 -81
  113. package/dist/runtime/replay-recovery-reporter.d.ts +36 -0
  114. package/dist/runtime/replay-recovery-reporter.d.ts.map +1 -0
  115. package/dist/runtime/replay-recovery-reporter.js +64 -0
  116. package/dist/runtime/resume-hook.d.ts +93 -8
  117. package/dist/runtime/resume-hook.d.ts.map +1 -1
  118. package/dist/runtime/resume-hook.js +709 -110
  119. package/dist/runtime/resume-latency.d.ts +150 -0
  120. package/dist/runtime/resume-latency.d.ts.map +1 -0
  121. package/dist/runtime/resume-latency.js +155 -0
  122. package/dist/runtime/run-id-time.d.ts +19 -0
  123. package/dist/runtime/run-id-time.d.ts.map +1 -0
  124. package/dist/runtime/run-id-time.js +42 -0
  125. package/dist/runtime/run-spec-version.d.ts +16 -0
  126. package/dist/runtime/run-spec-version.d.ts.map +1 -0
  127. package/dist/runtime/run-spec-version.js +19 -0
  128. package/dist/runtime/run.d.ts +72 -7
  129. package/dist/runtime/run.d.ts.map +1 -1
  130. package/dist/runtime/run.js +295 -58
  131. package/dist/runtime/runs.d.ts +54 -3
  132. package/dist/runtime/runs.d.ts.map +1 -1
  133. package/dist/runtime/runs.js +148 -21
  134. package/dist/runtime/start.d.ts +164 -3
  135. package/dist/runtime/start.d.ts.map +1 -1
  136. package/dist/runtime/start.js +736 -89
  137. package/dist/runtime/step-executor.d.ts +186 -5
  138. package/dist/runtime/step-executor.d.ts.map +1 -1
  139. package/dist/runtime/step-executor.js +759 -125
  140. package/dist/runtime/step-latency.d.ts +221 -0
  141. package/dist/runtime/step-latency.d.ts.map +1 -0
  142. package/dist/runtime/step-latency.js +215 -0
  143. package/dist/runtime/step-ownership.d.ts +72 -0
  144. package/dist/runtime/step-ownership.d.ts.map +1 -0
  145. package/dist/runtime/step-ownership.js +114 -0
  146. package/dist/runtime/step-single-flight.d.ts +12 -0
  147. package/dist/runtime/step-single-flight.d.ts.map +1 -0
  148. package/dist/runtime/step-single-flight.js +71 -0
  149. package/dist/runtime/suspension-handler.d.ts +279 -10
  150. package/dist/runtime/suspension-handler.d.ts.map +1 -1
  151. package/dist/runtime/suspension-handler.js +1442 -169
  152. package/dist/runtime/unserializable-step.d.ts +34 -0
  153. package/dist/runtime/unserializable-step.d.ts.map +1 -0
  154. package/dist/runtime/unserializable-step.js +52 -0
  155. package/dist/runtime/vm-mode.d.ts +88 -0
  156. package/dist/runtime/vm-mode.d.ts.map +1 -0
  157. package/dist/runtime/vm-mode.js +140 -0
  158. package/dist/runtime/vm-serde-bundle.generated.d.ts +14 -0
  159. package/dist/runtime/vm-serde-bundle.generated.d.ts.map +1 -0
  160. package/dist/runtime/vm-serde-bundle.generated.js +16 -0
  161. package/dist/runtime/wait-continuation.d.ts +106 -0
  162. package/dist/runtime/wait-continuation.d.ts.map +1 -0
  163. package/dist/runtime/wait-continuation.js +136 -0
  164. package/dist/runtime/wait-until.d.ts +18 -0
  165. package/dist/runtime/wait-until.d.ts.map +1 -0
  166. package/dist/runtime/wait-until.js +42 -0
  167. package/dist/runtime/world-compatibility.d.ts +32 -0
  168. package/dist/runtime/world-compatibility.d.ts.map +1 -0
  169. package/dist/runtime/world-compatibility.js +44 -0
  170. package/dist/runtime/world-init.d.ts +17 -42
  171. package/dist/runtime/world-init.d.ts.map +1 -1
  172. package/dist/runtime/world-init.js +18 -43
  173. package/dist/runtime/world.d.ts +14 -2
  174. package/dist/runtime/world.d.ts.map +1 -1
  175. package/dist/runtime/world.js +75 -19
  176. package/dist/runtime.d.ts +11 -7
  177. package/dist/runtime.d.ts.map +1 -1
  178. package/dist/runtime.js +4117 -446
  179. package/dist/schemas.d.ts +1 -1
  180. package/dist/schemas.d.ts.map +1 -1
  181. package/dist/schemas.js +1 -1
  182. package/dist/sealed-box.d.ts +167 -0
  183. package/dist/sealed-box.d.ts.map +1 -0
  184. package/dist/sealed-box.js +571 -0
  185. package/dist/serialization/client.d.ts +3 -3
  186. package/dist/serialization/client.d.ts.map +1 -1
  187. package/dist/serialization/client.js +8 -4
  188. package/dist/serialization/codec-devalue-vm.d.ts +16 -0
  189. package/dist/serialization/codec-devalue-vm.d.ts.map +1 -0
  190. package/dist/serialization/codec-devalue-vm.js +148 -0
  191. package/dist/serialization/codec-devalue.d.ts +1 -1
  192. package/dist/serialization/codec-devalue.d.ts.map +1 -1
  193. package/dist/serialization/codec-devalue.js +24 -6
  194. package/dist/serialization/codec.d.ts +37 -2
  195. package/dist/serialization/codec.d.ts.map +1 -1
  196. package/dist/serialization/codec.js +2 -2
  197. package/dist/serialization/compression.d.ts +130 -0
  198. package/dist/serialization/compression.d.ts.map +1 -0
  199. package/dist/serialization/compression.js +316 -0
  200. package/dist/serialization/encryption.d.ts +119 -17
  201. package/dist/serialization/encryption.d.ts.map +1 -1
  202. package/dist/serialization/encryption.js +152 -17
  203. package/dist/serialization/errors.d.ts +13 -0
  204. package/dist/serialization/errors.d.ts.map +1 -1
  205. package/dist/serialization/errors.js +20 -2
  206. package/dist/serialization/format.d.ts +6 -6
  207. package/dist/serialization/format.js +7 -7
  208. package/dist/serialization/hardened.d.ts +164 -0
  209. package/dist/serialization/hardened.d.ts.map +1 -0
  210. package/dist/serialization/hardened.js +554 -0
  211. package/dist/serialization/index.d.ts +10 -8
  212. package/dist/serialization/index.d.ts.map +1 -1
  213. package/dist/serialization/index.js +10 -8
  214. package/dist/serialization/reducers/class-vm.d.ts +20 -0
  215. package/dist/serialization/reducers/class-vm.d.ts.map +1 -0
  216. package/dist/serialization/reducers/class-vm.js +77 -0
  217. package/dist/serialization/reducers/class.d.ts.map +1 -1
  218. package/dist/serialization/reducers/class.js +11 -6
  219. package/dist/serialization/reducers/common-vm.d.ts +15 -0
  220. package/dist/serialization/reducers/common-vm.d.ts.map +1 -0
  221. package/dist/serialization/reducers/common-vm.js +661 -0
  222. package/dist/serialization/reducers/common.d.ts +1 -1
  223. package/dist/serialization/reducers/common.d.ts.map +1 -1
  224. package/dist/serialization/reducers/common.js +227 -66
  225. package/dist/serialization/reducers/step-function-vm.d.ts +44 -0
  226. package/dist/serialization/reducers/step-function-vm.d.ts.map +1 -0
  227. package/dist/serialization/reducers/step-function-vm.js +97 -0
  228. package/dist/serialization/reducers/step-function.d.ts.map +1 -1
  229. package/dist/serialization/reducers/step-function.js +25 -9
  230. package/dist/serialization/step.d.ts +4 -4
  231. package/dist/serialization/step.d.ts.map +1 -1
  232. package/dist/serialization/step.js +9 -5
  233. package/dist/serialization/types.d.ts +75 -1
  234. package/dist/serialization/types.d.ts.map +1 -1
  235. package/dist/serialization/types.js +15 -1
  236. package/dist/serialization/workflow-vm.d.ts +29 -0
  237. package/dist/serialization/workflow-vm.d.ts.map +1 -0
  238. package/dist/serialization/workflow-vm.js +74 -0
  239. package/dist/serialization-format.d.ts +64 -8
  240. package/dist/serialization-format.d.ts.map +1 -1
  241. package/dist/serialization-format.js +239 -73
  242. package/dist/serialization.d.ts +319 -34
  243. package/dist/serialization.d.ts.map +1 -1
  244. package/dist/serialization.js +1961 -321
  245. package/dist/set-attributes.d.ts +7 -7
  246. package/dist/set-attributes.d.ts.map +1 -1
  247. package/dist/set-attributes.js +42 -21
  248. package/dist/set-error-stack.d.ts +12 -0
  249. package/dist/set-error-stack.d.ts.map +1 -0
  250. package/dist/set-error-stack.js +30 -0
  251. package/dist/source-map.d.ts +25 -0
  252. package/dist/source-map.d.ts.map +1 -1
  253. package/dist/source-map.js +113 -7
  254. package/dist/step/context-storage.d.ts +50 -3
  255. package/dist/step/context-storage.d.ts.map +1 -1
  256. package/dist/step/context-storage.js +7 -5
  257. package/dist/step/writable-stream.d.ts +3 -3
  258. package/dist/step/writable-stream.d.ts.map +1 -1
  259. package/dist/step/writable-stream.js +53 -19
  260. package/dist/step.d.ts.map +1 -1
  261. package/dist/step.js +142 -28
  262. package/dist/symbols.d.ts +35 -1
  263. package/dist/symbols.d.ts.map +1 -1
  264. package/dist/symbols.js +36 -2
  265. package/dist/telemetry/semantic-conventions.d.ts +509 -2
  266. package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
  267. package/dist/telemetry/semantic-conventions.js +363 -3
  268. package/dist/telemetry.d.ts +91 -0
  269. package/dist/telemetry.d.ts.map +1 -1
  270. package/dist/telemetry.js +244 -17
  271. package/dist/test-support/orchestrator-context.d.ts +25 -0
  272. package/dist/test-support/orchestrator-context.d.ts.map +1 -0
  273. package/dist/test-support/orchestrator-context.js +107 -0
  274. package/dist/types.d.ts +23 -0
  275. package/dist/types.d.ts.map +1 -1
  276. package/dist/types.js +76 -1
  277. package/dist/util.d.ts +0 -5
  278. package/dist/util.d.ts.map +1 -1
  279. package/dist/util.js +1 -15
  280. package/dist/version.d.ts +1 -1
  281. package/dist/version.d.ts.map +1 -1
  282. package/dist/version.js +2 -2
  283. package/dist/vm/index.d.ts.map +1 -1
  284. package/dist/vm/index.js +84 -14
  285. package/dist/vm/script-cache.d.ts +26 -0
  286. package/dist/vm/script-cache.d.ts.map +1 -0
  287. package/dist/vm/script-cache.js +131 -0
  288. package/dist/vm/uint8array-base64.js +1 -1
  289. package/dist/workflow/abort-controller.d.ts +2 -2
  290. package/dist/workflow/abort-controller.d.ts.map +1 -1
  291. package/dist/workflow/abort-controller.js +75 -21
  292. package/dist/workflow/attribute-dispatcher.d.ts +6 -0
  293. package/dist/workflow/attribute-dispatcher.d.ts.map +1 -0
  294. package/dist/workflow/attribute-dispatcher.js +65 -0
  295. package/dist/workflow/create-hook.d.ts.map +1 -1
  296. package/dist/workflow/create-hook.js +24 -3
  297. package/dist/workflow/get-workflow-metadata.js +2 -2
  298. package/dist/workflow/hook.d.ts.map +1 -1
  299. package/dist/workflow/hook.js +403 -53
  300. package/dist/workflow/index.d.ts +1 -1
  301. package/dist/workflow/index.d.ts.map +1 -1
  302. package/dist/workflow/index.js +2 -2
  303. package/dist/workflow/set-attributes.d.ts +19 -21
  304. package/dist/workflow/set-attributes.d.ts.map +1 -1
  305. package/dist/workflow/set-attributes.js +23 -25
  306. package/dist/workflow/sleep.d.ts.map +1 -1
  307. package/dist/workflow/sleep.js +42 -13
  308. package/dist/workflow/world-init-stub.d.ts +3 -3
  309. package/dist/workflow/world-init-stub.js +4 -4
  310. package/dist/workflow.d.ts +89 -3
  311. package/dist/workflow.d.ts.map +1 -1
  312. package/dist/workflow.js +920 -568
  313. package/docs/api-reference/create-hook.mdx +170 -10
  314. package/docs/api-reference/create-webhook.mdx +16 -15
  315. package/docs/api-reference/define-hook.mdx +41 -33
  316. package/docs/api-reference/fatal-error.mdx +30 -8
  317. package/docs/api-reference/fetch.mdx +14 -10
  318. package/docs/api-reference/get-step-metadata.mdx +2 -2
  319. package/docs/api-reference/get-workflow-metadata.mdx +3 -3
  320. package/docs/api-reference/get-writable.mdx +7 -7
  321. package/docs/api-reference/index.mdx +3 -3
  322. package/docs/api-reference/retryable-error.mdx +1 -1
  323. package/docs/api-reference/set-attributes.mdx +63 -0
  324. package/docs/api-reference/sleep.mdx +4 -4
  325. package/docs/foundations/cancellation.mdx +31 -32
  326. package/docs/foundations/errors-and-retries.mdx +54 -11
  327. package/docs/foundations/hooks.mdx +187 -36
  328. package/docs/foundations/idempotency.mdx +267 -12
  329. package/docs/foundations/index.mdx +1 -26
  330. package/docs/foundations/serialization.mdx +22 -22
  331. package/docs/foundations/starting-workflows.mdx +104 -30
  332. package/docs/foundations/streaming.mdx +108 -60
  333. package/docs/foundations/versioning.mdx +4 -4
  334. package/docs/foundations/workflows-and-steps.mdx +10 -10
  335. package/docs/how-it-works/cancellation.mdx +63 -63
  336. package/docs/how-it-works/code-transform.mdx +82 -66
  337. package/docs/how-it-works/encryption.mdx +30 -26
  338. package/docs/how-it-works/event-sourcing.mdx +132 -35
  339. package/docs/how-it-works/framework-integrations.mdx +96 -337
  340. package/docs/how-it-works/understanding-directives.mdx +22 -22
  341. package/package.json +29 -15
  342. package/dist/runtime/step-handler.d.ts +0 -2
  343. package/dist/runtime/step-handler.d.ts.map +0 -1
  344. package/dist/runtime/step-handler.js +0 -779
  345. package/docs/api-reference/experimental-set-attributes.mdx +0 -63
@@ -0,0 +1,299 @@
1
+ /**
2
+ * QuickJS WebAssembly (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 and the workflow primitives. (Serialization lives on
19
+ * the host (see quickjs-serde.ts) so no serde code is evaluated
20
+ * in the VM.)
21
+ * 2. Per-run initialization (inline in `runQuickJSWorkflow`): seeded
22
+ * PRNG/ULID host functions, workflow bundle evaluation, run metadata,
23
+ * workflow input, and start.
24
+ * Keeping the phases separate is groundwork for VM-memory snapshotting:
25
+ * a follow-up can persist/restore the VM at the phase boundary (e.g. a
26
+ * build-time initial snapshot) without restructuring this module. Note
27
+ * that bundle evaluation currently sits in the per-run phase so that
28
+ * module-scope user code observes the seeded `Math.random`, matching the
29
+ * `node:vm` engine's replay determinism.
30
+ */
31
+ import { SerializationError } from '@workflow/errors';
32
+ import { type Event, type RunInput, type SnapshotMetadata, type WorkflowRun, type WorldCapabilities } from '@workflow/world';
33
+ import { type AttributeChange } from '@workflow/world/attributes-validation';
34
+ import { type Snapshot } from 'quickjs-wasi';
35
+ import type { DecryptionKey } from '../serialization/encryption.js';
36
+ export interface PendingStep {
37
+ type: 'step';
38
+ correlationId: string;
39
+ stepId: string;
40
+ /**
41
+ * Format-prefixed devalue-serialized step input (args + closureVars).
42
+ * Absent when {@link serializationError} is set: the input is precisely
43
+ * what refused to serialize.
44
+ */
45
+ input?: Uint8Array;
46
+ /** Whether a step_created event already exists for this step */
47
+ hasCreatedEvent: boolean;
48
+ /**
49
+ * Set when host-side serialization of the step's raw input failed while
50
+ * dumping the VM's pending ops (see `dumpPendingOps`). The failure is
51
+ * deterministic (replaying re-derives the same unserializable value), so
52
+ * instead of failing the whole collection the op is surfaced with the
53
+ * reframed error and no `input`; the entrypoint finalizes the step as
54
+ * `step_created` (placeholder input) + `step_failed`, mirroring the
55
+ * node:vm engine's `finalizeUnserializableStep`, so a try/catch around
56
+ * the step call observes the SerializationError.
57
+ */
58
+ serializationError?: SerializationError;
59
+ }
60
+ export interface PendingWait {
61
+ type: 'wait';
62
+ correlationId: string;
63
+ /** ISO string of when to resume */
64
+ resumeAt: string;
65
+ /** Whether a wait_created event already exists for this wait */
66
+ hasCreatedEvent: boolean;
67
+ }
68
+ export interface PendingHook {
69
+ type: 'hook';
70
+ correlationId: string;
71
+ token: string;
72
+ /** Earliest token reuse time, as milliseconds since the Unix epoch. */
73
+ tokenRetentionUntil?: number;
74
+ isWebhook: boolean;
75
+ /** `createHook({ experimental_force })`: take the token over if held. */
76
+ force?: boolean;
77
+ metadata?: unknown;
78
+ hasCreatedEvent: boolean;
79
+ /**
80
+ * True for internal system hooks (e.g. AbortController's hook), which
81
+ * are exempt from user-hook token namespace conflict checks.
82
+ */
83
+ isSystem?: boolean;
84
+ /**
85
+ * Set when the workflow called AbortController.abort() during this
86
+ * invocation. The host must record the abort: create a hook_received
87
+ * event carrying `abortPayload` and write/close the abort stream.
88
+ */
89
+ abortRequested?: boolean;
90
+ /** VM-serialized `{ aborted: true, reason }` payload for the abort. */
91
+ abortPayload?: Uint8Array;
92
+ /** Set by the completion drain when a system hook is implicitly disposed. */
93
+ disposed?: boolean;
94
+ /**
95
+ * True when the workflow is awaiting hook.getConflict() for this hook.
96
+ * The entrypoint re-invokes the workflow right after writing
97
+ * hook_created so replay can confirm creation and resolve the awaiter.
98
+ */
99
+ hasGetConflictAwaiter?: boolean;
100
+ }
101
+ export interface PendingAttribute {
102
+ type: 'attribute';
103
+ correlationId: string;
104
+ /** Normalized attribute changes (plain JSON-able objects) */
105
+ changes: AttributeChange[];
106
+ allowReservedAttributes?: boolean;
107
+ /** Whether an attr_set event already exists for this write */
108
+ hasCreatedEvent: boolean;
109
+ }
110
+ export interface PendingHookDispose {
111
+ type: 'hook_dispose';
112
+ correlationId: string;
113
+ /**
114
+ * Token of the hook being disposed. Used by the entrypoint to order
115
+ * same-token hook operations sequentially in code order.
116
+ */
117
+ token?: string;
118
+ hasCreatedEvent: boolean;
119
+ }
120
+ export type PendingOperation = PendingStep | PendingWait | PendingHook | PendingAttribute | PendingHookDispose;
121
+ export interface QuickJSRuntimeResult {
122
+ /** The workflow completed: result is format-prefixed devalue bytes */
123
+ completed?: {
124
+ result: Uint8Array;
125
+ /**
126
+ * Leftover pending operations that still need durable side effects at
127
+ * completion: abort recordings, system-hook disposals, fire-and-forget
128
+ * attribute/hook/step events. Mirrors the node:vm engine's
129
+ * drainPendingQueueItems. The entrypoint dispatches these WITHOUT
130
+ * queueing steps or requeuing the run.
131
+ */
132
+ drainOperations?: PendingOperation[];
133
+ };
134
+ /** The workflow suspended with pending operations */
135
+ suspended?: {
136
+ pendingOperations: PendingOperation[];
137
+ };
138
+ /** The workflow failed */
139
+ failed?: {
140
+ message: string;
141
+ stack?: string;
142
+ name?: string;
143
+ /** See completed.drainOperations: same semantics on failure. */
144
+ drainOperations?: PendingOperation[];
145
+ /**
146
+ * Format-prefixed devalue bytes of the original thrown value
147
+ * (Error subclass with cause chain, plain object, primitive, etc.).
148
+ * Set when the VM-side rejection handler successfully serializes
149
+ * the thrown value. The host uses these bytes to reconstruct the
150
+ * original value through the standard error hydration pipeline,
151
+ * preserving type identity (TypeError, FatalError) and non-Error
152
+ * throws verbatim. Falls back to the message/stack/name fields
153
+ * when this is undefined (e.g. extractError pseudo-failures).
154
+ */
155
+ valueBytes?: Uint8Array;
156
+ };
157
+ }
158
+ export interface QuickJSRuntimeOptions {
159
+ /** The compiled workflow bundle code (workflow mode output from SWC) */
160
+ workflowCode: string;
161
+ /** The workflow ID (e.g. "workflow//./workflows/1_simple//simple") */
162
+ workflowId: string;
163
+ /** The workflow run entity */
164
+ workflowRun: WorkflowRun;
165
+ /** Features supported by the World executing this workflow. */
166
+ worldCapabilities?: WorldCapabilities;
167
+ /**
168
+ * The event log to process. Without a snapshot this is the FULL log and
169
+ * every invocation replays it from the start (same replay semantics as
170
+ * the `node:vm` engine). With `existingSnapshot`, this is the delta of
171
+ * events recorded at/after the snapshot's `eventsCursor` — feeding
172
+ * already-consumed events is harmless (consumed resolvers are gone and
173
+ * hook deliveries are deduped in the VM heap), so an imprecise cursor
174
+ * only costs redundant scanning.
175
+ */
176
+ events: Event[];
177
+ /**
178
+ * A previously persisted VM-memory snapshot to restore from, or
179
+ * null/undefined for a fresh boot + full replay. Restoring skips VM
180
+ * bootstrap, bundle evaluation, and pre-snapshot re-execution entirely:
181
+ * the WASM heap resumes at the exact suspension point it was captured
182
+ * at, and only `events` are processed on top.
183
+ */
184
+ existingSnapshot?: {
185
+ data: Uint8Array;
186
+ metadata: SnapshotMetadata;
187
+ } | null;
188
+ /** Encryption key for decrypting event payloads (undefined if unencrypted) */
189
+ encryptionKey?: DecryptionKey;
190
+ /**
191
+ * The local port the workflow server is listening on, used to populate
192
+ * `workflowMetadata.url`. Resolved at call time on the host side so the
193
+ * VM doesn't have to probe the filesystem. Ignored on Vercel, where
194
+ * VERCEL_URL takes precedence.
195
+ */
196
+ port?: number;
197
+ /**
198
+ * Fallback workflow input from the queue message's resilient-start
199
+ * payload. Used when the fetched event log lacks a `run_created` event
200
+ * (eventually-consistent read after the parent's start() wrote it).
201
+ */
202
+ runInput?: RunInput;
203
+ }
204
+ /**
205
+ * Eval filename used when hydrating the baseline VM. The baseline is
206
+ * shared by EVERY workflow in the bundle, so the filename baked into
207
+ * its compiled code (and therefore into snapshot-path stack frames)
208
+ * must be workflow-independent: hydrating under the first caller's
209
+ * workflowId would break `remapErrorStack`'s filename matching for
210
+ * every other workflow in the bundle. Remap call sites match this
211
+ * constant IN ADDITION to the run's module specifier (which covers
212
+ * fresh-path frames).
213
+ */
214
+ export declare const BASELINE_BUNDLE_FILENAME = "workflow-bundle.js";
215
+ type BaselineEntry = {
216
+ state: 'ready';
217
+ snapshot: Snapshot;
218
+ /**
219
+ * Raw box pointer of the serde capture root created BEFORE the
220
+ * bundle evaluated (see captureSerdeRoot). The box lives in the
221
+ * snapshot's memory image at this offset; every restored VM
222
+ * re-adopts it so serde initialization executes no guest code
223
+ * after user code has run: capture-before-user-code semantics,
224
+ * identical to the fresh path.
225
+ */
226
+ serdeRootPtr: number;
227
+ } | {
228
+ state: 'ineligible';
229
+ reason: string;
230
+ };
231
+ /** Test-only: reset the baseline cache between test cases. */
232
+ export declare function __clearBaselineSnapshotCacheForTests(): void;
233
+ /** Test-only: observe how a bundle was classified. */
234
+ export declare function __peekBaselineEntryForTests(workflowCode: string): Promise<BaselineEntry | undefined>;
235
+ /**
236
+ * Continue a monotonic ULID sequence from a persisted last value:
237
+ * re-implements the `ulid` package's same-timestamp step (Crockford
238
+ * base32 +1 on the 16-char random part, carrying left; the 10-char time
239
+ * prefix is preserved — the run's seed timestamp is constant, so the
240
+ * package would never re-encode it). Byte-for-byte equivalent to what
241
+ * `monotonicFactory` returns for the same draw position, which is what
242
+ * keeps correlation ids identical between a snapshot-restored invocation
243
+ * and a full replay. Exported for tests (equivalence is asserted against
244
+ * the package itself).
245
+ */
246
+ export declare function incrementUlidRandom(prev: string): string;
247
+ /**
248
+ * A live QuickJS workflow invocation. When the initial `result` is
249
+ * `suspended`, the VM is kept alive so the caller can feed newly recorded
250
+ * events (e.g. terminal events of inline-executed steps) into the SAME VM
251
+ * via `continueWithEvents`, resuming execution exactly where it left off
252
+ * without a fresh-VM re-replay. Terminal results dispose the VM
253
+ * automatically; `dispose()` must be called when abandoning a suspended
254
+ * session (idempotent).
255
+ */
256
+ export interface QuickJSWorkflowSession {
257
+ result: QuickJSRuntimeResult;
258
+ /**
259
+ * Process newly recorded events in the live VM and re-evaluate the
260
+ * workflow state. Only valid while the last result was `suspended`.
261
+ * Resets the VM's interrupt budget for the new execution burst.
262
+ */
263
+ continueWithEvents(newEvents: Event[]): Promise<QuickJSRuntimeResult>;
264
+ /**
265
+ * Capture and serialize the live VM's memory. Only valid while the
266
+ * last result was `suspended`. The returned bytes restore via
267
+ * `existingSnapshot` on a later invocation (pair them with the events
268
+ * cursor at capture time). `rngDraws` is the seeded PRNG's draw count
269
+ * at capture — persisted in the snapshot metadata so a restore
270
+ * fast-forwards the base seed to the same position. `lastUlid` is the
271
+ * monotonic correlation-id factory's last output (undefined if the
272
+ * run has drawn none) — persisted so a restore continues the exact
273
+ * ULID sequence instead of drawing fresh randomness. `serdeRootPtr`
274
+ * is the host-serde capture root's snapshot-portable token — the
275
+ * restore path re-adopts it so serde initialization executes no guest
276
+ * code after user code has run.
277
+ */
278
+ snapshot(): {
279
+ data: Uint8Array;
280
+ rngDraws: number;
281
+ lastUlid: string | undefined;
282
+ serdeRootPtr: number;
283
+ /** Deterministic clock high-water mark at capture (ms since epoch). */
284
+ clockMs: number;
285
+ /** Exact engine build (quickjs-wasi version) that captured the heap. */
286
+ engineVersion: string;
287
+ };
288
+ /** Dispose the VM if it is still alive. Safe to call multiple times. */
289
+ dispose(): void;
290
+ }
291
+ /**
292
+ * Run a workflow invocation to its first settled state and dispose the
293
+ * VM. Convenience wrapper over {@link startQuickJSWorkflow} for callers
294
+ * (and tests) that don't use live-VM continuation.
295
+ */
296
+ export declare function runQuickJSWorkflow(options: QuickJSRuntimeOptions): Promise<QuickJSRuntimeResult>;
297
+ export declare function startQuickJSWorkflow(options: QuickJSRuntimeOptions): Promise<QuickJSWorkflowSession>;
298
+ export {};
299
+ //# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;A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