import { useId } from "react"; import { Check, Circle, Loader2 } from "lucide-react"; import { AGENT_ROLES, type CreateGrokInvitation, type DotPairing, type GrokConnection } from "@paperclipai/shared"; import { AdapterMark } from "../AdapterMark"; import { AgentSetupPrompt } from "../AgentSetupPrompt"; import { Button, buttonVariants } from "../ui/button"; import { CopyText } from "../CopyText"; import { Input } from "../ui/input"; import { NativeSelect } from "../ui/select"; import { DialogDescription, DialogTitle } from "../ui/dialog"; import { buildGrokAccessPrompt, buildGrokRoutinePrompt } from "@/lib/grok-bot-setup-prompt"; import { Link } from "@/lib/router"; export type GrokSetupStep = 0 | 1 | 2 | 3; export interface GrokBotSetupContentProps { step: GrokSetupStep; companyName: string; details: CreateGrokInvitation; created: boolean; loading?: boolean; busy?: boolean; error?: string; managers: Array<{ id: string; name: string }>; connection?: GrokConnection; pairing: DotPairing | null; approvalHref?: string; webhookUrl: string; webhookKey: string; editingCredentials?: boolean; onEditCredentials?: () => void; onDetails: (details: CreateGrokInvitation) => void; onCredentials: (url: string, key: string) => void; onBack: () => void; onExit: () => void; onNext: () => void; onRetry: () => void; } const steps = ["Identify Bot", "Connect access", "Enable assignments", "Verify"]; export function GrokBotSetupContent(p: GrokBotSetupContentProps) { const pairingCodeId = useId(); const binding = p.connection?.binding; const routine = binding?.routine; const exchange = routine?.lastExchange; const delivered = exchange?.status === "accepted" || exchange?.status === "acknowledged"; const replied = !!routine?.verified && exchange?.status === "acknowledged"; const ready = replied && p.connection?.agentLifecycleState === "ready" && !!p.connection.canConfigureConnection && !routine?.recoveryNeeded; const pending = exchange && ["prepared", "sending", "accepted"].includes(exchange.status) && Date.parse(exchange.expiresAt) > Date.now(); const nextDisabled = p.busy || p.loading || !!p.approvalHref || p.step === 0 && (!p.details.name.trim() || !p.details.botName.trim()) || p.step === 1 && !binding?.connected || p.step === 2 && ((!routine?.configured || p.editingCredentials) && (!p.webhookUrl || !p.webhookKey)) || p.step === 3 && !ready && (!!pending || !!routine?.recoveryNeeded || !!replied); return <>
{p.error}
Restoring saved setup…
: p.approvalHref ?An organization admin needs to approve this agent. Setup is saved and will resume after approval.
: <> {p.step === 0 &&Use the name shown in the Grok Bot desktop app. Bot web links may no longer work.
Copy the connection instructions into your Bot’s chat. Add the custom MCP plugin and complete its browser authorization.
{p.connection?.resourceUrl &&Copy this code into Paperclip’s authorization page. Do not paste it into Bot chat. Expires {new Date(p.pairing.expiresAt).toLocaleTimeString()}.
{binding?.connected ? "Agent access connected." : "Watching for authorization. This connection works as the named agent."}
Grok plugins are account-wide. Linking one Bot does not isolate its credentials from other Bots on your account.
Ask your Bot to create a webhook-only routine, then open its Webhook panel in the desktop app.
{binding &&If clicking the routine does nothing, use the “Webhook URL” navigation link the Bot supplies.
{routine?.configured && !p.editingCredentials && !p.webhookUrl && !p.webhookKey ?Routine credentials are stored. Continue to verify both directions.
{p.onEditCredentials && }Copy these fields directly from Grok into Paperclip. Credentials are stored securely and are never included in instructions.
{check.done ?
{routine?.recoveryNeeded ? "Recovery needed. Inspect Grok’s activity in this agent’s configuration before another delivery." : ready ? "Both directions verified. Your Bot is ready for tasks." : replied ? "Both directions verified. Paperclip is finishing agent setup." : exchange?.status === "rejected" ? "The routine rejected delivery. Check its URL and key, then try again." : delivered ? "The routine accepted delivery. Waiting for an authenticated reply to Paperclip." : "Send a harmless challenge. This creates no task."}
Grok runs externally. Usage and spending are not reported. Paperclip contact does not prove the Bot is continuously available.