/** * llmindex.io — live benchmark progress writer (Redis, read by /api/v1/benchmark/progress) * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * License: Proprietary — © Simon-Pierre Boucher, all rights reserved */ import IORedis from 'ioredis'; import { redisUrl } from './env'; export const PROGRESS_KEY = 'llmindex:benchmark:progress'; export interface BenchmarkCurrent { model: string; domain: string; domain_index: number; domains_total: number; calls_done: number; calls_total: number; } export interface BenchmarkProgress { active: boolean; started_at: string; models: string[]; completed: string[]; failed: string[]; /** First active lane (kept for backward compatibility). */ current: BenchmarkCurrent | null; /** All active lanes (parallel evaluation). */ currents?: BenchmarkCurrent[]; last_refit_run_id?: string | null; note?: string; } let redis: IORedis | null = null; function client(): IORedis { if (!redis) { redis = new IORedis(redisUrl(), { maxRetriesPerRequest: 1, enableOfflineQueue: false }); redis.on('error', () => { /* progress is best-effort; never crash the benchmark on Redis hiccups */ }); } return redis; } export async function writeProgress(p: BenchmarkProgress): Promise { try { await client().set(PROGRESS_KEY, JSON.stringify({ ...p, updated_at: new Date().toISOString() })); } catch { /* best-effort */ } } export async function closeProgress(): Promise { try { await redis?.quit(); } catch { /* ignore */ } }