@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
@@ -1,211 +1,297 @@
1
- import { type CryptoKey } from './encryption.js';
2
- /**
3
- * Encryption key parameter type. Accepts a resolved key, undefined (no encryption),
4
- * or a promise that resolves to either. This allows synchronous function signatures
5
- * (e.g., getReadable()) to thread the key through without awaiting it — the promise
6
- * is resolved lazily inside the first async transform() call.
7
- */
8
- export type EncryptionKeyParam = CryptoKey | undefined | Promise<CryptoKey | undefined>;
9
- /**
10
- * Known serialization format identifiers.
11
- * Each format ID is exactly 4 ASCII characters, matching the convention
12
- * used for other workflow IDs (wrun, step, wait, etc.)
13
- */
14
- export declare const SerializationFormat: {
15
- /** devalue stringify/parse with TextEncoder/TextDecoder */
16
- readonly DEVALUE_V1: "devl";
17
- /** Encrypted payload (inner payload has its own format prefix) */
18
- readonly ENCRYPTED: "encr";
19
- };
1
+ import { compress, decompress } from './serialization/compression.js';
2
+ import { aesKeyOf, decrypt, deriveRunPayloadKeys, type EncryptionKeyParam, encrypt, isRunPayloadKeys, isSealTarget, type PayloadKey, type RunPayloadKeys, runPayloadKeys, type SealTarget, sealTo } from './serialization/encryption.js';
3
+ import { decodeFormatPrefix, encodeWithFormatPrefix, isEncrypted, peekFormatPrefix } from './serialization/format.js';
4
+ import { type GuestCodeStats } from './serialization/hardened.js';
5
+ import { type FormatPrefix, isFormatPrefix, SerializationFormat } from './serialization/types.js';
6
+ export { SerializationFormat, type FormatPrefix, isFormatPrefix, encodeWithFormatPrefix, decodeFormatPrefix, peekFormatPrefix, isEncrypted, encrypt, decrypt, compress, decompress, type EncryptionKeyParam, type PayloadKey, type RunPayloadKeys, type SealTarget, sealTo, runPayloadKeys, deriveRunPayloadKeys, isSealTarget, isRunPayloadKeys, aesKeyOf, };
20
7
  export type SerializationFormatType = (typeof SerializationFormat)[keyof typeof SerializationFormat];
21
8
  /**
22
- * Encode a payload with a format prefix.
9
+ * Detect if a readable stream is a byte stream.
23
10
  *
24
- * @param format - The format identifier (must be exactly 4 ASCII characters)
25
- * @param payload - The serialized payload bytes
26
- * @returns A new Uint8Array with format prefix prepended
11
+ * @param stream
12
+ * @returns `"bytes"` if the stream is a byte stream, `undefined` otherwise
27
13
  */
28
- export declare function encodeWithFormatPrefix(format: SerializationFormatType, payload: Uint8Array | unknown): Uint8Array | unknown;
14
+ export declare function getStreamType(stream: ReadableStream): 'bytes' | undefined;
15
+ export declare function getSerializeStream(reducers: Partial<Reducers>, cryptoKey: EncryptionKeyParam): TransformStream<any, Uint8Array>;
16
+ export declare function getDeserializeStream(revivers: Partial<Revivers>, cryptoKey: EncryptionKeyParam): TransformStream<Uint8Array, any>;
29
17
  /**
30
- * Peek at the format prefix without consuming it.
31
- * Useful for checking if data is encrypted before deciding how to process it.
18
+ * Wraps each chunk of a byte stream in a 4-byte big-endian length
19
+ * prefix. Used by the producer side of a framed byte-stream pipe.
32
20
  *
33
- * @param data - The format-prefixed data
34
- * @returns The format identifier, or null if data is legacy/non-binary
35
- */
36
- export declare function peekFormatPrefix(data: Uint8Array | unknown): SerializationFormatType | null;
37
- /**
38
- * Check if data is encrypted (has 'encr' format prefix).
21
+ * Empty chunks (length 0) are dropped — the resulting `[0x00 0x00 0x00 0x00]`
22
+ * frame would be ambiguous with the legacy "looks framed" detection in
23
+ * `getDeserializeStream`, and it carries no information.
39
24
  *
40
- * @param data - The format-prefixed data
41
- * @returns true if data has the encrypted format prefix
25
+ * Load-bearing invariant: each user chunk becomes exactly one frame, and
26
+ * each frame is enqueued as exactly one transport chunk (the downstream
27
+ * writable performs one wire write per chunk, preserving boundaries). The
28
+ * server therefore stores one frame per chunk index, which is what allows
29
+ * a future reconnecting reader to resume a framed byte stream at
30
+ * `startIndex + consumedFrames` — the same arithmetic
31
+ * `createReconnectingFramedStream` relies on for object streams. Do not
32
+ * coalesce or split frames here without revisiting that resume logic.
42
33
  */
