rivetkit 0.0.0-sqlite-query-metrics-v2.f5d3605 → 0.0.0-sqlite-query-metrics-v3.1dff84f

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 (150) hide show
  1. package/dist/browser/client.d.ts +60 -10
  2. package/dist/browser/client.js +294 -40
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +4 -2
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/{chunk-HO76AEDH.cjs → chunk-22S5RCCJ.cjs} +3 -3
  7. package/dist/tsup/{chunk-HO76AEDH.cjs.map → chunk-22S5RCCJ.cjs.map} +1 -1
  8. package/dist/tsup/{chunk-EPRA2TCT.js → chunk-2CTZU7GL.js} +2 -2
  9. package/dist/tsup/{chunk-JI6GZ2C2.js → chunk-A2CF6PFH.js} +18 -1
  10. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  11. package/dist/tsup/{chunk-QR6EAWEC.cjs → chunk-CWN7N5AF.cjs} +7 -7
  12. package/dist/tsup/{chunk-QR6EAWEC.cjs.map → chunk-CWN7N5AF.cjs.map} +1 -1
  13. package/dist/tsup/{chunk-3URZ4UV5.js → chunk-D7DWNYEO.js} +2 -2
  14. package/dist/tsup/{chunk-F7IGTKGM.js → chunk-F5PWAGS7.js} +2 -2
  15. package/dist/tsup/{chunk-E2CUROR3.js → chunk-FT6VRK4C.js} +2 -2
  16. package/dist/tsup/{chunk-FYDB45YU.cjs → chunk-HFGXV2CC.cjs} +10 -10
  17. package/dist/tsup/{chunk-FYDB45YU.cjs.map → chunk-HFGXV2CC.cjs.map} +1 -1
  18. package/dist/tsup/{chunk-D4G35VTO.js → chunk-HRKFVQPS.js} +4 -4
  19. package/dist/tsup/{chunk-DHL2M2E2.cjs → chunk-HXJ5U2ZI.cjs} +3 -3
  20. package/dist/tsup/{chunk-DHL2M2E2.cjs.map → chunk-HXJ5U2ZI.cjs.map} +1 -1
  21. package/dist/tsup/{chunk-L3Z3W44Q.cjs → chunk-JJUSO7GJ.cjs} +3 -3
  22. package/dist/tsup/{chunk-L3Z3W44Q.cjs.map → chunk-JJUSO7GJ.cjs.map} +1 -1
  23. package/dist/tsup/{chunk-DDS7OOVF.cjs → chunk-NG5CUXMM.cjs} +420 -182
  24. package/dist/tsup/chunk-NG5CUXMM.cjs.map +1 -0
  25. package/dist/tsup/{chunk-USKGKQZM.js → chunk-NNCL4IBC.js} +12 -7
  26. package/dist/tsup/chunk-NNCL4IBC.js.map +1 -0
  27. package/dist/tsup/{chunk-PJ5EXY6F.js → chunk-QQIFRR3B.js} +283 -45
  28. package/dist/tsup/chunk-QQIFRR3B.js.map +1 -0
  29. package/dist/tsup/{chunk-MYWZCDML.cjs → chunk-RTWH3AX3.cjs} +19 -2
  30. package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
  31. package/dist/tsup/{chunk-HDVZ6YZG.cjs → chunk-SSF2XC33.cjs} +1 -1
  32. package/dist/tsup/chunk-SSF2XC33.cjs.map +1 -0
  33. package/dist/tsup/{chunk-KSP3NXGY.js → chunk-SW33HMM5.js} +3 -3
  34. package/dist/tsup/{chunk-6FEYCVZC.js → chunk-UXDASKP6.js} +1 -1
  35. package/dist/tsup/chunk-UXDASKP6.js.map +1 -0
  36. package/dist/tsup/{chunk-KDT56V3Y.cjs → chunk-Y4QLVCCS.cjs} +12 -7
  37. package/dist/tsup/chunk-Y4QLVCCS.cjs.map +1 -0
  38. package/dist/tsup/{chunk-JW2WPE6Z.cjs → chunk-Y5CFDGPA.cjs} +4 -4
  39. package/dist/tsup/{chunk-JW2WPE6Z.cjs.map → chunk-Y5CFDGPA.cjs.map} +1 -1
  40. package/dist/tsup/client/mod.cjs +6 -6
  41. package/dist/tsup/client/mod.d.cts +15 -3
  42. package/dist/tsup/client/mod.d.ts +15 -3
  43. package/dist/tsup/client/mod.js +5 -5
  44. package/dist/tsup/common/log.cjs +2 -2
  45. package/dist/tsup/common/log.js +1 -1
  46. package/dist/tsup/common/websocket.cjs +3 -3
  47. package/dist/tsup/common/websocket.js +2 -2
  48. package/dist/tsup/{config-Cw_BwH_G.d.ts → config-BiiS5T5M.d.ts} +45 -12
  49. package/dist/tsup/{config-CkmVg2fG.d.cts → config-BnMhcPHl.d.cts} +45 -12
  50. package/dist/tsup/{config-D4clT6mq.d.ts → config-CBTr4IhE.d.cts} +0 -2
  51. package/dist/tsup/{config-D4clT6mq.d.cts → config-CBTr4IhE.d.ts} +0 -2
  52. package/dist/tsup/{context-_xIcgBnE.d.cts → context-DVE8XMm1.d.cts} +2 -2
  53. package/dist/tsup/{context-BYOKTQJi.d.ts → context-iMxXq_Lt.d.ts} +2 -2
  54. package/dist/tsup/db/drizzle.cjs +2 -2
  55. package/dist/tsup/db/drizzle.d.cts +1 -1
  56. package/dist/tsup/db/drizzle.d.ts +1 -1
  57. package/dist/tsup/db/drizzle.js +1 -1
  58. package/dist/tsup/db/mod.cjs +3 -3
  59. package/dist/tsup/db/mod.d.cts +2 -2
  60. package/dist/tsup/db/mod.d.ts +2 -2
  61. package/dist/tsup/db/mod.js +2 -2
  62. package/dist/tsup/dynamic/mod.cjs +2 -2
  63. package/dist/tsup/dynamic/mod.d.cts +2 -2
  64. package/dist/tsup/dynamic/mod.d.ts +2 -2
  65. package/dist/tsup/dynamic/mod.js +1 -1
  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.cjs +2 -2
  71. package/dist/tsup/inspector-tab/mod.d.cts +3 -3
  72. package/dist/tsup/inspector-tab/mod.d.ts +3 -3
  73. package/dist/tsup/inspector-tab/mod.js +1 -1
  74. package/dist/tsup/mod.cjs +298 -198
  75. package/dist/tsup/mod.cjs.map +1 -1
  76. package/dist/tsup/mod.d.cts +4 -4
  77. package/dist/tsup/mod.d.ts +4 -4
  78. package/dist/tsup/mod.js +192 -92
  79. package/dist/tsup/mod.js.map +1 -1
  80. package/dist/tsup/test/mod.cjs +7 -7
  81. package/dist/tsup/test/mod.d.cts +2 -2
  82. package/dist/tsup/test/mod.d.ts +2 -2
  83. package/dist/tsup/test/mod.js +5 -5
  84. package/dist/tsup/unstable/migrations.d.cts +1 -1
  85. package/dist/tsup/unstable/migrations.d.ts +1 -1
  86. package/dist/tsup/utils.cjs +2 -2
  87. package/dist/tsup/utils.js +1 -1
  88. package/dist/tsup/workflow/mod.cjs +25 -22
  89. package/dist/tsup/workflow/mod.cjs.map +1 -1
  90. package/dist/tsup/workflow/mod.d.cts +4 -4
  91. package/dist/tsup/workflow/mod.d.ts +4 -4
  92. package/dist/tsup/workflow/mod.js +11 -8
  93. package/dist/tsup/workflow/mod.js.map +1 -1
  94. package/package.json +12 -10
  95. package/src/actor/config.ts +2 -0
  96. package/src/actor/keys.ts +86 -0
  97. package/src/client/actor-conn.ts +136 -24
  98. package/src/client/actor-handle.ts +64 -10
  99. package/src/client/client.ts +6 -0
  100. package/src/client/config.ts +12 -1
  101. package/src/client/lifecycle-errors.ts +35 -2
  102. package/src/client/raw-utils.ts +17 -3
  103. package/src/client/retry-budget.ts +78 -0
  104. package/src/client/utils.ts +17 -2
  105. package/src/common/database/config.ts +0 -2
  106. package/src/common/database/native-database.ts +17 -6
  107. package/src/common/router.ts +1 -1
  108. package/src/engine-api/actors.ts +3 -3
  109. package/src/engine-client/actor-websocket-client.ts +4 -2
  110. package/src/engine-client/api-endpoints.ts +44 -14
  111. package/src/engine-client/mod.ts +2 -2
  112. package/src/registry/config/envoy.ts +1 -1
  113. package/src/registry/config/index.ts +30 -30
  114. package/src/registry/index.ts +66 -21
  115. package/src/registry/napi-runtime.ts +4 -3
  116. package/src/registry/native.ts +147 -48
  117. package/src/registry/runtime.ts +27 -10
  118. package/src/registry/wasm-runtime.ts +6 -3
  119. package/src/utils/env-vars.ts +13 -6
  120. package/src/workflow/driver.ts +5 -3
  121. package/dist/tsup/chunk-6FEYCVZC.js.map +0 -1
  122. package/dist/tsup/chunk-DDS7OOVF.cjs.map +0 -1
  123. package/dist/tsup/chunk-HDVZ6YZG.cjs.map +0 -1
  124. package/dist/tsup/chunk-JI6GZ2C2.js.map +0 -1
  125. package/dist/tsup/chunk-KDT56V3Y.cjs.map +0 -1
  126. package/dist/tsup/chunk-MYWZCDML.cjs.map +0 -1
  127. package/dist/tsup/chunk-PJ5EXY6F.js.map +0 -1
  128. package/dist/tsup/chunk-USKGKQZM.js.map +0 -1
  129. package/src/actor/config.test.ts +0 -78
  130. package/src/actor/keys.test.ts +0 -275
  131. package/src/actor/utils.test.ts +0 -48
  132. package/src/client/test.ts +0 -44
  133. package/src/client/token-provider.test.ts +0 -86
  134. package/src/common/database/mod.test.ts +0 -364
  135. package/src/common/database/native-database.test.ts +0 -220
  136. package/src/common/inline-websocket-adapter.test.ts +0 -51
  137. package/src/db/drizzle.test.ts +0 -164
  138. package/src/registry/config/index.test.ts +0 -25
  139. package/src/registry/run-handler-coordinator.test.ts +0 -252
  140. package/src/registry/runtime.test.ts +0 -124
  141. package/src/unstable/migrations.test.ts +0 -170
  142. package/src/utils/endpoint-parser.test.ts +0 -206
  143. package/src/utils.test.ts +0 -34
  144. package/src/workflow/driver.test.ts +0 -62
  145. /package/dist/tsup/{chunk-EPRA2TCT.js.map → chunk-2CTZU7GL.js.map} +0 -0
  146. /package/dist/tsup/{chunk-3URZ4UV5.js.map → chunk-D7DWNYEO.js.map} +0 -0
  147. /package/dist/tsup/{chunk-F7IGTKGM.js.map → chunk-F5PWAGS7.js.map} +0 -0
  148. /package/dist/tsup/{chunk-E2CUROR3.js.map → chunk-FT6VRK4C.js.map} +0 -0
  149. /package/dist/tsup/{chunk-D4G35VTO.js.map → chunk-HRKFVQPS.js.map} +0 -0
  150. /package/dist/tsup/{chunk-KSP3NXGY.js.map → chunk-SW33HMM5.js.map} +0 -0
