rivetkit 2.3.0-rc.7 → 2.3.0-rc.9

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 (122) hide show
  1. package/dist/browser/client.d.ts +8 -37
  2. package/dist/browser/client.js +34 -64
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +3 -4
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +2 -2
  7. package/dist/tsup/actor/errors.js +1 -1
  8. package/dist/tsup/agent-os/index.cjs +5 -7
  9. package/dist/tsup/agent-os/index.cjs.map +1 -1
  10. package/dist/tsup/agent-os/index.d.cts +5 -26
  11. package/dist/tsup/agent-os/index.d.ts +5 -26
  12. package/dist/tsup/agent-os/index.js +5 -7
  13. package/dist/tsup/agent-os/index.js.map +1 -1
  14. package/dist/tsup/{chunk-55E7IR6D.cjs → chunk-4CGA6QJO.cjs} +4 -4
  15. package/dist/tsup/{chunk-55E7IR6D.cjs.map → chunk-4CGA6QJO.cjs.map} +1 -1
  16. package/dist/tsup/{chunk-G5HUSWP4.cjs → chunk-4WPEZBK4.cjs} +8 -8
  17. package/dist/tsup/{chunk-G5HUSWP4.cjs.map → chunk-4WPEZBK4.cjs.map} +1 -1
  18. package/dist/tsup/{chunk-2H4ISA4Y.cjs → chunk-CPA4Y3RG.cjs} +10 -10
  19. package/dist/tsup/chunk-CPA4Y3RG.cjs.map +1 -0
  20. package/dist/tsup/{chunk-VJ4Y4WBT.js → chunk-F3Q5BFQ6.js} +34 -10
  21. package/dist/tsup/chunk-F3Q5BFQ6.js.map +1 -0
  22. package/dist/tsup/{chunk-ZGPX6KAH.cjs → chunk-GVTOE34S.cjs} +193 -169
  23. package/dist/tsup/chunk-GVTOE34S.cjs.map +1 -0
  24. package/dist/tsup/{chunk-4DJMFOSU.js → chunk-H37XQU3I.js} +2 -2
  25. package/dist/tsup/{chunk-CMV6N5OX.js → chunk-H7P7WR2Y.js} +3 -3
  26. package/dist/tsup/{chunk-TMLOKTRB.js → chunk-KIWH5H3K.js} +3 -3
  27. package/dist/tsup/chunk-KIWH5H3K.js.map +1 -0
  28. package/dist/tsup/{chunk-52TPEKEC.js → chunk-KJTA3ATT.js} +2 -2
  29. package/dist/tsup/{chunk-SJLPZEA3.cjs → chunk-MALSPBAF.cjs} +3 -3
  30. package/dist/tsup/{chunk-SJLPZEA3.cjs.map → chunk-MALSPBAF.cjs.map} +1 -1
  31. package/dist/tsup/{chunk-VFIY6GWO.js → chunk-MMMEZM5J.js} +4 -4
  32. package/dist/tsup/chunk-MMMEZM5J.js.map +1 -0
  33. package/dist/tsup/{chunk-63WNTDRC.cjs → chunk-QAZLM4WT.cjs} +3 -3
  34. package/dist/tsup/{chunk-63WNTDRC.cjs.map → chunk-QAZLM4WT.cjs.map} +1 -1
  35. package/dist/tsup/{chunk-D5G75T7J.js → chunk-T6YVRM4K.js} +1 -3
  36. package/dist/tsup/chunk-T6YVRM4K.js.map +1 -0
  37. package/dist/tsup/{chunk-FEOG44WH.cjs → chunk-VJFRBJVQ.cjs} +9 -137
  38. package/dist/tsup/chunk-VJFRBJVQ.cjs.map +1 -0
  39. package/dist/tsup/{chunk-HERL2VQ2.js → chunk-VRCIXJRN.js} +5 -7
  40. package/dist/tsup/chunk-VRCIXJRN.js.map +1 -0
  41. package/dist/tsup/{chunk-4LTY5TOO.js → chunk-W7EYSYVI.js} +4 -132
  42. package/dist/tsup/chunk-W7EYSYVI.js.map +1 -0
  43. package/dist/tsup/{chunk-SRNOPUC6.cjs → chunk-WQ4HNA4W.cjs} +2 -4
  44. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +1 -0
  45. package/dist/tsup/{chunk-X6HIFXNK.cjs → chunk-Y5NSCZA2.cjs} +12 -14
  46. package/dist/tsup/chunk-Y5NSCZA2.cjs.map +1 -0
  47. package/dist/tsup/client/mod.cjs +7 -7
  48. package/dist/tsup/client/mod.d.cts +2 -2
  49. package/dist/tsup/client/mod.d.ts +2 -2
  50. package/dist/tsup/client/mod.js +6 -6
  51. package/dist/tsup/common/log.cjs +3 -3
  52. package/dist/tsup/common/log.js +2 -2
  53. package/dist/tsup/common/websocket.cjs +4 -4
  54. package/dist/tsup/common/websocket.js +3 -3
  55. package/dist/tsup/{config-Ak1lv4gF.d.ts → config-0Ta55UV0.d.ts} +6 -27
  56. package/dist/tsup/{config-DU_xj4qZ.d.cts → config-Ca8dN4cS.d.cts} +6 -27
  57. package/dist/tsup/{context-DAAp4Lpg.d.ts → context-B_IWbWne.d.ts} +1 -1
  58. package/dist/tsup/{context-Dt_L55q8.d.cts → context-CUrQ9MHc.d.cts} +1 -1
  59. package/dist/tsup/inspector/mod.cjs +6 -6
  60. package/dist/tsup/inspector/mod.js +5 -5
  61. package/dist/tsup/mod.cjs +355 -482
  62. package/dist/tsup/mod.cjs.map +1 -1
  63. package/dist/tsup/mod.d.cts +3 -3
  64. package/dist/tsup/mod.d.ts +3 -3
  65. package/dist/tsup/mod.js +276 -403
  66. package/dist/tsup/mod.js.map +1 -1
  67. package/dist/tsup/test/mod.cjs +10 -10
  68. package/dist/tsup/test/mod.d.cts +1 -1
  69. package/dist/tsup/test/mod.d.ts +1 -1
  70. package/dist/tsup/test/mod.js +6 -6
  71. package/dist/tsup/utils.cjs +3 -3
  72. package/dist/tsup/utils.js +2 -2
  73. package/dist/tsup/workflow/mod.cjs +16 -41
  74. package/dist/tsup/workflow/mod.cjs.map +1 -1
  75. package/dist/tsup/workflow/mod.d.cts +3 -3
  76. package/dist/tsup/workflow/mod.d.ts +3 -3
  77. package/dist/tsup/workflow/mod.js +10 -35
  78. package/dist/tsup/workflow/mod.js.map +1 -1
  79. package/package.json +10 -11
  80. package/src/actor/config.ts +0 -3
  81. package/src/actor/errors.ts +2 -2
  82. package/src/agent-os/actor/session.ts +2 -2
  83. package/src/client/actor-conn.ts +34 -6
  84. package/src/client/actor-handle.ts +1 -2
  85. package/src/client/queue.ts +1 -2
  86. package/src/client/utils.ts +1 -0
  87. package/src/common/encoding.ts +5 -243
  88. package/src/common/inline-websocket-adapter.ts +12 -12
  89. package/src/common/log.ts +0 -1
  90. package/src/common/router.ts +2 -2
  91. package/src/common/utils.ts +148 -0
  92. package/src/drivers/engine/actor-driver.ts +11 -11
  93. package/src/engine-client/actor-websocket-client.ts +1 -2
  94. package/src/engine-client/mod.ts +2 -3
  95. package/src/registry/index.ts +109 -46
  96. package/src/registry/napi-runtime.ts +34 -11
  97. package/src/registry/native.ts +162 -205
  98. package/src/registry/runtime.ts +12 -5
  99. package/src/registry/wasm-runtime.ts +13 -2
  100. package/src/serde.ts +2 -2
  101. package/src/workflow/context.ts +5 -32
  102. package/src/workflow/inspector.ts +1 -2
  103. package/dist/tsup/chunk-2H4ISA4Y.cjs.map +0 -1
  104. package/dist/tsup/chunk-4LTY5TOO.js.map +0 -1
  105. package/dist/tsup/chunk-D5G75T7J.js.map +0 -1
  106. package/dist/tsup/chunk-FEOG44WH.cjs.map +0 -1
  107. package/dist/tsup/chunk-HERL2VQ2.js.map +0 -1
  108. package/dist/tsup/chunk-SRNOPUC6.cjs.map +0 -1
  109. package/dist/tsup/chunk-TMLOKTRB.js.map +0 -1
  110. package/dist/tsup/chunk-VFIY6GWO.js.map +0 -1
  111. package/dist/tsup/chunk-VJ4Y4WBT.js.map +0 -1
  112. package/dist/tsup/chunk-X6HIFXNK.cjs.map +0 -1
  113. package/dist/tsup/chunk-ZGPX6KAH.cjs.map +0 -1
  114. package/dist/tsup/process-metrics-NW754INA.js +0 -118
  115. package/dist/tsup/process-metrics-NW754INA.js.map +0 -1
  116. package/dist/tsup/process-metrics-TYAGKCEJ.cjs +0 -118
  117. package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +0 -1
  118. package/src/registry/process-metrics.ts +0 -183
  119. package/src/registry/write-through-proxy.ts +0 -40
  120. /package/dist/tsup/{chunk-4DJMFOSU.js.map → chunk-H37XQU3I.js.map} +0 -0
  121. /package/dist/tsup/{chunk-CMV6N5OX.js.map → chunk-H7P7WR2Y.js.map} +0 -0
  122. /package/dist/tsup/{chunk-52TPEKEC.js.map → chunk-KJTA3ATT.js.map} +0 -0
package/dist/tsup/mod.cjs CHANGED
@@ -1,15 +1,15 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2; var _class3;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2;
2
2
 
3
3
 
4
4
 
5
5
 
6
6
 
7
7
 
8
+ var _chunkWQ4HNA4Wcjs = require('./chunk-WQ4HNA4W.cjs');
8
9
 
9
- var _chunkSRNOPUC6cjs = require('./chunk-SRNOPUC6.cjs');
10
10
 
11
+ var _chunk4CGA6QJOcjs = require('./chunk-4CGA6QJO.cjs');
11
12
 