43
- export declare function isEncrypted(data: Uint8Array | unknown): boolean;
34
+ export declare function getByteFramingStream(): TransformStream<Uint8Array, Uint8Array>;
44
35
  /**
45
- * Decode a format-prefixed payload.
36
+ * Unwraps length-prefixed byte-stream frames back into the original user
37
+ * chunks. Used by the consumer side of a framed byte-stream pipe.
46
38
  *
47
- * @param data - The format-prefixed data
48
- * @returns An object with the format identifier and payload
49
- * @throws Error if the data is too short or has an unknown format
50
- */
51
- export declare function decodeFormatPrefix(data: Uint8Array | unknown): {
52
- format: SerializationFormatType;
53
- payload: Uint8Array;
54
- };
55
- /**
56
- * Detect if a readable stream is a byte stream.
39
+ * Buffers across read boundaries the transport may split a single
40
+ * frame across multiple reads (header in one chunk, payload in another)
41
+ * or coalesce multiple frames into a single read. The transform emits
42
+ * whole user chunks regardless of transport chunking.
57
43
  *
58
- * @param stream
59
- * @returns `"bytes"` if the stream is a byte stream, `undefined` otherwise
44
+ * Errors the stream if the length header advertises a frame larger than
45
+ * `MAX_FRAME_SIZE` bytes, since that almost certainly indicates a
46
+ * misframed wire (e.g. a raw byte stream being fed through this transform
47
+ * by mistake) and we don't want to allocate an enormous buffer.
60
48
  */
61
- export declare function getStreamType(stream: ReadableStream): 'bytes' | undefined;
62
- export declare function getSerializeStream(reducers: Reducers, cryptoKey: EncryptionKeyParam): TransformStream<any, Uint8Array>;
63
- export declare function getDeserializeStream(revivers: Revivers, cryptoKey: EncryptionKeyParam): TransformStream<Uint8Array, any>;
49
+ export declare function getByteUnframingStream(): TransformStream<Uint8Array, Uint8Array>;
64
50
  export declare class WorkflowServerReadableStream extends ReadableStream<Uint8Array> {
65
51
  #private;
66
52
  constructor(runId: string, name: string, startIndex?: number);
67
53
  }
54
+ /**
55
+ * Maximum consecutive reconnect attempts for a single framed stream session.
56
+ * The counter resets to zero whenever a reconnect makes forward progress (a
57
+ * frame is delivered), so this bounds *consecutive* failures, not the lifetime
58
+ * total — a long-lived serverless stream may legitimately reconnect far more
59
+ * than this many times as long as each reconnect keeps delivering data. We only
60
+ * give up after this many reconnects in a row produce nothing.
61
+ */
62
+ export declare const FRAMED_STREAM_MAX_RECONNECTS = 50;
63
+ /**
64
+ * Absolute backstop on total reconnects for a single session, independent of
65
+ * progress. The consecutive cap above resets on forward progress, which is
66
+ * correct for a well-behaved backend that honors `startIndex`. But if a World's
67
+ * `streams.get` ever ignored `startIndex` and re-delivered earlier chunks,
68
+ * "progress" would be reported every reconnect and the consecutive cap would
69
+ * never trip — turning a bounded failure into an unbounded reconnect loop. This
70
+ * hard ceiling guarantees the loop always terminates. It is set high enough
71
+ * (hours of streaming at realistic per-session timeouts) to never interfere
72
+ * with legitimate long-lived streams.
73
+ */
74
+ export declare const FRAMED_STREAM_MAX_TOTAL_RECONNECTS = 1000;
75
+ /**
76
+ * Wraps the length-prefix-framed byte stream from `world.streams.get` with
77
+ * transparent auto-reconnect.
78
+ *
79
+ * Every fully-decoded outer frame corresponds to exactly one server-side
80
+ * chunk (the serialize transform enqueues one frame per workflow write, and
81
+ * the writable buffers one frame per chunk when multi-writing). The wrapper
82
+ * counts completed frames and, on upstream error, reopens the connection
83
+ * with `startIndex = resolvedStartIndex + consumedFrames`. Partial-frame
84
+ * bytes buffered before the cut are discarded — the server will resend the
85
+ * in-flight chunk in full from the new startIndex.
86
+ *
87
+ * A clean upstream close (EOF with no error) signals the stream is truly
88
+ * done; we close the wrapper and do not reconnect.
89
+ *
90
+ * Negative `startIndex` values (last-N semantics) skip the reconnect
91
+ * machinery because we cannot compute an absolute resume position without
92
+ * a tail-index lookup — the returned stream behaves as a single-shot read.
93
+ */
94
+ export declare function createReconnectingFramedStream(runId: string, name: string, startIndex?: number): ReadableStream<Uint8Array>;
68
95
  export declare class WorkflowServerWritableStream extends WritableStream<Uint8Array> {
69
- constructor(runId: string, name: string);
96
+ /**
97
+ * @param runReadyBarrier Turbo mode only: a promise that resolves once the
98
+ * backgrounded `run_started` has landed. When the step body runs
99
+ * optimistically (before `run_started` is durable), the first chunk write to
100
+ * a brand-new stream would otherwise reach the World before the run exists
101
+ * and be rejected as run-not-found. Awaiting this once before the first
102
+ * flush/close orders the write after the run's creation. `undefined` outside
103
+ * turbo and on the await path, where the run was already durable.
104
+ */
105
+ constructor(runId: string, name: string, runReadyBarrier?: Promise<unknown>);
70
106
  }
