{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chat-assistant",
  "title": "Chat Assistant",
  "description": "An AI chat that shows the model working, as a full screen, a panel docked beside the work, or a launcher that opens a small window.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/motion.json",
    "https://miseui.junsu4621.workers.dev/r/agent-avatar.json",
    "https://miseui.junsu4621.workers.dev/r/beam-border.json",
    "https://miseui.junsu4621.workers.dev/r/button.json",
    "https://miseui.junsu4621.workers.dev/r/reasoning-steps.json",
    "https://miseui.junsu4621.workers.dev/r/shimmer-text.json",
    "https://miseui.junsu4621.workers.dev/r/streaming-text.json",
    "https://miseui.junsu4621.workers.dev/r/textarea.json",
    "https://miseui.junsu4621.workers.dev/r/thinking-orb.json",
    "https://miseui.junsu4621.workers.dev/r/tool-call-card.json"
  ],
  "files": [
    {
      "path": "registry/miseui/blocks/chat-assistant.tsx",
      "content": "import type * as React from \"react\"\nimport { ChatDocked } from \"@/registry/miseui/blocks/chat-assistant-docked\"\nimport type { ChatPanelOptions } from \"@/registry/miseui/blocks/chat-assistant-panel-state\"\nimport type { ChatMessage, ChatStatus, ChatToolCall } from \"@/registry/miseui/blocks/chat-assistant-parts\"\nimport { ChatPopup } from \"@/registry/miseui/blocks/chat-assistant-popup\"\nimport { useSampleChat } from \"@/registry/miseui/blocks/chat-assistant-sample\"\nimport { ChatScreen, type ChatConversation, type ChatOptions } from \"@/registry/miseui/blocks/chat-assistant-screen\"\n\ntype ChatAssistantVariant = \"full\" | \"docked\" | \"popup\"\n\ninterface ChatAssistantProps extends React.ComponentProps<\"section\">, ChatOptions, ChatPanelOptions {\n  /** `full` is the whole screen, `docked` a panel beside the work, `popup` a launcher that opens a small window. Anything else is `full`. */\n  variant?: ChatAssistantVariant\n  /** The conversation. Leave it out and the block runs a scripted sample, so it can be previewed as is. */\n  messages?: readonly ChatMessage[]\n  /** \"generating\" swaps Send for Stop and lights the composer. Ignored while the sample runs. */\n  status?: ChatStatus\n  /** `docked` and `popup`: the page the chat sits beside or floats over. Leave it out to see a sample report. */\n  children?: React.ReactNode\n}\n\ntype ChatLayoutProps = Omit<ChatAssistantProps, \"messages\" | \"status\"> & ChatConversation\n\n/** `full` has no work to sit beside, so children and the open state only reach the two that do. */\nfunction ChatLayout({ variant, children, open, defaultOpen, onOpenChange, ...props }: ChatLayoutProps) {\n  const panel = { open, defaultOpen, onOpenChange }\n  if (variant === \"docked\") return <ChatDocked {...props} {...panel}>{children}</ChatDocked>\n  if (variant === \"popup\") return <ChatPopup {...props} {...panel}>{children}</ChatPopup>\n  return <ChatScreen data-variant=\"full\" {...props} />\n}\n\nfunction SampleChat({ onSend, onStop, onNewChat, ...props }: Omit<ChatAssistantProps, \"messages\" | \"status\">) {\n  const sample = useSampleChat()\n  return (\n    <ChatLayout\n      {...props}\n      messages={sample.messages}\n      status={sample.status}\n      onSend={(text) => {\n        onSend?.(text)\n        sample.send(text)\n      }}\n      onStop={() => {\n        onStop?.()\n        sample.stop()\n      }}\n      onNewChat={() => {\n        onNewChat?.()\n        sample.reset()\n      }}\n    />\n  )\n}\n\nfunction ChatAssistant({ messages, status = \"idle\", ...props }: ChatAssistantProps) {\n  if (messages) return <ChatLayout messages={messages} status={status} {...props} />\n  return <SampleChat {...props} />\n}\n\nexport { ChatAssistant, type ChatAssistantProps, type ChatAssistantVariant, type ChatMessage, type ChatStatus, type ChatToolCall }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/chat-assistant-screen.tsx",
      "content": "import type * as React from \"react\"\nimport { useEffect, useRef } from \"react\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport { ChatComposer } from \"@/registry/miseui/blocks/chat-assistant-composer\"\nimport { ChatError, ChatHeader, ChatStarter, COLUMN_CLASS, type ChatMessage, type ChatStatus } from \"@/registry/miseui/blocks/chat-assistant-parts\"\nimport { ChatThread } from \"@/registry/miseui/blocks/chat-assistant-thread\"\n\n/** Within this distance of the end still counts as reading the end, so a small scroll does not stop the follow. */\nconst STICK_THRESHOLD_PX = 32\nconst DEFAULT_AGENT_NAME = \"Tally\"\n\nconst DEFAULT_SUGGESTIONS: readonly string[] = [\n  \"Why did churn rise last month?\",\n  \"Which accounts are at risk this quarter?\",\n  \"Summarize last week's renewals\",\n]\n\ninterface ChatOptions {\n  onSend?: (text: string) => void\n  onStop?: () => void\n  /** Shown when the conversation is empty, and sent as they are when picked. */\n  suggestions?: readonly string[]\n  agentName?: string\n  /** One line under the name while nothing is running. */\n  agentDescription?: string\n  placeholder?: string\n  /** Shows the New chat button. */\n  onNewChat?: () => void\n  /** The last turn failed. Shown above the composer. */\n  error?: string\n  onRetry?: () => void\n  /** Blocks new messages, for example when the plan's quota is used up. Stop keeps working. */\n  disabled?: boolean\n}\n\ninterface ChatConversation extends ChatOptions {\n  messages: readonly ChatMessage[]\n  status: ChatStatus\n}\n\ninterface ChatScreenProps extends React.ComponentProps<\"section\">, ChatConversation {\n  /** Extra controls in the header, such as a way to close a panel. */\n  headerActions?: React.ReactNode\n  /** A narrow panel, with a smaller headline on the empty screen. */\n  compact?: boolean\n}\n\n/** Follows new text while the reader is at the end, and lets go as soon as they scroll up to read. */\nfunction useStickToBottom(messageCount: number) {\n  const scrollRef = useRef<HTMLDivElement>(null)\n  const contentRef = useRef<HTMLDivElement>(null)\n  const pinnedRef = useRef(true)\n\n  useEffect(() => {\n    const scroller = scrollRef.current\n    const content = contentRef.current\n    if (!scroller || !content || typeof ResizeObserver === \"undefined\") return\n    const observer = new ResizeObserver(() => {\n      if (pinnedRef.current) scroller.scrollTop = scroller.scrollHeight\n    })\n    observer.observe(content)\n    return () => observer.disconnect()\n  }, [])\n\n  // A new message means the reader just sent something, so they want the end again.\n  useEffect(() => {\n    pinnedRef.current = true\n    const scroller = scrollRef.current\n    if (scroller) scroller.scrollTop = scroller.scrollHeight\n  }, [messageCount])\n\n  const onScroll = () => {\n    const scroller = scrollRef.current\n    if (!scroller) return\n    pinnedRef.current = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < STICK_THRESHOLD_PX\n  }\n\n  return { scrollRef, contentRef, onScroll }\n}\n\nfunction ChatScreen({\n  messages,\n  status,\n  onSend,\n  onStop,\n  suggestions = DEFAULT_SUGGESTIONS,\n  agentName = DEFAULT_AGENT_NAME,\n  agentDescription = \"Reads your reports\",\n  placeholder = \"Ask about a report\",\n  onNewChat,\n  error,\n  onRetry,\n  disabled = false,\n  headerActions,\n  compact = false,\n  className,\n  ...props\n}: ChatScreenProps) {\n  const { scrollRef, contentRef, onScroll } = useStickToBottom(messages.length)\n  const generating = status === \"generating\"\n  const send = (text: string) => onSend?.(text)\n\n  return (\n    <section data-slot=\"chat-assistant\" data-status={status} aria-label={`Chat with ${agentName}`} className={cn(\"@container flex h-[640px] max-h-dvh w-full flex-col bg-muted/40 dark:bg-background\", className)} {...props}>\n      <ChatHeader agentName={agentName} description={agentDescription} generating={generating} onNewChat={onNewChat} actions={headerActions} />\n      <div ref={scrollRef} onScroll={onScroll} className=\"min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 @md:px-6\">\n        <div ref={contentRef} className={cn(COLUMN_CLASS, \"flex min-h-full flex-col py-6\")}>\n          {messages.length === 0 && !generating ? (\n            <ChatStarter agentName={agentName} suggestions={suggestions} disabled={disabled} onPick={send} compact={compact} />\n          ) : (\n            <ChatThread messages={messages} status={status} />\n          )}\n        </div>\n      </div>\n      <div className=\"px-4 pb-4 @md:px-6 @md:pb-6\">\n        <div className={cn(COLUMN_CLASS, \"flex flex-col gap-2\")}>\n          {error ? <ChatError message={error} onRetry={onRetry} /> : null}\n          <ChatComposer label={`Message ${agentName}`} placeholder={placeholder} generating={generating} disabled={disabled} onSend={send} onStop={onStop} />\n        </div>\n      </div>\n    </section>\n  )\n}\n\n/** The chat's own props go to the panel, and everything else stays with the outer block, which is the thing placed on the page. */\nfunction splitChatProps<Rest extends object>(props: ChatConversation & Rest) {\n  const { messages, status, onSend, onStop, suggestions, agentName, agentDescription, placeholder, onNewChat, error, onRetry, disabled, ...rest } = props\n  const chat: ChatConversation = { messages, status, onSend, onStop, suggestions, agentName, agentDescription, placeholder, onNewChat, error, onRetry, disabled }\n  return { chat, rest }\n}\n\nexport { ChatScreen, DEFAULT_AGENT_NAME, splitChatProps, type ChatConversation, type ChatOptions, type ChatScreenProps }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/chat-assistant-docked.tsx",
      "content": "import type * as React from \"react\"\nimport { useRef } from \"react\"\nimport { MessageCircle, X } from \"lucide-react\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport { Button } from \"@/registry/miseui/ui/button\"\nimport { useChatOpen, useChatPanelFocus, type ChatPanelOptions } from \"@/registry/miseui/blocks/chat-assistant-panel-state\"\nimport { ChatScreen, DEFAULT_AGENT_NAME, splitChatProps, type ChatConversation } from \"@/registry/miseui/blocks/chat-assistant-screen\"\nimport { ChatSampleWork } from \"@/registry/miseui/blocks/chat-assistant-work\"\n\ntype ChatDockedProps = React.ComponentProps<\"section\"> & ChatConversation & ChatPanelOptions\n\n/** The way back to the panel: a narrow strip beside the work when wide, a short bar under it when narrow. Never over the work. */\nfunction DockedOpener({ openerRef, agentName, onOpen }: { openerRef: React.RefObject<HTMLButtonElement | null>; agentName: string; onOpen: () => void }) {\n  return (\n    <div className=\"flex shrink-0 justify-end border-t bg-background p-2 dark:bg-card @3xl:flex-col @3xl:justify-start @3xl:border-t-0 @3xl:border-l\">\n      <Button ref={openerRef} variant=\"outline\" aria-expanded={false} className=\"pointer-coarse:h-10 @3xl:size-10 @3xl:p-0\" onClick={onOpen}>\n        <MessageCircle aria-hidden=\"true\" />\n        <span className=\"@3xl:sr-only\">Ask {agentName}</span>\n      </Button>\n    </div>\n  )\n}\n\nfunction ChatDocked({ open, defaultOpen = true, onOpenChange, ...props }: ChatDockedProps) {\n  const { chat, rest } = splitChatProps(props)\n  const { children, className, ...root } = rest\n  const [isOpen, setOpen] = useChatOpen({ open, defaultOpen, onOpenChange })\n  const panelRef = useRef<HTMLDivElement>(null)\n  const openerRef = useRef<HTMLButtonElement>(null)\n  useChatPanelFocus(isOpen, panelRef, openerRef)\n  const agentName = chat.agentName ?? DEFAULT_AGENT_NAME\n\n  return (\n    <section\n      data-slot=\"chat-assistant\"\n      data-variant=\"docked\"\n      data-status={chat.status}\n      data-open={isOpen ? \"true\" : \"false\"}\n      className={cn(\"@container flex h-[640px] max-h-dvh w-full flex-col bg-muted dark:bg-background\", className)}\n      {...root}\n    >\n      {/* Its own element: a container query only sees ancestors, so the root cannot change its own direction. */}\n      <div className=\"flex min-h-0 flex-1 flex-col @3xl:flex-row\">\n        {/* A tab stop, because it scrolls and may hold nothing else a keyboard could reach. */}\n        <div\n          data-slot=\"chat-assistant-work\"\n          role=\"region\"\n          aria-label=\"Your work\"\n          tabIndex={0}\n          className=\"min-h-0 min-w-0 flex-[2_1_0%] overflow-auto overscroll-contain outline-none focus-visible:ring-[3px] focus-visible:ring-inset focus-visible:ring-ring/50 @3xl:flex-1\"\n        >\n          {children ?? <ChatSampleWork />}\n        </div>\n        {/* Kept mounted while closed: a half-written message and the thread are still there when it comes back. */}\n        <div\n          ref={panelRef}\n          hidden={!isOpen}\n          className={cn(\"min-h-0 min-w-0 flex-[3_1_0%] flex-col border-t @3xl:w-[400px] @3xl:flex-none @3xl:border-t-0 @3xl:border-l\", isOpen ? \"flex\" : \"hidden\")}\n        >\n          <ChatScreen\n            {...chat}\n            data-slot=\"chat-assistant-panel\"\n            compact\n            className=\"h-auto max-h-none min-h-0 flex-1 bg-background pointer-coarse:[&_button]:min-h-10 pointer-coarse:[&_button]:min-w-10 dark:bg-card\"\n            headerActions={\n              <Button variant=\"ghost\" size=\"icon\" aria-label={`Close ${agentName}`} className=\"pointer-coarse:size-10\" onClick={() => setOpen(false)}>\n                <X aria-hidden=\"true\" />\n              </Button>\n            }\n          />\n        </div>\n        {isOpen ? null : <DockedOpener openerRef={openerRef} agentName={agentName} onOpen={() => setOpen(true)} />}\n      </div>\n    </section>\n  )\n}\n\nexport { ChatDocked, type ChatDockedProps }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/chat-assistant-popup.tsx",
      "content": "import type * as React from \"react\"\nimport { useId, useRef, useState } from \"react\"\nimport { MessageCircle, X } from \"lucide-react\"\nimport { motion, useReducedMotion } from \"motion/react\"\nimport { SPRING_DEFAULT } from \"@/registry/miseui/lib/motion\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport { Button } from \"@/registry/miseui/ui/button\"\nimport type { ChatStatus } from \"@/registry/miseui/blocks/chat-assistant-parts\"\nimport { useChatOpen, useChatPanelFocus, type ChatPanelOptions } from \"@/registry/miseui/blocks/chat-assistant-panel-state\"\nimport { ChatScreen, DEFAULT_AGENT_NAME, splitChatProps, type ChatConversation } from \"@/registry/miseui/blocks/chat-assistant-screen\"\nimport { ChatSampleWork } from \"@/registry/miseui/blocks/chat-assistant-work\"\n\nconst WINDOW_SHOWN = { opacity: 1, scale: 1, y: 0 }\nconst WINDOW_GONE = { opacity: 0, scale: 0.96, y: 8 }\nconst WINDOW_GONE_REDUCED = { opacity: 0, scale: 1, y: 0 }\n\ntype ChatPopupProps = React.ComponentProps<\"section\"> & ChatConversation & ChatPanelOptions\n\n/** A reply that finishes while the window is closed would otherwise go unnoticed. */\nfunction useMissedReply(open: boolean, status: ChatStatus) {\n  const [previous, setPrevious] = useState(status)\n  const [missed, setMissed] = useState(false)\n  if (previous !== status) {\n    setPrevious(status)\n    if (!open && previous === \"generating\" && status === \"idle\") setMissed(true)\n  }\n  if (open && missed) setMissed(false)\n  return missed\n}\n\nfunction launcherLabel(open: boolean, missed: boolean, generating: boolean, agentName: string) {\n  if (open) return \"Hide chat\"\n  if (missed) return `New reply from ${agentName}`\n  return generating ? `${agentName} is working` : `Ask ${agentName}`\n}\n\n/** Stays mounted through the exit, then leaves the layout. Under reduced motion there is no exit to wait for. */\nfunction useWindowExit(open: boolean) {\n  const reduceMotion = useReducedMotion()\n  const [exited, setExited] = useState(!open)\n  if (open && exited) setExited(false)\n  return {\n    reduceMotion,\n    gone: !open && (exited || Boolean(reduceMotion)),\n    onAnimationComplete: () => {\n      if (!open) setExited(true)\n    },\n  }\n}\n\ninterface PopupWindowProps {\n  id: string\n  panelRef: React.RefObject<HTMLDivElement | null>\n  open: boolean\n  agentName: string\n  chat: ChatConversation\n  onClose: () => void\n}\n\nfunction PopupWindow({ id, panelRef, open, agentName, chat, onClose }: PopupWindowProps) {\n  const exit = useWindowExit(open)\n  return (\n    <motion.div\n      ref={panelRef}\n      id={id}\n      role=\"dialog\"\n      aria-label={`Chat with ${agentName}`}\n      aria-hidden={!open}\n      inert={!open}\n      initial={false}\n      animate={open ? WINDOW_SHOWN : exit.reduceMotion ? WINDOW_GONE_REDUCED : WINDOW_GONE}\n      transition={exit.reduceMotion ? { duration: 0 } : SPRING_DEFAULT}\n      onAnimationComplete={exit.onAnimationComplete}\n      style={{ transformOrigin: \"100% 100%\" }}\n      className={cn(\n        \"absolute inset-2 z-10 flex-col overflow-hidden rounded-2xl border bg-background shadow-[0_24px_48px_-16px_oklch(0_0_0/24%)] dark:bg-card\",\n        \"@md:inset-auto @md:right-4 @md:bottom-20 @md:h-[min(520px,calc(100%-96px))] @md:w-[384px]\",\n        exit.gone ? \"hidden\" : \"flex\",\n      )}\n    >\n      <ChatScreen\n        {...chat}\n        data-slot=\"chat-assistant-panel\"\n        aria-label={undefined}\n        compact\n        className=\"h-auto max-h-none min-h-0 flex-1 bg-transparent pointer-coarse:[&_button]:min-h-10 pointer-coarse:[&_button]:min-w-10 dark:bg-transparent\"\n        headerActions={\n          <Button variant=\"ghost\" size=\"icon\" aria-label=\"Close chat\" className=\"pointer-coarse:size-10\" onClick={onClose}>\n            <X aria-hidden=\"true\" />\n          </Button>\n        }\n      />\n    </motion.div>\n  )\n}\n\nfunction ChatPopup({ open, defaultOpen = false, onOpenChange, ...props }: ChatPopupProps) {\n  const { chat, rest } = splitChatProps(props)\n  const { children, className, onKeyDown, ...root } = rest\n  const [isOpen, setOpen] = useChatOpen({ open, defaultOpen, onOpenChange })\n  const windowId = useId()\n  const panelRef = useRef<HTMLDivElement>(null)\n  const launcherRef = useRef<HTMLButtonElement>(null)\n  useChatPanelFocus(isOpen, panelRef, launcherRef)\n  const missed = useMissedReply(isOpen, chat.status)\n  const agentName = chat.agentName ?? DEFAULT_AGENT_NAME\n\n  const keyDown = (event: React.KeyboardEvent<HTMLElement>) => {\n    onKeyDown?.(event)\n    // isComposing: Escape cancels a half-typed Korean or Japanese syllable, and must not close the window with it.\n    if (event.key !== \"Escape\" || !isOpen || event.nativeEvent.isComposing) return\n    setOpen(false)\n  }\n\n  return (\n    // The block is the frame: everything is placed against it, so a preview or a page section contains the window.\n    <section\n      data-slot=\"chat-assistant\"\n      data-variant=\"popup\"\n      data-status={chat.status}\n      data-open={isOpen ? \"true\" : \"false\"}\n      className={cn(\"@container relative h-[640px] max-h-dvh w-full overflow-hidden bg-muted dark:bg-background\", className)}\n      onKeyDown={keyDown}\n      {...root}\n    >\n      {/* The bottom padding keeps the last row of the page clear of the launcher. */}\n      <div data-slot=\"chat-assistant-work\" role=\"region\" aria-label=\"Your work\" tabIndex={0} className=\"size-full overflow-auto overscroll-contain pb-20 outline-none focus-visible:ring-[3px] focus-visible:ring-inset focus-visible:ring-ring/50\">\n        {children ?? <ChatSampleWork />}\n      </div>\n      <PopupWindow id={windowId} panelRef={panelRef} open={isOpen} agentName={agentName} chat={chat} onClose={() => setOpen(false)} />\n      {/* Quiet while open, when Send is the accent. Hidden when the window fills a narrow block: the header has a close button there. */}\n      <Button\n        ref={launcherRef}\n        variant={isOpen ? \"outline\" : \"mise\"}\n        size=\"lg\"\n        aria-expanded={isOpen}\n        aria-controls={windowId}\n        onClick={() => setOpen(!isOpen)}\n        className={cn(\"absolute right-4 bottom-4 z-10 max-w-[calc(100%-32px)] shadow-md\", isOpen && \"@max-md:hidden\")}\n      >\n        {isOpen ? <X aria-hidden=\"true\" /> : <MessageCircle aria-hidden=\"true\" />}\n        <span className=\"truncate\">{launcherLabel(isOpen, missed, chat.status === \"generating\", agentName)}</span>\n      </Button>\n    </section>\n  )\n}\n\nexport { ChatPopup, type ChatPopupProps }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/chat-assistant-panel-state.ts",
      "content": "import type * as React from \"react\"\nimport { useEffect, useRef, useState } from \"react\"\n\ninterface ChatPanelOptions {\n  /** Whether the chat is showing. Leave it out and the block keeps this itself. */\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n}\n\nfunction useChatOpen({ open, defaultOpen = false, onOpenChange }: ChatPanelOptions) {\n  const [internal, setInternal] = useState(defaultOpen)\n  const current = open ?? internal\n  const setOpen = (next: boolean) => {\n    setInternal(next)\n    onOpenChange?.(next)\n  }\n  return [current, setOpen] as const\n}\n\n/**\n * Opening puts the cursor in the composer, and closing hands focus back to the button that opens it again.\n * Only on a change: a panel that is open from the start must not steal focus from the page.\n */\nfunction useChatPanelFocus(open: boolean, panel: React.RefObject<HTMLElement | null>, opener: React.RefObject<HTMLElement | null>) {\n  const previousRef = useRef(open)\n  useEffect(() => {\n    if (previousRef.current === open) return\n    previousRef.current = open\n    if (open) panel.current?.querySelector(\"textarea\")?.focus()\n    else opener.current?.focus()\n  }, [open, panel, opener])\n}\n\nexport { useChatOpen, useChatPanelFocus, type ChatPanelOptions }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/chat-assistant-work.tsx",
      "content": "/** Invented report, shown only when no children are passed. It carries the figures the sample conversation is about. */\n\nconst BREAKDOWN = [\n  { id: \"starter-annual\", label: \"Starter, annual\", count: 29 },\n  { id: \"starter-monthly\", label: \"Starter, monthly\", count: 7 },\n  { id: \"team\", label: \"Team\", count: 5 },\n]\nconst TOTAL = BREAKDOWN.reduce((sum, row) => sum + row.count, 0)\nconst PERCENT = 100\n\nconst ACCOUNTS = [\n  { id: \"northgate\", name: \"Northgate Studio\", note: \"Open invoice question\", value: \"$1,008\" },\n  { id: \"halden\", name: \"Halden Freight\", note: \"Open invoice question\", value: \"$1,008\" },\n  { id: \"pell\", name: \"Pell Street Studio\", note: \"Never added a second seat\", value: \"$504\" },\n]\n\n/** Sample work for the chat to sit beside. Replace it by passing your own screen as children. */\nfunction ChatSampleWork() {\n  return (\n    <div className=\"@container\">\n      <div className=\"flex flex-col gap-6 p-4 @2xl:p-8\">\n        <div className=\"flex flex-col gap-1\">\n          <h2 className=\"text-display text-2xl text-balance @2xl:text-3xl\">\n            March churn. <span className=\"text-muted-foreground\">41 accounts left, up from 18 in February.</span>\n          </h2>\n          <p className=\"text-[13px] text-muted-foreground\">Sample report. Every figure is made up.</p>\n        </div>\n        <section aria-label=\"Accounts lost by plan\" className=\"flex flex-col gap-3 rounded-2xl border bg-background p-4 dark:bg-card @2xl:p-6\">\n          {BREAKDOWN.map((row) => (\n            <div key={row.id} className=\"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1\">\n              <span className=\"text-[13px] text-muted-foreground\">{row.label}</span>\n              <span className=\"text-[13px] tabular-nums\">{row.count}</span>\n              <span aria-hidden=\"true\" className=\"col-span-2 h-2 overflow-hidden rounded-full bg-muted\">\n                <span className=\"block h-full rounded-full bg-foreground/30\" style={{ width: `${(row.count / TOTAL) * PERCENT}%` }} />\n              </span>\n            </div>\n          ))}\n        </section>\n        <section aria-label=\"Accounts to call\" className=\"flex flex-col divide-y rounded-2xl border bg-background dark:bg-card\">\n          {ACCOUNTS.map((account) => (\n            <div key={account.id} className=\"flex items-center justify-between gap-4 p-4 @2xl:px-6\">\n              <div className=\"min-w-0\">\n                <p className=\"text-[15px] text-pretty\">{account.name}</p>\n                <p className=\"text-[13px] text-pretty text-muted-foreground\">{account.note}</p>\n              </div>\n              <span className=\"shrink-0 text-[13px] tabular-nums\">{account.value}</span>\n            </div>\n          ))}\n        </section>\n      </div>\n    </div>\n  )\n}\n\nexport { ChatSampleWork }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/chat-assistant-parts.tsx",
      "content": "import type * as React from \"react\"\nimport { ArrowRight } from \"lucide-react\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport { AgentAvatar } from \"@/registry/miseui/ui/agent-avatar\"\nimport { Button } from \"@/registry/miseui/ui/button\"\nimport type { ReasoningStep } from \"@/registry/miseui/ui/reasoning-steps\"\nimport { ShimmerText } from \"@/registry/miseui/ui/shimmer-text\"\nimport type { ToolCallStatus } from \"@/registry/miseui/ui/tool-call-card\"\n\ntype ChatStatus = \"idle\" | \"generating\"\n\ninterface ChatToolCall {\n  id: string\n  name: string\n  status: ToolCallStatus\n  input?: unknown\n  output?: unknown\n  durationMs?: number\n}\n\ninterface ChatMessage {\n  id: string\n  role: \"user\" | \"assistant\"\n  text: string\n  /** Assistant turns only: what the model did on the way to this answer. */\n  reasoning?: readonly ReasoningStep[]\n  tools?: readonly ChatToolCall[]\n}\n\n/** Header, thread and composer share this column, so all three start on one left edge. */\nconst COLUMN_CLASS = \"mx-auto w-full max-w-2xl\"\nconst BODY_CLASS = \"text-[15px] leading-relaxed text-pretty\"\n\ninterface ChatHeaderProps {\n  agentName: string\n  description: string\n  generating: boolean\n  onNewChat?: () => void\n  /** Extra controls after New chat, such as a way to close a panel. */\n  actions?: React.ReactNode\n}\n\nfunction ChatHeader({ agentName, description, generating, onNewChat, actions }: ChatHeaderProps) {\n  return (\n    <header className=\"border-b px-4 py-3 @md:px-6\">\n      <div className={cn(COLUMN_CLASS, \"flex items-center gap-3\")}>\n        <AgentAvatar seed={agentName} size={32} label={agentName} />\n        <div className=\"flex min-w-0 flex-1 flex-col\">\n          <h2 className=\"truncate text-[15px] font-medium\">{agentName}</h2>\n          <p className=\"truncate text-[13px] text-muted-foreground\">\n            {generating ? <ShimmerText>Working on it</ShimmerText> : description}\n          </p>\n        </div>\n        {onNewChat ? (\n          <Button variant=\"ghost\" size=\"sm\" className={actions ? \"pointer-coarse:h-10\" : undefined} onClick={onNewChat}>\n            New chat\n          </Button>\n        ) : null}\n        {actions}\n      </div>\n    </header>\n  )\n}\n\ninterface ChatStarterProps {\n  agentName: string\n  suggestions: readonly string[]\n  disabled: boolean\n  onPick: (suggestion: string) => void\n  /** A narrow panel: the headline would otherwise take the whole thread. */\n  compact?: boolean\n}\n\n/** Sits at the bottom of the thread, just above the composer, so sending the first message moves nothing. */\nfunction ChatStarter({ agentName, suggestions, disabled, onPick, compact = false }: ChatStarterProps) {\n  return (\n    <div className=\"mt-auto flex flex-col gap-6\">\n      <h3 className={cn(\"text-display leading-[1.12]! text-balance\", compact ? \"text-xl\" : \"text-3xl @2xl:text-4xl\")}>\n        What should we look at?{\" \"}\n        <span className=\"text-muted-foreground\">{agentName} reads your reports and answers with the numbers.</span>\n      </h3>\n      {suggestions.length > 0 ? (\n        <ul className=\"-mx-3 flex flex-col\">\n          {suggestions.map((suggestion) => (\n            <li key={suggestion}>\n              <button\n                type=\"button\"\n                disabled={disabled}\n                onClick={() => onPick(suggestion)}\n                className=\"group flex w-full items-center justify-between gap-3 rounded-md px-3 py-2 text-left text-[15px] text-muted-foreground outline-none transition-colors duration-(--duration-fast) ease-(--ease-mise) hover:bg-accent hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50\"\n              >\n                {suggestion}\n                <ArrowRight\n                  aria-hidden=\"true\"\n                  className=\"size-4 shrink-0 opacity-0 transition-opacity duration-(--duration-fast) ease-(--ease-mise) group-hover:opacity-100 group-focus-visible:opacity-100\"\n                />\n              </button>\n            </li>\n          ))}\n        </ul>\n      ) : null}\n    </div>\n  )\n}\n\nfunction ChatError({ message, onRetry }: { message: string; onRetry?: () => void }) {\n  return (\n    <div role=\"alert\" className=\"flex items-center justify-between gap-3 text-[13px] text-destructive\">\n      <p className=\"text-pretty\">{message}</p>\n      {onRetry ? (\n        <Button variant=\"ghost\" size=\"sm\" onClick={onRetry}>\n          Try again\n        </Button>\n      ) : null}\n    </div>\n  )\n}\n\nexport { BODY_CLASS, ChatError, ChatHeader, ChatStarter, COLUMN_CLASS, type ChatMessage, type ChatStatus, type ChatToolCall }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/chat-assistant-thread.tsx",
      "content": "import { useState } from \"react\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport { ReasoningSteps } from \"@/registry/miseui/ui/reasoning-steps\"\nimport { ShimmerText } from \"@/registry/miseui/ui/shimmer-text\"\nimport { StreamingText } from \"@/registry/miseui/ui/streaming-text\"\nimport { ThinkingOrb } from \"@/registry/miseui/ui/thinking-orb\"\nimport { ToolCallCard } from \"@/registry/miseui/ui/tool-call-card\"\nimport { BODY_CLASS, type ChatMessage, type ChatStatus } from \"@/registry/miseui/blocks/chat-assistant-parts\"\n\nconst WORKING_ORB_PX = 16\n\nfunction UserBubble({ text }: { text: string }) {\n  return (\n    <div className={cn(BODY_CLASS, \"ml-auto w-fit max-w-[85%] rounded-2xl border bg-popover px-4 py-2 break-words whitespace-pre-wrap\")}>\n      {text}\n    </div>\n  )\n}\n\nfunction WorkingRow() {\n  return (\n    <div role=\"status\" className=\"flex items-center gap-2 text-[15px]\">\n      <ThinkingOrb state=\"thinking\" size={WORKING_ORB_PX} label=\"Working\" />\n      <ShimmerText>Thinking</ShimmerText>\n    </div>\n  )\n}\n\ninterface AssistantTurnProps {\n  message: ChatMessage\n  /** Reveal the text at reading pace instead of showing it whole. */\n  streaming: boolean\n  working: boolean\n}\n\nfunction AssistantTurn({ message, streaming, working }: AssistantTurnProps) {\n  const steps = message.reasoning ?? []\n  const tools = message.tools ?? []\n  return (\n    <div className=\"flex flex-col gap-3\">\n      {steps.length > 0 ? (\n        <ReasoningSteps steps={steps} defaultOpen={steps.some((step) => step.status === \"active\")} className=\"bg-popover\" />\n      ) : null}\n      {tools.map(({ id, ...tool }) => (\n        <ToolCallCard key={id} {...tool} className=\"bg-popover\" />\n      ))}\n      {working && steps.length === 0 ? <WorkingRow /> : null}\n      {message.text && streaming ? <StreamingText text={message.text} className={cn(BODY_CLASS, \"block\")} /> : null}\n      {message.text && !streaming ? <p className={cn(BODY_CLASS, \"whitespace-pre-wrap\")}>{message.text}</p> : null}\n    </div>\n  )\n}\n\n/** Keeps the streaming reveal on a turn after status goes idle: the text may still be catching up, and swapping to plain text would make it jump. */\nfunction useStreamingTurnId(messages: readonly ChatMessage[], status: ChatStatus) {\n  const last = messages[messages.length - 1]\n  const liveId = status === \"generating\" && last?.role === \"assistant\" ? last.id : null\n  const [streamingId, setStreamingId] = useState(liveId)\n  if (liveId && liveId !== streamingId) setStreamingId(liveId)\n  return streamingId\n}\n\ninterface ChatThreadProps {\n  messages: readonly ChatMessage[]\n  status: ChatStatus\n}\n\nfunction ChatThread({ messages, status }: ChatThreadProps) {\n  const streamingId = useStreamingTurnId(messages, status)\n  const generating = status === \"generating\"\n  const last = messages[messages.length - 1]\n  return (\n    <ol aria-label=\"Conversation\" className=\"flex flex-col gap-8\">\n      {messages.map((message) => (\n        <li key={message.id}>\n          {message.role === \"user\" ? (\n            <UserBubble text={message.text} />\n          ) : (\n            <AssistantTurn\n              message={message}\n              streaming={message.id === streamingId}\n              working={generating && message === last && !message.text}\n            />\n          )}\n        </li>\n      ))}\n      {generating && last?.role !== \"assistant\" ? (\n        <li>\n          <WorkingRow />\n        </li>\n      ) : null}\n    </ol>\n  )\n}\n\nexport { ChatThread }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/chat-assistant-composer.tsx",
      "content": "import type * as React from \"react\"\nimport { useRef, useState } from \"react\"\nimport { ArrowUp, Square } from \"lucide-react\"\nimport { motion, useReducedMotion } from \"motion/react\"\nimport { SPRING_PRESS } from \"@/registry/miseui/lib/motion\"\nimport { BeamBorder } from \"@/registry/miseui/ui/beam-border\"\nimport { Button } from \"@/registry/miseui/ui/button\"\nimport { Textarea } from \"@/registry/miseui/ui/textarea\"\n\nconst ACTION_ICON_START = { scale: 0.6, opacity: 0 }\nconst ACTION_ICON_END = { scale: 1, opacity: 1 }\n\ninterface ChatComposerProps {\n  label: string\n  placeholder: string\n  generating: boolean\n  disabled: boolean\n  onSend: (text: string) => void\n  onStop?: () => void\n}\n\nfunction ChatComposer({ label, placeholder, generating, disabled, onSend, onStop }: ChatComposerProps) {\n  const [draft, setDraft] = useState(\"\")\n  const fieldRef = useRef<HTMLTextAreaElement>(null)\n  const canSend = !generating && !disabled && draft.trim().length > 0\n\n  const send = () => {\n    if (!canSend) return\n    onSend(draft.trim())\n    setDraft(\"\")\n    fieldRef.current?.focus()\n  }\n  const stop = () => {\n    onStop?.()\n    fieldRef.current?.focus()\n  }\n  const sendOnEnter = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {\n    // isComposing: Enter confirms a Korean or Japanese syllable; sending here would post half a word.\n    if (event.key !== \"Enter\" || event.shiftKey || event.nativeEvent.isComposing) return\n    event.preventDefault()\n    send()\n  }\n\n  return (\n    <BeamBorder active={generating} className=\"rounded-2xl\">\n      <div className=\"flex flex-col gap-2 rounded-[inherit] border bg-popover p-3 shadow-[0_16px_40px_-24px_color-mix(in_oklab,var(--mise)_24%,oklch(0_0_0/40%))] transition-[border-color,box-shadow] duration-(--duration-fast) ease-(--ease-mise) focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50\">\n        <Textarea\n          ref={fieldRef}\n          aria-label={label}\n          rows={1}\n          value={draft}\n          disabled={disabled}\n          placeholder={placeholder}\n          onChange={(event) => setDraft(event.target.value)}\n          onKeyDown={sendOnEnter}\n          className=\"max-h-48 min-h-12 resize-none overflow-y-auto rounded-none border-0 bg-transparent px-1 py-1 leading-relaxed shadow-none focus-visible:ring-0 md:text-[15px]\"\n        />\n        <div className=\"flex items-center justify-between gap-3\">\n          <p className=\"hidden pl-1 text-[13px] text-muted-foreground @md:block\">Enter to send, Shift + Enter for a new line</p>\n          <ComposerAction generating={generating} canSend={canSend} onSend={send} onStop={stop} />\n        </div>\n      </div>\n    </BeamBorder>\n  )\n}\n\ninterface ComposerActionProps {\n  generating: boolean\n  canSend: boolean\n  onSend: () => void\n  onStop: () => void\n}\n\n/**\n * One button that changes job, not two that swap: it keeps keyboard focus across the change. Always\n * type=\"button\", because a type that flips mid-click could submit a form right after Stop.\n */\nfunction ComposerAction({ generating, canSend, onSend, onStop }: ComposerActionProps) {\n  const reduceMotion = useReducedMotion()\n  return (\n    <Button\n      type=\"button\"\n      size=\"icon\"\n      variant={generating ? \"secondary\" : \"mise\"}\n      aria-label={generating ? \"Stop generating\" : \"Send message\"}\n      disabled={!generating && !canSend}\n      onClick={generating ? onStop : onSend}\n      className=\"ml-auto\"\n    >\n      <motion.span\n        key={generating ? \"stop\" : \"send\"}\n        aria-hidden=\"true\"\n        className=\"grid place-items-center\"\n        initial={reduceMotion ? false : ACTION_ICON_START}\n        animate={ACTION_ICON_END}\n        transition={SPRING_PRESS}\n      >\n        {generating ? <Square className=\"size-3.5 fill-current\" /> : <ArrowUp />}\n      </motion.span>\n    </Button>\n  )\n}\n\nexport { ChatComposer }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/chat-assistant-sample.ts",
      "content": "import { useEffect, useReducer } from \"react\"\nimport { useReducedMotion } from \"motion/react\"\nimport type { ReasoningStep, ReasoningStepStatus } from \"@/registry/miseui/ui/reasoning-steps\"\nimport type { ToolCallStatus } from \"@/registry/miseui/ui/tool-call-card\"\nimport type { ChatMessage, ChatStatus, ChatToolCall } from \"@/registry/miseui/blocks/chat-assistant-parts\"\n\n/**\n * A scripted conversation, used only when no `messages` are passed, so the block shows every state out\n * of the box. Once your model is wired up, delete this file together with SampleChat in chat-assistant.tsx.\n * Text arrives word by word, as a real stream does.\n */\nconst FRAME_MS = 700\n/** About 55 characters a second, a little under StreamingText's reveal, so the caret never stalls. */\nconst WORD_MS = 110\n\nconst STEP_LABELS = [\"Reading your question\", \"Searching the reports\", \"Writing the answer\"] as const\n\nfunction stepsAt(statuses: readonly ReasoningStepStatus[]): readonly ReasoningStep[] {\n  return STEP_LABELS.map((label, index) => ({ id: `step-${index}`, label, status: statuses[index] }))\n}\n\nfunction toolAt(status: ToolCallStatus): readonly ChatToolCall[] {\n  return [\n    {\n      id: \"search\",\n      name: \"search_reports\",\n      status,\n      input: { period: \"last_90_days\" },\n      output: status === \"success\" ? { reports: 4 } : undefined,\n      durationMs: status === \"success\" ? 840 : undefined,\n    },\n  ]\n}\n\nconst FRAMES: readonly Pick<ChatMessage, \"reasoning\" | \"tools\">[] = [\n  { reasoning: stepsAt([\"active\", \"pending\", \"pending\"]), tools: [] },\n  { reasoning: stepsAt([\"done\", \"active\", \"pending\"]), tools: toolAt(\"running\") },\n  { reasoning: stepsAt([\"done\", \"done\", \"active\"]), tools: toolAt(\"success\") },\n  { reasoning: stepsAt([\"done\", \"done\", \"done\"]), tools: toolAt(\"success\") },\n]\nconst LAST_FRAME = FRAMES.length - 1\n\nconst SAMPLE_HISTORY: readonly ChatMessage[] = [\n  { id: \"m1\", role: \"user\", text: \"Why did churn jump in March?\" },\n  {\n    id: \"m2\",\n    role: \"assistant\",\n    text: \"41 accounts left in March, up from 18 in February. 29 of them were annual Starter renewals that came due after the price change, and most of those never added a second seat. Monthly plans held steady, so this looks like a renewal problem, not a product one.\",\n    reasoning: [\n      { id: \"r1\", label: \"Read the March churn export\", status: \"done\" },\n      { id: \"r2\", label: \"Compared cohorts against February\", status: \"done\", detail: \"Starter annual stands out\" },\n      { id: \"r3\", label: \"Checked billing events\", status: \"done\" },\n    ],\n    tools: [\n      {\n        id: \"t1\",\n        name: \"query_accounts\",\n        status: \"success\",\n        input: { churned_in: \"2026-03\", group_by: \"plan\" },\n        output: { starter_annual: 29, starter_monthly: 7, team: 5 },\n        durationMs: 1240,\n      },\n    ],\n  },\n  { id: \"m3\", role: \"user\", text: \"Which of those are worth a call this week?\" },\n]\n\nconst OPENING_REPLY =\n  \"Start with Northgate Studio and Halden Freight. Both renewed for two years before this one, both went quiet after the price change, and each still has an open invoice question. I can draft the two emails if you want.\"\nconst PREVIEW_REPLY =\n  \"This is a preview reply, so nothing was really read. Pass messages and status to connect your own model, and this turn will show its steps as they happen.\"\n\nfunction toWords(text: string) {\n  return text.split(\" \")\n}\n\ninterface SampleState {\n  messages: readonly ChatMessage[]\n  status: ChatStatus\n  frame: number\n  words: number\n  script: readonly string[]\n  nextId: number\n}\n\ntype SampleAction = { type: \"send\"; text: string; instant: boolean } | { type: \"tick\" } | { type: \"stop\" } | { type: \"reset\" }\n\nfunction initialState(instant: boolean): SampleState {\n  const script = toWords(OPENING_REPLY)\n  const reply: ChatMessage = { id: \"m4\", role: \"assistant\", text: instant ? OPENING_REPLY : \"\" }\n  return {\n    messages: [...SAMPLE_HISTORY, reply],\n    status: instant ? \"idle\" : \"generating\",\n    frame: LAST_FRAME,\n    words: instant ? script.length : 0,\n    script,\n    nextId: 5,\n  }\n}\n\nfunction patchLast(messages: readonly ChatMessage[], patch: Partial<ChatMessage>) {\n  return messages.map((message, index) => (index === messages.length - 1 ? { ...message, ...patch } : message))\n}\n\nfunction sendMessage(state: SampleState, text: string, instant: boolean): SampleState {\n  const user: ChatMessage = { id: `m${state.nextId}`, role: \"user\", text }\n  const id = `m${state.nextId + 1}`\n  const script = toWords(PREVIEW_REPLY)\n  const reply: ChatMessage = instant\n    ? { id, role: \"assistant\", text: PREVIEW_REPLY, ...FRAMES[LAST_FRAME] }\n    : { id, role: \"assistant\", text: \"\", ...FRAMES[0] }\n  return {\n    messages: [...state.messages, user, reply],\n    status: instant ? \"idle\" : \"generating\",\n    frame: instant ? LAST_FRAME : 0,\n    words: instant ? script.length : 0,\n    script,\n    nextId: state.nextId + 2,\n  }\n}\n\nfunction advance(state: SampleState): SampleState {\n  if (state.frame < LAST_FRAME) {\n    const frame = state.frame + 1\n    return { ...state, frame, messages: patchLast(state.messages, FRAMES[frame]) }\n  }\n  const words = state.words + 1\n  return {\n    ...state,\n    words,\n    status: words >= state.script.length ? \"idle\" : \"generating\",\n    messages: patchLast(state.messages, { text: state.script.slice(0, words).join(\" \") }),\n  }\n}\n\n/** A stopped turn must not keep breathing: unfinished steps go back to waiting, a running tool reads as failed. */\nfunction stopTurn(state: SampleState): SampleState {\n  const last = state.messages[state.messages.length - 1]\n  const reasoning = last.reasoning?.map((step) => (step.status === \"active\" ? { ...step, status: \"pending\" as const } : step))\n  const tools = last.tools?.map((tool) => (tool.status === \"running\" ? { ...tool, status: \"error\" as const } : tool))\n  return { ...state, status: \"idle\", messages: patchLast(state.messages, { reasoning, tools }) }\n}\n\nfunction reducer(state: SampleState, action: SampleAction): SampleState {\n  if (action.type === \"send\") return sendMessage(state, action.text, action.instant)\n  if (action.type === \"tick\") return advance(state)\n  if (action.type === \"stop\") return stopTurn(state)\n  return { ...state, messages: [], status: \"idle\" }\n}\n\nfunction useSampleChat() {\n  const instant = Boolean(useReducedMotion())\n  const [state, dispatch] = useReducer(reducer, instant, initialState)\n  const { status, frame } = state\n\n  useEffect(() => {\n    if (status !== \"generating\") return\n    const id = window.setInterval(() => dispatch({ type: \"tick\" }), frame < LAST_FRAME ? FRAME_MS : WORD_MS)\n    return () => window.clearInterval(id)\n  }, [status, frame])\n\n  return {\n    messages: state.messages,\n    status,\n    send: (text: string) => dispatch({ type: \"send\", text, instant }),\n    stop: () => dispatch({ type: \"stop\" }),\n    reset: () => dispatch({ type: \"reset\" }),\n  }\n}\n\nexport { useSampleChat }\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "blocks"
  ],
  "type": "registry:block"
}