rivetkit 2.3.0-rc.10 → 2.3.0-rc.12

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 (205) hide show
  1. package/dist/browser/client.d.ts +448 -62
  2. package/dist/browser/client.js +131 -89
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +40 -20
  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.js +1 -1
  8. package/dist/tsup/agent-os/index.cjs +2103 -2090
  9. package/dist/tsup/agent-os/index.cjs.map +1 -1
  10. package/dist/tsup/agent-os/index.d.cts +446 -69
  11. package/dist/tsup/agent-os/index.d.ts +446 -69
  12. package/dist/tsup/agent-os/index.js +2102 -2089
  13. package/dist/tsup/agent-os/index.js.map +1 -1
  14. package/dist/tsup/{chunk-TE4VCDNY.cjs → chunk-2U6RLFKX.cjs} +219 -234
  15. package/dist/tsup/chunk-2U6RLFKX.cjs.map +1 -0
  16. package/dist/tsup/{chunk-4K3MV2MW.cjs → chunk-2ZTBRZRS.cjs} +10 -10
  17. package/dist/tsup/chunk-2ZTBRZRS.cjs.map +1 -0
  18. package/dist/tsup/{chunk-KU6VKVEK.js → chunk-3EVVOYFD.js} +19 -7
  19. package/dist/tsup/chunk-3EVVOYFD.js.map +1 -0
  20. package/dist/tsup/{chunk-3LGP4JSO.cjs → chunk-6KTMKPNU.cjs} +8 -8
  21. package/dist/tsup/{chunk-3LGP4JSO.cjs.map → chunk-6KTMKPNU.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-WU2O2KIE.js → chunk-7UZF56RS.js} +63 -78
  23. package/dist/tsup/chunk-7UZF56RS.js.map +1 -0
  24. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-BRP62GZC.js} +3 -3
  25. package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
  26. package/dist/tsup/{chunk-G5RULGYQ.cjs → chunk-C7AAIILH.cjs} +24 -9
  27. package/dist/tsup/chunk-C7AAIILH.cjs.map +1 -0
  28. package/dist/tsup/{chunk-XV52XUWU.js → chunk-EWVOWEMD.js} +4 -4
  29. package/dist/tsup/chunk-EWVOWEMD.js.map +1 -0
  30. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  31. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  32. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  33. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  34. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-KORQB2IR.cjs} +3 -3
  35. package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
  36. package/dist/tsup/{chunk-CMYS77J6.js → chunk-OLIJHKLL.js} +3 -3
  37. package/dist/tsup/{chunk-BM3EOY7M.js → chunk-OOB32JVG.js} +134 -20
  38. package/dist/tsup/chunk-OOB32JVG.js.map +1 -0
  39. package/dist/tsup/{chunk-G34LIR7S.js → chunk-QKSGGKGQ.js} +22 -7
  40. package/dist/tsup/chunk-QKSGGKGQ.js.map +1 -0
  41. package/dist/tsup/{chunk-PWFGP2US.cjs → chunk-SS56HFM2.cjs} +138 -24
  42. package/dist/tsup/chunk-SS56HFM2.cjs.map +1 -0
  43. package/dist/tsup/{chunk-Z4C3W2CQ.cjs → chunk-UETC5RF7.cjs} +3 -3
  44. package/dist/tsup/{chunk-Z4C3W2CQ.cjs.map → chunk-UETC5RF7.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  46. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  47. package/dist/tsup/{chunk-6BI2MS3S.js → chunk-VLXRFJ7P.js} +2 -2
  48. package/dist/tsup/{chunk-J5P6S2LC.cjs → chunk-VNMIAPPF.cjs} +26 -14
  49. package/dist/tsup/chunk-VNMIAPPF.cjs.map +1 -0
  50. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-WHYBAEWG.cjs} +4 -2
  51. package/dist/tsup/chunk-WHYBAEWG.cjs.map +1 -0
  52. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-WIMUFZVJ.js} +3 -1
  53. package/dist/tsup/chunk-WIMUFZVJ.js.map +1 -0
  54. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  55. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  56. package/dist/tsup/client/mod.cjs +9 -9
  57. package/dist/tsup/client/mod.d.cts +4 -4
  58. package/dist/tsup/client/mod.d.ts +4 -4
  59. package/dist/tsup/client/mod.js +8 -8
  60. package/dist/tsup/common/log.cjs +3 -3
  61. package/dist/tsup/common/log.js +2 -2
  62. package/dist/tsup/common/websocket.cjs +4 -4
  63. package/dist/tsup/common/websocket.js +3 -3
  64. package/dist/tsup/{config-Ca8dN4cS.d.cts → config-BtAh7oBu.d.cts} +409 -22
  65. package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.cts} +1 -2
  66. package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.ts} +1 -2
  67. package/dist/tsup/{config-0Ta55UV0.d.ts → config-DKgPGC0f.d.ts} +409 -22
  68. package/dist/tsup/{context-B_IWbWne.d.ts → context-C-6dGebY.d.ts} +8 -8
  69. package/dist/tsup/{context-CUrQ9MHc.d.cts → context-Cfjl5pgz.d.cts} +8 -8
  70. package/dist/tsup/db/drizzle.cjs +3 -3
  71. package/dist/tsup/db/drizzle.d.cts +1 -1
  72. package/dist/tsup/db/drizzle.d.ts +1 -1
  73. package/dist/tsup/db/drizzle.js +1 -1
  74. package/dist/tsup/db/mod.cjs +2 -2
  75. package/dist/tsup/db/mod.d.cts +2 -2
  76. package/dist/tsup/db/mod.d.ts +2 -2
  77. package/dist/tsup/db/mod.js +1 -1
  78. package/dist/tsup/dynamic/mod.cjs +24 -0
  79. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  80. package/dist/tsup/dynamic/mod.d.cts +37 -0
  81. package/dist/tsup/dynamic/mod.d.ts +37 -0
  82. package/dist/tsup/dynamic/mod.js +24 -0
  83. package/dist/tsup/dynamic/mod.js.map +1 -0
  84. package/dist/tsup/inspector/mod.cjs +6 -6
  85. package/dist/tsup/inspector/mod.js +5 -5
  86. package/dist/tsup/mod.cjs +606 -325
  87. package/dist/tsup/mod.cjs.map +1 -1
  88. package/dist/tsup/mod.d.cts +4 -4
  89. package/dist/tsup/mod.d.ts +4 -4
  90. package/dist/tsup/mod.js +510 -229
  91. package/dist/tsup/mod.js.map +1 -1
  92. package/dist/tsup/test/mod.cjs +21 -18
  93. package/dist/tsup/test/mod.cjs.map +1 -1
  94. package/dist/tsup/test/mod.d.cts +3 -3
  95. package/dist/tsup/test/mod.d.ts +3 -3
  96. package/dist/tsup/test/mod.js +18 -15
  97. package/dist/tsup/test/mod.js.map +1 -1
  98. package/dist/tsup/utils.cjs +3 -3
  99. package/dist/tsup/utils.d.cts +1 -1
  100. package/dist/tsup/utils.d.ts +1 -1
  101. package/dist/tsup/utils.js +2 -2
  102. package/dist/tsup/workflow/mod.cjs +307 -282
  103. package/dist/tsup/workflow/mod.cjs.map +1 -1
  104. package/dist/tsup/workflow/mod.d.cts +5 -5
  105. package/dist/tsup/workflow/mod.d.ts +5 -5
  106. package/dist/tsup/workflow/mod.js +501 -476
  107. package/dist/tsup/workflow/mod.js.map +1 -1
  108. package/package.json +22 -11
  109. package/src/actor/config.ts +68 -51
  110. package/src/actor/contexts/index.ts +7 -2
  111. package/src/actor/definition.ts +17 -19
  112. package/src/actor/driver.ts +3 -3
  113. package/src/actor/errors.ts +9 -3
  114. package/src/actor/instance/mod.ts +22 -30
  115. package/src/actor/keys.ts +1 -1
  116. package/src/actor/mod.ts +20 -20
  117. package/src/actor/schema.ts +2 -2
  118. package/src/agent-os/actor/index.ts +38 -18
  119. package/src/agent-os/actor/preview.ts +1 -2
  120. package/src/agent-os/actor/session.ts +2 -2
  121. package/src/agent-os/config.ts +1 -1
  122. package/src/agent-os/fs/database-vfs.ts +1 -1
  123. package/src/agent-os/index.ts +16 -15
  124. package/src/client/actor-common.ts +87 -54
  125. package/src/client/actor-conn.ts +8 -36
  126. package/src/client/actor-handle.ts +69 -51
  127. package/src/client/actor-query.ts +5 -5
  128. package/src/client/errors.ts +1 -1
  129. package/src/client/lifecycle-errors.ts +2 -4
  130. package/src/client/query.ts +1 -1
  131. package/src/client/queue.ts +8 -3
  132. package/src/client/raw-utils.ts +8 -6
  133. package/src/client/resolve-gateway-target.ts +1 -1
  134. package/src/client/utils.ts +2 -7
  135. package/src/common/actor-websocket.ts +3 -1
  136. package/src/common/bare/actor-persist/v1.ts +205 -163
  137. package/src/common/bare/actor-persist/v2.ts +265 -213
  138. package/src/common/bare/actor-persist/v3.ts +176 -172
  139. package/src/common/bare/actor-persist/v4.ts +254 -253
  140. package/src/common/bare/transport/v1.ts +659 -543
  141. package/src/common/client-protocol-versioned.ts +66 -64
  142. package/src/common/database/config.ts +2 -8
  143. package/src/common/database/native-database.ts +1 -1
  144. package/src/common/database/shared.ts +1 -0
  145. package/src/common/encoding.ts +250 -16
  146. package/src/common/eventsource.ts +1 -1
  147. package/src/common/inline-websocket-adapter.ts +14 -13
  148. package/src/common/log.ts +1 -0
  149. package/src/common/router.ts +13 -17
  150. package/src/common/utils.ts +1 -150
  151. package/src/common/websocket-interface.ts +1 -1
  152. package/src/db/mod.ts +1 -1
  153. package/src/drivers/engine/actor-driver.ts +58 -56
  154. package/src/dynamic/instance.ts +32 -0
  155. package/src/dynamic/internal.ts +50 -0
  156. package/src/dynamic/isolate-runtime.ts +66 -0
  157. package/src/dynamic/mod.ts +32 -0
  158. package/src/engine-client/actor-http-client.ts +1 -1
  159. package/src/engine-client/actor-websocket-client.ts +6 -5
  160. package/src/engine-client/api-endpoints.ts +51 -2
  161. package/src/engine-client/api-utils.ts +2 -2
  162. package/src/engine-client/driver.ts +1 -1
  163. package/src/engine-client/mod.ts +6 -3
  164. package/src/engine-client/ws-proxy.ts +4 -4
  165. package/src/inspector/client.browser.ts +5 -11
  166. package/src/inspector/mod.ts +1 -3
  167. package/src/registry/config/envoy.ts +1 -2
  168. package/src/registry/config/index.ts +3 -9
  169. package/src/registry/index.ts +150 -72
  170. package/src/registry/napi-runtime.ts +13 -2
  171. package/src/registry/native-validation.ts +10 -12
  172. package/src/registry/native.ts +231 -173
  173. package/src/registry/process-metrics.ts +250 -0
  174. package/src/registry/runtime.ts +4 -0
  175. package/src/registry/wasm-runtime.ts +18 -2
  176. package/src/registry/write-through-proxy.ts +40 -0
  177. package/src/serde.ts +2 -2
  178. package/src/serverless/configure.ts +18 -7
  179. package/src/test/mod.ts +11 -8
  180. package/src/utils/endpoint-parser.ts +1 -1
  181. package/src/utils/router.ts +1 -1
  182. package/src/utils/serve.ts +4 -5
  183. package/src/utils.ts +1 -2
  184. package/src/workflow/context.ts +61 -33
  185. package/src/workflow/driver.ts +4 -6
  186. package/src/workflow/inspector.ts +4 -3
  187. package/src/workflow/mod.ts +15 -17
  188. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  189. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  190. package/dist/tsup/chunk-4K3MV2MW.cjs.map +0 -1
  191. package/dist/tsup/chunk-BM3EOY7M.js.map +0 -1
  192. package/dist/tsup/chunk-G34LIR7S.js.map +0 -1
  193. package/dist/tsup/chunk-G5RULGYQ.cjs.map +0 -1
  194. package/dist/tsup/chunk-J5P6S2LC.cjs.map +0 -1
  195. package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
  196. package/dist/tsup/chunk-KU6VKVEK.js.map +0 -1
  197. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  198. package/dist/tsup/chunk-PWFGP2US.cjs.map +0 -1
  199. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  200. package/dist/tsup/chunk-TE4VCDNY.cjs.map +0 -1
  201. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  202. package/dist/tsup/chunk-WU2O2KIE.js.map +0 -1
  203. package/dist/tsup/chunk-XV52XUWU.js.map +0 -1
  204. /package/dist/tsup/{chunk-CMYS77J6.js.map → chunk-OLIJHKLL.js.map} +0 -0
  205. /package/dist/tsup/{chunk-6BI2MS3S.js.map → chunk-VLXRFJ7P.js.map} +0 -0
