rivetkit 0.0.0-feat-sqlite-sync.32022a9 → 0.0.0-feat-sqlite-sync-3x.a00b07f

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 (154) hide show
  1. package/dist/browser/client.d.ts +58 -9
  2. package/dist/browser/client.js +193 -23
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +1 -5
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/agent-os/index.cjs +3 -2652
  7. package/dist/tsup/agent-os/index.cjs.map +1 -1
  8. package/dist/tsup/agent-os/index.d.cts +1 -2758
  9. package/dist/tsup/agent-os/index.d.ts +1 -2758
  10. package/dist/tsup/agent-os/index.js +3 -2652
  11. package/dist/tsup/agent-os/index.js.map +1 -1
  12. package/dist/tsup/{chunk-6ZHUGY2E.cjs → chunk-3JPXBFED.cjs} +4 -4
  13. package/dist/tsup/{chunk-6ZHUGY2E.cjs.map → chunk-3JPXBFED.cjs.map} +1 -1
  14. package/dist/tsup/{chunk-6VNQCLKF.js → chunk-5X35FD2T.js} +4 -4
  15. package/dist/tsup/{chunk-BJGWUWNE.js → chunk-6QNBANXM.js} +3 -3
  16. package/dist/tsup/{chunk-Z6IVW2Y5.js → chunk-7HILY7QU.js} +188 -28
  17. package/dist/tsup/chunk-7HILY7QU.js.map +1 -0
  18. package/dist/tsup/{chunk-JI6GZ2C2.js → chunk-A2CF6PFH.js} +18 -1
  19. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  20. package/dist/tsup/{chunk-7XBDAFGQ.cjs → chunk-CT6GQRUN.cjs} +3 -3
  21. package/dist/tsup/{chunk-7XBDAFGQ.cjs.map → chunk-CT6GQRUN.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-M27XAZNI.js → chunk-DRZTELHJ.js} +10 -14
  23. package/dist/tsup/chunk-DRZTELHJ.js.map +1 -0
  24. package/dist/tsup/{chunk-EDJKDOI2.js → chunk-DUGEPEJO.js} +2 -2
  25. package/dist/tsup/{chunk-PMU5EDGT.cjs → chunk-EA6P3N4I.cjs} +3 -3
  26. package/dist/tsup/{chunk-PMU5EDGT.cjs.map → chunk-EA6P3N4I.cjs.map} +1 -1
  27. package/dist/tsup/{chunk-WE7D64FW.cjs → chunk-ERZDCOQ3.cjs} +10 -10
  28. package/dist/tsup/{chunk-WE7D64FW.cjs.map → chunk-ERZDCOQ3.cjs.map} +1 -1
  29. package/dist/tsup/{chunk-UZ5O42HF.js → chunk-GHTA76HT.js} +2 -2
  30. package/dist/tsup/{chunk-IAVZH6HH.js → chunk-ID5VJNZY.js} +2 -2
  31. package/dist/tsup/{chunk-2LRKNNQJ.cjs → chunk-PXIOH445.cjs} +327 -167
  32. package/dist/tsup/chunk-PXIOH445.cjs.map +1 -0
  33. package/dist/tsup/{chunk-MYWZCDML.cjs → chunk-RTWH3AX3.cjs} +19 -2
  34. package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
  35. package/dist/tsup/{chunk-5LBUG2IK.cjs → chunk-UV4KDO4W.cjs} +3 -3
  36. package/dist/tsup/{chunk-5LBUG2IK.cjs.map → chunk-UV4KDO4W.cjs.map} +1 -1
  37. package/dist/tsup/{chunk-HHALUH4L.js → chunk-VI2S336K.js} +2 -2
  38. package/dist/tsup/{chunk-6BRDJRCZ.cjs → chunk-W7NPIYWC.cjs} +10 -14
  39. package/dist/tsup/chunk-W7NPIYWC.cjs.map +1 -0
  40. package/dist/tsup/{chunk-4SIQMCXI.cjs → chunk-ZZQM77UA.cjs} +7 -7
  41. package/dist/tsup/{chunk-4SIQMCXI.cjs.map → chunk-ZZQM77UA.cjs.map} +1 -1
  42. package/dist/tsup/client/mod.cjs +6 -6
  43. package/dist/tsup/client/mod.d.cts +15 -3
  44. package/dist/tsup/client/mod.d.ts +15 -3
  45. package/dist/tsup/client/mod.js +5 -5
  46. package/dist/tsup/common/log.cjs +2 -2
  47. package/dist/tsup/common/log.js +1 -1
  48. package/dist/tsup/common/websocket.cjs +3 -3
  49. package/dist/tsup/common/websocket.js +2 -2
  50. package/dist/tsup/{config-DfVrAigH.d.ts → config-B4erdavw.d.ts} +43 -12
  51. package/dist/tsup/{config-BaUctMNL.d.cts → config-BfG1qpYz.d.cts} +7 -1
  52. package/dist/tsup/{config-BaUctMNL.d.ts → config-BfG1qpYz.d.ts} +7 -1
  53. package/dist/tsup/{config-D6T6Ud_V.d.cts → config-DK144OAw.d.cts} +43 -12
  54. package/dist/tsup/{context-CowF_zyQ.d.cts → context-Cvnf3BRe.d.cts} +2 -2
  55. package/dist/tsup/{context-BsFWwi3i.d.ts → context-Oxi6YWcG.d.ts} +2 -2
  56. package/dist/tsup/db/drizzle.cjs +2 -2
  57. package/dist/tsup/db/drizzle.d.cts +1 -1
  58. package/dist/tsup/db/drizzle.d.ts +1 -1
  59. package/dist/tsup/db/drizzle.js +1 -1
  60. package/dist/tsup/db/mod.cjs +3 -3
  61. package/dist/tsup/db/mod.d.cts +2 -2
  62. package/dist/tsup/db/mod.d.ts +2 -2
  63. package/dist/tsup/db/mod.js +2 -2
  64. package/dist/tsup/dynamic/mod.d.cts +2 -2
  65. package/dist/tsup/dynamic/mod.d.ts +2 -2
  66. package/dist/tsup/inspector/mod.cjs +5 -5
  67. package/dist/tsup/inspector/mod.js +4 -4
  68. package/dist/tsup/inspector/workflow.cjs +4 -4
  69. package/dist/tsup/inspector/workflow.js +3 -3
  70. package/dist/tsup/inspector-tab/mod.d.cts +3 -3
  71. package/dist/tsup/inspector-tab/mod.d.ts +3 -3
  72. package/dist/tsup/mod.cjs +256 -174
  73. package/dist/tsup/mod.cjs.map +1 -1
  74. package/dist/tsup/mod.d.cts +4 -4
  75. package/dist/tsup/mod.d.ts +4 -4
  76. package/dist/tsup/mod.js +170 -88
  77. package/dist/tsup/mod.js.map +1 -1
  78. package/dist/tsup/test/mod.cjs +7 -7
  79. package/dist/tsup/test/mod.d.cts +2 -2
  80. package/dist/tsup/test/mod.d.ts +2 -2
  81. package/dist/tsup/test/mod.js +5 -5
  82. package/dist/tsup/unstable/migrations.d.cts +1 -1
  83. package/dist/tsup/unstable/migrations.d.ts +1 -1
  84. package/dist/tsup/utils.cjs +2 -2
  85. package/dist/tsup/utils.js +1 -1
  86. package/dist/tsup/workflow/mod.cjs +17 -17
  87. package/dist/tsup/workflow/mod.d.cts +4 -4
  88. package/dist/tsup/workflow/mod.d.ts +4 -4
  89. package/dist/tsup/workflow/mod.js +5 -5
  90. package/package.json +9 -13
  91. package/src/actor/keys.ts +86 -0
  92. package/src/agent-os/index.ts +5 -65
  93. package/src/client/actor-conn.ts +92 -6
  94. package/src/client/actor-handle.ts +24 -4
  95. package/src/client/client.ts +14 -4
  96. package/src/client/config.ts +12 -1
  97. package/src/client/lifecycle-errors.ts +16 -1
  98. package/src/client/retry-budget.ts +78 -0
  99. package/src/client/utils.ts +13 -2
  100. package/src/common/database/config.ts +7 -1
  101. package/src/common/database/native-database.ts +17 -9
  102. package/src/common/router.ts +1 -1
  103. package/src/engine-api/actors.ts +3 -3
  104. package/src/engine-client/actor-websocket-client.ts +4 -2
  105. package/src/engine-client/api-endpoints.ts +44 -14
  106. package/src/engine-client/mod.ts +2 -2
  107. package/src/registry/config/envoy.ts +1 -1
  108. package/src/registry/config/index.ts +28 -31
  109. package/src/registry/index.ts +51 -19
  110. package/src/registry/napi-runtime.ts +3 -2
  111. package/src/registry/native.ts +129 -40
  112. package/src/registry/runtime.ts +27 -10
  113. package/src/registry/wasm-runtime.ts +6 -3
  114. package/src/utils/env-vars.ts +15 -10
  115. package/dist/tsup/chunk-2LRKNNQJ.cjs.map +0 -1
  116. package/dist/tsup/chunk-6BRDJRCZ.cjs.map +0 -1
  117. package/dist/tsup/chunk-JI6GZ2C2.js.map +0 -1
  118. package/dist/tsup/chunk-M27XAZNI.js.map +0 -1
  119. package/dist/tsup/chunk-MYWZCDML.cjs.map +0 -1
  120. package/dist/tsup/chunk-Z6IVW2Y5.js.map +0 -1
  121. package/src/actor/config.test.ts +0 -78
  122. package/src/actor/keys.test.ts +0 -275
  123. package/src/actor/utils.test.ts +0 -48
  124. package/src/agent-os/actor/cron.ts +0 -84
  125. package/src/agent-os/actor/db.ts +0 -54
  126. package/src/agent-os/actor/filesystem.ts +0 -131
  127. package/src/agent-os/actor/index.ts +0 -285
  128. package/src/agent-os/actor/network.ts +0 -58
  129. package/src/agent-os/actor/preview.ts +0 -190
  130. package/src/agent-os/actor/process.ts +0 -177
  131. package/src/agent-os/actor/session.ts +0 -518
  132. package/src/agent-os/actor/shell.ts +0 -60
  133. package/src/agent-os/config.ts +0 -79
  134. package/src/agent-os/fs/database-vfs.ts +0 -624
  135. package/src/agent-os/types.ts +0 -148
  136. package/src/client/test.ts +0 -44
  137. package/src/client/token-provider.test.ts +0 -86
  138. package/src/common/database/mod.test.ts +0 -364
  139. package/src/common/database/native-database.test.ts +0 -241
  140. package/src/common/inline-websocket-adapter.test.ts +0 -51
  141. package/src/db/drizzle.test.ts +0 -164
  142. package/src/registry/config/index.test.ts +0 -25
  143. package/src/registry/run-handler-coordinator.test.ts +0 -252
  144. package/src/registry/runtime.test.ts +0 -124
  145. package/src/unstable/migrations.test.ts +0 -170
  146. package/src/utils/endpoint-parser.test.ts +0 -206
  147. package/src/utils.test.ts +0 -34
  148. package/src/workflow/driver.test.ts +0 -62
  149. /package/dist/tsup/{chunk-6VNQCLKF.js.map → chunk-5X35FD2T.js.map} +0 -0
  150. /package/dist/tsup/{chunk-BJGWUWNE.js.map → chunk-6QNBANXM.js.map} +0 -0
  151. /package/dist/tsup/{chunk-EDJKDOI2.js.map → chunk-DUGEPEJO.js.map} +0 -0
  152. /package/dist/tsup/{chunk-UZ5O42HF.js.map → chunk-GHTA76HT.js.map} +0 -0
  153. /package/dist/tsup/{chunk-IAVZH6HH.js.map → chunk-ID5VJNZY.js.map} +0 -0
  154. /package/dist/tsup/{chunk-HHALUH4L.js.map → chunk-VI2S336K.js.map} +0 -0
