import fs from "node:fs"; import path from "node:path"; import { ImageResponse } from "next/og"; import { fmtParams, getRun, getRuns, limitOf } from "@/lib/results"; /** * Shareable score card as a PNG. * * One image serves two jobs: the download button and the OpenGraph tag, so a * pasted link unfurls as the card itself. Fonts are bundled rather than * fetched at request time — satori needs real font buffers, and a network * dependency inside image generation fails in exactly the situations where * you want a share link to work. * * Note: satori supports flexbox only. Every container needs an explicit * display value; CSS grid silently renders nothing. */ export const dynamic = "force-static"; export function generateStaticParams() { return getRuns().map((r) => ({ id: r.run_id.slice(0, 8) })); } const FONT_DIR = path.join(process.cwd(), "assets", "fonts"); const font = (file: string) => fs.readFileSync(path.join(FONT_DIR, file)); const VOID = "#08090b"; const RULE = "#1e232b"; const INK = "#e8e6e1"; const DIM = "#79818d"; const DIMMER = "#4a515b"; const SIGNAL = "#f2b134"; const REFERENCE = "#5896ae"; function Stat({ label, value, unit, color = INK, hint, }: { label: string; value: string; unit?: string; color?: string; hint?: string; }) { return (
{label}
{value} {unit && {unit}}
{hint &&
{hint}
}
); } export async function GET( _req: Request, { params }: { params: Promise<{ id: string }> }, ) { const { id } = await params; const run = getRun(id); if (!run) return new Response("not found", { status: 404 }); const v = run.verdict; const limit = limitOf(run); const perf = run.perf?.points ?? []; const single = perf.find((p) => p.concurrency === 1); const peak = perf.length ? perf.reduce((a, b) => (b.output_tps_total > a.output_tps_total ? b : a)) : null; return new ImageResponse( (
{/* header */}
bench .karti.ai
{run.timestamp.slice(0, 10)}
{/* title */}
{run.target.display_name} {run.host.hardware} · {fmtParams(run.target)} ·{" "} {run.target.quant?.toUpperCase()} · {run.target.serving.engine}
{/* stats */}
{/* tick strip — a measurement scale across the full plate */}
{Array.from({ length: 96 }).map((_, i) => (
))}
), { width: 1200, height: 630, fonts: [ { name: "Instrument", data: font("InstrumentSerif-Regular.ttf"), style: "normal", weight: 400 }, { name: "Plex", data: font("IBMPlexMono-Regular.ttf"), style: "normal", weight: 400 }, { name: "Plex", data: font("IBMPlexMono-SemiBold.ttf"), style: "normal", weight: 600 }, ], }, ); }