squad-openclaw 2026.2.2009 → 2026.2.2011

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 +56 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1309,7 +1309,7 @@ function registerVersionMethods(api) {
1309
1309
  }
1310
1310
  try {
1311
1311
  updateOutput = execSync2(
1312
- `openclaw plugins install ${PACKAGE_NAME} 2>&1`,
1312
+ `openclaw plugins update ${PACKAGE_NAME} 2>&1`,
1313
1313
  { timeout: 12e4, encoding: "utf-8" }
1314
1314
  );
1315
1315
  } catch (installErr) {
@@ -1508,6 +1508,25 @@ function readOperatorToken() {
1508
1508
  return null;
1509
1509
  }
1510
1510
  }
1511
+ function readGatewayLocalWsConfig() {
1512
+ const defaults = {
1513
+ port: 18789,
1514
+ // Try IPv4, hostname, then IPv6 loopback.
1515
+ hosts: ["127.0.0.1", "localhost", "[::1]"]
1516
+ };
1517
+ const stateDir = getOpenclawStateDir();
1518
+ const configPath = path8.join(stateDir, "openclaw.json");
1519
+ try {
1520
+ const raw = fs7.readFileSync(configPath, "utf-8");
1521
+ const config = JSON.parse(raw);
1522
+ const parsedPort = Number(config?.gateway?.port);
1523
+ if (Number.isFinite(parsedPort) && parsedPort > 0) {
1524
+ defaults.port = parsedPort;
1525
+ }
1526
+ } catch {
1527
+ }
1528
+ return defaults;
1529
+ }
1511
1530
  function signDeviceIdentity(keys, clientId, clientMode, role, scopes, token, challengeNonce) {
1512
1531
  const signedAtMs = Date.now();
1513
1532
  const nonce = challengeNonce || crypto3.randomBytes(16).toString("hex");
@@ -1527,6 +1546,7 @@ var RelayClient = class {
1527
1546
  config;
1528
1547
  relayWs = null;
1529
1548
  userConnections = /* @__PURE__ */ new Map();
1549
+ localConnectAttempts = /* @__PURE__ */ new Map();
1530
1550
  reconnectAttempts = 0;
1531
1551
  maxReconnectAttempts = 100;
1532
1552
  reconnectTimer = null;
@@ -1538,9 +1558,11 @@ var RelayClient = class {
1538
1558
  deviceKeys;
1539
1559
  constructor(config) {
1540
1560
  const state = readRelayState();
1561
+ const localWs = readGatewayLocalWsConfig();
1541
1562
  this.config = {
1542
1563
  relayUrl: config.relayUrl,
1543
- localGatewayPort: config.localGatewayPort ?? 18789,
1564
+ localGatewayPort: config.localGatewayPort ?? localWs.port,
1565
+ localGatewayHosts: config.localGatewayHosts ?? localWs.hosts,
1544
1566
  operatorToken: config.operatorToken ?? readOperatorToken(),
1545
1567
  claimToken: config.claimToken ?? state.claimToken ?? null,
1546
1568
  roomId: config.roomId ?? state.roomId ?? null
@@ -1815,7 +1837,7 @@ var RelayClient = class {
1815
1837
  console.log(`[relay-client] Injected device identity for ${conn.userId}: nonce=${conn.challengeNonce?.substring(0, 12)}...`);
1816
1838
  }
1817
1839
  /** Create a local WS connection to the gateway for a specific user */
1818
- createUserConnection(userId) {
1840
+ createUserConnection(userId, carry) {
1819
1841
  const existing = this.userConnections.get(userId);
1820
1842
  if (existing) {
1821
1843
  try {
@@ -1823,21 +1845,24 @@ var RelayClient = class {
1823
1845
  } catch {
1824
1846
  }
1825
1847
  }
1826
- const localUrl = `ws://127.0.0.1:${this.config.localGatewayPort}`;
1848
+ const attempt = this.localConnectAttempts.get(userId) ?? 0;
1849
+ const host = this.config.localGatewayHosts[attempt % this.config.localGatewayHosts.length];
1850
+ const localUrl = `ws://${host}:${this.config.localGatewayPort}`;
1827
1851
  console.log(`[relay-client] Creating local WS for user ${userId} \u2192 ${localUrl}`);
1828
1852
  const localWs = new NodeWebSocket(localUrl);
1829
1853
  const conn = {
1830
1854
  localWs,
1831
1855
  userId,
1832
- e2e: null,
1856
+ e2e: carry?.e2e ?? null,
1833
1857
  connectHandshakeComplete: false,
1834
1858
  challengeNonce: null,
1835
- pendingConnect: null,
1836
- pendingMessages: []
1859
+ pendingConnect: carry?.pendingConnect ?? null,
1860
+ pendingMessages: carry?.pendingMessages ?? []
1837
1861
  };
1838
1862
  this.userConnections.set(userId, conn);
1839
1863
  localWs.on("open", () => {
1840
1864
  console.log(`[relay-client] Local WS for user ${userId} connected`);
1865
+ this.localConnectAttempts.delete(userId);
1841
1866
  });
1842
1867
  localWs.on("message", (data) => {
1843
1868
  try {
@@ -1859,6 +1884,29 @@ Device ID: ${this.deviceKeys.deviceId}`
1859
1884
  const current = this.userConnections.get(userId);
1860
1885
  if (current && current.localWs === localWs) {
1861
1886
  this.userConnections.delete(userId);
1887
+ const nextAttempt = (this.localConnectAttempts.get(userId) ?? 0) + 1;
1888
+ const shouldRetryLocalConnect = code === 1006 && !conn.connectHandshakeComplete && nextAttempt <= 8 && this.relayWs?.readyState === NodeWebSocket.OPEN;
1889
+ if (shouldRetryLocalConnect) {
1890
+ this.localConnectAttempts.set(userId, nextAttempt);
1891
+ const delay = Math.min(300 * nextAttempt, 2e3);
1892
+ console.log(
1893
+ `[relay-client] Local WS unavailable for ${userId}, retrying in ${delay}ms (attempt ${nextAttempt}/8)`
1894
+ );
1895
+ const carry2 = {
1896
+ pendingConnect: conn.pendingConnect,
1897
+ pendingMessages: conn.pendingMessages,
1898
+ e2e: conn.e2e
1899
+ };
1900
+ setTimeout(() => {
1901
+ if (this.destroyed) return;
1902
+ if (this.relayWs?.readyState !== NodeWebSocket.OPEN) return;
1903
+ if (!this.userConnections.has(userId)) {
1904
+ this.createUserConnection(userId, carry2);
1905
+ }
1906
+ }, delay);
1907
+ return;
1908
+ }
1909
+ this.localConnectAttempts.delete(userId);
1862
1910
  this.sendToRelay({
1863
1911
  type: "relay.forward",
1864
1912
  userId,
@@ -1989,10 +2037,8 @@ Device ID: ${this.deviceKeys.deviceId}`
1989
2037
  };
1990
2038
  var relayClient = null;
1991
2039
  function startRelayClient(api, relayUrl) {
1992
- const localPort = 18789;
1993
2040
  relayClient = new RelayClient({
1994
- relayUrl,
1995
- localGatewayPort: localPort
2041
+ relayUrl
1996
2042
  });
1997
2043
  relayClient.start();
1998
2044
  api.registerGatewayMethod(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squad-openclaw",
3
- "version": "2026.2.2009",
3
+ "version": "2026.2.2011",
4
4
  "description": "Entity registry, filesystem tools, and version management plugin for OpenClaw gateway",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",