rivetkit 2.3.0-rc.5 → 2.3.0-rc.6

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 (113) hide show
  1. package/dist/browser/client.d.ts +21 -18
  2. package/dist/browser/client.js +735 -170
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +1 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +4 -2
  7. package/dist/tsup/actor/errors.cjs.map +1 -1
  8. package/dist/tsup/actor/errors.d.cts +1 -74
  9. package/dist/tsup/actor/errors.d.ts +1 -74
  10. package/dist/tsup/actor/errors.js +3 -1
  11. package/dist/tsup/agent-os/index.cjs +1 -1
  12. package/dist/tsup/agent-os/index.cjs.map +1 -1
  13. package/dist/tsup/agent-os/index.d.cts +18 -7
  14. package/dist/tsup/agent-os/index.d.ts +18 -7
  15. package/dist/tsup/agent-os/index.js +1 -1
  16. package/dist/tsup/agent-os/index.js.map +1 -1
  17. package/dist/tsup/{chunk-2GANBXVP.cjs → chunk-2G64KSZQ.cjs} +10 -10
  18. package/dist/tsup/{chunk-2GANBXVP.cjs.map → chunk-2G64KSZQ.cjs.map} +1 -1
  19. package/dist/tsup/{chunk-N2DQSJIW.js → chunk-6S25NVAP.js} +13 -46
  20. package/dist/tsup/chunk-6S25NVAP.js.map +1 -0
  21. package/dist/tsup/{chunk-NATOT3ET.js → chunk-CAF6JDJE.js} +4 -4
  22. package/dist/tsup/{chunk-PGYEMIOE.js → chunk-DEO7MMWQ.js} +2 -2
  23. package/dist/tsup/{chunk-SULB574D.js → chunk-EMO6E3PJ.js} +3 -3
  24. package/dist/tsup/{chunk-FTZIZ3JG.cjs → chunk-ENK7C66G.cjs} +838 -236
  25. package/dist/tsup/chunk-ENK7C66G.cjs.map +1 -0
  26. package/dist/tsup/{chunk-JY73X7VU.js → chunk-FLODVLYW.js} +690 -88
  27. package/dist/tsup/chunk-FLODVLYW.js.map +1 -0
  28. package/dist/tsup/{chunk-OVJX4IFY.cjs → chunk-HTR4YLNT.cjs} +4 -4
  29. package/dist/tsup/{chunk-OVJX4IFY.cjs.map → chunk-HTR4YLNT.cjs.map} +1 -1
  30. package/dist/tsup/{chunk-LELRJK66.cjs → chunk-JALSAX7Z.cjs} +3 -3
  31. package/dist/tsup/{chunk-LELRJK66.cjs.map → chunk-JALSAX7Z.cjs.map} +1 -1
  32. package/dist/tsup/{chunk-JRCZDHXT.cjs → chunk-K5BA2LEO.cjs} +19 -52
  33. package/dist/tsup/chunk-K5BA2LEO.cjs.map +1 -0
  34. package/dist/tsup/{chunk-K34B3OVG.js → chunk-KIWH5H3K.js} +30 -9
  35. package/dist/tsup/chunk-KIWH5H3K.js.map +1 -0
  36. package/dist/tsup/{chunk-NW2J4SOL.cjs → chunk-LIXXFXVR.cjs} +5 -5
  37. package/dist/tsup/{chunk-NW2J4SOL.cjs.map → chunk-LIXXFXVR.cjs.map} +1 -1
  38. package/dist/tsup/{chunk-HR547GVH.cjs → chunk-M5C7YNI5.cjs} +8 -8
  39. package/dist/tsup/{chunk-HR547GVH.cjs.map → chunk-M5C7YNI5.cjs.map} +1 -1
  40. package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-QAZLM4WT.cjs} +31 -10
  41. package/dist/tsup/chunk-QAZLM4WT.cjs.map +1 -0
  42. package/dist/tsup/{chunk-LDTT6WKJ.js → chunk-RTC2AZGB.js} +2 -2
  43. package/dist/tsup/{chunk-UXTP4EBU.js → chunk-ZI5QJMKO.js} +2 -2
  44. package/dist/tsup/client/mod.cjs +7 -7
  45. package/dist/tsup/client/mod.d.cts +3 -4
  46. package/dist/tsup/client/mod.d.ts +3 -4
  47. package/dist/tsup/client/mod.js +6 -6
  48. package/dist/tsup/common/log.cjs +3 -3
  49. package/dist/tsup/common/log.js +2 -2
  50. package/dist/tsup/common/websocket.cjs +4 -4
  51. package/dist/tsup/common/websocket.js +3 -3
  52. package/dist/tsup/{config-CvQUtDp9.d.ts → config-0Ta55UV0.d.ts} +10 -9
  53. package/dist/tsup/{config-C-a9vrke.d.cts → config-Ca8dN4cS.d.cts} +10 -9
  54. package/dist/tsup/{context-A7R0bsZL.d.ts → context-B_IWbWne.d.ts} +1 -1
  55. package/dist/tsup/{context-CA3r-pf2.d.cts → context-CUrQ9MHc.d.cts} +1 -1
  56. package/dist/tsup/inspector/mod.cjs +6 -6
  57. package/dist/tsup/inspector/mod.js +5 -5
  58. package/dist/tsup/mod.cjs +252 -207
  59. package/dist/tsup/mod.cjs.map +1 -1
  60. package/dist/tsup/mod.d.cts +4 -5
  61. package/dist/tsup/mod.d.ts +4 -5
  62. package/dist/tsup/mod.js +183 -138
  63. package/dist/tsup/mod.js.map +1 -1
  64. package/dist/tsup/test/mod.cjs +10 -10
  65. package/dist/tsup/test/mod.d.cts +2 -3
  66. package/dist/tsup/test/mod.d.ts +2 -3
  67. package/dist/tsup/test/mod.js +6 -6
  68. package/dist/tsup/utils-DVekpm4I.d.cts +103 -0
  69. package/dist/tsup/utils-DVekpm4I.d.ts +103 -0
  70. package/dist/tsup/utils.cjs +3 -3
  71. package/dist/tsup/utils.d.cts +1 -1
  72. package/dist/tsup/utils.d.ts +1 -1
  73. package/dist/tsup/utils.js +2 -2
  74. package/dist/tsup/workflow/mod.cjs +9 -9
  75. package/dist/tsup/workflow/mod.d.cts +4 -5
  76. package/dist/tsup/workflow/mod.d.ts +4 -5
  77. package/dist/tsup/workflow/mod.js +5 -5
  78. package/package.json +8 -8
  79. package/src/actor/errors.ts +53 -7
  80. package/src/client/actor-conn.ts +52 -29
  81. package/src/client/actor-handle.ts +57 -23
  82. package/src/client/errors.ts +2 -1
  83. package/src/client/raw-utils.ts +2 -4
  84. package/src/client/utils.ts +32 -3
  85. package/src/common/actor-router-consts.ts +4 -0
  86. package/src/common/bare/generated/client-protocol/v4.ts +599 -0
  87. package/src/common/client-protocol-versioned.ts +125 -18
  88. package/src/common/client-protocol-zod.ts +7 -0
  89. package/src/common/client-protocol.ts +1 -1
  90. package/src/common/database/native-database.test.ts +35 -0
  91. package/src/common/database/native-database.ts +8 -4
  92. package/src/common/router.ts +38 -8
  93. package/src/common/utils.ts +9 -52
  94. package/src/drivers/engine/actor-driver.ts +18 -17
  95. package/src/registry/config/index.ts +3 -5
  96. package/src/registry/index.ts +156 -19
  97. package/src/registry/napi-runtime.ts +44 -6
  98. package/src/registry/native.ts +5 -152
  99. package/src/registry/runtime.ts +16 -5
  100. package/src/registry/wasm-runtime.ts +22 -2
  101. package/dist/tsup/chunk-FTZIZ3JG.cjs.map +0 -1
  102. package/dist/tsup/chunk-JRCZDHXT.cjs.map +0 -1
  103. package/dist/tsup/chunk-JY73X7VU.js.map +0 -1
  104. package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
  105. package/dist/tsup/chunk-N2DQSJIW.js.map +0 -1
  106. package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
  107. package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
  108. package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
  109. /package/dist/tsup/{chunk-NATOT3ET.js.map → chunk-CAF6JDJE.js.map} +0 -0
  110. /package/dist/tsup/{chunk-PGYEMIOE.js.map → chunk-DEO7MMWQ.js.map} +0 -0
  111. /package/dist/tsup/{chunk-SULB574D.js.map → chunk-EMO6E3PJ.js.map} +0 -0
  112. /package/dist/tsup/{chunk-LDTT6WKJ.js.map → chunk-RTC2AZGB.js.map} +0 -0
  113. /package/dist/tsup/{chunk-UXTP4EBU.js.map → chunk-ZI5QJMKO.js.map} +0 -0
