rivetkit 0.0.0-skip-ready-wait-flatten-client-options.1cae221 → 0.0.0-sqlite-uds.4e59a38

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 (253) hide show
  1. package/dist/browser/client.d.ts +561 -89
  2. package/dist/browser/client.js +1063 -430
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +22 -2
  5. package/dist/browser/inspector/client.js +1036 -232
  6. package/dist/browser/inspector/client.js.map +1 -1
  7. package/dist/tsup/actor/errors.cjs +6 -2
  8. package/dist/tsup/actor/errors.cjs.map +1 -1
  9. package/dist/tsup/actor/errors.d.cts +1 -74
  10. package/dist/tsup/actor/errors.d.ts +1 -74
  11. package/dist/tsup/actor/errors.js +5 -1
  12. package/dist/tsup/agent-os/index.cjs +2218 -2082
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +556 -85
  15. package/dist/tsup/agent-os/index.d.ts +556 -85
  16. package/dist/tsup/agent-os/index.js +2220 -2084
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/{chunk-NFC5VU36.cjs → chunk-3GC3EP6D.cjs} +18 -10
  19. package/dist/tsup/chunk-3GC3EP6D.cjs.map +1 -0
  20. package/dist/tsup/{chunk-7MRGNVSR.js → chunk-3GLNEWGY.js} +78 -6
  21. package/dist/tsup/chunk-3GLNEWGY.js.map +1 -0
  22. package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-4FC7TVS6.cjs} +35 -10
  23. package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
  24. package/dist/tsup/{chunk-POTPHU3P.cjs → chunk-62LSMTP2.cjs} +3 -3
  25. package/dist/tsup/{chunk-POTPHU3P.cjs.map → chunk-62LSMTP2.cjs.map} +1 -1
  26. package/dist/tsup/{chunk-OIKOPSXQ.js → chunk-7IVUT2JT.js} +12 -4
  27. package/dist/tsup/chunk-7IVUT2JT.js.map +1 -0
  28. package/dist/tsup/{chunk-22XU3BVY.cjs → chunk-GEYQLGXC.cjs} +925 -328
  29. package/dist/tsup/chunk-GEYQLGXC.cjs.map +1 -0
  30. package/dist/tsup/{chunk-D2TLG75Y.cjs → chunk-GMN45CQ6.cjs} +10 -10
  31. package/dist/tsup/chunk-GMN45CQ6.cjs.map +1 -0
  32. package/dist/tsup/{chunk-3BFYSYRU.js → chunk-HXUEHHJF.js} +3 -2
  33. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  34. package/dist/tsup/{chunk-IOYKCB6Y.cjs → chunk-I336PMWT.cjs} +44 -9
  35. package/dist/tsup/chunk-I336PMWT.cjs.map +1 -0
  36. package/dist/tsup/{chunk-RZEJJJKU.js → chunk-IB73AMGJ.js} +42 -7
  37. package/dist/tsup/chunk-IB73AMGJ.js.map +1 -0
  38. package/dist/tsup/{chunk-4ZIWB4CQ.js → chunk-ITWJ6Y7G.js} +2 -2
  39. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  40. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  41. package/dist/tsup/{chunk-W54QCENI.js → chunk-KTNBYGRU.js} +134 -20
  42. package/dist/tsup/chunk-KTNBYGRU.js.map +1 -0
  43. package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-OAPVVVTX.cjs} +79 -7
  44. package/dist/tsup/chunk-OAPVVVTX.cjs.map +1 -0
  45. package/dist/tsup/{chunk-TPBHXFB2.cjs → chunk-OUDV3ITX.cjs} +138 -24
  46. package/dist/tsup/chunk-OUDV3ITX.cjs.map +1 -0
  47. package/dist/tsup/{chunk-XNZR7UD2.cjs → chunk-PRXTIERO.cjs} +90 -65
  48. package/dist/tsup/chunk-PRXTIERO.cjs.map +1 -0
  49. package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-VE2X4KMG.cjs} +3 -2
  50. package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -0
  51. package/dist/tsup/{chunk-KSG2COSQ.js → chunk-WRZEVVLL.js} +6 -6
  52. package/dist/tsup/chunk-WRZEVVLL.js.map +1 -0
  53. package/dist/tsup/{chunk-LNMB25HW.js → chunk-XAIMHUPG.js} +780 -183
  54. package/dist/tsup/chunk-XAIMHUPG.js.map +1 -0
  55. package/dist/tsup/{chunk-D4TSTM6C.js → chunk-XZ62SWSC.js} +83 -58
  56. package/dist/tsup/chunk-XZ62SWSC.js.map +1 -0
  57. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  58. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  59. package/dist/tsup/{chunk-K34B3OVG.js → chunk-ZZ3WBRPD.js} +34 -9
  60. package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
  61. package/dist/tsup/client/mod.cjs +9 -9
  62. package/dist/tsup/client/mod.cjs.map +1 -1
  63. package/dist/tsup/client/mod.d.cts +8 -9
  64. package/dist/tsup/client/mod.d.ts +8 -9
  65. package/dist/tsup/client/mod.js +8 -8
  66. package/dist/tsup/common/log.cjs +5 -3
  67. package/dist/tsup/common/log.cjs.map +1 -1
  68. package/dist/tsup/common/log.d.cts +5 -1
  69. package/dist/tsup/common/log.d.ts +5 -1
  70. package/dist/tsup/common/log.js +6 -4
  71. package/dist/tsup/common/websocket.cjs +4 -4
  72. package/dist/tsup/common/websocket.js +3 -3
  73. package/dist/tsup/{config-CRdGwwbr.d.cts → config-CxG53eQo.d.cts} +577 -36
  74. package/dist/tsup/{config-kxXbtrJU.d.ts → config-DLOxy81E.d.cts} +5 -5
  75. package/dist/tsup/{config-kxXbtrJU.d.cts → config-DLOxy81E.d.ts} +5 -5
  76. package/dist/tsup/{config-DIpBWm5C.d.ts → config-Ds6DCRhV.d.ts} +577 -36
  77. package/dist/tsup/context-8KlcOYIs.d.cts +129 -0
  78. package/dist/tsup/context-Cfbm4QLr.d.ts +129 -0
  79. package/dist/tsup/db/drizzle.cjs +151 -79
  80. package/dist/tsup/db/drizzle.cjs.map +1 -1
  81. package/dist/tsup/db/drizzle.d.cts +2 -2
  82. package/dist/tsup/db/drizzle.d.ts +2 -2
  83. package/dist/tsup/db/drizzle.js +151 -79
  84. package/dist/tsup/db/drizzle.js.map +1 -1
  85. package/dist/tsup/db/mod.cjs +79 -24
  86. package/dist/tsup/db/mod.cjs.map +1 -1
  87. package/dist/tsup/db/mod.d.cts +2 -2
  88. package/dist/tsup/db/mod.d.ts +2 -2
  89. package/dist/tsup/db/mod.js +78 -23
  90. package/dist/tsup/db/mod.js.map +1 -1
  91. package/dist/tsup/dynamic/mod.cjs +24 -0
  92. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  93. package/dist/tsup/dynamic/mod.d.cts +37 -0
  94. package/dist/tsup/dynamic/mod.d.ts +37 -0
  95. package/dist/tsup/dynamic/mod.js +24 -0
  96. package/dist/tsup/dynamic/mod.js.map +1 -0
  97. package/dist/tsup/inspector/mod.cjs +47 -12
  98. package/dist/tsup/inspector/mod.cjs.map +1 -1
  99. package/dist/tsup/inspector/mod.d.cts +37 -15
  100. package/dist/tsup/inspector/mod.d.ts +37 -15
  101. package/dist/tsup/inspector/mod.js +46 -11
  102. package/dist/tsup/inspector/mod.js.map +1 -1
  103. package/dist/tsup/inspector-tab/mod.cjs +162 -0
  104. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  105. package/dist/tsup/inspector-tab/mod.d.cts +240 -0
  106. package/dist/tsup/inspector-tab/mod.d.ts +240 -0
  107. package/dist/tsup/inspector-tab/mod.js +162 -0
  108. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  109. package/dist/tsup/mod.cjs +1078 -479
  110. package/dist/tsup/mod.cjs.map +1 -1
  111. package/dist/tsup/mod.d.cts +5 -6
  112. package/dist/tsup/mod.d.ts +5 -6
  113. package/dist/tsup/mod.js +996 -397
  114. package/dist/tsup/mod.js.map +1 -1
  115. package/dist/tsup/test/mod.cjs +21 -18
  116. package/dist/tsup/test/mod.cjs.map +1 -1
  117. package/dist/tsup/test/mod.d.cts +4 -5
  118. package/dist/tsup/test/mod.d.ts +4 -5
  119. package/dist/tsup/test/mod.js +18 -15
  120. package/dist/tsup/test/mod.js.map +1 -1
  121. package/dist/tsup/utils-CqDnC_PS.d.cts +104 -0
  122. package/dist/tsup/utils-CqDnC_PS.d.ts +104 -0
  123. package/dist/tsup/utils.cjs +3 -3
  124. package/dist/tsup/utils.d.cts +1 -1
  125. package/dist/tsup/utils.d.ts +1 -1
  126. package/dist/tsup/utils.js +2 -2
  127. package/dist/tsup/workflow/mod.cjs +386 -322
  128. package/dist/tsup/workflow/mod.cjs.map +1 -1
  129. package/dist/tsup/workflow/mod.d.cts +8 -9
  130. package/dist/tsup/workflow/mod.d.ts +8 -9
  131. package/dist/tsup/workflow/mod.js +363 -299
  132. package/dist/tsup/workflow/mod.js.map +1 -1
  133. package/package.json +35 -14
  134. package/src/actor/config.ts +188 -59
  135. package/src/actor/contexts/index.ts +7 -2
  136. package/src/actor/definition.ts +17 -19
  137. package/src/actor/driver.ts +3 -3
  138. package/src/actor/errors.ts +70 -7
  139. package/src/actor/instance/mod.ts +39 -56
  140. package/src/actor/keys.ts +2 -1
  141. package/src/actor/mod.ts +22 -20
  142. package/src/actor/schema.ts +2 -2
  143. package/src/agent-os/actor/index.ts +38 -18
  144. package/src/agent-os/actor/preview.ts +1 -2
  145. package/src/agent-os/actor/session.ts +2 -2
  146. package/src/agent-os/config.ts +1 -1
  147. package/src/agent-os/fs/database-vfs.ts +1 -1
  148. package/src/agent-os/index.ts +16 -15
  149. package/src/client/actor-common.ts +88 -62
  150. package/src/client/actor-conn.ts +58 -63
  151. package/src/client/actor-handle.ts +125 -71
  152. package/src/client/actor-query.ts +5 -5
  153. package/src/client/config.ts +3 -3
  154. package/src/client/errors.ts +2 -1
  155. package/src/client/lifecycle-errors.ts +2 -4
  156. package/src/client/query.ts +1 -1
  157. package/src/client/queue.ts +8 -3
  158. package/src/client/raw-utils.ts +10 -10
  159. package/src/client/resolve-gateway-target.ts +1 -1
  160. package/src/client/utils.ts +34 -10
  161. package/src/common/actor-router-consts.ts +7 -4
  162. package/src/common/actor-websocket.ts +3 -1
  163. package/src/common/bare/actor-persist/v1.ts +205 -163
  164. package/src/common/bare/actor-persist/v2.ts +265 -213
  165. package/src/common/bare/actor-persist/v3.ts +176 -172
  166. package/src/common/bare/actor-persist/v4.ts +254 -253
  167. package/src/common/bare/generated/client-protocol/v4.ts +599 -0
  168. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  169. package/src/common/bare/transport/v1.ts +694 -542
  170. package/src/common/client-protocol-versioned.ts +176 -67
  171. package/src/common/client-protocol-zod.ts +7 -0
  172. package/src/common/client-protocol.ts +1 -1
  173. package/src/common/database/config.ts +16 -5
  174. package/src/common/database/mod.test.ts +83 -16
  175. package/src/common/database/mod.ts +86 -30
  176. package/src/common/database/native-database.test.ts +35 -22
  177. package/src/common/database/native-database.ts +26 -10
  178. package/src/common/database/shared.ts +1 -0
  179. package/src/common/encoding.ts +250 -16
  180. package/src/common/engine.ts +28 -1
  181. package/src/common/eventsource.ts +1 -1
  182. package/src/common/inline-websocket-adapter.ts +14 -13
  183. package/src/common/log.ts +15 -8
  184. package/src/common/router.ts +49 -23
  185. package/src/common/utils.ts +10 -202
  186. package/src/common/websocket-interface.ts +1 -1
  187. package/src/db/drizzle.ts +173 -96
  188. package/src/db/mod.ts +1 -1
  189. package/src/devtools-loader/index.ts +4 -7
  190. package/src/devtools-loader/serve-devtools.ts +26 -0
  191. package/src/drivers/engine/actor-driver.ts +76 -73
  192. package/src/dynamic/instance.ts +32 -0
  193. package/src/dynamic/internal.ts +50 -0
  194. package/src/dynamic/isolate-runtime.ts +66 -0
  195. package/src/dynamic/mod.ts +32 -0
  196. package/src/engine-client/actor-http-client.ts +6 -9
  197. package/src/engine-client/actor-websocket-client.ts +14 -13
  198. package/src/engine-client/api-endpoints.ts +51 -2
  199. package/src/engine-client/api-utils.ts +2 -2
  200. package/src/engine-client/driver.ts +3 -4
  201. package/src/engine-client/mod.ts +17 -10
  202. package/src/engine-client/ws-proxy.ts +9 -4
  203. package/src/inspector/client.browser.ts +66 -15
  204. package/src/inspector/mod.ts +2 -4
  205. package/src/inspector-tab/mod.ts +300 -0
  206. package/src/registry/config/envoy.ts +1 -2
  207. package/src/registry/config/index.ts +46 -20
  208. package/src/registry/index.ts +364 -87
  209. package/src/registry/napi-runtime.ts +97 -8
  210. package/src/registry/native-validation.ts +10 -12
  211. package/src/registry/native.ts +592 -343
  212. package/src/registry/process-metrics.ts +250 -0
  213. package/src/registry/runtime.ts +85 -6
  214. package/src/registry/wasm-runtime.ts +72 -3
  215. package/src/registry/write-through-proxy.ts +40 -0
  216. package/src/serde.ts +2 -2
  217. package/src/serverless/configure.ts +19 -8
  218. package/src/test/mod.ts +11 -8
  219. package/src/utils/crypto.ts +14 -0
  220. package/src/utils/endpoint-parser.ts +1 -1
  221. package/src/utils/env-vars.ts +37 -0
  222. package/src/utils/router.ts +1 -1
  223. package/src/utils.ts +1 -2
  224. package/src/workflow/context.ts +703 -240
  225. package/src/workflow/driver.ts +23 -12
  226. package/src/workflow/inspector.ts +12 -3
  227. package/src/workflow/mod.ts +37 -23
  228. package/dist/tsup/chunk-22XU3BVY.cjs.map +0 -1
  229. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  230. package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
  231. package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
  232. package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
  233. package/dist/tsup/chunk-D2TLG75Y.cjs.map +0 -1
  234. package/dist/tsup/chunk-D4TSTM6C.js.map +0 -1
  235. package/dist/tsup/chunk-IOYKCB6Y.cjs.map +0 -1
  236. package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
  237. package/dist/tsup/chunk-KSG2COSQ.js.map +0 -1
  238. package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
  239. package/dist/tsup/chunk-LNMB25HW.js.map +0 -1
  240. package/dist/tsup/chunk-NFC5VU36.cjs.map +0 -1
  241. package/dist/tsup/chunk-OIKOPSXQ.js.map +0 -1
  242. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  243. package/dist/tsup/chunk-RZEJJJKU.js.map +0 -1
  244. package/dist/tsup/chunk-TPBHXFB2.cjs.map +0 -1
  245. package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
  246. package/dist/tsup/chunk-W54QCENI.js.map +0 -1
  247. package/dist/tsup/chunk-XNZR7UD2.cjs.map +0 -1
  248. package/dist/tsup/context-B7G6sk7x.d.ts +0 -92
  249. package/dist/tsup/context-DzMRHkjC.d.cts +0 -92
  250. package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
  251. package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
  252. package/src/utils/serve.ts +0 -217
  253. /package/dist/tsup/{chunk-4ZIWB4CQ.js.map → chunk-ITWJ6Y7G.js.map} +0 -0
