craftllm1.0b 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/assistant-ui/SKILL.md +166 -0
- package/.agents/skills/assistant-ui/references/architecture.md +143 -0
- package/.agents/skills/assistant-ui/references/packages.md +93 -0
- package/.agents/skills/cloud/SKILL.md +230 -0
- package/.agents/skills/cloud/references/auth-integrations.md +306 -0
- package/.agents/skills/cloud/references/authorization.md +178 -0
- package/.agents/skills/cloud/references/custom-persistence.md +108 -0
- package/.agents/skills/cloud/references/persistence.md +148 -0
- package/.agents/skills/copilots/SKILL.md +123 -0
- package/.agents/skills/copilots/references/assistant-frame.md +145 -0
- package/.agents/skills/copilots/references/instructions.md +96 -0
- package/.agents/skills/copilots/references/interactables.md +310 -0
- package/.agents/skills/copilots/references/model-context.md +216 -0
- package/.agents/skills/copilots/references/visible.md +140 -0
- package/.agents/skills/elements/SKILL.md +141 -0
- package/.agents/skills/elements/references/aui-elements.md +648 -0
- package/.agents/skills/elements/references/catalog.md +123 -0
- package/.agents/skills/elements/references/standalone-elements.md +1816 -0
- package/.agents/skills/generative-ui/SKILL.md +177 -0
- package/.agents/skills/generative-ui/references/a2ui-openui.md +159 -0
- package/.agents/skills/generative-ui/references/actions.md +79 -0
- package/.agents/skills/generative-ui/references/renderers.md +350 -0
- package/.agents/skills/generative-ui/references/tokens.md +101 -0
- package/.agents/skills/generative-ui/references/vocabulary.md +137 -0
- package/.agents/skills/ink/SKILL.md +181 -0
- package/.agents/skills/ink/references/adapters.md +70 -0
- package/.agents/skills/ink/references/custom-backend.md +84 -0
- package/.agents/skills/ink/references/hooks.md +108 -0
- package/.agents/skills/ink/references/migration.md +69 -0
- package/.agents/skills/ink/references/primitives.md +130 -0
- package/.agents/skills/markdown/SKILL.md +128 -0
- package/.agents/skills/markdown/references/latex-mermaid.md +102 -0
- package/.agents/skills/markdown/references/markdown-text.md +107 -0
- package/.agents/skills/markdown/references/streamdown.md +115 -0
- package/.agents/skills/markdown/references/syntax-highlighting.md +101 -0
- package/.agents/skills/observability/SKILL.md +93 -0
- package/.agents/skills/observability/references/helicone.md +76 -0
- package/.agents/skills/observability/references/langfuse.md +95 -0
- package/.agents/skills/observability/references/langsmith.md +79 -0
- package/.agents/skills/observability/references/react-o11y.md +140 -0
- package/.agents/skills/primitives/SKILL.md +295 -0
- package/.agents/skills/primitives/references/action-bar.md +130 -0
- package/.agents/skills/primitives/references/composer-input.md +238 -0
- package/.agents/skills/primitives/references/composer.md +165 -0
- package/.agents/skills/primitives/references/mentions.md +256 -0
- package/.agents/skills/primitives/references/message.md +188 -0
- package/.agents/skills/primitives/references/messages.md +226 -0
- package/.agents/skills/primitives/references/part-grouping.md +181 -0
- package/.agents/skills/primitives/references/suggestions.md +133 -0
- package/.agents/skills/primitives/references/thread.md +186 -0
- package/.agents/skills/react-mcp/SKILL.md +212 -0
- package/.agents/skills/react-mcp/references/oauth.md +106 -0
- package/.agents/skills/react-mcp/references/setup.md +185 -0
- package/.agents/skills/react-mcp/references/ui.md +151 -0
- package/.agents/skills/react-native/SKILL.md +228 -0
- package/.agents/skills/react-native/references/adapters.md +78 -0
- package/.agents/skills/react-native/references/custom-backend.md +138 -0
- package/.agents/skills/react-native/references/hooks.md +132 -0
- package/.agents/skills/react-native/references/migration.md +94 -0
- package/.agents/skills/react-native/references/primitives.md +146 -0
- package/.agents/skills/runtime/SKILL.md +205 -0
- package/.agents/skills/runtime/references/adapters.md +343 -0
- package/.agents/skills/runtime/references/external-store.md +315 -0
- package/.agents/skills/runtime/references/local-runtime.md +331 -0
- package/.agents/skills/runtime/references/runtime-concepts.md +220 -0
- package/.agents/skills/runtime/references/state-hooks.md +286 -0
- package/.agents/skills/runtime/references/types.md +191 -0
- package/.agents/skills/runtime/references/voice.md +332 -0
- package/.agents/skills/setup/SKILL.md +197 -0
- package/.agents/skills/setup/references/a2a.md +127 -0
- package/.agents/skills/setup/references/ag-ui.md +136 -0
- package/.agents/skills/setup/references/ai-sdk-legacy.md +158 -0
- package/.agents/skills/setup/references/ai-sdk.md +339 -0
- package/.agents/skills/setup/references/claude-managed-agents.md +82 -0
- package/.agents/skills/setup/references/cloudflare-agents.md +111 -0
- package/.agents/skills/setup/references/custom-backend.md +117 -0
- package/.agents/skills/setup/references/devtools.md +50 -0
- package/.agents/skills/setup/references/eve.md +110 -0
- package/.agents/skills/setup/references/google-adk.md +187 -0
- package/.agents/skills/setup/references/langchain.md +143 -0
- package/.agents/skills/setup/references/langgraph.md +187 -0
- package/.agents/skills/setup/references/mastra.md +112 -0
- package/.agents/skills/setup/references/opencode.md +92 -0
- package/.agents/skills/setup/references/providers.md +92 -0
- package/.agents/skills/setup/references/tanstack.md +57 -0
- package/.agents/skills/streaming/SKILL.md +152 -0
- package/.agents/skills/streaming/references/assistant-transport.md +241 -0
- package/.agents/skills/streaming/references/data-stream.md +200 -0
- package/.agents/skills/streaming/references/encoders.md +106 -0
- package/.agents/skills/streaming/references/resumable.md +243 -0
- package/.agents/skills/thread-list/SKILL.md +226 -0
- package/.agents/skills/thread-list/references/custom-ui.md +176 -0
- package/.agents/skills/thread-list/references/management.md +212 -0
- package/.agents/skills/thread-list/references/remote-adapter.md +179 -0
- package/.agents/skills/tools/SKILL.md +259 -0
- package/.agents/skills/tools/references/human-in-loop.md +214 -0
- package/.agents/skills/tools/references/legacy-component-apis.md +160 -0
- package/.agents/skills/tools/references/mcp-apps.md +206 -0
- package/.agents/skills/tools/references/mcp-server.md +214 -0
- package/.agents/skills/tools/references/multi-agent.md +112 -0
- package/.agents/skills/tools/references/tool-ui.md +253 -0
- package/.agents/skills/tools/references/toolkits.md +350 -0
- package/.agents/skills/tools/references/webmcp.md +75 -0
- package/.agents/skills/update/SKILL.md +215 -0
- package/.agents/skills/update/references/ai-sdk.md +142 -0
- package/.agents/skills/update/references/assistant-ui.md +289 -0
- package/.agents/skills/update/references/breaking-changes.md +60 -0
- package/.env.example +7 -0
- package/.oxfmtrc.json +32 -0
- package/README.md +22 -2
- package/app/api/chat/route.ts +59 -0
- package/app/api/request-context.ts +16 -0
- package/app/assistant.tsx +110 -0
- package/app/favicon.ico +0 -0
- package/app/globals.css +254 -0
- package/app/layout.tsx +35 -0
- package/app/page.tsx +5 -0
- package/components/attachment-state.ts +59 -0
- package/components/attachment.aui.tsx +246 -0
- package/components/collapsible-root.tsx +19 -0
- package/components/file.tsx +426 -0
- package/components/follow-up-suggestions.aui.tsx +82 -0
- package/components/github.tsx +12 -0
- package/components/href.ts +123 -0
- package/components/image.tsx +681 -0
- package/components/markdown-text.tsx +279 -0
- package/components/media-player.tsx +375 -0
- package/components/reasoning.aui.tsx +126 -0
- package/components/reasoning.tsx +341 -0
- package/components/surfaces.tsx +122 -0
- package/components/thread-activity-heat-graph.tsx +93 -0
- package/components/thread-list.aui.tsx +499 -0
- package/components/thread.aui.tsx +1032 -0
- package/components/threadlist-sidebar.aui.tsx +75 -0
- package/components/tool-fallback.aui.tsx +1336 -0
- package/components/tool-group.aui.tsx +231 -0
- package/components/tooltip-icon-button.tsx +49 -0
- package/components/ui/avatar.tsx +108 -0
- package/components/ui/breadcrumb.tsx +121 -0
- package/components/ui/button.tsx +57 -0
- package/components/ui/dialog.tsx +156 -0
- package/components/ui/input.tsx +19 -0
- package/components/ui/separator.tsx +24 -0
- package/components/ui/sheet.tsx +134 -0
- package/components/ui/sidebar.tsx +723 -0
- package/components/ui/skeleton.tsx +13 -0
- package/components/ui/textarea.tsx +17 -0
- package/components/ui/tooltip.tsx +65 -0
- package/components/useIsomorphicLayoutEffect.ts +9 -0
- package/components.json +24 -0
- package/hooks/use-attachment-src.ts +46 -0
- package/hooks/use-copy-to-clipboard.ts +54 -0
- package/hooks/use-mobile.ts +21 -0
- package/lib/utils.ts +1 -0
- package/lib/web-search.ts +153 -0
- package/next.config.ts +6 -0
- package/package.json +42 -4
- package/postcss.config.mjs +5 -0
- package/public/craftllm-logo.svg +13 -0
- package/public/go-pro-cart.svg +6 -0
- package/skills-lock.json +107 -0
- package/tsconfig.json +33 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: assistant-ui
|
|
3
|
+
description: "Overview and router for assistant-ui, the React library for building AI chat interfaces from composable primitives and a styled elements catalog. Use for high-level, cross-cutting, or architecture questions: choosing packages, picking a runtime, or understanding the layers (elements, primitives, the aui client with AuiConfig and AuiProvider, the runtime, adapters) and the message model. Covers `@assistant-ui/react` 0.15.x, `@assistant-ui/ai-sdk` for AI SDK v7 (`useChatRuntime`), `@assistant-ui/core`, `@assistant-ui/store`, `assistant-stream`, `assistant-cloud`, the LangGraph, LangChain, Google ADK, A2A, AG-UI, Eve, OpenCode, and Pi adapters, the `@assistant-ui/react-native` and `@assistant-ui/react-ink` bindings, and the `useAui`, `useAuiState`, and `useAuiEvent` hooks. For a specific area route to a focused sibling instead: setup, elements, primitives, runtime, tools, generative-ui, streaming, cloud, thread-list, copilots, markdown, react-mcp, observability, react-native, ink, or update."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# assistant-ui
|
|
8
|
+
|
|
9
|
+
**Always consult [assistant-ui.com/llms.txt](https://www.assistant-ui.com/llms.txt) for the latest API.**
|
|
10
|
+
|
|
11
|
+
React library for AI chat interfaces: unstyled primitives, a styled elements catalog, a runtime that adapts any backend, and optional cloud persistence. Current line is `@assistant-ui/react` 0.15.x on AI SDK v7 through `@assistant-ui/ai-sdk`.
|
|
12
|
+
|
|
13
|
+
## References
|
|
14
|
+
|
|
15
|
+
- [./references/architecture.md](./references/architecture.md) -- layers, the aui client, data flow, message model
|
|
16
|
+
- [./references/packages.md](./references/packages.md) -- every published package and when to install it
|
|
17
|
+
|
|
18
|
+
## When to Use
|
|
19
|
+
|
|
20
|
+
| Use Case | Reach for |
|
|
21
|
+
|----------|-----------|
|
|
22
|
+
| Chat UI in an afternoon | `npx assistant-ui@latest create`, then the `thread` element |
|
|
23
|
+
| Full control over markup | Primitives (`ThreadPrimitive`, `ComposerPrimitive`, `MessagePrimitive`) |
|
|
24
|
+
| Existing AI backend | A runtime adapter (AI SDK, LangGraph, LangChain, ADK, A2A, AG-UI, Eve, OpenCode) or `useLocalRuntime` |
|
|
25
|
+
| Tools with UI | `"use generative"` toolkits, tool UI, generative UI |
|
|
26
|
+
| Multi-thread apps | Thread list elements plus Assistant Cloud or your own adapter |
|
|
27
|
+
| Copilots in an app | Instructions, context, visible components, interactables |
|
|
28
|
+
| Mobile or terminal | `@assistant-ui/react-native`, `@assistant-ui/react-ink` |
|
|
29
|
+
|
|
30
|
+
## Architecture
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
34
|
+
│ Elements (styled, copied into components/assistant-ui/) │
|
|
35
|
+
│ Primitives (unstyled, @assistant-ui/react) │
|
|
36
|
+
└───────────────────────────┬──────────────────────────────────┘
|
|
37
|
+
│ read state, call actions
|
|
38
|
+
┌───────────────────────────▼──────────────────────────────────┐
|
|
39
|
+
│ aui client: useAui, useAuiState, useAuiEvent, AuiIf │
|
|
40
|
+
│ scopes provided by AuiConfig through AssistantRuntimeProvider│
|
|
41
|
+
│ or AuiProvider (@assistant-ui/store on @assistant-ui/tap) │
|
|
42
|
+
└───────────────────────────┬──────────────────────────────────┘
|
|
43
|
+
│
|
|
44
|
+
┌───────────────────────────▼──────────────────────────────────┐
|
|
45
|
+
│ Runtime: AssistantRuntime → ThreadRuntime → MessageRuntime │
|
|
46
|
+
│ (@assistant-ui/core, framework neutral) │
|
|
47
|
+
└───────────────────────────┬──────────────────────────────────┘
|
|
48
|
+
│
|
|
49
|
+
┌───────────────────────────▼──────────────────────────────────┐
|
|
50
|
+
│ Adapters and backends: AI SDK · LangGraph · LangChain · ADK │
|
|
51
|
+
│ A2A · AG-UI · Eve · OpenCode · custom · Assistant Cloud │
|
|
52
|
+
└──────────────────────────────────────────────────────────────┘
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Pick a Runtime
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
Vercel AI SDK?
|
|
59
|
+
├─ Yes → useChatRuntime from @assistant-ui/ai-sdk (recommended)
|
|
60
|
+
└─ No
|
|
61
|
+
├─ LangGraph server → useLangGraphRuntime (@assistant-ui/react-langgraph)
|
|
62
|
+
├─ LangChain / LangGraph useStream → useStreamRuntime (@assistant-ui/react-langchain)
|
|
63
|
+
├─ Google ADK → useAdkRuntime (@assistant-ui/react-google-adk)
|
|
64
|
+
├─ A2A protocol → useA2ARuntime (@assistant-ui/react-a2a)
|
|
65
|
+
├─ AG-UI protocol → useAgUiRuntime (@assistant-ui/react-ag-ui)
|
|
66
|
+
├─ Eve agents → useEveAgentRuntime (@assistant-ui/eve)
|
|
67
|
+
├─ OpenCode → useOpenCodeRuntime (@assistant-ui/react-opencode)
|
|
68
|
+
├─ Claude Managed Agents → useExternalStoreRuntime + useRemoteThreadListRuntime
|
|
69
|
+
├─ State already in Redux/Zustand/your store → useExternalStoreRuntime
|
|
70
|
+
├─ Custom endpoint speaking Assistant Transport → useAssistantTransportRuntime
|
|
71
|
+
└─ Any other custom API → useLocalRuntime with a ChatModelAdapter
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Core Packages
|
|
75
|
+
|
|
76
|
+
| Package | Purpose |
|
|
77
|
+
|---------|---------|
|
|
78
|
+
| `@assistant-ui/react` | Primitives, hooks, runtimes, provider |
|
|
79
|
+
| `@assistant-ui/ai-sdk` | AI SDK v7 integration (`useChatRuntime`, `AssistantChatTransport`, `AISDKToolkit`, `frontendTools`) |
|
|
80
|
+
| `@assistant-ui/core` | Framework-neutral runtime shared by React, React Native, Ink |
|
|
81
|
+
| `@assistant-ui/store` | `AuiConfig`, `AuiProvider`, `useAui` state layer |
|
|
82
|
+
| `@assistant-ui/react-markdown` | Markdown rendering (`MarkdownTextPrimitive`) |
|
|
83
|
+
| `assistant-stream` | Streaming protocol, encoders, resumable streams |
|
|
84
|
+
| `assistant-cloud` | Assistant Cloud client |
|
|
85
|
+
| `assistant-ui` | The CLI (`create`, `init`, `add`, `update`, `upgrade`, `doctor`, `mcp`, `agent`) |
|
|
86
|
+
|
|
87
|
+
`@assistant-ui/react-ai-sdk` re-exports `@assistant-ui/ai-sdk` for older installs; new code imports from `@assistant-ui/ai-sdk`. Styled components are not a package: `npx assistant-ui@latest add thread` copies them into `components/assistant-ui/elements/`. See [./references/packages.md](./references/packages.md) for the full inventory.
|
|
88
|
+
|
|
89
|
+
## Quick Start
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
"use client";
|
|
93
|
+
|
|
94
|
+
import { AssistantRuntimeProvider } from "@assistant-ui/react";
|
|
95
|
+
import { useChatRuntime } from "@assistant-ui/ai-sdk";
|
|
96
|
+
import { Thread } from "@/components/assistant-ui/elements/thread.aui";
|
|
97
|
+
|
|
98
|
+
export default function Chat() {
|
|
99
|
+
const runtime = useChatRuntime();
|
|
100
|
+
return (
|
|
101
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
102
|
+
<Thread />
|
|
103
|
+
</AssistantRuntimeProvider>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`useChatRuntime()` posts to `/api/chat` through `AssistantChatTransport`, which also forwards frontend tools and system instructions. Pass `new AssistantChatTransport({ api })` to change the endpoint.
|
|
109
|
+
|
|
110
|
+
## State Access
|
|
111
|
+
|
|
112
|
+
Scope accessors on `aui` are properties; methods on a scope keep their parentheses. Selectors return one primitive or stable reference each.
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import { useAui, useAuiState, useAuiEvent } from "@assistant-ui/react";
|
|
116
|
+
|
|
117
|
+
const aui = useAui();
|
|
118
|
+
aui.thread.append({ role: "user", content: [{ type: "text", text: "Hi" }] });
|
|
119
|
+
aui.thread.cancelRun();
|
|
120
|
+
aui.thread.composer().send();
|
|
121
|
+
aui.threads.switchToNewThread();
|
|
122
|
+
|
|
123
|
+
const messages = useAuiState((s) => s.thread.messages);
|
|
124
|
+
const isRunning = useAuiState((s) => s.thread.isRunning);
|
|
125
|
+
|
|
126
|
+
useAuiEvent("threads.selectionChanged", ({ threadId, previousThreadId }) => {});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Providing Scopes
|
|
130
|
+
|
|
131
|
+
Tools, suggestions, interactables, MCP managers, and other scopes are declared with `AuiConfig` and handed to the provider; `useAui()` takes no arguments.
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import { AssistantRuntimeProvider, AuiConfig, Suggestions, Tools } from "@assistant-ui/react";
|
|
135
|
+
import { useChatRuntime } from "@assistant-ui/ai-sdk";
|
|
136
|
+
import toolkit from "./toolkit";
|
|
137
|
+
|
|
138
|
+
const runtime = useChatRuntime();
|
|
139
|
+
const config = AuiConfig({
|
|
140
|
+
tools: Tools({ toolkit }),
|
|
141
|
+
suggestions: Suggestions(["What can you do?", "Summarize this page"]),
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
<AssistantRuntimeProvider runtime={runtime} config={config}>{children}</AssistantRuntimeProvider>;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Nested scopes use `<AuiProvider extends={useAui()} config={config}>`; an isolated root uses `extends={null}`.
|
|
148
|
+
|
|
149
|
+
## Related Skills
|
|
150
|
+
|
|
151
|
+
- [setup](../setup/SKILL.md) -- CLI, templates, runtime adapters, platforms
|
|
152
|
+
- [elements](../elements/SKILL.md) -- the styled component catalog and how to install and override it
|
|
153
|
+
- [primitives](../primitives/SKILL.md) -- unstyled building blocks and composer features
|
|
154
|
+
- [runtime](../runtime/SKILL.md) -- runtimes, the aui client, adapters, events
|
|
155
|
+
- [tools](../tools/SKILL.md) -- toolkits, tool UI, approvals, MCP, WebMCP
|
|
156
|
+
- [generative-ui](../generative-ui/SKILL.md) -- the `present` tool and component vocabularies
|
|
157
|
+
- [streaming](../streaming/SKILL.md) -- assistant-stream, transports, resumable streams
|
|
158
|
+
- [cloud](../cloud/SKILL.md) -- Assistant Cloud persistence and auth
|
|
159
|
+
- [thread-list](../thread-list/SKILL.md) -- multi-thread management
|
|
160
|
+
- [copilots](../copilots/SKILL.md) -- grounding the assistant in your app
|
|
161
|
+
- [markdown](../markdown/SKILL.md) -- markdown, code, math, diagrams
|
|
162
|
+
- [react-mcp](../react-mcp/SKILL.md) -- user-managed MCP servers
|
|
163
|
+
- [observability](../observability/SKILL.md) -- tracing and span visualization
|
|
164
|
+
- [react-native](../react-native/SKILL.md) -- Expo and React Native
|
|
165
|
+
- [ink](../ink/SKILL.md) -- terminal chat with Ink
|
|
166
|
+
- [update](../update/SKILL.md) -- upgrades and migrations
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# assistant-ui Architecture
|
|
2
|
+
|
|
3
|
+
## Layers
|
|
4
|
+
|
|
5
|
+
Each layer depends only on the layers below it.
|
|
6
|
+
|
|
7
|
+
### UI: elements and primitives
|
|
8
|
+
|
|
9
|
+
Primitives from `@assistant-ui/react` are unstyled, Radix-style parts (`ThreadPrimitive.Root`, `ComposerPrimitive.Input`, `MessagePrimitive.Parts`, ...) that read and write through the aui client, never against the backend directly. Elements are styled compositions of those primitives that the CLI copies into `components/assistant-ui/elements/`; runtime-connected ones carry the `.aui.tsx` suffix and standalone ones take props.
|
|
10
|
+
|
|
11
|
+
### The aui client
|
|
12
|
+
|
|
13
|
+
`useAui()` returns an `AssistantClient`: one property accessor per registered scope plus `subscribe` and `on`. Application code uses it instead of the runtime object.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { useAui, useAuiState, useAuiEvent } from "@assistant-ui/react";
|
|
17
|
+
|
|
18
|
+
const aui = useAui();
|
|
19
|
+
aui.thread.append({ role: "user", content: [{ type: "text", text: "Hi" }] });
|
|
20
|
+
aui.thread.message({ index: 0 }).reload();
|
|
21
|
+
aui.thread.composer().send();
|
|
22
|
+
aui.threads.switchToNewThread();
|
|
23
|
+
|
|
24
|
+
const messages = useAuiState((s) => s.thread.messages);
|
|
25
|
+
useAuiEvent("threads.selectionChanged", ({ threadId, previousThreadId }) => {});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Scopes: `threads`, `threadListItem`, `thread`, `message`, `part`, `composer`, `attachment`, `modelContext`, `suggestions`, `suggestion`, `chainOfThought`, `queueItem`, `tools`, `dataRenderers`, `unstable_interactables`, plus package scopes such as `mcp` and `span`.
|
|
29
|
+
|
|
30
|
+
An unavailable scope never throws at selection: `aui.thread` is always truthy, its `source` is `null`, and any other read throws. Guard with `aui.thread.source != null` or select through `s.optional.thread`.
|
|
31
|
+
|
|
32
|
+
Scopes are declared with `AuiConfig` and mounted by a provider. `AssistantRuntimeProvider` installs an `AuiProvider` for the runtime's `threads` scope and merges anything you pass as `config`; nested subtrees add scopes with `<AuiProvider extends={aui} config={config}>`; `extends={null}` starts an isolated root. Configs are plain data and identity-insensitive.
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { AssistantRuntimeProvider, AuiConfig, Tools } from "@assistant-ui/react";
|
|
36
|
+
|
|
37
|
+
const config = AuiConfig({ tools: Tools({ toolkit }) });
|
|
38
|
+
<AssistantRuntimeProvider runtime={runtime} config={config}>{children}</AssistantRuntimeProvider>;
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Runtime
|
|
42
|
+
|
|
43
|
+
The object a runtime hook returns and the provider mounts. `thread` and `threads` are properties.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
type AssistantRuntime = {
|
|
47
|
+
readonly thread: ThreadRuntime;
|
|
48
|
+
readonly threads: ThreadListRuntime;
|
|
49
|
+
registerModelContextProvider(provider: ModelContextProvider): Unsubscribe;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type ThreadRuntime = {
|
|
53
|
+
readonly composer: ThreadComposerRuntime;
|
|
54
|
+
getState(): ThreadState;
|
|
55
|
+
append(message: CreateAppendMessage): void;
|
|
56
|
+
startRun(config: CreateStartRunConfig): void;
|
|
57
|
+
resumeRun(config: CreateResumeRunConfig): void;
|
|
58
|
+
cancelRun(): void;
|
|
59
|
+
getMessageByIndex(idx: number): MessageRuntime;
|
|
60
|
+
getMessageById(messageId: string): MessageRuntime;
|
|
61
|
+
subscribe(callback: () => void): Unsubscribe;
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`LocalRuntime` keeps conversation state inside assistant-ui and drives a `ChatModelAdapter`; every framework adapter (AI SDK, LangGraph, ADK, A2A, ...) builds on it. `ExternalStoreRuntime` delegates state to your store and calls your callbacks (`onNew`, `onEdit`, `onReload`, `onCancel`, `onRespondToToolApproval`). The runtime is framework neutral (`@assistant-ui/core`), which is why React Native and Ink share it.
|
|
66
|
+
|
|
67
|
+
### Adapters, protocols, persistence
|
|
68
|
+
|
|
69
|
+
Runtime adapters translate a backend's wire shape (AI SDK UI message stream, LangGraph events, ADK sessions, AG-UI events, A2A tasks) into thread state. Two generic protocols avoid a bespoke adapter: the AI SDK data stream and Assistant Transport (`assistant-stream`). Persistence is a separate seam: Assistant Cloud or your own `ThreadHistoryAdapter` and `RemoteThreadListAdapter`.
|
|
70
|
+
|
|
71
|
+
## Data flow
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
User action (send)
|
|
75
|
+
→ primitive calls aui.thread.composer().send()
|
|
76
|
+
→ runtime appends the message and starts a run
|
|
77
|
+
→ adapter streams parts from the backend into thread state
|
|
78
|
+
→ subscribers notified, primitives and elements re-render
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Message model
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
type ThreadMessage = ThreadUserMessage | ThreadAssistantMessage | ThreadSystemMessage;
|
|
85
|
+
|
|
86
|
+
type ThreadUserMessage = {
|
|
87
|
+
id: string;
|
|
88
|
+
role: "user";
|
|
89
|
+
content: readonly ThreadUserMessagePart[];
|
|
90
|
+
attachments: readonly CompleteAttachment[];
|
|
91
|
+
metadata: { custom: Record<string, unknown>; isOptimistic?: boolean };
|
|
92
|
+
createdAt: Date;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
type ThreadAssistantMessage = {
|
|
96
|
+
id: string;
|
|
97
|
+
role: "assistant";
|
|
98
|
+
content: readonly ThreadAssistantMessagePart[];
|
|
99
|
+
status: MessageStatus;
|
|
100
|
+
metadata: {
|
|
101
|
+
steps: readonly ThreadStep[];
|
|
102
|
+
submittedFeedback?: { type: "positive" | "negative" };
|
|
103
|
+
timing?: MessageTiming;
|
|
104
|
+
custom: Record<string, unknown>;
|
|
105
|
+
};
|
|
106
|
+
createdAt: Date;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
type MessageStatus =
|
|
110
|
+
| { type: "running" }
|
|
111
|
+
| { type: "requires-action"; reason: "interrupt" | "tool-calls" }
|
|
112
|
+
| { type: "complete"; reason: "stop" | "unknown" }
|
|
113
|
+
| { type: "incomplete"; reason: "cancelled" | "content-filter" | "error" | "length" | "other" | "tool-calls"; error?: ReadonlyJSONValue };
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`status` is an object; branch on `status.type`. The two roles carry different part unions:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
type ThreadUserMessagePart = TextMessagePart | ImageMessagePart | FileMessagePart | DataMessagePart | Unstable_AudioMessagePart;
|
|
120
|
+
|
|
121
|
+
type ThreadAssistantMessagePart =
|
|
122
|
+
| TextMessagePart // { type: "text"; text }
|
|
123
|
+
| ReasoningMessagePart // { type: "reasoning"; text }
|
|
124
|
+
| ToolCallMessagePart // { type: "tool-call"; toolCallId; toolName; args; argsText; result?; isError?; artifact?; approval?; messages? }
|
|
125
|
+
| SourceMessagePart // { type: "source"; sourceType: "url"; id; url; title? }
|
|
126
|
+
| FileMessagePart // { type: "file"; data; mimeType; filename? }
|
|
127
|
+
| ImageMessagePart // { type: "image"; image; filename? }
|
|
128
|
+
| DataMessagePart // { type: "data"; name; data }
|
|
129
|
+
| GenerativeUIMessagePart; // { type: "generative-ui"; spec }
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
In UI code you read `MessageState`: the message plus `parentId`, `index`, `isLast`, `branchNumber`, `branchCount`, `parts` (part data with per-part status), `composer` (the edit composer), `isCopied`, and `isHovering`. Metadata a backend attaches outside the fixed shape lands under `metadata.custom`.
|
|
133
|
+
|
|
134
|
+
## Branching
|
|
135
|
+
|
|
136
|
+
Messages form a tree. Editing or reloading creates a sibling branch; `BranchPickerPrimitive` and `aui.message.switchToBranch({ position })` move between them.
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
User: "Hello"
|
|
140
|
+
└─ Assistant: "Hi there!"
|
|
141
|
+
├─ User: "Tell me a joke" → Assistant: "Why did..." (current)
|
|
142
|
+
└─ User: "Tell me a fact" → Assistant: "The sun..." (edit)
|
|
143
|
+
```
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# assistant-ui Packages
|
|
2
|
+
|
|
3
|
+
Check the current version with `npm view <package> version`. Every published package exposes only the `latest` dist-tag, so install from `latest`. Monorepo-only packages (`@assistant-ui/ui`, `@assistant-ui/x-*`, `@assistant-ui/vue`, `@assistant-ui/svelte`) are not on npm; `@assistant-ui/ui` is the source of the elements catalog that the CLI copies into your project.
|
|
4
|
+
|
|
5
|
+
## Core
|
|
6
|
+
|
|
7
|
+
| Package | Notes |
|
|
8
|
+
|---------|-------|
|
|
9
|
+
| `@assistant-ui/react` | Primitives, hooks, runtimes, `AssistantRuntimeProvider`, toolkit authoring; 0.15.x |
|
|
10
|
+
| `@assistant-ui/core` | Framework-neutral runtime, adapters, and store entries shared by every binding |
|
|
11
|
+
| `@assistant-ui/store` | `AuiConfig`, `AuiProvider`, `useAui`, `useAuiState`, `useAuiEvent`, `Derived` |
|
|
12
|
+
| `@assistant-ui/tap` | Reactive resources behind the store (`withKey`, `createTapRoot`) |
|
|
13
|
+
| `assistant-stream` | Streaming protocol, encoders and decoders, `assistant-stream/resumable` |
|
|
14
|
+
| `assistant-cloud` | Assistant Cloud client (`AssistantCloud`, persistence helpers, run telemetry) |
|
|
15
|
+
| `assistant-ui` | The CLI: `create`, `init`, `add`, `update`, `upgrade`, `codemod`, `doctor`, `info`, `mcp`, `agent` |
|
|
16
|
+
| `create-assistant-ui` | `npm create assistant-ui` entry point |
|
|
17
|
+
|
|
18
|
+
## Backend adapters
|
|
19
|
+
|
|
20
|
+
| Package | Hook | Notes |
|
|
21
|
+
|---------|------|-------|
|
|
22
|
+
| `@assistant-ui/ai-sdk` | `useChatRuntime`, `useAISDKRuntime` | AI SDK v7 (`ai@^7`, `@ai-sdk/react@^4`); also `AISDKChat`, `AISDKThreads`, `AISDKToolkit`, `frontendTools`, `injectQuoteContext`, `useThreadTokenUsage`, resumable stream helpers |
|
|
23
|
+
| `@assistant-ui/react-ai-sdk` | same | Re-exports `@assistant-ui/ai-sdk`; keep it only in existing installs |
|
|
24
|
+
| `@assistant-ui/react-langgraph` | `useLangGraphRuntime` | LangGraph server streaming, interrupts, agent state, `ui_message` generative UI |
|
|
25
|
+
| `@assistant-ui/react-langchain` | `useStreamRuntime` | LangChain `useStream` adapter, subgraphs and subagents; the `langchain` CLI template |
|
|
26
|
+
| `@assistant-ui/react-google-adk` | `useAdkRuntime` | Google ADK sessions, tool confirmations, auth requests |
|
|
27
|
+
| `@assistant-ui/react-a2a` | `useA2ARuntime` | Agent-to-Agent protocol, tasks and artifacts |
|
|
28
|
+
| `@assistant-ui/react-ag-ui` | `useAgUiRuntime` | AG-UI protocol, shared state, interrupts, subagent lifecycle, A2UI actions |
|
|
29
|
+
| `@assistant-ui/eve` | `useEveAgentRuntime` | Eve agents; the `eve` CLI template |
|
|
30
|
+
| `@assistant-ui/react-opencode` | `useOpenCodeRuntime` | OpenCode sessions, permissions, questions |
|
|
31
|
+
| `@assistant-ui/react-pi` | `usePiRuntime` | Pi coding agent sessions |
|
|
32
|
+
| `@assistant-ui/react-data-stream` | `useDataStreamRuntime` | AI SDK v4 data stream protocol (legacy) |
|
|
33
|
+
| `@assistant-ui/cloud-ai-sdk` | Deprecated | Use the `cloud` option of `useChatRuntime` or `AISDKThreads({ cloud })`; see [Migrate from Cloud AI SDK](https://www.assistant-ui.com/docs/cloud/migrate-cloud-ai-sdk) |
|
|
34
|
+
|
|
35
|
+
Claude Managed Agents, Mastra, Cloudflare Agents, and AI gateways need no adapter package; see the setup skill.
|
|
36
|
+
|
|
37
|
+
## Platform bindings and build plugins
|
|
38
|
+
|
|
39
|
+
| Package | Notes |
|
|
40
|
+
|---------|-------|
|
|
41
|
+
| `@assistant-ui/react-native` | Expo and React Native primitives, hooks, and runtimes |
|
|
42
|
+
| `@assistant-ui/react-ink` | Terminal (Ink) primitives, hooks, and runtimes |
|
|
43
|
+
| `@assistant-ui/react-ink-markdown` | Markdown rendering for the terminal |
|
|
44
|
+
| `@assistant-ui/next` | `withAui()` Next.js config wrapper for `"use generative"` |
|
|
45
|
+
| `@assistant-ui/vite` | `aui()` Vite plugin for `"use generative"` |
|
|
46
|
+
| `@assistant-ui/metro` | `withAui()` Metro config wrapper for `"use generative"` |
|
|
47
|
+
|
|
48
|
+
## Rendering
|
|
49
|
+
|
|
50
|
+
| Package | Notes |
|
|
51
|
+
|---------|-------|
|
|
52
|
+
| `@assistant-ui/react-markdown` | `MarkdownTextPrimitive`, math delimiter helpers, `unstable_memoizeMarkdownComponents` |
|
|
53
|
+
| `@assistant-ui/react-streamdown` | `StreamdownTextPrimitive` with built-in Shiki, KaTeX, Mermaid, block streaming |
|
|
54
|
+
| `@assistant-ui/react-syntax-highlighter` | Prism-based highlighter adapters |
|
|
55
|
+
| `@assistant-ui/generative-ui` | React-free tree types and tokens; `/react` exports `JSONGenerativeUI` and the default component vocabulary; `/slack`, `/teams`, and `/a2ui` export converters |
|
|
56
|
+
| `@assistant-ui/react-lexical` | Lexical composer input with directive chips (mentions, slash commands) |
|
|
57
|
+
| `@assistant-ui/react-hook-form` | `useAssistantForm` for React Hook Form |
|
|
58
|
+
| `safe-content-frame` | Sandboxed iframe for untrusted HTML (used by MCP Apps and artifacts) |
|
|
59
|
+
| `heat-graph` | Headless activity heatmap |
|
|
60
|
+
| `tw-shimmer` | Tailwind v4 shimmer plugin used by the elements |
|
|
61
|
+
| `tw-glass` | Tailwind v4 glass refraction plugin |
|
|
62
|
+
|
|
63
|
+
Existing imports from `@assistant-ui/react-generative-ui` keep working because that shell re-exports `@assistant-ui/generative-ui`.
|
|
64
|
+
|
|
65
|
+
## Tooling and integrations
|
|
66
|
+
|
|
67
|
+
| Package | Notes |
|
|
68
|
+
|---------|-------|
|
|
69
|
+
| `@assistant-ui/react-mcp` | User-managed MCP servers: connectors, OAuth, elicitation, `McpManagerResource` |
|
|
70
|
+
| `@assistant-ui/react-devtools` | DevTools panel and modal |
|
|
71
|
+
| `@assistant-ui/react-o11y` | Headless span and trace primitives |
|
|
72
|
+
| `@assistant-ui/mcp-docs-server` | Local stdio proxy to the hosted docs MCP server at `https://www.assistant-ui.com/mcp` |
|
|
73
|
+
| `@assistant-ui/agent-launcher` | Launches Claude Code with the assistant-ui skills (`assistant-ui agent`) |
|
|
74
|
+
|
|
75
|
+
## Package selection
|
|
76
|
+
|
|
77
|
+
| Scenario | Packages |
|
|
78
|
+
|----------|----------|
|
|
79
|
+
| Next.js + AI SDK | `@assistant-ui/react`, `@assistant-ui/ai-sdk`, `ai@^7`, `@ai-sdk/react@^4`, a provider such as `@ai-sdk/openai` |
|
|
80
|
+
| LangGraph | `@assistant-ui/react`, `@assistant-ui/react-langgraph` (or `@assistant-ui/react-langchain` for `useStream`) |
|
|
81
|
+
| Custom backend | `@assistant-ui/react`, `assistant-stream` |
|
|
82
|
+
| Markdown | `@assistant-ui/react-markdown` (or `@assistant-ui/react-streamdown`) plus the `markdown-text` element |
|
|
83
|
+
| Toolkits with `"use generative"` | `@assistant-ui/next`, `@assistant-ui/vite`, or `@assistant-ui/metro` |
|
|
84
|
+
| Expo / React Native | `@assistant-ui/react-native`, `@assistant-ui/ai-sdk`, `@assistant-ui/metro` |
|
|
85
|
+
| Terminal | `@assistant-ui/react-ink`, `@assistant-ui/react-ink-markdown`, `@assistant-ui/ai-sdk` |
|
|
86
|
+
| Persistence | `assistant-cloud` |
|
|
87
|
+
|
|
88
|
+
## Version compatibility
|
|
89
|
+
|
|
90
|
+
- `@assistant-ui/react` requires React 18 or 19.
|
|
91
|
+
- `@assistant-ui/ai-sdk` targets AI SDK v7 (`ai@^7`, `@ai-sdk/react@^4`). Older AI SDK majors use pinned `@assistant-ui/react-ai-sdk` releases (`1.3.x` for `ai@^6`, `1.1.x` for `ai@^5`) or `@assistant-ui/react-data-stream` for `ai@^4`; see the update skill.
|
|
92
|
+
- AI SDK accepts Zod 3.25+ and Zod 4.
|
|
93
|
+
- Node.js 24 is required only to build the monorepo; apps follow their framework's requirement.
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cloud
|
|
3
|
+
description: "Adds AssistantCloud backed persistence, authorization, and telemetry to assistant-ui apps. Use when wiring cross-session thread and message history, multi-device chat, message feedback, file uploads, or auth: passing `cloud` to `useChatRuntime` from `@assistant-ui/ai-sdk`, `AISDKThreads({ cloud })` for `AuiConfig` hosts, or `cloud` on `useLangGraphRuntime`. Covers constructing `AssistantCloud` with `authToken` (JWT), `apiKey` plus `userId`/`workspaceId` (server-side only), or `anonymous`; Clerk, Auth0, Supabase, and Firebase integrations and a backend token endpoint; the `cloud.threads`, `cloud.files`, `cloud.runs`, and `cloud.telemetry` client surface; and a custom `ThreadHistoryAdapter` on `CloudMessagePersistence`. Route here for threads that do not persist, 401s against the cloud API, or feedback buttons that do not save. For the `<ThreadList />` sidebar UI use thread-list; for the general adapter contracts use runtime."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# assistant-ui Cloud
|
|
8
|
+
|
|
9
|
+
**Always consult [assistant-ui.com/llms.txt](https://www.assistant-ui.com/llms.txt) for the latest API.**
|
|
10
|
+
|
|
11
|
+
Assistant Cloud is a hosted service that adds thread persistence, message history, auto-generated titles, message feedback, and file uploads to any React chat UI. One `AssistantCloud` client backs the assistant-ui runtime, `AuiConfig` thread integration, and LangGraph Cloud.
|
|
12
|
+
|
|
13
|
+
## Contents
|
|
14
|
+
|
|
15
|
+
- [References](#references) | [Install](#install) | [Quick start: useChatRuntime](#quick-start-usechatruntime) | [AuiConfig hosts: AISDKThreads](#auiconfig-hosts-aisdkthreads) | [Migrate from Cloud AI SDK](#migrate-from-cloud-ai-sdk) | [LangGraph](#langgraph-uselanggraphruntime) | [Message feedback](#message-feedback) | [Authentication](#authentication) | [Client API](#client-api) | [Environment variables](#environment-variables) | [Common Gotchas](#common-gotchas) | [Related Skills](#related-skills)
|
|
16
|
+
|
|
17
|
+
## References
|
|
18
|
+
|
|
19
|
+
- [./references/persistence.md](./references/persistence.md) -- the thread, message, file, and run client API in full, verified against source
|
|
20
|
+
- [./references/authorization.md](./references/authorization.md) -- the three auth modes and direct provider integrations (Clerk, Auth0, Supabase, Firebase)
|
|
21
|
+
- [./references/custom-persistence.md](./references/custom-persistence.md) -- `CloudMessagePersistence` and `createFormattedPersistence`, for a custom `ThreadHistoryAdapter` backed by cloud message storage
|
|
22
|
+
- [./references/auth-integrations.md](./references/auth-integrations.md) -- non-cloud auth gating with Auth.js (next-auth), Clerk, and better-auth, plus pairing AssistantCloud with a backend token endpoint
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @assistant-ui/react @assistant-ui/ai-sdk
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`assistant-cloud` ships as a dependency of `@assistant-ui/react`, which re-exports `AssistantCloud` for browser code. Server-side code (API routes, token endpoints) that has no reason to depend on `@assistant-ui/react` imports `AssistantCloud` from `assistant-cloud` directly.
|
|
31
|
+
|
|
32
|
+
## Quick start: useChatRuntime
|
|
33
|
+
|
|
34
|
+
`useChatRuntime({ cloud })` from `@assistant-ui/ai-sdk` wraps AI SDK's `useChat` and adds persistence. It creates a cloud thread on the first message, persists messages as they stream, generates a title after the first response, loads history on thread switch through `<ThreadList />`, and submits message feedback against the stored message.
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
"use client";
|
|
38
|
+
|
|
39
|
+
import { useMemo } from "react";
|
|
40
|
+
import { AssistantCloud, AssistantRuntimeProvider } from "@assistant-ui/react";
|
|
41
|
+
import { useChatRuntime } from "@assistant-ui/ai-sdk";
|
|
42
|
+
import { Thread } from "@/components/assistant-ui/elements/thread.aui";
|
|
43
|
+
import { ThreadList } from "@/components/assistant-ui/elements/thread-list.aui";
|
|
44
|
+
|
|
45
|
+
export default function ChatPage() {
|
|
46
|
+
const cloud = useMemo(
|
|
47
|
+
() =>
|
|
48
|
+
new AssistantCloud({
|
|
49
|
+
baseUrl: process.env.NEXT_PUBLIC_ASSISTANT_BASE_URL!,
|
|
50
|
+
anonymous: true,
|
|
51
|
+
}),
|
|
52
|
+
[],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const runtime = useChatRuntime({ cloud });
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
59
|
+
<div className="grid h-dvh grid-cols-[250px_1fr] gap-x-2">
|
|
60
|
+
<ThreadList />
|
|
61
|
+
<Thread />
|
|
62
|
+
</div>
|
|
63
|
+
</AssistantRuntimeProvider>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`anonymous: true` is for demos; see [Authentication](#authentication) for production auth. `useChatRuntime` also accepts `adapters.history` (a `ThreadHistoryAdapter`, must implement `withFormat` to combine with AI SDK), `adapters.feedback` (defaults to the cloud feedback adapter when `cloud` is set), `adapters.attachments`, `toCreateMessage`, `transport` (defaults to `AssistantChatTransport` calling `/api/chat`), and `onResumeError`.
|
|
69
|
+
|
|
70
|
+
## AuiConfig hosts: AISDKThreads
|
|
71
|
+
|
|
72
|
+
`AISDKThreads({ cloud })` from `@assistant-ui/ai-sdk` is the `AuiConfig` equivalent for a host that is not `AssistantRuntimeProvider` (Vue, or a hand-rolled `AssistantClient`). With `cloud` set, the thread list is a `RemoteThreadList` with background threads: every visited thread keeps running and its own history after a switch, and a freshly created thread titles itself.
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { AuiConfig, AuiProvider } from "@assistant-ui/react";
|
|
76
|
+
import { AISDKThreads } from "@assistant-ui/ai-sdk";
|
|
77
|
+
|
|
78
|
+
const config = AuiConfig({
|
|
79
|
+
threads: AISDKThreads({ cloud }),
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Migrate from Cloud AI SDK
|
|
84
|
+
|
|
85
|
+
`@assistant-ui/cloud-ai-sdk` is deprecated. For new code, use the `cloud` option of `useChatRuntime` from `@assistant-ui/ai-sdk`; for an `AuiConfig` host, use `AISDKThreads({ cloud })`. See [Migrate from Cloud AI SDK](https://www.assistant-ui.com/docs/cloud/migrate-cloud-ai-sdk) for the migration details.
|
|
86
|
+
|
|
87
|
+
## LangGraph: useLangGraphRuntime
|
|
88
|
+
|
|
89
|
+
`useLangGraphRuntime` from `@assistant-ui/react-langgraph` takes `cloud` alongside `stream`, `create`, `load`, and `delete` for cloud-backed thread management over a LangGraph Cloud backend.
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
"use client";
|
|
93
|
+
|
|
94
|
+
import { AssistantCloud, AssistantRuntimeProvider } from "@assistant-ui/react";
|
|
95
|
+
import { useLangGraphRuntime, type LangChainMessage } from "@assistant-ui/react-langgraph";
|
|
96
|
+
import { useMemo } from "react";
|
|
97
|
+
import { createThread, deleteThread, getThreadState, sendMessage } from "@/lib/chatApi";
|
|
98
|
+
|
|
99
|
+
export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
|
|
100
|
+
const cloud = useMemo(
|
|
101
|
+
() => new AssistantCloud({ baseUrl: process.env.NEXT_PUBLIC_ASSISTANT_BASE_URL!, anonymous: true }),
|
|
102
|
+
[],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const runtime = useLangGraphRuntime({
|
|
106
|
+
cloud,
|
|
107
|
+
stream: async function* (messages, { initialize }) {
|
|
108
|
+
const { externalId } = await initialize();
|
|
109
|
+
if (!externalId) throw new Error("Thread not found");
|
|
110
|
+
return sendMessage({ threadId: externalId, messages });
|
|
111
|
+
},
|
|
112
|
+
create: async () => ({ externalId: (await createThread()).thread_id }),
|
|
113
|
+
load: async (externalId) => {
|
|
114
|
+
const state = await getThreadState(externalId);
|
|
115
|
+
return { messages: (state.values as { messages?: LangChainMessage[] }).messages ?? [] };
|
|
116
|
+
},
|
|
117
|
+
delete: async (externalId) => deleteThread(externalId),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return <AssistantRuntimeProvider runtime={runtime}>{children}</AssistantRuntimeProvider>;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`create` returns `{ externalId }`, your backend's LangGraph thread id; `load` returns that thread's messages (and optionally interrupts); `delete` receives the `externalId` and, when provided, enables delete from the thread list UI.
|
|
125
|
+
|
|
126
|
+
## Message feedback
|
|
127
|
+
|
|
128
|
+
When `cloud` is set on `useChatRuntime` (or `AISDKThreads`), the runtime wires a default `FeedbackAdapter` that calls `cloud.threads.messages.feedback` automatically, so the built-in thumbs up and down buttons persist against the stored message with no extra code. Calling it directly:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
const { feedback_id, type } = await cloud.threads.messages.feedback(threadId, messageId, {
|
|
132
|
+
type: "positive", // or "negative"
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Authentication
|
|
137
|
+
|
|
138
|
+
Three constructor shapes, chosen by which fields you pass:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
// JWT (recommended for production; client-side)
|
|
142
|
+
const cloud = new AssistantCloud({
|
|
143
|
+
baseUrl: process.env.NEXT_PUBLIC_ASSISTANT_BASE_URL!,
|
|
144
|
+
authToken: async () => getAuthToken(), // returns a JWT, or null
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// API key (server-side only; baseUrl defaults to https://backend.assistant-api.com)
|
|
148
|
+
const cloud = new AssistantCloud({
|
|
149
|
+
apiKey: process.env.ASSISTANT_API_KEY!,
|
|
150
|
+
userId: user.id,
|
|
151
|
+
workspaceId: user.workspaceId,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Anonymous (demos and prototypes; a new user per browser session)
|
|
155
|
+
const cloud = new AssistantCloud({
|
|
156
|
+
baseUrl: process.env.NEXT_PUBLIC_ASSISTANT_BASE_URL!,
|
|
157
|
+
anonymous: true,
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Authorization is scoped to a workspace (commonly `userId`, `orgId_userId`, or `projectId_userId`). Wire a direct provider integration (Clerk, Auth0, Supabase, Firebase) from the Assistant Cloud dashboard, or mint a token server-side with the API key client and return it from an endpoint your frontend's `authToken` callback fetches. See [authorization.md](./references/authorization.md) for both paths in full, and [auth-integrations.md](./references/auth-integrations.md) for pairing Cloud with Auth.js, Clerk, or better-auth session data.
|
|
162
|
+
|
|
163
|
+
## Client API
|
|
164
|
+
|
|
165
|
+
Every method is verified against `src/cloud/**`. `threadId`/`messageId` are always the first arguments; list endpoints page with `after` (a cursor, not an offset).
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
// Threads
|
|
169
|
+
const { threads } = await cloud.threads.list({ is_archived: false, limit: 50, after: cursor });
|
|
170
|
+
const thread = await cloud.threads.get(threadId);
|
|
171
|
+
const { thread_id } = await cloud.threads.create({ last_message_at: new Date(), title, external_id, metadata });
|
|
172
|
+
await cloud.threads.update(threadId, { title, last_message_at, metadata, is_archived });
|
|
173
|
+
await cloud.threads.delete(threadId);
|
|
174
|
+
|
|
175
|
+
// Messages (parent_id and format are required on create; update touches content only)
|
|
176
|
+
const { messages } = await cloud.threads.messages.list(threadId, { format: "ai-sdk/v6" });
|
|
177
|
+
const { message_id } = await cloud.threads.messages.create(threadId, { parent_id, format, content });
|
|
178
|
+
await cloud.threads.messages.update(threadId, messageId, { content });
|
|
179
|
+
await cloud.threads.messages.feedback(threadId, messageId, { type: "positive" });
|
|
180
|
+
|
|
181
|
+
// Files
|
|
182
|
+
const { signedUrl, publicUrl, expiresAt } = await cloud.files.generatePresignedUploadUrl({ filename });
|
|
183
|
+
await fetch(signedUrl, { method: "PUT", body: file });
|
|
184
|
+
|
|
185
|
+
// Runs, projects, auth
|
|
186
|
+
await cloud.runs.report(runReport); // telemetry sink; the runtime calls this for you
|
|
187
|
+
const { threads: projectThreads } = await cloud.projects.threads.list({ limit: 50, after: cursor }); // whole project, not one workspace
|
|
188
|
+
const { messages: projectMessages } = await cloud.projects.threads.messages.list(threadId, { limit: 50, after: cursor });
|
|
189
|
+
const { token } = await cloud.auth.tokens.create(); // server-side, API key mode
|
|
190
|
+
cloud.telemetry; // { enabled: boolean, beforeReport? }
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`cloud.threads.create`'s `last_message_at` is required; everything else on create and update is optional. `CloudThread` fields: `id`, `title`, `last_message_at`, `created_at`, `updated_at`, `is_archived`, `external_id`, `metadata`, `project_id`, `workspace_id`. `CloudMessage` fields: `id`, `parent_id`, `height`, `format`, `content`, `created_at`, `updated_at`. `content`/`format` are opaque to the client; `useChatRuntime` and `AISDKThreads` write `format: "ai-sdk/v6"` with an AI SDK `UIMessage`-shaped `content`. `cloud.projects.threads.messages.list` accepts `limit`/`after` paging that `cloud.threads.messages.list` does not. Failed requests throw `CloudAPIError` (with `.status`) from `assistant-cloud`; a malformed response throws `CloudResponseError`. Full detail, auto-save behavior, telemetry fields, and error handling: [persistence.md](./references/persistence.md).
|
|
194
|
+
|
|
195
|
+
## Environment variables
|
|
196
|
+
|
|
197
|
+
```env
|
|
198
|
+
NEXT_PUBLIC_ASSISTANT_BASE_URL=https://proj-[YOUR-ID].assistant-api.com # client-side
|
|
199
|
+
ASSISTANT_API_KEY=your-api-key-here # server-side only, never expose to the client
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
React Native reads `EXPO_PUBLIC_ASSISTANT_BASE_URL`; React Ink reads `ASSISTANT_BASE_URL` (no `NEXT_PUBLIC_` prefix, since there is no bundler exposing it to a browser).
|
|
203
|
+
|
|
204
|
+
## Common Gotchas
|
|
205
|
+
|
|
206
|
+
**Threads not persisting**
|
|
207
|
+
- `cloud` must be passed to `useChatRuntime` or `AISDKThreads`; a thread with no messages yet is never created.
|
|
208
|
+
- Check that `authToken` isn't silently resolving to `null`: any real request then throws a plain `Error("Authorization failed")` before it reaches the network, distinct from a `CloudAPIError` 401.
|
|
209
|
+
|
|
210
|
+
**401 or "Authorization failed" against the cloud API**
|
|
211
|
+
- Verify `baseUrl` matches the project's Frontend API URL exactly (no trailing content after the host).
|
|
212
|
+
- For JWT mode, confirm `authToken` resolves before the first request; for a Clerk template, the aud claim in the JWT must be `"assistant-ui"`.
|
|
213
|
+
|
|
214
|
+
**Feedback buttons render but nothing persists**
|
|
215
|
+
- The default feedback adapter only wires up when `cloud` is passed to the runtime; a custom `adapters.feedback` overrides it entirely.
|
|
216
|
+
|
|
217
|
+
**Message history reappears out of order after a page reload**
|
|
218
|
+
- Do not hand-write `content` for a message row; it must be exactly what the active format's `encode` produced, or `decode` fails on reload. Seed test data through the runtime, not by inserting rows directly.
|
|
219
|
+
|
|
220
|
+
**Importing from `@assistant-ui/react-ai-sdk`**
|
|
221
|
+
- That package only re-exports `@assistant-ui/ai-sdk` for installs pinned to an older version. Import `useChatRuntime` and `AssistantChatTransport` from `@assistant-ui/ai-sdk` in new code.
|
|
222
|
+
|
|
223
|
+
**Anonymous mode loses history**
|
|
224
|
+
- Anonymous creates a new user per browser session (no cross-device sync); switch to JWT or API key auth once you need durability.
|
|
225
|
+
|
|
226
|
+
## Related Skills
|
|
227
|
+
|
|
228
|
+
- [thread-list](../thread-list/SKILL.md) -- the `<ThreadList />` sidebar UI, thread CRUD selectors, and the `RemoteThreadListAdapter` contract for a fully self-hosted (non-cloud) thread list
|
|
229
|
+
- [setup](../setup/SKILL.md) -- installing assistant-ui and picking a runtime hook, including the `cloud` and `cloud-clerk` CLI templates
|
|
230
|
+
- [runtime](../runtime/SKILL.md) -- the general adapter contracts (`ThreadHistoryAdapter`, `FeedbackAdapter`, `AttachmentAdapter`) that cloud fulfills
|