@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,124 @@
1
+ /**
2
+ * QuickJS VM integration with the Workflow DevKit.
3
+ *
4
+ * This module provides the entry point for running workflows in the
5
+ * QuickJS WASM VM engine instead of the `node:vm` engine. Both engines
6
+ * implement the same event-replay execution model — every invocation:
7
+ *
8
+ * 1. Loads the full event log for the run
9
+ * 2. Runs the workflow function from the top in a fresh QuickJS VM,
10
+ * replaying the event log to resolve awaited primitives
11
+ * 3. On suspension: creates events + queues steps for new pending ops
12
+ * 4. On completion: creates run_completed
13
+ * 5. On failure: creates run_failed
14
+ */
15
+ import type { Span } from '@opentelemetry/api';
16
+ import { type Event, type RunInput, type WorkflowRun } from '@workflow/world';
17
+ /**
18
+ * Returns true when the supplied preloaded events indicate this is the
19
+ * first workflow handler invocation for the run — i.e. the log contains
20
+ * nothing beyond `run_created` / `run_started`. In that case the
21
+ * preloaded events ARE the complete event log and the `events.list`
22
+ * round-trips can be skipped entirely.
23
+ *
24
+ * Crucially, if the world backfilled a missing `run_created` via the
25
+ * resilient start path, `preloadedEvents` contains it even when a fresh
26
+ * `events.list` might not (eventual consistency), so preferring the
27
+ * preloaded events on first invocation is also the more correct choice.
28
+ *
29
+ * Returns false when `preloadedEvents` is missing/empty so the caller
30
+ * falls back to the normal fetch path.
31
+ *
32
+ * Exported for unit testing.
33
+ */
34
+ export declare function isFirstInvocation(preloadedEvents: readonly Event[] | undefined): boolean;
35
+ /**
36
+ * Run a workflow using the QuickJS WASM VM engine.
37
+ *
38
+ * This replaces the `node:vm` replay path (runWorkflow + EventsConsumer)
39
+ * with a QuickJS VM invocation that performs the same full event replay.
40
+ *
41
+ * KNOWN GAP — precondition guard: unlike the node:vm path, no event write
42
+ * in this file participates in the optimistic-concurrency precondition
43
+ * guard (`withPreconditionRetry` + `stateUpdatedAtForCreate`), which
44
+ * protects a writer holding a stale event-log snapshot from clobbering a
45
+ * concurrent one. The engine currently relies on per-(runId,
46
+ * correlationId) event uniqueness (EntityConflictError dedup) alone. This
47
+ * is a deliberate simplification while the engine is experimental — wiring
48
+ * the guard is tracked follow-up work; anyone adding new write paths here
49
+ * should not assume parity with the node engine on this axis.
50
+ */
51
+ export declare function runWorkflowWithQuickJS(params: {
52
+ workflowCode: string;
53
+ workflowName: string;
54
+ workflowRun: WorkflowRun;
55
+ /**
56
+ * Events returned inline by `events.create('run_started', ...)` or by
57
+ * the lazy hook fast path's `hook_received` preload. When they indicate
58
+ * a first invocation — or when `preloadedEventsComplete` attests they
59
+ * are the complete log — they are used as the event log instead of
60
+ * fetching via `events.list`, matching the node:vm engine's fast path.
61
+ */
62
+ preloadedEvents?: Event[];
63
+ /**
64
+ * True when the caller has validated that `preloadedEvents` is the run's
65
+ * COMPLETE event log (e.g. the lazy hook fast path's hasMore-false
66
+ * replay preload). The first-invocation heuristic below only recognizes
67
+ * run_created/run_started-only preloads, so without this attestation a
68
+ * hook-resume preload would be discarded and refetched.
69
+ */
70
+ preloadedEventsComplete?: boolean;
71
+ /**
72
+ * Run input carried through the queue message on first delivery. Used
73
+ * as a last-resort fallback for `run_created.eventData.input` when
74
+ * the event log is incomplete.
75
+ */
76
+ runInput?: RunInput;
77
+ /**
78
+ * The parent OTel span (the outer `WORKFLOW {workflowName}` span from
79
+ * `runtime.ts`). When supplied, VM lifecycle attributes are attached
80
+ * to it for end-to-end visibility.
81
+ */
82
+ parentSpan?: Span;
83
+ /**
84
+ * Server-supplied per-run event ceiling from the run_started response
85
+ * (undefined ⇒ no enforcement). Mirrors the node:vm engine's guard:
86
+ * a runaway run is failed once its log reaches the ceiling. The throw
87
+ * propagates to the replay loop's catch in runtime.ts (the QuickJS
88
+ * dispatch runs inside that loop's try), which classifies it and
89
+ * records run_failed with MAX_EVENTS_EXCEEDED.
90
+ */
91
+ maxEventsLimit?: number;
92
+ /**
93
+ * Queue delivery attempt of the message driving this invocation (from
94
+ * the queue handler's metadata; 1 = first delivery). Surfaced in
95
+ * diagnostics; crash recovery itself is driven by the ownership-lease
96
+ * decision table in the loop, not by the attempt count.
97
+ */
98
+ deliveryAttempt?: number;
99
+ /**
100
+ * Queue message ID of the delivery driving this invocation, stamped as
101
+ * `ownerMessageId` on inline lazy step claims so wake replays defer to
102
+ * the in-flight body instead of requeueing the step.
103
+ */
104
+ ownerMessageId?: string;
105
+ /**
106
+ * Queue namespace resolved at route registration (runtime.ts). Must be
107
+ * threaded into every message publish: the builders bake the namespace
108
+ * into generated routes, so consumers listen on `__<ns>_wkf_workflow_*`
109
+ * — a publish without it lands on `__wkf_workflow_*` and is never
110
+ * picked up.
111
+ */
112
+ namespace?: string;
113
+ /**
114
+ * Run-origin trace carrier accessor from runtime.ts
115
+ * (getNextTraceCarrier). In the default `linked` trace mode every
116
+ * invocation must link back to the run's origin (workflow.start) in a
117
+ * star; capturing the current invocation context instead would chain
118
+ * invocations to each other and fragment the run view on async queues.
119
+ */
120
+ nextTraceCarrier?: () => Promise<Record<string, string>>;
121
+ }): Promise<{
122
+ timeoutSeconds?: number;
123
+ } | void>;
124
+ //# sourceMappingURL=quickjs-entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickjs-entrypoint.d.ts","sourceRoot":"","sources":["../../src/runtime/quickjs-entrypoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAS/C,OAAO,EACL,KAAK,KAAK,EAEV,KAAK,QAAQ,EAEb,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AA0CzB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,GAC5C,OAAO,CAOT;AAsaD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,sBAAsB,CAAC,MAAM,EAAE;IACnD,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;IACzB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,KAAK,EAAE,CAAC;IAC1B;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC1D,GAAG,OAAO,CAAC;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAopC9C"}