@@ -1,22 +1,24 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class; var _class2;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2;
2
2
 
3
- var _chunkNFC5VU36cjs = require('../chunk-NFC5VU36.cjs');
3
+ var _chunk3GC3EP6Dcjs = require('../chunk-3GC3EP6D.cjs');
4
+ require('../chunk-I336PMWT.cjs');
4
5
 
5
6
 
6
7
 
7
- var _chunkAK57AL7Scjs = require('../chunk-AK57AL7S.cjs');
8
- require('../chunk-IOYKCB6Y.cjs');
9
8
 
9
+ var _chunkOAPVVVTXcjs = require('../chunk-OAPVVVTX.cjs');
10
10
 
11
11
 
12
- var _chunkLLD2D5LOcjs = require('../chunk-LLD2D5LO.cjs');
13
- require('../chunk-TPBHXFB2.cjs');
14
12
 
13
+ var _chunkVE2X4KMGcjs = require('../chunk-VE2X4KMG.cjs');
14
+ require('../chunk-OUDV3ITX.cjs');
15
15
 
16
- var _chunkXNZR7UD2cjs = require('../chunk-XNZR7UD2.cjs');
17
16
 
17
+ var _chunkPRXTIEROcjs = require('../chunk-PRXTIERO.cjs');
18
18
 
