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.
Files changed (2) hide show
  1. package/mcp.mjs +54 -34
  2. package/package.json +1 -1
package/mcp.mjs CHANGED
@@ -63,46 +63,66 @@ function authHeaders() {
63
63
 
64
64
  // ── HTTP helpers ──────────────────────────────────────────────────────────
65
65
 
66
- async function bridgeGet(path) {
67
- const res = await fetch(`${BRIDGE_URL}${path}`, {
68
- headers: authHeaders(),
69
- });
70
- if (!res.ok) {
71
- // If 401, try reloading the token (bridge may have restarted with new identity)
72
- if (res.status === 401 && !bridgeGet._retrying) {
73
- bridgeGet._retrying = true;
74
- bridgeToken = loadBridgeToken();
75
- const retry = await bridgeGet(path);
76
- bridgeGet._retrying = false;
77
- return retry;
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
- bridgeGet._retrying = false;
83
- return res.json();
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
- const res = await fetch(`${BRIDGE_URL}${path}`, {
88
- method: "POST",
89
- headers: authHeaders(),
90
- body: JSON.stringify(body),
91
- });
92
- if (!res.ok) {
93
- // If 401, try reloading the token (bridge may have restarted with new identity)
94
- if (res.status === 401 && !bridgePost._retrying) {
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
- bridgePost._retrying = false;
102
- throw new Error(`Bridge POST ${path} returned ${res.status}`);
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 ──────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-navigator",
3
- "version": "5.2.1",
3
+ "version": "5.2.2",
4
4
  "description": "One-command bridge + tunnel for the Navigator browser — works on any machine, any OS",
5
5
  "keywords": [
6
6
  "browser",