| 1 | import Link from "next/link"; |
| 2 | import { Icon } from "@/components/icon"; |
| 3 | import { PageHeader, Section } from "@/components/page-header"; |
| 4 | import { Status } from "@/components/status-badge"; |
| 5 | import { getComputerUse, getFeatures } from "@/lib/i18n/dictionaries"; |
| 6 | import { buildPageMetadata } from "@/lib/page-meta"; |
| 7 | import { COMPUTER_USE_REPO, getComputerUseRelease } from "@/lib/computer-use-release"; |
| 8 | import { getEnv } from "@/lib/kv"; |
| 9 | import { FACTS } from "@/lib/facts.generated"; |
| 10 | import { EnglishText, FallbackRegion } from "@/components/fallback-region"; |
| 11 | |
| 12 | const BUNDLED_CU_CAVEAT_VERSION = "0.10.2"; |
| 13 | |
| 14 | // Rendered per request rather than through ISR: the download state must be |
| 15 | // right the moment a release is published, the page must never serve a |
| 16 | // build-time snapshot, and OpenNext's in-isolate revalidation queue was seen |
| 17 | // leaving stale copies in place for many minutes. The GitHub reads inside |
| 18 | // getComputerUseRelease stay cached for five minutes via the fetch data cache. |
| 19 | export const dynamic = "force-dynamic"; |
| 20 | |
| 21 | export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) { |
| 22 | const { locale } = await params; |
| 23 | const copy = getComputerUse(locale); |
| 24 | return buildPageMetadata({ path: "/computer-use", locale, title: copy.metaTitle, description: copy.metaDescription }); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * /computer-use — the Mac helper. The download button exists only while the |
| 29 | * release check reports a ready, verified release; otherwise the page says |
| 30 | * why there is no download and links the published releases. |
| 31 | */ |
| 32 | export default async function ComputerUsePage({ params }: { params: Promise<{ locale: string }> }) { |
| 33 | const { locale } = await params; |
| 34 | const t = getComputerUse(locale); |
| 35 | const release = await getComputerUseRelease((await getEnv()).GITHUB_TOKEN); |
| 36 | // The disk image is the human download; the archive stays for the updater. |
| 37 | const primary = release.status === "ready" ? (release.dmg ?? { downloadUrl: release.downloadUrl, size: release.size }) : null; |
| 38 | |
| 39 | return ( |
| 40 | <FallbackRegion path="/computer-use" locale={locale}> |
| 41 | <PageHeader |
| 42 | title={t.title} |
| 43 | lede={t.lead} |
| 44 | pose="computer" |
| 45 | meta={ |
| 46 | <> |
| 47 | <Status tone="attention">{getFeatures(locale).preview}</Status> |
| 48 | <br /> |
| 49 | {t.requirements} |
| 50 | </> |
| 51 | } |
| 52 | actions={ |
| 53 | <> |
| 54 | {release.status === "ready" && primary ? ( |
| 55 | <a className="btn btn-primary btn-lg" href={primary.downloadUrl}> |
| 56 | {t.download} |
| 57 | </a> |
| 58 | ) : null} |
| 59 | <a href={COMPUTER_USE_REPO} className="btn btn-secondary btn-lg"> |
| 60 | {t.source} |
| 61 | <Icon name="external" className="icon" /> |
| 62 | </a> |
| 63 | </> |
| 64 | } |
| 65 | > |
| 66 | {release.status === "ready" && primary ? ( |
| 67 | <div className="cu-download"> |
| 68 | <span className="page-meta tabular"> |
| 69 | v{release.version} · {Math.ceil(primary.size / 1024 / 1024)} MB |
| 70 | </span> |
| 71 | <p className="status-line"> |
| 72 | <a href={release.receiptUrl} className="link">{t.receipt}</a> |
| 73 | {release.dmg ? <a href={release.downloadUrl} className="link">{t.downloadZip}</a> : null} |
| 74 | </p> |
| 75 | </div> |
| 76 | ) : ( |
| 77 | <div className="callout" role="status"> |
| 78 | <p className="callout-title"> |
| 79 | <Status tone={release.status === "pending" ? "attention" : "idle"}> |
| 80 | {release.status === "pending" ? t.pendingTitle : t.unavailableTitle} |
| 81 | </Status> |
| 82 | </p> |
| 83 | <p>{release.status === "pending" ? t.pendingBody : t.unavailableBody}</p> |
| 84 | <p> |
| 85 | <a href={`${COMPUTER_USE_REPO}/releases`} className="link">{t.releases}</a> |
| 86 | </p> |
| 87 | </div> |
| 88 | )} |
| 89 | </PageHeader> |
| 90 | |
| 91 | <div className="page-body"> |
| 92 | <Section id="cu-setup" title={t.setup}> |
| 93 | <ol className="steps"> |
| 94 | {t.steps.map((step, index) => ( |
| 95 | <li key={index}> |
| 96 | <span className="gs-step-index" aria-hidden="true">{index + 1}</span> |
| 97 | <h3>{step.title}</h3> |
| 98 | <p>{step.body}</p> |
| 99 | </li> |
| 100 | ))} |
| 101 | </ol> |
| 102 | </Section> |
| 103 | |
| 104 | <Section id="cu-codewhale" title={t.connectTitle}> |
| 105 | {FACTS.latestPublishedRelease?.version === BUNDLED_CU_CAVEAT_VERSION && <p>{t.connectVersion}</p>} |
| 106 | <p>{t.connectLimit}</p> |
| 107 | <p>{t.connectRuntime}</p> |
| 108 | <pre tabIndex={0} className="code-block">{`APP="/Applications/Codewhale Computer Use.app" |
| 109 | codewhale mcp add computer --command "$APP/Contents/MacOS/node" --arg "$APP/Contents/Resources/plugin/mcp/server.mjs" |
| 110 | codewhale mcp tools computer`}</pre> |
| 111 | <p>{t.connectReload}</p> |
| 112 | <pre tabIndex={0} className="code-block">{t.connectPrompt}</pre> |
| 113 | <p>{t.connectExpected}</p> |
| 114 | <p className="status-line"> |
| 115 | <Link href={`/${locale}/docs/mcp`} className="link">{t.connectGuide}</Link> |
| 116 | <a href={`${COMPUTER_USE_REPO}/blob/main/README.md#codewhale-cli-setup`} className="link"><EnglishText>Computer Use</EnglishText></a> |
| 117 | </p> |
| 118 | </Section> |
| 119 | |
| 120 | <section className="page-section" aria-label={t.controlsTitle}> |
| 121 | <div className="grid-2"> |
| 122 | <div className="tile"> |
| 123 | <span className="tile-icon" aria-hidden="true"><Icon name="shield" /></span> |
| 124 | <h2 className="section-title">{t.controlsTitle}</h2> |
| 125 | <p>{t.controlsBody}</p> |
| 126 | <a href={`${COMPUTER_USE_REPO}/blob/main/docs/DEMO.md`} className="section-link"> |
| 127 | {t.demo} |
| 128 | <Icon name="arrow-right" className="icon icon-flip" /> |
| 129 | </a> |
| 130 | </div> |
| 131 | <div className="tile"> |
| 132 | <span className="tile-icon" aria-hidden="true"><Icon name="repeat" /></span> |
| 133 | <h2 className="section-title">{t.updateTitle}</h2> |
| 134 | <p>{t.updateBody}</p> |
| 135 | <a href={`${COMPUTER_USE_REPO}/blob/main/CHANGELOG.md`} className="section-link"> |
| 136 | {t.notes} |
| 137 | <Icon name="arrow-right" className="icon icon-flip" /> |
| 138 | </a> |
| 139 | </div> |
| 140 | </div> |
| 141 | </section> |
| 142 | |
| 143 | <section className="page-section"> |
| 144 | <div className="callout"> |
| 145 | <p className="callout-title"> |
| 146 | <Icon name="info" className="icon" /> |
| 147 | {t.platforms} |
| 148 | </p> |
| 149 | <div className="actions"> |
| 150 | <a href={`${COMPUTER_USE_REPO}/blob/main/docs/TROUBLESHOOTING.md`} className="btn btn-secondary">{t.help}</a> |
| 151 | </div> |
| 152 | </div> |
| 153 | </section> |
| 154 | |
| 155 | <Section id="cu-contribute" title={t.contributeTitle}> |
| 156 | <p>{t.contributeBody}</p> |
| 157 | <div className="actions"> |
| 158 | <a href={`${COMPUTER_USE_REPO}/blob/main/CONTRIBUTING.md`} className="btn btn-secondary">{t.contributeGuide}</a> |
| 159 | <a href={`${COMPUTER_USE_REPO}/issues`} className="btn btn-ghost">{t.contributeIssue}</a> |
| 160 | </div> |
| 161 | </Section> |
| 162 | </div> |
| 163 | </FallbackRegion> |
| 164 | ); |
| 165 | } |
| 166 |