19
- var _chunkV3QNBJ7Ncjs = require('../chunk-V3QNBJ7N.cjs');
19
+
20
+
21
+ var _chunk4FC7TVS6cjs = require('../chunk-4FC7TVS6.cjs');
20
22
 
21
23
  // src/workflow/mod.ts
22
24
 
@@ -33,8 +35,348 @@ var _chunkV3QNBJ7Ncjs = require('../chunk-V3QNBJ7N.cjs');
33
35
  var _workflowengine = require('@rivetkit/workflow-engine');
34
36
  var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);
35
37
 
38
+ // src/workflow/constants.ts
39
+ var WORKFLOW_GUARD_KV_KEY = "__rivet_actor_workflow_guard_triggered";
40
+
41
+ // src/workflow/context.ts
42
+ var DEACTIVATE_STEP = /* @__PURE__ */ Symbol("workflow.step.deactivate");
43
+ var WorkflowStepContext = class {
44
+ #runCtx;
45
+ #active = true;
46
+ #onGuardViolation;
47
+ constructor(runCtx, onGuardViolation) {
48
+ this.#runCtx = runCtx;
49
+ this.#onGuardViolation = onGuardViolation;
50
+ }
51
+ [DEACTIVATE_STEP]() {
52
+ this.#active = false;
53
+ }
54
+ #ensureActive(feature) {
55
+ if (!this.#active) {
56
+ this.#onGuardViolation();
57
+ throw new Error(
58
+ `${feature} is only available inside workflow steps`
59
+ );
60
+ }
61
+ }
62
+ get actorId() {
63
+ return this.#runCtx.actorId;
64
+ }
65
+ get name() {
66
+ return this.#runCtx.name;
67
+ }
68
+ get key() {
69
+ return this.#runCtx.key;
70
+ }
71
+ get log() {
72
+ return this.#runCtx.log;
73
+ }
74
+ get abortSignal() {
75
+ return this.#runCtx.abortSignal;
76
+ }
77
+ get state() {
78
+ this.#ensureActive("state");
79
+ return this.#runCtx.state;
80
+ }
81
+ get vars() {
82
+ this.#ensureActive("vars");
83
+ return this.#runCtx.vars;
84
+ }
85
+ get db() {
86
+ this.#ensureActive("db");
87
+ return this.#runCtx.db;
88
+ }
89
+ client() {
90
+ this.#ensureActive("client");
91
+ return this.#runCtx.client();
92
+ }
93
+ broadcast(name, ...args) {
94
+ this.#ensureActive("broadcast");
95
+ this.#runCtx.broadcast(
96
+ name,
97
+ ...args
98
+ );
99
+ }
100
+ get queue() {
101
+ const self = this;
102
+ async function send(name, body) {
103
+ self.#ensureActive("queue.send");
104
+ await self.#runCtx.queue.send(name, body);
105
+ }
106
+ return { send };
107
+ }
108
+ /**
109
+ * Holds the actor awake for the duration of the provided promise. The actor
110
+ * cannot idle-sleep or finalize the sleep grace period until the promise
111
+ * settles.
112
+ */
113
+ keepAwake(promise) {
114
+ this.#ensureActive("keepAwake");
115
+ return this.#runCtx.keepAwake(promise);
116
+ }
117
+ /**
118
+ * Registers a promise that the sleep grace period will wait on. Use this for
119
+ * best-effort flush/cleanup work that may complete inside the grace window.
120
+ */
121
+ waitUntil(promise) {
122
+ this.#ensureActive("waitUntil");
123
+ this.#runCtx.waitUntil(promise);
124
+ }
125
+ destroy() {
126
+ this.#ensureActive("destroy");
127
+ this.#runCtx.destroy();
128
+ }
129
+ };
130
+ var WorkflowContext = class _WorkflowContext {
131
+ #inner;
132
+ #runCtx;
133
+ constructor(inner, runCtx) {
134
+ this.#inner = inner;
135
+ this.#runCtx = runCtx;
136
+ }
137
+ get workflowId() {
138
+ return this.#inner.workflowId;
139
+ }
140
+ get abortSignal() {
141
+ return this.#inner.abortSignal;
142
+ }
143
+ get actorId() {
144
+ return this.#runCtx.actorId;
145
+ }
146
+ get name() {
147
+ return this.#runCtx.name;
148
+ }
149
+ get key() {
150
+ return this.#runCtx.key;
151
+ }
152
+ get log() {
153
+ return this.#runCtx.log;
154
+ }
155
+ get queue() {
156
+ const self = this;
157
+ async function next(name, opts) {
158
+ const message = await self.#inner.queue.next(name, opts);
159
+ return self.#toActorQueueMessage(message);
160
+ }
161
+ async function nextBatch(name, opts) {
162
+ const messages = await self.#inner.queue.nextBatch(name, opts);
163
+ return messages.map(
164
+ (message) => self.#toActorQueueMessage(message)
165
+ );
166
+ }
167
+ return {
168
+ next,
169
+ nextBatch
170
+ };
171
+ }
172
+ async step(nameOrConfig, run) {
173
+ if (typeof nameOrConfig === "string") {
174
+ if (!run) {
175
+ throw new Error("Step run function missing");
176
+ }
177
+ const stepRun = run;
178
+ return await this.#wrapActive(
179
+ () => this.#inner.step(nameOrConfig, () => this.#runStep(stepRun))
180
+ );
181
+ }
182
+ const stepConfig = nameOrConfig;
183
+ const rollback = stepConfig.rollback;
184
+ const config = {
185
+ ...stepConfig,
186
+ run: () => this.#runStep(stepConfig.run),
187
+ rollback: rollback ? (_ctx, output) => this.#runRollback(rollback, output) : void 0
188
+ };
189
+ return await this.#wrapActive(() => this.#inner.step(config));
190
+ }
191
+ async tryStep(nameOrConfig, run) {
192
+ if (typeof nameOrConfig === "string") {
193
+ if (!run) {
194
+ throw new Error("Step run function missing");
195
+ }
196
+ const stepRun = run;
197
+ return await this.#wrapActive(
198
+ () => this.#inner.tryStep(nameOrConfig, () => this.#runStep(stepRun))
199
+ );
200
+ }
201
+ const stepConfig = nameOrConfig;
202
+ const rollback = stepConfig.rollback;
203
+ const config = {
204
+ ...stepConfig,
205
+ run: () => this.#runStep(stepConfig.run),
206
+ rollback: rollback ? (_ctx, output) => this.#runRollback(rollback, output) : void 0
207
+ };
208
+ return await this.#wrapActive(() => this.#inner.tryStep(config));
209
+ }
210
+ async try(nameOrConfig, run) {
211
+ if (typeof nameOrConfig === "string") {
212
+ if (!run) {
213
+ throw new Error("Try run function missing");
214
+ }
215
+ const tryRun = run;
216
+ return await this.#wrapActive(
217
+ () => this.#inner.try(
218
+ nameOrConfig,
219
+ async (ctx) => tryRun(this.#createChildContext(ctx))
220
+ )
221
+ );
222
+ }
223
+ const tryConfig = nameOrConfig;
224
+ const config = {
225
+ ...tryConfig,
226
+ run: async (ctx) => tryConfig.run(this.#createChildContext(ctx))
227
+ };
228
+ return await this.#wrapActive(() => this.#inner.try(config));
229
+ }
230
+ async loop(nameOrConfig, run) {
231
+ if (typeof nameOrConfig === "string") {
232
+ if (!run) {
233
+ throw new Error("Loop run function missing");
234
+ }
235
+ const loopRun = run;
236
+ return await this.#wrapActive(
237
+ () => this.#inner.loop(
238
+ nameOrConfig,
239
+ // A void return (no explicit Loop result) is undefined at
240
+ // runtime, which the engine treats as continue.
241
+ async (ctx) => await _asyncNullishCoalesce(await loopRun(this.#createChildContext(ctx)), async () => ( void 0))
242
+ )
243
+ );
244
+ }
245
+ const loopConfig = nameOrConfig;
246
+ const wrapped = {
247
+ ...loopConfig,
248
+ run: (async (ctx, state) => await _asyncNullishCoalesce(await loopConfig.run(this.#createChildContext(ctx), state), async () => ( void 0)))
249
+ };
250
+ return await this.#wrapActive(() => this.#inner.loop(wrapped));
251
+ }
252
+ sleep(name, durationMs) {
253
+ return this.#inner.sleep(name, durationMs);
254
+ }
255
+ sleepUntil(name, timestampMs) {
256
+ return this.#inner.sleepUntil(name, timestampMs);
257
+ }
258
+ async rollbackCheckpoint(name) {
259
+ await this.#wrapActive(() => this.#inner.rollbackCheckpoint(name));
260
+ }
261
+ async join(name, branches) {
262
+ const wrappedBranches = Object.fromEntries(
263
+ Object.entries(branches).map(([key, branch]) => [
264
+ key,
265
+ {
266
+ run: async (ctx) => branch.run(this.#createChildContext(ctx))
267
+ }
268
+ ])
269
+ );
270
+ return await this.#wrapActive(
271
+ () => this.#inner.join(name, wrappedBranches)
272
+ );
273
+ }
274
+ async race(name, branches) {
275
+ const wrappedBranches = branches.map((branch) => ({
276
+ name: branch.name,
277
+ run: (ctx) => branch.run(this.#createChildContext(ctx))
278
+ }));
279
+ return await this.#wrapActive(
280
+ () => this.#inner.race(name, wrappedBranches)
281
+ );
282
+ }
283
+ async removed(name, originalType) {
284
+ await this.#wrapActive(() => this.#inner.removed(name, originalType));
285
+ }
286
+ getVersion(name, latest) {
287
+ return this.#wrapActive(() => this.#inner.getVersion(name, latest));
288
+ }
289
+ isEvicted() {
290
+ return this.#inner.isEvicted();
291
+ }
292
+ // Runs a user step body inside a fresh step context, snapshotting actor
293
+ // state/vars so a thrown step rolls back its mutations, and deactivating the
294
+ // step context once the body settles so it cannot be used after the step.
295
+ async #runStep(run) {
296
+ const stepCtx = new WorkflowStepContext(this.#runCtx, () => this.#markGuardTriggered());
297
+ let stateSnapshot = null;
298
+ try {
299
+ stateSnapshot = { state: this.#runCtx[_chunkOAPVVVTXcjs.RAW_STATE_SYMBOL]() };
300
+ } catch (error) {
301
+ this.#runCtx.log.debug({
302
+ msg: "failed to get state, likely due to being stateless workflow",
303
+ error
304
+ });
305
+ }
306
+ if (stateSnapshot) {
307
+ stateSnapshot.state = structuredClone(stateSnapshot.state);
308
+ }
309
+ const varsSnapshot = structuredClone(this.#runCtx.vars);
310
+ try {
311
+ return await run(stepCtx);
312
+ } catch (error) {
313
+ if (stateSnapshot) {
314
+ this.#runCtx.state = stateSnapshot.state;
315
+ }
316
+ this.#runCtx.vars = varsSnapshot;
317
+ throw error;
318
+ } finally {
319
+ stepCtx[DEACTIVATE_STEP]();
320
+ }
321
+ }
322
+ #toActorQueueMessage(message) {
323
+ let id;
324
+ try {
325
+ id = BigInt(message.id);
326
+ } catch (e) {
327
+ throw new Error(`Invalid queue message id "${message.id}"`);
328
+ }
329
+ return {
330
+ id,
331
+ name: message.name,
332
+ body: message.body,
333
+ createdAt: message.createdAt,
334
+ ...message.complete ? { complete: message.complete } : {}
335
+ };
336
+ }
337
+ // Runs a step rollback compensation with an active step context. Rollbacks
338
+ // intentionally mutate actor state, so their writes are not snapshotted.
339
+ async #runRollback(rollback, output) {
340
+ const stepCtx = new WorkflowStepContext(this.#runCtx, () => this.#markGuardTriggered());
341
+ try {
342
+ await rollback(stepCtx, output);
343
+ } finally {
344
+ stepCtx[DEACTIVATE_STEP]();
345
+ }
346
+ }
347
+ async #wrapActive(run) {
348
+ return await this.#runCtx.internalKeepAwake(run);
349
+ }
350
+ // Records that a step context was used outside its step. Mirrors the value
351
+ // onto actor state and a KV flag so callers can observe the violation.
352
+ #markGuardTriggered() {
353
+ try {
354
+ const state = this.#runCtx.state;
355
+ if (state && typeof state === "object" && "guardTriggered" in state) {
356
+ state.guardTriggered = true;
357
+ }
358
+ } catch (e2) {
359
+ }
360
+ this.#runCtx.waitUntil(
361
+ (async () => {
362
+ try {
363
+ await this.#runCtx.kv.put(WORKFLOW_GUARD_KV_KEY, "true");
364
+ } catch (error) {
365
+ this.#runCtx.log.error({
366
+ msg: "failed to persist workflow guard flag",
367
+ error
368
+ });
369
+ }
370
+ })()
371
+ );
372
+ }
373
+ #createChildContext(ctx) {
374
+ return new _WorkflowContext(ctx, this.#runCtx);
375
+ }
376
+ };
377
+
36
378
  // src/workflow/driver.ts
