rivetkit 2.3.0-rc.8 → 2.3.0

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 (221) hide show
  1. package/dist/browser/client.d.ts +481 -74
  2. package/dist/browser/client.js +174 -148
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +47 -18
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +2 -2
  7. package/dist/tsup/actor/errors.d.cts +1 -1
  8. package/dist/tsup/actor/errors.d.ts +1 -1
  9. package/dist/tsup/actor/errors.js +1 -1
  10. package/dist/tsup/agent-os/index.cjs +2160 -2086
  11. package/dist/tsup/agent-os/index.cjs.map +1 -1
  12. package/dist/tsup/agent-os/index.d.cts +479 -73
  13. package/dist/tsup/agent-os/index.d.ts +479 -73
  14. package/dist/tsup/agent-os/index.js +2160 -2086
  15. package/dist/tsup/agent-os/index.js.map +1 -1
  16. package/dist/tsup/{chunk-KY3CERZR.js → chunk-2OTRTA3J.js} +7 -21
  17. package/dist/tsup/chunk-2OTRTA3J.js.map +1 -0
  18. package/dist/tsup/{chunk-HGW6PBWR.cjs → chunk-3677IIOV.cjs} +11 -25
  19. package/dist/tsup/chunk-3677IIOV.cjs.map +1 -0
  20. package/dist/tsup/{chunk-OT7FF6GB.cjs → chunk-47HHIEXH.cjs} +24 -9
  21. package/dist/tsup/chunk-47HHIEXH.cjs.map +1 -0
  22. package/dist/tsup/{chunk-EMFKMVJR.js → chunk-4JDSFJS5.js} +69 -58
  23. package/dist/tsup/chunk-4JDSFJS5.js.map +1 -0
  24. package/dist/tsup/{chunk-7HLFSAJP.cjs → chunk-7QKCIVAY.cjs} +225 -214
  25. package/dist/tsup/chunk-7QKCIVAY.cjs.map +1 -0
  26. package/dist/tsup/{chunk-AWTPTUQ7.cjs → chunk-B6VUNZUD.cjs} +10 -10
  27. package/dist/tsup/{chunk-AWTPTUQ7.cjs.map → chunk-B6VUNZUD.cjs.map} +1 -1
  28. package/dist/tsup/{chunk-D3T3ZBSY.js → chunk-BEI24WTI.js} +2 -2
  29. package/dist/tsup/{chunk-TMLOKTRB.js → chunk-BRP62GZC.js} +1 -1
  30. package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
  31. package/dist/tsup/{chunk-D5G75T7J.js → chunk-DPIMKYNB.js} +61 -2
  32. package/dist/tsup/chunk-DPIMKYNB.js.map +1 -0
  33. package/dist/tsup/{chunk-BATTOVHF.cjs → chunk-DXXJPH55.cjs} +40 -13
  34. package/dist/tsup/chunk-DXXJPH55.cjs.map +1 -0
  35. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  36. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  37. package/dist/tsup/{chunk-4BPKKZJO.cjs → chunk-I4LN3FNT.cjs} +10 -10
  38. package/dist/tsup/chunk-I4LN3FNT.cjs.map +1 -0
  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-63WNTDRC.cjs → chunk-KORQB2IR.cjs} +1 -1
  42. package/dist/tsup/{chunk-63WNTDRC.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
  43. package/dist/tsup/{chunk-6TQSSJ4F.cjs → chunk-LVTBW2RE.cjs} +3 -3
  44. package/dist/tsup/{chunk-6TQSSJ4F.cjs.map → chunk-LVTBW2RE.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-4JU3IPG2.js → chunk-MEHBWPLJ.js} +6 -6
  46. package/dist/tsup/chunk-MEHBWPLJ.js.map +1 -0
  47. package/dist/tsup/{chunk-SRNOPUC6.cjs → chunk-NIY3RSPX.cjs} +62 -3
  48. package/dist/tsup/chunk-NIY3RSPX.cjs.map +1 -0
  49. package/dist/tsup/{chunk-UZXQEGVJ.js → chunk-P2GNQ4RN.js} +4 -4
  50. package/dist/tsup/{chunk-UZXQEGVJ.js.map → chunk-P2GNQ4RN.js.map} +1 -1
  51. package/dist/tsup/{chunk-VUGENVIK.js → chunk-UMZVD6DQ.js} +22 -7
  52. package/dist/tsup/chunk-UMZVD6DQ.js.map +1 -0
  53. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  54. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  55. package/dist/tsup/{chunk-GBG63SUG.js → chunk-VTTFNQQI.js} +32 -5
  56. package/dist/tsup/chunk-VTTFNQQI.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/client/mod.cjs +9 -9
  60. package/dist/tsup/client/mod.d.cts +5 -5
  61. package/dist/tsup/client/mod.d.ts +5 -5
  62. package/dist/tsup/client/mod.js +8 -8
  63. package/dist/tsup/common/log.cjs +3 -3
  64. package/dist/tsup/common/log.js +2 -2
  65. package/dist/tsup/common/websocket.cjs +4 -4
  66. package/dist/tsup/common/websocket.js +3 -3
  67. package/dist/tsup/{config-Ak1lv4gF.d.ts → config-BxWAw3iH.d.ts} +512 -27
  68. package/dist/tsup/{config-DU_xj4qZ.d.cts → config-CZQQ-mso.d.cts} +512 -27
  69. package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.cts} +1 -2
  70. package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.ts} +1 -2
  71. package/dist/tsup/{context-DAAp4Lpg.d.ts → context-Bw7xq8w3.d.cts} +8 -8
  72. package/dist/tsup/{context-Dt_L55q8.d.cts → context-D8QA76sV.d.ts} +8 -8
  73. package/dist/tsup/db/drizzle.cjs +3 -3
  74. package/dist/tsup/db/drizzle.d.cts +1 -1
  75. package/dist/tsup/db/drizzle.d.ts +1 -1
  76. package/dist/tsup/db/drizzle.js +1 -1
  77. package/dist/tsup/db/mod.cjs +2 -2
  78. package/dist/tsup/db/mod.d.cts +2 -2
  79. package/dist/tsup/db/mod.d.ts +2 -2
  80. package/dist/tsup/db/mod.js +1 -1
  81. package/dist/tsup/dynamic/mod.cjs +24 -0
  82. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  83. package/dist/tsup/dynamic/mod.d.cts +37 -0
  84. package/dist/tsup/dynamic/mod.d.ts +37 -0
  85. package/dist/tsup/dynamic/mod.js +24 -0
  86. package/dist/tsup/dynamic/mod.js.map +1 -0
  87. package/dist/tsup/inspector/mod.cjs +6 -6
  88. package/dist/tsup/inspector/mod.js +5 -5
  89. package/dist/tsup/inspector-tab/mod.cjs +173 -0
  90. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  91. package/dist/tsup/inspector-tab/mod.d.cts +250 -0
  92. package/dist/tsup/inspector-tab/mod.d.ts +250 -0
  93. package/dist/tsup/inspector-tab/mod.js +173 -0
  94. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  95. package/dist/tsup/mod.cjs +615 -348
  96. package/dist/tsup/mod.cjs.map +1 -1
  97. package/dist/tsup/mod.d.cts +5 -5
  98. package/dist/tsup/mod.d.ts +5 -5
  99. package/dist/tsup/mod.js +511 -244
  100. package/dist/tsup/mod.js.map +1 -1
  101. package/dist/tsup/test/mod.cjs +21 -18
  102. package/dist/tsup/test/mod.cjs.map +1 -1
  103. package/dist/tsup/test/mod.d.cts +4 -4
  104. package/dist/tsup/test/mod.d.ts +4 -4
  105. package/dist/tsup/test/mod.js +18 -15
  106. package/dist/tsup/test/mod.js.map +1 -1
  107. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-DQosb24I.d.cts} +1 -1
  108. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-DQosb24I.d.ts} +1 -1
  109. package/dist/tsup/utils.cjs +3 -3
  110. package/dist/tsup/utils.d.cts +1 -1
  111. package/dist/tsup/utils.d.ts +1 -1
  112. package/dist/tsup/utils.js +2 -2
  113. package/dist/tsup/workflow/mod.cjs +279 -279
  114. package/dist/tsup/workflow/mod.cjs.map +1 -1
  115. package/dist/tsup/workflow/mod.d.cts +6 -6
  116. package/dist/tsup/workflow/mod.d.ts +6 -6
  117. package/dist/tsup/workflow/mod.js +380 -380
  118. package/dist/tsup/workflow/mod.js.map +1 -1
  119. package/package.json +29 -9
  120. package/src/actor/config.ts +156 -51
  121. package/src/actor/contexts/index.ts +7 -2
  122. package/src/actor/definition.ts +17 -19
  123. package/src/actor/driver.ts +3 -3
  124. package/src/actor/errors.ts +8 -2
  125. package/src/actor/instance/mod.ts +26 -34
  126. package/src/actor/keys.ts +1 -1
  127. package/src/actor/mod.ts +22 -20
  128. package/src/actor/schema.ts +2 -2
  129. package/src/agent-os/actor/index.ts +38 -18
  130. package/src/agent-os/actor/preview.ts +1 -2
  131. package/src/agent-os/config.ts +1 -1
  132. package/src/agent-os/fs/database-vfs.ts +1 -1
  133. package/src/agent-os/index.ts +16 -15
  134. package/src/client/actor-common.ts +87 -54
  135. package/src/client/actor-conn.ts +11 -11
  136. package/src/client/actor-handle.ts +69 -52
  137. package/src/client/actor-query.ts +5 -5
  138. package/src/client/errors.ts +1 -1
  139. package/src/client/lifecycle-errors.ts +2 -4
  140. package/src/client/query.ts +1 -1
  141. package/src/client/queue.ts +8 -4
  142. package/src/client/raw-utils.ts +8 -6
  143. package/src/client/resolve-gateway-target.ts +1 -1
  144. package/src/client/utils.ts +2 -6
  145. package/src/common/actor-websocket.ts +3 -1
  146. package/src/common/bare/actor-persist/v1.ts +205 -163
  147. package/src/common/bare/actor-persist/v2.ts +265 -213
  148. package/src/common/bare/actor-persist/v3.ts +176 -172
  149. package/src/common/bare/actor-persist/v4.ts +254 -253
  150. package/src/common/bare/transport/v1.ts +659 -543
  151. package/src/common/client-protocol-versioned.ts +66 -64
  152. package/src/common/database/config.ts +2 -8
  153. package/src/common/database/native-database.ts +1 -1
  154. package/src/common/database/shared.ts +1 -0
  155. package/src/common/encoding.ts +13 -17
  156. package/src/common/engine.ts +28 -1
  157. package/src/common/eventsource.ts +1 -1
  158. package/src/common/inline-websocket-adapter.ts +3 -2
  159. package/src/common/router.ts +13 -17
  160. package/src/common/utils.ts +1 -2
  161. package/src/common/websocket-interface.ts +1 -1
  162. package/src/db/mod.ts +1 -1
  163. package/src/devtools-loader/index.ts +4 -7
  164. package/src/devtools-loader/serve-devtools.ts +26 -0
  165. package/src/drivers/engine/actor-driver.ts +48 -46
  166. package/src/dynamic/instance.ts +32 -0
  167. package/src/dynamic/internal.ts +50 -0
  168. package/src/dynamic/isolate-runtime.ts +66 -0
  169. package/src/dynamic/mod.ts +32 -0
  170. package/src/engine-client/actor-http-client.ts +3 -3
  171. package/src/engine-client/actor-websocket-client.ts +5 -5
  172. package/src/engine-client/api-endpoints.ts +51 -2
  173. package/src/engine-client/api-utils.ts +2 -2
  174. package/src/engine-client/driver.ts +1 -1
  175. package/src/engine-client/mod.ts +5 -3
  176. package/src/engine-client/ws-proxy.ts +9 -4
  177. package/src/inspector/client.browser.ts +5 -11
  178. package/src/inspector/mod.ts +1 -3
  179. package/src/inspector-tab/mod.ts +315 -0
  180. package/src/registry/config/envoy.ts +1 -2
  181. package/src/registry/config/index.ts +40 -16
  182. package/src/registry/index.ts +226 -83
  183. package/src/registry/napi-runtime.ts +46 -12
  184. package/src/registry/native-validation.ts +10 -12
  185. package/src/registry/native.ts +307 -164
  186. package/src/registry/process-metrics.ts +90 -23
  187. package/src/registry/runtime.ts +53 -6
  188. package/src/registry/wasm-runtime.ts +30 -3
  189. package/src/serde.ts +1 -1
  190. package/src/serverless/configure.ts +18 -7
  191. package/src/test/mod.ts +11 -8
  192. package/src/utils/endpoint-parser.ts +1 -1
  193. package/src/utils/env-vars.ts +6 -0
  194. package/src/utils/router.ts +1 -1
  195. package/src/utils/serve.ts +4 -5
  196. package/src/utils.ts +1 -2
  197. package/src/workflow/context.ts +30 -29
  198. package/src/workflow/driver.ts +4 -6
  199. package/src/workflow/inspector.ts +2 -2
  200. package/src/workflow/mod.ts +15 -17
  201. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  202. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  203. package/dist/tsup/chunk-4BPKKZJO.cjs.map +0 -1
  204. package/dist/tsup/chunk-4JU3IPG2.js.map +0 -1
  205. package/dist/tsup/chunk-7HLFSAJP.cjs.map +0 -1
  206. package/dist/tsup/chunk-BATTOVHF.cjs.map +0 -1
  207. package/dist/tsup/chunk-D5G75T7J.js.map +0 -1
  208. package/dist/tsup/chunk-EMFKMVJR.js.map +0 -1
  209. package/dist/tsup/chunk-GBG63SUG.js.map +0 -1
  210. package/dist/tsup/chunk-HGW6PBWR.cjs.map +0 -1
  211. package/dist/tsup/chunk-KY3CERZR.js.map +0 -1
  212. package/dist/tsup/chunk-OT7FF6GB.cjs.map +0 -1
  213. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  214. package/dist/tsup/chunk-SRNOPUC6.cjs.map +0 -1
  215. package/dist/tsup/chunk-TMLOKTRB.js.map +0 -1
  216. package/dist/tsup/chunk-VUGENVIK.js.map +0 -1
  217. package/dist/tsup/process-metrics-NW754INA.js +0 -118
  218. package/dist/tsup/process-metrics-NW754INA.js.map +0 -1
  219. package/dist/tsup/process-metrics-TYAGKCEJ.cjs +0 -118
  220. package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +0 -1
  221. /package/dist/tsup/{chunk-D3T3ZBSY.js.map → chunk-BEI24WTI.js.map} +0 -0
