|
| 1 | +--- |
| 2 | +/** |
| 3 | + * Static benchmark boards (ported from PR #144's GUI Frontier page). |
| 4 | + * Renders one section per board: provenance line, honesty note for non-measured |
| 5 | + * cost figures, an ECharts cost-vs-score scatter (client-side, vanilla API), and |
| 6 | + * a data table. Score-per-dollar columns appear ONLY when every row carries a |
| 7 | + * source-measured cost (costKind honesty rule from the PR). |
| 8 | + */ |
| 9 | +import data from "../data/frontier-benchmarks.json"; |
| 10 | +import { FRONTIER_STRINGS } from "../data/frontier-i18n"; |
| 11 | +
|
| 12 | +interface Props { |
| 13 | + locale?: "en" | "ko" | "zh-cn"; |
| 14 | +} |
| 15 | +
|
| 16 | +const { locale = "en" } = Astro.props; |
| 17 | +const strings = FRONTIER_STRINGS[locale] as Record<string, string>; |
| 18 | +const fallback = FRONTIER_STRINGS.en as Record<string, string>; |
| 19 | +const t = (key: string): string => strings[key] ?? fallback[key] ?? key; |
| 20 | +const fill = (key: string, vars: Record<string, string>): string => |
| 21 | + Object.entries(vars).reduce((acc, [k, v]) => acc.replace(`{${k}}`, v), t(key)); |
| 22 | +
|
| 23 | +// The PR i18n has no column-header key for "score" — keep a tiny local map. |
| 24 | +const SCORE_HEADER: Record<string, string> = { en: "Score", ko: "점수", "zh-cn": "得分" }; |
| 25 | +/** Dataset tags are kebab-case; i18n keys are camelCase (cheap-subagent → cheapSubagent). */ |
| 26 | +const tagKey = (tag: string): string => tag.replace(/-([a-z])/g, (_, c) => c.toUpperCase()); |
| 27 | +
|
| 28 | +const boards = data.benchmarks.map(board => { |
| 29 | + const allMeasured = board.rows.every(row => row.costKind === "measured"); |
| 30 | + const bestValue = allMeasured |
| 31 | + ? board.rows.reduce((best, row) => (row.score / row.avgCostUsd > best.score / best.avgCostUsd ? row : best), board.rows[0]) |
| 32 | + : null; |
| 33 | + const chart = { |
| 34 | + id: board.id, |
| 35 | + xLabel: t(`frontier.board.${board.id}.xLabel`), |
| 36 | + yLabel: t(`frontier.board.${board.id}.yLabel`), |
| 37 | + xUnit: board.axes.xUnit, |
| 38 | + yUnit: board.axes.yUnit, |
| 39 | + rows: board.rows.map(row => ({ |
| 40 | + model: row.model, |
| 41 | + family: row.family, |
| 42 | + effort: row.effort ?? null, |
| 43 | + score: row.score, |
| 44 | + cost: row.avgCostUsd, |
| 45 | + })), |
| 46 | + }; |
| 47 | + return { ...board, allMeasured, bestValue, chart }; |
| 48 | +}); |
| 49 | +--- |
| 50 | + |
| 51 | +<div class="frontier-root"> |
| 52 | + <p class="frontier-subtitle">{t("frontier.subtitle")}</p> |
| 53 | + { |
| 54 | + boards.map(board => ( |
| 55 | + <section class="frontier-board" aria-label={t(`frontier.board.${board.id}.title`)}> |
| 56 | + <h3 id={`board-${board.id}`}>{t(`frontier.board.${board.id}.title`)}</h3> |
| 57 | + <p class="frontier-meta"> |
| 58 | + {fill("frontier.updated", { date: board.updated })} |
| 59 | + {" · "} |
| 60 | + {fill("frontier.tasks", { count: String(board.taskCount) })} |
| 61 | + {" · "} |
| 62 | + <a href={board.provenance.url}>{t("frontier.sourceLink")}</a> |
| 63 | + {board.provenance.license && <span class="frontier-license"> · {board.provenance.license}</span>} |
| 64 | + </p> |
| 65 | + <p class="frontier-note">{t(`frontier.board.${board.id}.sourceNote`)}</p> |
| 66 | + {!board.allMeasured && <p class="frontier-honesty">{t("frontier.costKindEstimated")}</p>} |
| 67 | + <div class="frontier-chart" role="img" aria-label={t("frontier.chartAria")} data-chart={JSON.stringify(board.chart)} /> |
| 68 | + <table> |
| 69 | + <thead> |
| 70 | + <tr> |
| 71 | + <th>{t("frontier.col.model")}</th> |
| 72 | + <th>{t("frontier.col.effort")}</th> |
| 73 | + <th>{SCORE_HEADER[locale] ?? SCORE_HEADER.en}</th> |
| 74 | + <th>{t("frontier.col.cost")}</th> |
| 75 | + {board.allMeasured && <th>{t("frontier.col.efficiency")}</th>} |
| 76 | + <th>{t("frontier.col.tags")}</th> |
| 77 | + </tr> |
| 78 | + </thead> |
| 79 | + <tbody> |
| 80 | + {board.rows.map(row => ( |
| 81 | + <tr class={board.bestValue && row.id === board.bestValue.id ? "frontier-best" : undefined}> |
| 82 | + <td> |
| 83 | + {row.model} |
| 84 | + {board.bestValue && row.id === board.bestValue.id && ( |
| 85 | + <span class="frontier-best-badge">{t("frontier.bestValue")}</span> |
| 86 | + )} |
| 87 | + </td> |
| 88 | + <td>{row.effort ?? "—"}</td> |
| 89 | + <td> |
| 90 | + {row.score} |
| 91 | + {board.axes.yUnit === "%" ? "%" : ""} |
| 92 | + {row.scoreCi ? ` ±${row.scoreCi}` : ""} |
| 93 | + </td> |
| 94 | + <td>${row.avgCostUsd}</td> |
| 95 | + {board.allMeasured && <td>{(row.score / row.avgCostUsd).toFixed(1)}</td>} |
| 96 | + <td>{(row.tags ?? []).map(tag => t(`frontier.tag.${tagKey(tag)}`)).join(", ") || "—"}</td> |
| 97 | + </tr> |
| 98 | + ))} |
| 99 | + </tbody> |
| 100 | + </table> |
| 101 | + </section> |
| 102 | + )) |
| 103 | + } |
| 104 | +</div> |
| 105 | + |
| 106 | +<style> |
| 107 | + .frontier-root .frontier-subtitle { |
| 108 | + color: var(--sl-color-gray-3); |
| 109 | + } |
| 110 | + .frontier-board { |
| 111 | + margin-top: 2.5rem; |
| 112 | + } |
| 113 | + .frontier-meta, |
| 114 | + .frontier-note { |
| 115 | + font-size: var(--sl-text-sm); |
| 116 | + color: var(--sl-color-gray-3); |
| 117 | + margin: 0.25rem 0; |
| 118 | + } |
| 119 | + .frontier-honesty { |
| 120 | + font-size: var(--sl-text-sm); |
| 121 | + border-left: 3px solid var(--sl-color-orange); |
| 122 | + padding-left: 0.75rem; |
| 123 | + color: var(--sl-color-gray-2); |
| 124 | + } |
| 125 | + .frontier-chart { |
| 126 | + width: 100%; |
| 127 | + height: 340px; |
| 128 | + margin: 1rem 0; |
| 129 | + } |
| 130 | + .frontier-best td { |
| 131 | + font-weight: 600; |
| 132 | + } |
| 133 | + .frontier-best-badge { |
| 134 | + margin-left: 0.5rem; |
| 135 | + font-size: var(--sl-text-xs); |
| 136 | + font-weight: 600; |
| 137 | + color: var(--sl-color-accent); |
| 138 | + border: 1px solid var(--sl-color-accent); |
| 139 | + border-radius: 999px; |
| 140 | + padding: 0 0.5rem; |
| 141 | + } |
| 142 | +</style> |
| 143 | + |
| 144 | +<script> |
| 145 | + import * as echarts from "echarts"; |
| 146 | + |
| 147 | + const FAMILY_COLORS: Record<string, string> = { |
| 148 | + openai: "#10a37f", |
| 149 | + anthropic: "#d97757", |
| 150 | + xai: "#1da1f2", |
| 151 | + google: "#4285f4", |
| 152 | + moonshot: "#7c3aed", |
| 153 | + zhipu: "#0ea5e9", |
| 154 | + cursor: "#f59e0b", |
| 155 | + deepseek: "#2563eb", |
| 156 | + other: "#6b7280", |
| 157 | + }; |
| 158 | + |
| 159 | + interface ChartRow { |
| 160 | + model: string; |
| 161 | + family: string; |
| 162 | + effort: string | null; |
| 163 | + score: number; |
| 164 | + cost: number; |
| 165 | + } |
| 166 | + interface ChartConfig { |
| 167 | + id: string; |
| 168 | + xLabel: string; |
| 169 | + yLabel: string; |
| 170 | + xUnit: string; |
| 171 | + yUnit: string; |
| 172 | + rows: ChartRow[]; |
| 173 | + } |
| 174 | + |
| 175 | + const charts: echarts.ECharts[] = []; |
| 176 | + |
| 177 | + function renderAll(): void { |
| 178 | + const textColor = getComputedStyle(document.body).color; |
| 179 | + document.querySelectorAll<HTMLElement>(".frontier-chart").forEach(el => { |
| 180 | + const cfg = JSON.parse(el.dataset.chart ?? "{}") as ChartConfig; |
| 181 | + const families = [...new Set(cfg.rows.map(r => r.family))]; |
| 182 | + let chart = echarts.getInstanceByDom(el); |
| 183 | + if (!chart) { |
| 184 | + chart = echarts.init(el); |
| 185 | + charts.push(chart); |
| 186 | + } |
| 187 | + chart.setOption( |
| 188 | + { |
| 189 | + textStyle: { color: textColor }, |
| 190 | + grid: { left: 56, right: 24, top: 32, bottom: 48 }, |
| 191 | + legend: { top: 0, textStyle: { color: textColor } }, |
| 192 | + tooltip: { |
| 193 | + trigger: "item", |
| 194 | + formatter: (p: { data: [number, number, string, string, string | null] }) => |
| 195 | + `${p.data[3]}${p.data[4] ? ` (${p.data[4]})` : ""}<br/>` + |
| 196 | + `${cfg.yLabel}: ${p.data[1]}${cfg.yUnit === "%" ? "%" : ""}<br/>` + |
| 197 | + `${cfg.xLabel}: $${p.data[0]}`, |
| 198 | + }, |
| 199 | + xAxis: { |
| 200 | + type: "value", |
| 201 | + scale: true, |
| 202 | + name: cfg.xLabel, |
| 203 | + nameLocation: "middle", |
| 204 | + nameGap: 30, |
| 205 | + axisLabel: { color: textColor }, |
| 206 | + nameTextStyle: { color: textColor }, |
| 207 | + }, |
| 208 | + yAxis: { |
| 209 | + type: "value", |
| 210 | + scale: true, |
| 211 | + name: cfg.yLabel, |
| 212 | + axisLabel: { color: textColor }, |
| 213 | + nameTextStyle: { color: textColor }, |
| 214 | + }, |
| 215 | + series: families.map(family => ({ |
| 216 | + name: family, |
| 217 | + type: "scatter", |
| 218 | + symbolSize: 11, |
| 219 | + itemStyle: { color: FAMILY_COLORS[family] ?? FAMILY_COLORS.other }, |
| 220 | + data: cfg.rows |
| 221 | + .filter(r => r.family === family) |
| 222 | + .map(r => [r.cost, r.score, r.family, r.model, r.effort]), |
| 223 | + })), |
| 224 | + }, |
| 225 | + { notMerge: true }, |
| 226 | + ); |
| 227 | + }); |
| 228 | + } |
| 229 | + |
| 230 | + renderAll(); |
| 231 | + window.addEventListener("resize", () => charts.forEach(c => c.resize())); |
| 232 | + // Starlight flips data-theme on <html> — re-render so axis/legend colors follow. |
| 233 | + new MutationObserver(() => renderAll()).observe(document.documentElement, { |
| 234 | + attributes: true, |
| 235 | + attributeFilter: ["data-theme"], |
| 236 | + }); |
| 237 | +</script> |
0 commit comments