71
- export interface SerializableSpecial {
72
- ArrayBuffer: string;
73
- BigInt: string;
74
- BigInt64Array: string;
75
- BigUint64Array: string;
76
- Date: string;
77
- DOMException: {
107
+ export type { ByteStreamFraming, Reducers, Revivers, SerializableSpecial, } from './serialization/types.js';
108
+ import type { ByteStreamFraming, Reducers, Revivers } from './serialization/types.js';
109
+ /**
110
+ * Reducers for serialization boundary from the client side, passing arguments
111
+ * to the workflow handler.
112
+ *
113
+ * @param global
114
+ * @param ops
115
+ * @param runId
116
+ * @param cryptoKey
117
+ * @param framedByteStreams - When `true`, byte streams (`type: 'bytes'`)
118
+ * are wrapped in length-prefixed frames on the wire so the consumer
119
+ * can reconnect on transient errors. Should match the target run's
120
+ * capability — see `getRunCapabilities` in `capabilities.ts`. Defaults
121
+ * to `false` for backwards compatibility with older runs.
122
+ * @returns
123
+ */
124
+ export declare function getExternalReducers(global: Record<string, any> | undefined, ops: Promise<void>[], runId: string, cryptoKey: EncryptionKeyParam, framedByteStreams?: boolean, runReadyBarrier?: Promise<unknown>): Partial<Reducers>;
125
+ export declare function getWorkflowReducers(global?: Record<string, any>): Partial<Reducers>;
126
+ /**
127
+ * Cancel dangling abort-stream readers on any AbortController instances found
128
+ * in the hydrated step arguments. Called after the step function returns
129
+ * (success or failure) to prevent reader promises from keeping the serverless
130
+ * function alive indefinitely.
131
+ */
132
+ export declare function cancelAbortReaders(...values: unknown[]): void;
133
+ /**
134
+ * Base revivers shared across all serialization boundaries.
135
+ * Composes: class + common revivers from the modular modules.
136
+ *
137
+ * This is exported because serialization-format.ts and other files reference it.
138
+ */
139
+ export declare function getCommonRevivers(global?: Record<string, any>): {
140
+ ArrayBuffer?: ((value: string) => any) | undefined;
141
+ BigInt?: ((value: string) => any) | undefined;
142
+ BigInt64Array?: ((value: string) => any) | undefined;
143
+ BigUint64Array?: ((value: string) => any) | undefined;
144
+ Date?: ((value: string) => any) | undefined;
145
+ DOMException?: ((value: {
78
146
  message: string;
79
147
  name: string;
80
148
  stack?: string;
81
149
  cause?: unknown;
82
- };
83
- Float32Array: string;
84
- Float64Array: string;
85
- Error: Record<string, any>;
86
- Headers: [string, string][];
87
- Int8Array: string;
88
- Int16Array: string;
89
- Int32Array: string;
90
- Map: [any, any][];
91
- ReadableStream: {
150
+ }) => any) | undefined;
151
+ FatalError?: ((value: {
152
+ message: string;
153
+ stack?: string;
154
+ cause?: unknown;
155
+ }) => any) | undefined;
156
+ Float32Array?: ((value: string) => any) | undefined;
157
+ Float64Array?: ((value: string) => any) | undefined;
158
+ Error?: ((value: {
92
159
  name: string;
93
- type?: 'bytes';
160
+ message: string;
161
+ stack?: string;
162
+ cause?: unknown;
163
+ }) => any) | undefined;
164
+ EvalError?: ((value: {
165
+ message: string;
166
+ stack?: string;
167
+ cause?: unknown;
168
+ }) => any) | undefined;
169
+ Headers?: ((value: [string, string][]) => any) | undefined;
170
+ HookConflictError?: ((value: {
171
+ message: string;
172
+ stack?: string;
173
+ cause?: unknown;
174
+ token: string;
175
+ conflictingRunId?: string;
176
+ }) => any) | undefined;
177
+ Int8Array?: ((value: string) => any) | undefined;
178
+ Int16Array?: ((value: string) => any) | undefined;
179
+ Int32Array?: ((value: string) => any) | undefined;
180
+ Map?: ((value: [any, any][]) => any) | undefined;
181
+ RangeError?: ((value: {
182
+ message: string;
183
+ stack?: string;
184
+ cause?: unknown;
185
+ }) => any) | undefined;
186
+ ReadableStream?: ((value: {
187
+ name: string;
188
+ type?: "bytes";
94
189
  startIndex?: number;
190
+ framing?: ByteStreamFraming;
95
191
  } | {
96
192
  bodyInit: any;
97
- };
98
- RegExp: {
193
+ }) => any) | undefined;
194
+ ReferenceError?: ((value: {
195
+ message: string;
196
+ stack?: string;
197
+ cause?: unknown;
198
+ }) => any) | undefined;
199
+ RegExp?: ((value: {
99
200
  source: string;
100
201
  flags: string;
101
- };
102
- Request: {
202
+ }) => any) | undefined;
203
+ RetryableError?: ((value: {
204
+ message: string;
205
+ stack?: string;
206
+ cause?: unknown;
207
+ retryAfter: number;
208
+ }) => any) | undefined;
209
+ RuntimeDecryptionError?: ((value: {
210
+ message: string;
211
+ stack?: string;
212
+ cause?: unknown;
213
+ context?: import("@workflow/errors").RuntimeDecryptionErrorContext;
214
+ }) => any) | undefined;
215
+ Request?: ((value: {
103
216
  method: string;
104
217
  url: string;
105
218
  headers: Headers;
106
- body: Request['body'];
107
- duplex: Request['duplex'];
219
+ body: Request["body"];
220
+ duplex: Request["duplex"];
108
221
  responseWritable?: WritableStream<Response>;
109
- };
110
- Response: {
111
- type: Response['type'];
222
+ signal?: AbortSignal;
223
+ }) => any) | undefined;
224
+ Response?: ((value: {
225
+ type: Response["type"];
112
226
  url: string;
113
227
  status: number;
114
228
  statusText: string;
115
229
  headers: Headers;
116
- body: Response['body'];
230
+ body: Response["body"];
117
231
  redirected: boolean;
118
- };
119
- Class: {
232
+ }) => any) | undefined;
233
+ Class?: ((value: {
120
234
  classId: string;
121
- };
122
- /**
123
- * Custom serialized class instance.
124
- * The class must have a `classId` property and be registered for deserialization.
125
- */
126
- Instance: {
235
+ }) => any) | undefined;
236
+ Instance?: ((value: {
127
237
  classId: string;
128
238
  data: unknown;
129
- };
130
- Set: any[];
131
- StepFunction: {
239
+ }) => any) | undefined;
240
+ Set?: ((value: any[]) => any) | undefined;
241
+ SyntaxError?: ((value: {
242
+ message: string;
243
+ stack?: string;
244
+ cause?: unknown;
245
+ }) => any) | undefined;
246
+ StepFunction?: ((value: {
132
247
  stepId: string;
133
248
  closureVars?: Record<string, any>;
134
- };
135
- URL: string;
136
- WorkflowFunction: {
249
+ boundThis?: unknown;
250
+ boundArgs?: unknown[];
251
+ }) => any) | undefined;
252
+ TypeError?: ((value: {
253
+ message: string;
254
+ stack?: string;
255
+ cause?: unknown;
256
+ }) => any) | undefined;
257
+ URIError?: ((value: {
258
+ message: string;
259
+ stack?: string;
260
+ cause?: unknown;
261
+ }) => any) | undefined;
262
+ URL?: ((value: string) => any) | undefined;
263
+ WorkflowFunction?: ((value: {
137
264
  workflowId: string;
138
- };
139
- URLSearchParams: string;
140
- Uint8Array: string;
141
- Uint8ClampedArray: string;
142
- Uint16Array: string;
143
- Uint32Array: string;
144
- WritableStream: {
145
- name: string;
146
- };
147
- }
148
- type Reducers = {
149
- [K in keyof SerializableSpecial]: (value: any) => SerializableSpecial[K] | false;
150
- };
151
- type Revivers = {
152
- [K in keyof SerializableSpecial]: (value: SerializableSpecial[K]) => any;
153
- };
154
- /**
155
- * Reducers for serialization boundary from the client side, passing arguments
156
- * to the workflow handler.
157
- *
158
- * @param global
159
- * @param ops
160
- * @returns
161
- */
162
- export declare function getExternalReducers(global: Record<string, any> | undefined, ops: Promise<void>[], runId: string, cryptoKey: EncryptionKeyParam): Reducers;
163
- /**
164
- * Reducers for serialization boundary from within the workflow execution
165
- * environment, passing return value to the client side and into step arguments.
166
- *
167
- * @param global
168
- * @returns
169
- */
170
- export declare function getWorkflowReducers(global?: Record<string, any>): Reducers;
171
- export declare function getCommonRevivers(global?: Record<string, any>): {
172
- readonly ArrayBuffer: (value: string) => any;
173
- readonly BigInt: (value: string) => any;
174
- readonly BigInt64Array: (value: string) => any;
175
- readonly BigUint64Array: (value: string) => any;
176
- readonly Date: (value: string) => any;
177
- readonly DOMException: (value: {
265
+ }) => any) | undefined;
266
+ URLSearchParams?: ((value: string) => any) | undefined;
267
+ Uint8Array?: ((value: string) => any) | undefined;
268
+ Uint8ClampedArray?: ((value: string) => any) | undefined;
269
+ Uint16Array?: ((value: string) => any) | undefined;
270
+ Uint32Array?: ((value: string) => any) | undefined;
271
+ AggregateError?: ((value: {
178
272
  message: string;
179
- name: string;
180
273
  stack?: string;
181
274
  cause?: unknown;
182
- }) => any;
183
- readonly Error: (value: Record<string, any>) => any;
184
- readonly Float32Array: (value: string) => any;
185
- readonly Float64Array: (value: string) => any;
186
- readonly Headers: (value: [string, string][]) => any;
187
- readonly Int8Array: (value: string) => any;
188
- readonly Int16Array: (value: string) => any;
189
- readonly Int32Array: (value: string) => any;
190
- readonly Map: (value: [any, any][]) => any;
191
- readonly RegExp: (value: {
192
- source: string;
193
- flags: string;
194
- }) => any;
195
- readonly Class: (value: {
196
- classId: string;
197
- }) => Function;
198
- readonly Instance: (value: {
199
- classId: string;
200
- data: unknown;
201
- }) => any;
202
- readonly Set: (value: any[]) => any;
203
- readonly URL: (value: string) => any;
204
- readonly URLSearchParams: (value: string) => any;
205
- readonly Uint8Array: (value: string) => any;
206
- readonly Uint8ClampedArray: (value: string) => any;
207
- readonly Uint16Array: (value: string) => any;
208
- readonly Uint32Array: (value: string) => any;
275
+ errors: unknown[];
276
+ }) => any) | undefined;
277
+ WritableStream?: ((value: {
278
+ name: string;
279
+ runId?: string;
280
+ deploymentId?: string;
281
+ encryptionPublicKey?: string;
282
+ }) => any) | undefined;
283
+ AbortController?: ((value: {
284
+ streamName: string;
285
+ hookToken: string;
286
+ aborted: boolean;
287
+ reason?: unknown;
288
+ }) => any) | undefined;
289
+ AbortSignal?: ((value: {
290
+ streamName: string;
291
+ hookToken: string;
292
+ aborted: boolean;
293
+ reason?: unknown;
294
+ }) => any) | undefined;
209
295
  };
210
296
  /**
211
297
  * Revivers for deserialization boundary from the client side,
@@ -215,7 +301,7 @@ export declare function getCommonRevivers(global?: Record<string, any>): {
215
301
  * @param ops
216
302
  * @param runId
217
303
  */
218
- export declare function getExternalRevivers(global: Record<string, any> | undefined, ops: Promise<void>[], runId: string, cryptoKey: EncryptionKeyParam): Revivers;
304
+ export declare function getExternalRevivers(global: Record<string, any> | undefined, ops: Promise<void>[], runId: string, cryptoKey: EncryptionKeyParam): Partial<Revivers>;
219
305
  /**
220
306
  * Revivers for deserialization boundary from within the workflow execution
221
307
  * environment, receiving arguments from the client side, and return values
@@ -224,29 +310,57 @@ export declare function getExternalRevivers(global: Record<string, any> | undefi
224
310
  * @param global
225
311
  * @returns
226
312
  */
227
- export declare function getWorkflowRevivers(global?: Record<string, any>): Revivers;
313
+ export declare function getWorkflowRevivers(global?: Record<string, any>): Partial<Revivers>;
228
314
  /**
229
315
  * Encrypt data if the world supports encryption.
230
316
  * Returns original data if encryption is not available.
231
317
  *
232
- * @param data - Serialized data to encrypt
233
- * @param key - Encryption key (undefined to skip encryption)
234
- * @param context - Encryption context with runId
235
- * @returns Encrypted data if encryption available, original data otherwise
318
+ * @deprecated Use `encrypt` from `./serialization/encryption.js` instead.
236
319
  */
237
- export declare function maybeEncrypt(data: Uint8Array, key: CryptoKey | undefined): Promise<Uint8Array>;
320
+ export declare function maybeEncrypt(data: Uint8Array, key: PayloadKey | undefined): Promise<Uint8Array>;
238
321
  /**
239
322
  * Decrypt data if it has the 'encr' prefix.
240
323
  *
241
- * @param data - Data that may be encrypted
242
- * @param key - Encryption key (undefined if no key available)
243
- * @returns Decrypted data if encrypted, original data otherwise
244
- * @throws {WorkflowRuntimeError} If the data is encrypted but no key is
245
- * available. Callers (e.g., `Run.pollReturnValue()`, `hydrateStepReturnValue`)
246
- * should be aware this can surface as a rejected promise during key rotation
247
- * or misconfiguration scenarios.
324
+ * @deprecated Use `decrypt` from `./serialization/encryption.js` instead.
325
+ */
326
+ export declare function maybeDecrypt(data: Uint8Array | unknown, key: PayloadKey | undefined): Promise<Uint8Array | unknown>;
327
+ /**
328
+ * Replay hydration has two stages:
329
+ *
330
+ * 1. Host-side preparation decrypts and decompresses persisted data. That work
331
+ * is independent of a workflow VM and can be cached across replay VMs.
332
+ * 2. Deserialization revives the prepared representation against the current
333
+ * VM's globals. It must run again for every VM to produce fresh object graphs
334
+ * and correctly scoped Workflow objects.
335
+ *
336
+ * `data` is the boundary between those stages. For current-format payloads it
337
+ * is still format-prefixed serialized bytes, not a live JavaScript value.
248
338
  */
249
- export declare function maybeDecrypt(data: Uint8Array | unknown, key: CryptoKey | undefined): Promise<Uint8Array | unknown>;
339
+ export interface PreparedReplayPayload {
340
+ readonly data: unknown;
341
+ }
342
+ /**
343
+ * Swappable implementation of the host-side preparation stage. Supporting
344
+ * both direct and promised results lets a future synchronous Node decryptor use
345
+ * the same cache contract as today's asynchronous Web Crypto implementation.
346
+ */
347
+ export type ReplayPayloadPreparer = (value: unknown, key: PayloadKey | undefined) => PreparedReplayPayload | Promise<PreparedReplayPayload>;
348
+ /**
349
+ * Decrypt and decompress persisted data without parsing it into JavaScript.
350
+ * Legacy non-binary values pass through unchanged for their consumer to revive.
351
+ */
352
+ export declare const prepareReplayPayload: ReplayPayloadPreparer;
353
+ /**
354
+ * Parse a prepared workflow argument or successful step/hook payload using the
355
+ * current workflow VM's globals and revivers. Each call intentionally creates
356
+ * a fresh object graph so mutations cannot leak across replay iterations.
357
+ */
358
+ export declare function deserializePreparedReplayPayload(prepared: PreparedReplayPayload, global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>): any;
359
+ /**
360
+ * Parse a prepared step error using the current workflow VM's class revivers.
361
+ * This preserves thrown-value identity without sharing objects between VMs.
362
+ */
363
+ export declare function deserializePreparedStepError(prepared: PreparedReplayPayload, global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>): unknown;
250
364
  /**
251
365
  * Called from the `start()` function to serialize the workflow arguments
252
366
  * into a format that can be saved to the database and then hydrated from
@@ -258,61 +372,113 @@ export declare function maybeDecrypt(data: Uint8Array | unknown, key: CryptoKey
258
372
  * @param ops - Promise array for stream operations
259
373
  * @param global - Global object for serialization context
260
374
  * @param v1Compat - Enable legacy v1 compatibility mode
375
+ * @param framedByteStreams - Whether the target run can decode wire-framed
376
+ * byte streams. Should match the target deployment's capability — see
377
+ * `getRunCapabilities` in `capabilities.ts`. Defaults to `false` for
378
+ * backwards compatibility with older runs.
261
379
  * @returns The dehydrated value as binary data (Uint8Array) with format prefix
262
380
  */
263
- export declare function dehydrateWorkflowArguments(value: unknown, runId: string, key: CryptoKey | undefined, ops?: Promise<void>[], global?: Record<string, any>, v1Compat?: boolean): Promise<Uint8Array | unknown>;
381
+ export declare function dehydrateWorkflowArguments(value: unknown, runId: string, key: PayloadKey | undefined, ops?: Promise<void>[], global?: Record<string, any>, v1Compat?: boolean, framedByteStreams?: boolean, compression?: boolean): Promise<Uint8Array | unknown>;
264
382
  /**
265
383
  * Called from workflow execution environment to hydrate the workflow
266
- * arguments from the database at the start of workflow execution.
267
- *
268
- * @param value - Binary serialized data (Uint8Array) with format prefix
269
- * @param _runId - Workflow run ID (reserved for future decryption context; decryption is currently driven solely by the provided key)
270
- * @param key - Encryption key (undefined to skip decryption)
271
- * @param global - Global object for deserialization context
272
- * @param extraRevivers - Additional revivers for custom types
273
- * @returns The hydrated value
384
+ * arguments from the database at the start of workflow execution. A prepared
385
+ * payload skips host-side decrypt/decompress but always performs VM revival.
274
386
  */
275
- export declare function hydrateWorkflowArguments(value: Uint8Array | unknown, _runId: string, key: CryptoKey | undefined, global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>): Promise<any>;
387
+ export declare function hydrateWorkflowArguments(value: Uint8Array | unknown, _runId: string, key: PayloadKey | undefined, global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>, prepared?: PreparedReplayPayload): Promise<any>;
276
388
  /**
277
389
  * Dehydrate workflow return value for storage.
390
+ */
391
+ export declare function dehydrateWorkflowReturnValue(value: unknown, _runId: string, key: PayloadKey | undefined, global?: Record<string, any>, v1Compat?: boolean, compression?: boolean,
392
+ /**
393
+ * Optional sink receiving every workflow-code execution serialization could
394
+ * not avoid, for callers that need them programmatically (e.g. a
395
+ * retained-VM gate deciding whether the VM is still reusable). The
396
+ * executions are emitted as span attributes either way, so omitting this
397
+ * loses nothing observability-wise. The retained-VM gate in
398
+ * runtime/suspension-handler.ts passes one for step-input dehydration.
399
+ */
400
+ guestCodeStatsOut?: GuestCodeStats): Promise<Uint8Array | unknown>;
401
+ /**
402
+ * Called from the client side to hydrate the workflow return value
403
+ * of a completed workflow run.
404
+ */
405
+ export declare function hydrateWorkflowReturnValue(value: Uint8Array | unknown, runId: string, key: PayloadKey | undefined, ops?: Promise<void>[], global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>): Promise<any>;
406
+ /**
407
+ * Called from the workflow handler when a step is being created.
408
+ * Dehydrates values from within the workflow execution environment.
409
+ */
410
+ export declare function dehydrateStepArguments(value: unknown, _runId: string, key: PayloadKey | undefined, global?: Record<string, any>, v1Compat?: boolean, compression?: boolean,
411
+ /** See `dehydrateWorkflowReturnValue`. */
412
+ guestCodeStatsOut?: GuestCodeStats): Promise<Uint8Array | unknown>;
413
+ /**
414
+ * Called from the step executor to hydrate the arguments of a step
415
+ * from the database at the start of the step execution.
416
+ */
417
+ export declare function hydrateStepArguments(value: Uint8Array | unknown, runId: string, key: PayloadKey | undefined, ops?: Promise<any>[], global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>, deploymentId?: string): Promise<any>;
418
+ /**
419
+ * Called from the step executor when a step has completed.
420
+ * Dehydrates values from within the step execution environment
421
+ * into a format that can be saved to the database.
278
422
  *
279
423
  * @param value - The value to serialize
280
424
  * @param runId - Run ID for encryption context
281
425
  * @param key - Encryption key (undefined to skip encryption)
426
+ * @param ops - Promise array for stream operations
282
427
  * @param global - Global object for serialization context
428
+ * @param v1Compat - Enable legacy v1 compatibility mode
429
+ * @param framedByteStreams - Whether the target run can decode wire-framed
430
+ * byte streams. Should match the target deployment's capability — see
431
+ * `getRunCapabilities` in `capabilities.ts`. Defaults to `false` for
432
+ * backwards compatibility with older runs.
283
433
  * @returns The dehydrated value as binary data (Uint8Array) with format prefix
284
434
  */
285
- export declare function dehydrateWorkflowReturnValue(value: unknown, _runId: string, key: CryptoKey | undefined, global?: Record<string, any>, v1Compat?: boolean): Promise<Uint8Array | unknown>;
435
+ export declare function dehydrateStepReturnValue(value: unknown, runId: string, key: PayloadKey | undefined, ops?: Promise<any>[], global?: Record<string, any>, v1Compat?: boolean, framedByteStreams?: boolean, compression?: boolean, runReadyBarrier?: Promise<unknown>): Promise<Uint8Array | unknown>;
286
436
  /**
287
- * Called from the client side (i.e. the execution environment where
288
- * the workflow run was initiated from) to hydrate the workflow
289
- * return value of a completed workflow run.
437
+ * Called from the step executor when a step throws. Dehydrates the thrown
438
+ * value from within the step execution environment into a format that can
439
+ * be saved to the database in a `step_failed` or `step_retrying` event.
440
+ *
441
+ * Any JavaScript value can be thrown (strings, numbers, objects, Errors,
442
+ * Error subclasses), so the same serialization pipeline used for step
443
+ * arguments and return values is applied here.
444
+ *
445
+ * @param value - The thrown value to serialize (can be any type)
446
+ * @param runId - Run ID for encryption context
447
+ * @param key - Encryption key (undefined to skip encryption)
448
+ * @param ops - Promise array for stream operations
449
+ * @param global - Global object for serialization context
450
+ * @returns The dehydrated value as binary data (Uint8Array) with format prefix
451
+ */
452
+ export declare function dehydrateStepError(value: unknown, runId: string, key: PayloadKey | undefined, ops?: Promise<any>[], global?: Record<string, any>, compression?: boolean): Promise<Uint8Array>;
453
+ /**
454
+ * Called from the workflow handler when replaying the event log of a
455
+ * `step_failed` or `step_retrying` event. Hydrates the thrown value from
456
+ * the database so the workflow can see the original thrown value.
290
457
  *
291
458
  * @param value - Binary serialized data (Uint8Array) with format prefix
292
459
  * @param runId - Run ID for decryption context
293
460
  * @param key - Encryption key (undefined to skip decryption)
294
- * @param ops - Promise array for stream operations
295
461
  * @param global - Global object for deserialization context
296
462
  * @param extraRevivers - Additional revivers for custom types
297
- * @returns The hydrated return value, ready to be consumed by the client
463
+ * @param prepared - Optional cached decrypt/decompress result
464
+ * @returns The hydrated thrown value, ready to reject the step promise
298
465
  */
299
- export declare function hydrateWorkflowReturnValue(value: Uint8Array | unknown, runId: string, key: CryptoKey | undefined, ops?: Promise<void>[], global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>): Promise<any>;
466
+ export declare function hydrateStepError(value: Uint8Array | unknown, _runId: string, key: PayloadKey | undefined, global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>, prepared?: PreparedReplayPayload): Promise<unknown>;
300
467
  /**
301
- * Called from the workflow handler when a step is being created.
302
- * Dehydrates values from within the workflow execution environment
303
- * into a format that can be saved to the database.
468
+ * Called from the workflow handler when the workflow itself throws.
469
+ * Dehydrates the thrown value from within the workflow execution environment
470
+ * into a format that can be saved to the database in a `run_failed` event.
304
471
  *
305
- * @param value - The value to serialize
472
+ * @param value - The thrown value to serialize (can be any type)
306
473
  * @param runId - Run ID for encryption context
307
474
  * @param key - Encryption key (undefined to skip encryption)
308
475
  * @param global - Global object for serialization context
309
- * @param v1Compat - Enable legacy v1 compatibility mode
310
476
  * @returns The dehydrated value as binary data (Uint8Array) with format prefix
311
477
  */
312
- export declare function dehydrateStepArguments(value: unknown, _runId: string, key: CryptoKey | undefined, global?: Record<string, any>, v1Compat?: boolean): Promise<Uint8Array | unknown>;
478
+ export declare function dehydrateRunError(value: unknown, _runId: string, key: PayloadKey | undefined, global?: Record<string, any>, compression?: boolean): Promise<Uint8Array>;
313
479
  /**
314
- * Called from the step handler to hydrate the arguments of a step
315
- * from the database at the start of the step execution.
480
+ * Called from the client side (or observability tools) to hydrate the run
481
+ * error value of a failed workflow run.
316
482
  *
317
483
  * @param value - Binary serialized data (Uint8Array) with format prefix
318
484
  * @param runId - Run ID for decryption context
@@ -320,23 +486,9 @@ export declare function dehydrateStepArguments(value: unknown, _runId: string, k
320
486
  * @param ops - Promise array for stream operations
321
487
  * @param global - Global object for deserialization context
322
488
  * @param extraRevivers - Additional revivers for custom types
323
- * @returns The hydrated value, ready to be consumed by the step user-code function
324
- */
325
- export declare function hydrateStepArguments(value: Uint8Array | unknown, runId: string, key: CryptoKey | undefined, ops?: Promise<any>[], global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>): Promise<any>;
326
- /**
327
- * Called from the step handler when a step has completed.
328
- * Dehydrates values from within the step execution environment
329
- * into a format that can be saved to the database.
330
- *
331
- * @param value - The value to serialize
332
- * @param runId - Run ID for encryption context
333
- * @param key - Encryption key (undefined to skip encryption)
334
- * @param ops - Promise array for stream operations
335
- * @param global - Global object for serialization context
336
- * @param v1Compat - Enable legacy v1 compatibility mode
337
- * @returns The dehydrated value as binary data (Uint8Array) with format prefix
489
+ * @returns The hydrated thrown value, ready to be consumed by the client
338
490
  */
339
- export declare function dehydrateStepReturnValue(value: unknown, runId: string, key: CryptoKey | undefined, ops?: Promise<any>[], global?: Record<string, any>, v1Compat?: boolean): Promise<Uint8Array | unknown>;
491
+ export declare function hydrateRunError(value: Uint8Array | unknown, runId: string, key: PayloadKey | undefined, ops?: Promise<void>[], global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>): Promise<unknown>;
340
492
  /**
341
493
  * Called from the workflow handler when replaying the event log of a `step_completed` event.
342
494
  * Hydrates the return value of a step from the database.
@@ -346,8 +498,9 @@ export declare function dehydrateStepReturnValue(value: unknown, runId: string,
346
498
  * @param key - Encryption key (undefined to skip decryption)
347
499
  * @param global - Global object for deserialization context
348
500
  * @param extraRevivers - Additional revivers for custom types
349
- * @returns The hydrated return value of a step, ready to be consumed by the workflow handler
501
+ * @param prepared - Optional cached decrypt/decompress result
502
+ * Called from the workflow handler when replaying the event log
503
+ * of a `step_completed` event.
350
504
  */
351
- export declare function hydrateStepReturnValue(value: Uint8Array | unknown, _runId: string, key: CryptoKey | undefined, global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>): Promise<any>;
352
- export {};
505
+ export declare function hydrateStepReturnValue(value: Uint8Array | unknown, _runId: string, key: PayloadKey | undefined, global?: Record<string, any>, extraRevivers?: Record<string, (value: any) => any>, prepared?: PreparedReplayPayload): Promise<any>;
353
506
  //# sourceMappingURL=serialization.d.ts.map