rivetkit 2.0.42 → 2.1.0-rc.1

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/{tsup/config-CLnylLYY.d.ts → browser/client.d.ts} +2127 -1910
  2. package/dist/browser/client.js +5182 -0
  3. package/dist/browser/client.js.map +1 -0
  4. package/dist/browser/inspector/client.d.ts +130 -0
  5. package/dist/browser/inspector/client.js +2854 -0
  6. package/dist/browser/inspector/client.js.map +1 -0
  7. package/dist/browser/v3-DnYObHH3.d.ts +279 -0
  8. package/dist/schemas/actor-inspector/v2.ts +796 -0
  9. package/dist/schemas/actor-inspector/v3.ts +899 -0
  10. package/dist/schemas/actor-persist/v4.ts +406 -0
  11. package/dist/schemas/client-protocol/v3.ts +554 -0
  12. package/dist/schemas/persist/v1.ts +781 -0
  13. package/dist/schemas/transport/v1.ts +697 -0
  14. package/dist/tsup/actor/errors.cjs +27 -3
  15. package/dist/tsup/actor/errors.cjs.map +1 -1
  16. package/dist/tsup/actor/errors.d.cts +37 -1
  17. package/dist/tsup/actor/errors.d.ts +37 -1
  18. package/dist/tsup/actor/errors.js +26 -1
  19. package/dist/tsup/{actor-router-consts-DzI2szci.d.cts → actor-router-consts-D29T1Z-K.d.cts} +1 -1
  20. package/dist/tsup/{actor-router-consts-DzI2szci.d.ts → actor-router-consts-D29T1Z-K.d.ts} +1 -1
  21. package/dist/tsup/chunk-424PT5DM.js +23 -0
  22. package/dist/tsup/chunk-424PT5DM.js.map +1 -0
  23. package/dist/tsup/{chunk-JDAD2YFA.js → chunk-5ESWDTHJ.js} +148 -273
  24. package/dist/tsup/chunk-5ESWDTHJ.js.map +1 -0
  25. package/dist/tsup/{chunk-FJ3KTN4V.js → chunk-6LIBPELE.js} +119 -11
  26. package/dist/tsup/chunk-6LIBPELE.js.map +1 -0
  27. package/dist/tsup/chunk-6LJAZ5R4.cjs +96 -0
  28. package/dist/tsup/chunk-6LJAZ5R4.cjs.map +1 -0
  29. package/dist/tsup/{chunk-LFVF5SCU.js → chunk-7HTNH26M.js} +126 -1
  30. package/dist/tsup/chunk-7HTNH26M.js.map +1 -0
  31. package/dist/tsup/chunk-7K4CYDGD.js +630 -0
  32. package/dist/tsup/chunk-7K4CYDGD.js.map +1 -0
  33. package/dist/tsup/{chunk-XXGJCOL6.js → chunk-A6YIZWTK.js} +2 -2
  34. package/dist/tsup/chunk-AIYEYMX5.cjs +630 -0
  35. package/dist/tsup/chunk-AIYEYMX5.cjs.map +1 -0
  36. package/dist/tsup/{chunk-Q6W7RJJP.js → chunk-DIGBC2VI.js} +211 -2316
  37. package/dist/tsup/chunk-DIGBC2VI.js.map +1 -0
  38. package/dist/tsup/{chunk-RZW2DNND.cjs → chunk-F6JYU5IK.cjs} +1957 -1039
  39. package/dist/tsup/chunk-F6JYU5IK.cjs.map +1 -0
  40. package/dist/tsup/chunk-HAZL2EPK.cjs +534 -0
  41. package/dist/tsup/chunk-HAZL2EPK.cjs.map +1 -0
  42. package/dist/tsup/chunk-HDQ2JUQT.cjs +23 -0
  43. package/dist/tsup/chunk-HDQ2JUQT.cjs.map +1 -0
  44. package/dist/tsup/chunk-HIDX4C5Y.cjs +1036 -0
  45. package/dist/tsup/chunk-HIDX4C5Y.cjs.map +1 -0
  46. package/dist/tsup/chunk-IVG73YCW.js +534 -0
  47. package/dist/tsup/chunk-IVG73YCW.js.map +1 -0
  48. package/dist/tsup/chunk-KJSYAUOM.js +96 -0
  49. package/dist/tsup/chunk-KJSYAUOM.js.map +1 -0
  50. package/dist/tsup/{chunk-2XQS746M.cjs → chunk-L47L3ZWJ.cjs} +127 -2
  51. package/dist/tsup/chunk-L47L3ZWJ.cjs.map +1 -0
  52. package/dist/tsup/{chunk-H4TB4X25.cjs → chunk-LW6KLR7A.cjs} +126 -18
  53. package/dist/tsup/chunk-LW6KLR7A.cjs.map +1 -0
  54. package/dist/tsup/chunk-LXUQ667X.js +2006 -0
  55. package/dist/tsup/chunk-LXUQ667X.js.map +1 -0
  56. package/dist/tsup/{chunk-GMAVRZSF.js → chunk-M2T62AZQ.js} +1790 -872
  57. package/dist/tsup/chunk-M2T62AZQ.js.map +1 -0
  58. package/dist/tsup/chunk-MZ37VV3P.js +5974 -0
  59. package/dist/tsup/chunk-MZ37VV3P.js.map +1 -0
  60. package/dist/tsup/chunk-N4KRDJ56.js +72 -0
  61. package/dist/tsup/chunk-N4KRDJ56.js.map +1 -0
  62. package/dist/tsup/chunk-NIYZDWMW.cjs +2006 -0
  63. package/dist/tsup/chunk-NIYZDWMW.cjs.map +1 -0
  64. package/dist/tsup/chunk-OMEPCQK2.js +649 -0
  65. package/dist/tsup/chunk-OMEPCQK2.js.map +1 -0
  66. package/dist/tsup/chunk-SR3KQE7Q.cjs +72 -0
  67. package/dist/tsup/chunk-SR3KQE7Q.cjs.map +1 -0
  68. package/dist/tsup/chunk-SSEP6DHP.cjs +2657 -0
  69. package/dist/tsup/chunk-SSEP6DHP.cjs.map +1 -0
  70. package/dist/tsup/chunk-T5YCUGVS.js +1036 -0
  71. package/dist/tsup/chunk-T5YCUGVS.js.map +1 -0
  72. package/dist/tsup/{chunk-EJVBH5VF.cjs → chunk-TPGXWFQT.cjs} +3 -3
  73. package/dist/tsup/{chunk-EJVBH5VF.cjs.map → chunk-TPGXWFQT.cjs.map} +1 -1
  74. package/dist/tsup/{chunk-X35U3YNX.cjs → chunk-TYLXNCA5.cjs} +214 -339
  75. package/dist/tsup/chunk-TYLXNCA5.cjs.map +1 -0
  76. package/dist/tsup/chunk-VKVNIQRQ.js +257 -0
  77. package/dist/tsup/chunk-VKVNIQRQ.js.map +1 -0
  78. package/dist/tsup/chunk-XWBAQO5H.cjs +649 -0
  79. package/dist/tsup/chunk-XWBAQO5H.cjs.map +1 -0
  80. package/dist/tsup/chunk-YQ4LDVD6.cjs +5974 -0
  81. package/dist/tsup/chunk-YQ4LDVD6.cjs.map +1 -0
  82. package/dist/tsup/chunk-ZFY5J2EP.cjs +257 -0
  83. package/dist/tsup/chunk-ZFY5J2EP.cjs.map +1 -0
  84. package/dist/tsup/client/mod.cjs +9 -10
  85. package/dist/tsup/client/mod.cjs.map +1 -1
  86. package/dist/tsup/client/mod.d.cts +11 -5
  87. package/dist/tsup/client/mod.d.ts +11 -5
  88. package/dist/tsup/client/mod.js +8 -8
  89. package/dist/tsup/common/log.cjs +4 -4
  90. package/dist/tsup/common/log.d.cts +2 -2
  91. package/dist/tsup/common/log.d.ts +2 -2
  92. package/dist/tsup/common/log.js +3 -2
  93. package/dist/tsup/common/websocket.cjs +5 -5
  94. package/dist/tsup/common/websocket.js +4 -3
  95. package/dist/tsup/config-BFqid9Gr.d.ts +2574 -0
  96. package/dist/tsup/config-BiNoIHRs.d.cts +80 -0
  97. package/dist/tsup/config-BiNoIHRs.d.ts +80 -0
  98. package/dist/tsup/{config-CZB2-W8x.d.cts → config-CAZphOS1.d.cts} +681 -355
  99. package/dist/tsup/db/drizzle/mod.cjs +49 -0
  100. package/dist/tsup/db/drizzle/mod.cjs.map +1 -0
  101. package/dist/tsup/db/drizzle/mod.d.cts +17 -0
  102. package/dist/tsup/db/drizzle/mod.d.ts +17 -0
  103. package/dist/tsup/db/drizzle/mod.js +49 -0
  104. package/dist/tsup/db/drizzle/mod.js.map +1 -0
  105. package/dist/tsup/db/mod.cjs +9 -0
  106. package/dist/tsup/db/mod.cjs.map +1 -0
  107. package/dist/tsup/db/mod.d.cts +9 -0
  108. package/dist/tsup/db/mod.d.ts +9 -0
  109. package/dist/tsup/db/mod.js +9 -0
  110. package/dist/tsup/db/mod.js.map +1 -0
  111. package/dist/tsup/{driver-D0QX9M11.d.ts → driver-Bxv62E2p.d.ts} +2 -2
  112. package/dist/tsup/{driver-q-zqG7fc.d.cts → driver-DYXwJR5D.d.cts} +2 -2
  113. package/dist/tsup/driver-helpers/mod.cjs +12 -6
  114. package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
  115. package/dist/tsup/driver-helpers/mod.d.cts +12 -5
  116. package/dist/tsup/driver-helpers/mod.d.ts +12 -5
  117. package/dist/tsup/driver-helpers/mod.js +12 -5
  118. package/dist/tsup/driver-test-suite/mod.cjs +1370 -116
  119. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  120. package/dist/tsup/driver-test-suite/mod.d.cts +10 -4
  121. package/dist/tsup/driver-test-suite/mod.d.ts +10 -4
  122. package/dist/tsup/driver-test-suite/mod.js +2093 -838
  123. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  124. package/dist/tsup/inspector/mod.cjs +29 -3
  125. package/dist/tsup/inspector/mod.cjs.map +1 -1
  126. package/dist/tsup/inspector/mod.d.cts +124 -3
  127. package/dist/tsup/inspector/mod.d.ts +124 -3
  128. package/dist/tsup/inspector/mod.js +72 -45
  129. package/dist/tsup/keys-CydblqMh.d.cts +13 -0
  130. package/dist/tsup/keys-CydblqMh.d.ts +13 -0
  131. package/dist/tsup/mod.cjs +16 -10
  132. package/dist/tsup/mod.cjs.map +1 -1
  133. package/dist/tsup/mod.d.cts +26 -14
  134. package/dist/tsup/mod.d.ts +26 -14
  135. package/dist/tsup/mod.js +20 -13
  136. package/dist/tsup/serve-test-suite/mod.cjs +1165 -83
  137. package/dist/tsup/serve-test-suite/mod.cjs.map +1 -1
  138. package/dist/tsup/serve-test-suite/mod.js +1114 -29
  139. package/dist/tsup/serve-test-suite/mod.js.map +1 -1
  140. package/dist/tsup/test/mod.cjs +84 -11
  141. package/dist/tsup/test/mod.cjs.map +1 -1
  142. package/dist/tsup/test/mod.d.cts +10 -5
  143. package/dist/tsup/test/mod.d.ts +10 -5
  144. package/dist/tsup/test/mod.js +85 -11
  145. package/dist/tsup/test/mod.js.map +1 -1
  146. package/dist/tsup/utils.cjs +10 -4
  147. package/dist/tsup/utils.cjs.map +1 -1
  148. package/dist/tsup/utils.d.cts +72 -2
  149. package/dist/tsup/utils.d.ts +72 -2
  150. package/dist/tsup/utils.js +9 -2
  151. package/dist/tsup/v3-DnYObHH3.d.cts +279 -0
  152. package/dist/tsup/v3-DnYObHH3.d.ts +279 -0
  153. package/dist/tsup/workflow/mod.cjs +16 -0
  154. package/dist/tsup/workflow/mod.cjs.map +1 -0
  155. package/dist/tsup/workflow/mod.d.cts +83 -0
  156. package/dist/tsup/workflow/mod.d.ts +83 -0
  157. package/dist/tsup/workflow/mod.js +16 -0
  158. package/dist/tsup/workflow/mod.js.map +1 -0
  159. package/package.json +62 -5
  160. package/src/actor/config.ts +478 -68
  161. package/src/actor/conn/mod.ts +68 -16
  162. package/src/actor/conn/state-manager.ts +2 -2
  163. package/src/actor/contexts/action.ts +20 -12
  164. package/src/actor/contexts/base/actor.ts +137 -7
  165. package/src/actor/contexts/base/conn-init.ts +27 -7
  166. package/src/actor/contexts/base/conn.ts +27 -18
  167. package/src/actor/contexts/before-action-response.ts +9 -2
  168. package/src/actor/contexts/before-connect.ts +7 -2
  169. package/src/actor/contexts/connect.ts +9 -2
  170. package/src/actor/contexts/create-conn-state.ts +7 -2
  171. package/src/actor/contexts/create-vars.ts +16 -3
  172. package/src/actor/contexts/create.ts +16 -3
  173. package/src/actor/contexts/destroy.ts +9 -3
  174. package/src/actor/contexts/disconnect.ts +10 -4
  175. package/src/actor/contexts/index.ts +4 -3
  176. package/src/actor/contexts/request.ts +23 -6
  177. package/src/actor/contexts/run.ts +47 -0
  178. package/src/actor/contexts/sleep.ts +9 -3
  179. package/src/actor/contexts/state-change.ts +9 -3
  180. package/src/actor/contexts/wake.ts +9 -3
  181. package/src/actor/contexts/websocket.ts +23 -6
  182. package/src/actor/database.ts +8 -18
  183. package/src/actor/definition.ts +20 -6
  184. package/src/actor/driver.ts +32 -3
  185. package/src/actor/errors.ts +127 -0
  186. package/src/actor/instance/connection-manager.ts +183 -80
  187. package/src/actor/instance/event-manager.ts +26 -15
  188. package/src/actor/instance/keys.ts +117 -0
  189. package/src/actor/instance/mod.ts +784 -174
  190. package/src/actor/instance/queue-manager.ts +603 -0
  191. package/src/actor/instance/queue.ts +287 -0
  192. package/src/actor/instance/schedule-manager.ts +49 -7
  193. package/src/actor/instance/state-manager.ts +35 -11
  194. package/src/actor/instance/traces-driver.ts +128 -0
  195. package/src/actor/mod.ts +26 -2
  196. package/src/actor/protocol/old.ts +28 -13
  197. package/src/actor/protocol/serde.ts +1 -1
  198. package/src/actor/router-endpoints.ts +177 -21
  199. package/src/actor/router-websocket-endpoints.ts +18 -29
  200. package/src/actor/router.ts +177 -0
  201. package/src/actor/schema.ts +291 -0
  202. package/src/actor/utils.ts +40 -0
  203. package/src/client/actor-common.ts +1 -1
  204. package/src/client/actor-conn.ts +100 -33
  205. package/src/client/actor-handle.ts +61 -33
  206. package/src/client/client.ts +2 -4
  207. package/src/client/config.ts +1 -1
  208. package/src/client/mod.browser.ts +2 -0
  209. package/src/client/mod.ts +1 -4
  210. package/src/client/queue.ts +146 -0
  211. package/src/client/utils.ts +1 -1
  212. package/src/common/log.ts +1 -1
  213. package/src/common/utils.ts +3 -3
  214. package/src/db/config.ts +100 -0
  215. package/src/db/drizzle/mod.ts +226 -0
  216. package/src/db/drizzle/sqlite-core.ts +22 -0
  217. package/src/db/mod.ts +125 -0
  218. package/src/db/shared.ts +92 -0
  219. package/src/db/sqlite-vfs.ts +12 -0
  220. package/src/driver-helpers/mod.ts +1 -0
  221. package/src/driver-test-suite/mod.ts +69 -43
  222. package/src/driver-test-suite/tests/access-control.ts +218 -0
  223. package/src/driver-test-suite/tests/actor-db-raw.ts +73 -0
  224. package/src/driver-test-suite/tests/actor-db.ts +394 -0
  225. package/src/driver-test-suite/tests/actor-inspector.ts +259 -358
  226. package/src/driver-test-suite/tests/actor-kv.ts +41 -20
  227. package/src/driver-test-suite/tests/actor-queue.ts +324 -0
  228. package/src/driver-test-suite/tests/actor-run.ts +181 -0
  229. package/src/driver-test-suite/tests/actor-schedule.ts +5 -2
  230. package/src/driver-test-suite/tests/actor-sleep.ts +3 -3
  231. package/src/driver-test-suite/tests/actor-stateless.ts +70 -0
  232. package/src/driver-test-suite/tests/actor-workflow.ts +108 -0
  233. package/src/driver-test-suite/tests/manager-driver.ts +11 -0
  234. package/src/driver-test-suite/tests/raw-http-request-properties.ts +1 -1
  235. package/src/driver-test-suite/tests/raw-websocket.ts +12 -12
  236. package/src/drivers/default.ts +7 -2
  237. package/src/drivers/engine/actor-driver.ts +45 -37
  238. package/src/drivers/engine/config.ts +1 -1
  239. package/src/drivers/file-system/actor.ts +20 -2
  240. package/src/drivers/file-system/global-state.ts +569 -258
  241. package/src/drivers/file-system/kv-limits.ts +70 -0
  242. package/src/drivers/file-system/manager.ts +22 -6
  243. package/src/drivers/file-system/mod.ts +39 -16
  244. package/src/drivers/file-system/sqlite-runtime.ts +210 -0
  245. package/src/inspector/actor-inspector.ts +224 -102
  246. package/src/inspector/config.ts +1 -1
  247. package/src/inspector/handler.ts +102 -20
  248. package/src/inspector/mod.browser.ts +8 -0
  249. package/src/inspector/mod.ts +2 -0
  250. package/src/inspector/serve-ui.ts +40 -0
  251. package/src/inspector/transport.ts +18 -0
  252. package/src/inspector/utils.ts +5 -39
  253. package/src/manager/gateway.ts +1 -1
  254. package/src/manager/protocol/mod.ts +1 -1
  255. package/src/manager/protocol/query.ts +1 -1
  256. package/src/manager/router-schema.ts +1 -1
  257. package/src/manager/router.ts +38 -12
  258. package/src/manager-api/actors.ts +1 -1
  259. package/src/manager-api/common.ts +1 -1
  260. package/src/registry/config/driver.ts +1 -1
  261. package/src/registry/config/index.ts +212 -43
  262. package/src/registry/config/legacy-runner.ts +1 -1
  263. package/src/registry/config/runner.ts +1 -1
  264. package/src/registry/config/serverless.ts +1 -1
  265. package/src/registry/index.ts +7 -5
  266. package/src/remote-manager-driver/api-utils.ts +1 -1
  267. package/src/schemas/actor-inspector/mod.ts +1 -1
  268. package/src/schemas/actor-inspector/versioned.ts +195 -8
  269. package/src/schemas/actor-persist/versioned.ts +87 -7
  270. package/src/schemas/client-protocol/mod.ts +1 -1
  271. package/src/schemas/client-protocol/versioned.ts +127 -11
  272. package/src/schemas/client-protocol-zod/mod.ts +16 -1
  273. package/src/schemas/persist/mod.ts +1 -0
  274. package/src/schemas/transport/mod.ts +1 -0
  275. package/src/serde.ts +1 -1
  276. package/src/serve-test-suite/mod.ts +10 -9
  277. package/src/test/mod.ts +15 -56
  278. package/src/utils/endpoint-parser.test.ts +1 -1
  279. package/src/utils/endpoint-parser.ts +1 -1
  280. package/src/utils/env-vars.ts +12 -1
  281. package/src/utils/node.ts +15 -2
  282. package/src/utils.test.ts +34 -0
  283. package/src/utils.ts +140 -6
  284. package/src/workflow/constants.ts +2 -0
  285. package/src/workflow/context.ts +532 -0
  286. package/src/workflow/driver.ts +191 -0
  287. package/src/workflow/inspector.ts +268 -0
  288. package/src/workflow/mod.ts +122 -0
  289. package/dist/tsup/chunk-2IJTYN6K.cjs +0 -278
  290. package/dist/tsup/chunk-2IJTYN6K.cjs.map +0 -1
  291. package/dist/tsup/chunk-2XQS746M.cjs.map +0 -1
  292. package/dist/tsup/chunk-3VP5CSHV.cjs +0 -114
  293. package/dist/tsup/chunk-3VP5CSHV.cjs.map +0 -1
  294. package/dist/tsup/chunk-AQFSQMBG.js +0 -114
  295. package/dist/tsup/chunk-AQFSQMBG.js.map +0 -1
  296. package/dist/tsup/chunk-E6ZE2YEA.js +0 -664
  297. package/dist/tsup/chunk-E6ZE2YEA.js.map +0 -1
  298. package/dist/tsup/chunk-FJ3KTN4V.js.map +0 -1
  299. package/dist/tsup/chunk-GBENOENJ.cjs +0 -8
  300. package/dist/tsup/chunk-GBENOENJ.cjs.map +0 -1
  301. package/dist/tsup/chunk-GD7UXGOE.cjs +0 -4762
  302. package/dist/tsup/chunk-GD7UXGOE.cjs.map +0 -1
  303. package/dist/tsup/chunk-GMAVRZSF.js.map +0 -1
  304. package/dist/tsup/chunk-H4TB4X25.cjs.map +0 -1
  305. package/dist/tsup/chunk-JDAD2YFA.js.map +0 -1
  306. package/dist/tsup/chunk-KCOVZOPS.js +0 -1946
  307. package/dist/tsup/chunk-KCOVZOPS.js.map +0 -1
  308. package/dist/tsup/chunk-KDFWJKMJ.cjs +0 -664
  309. package/dist/tsup/chunk-KDFWJKMJ.cjs.map +0 -1
  310. package/dist/tsup/chunk-LFVF5SCU.js.map +0 -1
  311. package/dist/tsup/chunk-Q6W7RJJP.js.map +0 -1
  312. package/dist/tsup/chunk-RUW5CZ5Z.cjs +0 -1949
  313. package/dist/tsup/chunk-RUW5CZ5Z.cjs.map +0 -1
  314. package/dist/tsup/chunk-RZW2DNND.cjs.map +0 -1
  315. package/dist/tsup/chunk-TCOEBUUE.js +0 -278
  316. package/dist/tsup/chunk-TCOEBUUE.js.map +0 -1
  317. package/dist/tsup/chunk-X35U3YNX.cjs.map +0 -1
  318. package/dist/tsup/keys-Chhy4ylv.d.cts +0 -8
  319. package/dist/tsup/keys-Chhy4ylv.d.ts +0 -8
  320. package/dist/tsup/v1-Gq4avTK3.d.cts +0 -240
  321. package/dist/tsup/v1-Gq4avTK3.d.ts +0 -240
  322. /package/dist/tsup/{chunk-XXGJCOL6.js.map → chunk-A6YIZWTK.js.map} +0 -0
