rivetkit 2.3.18-rc.4 → 2.3.19

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 (136) hide show
  1. package/dist/browser/client.d.ts +723 -616
  2. package/dist/browser/client.js +184 -28
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +3 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +6 -2
  7. package/dist/tsup/actor/errors.cjs.map +1 -1
  8. package/dist/tsup/actor/errors.d.cts +1 -1
  9. package/dist/tsup/actor/errors.d.ts +1 -1
  10. package/dist/tsup/actor/errors.js +5 -1
  11. package/dist/tsup/agent-os/index.cjs +3 -1
  12. package/dist/tsup/agent-os/index.cjs.map +1 -1
  13. package/dist/tsup/agent-os/index.d.cts +110 -3
  14. package/dist/tsup/agent-os/index.d.ts +110 -3
  15. package/dist/tsup/agent-os/index.js +3 -1
  16. package/dist/tsup/agent-os/index.js.map +1 -1
  17. package/dist/tsup/{chunk-ENDOWQTM.js → chunk-464WE4RF.js} +2 -2
  18. package/dist/tsup/{chunk-KKG2CTSI.js → chunk-4SC2NSAV.js} +2 -2
  19. package/dist/tsup/{chunk-R2WRP6VV.cjs → chunk-7A5EIXJJ.cjs} +7 -7
  20. package/dist/tsup/{chunk-R2WRP6VV.cjs.map → chunk-7A5EIXJJ.cjs.map} +1 -1
  21. package/dist/tsup/{chunk-GUVDWB2O.cjs → chunk-7BRRGBRY.cjs} +10 -10
  22. package/dist/tsup/{chunk-GUVDWB2O.cjs.map → chunk-7BRRGBRY.cjs.map} +1 -1
  23. package/dist/tsup/{chunk-KVPU65TI.js → chunk-7HTST3NX.js} +3 -3
  24. package/dist/tsup/{chunk-MS6C3B2I.js → chunk-BKX7UDTA.js} +185 -28
  25. package/dist/tsup/chunk-BKX7UDTA.js.map +1 -0
  26. package/dist/tsup/{chunk-FL2FDUSZ.js → chunk-DK3L22R6.js} +4 -4
  27. package/dist/tsup/{chunk-CAL23WOC.js → chunk-DN6MD3KK.js} +7 -7
  28. package/dist/tsup/chunk-DN6MD3KK.js.map +1 -0
  29. package/dist/tsup/{chunk-6W5VGLFT.js → chunk-EB77NZL4.js} +1 -1
  30. package/dist/tsup/chunk-EB77NZL4.js.map +1 -0
  31. package/dist/tsup/{chunk-4KGXFC6M.cjs → chunk-EO5UOXXY.cjs} +1 -1
  32. package/dist/tsup/chunk-EO5UOXXY.cjs.map +1 -0
  33. package/dist/tsup/{chunk-QFLG6UB4.cjs → chunk-G4U5L6AX.cjs} +3 -3
  34. package/dist/tsup/{chunk-QFLG6UB4.cjs.map → chunk-G4U5L6AX.cjs.map} +1 -1
  35. package/dist/tsup/{chunk-TGGF6SZN.cjs → chunk-IJUXBWH4.cjs} +351 -194
  36. package/dist/tsup/chunk-IJUXBWH4.cjs.map +1 -0
  37. package/dist/tsup/{chunk-2JSYYH6P.cjs → chunk-JX2ITWAV.cjs} +13 -2
  38. package/dist/tsup/chunk-JX2ITWAV.cjs.map +1 -0
  39. package/dist/tsup/{chunk-N3DJTMSZ.cjs → chunk-OGPFN6BT.cjs} +3 -3
  40. package/dist/tsup/{chunk-N3DJTMSZ.cjs.map → chunk-OGPFN6BT.cjs.map} +1 -1
  41. package/dist/tsup/{chunk-OUQUIBVW.js → chunk-P2OFXH4G.js} +12 -1
  42. package/dist/tsup/chunk-P2OFXH4G.js.map +1 -0
  43. package/dist/tsup/{chunk-F3IP3SGO.cjs → chunk-PPEIPCW4.cjs} +4 -4
  44. package/dist/tsup/{chunk-F3IP3SGO.cjs.map → chunk-PPEIPCW4.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-7E2W2YSM.cjs → chunk-RJC5O2SD.cjs} +13 -13
  46. package/dist/tsup/chunk-RJC5O2SD.cjs.map +1 -0
  47. package/dist/tsup/{chunk-YQD6RRVP.js → chunk-WME6KOXW.js} +2 -2
  48. package/dist/tsup/{chunk-PLAJJOTE.js → chunk-X7RMJQGY.js} +2 -2
  49. package/dist/tsup/{chunk-4OMHYVOQ.cjs → chunk-Z4RAXFSD.cjs} +3 -3
  50. package/dist/tsup/{chunk-4OMHYVOQ.cjs.map → chunk-Z4RAXFSD.cjs.map} +1 -1
  51. package/dist/tsup/client/mod.cjs +6 -6
  52. package/dist/tsup/client/mod.d.cts +5 -5
  53. package/dist/tsup/client/mod.d.ts +5 -5
  54. package/dist/tsup/client/mod.js +5 -5
  55. package/dist/tsup/common/log.cjs +3 -3
  56. package/dist/tsup/common/log.js +2 -2
  57. package/dist/tsup/common/websocket.cjs +4 -4
  58. package/dist/tsup/common/websocket.js +3 -3
  59. package/dist/tsup/{config-gvHwMas-.d.cts → config-8n2AOhXK.d.cts} +114 -10
  60. package/dist/tsup/{config-Ug5M2MOr.d.ts → config-DEm0yIVV.d.ts} +114 -10
  61. package/dist/tsup/{context-DererUCI.d.ts → context-DGg2-IOm.d.ts} +1 -1
  62. package/dist/tsup/{context-BSCBvbfM.d.cts → context-DwjOVvlE.d.cts} +1 -1
  63. package/dist/tsup/db/drizzle.cjs +3 -3
  64. package/dist/tsup/db/drizzle.js +2 -2
  65. package/dist/tsup/db/mod.cjs +4 -4
  66. package/dist/tsup/db/mod.js +3 -3
  67. package/dist/tsup/dynamic/mod.cjs +2 -2
  68. package/dist/tsup/dynamic/mod.d.cts +3 -3
  69. package/dist/tsup/dynamic/mod.d.ts +3 -3
  70. package/dist/tsup/dynamic/mod.js +1 -1
  71. package/dist/tsup/inspector/mod.cjs +6 -6
  72. package/dist/tsup/inspector/mod.js +5 -5
  73. package/dist/tsup/inspector/workflow.cjs +5 -5
  74. package/dist/tsup/inspector/workflow.js +4 -4
  75. package/dist/tsup/inspector-tab/mod.cjs +2 -2
  76. package/dist/tsup/inspector-tab/mod.d.cts +4 -4
  77. package/dist/tsup/inspector-tab/mod.d.ts +4 -4
  78. package/dist/tsup/inspector-tab/mod.js +1 -1
  79. package/dist/tsup/mod.cjs +492 -319
  80. package/dist/tsup/mod.cjs.map +1 -1
  81. package/dist/tsup/mod.d.cts +5 -5
  82. package/dist/tsup/mod.d.ts +5 -5
  83. package/dist/tsup/mod.js +367 -194
  84. package/dist/tsup/mod.js.map +1 -1
  85. package/dist/tsup/test/mod.cjs +7 -7
  86. package/dist/tsup/test/mod.d.cts +3 -3
  87. package/dist/tsup/test/mod.d.ts +3 -3
  88. package/dist/tsup/test/mod.js +5 -5
  89. package/dist/tsup/{utils-Bbz-3411.d.cts → utils-CNFeS-Dk.d.cts} +1 -1
  90. package/dist/tsup/{utils-vvJQyygr.d.ts → utils-DsoDinPz.d.cts} +9 -1
  91. package/dist/tsup/{utils-vvJQyygr.d.cts → utils-DsoDinPz.d.ts} +9 -1
  92. package/dist/tsup/{utils-BqdWVlzm.d.ts → utils-OQHBjfcM.d.ts} +1 -1
  93. package/dist/tsup/utils.cjs +3 -3
  94. package/dist/tsup/utils.d.cts +2 -2
  95. package/dist/tsup/utils.d.ts +2 -2
  96. package/dist/tsup/utils.js +2 -2
  97. package/dist/tsup/workflow/mod.cjs +33 -27
  98. package/dist/tsup/workflow/mod.cjs.map +1 -1
  99. package/dist/tsup/workflow/mod.d.cts +5 -5
  100. package/dist/tsup/workflow/mod.d.ts +5 -5
  101. package/dist/tsup/workflow/mod.js +25 -19
  102. package/dist/tsup/workflow/mod.js.map +1 -1
  103. package/package.json +10 -8
  104. package/src/actor/config.ts +38 -0
  105. package/src/actor/errors.ts +31 -0
  106. package/src/client/actor-conn.ts +7 -0
  107. package/src/client/actor-handle.ts +57 -17
  108. package/src/client/client.ts +26 -6
  109. package/src/client/outbound-telemetry.ts +66 -0
  110. package/src/client/queue.ts +3 -0
  111. package/src/client/raw-utils.ts +3 -0
  112. package/src/common/actor-router-consts.ts +3 -0
  113. package/src/common/actor-telemetry-context.ts +19 -0
  114. package/src/common/otel-context.ts +99 -0
  115. package/src/common/utils.ts +1 -19
  116. package/src/engine-client/actor-http-client.ts +15 -0
  117. package/src/registry/index.ts +6 -0
  118. package/src/registry/napi-runtime.ts +155 -35
  119. package/src/registry/native.ts +277 -191
  120. package/src/registry/runtime.ts +66 -0
  121. package/src/registry/wasm-runtime.ts +40 -0
  122. package/src/workflow/driver.ts +20 -12
  123. package/dist/tsup/chunk-2JSYYH6P.cjs.map +0 -1
  124. package/dist/tsup/chunk-4KGXFC6M.cjs.map +0 -1
  125. package/dist/tsup/chunk-6W5VGLFT.js.map +0 -1
  126. package/dist/tsup/chunk-7E2W2YSM.cjs.map +0 -1
  127. package/dist/tsup/chunk-CAL23WOC.js.map +0 -1
  128. package/dist/tsup/chunk-MS6C3B2I.js.map +0 -1
  129. package/dist/tsup/chunk-OUQUIBVW.js.map +0 -1
  130. package/dist/tsup/chunk-TGGF6SZN.cjs.map +0 -1
  131. /package/dist/tsup/{chunk-ENDOWQTM.js.map → chunk-464WE4RF.js.map} +0 -0
  132. /package/dist/tsup/{chunk-KKG2CTSI.js.map → chunk-4SC2NSAV.js.map} +0 -0
  133. /package/dist/tsup/{chunk-KVPU65TI.js.map → chunk-7HTST3NX.js.map} +0 -0
  134. /package/dist/tsup/{chunk-FL2FDUSZ.js.map → chunk-DK3L22R6.js.map} +0 -0
  135. /package/dist/tsup/{chunk-YQD6RRVP.js.map → chunk-WME6KOXW.js.map} +0 -0
  136. /package/dist/tsup/{chunk-PLAJJOTE.js.map → chunk-X7RMJQGY.js.map} +0 -0
package/dist/tsup/mod.cjs CHANGED
@@ -1,6 +1,5 @@
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 _chunkF3IP3SGOcjs = require('./chunk-F3IP3SGO.cjs');
4
3
 
5
4
 
6
5
 
@@ -14,9 +13,10 @@ var _chunkF3IP3SGOcjs = require('./chunk-F3IP3SGO.cjs');
14
13
 
15
14
 
16
15
 
16
+ var _chunkEO5UOXXYcjs = require('./chunk-EO5UOXXY.cjs');
17
17
 
18
18
 
19
- var _chunk4KGXFC6Mcjs = require('./chunk-4KGXFC6M.cjs');
19
+ var _chunkPPEIPCW4cjs = require('./chunk-PPEIPCW4.cjs');
20
20
 
21
21
 
22
22
 
@@ -28,17 +28,19 @@ var _chunk4KGXFC6Mcjs = require('./chunk-4KGXFC6M.cjs');
28
28
 
29
29
 
30
30
 
31
- var _chunkTGGF6SZNcjs = require('./chunk-TGGF6SZN.cjs');
31
+
32
+
33
+ var _chunkIJUXBWH4cjs = require('./chunk-IJUXBWH4.cjs');
32
34
 
33
35
 
34
36
 
35
37
  var _chunkMYWZCDMLcjs = require('./chunk-MYWZCDML.cjs');
36
- require('./chunk-N3DJTMSZ.cjs');
38
+ require('./chunk-OGPFN6BT.cjs');
37
39
 
38
40
 
39
41
 
40
42
 
41
- var _chunk4OMHYVOQcjs = require('./chunk-4OMHYVOQ.cjs');
43
+ var _chunkZ4RAXFSDcjs = require('./chunk-Z4RAXFSD.cjs');
42
44
  require('./chunk-KVFIONKQ.cjs');
43
45
 
44
46
 
@@ -73,7 +75,8 @@ require('./chunk-KVFIONKQ.cjs');
73
75
 
74
76
 
75
77
 
76
- var _chunk7E2W2YSMcjs = require('./chunk-7E2W2YSM.cjs');
78
+ var _chunkRJC5O2SDcjs = require('./chunk-RJC5O2SD.cjs');
79
+
77
80
 
78
81
 
79
82
 
@@ -85,11 +88,11 @@ var _chunk7E2W2YSMcjs = require('./chunk-7E2W2YSM.cjs');
85
88
 
86
89
 
87
90
 
88
- var _chunk2JSYYH6Pcjs = require('./chunk-2JSYYH6P.cjs');
91
+ var _chunkJX2ITWAVcjs = require('./chunk-JX2ITWAV.cjs');
89
92
 
