import { type LlamaSwapConfig } from "./util"; const TIMEOUT_MS = 5000; export interface ModelInfo { id: string; status: string; } function headersFor(cfg: LlamaSwapConfig): Record { const headers: Record = {}; if (cfg.apiKey) headers["Authorization"] = `Bearer ${cfg.apiKey}`; return headers; } export async function fetchMetrics(cfg: LlamaSwapConfig): Promise { const res = await fetch(`${cfg.baseUrl}/metrics`, { headers: headersFor(cfg), signal: AbortSignal.timeout(TIMEOUT_MS), }); if (!res.ok) throw new Error(`metrics HTTP ${res.status}`); return await res.text(); } export async function fetchModels(cfg: LlamaSwapConfig): Promise { const res = await fetch(`${cfg.baseUrl}/v1/models`, { headers: headersFor(cfg), signal: AbortSignal.timeout(TIMEOUT_MS), }); if (!res.ok) throw new Error(`models HTTP ${res.status}`); const body = (await res.json()) as { data?: { id: string; status?: { value?: string } }[] }; return (body.data ?? []).map((m) => ({ id: m.id, status: m.status?.value ?? "unknown" })); }