import "server-only" import type { BackendManifestStatus } from "@/lib/backend-artifacts" import { cleanHierarchy } from "@/lib/clean-hierarchy" async function viewBackend() { return import("@/lib/view-data") } async function sidecars() { return import("@/lib/sidecars") } async function hfData() { return import("@/lib/hf-data") } async function applyModelCoverage( cards: T[], ): Promise { try { const coverage = await (await sidecars()).fetchModelCoverage() if (Object.keys(coverage).length === 0) return cards return cards.map((c) => coverage[c.route_id] != null ? { ...c, benchmarks_count: coverage[c.route_id] } : c, ) } catch { return cards } } export async function getModelCards() { const cards = await (await viewBackend()).getModelCards() return applyModelCoverage(cards) } export async function getModelCardsLite() { const cards = await (await viewBackend()).getModelCardsLite() return applyModelCoverage(cards) } export async function getEvalListData() { return (await viewBackend()).getEvalListData() } export async function getEvalListLiteData() { return (await viewBackend()).getEvalListLiteData() } export async function getEvalList() { return (await viewBackend()).getEvalList() } export async function getDashboardData() { return (await viewBackend()).getDashboardData() } export async function getDeveloperList() { return (await viewBackend()).getDeveloperList() } export async function getDeveloperSummaryById(routeId: string) { return (await viewBackend()).getDeveloperSummaryById(routeId) } export async function getModelSummaryById(modelId: string) { return (await viewBackend()).getModelSummaryById(modelId) } export async function getEvalSummaryById(evalId: string) { return (await viewBackend()).getEvalSummaryById(evalId) } export async function getBackendManifestData() { return (await sidecars()).fetchManifest() } export async function getBackendManifestStatusData(): Promise { const manifest = await (await sidecars()).fetchManifest() return { currentManifest: manifest, latestManifest: manifest, currentManifestSignature: manifest.generated_at, latestManifestSignature: manifest.generated_at, updateAvailable: false, refreshing: false, pendingRefreshCount: 0, } } export async function getEvalHierarchyData() { // The v2 sidecar ships hierarchy.json in the composite/family/slice // taxonomy shape (top-level `composites[]`, flat `families[]` lookup // index). UI components expect the legacy nested // `families[].composites[]` / `families[].standalone_benchmarks[]` // shape, so route the sidecar through the adapter, then `cleanHierarchy` // for sanitised display names + family-rollup filtering. const raw = await (await sidecars()).fetchHierarchy() return cleanHierarchy((await hfData()).adaptEvalHierarchy(raw)) }