90
93
  // src/actor/log.ts
91
94
  function loggerWithoutContext() {
92
- return _chunk7E2W2YSMcjs.getLogger.call(void 0, "actor-runtime");
95
+ return _chunkRJC5O2SDcjs.getLogger.call(void 0, "actor-runtime");
93
96
  }
94
97
 
95
98
  // src/actor/definition.ts
@@ -128,9 +131,9 @@ function actor(input) {
128
131
  warnDeprecatedOptionKeys(
129
132
  input == null ? void 0 : input.options
130
133
  );
131
- const config = _chunk4KGXFC6Mcjs.ActorConfigSchema.parse(input);
132
- _chunk4KGXFC6Mcjs.flattenActionHandlers.call(void 0, config.actions);
133
- _chunk4KGXFC6Mcjs.flattenActionInputSchemas.call(void 0, config.actions, config.actionInputSchemas);
134
+ const config = _chunkEO5UOXXYcjs.ActorConfigSchema.parse(input);
135
+ _chunkEO5UOXXYcjs.flattenActionHandlers.call(void 0, config.actions);
136
+ _chunkEO5UOXXYcjs.flattenActionInputSchemas.call(void 0, config.actions, config.actionInputSchemas);
134
137
  return new ActorDefinition(config);
135
138
  }
136
139
  function isStaticActorDefinition(definition) {
@@ -212,7 +215,7 @@ function validateSchemaSync(schemas, key, data) {
212
215
  if (isStandardSchema(schema)) {
213
216
  const result = schema["~standard"].validate(data);
214
217
  if (isPromiseLike(result)) {
215
- throw _chunk2JSYYH6Pcjs.unsupportedFeature.call(void 0, "async schema validation");
218
+ throw _chunkJX2ITWAVcjs.unsupportedFeature.call(void 0, "async schema validation");
216
219
  }
217
220
  if (result.issues) {
218
221
  return { success: false, issues: [...result.issues] };
@@ -229,7 +232,7 @@ function validateSchemaSync(schemas, key, data) {
229
232
  var _virtualwebsocket = require('@rivetkit/virtual-websocket');
230
233
  var _ws = require('hono/ws');
231
234
  function logger() {
232
- return _chunk7E2W2YSMcjs.getLogger.call(void 0, "inline-websocket-adapter");
235
+ return _chunkRJC5O2SDcjs.getLogger.call(void 0, "inline-websocket-adapter");
233
236
  }
234
237
  var InlineWebSocketAdapter = class {
235
238
  #handler;
@@ -400,7 +403,7 @@ function isLocalEngineEndpoint(endpoint) {
400
403
 
401
404
  // src/registry/log.ts
402
405
  function logger2() {
403
- return _chunk7E2W2YSMcjs.getLogger.call(void 0, "registry");
406
+ return _chunkRJC5O2SDcjs.getLogger.call(void 0, "registry");
404
407
  }
405
408
 
406
409
  // src/serverless/configure.ts
@@ -446,8 +449,8 @@ async function configureServerlessPool(config) {
446
449
  );
447
450
  }
448
451
  const customConfig = config.configurePool;
449
- const clientConfig = _chunkTGGF6SZNcjs.convertRegistryConfigToClientConfig.call(void 0, config);
450
- const dcsRes = await _chunkTGGF6SZNcjs.getDatacenters.call(void 0, clientConfig);
452
+ const clientConfig = _chunkIJUXBWH4cjs.convertRegistryConfigToClientConfig.call(void 0, config);
453
+ const dcsRes = await _chunkIJUXBWH4cjs.getDatacenters.call(void 0, clientConfig);
451
454
  const poolName = _nullishCoalesce(customConfig.name, () => ( "default"));
452
455
  const serverlessToken = _nullishCoalesce(config.token, () => ( config.publicToken));
453
456
  const headers = {
@@ -469,7 +472,7 @@ async function configureServerlessPool(config) {
469
472
  metadata: _nullishCoalesce(customConfig.metadata, () => ( {})),
470
473
  drain_on_version_upgrade: _nullishCoalesce(customConfig.drainOnVersionUpgrade, () => ( true))
471
474
  };
472
- await _chunkTGGF6SZNcjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
475
+ await _chunkIJUXBWH4cjs.updateRunnerConfig.call(void 0, clientConfig, poolName, {
473
476
  datacenters: Object.fromEntries(
474
477
  dcsRes.datacenters.map((dc) => [dc.name, serverlessConfig])
475
478
  )
@@ -486,7 +489,7 @@ async function configureServerlessPool(config) {
486
489
  logger2().warn({
487
490
  msg: "serverless pool configuration attempt failed",
488
491
  attempts,
489
- error: _chunk7E2W2YSMcjs.stringifyError.call(void 0, error)
492
+ error: _chunkRJC5O2SDcjs.stringifyError.call(void 0, error)
490
493
  });
491
494
  await sleep(CONFIGURE_RETRY_DELAY_MS);
492
495
  }
@@ -494,7 +497,7 @@ async function configureServerlessPool(config) {
494
497
  logger2().error({
495
498
  msg: "failed to configure serverless pool, validate endpoint is configured correctly then restart this process",
496
499
  attempts,
497
- error: _chunk7E2W2YSMcjs.stringifyError.call(void 0, lastError)
500
+ error: _chunkRJC5O2SDcjs.stringifyError.call(void 0, lastError)
498
501
  });
499
502
  throw lastError;
500
503
  }
@@ -506,20 +509,20 @@ var _zod = require('zod');
506
509
  var _v4 = require('zod/v4');
507
510
  var warnedMissingVersion = false;
508
511
  var EnvoyConfigSchema = _v4.z.object({
509
- poolName: _v4.z.string().default(() => _nullishCoalesce(_chunk7E2W2YSMcjs.getRivetPool.call(void 0, ), () => ( "default"))),
512
+ poolName: _v4.z.string().default(() => _nullishCoalesce(_chunkRJC5O2SDcjs.getRivetPool.call(void 0, ), () => ( "default"))),
510
513
  version: _v4.z.number().default(() => {
511
- const version = _chunk7E2W2YSMcjs.getRivetEnvoyVersion.call(void 0, );
514
+ const version = _chunkRJC5O2SDcjs.getRivetEnvoyVersion.call(void 0, );
512
515
  if (version !== void 0) return version;
513
- if (_chunk7E2W2YSMcjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
516
+ if (_chunkRJC5O2SDcjs.getNodeEnv.call(void 0, ) === "production" && !warnedMissingVersion) {
514
517
  warnedMissingVersion = true;
515
- _chunk7E2W2YSMcjs.getLogger.call(void 0, "rivetkit").error(
518
+ _chunkRJC5O2SDcjs.getLogger.call(void 0, "rivetkit").error(
516
519
  "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"
517
520
  );
518
521
  }
519
522
  return 1;
520
523
  }),
521
524
  // Deprecated.
522
- totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunk7E2W2YSMcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
525
+ totalSlots: _v4.z.number().default(() => _nullishCoalesce(_chunkRJC5O2SDcjs.getRivetTotalSlots.call(void 0, ), () => ( 1e5))),
523
526
  envoyKey: _v4.z.string().optional()
524
527
  });
525
528
 
@@ -557,7 +560,7 @@ var ServerlessConfigSchema = _v4.z.object({
557
560
  *
558
561
  * Can also be set via RIVET_PUBLIC_ENDPOINT environment variable.
559
562
  */
560
- publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk7E2W2YSMcjs.getRivetPublicEndpoint.call(void 0, )))),
563
+ publicEndpoint: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkRJC5O2SDcjs.getRivetPublicEndpoint.call(void 0, )))),
561
564
  /**
562
565
  * Token that clients should use when connecting via the public endpoint.
563
566
  *
@@ -565,7 +568,7 @@ var ServerlessConfigSchema = _v4.z.object({
565
568
  *
566
569
  * Can also be specified in the publicEndpoint URL as `https://namespace:token@host`.
567
570
  */
568
- publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk7E2W2YSMcjs.getRivetPublicToken.call(void 0, ))))
571
+ publicToken: _v4.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkRJC5O2SDcjs.getRivetPublicToken.call(void 0, ))))
569
572
  // There is no publicNamespace config option because the frontend and backend
570
573
  // cannot use different namespaces. The namespace is extracted from the
571
574
  // publicEndpoint URL auth syntax if provided.
@@ -619,7 +622,7 @@ var RegistryConfigSchema = _zod.z.object({
619
622
  * Runtime binding to use for RivetKit core.
620
623
  * */
621
624
  runtime: RuntimeKindSchema.optional().transform((val, ctx) => {
622
- const rawRuntime = _nullishCoalesce(val, () => ( _chunk7E2W2YSMcjs.getRivetkitRuntime.call(void 0, )));
625
+ const rawRuntime = _nullishCoalesce(val, () => ( _chunkRJC5O2SDcjs.getRivetkitRuntime.call(void 0, )));
623
626
  if (rawRuntime === void 0) {
624
627
  return "auto";
625
628
  }
@@ -656,7 +659,7 @@ var RegistryConfigSchema = _zod.z.object({
656
659
  * */
657
660
  logging: _zod.z.object({
658
661
  baseLogger: _zod.z.custom().optional(),
659
- level: _chunk7E2W2YSMcjs.LogLevelSchema.optional()
662
+ level: _chunkRJC5O2SDcjs.LogLevelSchema.optional()
660
663
  }).optional().default(() => ({})),
661
664
  // MARK: Routing
662
665
  // // This is a function to allow for lazy configuration of upgradeWebSocket on the
@@ -674,9 +677,9 @@ var RegistryConfigSchema = _zod.z.object({
674
677
  *
675
678
  * Can also be set via RIVET_ENDPOINT environment variables.
676
679
  */
677
- endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunk7E2W2YSMcjs.getRivetEngine.call(void 0, ))), () => ( _chunk7E2W2YSMcjs.getRivetEndpoint.call(void 0, )))),
678
- token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk7E2W2YSMcjs.getRivetToken.call(void 0, )))),
679
- namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunk7E2W2YSMcjs.getRivetNamespace.call(void 0, )))),
680
+ endpoint: _zod.z.string().optional().transform((val) => _nullishCoalesce(_nullishCoalesce(val, () => ( _chunkRJC5O2SDcjs.getRivetEngine.call(void 0, ))), () => ( _chunkRJC5O2SDcjs.getRivetEndpoint.call(void 0, )))),
681
+ token: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkRJC5O2SDcjs.getRivetToken.call(void 0, )))),
682
+ namespace: _zod.z.string().optional().transform((val) => _nullishCoalesce(val, () => ( _chunkRJC5O2SDcjs.getRivetNamespace.call(void 0, )))),
680
683
  headers: _zod.z.record(_zod.z.string(), _zod.z.string()).optional().default({}),
681
684
  // MARK: Client
682
685
  // TODO:
@@ -716,21 +719,21 @@ var RegistryConfigSchema = _zod.z.object({
716
719
  *
717
720
  * Starts the full Rust engine process locally.
718
721
  */
719
- startEngine: _zod.z.boolean().default(() => _chunk7E2W2YSMcjs.getRivetRunEngine.call(void 0, )),
722
+ startEngine: _zod.z.boolean().default(() => _chunkRJC5O2SDcjs.getRivetRunEngine.call(void 0, )),
720
723
  /**
721
724
  * @experimental
722
725
  *
723
726
  * Host to bind the spawned local engine process to.
724
727
  */
725
- engineHost: _zod.z.string().optional().default(() => _nullishCoalesce(_chunk7E2W2YSMcjs.getRivetRunEngineHost.call(void 0, ), () => ( ENGINE_HOST))),
728
+ engineHost: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkRJC5O2SDcjs.getRivetRunEngineHost.call(void 0, ), () => ( ENGINE_HOST))),
726
729
  /**
727
730
  * @experimental
728
731
  *
729
732
  * Port to bind the spawned local engine process to.
730
733
  */
731
- enginePort: _zod.z.number().int().min(1).max(65535).optional().default(() => _nullishCoalesce(_chunk7E2W2YSMcjs.getRivetRunEnginePort.call(void 0, ), () => ( ENGINE_PORT))),
734
+ enginePort: _zod.z.number().int().min(1).max(65535).optional().default(() => _nullishCoalesce(_chunkRJC5O2SDcjs.getRivetRunEnginePort.call(void 0, ), () => ( ENGINE_PORT))),
732
735
  /** @experimental */
