Chat Message

One turn in a conversation, for the person or the assistant, with sources and attachments.

Category
AI Chat
Access
Free with an account
Source
315 lines · one file
States
4 drawn

When to use it

Use Chat Message to render one turn of a conversation you manage yourself: user bubbles on the right, assistant answers unboxed on the left, with sources, attachments, and stopped or failed states. For a whole working chat window with streaming and auto-scroll, use AI Chat instead.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Chat Message for this.
Install it: npx shadcn@latest add @liro/chat-message
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/chat-message.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/thread.tsx
import { ChatMessage, ChatMessageList } from "@/components/ui/chat-message";

export function Thread({ onRetry }: { onRetry: () => void }) {
  return (
    <ChatMessageList>
      <ChatMessage role="user">Which invoices are still unpaid?</ChatMessage>
      <ChatMessage
        role="assistant"
        sources={[{ title: "Invoices · October", meta: "billing.csv", href: "/billing" }]}
      >
        Two: INV-2041 for $1,200 and INV-2044 for $380.
      </ChatMessage>
      <ChatMessage role="assistant" status="failed" error="The model timed out." onRetry={onRetry} />
    </ChatMessageList>
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
roleChatRole YesWho is speaking. `system` is a centred line for events: "Context cleared".
childrenReact.ReactNode NoThe message. Plain text, or `<StreamingResponse>` for an assistant's answer.
namestring NoShown above an assistant message. Also read out before it.
avatarReact.ReactNode NoReplaces the default mark (assistant) or adds a face (user).
timestring NoAlready formatted: "10:42".
statusChatMessageStatus NoHow the message ended, or that it has not yet. Default `complete`.
errorstring NoWhy it failed, in plain words. Shown when `status` is `failed`.
onRetry() => void NoShows Retry beside the error. Leave it out when retrying cannot help.
attachmentsChatAttachment[] NoFiles sent with the message.
sourcesChatSource[] NoWhat the answer was drawn from, numbered in the order given.
actionsReact.ReactNode NoThe row under an assistant message — usually `<MessageActions>`.
animateboolean NoRise and fade in when mounted. Default true; reduced motion turns it off.

Dependencies

npm packages

clsxframer-motionlucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-themebutton

States

All of them are drawn by the component. None is left for you to design.

  • Complete
  • Streaming
  • Cancelled
  • Failed

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances