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
Pro
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

components/support-chat.tsx
"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.

TypeNotes
onSend(request: AIChatRequest) => AsyncIterable<string | AIChatEvent> | Promise<string> NoSends the conversation to your model; returns the answer as a stream, or a promise of the whole text.
defaultMessagesAIChatMessage[] NoA conversation to start from.
onMessagesChange(messages: AIChatMessage[]) => void NoCalled whenever the thread changes — to save it.
assistant{ name: string; avatar?: React.ReactNode; model?: string; modelLogo?: React.ReactNode } NoShown 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.
userAvatarReact.ReactNode NoA face beside the person's messages.
welcomeAIChatWelcome NoThe empty screen.
placeholderstring No–
onFeedback(message: AIChatMessage, value: MessageFeedback, reason?: string) => void NoCalled when an answer is rated, and again with the reason for a thumbs down.
headerboolean NoShow the header with the assistant's name and New chat. Default true.
headerLeadingReact.ReactNode NoBefore the name in the header: a menu button that opens your sidebar on phones.
headerActionsReact.ReactNode NoBefore New chat in the header: more buttons of your own.
onNewChat() => void NoNew 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 NoA choice, an option or Confirm was picked. Its label is also sent as the next message.
onStatusChange(status: "idle" | "submitting" | "streaming") => void NoIdle, waiting for the first word, or writing — for a header of your own.
notice{ text: React.ReactNode; action?: { label: string; onClick: () => void } } NoA line above the box: "Recording ready: demo.mp4", with one action.
toolsReact.ReactNode NoBottom-left of the box: an attach button, a model picker.
composerHeaderReact.ReactNode NoAbove the text in the box: attachment chips.
composerDisabledboolean NoKeep the box usable while waiting, e.g. disabled while a human agent is joining.
lookLook NoLayered 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-merge

Liro foundations, installed alongside it

liro-themebuttonchat-empty-statechat-messagemessage-actionsprompt-inputstreaming-responsethinking-statetooltip

States

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

Used in a screenAll screens