rivetkit 2.3.12-rc.3 → 2.3.12

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 (109) hide show
  1. package/dist/browser/client.d.ts +17 -2
  2. package/dist/browser/client.js +32 -24
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +2 -1
  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 +2 -1
  9. package/dist/tsup/agent-os/index.cjs.map +1 -1
  10. package/dist/tsup/agent-os/index.d.cts +17 -2
  11. package/dist/tsup/agent-os/index.d.ts +17 -2
  12. package/dist/tsup/agent-os/index.js +2 -1
  13. package/dist/tsup/agent-os/index.js.map +1 -1
  14. package/dist/tsup/{chunk-SPJORZMM.cjs → chunk-2JSYYH6P.cjs} +1 -1
  15. package/dist/tsup/chunk-2JSYYH6P.cjs.map +1 -0
  16. package/dist/tsup/{chunk-IJWTHKH6.cjs → chunk-AN7WO7BM.cjs} +3 -3
  17. package/dist/tsup/{chunk-IJWTHKH6.cjs.map → chunk-AN7WO7BM.cjs.map} +1 -1
  18. package/dist/tsup/{chunk-PSXMESQJ.js → chunk-EBXARMGI.js} +2 -2
  19. package/dist/tsup/{chunk-O6H3BUN4.cjs → chunk-FGQABMXZ.cjs} +3 -3
  20. package/dist/tsup/{chunk-O6H3BUN4.cjs.map → chunk-FGQABMXZ.cjs.map} +1 -1
  21. package/dist/tsup/{chunk-WVFTFWJL.js → chunk-GEN4NHXM.js} +2 -2
  22. package/dist/tsup/{chunk-XI4MEUUI.js → chunk-JYTXOMM7.js} +2 -2
  23. package/dist/tsup/{chunk-OX6WVQE6.cjs → chunk-MEF7RVQ7.cjs} +10 -10
  24. package/dist/tsup/{chunk-OX6WVQE6.cjs.map → chunk-MEF7RVQ7.cjs.map} +1 -1
  25. package/dist/tsup/{chunk-OLGQYFUW.js → chunk-MF42PRF2.js} +9 -3
  26. package/dist/tsup/chunk-MF42PRF2.js.map +1 -0
  27. package/dist/tsup/{chunk-IXBD7BXC.js → chunk-OUQUIBVW.js} +1 -1
  28. package/dist/tsup/chunk-OUQUIBVW.js.map +1 -0
  29. package/dist/tsup/{chunk-QLOBB27M.cjs → chunk-PW2VSGUR.cjs} +4 -4
  30. package/dist/tsup/{chunk-QLOBB27M.cjs.map → chunk-PW2VSGUR.cjs.map} +1 -1
  31. package/dist/tsup/{chunk-NHI5L7C7.js → chunk-RBXJWAJB.js} +3 -3
  32. package/dist/tsup/{chunk-UBB32UOG.cjs → chunk-SSPTEGTX.cjs} +7 -7
  33. package/dist/tsup/{chunk-UBB32UOG.cjs.map → chunk-SSPTEGTX.cjs.map} +1 -1
  34. package/dist/tsup/{chunk-4ESGNS3Z.cjs → chunk-TAG6UEL5.cjs} +17 -11
  35. package/dist/tsup/chunk-TAG6UEL5.cjs.map +1 -0
  36. package/dist/tsup/{chunk-EQKSWDIH.cjs → chunk-TXUHVBKH.cjs} +3 -3
  37. package/dist/tsup/{chunk-EQKSWDIH.cjs.map → chunk-TXUHVBKH.cjs.map} +1 -1
  38. package/dist/tsup/{chunk-PZBWSCQR.cjs → chunk-TZPNSOG2.cjs} +203 -195
  39. package/dist/tsup/chunk-TZPNSOG2.cjs.map +1 -0
  40. package/dist/tsup/{chunk-YYIDQBBM.js → chunk-VOYNLY57.js} +41 -33
  41. package/dist/tsup/chunk-VOYNLY57.js.map +1 -0
  42. package/dist/tsup/{chunk-UN5JNDBT.js → chunk-XUODFCRJ.js} +4 -4
  43. package/dist/tsup/{chunk-34Q4YVCX.js → chunk-ZIPXAVKR.js} +2 -2
  44. package/dist/tsup/client/mod.cjs +6 -6
  45. package/dist/tsup/client/mod.d.cts +2 -2
  46. package/dist/tsup/client/mod.d.ts +2 -2
  47. package/dist/tsup/client/mod.js +5 -5
  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-Bi1r6gI7.d.ts → config-BGTanB_3.d.ts} +18 -2
  53. package/dist/tsup/{config-BXSV17G7.d.cts → config-NHz6oMb9.d.cts} +18 -2
  54. package/dist/tsup/{context-4fJemY0D.d.cts → context-DB8zG_Ib.d.cts} +1 -1
  55. package/dist/tsup/{context-D4sNYboo.d.ts → context-SHomdVV8.d.ts} +1 -1
  56. package/dist/tsup/db/drizzle.cjs +3 -3
  57. package/dist/tsup/db/drizzle.js +2 -2
  58. package/dist/tsup/db/mod.cjs +4 -4
  59. package/dist/tsup/db/mod.js +3 -3
  60. package/dist/tsup/dynamic/mod.d.cts +1 -1
  61. package/dist/tsup/dynamic/mod.d.ts +1 -1
  62. package/dist/tsup/inspector/mod.cjs +6 -6
  63. package/dist/tsup/inspector/mod.js +5 -5
  64. package/dist/tsup/inspector/workflow.cjs +5 -5
  65. package/dist/tsup/inspector/workflow.js +4 -4
  66. package/dist/tsup/inspector-tab/mod.d.cts +2 -2
  67. package/dist/tsup/inspector-tab/mod.d.ts +2 -2
  68. package/dist/tsup/mod.cjs +423 -177
  69. package/dist/tsup/mod.cjs.map +1 -1
  70. package/dist/tsup/mod.d.cts +3 -3
  71. package/dist/tsup/mod.d.ts +3 -3
  72. package/dist/tsup/mod.js +322 -76
  73. package/dist/tsup/mod.js.map +1 -1
  74. package/dist/tsup/test/mod.cjs +7 -7
  75. package/dist/tsup/test/mod.d.cts +1 -1
  76. package/dist/tsup/test/mod.d.ts +1 -1
  77. package/dist/tsup/test/mod.js +5 -5
  78. package/dist/tsup/utils.cjs +3 -3
  79. package/dist/tsup/utils.js +2 -2
  80. package/dist/tsup/workflow/mod.cjs +11 -11
  81. package/dist/tsup/workflow/mod.d.cts +3 -3
  82. package/dist/tsup/workflow/mod.d.ts +3 -3
  83. package/dist/tsup/workflow/mod.js +5 -5
  84. package/package.json +9 -8
  85. package/src/actor/errors.ts +2 -1
  86. package/src/client/actor-handle.ts +10 -3
  87. package/src/client/raw-utils.ts +8 -0
  88. package/src/common/actor-router-consts.ts +2 -0
  89. package/src/engine-client/actor-http-client.ts +6 -22
  90. package/src/engine-client/mod.ts +1 -1
  91. package/src/registry/config/index.ts +27 -1
  92. package/src/registry/index.ts +48 -14
  93. package/src/registry/napi-runtime.ts +32 -5
  94. package/src/registry/native-http.ts +225 -0
  95. package/src/registry/native.ts +130 -64
  96. package/src/registry/runtime.ts +30 -2
  97. package/src/utils/env-vars.ts +4 -0
  98. package/dist/tsup/chunk-4ESGNS3Z.cjs.map +0 -1
  99. package/dist/tsup/chunk-IXBD7BXC.js.map +0 -1
  100. package/dist/tsup/chunk-OLGQYFUW.js.map +0 -1
  101. package/dist/tsup/chunk-PZBWSCQR.cjs.map +0 -1
  102. package/dist/tsup/chunk-SPJORZMM.cjs.map +0 -1
  103. package/dist/tsup/chunk-YYIDQBBM.js.map +0 -1
  104. /package/dist/tsup/{chunk-PSXMESQJ.js.map → chunk-EBXARMGI.js.map} +0 -0
  105. /package/dist/tsup/{chunk-WVFTFWJL.js.map → chunk-GEN4NHXM.js.map} +0 -0
  106. /package/dist/tsup/{chunk-XI4MEUUI.js.map → chunk-JYTXOMM7.js.map} +0 -0
  107. /package/dist/tsup/{chunk-NHI5L7C7.js.map → chunk-RBXJWAJB.js.map} +0 -0
  108. /package/dist/tsup/{chunk-UN5JNDBT.js.map → chunk-XUODFCRJ.js.map} +0 -0
  109. /package/dist/tsup/{chunk-34Q4YVCX.js.map → chunk-ZIPXAVKR.js.map} +0 -0
package/dist/tsup/mod.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2; var _class3;
2
2
 
3
- var _chunkQLOBB27Mcjs = require('./chunk-QLOBB27M.cjs');
3
+ var _chunkPW2VSGURcjs = require('./chunk-PW2VSGUR.cjs');
4
4
 
5
5
 
6
6
 
@@ -27,18 +27,19 @@ var _chunk4KGXFC6Mcjs = require('./chunk-4KGXFC6M.cjs');
27
27
 
28
28
 
29
29
 
30
- var _chunkPZBWSCQRcjs = require('./chunk-PZBWSCQR.cjs');
30
+
31
+ var _chunkTZPNSOG2cjs = require('./chunk-TZPNSOG2.cjs');
31
32
 
32
33
 
33
34
 
34
35
  var _chunkMYWZCDMLcjs = require('./chunk-MYWZCDML.cjs');
36
+ require('./chunk-TXUHVBKH.cjs');
35
37
 
36
38
 
37
39
 
38
40
 
39
- var _chunkO6H3BUN4cjs = require('./chunk-O6H3BUN4.cjs');
41
+ var _chunkFGQABMXZcjs = require('./chunk-FGQABMXZ.cjs');
40
42
  require('./chunk-KVFIONKQ.cjs');
41
- require('./chunk-EQKSWDIH.cjs');
42
43
 
43
44
 
44
45
 
@@ -71,7 +72,8 @@ require('./chunk-EQKSWDIH.cjs');
71
72
 
72
73
 
73
74
 
74
- var _chunk4ESGNS3Zcjs = require('./chunk-4ESGNS3Z.cjs');
75
+
76
+ var _chunkTAG6UEL5cjs = require('./chunk-TAG6UEL5.cjs');
75
77
 
