@teamlearners/clawops 0.5.4 → 0.5.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.
@@ -335,6 +335,7 @@ function createPipelineLogger(parent) {
335
335
  // src/agent/control-ws.ts
336
336
  var INITIAL_RECONNECT_DELAY = 1e3;
337
337
  var MAX_RECONNECT_DELAY = 3e4;
338
+ var PING_TIMEOUT = 6e4;
338
339
  function buildControlWsUrl(options) {
339
340
  const scheme = options.baseUrl.startsWith("https") ? "wss" : "ws";
340
341
  const host = options.baseUrl.replace(/^https?:\/\//, "").replace(/\/$/, "");
@@ -360,6 +361,7 @@ var ControlWebSocket = class {
360
361
  _connectedResolve = null;
361
362
  _connectedPromise;
362
363
  _log = NOOP_LOGGER;
364
+ _pingTimer = null;
363
365
  setLogger(logger) {
364
366
  this._log = logger;
365
367
  }
@@ -390,6 +392,7 @@ var ControlWebSocket = class {
390
392
  /** Close the WebSocket and stop reconnecting. */
391
393
  close() {
392
394
  this._closed = true;
395
+ this._clearPingTimer();
393
396
  if (this._ws) {
394
397
  this._ws.close();
395
398
  this._ws = null;
@@ -406,12 +409,16 @@ var ControlWebSocket = class {
406
409
  this._ws = ws;
407
410
  ws.on("open", () => {
408
411
  this._reconnectDelay = INITIAL_RECONNECT_DELAY;
412
+ this._resetPingTimer();
409
413
  if (this._connectedResolve) {
410
414
  this._connectedResolve();
411
415
  this._connectedResolve = null;
412
416
  }
413
417
  this._log.info("Control WS connected: %s", this._url);
414
418
  });
419
+ ws.on("ping", () => {
420
+ this._resetPingTimer();
421
+ });
415
422
  ws.on("message", (data) => {
416
423
  try {
417
424
  const msg = JSON.parse(data.toString());
@@ -421,6 +428,7 @@ var ControlWebSocket = class {
421
428
  }
422
429
  });
423
430
  ws.on("close", () => {
431
+ this._clearPingTimer();
424
432
  if (!this._closed) {
425
433
  this._scheduleReconnect();
426
434
  }
@@ -446,6 +454,21 @@ var ControlWebSocket = class {
446
454
  }
447
455
  }
448
456
  }
457
+ _resetPingTimer() {
458
+ this._clearPingTimer();
459
+ this._pingTimer = setTimeout(() => {
460
+ this._log.warn("Control WS ping timeout, closing connection");
461
+ if (this._ws) {
462
+ this._ws.terminate();
463
+ }
464
+ }, PING_TIMEOUT);
465
+ }
466
+ _clearPingTimer() {
467
+ if (this._pingTimer) {
468
+ clearTimeout(this._pingTimer);
469
+ this._pingTimer = null;
470
+ }
471
+ }
449
472
  _scheduleReconnect() {
450
473
  const delay = this._reconnectDelay;
451
474
  this._reconnectDelay = Math.min(this._reconnectDelay * 2, MAX_RECONNECT_DELAY);