package/dist/tsup/mod.cjs CHANGED
@@ -1,15 +1,15 @@
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 _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;
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(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2; var _class3;
2
2
 
3
3
 
4
4
 
5
5
 
6
6
 
7
7
 
8
- var _chunkWQ4HNA4Wcjs = require('./chunk-WQ4HNA4W.cjs');
9
8
 
9
+ var _chunkWHYBAEWGcjs = require('./chunk-WHYBAEWG.cjs');
10
10
 
11
- var _chunkG5RULGYQcjs = require('./chunk-G5RULGYQ.cjs');
12
11
 
12
+ var _chunkC7AAIILHcjs = require('./chunk-C7AAIILH.cjs');
13
13
 
14
14
 
15
15
 
@@ -18,23 +18,23 @@ var _chunkG5RULGYQcjs = require('./chunk-G5RULGYQ.cjs');
18
18
 
19
19
 
20
20
 
21
- var _chunkTE4VCDNYcjs = require('./chunk-TE4VCDNY.cjs');
22
21
 
22
+ var _chunk2U6RLFKXcjs = require('./chunk-2U6RLFKX.cjs');
23
23
 
24
24
 
25
25
 
26
26
 
27
27
 
28
28
 
29
- var _chunkLD5YASJUcjs = require('./chunk-LD5YASJU.cjs');
30
29
 
30
+ var _chunkVE2X4KMGcjs = require('./chunk-VE2X4KMG.cjs');
31
31
 
32
32
 
33
33
 
34
- var _chunkPWFGP2UScjs = require('./chunk-PWFGP2US.cjs');
35
- require('./chunk-2NDZ7JCR.cjs');
36
- require('./chunk-Z4C3W2CQ.cjs');
37
34
 
35
+ var _chunkSS56HFM2cjs = require('./chunk-SS56HFM2.cjs');
36
+ require('./chunk-ZA7FLHKH.cjs');
37
+ require('./chunk-UETC5RF7.cjs');
38
38
 
39
39
 
40
40
 
@@ -57,9 +57,9 @@ require('./chunk-Z4C3W2CQ.cjs');
57
57
 
58
58
 
59
59
 
60
- var _chunkJ5P6S2LCcjs = require('./chunk-J5P6S2LC.cjs');
61
60
 
62
61
 
62
+ var _chunkVNMIAPPFcjs = require('./chunk-VNMIAPPF.cjs');
63
63
 
64
64
 
65
65
 
@@ -68,11 +68,13 @@ var _chunkJ5P6S2LCcjs = require('./chunk-J5P6S2LC.cjs');
68
68
 
69
69
 
70
70
 
71
- var _chunkQAZLM4WTcjs = require('./chunk-QAZLM4WT.cjs');
71
+
72
+
73
+ var _chunkKORQB2IRcjs = require('./chunk-KORQB2IR.cjs');
72
74
 
73
75
  // src/actor/log.ts
74
76
  function loggerWithoutContext() {
75
- return _chunkJ5P6S2LCcjs.getLogger.call(void 0, "actor-runtime");
77
+ return _chunkVNMIAPPFcjs.getLogger.call(void 0, "actor-runtime");
76
78
  }
77
79
 
78
80
  // src/actor/definition.ts
@@ -105,7 +107,7 @@ function actor(input) {
105
107
  warnDeprecatedShutdownTimeoutKeys(
106
108
  input == null ? void 0 : input.options
107
109
  );
108
- const config = _chunkWQ4HNA4Wcjs.ActorConfigSchema.parse(input);
110
+ const config = _chunkWHYBAEWGcjs.ActorConfigSchema.parse(input);
109
111
  return new ActorDefinition(config);
110
112
  }
111
113
  function isStaticActorDefinition(definition) {
@@ -140,7 +142,7 @@ function hasSchemaConfigKey(schemas, key) {
140
142
  if (!schemas) {
141
143
  return false;
142
144
  }
143
- return Object.prototype.hasOwnProperty.call(schemas, key);
145
+ return Object.hasOwn(schemas, key);
144
146
  }
145
147
  function getEventCanSubscribe(schemas, key) {
146
148
  const schema = schemas == null ? void 0 : schemas[key];
@@ -187,7 +189,7 @@ function validateSchemaSync(schemas, key, data) {
187
189
  if (isStandardSchema(schema)) {
188
190
  const result = schema["~standard"].validate(data);
189
191
  if (isPromiseLike(result)) {
190
- throw _chunkQAZLM4WTcjs.unsupportedFeature.call(void 0, "async schema validation");
192
+ throw _chunkKORQB2IRcjs.unsupportedFeature.call(void 0, "async schema validation");
191
193
  }
192
194
  if (result.issues) {
193
195
  return { success: false, issues: [...result.issues] };
@@ -201,10 +203,10 @@ function validateSchemaSync(schemas, key, data) {
201
203
  }
202
204
 
203
205
  // src/common/inline-websocket-adapter.ts
204
- var _ws = require('hono/ws');
205
206
  var _virtualwebsocket = require('@rivetkit/virtual-websocket');
207
+ var _ws = require('hono/ws');
206
208
  function logger() {
207
- return _chunkJ5P6S2LCcjs.getLogger.call(void 0, "inline-websocket-adapter");
209
+ return _chunkVNMIAPPFcjs.getLogger.call(void 0, "inline-websocket-adapter");
208
210
  }
209
211
  var InlineWebSocketAdapter = class {
210
212
  #handler;
@@ -314,24 +316,24 @@ var InlineWebSocketAdapter = class {
314
316
  this.#close(1011, "Internal error during initialization");
315
317
  }
316
318
  }
317
- #handleError(err) {
318
- console.error("INLINE_WEBSOCKET_ADAPTER_ERROR", err);
319
+ #handleError(error) {
320
+ console.error("INLINE_WEBSOCKET_ADAPTER_ERROR", error);
319
321
  logger().error({
320
322
  msg: "error in websocket",
321
- error: err,
322
- errorMessage: err instanceof Error ? err.message : String(err),
323
- stack: err instanceof Error ? err.stack : void 0
323
+ error,
324
+ errorMessage: error instanceof Error ? error.message : String(error),
325
+ stack: error instanceof Error ? error.stack : void 0
324
326
  });
325
327
  try {
326
- this.#handler.onError(err, this.#wsContext);
327
- } catch (handlerErr) {
328
+ this.#handler.onError(error, this.#wsContext);
329
+ } catch (error2) {
328
330
  logger().error({
329
331
  msg: "error in onError handler",
330
- error: handlerErr
332
+ error: error2
331
333
  });
332
334
  }
333
- this.#clientWs.triggerError(err);
334
- this.#actorWs.triggerError(err);
335
+ this.#clientWs.triggerError(error);
336
+ this.#actorWs.triggerError(error);
335
337
  }
336
338
  #close(code, reason) {
337
339
  if (this.#readyState === 3 || this.#readyState === 2) {
@@ -344,8 +346,8 @@ var InlineWebSocketAdapter = class {
344
346
  { code, reason, wasClean: true },
345
347
  this.#wsContext
346
348
  );
347
- } catch (err) {
348
- logger().error({ msg: "error closing websocket", error: err });
349
+ } catch (error) {
350
+ logger().error({ msg: "error closing websocket", error });
349
351
  } finally {
350
352
  this.#readyState = 3;
351
353
  this.#clientWs.triggerClose(code, reason);
@@ -354,13 +356,16 @@ var InlineWebSocketAdapter = class {
354
356
  }
355
357
  };
356
358
 
359
+ // src/registry/index.ts
360
+ var _hono = require('hono');
361
+
357
362
  // src/common/engine.ts
358
363
  var ENGINE_PORT = 6420;
359
364
  var ENGINE_ENDPOINT = `http://127.0.0.1:${ENGINE_PORT}`;
360
365
 
361
366
  // src/registry/log.ts
362
367
  function logger2() {
363
- return _chunkJ5P6S2LCcjs.getLogger.call(void 0, "registry");
368
+ return _chunkVNMIAPPFcjs.getLogger.call(void 0, "registry");
364
369
  }
365
370
 
366
371
  // src/serverless/configure.ts
@@ -371,10 +376,13 @@ function sleep(ms) {
371
376
  }
372
377
  function configureTimeoutMs() {
373
378
  const value = process.env.RIVET_SERVERLESS_CONFIGURE_TIMEOUT_MS;
374
- if (value === void 0 || value === "") return DEFAULT_CONFIGURE_TIMEOUT_MS;
379
+ if (value === void 0 || value === "")
380
+ return DEFAULT_CONFIGURE_TIMEOUT_MS;
375
381
  const parsed = Number(value);
376
382
  if (!Number.isFinite(parsed) || parsed < 0) {
377
- throw new Error("RIVET_SERVERLESS_CONFIGURE_TIMEOUT_MS must be a finite non-negative number");
383
+ throw new Error(
384
+ "RIVET_SERVERLESS_CONFIGURE_TIMEOUT_MS must be a finite non-negative number"
385
+ );
378
386
  }
379
387
  return parsed;
380
388
  }
@@ -388,17 +396,23 @@ async function configureServerlessPool(config) {
388
396
  attempts += 1;
389
397
  try {
390
398
  if (!config.namespace) {
391
- throw new Error("namespace is required for serverless configuration");
399
+ throw new Error(
400
+ "namespace is required for serverless configuration"
401
+ );
392
402
  }
393
403
  if (!config.endpoint) {
394
- throw new Error("endpoint is required for serverless configuration");
404
+ throw new Error(
405
+ "endpoint is required for serverless configuration"
406
+ );
395
407
  }
396
408
  if (!config.configurePool) {
397
- throw new Error("configurePool is required for serverless configuration");
409
+ throw new Error(
410
+ "configurePool is required for serverless configuration"
411
+ );
398
412
  }
399
413
  const customConfig = config.configurePool;
400
- const clientConfig = _chunkTE4VCDNYcjs.convertRegistryConfigToClientConfig.call(void 0, config);
401
- const dcsRes = await _chunkTE4VCDNYcjs.getDatacenters.call(void 0, clientConfig);
414
+ const clientConfig = _chunk2U6RLFKXcjs.convertRegistryConfigToClientConfig.call(void 0, config);
415
+ const dcsRes = await _chunk2U6RLFKXcjs.getDatacenters.call(void 0, clientConfig);
402
416
  const poolName = _nullishCoalesce(customConfig.name, () => ( "default"));
403
417
  const serverlessToken = _nullishCoalesce(config.token, () => ( config.publicToken));
404
418
  const headers = {
@@ -420,7 +434,7 @@ async function configureServerlessPool(config) {
420
434
  metadata: _nullishCoalesce(customConfig.metadata, () => ( {})),
421
435
  drain_on_version_upgrade: _nullishCoalesce(customConfig.drainOnVersionUpgrade, () => ( true))
422
436
  };
423
- await _chunkTE4VCDNYcjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
437
+ await _chunk2U6RLFKXcjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
424
438
  datacenters: Object.fromEntries(
425
439
  dcsRes.datacenters.map((dc) => [dc.name, serverlessConfig])
426
440
  )
@@ -437,7 +451,7 @@ async function configureServerlessPool(config) {
437
451
  logger2().warn({
438
452
  msg: "serverless pool configuration attempt failed",
439
453
  attempts,
440
- error: _chunkJ5P6S2LCcjs.stringifyError.call(void 0, error)
454
+ error: _chunkVNMIAPPFcjs.stringifyError.call(void 0, error)
441
455
  });
442
456
  await sleep(CONFIGURE_RETRY_DELAY_MS);
443
457
  }
@@ -445,11 +459,150 @@ async function configureServerlessPool(config) {
445
459
  logger2().error({
446
460
  msg: "failed to configure serverless pool, validate endpoint is configured correctly then restart this process",
447
461
  attempts,
448
- error: _chunkJ5P6S2LCcjs.stringifyError.call(void 0, lastError)
462
+ error: _chunkVNMIAPPFcjs.stringifyError.call(void 0, lastError)
449
463
  });
450
464
  throw lastError;
451
465
  }
452
466
 
467
+ // src/utils/serve.ts
468
+ var _getport = require('get-port'); var _getport2 = _interopRequireDefault(_getport);
469
+ var serveStaticLoaderPromises = {};
470
+ async function crossPlatformServe(config, httpPort, app, runtime = _chunkVNMIAPPFcjs.detectRuntime.call(void 0, )) {
471
+ logger2().debug({ msg: "detected runtime for serve", runtime });
472
+ switch (runtime) {
473
+ case "deno":
474
+ return serveDeno(config, httpPort, app);
475
+ case "bun":
476
+ return serveBun(config, httpPort, app);
477
+ case "node":
478
+ return serveNode(config, httpPort, app);
479
+ default:
480
+ return serveNode(config, httpPort, app);
481
+ }
482
+ }
483
+ async function loadRuntimeServeStatic(runtime) {
484
+ if (!serveStaticLoaderPromises[runtime]) {
485
+ if (runtime === "node") {
486
+ const nodeServeStaticModule = "@hono/node-server/serve-static";
487
+ serveStaticLoaderPromises[runtime] = Promise.resolve().then(() => _interopRequireWildcard(require(
488
+ /* webpackIgnore: true */
489
+ nodeServeStaticModule
490
+ ))).then((x) => x.serveStatic);
491
+ } else if (runtime === "bun") {
492
+ const bunModule = "hono/bun";
493
+ serveStaticLoaderPromises[runtime] = Promise.resolve().then(() => _interopRequireWildcard(require(
494
+ /* webpackIgnore: true */
495
+ bunModule
496
+ ))).then((x) => x.serveStatic);
497
+ } else if (runtime === "deno") {
498
+ const denoModule = "hono/deno";
499
+ serveStaticLoaderPromises[runtime] = Promise.resolve().then(() => _interopRequireWildcard(require(
500
+ /* webpackIgnore: true */
501
+ denoModule
502
+ ))).then((x) => x.serveStatic);
503
+ } else {
504
+ throw new Error(`unsupported runtime: ${runtime}`);
505
+ }
506
+ }
507
+ return await serveStaticLoaderPromises[runtime];
508
+ }
509
+ async function serveNode(config, httpPort, app) {
510
+ const nodeServerModule = "@hono/node-server";
511
+ let serve;
512
+ try {
513
+ const dep = await Promise.resolve().then(() => _interopRequireWildcard(require(
514
+ /* webpackIgnore: true */
515
+ nodeServerModule
516
+ )));
517
+ serve = dep.serve;
518
+ } catch (err) {
519
+ logger2().error({
520
+ msg: "failed to import @hono/node-server. please run 'npm install @hono/node-server @hono/node-ws'",
521
+ error: _chunkVNMIAPPFcjs.stringifyError.call(void 0, err)
522
+ });
523
+ process.exit(1);
524
+ }
525
+ const nodeWsModule = "@hono/node-ws";
526
+ let createNodeWebSocket;
527
+ try {
528
+ const dep = await Promise.resolve().then(() => _interopRequireWildcard(require(
529
+ /* webpackIgnore: true */
530
+ nodeWsModule
531
+ )));
532
+ createNodeWebSocket = dep.createNodeWebSocket;
533
+ } catch (err) {
534
+ logger2().error({
535
+ msg: "failed to import @hono/node-ws. please run 'npm install @hono/node-server @hono/node-ws'",
536
+ error: _chunkVNMIAPPFcjs.stringifyError.call(void 0, err)
537
+ });
538
+ process.exit(1);
539
+ }
540
+ const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({
541
+ app
542
+ });
543
+ const port = httpPort;
544
+ const hostname = config.httpHost;
545
+ const server = serve(
546
+ { fetch: app.fetch, port, hostname },
547
+ () => logger2().info({ msg: "server listening", port, hostname })
548
+ );
549
+ injectWebSocket(server);
550
+ const closeServer = () => {
551
+ server.close();
552
+ };
553
+ return { upgradeWebSocket, closeServer };
554
+ }
555
+ async function serveDeno(config, httpPort, app) {
556
+ const honoDenoModule = "hono/deno";
557
+ let upgradeWebSocket;
558
+ try {
559
+ const dep = await Promise.resolve().then(() => _interopRequireWildcard(require(
560
+ /* webpackIgnore: true */
561
+ honoDenoModule
562
+ )));
563
+ upgradeWebSocket = dep.upgradeWebSocket;
564
+ } catch (err) {
565
+ logger2().error({
566
+ msg: "failed to import hono/deno",
567
+ error: _chunkVNMIAPPFcjs.stringifyError.call(void 0, err)
568
+ });
569
+ process.exit(1);
570
+ }
571
+ const port = httpPort;
572
+ const hostname = config.httpHost;
573
+ Deno.serve({ port, hostname }, app.fetch);
574
+ logger2().info({ msg: "server listening", port, hostname });
575
+ return { upgradeWebSocket };
576
+ }
577
+ async function serveBun(config, httpPort, app) {
578
+ const honoBunModule = "hono/bun";
579
+ let createBunWebSocket;
580
+ try {
581
+ const dep = await Promise.resolve().then(() => _interopRequireWildcard(require(
582
+ /* webpackIgnore: true */
583
+ honoBunModule
584
+ )));
585
+ createBunWebSocket = dep.createBunWebSocket;
586
+ } catch (err) {
587
+ logger2().error({
588
+ msg: "failed to import hono/bun",
589
+ error: _chunkVNMIAPPFcjs.stringifyError.call(void 0, err)
590
+ });
591
+ process.exit(1);
592
+ }
593
+ const { websocket, upgradeWebSocket } = createBunWebSocket();
594
+ const port = httpPort;
595
+ const hostname = config.httpHost;
596
+ Bun.serve({
597
+ fetch: app.fetch,
598
+ port,
599
+ hostname,
600
+ websocket
601
+ });
602
+ logger2().info({ msg: "server listening", port, hostname });
603
+ return { upgradeWebSocket };
604
+ }
605
+
453
606
  // src/registry/config/index.ts
454
607
  var _zod = require('zod');
455
608
 
@@ -457,20 +610,20 @@ var _zod = require('zod');
457
610
  var _v4 = require('zod/v4');
458
611
  var warnedMissingVersion = false;
459
612
  var EnvoyConfigSchema = _v4.z.object({
460
- poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkJ5P6S2LCcjs.getRivetPool.call(void 0, ), () => ( "default"))),
613
+ poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkVNMIAPPFcjs.getRivetPool.call(void 0, ), () => ( "default"))),
461
614
  version: _v4.z.number().default(() => {
462
- const version = _chunkJ5P6S2LCcjs.getRivetEnvoyVersion.call(void 0, );
615
+ const version = _chunkVNMIAPPFcjs.getRivetEnvoyVersion.call(void 0, );
463
616
  if (version !== void 0) return version;
464
- if (_chunkJ5P6S2LCcjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
617
+ if (_chunkVNMIAPPFcjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
465
618
  warnedMissingVersion = true;
466
- _chunkJ5P6S2LCcjs.getLogger.call(void 0, "rivetkit").error(
619
+ _chunkVNMIAPPFcjs.getLogger.call(void 0, "rivetkit").error(
467
620
  "RIVET_ENVOY_VERSION is not set. Actors will not be versioned, which means they won't be drained on deploy. This is only needed when self-hosting or using a custom envoy (not needed for Rivet Compute). Set this as a build arg in your Dockerfile. See https://rivet.dev/docs/actors/versions"
468
621
  );
469
622
  }
470
623
  return 1;
471
624
  }),
472
625
  // Deprecated.
473
- totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkJ5P6S2LCcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
626
+ totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkVNMIAPPFcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
474
627
  envoyKey: _v4.z.string().optional()
475
628
  });
476
629
 
@@ -508,7 +661,7 @@ var ServerlessConfigSchema = _v4.z.object({
508
661
  *
509
662
  * Can also be set via RIVET_PUBLIC_ENDPOINT environment variable.
510
663
  */
511
- publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkJ5P6S2LCcjs.getRivetPublicEndpoint.call(void 0, )))),
664
+ publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkVNMIAPPFcjs.getRivetPublicEndpoint.call(void 0, )))),
512
665
  /**
513
666
  * Token that clients should use when connecting via the public endpoint.
514
667
  *
@@ -516,7 +669,7 @@ var ServerlessConfigSchema = _v4.z.object({
516
669
  *
517
670
  * Can also be specified in the publicEndpoint URL as `https://namespace:token@host`.
518
671
  */
519
- publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkJ5P6S2LCcjs.getRivetPublicToken.call(void 0, ))))
672
+ publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkVNMIAPPFcjs.getRivetPublicToken.call(void 0, ))))
520
673
  // There is no publicNamespace config option because the frontend and backend
