diff --git a/.gitignore b/.gitignore index bf30515..b14a3db 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ content/docs *.log .DS_Store *.tsbuildinfo + +# Pairing service worker bundle — built by scripts/build-sw.mjs +public/pair-sw.js diff --git a/README.md b/README.md index 49acdc4..872938e 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,45 @@ Env vars at build time: Set them when you want to publish from a fork or a non-main branch. +## Phone pairing (`/pair`, `/d//`) + +`agentproto pair offer --qr` prints a QR for +`https://cli.agentproto.sh/pair#`. The offer rides in the fragment, +so it never reaches this server. + +- **`/pair`** reads the offer, runs the end-to-end handshake through the + rendezvous (`@agentproto/pair-client`), shows the daemon's name and + fingerprint to confirm, and stores the credential in IndexedDB (never + localStorage). With no offer, it lists the paired daemons. +- **`/d/`** (`` = daemon fingerprint) is the state page: not paired, + connecting, daemon offline (retrying), revoked. +- **`/d//…`** is answered by a service worker registered for that scope + (`src/sw/pair-sw.ts`, bundled by `scripts/build-sw.mjs` to + `public/pair-sw.js`). It holds the one tunnel to the daemon and proxies + every request under the scope to it. The Control Center + (`/d//apps/@agentik/session-chat/ui/`) and its REST, `/mcp` and SSE + calls all come from the daemon. cli-site serves none of it. + +`public/pair.webmanifest` makes it installable (add to home screen). + +**One origin per daemon.** Served at `https://.agentproto.cloud`, +the origin belongs to that one daemon (`src/lib/pair-host.ts`). `/pair` refuses +offers for any other daemon, and the credential store only holds that daemon. +Browsers isolate storage and service workers per origin, so no daemon's +Control Center can reach another daemon's pairing. Any other host +(cli.agentproto.sh, localhost) is a shared origin: it still works, and says +so. The pair domain is set at build time: + +| Var | Default | +| ------------------------------------- | ------------------ | +| `NEXT_PUBLIC_AGENTPROTO_PAIR_DOMAIN` | `agentproto.cloud` | + +To try per-daemon origins locally, build with +`NEXT_PUBLIC_AGENTPROTO_PAIR_DOMAIN=localhost` and open +`http://.localhost:3010/pair`. Chrome resolves `*.localhost` to +loopback and treats it as a secure context, which service workers and +WebCrypto need. + ## Structure ``` diff --git a/docs/pair/1-confirm.png b/docs/pair/1-confirm.png new file mode 100644 index 0000000..fa8df0e Binary files /dev/null and b/docs/pair/1-confirm.png differ diff --git a/docs/pair/2-control-center.png b/docs/pair/2-control-center.png new file mode 100644 index 0000000..151d28d Binary files /dev/null and b/docs/pair/2-control-center.png differ diff --git a/docs/pair/3-sessions-panel.png b/docs/pair/3-sessions-panel.png new file mode 100644 index 0000000..6b4688d Binary files /dev/null and b/docs/pair/3-sessions-panel.png differ diff --git a/docs/pair/4-offline.png b/docs/pair/4-offline.png new file mode 100644 index 0000000..3e5652b Binary files /dev/null and b/docs/pair/4-offline.png differ diff --git a/docs/pair/5-revoked.png b/docs/pair/5-revoked.png new file mode 100644 index 0000000..bda94e2 Binary files /dev/null and b/docs/pair/5-revoked.png differ diff --git a/docs/pair/6-not-paired.png b/docs/pair/6-not-paired.png new file mode 100644 index 0000000..37c240e Binary files /dev/null and b/docs/pair/6-not-paired.png differ diff --git a/docs/pair/7-outdated.png b/docs/pair/7-outdated.png new file mode 100644 index 0000000..6d575fb Binary files /dev/null and b/docs/pair/7-outdated.png differ diff --git a/docs/pair/8-wrong-origin.png b/docs/pair/8-wrong-origin.png new file mode 100644 index 0000000..94aeac9 Binary files /dev/null and b/docs/pair/8-wrong-origin.png differ diff --git a/docs/pair/9-shared-origin-confirm.png b/docs/pair/9-shared-origin-confirm.png new file mode 100644 index 0000000..0eb8ca8 Binary files /dev/null and b/docs/pair/9-shared-origin-confirm.png differ diff --git a/package.json b/package.json index 8072760..195e00c 100644 --- a/package.json +++ b/package.json @@ -11,17 +11,18 @@ "license": "Apache-2.0", "type": "module", "scripts": { - "predev": "node scripts/sync-content.mjs", + "predev": "node scripts/sync-content.mjs && node scripts/build-sw.mjs", "dev": "next dev --turbopack -p 3010", - "prebuild": "node scripts/sync-content.mjs", + "prebuild": "node scripts/sync-content.mjs && node scripts/build-sw.mjs", "build": "next build", "start": "next start", "lint": "next lint", "pretypecheck": "node scripts/sync-content.mjs && fumadocs-mdx", - "typecheck": "tsc --noEmit", + "typecheck": "tsc --noEmit && tsc --noEmit -p src/sw", "clean": "rm -rf .next .source content/docs .cache" }, "dependencies": { + "@agentproto/pair-client": "^0.1.0", "@xterm/addon-fit": "^0.11.0", "@xterm/xterm": "^6.0.0", "clsx": "^2.1.1", @@ -41,6 +42,7 @@ "@types/node": "^24.12.3", "@types/react": "19.2.14", "@types/react-dom": "19.2.3", + "esbuild": "^0.28.2", "tailwindcss": "^4.3.0", "typescript": "^5.9.3" }, diff --git a/public/pair-icon-192.png b/public/pair-icon-192.png new file mode 100644 index 0000000..340a617 Binary files /dev/null and b/public/pair-icon-192.png differ diff --git a/public/pair-icon-512.png b/public/pair-icon-512.png new file mode 100644 index 0000000..b47d9a0 Binary files /dev/null and b/public/pair-icon-512.png differ diff --git a/public/pair.webmanifest b/public/pair.webmanifest new file mode 100644 index 0000000..d227655 --- /dev/null +++ b/public/pair.webmanifest @@ -0,0 +1,16 @@ +{ + "name": "agentproto Control Center", + "short_name": "agentproto", + "description": "Your agentproto daemon on your phone, end-to-end encrypted through the rendezvous.", + "id": "/pair", + "start_url": "/pair?launch=1", + "scope": "/", + "display": "standalone", + "background_color": "#0d1512", + "theme_color": "#0d1512", + "icons": [ + { "src": "/pair-icon-192.png", "sizes": "192x192", "type": "image/png" }, + { "src": "/pair-icon-512.png", "sizes": "512x512", "type": "image/png" }, + { "src": "/pair-icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" } + ] +} diff --git a/scripts/build-sw.mjs b/scripts/build-sw.mjs new file mode 100644 index 0000000..5ce256b --- /dev/null +++ b/scripts/build-sw.mjs @@ -0,0 +1,37 @@ +#!/usr/bin/env node +/** + * build-sw.mjs — bundle the pairing service worker (src/sw/pair-sw.ts) for + * the browser into public/pair-sw.js. + * + * A service worker is a classic script at a fixed URL, outside Next's module + * graph, so it is built separately: one self-contained IIFE with + * @agentproto/pair-client inlined. Served from the root, its default max + * scope is `/`, which covers every `/d//` registration without a + * `Service-Worker-Allowed` header. Runs before `dev` and `build`; the output + * is gitignored. + */ + +import { build } from "esbuild" +import path from "node:path" +import { fileURLToPath } from "node:url" + +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..") + +await build({ + entryPoints: [path.join(root, "src/sw/pair-sw.ts")], + outfile: path.join(root, "public/pair-sw.js"), + bundle: true, + format: "iife", + platform: "browser", + target: ["es2022"], + minify: process.env.NODE_ENV === "production", + sourcemap: process.env.NODE_ENV === "production" ? false : "inline", + legalComments: "none", + // Same pair domain the pages get from Next (src/lib/pair-host.ts). + define: { + "process.env.NEXT_PUBLIC_AGENTPROTO_PAIR_DOMAIN": JSON.stringify( + process.env.NEXT_PUBLIC_AGENTPROTO_PAIR_DOMAIN ?? "", + ), + }, + logLevel: "info", +}) diff --git a/src/app/d/[id]/[[...rest]]/page.tsx b/src/app/d/[id]/[[...rest]]/page.tsx new file mode 100644 index 0000000..a41bfe4 --- /dev/null +++ b/src/app/d/[id]/[[...rest]]/page.tsx @@ -0,0 +1,235 @@ +"use client" + +import { useEffect, useRef, useState } from "react" +import { useParams } from "next/navigation" +import { Fingerprint, HowToPair, PairButton, PairShell } from "@/components/pair-shell" +import { controlCenterUrl, isPairWorkerStatus, isPairingId, pairingScope, type PairState } from "@/lib/pair" +import { daemonOrigin, PAIR_DOMAIN } from "@/lib/pair-host" +import { + forgetPairing, + hostMode, + pairStore, + postToWorker, + registerPairingWorker, + serviceWorkersSupported, +} from "@/lib/pair-worker" + +/** How often to ask the worker for its state. Each message also keeps a worker + * that would otherwise idle out alive while this page waits on it. */ +const POLL_MS = 2_500 + +type View = + | { state: "loading" } + | { state: PairState; error?: { code: string; message: string } } + | { state: "error"; error: { code: string; message: string } } + +/** Only ever send the user back inside this pairing's own scope. */ +function resolveNext(id: string, fromQuery: string | null, here: string | null): string { + for (const candidate of [fromQuery, here]) { + if (candidate && candidate.startsWith(pairingScope(id)) && !candidate.includes("//")) return candidate + } + return controlCenterUrl(id) +} + +function isPairState(s: string | null): s is PairState { + return ( + s === "connecting" || + s === "open" || + s === "offline" || + s === "revoked" || + s === "not_paired" || + s === "outdated" + ) +} + +/** + * `/d/` — the state page for one paired daemon: registers the pairing's + * service worker, follows its tunnel state (the worker owns the one + * connection; this page only asks it), and opens the Control Center as soon + * as the tunnel is up. The worker sends the Control Center back here when + * the daemon goes offline or revokes this device. + * + * Also catches `/d//…` loaded while no worker controls it (first visit on + * a new tab, site data cleared): the worker is installed, then the same URL + * is loaded again through it. + */ +export default function DaemonStatusPage(): React.ReactElement { + const params = useParams<{ id: string; rest?: string[] }>() + const id = params.id + const deep = (params.rest?.length ?? 0) > 0 + const [view, setView] = useState({ state: "loading" }) + const [name, setName] = useState(null) + const [fingerprint, setFingerprint] = useState(null) + const regRef = useRef(null) + /** Set on a per-daemon origin asked for another daemon: that origin's id. */ + const [originOwner, setOriginOwner] = useState(null) + + useEffect(() => { + if (!isPairingId(id)) { + setView({ state: "not_paired" }) + return + } + const mode = hostMode() + if (mode.kind === "daemon" && mode.fingerprint !== id) { + setOriginOwner(mode.fingerprint) + setView({ state: "not_paired" }) + return + } + if (!serviceWorkersSupported()) { + setView({ state: "error", error: { code: "unsupported", message: "This browser has no service workers." } }) + return + } + const search = new URLSearchParams(window.location.search) + const hinted = search.get("state") + if (isPairState(hinted)) setView({ state: hinted }) + const next = resolveNext(id, search.get("next"), deep ? window.location.pathname + window.location.search : null) + + let stopped = false + let timer: ReturnType | undefined + const onMessage = (event: MessageEvent): void => { + const status = event.data + if (stopped || !isPairWorkerStatus(status) || status.id !== id) return + if (status.daemonName) setName(status.daemonName) + setView(status.error ? { state: status.state, error: status.error } : { state: status.state }) + if (status.state === "open") { + stopped = true + window.location.replace(next) + } + } + const onOnline = (): void => { + if (regRef.current) postToWorker(regRef.current, { type: "agentproto-pair:reconnect" }) + } + navigator.serviceWorker.addEventListener("message", onMessage) + window.addEventListener("online", onOnline) + + void (async () => { + const credential = await pairStore().get(id) + if (stopped) return + if (!credential) { + setView({ state: "not_paired" }) + return + } + setName(credential.name) + setFingerprint(credential.fingerprint) + const reg = await registerPairingWorker(id) + if (stopped) return + regRef.current = reg + const poll = (): void => { + postToWorker(reg, { type: "agentproto-pair:status" }) + } + poll() + timer = setInterval(poll, POLL_MS) + })().catch(err => { + if (!stopped) { + setView({ state: "error", error: { code: "error", message: err instanceof Error ? err.message : String(err) } }) + } + }) + + return () => { + stopped = true + clearInterval(timer) + navigator.serviceWorker.removeEventListener("message", onMessage) + window.removeEventListener("online", onOnline) + } + }, [id, deep]) + + const daemon = name ?? "your daemon" + + const forget = async () => { + await forgetPairing(id) + window.location.replace("/pair") + } + + switch (view.state) { + case "loading": + case "connecting": + case "closed": + return ( + + {fingerprint && } +

