rivetkit 2.3.24-rc.1 → 2.3.24

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 (115) hide show
  1. package/dist/browser/client.d.ts +3 -2
  2. package/dist/browser/client.js +36 -17
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +1 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/agent-os/index.cjs +1 -1
  7. package/dist/tsup/agent-os/index.cjs.map +1 -1
  8. package/dist/tsup/agent-os/index.d.cts +0 -2
  9. package/dist/tsup/agent-os/index.d.ts +0 -2
  10. package/dist/tsup/agent-os/index.js +1 -1
  11. package/dist/tsup/agent-os/index.js.map +1 -1
  12. package/dist/tsup/{chunk-6HW3TU7Q.js → chunk-45WBFRBN.js} +2 -2
  13. package/dist/tsup/{chunk-64CRWLOX.js → chunk-7OEOLF5T.js} +3 -3
  14. package/dist/tsup/{chunk-LTGBHN5Z.js → chunk-CSOHAAZK.js} +1 -1
  15. package/dist/tsup/chunk-CSOHAAZK.js.map +1 -0
  16. package/dist/tsup/{chunk-CE6NBGOL.cjs → chunk-JOJ42ZLR.cjs} +3 -3
  17. package/dist/tsup/{chunk-CE6NBGOL.cjs.map → chunk-JOJ42ZLR.cjs.map} +1 -1
  18. package/dist/tsup/{chunk-ERBNWARB.cjs → chunk-L4AZXL2Q.cjs} +4 -4
  19. package/dist/tsup/{chunk-ERBNWARB.cjs.map → chunk-L4AZXL2Q.cjs.map} +1 -1
  20. package/dist/tsup/{chunk-YVVFOKEP.cjs → chunk-NNM2X3ER.cjs} +2 -2
  21. package/dist/tsup/chunk-NNM2X3ER.cjs.map +1 -0
  22. package/dist/tsup/{chunk-OB5JLDBM.js → chunk-NSNBWLCG.js} +2 -2
  23. package/dist/tsup/{chunk-NGJWQMUU.cjs → chunk-NWCAIWHL.cjs} +1 -1
  24. package/dist/tsup/chunk-NWCAIWHL.cjs.map +1 -0
  25. package/dist/tsup/{chunk-M5J3PXNU.js → chunk-QMR2J7PT.js} +2 -2
  26. package/dist/tsup/{chunk-QQ454DVR.js → chunk-QZQE75U2.js} +2 -2
  27. package/dist/tsup/{chunk-B6WTPGOR.js → chunk-SW22GCYF.js} +30 -11
  28. package/dist/tsup/chunk-SW22GCYF.js.map +1 -0
  29. package/dist/tsup/{chunk-PFHGTLF2.cjs → chunk-TMMZAGZL.cjs} +10 -10
  30. package/dist/tsup/{chunk-PFHGTLF2.cjs.map → chunk-TMMZAGZL.cjs.map} +1 -1
  31. package/dist/tsup/{chunk-R3UI7MO3.cjs → chunk-TQNVNKDB.cjs} +165 -146
  32. package/dist/tsup/chunk-TQNVNKDB.cjs.map +1 -0
  33. package/dist/tsup/{chunk-JKDAOE4T.js → chunk-UIPQ7RI4.js} +4 -4
  34. package/dist/tsup/{chunk-SWQCSORE.cjs → chunk-WCSFWDKH.cjs} +3 -3
  35. package/dist/tsup/{chunk-SWQCSORE.cjs.map → chunk-WCSFWDKH.cjs.map} +1 -1
  36. package/dist/tsup/{chunk-DAC73W53.cjs → chunk-WTZGJFD4.cjs} +7 -7
  37. package/dist/tsup/{chunk-DAC73W53.cjs.map → chunk-WTZGJFD4.cjs.map} +1 -1
  38. package/dist/tsup/{chunk-JJCUSUWO.js → chunk-YH2CAWLD.js} +2 -2
  39. package/dist/tsup/chunk-YH2CAWLD.js.map +1 -0
  40. package/dist/tsup/{chunk-JMO6AVUC.cjs → chunk-ZCHJJ2FZ.cjs} +3 -3
  41. package/dist/tsup/{chunk-JMO6AVUC.cjs.map → chunk-ZCHJJ2FZ.cjs.map} +1 -1
  42. package/dist/tsup/client/mod.cjs +5 -5
  43. package/dist/tsup/client/mod.d.cts +5 -2
  44. package/dist/tsup/client/mod.d.ts +5 -2
  45. package/dist/tsup/client/mod.js +4 -4
  46. package/dist/tsup/common/log.cjs +2 -2
  47. package/dist/tsup/common/log.js +1 -1
  48. package/dist/tsup/common/websocket.cjs +3 -3
  49. package/dist/tsup/common/websocket.js +2 -2
  50. package/dist/tsup/{config-RV6gIa2L.d.ts → config-Cv6pjCt-.d.ts} +0 -4
  51. package/dist/tsup/{config-CuKzfH58.d.cts → config-osdJqQwX.d.cts} +0 -4
  52. package/dist/tsup/{context-DoMKZBQA.d.ts → context-CoVbKBuk.d.ts} +1 -1
  53. package/dist/tsup/{context-DPCxyjax.d.cts → context-DpjrM7n7.d.cts} +1 -1
  54. package/dist/tsup/db/drizzle.cjs +2 -2
  55. package/dist/tsup/db/drizzle.js +1 -1
  56. package/dist/tsup/db/mod.cjs +3 -3
  57. package/dist/tsup/db/mod.js +2 -2
  58. package/dist/tsup/dynamic/mod.cjs +2 -2
  59. package/dist/tsup/dynamic/mod.d.cts +1 -1
  60. package/dist/tsup/dynamic/mod.d.ts +1 -1
  61. package/dist/tsup/dynamic/mod.js +1 -1
  62. package/dist/tsup/inspector/mod.cjs +5 -5
  63. package/dist/tsup/inspector/mod.js +4 -4
  64. package/dist/tsup/inspector/workflow.cjs +4 -4
  65. package/dist/tsup/inspector/workflow.js +3 -3
  66. package/dist/tsup/inspector-tab/mod.cjs +2 -2
  67. package/dist/tsup/inspector-tab/mod.d.cts +2 -2
  68. package/dist/tsup/inspector-tab/mod.d.ts +2 -2
  69. package/dist/tsup/inspector-tab/mod.js +1 -1
  70. package/dist/tsup/mod.cjs +188 -416
  71. package/dist/tsup/mod.cjs.map +1 -1
  72. package/dist/tsup/mod.d.cts +3 -3
  73. package/dist/tsup/mod.d.ts +3 -3
  74. package/dist/tsup/mod.js +90 -318
  75. package/dist/tsup/mod.js.map +1 -1
  76. package/dist/tsup/test/mod.cjs +6 -6
  77. package/dist/tsup/test/mod.d.cts +1 -1
  78. package/dist/tsup/test/mod.d.ts +1 -1
  79. package/dist/tsup/test/mod.js +4 -4
  80. package/dist/tsup/utils.cjs +2 -2
  81. package/dist/tsup/utils.js +1 -1
  82. package/dist/tsup/workflow/mod.cjs +21 -69
  83. package/dist/tsup/workflow/mod.cjs.map +1 -1
  84. package/dist/tsup/workflow/mod.d.cts +3 -3
  85. package/dist/tsup/workflow/mod.d.ts +3 -3
  86. package/dist/tsup/workflow/mod.js +16 -64
  87. package/dist/tsup/workflow/mod.js.map +1 -1
  88. package/package.json +9 -9
  89. package/src/actor/config.ts +0 -2
  90. package/src/client/config.ts +3 -0
  91. package/src/client/raw-utils.ts +7 -2
  92. package/src/common/fetch-like.ts +14 -0
  93. package/src/engine-client/actor-http-client.ts +16 -6
  94. package/src/registry/napi-runtime.ts +0 -8
  95. package/src/registry/native.ts +65 -332
  96. package/src/registry/run-handler-coordinator.test.ts +0 -102
  97. package/src/registry/run-handler-coordinator.ts +17 -84
  98. package/src/registry/runtime.ts +0 -2
  99. package/src/registry/wasm-runtime.ts +0 -8
  100. package/src/workflow/context.ts +0 -20
  101. package/src/workflow/driver.ts +1 -25
  102. package/src/workflow/mod.ts +12 -46
  103. package/dist/tsup/chunk-B6WTPGOR.js.map +0 -1
  104. package/dist/tsup/chunk-JJCUSUWO.js.map +0 -1
  105. package/dist/tsup/chunk-LTGBHN5Z.js.map +0 -1
  106. package/dist/tsup/chunk-NGJWQMUU.cjs.map +0 -1
  107. package/dist/tsup/chunk-R3UI7MO3.cjs.map +0 -1
  108. package/dist/tsup/chunk-YVVFOKEP.cjs.map +0 -1
  109. package/src/registry/lost-callbacks.test.ts +0 -64
  110. /package/dist/tsup/{chunk-6HW3TU7Q.js.map → chunk-45WBFRBN.js.map} +0 -0
  111. /package/dist/tsup/{chunk-64CRWLOX.js.map → chunk-7OEOLF5T.js.map} +0 -0
  112. /package/dist/tsup/{chunk-OB5JLDBM.js.map → chunk-NSNBWLCG.js.map} +0 -0
  113. /package/dist/tsup/{chunk-M5J3PXNU.js.map → chunk-QMR2J7PT.js.map} +0 -0
  114. /package/dist/tsup/{chunk-QQ454DVR.js.map → chunk-QZQE75U2.js.map} +0 -0
  115. /package/dist/tsup/{chunk-JKDAOE4T.js.map → chunk-UIPQ7RI4.js.map} +0 -0
