rivetkit 0.0.0-feat-sqlite-sync.a2b9069 → 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-PFLHGSS7.cjs → chunk-3JPXBFED.cjs} +4 -4
  13. package/dist/tsup/{chunk-PFLHGSS7.cjs.map → chunk-3JPXBFED.cjs.map} +1 -1
  14. package/dist/tsup/{chunk-VZPQBM4T.js → chunk-5X35FD2T.js} +4 -4
  15. package/dist/tsup/{chunk-62NMENN2.js → chunk-6QNBANXM.js} +3 -3
  16. package/dist/tsup/{chunk-TBVEI4CG.js → chunk-7HILY7QU.js} +185 -25
  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-XU5FXL53.cjs → chunk-CT6GQRUN.cjs} +3 -3
  21. package/dist/tsup/{chunk-XU5FXL53.cjs.map → chunk-CT6GQRUN.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-3XABSX7Z.js → chunk-DRZTELHJ.js} +10 -14
  23. package/dist/tsup/chunk-DRZTELHJ.js.map +1 -0
  24. package/dist/tsup/{chunk-S4JJAPRX.js → chunk-DUGEPEJO.js} +2 -2
  25. package/dist/tsup/{chunk-E443NPGV.cjs → chunk-EA6P3N4I.cjs} +3 -3
  26. package/dist/tsup/{chunk-E443NPGV.cjs.map → chunk-EA6P3N4I.cjs.map} +1 -1
  27. package/dist/tsup/{chunk-KNVSGCHJ.cjs → chunk-ERZDCOQ3.cjs} +10 -10
  28. package/dist/tsup/{chunk-KNVSGCHJ.cjs.map → chunk-ERZDCOQ3.cjs.map} +1 -1
  29. package/dist/tsup/{chunk-PFOK45LA.js → chunk-GHTA76HT.js} +2 -2
  30. package/dist/tsup/{chunk-74MPKC4U.js → chunk-ID5VJNZY.js} +2 -2
  31. package/dist/tsup/{chunk-FKJJX36M.cjs → chunk-PXIOH445.cjs} +326 -166
  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-WMBIR2SY.cjs → chunk-UV4KDO4W.cjs} +3 -3
  36. package/dist/tsup/{chunk-WMBIR2SY.cjs.map → chunk-UV4KDO4W.cjs.map} +1 -1
  37. package/dist/tsup/{chunk-4G6WPUYN.js → chunk-VI2S336K.js} +2 -2
  38. package/dist/tsup/{chunk-4AIU4P2C.cjs → chunk-W7NPIYWC.cjs} +10 -14
  39. package/dist/tsup/chunk-W7NPIYWC.cjs.map +1 -0
  40. package/dist/tsup/{chunk-BO74QMUL.cjs → chunk-ZZQM77UA.cjs} +7 -7
  41. package/dist/tsup/{chunk-BO74QMUL.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-3XABSX7Z.js.map +0 -1
  116. package/dist/tsup/chunk-4AIU4P2C.cjs.map +0 -1
  117. package/dist/tsup/chunk-FKJJX36M.cjs.map +0 -1
  118. package/dist/tsup/chunk-JI6GZ2C2.js.map +0 -1
  119. package/dist/tsup/chunk-MYWZCDML.cjs.map +0 -1
  120. package/dist/tsup/chunk-TBVEI4CG.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-VZPQBM4T.js.map → chunk-5X35FD2T.js.map} +0 -0
  150. /package/dist/tsup/{chunk-62NMENN2.js.map → chunk-6QNBANXM.js.map} +0 -0
  151. /package/dist/tsup/{chunk-S4JJAPRX.js.map → chunk-DUGEPEJO.js.map} +0 -0
  152. /package/dist/tsup/{chunk-PFOK45LA.js.map → chunk-GHTA76HT.js.map} +0 -0
  153. /package/dist/tsup/{chunk-74MPKC4U.js.map → chunk-ID5VJNZY.js.map} +0 -0
  154. /package/dist/tsup/{chunk-4G6WPUYN.js.map → chunk-VI2S336K.js.map} +0 -0
