| 1 | import Link from "next/link"; |
| 2 | import { releaseView } from "@/lib/capabilities"; |
| 3 | import { getFacts } from "@/lib/facts"; |
| 4 | import { buildPageMetadata } from "@/lib/page-meta"; |
| 5 | import { |
| 6 | MODELS_COPY, |
| 7 | ROUTE_PROVIDERS, |
| 8 | formatModelDate, |
| 9 | formatModelTokens, |
| 10 | latestFirstPartyModels, |
| 11 | splitCode, |
| 12 | sortProvidersFirstPartyFirst, |
| 13 | } from "@/lib/content/models"; |
| 14 | import { DesktopShot } from "@/components/desktop-shot"; |
| 15 | import { Icon } from "@/components/icon"; |
| 16 | import { TerminalCapture } from "@/components/terminal-capture"; |
| 17 | import { RELEASED_CAPTURE_FRAMES } from "@/lib/released-capture.generated"; |
| 18 | import { ModelBadge, ModelsCatalog } from "@/components/models-catalog"; |
| 19 | import { PageHeader, Section } from "@/components/page-header"; |
| 20 | import type { LocalizedText } from "@/lib/content/vocabulary"; |
| 21 | import { fill, pickText } from "@/lib/i18n/dictionaries"; |
| 22 | import { bodyDateLocale } from "@/lib/i18n/fallback"; |
| 23 | import { FallbackRegion } from "@/components/fallback-region"; |
| 24 | |
| 25 | export const revalidate = 300; |
| 26 | |
| 27 | function Rich({ text }: { text: string }) { |
| 28 | return <>{splitCode(text).map((part, i) => (part.code ? <code key={i}>{part.text}</code> : part.text))}</>; |
| 29 | } |
| 30 | |
| 31 | export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) { |
| 32 | const { locale } = await params; |
| 33 | return buildPageMetadata({ path: "/models", locale, |
| 34 | title: pickText(MODELS_COPY.metaTitle, locale), |
| 35 | description: pickText(MODELS_COPY.metaDescription, locale) }); |
| 36 | } |
| 37 | |
| 38 | export default async function ModelsPage({ params }: { params: Promise<{ locale: string }> }) { |
| 39 | const { locale } = await params; |
| 40 | const facts = await getFacts(); |
| 41 | const released = releaseView(facts); |
| 42 | const t = (copy: LocalizedText) => fill(pickText(copy, locale), { |
| 43 | version: facts.latestPublishedRelease?.version ?? "—", model: facts.defaultModel ?? "—", count: released.models.length, |
| 44 | }); |
| 45 | const dateLocale = bodyDateLocale("/models", locale); |
| 46 | const latest = latestFirstPartyModels(released.models); |
| 47 | const providers = sortProvidersFirstPartyFirst(released.providers); |
| 48 | const routeEnv = ROUTE_PROVIDERS.flatMap((route) => { |
| 49 | const provider = released.providers.find((p) => p.id === route.id); |
| 50 | return provider ? [{ ...route, env: provider.env }] : []; |
| 51 | }); |
| 52 | const deepseekEnv = released.providers.find((p) => p.id === "deepseek")?.env; |
| 53 | |
| 54 | return ( |
| 55 | <FallbackRegion path="/models" locale={locale}> |
| 56 | <PageHeader |
| 57 | titleId="models-overview" |
| 58 | title={t(MODELS_COPY.title)} |
| 59 | lede={t(MODELS_COPY.lead)} |
| 60 | pose="think" |
| 61 | /> |
| 62 | |
| 63 | <div className="page-body"> |
| 64 | {latest.length > 0 ? ( |
| 65 | <Section id="models-latest" title={t(MODELS_COPY.latestTitle)} scope={t(MODELS_COPY.latestLead)}> |
| 66 | <ul className="models-latest"> |
| 67 | {latest.map(({ key, label, model }) => ( |
| 68 | <li key={key} className="tile"> |
| 69 | <span className="models-maker">{label}</span> |
| 70 | <code>{model.id}</code> |
| 71 | <span className="models-meta"> |
| 72 | {formatModelTokens(model.contextWindow)} {t(MODELS_COPY.colContext).toLowerCase()} |
| 73 | {model.reasoning ? <>{" "}<ModelBadge locale={locale} /></> : null} |
| 74 | </span> |
| 75 | <span className="models-meta"> |
| 76 | {fill(pickText(MODELS_COPY.latestSince, locale), { date: formatModelDate(model.addedAt, dateLocale) })} |
| 77 | </span> |
| 78 | </li> |
| 79 | ))} |
| 80 | </ul> |
| 81 | </Section> |
| 82 | ) : null} |
| 83 | |
| 84 | <Section id="models-picker" title={t(MODELS_COPY.pickerTitle)} scope={t(MODELS_COPY.pickerLead)}> |
| 85 | <div className="models-picker"> |
| 86 | <figure className="figure"> |
| 87 | <div className="home-frame home-only-wide"> |
| 88 | <TerminalCapture data={RELEASED_CAPTURE_FRAMES["cols100/01-model-picker"]} label={t(MODELS_COPY.pickerTerminalLabel)} regionLabel={t(MODELS_COPY.pickerTerminalCaption)} rows={[6, 16]} /> |
| 89 | </div> |
| 90 | <div className="home-frame home-only-narrow"> |
| 91 | <TerminalCapture data={RELEASED_CAPTURE_FRAMES["cols48/01-model-picker"]} label={t(MODELS_COPY.pickerTerminalLabel)} regionLabel={t(MODELS_COPY.pickerTerminalCaption)} rows={[7, 17]} /> |
| 92 | </div> |
| 93 | <figcaption className="figure-caption">{t(MODELS_COPY.pickerTerminalCaption)}</figcaption> |
| 94 | </figure> |
| 95 | <figure className="figure"> |
| 96 | <div className="figure-frame"> |
| 97 | <DesktopShot id="models" alt={t(MODELS_COPY.pickerDesktopAlt)} /> |
| 98 | </div> |
| 99 | <figcaption className="figure-caption">{t(MODELS_COPY.pickerDesktopCaption)}</figcaption> |
| 100 | </figure> |
| 101 | </div> |
| 102 | </Section> |
| 103 | |
| 104 | <Section |
| 105 | id="models-setup" |
| 106 | title={t(MODELS_COPY.setupTitle)} |
| 107 | scope={t(MODELS_COPY.setupLead)} |
| 108 | link={ |
| 109 | <Link href="https://github.com/codewhale-hq/CodeWhale/blob/main/docs/PROVIDERS.md" className="section-link"> |
| 110 | {t(MODELS_COPY.providerDocs)} |
| 111 | <Icon name="external" className="icon" /> |
| 112 | </Link> |
| 113 | } |
| 114 | > |
| 115 | <ol className="steps"> |
| 116 | {MODELS_COPY.steps.map((step, i) => ( |
| 117 | <li key={i}> |
| 118 | <span className="gs-step-index" aria-hidden="true">{i + 1}</span> |
| 119 | <h3>{t(step.title)}</h3> |
| 120 | <p><Rich text={t(step.detail)} /></p> |
| 121 | </li> |
| 122 | ))} |
| 123 | </ol> |
| 124 | <div className="models-routes"> |
| 125 | <div className="tile"> |
| 126 | <h3 className="models-route-title">{t(MODELS_COPY.routeDeepseekTitle)}</h3> |
| 127 | <p>{t(MODELS_COPY.routeDeepseekBody)}</p> |
| 128 | {deepseekEnv ? <code>{deepseekEnv}</code> : null} |
| 129 | </div> |
| 130 | <div className="tile"> |
| 131 | <h3 className="models-route-title">{t(MODELS_COPY.routeFirstPartyTitle)}</h3> |
| 132 | <p>{t(MODELS_COPY.routeFirstPartyBody)}</p> |
| 133 | <dl className="models-env"> |
| 134 | {routeEnv.map((route) => ( |
| 135 | <div key={route.id}> |
| 136 | <dt>{route.label}</dt> |
| 137 | <dd><code>{route.env}</code></dd> |
| 138 | </div> |
| 139 | ))} |
| 140 | </dl> |
| 141 | </div> |
| 142 | <div className="tile"> |
| 143 | <h3 className="models-route-title">{t(MODELS_COPY.routeCompatTitle)}</h3> |
| 144 | <p>{t(MODELS_COPY.routeCompatBody)}</p> |
| 145 | <p><Rich text={t(MODELS_COPY.routeCompatConfig)} /></p> |
| 146 | </div> |
| 147 | </div> |
| 148 | </Section> |
| 149 | |
| 150 | {released.counts && ( |
| 151 | <Section id="models-title" title={t(MODELS_COPY.modelsTitle)} scope={t(MODELS_COPY.modelsLead)}> |
| 152 | <ModelsCatalog models={released.models} locale={locale} /> |
| 153 | </Section> |
| 154 | )} |
| 155 | |
| 156 | <Section id="providers-title" title={t(MODELS_COPY.listTitle)}> |
| 157 | <details className="group-card disclosure-row"> |
| 158 | <summary> |
| 159 | <span>{released.counts ? fill(pickText(MODELS_COPY.providerCount, locale), { count: released.counts.providerRoutes }) : t(MODELS_COPY.listTitle)}</span> |
| 160 | <Icon name="chevron-down" className="disclosure-chevron" /> |
| 161 | </summary> |
| 162 | <div className="disclosure-body"> |
| 163 | <div className="data-table-wrap"> |
| 164 | <table className="data-table"> |
| 165 | <thead> |
| 166 | <tr> |
| 167 | <th scope="col">{t(MODELS_COPY.provider)}</th> |
| 168 | <th scope="col">{t(MODELS_COPY.id)}</th> |
| 169 | <th scope="col">{t(MODELS_COPY.credential)}</th> |
| 170 | </tr> |
| 171 | </thead> |
| 172 | <tbody> |
| 173 | {providers.map((provider) => ( |
| 174 | <tr key={provider.id}> |
| 175 | <th scope="row">{provider.label}</th> |
| 176 | <td><code>{provider.id}</code></td> |
| 177 | <td><code>{provider.env}</code></td> |
| 178 | </tr> |
| 179 | ))} |
| 180 | </tbody> |
| 181 | </table> |
| 182 | </div> |
| 183 | </div> |
| 184 | </details> |
| 185 | <p className="section-scope mt-5"> |
| 186 | {t(MODELS_COPY.missing)}{" "} |
| 187 | <Link href="https://github.com/codewhale-hq/CodeWhale/issues/new/choose" className="link">{t(MODELS_COPY.request)}</Link> |
| 188 | </p> |
| 189 | </Section> |
| 190 | </div> |
| 191 | </FallbackRegion> |
| 192 | ); |
| 193 | } |
| 194 |