rivetkit 3.0.0-preview.3 → 3.0.0-preview.5

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 (68) hide show
  1. package/dist/browser/client.js +49 -28
  2. package/dist/browser/client.js.map +1 -1
  3. package/dist/browser/inspector/client.js +1 -1
  4. package/dist/browser/inspector/client.js.map +1 -1
  5. package/dist/tsup/{chunk-KCWRKXTY.js → chunk-AW7C2XT5.js} +2 -2
  6. package/dist/tsup/{chunk-JWI6YJEA.js → chunk-BAXQGOBL.js} +2 -2
  7. package/dist/tsup/{chunk-4WDX5ZI7.cjs → chunk-CFGRIV62.cjs} +2 -2
  8. package/dist/tsup/{chunk-4WDX5ZI7.cjs.map → chunk-CFGRIV62.cjs.map} +1 -1
  9. package/dist/tsup/{chunk-7KES6QNE.cjs → chunk-CLY73DEM.cjs} +3 -3
  10. package/dist/tsup/{chunk-7KES6QNE.cjs.map → chunk-CLY73DEM.cjs.map} +1 -1
  11. package/dist/tsup/{chunk-KMYBA4P5.cjs → chunk-EON5X6B7.cjs} +3 -3
  12. package/dist/tsup/{chunk-KMYBA4P5.cjs.map → chunk-EON5X6B7.cjs.map} +1 -1
  13. package/dist/tsup/{chunk-2VXPVVNW.js → chunk-EOUH7MP7.js} +54 -33
  14. package/dist/tsup/chunk-EOUH7MP7.js.map +1 -0
  15. package/dist/tsup/{chunk-BCX5V7NI.cjs → chunk-GJUWI47D.cjs} +191 -170
  16. package/dist/tsup/chunk-GJUWI47D.cjs.map +1 -0
  17. package/dist/tsup/{chunk-PJ4PORWE.cjs → chunk-KEHBPXZE.cjs} +3 -3
  18. package/dist/tsup/{chunk-PJ4PORWE.cjs.map → chunk-KEHBPXZE.cjs.map} +1 -1
  19. package/dist/tsup/{chunk-HDQQVBOG.js → chunk-KJM23DKG.js} +2 -2
  20. package/dist/tsup/{chunk-JXO5QVDX.js → chunk-KKSIGBUN.js} +2 -2
  21. package/dist/tsup/{chunk-JXO5QVDX.js.map → chunk-KKSIGBUN.js.map} +1 -1
  22. package/dist/tsup/{chunk-HRBZ4VW5.cjs → chunk-MVDTFTCY.cjs} +7 -7
  23. package/dist/tsup/{chunk-HRBZ4VW5.cjs.map → chunk-MVDTFTCY.cjs.map} +1 -1
  24. package/dist/tsup/{chunk-B6U5V6WE.cjs → chunk-PHFXQQGE.cjs} +4 -4
  25. package/dist/tsup/{chunk-B6U5V6WE.cjs.map → chunk-PHFXQQGE.cjs.map} +1 -1
  26. package/dist/tsup/{chunk-A447S5YG.js → chunk-SJUGJ5DT.js} +2 -2
  27. package/dist/tsup/{chunk-AGQNNAZ2.js → chunk-W4CGRSYM.js} +3 -3
  28. package/dist/tsup/{chunk-IJGFSNGA.js → chunk-W5DDGJBO.js} +4 -4
  29. package/dist/tsup/{chunk-7Y4GHUAT.cjs → chunk-ZOFNA4SR.cjs} +10 -10
  30. package/dist/tsup/{chunk-7Y4GHUAT.cjs.map → chunk-ZOFNA4SR.cjs.map} +1 -1
  31. package/dist/tsup/client/mod.cjs +5 -5
  32. package/dist/tsup/client/mod.js +4 -4
  33. package/dist/tsup/common/log.cjs +2 -2
  34. package/dist/tsup/common/log.js +1 -1
  35. package/dist/tsup/common/websocket.cjs +3 -3
  36. package/dist/tsup/common/websocket.js +2 -2
  37. package/dist/tsup/db/drizzle.cjs +2 -2
  38. package/dist/tsup/db/drizzle.js +1 -1
  39. package/dist/tsup/db/mod.cjs +3 -3
  40. package/dist/tsup/db/mod.js +2 -2
  41. package/dist/tsup/inspector/mod.cjs +5 -5
  42. package/dist/tsup/inspector/mod.js +4 -4
  43. package/dist/tsup/inspector/workflow.cjs +4 -4
  44. package/dist/tsup/inspector/workflow.js +3 -3
  45. package/dist/tsup/mod.cjs +94 -90
  46. package/dist/tsup/mod.cjs.map +1 -1
  47. package/dist/tsup/mod.js +15 -11
  48. package/dist/tsup/mod.js.map +1 -1
  49. package/dist/tsup/test/mod.cjs +6 -6
  50. package/dist/tsup/test/mod.js +4 -4
  51. package/dist/tsup/utils.cjs +2 -2
  52. package/dist/tsup/utils.js +1 -1
  53. package/dist/tsup/workflow/mod.cjs +7 -7
  54. package/dist/tsup/workflow/mod.cjs.map +1 -1
  55. package/dist/tsup/workflow/mod.js +4 -4
  56. package/package.json +9 -9
  57. package/src/client/actor-conn.ts +59 -33
  58. package/src/client/lifecycle-errors.ts +13 -0
  59. package/src/registry/config/index.ts +2 -1
  60. package/src/registry/index.ts +16 -3
  61. package/dist/tsup/chunk-2VXPVVNW.js.map +0 -1
  62. package/dist/tsup/chunk-BCX5V7NI.cjs.map +0 -1
  63. /package/dist/tsup/{chunk-KCWRKXTY.js.map → chunk-AW7C2XT5.js.map} +0 -0
  64. /package/dist/tsup/{chunk-JWI6YJEA.js.map → chunk-BAXQGOBL.js.map} +0 -0
  65. /package/dist/tsup/{chunk-HDQQVBOG.js.map → chunk-KJM23DKG.js.map} +0 -0
  66. /package/dist/tsup/{chunk-A447S5YG.js.map → chunk-SJUGJ5DT.js.map} +0 -0
  67. /package/dist/tsup/{chunk-AGQNNAZ2.js.map → chunk-W4CGRSYM.js.map} +0 -0
  68. /package/dist/tsup/{chunk-IJGFSNGA.js.map → chunk-W5DDGJBO.js.map} +0 -0