package/dist/tsup/mod.js CHANGED
@@ -1,6 +1,3 @@
1
- import {
2
- decodeWorkflowHistoryTransport
3
- } from "./chunk-3URZ4UV5.js";
4
1
  import {
5
2
  ACTOR_CONTEXT_INTERNAL_SYMBOL,
6
3
  ActorConfigSchema,
@@ -17,7 +14,10 @@ import {
17
14
  getRunInspectorKind,
18
15
  getRunMetadata,
19
16
  hasRunInspectorConfig
20
- } from "./chunk-6FEYCVZC.js";
17
+ } from "./chunk-UXDASKP6.js";
18
+ import {
19
+ decodeWorkflowHistoryTransport
20
+ } from "./chunk-D7DWNYEO.js";
21
21
  import {
22
22
  ALLOWED_PUBLIC_HEADERS,
23
23
  ENGINE_HOST,
@@ -35,17 +35,17 @@ import {
35
35
  runWithActorInvocationSpan,
36
36
  tryParseEndpoint,
37
37
  updateRunnerConfig
38
- } from "./chunk-PJ5EXY6F.js";
38
+ } from "./chunk-QQIFRR3B.js";
39
39
  import {
40
40
  makePrefixedKey,
41
41
  removePrefixFromKey
42
- } from "./chunk-JI6GZ2C2.js";
43
- import "./chunk-F7IGTKGM.js";
42
+ } from "./chunk-A2CF6PFH.js";
43
+ import "./chunk-F5PWAGS7.js";
44
44
  import {
45
45
  bindNativeStateTransactionContext,
46
46
  db,
47
47
  registerNativeStateTransactionOpener
48
- } from "./chunk-E2CUROR3.js";
48
+ } from "./chunk-FT6VRK4C.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-USKGKQZM.js";
83
+ } from "./chunk-NNCL4IBC.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. Enabled by default for a managed local Engine. Set
718
+ * RIVET_RUN_SERVICES=0 or startServices: false to disable 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,12 @@ 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
+ * four seconds by default so actors can acknowledge stopping before
755
+ * a file watcher restarts the process.
752
756
  *
