{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "conversation-shell",
  "title": "Conversation shell",
  "description": "App frame for an AI agent chat: a top bar with breadcrumb, search and Ask AI over a chat panel, a message list that sticks to the newest message while it streams, a jump-to-latest button once you scroll up, an empty state with suggestions, and a growing composer with Send / Stop.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/components/conversation-shell.tsx",
      "content": "\"use client\";\n\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport { ArrowDown, ArrowUp, Bell, Search, Sparkles, Square, Wrench } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ConversationMessage = {\n  id: string;\n  role: \"user\" | \"assistant\";\n  /** Plain text, or any element: a streaming message, a tool call, an approval card. */\n  content: React.ReactNode;\n};\n\nexport type ConversationShellProps = {\n  messages?: ConversationMessage[];\n  /** Called with the composer text when the user sends. */\n  onSend?: (text: string) => void;\n  /** True while the agent is answering: the send button becomes Stop. */\n  busy?: boolean;\n  onStop?: () => void;\n  /** Prompts shown on the empty state; clicking one sends it. */\n  suggestions?: string[];\n  /** Heading of the empty state. */\n  emptyTitle?: React.ReactNode;\n  placeholder?: string;\n  /** Title of the open chat, shown in the top bar. */\n  title?: string;\n  /** Product name next to the logo. */\n  brand?: string;\n  /** Called by the Ask AI button in the top bar. */\n  onAskAI?: () => void;\n  /** Play a scripted two-turn chat on a loop while on screen, for demos. */\n  autoPlay?: boolean;\n  /** Drop the top bar and the frame borders, for when the page draws its own chrome. */\n  bare?: boolean;\n  className?: string;\n};\n\nconst SUGGESTIONS = [\"Summarize this week's launch tasks\", \"Draft a Product Hunt tagline\", \"What changed in v2?\"];\n\nconst DEMO_REPLY_1 =\n  \"Three things are left before launch: record the demo clips, finish the starter repo, and schedule the Product Hunt post for Tuesday. The clips are the long pole, so start there.\";\nconst DEMO_ASK_2 = \"Draft a Product Hunt tagline\";\nconst DEMO_REPLY_2 =\n  \"Agent UI components for React & Tailwind: tool calls, approvals, sources and streaming, ready to copy into your app.\";\n\n// Demo loop, in ms.\nconst PICK = 1600;\nconst R1 = PICK + 500;\nconst WORD_MS = 75;\nconst R1_END = R1 + DEMO_REPLY_1.split(\" \").length * WORD_MS;\nconst TYPE2 = R1_END + 700;\nconst CHAR_MS = 32;\nconst SEND2 = TYPE2 + DEMO_ASK_2.length * CHAR_MS + 300;\nconst R2 = SEND2 + 500;\nconst R2_END = R2 + DEMO_REPLY_2.split(\" \").length * WORD_MS;\nconst LOOP = R2_END + 3600;\nconst TICK = 50;\n\nfunction words(text: string, n: number) {\n  return text.split(\" \").slice(0, Math.max(0, n)).join(\" \");\n}\n\nfunction demoState(t: number): { messages: ConversationMessage[]; draft: string; busy: boolean; picking: boolean } {\n  const messages: ConversationMessage[] = [];\n  if (t >= PICK) messages.push({ id: \"u1\", role: \"user\", content: SUGGESTIONS[0] });\n  if (t >= R1) messages.push({ id: \"a1\", role: \"assistant\", content: words(DEMO_REPLY_1, Math.floor((t - R1) / WORD_MS) + 1) });\n  if (t >= SEND2) messages.push({ id: \"u2\", role: \"user\", content: DEMO_ASK_2 });\n  if (t >= R2) messages.push({ id: \"a2\", role: \"assistant\", content: words(DEMO_REPLY_2, Math.floor((t - R2) / WORD_MS) + 1) });\n  const draft = t >= TYPE2 && t < SEND2 ? DEMO_ASK_2.slice(0, Math.floor((t - TYPE2) / CHAR_MS)) : \"\";\n  const busy = (t >= PICK && t < R1_END) || (t >= SEND2 && t < R2_END);\n  return { messages, draft, busy, picking: t >= PICK - 450 && t < PICK };\n}\n\nfunction Logo() {\n  return (\n    <span className=\"grid size-6 place-items-center rounded-md bg-foreground text-background\" aria-hidden>\n      <Sparkles className=\"size-3.5\" />\n    </span>\n  );\n}\n\n/**\n * An app frame for an agent chat: a top bar with breadcrumb and search over a chat panel,\n * with a message list that sticks to the newest message, with a jump-to-latest button,\n * an empty state and a composer.\n */\nexport function ConversationShell({\n  messages: messagesProp,\n  onSend,\n  busy: busyProp = false,\n  onStop,\n  suggestions = SUGGESTIONS,\n  emptyTitle = \"What should the agent do?\",\n  placeholder = \"Ask the agent…\",\n  title = \"Launch planning\",\n  brand = \"Agent\",\n  onAskAI,\n  autoPlay = false,\n  bare = false,\n  className,\n}: ConversationShellProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const scrollRef = useRef<HTMLDivElement>(null);\n  const contentRef = useRef<HTMLDivElement>(null);\n  const inputRef = useRef<HTMLTextAreaElement>(null);\n  const reduce = useReducedMotion();\n  const [visible, setVisible] = useState(false);\n  const [tick, setTick] = useState(0);\n  const [draft, setDraft] = useState(\"\");\n  const [atBottom, setAtBottom] = useState(true);\n  const stick = useRef(true);\n\n  useEffect(() => {\n    const el = ref.current;\n    if (!el || !autoPlay) return;\n    const io = new IntersectionObserver(([entry]) => setVisible(entry.isIntersecting));\n    io.observe(el);\n    return () => io.disconnect();\n  }, [autoPlay]);\n\n  useEffect(() => {\n    if (!autoPlay || !visible || reduce) return;\n    const id = setInterval(() => setTick((t) => (t + TICK) % LOOP), TICK);\n    return () => clearInterval(id);\n  }, [autoPlay, visible, reduce]);\n\n  const demo = autoPlay ? demoState(reduce ? LOOP - 1 : tick) : null;\n  const messages = demo?.messages ?? messagesProp ?? [];\n  const busy = demo?.busy ?? busyProp;\n  const shownDraft = demo && demo.draft ? demo.draft : draft;\n\n  const scrollToBottom = useCallback(\n    (smooth: boolean) => {\n      const el = scrollRef.current;\n      if (!el) return;\n      el.scrollTo({ top: el.scrollHeight, behavior: smooth && !reduce ? \"smooth\" : \"auto\" });\n    },\n    [reduce],\n  );\n\n  // Follow new content while the reader is at the bottom; leave them alone once they scroll up.\n  useLayoutEffect(() => {\n    const inner = contentRef.current;\n    if (!inner) return;\n    const ro = new ResizeObserver(() => {\n      if (stick.current) scrollToBottom(false);\n    });\n    ro.observe(inner);\n    return () => ro.disconnect();\n  }, [scrollToBottom]);\n\n  function onScroll() {\n    const el = scrollRef.current;\n    if (!el) return;\n    const near = el.scrollHeight - el.scrollTop - el.clientHeight < 48;\n    stick.current = near;\n    setAtBottom(near);\n  }\n\n  function send(text: string) {\n    const value = text.trim();\n    if (!value || busy) return;\n    onSend?.(value);\n    setDraft(\"\");\n    stick.current = true;\n    setAtBottom(true);\n  }\n\n  // Grow the composer with its text, up to a cap.\n  useLayoutEffect(() => {\n    const el = inputRef.current;\n    if (!el) return;\n    el.style.height = \"auto\";\n    el.style.height = `${Math.min(el.scrollHeight, 120)}px`;\n  }, [shownDraft]);\n\n  const empty = messages.length === 0;\n\n  return (\n    <div\n      ref={ref}\n      className={cn(\n        \"@container flex h-[600px] w-full flex-col overflow-hidden rounded-2xl border bg-muted/50 text-foreground shadow-xs\",\n        bare && \"rounded-none border-0 bg-background shadow-none\",\n        className,\n      )}\n    >\n      {!bare && (\n        <header className=\"flex h-14 shrink-0 items-center gap-2.5 px-3 @[560px]:px-4\">\n          <Logo />\n          <span className=\"hidden text-sm font-semibold tracking-tight @[480px]:inline\">{brand}</span>\n          <span className=\"hidden h-4 w-px bg-border @[480px]:block\" aria-hidden />\n          <nav aria-label=\"Breadcrumb\" className=\"flex min-w-0 items-center gap-1.5 text-sm\">\n            <span className=\"hidden text-muted-foreground @[640px]:inline\">Chats</span>\n            <span className=\"hidden text-muted-foreground/50 @[640px]:inline\" aria-hidden>\n              /\n            </span>\n            <span className=\"truncate font-medium\" aria-current=\"page\">\n              {title}\n            </span>\n          </nav>\n\n          <div className=\"ml-auto flex items-center gap-2\">\n            <label className=\"hidden h-8 w-56 items-center gap-2 rounded-full border bg-background px-3 text-xs text-muted-foreground shadow-xs focus-within:ring-2 focus-within:ring-ring @[820px]:flex\">\n              <Search className=\"size-3.5 shrink-0\" aria-hidden />\n              <input placeholder=\"Search for something…\" aria-label=\"Search chats\" className=\"min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground\" />\n            </label>\n            <button\n              type=\"button\"\n              onClick={onAskAI}\n              className=\"hidden h-8 items-center gap-1.5 rounded-full bg-foreground px-3 text-xs font-medium text-background outline-none transition-opacity hover:opacity-90 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 @[560px]:flex\"\n            >\n              <Sparkles className=\"size-3.5\" aria-hidden />\n              Ask AI\n            </button>\n            <button\n              type=\"button\"\n              aria-label=\"Notifications\"\n              className=\"relative grid size-8 place-items-center rounded-full border bg-background text-muted-foreground shadow-xs outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n            >\n              <Bell className=\"size-3.5\" aria-hidden />\n              <span className=\"absolute top-1.5 right-2 size-1.5 rounded-full bg-red-500\" aria-hidden />\n            </button>\n          </div>\n        </header>\n      )}\n\n      <section\n        className={cn(\n          \"flex min-h-0 flex-1 flex-col overflow-hidden bg-background\",\n          !bare && \"mx-2 mb-2 rounded-xl border shadow-xs @[560px]:mx-3 @[560px]:mb-3\",\n        )}\n      >\n        <div className=\"relative min-h-0 flex-1\">\n          <div ref={scrollRef} onScroll={onScroll} className=\"h-full overflow-y-auto [scrollbar-width:thin]\">\n            <div ref={contentRef} className=\"mx-auto flex min-h-full w-full max-w-2xl flex-col px-4 py-5 @[720px]:px-6\">\n              {empty ? (\n                <div className=\"m-auto flex flex-col items-center gap-4 text-center\">\n                  <span className=\"grid size-11 place-items-center rounded-xl border bg-card shadow-xs\" aria-hidden>\n                    <Sparkles className=\"size-5\" />\n                  </span>\n                  <div>\n                    <p className=\"text-base font-semibold tracking-tight\">{emptyTitle}</p>\n                    <p className=\"mt-1 text-xs text-muted-foreground\">Pick a prompt or write your own.</p>\n                  </div>\n                  <div className=\"flex max-w-md flex-wrap justify-center gap-2\">\n                    {suggestions.map((s, i) => (\n                      <motion.button\n                        key={s}\n                        type=\"button\"\n                        onClick={() => send(s)}\n                        animate={demo?.picking && i === 0 ? { scale: [1, 0.95, 1] } : { scale: 1 }}\n                        transition={{ duration: 0.45 }}\n                        className={cn(\n                          \"rounded-full border bg-card px-3 py-1.5 text-xs text-muted-foreground shadow-xs outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\",\n                          demo?.picking && i === 0 && \"bg-muted text-foreground\",\n                        )}\n                      >\n                        {s}\n                      </motion.button>\n                    ))}\n                  </div>\n                </div>\n              ) : (\n                <ol className=\"flex flex-col gap-5\" aria-live=\"polite\" aria-busy={busy}>\n                  <AnimatePresence initial={false}>\n                    {messages.map((m) => (\n                      <motion.li\n                        key={m.id}\n                        initial={reduce ? false : { opacity: 0, y: 8 }}\n                        animate={{ opacity: 1, y: 0 }}\n                        transition={{ duration: 0.3, ease: [0.22, 1, 0.36, 1] }}\n                        className={cn(\"flex gap-3\", m.role === \"user\" && \"justify-end\")}\n                      >\n                        {m.role === \"assistant\" && (\n                          <span className=\"mt-0.5 grid size-7 shrink-0 place-items-center rounded-lg bg-foreground text-background\" aria-hidden>\n                            <Sparkles className=\"size-3.5\" />\n                          </span>\n                        )}\n                        <div\n                          className={cn(\n                            \"min-w-0 text-sm leading-relaxed\",\n                            m.role === \"user\" ? \"max-w-[80%] rounded-2xl rounded-br-md bg-muted px-3.5 py-2\" : \"flex-1 pt-1\",\n                          )}\n                        >\n                          <span className=\"sr-only\">{m.role === \"user\" ? \"You: \" : \"Agent: \"}</span>\n                          {m.content}\n                        </div>\n                      </motion.li>\n                    ))}\n                  </AnimatePresence>\n                </ol>\n              )}\n            </div>\n          </div>\n\n          <AnimatePresence>\n            {!atBottom && !empty && (\n              <motion.button\n                type=\"button\"\n                onClick={() => {\n                  stick.current = true;\n                  setAtBottom(true);\n                  scrollToBottom(true);\n                }}\n                initial={reduce ? false : { opacity: 0, y: 6 }}\n                animate={{ opacity: 1, y: 0 }}\n                exit={reduce ? undefined : { opacity: 0, y: 6 }}\n                transition={{ duration: 0.2 }}\n                aria-label=\"Jump to latest message\"\n                className=\"absolute bottom-3 left-1/2 grid size-8 -translate-x-1/2 place-items-center rounded-full border bg-background shadow-md outline-none hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring\"\n              >\n                <ArrowDown className=\"size-4\" aria-hidden />\n              </motion.button>\n            )}\n          </AnimatePresence>\n        </div>\n\n        <form\n          onSubmit={(e) => {\n            e.preventDefault();\n            send(draft);\n          }}\n          className=\"mx-auto w-full max-w-2xl px-4 pb-4 @[720px]:px-6\"\n        >\n          <div className=\"rounded-2xl border bg-card p-2 shadow-sm focus-within:ring-2 focus-within:ring-ring\">\n            <textarea\n              ref={inputRef}\n              rows={1}\n              value={shownDraft}\n              onChange={(e) => setDraft(e.target.value)}\n              onKeyDown={(e) => {\n                if (e.key === \"Enter\" && !e.shiftKey && !e.nativeEvent.isComposing) {\n                  e.preventDefault();\n                  send(draft);\n                }\n              }}\n              placeholder={placeholder}\n              aria-label=\"Message\"\n              className=\"block min-h-9 w-full resize-none bg-transparent px-2 py-1.5 text-sm leading-relaxed outline-none placeholder:text-muted-foreground\"\n            />\n            <div className=\"flex items-center gap-1.5 px-1\">\n              <span className=\"flex h-7 items-center gap-1.5 rounded-md border px-2 text-[11px] text-muted-foreground\">\n                <Wrench className=\"size-3\" aria-hidden />3 tools\n              </span>\n              <span className=\"ml-auto hidden text-[11px] text-muted-foreground @[560px]:inline\">Enter to send · Shift+Enter for a new line</span>\n              {busy ? (\n                <button\n                  type=\"button\"\n                  onClick={onStop}\n                  aria-label=\"Stop\"\n                  className=\"ml-auto grid size-8 shrink-0 place-items-center rounded-lg bg-foreground text-background outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 @[560px]:ml-2\"\n                >\n                  <Square className=\"size-3 fill-current\" aria-hidden />\n                </button>\n              ) : (\n                <button\n                  type=\"submit\"\n                  disabled={!shownDraft.trim()}\n                  aria-label=\"Send\"\n                  className=\"ml-auto grid size-8 shrink-0 place-items-center rounded-lg bg-foreground text-background outline-none transition-opacity focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-30 @[560px]:ml-2\"\n                >\n                  <ArrowUp className=\"size-4\" aria-hidden />\n                </button>\n              )}\n            </div>\n          </div>\n        </form>\n      </section>\n    </div>\n  );\n}\n\nexport default function ConversationShellDemo() {\n  return <ConversationShell autoPlay />;\n}\n",
      "type": "registry:component",
      "target": "components/nextui/conversation-shell.tsx"
    }
  ],
  "meta": {
    "kind": "component",
    "category": "ai",
    "previewHeight": 520,
    "new": true,
    "free": true,
    "openSource": true,
    "added": "2026-10-31"
  },
  "categories": [
    "ai"
  ],
  "type": "registry:component"
}