@@ -1,23 +1,23 @@
1
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;
2
2
 
3
- var _chunkAWTPTUQ7cjs = require('../chunk-AWTPTUQ7.cjs');
3
+ var _chunkB6VUNZUDcjs = require('../chunk-B6VUNZUD.cjs');
4
+ require('../chunk-47HHIEXH.cjs');
4
5
 
5
6
 
6
7
 
7
8
 
8
- var _chunkSRNOPUC6cjs = require('../chunk-SRNOPUC6.cjs');
9
- require('../chunk-OT7FF6GB.cjs');
9
+ var _chunkNIY3RSPXcjs = require('../chunk-NIY3RSPX.cjs');
10
10
 
11
11
 
12
12
 
13
- var _chunkLD5YASJUcjs = require('../chunk-LD5YASJU.cjs');
14
- require('../chunk-HGW6PBWR.cjs');
13
+ var _chunkVE2X4KMGcjs = require('../chunk-VE2X4KMG.cjs');
14
+ require('../chunk-3677IIOV.cjs');
15
15
 
16
16
 
17
- var _chunkBATTOVHFcjs = require('../chunk-BATTOVHF.cjs');
17
+ var _chunkDXXJPH55cjs = require('../chunk-DXXJPH55.cjs');
18
18
 
19
19
 
20
- var _chunk63WNTDRCcjs = require('../chunk-63WNTDRC.cjs');
20
+ var _chunkKORQB2IRcjs = require('../chunk-KORQB2IR.cjs');
21
21
 
22
22
  // src/workflow/mod.ts
23
23
 
@@ -34,269 +34,6 @@ var _chunk63WNTDRCcjs = require('../chunk-63WNTDRC.cjs');
34
34
  var _workflowengine = require('@rivetkit/workflow-engine');
35
35
  var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);
36
36
 
37
- // src/workflow/driver.ts
38
- var WORKFLOW_STORAGE_PREFIX = _chunkLD5YASJUcjs.workflowStoragePrefix.call(void 0, );
39
- function stripWorkflowKey(prefixed) {
40
- return prefixed.slice(WORKFLOW_STORAGE_PREFIX.length);
41
- }
42
- function computeUpperBound(prefix) {
43
- const upperBound = prefix.slice();
44
- for (let i = upperBound.length - 1; i >= 0; i--) {
45
- if (upperBound[i] !== 255) {
46
- upperBound[i]++;
47
- return upperBound.slice(0, i + 1);
48
- }
49
- }
50
- return null;
51
- }
52
- var ActorWorkflowMessageDriver = class {
53
- #actor;
54
- #runCtx;
55
- constructor(actor, runCtx) {
56
- this.#actor = actor;
57
- this.#runCtx = runCtx;
58
- }
59
- async addMessage(message) {
60
- await this.#runCtx.internalKeepAwake(
61
- this.#actor.queueManager.enqueue(message.name, message.data)
62
- );
63
- }
64
- async receiveMessages(opts) {
65
- const messages = await this.#runCtx.internalKeepAwake(
66
- this.#actor.queueManager.receive(
67
- opts.names && opts.names.length > 0 ? [...opts.names] : void 0,
68
- opts.count,
69
- 0,
70
- void 0,
71
- opts.completable
72
- )
73
- );
74
- return messages.map((message) => ({
75
- id: message.id.toString(),
76
- name: message.name,
77
- data: message.body,
78
- sentAt: message.createdAt,
79
- ...opts.completable ? {
80
- complete: async (response) => {
81
- await this.#runCtx.internalKeepAwake(
82
- this.#actor.queueManager.completeMessage(
83
- message,
84
- response
85
- )
86
- );
87
- }
88
- } : {}
89
- }));
90
- }
91
- async completeMessage(messageId, response) {
92
- let parsedId;
93
- try {
94
- parsedId = BigInt(messageId);
95
- } catch (e) {
96
- return;
97
- }
98
- await this.#runCtx.internalKeepAwake(
99
- this.#actor.queueManager.completeMessageById(parsedId, response)
100
- );
101
- }
102
- };
103
- var ActorWorkflowDriver = (_class = class {
104
- __init() {this.workerPollInterval = 100}
105
-
106
- #actor;
107
- #runCtx;
108
- constructor(actor, runCtx) {;_class.prototype.__init.call(this);
109
- this.#actor = actor;
110
- this.#runCtx = runCtx;
111
- this.messageDriver = new ActorWorkflowMessageDriver(actor, runCtx);
112
- }
113
- async get(key) {
114
- const [value] = await this.#runCtx.internalKeepAwake(
115
- this.#actor.driver.kvBatchGet(this.#actor.id, [
116
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key)
117
- ])
118
- );
119
- return _nullishCoalesce(value, () => ( null));
120
- }
121
- async set(key, value) {
122
- await this.#runCtx.internalKeepAwake(
123
- this.#actor.driver.kvBatchPut(this.#actor.id, [
124
- [_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key), value]
125
- ])
126
- );
127
- }
128
- async delete(key) {
129
- await this.#runCtx.internalKeepAwake(
130
- this.#actor.driver.kvBatchDelete(this.#actor.id, [
131
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key)
132
- ])
133
- );
134
- }
135
- async deletePrefix(prefix) {
136
- const start = _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, prefix);
137
- const end = computeUpperBound(start);
138
- if (end) {
139
- await this.#runCtx.internalKeepAwake(
140
- this.#actor.driver.kvDeleteRange(this.#actor.id, start, end)
141
- );
142
- } else {
143
- const entries = await this.#runCtx.internalKeepAwake(
144
- this.#actor.driver.kvListPrefix(this.#actor.id, start)
145
- );
146
- if (entries.length === 0) {
147
- return;
148
- }
149
- await this.#runCtx.internalKeepAwake(
150
- this.#actor.driver.kvBatchDelete(
151
- this.#actor.id,
152
- entries.map(([key]) => key)
153
- )
154
- );
155
- }
156
- }
157
- async deleteRange(start, end) {
158
- await this.#runCtx.internalKeepAwake(
159
- this.#actor.driver.kvDeleteRange(
160
- this.#actor.id,
161
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, start),
162
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, end)
163
- )
164
- );
165
- }
166
- async list(prefix) {
167
- const entries = await this.#runCtx.internalKeepAwake(
168
- this.#actor.driver.kvListPrefix(
169
- this.#actor.id,
170
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, prefix)
171
- )
172
- );
173
- return entries.map(([key, value]) => ({
174
- key: stripWorkflowKey(key),
175
- value
176
- }));
177
- }
178
- async batch(writes) {
179
- if (writes.length === 0) return;
180
- await this.#runCtx.internalKeepAwake(
181
- Promise.all([
182
- this.#actor.driver.kvBatchPut(
183
- this.#actor.id,
184
- writes.map(({ key, value }) => [
185
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key),
186
- value
187
- ])
188
- ),
189
- this.#actor.stateManager.saveState({
190
- immediate: true
191
- })
192
- ])
193
- );
194
- }
195
- async setAlarm(_workflowId, wakeAt) {
196
- await this.#runCtx.internalKeepAwake(
197
- this.#actor.driver.setAlarm(this.#actor, wakeAt)
198
- );
199
- }
200
- async clearAlarm(_workflowId) {
201
- return;
202
- }
203
- waitForMessages(messageNames, abortSignal) {
204
- return this.#actor.queueManager.waitForNames(
205
- messageNames.length > 0 ? messageNames : void 0,
206
- abortSignal
207
- );
208
- }
209
- }, _class);
210
- var NoopWorkflowMessageDriver = class {
211
- async addMessage(_message) {
212
- throw new Error("Workflow control driver does not support messages");
213
- }
214
- async receiveMessages(_opts) {
215
- throw new Error("Workflow control driver does not support messages");
216
- }
217
- async completeMessage(_messageId, _response) {
218
- throw new Error("Workflow control driver does not support messages");
219
- }
220
- };
221
- var ActorWorkflowControlDriver = (_class2 = class {
222
- __init2() {this.workerPollInterval = 100}
223
- __init3() {this.messageDriver = new NoopWorkflowMessageDriver()}
224
- #actor;
225
- constructor(actor) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);
226
- this.#actor = actor;
227
- }
228
- async get(key) {
229
- const [value] = await this.#actor.driver.kvBatchGet(this.#actor.id, [
230
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key)
231
- ]);
232
- return _nullishCoalesce(value, () => ( null));
233
- }
234
- async set(key, value) {
235
- await this.#actor.driver.kvBatchPut(this.#actor.id, [
236
- [_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key), value]
237
- ]);
238
- }
239
- async delete(key) {
240
- await this.#actor.driver.kvBatchDelete(this.#actor.id, [
241
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key)
242
- ]);
243
- }
244
- async deletePrefix(prefix) {
245
- const start = _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, prefix);
246
- const end = computeUpperBound(start);
247
- if (end) {
248
- await this.#actor.driver.kvDeleteRange(this.#actor.id, start, end);
249
- return;
250
- }
251
- const entries = await this.#actor.driver.kvListPrefix(
252
- this.#actor.id,
253
- start
254
- );
255
- if (entries.length === 0) {
256
- return;
257
- }
258
- await this.#actor.driver.kvBatchDelete(
259
- this.#actor.id,
260
- entries.map(([key]) => key)
261
- );
262
- }
263
- async deleteRange(start, end) {
264
- await this.#actor.driver.kvDeleteRange(
265
- this.#actor.id,
266
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, start),
267
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, end)
268
- );
269
- }
270
- async list(prefix) {
271
- const entries = await this.#actor.driver.kvListPrefix(
272
- this.#actor.id,
273
- _chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, prefix)
274
- );
275
- return entries.map(([key, value]) => ({
276
- key: stripWorkflowKey(key),
277
- value
278
- }));
279
- }
280
- async batch(writes) {
281
- if (writes.length === 0) {
282
- return;
283
- }
284
- await this.#actor.driver.kvBatchPut(
285
- this.#actor.id,
286
- writes.map(({ key, value }) => [_chunkLD5YASJUcjs.makeWorkflowKey.call(void 0, key), value])
287
- );
288
- }
289
- async setAlarm(_workflowId, wakeAt) {
290
- await this.#actor.driver.setAlarm(this.#actor, wakeAt);
291
- }
292
- async clearAlarm(_workflowId) {
293
- return;
294
- }
295
- waitForMessages(_messageNames, _abortSignal) {
296
- throw new Error("Workflow control driver does not support messages");
297
- }
298
- }, _class2);
299
-
300
37
  // src/workflow/constants.ts