76
78
 
77
79
 
@@ -83,11 +85,11 @@ var _chunk4ESGNS3Zcjs = require('./chunk-4ESGNS3Z.cjs');
83
85
 
84
86
 
85
87
 
86
- var _chunkSPJORZMMcjs = require('./chunk-SPJORZMM.cjs');
88
+ var _chunk2JSYYH6Pcjs = require('./chunk-2JSYYH6P.cjs');
87
89
 
88
90
  // src/actor/log.ts
89
91
  function loggerWithoutContext() {
90
- return _chunk4ESGNS3Zcjs.getLogger.call(void 0, "actor-runtime");
92
+ return _chunkTAG6UEL5cjs.getLogger.call(void 0, "actor-runtime");
91
93
  }
92
94
 
93
95
  // src/actor/definition.ts
@@ -210,7 +212,7 @@ function validateSchemaSync(schemas, key, data) {
210
212
  if (isStandardSchema(schema)) {
211
213
  const result = schema["~standard"].validate(data);
212
214
  if (isPromiseLike(result)) {
213
- throw _chunkSPJORZMMcjs.unsupportedFeature.call(void 0, "async schema validation");
215
+ throw _chunk2JSYYH6Pcjs.unsupportedFeature.call(void 0, "async schema validation");
214
216
  }
215
217
  if (result.issues) {
216
218
  return { success: false, issues: [...result.issues] };
@@ -227,7 +229,7 @@ function validateSchemaSync(schemas, key, data) {
227
229
  var _virtualwebsocket = require('@rivetkit/virtual-websocket');
228
230
  var _ws = require('hono/ws');
229
231
  function logger() {
230
- return _chunk4ESGNS3Zcjs.getLogger.call(void 0, "inline-websocket-adapter");
232
+ return _chunkTAG6UEL5cjs.getLogger.call(void 0, "inline-websocket-adapter");
231
233
  }
232
234
  var InlineWebSocketAdapter = class {
233
235
  #handler;
@@ -398,7 +400,7 @@ function isLocalEngineEndpoint(endpoint) {
398
400
 
399
401
  // src/registry/log.ts
400
402
  function logger2() {
401
- return _chunk4ESGNS3Zcjs.getLogger.call(void 0, "registry");
403
+ return _chunkTAG6UEL5cjs.getLogger.call(void 0, "registry");
402
404
  }
403
405
 
404
406
  // src/serverless/configure.ts
@@ -444,8 +446,8 @@ async function configureServerlessPool(config) {
444
446
  );
445
447
  }
446
448
  const customConfig = config.configurePool;
447
- const clientConfig = _chunkPZBWSCQRcjs.convertRegistryConfigToClientConfig.call(void 0, config);
448
- const dcsRes = await _chunkPZBWSCQRcjs.getDatacenters.call(void 0, clientConfig);
449
+ const clientConfig = _chunkTZPNSOG2cjs.convertRegistryConfigToClientConfig.call(void 0, config);
450
+ const dcsRes = await _chunkTZPNSOG2cjs.getDatacenters.call(void 0, clientConfig);
449
451
  const poolName = _nullishCoalesce(customConfig.name, () => ( "default"));
450
452
  const serverlessToken = _nullishCoalesce(config.token, () => ( config.publicToken));
451
453
  const headers = {
@@ -467,7 +469,7 @@ async function configureServerlessPool(config) {
467
469
  metadata: _nullishCoalesce(customConfig.metadata, () => ( {})),
468
470
  drain_on_version_upgrade: _nullishCoalesce(customConfig.drainOnVersionUpgrade, () => ( true))
469
471
  };
470
- await _chunkPZBWSCQRcjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
472
+ await _chunkTZPNSOG2cjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
471
473
  datacenters: Object.fromEntries(
472
474
  dcsRes.datacenters.map((dc) => [dc.name, serverlessConfig])
473
475
  )
@@ -484,7 +486,7 @@ async function configureServerlessPool(config) {
484
486
  logger2().warn({
485
487
  msg: "serverless pool configuration attempt failed",
486
488
  attempts,
487
- error: _chunk4ESGNS3Zcjs.stringifyError.call(void 0, error)
489
+ error: _chunkTAG6UEL5cjs.stringifyError.call(void 0, error)
488
490
  });
489
491
  await sleep(CONFIGURE_RETRY_DELAY_MS);
490
492
  }
@@ -492,7 +494,7 @@ async function configureServerlessPool(config) {
492
494
  logger2().error({
493
495
  msg: "failed to configure serverless pool, validate endpoint is configured correctly then restart this process",
494
496
  attempts,
495
- error: _chunk4ESGNS3Zcjs.stringifyError.call(void 0, lastError)
497
+ error: _chunkTAG6UEL5cjs.stringifyError.call(void 0, lastError)
496
498
  });
497
499
  throw lastError;
498
500
  }
@@ -504,20 +506,20 @@ var _zod = require('zod');
504
506
  var _v4 = require('zod/v4');
505
507
  var warnedMissingVersion = false;
506
508
  var EnvoyConfigSchema = _v4.z.object({
507
- poolName: _v4.z.string().default(() => _nullishCoalesce(_chunk4ESGNS3Zcjs.getRivetPool.call(void 0, ), () => ( "default"))),
509
+ poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkTAG6UEL5cjs.getRivetPool.call(void 0, ), () => ( "default"))),
508
510
  version: _v4.z.number().default(() => {
509
- const version = _chunk4ESGNS3Zcjs.getRivetEnvoyVersion.call(void 0, );
511
+ const version = _chunkTAG6UEL5cjs.getRivetEnvoyVersion.call(void 0, );
510
512
  if (version !== void 0) return version;
511
- if (_chunk4ESGNS3Zcjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
513
+ if (_chunkTAG6UEL5cjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
512
514
  warnedMissingVersion = true;
513
- _chunk4ESGNS3Zcjs.getLogger.call(void 0, "rivetkit").error(
515
+ _chunkTAG6UEL5cjs.getLogger.call(void 0, "rivetkit").error(
514
516
  "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"
515
517
  );
516
518
  }
517
519
  return 1;
518
520
  }),
519
521
  // Deprecated.
520
- totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunk4ESGNS3Zcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
522
+ totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkTAG6UEL5cjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
521
523
  envoyKey: _v4.z.string().optional()
522
524
  });
523
525
 
@@ -555,7 +557,7 @@ var ServerlessConfigSchema = _v4.z.object({
555
557
  *
556
558
  * Can also be set via RIVET_PUBLIC_ENDPOINT environment variable.
557
559
  */
558
- publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk4ESGNS3Zcjs.getRivetPublicEndpoint.call(void 0, )))),
560
+ publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkTAG6UEL5cjs.getRivetPublicEndpoint.call(void 0, )))),
559
561
  /**
560
562
  * Token that clients should use when connecting via the public endpoint.
561
563
  *
@@ -563,7 +565,7 @@ var ServerlessConfigSchema = _v4.z.object({
563
565
  *
564
566
  * Can also be specified in the publicEndpoint URL as `https://namespace:token@host`.
565
567
  */
566
- publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk4ESGNS3Zcjs.getRivetPublicToken.call(void 0, ))))
568
+ publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkTAG6UEL5cjs.getRivetPublicToken.call(void 0, ))))
567
569
  // There is no publicNamespace config option because the frontend and backend
568
570
  // cannot use different namespaces. The namespace is extracted from the
569
571
  // publicEndpoint URL auth syntax if provided.
@@ -617,7 +619,7 @@ var RegistryConfigSchema = _zod.z.object({
617
619
  * Runtime binding to use for RivetKit core.
618
620
  * */
619
621
  runtime: RuntimeKindSchema.optional().transform((val, ctx) => {
620
- const rawRuntime = _nullishCoalesce(val, () => ( _chunk4ESGNS3Zcjs.getRivetkitRuntime.call(void 0, )));
622
+ const rawRuntime = _nullishCoalesce(val, () => ( _chunkTAG6UEL5cjs.getRivetkitRuntime.call(void 0, )));
621
623
  if (rawRuntime === void 0) {
622
624
  return "auto";
623
625
  }
@@ -654,7 +656,7 @@ var RegistryConfigSchema = _zod.z.object({
654
656
  * */
655
657
  logging: _zod.z.object({
656
658
  baseLogger: _zod.z.custom().optional(),
657
- level: _chunk4ESGNS3Zcjs.LogLevelSchema.optional()
659
+ level: _chunkTAG6UEL5cjs.LogLevelSchema.optional()
658
660
  }).optional().default(() => ({})),
659
661
  // MARK: Routing
660
662
  // // This is a function to allow for lazy configuration of upgradeWebSocket on the
@@ -672,9 +674,9 @@ var RegistryConfigSchema = _zod.z.object({
672
674
  *
673
675
  * Can also be set via RIVET_ENDPOINT environment variables.
674
676
  */
675
- endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunk4ESGNS3Zcjs.getRivetEngine.call(void 0, ))), () => ( _chunk4ESGNS3Zcjs.getRivetEndpoint.call(void 0, )))),
676
- token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk4ESGNS3Zcjs.getRivetToken.call(void 0, )))),
677
- namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk4ESGNS3Zcjs.getRivetNamespace.call(void 0, )))),
677
+ endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkTAG6UEL5cjs.getRivetEngine.call(void 0, ))), () => ( _chunkTAG6UEL5cjs.getRivetEndpoint.call(void 0, )))),
678
+ token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkTAG6UEL5cjs.getRivetToken.call(void 0, )))),
679
+ namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkTAG6UEL5cjs.getRivetNamespace.call(void 0, )))),
678
680
  headers: _zod.z.record(_zod.z.string(), _zod.z.string()).optional().default({}),
679
681
  // MARK: Client
680
682
  // TODO:
@@ -714,21 +716,27 @@ var RegistryConfigSchema = _zod.z.object({
714
716
  *
715
717
  * Starts the full Rust engine process locally.
716
718
  */
717
- startEngine: _zod.z.boolean().default(() => _chunk4ESGNS3Zcjs.getRivetRunEngine.call(void 0, )),
719
+ startEngine: _zod.z.boolean().default(() => _chunkTAG6UEL5cjs.getRivetRunEngine.call(void 0, )),
718
720
  /**
719
721
  * @experimental
720
722
  *
721
723
  * Host to bind the spawned local engine process to.
722
724
  */
723
- engineHost: _zod.z.string().optional().default(() => _nullishCoalesce(_chunk4ESGNS3Zcjs.getRivetRunEngineHost.call(void 0, ), () => ( ENGINE_HOST))),
725
+ engineHost: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkTAG6UEL5cjs.getRivetRunEngineHost.call(void 0, ), () => ( ENGINE_HOST))),
724
726
  /**
725
727
  * @experimental
726
728
  *
727
729
  * Port to bind the spawned local engine process to.
728
730
  */
