{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "connection-state",
  "title": "Connection State",
  "description": "Clear connected, reconnecting, resumed, and offline states for resumable agent streams.",
  "dependencies": [
    "@solar-icons/react@^2.2.0",
    "cn@^0.3.0",
    "motion@^13.4.0"
  ],
  "registryDependencies": [
    "button",
    "https://pastaui.com/r/pastaui-styles.json"
  ],
  "files": [
    {
      "path": "src/components/ai/connection-state.tsx",
      "content": "import { CheckCircleIcon as CheckCircle2Icon } from '@solar-icons/react/linear/check-circle'\nimport { CloudCrossIcon as CloudOffIcon } from '@solar-icons/react/linear/cloud-cross'\nimport { LoaderIcon as LoaderCircleIcon } from '@solar-icons/react/linear/loader'\nimport { RefreshIcon as RefreshCwIcon } from '@solar-icons/react/linear/refresh'\nimport { WiFiIcon as WifiIcon } from '@solar-icons/react/linear/wi-fi'\nimport { AltArrowDownIcon as ChevronDownIcon } from '@solar-icons/react/linear/alt-arrow-down'\nimport { AnimatePresence, MotionConfig, motion } from 'motion/react'\nimport * as React from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { cn } from 'cn'\n\ntype ConnectionStatus = 'connected' | 'offline' | 'reconnected' | 'reconnecting'\n\ninterface ConnectionEvent {\n  id: string\n  label: string\n  state: ConnectionStatus\n  time: string\n}\n\ninterface ConnectionStateProps extends React.ComponentProps<'div'> {\n  attempt?: number\n  defaultLogOpen?: boolean\n  detail?: string\n  events?: ConnectionEvent[]\n  maxAttempts?: number\n  onRetry?: () => void\n  retryDelay?: number\n  retryIn?: number\n  state: ConnectionStatus\n}\n\nconst ease = [0.23, 1, 0.32, 1] as const\n\nconst copy: Record<ConnectionStatus, string> = {\n  connected: 'Connected',\n  offline: 'Connection lost',\n  reconnected: 'Stream resumed',\n  reconnecting: 'Reconnecting',\n}\n\nfunction ConnectionState({\n  attempt,\n  className,\n  defaultLogOpen = false,\n  detail,\n  events = [],\n  maxAttempts,\n  onRetry,\n  retryDelay,\n  retryIn,\n  state,\n  ...props\n}: ConnectionStateProps) {\n  const logId = React.useId()\n  const [logOpen, setLogOpen] = React.useState(defaultLogOpen)\n  const waiting = state === 'reconnecting' && retryIn !== undefined && retryIn > 0\n  const status =\n    state === 'reconnecting' && attempt !== undefined\n      ? `Attempt ${attempt}${maxAttempts ? ` of ${maxAttempts}` : ''}${waiting ? ` · next try in ${retryIn}s` : ''}`\n      : undefined\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div\n        data-slot=\"connection-state\"\n        data-state={state}\n        className={cn(\n          'overflow-hidden rounded-[16px] bg-card font-sans text-sm font-[450] tracking-[-0.05px] text-muted-foreground shadow-card transition-colors duration-200 ease-out',\n          className,\n        )}\n        {...props}\n      >\n        <div\n          aria-live=\"polite\"\n          className={cn('flex items-center gap-3 p-3', state === 'offline' && 'text-destructive')}\n        >\n          <span className=\"grid size-4 shrink-0 place-items-center\">\n            <AnimatePresence initial={false} mode=\"popLayout\">\n              <motion.span\n                animate={{ opacity: 1, scale: 1 }}\n                className=\"col-start-1 row-start-1 flex\"\n                exit={{ opacity: 0, scale: 0.7 }}\n                initial={{ opacity: 0, scale: 0.7 }}\n                key={state}\n                transition={{ duration: 0.2, ease }}\n              >\n                <ConnectionIcon state={state} />\n              </motion.span>\n            </AnimatePresence>\n          </span>\n          <div className=\"min-w-0 flex-1\">\n            <AnimatePresence initial={false} mode=\"popLayout\">\n              <motion.p\n                animate={{ opacity: 1, y: 0 }}\n                className=\"card-heading\"\n                exit={{ opacity: 0, y: -4 }}\n                initial={{ opacity: 0, y: 4 }}\n                key={state}\n                transition={{ duration: 0.2, ease }}\n              >\n                {copy[state]}\n              </motion.p>\n            </AnimatePresence>\n            {(status || detail) && (\n              <p className=\"mt-0.5 truncate text-xs leading-5 tabular-nums opacity-70\">\n                {status ?? detail}\n              </p>\n            )}\n          </div>\n          {(state === 'offline' || waiting) && onRetry && (\n            <Button\n              className=\"transition-[opacity,background-color] duration-150 ease-out starting:opacity-0\"\n              onClick={onRetry}\n              size=\"sm\"\n              variant=\"outline\"\n            >\n              <RefreshCwIcon data-icon=\"inline-start\" /> {waiting ? 'Retry now' : 'Retry'}\n            </Button>\n          )}\n          {events.length > 0 && (\n            <Button\n              aria-controls={logId}\n              aria-expanded={logOpen}\n              aria-label={logOpen ? 'Hide connection log' : 'Show connection log'}\n              onClick={() => setLogOpen((open) => !open)}\n              size=\"icon-sm\"\n              variant=\"ghost\"\n            >\n              <ChevronDownIcon\n                className={cn(\n                  'transition-[rotate] duration-200 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none',\n                  logOpen && 'rotate-180',\n                )}\n              />\n            </Button>\n          )}\n        </div>\n        <div aria-hidden=\"true\" className=\"h-0.5 bg-muted\">\n          <motion.div\n            animate={{\n              opacity: waiting ? 1 : 0,\n              scaleX: waiting && retryDelay ? (retryIn ?? 0) / retryDelay : 0,\n            }}\n            className=\"h-full origin-left bg-muted-foreground\"\n            initial={false}\n            transition={{ duration: waiting ? 1 : 0.2, ease: 'linear' }}\n          />\n        </div>\n        <AnimatePresence initial={false}>\n          {logOpen && events.length > 0 && (\n            <motion.div\n              animate={{ height: 'auto', opacity: 1 }}\n              className=\"overflow-hidden\"\n              exit={{ height: 0, opacity: 0 }}\n              id={logId}\n              initial={{ height: 0, opacity: 0 }}\n              transition={{ duration: 0.22, ease }}\n            >\n              <ol aria-label=\"Connection log\" className=\"space-y-2 px-3 py-3\">\n                <AnimatePresence initial={false}>\n                  {events.map((event) => (\n                    <motion.li\n                      animate={{ opacity: 1, y: 0 }}\n                      className={cn(\n                        'flex items-center gap-3 text-xs leading-5',\n                        event.state === 'offline' && 'text-destructive',\n                      )}\n                      initial={{ opacity: 0, y: -4 }}\n                      key={event.id}\n                      layout=\"position\"\n                      transition={{ duration: 0.2, ease }}\n                    >\n                      <span className=\"flex size-4 shrink-0 items-center justify-center\">\n                        <ConnectionIcon state={event.state} small />\n                      </span>\n                      <span className=\"min-w-0 flex-1 truncate\">{event.label}</span>\n                      <span className=\"shrink-0 tabular-nums opacity-70\">{event.time}</span>\n                    </motion.li>\n                  ))}\n                </AnimatePresence>\n              </ol>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    </MotionConfig>\n  )\n}\n\nfunction ConnectionIcon({ small, state }: { small?: boolean; state: ConnectionStatus }) {\n  const size = small ? 'size-3.5' : 'size-4'\n  if (state === 'offline') return <CloudOffIcon className={size} />\n  if (state === 'reconnecting')\n    return <LoaderCircleIcon className={cn(size, 'animate-spin motion-reduce:animate-none')} />\n  if (state === 'reconnected') return <CheckCircle2Icon className={cn(size, 'text-emerald-600')} />\n  return <WifiIcon className={cn(size, 'text-muted-foreground')} />\n}\n\nexport { ConnectionState }\nexport type { ConnectionEvent, ConnectionStateProps, ConnectionStatus }\n",
      "type": "registry:component",
      "target": "@components/ai/connection-state.tsx"
    }
  ],
  "type": "registry:component"
}