521
674
  // cannot use different namespaces. The namespace is extracted from the
522
675
  // publicEndpoint URL auth syntax if provided.
@@ -570,7 +723,7 @@ var RegistryConfigSchema = _zod.z.object({
570
723
  * Runtime binding to use for RivetKit core.
571
724
  * */
572
725
  runtime: RuntimeKindSchema.optional().transform((val, ctx) => {
573
- const rawRuntime = _nullishCoalesce(val, () => ( _chunkJ5P6S2LCcjs.getRivetkitRuntime.call(void 0, )));
726
+ const rawRuntime = _nullishCoalesce(val, () => ( _chunkVNMIAPPFcjs.getRivetkitRuntime.call(void 0, )));
574
727
  if (rawRuntime === void 0) {
575
728
  return "auto";
576
729
  }
@@ -607,7 +760,7 @@ var RegistryConfigSchema = _zod.z.object({
607
760
  * */
608
761
  logging: _zod.z.object({
609
762
  baseLogger: _zod.z.custom().optional(),
610
- level: _chunkJ5P6S2LCcjs.LogLevelSchema.optional()
763
+ level: _chunkVNMIAPPFcjs.LogLevelSchema.optional()
611
764
  }).optional().default(() => ({})),
612
765
  // MARK: Routing
613
766
  // // This is a function to allow for lazy configuration of upgradeWebSocket on the
@@ -625,9 +778,9 @@ var RegistryConfigSchema = _zod.z.object({
625
778
  *
626
779
  * Can also be set via RIVET_ENDPOINT environment variables.
627
780
  */
628
- endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkJ5P6S2LCcjs.getRivetEngine.call(void 0, ))), () => ( _chunkJ5P6S2LCcjs.getRivetEndpoint.call(void 0, )))),
629
- token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkJ5P6S2LCcjs.getRivetToken.call(void 0, )))),
630
- namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkJ5P6S2LCcjs.getRivetNamespace.call(void 0, )))),
781
+ endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkVNMIAPPFcjs.getRivetEngine.call(void 0, ))), () => ( _chunkVNMIAPPFcjs.getRivetEndpoint.call(void 0, )))),
782
+ token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkVNMIAPPFcjs.getRivetToken.call(void 0, )))),
783
+ namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkVNMIAPPFcjs.getRivetNamespace.call(void 0, )))),
631
784
  headers: _zod.z.record(_zod.z.string(), _zod.z.string()).optional().default({}),
632
785
  // MARK: Client
633
786
  // TODO:
@@ -667,9 +820,9 @@ var RegistryConfigSchema = _zod.z.object({
667
820
  *
668
821
  * Starts the full Rust engine process locally.
669
822
  */
670
- startEngine: _zod.z.boolean().default(() => _chunkJ5P6S2LCcjs.getRivetRunEngine.call(void 0, )),
823
+ startEngine: _zod.z.boolean().default(() => _chunkVNMIAPPFcjs.getRivetRunEngine.call(void 0, )),
671
824
  /** @experimental */
672
- engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkJ5P6S2LCcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkJ5P6S2LCcjs.VERSION))),
825
+ engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkVNMIAPPFcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkVNMIAPPFcjs.VERSION))),
673
826
  /**
674
827
  * @experimental
675
828
  *
@@ -703,7 +856,7 @@ var RegistryConfigSchema = _zod.z.object({
703
856
  * after calling `CoreRegistry::shutdown()`. Defaults to the
704
857
  * engine-provided actor stop threshold once the envoy connects.
705
858
  *
706
- * Must be >= rivetkit-core's drain timeout (20s) + margin.
859
+ * Must be long enough for rivetkit-core to drain the envoy.
707
860
  */
708
861
  gracePeriodMs: _zod.z.number().int().min(1e3).optional(),
