@workflow/core 5.0.0-beta.5 → 5.0.0-beta.50

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