package/dist/tsup/mod.cjs CHANGED
@@ -8,7 +8,7 @@
8
8
  var _chunkWQ4HNA4Wcjs = require('./chunk-WQ4HNA4W.cjs');
9
9
 
10
10
 
11
- var _chunkOVJX4IFYcjs = require('./chunk-OVJX4IFY.cjs');
11
+ var _chunkHTR4YLNTcjs = require('./chunk-HTR4YLNT.cjs');
12
12
 
13
13
 
14
14
 
@@ -18,11 +18,7 @@ var _chunkOVJX4IFYcjs = require('./chunk-OVJX4IFY.cjs');
18
18
 
19
19
 
20
20
 
21
-
22
-
23
-
24
-
25
- var _chunkFTZIZ3JGcjs = require('./chunk-FTZIZ3JG.cjs');
21
+ var _chunkENK7C66Gcjs = require('./chunk-ENK7C66G.cjs');
26
22
 
27
23
 
28
24
 
@@ -35,11 +31,9 @@ var _chunkLD5YASJUcjs = require('./chunk-LD5YASJU.cjs');
35
31
 
36
32
 
37
33
 
38
-
39
-
40
- var _chunkNW2J4SOLcjs = require('./chunk-NW2J4SOL.cjs');
34
+ var _chunkLIXXFXVRcjs = require('./chunk-LIXXFXVR.cjs');
41
35
  require('./chunk-2NDZ7JCR.cjs');
42
- require('./chunk-LELRJK66.cjs');
36
+ require('./chunk-JALSAX7Z.cjs');
43
37
 
44
38
 
45
39
 
@@ -63,7 +57,7 @@ require('./chunk-LELRJK66.cjs');
63
57
 
64
58
 
65
59
 
66
- var _chunkJRCZDHXTcjs = require('./chunk-JRCZDHXT.cjs');
60
+ var _chunkK5BA2LEOcjs = require('./chunk-K5BA2LEO.cjs');
67
61
 
68
62
 
69
63
 
@@ -74,11 +68,11 @@ var _chunkJRCZDHXTcjs = require('./chunk-JRCZDHXT.cjs');
74
68
 
75
69
 
76
70
 
77
- var _chunkV3QNBJ7Ncjs = require('./chunk-V3QNBJ7N.cjs');
71
+ var _chunkQAZLM4WTcjs = require('./chunk-QAZLM4WT.cjs');
78
72
 
79
73
  // src/actor/log.ts
80
74
  function loggerWithoutContext() {
81
- return _chunkJRCZDHXTcjs.getLogger.call(void 0, "actor-runtime");
75
+ return _chunkK5BA2LEOcjs.getLogger.call(void 0, "actor-runtime");
82
76
  }
83
77
 
84
78
  // src/actor/definition.ts
@@ -193,7 +187,7 @@ function validateSchemaSync(schemas, key, data) {
193
187
  if (isStandardSchema(schema)) {
194
188
  const result = schema["~standard"].validate(data);
195
189
  if (isPromiseLike(result)) {
196
- throw _chunkV3QNBJ7Ncjs.unsupportedFeature.call(void 0, "async schema validation");
190
+ throw _chunkQAZLM4WTcjs.unsupportedFeature.call(void 0, "async schema validation");
197
191
  }
198
192
  if (result.issues) {
199
193
  return { success: false, issues: [...result.issues] };
@@ -210,7 +204,7 @@ function validateSchemaSync(schemas, key, data) {
210
204
  var _ws = require('hono/ws');
211
205
  var _virtualwebsocket = require('@rivetkit/virtual-websocket');
212
206
  function logger() {
213
- return _chunkJRCZDHXTcjs.getLogger.call(void 0, "inline-websocket-adapter");
207
+ return _chunkK5BA2LEOcjs.getLogger.call(void 0, "inline-websocket-adapter");
214
208
  }
215
209
  var InlineWebSocketAdapter = class {
216
210
  #handler;
@@ -366,7 +360,7 @@ var ENGINE_ENDPOINT = `http://127.0.0.1:${ENGINE_PORT}`;
366
360
 
367
361
  // src/registry/log.ts
368
362
  function logger2() {
369
- return _chunkJRCZDHXTcjs.getLogger.call(void 0, "registry");
363
+ return _chunkK5BA2LEOcjs.getLogger.call(void 0, "registry");
370
364
  }
371
365
 
372
366
  // src/serverless/configure.ts
@@ -403,8 +397,8 @@ async function configureServerlessPool(config) {
403
397
  throw new Error("configurePool is required for serverless configuration");
404
398
  }
405
399
  const customConfig = config.configurePool;
406
- const clientConfig = _chunkFTZIZ3JGcjs.convertRegistryConfigToClientConfig.call(void 0, config);
407
- const dcsRes = await _chunkFTZIZ3JGcjs.getDatacenters.call(void 0, clientConfig);
400
+ const clientConfig = _chunkENK7C66Gcjs.convertRegistryConfigToClientConfig.call(void 0, config);
401
+ const dcsRes = await _chunkENK7C66Gcjs.getDatacenters.call(void 0, clientConfig);
408
402
  const poolName = _nullishCoalesce(customConfig.name, () => ( "default"));
409
403
  const serverlessToken = _nullishCoalesce(config.token, () => ( config.publicToken));
410
404
  const headers = {
@@ -426,7 +420,7 @@ async function configureServerlessPool(config) {
426
420
  metadata: _nullishCoalesce(customConfig.metadata, () => ( {})),
427
421
  drain_on_version_upgrade: _nullishCoalesce(customConfig.drainOnVersionUpgrade, () => ( true))
428
422
  };
429
- await _chunkFTZIZ3JGcjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
423
+ await _chunkENK7C66Gcjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
430
424
  datacenters: Object.fromEntries(
431
425
  dcsRes.datacenters.map((dc) => [dc.name, serverlessConfig])
432
426
  )
@@ -443,7 +437,7 @@ async function configureServerlessPool(config) {
443
437
  logger2().warn({
444
438
  msg: "serverless pool configuration attempt failed",
445
439
  attempts,
446
- error: _chunkJRCZDHXTcjs.stringifyError.call(void 0, error)
440
+ error: _chunkK5BA2LEOcjs.stringifyError.call(void 0, error)
447
441
  });
448
442
  await sleep(CONFIGURE_RETRY_DELAY_MS);
449
443
  }
@@ -451,7 +445,7 @@ async function configureServerlessPool(config) {
451
445
  logger2().error({
452
446
  msg: "failed to configure serverless pool, validate endpoint is configured correctly then restart this process",
453
447
  attempts,
454
- error: _chunkJRCZDHXTcjs.stringifyError.call(void 0, lastError)
448
+ error: _chunkK5BA2LEOcjs.stringifyError.call(void 0, lastError)
455
449
  });
456
450
  throw lastError;
457
451
  }
@@ -463,20 +457,20 @@ var _zod = require('zod');
463
457
  var _v4 = require('zod/v4');
464
458
  var warnedMissingVersion = false;
465
459
  var EnvoyConfigSchema = _v4.z.object({
466
- poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkJRCZDHXTcjs.getRivetPool.call(void 0, ), () => ( "default"))),
460
+ poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkK5BA2LEOcjs.getRivetPool.call(void 0, ), () => ( "default"))),
467
461
  version: _v4.z.number().default(() => {
468
- const version = _chunkJRCZDHXTcjs.getRivetEnvoyVersion.call(void 0, );
462
+ const version = _chunkK5BA2LEOcjs.getRivetEnvoyVersion.call(void 0, );
469
463
  if (version !== void 0) return version;
470
- if (_chunkJRCZDHXTcjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
464
+ if (_chunkK5BA2LEOcjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
471
465
  warnedMissingVersion = true;
472
- _chunkJRCZDHXTcjs.getLogger.call(void 0, "rivetkit").error(
466
+ _chunkK5BA2LEOcjs.getLogger.call(void 0, "rivetkit").error(
473
467
  "RIVET_ENVOY_VERSION is not set. Actors will not be versioned, which means they won't be drained on deploy. This is only needed when self-hosting or using a custom envoy (not needed for Rivet Compute). Set this as a build arg in your Dockerfile. See https://rivet.dev/docs/actors/versions"
474
468
  );
475
469
  }
476
470
  return 1;
477
471
  }),
478
472
  // Deprecated.
479
- totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkJRCZDHXTcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
473
+ totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkK5BA2LEOcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
480
474
  envoyKey: _v4.z.string().optional()
481
475
  });
482
476
 
@@ -514,7 +508,7 @@ var ServerlessConfigSchema = _v4.z.object({
514
508
  *
515
509
  * Can also be set via RIVET_PUBLIC_ENDPOINT environment variable.
516
510
  */
517
- publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkJRCZDHXTcjs.getRivetPublicEndpoint.call(void 0, )))),
511
+ publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkK5BA2LEOcjs.getRivetPublicEndpoint.call(void 0, )))),
518
512
  /**
519
513
  * Token that clients should use when connecting via the public endpoint.
520
514
  *
@@ -522,7 +516,7 @@ var ServerlessConfigSchema = _v4.z.object({
522
516
  *
523
517
  * Can also be specified in the publicEndpoint URL as `https://namespace:token@host`.
524
518
  */