package/dist/tsup/mod.cjs CHANGED
@@ -1,6 +1,6 @@
1
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 _chunk6ZHUGY2Ecjs = require('./chunk-6ZHUGY2E.cjs');
3
+ var _chunk3JPXBFEDcjs = require('./chunk-3JPXBFED.cjs');
4
4
 
5
5
 
6
6
 
@@ -35,18 +35,18 @@ var _chunkHDVZ6YZGcjs = require('./chunk-HDVZ6YZG.cjs');
35
35
 
36
36
 
37
37
 
38
- var _chunk2LRKNNQJcjs = require('./chunk-2LRKNNQJ.cjs');
38
+ var _chunkPXIOH445cjs = require('./chunk-PXIOH445.cjs');
39
39
 
40
40
 
41
41
 
42
- var _chunkMYWZCDMLcjs = require('./chunk-MYWZCDML.cjs');
42
+ var _chunkRTWH3AX3cjs = require('./chunk-RTWH3AX3.cjs');
43
+ require('./chunk-UV4KDO4W.cjs');
43
44
 
44
45
 
45
46
 
46
47
 
47
- var _chunkPMU5EDGTcjs = require('./chunk-PMU5EDGT.cjs');
48
+ var _chunkEA6P3N4Icjs = require('./chunk-EA6P3N4I.cjs');
48
49
  require('./chunk-KVFIONKQ.cjs');
49
- require('./chunk-5LBUG2IK.cjs');
50
50
 
51
51
 
52
52
 
@@ -80,7 +80,8 @@ require('./chunk-5LBUG2IK.cjs');
80
80
 
81
81
 
82
82
 
83
- var _chunk6BRDJRCZcjs = require('./chunk-6BRDJRCZ.cjs');
83
+ var _chunkW7NPIYWCcjs = require('./chunk-W7NPIYWC.cjs');
84
+
84
85
 
85
86
 
86
87
 
@@ -97,7 +98,7 @@ var _chunkMGI2VVF6cjs = require('./chunk-MGI2VVF6.cjs');
97
98
 
98
99
  // src/actor/log.ts
99
100
  function loggerWithoutContext() {
100
- return _chunk6BRDJRCZcjs.getLogger.call(void 0, "actor-runtime");
101
+ return _chunkW7NPIYWCcjs.getLogger.call(void 0, "actor-runtime");
101
102
  }
102
103
 
103
104
  // src/actor/definition.ts
@@ -239,7 +240,7 @@ function validateSchemaSync(schemas, key, data) {
239
240
  var _virtualwebsocket = require('@rivetkit/virtual-websocket');
240
241
  var _ws = require('hono/ws');
241
242
  function logger() {
242
- return _chunk6BRDJRCZcjs.getLogger.call(void 0, "inline-websocket-adapter");
243
+ return _chunkW7NPIYWCcjs.getLogger.call(void 0, "inline-websocket-adapter");
243
244
  }
244
245
  var InlineWebSocketAdapter = class {
245
246
  #handler;
@@ -391,7 +392,7 @@ var InlineWebSocketAdapter = class {
391
392
 
392
393
  // src/registry/log.ts
393
394
  function logger2() {
394
- return _chunk6BRDJRCZcjs.getLogger.call(void 0, "registry");
395
+ return _chunkW7NPIYWCcjs.getLogger.call(void 0, "registry");
395
396
  }
396
397
 
397
398
  // src/serverless/configure.ts
@@ -437,8 +438,8 @@ async function configureServerlessPool(config) {
437
438
  );
438
439
  }
439
440
  const customConfig = config.configurePool;
440
- const clientConfig = _chunk2LRKNNQJcjs.convertRegistryConfigToClientConfig.call(void 0, config);
441
- const dcsRes = await _chunk2LRKNNQJcjs.getDatacenters.call(void 0, clientConfig);
441
+ const clientConfig = _chunkPXIOH445cjs.convertRegistryConfigToClientConfig.call(void 0, config);
442
+ const dcsRes = await _chunkPXIOH445cjs.getDatacenters.call(void 0, clientConfig);
442
443
  const poolName = _nullishCoalesce(customConfig.name, () => ( "default"));
443
444
  const serverlessToken = _nullishCoalesce(config.token, () => ( config.publicToken));
444
445
  const headers = {
@@ -460,7 +461,7 @@ async function configureServerlessPool(config) {
460
461
  metadata: _nullishCoalesce(customConfig.metadata, () => ( {})),
461
462
  drain_on_version_upgrade: _nullishCoalesce(customConfig.drainOnVersionUpgrade, () => ( true))
462
463
  };
463
- await _chunk2LRKNNQJcjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
464
+ await _chunkPXIOH445cjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
464
465
  datacenters: Object.fromEntries(
465
466
  dcsRes.datacenters.map((dc) => [dc.name, serverlessConfig])
466
467
  )
@@ -477,7 +478,7 @@ async function configureServerlessPool(config) {
477
478
  logger2().warn({
478
479
  msg: "serverless pool configuration attempt failed",
479
480
  attempts,
480
- error: _chunk6BRDJRCZcjs.stringifyError.call(void 0, error)
481
+ error: _chunkW7NPIYWCcjs.stringifyError.call(void 0, error)
481
482
  });
482
483
  await sleep(CONFIGURE_RETRY_DELAY_MS);
483
484
  }
@@ -485,7 +486,7 @@ async function configureServerlessPool(config) {
485
486
  logger2().error({
486
487
  msg: "failed to configure serverless pool, validate endpoint is configured correctly then restart this process",
487
488
  attempts,
488
- error: _chunk6BRDJRCZcjs.stringifyError.call(void 0, lastError)
489
+ error: _chunkW7NPIYWCcjs.stringifyError.call(void 0, lastError)
489
490
  });
490
491
  throw lastError;
491
492
  }
@@ -496,11 +497,11 @@ var _zod = require('zod');
496
497
  // src/registry/config/envoy.ts
497
498
  var _v4 = require('zod/v4');
498
499
  var EnvoyConfigSchema = _v4.z.object({
499
- poolName: _v4.z.string().default(() => _nullishCoalesce(_chunk6BRDJRCZcjs.getRivetPool.call(void 0, ), () => ( "default"))),
500
- version: _v4.z.number().default(() => _nullishCoalesce(_chunk6BRDJRCZcjs.getRivetEnvoyVersion.call(void 0, ), () => ( 1))),
500
+ poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkW7NPIYWCcjs.getRivetPool.call(void 0, ), () => ( "default"))),
501
+ version: _v4.z.number().default(() => _nullishCoalesce(_chunkW7NPIYWCcjs.getRivetEnvoyVersion.call(void 0, ), () => ( 1))),
501
502
  // Deprecated.
502
- totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunk6BRDJRCZcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
503
- envoyKey: _v4.z.string().optional()
503
+ totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkW7NPIYWCcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
504
+ nodeKey: _v4.z.string().optional()
504
505
  });
505
506
 
506
507
  // src/registry/config/serverless.ts
@@ -537,7 +538,7 @@ var ServerlessConfigSchema = _v4.z.object({
537
538
  *
538
539
  * Can also be set via RIVET_PUBLIC_ENDPOINT environment variable.
539
540
  */
540
- publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk6BRDJRCZcjs.getRivetPublicEndpoint.call(void 0, )))),
541
+ publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkW7NPIYWCcjs.getRivetPublicEndpoint.call(void 0, )))),
541
542
  /**
542
543
  * Token that clients should use when connecting via the public endpoint.
543
544
  *
@@ -545,7 +546,7 @@ var ServerlessConfigSchema = _v4.z.object({
545
546
  *
546
547
  * Can also be specified in the publicEndpoint URL as `https://namespace:token@host`.
547
548
  */
548
- publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk6BRDJRCZcjs.getRivetPublicToken.call(void 0, ))))
549
+ publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkW7NPIYWCcjs.getRivetPublicToken.call(void 0, ))))
549
550
  // There is no publicNamespace config option because the frontend and backend
550
551
  // cannot use different namespaces. The namespace is extracted from the
551
552
  // publicEndpoint URL auth syntax if provided.
