@workflow/core 5.0.0-beta.4 → 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 (325) 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/correlation-id.d.ts +109 -0
  23. package/dist/correlation-id.d.ts.map +1 -0
  24. package/dist/correlation-id.js +139 -0
  25. package/dist/create-hook.d.ts +62 -4
  26. package/dist/create-hook.d.ts.map +1 -1
  27. package/dist/create-hook.js +4 -3
  28. package/dist/define-hook.d.ts.map +1 -1
  29. package/dist/define-hook.js +20 -5
  30. package/dist/describe-error.d.ts +70 -0
  31. package/dist/describe-error.d.ts.map +1 -0
  32. package/dist/describe-error.js +189 -0
  33. package/dist/encryption.d.ts +37 -3
  34. package/dist/encryption.d.ts.map +1 -1
  35. package/dist/encryption.js +97 -31
  36. package/dist/events-consumer.d.ts +26 -1
  37. package/dist/events-consumer.d.ts.map +1 -1
  38. package/dist/events-consumer.js +105 -18
  39. package/dist/flushable-stream.d.ts +65 -10
  40. package/dist/flushable-stream.d.ts.map +1 -1
  41. package/dist/flushable-stream.js +131 -18
  42. package/dist/global.d.ts +37 -1
  43. package/dist/global.d.ts.map +1 -1
  44. package/dist/global.js +21 -3
  45. package/dist/index.d.ts +1 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +2 -1
  48. package/dist/log-format.d.ts +25 -0
  49. package/dist/log-format.d.ts.map +1 -0
  50. package/dist/log-format.js +250 -0
  51. package/dist/logger.d.ts +29 -30
  52. package/dist/logger.d.ts.map +1 -1
  53. package/dist/logger.js +82 -32
  54. package/dist/private.d.ts +178 -9
  55. package/dist/private.d.ts.map +1 -1
  56. package/dist/private.js +273 -9
  57. package/dist/replay-payload-cache.d.ts +68 -0
  58. package/dist/replay-payload-cache.d.ts.map +1 -0
  59. package/dist/replay-payload-cache.js +160 -0
  60. package/dist/runtime/compute-instance.d.ts +12 -0
  61. package/dist/runtime/compute-instance.d.ts.map +1 -0
  62. package/dist/runtime/compute-instance.js +13 -0
  63. package/dist/runtime/constants.d.ts +237 -0
  64. package/dist/runtime/constants.d.ts.map +1 -1
  65. package/dist/runtime/constants.js +405 -15
  66. package/dist/runtime/count-step-started-events.d.ts +52 -0
  67. package/dist/runtime/count-step-started-events.d.ts.map +1 -0
  68. package/dist/runtime/count-step-started-events.js +72 -0
  69. package/dist/runtime/deployment-guard.d.ts +99 -0
  70. package/dist/runtime/deployment-guard.d.ts.map +1 -0
  71. package/dist/runtime/deployment-guard.js +154 -0
  72. package/dist/runtime/get-port-lazy.d.ts +25 -0
  73. package/dist/runtime/get-port-lazy.d.ts.map +1 -0
  74. package/dist/runtime/get-port-lazy.js +92 -0
  75. package/dist/runtime/get-world-lazy.d.ts +23 -0
  76. package/dist/runtime/get-world-lazy.d.ts.map +1 -0
  77. package/dist/runtime/get-world-lazy.js +46 -0
  78. package/dist/runtime/helpers.d.ts +219 -10
  79. package/dist/runtime/helpers.d.ts.map +1 -1
  80. package/dist/runtime/helpers.js +414 -40
  81. package/dist/runtime/quickjs-assets.generated.d.ts +14 -0
  82. package/dist/runtime/quickjs-assets.generated.d.ts.map +1 -0
  83. package/dist/runtime/quickjs-assets.generated.js +30 -0
  84. package/dist/runtime/quickjs-entrypoint.d.ts +124 -0
  85. package/dist/runtime/quickjs-entrypoint.d.ts.map +1 -0
  86. package/dist/runtime/quickjs-entrypoint.js +1429 -0
  87. package/dist/runtime/quickjs-runtime.d.ts +193 -0
  88. package/dist/runtime/quickjs-runtime.d.ts.map +1 -0
  89. package/dist/runtime/quickjs-runtime.js +1944 -0
  90. package/dist/runtime/replay-budget.d.ts +98 -0
  91. package/dist/runtime/replay-budget.d.ts.map +1 -0
  92. package/dist/runtime/replay-budget.js +192 -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 +448 -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 +117 -10
  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 +312 -54
  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 +949 -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 +102 -7
  124. package/dist/runtime/suspension-handler.d.ts.map +1 -1
  125. package/dist/runtime/suspension-handler.js +439 -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 +5 -0
  139. package/dist/runtime/world-compatibility.d.ts.map +1 -0
  140. package/dist/runtime/world-compatibility.js +12 -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 +3078 -327
  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 +9 -0
  160. package/dist/serialization/codec-devalue-vm.d.ts.map +1 -0
  161. package/dist/serialization/codec-devalue-vm.js +137 -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/vm-bundle-entry.d.ts +12 -0
  211. package/dist/serialization/vm-bundle-entry.d.ts.map +1 -0
  212. package/dist/serialization/vm-bundle-entry.js +58 -0
  213. package/dist/serialization/workflow-vm.d.ts +24 -0
  214. package/dist/serialization/workflow-vm.d.ts.map +1 -0
  215. package/dist/serialization/workflow-vm.js +66 -0
  216. package/dist/serialization/workflow.d.ts +29 -0
  217. package/dist/serialization/workflow.d.ts.map +1 -0
  218. package/dist/serialization/workflow.js +54 -0
  219. package/dist/serialization-format.d.ts +60 -4
  220. package/dist/serialization-format.d.ts.map +1 -1
  221. package/dist/serialization-format.js +276 -56
  222. package/dist/serialization.d.ts +374 -221
  223. package/dist/serialization.d.ts.map +1 -1
  224. package/dist/serialization.js +2300 -783
  225. package/dist/set-attributes.d.ts +13 -0
  226. package/dist/set-attributes.d.ts.map +1 -0
  227. package/dist/set-attributes.js +60 -0
  228. package/dist/sleep.d.ts.map +1 -1
  229. package/dist/sleep.js +3 -2
  230. package/dist/source-map.d.ts +25 -0
  231. package/dist/source-map.d.ts.map +1 -1
  232. package/dist/source-map.js +148 -10
  233. package/dist/step/context-storage.d.ts +61 -2
  234. package/dist/step/context-storage.d.ts.map +1 -1
  235. package/dist/step/context-storage.js +7 -5
  236. package/dist/step/get-closure-vars.d.ts.map +1 -1
  237. package/dist/step/get-closure-vars.js +3 -2
  238. package/dist/step/get-step-metadata.d.ts.map +1 -1
  239. package/dist/step/get-step-metadata.js +3 -2
  240. package/dist/step/get-workflow-metadata.d.ts.map +1 -1
  241. package/dist/step/get-workflow-metadata.js +3 -2
  242. package/dist/step/writable-stream.d.ts.map +1 -1
  243. package/dist/step/writable-stream.js +71 -7
  244. package/dist/step.d.ts.map +1 -1
  245. package/dist/step.js +226 -30
  246. package/dist/symbols.d.ts +54 -0
  247. package/dist/symbols.d.ts.map +1 -1
  248. package/dist/symbols.js +55 -1
  249. package/dist/telemetry/semantic-conventions.d.ts +242 -2
  250. package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
  251. package/dist/telemetry/semantic-conventions.js +173 -1
  252. package/dist/telemetry.d.ts +73 -0
  253. package/dist/telemetry.d.ts.map +1 -1
  254. package/dist/telemetry.js +153 -16
  255. package/dist/types.d.ts +6 -0
  256. package/dist/types.d.ts.map +1 -1
  257. package/dist/types.js +23 -1
  258. package/dist/util.d.ts +16 -6
  259. package/dist/util.d.ts.map +1 -1
  260. package/dist/util.js +25 -16
  261. package/dist/version.d.ts +1 -1
  262. package/dist/version.d.ts.map +1 -1
  263. package/dist/version.js +2 -2
  264. package/dist/vm/index.d.ts.map +1 -1
  265. package/dist/vm/index.js +77 -9
  266. package/dist/vm/script-cache.d.ts +28 -0
  267. package/dist/vm/script-cache.d.ts.map +1 -0
  268. package/dist/vm/script-cache.js +140 -0
  269. package/dist/workflow/abort-controller.d.ts +65 -0
  270. package/dist/workflow/abort-controller.d.ts.map +1 -0
  271. package/dist/workflow/abort-controller.js +314 -0
  272. package/dist/workflow/attribute-dispatcher.d.ts +6 -0
  273. package/dist/workflow/attribute-dispatcher.d.ts.map +1 -0
  274. package/dist/workflow/attribute-dispatcher.js +48 -0
  275. package/dist/workflow/create-hook.d.ts.map +1 -1
  276. package/dist/workflow/create-hook.js +25 -3
  277. package/dist/workflow/define-hook.d.ts +1 -1
  278. package/dist/workflow/define-hook.d.ts.map +1 -1
  279. package/dist/workflow/define-hook.js +8 -4
  280. package/dist/workflow/get-workflow-metadata.d.ts.map +1 -1
  281. package/dist/workflow/get-workflow-metadata.js +14 -3
  282. package/dist/workflow/hook.d.ts.map +1 -1
  283. package/dist/workflow/hook.js +303 -37
  284. package/dist/workflow/index.d.ts +1 -0
  285. package/dist/workflow/index.d.ts.map +1 -1
  286. package/dist/workflow/index.js +5 -3
  287. package/dist/workflow/set-attributes.d.ts +68 -0
  288. package/dist/workflow/set-attributes.d.ts.map +1 -0
  289. package/dist/workflow/set-attributes.js +60 -0
  290. package/dist/workflow/sleep.d.ts.map +1 -1
  291. package/dist/workflow/sleep.js +58 -9
  292. package/dist/workflow/world-init-stub.d.ts +15 -0
  293. package/dist/workflow/world-init-stub.d.ts.map +1 -0
  294. package/dist/workflow/world-init-stub.js +15 -0
  295. package/dist/workflow.d.ts +69 -3
  296. package/dist/workflow.d.ts.map +1 -1
  297. package/dist/workflow.js +791 -554
  298. package/docs/api-reference/create-hook.mdx +79 -0
  299. package/docs/api-reference/create-webhook.mdx +1 -0
  300. package/docs/api-reference/define-hook.mdx +26 -24
  301. package/docs/api-reference/fatal-error.mdx +29 -7
  302. package/docs/api-reference/fetch.mdx +8 -4
  303. package/docs/api-reference/index.mdx +3 -0
  304. package/docs/api-reference/set-attributes.mdx +61 -0
  305. package/docs/api-reference/sleep.mdx +1 -1
  306. package/docs/foundations/cancellation.mdx +459 -0
  307. package/docs/foundations/errors-and-retries.mdx +7 -3
  308. package/docs/foundations/hooks.mdx +29 -0
  309. package/docs/foundations/idempotency.mdx +243 -11
  310. package/docs/foundations/index.mdx +1 -23
  311. package/docs/foundations/meta.json +3 -1
  312. package/docs/foundations/serialization.mdx +77 -41
  313. package/docs/foundations/starting-workflows.mdx +79 -2
  314. package/docs/foundations/streaming.mdx +14 -23
  315. package/docs/foundations/versioning.mdx +263 -0
  316. package/docs/how-it-works/cancellation.mdx +287 -0
  317. package/docs/how-it-works/code-transform.mdx +21 -17
  318. package/docs/how-it-works/encryption.mdx +5 -5
  319. package/docs/how-it-works/event-sourcing.mdx +6 -6
  320. package/docs/how-it-works/framework-integrations.mdx +96 -337
  321. package/docs/how-it-works/meta.json +2 -1
  322. package/package.json +31 -13
  323. package/dist/runtime/step-handler.d.ts +0 -2
  324. package/dist/runtime/step-handler.d.ts.map +0 -1
  325. package/dist/runtime/step-handler.js +0 -678
