Compare commits

...
Author SHA1 Message Date
vimtor 2288a1626b trim search index to essential fields and remove dead code 2026-05-13 12:21:52 +02:00
vimtor b3ecfc3d70 improve row scanning 2026-05-13 11:20:42 +02:00
vimtor 9828a0177d improve empty row 2026-05-12 19:49:03 +02:00
vimtor 4dee8d0d34 minor improvements 2026-05-12 19:10:21 +02:00
vimtor 950a0446d4 bring back svg loading 2026-05-08 20:18:12 +02:00
vimtor 41fbfb1a17 change sst mention 2026-05-08 20:13:09 +02:00
vimtor cf5045a90b move copy button next to name 2026-05-08 20:12:39 +02:00
vimtor ef739220de lock virtualized table column widths to prevent scroll jitter 2026-05-08 19:07:25 +02:00
vimtor 7294efee15 move row-render.ts to shared.ts 2026-05-08 18:30:14 +02:00
vimtor 1e537147eb remove table row tuple optimization 2026-05-08 18:24:18 +02:00
vimtor e9f4cecc54 extract shared row rendering module 2026-05-08 17:29:04 +02:00
vimtor fb1ac09883 virtualize model table 2026-05-08 17:07:28 +02:00
6 changed files with 562 additions and 334 deletions

No files matched your search

