# Chat App (Notchset): prompt.md (v1.0.0)

- id: `chat-app` · 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/chat-app`
- npm dependencies: none
- registry dependencies: utils, https://beautiful-ui.dev/r/notchset-foundation.json
- docs: https://beautiful-ui.dev/components/chat-app
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

A team assistant workspace: a rail with a history drawer, an empty state that starts from your data, a thread that reads as a ledger with sources, tables and follow-ups, and an aside for the model, the context of the next message and today's spend.

## 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/notchset/blocks/chat-app.tsx`; shared code: `lib/beautiful-ui/notchset/instrument.tsx`, `lib/beautiful-ui/notchset/root.ts`, `lib/beautiful-ui/notchset/blocks.tsx`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `notchset-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: `ChatApp`, and every exported type.
- CSS: the install adds the notchset foundation (tokens, keyframes, motion levels) to your global stylesheet 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 `--notchset-*` custom properties (`--notchset-check`, `--notchset-control-edge`, `--notchset-draw-from`, `--notchset-ease-bloom`, `--notchset-ease-glide`, `--notchset-ease-key-down`, `--notchset-ease-key-up`, `--notchset-ease-travel`, `--notchset-fade`, `--notchset-focus-color`, `--notchset-focus-inset`, `--notchset-grow-to`, `--notchset-key-down`, `--notchset-key-up`, `--notchset-life-from`, `--notchset-life-ms`, `--notchset-node-blink`, `--notchset-node-bloom`, `--notchset-node-delay`, `--notchset-plate-color`, `--notchset-rise-from`, `--notchset-rule`, `--notchset-scan-to`, `--notchset-scroll`, `--notchset-signal`, `--notchset-sweep-to`, `--notchset-travel`). Never add Tailwind colour classes inside the component.

```tsx
import { ChatApp, type ChatMessage } from "@/components/ui/notchset/blocks/chat-app";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `ChatApp` | `chat-app` | The block: rail, history, thread, composer and aside. |

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 `SoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/notchset-sound.json`, import from `@/components/ui/notchset/sound-provider`); `useSound()` gives `muted` and `setMuted` for a mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/notchset/blocks/chat-app.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
- chat app, AI chat, assistant workspace, chat history, model picker, chat with data, LLM chat UI, Notchset
- A full-page assistant over your product's data, with history and model choice
- An internal tool where answers must show what they read

### Not when
- An assistant inside another page: use Assistant Panel
- A support widget with a single thread: a smaller composer fits better

## Mistakes
- Keep the answer's status at streaming until the last token: done is what reveals copy and follow-ups
- Give the block a height (it is 660px by default) so the log, not the page, scrolls

## Usage

```tsx
"use client";

import * as React from "react";
import { ChatApp, type ChatMessage } from "@/components/ui/notchset/blocks/chat-app";

const models = [{ id: "flash", name: "ATLAS 3 FLASH", label: "Atlas 3 Flash", price: "$0.0007 / RUN", quality: 0.6, speed: 0.85 }];

export function Assistant() {
  const [messages, setMessages] = React.useState<ChatMessage[]>([]);
  const [active, setActive] = React.useState<string | null>(null);
  return (
    <ChatApp
      org="ACME LABS"
      user={{ name: "Maya Kerr", initials: "MK" }}
      threads={active ? [{ id: active, title: "New chat", group: "TODAY", time: "NOW", questions: 1 }] : []}
      activeThreadId={active}
      onNewChat={() => {
        setActive(null);
        setMessages([]);
      }}
      messages={messages}
      models={models}
      model="flash"
      contextSources={[]}
      context={[]}
      suggestions={[{ kind: "EVALS", text: "Which suites got worse?", reads: "READS 1,200 CASES" }]}
      onSend={({ text }) => {
        // Post to your API here; stream the answer into the assistant message's paragraphs.
        setActive("t1");
        setMessages((m) => [...m, { id: String(m.length), role: "user", text }, { id: `${m.length}a`, role: "assistant", status: "checking", paragraphs: [] }]);
      }}
    />
  );
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `org / user / logo` | `string / { name, initials } / ReactNode` |  | Whose workspace, who is asking, and the rail's mark. |
| `threads` | `{ id, title, group, time, questions }[]` |  | History, grouped by group in the order groups first appear. A thread that arrives after mount types its title in. |
| `activeThreadId / onSelectThread / onNewChat` | `string \| null` |  | null shows the empty state. |
| `messages` | `({ id, role: 'user', text, context? } \| { id, role: 'assistant', status, source?, paragraphs, table?, meta?, followUps? })[]` |  | The active thread. Grow paragraphs as an answer streams; status done reveals copy, meta and follow-ups. |
| `models / model / onModelChange` | `{ id, name, label, price, quality, speed }[]` |  | quality and speed are 0–1 for the meters. |
| `contextSources / context / onContextChange` | `{ id, label, detail }[] / string[]` |  | What the next message reads; chosen ones become chips in the composer. |
| `suggestions` | `{ kind, text, reads }[]` |  | The empty state's ledger; keys 1–4 pick the first four. |
| `onSend` | `({ text, model, context }) => void` |  | Called on send, a suggestion or a follow-up. |
| `usage` | `{ tokens, cost, limit, alertAt? }` |  | Today's spend in the aside; alertAt (0–1, default 0.8) is marked in signal. |
| `eyebrow / headline / placeholder` | `string` |  | The empty state's words and the composer's hint. |

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

## Customising
- Colours: the component reads your shadcn tokens (`--background`, `--foreground`, `--border` …), refined by the `--notchset-*` tokens. The signal colour is `--notchset-signal` (it falls back to `--destructive`). Set tokens on `:root`, or on any container to retheme one area.
- 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 |
|---|---|
| 1–4 | Pick a suggestion from the empty state (not while typing) |
| Enter / Shift+Enter | Send / new line (ignored while composing with an IME) |
| Esc | Close the history drawer |
| ↑ ↓ | Move between models |

## Performance

- Plain DOM; the log follows new words only while the reader is at the bottom. Nothing animates per frame.

## Responsive

- Container queries: the aside narrows to 216px under 900px and hides under 640px; under 480px the ledger drops its category column.

## Motion inventory

| Interaction | What moves |
|---|---|
| History | Slides out over the content (380ms), back in faster (260ms) |
| First send | The empty state lifts 16px and fades; the thread fades in |
| New chat in history | The row grows in and its title types itself with a block caret |
| Answer | The scanner while checking, then the words as you stream them; table and follow-ups rise in when done |
| Aside | The model dot pops (300ms); context checks draw (240ms); today's tokens roll |

## Accessibility contract (preserve when editing)
- The rail is a nav; history is a dialog that takes focus on open and returns it to the history button when closed with Esc, its close button or a chosen chat; a press outside closes it too
- The thread is a log (focusable, polite); an answer is aria-busy until it is done
- Models are a radio group with arrow keys; context sources are checkboxes; the aside is a labelled complementary region
- Suggestion keys are announced (aria-keyshortcuts 1–4); a title typing in keeps its full text for screen readers

## Install

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

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 notchset 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/notchset-foundation.json.
