AI Chat UI for React
An AI chat UI for React with replies that stream in word by word, a “thinking” shimmer, Markdown with code blocks and a model picker.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/ai-chat.jsonSheen
Online
AiChatdefaultAiChatLabels
Assistant
Pick a suggestion or type a message. Press Stop (or Escape) while it writes, regenerate the last reply, attach or drop a file, and scroll up mid-reply to see the jump button.
Sheen
Online
import { AiChat } from "@/components/sheenui/blocks/ai-chat";
// Package build (after the first npm release, or a packed tarball): import { AiChat } from "@sheenui/theme";
// Your analytics call
function track(event: string, properties: Record<string, unknown>) {
void fetch("/api/track", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ event, properties }),
});
}
export function Example() {
return (
<AiChat
respond={async ({ messages, model, signal }) => {
const res = await fetch("/api/chat", {
method: "POST",
body: JSON.stringify({ model, messages }),
signal, // Stop aborts the request
});
return res.text(); // a string is typed out word by word
}}
onFeedback={(message, rating) => track("feedback", { id: message.id, rating })}
/>
);
}Files to copy
14 folders · 26 files · 4 packages
- From
theme/src/ blocks/ai-chat.tsxcomponents/button/components/code-block/tokenize.tscomponents/drawer/parts/sheet.tsxcomponents/glass-card/components/select/components/spinner/components/status-icons/components/tooltip/blocks/ai-chat/hooks/{use-controllable.ts, use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts, use-virtual-window.ts}motion/{gate.ts, light-follower.ts, presets.ts, tokens.ts}lib/{cn.ts, field-size.ts, form.ts, glide-highlight.tsx, group-segments.ts, heading.ts, ime.ts, page-size.ts, popup-a11y.ts, popup-motion.ts, state-light.tsx, uid.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/ai-chat.jsonRegistry item: ai-chat. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Real streaming and history
Return an async iterable to stream tokens as they arrive. This one continues an earlier conversation, uses its own assistant name and models, and turns attachments off.
Nova
Online
import { AiChat } from "@/components/sheenui/blocks/ai-chat";
import { type AiChatMessage } from "@/components/sheenui/blocks/ai-chat/types";
// Package build (after the first npm release, or a packed tarball): import { AiChat, type AiChatMessage } from "@sheenui/theme";
// An earlier conversation, e.g. loaded from your database
const savedMessages: AiChatMessage[] = [
{ id: "h1", role: "user", content: "How do I debounce a search field in React?" },
{
id: "h2",
role: "assistant",
model: "nova-large",
content: "Keep the input instant and debounce the **value** you search with, then fetch with the debounced value instead of the raw one.",
},
];
export function Example() {
return (
<AiChat
defaultMessages={savedMessages}
models={[
{ value: "nova-large", label: "Nova Large", description: "Most capable" },
{ value: "nova-small", label: "Nova Small", description: "Fastest" },
]}
allowAttachments={false}
labels={{ assistant: "Nova", placeholder: "Ask Nova…" }}
respond={async function* ({ messages, model, signal }) {
const res = await fetch("/api/chat/stream", { method: "POST", body: JSON.stringify({ model, messages }), signal });
const reader = res.body!.pipeThrough(new TextDecoderStream()).getReader();
for (;;) {
const { value, done } = await reader.read();
if (done) return;
yield value; // each chunk is appended as it arrives
}
}}
/>
);
}Errors and retry
Throw from respond to show an error under the reply. This one fails the first time and works on Try again. Give each chat on a page its own assistant name: it names the chat for screen readers.
Atlas
Online
import { AiChat } from "@/components/sheenui/blocks/ai-chat";
// Package build (after the first npm release, or a packed tarball): import { AiChat } from "@sheenui/theme";
<AiChat
labels={{ assistant: "Atlas" }}
suggestions={["Summarize my week"]}
respond={async ({ attempt }) => {
if (attempt === 0) throw new Error("The model is busy right now (429).");
return "Back online…";
}}
/>Props
AiChatLabels keys and English defaults (46)
AiChatRequest
AiChatMessage
Keyboard
Accessibility
- Every message starts with a visually hidden heading (“You said:”), so the conversation can be navigated by heading.
- Streaming text is not read piece by piece: one polite live region reports thinking, then the finished reply, a stop or an error.
- The key hint is linked to the field with aria-describedby. Give each chat on a page its own assistant name: it names the chat for screen readers.
All exports on this page
AiChat— An assistant chat panel: a message list with streaming replies, a composer, attachments and a model picker.defaultAiChatLabels— The English strings used when the labels prop is omitted (an AiChatLabels); the block merges a partial labels over them.
When to use the AI chat block
- Use AiChat as a streaming chat UI for an assistant panel inside a product, such as a help sidebar or docs search, where you supply a respond function that calls your model API and returns text or an async iterable of chunks. Use it as a chatbot UI in React and Tailwind that you connect to your own model.
- Use it for a prompt playground with a model picker, passing models and onModelChange, plus suggestion chips so first-time visitors have a starting prompt. It is a ChatGPT UI clone in React in layout only: you bring the model and the streaming.
- Use it when users need to attach screenshots or files, since allowAttachments defaults to true and accept and maxAttachments (default 4) limit what the composer takes.
- Skip it when the conversation is between people rather than a person and a model; ChatApp has conversation lists, presence, read state and message actions that AiChat does not.
- Pair it with useSheenReducedMotion if the rest of your page animates around the panel, and Toast for notices outside the chat. Give the panel a fixed height through className.
Frequently asked questions
Related pages
20 blocks pages in all: browse them on All blocks.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .