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

index.tsx

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