@agentconnect.md/daemon 1.0.0-rc.183 → 1.0.0-rc.185

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/index.js CHANGED
@@ -22259,6 +22259,37 @@ var wrapper_default = import_websocket.default;
22259
22259
  const SUBPROTOCOL = "agentconnect.v1";
22260
22260
  const DEFAULT_WS_PATH = "/daemon/ws";
22261
22261
  const HANDSHAKE_TIMEOUT_MS = 1e4;
22262
+ const SELF_PING_MS = 15e3;
22263
+ const RX_IDLE_MS = 45e3;
22264
+ /**
22265
+ * Arm a receive-idle watchdog on an open socket: every `selfPingMs` send a ping
22266
+ * (the peer auto-pongs, which counts as inbound), and if NOTHING has arrived for
22267
+ * `idleMs`, `terminate()` the socket — routing a dead half-open connection into
22268
+ * the normal `close` → reconnect path. Any inbound frame (message/ping/pong)
22269
+ * resets the idle clock. Cleared on `close`. Kept off the FSM's injected Clock
22270
+ * so it never perturbs the fake-clock CpClient tests.
22271
+ */
22272
+ function armRxWatchdog(ws, opts) {
22273
+ const now = opts.now ?? (() => Date.now());
22274
+ const setIv = opts.setInterval ?? ((fn, ms) => globalThis.setInterval(fn, ms));
22275
+ const clearIv = opts.clearInterval ?? ((h) => globalThis.clearInterval(h));
22276
+ let lastRx = now();
22277
+ const touch = () => {
22278
+ lastRx = now();
22279
+ };
22280
+ ws.on("message", touch);
22281
+ ws.on("ping", touch);
22282
+ ws.on("pong", touch);
22283
+ const timer = setIv(() => {
22284
+ if (now() - lastRx > opts.idleMs) {
22285
+ ws.terminate();
22286
+ return;
22287
+ }
22288
+ if (ws.readyState === ws.OPEN) ws.ping();
22289
+ }, opts.selfPingMs);
22290
+ if (typeof timer.unref === "function") timer.unref();
22291
+ ws.on("close", () => clearIv(timer));
22292
+ }
22262
22293
  var ClientTransport = class ClientTransport {
22263
22294
  ws;
22264
22295
  get subprotocol() {
@@ -22266,6 +22297,10 @@ var ClientTransport = class ClientTransport {
22266
22297
  }
22267
22298
  constructor(ws) {
22268
22299
  this.ws = ws;
22300
+ armRxWatchdog(ws, {
22301
+ selfPingMs: SELF_PING_MS,
22302
+ idleMs: RX_IDLE_MS
22303
+ });
22269
22304
  }
22270
22305
  /**
22271
22306
  * Dial `wss://<host>/daemon/ws` with the `agentconnect.v1` subprotocol.