Spaces:
Running
Running
Commit Β·
62f946b
1
Parent(s): c3c95c3
Keep key rotator logs off stdout
Browse files
multi-provider-key-rotator.cjs
CHANGED
|
@@ -19,6 +19,11 @@
|
|
| 19 |
const http = require('node:http');
|
| 20 |
const https = require('node:https');
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
// βββ Provider definitions ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 23 |
//
|
| 24 |
// hostname β regex tested against the request hostname (case-insensitive)
|
|
@@ -185,7 +190,7 @@ const providerState = PROVIDERS.map(p => {
|
|
| 185 |
: normalizeKeys(process.env.LLM_API_KEY || '');
|
| 186 |
|
| 187 |
if (hasDedicated) {
|
| 188 |
-
|
| 189 |
} else if (!keys.length) {
|
| 190 |
console.warn(`[key-rotator] No keys for provider "${p.name}"`);
|
| 191 |
}
|
|
@@ -202,7 +207,7 @@ const fallbackCount = providerState.filter(p => {
|
|
| 202 |
return dedicated.length === 0 && p.keys.length > 0;
|
| 203 |
}).length;
|
| 204 |
if (fallbackCount > 0) {
|
| 205 |
-
|
| 206 |
}
|
| 207 |
|
| 208 |
// βββ Runtime helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -332,4 +337,4 @@ patchFetch();
|
|
| 332 |
patchHttpModule(http);
|
| 333 |
patchHttpModule(https);
|
| 334 |
|
| 335 |
-
|
|
|
|
| 19 |
const http = require('node:http');
|
| 20 |
const https = require('node:https');
|
| 21 |
|
| 22 |
+
// This file is preloaded through NODE_OPTIONS, so it also runs inside npm and
|
| 23 |
+
// OpenClaw helper subprocesses that may emit machine-readable JSON on stdout.
|
| 24 |
+
// Keep rotator diagnostics on stderr to avoid corrupting those stdout streams.
|
| 25 |
+
const log = (...args) => console.error(...args);
|
| 26 |
+
|
| 27 |
// βββ Provider definitions ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 28 |
//
|
| 29 |
// hostname β regex tested against the request hostname (case-insensitive)
|
|
|
|
| 190 |
: normalizeKeys(process.env.LLM_API_KEY || '');
|
| 191 |
|
| 192 |
if (hasDedicated) {
|
| 193 |
+
log(`[key-rotator] ${p.name}: ${keys.length} key${keys.length === 1 ? '' : 's'}`);
|
| 194 |
} else if (!keys.length) {
|
| 195 |
console.warn(`[key-rotator] No keys for provider "${p.name}"`);
|
| 196 |
}
|
|
|
|
| 207 |
return dedicated.length === 0 && p.keys.length > 0;
|
| 208 |
}).length;
|
| 209 |
if (fallbackCount > 0) {
|
| 210 |
+
log(`[key-rotator] ${fallbackCount} provider(s) using LLM_API_KEY fallback`);
|
| 211 |
}
|
| 212 |
|
| 213 |
// βββ Runtime helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 337 |
patchHttpModule(http);
|
| 338 |
patchHttpModule(https);
|
| 339 |
|
| 340 |
+
log('[key-rotator] loaded β all providers active');
|