301
38
  var WORKFLOW_GUARD_KV_KEY = "__rivet_actor_workflow_guard_triggered";
302
39
 
@@ -516,7 +253,7 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
516
253
  let id;
517
254
  try {
518
255
  id = BigInt(message.id);
519
- } catch (e2) {
256
+ } catch (e) {
520
257
  throw new Error(`Invalid queue message id "${message.id}"`);
521
258
  }
522
259
  return {
@@ -547,7 +284,7 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
547
284
  async #withActorAccessAndStateRollback(run) {
548
285
  let stateSnapshot = null;
549
286
  try {
550
- stateSnapshot = { state: this.#runCtx[_chunkSRNOPUC6cjs.RAW_STATE_SYMBOL]() };
287
+ stateSnapshot = { state: this.#runCtx[_chunkNIY3RSPXcjs.RAW_STATE_SYMBOL]() };
551
288
  } catch (error) {
552
289
  this.#runCtx.log.debug({
553
290
  msg: "failed to get state, likely due to being stateless workflow",
@@ -588,7 +325,7 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
588
325
  if (state && typeof state === "object" && "guardTriggered" in state) {
589
326
  state.guardTriggered = true;
590
327
  }
591
- } catch (e3) {
328
+ } catch (e2) {
592
329
  }
593
330
  this.#runCtx.waitUntil(
594
331
  (async () => {
@@ -608,6 +345,269 @@ var ActorWorkflowContext = class _ActorWorkflowContext {
608
345
  }
609
346
  };
610
347
 
348
+ // src/workflow/driver.ts
349
+ var WORKFLOW_STORAGE_PREFIX = _chunkVE2X4KMGcjs.workflowStoragePrefix.call(void 0, );
350
+ function stripWorkflowKey(prefixed) {
351
+ return prefixed.slice(WORKFLOW_STORAGE_PREFIX.length);
352
+ }
353
+ function computeUpperBound(prefix) {
354
+ const upperBound = prefix.slice();
355
+ for (let i = upperBound.length - 1; i >= 0; i--) {
356
+ if (upperBound[i] !== 255) {
357
+ upperBound[i]++;
358
+ return upperBound.slice(0, i + 1);
359
+ }
360
+ }
361
+ return null;
362
+ }
363
+ var ActorWorkflowMessageDriver = class {
364
+ #actor;
365
+ #runCtx;
366
+ constructor(actor, runCtx) {
367
+ this.#actor = actor;
368
+ this.#runCtx = runCtx;
369
+ }
370
+ async addMessage(message) {
371
+ await this.#runCtx.internalKeepAwake(
372
+ this.#actor.queueManager.enqueue(message.name, message.data)
373
+ );
374
+ }
375
+ async receiveMessages(opts) {
376
+ const messages = await this.#runCtx.internalKeepAwake(
377
+ this.#actor.queueManager.receive(
378
+ opts.names && opts.names.length > 0 ? [...opts.names] : void 0,
379
+ opts.count,
380
+ 0,
381
+ void 0,
382
+ opts.completable
383
+ )
384
+ );
385
+ return messages.map((message) => ({
386
+ id: message.id.toString(),
387
+ name: message.name,
388
+ data: message.body,
389
+ sentAt: message.createdAt,
390
+ ...opts.completable ? {
391
+ complete: async (response) => {
392
+ await this.#runCtx.internalKeepAwake(
393
+ this.#actor.queueManager.completeMessage(
394
+ message,
395
+ response
396
+ )
397
+ );
398
+ }
399
+ } : {}
400
+ }));
401
+ }
402
+ async completeMessage(messageId, response) {
403
+ let parsedId;
404
+ try {
405
+ parsedId = BigInt(messageId);
406
+ } catch (e3) {
407
+ return;
408
+ }
409
+ await this.#runCtx.internalKeepAwake(
410
+ this.#actor.queueManager.completeMessageById(parsedId, response)
411
+ );
412
+ }
413
+ };
414
+ var ActorWorkflowDriver = (_class = class {
415
+ __init() {this.workerPollInterval = 100}
416
+
417
+ #actor;
418
+ #runCtx;
419
+ constructor(actor, runCtx) {;_class.prototype.__init.call(this);
420
+ this.#actor = actor;
421
+ this.#runCtx = runCtx;
422
+ this.messageDriver = new ActorWorkflowMessageDriver(actor, runCtx);
423
+ }
424
+ async get(key) {
425
+ const [value] = await this.#runCtx.internalKeepAwake(
426
+ this.#actor.driver.kvBatchGet(this.#actor.id, [
427
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key)
428
+ ])
429
+ );
430
+ return _nullishCoalesce(value, () => ( null));
431
+ }
432
+ async set(key, value) {
433
+ await this.#runCtx.internalKeepAwake(
434
+ this.#actor.driver.kvBatchPut(this.#actor.id, [
435
+ [_chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key), value]
436
+ ])
437
+ );
438
+ }
439
+ async delete(key) {
440
+ await this.#runCtx.internalKeepAwake(
441
+ this.#actor.driver.kvBatchDelete(this.#actor.id, [
442
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key)
443
+ ])
444
+ );
445
+ }
446
+ async deletePrefix(prefix) {
447
+ const start = _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, prefix);
448
+ const end = computeUpperBound(start);
449
+ if (end) {
450
+ await this.#runCtx.internalKeepAwake(
451
+ this.#actor.driver.kvDeleteRange(this.#actor.id, start, end)
452
+ );
453
+ } else {
454
+ const entries = await this.#runCtx.internalKeepAwake(
455
+ this.#actor.driver.kvListPrefix(this.#actor.id, start)
456
+ );
457
+ if (entries.length === 0) {
458
+ return;
459
+ }
460
+ await this.#runCtx.internalKeepAwake(
461
+ this.#actor.driver.kvBatchDelete(
462
+ this.#actor.id,
463
+ entries.map(([key]) => key)
464
+ )
465
+ );
466
+ }
467
+ }
468
+ async deleteRange(start, end) {
469
+ await this.#runCtx.internalKeepAwake(
470
+ this.#actor.driver.kvDeleteRange(
471
+ this.#actor.id,
472
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, start),
473
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, end)
474
+ )
475
+ );
476
+ }
477
+ async list(prefix) {
478
+ const entries = await this.#runCtx.internalKeepAwake(
479
+ this.#actor.driver.kvListPrefix(
480
+ this.#actor.id,
481
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, prefix)
482
+ )
483
+ );
484
+ return entries.map(([key, value]) => ({
485
+ key: stripWorkflowKey(key),
486
+ value
487
+ }));
488
+ }
489
+ async batch(writes) {
490
+ if (writes.length === 0) return;
491
+ await this.#runCtx.internalKeepAwake(
492
+ Promise.all([
493
+ this.#actor.driver.kvBatchPut(
494
+ this.#actor.id,
495
+ writes.map(({ key, value }) => [
496
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key),
497
+ value
498
+ ])
499
+ ),
500
+ this.#actor.stateManager.saveState({
501
+ immediate: true
502
+ })
503
+ ])
504
+ );
505
+ }
506
+ async setAlarm(_workflowId, wakeAt) {
507
+ await this.#runCtx.internalKeepAwake(
508
+ this.#actor.driver.setAlarm(this.#actor, wakeAt)
509
+ );
510
+ }
511
+ async clearAlarm(_workflowId) {
512
+ return;
513
+ }
514
+ waitForMessages(messageNames, abortSignal) {
515
+ return this.#actor.queueManager.waitForNames(
516
+ messageNames.length > 0 ? messageNames : void 0,
517
+ abortSignal
518
+ );
519
+ }
520
+ }, _class);
521
+ var NoopWorkflowMessageDriver = class {
522
+ async addMessage(_message) {
523
+ throw new Error("Workflow control driver does not support messages");
524
+ }
525
+ async receiveMessages(_opts) {
526
+ throw new Error("Workflow control driver does not support messages");
527
+ }
528
+ async completeMessage(_messageId, _response) {
529
+ throw new Error("Workflow control driver does not support messages");
530
+ }
531
+ };
532
+ var ActorWorkflowControlDriver = (_class2 = class {
533
+ __init2() {this.workerPollInterval = 100}
534
+ __init3() {this.messageDriver = new NoopWorkflowMessageDriver()}
535
+ #actor;
536
+ constructor(actor) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);
537
+ this.#actor = actor;
538
+ }
539
+ async get(key) {
540
+ const [value] = await this.#actor.driver.kvBatchGet(this.#actor.id, [
541
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key)
542
+ ]);
543
+ return _nullishCoalesce(value, () => ( null));
544
+ }
545
+ async set(key, value) {
546
+ await this.#actor.driver.kvBatchPut(this.#actor.id, [
547
+ [_chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key), value]
548
+ ]);
549
+ }
550
+ async delete(key) {
551
+ await this.#actor.driver.kvBatchDelete(this.#actor.id, [
552
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key)
553
+ ]);
554
+ }
555
+ async deletePrefix(prefix) {
556
+ const start = _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, prefix);
557
+ const end = computeUpperBound(start);
558
+ if (end) {
559
+ await this.#actor.driver.kvDeleteRange(this.#actor.id, start, end);
560
+ return;
561
+ }
562
+ const entries = await this.#actor.driver.kvListPrefix(
563
+ this.#actor.id,
564
+ start
565
+ );
566
+ if (entries.length === 0) {
567
+ return;
568
+ }
569
+ await this.#actor.driver.kvBatchDelete(
570
+ this.#actor.id,
571
+ entries.map(([key]) => key)
572
+ );
573
+ }
574
+ async deleteRange(start, end) {
575
+ await this.#actor.driver.kvDeleteRange(
576
+ this.#actor.id,
577
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, start),
578
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, end)
579
+ );
580
+ }
581
+ async list(prefix) {
582
+ const entries = await this.#actor.driver.kvListPrefix(
583
+ this.#actor.id,
584
+ _chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, prefix)
585
+ );
586
+ return entries.map(([key, value]) => ({
587
+ key: stripWorkflowKey(key),
588
+ value
589
+ }));
590
+ }
591
+ async batch(writes) {
592
+ if (writes.length === 0) {
593
+ return;
594
+ }
595
+ await this.#actor.driver.kvBatchPut(
596
+ this.#actor.id,
597
+ writes.map(({ key, value }) => [_chunkVE2X4KMGcjs.makeWorkflowKey.call(void 0, key), value])
598
+ );
599
+ }
600
+ async setAlarm(_workflowId, wakeAt) {
601
+ await this.#actor.driver.setAlarm(this.#actor, wakeAt);
602
+ }
603
+ async clearAlarm(_workflowId) {
604
+ return;
605
+ }
606
+ waitForMessages(_messageNames, _abortSignal) {
607
+ throw new Error("Workflow control driver does not support messages");
608
+ }
609
+ }, _class2);
610
+
611
611
  // src/workflow/mod.ts
