Chat
The AI conversation thread, the second piece of the AI module. The assistant answers as a document, the Notion and ChatGPT style; the user turn stays a bubble. Streaming and reasoning included.
Try it yourself. This one is live, and its code is right below.
Installation#
Usage#
The preview is yours to explore. Its code comes with a Pro license, paid once and used in every project.
Have a license? Unlock it here
Anatomy#
Every part is a named export, never dot-notation, so each one crosses the server and client boundary cleanly. Conversation is the scrollable thread; each Message carries its role to its parts through context, so one prop drives the side, tint, and meta alignment. Compose only the parts a turn needs.
import {
Conversation,
ConversationScrollButton,
Message,
MessageAvatar,
MessageBody,
MessageHeader,
MessageName,
MessageTime,
MessageReasoning,
MessageReasoningTrigger,
MessageReasoningElapsed,
MessageReasoningContent,
MessageReasoningStep,
MessageReasoningFiles,
MessageReasoningFile,
MessageReasoningFilesMore,
MessageReasoningQueries,
MessageReasoningQuery,
MessageReasoningSources,
MessageReasoningSource,
MessageContent,
MessageTyping,
MessageBranch,
MessageBranchContent,
MessageBranchPrevious,
MessageBranchCount,
MessageBranchNext,
MessageError,
MessageErrorRetry,
MessageErrorDetails,
MessageFeedback,
MessageFeedbackUp,
MessageFeedbackDown,
MessageFeedbackReasons,
MessageActions,
MessageAction,
MessageFollowUps,
MessageFollowUp,
} from "@/components/ui/chat"
<Conversation>
<Message>
<MessageAvatar />
<MessageBody>
<MessageHeader>
<MessageName />
<MessageTime />
</MessageHeader>
<MessageReasoning>
<MessageReasoningTrigger>
<MessageReasoningElapsed />
</MessageReasoningTrigger>
<MessageReasoningContent>
<MessageReasoningStep>
<MessageReasoningQueries>
<MessageReasoningQuery />
</MessageReasoningQueries>
<MessageReasoningSources>
<MessageReasoningSource />
</MessageReasoningSources>
<MessageReasoningFiles>
<MessageReasoningFile />
<MessageReasoningFilesMore />
</MessageReasoningFiles>
</MessageReasoningStep>
</MessageReasoningContent>
</MessageReasoning>
<MessageBranch>
<MessageBranchContent>
<MessageTyping>
<MessageTypingNote />
</MessageTyping>
</MessageBranchContent>
<MessageError>
<MessageErrorRetry />
<MessageErrorDetails />
</MessageError>
<MessageFeedback>
<MessageActions>
<MessageBranchPrevious />
<MessageBranchCount />
<MessageBranchNext />
<MessageAction />
<MessageFeedbackUp />
<MessageFeedbackDown />
</MessageActions>
<MessageFeedbackReasons />
</MessageFeedback>
</MessageBranch>
<MessageFollowUps>
<MessageFollowUp />
</MessageFollowUps>
</MessageBody>
</Message>
<ConversationScrollButton />
</Conversation>Roles#
A message's role is the only switch. assistant aligns left with an avatar and a muted bubble; user aligns right with a solid blue bubble. Both use a soft, uniform radius on all four corners.
With avatar (bubble)#
The default is the document style above. For a chat with an identity, the “robotized” look, set variant="bubble" on the Conversation: every turn gets a bubble, and you pair the assistant with a MessageAvatar, name, time, and actions. A per-message variant overrides the conversation default.
Rich content#
MessageContent is markup-agnostic. For a model reply, put Markdown in it: it takes the message's streaming and keeps half-written syntax off screen. Plain text or markup of your own works too: the bubble styles paragraphs, headings, lists, tables, quotes, code and links, tinted to read on either bubble.
Actions#
MessageActions holds a row of MessageAction buttons for copy and regenerate. Each wraps our Button, so it inherits the focus ring and a tooltip drawn from its aria-label. Thumbs, version arrows and retry have their own parts, below.
Branches#
After a regenerate or an edit, a turn holds several versions of the answer. MessageBranch keeps the active one and MessageBranchContent renders it from its children, one child per version. The pager fits in the actions row: previous and next disable at the ends, the count reads “2/3” and announces “Version 2 of 3”, and all three hide while there is only one version. Switching slides the new version in from the side you moved toward; under reduced motion it only fades. Uncontrolled, it follows the newest version; control index to jump to a fresh regenerate. If only the active version lives on the client, pass count and render that one child. Press regenerate to add a fourth.
Feedback#
MessageFeedback wraps the actions row and holds the vote. MessageFeedbackUp and MessageFeedbackDown are toggles (aria-pressed): the picked one sits on a faint chip, in ink (the thumbs up also fills its glyph, the thumbs down keeps its outline), and pressing it again takes the vote back. A thumbs down opens MessageFeedbackReasons in a popover pinned to the thumb, so the thread stays put: reason chips, an optional comment and Submit. Escape or a click away closes it and keeps the vote. Once sent, a thank you shows in the popover before it folds away; a thumbs up only fills its glyph.
Error#
When a reply fails, put a MessageError where the content would be. The message is a polite sentence about what happened, announced as an alert; its children line up under it. MessageErrorRetry sends the turn again and MessageErrorDetails folds the raw error (status, request id) behind a Details toggle, for support and bug reports.
The model is busy right now, so this reply didn't finish.
Typing indicator#
Until the first words arrive, put a MessageTyping straight in the MessageBody: one quiet line with the same arc as the reasoning trigger, so the chat has a single loader. Pass the current step as label and it swaps in place; elapsed counts the seconds, and MessageTypingNote children list what the model has found so far. When the answer starts, the line hands over to a MessageReasoningTrigger that reads “Thought for 4s”.
A person typing#
In a chat between people, set indicator="dots": three dots pulse in turn in place of the agent arc. Name who is typing in the label, so the status reads the same out loud.
Streaming text#
Once the first words arrive, swap the typing line for the text and pass streaming to MessageContent. The bursts a model sends come out at a steady reading pace, nothing fades, blurs or blinks, and only the freshest words come in lighter and settle to full ink as newer ones push them back. Before a new paragraph the pace waits for that ink to dry, and once the answer is done the last words settle and the text goes back to plain markup. Under reduced motion the pace stays and the ink is full from the start. Plain string children and a Markdown inside both stream this way.
Follow-ups#
Suggested next prompts under an answer, the way Grok and Perplexity offer them. MessageFollowUps is a labelled list and each MessageFollowUp a quiet Button that wraps long lines. Send the text as is on click, and keep them on the latest answer only: under an older one they no longer say what they refer to.
Reasoning#
The collapsible “thinking” block, the way Claude and ChatGPT show it. While streaming a small spinner turns beside the label and the trigger reads “Investigating…”; once done, it settles to a summary like “Investigated 14 sources” that anyone can expand, and the spinner closes into a check. For a simple answer, pass plain text; for an agentic run, the block becomes a log of what it did. Group each phase in a MessageReasoningStep (an optional label captions it, a dot pins onto the rail so a column reads as a timeline, and status="active" pulses the in-progress one). Show the searches it ran with MessageReasoningQuery and the URLs it consulted with MessageReasoningSource, as compact favicon and domain chips by default or a bordered title list via layout="list". The domain and favicon are derived from the href. Built on Radix Collapsible, so keyboard and ARIA come for free. Press Ask again to watch it stream through the phases.
Agent trace#
For a coding agent, write each step as one line with title, in the present while it runs (“Reading 3 of 6 files”) and in the past once done (“Read 6 files about sessions and cookies”). The live line takes full ink and a slow sweep; finished lines go muted. Give a step an icon for its kind, a search or the final check. Mark an approach that went nowhere with status="dead-end": a cross on the rail, and the line fades back. Set elapsed on the trigger and it counts “Thinking 9s”, then settles to “Thought for 14s”. Press Run again to watch the full trace.
Stopped runs and a custom clock#
When the user stops a run, mark the step it was on as status="stopped": a small square takes the dot's place and the title fades, so the log shows where it was cut. With your own trigger label, MessageReasoningElapsed adds the live clock: it counts from since (the time the turn was sent, so a remount doesn't restart it), stays hidden below hideBelow seconds and disappears once the run stops streaming.
Jump to latest#
Drop a ConversationScrollButton as the last child of a Conversation. It stays hidden while the reader is at the newest turn; scroll up and a pill fades in, centered over the thread's bottom edge (a sticky row, so it never scrolls with the history and takes no room in it). Pressing it glides back down and resumes following. The follow survives streaming and resizing: a turn that grows by itself, or a panel that changes size, keeps a reader who was at the bottom there, and the thread's own glide never flashes the pill on the way down. Stream the answer below, then scroll up while it writes.
The Conversation must be the element that scrolls: give it a height (here min-h-0 flex-1 in a sized column; in an AI Panel, <AIPanelBody scrollable={false}>).
API reference#
Conversation
The scrollable thread, a role="log" polite live region; give it a height or max-height to scroll. Forwards all native <div> props. Every part accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "plain" | "bubble" | "plain" | The style of every turn: the assistant answer as a page, or every turn a bubble. |
| stickToBottom | boolean | true | Follows new turns while the reader is already at the bottom; scrolling up is never yanked back. The first pass lands instantly, later ones glide. Turn it off for a static transcript that opens at the top. |
| Data attribute | Description |
|---|---|
| data-variant | "plain" or "bubble". |
ConversationScrollButton
The "jump to latest" pill: place it as the last child of a Conversation. It shows only while the reader has scrolled away from the newest turn, floats centered over the thread's bottom edge, and on press glides back down and resumes following. The Conversation must be the element that scrolls (min-h-0 flex-1, or AIPanelBody scrollable={false}). Takes every Button prop except asChild.
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | "Jump to latest" | The pill's text, also its accessible name. |
| children | React.ReactNode | - | Replaces the default arrow and label. |
| variant | ButtonProps["variant"] | "outline" | Any Button variant. |
| size | "sm" | "md" | "lg" | "xl" | "sm" | The Button size. |
| Data attribute | Description |
|---|---|
| data-state | "visible" or "hidden", on the sticky row that wraps the button. |
Message
One turn; its role flows to every part. Forwards all native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| role | "assistant" | "user" | "assistant" | Who sent it: drives the side, the alignment and the bubble tint. |
| variant | "plain" | "bubble" | - | Overrides the style of the conversation for this turn. |
| Data attribute | Description |
|---|---|
| data-role | "assistant" or "user". |
MessageAvatar
The sender avatar, an Avatar that takes every Avatar root prop. Children replace the initials (with an icon, say).
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | - | The image URL. |
| name | string | - | The alt text, and the source of the initials fallback. |
| size | "xs" | "sm" | "md" | "lg" | "xl" | "sm" | The Avatar size. |
MessageBody
The column holding header, content and actions, aligned to the message side. Forwards all native <div> props.
MessageHeader
The optional meta row above the content. Forwards all native <div> props.
MessageName
The sender name. Forwards all native <span> props.
MessageTime
The muted timestamp. Forwards all native <span> props.
MessageContent
The bubble (or, for a plain assistant turn, the page), markup-agnostic. Forwards all native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| streaming | boolean | false | The answer is still arriving: its text comes out at a steady pace and the freshest words settle from a lighter ink. No caret, no fade. Under reduced motion the ink is full from the start. |
| Data attribute | Description |
|---|---|
| data-streaming | Present while streaming. |
MessageActions
The row of actions under a turn. Forwards all native <div> props.
MessageAction
One action (copy, regenerate): a Button that takes every Button prop; its aria-label names it and feeds the tooltip.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | ButtonProps["variant"] | "ghost" | Any Button variant. |
| size | "sm" | "md" | "lg" | "xl" | "sm" | The Button size. |
| iconOnly | boolean | true | A square icon button. |
MessageBranch
Holds the versions of one answer and which is showing. Renders as display: contents, so it wraps the content and the actions row without changing the layout. Forwards all native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| index | number | - | The active version, zero-based, controlled. |
| defaultIndex | number | - | The first version shown, uncontrolled. Without it the newest is shown, and the branch follows each new one. |
| onIndexChange | (index: number) => void | - | Called when the pager moves. |
| count | number | - | The number of versions, when MessageBranchContent renders only the active one. Without it the count comes from the content's children. |
MessageBranchContent
Renders the active version: one child per version, or just the active one with count. A switch slides the new version in toward the direction of travel; reduced motion fades only. Forwards all native <div> props.
| Data attribute | Description |
|---|---|
| data-direction | "next" or "prev", the last move. Absent until the first one. |
MessageBranchPrevious
Shows the previous version: a MessageAction labelled "Previous version", disabled on the first. Hidden while there is one version. Takes every Button prop; children replace the caret.
MessageBranchNext
Shows the next version: a MessageAction labelled "Next version", disabled on the last. Hidden while there is one version. Takes every Button prop; children replace the caret.
MessageBranchCount
The "2/3" between the arrows, in tabular figures, with a polite live label for screen readers. Hidden while there is one version. Forwards all native <span> props; children replace the visible text.
| Prop | Type | Default | Description |
|---|---|---|---|
| label | (index: number, count: number) => string | Version ${index} of ${count} | The announced text, one-based. Use it to translate. |
MessageFeedback
Holds the thumbs vote for one answer; wrap the actions row and the reasons with it. Renders as display: contents. Forwards all native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | "up" | "down" | null | - | The vote, controlled. |
| defaultValue | "up" | "down" | null | null | The vote on first render, uncontrolled. |
| onValueChange | (value: "up" | "down" | null) => void | - | Called on each vote, and with null when a vote is taken back. |
| Data attribute | Description |
|---|---|
| data-value | "up" or "down"; absent with no vote. |
MessageFeedbackUp
The thumbs-up toggle: a MessageAction with aria-pressed, labelled "Good response". Picked, it fills its glyph on a faint chip; pressed again, it clears the vote. Takes every Button prop.
MessageFeedbackDown
The thumbs-down toggle, labelled "Bad response". Picking it opens MessageFeedbackReasons. Takes every Button prop.
MessageFeedbackReasons
The popover that opens from the thumbs down: reason chips, an optional comment, Cancel and Submit. Focus moves to the first reason and returns to the thumb on close. After Submit (the button spins while an async onSubmit is pending) the popover morphs into a status line, Feedback sent then the thank-you, each announced, and closes. Forwards PopoverContent props (align, side, sideOffset) except title and onSubmit.
| Prop | Type | Default | Description |
|---|---|---|---|
| reasons | readonly string[] | MESSAGE_FEEDBACK_REASONS | The chips: Inaccurate, Didn't follow instructions, Too long, Unsafe, Other. |
| onSubmit | (details: { reasons: string[]; comment: string }) => void | PromiseLike<unknown> | - | Called with the picked reasons and the trimmed comment. While a returned promise is pending the Submit button spins; if it rejects, the form comes back. |
| title | React.ReactNode | "What went wrong?" | The panel's heading, also the chip group's name. |
| comment | boolean | true | Shows the optional comment field. |
| commentPlaceholder | string | "Add details (optional)" | The field's placeholder and accessible name. |
| submitLabel | string | "Submit" | The primary button. Disabled until a reason or a comment. |
| cancelLabel | string | "Cancel" | Closes the popover; the vote stays. |
| sentLabel | React.ReactNode | "Feedback sent" | Beside the success check once the feedback is in, before the thank-you. |
| thanks | React.ReactNode | "Thanks for the feedback." | The last line, rolled in from sentLabel before the popover folds away. |
| align | "start" | "center" | "end" | "start" | Where the popover lines up against the thumb. |
MessageError
A failed reply, in place of the content: a warning glyph and the message, announced as an alert, with its children (retry, details) in a row under the text. Forwards all native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| message | React.ReactNode | "Something went wrong while writing this reply." | What happened, in a sentence. |
| icon | React.ReactNode | - | Replaces the warning glyph. |
MessageErrorRetry
Sends the turn again: an outline Button that takes every Button prop.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode | "Try again" | The label. |
| variant | ButtonProps["variant"] | "outline" | Any Button variant. |
| size | "sm" | "md" | "lg" | "xl" | "sm" | The Button size. |
MessageErrorDetails
The raw error (status, request id) folded behind a ghost toggle, over Radix Collapsible.Root: forwards its props (open, defaultOpen, onOpenChange). Children render monospace, wrapping; className lands on that block.
| Prop | Type | Default | Description |
|---|---|---|---|
| label | React.ReactNode | "Details" | The toggle's text. |
| Data attribute | Description |
|---|---|
| data-state | "open" or "closed", from Radix. |
MessageFollowUps
A labelled list of suggested next prompts under an answer; each child becomes a list item. Forwards all native <ul> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | "Suggested follow-ups" | The list's accessible name. |
MessageFollowUp
One suggestion: a ghost Button that wraps long lines, with a reply-arrow glyph. Takes every Button prop.
| Prop | Type | Default | Description |
|---|---|---|---|
| icon | React.ReactNode | - | Replaces the reply arrow. |
MessageTyping
The line shown before the reply starts: the reasoning arc and a label, as a role="status". Children are MessageTypingNotes listed under it. Put it straight in the MessageBody. Forwards all native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | "Thinking" | The current step; a new value swaps in place. |
| elapsed | boolean | number | - | true counts seconds while it is shown; a number shows that value. |
| indicator | "arc" | "dots" | "arc" | arc is the agent mark. dots is three pulsing dots, for a person typing in a chat between people. |
MessageTypingNote
One finding under the typing line, a list item that fades and sharpens in as it arrives. Forwards all native <li> props.
MessageReasoning
The collapsible thinking block, over Radix Collapsible.Root: forwards all its props.
| Prop | Type | Default | Description |
|---|---|---|---|
| streaming | boolean | false | The model is still thinking: the mark spins and the default label reads "Thinking…". |
| status | AgentStatus | - | Overrides what the mark shows, in the shared agent vocabulary: working spins, waiting holds with a warning dot, done closes into a check, failed draws a cross, cancelled a square. Defaults to working while streaming, else done. |
| open | boolean | - | Open state, controlled. |
| defaultOpen | boolean | false | Open state on first render, uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when it opens or closes. |
| Data attribute | Description |
|---|---|
| data-state | "open" or "closed", from Radix. |
MessageReasoningTrigger
The one-line toggle, over Radix Collapsible.Trigger. Children are the label ("Thought for 6s"); without them it rolls between "Thinking…" and "Reasoning".
| Prop | Type | Default | Description |
|---|---|---|---|
| elapsed | boolean | number | - | true keeps its own clock: "Thinking 9s" while streaming, then "Thought for 14s". A number shows that many seconds. Ignored when you pass children. |
| Data attribute | Description |
|---|---|
| data-state | "open" or "closed". Turns the caret. |
MessageReasoningElapsed
A live seconds counter for your own trigger label ("Working… 7s"). Renders only while the reasoning streams. Forwards all native <span> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| since | number | - | Epoch ms the clock counts from. Defaults to when it mounted. |
| hideBelow | number | 0 | Stay hidden until this many seconds have passed: a short wait needs no clock. |
| format | (seconds: number) => React.ReactNode | - | Renders the count, for another unit style or locale (7 s). Defaults to 7s. |
MessageReasoningContent
The chain of thought behind a left rail, over Radix Collapsible.Content. className lands on the inner <div>.
| Data attribute | Description |
|---|---|
| data-state | "open" or "closed". |
MessageReasoningStep
One phase of the reasoning log, with a node on the rail. Forwards native <div> props except title.
| Prop | Type | Default | Description |
|---|---|---|---|
| title | React.ReactNode | - | The one line an agent-trace step reads as. Full ink and a sweep while active, muted once done, fainter as a dead end. |
| label | React.ReactNode | - | A quiet caption above the step ("Searching"). |
| status | "active" | "done" | "dead-end" | "stopped" | "done" | active turns the dot into an ink pulse; dead-end swaps it for a cross and stopped (the user cut the run there) for a small square, both fading the title. |
| marker | boolean | true | Draws the rail node (the dot, or the icon). |
| icon | React.ReactNode | - | A glyph in place of the dot (14px unless it carries its own size-*), such as a search or the final check. |
| Data attribute | Description |
|---|---|
| data-status | "active", "done", "dead-end" or "stopped". |
MessageReasoningFiles
A wrapping row of file pills. Forwards all native <div> props.
MessageReasoningFile
One file or page the model opened: a pill, not a link. Forwards all native <span> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| name* | string | - | The file name; its extension picks the glyph (ts, tsx, css, md…). Children replace it as the label. |
| icon | React.ReactNode | - | Overrides the derived glyph. |
MessageReasoningFilesMore
The "+3 more" that closes a row of files. Forwards all native <span> props.
MessageReasoningQueries
A wrapping row of query pills. Forwards all native <div> props.
MessageReasoningQuery
One search the model ran: a monospace pill with a magnifier. Forwards all native <span> props.
MessageReasoningSources
The URLs the model consulted. Forwards all native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| layout | "chips" | "list" | "chips" | Compact domain pills, or a bordered list of titled rows. Flows to each source. |
| Data attribute | Description |
|---|---|
| data-layout | "chips" or "list". |
MessageReasoningSource
One source, an <a> that opens in a new tab. Forwards native <a> props except title.
| Prop | Type | Default | Description |
|---|---|---|---|
| href* | string | - | The URL; the domain and favicon derive from it. |
| title | React.ReactNode | - | The headline in the list layout; the domain by default. |
| favicon | string | - | Overrides the derived favicon; a globe shows if it fails. |