709
862
  /**
@@ -717,7 +870,7 @@ var RegistryConfigSchema = _zod.z.object({
717
870
  }))
718
871
  }).transform((config, ctx) => {
719
872
  var _a, _b, _c;
720
- const isDevEnv = _chunkJ5P6S2LCcjs.isDev.call(void 0, );
873
+ const isDevEnv = _chunkVNMIAPPFcjs.isDev.call(void 0, );
721
874
  const sqliteBackend = _nullishCoalesce(((_a = config.sqlite) == null ? void 0 : _a.backend), () => ( ((_b = config.test) == null ? void 0 : _b.sqliteBackend)));
722
875
  if (config.runtime === "wasm" && sqliteBackend === "local") {
723
876
  ctx.addIssue({
@@ -727,7 +880,7 @@ var RegistryConfigSchema = _zod.z.object({
727
880
  });
728
881
  }
729
882
  const sqlite = config.runtime === "wasm" && config.sqlite === void 0 ? { backend: "remote" } : config.sqlite;
730
- const parsedEndpoint = config.endpoint ? _chunkTE4VCDNYcjs.tryParseEndpoint.call(void 0, ctx, {
883
+ const parsedEndpoint = config.endpoint ? _chunk2U6RLFKXcjs.tryParseEndpoint.call(void 0, ctx, {
731
884
  endpoint: config.endpoint,
732
885
  path: ["endpoint"],
733
886
  namespace: config.namespace,
@@ -751,7 +904,7 @@ var RegistryConfigSchema = _zod.z.object({
751
904
  );
752
905
  const namespace = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.namespace), () => ( config.namespace)), () => ( "default"));
753
906
  const token = _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.token), () => ( config.token));
754
- const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkTE4VCDNYcjs.tryParseEndpoint.call(void 0, ctx, {
907
+ const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunk2U6RLFKXcjs.tryParseEndpoint.call(void 0, ctx, {
755
908
  endpoint: config.serverless.publicEndpoint,
756
909
  path: ["serverless", "publicEndpoint"]
757
910
  }) : void 0;
@@ -786,30 +939,30 @@ function buildActorNames(config) {
786
939
  Object.keys(config.use).map((actorName) => {
787
940
  const definition = config.use[actorName];
788
941
  const options = _nullishCoalesce(definition.config.options, () => ( {}));
789
- const runMeta = _chunkWQ4HNA4Wcjs.getRunMetadata.call(void 0, definition.config.run);
942
+ const runMeta = _chunkWHYBAEWGcjs.getRunMetadata.call(void 0, definition.config.run);
790
943
  const metadata = {};
791
944
  metadata.icon = _nullishCoalesce(options.icon, () => ( runMeta.icon));
792
945
  metadata.name = _nullishCoalesce(options.name, () => ( runMeta.name));
793
946
  metadata.preload = {
794
947
  keys: [
795
- Array.from(_chunkLD5YASJUcjs.KEYS.PERSIST_DATA),
796
- Array.from(_chunkLD5YASJUcjs.KEYS.INSPECTOR_TOKEN),
797
- Array.from(_chunkLD5YASJUcjs.queueMetadataKey.call(void 0, )),
798
- Array.from(_chunkLD5YASJUcjs.KEYS.LAST_PUSHED_ALARM)
948
+ Array.from(_chunkVE2X4KMGcjs.KEYS.PERSIST_DATA),
949
+ Array.from(_chunkVE2X4KMGcjs.KEYS.INSPECTOR_TOKEN),
950
+ Array.from(_chunkVE2X4KMGcjs.queueMetadataKey.call(void 0, )),
951
+ Array.from(_chunkVE2X4KMGcjs.KEYS.LAST_PUSHED_ALARM)
799
952
  ],
800
953
  prefixes: [
801
954
  {
802
- prefix: Array.from(_chunkLD5YASJUcjs.workflowStoragePrefix.call(void 0, )),
955
+ prefix: Array.from(_chunkVE2X4KMGcjs.workflowStoragePrefix.call(void 0, )),
803
956
  maxBytes: _nullishCoalesce(options.preloadMaxWorkflowBytes, () => ( 131072)),
804
957
  partial: false
805
958
  },
806
959
  {
807
- prefix: Array.from(_chunkLD5YASJUcjs.KEYS.CONN_PREFIX),
960
+ prefix: Array.from(_chunkVE2X4KMGcjs.KEYS.CONN_PREFIX),
808
961
  maxBytes: _nullishCoalesce(options.preloadMaxConnectionsBytes, () => ( 65536)),
809
962
  partial: false
810
963
  },
811
964
  {
812
- prefix: Array.from(_chunkLD5YASJUcjs.queueMessagesPrefix.call(void 0, )),
965
+ prefix: Array.from(_chunkVE2X4KMGcjs.queueMessagesPrefix.call(void 0, )),
813
966
  maxBytes: 65536,
814
967
  partial: false
815
968
  }
@@ -879,7 +1032,7 @@ var DocRegistryConfigSchema = _zod.z.object({
879
1032
  noWelcome: _zod.z.boolean().optional().describe("Disable the welcome message on startup. Default: false"),
880
1033
  sqlite: DocSqliteConfigSchema,
881
1034
  logging: _zod.z.object({
882
- level: _chunkJ5P6S2LCcjs.LogLevelSchema.optional().describe(
1035
+ level: _chunkVNMIAPPFcjs.LogLevelSchema.optional().describe(
883
1036
  "Log level for RivetKit. Default: 'warn'"
884
1037
  )
885
1038
  }).optional().describe("Logging configuration."),
@@ -924,7 +1077,7 @@ function shouldAttachNativeKvError(message) {
924
1077
  function enrichNativeDatabaseError(database, error) {
925
1078
  var _a;
926
1079
  const bridgeReason = typeof error === "string" ? error : error instanceof Error ? error.message : void 0;
927
- const bridged = bridgeReason === void 0 ? void 0 : _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, bridgeReason);
1080
+ const bridged = bridgeReason === void 0 ? void 0 : _chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, bridgeReason);
928
1081
  if (bridged) {
929
1082
  throw bridged;
930
1083
  }
@@ -1424,6 +1577,9 @@ var NapiCoreRuntime = (_class = class {
1424
1577
  async actorWaitForTrackedShutdownWork(ctx) {
1425
1578
  return await asNativeActorContext(ctx).waitForTrackedShutdownWork();
1426
1579
  }
1580
+ async actorWaitForTrackedShutdownWorkUnbounded(ctx) {
1581
+ await asNativeActorContext(ctx).waitForTrackedShutdownWorkUnbounded();
1582
+ }
1427
1583
  actorKeepAwake(ctx, promise) {
1428
1584
  asNativeActorContext(ctx).keepAwake(promise);
1429
1585
  }
@@ -1535,8 +1691,12 @@ var NapiCoreRuntime = (_class = class {
1535
1691
  )
1536
1692
  );
1537
1693
  }
1538
- async actorQueueWaitForNamesAvailable(ctx, names, options) {
1539
- await asNativeActorContext(ctx).queue().waitForNamesAvailable(names, options);
1694
+ async actorQueueWaitForNamesAvailable(ctx, names, options, signal) {
1695
+ await asNativeActorContext(ctx).queue().waitForNamesAvailable(
1696
+ names,
1697
+ options,
1698
+ signal ? asNativeCancellationToken(signal) : signal
1699
+ );
1540
1700
  }
1541
1701
  async actorQueueEnqueueAndWait(ctx, name, body, options, signal) {
1542
1702
  return await asNativeActorContext(ctx).queue().enqueueAndWait(
@@ -1670,20 +1830,18 @@ function validateQueueComplete(schemas, name, response) {
1670
1830
  response
1671
1831
  );
1672
1832
  if (!result.success) {
1673
- throw validationError(`queue \`${name}\` completion response`, result.issues);
1833
+ throw validationError(
1834
+ `queue \`${name}\` completion response`,
1835
+ result.issues
1836
+ );
1674
1837
  }
1675
1838
  return result.data;
1676
1839
  }
1677
1840
  function validationError(target, issues) {
1678
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
1679
- "actor",
1680
- "validation_error",
1681
- `Invalid ${target}`,
1682
- {
1683
- public: true,
1684
- metadata: { issues }
1685
- }
1686
- );
1841
+ return new (0, _chunkKORQB2IRcjs.RivetError)("actor", "validation_error", `Invalid ${target}`, {
1842
+ public: true,
1843
+ metadata: { issues }
1844
+ });
1687
1845
  }
1688
1846
 
1689
1847
  // src/registry/wasm-runtime.ts
@@ -1749,16 +1907,16 @@ function normalizeQueueMessage(message) {
1749
1907
  }
1750
1908
  function normalizeWasmBridgeError(error) {
1751
1909
  if (typeof error === "string") {
1752
- return _nullishCoalesce(_chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
1910
+ return _nullishCoalesce(_chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
1753
1911
  }
1754
1912
  if (error instanceof Error) {
1755
- const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.message);
1913
+ const bridged = _chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error.message);
1756
1914
  if (bridged) {
1757
1915
  return bridged;
1758
1916
  }
1759
1917
  }
1760
1918
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
1761
- const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.reason);
1919
+ const bridged = _chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error.reason);
1762
1920
  if (bridged) {
1763
1921
  return bridged;
1764
1922
  }
@@ -1780,7 +1938,7 @@ function callWasmSync(invoke) {
1780
1938
  }
1781
1939
  }
1782
1940
  function unsupportedWasmMethod(method2) {
1783
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
1941
+ throw new (0, _chunkKORQB2IRcjs.RivetError)(
1784
1942
  "runtime",
1785
1943
  "unsupported",
1786
1944
  `Unsupported wasm runtime method: ${method2}`,
@@ -2007,6 +2165,12 @@ var WasmCoreRuntime = (_class2 = class {
2007
2165
  "waitForTrackedShutdownWork"
2008
2166
  );
2009
2167
  }
2168
+ async actorWaitForTrackedShutdownWorkUnbounded(ctx) {
2169
+ await callHandle(
2170
+ asWasmActorContext(ctx),
2171
+ "waitForTrackedShutdownWorkUnbounded"
2172
+ );
2173
+ }
2010
2174
  actorKeepAwake(ctx, promise) {
2011
2175
  const wasmCtx = asWasmActorContext(ctx);
2012
2176
  const regionId = callHandle(wasmCtx, "beginKeepAwake");
@@ -2154,9 +2318,15 @@ var WasmCoreRuntime = (_class2 = class {
2154
2318
  )
2155
2319
  );
2156
2320
  }
2157
- async actorQueueWaitForNamesAvailable(ctx, names, options) {
2321
+ async actorQueueWaitForNamesAvailable(ctx, names, options, signal) {
2158
2322
  const queue2 = childHandle(asWasmActorContext(ctx), "queue");
2159
- await callHandleAsync(queue2, "waitForNamesAvailable", names, options);
2323
+ await callHandleAsync(
2324
+ queue2,
2325
+ "waitForNamesAvailable",
2326
+ names,
2327
+ options,
2328
+ signal
2329
+ );
2160
2330
  }
2161
2331
  async actorQueueEnqueueAndWait(ctx, name, body, options, signal) {
2162
2332
  const queue2 = childHandle(asWasmActorContext(ctx), "queue");
@@ -2248,6 +2418,29 @@ async function loadWasmRuntime(config) {
2248
2418
  };
2249
2419
  }
2250
2420
 
2421
+ // src/registry/write-through-proxy.ts
2422
+ var _onchange = require('@rivetkit/on-change'); var _onchange2 = _interopRequireDefault(_onchange);
2423
+ function createWriteThroughProxy(value, commit, beforeChange) {
2424
+ if (!value || typeof value !== "object") {
2425
+ return value;
2426
+ }
2427
+ return _onchange2.default.call(void 0,
2428
+ value,
2429
+ () => {
2430
+ commit(value);
2431
+ },
2432
+ {
2433
+ // Rejection is throw-based: beforeChange throws to prevent the
2434
+ // mutation. We always return true so on-change applies the change
2435
+ // if beforeChange did not throw.
2436
+ onValidate(_path, newValue) {
2437
+ beforeChange == null ? void 0 : beforeChange(newValue);
2438
+ return true;
2439
+ }
2440
+ }
2441
+ );
2442
+ }
2443
+
2251
2444
  // src/registry/native.ts
2252
2445
  var textEncoder = new TextEncoder();
2253
2446
  var textDecoder = new TextDecoder();
@@ -2281,7 +2474,7 @@ function loadedRuntimeKind(runtime) {
2281
2474
  case "wasm":
2282
2475
  return "wasm";
2283
2476
  }
2284
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
2477
+ throw new (0, _chunkKORQB2IRcjs.RivetError)(
2285
2478
  "config",
2286
2479
  "unknown_runtime",
2287
2480
  "RivetKit runtime must be NAPI or wasm.",
@@ -2321,7 +2514,7 @@ function normalizeRuntimeConfigForKind(config, runtimeKind) {
2321
2514
  return config;
2322
2515
  }
2323
2516
  if (sqliteBackendForConfig(config) === "local") {
2324
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
2517
+ throw new (0, _chunkKORQB2IRcjs.RivetError)(
2325
2518
  "config",
2326
2519
  "wasm_local_sqlite",
2327
2520
  "WebAssembly runtime cannot use local SQLite. Use remote SQLite instead.",
@@ -2387,22 +2580,30 @@ function getNativeConnPersistState(runtime, ctx, conn) {
2387
2580
  return connState;
2388
2581
  }
2389
2582
  function stateMutationReentrantError() {
2390
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
2583
+ return new (0, _chunkKORQB2IRcjs.RivetError)(
2391
2584
  "actor",
2392
2585
  "state_mutation_reentrant",
2393
2586
  "State mutations are not allowed inside onStateChange."
2394
2587
  );
2395
2588
  }
2396
2589
  function databaseNotConfiguredError() {
2397
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
2590
+ return new (0, _chunkKORQB2IRcjs.RivetError)(
2398
2591
  "actor",
2399
2592
  "database_not_configured",
2400
2593
  "database is not configured for this actor",
2401
2594
  { public: true }
2402
2595
  );
2403
2596
  }
2597
+ function databaseClientNotReadyError() {
2598
+ return new (0, _chunkKORQB2IRcjs.RivetError)(
2599
+ "actor",
2600
+ "database_client_not_ready",
2601
+ "actor database client was not initialized before user code ran. this is an internal lifecycle error; the migration callback should have pre-warmed the client. file an issue if you can reproduce.",
2602
+ { public: true }
2603
+ );
2604
+ }
2404
2605
  function stateNotEnabledError() {
2405
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
2606
+ return new (0, _chunkKORQB2IRcjs.RivetError)(
2406
2607
  "actor",
2407
2608
  "state_not_enabled",
2408
2609
  "State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.dev/docs/actors/state/#initializing-state)",
@@ -2410,7 +2611,7 @@ function stateNotEnabledError() {
2410
2611
  );
2411
2612
  }
2412
2613
  function nativeClientNotConfiguredError() {
2413
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
2614
+ return new (0, _chunkKORQB2IRcjs.RivetError)(
2414
2615
  "native",
2415
2616
  "client_not_configured",
2416
2617
  "native actor client is not configured",
@@ -2418,7 +2619,7 @@ function nativeClientNotConfiguredError() {
2418
2619
  );
2419
2620
  }
2420
2621
  function nativeEndpointNotConfiguredError() {
2421
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
2622
+ return new (0, _chunkKORQB2IRcjs.RivetError)(
2422
2623
  "native",
2423
2624
  "endpoint_not_configured",
2424
2625
  "registry endpoint is required for native envoy startup",
@@ -2452,8 +2653,23 @@ function resolveNativeDestroy(runtime, ctx) {
2452
2653
  function clearNativeRuntimeState(runtime, ctx) {
2453
2654
  callNativeSync(() => runtime.actorClearRuntimeState(ctx));
2454
2655
  }
2455
- async function cleanupNativeSleepRuntimeState(runtime, ctx) {
2456
- await runtime.actorWaitForTrackedShutdownWork(ctx);
2656
+ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrained) {
2657
+ const drained = await runtime.actorWaitForTrackedShutdownWork(ctx);
2658
+ if (!drained) {
2659
+ await closeNativeDatabaseClient(runtime, ctx);
2660
+ await closeNativeSqlDatabase(runtime, ctx);
2661
+ void runtime.actorWaitForTrackedShutdownWorkUnbounded(ctx).then(async () => {
2662
+ await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
2663
+ clearNativeRuntimeState(runtime, ctx);
2664
+ }).catch((error) => {
2665
+ logger2().warn({
2666
+ msg: "deferred native sleep cleanup failed",
2667
+ error: _chunkVNMIAPPFcjs.stringifyError.call(void 0, error)
2668
+ });
2669
+ });
2670
+ return;
2671
+ }
2672
+ await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
2457
2673
  await closeNativeDatabaseClient(runtime, ctx);
2458
2674
  await closeNativeSqlDatabase(runtime, ctx);
2459
2675
  clearNativeRuntimeState(runtime, ctx);
@@ -2558,10 +2774,10 @@ function decodeValue(value) {
2558
2774
  if (!value || value.length === 0) {
2559
2775
  return void 0;
2560
2776
  }
2561
- return _chunkPWFGP2UScjs.decodeCborJsonCompat.call(void 0, value);
2777
+ return _chunkSS56HFM2cjs.decodeCborCompat.call(void 0, value);
2562
2778
  }
2563
2779
  function encodeValue(value) {
2564
- return _chunkPWFGP2UScjs.encodeCborCompat.call(void 0, value);
2780
+ return _chunkSS56HFM2cjs.encodeCborCompat.call(void 0, value);
2565
2781
  }
2566
2782
  function unwrapTsfnPayload(error, payload) {
2567
2783
  if (error !== null && error !== void 0) {
@@ -2571,16 +2787,16 @@ function unwrapTsfnPayload(error, payload) {
2571
2787
  }
2572
2788
  function normalizeNativeBridgeError(error) {
2573
2789
  if (typeof error === "string") {
2574
- return _nullishCoalesce(_chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2790
+ return _nullishCoalesce(_chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2575
2791
  }
2576
2792
  if (error instanceof Error) {
2577
- const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.message);
2793
+ const bridged = _chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error.message);
2578
2794
  if (bridged) {
2579
2795
  return bridged;
2580
2796
  }
2581
2797
  }
2582
2798
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
2583
- const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.reason);
2799
+ const bridged = _chunkKORQB2IRcjs.decodeBridgeRivetError.call(void 0, error.reason);
2584
2800
  if (bridged) {
2585
2801
  return bridged;
2586
2802
  }
@@ -2588,14 +2804,14 @@ function normalizeNativeBridgeError(error) {
2588
2804
  return error;
2589
2805
  }
2590
2806
  function isStructuredBridgeError(error) {
2591
- if (error instanceof _chunkQAZLM4WTcjs.RivetError) {
2807
+ if (error instanceof _chunkKORQB2IRcjs.RivetError) {
2592
2808
  return true;
2593
2809
  }
2594
- return _chunkQAZLM4WTcjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
2810
+ return _chunkKORQB2IRcjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
2595
2811
  }
2596
2812
  function encodeNativeCallbackError(error) {
2597
- const structuredError = isStructuredBridgeError(error) ? error : _chunkJ5P6S2LCcjs.deconstructError.call(void 0, error, true);
2598
- const bridgeError = new Error(_chunkQAZLM4WTcjs.encodeBridgeRivetError.call(void 0, structuredError), {
2813
+ const structuredError = isStructuredBridgeError(error) ? error : _chunkVNMIAPPFcjs.deconstructError.call(void 0, error, true);
2814
+ const bridgeError = new Error(_chunkKORQB2IRcjs.encodeBridgeRivetError.call(void 0, structuredError), {
2599
2815
  cause: error instanceof Error ? error : void 0
2600
2816
  });
2601
2817
  return Object.assign(bridgeError, {
@@ -2618,16 +2834,10 @@ function callNativeSync(invoke) {
2618
2834
  throw normalizeNativeBridgeError(error);
2619
2835
  }
2620
2836
  }
2621
- function actorAbortedError() {
2622
- return Object.assign(new Error("Actor aborted"), {
2623
- group: "actor",
2624
- code: "aborted"
2625
- });
2626
- }
2627
2837
  function isClosedTaskRegistrationError(error) {
2628
- const metadata = error instanceof _chunkQAZLM4WTcjs.RivetError ? error.metadata : void 0;
2838
+ const metadata = error instanceof _chunkKORQB2IRcjs.RivetError ? error.metadata : void 0;
2629
2839
  const metadataError = metadata && typeof metadata === "object" && "error" in metadata ? metadata.error : void 0;
2630
- return error instanceof _chunkQAZLM4WTcjs.RivetError && error.group === "core" && error.code === _chunkQAZLM4WTcjs.INTERNAL_ERROR_CODE && typeof metadataError === "string" && /actor task registration is (closed|not configured)/.test(metadataError);
2840
+ return error instanceof _chunkKORQB2IRcjs.RivetError && error.group === "core" && error.code === _chunkKORQB2IRcjs.INTERNAL_ERROR_CODE && typeof metadataError === "string" && /actor task registration is (closed|not configured)/.test(metadataError);
2631
2841
  }
2632
2842
  async function createCancellationTokenHandle(runtime, signal) {
2633
2843
  if (!signal) {
@@ -2650,7 +2860,7 @@ function decodeWorkflowCbor(data) {
2650
2860
  return null;
2651
2861
  }
2652
2862
  try {
2653
- return _chunkPWFGP2UScjs.decodeCborCompat.call(void 0, new Uint8Array(data));
2863
+ return _chunkSS56HFM2cjs.decodeCborCompat.call(void 0, new Uint8Array(data));
2654
2864
  } catch (e3) {
2655
2865
  return null;
2656
2866
  }
@@ -2755,8 +2965,8 @@ function serializeWorkflowHistoryForJson(data) {
2755
2965
  if (data === null) {
2756
2966
  return null;
2757
2967
  }
2758
- const history = _chunkG5RULGYQcjs.decodeWorkflowHistoryTransport.call(void 0, data);
2759
- return {
2968
+ const history = _chunkC7AAIILHcjs.decodeWorkflowHistoryTransport.call(void 0, data);
2969
+ return jsonSafe({
2760
2970
  nameRegistry: [...history.nameRegistry],
2761
2971
  entries: history.entries.map((entry) => ({
2762
2972
  id: entry.id,
@@ -2780,7 +2990,7 @@ function serializeWorkflowHistoryForJson(data) {
2780
2990
  ]
2781
2991
  )
2782
2992
  )
2783
- };
2993
+ });
2784
2994
  }
2785
2995
  function toHttpJsonCompatible(value) {
2786
2996
  return JSON.parse(
@@ -2833,44 +3043,6 @@ function decodeArgs(value) {
2833
3043
  const decoded = decodeValue(value);
2834
3044
  return Array.isArray(decoded) ? decoded : decoded === void 0 ? [] : [decoded];
2835
3045
  }
2836
- function createWriteThroughProxy(value, commit, beforeChange) {
2837
- if (!value || typeof value !== "object") {
2838
- return value;
2839
- }
2840
- const proxies = /* @__PURE__ */ new WeakMap();
2841
- const wrap = (target) => {
2842
- const cached = proxies.get(target);
2843
- if (cached) {
2844
- return cached;
2845
- }
2846
- const proxy = new Proxy(target, {
2847
- get(innerTarget, property, receiver) {
2848
- const result = Reflect.get(innerTarget, property, receiver);
2849
- return result && typeof result === "object" ? wrap(result) : result;
2850
- },
2851
- set(innerTarget, property, nextValue, receiver) {
2852
- beforeChange == null ? void 0 : beforeChange();
2853
- const updated = Reflect.set(
2854
- innerTarget,
2855
- property,
2856
- nextValue,
2857
- receiver
2858
- );
2859
- commit(value);
2860
- return updated;
2861
- },
2862
- deleteProperty(innerTarget, property) {
2863
- beforeChange == null ? void 0 : beforeChange();
2864
- const updated = Reflect.deleteProperty(innerTarget, property);
2865
- commit(value);
2866
- return updated;
2867
- }
2868
- });
2869
- proxies.set(target, proxy);
2870
- return proxy;
2871
- };
2872
- return wrap(value);
2873
- }
2874
3046
  function buildRequest(init) {
2875
3047
  const url = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
2876
3048
  const body = init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
@@ -2906,7 +3078,7 @@ var NativeConnAdapter = class {
2906
3078
  this.#schemas = schemas;
2907
3079
  this.#ctx = ctx;
2908
3080
  this.#queueHibernationRemoval = queueHibernationRemoval;
2909
- this[_chunkWQ4HNA4Wcjs.CONN_STATE_MANAGER_SYMBOL] = {
3081
+ this[_chunkWHYBAEWGcjs.CONN_STATE_MANAGER_SYMBOL] = {
2910
3082
  stateEnabled: true,
2911
3083
  get state() {
2912
3084
  return thisConn.state;
@@ -2923,13 +3095,23 @@ var NativeConnAdapter = class {
2923
3095
  decodeValue(this.#runtime.connParams(this.#conn))
2924
3096
  );
2925
3097
  }
3098
+ [_chunkWHYBAEWGcjs.RAW_STATE_SYMBOL]() {
3099
+ return this.#readState();
3100
+ }
2926
3101
  get state() {
2927
3102
  const nextState = this.#readState();
2928
- return createWriteThroughProxy(nextState, (nextValue) => {
2929
- this.#writeState(nextValue, { writeNative: true });
2930
- });
3103
+ return createWriteThroughProxy(
3104
+ nextState,
3105
+ (nextValue) => {
3106
+ this.#writeState(nextValue, { writeNative: true });
3107
+ },
3108
+ (newValue) => {
3109
+ _chunkSS56HFM2cjs.assertJsonCompatValue.call(void 0, newValue);
3110
+ }
3111
+ );
2931
3112
  }
2932
3113
  set state(value) {
3114
+ _chunkSS56HFM2cjs.assertJsonCompatValue.call(void 0, value);
2933
3115
  this.#writeState(value, { writeNative: true });
2934
3116
  }
2935
3117
  initializeState(value) {
@@ -3034,7 +3216,7 @@ var NativeKvAdapter = class {
3034
3216
  const value = await callNative(
3035
3217
  () => this.#runtime.actorKvGet(
3036
3218
  this.#ctx,
3037
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
3219
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
3038
3220
  )
3039
3221
  );
3040
3222
  return value ? decodeNativeKvValue(new Uint8Array(value), options) : null;
@@ -3043,7 +3225,7 @@ var NativeKvAdapter = class {
3043
3225
  await callNative(
3044
3226
  () => this.#runtime.actorKvPut(
3045
3227
  this.#ctx,
3046
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key)),
3228
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key)),
3047
3229
  toRuntimeBytes(value)
3048
3230
  )
3049
3231
  );
@@ -3052,7 +3234,7 @@ var NativeKvAdapter = class {
3052
3234
  await callNative(
3053
3235
  () => this.#runtime.actorKvDelete(
3054
3236
  this.#ctx,
3055
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
3237
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
3056
3238
  )
3057
3239
  );
3058
3240
  }
@@ -3060,8 +3242,8 @@ var NativeKvAdapter = class {
3060
3242
  await callNative(
3061
3243
  () => this.#runtime.actorKvDeleteRange(
3062
3244
  this.#ctx,
3063
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(start)),
3064
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(end))
3245
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(start)),
3246
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(end))
3065
3247
  )
3066
3248
  );
3067
3249
  }
@@ -3074,7 +3256,7 @@ var NativeKvAdapter = class {
3074
3256
  const entries = await callNative(
3075
3257
  () => this.#runtime.actorKvListPrefix(
3076
3258
  this.#ctx,
3077
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0,
3259
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0,
3078
3260
  encodeNativeKvUserKey(
3079
3261
  prefix,
3080
3262
  options == null ? void 0 : options.keyType
@@ -3088,7 +3270,7 @@ var NativeKvAdapter = class {
3088
3270
  );
3089
3271
  return entries.map((entry) => [
3090
3272
  decodeNativeKvKey(
3091
- _chunkLD5YASJUcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
3273
+ _chunkVE2X4KMGcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
3092
3274
  options == null ? void 0 : options.keyType
3093
3275
  ),
3094
3276
  decodeNativeKvValue(new Uint8Array(entry.value), options)
@@ -3107,13 +3289,13 @@ var NativeKvAdapter = class {
3107
3289
  const entries = await callNative(
3108
3290
  () => this.#runtime.actorKvListRange(
3109
3291
  this.#ctx,
3110
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0,
3292
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0,
3111
3293
  encodeNativeKvUserKey(
3112
3294
  start,
3113
3295
  options == null ? void 0 : options.keyType
3114
3296
  )
3115
3297
  ),
3116
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0,
3298
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0,
3117
3299
  encodeNativeKvUserKey(
3118
3300
  end,
3119
3301
  options == null ? void 0 : options.keyType
@@ -3127,7 +3309,7 @@ var NativeKvAdapter = class {
3127
3309
  );
3128
3310
  return entries.map((entry) => [
3129
3311
  decodeNativeKvKey(
3130
- _chunkLD5YASJUcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
3312
+ _chunkVE2X4KMGcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
3131
3313
  options == null ? void 0 : options.keyType
3132
3314
  ),
3133
3315
  decodeNativeKvValue(new Uint8Array(entry.value), options)
@@ -3219,7 +3401,7 @@ var NativeQueueAdapter = class {
3219
3401
  async nextBatch(options) {
3220
3402
  const completable = (options == null ? void 0 : options.completable) === true;
3221
3403
  if (this.#pendingCompletableMessageIds.size > 0) {
3222
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3404
+ throw new (0, _chunkKORQB2IRcjs.RivetError)(
3223
3405
  "queue",
3224
3406
  "previous_message_not_completed",
3225
3407
  "Previous completable queue message is not completed. Call `message.complete(...)` before receiving the next message.",
@@ -3281,44 +3463,23 @@ var NativeQueueAdapter = class {
3281
3463
  }
3282
3464
  }
3283
3465
  async waitForNamesAvailable(names, options) {
3284
- if (!(options == null ? void 0 : options.signal)) {
3466
+ const { token, cleanup } = await createCancellationTokenHandle(
3467
+ this.#runtime,
3468
+ options == null ? void 0 : options.signal
3469
+ );
3470
+ try {
3285
3471
  await callNative(
3286
3472
  () => this.#runtime.actorQueueWaitForNamesAvailable(
3287
3473
  this.#ctx,
3288
3474
  [...names],
3289
3475
  {
3290
3476
  timeoutMs: options == null ? void 0 : options.timeout
3291
- }
3477
+ },
3478
+ token
3292
3479
  )
3293
3480
  );
3294
- return;
3295
- }
3296
- const deadline = options.timeout === void 0 ? void 0 : Date.now() + options.timeout;
3297
- for (; ; ) {
3298
- if (options.signal.aborted) {
3299
- throw actorAbortedError();
3300
- }
3301
- const remainingTimeout = deadline === void 0 ? void 0 : Math.max(0, deadline - Date.now());
3302
- const sliceTimeout = remainingTimeout === void 0 ? 100 : Math.min(remainingTimeout, 100);
3303
- try {
3304
- await callNative(
3305
- () => this.#runtime.actorQueueWaitForNamesAvailable(
3306
- this.#ctx,
3307
- [...names],
3308
- {
3309
- timeoutMs: sliceTimeout
3310
- }
3311
- )
3312
- );
3313
- return;
3314
- } catch (error) {
3315
- if (error.group === "queue" && error.code === "timed_out") {
3316
- if (remainingTimeout === void 0 || remainingTimeout > 100) {
3317
- continue;
3318
- }
3319
- }
3320
- throw error;
3321
- }
3481
+ } finally {
3482
+ cleanup == null ? void 0 : cleanup();
3322
3483
  }
3323
3484
  }
3324
3485
  async enqueueAndWait(name, body, options) {
@@ -3388,7 +3549,7 @@ var NativeQueueAdapter = class {
3388
3549
  }
3389
3550
  yield message;
3390
3551
  } catch (error) {
3391
- if (_chunkQAZLM4WTcjs.isRivetErrorLike.call(void 0, error) && error.group === "actor" && error.code === "aborted") {
3552
+ if (_chunkKORQB2IRcjs.isRivetErrorLike.call(void 0, error) && error.group === "actor" && error.code === "aborted") {
3392
3553
  return;
3393
3554
  }
3394
3555
  throw error;
@@ -3409,7 +3570,7 @@ var NativeQueueAdapter = class {
3409
3570
  ...message,
3410
3571
  complete: async (response) => {
3411
3572
  if (typeof message.complete !== "function") {
3412
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3573
+ throw new (0, _chunkKORQB2IRcjs.RivetError)(
3413
3574
  "queue",
3414
3575
  "complete_not_configured",
3415
3576
  `Queue '${message.name}' does not support completion responses.`,
@@ -3421,7 +3582,7 @@ var NativeQueueAdapter = class {
3421
3582
  );
3422
3583
  }
3423
3584
  if (completed) {
3424
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3585
+ throw new (0, _chunkKORQB2IRcjs.RivetError)(
3425
3586
  "queue",
3426
3587
  "already_completed",
3427
3588
  "Queue message was already completed.",
@@ -3753,6 +3914,68 @@ var TrackedWebSocketHandleAdapter = class {
3753
3914
  return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
3754
3915
  }
3755
3916
  };
3917
+ var NativeConnectionMap = (_class3 = class {
3918
+ #runtime;
3919
+ #ctx;
3920
+ #schemas;
3921
+ constructor(runtime, ctx, schemas) {;_class3.prototype.__init3.call(this);
3922
+ this.#runtime = runtime;
3923
+ this.#ctx = ctx;
3924
+ this.#schemas = schemas;
3925
+ }
3926
+ #connToAdapter(conn) {
3927
+ return new NativeConnAdapter(
3928
+ this.#runtime,
3929
+ conn,
3930
+ this.#schemas,
3931
+ this.#ctx,
3932
+ (connId) => callNativeSync(
3933
+ () => this.#runtime.actorQueueHibernationRemoval(
3934
+ this.#ctx,
3935
+ connId
3936
+ )
3937
+ )
3938
+ );
3939
+ }
3940
+ get size() {
3941
+ return callNativeSync(() => this.#runtime.actorConns(this.#ctx)).length;
3942
+ }
3943
+ get(key) {
3944
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3945
+ const conn = conns.find((c) => this.#runtime.connId(c) === key);
3946
+ if (!conn) return void 0;
3947
+ return this.#connToAdapter(conn);
3948
+ }
3949
+ has(key) {
3950
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3951
+ return conns.some((c) => this.#runtime.connId(c) === key);
3952
+ }
3953
+ keys() {
3954
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3955
+ return conns.map((c) => this.#runtime.connId(c))[Symbol.iterator]();
3956
+ }
3957
+ values() {
3958
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3959
+ return conns.map((c) => this.#connToAdapter(c))[Symbol.iterator]();
3960
+ }
3961
+ entries() {
3962
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3963
+ return conns.map(
3964
+ (c) => [this.#runtime.connId(c), this.#connToAdapter(c)]
3965
+ )[Symbol.iterator]();
3966
+ }
3967
+ forEach(callback, thisArg) {
3968
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3969
+ for (const conn of conns) {
3970
+ const id = this.#runtime.connId(conn);
3971
+ callback.call(thisArg, this.#connToAdapter(conn), id, this);
3972
+ }
3973
+ }
3974
+ [Symbol.iterator]() {
3975
+ return this.entries();
3976
+ }
3977
+ __init3() {this[Symbol.toStringTag] = "NativeConnectionMap"}
3978
+ }, _class3);
3756
3979
  var ActorContextHandleAdapter = class {
3757
3980
  #runtime;
3758
3981
  #ctx;
@@ -3761,9 +3984,9 @@ var ActorContextHandleAdapter = class {
3761
3984
  #abortSignalCleanup;
3762
3985
  #client;
3763
3986
  #clientFactory;
3987
+ #connMap;
3764
3988
  #databaseProvider;
3765
3989
  #db;
3766
- #dbProxy;
3767
3990
  #dispatchCancelToken;
3768
3991
  #kv;
3769
3992
  #queue;
@@ -3786,7 +4009,7 @@ var ActorContextHandleAdapter = class {
3786
4009
  this.#databaseProvider = databaseProvider;
3787
4010
  }
3788
4011
  this.#request = request;
3789
- this[_chunkWQ4HNA4Wcjs.ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
4012
+ this[_chunkWHYBAEWGcjs.ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
3790
4013
  this
3791
4014
  );
3792
4015
  }
@@ -3806,30 +4029,22 @@ var ActorContextHandleAdapter = class {
3806
4029
  if (!this.#databaseProvider) {
3807
4030
  throw databaseNotConfiguredError();
3808
4031
  }
3809
- if (!this.#dbProxy) {
3810
- this.#dbProxy = new Proxy(
3811
- {},
3812
- {
3813
- get: (_target, property) => {
3814
- if (property === "then") {
3815
- return void 0;
3816
- }
3817
- return async (...args) => {
3818
- const client = await this.ensureDatabaseClient();
3819
- const value = Reflect.get(
3820
- client,
3821
- property
3822
- );
3823
- if (typeof value !== "function") {
3824
- return value;
3825
- }
3826
- return await value.apply(client, args);
3827
- };
3828
- }
3829
- }
3830
- );
4032
+ if (this.#db) {
4033
+ return this.#db;
3831
4034
  }
3832
- return this.#dbProxy;
4035
+ const runtimeState = getNativeRuntimeState(this.#runtime, this.#ctx);
4036
+ const cachedClient = runtimeState.databaseClient;
4037
+ if (cachedClient) {
4038
+ this.#db = cachedClient.client;
4039
+ return this.#db;
4040
+ }
4041
+ throw databaseClientNotReadyError();
4042
+ }
4043
+ [_chunkWHYBAEWGcjs.RAW_STATE_SYMBOL]() {
4044
+ if (!this.#stateEnabled) {
4045
+ throw stateNotEnabledError();
4046
+ }
4047
+ return this.#readState();
3833
4048
  }
3834
4049
  get state() {
3835
4050
  if (!this.#stateEnabled) {
@@ -3844,8 +4059,9 @@ var ActorContextHandleAdapter = class {
3844
4059
  (nextValue) => {
3845
4060
  this.#writeState(nextValue, { scheduleSave: true });
3846
4061
  },
3847
- () => {
4062
+ (newValue) => {
3848
4063
  this.#assertCanMutateState();
4064
+ _chunkSS56HFM2cjs.assertJsonCompatValue.call(void 0, newValue);
3849
4065
  }
3850
4066
  );
3851
4067
  }
@@ -3856,6 +4072,7 @@ var ActorContextHandleAdapter = class {
3856
4072
  throw stateNotEnabledError();
3857
4073
  }
3858
4074
  this.#assertCanMutateState();
4075
+ _chunkSS56HFM2cjs.assertJsonCompatValue.call(void 0, value);
3859
4076
  this.#writeState(value, { scheduleSave: true });
3860
4077
  }
3861
4078
  initializeState(value) {
@@ -3912,25 +4129,14 @@ var ActorContextHandleAdapter = class {
3912
4129
  return callNativeSync(() => this.#runtime.actorRegion(this.#ctx));
3913
4130
  }
3914
4131
  get conns() {
3915
- return new Map(
3916
- callNativeSync(() => this.#runtime.actorConns(this.#ctx)).map(
3917
- (conn) => [
3918
- this.#runtime.connId(conn),
3919
- new NativeConnAdapter(
3920
- this.#runtime,
3921
- conn,
3922
- this.#schemas,
3923
- this.#ctx,
3924
- (connId) => callNativeSync(
3925
- () => this.#runtime.actorQueueHibernationRemoval(
3926
- this.#ctx,
3927
- connId
3928
- )
3929
- )
3930
- )
3931
- ]
3932
- )
3933
- );
4132
+ if (!this.#connMap) {
4133
+ this.#connMap = new NativeConnectionMap(
4134
+ this.#runtime,
4135
+ this.#ctx,
4136
+ this.#schemas
4137
+ );
4138
+ }
4139
+ return this.#connMap;
3934
4140
  }
3935
4141
  get log() {
3936
4142
  return logger2();
@@ -4131,7 +4337,7 @@ var ActorContextHandleAdapter = class {
4131
4337
  const trackedPromise = Promise.resolve(promise).catch((error) => {
4132
4338
  logger2().warn({
4133
4339
  msg: "keepAwake promise rejected",
4134
- error: _chunkJ5P6S2LCcjs.stringifyError.call(void 0, error)
4340
+ error: _chunkVNMIAPPFcjs.stringifyError.call(void 0, error)
4135
4341
  });
4136
4342
  }).then(() => null);
4137
4343
  try {
@@ -4207,6 +4413,7 @@ var ActorContextHandleAdapter = class {
4207
4413
  return false;
4208
4414
  }
4209
4415
  sleep() {
4416
+ this.#flushStateChange();
4210
4417
  callNativeSync(() => this.#runtime.actorSleep(this.#ctx));
4211
4418
  }
4212
4419
  destroy() {
@@ -4512,9 +4719,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4512
4719
  const actionHandlers = Object.fromEntries(
4513
4720
  Object.entries(_nullishCoalesce(config.actions, () => ( {}))).map(([name, handler]) => [name, handler])
4514
4721
  );
4515
- const createClient = () => _chunkTE4VCDNYcjs.createClientWithDriver.call(void 0,
4516
- new (0, _chunkTE4VCDNYcjs.RemoteEngineControlClient)(
4517
- _chunkTE4VCDNYcjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
4722
+ const createClient = () => _chunk2U6RLFKXcjs.createClientWithDriver.call(void 0,
4723
+ new (0, _chunk2U6RLFKXcjs.RemoteEngineControlClient)(
4724
+ _chunk2U6RLFKXcjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
4518
4725
  ),
4519
4726
  { encoding: "bare" }
4520
4727
  );
@@ -4524,7 +4731,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4524
4731
  ), () => ( false));
4525
4732
  const getNativeWorkflowInspector = (ctx) => {
4526
4733
  var _a2;
4527
- return (_a2 = _chunkWQ4HNA4Wcjs.getRunInspectorConfig.call(void 0,
4734
+ return (_a2 = _chunkWHYBAEWGcjs.getRunInspectorConfig.call(void 0,
4528
4735
  config.run,
4529
4736
  callNativeSync(() => runtime.actorId(ctx))
4530
4737
  )) == null ? void 0 : _a2.workflow;
@@ -4577,7 +4784,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4577
4784
  }
4578
4785
  });
4579
4786
  const errorResponse = (error, status) => {
4580
- const rivetError = _chunkQAZLM4WTcjs.toRivetError.call(void 0, error);
4787
+ const rivetError = _chunkKORQB2IRcjs.toRivetError.call(void 0, error);
4581
4788
  return jsonResponse(
4582
4789
  {
4583
4790
  group: rivetError.group,
@@ -4687,6 +4894,10 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4687
4894
  isWorkflowEnabled: getNativeWorkflowInspector(ctx) !== void 0
4688
4895
  });
4689
4896
  } catch (error) {
4897
+ logger2().error({
4898
+ msg: "error replaying workflow history",
4899
+ error
4900
+ });
4690
4901
  return errorResponse(error);
4691
4902
  }
4692
4903
  }
@@ -4818,7 +5029,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4818
5029
  const action = actionHandlers[actionName];
4819
5030
  if (!action) {
4820
5031
  return errorResponse(
4821
- new (0, _chunkQAZLM4WTcjs.RivetError)(
5032
+ new (0, _chunkKORQB2IRcjs.RivetError)(
4822
5033
  "action",
4823
5034
  "action_not_found",
4824
5035
  `Action ${actionName} not found`
@@ -4838,6 +5049,10 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4838
5049
  );
4839
5050
  return jsonResponse({ output });
4840
5051
  } catch (error) {
5052
+ logger2().error({
5053
+ msg: "Error handling inspector action request",
5054
+ error
5055
+ });
4841
5056
  return errorResponse(error);
4842
5057
  }
4843
5058
  }
@@ -4851,6 +5066,10 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4851
5066
  { status: 404 }
4852
5067
  );
4853
5068
  } catch (error) {
5069
+ logger2().error({
5070
+ msg: "Error handling inspector request",
5071
+ error
5072
+ });
4854
5073
  return errorResponse(error);
4855
5074
  } finally {
4856
5075
  await actorCtx.dispose();
@@ -4973,24 +5192,30 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4973
5192
  async (error, payload) => {
4974
5193
  const { ctx } = unwrapTsfnPayload(error, payload);
4975
5194
  const actorCtx = makeActorCtx(ctx);
5195
+ const saveActorState = async () => {
5196
+ if (runtime.kind === "wasm") {
5197
+ await runtime.actorSaveState(
5198
+ ctx,
5199
+ actorCtx.serializeForTick("save")
5200
+ );
5201
+ } else {
5202
+ await actorCtx.saveState({
5203
+ immediate: true
5204
+ });
5205
+ }
5206
+ };
4976
5207
  try {
4977
5208
  if (onSleep) {
4978
- try {
4979
- await onSleep(actorCtx);
4980
- } finally {
4981
- if (runtime.kind === "wasm") {
4982
- await runtime.actorSaveState(
4983
- ctx,
4984
- actorCtx.serializeForTick("save")
4985
- );
4986
- } else {
4987
- await actorCtx.saveState({ immediate: true });
4988
- }
4989
- }
5209
+ await onSleep(actorCtx);
4990
5210
  }
5211
+ await saveActorState();
4991
5212
  } finally {
4992
5213
  try {
4993
- await cleanupNativeSleepRuntimeState(runtime, ctx);
5214
+ await cleanupNativeSleepRuntimeState(
5215
+ runtime,
5216
+ ctx,
5217
+ saveActorState
5218
+ );
4994
5219
  } finally {
4995
5220
  await actorCtx.dispose();
4996
5221
  }
@@ -5155,7 +5380,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5155
5380
  );
5156
5381
  }
5157
5382
  if (!result) {
5158
- throw _chunkQAZLM4WTcjs.forbiddenError.call(void 0, );
5383
+ throw _chunkKORQB2IRcjs.forbiddenError.call(void 0, );
5159
5384
  }
5160
5385
  } finally {
5161
5386
  await actorCtx.dispose();
@@ -5201,7 +5426,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5201
5426
  new Response(null, { status: 404 })
5202
5427
  );
5203
5428
  }
5204
- const rawConnParams = jsRequest.headers.get(_chunkTE4VCDNYcjs.HEADER_CONN_PARAMS);
5429
+ const rawConnParams = jsRequest.headers.get(_chunk2U6RLFKXcjs.HEADER_CONN_PARAMS);
5205
5430
  let requestCtx;
5206
5431
  let conn;
5207
5432
  try {
@@ -5266,7 +5491,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5266
5491
  }
5267
5492
  ) : void 0,
5268
5493
  run: (() => {
5269
- const run = _chunkWQ4HNA4Wcjs.getRunFunction.call(void 0, config.run);
5494
+ const run = _chunkWHYBAEWGcjs.getRunFunction.call(void 0, config.run);
5270
5495
  if (!run) {
5271
5496
  return void 0;
5272
5497
  }
@@ -5285,7 +5510,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5285
5510
  }
5286
5511
  );
5287
5512
  })(),
5288
- getWorkflowHistory: _chunkWQ4HNA4Wcjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5513
+ getWorkflowHistory: _chunkWHYBAEWGcjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5289
5514
  async (error, payload) => {
5290
5515
  var _a2;
5291
5516
  const { ctx } = unwrapTsfnPayload(error, payload);
@@ -5293,7 +5518,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5293
5518
  return history == null ? void 0 : encodeValue(history);
5294
5519
  }
5295
5520
  ) : void 0,
5296
- replayWorkflow: _chunkWQ4HNA4Wcjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5521
+ replayWorkflow: _chunkWHYBAEWGcjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5297
5522
  async (error, payload) => {
5298
5523
  const { ctx, entryId } = unwrapTsfnPayload(
5299
5524
  error,
@@ -5368,7 +5593,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5368
5593
  name
5369
5594
  );
5370
5595
  if (canPublish && !await canPublish(actorCtx)) {
5371
- throw _chunkQAZLM4WTcjs.forbiddenError.call(void 0, );
5596
+ throw _chunkKORQB2IRcjs.forbiddenError.call(void 0, );
5372
5597
  }
5373
5598
  const decodedBody = decodeValue(body);
5374
5599
  if (wait) {
@@ -5428,7 +5653,7 @@ async function buildServeConfig(config) {
5428
5653
  poolName: config.envoy.poolName,
5429
5654
  handleInspectorHttpInRuntime: true,
5430
5655
  serverlessBasePath: config.serverless.basePath,
5431
- serverlessPackageVersion: _chunkJ5P6S2LCcjs.VERSION,
5656
+ serverlessPackageVersion: _chunkVNMIAPPFcjs.VERSION,
5432
5657
  serverlessClientEndpoint: config.publicEndpoint,
5433
5658
  serverlessClientNamespace: config.publicNamespace,
5434
5659
  serverlessClientToken: config.publicToken,
@@ -5440,13 +5665,13 @@ async function buildServeConfig(config) {
5440
5665
  serveConfig.engineBinaryPath = getEnginePath();
5441
5666
  }
5442
5667
  if ((_a = config.test) == null ? void 0 : _a.enabled) {
5443
- serveConfig.inspectorTestToken = _nullishCoalesce(_chunkJ5P6S2LCcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
5668
+ serveConfig.inspectorTestToken = _nullishCoalesce(_chunkVNMIAPPFcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
5444
5669
  }
5445
5670
  return serveConfig;
5446
5671
  }
5447
5672
  async function buildRegistryWithRuntime(config, runtime) {
5448
5673
  var _a;
5449
- if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkJ5P6S2LCcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
5674
+ if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkVNMIAPPFcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
5450
5675
  trySetProcessEnv("_RIVET_TEST_INSPECTOR_TOKEN", "token");
5451
5676
  }
5452
5677
  const registry = runtime.createRegistry();
@@ -5488,6 +5713,7 @@ function finishShutdownSignal(signal) {
5488
5713
  }
5489
5714
  var Registry = class {
5490
5715
  #config;
5716
+ #buildConfiguredRegistry;
5491
5717
 
5492
5718
  get config() {
5493
5719
  return this.#config;
@@ -5503,8 +5729,9 @@ var Registry = class {
5503
5729
  #shutdownInstalled = false;
5504
5730
  #shutdownInFlight = null;
5505
5731
  #signalHandlers = {};
5506
- constructor(config) {
5732
+ constructor(config, deps) {
5507
5733
  this.#config = config;
5734
+ this.#buildConfiguredRegistry = _nullishCoalesce((deps == null ? void 0 : deps.buildConfiguredRegistry), () => ( buildConfiguredRegistry));
5508
5735
  this.routes = {
5509
5736
  health: () => this.#healthRoute(),
5510
5737
  metadata: () => this.#metadataRoute(),
@@ -5514,12 +5741,12 @@ var Registry = class {
5514
5741
  #ensureServerlessPoolConfigured(config) {
5515
5742
  if (!config.configurePool) return void 0;
5516
5743
  if (!this.#configureServerlessPoolPromise) {
5517
- this.#configureServerlessPoolPromise = configureServerlessPool(config).catch(
5518
- (error) => {
5519
- this.#configureServerlessPoolPromise = void 0;
5520
- throw error;
5521
- }
5522
- );
5744
+ this.#configureServerlessPoolPromise = configureServerlessPool(
5745
+ config
5746
+ ).catch((error) => {
5747
+ this.#configureServerlessPoolPromise = void 0;
5748
+ throw error;
5749
+ });
5523
5750
  this.#configureServerlessPoolPromise.catch(() => {
5524
5751
  });
5525
5752
  }
@@ -5540,7 +5767,7 @@ var Registry = class {
5540
5767
  const config = this.parseConfig();
5541
5768
  this.#printWelcome(config, "serverless");
5542
5769
  if (!this.#runtimeServerlessPromise) {
5543
- this.#runtimeServerlessPromise = buildConfiguredRegistry(config);
5770
+ this.#runtimeServerlessPromise = this.#buildConfiguredRegistry(config);
5544
5771
  }
5545
5772
  const { runtime, registry, serveConfig } = await this.#runtimeServerlessPromise;
5546
5773
  const isStartRequest = isServerlessStartRequest(
@@ -5555,7 +5782,7 @@ var Registry = class {
5555
5782
  if (isStartRequest) {
5556
5783
  try {
5557
5784
  await this.#ensureServerlessPoolConfigured(config);
5558
- } catch (error) {
5785
+ } catch (_error) {
5559
5786
  return new Response(
5560
5787
  JSON.stringify({
5561
5788
  group: "guard",
@@ -5669,7 +5896,7 @@ var Registry = class {
5669
5896
  if (isMetadataRequest && !isEngineMetadataRequest) {
5670
5897
  try {
5671
5898
  await this.#ensureServerlessPoolConfigured(config);
5672
- } catch (error) {
5899
+ } catch (_error) {
5673
5900
  return new Response(
5674
5901
  JSON.stringify({
5675
5902
  group: "guard",
@@ -5702,6 +5929,33 @@ var Registry = class {
5702
5929
  fetch: (request) => this.handler(request)
5703
5930
  };
5704
5931
  }
5932
+ /**
5933
+ * Starts an HTTP server that dispatches every request through the
5934
+ * serverless handler. Uses `crossPlatformServe` to pick the right
5935
+ * runtime (Node, Bun, Deno).
5936
+ *
5937
+ * @param opts.port Port to listen on. Defaults to 3000.
5938
+ * @param opts.publicDir If set, serves static files from this directory
5939
+ * before falling through to the registry handler.
5940
+ *
5941
+ * @example
5942
+ * ```ts
5943
+ * await registry.listen();
5944
+ * await registry.listen({ port: 8080, publicDir: "./public" });
5945
+ * ```
5946
+ */
5947
+ async listen(opts = {}) {
5948
+ const port = _nullishCoalesce(opts.port, () => ( 3e3));
5949
+ const config = this.parseConfig();
5950
+ const runtime = _chunkVNMIAPPFcjs.detectRuntime.call(void 0, );
5951
+ const app = new (0, _hono.Hono)();
5952
+ if (opts.publicDir) {
5953
+ const serveStatic = await loadRuntimeServeStatic(runtime);
5954
+ app.use("*", serveStatic({ root: opts.publicDir }));
5955
+ }
5956
+ app.all("*", (c) => this.handler(c.req.raw));
5957
+ await crossPlatformServe(config, port, app, runtime);
5958
+ }
5705
5959
  /**
5706
5960
  * Returns a health response suitable for mounting in a user-owned router.
5707
5961
  */
@@ -5711,7 +5965,7 @@ var Registry = class {
5711
5965
  return jsonRouteResponse(503, {
5712
5966
  status: "not_started",
5713
5967
  runtime: "rivetkit",
5714
- version: _chunkJ5P6S2LCcjs.VERSION
5968
+ version: _chunkVNMIAPPFcjs.VERSION
5715
5969
  });
5716
5970
  }
5717
5971
  const { runtime, registry } = configured;
@@ -5719,7 +5973,7 @@ var Registry = class {
5719
5973
  return jsonRouteResponse(501, {
5720
5974
  status: "unsupported",
5721
5975
  runtime: "rivetkit",
5722
- version: _chunkJ5P6S2LCcjs.VERSION
5976
+ version: _chunkVNMIAPPFcjs.VERSION
5723
5977
  });
5724
5978
  }
5725
5979
  const response = await runtime.registryHealth(registry);
@@ -5791,20 +6045,20 @@ var Registry = class {
5791
6045
  */
5792
6046
  #startEnvoy(config, printWelcome) {
5793
6047
  if (!this.#runtimeServePromise) {
5794
- const configuredRegistryPromise = buildConfiguredRegistry(config);
6048
+ const configuredRegistryPromise = this.#buildConfiguredRegistry(config);
5795
6049
  this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
5796
6050
  this.#runtimeServePromise = configuredRegistryPromise.then(async ({ runtime, registry, serveConfig }) => {
5797
6051
  await runtime.serveRegistry(registry, serveConfig);
5798
- }).catch((err) => {
5799
- logger2().warn({ err }, "runtime registry serve errored");
6052
+ }).catch((error) => {
6053
+ logger2().warn({ error }, "runtime registry serve errored");
5800
6054
  });
5801
- this.#installSignalHandlers(config, configuredRegistryPromise);
6055
+ this.#installSignalHandlers(config);
5802
6056
  }
5803
6057
  if (printWelcome) {
5804
6058
  this.#printWelcome(config, "serverful");
5805
6059
  }
5806
6060
  }
5807
- #installSignalHandlers(config, configuredRegistryPromise) {
6061
+ #installSignalHandlers(config) {
5808
6062
  var _a;
5809
6063
  if (this.#shutdownInstalled) return;
5810
6064
  if ((_a = config.shutdown) == null ? void 0 : _a.disableSignalHandlers) return;
@@ -5813,58 +6067,86 @@ var Registry = class {
5813
6067
  }
5814
6068
  this.#shutdownInstalled = true;
5815
6069
  const install = (signal) => {
5816
- const handler = () => this.#onShutdownSignal(
5817
- signal,
5818
- config,
5819
- configuredRegistryPromise
5820
- );
6070
+ const handler = () => this.#onShutdownSignal(signal, config);
5821
6071
  this.#signalHandlers[signal] = handler;
5822
6072
  process.on(signal, handler);
5823
6073
  };
5824
6074
  install("SIGINT");
5825
6075
  install("SIGTERM");
5826
6076
  }
5827
- #onShutdownSignal(signal, config, configuredRegistryPromise) {
6077
+ #onShutdownSignal(signal, config) {
5828
6078
  if (this.#shutdownInFlight !== null) {
5829
6079
  this.#removeSignalHandlers();
5830
6080
  finishShutdownSignal(signal);
5831
6081
  return;
5832
6082
  }
5833
- this.#shutdownInFlight = this.#runShutdown(
5834
- signal,
5835
- config,
5836
- configuredRegistryPromise
5837
- ).catch((err) => {
6083
+ this.#shutdownInFlight = this.#drain(config).catch((err) => {
6084
+ logger2().warn({ err }, "shutdown error");
6085
+ }).then(() => {
6086
+ this.#removeSignalHandlers();
6087
+ finishShutdownSignal(signal);
6088
+ });
6089
+ }
6090
+ /**
6091
+ * Gracefully drains all live registries.
6092
+ *
6093
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
6094
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
6095
+ * waits for the serve promise to resolve, all bounded by the shutdown
6096
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
6097
+ * signal or exit the process. The caller owns process lifetime.
6098
+ *
6099
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
6100
+ * call even if nothing has been started.
6101
+ *
6102
+ * @example
6103
+ * ```ts
6104
+ * const registry = setup({ use: { counter } });
6105
+ * registry.start();
6106
+ * // ...later, on your own shutdown trigger:
6107
+ * await registry.shutdown();
6108
+ * ```
6109
+ */
6110
+ async shutdown() {
6111
+ if (this.#shutdownInFlight !== null) return this.#shutdownInFlight;
6112
+ const config = this.parseConfig();
6113
+ this.#removeSignalHandlers();
6114
+ this.#shutdownInFlight = this.#drain(config).catch((err) => {
5838
6115
  logger2().warn({ err }, "shutdown error");
5839
6116
  });
6117
+ return this.#shutdownInFlight;
5840
6118
  }
5841
- async #runShutdown(signal, config, configuredRegistryPromise) {
6119
+ async #drain(config) {
5842
6120
  var _a;
5843
- const gracePeriodMs = await _asyncNullishCoalesce(await _asyncNullishCoalesce(((_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs), async () => ( await this.#actorStopThresholdMs(configuredRegistryPromise))), async () => ( 30 * 60 * 1e3));
6121
+ const modeAPromise = this.#runtimeServeConfiguredPromise;
6122
+ const modeBPromise = this.#runtimeServerlessPromise;
6123
+ const gracePeriodMs = await _asyncNullishCoalesce(await _asyncNullishCoalesce(((_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs), async () => ( await this.#actorStopThresholdMs(_nullishCoalesce(modeAPromise, () => ( modeBPromise))))), async () => ( 30 * 60 * 1e3));
5844
6124
  const drain = async () => {
5845
- const registries = [
5846
- (async () => {
5847
- try {
5848
- const { runtime, registry } = await configuredRegistryPromise;
5849
- await runtime.shutdownRegistry(registry);
5850
- } catch (err) {
5851
- logger2().warn(
5852
- { err },
5853
- "runtime registry shutdown errored (mode A)"
5854
- );
5855
- }
5856
- })()
5857
- ];
5858
- const runtimeServerlessPromise = this.#runtimeServerlessPromise;
5859
- if (runtimeServerlessPromise !== void 0) {
6125
+ const registries = [];
6126
+ if (modeAPromise !== void 0) {
5860
6127
  registries.push(
5861
6128
  (async () => {
5862
6129
  try {
5863
- const { runtime, registry } = await runtimeServerlessPromise;
6130
+ const { runtime, registry } = await modeAPromise;
5864
6131
  await runtime.shutdownRegistry(registry);
5865
6132
  } catch (err) {
5866
6133
  logger2().warn(
5867
6134
  { err },
6135
+ "runtime registry shutdown errored (mode A)"
6136
+ );
6137
+ }
6138
+ })()
6139
+ );
6140
+ }
6141
+ if (modeBPromise !== void 0) {
6142
+ registries.push(
6143
+ (async () => {
6144
+ try {
6145
+ const { runtime, registry } = await modeBPromise;
6146
+ await runtime.shutdownRegistry(registry);
6147
+ } catch (err) {
6148
+ logger2().warn(
6149
+ { error: err },
5868
6150
  "runtime registry shutdown errored (mode B)"
5869
6151
  );
5870
6152
  }
@@ -5886,11 +6168,10 @@ var Registry = class {
5886
6168
  }
5887
6169
  )
5888
6170
  ]);
5889
- this.#removeSignalHandlers();
5890
- finishShutdownSignal(signal);
5891
6171
  }
5892
6172
  async #actorStopThresholdMs(configuredRegistryPromise) {
5893
6173
  var _a;
6174
+ if (configuredRegistryPromise === void 0) return void 0;
5894
6175
  try {
5895
6176
  const { runtime, registry } = await configuredRegistryPromise;
5896
6177
  const thresholdMs = await ((_a = runtime.registryActorStopThresholdMs) == null ? void 0 : _a.call(runtime, registry));
@@ -5938,7 +6219,7 @@ var Registry = class {
5938
6219
  };
5939
6220
  console.log();
5940
6221
  console.log(
5941
- ` RivetKit ${_chunkJ5P6S2LCcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
6222
+ ` RivetKit ${_chunkVNMIAPPFcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
5942
6223
  );
5943
6224
  if (config.namespace !== "default") {
5944
6225
  logLine("Namespace", config.namespace);
@@ -6006,5 +6287,5 @@ function setup(input) {
6006
6287
 
6007
6288
 
6008
6289
 
6009
- exports.ALLOWED_PUBLIC_HEADERS = _chunkTE4VCDNYcjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunkQAZLM4WTcjs.RivetError; exports.ActorsSchema = ActorsSchema; exports.DocConfigurePoolSchema = DocConfigurePoolSchema; exports.DocEnvoyConfigSchema = DocEnvoyConfigSchema; exports.DocRegistryConfigSchema = DocRegistryConfigSchema; exports.DocServerlessConfigSchema = DocServerlessConfigSchema; exports.DocSqliteConfigSchema = DocSqliteConfigSchema; exports.InlineWebSocketAdapter = InlineWebSocketAdapter; exports.Registry = Registry; exports.RegistryConfigSchema = RegistryConfigSchema; exports.RivetError = _chunkQAZLM4WTcjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunkQAZLM4WTcjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunkTE4VCDNYcjs.createClientWithDriver; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkJ5P6S2LCcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkJ5P6S2LCcjs.toUint8Array;
6290
+ exports.ALLOWED_PUBLIC_HEADERS = _chunk2U6RLFKXcjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunkKORQB2IRcjs.RivetError; exports.ActorsSchema = ActorsSchema; exports.DocConfigurePoolSchema = DocConfigurePoolSchema; exports.DocEnvoyConfigSchema = DocEnvoyConfigSchema; exports.DocRegistryConfigSchema = DocRegistryConfigSchema; exports.DocServerlessConfigSchema = DocServerlessConfigSchema; exports.DocSqliteConfigSchema = DocSqliteConfigSchema; exports.InlineWebSocketAdapter = InlineWebSocketAdapter; exports.Registry = Registry; exports.RegistryConfigSchema = RegistryConfigSchema; exports.RivetError = _chunkKORQB2IRcjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunkKORQB2IRcjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunk2U6RLFKXcjs.createClientWithDriver; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkVNMIAPPFcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkVNMIAPPFcjs.toUint8Array;
6010
6291
  //# sourceMappingURL=mod.cjs.map