squad-openclaw 2026.2.2008 → 2026.2.2010
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 +75 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1230,6 +1230,7 @@ import path6 from "path";
|
|
|
1230
1230
|
import { fileURLToPath } from "url";
|
|
1231
1231
|
var PACKAGE_NAME = "squad-openclaw";
|
|
1232
1232
|
var CONFIG_PATH = path6.join(getOpenclawStateDir(), "openclaw.json");
|
|
1233
|
+
var updateInProgress = false;
|
|
1233
1234
|
function getCurrentVersion() {
|
|
1234
1235
|
const thisFile = fileURLToPath(import.meta.url);
|
|
1235
1236
|
const pkgPath = path6.resolve(path6.dirname(thisFile), "..", "package.json");
|
|
@@ -1286,6 +1287,11 @@ function registerVersionMethods(api) {
|
|
|
1286
1287
|
api.registerGatewayMethod(
|
|
1287
1288
|
"squad.version.update",
|
|
1288
1289
|
async ({ respond }) => {
|
|
1290
|
+
if (updateInProgress) {
|
|
1291
|
+
respond(false, { error: "Update already in progress" });
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
updateInProgress = true;
|
|
1289
1295
|
try {
|
|
1290
1296
|
const before = getCurrentVersion();
|
|
1291
1297
|
let updateOutput = "";
|
|
@@ -1303,29 +1309,22 @@ function registerVersionMethods(api) {
|
|
|
1303
1309
|
}
|
|
1304
1310
|
try {
|
|
1305
1311
|
updateOutput = execSync2(
|
|
1306
|
-
`openclaw plugins
|
|
1312
|
+
`openclaw plugins install ${PACKAGE_NAME} 2>&1`,
|
|
1307
1313
|
{ timeout: 12e4, encoding: "utf-8" }
|
|
1308
1314
|
);
|
|
1309
|
-
} catch {
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
);
|
|
1315
|
-
} catch (npmErr) {
|
|
1316
|
-
if (configBackup) {
|
|
1317
|
-
try {
|
|
1318
|
-
fs5.writeFileSync(CONFIG_PATH, configBackup, "utf-8");
|
|
1319
|
-
} catch {
|
|
1320
|
-
}
|
|
1315
|
+
} catch (installErr) {
|
|
1316
|
+
if (configBackup) {
|
|
1317
|
+
try {
|
|
1318
|
+
fs5.writeFileSync(CONFIG_PATH, configBackup, "utf-8");
|
|
1319
|
+
} catch {
|
|
1321
1320
|
}
|
|
1322
|
-
const msg = npmErr instanceof Error ? npmErr.message : String(npmErr);
|
|
1323
|
-
respond(false, {
|
|
1324
|
-
error: `Update failed: ${msg}`,
|
|
1325
|
-
output: updateOutput
|
|
1326
|
-
});
|
|
1327
|
-
return;
|
|
1328
1321
|
}
|
|
1322
|
+
const msg = installErr instanceof Error ? installErr.message : String(installErr);
|
|
1323
|
+
respond(false, {
|
|
1324
|
+
error: `Update failed: ${msg}`,
|
|
1325
|
+
output: updateOutput
|
|
1326
|
+
});
|
|
1327
|
+
return;
|
|
1329
1328
|
}
|
|
1330
1329
|
const after = getCurrentVersion();
|
|
1331
1330
|
respond(true, {
|
|
@@ -1350,6 +1349,8 @@ function registerVersionMethods(api) {
|
|
|
1350
1349
|
} catch (e) {
|
|
1351
1350
|
const msg = e instanceof Error ? e.message : String(e);
|
|
1352
1351
|
respond(false, { error: msg });
|
|
1352
|
+
} finally {
|
|
1353
|
+
updateInProgress = false;
|
|
1353
1354
|
}
|
|
1354
1355
|
}
|
|
1355
1356
|
);
|
|
@@ -1507,6 +1508,25 @@ function readOperatorToken() {
|
|
|
1507
1508
|
return null;
|
|
1508
1509
|
}
|
|
1509
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
|
+
}
|
|
1510
1530
|
function signDeviceIdentity(keys, clientId, clientMode, role, scopes, token, challengeNonce) {
|
|
1511
1531
|
const signedAtMs = Date.now();
|
|
1512
1532
|
const nonce = challengeNonce || crypto3.randomBytes(16).toString("hex");
|
|
@@ -1526,6 +1546,7 @@ var RelayClient = class {
|
|
|
1526
1546
|
config;
|
|
1527
1547
|
relayWs = null;
|
|
1528
1548
|
userConnections = /* @__PURE__ */ new Map();
|
|
1549
|
+
localConnectAttempts = /* @__PURE__ */ new Map();
|
|
1529
1550
|
reconnectAttempts = 0;
|
|
1530
1551
|
maxReconnectAttempts = 100;
|
|
1531
1552
|
reconnectTimer = null;
|
|
@@ -1537,9 +1558,11 @@ var RelayClient = class {
|
|
|
1537
1558
|
deviceKeys;
|
|
1538
1559
|
constructor(config) {
|
|
1539
1560
|
const state = readRelayState();
|
|
1561
|
+
const localWs = readGatewayLocalWsConfig();
|
|
1540
1562
|
this.config = {
|
|
1541
1563
|
relayUrl: config.relayUrl,
|
|
1542
|
-
localGatewayPort: config.localGatewayPort ??
|
|
1564
|
+
localGatewayPort: config.localGatewayPort ?? localWs.port,
|
|
1565
|
+
localGatewayHosts: config.localGatewayHosts ?? localWs.hosts,
|
|
1543
1566
|
operatorToken: config.operatorToken ?? readOperatorToken(),
|
|
1544
1567
|
claimToken: config.claimToken ?? state.claimToken ?? null,
|
|
1545
1568
|
roomId: config.roomId ?? state.roomId ?? null
|
|
@@ -1814,7 +1837,7 @@ var RelayClient = class {
|
|
|
1814
1837
|
console.log(`[relay-client] Injected device identity for ${conn.userId}: nonce=${conn.challengeNonce?.substring(0, 12)}...`);
|
|
1815
1838
|
}
|
|
1816
1839
|
/** Create a local WS connection to the gateway for a specific user */
|
|
1817
|
-
createUserConnection(userId) {
|
|
1840
|
+
createUserConnection(userId, carry) {
|
|
1818
1841
|
const existing = this.userConnections.get(userId);
|
|
1819
1842
|
if (existing) {
|
|
1820
1843
|
try {
|
|
@@ -1822,21 +1845,24 @@ var RelayClient = class {
|
|
|
1822
1845
|
} catch {
|
|
1823
1846
|
}
|
|
1824
1847
|
}
|
|
1825
|
-
const
|
|
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}`;
|
|
1826
1851
|
console.log(`[relay-client] Creating local WS for user ${userId} \u2192 ${localUrl}`);
|
|
1827
1852
|
const localWs = new NodeWebSocket(localUrl);
|
|
1828
1853
|
const conn = {
|
|
1829
1854
|
localWs,
|
|
1830
1855
|
userId,
|
|
1831
|
-
e2e: null,
|
|
1856
|
+
e2e: carry?.e2e ?? null,
|
|
1832
1857
|
connectHandshakeComplete: false,
|
|
1833
1858
|
challengeNonce: null,
|
|
1834
|
-
pendingConnect: null,
|
|
1835
|
-
pendingMessages: []
|
|
1859
|
+
pendingConnect: carry?.pendingConnect ?? null,
|
|
1860
|
+
pendingMessages: carry?.pendingMessages ?? []
|
|
1836
1861
|
};
|
|
1837
1862
|
this.userConnections.set(userId, conn);
|
|
1838
1863
|
localWs.on("open", () => {
|
|
1839
1864
|
console.log(`[relay-client] Local WS for user ${userId} connected`);
|
|
1865
|
+
this.localConnectAttempts.delete(userId);
|
|
1840
1866
|
});
|
|
1841
1867
|
localWs.on("message", (data) => {
|
|
1842
1868
|
try {
|
|
@@ -1858,6 +1884,29 @@ Device ID: ${this.deviceKeys.deviceId}`
|
|
|
1858
1884
|
const current = this.userConnections.get(userId);
|
|
1859
1885
|
if (current && current.localWs === localWs) {
|
|
1860
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);
|
|
1861
1910
|
this.sendToRelay({
|
|
1862
1911
|
type: "relay.forward",
|
|
1863
1912
|
userId,
|
|
@@ -1988,10 +2037,8 @@ Device ID: ${this.deviceKeys.deviceId}`
|
|
|
1988
2037
|
};
|
|
1989
2038
|
var relayClient = null;
|
|
1990
2039
|
function startRelayClient(api, relayUrl) {
|
|
1991
|
-
const localPort = 18789;
|
|
1992
2040
|
relayClient = new RelayClient({
|
|
1993
|
-
relayUrl
|
|
1994
|
-
localGatewayPort: localPort
|
|
2041
|
+
relayUrl
|
|
1995
2042
|
});
|
|
1996
2043
|
relayClient.start();
|
|
1997
2044
|
api.registerGatewayMethod(
|
package/package.json
CHANGED