729
- enginePort: _zod.z.number().int().min(1).max(65535).optional().default(() => _nullishCoalesce(_chunk4ESGNS3Zcjs.getRivetRunEnginePort.call(void 0, ), () => ( ENGINE_PORT))),
731
+ enginePort: _zod.z.number().int().min(1).max(65535).optional().default(() => _nullishCoalesce(_chunkTAG6UEL5cjs.getRivetRunEnginePort.call(void 0, ), () => ( ENGINE_PORT))),
730
732
  /** @experimental */
731
- engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunk4ESGNS3Zcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunk4ESGNS3Zcjs.VERSION))),
733
+ engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkTAG6UEL5cjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkTAG6UEL5cjs.VERSION))),
734
+ /**
735
+ * Starts the first-party Services actor host when RivetKit manages
736
+ * a local engine. Defaults to the local-engine decision. Set
737
+ * RIVET_RUN_SERVICES=0 or 1 to override it.
738
+ */
739
+ startServices: _zod.z.boolean().optional(),
732
740
  /**
733
741
  * @experimental
734
742
  *
@@ -776,7 +784,7 @@ var RegistryConfigSchema = _zod.z.object({
776
784
  }))
777
785
  }).transform((config, ctx) => {
778
786
  var _a, _b, _c;
779
- const isDevEnv = _chunk4ESGNS3Zcjs.isDev.call(void 0, );
787
+ const isDevEnv = _chunkTAG6UEL5cjs.isDev.call(void 0, );
780
788
  const sqliteBackend = _nullishCoalesce(((_a = config.sqlite) == null ? void 0 : _a.backend), () => ( ((_b = config.test) == null ? void 0 : _b.sqliteBackend)));
781
789
  if (config.runtime === "wasm" && sqliteBackend === "local") {
782
790
  ctx.addIssue({
@@ -786,7 +794,7 @@ var RegistryConfigSchema = _zod.z.object({
786
794
  });
787
795
  }
788
796
  const sqlite = config.runtime === "wasm" && config.sqlite === void 0 ? { backend: "remote" } : config.sqlite;
789
- const parsedEndpoint = config.endpoint ? _chunkPZBWSCQRcjs.tryParseEndpoint.call(void 0, ctx, {
797
+ const parsedEndpoint = config.endpoint ? _chunkTZPNSOG2cjs.tryParseEndpoint.call(void 0, ctx, {
790
798
  endpoint: config.endpoint,
791
799
  path: ["endpoint"],
792
800
  namespace: config.namespace,
@@ -809,12 +817,13 @@ var RegistryConfigSchema = _zod.z.object({
809
817
  config.enginePort
810
818
  );
811
819
  const endpoint = config.startEngine ? localEngineEndpoint : _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint), () => ( (isDevEnv ? localEngineEndpoint : void 0)));
820
+ const startServices = _nullishCoalesce(_nullishCoalesce(config.startServices, () => ( _chunkTAG6UEL5cjs.getRivetRunServices.call(void 0, ))), () => ( Boolean(endpoint && isLocalEngineEndpoint(endpoint))));
812
821
  const validateServerlessEndpoint = Boolean(
813
822
  config.startEngine || parsedEndpoint
814
823
  );
815
824
  const namespace = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.namespace), () => ( config.namespace)), () => ( "default"));
816
825
  const token = _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.token), () => ( config.token));
817
- const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkPZBWSCQRcjs.tryParseEndpoint.call(void 0, ctx, {
826
+ const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkTZPNSOG2cjs.tryParseEndpoint.call(void 0, ctx, {
818
827
  endpoint: config.serverless.publicEndpoint,
819
828
  path: ["serverless", "publicEndpoint"]
820
829
  }) : void 0;
@@ -832,6 +841,7 @@ var RegistryConfigSchema = _zod.z.object({
832
841
  ...config,
833
842
  sqlite,
834
843
  endpoint,
844
+ startServices,
835
845
  namespace,
836
846
  token,
837
847
  publicEndpoint,
@@ -917,7 +927,7 @@ var DocRegistryConfigSchema = _zod.z.object({
917
927
  noWelcome: _zod.z.boolean().optional().describe("Disable the welcome message on startup. Default: false"),
918
928
  sqlite: DocSqliteConfigSchema,
919
929
  logging: _zod.z.object({
920
- level: _chunk4ESGNS3Zcjs.LogLevelSchema.optional().describe(
930
+ level: _chunkTAG6UEL5cjs.LogLevelSchema.optional().describe(
921
931
  "Log level for RivetKit. Default: 'warn'"
922
932
  )
923
933
  }).optional().describe("Logging configuration."),
@@ -945,6 +955,9 @@ var DocRegistryConfigSchema = _zod.z.object({
945
955
  engineVersion: _zod.z.string().optional().describe(
946
956
  "Version of the local engine package to use. Defaults to the current RivetKit version."
947
957
  ),
958
+ startServices: _zod.z.boolean().optional().describe(
959
+ "Starts Services when RivetKit manages a local Engine. Defaults to the local-Engine decision. Set RIVET_RUN_SERVICES=0 or 1 to override."
960
+ ),
948
961
  configurePool: DocConfigurePoolSchema.describe(
949
962
  "Automatically configure serverless runners in the engine."
950
963
  ),
@@ -962,7 +975,7 @@ function shouldAttachNativeKvError(message) {
962
975
  function enrichNativeDatabaseError(database, error) {
963
976
  var _a;
964
977
  const bridgeReason = typeof error === "string" ? error : error instanceof Error ? error.message : void 0;
965
- const bridged = bridgeReason === void 0 ? void 0 : _chunkSPJORZMMcjs.decodeBridgeRivetError.call(void 0, bridgeReason);
978
+ const bridged = bridgeReason === void 0 ? void 0 : _chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, bridgeReason);
966
979
  if (bridged) {
967
980
  throw bridged;
968
981
  }
@@ -1466,16 +1479,30 @@ function toNapiApplication(application) {
1466
1479
  if (!request) {
1467
1480
  throw new Error("application fetch callback received no request");
1468
1481
  }
1469
- const response = await application({
1470
- ...request,
1471
- body: new Uint8Array(request.body)
1472
- });
1482
+ const response = await application(
1483
+ {
1484
+ ...request,
1485
+ body: new Uint8Array(request.body),
1486
+ cancelToken: request.cancelToken
1487
+ },
1488
+ request.responseBodyStream ? fromNapiHttpResponseBodyStream(
1489
+ request.responseBodyStream
1490
+ ) : void 0
1491
+ );
1473
1492
  return {
1474
1493
  ...response,
1475
- body: toNapiBuffer(response.body)
1494
+ body: response.body === void 0 ? void 0 : toNapiBuffer(response.body)
1476
1495
  };
1477
1496
  };
1478
1497
  }
1498
+ function fromNapiHttpResponseBodyStream(stream) {
1499
+ return {
1500
+ cancelled: () => stream.cancelled(),
1501
+ write: (chunk) => stream.write(Buffer.from(chunk)),
1502
+ end: () => stream.end(),
1503
+ error: (message) => stream.error(message)
1504
+ };
1505
+ }
1479
1506
  function toNapiHttpRequest(request) {
1480
1507
  if (!request) {
1481
1508
  return request;
@@ -2019,6 +2046,149 @@ async function loadNapiRuntime() {
2019
2046
  };
2020
2047
  }
2021
2048
 
2049
+ // src/registry/native-http.ts
2050
+ var HTTP_BODY_CHUNK_SIZE = 64 * 1024;
2051
+ function runtimeBytesToArrayBuffer(value) {
2052
+ return value.buffer.slice(
2053
+ value.byteOffset,
2054
+ value.byteOffset + value.byteLength
2055
+ );
2056
+ }
2057
+ function buildNativeHttpRequest(init) {
2058
+ var _a;
2059
+ const headers = new Headers(init.headers);
2060
+ const originalUrl = headers.get(_chunkTZPNSOG2cjs.HEADER_ORIGINAL_REQUEST_URL);
2061
+ headers.delete(_chunkTZPNSOG2cjs.HEADER_ORIGINAL_REQUEST_URL);
2062
+ const url = _nullishCoalesce(originalUrl, () => ( (init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString())));
2063
+ const method2 = init.method.toUpperCase();
2064
+ const bodyForbidden = method2 === "GET" || method2 === "HEAD";
2065
+ const body = bodyForbidden ? void 0 : init.bodyStream ? new ReadableStream({
2066
+ async pull(controller) {
2067
+ var _a2, _b;
2068
+ try {
2069
+ if (init.body && init.body.length > 0) {
2070
+ controller.enqueue(new Uint8Array(init.body));
2071
+ init.body = void 0;
2072
+ return;
2073
+ }
2074
+ const chunk = await ((_a2 = init.bodyStream) == null ? void 0 : _a2.read());
2075
+ if (!chunk) {
2076
+ controller.close();
2077
+ } else {
2078
+ controller.enqueue(new Uint8Array(chunk));
2079
+ }
2080
+ } catch (error) {
2081
+ (_b = init.abortController) == null ? void 0 : _b.abort(error);
2082
+ controller.error(error);
2083
+ }
2084
+ },
2085
+ async cancel() {
2086
+ var _a2;
2087
+ await ((_a2 = init.bodyStream) == null ? void 0 : _a2.cancel());
2088
+ }
2089
+ }) : init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
2090
+ const streamInit = init.bodyStream && !bodyForbidden ? { duplex: "half" } : {};
2091
+ return new Request(url, {
2092
+ method: method2,
2093
+ headers,
2094
+ body,
2095
+ signal: _nullishCoalesce(((_a = init.abortController) == null ? void 0 : _a.signal), () => ( init.signal)),
2096
+ ...streamInit
2097
+ });
2098
+ }
2099
+ async function cancelNativeHttpRequestBody(bodyStream) {
2100
+ await (bodyStream == null ? void 0 : bodyStream.cancel());
2101
+ }
2102
+ async function writeResponseChunk(stream, chunk) {
2103
+ for (let offset = 0; offset < chunk.byteLength; offset += HTTP_BODY_CHUNK_SIZE) {
2104
+ await stream.write(
2105
+ chunk.subarray(offset, offset + HTTP_BODY_CHUNK_SIZE)
2106
+ );
2107
+ }
2108
+ }
2109
+ async function pumpResponseBody(reader, stream) {
2110
+ var _a;
2111
+ const cancelled = stream.cancelled().then(() => ({ cancelled: true }));
2112
+ try {
2113
+ for (; ; ) {
2114
+ const read = reader.read().then((next2) => ({ cancelled: false, next: next2 }));
2115
+ const result = await Promise.race([read, cancelled]);
2116
+ if (result.cancelled) {
2117
+ void reader.cancel(
2118
+ new Error(
2119
+ "native http response stream receiver dropped"
2120
+ )
2121
+ ).catch((error) => {
2122
+ logger2().debug({
2123
+ msg: "failed to cancel native http response reader",
2124
+ error
2125
+ });
2126
+ });
2127
+ return;
2128
+ }
2129
+ const { next } = result;
2130
+ if (next.done) {
2131
+ await stream.end();
2132
+ return;
2133
+ }
2134
+ if ((_a = next.value) == null ? void 0 : _a.byteLength) {
2135
+ await writeResponseChunk(stream, next.value);
2136
+ }
2137
+ }
2138
+ } catch (error) {
2139
+ try {
2140
+ await stream.error(_chunkTAG6UEL5cjs.stringifyError.call(void 0, error));
2141
+ } catch (streamError) {
2142
+ logger2().debug({
2143
+ msg: "failed to report native http response stream error",
2144
+ error: streamError
2145
+ });
2146
+ }
2147
+ void reader.cancel(error).catch(() => {
2148
+ });
2149
+ } finally {
2150
+ try {
2151
+ reader.releaseLock();
2152
+ } catch (error) {
2153
+ logger2().debug({
2154
+ msg: "failed to release native http response reader lock",
2155
+ error
2156
+ });
2157
+ }
2158
+ }
2159
+ }
2160
+ async function convertNativeHttpResponse(response, responseBodyStream) {
2161
+ const headers = Object.fromEntries(response.headers.entries());
2162
+ if (!response.body) {
2163
+ return {
2164
+ response: {
2165
+ status: response.status,
2166
+ headers,
2167
+ body: new Uint8Array()
2168
+ }
2169
+ };
2170
+ }
2171
+ if (responseBodyStream) {
2172
+ const reader = response.body.getReader();
2173
+ const bodyCompletion = pumpResponseBody(reader, responseBodyStream);
2174
+ return {
2175
+ response: {
2176
+ status: response.status,
2177
+ headers,
2178
+ stream: true
2179
+ },
2180
+ bodyCompletion
2181
+ };
2182
+ }
2183
+ return {
2184
+ response: {
2185
+ status: response.status,
2186
+ headers,
2187
+ body: new Uint8Array(await response.arrayBuffer())
2188
+ }
2189
+ };
2190
+ }
2191
+
2022
2192
  // src/registry/native-validation.ts
2023
2193
  var CONN_PARAMS_KEY = "__conn_params__";
2024
2194
  function validateActionArgs(schemas, name, args) {
@@ -2097,7 +2267,7 @@ function validateQueueComplete(schemas, name, response) {
2097
2267
  return result.data;
2098
2268
  }
2099
2269
  function validationError(target, issues) {
2100
- return new (0, _chunkSPJORZMMcjs.RivetError)("actor", "validation_error", `Invalid ${target}`, {
2270
+ return new (0, _chunk2JSYYH6Pcjs.RivetError)("actor", "validation_error", `Invalid ${target}`, {
2101
2271
  public: true,
2102
2272
  metadata: { issues }
2103
2273
  });
@@ -2105,7 +2275,7 @@ function validationError(target, issues) {
2105
2275
 
2106
2276
  // src/registry/run-handler-coordinator.ts
2107
2277
  function runUnavailable(actorId, reason) {
2108
- return new (0, _chunkSPJORZMMcjs.RivetError)(
2278
+ return new (0, _chunk2JSYYH6Pcjs.RivetError)(
2109
2279
  "actor",
2110
2280
  "run_handler_unavailable",
2111
2281
  `Run handler control is unavailable for actor ${actorId}: ${reason}.`,
@@ -2326,16 +2496,16 @@ function normalizeQueueMessage(message) {
2326
2496
  }
2327
2497
  function normalizeWasmBridgeError(error) {
2328
2498
  if (typeof error === "string") {
2329
- return _nullishCoalesce(_chunkSPJORZMMcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2499
+ return _nullishCoalesce(_chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2330
2500
  }
2331
2501
  if (error instanceof Error) {
2332
- const bridged = _chunkSPJORZMMcjs.decodeBridgeRivetError.call(void 0, error.message);
2502
+ const bridged = _chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error.message);
2333
2503
  if (bridged) {
2334
2504
  return bridged;
2335
2505
  }
2336
2506
  }
2337
2507
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
2338
- const bridged = _chunkSPJORZMMcjs.decodeBridgeRivetError.call(void 0, error.reason);
2508
+ const bridged = _chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error.reason);
2339
2509
  if (bridged) {
2340
2510
  return bridged;
2341
2511
  }
@@ -2357,7 +2527,7 @@ function callWasmSync(invoke) {
2357
2527
  }
2358
2528
  }
2359
2529
  function unsupportedWasmMethod(method2) {
2360
- throw new (0, _chunkSPJORZMMcjs.RivetError)(
2530
+ throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
2361
2531
  "runtime",
2362
2532
  "unsupported",
2363
2533
  `Unsupported wasm runtime method: ${method2}`,
@@ -2792,7 +2962,7 @@ var WasmCoreRuntime = (_class2 = class {
2792
2962
  await callWasm(() => database.close());
2793
2963
  }
2794
2964
  async actorRuntimeSocketProvision(_ctx) {
2795
- throw new (0, _chunkSPJORZMMcjs.RivetError)(
2965
+ throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
2796
2966
  "actor_runtime_socket",
2797
2967
  "unsupported",
2798
2968
  "Actor Runtime Socket is only available on Unix native runtimes.",
@@ -3161,7 +3331,7 @@ function loadedRuntimeKind(runtime) {
3161
3331
  case "wasm":
3162
3332
  return "wasm";
3163
3333
  }
3164
- throw new (0, _chunkSPJORZMMcjs.RivetError)(
3334
+ throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
3165
3335
  "config",
3166
3336
  "unknown_runtime",
3167
3337
  "RivetKit runtime must be NAPI or wasm.",
@@ -3201,7 +3371,7 @@ function normalizeRuntimeConfigForKind(config, runtimeKind) {
3201
3371
  return config;
3202
3372
  }
3203
3373
  if (sqliteBackendForConfig(config) === "local") {
3204
- throw new (0, _chunkSPJORZMMcjs.RivetError)(
3374
+ throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
3205
3375
  "config",
3206
3376
  "wasm_local_sqlite",
3207
3377
  "WebAssembly runtime cannot use local SQLite. Use remote SQLite instead.",
@@ -3267,14 +3437,14 @@ function getNativeConnPersistState(runtime, ctx, conn) {
3267
3437
  return connState;
3268
3438
  }
3269
3439
  function stateMutationReentrantError() {
3270
- return new (0, _chunkSPJORZMMcjs.RivetError)(
3440
+ return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3271
3441
  "actor",
3272
3442
  "state_mutation_reentrant",
3273
3443
  "State mutations are not allowed inside onStateChange."
3274
3444
  );
3275
3445
  }
3276
3446
  function stateTransactionConflictError() {
3277
- return new (0, _chunkSPJORZMMcjs.RivetError)(
3447
+ return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3278
3448
  "actor",
3279
3449
  "state_transaction_conflict",
3280
3450
  "State cannot be mutated by another action while an experimental state-aware database transaction is active.",
@@ -3282,7 +3452,7 @@ function stateTransactionConflictError() {
3282
3452
  );
3283
3453
  }
3284
3454
  function databaseNotConfiguredError() {
3285
- return new (0, _chunkSPJORZMMcjs.RivetError)(
3455
+ return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3286
3456
  "actor",
3287
3457
  "database_not_configured",
3288
3458
  "database is not configured for this actor",
@@ -3290,7 +3460,7 @@ function databaseNotConfiguredError() {
3290
3460
  );
3291
3461
  }
3292
3462
  function databaseClientNotReadyError() {
3293
- return new (0, _chunkSPJORZMMcjs.RivetError)(
3463
+ return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3294
3464
  "actor",
3295
3465
  "database_client_not_ready",
3296
3466
  "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.",
@@ -3298,7 +3468,7 @@ function databaseClientNotReadyError() {
3298
3468
  );
3299
3469
  }
3300
3470
  function runHandlerNotConfiguredError() {
3301
- return new (0, _chunkSPJORZMMcjs.RivetError)(
3471
+ return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3302
3472
  "actor",
3303
3473
  "run_handler_unavailable",
3304
3474
  "Cannot schedule a run wake because this actor does not define a run handler.",
@@ -3306,7 +3476,7 @@ function runHandlerNotConfiguredError() {
3306
3476
  );
3307
3477
  }
3308
3478
  function stateNotEnabledError() {
3309
- return new (0, _chunkSPJORZMMcjs.RivetError)(
3479
+ return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3310
3480
  "actor",
3311
3481
  "state_not_enabled",
3312
3482
  "State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.dev/docs/actors/state/#initializing-state)",
@@ -3314,7 +3484,7 @@ function stateNotEnabledError() {
3314
3484
  );
3315
3485
  }
3316
3486
  function nativeClientNotConfiguredError() {
3317
- return new (0, _chunkSPJORZMMcjs.RivetError)(
3487
+ return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3318
3488
  "native",
3319
3489
  "client_not_configured",
3320
3490
  "native actor client is not configured",
@@ -3322,7 +3492,7 @@ function nativeClientNotConfiguredError() {
3322
3492
  );
3323
3493
  }
3324
3494
  function nativeEndpointNotConfiguredError() {
3325
- return new (0, _chunkSPJORZMMcjs.RivetError)(
3495
+ return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3326
3496
  "native",
3327
3497
  "endpoint_not_configured",
3328
3498
  "registry endpoint is required for native envoy startup",
@@ -3367,7 +3537,7 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
3367
3537
  }).catch((error) => {
3368
3538
  logger2().warn({
3369
3539
  msg: "deferred native sleep cleanup failed",
3370
- error: _chunk4ESGNS3Zcjs.stringifyError.call(void 0, error)
3540
+ error: _chunkTAG6UEL5cjs.stringifyError.call(void 0, error)
3371
3541
  });
3372
3542
  });
3373
3543
  return;
@@ -3477,7 +3647,7 @@ function toRuntimeBytes(value) {
3477
3647
  function arrayBufferViewToRuntimeBytes(value) {
3478
3648
  return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
3479
3649
  }
3480
- function runtimeBytesToArrayBuffer(value) {
3650
+ function runtimeBytesToArrayBuffer2(value) {
3481
3651
  return value.buffer.slice(
3482
3652
  value.byteOffset,
3483
3653
  value.byteOffset + value.byteLength
@@ -3523,14 +3693,17 @@ function decodeNativeKvValue(value, options) {
3523
3693
  async function loadEngineCli() {
3524
3694
  return Promise.resolve().then(() => _interopRequireWildcard(require(["@rivetkit", "engine-cli"].join("/"))));
3525
3695
  }
3696
+ async function loadServices() {
3697
+ return Promise.resolve().then(() => _interopRequireWildcard(require(["@rivet-dev", "services"].join("/"))));
3698
+ }
3526
3699
  function decodeValue(value) {
3527
3700
  if (!value || value.length === 0) {
3528
3701
  return void 0;
3529
3702
  }
3530
- return _chunk4ESGNS3Zcjs.decodeCborCompat.call(void 0, value);
3703
+ return _chunkTAG6UEL5cjs.decodeCborCompat.call(void 0, value);
3531
3704
  }
3532
3705
  function encodeValue(value) {
3533
- return _chunk4ESGNS3Zcjs.encodeCborCompat.call(void 0, value);
3706
+ return _chunkTAG6UEL5cjs.encodeCborCompat.call(void 0, value);
3534
3707
  }
3535
3708
  function normalizeArgs(value) {
3536
3709
  return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
@@ -3543,16 +3716,16 @@ function unwrapTsfnPayload(error, payload) {
3543
3716
  }
3544
3717
  function normalizeNativeBridgeError(error) {
3545
3718
  if (typeof error === "string") {
3546
- return _nullishCoalesce(_chunkSPJORZMMcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
3719
+ return _nullishCoalesce(_chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
3547
3720
  }
3548
3721
  if (error instanceof Error) {
3549
- const bridged = _chunkSPJORZMMcjs.decodeBridgeRivetError.call(void 0, error.message);
3722
+ const bridged = _chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error.message);
3550
3723
  if (bridged) {
3551
3724
  return bridged;
3552
3725
  }
3553
3726
  }
3554
3727
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
3555
- const bridged = _chunkSPJORZMMcjs.decodeBridgeRivetError.call(void 0, error.reason);
3728
+ const bridged = _chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error.reason);
3556
3729
  if (bridged) {
3557
3730
  return bridged;
3558
3731
  }
@@ -3560,14 +3733,14 @@ function normalizeNativeBridgeError(error) {
3560
3733
  return error;
3561
3734
  }
3562
3735
  function isStructuredBridgeError(error) {
3563
- if (error instanceof _chunkSPJORZMMcjs.RivetError) {
3736
+ if (error instanceof _chunk2JSYYH6Pcjs.RivetError) {
3564
3737
  return true;
3565
3738
  }
3566
- return _chunkSPJORZMMcjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
3739
+ return _chunk2JSYYH6Pcjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
3567
3740
  }
3568
3741
  function encodeNativeCallbackError(error) {
3569
- const structuredError = isStructuredBridgeError(error) ? error : _chunk4ESGNS3Zcjs.deconstructError.call(void 0, error, true);
3570
- const bridgeError = new Error(_chunkSPJORZMMcjs.encodeBridgeRivetError.call(void 0, structuredError), {
3742
+ const structuredError = isStructuredBridgeError(error) ? error : _chunkTAG6UEL5cjs.deconstructError.call(void 0, error, true);
3743
+ const bridgeError = new Error(_chunk2JSYYH6Pcjs.encodeBridgeRivetError.call(void 0, structuredError), {
3571
3744
  cause: error instanceof Error ? error : void 0
3572
3745
  });
3573
3746
  return Object.assign(bridgeError, {
@@ -3592,9 +3765,9 @@ function callNativeSync(invoke) {
3592
3765
  }
3593
3766
  }
3594
3767
  function isClosedTaskRegistrationError(error) {
3595
- const metadata = error instanceof _chunkSPJORZMMcjs.RivetError ? error.metadata : void 0;
3768
+ const metadata = error instanceof _chunk2JSYYH6Pcjs.RivetError ? error.metadata : void 0;
3596
3769
  const metadataError = metadata && typeof metadata === "object" && "error" in metadata ? metadata.error : void 0;
3597
- return error instanceof _chunkSPJORZMMcjs.RivetError && error.group === "core" && error.code === _chunkSPJORZMMcjs.INTERNAL_ERROR_CODE && typeof metadataError === "string" && /actor task registration is (closed|not configured)/.test(metadataError);
3770
+ return error instanceof _chunk2JSYYH6Pcjs.RivetError && error.group === "core" && error.code === _chunk2JSYYH6Pcjs.INTERNAL_ERROR_CODE && typeof metadataError === "string" && /actor task registration is (closed|not configured)/.test(metadataError);
3598
3771
  }
3599
3772
  async function createCancellationTokenHandle(runtime, signal) {
3600
3773
  if (!signal) {
@@ -3617,7 +3790,7 @@ function decodeWorkflowCbor(data) {
3617
3790
  return null;
3618
3791
  }
3619
3792
  try {
3620
- return _chunk4ESGNS3Zcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
3793
+ return _chunkTAG6UEL5cjs.decodeCborCompat.call(void 0, new Uint8Array(data));
3621
3794
  } catch (e5) {
3622
3795
  return null;
3623
3796
  }
@@ -3730,7 +3903,7 @@ function serializeWorkflowHistoryForJson(data) {
3730
3903
  if (data === null) {
3731
3904
  return null;
3732
3905
  }
3733
- const history = _chunkQLOBB27Mcjs.decodeWorkflowHistoryTransport.call(void 0, data);
3906
+ const history = _chunkPW2VSGURcjs.decodeWorkflowHistoryTransport.call(void 0, data);
3734
3907
  return jsonSafe({
3735
3908
  nameRegistry: [...history.nameRegistry],
3736
3909
  entries: history.entries.map((entry) => ({
@@ -3808,24 +3981,6 @@ function decodeArgs(value) {
3808
3981
  const decoded = decodeValue(value);
3809
3982
  return normalizeArgs(decoded);
3810
3983
  }
3811
- function buildRequest(init) {
3812
- const url = init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString();
3813
- const body = init.body && init.body.length > 0 ? runtimeBytesToArrayBuffer(init.body) : void 0;
3814
- return new Request(url, {
3815
- method: init.method,
3816
- headers: init.headers,
3817
- body
3818
- });
3819
- }
3820
- async function toRuntimeHttpResponse(response) {
3821
- const headers = Object.fromEntries(response.headers.entries());
3822
- const body = new Uint8Array(await response.arrayBuffer());
3823
- return {
3824
- status: response.status,
3825
- headers,
3826
- body
3827
- };
3828
- }
3829
3984
  function toActorKey(segments) {
3830
3985
  return segments.map(
3831
3986
  (segment) => segment.kind === "number" ? String(_nullishCoalesce(segment.numberValue, () => ( 0))) : _nullishCoalesce(segment.stringValue, () => ( ""))
@@ -3894,7 +4049,7 @@ var NativeConnAdapter = class {
3894
4049
  },
3895
4050
  (newValue) => {
3896
4051
  assertCurrentState();
3897
- _chunk4ESGNS3Zcjs.assertJsonCompatValue.call(void 0, newValue);
4052
+ _chunkTAG6UEL5cjs.assertJsonCompatValue.call(void 0, newValue);
3898
4053
  }
3899
4054
  );
3900
4055
  }
@@ -3902,7 +4057,7 @@ var NativeConnAdapter = class {
3902
4057
  var _a;
3903
4058
  (_a = this.#assertCanMutateState) == null ? void 0 : _a.call(this);
3904
4059
  const nextValue = unwrapWriteThroughProxy(value);
3905
- _chunk4ESGNS3Zcjs.assertJsonCompatValue.call(void 0, nextValue);
4060
+ _chunkTAG6UEL5cjs.assertJsonCompatValue.call(void 0, nextValue);
3906
4061
  this.#writeState(nextValue, { writeNative: true });
3907
4062
  }
3908
4063
  initializeState(value) {
@@ -4285,7 +4440,7 @@ var NativeQueueAdapter = class {
4285
4440
  async nextBatch(options) {
4286
4441
  const completable = (options == null ? void 0 : options.completable) === true;
4287
4442
  if (this.#pendingCompletableMessageIds.size > 0) {
4288
- throw new (0, _chunkSPJORZMMcjs.RivetError)(
4443
+ throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
4289
4444
  "queue",
4290
4445
  "previous_message_not_completed",
4291
4446
  "Previous completable queue message is not completed. Call `message.complete(...)` before receiving the next message.",
@@ -4452,7 +4607,7 @@ var NativeQueueAdapter = class {
4452
4607
  }
4453
4608
  yield message;
4454
4609
  } catch (error) {
4455
- if (_chunkSPJORZMMcjs.isActorAbortedError.call(void 0, error)) {
4610
+ if (_chunk2JSYYH6Pcjs.isActorAbortedError.call(void 0, error)) {
4456
4611
  return;
4457
4612
  }
4458
4613
  throw error;
@@ -4473,7 +4628,7 @@ var NativeQueueAdapter = class {
4473
4628
  ...message,
4474
4629
  complete: async (response) => {
4475
4630
  if (typeof message.complete !== "function") {
4476
- throw new (0, _chunkSPJORZMMcjs.RivetError)(
4631
+ throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
4477
4632
  "queue",
4478
4633
  "complete_not_configured",
4479
4634
  `Queue '${message.name}' does not support completion responses.`,
@@ -4485,7 +4640,7 @@ var NativeQueueAdapter = class {
4485
4640
  );
4486
4641
  }
4487
4642
  if (completed) {
4488
- throw new (0, _chunkSPJORZMMcjs.RivetError)(
4643
+ throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
4489
4644
  "queue",
4490
4645
  "already_completed",
4491
4646
  "Queue message was already completed.",
@@ -4538,7 +4693,7 @@ var NativeWebSocketAdapter = class {
4538
4693
  this.#runtime.webSocketSetEventCallback(this.#ws, (event2) => {
4539
4694
  if (event2.kind === "message") {
4540
4695
  this.#virtual.triggerMessage(
4541
- event2.binary ? runtimeBytesToArrayBuffer(event2.data) : event2.data,
4696
+ event2.binary ? runtimeBytesToArrayBuffer2(event2.data) : event2.data,
4542
4697
  event2.messageIndex
4543
4698
  );
4544
4699
  return;
@@ -4976,7 +5131,7 @@ var ActorContextHandleAdapter = class {
4976
5131
  },
4977
5132
  (newValue) => {
4978
5133
  assertCurrentState();
4979
- _chunk4ESGNS3Zcjs.assertJsonCompatValue.call(void 0, newValue);
5134
+ _chunkTAG6UEL5cjs.assertJsonCompatValue.call(void 0, newValue);
4980
5135
  }
4981
5136
  );
4982
5137
  }
@@ -4988,7 +5143,7 @@ var ActorContextHandleAdapter = class {
4988
5143
  }
4989
5144
  this.#assertCanMutateState();
4990
5145
  const nextValue = unwrapWriteThroughProxy(value);
4991
- _chunk4ESGNS3Zcjs.assertJsonCompatValue.call(void 0, nextValue);
5146
+ _chunkTAG6UEL5cjs.assertJsonCompatValue.call(void 0, nextValue);
4992
5147
  this.#writeState(nextValue, { scheduleSave: true });
4993
5148
  }
4994
5149
  initializeState(value) {
@@ -5172,7 +5327,7 @@ var ActorContextHandleAdapter = class {
5172
5327
  log: {
5173
5328
  debug: (obj) => logger2().debug(obj)
5174
5329
  },
5175
- nativeDatabaseProvider: _chunkO6H3BUN4cjs.registerNativeStateTransactionOpener.call(void 0,
5330
+ nativeDatabaseProvider: _chunkFGQABMXZcjs.registerNativeStateTransactionOpener.call(void 0,
5176
5331
  {
5177
5332
  open: async (requestedActorId) => {
5178
5333
  void requestedActorId;
@@ -5195,7 +5350,7 @@ var ActorContextHandleAdapter = class {
5195
5350
  return this.#db;
5196
5351
  }
5197
5352
  #bindDatabaseClient(client) {
5198
- return _chunkO6H3BUN4cjs.bindNativeStateTransactionContext.call(void 0, client, {
5353
+ return _chunkFGQABMXZcjs.bindNativeStateTransactionContext.call(void 0, client, {
5199
5354
  enter: async () => await this.#enterStateTransaction(),
5200
5355
  exit: (scope) => this.#exitStateTransaction(
5201
5356
  scope
@@ -5399,7 +5554,7 @@ var ActorContextHandleAdapter = class {
5399
5554
  const trackedPromise = Promise.resolve(promise).catch((error) => {
5400
5555
  logger2().warn({
5401
5556
  msg: "keepAwake promise rejected",
5402
- error: _chunk4ESGNS3Zcjs.stringifyError.call(void 0, error)
5557
+ error: _chunkTAG6UEL5cjs.stringifyError.call(void 0, error)
5403
5558
  });
5404
5559
  }).then(() => null);
5405
5560
  try {
@@ -5861,7 +6016,7 @@ function validateInspectorTabSource(tabId, resolved) {
5861
6016
  function buildNativeFactory(runtime, registryConfig, definition) {
5862
6017
  var _a;
5863
6018
  const config = definition.config;
5864
- const databaseProvider = _nullishCoalesce(config.db, () => ( _chunkO6H3BUN4cjs.db.call(void 0, )));
6019
+ const databaseProvider = _nullishCoalesce(config.db, () => ( _chunkFGQABMXZcjs.db.call(void 0, )));
5865
6020
  const actionHandlers = _chunk4KGXFC6Mcjs.flattenActionHandlers.call(void 0, config.actions);
5866
6021
  const schemaConfig = {
5867
6022
  actionInputSchemas: _chunk4KGXFC6Mcjs.flattenActionInputSchemas.call(void 0,
@@ -5872,9 +6027,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5872
6027
  events: config.events,
5873
6028
  queues: config.queues
5874
6029
  };
5875
- const createClient = () => _chunkPZBWSCQRcjs.createClientWithDriver.call(void 0,
5876
- new (0, _chunkPZBWSCQRcjs.RemoteEngineControlClient)(
5877
- _chunkPZBWSCQRcjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
6030
+ const createClient = () => _chunkTZPNSOG2cjs.createClientWithDriver.call(void 0,
6031
+ new (0, _chunkTZPNSOG2cjs.RemoteEngineControlClient)(
6032
+ _chunkTZPNSOG2cjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
5878
6033
  ),
5879
6034
  { encoding: "bare" }
5880
6035
  );
@@ -5921,12 +6076,14 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5921
6076
  cancelToken,
5922
6077
  run !== void 0
5923
6078
  );
5924
- const maybeHandleNativeInspectorRequest = async (ctx, _rawRequest, jsRequest) => {
6079
+ const maybeHandleNativeInspectorRequest = async (ctx, rawRequest) => {
5925
6080
  var _a2, _b, _c, _d;
5926
- const url = new URL(jsRequest.url);
6081
+ const rawUrl = rawRequest.uri.startsWith("http") ? rawRequest.uri : new URL(rawRequest.uri, "http://127.0.0.1").toString();
6082
+ const url = new URL(rawUrl);
5927
6083
  if (!url.pathname.startsWith("/inspector/")) {
5928
6084
  return void 0;
5929
6085
  }
6086
+ const jsRequest = buildNativeHttpRequest(rawRequest);
5930
6087
  const jsonResponse = (body, init) => new Response(JSON.stringify(body), {
5931
6088
  status: _nullishCoalesce((init == null ? void 0 : init.status), () => ( 200)),
5932
6089
  headers: {
@@ -5935,7 +6092,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
5935
6092
  }
5936
6093
  });
5937
6094
  const errorResponse = (error, status) => {
5938
- const rivetError = _chunkSPJORZMMcjs.toRivetError.call(void 0, error);
6095
+ const rivetError = _chunk2JSYYH6Pcjs.toRivetError.call(void 0, error);
5939
6096
  return jsonResponse(
5940
6097
  {
5941
6098
  group: rivetError.group,
@@ -6035,7 +6192,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6035
6192
  body = await jsRequest.json();
6036
6193
  } catch (e6) {
6037
6194
  return errorResponse(
6038
- new (0, _chunkSPJORZMMcjs.RivetError)(
6195
+ new (0, _chunk2JSYYH6Pcjs.RivetError)(
6039
6196
  "actor",
6040
6197
  "invalid_request",
6041
6198
  "Invalid inspector JSON body",
@@ -6047,7 +6204,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6047
6204
  const name = _nullishCoalesce(body.name, () => ( ""));
6048
6205
  if (name === "") {
6049
6206
  return errorResponse(
6050
- new (0, _chunkSPJORZMMcjs.RivetError)(
6207
+ new (0, _chunk2JSYYH6Pcjs.RivetError)(
6051
6208
  "actor",
6052
6209
  "invalid_request",
6053
6210
  "Queue message name must not be empty",
@@ -6056,7 +6213,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6056
6213
  400
6057
6214
  );
6058
6215
  }
6059
- const cbor = _chunk4ESGNS3Zcjs.encodeCborCompat.call(void 0,
6216
+ const cbor = _chunkTAG6UEL5cjs.encodeCborCompat.call(void 0,
6060
6217
  _nullishCoalesce(body.body, () => ( null))
6061
6218
  );
6062
6219
  const message = await runtime.actorQueueSend(ctx, name, cbor);
@@ -6221,7 +6378,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6221
6378
  const action = actionHandlers[actionName];
6222
6379
  if (!action) {
6223
6380
  return errorResponse(
6224
- new (0, _chunkSPJORZMMcjs.RivetError)(
6381
+ new (0, _chunk2JSYYH6Pcjs.RivetError)(
6225
6382
  "action",
6226
6383
  "action_not_found",
6227
6384
  `Action ${actionName} not found`
@@ -6457,7 +6614,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6457
6614
  );
6458
6615
  const actorCtx = makeActorCtx(
6459
6616
  ctx,
6460
- request ? buildRequest(request) : void 0
6617
+ request ? buildNativeHttpRequest(request) : void 0
6461
6618
  );
6462
6619
  try {
6463
6620
  await config.onBeforeConnect(
@@ -6477,7 +6634,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6477
6634
  const { ctx, conn, params, request } = unwrapTsfnPayload(error, payload);
6478
6635
  const actorCtx = makeActorCtx(
6479
6636
  ctx,
6480
- request ? buildRequest(request) : void 0
6637
+ request ? buildNativeHttpRequest(request) : void 0
6481
6638
  );
6482
6639
  const connAdapter = new NativeConnAdapter(
6483
6640
  runtime,
@@ -6515,7 +6672,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6515
6672
  );
6516
6673
  const actorCtx = makeActorCtx(
6517
6674
  ctx,
6518
- request ? buildRequest(request) : void 0
6675
+ request ? buildNativeHttpRequest(request) : void 0
6519
6676
  );
6520
6677
  const connAdapter = new NativeConnAdapter(
6521
6678
  runtime,
@@ -6594,7 +6751,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6594
6751
  );
6595
6752
  }
6596
6753
  if (!result) {
6597
- throw _chunkSPJORZMMcjs.forbiddenError.call(void 0, );
6754
+ throw _chunk2JSYYH6Pcjs.forbiddenError.call(void 0, );
6598
6755
  }
6599
6756
  } finally {
6600
6757
  await actorCtx.dispose();
@@ -6622,27 +6779,45 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6622
6779
  onRequest: wrapNativeCallback(
6623
6780
  async (error, payload) => {
6624
6781
  try {
6625
- const { ctx, request, cancelToken } = unwrapTsfnPayload(
6626
- error,
6627
- payload
6628
- );
6629
- const jsRequest = buildRequest(request);
6630
- const inspectorResponse = await maybeHandleNativeInspectorRequest(
6631
- ctx,
6632
- request,
6633
- jsRequest
6634
- );
6782
+ const { ctx, request, cancelToken, responseBodyStream } = unwrapTsfnPayload(error, payload);
6783
+ const inspectorResponse = await maybeHandleNativeInspectorRequest(ctx, request);
6635
6784
  if (inspectorResponse) {
6636
- return await toRuntimeHttpResponse(inspectorResponse);
6785
+ await cancelNativeHttpRequestBody(request.bodyStream);
6786
+ return (await convertNativeHttpResponse(
6787
+ inspectorResponse,
6788
+ responseBodyStream
6789
+ )).response;
6637
6790
  }
6638
6791
  if (typeof config.onRequest !== "function") {
6639
- return await toRuntimeHttpResponse(
6640
- new Response(null, { status: 404 })
6641
- );
6792
+ await cancelNativeHttpRequestBody(request.bodyStream);
6793
+ return (await convertNativeHttpResponse(
6794
+ new Response(null, { status: 404 }),
6795
+ responseBodyStream
6796
+ )).response;
6642
6797
  }
6643
- const rawConnParams = jsRequest.headers.get(_chunkPZBWSCQRcjs.HEADER_CONN_PARAMS);
6798
+ const requestAbortController = new AbortController();
6799
+ const handlerRequest = buildNativeHttpRequest({
6800
+ ...request,
6801
+ abortController: requestAbortController
6802
+ });
6803
+ const rawConnParams = handlerRequest.headers.get(_chunkTZPNSOG2cjs.HEADER_CONN_PARAMS);
6644
6804
  let requestCtx;
6645
6805
  let conn;
6806
+ let removeRequestAbortListener;
6807
+ let cleanupDeferredToBody = false;
6808
+ let cleanedUp = false;
6809
+ const cleanupRequest = async () => {
6810
+ if (cleanedUp) return;
6811
+ cleanedUp = true;
6812
+ removeRequestAbortListener == null ? void 0 : removeRequestAbortListener();
6813
+ try {
6814
+ await (requestCtx == null ? void 0 : requestCtx.dispose());
6815
+ } finally {
6816
+ if (conn) {
6817
+ await runtime.connDisconnect(conn);
6818
+ }
6819
+ }
6820
+ };
6646
6821
  try {
6647
6822
  const connParams = validateConnParams(
6648
6823
  schemaConfig.connParamsSchema,
@@ -6658,23 +6833,56 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6658
6833
  requestCtx = makeConnCtx(
6659
6834
  ctx,
6660
6835
  conn,
6661
- jsRequest,
6836
+ handlerRequest,
6662
6837
  cancelToken
6663
6838
  );
6839
+ const ctxAbortSignal = requestCtx.abortSignal;
6840
+ const abortRequest = () => requestAbortController.abort(ctxAbortSignal.reason);
6841
+ if (ctxAbortSignal.aborted) {
6842
+ abortRequest();
6843
+ } else {
6844
+ ctxAbortSignal.addEventListener(
6845
+ "abort",
6846
+ abortRequest,
6847
+ { once: true }
6848
+ );
6849
+ removeRequestAbortListener = () => ctxAbortSignal.removeEventListener(
6850
+ "abort",
6851
+ abortRequest
6852
+ );
6853
+ }
6664
6854
  const response = await config.onRequest(
6665
6855
  requestCtx,
6666
- jsRequest
6856
+ handlerRequest
6667
6857
  );
6668
- if (!_chunkPZBWSCQRcjs.isResponseLike.call(void 0, response)) {
6858
+ if (!_chunkTZPNSOG2cjs.isResponseLike.call(void 0, response)) {
6669
6859
  throw new Error(
6670
6860
  "onRequest handler must return a Response"
6671
6861
  );
6672
6862
  }
6673
- return await toRuntimeHttpResponse(response);
6863
+ const conversion = await convertNativeHttpResponse(
6864
+ response,
6865
+ responseBodyStream
6866
+ );
6867
+ if (conversion.bodyCompletion) {
6868
+ cleanupDeferredToBody = true;
6869
+ void conversion.bodyCompletion.then(cleanupRequest).catch((cleanupError) => {
6870
+ logger2().error({
6871
+ msg: "failed to clean up native streaming http request",
6872
+ error: cleanupError
6873
+ });
6874
+ });
6875
+ }
6876
+ return conversion.response;
6674
6877
  } finally {
6675
- await (requestCtx == null ? void 0 : requestCtx.dispose());
6676
- if (conn) {
6677
- await runtime.connDisconnect(conn);
6878
+ try {
6879
+ await cancelNativeHttpRequestBody(
6880
+ request.bodyStream
6881
+ );
6882
+ } finally {
6883
+ if (!cleanupDeferredToBody) {
6884
+ await cleanupRequest();
6885
+ }
6678
6886
  }
6679
6887
  }
6680
6888
  } catch (error2) {
@@ -6689,7 +6897,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6689
6897
  onWebSocket: typeof config.onWebSocket === "function" ? wrapNativeCallback(
6690
6898
  async (error, payload) => {
6691
6899
  const { ctx, conn, ws, request } = unwrapTsfnPayload(error, payload);
6692
- const jsRequest = request ? buildRequest(request) : void 0;
6900
+ const jsRequest = request ? buildNativeHttpRequest(request) : void 0;
6693
6901
  const actorCtx = makeConnCtx(ctx, conn, jsRequest);
6694
6902
  try {
6695
6903
  await config.onWebSocket(
@@ -6740,7 +6948,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6740
6948
  var _a2;
6741
6949
  const { ctx } = unwrapTsfnPayload(error, payload);
6742
6950
  const history = (_a2 = getNativeWorkflowInspector(ctx)) == null ? void 0 : _a2.getHistory();
6743
- return history == null ? void 0 : _chunk4ESGNS3Zcjs.toUint8Array.call(void 0, history);
6951
+ return history == null ? void 0 : _chunkTAG6UEL5cjs.toUint8Array.call(void 0, history);
6744
6952
  }
6745
6953
  ) : void 0,
6746
6954
  replayWorkflow: _chunk4KGXFC6Mcjs.hasRunInspectorConfig.call(void 0, config.run) ? wrapNativeCallback(
@@ -6754,7 +6962,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6754
6962
  return void 0;
6755
6963
  }
6756
6964
  const history = await _asyncNullishCoalesce(await workflowInspector.replayFromStep(entryId), async () => ( null));
6757
- return history == null ? void 0 : _chunk4ESGNS3Zcjs.toUint8Array.call(void 0, history);
6965
+ return history == null ? void 0 : _chunkTAG6UEL5cjs.toUint8Array.call(void 0, history);
6758
6966
  }
6759
6967
  ) : void 0,
6760
6968
  actions: Object.fromEntries(
@@ -6795,7 +7003,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6795
7003
  timeoutMs,
6796
7004
  cancelToken
6797
7005
  } = unwrapTsfnPayload(error, payload);
6798
- const jsRequest = buildRequest(request);
7006
+ const jsRequest = buildNativeHttpRequest(request);
6799
7007
  const actorCtx = withConnContext(
6800
7008
  runtime,
6801
7009
  ctx,
@@ -6818,7 +7026,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6818
7026
  name
6819
7027
  );
6820
7028
  if (canPublish && !await canPublish(actorCtx)) {
6821
- throw _chunkSPJORZMMcjs.forbiddenError.call(void 0, );
7029
+ throw _chunk2JSYYH6Pcjs.forbiddenError.call(void 0, );
6822
7030
  }
6823
7031
  const decodedBody = decodeValue(body);
6824
7032
  if (wait) {
@@ -6865,7 +7073,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6865
7073
  buildActorConfig(definition, registryConfig, runtime.kind)
6866
7074
  );
6867
7075
  }
6868
- async function buildServeConfig(config) {
7076
+ async function buildServeConfig(config, resolveServicesBinary = true) {
6869
7077
  var _a;
6870
7078
  if (!config.endpoint) {
6871
7079
  throw nativeEndpointNotConfiguredError();
@@ -6876,9 +7084,10 @@ async function buildServeConfig(config) {
6876
7084
  token: config.token,
6877
7085
  namespace: config.namespace,
6878
7086
  poolName: config.envoy.poolName,
7087
+ startServices: resolveServicesBinary && config.startServices,
6879
7088
  handleInspectorHttpInRuntime: true,
6880
7089
  serverlessBasePath: config.serverless.basePath,
6881
- serverlessPackageVersion: _chunk4ESGNS3Zcjs.VERSION,
7090
+ serverlessPackageVersion: _chunkTAG6UEL5cjs.VERSION,
6882
7091
  serverlessClientEndpoint: config.publicEndpoint,
6883
7092
  serverlessClientNamespace: config.publicNamespace,
6884
7093
  serverlessClientToken: config.publicToken,
@@ -6891,19 +7100,30 @@ async function buildServeConfig(config) {
6891
7100
  } catch (error) {
6892
7101
  logger2().warn({
6893
7102
  msg: "could not resolve a local engine binary; if a local engine must be spawned it will fail with engine.binary_unavailable \u2014 set RIVET_ENGINE_BINARY_PATH or install the @rivetkit/engine-cli platform package",
6894
- error: _chunk4ESGNS3Zcjs.stringifyError.call(void 0, error)
7103
+ error: _chunkTAG6UEL5cjs.stringifyError.call(void 0, error)
6895
7104
  });
6896
7105
  }
7106
+ if (resolveServicesBinary && config.startServices) {
7107
+ try {
7108
+ const { getServicesPath } = await loadServices();
7109
+ serveConfig.servicesBinaryPath = getServicesPath();
7110
+ } catch (error) {
7111
+ logger2().warn({
7112
+ msg: "could not resolve the Services binary; a local engine will fail with services.binary_unavailable \u2014 set RIVET_RUN_SERVICES=0 to disable Services or RIVET_SERVICES_BINARY to a local rivet-services binary",
7113
+ error: _chunkTAG6UEL5cjs.stringifyError.call(void 0, error)
7114
+ });
7115
+ }
7116
+ }
6897
7117
  serveConfig.engineHost = config.engineHost;
6898
7118
  serveConfig.enginePort = config.enginePort;
6899
7119
  if ((_a = config.test) == null ? void 0 : _a.enabled) {
6900
- serveConfig.inspectorTestToken = _nullishCoalesce(_chunk4ESGNS3Zcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
7120
+ serveConfig.inspectorTestToken = _nullishCoalesce(_chunkTAG6UEL5cjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
6901
7121
  }
6902
7122
  return serveConfig;
6903
7123
  }
6904
7124
  async function buildRegistryWithRuntime(config, runtime) {
6905
7125
  var _a;
6906
- if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunk4ESGNS3Zcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
7126
+ if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkTAG6UEL5cjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
6907
7127
  trySetProcessEnv("_RIVET_TEST_INSPECTOR_TOKEN", "token");
6908
7128
  }
6909
7129
  if (runtime.kind === "napi") {
@@ -6920,7 +7140,7 @@ async function buildRegistryWithRuntime(config, runtime) {
6920
7140
  return {
6921
7141
  runtime,
6922
7142
  registry,
6923
- serveConfig: await buildServeConfig(config)
7143
+ serveConfig: await buildServeConfig(config, runtime.kind === "napi")
6924
7144
  };
6925
7145
  }
6926
7146
  async function buildConfiguredRegistry(config) {
@@ -6947,26 +7167,51 @@ function finishShutdownSignal(signal) {
6947
7167
  }
6948
7168
  process.kill(process.pid, signal);
6949
7169
  }
6950
- function createApplicationFetch(application) {
6951
- return async (request) => {
7170
+ function createApplicationFetch(application, runtime) {
7171
+ return async (request, responseBodyStream) => {
6952
7172
  const method2 = request.method.toUpperCase();
6953
7173
  const body = method2 === "GET" || method2 === "HEAD" || request.body.length === 0 ? void 0 : Uint8Array.from(request.body).buffer;
7174
+ const abortController = new AbortController();
7175
+ if (request.cancelToken) {
7176
+ if (runtime.cancellationTokenAborted(request.cancelToken)) {
7177
+ abortController.abort();
7178
+ } else {
7179
+ runtime.onCancellationTokenCancelled(
7180
+ request.cancelToken,
7181
+ () => abortController.abort()
7182
+ );
7183
+ }
7184
+ }
6954
7185
  const response = await application.fetch(
6955
7186
  new Request(request.url, {
6956
7187
  method: method2,
6957
7188
  headers: request.headers,
6958
- body
7189
+ body,
7190
+ signal: abortController.signal
6959
7191
  })
6960
7192
  );
6961
- if (!_chunkPZBWSCQRcjs.isResponseLike.call(void 0, response)) {
7193
+ if (!_chunkTZPNSOG2cjs.isResponseLike.call(void 0, response)) {
6962
7194
  throw new TypeError(
6963
7195
  "registry.listen() application fetch must return a Response"
6964
7196
  );
6965
7197
  }
7198
+ const conversion = await convertNativeHttpResponse(
7199
+ response,
7200
+ responseBodyStream
7201
+ );
7202
+ if (conversion.bodyCompletion) {
7203
+ void conversion.bodyCompletion.catch((error) => {
7204
+ logger2().error({
7205
+ msg: "application response stream failed",
7206
+ error
7207
+ });
7208
+ });
7209
+ }
6966
7210
  return {
6967
- status: response.status,
6968
- headers: Object.fromEntries(response.headers.entries()),
6969
- body: new Uint8Array(await response.arrayBuffer())
7211
+ status: _nullishCoalesce(conversion.response.status, () => ( response.status)),
7212
+ headers: _nullishCoalesce(conversion.response.headers, () => ( Object.fromEntries(response.headers.entries()))),
7213
+ body: conversion.response.body,
7214
+ stream: conversion.response.stream
6970
7215
  };
6971
7216
  };
6972
7217
  }
@@ -6995,7 +7240,7 @@ var Registry = class {
6995
7240
  var _a;
6996
7241
  this.#config = config;
6997
7242
  if ((_a = config.logging) == null ? void 0 : _a.baseLogger) {
6998
- _chunk4ESGNS3Zcjs.configureBaseLogger.call(void 0, config.logging.baseLogger);
7243
+ _chunkTAG6UEL5cjs.configureBaseLogger.call(void 0, config.logging.baseLogger);
6999
7244
  }
7000
7245
  this.#buildConfiguredRegistry = _nullishCoalesce((deps == null ? void 0 : deps.buildConfiguredRegistry), () => ( buildConfiguredRegistry));
7001
7246
  this.routes = {
@@ -7221,11 +7466,10 @@ var Registry = class {
7221
7466
  * ```
7222
7467
  */
