import { Trans, useLingui } from "@lingui/react/macro"; import type { CapabilityInstall } from "@rakazo/contracts"; import { GITHUB_MCP_SOURCE, GITHUB_TOKEN_URL, isGithubInstall } from "@rakazo/core"; import { Button, buttonVariants, cn, Input } from "@rakazo/ui-web"; import { useState } from "react"; import { rpc } from "../../lib/rpc"; /** GitHub's mark, monochrome like the rest of the app. */ function GithubMark({ className }: { className?: string }) { return ( ); } /** * GitHub without a vendor account or an app registration: a token from GitHub's prefilled form * connects GitHub's own MCP server for every bot. */ export function GithubConnect({ sources, onChanged, }: { sources: CapabilityInstall[]; onChanged: () => Promise; }) { const { t } = useLingui(); const installed = sources.find(isGithubInstall); const [open, setOpen] = useState(false); const [token, setToken] = useState(""); const [pending, setPending] = useState(false); const [error, setError] = useState(null); async function run(task: () => Promise) { setPending(true); setError(null); try { await task(); await onChanged(); } catch (err) { setError(err instanceof Error ? err.message : t`Could not connect GitHub`); } finally { setPending(false); } } return (
GitHub
{installed ? ( <> Connected ) : open ? null : ( )}
{!installed && open ? (
{ event.preventDefault(); void run(async () => { await rpc.capabilities.install({ kind: "mcp", name: "GitHub", source: GITHUB_MCP_SOURCE, credential: token.trim(), config: { preset: "github" }, }); setToken(""); setOpen(false); }); }} > Create token on GitHub
setToken(event.target.value)} aria-label={t`GitHub token`} placeholder="ghp_…" className="h-10 flex-1 rounded-full px-4" />
) : null} {error ?

{error}

: null}
); }