{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"agent-popup-01","title":"Agent Popup","author":"LiveKit (https://livekit.com)","description":"A floating chat-bubble trigger that expands into a compact agent session popup, suitable for embedding on any page.","dependencies":["@livekit/components-react@^2.0.0","livekit-client@^2.0.0","motion","lucide-react"],"registryDependencies":["utils","button","@agents-ui/agent-session-provider","@agents-ui/start-audio-button","@agents-ui/agent-session-view-01"],"files":[{"path":"components/agents-ui/blocks/agent-popup-01/components/agent-popup-block.tsx","content":"'use client';\n\nimport { useCallback, useEffect, useRef, useState, type ComponentProps } from 'react';\nimport { useAgent, useSession } from '@livekit/components-react';\nimport { type TokenSourceConfigurable, type TokenSourceFixed } from 'livekit-client';\n\nimport { type AgentControlBarControls } from '@/components/agents-ui/agent-control-bar';\nimport { AgentSessionProvider } from '@/components/agents-ui/agent-session-provider';\nimport type { AudioVisualizerConfig } from '@/components/agents-ui/blocks/agent-session-view-01/components/agent-session-block';\nimport { PopupView } from './popup-view';\nimport { Trigger } from './trigger';\n\nconst DEFAULT_CONTROLS: AgentControlBarControls = {\n  leave: false,\n  microphone: true,\n  chat: false,\n  camera: false,\n  screenShare: false,\n};\n\nexport interface AgentPopupError {\n  title: string;\n  description: string;\n}\n\nfunction TriggerProvider({ ...props }: ComponentProps<typeof Trigger>) {\n  const { isConnected } = useAgent();\n\n  return <Trigger {...props} isConnected={isConnected} />;\n}\n\nexport interface AgentPopupProps {\n  /** Logo shown in the trigger bubble in place of the default agent icon. */\n  logo?: string;\n  /** @default 'Agent' */\n  agentName?: string;\n  /** Where to fetch a LiveKit session token from. See `useSession`'s `tokenSource` argument. */\n  tokenSource: TokenSourceConfigurable | TokenSourceFixed;\n  /**\n   * Theme mode forwarded to the aura visualizer (`audioVisualizer.type === 'aura'`) so the\n   * shader's blend mode adapts to the theme mode. Ignored by other visualizer types.\n   */\n  themeMode?: 'dark' | 'light';\n  /**\n   * Message shown above the controls before the first chat message is sent.\n   *\n   * @default 'Agent is listening, ask it a question'\n   */\n  preConnectMessage?: string;\n  /**\n   * An object with the following keys: leave, microphone, screenShare, camera, chat. Each key maps\n   * to a boolean value that determines whether the control is displayed.\n   *\n   * @default { leave: false, microphone: true, chat: false, camera: false, screenShare: false }\n   */\n  controls?: AgentControlBarControls;\n  /** Brand color used for the trigger bubble's idle ring/disc and fallback icon contrast. */\n  triggerColor?: `#${string}`;\n  /**\n   * Shows a pre-connect buffer state with a shimmer message before messages appear.\n   *\n   * @default true\n   */\n  isPreConnectBufferEnabled?: boolean;\n  /**\n   * Configures the visualizer style rendered in the main tile area.\n   *\n   * @default { type: 'bar', size: 'lg' }\n   */\n  audioVisualizer?: AudioVisualizerConfig;\n}\n\nexport function AgentPopup_01({\n  logo,\n  themeMode,\n  tokenSource,\n  triggerColor,\n  agentName = 'Agent',\n  controls = DEFAULT_CONTROLS,\n  isPreConnectBufferEnabled,\n  preConnectMessage,\n  audioVisualizer = {\n    type: 'bar',\n    size: 'lg',\n  },\n}: AgentPopupProps) {\n  const session = useSession(tokenSource);\n  const [popupOpen, setPopupOpen] = useState(false);\n  const [error, setError] = useState<AgentPopupError>();\n\n  // Drive the session lifecycle off the popup-open state. Opening the popup\n  // connects; closing it (or unmounting) tears the room down so we don't\n  // leave a mic-hot connection while the bubble sits idle.\n  //\n  // useSession returns a fresh object on every connectionState change (the\n  // discriminated union swaps shape), so we can't depend on `session`\n  // directly - that would tear down + restart the room every time it\n  // transitioned through connecting -> connected. We pin the start/end\n  // calls via a ref instead, and only react to popupOpen.\n  const sessionRef = useRef(session);\n  sessionRef.current = session;\n\n  useEffect(() => {\n    if (!popupOpen) return;\n    let cancelled = false;\n    sessionRef.current.start().catch((cause) => {\n      if (cancelled) return;\n\n      console.error('agent-popup-01: session.start failed:', cause);\n      setError({\n        title: 'Could not connect to the agent',\n        description: cause instanceof Error ? cause.message : String(cause),\n      });\n    });\n    return () => {\n      cancelled = true;\n      void sessionRef.current.end();\n    };\n  }, [popupOpen]);\n\n  const handleToggle = useCallback(() => {\n    setPopupOpen((open) => {\n      const next = !open;\n      if (!next) setError(undefined);\n      return next;\n    });\n  }, []);\n\n  const finalControls = {\n    ...DEFAULT_CONTROLS,\n    ...controls,\n  };\n\n  return (\n    <AgentSessionProvider session={session}>\n      <TriggerProvider\n        logo={logo}\n        error={error}\n        color={triggerColor}\n        agentName={agentName}\n        isPressed={popupOpen}\n        onToggle={handleToggle}\n        className=\"fixed right-4 bottom-4 z-50\"\n      />\n      {popupOpen && (\n        <PopupView\n          logo={logo}\n          error={error}\n          agentName={agentName}\n          themeMode={themeMode}\n          isPreConnectBufferEnabled={isPreConnectBufferEnabled}\n          preConnectMessage={preConnectMessage}\n          audioVisualizer={audioVisualizer}\n          controls={finalControls}\n          onDisconnect={handleToggle}\n        />\n      )}\n    </AgentSessionProvider>\n  );\n}\n","type":"registry:component"},{"path":"components/agents-ui/blocks/agent-popup-01/components/trigger.tsx","content":"'use client';\n\nimport { useEffect, useState, type ComponentProps } from 'react';\nimport { BotIcon, PhoneOffIcon, XIcon } from 'lucide-react';\n\nimport { cn } from '@/lib/utils';\nimport { Button } from '@/components/ui/button';\nimport type { AgentPopupError } from './agent-popup-block';\n\nexport interface TriggerProps extends ComponentProps<'button'> {\n  /** Logo image shown in place of the default bot icon. */\n  logo?: string;\n  /** Brand color used for the idle ring/disc and, via contrast, the fallback icon color. */\n  color?: string;\n  /** Used to build the default `aria-label` (e.g. \"Rex agent\") and image `alt` text. */\n  agentName?: string;\n  /** Whether the popup is currently open. Drives the connecting/active/error visual states. */\n  isPressed?: boolean;\n  /** Whether the agent session is connected. Only relevant while `isPressed` is true. */\n  isConnected?: boolean;\n  /** Session error, if any. Only relevant while `isPressed` is true. */\n  error?: AgentPopupError;\n  /** Called when the trigger is clicked. */\n  onToggle: () => void;\n}\n\nexport function Trigger({\n  logo,\n  color,\n  error,\n  agentName,\n  isPressed = false,\n  isConnected = false,\n  onToggle,\n  className,\n  ...props\n}: TriggerProps) {\n  const altText = agentName ? `${agentName} agent` : 'Open assistant';\n  const isError = isPressed && error !== undefined;\n  const isActive = isPressed && error === undefined && isConnected;\n  const isConnecting = isPressed && !isError && !isActive;\n  const isDestructive = isError || isActive;\n  const [logoFailed, setLogoFailed] = useState(false);\n\n  useEffect(() => {\n    setLogoFailed(false);\n  }, [logo]);\n  const showLogo = Boolean(logo) && !logoFailed;\n\n  return (\n    <Button\n      type=\"button\"\n      size=\"lg\"\n      variant=\"ghost\"\n      onClick={onToggle}\n      aria-label={isPressed ? 'Close assistant' : altText}\n      aria-expanded={isPressed}\n      className={cn(\n        'relative m-0 block size-12 rounded-full p-0.5 drop-shadow-sm transition-transform duration-200 hover:scale-105 focus-visible:scale-105',\n        className,\n      )}\n      {...props}\n    >\n      <div\n        className={cn(\n          'absolute inset-0 rounded-full bg-current transition-colors',\n          isConnecting && 'animate-spin',\n          isConnecting &&\n            'bg-current/30 bg-conic from-transparent from-30% via-current via-50% to-transparent to-70%',\n          isDestructive && 'bg-transparent',\n        )}\n        style={{ color }}\n      />\n      <div\n        className={cn(\n          'absolute z-10 grid place-items-center rounded-full transition-colors inset-0',\n          isConnecting && 'bg-background text-background inset-0.5',\n          isDestructive && 'bg-destructive text-white',\n        )}\n      >\n        {isConnecting ? null : isError ? (\n          // The spinning ring is the connecting signal; skip a centred glyph\n          // so it reads as a clean spinner rather than a flashing X.\n          <XIcon className=\"size-5\" aria-hidden=\"true\" />\n        ) : isActive ? (\n          // Crossed-out phone on the solid destructive disc signals\n          // \"click to end the call\".\n          <PhoneOffIcon className=\"size-5\" aria-hidden=\"true\" />\n        ) : showLogo ? (\n          // eslint-disable-next-line @next/next/no-img-element\n          <img\n            src={logo}\n            alt={altText}\n            className=\"size-6 rounded-sm object-contain\"\n            referrerPolicy=\"no-referrer\"\n            onError={() => setLogoFailed(true)}\n          />\n        ) : (\n          // Pick black vs white based on the user-set brand color so the\n          // icon stays readable across a bright yellow, deep navy, etc.\n          <BotIcon\n            className=\"text-background size-6\"\n            aria-hidden=\"true\"\n            style={\n              color\n                ? {\n                    color: `contrast-color(${color})`,\n                  }\n                : undefined\n            }\n          />\n        )}\n      </div>\n    </Button>\n  );\n}\n","type":"registry:component"},{"path":"components/agents-ui/blocks/agent-popup-01/components/popup-view.tsx","content":"'use client';\n\nimport { useEffect, useState } from 'react';\nimport { AnimatePresence, motion } from 'motion/react';\nimport { StartAudioButton } from '@/components/agents-ui/start-audio-button';\nimport { type AgentControlBarControls } from '@/components/agents-ui/agent-control-bar';\nimport { AgentSessionView_01 } from '@/components/agents-ui/blocks/agent-session-view-01/components/agent-session-block';\nimport type { AudioVisualizerConfig } from '@/components/agents-ui/blocks/agent-session-view-01/components/agent-session-block';\nimport { cn } from '@/lib/utils';\nimport type { AgentPopupError } from './agent-popup-block';\n\ninterface ErrorOverlayProps {\n  logo?: string;\n  agentName?: string;\n  error?: AgentPopupError;\n}\n\nfunction ErrorOverlay({ logo, agentName, error }: ErrorOverlayProps) {\n  const [logoFailed, setLogoFailed] = useState(false);\n  useEffect(() => {\n    setLogoFailed(false);\n  }, [logo]);\n  const showLogo = Boolean(logo) && !logoFailed;\n\n  return error ? (\n    <motion.div\n      initial={{ opacity: 0 }}\n      animate={{ opacity: 1 }}\n      data-testid=\"error-overlay\"\n      // @ts-expect-error React's types lag the platform on `inert`.\n      inert={error === null ? '' : undefined}\n      className={cn(\n        'bg-background absolute inset-0 z-50 flex h-full w-full flex-col items-center justify-center gap-5 px-6 text-center transition-opacity',\n      )}\n    >\n      {showLogo ? (\n        // eslint-disable-next-line @next/next/no-img-element\n        <img\n          src={logo}\n          alt={`${agentName ?? 'Agent'} logo`}\n          className=\"size-6 object-contain\"\n          referrerPolicy=\"no-referrer\"\n          onError={() => setLogoFailed(true)}\n        />\n      ) : null}\n      <span className=\"text-foreground leading-tight font-medium text-pretty\">{error?.title}</span>\n      <span className=\"text-muted-foreground text-sm text-balance\">{error?.description}</span>\n    </motion.div>\n  ) : null;\n}\n\nexport interface PopupViewProps {\n  agentName?: string;\n  logo?: string;\n  error?: AgentPopupError;\n  controls: AgentControlBarControls;\n  themeMode?: 'dark' | 'light';\n  preConnectMessage?: string;\n  isPreConnectBufferEnabled?: boolean;\n  audioVisualizer?: AudioVisualizerConfig;\n  onDisconnect?: () => void;\n}\n\nexport function PopupView({\n  agentName,\n  logo,\n  error,\n  controls,\n  themeMode,\n  isPreConnectBufferEnabled,\n  preConnectMessage,\n  audioVisualizer,\n  onDisconnect,\n}: PopupViewProps) {\n  return (\n    <motion.div\n      initial={{ opacity: 0, translateY: 8 }}\n      animate={{ opacity: 1, translateY: 0 }}\n      exit={{ opacity: 0, translateY: 8 }}\n      transition={{ type: 'spring', bounce: 0, duration: 0.4 }}\n      className=\"fixed right-4 bottom-20 left-4 z-50 h-[480px] md:left-auto md:w-[360px]\"\n    >\n      <div className=\"relative flex h-full w-full flex-col overflow-hidden rounded-[40px] border drop-shadow-md\">\n        <AnimatePresence>\n          <ErrorOverlay logo={logo} agentName={agentName} error={error} />\n        </AnimatePresence>\n        <StartAudioButton label=\"Enable Audio\" className=\"mx-4 mt-2 rounded-full\" />\n        <AgentSessionView_01\n          controls={controls}\n          themeMode={themeMode}\n          isPreConnectBufferEnabled={isPreConnectBufferEnabled}\n          preConnectMessage={preConnectMessage}\n          audioVisualizer={audioVisualizer}\n          onDisconnect={onDisconnect}\n        />\n      </div>\n    </motion.div>\n  );\n}\n","type":"registry:component"},{"path":"components/agents-ui/blocks/agent-popup-01/index.ts","content":"export * from './components/agent-popup-block';\nexport * from './components/trigger';\n","type":"registry:item"}],"categories":["agents","blocks"],"type":"registry:block"}