37
- var WORKFLOW_STORAGE_PREFIX = _chunkLLD2D5LOcjs.workflowStoragePrefix.call(void 0, );
379
+ var WORKFLOW_STORAGE_PREFIX = _chunkVE2X4KMGcjs.workflowStoragePrefix.call(void 0, );
38
380
  function stripWorkflowKey(prefixed) {
39
381
  return prefixed.slice(WORKFLOW_STORAGE_PREFIX.length);
40
382
  }
@@ -91,7 +433,7 @@ var ActorWorkflowMessageDriver = class {
91
433
  let parsedId;
92
434
  try {
93
435
  parsedId = BigInt(messageId);
94
- } catch (e) {
436
+ } catch (e3) {
95
437
  return;
96
438
  }
97
439
  await this.#runCtx.internalKeepAwake(
@@ -112,7 +454,7 @@ var ActorWorkflowDriver = (_class = class {
112
454
  async get(key) {
113
455
  const [value] = await this.#runCtx.internalKeepAwake(
114
456
  this.#actor.driver.kvBatchGet(this.#actor.id, [
115
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, key)
457
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key)
116
458
  ])
117
459
  );
118
460
  return _nullishCoalesce(value, () => ( null));
@@ -120,19 +462,19 @@ var ActorWorkflowDriver = (_class = class {
120
462
  async set(key, value) {
121
463
  await this.#runCtx.internalKeepAwake(
122
464
  this.#actor.driver.kvBatchPut(this.#actor.id, [
123
- [_chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, key), value]
465
+ [_chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key), value]
124
466
  ])