package/dist/tsup/mod.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  decodeWorkflowHistoryTransport
3
- } from "./chunk-M5J3PXNU.js";
3
+ } from "./chunk-QMR2J7PT.js";
4
4
  import {
5
5
  ACTOR_CONTEXT_INTERNAL_SYMBOL,
6
6
  ActorConfigSchema,
@@ -17,7 +17,7 @@ import {
17
17
  getRunInspectorKind,
18
18
  getRunMetadata,
19
19
  hasRunInspectorConfig
20
- } from "./chunk-LTGBHN5Z.js";
20
+ } from "./chunk-CSOHAAZK.js";
21
21
  import {
22
22
  ALLOWED_PUBLIC_HEADERS,
23
23
  ENGINE_HOST,
@@ -35,18 +35,18 @@ import {
35
35
  runWithActorInvocationSpan,
36
36
  tryParseEndpoint,
37
37
  updateRunnerConfig
38
- } from "./chunk-B6WTPGOR.js";
38
+ } from "./chunk-SW22GCYF.js";
39
39
  import {
40
40
  makePrefixedKey,
41
41
  removePrefixFromKey
42
42
  } from "./chunk-JI6GZ2C2.js";
43
+ import "./chunk-NSNBWLCG.js";
43
44
  import {
44
45
  bindNativeStateTransactionContext,
45
46
  db,
46
47
  registerNativeStateTransactionOpener
47
- } from "./chunk-QQ454DVR.js";
48
+ } from "./chunk-QZQE75U2.js";
48
49
  import "./chunk-JTHHCZCZ.js";