753
- * Must be long enough for rivetkit-core to drain the envoy.
757
+ * Set a longer period when a complete graceful node drain is required.
754
758
  */
755
759
  gracePeriodMs: z3.number().int().min(1e3).optional(),
756
760
  /**
@@ -786,10 +790,11 @@ var RegistryConfigSchema = z3.object({
786
790
  message: "cannot specify both startEngine and endpoint"
787
791
  });
788
792
  }
789
- if (config.configurePool && !parsedEndpoint && !config.startEngine) {
793
+ if (config.configurePool) {
790
794
  ctx.addIssue({
791
795
  code: "custom",
792
- message: "configurePool requires either endpoint or startEngine"
796
+ message: "serverless is disabled in this version",
797
+ path: ["configurePool"]
793
798
  });
794
799
  }
795
800
  const localEngineEndpoint = buildEngineEndpoint(
@@ -797,7 +802,8 @@ var RegistryConfigSchema = z3.object({
797
802
  config.enginePort
798
803
  );
799
804
  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));
805
+ const engineSpawn = !parsedEndpoint && Boolean(endpoint);
806
+ const startServices = config.startServices ?? getRivetRunServices() ?? engineSpawn;
801
807
  const validateServerlessEndpoint = Boolean(
802
808
  config.startEngine || parsedEndpoint
803
809
  );
@@ -821,6 +827,7 @@ var RegistryConfigSchema = z3.object({
821
827
  ...config,
822
828
  sqlite,
823
829
  endpoint,
830
+ engineSpawn,
824
831
  startServices,
825
832
  namespace,
826
833
  token,
@@ -850,8 +857,8 @@ function buildActorNames(config) {
850
857
  );
851
858
  }
852
859
  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."),
860
+ name: z3.string().optional().describe("Name of the node pool."),
861
+ url: z3.string().describe("URL of the serverless platform to configure nodes."),
855
862
  headers: z3.record(z3.string(), z3.string()).optional().describe(
856
863
  "Headers to include in requests to the serverless platform."
857
864
  ),
@@ -866,7 +873,7 @@ var DocConfigurePoolSchema = z3.object({
866
873
  "Interval in milliseconds between metadata polls from the engine. Defaults to 10000 milliseconds (10 seconds)."
867
874
  ),
868
875
  drainOnVersionUpgrade: z3.boolean().optional().describe(
869
- "Drain runners when a new version is deployed. Defaults to true."
876
+ "Drain nodes when a new version is deployed. Defaults to true."
870
877
  )
871
878
  }).optional();
872
879
  var DocServerlessConfigSchema = z3.object({
@@ -885,10 +892,10 @@ var DocServerlessConfigSchema = z3.object({
885
892
  }).describe("Configuration for serverless deployment mode.");
886
893
  var DocEnvoyConfigSchema = z3.object({
887
894
  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.");
895
+ poolName: z3.string().optional().describe("Name of this node pool. Default: 'default'"),
896
+ nodeKey: z3.string().optional().describe("Deprecated. Authentication key for the node."),
897
+ version: z3.number().optional().describe("Version number of this node. Default: 1")
898
+ }).describe("Configuration for node mode.");
892
899
  var DocSqliteConfigSchema = z3.object({
893
900
  backend: SqliteBackendSchema.optional().describe(
894
901
  "SQLite backend to use. Native defaults to local. Wasm defaults to remote and cannot use local."
@@ -936,13 +943,13 @@ var DocRegistryConfigSchema = z3.object({
936
943
  "Version of the local engine package to use. Defaults to the current RivetKit version."
937
944
  ),
938
945
  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."
946
+ "Starts Services when RivetKit manages a local Engine. Enabled by default for a managed local Engine. Set RIVET_RUN_SERVICES=0 or startServices: false to disable."
940
947
  ),
941
948
  configurePool: DocConfigurePoolSchema.describe(
942
- "Automatically configure serverless runners in the engine."
949
+ "Automatically configure serverless nodes in the engine."
943
950
  ),
944
951
  serverless: DocServerlessConfigSchema.optional(),
945
- envoy: DocEnvoyConfigSchema.optional()
952
+ node: DocEnvoyConfigSchema.optional()
946
953
  }).describe("RivetKit registry configuration.");
947
954
 
948
955
  // src/registry/native.ts
@@ -1105,12 +1112,12 @@ var NativeCloseGate = class {
1105
1112
  if (this.#active > 0) {
1106
1113
  await new Promise((resolve) => this.#waiters.push(resolve));
1107
1114
  }
1108
- await callback();
1115
+ await (callback == null ? void 0 : callback());
1109
1116
  }
1110
1117
  };
1111
1118
  function wrapJsNativeDatabase(database) {
1112
1119
  const gate = new NativeCloseGate();
1113
- let closePromise;
1120
+ let terminalPromise;
1114
1121
  let lastInsertRowId = null;
1115
1122
  const executeNative = async (sql, params) => {
1116
1123
  const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
@@ -1245,8 +1252,12 @@ function wrapJsNativeDatabase(database) {
1245
1252
  return normalizeNativeMetrics((_a = database.metrics) == null ? void 0 : _a.call(database));
1246
1253
  },
1247
1254
  async close() {
1248
- closePromise ??= gate.close(() => database.close());
1249
- await closePromise;
1255
+ terminalPromise ??= gate.close(() => database.close());
1256
+ await terminalPromise;
1257
+ },
1258
+ async detachForShutdown() {
1259
+ terminalPromise ??= gate.close();
1260
+ await terminalPromise;
1250
1261
  }
1251
1262
  };
1252
1263
  }
@@ -1392,6 +1403,12 @@ function getNodePath() {
1392
1403
  function normalizeRuntimeSqlExecuteResult(result) {
1393
1404
  return result;
1394
1405
  }
1406
+ function servicesBinaryUnavailable(cause) {
1407
+ return new Error(
1408
+ "services.binary_unavailable: Install @rivet-dev/services to run local Services, set RIVET_SERVICES_BINARY to its executable path, or set RIVET_RUN_SERVICES=0 to disable Services.",
1409
+ { cause }
1410
+ );
1411
+ }
1395
1412
 
1396
1413
  // src/registry/napi-runtime.ts
1397
1414
  function asNativeRegistry(handle) {
@@ -1664,7 +1681,8 @@ var NapiCoreRuntime = class {
1664
1681
  asNativeCancellationToken(token).cancel();
1665
1682
  }
1666
1683
  onCancellationTokenCancelled(token, callback) {
1667
- asNativeCancellationToken(token).onCancelled(callback);
1684
+ const listener = asNativeCancellationToken(token).onCancelled(callback);
1685
+ return () => listener.release();
1668
1686
  }
1669
1687
  actorState(ctx) {
1670
1688
  return asNativeActorContext(ctx).state();
@@ -2703,9 +2721,10 @@ var WasmCoreRuntime = class {
2703
2721
  callWasmSync(() => asWasmCancellationToken(token).cancel());
2704
2722
  }
2705
2723
  onCancellationTokenCancelled(token, callback) {
2706
- callWasmSync(
2724
+ const listener = callWasmSync(
2707
2725
  () => asWasmCancellationToken(token).onCancelled(callback)
2708
2726
  );
2727
+ return () => callWasmSync(() => listener.release());
2709
2728
  }
2710
2729
  actorState(ctx) {
2711
2730
  return toBytes(
@@ -3498,9 +3517,10 @@ function normalizeRuntimeConfig(config, runtime) {
3498
3517
  return normalizeRuntimeConfigForKind(config, loadedRuntimeKind(runtime));
3499
3518
  }
3500
3519
  function getNativeRuntimeState(runtime, ctx) {
3501
- const runtimeState = callNativeSync(
3502
- () => runtime.actorRuntimeState(ctx)
3503
- );
3520
+ const runtimeState = readNativeRuntimeStateBag(runtime, ctx);
3521
+ if (runtimeState.cleared) {
3522
+ throw actorStopping(callNativeSync(() => runtime.actorId(ctx)));
3523
+ }
3504
3524
  if (!runtimeState.destroyGate) {
3505
3525
  runtimeState.destroyGate = {};
3506
3526
  }
@@ -3513,6 +3533,14 @@ function getNativeRuntimeState(runtime, ctx) {
3513
3533
  }
3514
3534
  return runtimeState;
3515
3535
  }
3536
+ function readNativeRuntimeStateBag(runtime, ctx) {
3537
+ return callNativeSync(
3538
+ () => runtime.actorRuntimeState(ctx)
3539
+ );
3540
+ }
3541
+ function isNativeRuntimeStateCleared(runtime, ctx) {
3542
+ return readNativeRuntimeStateBag(runtime, ctx).cleared === true;
3543
+ }
3516
3544
  function getNativePersistState(runtime, ctx) {
3517
3545
  const persistState = getNativeRuntimeState(runtime, ctx).persistState;
3518
3546
  if (!persistState) {
@@ -3623,13 +3651,18 @@ function resolveNativeDestroy(runtime, ctx) {
3623
3651
  gate.destroyCompletion = void 0;
3624
3652
  }
3625
3653
  function clearNativeRuntimeState(runtime, ctx) {
3654
+ var _a;
3655
+ const pendingSaveHandle = (_a = readNativeRuntimeStateBag(runtime, ctx).persistState) == null ? void 0 : _a.pendingSaveHandle;
3656
+ if (pendingSaveHandle !== void 0) {
3657
+ clearImmediate(pendingSaveHandle);
3658
+ }
3626
3659
  callNativeSync(() => runtime.actorClearRuntimeState(ctx));
3660
+ readNativeRuntimeStateBag(runtime, ctx).cleared = true;
3627
3661
  }
3628
3662
  async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrained) {
3629
3663
  const drained = await runtime.actorWaitForTrackedShutdownWork(ctx);
3630
3664
  if (!drained) {
3631
- await closeNativeDatabaseClient(runtime, ctx);
3632
- await closeNativeSqlDatabase(runtime, ctx);
3665
+ await detachNativeDatabaseForShutdown(runtime, ctx);
3633
3666
  void runtime.actorWaitForTrackedShutdownWorkUnbounded(ctx).then(async () => {
3634
3667
  await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
3635
3668
  clearNativeRuntimeState(runtime, ctx);
@@ -3642,10 +3675,19 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
3642
3675
  return;
3643
3676
  }
3644
3677
  await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
3645
- await closeNativeDatabaseClient(runtime, ctx);
3646
- await closeNativeSqlDatabase(runtime, ctx);
3678
+ await detachNativeDatabaseForShutdown(runtime, ctx);
3647
3679
  clearNativeRuntimeState(runtime, ctx);
3648
3680
  }
3681
+ async function detachNativeDatabaseForShutdown(runtime, ctx) {
3682
+ var _a;
3683
+ const runtimeState = getNativeRuntimeState(runtime, ctx);
3684
+ await ((_a = runtimeState.sql) == null ? void 0 : _a.detachForShutdown());
3685
+ try {
3686
+ await closeNativeDatabaseClient(runtime, ctx);
3687
+ } finally {
3688
+ runtimeState.sql = void 0;
3689
+ }
3690
+ }
3649
3691
  function closeNativeSqlDatabase(runtime, ctx) {
3650
3692
  const runtimeState = getNativeRuntimeState(runtime, ctx);
3651
3693
  const database = runtimeState.sql;
@@ -5386,12 +5428,14 @@ var ActorContextHandleAdapter = class {
5386
5428
  }
5387
5429
  get abortSignal() {
5388
5430
  if (!this.#abortSignal) {
5389
- const actorSignal = this.#createActorAbortSignal();
5431
+ const actorAbort = this.#actorAbort();
5432
+ const actorSignal = actorAbort.signal;
5390
5433
  if (this.#dispatchCancelToken === void 0) {
5391
5434
  this.#abortSignal = actorSignal;
5392
5435
  } else {
5393
5436
  const controller = new AbortController();
5394
5437
  let cleanedUp = false;
5438
+ let releaseDispatchListener;
5395
5439
  const onActorAbort = () => {
5396
5440
  cleanup();
5397
5441
  controller.abort();
@@ -5401,7 +5445,9 @@ var ActorContextHandleAdapter = class {
5401
5445
  return;
5402
5446
  }
5403
5447
  cleanedUp = true;
5404
- actorSignal.removeEventListener("abort", onActorAbort);
5448
+ actorAbort.listeners.delete(onActorAbort);
5449
+ releaseDispatchListener == null ? void 0 : releaseDispatchListener();
5450
+ releaseDispatchListener = void 0;
5405
5451
  this.#abortSignalCleanup = void 0;
5406
5452
  };
5407
5453
  if (actorSignal.aborted || this.#runtime.cancellationTokenAborted(
@@ -5411,10 +5457,8 @@ var ActorContextHandleAdapter = class {
5411
5457
  } else {
5412
5458
  const dispatchCancelToken = this.#dispatchCancelToken;
5413
5459
  this.#abortSignalCleanup = cleanup;
5414
- actorSignal.addEventListener("abort", onActorAbort, {
5415
- once: true
5416
- });
5417
- callNativeSync(
5460
+ actorAbort.listeners.add(onActorAbort);
5461
+ releaseDispatchListener = callNativeSync(
5418
5462
  () => this.#runtime.onCancellationTokenCancelled(
5419
5463
  dispatchCancelToken,
5420
5464
  () => {
@@ -5790,22 +5834,42 @@ var ActorContextHandleAdapter = class {
5790
5834
  }
5791
5835
  async dispose() {
5792
5836
  var _a;
5793
- this.#flushStateChange();
5837
+ if (!isNativeRuntimeStateCleared(this.#runtime, this.#ctx)) {
5838
+ this.#flushStateChange();
5839
+ }
5794
5840
  (_a = this.#abortSignalCleanup) == null ? void 0 : _a.call(this);
5795
5841
  }
5796
- #createActorAbortSignal() {
5842
+ #actorAbort() {
5843
+ const runtimeState = readNativeRuntimeStateBag(
5844
+ this.#runtime,
5845
+ this.#ctx
5846
+ );
5847
+ const cached = runtimeState.actorAbort;
5848
+ if (cached && !cached.signal.aborted) {
5849
+ return cached;
5850
+ }
5797
5851
  const nativeSignal = callNativeSync(
5798
5852
  () => this.#runtime.actorAbortSignal(this.#ctx)
5799
5853
  );
5800
5854
  const controller = new AbortController();
5801
- if (nativeSignal.aborted) {
5855
+ const actorAbort = {
5856
+ signal: controller.signal,
5857
+ listeners: /* @__PURE__ */ new Set()
5858
+ };
5859
+ const abort = () => {
5802
5860
  controller.abort();
5861
+ for (const listener of actorAbort.listeners) {
5862
+ listener();
5863
+ }
5864
+ actorAbort.listeners.clear();
5865
+ };
5866
+ if (nativeSignal.aborted) {
5867
+ abort();
5803
5868
  } else {
5804
- nativeSignal.addEventListener("abort", () => controller.abort(), {
5805
- once: true
5806
- });
5869
+ nativeSignal.addEventListener("abort", abort, { once: true });
5807
5870
  }
