import "../index.css" import { Link, Meta, Title } from "@solidjs/meta" import { ProviderIcon } from "@opencode-ai/ui/provider-icon" import { geoEquirectangular, geoPath } from "d3-geo" import { scaleSqrt } from "d3-scale" import countryCodesSource from "i18n-iso-countries/codes.json?raw" import { feature, mesh } from "topojson-client" import countriesTopologySource from "world-atlas/countries-110m.json?raw" import { getStatsModelData, type CountryEntry, type ModelPeerEntry, type ModelUsagePoint, type StatsModelData, type UsageRange, } from "@opencode-ai/stats-core/domain/home" import { runtime } from "@opencode-ai/stats-core/runtime" import { createAsync, query, useParams } from "@solidjs/router" import { createMemo, createSignal, For, onMount, Show, type JSX } from "solid-js" import { getRequestEvent } from "solid-js/web" import type { FeatureCollection, GeometryObject, GeoJsonProperties } from "geojson" import type { GeometryCollection, Topology } from "topojson-specification" import { findModelCatalogEntry, formatCatalogLabName, getModelCatalog, type ModelCatalogEntry } from "../model-catalog" import { applyThemePreference, Footer, getGitHubStars, Header, isThemePreference, themeStorageKey, type HeaderLink, type ThemePreference, } from "../stats-shell" const statsCanonicalBaseUrl = "https://opencode.ai/data/" const statsUnfurlPath = "banner.png" const statsUnfurlAlt = "OpenCode Data wordmark on a dark patterned background" const statsUnfurlUrl = new URL(statsUnfurlPath, statsCanonicalBaseUrl).toString() const modelHeaderLinks: readonly HeaderLink[] = [ { href: "#overview", label: "Overview" }, { href: "#usage", label: "Usage" }, { href: "#efficiency", label: "Efficiency" }, { href: "#geo-breakdown", label: "Geo Breakdown" }, { href: "#peers", label: "Peers" }, ] const modelFooterLinks: readonly HeaderLink[] = [ { href: import.meta.env.BASE_URL, label: "Data Home" }, { href: `${import.meta.env.BASE_URL}#top-models`, label: "Top Models" }, { href: `${import.meta.env.BASE_URL}#leaderboard`, label: "Leaderboard" }, { href: `${import.meta.env.BASE_URL}#session-cost`, label: "Session Cost" }, { href: `${import.meta.env.BASE_URL}#token-cost`, label: "Token Cost" }, { href: `${import.meta.env.BASE_URL}#market-share`, label: "Market Share" }, { href: `${import.meta.env.BASE_URL}#geo-breakdown`, label: "Geo Breakdown" }, ] const geoMapWidth = 960 const geoMapHeight = 430 const countryDisplayNames = new Intl.DisplayNames(["en"], { type: "region" }) type IsoCountryCode = readonly [string, string, string] type WorldCountryProperties = GeoJsonProperties & { name?: string } type WorldTopology = Topology<{ countries: GeometryCollection }> const countryNumericIds = new Map( (JSON.parse(countryCodesSource) as IsoCountryCode[]).map((country) => [country[0], country[2]] as const), ) const worldTopology = JSON.parse(countriesTopologySource) as WorldTopology const worldCountryGeometries: GeometryCollection = { ...worldTopology.objects.countries, geometries: worldTopology.objects.countries.geometries.filter((country) => String(country.id ?? "") !== "010"), } const worldCountries = feature(worldTopology, worldCountryGeometries) as FeatureCollection< GeometryObject, WorldCountryProperties > const worldProjection = geoEquirectangular().fitExtent( [ [10, 12], [geoMapWidth - 10, geoMapHeight - 12], ], worldCountries, ) const worldPath = geoPath(worldProjection) const worldCountryPaths = worldCountries.features.map((country) => ({ id: String(country.id ?? "").padStart(3, "0"), path: worldPath(country) ?? "", })) const worldBorderPath = worldPath(mesh(worldTopology, worldCountryGeometries, (a, b) => a !== b)) ?? "" const getModelData = query(async (lab: string, model: string) => { "use server" return runtime.runPromise(getStatsModelData(model, lab)) }, "getStatsModelData") export default function StatsModel() { const event = getRequestEvent() event?.response.headers.set("Cache-Control", "public, max-age=60, s-maxage=300, stale-while-revalidate=86400") const params = useParams() const labParam = createMemo(() => params.lab ?? "") const modelParam = createMemo(() => params.model ?? "") const catalog = createAsync(() => getModelCatalog()) const catalogEntry = createMemo(() => { const data = catalog() if (!data) return undefined return findModelCatalogEntry(data, modelParam(), labParam()) ?? null }) const stats = createAsync(() => { const entry = catalogEntry() if (catalog() === undefined || entry === undefined) return Promise.resolve(undefined) if (!entry && (!labParam() || !modelParam())) return Promise.resolve(null) return getModelData(labParam(), entry?.slug ?? modelParam()) }) const githubStars = createAsync(() => getGitHubStars()) const [themePreference, setThemePreference] = createSignal("system") const modelName = createMemo(() => catalogEntry()?.name ?? stats()?.model ?? modelParam() ?? "Model") const labName = createMemo(() => formatCatalogLabName(catalogEntry()?.lab ?? stats()?.provider ?? labParam())) const modelTitle = createMemo(() => `${modelName()} Data`) const modelDescription = createMemo(() => stats() ? `${modelName()} usage, rank, token mix, cost, geo breakdown, and peer data across OpenCode.` : `${modelName()} model facts, limits, and OpenCode usage availability.`, ) const modelUrl = createMemo(() => new URL( catalogEntry()?.id ?? [labParam(), stats()?.slug ?? modelParam()].filter((part) => part.length > 0).join("/"), statsCanonicalBaseUrl, ).toString(), ) const updateThemePreference = (preference: ThemePreference) => { applyThemePreference(preference) setThemePreference(preference) if (typeof window === "undefined") return window.localStorage.setItem(themeStorageKey, preference) } onMount(() => { if (typeof window === "undefined") return const preference = window.localStorage.getItem(themeStorageKey) const nextPreference = isThemePreference(preference) ? preference : "system" applyThemePreference(nextPreference) setThemePreference(nextPreference) }) return (
{modelTitle()}
}> }> <>
) } function ModelLoading() { return ( <>
Data

Model Data

Reading model aggregates from model_stat.

) } function ModelNotFound(props: { lab: string; model: string }) { return ( <>
Data

{props.model || "Model"}

No model facts or model_stat rows matched {props.lab ? `${props.lab}/${props.model}` : props.model}.

) } function ModelHero(props: { data: StatsModelData | null; catalog: ModelCatalogEntry | null; labName: string }) { const labId = () => props.catalog?.lab ?? props.data?.provider ?? props.labName const modelId = () => props.catalog?.id ?? props.data?.model ?? "Model" const weights = () => props.catalog?.weights[0] return (
Data
{modelId()}

{props.catalog?.name ?? props.data?.model ?? "Model"}

Model facts from the shared model index. OpenCode usage appears once this model has activity.

} > {(data) => (

Ranked #{data().rank} across recent OpenCode token usage with {formatPercent(data().tokenShare)} of observed volume.

)}
{(weight) => ( Model weights: {weight().label} )}
}> {(data) => (
Current Rank #{data().rank}

{formatRankMoveLabel(data().previousRank, data().rank)}

)}
) } function ModelCatalogCallout(props: { catalog: ModelCatalogEntry | null }) { return (
Model Profile {props.catalog?.releaseDate ? formatCatalogDate(props.catalog.releaseDate) : "Listed"}

No OpenCode usage in the current data window.

) } function ModelCatalogPanel(props: { data: ModelCatalogEntry }) { return ( ) } function CatalogDatum(props: { label: string; value: string }) { return (
{props.label} {props.value}
) } function ModelOverview(props: { data: StatsModelData | null }) { return (
} > {(data) => (
)}
) } function ModelUsageSection(props: { data: ModelUsagePoint[] }) { const [activeIndex, setActiveIndex] = createSignal() const max = createMemo(() => Math.max(0, ...props.data.map((item) => item.tokens)) || 1) const activePoint = createMemo(() => { const index = activeIndex() if (index === undefined) return undefined return props.data[index] }) return (
item.tokens > 0)} fallback={} >
{ if (event.pointerType === "touch") return setActiveIndex(undefined) }} >
{(point, index) => (
{ if (event.pointerType !== "touch") return setActiveIndex(index()) }} onPointerEnter={() => setActiveIndex(index())} onPointerMove={(event) => { if (event.pointerType === "touch") return setActiveIndex(index()) }} onClick={() => setActiveIndex(index())} onFocus={() => setActiveIndex(index())} onBlur={() => setActiveIndex(undefined)} onKeyDown={(event) => { if (event.key !== "Enter" && event.key !== " ") return event.preventDefault() setActiveIndex(index()) }} >
{(active) => (
props.data.length * 0.62 ? "left" : "right"} > {active().date} {formatTokens(active().tokens)} tokens

Daily tokens {formatTokens(active().tokens)}

)}
)}
) } function ModelEfficiencySection(props: { data: StatsModelData | null }) { return (
} > {(data) => (
)}
) } function ModelGeoBreakdownSection(props: { data: Record }) { const [activeCountry, setActiveCountry] = createSignal() const data = createMemo(() => props.data["2M"]) const countryById = createMemo( () => new Map( data().flatMap((country) => { const id = countryNumericId(country.country) return id ? [[id, country] as const] : [] }), ), ) const maxTokens = createMemo(() => Math.max(0, ...data().map((country) => country.tokens)) || 1) const topCountries = createMemo(() => data().slice(0, 15)) const active = createMemo(() => data().find((country) => country.country === activeCountry()) ?? data()[0]) return (
{ if (event.pointerType === "touch") return setActiveCountry(undefined) }} > 0} fallback={} >
{(country) => (
#{String(country().rank).padStart(2, "0")} {formatCountryName(country().country)}

{formatGeoTokens(country().tokens)} {formatGeoShare(country().share)}

)}
) } function GeoWorldMap(props: { countryById: Map activeCountry: string | undefined maxTokens: number onActiveCountryChange: (country: string | undefined) => void }) { const opacityScale = createMemo(() => scaleSqrt().domain([0, props.maxTokens]).range([0.26, 0.96]).clamp(true)) const countryOpacity = (country: CountryEntry | undefined) => { if (!country) return 0 const opacity = opacityScale()(country.tokens) if (!props.activeCountry || props.activeCountry === country.country) return opacity return Math.max(0.18, opacity * 0.36) } return ( Geo Breakdown map {(country) => { const entry = () => props.countryById.get(country.id) return ( ) } function GeoCountryList(props: { data: CountryEntry[] activeCountry: string | undefined maxTokens: number onActiveCountryChange: (country: string | undefined) => void }) { const opacityScale = createMemo(() => scaleSqrt().domain([0, props.maxTokens]).range([0.26, 0.96]).clamp(true)) return (
    {(country) => (
  1. )}
) } function ModelPeersSection(props: { data: StatsModelData | null }) { return (
} >
    {(peer) => }
) } function MetricCard(props: { label: string; value: string; detail: string; state?: "positive" | "negative" }) { return (
{props.label} {props.value}

{props.detail}

) } function PeerRow(props: { peer: ModelPeerEntry; active: boolean }) { return (
  • {String(props.peer.rank).padStart(2, "0")}
  • ) } function SectionTitle(props: { title: string; description: string }) { return (

    {props.title}. {props.description}

    ) } function ModelEmptyState(props: { title: string; description: string; compact?: boolean }) { return (
    {props.title}

    {props.description}

    ) } function getProviderIconId(author: string) { if (author === "MiniMax") return "minimax" if (author === "Moonshot") return "moonshotai" if (author === "Zhipu") return "zhipuai" return author.toLowerCase().replace(/[^a-z0-9]+/g, "") } function emptyCountryRecord(): Record { return { "1D": [], "1W": [], "2W": [], "1M": [], "2M": [], "3M": [], YTD: [], ALL: [], } } function countryNumericId(country: string) { return countryNumericIds.get(country.toUpperCase())?.padStart(3, "0") } function formatCountryName(country: string) { const code = country.toUpperCase() if (code === "ZZ") return "Unknown" if (!countryNumericId(code)) return code return countryDisplayNames.of(code) ?? code } function formatGeoTokens(value: number) { return formatTokens(value * 1_000_000_000_000) } function formatGeoShare(value: number) { return `${value.toFixed(value > 0 && value < 1 ? 1 : 0)}%` } function modelUsageHeight(tokens: number, max: number) { if (tokens <= 0) return 0 return Math.max(2, Math.min(100, (tokens / max) * 100)) } function isModelUsageDense(count: number) { return count > 20 } function isModelUsageLabelHidden(index: number, count: number) { if (count <= 16) return false const interval = Math.ceil(count / 8) return index !== count - 1 && index % interval !== 0 } function formatRankMove(previousRank: number, rank: number) { const change = previousRank - rank if (change > 0) return `+${change}` if (change < 0) return `${change}` return "Even" } function formatRankMoveLabel(previousRank: number | null, rank: number) { return previousRank === null ? "New in window" : `${formatRankMove(previousRank, rank)} vs previous window` } function formatTokens(value: number) { if (value >= 1_000_000_000_000) return `${trimNumber(value / 1_000_000_000_000, value >= 10_000_000_000_000 ? 0 : 1)}T` if (value >= 1_000_000_000) return `${trimNumber(value / 1_000_000_000, value >= 10_000_000_000 ? 0 : 1)}B` if (value >= 1_000_000) return `${trimNumber(value / 1_000_000, value >= 10_000_000 ? 0 : 1)}M` if (value >= 1_000) return `${trimNumber(value / 1_000, value >= 10_000 ? 0 : 1)}K` return String(Math.round(value)) } function formatInteger(value: number) { return new Intl.NumberFormat("en").format(value) } function formatPercent(value: number) { return `${value.toFixed(value > 0 && value < 10 ? 1 : 0)}%` } function formatMoney(value: number) { if (value >= 1_000_000) return `$${trimNumber(value / 1_000_000, value >= 10_000_000 ? 0 : 1)}M` if (value >= 1_000) return `$${trimNumber(value / 1_000, value >= 10_000 ? 0 : 1)}K` return `$${value.toFixed(value >= 10 ? 0 : 2)}` } function formatSessionCost(value: number) { return `$${value.toFixed(value > 0 && value < 0.01 ? 4 : 2)}` } function formatChange(value: number) { if (value > 0) return `+${value}%` return `${value}%` } function formatCatalogLimit(value: number | undefined) { return value === undefined ? "Unknown" : formatTokens(value) } function formatCatalogModalities(value: string[]) { if (value.length === 0) return "Unknown" return value.map(formatCatalogModality).join(", ") } function formatCatalogModality(value: string) { if (value === "pdf") return "PDF" return value.charAt(0).toUpperCase() + value.slice(1) } function formatCatalogDate(value: string | undefined) { if (!value) return "Unknown" const match = /^(\d{4})(?:-(\d{2}))?(?:-(\d{2}))?$/.exec(value) if (!match) return value const year = Number(match[1]) const month = match[2] ? Number(match[2]) - 1 : 0 const day = match[3] ? Number(match[3]) : 1 return new Intl.DateTimeFormat("en", { month: match[2] ? "short" : undefined, day: match[3] ? "numeric" : undefined, year: "numeric", timeZone: "UTC", }).format(new Date(Date.UTC(year, month, day))) } function trimNumber(value: number, digits: number) { return Number(value.toFixed(digits)).toLocaleString("en") } function providerSlug(provider: string) { return provider .trim() .toLowerCase() .replace(/[^a-z0-9]+/g, "-") .replace(/^-+|-+$/g, "") .replace(/-{2,}/g, "-") }