@@ -230,7 +230,7 @@ function noopNext() {
230
230
  // package.json
231
231
  var package_default = {
232
232
  name: "rivetkit",
233
- version: "3.0.0-preview.3",
233
+ version: "3.0.0-preview.5",
234
234
  description: "Lightweight libraries for building stateful actors on edge platforms",
235
235
  license: "Apache-2.0",
236
236
  keywords: [
@@ -4934,6 +4934,14 @@ function classifyActorError(error) {
4934
4934
  }
4935
4935
  );
4936
4936
  }
4937
+ if (error.group === "ups" && error.code === "consumer_closed" || error.group === "depot" && error.code === "request_deadline_exceeded") {
4938
+ return buildLifecycleBoundaryInfo(
4939
+ "reconnect_only",
4940
+ "actor_error",
4941
+ error.message,
4942
+ { group: error.group, code: error.code }
4943
+ );
4944
+ }
4937
4945
  if (error.group === "guard" && isRetryableGuardGatewayHttpError(error.code)) {
4938
4946
  return buildLifecycleBoundaryInfo(
4939
4947
  "request_retry",
@@ -5254,6 +5262,8 @@ var ActorConnRaw = class {
5254
5262
  /* Will be aborted on dispose. */
5255
5263
  #abortController = new AbortController();
5256
5264
  #connStatus = "idle";
5265
+ /** The opening failure that stopped retries. Later actions must fail instead of queueing. */
5266
+ #connectionOpenError;
5257
5267
  #actorId;
5258
5268
  #connId;
5259
5269
  #messageQueue = [];
@@ -5372,6 +5382,8 @@ var ActorConnRaw = class {
5372
5382
  `Invalid action call: expected an options object { name, args }, got ${typeof opts}. Use conn.actionName(...args) for the shorthand API.`
5373
5383
  );
5374
5384
  }
5385
+ if (this.#disposed) throw new ActorConnDisposed();
5386
+ if (this.#connectionOpenError) throw this.#connectionOpenError;
5375
5387
  logger2().debug({ msg: "action", name: opts.name, args: opts.args });
5376
5388
  const actionId = this.#actionIdCounter;
5377
5389
  this.#actionIdCounter += 1;
@@ -5459,6 +5471,7 @@ var ActorConnRaw = class {
5459
5471
  }
5460
5472
  }
5461
5473
  #connectWithRetry() {
5474
+ this.#connectionOpenError = void 0;
5462
5475
  this.#setConnStatus("connecting");
5463
5476
  pRetry2(this.#connectAndWait.bind(this), {
5464
5477
  forever: true,
@@ -5501,6 +5514,9 @@ var ActorConnRaw = class {
5501
5514
  await this.#connectWebSocket();
5502
5515
  await this.#waitForOpen(this.#onOpenPromise.promise);
5503
5516
  } catch (error) {
5517
+ this.#abandonCurrentSocket(
5518
+ isConnectionOpenTimeout(error) ? "Connect timeout" : "Connection opening failed"
5519
+ );
5504
5520
  if (this.#shouldRetryConnectionOpenError(error)) {
5505
5521
  throw error;
5506
5522
  }
@@ -5510,7 +5526,7 @@ var ActorConnRaw = class {
5510
5526
  `Failed to open connection: ${stringifyError(error)}`,
5511
5527
  { error: stringifyError(error) }
5512
5528
  );
5513
- this.#clearQueuedMessages();
5529
+ this.#connectionOpenError = actorError;
5514
5530
  this.#rejectPendingPromises(actorError, false);
5515
5531
  this.#dispatchActorError(actorError);
5516
5532
  this.#setConnStatus("idle");
@@ -5542,28 +5558,23 @@ var ActorConnRaw = class {
5542
5558
  });
5543
5559
  try {
5544
5560
  await Promise.race([open, timedOut]);
5545
- } catch (error) {
5546
- if (isConnectionOpenTimeout(error)) {
5547
- this.#abandonCurrentSocket();
5548
- }
5549
- throw error;
5550
5561
  } finally {
5551
5562
  clearTimeout(timer);
5552
5563
  }
5553
5564
  }
5554
- #abandonCurrentSocket() {
5565
+ #abandonCurrentSocket(reason) {
5555
5566
  const ws = this.#websocket;
5556
5567
  if (!ws) return;
5557
5568
  this.#websocket = void 0;
5558
5569
  this.#abandonedSockets.add(ws);
5559
- logger2().warn({
5560
- msg: "connection did not open in time, retrying",
5570
+ logger2().debug({
5571
+ msg: "closing failed connection attempt",
5561
5572
  connId: this.#connId,
5562
5573
  readyState: ws.readyState,
5563
- timeoutMs: CONNECT_TIMEOUT_MS
5574
+ reason
5564
5575
  });
5565
5576
  try {
5566
- ws.close(1e3, "Connect timeout");
5577
+ ws.close(1e3, reason);
5567
5578
  } catch (err) {
5568
5579
  logger2().debug({
5569
5580
  msg: "failed to close abandoned websocket",
@@ -5578,6 +5589,9 @@ var ActorConnRaw = class {
5578
5589
  if (isConnectionOpenTimeout(error)) {
5579
5590
  return true;
5580
5591
  }
5592
+ if (error instanceof RivetError && error.group === "client" && error.code === "connection_open_interrupted") {
5593
+ return true;
5594
+ }
5581
5595
  if (error instanceof RivetError && isInvalidToken(error.group, error.code) && this.#driver.refreshAuthToken && this.#authRetryAvailable) {
5582
5596
  this.#authRetryAvailable = false;
5583
5597
  return true;
@@ -5637,16 +5651,18 @@ var ActorConnRaw = class {
5637
5651
  });
5638
5652
  this.#websocket = ws;
5639
5653
  ws.addEventListener("open", () => {
5640
- if (this.#abandonedSockets.has(ws)) return;
5654
+ if (this.#websocket !== ws || this.#abandonedSockets.has(ws))
5655
+ return;
5641
5656
  logger2().debug({
5642
5657
  msg: "client websocket open",
5643
5658
  connId: this.#connId
5644
5659
  });
5645
5660
  });
5646
5661
  ws.addEventListener("message", async (ev) => {
5647
- if (this.#abandonedSockets.has(ws)) return;
5662
+ if (this.#websocket !== ws || this.#abandonedSockets.has(ws))
5663
+ return;
5648
5664
  try {
5649
- await this.#handleOnMessage(ev.data);
5665
+ await this.#handleOnMessage(ev.data, ws);
5650
5666
  } catch (err) {
5651
5667
  logger2().error({
5652
5668
  msg: "error in websocket message handler",
@@ -5655,7 +5671,8 @@ var ActorConnRaw = class {
5655
5671
  }
5656
5672
  });
5657
5673
  ws.addEventListener("close", async (ev) => {
5658
- if (this.#abandonedSockets.has(ws)) return;
5674
+ if (this.#websocket !== ws || this.#abandonedSockets.has(ws))
5675
+ return;
5659
5676
  try {
5660
5677
  await this.#handleOnClose(ev);
5661
5678
  } catch (err) {
@@ -5666,7 +5683,8 @@ var ActorConnRaw = class {
5666
5683
  }
5667
5684
  });
5668
5685
  ws.addEventListener("error", () => {
5669
- if (this.#abandonedSockets.has(ws)) return;
5686
+ if (this.#websocket !== ws || this.#abandonedSockets.has(ws))
5687
+ return;
5670
5688
  try {
5671
5689
  this.#handleOnError();
5672
5690
  } catch (err) {
@@ -5732,7 +5750,7 @@ var ActorConnRaw = class {
5732
5750
  });
5733
5751
  }
5734
5752
  /** Called by the onmessage event from drivers. */
5735
- async #handleOnMessage(data) {
5753
+ async #handleOnMessage(data, socket) {
5736
5754
  logger2().trace({
5737
5755
  msg: "received message",
5738
5756
  dataType: typeof data,
@@ -5740,6 +5758,8 @@ var ActorConnRaw = class {
5740
5758
  isArrayBuffer: data instanceof ArrayBuffer
5741
5759
  });
5742
5760
  const response = await this.#parseMessage(data);
5761
+ if (this.#websocket !== socket || this.#abandonedSockets.has(socket))
5762
+ return;
5743
5763
  logger2().trace(
5744
5764
  getLogMessage() ? {
5745
5765
  msg: "parsed message",
@@ -5811,18 +5831,15 @@ var ActorConnRaw = class {
5811
5831
  this.#actorResolutionState,
5812
5832
  this.#driver
5813
5833
  );
5834
+ if (this.#websocket !== socket || this.#abandonedSockets.has(socket)) {
5835
+ return;
5836
+ }
5814
5837
  if (schedulingError) {
5815
5838
  errorToThrow = schedulingError;
5816
5839
  }
5817
5840
  }
5818
- if (this.#onOpenPromise) {
5819
- this.#onOpenPromise.reject(errorToThrow);
5820
- }
5821
5841
  this.#invalidateActorIfStale(group, code);
5822
- for (const [id, inFlight] of this.#actionsInFlight.entries()) {
5823
- inFlight.reject(errorToThrow);
5824
- this.#actionsInFlight.delete(id);
5825
- }
5842
+ this.#rejectPendingPromises(errorToThrow, false);
5826
5843
  this.#dispatchActorError(errorToThrow);
5827
5844
  }
5828
5845
  } else if (response.body.tag === "ActionResponse") {
@@ -5930,9 +5947,12 @@ var ActorConnRaw = class {
5930
5947
  }
5931
5948
  this.#invalidateActorIfStale(group, code);
5932
5949
  } else {
5933
- error = new Error(
5934
- `${wasClean ? "Connection closed" : "Connection lost"} (code: ${closeEvent.code}, reason: ${reason})`
5935
- );
5950
+ const message = `${wasClean ? "Connection closed" : "Connection lost"} (code: ${closeEvent.code}, reason: ${reason})`;
5951
+ error = !wasConnected && closeEvent.code === 1006 ? new RivetError(
5952
+ "client",
5953
+ "connection_open_interrupted",
5954
+ message
5955
+ ) : new Error(message);
5936
5956
  }
5937
5957
  this.#rejectPendingPromises(error, false);
5938
5958
  if (error instanceof RivetError) {
@@ -5948,6 +5968,7 @@ var ActorConnRaw = class {
5948
5968
  }
5949
5969
  }
5950
5970
  #rejectPendingPromises(error, suppressUnhandled) {
5971
+ this.#clearQueuedMessages();
5951
5972
  if (this.#onOpenPromise) {
5952
5973
  if (suppressUnhandled) {
5953
5974
  this.#onOpenPromise.promise.catch(() => {