@attson/atwebpilot-mcp 0.0.23 → 0.0.25

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 (2) hide show
  1. package/dist/index.js +32 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -771,10 +771,12 @@ var Coordinator = class {
771
771
  // src/loopback-ws-hub.ts
772
772
  import { WebSocketServer, WebSocket } from "ws";
773
773
  var HEARTBEAT_INTERVAL_MS = 2e4;
774
+ var DEFAULT_KEEPALIVE_INTERVAL_MS = 15e3;
774
775
  var LoopbackWSHub = class {
775
776
  constructor(opts) {
776
777
  this.opts = opts;
777
778
  this.execTimeoutMs = opts.execTimeoutMs ?? 3e4;
779
+ this.keepaliveIntervalMs = opts.keepaliveIntervalMs ?? DEFAULT_KEEPALIVE_INTERVAL_MS;
778
780
  this.wss = new WebSocketServer({
779
781
  port: opts.port,
780
782
  path: "/worker",
@@ -790,6 +792,8 @@ var LoopbackWSHub = class {
790
792
  msgHandlers = [];
791
793
  disconnectHandlers = [];
792
794
  execTimeoutMs;
795
+ keepaliveIntervalMs;
796
+ keepaliveTimers = /* @__PURE__ */ new Map();
793
797
  ready() {
794
798
  return new Promise((resolve) => {
795
799
  const addr = this.wss.address();
@@ -806,6 +810,8 @@ var LoopbackWSHub = class {
806
810
  p.reject(new Error("hub closing"));
807
811
  }
808
812
  this.pending.clear();
813
+ for (const timer of this.keepaliveTimers.values()) clearInterval(timer);
814
+ this.keepaliveTimers.clear();
809
815
  for (const socket of this.wss.clients) {
810
816
  socket.terminate();
811
817
  }
@@ -859,6 +865,7 @@ var LoopbackWSHub = class {
859
865
  server_time: this.opts.clock.now(),
860
866
  heartbeat_interval_ms: HEARTBEAT_INTERVAL_MS
861
867
  });
868
+ this.startKeepalive(socket);
862
869
  for (const h of this.msgHandlers) h(msg.worker_id, msg);
863
870
  return;
864
871
  }
@@ -886,6 +893,7 @@ var LoopbackWSHub = class {
886
893
  }
887
894
  }
888
895
  onSocketClose(socket) {
896
+ this.stopKeepalive(socket);
889
897
  const wid = this.workerOf.get(socket);
890
898
  if (!wid) return;
891
899
  this.workerOf.delete(socket);
@@ -899,6 +907,30 @@ var LoopbackWSHub = class {
899
907
  }
900
908
  for (const h of this.disconnectHandlers) h(wid);
901
909
  }
910
+ startKeepalive(socket) {
911
+ if (this.keepaliveIntervalMs <= 0) return;
912
+ if (this.keepaliveTimers.has(socket)) return;
913
+ const timer = setInterval(() => {
914
+ if (socket.readyState !== WebSocket.OPEN) return;
915
+ this.rawSend(socket, {
916
+ type: "PONG",
917
+ nonce: this.opts.idGen.next("nonce"),
918
+ ts: this.opts.clock.now(),
919
+ protocol_version: PROTOCOL_VERSION,
920
+ echo_nonce: "server-keepalive"
921
+ });
922
+ }, this.keepaliveIntervalMs);
923
+ if (typeof timer.unref === "function") {
924
+ timer.unref();
925
+ }
926
+ this.keepaliveTimers.set(socket, timer);
927
+ }
928
+ stopKeepalive(socket) {
929
+ const timer = this.keepaliveTimers.get(socket);
930
+ if (!timer) return;
931
+ clearInterval(timer);
932
+ this.keepaliveTimers.delete(socket);
933
+ }
902
934
  rawSend(socket, msg) {
903
935
  const r = ServerToClientSchema.safeParse(msg);
904
936
  if (!r.success) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attson/atwebpilot-mcp",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "license": "Apache-2.0",
5
5
  "description": "MCP server for the atwebpilot browser extension — let Claude Code drive your browser.",
6
6
  "homepage": "https://github.com/attson/atwebpilot#readme",