@@ -1,10 +1,11 @@
1
- import type { Event, HealthCheckPayload, ValidQueueName, World } from '@workflow/world';
1
+ import type { CreateEventParams, CreateEventRequest, Event, EventResult, HealthCheckPayload, ValidQueueName, WorkflowRun, World } from '@workflow/world';
2
+ import { type PayloadKey } from '../serialization/encryption.js';
2
3
  /**
3
4
  * Validates a workflow name and returns the corresponding queue name.
4
5
  * Ensures the workflow name only contains safe characters before
5
6
  * interpolating it into the queue name string.
6
7
  */
7
- export declare function getWorkflowQueueName(workflowName: string): ValidQueueName;
8
+ export declare function getWorkflowQueueName(workflowName: string, namespace?: string): ValidQueueName;
8
9
  /**
9
10
  * Result of a health check operation.
10
11
  */
@@ -16,6 +17,35 @@ export interface HealthCheckResult {
16
17
  latencyMs?: number;
17
18
  /** Spec version of the responding deployment */
18
19
  specVersion?: number;
20
+ /**
21
+ * `@workflow/core` version of the responding deployment, used for
22
+ * capability detection (see `getRunCapabilities`). Omitted when the
23
+ * responding deployment did not provide the field as a string —
24
+ * for example, an older `@workflow/core` that predates this field,
25
+ * or a non-JSON plain-text health response.
26
+ */
27
+ workflowCoreVersion?: string;
28
+ /**
29
+ * The target run's X25519 public key (base64), returned only when the probe
30
+ * carried a `runId` and the responding deployment has encryption enabled.
31
+ *
32
+ * Lets a cross-deployment `start()` seal the workflow arguments using a
33
+ * response it was already waiting on, instead of making a separate
34
+ * key-lookup request.
35
+ */
36
+ encryptionPublicKey?: string;
37
+ /**
38
+ * The responding deployment's `HOOK_RESUME_INPUT_VERSION` — the protocol
39
+ * version at which the *consumer* (queue-message target) re-ensures the
40
+ * `hook_received` event from `hookInput` on replay. A cross-deployment
41
+ * `start()` stamps the *target's* value (not the caller's) into the new
42
+ * run's `executionContext.hookResumeInputVersion` so that `resumeHook()`
43
+ * only takes the parallel path when the deployment that will actually
44
+ * consume the queue message is known to honor `hookInput`. Omitted when the
45
+ * responding deployment predates this field (an older consumer that ignores
46
+ * `hookInput`), which fails the gate closed.
47
+ */
48
+ hookResumeInputVersion?: number;
19
49
  }
