@workflow/core 5.0.0-beta.4 → 5.0.0-beta.41

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 (322) hide show
  1. package/dist/attribute-changes.d.ts +7 -0
  2. package/dist/attribute-changes.d.ts.map +1 -0
  3. package/dist/attribute-changes.js +25 -0
  4. package/dist/capabilities.d.ts +33 -1
  5. package/dist/capabilities.d.ts.map +1 -1
  6. package/dist/capabilities.js +71 -4
  7. package/dist/capture-stack.d.ts +16 -0
  8. package/dist/capture-stack.d.ts.map +1 -0
  9. package/dist/capture-stack.js +21 -0
  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 +26 -3
  14. package/dist/classify-error.d.ts.map +1 -1
  15. package/dist/classify-error.js +109 -6
  16. package/dist/context-errors.d.ts +27 -0
  17. package/dist/context-errors.d.ts.map +1 -0
  18. package/dist/context-errors.js +101 -0
  19. package/dist/context-violation-error.d.ts +97 -0
  20. package/dist/context-violation-error.d.ts.map +1 -0
  21. package/dist/context-violation-error.js +149 -0
  22. package/dist/create-hook.d.ts +62 -4
  23. package/dist/create-hook.d.ts.map +1 -1
  24. package/dist/create-hook.js +4 -3
  25. package/dist/define-hook.d.ts.map +1 -1
  26. package/dist/define-hook.js +20 -5
  27. package/dist/describe-error.d.ts +70 -0
  28. package/dist/describe-error.d.ts.map +1 -0
  29. package/dist/describe-error.js +189 -0
  30. package/dist/encryption.d.ts +37 -3
  31. package/dist/encryption.d.ts.map +1 -1
  32. package/dist/encryption.js +97 -31
  33. package/dist/events-consumer.d.ts +147 -1
  34. package/dist/events-consumer.d.ts.map +1 -1
  35. package/dist/events-consumer.js +444 -43
  36. package/dist/flushable-stream.d.ts +65 -10
  37. package/dist/flushable-stream.d.ts.map +1 -1
  38. package/dist/flushable-stream.js +131 -18
  39. package/dist/global.d.ts +37 -1
  40. package/dist/global.d.ts.map +1 -1
  41. package/dist/global.js +21 -3
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +2 -1
  45. package/dist/log-format.d.ts +25 -0
  46. package/dist/log-format.d.ts.map +1 -0
  47. package/dist/log-format.js +250 -0
  48. package/dist/logger.d.ts +29 -30
  49. package/dist/logger.d.ts.map +1 -1
  50. package/dist/logger.js +82 -32
  51. package/dist/private.d.ts +246 -8
  52. package/dist/private.d.ts.map +1 -1
  53. package/dist/private.js +345 -9
  54. package/dist/replay-payload-cache.d.ts +68 -0
  55. package/dist/replay-payload-cache.d.ts.map +1 -0
  56. package/dist/replay-payload-cache.js +160 -0
  57. package/dist/runtime/compute-instance.d.ts +12 -0
  58. package/dist/runtime/compute-instance.d.ts.map +1 -0
  59. package/dist/runtime/compute-instance.js +13 -0
  60. package/dist/runtime/constants.d.ts +251 -0
  61. package/dist/runtime/constants.d.ts.map +1 -1
  62. package/dist/runtime/constants.js +425 -16
  63. package/dist/runtime/count-step-started-events.d.ts +52 -0
  64. package/dist/runtime/count-step-started-events.d.ts.map +1 -0
  65. package/dist/runtime/count-step-started-events.js +72 -0
  66. package/dist/runtime/deployment-guard.d.ts +99 -0
  67. package/dist/runtime/deployment-guard.d.ts.map +1 -0
  68. package/dist/runtime/deployment-guard.js +154 -0
  69. package/dist/runtime/get-port-lazy.d.ts +25 -0
  70. package/dist/runtime/get-port-lazy.d.ts.map +1 -0
  71. package/dist/runtime/get-port-lazy.js +92 -0
  72. package/dist/runtime/get-world-lazy.d.ts +23 -0
  73. package/dist/runtime/get-world-lazy.d.ts.map +1 -0
  74. package/dist/runtime/get-world-lazy.js +46 -0
  75. package/dist/runtime/helpers.d.ts +327 -10
  76. package/dist/runtime/helpers.d.ts.map +1 -1
  77. package/dist/runtime/helpers.js +586 -40
  78. package/dist/runtime/quickjs-assets.generated.d.ts +14 -0
  79. package/dist/runtime/quickjs-assets.generated.d.ts.map +1 -0
  80. package/dist/runtime/quickjs-assets.generated.js +30 -0
  81. package/dist/runtime/quickjs-entrypoint.d.ts +124 -0
  82. package/dist/runtime/quickjs-entrypoint.d.ts.map +1 -0
  83. package/dist/runtime/quickjs-entrypoint.js +1437 -0
  84. package/dist/runtime/quickjs-runtime.d.ts +228 -0
  85. package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
  86. package/dist/runtime/quickjs-runtime.js +2372 -0
  87. package/dist/runtime/quickjs-serde.d.ts +107 -0
  88. package/dist/runtime/quickjs-serde.d.ts.map +1 -0
  89. package/dist/runtime/quickjs-serde.js +2098 -0
  90. package/dist/runtime/replay-budget.d.ts +89 -0
  91. package/dist/runtime/replay-budget.d.ts.map +1 -0
  92. package/dist/runtime/replay-budget.js +139 -0
  93. package/dist/runtime/replay-recovery-reporter.d.ts +36 -0
  94. package/dist/runtime/replay-recovery-reporter.d.ts.map +1 -0
  95. package/dist/runtime/replay-recovery-reporter.js +64 -0
  96. package/dist/runtime/resume-hook.d.ts +27 -4
  97. package/dist/runtime/resume-hook.d.ts.map +1 -1
  98. package/dist/runtime/resume-hook.js +452 -76
  99. package/dist/runtime/run-id-time.d.ts +19 -0
  100. package/dist/runtime/run-id-time.d.ts.map +1 -0
  101. package/dist/runtime/run-id-time.js +42 -0
  102. package/dist/runtime/run.d.ts +8 -2
  103. package/dist/runtime/run.d.ts.map +1 -1
  104. package/dist/runtime/run.js +62 -15
  105. package/dist/runtime/runs.d.ts +54 -3
  106. package/dist/runtime/runs.d.ts.map +1 -1
  107. package/dist/runtime/runs.js +119 -13
  108. package/dist/runtime/start.d.ts +70 -1
  109. package/dist/runtime/start.d.ts.map +1 -1
  110. package/dist/runtime/start.js +313 -60
  111. package/dist/runtime/step-executor.d.ts +177 -0
  112. package/dist/runtime/step-executor.d.ts.map +1 -0
  113. package/dist/runtime/step-executor.js +946 -0
  114. package/dist/runtime/step-latency.d.ts +197 -0
  115. package/dist/runtime/step-latency.d.ts.map +1 -0
  116. package/dist/runtime/step-latency.js +207 -0
  117. package/dist/runtime/step-ownership.d.ts +72 -0
  118. package/dist/runtime/step-ownership.d.ts.map +1 -0
  119. package/dist/runtime/step-ownership.js +114 -0
  120. package/dist/runtime/step-single-flight.d.ts +12 -0
  121. package/dist/runtime/step-single-flight.d.ts.map +1 -0
  122. package/dist/runtime/step-single-flight.js +69 -0
  123. package/dist/runtime/suspension-handler.d.ts +109 -7
  124. package/dist/runtime/suspension-handler.d.ts.map +1 -1
  125. package/dist/runtime/suspension-handler.js +486 -140
  126. package/dist/runtime/vm-mode.d.ts +44 -0
  127. package/dist/runtime/vm-mode.d.ts.map +1 -0
  128. package/dist/runtime/vm-mode.js +62 -0
  129. package/dist/runtime/vm-serde-bundle.generated.d.ts +14 -0
  130. package/dist/runtime/vm-serde-bundle.generated.d.ts.map +1 -0
  131. package/dist/runtime/vm-serde-bundle.generated.js +16 -0
  132. package/dist/runtime/wait-continuation.d.ts +84 -0
  133. package/dist/runtime/wait-continuation.d.ts.map +1 -0
  134. package/dist/runtime/wait-continuation.js +105 -0
  135. package/dist/runtime/wait-until.d.ts +18 -0
  136. package/dist/runtime/wait-until.d.ts.map +1 -0
  137. package/dist/runtime/wait-until.js +42 -0
  138. package/dist/runtime/world-compatibility.d.ts +20 -0
  139. package/dist/runtime/world-compatibility.d.ts.map +1 -0
  140. package/dist/runtime/world-compatibility.js +32 -0
  141. package/dist/runtime/world-init.d.ts +50 -0
  142. package/dist/runtime/world-init.d.ts.map +1 -0
  143. package/dist/runtime/world-init.js +50 -0
  144. package/dist/runtime/world.d.ts +14 -2
  145. package/dist/runtime/world.d.ts.map +1 -1
  146. package/dist/runtime/world.js +101 -26
  147. package/dist/runtime.d.ts +17 -12
  148. package/dist/runtime.d.ts.map +1 -1
  149. package/dist/runtime.js +3135 -328
  150. package/dist/schemas.d.ts +1 -1
  151. package/dist/schemas.d.ts.map +1 -1
  152. package/dist/schemas.js +1 -1
  153. package/dist/sealed-box.d.ts +167 -0
  154. package/dist/sealed-box.d.ts.map +1 -0
  155. package/dist/sealed-box.js +571 -0
  156. package/dist/serialization/client.d.ts +17 -0
  157. package/dist/serialization/client.d.ts.map +1 -0
  158. package/dist/serialization/client.js +48 -0
  159. package/dist/serialization/codec-devalue-vm.d.ts +16 -0
  160. package/dist/serialization/codec-devalue-vm.d.ts.map +1 -0
  161. package/dist/serialization/codec-devalue-vm.js +148 -0
  162. package/dist/serialization/codec-devalue.d.ts +14 -0
  163. package/dist/serialization/codec-devalue.d.ts.map +1 -0
  164. package/dist/serialization/codec-devalue.js +105 -0
  165. package/dist/serialization/codec.d.ts +125 -0
  166. package/dist/serialization/codec.d.ts.map +1 -0
  167. package/dist/serialization/codec.js +17 -0
  168. package/dist/serialization/compression.d.ts +104 -0
  169. package/dist/serialization/compression.d.ts.map +1 -0
  170. package/dist/serialization/compression.js +260 -0
  171. package/dist/serialization/encryption.d.ts +134 -0
  172. package/dist/serialization/encryption.d.ts.map +1 -0
  173. package/dist/serialization/encryption.js +186 -0
  174. package/dist/serialization/errors.d.ts +34 -0
  175. package/dist/serialization/errors.d.ts.map +1 -0
  176. package/dist/serialization/errors.js +59 -0
  177. package/dist/serialization/format.d.ts +60 -0
  178. package/dist/serialization/format.d.ts.map +1 -0
  179. package/dist/serialization/format.js +97 -0
  180. package/dist/serialization/hardened.d.ts +155 -0
  181. package/dist/serialization/hardened.d.ts.map +1 -0
  182. package/dist/serialization/hardened.js +523 -0
  183. package/dist/serialization/index.d.ts +20 -0
  184. package/dist/serialization/index.d.ts.map +1 -0
  185. package/dist/serialization/index.js +22 -0
  186. package/dist/serialization/reducers/class-vm.d.ts +20 -0
  187. package/dist/serialization/reducers/class-vm.d.ts.map +1 -0
  188. package/dist/serialization/reducers/class-vm.js +77 -0
  189. package/dist/serialization/reducers/class.d.ts +11 -0
  190. package/dist/serialization/reducers/class.d.ts.map +1 -0
  191. package/dist/serialization/reducers/class.js +73 -0
  192. package/dist/serialization/reducers/common-vm.d.ts +15 -0
  193. package/dist/serialization/reducers/common-vm.d.ts.map +1 -0
  194. package/dist/serialization/reducers/common-vm.js +579 -0
  195. package/dist/serialization/reducers/common.d.ts +16 -0
  196. package/dist/serialization/reducers/common.d.ts.map +1 -0
  197. package/dist/serialization/reducers/common.js +478 -0
  198. package/dist/serialization/reducers/step-function-vm.d.ts +44 -0
  199. package/dist/serialization/reducers/step-function-vm.d.ts.map +1 -0
  200. package/dist/serialization/reducers/step-function-vm.js +97 -0
  201. package/dist/serialization/reducers/step-function.d.ts +35 -0
  202. package/dist/serialization/reducers/step-function.d.ts.map +1 -0
  203. package/dist/serialization/reducers/step-function.js +104 -0
  204. package/dist/serialization/step.d.ts +17 -0
  205. package/dist/serialization/step.d.ts.map +1 -0
  206. package/dist/serialization/step.js +48 -0
  207. package/dist/serialization/types.d.ts +273 -0
  208. package/dist/serialization/types.d.ts.map +1 -0
  209. package/dist/serialization/types.js +35 -0
  210. package/dist/serialization/workflow-vm.d.ts +29 -0
  211. package/dist/serialization/workflow-vm.d.ts.map +1 -0
  212. package/dist/serialization/workflow-vm.js +71 -0
  213. package/dist/serialization/workflow.d.ts +29 -0
  214. package/dist/serialization/workflow.d.ts.map +1 -0
  215. package/dist/serialization/workflow.js +54 -0
  216. package/dist/serialization-format.d.ts +60 -4
  217. package/dist/serialization-format.d.ts.map +1 -1
  218. package/dist/serialization-format.js +276 -56
  219. package/dist/serialization.d.ts +374 -221
  220. package/dist/serialization.d.ts.map +1 -1
  221. package/dist/serialization.js +2300 -783
  222. package/dist/set-attributes.d.ts +13 -0
  223. package/dist/set-attributes.d.ts.map +1 -0
  224. package/dist/set-attributes.js +60 -0
  225. package/dist/sleep.d.ts.map +1 -1
  226. package/dist/sleep.js +3 -2
  227. package/dist/source-map.d.ts +25 -0
  228. package/dist/source-map.d.ts.map +1 -1
  229. package/dist/source-map.js +148 -10
  230. package/dist/step/context-storage.d.ts +61 -2
  231. package/dist/step/context-storage.d.ts.map +1 -1
  232. package/dist/step/context-storage.js +7 -5
  233. package/dist/step/get-closure-vars.d.ts.map +1 -1
  234. package/dist/step/get-closure-vars.js +3 -2
  235. package/dist/step/get-step-metadata.d.ts.map +1 -1
  236. package/dist/step/get-step-metadata.js +3 -2
  237. package/dist/step/get-workflow-metadata.d.ts.map +1 -1
  238. package/dist/step/get-workflow-metadata.js +3 -2
  239. package/dist/step/writable-stream.d.ts.map +1 -1
  240. package/dist/step/writable-stream.js +71 -7
  241. package/dist/step.d.ts.map +1 -1
  242. package/dist/step.js +225 -29
  243. package/dist/symbols.d.ts +54 -0
  244. package/dist/symbols.d.ts.map +1 -1
  245. package/dist/symbols.js +55 -1
  246. package/dist/telemetry/semantic-conventions.d.ts +265 -2
  247. package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
  248. package/dist/telemetry/semantic-conventions.js +190 -1
  249. package/dist/telemetry.d.ts +73 -0
  250. package/dist/telemetry.d.ts.map +1 -1
  251. package/dist/telemetry.js +153 -16
  252. package/dist/types.d.ts +6 -0
  253. package/dist/types.d.ts.map +1 -1
  254. package/dist/types.js +23 -1
  255. package/dist/util.d.ts +16 -6
  256. package/dist/util.d.ts.map +1 -1
  257. package/dist/util.js +25 -16
  258. package/dist/version.d.ts +1 -1
  259. package/dist/version.d.ts.map +1 -1
  260. package/dist/version.js +2 -2
  261. package/dist/vm/index.d.ts.map +1 -1
  262. package/dist/vm/index.js +85 -14
  263. package/dist/vm/script-cache.d.ts +28 -0
  264. package/dist/vm/script-cache.d.ts.map +1 -0
  265. package/dist/vm/script-cache.js +140 -0
  266. package/dist/workflow/abort-controller.d.ts +65 -0
  267. package/dist/workflow/abort-controller.d.ts.map +1 -0
  268. package/dist/workflow/abort-controller.js +312 -0
  269. package/dist/workflow/attribute-dispatcher.d.ts +6 -0
  270. package/dist/workflow/attribute-dispatcher.d.ts.map +1 -0
  271. package/dist/workflow/attribute-dispatcher.js +48 -0
  272. package/dist/workflow/create-hook.d.ts.map +1 -1
  273. package/dist/workflow/create-hook.js +25 -3
  274. package/dist/workflow/define-hook.d.ts +1 -1
  275. package/dist/workflow/define-hook.d.ts.map +1 -1
  276. package/dist/workflow/define-hook.js +8 -4
  277. package/dist/workflow/get-workflow-metadata.d.ts.map +1 -1
  278. package/dist/workflow/get-workflow-metadata.js +14 -3
  279. package/dist/workflow/hook.d.ts.map +1 -1
  280. package/dist/workflow/hook.js +302 -36
  281. package/dist/workflow/index.d.ts +1 -0
  282. package/dist/workflow/index.d.ts.map +1 -1
  283. package/dist/workflow/index.js +5 -3
  284. package/dist/workflow/set-attributes.d.ts +68 -0
  285. package/dist/workflow/set-attributes.d.ts.map +1 -0
  286. package/dist/workflow/set-attributes.js +60 -0
  287. package/dist/workflow/sleep.d.ts.map +1 -1
  288. package/dist/workflow/sleep.js +57 -8
  289. package/dist/workflow/world-init-stub.d.ts +15 -0
  290. package/dist/workflow/world-init-stub.d.ts.map +1 -0
  291. package/dist/workflow/world-init-stub.js +15 -0
  292. package/dist/workflow.d.ts +79 -3
  293. package/dist/workflow.d.ts.map +1 -1
  294. package/dist/workflow.js +831 -553
  295. package/docs/api-reference/create-hook.mdx +79 -0
  296. package/docs/api-reference/create-webhook.mdx +1 -0
  297. package/docs/api-reference/define-hook.mdx +26 -24
  298. package/docs/api-reference/fatal-error.mdx +29 -7
  299. package/docs/api-reference/fetch.mdx +8 -4
  300. package/docs/api-reference/index.mdx +3 -0
  301. package/docs/api-reference/set-attributes.mdx +61 -0
  302. package/docs/api-reference/sleep.mdx +1 -1
  303. package/docs/foundations/cancellation.mdx +459 -0
  304. package/docs/foundations/errors-and-retries.mdx +7 -3
  305. package/docs/foundations/hooks.mdx +29 -0
  306. package/docs/foundations/idempotency.mdx +243 -11
  307. package/docs/foundations/index.mdx +1 -23
  308. package/docs/foundations/meta.json +3 -1
  309. package/docs/foundations/serialization.mdx +77 -41
  310. package/docs/foundations/starting-workflows.mdx +79 -2
  311. package/docs/foundations/streaming.mdx +14 -23
  312. package/docs/foundations/versioning.mdx +263 -0
  313. package/docs/how-it-works/cancellation.mdx +287 -0
  314. package/docs/how-it-works/code-transform.mdx +21 -17
  315. package/docs/how-it-works/encryption.mdx +5 -5
  316. package/docs/how-it-works/event-sourcing.mdx +17 -9
  317. package/docs/how-it-works/framework-integrations.mdx +96 -337
  318. package/docs/how-it-works/meta.json +2 -1
  319. package/package.json +31 -13
  320. package/dist/runtime/step-handler.d.ts +0 -2
  321. package/dist/runtime/step-handler.d.ts.map +0 -1
  322. package/dist/runtime/step-handler.js +0 -678
