{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "conversation",
  "title": "Conversation",
  "description": "Live scrolling transcript of the user/agent conversation with role labels, karaoke text rendering, function-call cards, and connection-aware empty states.",
  "dependencies": [
    "@pipecat-ai/client-js@^1.14.0",
    "@pipecat-ai/client-react@^1.9.0",
    "lucide-react@^1.41.0"
  ],
  "registryDependencies": [
    "collapsible"
  ],
  "files": [
    {
      "path": "src/components/conversation.tsx",
      "content": "\"use client\";\n\nimport type { ConversationMessage } from \"@pipecat-ai/client-react\";\nimport {\n  useConversationContext,\n  usePipecatClientTransportState,\n  usePipecatConversation,\n} from \"@pipecat-ai/client-react\";\nimport { useCallback, useEffect, useMemo, useRef } from \"react\";\n\nimport {\n  ConversationMessageItem,\n  type ConversationMessageItemProps,\n  type TextRenderMode,\n} from \"@/components/pipecat/conversation-message\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ConversationViewProps extends Omit<\n  ConversationMessageItemProps,\n  \"message\" | \"className\"\n> {\n  /** Messages to render. */\n  messages?: ConversationMessage[];\n  /** Disable automatic scrolling when new messages arrive. */\n  noAutoscroll?: boolean;\n  /** Newest messages first; auto-scroll targets the top. */\n  reverseOrder?: boolean;\n  /** Rendered when there are no messages. */\n  empty?: React.ReactNode;\n  className?: string;\n  /** Classes for each message row. */\n  messageClassName?: string;\n}\n\n/**\n * Scrolling conversation list. Auto-scrolls to the newest message unless\n * the user has scrolled away. Fully props-driven; pair with the connected\n * Conversation for Pipecat wiring.\n */\nexport function ConversationView({\n  messages = [],\n  noAutoscroll = false,\n  reverseOrder = false,\n  empty,\n  className,\n  messageClassName,\n  ...messageProps\n}: ConversationViewProps) {\n  const scrollRef = useRef<HTMLDivElement>(null);\n  const isScrolledToEdge = useRef(true);\n\n  const maybeScrollToEdge = useCallback(() => {\n    if (!scrollRef.current) return;\n    if (isScrolledToEdge.current) {\n      scrollRef.current.scrollTo({\n        top: reverseOrder ? 0 : scrollRef.current.scrollHeight,\n        behavior: \"smooth\",\n      });\n    }\n  }, [reverseOrder]);\n\n  const lastScrollTop = useRef(0);\n\n  // Only a scroll away from the edge detaches. Our own smooth scroll reports\n  // intermediate positions short of the edge while it moves toward it.\n  const updateScrollState = useCallback(() => {\n    if (!scrollRef.current) return;\n    const { clientHeight, scrollHeight, scrollTop } = scrollRef.current;\n    const movedAway = reverseOrder\n      ? scrollTop > lastScrollTop.current\n      : scrollTop < lastScrollTop.current;\n    // Tracked even while noAutoscroll is set, so re-enabling starts fresh.\n    lastScrollTop.current = scrollTop;\n    if (noAutoscroll) return;\n    const atEdge = reverseOrder\n      ? scrollTop <= 1\n      : Math.ceil(scrollHeight - scrollTop) <= Math.ceil(clientHeight);\n    if (atEdge) isScrolledToEdge.current = true;\n    else if (movedAway) isScrolledToEdge.current = false;\n  }, [noAutoscroll, reverseOrder]);\n\n  useEffect(() => {\n    if (noAutoscroll) return;\n    if (messages.length === 0) {\n      isScrolledToEdge.current = true;\n      lastScrollTop.current = 0;\n    }\n    maybeScrollToEdge();\n  }, [messages, maybeScrollToEdge, noAutoscroll]);\n\n  if (messages.length === 0) {\n    return (\n      <div\n        data-slot=\"conversation\"\n        className={cn(\"relative flex h-full flex-col\", className)}\n      >\n        <div className=\"flex flex-1 items-center justify-center\">\n          {empty ?? (\n            <div className=\"text-muted-foreground text-sm\">\n              Waiting for messages…\n            </div>\n          )}\n        </div>\n      </div>\n    );\n  }\n\n  return (\n    <div\n      data-slot=\"conversation\"\n      className={cn(\"relative flex h-full flex-col\", className)}\n    >\n      <div\n        ref={scrollRef}\n        onScroll={updateScrollState}\n        className=\"relative flex-1 overflow-y-auto p-4\"\n      >\n        <div className=\"flex flex-col gap-4\">\n          {(reverseOrder ? [...messages].reverse() : messages).map(\n            (message, index) => (\n              <ConversationMessageItem\n                key={`${message.createdAt}-${index}`}\n                message={message}\n                className={messageClassName}\n                {...messageProps}\n              />\n            ),\n          )}\n        </div>\n      </div>\n    </div>\n  );\n}\n\nexport interface ConversationProps extends Omit<\n  ConversationViewProps,\n  \"messages\" | \"empty\"\n> {\n  /** Hide function-call messages (they remain captured in the store). */\n  noFunctionCalls?: boolean;\n  /** Controls how bot message text is rendered. */\n  textRenderMode?: TextRenderMode;\n}\n\n/**\n * Live conversation wired to the Pipecat client, with connection-aware\n * empty states. Must be rendered inside a PipecatClientProvider.\n */\nexport function Conversation({\n  noFunctionCalls = false,\n  textRenderMode,\n  aggregationMetadata,\n  ...props\n}: ConversationProps) {\n  const transportState = usePipecatClientTransportState();\n\n  // \"captions\" mode only needs spoken text; the other modes need all data.\n  const botOutputFilter = useMemo(() => {\n    if (textRenderMode === \"captions\") return { unspoken: false };\n    return undefined;\n  }, [textRenderMode]);\n\n  const { messages: allMessages } = usePipecatConversation({\n    aggregationMetadata,\n    botOutputFilter,\n  });\n  const { botOutputSupported } = useConversationContext();\n\n  const messages = useMemo(\n    () =>\n      noFunctionCalls\n        ? allMessages.filter((m) => m.role !== \"function_call\")\n        : allMessages,\n    [allMessages, noFunctionCalls],\n  );\n\n  const isConnecting =\n    transportState === \"authenticating\" || transportState === \"connecting\";\n  const isConnected =\n    transportState === \"connected\" || transportState === \"ready\";\n\n  let empty: React.ReactNode;\n  if (isConnecting) {\n    empty = (\n      <div className=\"text-muted-foreground text-sm\">Connecting to agent…</div>\n    );\n  } else if (!isConnected) {\n    empty = (\n      <div className=\"p-4 text-center\">\n        <div className=\"text-muted-foreground mb-2\">Not connected to agent</div>\n        <p className=\"text-muted-foreground max-w-md text-sm\">\n          Connect to an agent to see conversation messages in real-time.\n        </p>\n      </div>\n    );\n  } else if (botOutputSupported === false) {\n    empty = (\n      <div className=\"max-w-md p-4 text-center\">\n        <div className=\"text-destructive mb-2 font-medium\">\n          BotOutput events not supported\n        </div>\n        <p className=\"text-muted-foreground text-sm\">\n          This server does not support BotOutput events (requires RTVI 1.1.0+).\n          Conversation messages cannot be displayed without them.\n        </p>\n      </div>\n    );\n  }\n\n  return (\n    <ConversationView\n      messages={messages}\n      empty={empty}\n      textRenderMode={textRenderMode}\n      aggregationMetadata={aggregationMetadata}\n      {...props}\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/pipecat/conversation.tsx"
    },
    {
      "path": "src/components/conversation-message.tsx",
      "content": "\"use client\";\n\nimport type {\n  AggregationMetadata,\n  BotOutputText,\n  ConversationMessage,\n  ConversationMessagePart,\n  FunctionCallData,\n  FunctionCallRenderer,\n} from \"@pipecat-ai/client-react\";\nimport { isMessageEmpty } from \"@pipecat-ai/client-react\";\nimport {\n  CheckIcon,\n  ChevronRightIcon,\n  LoaderCircleIcon,\n  XIcon,\n} from \"lucide-react\";\nimport { Fragment, useEffect, useState } from \"react\";\n\nimport {\n  Collapsible,\n  CollapsibleContent,\n  CollapsibleTrigger,\n} from \"@/components/ui/collapsible\";\nimport { cn } from \"@/lib/utils\";\n\n/** Controls how bot message text is rendered. */\nexport type TextRenderMode = \"karaoke\" | \"captions\" | \"instant\";\n\nexport type BotOutputRenderer = (\n  content: string,\n  metadata: { spoken: string; unspoken: string },\n) => React.ReactNode;\n\nconst timeFormatter = new Intl.DateTimeFormat(undefined, {\n  hour: \"numeric\",\n  minute: \"numeric\",\n  second: \"numeric\",\n});\n\n/** Animated \"…\" typing indicator. */\nexport function Thinking({\n  className,\n  interval = 500,\n  maxDots = 3,\n}: {\n  className?: string;\n  interval?: number;\n  maxDots?: number;\n}) {\n  const [dots, setDots] = useState(1);\n\n  useEffect(() => {\n    const i = setInterval(() => {\n      setDots((prev) => (prev % maxDots) + 1);\n    }, interval);\n    return () => clearInterval(i);\n  }, [interval, maxDots]);\n\n  return (\n    <span className={className} aria-label=\"Thinking\">\n      {\".\".repeat(dots)}\n    </span>\n  );\n}\n\nexport interface MessageRoleProps {\n  role: ConversationMessage[\"role\"];\n  assistantLabel?: string;\n  clientLabel?: string;\n  systemLabel?: string;\n  functionCallLabel?: string;\n  className?: string;\n}\n\n/** Role label for a conversation message, colored by participant. */\nexport function MessageRole({\n  role,\n  assistantLabel = \"assistant\",\n  clientLabel = \"user\",\n  systemLabel = \"system\",\n  functionCallLabel = \"function call\",\n  className,\n}: MessageRoleProps) {\n  const labels: Record<string, string> = {\n    user: clientLabel,\n    assistant: assistantLabel,\n    system: systemLabel,\n    function_call: functionCallLabel,\n  };\n\n  return (\n    <div\n      data-slot=\"message-role\"\n      className={cn(\n        \"w-max font-mono text-xs leading-6 font-semibold\",\n        {\n          \"text-client-foreground\": role === \"user\",\n          \"text-agent-foreground\": role === \"assistant\",\n          \"text-muted-foreground\":\n            role === \"system\" || role === \"function_call\",\n        },\n        className,\n      )}\n    >\n      {labels[role] || role}\n    </div>\n  );\n}\n\nfunction StatusIcon({\n  status,\n  cancelled,\n}: {\n  status: FunctionCallData[\"status\"];\n  cancelled?: boolean;\n}) {\n  if (status === \"completed\" && cancelled) {\n    return <XIcon className=\"text-destructive size-3.5\" />;\n  }\n  switch (status) {\n    case \"started\":\n    case \"in_progress\":\n      return <LoaderCircleIcon className=\"size-3.5 animate-spin\" />;\n    case \"completed\":\n      return <CheckIcon className=\"text-active size-3.5\" />;\n  }\n}\n\nexport interface FunctionCallContentProps {\n  functionCall: FunctionCallData;\n  functionCallLabel?: string;\n  /** Replaces the default rendering entirely. */\n  functionCallRenderer?: FunctionCallRenderer;\n  className?: string;\n}\n\n/** Collapsible display of a function call with its args and result. */\nexport function FunctionCallContent({\n  functionCall,\n  functionCallLabel = \"Function call\",\n  functionCallRenderer,\n  className,\n}: FunctionCallContentProps) {\n  const [isOpen, setIsOpen] = useState(false);\n\n  if (functionCallRenderer) {\n    return <>{functionCallRenderer(functionCall)}</>;\n  }\n\n  const hasDetails =\n    (functionCall.args && Object.keys(functionCall.args).length > 0) ||\n    functionCall.result !== undefined;\n\n  return (\n    <Collapsible open={isOpen} onOpenChange={setIsOpen}>\n      <div className={cn(\"flex flex-col gap-1\", className)}>\n        <CollapsibleTrigger\n          disabled={!hasDetails}\n          className={cn(\n            \"text-muted-foreground flex items-center gap-2 font-mono text-xs transition-colors select-none\",\n            hasDetails\n              ? \"hover:text-foreground cursor-pointer\"\n              : \"cursor-default\",\n          )}\n        >\n          {hasDetails && (\n            <ChevronRightIcon\n              className={cn(\n                \"size-3.5 transition-transform duration-200\",\n                isOpen && \"rotate-90\",\n              )}\n            />\n          )}\n          <StatusIcon\n            status={functionCall.status}\n            cancelled={functionCall.cancelled}\n          />\n          <span className=\"font-semibold\">{functionCallLabel}</span>\n          {functionCall.function_name && (\n            <span className=\"text-muted-foreground\">\n              ({functionCall.function_name})\n            </span>\n          )}\n        </CollapsibleTrigger>\n\n        {hasDetails && (\n          <CollapsibleContent>\n            <div className=\"border-muted mt-1 ml-3.5 flex flex-col gap-2 border-l-2 pl-3 font-mono text-xs\">\n              {functionCall.args &&\n                Object.keys(functionCall.args).length > 0 && (\n                  <div>\n                    <div className=\"text-muted-foreground mb-1 font-semibold\">\n                      Arguments\n                    </div>\n                    <pre className=\"bg-muted/50 overflow-x-auto rounded p-2 break-all whitespace-pre-wrap\">\n                      {JSON.stringify(functionCall.args, null, 2)}\n                    </pre>\n                  </div>\n                )}\n              {functionCall.result !== undefined && (\n                <div>\n                  <div className=\"text-muted-foreground mb-1 font-semibold\">\n                    Result\n                  </div>\n                  <pre className=\"bg-muted/50 overflow-x-auto rounded p-2 break-all whitespace-pre-wrap\">\n                    {typeof functionCall.result === \"string\"\n                      ? functionCall.result\n                      : JSON.stringify(functionCall.result, null, 2)}\n                  </pre>\n                </div>\n              )}\n            </div>\n          </CollapsibleContent>\n        )}\n      </div>\n    </Collapsible>\n  );\n}\n\nfunction isBotOutputText(\n  part: ConversationMessagePart,\n): part is ConversationMessagePart & { text: BotOutputText } {\n  const text = part.text;\n  return (\n    text !== null &&\n    typeof text === \"object\" &&\n    \"spoken\" in text &&\n    \"unspoken\" in text\n  );\n}\n\nfunction renderBotOutput(\n  spoken: string,\n  unspoken: string,\n  aggregatedBy?: string,\n  customRenderer?: BotOutputRenderer,\n  metadata?: AggregationMetadata,\n  textRenderMode?: TextRenderMode,\n): React.ReactNode {\n  if (aggregatedBy && customRenderer) {\n    return customRenderer(spoken + unspoken, { spoken, unspoken });\n  }\n\n  const displayMode = metadata?.displayMode || \"inline\";\n  const Wrapper = displayMode === \"block\" ? \"div\" : \"span\";\n\n  if (textRenderMode === \"instant\") {\n    return (\n      <Wrapper>\n        {spoken}\n        {unspoken}\n      </Wrapper>\n    );\n  }\n\n  return (\n    <Wrapper>\n      {spoken}\n      {unspoken && <span className=\"text-muted-foreground\">{unspoken}</span>}\n    </Wrapper>\n  );\n}\n\nfunction renderPartContent(\n  part: ConversationMessagePart,\n  botOutputRenderers?: Record<string, BotOutputRenderer>,\n  aggregationMetadata?: Record<string, AggregationMetadata>,\n  textRenderMode?: TextRenderMode,\n): React.ReactNode {\n  if (!part.text) return null;\n  if (isBotOutputText(part)) {\n    const text = part.text as BotOutputText;\n    const customRenderer = part.aggregatedBy\n      ? botOutputRenderers?.[part.aggregatedBy]\n      : undefined;\n    const metadata = part.aggregatedBy\n      ? aggregationMetadata?.[part.aggregatedBy]\n      : undefined;\n    return renderBotOutput(\n      text.spoken,\n      text.unspoken,\n      part.aggregatedBy,\n      customRenderer,\n      metadata,\n      textRenderMode,\n    );\n  }\n  return part.text as React.ReactNode;\n}\n\nexport interface MessageContentProps {\n  message: ConversationMessage;\n  botOutputRenderers?: Record<string, BotOutputRenderer>;\n  aggregationMetadata?: Record<string, AggregationMetadata>;\n  textRenderMode?: TextRenderMode;\n  className?: string;\n}\n\n/** Message body: grouped inline/block parts, thinking dots, timestamp. */\nexport function MessageContent({\n  message,\n  botOutputRenderers,\n  aggregationMetadata,\n  textRenderMode,\n  className,\n}: MessageContentProps) {\n  const parts = Array.isArray(message.parts) ? message.parts : [];\n\n  // Group parts by display mode: inline parts flow together, block parts\n  // each get their own line.\n  const groupedParts: Array<{\n    type: \"inline\" | \"block\";\n    parts: ConversationMessagePart[];\n  }> = [];\n  let currentInlineGroup: ConversationMessagePart[] = [];\n\n  for (const part of parts) {\n    const metadata = part.aggregatedBy\n      ? aggregationMetadata?.[part.aggregatedBy]\n      : undefined;\n    const displayMode = part.displayMode ?? metadata?.displayMode ?? \"inline\";\n\n    if (displayMode === \"block\") {\n      if (currentInlineGroup.length > 0) {\n        groupedParts.push({ type: \"inline\", parts: currentInlineGroup });\n        currentInlineGroup = [];\n      }\n      groupedParts.push({ type: \"block\", parts: [part] });\n    } else {\n      currentInlineGroup.push(part);\n    }\n  }\n  if (currentInlineGroup.length > 0) {\n    groupedParts.push({ type: \"inline\", parts: currentInlineGroup });\n  }\n\n  return (\n    <div\n      data-slot=\"message-content\"\n      className={cn(\"flex flex-col gap-2\", className)}\n    >\n      {groupedParts.map((group, groupIdx) =>\n        group.type === \"inline\" ? (\n          <div key={groupIdx} className=\"inline-block\">\n            {group.parts.map((part, partIdx) => {\n              const content = renderPartContent(\n                part,\n                botOutputRenderers,\n                aggregationMetadata,\n                textRenderMode,\n              );\n              const shouldAddSpace = partIdx > 0 && !isBotOutputText(part);\n              return (\n                <Fragment key={partIdx}>\n                  {shouldAddSpace && \" \"}\n                  {content}\n                </Fragment>\n              );\n            })}\n          </div>\n        ) : (\n          <Fragment key={groupIdx}>\n            {group.parts.map((part, partIdx) => (\n              <Fragment key={partIdx}>\n                {renderPartContent(\n                  part,\n                  botOutputRenderers,\n                  aggregationMetadata,\n                  textRenderMode,\n                )}\n              </Fragment>\n            ))}\n          </Fragment>\n        ),\n      )}\n      {isMessageEmpty(message) ? <Thinking /> : null}\n      <div className=\"text-muted-foreground mb-1 self-end text-xs\">\n        {timeFormatter.format(new Date(message.createdAt))}\n      </div>\n    </div>\n  );\n}\n\nexport interface ConversationMessageItemProps {\n  message: ConversationMessage;\n  assistantLabel?: string;\n  clientLabel?: string;\n  systemLabel?: string;\n  functionCallLabel?: string;\n  functionCallRenderer?: FunctionCallRenderer;\n  botOutputRenderers?: Record<string, BotOutputRenderer>;\n  aggregationMetadata?: Record<string, AggregationMetadata>;\n  textRenderMode?: TextRenderMode;\n  className?: string;\n}\n\n/** One conversation row: role label plus content (or a function call). */\nexport function ConversationMessageItem({\n  message,\n  assistantLabel,\n  clientLabel,\n  systemLabel,\n  functionCallLabel,\n  functionCallRenderer,\n  botOutputRenderers,\n  aggregationMetadata,\n  textRenderMode,\n  className,\n}: ConversationMessageItemProps) {\n  if (message.role === \"function_call\" && message.functionCall) {\n    return (\n      <div className={cn(\"flex flex-col gap-2\", className)}>\n        <FunctionCallContent\n          functionCall={message.functionCall}\n          functionCallLabel={functionCallLabel}\n          functionCallRenderer={functionCallRenderer}\n        />\n        <div className=\"text-muted-foreground mb-1 self-end text-xs\">\n          {timeFormatter.format(new Date(message.createdAt))}\n        </div>\n      </div>\n    );\n  }\n\n  return (\n    <div className={cn(\"flex flex-col gap-2\", className)}>\n      <MessageRole\n        role={message.role}\n        assistantLabel={assistantLabel}\n        clientLabel={clientLabel}\n        systemLabel={systemLabel}\n        functionCallLabel={functionCallLabel}\n      />\n      <MessageContent\n        message={message}\n        botOutputRenderers={botOutputRenderers}\n        aggregationMetadata={aggregationMetadata}\n        textRenderMode={textRenderMode}\n      />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/pipecat/conversation-message.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-agent": "var(--agent-background)",
      "color-agent-foreground": "var(--agent-foreground)",
      "color-client": "var(--client-background)",
      "color-client-foreground": "var(--client-foreground)",
      "color-active": "var(--active-background)",
      "color-active-foreground": "var(--active-foreground)"
    },
    "light": {
      "agent-background": "oklch(0.962 0.018 272.314)",
      "agent-foreground": "oklch(0.585 0.233 277.117)",
      "client-background": "oklch(0.97 0.014 254.604)",
      "client-foreground": "oklch(0.623 0.214 259.815)",
      "active-background": "oklch(0.696 0.17 162.48)",
      "active-foreground": "oklch(0.979 0.021 166.113)"
    },
    "dark": {
      "agent-background": "oklch(0.19 0.045 277.117)",
      "agent-foreground": "oklch(0.585 0.233 277.117)",
      "client-background": "oklch(0.19 0.045 259.815)",
      "client-foreground": "oklch(0.623 0.214 259.815)",
      "active-background": "oklch(0.702 0.158 160.44)",
      "active-foreground": "oklch(0.979 0.021 166.11)"
    }
  },
  "docs": "Render inside a PipecatClientProvider. Pair with @pipecat/text-input for a full chat surface.",
  "categories": [
    "voice"
  ],
  "type": "registry:component"
}