@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.
- package/dist/agent/index.cjs +23 -0
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.js +23 -0
- package/dist/agent/index.js.map +1 -1
- package/package.json +1 -1
package/dist/agent/index.cjs
CHANGED
|
@@ -361,6 +361,7 @@ function createPipelineLogger(parent) {
|
|
|
361
361
|
// src/agent/control-ws.ts
|
|
362
362
|
var INITIAL_RECONNECT_DELAY = 1e3;
|
|
363
363
|
var MAX_RECONNECT_DELAY = 3e4;
|
|
364
|
+
var PING_TIMEOUT = 6e4;
|
|
364
365
|
function buildControlWsUrl(options) {
|
|
365
366
|
const scheme = options.baseUrl.startsWith("https") ? "wss" : "ws";
|
|
366
367
|
const host = options.baseUrl.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
@@ -386,6 +387,7 @@ var ControlWebSocket = class {
|
|
|
386
387
|
_connectedResolve = null;
|
|
387
388
|
_connectedPromise;
|
|
388
389
|
_log = NOOP_LOGGER;
|
|
390
|
+
_pingTimer = null;
|
|
389
391
|
setLogger(logger) {
|
|
390
392
|
this._log = logger;
|
|
391
393
|
}
|
|
@@ -416,6 +418,7 @@ var ControlWebSocket = class {
|
|
|
416
418
|
/** Close the WebSocket and stop reconnecting. */
|
|
417
419
|
close() {
|
|
418
420
|
this._closed = true;
|
|
421
|
+
this._clearPingTimer();
|
|
419
422
|
if (this._ws) {
|
|
420
423
|
this._ws.close();
|
|
421
424
|
this._ws = null;
|
|
@@ -432,12 +435,16 @@ var ControlWebSocket = class {
|
|
|
432
435
|
this._ws = ws;
|
|
433
436
|
ws.on("open", () => {
|
|
434
437
|
this._reconnectDelay = INITIAL_RECONNECT_DELAY;
|
|
438
|
+
this._resetPingTimer();
|
|
435
439
|
if (this._connectedResolve) {
|
|
436
440
|
this._connectedResolve();
|
|
437
441
|
this._connectedResolve = null;
|
|
438
442
|
}
|
|
439
443
|
this._log.info("Control WS connected: %s", this._url);
|
|
440
444
|
});
|
|
445
|
+
ws.on("ping", () => {
|
|
446
|
+
this._resetPingTimer();
|
|
447
|
+
});
|
|
441
448
|
ws.on("message", (data) => {
|
|
442
449
|
try {
|
|
443
450
|
const msg = JSON.parse(data.toString());
|
|
@@ -447,6 +454,7 @@ var ControlWebSocket = class {
|
|
|
447
454
|
}
|
|
448
455
|
});
|
|
449
456
|
ws.on("close", () => {
|
|
457
|
+
this._clearPingTimer();
|
|
450
458
|
if (!this._closed) {
|
|
451
459
|
this._scheduleReconnect();
|
|
452
460
|
}
|
|
@@ -472,6 +480,21 @@ var ControlWebSocket = class {
|
|
|
472
480
|
}
|
|
473
481
|
}
|
|
474
482
|
}
|
|
483
|
+
_resetPingTimer() {
|
|
484
|
+
this._clearPingTimer();
|
|
485
|
+
this._pingTimer = setTimeout(() => {
|
|
486
|
+
this._log.warn("Control WS ping timeout, closing connection");
|
|
487
|
+
if (this._ws) {
|
|
488
|
+
this._ws.terminate();
|
|
489
|
+
}
|
|
490
|
+
}, PING_TIMEOUT);
|
|
491
|
+
}
|
|
492
|
+
_clearPingTimer() {
|
|
493
|
+
if (this._pingTimer) {
|
|
494
|
+
clearTimeout(this._pingTimer);
|
|
495
|
+
this._pingTimer = null;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
475
498
|
_scheduleReconnect() {
|
|
476
499
|
const delay = this._reconnectDelay;
|
|
477
500
|
this._reconnectDelay = Math.min(this._reconnectDelay * 2, MAX_RECONNECT_DELAY);
|