@@ -0,0 +1,228 @@
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 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 type { Event, RunInput, WorkflowRun, WorldCapabilities } from '@workflow/world';
32
+ import { type Snapshot } from 'quickjs-wasi';
33
+ import type { DecryptionKey } from '../serialization/encryption.js';
34
+ export interface PendingStep {
35
+ type: 'step';
36
+ correlationId: string;
37
+ stepId: string;
38
+ /** Format-prefixed devalue-serialized step input (args + closureVars) */
39
+ input: Uint8Array;
40
+ /** Whether a step_created event already exists for this step */
41
+ hasCreatedEvent: boolean;
42
+ }
43
+ export interface PendingWait {
44
+ type: 'wait';
45
+ correlationId: string;
46
+ /** ISO string of when to resume */
47
+ resumeAt: string;
48
+ /** Whether a wait_created event already exists for this wait */
49
+ hasCreatedEvent: boolean;
50
+ }
51
+ export interface PendingHook {
52
+ type: 'hook';
53
+ correlationId: string;
54
+ token: string;
55
+ /** Earliest token reuse time, as milliseconds since the Unix epoch. */
56
+ tokenRetentionUntil?: number;
57
+ isWebhook: boolean;
58
+ metadata?: unknown;
59
+ hasCreatedEvent: boolean;
60
+ /**
61
+ * True for internal system hooks (e.g. AbortController's hook), which
62
+ * are exempt from user-hook token namespace conflict checks.
63
+ */
64
+ isSystem?: boolean;
65
+ /**
66
+ * Set when the workflow called AbortController.abort() during this
67
+ * invocation. The host must record the abort: create a hook_received
68
+ * event carrying `abortPayload` and write/close the abort stream.
69
+ */
70
+ abortRequested?: boolean;
71
+ /** VM-serialized `{ aborted: true, reason }` payload for the abort. */
72
+ abortPayload?: Uint8Array;
73
+ /** Set by the completion drain when a system hook is implicitly disposed. */
74
+ disposed?: boolean;
75
+ /**
76
+ * True when the workflow is awaiting hook.getConflict() for this hook.
77
+ * The entrypoint re-invokes the workflow right after writing
78
+ * hook_created so replay can confirm creation and resolve the awaiter.
79
+ */
80
+ hasGetConflictAwaiter?: boolean;
81
+ }
82
+ export interface PendingAttribute {
83
+ type: 'attribute';
84
+ correlationId: string;
85
+ /** Normalized attribute changes (plain JSON-able objects) */
86
+ changes: unknown[];
87
+ allowReservedAttributes?: boolean;
88
+ /** Whether an attr_set event already exists for this write */
89
+ hasCreatedEvent: boolean;
90
+ }
91
+ export interface PendingHookDispose {
92
+ type: 'hook_dispose';
93
+ correlationId: string;
94
+ /**
95
+ * Token of the hook being disposed. Used by the entrypoint to order
96
+ * same-token hook operations sequentially in code order.
97
+ */
98
+ token?: string;
99
+ hasCreatedEvent: boolean;
100
+ }
101
+ export type PendingOperation = PendingStep | PendingWait | PendingHook | PendingAttribute | PendingHookDispose;
102
+ export interface QuickJSRuntimeResult {
103
+ /** The workflow completed — result is format-prefixed devalue bytes */
104
+ completed?: {
105
+ result: Uint8Array;
106
+ /**
107
+ * Leftover pending operations that still need durable side effects at
108
+ * completion: abort recordings, system-hook disposals, fire-and-forget
109
+ * attribute/hook/step events. Mirrors the node:vm engine's
110
+ * drainPendingQueueItems. The entrypoint dispatches these WITHOUT
111
+ * queueing steps or requeuing the run.
112
+ */
113
+ drainOperations?: PendingOperation[];
114
+ };
115
+ /** The workflow suspended with pending operations */
116
+ suspended?: {
117
+ pendingOperations: PendingOperation[];
118
+ };
119
+ /** The workflow failed */
120
+ failed?: {
121
+ message: string;
122
+ stack?: string;
123
+ name?: string;
124
+ /** See completed.drainOperations — same semantics on failure. */
125
+ drainOperations?: PendingOperation[];
126
+ /**
127
+ * Format-prefixed devalue bytes of the original thrown value
128
+ * (Error subclass with cause chain, plain object, primitive, etc.).
129
+ * Set when the VM-side rejection handler successfully serializes
130
+ * the thrown value. The host uses these bytes to reconstruct the
131
+ * original value through the standard error hydration pipeline,
132
+ * preserving type identity (TypeError, FatalError) and non-Error
133
+ * throws verbatim. Falls back to the message/stack/name fields
134
+ * when this is undefined (e.g. extractError pseudo-failures).
135
+ */
136
+ valueBytes?: Uint8Array;
137
+ };
138
+ }
139
+ export interface QuickJSRuntimeOptions {
140
+ /** The compiled workflow bundle code (workflow mode output from SWC) */
141
+ workflowCode: string;
142
+ /** The workflow ID (e.g. "workflow//./workflows/1_simple//simple") */
143
+ workflowId: string;
144
+ /** The workflow run entity */
145
+ workflowRun: WorkflowRun;
146
+ /** Features supported by the World executing this workflow. */
147
+ worldCapabilities?: WorldCapabilities;
148
+ /**
149
+ * The full event log for the run. Every invocation replays the complete
150
+ * log from the start (same replay semantics as the `node:vm` engine).
151
+ */
152
+ events: Event[];
153
+ /** Encryption key for decrypting event payloads (undefined if unencrypted) */
154
+ encryptionKey?: DecryptionKey;
155
+ /**
156
+ * The local port the workflow server is listening on, used to populate
157
+ * `workflowMetadata.url`. Resolved at call time on the host side so the
158
+ * VM doesn't have to probe the filesystem. Ignored on Vercel — VERCEL_URL
159
+ * takes precedence there.
160
+ */
161
+ port?: number;
162
+ /**
163
+ * Fallback workflow input from the queue message's resilient-start
164
+ * payload. Used when the fetched event log lacks a `run_created` event
165
+ * (eventually-consistent read after the parent's start() wrote it).
166
+ */
167
+ runInput?: RunInput;
168
+ }
169
+ /**
170
+ * Eval filename used when hydrating the baseline VM. The baseline is
171
+ * shared by EVERY workflow in the bundle, so the filename baked into
172
+ * its compiled code (and therefore into snapshot-path stack frames)
173
+ * must be workflow-independent — hydrating under the first caller's
174
+ * workflowId would break `remapErrorStack`'s filename matching for
175
+ * every other workflow in the bundle. Remap call sites match this
176
+ * constant IN ADDITION to the run's module specifier (which covers
177
+ * fresh-path frames).
178
+ */
179
+ export declare const BASELINE_BUNDLE_FILENAME = "workflow-bundle.js";
180
+ type BaselineEntry = {
181
+ state: 'ready';
182
+ snapshot: Snapshot;
183
+ /**
184
+ * Raw box pointer of the serde capture root created BEFORE the
185
+ * bundle evaluated (see captureSerdeRoot). The box lives in the
186
+ * snapshot's memory image at this offset; every restored VM
187
+ * re-adopts it so serde initialization executes no guest code
188
+ * after user code has run — capture-before-user-code semantics,
189
+ * identical to the fresh path.
190
+ */
191
+ serdeRootPtr: number;
192
+ } | {
193
+ state: 'ineligible';
194
+ reason: string;
195
+ };
196
+ /** Test-only: reset the baseline cache between test cases. */
197
+ export declare function __clearBaselineSnapshotCacheForTests(): void;
198
+ /** Test-only: observe how a bundle was classified. */
199
+ export declare function __peekBaselineEntryForTests(workflowCode: string): Promise<BaselineEntry | undefined>;
200
+ /**
201
+ * A live QuickJS workflow invocation. When the initial `result` is
202
+ * `suspended`, the VM is kept alive so the caller can feed newly recorded
203
+ * events (e.g. terminal events of inline-executed steps) into the SAME VM
204
+ * via `continueWithEvents` — resuming execution exactly where it left off
205
+ * without a fresh-VM re-replay. Terminal results dispose the VM
206
+ * automatically; `dispose()` must be called when abandoning a suspended
207
+ * session (idempotent).
208
+ */
209
+ export interface QuickJSWorkflowSession {
210
+ result: QuickJSRuntimeResult;
211
+ /**
212
+ * Process newly recorded events in the live VM and re-evaluate the
213
+ * workflow state. Only valid while the last result was `suspended`.
214
+ * Resets the VM's interrupt budget for the new execution burst.
215
+ */
216
+ continueWithEvents(newEvents: Event[]): Promise<QuickJSRuntimeResult>;
217
+ /** Dispose the VM if it is still alive. Safe to call multiple times. */
218
+ dispose(): void;
219
+ }
220
+ /**
221
+ * Run a workflow invocation to its first settled state and dispose the
222
+ * VM. Convenience wrapper over {@link startQuickJSWorkflow} for callers
223
+ * (and tests) that don't use live-VM continuation.
224
+ */
225
+ export declare function runQuickJSWorkflow(options: QuickJSRuntimeOptions): Promise<QuickJSRuntimeResult>;
226
+ export declare function startQuickJSWorkflow(options: QuickJSRuntimeOptions): Promise<QuickJSWorkflowSession>;
227
+ export {};
228
+ //# 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,KAAK,EACV,KAAK,EACL,QAAQ,EACR,WAAW,EACX,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAIL,KAAK,QAAQ,EAEd,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAuCpE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;I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