@appchy/jarvis 0.1.6 → 0.1.7
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/bin.js +21 -4
- package/dist/bin.js.map +1 -1
- package/package.json +4 -4
package/dist/bin.js
CHANGED
|
@@ -2520,12 +2520,15 @@ function createUpstreamClient(config) {
|
|
|
2520
2520
|
let messageHandler = null;
|
|
2521
2521
|
let reconnectTimer = null;
|
|
2522
2522
|
let closed = false;
|
|
2523
|
+
let authFailures = 0;
|
|
2524
|
+
const MAX_AUTH_RETRIES = 3;
|
|
2523
2525
|
function connect() {
|
|
2524
2526
|
if (closed) return;
|
|
2525
2527
|
ws = new WebSocket2(config.apiUrl, {
|
|
2526
2528
|
headers: { authorization: `Bearer ${config.token}` }
|
|
2527
2529
|
});
|
|
2528
2530
|
ws.on("open", () => {
|
|
2531
|
+
authFailures = 0;
|
|
2529
2532
|
logger.sys.info("[Upstream] Connected to cloud", { apiUrl: config.apiUrl });
|
|
2530
2533
|
});
|
|
2531
2534
|
ws.on("message", (raw) => {
|
|
@@ -2539,11 +2542,25 @@ function createUpstreamClient(config) {
|
|
|
2539
2542
|
} catch {
|
|
2540
2543
|
}
|
|
2541
2544
|
});
|
|
2542
|
-
ws.on("close", () => {
|
|
2543
|
-
if (
|
|
2544
|
-
|
|
2545
|
-
|
|
2545
|
+
ws.on("close", (code) => {
|
|
2546
|
+
if (closed) return;
|
|
2547
|
+
if (code === 4001 || code === 4003) {
|
|
2548
|
+
authFailures++;
|
|
2549
|
+
if (authFailures >= MAX_AUTH_RETRIES) {
|
|
2550
|
+
logger.sys.error("[Upstream] Auth failed after max retries, giving up", {
|
|
2551
|
+
code,
|
|
2552
|
+
attempts: authFailures
|
|
2553
|
+
});
|
|
2554
|
+
return;
|
|
2555
|
+
}
|
|
2556
|
+
logger.sys.warn("[Upstream] Auth failed, retrying...", {
|
|
2557
|
+
code,
|
|
2558
|
+
attempt: authFailures,
|
|
2559
|
+
maxRetries: MAX_AUTH_RETRIES
|
|
2560
|
+
});
|
|
2546
2561
|
}
|
|
2562
|
+
logger.sys.info("[Upstream] Disconnected, reconnecting in 3s...");
|
|
2563
|
+
reconnectTimer = setTimeout(connect, 3e3);
|
|
2547
2564
|
});
|
|
2548
2565
|
ws.on("error", (err) => {
|
|
2549
2566
|
logger.sys.error("[Upstream] Connection error", {
|