125
467
  );
126
468
  }
127
469
  async delete(key) {
128
470
  await this.#runCtx.internalKeepAwake(
129
471
  this.#actor.driver.kvBatchDelete(this.#actor.id, [
130
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, key)
472
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key)
131
473
  ])
132
474
  );
133
475
  }
134
476
  async deletePrefix(prefix) {
135
- const start = _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, prefix);
477
+ const start = _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, prefix);
136
478
  const end = computeUpperBound(start);
137
479
  if (end) {
138
480
  await this.#runCtx.internalKeepAwake(
@@ -157,8 +499,8 @@ var ActorWorkflowDriver = (_class = class {
157
499
  await this.#runCtx.internalKeepAwake(
158
500
  this.#actor.driver.kvDeleteRange(
159
501
  this.#actor.id,
160
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, start),
161
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, end)
502
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, start),
503
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, end)
162
504
  )
163
505
  );
164
506
  }
@@ -166,7 +508,7 @@ var ActorWorkflowDriver = (_class = class {
166
508
  const entries = await this.#runCtx.internalKeepAwake(
167
509
  this.#actor.driver.kvListPrefix(
168
510
  this.#actor.id,
169
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, prefix)
511
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, prefix)
170
512
  )
171
513
  );
172
514
  return entries.map(([key, value]) => ({
@@ -181,7 +523,7 @@ var ActorWorkflowDriver = (_class = class {
181
523
  this.#actor.driver.kvBatchPut(
182
524
  this.#actor.id,
183
525
  writes.map(({ key, value }) => [
184
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, key),
526
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key),
185
527
  value
186
528
  ])
187
529
  ),
@@ -226,22 +568,22 @@ var ActorWorkflowControlDriver = (_class2 = class {
226
568
  }
227
569
  async get(key) {
228
570
  const [value] = await this.#actor.driver.kvBatchGet(this.#actor.id, [
229
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, key)
571
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key)
230
572
  ]);