7223
7468
  async listen(opts = {}) {
7224
- const port = _nullishCoalesce(_nullishCoalesce(opts.port, () => ( _chunk4ESGNS3Zcjs.parsePortEnv.call(void 0, process.env.RIVET_PORT))), () => ( 3e3));
7225
- const publicDir = _nullishCoalesce(opts.publicDir, () => ( _chunk4ESGNS3Zcjs.getRivetkitPublicDir.call(void 0, )));
7469
+ const port = _nullishCoalesce(_nullishCoalesce(opts.port, () => ( _chunkTAG6UEL5cjs.parsePortEnv.call(void 0, process.env.RIVET_PORT))), () => ( 3e3));
7470
+ const publicDir = _nullishCoalesce(opts.publicDir, () => ( _chunkTAG6UEL5cjs.getRivetkitPublicDir.call(void 0, )));
7226
7471
  const config = this.parseConfig();
7227
- const application = opts.application ? createApplicationFetch(opts.application) : void 0;
7228
- if (application && _chunk4ESGNS3Zcjs.getRivetkitRuntimeMode.call(void 0, ) !== "serverless") {
7472
+ if (opts.application && _chunkTAG6UEL5cjs.getRivetkitRuntimeMode.call(void 0, ) !== "serverless") {
7229
7473
  if (config.runtime === "wasm") {
7230
7474
  throw new Error(
7231
7475
  "registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly"
@@ -7244,13 +7488,18 @@ var Registry = class {
7244
7488
  throw new Error("registry envoy startup did not initialize");
7245
7489
  }
7246
7490
  const { runtime: runtime2, registry: registry2, serveConfig: serveConfig2 } = await configuredRegistryPromise2;
7491
+ const application2 = createApplicationFetch(
7492
+ opts.application,
7493
+ runtime2
7494
+ );
7495
+ await readyPromise;
7247
7496
  const listenerPromise = runtime2.serveApplicationListener(
7248
7497
  registry2,
7249
7498
  {
7250
7499
  port,
7251
7500
  host: opts.host,
7252
7501
  publicDir,
7253
- application
7502
+ application: application2
7254
7503
  },
7255
7504
  serveConfig2
7256
7505
  );
@@ -7261,14 +7510,10 @@ var Registry = class {
7261
7510
  "registry envoy serve lifecycle did not initialize"
7262
7511
  );
7263
7512
  }
7264
- await Promise.all([
7265
- readyPromise,
7266
- listenerPromise,
7267
- serveLifecyclePromise
7268
- ]);
7513
+ await Promise.all([listenerPromise, serveLifecyclePromise]);
7269
7514
  return;
7270
7515
  }
7271
- const configuredRegistryPromise = buildConfiguredRegistry(config);
7516
+ const configuredRegistryPromise = this.#buildConfiguredRegistry(config);
7272
7517
  this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
7273
7518
  this.#runtimeServerlessPromise = configuredRegistryPromise;
7274
7519
  this.#installSignalHandlers(config);
@@ -7279,6 +7524,7 @@ var Registry = class {
7279
7524
  });
7280
7525
  this.#ensureServerlessPoolConfigured(config);
7281
7526
  const { runtime, registry, serveConfig } = await configuredRegistryPromise;
7527
+ const application = opts.application ? createApplicationFetch(opts.application, runtime) : void 0;
7282
7528
  await runtime.serveListener(
7283
7529
  registry,
7284
7530
  {
@@ -7299,7 +7545,7 @@ var Registry = class {
7299
7545
  return jsonRouteResponse(503, {
7300
7546
  status: "not_started",
7301
7547
  runtime: "rivetkit",
7302
- version: _chunk4ESGNS3Zcjs.VERSION
7548
+ version: _chunkTAG6UEL5cjs.VERSION
7303
7549
  });
7304
7550
  }
7305
7551
  const { runtime, registry } = configured;
@@ -7307,7 +7553,7 @@ var Registry = class {
7307
7553
  return jsonRouteResponse(501, {
7308
7554
  status: "unsupported",
7309
7555
  runtime: "rivetkit",
7310
- version: _chunk4ESGNS3Zcjs.VERSION
7556
+ version: _chunkTAG6UEL5cjs.VERSION
7311
7557
  });
7312
7558
  }
7313
7559
  const response = await runtime.registryHealth(registry);
@@ -7554,7 +7800,7 @@ var Registry = class {
7554
7800
  );
7555
7801
  }
7556
7802
  if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
7557
- if (_chunk4ESGNS3Zcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
7803
+ if (_chunkTAG6UEL5cjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
7558
7804
  return Promise.reject(
7559
7805
  new Error(
7560
7806
  "registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request"
@@ -7624,8 +7870,8 @@ var Registry = class {
7624
7870
  * ```
7625
7871
  */
7626
7872
  start() {
7627
- if (_chunk4ESGNS3Zcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
7628
- const publicDir = _nullishCoalesce(_chunk4ESGNS3Zcjs.getRivetkitPublicDir.call(void 0, ), () => ( "/public"));
7873
+ if (_chunkTAG6UEL5cjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
7874
+ const publicDir = _nullishCoalesce(_chunkTAG6UEL5cjs.getRivetkitPublicDir.call(void 0, ), () => ( "/public"));
7629
7875
  this.listen({ publicDir }).catch((error) => {
7630
7876
  logger2().error({ error }, "auto-listen failed; exiting");
7631
7877
  if (typeof process !== "undefined" && typeof process.exit === "function") {
@@ -7646,7 +7892,7 @@ var Registry = class {
7646
7892
  };
7647
7893
  console.log();
7648
7894
  console.log(
7649
- ` RivetKit ${_chunk4ESGNS3Zcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
7895
+ ` RivetKit ${_chunkTAG6UEL5cjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
7650
7896
  );
7651
7897
  if (config.namespace !== "default") {
7652
7898
  logLine("Namespace", config.namespace);
@@ -7722,5 +7968,5 @@ function setup(input) {
7722
7968
 
7723
7969
 
7724
7970
 
7725
- exports.ALLOWED_PUBLIC_HEADERS = _chunkPZBWSCQRcjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunkSPJORZMMcjs.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 = _chunkSPJORZMMcjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunkSPJORZMMcjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunkPZBWSCQRcjs.createClientWithDriver; exports.defineRunHandler = _chunk4KGXFC6Mcjs.defineRunHandler; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunk4ESGNS3Zcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunk4ESGNS3Zcjs.toUint8Array;
7971
+ exports.ALLOWED_PUBLIC_HEADERS = _chunkTZPNSOG2cjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunk2JSYYH6Pcjs.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 = _chunk2JSYYH6Pcjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunk2JSYYH6Pcjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunkTZPNSOG2cjs.createClientWithDriver; exports.defineRunHandler = _chunk4KGXFC6Mcjs.defineRunHandler; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkTAG6UEL5cjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkTAG6UEL5cjs.toUint8Array;
7726
7972
  //# sourceMappingURL=mod.cjs.map