49
- import "./chunk-OB5JLDBM.js";
50
50
  import {
51
51
  LogLevelSchema,
52
52
  VERSION,
@@ -80,7 +80,7 @@ import {
80
80
  parsePortEnv,
81
81
  stringifyError,
82
82
  toUint8Array
83
- } from "./chunk-JJCUSUWO.js";
83
+ } from "./chunk-YH2CAWLD.js";
84
84
  import {
85
85
  INTERNAL_ERROR_CODE,
86
86
  RivetError,
@@ -1732,12 +1732,6 @@ var NapiCoreRuntime = class {
1732
1732
  actorId(ctx) {
1733
1733
  return asNativeActorContext(ctx).actorId();
1734
1734
  }
1735
- actorGeneration(ctx) {
1736
- return asNativeActorContext(ctx).generation() ?? void 0;
1737
- }
1738
- actorIsLost(ctx) {
1739
- return asNativeActorContext(ctx).isLost();
1740
- }
1741
1735
  runWithActorInvocationContext(ctx, run) {
1742
1736
  return this.#runAs(asNativeActorContext(ctx), run);
1743
1737
  }
@@ -2357,27 +2351,6 @@ function notifyStateChanged(state) {
2357
2351
  waiter();
2358
2352
  }
2359
2353
  }
2360
- function createRunState(actorGeneration) {
2361
- return {
2362
- actorGeneration,
2363
- active: false,
2364
- closed: false,
2365
- exclusive: false,
2366
- exclusiveGeneration: 0,
2367
- inspectorInitialized: false,
2368
- queued: 0,
2369
- waiters: /* @__PURE__ */ new Set()
2370
- };
2371
- }
2372
- function closeRunState(state, disposeInspector = true) {
2373
- var _a, _b;
2374
- state.closed = true;
2375
- if (disposeInspector) {
2376
- (_b = (_a = state.inspector) == null ? void 0 : _a.dispose) == null ? void 0 : _b.call(_a);
2377
- }
2378
- state.inspector = void 0;
2379
- notifyStateChanged(state);
2380
- }
2381
2354
  function waitForStateChange(state) {
2382
2355
  return new Promise((resolve) => {
2383
2356
  state.waiters.add(resolve);
@@ -2392,11 +2365,8 @@ var RunHandlerCoordinator = class {
2392
2365
  get inspectorKind() {
2393
2366
  return getRunInspectorKind(this.#run);
2394
2367
  }
2395
- async run(actorId, restart, callback, actorGeneration) {
2396
- const state = this.#getOrCreate(actorId, actorGeneration);
2397
- if (state.closed) {
2398
- return "closed";
2399
- }
2368
+ async run(actorId, restart, callback) {
2369
+ const state = this.#getOrCreate(actorId);
2400
2370
  state.restart = restart;
2401
2371
  this.#initializeInspector(actorId, state);
2402
2372
  state.queued += 1;
@@ -2423,27 +2393,21 @@ var RunHandlerCoordinator = class {
2423
2393
  notifyStateChanged(state);
2424
2394
  }
2425
2395
  }
2426
- getInspector(actorId, restart, actorGeneration) {
2396
+ getInspector(actorId, restart) {
2427
2397
  var _a;
2428
- const state = this.#getOrCreate(actorId, actorGeneration);
2429
- if (state.closed) {
2430
- return void 0;
2431
- }
2398
+ const state = this.#getOrCreate(actorId);
2432
2399
  state.restart = restart;
2433
2400
  this.#initializeInspector(actorId, state);
2434
2401
  return (_a = state.inspector) == null ? void 0 : _a.inspector;
2435
2402
  }
2436
- /**
2437
- * Closes the run state for `actorId`. With `actorGeneration`, only state owned by that
2438
- * generation is closed, so an older generation's late cleanup cannot close a newer one.
2439
- */
2440
- destroy(actorId, actorGeneration, options = {}) {
2403
+ destroy(actorId) {
2404
+ var _a, _b;
2441
2405
  const state = this.#states.get(actorId);
2442
2406
  if (!state) return;
2443
- if (actorGeneration !== void 0 && state.actorGeneration !== void 0 && state.actorGeneration !== actorGeneration) {
2444
- return;
2445
- }
2446
- closeRunState(state, options.disposeInspector ?? true);
2407
+ state.closed = true;
2408
+ (_b = (_a = state.inspector) == null ? void 0 : _a.dispose) == null ? void 0 : _b.call(_a);
2409
+ state.inspector = void 0;
2410
+ notifyStateChanged(state);
2447
2411
  this.#states.delete(actorId);
2448
2412
  }
2449
2413
  #control(actorId, state) {
@@ -2489,20 +2453,18 @@ var RunHandlerCoordinator = class {
2489
2453
  }
2490
2454
  };
2491
2455
  }
2492
- #getOrCreate(actorId, actorGeneration) {
2456
+ #getOrCreate(actorId) {
2493
2457
  let state = this.#states.get(actorId);
2494
- if (state && actorGeneration !== void 0 && state.actorGeneration !== void 0 && state.actorGeneration !== actorGeneration) {
2495
- if (actorGeneration < state.actorGeneration) {
2496
- const detached = createRunState(actorGeneration);
2497
- detached.closed = true;
2498
- return detached;
2499
- }
2500
- closeRunState(state, false);
2501
- this.#states.delete(actorId);
2502
- state = void 0;
2503
- }
2504
2458
  if (!state) {
2505
- state = createRunState(actorGeneration);
2459
+ state = {
2460
+ active: false,
2461
+ closed: false,
2462
+ exclusive: false,
2463
+ exclusiveGeneration: 0,
2464
+ inspectorInitialized: false,
2465
+ queued: 0,
2466
+ waiters: /* @__PURE__ */ new Set()
2467
+ };
2506
2468
  this.#states.set(actorId, state);
2507
2469
  }
2508
2470
  return state;
@@ -2511,7 +2473,6 @@ var RunHandlerCoordinator = class {
2511
2473
  if (state.inspectorInitialized) return;
2512
2474
  const inspector = createRunInspector(this.#run, {
2513
2475
  actorId,
2514
- actorGeneration: state.actorGeneration,
2515
2476
  control: this.#control(actorId, state)
2516
2477
  });
2517
2478
  if (this.inspectorKind === "workflow") {
@@ -2839,12 +2800,6 @@ var WasmCoreRuntime = class {
2839
2800
  actorId(ctx) {
2840
2801
  return callHandle(asWasmActorContext(ctx), "actorId");
2841
2802
  }
2842
- actorGeneration(ctx) {
2843
- return callHandle(asWasmActorContext(ctx), "generation") ?? void 0;
2844
- }
2845
- actorIsLost(ctx) {
2846
- return callHandle(asWasmActorContext(ctx), "isLost");
2847
- }
2848
2803
  runWithActorInvocationContext(_ctx, run) {
2849
2804
  return run();
2850
2805
  }
@@ -3676,11 +3631,8 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
3676
3631
  await closeNativeDatabaseClient(runtime, ctx);
3677
3632
  await closeNativeSqlDatabase(runtime, ctx);
3678
3633
  void runtime.actorWaitForTrackedShutdownWorkUnbounded(ctx).then(async () => {
3679
- try {
3680
- await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
3681
- } finally {
3682
- clearNativeRuntimeState(runtime, ctx);
3683
- }
3634
+ await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
3635
+ clearNativeRuntimeState(runtime, ctx);
3684
3636
  }).catch((error) => {
3685
3637
  logger2().warn({
3686
3638
  msg: "deferred native sleep cleanup failed",
@@ -3689,24 +3641,10 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
3689
3641
  });
3690
3642
  return;
3691
3643
  }
3692
- try {
3693
- await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
3694
- } finally {
3695
- try {
3696
- await closeNativeDatabaseClient(runtime, ctx);
3697
- await closeNativeSqlDatabase(runtime, ctx);
3698
- } finally {
3699
- clearNativeRuntimeState(runtime, ctx);
3700
- }
3701
- }
3702
- }
3703
- async function cleanupNativeLostRuntimeState(runtime, ctx) {
3644
+ await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
3704
3645
  await closeNativeDatabaseClient(runtime, ctx);
3705
- try {
3706
- await closeNativeSqlDatabase(runtime, ctx);
3707
- } finally {
3708
- clearNativeRuntimeState(runtime, ctx);
3709
- }
3646
+ await closeNativeSqlDatabase(runtime, ctx);
3647
+ clearNativeRuntimeState(runtime, ctx);
3710
3648
  }
3711
3649
  function closeNativeSqlDatabase(runtime, ctx) {
3712
3650
  const runtimeState = getNativeRuntimeState(runtime, ctx);
@@ -3724,9 +3662,6 @@ async function closeNativeDatabaseClient(runtime, ctx) {
3724
3662
  return;
3725
3663
  }
3726
3664
  runtimeState.databaseClient = void 0;
3727
- if (callNativeSync(() => runtime.actorIsLost(ctx))) {
3728
- return;
3729
- }
3730
3665
  if (entry.client && typeof entry.client === "object" && "close" in entry.client && typeof entry.client.close === "function") {
3731
3666
  await entry.client.close();
3732
3667
  }
@@ -4152,49 +4087,6 @@ function wrapNativeCallback(callback) {
4152
4087
  }
4153
4088
  };
4154
4089
  }
4155
- var LOST_GENERATION_CLEANUP_CALLBACKS = /* @__PURE__ */ new Set(["onSleep", "onDestroy"]);
4156
- function throwIfActorLost(runtime, ctx) {
4157
- if (callNativeSync(() => runtime.actorIsLost(ctx))) {
4158
- throw actorGenerationLostError();
4159
- }
4160
- }
4161
- function actorGenerationLostError() {
4162
- return new RivetError(
4163
- "actor",
4164
- "stopping",
4165
- "Actor generation was declared lost; it starts no new user callbacks."
4166
- );
4167
- }
4168
- function refuseCallbacksAfterLost(runtime, callbacks) {
4169
- const guard = (callback) => {
4170
- return async (...args) => {
4171
- var _a;
4172
- const ctx = (_a = args[1]) == null ? void 0 : _a.ctx;
4173
- if (ctx !== void 0 && callNativeSync(() => runtime.actorIsLost(ctx))) {
4174
- throw encodeNativeCallbackError(actorGenerationLostError());
4175
- }
4176
- return await callback(...args);
4177
- };
4178
- };
4179
- const guarded = {};
4180
- for (const [name, value] of Object.entries(callbacks)) {
4181
- if (LOST_GENERATION_CLEANUP_CALLBACKS.has(name)) {
4182
- guarded[name] = value;
4183
- } else if (typeof value === "function") {
4184
- guarded[name] = guard(value);
4185
- } else if (name === "actions" && value !== null && typeof value === "object") {
4186
- guarded[name] = Object.fromEntries(
4187
- Object.entries(value).map(([actionName, handler]) => [
4188
- actionName,
4189
- guard(handler)
4190
- ])
4191
- );
4192
- } else {
4193
- guarded[name] = value;
4194
- }
4195
- }
4196
- return guarded;
4197
- }
4198
4090
  function decodeArgs(value) {
4199
4091
  const decoded = decodeValue(value);
4200
4092
  return normalizeArgs(decoded);
@@ -4632,30 +4524,17 @@ var NativeQueueAdapter = class {
4632
4524
  this.#ctx = ctx;
4633
4525
  this.#schemas = schemas;
4634
4526
  }
4635
- // Queue results arrive after awaits, and their schema validation is user code, so each
4636
- // validation checks that the generation was not lost first.
4637
- #validateBody(name, body) {
4638
- throwIfActorLost(this.#runtime, this.#ctx);
4639
- return validateQueueBody(this.#schemas, name, body);
4640
- }
4641
- #validateComplete(name, response) {
4642
- throwIfActorLost(this.#runtime, this.#ctx);
4643
- return validateQueueComplete(this.#schemas, name, response);
4644
- }
4645
- #wrap(message) {
4646
- throwIfActorLost(this.#runtime, this.#ctx);
4647
- return wrapQueueMessage(message, this.#schemas);
4648
- }
4649
4527
  async send(name, body) {
4650
- const validatedBody = this.#validateBody(name, body);
4651
- return this.#wrap(
4528
+ const validatedBody = validateQueueBody(this.#schemas, name, body);
4529
+ return wrapQueueMessage(
4652
4530
  await callNative(
4653
4531
  () => this.#runtime.actorQueueSend(
4654
4532
  this.#ctx,
4655
4533
  name,
4656
4534
  encodeValue(validatedBody)
4657
4535
  )
4658
- )
4536
+ ),
4537
+ this.#schemas
4659
4538
  );
4660
4539
  }
4661
4540
  async next(options) {
@@ -4698,7 +4577,9 @@ var NativeQueueAdapter = class {
4698
4577
  token
4699
4578
  )
4700
4579
  );
4701
- const wrapped = messages.map((message) => this.#wrap(message));
4580
+ const wrapped = messages.map(
4581
+ (message) => wrapQueueMessage(message, this.#schemas)
4582
+ );
4702
4583
  return completable ? wrapped.map(
4703
4584
  (message) => this.#makeCompletableMessage(message)
4704
4585
  ) : wrapped;
@@ -4712,7 +4593,7 @@ var NativeQueueAdapter = class {
4712
4593
  options == null ? void 0 : options.signal
4713
4594
  );
4714
4595
  try {
4715
- return this.#wrap(
4596
+ return wrapQueueMessage(
4716
4597
  await callNative(
4717
4598
  () => this.#runtime.actorQueueWaitForNames(
4718
4599
  this.#ctx,
@@ -4723,7 +4604,8 @@ var NativeQueueAdapter = class {
4723
4604
  },
4724
4605
  token
4725
4606
  )
4726
- )
4607
+ ),
4608
+ this.#schemas
4727
4609
  );
4728
4610
  } finally {
4729
4611
  cleanup == null ? void 0 : cleanup();
@@ -4753,7 +4635,8 @@ var NativeQueueAdapter = class {
4753
4635
  await this.waitForNamesAvailable(names ?? [], options);
4754
4636
  }
4755
4637
  async complete(message, response) {
4756
- const validatedResponse = this.#validateComplete(
4638
+ const validatedResponse = validateQueueComplete(
4639
+ this.#schemas,
4757
4640
  message.name,
4758
4641
  response
4759
4642
  );
@@ -4768,7 +4651,7 @@ var NativeQueueAdapter = class {
4768
4651
  this.#pendingCompletableMessageIds.delete(message.id.toString());
4769
4652
  }
4770
4653
  async enqueueAndWait(name, body, options) {
4771
- const validatedBody = this.#validateBody(name, body);
4654
+ const validatedBody = validateQueueBody(this.#schemas, name, body);
4772
4655
  const { token, cleanup } = await createCancellationTokenHandle(
4773
4656
  this.#runtime,
4774
4657
  options == null ? void 0 : options.signal
@@ -4785,7 +4668,11 @@ var NativeQueueAdapter = class {
4785
4668
  token
4786
4669
  )
4787
4670
  );
4788
- return response === void 0 || response === null ? void 0 : this.#validateComplete(name, decodeValue(response));
4671
+ return response === void 0 || response === null ? void 0 : validateQueueComplete(
4672
+ this.#schemas,
4673
+ name,
4674
+ decodeValue(response)
4675
+ );
4789
4676
  } finally {
4790
4677
  cleanup == null ? void 0 : cleanup();
4791
4678
  }
@@ -5166,9 +5053,6 @@ var TrackedWebSocketHandleAdapter = class {
5166
5053
  }
5167
5054
  }
5168
5055
  #callHandler(type, handler, event2) {
5169
- if ((type === "message" || type === "open") && this.#ctx.isLost) {
5170
- return;
5171
- }
5172
5056
  try {
5173
5057
  const result = handler(event2);
5174
5058
  if (!this.#isPromiseLike(result)) {
@@ -5451,13 +5335,6 @@ var ActorContextHandleAdapter = class {
5451
5335
  get actorId() {
5452
5336
  return callNativeSync(() => this.#runtime.actorId(this.#ctx));
5453
5337
  }
5454
- get actorGeneration() {
5455
- return callNativeSync(() => this.#runtime.actorGeneration(this.#ctx));
5456
- }
5457
- /** Whether this generation was declared lost. A lost generation starts no new user code. */
5458
- get isLost() {
5459
- return callNativeSync(() => this.#runtime.actorIsLost(this.#ctx));
5460
- }
5461
5338
  get name() {
5462
5339
  return callNativeSync(() => this.#runtime.actorName(this.#ctx));
5463
5340
  }
@@ -5572,9 +5449,6 @@ var ActorContextHandleAdapter = class {
5572
5449
  return this.#db;
5573
5450
  }
5574
5451
  const actorId = this.actorId;
5575
- if (this.isLost) {
5576
- throw actorGenerationLostError();
5577
- }
5578
5452
  const createdClient = await this.#databaseProvider.createClient({
5579
5453
  actorId,
5580
5454
  kv: {
@@ -5727,11 +5601,9 @@ var ActorContextHandleAdapter = class {
5727
5601
  if (!this.#databaseProvider) {
5728
5602
  return;
5729
5603
  }
5730
- const client = await this.ensureDatabaseClient();
5731
- if (this.isLost) {
5732
- throw actorGenerationLostError();
5733
- }
5734
- await this.#databaseProvider.onMigrate(client);
5604
+ await this.#databaseProvider.onMigrate(
5605
+ await this.ensureDatabaseClient()
5606
+ );
5735
5607
  }
5736
5608
  async closeDatabase() {
5737
5609
  this.#db = void 0;
@@ -6003,7 +5875,7 @@ var ActorContextHandleAdapter = class {
6003
5875
  callNativeSync(
6004
5876
  () => this.#runtime.actorRequestSave(this.#ctx, { immediate: false })
6005
5877
  );
6006
- if (!this.#onStateChange || this.isLost) {
5878
+ if (!this.#onStateChange) {
6007
5879
  return;
6008
5880
  }
6009
5881
  actorState.isInOnStateChange = true;
@@ -6043,12 +5915,6 @@ var NativeWorkflowRuntimeAdapter = class {
6043
5915
  #onMessagesReceived;
6044
5916
  #completions = /* @__PURE__ */ new Map();
6045
5917
  id;
6046
- /** Actor generation, used to keep workflow registrations of different generations apart. */
6047
- generation;
6048
- /** Whether this generation was declared lost. Workflow code checks it before each user callback. */
6049
- get isLost() {
6050
- return this.#ctx.isLost;
6051
- }
6052
5918
  driver;
6053
5919
  queueManager;
6054
5920
  stateManager;
@@ -6056,7 +5922,6 @@ var NativeWorkflowRuntimeAdapter = class {
6056
5922
  this.#ctx = ctx;
6057
5923
  this.#onMessagesReceived = onMessagesReceived;
6058
5924
  this.id = ctx.actorId;
6059
- this.generation = ctx.actorGeneration;
6060
5925
  this.driver = {
6061
5926
  kvBatchGet: async (actorId, keys) => {
6062
5927
  this.#assertActorId(actorId);
@@ -6339,23 +6204,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6339
6204
  const runHandlerCoordinator = getRunInspectorKind(config.run) === "workflow" ? new RunHandlerCoordinator(config.run) : void 0;
6340
6205
  const getNativeWorkflowInspector = (ctx) => {
6341
6206
  var _a2, _b;
6342
- if (callNativeSync(() => runtime.actorIsLost(ctx))) {
6343
- return void 0;
6344
- }
6345
6207
  const actorId = callNativeSync(() => runtime.actorId(ctx));
6346
6208
  const restart = () => callNativeSync(() => runtime.actorRestartRunHandler(ctx));
6347
- const actorGeneration = callNativeSync(
6348
- () => runtime.actorGeneration(ctx)
6349
- );
6350
- const inspector = ((_a2 = runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.getInspector(
6351
- actorId,
6352
- restart,
6353
- actorGeneration
6354
- )) == null ? void 0 : _a2.workflow) ?? ((_b = getRunInspectorConfig(config.run, actorId)) == null ? void 0 : _b.workflow);
6355
- if (callNativeSync(() => runtime.actorIsLost(ctx))) {
6356
- return void 0;
6357
- }
6358
- return inspector;
6209
+ return ((_a2 = runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.getInspector(actorId, restart)) == null ? void 0 : _a2.workflow) ?? ((_b = getRunInspectorConfig(config.run, actorId)) == null ? void 0 : _b.workflow);
6359
6210
  };
6360
6211
  const onStateChange = typeof config.onStateChange === "function" ? (actorCtx, nextState) => {
6361
6212
  config.onStateChange(actorCtx, nextState);
@@ -6432,10 +6283,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6432
6283
  return errorResponse(error, 401);
6433
6284
  }
6434
6285
  }
6435
- const inspectorConnParams = (conn) => {
6436
- throwIfActorLost(runtime, ctx);
6437
- return conn.params;
6438
- };
6439
6286
  const workflowHistory = () => {
6440
6287
  var _a3;
6441
6288
  return serializeWorkflowHistoryForJson(
@@ -6469,7 +6316,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6469
6316
  id: conn.id,
6470
6317
  details: {
6471
6318
  type: null,
6472
- params: inspectorConnParams(conn),
6319
+ params: conn.params,
6473
6320
  stateEnabled: true,
6474
6321
  state: conn.state,
6475
6322
  subscriptions: 0,
@@ -6673,7 +6520,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6673
6520
  id: conn.id,
6674
6521
  details: {
6675
6522
  type: null,
6676
- params: inspectorConnParams(conn),
6523
+ params: conn.params,
6677
6524
  stateEnabled: true,
6678
6525
  state: conn.state,
6679
6526
  subscriptions: 0,
@@ -6720,20 +6567,15 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6720
6567
  );
6721
6568
  }
6722
6569
  const args = body.properties !== void 0 ? [body.properties] : normalizeArgs(body.args);
6723
- if (callNativeSync(() => runtime.actorIsLost(ctx))) {
6724
- return jsonResponse(
6725
- { error: "actor generation was declared lost" },
6726
- { status: 503 }
6727
- );
6728
- }
6729
6570
  try {
6730
- const validatedArgs = validateActionArgs(
6731
- schemaConfig.actionInputSchemas,
6732
- actionName,
6733
- args
6571
+ const output = await action(
6572
+ actorCtx,
6573
+ ...validateActionArgs(
6574
+ schemaConfig.actionInputSchemas,
6575
+ actionName,
6576
+ args
6577
+ )
6734
6578
  );
6735
- throwIfActorLost(runtime, ctx);
6736
- const output = await action(actorCtx, ...validatedArgs);
6737
6579
  return jsonResponse({ output });
6738
6580
  } catch (error) {
6739
6581
  logger2().error({
@@ -6837,9 +6679,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6837
6679
  await actorCtx.closeDatabase();
6838
6680
  }
6839
6681
  await actorCtx.runDatabaseMigrations();
6840
- if (typeof config.onMigrate === "function" && !callNativeSync(
6841
- () => runtime.actorIsLost(ctx)
6842
- )) {
6682
+ if (typeof config.onMigrate === "function") {
6843
6683
  await config.onMigrate(actorCtx, isNew);
6844
6684
  }
6845
6685
  } catch (error2) {
@@ -6882,29 +6722,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6882
6722
  const { ctx } = unwrapTsfnPayload(error, payload);
6883
6723
  const actorCtx = makeActorCtx(ctx);
6884
6724
  const actorId = callNativeSync(() => runtime.actorId(ctx));
6885
- const actorGeneration = callNativeSync(
6886
- () => runtime.actorGeneration(ctx)
6887
- );
6888
- const isLost = () => callNativeSync(() => runtime.actorIsLost(ctx));
6889
- if (isLost()) {
6890
- try {
6891
- await cleanupNativeLostRuntimeState(runtime, ctx);
6892
- } finally {
6893
- runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(
6894
- actorId,
6895
- actorGeneration,
6896
- {
6897
- disposeInspector: false
6898
- }
6899
- );
6900
- await actorCtx.dispose();
6901
- }
6902
- return;
6903
- }
6904
6725
  const saveActorState = async () => {
6905
- if (isLost()) {
6906
- return;
6907
- }
6908
6726
  if (runtime.kind === "wasm") {
6909
6727
  await runtime.actorSaveState(
6910
6728
  ctx,
@@ -6923,26 +6741,14 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6923
6741
  await saveActorState();
6924
6742
  } finally {
6925
6743
  try {
6926
- if (isLost()) {
6927
- await cleanupNativeLostRuntimeState(runtime, ctx);
6928
- } else {
6929
- await cleanupNativeSleepRuntimeState(
6930
- runtime,
6931
- ctx,
6932
- saveActorState
6933
- );
6934
- }
6935
- } finally {
6936
- runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(
6937
- actorId,
6938
- actorGeneration,
6939
- {
6940
- disposeInspector: !isLost()
6941
- }
6744
+ await cleanupNativeSleepRuntimeState(
6745
+ runtime,
6746
+ ctx,
6747
+ saveActorState
6942
6748
  );
6943
- if (!isLost()) {
6944
- disposeRunInspector(config.run, actorId);
6945
- }
6749
+ } finally {
6750
+ runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(actorId);
6751
+ disposeRunInspector(config.run, actorId);
6946
6752
  await actorCtx.dispose();
6947
6753
  }
6948
6754
  }
@@ -6953,17 +6759,10 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6953
6759
  const { ctx } = unwrapTsfnPayload(error, payload);
6954
6760
  const actorCtx = makeActorCtx(ctx);
6955
6761
  const actorId = callNativeSync(() => runtime.actorId(ctx));
6956
- const isLost = () => callNativeSync(() => runtime.actorIsLost(ctx));
6957
- runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(
6958
- actorId,
6959
- callNativeSync(() => runtime.actorGeneration(ctx)),
6960
- { disposeInspector: !isLost() }
6961
- );
6962
- if (!isLost()) {
6963
- disposeRunInspector(config.run, actorId);
6964
- }
6762
+ runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(actorId);
6763
+ disposeRunInspector(config.run, actorId);
6965
6764
  try {
6966
- if (typeof config.onDestroy === "function" && !isLost()) {
6765
+ if (typeof config.onDestroy === "function") {
6967
6766
  await config.onDestroy(actorCtx);
6968
6767
  }
6969
6768
  } finally {
@@ -6985,14 +6784,12 @@ function buildNativeFactory(runtime, registryConfig, definition) {
6985
6784
  request ? buildNativeHttpRequest(request) : void 0
6986
6785
  );
6987
6786
  try {
6988
- const validatedParams = validateConnParams(
6989
- schemaConfig.connParamsSchema,
6990
- decodeValue(params)
6991
- );
6992
- throwIfActorLost(runtime, ctx);
6993
6787
  await config.onBeforeConnect(
6994
6788
  actorCtx,
6995
- validatedParams
6789
+ validateConnParams(
6790
+ schemaConfig.connParamsSchema,
6791
+ decodeValue(params)
6792
+ )
6996
6793
  );
6997
6794
  } finally {
6998
6795
  await actorCtx.dispose();
@@ -7020,22 +6817,13 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7020
6817
  () => actorCtx.assertCanMutateState()
7021
6818
  );
7022
6819
  try {
7023
- let nextConnState;
7024
- if (hasStaticConnState) {
7025
- nextConnState = structuredClone(
7026
- config.connState
7027
- );
7028
- } else {
7029
- const validatedParams = validateConnParams(
6820
+ const nextConnState = hasStaticConnState ? structuredClone(config.connState) : await config.createConnState(
6821
+ actorCtx,
6822
+ validateConnParams(
7030
6823
  schemaConfig.connParamsSchema,
7031
6824
  decodeValue(params)
7032
- );
7033
- throwIfActorLost(runtime, ctx);
7034
- nextConnState = await config.createConnState(
7035
- actorCtx,
7036
- validatedParams
7037
- );
7038
- }
6825
+ )
6826
+ );
7039
6827
  connAdapter.initializeState(nextConnState);
7040
6828
  return encodeValue(nextConnState);
7041
6829
  } finally {
@@ -7140,9 +6928,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7140
6928
  onBeforeActionResponse: typeof config.onBeforeActionResponse === "function" ? wrapNativeCallback(
7141
6929
  async (error, payload) => {
7142
6930
  const { ctx, name, args, output } = unwrapTsfnPayload(error, payload);
7143
- if (callNativeSync(() => runtime.actorIsLost(ctx))) {
7144
- return output;
7145
- }
7146
6931
  const actorCtx = makeActorCtx(ctx);
7147
6932
  try {
7148
6933
  return encodeValue(
@@ -7211,7 +6996,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7211
6996
  }
7212
6997
  };
7213
6998
  try {
7214
- throwIfActorLost(runtime, ctx);
7215
6999
  const connParams = validateConnParams(
7216
7000
  schemaConfig.connParamsSchema,
7217
7001
  rawConnParams ? JSON.parse(rawConnParams) : void 0
@@ -7246,11 +7030,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7246
7030
  abortRequest
7247
7031
  );
7248
7032
  }
7249
- if (callNativeSync(
7250
- () => runtime.actorIsLost(ctx)
7251
- )) {
7252
- throw actorGenerationLostError();
7253
- }
7254
7033
  const response = await config.onRequest(
7255
7034
  requestCtx,
7256
7035
  handlerRequest
@@ -7323,9 +7102,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7323
7102
  const { ctx } = unwrapTsfnPayload(error, payload);
7324
7103
  const actorId = callNativeSync(() => runtime.actorId(ctx));
7325
7104
  const executeRun = async () => {
7326
- if (callNativeSync(() => runtime.actorIsLost(ctx))) {
7327
- return;
7328
- }
7329
7105
  const actorCtx = makeActorCtx(ctx);
7330
7106
  try {
7331
7107
  await run(actorCtx);
@@ -7339,8 +7115,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7339
7115
  () => callNativeSync(
7340
7116
  () => runtime.actorRestartRunHandler(ctx)
7341
7117
  ),
7342
- executeRun,
7343
- callNativeSync(() => runtime.actorGeneration(ctx))
7118
+ executeRun
7344
7119
  );
7345
7120
  return outcome !== "suppressed";
7346
7121
  }
@@ -7380,16 +7155,14 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7380
7155
  const actorCtx = conn != null ? makeConnCtx(ctx, conn, void 0, cancelToken) : makeActorCtx(ctx, void 0, cancelToken);
7381
7156
  const runAction = async () => {
7382
7157
  try {
7383
- const validatedArgs = validateActionArgs(
7384
- schemaConfig.actionInputSchemas,
7385
- name,
7386
- decodeArgs(args)
7387
- );
7388
- throwIfActorLost(runtime, ctx);
7389
7158
  return encodeValue(
7390
7159
  await handler(
7391
7160
  actorCtx,
7392
- ...validatedArgs,
7161
+ ...validateActionArgs(
7162
+ schemaConfig.actionInputSchemas,
7163
+ name,
7164
+ decodeArgs(args)
7165
+ ),
7393
7166
  ...scheduledFire ? [scheduledFire] : []
7394
7167
  )
7395
7168
  );
@@ -7445,7 +7218,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7445
7218
  if (canPublish && !await canPublish(actorCtx)) {
7446
7219
  throw forbiddenError();
7447
7220
  }
7448
- throwIfActorLost(runtime, ctx);
7449
7221
  const decodedBody = decodeValue(body);
7450
7222
  if (wait) {
7451
7223
  try {
@@ -7489,7 +7261,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
7489
7261
  )
7490
7262
  };
7491
7263
  return runtime.createActorFactory(
7492
- refuseCallbacksAfterLost(runtime, callbacks),
7264
+ callbacks,
7493
7265
  buildActorConfig(definition, registryConfig, runtime.kind)
7494
7266
  );
7495
7267
  }