525
- publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkJRCZDHXTcjs.getRivetPublicToken.call(void 0, ))))
519
+ publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkK5BA2LEOcjs.getRivetPublicToken.call(void 0, ))))
526
520
  // There is no publicNamespace config option because the frontend and backend
527
521
  // cannot use different namespaces. The namespace is extracted from the
528
522
  // publicEndpoint URL auth syntax if provided.
@@ -576,7 +570,7 @@ var RegistryConfigSchema = _zod.z.object({
576
570
  * Runtime binding to use for RivetKit core.
577
571
  * */
578
572
  runtime: RuntimeKindSchema.optional().transform((val, ctx) => {
579
- const rawRuntime = _nullishCoalesce(val, () => ( _chunkJRCZDHXTcjs.getRivetkitRuntime.call(void 0, )));
573
+ const rawRuntime = _nullishCoalesce(val, () => ( _chunkK5BA2LEOcjs.getRivetkitRuntime.call(void 0, )));
580
574
  if (rawRuntime === void 0) {
581
575
  return "auto";
582
576
  }
@@ -613,7 +607,7 @@ var RegistryConfigSchema = _zod.z.object({
613
607
  * */
614
608
  logging: _zod.z.object({
615
609
  baseLogger: _zod.z.custom().optional(),
616
- level: _chunkJRCZDHXTcjs.LogLevelSchema.optional()
610
+ level: _chunkK5BA2LEOcjs.LogLevelSchema.optional()
617
611
  }).optional().default(() => ({})),
618
612
  // MARK: Routing
619
613
  // // This is a function to allow for lazy configuration of upgradeWebSocket on the
@@ -631,9 +625,9 @@ var RegistryConfigSchema = _zod.z.object({
631
625
  *
632
626
  * Can also be set via RIVET_ENDPOINT environment variables.
633
627
  */
634
- endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkJRCZDHXTcjs.getRivetEngine.call(void 0, ))), () => ( _chunkJRCZDHXTcjs.getRivetEndpoint.call(void 0, )))),
635
- token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkJRCZDHXTcjs.getRivetToken.call(void 0, )))),
636
- namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkJRCZDHXTcjs.getRivetNamespace.call(void 0, )))),
628
+ endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkK5BA2LEOcjs.getRivetEngine.call(void 0, ))), () => ( _chunkK5BA2LEOcjs.getRivetEndpoint.call(void 0, )))),
629
+ token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkK5BA2LEOcjs.getRivetToken.call(void 0, )))),
630
+ namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkK5BA2LEOcjs.getRivetNamespace.call(void 0, )))),
637
631
  headers: _zod.z.record(_zod.z.string(), _zod.z.string()).optional().default({}),
638
632
  // MARK: Client
639
633
  // TODO:
@@ -673,9 +667,9 @@ var RegistryConfigSchema = _zod.z.object({
673
667
  *
674
668
  * Starts the full Rust engine process locally.
675
669
  */
676
- startEngine: _zod.z.boolean().default(() => _chunkJRCZDHXTcjs.getRivetRunEngine.call(void 0, )),
670
+ startEngine: _zod.z.boolean().default(() => _chunkK5BA2LEOcjs.getRivetRunEngine.call(void 0, )),
677
671
  /** @experimental */
678
- engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkJRCZDHXTcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkJRCZDHXTcjs.VERSION))),
672
+ engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkK5BA2LEOcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkK5BA2LEOcjs.VERSION))),
679
673
  /**
680
674
  * @experimental
681
675
  *
@@ -706,12 +700,12 @@ var RegistryConfigSchema = _zod.z.object({
706
700
  shutdown: _zod.z.object({
707
701
  /**
708
702
  * Wait this many milliseconds for the serve promise to resolve
709
- * after calling `CoreRegistry::shutdown()`. Defaults to 30s,
710
- * matching Kubernetes `terminationGracePeriodSeconds`.
703
+ * after calling `CoreRegistry::shutdown()`. Defaults to the
704
+ * engine-provided actor stop threshold once the envoy connects.
711
705
  *
712
706
  * Must be >= rivetkit-core's drain timeout (20s) + margin.
713
707
  */
714
- gracePeriodMs: _zod.z.number().int().min(1e3).optional().default(3e4),
708
+ gracePeriodMs: _zod.z.number().int().min(1e3).optional(),
715
709
  /**
716
710
  * If true, rivetkit will not install SIGINT/SIGTERM handlers.
717
711
  * Use when the host application owns signal policy and will
@@ -719,12 +713,11 @@ var RegistryConfigSchema = _zod.z.object({
719
713
  */
720
714
  disableSignalHandlers: _zod.z.boolean().optional().default(false)
721
715
  }).optional().default(() => ({
722
- gracePeriodMs: 3e4,
723
716
  disableSignalHandlers: false
724
717
  }))
