Launch priceOne payment

AI Chat

The seven free chat components working together as one window. You give it a single `onSend` function that returns the answer as a stream; it draws thinking, generating, completed, cancelled and failed, follows new text while you are at the bottom, and leaves you alone once you scroll up to read.

AI ChatBlockFree439 lines · one file

Ready for AI tools one file typed props installs by name prompt included

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.

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 Layro's AI Chat for this.
Install it: npx shadcn@latest add https://layropro.com/r/ai-chat
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.

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.

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

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

PropTypeNotes
onSend(request: AIChatRequest) => AsyncIterable<string | AIChatEvent> | Promise<string>Sends the conversation to your model; returns the answer as a stream, or a promise of the whole text.
defaultMessagesAIChatMessage[]A conversation to start from.
onMessagesChange(messages: AIChatMessage[]) => voidCalled whenever the thread changes — to save it.
assistant{ name: string; avatar?: React.ReactNode }Shown in the header and above each answer.
userAvatarReact.ReactNodeA face beside the person's messages.
welcomeAIChatWelcomeThe empty screen.
placeholderstring—
onFeedback(message: AIChatMessage, value: MessageFeedback, reason?: string) => voidCalled when an answer is rated, and again with the reason for a thumbs down.
headerbooleanShow the header with the assistant's name and New chat. Default true.
onAction(action: AIChatAction) => voidA choice, an option or Confirm was picked. Its label is also sent as the next message.
onStatusChange(status: "idle" | "submitting" | "streaming") => voidIdle, waiting for the first word, or writing — for a header of your own.
notice{ text: React.ReactNode; action?: { label: string; onClick: () => void } }A line above the box: "Recording ready: demo.mp4", with one action.
toolsReact.ReactNodeBottom-left of the box: an attach button, a model picker.
composerHeaderReact.ReactNodeAbove the text in the box: attachment chips.
composerDisabledbooleanKeep the box usable while waiting, e.g. disabled while a human agent is joining.

Dependencies

npm packages

clsxframer-motionlucide-reacttailwind-merge

Layro foundations, installed alongside it

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

Lifetime access

Every component, and everything we ship next.

  • All 112 components, source included
  • The template, and everything released after you buy
  • shadcn CLI or download — React 18/19, Tailwind v4
  • One payment. No subscription.

More in AI Chat

All AI Chat components