mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 09:47:40 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
const KEY_SPLIT_RE = /[\s,;]+/g;
|
||||
|
||||
function parseKeyList(raw?: string | null): string[] {
|
||||
if (!raw) return [];
|
||||
if (!raw) {
|
||||
return [];
|
||||
}
|
||||
return raw
|
||||
.split(KEY_SPLIT_RE)
|
||||
.map((value) => value.trim())
|
||||
@@ -11,9 +13,13 @@ function parseKeyList(raw?: string | null): string[] {
|
||||
function collectEnvPrefixedKeys(prefix: string): string[] {
|
||||
const keys: string[] = [];
|
||||
for (const [name, value] of Object.entries(process.env)) {
|
||||
if (!name.startsWith(prefix)) continue;
|
||||
if (!name.startsWith(prefix)) {
|
||||
continue;
|
||||
}
|
||||
const trimmed = value?.trim();
|
||||
if (!trimmed) continue;
|
||||
if (!trimmed) {
|
||||
continue;
|
||||
}
|
||||
keys.push(trimmed);
|
||||
}
|
||||
return keys;
|
||||
@@ -21,7 +27,9 @@ function collectEnvPrefixedKeys(prefix: string): string[] {
|
||||
|
||||
export function collectAnthropicApiKeys(): string[] {
|
||||
const forcedSingle = process.env.OPENCLAW_LIVE_ANTHROPIC_KEY?.trim();
|
||||
if (forcedSingle) return [forcedSingle];
|
||||
if (forcedSingle) {
|
||||
return [forcedSingle];
|
||||
}
|
||||
|
||||
const fromList = parseKeyList(process.env.OPENCLAW_LIVE_ANTHROPIC_KEYS);
|
||||
const fromEnv = collectEnvPrefixedKeys("ANTHROPIC_API_KEY");
|
||||
@@ -29,33 +37,61 @@ export function collectAnthropicApiKeys(): string[] {
|
||||
|
||||
const seen = new Set<string>();
|
||||
const add = (value?: string) => {
|
||||
if (!value) return;
|
||||
if (seen.has(value)) return;
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
if (seen.has(value)) {
|
||||
return;
|
||||
}
|
||||
seen.add(value);
|
||||
};
|
||||
|
||||
for (const value of fromList) add(value);
|
||||
if (primary) add(primary);
|
||||
for (const value of fromEnv) add(value);
|
||||
for (const value of fromList) {
|
||||
add(value);
|
||||
}
|
||||
if (primary) {
|
||||
add(primary);
|
||||
}
|
||||
for (const value of fromEnv) {
|
||||
add(value);
|
||||
}
|
||||
|
||||
return Array.from(seen);
|
||||
}
|
||||
|
||||
export function isAnthropicRateLimitError(message: string): boolean {
|
||||
const lower = message.toLowerCase();
|
||||
if (lower.includes("rate_limit")) return true;
|
||||
if (lower.includes("rate limit")) return true;
|
||||
if (lower.includes("429")) return true;
|
||||
if (lower.includes("rate_limit")) {
|
||||
return true;
|
||||
}
|
||||
if (lower.includes("rate limit")) {
|
||||
return true;
|
||||
}
|
||||
if (lower.includes("429")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isAnthropicBillingError(message: string): boolean {
|
||||
const lower = message.toLowerCase();
|
||||
if (lower.includes("credit balance")) return true;
|
||||
if (lower.includes("insufficient credit")) return true;
|
||||
if (lower.includes("insufficient credits")) return true;
|
||||
if (lower.includes("payment required")) return true;
|
||||
if (lower.includes("billing") && lower.includes("disabled")) return true;
|
||||
if (lower.includes("402")) return true;
|
||||
if (lower.includes("credit balance")) {
|
||||
return true;
|
||||
}
|
||||
if (lower.includes("insufficient credit")) {
|
||||
return true;
|
||||
}
|
||||
if (lower.includes("insufficient credits")) {
|
||||
return true;
|
||||
}
|
||||
if (lower.includes("payment required")) {
|
||||
return true;
|
||||
}
|
||||
if (lower.includes("billing") && lower.includes("disabled")) {
|
||||
return true;
|
||||
}
|
||||
if (lower.includes("402")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user