rivetkit 2.3.0-rc.9 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/dist/browser/client.d.ts +511 -62
  2. package/dist/browser/client.js +230 -174
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +53 -23
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +4 -2
  7. package/dist/tsup/actor/errors.cjs.map +1 -1
  8. package/dist/tsup/actor/errors.d.cts +1 -1
  9. package/dist/tsup/actor/errors.d.ts +1 -1
  10. package/dist/tsup/actor/errors.js +3 -1
  11. package/dist/tsup/agent-os/index.cjs +2163 -2087
  12. package/dist/tsup/agent-os/index.cjs.map +1 -1
  13. package/dist/tsup/agent-os/index.d.cts +509 -69
  14. package/dist/tsup/agent-os/index.d.ts +509 -69
  15. package/dist/tsup/agent-os/index.js +2163 -2087
  16. package/dist/tsup/agent-os/index.js.map +1 -1
  17. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-3MHDOUD7.cjs} +73 -3
  18. package/dist/tsup/chunk-3MHDOUD7.cjs.map +1 -0
  19. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-4FC7TVS6.cjs} +8 -4
  20. package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
  21. package/dist/tsup/{chunk-4CGA6QJO.cjs → chunk-4UUEB43Y.cjs} +24 -9
  22. package/dist/tsup/chunk-4UUEB43Y.cjs.map +1 -0
  23. package/dist/tsup/{chunk-GVTOE34S.cjs → chunk-5IWLUJ6W.cjs} +222 -235
  24. package/dist/tsup/chunk-5IWLUJ6W.cjs.map +1 -0
  25. package/dist/tsup/{chunk-MMMEZM5J.js → chunk-H6VVZMWN.js} +4 -4
  26. package/dist/tsup/chunk-H6VVZMWN.js.map +1 -0
  27. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  28. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  29. package/dist/tsup/{chunk-H7P7WR2Y.js → chunk-I35VSLEM.js} +6 -6
  30. package/dist/tsup/chunk-I35VSLEM.js.map +1 -0
  31. package/dist/tsup/{chunk-H37XQU3I.js → chunk-JBUZRPY5.js} +2 -2
  32. package/dist/tsup/{chunk-CPA4Y3RG.cjs → chunk-JLJJZYCJ.cjs} +10 -10
  33. package/dist/tsup/chunk-JLJJZYCJ.cjs.map +1 -0
  34. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  35. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  36. package/dist/tsup/{chunk-VRCIXJRN.js → chunk-L2X3YFER.js} +64 -10
  37. package/dist/tsup/chunk-L2X3YFER.js.map +1 -0
  38. package/dist/tsup/{chunk-Y5NSCZA2.cjs → chunk-MNHKOS6L.cjs} +72 -18
  39. package/dist/tsup/chunk-MNHKOS6L.cjs.map +1 -0
  40. package/dist/tsup/{chunk-KJTA3ATT.js → chunk-NERUIBOT.js} +22 -7
  41. package/dist/tsup/chunk-NERUIBOT.js.map +1 -0
  42. package/dist/tsup/{chunk-4WPEZBK4.cjs → chunk-OST76LRW.cjs} +10 -10
  43. package/dist/tsup/chunk-OST76LRW.cjs.map +1 -0
  44. package/dist/tsup/{chunk-MALSPBAF.cjs → chunk-OZBCXBVP.cjs} +3 -3
  45. package/dist/tsup/{chunk-MALSPBAF.cjs.map → chunk-OZBCXBVP.cjs.map} +1 -1
  46. package/dist/tsup/{chunk-F3Q5BFQ6.js → chunk-PT6OIW5E.js} +66 -79
  47. package/dist/tsup/chunk-PT6OIW5E.js.map +1 -0
  48. package/dist/tsup/{chunk-W7EYSYVI.js → chunk-R6KPN5EW.js} +134 -20
  49. package/dist/tsup/chunk-R6KPN5EW.js.map +1 -0
  50. package/dist/tsup/{chunk-VJFRBJVQ.cjs → chunk-V5KMAMX3.cjs} +138 -24
  51. package/dist/tsup/chunk-V5KMAMX3.cjs.map +1 -0
  52. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  53. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  54. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-XIX5DOZN.js} +72 -2
  55. package/dist/tsup/chunk-XIX5DOZN.js.map +1 -0
  56. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  57. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  58. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-ZZ3WBRPD.js} +7 -3
  59. package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
  60. package/dist/tsup/client/mod.cjs +9 -9
  61. package/dist/tsup/client/mod.d.cts +5 -5
  62. package/dist/tsup/client/mod.d.ts +5 -5
  63. package/dist/tsup/client/mod.js +8 -8
  64. package/dist/tsup/common/log.cjs +3 -3
  65. package/dist/tsup/common/log.js +2 -2
  66. package/dist/tsup/common/websocket.cjs +4 -4
  67. package/dist/tsup/common/websocket.js +3 -3
  68. package/dist/tsup/{config-Ca8dN4cS.d.cts → config-CzvopP5m.d.cts} +544 -23
  69. package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.cts} +1 -2
  70. package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.ts} +1 -2
  71. package/dist/tsup/{config-0Ta55UV0.d.ts → config-DZuT7tcp.d.ts} +544 -23
  72. package/dist/tsup/context-CyAdY-aA.d.ts +128 -0
  73. package/dist/tsup/context-sNB28g0N.d.cts +128 -0
  74. package/dist/tsup/db/drizzle.cjs +3 -3
  75. package/dist/tsup/db/drizzle.d.cts +1 -1
  76. package/dist/tsup/db/drizzle.d.ts +1 -1
  77. package/dist/tsup/db/drizzle.js +1 -1
  78. package/dist/tsup/db/mod.cjs +2 -2
  79. package/dist/tsup/db/mod.d.cts +2 -2
  80. package/dist/tsup/db/mod.d.ts +2 -2
  81. package/dist/tsup/db/mod.js +1 -1
  82. package/dist/tsup/dynamic/mod.cjs +24 -0
  83. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  84. package/dist/tsup/dynamic/mod.d.cts +37 -0
  85. package/dist/tsup/dynamic/mod.d.ts +37 -0
  86. package/dist/tsup/dynamic/mod.js +24 -0
  87. package/dist/tsup/dynamic/mod.js.map +1 -0
  88. package/dist/tsup/inspector/mod.cjs +6 -6
  89. package/dist/tsup/inspector/mod.js +5 -5
  90. package/dist/tsup/inspector-tab/mod.cjs +173 -0
  91. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  92. package/dist/tsup/inspector-tab/mod.d.cts +250 -0
  93. package/dist/tsup/inspector-tab/mod.d.ts +250 -0
  94. package/dist/tsup/inspector-tab/mod.js +173 -0
  95. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  96. package/dist/tsup/mod.cjs +758 -348
  97. package/dist/tsup/mod.cjs.map +1 -1
  98. package/dist/tsup/mod.d.cts +5 -5
  99. package/dist/tsup/mod.d.ts +5 -5
  100. package/dist/tsup/mod.js +662 -252
  101. package/dist/tsup/mod.js.map +1 -1
  102. package/dist/tsup/test/mod.cjs +21 -18
  103. package/dist/tsup/test/mod.cjs.map +1 -1
  104. package/dist/tsup/test/mod.d.cts +4 -4
  105. package/dist/tsup/test/mod.d.ts +4 -4
  106. package/dist/tsup/test/mod.js +18 -15
  107. package/dist/tsup/test/mod.js.map +1 -1
  108. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-CqDnC_PS.d.cts} +2 -1
  109. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-CqDnC_PS.d.ts} +2 -1
  110. package/dist/tsup/utils.cjs +3 -3
  111. package/dist/tsup/utils.d.cts +1 -1
  112. package/dist/tsup/utils.d.ts +1 -1
  113. package/dist/tsup/utils.js +2 -2
  114. package/dist/tsup/workflow/mod.cjs +383 -322
  115. package/dist/tsup/workflow/mod.cjs.map +1 -1
  116. package/dist/tsup/workflow/mod.d.cts +8 -8
  117. package/dist/tsup/workflow/mod.d.ts +8 -8
  118. package/dist/tsup/workflow/mod.js +360 -299
  119. package/dist/tsup/workflow/mod.js.map +1 -1
  120. package/package.json +35 -14
  121. package/src/actor/config.ts +173 -51
  122. package/src/actor/contexts/index.ts +7 -2
  123. package/src/actor/definition.ts +17 -19
  124. package/src/actor/driver.ts +3 -3
  125. package/src/actor/errors.ts +20 -3
  126. package/src/actor/instance/mod.ts +26 -34
  127. package/src/actor/keys.ts +1 -1
  128. package/src/actor/mod.ts +22 -20
  129. package/src/actor/schema.ts +2 -2
  130. package/src/agent-os/actor/index.ts +38 -18
  131. package/src/agent-os/actor/preview.ts +1 -2
  132. package/src/agent-os/actor/session.ts +2 -2
  133. package/src/agent-os/config.ts +1 -1
  134. package/src/agent-os/fs/database-vfs.ts +1 -1
  135. package/src/agent-os/index.ts +16 -15
  136. package/src/client/actor-common.ts +87 -54
  137. package/src/client/actor-conn.ts +8 -36
  138. package/src/client/actor-handle.ts +69 -51
  139. package/src/client/actor-query.ts +5 -5
  140. package/src/client/errors.ts +1 -1
  141. package/src/client/lifecycle-errors.ts +2 -4
  142. package/src/client/query.ts +1 -1
  143. package/src/client/queue.ts +8 -3
  144. package/src/client/raw-utils.ts +8 -6
  145. package/src/client/resolve-gateway-target.ts +1 -1
  146. package/src/client/utils.ts +2 -7
  147. package/src/common/actor-websocket.ts +3 -1
  148. package/src/common/bare/actor-persist/v1.ts +205 -163
  149. package/src/common/bare/actor-persist/v2.ts +265 -213
  150. package/src/common/bare/actor-persist/v3.ts +176 -172
  151. package/src/common/bare/actor-persist/v4.ts +254 -253
  152. package/src/common/bare/transport/v1.ts +659 -543
  153. package/src/common/client-protocol-versioned.ts +66 -64
  154. package/src/common/database/config.ts +2 -8
  155. package/src/common/database/native-database.ts +1 -1
  156. package/src/common/database/shared.ts +1 -0
  157. package/src/common/encoding.ts +250 -16
  158. package/src/common/engine.ts +28 -1
  159. package/src/common/eventsource.ts +1 -1
  160. package/src/common/inline-websocket-adapter.ts +14 -13
  161. package/src/common/log.ts +1 -0
  162. package/src/common/router.ts +13 -17
  163. package/src/common/utils.ts +1 -150
  164. package/src/common/websocket-interface.ts +1 -1
  165. package/src/db/mod.ts +1 -1
  166. package/src/devtools-loader/index.ts +4 -7
  167. package/src/devtools-loader/serve-devtools.ts +26 -0
  168. package/src/drivers/engine/actor-driver.ts +58 -56
  169. package/src/dynamic/instance.ts +32 -0
  170. package/src/dynamic/internal.ts +50 -0
  171. package/src/dynamic/isolate-runtime.ts +66 -0
  172. package/src/dynamic/mod.ts +32 -0
  173. package/src/engine-client/actor-http-client.ts +3 -3
  174. package/src/engine-client/actor-websocket-client.ts +6 -5
  175. package/src/engine-client/api-endpoints.ts +51 -2
  176. package/src/engine-client/api-utils.ts +2 -2
  177. package/src/engine-client/driver.ts +1 -1
  178. package/src/engine-client/mod.ts +6 -3
  179. package/src/engine-client/ws-proxy.ts +9 -4
  180. package/src/inspector/client.browser.ts +5 -11
  181. package/src/inspector/mod.ts +1 -3
  182. package/src/inspector-tab/mod.ts +315 -0
  183. package/src/registry/config/envoy.ts +1 -2
  184. package/src/registry/config/index.ts +40 -16
  185. package/src/registry/index.ts +209 -73
  186. package/src/registry/napi-runtime.ts +29 -2
  187. package/src/registry/native-validation.ts +10 -12
  188. package/src/registry/native.ts +433 -198
  189. package/src/registry/process-metrics.ts +250 -0
  190. package/src/registry/runtime.ts +52 -1
  191. package/src/registry/wasm-runtime.ts +29 -2
  192. package/src/registry/write-through-proxy.ts +40 -0
  193. package/src/serde.ts +2 -2
  194. package/src/serverless/configure.ts +18 -7
  195. package/src/test/mod.ts +11 -8
  196. package/src/utils/endpoint-parser.ts +1 -1
  197. package/src/utils/env-vars.ts +37 -0
  198. package/src/utils/router.ts +1 -1
  199. package/src/utils.ts +1 -2
  200. package/src/workflow/context.ts +699 -240
  201. package/src/workflow/driver.ts +23 -12
  202. package/src/workflow/inspector.ts +4 -3
  203. package/src/workflow/mod.ts +37 -23
  204. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  205. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  206. package/dist/tsup/chunk-4CGA6QJO.cjs.map +0 -1
  207. package/dist/tsup/chunk-4WPEZBK4.cjs.map +0 -1
  208. package/dist/tsup/chunk-CPA4Y3RG.cjs.map +0 -1
  209. package/dist/tsup/chunk-F3Q5BFQ6.js.map +0 -1
  210. package/dist/tsup/chunk-GVTOE34S.cjs.map +0 -1
  211. package/dist/tsup/chunk-H7P7WR2Y.js.map +0 -1
  212. package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
  213. package/dist/tsup/chunk-KJTA3ATT.js.map +0 -1
  214. package/dist/tsup/chunk-MMMEZM5J.js.map +0 -1
  215. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  216. package/dist/tsup/chunk-QAZLM4WT.cjs.map +0 -1
  217. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  218. package/dist/tsup/chunk-VJFRBJVQ.cjs.map +0 -1
  219. package/dist/tsup/chunk-VRCIXJRN.js.map +0 -1
  220. package/dist/tsup/chunk-W7EYSYVI.js.map +0 -1
  221. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  222. package/dist/tsup/chunk-Y5NSCZA2.cjs.map +0 -1
  223. package/dist/tsup/context-B_IWbWne.d.ts +0 -92
  224. package/dist/tsup/context-CUrQ9MHc.d.cts +0 -92
  225. package/src/utils/serve.ts +0 -217
  226. /package/dist/tsup/{chunk-H37XQU3I.js.map → chunk-JBUZRPY5.js.map} +0 -0
