claw-control-center 0.1.3 → 0.1.4
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.cjs +102 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6476,6 +6476,9 @@ var CHAT_HISTORY_MAX_PAGES = 100;
|
|
|
6476
6476
|
var CRON_LIST_PAGE_LIMIT = 50;
|
|
6477
6477
|
var CRON_LIST_MAX_PAGES = 100;
|
|
6478
6478
|
var OPENCLAW_STOP_SETTLE_TIMEOUT_MS = 3e3;
|
|
6479
|
+
var GATEWAY_PROTOCOL_MIN = 3;
|
|
6480
|
+
var GATEWAY_PROTOCOL_MAX = 4;
|
|
6481
|
+
var WEBSOCKET_CONNECTING = 0;
|
|
6479
6482
|
function createGatewayClient(config) {
|
|
6480
6483
|
const resolved = resolveGatewayConfig(config);
|
|
6481
6484
|
const hostKind = resolved.hostKind ?? "openclaw";
|
|
@@ -7237,6 +7240,82 @@ function readUnknownPath(value, path) {
|
|
|
7237
7240
|
}
|
|
7238
7241
|
return current;
|
|
7239
7242
|
}
|
|
7243
|
+
function createGatewayFrameError(error) {
|
|
7244
|
+
const message = error?.message ?? "gateway request failed";
|
|
7245
|
+
const details = error?.details !== void 0 ? `: ${JSON.stringify(error.details)}` : "";
|
|
7246
|
+
return new Error(`${message}${details}`);
|
|
7247
|
+
}
|
|
7248
|
+
function createGatewayHandshakeError(error) {
|
|
7249
|
+
if (!/protocol mismatch/i.test(error.message)) {
|
|
7250
|
+
return error;
|
|
7251
|
+
}
|
|
7252
|
+
return new Error(`Gateway protocol negotiation failed: ${error.message}`);
|
|
7253
|
+
}
|
|
7254
|
+
function createUnsupportedGatewayProtocolError(expectedProtocol, originalError) {
|
|
7255
|
+
return new Error(
|
|
7256
|
+
`Gateway protocol ${expectedProtocol} is not supported by this client; supported range is ${GATEWAY_PROTOCOL_MIN}-${GATEWAY_PROTOCOL_MAX}. Original error: ${originalError.message}`
|
|
7257
|
+
);
|
|
7258
|
+
}
|
|
7259
|
+
function extractExpectedGatewayProtocol(error, fallbackMessage) {
|
|
7260
|
+
const fromDetails = readExpectedProtocolValue(error?.details);
|
|
7261
|
+
if (fromDetails !== null) {
|
|
7262
|
+
return fromDetails;
|
|
7263
|
+
}
|
|
7264
|
+
return readExpectedProtocolFromText([error?.message, fallbackMessage].filter(Boolean).join(" "));
|
|
7265
|
+
}
|
|
7266
|
+
function readExpectedProtocolValue(value, depth = 0) {
|
|
7267
|
+
if (value === null || value === void 0 || depth > 4) {
|
|
7268
|
+
return null;
|
|
7269
|
+
}
|
|
7270
|
+
if (typeof value === "string") {
|
|
7271
|
+
const fromText = readExpectedProtocolFromText(value);
|
|
7272
|
+
if (fromText !== null) {
|
|
7273
|
+
return fromText;
|
|
7274
|
+
}
|
|
7275
|
+
try {
|
|
7276
|
+
return readExpectedProtocolValue(JSON.parse(value), depth + 1);
|
|
7277
|
+
} catch {
|
|
7278
|
+
return null;
|
|
7279
|
+
}
|
|
7280
|
+
}
|
|
7281
|
+
if (Array.isArray(value)) {
|
|
7282
|
+
for (const item of value) {
|
|
7283
|
+
const match = readExpectedProtocolValue(item, depth + 1);
|
|
7284
|
+
if (match !== null) {
|
|
7285
|
+
return match;
|
|
7286
|
+
}
|
|
7287
|
+
}
|
|
7288
|
+
return null;
|
|
7289
|
+
}
|
|
7290
|
+
if (typeof value !== "object") {
|
|
7291
|
+
return null;
|
|
7292
|
+
}
|
|
7293
|
+
const record = value;
|
|
7294
|
+
for (const key of ["expectedProtocol", "expected_protocol"]) {
|
|
7295
|
+
const match = coerceGatewayProtocol(record[key]);
|
|
7296
|
+
if (match !== null) {
|
|
7297
|
+
return match;
|
|
7298
|
+
}
|
|
7299
|
+
}
|
|
7300
|
+
for (const item of Object.values(record)) {
|
|
7301
|
+
const match = readExpectedProtocolValue(item, depth + 1);
|
|
7302
|
+
if (match !== null) {
|
|
7303
|
+
return match;
|
|
7304
|
+
}
|
|
7305
|
+
}
|
|
7306
|
+
return null;
|
|
7307
|
+
}
|
|
7308
|
+
function readExpectedProtocolFromText(value) {
|
|
7309
|
+
const match = value.match(/["']?expectedProtocol["']?\s*[:=]\s*["']?(\d+)["']?/i);
|
|
7310
|
+
return match ? coerceGatewayProtocol(match[1]) : null;
|
|
7311
|
+
}
|
|
7312
|
+
function coerceGatewayProtocol(value) {
|
|
7313
|
+
const protocol = typeof value === "number" ? value : typeof value === "string" ? Number(value) : Number.NaN;
|
|
7314
|
+
return Number.isInteger(protocol) ? protocol : null;
|
|
7315
|
+
}
|
|
7316
|
+
function isSupportedGatewayProtocol(protocol) {
|
|
7317
|
+
return protocol >= GATEWAY_PROTOCOL_MIN && protocol <= GATEWAY_PROTOCOL_MAX;
|
|
7318
|
+
}
|
|
7240
7319
|
var RpcSocketClient = class {
|
|
7241
7320
|
constructor(config) {
|
|
7242
7321
|
this.config = config;
|
|
@@ -7249,6 +7328,8 @@ var RpcSocketClient = class {
|
|
|
7249
7328
|
connectPromise = null;
|
|
7250
7329
|
ready = false;
|
|
7251
7330
|
challengeNonce = null;
|
|
7331
|
+
connectProtocolOverride = null;
|
|
7332
|
+
connectProtocolRetryUsed = false;
|
|
7252
7333
|
stopped = false;
|
|
7253
7334
|
onEvent(listener) {
|
|
7254
7335
|
this.listeners.add(listener);
|
|
@@ -7318,6 +7399,7 @@ var RpcSocketClient = class {
|
|
|
7318
7399
|
this.socket = socket;
|
|
7319
7400
|
this.ready = false;
|
|
7320
7401
|
this.challengeNonce = null;
|
|
7402
|
+
this.connectProtocolRetryUsed = false;
|
|
7321
7403
|
let settled = false;
|
|
7322
7404
|
const finishError = (error) => {
|
|
7323
7405
|
if (settled) {
|
|
@@ -7327,6 +7409,9 @@ var RpcSocketClient = class {
|
|
|
7327
7409
|
if (this.socket === socket) {
|
|
7328
7410
|
this.socket = null;
|
|
7329
7411
|
}
|
|
7412
|
+
if (socket.readyState === WEBSOCKET_CONNECTING || socket.readyState === wrapper_default.OPEN) {
|
|
7413
|
+
socket.close();
|
|
7414
|
+
}
|
|
7330
7415
|
this.ready = false;
|
|
7331
7416
|
this.challengeNonce = null;
|
|
7332
7417
|
reject(error);
|
|
@@ -7394,11 +7479,20 @@ var RpcSocketClient = class {
|
|
|
7394
7479
|
clearTimeout(pending.timeout);
|
|
7395
7480
|
}
|
|
7396
7481
|
if (!frame.ok) {
|
|
7397
|
-
const
|
|
7398
|
-
const details = frame.error?.details ? `: ${JSON.stringify(frame.error.details)}` : "";
|
|
7399
|
-
const error = new Error(`${message}${details}`);
|
|
7482
|
+
const error = createGatewayFrameError(frame.error);
|
|
7400
7483
|
if (frame.id === "connect-handshake") {
|
|
7401
|
-
|
|
7484
|
+
const expectedProtocol = extractExpectedGatewayProtocol(frame.error, error.message);
|
|
7485
|
+
if (expectedProtocol !== null && !isSupportedGatewayProtocol(expectedProtocol)) {
|
|
7486
|
+
rejectConnect(createUnsupportedGatewayProtocolError(expectedProtocol, error));
|
|
7487
|
+
return;
|
|
7488
|
+
}
|
|
7489
|
+
if (expectedProtocol !== null && !this.connectProtocolRetryUsed) {
|
|
7490
|
+
this.connectProtocolOverride = expectedProtocol;
|
|
7491
|
+
this.connectProtocolRetryUsed = true;
|
|
7492
|
+
this.sendConnect();
|
|
7493
|
+
return;
|
|
7494
|
+
}
|
|
7495
|
+
rejectConnect(createGatewayHandshakeError(error));
|
|
7402
7496
|
return;
|
|
7403
7497
|
}
|
|
7404
7498
|
pending.reject(error);
|
|
@@ -7416,13 +7510,15 @@ var RpcSocketClient = class {
|
|
|
7416
7510
|
if (!this.socket || this.socket.readyState !== wrapper_default.OPEN || !this.challengeNonce) {
|
|
7417
7511
|
return;
|
|
7418
7512
|
}
|
|
7513
|
+
const minProtocol = this.connectProtocolOverride ?? GATEWAY_PROTOCOL_MIN;
|
|
7514
|
+
const maxProtocol = this.connectProtocolOverride ?? GATEWAY_PROTOCOL_MAX;
|
|
7419
7515
|
const frame = {
|
|
7420
7516
|
type: "req",
|
|
7421
7517
|
id: "connect-handshake",
|
|
7422
7518
|
method: "connect",
|
|
7423
7519
|
params: {
|
|
7424
|
-
minProtocol
|
|
7425
|
-
maxProtocol
|
|
7520
|
+
minProtocol,
|
|
7521
|
+
maxProtocol,
|
|
7426
7522
|
client: {
|
|
7427
7523
|
id: "gateway-client",
|
|
7428
7524
|
displayName: "Claw Control Center",
|