AI Chat
A whole chat window: greeting, streaming answers, stop, retry and regenerate.
PROGet AI Chat and 168 other Pro components with pro lifetime — Get Pro
- Category
- AI Chat
- Access
- ProPro · unlocked
- Source
- 870 lines · one file
- States
- 7 drawn
- Kind
- Block
- Added
- 19 Oct 2026
The decision inside it
It takes one function, not an SDK
The window owns the screen and nothing else. `onSend` receives the conversation and an abort signal and returns strings, so it fits any model or provider, and a built-in simulator means it runs before there is a backend.
When to use it
Use AI Chat when you want a complete chat window: a support assistant, a copilot panel, a chat page. Pass one onSend function that streams the answer from your model; thinking, streaming, stop, retry and regenerate are handled. To build a custom layout, use the parts it is made of, such as Chat Message, Streaming Response and Prompt Input.
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 AI Chat for this.
Install it: npx shadcn@latest add @liro/ai-chat
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/ai-chat.
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. Pro components install through the @liro registry with your CLI token: see the Namespaced tab.
Usage
"use client";
import { AIChat, type AIChatRequest } from "@/components/ui/ai-chat";
async function* send({ messages, signal }: AIChatRequest) {
const res = await fetch("/api/chat", { method: "POST", body: JSON.stringify({ messages }), signal });
const reader = res.body!.pipeThrough(new TextDecoderStream()).getReader();
for (;;) {
const { done, value } = await reader.read();
if (done) return;
yield value;
}
}
export function SupportChat() {
return (
<AIChat
assistant={{ name: "Support" }}
welcome={{ title: "How can I help?", starters: ["Where is my order?", "Change my plan"] }}
onSend={send}
/>
);
}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.
| Type | Notes | ||
|---|---|---|---|
onSend | (request: AIChatRequest) => AsyncIterable<string | AIChatEvent> | Promise<string> | No | Sends the conversation to your model; returns the answer as a stream, or a promise of the whole text. |
defaultMessages | AIChatMessage[] | No | A conversation to start from. |
onMessagesChange | (messages: AIChatMessage[]) => void | No | Called whenever the thread changes — to save it. |
assistant | { name: string; avatar?: React.ReactNode; model?: string; modelLogo?: React.ReactNode } | No | Shown in the header and above each answer. `model` names what it runs on ("Claude Sonnet 4.5") beside the status in the header, led by `modelLogo`, the vendor's mark in its own colours. |
userAvatar | React.ReactNode | No | A face beside the person's messages. |
welcome | AIChatWelcome | No | The empty screen. |
placeholder | string | No | – |
onFeedback | (message: AIChatMessage, value: MessageFeedback, reason?: string) => void | No | Called when an answer is rated, and again with the reason for a thumbs down. |
header | boolean | No | Show the header with the assistant's name and New chat. Default true. |
headerLeading | React.ReactNode | No | Before the name in the header: a menu button that opens your sidebar on phones. |
headerActions | React.ReactNode | No | Before New chat in the header: more buttons of your own. |
onNewChat | () => void | No | New chat in the header. When set, it is called instead of clearing this thread, so you can add a conversation to your list and switch to it (with a new `key`). Without it, New chat clears the thread. |
onAction | (action: AIChatAction) => void | No | A choice, an option or Confirm was picked. Its label is also sent as the next message. |
onStatusChange | (status: "idle" | "submitting" | "streaming") => void | No | Idle, waiting for the first word, or writing — for a header of your own. |
notice | { text: React.ReactNode; action?: { label: string; onClick: () => void } } | No | A line above the box: "Recording ready: demo.mp4", with one action. |
tools | React.ReactNode | No | Bottom-left of the box: an attach button, a model picker. |
composerHeader | React.ReactNode | No | Above the text in the box: attachment chips. |
composerDisabled | boolean | No | Keep the box usable while waiting, e.g. disabled while a human agent is joining. |
look | Look | No | Layered sets the conversation on a card in a tray, the assistant's name above it. Flat is one card. |
Dependencies
npm packages
clsxframer-motionlucide-reacttailwind-mergeLiro foundations, installed alongside it
liro-themebuttonchat-empty-statechat-messagemessage-actionsprompt-inputstreaming-responsethinking-statetooltipStates
All of them are drawn by the component. None is left for you to design.
- Idle
- Thinking
- Generating
- Completed
- Cancelled
- Failed
- Empty
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