Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

index.tsx

447 lines16.3 KB

1import { useEffect } from 'react'
2import { createFileRoute } from '@tanstack/react-router'
3import { createServerFn } from '@tanstack/react-start'
4​
5import { registerWebMcp } from '#/lib/webmcp.ts'
6import { timeAgo } from '#/lib/time.ts'
7import { EXAMPLES } from '#/lib/examples.ts'
8​
9import {
10 ChangeSummary,
11 CodePanel,
12 SectionHead,
13 SiteFooter,
14 SiteNav,
15 StatusDot,
16} from '#/components/site.tsx'
17import type { Completeness, ServiceStatus } from '#/server/status.ts'
18​
19interface DashboardChange {
20 id: string
21 type: string
22 providerId: string
23 subjectId: string
24 summary: string
25 createdAt: number
27​
28interface DashboardData {
29 status: ServiceStatus
30 changes: Array<DashboardChange>
32​
33const getDashboardData = createServerFn({ method: 'GET' }).handler(
34 async (): Promise<DashboardData> => {
35 const { env } = await import('cloudflare:workers')
36 const { getDb } = await import('#/db/index.ts')
37 const { getServiceStatus } = await import('#/server/status.ts')
38 const { listChanges } = await import('#/server/changes-api.ts')
39​
40 const db = getDb(env)
41 const [status, changesOutcome] = await Promise.all([
42 getServiceStatus(db),
43 // Updates are mostly router prices moving poll to poll; additions
44 // are what a visitor wants to see first.
45 listChanges(db, { type: 'model.added', limit: 8 }),
46 ])
47 return {
48 status,
49 changes: changesOutcome.ok
50 ? changesOutcome.result.changes.map((c) => ({
51 id: c.id,
52 type: c.type,
53 providerId: c.providerId,
54 subjectId: c.subjectId,
55 summary: c.summary,
56 createdAt: c.createdAt,
57 }))
58 : [],
59 }
60 },
62​
63export const Route = createFileRoute('/')({
64 loader: () => getDashboardData(),
65 component: Landing,
66})
67​
68const fmt = new Intl.NumberFormat('en-US')
69​
70/** Whole-percent coverage, or null when there is nothing to cover. */
71const pct = (part: number, whole: number) =>
72 whole > 0 ? Math.round((part / whole) * 100) : null
73const showPct = (value: number | null) => (value === null ? '—' : `${value}%`)
74/** "2026-10-07 05:15Z (3 polls)" for a status marker's tooltip. */
75const since = (record: { since: number; polls: number }) =>
76 `${new Date(record.since * 1000).toISOString().slice(0, 16).replace('T', ' ')}Z (${record.polls} ${record.polls === 1 ? 'poll' : 'polls'})`
77​
78/** An amber word beside the status dot; the detail is its tooltip and label. */
79function Marker({ label, text }: { label: string; text: string }) {
80 return (
81 <span
82 className="ml-2 cursor-help text-xs text-tok-amber"
83 title={text}
84 aria-label={text}
85 >
86 {label}
87 </span>
88 )
90​
91function completenessNote(c: Completeness): string {
92 // Defensive: nothing `/v1/status` sends may throw in render.
93 const silent = Array.isArray(c.silent) ? c.silent.join(', ') : ''
94 if (c.needed === 0) {
95 return `Nothing to fill across ${c.chat} chat models: this provider does not publish ${silent}`
96 }
97 return `${c.filled} of ${c.needed} facts filled across ${c.chat} chat models${silent ? `; not published by this provider: ${silent}` : ''}`
99​
100function Landing() {
101 const { status, changes } = Route.useLoaderData()
102 // WebMCP (task 10.6): in-page tools for browsers that ship
103 // navigator.modelContext; silently absent everywhere else.
104 useEffect(() => {
105 registerWebMcp()
106 }, [])
107 const totals = status.providers.reduce(
108 (acc, p) => ({
109 models: acc.models + p.counts.models,
110 endpoints: acc.endpoints + p.counts.endpoints,
111 schemas: acc.schemas + p.counts.schemas,
112 }),
113 { models: 0, endpoints: 0, schemas: 0 },
114 )
115 // Unweighted across providers, so one huge catalog can't swamp the rest.
116 const pricePcts = status.providers
117 .map((p) => pct(p.counts.priced, p.counts.models))
118 .filter((v) => v !== null)
119 const avgPrice = pricePcts.length
120 ? Math.round(pricePcts.reduce((a, b) => a + b, 0) / pricePcts.length)
121 : null
122 const lastPolledAt = Math.max(
123 0,
124 ...status.providers.map((p) => p.lastPolledAt ?? 0),
125 )
126 const lastSyncedAt = Math.max(
127 0,
128 ...status.providers.map((p) => p.lastSyncedAt ?? 0),
129 )
130​
131 return (
132 <div className="min-h-screen text-ink">
133 <SiteNav />
134​
135 <main className="mx-auto max-w-[1080px] px-6 pb-16">
136 <header className="pt-13">
137 <h1 className="m-0 mb-3 max-w-[30em] font-mono text-[clamp(22px,3.4vw,30px)] leading-[1.25] font-semibold tracking-[-0.01em] text-balance">
138 Live request &amp; response schemas for every AI model API
139 <span className="text-tok-blue">▌</span>
140 </h1>
141 <p className="m-0 mb-6 max-w-[40em] text-[14.5px] text-ink-soft">
142 Which models exist right now, and what their payloads look like.
143 JSON Schemas for {status.providers.length} providers, refreshed
144 automatically, served as plain JSON over HTTP — no key needed for
145 reads.
146 </p>
147​
148 <CodePanel
149 title="try it"
150 copyText="curl https://modelschemas.com/v1/models?q=claude"
151 >
152 <code>
153 <span className="prompt">$</span> curl{' '}
154 <span className="cj-str">
155 https://modelschemas.com/v1/models?q=claude
156 </span>
157 {'\n'}
158 <span className="cj-dim">{'{'} </span>
159 <span className="cj-key">"id"</span>
160 <span className="cj-dim">: </span>
161 <span className="cj-str">"anthropic-claude-sonnet-5"</span>
162 <span className="cj-dim">, </span>
163 <span className="cj-key">"rawId"</span>
164 <span className="cj-dim">: </span>
165 <span className="cj-str">"claude-sonnet-5"</span>
166 <span className="cj-dim">, </span>
167 <span className="cj-key">"lastSeenAt"</span>
168 <span className="cj-dim">: </span>
169 <span className="cj-num">{lastPolledAt || 1783408549}</span>
170 <span className="cj-dim">, … {'}'}</span>
171 </code>
172 </CodePanel>
173​
174 <div className="mt-5 flex flex-wrap gap-2.5 font-mono text-[12.5px]">
175 <a
176 href="/models"
177 className="rounded-[4px] border border-ink bg-ink px-3.5 py-2 text-paper transition-opacity hover:opacity-85"
178 >
179 GET /v1/models
180 </a>
181 <a
182 href="/schemas"
183 className="rounded-[4px] border border-rule-strong px-3.5 py-2 transition-colors hover:border-ink"
184 >
185 GET /v1/schemas
186 </a>
187 <a
188 href="/docs"
189 className="rounded-[4px] border border-rule-strong px-3.5 py-2 transition-colors hover:border-ink"
190 >
191 docs
192 </a>
193 <a
194 href="/mcp"
195 className="rounded-[4px] border border-rule-strong px-3.5 py-2 transition-colors hover:border-ink"
196 >
197 /mcp
198 </a>
199 <a
200 href="/llms.txt"
201 className="rounded-[4px] border border-rule-strong px-3.5 py-2 transition-colors hover:border-ink"
202 >
203 /llms.txt
204 </a>
205 </div>
206​
207 <div className="hairline mt-11 flex flex-wrap gap-x-5 gap-y-2 border-y py-3 font-mono text-xs text-ink-soft">
208 <span className="inline-flex items-center gap-2">
209 <span className="pulse-dot bg-tok-green" />
210 <span className="text-tok-green">live</span>
211 </span>
212 <span>
213 <b className="font-semibold text-ink tabular-nums">
214 {status.providers.length}
215 </b>{' '}
216 providers
217 </span>
218 <span>
219 <b className="font-semibold text-ink tabular-nums">
220 {fmt.format(totals.models)}
221 </b>{' '}
222 models
223 </span>
224 <span>
225 <b className="font-semibold text-ink tabular-nums">
226 {fmt.format(totals.endpoints)}
227 </b>{' '}
228 endpoints
229 </span>
230 <span>
231 <b className="font-semibold text-ink tabular-nums">
232 {fmt.format(totals.schemas)}
233 </b>{' '}
234 schema versions
235 </span>
236 <span>
237 <b className="font-semibold text-ink tabular-nums">
238 {showPct(avgPrice)}
239 </b>{' '}
240 priced, avg per provider
241 </span>
242 <span>
243 polled{' '}
244 <b className="font-semibold text-ink">{timeAgo(lastPolledAt)}</b>{' '}
245 · specs synced{' '}
246 <b className="font-semibold text-ink">{timeAgo(lastSyncedAt)}</b>
247 </span>
248 </div>
249 </header>
250​
251 <section>
252 <SectionHead
253 title="Providers"
254 aside={
255 <a className="press-link" href="/v1/providers">
256 GET /v1/providers →
257 </a>
258 }
259 />
260 <div className="figure overflow-x-auto">
261 <table className="dtable dtable-cards">
262 <thead>
263 <tr>
264 <th>provider</th>
265 <th>status</th>
266 <th className="num">models</th>
267 <th className="num">endpoints</th>
268 <th className="num">schemas</th>
269 <th className="num" title="Share of models with a price card">
270 priced
271 </th>
272 <th
273 className="num"
274 title="Chat completeness: the share of the chat facts @tanstack/ai-models needs that are filled for this provider's chat models: context window, max output, modalities, price, cache price, capabilities, reasoning, effort levels, request map, endpoint. Facts the provider does not publish are left out."
275 >
276 chat
277 </th>
278 <th className="num">polled</th>
279 <th className="num">synced</th>
280 </tr>
281 </thead>
282 <tbody>
283 {status.providers.map((p) => (
284 <tr key={p.id}>
285 <td className="font-medium">
286 <a
287 className="text-ink hover:text-tok-blue"
288 href={`/models?provider=${p.id}`}
289 >
290 {p.displayName}
291 </a>
292 </td>
293 <td>
294 <StatusDot status={p.status} />
295 {p.docsFailing && (
296 <Marker
297 label="docs"
298 text={`docs failing since ${since(p.docsFailing)}: ${[p.docsFailing.sources[0], String(p.docsFailing.error).slice(0, 160)].filter(Boolean).join(' — ')}`}
299 />
300 )}
301 {p.priceClearsRefused && (
302 <Marker
303 label="prices"
304 text={`price clears refused since ${since(p.priceClearsRefused)}: ${p.priceClearsRefused.refused} of ${p.priceClearsRefused.priced} stored prices kept`}
305 />
306 )}
307 {p.updateStorm && (
308 <Marker
309 label="updates"
310 text={`update storm since ${since(p.updateStorm)}: ${p.updateStorm.updated} of ${p.updateStorm.live} live rows updated in one poll`}
311 />
312 )}
313 </td>
314 <td className="num" data-label="models">
315 {fmt.format(p.counts.models)}
316 </td>
317 <td className="num" data-label="endpoints">
318 {fmt.format(p.counts.endpoints)}
319 </td>
320 <td className="num" data-label="schemas">
321 {p.counts.schemas > 0 ? (
322 <a
323 className="text-ink hover:text-tok-blue"
324 href={`/schemas?provider=${p.id}`}
325 >
326 {fmt.format(p.counts.schemas)}
327 </a>
328 ) : (
329 fmt.format(p.counts.schemas)
330 )}
331 </td>
332 <td className="num" data-label="priced">
333 {showPct(pct(p.counts.priced, p.counts.models))}
334 </td>
335 <td className="num" data-label="chat">
336 {p.completeness.score === null ? (
337 '—'
338 ) : (
339 <a
340 className="text-ink hover:text-tok-blue"
341 href={`/models?provider=${p.id}&activity=chat`}
342 title={completenessNote(p.completeness)}
343 >
344 {showPct(
345 Math.round(Number(p.completeness.score) * 100),
346 )}
347 </a>
348 )}
349 </td>
350 <td className="num text-ink-faint" data-label="polled">
351 {timeAgo(p.lastPolledAt)}
352 </td>
353 <td className="num text-ink-faint max-[899px]:hidden">
354 {timeAgo(p.lastSyncedAt)}
355 </td>
356 </tr>
357 ))}
358 </tbody>
359 </table>
360 </div>
361 </section>
362​
363 <section>
364 <SectionHead
365 title="New models"
366 aside={
367 <a className="press-link" href="/changes?type=model.added">
368 all new models →
369 </a>
370 }
371 />
372 {changes.length === 0 ? (
373 <p className="font-mono text-sm text-ink-faint">
374 no new models yet — the next cron poll will populate this list.
375 </p>
376 ) : (
377 <>
378 <div className="figure overflow-x-auto">
379 <table className="dtable">
380 <tbody>
381 {changes.map((change) => (
382 <tr key={change.id}>
383 <td className="font-mono text-xs whitespace-nowrap text-ink-faint">
384 {timeAgo(change.createdAt)}
385 </td>
386 <td className="max-w-[38em] truncate">
387 <ChangeSummary change={change} />
388 </td>
389 <td className="font-mono text-xs text-ink-faint max-sm:hidden">
390 {change.providerId}
391 </td>
392 </tr>
393 ))}
394 </tbody>
395 </table>
396 </div>
397 <p className="mt-2.5 font-mono text-xs text-ink-faint">
398 <a className="press-link" href="/changes">
399 every change: GET /v1/changes
400 </a>{' '}
401 · subscribe with a webhook to get these pushed —{' '}
402 <a className="press-link" href="/docs">
403 POST /v1/subscriptions
404 </a>
405 </p>
406 </>
407 )}
408 </section>
409​
410 <section>
411 <SectionHead
412 title="Examples"
413 aside={
414 <a className="press-link" href="/examples">
415 /examples →
416 </a>
417 }
418 />
419 <div className="figure overflow-x-auto">
420 <table className="dtable">
421 <tbody>
422 {EXAMPLES.map((example) => (
423 <tr key={example.slug}>
424 <td className="font-mono text-xs whitespace-nowrap">
425 <a
426 className="press-link"
427 href={`/examples/${example.slug}/`}
428 >
429 {example.slug}
430 </a>
431 </td>
432 <td className="max-w-[38em]">{example.blurb}</td>
433 <td className="font-mono text-xs whitespace-nowrap text-ink-faint max-sm:hidden">
434 {example.package}
435 </td>
436 </tr>
437 ))}
438 </tbody>
439 </table>
440 </div>
441 </section>
442 </main>
443​
444 <SiteFooter />
445 </div>
446 )