squad-openclaw 2026.2.197 → 2026.2.199
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 +51 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -972,7 +972,7 @@ function readOperatorToken() {
|
|
|
972
972
|
return null;
|
|
973
973
|
}
|
|
974
974
|
}
|
|
975
|
-
var RELAY_STATE_PATH = path5.join(os.homedir(), ".
|
|
975
|
+
var RELAY_STATE_PATH = path5.join(os.homedir(), ".openclaw", "squad-relay.json");
|
|
976
976
|
function readRelayState() {
|
|
977
977
|
try {
|
|
978
978
|
const raw = fs5.readFileSync(RELAY_STATE_PATH, "utf-8");
|
|
@@ -992,7 +992,7 @@ function toBase64Url(buf) {
|
|
|
992
992
|
return buf.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
993
993
|
}
|
|
994
994
|
function loadOrCreateDeviceKeys() {
|
|
995
|
-
const keysPath = path5.join(os.homedir(), ".
|
|
995
|
+
const keysPath = path5.join(os.homedir(), ".openclaw", "squad-relay-keys.json");
|
|
996
996
|
try {
|
|
997
997
|
const raw = fs5.readFileSync(keysPath, "utf-8");
|
|
998
998
|
const keys2 = JSON.parse(raw);
|
|
@@ -1017,6 +1017,40 @@ function loadOrCreateDeviceKeys() {
|
|
|
1017
1017
|
console.log(`[relay-client] Generated new device keys: ${deviceId.substring(0, 12)}...`);
|
|
1018
1018
|
return keys;
|
|
1019
1019
|
}
|
|
1020
|
+
function ensureDevicePaired(keys) {
|
|
1021
|
+
const stateDir = process.env.OPENCLAW_STATE_DIR || path5.join(os.homedir(), ".openclaw");
|
|
1022
|
+
const pairedPath = path5.join(stateDir, "devices", "paired.json");
|
|
1023
|
+
let paired = {};
|
|
1024
|
+
try {
|
|
1025
|
+
const raw = fs5.readFileSync(pairedPath, "utf-8");
|
|
1026
|
+
paired = JSON.parse(raw);
|
|
1027
|
+
} catch {
|
|
1028
|
+
}
|
|
1029
|
+
if (paired[keys.deviceId]) {
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
const now = Date.now();
|
|
1033
|
+
paired[keys.deviceId] = {
|
|
1034
|
+
deviceId: keys.deviceId,
|
|
1035
|
+
publicKey: keys.publicKey,
|
|
1036
|
+
platform: process.platform,
|
|
1037
|
+
clientId: "cli",
|
|
1038
|
+
clientMode: "ui",
|
|
1039
|
+
role: "operator",
|
|
1040
|
+
roles: ["operator"],
|
|
1041
|
+
scopes: ["operator.admin", "operator.read", "operator.write"],
|
|
1042
|
+
tokens: {},
|
|
1043
|
+
createdAtMs: now,
|
|
1044
|
+
approvedAtMs: now,
|
|
1045
|
+
displayName: "squad-relay"
|
|
1046
|
+
};
|
|
1047
|
+
const dir = path5.dirname(pairedPath);
|
|
1048
|
+
if (!fs5.existsSync(dir)) {
|
|
1049
|
+
fs5.mkdirSync(dir, { recursive: true });
|
|
1050
|
+
}
|
|
1051
|
+
fs5.writeFileSync(pairedPath, JSON.stringify(paired, null, 2));
|
|
1052
|
+
console.log(`[relay-client] Auto-registered device in gateway store: ${keys.deviceId.substring(0, 12)}...`);
|
|
1053
|
+
}
|
|
1020
1054
|
function signDeviceIdentity(keys, clientId, clientMode, role, scopes, token) {
|
|
1021
1055
|
const signedAtMs = Date.now();
|
|
1022
1056
|
const nonce = crypto2.randomBytes(16).toString("hex");
|
|
@@ -1057,6 +1091,7 @@ var RelayClient = class {
|
|
|
1057
1091
|
};
|
|
1058
1092
|
this.pendingClaimToken = this.config.claimToken;
|
|
1059
1093
|
this.deviceKeys = loadOrCreateDeviceKeys();
|
|
1094
|
+
ensureDevicePaired(this.deviceKeys);
|
|
1060
1095
|
}
|
|
1061
1096
|
/** Start connecting to the relay */
|
|
1062
1097
|
start() {
|
|
@@ -1152,6 +1187,20 @@ var RelayClient = class {
|
|
|
1152
1187
|
this.relayWs.on("error", (err2) => {
|
|
1153
1188
|
console.error("[relay-client] Relay WebSocket error:", err2.message);
|
|
1154
1189
|
});
|
|
1190
|
+
this.relayWs.on("unexpected-response", (_req, res) => {
|
|
1191
|
+
console.warn(`[relay-client] Unexpected response: ${res.statusCode}`);
|
|
1192
|
+
if (res.statusCode === 401 && this.pendingClaimToken) {
|
|
1193
|
+
console.log("[relay-client] Claim token rejected \u2014 checking for stored room ID");
|
|
1194
|
+
this.pendingClaimToken = null;
|
|
1195
|
+
const state = readRelayState();
|
|
1196
|
+
if (state.roomId) {
|
|
1197
|
+
this.config.roomId = state.roomId;
|
|
1198
|
+
console.log(`[relay-client] Found stored room ID, will use on next reconnect`);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
this.relayWs = null;
|
|
1202
|
+
this.scheduleReconnect();
|
|
1203
|
+
});
|
|
1155
1204
|
}
|
|
1156
1205
|
scheduleReconnect() {
|
|
1157
1206
|
if (this.destroyed || !this.shouldReconnect) return;
|