@@ -599,7 +600,7 @@ var RegistryConfigSchema = _zod.z.object({
599
600
  * Runtime binding to use for RivetKit core.
600
601
  * */
601
602
  runtime: RuntimeKindSchema.optional().transform((val, ctx) => {
602
- const rawRuntime = _nullishCoalesce(val, () => ( _chunk6BRDJRCZcjs.getRivetkitRuntime.call(void 0, )));
603
+ const rawRuntime = _nullishCoalesce(val, () => ( _chunkW7NPIYWCcjs.getRivetkitRuntime.call(void 0, )));
603
604
  if (rawRuntime === void 0) {
604
605
  return "auto";
605
606
  }
@@ -636,7 +637,7 @@ var RegistryConfigSchema = _zod.z.object({
636
637
  * */
637
638
  logging: _zod.z.object({
638
639
  baseLogger: _zod.z.custom().optional(),
639
- level: _chunk6BRDJRCZcjs.LogLevelSchema.optional()
640
+ level: _chunkW7NPIYWCcjs.LogLevelSchema.optional()
640
641
  }).optional().default(() => ({})),
641
642
  // MARK: Routing
642
643
  // // This is a function to allow for lazy configuration of upgradeWebSocket on the
@@ -644,7 +645,7 @@ var RegistryConfigSchema = _zod.z.object({
644
645
  // // (specifically Node.js) can sometimes only be specified after the router is
645
646
  // // created or must be imported async using `await import(...)`
646
647
  // getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
647
- // MARK: Runner Configuration
648
+ // MARK: Node Configuration
648
649
  /**
649
650
  * Endpoint to connect to for Rivet Engine.
650
651
  *
@@ -654,9 +655,9 @@ var RegistryConfigSchema = _zod.z.object({
654
655
  *
655
656
  * Can also be set via RIVET_ENDPOINT environment variables.
656
657
  */
657
- endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunk6BRDJRCZcjs.getRivetEngine.call(void 0, ))), () => ( _chunk6BRDJRCZcjs.getRivetEndpoint.call(void 0, )))),
658
- token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk6BRDJRCZcjs.getRivetToken.call(void 0, )))),
659
- namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk6BRDJRCZcjs.getRivetNamespace.call(void 0, )))),
658
+ endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkW7NPIYWCcjs.getRivetEngine.call(void 0, ))), () => ( _chunkW7NPIYWCcjs.getRivetEndpoint.call(void 0, )))),
659
+ token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkW7NPIYWCcjs.getRivetToken.call(void 0, )))),
660
+ namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkW7NPIYWCcjs.getRivetNamespace.call(void 0, )))),
660
661
  headers: _zod.z.record(_zod.z.string(), _zod.z.string()).optional().default({}),
661
662
  // MARK: Client
662
663
  // TODO:
@@ -696,47 +697,47 @@ var RegistryConfigSchema = _zod.z.object({
696
697
  *
697
698
  * Starts the full Rust engine process locally.
698
699
  */
699
- startEngine: _zod.z.boolean().default(() => _chunk6BRDJRCZcjs.getRivetRunEngine.call(void 0, )),
700
+ startEngine: _zod.z.boolean().default(() => _chunkW7NPIYWCcjs.getRivetRunEngine.call(void 0, )),
700
701
  /**
701
702
  * @experimental
702
703
  *
703
704
  * Host to bind the spawned local engine process to.
704
705
  */
705
- engineHost: _zod.z.string().optional().default(() => _nullishCoalesce(_chunk6BRDJRCZcjs.getRivetRunEngineHost.call(void 0, ), () => ( _chunk2LRKNNQJcjs.ENGINE_HOST))),
706
+ engineHost: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkW7NPIYWCcjs.getRivetRunEngineHost.call(void 0, ), () => ( _chunkPXIOH445cjs.ENGINE_HOST))),
706
707
  /**
707
708
  * @experimental
708
709
  *
709
710
  * Port to bind the spawned local engine process to.
710
711
  */
711
- enginePort: _zod.z.number().int().min(1).max(65535).optional().default(() => _nullishCoalesce(_chunk6BRDJRCZcjs.getRivetRunEnginePort.call(void 0, ), () => ( _chunk2LRKNNQJcjs.ENGINE_PORT))),
712
+ enginePort: _zod.z.number().int().min(1).max(65535).optional().default(() => _nullishCoalesce(_chunkW7NPIYWCcjs.getRivetRunEnginePort.call(void 0, ), () => ( _chunkPXIOH445cjs.ENGINE_PORT))),
712
713
  /** @experimental */
713
- engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunk6BRDJRCZcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunk6BRDJRCZcjs.VERSION))),
714
+ engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkW7NPIYWCcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkW7NPIYWCcjs.VERSION))),
714
715
  /**
715
716
  * Starts the first-party Services actor host when RivetKit manages
716
- * a local engine. Defaults to the local-engine decision. Set
717
- * RIVET_RUN_SERVICES=0 or 1 to override it.
717
+ * a local engine. Disabled by default. Set RIVET_RUN_SERVICES=1
718
+ * or startServices: true to enable it.
718
719
  */
719
720
  startServices: _zod.z.boolean().optional(),
720
721
  /**
721
722
  * @experimental
722
723
  *
723
- * Automatically configure serverless envoys in the engine.
724
+ * Automatically configure serverless nodes in the engine.
724
725
  */
725
726
  configurePool: ConfigurePoolSchema.optional(),
726
727
  // MARK: Runtime-specific
727
728
  serverless: ServerlessConfigSchema.optional().default(
728
729
  () => ServerlessConfigSchema.parse({})
729
730
  ),