733
- engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunk7E2W2YSMcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunk7E2W2YSMcjs.VERSION))),
736
+ engineVersion: _zod.z.string().optional().default(() => _nullishCoalesce(_chunkRJC5O2SDcjs.getRivetRunEngineVersion.call(void 0, ), () => ( _chunkRJC5O2SDcjs.VERSION))),
734
737
  /**
735
738
  * Starts the first-party Services actor host when RivetKit manages
736
739
  * a local engine. Defaults to the local-engine decision. Set
@@ -784,7 +787,7 @@ var RegistryConfigSchema = _zod.z.object({
784
787
  }))
785
788
  }).transform((config, ctx) => {
786
789
  var _a, _b, _c;
787
- const isDevEnv = _chunk7E2W2YSMcjs.isDev.call(void 0, );
790
+ const isDevEnv = _chunkRJC5O2SDcjs.isDev.call(void 0, );
788
791
  const sqliteBackend = _nullishCoalesce(((_a = config.sqlite) == null ? void 0 : _a.backend), () => ( ((_b = config.test) == null ? void 0 : _b.sqliteBackend)));
789
792
  if (config.runtime === "wasm" && sqliteBackend === "local") {
790
793
  ctx.addIssue({
@@ -794,7 +797,7 @@ var RegistryConfigSchema = _zod.z.object({
794
797
  });
795
798
  }
796
799
  const sqlite = config.runtime === "wasm" && config.sqlite === void 0 ? { backend: "remote" } : config.sqlite;
797
- const parsedEndpoint = config.endpoint ? _chunkTGGF6SZNcjs.tryParseEndpoint.call(void 0, ctx, {
800
+ const parsedEndpoint = config.endpoint ? _chunkIJUXBWH4cjs.tryParseEndpoint.call(void 0, ctx, {
798
801
  endpoint: config.endpoint,
799
802
  path: ["endpoint"],
800
803
  namespace: config.namespace,
@@ -817,13 +820,13 @@ var RegistryConfigSchema = _zod.z.object({
817
820
  config.enginePort
818
821
  );
819
822
  const endpoint = config.startEngine ? localEngineEndpoint : _nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint), () => ( (isDevEnv ? localEngineEndpoint : void 0)));
820
- const startServices = _nullishCoalesce(_nullishCoalesce(config.startServices, () => ( _chunk7E2W2YSMcjs.getRivetRunServices.call(void 0, ))), () => ( Boolean(endpoint && isLocalEngineEndpoint(endpoint))));
823
+ const startServices = _nullishCoalesce(_nullishCoalesce(config.startServices, () => ( _chunkRJC5O2SDcjs.getRivetRunServices.call(void 0, ))), () => ( Boolean(endpoint && isLocalEngineEndpoint(endpoint))));
821
824
  const validateServerlessEndpoint = Boolean(
822
825
  config.startEngine || parsedEndpoint
823
826
  );
824
827
  const namespace = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.namespace), () => ( config.namespace)), () => ( "default"));
825
828
  const token = _nullishCoalesce(_nullishCoalesce((parsedEndpoint == null ? void 0 : parsedEndpoint.token), () => ( config.token)), () => ( "dev"));
826
- const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkTGGF6SZNcjs.tryParseEndpoint.call(void 0, ctx, {
829
+ const parsedPublicEndpoint = config.serverless.publicEndpoint ? _chunkIJUXBWH4cjs.tryParseEndpoint.call(void 0, ctx, {
827
830
  endpoint: config.serverless.publicEndpoint,
828
831
  path: ["serverless", "publicEndpoint"]
829
832
  }) : void 0;
@@ -859,7 +862,7 @@ function buildActorNames(config) {
859
862
  Object.keys(config.use).map((actorName) => {
860
863
  const definition = config.use[actorName];
861
864
  const options = _nullishCoalesce(definition.config.options, () => ( {}));
862
- const runMeta = _chunk4KGXFC6Mcjs.getRunMetadata.call(void 0, definition.config.run);
865
+ const runMeta = _chunkEO5UOXXYcjs.getRunMetadata.call(void 0, definition.config.run);
863
866
  const metadata = {};
864
867
  metadata.icon = _nullishCoalesce(options.icon, () => ( runMeta.icon));
865
868
  metadata.name = _nullishCoalesce(options.name, () => ( runMeta.name));
@@ -927,7 +930,7 @@ var DocRegistryConfigSchema = _zod.z.object({
927
930
  noWelcome: _zod.z.boolean().optional().describe("Disable the welcome message on startup. Default: false"),
928
931
  sqlite: DocSqliteConfigSchema,
929
932
  logging: _zod.z.object({
930
- level: _chunk7E2W2YSMcjs.LogLevelSchema.optional().describe(
933
+ level: _chunkRJC5O2SDcjs.LogLevelSchema.optional().describe(
931
934
  "Log level for RivetKit. Default: 'warn'"
932
935
  )
933
936
  }).optional().describe("Logging configuration."),
@@ -975,7 +978,7 @@ function shouldAttachNativeKvError(message) {
975
978
  function enrichNativeDatabaseError(database, error) {
976
979
  var _a;
977
980
  const bridgeReason = typeof error === "string" ? error : error instanceof Error ? error.message : void 0;
978
- const bridged = bridgeReason === void 0 ? void 0 : _chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, bridgeReason);
981
+ const bridged = bridgeReason === void 0 ? void 0 : _chunkJX2ITWAVcjs.decodeBridgeRivetError.call(void 0, bridgeReason);
979
982
  if (bridged) {
980
983
  throw bridged;
981
984
  }
@@ -1545,20 +1548,43 @@ function toNapiQueueMessage(message) {
1545
1548
  var NapiCoreRuntime = (_class = class {
1546
1549
  __init() {this.kind = "napi"}
1547
1550
  #bindings;
1548
- #sql = /* @__PURE__ */ new WeakMap();
1549
- constructor(bindings) {;_class.prototype.__init.call(this);
1551
+ #sqlOpened = /* @__PURE__ */ new WeakSet();
1552
+ #invocationContext;
1553
+ constructor(bindings, invocationContext) {;_class.prototype.__init.call(this);
1550
1554
  this.#bindings = bindings;
1555
+ this.#invocationContext = invocationContext;
1551
1556
  }
1552
- #actorSql(ctx) {
1553
- const nativeCtx = asNativeActorContext(ctx);
1554
- let database = this.#sql.get(nativeCtx);
1555
- if (!database) {
1556
- database = nativeCtx.sql();
1557
- this.#sql.set(nativeCtx, database);
1557
+ #actorContextForOperation(owner) {
1558
+ const ownerCtx = asNativeActorContext(owner);
1559
+ const active = this.#invocationContext.getStore();
1560
+ if (!(active == null ? void 0 : active.sameActorInstance(ownerCtx))) {
1561
+ return ownerCtx;
1558
1562
  }
1559
- return database;
1563
+ const applicationSpan = _chunkIJUXBWH4cjs.readActiveTraceHeaders.call(void 0, );
1564
+ if (!applicationSpan) {
1565
+ return active;
1566
+ }
1567
+ return active.withApplicationSpan(
1568
+ applicationSpan.traceparent,
1569
+ _nullishCoalesce(applicationSpan.tracestate, () => ( null))
1570
+ );
1571
+ }
1572
+ #actorSql(ctx) {
1573
+ this.#sqlOpened.add(asNativeActorContext(ctx));
1574
+ return this.#actorContextForOperation(ctx).sql();
1560
1575
  }
1561
1576
  createRegistry() {
1577
+ this.#bindings.setTelemetryLogSink(
1578
+ (event2) => {
1579
+ const fields = { otelEvent: event2.name };
1580
+ const message = event2.message || event2.name;
1581
+ if (event2.level === "error") {
1582
+ logger2().error(fields, message);
1583
+ } else {
1584
+ logger2().warn(fields, message);
1585
+ }
1586
+ }
1587
+ );
1562
1588
  return asRegistryHandle(new this.#bindings.CoreRegistry());
1563
1589
  }