20
50
  /**
21
51
  * Checks if the given message is a health check payload.
@@ -27,23 +57,171 @@ export declare function parseHealthCheckPayload(message: unknown): HealthCheckPa
27
57
  * The caller can listen to this stream to get the health check response.
28
58
  *
29
59
  * @param healthCheck - The parsed health check payload
30
- * @param endpoint - Which endpoint is responding ('workflow' or 'step')
31
60
  */
32
- export declare function handleHealthCheckMessage(healthCheck: HealthCheckPayload, endpoint: 'workflow' | 'step', worldSpecVersion?: number): Promise<void>;
33
- export type HealthCheckEndpoint = 'workflow' | 'step';
61
+ export declare function handleHealthCheckMessage(healthCheck: HealthCheckPayload, worldSpecVersion?: number): Promise<void>;
34
62
  export interface HealthCheckOptions {
35
63
  /** Timeout in milliseconds to wait for health check response. Default: 30000 (30s) */
36
64
  timeout?: number;
37
65
  /** Deployment ID to send the health check to. Falls back to process.env.VERCEL_DEPLOYMENT_ID. */
38
66
  deploymentId?: string;
67
+ /**
68
+ * The run id the caller is about to create. When set, the responding
69
+ * deployment derives that run's public key locally and returns it as
70
+ * `encryptionPublicKey`, letting a cross-deployment `start()` seal the
71
+ * workflow arguments without a separate key lookup.
72
+ */
73
+ runId?: string;
74
+ /**
75
+ * Queue namespace of the target deployment (e.g. `'eve'` for topics like
76
+ * `__eve_wkf_workflow_*`). Falls back to `WORKFLOW_QUEUE_NAMESPACE` in the
77
+ * calling process. Cross-context callers (e.g. the observability
78
+ * dashboard) must pass the target deployment's namespace explicitly —
79
+ * the env fallback resolves in the caller's process, and a message
80
+ * published to a mismatched topic has no consumer, so the check would
81
+ * always time out.
82
+ */
83
+ namespace?: string;
39
84
  }