Opening the end-to-end tunnel through the rendezvous. The Control Center loads from the daemon itself.

+
+ ) + + case "open": + return ( + +

Opening the Control Center…

+
+ ) + + case "offline": + return ( + +

+ Retrying on its own. Check that the computer is awake and the daemon is running ( + agentproto serve). +

+ {view.error &&

{view.error.message}

} + regRef.current && postToWorker(regRef.current, { type: "agentproto-pair:reconnect" })} + > + Retry now + +
+ ) + + case "revoked": + return ( + +

The daemon revoked this device, so it can't reconnect. To use it again, pair from a new QR.

+ + void forget()}> + Forget this daemon + +
+ ) + + case "outdated": + return ( + +

+ This phone was paired with {daemon} using an older pairing protocol, which the daemon no longer + accepts. Make sure agentproto is up to date on the computer, then pair again from a new QR. +

+ + void forget()}> + Forget the old pairing + +
+ ) + + case "not_paired": + if (originOwner) { + return ( + +

+ This address belongs to daemon {originOwner} only. Daemon {id} has its own: +

+ + Open {id}.{PAIR_DOMAIN} + +
+ ) + } + return ( + + + window.location.assign("/pair")}> + See paired daemons + + + ) + + case "error": + return ( + +

{view.error.message}

+
+ ) + } +} diff --git a/src/app/d/layout.tsx b/src/app/d/layout.tsx new file mode 100644 index 0000000..d8956cc --- /dev/null +++ b/src/app/d/layout.tsx @@ -0,0 +1,13 @@ +import type { Metadata, Viewport } from "next" +import { pairMetadata, pairViewport } from "@/components/pair-shell" + +export const viewport: Viewport = pairViewport + +export const metadata: Metadata = { ...pairMetadata, title: "Control Center" } + +/** `/d/` is the status page for one paired daemon. Everything under + * `/d//` is answered by that pairing's service worker; these routes only + * render when it isn't in control yet (see src/lib/pair.ts). */ +export default function DaemonLayout({ children }: { children: React.ReactNode }): React.ReactElement { + return <>{children} +} diff --git a/src/app/pair/layout.tsx b/src/app/pair/layout.tsx new file mode 100644 index 0000000..06b9b00 --- /dev/null +++ b/src/app/pair/layout.tsx @@ -0,0 +1,10 @@ +import type { Metadata, Viewport } from "next" +import { pairMetadata, pairViewport } from "@/components/pair-shell" + +export const viewport: Viewport = pairViewport + +export const metadata: Metadata = { ...pairMetadata, title: "Pair a phone" } + +export default function PairLayout({ children }: { children: React.ReactNode }): React.ReactElement { + return <>{children} +} diff --git a/src/app/pair/page.tsx b/src/app/pair/page.tsx new file mode 100644 index 0000000..4475130 --- /dev/null +++ b/src/app/pair/page.tsx @@ -0,0 +1,328 @@ +"use client" + +import { useCallback, useEffect, useRef, useState } from "react" +import { + inspectOffer, + pairFromOffer, + TunnelClientError, + type PairCredential, + type PairedDaemon, + type PendingPairing, +} from "@agentproto/pair-client" +import { Fingerprint, HowToPair, PairButton, PairShell } from "@/components/pair-shell" +import { SharedOriginNotice } from "@/components/shared-origin-notice" +import { isOutdatedPairingError, statusPath } from "@/lib/pair" +import { daemonOrigin, PAIR_DOMAIN } from "@/lib/pair-host" +import { + forgetPairing, + hostMode, + pairStore, + postToWorker, + registerPairingWorker, + serviceWorkersSupported, +} from "@/lib/pair-worker" + +type Phase = + | { kind: "loading" } + | { kind: "home"; pairings: PairCredential[] } + | { kind: "pairing"; fingerprint: string | null } + | { kind: "confirm"; daemon: PairedDaemon } + | { kind: "saving"; daemon: PairedDaemon } + | { kind: "cancelled"; daemon: PairedDaemon } + | { kind: "error"; title: string; message: string; outdated?: boolean } + /** The offer is for another daemon than this per-daemon origin's. */ + | { kind: "foreign"; here: string; offered: string; link: string } + /** A host under the pair domain that isn't `.`. */ + | { kind: "not_daemon_origin" } + | { kind: "unsupported" } + +const OFFER_PREFIX = "agentproto://pair?" + +/** + * Read the offer out of the fragment (`/pair#v=2&rv=…`, what `agentproto pair + * offer --qr` links to) and wipe it from the address bar and history right + * away, before anything else runs. The fragment is the query string of an + * `agentproto://pair?…` offer; it never reached a server. + */ +function takeOfferFromFragment(): string | null { + const fragment = window.location.hash.replace(/^#/, "") + if (!fragment) return null + window.history.replaceState(window.history.state, "", window.location.pathname + window.location.search) + return `${OFFER_PREFIX}${fragment}` +} + +/** The same offer on its own daemon's origin (the fragment is never sent to + * a server, and the offer isn't spent yet: only inspected). */ +function foreignPhase(here: string, offered: string, offer: string): Phase { + const link = `${daemonOrigin(offered, window.location)}/pair#${offer.slice(OFFER_PREFIX.length)}` + return { kind: "foreign", here, offered, link } +} + +/** How this phone is listed on the daemon (`agentproto pair ls`). */ +function deviceName(): string { + const ua = navigator.userAgent + const device = /iPhone/.test(ua) + ? "iPhone" + : /iPad/.test(ua) + ? "iPad" + : /Android/.test(ua) + ? "Android" + : /Macintosh/.test(ua) + ? "Mac" + : /Windows/.test(ua) + ? "Windows" + : /Linux/.test(ua) + ? "Linux" + : null + return device ? `${device} browser (${window.location.host})` : `browser@${window.location.host}` +} + +function describeError(err: unknown): { title: string; message: string; outdated?: boolean } { + const message = err instanceof Error ? err.message : String(err) + if (isOutdatedPairingError(err)) { + return { title: "This pairing link is from an older agentproto", message, outdated: true } + } + if (err instanceof TunnelClientError) { + if (err.code === "invalid_offer") { + return { title: "This pairing link is invalid or expired", message } + } + if (err.code === "pairing_failed") { + return { title: "Pairing failed", message } + } + } + return { title: "Something went wrong", message } +} + +export default function PairPage(): React.ReactElement { + const [phase, setPhase] = useState({ kind: "loading" }) + const pendingRef = useRef(null) + const startedRef = useRef(false) + + const loadHome = useCallback(async () => { + const pairings = await pairStore().list() + const launch = new URLSearchParams(window.location.search).get("launch") === "1" + // Home-screen launch with a single daemon: straight to it. + if (launch && pairings.length === 1) { + window.location.replace(statusPath(pairings[0]!.id)) + return + } + setPhase({ kind: "home", pairings }) + }, []) + + useEffect(() => { + // Runs once: the offer is single-use, so a second handshake (StrictMode + // re-running this effect) would only fail against the spent offer. + if (startedRef.current) return + startedRef.current = true + + const offer = takeOfferFromFragment() + const mode = hostMode() + if (mode.kind === "invalid") { + setPhase({ kind: "not_daemon_origin" }) + return + } + if (!serviceWorkersSupported()) { + setPhase({ kind: "unsupported" }) + return + } + if (!offer) { + void loadHome().catch(err => setPhase({ kind: "error", ...describeError(err) })) + return + } + void (async () => { + try { + const info = await inspectOffer(offer) + // A per-daemon origin pairs its own daemon only: refuse before any + // handshake, so the offer stays unspent for the right origin. + if (mode.kind === "daemon" && info.fingerprint !== mode.fingerprint) { + setPhase(foreignPhase(mode.fingerprint, info.fingerprint, offer)) + return + } + setPhase({ kind: "pairing", fingerprint: info.fingerprint }) + const pending = await pairFromOffer(offer, { store: pairStore(), clientName: deviceName() }) + if (mode.kind === "daemon" && pending.daemon.fingerprint !== mode.fingerprint) { + pending.cancel() + setPhase(foreignPhase(mode.fingerprint, pending.daemon.fingerprint, offer)) + return + } + pendingRef.current = pending + setPhase({ kind: "confirm", daemon: pending.daemon }) + } catch (err) { + setPhase({ kind: "error", ...describeError(err) }) + } + })() + }, [loadHome]) + + useEffect(() => { + // An offer link opened while this page is already showing is only a + // fragment change (no load): start over so the effect above reads it. + const onHashChange = (): void => { + if (window.location.hash.length > 1) window.location.reload() + } + window.addEventListener("hashchange", onHashChange) + return () => window.removeEventListener("hashchange", onHashChange) + }, []) + + const confirm = async (daemon: PairedDaemon) => { + const pending = pendingRef.current + if (!pending) return + setPhase({ kind: "saving", daemon }) + try { + const credential = await pending.confirm() + pendingRef.current = null + const reg = await registerPairingWorker(credential.id) + // A worker already running for this daemon (a re-pair after a revoke) + // still holds the old credential's client. + postToWorker(reg, { type: "agentproto-pair:reset" }) + window.location.replace(statusPath(credential.id)) + } catch (err) { + setPhase({ kind: "error", ...describeError(err) }) + } + } + + const cancel = (daemon: PairedDaemon) => { + pendingRef.current?.cancel() + pendingRef.current = null + setPhase({ kind: "cancelled", daemon }) + } + + const forget = async (id: string) => { + await forgetPairing(id) + await loadHome() + } + + switch (phase.kind) { + case "loading": + return + + case "unsupported": + return ( + +

+ Pairing needs service workers, which this browser (or this private window) doesn't offer. Open the + pairing link in Safari or Chrome. +

+
+ ) + + case "home": + if (phase.pairings.length === 0) { + return ( + + + + + ) + } + return ( + +
    + {phase.pairings.map(p => ( +
  • +
    {p.name}
    +
    {p.fingerprint}
    +
    + window.location.assign(statusPath(p.id))}>Open + void forget(p.id)}> + Forget + +
    +
  • + ))} +