package/dist/tsup/mod.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  decodeWorkflowHistoryTransport
3
- } from "./chunk-PFOK45LA.js";
3
+ } from "./chunk-GHTA76HT.js";
4
4
  import {
5
5
  ACTOR_CONTEXT_INTERNAL_SYMBOL,
6
6
  ActorConfigSchema,
@@ -35,17 +35,17 @@ import {
35
35
  runWithActorInvocationSpan,
36
36
  tryParseEndpoint,
37
37
  updateRunnerConfig
38
- } from "./chunk-TBVEI4CG.js";
38
+ } from "./chunk-7HILY7QU.js";
39
39
  import {
40
40
  makePrefixedKey,
41
41
  removePrefixFromKey
42
- } from "./chunk-JI6GZ2C2.js";
43
- import "./chunk-S4JJAPRX.js";
42
+ } from "./chunk-A2CF6PFH.js";
43
+ import "./chunk-DUGEPEJO.js";
44
44
  import {
45
45
  bindNativeStateTransactionContext,
46
46
  db,
47
47
  registerNativeStateTransactionOpener
48
- } from "./chunk-4G6WPUYN.js";
48
+ } from "./chunk-VI2S336K.js";
49
49
  import "./chunk-JTHHCZCZ.js";
50
50
  import {
51
51
  LogLevelSchema,
@@ -80,11 +80,12 @@ import {
80
80
  parsePortEnv,
81
81
  stringifyError,
82
82
  toUint8Array
83
- } from "./chunk-3XABSX7Z.js";
83
+ } from "./chunk-DRZTELHJ.js";
84
84
  import {
85
85
  INTERNAL_ERROR_CODE,
86
86
  RivetError,
87
87
  UserError,
88
+ actorStopping,
88
89
  decodeBridgeRivetError,
89
90
  encodeBridgeRivetError,
90
91
  encodeErrorForBridge,
@@ -500,7 +501,7 @@ var EnvoyConfigSchema = z.object({
500
501
  version: z.number().default(() => getRivetEnvoyVersion() ?? 1),
501
502
  // Deprecated.
502
503
  totalSlots: z.number().default(() => getRivetTotalSlots() ?? 1e5),
503
- envoyKey: z.string().optional()
504
+ nodeKey: z.string().optional()
504
505
  });
505
506
 
506
507
  // src/registry/config/serverless.ts
@@ -644,7 +645,7 @@ var RegistryConfigSchema = z3.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
  *
@@ -713,30 +714,30 @@ var RegistryConfigSchema = z3.object({
713
714
  engineVersion: z3.string().optional().default(() => getRivetRunEngineVersion() ?? 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: z3.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 = z3.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: z3.number().int().min(1e3).optional(),
756
759
  /**
@@ -786,10 +789,11 @@ var RegistryConfigSchema = z3.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
799
  const localEngineEndpoint = buildEngineEndpoint(
@@ -797,7 +801,7 @@ var RegistryConfigSchema = z3.object({
797
801
  config.enginePort
798
802
  );
799
803
  const endpoint = config.startEngine ? localEngineEndpoint : (parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint) ?? (isDevEnv ? localEngineEndpoint : void 0);
800
- const startServices = config.startServices ?? getRivetRunServices() ?? Boolean(endpoint && isLocalEngineEndpoint(endpoint));
804
+ const startServices = config.startServices ?? getRivetRunServices();
801
805
  const validateServerlessEndpoint = Boolean(
802
806
  config.startEngine || parsedEndpoint
803
807
  );
@@ -821,6 +825,7 @@ var RegistryConfigSchema = z3.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 = z3.object({
853
- name: z3.string().optional().describe("Name of the runner pool."),
854
- url: z3.string().describe("URL of the serverless platform to configure runners."),
858
+ name: z3.string().optional().describe("Name of the node pool."),
859
+ url: z3.string().describe("URL of the serverless platform to configure nodes."),
855
860
  headers: z3.record(z3.string(), z3.string()).optional().describe(
856
861
  "Headers to include in requests to the serverless platform."
857
862
  ),
@@ -866,7 +871,7 @@ var DocConfigurePoolSchema = z3.object({
866
871
  "Interval in milliseconds between metadata polls from the engine. Defaults to 10000 milliseconds (10 seconds)."
867
872
  ),
868
873
  drainOnVersionUpgrade: z3.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 = z3.object({
@@ -885,10 +890,10 @@ var DocServerlessConfigSchema = z3.object({
885
890
  }).describe("Configuration for serverless deployment mode.");
886
891
  var DocEnvoyConfigSchema = z3.object({
887
892
  totalSlots: z3.number().optional().describe("Total number of actor slots available. Default: 100000"),
888
- poolName: z3.string().optional().describe("Name of this envoy pool. Default: 'default'"),
889
- envoyKey: z3.string().optional().describe("Deprecated. Authentication key for the envoy."),
890
- version: z3.number().optional().describe("Version number of this envoy. Default: 1")
891
- }).describe("Configuration for envoy mode.");
893
+ poolName: z3.string().optional().describe("Name of this node pool. Default: 'default'"),
894
+ nodeKey: z3.string().optional().describe("Deprecated. Authentication key for the node."),
895
+ version: z3.number().optional().describe("Version number of this node. Default: 1")
896
+ }).describe("Configuration for node mode.");
892
897
  var DocSqliteConfigSchema = z3.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."
@@ -936,13 +941,13 @@ var DocRegistryConfigSchema = z3.object({
936
941
  "Version of the local engine package to use. Defaults to the current RivetKit version."
937
942
  ),
938
943
  startServices: z3.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) {
@@ -1807,7 +1820,8 @@ var NapiCoreRuntime = 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();
@@ -2909,9 +2923,10 @@ var WasmCoreRuntime = 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(
@@ -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 actorStopping(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,13 +3885,18 @@ 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);
@@ -3880,10 +3909,19 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
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
  }
@@ -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
  () => {
@@ -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);
@@ -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
  }
@@ -7536,11 +7592,12 @@ 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,
@@ -7561,14 +7618,16 @@ async function buildServeConfig(config, resolveServicesBinary = true) {
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: stringifyError(error)
7571
- });
7621
+ const servicesBinary = getEnvUniversal("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;
@@ -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":
@@ -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,6 +7988,9 @@ var Registry = class {
7923
7988
  * ```
7924
7989
  */
7925
7990
  async listen(opts = {}) {
7991
+ if (!opts.application) {
7992
+ rejectServerless();
7993
+ }
7926
7994
  const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3e3;
7927
7995
  const publicDir = opts.publicDir ?? getRivetkitPublicDir();
7928
7996
  const config = this.parseConfig();
@@ -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;
8155
+ const configuredEnvoyVersion = (_a = this.#config.node) == null ? void 0 : _a.version;
8087
8156
  const envoyVersionSource = configuredEnvoyVersion !== void 0 ? "config" : getRivetEnvoyVersion() !== void 0 ? "environment" : "default";
8088
8157
  logger2().info({
8089
8158
  msg: "starting rivetkit envoy",
8090
8159
  rivetkitVersion: VERSION,
8091
- envoyVersion: config.envoy.version,
8160
+ envoyVersion: config.node.version,
8092
8161
  envoyVersionSource
8093
8162
  });
8094
8163
  if (envoyVersionSource === "default" && getNodeEnv() === "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 = ((_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs) ?? await this.#actorStopThresholdMs(modeAPromise ?? modeBPromise) ?? 30 * 60 * 1e3;
8252
+ const localDevSignal = signalDriven && getNodeEnv() !== "production" && config.engineSpawn && config.endpoint !== void 0 && isLocalEngineEndpoint(config.endpoint);
8253
+ let gracePeriodMs = (_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs;
8254
+ if (gracePeriodMs === void 0) {
8255
+ gracePeriodMs = localDevSignal ? 1e3 : await this.#actorStopThresholdMs(
8256
+ modeAPromise ?? modeBPromise
8257
+ ) ?? 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 (getRivetkitRuntimeMode() === "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 (getRivetkitRuntimeMode() === "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") {