40
- export declare function healthCheck(world: World, endpoint: HealthCheckEndpoint, options?: HealthCheckOptions): Promise<HealthCheckResult>;
85
+ export declare function healthCheck(world: World, options?: HealthCheckOptions): Promise<HealthCheckResult>;
41
86
  /**
42
- * Loads all workflow run events by iterating through all pages of paginated results.
43
- * This ensures that *all* events are loaded into memory before running the workflow.
44
- * Events must be in chronological order (ascending) for proper workflow replay.
87
+ * Appends events whose IDs are not already present in `target`.
88
+ *
89
+ * Pass the IDs currently present in `target` when appending repeatedly to the
90
+ * same array. The set is updated alongside `target`.
91
+ *
92
+ * Events are appended in the order the World returned them, and are not
93
+ * re-sorted: a World's canonical order is its own, and the runtime cannot
94
+ * reproduce it from event ids alone. `world-vercel` orders by event id, while
95
+ * `world-local` orders by `(createdAt, eventId)` and deliberately re-mints keys
96
+ * so that the two diverge. Every append source is already in canonical order
97
+ * relative to the tail (a cursor-delimited page, or a write-response delta), so
98
+ * receipt order is the order to keep. Nothing downstream may assume the tail is
99
+ * the newest event — see {@link latestEventStateUpdatedAt}.
100
+ */
101
+ export declare function appendUniqueEvents(target: Event[], events: readonly Event[], targetIds?: Set<string>): void;
102
+ /**
103
+ * Inserts `event` into `target` at the position that keeps `target` ordered by
104
+ * ascending `eventId`, or no-ops if an event with the same `eventId` is already
105
+ * present (idempotent).
106
+ *
107
+ * `preloadedEvents` is loaded `sortOrder: 'asc'` and is never re-sorted
108
+ * client-side, so a `hook_received` spliced in by the lazy-resume consumer must
109
+ * land in `eventId` order — a plain `push` would place a late-committing
110
+ * earlier event after events that sort before it, corrupting replay. Event IDs
111
+ * are ULIDs, so lexicographic string order matches commit order.
45
112
  */