@@ -0,0 +1,630 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
+
3
+ var _chunkHAZL2EPKcjs = require('./chunk-HAZL2EPK.cjs');
4
+
5
+
6
+
7
+
8
+
9
+ var _chunkHIDX4C5Ycjs = require('./chunk-HIDX4C5Y.cjs');
10
+
11
+
12
+
13
+
14
+ var _chunkLW6KLR7Acjs = require('./chunk-LW6KLR7A.cjs');
15
+
16
+ // src/workflow/mod.ts
17
+ var _workflowengine = require('@rivetkit/workflow-engine');
18
+ var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);
19
+
20
+ // src/workflow/constants.ts
21
+ var WORKFLOW_GUARD_KV_KEY = "__rivet_actor_workflow_guard_triggered";
22
+
23
+ // src/workflow/context.ts
24
+ var ActorWorkflowContext = class _ActorWorkflowContext {
25
+ #inner;
26
+ #runCtx;
27
+ #actorAccessDepth = 0;
28
+ #allowActorAccess = false;
29
+ #guardViolation = false;
30
+ constructor(inner, runCtx) {
31
+ this.#inner = inner;
32
+ this.#runCtx = runCtx;
33
+ }
34
+ get workflowId() {
35
+ return this.#inner.workflowId;
36
+ }
37
+ get abortSignal() {
38
+ return this.#inner.abortSignal;
39
+ }
40
+ get queue() {
41
+ const self = this;
42
+ async function next(name, opts) {
43
+ const messages = await self.#inner.queue.next(name, opts);
44
+ return messages.map((message) => self.#toActorQueueMessage(message));
45
+ }
46
+ async function send(name, body) {
47
+ await self.#runCtx.queue.send(name, body);
48
+ }
49
+ return {
50
+ next,
51
+ send
52
+ };
53
+ }
54
+ async step(nameOrConfig, run) {
55
+ if (typeof nameOrConfig === "string") {
56
+ if (!run) {
57
+ throw new Error("Step run function missing");
58
+ }
59
+ return await this.#wrapActive(
60
+ () => this.#inner.step(nameOrConfig, () => this.#withActorAccess(run))
61
+ );
62
+ }
63
+ const stepConfig = nameOrConfig;
64
+ const config = {
65
+ ...stepConfig,
66
+ run: () => this.#withActorAccess(stepConfig.run)
67
+ };
68
+ return await this.#wrapActive(() => this.#inner.step(config));
69
+ }
70
+ async loop(nameOrConfig, run) {
71
+ if (typeof nameOrConfig === "string") {
72
+ if (!run) {
73
+ throw new Error("Loop run function missing");
74
+ }
75
+ return await this.#wrapActive(
76
+ () => this.#inner.loop(
77
+ nameOrConfig,
78
+ async (ctx) => run(this.#createChildContext(ctx))
79
+ )
80
+ );
81
+ }
82
+ const wrapped = {
83
+ ...nameOrConfig,
84
+ run: async (ctx, state) => nameOrConfig.run(this.#createChildContext(ctx), state)
85
+ };
86
+ return await this.#wrapActive(() => this.#inner.loop(wrapped));
87
+ }
88
+ sleep(name, durationMs) {
89
+ return this.#inner.sleep(name, durationMs);
90
+ }
91
+ sleepUntil(name, timestampMs) {
92
+ return this.#inner.sleepUntil(name, timestampMs);
93
+ }
94
+ async rollbackCheckpoint(name) {
95
+ await this.#wrapActive(() => this.#inner.rollbackCheckpoint(name));
96
+ }
97
+ async join(name, branches) {
98
+ const wrappedBranches = Object.fromEntries(
99
+ Object.entries(branches).map(([key, branch]) => [
100
+ key,
101
+ {
102
+ run: async (ctx) => branch.run(this.#createChildContext(ctx))
103
+ }
104
+ ])
105
+ );
106
+ return await this.#wrapActive(
107
+ () => this.#inner.join(name, wrappedBranches)
108
+ );
109
+ }
110
+ async race(name, branches) {
111
+ const wrappedBranches = branches.map((branch) => ({
112
+ name: branch.name,
113
+ run: (ctx) => branch.run(this.#createChildContext(ctx))
114
+ }));
115
+ return await this.#wrapActive(
116
+ () => this.#inner.race(name, wrappedBranches)
117
+ );
118
+ }
119
+ async removed(name, originalType) {
120
+ await this.#wrapActive(() => this.#inner.removed(name, originalType));
121
+ }
122
+ isEvicted() {
123
+ return this.#inner.isEvicted();
124
+ }
125
+ get state() {
126
+ this.#ensureActorAccess("state");
127
+ return this.#runCtx.state;
128
+ }
129
+ get vars() {
130
+ this.#ensureActorAccess("vars");
131
+ return this.#runCtx.vars;
132
+ }
133
+ client() {
134
+ this.#ensureActorAccess("client");
135
+ return this.#runCtx.client();
136
+ }
137
+ get db() {
138
+ this.#ensureActorAccess("db");
139
+ return this.#runCtx.db;
140
+ }
141
+ get log() {
142
+ return this.#runCtx.log;
143
+ }
144
+ keepAwake(promise) {
145
+ return this.#runCtx.keepAwake(promise);
146
+ }
147
+ waitUntil(promise) {
148
+ this.#runCtx.waitUntil(promise);
149
+ }
150
+ get actorId() {
151
+ return this.#runCtx.actorId;
152
+ }
153
+ broadcast(name, ...args) {
154
+ this.#runCtx.broadcast(
155
+ name,
156
+ ...args
157
+ );
158
+ }
159
+ #toActorQueueMessage(message) {
160
+ let id;
161
+ try {
162
+ id = BigInt(message.id);
163
+ } catch (e) {
164
+ throw new Error(`Invalid queue message id "${message.id}"`);
165
+ }
166
+ return {
167
+ id,
168
+ name: message.name,
169
+ body: message.body,
170
+ createdAt: message.createdAt,
171
+ ...message.complete ? { complete: message.complete } : {}
172
+ };
173
+ }
174
+ async #wrapActive(run) {
175
+ return await this.#runCtx.keepAwake(run());
176
+ }
177
+ async #withActorAccess(run) {
178
+ this.#actorAccessDepth++;
179
+ if (this.#actorAccessDepth === 1) {
180
+ this.#allowActorAccess = true;
181
+ }
182
+ try {
183
+ return await run();
184
+ } finally {
185
+ this.#actorAccessDepth--;
186
+ if (this.#actorAccessDepth === 0) {
187
+ this.#allowActorAccess = false;
188
+ }
189
+ }
190
+ }
191
+ #ensureActorAccess(feature) {
192
+ if (!this.#allowActorAccess) {
193
+ this.#guardViolation = true;
194
+ this.#markGuardTriggered();
195
+ throw new Error(
196
+ `${feature} is only available inside workflow steps`
197
+ );
198
+ }
199
+ }
200
+ consumeGuardViolation() {
201
+ const violated = this.#guardViolation;
202
+ this.#guardViolation = false;
203
+ return violated;
204
+ }
205
+ #markGuardTriggered() {
206
+ try {
207
+ const state = this.#runCtx.state;
208
+ if (state && typeof state === "object" && "guardTriggered" in state) {
209
+ state.guardTriggered = true;
210
+ }
211
+ } catch (e2) {
212
+ }
213
+ this.#runCtx.waitUntil(
214
+ (async () => {
215
+ try {
216
+ await this.#runCtx.kv.put(WORKFLOW_GUARD_KV_KEY, "true");
217
+ } catch (error) {
218
+ this.#runCtx.log.error({
219
+ msg: "failed to persist workflow guard flag",
220
+ error
221
+ });
222
+ }
223
+ })()
224
+ );
225
+ }
226
+ #createChildContext(ctx) {
227
+ return new _ActorWorkflowContext(ctx, this.#runCtx);
228
+ }
229
+ };
230
+
231
+ // src/workflow/driver.ts
232
+ var WORKFLOW_STORAGE_PREFIX = _chunkHIDX4C5Ycjs.workflowStoragePrefix.call(void 0, );
233
+ function stripWorkflowKey(prefixed) {
234
+ return prefixed.slice(WORKFLOW_STORAGE_PREFIX.length);
235
+ }
236
+ var ActorWorkflowMessageDriver = class {
237
+ #actor;
238
+ #runCtx;
239
+ constructor(actor, runCtx) {
240
+ this.#actor = actor;
241
+ this.#runCtx = runCtx;
242
+ }
243
+ async addMessage(message) {
244
+ await this.#runCtx.keepAwake(
245
+ this.#actor.queueManager.enqueue(message.name, message.data)
246
+ );
247
+ }
248
+ async receiveMessages(opts) {
249
+ const messages = await this.#runCtx.keepAwake(
250
+ this.#actor.queueManager.receive(
251
+ opts.names && opts.names.length > 0 ? [...opts.names] : void 0,
252
+ opts.count,
253
+ 0,
254
+ void 0,
255
+ opts.completable
256
+ )
257
+ );
258
+ return messages.map((message) => ({
259
+ id: message.id.toString(),
260
+ name: message.name,
261
+ data: message.body,
262
+ sentAt: message.createdAt,
263
+ ...opts.completable ? {
264
+ complete: async (response) => {
265
+ await this.#runCtx.keepAwake(
266
+ this.#actor.queueManager.completeMessage(
267
+ message,
268
+ response
269
+ )
270
+ );
271
+ }
272
+ } : {}
273
+ }));
274
+ }
275
+ async completeMessage(messageId, response) {
276
+ let parsedId;
277
+ try {
278
+ parsedId = BigInt(messageId);
279
+ } catch (e3) {
280
+ return;
281
+ }
282
+ await this.#runCtx.keepAwake(
283
+ this.#actor.queueManager.completeMessageById(parsedId, response)
284
+ );
285
+ }
286
+ };
287
+ var ActorWorkflowDriver = (_class = class {
288
+ __init() {this.workerPollInterval = 100}
289
+
290
+ #actor;
291
+ #runCtx;
292
+ constructor(actor, runCtx) {;_class.prototype.__init.call(this);
293
+ this.#actor = actor;
294
+ this.#runCtx = runCtx;
295
+ this.messageDriver = new ActorWorkflowMessageDriver(actor, runCtx);
296
+ }
297
+ async get(key) {
298
+ const [value] = await this.#runCtx.keepAwake(
299
+ this.#actor.driver.kvBatchGet(this.#actor.id, [
300
+ _chunkHIDX4C5Ycjs.makeWorkflowKey.call(void 0, key)
301
+ ])
302
+ );
303
+ return _nullishCoalesce(value, () => ( null));
304
+ }
305
+ async set(key, value) {
306
+ await this.#runCtx.keepAwake(
307
+ this.#actor.driver.kvBatchPut(this.#actor.id, [
308
+ [_chunkHIDX4C5Ycjs.makeWorkflowKey.call(void 0, key), value]
309
+ ])
310
+ );
311
+ }
312
+ async delete(key) {
313
+ await this.#runCtx.keepAwake(
314
+ this.#actor.driver.kvBatchDelete(this.#actor.id, [
315
+ _chunkHIDX4C5Ycjs.makeWorkflowKey.call(void 0, key)
316
+ ])
317
+ );
318
+ }
319
+ async deletePrefix(prefix) {
320
+ const entries = await this.#runCtx.keepAwake(
321
+ this.#actor.driver.kvListPrefix(
322
+ this.#actor.id,
323
+ _chunkHIDX4C5Ycjs.makeWorkflowKey.call(void 0, prefix)
324
+ )
325
+ );
326
+ if (entries.length === 0) {
327
+ return;
328
+ }
329
+ await this.#runCtx.keepAwake(
330
+ this.#actor.driver.kvBatchDelete(
331
+ this.#actor.id,
332
+ entries.map(([key]) => key)
333
+ )
334
+ );
335
+ }
336
+ async list(prefix) {
337
+ const entries = await this.#runCtx.keepAwake(
338
+ this.#actor.driver.kvListPrefix(
339
+ this.#actor.id,
340
+ _chunkHIDX4C5Ycjs.makeWorkflowKey.call(void 0, prefix)
341
+ )
342
+ );
343
+ return entries.map(([key, value]) => ({
344
+ key: stripWorkflowKey(key),
345
+ value
346
+ }));
347
+ }
348
+ async batch(writes) {
349
+ if (writes.length === 0) return;
350
+ await this.#runCtx.keepAwake(
351
+ Promise.all([
352
+ this.#actor.driver.kvBatchPut(
353
+ this.#actor.id,
354
+ writes.map(({ key, value }) => [_chunkHIDX4C5Ycjs.makeWorkflowKey.call(void 0, key), value])
355
+ ),
356
+ this.#actor.stateManager.saveState({ immediate: true })
357
+ ])
358
+ );
359
+ }
360
+ async setAlarm(_workflowId, wakeAt) {
361
+ await this.#runCtx.keepAwake(
362
+ this.#actor.driver.setAlarm(this.#actor, wakeAt)
363
+ );
364
+ }
365
+ async clearAlarm(_workflowId) {
366
+ return;
367
+ }
368
+ waitForMessages(messageNames, abortSignal) {
369
+ return this.#actor.queueManager.waitForNames(
370
+ messageNames.length > 0 ? messageNames : void 0,
371
+ abortSignal
372
+ );
373
+ }
374
+ }, _class);
375
+
376
+ // src/workflow/inspector.ts
377
+ var _cborx = require('cbor-x'); var cbor = _interopRequireWildcard(_cborx);
378
+ var _nanoevents = require('nanoevents');
379
+ function createWorkflowInspectorAdapter() {
380
+ const emitter = _nanoevents.createNanoEvents.call(void 0, );
381
+ let history = null;
382
+ const adapter = {
383
+ getHistory: () => history,
384
+ onHistoryUpdated: (listener) => emitter.on("updated", listener)
385
+ };
386
+ const update = (snapshot) => {
387
+ const transportHistory = toWorkflowHistory(snapshot);
388
+ const next = _chunkHAZL2EPKcjs.encodeWorkflowHistoryTransport.call(void 0, transportHistory);
389
+ history = next;
390
+ emitter.emit("updated", next);
391
+ };
392
+ return { adapter, update };
393
+ }
394
+ function encodeCbor(value) {
395
+ return _chunkLW6KLR7Acjs.bufferToArrayBuffer.call(void 0, cbor.encode(value));
396
+ }
397
+ function encodeOptionalCbor(value) {
398
+ if (value === void 0) {
399
+ return null;
400
+ }
401
+ return encodeCbor(value);
402
+ }
403
+ function toU64(value) {
404
+ return BigInt(Math.max(0, Math.floor(value)));
405
+ }
406
+ function toWorkflowLocation(location) {
407
+ return location.map((segment) => {
408
+ if (typeof segment === "number") {
409
+ return { tag: "WorkflowNameIndex", val: segment };
410
+ }
411
+ return {
412
+ tag: "WorkflowLoopIterationMarker",
413
+ val: {
414
+ loop: segment.loop,
415
+ iteration: segment.iteration
416
+ }
417
+ };
418
+ });
419
+ }
420
+ function toWorkflowEntryKind(kind) {
421
+ switch (kind.type) {
422
+ case "step":
423
+ return {
424
+ tag: "WorkflowStepEntry",
425
+ val: {
426
+ output: encodeOptionalCbor(kind.data.output),
427
+ error: _nullishCoalesce(kind.data.error, () => ( null))
428
+ }
429
+ };
430
+ case "loop":
431
+ return {
432
+ tag: "WorkflowLoopEntry",
433
+ val: {
434
+ state: encodeCbor(kind.data.state),
435
+ iteration: kind.data.iteration,
436
+ output: encodeOptionalCbor(kind.data.output)
437
+ }
438
+ };
439
+ case "sleep":
440
+ return {
441
+ tag: "WorkflowSleepEntry",
442
+ val: {
443
+ deadline: toU64(kind.data.deadline),
444
+ state: toWorkflowSleepState(kind.data.state)
445
+ }
446
+ };
447
+ case "message":
448
+ return {
449
+ tag: "WorkflowMessageEntry",
450
+ val: {
451
+ name: kind.data.name,
452
+ messageData: encodeCbor(kind.data.data)
453
+ }
454
+ };
455
+ case "rollback_checkpoint":
456
+ return {
457
+ tag: "WorkflowRollbackCheckpointEntry",
458
+ val: { name: kind.data.name }
459
+ };
460
+ case "join":
461
+ return {
462
+ tag: "WorkflowJoinEntry",
463
+ val: { branches: toWorkflowBranchStatusMap(kind.data.branches) }
464
+ };
465
+ case "race":
466
+ return {
467
+ tag: "WorkflowRaceEntry",
468
+ val: {
469
+ winner: _nullishCoalesce(kind.data.winner, () => ( null)),
470
+ branches: toWorkflowBranchStatusMap(kind.data.branches)
471
+ }
472
+ };
473
+ case "removed":
474
+ return {
475
+ tag: "WorkflowRemovedEntry",
476
+ val: {
477
+ originalType: kind.data.originalType,
478
+ originalName: _nullishCoalesce(kind.data.originalName, () => ( null))
479
+ }
480
+ };
481
+ default:
482
+ _chunkLW6KLR7Acjs.assertUnreachable.call(void 0, kind);
483
+ }
484
+ }
485
+ function toWorkflowEntry(entry) {
486
+ return {
487
+ id: entry.id,
488
+ location: toWorkflowLocation(entry.location),
489
+ kind: toWorkflowEntryKind(entry.kind)
490
+ };
491
+ }
492
+ function toWorkflowEntryStatus(status) {
493
+ switch (status) {
494
+ case "pending":
495
+ return "PENDING" /* PENDING */;
496
+ case "running":
497
+ return "RUNNING" /* RUNNING */;
498
+ case "completed":
499
+ return "COMPLETED" /* COMPLETED */;
500
+ case "failed":
501
+ return "FAILED" /* FAILED */;
502
+ case "exhausted":
503
+ return "EXHAUSTED" /* EXHAUSTED */;
504
+ default:
505
+ _chunkLW6KLR7Acjs.assertUnreachable.call(void 0, status);
506
+ }
507
+ }
508
+ function toWorkflowSleepState(state) {
509
+ switch (state) {
510
+ case "pending":
511
+ return "PENDING" /* PENDING */;
512
+ case "completed":
513
+ return "COMPLETED" /* COMPLETED */;
514
+ case "interrupted":
515
+ return "INTERRUPTED" /* INTERRUPTED */;
516
+ default:
517
+ _chunkLW6KLR7Acjs.assertUnreachable.call(void 0, state);
518
+ }
519
+ }
520
+ function toWorkflowBranchStatusType(status) {
521
+ switch (status) {
522
+ case "pending":
523
+ return "PENDING" /* PENDING */;
524
+ case "running":
525
+ return "RUNNING" /* RUNNING */;
526
+ case "completed":
527
+ return "COMPLETED" /* COMPLETED */;
528
+ case "failed":
529
+ return "FAILED" /* FAILED */;
530
+ case "cancelled":
531
+ return "CANCELLED" /* CANCELLED */;
532
+ default:
533
+ _chunkLW6KLR7Acjs.assertUnreachable.call(void 0, status);
534
+ }
535
+ }
536
+ function toWorkflowBranchStatus(status) {
537
+ return {
538
+ status: toWorkflowBranchStatusType(status.status),
539
+ output: encodeOptionalCbor(status.output),
540
+ error: _nullishCoalesce(status.error, () => ( null))
541
+ };
542
+ }
543
+ function toWorkflowBranchStatusMap(branches) {
544
+ return new Map(
545
+ Object.entries(branches).map(([name, status]) => [
546
+ name,
547
+ toWorkflowBranchStatus(status)
548
+ ])
549
+ );
550
+ }
551
+ function toWorkflowEntryMetadata(metadata) {
552
+ return {
553
+ status: toWorkflowEntryStatus(metadata.status),
554
+ error: _nullishCoalesce(metadata.error, () => ( null)),
555
+ attempts: metadata.attempts,
556
+ lastAttemptAt: toU64(metadata.lastAttemptAt),
557
+ createdAt: toU64(metadata.createdAt),
558
+ completedAt: metadata.completedAt === void 0 ? null : toU64(metadata.completedAt),
559
+ rollbackCompletedAt: metadata.rollbackCompletedAt === void 0 ? null : toU64(metadata.rollbackCompletedAt),
560
+ rollbackError: _nullishCoalesce(metadata.rollbackError, () => ( null))
561
+ };
562
+ }
563
+ function toWorkflowHistory(snapshot) {
564
+ const entryMetadata = /* @__PURE__ */ new Map();
565
+ for (const [id, metadata] of snapshot.entryMetadata) {
566
+ entryMetadata.set(id, toWorkflowEntryMetadata(metadata));
567
+ }
568
+ return {
569
+ nameRegistry: snapshot.nameRegistry,
570
+ entries: snapshot.entries.map((entry) => toWorkflowEntry(entry)),
571
+ entryMetadata
572
+ };
573
+ }
574
+
575
+ // src/workflow/mod.ts
576
+
577
+ function workflow(fn) {
578
+ const workflowInspector = createWorkflowInspectorAdapter();
579
+ async function run(runCtx) {
580
+ const actor = runCtx[_chunkHIDX4C5Ycjs.ACTOR_CONTEXT_INTERNAL_SYMBOL];
581
+ _invariant2.default.call(void 0, actor, "workflow() requires an actor instance");
582
+ const driver = new ActorWorkflowDriver(actor, runCtx);
583
+ const handle = _workflowengine.runWorkflow.call(void 0,
584
+ actor.id,
585
+ async (ctx) => await fn(new ActorWorkflowContext(ctx, runCtx)),
586
+ void 0,
587
+ driver,
588
+ {
589
+ mode: "live",
590
+ logger: runCtx.log,
591
+ onHistoryUpdated: workflowInspector.update
592
+ }
593
+ );
594
+ const onAbort = () => {
595
+ handle.evict();
596
+ };
597
+ if (runCtx.abortSignal.aborted) {
598
+ onAbort();
599
+ } else {
600
+ runCtx.abortSignal.addEventListener("abort", onAbort, {
601
+ once: true
602
+ });
603
+ }
604
+ try {
605
+ await handle.result;
606
+ } catch (error) {
607
+ runCtx.log.error({
608
+ msg: "workflow run failed",
609
+ error: _chunkLW6KLR7Acjs.stringifyError.call(void 0, error)
610
+ });
611
+ throw error;
612
+ } finally {
613
+ runCtx.abortSignal.removeEventListener("abort", onAbort);
614
+ }
615
+ }
616
+ const runWithConfig = run;
617
+ runWithConfig[_chunkHIDX4C5Ycjs.RUN_FUNCTION_CONFIG_SYMBOL] = {
618
+ icon: "diagram-project",
619
+ inspector: { workflow: workflowInspector.adapter }
620
+ };
621
+ return runWithConfig;
622
+ }
623
+
624
+
625
+
626
+
627
+
628
+
629
+ exports.WORKFLOW_GUARD_KV_KEY = WORKFLOW_GUARD_KV_KEY; exports.ActorWorkflowContext = ActorWorkflowContext; exports.workflow = workflow; exports.Loop = _workflowengine.Loop;
630
+ //# sourceMappingURL=chunk-AIYEYMX5.cjs.map