730
- envoy: EnvoyConfigSchema.optional().default(
731
+ node: EnvoyConfigSchema.optional().default(
731
732
  () => EnvoyConfigSchema.parse({})
732
733
  ),
733
734
  // MARK: Shutdown
734
735
  /**
735
736
  * Graceful shutdown configuration for SIGINT/SIGTERM.
736
737
  *
737
- * When a persistent envoy is running (Mode A, started via `registry.start()`),
738
+ * When a persistent node is running (Mode A, started via `registry.start()`),
738
739
  * rivetkit installs Node SIGINT/SIGTERM handlers that call into core's
739
- * `shutdown()` and wait up to `gracePeriodMs` for the envoy to drain
740
+ * `shutdown()` and wait up to `gracePeriodMs` for the node to drain
740
741
  * before re-raising the signal to let Node exit via its default path.
741
742
  *
742
743
  * Handlers are NOT installed when `handler(request)` is used alone
@@ -748,9 +749,11 @@ var RegistryConfigSchema = _zod.z.object({
748
749
  /**
749
750
  * Wait this many milliseconds for the serve promise to resolve
750
751
  * after calling `CoreRegistry::shutdown()`. Defaults to the
751
- * engine-provided actor stop threshold once the envoy connects.
752
+ * engine-provided actor stop threshold once the node connects. A
753
+ * signal-driven shutdown of a managed local development engine waits
754
+ * one second by default so a file watcher can restart promptly.
752
755
  *
753
- * Must be long enough for rivetkit-core to drain the envoy.
756
+ * Set a longer period when a complete graceful node drain is required.
754
757
  */
755
758
  gracePeriodMs: _zod.z.number().int().min(1e3).optional(),
756
759
  /**
@@ -764,7 +767,7 @@ var RegistryConfigSchema = _zod.z.object({
764
767
  }))
765
768
  }).transform((config, ctx) => {
766
769
  var _a, _b, _c;
767
- const isDevEnv = _chunk6BRDJRCZcjs.isDev.call(void 0, );
770
+ const isDevEnv = _chunkW7NPIYWCcjs.isDev.call(void 0, );
768
771
  const sqliteBackend = _nullishCoalesce(((_a = config.sqlite) == null ? void 0 : _a.backend), () => ( ((_b = config.test) == null ? void 0 : _b.sqliteBackend)));
769
772
  if (config.runtime === "wasm" && sqliteBackend === "local") {
770
773
  ctx.addIssue({
@@ -774,7 +777,7 @@ var RegistryConfigSchema = _zod.z.object({
774
777
  });
775
778
  }
776
779
  const sqlite = config.runtime === "wasm" && config.sqlite === void 0 ? { backend: "remote" } : config.sqlite;
777
- const parsedEndpoint = config.endpoint ? _chunk2LRKNNQJcjs.tryParseEndpoint.call(void 0, ctx, {
780
+ const parsedEndpoint = config.endpoint ? _chunkPXIOH445cjs.tryParseEndpoint.call(void 0, ctx, {
778
781
  endpoint: config.endpoint,
779
782
  path: ["endpoint"],
780
783
  namespace: config.namespace,
@@ -786,24 +789,25 @@ var RegistryConfigSchema = _zod.z.object({
786
789
  message: "cannot specify both startEngine and endpoint"
787
790
  });
788
791
  }
789
- if (config.configurePool && !parsedEndpoint && !config.startEngine) {
792
+ if (config.configurePool) {
790
793
  ctx.addIssue({
791
794
  code: "custom",
792
- message: "configurePool requires either endpoint or startEngine"
795
+ message: "serverless is disabled in this version",
796
+ path: ["configurePool"]
793
797
  });
794
798
  }
795
- const localEngineEndpoint = _chunk2LRKNNQJcjs.buildEngineEndpoint.call(void 0,
799
+ const localEngineEndpoint = _chunkPXIOH445cjs.buildEngineEndpoint.call(void 0,
796
800
  config.engineHost,
797
801
  config.enginePort
798
802
  );
799
803
  const endpoint = config.startEngine ? localEngineEndpoint : _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint), () => ( (isDevEnv ? localEngineEndpoint : void 0)));
800
- const startServices = _nullishCoalesce(_nullishCoalesce(config.startServices, () => ( _chunk6BRDJRCZcjs.getRivetRunServices.call(void 0, ))), () => ( Boolean(endpoint && _chunk2LRKNNQJcjs.isLocalEngineEndpoint.call(void 0, endpoint))));
804
+ const startServices = _nullishCoalesce(config.startServices, () => ( _chunkW7NPIYWCcjs.getRivetRunServices.call(void 0, )));
801
805
  const validateServerlessEndpoint = Boolean(
802
806
  config.startEngine || parsedEndpoint
803
807
  );
804
808
  const namespace = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.namespace), () => ( config.namespace)), () => ( "default"));
805
- const token = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.token), () => ( config.token)), () => ( (endpoint && _chunk2LRKNNQJcjs.isLocalEngineEndpoint.call(void 0, endpoint) ? "default" : void 0)));
806
- const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunk2LRKNNQJcjs.tryParseEndpoint.call(void 0, ctx, {
809
+ const token = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.token), () => ( config.token)), () => ( (endpoint && _chunkPXIOH445cjs.isLocalEngineEndpoint.call(void 0, endpoint) ? "default" : void 0)));
810
+ const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkPXIOH445cjs.tryParseEndpoint.call(void 0, ctx, {
807
811
  endpoint: config.serverless.publicEndpoint,
808
812
  path: ["serverless", "publicEndpoint"]
809
813
  }) : void 0;
@@ -821,6 +825,7 @@ var RegistryConfigSchema = _zod.z.object({
821
825
  ...config,
822
826
  sqlite,
823
827
  endpoint,
828
+ engineSpawn: !parsedEndpoint && Boolean(endpoint),
824
829
  startServices,
825
830
  namespace,
826
831
  token,
@@ -850,8 +855,8 @@ function buildActorNames(config) {
850
855
  );
851
856
  }
852
857
  var DocConfigurePoolSchema = _zod.z.object({
853
- name: _zod.z.string().optional().describe("Name of the runner pool."),
854
- url: _zod.z.string().describe("URL of the serverless platform to configure runners."),
858
+ name: _zod.z.string().optional().describe("Name of the node pool."),
859
+ url: _zod.z.string().describe("URL of the serverless platform to configure nodes."),
855
860
  headers: _zod.z.record(_zod.z.string(), _zod.z.string()).optional().describe(
856
861
  "Headers to include in requests to the serverless platform."
857
862
  ),
@@ -866,7 +871,7 @@ var DocConfigurePoolSchema = _zod.z.object({
866
871
  "Interval in milliseconds between metadata polls from the engine. Defaults to 10000 milliseconds (10 seconds)."
867
872
  ),
868
873
  drainOnVersionUpgrade: _zod.z.boolean().optional().describe(
869
- "Drain runners when a new version is deployed. Defaults to true."
874
+ "Drain nodes when a new version is deployed. Defaults to true."
870
875
  )
871
876
  }).optional();
872
877
  var DocServerlessConfigSchema = _zod.z.object({
@@ -885,10 +890,10 @@ var DocServerlessConfigSchema = _zod.z.object({
885
890
  }).describe("Configuration for serverless deployment mode.");
886
891
  var DocEnvoyConfigSchema = _zod.z.object({
887
892
  totalSlots: _zod.z.number().optional().describe("Total number of actor slots available. Default: 100000"),
888
- poolName: _zod.z.string().optional().describe("Name of this envoy pool. Default: 'default'"),
889
- envoyKey: _zod.z.string().optional().describe("Deprecated. Authentication key for the envoy."),
890
- version: _zod.z.number().optional().describe("Version number of this envoy. Default: 1")
891
- }).describe("Configuration for envoy mode.");
893
+ poolName: _zod.z.string().optional().describe("Name of this node pool. Default: 'default'"),
894
+ nodeKey: _zod.z.string().optional().describe("Deprecated. Authentication key for the node."),
895
+ version: _zod.z.number().optional().describe("Version number of this node. Default: 1")
896
+ }).describe("Configuration for node mode.");
892
897
  var DocSqliteConfigSchema = _zod.z.object({
893
898
  backend: SqliteBackendSchema.optional().describe(
894
899
  "SQLite backend to use. Native defaults to local. Wasm defaults to remote and cannot use local."
@@ -907,7 +912,7 @@ var DocRegistryConfigSchema = _zod.z.object({
907
912
  noWelcome: _zod.z.boolean().optional().describe("Disable the welcome message on startup. Default: false"),
908
913
  sqlite: DocSqliteConfigSchema,
909
914
  logging: _zod.z.object({
910
- level: _chunk6BRDJRCZcjs.LogLevelSchema.optional().describe(
915
+ level: _chunkW7NPIYWCcjs.LogLevelSchema.optional().describe(
911
916
  "Log level for RivetKit. Default: 'warn'"
912
917
  )
913
918
  }).optional().describe("Logging configuration."),
@@ -936,13 +941,13 @@ var DocRegistryConfigSchema = _zod.z.object({
936
941
  "Version of the local engine package to use. Defaults to the current RivetKit version."
937
942
  ),
938
943
  startServices: _zod.z.boolean().optional().describe(
939
- "Starts Services when RivetKit manages a local Engine. Defaults to the local-Engine decision. Set RIVET_RUN_SERVICES=0 or 1 to override."
944
+ "Starts Services when RivetKit manages a local Engine. Disabled by default. Set RIVET_RUN_SERVICES=1 or startServices: true to enable."
940
945
  ),
941
946
  configurePool: DocConfigurePoolSchema.describe(
942
- "Automatically configure serverless runners in the engine."
947
+ "Automatically configure serverless nodes in the engine."
943
948
  ),
944
949
  serverless: DocServerlessConfigSchema.optional(),
945
- envoy: DocEnvoyConfigSchema.optional()
950
+ node: DocEnvoyConfigSchema.optional()
946
951
  }).describe("RivetKit registry configuration.");
947
952
 
948
953
  // src/registry/native.ts
@@ -1113,12 +1118,12 @@ var NativeCloseGate = class {
1113
1118
  if (this.#active > 0) {
1114
1119
  await new Promise((resolve) => this.#waiters.push(resolve));
1115
1120
  }
1116
- await callback();
1121
+ await (callback == null ? void 0 : callback());
1117
1122
  }
1118
1123
  };
1119
- function wrapJsNativeDatabase(database, { ownsDatabase = true } = {}) {
1124
+ function wrapJsNativeDatabase(database) {
1120
1125
  const gate = new NativeCloseGate();
1121
- let closePromise;
1126
+ let terminalPromise;
1122
1127
  let lastInsertRowId = null;
1123
1128
  const executeNative = async (sql, params) => {
1124
1129
  const release = gate.enter();
@@ -1331,10 +1336,12 @@ function wrapJsNativeDatabase(database, { ownsDatabase = true } = {}) {
1331
1336
  database.abortGeneration(reason);
1332
1337
  },
1333
1338
  async close() {
1334
- closePromise ??= gate.close(async () => {
1335
- if (ownsDatabase) await database.close();
1336
- });
1337
- await closePromise;
1339
+ terminalPromise ??= gate.close(() => database.close());
1340
+ await terminalPromise;
1341
+ },
1342
+ async detachForShutdown() {
1343
+ terminalPromise ??= gate.close();
1344
+ await terminalPromise;
1338
1345
  }
1339
1346
  };
1340
1347
  }
@@ -1535,6 +1542,12 @@ function getNodePath() {
1535
1542
  function normalizeRuntimeSqlExecuteResult(result) {
1536
1543
  return result;
1537
1544
  }
1545
+ function servicesBinaryUnavailable(cause) {
1546
+ return new Error(
1547
+ "services.binary_unavailable: Install @rivet-dev/services yourself to run local Services, or set RIVET_SERVICES_BINARY to its executable path.",
1548
+ { cause }
1549
+ );
1550
+ }
1538
1551
 
1539
1552
  // src/registry/napi-runtime.ts
1540
1553
  function asNativeRegistry(handle) {
@@ -1680,7 +1693,7 @@ var NapiCoreRuntime = (_class = class {
1680
1693
  if (!(active == null ? void 0 : active.sameActorInstance(ownerCtx))) {
1681
1694
  return ownerCtx;
1682
1695
  }
1683
- const applicationSpan = _chunk2LRKNNQJcjs.readActiveTraceHeaders.call(void 0, );
1696
+ const applicationSpan = _chunkPXIOH445cjs.readActiveTraceHeaders.call(void 0, );
1684
1697
  if (!applicationSpan) {
1685
1698
  return active;
1686
1699
  }
@@ -1807,7 +1820,8 @@ var NapiCoreRuntime = (_class = class {
1807
1820
  asNativeCancellationToken(token).cancel();
1808
1821
  }
1809
1822
  onCancellationTokenCancelled(token, callback) {
1810
- asNativeCancellationToken(token).onCancelled(callback);
1823
+ const listener = asNativeCancellationToken(token).onCancelled(callback);
1824
+ return () => listener.release();
1811
1825
  }
1812
1826
  actorState(ctx) {
1813
1827
  return asNativeActorContext(ctx).state();
@@ -1883,7 +1897,7 @@ var NapiCoreRuntime = (_class = class {
1883
1897
  const span = (_a = nativeCtx.invocationTraceContext()) == null ? void 0 : _a.span;
1884
1898
  return this.#invocationContext.run(
1885
1899
  nativeCtx,
1886
- () => _chunk2LRKNNQJcjs.runWithActorInvocationSpan.call(void 0, span, run)
1900
+ () => _chunkPXIOH445cjs.runWithActorInvocationSpan.call(void 0, span, run)
1887
1901
  );
1888
1902
  }
1889
1903
  actorInvocationTraceContext(ctx) {
@@ -2302,8 +2316,8 @@ function runtimeBytesToArrayBuffer(value) {
2302
2316
  function buildNativeHttpRequest(init) {
2303
2317
  var _a;
2304
2318
  const headers = new Headers(init.headers);
2305
- const originalUrl = headers.get(_chunk2LRKNNQJcjs.HEADER_ORIGINAL_REQUEST_URL);
2306
- headers.delete(_chunk2LRKNNQJcjs.HEADER_ORIGINAL_REQUEST_URL);
2319
+ const originalUrl = headers.get(_chunkPXIOH445cjs.HEADER_ORIGINAL_REQUEST_URL);
2320
+ headers.delete(_chunkPXIOH445cjs.HEADER_ORIGINAL_REQUEST_URL);
2307
2321
  const url = _nullishCoalesce(originalUrl, () => ( (init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString())));
2308
2322
  const method2 = init.method.toUpperCase();
2309
2323
  const bodyForbidden = method2 === "GET" || method2 === "HEAD";
@@ -2382,7 +2396,7 @@ async function pumpResponseBody(reader, stream) {
2382
2396
  }
2383
2397
  } catch (error) {
2384
2398
  try {
2385
- await stream.error(_chunk6BRDJRCZcjs.stringifyError.call(void 0, error));
2399
+ await stream.error(_chunkW7NPIYWCcjs.stringifyError.call(void 0, error));
2386
2400
  } catch (streamError) {
2387
2401
  logger2().debug({
2388
2402
  msg: "failed to report native http response stream error",
@@ -2909,9 +2923,10 @@ var WasmCoreRuntime = (_class2 = class {
2909
2923
  callWasmSync(() => asWasmCancellationToken(token).cancel());
2910
2924
  }
2911
2925
  onCancellationTokenCancelled(token, callback) {
2912
- callWasmSync(
2926
+ const listener = callWasmSync(
2913
2927
  () => asWasmCancellationToken(token).onCancelled(callback)
2914
2928
  );
2929
+ return () => callWasmSync(() => listener.release());
2915
2930
  }
2916
2931
  actorState(ctx) {
2917
2932
  return toBytes(
@@ -3671,7 +3686,7 @@ async function loadAutoRuntime(config, loaders = defaultRuntimeLoaders) {
3671
3686
  nativeError = error;
3672
3687
  logger2().warn({
3673
3688
  msg: "native runtime failed to load; falling back to wasm",
3674
- error: _chunk6BRDJRCZcjs.stringifyError.call(void 0, error)
3689
+ error: _chunkW7NPIYWCcjs.stringifyError.call(void 0, error)
3675
3690
  });
3676
3691
  }
3677
3692
  try {
@@ -3680,7 +3695,7 @@ async function loadAutoRuntime(config, loaders = defaultRuntimeLoaders) {
3680
3695
  throw new (0, _chunkMGI2VVF6cjs.RivetError)(
3681
3696
  "config",
3682
3697
  "runtime_unavailable",
3683
- `RivetKit could not load a core runtime. Native runtime: ${_chunk6BRDJRCZcjs.stringifyError.call(void 0, nativeError)} Wasm runtime: ${_chunk6BRDJRCZcjs.stringifyError.call(void 0, wasmError)}`,
3698
+ `RivetKit could not load a core runtime. Native runtime: ${_chunkW7NPIYWCcjs.stringifyError.call(void 0, nativeError)} Wasm runtime: ${_chunkW7NPIYWCcjs.stringifyError.call(void 0, wasmError)}`,
3684
3699
  {
3685
3700
  public: true,
3686
3701
  statusCode: 500
@@ -3736,9 +3751,10 @@ function normalizeRuntimeConfig(config, runtime) {
3736
3751
  return normalizeRuntimeConfigForKind(config, loadedRuntimeKind(runtime));
3737
3752
  }
3738
3753
  function getNativeRuntimeState(runtime, ctx) {
3739
- const runtimeState = callNativeSync(
3740
- () => runtime.actorRuntimeState(ctx)
3741
- );
3754
+ const runtimeState = readNativeRuntimeStateBag(runtime, ctx);
3755
+ if (runtimeState.cleared) {
3756
+ throw _chunkMGI2VVF6cjs.actorStopping.call(void 0, callNativeSync(() => runtime.actorId(ctx)));
3757
+ }
3742
3758
  if (!runtimeState.destroyGate) {
3743
3759
  runtimeState.destroyGate = {};
3744
3760
  }
@@ -3751,6 +3767,14 @@ function getNativeRuntimeState(runtime, ctx) {
3751
3767
  }
3752
3768
  return runtimeState;
3753
3769
  }
3770
+ function readNativeRuntimeStateBag(runtime, ctx) {
3771
+ return callNativeSync(
3772
+ () => runtime.actorRuntimeState(ctx)
3773
+ );
3774
+ }
3775
+ function isNativeRuntimeStateCleared(runtime, ctx) {
3776
+ return readNativeRuntimeStateBag(runtime, ctx).cleared === true;
3777
+ }
3754
3778
  function getNativePersistState(runtime, ctx) {
3755
3779
  const persistState = getNativeRuntimeState(runtime, ctx).persistState;
3756
3780
  if (!persistState) {
@@ -3861,29 +3885,43 @@ function resolveNativeDestroy(runtime, ctx) {
3861
3885
  gate.destroyCompletion = void 0;
3862
3886
  }
3863
3887
  function clearNativeRuntimeState(runtime, ctx) {
3888
+ var _a;
3889
+ const pendingSaveHandle = (_a = readNativeRuntimeStateBag(runtime, ctx).persistState) == null ? void 0 : _a.pendingSaveHandle;
3890
+ if (pendingSaveHandle !== void 0) {
3891
+ clearImmediate(pendingSaveHandle);
3892
+ }
3864
3893
  callNativeSync(() => runtime.actorClearRuntimeState(ctx));
3894
+ readNativeRuntimeStateBag(runtime, ctx).cleared = true;
3865
3895
  }
3866
3896
  async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrained) {
3867
3897
  const drained = await runtime.actorWaitForTrackedShutdownWork(ctx);
3868
3898
  if (!drained) {
3869
- await closeNativeDatabaseClient(runtime, ctx);
3870
- await closeNativeSqlDatabase(runtime, ctx);
3899
+ await detachNativeDatabaseForShutdown(runtime, ctx);
3871
3900
  void runtime.actorWaitForTrackedShutdownWorkUnbounded(ctx).then(async () => {
3872
3901
  await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
3873
3902
  clearNativeRuntimeState(runtime, ctx);
3874
3903
  }).catch((error) => {
3875
3904
  logger2().warn({
3876
3905
  msg: "deferred native sleep cleanup failed",
3877
- error: _chunk6BRDJRCZcjs.stringifyError.call(void 0, error)
3906
+ error: _chunkW7NPIYWCcjs.stringifyError.call(void 0, error)
3878
3907
  });
3879
3908
  });
3880
3909
  return;
3881
3910
  }
3882
3911
  await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
3883
- await closeNativeDatabaseClient(runtime, ctx);
3884
- await closeNativeSqlDatabase(runtime, ctx);
3912
+ await detachNativeDatabaseForShutdown(runtime, ctx);
3885
3913
  clearNativeRuntimeState(runtime, ctx);
3886
3914
  }
3915
+ async function detachNativeDatabaseForShutdown(runtime, ctx) {
3916
+ var _a;
3917
+ const runtimeState = getNativeRuntimeState(runtime, ctx);
3918
+ await ((_a = runtimeState.sql) == null ? void 0 : _a.detachForShutdown());
3919
+ try {
3920
+ await closeNativeDatabaseClient(runtime, ctx);
3921
+ } finally {
3922
+ runtimeState.sql = void 0;
3923
+ }
3924
+ }
3887
3925
  function closeNativeSqlDatabase(runtime, ctx) {
3888
3926
  const runtimeState = getNativeRuntimeState(runtime, ctx);
3889
3927
  const database = runtimeState.sql;
@@ -3986,11 +4024,7 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
3986
4024
  abortGeneration: (reason) => runtime.actorSqlAbortGeneration(ctx, reason),
3987
4025
  close: () => runtime.actorSqlClose(ctx)
3988
4026
  };
3989
- const database = wrapJsNativeDatabase(bindings, {
3990
- // Core still needs its shared database for the final state save, and
3991
- // closes it after shutting down the Actor Runtime Socket.
3992
- ownsDatabase: false
3993
- });
4027
+ const database = wrapJsNativeDatabase(bindings);
3994
4028
  runtimeState.sql = database;
3995
4029
  return database;
3996
4030
  }
@@ -4059,10 +4093,10 @@ function decodeValue(value) {
4059
4093
  if (!value || value.length === 0) {
4060
4094
  return void 0;
4061
4095
  }
4062
- return _chunk6BRDJRCZcjs.decodeCborCompat.call(void 0, value);
4096
+ return _chunkW7NPIYWCcjs.decodeCborCompat.call(void 0, value);
4063
4097
  }
4064
4098
  function encodeValue(value) {
4065
- return _chunk6BRDJRCZcjs.encodeCborCompat.call(void 0, value);
4099
+ return _chunkW7NPIYWCcjs.encodeCborCompat.call(void 0, value);
4066
4100
  }
4067
4101
  function normalizeArgs(value) {
4068
4102
  return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
@@ -4098,7 +4132,7 @@ function isStructuredBridgeError(error) {
4098
4132
  return _chunkMGI2VVF6cjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
4099
4133
  }
4100
4134
  function encodeNativeCallbackError(error) {
4101
- const structuredError = isStructuredBridgeError(error) ? error : _chunk6BRDJRCZcjs.deconstructError.call(void 0, error, true);
4135
+ const structuredError = isStructuredBridgeError(error) ? error : _chunkW7NPIYWCcjs.deconstructError.call(void 0, error, true);
4102
4136
  const { encoded, droppedMetadataCause } = _chunkMGI2VVF6cjs.encodeBridgeRivetError.call(void 0, structuredError);
4103
4137
  if (droppedMetadataCause !== void 0) {
4104
4138
  logger2().warn(
@@ -4160,7 +4194,7 @@ function decodeWorkflowCbor(data) {
4160
4194
  return null;
4161
4195
  }
4162
4196
  try {
4163
- return _chunk6BRDJRCZcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
4197
+ return _chunkW7NPIYWCcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
4164
4198
  } catch (e3) {
4165
4199
  return null;
4166
4200
  }
@@ -4273,7 +4307,7 @@ function serializeWorkflowHistoryForJson(data) {
4273
4307
  if (data === null) {
4274
4308
  return null;
4275
4309
  }
4276
- const history = _chunk6ZHUGY2Ecjs.decodeWorkflowHistoryTransport.call(void 0, data);
4310
+ const history = _chunk3JPXBFEDcjs.decodeWorkflowHistoryTransport.call(void 0, data);
4277
4311
  return jsonSafe({
4278
4312
  nameRegistry: [...history.nameRegistry],
4279
4313
  entries: history.entries.map((entry) => ({
@@ -4419,7 +4453,7 @@ var NativeConnAdapter = class {
4419
4453
  },
4420
4454
  (newValue) => {
4421
4455
  assertCurrentState();
4422
- _chunk6BRDJRCZcjs.assertJsonCompatValue.call(void 0, newValue);
4456
+ _chunkW7NPIYWCcjs.assertJsonCompatValue.call(void 0, newValue);
4423
4457
  }
4424
4458
  );
4425
4459
  }
@@ -4427,7 +4461,7 @@ var NativeConnAdapter = class {
4427
4461
  var _a;
4428
4462
  (_a = this.#assertCanMutateState) == null ? void 0 : _a.call(this);
4429
4463
  const nextValue = unwrapWriteThroughProxy(value);
4430
- _chunk6BRDJRCZcjs.assertJsonCompatValue.call(void 0, nextValue);
4464
+ _chunkW7NPIYWCcjs.assertJsonCompatValue.call(void 0, nextValue);
4431
4465
  this.#writeState(nextValue, { writeNative: true });
4432
4466
  }
4433
4467
  initializeState(value) {
@@ -4624,7 +4658,7 @@ var NativeKvAdapter = class {
4624
4658
  const value = await callNative(
4625
4659
  () => this.#runtime.actorKvGet(
4626
4660
  this.#ctx,
4627
- _chunkMYWZCDMLcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
4661
+ _chunkRTWH3AX3cjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
4628
4662
  )
4629
4663
  );
4630
4664
  return value ? decodeNativeKvValue(new Uint8Array(value), options) : null;
@@ -4633,7 +4667,7 @@ var NativeKvAdapter = class {
4633
4667
  await callNative(
4634
4668
  () => this.#runtime.actorKvPut(
4635
4669
  this.#ctx,
4636
- _chunkMYWZCDMLcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key)),
4670
+ _chunkRTWH3AX3cjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key)),
4637
4671
  toRuntimeBytes(value)
4638
4672
  )
4639
4673
  );
@@ -4642,7 +4676,7 @@ var NativeKvAdapter = class {
4642
4676
  await callNative(
4643
4677
  () => this.#runtime.actorKvDelete(
4644
4678
  this.#ctx,
4645
- _chunkMYWZCDMLcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
4679
+ _chunkRTWH3AX3cjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(key))
4646
4680
  )
4647
4681
  );
4648
4682
  }
@@ -4650,8 +4684,8 @@ var NativeKvAdapter = class {
4650
4684
  await callNative(
4651
4685
  () => this.#runtime.actorKvDeleteRange(
4652
4686
  this.#ctx,
4653
- _chunkMYWZCDMLcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(start)),
4654
- _chunkMYWZCDMLcjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(end))
4687
+ _chunkRTWH3AX3cjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(start)),
4688
+ _chunkRTWH3AX3cjs.makePrefixedKey.call(void 0, encodeNativeKvUserKey(end))
4655
4689
  )
4656
4690
  );
4657
4691
  }
@@ -4664,7 +4698,7 @@ var NativeKvAdapter = class {
4664
4698
  const entries = await callNative(
4665
4699
  () => this.#runtime.actorKvListPrefix(
4666
4700
  this.#ctx,
4667
- _chunkMYWZCDMLcjs.makePrefixedKey.call(void 0,
4701
+ _chunkRTWH3AX3cjs.makePrefixedKey.call(void 0,
4668
4702
  encodeNativeKvUserKey(
4669
4703
  prefix,
4670
4704
  options == null ? void 0 : options.keyType
@@ -4678,7 +4712,7 @@ var NativeKvAdapter = class {
4678
4712
  );
4679
4713
  return entries.map((entry) => [
4680
4714
  decodeNativeKvKey(
4681
- _chunkMYWZCDMLcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
4715
+ _chunkRTWH3AX3cjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
4682
4716
  options == null ? void 0 : options.keyType
4683
4717
  ),
4684
4718
  decodeNativeKvValue(new Uint8Array(entry.value), options)
@@ -4697,13 +4731,13 @@ var NativeKvAdapter = class {
4697
4731
  const entries = await callNative(
4698
4732
  () => this.#runtime.actorKvListRange(
4699
4733
  this.#ctx,
4700
- _chunkMYWZCDMLcjs.makePrefixedKey.call(void 0,
4734
+ _chunkRTWH3AX3cjs.makePrefixedKey.call(void 0,
4701
4735
  encodeNativeKvUserKey(
4702
4736
  start,
4703
4737
  options == null ? void 0 : options.keyType
4704
4738
  )
4705
4739
  ),
4706
- _chunkMYWZCDMLcjs.makePrefixedKey.call(void 0,
4740
+ _chunkRTWH3AX3cjs.makePrefixedKey.call(void 0,
4707
4741
  encodeNativeKvUserKey(
4708
4742
  end,
4709
4743
  options == null ? void 0 : options.keyType
@@ -4717,7 +4751,7 @@ var NativeKvAdapter = class {
4717
4751
  );
4718
4752
  return entries.map((entry) => [
4719
4753
  decodeNativeKvKey(
4720
- _chunkMYWZCDMLcjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
4754
+ _chunkRTWH3AX3cjs.removePrefixFromKey.call(void 0, new Uint8Array(entry.key)),
4721
4755
  options == null ? void 0 : options.keyType
4722
4756
  ),
4723
4757
  decodeNativeKvValue(new Uint8Array(entry.value), options)
@@ -5506,7 +5540,7 @@ var ActorContextHandleAdapter = class {
5506
5540
  },
5507
5541
  (newValue) => {
5508
5542
  assertCurrentState();
5509
- _chunk6BRDJRCZcjs.assertJsonCompatValue.call(void 0, newValue);
5543
+ _chunkW7NPIYWCcjs.assertJsonCompatValue.call(void 0, newValue);
5510
5544
  }
5511
5545
  );
5512
5546
  }
@@ -5518,7 +5552,7 @@ var ActorContextHandleAdapter = class {
5518
5552
  }
5519
5553
  this.#assertCanMutateState();
5520
5554
  const nextValue = unwrapWriteThroughProxy(value);
5521
- _chunk6BRDJRCZcjs.assertJsonCompatValue.call(void 0, nextValue);
5555
+ _chunkW7NPIYWCcjs.assertJsonCompatValue.call(void 0, nextValue);
5522
5556
  this.#writeState(nextValue, { scheduleSave: true });
5523
5557
  }
5524
5558
  initializeState(value) {
@@ -5646,12 +5680,14 @@ var ActorContextHandleAdapter = class {
5646
5680
  }
5647
5681
  get abortSignal() {
5648
5682
  if (!this.#abortSignal) {
5649
- const actorSignal = this.#createActorAbortSignal();
5683
+ const actorAbort = this.#actorAbort();
5684
+ const actorSignal = actorAbort.signal;
5650
5685
  if (this.#dispatchCancelToken === void 0) {
5651
5686
  this.#abortSignal = actorSignal;
5652
5687
  } else {
5653
5688
  const controller = new AbortController();
5654
5689
  let cleanedUp = false;
5690
+ let releaseDispatchListener;
5655
5691
  const onActorAbort = () => {
5656
5692
  cleanup();
5657
5693
  controller.abort();
@@ -5661,7 +5697,9 @@ var ActorContextHandleAdapter = class {
5661
5697
  return;
5662
5698
  }
5663
5699
  cleanedUp = true;
5664
- actorSignal.removeEventListener("abort", onActorAbort);
5700
+ actorAbort.listeners.delete(onActorAbort);
5701
+ releaseDispatchListener == null ? void 0 : releaseDispatchListener();
5702
+ releaseDispatchListener = void 0;
5665
5703
  this.#abortSignalCleanup = void 0;
5666
5704
  };
5667
5705
  if (actorSignal.aborted || this.#runtime.cancellationTokenAborted(
@@ -5671,10 +5709,8 @@ var ActorContextHandleAdapter = class {
5671
5709
  } else {
5672
5710
  const dispatchCancelToken = this.#dispatchCancelToken;
5673
5711
  this.#abortSignalCleanup = cleanup;
5674
- actorSignal.addEventListener("abort", onActorAbort, {
5675
- once: true
5676
- });
5677
- callNativeSync(
5712
+ actorAbort.listeners.add(onActorAbort);
5713
+ releaseDispatchListener = callNativeSync(
5678
5714
  () => this.#runtime.onCancellationTokenCancelled(
5679
5715
  dispatchCancelToken,
5680
5716
  () => {
@@ -5730,7 +5766,7 @@ var ActorContextHandleAdapter = class {
5730
5766
  log: {
5731
5767
  debug: (obj) => logger2().debug(obj)
5732
5768
  },
5733
- nativeDatabaseProvider: _chunkPMU5EDGTcjs.registerNativeStateTransactionOpener.call(void 0,
5769
+ nativeDatabaseProvider: _chunkEA6P3N4Icjs.registerNativeStateTransactionOpener.call(void 0,
5734
5770
  {
5735
5771
  open: async (requestedActorId) => {
5736
5772
  void requestedActorId;
@@ -5755,7 +5791,7 @@ var ActorContextHandleAdapter = class {
5755
5791
  return this.#db;
5756
5792
  }
5757
5793
  #bindDatabaseClient(client) {
5758
- return _chunkPMU5EDGTcjs.bindNativeStateTransactionContext.call(void 0, client, {
5794
+ return _chunkEA6P3N4Icjs.bindNativeStateTransactionContext.call(void 0, client, {
5759
5795
  enter: async () => await this.#enterStateTransaction(),
5760
5796
  exit: (scope) => this.#exitStateTransaction(
5761
5797
  scope
@@ -5959,7 +5995,7 @@ var ActorContextHandleAdapter = class {
5959
5995
  const trackedPromise = Promise.resolve(promise).catch((error) => {
5960
5996
  logger2().warn({
5961
5997
  msg: "keepAwake promise rejected",
5962
- error: _chunk6BRDJRCZcjs.stringifyError.call(void 0, error)
5998
+ error: _chunkW7NPIYWCcjs.stringifyError.call(void 0, error)
5963
5999
  });
5964
6000
  }).then(() => null);
5965
6001
  try {
@@ -6052,22 +6088,42 @@ var ActorContextHandleAdapter = class {
6052
6088
  }
6053
6089
  async dispose() {
6054
6090
  var _a;
6055
- this.#flushStateChange();
6091
+ if (!isNativeRuntimeStateCleared(this.#runtime, this.#ctx)) {
6092
+ this.#flushStateChange();
6093
+ }
6056
6094
  (_a = this.#abortSignalCleanup) == null ? void 0 : _a.call(this);
6057
6095
  }
6058
- #createActorAbortSignal() {
6096
+ #actorAbort() {
6097
+ const runtimeState = readNativeRuntimeStateBag(
6098
+ this.#runtime,
6099
+ this.#ctx
6100
+ );
6101
+ const cached = runtimeState.actorAbort;
6102
+ if (cached && !cached.signal.aborted) {
6103
+ return cached;
6104
+ }
6059
6105
  const nativeSignal = callNativeSync(
6060
6106
  () => this.#runtime.actorAbortSignal(this.#ctx)
6061
6107
  );
6062
6108
  const controller = new AbortController();
6063
- if (nativeSignal.aborted) {
6109
+ const actorAbort = {
6110
+ signal: controller.signal,
6111
+ listeners: /* @__PURE__ */ new Set()
6112
+ };
6113
+ const abort = () => {
6064
6114
  controller.abort();
6115
+ for (const listener of actorAbort.listeners) {
6116
+ listener();
6117
+ }
6118
+ actorAbort.listeners.clear();
6119
+ };
6120
+ if (nativeSignal.aborted) {
6121
+ abort();
6065
6122
  } else {
6066
- nativeSignal.addEventListener("abort", () => controller.abort(), {
6067
- once: true
6068
- });
6123
+ nativeSignal.addEventListener("abort", abort, { once: true });
6069
6124
  }