231
573
  return _nullishCoalesce(value, () => ( null));
232
574
  }
233
575
  async set(key, value) {
234
576
  await this.#actor.driver.kvBatchPut(this.#actor.id, [
235
- [_chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, key), value]
577
+ [_chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key), value]
236
578
  ]);
237
579
  }
238
580
  async delete(key) {
239
581
  await this.#actor.driver.kvBatchDelete(this.#actor.id, [
240
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, key)
582
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key)
241
583
  ]);
242
584
  }
243
585
  async deletePrefix(prefix) {
244
- const start = _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, prefix);
586
+ const start = _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, prefix);
245
587
  const end = computeUpperBound(start);
246
588
  if (end) {
247
589
  await this.#actor.driver.kvDeleteRange(this.#actor.id, start, end);
@@ -262,14 +604,14 @@ var ActorWorkflowControlDriver = (_class2 = class {
262
604
  async deleteRange(start, end) {
263
605
  await this.#actor.driver.kvDeleteRange(
264
606
  this.#actor.id,
265
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, start),
266
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, end)
607
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, start),
608
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, end)
267
609
  );
268
610
  }
269
611
  async list(prefix) {
270
612
  const entries = await this.#actor.driver.kvListPrefix(
271
613
  this.#actor.id,
272
- _chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, prefix)
614
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, prefix)
273
615
  );
