Skip to content

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.json

Sheen

Online

How can I help today?

Ask a question, paste some code or pick a suggestion to get started.

AI replies can be wrong. Check anything important.Enter to send, Shift + Enter for a new line

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

How can I help today?

Ask a question, paste some code or pick a suggestion to get started.

AI replies can be wrong. Check anything important.Enter to send, Shift + Enter for a new line

Files to copy

14 folders · 26 files · 4 packages
From theme/src/
  • blocks/ai-chat.tsx
  • components/button/
  • components/code-block/tokenize.ts
  • components/drawer/parts/sheet.tsx
  • components/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

  1. You said:

    How do I debounce a search field in React?
  2. Nova said:

    Keep the input instant and debounce the value you search with:

    function useDebounced<T>(value: T, ms = 250) {
      const [debounced, setDebounced] = useState(value);
      useEffect(() => {
        const id = setTimeout(() => setDebounced(value), ms);
        return () => clearTimeout(id);
      }, [value, ms]);
      return debounced;
    }

    Then fetch with useDebounced(query) instead of query.

    Nova Large

AI replies can be wrong. Check anything important.Enter to send, Shift + Enter for a new line

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

How can I help today?

Ask a question, paste some code or pick a suggestion to get started.

AI replies can be wrong. Check anything important.Enter to send, Shift + Enter for a new line

Props

PropTypeDefaultDescription
respondAiChatResponddemoRespondProduces the reply (AiChatRespond). Returns a string (typed out for you), a promise of one, or an async iterable of chunks (real streaming). Defaults to canned demo replies. The default is sample content for demos and prototypes: pass your own in production.
defaultMessagesAiChatMessage[][]Conversation to start with (shown without animation).
messagesAiChatMessage[]NoneThe conversation (controlled). Passing a new array replaces what is shown (load history, switch threads) without animation and stops a reply in progress. Keep it in sync with onMessagesChange; leave it out to let the chat own it.
isTypingbooleanfalseShow the assistant's "thinking" row although no reply is running here, for chats whose replies come from your own backend (controlled messages).
onMessagesChange((messages: AiChatMessage[]) => void)NoneCalled with the whole conversation whenever it settles: a reply ends, stops or fails, or the chat is cleared.
onSend((message: AiChatMessage) => void)NoneCalled when the person sends a message.
onFeedback((message: AiChatMessage, feedback: AiChatFeedback) => void)NoneCalled when a reply is rated (null = rating removed).
modelsAiChatModel[]defaultModelsModels for the picker; the picker hides with fewer than two. The default is sample content for demos and prototypes: pass your own in production.
modelstringNoneSets the selected model's value when controlled.
defaultModelstringNoneThe model selected at first when model is not controlled; the first of models when omitted.
onModelChange((model: string) => void)NoneCalled when another model is picked.
suggestionsstring[]defaultSuggestionsPrompts offered as chips while the chat is empty.
allowAttachmentsbooleantrueShow the attach button and accept dropped files.
acceptstringNoneaccept for the file picker, e.g. "image/*,.pdf".
maxAttachmentsnumber4Most files one message can carry.
simulateStreamingbooleantrueType out string replies word by word (turn it off to show them whole). Streams are never delayed.
typingSpeednumber160Characters per second for the typed-out reply.
thinkingDelaynumber900Shortest "thinking" time (ms) before a string reply starts, so it never flashes.
maxRowsnumber8Tallest the message field grows, in lines, before it scrolls.
headingLevelHeadingLevelOption2Heading level of the assistant name; message headings are one level below. "none" renders them all as paragraphs with no heading role (for an example).
autoFocusbooleanfalseFocus the message field on mount. Off by default: only use it when the chat is the page's main task.
localestring"en-US"BCP 47 locale for file sizes.
labelsPartial<AiChatLabels>defaultAiChatLabelsEvery other string, for translation: labels={{ assistant: "…" }}; omitted keys keep the English of defaultAiChatLabels. All 46 keys of AiChatLabels are listed in the key table under the props table.
classNamestringNoneClasses for the outer glass panel (set its height here).
AiChatLabels keys and English defaults (46)
Pass any key in labels; the rest keep the defaults of defaultAiChatLabels.
KeyEnglish default
assistantSheen
onlineOnline
thinkingThinking
writingWriting…
newChatNew chat
conversationConversation
youSaidYou said:
assistantSaid(assistant) => `${assistant} said:`
emptyTitleHow can I help today?
emptyDescriptionAsk a question, paste some code or pick a suggestion to get started.
suggestionsSuggestions
messageMessage
placeholderAsk anything…
keyHintEnter to send, Shift + Enter for a new line
keyHintTouchUse the send button to send
disclaimerAI replies can be wrong. Check anything important.
sendSend message
stopStop generating
attachAttach files
attachmentsAttachments
removeAttachment(name) => `Remove ${name}`
attached(names) => (names.length === 1 ? `Attached ${names[0]}` : `Attached ${names.length} files`)
removed(name) => `Removed ${name}`
tooManyFiles(max) => `You can attach up to ${max} files`
dropFilesDrop files to attach
modelModel
scrollToBottomScroll to latest message
copyCopy
copiedCopied
copyFailedCouldn't copy. Select the text and copy it instead.
codecode
codeRegion(language) => (language ? `Code, ${language}` : "Code")
copyCodeCopy code
goodResponseGood response
badResponseBad response
feedbackThanksThanks for the feedback
regenerateRegenerate
stoppedStopped
stoppedEarlyStopped before replying.
errorFallbackSomething went wrong while replying.
retryTry again
thinkingAnnouncementThinking
replied(assistant, text) => `${assistant}: ${text}`
replyContinuesThe full reply is in the conversation.
stoppedAnnouncementReply stopped
clearedNew chat started

AiChatRequest

PropTypeDefaultDescription
promptstringNoneThe text of the message being answered.
attachmentsAiChatAttachment[]None{ id, name, size, type, previewUrl, file } for files sent with it.
messagesAiChatMessage[]NoneThe conversation so far, oldest first, ending with this prompt.
modelstringNoneHolds the value of the model the person chose.
attemptnumberNone0 for a new prompt; 1, 2… for each regenerate or retry.
signalAbortSignalNoneAborted by Stop, New chat or unmount. Pass it to fetch.

AiChatMessage

PropTypeDefaultDescription
idstringNoneStable identifier of the message, used as the React key and in callbacks.
role"user" | "assistant"NoneSays who wrote the message: the person ("user") or the model ("assistant").
contentstringNoneLight Markdown: **bold**, code, fenced code blocks, - and 1. lists, [links](https://…). User messages show as plain text.
attachmentsAiChatAttachment[]NoneLists the files shown above a user message.
modelstringNoneSets the model value shown under an assistant reply.
status"thinking" | "streaming" | "done" | "stopped" | "error""done"Progress of an assistant reply; user messages have no status.
errorstringNoneShown when status is error.

Keyboard

KeysAction
EnterSend the message (on touch keyboards Enter adds a line and the send button sends).
Shift + EnterAdd a line.
EscapeStop a reply.
TabThe conversation (a scrollable region), the suggestion chips, the attach button, the model picker, then send.

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

20 blocks pages in all: browse them on All blocks.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .