remote provider health checks + compact display
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -387,6 +387,52 @@ piMonoRouter.put('/api-keys', async (ctx) => {
|
||||
return ctx.json({ ok: true });
|
||||
});
|
||||
|
||||
const REMOTE_HEALTH_CONFIG: Record<string, {
|
||||
url: string | ((key: string) => string);
|
||||
headers: (key: string) => Record<string, string>;
|
||||
}> = {
|
||||
openai: { url: 'https://api.openai.com/v1/models', headers: (k) => ({ Authorization: `Bearer ${k}` }) },
|
||||
anthropic: { url: 'https://api.anthropic.com/v1/models', headers: (k) => ({ 'x-api-key': k, 'anthropic-version': '2023-06-01' }) },
|
||||
google: { url: (k) => `https://generativelanguage.googleapis.com/v1beta/models?key=${k}`, headers: () => ({}) },
|
||||
groq: { url: 'https://api.groq.com/openai/v1/models', headers: (k) => ({ Authorization: `Bearer ${k}` }) },
|
||||
mistral: { url: 'https://api.mistral.ai/v1/models', headers: (k) => ({ Authorization: `Bearer ${k}` }) },
|
||||
xai: { url: 'https://api.x.ai/v1/models', headers: (k) => ({ Authorization: `Bearer ${k}` }) },
|
||||
openrouter: { url: 'https://openrouter.ai/api/v1/auth/key', headers: (k) => ({ Authorization: `Bearer ${k}` }) },
|
||||
cerebras: { url: 'https://api.cerebras.ai/v1/models', headers: (k) => ({ Authorization: `Bearer ${k}` }) },
|
||||
zai: { url: 'https://opencode.ai/zen/v1/models', headers: (k) => ({ Authorization: `Bearer ${k}` }) },
|
||||
};
|
||||
|
||||
piMonoRouter.get('/api-keys/health', async (ctx) => {
|
||||
const auth = await readAuthJson();
|
||||
const results: Record<string, boolean | null> = {};
|
||||
|
||||
const checks = PROVIDERS
|
||||
.filter((p) => auth[p.piId]?.key?.trim())
|
||||
.map(async (p) => {
|
||||
const config = REMOTE_HEALTH_CONFIG[p.piId];
|
||||
if (!config) {
|
||||
results[p.piId] = null;
|
||||
return;
|
||||
}
|
||||
const key = auth[p.piId]!.key;
|
||||
const url = typeof config.url === 'function' ? config.url(key) : config.url;
|
||||
const headers = config.headers(key);
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), 3000);
|
||||
try {
|
||||
const res = await fetch(url, { headers, signal: controller.signal });
|
||||
results[p.piId] = res.ok;
|
||||
} catch {
|
||||
results[p.piId] = false;
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.all(checks);
|
||||
return ctx.json(results);
|
||||
});
|
||||
|
||||
const GLOBAL_DIRS = ['/usr/local/bin', '/usr/bin'];
|
||||
|
||||
const getPaths = async () => {
|
||||
|
||||
Reference in New Issue
Block a user