12
- var _chunk55E7IR6Dcjs = require('./chunk-55E7IR6D.cjs');
13
13
 
14
14
 
15
15
 
@@ -18,8 +18,7 @@ var _chunk55E7IR6Dcjs = require('./chunk-55E7IR6D.cjs');
18
18
 
19
19
 
20
20
 
21
-
22
- var _chunkZGPX6KAHcjs = require('./chunk-ZGPX6KAH.cjs');
21
+ var _chunkGVTOE34Scjs = require('./chunk-GVTOE34S.cjs');
23
22
 
24
23
 
25
24
 
@@ -32,10 +31,9 @@ var _chunkLD5YASJUcjs = require('./chunk-LD5YASJU.cjs');
32
31
 
33
32
 
34
33
 
35
-
36
- var _chunkFEOG44WHcjs = require('./chunk-FEOG44WH.cjs');
34
+ var _chunkVJFRBJVQcjs = require('./chunk-VJFRBJVQ.cjs');
37
35
  require('./chunk-2NDZ7JCR.cjs');
38
- require('./chunk-SJLPZEA3.cjs');
36
+ require('./chunk-MALSPBAF.cjs');
39
37
 
40
38
 
41
39
 
@@ -59,8 +57,8 @@ require('./chunk-SJLPZEA3.cjs');
59
57
 
60
58
 
61
59
 
60
+ var _chunkY5NSCZA2cjs = require('./chunk-Y5NSCZA2.cjs');
62
61
 
63
- var _chunkX6HIFXNKcjs = require('./chunk-X6HIFXNK.cjs');
64
62
 
65
63
 
66
64
 
@@ -70,12 +68,11 @@ var _chunkX6HIFXNKcjs = require('./chunk-X6HIFXNK.cjs');
70
68
 
71
69
 
72
70
 
73
-
74
- var _chunk63WNTDRCcjs = require('./chunk-63WNTDRC.cjs');
71
+ var _chunkQAZLM4WTcjs = require('./chunk-QAZLM4WT.cjs');
75
72
 
76
73
  // src/actor/log.ts
77
74
  function loggerWithoutContext() {
78
- return _chunkX6HIFXNKcjs.getLogger.call(void 0, "actor-runtime");
75
+ return _chunkY5NSCZA2cjs.getLogger.call(void 0, "actor-runtime");
79
76
  }
80
77
 
81
78
  // src/actor/definition.ts
@@ -108,7 +105,7 @@ function actor(input) {
108
105
  warnDeprecatedShutdownTimeoutKeys(
109
106
  input == null ? void 0 : input.options
110
107
  );
111
- const config = _chunkSRNOPUC6cjs.ActorConfigSchema.parse(input);
108
+ const config = _chunkWQ4HNA4Wcjs.ActorConfigSchema.parse(input);
112
109
  return new ActorDefinition(config);
113
110
  }
114
111
  function isStaticActorDefinition(definition) {
@@ -190,7 +187,7 @@ function validateSchemaSync(schemas, key, data) {
190
187
  if (isStandardSchema(schema)) {
191
188
  const result = schema["~standard"].validate(data);
192
189
  if (isPromiseLike(result)) {
193
- throw _chunk63WNTDRCcjs.unsupportedFeature.call(void 0, "async schema validation");
190
+ throw _chunkQAZLM4WTcjs.unsupportedFeature.call(void 0, "async schema validation");
194
191
  }
195
192
  if (result.issues) {
196
193
  return { success: false, issues: [...result.issues] };
@@ -207,7 +204,7 @@ function validateSchemaSync(schemas, key, data) {
207
204
  var _ws = require('hono/ws');
208
205
  var _virtualwebsocket = require('@rivetkit/virtual-websocket');
209
206
  function logger() {
210
- return _chunkX6HIFXNKcjs.getLogger.call(void 0, "inline-websocket-adapter");
207
+ return _chunkY5NSCZA2cjs.getLogger.call(void 0, "inline-websocket-adapter");
211
208
  }
212
209
  var InlineWebSocketAdapter = class {
213
210
  #handler;
@@ -317,24 +314,24 @@ var InlineWebSocketAdapter = class {
317
314
  this.#close(1011, "Internal error during initialization");
318
315
  }
319
316
  }
320
- #handleError(error) {
321
- console.error("INLINE_WEBSOCKET_ADAPTER_ERROR", error);
317
+ #handleError(err) {
318
+ console.error("INLINE_WEBSOCKET_ADAPTER_ERROR", err);
322
319
  logger().error({
323
320
  msg: "error in websocket",
324
- error,
325
- errorMessage: error instanceof Error ? error.message : String(error),
326
- stack: error instanceof Error ? error.stack : void 0
321
+ error: err,
322
+ errorMessage: err instanceof Error ? err.message : String(err),
323
+ stack: err instanceof Error ? err.stack : void 0
327
324
  });
328
325
  try {
329
- this.#handler.onError(error, this.#wsContext);
330
- } catch (error2) {
326
+ this.#handler.onError(err, this.#wsContext);
327
+ } catch (handlerErr) {
331
328
  logger().error({
332
329
  msg: "error in onError handler",
333
- error: error2
330
+ error: handlerErr
334
331
  });
335
332
  }
336
- this.#clientWs.triggerError(error);
337
- this.#actorWs.triggerError(error);
333
+ this.#clientWs.triggerError(err);
334
+ this.#actorWs.triggerError(err);
338
335
  }
339
336
  #close(code, reason) {
340
337
  if (this.#readyState === 3 || this.#readyState === 2) {
@@ -347,8 +344,8 @@ var InlineWebSocketAdapter = class {
347
344
  { code, reason, wasClean: true },
348
345
  this.#wsContext
349
346
  );
350
- } catch (error) {
351
- logger().error({ msg: "error closing websocket", error });
347
+ } catch (err) {
348
+ logger().error({ msg: "error closing websocket", error: err });
352
349
  } finally {
353
350
  this.#readyState = 3;
354
351
  this.#clientWs.triggerClose(code, reason);
@@ -357,16 +354,13 @@ var InlineWebSocketAdapter = class {
357
354
  }
358
355
  };
359
356
 
360
- // src/registry/index.ts
361
- var _hono = require('hono');
362
-
363
357
  // src/common/engine.ts
364
358
  var ENGINE_PORT = 6420;
365
359
  var ENGINE_ENDPOINT = `http://127.0.0.1:${ENGINE_PORT}`;
366
360
 
367
361
  // src/registry/log.ts
368
362
  function logger2() {
369
- return _chunkX6HIFXNKcjs.getLogger.call(void 0, "registry");
363
+ return _chunkY5NSCZA2cjs.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 = _chunkZGPX6KAHcjs.convertRegistryConfigToClientConfig.call(void 0, config);
407
- const dcsRes = await _chunkZGPX6KAHcjs.getDatacenters.call(void 0, clientConfig);
400
+ const clientConfig = _chunkGVTOE34Scjs.convertRegistryConfigToClientConfig.call(void 0, config);
401
+ const dcsRes = await _chunkGVTOE34Scjs.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 _chunkZGPX6KAHcjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
423
+ await _chunkGVTOE34Scjs.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: _chunkX6HIFXNKcjs.stringifyError.call(void 0, error)
440
+ error: _chunkY5NSCZA2cjs.stringifyError.call(void 0, error)
447
441
  });
448
442
  await sleep(CONFIGURE_RETRY_DELAY_MS);
449
443
  }
@@ -451,150 +445,11 @@ 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: _chunkX6HIFXNKcjs.stringifyError.call(void 0, lastError)
448
+ error: _chunkY5NSCZA2cjs.stringifyError.call(void 0, lastError)
455
449
  });
456
450
  throw lastError;
457
451
  }
458
452
 
