@rivetkit/engine-runner 2.2.2-rc.1 → 2.3.0-rc.10

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.
package/dist/mod.cjs CHANGED
@@ -513,6 +513,8 @@ function stringifyKvResponseData(data) {
513
513
  }
514
514
 
515
515
  // src/websocket-tunnel-adapter.ts
516
+
517
+
516
518
  var _virtualwebsocket = require('@rivetkit/virtual-websocket');
517
519
  var HIBERNATABLE_SYMBOL = /* @__PURE__ */ Symbol("hibernatable");
518
520
  var WebSocketTunnelAdapter = class {
@@ -570,14 +572,23 @@ var WebSocketTunnelAdapter = class {
570
572
  }
571
573
  messageData = data;
572
574
  } else if (data instanceof ArrayBuffer) {
573
- if (data.byteLength > MAX_PAYLOAD_SIZE) throw new Error("WebSocket message too large");
575
+ if (data.byteLength > MAX_PAYLOAD_SIZE)
576
+ throw new Error("WebSocket message too large");
574
577
  isBinary = true;
575
578
  messageData = data;
576
579
  } else if (ArrayBuffer.isView(data)) {
577
- if (data.byteLength > MAX_PAYLOAD_SIZE) throw new Error("WebSocket message too large");
580
+ if (data.byteLength > MAX_PAYLOAD_SIZE)
581
+ throw new Error("WebSocket message too large");
578
582
  isBinary = true;
579
583
  const view = data;
580
- const buffer = view.buffer instanceof SharedArrayBuffer ? new Uint8Array(view.buffer, view.byteOffset, view.byteLength).slice().buffer : view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength);
584
+ const buffer = view.buffer instanceof SharedArrayBuffer ? new Uint8Array(
585
+ view.buffer,
586
+ view.byteOffset,
587
+ view.byteLength
588
+ ).slice().buffer : view.buffer.slice(
589
+ view.byteOffset,
590
+ view.byteOffset + view.byteLength
591
+ );
581
592
  messageData = buffer;
582
593
  } else {
583
594
  throw new Error("Unsupported data type");
@@ -588,7 +599,11 @@ var WebSocketTunnelAdapter = class {
588
599
  _handleOpen(requestId) {
589
600
  if (this.#readyState !== 0) return;
590
601
  this.#readyState = 1;
591
- this.#ws.dispatchEvent({ type: "open", rivetRequestId: requestId, target: this.#ws });
602
+ this.#ws.dispatchEvent({
603
+ type: "open",
604
+ rivetRequestId: requestId,
605
+ target: this.#ws
606
+ });
592
607
  }
593
608
  // Called by Tunnel when message is received
594
609
  _handleMessage(requestId, data, serverMessageIndex, isBinary) {
@@ -625,7 +640,10 @@ var WebSocketTunnelAdapter = class {
625
640
  expectedIndex,
626
641
  receivedIndex: serverMessageIndex,
627
642
  closeReason,
628
- gap: wrappingSubU16(wrappingSubU16(serverMessageIndex, previousIndex), 1)
643
+ gap: wrappingSubU16(
644
+ wrappingSubU16(serverMessageIndex, previousIndex),
645
+ 1
646
+ )
629
647
  });
630
648
  this.#close(1008, closeReason, true);
631
649
  return true;
@@ -637,7 +655,10 @@ var WebSocketTunnelAdapter = class {
637
655
  if (this.#binaryType === "nodebuffer") {
638
656
  messageData = Buffer.from(data);
639
657
  } else if (this.#binaryType === "arraybuffer") {
640
- messageData = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
658
+ messageData = data.buffer.slice(
659
+ data.byteOffset,
660
+ data.byteOffset + data.byteLength
661
+ );
641
662
  }
642
663
  }
643
664
  this.#ws.dispatchEvent({
@@ -1516,8 +1537,6 @@ async function importWebSocket() {
1516
1537
  }
1517
1538
 
1518
1539
  // src/mod.ts
1519
-
1520
-
1521
1540
  var _uuid = require('uuid');
1522
1541
  var KV_EXPIRE = 3e4;
1523
1542
  var PROTOCOL_VERSION = 7;
@@ -1593,7 +1612,6 @@ var Runner = class {
1593
1612
  sleepActor(actorId, generation) {
1594
1613
  const actor = this.getActor(actorId, generation);
1595
1614
  if (!actor) return;
1596
- actor.stopIntentSent = true;
1597
1615
  this.#sendActorIntent(actorId, actor.generation, "sleep");
1598
1616
  }
1599
1617
  async stopActor(actorId, generation) {
@@ -1797,9 +1815,12 @@ var Runner = class {
1797
1815
  );
1798
1816
  }
1799
1817
  this.#kvRequests.clear();
1800
- const pegboardWebSocket = this.getPegboardWebSocketIfReady();
1801
- if (pegboardWebSocket) {
1802
- if (immediate) {
1818
+ const pegboardWebSocket = this.#pegboardWebSocket;
1819
+ const readyState = pegboardWebSocket == null ? void 0 : pegboardWebSocket.readyState;
1820
+ const isOpen = readyState === 1;
1821
+ const isConnecting = readyState === 0;
1822
+ if (pegboardWebSocket && (isOpen || isConnecting)) {
1823
+ if (immediate || isConnecting) {
1803
1824
  pegboardWebSocket.close(1e3, "pegboard.runner_shutdown");
1804
1825
  } else {
1805
1826
  try {
@@ -2054,6 +2075,7 @@ var Runner = class {
2054
2075
  const init = message.val;
2055
2076
  if (this.runnerId !== init.runnerId) {
2056
2077
  this.runnerId = init.runnerId;
2078
+ this.#logCached = void 0;
2057
2079
  this.#stopAllActors();
2058
2080
  }
2059
2081
  this.#protocolMetadata = init.metadata;
@@ -2298,8 +2320,6 @@ var Runner = class {
2298
2320
  const stopCommand = commandWrapper.inner.val;
2299
2321
  const actorId = commandWrapper.checkpoint.actorId;
2300
2322
  const generation = commandWrapper.checkpoint.generation;
2301
- const actor = this.getActor(actorId, generation);
2302
- if (actor) actor.stopIntentSent = true;
2303
2323
  await this.forceStopActor(actorId, generation);
2304
2324
  }
2305
2325
  #sendActorIntent(actorId, generation, intentType) {