package/dist/tsup/mod.cjs CHANGED
@@ -1,16 +1,16 @@
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
+ var _chunk4UUEB43Ycjs = require('./chunk-4UUEB43Y.cjs');
3
4
 
4
5
 
5
6
 
6
7
 
7
8
 
8
- var _chunkWQ4HNA4Wcjs = require('./chunk-WQ4HNA4W.cjs');
9
9
 
10
10
 
11
- var _chunk4CGA6QJOcjs = require('./chunk-4CGA6QJO.cjs');
12
11
 
13
12
 
13
+ var _chunk3MHDOUD7cjs = require('./chunk-3MHDOUD7.cjs');
14
14
 
15
15
 
16
16
 
@@ -18,24 +18,24 @@ var _chunk4CGA6QJOcjs = require('./chunk-4CGA6QJO.cjs');
18
18
 
19
19
 
20
20
 
21
- var _chunkGVTOE34Scjs = require('./chunk-GVTOE34S.cjs');
22
21
 
23
22
 
23
+ var _chunk5IWLUJ6Wcjs = require('./chunk-5IWLUJ6W.cjs');
24
24
 
25
25
 
26
26
 
27
27
 
28
28
 
29
- var _chunkLD5YASJUcjs = require('./chunk-LD5YASJU.cjs');
30
29
 
31
30
 
31
+ var _chunkVE2X4KMGcjs = require('./chunk-VE2X4KMG.cjs');
32
32
 
33
33
 
34
- var _chunkVJFRBJVQcjs = require('./chunk-VJFRBJVQ.cjs');
35
- require('./chunk-2NDZ7JCR.cjs');
36
- require('./chunk-MALSPBAF.cjs');
37
34
 
38
35
 
36
+ var _chunkV5KMAMX3cjs = require('./chunk-V5KMAMX3.cjs');
37
+ require('./chunk-ZA7FLHKH.cjs');
38
+ require('./chunk-OZBCXBVP.cjs');
39
39
 
40
40
 
41
41
 
@@ -57,7 +57,6 @@ require('./chunk-MALSPBAF.cjs');
57
57
 
58
58
 
59
59
 
60
- var _chunkY5NSCZA2cjs = require('./chunk-Y5NSCZA2.cjs');
61
60
 
62
61
 
63
62
 
@@ -65,14 +64,23 @@ var _chunkY5NSCZA2cjs = require('./chunk-Y5NSCZA2.cjs');
65
64
 
66
65
 
67
66
 
67
+ var _chunkMNHKOS6Lcjs = require('./chunk-MNHKOS6L.cjs');
68
68
 
69
69
 
70
70
 
71
- var _chunkQAZLM4WTcjs = require('./chunk-QAZLM4WT.cjs');
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ var _chunk4FC7TVS6cjs = require('./chunk-4FC7TVS6.cjs');
72
80
 
73
81
  // src/actor/log.ts
74
82
  function loggerWithoutContext() {
75
- return _chunkY5NSCZA2cjs.getLogger.call(void 0, "actor-runtime");
83
+ return _chunkMNHKOS6Lcjs.getLogger.call(void 0, "actor-runtime");
76
84
  }
77
85
 
78
86
  // src/actor/definition.ts
@@ -105,7 +113,7 @@ function actor(input) {
105
113
  warnDeprecatedShutdownTimeoutKeys(
106
114
  input == null ? void 0 : input.options
107
115
  );
108
- const config = _chunkWQ4HNA4Wcjs.ActorConfigSchema.parse(input);
116
+ const config = _chunk3MHDOUD7cjs.ActorConfigSchema.parse(input);
109
117
  return new ActorDefinition(config);
110
118
  }
111
119
  function isStaticActorDefinition(definition) {
@@ -140,7 +148,7 @@ function hasSchemaConfigKey(schemas, key) {
140
148
  if (!schemas) {
141
149
  return false;
142
150
  }
143
- return Object.prototype.hasOwnProperty.call(schemas, key);
151
+ return Object.hasOwn(schemas, key);
144
152
  }
145
153
  function getEventCanSubscribe(schemas, key) {
146
154
  const schema = schemas == null ? void 0 : schemas[key];
@@ -187,7 +195,7 @@ function validateSchemaSync(schemas, key, data) {
187
195
  if (isStandardSchema(schema)) {
188
196
  const result = schema["~standard"].validate(data);
189
197
  if (isPromiseLike(result)) {
190
- throw _chunkQAZLM4WTcjs.unsupportedFeature.call(void 0, "async schema validation");
198
+ throw _chunk4FC7TVS6cjs.unsupportedFeature.call(void 0, "async schema validation");
191
199
  }
192
200
  if (result.issues) {
193
201
  return { success: false, issues: [...result.issues] };
@@ -201,10 +209,10 @@ function validateSchemaSync(schemas, key, data) {
201
209
  }
202
210
 
203
211
  // src/common/inline-websocket-adapter.ts
204
- var _ws = require('hono/ws');
205
212
  var _virtualwebsocket = require('@rivetkit/virtual-websocket');
213
+ var _ws = require('hono/ws');
206
214
  function logger() {
207
- return _chunkY5NSCZA2cjs.getLogger.call(void 0, "inline-websocket-adapter");
215
+ return _chunkMNHKOS6Lcjs.getLogger.call(void 0, "inline-websocket-adapter");
208
216
  }
209
217
  var InlineWebSocketAdapter = class {
210
218
  #handler;
@@ -314,24 +322,24 @@ var InlineWebSocketAdapter = class {
314
322
  this.#close(1011, "Internal error during initialization");
315
323
  }
316
324
  }
317
- #handleError(err) {
318
- console.error("INLINE_WEBSOCKET_ADAPTER_ERROR", err);
325
+ #handleError(error) {
326
+ console.error("INLINE_WEBSOCKET_ADAPTER_ERROR", error);
319
327
  logger().error({
320
328
  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
329
+ error,
330
+ errorMessage: error instanceof Error ? error.message : String(error),
331
+ stack: error instanceof Error ? error.stack : void 0
324
332
  });
325
333
  try {
326
- this.#handler.onError(err, this.#wsContext);
327
- } catch (handlerErr) {
334
+ this.#handler.onError(error, this.#wsContext);
335
+ } catch (error2) {
328
336
  logger().error({
329
337
  msg: "error in onError handler",
330
- error: handlerErr
338
+ error: error2
331
339
  });
332
340
  }
333
- this.#clientWs.triggerError(err);
334
- this.#actorWs.triggerError(err);
341
+ this.#clientWs.triggerError(error);
342
+ this.#actorWs.triggerError(error);
335
343
  }
336
344
  #close(code, reason) {
337
345
  if (this.#readyState === 3 || this.#readyState === 2) {
@@ -344,8 +352,8 @@ var InlineWebSocketAdapter = class {
344
352
  { code, reason, wasClean: true },
345
353
  this.#wsContext
346
354
  );
347
- } catch (err) {
348
- logger().error({ msg: "error closing websocket", error: err });
355
+ } catch (error) {
356
+ logger().error({ msg: "error closing websocket", error });
349
357
  } finally {
350
358
  this.#readyState = 3;
351
359
  this.#clientWs.triggerClose(code, reason);
@@ -355,12 +363,27 @@ var InlineWebSocketAdapter = class {
355
363
  };
356
364
 
357
365
  // src/common/engine.ts
366
+ var ENGINE_HOST = "127.0.0.1";
358
367
  var ENGINE_PORT = 6420;
359
- var ENGINE_ENDPOINT = `http://127.0.0.1:${ENGINE_PORT}`;
368
+ var ENGINE_ENDPOINT = buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT);
369
+ function buildEngineEndpoint(host, port) {
370
+ const urlHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
371
+ return `http://${urlHost}:${port}`;
372
+ }
373
+ function isLocalEngineEndpoint(endpoint) {
374
+ let url;
375
+ try {
376
+ url = new URL(endpoint);
377
+ } catch (e) {
378
+ return false;
379
+ }
380
+ const hostname = url.hostname.toLowerCase();
381
+ return hostname === "localhost" || hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]" || hostname === "::1" || hostname === "[::1]" || /^127(?:\.\d{1,3}){0,3}$/.test(hostname);
382
+ }
360
383
 
361
384
  // src/registry/log.ts
362
385
  function logger2() {
363
- return _chunkY5NSCZA2cjs.getLogger.call(void 0, "registry");
386
+ return _chunkMNHKOS6Lcjs.getLogger.call(void 0, "registry");
364
387
  }
365
388
 
366
389
  // src/serverless/configure.ts
@@ -371,10 +394,13 @@ function sleep(ms) {
371
394
  }
372
395
  function configureTimeoutMs() {
373
396
  const value = process.env.RIVET_SERVERLESS_CONFIGURE_TIMEOUT_MS;
374
- if (value === void 0 || value === "") return DEFAULT_CONFIGURE_TIMEOUT_MS;
397
+ if (value === void 0 || value === "")
398
+ return DEFAULT_CONFIGURE_TIMEOUT_MS;
375
399
  const parsed = Number(value);
376
400
  if (!Number.isFinite(parsed) || parsed < 0) {
377
- throw new Error("RIVET_SERVERLESS_CONFIGURE_TIMEOUT_MS must be a finite non-negative number");
401
+ throw new Error(
402
+ "RIVET_SERVERLESS_CONFIGURE_TIMEOUT_MS must be a finite non-negative number"
403
+ );
378
404
  }
379
405
  return parsed;
380
406
  }
@@ -388,17 +414,23 @@ async function configureServerlessPool(config) {
388
414
  attempts += 1;
389
415
  try {
390
416
  if (!config.namespace) {
391
- throw new Error("namespace is required for serverless configuration");
417
+ throw new Error(
418
+ "namespace is required for serverless configuration"
419
+ );
392
420
  }
393
421
  if (!config.endpoint) {
394
- throw new Error("endpoint is required for serverless configuration");
422
+ throw new Error(
423
+ "endpoint is required for serverless configuration"
424
+ );
395
425
  }
396
426
  if (!config.configurePool) {
397
- throw new Error("configurePool is required for serverless configuration");
427
+ throw new Error(
428
+ "configurePool is required for serverless configuration"
429
+ );
398
430
  }
399
431
  const customConfig = config.configurePool;
400
- const clientConfig = _chunkGVTOE34Scjs.convertRegistryConfigToClientConfig.call(void 0, config);
401
- const dcsRes = await _chunkGVTOE34Scjs.getDatacenters.call(void 0, clientConfig);
432
+ const clientConfig = _chunk5IWLUJ6Wcjs.convertRegistryConfigToClientConfig.call(void 0, config);
433
+ const dcsRes = await _chunk5IWLUJ6Wcjs.getDatacenters.call(void 0, clientConfig);
402
434
  const poolName = _nullishCoalesce(customConfig.name, () => ( "default"));
403
435
  const serverlessToken = _nullishCoalesce(config.token, () => ( config.publicToken));
404
436
  const headers = {
@@ -420,7 +452,7 @@ async function configureServerlessPool(config) {
420
452
  metadata: _nullishCoalesce(customConfig.metadata, () => ( {})),
421
453
  drain_on_version_upgrade: _nullishCoalesce(customConfig.drainOnVersionUpgrade, () => ( true))
422
454
  };
423
- await _chunkGVTOE34Scjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
455
+ await _chunk5IWLUJ6Wcjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
424
456
  datacenters: Object.fromEntries(
425
457
  dcsRes.datacenters.map((dc) => [dc.name, serverlessConfig])
426
458
  )
@@ -437,7 +469,7 @@ async function configureServerlessPool(config) {
437
469
  logger2().warn({
438
470
  msg: "serverless pool configuration attempt failed",
439
471
  attempts,
440
- error: _chunkY5NSCZA2cjs.stringifyError.call(void 0, error)
472
+ error: _chunkMNHKOS6Lcjs.stringifyError.call(void 0, error)
441
473
  });
442
474
  await sleep(CONFIGURE_RETRY_DELAY_MS);
443
475
  }
@@ -445,7 +477,7 @@ async function configureServerlessPool(config) {
445
477
  logger2().error({
446
478
  msg: "failed to configure serverless pool, validate endpoint is configured correctly then restart this process",
447
479
  attempts,
448
- error: _chunkY5NSCZA2cjs.stringifyError.call(void 0, lastError)
480
+ error: _chunkMNHKOS6Lcjs.stringifyError.call(void 0, lastError)
449
481
  });
450
482
  throw lastError;
451
483
  }
@@ -457,20 +489,20 @@ var _zod = require('zod');
457
489
  var _v4 = require('zod/v4');
458
490
  var warnedMissingVersion = false;
459
491
  var EnvoyConfigSchema = _v4.z.object({
460
- poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkY5NSCZA2cjs.getRivetPool.call(void 0, ), () => ( "default"))),
492
+ poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkMNHKOS6Lcjs.getRivetPool.call(void 0, ), () => ( "default"))),
461
493
  version: _v4.z.number().default(() => {
462
- const version = _chunkY5NSCZA2cjs.getRivetEnvoyVersion.call(void 0, );
494
+ const version = _chunkMNHKOS6Lcjs.getRivetEnvoyVersion.call(void 0, );
463
495
  if (version !== void 0) return version;
464
- if (_chunkY5NSCZA2cjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
496
+ if (_chunkMNHKOS6Lcjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
465
497
  warnedMissingVersion = true;
466
- _chunkY5NSCZA2cjs.getLogger.call(void 0, "rivetkit").error(
498
+ _chunkMNHKOS6Lcjs.getLogger.call(void 0, "rivetkit").error(
467
499
  "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
500
  );
469
501
  }
470
502
  return 1;
471
503
  }),
472
504
  // Deprecated.
473
- totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkY5NSCZA2cjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
505
+ totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkMNHKOS6Lcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
474
506
  envoyKey: _v4.z.string().optional()
475
507
  });
476
508
 
@@ -508,7 +540,7 @@ var ServerlessConfigSchema = _v4.z.object({
508
540
  *
509
541
  * Can also be set via RIVET_PUBLIC_ENDPOINT environment variable.
510
542
  */
511
- publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetPublicEndpoint.call(void 0, )))),
543
+ publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkMNHKOS6Lcjs.getRivetPublicEndpoint.call(void 0, )))),
512
544
  /**
513
545
  * Token that clients should use when connecting via the public endpoint.
514
546
  *
@@ -516,7 +548,7 @@ var ServerlessConfigSchema = _v4.z.object({
516
548
  *
517
549
  * Can also be specified in the publicEndpoint URL as `https://namespace:token@host`.
518
550
  */
