assistant-ui

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

assistant-ui

assistant-ui

Always consult assistant-ui.com/llms.txt for latest API.
React library for building AI chat interfaces with composable primitives.
请始终查阅assistant-ui.com/llms.txt获取最新API。
用于构建AI聊天界面的React库,提供可组合的基础组件。

References

参考资料

  • ./references/architecture.md -- Core architecture and layered system
  • ./references/packages.md -- Package overview and selection guide
  • ./references/architecture.md -- 核心架构与分层系统
  • ./references/packages.md -- 包概览与选择指南

When to Use

使用场景

Use CaseBest For
Chat UI from scratchFull control over UX
Existing AI backendConnects to any streaming backend
Custom message typesTools, images, files, custom parts
Multi-thread appsBuilt-in thread list management
Production appsCloud persistence, auth, analytics
使用场景适用场景
从零构建聊天UI完全控制用户体验
已有AI后端可连接至任何流式后端
自定义消息类型支持工具、图片、文件、自定义组件
多线程应用内置线程列表管理
生产环境应用支持云端持久化、认证、分析

Architecture

架构

┌─────────────────────────────────────────────────────────┐
│                  UI Components (Primitives)             │
│    ThreadPrimitive, MessagePrimitive, ComposerPrimitive │
└─────────────────────────┬───────────────────────────────┘
┌─────────────────────────▼───────────────────────────────┐
│                   Context Hooks                         │
│   useAssistantApi, useAssistantState, useAssistantEvent │
└─────────────────────────┬───────────────────────────────┘
┌─────────────────────────▼───────────────────────────────┐
│                    Runtime Layer                        │
│  AssistantRuntime → ThreadRuntime → MessageRuntime      │
└─────────────────────────┬───────────────────────────────┘
┌─────────────────────────▼───────────────────────────────┐
│                   Adapters/Backend                      │
│   AI SDK · LangGraph · Custom · Cloud Persistence       │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│                  UI Components (Primitives)             │
│    ThreadPrimitive, MessagePrimitive, ComposerPrimitive │
└─────────────────────────┬───────────────────────────────┘
┌─────────────────────────▼───────────────────────────────┐
│                   Context Hooks                         │
│   useAssistantApi, useAssistantState, useAssistantEvent │
└─────────────────────────┬───────────────────────────────┘
┌─────────────────────────▼───────────────────────────────┐
│                    Runtime Layer                        │
│  AssistantRuntime → ThreadRuntime → MessageRuntime      │
└─────────────────────────┬───────────────────────────────┘
┌─────────────────────────▼───────────────────────────────┐
│                   Adapters/Backend                      │
│   AI SDK · LangGraph · Custom · Cloud Persistence       │
└─────────────────────────────────────────────────────────┘

Pick a Runtime

选择Runtime

Using AI SDK?
├─ Yes → useChatRuntime (recommended)
└─ No
   ├─ External state (Redux/Zustand)? → useExternalStoreRuntime
   ├─ LangGraph agent? → useLangGraphRuntime
   ├─ AG-UI protocol? → useAgUiRuntime
   ├─ A2A protocol? → useA2ARuntime
   └─ Custom API → useLocalRuntime
使用AI SDK?
├─ 是 → 使用useChatRuntime(推荐)
└─ 否
   ├─ 外部状态管理(Redux/Zustand)? → 使用useExternalStoreRuntime
   ├─ LangGraph agent? → 使用useLangGraphRuntime
   ├─ AG-UI协议? → 使用useAgUiRuntime
   ├─ A2A协议? → 使用useA2ARuntime
   └─ 自定义API → 使用useLocalRuntime

Core Packages

核心包

PackagePurpose
@assistant-ui/react
UI primitives & hooks
@assistant-ui/react-ai-sdk
Vercel AI SDK v6 adapter
@assistant-ui/react-langgraph
LangGraph adapter
@assistant-ui/react-markdown
Markdown rendering
@assistant-ui/styles
Pre-built CSS
assistant-stream
Streaming protocol
assistant-cloud
Cloud persistence
用途
@assistant-ui/react
UI基础组件与钩子
@assistant-ui/react-ai-sdk
Vercel AI SDK v6适配器
@assistant-ui/react-langgraph
LangGraph适配器
@assistant-ui/react-markdown
Markdown渲染
@assistant-ui/styles
预构建CSS
assistant-stream
流式协议
assistant-cloud
云端持久化

Quick Start

快速开始

tsx
import { AssistantRuntimeProvider, Thread } from "@assistant-ui/react";
import { useChatRuntime, AssistantChatTransport } from "@assistant-ui/react-ai-sdk";

function App() {
  const runtime = useChatRuntime({
    transport: new AssistantChatTransport({ api: "/api/chat" }),
  });
  return (
    <AssistantRuntimeProvider runtime={runtime}>
      <Thread />
    </AssistantRuntimeProvider>
  );
}
tsx
import { AssistantRuntimeProvider, Thread } from "@assistant-ui/react";
import { useChatRuntime, AssistantChatTransport } from "@assistant-ui/react-ai-sdk";

function App() {
  const runtime = useChatRuntime({
    transport: new AssistantChatTransport({ api: "/api/chat" }),
  });
  return (
    <AssistantRuntimeProvider runtime={runtime}>
      <Thread />
    </AssistantRuntimeProvider>
  );
}

State Access

状态访问

tsx
import { useAssistantApi, useAssistantState } from "@assistant-ui/react";

const api = useAssistantApi();
api.thread().append({ role: "user", content: [{ type: "text", text: "Hi" }] });
api.thread().cancelRun();

const messages = useAssistantState(s => s.thread.messages);
const isRunning = useAssistantState(s => s.thread.isRunning);
tsx
import { useAssistantApi, useAssistantState } from "@assistant-ui/react";

const api = useAssistantApi();
api.thread().append({ role: "user", content: [{ type: "text", text: "Hi" }] });
api.thread().cancelRun();

const messages = useAssistantState(s => s.thread.messages);
const isRunning = useAssistantState(s => s.thread.isRunning);

Related Skills

相关技能

  • /setup
    - Installation and configuration
  • /primitives
    - UI component customization
  • /runtime
    - State management deep dive
  • /tools
    - Tool registration and UI
  • /streaming
    - Streaming protocols
  • /cloud
    - Persistence and auth
  • /thread-list
    - Multi-thread management
  • /update
    - Version updates and migrations
  • /setup
    - 安装与配置
  • /primitives
    - UI组件定制
  • /runtime
    - 状态管理深入解析
  • /tools
    - 工具注册与UI
  • /streaming
    - 流式协议
  • /cloud
    - 持久化与认证
  • /thread-list
    - 多线程管理
  • /update
    - 版本更新与迁移