# AI Chat (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-ai-chat` · version 1.0.0 · block · pro (Pro)
- category: AI interfaces
- build: Base UI (one set of files; its dependencies follow the build)
- install (this build): `npx shadcn@latest add @beautiful-ui-pro/lumen-ai-chat`
- npm dependencies: none
- registry dependencies: utils, @beautiful-ui/lumen-button, @beautiful-ui-pro/lumen-conversation, @beautiful-ui-pro/lumen-prompt-composer, @beautiful-ui-pro/lumen-streaming-text, @beautiful-ui-pro/lumen-reasoning, @beautiful-ui-pro/lumen-citations, @beautiful-ui/lumen-message, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-ai-chat
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

A complete assistant panel: ask, and the reply shows its reasoning, streams in with numbered citations that open their source, and ends with the sources it used. Stop, retry, a failed reply that keeps your message, suggested prompts, and one function to bring your model.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: none beyond React.
- Files: `components/ui/lumen/blocks/ai-chat.tsx`; shared code: `lib/beautiful-ui/lumen/ai-chat-sample.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-button`, `lumen-conversation`, `lumen-prompt-composer`, `lumen-streaming-text`, `lumen-reasoning`, `lumen-citations`, `lumen-message`, `lumen-foundation`.
- Builds: one set of files for both, but its dependencies come in Base UI and Radix builds. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `AiChat`, and every exported type.
- CSS: the install merges this item's rules (the registry `css` field) into your global stylesheet, in `@layer components`, and adds the lumen foundation (tokens, keyframes, motion levels) once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--lumen-*` custom properties (`--lumen-accent`, `--lumen-accent-foreground`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-chart-accent`, `--lumen-chart-accent-foreground`, `--lumen-chart-accent-text`, `--lumen-focus`, `--lumen-good`, `--lumen-good-text`, `--lumen-hairline`, `--lumen-ink`, `--lumen-muted-ink`, `--lumen-series-1`, `--lumen-series-2`, `--lumen-series-3`, `--lumen-series-4`, `--lumen-series-5`, `--lumen-series-6`, `--lumen-warn`, `--lumen-warn-text`); this item's CSS also reads `--lumen-conversation-width`, `--lumen-font-sans`, `--lumen-radius-k`. Never add Tailwind colour classes inside the component.

```tsx
import { AiChat, type AiChatRespond } from "@/components/ui/lumen/blocks/ai-chat";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `AiChat` | `ai-chat` | The panel: header, thread (Conversation) and composer (Prompt Composer). |

Style a part with `[data-slot="<slot>"]` selectors or its `className`; keep the attributes when editing.

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `GlassSoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/glass-sound.json`, import from `@/components/beautiful-ui/glass-sound`); `GlassSoundToggle` is its mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/lumen/blocks/ai-chat.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- AI chat, chatbot UI, assistant panel, LLM chat interface, copilot sidebar, RAG chat with sources, Lumen
- An assistant inside your product, in a page or a side panel
- A starting point for any chat with a model: swap respond for your API

### Not when
- An agent that changes things and needs approvals: use Agent Run
- A single question with one answer: use Message and Streaming Text

## Mistakes
- Pass the AbortSignal to your fetch, or Stop can't end the request
- Give the block a height: the thread scrolls inside it
- Cite with [n] in the order of the sources you yielded

## Usage

```tsx
"use client";

import { AiChat, type AiChatRespond } from "@/components/ui/lumen/blocks/ai-chat";

// Your route streams plain text; Stop aborts the request.
const respond: AiChatRespond = async function* (prompt, { signal, history }) {
  const res = await fetch("/api/chat", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ prompt, history: history.map((m) => ({ role: m.from, content: m.text })) }),
    signal,
  });
  if (!res.ok || !res.body) throw new Error(`Chat failed: ${res.status}`);
  const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
  for (;;) {
    const { value, done } = await reader.read();
    if (done) return;
    yield value;
  }
};

export function HelpPanel() {
  return (
    <div className="h-[640px]">
      <AiChat respond={respond} suggestions={["How do I invite my team?", "Where are invoices?"]} labels={{ title: "Help" }} />
    </div>
  );
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `respond` | `(prompt, { signal, history }) => AsyncIterable<AiChatChunk>` | `the scripted sample` | Your model. Yield text as it streams; yield { type: "reasoning", steps, done? } and { type: "sources", sources } when you have them, and cite as [1], [2] in the text. Stop aborts signal. |
| `suggestions` | `string[]` |  | Prompts offered while the chat is empty. |
| `initialMessages / onMessagesChange` | `ChatMessage[] / (messages) => void` |  | Start from a saved thread; save every change. |
| `assistantName` | `string` | `labels.title` | The assistant's name in the thread. |
| `labels` | `Partial<AiChatLabels>` |  | title, newChat, empty, emptyHint, placeholder, stopped, failed. |
| `timeZone / locale` | `string / string` |  | Times and day breaks in the thread; set the time zone so the server and browser render the same groups. |
| `partLabels` | `{ composer?, conversation?, message?, reasoning?, citations? }` |  | Words inside the parts, for i18n (each the part's own labels). |

Full docs: https://beautiful-ui.dev/components/lumen-ai-chat

## Customising
- Colours: set the `--lumen-*` tokens on `:root`, or on a container with the `lumen-scope` class to retheme one area. Add the `lumen-inherit` class to follow your shadcn palette instead (`--chart-N`, `--destructive`).
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| Enter / Shift+Enter | Send / new line |
| Escape (in the composer) | Stop the reply |
| Tab | Through the thread, its actions and citations, then the composer |

## Motion inventory

| Interaction | What moves |
|---|---|
| Reply | Reasoning shimmers while it works, words settle in as they stream, and the thread follows unless you scroll up |
| Reduced motion | No shimmer, fades or smooth scrolling; text appears as it arrives |

## Accessibility contract (preserve when editing)
- A labelled section; the thread is a polite log and a reply is aria-busy until it settles, so it's read once, whole
- Reasoning is a disclosure; citations are named links; Stop, Retry and New chat are real buttons
- Focus returns to the composer on New chat

## Install

```bash
npx shadcn@latest add @beautiful-ui-pro/lumen-ai-chat
```

Pro item: needs the `@beautiful-ui-pro` registry in `components.json` and `BEAUTIFUL_UI_TOKEN` in `.env.local` (https://beautiful-ui.dev/account). Setup: https://beautiful-ui.dev/docs/pro. Your components.json `style` picks the build: radix-*, new-york and default get Radix, base-* gets Base UI.

## Credits
- Built on shadcn/ui (https://ui.shadcn.com)

The lumen foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/lumen-foundation.json.