725
718
  }).transform((config, ctx) => {
726
719
  var _a, _b, _c;
727
- const isDevEnv = _chunkJRCZDHXTcjs.isDev.call(void 0, );
720
+ const isDevEnv = _chunkK5BA2LEOcjs.isDev.call(void 0, );
728
721
  const sqliteBackend = _nullishCoalesce(((_a = config.sqlite) == null ? void 0 : _a.backend), () => ( ((_b = config.test) == null ? void 0 : _b.sqliteBackend)));
729
722
  if (config.runtime === "wasm" && sqliteBackend === "local") {
730
723
  ctx.addIssue({
@@ -734,7 +727,7 @@ var RegistryConfigSchema = _zod.z.object({
734
727
  });
735
728
  }
736
729
  const sqlite = config.runtime === "wasm" && config.sqlite === void 0 ? { backend: "remote" } : config.sqlite;
737
- const parsedEndpoint = config.endpoint ? _chunkFTZIZ3JGcjs.tryParseEndpoint.call(void 0, ctx, {
730
+ const parsedEndpoint = config.endpoint ? _chunkENK7C66Gcjs.tryParseEndpoint.call(void 0, ctx, {
738
731
  endpoint: config.endpoint,
739
732
  path: ["endpoint"],
740
733
  namespace: config.namespace,
@@ -758,7 +751,7 @@ var RegistryConfigSchema = _zod.z.object({
758
751
  );
759
752
  const namespace = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.namespace), () => ( config.namespace)), () => ( "default"));
760
753
  const token = _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.token), () => ( config.token));
761
- const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkFTZIZ3JGcjs.tryParseEndpoint.call(void 0, ctx, {
754
+ const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkENK7C66Gcjs.tryParseEndpoint.call(void 0, ctx, {
762
755
  endpoint: config.serverless.publicEndpoint,
763
756
  path: ["serverless", "publicEndpoint"]
764
757
  }) : void 0;
@@ -886,7 +879,7 @@ var DocRegistryConfigSchema = _zod.z.object({
886
879
  noWelcome: _zod.z.boolean().optional().describe("Disable the welcome message on startup. Default: false"),
887
880
  sqlite: DocSqliteConfigSchema,
888
881
  logging: _zod.z.object({
889
- level: _chunkJRCZDHXTcjs.LogLevelSchema.optional().describe(
882
+ level: _chunkK5BA2LEOcjs.LogLevelSchema.optional().describe(
890
883
  "Log level for RivetKit. Default: 'warn'"
891
884
  )
892
885
  }).optional().describe("Logging configuration."),
@@ -930,7 +923,8 @@ function shouldAttachNativeKvError(message) {
930
923
  }
931
924
  function enrichNativeDatabaseError(database, error) {
932
925
  var _a;
933
- const bridged = typeof error === "string" ? _chunkV3QNBJ7Ncjs.decodeBridgeRivetError.call(void 0, error) : error instanceof Error ? _chunkV3QNBJ7Ncjs.decodeBridgeRivetError.call(void 0, error.message) : void 0;
926
+ const bridgeReason = typeof error === "string" ? error : error instanceof Error ? error.message : void 0;
927
+ const bridged = bridgeReason === void 0 ? void 0 : _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, bridgeReason);
934
928
  if (bridged) {
935
929
  throw bridged;
936
930
  }
@@ -1280,11 +1274,31 @@ var NapiCoreRuntime = (_class = class {
1280
1274
  async shutdownRegistry(registry) {
1281
1275
  await asNativeRegistry(registry).shutdown();
1282
1276
  }
1283
- async registryDiagnostics(registry) {
1284
- const diagnostics = await asNativeRegistry(registry).diagnostics();
1277
+ async registryActorStopThresholdMs(registry) {
1278
+ return await _asyncNullishCoalesce(await asNativeRegistry(registry).actorStopThresholdMs(), async () => ( void 0));
1279
+ }
1280
+ async registryHealth(registry) {
1281
+ const response = await asNativeRegistry(registry).health();
1282
+ return {
1283
+ status: response.status,
1284
+ headers: response.headers,
1285
+ body: response.body
1286
+ };
1287
+ }
1288
+ async registryMetadata(registry) {
1289
+ const response = asNativeRegistry(registry).metadata();
1290
+ return {
1291
+ status: response.status,
1292
+ headers: response.headers,
1293
+ body: response.body
1294
+ };
1295
+ }
1296
+ async registryMetrics(registry) {
1297
+ const response = asNativeRegistry(registry).metrics();
1285
1298
  return {
1286
- mode: diagnostics.mode,
1287
- envoyActiveActorCount: diagnostics.envoyActiveActorCount
1299
+ status: response.status,
1300
+ headers: response.headers,
1301
+ body: response.body
1288
1302
  };
1289
1303
  }
1290
1304
  async handleServerlessRequest(registry, req, onStreamEvent, cancelToken, config) {
@@ -1407,6 +1421,9 @@ var NapiCoreRuntime = (_class = class {
1407
1421
  actorWaitUntil(ctx, promise) {
1408
1422
  asNativeActorContext(ctx).waitUntil(promise);
1409
1423
  }
1424
+ async actorWaitForTrackedShutdownWork(ctx) {
1425
+ return await asNativeActorContext(ctx).waitForTrackedShutdownWork();
1426
+ }
1410
1427
  actorKeepAwake(ctx, promise) {
1411
1428
  asNativeActorContext(ctx).keepAwake(promise);
1412
1429
  }
@@ -1658,7 +1675,7 @@ function validateQueueComplete(schemas, name, response) {
1658
1675
  return result.data;
1659
1676
  }
1660
1677
  function validationError(target, issues) {
1661
- return new (0, _chunkV3QNBJ7Ncjs.RivetError)(
1678
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
1662
1679
  "actor",
1663
1680
  "validation_error",
1664
1681
  `Invalid ${target}`,
@@ -1732,16 +1749,16 @@ function normalizeQueueMessage(message) {
1732
1749
  }
1733
1750
  function normalizeWasmBridgeError(error) {
1734
1751
  if (typeof error === "string") {
1735
- return _nullishCoalesce(_chunkV3QNBJ7Ncjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
1752
+ return _nullishCoalesce(_chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
1736
1753
  }
1737
1754
  if (error instanceof Error) {
1738
- const bridged = _chunkV3QNBJ7Ncjs.decodeBridgeRivetError.call(void 0, error.message);
1755
+ const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.message);
1739
1756
  if (bridged) {
1740
1757
  return bridged;
1741
1758
  }
1742
1759
  }
1743
1760
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
1744
- const bridged = _chunkV3QNBJ7Ncjs.decodeBridgeRivetError.call(void 0, error.reason);
1761
+ const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.reason);
1745
1762
  if (bridged) {
1746
1763
  return bridged;
1747
1764
  }
@@ -1763,7 +1780,7 @@ function callWasmSync(invoke) {
1763
1780
  }
1764
1781
  }
1765
1782
  function unsupportedWasmMethod(method2) {
1766
- throw new (0, _chunkV3QNBJ7Ncjs.RivetError)(
1783
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
1767
1784
  "runtime",
1768
1785
  "unsupported",
1769
1786
  `Unsupported wasm runtime method: ${method2}`,
@@ -1824,8 +1841,18 @@ var WasmCoreRuntime = (_class2 = class {
1824
1841
  async shutdownRegistry(registry) {
1825
1842
  await callWasm(() => asWasmRegistry(registry).shutdown());
1826
1843
  }
1827
- async registryDiagnostics() {
1828
- return { mode: "wasm", envoyActiveActorCount: null };
1844
+ async registryHealth() {
1845
+ return {
1846
+ status: 200,
1847
+ headers: { "content-type": "application/json" },
1848
+ body: new TextEncoder().encode(
1849
+ JSON.stringify({
1850
+ status: "ok",
1851
+ runtime: "rivetkit",
1852
+ version: "wasm"
1853
+ })
1854
+ )
1855
+ };
1829
1856
  }
1830
1857
  async handleServerlessRequest(registry, req, onStreamEvent, cancelToken, config) {
1831
1858
  return await callHandleAsync(
@@ -1974,6 +2001,12 @@ var WasmCoreRuntime = (_class2 = class {
1974
2001
  actorWaitUntil(ctx, promise) {
1975
2002
  callHandle(asWasmActorContext(ctx), "waitUntil", promise);
1976
2003
  }
2004
+ async actorWaitForTrackedShutdownWork(ctx) {
2005
+ return await callHandle(
2006
+ asWasmActorContext(ctx),
2007
+ "waitForTrackedShutdownWork"
2008
+ );
2009
+ }
1977
2010
  actorKeepAwake(ctx, promise) {
1978
2011
  const wasmCtx = asWasmActorContext(ctx);
1979
2012
  const regionId = callHandle(wasmCtx, "beginKeepAwake");
@@ -2248,7 +2281,7 @@ function loadedRuntimeKind(runtime) {
2248
2281
  case "wasm":
2249
2282
  return "wasm";
2250
2283
  }
2251
- throw new (0, _chunkV3QNBJ7Ncjs.RivetError)(
2284
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
2252
2285
  "config",
2253
2286
  "unknown_runtime",
2254
2287
  "RivetKit runtime must be NAPI or wasm.",
@@ -2288,7 +2321,7 @@ function normalizeRuntimeConfigForKind(config, runtimeKind) {
2288
2321
  return config;
2289
2322
  }
2290
2323
  if (sqliteBackendForConfig(config) === "local") {
2291
- throw new (0, _chunkV3QNBJ7Ncjs.RivetError)(
2324
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
2292
2325
  "config",
2293
2326
  "wasm_local_sqlite",
2294
2327
  "WebAssembly runtime cannot use local SQLite. Use remote SQLite instead.",
@@ -2354,14 +2387,14 @@ function getNativeConnPersistState(runtime, ctx, conn) {
2354
2387
  return connState;
2355
2388
  }
2356
2389
  function stateMutationReentrantError() {
2357
- return new (0, _chunkV3QNBJ7Ncjs.RivetError)(
2390
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
2358
2391
  "actor",
2359
2392
  "state_mutation_reentrant",
2360
2393
  "State mutations are not allowed inside onStateChange."
2361
2394
  );
2362
2395
  }
2363
2396
  function databaseNotConfiguredError() {
2364
- return new (0, _chunkV3QNBJ7Ncjs.RivetError)(
2397
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
2365
2398
  "actor",
2366
2399
  "database_not_configured",
2367
2400
  "database is not configured for this actor",
@@ -2369,7 +2402,7 @@ function databaseNotConfiguredError() {
2369
2402
  );
2370
2403
  }
2371
2404
  function stateNotEnabledError() {
2372
- return new (0, _chunkV3QNBJ7Ncjs.RivetError)(
2405
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
2373
2406
  "actor",
2374
2407
  "state_not_enabled",
2375
2408
  "State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.dev/docs/actors/state/#initializing-state)",
@@ -2377,7 +2410,7 @@ function stateNotEnabledError() {
2377
2410
  );
2378
2411
  }
2379
2412
  function nativeClientNotConfiguredError() {
2380
- return new (0, _chunkV3QNBJ7Ncjs.RivetError)(
2413
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
2381
2414
  "native",
2382
2415
  "client_not_configured",
2383
2416
  "native actor client is not configured",
@@ -2385,7 +2418,7 @@ function nativeClientNotConfiguredError() {
2385
2418
  );
2386
2419
  }
2387
2420
  function nativeEndpointNotConfiguredError() {
2388
- return new (0, _chunkV3QNBJ7Ncjs.RivetError)(
2421
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
2389
2422
  "native",
2390
2423
  "endpoint_not_configured",
2391
2424
  "registry endpoint is required for native envoy startup",
@@ -2420,20 +2453,11 @@ function clearNativeRuntimeState(runtime, ctx) {
2420
2453
  callNativeSync(() => runtime.actorClearRuntimeState(ctx));
2421
2454
  }
2422
2455
  async function cleanupNativeSleepRuntimeState(runtime, ctx) {
2456
+ await runtime.actorWaitForTrackedShutdownWork(ctx);
2423
2457
  await closeNativeDatabaseClient(runtime, ctx);
2424
2458
  await closeNativeSqlDatabase(runtime, ctx);
2425
2459
  clearNativeRuntimeState(runtime, ctx);
2426
2460
  }
2427
- async function cleanupDeferredNativeSleepRuntimeState(runtime, ctx, runtimeState) {
2428
- runtimeState.deferSleepCleanupUntilKeepAwakeIdle = false;
2429
- const actorCtx = runtimeState.deferredSleepCleanupActorCtx;
2430
- runtimeState.deferredSleepCleanupActorCtx = void 0;
2431
- try {
2432
- await cleanupNativeSleepRuntimeState(runtime, ctx);
2433
- } finally {
2434
- await (actorCtx == null ? void 0 : actorCtx.dispose());
2435
- }
2436
- }
2437
2461
  function closeNativeSqlDatabase(runtime, ctx) {
2438
2462
  const runtimeState = getNativeRuntimeState(runtime, ctx);
2439
2463
  const database = runtimeState.sql;
@@ -2534,10 +2558,10 @@ function decodeValue(value) {
2534
2558
  if (!value || value.length === 0) {
2535
2559
  return void 0;
2536
2560
  }
2537
- return _chunkNW2J4SOLcjs.decodeCborJsonCompat.call(void 0, value);
2561
+ return _chunkLIXXFXVRcjs.decodeCborJsonCompat.call(void 0, value);
2538
2562
  }
2539
2563
  function encodeValue(value) {
2540
- return _chunkNW2J4SOLcjs.encodeCborCompat.call(void 0, value);
2564
+ return _chunkLIXXFXVRcjs.encodeCborCompat.call(void 0, value);
2541
2565
  }
2542
2566
  function unwrapTsfnPayload(error, payload) {
2543
2567
  if (error !== null && error !== void 0) {
@@ -2547,16 +2571,16 @@ function unwrapTsfnPayload(error, payload) {
2547
2571
  }
2548
2572
  function normalizeNativeBridgeError(error) {
2549
2573
  if (typeof error === "string") {
2550
- return _nullishCoalesce(_chunkV3QNBJ7Ncjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2574
+ return _nullishCoalesce(_chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2551
2575
  }
2552
2576
  if (error instanceof Error) {
2553
- const bridged = _chunkV3QNBJ7Ncjs.decodeBridgeRivetError.call(void 0, error.message);
2577
+ const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.message);
2554
2578
  if (bridged) {
2555
2579
  return bridged;
2556
2580
  }
2557
2581
  }
2558
2582
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
2559
- const bridged = _chunkV3QNBJ7Ncjs.decodeBridgeRivetError.call(void 0, error.reason);
2583
+ const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.reason);
2560
2584
  if (bridged) {
2561
2585
  return bridged;
2562
2586
  }
@@ -2564,34 +2588,14 @@ function normalizeNativeBridgeError(error) {
2564
2588
  return error;
2565
2589
  }
2566
2590
  function isStructuredBridgeError(error) {
2567
- if (error instanceof _chunkV3QNBJ7Ncjs.RivetError) {
2591
+ if (error instanceof _chunkQAZLM4WTcjs.RivetError) {
2568
2592
  return true;
2569
2593
  }
2570
- return _chunkV3QNBJ7Ncjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
2594
+ return _chunkQAZLM4WTcjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
2571
2595
  }
2572
2596
  function encodeNativeCallbackError(error) {
2573
- const structuredError = isStructuredBridgeError(error) ? error : _chunkJRCZDHXTcjs.deconstructError.call(void 0, error, logger2(), {
2574
- bridge: "native_callback"
2575
- });
2576
- let stack;
2577
- if (error instanceof Error) {
2578
- try {
2579
- stack = error.stack;
2580
- } catch (e3) {
2581
- stack = void 0;
2582
- }
2583
- }
2584
- logger2().warn({
2585
- msg: "native callback error encoded for bridge",
2586
- group: structuredError.group,
2587
- code: structuredError.code,
2588
- message: structuredError.message,
2589
- metadata: structuredError.metadata,
2590
- originalError: _chunkJRCZDHXTcjs.stringifyError.call(void 0, error),
2591
- stack,
2592
- bridge: "native_callback"
2593
- });
2594
- const bridgeError = new Error(_chunkV3QNBJ7Ncjs.encodeBridgeRivetError.call(void 0, structuredError), {
2597
+ const structuredError = isStructuredBridgeError(error) ? error : _chunkK5BA2LEOcjs.deconstructError.call(void 0, error, true);
2598
+ const bridgeError = new Error(_chunkQAZLM4WTcjs.encodeBridgeRivetError.call(void 0, structuredError), {
2595
2599
  cause: error instanceof Error ? error : void 0
2596
2600
  });
2597
2601
  return Object.assign(bridgeError, {
@@ -2621,9 +2625,9 @@ function actorAbortedError() {
2621
2625
  });
2622
2626
  }
2623
2627
  function isClosedTaskRegistrationError(error) {
2624
- const metadata = error instanceof _chunkV3QNBJ7Ncjs.RivetError ? error.metadata : void 0;
2628
+ const metadata = error instanceof _chunkQAZLM4WTcjs.RivetError ? error.metadata : void 0;
2625
2629
  const metadataError = metadata && typeof metadata === "object" && "error" in metadata ? metadata.error : void 0;
2626
- return error instanceof _chunkV3QNBJ7Ncjs.RivetError && error.group === "core" && error.code === _chunkV3QNBJ7Ncjs.INTERNAL_ERROR_CODE && typeof metadataError === "string" && /actor task registration is (closed|not configured)/.test(metadataError);
2630
+ return error instanceof _chunkQAZLM4WTcjs.RivetError && error.group === "core" && error.code === _chunkQAZLM4WTcjs.INTERNAL_ERROR_CODE && typeof metadataError === "string" && /actor task registration is (closed|not configured)/.test(metadataError);
2627
2631
  }
2628
2632
  async function createCancellationTokenHandle(runtime, signal) {
2629
2633
  if (!signal) {
@@ -2646,8 +2650,8 @@ function decodeWorkflowCbor(data) {
2646
2650
  return null;
2647
2651
  }
2648
2652
  try {
2649
- return _chunkNW2J4SOLcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
2650
- } catch (e4) {
2653
+ return _chunkLIXXFXVRcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
2654
+ } catch (e3) {
2651
2655
  return null;
2652
2656
  }
2653
2657
  }
@@ -2751,7 +2755,7 @@ function serializeWorkflowHistoryForJson(data) {
2751
2755
  if (data === null) {
2752
2756
  return null;
2753
2757
  }
2754
- const history = _chunkOVJX4IFYcjs.decodeWorkflowHistoryTransport.call(void 0, data);
2758
+ const history = _chunkHTR4YLNTcjs.decodeWorkflowHistoryTransport.call(void 0, data);
2755
2759
  return {
2756
2760
  nameRegistry: [...history.nameRegistry],
2757
2761
  entries: history.entries.map((entry) => ({
@@ -3215,7 +3219,7 @@ var NativeQueueAdapter = class {
3215
3219
  async nextBatch(options) {
3216
3220
  const completable = (options == null ? void 0 : options.completable) === true;
3217
3221
  if (this.#pendingCompletableMessageIds.size > 0) {
3218
- throw new (0, _chunkV3QNBJ7Ncjs.RivetError)(
3222
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3219
3223
  "queue",
3220
3224
  "previous_message_not_completed",
3221
3225
  "Previous completable queue message is not completed. Call `message.complete(...)` before receiving the next message.",
@@ -3384,7 +3388,7 @@ var NativeQueueAdapter = class {
3384
3388
  }
3385
3389
  yield message;
3386
3390
  } catch (error) {
3387
- if (_chunkV3QNBJ7Ncjs.isRivetErrorLike.call(void 0, error) && error.group === "actor" && error.code === "aborted") {
3391
+ if (_chunkQAZLM4WTcjs.isRivetErrorLike.call(void 0, error) && error.group === "actor" && error.code === "aborted") {
3388
3392
  return;
3389
3393
  }
3390
3394
  throw error;
@@ -3405,7 +3409,7 @@ var NativeQueueAdapter = class {
3405
3409
  ...message,
3406
3410
  complete: async (response) => {
3407
3411
  if (typeof message.complete !== "function") {
3408
- throw new (0, _chunkV3QNBJ7Ncjs.RivetError)(
3412
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3409
3413
  "queue",
3410
3414
  "complete_not_configured",
3411
3415
  `Queue '${message.name}' does not support completion responses.`,
@@ -3417,7 +3421,7 @@ var NativeQueueAdapter = class {
3417
3421
  );
3418
3422
  }
3419
3423
  if (completed) {
3420
- throw new (0, _chunkV3QNBJ7Ncjs.RivetError)(
3424
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3421
3425
  "queue",
3422
3426
  "already_completed",
3423
3427
  "Queue message was already completed.",
@@ -4119,40 +4123,17 @@ var ActorContextHandleAdapter = class {
4119
4123
  });
4120
4124
  }
4121
4125
  keepAwake(promise) {
4122
- const runtimeState = getNativeRuntimeState(this.#runtime, this.#ctx);
4123
- runtimeState.keepAwakeCount = (_nullishCoalesce(runtimeState.keepAwakeCount, () => ( 0))) + 1;
4124
- let registered = false;
4125
4126
  const trackedPromise = Promise.resolve(promise).catch((error) => {
4126
4127
  logger2().warn({
4127
4128
  msg: "keepAwake promise rejected",
4128
- error: _chunkJRCZDHXTcjs.stringifyError.call(void 0, error)
4129
+ error: _chunkK5BA2LEOcjs.stringifyError.call(void 0, error)
4129
4130
  });
4130
- }).finally(async () => {
4131
- if (!registered) {
4132
- return;
4133
- }
4134
- runtimeState.keepAwakeCount = Math.max(
4135
- (_nullishCoalesce(runtimeState.keepAwakeCount, () => ( 1))) - 1,
4136
- 0
4137
- );
4138
- if (runtimeState.keepAwakeCount === 0 && runtimeState.deferSleepCleanupUntilKeepAwakeIdle) {
4139
- await cleanupDeferredNativeSleepRuntimeState(
4140
- this.#runtime,
4141
- this.#ctx,
4142
- runtimeState
4143
- );
4144
- }
4145
4131
  }).then(() => null);
4146
4132
  try {
4147
4133
  callNativeSync(
4148
4134
  () => this.#runtime.actorKeepAwake(this.#ctx, trackedPromise)
4149
4135
  );
4150
- registered = true;
4151
4136
  } catch (error) {
4152
- runtimeState.keepAwakeCount = Math.max(
4153
- (_nullishCoalesce(runtimeState.keepAwakeCount, () => ( 1))) - 1,
4154
- 0
4155
- );
4156
4137
  if (!isClosedTaskRegistrationError(error)) {
4157
4138
  throw error;
4158
4139
  }
@@ -4459,39 +4440,6 @@ function withConnContext(runtime, ctx, conn, clientFactory, schemas = {}, databa
4459
4440
  }
4460
4441
  );
4461
4442
  }
4462
- function buildNativeRequestErrorResponse(encoding, path, error) {
4463
- const { statusCode, group, code, message, metadata } = _chunkJRCZDHXTcjs.deconstructError.call(void 0,
4464
- error,
4465
- logger2(),
4466
- {
4467
- path,
4468
- runtime: "native"
4469
- },
4470
- false
4471
- );
4472
- const body = _chunkNW2J4SOLcjs.serializeWithEncoding.call(void 0,
4473
- encoding,
4474
- { group, code, message, metadata },
4475
- _chunkFTZIZ3JGcjs.HTTP_RESPONSE_ERROR_VERSIONED,
4476
- _chunkFTZIZ3JGcjs.CURRENT_VERSION,
4477
- _chunkFTZIZ3JGcjs.HttpResponseErrorSchema,
4478
- (value) => value,
4479
- (value) => ({
4480
- group: value.group,
4481
- code: value.code,
4482
- message: value.message,
4483
- metadata: value.metadata === void 0 ? null : runtimeBytesToArrayBuffer(
4484
- _chunkNW2J4SOLcjs.encodeCborCompat.call(void 0, value.metadata)
4485
- )
4486
- })
4487
- );
4488
- return new Response(body, {
4489
- status: statusCode,
4490
- headers: {
4491
- "Content-Type": _chunkNW2J4SOLcjs.contentTypeForEncoding.call(void 0, encoding)
4492
- }
4493
- });
4494
- }
4495
4443
  function buildActorConfig(definition, registryConfig) {
4496
4444
  const config = definition.config;
4497
4445
  const options = _nullishCoalesce(config.options, () => ( {}));
@@ -4537,9 +4485,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4537
4485
  const actionHandlers = Object.fromEntries(
4538
4486
  Object.entries(_nullishCoalesce(config.actions, () => ( {}))).map(([name, handler]) => [name, handler])
4539
4487
  );
4540
- const createClient = () => _chunkFTZIZ3JGcjs.createClientWithDriver.call(void 0,
4541
- new (0, _chunkFTZIZ3JGcjs.RemoteEngineControlClient)(
4542
- _chunkFTZIZ3JGcjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
4488
+ const createClient = () => _chunkENK7C66Gcjs.createClientWithDriver.call(void 0,
4489
+ new (0, _chunkENK7C66Gcjs.RemoteEngineControlClient)(
4490
+ _chunkENK7C66Gcjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
4543
4491
  ),
4544
4492
  { encoding: "bare" }
4545
4493
  );
@@ -4602,7 +4550,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4602
4550
  }
4603
4551
  });
4604
4552
  const errorResponse = (error, status) => {
4605
- const rivetError = _chunkV3QNBJ7Ncjs.toRivetError.call(void 0, error);
4553
+ const rivetError = _chunkQAZLM4WTcjs.toRivetError.call(void 0, error);
4606
4554
  return jsonResponse(
4607
4555
  {
4608
4556
  group: rivetError.group,
@@ -4843,7 +4791,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4843
4791
  const action = actionHandlers[actionName];
4844
4792
  if (!action) {
4845
4793
  return errorResponse(
4846
- new (0, _chunkV3QNBJ7Ncjs.RivetError)(
4794
+ new (0, _chunkQAZLM4WTcjs.RivetError)(
4847
4795
  "action",
4848
4796
  "action_not_found",
4849
4797
  `Action ${actionName} not found`
@@ -5014,12 +4962,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5014
4962
  }
5015
4963
  }
5016
4964
  } finally {
5017
- const runtimeState = getNativeRuntimeState(runtime, ctx);
5018
- if ((_nullishCoalesce(runtimeState.keepAwakeCount, () => ( 0))) > 0) {
5019
- runtimeState.deferSleepCleanupUntilKeepAwakeIdle = true;
5020
- runtimeState.deferredSleepCleanupActorCtx = actorCtx;
5021
- } else {
4965
+ try {
5022
4966
  await cleanupNativeSleepRuntimeState(runtime, ctx);
4967
+ } finally {
5023
4968
  await actorCtx.dispose();
5024
4969
  }
5025
4970
  }
@@ -5183,7 +5128,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5183
5128
  );
5184
5129
  }
5185
5130
  if (!result) {
5186
- throw _chunkV3QNBJ7Ncjs.forbiddenError.call(void 0, );
5131
+ throw _chunkQAZLM4WTcjs.forbiddenError.call(void 0, );
5187
5132
  }
5188
5133
  } finally {
5189
5134
  await actorCtx.dispose();
@@ -5229,7 +5174,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5229
5174
  new Response(null, { status: 404 })
5230
5175
  );
5231
5176
  }
5232
- const rawConnParams = jsRequest.headers.get(_chunkFTZIZ3JGcjs.HEADER_CONN_PARAMS);
5177
+ const rawConnParams = jsRequest.headers.get(_chunkENK7C66Gcjs.HEADER_CONN_PARAMS);
5233
5178
  let requestCtx;
5234
5179
  let conn;
5235
5180
  try {
@@ -5260,17 +5205,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5260
5205
  );
5261
5206
  }
5262
5207
  return await toRuntimeHttpResponse(response);
5263
- } catch (error2) {
5264
- const encodingHeader = jsRequest.headers.get(_chunkFTZIZ3JGcjs.HEADER_ENCODING);
5265
- const encoding = encodingHeader === "cbor" || encodingHeader === "bare" ? encodingHeader : "json";
5266
- const path = new URL(jsRequest.url).pathname;
5267
- return await toRuntimeHttpResponse(
5268
- buildNativeRequestErrorResponse(
5269
- encoding,
5270
- path,
5271
- error2
5272
- )
5273
- );
5274
5208
  } finally {
5275
5209
  await (requestCtx == null ? void 0 : requestCtx.dispose());
5276
5210
  if (conn) {
@@ -5407,7 +5341,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5407
5341
  name
5408
5342
  );
5409
5343
  if (canPublish && !await canPublish(actorCtx)) {
5410
- throw _chunkV3QNBJ7Ncjs.forbiddenError.call(void 0, );
5344
+ throw _chunkQAZLM4WTcjs.forbiddenError.call(void 0, );
5411
5345
  }
5412
5346
  const decodedBody = decodeValue(body);
5413
5347
  if (wait) {
@@ -5467,7 +5401,7 @@ async function buildServeConfig(config) {
5467
5401
  poolName: config.envoy.poolName,
5468
5402
  handleInspectorHttpInRuntime: true,
5469
5403
  serverlessBasePath: config.serverless.basePath,
5470
- serverlessPackageVersion: _chunkJRCZDHXTcjs.VERSION,
5404
+ serverlessPackageVersion: _chunkK5BA2LEOcjs.VERSION,
5471
5405
  serverlessClientEndpoint: config.publicEndpoint,
5472
5406
  serverlessClientNamespace: config.publicNamespace,
5473
5407
  serverlessClientToken: config.publicToken,
@@ -5479,13 +5413,13 @@ async function buildServeConfig(config) {
5479
5413
  serveConfig.engineBinaryPath = getEnginePath();
5480
5414
  }
5481
5415
  if ((_a = config.test) == null ? void 0 : _a.enabled) {
5482
- serveConfig.inspectorTestToken = _nullishCoalesce(_chunkJRCZDHXTcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
5416
+ serveConfig.inspectorTestToken = _nullishCoalesce(_chunkK5BA2LEOcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
5483
5417
  }
5484
5418
  return serveConfig;
5485
5419
  }
5486
5420
  async function buildRegistryWithRuntime(config, runtime) {
5487
5421
  var _a;
5488
- if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkJRCZDHXTcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
5422
+ if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkK5BA2LEOcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
5489
5423
  trySetProcessEnv("_RIVET_TEST_INSPECTOR_TOKEN", "token");
5490
5424
  }
5491
5425
  const registry = runtime.createRegistry();
@@ -5511,8 +5445,23 @@ async function buildConfiguredRegistry(config) {
5511
5445
  }
5512
5446
 
5513
5447
  // src/registry/index.ts
5448
+ function signalExitCode(signal) {
5449
+ switch (signal) {
5450
+ case "SIGINT":
5451
+ return 130;
5452
+ case "SIGTERM":
5453
+ return 143;
5454
+ }
5455
+ }
5456
+ function finishShutdownSignal(signal) {
5457
+ if (process.pid === 1) {
5458
+ process.exit(signalExitCode(signal));
5459
+ }
5460
+ process.kill(process.pid, signal);
5461
+ }
5514
5462
  var Registry = class {
5515
5463
  #config;
5464
+
5516
5465
  get config() {
5517
5466
  return this.#config;
5518
5467
  }
@@ -5529,6 +5478,11 @@ var Registry = class {
5529
5478
  #signalHandlers = {};
5530
5479
  constructor(config) {
5531
5480
  this.#config = config;
5481
+ this.routes = {
5482
+ health: () => this.#healthRoute(),
5483
+ metadata: () => this.#metadataRoute(),
5484
+ prometheusMetrics: (request) => this.#prometheusMetricsRoute(request)
5485
+ };
5532
5486
  }
5533
5487
  #ensureServerlessPoolConfigured(config) {
5534
5488
  if (!config.configurePool) return void 0;
@@ -5721,20 +5675,89 @@ var Registry = class {
5721
5675
  fetch: (request) => this.handler(request)
5722
5676
  };
5723
5677
  }
5724
- async diagnostics() {
5725
- var _a;
5678
+ /**
5679
+ * Returns a health response suitable for mounting in a user-owned router.
5680
+ */
5681
+ async #healthRoute() {
5682
+ const configured = await this.#activeConfiguredRegistry();
5683
+ if (!configured) {
5684
+ return jsonRouteResponse(503, {
5685
+ status: "not_started",
5686
+ runtime: "rivetkit",
5687
+ version: _chunkK5BA2LEOcjs.VERSION
5688
+ });
5689
+ }
5690
+ const { runtime, registry } = configured;
5691
+ if (!runtime.registryHealth) {
5692
+ return jsonRouteResponse(501, {
5693
+ status: "unsupported",
5694
+ runtime: "rivetkit",
5695
+ version: _chunkK5BA2LEOcjs.VERSION
5696
+ });
5697
+ }
5698
+ const response = await runtime.registryHealth(registry);
5699
+ return new Response(new Uint8Array(response.body), {
5700
+ status: response.status,
5701
+ headers: response.headers
5702
+ });
5703
+ }
5704
+ /**
5705
+ * Returns serverless metadata suitable for mounting in a user-owned router.
5706
+ */
5707
+ async #metadataRoute() {
5708
+ const configured = await this.#activeConfiguredRegistry();
5709
+ if (!configured) {
5710
+ return new Response("registry not started\n", {
5711
+ status: 503,
5712
+ headers: { "content-type": "text/plain; charset=utf-8" }
5713
+ });
5714
+ }
5715
+ const { runtime, registry } = configured;
5716
+ if (!runtime.registryMetadata) {
5717
+ return new Response("metadata is not supported by this runtime\n", {
5718
+ status: 501,
5719
+ headers: { "content-type": "text/plain; charset=utf-8" }
5720
+ });
5721
+ }
5722
+ const response = await runtime.registryMetadata(registry);
5723
+ return new Response(new Uint8Array(response.body), {
5724
+ status: response.status,
5725
+ headers: response.headers
5726
+ });
5727
+ }
5728
+ /**
5729
+ * Returns a Prometheus metrics response suitable for mounting in a user-owned router.
5730
+ */
5731
+ async #prometheusMetricsRoute(_request) {
5732
+ const configured = await this.#activeConfiguredRegistry();
5733
+ if (!configured) {
5734
+ return new Response("registry not started\n", {
5735
+ status: 503,
5736
+ headers: { "content-type": "text/plain; charset=utf-8" }
5737
+ });
5738
+ }
5739
+ const { runtime, registry } = configured;
5740
+ if (!runtime.registryMetrics) {
5741
+ return new Response("metrics are not supported by this runtime\n", {
5742
+ status: 501,
5743
+ headers: { "content-type": "text/plain; charset=utf-8" }
5744
+ });
5745
+ }
5746
+ const response = await runtime.registryMetrics(registry);
5747
+ return new Response(new Uint8Array(response.body), {
5748
+ status: response.status,
5749
+ headers: response.headers
5750
+ });
5751
+ }
5752
+ async #activeConfiguredRegistry() {
5726
5753
  const candidates = [
5727
5754
  this.#runtimeServerlessPromise,
5728
5755
  this.#runtimeServeConfiguredPromise
5729
5756
  ].filter(
5730
5757
  (candidate) => candidate !== void 0
5731
5758
  );
5732
- for (const candidate of candidates) {
5733
- const { runtime, registry } = await candidate;
5734
- const diagnostics = await ((_a = runtime.registryDiagnostics) == null ? void 0 : _a.call(runtime, registry));
5735
- if (diagnostics) return diagnostics;
5736
- }
5737
- return { mode: "not_started", envoyActiveActorCount: null };
5759
+ if (candidates.length === 0) return void 0;
5760
+ return await candidates[0];
5738
5761
  }
5739
5762
  /**
5740
5763
  * Starts an actor envoy for standalone server deployments.
@@ -5777,7 +5800,7 @@ var Registry = class {
5777
5800
  #onShutdownSignal(signal, config, configuredRegistryPromise) {
5778
5801
  if (this.#shutdownInFlight !== null) {
5779
5802
  this.#removeSignalHandlers();
5780
- process.kill(process.pid, signal);
5803
+ finishShutdownSignal(signal);
5781
5804
  return;
5782
5805
  }
5783
5806
  this.#shutdownInFlight = this.#runShutdown(
@@ -5790,7 +5813,7 @@ var Registry = class {
5790
5813
  }
5791
5814
  async #runShutdown(signal, config, configuredRegistryPromise) {
5792
5815
  var _a;
5793
- const gracePeriodMs = _nullishCoalesce(((_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs), () => ( 3e4));
5816
+ const gracePeriodMs = await _asyncNullishCoalesce(await _asyncNullishCoalesce(((_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs), async () => ( await this.#actorStopThresholdMs(configuredRegistryPromise))), async () => ( 30 * 60 * 1e3));
5794
5817
  const drain = async () => {
5795
5818
  const registries = [
5796
5819
  (async () => {
@@ -5837,7 +5860,23 @@ var Registry = class {
5837
5860
  )
5838
5861
  ]);
5839
5862
  this.#removeSignalHandlers();
5840
- process.kill(process.pid, signal);
5863
+ finishShutdownSignal(signal);
5864
+ }
5865
+ async #actorStopThresholdMs(configuredRegistryPromise) {
5866
+ var _a;
5867
+ try {
5868
+ const { runtime, registry } = await configuredRegistryPromise;
5869
+ const thresholdMs = await ((_a = runtime.registryActorStopThresholdMs) == null ? void 0 : _a.call(runtime, registry));
5870
+ if (thresholdMs !== void 0 && Number.isFinite(thresholdMs) && thresholdMs > 0) {
5871
+ return thresholdMs;
5872
+ }
5873
+ } catch (err) {
5874
+ logger2().warn(
5875
+ { err },
5876
+ "failed to read actor stop threshold for shutdown grace"
5877
+ );
5878
+ }
5879
+ return void 0;
5841
5880
  }
5842
5881
  #removeSignalHandlers() {
5843
5882
  for (const [signal, handler] of Object.entries(
@@ -5872,7 +5911,7 @@ var Registry = class {
5872
5911
  };
5873
5912
  console.log();
5874
5913
  console.log(
5875
- ` RivetKit ${_chunkJRCZDHXTcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
5914
+ ` RivetKit ${_chunkK5BA2LEOcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
5876
5915
  );
5877
5916
  if (config.namespace !== "default") {
5878
5917
  logLine("Namespace", config.namespace);
@@ -5900,6 +5939,12 @@ function isServerlessMetadataRequest(request, basePath) {
5900
5939
  const normalizedBase = basePath === "/" ? "" : `/${basePath.replace(/^\/+|\/+$/g, "")}`;
5901
5940
  return parsed.pathname === `${normalizedBase}/metadata`;
5902
5941
  }
5942
+ function jsonRouteResponse(status, body) {
5943
+ return new Response(JSON.stringify(body), {
5944
+ status,
5945
+ headers: { "content-type": "application/json" }
5946
+ });
5947
+ }
5903
5948
  function setup(input) {
5904
5949
  return new Registry(input);
5905
5950
  }
@@ -5934,5 +5979,5 @@ function setup(input) {
5934
5979
 
5935
5980
 
5936
5981
 
5937
- exports.ALLOWED_PUBLIC_HEADERS = _chunkFTZIZ3JGcjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunkV3QNBJ7Ncjs.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 = _chunkV3QNBJ7Ncjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunkV3QNBJ7Ncjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunkFTZIZ3JGcjs.createClientWithDriver; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkJRCZDHXTcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkJRCZDHXTcjs.toUint8Array;
5982
+ exports.ALLOWED_PUBLIC_HEADERS = _chunkENK7C66Gcjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunkQAZLM4WTcjs.RivetError; exports.ActorsSchema = ActorsSchema; exports.DocConfigurePoolSchema = DocConfigurePoolSchema; exports.DocEnvoyConfigSchema = DocEnvoyConfigSchema; exports.DocRegistryConfigSchema = DocRegistryConfigSchema; exports.DocServerlessConfigSchema = DocServerlessConfigSchema; exports.DocSqliteConfigSchema = DocSqliteConfigSchema; exports.InlineWebSocketAdapter = InlineWebSocketAdapter; exports.Registry = Registry; exports.RegistryConfigSchema = RegistryConfigSchema; exports.RivetError = _chunkQAZLM4WTcjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunkQAZLM4WTcjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunkENK7C66Gcjs.createClientWithDriver; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkK5BA2LEOcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkK5BA2LEOcjs.toUint8Array;
5938
5983
  //# sourceMappingURL=mod.cjs.map