274
616
  return entries.map(([key, value]) => ({
275
617
  key: stripWorkflowKey(key),
@@ -282,7 +624,7 @@ var ActorWorkflowControlDriver = (_class2 = class {
282
624
  }
283
625
  await this.#actor.driver.kvBatchPut(
284
626
  this.#actor.id,
285
- writes.map(({ key, value }) => [_chunkLLD2D5LOcjs.makeWorkflowKey.call(void 0, key), value])
627
+ writes.map(({ key, value }) => [_chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key), value])
286
628
  );
287
629
  }
288
630
  async setAlarm(_workflowId, wakeAt) {
@@ -296,293 +638,6 @@ var ActorWorkflowControlDriver = (_class2 = class {
296
638
  }
297
639
  }, _class2);
298
640
 
299
- // src/workflow/constants.ts
300
- var WORKFLOW_GUARD_KV_KEY = "__rivet_actor_workflow_guard_triggered";
301
-
302
- // src/workflow/context.ts
303
- var ActorWorkflowContext = class _ActorWorkflowContext {
304
- #inner;
305
- #runCtx;
306
- #actorAccessDepth = 0;
307
- #allowActorAccess = false;
308
- #guardViolation = false;
309
- constructor(inner, runCtx) {
310
- this.#inner = inner;
311
- this.#runCtx = runCtx;
312
- }
313
- get workflowId() {
314
- return this.#inner.workflowId;
315
- }
316
- get abortSignal() {
317
- return this.#inner.abortSignal;
318
- }
319
- get queue() {
320
- const self = this;
321
- async function next(name, opts) {
322
- const message = await self.#inner.queue.next(name, opts);
323
- return self.#toActorQueueMessage(message);
324
- }
325
- async function nextBatch(name, opts) {
326
- const messages = await self.#inner.queue.nextBatch(name, opts);
327
- return messages.map(
328
- (message) => self.#toActorQueueMessage(message)
329
- );
330
- }
331
- async function send(name, body) {
332
- self.#ensureActorAccess("queue.send");
333
- await self.#runCtx.queue.send(name, body);
334
- }
335
- return {
336
- next,
337
- nextBatch,
338
- send
339
- };
340
- }
341
- async step(nameOrConfig, run) {
342
- if (typeof nameOrConfig === "string") {
343
- if (!run) {
344
- throw new Error("Step run function missing");
345
- }
346
- return await this.#wrapActive(
347
- () => this.#inner.step(
348
- nameOrConfig,
349
- () => this.#withActorAccess(run)
350
- )
351
- );
352
- }
353
- const stepConfig = nameOrConfig;
354
- const config = {
355
- ...stepConfig,
356
- run: () => this.#withActorAccess(stepConfig.run)
357
- };
358
- return await this.#wrapActive(() => this.#inner.step(config));
359
- }
360
- async tryStep(nameOrConfig, run) {
361
- if (typeof nameOrConfig === "string") {
362
- if (!run) {
363
- throw new Error("Step run function missing");
364
- }
365
- return await this.#wrapActive(
366
- () => this.#inner.tryStep(
367
- nameOrConfig,
368
- () => this.#withActorAccess(run)
369
- )
370
- );
371
- }
372
- const stepConfig = nameOrConfig;
373
- const config = {
374
- ...stepConfig,
375
- run: () => this.#withActorAccess(stepConfig.run)
376
- };
377
- return await this.#wrapActive(() => this.#inner.tryStep(config));
378
- }
379
- async try(nameOrConfig, run) {
380
- if (typeof nameOrConfig === "string") {
381
- if (!run) {
382
- throw new Error("Try run function missing");
383
- }
384
- return await this.#wrapActive(
385
- () => this.#inner.try(
386
- nameOrConfig,
387
- async (ctx) => run(this.#createChildContext(ctx))
388
- )
389
- );
390
- }
391
- const tryConfig = nameOrConfig;
392
- const config = {
393
- ...tryConfig,
394
- run: async (ctx) => tryConfig.run(this.#createChildContext(ctx))
395
- };
396
- return await this.#wrapActive(() => this.#inner.try(config));
397
- }
398
- async loop(nameOrConfig, run) {
399
- if (typeof nameOrConfig === "string") {
400
- if (!run) {
401
- throw new Error("Loop run function missing");
402
- }
403
- return await this.#wrapActive(
404
- () => this.#inner.loop(
405
- nameOrConfig,
406
- async (ctx) => run(this.#createChildContext(ctx))
407
- )
408
- );
409
- }
410
- const wrapped = {
411
- ...nameOrConfig,
412
- run: async (ctx, state) => nameOrConfig.run(this.#createChildContext(ctx), state)
413
- };
414
- return await this.#wrapActive(() => this.#inner.loop(wrapped));
415
- }
416
- sleep(name, durationMs) {
417
- return this.#inner.sleep(name, durationMs);
418
- }
419
- sleepUntil(name, timestampMs) {
420
- return this.#inner.sleepUntil(name, timestampMs);
421
- }
422
- destroy() {
423
- this.#ensureActorAccess("destroy");
424
- this.#runCtx.destroy();
425
- }
426
- async rollbackCheckpoint(name) {
427
- await this.#wrapActive(() => this.#inner.rollbackCheckpoint(name));
428
- }
429
- async join(name, branches) {
430
- const wrappedBranches = Object.fromEntries(
431
- Object.entries(branches).map(([key, branch]) => [
432
- key,
433
- {
434
- run: async (ctx) => branch.run(this.#createChildContext(ctx))
435
- }
436
- ])
437
- );
438
- return await this.#wrapActive(
439
- () => this.#inner.join(name, wrappedBranches)
440
- );
441
- }
442
- async race(name, branches) {
443
- const wrappedBranches = branches.map((branch) => ({
444
- name: branch.name,
445
- run: (ctx) => branch.run(this.#createChildContext(ctx))
446
- }));
447
- return await this.#wrapActive(
448
- () => this.#inner.race(name, wrappedBranches)
449
- );
450
- }
451
- async removed(name, originalType) {
452
- await this.#wrapActive(() => this.#inner.removed(name, originalType));
453
- }
454
- isEvicted() {
455
- return this.#inner.isEvicted();
456
- }
457
- get state() {
458
- this.#ensureActorAccess("state");
459
- return this.#runCtx.state;
460
- }
461
- get vars() {
462
- this.#ensureActorAccess("vars");
463
- return this.#runCtx.vars;
464
- }
465
- client() {
466
- this.#ensureActorAccess("client");
467
- return this.#runCtx.client();
468
- }
469
- get db() {
470
- this.#ensureActorAccess("db");
471
- return this.#runCtx.db;
472
- }
473
- get log() {
474
- return this.#runCtx.log;
475
- }
476
- /** @deprecated No-op. Use `keepAwake(promise)` or `waitUntil(promise)` instead. */
477
- setPreventSleep(_prevent) {
478
- this.#ensureActorAccess("setPreventSleep");
479
- }
480
- /** @deprecated No-op. Always returns `false`. */
481
- get preventSleep() {
482
- this.#ensureActorAccess("preventSleep");
483
- return false;
484
- }
485
- /**
486
- * Holds the actor awake for the duration of the provided promise. The
487
- * actor cannot idle-sleep or finalize the sleep grace period until the
488
- * promise settles.
489
- */
490
- keepAwake(promise) {
491
- this.#ensureActorAccess("keepAwake");
492
- return this.#runCtx.keepAwake(promise);
493
- }
494
- /**
495
- * Registers a promise that the sleep grace period will wait on. Use this
496
- * for best-effort flush/cleanup work that may complete inside the grace
497
- * window. For work the actor must stay running through, prefer
498
- * `c.keepAwake(promise)` which also blocks idle sleep.
499
- */
500
- waitUntil(promise) {
501
- this.#ensureActorAccess("waitUntil");
502
- this.#runCtx.waitUntil(promise);
503
- }
504
- get actorId() {
505
- return this.#runCtx.actorId;
506
- }
507
- broadcast(name, ...args) {
508
- this.#ensureActorAccess("broadcast");
509
- this.#runCtx.broadcast(
510
- name,
511
- ...args
512
- );
513
- }
514
- #toActorQueueMessage(message) {
515
- let id;
516
- try {
517
- id = BigInt(message.id);
518
- } catch (e2) {
519
- throw new Error(`Invalid queue message id "${message.id}"`);
520
- }
521
- return {
522
- id,
523
- name: message.name,
524
- body: message.body,
525
- createdAt: message.createdAt,
526
- ...message.complete ? { complete: message.complete } : {}
527
- };
528
- }
529
- async #wrapActive(run) {
530
- return await this.#runCtx.internalKeepAwake(run);
531
- }
532
- async #withActorAccess(run) {
533
- this.#actorAccessDepth++;
534
- if (this.#actorAccessDepth === 1) {
535
- this.#allowActorAccess = true;
536
- }
537
- try {
538
- return await run();
539
- } finally {
540
- this.#actorAccessDepth--;
541
- if (this.#actorAccessDepth === 0) {
542
- this.#allowActorAccess = false;
543
- }
544
- }
545
- }
546
- #ensureActorAccess(feature) {
547
- if (!this.#allowActorAccess) {
548
- this.#guardViolation = true;
549
- this.#markGuardTriggered();
550
- throw new Error(
551
- `${feature} is only available inside workflow steps`
552
- );
553
- }
554
- }
555
- consumeGuardViolation() {
556
- const violated = this.#guardViolation;
557
- this.#guardViolation = false;
558
- return violated;
559
- }
560
- #markGuardTriggered() {
561
- try {
562
- const state = this.#runCtx.state;
563
- if (state && typeof state === "object" && "guardTriggered" in state) {
564
- state.guardTriggered = true;
565
- }
566
- } catch (e3) {
567
- }
568
- this.#runCtx.waitUntil(
569
- (async () => {
570
- try {
571
- await this.#runCtx.kv.put(WORKFLOW_GUARD_KV_KEY, "true");
572
- } catch (error) {
573
- this.#runCtx.log.error({
574
- msg: "failed to persist workflow guard flag",
575
- error
576
- });
577
- }
578
- })()
579
- );
580
- }
581
- #createChildContext(ctx) {
582
- return new _ActorWorkflowContext(ctx, this.#runCtx);
583
- }
584
- };
585
-
586
641
  // src/workflow/mod.ts