519
- publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetPublicToken.call(void 0, ))))
551
+ publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkMNHKOS6Lcjs.getRivetPublicToken.call(void 0, ))))
520
552
  // There is no publicNamespace config option because the frontend and backend
521
553
  // cannot use different namespaces. The namespace is extracted from the
522
554
  // publicEndpoint URL auth syntax if provided.
@@ -570,7 +602,7 @@ var RegistryConfigSchema = _zod.z.object({
570
602
  * Runtime binding to use for RivetKit core.
571
603
  * */
572
604
  runtime: RuntimeKindSchema.optional().transform((val, ctx) => {
573
- const rawRuntime = _nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetkitRuntime.call(void 0, )));
605
+ const rawRuntime = _nullishCoalesce(val, () => ( _chunkMNHKOS6Lcjs.getRivetkitRuntime.call(void 0, )));
574
606
  if (rawRuntime === void 0) {
575
607
  return "auto";
576
608
  }
@@ -607,7 +639,7 @@ var RegistryConfigSchema = _zod.z.object({
607
639
  * */
608
640
  logging: _zod.z.object({
609
641
  baseLogger: _zod.z.custom().optional(),
610
- level: _chunkY5NSCZA2cjs.LogLevelSchema.optional()
642
+ level: _chunkMNHKOS6Lcjs.LogLevelSchema.optional()
611
643
  }).optional().default(() => ({})),
612
644
  // MARK: Routing
613
645
  // // This is a function to allow for lazy configuration of upgradeWebSocket on the
@@ -625,9 +657,9 @@ var RegistryConfigSchema = _zod.z.object({
625
657
  *
626
658
  * Can also be set via RIVET_ENDPOINT environment variables.
627
659
  */
628
- endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetEngine.call(void 0, ))), () => ( _chunkY5NSCZA2cjs.getRivetEndpoint.call(void 0, )))),
629
- token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetToken.call(void 0, )))),
630
- namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetNamespace.call(void 0, )))),
660
+ endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkMNHKOS6Lcjs.getRivetEngine.call(void 0, ))), () => ( _chunkMNHKOS6Lcjs.getRivetEndpoint.call(void 0, )))),
661
+ token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkMNHKOS6Lcjs.getRivetToken.call(void 0, )))),
662
+ namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkMNHKOS6Lcjs.getRivetNamespace.call(void 0, )))),
631
663
  headers: _zod.z.record(_zod.z.string(), _zod.z.string()).optional().default({}),
632
664
  // MARK: Client
633
665
  // TODO:
@@ -667,9 +699,21 @@ var RegistryConfigSchema = _zod.z.object({
667
699
  *
668
700
  * Starts the full Rust engine process locally.
669
701
  */
670
- startEngine: _zod.z.boolean().default(() => _chunkY5NSCZA2cjs.getRivetRunEngine.call(void 0, )),
702
+ startEngine: _zod.z.boolean().default(() => _chunkMNHKOS6Lcjs.getRivetRunEngine.call(void 0, )),
703
+ /**
704
+ * @experimental
705
+ *
706
+ * Host to bind the spawned local engine process to.
707
+ */
708
+ engineHost: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkMNHKOS6Lcjs.getRivetRunEngineHost.call(void 0, ), () => ( ENGINE_HOST))),
709
+ /**
710
+ * @experimental
711
+ *
712
+ * Port to bind the spawned local engine process to.
713
+ */
714
+ enginePort: _zod.z.number().int().min(1).max(65535).optional().default(() => _nullishCoalesce(_chunkMNHKOS6Lcjs.getRivetRunEnginePort.call(void 0, ), () => ( ENGINE_PORT))),
671
715
  /** @experimental */
672
- engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkY5NSCZA2cjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkY5NSCZA2cjs.VERSION))),
716
+ engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkMNHKOS6Lcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkMNHKOS6Lcjs.VERSION))),
673
717
  /**
674
718
  * @experimental
675
719
  *
@@ -703,7 +747,7 @@ var RegistryConfigSchema = _zod.z.object({
703
747
  * after calling `CoreRegistry::shutdown()`. Defaults to the
704
748
  * engine-provided actor stop threshold once the envoy connects.
705
749
  *
706
- * Must be >= rivetkit-core's drain timeout (20s) + margin.
750
+ * Must be long enough for rivetkit-core to drain the envoy.
707
751
  */
708
752
  gracePeriodMs: _zod.z.number().int().min(1e3).optional(),
709
753
  /**
@@ -717,7 +761,7 @@ var RegistryConfigSchema = _zod.z.object({
717
761
  }))
718
762
  }).transform((config, ctx) => {
719
763
  var _a, _b, _c;
720
- const isDevEnv = _chunkY5NSCZA2cjs.isDev.call(void 0, );
764
+ const isDevEnv = _chunkMNHKOS6Lcjs.isDev.call(void 0, );
721
765
  const sqliteBackend = _nullishCoalesce(((_a = config.sqlite) == null ? void 0 : _a.backend), () => ( ((_b = config.test) == null ? void 0 : _b.sqliteBackend)));
722
766
  if (config.runtime === "wasm" && sqliteBackend === "local") {
723
767
  ctx.addIssue({
@@ -727,7 +771,7 @@ var RegistryConfigSchema = _zod.z.object({
727
771
  });
728
772
  }
729
773
  const sqlite = config.runtime === "wasm" && config.sqlite === void 0 ? { backend: "remote" } : config.sqlite;
730
- const parsedEndpoint = config.endpoint ? _chunkGVTOE34Scjs.tryParseEndpoint.call(void 0, ctx, {
774
+ const parsedEndpoint = config.endpoint ? _chunk5IWLUJ6Wcjs.tryParseEndpoint.call(void 0, ctx, {
731
775
  endpoint: config.endpoint,
732
776
  path: ["endpoint"],
733
777
  namespace: config.namespace,
@@ -745,13 +789,17 @@ var RegistryConfigSchema = _zod.z.object({
745
789
  message: "configurePool requires either endpoint or startEngine"
746
790
  });
747
791
  }
748
- const endpoint = config.startEngine ? ENGINE_ENDPOINT : _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint), () => ( (isDevEnv ? ENGINE_ENDPOINT : void 0)));
792
+ const localEngineEndpoint = buildEngineEndpoint(
793
+ config.engineHost,
794
+ config.enginePort
795
+ );
796
+ const endpoint = config.startEngine ? localEngineEndpoint : _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint), () => ( (isDevEnv ? buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT) : void 0)));
749
797
  const validateServerlessEndpoint = Boolean(
750
798
  config.startEngine || parsedEndpoint
751
799
  );
752
800
  const namespace = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.namespace), () => ( config.namespace)), () => ( "default"));
753
801
  const token = _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.token), () => ( config.token));
754
- const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkGVTOE34Scjs.tryParseEndpoint.call(void 0, ctx, {
802
+ const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunk5IWLUJ6Wcjs.tryParseEndpoint.call(void 0, ctx, {
755
803
  endpoint: config.serverless.publicEndpoint,
756
804
  path: ["serverless", "publicEndpoint"]
757
805
  }) : void 0;
@@ -762,7 +810,7 @@ var RegistryConfigSchema = _zod.z.object({
762
810
  path: ["serverless", "publicEndpoint"]
763
811
  });
764
812
  }
765
- const publicEndpoint = _nullishCoalesce((parsedPublicEndpoint == null ? void 0 : parsedPublicEndpoint.endpoint), () => ( (isDevEnv && config.startEngine ? ENGINE_ENDPOINT : void 0)));
813
+ const publicEndpoint = _nullishCoalesce((parsedPublicEndpoint == null ? void 0 : parsedPublicEndpoint.endpoint), () => ( (isDevEnv && config.startEngine ? endpoint : void 0)));
766
814
  const publicNamespace = parsedPublicEndpoint == null ? void 0 : parsedPublicEndpoint.namespace;
767
815
  const publicToken = _nullishCoalesce((parsedPublicEndpoint == null ? void 0 : parsedPublicEndpoint.token), () => ( config.serverless.publicToken));
768
816
  return {
@@ -786,30 +834,30 @@ function buildActorNames(config) {
786
834
  Object.keys(config.use).map((actorName) => {
787
835
  const definition = config.use[actorName];
788
836
  const options = _nullishCoalesce(definition.config.options, () => ( {}));
789
- const runMeta = _chunkWQ4HNA4Wcjs.getRunMetadata.call(void 0, definition.config.run);
837
+ const runMeta = _chunk3MHDOUD7cjs.getRunMetadata.call(void 0, definition.config.run);
790
838
  const metadata = {};
791
839
  metadata.icon = _nullishCoalesce(options.icon, () => ( runMeta.icon));
792
840
  metadata.name = _nullishCoalesce(options.name, () => ( runMeta.name));
793
841
  metadata.preload = {
794
842
  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)
843
+ Array.from(_chunkVE2X4KMGcjs.KEYS.PERSIST_DATA),
844
+ Array.from(_chunkVE2X4KMGcjs.KEYS.INSPECTOR_TOKEN),
845
+ Array.from(_chunkVE2X4KMGcjs.queueMetadataKey.call(void 0, )),
846
+ Array.from(_chunkVE2X4KMGcjs.KEYS.LAST_PUSHED_ALARM)
799
847
  ],
800
848
  prefixes: [
801
849
  {
802
- prefix: Array.from(_chunkLD5YASJUcjs.workflowStoragePrefix.call(void 0, )),
850
+ prefix: Array.from(_chunkVE2X4KMGcjs.workflowStoragePrefix.call(void 0, )),
803
851
  maxBytes: _nullishCoalesce(options.preloadMaxWorkflowBytes, () => ( 131072)),
804
852
  partial: false
805
853
  },
806
854
  {
807
- prefix: Array.from(_chunkLD5YASJUcjs.KEYS.CONN_PREFIX),
855
+ prefix: Array.from(_chunkVE2X4KMGcjs.KEYS.CONN_PREFIX),
808
856
  maxBytes: _nullishCoalesce(options.preloadMaxConnectionsBytes, () => ( 65536)),
809
857
  partial: false
810
858
  },
811
859
  {
812
- prefix: Array.from(_chunkLD5YASJUcjs.queueMessagesPrefix.call(void 0, )),
860
+ prefix: Array.from(_chunkVE2X4KMGcjs.queueMessagesPrefix.call(void 0, )),
813
861
  maxBytes: 65536,
814
862
  partial: false
815
863
  }
@@ -879,7 +927,7 @@ var DocRegistryConfigSchema = _zod.z.object({
879
927
  noWelcome: _zod.z.boolean().optional().describe("Disable the welcome message on startup. Default: false"),
880
928
  sqlite: DocSqliteConfigSchema,
881
929
  logging: _zod.z.object({
882
- level: _chunkY5NSCZA2cjs.LogLevelSchema.optional().describe(
930
+ level: _chunkMNHKOS6Lcjs.LogLevelSchema.optional().describe(
883
931
  "Log level for RivetKit. Default: 'warn'"
884
932
  )
885
933
  }).optional().describe("Logging configuration."),
@@ -924,7 +972,7 @@ function shouldAttachNativeKvError(message) {
924
972
  function enrichNativeDatabaseError(database, error) {
925
973
  var _a;
926
974
  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);
975
+ const bridged = bridgeReason === void 0 ? void 0 : _chunk4FC7TVS6cjs.decodeBridgeRivetError.call(void 0, bridgeReason);
928
976
  if (bridged) {
929
977
  throw bridged;
930
978
  }
@@ -1154,6 +1202,82 @@ function lastInsertRowIdColumnName(sql) {
1154
1202
  return alias;
1155
1203
  }
1156
1204
 
1205
+ // src/utils/node.ts
1206
+ var _module = require('module');
1207
+ var nodeCrypto;
1208
+ var nodeFsSync;
1209
+ var nodeFs;
1210
+ var nodePath;
1211
+ var nodeOs;
1212
+ var nodeChildProcess;
1213
+ var nodeStream;
1214
+ var nodeUrl;
1215
+ var hasImportedDependencies = false;
1216
+ function getRequireFn() {
1217
+ return _module.createRequire.call(void 0, import.meta.url);
1218
+ }
1219
+ function importNodeDependencies() {
1220
+ if (hasImportedDependencies) return;
1221
+ try {
1222
+ const requireFn = getRequireFn();
1223
+ nodeCrypto = requireFn(
1224
+ /* webpackIgnore: true */
1225
+ "node:crypto"
1226
+ );
1227
+ nodeFsSync = requireFn(
1228
+ /* webpackIgnore: true */
1229
+ "node:fs"
1230
+ );
1231
+ nodeFs = requireFn(
1232
+ /* webpackIgnore: true */
1233
+ "node:fs/promises"
1234
+ );
1235
+ nodePath = requireFn(
1236
+ /* webpackIgnore: true */
1237
+ "node:path"
1238
+ );
1239
+ nodeOs = requireFn(
1240
+ /* webpackIgnore: true */
1241
+ "node:os"
1242
+ );
1243
+ nodeChildProcess = requireFn(
1244
+ /* webpackIgnore: true */
1245
+ "node:child_process"
1246
+ );
1247
+ nodeStream = requireFn(
1248
+ /* webpackIgnore: true */
1249
+ "node:stream/promises"
1250
+ );
1251
+ nodeUrl = requireFn(
1252
+ /* webpackIgnore: true */
1253
+ "node:url"
1254
+ );
1255
+ hasImportedDependencies = true;
1256
+ } catch (err) {
1257
+ console.warn(
1258
+ "Node.js modules not available, file system driver will not work",
1259
+ err
1260
+ );
1261
+ throw err;
1262
+ }
1263
+ }
1264
+ function getNodeFsSync() {
1265
+ if (!nodeFsSync) {
1266
+ throw new Error(
1267
+ "Node fs module not loaded. Ensure importNodeDependencies() has been called."
1268
+ );
1269
+ }
1270
+ return nodeFsSync;
1271
+ }
1272
+ function getNodePath() {
1273
+ if (!nodePath) {
1274
+ throw new Error(
1275
+ "Node path module not loaded. Ensure importNodeDependencies() has been called."
1276
+ );
1277
+ }
1278
+ return nodePath;
1279
+ }
1280
+
1157
1281
  // src/registry/runtime.ts