459
- // src/utils/serve.ts
460
- var _getport = require('get-port'); var _getport2 = _interopRequireDefault(_getport);
461
- var serveStaticLoaderPromises = {};
462
- async function crossPlatformServe(config, httpPort, app, runtime = _chunkX6HIFXNKcjs.detectRuntime.call(void 0, )) {
463
- logger2().debug({ msg: "detected runtime for serve", runtime });
464
- switch (runtime) {
465
- case "deno":
466
- return serveDeno(config, httpPort, app);
467
- case "bun":
468
- return serveBun(config, httpPort, app);
469
- case "node":
470
- return serveNode(config, httpPort, app);
471
- default:
472
- return serveNode(config, httpPort, app);
473
- }
474
- }
475
- async function loadRuntimeServeStatic(runtime) {
476
- if (!serveStaticLoaderPromises[runtime]) {
477
- if (runtime === "node") {
478
- const nodeServeStaticModule = "@hono/node-server/serve-static";
479
- serveStaticLoaderPromises[runtime] = Promise.resolve().then(() => _interopRequireWildcard(require(
480
- /* webpackIgnore: true */
481
- nodeServeStaticModule
482
- ))).then((x) => x.serveStatic);
483
- } else if (runtime === "bun") {
484
- const bunModule = "hono/bun";
485
- serveStaticLoaderPromises[runtime] = Promise.resolve().then(() => _interopRequireWildcard(require(
486
- /* webpackIgnore: true */
487
- bunModule
488
- ))).then((x) => x.serveStatic);
489
- } else if (runtime === "deno") {
490
- const denoModule = "hono/deno";
491
- serveStaticLoaderPromises[runtime] = Promise.resolve().then(() => _interopRequireWildcard(require(
492
- /* webpackIgnore: true */
493
- denoModule
494
- ))).then((x) => x.serveStatic);
495
- } else {
496
- throw new Error(`unsupported runtime: ${runtime}`);
497
- }
498
- }
499
- return await serveStaticLoaderPromises[runtime];
500
- }
501
- async function serveNode(config, httpPort, app) {
502
- const nodeServerModule = "@hono/node-server";
503
- let serve;
504
- try {
505
- const dep = await Promise.resolve().then(() => _interopRequireWildcard(require(
506
- /* webpackIgnore: true */
507
- nodeServerModule
508
- )));
509
- serve = dep.serve;
510
- } catch (err) {
511
- logger2().error({
512
- msg: "failed to import @hono/node-server. please run 'npm install @hono/node-server @hono/node-ws'",
513
- error: _chunkX6HIFXNKcjs.stringifyError.call(void 0, err)
514
- });
515
- process.exit(1);
516
- }
517
- const nodeWsModule = "@hono/node-ws";
518
- let createNodeWebSocket;
519
- try {
520
- const dep = await Promise.resolve().then(() => _interopRequireWildcard(require(
521
- /* webpackIgnore: true */
522
- nodeWsModule
523
- )));
524
- createNodeWebSocket = dep.createNodeWebSocket;
525
- } catch (err) {
526
- logger2().error({
527
- msg: "failed to import @hono/node-ws. please run 'npm install @hono/node-server @hono/node-ws'",
528
- error: _chunkX6HIFXNKcjs.stringifyError.call(void 0, err)
529
- });
530
- process.exit(1);
531
- }
532
- const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({
533
- app
534
- });
535
- const port = httpPort;
536
- const hostname = config.httpHost;
537
- const server = serve(
538
- { fetch: app.fetch, port, hostname },
539
- () => logger2().info({ msg: "server listening", port, hostname })
540
- );
541
- injectWebSocket(server);
542
- const closeServer = () => {
543
- server.close();
544
- };
545
- return { upgradeWebSocket, closeServer };
546
- }
547
- async function serveDeno(config, httpPort, app) {
548
- const honoDenoModule = "hono/deno";
549
- let upgradeWebSocket;
550
- try {
551
- const dep = await Promise.resolve().then(() => _interopRequireWildcard(require(
552
- /* webpackIgnore: true */
553
- honoDenoModule
554
- )));
555
- upgradeWebSocket = dep.upgradeWebSocket;
556
- } catch (err) {
557
- logger2().error({
558
- msg: "failed to import hono/deno",
559
- error: _chunkX6HIFXNKcjs.stringifyError.call(void 0, err)
560
- });
561
- process.exit(1);
562
- }
563
- const port = httpPort;
564
- const hostname = config.httpHost;
565
- Deno.serve({ port, hostname }, app.fetch);
566
- logger2().info({ msg: "server listening", port, hostname });
567
- return { upgradeWebSocket };
568
- }
569
- async function serveBun(config, httpPort, app) {
570
- const honoBunModule = "hono/bun";
571
- let createBunWebSocket;
572
- try {
573
- const dep = await Promise.resolve().then(() => _interopRequireWildcard(require(
574
- /* webpackIgnore: true */
575
- honoBunModule
576
- )));
577
- createBunWebSocket = dep.createBunWebSocket;
578
- } catch (err) {
579
- logger2().error({
580
- msg: "failed to import hono/bun",
581
- error: _chunkX6HIFXNKcjs.stringifyError.call(void 0, err)
582
- });
583
- process.exit(1);
584
- }
585
- const { websocket, upgradeWebSocket } = createBunWebSocket();
586
- const port = httpPort;
587
- const hostname = config.httpHost;
588
- Bun.serve({
589
- fetch: app.fetch,
590
- port,
591
- hostname,
592
- websocket
593
- });
594
- logger2().info({ msg: "server listening", port, hostname });
595
- return { upgradeWebSocket };
596
- }
597
-
598
453
  // src/registry/config/index.ts
599
454
  var _zod = require('zod');
600
455
 
@@ -602,20 +457,20 @@ var _zod = require('zod');
602
457
  var _v4 = require('zod/v4');
603
458
  var warnedMissingVersion = false;
604
459
  var EnvoyConfigSchema = _v4.z.object({
605
- poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkX6HIFXNKcjs.getRivetPool.call(void 0, ), () => ( "default"))),
460
+ poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkY5NSCZA2cjs.getRivetPool.call(void 0, ), () => ( "default"))),
606
461
  version: _v4.z.number().default(() => {
607
- const version = _chunkX6HIFXNKcjs.getRivetEnvoyVersion.call(void 0, );
462
+ const version = _chunkY5NSCZA2cjs.getRivetEnvoyVersion.call(void 0, );
608
463
  if (version !== void 0) return version;
609
- if (_chunkX6HIFXNKcjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
464
+ if (_chunkY5NSCZA2cjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
610
465
  warnedMissingVersion = true;
611
- _chunkX6HIFXNKcjs.getLogger.call(void 0, "rivetkit").error(
466
+ _chunkY5NSCZA2cjs.getLogger.call(void 0, "rivetkit").error(
612
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"
613
468
  );
614
469
  }
615
470
  return 1;
616
471
  }),
617
472
  // Deprecated.
618
- totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkX6HIFXNKcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
473
+ totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkY5NSCZA2cjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
619
474
  envoyKey: _v4.z.string().optional()
620
475
  });
621
476
 
@@ -653,7 +508,7 @@ var ServerlessConfigSchema = _v4.z.object({
653
508
  *
654
509
  * Can also be set via RIVET_PUBLIC_ENDPOINT environment variable.
655
510
  */
656
- publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkX6HIFXNKcjs.getRivetPublicEndpoint.call(void 0, )))),
511
+ publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetPublicEndpoint.call(void 0, )))),
657
512
  /**
658
513
  * Token that clients should use when connecting via the public endpoint.
659
514
  *
@@ -661,7 +516,7 @@ var ServerlessConfigSchema = _v4.z.object({
661
516
  *
662
517
  * Can also be specified in the publicEndpoint URL as `https://namespace:token@host`.
663
518
  */
664
- publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkX6HIFXNKcjs.getRivetPublicToken.call(void 0, ))))
519
+ publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetPublicToken.call(void 0, ))))
665
520
  // There is no publicNamespace config option because the frontend and backend
666
521
  // cannot use different namespaces. The namespace is extracted from the
667
522
  // publicEndpoint URL auth syntax if provided.
@@ -715,7 +570,7 @@ var RegistryConfigSchema = _zod.z.object({
715
570
  * Runtime binding to use for RivetKit core.
716
571
  * */
717
572
  runtime: RuntimeKindSchema.optional().transform((val, ctx) => {
718
- const rawRuntime = _nullishCoalesce(val, () => ( _chunkX6HIFXNKcjs.getRivetkitRuntime.call(void 0, )));
573
+ const rawRuntime = _nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetkitRuntime.call(void 0, )));
719
574
  if (rawRuntime === void 0) {
720
575
  return "auto";
721
576
  }
@@ -752,7 +607,7 @@ var RegistryConfigSchema = _zod.z.object({
752
607
  * */
753
608
  logging: _zod.z.object({
754
609
  baseLogger: _zod.z.custom().optional(),
755
- level: _chunkX6HIFXNKcjs.LogLevelSchema.optional()
610
+ level: _chunkY5NSCZA2cjs.LogLevelSchema.optional()
756
611
  }).optional().default(() => ({})),
757
612
  // MARK: Routing
758
613
  // // This is a function to allow for lazy configuration of upgradeWebSocket on the
@@ -770,9 +625,9 @@ var RegistryConfigSchema = _zod.z.object({
770
625
  *
771
626
  * Can also be set via RIVET_ENDPOINT environment variables.
772
627
  */
773
- endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkX6HIFXNKcjs.getRivetEngine.call(void 0, ))), () => ( _chunkX6HIFXNKcjs.getRivetEndpoint.call(void 0, )))),
774
- token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkX6HIFXNKcjs.getRivetToken.call(void 0, )))),
775
- namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkX6HIFXNKcjs.getRivetNamespace.call(void 0, )))),
628
+ endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetEngine.call(void 0, ))), () => ( _chunkY5NSCZA2cjs.getRivetEndpoint.call(void 0, )))),
629
+ token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetToken.call(void 0, )))),
630
+ namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkY5NSCZA2cjs.getRivetNamespace.call(void 0, )))),
776
631
  headers: _zod.z.record(_zod.z.string(), _zod.z.string()).optional().default({}),
777
632
  // MARK: Client
778
633
  // TODO:
@@ -812,9 +667,9 @@ var RegistryConfigSchema = _zod.z.object({
812
667
  *
813
668
  * Starts the full Rust engine process locally.
814
669
  */
815
- startEngine: _zod.z.boolean().default(() => _chunkX6HIFXNKcjs.getRivetRunEngine.call(void 0, )),
670
+ startEngine: _zod.z.boolean().default(() => _chunkY5NSCZA2cjs.getRivetRunEngine.call(void 0, )),
816
671
  /** @experimental */
817
- engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkX6HIFXNKcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkX6HIFXNKcjs.VERSION))),
672
+ engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkY5NSCZA2cjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkY5NSCZA2cjs.VERSION))),
818
673
  /**
819
674
  * @experimental
820
675
  *
@@ -862,7 +717,7 @@ var RegistryConfigSchema = _zod.z.object({
862
717
  }))
863
718
  }).transform((config, ctx) => {
864
719
  var _a, _b, _c;
865
- const isDevEnv = _chunkX6HIFXNKcjs.isDev.call(void 0, );
720
+ const isDevEnv = _chunkY5NSCZA2cjs.isDev.call(void 0, );
866
721
  const sqliteBackend = _nullishCoalesce(((_a = config.sqlite) == null ? void 0 : _a.backend), () => ( ((_b = config.test) == null ? void 0 : _b.sqliteBackend)));
867
722
  if (config.runtime === "wasm" && sqliteBackend === "local") {
868
723
  ctx.addIssue({
@@ -872,7 +727,7 @@ var RegistryConfigSchema = _zod.z.object({
872
727
  });
873
728
  }
874
729
  const sqlite = config.runtime === "wasm" && config.sqlite === void 0 ? { backend: "remote" } : config.sqlite;
875
- const parsedEndpoint = config.endpoint ? _chunkZGPX6KAHcjs.tryParseEndpoint.call(void 0, ctx, {
730
+ const parsedEndpoint = config.endpoint ? _chunkGVTOE34Scjs.tryParseEndpoint.call(void 0, ctx, {
876
731
  endpoint: config.endpoint,
877
732
  path: ["endpoint"],
878
733
  namespace: config.namespace,
@@ -896,7 +751,7 @@ var RegistryConfigSchema = _zod.z.object({
896
751
  );
897
752
  const namespace = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.namespace), () => ( config.namespace)), () => ( "default"));
898
753
  const token = _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.token), () => ( config.token));
899
- const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkZGPX6KAHcjs.tryParseEndpoint.call(void 0, ctx, {
754
+ const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkGVTOE34Scjs.tryParseEndpoint.call(void 0, ctx, {
900
755
  endpoint: config.serverless.publicEndpoint,
901
756
  path: ["serverless", "publicEndpoint"]
902
757
  }) : void 0;
@@ -931,7 +786,7 @@ function buildActorNames(config) {
931
786
  Object.keys(config.use).map((actorName) => {
932
787
  const definition = config.use[actorName];
933
788
  const options = _nullishCoalesce(definition.config.options, () => ( {}));
934
- const runMeta = _chunkSRNOPUC6cjs.getRunMetadata.call(void 0, definition.config.run);
789
+ const runMeta = _chunkWQ4HNA4Wcjs.getRunMetadata.call(void 0, definition.config.run);
935
790
  const metadata = {};
936
791
  metadata.icon = _nullishCoalesce(options.icon, () => ( runMeta.icon));
937
792
  metadata.name = _nullishCoalesce(options.name, () => ( runMeta.name));
@@ -1024,7 +879,7 @@ var DocRegistryConfigSchema = _zod.z.object({
1024
879
  noWelcome: _zod.z.boolean().optional().describe("Disable the welcome message on startup. Default: false"),
1025
880
  sqlite: DocSqliteConfigSchema,
1026
881
  logging: _zod.z.object({
1027
- level: _chunkX6HIFXNKcjs.LogLevelSchema.optional().describe(
882
+ level: _chunkY5NSCZA2cjs.LogLevelSchema.optional().describe(
1028
883
  "Log level for RivetKit. Default: 'warn'"
1029
884
  )
1030
885
  }).optional().describe("Logging configuration."),
@@ -1069,7 +924,7 @@ function shouldAttachNativeKvError(message) {
1069
924
  function enrichNativeDatabaseError(database, error) {
1070
925
  var _a;
1071
926
  const bridgeReason = typeof error === "string" ? error : error instanceof Error ? error.message : void 0;
1072
- const bridged = bridgeReason === void 0 ? void 0 : _chunk63WNTDRCcjs.decodeBridgeRivetError.call(void 0, bridgeReason);
927
+ const bridged = bridgeReason === void 0 ? void 0 : _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, bridgeReason);
1073
928
  if (bridged) {
1074
929
  throw bridged;
1075
930
  }
@@ -1299,29 +1154,6 @@ function lastInsertRowIdColumnName(sql) {
1299
1154
  return alias;
1300
1155
  }
1301
1156
 
1302
- // src/registry/write-through-proxy.ts
1303
- var _onchange = require('@rivetkit/on-change'); var _onchange2 = _interopRequireDefault(_onchange);
1304
- function createWriteThroughProxy(value, commit, beforeChange) {
1305
- if (!value || typeof value !== "object") {
1306
- return value;
1307
- }
1308
- return _onchange2.default.call(void 0,
1309
- value,
1310
- () => {
1311
- commit(value);
1312
- },
1313
- {
1314
- // Rejection is throw-based: beforeChange throws to prevent the
1315
- // mutation. We always return true so on-change applies the change
1316
- // if beforeChange did not throw.
1317
- onValidate(_path, newValue) {
1318
- beforeChange == null ? void 0 : beforeChange(newValue);
1319
- return true;
1320
- }
1321
- }
1322
- );
1323
- }
1324
-
1325
1157
  // src/registry/runtime.ts
1326
1158
  function normalizeRuntimeSqlExecuteResult(result) {
1327
1159
  return result;
@@ -1442,15 +1274,32 @@ var NapiCoreRuntime = (_class = class {
1442
1274
  async shutdownRegistry(registry) {
1443
1275
  await asNativeRegistry(registry).shutdown();
1444
1276
  }
1445
- async registryDiagnostics(registry) {
1446
- 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();
1447
1282
  return {
1448
- mode: diagnostics.mode,
1449
- envoyActiveActorCount: diagnostics.envoyActiveActorCount
1283
+ status: response.status,
1284
+ headers: response.headers,
1285
+ body: response.body
1450
1286
  };
1451
1287
  }
1452
- async registryActorStopThresholdMs(registry) {
1453
- return await _asyncNullishCoalesce(await asNativeRegistry(registry).actorStopThresholdMs(), async () => ( void 0));
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();
1298
+ return {
1299
+ status: response.status,
1300
+ headers: response.headers,
1301
+ body: response.body
1302
+ };
1454
1303
  }
1455
1304
  async handleServerlessRequest(registry, req, onStreamEvent, cancelToken, config) {
1456
1305
  return await asNativeRegistry(registry).handleServerlessRequest(
@@ -1826,7 +1675,7 @@ function validateQueueComplete(schemas, name, response) {
1826
1675
  return result.data;
1827
1676
  }
1828
1677
  function validationError(target, issues) {
1829
- return new (0, _chunk63WNTDRCcjs.RivetError)(
1678
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
1830
1679
  "actor",
1831
1680
  "validation_error",
1832
1681
  `Invalid ${target}`,
@@ -1900,16 +1749,16 @@ function normalizeQueueMessage(message) {
1900
1749
  }
1901
1750
  function normalizeWasmBridgeError(error) {
1902
1751
  if (typeof error === "string") {
1903
- return _nullishCoalesce(_chunk63WNTDRCcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
1752
+ return _nullishCoalesce(_chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
1904
1753
  }
1905
1754
  if (error instanceof Error) {
1906
- const bridged = _chunk63WNTDRCcjs.decodeBridgeRivetError.call(void 0, error.message);
1755
+ const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.message);
1907
1756
  if (bridged) {
1908
1757
  return bridged;
1909
1758
  }
1910
1759
  }
1911
1760
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
1912
- const bridged = _chunk63WNTDRCcjs.decodeBridgeRivetError.call(void 0, error.reason);
1761
+ const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.reason);
1913
1762
  if (bridged) {
1914
1763
  return bridged;
1915
1764
  }
@@ -1931,7 +1780,7 @@ function callWasmSync(invoke) {
1931
1780
  }
1932
1781
  }
1933
1782
  function unsupportedWasmMethod(method2) {
1934
- throw new (0, _chunk63WNTDRCcjs.RivetError)(
1783
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
1935
1784
  "runtime",
1936
1785
  "unsupported",
1937
1786
  `Unsupported wasm runtime method: ${method2}`,
@@ -1992,8 +1841,18 @@ var WasmCoreRuntime = (_class2 = class {
1992
1841
  async shutdownRegistry(registry) {
1993
1842
  await callWasm(() => asWasmRegistry(registry).shutdown());
1994
1843
  }
1995
- async registryDiagnostics() {
1996
- 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
+ };
1997
1856
  }
1998
1857
  async handleServerlessRequest(registry, req, onStreamEvent, cancelToken, config) {
1999
1858
  return await callHandleAsync(
@@ -2422,7 +2281,7 @@ function loadedRuntimeKind(runtime) {
2422
2281
  case "wasm":
2423
2282
  return "wasm";
2424
2283
  }
2425
- throw new (0, _chunk63WNTDRCcjs.RivetError)(
2284
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
2426
2285
  "config",
2427
2286
  "unknown_runtime",
2428
2287
  "RivetKit runtime must be NAPI or wasm.",
@@ -2462,7 +2321,7 @@ function normalizeRuntimeConfigForKind(config, runtimeKind) {
2462
2321
  return config;
2463
2322
  }
2464
2323
  if (sqliteBackendForConfig(config) === "local") {
2465
- throw new (0, _chunk63WNTDRCcjs.RivetError)(
2324
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
2466
2325
  "config",
2467
2326
  "wasm_local_sqlite",
2468
2327
  "WebAssembly runtime cannot use local SQLite. Use remote SQLite instead.",
@@ -2528,30 +2387,22 @@ function getNativeConnPersistState(runtime, ctx, conn) {
2528
2387
  return connState;
2529
2388
  }
2530
2389
  function stateMutationReentrantError() {
2531
- return new (0, _chunk63WNTDRCcjs.RivetError)(
2390
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
2532
2391
  "actor",
2533
2392
  "state_mutation_reentrant",
2534
2393
  "State mutations are not allowed inside onStateChange."
2535
2394
  );
2536
2395
  }
2537
2396
  function databaseNotConfiguredError() {
2538
- return new (0, _chunk63WNTDRCcjs.RivetError)(
2397
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
2539
2398
  "actor",
2540
2399
  "database_not_configured",
2541
2400
  "database is not configured for this actor",
2542
2401
  { public: true }
2543
2402
  );
2544
2403
  }
2545
- function databaseClientNotReadyError() {
2546
- return new (0, _chunk63WNTDRCcjs.RivetError)(
2547
- "actor",
2548
- "database_client_not_ready",
2549
- "actor database client was not initialized before user code ran. this is an internal lifecycle error; the migration callback should have pre-warmed the client. file an issue if you can reproduce.",
2550
- { public: true }
2551
- );
2552
- }
2553
2404
  function stateNotEnabledError() {
2554
- return new (0, _chunk63WNTDRCcjs.RivetError)(
2405
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
2555
2406
  "actor",
2556
2407
  "state_not_enabled",
2557
2408
  "State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.dev/docs/actors/state/#initializing-state)",
@@ -2559,7 +2410,7 @@ function stateNotEnabledError() {
2559
2410
  );
2560
2411
  }
2561
2412
  function nativeClientNotConfiguredError() {
2562
- return new (0, _chunk63WNTDRCcjs.RivetError)(
2413
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
2563
2414
  "native",
2564
2415
  "client_not_configured",
2565
2416
  "native actor client is not configured",
@@ -2567,7 +2418,7 @@ function nativeClientNotConfiguredError() {
2567
2418
  );
2568
2419
  }
2569
2420
  function nativeEndpointNotConfiguredError() {
2570
- return new (0, _chunk63WNTDRCcjs.RivetError)(
2421
+ return new (0, _chunkQAZLM4WTcjs.RivetError)(
2571
2422
  "native",
2572
2423
  "endpoint_not_configured",
2573
2424
  "registry endpoint is required for native envoy startup",
@@ -2602,20 +2453,7 @@ function clearNativeRuntimeState(runtime, ctx) {
2602
2453
  callNativeSync(() => runtime.actorClearRuntimeState(ctx));
2603
2454
  }
2604
2455
  async function cleanupNativeSleepRuntimeState(runtime, ctx) {
2605
- const waitStarted = Date.now();
2606
- const drained = await runtime.actorWaitForTrackedShutdownWork(ctx);
2607
- const waitMs = Date.now() - waitStarted;
2608
- if (drained) {
2609
- logger2().debug({
2610
- msg: "sleep cleanup: tracked shutdown work drained",
2611
- waitMs
2612
- });
2613
- } else {
2614
- logger2().warn({
2615
- msg: "sleep cleanup: shutdown deadline reached before tracked work drained; closing DB anyway",
2616
- waitMs
2617
- });
2618
- }
2456
+ await runtime.actorWaitForTrackedShutdownWork(ctx);
2619
2457
  await closeNativeDatabaseClient(runtime, ctx);
2620
2458
  await closeNativeSqlDatabase(runtime, ctx);
2621
2459
  clearNativeRuntimeState(runtime, ctx);
@@ -2720,10 +2558,10 @@ function decodeValue(value) {
2720
2558
  if (!value || value.length === 0) {
2721
2559
  return void 0;
2722
2560
  }
2723
- return _chunkFEOG44WHcjs.decodeCborJsonCompat.call(void 0, value);
2561
+ return _chunkVJFRBJVQcjs.decodeCborJsonCompat.call(void 0, value);
2724
2562
  }
2725
2563
  function encodeValue(value) {
2726
- return _chunkFEOG44WHcjs.encodeCborCompat.call(void 0, value);
2564
+ return _chunkVJFRBJVQcjs.encodeCborCompat.call(void 0, value);
2727
2565
  }
2728
2566
  function unwrapTsfnPayload(error, payload) {
2729
2567
  if (error !== null && error !== void 0) {
@@ -2733,16 +2571,16 @@ function unwrapTsfnPayload(error, payload) {
2733
2571
  }
2734
2572
  function normalizeNativeBridgeError(error) {
2735
2573
  if (typeof error === "string") {
2736
- return _nullishCoalesce(_chunk63WNTDRCcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2574
+ return _nullishCoalesce(_chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2737
2575
  }
2738
2576
  if (error instanceof Error) {
2739
- const bridged = _chunk63WNTDRCcjs.decodeBridgeRivetError.call(void 0, error.message);
2577
+ const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.message);
2740
2578
  if (bridged) {
2741
2579
  return bridged;
2742
2580
  }
2743
2581
  }
2744
2582
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
2745
- const bridged = _chunk63WNTDRCcjs.decodeBridgeRivetError.call(void 0, error.reason);
2583
+ const bridged = _chunkQAZLM4WTcjs.decodeBridgeRivetError.call(void 0, error.reason);
2746
2584
  if (bridged) {
2747
2585
  return bridged;
2748
2586
  }
@@ -2750,14 +2588,14 @@ function normalizeNativeBridgeError(error) {
2750
2588
  return error;
2751
2589
  }
2752
2590
  function isStructuredBridgeError(error) {
2753
- if (error instanceof _chunk63WNTDRCcjs.RivetError) {
2591
+ if (error instanceof _chunkQAZLM4WTcjs.RivetError) {
2754
2592
  return true;
2755
2593
  }
2756
- return _chunk63WNTDRCcjs.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");
2757
2595
  }
2758
2596
  function encodeNativeCallbackError(error) {
2759
- const structuredError = isStructuredBridgeError(error) ? error : _chunkX6HIFXNKcjs.deconstructError.call(void 0, error, true);
2760
- const bridgeError = new Error(_chunk63WNTDRCcjs.encodeBridgeRivetError.call(void 0, structuredError), {
2597
+ const structuredError = isStructuredBridgeError(error) ? error : _chunkY5NSCZA2cjs.deconstructError.call(void 0, error, true);
2598
+ const bridgeError = new Error(_chunkQAZLM4WTcjs.encodeBridgeRivetError.call(void 0, structuredError), {
2761
2599
  cause: error instanceof Error ? error : void 0
2762
2600
  });
2763
2601
  return Object.assign(bridgeError, {
@@ -2787,9 +2625,9 @@ function actorAbortedError() {
2787
2625
  });
2788
2626
  }
2789
2627
  function isClosedTaskRegistrationError(error) {
2790
- const metadata = error instanceof _chunk63WNTDRCcjs.RivetError ? error.metadata : void 0;
2628
+ const metadata = error instanceof _chunkQAZLM4WTcjs.RivetError ? error.metadata : void 0;
2791
2629
  const metadataError = metadata && typeof metadata === "object" && "error" in metadata ? metadata.error : void 0;
2792
- return error instanceof _chunk63WNTDRCcjs.RivetError && error.group === "core" && error.code === _chunk63WNTDRCcjs.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);
2793
2631
  }
2794
2632
  async function createCancellationTokenHandle(runtime, signal) {
2795
2633
  if (!signal) {
@@ -2812,7 +2650,7 @@ function decodeWorkflowCbor(data) {
2812
2650
  return null;
2813
2651
  }
2814
2652
  try {
2815
- return _chunkFEOG44WHcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
2653
+ return _chunkVJFRBJVQcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
2816
2654
  } catch (e3) {
2817
2655
  return null;
2818
2656
  }
@@ -2917,7 +2755,7 @@ function serializeWorkflowHistoryForJson(data) {
2917
2755
  if (data === null) {
2918
2756
  return null;
2919
2757
  }
2920
- const history = _chunk55E7IR6Dcjs.decodeWorkflowHistoryTransport.call(void 0, data);
2758
+ const history = _chunk4CGA6QJOcjs.decodeWorkflowHistoryTransport.call(void 0, data);
2921
2759
  return {
2922
2760
  nameRegistry: [...history.nameRegistry],
2923
2761
  entries: history.entries.map((entry) => ({
@@ -2995,6 +2833,44 @@ function decodeArgs(value) {
2995
2833
  const decoded = decodeValue(value);
2996
2834
  return Array.isArray(decoded) ? decoded : decoded === void 0 ? [] : [decoded];
2997
2835
  }
2836
+ function createWriteThroughProxy(value, commit, beforeChange) {
2837
+ if (!value || typeof value !== "object") {
2838
+ return value;
2839
+ }
2840
+ const proxies = /* @__PURE__ */ new WeakMap();
2841
+ const wrap = (target) => {
2842
+ const cached = proxies.get(target);
2843
+ if (cached) {
2844
+ return cached;
2845
+ }
2846
+ const proxy = new Proxy(target, {
2847
+ get(innerTarget, property, receiver) {
2848
+ const result = Reflect.get(innerTarget, property, receiver);
2849
+ return result && typeof result === "object" ? wrap(result) : result;
2850
+ },
2851
+ set(innerTarget, property, nextValue, receiver) {
2852
+ beforeChange == null ? void 0 : beforeChange();
2853
+ const updated = Reflect.set(
2854
+ innerTarget,
2855
+ property,
2856
+ nextValue,
2857
+ receiver
2858
+ );
2859
+ commit(value);
2860
+ return updated;
2861
+ },
2862
+ deleteProperty(innerTarget, property) {
2863
+ beforeChange == null ? void 0 : beforeChange();
2864
+ const updated = Reflect.deleteProperty(innerTarget, property);
2865
+ commit(value);
2866
+ return updated;
2867
+ }
2868
+ });
2869
+ proxies.set(target, proxy);
2870
+ return proxy;
2871
+ };
2872
+ return wrap(value);
2873
+ }
2998
2874
  function buildRequest(init) {
2999
2875
  const url = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
3000
2876
  const body = init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
@@ -3030,7 +2906,7 @@ var NativeConnAdapter = class {
3030
2906
  this.#schemas = schemas;
3031
2907
  this.#ctx = ctx;
3032
2908
  this.#queueHibernationRemoval = queueHibernationRemoval;
3033
- this[_chunkSRNOPUC6cjs.CONN_STATE_MANAGER_SYMBOL] = {
2909
+ this[_chunkWQ4HNA4Wcjs.CONN_STATE_MANAGER_SYMBOL] = {
3034
2910
  stateEnabled: true,
3035
2911
  get state() {
3036
2912
  return thisConn.state;
@@ -3047,19 +2923,13 @@ var NativeConnAdapter = class {
3047
2923
  decodeValue(this.#runtime.connParams(this.#conn))
3048
2924
  );
3049
2925
  }
3050
- [_chunkSRNOPUC6cjs.RAW_STATE_SYMBOL]() {
3051
- return this.#readState();
3052
- }
3053
2926
  get state() {
3054
2927
  const nextState = this.#readState();
3055
2928
  return createWriteThroughProxy(nextState, (nextValue) => {
3056
2929
  this.#writeState(nextValue, { writeNative: true });
3057
- }, (newValue) => {
3058
- _chunkFEOG44WHcjs.assertJsonCompatValue.call(void 0, newValue);
3059
2930
  });
3060
2931
  }
3061
2932
  set state(value) {
3062
- _chunkFEOG44WHcjs.assertJsonCompatValue.call(void 0, value);
3063
2933
  this.#writeState(value, { writeNative: true });
3064
2934
  }
3065
2935
  initializeState(value) {
@@ -3349,7 +3219,7 @@ var NativeQueueAdapter = class {
3349
3219
  async nextBatch(options) {
3350
3220
  const completable = (options == null ? void 0 : options.completable) === true;
3351
3221
  if (this.#pendingCompletableMessageIds.size > 0) {
3352
- throw new (0, _chunk63WNTDRCcjs.RivetError)(
3222
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3353
3223
  "queue",
3354
3224
  "previous_message_not_completed",
3355
3225
  "Previous completable queue message is not completed. Call `message.complete(...)` before receiving the next message.",
@@ -3518,7 +3388,7 @@ var NativeQueueAdapter = class {
3518
3388
  }
3519
3389
  yield message;
3520
3390
  } catch (error) {
3521
- if (_chunk63WNTDRCcjs.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") {
3522
3392
  return;
3523
3393
  }
3524
3394
  throw error;
@@ -3539,7 +3409,7 @@ var NativeQueueAdapter = class {
3539
3409
  ...message,
3540
3410
  complete: async (response) => {
3541
3411
  if (typeof message.complete !== "function") {
3542
- throw new (0, _chunk63WNTDRCcjs.RivetError)(
3412
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3543
3413
  "queue",
3544
3414
  "complete_not_configured",
3545
3415
  `Queue '${message.name}' does not support completion responses.`,
@@ -3551,7 +3421,7 @@ var NativeQueueAdapter = class {
3551
3421
  );
3552
3422
  }
3553
3423
  if (completed) {
3554
- throw new (0, _chunk63WNTDRCcjs.RivetError)(
3424
+ throw new (0, _chunkQAZLM4WTcjs.RivetError)(
3555
3425
  "queue",
3556
3426
  "already_completed",
3557
3427
  "Queue message was already completed.",
@@ -3883,70 +3753,6 @@ var TrackedWebSocketHandleAdapter = class {
3883
3753
  return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
3884
3754
  }
3885
3755
  };
3886
- var NativeConnectionMap = (_class3 = class {
3887
- #runtime;
3888
- #ctx;
3889
- #schemas;
3890
- constructor(runtime, ctx, schemas) {;_class3.prototype.__init3.call(this);
3891
- this.#runtime = runtime;
3892
- this.#ctx = ctx;
3893
- this.#schemas = schemas;
3894
- }
3895
- #connToAdapter(conn) {
3896
- return new NativeConnAdapter(
3897
- this.#runtime,
3898
- conn,
3899
- this.#schemas,
3900
- this.#ctx,
3901
- (connId) => callNativeSync(
3902
- () => this.#runtime.actorQueueHibernationRemoval(
3903
- this.#ctx,
3904
- connId
3905
- )
3906
- )
3907
- );
3908
- }
3909
- get size() {
3910
- return callNativeSync(() => this.#runtime.actorConns(this.#ctx)).length;
3911
- }
3912
- get(key) {
3913
- const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3914
- const conn = conns.find(
3915
- (c) => this.#runtime.connId(c) === key
3916
- );
3917
- if (!conn) return void 0;
3918
- return this.#connToAdapter(conn);
3919
- }
3920
- has(key) {
3921
- const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3922
- return conns.some((c) => this.#runtime.connId(c) === key);
3923
- }
3924
- keys() {
3925
- const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3926
- return conns.map((c) => this.#runtime.connId(c))[Symbol.iterator]();
3927
- }
3928
- values() {
3929
- const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3930
- return conns.map((c) => this.#connToAdapter(c))[Symbol.iterator]();
3931
- }
3932
- entries() {
3933
- const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3934
- return conns.map(
3935
- (c) => [this.#runtime.connId(c), this.#connToAdapter(c)]
3936
- )[Symbol.iterator]();
3937
- }
3938
- forEach(callback, thisArg) {
3939
- const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
3940
- for (const conn of conns) {
3941
- const id = this.#runtime.connId(conn);
3942
- callback.call(thisArg, this.#connToAdapter(conn), id, this);
3943
- }
3944
- }
3945
- [Symbol.iterator]() {
3946
- return this.entries();
3947
- }
3948
- __init3() {this[Symbol.toStringTag] = "NativeConnectionMap"}
3949
- }, _class3);
3950
3756
  var ActorContextHandleAdapter = class {
3951
3757
  #runtime;
3952
3758
  #ctx;
@@ -3955,9 +3761,9 @@ var ActorContextHandleAdapter = class {
3955
3761
  #abortSignalCleanup;
3956
3762
  #client;
3957
3763
  #clientFactory;
3958
- #connMap;
3959
3764
  #databaseProvider;
3960
3765
  #db;
3766
+ #dbProxy;
3961
3767
  #dispatchCancelToken;
3962
3768
  #kv;
3963
3769
  #queue;
@@ -3980,7 +3786,7 @@ var ActorContextHandleAdapter = class {
3980
3786
  this.#databaseProvider = databaseProvider;
3981
3787
  }
3982
3788
  this.#request = request;
3983
- this[_chunkSRNOPUC6cjs.ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
3789
+ this[_chunkWQ4HNA4Wcjs.ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
3984
3790
  this
3985
3791
  );
3986
3792
  }
@@ -4000,45 +3806,56 @@ var ActorContextHandleAdapter = class {
4000
3806
  if (!this.#databaseProvider) {
4001
3807
  throw databaseNotConfiguredError();
4002
3808
  }
4003
- if (this.#db) {
4004
- return this.#db;
4005
- }
4006
- const runtimeState = getNativeRuntimeState(this.#runtime, this.#ctx);
4007
- const cachedClient = runtimeState.databaseClient;
4008
- if (cachedClient) {
4009
- this.#db = cachedClient.client;
4010
- return this.#db;
4011
- }
4012
- throw databaseClientNotReadyError();
4013
- }
4014
- [_chunkSRNOPUC6cjs.RAW_STATE_SYMBOL]() {
4015
- if (!this.#stateEnabled) {
4016
- throw stateNotEnabledError();
3809
+ if (!this.#dbProxy) {
3810
+ this.#dbProxy = new Proxy(
3811
+ {},
3812
+ {
3813
+ get: (_target, property) => {
3814
+ if (property === "then") {
3815
+ return void 0;
3816
+ }
3817
+ return async (...args) => {
3818
+ const client = await this.ensureDatabaseClient();
3819
+ const value = Reflect.get(
3820
+ client,
3821
+ property
3822
+ );
3823
+ if (typeof value !== "function") {
3824
+ return value;
3825
+ }
3826
+ return await value.apply(client, args);
3827
+ };
3828
+ }
3829
+ }
3830
+ );
4017
3831
  }
4018
- return this.#readState();
3832
+ return this.#dbProxy;
4019
3833
  }
4020
3834
  get state() {
4021
3835
  if (!this.#stateEnabled) {
4022
3836
  throw stateNotEnabledError();
4023
3837
  }
3838
+ const actorState = getNativePersistState(this.#runtime, this.#ctx);
4024
3839
  const nextState = this.#readState();
4025
- return createWriteThroughProxy(
4026
- nextState,
4027
- (nextValue) => {
4028
- this.#writeState(nextValue, { scheduleSave: true });
4029
- },
4030
- (newValue) => {
4031
- this.#assertCanMutateState();
4032
- _chunkFEOG44WHcjs.assertJsonCompatValue.call(void 0, newValue);
4033
- }
4034
- );
3840
+ if (actorState.stateProxy === void 0 || actorState.stateProxyTarget !== nextState) {
3841
+ actorState.stateProxyTarget = nextState;
3842
+ actorState.stateProxy = createWriteThroughProxy(
3843
+ nextState,
3844
+ (nextValue) => {
3845
+ this.#writeState(nextValue, { scheduleSave: true });
3846
+ },
3847
+ () => {
3848
+ this.#assertCanMutateState();
3849
+ }
3850
+ );
3851
+ }
3852
+ return actorState.stateProxy;
4035
3853
  }
4036
3854
  set state(value) {
4037
3855
  if (!this.#stateEnabled) {
4038
3856
  throw stateNotEnabledError();
4039
3857
  }
4040
3858
  this.#assertCanMutateState();
4041
- _chunkFEOG44WHcjs.assertJsonCompatValue.call(void 0, value);
4042
3859
  this.#writeState(value, { scheduleSave: true });
4043
3860
  }
4044
3861
  initializeState(value) {
@@ -4095,10 +3912,25 @@ var ActorContextHandleAdapter = class {
4095
3912
  return callNativeSync(() => this.#runtime.actorRegion(this.#ctx));
4096
3913
  }
4097
3914
  get conns() {
4098
- if (!this.#connMap) {
4099
- this.#connMap = new NativeConnectionMap(this.#runtime, this.#ctx, this.#schemas);
4100
- }
4101
- return this.#connMap;
3915
+ return new Map(
3916
+ callNativeSync(() => this.#runtime.actorConns(this.#ctx)).map(
3917
+ (conn) => [
3918
+ this.#runtime.connId(conn),
3919
+ new NativeConnAdapter(
3920
+ this.#runtime,
3921
+ conn,
3922
+ this.#schemas,
3923
+ this.#ctx,
3924
+ (connId) => callNativeSync(
3925
+ () => this.#runtime.actorQueueHibernationRemoval(
3926
+ this.#ctx,
3927
+ connId
3928
+ )
3929
+ )
3930
+ )
3931
+ ]
3932
+ )
3933
+ );
4102
3934
  }
4103
3935
  get log() {
4104
3936
  return logger2();
@@ -4296,39 +4128,20 @@ var ActorContextHandleAdapter = class {
4296
4128
  });
4297
4129
  }
4298
4130
  keepAwake(promise) {
4299
- const startedAt = Date.now();
4300
- logger2().debug({
4301
- msg: "keepAwake registered",
4302
- at: startedAt
4303
- });
4304
- const trackedPromise = Promise.resolve(promise).then(
4305
- () => {
4306
- logger2().debug({
4307
- msg: "keepAwake promise resolved",
4308
- durationMs: Date.now() - startedAt
4309
- });
4310
- },
4311
- (error) => {
4312
- logger2().warn({
4313
- msg: "keepAwake promise rejected",
4314
- durationMs: Date.now() - startedAt,
4315
- error: _chunkX6HIFXNKcjs.stringifyError.call(void 0, error)
4316
- });
4317
- }
4318
- ).then(() => null);
4131
+ const trackedPromise = Promise.resolve(promise).catch((error) => {
4132
+ logger2().warn({
4133
+ msg: "keepAwake promise rejected",
4134
+ error: _chunkY5NSCZA2cjs.stringifyError.call(void 0, error)
4135
+ });
4136
+ }).then(() => null);
4319
4137
  try {
4320
4138
  callNativeSync(
4321
4139
  () => this.#runtime.actorKeepAwake(this.#ctx, trackedPromise)
4322
4140
  );
4323
4141
  } catch (error) {
4324
- if (isClosedTaskRegistrationError(error)) {
4325
- logger2().warn({
4326
- msg: "keepAwake registration dropped (teardown already started); promise will not delay grace",
4327
- error: _chunkX6HIFXNKcjs.stringifyError.call(void 0, error)
4328
- });
4329
- return promise;
4142
+ if (!isClosedTaskRegistrationError(error)) {
4143
+ throw error;
4330
4144
  }
4331
- throw error;
4332
4145
  }
4333
4146
  return promise;
4334
4147
  }
@@ -4411,6 +4224,7 @@ var ActorContextHandleAdapter = class {
4411
4224
  }
4412
4225
  async dispose() {
4413
4226
  var _a;
4227
+ this.#flushStateChange();
4414
4228
  (_a = this.#abortSignalCleanup) == null ? void 0 : _a.call(this);
4415
4229
  this.#sql = void 0;
4416
4230
  }
@@ -4438,13 +4252,12 @@ var ActorContextHandleAdapter = class {
4438
4252
  return actorState.state;
4439
4253
  }
4440
4254
  #writeState(value, options) {
4441
- encodeValue(value);
4442
4255
  const actorState = getNativePersistState(this.#runtime, this.#ctx);
4443
4256
  actorState.state = value;
4444
4257
  if (!options.scheduleSave) {
4445
4258
  return;
4446
4259
  }
4447
- this.#handleStateChange();
4260
+ this.#scheduleSave();
4448
4261
  }
4449
4262
  #assertCanMutateState() {
4450
4263
  const actorState = getNativePersistState(this.#runtime, this.#ctx);
@@ -4452,9 +4265,31 @@ var ActorContextHandleAdapter = class {
4452
4265
  throw stateMutationReentrantError();
4453
4266
  }
4454
4267
  }
4455
- #handleStateChange() {
4268
+ // Coalesce the request-save and onStateChange work to once per event loop
4269
+ // tick. A synchronous burst of mutations (for example
4270
+ // `Object.assign(c.state, ...)`) would otherwise cross the NAPI boundary and
4271
+ // run onStateChange once per field, re-serializing the whole state each time
4272
+ // and pinning the event loop on large state.
4273
+ #scheduleSave() {
4456
4274
  const actorState = getNativePersistState(this.#runtime, this.#ctx);
4457
- encodeValue(actorState.state);
4275
+ if (actorState.saveScheduled) {
4276
+ return;
4277
+ }
4278
+ actorState.saveScheduled = true;
4279
+ actorState.pendingSaveHandle = setImmediate(() => {
4280
+ this.#flushStateChange();
4281
+ });
4282
+ }
4283
+ #flushStateChange() {
4284
+ const actorState = getNativePersistState(this.#runtime, this.#ctx);
4285
+ if (!actorState.saveScheduled) {
4286
+ return;
4287
+ }
4288
+ actorState.saveScheduled = false;
4289
+ if (actorState.pendingSaveHandle !== void 0) {
4290
+ clearImmediate(actorState.pendingSaveHandle);
4291
+ actorState.pendingSaveHandle = void 0;
4292
+ }
4458
4293
  callNativeSync(
4459
4294
  () => this.#runtime.actorRequestSave(this.#ctx, { immediate: false })
4460
4295
  );
@@ -4677,9 +4512,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4677
4512
  const actionHandlers = Object.fromEntries(
4678
4513
  Object.entries(_nullishCoalesce(config.actions, () => ( {}))).map(([name, handler]) => [name, handler])
4679
4514
  );
4680
- const createClient = () => _chunkZGPX6KAHcjs.createClientWithDriver.call(void 0,
4681
- new (0, _chunkZGPX6KAHcjs.RemoteEngineControlClient)(
4682
- _chunkZGPX6KAHcjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
4515
+ const createClient = () => _chunkGVTOE34Scjs.createClientWithDriver.call(void 0,
4516
+ new (0, _chunkGVTOE34Scjs.RemoteEngineControlClient)(
4517
+ _chunkGVTOE34Scjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
4683
4518
  ),
4684
4519
  { encoding: "bare" }
4685
4520
  );
@@ -4689,7 +4524,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4689
4524
  ), () => ( false));
4690
4525
  const getNativeWorkflowInspector = (ctx) => {
4691
4526
  var _a2;
4692
- return (_a2 = _chunkSRNOPUC6cjs.getRunInspectorConfig.call(void 0,
4527
+ return (_a2 = _chunkWQ4HNA4Wcjs.getRunInspectorConfig.call(void 0,
4693
4528
  config.run,
4694
4529
  callNativeSync(() => runtime.actorId(ctx))
4695
4530
  )) == null ? void 0 : _a2.workflow;
@@ -4742,7 +4577,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4742
4577
  }
4743
4578
  });
4744
4579
  const errorResponse = (error, status) => {
4745
- const rivetError = _chunk63WNTDRCcjs.toRivetError.call(void 0, error);
4580
+ const rivetError = _chunkQAZLM4WTcjs.toRivetError.call(void 0, error);
4746
4581
  return jsonResponse(
4747
4582
  {
4748
4583
  group: rivetError.group,
@@ -4852,10 +4687,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4852
4687
  isWorkflowEnabled: getNativeWorkflowInspector(ctx) !== void 0
4853
4688
  });
4854
4689
  } catch (error) {
4855
- logger2().error({
4856
- msg: "error replaying workflow history",
4857
- error
4858
- });
4859
4690
  return errorResponse(error);
4860
4691
  }
4861
4692
  }
@@ -4987,7 +4818,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
4987
4818
  const action = actionHandlers[actionName];
4988
4819
  if (!action) {
4989
4820
  return errorResponse(
4990
- new (0, _chunk63WNTDRCcjs.RivetError)(
4821
+ new (0, _chunkQAZLM4WTcjs.RivetError)(
4991
4822
  "action",
4992
4823
  "action_not_found",
4993
4824
  `Action ${actionName} not found`
@@ -5007,10 +4838,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5007
4838
  );
5008
4839
  return jsonResponse({ output });
5009
4840
  } catch (error) {
5010
- logger2().error({
5011
- msg: "Error handling inspector action request",
5012
- error
5013
- });
5014
4841
  return errorResponse(error);
5015
4842
  }
5016
4843
  }
@@ -5024,10 +4851,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5024
4851
  { status: 404 }
5025
4852
  );
5026
4853
  } catch (error) {
5027
- logger2().error({
5028
- msg: "Error handling inspector request",
5029
- error
5030
- });
5031
4854
  return errorResponse(error);
5032
4855
  } finally {
5033
4856
  await actorCtx.dispose();
@@ -5332,7 +5155,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5332
5155
  );
5333
5156
  }
5334
5157
  if (!result) {
5335
- throw _chunk63WNTDRCcjs.forbiddenError.call(void 0, );
5158
+ throw _chunkQAZLM4WTcjs.forbiddenError.call(void 0, );
5336
5159
  }
5337
5160
  } finally {
5338
5161
  await actorCtx.dispose();
@@ -5378,7 +5201,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5378
5201
  new Response(null, { status: 404 })
5379
5202
  );
5380
5203
  }
5381
- const rawConnParams = jsRequest.headers.get(_chunkZGPX6KAHcjs.HEADER_CONN_PARAMS);
5204
+ const rawConnParams = jsRequest.headers.get(_chunkGVTOE34Scjs.HEADER_CONN_PARAMS);
5382
5205
  let requestCtx;
5383
5206
  let conn;
5384
5207
  try {
@@ -5443,7 +5266,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5443
5266
  }
5444
5267
  ) : void 0,
5445
5268
  run: (() => {
5446
- const run = _chunkSRNOPUC6cjs.getRunFunction.call(void 0, config.run);
5269
+ const run = _chunkWQ4HNA4Wcjs.getRunFunction.call(void 0, config.run);
5447
5270
  if (!run) {
5448
5271
  return void 0;
5449
5272
  }
@@ -5462,7 +5285,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5462
5285
  }
5463
5286
  );
5464
5287
  })(),
5465
- getWorkflowHistory: _chunkSRNOPUC6cjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5288
+ getWorkflowHistory: _chunkWQ4HNA4Wcjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5466
5289
  async (error, payload) => {
5467
5290
  var _a2;
5468
5291
  const { ctx } = unwrapTsfnPayload(error, payload);
@@ -5470,7 +5293,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5470
5293
  return history == null ? void 0 : encodeValue(history);
5471
5294
  }
5472
5295
  ) : void 0,
5473
- replayWorkflow: _chunkSRNOPUC6cjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5296
+ replayWorkflow: _chunkWQ4HNA4Wcjs.getRunInspectorConfig.call(void 0, config.run) !== void 0 ? wrapNativeCallback(
5474
5297
  async (error, payload) => {
5475
5298
  const { ctx, entryId } = unwrapTsfnPayload(
5476
5299
  error,
@@ -5545,7 +5368,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5545
5368
  name
5546
5369
  );
5547
5370
  if (canPublish && !await canPublish(actorCtx)) {
5548
- throw _chunk63WNTDRCcjs.forbiddenError.call(void 0, );
5371
+ throw _chunkQAZLM4WTcjs.forbiddenError.call(void 0, );
5549
5372
  }
5550
5373
  const decodedBody = decodeValue(body);
5551
5374
  if (wait) {
@@ -5605,7 +5428,7 @@ async function buildServeConfig(config) {
5605
5428
  poolName: config.envoy.poolName,
5606
5429
  handleInspectorHttpInRuntime: true,
5607
5430
  serverlessBasePath: config.serverless.basePath,
5608
- serverlessPackageVersion: _chunkX6HIFXNKcjs.VERSION,
5431
+ serverlessPackageVersion: _chunkY5NSCZA2cjs.VERSION,
5609
5432
  serverlessClientEndpoint: config.publicEndpoint,
5610
5433
  serverlessClientNamespace: config.publicNamespace,
5611
5434
  serverlessClientToken: config.publicToken,
@@ -5617,13 +5440,13 @@ async function buildServeConfig(config) {
5617
5440
  serveConfig.engineBinaryPath = getEnginePath();
5618
5441
  }
5619
5442
  if ((_a = config.test) == null ? void 0 : _a.enabled) {
5620
- serveConfig.inspectorTestToken = _nullishCoalesce(_chunkX6HIFXNKcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
5443
+ serveConfig.inspectorTestToken = _nullishCoalesce(_chunkY5NSCZA2cjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
5621
5444
  }
5622
5445
  return serveConfig;
5623
5446
  }
5624
5447
  async function buildRegistryWithRuntime(config, runtime) {
5625
5448
  var _a;
5626
- if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkX6HIFXNKcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
5449
+ if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkY5NSCZA2cjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
5627
5450
  trySetProcessEnv("_RIVET_TEST_INSPECTOR_TOKEN", "token");
5628
5451
  }
5629
5452
  const registry = runtime.createRegistry();
@@ -5642,10 +5465,6 @@ async function buildRegistryWithRuntime(config, runtime) {
5642
5465
  }
5643
5466
  async function buildConfiguredRegistry(config) {
5644
5467
  const runtime = await loadConfiguredRuntime(config);
5645
- if (runtime.kind === "napi") {
5646
- const { startProcessMetrics } = await Promise.resolve().then(() => _interopRequireWildcard(require("./process-metrics-TYAGKCEJ.cjs")));
5647
- startProcessMetrics();
5648
- }
5649
5468
  return buildRegistryWithRuntime(
5650
5469
  normalizeRuntimeConfig(config, runtime),
5651
5470
  runtime
@@ -5669,6 +5488,7 @@ function finishShutdownSignal(signal) {
5669
5488
  }
5670
5489
  var Registry = class {
5671
5490
  #config;
5491
+
5672
5492
  get config() {
5673
5493
  return this.#config;
5674
5494
  }
@@ -5685,6 +5505,11 @@ var Registry = class {
5685
5505
  #signalHandlers = {};
5686
5506
  constructor(config) {
5687
5507
  this.#config = config;
5508
+ this.routes = {
5509
+ health: () => this.#healthRoute(),
5510
+ metadata: () => this.#metadataRoute(),
5511
+ prometheusMetrics: (request) => this.#prometheusMetricsRoute(request)
5512
+ };
5688
5513
  }
5689
5514
  #ensureServerlessPoolConfigured(config) {
5690
5515
  if (!config.configurePool) return void 0;
@@ -5878,46 +5703,88 @@ var Registry = class {
5878
5703
  };
5879
5704
  }
5880
5705
  /**
5881
- * Starts an HTTP server that dispatches every request through the
5882
- * serverless handler. Uses `crossPlatformServe` to pick the right
5883
- * runtime (Node, Bun, Deno).
5884
- *
5885
- * @param opts.port Port to listen on. Defaults to 3000.
5886
- * @param opts.publicDir If set, serves static files from this directory
5887
- * before falling through to the registry handler.
5888
- *
5889
- * @example
5890
- * ```ts
5891
- * await registry.listen();
5892
- * await registry.listen({ port: 8080, publicDir: "./public" });
5893
- * ```
5706
+ * Returns a health response suitable for mounting in a user-owned router.
5894
5707
  */
5895
- async listen(opts = {}) {
5896
- const port = _nullishCoalesce(opts.port, () => ( 3e3));
5897
- const config = this.parseConfig();
5898
- const runtime = _chunkX6HIFXNKcjs.detectRuntime.call(void 0, );
5899
- const app = new (0, _hono.Hono)();
5900
- if (opts.publicDir) {
5901
- const serveStatic = await loadRuntimeServeStatic(runtime);
5902
- app.use("*", serveStatic({ root: opts.publicDir }));
5708
+ async #healthRoute() {
5709
+ const configured = await this.#activeConfiguredRegistry();
5710
+ if (!configured) {
5711
+ return jsonRouteResponse(503, {
5712
+ status: "not_started",
5713
+ runtime: "rivetkit",
5714
+ version: _chunkY5NSCZA2cjs.VERSION
5715
+ });
5716
+ }
5717
+ const { runtime, registry } = configured;
5718
+ if (!runtime.registryHealth) {
5719
+ return jsonRouteResponse(501, {
5720
+ status: "unsupported",
5721
+ runtime: "rivetkit",
5722
+ version: _chunkY5NSCZA2cjs.VERSION
5723
+ });
5903
5724
  }
5904
- app.all("*", (c) => this.handler(c.req.raw));
5905
- await crossPlatformServe(config, port, app, runtime);
5725
+ const response = await runtime.registryHealth(registry);
5726
+ return new Response(new Uint8Array(response.body), {
5727
+ status: response.status,
5728
+ headers: response.headers
5729
+ });
5906
5730
  }
5907
- async diagnostics() {
5908
- var _a;
5731
+ /**
5732
+ * Returns serverless metadata suitable for mounting in a user-owned router.
5733
+ */
5734
+ async #metadataRoute() {
5735
+ const configured = await this.#activeConfiguredRegistry();
5736
+ if (!configured) {
5737
+ return new Response("registry not started\n", {
5738
+ status: 503,
5739
+ headers: { "content-type": "text/plain; charset=utf-8" }
5740
+ });
5741
+ }
5742
+ const { runtime, registry } = configured;
5743
+ if (!runtime.registryMetadata) {
5744
+ return new Response("metadata is not supported by this runtime\n", {
5745
+ status: 501,
5746
+ headers: { "content-type": "text/plain; charset=utf-8" }
5747
+ });
5748
+ }
5749
+ const response = await runtime.registryMetadata(registry);
5750
+ return new Response(new Uint8Array(response.body), {
5751
+ status: response.status,
5752
+ headers: response.headers
5753
+ });
5754
+ }
5755
+ /**
5756
+ * Returns a Prometheus metrics response suitable for mounting in a user-owned router.
5757
+ */
5758
+ async #prometheusMetricsRoute(_request) {
5759
+ const configured = await this.#activeConfiguredRegistry();
5760
+ if (!configured) {
5761
+ return new Response("registry not started\n", {
5762
+ status: 503,
5763
+ headers: { "content-type": "text/plain; charset=utf-8" }
5764
+ });
5765
+ }
5766
+ const { runtime, registry } = configured;
5767
+ if (!runtime.registryMetrics) {
5768
+ return new Response("metrics are not supported by this runtime\n", {
5769
+ status: 501,
5770
+ headers: { "content-type": "text/plain; charset=utf-8" }
5771
+ });
5772
+ }
5773
+ const response = await runtime.registryMetrics(registry);
5774
+ return new Response(new Uint8Array(response.body), {
5775
+ status: response.status,
5776
+ headers: response.headers
5777
+ });
5778
+ }
5779
+ async #activeConfiguredRegistry() {
5909
5780
  const candidates = [
5910
5781
  this.#runtimeServerlessPromise,
5911
5782
  this.#runtimeServeConfiguredPromise
5912
5783
  ].filter(
5913
5784
  (candidate) => candidate !== void 0
5914
5785
  );
5915
- for (const candidate of candidates) {
5916
- const { runtime, registry } = await candidate;
5917
- const diagnostics = await ((_a = runtime.registryDiagnostics) == null ? void 0 : _a.call(runtime, registry));
5918
- if (diagnostics) return diagnostics;
5919
- }
5920
- return { mode: "not_started", envoyActiveActorCount: null };
5786
+ if (candidates.length === 0) return void 0;
5787
+ return await candidates[0];
5921
5788
  }
5922
5789
  /**
5923
5790
  * Starts an actor envoy for standalone server deployments.
@@ -5928,8 +5795,8 @@ var Registry = class {
5928
5795
  this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
5929
5796
  this.#runtimeServePromise = configuredRegistryPromise.then(async ({ runtime, registry, serveConfig }) => {
5930
5797
  await runtime.serveRegistry(registry, serveConfig);
5931
- }).catch((error) => {
5932
- logger2().warn({ error }, "runtime registry serve errored");
5798
+ }).catch((err) => {
5799
+ logger2().warn({ err }, "runtime registry serve errored");
5933
5800
  });
5934
5801
  this.#installSignalHandlers(config, configuredRegistryPromise);
5935
5802
  }
@@ -5967,8 +5834,8 @@ var Registry = class {
5967
5834
  signal,
5968
5835
  config,
5969
5836
  configuredRegistryPromise
5970
- ).catch((error) => {
5971
- logger2().warn({ error }, "shutdown error");
5837
+ ).catch((err) => {
5838
+ logger2().warn({ err }, "shutdown error");
5972
5839
  });
5973
5840
  }
5974
5841
  async #runShutdown(signal, config, configuredRegistryPromise) {
@@ -5980,9 +5847,9 @@ var Registry = class {
5980
5847
  try {
5981
5848
  const { runtime, registry } = await configuredRegistryPromise;
5982
5849
  await runtime.shutdownRegistry(registry);
5983
- } catch (error) {
5850
+ } catch (err) {
5984
5851
  logger2().warn(
5985
- { error },
5852
+ { err },
5986
5853
  "runtime registry shutdown errored (mode A)"
5987
5854
  );
5988
5855
  }
@@ -5997,7 +5864,7 @@ var Registry = class {
5997
5864
  await runtime.shutdownRegistry(registry);
5998
5865
  } catch (err) {
5999
5866
  logger2().warn(
6000
- { error: err },
5867
+ { err },
6001
5868
  "runtime registry shutdown errored (mode B)"
6002
5869
  );
6003
5870
  }
@@ -6071,7 +5938,7 @@ var Registry = class {
6071
5938
  };
6072
5939
  console.log();
6073
5940
  console.log(
6074
- ` RivetKit ${_chunkX6HIFXNKcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
5941
+ ` RivetKit ${_chunkY5NSCZA2cjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
6075
5942
  );
6076
5943
  if (config.namespace !== "default") {
6077
5944
  logLine("Namespace", config.namespace);
@@ -6099,6 +5966,12 @@ function isServerlessMetadataRequest(request, basePath) {
6099
5966
  const normalizedBase = basePath === "/" ? "" : `/${basePath.replace(/^\/+|\/+$/g, "")}`;
6100
5967
  return parsed.pathname === `${normalizedBase}/metadata`;
6101
5968
  }
5969
+ function jsonRouteResponse(status, body) {
5970
+ return new Response(JSON.stringify(body), {
5971
+ status,
5972
+ headers: { "content-type": "application/json" }
5973
+ });
5974
+ }
6102
5975
  function setup(input) {
6103
5976
  return new Registry(input);
6104
5977
  }
@@ -6133,5 +6006,5 @@ function setup(input) {
6133
6006
 
6134
6007
 
6135
6008
 
6136
- exports.ALLOWED_PUBLIC_HEADERS = _chunkZGPX6KAHcjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunk63WNTDRCcjs.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 = _chunk63WNTDRCcjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunk63WNTDRCcjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunkZGPX6KAHcjs.createClientWithDriver; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkX6HIFXNKcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkX6HIFXNKcjs.toUint8Array;
6009
+ exports.ALLOWED_PUBLIC_HEADERS = _chunkGVTOE34Scjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunkQAZLM4WTcjs.RivetError; exports.ActorsSchema = ActorsSchema; exports.DocConfigurePoolSchema = DocConfigurePoolSchema; exports.DocEnvoyConfigSchema = DocEnvoyConfigSchema; exports.DocRegistryConfigSchema = DocRegistryConfigSchema; exports.DocServerlessConfigSchema = DocServerlessConfigSchema; exports.DocSqliteConfigSchema = DocSqliteConfigSchema; exports.InlineWebSocketAdapter = InlineWebSocketAdapter; exports.Registry = Registry; exports.RegistryConfigSchema = RegistryConfigSchema; exports.RivetError = _chunkQAZLM4WTcjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunkQAZLM4WTcjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunkGVTOE34Scjs.createClientWithDriver; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkY5NSCZA2cjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkY5NSCZA2cjs.toUint8Array;
6137
6010
  //# sourceMappingURL=mod.cjs.map