587
642
 
588
643
  function shouldRethrowWorkflowError(error) {
@@ -595,7 +650,7 @@ function shouldRethrowWorkflowError(error) {
595
650
  return true;
596
651
  }
597
652
  function workflowReplayInFlightError() {
598
- return new (0, _chunkV3QNBJ7Ncjs.RivetError)(
653
+ return new (0, _chunk4FC7TVS6cjs.RivetError)(
599
654
  "actor",
600
655
  "workflow_in_flight",
601
656
  "Workflow replay is unavailable while the workflow is currently in flight.",
@@ -614,13 +669,13 @@ function workflow(fn, options = {}) {
614
669
  function getWorkflowInspector(actorId) {
615
670
  let workflowInspector = workflowInspectors.get(actorId);
616
671
  if (!workflowInspector) {
617
- workflowInspector = _chunkNFC5VU36cjs.createWorkflowInspectorAdapter.call(void 0, );
672
+ workflowInspector = _chunk3GC3EP6Dcjs.createWorkflowInspectorAdapter.call(void 0, );
618
673
  workflowInspectors.set(actorId, workflowInspector);
619
674
  }
620
675
  return workflowInspector;
621
676
  }
622
677
  async function run(runCtx) {
623
- const actor = runCtx[_chunkAK57AL7Scjs.ACTOR_CONTEXT_INTERNAL_SYMBOL];
678
+ const actor = runCtx[_chunkOAPVVVTXcjs.ACTOR_CONTEXT_INTERNAL_SYMBOL];
624
679
  _invariant2.default.call(void 0, actor, "workflow() requires an actor instance");
625
680
  const workflowInspector = getWorkflowInspector(actor.id);
626
681
  const driver = new ActorWorkflowDriver(actor, runCtx);
@@ -650,11 +705,13 @@ function workflow(fn, options = {}) {
650
705
  });
651
706
  const handle = _workflowengine.runWorkflow.call(void 0,
652
707
  actor.id,
653
- async (ctx) => await fn(new ActorWorkflowContext(ctx, runCtx)),
708
+ async (ctx) => await fn(new WorkflowContext(ctx, runCtx)),
654
709
  void 0,
655
710
  driver,
656
711
  {
657
712
  mode: "live",
713
+ // The actor logger and the engine's pino logger are runtime
714
+ // compatible but not structurally assignable.
658
715
  logger: runCtx.log,
659
716
  onHistoryUpdated: workflowInspector.update,
660
717
  onError: onError ? async (event) => await onError(runCtx, event) : void 0
@@ -674,27 +731,33 @@ function workflow(fn, options = {}) {
674
731
  try {
675
732
  await handle.result;
676
733
  } catch (error) {
677
- if (runCtx.abortSignal.aborted) {
734
+ if (runCtx.abortSignal.aborted || _chunk4FC7TVS6cjs.isActorAbortedError.call(void 0, error)) {
678
735
  return;
679
736
  }
680
737
  if (shouldRethrowWorkflowError(error)) {
681
738
  runCtx.log.error({
682
739
  msg: "workflow run failed",
683
- error: _chunkXNZR7UD2cjs.stringifyError.call(void 0, error)
740
+ error: _chunkPRXTIEROcjs.stringifyError.call(void 0, error)
684
741
  });
685
742
  throw error;
686
743
  }
687
744
  runCtx.log.warn({
688
745
  msg: "workflow failed and will sleep until woken",
689
- error: _chunkXNZR7UD2cjs.stringifyError.call(void 0, error)
746
+ error: _chunkPRXTIEROcjs.stringifyError.call(void 0, error)
690
747
  });
691
748
  } finally {
692
749
  runCtx.abortSignal.removeEventListener("abort", onAbort);
693
750
  }
694
751
  }
695
752
  const runWithConfig = run;
696
- runWithConfig[_chunkAK57AL7Scjs.RUN_FUNCTION_CONFIG_SYMBOL] = {
753
+ runWithConfig[_chunkOAPVVVTXcjs.RUN_FUNCTION_CONFIG_SYMBOL] = {
697
754
  icon: "diagram-project",
755
+ // Drop the per-actor inspector when the actor is destroyed so this map
756
+ // does not retain one inspector (and its encoded history) per actor id
757
+ // for the process lifetime.
758
+ disposeInspector: (actorId) => {
759
+ workflowInspectors.delete(actorId);
760
+ },
698
761
  inspectorFactory: (actor) => {
699
762
  const actorId = resolveWorkflowInspectorActorId(actor);
700
763
  return {
@@ -729,5 +792,6 @@ function resolveWorkflowInspectorActorId(actor) {
729
792
 
730
793
 
731
794
 
732
- exports.ActorWorkflowContext = ActorWorkflowContext; exports.Loop = _workflowengine.Loop; exports.workflow = workflow;
795
+
796
+ exports.Loop = _workflowengine.Loop; exports.WorkflowContext = WorkflowContext; exports.WorkflowStepContext = WorkflowStepContext; exports.workflow = workflow;
733
797
  //# sourceMappingURL=mod.cjs.map