6070
- return controller.signal;
6125
+ runtimeState.actorAbort = actorAbort;
6126
+ return actorAbort;
6071
6127
  }
6072
6128
  #readState() {
6073
6129
  const actorState = getNativePersistState(this.#runtime, this.#ctx);
@@ -6440,7 +6496,7 @@ function validateInspectorTabSource(tabId, resolved) {
6440
6496
  function buildNativeFactory(runtime, registryConfig, definition) {
6441
6497
  var _a;
6442
6498
  const config = definition.config;
6443
- const databaseProvider = _nullishCoalesce(config.db, () => ( _chunkPMU5EDGTcjs.db.call(void 0, )));
6499
+ const databaseProvider = _nullishCoalesce(config.db, () => ( _chunkEA6P3N4Icjs.db.call(void 0, )));
6444
6500
  const actionHandlers = _chunkHDVZ6YZGcjs.flattenActionHandlers.call(void 0, config.actions);
6445
6501
  const schemaConfig = {
6446
6502
  actionInputSchemas: _chunkHDVZ6YZGcjs.flattenActionInputSchemas.call(void 0,
@@ -6451,9 +6507,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6451
6507
  events: config.events,
6452
6508
  queues: config.queues
6453
6509
  };
6454
- const createClient = (ctx) => _chunk2LRKNNQJcjs.createClientWithDriver.call(void 0,
6455
- new (0, _chunk2LRKNNQJcjs.RemoteEngineControlClient)(
6456
- _chunk2LRKNNQJcjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
6510
+ const createClient = (ctx) => _chunkPXIOH445cjs.createClientWithDriver.call(void 0,
6511
+ new (0, _chunkPXIOH445cjs.RemoteEngineControlClient)(
6512
+ _chunkPXIOH445cjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
6457
6513
  ),
6458
6514
  {
6459
6515
  encoding: "bare",
@@ -6645,7 +6701,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6645
6701
  400
6646
6702
  );
6647
6703
  }
6648
- const cbor = _chunk6BRDJRCZcjs.encodeCborCompat.call(void 0,
6704
+ const cbor = _chunkW7NPIYWCcjs.encodeCborCompat.call(void 0,
6649
6705
  _nullishCoalesce(body.body, () => ( null))
6650
6706
  );
6651
6707
  const message = await runtime.actorQueueSend(ctx, name, cbor);
@@ -7032,7 +7088,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7032
7088
  }
7033
7089
  } finally {
7034
7090
  resolveNativeDestroy(runtime, ctx);
7035
- await actorCtx.closeDatabase();
7091
+ await detachNativeDatabaseForShutdown(runtime, ctx);
7036
7092
  clearNativeRuntimeState(runtime, ctx);
7037
7093
  await actorCtx.dispose();
7038
7094
  }
@@ -7242,7 +7298,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7242
7298
  ...request,
7243
7299
  abortController: requestAbortController
7244
7300
  });
7245
- const rawConnParams = handlerRequest.headers.get(_chunk2LRKNNQJcjs.HEADER_CONN_PARAMS);
7301
+ const rawConnParams = handlerRequest.headers.get(_chunkPXIOH445cjs.HEADER_CONN_PARAMS);
7246
7302
  let requestCtx;
7247
7303
  let conn;
7248
7304
  let removeRequestAbortListener;
@@ -7299,7 +7355,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7299
7355
  requestCtx,
7300
7356
  handlerRequest
7301
7357
  );
7302
- if (!_chunk2LRKNNQJcjs.isResponseLike.call(void 0, response)) {
7358
+ if (!_chunkPXIOH445cjs.isResponseLike.call(void 0, response)) {
7303
7359
  throw new Error(
7304
7360
  "onRequest handler must return a Response"
7305
7361
  );
@@ -7394,7 +7450,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7394
7450
  var _a2;
7395
7451
  const { ctx } = unwrapTsfnPayload(error, payload);
7396
7452
  const history = (_a2 = getNativeWorkflowInspector(ctx)) == null ? void 0 : _a2.getHistory();
7397
- return history == null ? void 0 : _chunk6BRDJRCZcjs.toUint8Array.call(void 0, history);
7453
+ return history == null ? void 0 : _chunkW7NPIYWCcjs.toUint8Array.call(void 0, history);
7398
7454
  }
7399
7455
  ) : void 0,
7400
7456
  replayWorkflow: _chunkHDVZ6YZGcjs.hasRunInspectorConfig.call(void 0, config.run) ? wrapNativeCallback(
@@ -7408,7 +7464,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7408
7464
  return void 0;
7409
7465
  }
7410
7466
  const history = await _asyncNullishCoalesce(await workflowInspector.replayFromStep(entryId), async () => ( null));
7411
- return history == null ? void 0 : _chunk6BRDJRCZcjs.toUint8Array.call(void 0, history);
7467
+ return history == null ? void 0 : _chunkW7NPIYWCcjs.toUint8Array.call(void 0, history);
7412
7468
  }
7413
7469
  ) : void 0,
