Skip to content

Message

Lays out one conversation turn with its content, actions and branches.

Installation

pnpm dlx shadcn@latest add @frontal-labs/message

Usage

import {
  Message,
  MessageAction,
  MessageActions,
  MessageContent,
  MessageResponse,
  MessageToolbar,
} from "@/components/ui/message";

Each turn is a Message with its from role. MessageContent holds the turn's content and applies the bubble treatment for user turns:

<Message from="user">
  <MessageContent>How do I center a div?</MessageContent>
</Message>
 
<Message from="assistant">
  <MessageContent>
    <MessageResponse>{markdown}</MessageResponse>
  </MessageContent>
</Message>

API Reference

Message

A single conversation turn. Stacks its children vertically and aligns the turn to the end of the row for the user.

MessageContent

Wraps the content of the turn. Renders as a bubble inside a "user" message and as plain text inside an "assistant" message.

MessageResponse

Renders streamed markdown with Streamdown, including code and CJK plugins. Memoized on its children, so it only re-renders when the text changes.

MessageToolbar

A full-width row below the content, typically holding MessageActions and a branch selector.

MessageActions

Groups action buttons together in a row.

MessageAction

An icon button for a single action. Wraps Button and adds a tooltip when tooltip is set.

MessageBranch

Provides the branch context for a turn that has several regenerated variants.

MessageBranchContent

Holds one child per branch and renders only the current one.

MessageBranchSelector

The control row for switching branches. Renders nothing when there is only one branch.

MessageBranchPrevious

Button that moves to the previous branch, wrapping around at the start.

MessageBranchNext

Button that moves to the next branch, wrapping around at the end.

MessageBranchPage

Shows the current position as 1 of 3.

Examples

With Actions

<Message from="assistant">
  <MessageContent>
    <MessageResponse>{markdown}</MessageResponse>
  </MessageContent>
  <MessageToolbar>
    <MessageActions>
      <MessageAction tooltip="Copy">
        <CopyIcon aria-hidden="true" />
      </MessageAction>
      <MessageAction tooltip="Retry">
        <RefreshCcwIcon aria-hidden="true" />
      </MessageAction>
    </MessageActions>
  </MessageToolbar>
</Message>

With Branches

<MessageBranch defaultBranch={0}>
  <MessageBranchContent>
    <Message from="assistant">
      <MessageContent>The first answer.</MessageContent>
    </Message>
    <Message from="assistant">
      <MessageContent>The second answer.</MessageContent>
    </Message>
  </MessageBranchContent>
  <MessageBranchSelector from="assistant">
    <MessageBranchPrevious />
    <MessageBranchPage />
    <MessageBranchNext />
  </MessageBranchSelector>
</MessageBranch>