|
1 | 1 | --- |
2 | 2 | name: setup |
3 | | -description: Setup and configure assistant-ui in a project. Use when installing packages, configuring runtimes, or troubleshooting setup issues. |
4 | | -version: 0.0.1 |
| 3 | +description: Setup and configure assistant-ui in a project. Use when installing packages, configuring runtimes, setting up chat UI, or troubleshooting setup issues. |
| 4 | +version: 0.1.0 |
5 | 5 | license: MIT |
6 | 6 | --- |
7 | 7 |
|
8 | 8 | # assistant-ui Setup |
9 | 9 |
|
10 | | -**Always consult [assistant-ui.com/llms.txt](https://assistant-ui.com/llms.txt) for latest API.** |
| 10 | +## CLI Commands |
11 | 11 |
|
12 | | -## References |
| 12 | +### Quick Decision Flow |
13 | 13 |
|
14 | | -- [./references/ai-sdk.md](./references/ai-sdk.md) -- AI SDK v6 setup (recommended) |
15 | | -- [./references/langgraph.md](./references/langgraph.md) -- LangGraph agent setup |
16 | | -- [./references/custom-backend.md](./references/custom-backend.md) -- useLocalRuntime / useExternalStoreRuntime |
17 | | -- [./references/ag-ui.md](./references/ag-ui.md) -- AG-UI protocol |
18 | | -- [./references/a2a.md](./references/a2a.md) -- A2A protocol |
19 | | -- [./references/styling.md](./references/styling.md) -- Styling options |
20 | | -- [./references/tanstack.md](./references/tanstack.md) -- TanStack Router |
| 14 | +- Existing Next.js app (`package.json` exists): use `npx assistant-ui@latest init` |
| 15 | +- Existing app in CI/agent/non-interactive shell: use `npx assistant-ui@latest init --yes` |
| 16 | +- Existing app + force overwrite of conflicts: add `--overwrite` |
| 17 | +- New app / empty directory: use `npx assistant-ui@latest create <name>` |
| 18 | +- Need specific starter template: add `-t <default|minimal|cloud|cloud-clerk|langgraph|mcp>` |
| 19 | +- Need a curated example: use `npx assistant-ui@latest create <name> --example <example>` |
| 20 | +- Need playground preset config: use `npx assistant-ui@latest create <name> --preset <url>` |
21 | 21 |
|
22 | | -## Pick Your Setup |
| 22 | +### New Project (`create`) |
23 | 23 |
|
| 24 | +```bash |
| 25 | +npx assistant-ui@latest create my-app -t minimal |
| 26 | +npx assistant-ui@latest create my-app -t cloud-clerk |
| 27 | +npx assistant-ui@latest create my-app --preset "https://www.assistant-ui.com/playground/init?preset=chatgpt" |
24 | 28 | ``` |
25 | | -Using Vercel AI SDK? |
26 | | -├─ Yes → useChatRuntime (recommended) |
27 | | -└─ No |
28 | | - ├─ LangGraph agents? → useLangGraphRuntime |
29 | | - ├─ AG-UI protocol? → useAgUiRuntime |
30 | | - ├─ A2A protocol? → useA2ARuntime |
31 | | - ├─ External state (Redux/Zustand)? → useExternalStoreRuntime |
32 | | - └─ Custom API → useLocalRuntime |
33 | | -``` |
34 | 29 |
|
35 | | -## Quick Start (AI SDK) |
| 30 | +Templates: |
| 31 | + |
| 32 | +| Template | Description | |
| 33 | +|-------|-------| |
| 34 | +| `default` | Default template with Vercel AI SDK | |
| 35 | +| `minimal` | Bare-bones starting point | |
| 36 | +| `cloud` | Cloud-backed persistence starter | |
| 37 | +| `cloud-clerk` | Cloud-backed starter with Clerk auth | |
| 38 | +| `langgraph` | LangGraph starter template | |
| 39 | +| `mcp` | MCP starter template | |
| 40 | + |
| 41 | +When `-t` is omitted: |
| 42 | +- Interactive shell (TTY): an interactive template picker is shown. |
| 43 | +- Non-interactive shell (CI/agent): template defaults to `default`. |
| 44 | + |
| 45 | +If no project directory is provided in a non-interactive shell, `create` uses `my-aui-app`. |
| 46 | + |
| 47 | +### Existing Next.js Project (`init`) |
36 | 48 |
|
37 | 49 | ```bash |
38 | | -npm install @assistant-ui/react @assistant-ui/react-ai-sdk @ai-sdk/react ai @ai-sdk/openai |
| 50 | +npx assistant-ui@latest init --yes |
39 | 51 | ``` |
40 | 52 |
|
41 | | -```tsx |
42 | | -// app/page.tsx |
43 | | -"use client"; |
44 | | -import { AssistantRuntimeProvider, Thread } from "@assistant-ui/react"; |
45 | | -import { useChatRuntime, AssistantChatTransport } from "@assistant-ui/react-ai-sdk"; |
46 | | - |
47 | | -export default function Chat() { |
48 | | - const runtime = useChatRuntime({ |
49 | | - transport: new AssistantChatTransport({ api: "/api/chat" }), |
50 | | - }); |
51 | | - |
52 | | - return ( |
53 | | - <AssistantRuntimeProvider runtime={runtime}> |
54 | | - <Thread /> |
55 | | - </AssistantRuntimeProvider> |
56 | | - ); |
57 | | -} |
58 | | -``` |
| 53 | +The `init` command is for **existing projects only** (requires `package.json`). |
| 54 | +If no project is found, it automatically forwards to `create`. |
| 55 | +Passing `--preset` to `init` also forwards to `create` (compatibility path). |
| 56 | + |
| 57 | +The `--yes` flag runs non-interactively (no prompts). |
59 | 58 |
|
60 | | -```ts |
61 | | -// app/api/chat/route.ts |
62 | | -import { openai } from "@ai-sdk/openai"; |
63 | | -import { streamText } from "ai"; |
| 59 | +### Add Registry Components |
64 | 60 |
|
65 | | -export async function POST(req: Request) { |
66 | | - const { messages } = await req.json(); |
67 | | - const result = streamText({ model: openai("gpt-4o"), messages }); |
68 | | - return result.toUIMessageStreamResponse(); |
69 | | -} |
| 61 | +```bash |
| 62 | +npx assistant-ui@latest add markdown-text |
| 63 | +npx assistant-ui@latest add thread-list |
70 | 64 | ``` |
71 | 65 |
|
72 | | -## Styling |
| 66 | +Registry: `https://r.assistant-ui.com/{name}.json` |
73 | 67 |
|
74 | | -```tsx |
75 | | -// Option 1: Pre-built CSS |
76 | | -import "@assistant-ui/styles/default.css"; |
| 68 | +--- |
77 | 69 |
|
78 | | -// Option 2: Tailwind (add to tailwind.config.js) |
79 | | -content: ["./node_modules/@assistant-ui/react/dist/**/*.js"] |
80 | | -``` |
| 70 | +## Template Code Policy |
81 | 71 |
|
82 | | -## Environment Variables |
| 72 | +When using CLI templates (`npx assistant-ui@latest create`), **never modify generated code** unless explicitly requested. |
83 | 73 |
|
84 | | -```env |
85 | | -OPENAI_API_KEY=sk-... |
86 | | -ANTHROPIC_API_KEY=sk-ant-... |
87 | | -NEXT_PUBLIC_ASSISTANT_BASE_URL=https://api.assistant-ui.com # For cloud |
88 | | -``` |
| 74 | +--- |
89 | 75 |
|
90 | | -## Common Gotchas |
| 76 | +## Non-Default Setups |
91 | 77 |
|
92 | | -**"Cannot find module @ai-sdk/react"** |
93 | | -```bash |
94 | | -npm install @ai-sdk/react |
95 | | -``` |
| 78 | +For runtimes other than AI SDK or frameworks other than Next.js, consult the reference files: |
| 79 | + |
| 80 | +| Setup | Runtime Hook | Reference | |
| 81 | +|-------|-------------|-----------| |
| 82 | +| AI SDK advanced (tools, cloud, options) | `useChatRuntime` | [references/ai-sdk.md](./references/ai-sdk.md) | |
| 83 | +| LangGraph agents | `useLangGraphRuntime` | [references/langgraph.md](./references/langgraph.md) | |
| 84 | +| AG-UI protocol | `useAgUiRuntime` | [references/ag-ui.md](./references/ag-ui.md) | |
| 85 | +| A2A protocol | `useA2ARuntime` | [references/a2a.md](./references/a2a.md) | |
| 86 | +| Custom streaming API | `useLocalRuntime` | [references/custom-backend.md](./references/custom-backend.md) | |
| 87 | +| Existing state (Redux/Zustand) | `useExternalStoreRuntime` | [references/custom-backend.md](./references/custom-backend.md) | |
| 88 | +| Vite / TanStack Start | — | [references/tanstack.md](./references/tanstack.md) | |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## Deprecated Packages |
| 93 | + |
| 94 | +NEVER install `@assistant-ui/styles` or `@assistant-ui/react-ui` — both are deprecated and deleted. |
| 95 | + |
| 96 | +--- |
96 | 97 |
|
97 | | -**Styles not applied** |
98 | | -- Import CSS at root level or configure Tailwind content paths |
| 98 | +## Troubleshooting |
99 | 99 |
|
100 | | -**Streaming not working** |
101 | | -- Use `toUIMessageStreamResponse()` in API route |
102 | | -- Check for CORS errors in console |
| 100 | +For issues not covered by the reference files, use the docs website: |
103 | 101 |
|
104 | | -**"runtime is undefined"** |
105 | | -- Call `useChatRuntime` inside a component, not at module level |
| 102 | +1. **Fetch the index**: `https://www.assistant-ui.com/llms.txt` — compact table of contents |
| 103 | +2. **Fetch specific pages**: Append `.mdx` to the docs URL, e.g. `https://www.assistant-ui.com/docs/runtimes/ai-sdk.mdx` |
0 commit comments