7414
7470
  actions: Object.fromEntries(
@@ -7536,15 +7592,16 @@ async function buildServeConfig(config, resolveServicesBinary = true) {
7536
7592
  throw nativeEndpointNotConfiguredError();
7537
7593
  }
7538
7594
  const serveConfig = {
7539
- version: config.envoy.version,
7595
+ version: config.node.version,
7540
7596
  endpoint: config.endpoint,
7597
+ engineSpawn: config.engineSpawn,
7541
7598
  token: config.token,
7542
7599
  namespace: config.namespace,
7543
- poolName: config.envoy.poolName,
7600
+ poolName: config.node.poolName,
7544
7601
  startServices: resolveServicesBinary && config.startServices,
7545
7602
  handleInspectorHttpInRuntime: true,
7546
7603
  serverlessBasePath: config.serverless.basePath,
7547
- serverlessPackageVersion: _chunk6BRDJRCZcjs.VERSION,
7604
+ serverlessPackageVersion: _chunkW7NPIYWCcjs.VERSION,
7548
7605
  serverlessClientEndpoint: config.publicEndpoint,
7549
7606
  serverlessClientNamespace: config.publicNamespace,
7550
7607
  serverlessClientToken: config.publicToken,
@@ -7557,30 +7614,32 @@ async function buildServeConfig(config, resolveServicesBinary = true) {
7557
7614
  } catch (error) {
7558
7615
  logger2().warn({
7559
7616
  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",
7560
- error: _chunk6BRDJRCZcjs.stringifyError.call(void 0, error)
7617
+ error: _chunkW7NPIYWCcjs.stringifyError.call(void 0, error)
7561
7618
  });
7562
7619
  }
7563
7620
  if (resolveServicesBinary && config.startServices) {
7564
- try {
7565
- const { getServicesPath } = await loadServices();
7566
- serveConfig.servicesBinaryPath = getServicesPath();
7567
- } catch (error) {
7568
- logger2().warn({
7569
- msg: "could not resolve the Services binary; a local engine will fail with services.binary_unavailable \u2014 set RIVET_RUN_SERVICES=0 to disable Services or RIVET_SERVICES_BINARY to a local rivet-services binary",
7570
- error: _chunk6BRDJRCZcjs.stringifyError.call(void 0, error)
7571
- });
7621
+ const servicesBinary = _chunkW7NPIYWCcjs.getEnvUniversal.call(void 0, "RIVET_SERVICES_BINARY");
7622
+ if (servicesBinary) {
7623
+ serveConfig.servicesBinaryPath = servicesBinary;
7624
+ } else {
7625
+ try {
7626
+ const { getServicesPath } = await loadServices();
7627
+ serveConfig.servicesBinaryPath = getServicesPath();
7628
+ } catch (error) {
7629
+ throw servicesBinaryUnavailable(error);
7630
+ }
7572
7631
  }
7573
7632
  }
7574
7633
  serveConfig.engineHost = config.engineHost;
7575
7634
  serveConfig.enginePort = config.enginePort;
7576
7635
  if ((_a = config.test) == null ? void 0 : _a.enabled) {
7577
- serveConfig.inspectorTestToken = _nullishCoalesce(_chunk6BRDJRCZcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
7636
+ serveConfig.inspectorTestToken = _nullishCoalesce(_chunkW7NPIYWCcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
7578
7637
  }
7579
7638
  return serveConfig;
7580
7639
  }
7581
7640
  async function buildRegistryWithRuntime(config, runtime) {
7582
7641
  var _a;
7583
- if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunk6BRDJRCZcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
7642
+ if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkW7NPIYWCcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
7584
7643
  trySetProcessEnv("_RIVET_TEST_INSPECTOR_TOKEN", "token");
7585
7644
  }
7586
7645
  if (runtime.kind === "napi") {
@@ -7610,6 +7669,9 @@ async function buildConfiguredRegistry(config) {
7610
7669
 
7611
7670
  // src/registry/index.ts
7612
7671
  var REGISTRY_READY_TIMEOUT_MS = 3e4;
7672
+ function rejectServerless() {
7673
+ throw new Error("serverless is disabled in this version");
7674
+ }
7613
7675
  function signalExitCode(signal) {
7614
7676
  switch (signal) {
7615
7677
  case "SIGINT":
@@ -7647,7 +7709,7 @@ function createApplicationFetch(application, runtime) {
7647
7709
  signal: abortController.signal
7648
7710
  })
7649
7711
  );
7650
- if (!_chunk2LRKNNQJcjs.isResponseLike.call(void 0, response)) {
7712
+ if (!_chunkPXIOH445cjs.isResponseLike.call(void 0, response)) {
7651
7713
  throw new TypeError(
7652
7714
  "registry.listen() application fetch must return a Response"
7653
7715
  );
@@ -7697,7 +7759,7 @@ var Registry = class {
7697
7759
  var _a;
7698
7760
  this.#config = config;
7699
7761
  if ((_a = config.logging) == null ? void 0 : _a.baseLogger) {
7700
- _chunk6BRDJRCZcjs.configureBaseLogger.call(void 0, config.logging.baseLogger);
7762
+ _chunkW7NPIYWCcjs.configureBaseLogger.call(void 0, config.logging.baseLogger);
7701
7763
  }
7702
7764
  this.#buildConfiguredRegistry = _nullishCoalesce((deps == null ? void 0 : deps.buildConfiguredRegistry), () => ( buildConfiguredRegistry));
7703
7765
  this.routes = {
@@ -7714,6 +7776,7 @@ var Registry = class {
7714
7776
  */
7715
7777
  #ensureServerlessPoolConfigured(config) {
7716
7778
  if (!config.configurePool) return void 0;
7779
+ rejectServerless();
7717
7780
  if (!this.#configureServerlessPoolPromise) {
7718
7781
  this.#configureServerlessPoolPromise = configureServerlessPool(
7719
7782
  config
@@ -7738,6 +7801,7 @@ var Registry = class {
7738
7801
  */
7739
7802
  async handler(request) {
7740
7803
  var _a;
7804
+ rejectServerless();
7741
7805
  const config = this.parseConfig();
7742
7806
  this.#printWelcome(config, "serverless");
7743
7807
  if (!this.#runtimeServerlessPromise) {
@@ -7899,6 +7963,7 @@ var Registry = class {
7899
7963
  * ```
7900
7964
  */
7901
7965
  serve() {
7966
+ rejectServerless();
7902
7967
  return {
7903
7968
  fetch: (request) => this.handler(request)
7904
7969
  };
@@ -7923,10 +7988,13 @@ var Registry = class {
7923
7988
  * ```
7924
7989
  */
7925
7990
  async listen(opts = {}) {
7926
- const port = _nullishCoalesce(_nullishCoalesce(opts.port, () => ( _chunk6BRDJRCZcjs.parsePortEnv.call(void 0, process.env.RIVET_PORT))), () => ( 3e3));
7927
- const publicDir = _nullishCoalesce(opts.publicDir, () => ( _chunk6BRDJRCZcjs.getRivetkitPublicDir.call(void 0, )));
7991
+ if (!opts.application) {
7992
+ rejectServerless();
7993
+ }
7994
+ const port = _nullishCoalesce(_nullishCoalesce(opts.port, () => ( _chunkW7NPIYWCcjs.parsePortEnv.call(void 0, process.env.RIVET_PORT))), () => ( 3e3));
7995
+ const publicDir = _nullishCoalesce(opts.publicDir, () => ( _chunkW7NPIYWCcjs.getRivetkitPublicDir.call(void 0, )));
7928
7996
  const config = this.parseConfig();
7929
- if (opts.application && _chunk6BRDJRCZcjs.getRivetkitRuntimeMode.call(void 0, ) !== "serverless") {
7997
+ if (opts.application && _chunkW7NPIYWCcjs.getRivetkitRuntimeMode.call(void 0, ) !== "serverless") {
7930
7998
  if (config.runtime === "wasm") {
7931
7999
  throw new Error(
7932
8000
  "registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly"
@@ -8002,7 +8070,7 @@ var Registry = class {
8002
8070
  return jsonRouteResponse(503, {
8003
8071
  status: "not_started",
8004
8072
  runtime: "rivetkit",
8005
- version: _chunk6BRDJRCZcjs.VERSION
8073
+ version: _chunkW7NPIYWCcjs.VERSION
8006
8074
  });
8007
8075
  }
8008
8076
  const { runtime, registry } = configured;
@@ -8010,7 +8078,7 @@ var Registry = class {
8010
8078
  return jsonRouteResponse(501, {
8011
8079
  status: "unsupported",
8012
8080
  runtime: "rivetkit",
8013
- version: _chunk6BRDJRCZcjs.VERSION
8081
+ version: _chunkW7NPIYWCcjs.VERSION
8014
8082
  });
8015
8083
  }
8016
8084
  const response = await runtime.registryHealth(registry);
@@ -8023,6 +8091,7 @@ var Registry = class {
8023
8091
  * Returns serverless metadata suitable for mounting in a user-owned router.
8024
8092
  */
8025
8093
  async #metadataRoute() {
8094
+ rejectServerless();
8026
8095
  const configured = await this.#activeConfiguredRegistry();
8027
8096
  if (!configured) {
8028
8097
  return new Response("registry not started\n", {
@@ -8083,18 +8152,18 @@ var Registry = class {
8083
8152
  #startEnvoy(config, printWelcome) {
8084
8153
  var _a;
8085
8154
  if (!this.#runtimeServePromise) {
8086
- const configuredEnvoyVersion = (_a = this.#config.envoy) == null ? void 0 : _a.version;
8087
- const envoyVersionSource = configuredEnvoyVersion !== void 0 ? "config" : _chunk6BRDJRCZcjs.getRivetEnvoyVersion.call(void 0, ) !== void 0 ? "environment" : "default";
8155
+ const configuredEnvoyVersion = (_a = this.#config.node) == null ? void 0 : _a.version;
8156
+ const envoyVersionSource = configuredEnvoyVersion !== void 0 ? "config" : _chunkW7NPIYWCcjs.getRivetEnvoyVersion.call(void 0, ) !== void 0 ? "environment" : "default";
8088
8157
  logger2().info({
8089
8158
  msg: "starting rivetkit envoy",
8090
- rivetkitVersion: _chunk6BRDJRCZcjs.VERSION,
8091
- envoyVersion: config.envoy.version,
8159
+ rivetkitVersion: _chunkW7NPIYWCcjs.VERSION,
8160
+ envoyVersion: config.node.version,
8092
8161
  envoyVersionSource
8093
8162
  });
8094
- if (envoyVersionSource === "default" && _chunk6BRDJRCZcjs.getNodeEnv.call(void 0, ) === "production") {
8163
+ if (envoyVersionSource === "default" && _chunkW7NPIYWCcjs.getNodeEnv.call(void 0, ) === "production") {
8095
8164
  logger2().error({
8096
- msg: "envoy version defaulted because neither config.envoy.version nor RIVET_ENVOY_VERSION is set; actors will not drain automatically across deploys. See https://rivet.dev/docs/actors/versions",
8097
- envoyVersion: config.envoy.version,
8165
+ msg: "node version defaulted because neither config.node.version nor RIVET_NODE_VERSION is set; actors will not drain automatically across deploys. See https://rivet.dev/docs/actors/versions",
8166
+ envoyVersion: config.node.version,
8098
8167
  envoyVersionSource
8099
8168
  });
8100
8169
  }
@@ -8106,7 +8175,10 @@ var Registry = class {
8106
8175
  }
8107
8176
  );
8108
8177
  this.#runtimeServePromise = this.#runtimeServeLifecyclePromise.catch((error) => {
8109
- logger2().warn({ error }, "runtime registry serve errored");
8178
+ logger2().error({ error }, "runtime registry serve errored");
8179
+ if (typeof process !== "undefined" && typeof process.exit === "function") {
8180
+ process.exit(1);
8181
+ }
8110
8182
  });
8111
8183
  this.#installSignalHandlers(config);
8112
8184
  }
@@ -8136,7 +8208,7 @@ var Registry = class {
8136
8208
  finishShutdownSignal(signal);
8137
8209
  return;
8138
8210
  }
8139
- this.#shutdownInFlight = this.#drain(config).catch((err) => {
8211
+ this.#shutdownInFlight = this.#drain(config, true).catch((err) => {
8140
8212
  logger2().warn({ err }, "shutdown error");
8141
8213
  }).then(() => {
8142
8214
  this.#removeSignalHandlers();
@@ -8172,12 +8244,18 @@ var Registry = class {
8172
8244
  });
8173
8245
  return this.#shutdownInFlight;
8174
8246
  }
8175
- async #drain(config) {
8247
+ async #drain(config, signalDriven = false) {
8176
8248
  var _a;
8177
8249
  const modeAPromise = this.#runtimeServeConfiguredPromise;
8178
8250
  const modeBPromise = this.#runtimeServerlessPromise;
8179
8251
  const runtimes = /* @__PURE__ */ new Set();
8180
- 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));
8252
+ const localDevSignal = signalDriven && _chunkW7NPIYWCcjs.getNodeEnv.call(void 0, ) !== "production" && config.engineSpawn && config.endpoint !== void 0 && _chunkPXIOH445cjs.isLocalEngineEndpoint.call(void 0, config.endpoint);
8253
+ let gracePeriodMs = (_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs;
8254
+ if (gracePeriodMs === void 0) {
8255
+ gracePeriodMs = localDevSignal ? 1e3 : await _asyncNullishCoalesce(await this.#actorStopThresholdMs(
8256
+ _nullishCoalesce(modeAPromise, () => ( modeBPromise))
8257
+ ), async () => ( 30 * 60 * 1e3));
8258
+ }
8181
8259
  const drain = async () => {
8182
8260
  const registries = [];
8183
8261
  if (modeAPromise !== void 0) {
@@ -8282,12 +8360,16 @@ var Registry = class {
8282
8360
  );
8283
8361
  }
8284
8362
  if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
8285
- if (_chunk6BRDJRCZcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
8286
- return Promise.reject(
8287
- new Error(
8288
- "registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request"
8289
- )
8290
- );
8363
+ try {
8364
+ if (_chunkW7NPIYWCcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
8365
+ return Promise.reject(
8366
+ new Error(
8367
+ "registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request"
8368
+ )
8369
+ );
8370
+ }
8371
+ } catch (error) {
8372
+ return Promise.reject(error);
8291
8373
  }
8292
8374
  const config = this.parseConfig();
8293
8375
  if (config.runtime === "wasm") {
@@ -8352,8 +8434,8 @@ var Registry = class {
8352
8434
  * ```
8353
8435
  */
8354
8436
  start() {
8355
- if (_chunk6BRDJRCZcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
8356
- const publicDir = _nullishCoalesce(_chunk6BRDJRCZcjs.getRivetkitPublicDir.call(void 0, ), () => ( "/public"));
8437
+ if (_chunkW7NPIYWCcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
8438
+ const publicDir = _nullishCoalesce(_chunkW7NPIYWCcjs.getRivetkitPublicDir.call(void 0, ), () => ( "/public"));
8357
8439
  this.listen({ publicDir }).catch((error) => {
8358
8440
  logger2().error({ error }, "auto-listen failed; exiting");
8359
8441
  if (typeof process !== "undefined" && typeof process.exit === "function") {
@@ -8374,13 +8456,13 @@ var Registry = class {
8374
8456
  };
8375
8457
  console.log();
8376
8458
  console.log(
8377
- ` RivetKit ${_chunk6BRDJRCZcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
8459
+ ` RivetKit ${_chunkW7NPIYWCcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
8378
8460
  );
8379
8461
  if (config.namespace !== "default") {
8380
8462
  logLine("Namespace", config.namespace);
8381
8463
  }
8382
8464
  if (config.endpoint) {
8383
- const endpointType = config.startEngine || _chunk2LRKNNQJcjs.isLocalEngineEndpoint.call(void 0, config.endpoint) ? "local native" : "remote";
8465
+ const endpointType = config.startEngine || _chunkPXIOH445cjs.isLocalEngineEndpoint.call(void 0, config.endpoint) ? "local native" : "remote";
8384
8466
  logLine("Endpoint", `${config.endpoint} (${endpointType})`);
8385
8467
  }
8386
8468
  if (kind === "serverless" && config.publicEndpoint) {
@@ -8450,5 +8532,5 @@ function setup(input) {
8450
8532
 
8451
8533
 
8452
8534
 
8453
- exports.ALLOWED_PUBLIC_HEADERS = _chunk2LRKNNQJcjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunkMGI2VVF6cjs.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 = _chunkMGI2VVF6cjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunkMGI2VVF6cjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunk2LRKNNQJcjs.createClientWithDriver; exports.defineRunHandler = _chunkHDVZ6YZGcjs.defineRunHandler; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunk6BRDJRCZcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunk6BRDJRCZcjs.toUint8Array;
8535
+ exports.ALLOWED_PUBLIC_HEADERS = _chunkPXIOH445cjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunkMGI2VVF6cjs.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 = _chunkMGI2VVF6cjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunkMGI2VVF6cjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunkPXIOH445cjs.createClientWithDriver; exports.defineRunHandler = _chunkHDVZ6YZGcjs.defineRunHandler; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkW7NPIYWCcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkW7NPIYWCcjs.toUint8Array;
8454
8536
  //# sourceMappingURL=mod.cjs.map