612
612
 
613
613
  function shouldRethrowWorkflowError(error) {
@@ -620,7 +620,7 @@ function shouldRethrowWorkflowError(error) {
620
620
  return true;
621
621
  }
622
622
  function workflowReplayInFlightError() {
623
- return new (0, _chunk63WNTDRCcjs.RivetError)(
623
+ return new (0, _chunkKORQB2IRcjs.RivetError)(
624
624
  "actor",
625
625
  "workflow_in_flight",
626
626
  "Workflow replay is unavailable while the workflow is currently in flight.",
@@ -639,13 +639,13 @@ function workflow(fn, options = {}) {
639
639
  function getWorkflowInspector(actorId) {
640
640
  let workflowInspector = workflowInspectors.get(actorId);
641
641
  if (!workflowInspector) {
642
- workflowInspector = _chunkAWTPTUQ7cjs.createWorkflowInspectorAdapter.call(void 0, );
642
+ workflowInspector = _chunkB6VUNZUDcjs.createWorkflowInspectorAdapter.call(void 0, );
643
643
  workflowInspectors.set(actorId, workflowInspector);
644
644
  }
645
645
  return workflowInspector;
646
646
  }
647
647
  async function run(runCtx) {
648
- const actor = runCtx[_chunkSRNOPUC6cjs.ACTOR_CONTEXT_INTERNAL_SYMBOL];
648
+ const actor = runCtx[_chunkNIY3RSPXcjs.ACTOR_CONTEXT_INTERNAL_SYMBOL];
649
649
  _invariant2.default.call(void 0, actor, "workflow() requires an actor instance");
650
650
  const workflowInspector = getWorkflowInspector(actor.id);
651
651
  const driver = new ActorWorkflowDriver(actor, runCtx);
@@ -705,20 +705,20 @@ function workflow(fn, options = {}) {
705
705
  if (shouldRethrowWorkflowError(error)) {
706
706
  runCtx.log.error({
707
707
  msg: "workflow run failed",
708
- error: _chunkBATTOVHFcjs.stringifyError.call(void 0, error)
708
+ error: _chunkDXXJPH55cjs.stringifyError.call(void 0, error)
709
709
  });
710
710
  throw error;
711
711
  }
712
712
  runCtx.log.warn({
713
713
  msg: "workflow failed and will sleep until woken",
714
- error: _chunkBATTOVHFcjs.stringifyError.call(void 0, error)
714
+ error: _chunkDXXJPH55cjs.stringifyError.call(void 0, error)
715
715
  });
716
716
  } finally {
717
717
  runCtx.abortSignal.removeEventListener("abort", onAbort);
718
718
  }
719
719
  }
720
720
  const runWithConfig = run;
721
- runWithConfig[_chunkSRNOPUC6cjs.RUN_FUNCTION_CONFIG_SYMBOL] = {
721
+ runWithConfig[_chunkNIY3RSPXcjs.RUN_FUNCTION_CONFIG_SYMBOL] = {
722
722
  icon: "diagram-project",
723
723
  inspectorFactory: (actor) => {
724
724
  const actorId = resolveWorkflowInspectorActorId(actor);