1158
1282
  function normalizeRuntimeSqlExecuteResult(result) {
1159
1283
  return result;
@@ -1309,6 +1433,16 @@ var NapiCoreRuntime = (_class = class {
1309
1433
  config
1310
1434
  );
1311
1435
  }
1436
+ async serveListener(registry, listener, config) {
1437
+ await asNativeRegistry(registry).serveListener(
1438
+ {
1439
+ port: listener.port,
1440
+ host: listener.host,
1441
+ publicDir: listener.publicDir
1442
+ },
1443
+ config
1444
+ );
1445
+ }
1312
1446
  createActorFactory(callbacks, config) {
1313
1447
  return asActorFactoryHandle(
1314
1448
  new this.#bindings.NapiActorFactory(callbacks, config)
@@ -1424,6 +1558,9 @@ var NapiCoreRuntime = (_class = class {
1424
1558
  async actorWaitForTrackedShutdownWork(ctx) {
1425
1559
  return await asNativeActorContext(ctx).waitForTrackedShutdownWork();
1426
1560
  }
1561
+ async actorWaitForTrackedShutdownWorkUnbounded(ctx) {
1562
+ await asNativeActorContext(ctx).waitForTrackedShutdownWorkUnbounded();
1563
+ }
1427
1564
  actorKeepAwake(ctx, promise) {
1428
1565
  asNativeActorContext(ctx).keepAwake(promise);
1429
1566
  }
@@ -1535,8 +1672,12 @@ var NapiCoreRuntime = (_class = class {
1535
1672
  )
1536
1673
  );
1537
1674
  }
1538
- async actorQueueWaitForNamesAvailable(ctx, names, options) {
1539
- await asNativeActorContext(ctx).queue().waitForNamesAvailable(names, options);
1675
+ async actorQueueWaitForNamesAvailable(ctx, names, options, signal) {
1676
+ await asNativeActorContext(ctx).queue().waitForNamesAvailable(
1677
+ names,
1678
+ options,
1679
+ signal ? asNativeCancellationToken(signal) : signal
1680
+ );
1540
1681
  }
1541
1682
  async actorQueueEnqueueAndWait(ctx, name, body, options, signal) {
1542
1683
  return await asNativeActorContext(ctx).queue().enqueueAndWait(
@@ -1670,20 +1811,18 @@ function validateQueueComplete(schemas, name, response) {
1670
1811
  response
1671
1812
  );
1672
1813
  if (!result.success) {
1673
- throw validationError(`queue \`${name}\` completion response`, result.issues);
1814
+ throw validationError(
1815
+ `queue \`${name}\` completion response`,
1816
+ result.issues
1817
+ );
1674
1818
  }
1675
1819
  return result.data;
1676
1820
  }
1677
1821
  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
- );
1822
+ return new (0, _chunk4FC7TVS6cjs.RivetError)("actor", "validation_error", `Invalid ${target}`, {
1823
+ public: true,
1824
+ metadata: { issues }
1825
+ });
1687
1826
  }
1688
1827
 
1689
1828
  // src/registry/wasm-runtime.ts
@@ -1749,16 +1888,16 @@ function normalizeQueueMessage(message) {
1749
1888
  }
1750
1889
  function normalizeWasmBridgeError(error) {
1751
1890
  if (typeof error === "string") {
1752
- return _nullishCoalesce(_chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
1891
+ return _nullishCoalesce(_chunk4FC7TVS6cjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
1753
1892
  }
1754
1893
  if (error instanceof Error) {
1755
- const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.message);
1894
+ const bridged = _chunk4FC7TVS6cjs.decodeBridgeRivetError.call(void 0, error.message);
1756
1895
  if (bridged) {
1757
1896
  return bridged;
1758
1897
  }
1759
1898
  }
1760
1899
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
1761
- const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.reason);
1900
+ const bridged = _chunk4FC7TVS6cjs.decodeBridgeRivetError.call(void 0, error.reason);
1762
1901
  if (bridged) {
1763
1902
  return bridged;
1764
1903
  }
@@ -1780,7 +1919,7 @@ function callWasmSync(invoke) {
1780
1919
  }
1781
1920
  }
1782
1921
  function unsupportedWasmMethod(method2) {
1783
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
1922
+ throw new (0, _chunk4FC7TVS6cjs.RivetError)(
1784
1923
  "runtime",
1785
1924
  "unsupported",
1786
1925
  `Unsupported wasm runtime method: ${method2}`,
@@ -1864,6 +2003,11 @@ var WasmCoreRuntime = (_class2 = class {
1864
2003
  config
1865
2004
  );
1866
2005
  }
2006
+ async serveListener(_registry, _listener, _config) {
2007
+ throw new Error(
2008
+ "registry.listen() is not supported on the wasm runtime; use registry.serve() and mount the handler in your platform's HTTP server instead"
2009
+ );
2010
+ }
1867
2011
  createActorFactory(callbacks, config) {
1868
2012
  return callWasmSync(
1869
2013
  () => asActorFactoryHandle2(
@@ -2007,6 +2151,12 @@ var WasmCoreRuntime = (_class2 = class {
2007
2151
  "waitForTrackedShutdownWork"
2008
2152
  );
2009
2153
  }
2154
+ async actorWaitForTrackedShutdownWorkUnbounded(ctx) {
2155
+ await callHandle(
2156
+ asWasmActorContext(ctx),
2157
+ "waitForTrackedShutdownWorkUnbounded"
2158
+ );
2159
+ }
2010
2160
  actorKeepAwake(ctx, promise) {
2011
2161
  const wasmCtx = asWasmActorContext(ctx);
2012
2162
  const regionId = callHandle(wasmCtx, "beginKeepAwake");
@@ -2154,9 +2304,15 @@ var WasmCoreRuntime = (_class2 = class {
2154
2304
  )
2155
2305
  );
2156
2306
  }
2157
- async actorQueueWaitForNamesAvailable(ctx, names, options) {
2307
+ async actorQueueWaitForNamesAvailable(ctx, names, options, signal) {
2158
2308
  const queue2 = childHandle(asWasmActorContext(ctx), "queue");
2159
- await callHandleAsync(queue2, "waitForNamesAvailable", names, options);
2309
+ await callHandleAsync(
2310
+ queue2,
2311
+ "waitForNamesAvailable",
2312
+ names,
2313
+ options,
2314
+ signal
2315
+ );
2160
2316
  }
2161
2317
  async actorQueueEnqueueAndWait(ctx, name, body, options, signal) {
2162
2318
  const queue2 = childHandle(asWasmActorContext(ctx), "queue");
@@ -2248,6 +2404,29 @@ async function loadWasmRuntime(config) {
2248
2404
  };
2249
2405
  }
2250
2406
 
2407
+ // src/registry/write-through-proxy.ts
2408
+ var _onchange = require('@rivetkit/on-change'); var _onchange2 = _interopRequireDefault(_onchange);
2409
+ function createWriteThroughProxy(value, commit, beforeChange) {
2410
+ if (!value || typeof value !== "object") {
2411
+ return value;
2412
+ }
2413
+ return _onchange2.default.call(void 0,
2414
+ value,
2415
+ () => {
2416
+ commit(value);
2417
+ },
2418
+ {
2419
+ // Rejection is throw-based: beforeChange throws to prevent the
2420
+ // mutation. We always return true so on-change applies the change
2421
+ // if beforeChange did not throw.
2422
+ onValidate(_path, newValue) {
2423
+ beforeChange == null ? void 0 : beforeChange(newValue);
2424
+ return true;
2425
+ }
2426
+ }
2427
+ );
2428
+ }
2429
+
2251
2430
  // src/registry/native.ts
2252
2431
  var textEncoder = new TextEncoder();
2253
2432
  var textDecoder = new TextDecoder();
@@ -2260,7 +2439,7 @@ function trySetProcessEnv(key, value) {
2260
2439
  if (typeof process === "undefined") return;
2261
2440
  try {
2262
2441
  process.env[key] = value;
2263
- } catch (e) {
2442
+ } catch (e2) {
2264
2443
  }
2265
2444
  }
2266
2445
  function detectRuntimeHost() {
@@ -2281,7 +2460,7 @@ function loadedRuntimeKind(runtime) {
2281
2460
  case "wasm":
2282
2461
  return "wasm";
2283
2462
  }
2284
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
2463
+ throw new (0, _chunk4FC7TVS6cjs.RivetError)(
2285
2464
  "config",
2286
2465
  "unknown_runtime",
2287
2466
  "RivetKit runtime must be NAPI or wasm.",
@@ -2297,7 +2476,7 @@ async function loadAutoRuntime(config, loaders = defaultRuntimeLoaders) {
2297
2476
  }
2298
2477
  try {
2299
2478
  return (await loaders.loadNative()).runtime;
2300
- } catch (e2) {
2479
+ } catch (e3) {
2301
2480
  return (await loaders.loadWasm(config.wasm)).runtime;
2302
2481
  }
2303
2482
  }
@@ -2321,7 +2500,7 @@ function normalizeRuntimeConfigForKind(config, runtimeKind) {
2321
2500
  return config;
2322
2501
  }
2323
2502
  if (sqliteBackendForConfig(config) === "local") {
2324
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
2503
+ throw new (0, _chunk4FC7TVS6cjs.RivetError)(
2325
2504
  "config",
2326
2505
  "wasm_local_sqlite",
2327
2506
  "WebAssembly runtime cannot use local SQLite. Use remote SQLite instead.",
@@ -2387,22 +2566,30 @@ function getNativeConnPersistState(runtime, ctx, conn) {
2387
2566
  return connState;
2388
2567
  }
2389
2568
  function stateMutationReentrantError() {
2390
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
2569
+ return new (0, _chunk4FC7TVS6cjs.RivetError)(
2391
2570
  "actor",
2392
2571
  "state_mutation_reentrant",
2393
2572
  "State mutations are not allowed inside onStateChange."
2394
2573
  );
2395
2574
  }
2396
2575
  function databaseNotConfiguredError() {
2397
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
2576
+ return new (0, _chunk4FC7TVS6cjs.RivetError)(
2398
2577
  "actor",
2399
2578
  "database_not_configured",
2400
2579
  "database is not configured for this actor",
2401
2580
  { public: true }
2402
2581
  );
2403
2582
  }
2583
+ function databaseClientNotReadyError() {
2584
+ return new (0, _chunk4FC7TVS6cjs.RivetError)(
2585
+ "actor",
2586
+ "database_client_not_ready",
2587
+ "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.",
2588
+ { public: true }
2589
+ );
2590
+ }
2404
2591
  function stateNotEnabledError() {
2405
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
2592
+ return new (0, _chunk4FC7TVS6cjs.RivetError)(
2406
2593
  "actor",
2407
2594
  "state_not_enabled",
2408
2595
  "State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.dev/docs/actors/state/#initializing-state)",
@@ -2410,7 +2597,7 @@ function stateNotEnabledError() {
2410
2597
  );
2411
2598
  }
2412
2599
  function nativeClientNotConfiguredError() {
2413
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
2600
+ return new (0, _chunk4FC7TVS6cjs.RivetError)(
2414
2601
  "native",
2415
2602
  "client_not_configured",
2416
2603
  "native actor client is not configured",
@@ -2418,7 +2605,7 @@ function nativeClientNotConfiguredError() {
2418
2605
  );
2419
2606
  }
2420
2607
  function nativeEndpointNotConfiguredError() {
2421
- return new (0, _chunkQAZLM4WTcjs.RivetError)(
2608
+ return new (0, _chunk4FC7TVS6cjs.RivetError)(
2422
2609
  "native",
2423
2610
  "endpoint_not_configured",
2424
2611
  "registry endpoint is required for native envoy startup",
@@ -2452,8 +2639,23 @@ function resolveNativeDestroy(runtime, ctx) {
2452
2639
  function clearNativeRuntimeState(runtime, ctx) {
2453
2640
  callNativeSync(() => runtime.actorClearRuntimeState(ctx));
2454
2641
  }
2455
- async function cleanupNativeSleepRuntimeState(runtime, ctx) {
2456
- await runtime.actorWaitForTrackedShutdownWork(ctx);
2642
+ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrained) {
2643
+ const drained = await runtime.actorWaitForTrackedShutdownWork(ctx);
2644
+ if (!drained) {
2645
+ await closeNativeDatabaseClient(runtime, ctx);
2646
+ await closeNativeSqlDatabase(runtime, ctx);
2647
+ void runtime.actorWaitForTrackedShutdownWorkUnbounded(ctx).then(async () => {
2648
+ await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
2649
+ clearNativeRuntimeState(runtime, ctx);
2650
+ }).catch((error) => {
2651
+ logger2().warn({
2652
+ msg: "deferred native sleep cleanup failed",
2653
+ error: _chunkMNHKOS6Lcjs.stringifyError.call(void 0, error)
2654
+ });
2655
+ });
2656
+ return;
2657
+ }
2658
+ await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
2457
2659
  await closeNativeDatabaseClient(runtime, ctx);
2458
2660
  await closeNativeSqlDatabase(runtime, ctx);
2459
2661
  clearNativeRuntimeState(runtime, ctx);
@@ -2558,10 +2760,13 @@ function decodeValue(value) {
2558
2760
  if (!value || value.length === 0) {
2559
2761
  return void 0;
2560
2762
  }
2561
- return _chunkVJFRBJVQcjs.decodeCborJsonCompat.call(void 0, value);
2763
+ return _chunkV5KMAMX3cjs.decodeCborCompat.call(void 0, value);
2562
2764
  }
2563
2765
  function encodeValue(value) {
2564
- return _chunkVJFRBJVQcjs.encodeCborCompat.call(void 0, value);
2766
+ return _chunkV5KMAMX3cjs.encodeCborCompat.call(void 0, value);
2767
+ }
2768
+ function normalizeArgs(value) {
2769
+ return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
2565
2770
  }
2566
2771
  function unwrapTsfnPayload(error, payload) {
2567
2772
  if (error !== null && error !== void 0) {
@@ -2571,16 +2776,16 @@ function unwrapTsfnPayload(error, payload) {
2571
2776
  }
2572
2777
  function normalizeNativeBridgeError(error) {
2573
2778
  if (typeof error === "string") {
2574
- return _nullishCoalesce(_chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2779
+ return _nullishCoalesce(_chunk4FC7TVS6cjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2575
2780
  }
2576
2781
  if (error instanceof Error) {
2577
- const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.message);
2782
+ const bridged = _chunk4FC7TVS6cjs.decodeBridgeRivetError.call(void 0, error.message);
2578
2783
  if (bridged) {
2579
2784
  return bridged;
2580
2785
  }
2581
2786
  }
2582
2787
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
2583
- const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.reason);
2788
+ const bridged = _chunk4FC7TVS6cjs.decodeBridgeRivetError.call(void 0, error.reason);
2584
2789
  if (bridged) {
2585
2790
  return bridged;
2586
2791
  }
@@ -2588,14 +2793,14 @@ function normalizeNativeBridgeError(error) {
2588
2793
  return error;
2589
2794
  }
2590
2795
  function isStructuredBridgeError(error) {
2591
- if (error instanceof _chunkQAZLM4WTcjs.RivetError) {
2796
+ if (error instanceof _chunk4FC7TVS6cjs.RivetError) {
2592
2797
  return true;
2593
2798
  }
2594
- return _chunkQAZLM4WTcjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
2799
+ return _chunk4FC7TVS6cjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
2595
2800
  }
2596
2801
  function encodeNativeCallbackError(error) {
2597
- const structuredError = isStructuredBridgeError(error) ? error : _chunkY5NSCZA2cjs.deconstructError.call(void 0, error, true);
2598
- const bridgeError = new Error(_chunkQAZLM4WTcjs.encodeBridgeRivetError.call(void 0, structuredError), {
2802
+ const structuredError = isStructuredBridgeError(error) ? error : _chunkMNHKOS6Lcjs.deconstructError.call(void 0, error, true);
2803
+ const bridgeError = new Error(_chunk4FC7TVS6cjs.encodeBridgeRivetError.call(void 0, structuredError), {
2599
2804
  cause: error instanceof Error ? error : void 0
2600
2805
  });
2601
2806
  return Object.assign(bridgeError, {
@@ -2618,16 +2823,10 @@ function callNativeSync(invoke) {
2618
2823
  throw normalizeNativeBridgeError(error);
2619
2824
  }
2620
2825
  }
2621
- function actorAbortedError() {
2622
- return Object.assign(new Error("Actor aborted"), {
2623
- group: "actor",
2624
- code: "aborted"
2625
- });
2626
- }
2627
2826
  function isClosedTaskRegistrationError(error) {
2628
- const metadata = error instanceof _chunkQAZLM4WTcjs.RivetError ? error.metadata : void 0;
2827
+ const metadata = error instanceof _chunk4FC7TVS6cjs.RivetError ? error.metadata : void 0;
2629
2828
  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);
2829
+ return error instanceof _chunk4FC7TVS6cjs.RivetError && error.group === "core" && error.code === _chunk4FC7TVS6cjs.INTERNAL_ERROR_CODE && typeof metadataError === "string" && /actor task registration is (closed|not configured)/.test(metadataError);
2631
2830
  }
2632
2831
  async function createCancellationTokenHandle(runtime, signal) {
2633
2832
  if (!signal) {
@@ -2650,8 +2849,8 @@ function decodeWorkflowCbor(data) {
2650
2849
  return null;
2651
2850
  }
2652
2851
  try {
2653
- return _chunkVJFRBJVQcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
2654
- } catch (e3) {
2852
+ return _chunkV5KMAMX3cjs.decodeCborCompat.call(void 0, new Uint8Array(data));
2853
+ } catch (e4) {
2655
2854
  return null;
2656
2855
  }
2657
2856
  }
@@ -2755,8 +2954,8 @@ function serializeWorkflowHistoryForJson(data) {
2755
2954
  if (data === null) {
2756
2955
  return null;
2757
2956
  }
2758
- const history = _chunk4CGA6QJOcjs.decodeWorkflowHistoryTransport.call(void 0, data);
2759
- return {
2957
+ const history = _chunk4UUEB43Ycjs.decodeWorkflowHistoryTransport.call(void 0, data);
2958
+ return jsonSafe({
2760
2959
  nameRegistry: [...history.nameRegistry],
2761
2960
  entries: history.entries.map((entry) => ({
2762
2961
  id: entry.id,
@@ -2780,7 +2979,7 @@ function serializeWorkflowHistoryForJson(data) {
2780
2979
  ]
2781
2980
  )
2782
2981
  )
2783
- };
2982
+ });
2784
2983
  }
2785
2984
  function toHttpJsonCompatible(value) {
2786
2985
  return JSON.parse(
@@ -2831,45 +3030,7 @@ function wrapNativeCallback(callback) {
2831
3030
  }
2832
3031
  function decodeArgs(value) {
2833
3032
  const decoded = decodeValue(value);
2834
- return Array.isArray(decoded) ? decoded : decoded === void 0 ? [] : [decoded];
2835
- }
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);
3033
+ return normalizeArgs(decoded);
2873
3034
  }
2874
3035
  function buildRequest(init) {
2875
3036
  const url = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
@@ -2906,7 +3067,7 @@ var NativeConnAdapter = class {
2906
3067
  this.#schemas = schemas;
2907
3068
  this.#ctx = ctx;
2908
3069
  this.#queueHibernationRemoval = queueHibernationRemoval;
2909
- this[_chunkWQ4HNA4Wcjs.CONN_STATE_MANAGER_SYMBOL] = {
3070
+ this[_chunk3MHDOUD7cjs.CONN_STATE_MANAGER_SYMBOL] = {
2910
3071
  stateEnabled: true,
2911
3072
  get state() {
2912
3073
  return thisConn.state;
@@ -2923,13 +3084,23 @@ var NativeConnAdapter = class {
2923
3084
  decodeValue(this.#runtime.connParams(this.#conn))
2924
3085
  );
2925
3086
  }
3087
+ [_chunk3MHDOUD7cjs.RAW_STATE_SYMBOL]() {
3088
+ return this.#readState();
3089
+ }
2926
3090
  get state() {
2927
3091
  const nextState = this.#readState();
2928
- return createWriteThroughProxy(nextState, (nextValue) => {
2929
- this.#writeState(nextValue, { writeNative: true });
2930
- });
3092
+ return createWriteThroughProxy(
3093
+ nextState,
3094
+ (nextValue) => {
3095
+ this.#writeState(nextValue, { writeNative: true });
3096
+ },
3097
+ (newValue) => {
3098
+ _chunkV5KMAMX3cjs.assertJsonCompatValue.call(void 0, newValue);
3099
+ }
3100
+ );
2931
3101
  }
2932
3102
  set state(value) {
3103
+ _chunkV5KMAMX3cjs.assertJsonCompatValue.call(void 0, value);
2933
3104
  this.#writeState(value, { writeNative: true });
2934
3105
  }
2935
3106
  initializeState(value) {
@@ -3034,7 +3205,7 @@ var NativeKvAdapter = class {
3034
3205
  const value = await callNative(
3035
3206
  () => this.#runtime.actorKvGet(
3036
3207
  this.#ctx,
3037
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
3208
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
3038
3209
  )
3039
3210
  );
3040
3211
  return value ? decodeNativeKvValue(new Uint8Array(value), options) : null;
@@ -3043,7 +3214,7 @@ var NativeKvAdapter = class {
3043
3214
  await callNative(
3044
3215
  () => this.#runtime.actorKvPut(
3045
3216
  this.#ctx,
3046
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key)),
3217
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key)),
3047
3218
  toRuntimeBytes(value)
3048
3219
  )
3049
3220
  );
@@ -3052,7 +3223,7 @@ var NativeKvAdapter = class {
3052
3223
  await callNative(
3053
3224
  () => this.#runtime.actorKvDelete(
3054
3225
  this.#ctx,
3055
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
3226
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
3056
3227
  )
3057
3228
  );
3058
3229
  }
@@ -3060,8 +3231,8 @@ var NativeKvAdapter = class {
3060
3231
  await callNative(
3061
3232
  () => this.#runtime.actorKvDeleteRange(
3062
3233
  this.#ctx,
3063
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(start)),
3064
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(end))
3234
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(start)),
3235
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(end))
3065
3236
  )
3066
3237
  );
3067
3238
  }
@@ -3074,7 +3245,7 @@ var NativeKvAdapter = class {
3074
3245
  const entries = await callNative(
3075
3246
  () => this.#runtime.actorKvListPrefix(
3076
3247
  this.#ctx,
3077
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0,
3248
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0,
3078
3249
  encodeNativeKvUserKey(
3079
3250
  prefix,
3080
3251
  options == null ? void 0 : options.keyType
@@ -3088,7 +3259,7 @@ var NativeKvAdapter = class {
3088
3259
  );
3089
3260
  return entries.map((entry) => [
3090
3261
  decodeNativeKvKey(
3091
- _chunkLD5YASJUcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
3262
+ _chunkVE2X4KMGcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
3092
3263
  options == null ? void 0 : options.keyType
3093
3264
  ),
3094
3265
  decodeNativeKvValue(new Uint8Array(entry.value), options)
@@ -3107,13 +3278,13 @@ var NativeKvAdapter = class {
3107
3278
  const entries = await callNative(
3108
3279
  () => this.#runtime.actorKvListRange(
3109
3280
  this.#ctx,
3110
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0,
3281
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0,
3111
3282
  encodeNativeKvUserKey(
3112
3283
  start,
3113
3284
  options == null ? void 0 : options.keyType
3114
3285
  )
3115
3286
  ),
3116
- _chunkLD5YASJUcjs.makePrefixedKey.call(void 0,
3287
+ _chunkVE2X4KMGcjs.makePrefixedKey.call(void 0,
3117
3288
  encodeNativeKvUserKey(
3118
3289
  end,
3119
3290
  options == null ? void 0 : options.keyType
@@ -3127,7 +3298,7 @@ var NativeKvAdapter = class {
3127
3298
  );
3128
3299
  return entries.map((entry) => [
3129
3300
  decodeNativeKvKey(
3130
- _chunkLD5YASJUcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
3301
+ _chunkVE2X4KMGcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
3131
3302
  options == null ? void 0 : options.keyType
3132
3303
  ),
3133
3304
  decodeNativeKvValue(new Uint8Array(entry.value), options)
@@ -3219,7 +3390,7 @@ var NativeQueueAdapter = class {
3219
3390
  async nextBatch(options) {
3220
3391
  const completable = (options == null ? void 0 : options.completable) === true;
3221
3392
  if (this.#pendingCompletableMessageIds.size > 0) {
3222
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3393
+ throw new (0, _chunk4FC7TVS6cjs.RivetError)(
3223
3394
  "queue",
3224
3395
  "previous_message_not_completed",
3225
3396
  "Previous completable queue message is not completed. Call `message.complete(...)` before receiving the next message.",
@@ -3281,44 +3452,23 @@ var NativeQueueAdapter = class {
3281
3452
  }
3282
3453
  }
3283
3454
  async waitForNamesAvailable(names, options) {
3284
- if (!(options == null ? void 0 : options.signal)) {
3455
+ const { token, cleanup } = await createCancellationTokenHandle(
3456
+ this.#runtime,
3457
+ options == null ? void 0 : options.signal
3458
+ );
3459
+ try {
3285
3460
  await callNative(
3286
3461
  () => this.#runtime.actorQueueWaitForNamesAvailable(
3287
3462
  this.#ctx,
3288
3463
  [...names],
3289
3464
  {
3290
3465
  timeoutMs: options == null ? void 0 : options.timeout
3291
- }
3466
+ },
3467
+ token
3292
3468
  )
3293
3469
  );
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
- }
3470
+ } finally {
3471
+ cleanup == null ? void 0 : cleanup();
3322
3472
  }
3323
3473
  }
3324
3474
  async enqueueAndWait(name, body, options) {
@@ -3388,7 +3538,7 @@ var NativeQueueAdapter = class {
3388
3538
  }
3389
3539
  yield message;
3390
3540
  } catch (error) {
3391
- if (_chunkQAZLM4WTcjs.isRivetErrorLike.call(void 0, error) && error.group === "actor" && error.code === "aborted") {
3541
+ if (_chunk4FC7TVS6cjs.isActorAbortedError.call(void 0, error)) {
3392
3542
  return;
3393
3543
  }
3394
3544
  throw error;
@@ -3409,7 +3559,7 @@ var NativeQueueAdapter = class {
3409
3559
  ...message,
3410
3560
  complete: async (response) => {
3411
3561
  if (typeof message.complete !== "function") {
3412
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3562
+ throw new (0, _chunk4FC7TVS6cjs.RivetError)(
3413
3563
  "queue",
3414
3564
  "complete_not_configured",
3415
3565
  `Queue '${message.name}' does not support completion responses.`,
@@ -3421,7 +3571,7 @@ var NativeQueueAdapter = class {
3421
3571
  );
3422
3572
  }
3423
3573
  if (completed) {
3424
- throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3574
+ throw new (0, _chunk4FC7TVS6cjs.RivetError)(
3425
3575
  "queue",
3426
3576
  "already_completed",
3427
3577
  "Queue message was already completed.",
@@ -3753,6 +3903,68 @@ var TrackedWebSocketHandleAdapter = class {
3753
3903
  return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
3754
3904
  }
3755
3905
  };
3906
+ var NativeConnectionMap = (_class3 = class {
3907
+ #runtime;
3908
+ #ctx;
3909
+ #schemas;
3910
+ constructor(runtime, ctx, schemas) {;_class3.prototype.__init3.call(this);
3911
+ this.#runtime = runtime;
3912
+ this.#ctx = ctx;
3913
+ this.#schemas = schemas;
3914
+ }
3915
+ #connToAdapter(conn) {
3916
+ return new NativeConnAdapter(
3917
+ this.#runtime,
3918
+ conn,
3919
+ this.#schemas,
3920
+ this.#ctx,
3921
+ (connId) => callNativeSync(
3922
+ () => this.#runtime.actorQueueHibernationRemoval(
3923
+ this.#ctx,
3924
+ connId
3925
+ )
3926
+ )
3927
+ );
3928
+ }
3929
+ get size() {
3930
+ return callNativeSync(() => this.#runtime.actorConns(this.#ctx)).length;
3931
+ }
3932
+ get(key) {
3933
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3934
+ const conn = conns.find((c) => this.#runtime.connId(c) === key);
3935
+ if (!conn) return void 0;
3936
+ return this.#connToAdapter(conn);
3937
+ }
3938
+ has(key) {
3939
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3940
+ return conns.some((c) => this.#runtime.connId(c) === key);
3941
+ }
3942
+ keys() {
3943
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3944
+ return conns.map((c) => this.#runtime.connId(c))[Symbol.iterator]();
3945
+ }
3946
+ values() {
3947
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3948
+ return conns.map((c) => this.#connToAdapter(c))[Symbol.iterator]();
3949
+ }
3950
+ entries() {
3951
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3952
+ return conns.map(
3953
+ (c) => [this.#runtime.connId(c), this.#connToAdapter(c)]
3954
+ )[Symbol.iterator]();
3955
+ }
3956
+ forEach(callback, thisArg) {
3957
+ const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3958
+ for (const conn of conns) {
3959
+ const id = this.#runtime.connId(conn);
3960
+ callback.call(thisArg, this.#connToAdapter(conn), id, this);
3961
+ }
3962
+ }
3963
+ [Symbol.iterator]() {
3964
+ return this.entries();
3965
+ }
3966
+ __init3() {this[Symbol.toStringTag] = "NativeConnectionMap"}
3967
+ }, _class3);
3756
3968
  var ActorContextHandleAdapter = class {
3757
3969
  #runtime;
3758
3970
  #ctx;
@@ -3761,9 +3973,9 @@ var ActorContextHandleAdapter = class {
3761
3973
  #abortSignalCleanup;
3762
3974
  #client;
3763
3975
  #clientFactory;
3976
+ #connMap;
3764
3977
  #databaseProvider;
3765
3978
  #db;
3766
- #dbProxy;
3767
3979
  #dispatchCancelToken;
3768
3980
  #kv;
3769
3981
  #queue;
@@ -3786,7 +3998,7 @@ var ActorContextHandleAdapter = class {
3786
3998
  this.#databaseProvider = databaseProvider;
3787
3999
  }
3788
4000
  this.#request = request;
3789
- this[_chunkWQ4HNA4Wcjs.ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
4001
+ this[_chunk3MHDOUD7cjs.ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
3790
4002
  this
3791
4003
  );
3792
4004
  }
@@ -3806,30 +4018,22 @@ var ActorContextHandleAdapter = class {
3806
4018
  if (!this.#databaseProvider) {
3807
4019
  throw databaseNotConfiguredError();
3808
4020
  }
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
- );
4021
+ if (this.#db) {
4022
+ return this.#db;
3831
4023
  }
3832
- return this.#dbProxy;
4024
+ const runtimeState = getNativeRuntimeState(this.#runtime, this.#ctx);
4025
+ const cachedClient = runtimeState.databaseClient;
4026
+ if (cachedClient) {
4027
+ this.#db = cachedClient.client;
4028
+ return this.#db;
4029
+ }
4030
+ throw databaseClientNotReadyError();
4031
+ }
4032
+ [_chunk3MHDOUD7cjs.RAW_STATE_SYMBOL]() {
4033
+ if (!this.#stateEnabled) {
4034
+ throw stateNotEnabledError();
4035
+ }
4036
+ return this.#readState();
3833
4037
  }
3834
4038
  get state() {
3835
4039
  if (!this.#stateEnabled) {
@@ -3844,8 +4048,9 @@ var ActorContextHandleAdapter = class {
3844
4048
  (nextValue) => {
3845
4049
  this.#writeState(nextValue, { scheduleSave: true });
3846
4050
  },
3847
- () => {
4051
+ (newValue) => {
3848
4052
  this.#assertCanMutateState();
4053
+ _chunkV5KMAMX3cjs.assertJsonCompatValue.call(void 0, newValue);
3849
4054
  }
3850
4055
  );
3851
4056
  }
@@ -3856,6 +4061,7 @@ var ActorContextHandleAdapter = class {
3856
4061
  throw stateNotEnabledError();
3857
4062
  }
3858
4063
  this.#assertCanMutateState();
4064
+ _chunkV5KMAMX3cjs.assertJsonCompatValue.call(void 0, value);
3859
4065
  this.#writeState(value, { scheduleSave: true });
3860
4066
  }
3861
4067
  initializeState(value) {
@@ -3912,25 +4118,14 @@ var ActorContextHandleAdapter = class {
3912
4118
  return callNativeSync(() => this.#runtime.actorRegion(this.#ctx));
3913
4119
  }
3914
4120
  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
- );
4121
+ if (!this.#connMap) {
4122
+ this.#connMap = new NativeConnectionMap(
4123
+ this.#runtime,
4124
+ this.#ctx,
4125
+ this.#schemas
4126
+ );
4127
+ }
4128
+ return this.#connMap;
3934
4129
  }
3935
4130
  get log() {
3936
4131
  return logger2();
@@ -4131,7 +4326,7 @@ var ActorContextHandleAdapter = class {
4131
4326
  const trackedPromise = Promise.resolve(promise).catch((error) => {
4132
4327
  logger2().warn({
4133
4328
  msg: "keepAwake promise rejected",
4134
- error: _chunkY5NSCZA2cjs.stringifyError.call(void 0, error)
4329
+ error: _chunkMNHKOS6Lcjs.stringifyError.call(void 0, error)
4135
4330
  });
4136
4331
  }).then(() => null);
4137
4332
  try {
@@ -4151,7 +4346,10 @@ var ActorContextHandleAdapter = class {
4151
4346
  }
4152
4347
  internalKeepAwake(run) {
4153
4348
  const promise = typeof run === "function" ? run() : run;
4154
- const trackedPromise = promise.then(() => null);
4349
+ const trackedPromise = promise.then(
4350
+ () => null,
4351
+ () => null
4352
+ );
4155
4353
  try {
4156
4354
  callNativeSync(
4157
4355
  () => this.#runtime.actorRegisterTask(this.#ctx, trackedPromise)
@@ -4207,6 +4405,7 @@ var ActorContextHandleAdapter = class {
4207
4405
  return false;
4208
4406
  }
4209
4407
  sleep() {
4408
+ this.#flushStateChange();
4210
4409
  callNativeSync(() => this.#runtime.actorSleep(this.#ctx));
4211
4410
  }
4212
4411
  destroy() {
@@ -4467,7 +4666,7 @@ function withConnContext(runtime, ctx, conn, clientFactory, schemas = {}, databa
4467
4666
  }
4468
4667
  );
4469
4668
  }
4470
- function buildActorConfig(definition, registryConfig) {
4669
+ function buildActorConfig(definition, registryConfig, runtimeKind) {
4471
4670
  const config = definition.config;
4472
4671
  const options = _nullishCoalesce(config.options, () => ( {}));
4473
4672
  const canHibernate = options.canHibernateWebSocket;
@@ -4496,9 +4695,79 @@ function buildActorConfig(definition, registryConfig) {
4496
4695
  maxOutgoingMessageSize: registryConfig.maxOutgoingMessageSize,
4497
4696
  preloadMaxWorkflowBytes: options.preloadMaxWorkflowBytes,
4498
4697
  preloadMaxConnectionsBytes: options.preloadMaxConnectionsBytes,
4499
- actions: Object.keys(_nullishCoalesce(config.actions, () => ( {}))).sort().map((name) => ({ name }))
4698
+ actions: Object.keys(_nullishCoalesce(config.actions, () => ( {}))).sort().map((name) => ({ name })),
4699
+ inspectorTabs: buildInspectorTabs(config.inspector, runtimeKind)
4500
4700
  };
4501
4701
  }
4702
+ function buildInspectorTabs(inspector, runtimeKind) {
4703
+ if (!inspector || typeof inspector !== "object") return void 0;
4704
+ const tabs = inspector.tabs;
4705
+ if (!Array.isArray(tabs) || tabs.length === 0) return void 0;
4706
+ return tabs.map((raw) => {
4707
+ const entry = raw;
4708
+ if (entry.hidden === true) {
4709
+ return { id: entry.id, hidden: true };
4710
+ }
4711
+ if (runtimeKind === "wasm") {
4712
+ if (entry.source !== void 0) {
4713
+ logger2().warn(
4714
+ {
4715
+ tabId: entry.id,
4716
+ runtimeKind
4717
+ },
4718
+ "inspector.tabs[].source is not supported on wasm runners (current host: wasm). Tab descriptors will still appear in the dashboard strip but the tab body will render a not-available placeholder."
4719
+ );
4720
+ }
4721
+ return {
4722
+ id: entry.id,
4723
+ label: entry.label,
4724
+ icon: entry.icon,
4725
+ source: void 0
4726
+ };
4727
+ }
4728
+ const resolved = entry.source !== void 0 ? getNodePath().resolve(entry.source) : void 0;
4729
+ if (resolved !== void 0) {
4730
+ validateInspectorTabSource(entry.id, resolved);
4731
+ }
4732
+ return {
4733
+ id: entry.id,
4734
+ label: entry.label,
4735
+ icon: entry.icon,
4736
+ source: resolved
4737
+ };
4738
+ });
4739
+ }
4740
+ function validateInspectorTabSource(tabId, resolved) {
4741
+ if (resolved === getNodePath().parse(resolved).root) {
4742
+ throw new Error(
4743
+ `inspector.tabs[id="${tabId}"].source resolves to the filesystem root (${resolved}). Point it at the tab's own static-asset directory instead.`
4744
+ );
4745
+ }
4746
+ let stat;
4747
+ try {
4748
+ stat = getNodeFsSync().statSync(resolved);
4749
+ } catch (err) {
4750
+ const code = err == null ? void 0 : err.code;
4751
+ if (code === "ENOENT") {
4752
+ throw new Error(
4753
+ `inspector.tabs[id="${tabId}"].source (${resolved}) does not exist.`
4754
+ );
4755
+ }
4756
+ if (code === "EACCES") {
4757
+ throw new Error(
4758
+ `inspector.tabs[id="${tabId}"].source (${resolved}) is not readable (EACCES).`
4759
+ );
4760
+ }
4761
+ throw new Error(
4762
+ `inspector.tabs[id="${tabId}"].source (${resolved}) could not be stat'd: ${_nullishCoalesce((err == null ? void 0 : err.message), () => ( err))}`
4763
+ );
4764
+ }
4765
+ if (!stat.isDirectory()) {
4766
+ throw new Error(
4767
+ `inspector.tabs[id="${tabId}"].source (${resolved}) must be a directory, got ${stat.isFile() ? "file" : "non-directory"}.`
4768
+ );
4769
+ }
4770
+ }
4502
4771
  function buildNativeFactory(runtime, registryConfig, definition) {
4503
4772
  var _a;
4504
4773
  const config = definition.config;
@@ -4512,9 +4781,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4512
4781
  const actionHandlers = Object.fromEntries(
4513
4782
  Object.entries(_nullishCoalesce(config.actions, () => ( {}))).map(([name, handler]) => [name, handler])
4514
4783
  );
4515
- const createClient = () => _chunkGVTOE34Scjs.createClientWithDriver.call(void 0,
4516
- new (0, _chunkGVTOE34Scjs.RemoteEngineControlClient)(
4517
- _chunkGVTOE34Scjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
4784
+ const createClient = () => _chunk5IWLUJ6Wcjs.createClientWithDriver.call(void 0,
4785
+ new (0, _chunk5IWLUJ6Wcjs.RemoteEngineControlClient)(
4786
+ _chunk5IWLUJ6Wcjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
4518
4787
  ),
4519
4788
  { encoding: "bare" }
4520
4789
  );
@@ -4524,7 +4793,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4524
4793
  ), () => ( false));
4525
4794
  const getNativeWorkflowInspector = (ctx) => {
4526
4795
  var _a2;
4527
- return (_a2 = _chunkWQ4HNA4Wcjs.getRunInspectorConfig.call(void 0,
4796
+ return (_a2 = _chunk3MHDOUD7cjs.getRunInspectorConfig.call(void 0,
4528
4797
  config.run,
4529
4798
  callNativeSync(() => runtime.actorId(ctx))
4530
4799
  )) == null ? void 0 : _a2.workflow;
@@ -4577,7 +4846,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4577
4846
  }
4578
4847
  });
4579
4848
  const errorResponse = (error, status) => {
4580
- const rivetError = _chunkQAZLM4WTcjs.toRivetError.call(void 0, error);
4849
+ const rivetError = _chunk4FC7TVS6cjs.toRivetError.call(void 0, error);
4581
4850
  return jsonResponse(
4582
4851
  {
4583
4852
  group: rivetError.group,
@@ -4590,13 +4859,16 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4590
4859
  }
4591
4860
  );
4592
4861
  };
4593
- try {
4594
- await runtime.actorVerifyInspectorAuth(
4595
- ctx,
4596
- _nullishCoalesce(((_a2 = jsRequest.headers.get("authorization")) == null ? void 0 : _a2.replace(/^Bearer\s+/i, "")), () => ( null))
4597
- );
4598
- } catch (error) {
4599
- return errorResponse(error, 401);
4862
+ const isPublicPerActorPath = jsRequest.method === "GET" && (url.pathname === "/inspector/tab-config" || url.pathname.startsWith("/inspector/custom-tabs/"));
4863
+ if (!isPublicPerActorPath) {
4864
+ try {
4865
+ await runtime.actorVerifyInspectorAuth(
4866
+ ctx,
4867
+ _nullishCoalesce(((_a2 = jsRequest.headers.get("authorization")) == null ? void 0 : _a2.replace(/^Bearer\s+/i, "")), () => ( null))
4868
+ );
4869
+ } catch (error) {
4870
+ return errorResponse(error, 401);
4871
+ }
4600
4872
  }
4601
4873
  const workflowHistory = () => {
4602
4874
  var _a3;
@@ -4687,6 +4959,10 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4687
4959
  isWorkflowEnabled: getNativeWorkflowInspector(ctx) !== void 0
4688
4960
  });
4689
4961
  } catch (error) {
4962
+ logger2().error({
4963
+ msg: "error replaying workflow history",
4964
+ error
4965
+ });
4690
4966
  return errorResponse(error);
4691
4967
  }
4692
4968
  }
@@ -4818,7 +5094,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4818
5094
  const action = actionHandlers[actionName];
4819
5095
  if (!action) {
4820
5096
  return errorResponse(
4821
- new (0, _chunkQAZLM4WTcjs.RivetError)(
5097
+ new (0, _chunk4FC7TVS6cjs.RivetError)(
4822
5098
  "action",
4823
5099
  "action_not_found",
4824
5100
  `Action ${actionName} not found`
@@ -4827,17 +5103,34 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4827
5103
  );
4828
5104
  }
4829
5105
  const body = await jsRequest.json();
5106
+ if (body.args !== void 0 && body.properties !== void 0) {
5107
+ return jsonResponse(
5108
+ { error: "use either args or properties, not both" },
5109
+ { status: 400 }
5110
+ );
5111
+ }
5112
+ if (body.properties !== void 0 && (body.properties === null || typeof body.properties !== "object" || Array.isArray(body.properties))) {
5113
+ return jsonResponse(
5114
+ { error: "properties must be an object" },
5115
+ { status: 400 }
5116
+ );
5117
+ }
5118
+ const args = body.properties !== void 0 ? [body.properties] : normalizeArgs(body.args);
4830
5119
  try {
4831
5120
  const output = await action(
4832
5121
  actorCtx,
4833
5122
  ...validateActionArgs(
4834
5123
  schemaConfig.actionInputSchemas,
4835
5124
  actionName,
4836
- _nullishCoalesce(body.args, () => ( []))
5125
+ args
4837
5126
  )
4838
5127
  );
4839
5128
  return jsonResponse({ output });
4840
5129
  } catch (error) {
5130
+ logger2().error({
5131
+ msg: "Error handling inspector action request",
5132
+ error
5133
+ });
4841
5134
  return errorResponse(error);
4842
5135
  }
4843
5136
  }
@@ -4851,6 +5144,10 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4851
5144
  { status: 404 }
4852
5145
  );
4853
5146
  } catch (error) {
5147
+ logger2().error({
5148
+ msg: "Error handling inspector request",
5149
+ error
5150
+ });
4854
5151
  return errorResponse(error);
4855
5152
  } finally {
4856
5153
  await actorCtx.dispose();
@@ -4973,24 +5270,30 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4973
5270
  async (error, payload) => {
4974
5271
  const { ctx } = unwrapTsfnPayload(error, payload);
4975
5272
  const actorCtx = makeActorCtx(ctx);
5273
+ const saveActorState = async () => {
5274
+ if (runtime.kind === "wasm") {
5275
+ await runtime.actorSaveState(
5276
+ ctx,
5277
+ actorCtx.serializeForTick("save")
5278
+ );
5279
+ } else {
5280
+ await actorCtx.saveState({
5281
+ immediate: true
5282
+ });
5283
+ }
5284
+ };
4976
5285
  try {
4977
5286
  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
- }
5287
+ await onSleep(actorCtx);
4990
5288
  }
5289
+ await saveActorState();
4991
5290
  } finally {
4992
5291
  try {
4993
- await cleanupNativeSleepRuntimeState(runtime, ctx);
5292
+ await cleanupNativeSleepRuntimeState(
5293
+ runtime,
5294
+ ctx,
5295
+ saveActorState
5296
+ );
4994
5297
  } finally {
4995
5298
  await actorCtx.dispose();
4996
5299
  }
@@ -5006,6 +5309,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5006
5309
  await config.onDestroy(actorCtx);
5007
5310
  }
5008
5311
  } finally {
5312
+ const actorId = callNativeSync(() => runtime.actorId(ctx));
5313
+ nativeRunHandlerActiveByActorId.delete(actorId);
5314
+ _chunk3MHDOUD7cjs.disposeRunInspector.call(void 0, config.run, actorId);
5009
5315
  resolveNativeDestroy(runtime, ctx);
5010
5316
  await actorCtx.closeDatabase();
5011
5317
  clearNativeRuntimeState(runtime, ctx);
@@ -5155,7 +5461,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5155
5461
  );
5156
5462
  }
5157
5463
  if (!result) {
5158
- throw _chunkQAZLM4WTcjs.forbiddenError.call(void 0, );
5464
+ throw _chunk4FC7TVS6cjs.forbiddenError.call(void 0, );
5159
5465
  }
5160
5466
  } finally {
5161
5467
  await actorCtx.dispose();
@@ -5201,7 +5507,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5201
5507
  new Response(null, { status: 404 })
5202
5508
  );
5203
5509
  }
5204
- const rawConnParams = jsRequest.headers.get(_chunkGVTOE34Scjs.HEADER_CONN_PARAMS);
5510
+ const rawConnParams = jsRequest.headers.get(_chunk5IWLUJ6Wcjs.HEADER_CONN_PARAMS);
5205
5511
  let requestCtx;
5206
5512
  let conn;
5207
5513
  try {
@@ -5266,7 +5572,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5266
5572
  }
5267
5573
  ) : void 0,
5268
5574
  run: (() => {
5269
- const run = _chunkWQ4HNA4Wcjs.getRunFunction.call(void 0, config.run);
5575
+ const run = _chunk3MHDOUD7cjs.getRunFunction.call(void 0, config.run);
5270
5576
  if (!run) {
5271
5577
  return void 0;
5272
5578
  }
@@ -5279,13 +5585,13 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5279
5585
  try {
5280
5586
  await run(actorCtx);
5281
5587
  } finally {
5282
- nativeRunHandlerActiveByActorId.set(actorId, false);
5588
+ nativeRunHandlerActiveByActorId.delete(actorId);
5283
5589
  await actorCtx.dispose();
5284
5590
  }
5285
5591
  }
5286
5592
  );
5287
5593
  })(),
5288
- getWorkflowHistory: _chunkWQ4HNA4Wcjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5594
+ getWorkflowHistory: _chunk3MHDOUD7cjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5289
5595
  async (error, payload) => {
5290
5596
  var _a2;
5291
5597
  const { ctx } = unwrapTsfnPayload(error, payload);
@@ -5293,7 +5599,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5293
5599
  return history == null ? void 0 : encodeValue(history);
5294
5600
  }
5295
5601
  ) : void 0,
5296
- replayWorkflow: _chunkWQ4HNA4Wcjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5602
+ replayWorkflow: _chunk3MHDOUD7cjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5297
5603
  async (error, payload) => {
5298
5604
  const { ctx, entryId } = unwrapTsfnPayload(
5299
5605
  error,
@@ -5368,7 +5674,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5368
5674
  name
5369
5675
  );
5370
5676
  if (canPublish && !await canPublish(actorCtx)) {
5371
- throw _chunkQAZLM4WTcjs.forbiddenError.call(void 0, );
5677
+ throw _chunk4FC7TVS6cjs.forbiddenError.call(void 0, );
5372
5678
  }
5373
5679
  const decodedBody = decodeValue(body);
5374
5680
  if (wait) {
@@ -5412,7 +5718,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5412
5718
  };
5413
5719
  return runtime.createActorFactory(
5414
5720
  callbacks,
5415
- buildActorConfig(definition, registryConfig)
5721
+ buildActorConfig(definition, registryConfig, runtime.kind)
5416
5722
  );
5417
5723
  }
5418
5724
  async function buildServeConfig(config) {
@@ -5428,27 +5734,37 @@ async function buildServeConfig(config) {
5428
5734
  poolName: config.envoy.poolName,
5429
5735
  handleInspectorHttpInRuntime: true,
5430
5736
  serverlessBasePath: config.serverless.basePath,
5431
- serverlessPackageVersion: _chunkY5NSCZA2cjs.VERSION,
5737
+ serverlessPackageVersion: _chunkMNHKOS6Lcjs.VERSION,
5432
5738
  serverlessClientEndpoint: config.publicEndpoint,
5433
5739
  serverlessClientNamespace: config.publicNamespace,
5434
5740
  serverlessClientToken: config.publicToken,
5435
5741
  serverlessValidateEndpoint: config.validateServerlessEndpoint,
5436
5742
  serverlessMaxStartPayloadBytes: config.serverless.maxStartPayloadBytes
5437
5743
  };
5438
- if (config.startEngine) {
5744
+ try {
5439
5745
  const { getEnginePath } = await loadEngineCli();
5440
5746
  serveConfig.engineBinaryPath = getEnginePath();
5747
+ } catch (error) {
5748
+ logger2().warn({
5749
+ msg: "could not resolve a local engine binary; if a local engine must be spawned it will fail with engine.binary_unavailable \u2014 set RIVET_ENGINE_BINARY_PATH or install the @rivetkit/engine-cli platform package",
5750
+ error: _chunkMNHKOS6Lcjs.stringifyError.call(void 0, error)
5751
+ });
5441
5752
  }
5753
+ serveConfig.engineHost = config.engineHost;
5754
+ serveConfig.enginePort = config.enginePort;
5442
5755
  if ((_a = config.test) == null ? void 0 : _a.enabled) {
5443
- serveConfig.inspectorTestToken = _nullishCoalesce(_chunkY5NSCZA2cjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
5756
+ serveConfig.inspectorTestToken = _nullishCoalesce(_chunkMNHKOS6Lcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
5444
5757
  }
5445
5758
  return serveConfig;
5446
5759
  }
5447
5760
  async function buildRegistryWithRuntime(config, runtime) {
5448
5761
  var _a;
5449
- if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkY5NSCZA2cjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
5762
+ if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkMNHKOS6Lcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
5450
5763
  trySetProcessEnv("_RIVET_TEST_INSPECTOR_TOKEN", "token");
5451
5764
  }
5765
+ if (runtime.kind === "napi") {
5766
+ importNodeDependencies();
5767
+ }
5452
5768
  const registry = runtime.createRegistry();
5453
5769
  for (const [name, definition] of Object.entries(config.use)) {
5454
5770
  runtime.registerActor(
@@ -5488,6 +5804,7 @@ function finishShutdownSignal(signal) {
5488
5804
  }
5489
5805
  var Registry = class {
5490
5806
  #config;
5807
+ #buildConfiguredRegistry;
5491
5808
 
5492
5809
  get config() {
5493
5810
  return this.#config;
@@ -5503,23 +5820,30 @@ var Registry = class {
5503
5820
  #shutdownInstalled = false;
5504
5821
  #shutdownInFlight = null;
5505
5822
  #signalHandlers = {};
5506
- constructor(config) {
5823
+ constructor(config, deps) {
5507
5824
  this.#config = config;
5825
+ this.#buildConfiguredRegistry = _nullishCoalesce((deps == null ? void 0 : deps.buildConfiguredRegistry), () => ( buildConfiguredRegistry));
5508
5826
  this.routes = {
5509
5827
  health: () => this.#healthRoute(),
5510
5828
  metadata: () => this.#metadataRoute(),
5511
5829
  prometheusMetrics: (request) => this.#prometheusMetricsRoute(request)
5512
5830
  };
5513
5831
  }
5832
+ /**
5833
+ * Fires `configureServerlessPool` once per process when the registry
5834
+ * config opts into it. Cached on the instance so repeated calls (from
5835
+ * `handler()` and `listen()`) only run the upsert once. The retry loop
5836
+ * inside `configureServerlessPool` tolerates the engine still warming up.
5837
+ */
5514
5838
  #ensureServerlessPoolConfigured(config) {
5515
5839
  if (!config.configurePool) return void 0;
5516
5840
  if (!this.#configureServerlessPoolPromise) {
5517
- this.#configureServerlessPoolPromise = configureServerlessPool(config).catch(
5518
- (error) => {
5519
- this.#configureServerlessPoolPromise = void 0;
5520
- throw error;
5521
- }
5522
- );
5841
+ this.#configureServerlessPoolPromise = configureServerlessPool(
5842
+ config
5843
+ ).catch((error) => {
5844
+ this.#configureServerlessPoolPromise = void 0;
5845
+ throw error;
5846
+ });
5523
5847
  this.#configureServerlessPoolPromise.catch(() => {
5524
5848
  });
5525
5849
  }
@@ -5540,7 +5864,7 @@ var Registry = class {
5540
5864
  const config = this.parseConfig();
5541
5865
  this.#printWelcome(config, "serverless");
5542
5866
  if (!this.#runtimeServerlessPromise) {
5543
- this.#runtimeServerlessPromise = buildConfiguredRegistry(config);
5867
+ this.#runtimeServerlessPromise = this.#buildConfiguredRegistry(config);
5544
5868
  }
5545
5869
  const { runtime, registry, serveConfig } = await this.#runtimeServerlessPromise;
5546
5870
  const isStartRequest = isServerlessStartRequest(
@@ -5555,7 +5879,7 @@ var Registry = class {
5555
5879
  if (isStartRequest) {
5556
5880
  try {
5557
5881
  await this.#ensureServerlessPoolConfigured(config);
5558
- } catch (error) {
5882
+ } catch (_error) {
5559
5883
  return new Response(
5560
5884
  JSON.stringify({
5561
5885
  group: "guard",
@@ -5669,7 +5993,7 @@ var Registry = class {
5669
5993
  if (isMetadataRequest && !isEngineMetadataRequest) {
5670
5994
  try {
5671
5995
  await this.#ensureServerlessPoolConfigured(config);
5672
- } catch (error) {
5996
+ } catch (_error) {
5673
5997
  return new Response(
5674
5998
  JSON.stringify({
5675
5999
  group: "guard",
@@ -5702,6 +6026,44 @@ var Registry = class {
5702
6026
  fetch: (request) => this.handler(request)
5703
6027
  };
5704
6028
  }
6029
+ /**
6030
+ * Bind an HTTP listener provided by the native (Rust) runtime and serve
6031
+ * the registry's serverless endpoints over it. Resolves only after the
6032
+ * registry is shut down (SIGINT/SIGTERM or `nativeRegistry.shutdown()`).
6033
+ *
6034
+ * @param opts.port Port to listen on. Defaults to `process.env.RIVET_PORT`
6035
+ * if set, otherwise 3000.
6036
+ * @param opts.host Address to bind. Defaults to `0.0.0.0`.
6037
+ * @param opts.publicDir If set, serves static files from this directory
6038
+ * as a fallback below the framework routes.
6039
+ *
6040
+ * @example
6041
+ * ```ts
6042
+ * await registry.listen();
6043
+ * await registry.listen({ port: 8080, publicDir: "./public" });
6044
+ * ```
6045
+ */
6046
+ async listen(opts = {}) {
6047
+ const port = _nullishCoalesce(_nullishCoalesce(opts.port, () => ( _chunkMNHKOS6Lcjs.parsePortEnv.call(void 0, process.env.RIVET_PORT))), () => ( 3e3));
6048
+ const publicDir = _nullishCoalesce(opts.publicDir, () => ( _chunkMNHKOS6Lcjs.getRivetkitPublicDir.call(void 0, )));
6049
+ const config = this.parseConfig();
6050
+ const configuredRegistryPromise = buildConfiguredRegistry(config);
6051
+ this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
6052
+ this.#runtimeServerlessPromise = configuredRegistryPromise;
6053
+ this.#installSignalHandlers(config);
6054
+ this.#printWelcome(config, "serverless", {
6055
+ port,
6056
+ host: opts.host,
6057
+ publicDir
6058
+ });
6059
+ this.#ensureServerlessPoolConfigured(config);
6060
+ const { runtime, registry, serveConfig } = await configuredRegistryPromise;
6061
+ await runtime.serveListener(
6062
+ registry,
6063
+ { port, host: opts.host, publicDir },
6064
+ serveConfig
6065
+ );
6066
+ }
5705
6067
  /**
5706
6068
  * Returns a health response suitable for mounting in a user-owned router.
5707
6069
  */
@@ -5711,7 +6073,7 @@ var Registry = class {
5711
6073
  return jsonRouteResponse(503, {
5712
6074
  status: "not_started",
5713
6075
  runtime: "rivetkit",
5714
- version: _chunkY5NSCZA2cjs.VERSION
6076
+ version: _chunkMNHKOS6Lcjs.VERSION
5715
6077
  });
5716
6078
  }
5717
6079
  const { runtime, registry } = configured;
@@ -5719,7 +6081,7 @@ var Registry = class {
5719
6081
  return jsonRouteResponse(501, {
5720
6082
  status: "unsupported",
5721
6083
  runtime: "rivetkit",
5722
- version: _chunkY5NSCZA2cjs.VERSION
6084
+ version: _chunkMNHKOS6Lcjs.VERSION
5723
6085
  });
5724
6086
  }
5725
6087
  const response = await runtime.registryHealth(registry);
@@ -5791,20 +6153,20 @@ var Registry = class {
5791
6153
  */
5792
6154
  #startEnvoy(config, printWelcome) {
5793
6155
  if (!this.#runtimeServePromise) {
5794
- const configuredRegistryPromise = buildConfiguredRegistry(config);
6156
+ const configuredRegistryPromise = this.#buildConfiguredRegistry(config);
5795
6157
  this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
5796
6158
  this.#runtimeServePromise = configuredRegistryPromise.then(async ({ runtime, registry, serveConfig }) => {
5797
6159
  await runtime.serveRegistry(registry, serveConfig);
5798
- }).catch((err) => {
5799
- logger2().warn({ err }, "runtime registry serve errored");
6160
+ }).catch((error) => {
6161
+ logger2().warn({ error }, "runtime registry serve errored");
5800
6162
  });
5801
- this.#installSignalHandlers(config, configuredRegistryPromise);
6163
+ this.#installSignalHandlers(config);
5802
6164
  }
5803
6165
  if (printWelcome) {
5804
6166
  this.#printWelcome(config, "serverful");
5805
6167
  }
5806
6168
  }
5807
- #installSignalHandlers(config, configuredRegistryPromise) {
6169
+ #installSignalHandlers(config) {
5808
6170
  var _a;
5809
6171
  if (this.#shutdownInstalled) return;
5810
6172
  if ((_a = config.shutdown) == null ? void 0 : _a.disableSignalHandlers) return;
@@ -5813,58 +6175,86 @@ var Registry = class {
5813
6175
  }
5814
6176
  this.#shutdownInstalled = true;
5815
6177
  const install = (signal) => {
5816
- const handler = () => this.#onShutdownSignal(
5817
- signal,
5818
- config,
5819
- configuredRegistryPromise
5820
- );
6178
+ const handler = () => this.#onShutdownSignal(signal, config);
5821
6179
  this.#signalHandlers[signal] = handler;
5822
6180
  process.on(signal, handler);
5823
6181
  };
5824
6182
  install("SIGINT");
5825
6183
  install("SIGTERM");
5826
6184
  }
5827
- #onShutdownSignal(signal, config, configuredRegistryPromise) {
6185
+ #onShutdownSignal(signal, config) {
5828
6186
  if (this.#shutdownInFlight !== null) {
5829
6187
  this.#removeSignalHandlers();
5830
6188
  finishShutdownSignal(signal);
5831
6189
  return;
5832
6190
  }
5833
- this.#shutdownInFlight = this.#runShutdown(
5834
- signal,
5835
- config,
5836
- configuredRegistryPromise
5837
- ).catch((err) => {
6191
+ this.#shutdownInFlight = this.#drain(config).catch((err) => {
5838
6192
  logger2().warn({ err }, "shutdown error");
6193
+ }).then(() => {
6194
+ this.#removeSignalHandlers();
6195
+ finishShutdownSignal(signal);
5839
6196
  });
5840
6197
  }
5841
- async #runShutdown(signal, config, configuredRegistryPromise) {
6198
+ /**
6199
+ * Gracefully drains all live registries.
6200
+ *
6201
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
6202
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
6203
+ * waits for the serve promise to resolve, all bounded by the shutdown
6204
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
6205
+ * signal or exit the process. The caller owns process lifetime.
6206
+ *
6207
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
6208
+ * call even if nothing has been started.
6209
+ *
6210
+ * @example
6211
+ * ```ts
6212
+ * const registry = setup({ use: { counter } });
6213
+ * registry.start();
6214
+ * // ...later, on your own shutdown trigger:
6215
+ * await registry.shutdown();
6216
+ * ```
6217
+ */
6218
+ async shutdown() {
6219
+ if (this.#shutdownInFlight !== null) return this.#shutdownInFlight;
6220
+ const config = this.parseConfig();
6221
+ this.#removeSignalHandlers();
6222
+ this.#shutdownInFlight = this.#drain(config).catch((err) => {
6223
+ logger2().warn({ err }, "shutdown error");
6224
+ });
6225
+ return this.#shutdownInFlight;
6226
+ }
6227
+ async #drain(config) {
5842
6228
  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));
6229
+ const modeAPromise = this.#runtimeServeConfiguredPromise;
6230
+ const modeBPromise = this.#runtimeServerlessPromise;
6231
+ 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
6232
  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) {
6233
+ const registries = [];
6234
+ if (modeAPromise !== void 0) {
5860
6235
  registries.push(
5861
6236
  (async () => {
5862
6237
  try {
5863
- const { runtime, registry } = await runtimeServerlessPromise;
6238
+ const { runtime, registry } = await modeAPromise;
5864
6239
  await runtime.shutdownRegistry(registry);
5865
6240
  } catch (err) {
5866
6241
  logger2().warn(
5867
6242
  { err },
6243
+ "runtime registry shutdown errored (mode A)"
6244
+ );
6245
+ }
6246
+ })()
6247
+ );
6248
+ }
6249
+ if (modeBPromise !== void 0) {
6250
+ registries.push(
6251
+ (async () => {
6252
+ try {
6253
+ const { runtime, registry } = await modeBPromise;
6254
+ await runtime.shutdownRegistry(registry);
6255
+ } catch (err) {
6256
+ logger2().warn(
6257
+ { error: err },
5868
6258
  "runtime registry shutdown errored (mode B)"
5869
6259
  );
5870
6260
  }
@@ -5886,11 +6276,10 @@ var Registry = class {
5886
6276
  }
5887
6277
  )
5888
6278
  ]);
5889
- this.#removeSignalHandlers();
5890
- finishShutdownSignal(signal);
5891
6279
  }
5892
6280
  async #actorStopThresholdMs(configuredRegistryPromise) {
5893
6281
  var _a;
6282
+ if (configuredRegistryPromise === void 0) return void 0;
5894
6283
  try {
5895
6284
  const { runtime, registry } = await configuredRegistryPromise;
5896
6285
  const thresholdMs = await ((_a = runtime.registryActorStopThresholdMs) == null ? void 0 : _a.call(runtime, registry));
@@ -5919,6 +6308,10 @@ var Registry = class {
5919
6308
  /**
5920
6309
  * Starts the actor envoy for standalone server deployments.
5921
6310
  *
6311
+ * Set `RIVETKIT_RUNTIME_MODE=serverless` to instead bind an HTTP listener
6312
+ * via `listen()` (Mode B). Mode A (envoy) and Mode B (listener) are
6313
+ * mutually exclusive per registry instance.
6314
+ *
5922
6315
  * @example
5923
6316
  * ```ts
5924
6317
  * const registry = setup({ use: { counter } });
@@ -5926,10 +6319,20 @@ var Registry = class {
5926
6319
  * ```
5927
6320
  */
5928
6321
  start() {
6322
+ if (_chunkMNHKOS6Lcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
6323
+ const publicDir = _nullishCoalesce(_chunkMNHKOS6Lcjs.getRivetkitPublicDir.call(void 0, ), () => ( "/public"));
6324
+ this.listen({ publicDir }).catch((error) => {
6325
+ logger2().error({ error }, "auto-listen failed; exiting");
6326
+ if (typeof process !== "undefined" && typeof process.exit === "function") {
6327
+ process.exit(1);
6328
+ }
6329
+ });
6330
+ return;
6331
+ }
5929
6332
  const config = this.parseConfig();
5930
6333
  this.#startEnvoy(config, true);
5931
6334
  }
5932
- #printWelcome(config, kind) {
6335
+ #printWelcome(config, kind, listener) {
5933
6336
  if (config.noWelcome || this.#welcomePrinted) return;
5934
6337
  this.#welcomePrinted = true;
5935
6338
  const logLine = (label, value) => {
@@ -5938,19 +6341,26 @@ var Registry = class {
5938
6341
  };
5939
6342
  console.log();
5940
6343
  console.log(
5941
- ` RivetKit ${_chunkY5NSCZA2cjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
6344
+ ` RivetKit ${_chunkMNHKOS6Lcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
5942
6345
  );
5943
6346
  if (config.namespace !== "default") {
5944
6347
  logLine("Namespace", config.namespace);
5945
6348
  }
5946
6349
  if (config.endpoint) {
5947
- const endpointType = config.endpoint === ENGINE_ENDPOINT ? "local native" : "remote";
6350
+ const endpointType = config.startEngine || isLocalEngineEndpoint(config.endpoint) ? "local native" : "remote";
5948
6351
  logLine("Endpoint", `${config.endpoint} (${endpointType})`);
5949
6352
  }
5950
6353
  if (kind === "serverless" && config.publicEndpoint) {
5951
6354
  logLine("Client", config.publicEndpoint);
5952
6355
  }
5953
6356
  logLine("Actors", Object.keys(config.use).length.toString());
6357
+ if (listener) {
6358
+ const host = _nullishCoalesce(listener.host, () => ( "0.0.0.0"));
6359
+ logLine("Listening", `http://${host}:${listener.port}`);
6360
+ if (listener.publicDir) {
6361
+ logLine("Public Dir", listener.publicDir);
6362
+ }
6363
+ }
5954
6364
  console.log();
5955
6365
  }
5956
6366
  };
@@ -6006,5 +6416,5 @@ function setup(input) {
6006
6416
 
6007
6417
 
6008
6418
 
6009
- exports.ALLOWED_PUBLIC_HEADERS = _chunkGVTOE34Scjs.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 = _chunkGVTOE34Scjs.createClientWithDriver; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkY5NSCZA2cjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkY5NSCZA2cjs.toUint8Array;
6419
+ exports.ALLOWED_PUBLIC_HEADERS = _chunk5IWLUJ6Wcjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunk4FC7TVS6cjs.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 = _chunk4FC7TVS6cjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunk4FC7TVS6cjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunk5IWLUJ6Wcjs.createClientWithDriver; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkMNHKOS6Lcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkMNHKOS6Lcjs.toUint8Array;
6010
6420
  //# sourceMappingURL=mod.cjs.map