fix: modernize live tests and gemini ids

This commit is contained in:
Peter Steinberger
2026-01-12 06:58:31 +00:00
parent 79cbb20988
commit 1850013cae
11 changed files with 1053 additions and 593 deletions

View File

@@ -0,0 +1,50 @@
const KEY_SPLIT_RE = /[\s,;]+/g;
function parseKeyList(raw?: string | null): string[] {
if (!raw) return [];
return raw
.split(KEY_SPLIT_RE)
.map((value) => value.trim())
.filter(Boolean);
}
function collectEnvPrefixedKeys(prefix: string): string[] {
const keys: string[] = [];
for (const [name, value] of Object.entries(process.env)) {
if (!name.startsWith(prefix)) continue;
const trimmed = value?.trim();
if (!trimmed) continue;
keys.push(trimmed);
}
return keys;
}
export function collectAnthropicApiKeys(): string[] {
const forcedSingle = process.env.CLAWDBOT_LIVE_ANTHROPIC_KEY?.trim();
if (forcedSingle) return [forcedSingle];
const fromList = parseKeyList(process.env.CLAWDBOT_LIVE_ANTHROPIC_KEYS);
const fromEnv = collectEnvPrefixedKeys("ANTHROPIC_API_KEY");
const primary = process.env.ANTHROPIC_API_KEY?.trim();
const seen = new Set<string>();
const add = (value?: string) => {
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);
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;
return false;
}