5808
- return controller.signal;
5871
+ runtimeState.actorAbort = actorAbort;
5872
+ return actorAbort;
5809
5873
  }
5810
5874
  #readState() {
5811
5875
  const actorState = getNativePersistState(this.#runtime, this.#ctx);
@@ -6767,7 +6831,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6767
6831
  }
6768
6832
  } finally {
6769
6833
  resolveNativeDestroy(runtime, ctx);
6770
- await actorCtx.closeDatabase();
6834
+ await detachNativeDatabaseForShutdown(runtime, ctx);
6771
6835
  clearNativeRuntimeState(runtime, ctx);
6772
6836
  await actorCtx.dispose();
6773
6837
  }
@@ -7153,6 +7217,11 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7153
7217
  async (error, payload) => {
7154
7218
  const { ctx, conn, args, scheduledFire, cancelToken } = unwrapTsfnPayload(error, payload);
7155
7219
  const actorCtx = conn != null ? makeConnCtx(ctx, conn, void 0, cancelToken) : makeActorCtx(ctx, void 0, cancelToken);
7220
+ if (scheduledFire) {
7221
+ Object.defineProperty(actorCtx, "scheduledFire", {
7222
+ value: scheduledFire
7223
+ });
7224
+ }
7156
7225
  const runAction = async () => {
7157
7226
  try {
7158
7227
  return encodeValue(
@@ -7265,18 +7334,19 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7265
7334
  buildActorConfig(definition, registryConfig, runtime.kind)
7266
7335
  );
7267
7336
  }
7268
- async function buildServeConfig(config, resolveServicesBinary = true) {
7337
+ async function buildServeConfig(config, resolveNativeBinaries = true) {
7269
7338
  var _a;
7270
7339
  if (!config.endpoint) {
7271
7340
  throw nativeEndpointNotConfiguredError();
7272
7341
  }
7273
7342
  const serveConfig = {
7274
- version: config.envoy.version,
7343
+ version: config.node.version,
7275
7344
  endpoint: config.endpoint,
7345
+ engineSpawn: config.engineSpawn,
7276
7346
  token: config.token,
7277
7347
  namespace: config.namespace,
7278
- poolName: config.envoy.poolName,
7279
- startServices: resolveServicesBinary && config.startServices,
7348
+ poolName: config.node.poolName,
7349
+ startServices: resolveNativeBinaries && config.startServices,
7280
7350
  handleInspectorHttpInRuntime: true,
7281
7351
  serverlessBasePath: config.serverless.basePath,
7282
7352
  serverlessPackageVersion: VERSION,
@@ -7286,26 +7356,30 @@ async function buildServeConfig(config, resolveServicesBinary = true) {
7286
7356
  serverlessValidateEndpoint: config.validateServerlessEndpoint,
7287
7357
  serverlessMaxStartPayloadBytes: config.serverless.maxStartPayloadBytes
7288
7358
  };
7289
- try {
7290
- const { getEnginePath } = await loadEngineCli();
7291
- serveConfig.engineBinaryPath = getEnginePath();
7292
- } catch (error) {
7293
- logger2().warn({
7294
- 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",
7295
- error: stringifyError(error)
7296
- });
7297
- }
7298
- if (resolveServicesBinary && config.startServices) {
7359
+ if (resolveNativeBinaries) {
7299
7360
  try {
7300
- const { getServicesPath } = await loadServices();
7301
- serveConfig.servicesBinaryPath = getServicesPath();
7361
+ const { getEnginePath } = await loadEngineCli();
7362
+ serveConfig.engineBinaryPath = getEnginePath();
7302
7363
  } catch (error) {
7303
7364
  logger2().warn({
7304
- 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",
7365
+ 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",
7305
7366
  error: stringifyError(error)
7306
7367
  });
7307
7368
  }
7308
7369
  }
7370
+ if (resolveNativeBinaries && config.startServices) {
7371
+ const servicesBinary = getEnvUniversal("RIVET_SERVICES_BINARY");
7372
+ if (servicesBinary) {
7373
+ serveConfig.servicesBinaryPath = servicesBinary;
7374
+ } else {
7375
+ try {
7376
+ const { getServicesPath } = await loadServices();
7377
+ serveConfig.servicesBinaryPath = getServicesPath();
7378
+ } catch (error) {
7379
+ throw servicesBinaryUnavailable(error);
7380
+ }
7381
+ }
7382
+ }
7309
7383
  serveConfig.engineHost = config.engineHost;
7310
7384
  serveConfig.enginePort = config.enginePort;
7311
7385
  if ((_a = config.test) == null ? void 0 : _a.enabled) {
@@ -7345,6 +7419,11 @@ async function buildConfiguredRegistry(config) {
7345
7419
 
7346
7420
  // src/registry/index.ts
7347
7421
  var REGISTRY_READY_TIMEOUT_MS = 3e4;
7422
+ var LOCAL_ENGINE_READY_TIMEOUT_MS = 6e4;
7423
+ var LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS = 4e3;
7424
+ function rejectServerless() {
7425
+ throw new Error("serverless is disabled in this version");
7426
+ }
7348
7427
  function signalExitCode(signal) {
7349
7428
  switch (signal) {
7350
7429
  case "SIGINT":
@@ -7449,6 +7528,7 @@ var Registry = class {
7449
7528
  */
7450
7529
  #ensureServerlessPoolConfigured(config) {
7451
7530
  if (!config.configurePool) return void 0;
7531
+ rejectServerless();
7452
7532
  if (!this.#configureServerlessPoolPromise) {
7453
7533
  this.#configureServerlessPoolPromise = configureServerlessPool(
7454
7534
  config
@@ -7473,6 +7553,7 @@ var Registry = class {
7473
7553
  */
7474
7554
  async handler(request) {
7475
7555
  var _a;
7556
+ rejectServerless();
7476
7557
  const config = this.parseConfig();
7477
7558
  this.#printWelcome(config, "serverless");
7478
7559
  if (!this.#runtimeServerlessPromise) {
@@ -7634,6 +7715,7 @@ var Registry = class {
7634
7715
  * ```
7635
7716
  */
7636
7717
  serve() {
7718
+ rejectServerless();
7637
7719
  return {
7638
7720
  fetch: (request) => this.handler(request)
7639
7721
  };
@@ -7658,6 +7740,9 @@ var Registry = class {
7658
7740
  * ```
7659
7741
  */
7660
7742
  async listen(opts = {}) {
7743
+ if (!opts.application) {
7744
+ rejectServerless();
7745
+ }
7661
7746
  const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3e3;
7662
7747
  const publicDir = opts.publicDir ?? getRivetkitPublicDir();
7663
7748
  const config = this.parseConfig();
@@ -7758,6 +7843,7 @@ var Registry = class {
7758
7843
  * Returns serverless metadata suitable for mounting in a user-owned router.
7759
7844
  */
7760
7845
  async #metadataRoute() {
7846
+ rejectServerless();
7761
7847
  const configured = await this.#activeConfiguredRegistry();
7762
7848
  if (!configured) {
7763
7849
  return new Response("registry not started\n", {
@@ -7818,18 +7904,18 @@ var Registry = class {
7818
7904
  #startEnvoy(config, printWelcome) {
7819
7905
  var _a;
7820
7906
  if (!this.#runtimeServePromise) {
7821
- const configuredEnvoyVersion = (_a = this.#config.envoy) == null ? void 0 : _a.version;
7907
+ const configuredEnvoyVersion = (_a = this.#config.node) == null ? void 0 : _a.version;
7822
7908
  const envoyVersionSource = configuredEnvoyVersion !== void 0 ? "config" : getRivetEnvoyVersion() !== void 0 ? "environment" : "default";
7823
7909
  logger2().info({
7824
7910
  msg: "starting rivetkit envoy",
7825
7911
  rivetkitVersion: VERSION,
7826
- envoyVersion: config.envoy.version,
7912
+ envoyVersion: config.node.version,
7827
7913
  envoyVersionSource
7828
7914
  });
7829
7915
  if (envoyVersionSource === "default" && getNodeEnv() === "production") {
7830
7916
  logger2().error({
7831
- 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",
7832
- envoyVersion: config.envoy.version,
7917
+ 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",
7918
+ envoyVersion: config.node.version,
7833
7919
  envoyVersionSource
7834
7920
  });
7835
7921
  }
@@ -7841,7 +7927,10 @@ var Registry = class {
7841
7927
  }
7842
7928
  );
7843
7929
  this.#runtimeServePromise = this.#runtimeServeLifecyclePromise.catch((error) => {
7844
- logger2().warn({ error }, "runtime registry serve errored");
7930
+ logger2().error({ error }, "runtime registry serve errored");
7931
+ if (typeof process !== "undefined" && typeof process.exit === "function") {
7932
+ process.exit(1);
7933
+ }
7845
7934
  });
7846
7935
  this.#installSignalHandlers(config);
7847
7936
  }
@@ -7871,7 +7960,7 @@ var Registry = class {
7871
7960
  finishShutdownSignal(signal);
7872
7961
  return;
7873
7962
  }
7874
- this.#shutdownInFlight = this.#drain(config).catch((err) => {
7963
+ this.#shutdownInFlight = this.#drain(config, true).catch((err) => {
7875
7964
  logger2().warn({ err }, "shutdown error");
7876
7965
  }).then(() => {
7877
7966
  this.#removeSignalHandlers();
@@ -7907,12 +7996,18 @@ var Registry = class {
7907
7996
  });
7908
7997
  return this.#shutdownInFlight;
7909
7998
  }
7910
- async #drain(config) {
7999
+ async #drain(config, signalDriven = false) {
7911
8000
  var _a;
7912
8001
  const modeAPromise = this.#runtimeServeConfiguredPromise;
7913
8002
  const modeBPromise = this.#runtimeServerlessPromise;
7914
8003
  const runtimes = /* @__PURE__ */ new Set();
7915
- const gracePeriodMs = ((_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs) ?? await this.#actorStopThresholdMs(modeAPromise ?? modeBPromise) ?? 30 * 60 * 1e3;
8004
+ const localDevSignal = signalDriven && getNodeEnv() !== "production" && config.engineSpawn && config.endpoint !== void 0 && isLocalEngineEndpoint(config.endpoint);
8005
+ let gracePeriodMs = (_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs;
8006
+ if (gracePeriodMs === void 0) {
8007
+ gracePeriodMs = localDevSignal ? LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS : await this.#actorStopThresholdMs(
8008
+ modeAPromise ?? modeBPromise
8009
+ ) ?? 30 * 60 * 1e3;
8010
+ }
7916
8011
  const drain = async () => {
7917
8012
  const registries = [];
7918
8013
  if (modeAPromise !== void 0) {
@@ -8017,12 +8112,16 @@ var Registry = class {
8017
8112
  );
8018
8113
  }
8019
8114
  if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
8020
- if (getRivetkitRuntimeMode() === "serverless") {
8021
- return Promise.reject(
8022
- new Error(
8023
- "registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request"
8024
- )
8025
- );
8115
+ try {
8116
+ if (getRivetkitRuntimeMode() === "serverless") {
8117
+ return Promise.reject(
8118
+ new Error(
8119
+ "registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request"
8120
+ )
8121
+ );
8122
+ }
8123
+ } catch (error) {
8124
+ return Promise.reject(error);
8026
8125
  }
8027
8126
  const config = this.parseConfig();
8028
8127
  if (config.runtime === "wasm") {
@@ -8038,16 +8137,17 @@ var Registry = class {
8038
8137
  if (!configuredRegistryPromise || !serveLifecyclePromise) {
8039
8138
  throw new Error("registry envoy startup did not initialize");
8040
8139
  }
8140
+ const readyTimeoutMs = config.engineSpawn && config.endpoint !== void 0 && isLocalEngineEndpoint(config.endpoint) ? LOCAL_ENGINE_READY_TIMEOUT_MS : REGISTRY_READY_TIMEOUT_MS;
8041
8141
  let timeout;
8042
8142
  const timeoutPromise = new Promise((_resolve, reject) => {
8043
8143
  var _a;
8044
8144
  timeout = setTimeout(
8045
8145
  () => reject(
8046
8146
  new Error(
8047
- `RivetKit registry did not register with the Engine within ${REGISTRY_READY_TIMEOUT_MS}ms`
8147
+ `RivetKit registry did not register with the Engine within ${readyTimeoutMs}ms`
8048
8148
  )
8049
8149
  ),
8050
- REGISTRY_READY_TIMEOUT_MS
8150
+ readyTimeoutMs
8051
8151
  );
8052
8152
  (_a = timeout.unref) == null ? void 0 : _a.call(timeout);
8053
8153
  });