+3
View File
@@ -32,6 +32,7 @@
"packages/web": {
"name": "@models.dev/web",
"dependencies": {
"@tanstack/virtual-core": "^3.14.0",
"hono": "^4.8.0",
"models.dev": "workspace:*",
},
@@ -57,6 +58,8 @@
"@models.dev/web": ["@models.dev/web@workspace:packages/web"],
"@tanstack/virtual-core": ["@tanstack/virtual-core@3.14.0", "", {}, "sha512-JLANqGy/D6k4Ujmh8Tr25lGimuOXNiaVyXaCAZS0W+1390sADdGnyUdSWNIfd49gebtIxGMij4IktRVzrdr12Q=="],
"@tsconfig/bun": ["@tsconfig/bun@1.0.8", "", {}, "sha512-JlJaRaS4hBTypxtFe8WhnwV8blf0R+3yehLk8XuyxUYNx6VXsKCjACSCvOYEFUiqlhlBWxtYCn/zRlOb8BzBQg=="],
"@types/bun": ["@types/bun@1.3.0", "", { "dependencies": { "bun-types": "1.3.0" } }, "sha512-+lAGCYjXjip2qY375xX/scJeVRmZ5cY0wyHYyCYxNcdEXrQ4AOe3gACgd4iQ8ksOslJtW4VNxBJ8llUwc3a6AA=="],
+1
View File
@@ -6,6 +6,7 @@
"build": "./script/build.ts"
},
"dependencies": {
"@tanstack/virtual-core": "^3.14.0",
"hono": "^4.8.0",
"models.dev": "workspace:*"
},
+32 -8
View File
@@ -41,6 +41,8 @@
html,
body {
height: 100%;
overflow: hidden;
font-family: 'Rubik', sans-serif;
line-height: 1.6;
color: var(--color-text);
@@ -205,12 +207,17 @@ header {
}
}
.table-viewport {
height: calc(100svh - var(--header-height));
margin-top: var(--header-height);
overflow: auto;
}
table {
border-collapse: separate;
border-spacing: 0;
font-size: 0.875rem;
width: 100%;
margin-top: var(--header-height);
}
thead,
@@ -218,7 +225,7 @@ tbody {}
table thead th {
position: sticky;
top: var(--header-height);
top: 0;
border-top: 1px solid var(--color-border);
border-bottom: 1px solid var(--color-border);
font-size: 0.75rem;
@@ -264,6 +271,7 @@ td {
text-align: left;
border-bottom: 1px solid var(--color-border);
white-space: nowrap;
height: 48px;
}
tbody {
@@ -319,21 +327,37 @@ tbody {
gap: 0.375rem;
}
.provider-cell span:first-child {
flex: 0 0 auto;
}
.provider-cell img,
.provider-cell svg {
flex: 0 0 auto;
display: block;
width: 1rem;
height: 1rem;
color: var(--color-text-secondary);
}
.virtual-spacer td {
height: inherit;
padding: 0;
border-bottom: 0;
}
.empty-row td {
padding: 2rem 0.75rem;
color: var(--color-text-tertiary);
}
.empty-row div {
position: sticky;
left: 0;
width: calc(100vw - 1.5rem);
text-align: center;
}
.model-id-cell {
display: flex;
align-items: center;
justify-content: space-between;
justify-content: flex-start;
gap: 0.375rem;
}
@@ -546,4 +570,4 @@ dialog {
}
}
}
}
+295 -94
View File
@@ -1,7 +1,53 @@
import {
Virtualizer,
elementScroll,
observeElementOffset,
observeElementRect,
} from "@tanstack/virtual-core";
import {
type TableRow,
renderRow,
escapeHtml,
booleanText,
knowledgeText,
weightsText,
} from "./shared.js";
declare global {
interface Window {
__TABLE_DATA__: TableRow[];
}
}
interface VirtualizedRow extends TableRow {
key: string;
searchText: string;
sortValues: Array<string | number | undefined>;
}
type SortDirection = "asc" | "desc";
const ESTIMATED_ROW_HEIGHT = 48;
const VIRTUAL_OVERSCAN = 5;
const modal = document.getElementById("modal") as HTMLDialogElement;
const modalClose = document.getElementById("close")!;
const help = document.getElementById("help")!;
const search = document.getElementById("search")! as HTMLInputElement;
const viewport = document.getElementById("table-viewport") as HTMLElement;
const tbody = document.getElementById(
"models-table-body"
) as HTMLTableSectionElement;
const headers = Array.from(document.querySelectorAll("th.sortable"));
const columnCount = document.querySelectorAll("thead th").length;
let isLoaded = false;
let allRows: VirtualizedRow[] = [];
let visibleRows: VirtualizedRow[] = [];
let currentSort: { column: number; direction: SortDirection } = {
column: -1,
direction: "asc",
};
/////////////////////////
// URL State Management
@@ -31,10 +77,7 @@ function getColumnNameForURL(headerEl: Element): string {
}
function getColumnIndexByUrlName(name: string): number {
const headers = document.querySelectorAll("th.sortable");
return Array.from(headers).findIndex(
(header) => getColumnNameForURL(header) === name
);
return headers.findIndex((header) => getColumnNameForURL(header) === name);
}
/////////////////////////
@@ -63,32 +106,181 @@ modal.addEventListener("click", (e) => {
});
////////////////////
// Handle Sorting
// Row Data
////////////////////
let currentSort = { column: -1, direction: "asc" };
function lockColumnWidths() {
const ths = document.querySelectorAll("#models-table thead th");
const widths = Array.from(ths).map((th) => th.getBoundingClientRect().width);
function sortTable(column: number, direction: "asc" | "desc") {
const header = document.querySelectorAll("th.sortable")[column];
const columnType = header.getAttribute("data-type");
if (!columnType) return;
const measurementRow = tbody.querySelector('tr[aria-hidden="true"]');
if (measurementRow) measurementRow.remove();
// update state
currentSort = { column, direction };
updateQueryParams({
sort: getColumnNameForURL(header),
order: direction,
});
const table = document.getElementById("models-table")!;
table.style.tableLayout = "fixed";
// sort rows
const tbody = document.querySelector("table tbody")!;
const rows = Array.from(
tbody.querySelectorAll("tr")
) as HTMLTableRowElement[];
rows.sort((a, b) => {
const aValue = getCellValue(a.cells[column], columnType);
const bValue = getCellValue(b.cells[column], columnType);
const colgroup = document.createElement("colgroup");
for (const width of widths) {
const col = document.createElement("col");
col.style.width = `${width}px`;
colgroup.appendChild(col);
}
table.insertBefore(colgroup, table.firstChild);
}
function prepareRow(row: TableRow): VirtualizedRow {
const sortValues: VirtualizedRow["sortValues"] = [
row.providerName,
row.modelName,
row.family,
row.providerId,
row.modelId,
booleanText(row.toolCall),
booleanText(row.reasoning),
row.input.length,
row.output.length,
row.inputCost,
row.outputCost,
row.reasoningCost,
row.cacheReadCost,
row.cacheWriteCost,
row.audioInputCost,
row.audioOutputCost,
row.contextLimit,
row.inputLimit,
row.outputLimit,
row.structuredOutput === undefined
? undefined
: booleanText(row.structuredOutput),
booleanText(row.temperature),
weightsText(row.openWeights),
row.knowledge ? knowledgeText(row.knowledge) : undefined,
row.releaseDate,
row.lastUpdated,
];
const searchableValues = [
row.providerName,
row.modelName,
row.family ?? "",
row.providerId,
row.modelId,
row.releaseDate,
row.lastUpdated,
];
return {
...row,
key: `${row.providerId}/${row.modelId}`,
searchText: searchableValues.join(" ").toLowerCase(),
sortValues,
};
}
////////////////////
// Virtual Table
////////////////////
function getVirtualizerOptions(count: number) {
return {
count,
getScrollElement: () => viewport,
estimateSize: () => ESTIMATED_ROW_HEIGHT,
getItemKey: (index: number) => visibleRows[index]?.key ?? index,
initialRect: {
width: viewport.clientWidth || window.innerWidth,
height: viewport.clientHeight || window.innerHeight,
},
overscan: VIRTUAL_OVERSCAN,
observeElementRect,
observeElementOffset,
scrollToFn: elementScroll,
onChange: () => renderVirtualRows(),
};
}
const virtualizer = new Virtualizer<HTMLElement, HTMLTableRowElement>(
getVirtualizerOptions(0)
);
const cleanupVirtualizer = virtualizer._didMount();
virtualizer._willUpdate();
window.addEventListener("pagehide", () => cleanupVirtualizer());
function renderStatusRow(message: string) {
tbody.innerHTML = `<tr class="empty-row"><td colspan="${columnCount}"><div>${escapeHtml(
message
)}</div></td></tr>`;
}
function setVirtualizerCount(count: number, resetScroll: boolean) {
virtualizer.setOptions(getVirtualizerOptions(count));
virtualizer._willUpdate();
if (resetScroll) virtualizer.scrollToOffset(0);
renderVirtualRows();
}
function renderVirtualRows() {
if (!isLoaded) return;
if (visibleRows.length === 0) {
renderStatusRow("No models found");
return;
}
const virtualRows = virtualizer.getVirtualItems();
if (virtualRows.length === 0) return;
const firstRow = virtualRows[0]!;
const lastRow = virtualRows[virtualRows.length - 1]!;
const paddingTop = firstRow.start;
const paddingBottom = Math.max(virtualizer.getTotalSize() - lastRow.end, 0);
const html: string[] = [];
if (paddingTop > 0) html.push(renderSpacerRow(paddingTop));
for (const virtualRow of virtualRows) {
const row = visibleRows[virtualRow.index];
if (row) html.push(renderRow(row, virtualRow.index));
}
if (paddingBottom > 0) html.push(renderSpacerRow(paddingBottom));
tbody.innerHTML = html.join("");
tbody.querySelectorAll<HTMLTableRowElement>("tr[data-index]").forEach((row) =>
virtualizer.measureElement(row)
);
}
function renderSpacerRow(height: number) {
return `<tr class="virtual-spacer" style="height: ${height}px"><td colspan="${columnCount}"></td></tr>`;
}
function applyRows(resetScroll = true) {
if (!isLoaded) return;
visibleRows = getRowsForDisplay();
setVirtualizerCount(visibleRows.length, resetScroll);
}
////////////////////
// Sorting
////////////////////
function getRowsForDisplay() {
const terms = search.value
.toLowerCase()
.split(",")
.map((term) => term.trim())
.filter(Boolean);
const filteredRows =
terms.length === 0
? allRows
: allRows.filter((row) =>
terms.some((term) => row.searchText.includes(term))
);
if (currentSort.column === -1) return filteredRows;
const columnType = headers[currentSort.column]?.getAttribute("data-type");
if (!columnType) return filteredRows;
return [...filteredRows].sort((a, b) => {
const aValue = a.sortValues[currentSort.column];
const bValue = b.sortValues[currentSort.column];
// Handle undefined values - always sort to bottom
if (aValue === undefined && bValue === undefined) return 0;
if (aValue === undefined) return 1;
if (bValue === undefined) return -1;
@@ -96,45 +288,48 @@ function sortTable(column: number, direction: "asc" | "desc") {
let comparison = 0;
if (columnType === "number" || columnType === "modalities") {
comparison = (aValue as number) - (bValue as number);
} else if (columnType === "boolean") {
comparison = (aValue as string).localeCompare(bValue as string);
} else {
comparison = (aValue as string).localeCompare(bValue as string);
comparison = String(aValue).localeCompare(String(bValue));
}
return direction === "asc" ? comparison : -comparison;
return currentSort.direction === "asc" ? comparison : -comparison;
});
rows.forEach((row) => tbody.appendChild(row));
}
// update sort indicators
const headers = document.querySelectorAll("th.sortable");
function sortTable(
column: number,
direction: SortDirection,
updateURL = true
) {
const header = headers[column];
if (!header?.getAttribute("data-type")) return;
currentSort = { column, direction };
if (updateURL) {
updateQueryParams({
sort: getColumnNameForURL(header),
order: direction,
});
}
updateSortIndicators();
applyRows();
}
function updateSortIndicators() {
headers.forEach((header, i) => {
const indicator = header.querySelector(".sort-indicator")!;
if (i === column) {
indicator.textContent = direction === "asc" ? "↑" : "↓";
} else {
indicator.textContent = "";
}
indicator.textContent =
i === currentSort.column
? currentSort.direction === "asc"
? "↑"
: "↓"
: "";
});
}
function getCellValue(
cell: HTMLTableCellElement,
type: string
): string | number | undefined {
if (type === "modalities")
return cell.querySelectorAll(".modality-icon").length;
const text = cell.textContent?.trim() || "";
if (text === "-") return;
if (type === "number") return parseFloat(text.replace(/[$,]/g, "")) || 0;
return text;
}
document.querySelectorAll("th.sortable").forEach((header) => {
headers.forEach((header, column) => {
header.addEventListener("click", () => {
const column = Array.from(header.parentElement!.children).indexOf(header);
const direction =
currentSort.column === column && currentSort.direction === "asc"
? "desc"
@@ -144,34 +339,19 @@ document.querySelectorAll("th.sortable").forEach((header) => {
});
///////////////////
// Handle Search
// Search
///////////////////
function filterTable(value: string) {
const lowerCaseValues = value.toLowerCase().split(",").filter(str => str.trim() !== "");
const rows = document.querySelectorAll(
"table tbody tr"
) as NodeListOf<HTMLTableRowElement>;
rows.forEach((row) => {
const cellTexts = Array.from(row.cells).map((cell) =>
cell.textContent!.toLowerCase()
);
const isVisible = lowerCaseValues.length === 0 ||
lowerCaseValues.some((lowerCaseValue) => cellTexts.some((text) => text.includes(lowerCaseValue)));
row.style.display = isVisible ? "" : "none";
});
updateQueryParams({ search: value || null });
}
search.addEventListener("input", () => {
filterTable(search.value);
updateQueryParams({ search: search.value || null });
applyRows();
});
document.addEventListener("keydown", (e) => {
if ((e.metaKey || e.ctrlKey) && e.key === "k") {
const key = e.key.toLowerCase();
if ((e.metaKey || e.ctrlKey) && (key === "k" || key === "f")) {
e.preventDefault();
search.focus();
search.select();
}
});
@@ -185,10 +365,7 @@ search.addEventListener("keydown", (e) => {
///////////////////////////////////
// Handle Copy model ID function
///////////////////////////////////
(window as any).copyModelId = async (
button: HTMLButtonElement,
modelId: string
) => {
async function copyModelId(button: HTMLButtonElement, modelId: string) {
try {
if (navigator.clipboard) {
await navigator.clipboard.writeText(modelId);
@@ -209,7 +386,18 @@ search.addEventListener("keydown", (e) => {
} catch (err) {
console.error("Failed to copy text: ", err);
}
};
}
document.addEventListener("click", (event) => {
if (!(event.target instanceof Element)) return;
const button = event.target.closest<HTMLButtonElement>(
".copy-button[data-model-id]"
);
if (!button) return;
const modelId = button.dataset.modelId;
if (modelId) void copyModelId(button, modelId);
});
///////////////////////////////////
// Initialize State from URL
@@ -217,24 +405,37 @@ search.addEventListener("keydown", (e) => {
function initializeFromURL() {
const params = getQueryParams();
(() => {
const searchQuery = params.get("search");
if (!searchQuery) return;
search.value = searchQuery;
filterTable(searchQuery);
})();
(() => {
const columnName = params.get("sort");
if (!columnName) return;
search.value = params.get("search") ?? "";
currentSort = { column: -1, direction: "asc" };
const columnName = params.get("sort");
if (columnName) {
const columnIndex = getColumnIndexByUrlName(columnName);
if (columnIndex === -1) return;
if (columnIndex !== -1) {
currentSort = {
column: columnIndex,
direction: params.get("order") === "desc" ? "desc" : "asc",
};
}
}
const direction = (params.get("order") as "asc" | "desc") || "asc";
sortTable(columnIndex, direction);
})();
updateSortIndicators();
applyRows(false);
}
document.addEventListener("DOMContentLoaded", initializeFromURL);
function loadRows() {
try {
allRows = window.__TABLE_DATA__.map(prepareRow);
lockColumnWidths();
isLoaded = true;
initializeFromURL();
} catch (error) {
console.error(error);
isLoaded = true;
visibleRows = [];
renderStatusRow("Failed to load model data");
}
}
loadRows();
window.addEventListener("popstate", initializeFromURL);
+55 -232
View File
@@ -6,6 +6,7 @@ import { Fragment } from "hono/jsx";
import { renderToString } from "hono/jsx/dom/server";
import { existsSync } from "fs";
import path from "path";
import { type TableRow, renderRow, getLargestRow } from "./shared.js";
export const Providers = await generate(
path.join(import.meta.dir, "..", "..", "..", "providers")
@@ -38,7 +39,6 @@ const loadProviderSvg = async (providerId: string): Promise<string | null> => {
const file = Bun.file(providerLogoPath);
return await file.text();
}
//
// Fall back to default logo
if (existsSync(defaultLogoPath)) {
const file = Bun.file(defaultLogoPath);
@@ -62,122 +62,47 @@ for (const [providerId] of Object.entries(Providers)) {
}
}
function renderProviderLogo(providerId: string) {
const svgContent = providerLogos.get(providerId) || "";
export const INITIAL_ROW_COUNT = 50;
return <span dangerouslySetInnerHTML={{ __html: svgContent }} />;
}
export const TableRows: TableRow[] = Object.entries(Providers)
.sort(([, providerA], [, providerB]) =>
providerA.name.localeCompare(providerB.name)
)
.flatMap(([providerId, provider]) =>
Object.entries(provider.models)
.filter(([, model]) => model.status !== "alpha")
.sort(([, modelA], [, modelB]) => modelA.name.localeCompare(modelB.name))
.map(([modelId, model]) => ({
providerId,
providerName: provider.name,
providerLogoSvg: providerLogos.get(providerId) || "",
modelId,
modelName: model.name,
family: model.family,
toolCall: model.tool_call,
reasoning: model.reasoning,
input: model.modalities.input,
output: model.modalities.output,
inputCost: model.cost?.input,
outputCost: model.cost?.output,
reasoningCost: model.cost?.reasoning,
cacheReadCost: model.cost?.cache_read,
cacheWriteCost: model.cost?.cache_write,
audioInputCost: model.cost?.input_audio,
audioOutputCost: model.cost?.output_audio,
contextLimit: model.limit.context,
inputLimit: model.limit.input,
outputLimit: model.limit.output,
structuredOutput: model.structured_output,
temperature: model.temperature ?? false,
openWeights: model.open_weights,
knowledge: model.knowledge,
releaseDate: model.release_date,
lastUpdated: model.last_updated,
}))
);
const getModalityIcon = (modality: string) => {
switch (modality) {
case "text":
return (
<span class="modality-icon" data-tooltip="Text">
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<polyline points="4,7 4,4 20,4 20,7"></polyline>
<line x1="9" y1="20" x2="15" y2="20"></line>
<line x1="12" y1="4" x2="12" y2="20"></line>
</svg>
</span>
);
case "image":
return (
<span class="modality-icon" data-tooltip="Image">
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect width="18" height="18" x="3" y="3" rx="2" ry="2"></rect>
<circle cx="9" cy="9" r="2"></circle>
<path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"></path>
</svg>
</span>
);
case "audio":
return (
<span class="modality-icon" data-tooltip="Audio">
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"></polygon>
<path d="m19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"></path>
</svg>
</span>
);
case "video":
return (
<span class="modality-icon" data-tooltip="Video">
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m22 8-6 4 6 4V8Z"></path>
<rect width="14" height="12" x="2" y="6" rx="2" ry="2"></rect>
</svg>
</span>
);
case "pdf":
return (
<span class="modality-icon" data-tooltip="PDF">
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14,2 14,8 20,8"></polyline>
<line x1="16" y1="13" x2="8" y2="13"></line>
<line x1="16" y1="17" x2="8" y2="17"></line>
<polyline points="10,9 9,9 8,9"></polyline>
</svg>
</span>
);
default:
return null;
}
};
const renderCost = (cost?: number) => {
return cost === undefined ? "-" : `$${cost.toFixed(2)}`;
};
const largestRow = getLargestRow(TableRows);
export const Rendered = renderToString(
<Fragment>
@@ -213,7 +138,8 @@ export const Rendered = renderToString(
<button id="help">How to use</button>
</div>
</header>
<table>
<div id="table-viewport" class="table-viewport">
<table id="models-table">
<thead>
<tr>
<th class="sortable" data-type="text">
@@ -342,120 +268,12 @@ export const Rendered = renderToString(
</th>
</tr>
</thead>
<tbody>
{Object.entries(Providers)
.sort(([, providerA], [, providerB]) =>
providerA.name.localeCompare(providerB.name)
)
.flatMap(([providerId, provider]) =>
Object.entries(provider.models)
.filter(([, model]) => model.status !== "alpha")
.sort(([, modelA], [, modelB]) =>
modelA.name.localeCompare(modelB.name)
)
.map(([modelId, model]) => (
<tr key={`${providerId}-${modelId}`}>
<td>
<div class="provider-cell">
{renderProviderLogo(providerId)}
<span>{provider.name}</span>
</div>
</td>
<td>{model.name}</td>
<td>{model.family ?? "-"}</td>
<td>{providerId}</td>
<td>
<div class="model-id-cell">
<span class="model-id-text">{modelId}</span>
<button
class="copy-button"
onclick={`copyModelId(this, '${modelId}')`}
>
<svg
class="copy-icon"
xmlns="http://www.w3.org/2000/svg"
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect
width="14"
height="14"
x="8"
y="8"
rx="2"
ry="2"
/>
<path d="m4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
</svg>
<svg
class="check-icon"
xmlns="http://www.w3.org/2000/svg"
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
style="display: none;"
>
<polyline points="20,6 9,17 4,12" />
</svg>
</button>
</div>
</td>
<td>{model.tool_call ? "Yes" : "No"}</td>
<td>{model.reasoning ? "Yes" : "No"}</td>
<td>
<div class="modalities">
{model.modalities.input.map((modality) =>
getModalityIcon(modality)
)}
</div>
</td>
<td>
<div class="modalities">
{model.modalities.output.map((modality) =>
getModalityIcon(modality)
)}
</div>
</td>
<td>{renderCost(model.cost?.input)}</td>
<td>{renderCost(model.cost?.output)}</td>
<td>{renderCost(model.cost?.reasoning)}</td>
<td>{renderCost(model.cost?.cache_read)}</td>
<td>{renderCost(model.cost?.cache_write)}</td>
<td>{renderCost(model.cost?.input_audio)}</td>
<td>{renderCost(model.cost?.output_audio)}</td>
<td>{model.limit.context.toLocaleString()}</td>
<td>{model.limit.input?.toLocaleString() ?? "-"}</td>
<td>{model.limit.output.toLocaleString()}</td>
<td>
{model.structured_output === undefined
? "-"
: model.structured_output
? "Yes"
: "No"}
</td>
<td>{model.temperature ? "Yes" : "No"}</td>
<td>{model.open_weights ? "Open" : "Closed"}</td>
<td>
{model.knowledge ? model.knowledge.substring(0, 7) : "-"}
</td>
<td>{model.release_date}</td>
<td>{model.last_updated}</td>
</tr>
))
)}
</tbody>
</table>
<tbody id="models-table-body" dangerouslySetInnerHTML={{
__html: TableRows.slice(0, INITIAL_ROW_COUNT).map((row, i) => renderRow(row, i)).join('')
+ renderRow(largestRow, -1).replace('<tr', '<tr style="visibility:hidden" aria-hidden="true"')
}} />
</table>
</div>
<dialog id="modal">
<div class="header">
<h2>How to use</h2>
@@ -565,10 +383,15 @@ export const Rendered = renderToString(
>
Edit on GitHub
</a>
<a href="https://sst.dev" target="_blank" rel="noopener noreferrer">
Created by SST
<a href="https://opencode.ai" target="_blank" rel="noopener noreferrer">
Created by OpenCode
</a>
</div>
</dialog>
<script
dangerouslySetInnerHTML={{
__html: `window.__TABLE_DATA__ = ${JSON.stringify(TableRows)}`,
}}
></script>
</Fragment>
);
+176
View File
@@ -0,0 +1,176 @@
export interface TableRow {
providerId: string;
providerName: string;
providerLogoSvg: string;
modelId: string;
modelName: string;
family?: string;
toolCall: boolean;
reasoning: boolean;
input: string[];
output: string[];
inputCost?: number;
outputCost?: number;
reasoningCost?: number;
cacheReadCost?: number;
cacheWriteCost?: number;
audioInputCost?: number;
audioOutputCost?: number;
contextLimit: number;
inputLimit?: number;
outputLimit: number;
structuredOutput?: boolean;
temperature: boolean;
openWeights: boolean;
knowledge?: string;
releaseDate: string;
lastUpdated: string;
}
const MODALITY_ICONS: Record<string, string> = {
text: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4,7 4,4 20,4 20,7"></polyline><line x1="9" y1="20" x2="15" y2="20"></line><line x1="12" y1="4" x2="12" y2="20"></line></svg>`,
image: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"></rect><circle cx="9" cy="9" r="2"></circle><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"></path></svg>`,
audio: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"></polygon><path d="m19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"></path></svg>`,
video: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m22 8-6 4 6 4V8Z"></path><rect width="14" height="12" x="2" y="6" rx="2" ry="2"></rect></svg>`,
pdf: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14,2 14,8 20,8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10,9 9,9 8,9"></polyline></svg>`,
};
export function escapeHtml(value: string | number) {
return String(value).replace(/[&<>'"]/g, (char) => {
switch (char) {
case "&":
return "&amp;";
case "<":
return "&lt;";
case ">":
return "&gt;";
case "'":
return "&#39;";
case '"':
return "&quot;";
default:
return char;
}
});
}
export function booleanText(value: boolean) {
return value ? "Yes" : "No";
}
export function optionalBooleanText(value?: boolean) {
return value === undefined ? "-" : booleanText(value);
}
export function formatCost(cost?: number) {
return cost === undefined ? "-" : `$${cost.toFixed(2)}`;
}
export function formatNumber(value?: number) {
return value === undefined ? "-" : value.toLocaleString();
}
export function knowledgeText(value?: string) {
return value ? value.substring(0, 7) : "-";
}
export function weightsText(value: boolean) {
return value ? "Open" : "Closed";
}
export function renderModalityIcon(modality: string) {
const label =
modality === "pdf"
? "PDF"
: modality[0]!.toUpperCase() + modality.slice(1);
const icon = MODALITY_ICONS[modality];
if (!icon) return "";
return `<span class="modality-icon" data-tooltip="${label}">${icon}</span>`;
}
export function renderModalities(modalities: string[]) {
return `<div class="modalities">${modalities
.map(renderModalityIcon)
.join("")}</div>`;
}
export function renderCopyButton(modelId: string) {
const escapedModelId = escapeHtml(modelId);
return `<button type="button" class="copy-button" data-model-id="${escapedModelId}" aria-label="Copy model ID"><svg class="copy-icon" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"></rect><path d="m4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"></path></svg><svg class="check-icon" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><polyline points="20,6 9,17 4,12"></polyline></svg></button>`;
}
export function renderRow(row: TableRow, index: number) {
return `<tr data-index="${index}">
<td><div class="provider-cell">${row.providerLogoSvg}<span>${escapeHtml(
row.providerName
)}</span></div></td>
<td>${escapeHtml(row.modelName)}</td>
<td>${escapeHtml(row.family ?? "-")}</td>
<td>${escapeHtml(row.providerId)}</td>
<td><div class="model-id-cell"><span class="model-id-text">${escapeHtml(
row.modelId
)}</span>${renderCopyButton(row.modelId)}</div></td>
<td>${booleanText(row.toolCall)}</td>
<td>${booleanText(row.reasoning)}</td>
<td>${renderModalities(row.input)}</td>
<td>${renderModalities(row.output)}</td>
<td>${formatCost(row.inputCost)}</td>
<td>${formatCost(row.outputCost)}</td>
<td>${formatCost(row.reasoningCost)}</td>
<td>${formatCost(row.cacheReadCost)}</td>
<td>${formatCost(row.cacheWriteCost)}</td>
<td>${formatCost(row.audioInputCost)}</td>
<td>${formatCost(row.audioOutputCost)}</td>
<td>${formatNumber(row.contextLimit)}</td>
<td>${formatNumber(row.inputLimit)}</td>
<td>${formatNumber(row.outputLimit)}</td>
<td>${optionalBooleanText(row.structuredOutput)}</td>
<td>${booleanText(row.temperature)}</td>
<td>${weightsText(row.openWeights)}</td>
<td>${knowledgeText(row.knowledge)}</td>
<td>${escapeHtml(row.releaseDate)}</td>
<td>${escapeHtml(row.lastUpdated)}</td>
</tr>`;
}
export function getLargestRow(rows: TableRow[]): TableRow {
const worst: TableRow = {
providerId: "", providerName: "", providerLogoSvg: "", modelId: "", modelName: "",
toolCall: true, reasoning: true,
input: [], output: [],
contextLimit: 0, outputLimit: 0,
structuredOutput: true, temperature: true, openWeights: false,
releaseDate: "", lastUpdated: "",
};
for (const row of rows) {
if (row.providerName.length > worst.providerName.length) worst.providerName = row.providerName;
if (row.modelName.length > worst.modelName.length) worst.modelName = row.modelName;
if ((row.family ?? "").length > (worst.family ?? "").length) worst.family = row.family;
if (row.providerId.length > worst.providerId.length) worst.providerId = row.providerId;
if (row.modelId.length > worst.modelId.length) worst.modelId = row.modelId;
if ((row.knowledge ?? "").length > (worst.knowledge ?? "").length) worst.knowledge = row.knowledge;
if (row.releaseDate.length > worst.releaseDate.length) worst.releaseDate = row.releaseDate;
if (row.lastUpdated.length > worst.lastUpdated.length) worst.lastUpdated = row.lastUpdated;
if (row.input.length > worst.input.length) worst.input = row.input;
if (row.output.length > worst.output.length) worst.output = row.output;
const costWider = (a: number | undefined, b: number | undefined) =>
b !== undefined && (a === undefined || formatCost(b).length > formatCost(a).length);
if (costWider(worst.inputCost, row.inputCost)) worst.inputCost = row.inputCost;
if (costWider(worst.outputCost, row.outputCost)) worst.outputCost = row.outputCost;
if (costWider(worst.reasoningCost, row.reasoningCost)) worst.reasoningCost = row.reasoningCost;
if (costWider(worst.cacheReadCost, row.cacheReadCost)) worst.cacheReadCost = row.cacheReadCost;
if (costWider(worst.cacheWriteCost, row.cacheWriteCost)) worst.cacheWriteCost = row.cacheWriteCost;
if (costWider(worst.audioInputCost, row.audioInputCost)) worst.audioInputCost = row.audioInputCost;
if (costWider(worst.audioOutputCost, row.audioOutputCost)) worst.audioOutputCost = row.audioOutputCost;
const numWider = (a: number | undefined, b: number | undefined) =>
b !== undefined && (a === undefined || formatNumber(b).length > formatNumber(a).length);
if (numWider(worst.contextLimit as number | undefined, row.contextLimit)) worst.contextLimit = row.contextLimit;
if (numWider(worst.inputLimit, row.inputLimit)) worst.inputLimit = row.inputLimit;
if (numWider(worst.outputLimit as number | undefined, row.outputLimit)) worst.outputLimit = row.outputLimit;
}
return worst;
}