| 1 | import { Fragment } from "react"; |
| 2 | import Image from "next/image"; |
| 3 | import Link from "next/link"; |
| 4 | import { DesktopShot } from "@/components/desktop-shot"; |
| 5 | import { HeroInstall } from "@/components/hero-install"; |
| 6 | import { HeroSurfacePreview } from "@/components/hero-surface-preview"; |
| 7 | import { Icon } from "@/components/icon"; |
| 8 | import { readAsOf } from "@/components/project-pulse"; |
| 9 | import { InlineCode } from "@/components/route/inline-code"; |
| 10 | import { RouteMap, type RoutePart } from "@/components/route/product-route"; |
| 11 | import { SessionFrames, type SessionFrame } from "@/components/route/session-frames"; |
| 12 | import { Status } from "@/components/status-badge"; |
| 13 | import { TerminalCapture } from "@/components/terminal-capture"; |
| 14 | import { releaseView, runtimeCapabilityContext } from "@/lib/capabilities"; |
| 15 | import { STATE_TONE, stateLabel, surfaceState } from "@/lib/surface-states"; |
| 16 | import { captureCaption, frameNote } from "@/lib/capture-caption"; |
| 17 | import { PARTNER_PROMO } from "@/lib/content/partner-promo"; |
| 18 | import { PROJECT_COPY } from "@/lib/content/project"; |
| 19 | import { PRODUCT_MAP_STATE_KEY, PRODUCT_MAP_TEXT_KEYS, productMap, type ProductMapId } from "@/lib/content/product-map"; |
| 20 | import { getFacts } from "@/lib/facts"; |
| 21 | import { fill, getChrome, getContribute, getHome, pickText, splitToken } from "@/lib/i18n/dictionaries"; |
| 22 | import type { HomeDict } from "@/lib/i18n/dictionaries/types"; |
| 23 | import { REPO_URL } from "@/lib/i18n/links"; |
| 24 | import { pluralText } from "@/lib/i18n/plural"; |
| 25 | import { serializeJsonLd } from "@/lib/json-ld"; |
| 26 | import { RELEASED_CAPTURE_FRAMES, type ReleasedCaptureFrameId } from "@/lib/released-capture.generated"; |
| 27 | import { parseExclusions, repoActivityView, type ActivityPull } from "@/lib/repo-activity"; |
| 28 | import { buildSoftwareApplicationJsonLd } from "@/lib/software-application-schema"; |
| 29 | |
| 30 | export const revalidate = 300; |
| 31 | |
| 32 | const PART_DOC: Partial<Record<ProductMapId, string>> = { |
| 33 | terminal: "/install", |
| 34 | localBrowser: "/docs/web", |
| 35 | manyAgents: "/docs/fleet", |
| 36 | }; |
| 37 | |
| 38 | const SESSION_STEPS = [ |
| 39 | { key: "02-task-prompt", name: "frameLabelPrompt", summary: "frameSummaryPrompt" }, |
| 40 | { key: "03-task-diff", name: "frameLabelEdit", summary: "frameSummaryEdit" }, |
| 41 | { key: "04-task-approval", name: "frameLabelApproval", summary: "frameSummaryApproval" }, |
| 42 | { key: "05-task-result", name: "frameLabelResult", summary: "frameSummaryResult" }, |
| 43 | ] as const satisfies readonly { key: string; name: keyof HomeDict; summary: keyof HomeDict }[]; |
| 44 | const SESSION_OPENS_ON = 3; |
| 45 | const PROVIDER_ROWS = [7, 17] as const; |
| 46 | const RECEIPT_ROWS_WIDE = [6, 37] as const; |
| 47 | const RECEIPT_ROWS_NARROW = [2, 34] as const; |
| 48 | const MERGED_ROWS = 8; |
| 49 | const AGENT_ROLES = [ |
| 50 | { name: "explore", text: "agentRoleExplore" }, |
| 51 | { name: "implement", text: "agentRoleImplement" }, |
| 52 | { name: "reviewer", text: "agentRoleReviewer" }, |
| 53 | ] as const satisfies readonly { name: string; text: keyof HomeDict }[]; |
| 54 | |
| 55 | const avatar = (url: string, size: number) => `${url}${url.includes("?") ? "&" : "?"}s=${size}`; |
| 56 | |
| 57 | function latestPerAccount(pulls: readonly ActivityPull[], limit: number): ActivityPull[] { |
| 58 | const seen = new Set<string>(); |
| 59 | const rows: ActivityPull[] = []; |
| 60 | for (const pull of pulls) { |
| 61 | if (seen.has(pull.login)) continue; |
| 62 | seen.add(pull.login); |
| 63 | rows.push(pull); |
| 64 | if (rows.length === limit) break; |
| 65 | } |
| 66 | return rows; |
| 67 | } |
| 68 | |
| 69 | function splitCount(text: string, count: string): [string, string] { |
| 70 | const at = text.indexOf(count); |
| 71 | return at < 0 ? [text, ""] : [text.slice(0, at), text.slice(at + count.length)]; |
| 72 | } |
| 73 | |
| 74 | interface Fact { |
| 75 | key: string; |
| 76 | before: string; |
| 77 | number: string | null; |
| 78 | after: string; |
| 79 | href: string; |
| 80 | } |
| 81 | |
| 82 | export default async function HomePage({ params }: { params: Promise<{ locale: string }> }) { |
| 83 | const { locale } = await params; |
| 84 | const d = getHome(locale); |
| 85 | const chrome = getChrome(locale); |
| 86 | const contribute = getContribute(locale); |
| 87 | const facts = await getFacts(); |
| 88 | const release = facts.latestPublishedRelease; |
| 89 | const jsonLd = buildSoftwareApplicationJsonLd(release, locale); |
| 90 | const numbers = new Intl.NumberFormat(chrome.dateLocale); |
| 91 | const promoLeft = Date.parse(PARTNER_PROMO.endsAt) - Date.now(); |
| 92 | const promoDays = Math.max(1, Math.ceil(promoLeft / 86_400_000)); |
| 93 | const showPromo = promoLeft > 0 && PARTNER_PROMO.locales.includes(locale); |
| 94 | |
| 95 | const parts: RoutePart[] = productMap({ capabilities: runtimeCapabilityContext(facts) }).map((row) => { |
| 96 | const keys = PRODUCT_MAP_TEXT_KEYS[row.id]; |
| 97 | return { |
| 98 | id: row.id, |
| 99 | state: row.state, |
| 100 | name: d[keys.name], |
| 101 | stateWord: d[PRODUCT_MAP_STATE_KEY[row.state]], |
| 102 | sentence: row.sentenceHolds ? d[keys.sentence] : null, |
| 103 | href: row.state === "released" ? (PART_DOC[row.id] ?? null) : null, |
| 104 | }; |
| 105 | }); |
| 106 | |
| 107 | const frame = (id: ReleasedCaptureFrameId, summary: string, rows?: readonly [number, number]) => ( |
| 108 | <TerminalCapture data={RELEASED_CAPTURE_FRAMES[id]} label={summary} regionLabel={d.shotPreview} rows={rows} /> |
| 109 | ); |
| 110 | const sessionWide = SESSION_STEPS.map((step) => RELEASED_CAPTURE_FRAMES[`cols100/${step.key}`]); |
| 111 | const sessionCaption = captureCaption(sessionWide).caption; |
| 112 | const session: SessionFrame[] = SESSION_STEPS.map((step, index) => ({ |
| 113 | key: step.key, |
| 114 | name: d[step.name], |
| 115 | wide: frame(`cols100/${step.key}`, d[step.summary]), |
| 116 | narrow: frame(`cols48/${step.key}`, d[step.summary]), |
| 117 | note: frameNote(sessionWide[index]).needsPostureNote, |
| 118 | })); |
| 119 | |
| 120 | const desktopState = surfaceState("desktop"); |
| 121 | const cloudState = surfaceState("cloud-computers"); |
| 122 | const desktopStateLabel = stateLabel(desktopState, locale); |
| 123 | const cloudStateLabel = stateLabel(cloudState, locale); |
| 124 | const desktopPart = parts.find((part) => part.id === "desktop"); |
| 125 | const released = releaseView(facts); |
| 126 | const counted = (key: string, forms: HomeDict["factModels"], n: number, href: string): Fact => { |
| 127 | const number = numbers.format(n); |
| 128 | const [before, after] = splitCount(pluralText(forms, n, locale, chrome.dateLocale), number); |
| 129 | return { key, before, number, after, href }; |
| 130 | }; |
| 131 | const plain = (key: string, text: string, href: string): Fact => ({ key, before: text, number: null, after: "", href }); |
| 132 | const manyAgents = parts.find((part) => part.id === "manyAgents"); |
| 133 | const factList: Fact[] = [ |
| 134 | plain("rust", d.factRust, REPO_URL), |
| 135 | ...(facts.license ? [plain("license", fill(d.factLicense, { license: facts.license }), `${REPO_URL}/blob/main/LICENSE`)] : []), |
| 136 | ...(released.counts |
| 137 | ? [ |
| 138 | counted("providers", d.factProviders, released.counts.providerRoutes, `/${locale}/models`), |
| 139 | counted("models", d.factModels, released.counts.models, `/${locale}/models`), |
| 140 | ] |
| 141 | : []), |
| 142 | ...(manyAgents?.state === "released" ? [plain("agents", manyAgents.name, `/${locale}${PART_DOC.manyAgents}`)] : []), |
| 143 | ]; |
| 144 | |
| 145 | const activity = repoActivityView(); |
| 146 | const merged = latestPerAccount(activity?.pulls ?? [], MERGED_ROWS); |
| 147 | const accountForms = parseExclusions().confirmed ? contribute.mergedPeopleCount : contribute.mergedAccountsCount; |
| 148 | const accounts = activity?.count != null ? pluralText(accountForms, activity.count, locale, chrome.dateLocale) : null; |
| 149 | const accountsAsOf = readAsOf(activity?.readAt, locale); |
| 150 | const contributors = numbers.format(facts.contributorCount); |
| 151 | const [contributorsBefore, contributorsAfter] = splitCount(pluralText(d.contributorsCount, facts.contributorCount, locale, chrome.dateLocale), contributors); |
| 152 | |
| 153 | const titleAnswer = d.heroTitle.slice(d.heroTitleLead.length).trim(); |
| 154 | const brand = (text: string) => |
| 155 | splitToken(text, "brand").map((part, index) => ( |
| 156 | <Fragment key={index}> |
| 157 | {index > 0 ? <bdi>Codewhale</bdi> : null} |
| 158 | {part} |
| 159 | </Fragment> |
| 160 | )); |
| 161 | |
| 162 | const install = ( |
| 163 | <div className="home-install"> |
| 164 | <HeroInstall locale={locale} ariaLabel={d.heroInstallAria} copyLabel={d.copy} copiedLabel={d.copied} /> |
| 165 | <p className="home-version"> |
| 166 | {release ? <span>{fill(d.installNote, { version: release.version })}</span> : null} |
| 167 | <a href={REPO_URL} className="home-version-link"> |
| 168 | {d.readTheCode} |
| 169 | </a> |
| 170 | </p> |
| 171 | </div> |
| 172 | ); |
| 173 | const factRow = |
| 174 | factList.length > 0 ? ( |
| 175 | <ul className="home-facts" role="list" aria-label={d.factsLabel}> |
| 176 | {factList.map((fact) => { |
| 177 | const content = ( |
| 178 | <> |
| 179 | {fact.before} |
| 180 | {fact.number ? <strong className="tabular">{fact.number}</strong> : null} |
| 181 | {fact.after} |
| 182 | </> |
| 183 | ); |
| 184 | return ( |
| 185 | <li key={fact.key}> |
| 186 | {fact.href.startsWith("/") ? <Link href={fact.href}>{content}</Link> : <a href={fact.href}>{content}</a>} |
| 187 | </li> |
| 188 | ); |
| 189 | })} |
| 190 | </ul> |
| 191 | ) : null; |
| 192 | const sessionShot = ( |
| 193 | <SessionFrames frames={session} initial={SESSION_OPENS_ON} label={d.shotPreview} caption={sessionCaption ? d[sessionCaption] : null} note={d.captureFrameNoPosture} /> |
| 194 | ); |
| 195 | const desktopPreview = ( |
| 196 | <figure className="home-desktop"> |
| 197 | <div className="figure-frame home-desktop-frame"> |
| 198 | <DesktopShot id="approval" alt={d.directionShotAlt} sizes="(max-width: 64rem) 100vw, 60rem" /> |
| 199 | </div> |
| 200 | <figcaption className="home-desktop-caption"> |
| 201 | <Status tone={STATE_TONE[desktopState]}> |
| 202 | {d.mapDesktop}: {desktopStateLabel} |
| 203 | </Status> |
| 204 | <span className="home-caption">{d.directionShotCaption}</span> |
| 205 | <Link href={`/${locale}/app`} className="link">{d.directionShotLink}</Link> |
| 206 | </figcaption> |
| 207 | </figure> |
| 208 | ); |
| 209 | const heroShot = |
| 210 | desktopState === "released" ? ( |
| 211 | <HeroSurfacePreview |
| 212 | label={d.shotPreview} |
| 213 | terminalLabel={d.mapTerminal} |
| 214 | desktopLabel={d.mapDesktop} |
| 215 | terminal={sessionShot} |
| 216 | desktop={desktopPreview} |
| 217 | /> |
| 218 | ) : ( |
| 219 | sessionShot |
| 220 | ); |
| 221 | |
| 222 | return ( |
| 223 | <div className="home"> |
| 224 | <script type="application/ld+json" dangerouslySetInnerHTML={{ __html: serializeJsonLd(jsonLd) }} /> |
| 225 | |
| 226 | <section className="home-hero" data-hero="center" aria-labelledby="home-title"> |
| 227 | <div className="home-hero-text"> |
| 228 | <h1 id="home-title" className="home-title"> |
| 229 | <span className="home-title-lead">{d.heroTitleLead}</span> <span className="home-title-answer">{titleAnswer}</span> |
| 230 | </h1> |
| 231 | <p className="home-subhead">{brand(d.heroIntro)}</p> |
| 232 | {install} |
| 233 | <p className="home-version" aria-label={d.sectionDirectionHeading}> |
| 234 | <Link href={`/${locale}/app`} className="home-version-link"> |
| 235 | <Status tone={STATE_TONE[desktopState]}> |
| 236 | {d.mapDesktop}: {desktopStateLabel} |
| 237 | </Status> |
| 238 | </Link> |
| 239 | <Status tone={STATE_TONE[cloudState]}> |
| 240 | {d.mapCloud}: {cloudStateLabel} |
| 241 | </Status> |
| 242 | </p> |
| 243 | </div> |
| 244 | <div className="home-hero-shot">{heroShot}</div> |
| 245 | {factRow} |
| 246 | </section> |
| 247 | |
| 248 | <div className="home-sections"> |
| 249 | <section className="home-section home-split" aria-labelledby="home-model"> |
| 250 | <div className="home-text"> |
| 251 | <h2 id="home-model" className="home-h2">{d.sectionModelHeading}</h2> |
| 252 | <p className="home-body"><InlineCode text={d.sectionModelBody} /></p> |
| 253 | </div> |
| 254 | <figure className="home-figure"> |
| 255 | <div className="home-frame home-only-wide">{frame("cols56/01-model-picker", d.frameSummaryProvider, PROVIDER_ROWS)}</div> |
| 256 | <div className="home-frame home-only-narrow">{frame("cols48/01-model-picker", d.frameSummaryProvider, PROVIDER_ROWS)}</div> |
| 257 | </figure> |
| 258 | </section> |
| 259 | |
| 260 | {showPromo && ( |
| 261 | <aside className="home-promo-bar home-promo-inline" aria-label={PARTNER_PROMO.title}> |
| 262 | <div className="home-promo-bar-inner"> |
| 263 | <Image src={PARTNER_PROMO.thumb.src} alt="" width={64} height={36} className="home-promo-bar-art" unoptimized /> |
| 264 | <p> |
| 265 | <strong>{PARTNER_PROMO.title}</strong> |
| 266 | <span>{pickText(PARTNER_PROMO.bar, locale)}</span> |
| 267 | <span className="home-promo-bar-days">{fill(pickText(promoDays === 1 ? PARTNER_PROMO.dayLeft : PARTNER_PROMO.daysLeft, locale), { count: promoDays })}</span> |
| 268 | </p> |
| 269 | <span className="home-promo-bar-tag">{pickText(PARTNER_PROMO.referralTag, locale)}</span> |
| 270 | <p className="home-promo-bar-disclosure">{pickText(PARTNER_PROMO.disclosure, locale)}</p> |
| 271 | <a href={PARTNER_PROMO.href} rel="sponsored noopener" className="btn btn-primary"> |
| 272 | {pickText(PARTNER_PROMO.cta, locale)} |
| 273 | <Icon name="external" className="icon" /> |
| 274 | </a> |
| 275 | </div> |
| 276 | </aside> |
| 277 | )} |
| 278 | |
| 279 | <section className="home-section home-split home-split-flip" aria-labelledby="home-control"> |
| 280 | <div className="home-text"> |
| 281 | <h2 id="home-control" className="home-h2">{d.sectionControlHeading}</h2> |
| 282 | <p className="home-body"><InlineCode text={d.sectionControlBody} /></p> |
| 283 | </div> |
| 284 | <figure className="home-figure"> |
| 285 | <div className="home-frame home-only-wide">{frame("cols56/06b-receipt-tall", d.frameSummaryReceipt, RECEIPT_ROWS_WIDE)}</div> |
| 286 | <div className="home-frame home-only-narrow">{frame("cols48/06b-receipt-tall", d.frameSummaryReceipt, RECEIPT_ROWS_NARROW)}</div> |
| 287 | </figure> |
| 288 | </section> |
| 289 | |
| 290 | <section className="home-section home-split" aria-labelledby="home-agents"> |
| 291 | <div className="home-text"> |
| 292 | <h2 id="home-agents" className="home-h2">{d.sectionAgentsHeading}</h2> |
| 293 | <p className="home-body"><InlineCode text={d.sectionAgentsBody} /></p> |
| 294 | <p className="home-more"> |
| 295 | <Link href={`/${locale}/docs/subagents`} className="link">{d.agentsLink}</Link> |
| 296 | </p> |
| 297 | </div> |
| 298 | <dl className="home-figure home-roles" aria-label={d.agentsRolesLabel}> |
| 299 | {AGENT_ROLES.map((role) => ( |
| 300 | <div key={role.name}> |
| 301 | <dt><code>{role.name}</code></dt> |
| 302 | <dd>{d[role.text]}</dd> |
| 303 | </div> |
| 304 | ))} |
| 305 | </dl> |
| 306 | </section> |
| 307 | </div> |
| 308 | |
| 309 | <section className="home-direction" aria-labelledby="home-direction"> |
| 310 | <div className="home-direction-head"> |
| 311 | <h2 id="home-direction" className="home-h3">{d.sectionDirectionHeading}</h2> |
| 312 | <p className="home-body"><InlineCode text={d.sectionDirectionBody} /></p> |
| 313 | </div> |
| 314 | <RouteMap parts={parts} engine={d.mapHeading} label={d.sectionDirectionHeading} locale={locale} /> |
| 315 | <figure className="home-desktop"> |
| 316 | <div className="figure-frame home-desktop-frame"> |
| 317 | <DesktopShot id="approval" alt={d.directionShotAlt} sizes="(max-width: 64rem) 100vw, 64rem" /> |
| 318 | </div> |
| 319 | <figcaption className="home-desktop-caption"> |
| 320 | {desktopPart ? <Status tone={STATE_TONE[desktopState]}>{desktopPart.name}: {desktopPart.stateWord}</Status> : null} |
| 321 | <span className="home-caption">{d.directionShotCaption}</span> |
| 322 | <Link href={`/${locale}/app`} className="link">{d.directionShotLink}</Link> |
| 323 | </figcaption> |
| 324 | </figure> |
| 325 | </section> |
| 326 | |
| 327 | <div className="home-sections"> |
| 328 | <section className="home-section home-split" aria-labelledby="home-open"> |
| 329 | <div className="home-text"> |
| 330 | <h2 id="home-open" className="home-h2">{d.sectionOpenHeading}</h2> |
| 331 | <p className="home-body"><InlineCode text={d.sectionOpenBody} /></p> |
| 332 | </div> |
| 333 | <div className="home-people"> |
| 334 | <p className="home-count"> |
| 335 | {contributorsBefore.trim() ? <span className="home-count-label">{contributorsBefore.trim()}</span> : null} |
| 336 | <a className="home-count-number tabular" href={`${REPO_URL}/blob/main/docs/CONTRIBUTORS.md`}>{contributors}</a> |
| 337 | {contributorsAfter.trim() ? <span className="home-count-label">{contributorsAfter.trim()}</span> : null} |
| 338 | </p> |
| 339 | {accounts ? ( |
| 340 | <p className="home-accounts tabular" title={accountsAsOf}> |
| 341 | {accounts} |
| 342 | {accountsAsOf ? <span className="sr-only"> {accountsAsOf}</span> : null} |
| 343 | </p> |
| 344 | ) : null} |
| 345 | {merged.length > 0 ? ( |
| 346 | <ol className="home-merged" role="list" aria-label={pickText(PROJECT_COPY.mergedHeading, locale)}> |
| 347 | {merged.map((pull) => ( |
| 348 | <li key={pull.number}> |
| 349 | {/* eslint-disable-next-line @next/next/no-img-element */} |
| 350 | <img src={avatar(pull.avatar, 48)} alt="" width={24} height={24} loading="lazy" decoding="async" /> |
| 351 | <span className="home-merged-login" dir="ltr">{pull.login}</span> |
| 352 | <a className="home-merged-title" href={pull.url} dir="ltr" lang="en">{pull.title}</a> |
| 353 | </li> |
| 354 | ))} |
| 355 | </ol> |
| 356 | ) : null} |
| 357 | </div> |
| 358 | </section> |
| 359 | </div> |
| 360 | |
| 361 | <section className="home-start" aria-labelledby="home-start"> |
| 362 | <div className="home-start-inner"> |
| 363 | <div className="home-text"> |
| 364 | <h2 id="home-start" className="home-h2">{d.sectionStartHeading}</h2> |
| 365 | <p className="home-body"><InlineCode text={d.sectionStartBody} /></p> |
| 366 | </div> |
| 367 | {install} |
| 368 | </div> |
| 369 | </section> |
| 370 | </div> |
| 371 | ); |
| 372 | } |
| 373 |