+
+ Pair another daemon +
+ +
+
+ +
+ ) + + case "pairing": + return ( + + {phase.fingerprint && ( + <> +

The link names this daemon:

+ + + )} +

Running the end-to-end handshake through the rendezvous.

+
+ ) + + case "confirm": + case "saving": + return ( + +

Check that this fingerprint matches the one printed by agentproto pair offer:

+ + {phase.daemon.platform &&

{phase.daemon.platform}

} +
+ void confirm(phase.daemon)}> + {phase.kind === "saving" ? "Pairing…" : "Confirm"} + + cancel(phase.daemon)}> + Cancel + +
+ +
+ ) + + case "cancelled": + return ( + +

+ The daemon still lists this device. Remove it on the computer with{" "} + agentproto pair revoke {phase.daemon.fingerprint}. +

+ void loadHome()}> + Done + +
+ ) + + case "foreign": + return ( + +

+ This address pairs daemon {phase.here} only. The QR you scanned is for daemon: +

+ +

Nothing was saved. Open the pairing link on that daemon's own address:

+ + Open {phase.offered}.{PAIR_DOMAIN} + +
+ ) + + case "not_daemon_origin": + return ( + +

+ Pairing pages live at <daemon fingerprint>.{PAIR_DOMAIN}. Scan the QR from{" "} + agentproto pair offer --qr again, it opens the right address. +

+
+ ) + + case "error": + return ( + +

{phase.message}

+

+ {phase.outdated + ? "Update agentproto on the computer, then get a new pairing link:" + : "Pairing links are single-use and expire after a few minutes. Get a fresh one:"} +

+ +
+ ) + } +} diff --git a/src/components/pair-shell.tsx b/src/components/pair-shell.tsx new file mode 100644 index 0000000..b79028f --- /dev/null +++ b/src/components/pair-shell.tsx @@ -0,0 +1,103 @@ +import type { Metadata, Viewport } from "next" +import { cn } from "@/lib/utils" + +/** Shared by the `/pair` and `/d/` layouts: phone viewport, the + * add-to-home-screen manifest, and no indexing (these pages are per-device). */ +export const pairViewport: Viewport = { + width: "device-width", + initialScale: 1, + viewportFit: "cover", + themeColor: "#0d1512", +} + +export const pairMetadata: Metadata = { + manifest: "/pair.webmanifest", + robots: { index: false, follow: false }, + appleWebApp: { capable: true, title: "agentproto", statusBarStyle: "black-translucent" }, + icons: { apple: "/pair-icon-192.png" }, +} + +export type Tone = "neutral" | "ok" | "warn" | "danger" + +const DOT: Record = { + neutral: "bg-fd-muted-foreground", + ok: "bg-[var(--phos)] shadow-[0_0_6px_var(--phos)]", + warn: "bg-[var(--amber)] animate-pulse", + danger: "bg-[var(--color-fd-danger)]", +} + +export function PairShell({ + eyebrow, + title, + tone = "neutral", + children, +}: { + eyebrow: string + title: string + tone?: Tone + children?: React.ReactNode +}): React.ReactElement { + return ( +
+
+
+ + {eyebrow} +
+

{title}

+
{children}
+
+
+ ) +} + +export function Fingerprint({ value }: { value: string }): React.ReactElement { + return ( + + {value} + + ) +} + +export function PairButton({ + variant = "primary", + className, + ...props +}: React.ButtonHTMLAttributes & { variant?: "primary" | "secondary" | "danger" }): React.ReactElement { + return ( +