1564
1590
  registerActor(registry, name, factory) {
@@ -1573,6 +1599,9 @@ var NapiCoreRuntime = (_class = class {
1573
1599
  async shutdownRegistry(registry) {
1574
1600
  await asNativeRegistry(registry).shutdown();
1575
1601
  }
1602
+ async shutdownTelemetry() {
1603
+ await this.#bindings.shutdownTelemetry();
1604
+ }
1576
1605
  async registryActorStopThresholdMs(registry) {
1577
1606
  return await _asyncNullishCoalesce(await asNativeRegistry(registry).actorStopThresholdMs(), async () => ( void 0));
1578
1607
  }
@@ -1726,6 +1755,57 @@ var NapiCoreRuntime = (_class = class {
1726
1755
  actorId(ctx) {
1727
1756
  return asNativeActorContext(ctx).actorId();
1728
1757
  }
1758
+ runWithActorInvocationContext(ctx, run) {
1759
+ return this.#runAs(asNativeActorContext(ctx), run);
1760
+ }
1761
+ #runAs(nativeCtx, run) {
1762
+ var _a;
1763
+ const span = (_a = nativeCtx.invocationTraceContext()) == null ? void 0 : _a.span;
1764
+ return this.#invocationContext.run(
1765
+ nativeCtx,
1766
+ () => _chunkIJUXBWH4cjs.runWithActorInvocationSpan.call(void 0, span, run)
1767
+ );
1768
+ }
1769
+ actorInvocationTraceContext(ctx) {
1770
+ return _nullishCoalesce(this.#actorContextForOperation(ctx).invocationTraceContext(), () => ( void 0));
1771
+ }
1772
+ startCallSpan(ctx, actorName, actionName) {
1773
+ const call = this.#actorContextForOperation(ctx).startCallSpan(
1774
+ actorName,
1775
+ actionName
1776
+ );
1777
+ if (!call) return void 0;
1778
+ return {
1779
+ span: _nullishCoalesce(call.spanContext(), () => ( void 0)),
1780
+ finish: (error) => call.finish(error)
1781
+ };
1782
+ }
1783
+ async startWorkflowSpan(ctx) {
1784
+ const span = await asNativeActorContext(ctx).startWorkflowSpan();
1785
+ const spanCtx = span.ctx();
1786
+ return {
1787
+ run: (body) => this.#runAs(spanCtx, body),
1788
+ startStep: (name, attempt) => {
1789
+ const step = spanCtx.startWorkflowStepSpan(name, attempt);
1790
+ if (!step) return void 0;
1791
+ const stepCtx = step.ctx();
1792
+ return {
1793
+ run: (body) => this.#runAs(stepCtx, body),
1794
+ finish: (outcome, error) => step.finish(
1795
+ outcome,
1796
+ error === void 0 ? void 0 : _chunkJX2ITWAVcjs.encodeErrorForBridge.call(void 0, error)
1797
+ )
1798
+ };
1799
+ },
1800
+ finish: (outcome) => span.finish(outcome)
1801
+ };
1802
+ }
1803
+ runOutsideActorInvocationContext(run) {
1804
+ return this.#invocationContext.exit(run);
1805
+ }
1806
+ currentInvocationScope() {
1807
+ return this.#invocationContext.getStore();
1808
+ }
1729
1809
  actorName(ctx) {
1730
1810
  return asNativeActorContext(ctx).name();
1731
1811
  }
@@ -1757,7 +1837,7 @@ var NapiCoreRuntime = (_class = class {
1757
1837
  asNativeActorContext(ctx).broadcast(name, toNapiBuffer(args));
1758
1838
  }
1759
1839
  actorWaitUntil(ctx, promise) {
1760
- asNativeActorContext(ctx).waitUntil(promise);
1840
+ this.#actorContextForOperation(ctx).waitUntil(promise);
1761
1841
  }
1762
1842
  async actorWaitForTrackedShutdownWork(ctx) {
1763
1843
  return await asNativeActorContext(ctx).waitForTrackedShutdownWork();
@@ -1858,7 +1938,7 @@ var NapiCoreRuntime = (_class = class {
1858
1938
  await asNativeSqlTransaction(transaction).rollback();
1859
1939
  }
1860
1940
  async actorBeginStateTransaction(ctx, timeoutMs) {
1861
- return await asNativeActorContext(ctx).beginStateTransaction(
1941
+ return await this.#actorContextForOperation(ctx).beginStateTransaction(
1862
1942
  timeoutMs
1863
1943
  );
1864
1944
  }
@@ -1896,23 +1976,21 @@ var NapiCoreRuntime = (_class = class {
1896
1976
  }
1897
1977
  async actorSqlClose(ctx) {
1898
1978
  const nativeCtx = asNativeActorContext(ctx);
1899
- const database = this.#sql.get(nativeCtx);
1900
- if (!database) {
1979
+ if (!this.#sqlOpened.delete(nativeCtx)) {
1901
1980
  return;
1902
1981
  }
1903
- this.#sql.delete(nativeCtx);
1904
- await database.close();
1982
+ await nativeCtx.sql().close();
1905
1983
  }
1906
1984
  async actorRuntimeSocketProvision(ctx) {
1907
1985
  return await asNativeActorContext(ctx).provisionActorRuntimeSocket();
1908
1986
  }
1909
1987
  async actorQueueSend(ctx, name, body) {
1910
1988
  return toNapiQueueMessage(
1911
- await asNativeActorContext(ctx).queue().send(name, toNapiBuffer(body))
1989
+ await this.#actorContextForOperation(ctx).queue().send(name, toNapiBuffer(body))
1912
1990
  );
1913
1991
  }
1914
1992
  async actorQueueNextBatch(ctx, options, signal) {
1915
- const messages = await asNativeActorContext(ctx).queue().nextBatch(
1993
+ const messages = await this.#actorContextForOperation(ctx).queue().nextBatch(
1916
1994
  options,
1917
1995
  signal ? asNativeCancellationToken(signal) : signal
1918
1996
  );
@@ -1920,7 +1998,7 @@ var NapiCoreRuntime = (_class = class {
1920
1998
  }
1921
1999
  async actorQueueWaitForNames(ctx, names, options, signal) {
1922
2000
  return toNapiQueueMessage(
1923
- await asNativeActorContext(ctx).queue().waitForNames(
2001
+ await this.#actorContextForOperation(ctx).queue().waitForNames(
1924
2002
  names,
1925
2003
  options,
1926
2004
  signal ? asNativeCancellationToken(signal) : signal
@@ -1942,7 +2020,7 @@ var NapiCoreRuntime = (_class = class {
1942
2020
  );
1943
2021
  }
1944
2022
  async actorQueueEnqueueAndWait(ctx, name, body, options, signal) {
1945
- return await asNativeActorContext(ctx).queue().enqueueAndWait(
2023
+ return await this.#actorContextForOperation(ctx).queue().enqueueAndWait(
1946
2024
  name,
1947
2025
  toNapiBuffer(body),
1948
2026
  options,
@@ -1962,22 +2040,22 @@ var NapiCoreRuntime = (_class = class {
1962
2040
  await asNativeActorContext(ctx).queue().reset();
1963
2041
  }
1964
2042
  async actorScheduleAfter(ctx, durationMs, actionName, args) {
1965
- return await asNativeActorContext(ctx).schedule().after(durationMs, actionName, toNapiBuffer(args));
2043
+ return await this.#actorContextForOperation(ctx).schedule().after(durationMs, actionName, toNapiBuffer(args));
1966
2044
  }
1967
2045
  async actorScheduleAt(ctx, timestampMs, actionName, args) {
1968
- return await asNativeActorContext(ctx).schedule().at(timestampMs, actionName, toNapiBuffer(args));
2046
+ return await this.#actorContextForOperation(ctx).schedule().at(timestampMs, actionName, toNapiBuffer(args));
1969
2047
  }
1970
2048
  async actorScheduleCancel(ctx, id) {
1971
- return await asNativeActorContext(ctx).schedule().cancel(id);
2049
+ return await this.#actorContextForOperation(ctx).schedule().cancel(id);
1972
2050
  }
1973
2051
  async actorScheduleGet(ctx, id) {
1974
- return await _asyncNullishCoalesce(await asNativeActorContext(ctx).schedule().get(id), async () => ( void 0));
2052
+ return await _asyncNullishCoalesce(await this.#actorContextForOperation(ctx).schedule().get(id), async () => ( void 0));
1975
2053
  }
1976
2054
  async actorScheduleList(ctx) {
1977
- return await asNativeActorContext(ctx).schedule().list();
2055
+ return await this.#actorContextForOperation(ctx).schedule().list();
1978
2056
  }
1979
2057
  async actorCronSet(ctx, name, expression, timezone, actionName, args, maxHistory) {
1980
- await asNativeActorContext(ctx).schedule().cronSet(
2058
+ await this.#actorContextForOperation(ctx).schedule().cronSet(
1981
2059
  name,
1982
2060
  expression,
1983
2061
  timezone,
@@ -1987,7 +2065,7 @@ var NapiCoreRuntime = (_class = class {
1987
2065
  );
1988
2066
  }
1989
2067
  async actorCronEvery(ctx, name, intervalMs, actionName, args, maxHistory) {
1990
- await asNativeActorContext(ctx).schedule().cronEvery(
2068
+ await this.#actorContextForOperation(ctx).schedule().cronEvery(
1991
2069
  name,
1992
2070
  intervalMs,
1993
2071
  actionName,
@@ -1996,16 +2074,16 @@ var NapiCoreRuntime = (_class = class {
1996
2074
  );
1997
2075
  }
1998
2076
  async actorCronGet(ctx, name) {
1999
- return await _asyncNullishCoalesce(await asNativeActorContext(ctx).schedule().cronGet(name), async () => ( void 0));
2077
+ return await _asyncNullishCoalesce(await this.#actorContextForOperation(ctx).schedule().cronGet(name), async () => ( void 0));
2000
2078
  }
2001
2079
  async actorCronList(ctx) {
2002
- return await asNativeActorContext(ctx).schedule().cronList();
2080
+ return await this.#actorContextForOperation(ctx).schedule().cronList();
2003
2081
  }
2004
2082
  async actorCronDelete(ctx, name) {
2005
- return await asNativeActorContext(ctx).schedule().cronDelete(name);
2083
+ return await this.#actorContextForOperation(ctx).schedule().cronDelete(name);
2006
2084
  }
2007
2085
  async actorCronHistory(ctx, name, limit) {
2008
- return await asNativeActorContext(ctx).schedule().cronHistory(name, limit);
2086
+ return await this.#actorContextForOperation(ctx).schedule().cronHistory(name, limit);
2009
2087
  }
2010
2088
  connId(conn) {
2011
2089
  return asNativeConn(conn).id();
@@ -2039,10 +2117,13 @@ var NapiCoreRuntime = (_class = class {
2039
2117
  }
2040
2118
  }, _class);
2041
2119
  async function loadNapiRuntime() {
2042
- const bindings = await Promise.resolve().then(() => _interopRequireWildcard(require(["@rivetkit", "rivetkit-napi"].join("/"))));
2120
+ const [{ AsyncLocalStorage }, bindings] = await Promise.all([
2121
+ Promise.resolve().then(() => _interopRequireWildcard(require("async_hooks"))),
2122
+ Promise.resolve().then(() => _interopRequireWildcard(require(["@rivetkit", "rivetkit-napi"].join("/"))))
2123
+ ]);
2043
2124
  return {
2044
2125
  bindings,
2045
- runtime: new NapiCoreRuntime(bindings)
2126
+ runtime: new NapiCoreRuntime(bindings, new AsyncLocalStorage())
2046
2127
  };
2047
2128
  }
2048
2129
 
@@ -2057,8 +2138,8 @@ function runtimeBytesToArrayBuffer(value) {
2057
2138
  function buildNativeHttpRequest(init) {
2058
2139
  var _a;
2059
2140
  const headers = new Headers(init.headers);
2060
- const originalUrl = headers.get(_chunkTGGF6SZNcjs.HEADER_ORIGINAL_REQUEST_URL);
2061
- headers.delete(_chunkTGGF6SZNcjs.HEADER_ORIGINAL_REQUEST_URL);
2141
+ const originalUrl = headers.get(_chunkIJUXBWH4cjs.HEADER_ORIGINAL_REQUEST_URL);
2142
+ headers.delete(_chunkIJUXBWH4cjs.HEADER_ORIGINAL_REQUEST_URL);
2062
2143
  const url = _nullishCoalesce(originalUrl, () => ( (init.uri.startsWith("http") ? init.uri : new URL(init.uri, "http://127.0.0.1").toString())));
2063
2144
  const method2 = init.method.toUpperCase();
2064
2145
  const bodyForbidden = method2 === "GET" || method2 === "HEAD";
@@ -2137,7 +2218,7 @@ async function pumpResponseBody(reader, stream) {
2137
2218
  }
2138
2219
  } catch (error) {
2139
2220
  try {
2140
- await stream.error(_chunk7E2W2YSMcjs.stringifyError.call(void 0, error));
2221
+ await stream.error(_chunkRJC5O2SDcjs.stringifyError.call(void 0, error));
2141
2222
  } catch (streamError) {
2142
2223
  logger2().debug({
2143
2224
  msg: "failed to report native http response stream error",
@@ -2267,7 +2348,7 @@ function validateQueueComplete(schemas, name, response) {
2267
2348
  return result.data;
2268
2349
  }
2269
2350
  function validationError(target, issues) {
2270
- return new (0, _chunk2JSYYH6Pcjs.RivetError)("actor", "validation_error", `Invalid ${target}`, {
2351
+ return new (0, _chunkJX2ITWAVcjs.RivetError)("actor", "validation_error", `Invalid ${target}`, {
2271
2352
  public: true,
2272
2353
  metadata: { issues }
2273
2354
  });
@@ -2275,7 +2356,7 @@ function validationError(target, issues) {
2275
2356
 
2276
2357
  // src/registry/run-handler-coordinator.ts
2277
2358
  function runUnavailable(actorId, reason) {
2278
- return new (0, _chunk2JSYYH6Pcjs.RivetError)(
2359
+ return new (0, _chunkJX2ITWAVcjs.RivetError)(
2279
2360
  "actor",
2280
2361
  "run_handler_unavailable",
2281
2362
  `Run handler control is unavailable for actor ${actorId}: ${reason}.`,
@@ -2305,7 +2386,7 @@ var RunHandlerCoordinator = class {
2305
2386
  this.#run = run;
2306
2387
  }
2307
2388
  get inspectorKind() {
2308
- return _chunk4KGXFC6Mcjs.getRunInspectorKind.call(void 0, this.#run);
2389
+ return _chunkEO5UOXXYcjs.getRunInspectorKind.call(void 0, this.#run);
2309
2390
  }
2310
2391
  async run(actorId, restart, callback) {
2311
2392
  const state = this.#getOrCreate(actorId);
@@ -2413,7 +2494,7 @@ var RunHandlerCoordinator = class {
2413
2494
  }
2414
2495
  #initializeInspector(actorId, state) {
2415
2496
  if (state.inspectorInitialized) return;
2416
- const inspector = _chunk4KGXFC6Mcjs.createRunInspector.call(void 0, this.#run, {
2497
+ const inspector = _chunkEO5UOXXYcjs.createRunInspector.call(void 0, this.#run, {
2417
2498
  actorId,
2418
2499
  control: this.#control(actorId, state)
2419
2500
  });
@@ -2496,16 +2577,16 @@ function normalizeQueueMessage(message) {
2496
2577
  }
2497
2578
  function normalizeWasmBridgeError(error) {
2498
2579
  if (typeof error === "string") {
2499
- return _nullishCoalesce(_chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2580
+ return _nullishCoalesce(_chunkJX2ITWAVcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
2500
2581
  }
2501
2582
  if (error instanceof Error) {
2502
- const bridged = _chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error.message);
2583
+ const bridged = _chunkJX2ITWAVcjs.decodeBridgeRivetError.call(void 0, error.message);
2503
2584
  if (bridged) {
2504
2585
  return bridged;
2505
2586
  }
2506
2587
  }
2507
2588
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
2508
- const bridged = _chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error.reason);
2589
+ const bridged = _chunkJX2ITWAVcjs.decodeBridgeRivetError.call(void 0, error.reason);
2509
2590
  if (bridged) {
2510
2591
  return bridged;
2511
2592
  }
@@ -2527,7 +2608,7 @@ function callWasmSync(invoke) {
2527
2608
  }
2528
2609
  }
2529
2610
  function unsupportedWasmMethod(method2) {
2530
- throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
2611
+ throw new (0, _chunkJX2ITWAVcjs.RivetError)(
2531
2612
  "runtime",
2532
2613
  "unsupported",
2533
2614
  `Unsupported wasm runtime method: ${method2}`,
@@ -2742,6 +2823,29 @@ var WasmCoreRuntime = (_class2 = class {
2742
2823
  actorId(ctx) {
2743
2824
  return callHandle(asWasmActorContext(ctx), "actorId");
2744
2825
  }
2826
+ runWithActorInvocationContext(_ctx, run) {
2827
+ return run();
2828
+ }
2829
+ actorInvocationTraceContext(_ctx) {
2830
+ return void 0;
2831
+ }
2832
+ startCallSpan(_ctx, _actorName, _actionName) {
2833
+ return void 0;
2834
+ }
2835
+ async startWorkflowSpan(_ctx) {
2836
+ return {
2837
+ run: (body) => body(),
2838
+ startStep: () => void 0,
2839
+ finish: async () => {
2840
+ }
2841
+ };
2842
+ }
2843
+ runOutsideActorInvocationContext(run) {
2844
+ return run();
2845
+ }
2846
+ currentInvocationScope() {
2847
+ return void 0;
2848
+ }
2745
2849
  actorName(ctx) {
2746
2850
  return callHandle(asWasmActorContext(ctx), "name");
2747
2851
  }
@@ -2962,7 +3066,7 @@ var WasmCoreRuntime = (_class2 = class {
2962
3066
  await callWasm(() => database.close());
2963
3067
  }
2964
3068
  async actorRuntimeSocketProvision(_ctx) {
2965
- throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
3069
+ throw new (0, _chunkJX2ITWAVcjs.RivetError)(
2966
3070
  "actor_runtime_socket",
2967
3071
  "unsupported",
2968
3072
  "Actor Runtime Socket is only available on Unix native runtimes.",
@@ -3331,7 +3435,7 @@ function loadedRuntimeKind(runtime) {
3331
3435
  case "wasm":
3332
3436
  return "wasm";
3333
3437
  }
3334
- throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
3438
+ throw new (0, _chunkJX2ITWAVcjs.RivetError)(
3335
3439
  "config",
3336
3440
  "unknown_runtime",
3337
3441
  "RivetKit runtime must be NAPI or wasm.",
@@ -3352,16 +3456,16 @@ async function loadAutoRuntime(config, loaders = defaultRuntimeLoaders) {
3352
3456
  nativeError = error;
3353
3457
  logger2().warn({
3354
3458
  msg: "native runtime failed to load; falling back to wasm",
3355
- error: _chunk7E2W2YSMcjs.stringifyError.call(void 0, error)
3459
+ error: _chunkRJC5O2SDcjs.stringifyError.call(void 0, error)
3356
3460
  });
3357
3461
  }
3358
3462
  try {
3359
3463
  return (await loaders.loadWasm(config.wasm)).runtime;
3360
3464
  } catch (wasmError) {
3361
- throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
3465
+ throw new (0, _chunkJX2ITWAVcjs.RivetError)(
3362
3466
  "config",
3363
3467
  "runtime_unavailable",
3364
- `RivetKit could not load a core runtime. Native runtime: ${_chunk7E2W2YSMcjs.stringifyError.call(void 0, nativeError)} Wasm runtime: ${_chunk7E2W2YSMcjs.stringifyError.call(void 0, wasmError)}`,
3468
+ `RivetKit could not load a core runtime. Native runtime: ${_chunkRJC5O2SDcjs.stringifyError.call(void 0, nativeError)} Wasm runtime: ${_chunkRJC5O2SDcjs.stringifyError.call(void 0, wasmError)}`,
3365
3469
  {
3366
3470
  public: true,
3367
3471
  statusCode: 500
@@ -3389,7 +3493,7 @@ function normalizeRuntimeConfigForKind(config, runtimeKind) {
3389
3493
  return config;
3390
3494
  }
3391
3495
  if (sqliteBackendForConfig(config) === "local") {
3392
- throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
3496
+ throw new (0, _chunkJX2ITWAVcjs.RivetError)(
3393
3497
  "config",
3394
3498
  "wasm_local_sqlite",
3395
3499
  "WebAssembly runtime cannot use local SQLite. Use remote SQLite instead.",
@@ -3455,14 +3559,14 @@ function getNativeConnPersistState(runtime, ctx, conn) {
3455
3559
  return connState;
3456
3560
  }
3457
3561
  function stateMutationReentrantError() {
3458
- return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3562
+ return new (0, _chunkJX2ITWAVcjs.RivetError)(
3459
3563
  "actor",
3460
3564
  "state_mutation_reentrant",
3461
3565
  "State mutations are not allowed inside onStateChange."
3462
3566
  );
3463
3567
  }
3464
3568
  function stateTransactionConflictError() {
3465
- return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3569
+ return new (0, _chunkJX2ITWAVcjs.RivetError)(
3466
3570
  "actor",
3467
3571
  "state_transaction_conflict",
3468
3572
  "State cannot be mutated by another action while an experimental state-aware database transaction is active.",
@@ -3470,7 +3574,7 @@ function stateTransactionConflictError() {
3470
3574
  );
3471
3575
  }
3472
3576
  function databaseNotConfiguredError() {
3473
- return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3577
+ return new (0, _chunkJX2ITWAVcjs.RivetError)(
3474
3578
  "actor",
3475
3579
  "database_not_configured",
3476
3580
  "database is not configured for this actor",
@@ -3478,7 +3582,7 @@ function databaseNotConfiguredError() {
3478
3582
  );
3479
3583
  }
3480
3584
  function databaseClientNotReadyError() {
3481
- return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3585
+ return new (0, _chunkJX2ITWAVcjs.RivetError)(
3482
3586
  "actor",
3483
3587
  "database_client_not_ready",
3484
3588
  "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.",
@@ -3486,7 +3590,7 @@ function databaseClientNotReadyError() {
3486
3590
  );
3487
3591
  }
3488
3592
  function runHandlerNotConfiguredError() {
3489
- return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3593
+ return new (0, _chunkJX2ITWAVcjs.RivetError)(
3490
3594
  "actor",
3491
3595
  "run_handler_unavailable",
3492
3596
  "Cannot schedule a run wake because this actor does not define a run handler.",
@@ -3494,7 +3598,7 @@ function runHandlerNotConfiguredError() {
3494
3598
  );
3495
3599
  }
3496
3600
  function stateNotEnabledError() {
3497
- return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3601
+ return new (0, _chunkJX2ITWAVcjs.RivetError)(
3498
3602
  "actor",
3499
3603
  "state_not_enabled",
3500
3604
  "State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.dev/docs/actors/state/#initializing-state)",
@@ -3502,7 +3606,7 @@ function stateNotEnabledError() {
3502
3606
  );
3503
3607
  }
3504
3608
  function nativeClientNotConfiguredError() {
3505
- return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3609
+ return new (0, _chunkJX2ITWAVcjs.RivetError)(
3506
3610
  "native",
3507
3611
  "client_not_configured",
3508
3612
  "native actor client is not configured",
@@ -3510,7 +3614,7 @@ function nativeClientNotConfiguredError() {
3510
3614
  );
3511
3615
  }
3512
3616
  function nativeEndpointNotConfiguredError() {
3513
- return new (0, _chunk2JSYYH6Pcjs.RivetError)(
3617
+ return new (0, _chunkJX2ITWAVcjs.RivetError)(
3514
3618
  "native",
3515
3619
  "endpoint_not_configured",
3516
3620
  "registry endpoint is required for native envoy startup",
@@ -3555,7 +3659,7 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
3555
3659
  }).catch((error) => {
3556
3660
  logger2().warn({
3557
3661
  msg: "deferred native sleep cleanup failed",
3558
- error: _chunk7E2W2YSMcjs.stringifyError.call(void 0, error)
3662
+ error: _chunkRJC5O2SDcjs.stringifyError.call(void 0, error)
3559
3663
  });
3560
3664
  });
3561
3665
  return;
@@ -3718,10 +3822,10 @@ function decodeValue(value) {
3718
3822
  if (!value || value.length === 0) {
3719
3823
  return void 0;
3720
3824
  }
3721
- return _chunk7E2W2YSMcjs.decodeCborCompat.call(void 0, value);
3825
+ return _chunkRJC5O2SDcjs.decodeCborCompat.call(void 0, value);
3722
3826
  }
3723
3827
  function encodeValue(value) {
3724
- return _chunk7E2W2YSMcjs.encodeCborCompat.call(void 0, value);
3828
+ return _chunkRJC5O2SDcjs.encodeCborCompat.call(void 0, value);
3725
3829
  }
3726
3830
  function normalizeArgs(value) {
3727
3831
  return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
@@ -3734,16 +3838,16 @@ function unwrapTsfnPayload(error, payload) {
3734
3838
  }
3735
3839
  function normalizeNativeBridgeError(error) {
3736
3840
  if (typeof error === "string") {
3737
- return _nullishCoalesce(_chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
3841
+ return _nullishCoalesce(_chunkJX2ITWAVcjs.decodeBridgeRivetError.call(void 0, error), () => ( error));
3738
3842
  }
3739
3843
  if (error instanceof Error) {
3740
- const bridged = _chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error.message);
3844
+ const bridged = _chunkJX2ITWAVcjs.decodeBridgeRivetError.call(void 0, error.message);
3741
3845
  if (bridged) {
3742
3846
  return bridged;
3743
3847
  }
3744
3848
  }
3745
3849
  if (typeof error === "object" && error !== null && "reason" in error && typeof error.reason === "string") {
3746
- const bridged = _chunk2JSYYH6Pcjs.decodeBridgeRivetError.call(void 0, error.reason);
3850
+ const bridged = _chunkJX2ITWAVcjs.decodeBridgeRivetError.call(void 0, error.reason);
3747
3851
  if (bridged) {
3748
3852
  return bridged;
3749
3853
  }
@@ -3751,14 +3855,14 @@ function normalizeNativeBridgeError(error) {
3751
3855
  return error;
3752
3856
  }
3753
3857
  function isStructuredBridgeError(error) {
3754
- if (error instanceof _chunk2JSYYH6Pcjs.RivetError) {
3858
+ if (error instanceof _chunkJX2ITWAVcjs.RivetError) {
3755
3859
  return true;
3756
3860
  }
3757
- return _chunk2JSYYH6Pcjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
3861
+ return _chunkJX2ITWAVcjs.isRivetErrorLike.call(void 0, error) && "__type" in error && (error.__type === "RivetError" || error.__type === "ActorError");
3758
3862
  }
3759
3863
  function encodeNativeCallbackError(error) {
3760
- const structuredError = isStructuredBridgeError(error) ? error : _chunk7E2W2YSMcjs.deconstructError.call(void 0, error, true);
3761
- const bridgeError = new Error(_chunk2JSYYH6Pcjs.encodeBridgeRivetError.call(void 0, structuredError), {
3864
+ const structuredError = isStructuredBridgeError(error) ? error : _chunkRJC5O2SDcjs.deconstructError.call(void 0, error, true);
3865
+ const bridgeError = new Error(_chunkJX2ITWAVcjs.encodeBridgeRivetError.call(void 0, structuredError), {
3762
3866
  cause: error instanceof Error ? error : void 0
3763
3867
  });
3764
3868
  return Object.assign(bridgeError, {
@@ -3783,9 +3887,9 @@ function callNativeSync(invoke) {
3783
3887
  }
3784
3888
  }
3785
3889
  function isClosedTaskRegistrationError(error) {
3786
- const metadata = error instanceof _chunk2JSYYH6Pcjs.RivetError ? error.metadata : void 0;
3890
+ const metadata = error instanceof _chunkJX2ITWAVcjs.RivetError ? error.metadata : void 0;
3787
3891
  const metadataError = metadata && typeof metadata === "object" && "error" in metadata ? metadata.error : void 0;
3788
- 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);
3892
+ return error instanceof _chunkJX2ITWAVcjs.RivetError && error.group === "core" && error.code === _chunkJX2ITWAVcjs.INTERNAL_ERROR_CODE && typeof metadataError === "string" && /actor task registration is (closed|not configured)/.test(metadataError);
3789
3893
  }
3790
3894
  async function createCancellationTokenHandle(runtime, signal) {
3791
3895
  if (!signal) {
@@ -3808,7 +3912,7 @@ function decodeWorkflowCbor(data) {
3808
3912
  return null;
3809
3913
  }
3810
3914
  try {
3811
- return _chunk7E2W2YSMcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
3915
+ return _chunkRJC5O2SDcjs.decodeCborCompat.call(void 0, new Uint8Array(data));
3812
3916
  } catch (e4) {
3813
3917
  return null;
3814
3918
  }
@@ -3921,7 +4025,7 @@ function serializeWorkflowHistoryForJson(data) {
3921
4025
  if (data === null) {
3922
4026
  return null;
3923
4027
  }
3924
- const history = _chunkF3IP3SGOcjs.decodeWorkflowHistoryTransport.call(void 0, data);
4028
+ const history = _chunkPPEIPCW4cjs.decodeWorkflowHistoryTransport.call(void 0, data);
3925
4029
  return jsonSafe({
3926
4030
  nameRegistry: [...history.nameRegistry],
3927
4031
  entries: history.entries.map((entry) => ({
@@ -4020,7 +4124,7 @@ var NativeConnAdapter = class {
4020
4124
  this.#ctx = ctx;
4021
4125
  this.#queueHibernationRemoval = queueHibernationRemoval;
4022
4126
  this.#assertCanMutateState = assertCanMutateState;
4023
- this[_chunk4KGXFC6Mcjs.CONN_STATE_MANAGER_SYMBOL] = {
4127
+ this[_chunkEO5UOXXYcjs.CONN_STATE_MANAGER_SYMBOL] = {
4024
4128
  stateEnabled: true,
4025
4129
  get state() {
4026
4130
  return thisConn.state;
@@ -4037,7 +4141,7 @@ var NativeConnAdapter = class {
4037
4141
  decodeValue(this.#runtime.connParams(this.#conn))
4038
4142
  );
4039
4143
  }
4040
- [_chunk4KGXFC6Mcjs.RAW_STATE_SYMBOL]() {
4144
+ [_chunkEO5UOXXYcjs.RAW_STATE_SYMBOL]() {
4041
4145
  return this.#readState();
4042
4146
  }
4043
4147
  get state() {
@@ -4067,7 +4171,7 @@ var NativeConnAdapter = class {
4067
4171
  },
4068
4172
  (newValue) => {
4069
4173
  assertCurrentState();
4070
- _chunk7E2W2YSMcjs.assertJsonCompatValue.call(void 0, newValue);
4174
+ _chunkRJC5O2SDcjs.assertJsonCompatValue.call(void 0, newValue);
4071
4175
  }
4072
4176
  );
4073
4177
  }
@@ -4075,7 +4179,7 @@ var NativeConnAdapter = class {
4075
4179
  var _a;
4076
4180
  (_a = this.#assertCanMutateState) == null ? void 0 : _a.call(this);
4077
4181
  const nextValue = unwrapWriteThroughProxy(value);
4078
- _chunk7E2W2YSMcjs.assertJsonCompatValue.call(void 0, nextValue);
4182
+ _chunkRJC5O2SDcjs.assertJsonCompatValue.call(void 0, nextValue);
4079
4183
  this.#writeState(nextValue, { writeNative: true });
4080
4184
  }
4081
4185
  initializeState(value) {
@@ -4458,7 +4562,7 @@ var NativeQueueAdapter = class {
4458
4562
  async nextBatch(options) {
4459
4563
  const completable = (options == null ? void 0 : options.completable) === true;
4460
4564
  if (this.#pendingCompletableMessageIds.size > 0) {
4461
- throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
4565
+ throw new (0, _chunkJX2ITWAVcjs.RivetError)(
4462
4566
  "queue",
4463
4567
  "previous_message_not_completed",
4464
4568
  "Previous completable queue message is not completed. Call `message.complete(...)` before receiving the next message.",
@@ -4625,7 +4729,7 @@ var NativeQueueAdapter = class {
4625
4729
  }
4626
4730
  yield message;
4627
4731
  } catch (error) {
4628
- if (_chunk2JSYYH6Pcjs.isActorAbortedError.call(void 0, error)) {
4732
+ if (_chunkJX2ITWAVcjs.isActorAbortedError.call(void 0, error)) {
4629
4733
  return;
4630
4734
  }
4631
4735
  throw error;
@@ -4646,7 +4750,7 @@ var NativeQueueAdapter = class {
4646
4750
  ...message,
4647
4751
  complete: async (response) => {
4648
4752
  if (typeof message.complete !== "function") {
4649
- throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
4753
+ throw new (0, _chunkJX2ITWAVcjs.RivetError)(
4650
4754
  "queue",
4651
4755
  "complete_not_configured",
4652
4756
  `Queue '${message.name}' does not support completion responses.`,
@@ -4658,7 +4762,7 @@ var NativeQueueAdapter = class {
4658
4762
  );
4659
4763
  }
4660
4764
  if (completed) {
4661
- throw new (0, _chunk2JSYYH6Pcjs.RivetError)(
4765
+ throw new (0, _chunkJX2ITWAVcjs.RivetError)(
4662
4766
  "queue",
4663
4767
  "already_completed",
4664
4768
  "Queue message was already completed.",
@@ -5055,6 +5159,7 @@ var NativeConnectionMap = (_class3 = class {
5055
5159
  }
5056
5160
  __init3() {this[Symbol.toStringTag] = "NativeConnectionMap"}
5057
5161
  }, _class3);
5162
+ var NO_INVOCATION_SCOPE = {};
5058
5163
  var ActorContextHandleAdapter = class {
5059
5164
  #runtime;
5060
5165
  #ctx;
@@ -5069,6 +5174,7 @@ var ActorContextHandleAdapter = class {
5069
5174
  #db;
5070
5175
  #dispatchCancelToken;
5071
5176
  #kv;
5177
+ #logByInvocationScope = /* @__PURE__ */ new WeakMap();
5072
5178
  #queue;
5073
5179
  #request;
5074
5180
  #schedule;
@@ -5092,7 +5198,7 @@ var ActorContextHandleAdapter = class {
5092
5198
  this.#databaseProvider = databaseProvider;
5093
5199
  }
5094
5200
  this.#request = request;
5095
- this[_chunk4KGXFC6Mcjs.ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
5201
+ this[_chunkEO5UOXXYcjs.ACTOR_CONTEXT_INTERNAL_SYMBOL] = new NativeWorkflowRuntimeAdapter(
5096
5202
  this
5097
5203
  );
5098
5204
  }
@@ -5122,7 +5228,7 @@ var ActorContextHandleAdapter = class {
5122
5228
  }
5123
5229
  throw databaseClientNotReadyError();
5124
5230
  }
5125
- [_chunk4KGXFC6Mcjs.RAW_STATE_SYMBOL]() {
5231
+ [_chunkEO5UOXXYcjs.RAW_STATE_SYMBOL]() {
5126
5232
  if (!this.#stateEnabled) {
5127
5233
  throw stateNotEnabledError();
5128
5234
  }
@@ -5149,7 +5255,7 @@ var ActorContextHandleAdapter = class {
5149
5255
  },
5150
5256
  (newValue) => {
5151
5257
  assertCurrentState();
5152
- _chunk7E2W2YSMcjs.assertJsonCompatValue.call(void 0, newValue);
5258
+ _chunkRJC5O2SDcjs.assertJsonCompatValue.call(void 0, newValue);
5153
5259
  }
5154
5260
  );
5155
5261
  }
@@ -5161,7 +5267,7 @@ var ActorContextHandleAdapter = class {
5161
5267
  }
5162
5268
  this.#assertCanMutateState();
5163
5269
  const nextValue = unwrapWriteThroughProxy(value);
5164
- _chunk7E2W2YSMcjs.assertJsonCompatValue.call(void 0, nextValue);
5270
+ _chunkRJC5O2SDcjs.assertJsonCompatValue.call(void 0, nextValue);
5165
5271
  this.#writeState(nextValue, { scheduleSave: true });
5166
5272
  }
5167
5273
  initializeState(value) {
@@ -5211,7 +5317,11 @@ var ActorContextHandleAdapter = class {
5211
5317
  await callNative(
5212
5318
  () => this.#runtime.actorSetRunWakeAt(this.#ctx, timestamp)
5213
5319
  );
5214
- }
5320
+ },
5321
+ startWorkflowSpan: () => callNative(
5322
+ () => this.#runtime.startWorkflowSpan(this.#ctx)
5323
+ ),
5324
+ runOutsideWorkflowSpan: (body) => this.#runtime.runOutsideActorInvocationContext(body)
5215
5325
  };
5216
5326
  }
5217
5327
  return this.#run;
@@ -5256,8 +5366,29 @@ var ActorContextHandleAdapter = class {
5256
5366
  }
5257
5367
  return this.#connMap;
5258
5368
  }
5369
+ #invocationTraceContext() {
5370
+ return callNativeSync(
5371
+ () => this.#runtime.actorInvocationTraceContext(this.#ctx)
5372
+ );
5373
+ }
5374
+ /** Cached per invocation, because the `run` context outlives workflow runs and steps. */
5259
5375
  get log() {
5260
- return logger2();
5376
+ const scope = _nullishCoalesce(this.#runtime.currentInvocationScope(), () => ( NO_INVOCATION_SCOPE));
5377
+ const cached = this.#logByInvocationScope.get(scope);
5378
+ if (cached) return cached;
5379
+ const invocation = this.#invocationTraceContext();
5380
+ const log = logger2().child({
5381
+ actorId: this.actorId,
5382
+ actorName: this.name,
5383
+ actorKey: this.key,
5384
+ ...(invocation == null ? void 0 : invocation.rayId) && { rayId: invocation.rayId },
5385
+ ...(invocation == null ? void 0 : invocation.span) && {
5386
+ traceId: invocation.span.traceId,
5387
+ spanId: invocation.span.spanId
5388
+ }
5389
+ });
5390
+ this.#logByInvocationScope.set(scope, log);
5391
+ return log;
5261
5392
  }
5262
5393
  get abortSignal() {
5263
5394
  if (!this.#abortSignal) {
@@ -5345,7 +5476,7 @@ var ActorContextHandleAdapter = class {
5345
5476
  log: {
5346
5477
  debug: (obj) => logger2().debug(obj)
5347
5478
  },
5348
- nativeDatabaseProvider: _chunk4OMHYVOQcjs.registerNativeStateTransactionOpener.call(void 0,
5479
+ nativeDatabaseProvider: _chunkZ4RAXFSDcjs.registerNativeStateTransactionOpener.call(void 0,
5349
5480
  {
5350
5481
  open: async (requestedActorId) => {
5351
5482
  void requestedActorId;
@@ -5368,7 +5499,7 @@ var ActorContextHandleAdapter = class {
5368
5499
  return this.#db;
5369
5500
  }
5370
5501
  #bindDatabaseClient(client) {
5371
- return _chunk4OMHYVOQcjs.bindNativeStateTransactionContext.call(void 0, client, {
5502
+ return _chunkZ4RAXFSDcjs.bindNativeStateTransactionContext.call(void 0, client, {
5372
5503
  enter: async () => await this.#enterStateTransaction(),
5373
5504
  exit: (scope) => this.#exitStateTransaction(
5374
5505
  scope
@@ -5572,7 +5703,7 @@ var ActorContextHandleAdapter = class {
5572
5703
  const trackedPromise = Promise.resolve(promise).catch((error) => {
5573
5704
  logger2().warn({
5574
5705
  msg: "keepAwake promise rejected",
5575
- error: _chunk7E2W2YSMcjs.stringifyError.call(void 0, error)
5706
+ error: _chunkRJC5O2SDcjs.stringifyError.call(void 0, error)
5576
5707
  });
5577
5708
  }).then(() => null);
5578
5709
  try {
@@ -5958,7 +6089,7 @@ function buildActorConfig(definition, registryConfig, runtimeKind) {
5958
6089
  maxOutgoingMessageSize: registryConfig.maxOutgoingMessageSize,
5959
6090
  preloadMaxWorkflowBytes: options.preloadMaxWorkflowBytes,
5960
6091
  preloadMaxConnectionsBytes: options.preloadMaxConnectionsBytes,
5961
- actions: Object.keys(_chunk4KGXFC6Mcjs.flattenActionHandlers.call(void 0, config.actions)).sort().map((name) => ({ name })),
6092
+ actions: Object.keys(_chunkEO5UOXXYcjs.flattenActionHandlers.call(void 0, config.actions)).sort().map((name) => ({ name })),
5962
6093
  inspectorTabs: buildInspectorTabs(config.inspector, runtimeKind)
5963
6094
  };
5964
6095
  }
@@ -6034,10 +6165,10 @@ function validateInspectorTabSource(tabId, resolved) {
6034
6165
  function buildNativeFactory(runtime, registryConfig, definition) {
6035
6166
  var _a;
6036
6167
  const config = definition.config;
6037
- const databaseProvider = _nullishCoalesce(config.db, () => ( _chunk4OMHYVOQcjs.db.call(void 0, )));
6038
- const actionHandlers = _chunk4KGXFC6Mcjs.flattenActionHandlers.call(void 0, config.actions);
6168
+ const databaseProvider = _nullishCoalesce(config.db, () => ( _chunkZ4RAXFSDcjs.db.call(void 0, )));
6169
+ const actionHandlers = _chunkEO5UOXXYcjs.flattenActionHandlers.call(void 0, config.actions);
6039
6170
  const schemaConfig = {
6040
- actionInputSchemas: _chunk4KGXFC6Mcjs.flattenActionInputSchemas.call(void 0,
6171
+ actionInputSchemas: _chunkEO5UOXXYcjs.flattenActionInputSchemas.call(void 0,
6041
6172
  config.actions,
6042
6173
  config.actionInputSchemas
6043
6174
  ),
@@ -6045,19 +6176,27 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6045
6176
  events: config.events,
6046
6177
  queues: config.queues
6047
6178
  };
6048
- const createClient = () => _chunkTGGF6SZNcjs.createClientWithDriver.call(void 0,
6049
- new (0, _chunkTGGF6SZNcjs.RemoteEngineControlClient)(
6050
- _chunkTGGF6SZNcjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
6179
+ const createClient = (ctx) => _chunkIJUXBWH4cjs.createClientWithDriver.call(void 0,
6180
+ new (0, _chunkIJUXBWH4cjs.RemoteEngineControlClient)(
6181
+ _chunkIJUXBWH4cjs.convertRegistryConfigToClientConfig.call(void 0, registryConfig)
6051
6182
  ),
6052
- { encoding: "bare" }
6183
+ {
6184
+ encoding: "bare",
6185
+ currentActorInvocation: () => callNativeSync(
6186
+ () => runtime.actorInvocationTraceContext(ctx)
6187
+ ),
6188
+ startCallSpan: (actorName, actionName) => callNativeSync(
6189
+ () => runtime.startCallSpan(ctx, actorName, actionName)
6190
+ )
6191
+ }
6053
6192
  );
6054
- const run = _chunk4KGXFC6Mcjs.getRunFunction.call(void 0, config.run);
6055
- const runHandlerCoordinator = _chunk4KGXFC6Mcjs.getRunInspectorKind.call(void 0, config.run) === "workflow" ? new RunHandlerCoordinator(config.run) : void 0;
6193
+ const run = _chunkEO5UOXXYcjs.getRunFunction.call(void 0, config.run);
6194
+ const runHandlerCoordinator = _chunkEO5UOXXYcjs.getRunInspectorKind.call(void 0, config.run) === "workflow" ? new RunHandlerCoordinator(config.run) : void 0;
6056
6195
  const getNativeWorkflowInspector = (ctx) => {
6057
6196
  var _a2, _b;
6058
6197
  const actorId = callNativeSync(() => runtime.actorId(ctx));
6059
6198
  const restart = () => callNativeSync(() => runtime.actorRestartRunHandler(ctx));
6060
- return _nullishCoalesce(((_a2 = runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.getInspector(actorId, restart)) == null ? void 0 : _a2.workflow), () => ( ((_b = _chunk4KGXFC6Mcjs.getRunInspectorConfig.call(void 0, config.run, actorId)) == null ? void 0 : _b.workflow)));
6199
+ return _nullishCoalesce(((_a2 = runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.getInspector(actorId, restart)) == null ? void 0 : _a2.workflow), () => ( ((_b = _chunkEO5UOXXYcjs.getRunInspectorConfig.call(void 0, config.run, actorId)) == null ? void 0 : _b.workflow)));
6061
6200
  };
6062
6201
  const onStateChange = typeof config.onStateChange === "function" ? (actorCtx, nextState) => {
6063
6202
  config.onStateChange(actorCtx, nextState);
@@ -6072,7 +6211,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6072
6211
  const makeActorCtx = (ctx, request, cancelToken) => new ActorContextHandleAdapter(
6073
6212
  runtime,
6074
6213
  ctx,
6075
- createClient,
6214
+ () => createClient(ctx),
6076
6215
  schemaConfig,
6077
6216
  databaseProvider,
6078
6217
  request,
@@ -6085,7 +6224,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6085
6224
  runtime,
6086
6225
  ctx,
6087
6226
  conn,
6088
- createClient,
6227
+ () => createClient(ctx),
6089
6228
  schemaConfig,
6090
6229
  databaseProvider,
6091
6230
  request,
@@ -6110,7 +6249,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6110
6249
  }
6111
6250
  });
6112
6251
  const errorResponse = (error, status) => {
6113
- const rivetError = _chunk2JSYYH6Pcjs.toRivetError.call(void 0, error);
6252
+ const rivetError = _chunkJX2ITWAVcjs.toRivetError.call(void 0, error);
6114
6253
  return jsonResponse(
6115
6254
  {
6116
6255
  group: rivetError.group,
@@ -6210,7 +6349,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6210
6349
  body = await jsRequest.json();
6211
6350
  } catch (e5) {
6212
6351
  return errorResponse(
6213
- new (0, _chunk2JSYYH6Pcjs.RivetError)(
6352
+ new (0, _chunkJX2ITWAVcjs.RivetError)(
6214
6353
  "actor",
6215
6354
  "invalid_request",
6216
6355
  "Invalid inspector JSON body",
@@ -6222,7 +6361,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6222
6361
  const name = _nullishCoalesce(body.name, () => ( ""));
6223
6362
  if (name === "") {
6224
6363
  return errorResponse(
6225
- new (0, _chunk2JSYYH6Pcjs.RivetError)(
6364
+ new (0, _chunkJX2ITWAVcjs.RivetError)(
6226
6365
  "actor",
6227
6366
  "invalid_request",
6228
6367
  "Queue message name must not be empty",
@@ -6231,7 +6370,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6231
6370
  400
6232
6371
  );
6233
6372
  }
6234
- const cbor = _chunk7E2W2YSMcjs.encodeCborCompat.call(void 0,
6373
+ const cbor = _chunkRJC5O2SDcjs.encodeCborCompat.call(void 0,
6235
6374
  _nullishCoalesce(body.body, () => ( null))
6236
6375
  );
6237
6376
  const message = await runtime.actorQueueSend(ctx, name, cbor);
@@ -6396,7 +6535,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6396
6535
  const action = actionHandlers[actionName];
6397
6536
  if (!action) {
6398
6537
  return errorResponse(
6399
- new (0, _chunk2JSYYH6Pcjs.RivetError)(
6538
+ new (0, _chunkJX2ITWAVcjs.RivetError)(
6400
6539
  "action",
6401
6540
  "action_not_found",
6402
6541
  `Action ${actionName} not found`
@@ -6599,7 +6738,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6599
6738
  );
6600
6739
  } finally {
6601
6740
  runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(actorId);
6602
- _chunk4KGXFC6Mcjs.disposeRunInspector.call(void 0, config.run, actorId);
6741
+ _chunkEO5UOXXYcjs.disposeRunInspector.call(void 0, config.run, actorId);
6603
6742
  await actorCtx.dispose();
6604
6743
  }
6605
6744
  }
@@ -6611,7 +6750,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6611
6750
  const actorCtx = makeActorCtx(ctx);
6612
6751
  const actorId = callNativeSync(() => runtime.actorId(ctx));
6613
6752
  runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(actorId);
6614
- _chunk4KGXFC6Mcjs.disposeRunInspector.call(void 0, config.run, actorId);
6753
+ _chunkEO5UOXXYcjs.disposeRunInspector.call(void 0, config.run, actorId);
6615
6754
  try {
6616
6755
  if (typeof config.onDestroy === "function") {
6617
6756
  await config.onDestroy(actorCtx);
@@ -6769,7 +6908,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6769
6908
  );
6770
6909
  }
6771
6910
  if (!result) {
6772
- throw _chunk2JSYYH6Pcjs.forbiddenError.call(void 0, );
6911
+ throw _chunkJX2ITWAVcjs.forbiddenError.call(void 0, );
6773
6912
  }
6774
6913
  } finally {
6775
6914
  await actorCtx.dispose();
@@ -6798,111 +6937,125 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6798
6937
  async (error, payload) => {
6799
6938
  try {
6800
6939
  const { ctx, request, cancelToken, responseBodyStream } = unwrapTsfnPayload(error, payload);
6801
- const inspectorResponse = await maybeHandleNativeInspectorRequest(ctx, request);
6802
- if (inspectorResponse) {
6803
- await cancelNativeHttpRequestBody(request.bodyStream);
6804
- return (await convertNativeHttpResponse(
6805
- inspectorResponse,
6806
- responseBodyStream
6807
- )).response;
6808
- }
6809
- if (typeof config.onRequest !== "function") {
6810
- await cancelNativeHttpRequestBody(request.bodyStream);
6811
- return (await convertNativeHttpResponse(
6812
- new Response(null, { status: 404 }),
6813
- responseBodyStream
6814
- )).response;
6815
- }
6816
- const requestAbortController = new AbortController();
6817
- const handlerRequest = buildNativeHttpRequest({
6818
- ...request,
6819
- abortController: requestAbortController
6820
- });
6821
- const rawConnParams = handlerRequest.headers.get(_chunkTGGF6SZNcjs.HEADER_CONN_PARAMS);
6822
- let requestCtx;
6823
- let conn;
6824
- let removeRequestAbortListener;
6825
- let cleanupDeferredToBody = false;
6826
- let cleanedUp = false;
6827
- const cleanupRequest = async () => {
6828
- if (cleanedUp) return;
6829
- cleanedUp = true;
6830
- removeRequestAbortListener == null ? void 0 : removeRequestAbortListener();
6831
- try {
6832
- await (requestCtx == null ? void 0 : requestCtx.dispose());
6833
- } finally {
6834
- if (conn) {
6835
- await runtime.connDisconnect(conn);
6836
- }
6837
- }
6838
- };
6839
- try {
6840
- const connParams = validateConnParams(
6841
- schemaConfig.connParamsSchema,
6842
- rawConnParams ? JSON.parse(rawConnParams) : void 0
6843
- );
6844
- conn = await callNative(
6845
- () => runtime.actorConnectConn(
6940
+ return await runtime.runWithActorInvocationContext(
6941
+ ctx,
6942
+ async () => {
6943
+ const inspectorResponse = await maybeHandleNativeInspectorRequest(
6846
6944
  ctx,
6847
- encodeValue(connParams),
6848
6945
  request
6849
- )
6850
- );
6851
- requestCtx = makeConnCtx(
6852
- ctx,
6853
- conn,
6854
- handlerRequest,
6855
- cancelToken
6856
- );
6857
- const ctxAbortSignal = requestCtx.abortSignal;
6858
- const abortRequest = () => requestAbortController.abort(ctxAbortSignal.reason);
6859
- if (ctxAbortSignal.aborted) {
6860
- abortRequest();
6861
- } else {
6862
- ctxAbortSignal.addEventListener(
6863
- "abort",
6864
- abortRequest,
6865
- { once: true }
6866
- );
6867
- removeRequestAbortListener = () => ctxAbortSignal.removeEventListener(
6868
- "abort",
6869
- abortRequest
6870
- );
6871
- }
6872
- const response = await config.onRequest(
6873
- requestCtx,
6874
- handlerRequest
6875
- );
6876
- if (!_chunkTGGF6SZNcjs.isResponseLike.call(void 0, response)) {
6877
- throw new Error(
6878
- "onRequest handler must return a Response"
6879
6946
  );
6880
- }
6881
- const conversion = await convertNativeHttpResponse(
6882
- response,
6883
- responseBodyStream
6884
- );
6885
- if (conversion.bodyCompletion) {
6886
- cleanupDeferredToBody = true;
6887
- void conversion.bodyCompletion.then(cleanupRequest).catch((cleanupError) => {
6888
- logger2().error({
6889
- msg: "failed to clean up native streaming http request",
6890
- error: cleanupError
6891
- });
6947
+ if (inspectorResponse) {
6948
+ await cancelNativeHttpRequestBody(
6949
+ request.bodyStream
6950
+ );
6951
+ return (await convertNativeHttpResponse(
6952
+ inspectorResponse,
6953
+ responseBodyStream
6954
+ )).response;
6955
+ }
6956
+ if (typeof config.onRequest !== "function") {
6957
+ await cancelNativeHttpRequestBody(
6958
+ request.bodyStream
6959
+ );
6960
+ return (await convertNativeHttpResponse(
6961
+ new Response(null, { status: 404 }),
6962
+ responseBodyStream
6963
+ )).response;
6964
+ }
6965
+ const requestAbortController = new AbortController();
6966
+ const handlerRequest = buildNativeHttpRequest({
6967
+ ...request,
6968
+ abortController: requestAbortController
6892
6969
  });
6893
- }
6894
- return conversion.response;
6895
- } finally {
6896
- try {
6897
- await cancelNativeHttpRequestBody(
6898
- request.bodyStream
6899
- );
6900
- } finally {
6901
- if (!cleanupDeferredToBody) {
6902
- await cleanupRequest();
6970
+ const rawConnParams = handlerRequest.headers.get(_chunkIJUXBWH4cjs.HEADER_CONN_PARAMS);
6971
+ let requestCtx;
6972
+ let conn;
6973
+ let removeRequestAbortListener;
6974
+ let cleanupDeferredToBody = false;
6975
+ let cleanedUp = false;
6976
+ const cleanupRequest = async () => {
6977
+ if (cleanedUp) return;
6978
+ cleanedUp = true;
6979
+ removeRequestAbortListener == null ? void 0 : removeRequestAbortListener();
6980
+ try {
6981
+ await (requestCtx == null ? void 0 : requestCtx.dispose());
6982
+ } finally {
6983
+ if (conn) {
6984
+ await runtime.connDisconnect(conn);
6985
+ }
6986
+ }
6987
+ };
6988
+ try {
6989
+ const connParams = validateConnParams(
6990
+ schemaConfig.connParamsSchema,
6991
+ rawConnParams ? JSON.parse(rawConnParams) : void 0
6992
+ );
6993
+ conn = await callNative(
6994
+ () => runtime.actorConnectConn(
6995
+ ctx,
6996
+ encodeValue(connParams),
6997
+ request
6998
+ )
6999
+ );
7000
+ requestCtx = makeConnCtx(
7001
+ ctx,
7002
+ conn,
7003
+ handlerRequest,
7004
+ cancelToken
7005
+ );
7006
+ const ctxAbortSignal = requestCtx.abortSignal;
7007
+ const abortRequest = () => requestAbortController.abort(
7008
+ ctxAbortSignal.reason
7009
+ );
7010
+ if (ctxAbortSignal.aborted) {
7011
+ abortRequest();
7012
+ } else {
7013
+ ctxAbortSignal.addEventListener(
7014
+ "abort",
7015
+ abortRequest,
7016
+ { once: true }
7017
+ );
7018
+ removeRequestAbortListener = () => ctxAbortSignal.removeEventListener(
7019
+ "abort",
7020
+ abortRequest
7021
+ );
7022
+ }
7023
+ const response = await config.onRequest(
7024
+ requestCtx,
7025
+ handlerRequest
7026
+ );
7027
+ if (!_chunkIJUXBWH4cjs.isResponseLike.call(void 0, response)) {
7028
+ throw new Error(
7029
+ "onRequest handler must return a Response"
7030
+ );
7031
+ }
7032
+ const conversion = await convertNativeHttpResponse(
7033
+ response,
7034
+ responseBodyStream
7035
+ );
7036
+ if (conversion.bodyCompletion) {
7037
+ cleanupDeferredToBody = true;
7038
+ void conversion.bodyCompletion.then(cleanupRequest).catch((cleanupError) => {
7039
+ logger2().error({
7040
+ msg: "failed to clean up native streaming http request",
7041
+ error: cleanupError
7042
+ });
7043
+ });
7044
+ }
7045
+ return conversion.response;
7046
+ } finally {
7047
+ try {
7048
+ await cancelNativeHttpRequestBody(
7049
+ request.bodyStream
7050
+ );
7051
+ } finally {
7052
+ if (!cleanupDeferredToBody) {
7053
+ await cleanupRequest();
7054
+ }
7055
+ }
6903
7056
  }
6904
7057
  }
6905
- }
7058
+ );
6906
7059
  } catch (error2) {
6907
7060
  logger2().error({
6908
7061
  msg: "native onRequest failed",
@@ -6961,15 +7114,15 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6961
7114
  }
6962
7115
  );
6963
7116
  })(),
6964
- getWorkflowHistory: _chunk4KGXFC6Mcjs.hasRunInspectorConfig.call(void 0, config.run) ? wrapNativeCallback(
7117
+ getWorkflowHistory: _chunkEO5UOXXYcjs.hasRunInspectorConfig.call(void 0, config.run) ? wrapNativeCallback(
6965
7118
  async (error, payload) => {
6966
7119
  var _a2;
6967
7120
  const { ctx } = unwrapTsfnPayload(error, payload);
6968
7121
  const history = (_a2 = getNativeWorkflowInspector(ctx)) == null ? void 0 : _a2.getHistory();
6969
- return history == null ? void 0 : _chunk7E2W2YSMcjs.toUint8Array.call(void 0, history);
7122
+ return history == null ? void 0 : _chunkRJC5O2SDcjs.toUint8Array.call(void 0, history);
6970
7123
  }
6971
7124
  ) : void 0,
6972
- replayWorkflow: _chunk4KGXFC6Mcjs.hasRunInspectorConfig.call(void 0, config.run) ? wrapNativeCallback(
7125
+ replayWorkflow: _chunkEO5UOXXYcjs.hasRunInspectorConfig.call(void 0, config.run) ? wrapNativeCallback(
6973
7126
  async (error, payload) => {
6974
7127
  const { ctx, entryId } = unwrapTsfnPayload(
6975
7128
  error,
@@ -6980,7 +7133,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6980
7133
  return void 0;
6981
7134
  }
6982
7135
  const history = await _asyncNullishCoalesce(await workflowInspector.replayFromStep(entryId), async () => ( null));
6983
- return history == null ? void 0 : _chunk7E2W2YSMcjs.toUint8Array.call(void 0, history);
7136
+ return history == null ? void 0 : _chunkRJC5O2SDcjs.toUint8Array.call(void 0, history);
6984
7137
  }
6985
7138
  ) : void 0,
6986
7139
  actions: Object.fromEntries(
@@ -6990,21 +7143,27 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6990
7143
  async (error, payload) => {
6991
7144
  const { ctx, conn, args, scheduledFire, cancelToken } = unwrapTsfnPayload(error, payload);
6992
7145
  const actorCtx = conn != null ? makeConnCtx(ctx, conn, void 0, cancelToken) : makeActorCtx(ctx, void 0, cancelToken);
6993
- try {
6994
- return encodeValue(
6995
- await handler(
6996
- actorCtx,
6997
- ...validateActionArgs(
6998
- schemaConfig.actionInputSchemas,
6999
- name,
7000
- decodeArgs(args)
7001
- ),
7002
- ...scheduledFire ? [scheduledFire] : []
7003
- )
7004
- );
7005
- } finally {
7006
- await actorCtx.dispose();
7007
- }
7146
+ const runAction = async () => {
7147
+ try {
7148
+ return encodeValue(
7149
+ await handler(
7150
+ actorCtx,
7151
+ ...validateActionArgs(
7152
+ schemaConfig.actionInputSchemas,
7153
+ name,
7154
+ decodeArgs(args)
7155
+ ),
7156
+ ...scheduledFire ? [scheduledFire] : []
7157
+ )
7158
+ );
7159
+ } finally {
7160
+ await actorCtx.dispose();
7161
+ }
7162
+ };
7163
+ return await runtime.runWithActorInvocationContext(
7164
+ ctx,
7165
+ runAction
7166
+ );
7008
7167
  }
7009
7168
  )
7010
7169
  ])
@@ -7026,7 +7185,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7026
7185
  runtime,
7027
7186
  ctx,
7028
7187
  conn,
7029
- createClient,
7188
+ () => createClient(ctx),
7030
7189
  schemaConfig,
7031
7190
  databaseProvider,
7032
7191
  jsRequest,
@@ -7035,43 +7194,48 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7035
7194
  cancelToken,
7036
7195
  run !== void 0
7037
7196
  );
7038
- try {
7039
- if (!schemaConfig.queues || !hasSchemaConfigKey(schemaConfig.queues, name)) {
7040
- return { status: "completed" };
7041
- }
7042
- const canPublish = getQueueCanPublish(
7043
- schemaConfig.queues,
7044
- name
7045
- );
7046
- if (canPublish && !await canPublish(actorCtx)) {
7047
- throw _chunk2JSYYH6Pcjs.forbiddenError.call(void 0, );
7048
- }
7049
- const decodedBody = decodeValue(body);
7050
- if (wait) {
7197
+ return await runtime.runWithActorInvocationContext(
7198
+ ctx,
7199
+ async () => {
7051
7200
  try {
7052
- const response = await actorCtx.queue.enqueueAndWait(
7053
- name,
7054
- decodedBody,
7055
- {
7056
- timeout: timeoutMs === void 0 || timeoutMs === null ? void 0 : Number(timeoutMs)
7057
- }
7201
+ if (!schemaConfig.queues || !hasSchemaConfigKey(schemaConfig.queues, name)) {
7202
+ return { status: "completed" };
7203
+ }
7204
+ const canPublish = getQueueCanPublish(
7205
+ schemaConfig.queues,
7206
+ name
7058
7207
  );
7059
- return {
7060
- status: "completed",
7061
- response: response === void 0 ? void 0 : encodeValue(response)
7062
- };
7063
- } catch (error2) {
7064
- if (error2.group === "queue" && error2.code === "timed_out") {
7065
- return { status: "timedOut" };
7208
+ if (canPublish && !await canPublish(actorCtx)) {
7209
+ throw _chunkJX2ITWAVcjs.forbiddenError.call(void 0, );
7066
7210
  }
7067
- throw error2;
7211
+ const decodedBody = decodeValue(body);
7212
+ if (wait) {
7213
+ try {
7214
+ const response = await actorCtx.queue.enqueueAndWait(
7215
+ name,
7216
+ decodedBody,
7217
+ {
7218
+ timeout: timeoutMs === void 0 || timeoutMs === null ? void 0 : Number(timeoutMs)
7219
+ }
7220
+ );
7221
+ return {
7222
+ status: "completed",
7223
+ response: response === void 0 ? void 0 : encodeValue(response)
7224
+ };
7225
+ } catch (error2) {
7226
+ if (error2.group === "queue" && error2.code === "timed_out") {
7227
+ return { status: "timedOut" };
7228
+ }
7229
+ throw error2;
7230
+ }
7231
+ }
7232
+ await actorCtx.queue.send(name, decodedBody);
7233
+ return { status: "completed" };
7234
+ } finally {
7235
+ await actorCtx.dispose();
7068
7236
  }
7069
7237
  }
7070
- await actorCtx.queue.send(name, decodedBody);
7071
- return { status: "completed" };
7072
- } finally {
7073
- await actorCtx.dispose();
7074
- }
7238
+ );
7075
7239
  }
7076
7240
  ),
7077
7241
  serializeState: wrapNativeCallback(
@@ -7105,7 +7269,7 @@ async function buildServeConfig(config, resolveServicesBinary = true) {
7105
7269
  startServices: resolveServicesBinary && config.startServices,
7106
7270
  handleInspectorHttpInRuntime: true,
7107
7271
  serverlessBasePath: config.serverless.basePath,
7108
- serverlessPackageVersion: _chunk7E2W2YSMcjs.VERSION,
7272
+ serverlessPackageVersion: _chunkRJC5O2SDcjs.VERSION,
7109
7273
  serverlessClientEndpoint: config.publicEndpoint,
7110
7274
  serverlessClientNamespace: config.publicNamespace,
7111
7275
  serverlessClientToken: config.publicToken,
@@ -7118,7 +7282,7 @@ async function buildServeConfig(config, resolveServicesBinary = true) {
7118
7282
  } catch (error) {
7119
7283
  logger2().warn({
7120
7284
  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",
7121
- error: _chunk7E2W2YSMcjs.stringifyError.call(void 0, error)
7285
+ error: _chunkRJC5O2SDcjs.stringifyError.call(void 0, error)
7122
7286
  });
7123
7287
  }
7124
7288
  if (resolveServicesBinary && config.startServices) {
@@ -7128,20 +7292,20 @@ async function buildServeConfig(config, resolveServicesBinary = true) {
7128
7292
  } catch (error) {
7129
7293
  logger2().warn({
7130
7294
  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",
7131
- error: _chunk7E2W2YSMcjs.stringifyError.call(void 0, error)
7295
+ error: _chunkRJC5O2SDcjs.stringifyError.call(void 0, error)
7132
7296
  });
7133
7297
  }
7134
7298
  }
7135
7299
  serveConfig.engineHost = config.engineHost;
7136
7300
  serveConfig.enginePort = config.enginePort;
7137
7301
  if ((_a = config.test) == null ? void 0 : _a.enabled) {
7138
- serveConfig.inspectorTestToken = _nullishCoalesce(_chunk7E2W2YSMcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
7302
+ serveConfig.inspectorTestToken = _nullishCoalesce(_chunkRJC5O2SDcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN"), () => ( "token"));
7139
7303
  }
7140
7304
  return serveConfig;
7141
7305
  }
7142
7306
  async function buildRegistryWithRuntime(config, runtime) {
7143
7307
  var _a;
7144
- if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunk7E2W2YSMcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
7308
+ if (((_a = config.test) == null ? void 0 : _a.enabled) && _chunkRJC5O2SDcjs.getEnvUniversal.call(void 0, "_RIVET_TEST_INSPECTOR_TOKEN") === void 0) {
7145
7309
  trySetProcessEnv("_RIVET_TEST_INSPECTOR_TOKEN", "token");
7146
7310
  }
7147
7311
  if (runtime.kind === "napi") {
@@ -7208,7 +7372,7 @@ function createApplicationFetch(application, runtime) {
7208
7372
  signal: abortController.signal
7209
7373
  })
7210
7374
  );
7211
- if (!_chunkTGGF6SZNcjs.isResponseLike.call(void 0, response)) {
7375
+ if (!_chunkIJUXBWH4cjs.isResponseLike.call(void 0, response)) {
7212
7376
  throw new TypeError(
7213
7377
  "registry.listen() application fetch must return a Response"
7214
7378
  );
@@ -7258,7 +7422,7 @@ var Registry = class {
7258
7422
  var _a;
7259
7423
  this.#config = config;
7260
7424
  if ((_a = config.logging) == null ? void 0 : _a.baseLogger) {
7261
- _chunk7E2W2YSMcjs.configureBaseLogger.call(void 0, config.logging.baseLogger);
7425
+ _chunkRJC5O2SDcjs.configureBaseLogger.call(void 0, config.logging.baseLogger);
7262
7426
  }
7263
7427
  this.#buildConfiguredRegistry = _nullishCoalesce((deps == null ? void 0 : deps.buildConfiguredRegistry), () => ( buildConfiguredRegistry));
7264
7428
  this.routes = {
@@ -7484,10 +7648,10 @@ var Registry = class {
7484
7648
  * ```
7485
7649
  */
7486
7650
  async listen(opts = {}) {
7487
- const port = _nullishCoalesce(_nullishCoalesce(opts.port, () => ( _chunk7E2W2YSMcjs.parsePortEnv.call(void 0, process.env.RIVET_PORT))), () => ( 3e3));
7488
- const publicDir = _nullishCoalesce(opts.publicDir, () => ( _chunk7E2W2YSMcjs.getRivetkitPublicDir.call(void 0, )));
7651
+ const port = _nullishCoalesce(_nullishCoalesce(opts.port, () => ( _chunkRJC5O2SDcjs.parsePortEnv.call(void 0, process.env.RIVET_PORT))), () => ( 3e3));
7652
+ const publicDir = _nullishCoalesce(opts.publicDir, () => ( _chunkRJC5O2SDcjs.getRivetkitPublicDir.call(void 0, )));
7489
7653
  const config = this.parseConfig();
7490
- if (opts.application && _chunk7E2W2YSMcjs.getRivetkitRuntimeMode.call(void 0, ) !== "serverless") {
7654
+ if (opts.application && _chunkRJC5O2SDcjs.getRivetkitRuntimeMode.call(void 0, ) !== "serverless") {
7491
7655
  if (config.runtime === "wasm") {
7492
7656
  throw new Error(
7493
7657
  "registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly"
@@ -7563,7 +7727,7 @@ var Registry = class {
7563
7727
  return jsonRouteResponse(503, {
7564
7728
  status: "not_started",
7565
7729
  runtime: "rivetkit",
7566
- version: _chunk7E2W2YSMcjs.VERSION
7730
+ version: _chunkRJC5O2SDcjs.VERSION
7567
7731
  });
7568
7732
  }
7569
7733
  const { runtime, registry } = configured;
@@ -7571,7 +7735,7 @@ var Registry = class {
7571
7735
  return jsonRouteResponse(501, {
7572
7736
  status: "unsupported",
7573
7737
  runtime: "rivetkit",
7574
- version: _chunk7E2W2YSMcjs.VERSION
7738
+ version: _chunkRJC5O2SDcjs.VERSION
7575
7739
  });
7576
7740
  }
7577
7741
  const response = await runtime.registryHealth(registry);
@@ -7721,6 +7885,7 @@ var Registry = class {
7721
7885
  var _a;
7722
7886
  const modeAPromise = this.#runtimeServeConfiguredPromise;
7723
7887
  const modeBPromise = this.#runtimeServerlessPromise;
7888
+ const runtimes = /* @__PURE__ */ new Set();
7724
7889
  const gracePeriodMs = await _asyncNullishCoalesce(await _asyncNullishCoalesce(((_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs), async () => ( await this.#actorStopThresholdMs(_nullishCoalesce(modeAPromise, () => ( modeBPromise))))), async () => ( 30 * 60 * 1e3));
7725
7890
  const drain = async () => {
7726
7891
  const registries = [];
@@ -7729,6 +7894,7 @@ var Registry = class {
7729
7894
  (async () => {
7730
7895
  try {
7731
7896
  const { runtime, registry } = await modeAPromise;
7897
+ runtimes.add(runtime);
7732
7898
  await runtime.shutdownRegistry(registry);
7733
7899
  } catch (err) {
7734
7900
  logger2().warn(
@@ -7744,6 +7910,7 @@ var Registry = class {
7744
7910
  (async () => {
7745
7911
  try {
7746
7912
  const { runtime, registry } = await modeBPromise;
7913
+ runtimes.add(runtime);
7747
7914
  await runtime.shutdownRegistry(registry);
7748
7915
  } catch (err) {
7749
7916
  logger2().warn(
@@ -7772,6 +7939,12 @@ var Registry = class {
7772
7939
  }
7773
7940
  )
7774
7941
  ]);
7942
+ await Promise.all(
7943
+ [...runtimes].map((runtime) => {
7944
+ var _a2;
7945
+ return (_a2 = runtime.shutdownTelemetry) == null ? void 0 : _a2.call(runtime);
7946
+ })
7947
+ );
7775
7948
  }
7776
7949
  async #actorStopThresholdMs(configuredRegistryPromise) {
7777
7950
  var _a;
@@ -7818,7 +7991,7 @@ var Registry = class {
7818
7991
  );
7819
7992
  }
7820
7993
  if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
7821
- if (_chunk7E2W2YSMcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
7994
+ if (_chunkRJC5O2SDcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
7822
7995
  return Promise.reject(
7823
7996
  new Error(
7824
7997
  "registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request"
@@ -7888,8 +8061,8 @@ var Registry = class {
7888
8061
  * ```
7889
8062
  */
7890
8063
  start() {
7891
- if (_chunk7E2W2YSMcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
7892
- const publicDir = _nullishCoalesce(_chunk7E2W2YSMcjs.getRivetkitPublicDir.call(void 0, ), () => ( "/public"));
8064
+ if (_chunkRJC5O2SDcjs.getRivetkitRuntimeMode.call(void 0, ) === "serverless") {
8065
+ const publicDir = _nullishCoalesce(_chunkRJC5O2SDcjs.getRivetkitPublicDir.call(void 0, ), () => ( "/public"));
7893
8066
  this.listen({ publicDir }).catch((error) => {
7894
8067
  logger2().error({ error }, "auto-listen failed; exiting");
7895
8068
  if (typeof process !== "undefined" && typeof process.exit === "function") {
@@ -7910,7 +8083,7 @@ var Registry = class {
7910
8083
  };
7911
8084
  console.log();
7912
8085
  console.log(
7913
- ` RivetKit ${_chunk7E2W2YSMcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
8086
+ ` RivetKit ${_chunkRJC5O2SDcjs.VERSION} (Engine - ${kind === "serverless" ? "Serverless" : "Serverful"})`
7914
8087
  );
7915
8088
  if (config.namespace !== "default") {
7916
8089
  logLine("Namespace", config.namespace);
@@ -7986,5 +8159,5 @@ function setup(input) {
7986
8159
 
7987
8160
 
7988
8161
 
7989
- exports.ALLOWED_PUBLIC_HEADERS = _chunkTGGF6SZNcjs.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 = _chunkTGGF6SZNcjs.createClientWithDriver; exports.defineRunHandler = _chunk4KGXFC6Mcjs.defineRunHandler; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunk7E2W2YSMcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunk7E2W2YSMcjs.toUint8Array;
8162
+ exports.ALLOWED_PUBLIC_HEADERS = _chunkIJUXBWH4cjs.ALLOWED_PUBLIC_HEADERS; exports.ActorDefinition = ActorDefinition; exports.ActorError = _chunkJX2ITWAVcjs.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 = _chunkJX2ITWAVcjs.RivetError; exports.RuntimeKindSchema = RuntimeKindSchema; exports.SqliteBackendSchema = SqliteBackendSchema; exports.SqliteConfigSchema = SqliteConfigSchema; exports.TestConfigSchema = TestConfigSchema; exports.UserError = _chunkJX2ITWAVcjs.UserError; exports.WasmRuntimeConfigSchema = WasmRuntimeConfigSchema; exports.actor = actor; exports.buildActorNames = buildActorNames; exports.createClientWithDriver = _chunkIJUXBWH4cjs.createClientWithDriver; exports.defineRunHandler = _chunkEO5UOXXYcjs.defineRunHandler; exports.event = event; exports.isStaticActorDefinition = isStaticActorDefinition; exports.isStaticActorInstance = isStaticActorInstance; exports.lookupInRegistry = lookupInRegistry; exports.noopNext = _chunkRJC5O2SDcjs.noopNext; exports.queue = queue; exports.setup = setup; exports.toUint8Array = _chunkRJC5O2SDcjs.toUint8Array;
7990
8163
  //# sourceMappingURL=mod.cjs.map