openclaw-navigator 5.2.1 → 5.2.2
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/mcp.mjs +54 -34
- package/package.json +1 -1
package/mcp.mjs
CHANGED
|
@@ -63,46 +63,66 @@ function authHeaders() {
|
|
|
63
63
|
|
|
64
64
|
// ── HTTP helpers ──────────────────────────────────────────────────────────
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
const MAX_RETRIES = 3;
|
|
67
|
+
const RETRY_DELAYS = [500, 1500, 3000]; // ms — escalating backoff
|
|
68
|
+
|
|
69
|
+
/** Retry wrapper for bridge HTTP calls — handles ECONNREFUSED and 401 */
|
|
70
|
+
async function withRetry(fn, label) {
|
|
71
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
72
|
+
try {
|
|
73
|
+
return await fn();
|
|
74
|
+
} catch (err) {
|
|
75
|
+
const isConnErr =
|
|
76
|
+
err.cause?.code === "ECONNREFUSED" ||
|
|
77
|
+
err.message?.includes("ECONNREFUSED") ||
|
|
78
|
+
err.message?.includes("fetch failed");
|
|
79
|
+
const is401 = err.message?.includes("returned 401");
|
|
80
|
+
|
|
81
|
+
if (is401 && attempt === 0) {
|
|
82
|
+
// Auth mismatch — bridge may have restarted with new token
|
|
83
|
+
log(`${label}: 401 — reloading bridge token and retrying`);
|
|
84
|
+
bridgeToken = loadBridgeToken();
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (isConnErr && attempt < MAX_RETRIES) {
|
|
89
|
+
const delay = RETRY_DELAYS[attempt] || 3000;
|
|
90
|
+
log(`${label}: bridge unreachable — retry ${attempt + 1}/${MAX_RETRIES} in ${delay}ms`);
|
|
91
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
92
|
+
// Also reload token in case bridge restarted with new identity
|
|
93
|
+
bridgeToken = loadBridgeToken();
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
throw err;
|
|
78
98
|
}
|
|
79
|
-
bridgeGet._retrying = false;
|
|
80
|
-
throw new Error(`Bridge GET ${path} returned ${res.status}`);
|
|
81
99
|
}
|
|
82
|
-
|
|
83
|
-
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function bridgeGet(path) {
|
|
103
|
+
return withRetry(async () => {
|
|
104
|
+
const res = await fetch(`${BRIDGE_URL}${path}`, {
|
|
105
|
+
headers: authHeaders(),
|
|
106
|
+
});
|
|
107
|
+
if (!res.ok) {
|
|
108
|
+
throw new Error(`Bridge GET ${path} returned ${res.status}`);
|
|
109
|
+
}
|
|
110
|
+
return res.json();
|
|
111
|
+
}, `GET ${path}`);
|
|
84
112
|
}
|
|
85
113
|
|
|
86
114
|
async function bridgePost(path, body) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
bridgePost._retrying = true;
|
|
96
|
-
bridgeToken = loadBridgeToken();
|
|
97
|
-
const retry = await bridgePost(path, body);
|
|
98
|
-
bridgePost._retrying = false;
|
|
99
|
-
return retry;
|
|
115
|
+
return withRetry(async () => {
|
|
116
|
+
const res = await fetch(`${BRIDGE_URL}${path}`, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: authHeaders(),
|
|
119
|
+
body: JSON.stringify(body),
|
|
120
|
+
});
|
|
121
|
+
if (!res.ok) {
|
|
122
|
+
throw new Error(`Bridge POST ${path} returned ${res.status}`);
|
|
100
123
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
bridgePost._retrying = false;
|
|
105
|
-
return res.json();
|
|
124
|
+
return res.json();
|
|
125
|
+
}, `POST ${path}`);
|
|
106
126
|
}
|
|
107
127
|
|
|
108
128
|
// ── Event polling engine ──────────────────────────────────────────────────
|