46
- export declare function getAllWorkflowRunEvents(runId: string): Promise<Event[]>;
113
+ export declare function insertEventByEventId(target: Event[], event: Event): void;
114
+ /**
115
+ * Loads workflow run events by iterating through all pages of paginated
116
+ * results. Events are returned in chronological (ascending) order for
117
+ * deterministic workflow replay.
118
+ *
119
+ * @param runId - The workflow run ID.
120
+ * @param afterCursor - If provided, only events after this cursor are
121
+ * returned (incremental load). If omitted, all events are returned.
122
+ * The returned cursor can be passed back in on a subsequent call for
123
+ * incremental loading.
124
+ */
125
+ export declare function loadWorkflowRunEvents(runId: string, afterCursor?: string): Promise<{
126
+ events: Event[];
127
+ cursor: string | null;
128
+ }>;
129
+ /**
130
+ * The runtime's loaded event-log snapshot: the events replayed so far and the
131
+ * cursor positioned after them. Handed to helpers that derive the precondition
132
+ * snapshot from it; they do not mutate it.
133
+ */
134
+ export interface LoadedEventLog {
135
+ events: Event[];
136
+ cursor: string | null;
137
+ }
138
+ /**
139
+ * Whether the optimistic-concurrency guard for event creation is enabled.
140
+ * **On by default** where the runtime executes: replay-context creates send a
141
+ * `stateUpdatedAt` snapshot (and can be rejected with 412 by a supporting
142
+ * backend) unless `WORKFLOW_PRECONDITION_GUARD` is set to `0`. Backends without
143
+ * guard support ignore the snapshot, so enabling by default is
144
+ * backward-compatible.
145
+ */
146
+ export declare function isPreconditionGuardEnabled(): boolean;
147
+ /**
148
+ * The `stateUpdatedAt` value to send with a replay-context event creation: the
149
+ * *maximum* ULID time (epoch ms) over the events the runtime has loaded. Returns
150
+ * `undefined` when there are no events or that id is not a decodable ULID.
151
+ *
152
+ * It is the maximum rather than the tail's because the loaded log is in the
153
+ * World's canonical order, which is not necessarily event-id order (see
154
+ * {@link appendUniqueEvents}). The maximum is what lets the count sent alongside
155
+ * it be read as "events at or below this watermark": every loaded event is at or
156
+ * below it, so the count is exactly `events.length`. Reading the tail instead
157
+ * would understate the watermark on a World whose order is not id-ordered, which
158
+ * is safe (it can only weaken detection) but needlessly imprecise.
159
+ *
160
+ * The maximum is found by lexicographic id comparison, decoding only once: the
161
+ * 26-character Crockford ULID encodes its timestamp in the leading 10
162
+ * characters, so the greatest id also carries the greatest time.
163
+ *
164
+ * Granularity: snapshots are epoch-milliseconds, and the backend allows an
165
+ * equal-timestamp snapshot (an up-to-date client must not be rejected). Two
166
+ * out-of-band events landing in the same millisecond where only the first was
167
+ * loaded therefore pass this half of the guard undetected — that is exactly
168
+ * the hole `stateEventCount` closes, since the count of events at or below the
169
+ * watermark differs even when the watermarks are equal.
170
+ */
171
+ export declare function latestEventStateUpdatedAt(events: Event[]): number | undefined;
172
+ /**
173
+ * The precondition snapshot a replay-context event creation sends, describing
174
+ * the event log the replay derived the event from.
175
+ *
176
+ * The three fields are one indivisible unit: the backend reads the count only
177
+ * relative to the watermark, and returns its inline delta only relative to the
178
+ * cursor. Passing them as a single object is what keeps them from drifting
179
+ * apart at a call site.
180
+ */
181
+ export interface PreconditionSnapshotParams {
182
+ stateUpdatedAt?: number;
183
+ stateEventCount?: number;
184
+ stateCursor?: string;
185
+ }
186
+ /**
187
+ * Build the precondition snapshot to attach to a replay-context event creation.
188
+ *
189
+ * Returns an empty object — no guard, backend behaves as before — when the
190
+ * guard is disabled or the watermark is not derivable. All three fields fail
191
+ * open together: a count without a watermark is meaningless to the backend, and
192
+ * a cursor without either would invite a delta nobody asked for.
193
+ *
194
+ * `stateEventCount` is `events.length` because the watermark is the log's
195
+ * *maximum* ULID time, so every loaded event is at or below it regardless of the
196
+ * order the World returned them in.
197
+ *
198
+ * Both fields are therefore invariant under permutation of the log: a maximum is
199
+ * order-independent, and the length is set cardinality once `appendUniqueEvents`
200
+ * has deduped by event id. Two replays that consume the same events in different
201
+ * orders send an identical snapshot, so this guard detects that a log is missing
202
+ * an event and can never detect that a replay consumed one in a different order.
203
+ */
204
+ export declare function preconditionSnapshotParams(events: Event[], cursor?: string | null): PreconditionSnapshotParams;
205
+ /**
206
+ * The events a rejecting World attached to a `PreconditionFailedError`, when it
207
+ * returned the ones the client's snapshot was missing inline.
208
+ *
209
+ * Returns `null` for anything else — no details, a World that did not implement
210
+ * this, or a payload that does not narrow cleanly. Callers fall back to
211
+ * reloading the event log, which is always correct; this is untrusted-shaped
212
+ * data on a failure path, so nothing here is repaired.
213
+ *
214
+ * `runId` is the caller's run. Every event must belong to it: the delta is
215
+ * merged straight into the replay's log, and one foreign event there is a
216
+ * corrupt log rather than a corrected one — the replay would consume a
217
+ * correlation id for an event that does not exist on this run.
218
+ */
219
+ export declare function preconditionEventDelta(error: unknown, runId: string): {
220
+ events: Event[];
221
+ cursor: string | null;
222
+ } | null;
223
+ /** Creates one event on a bound run, carrying replay-recovery telemetry. */
224
+ export type EventCreator = (data: CreateEventRequest, params?: CreateEventParams) => Promise<EventResult>;
47
225
  /**
48
226
  * Wraps a request/response handler and adds a health check "mode"
49
227
  * based on the presence of a `__health` query parameter.
@@ -61,4 +239,35 @@ export declare function getQueueOverhead(message: {
61
239
  }): {
62
240
  [k: string]: number;
63
241
  } | undefined;
242
+ /**
243
+ * Returns a memoized accessor for a run's full encryption capability.
244
+ *
245
+ * The first call resolves the run's key material via
246
+ * `world.getEncryptionKeyForRun` (which may do HKDF derivation locally on
247
+ * Vercel, or a network fetch from external contexts) and derives a
248
+ * {@link PayloadKey} from it; subsequent calls await the same cached promise.
249
+ * If the world doesn't support encryption or the run has no key configured,
250
+ * the cached value is `undefined`.
251
+ *
252
+ * The resolved value is deliberately the *full* capability — the symmetric AES
253
+ * key plus the run's X25519 keypair — not just a `CryptoKey`. A run reading
254
+ * its own event log can encounter sealed (`encp`) payloads that another run
255
+ * wrote to it (a cross-deployment hook resumption, say), and opening those
256
+ * needs the keypair. Resolving only the symmetric key would leave those
257
+ * payloads unopenable and wedge the run.
258
+ *
259
+ * Used by step / workflow handlers to defer the (potentially expensive)
260
+ * key fetch until the first code path that actually needs it — typically
261
+ * input hydration on the success path, or error dehydration on a failure
262
+ * path. Both paths can race-call the accessor without triggering duplicate
263
+ * fetches.
264
+ *
265
+ * Errors thrown by `getEncryptionKeyForRun` propagate to every caller
266
+ * (the cached promise rejects). This is intentional: when encryption is
267
+ * configured, we never want to silently fall back to plaintext
268
+ * serialization. A propagated error in an event-emission path leaves the
269
+ * outer try/catch to log and surface the issue; the queue's redelivery
270
+ * semantics will retry the key fetch on the next attempt.
271
+ */
272
+ export declare function memoizeEncryptionKey(world: World, runOrId: WorkflowRun | string): () => Promise<PayloadKey | undefined>;
64
273
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/runtime/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,kBAAkB,EAClB,cAAc,EACd,KAAK,EACN,MAAM,iBAAiB,CAAC;AAwBzB;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,CAOzE;AAWD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,OAAO,GACf,kBAAkB,GAAG,SAAS,CAMhC;AAYD;;;;;;GAMG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,kBAAkB,EAC/B,QAAQ,EAAE,UAAU,GAAG,MAAM,EAC7B,gBAAgB,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,MAAM,CAAC;AAEtD,MAAM,WAAW,kBAAkB;IACjC,sFAAsF;IACtF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iGAAiG;IACjG,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAoGD,wBAAsB,WAAW,CAC/B,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,CAAC,EAAE,kBAAkB,GAC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