/** * llmindex.io — read live benchmark progress from Redis (server-side) * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * License: Proprietary — © Simon-Pierre Boucher, all rights reserved */ import 'server-only'; import Redis from 'ioredis'; const PROGRESS_KEY = 'llmindex:benchmark:progress'; let redis: Redis | null | undefined; function getRedis(): Redis | null { if (redis !== undefined) return redis; const url = process.env.REDIS_URL; if (!url) { redis = null; return redis; } redis = new Redis(url, { maxRetriesPerRequest: 1, enableOfflineQueue: false }); redis.on('error', () => { /* progress endpoint fails soft */ }); return redis; } export interface PublicBenchmarkProgress { active: boolean; started_at?: string; updated_at?: string; models?: string[]; completed?: string[]; failed?: string[]; current?: { model: string; domain: string; domain_index: number; domains_total: number; calls_done: number; calls_total: number; } | null; currents?: Array<{ model: string; domain: string; domain_index: number; domains_total: number; calls_done: number; calls_total: number; }>; last_refit_run_id?: string | null; note?: string; } export async function readBenchmarkProgress(): Promise { const client = getRedis(); if (!client) return { active: false }; try { const raw = await client.get(PROGRESS_KEY); if (!raw) return { active: false }; return JSON.parse(raw) as PublicBenchmarkProgress; } catch { return { active: false }; } }