agentic-ui-development

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Agentic UI Development Skill

Agentic UI开发技能

面向智能体的 UI 组件库开发技能,提供智能化的组件推荐、代码生成和设计系统支持。
面向智能体的UI组件库开发技能,提供智能化的组件推荐、代码生成和设计系统支持。

Quick Start

快速开始

bash
pnpm install    # 安装依赖
pnpm start      # 启动文档站点 (http://localhost:8000)
pnpm test       # 运行单元测试
pnpm run build  # 构建项目
bash
pnpm install    # 安装依赖
pnpm start      # 启动文档站点 (http://localhost:8000)
pnpm test       # 运行单元测试
pnpm run build  # 构建项目

Quick Reference - Search Commands

快速参考 - 搜索命令

bash
undefined
bash
undefined

搜索组件

搜索组件

python .cursor/skills/agentic-ui-development/scripts/search.py "chat bubble"
python .cursor/skills/agentic-ui-development/scripts/search.py "chat bubble"

按域搜索

按域搜索

python .cursor/skills/agentic-ui-development/scripts/search.py "chart" --domain plugin python .cursor/skills/agentic-ui-development/scripts/search.py "scroll" --domain hook python .cursor/skills/agentic-ui-development/scripts/search.py "color" --domain token
python .cursor/skills/agentic-ui-development/scripts/search.py "chart" --domain plugin python .cursor/skills/agentic-ui-development/scripts/search.py "scroll" --domain hook python .cursor/skills/agentic-ui-development/scripts/search.py "color" --domain token

获取推荐方案

获取推荐方案

python .cursor/skills/agentic-ui-development/scripts/search.py "ai assistant" --recommend
python .cursor/skills/agentic-ui-development/scripts/search.py "ai assistant" --recommend

生成完整设计系统 (推荐)

生成完整设计系统 (推荐)

-p 是 --project-name 的简写,用于指定项目名称

-p 是 --project-name 的简写,用于指定项目名称

python .cursor/skills/agentic-ui-development/scripts/search.py "ai chat" --design-system --project-name "My App"
python .cursor/skills/agentic-ui-development/scripts/search.py "ai chat" --design-system --project-name "My App"

持久化设计系统 (Master + Overrides 模式)

持久化设计系统 (Master + Overrides 模式)

python .cursor/skills/agentic-ui-development/scripts/search.py "ai chat" --design-system --persist --project-name "My App" --page "chat"
undefined
python .cursor/skills/agentic-ui-development/scripts/search.py "ai chat" --design-system --persist --project-name "My App" --page "chat"
undefined

Skill Activation

技能触发条件

当用户请求以下任务时自动激活:
触发关键词组件/功能
bubble
,
chat
,
message
对话气泡组件
thought chain
,
thinking
,
reasoning
思维链可视化
tool use
,
tool call
,
api call
工具调用展示
markdown
,
editor
,
rich text
Markdown 编辑器
input
,
multimodal
,
voice
多模态输入框
workspace
,
file
,
browser
工作区面板
task
,
progress
,
step
任务列表
history
,
conversation
会话历史
layout
,
agentic
布局框架
agent
,
run
,
control
智能体运行控制
button
,
icon
,
action
按钮组件
animation
,
typing
,
gradient
动画效果
i18n
,
locale
,
language
国际化
当用户请求以下任务时自动激活:
触发关键词组件/功能
bubble
,
chat
,
message
对话气泡组件
thought chain
,
thinking
,
reasoning
思维链可视化
tool use
,
tool call
,
api call
工具调用展示
markdown
,
editor
,
rich text
Markdown 编辑器
input
,
multimodal
,
voice
多模态输入框
workspace
,
file
,
browser
工作区面板
task
,
progress
,
step
任务列表
history
,
conversation
会话历史
layout
,
agentic
布局框架
agent
,
run
,
control
智能体运行控制
button
,
icon
,
action
按钮组件
animation
,
typing
,
gradient
动画效果
i18n
,
locale
,
language
国际化

How It Works

工作原理

┌─────────────────────────────────────────────────────────────────┐
│  1. USER REQUEST                                                │
│     "创建一个带思维链的 AI 对话气泡"                              │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│  2. DESIGN SYSTEM GENERATION (--design-system)                  │
│     • BM25 search across 4 domains (component, plugin, hook,    │
│       token)                                                    │
│     • Apply reasoning rules from reasoning-rules.json           │
│     • Generate complete recommendation with anti-patterns       │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│  3. COMPONENT SEARCH (Multi-domain)                             │
│     • Component matching (37 components)                        │
│     • Props API lookup                                          │
│     • Style token recommendations                               │
│     • Related hooks & utilities                                 │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│  4. CODE GENERATION                                             │
│     • Apply component template                                  │
│     • Use design tokens (not hardcoded values)                  │
│     • Include TypeScript types                                  │
│     • Add proper event handlers                                 │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│  5. PRE-DELIVERY CHECKLIST                                      │
│     [ ] Uses Ant Design tokens (no hardcoded colors)            │
│     [ ] TypeScript types complete (no `any`)                    │
│     [ ] Event handlers use `on` prefix                          │
│     [ ] CSS-in-JS with createStyles                             │
│     [ ] Tests included (≥80% coverage)                          │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│  1. 用户请求                                                    │
│     "创建一个带思维链的 AI 对话气泡"                              │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│  2. 设计系统生成 (--design-system)                  │
│     • 在4个域(component、plugin、hook、token)中执行BM25搜索 │
│     • 应用reasoning-rules.json中的推理规则           │
│     • 生成包含反模式提示的完整推荐方案       │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│  3. 多域组件搜索                             │
│     • 组件匹配(37个组件)                        │
│     • Props API 查找                                          │
│     • 样式令牌推荐                               │
│     • 相关Hooks与工具类                                 │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│  4. 代码生成                                             │
│     • 应用组件模板                                  │
│     • 使用设计令牌(而非硬编码值)                  │
│     • 包含TypeScript类型定义                                  │
│     • 添加合适的事件处理函数                                 │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│  5. 交付前检查清单                                      │
│     [ ] 使用Ant Design令牌(无硬编码颜色)            │
│     [ ] TypeScript类型定义完整(无`any`类型)                    │
│     [ ] 事件处理函数使用`on`前缀                          │
│     [ ] 使用createStyles的CSS-in-JS方案                             │
│     [ ] 包含测试用例(覆盖率≥80%)                          │
└─────────────────────────────────────────────────────────────────┘

Design System Generation (NEW)

设计系统生成(新增功能)

Generate Complete Recommendation

生成完整推荐方案

使用
--design-system
生成完整的组件推荐方案:
bash
python .cursor/skills/agentic-ui-development/scripts/search.py "ai chat assistant" --design-system --project-name "My AI App"
输出包含:
  • 推荐组件列表
  • 推荐 Hooks
  • 推荐插件
  • 关键设计令牌
  • 样式优先级
  • 反模式警告
  • 交付前检查清单
使用
--design-system
参数生成完整的组件推荐方案:
bash
python .cursor/skills/agentic-ui-development/scripts/search.py "ai chat assistant" --design-system --project-name "My AI App"
输出包含:
  • 推荐组件列表
  • 推荐Hooks
  • 推荐插件
  • 关键设计令牌
  • 样式优先级
  • 反模式警告
  • 交付前检查清单

Persist with Master + Overrides Pattern

采用Master + Overrides模式持久化

持久化设计系统到文件,支持分层覆盖:
bash
undefined
将设计系统持久化到文件,支持分层覆盖:
bash
undefined

创建 MASTER.md

创建MASTER.md

python .cursor/skills/agentic-ui-development/scripts/search.py "ai chat" --design-system --persist --project-name "My App"
python .cursor/skills/agentic-ui-development/scripts/search.py "ai chat" --design-system --persist --project-name "My App"

同时创建页面覆盖文件

同时创建页面覆盖文件

python .cursor/skills/agentic-ui-development/scripts/search.py "ai chat" --design-system --persist --project-name "My App" --page "chat"

生成文件结构:
design-system/my-app/ ├── MASTER.md # 全局设计规则 (Source of Truth) └── pages/ └── chat.md # 页面特定覆盖规则

**分层检索逻辑:**
1. 构建页面时,先检查 `design-system/<project>/pages/[page].md`
2. 如果页面文件存在,其规则**覆盖** Master 文件
3. 如果不存在,严格使用 `design-system/<project>/MASTER.md`
python .cursor/skills/agentic-ui-development/scripts/search.py "ai chat" --design-system --persist --project-name "My App" --page "chat"

生成的文件结构:
design-system/my-app/ ├── MASTER.md # 全局设计规则(唯一可信源) └── pages/ └── chat.md # 页面特定覆盖规则

**分层检索逻辑:**
1. 构建页面时,先检查`design-system/<project>/pages/[page].md`
2. 如果页面文件存在,其规则**覆盖**Master文件
3. 如果不存在,严格使用`design-system/<project>/MASTER.md`

Component Categories

组件分类

🤖 AI Core Components

🤖 AI核心组件

ComponentPurposeSource
Bubble
对话气泡 (AI/User)
src/Bubble/
ThoughtChainList
思维链可视化
src/ThoughtChainList/
ToolUseBar
工具调用展示
src/ToolUseBar/
TaskList
任务状态列表
src/TaskList/
AnswerAlert
结果状态提示
src/AnswerAlert/
AgentRunBar
智能体运行控制
src/AgentRunBar/
组件用途源码路径
Bubble
对话气泡(AI/用户)
src/Bubble/
ThoughtChainList
思维链可视化
src/ThoughtChainList/
ToolUseBar
工具调用展示
src/ToolUseBar/
TaskList
任务状态列表
src/TaskList/
AnswerAlert
结果状态提示
src/AnswerAlert/
AgentRunBar
智能体运行控制
src/AgentRunBar/

✍️ Editor Components

✍️ 编辑器组件

ComponentPurposeSource
MarkdownEditor
流式 Markdown 编辑器
src/MarkdownEditor/
MarkdownInputField
多模态输入框
src/MarkdownInputField/
SchemaForm
JSON Schema 表单
src/Schema/
组件用途源码路径
MarkdownEditor
流式Markdown编辑器
src/MarkdownEditor/
MarkdownInputField
多模态输入框
src/MarkdownInputField/
SchemaForm
JSON Schema表单
src/Schema/

📐 Layout Components

📐 布局组件

ComponentPurposeSource
AgenticLayout
智能体应用布局
src/AgenticLayout/
ChatLayout
对话界面布局
src/ChatLayout/
ChatBootPage
对话启动页
src/ChatBootPage/
Workspace
多标签工作台
src/Workspace/
组件用途源码路径
AgenticLayout
智能体应用布局
src/AgenticLayout/
ChatLayout
对话界面布局
src/ChatLayout/
ChatBootPage
对话启动页
src/ChatBootPage/
Workspace
多标签工作台
src/Workspace/

🎨 Utility Components

🎨 工具类组件

ComponentPurposeSource
History
会话历史
src/History/
WelcomeMessage
欢迎引导
src/WelcomeMessage/
SuggestionList
建议列表
src/Components/SuggestionList/
Loading
加载状态
src/Components/Loading/
Robot
机器人头像
src/Components/Robot/
GradientText
渐变文字效果
src/Components/GradientText/
TextAnimate
文字动画
src/Components/TextAnimate/
TypingAnimation
打字机动画
src/Components/TypingAnimation/
I18n
国际化支持
src/I18n/
组件用途源码路径
History
会话历史
src/History/
WelcomeMessage
欢迎引导
src/WelcomeMessage/
SuggestionList
建议列表
src/Components/SuggestionList/
Loading
加载状态
src/Components/Loading/
Robot
机器人头像
src/Components/Robot/
GradientText
渐变文字效果
src/Components/GradientText/
TextAnimate
文字动画
src/Components/TextAnimate/
TypingAnimation
打字机动画
src/Components/TypingAnimation/
I18n
国际化支持
src/I18n/

🔘 Button Components

🔘 按钮组件

ComponentPurposeSource
IconButton
图标按钮
src/Components/Button/IconButton/
SwitchButton
切换按钮
src/Components/Button/SwitchButton/
ToggleButton
激活按钮
src/Components/Button/ToggleButton/
ActionIconBox
操作图标盒
src/Components/ActionIconBox/
ActionItemBox
操作项容器
src/Components/ActionItemBox/
组件用途源码路径
IconButton
图标按钮
src/Components/Button/IconButton/
SwitchButton
切换按钮
src/Components/Button/SwitchButton/
ToggleButton
激活按钮
src/Components/Button/ToggleButton/
ActionIconBox
操作图标盒
src/Components/ActionIconBox/
ActionItemBox
操作项容器
src/Components/ActionItemBox/

🔌 Plugin System

🔌 插件系统

PluginPurposeSource
chart
图表渲染 (Chart.js)
src/Plugins/chart/
code
代码高亮 (ACE)
src/Plugins/code/
katex
数学公式
src/Plugins/katex/
mermaid
图表渲染
src/Plugins/mermaid/
formatter
代码格式化
src/Plugins/formatter/
插件用途源码路径
chart
图表渲染(Chart.js)
src/Plugins/chart/
code
代码高亮(ACE)
src/Plugins/code/
katex
数学公式
src/Plugins/katex/
mermaid
图表渲染
src/Plugins/mermaid/
formatter
代码格式化
src/Plugins/formatter/

Design System Rules

设计系统规则

✅ DO (Best Practices)

✅ 最佳实践

tsx
// 1. Use Ant Design tokens
const useStyles = createStyles(({ token }) => ({
  container: {
    padding: token.padding,           // ✅ Not '16px'
    color: token.colorText,           // ✅ Not '#000'
    borderRadius: token.borderRadius, // ✅ Not '6px'
  },
}));

// 2. Complete TypeScript types
interface MyComponentProps {
  onSelect?: (item: Item) => void;  // ✅ on prefix
  config?: MyConfig;                 // ✅ Config suffix
}

// 3. CSS-in-JS pattern
import { createStyles } from '@ant-design/cssinjs';
tsx
// 1. 使用Ant Design令牌
const useStyles = createStyles(({ token }) => ({
  container: {
    padding: token.padding,           // ✅ 避免使用'16px'
    color: token.colorText,           // ✅ 避免使用'#000'
    borderRadius: token.borderRadius, // ✅ 避免使用'6px'
  },
}));

// 2. 完整的TypeScript类型定义
interface MyComponentProps {
  onSelect?: (item: Item) => void;  // ✅ 使用on前缀
  config?: MyConfig;                 // ✅ 使用Config后缀
}

// 3. CSS-in-JS模式
import { createStyles } from '@ant-design/cssinjs';

❌ DON'T (Anti-Patterns)

❌ 反模式

tsx
// 1. Hardcoded values
padding: '16px',           // ❌ Use token.padding
color: '#1890ff',          // ❌ Use token.colorPrimary
backgroundColor: 'white',  // ❌ Use token.colorBgContainer

// 2. Any types
props: any                 // ❌ Define proper interface

// 3. Inline styles
style={{ padding: 16 }}    // ❌ Use createStyles

// 4. Wrong event naming
handleClick               // ❌ Use onClick
tsx
// 1. 硬编码值
padding: '16px',           // ❌ 使用token.padding
color: '#1890ff',          // ❌ 使用token.colorPrimary
backgroundColor: 'white',  // ❌ 使用token.colorBgContainer

// 2. Any类型
props: any                 // ❌ 定义合适的接口

// 3. 内联样式
style={{ padding: 16 }}    // ❌ 使用createStyles

// 4. 错误的事件命名
handleClick               // ❌ 使用onClick

File Structure Pattern

文件结构规范

ComponentName/
├── components/     # 子组件
├── hooks/          # 自定义 Hook (useXxx.ts)
├── types/          # 类型定义
├── __tests__/      # 测试文件 (ComponentName.test.tsx)
├── index.tsx       # 主组件入口
└── style.ts        # CSS-in-JS 样式
ComponentName/
├── components/     # 子组件
├── hooks/          # 自定义Hook(useXxx.ts)
├── types/          # 类型定义
├── __tests__/      # 测试文件(ComponentName.test.tsx)
├── index.tsx       # 主组件入口
└── style.ts        # CSS-in-JS样式

Pre-Delivery Checklist

交付前检查清单

Before completing any component task:
[ ] Uses @ant-design/cssinjs createStyles
[ ] All colors from token system
[ ] TypeScript types complete (no `any`)
[ ] Event handlers with `on` prefix
[ ] BEM class naming (.component__element--modifier)
[ ] Unit tests included
[ ] Proper error boundaries
[ ] Accessibility (aria-* attributes)
[ ] Performance (React.memo, useMemo, useCallback)
完成任何组件任务前,请检查:
[ ] 使用@ant-design/cssinjs的createStyles
[ ] 所有颜色来自令牌系统
[ ] TypeScript类型定义完整(无`any`类型)
[ ] 事件处理函数使用`on`前缀
[ ] BEM类命名规范(.component__element--modifier)
[ ] 包含单元测试
[ ] 合适的错误边界
[ ] 可访问性(aria-*属性)
[ ] 性能优化(React.memo、useMemo、useCallback)

Search Command Reference

搜索命令参考

Available Domains

可用域

DomainContentExample Keywords
component
37 个 UI 组件bubble, chat, layout, editor, thought, task, workspace
plugin
5 个 Markdown 插件chart, code, katex, mermaid, formatter
hook
12 个 React Hooksscroll, size, speech, click, language, intersection
token
51 个设计令牌color, padding, font, border, shadow, motion
内容示例关键词
component
37个UI组件bubble, chat, layout, editor, thought, task, workspace
plugin
5个Markdown插件chart, code, katex, mermaid, formatter
hook
12个React Hooksscroll, size, speech, click, language, intersection
token
51个设计令牌color, padding, font, border, shadow, motion

Command Options

命令选项

bash
undefined
bash
undefined

基本搜索

基本搜索

python .cursor/skills/agentic-ui-development/scripts/search.py "query"
python .cursor/skills/agentic-ui-development/scripts/search.py "query"

指定域搜索

指定域搜索

python .cursor/skills/agentic-ui-development/scripts/search.py "query" --domain component
python .cursor/skills/agentic-ui-development/scripts/search.py "query" --domain component

获取推荐方案

获取推荐方案

python .cursor/skills/agentic-ui-development/scripts/search.py "query" --recommend
python .cursor/skills/agentic-ui-development/scripts/search.py "query" --recommend

生成设计系统 (--project-name 可简写为 -p)

生成设计系统(--project-name可简写为-p)

python .cursor/skills/agentic-ui-development/scripts/search.py "query" --design-system --project-name "Project"
python .cursor/skills/agentic-ui-development/scripts/search.py "query" --design-system --project-name "Project"

持久化设计系统

持久化设计系统

python .cursor/skills/agentic-ui-development/scripts/search.py "query" --design-system --persist --project-name "Project" --page "page"
python .cursor/skills/agentic-ui-development/scripts/search.py "query" --design-system --persist --project-name "Project" --page "page"

输出格式 (--format 可简写为 -f)

输出格式(--format可简写为-f)

python .cursor/skills/agentic-ui-development/scripts/search.py "query" --format json # JSON python .cursor/skills/agentic-ui-development/scripts/search.py "query" --format markdown # Markdown python .cursor/skills/agentic-ui-development/scripts/search.py "query" --format ascii # ASCII (default)
python .cursor/skills/agentic-ui-development/scripts/search.py "query" --format json # JSON格式 python .cursor/skills/agentic-ui-development/scripts/search.py "query" --format markdown # Markdown格式 python .cursor/skills/agentic-ui-development/scripts/search.py "query" --format ascii # ASCII格式(默认)

限制结果数量 (--limit 可简写为 -n)

限制结果数量(--limit可简写为-n)

python .cursor/skills/agentic-ui-development/scripts/search.py "query" --limit 3
undefined
python .cursor/skills/agentic-ui-development/scripts/search.py "query" --limit 3
undefined

Example: Design System Output

示例:设计系统输出

+------------------------------------------------------------------------------------------+
|  TARGET: MY AI APP - AGENTIC UI RECOMMENDATION
+------------------------------------------------------------------------------------------+
|
|  QUERY: ai chat assistant
|  RULE MATCHED: ai-assistant
|
|  RECOMMENDED COMPONENTS:
|     Bubble.AIBubble, ThoughtChainList, ToolUseBar, WelcomeMessage
|
|  RECOMMENDED HOOKS:
|     useAutoScroll, useSpeechSynthesis
|
|  RECOMMENDED PLUGINS:
|     N/A
|
|  KEY TOKENS:
|     colorPrimary, colorSuccess, motionDurationMid
|
|  STYLE PRIORITY:
|     modern, glassmorphism, dark-mode
|
|  ANTI-PATTERNS (AVOID):
|     ❌ No thought chain for AI
|     ❌ Missing streaming support
|     ❌ No tool call visibility
|
|  PRE-DELIVERY CHECKLIST:
|     [ ] Uses @ant-design/cssinjs createStyles
|     [ ] All colors from token system
|     [ ] TypeScript types complete (no any)
|     [ ] Event handlers with 'on' prefix
|     [ ] BEM class naming
|     [ ] Unit tests included (≥80% coverage)
|     [ ] Proper error boundaries
|
+------------------------------------------------------------------------------------------+
+------------------------------------------------------------------------------------------+
|  目标: MY AI APP - AGENTIC UI推荐方案
+------------------------------------------------------------------------------------------+
|
|  查询词: ai chat assistant
|  匹配规则: ai-assistant
|
|  推荐组件:
|     Bubble.AIBubble, ThoughtChainList, ToolUseBar, WelcomeMessage
|
|  推荐Hooks:
|     useAutoScroll, useSpeechSynthesis
|
|  推荐插件:
|     无
|
|  关键令牌:
|     colorPrimary, colorSuccess, motionDurationMid
|
|  样式优先级:
|     modern, glassmorphism, dark-mode
|
|  反模式(需避免):
|     ❌ AI无思维链展示
|     ❌ 缺少流式支持
|     ❌ 无工具调用可见性
|
|  交付前检查清单:
|     [ ] 使用@ant-design/cssinjs的createStyles
|     [ ] 所有颜色来自令牌系统
|     [ ] TypeScript类型定义完整(无any)
|     [ ] 事件处理函数使用'on'前缀
|     [ ] BEM类命名
|     [ ] 包含单元测试(覆盖率≥80%)
|     [ ] 合适的错误边界
|
+------------------------------------------------------------------------------------------+

Data Files

数据文件

FileContent
data/components.csv
37 个组件数据
data/plugins.csv
5 个插件数据
data/hooks.csv
12 个 Hooks 数据
data/tokens.csv
51 个设计令牌
data/reasoning-rules.json
15 条推理规则
文件内容
data/components.csv
37个组件数据
data/plugins.csv
5个插件数据
data/hooks.csv
12个Hooks数据
data/tokens.csv
51个设计令牌
data/reasoning-rules.json
15条推理规则

Design Tokens (Quick Reference)

设计令牌快速参考

使用 Ant Design Token 系统,禁止硬编码值。
使用Ant Design令牌系统,禁止硬编码值。

Color Tokens

颜色令牌

TokenDescription
colorPrimary
主色
colorSuccess
成功色
colorWarning
警告色
colorError
错误色
colorText
主文本
colorTextSecondary
次要文本
colorBgContainer
容器背景
colorBorder
边框色
令牌描述
colorPrimary
主色
colorSuccess
成功色
colorWarning
警告色
colorError
错误色
colorText
主文本色
colorTextSecondary
次要文本色
colorBgContainer
容器背景色
colorBorder
边框色

Spacing Tokens

间距令牌

TokenValue
paddingXS
8px
paddingSM
12px
padding
16px
paddingLG
24px
令牌
paddingXS
8px
paddingSM
12px
padding
16px
paddingLG
24px

Usage

使用示例

tsx
const useStyles = createStyles(({ token }) => ({
  container: {
    padding: token.padding,        // DO: token
    color: token.colorText,        // DO: token
    // padding: '16px',            // DON'T: hardcode
  },
}));
tsx
const useStyles = createStyles(({ token }) => ({
  container: {
    padding: token.padding,        // 推荐:使用令牌
    color: token.colorText,        // 推荐:使用令牌
    // padding: '16px',            // 禁止:硬编码
  },
}));

Plugins (Quick Reference)

插件快速参考

PluginPurposeUsage
chart
图表渲染
<LineChart data={...} />
code
代码高亮
<CodeBlock code={...} language="ts" />
katex
数学公式
<Katex formula="E=mc^2" />
mermaid
图表渲染
<Mermaid chart={...} />
tsx
<MarkdownEditor plugins={['code', 'katex', 'mermaid', 'chart']} />

插件用途使用方式
chart
图表渲染
<LineChart data={...} />
code
代码高亮
<CodeBlock code={...} language="ts" />
katex
数学公式
<Katex formula="E=mc^2" />
mermaid
图表渲染
<Mermaid chart={...} />
tsx
<MarkdownEditor plugins={['code', 'katex', 'mermaid', 'chart']} />

Component API Examples

组件API示例

Bubble

Bubble

tsx
import { Bubble } from '@ant-design/agentic-ui';

<Bubble.AIBubble
  content="分析完成"
  thoughtChain={[
    { type: 'thought', content: '分析需求' },
    { type: 'action', content: '执行查询' },
  ]}
  status="success"
  streaming={true}
/>

<Bubble.UserBubble content="请分析数据" avatar={{ src: '/avatar.png' }} />
tsx
import { Bubble } from '@ant-design/agentic-ui';

<Bubble.AIBubble
  content="分析完成"
  thoughtChain={[
    { type: 'thought', content: '分析需求' },
    { type: 'action', content: '执行查询' },
  ]}
  status="success"
  streaming={true}
/>

<Bubble.UserBubble content="请分析数据" avatar={{ src: '/avatar.png' }} />

ThoughtChainList

ThoughtChainList

tsx
import { ThoughtChainList } from '@ant-design/agentic-ui';

<ThoughtChainList
  items={[
    { type: 'thought', title: '分析', status: 'completed' },
    { type: 'action', title: '执行', status: 'loading', costMillis: 234 },
  ]}
  collapsed={false}
  onToggle={(collapsed) => {}}
/>
tsx
import { ThoughtChainList } from '@ant-design/agentic-ui';

<ThoughtChainList
  items={[
    { type: 'thought', title: '分析', status: 'completed' },
    { type: 'action', title: '执行', status: 'loading', costMillis: 234 },
  ]}
  collapsed={false}
  onToggle={(collapsed) => {}}
/>

ToolUseBar

ToolUseBar

tsx
import { ToolUseBar } from '@ant-design/agentic-ui';

<ToolUseBar
  name="搜索工具"
  status="success"
  params={{ query: 'React' }}
  result={{ items: [...], count: 10 }}
  costMillis={1234}
/>
tsx
import { ToolUseBar } from '@ant-design/agentic-ui';

<ToolUseBar
  name="搜索工具"
  status="success"
  params={{ query: 'React' }}
  result={{ items: [...], count: 10 }}
  costMillis={1234}
/>

MarkdownEditor

MarkdownEditor

tsx
import { MarkdownEditor } from '@ant-design/agentic-ui';

<MarkdownEditor
  value={markdown}
  onChange={setMarkdown}
  plugins={['code', 'katex', 'mermaid']}
  toolbar={{ bold: true, italic: true, code: true }}
/>
tsx
import { MarkdownEditor } from '@ant-design/agentic-ui';

<MarkdownEditor
  value={markdown}
  onChange={setMarkdown}
  plugins={['code', 'katex', 'mermaid']}
  toolbar={{ bold: true, italic: true, code: true }}
/>

Workspace

Workspace

tsx
import Workspace from '@ant-design/agentic-ui';

<Workspace
  activeKey="file"
  tabs={[
    { key: 'browser', title: '浏览器', content: <BrowserPreview /> },
    { key: 'file', title: '文件', content: <FileViewer /> },
  ]}
  onTabChange={(key) => {}}
/>

tsx
import Workspace from '@ant-design/agentic-ui';

<Workspace
  activeKey="file"
  tabs={[
    { key: 'browser', title: '浏览器', content: <BrowserPreview /> },
    { key: 'file', title: '文件', content: <FileViewer /> },
  ]}
  onTabChange={(key) => {}}
/>

Code Templates

代码模板

Component Template

组件模板

tsx
import React from 'react';
import { createStyles } from '@ant-design/cssinjs';

export interface {{ComponentName}}Props {
  className?: string;
  children?: React.ReactNode;
  onSelect?: (value: string) => void;
}

const useStyles = createStyles(({ token }) => ({
  container: {
    padding: token.padding,
    backgroundColor: token.colorBgContainer,
    borderRadius: token.borderRadius,
  },
}));

export const {{ComponentName}}: React.FC<{{ComponentName}}Props> = ({
  className, children, onSelect,
}) => {
  const { styles, cx } = useStyles();
  return <div className={cx(styles.container, className)}>{children}</div>;
};
tsx
import React from 'react';
import { createStyles } from '@ant-design/cssinjs';

export interface {{ComponentName}}Props {
  className?: string;
  children?: React.ReactNode;
  onSelect?: (value: string) => void;
}

const useStyles = createStyles(({ token }) => ({
  container: {
    padding: token.padding,
    backgroundColor: token.colorBgContainer,
    borderRadius: token.borderRadius,
  },
}));

export const {{ComponentName}}: React.FC<{{ComponentName}}Props> = ({
  className, children, onSelect,
}) => {
  const { styles, cx } = useStyles();
  return <div className={cx(styles.container, className)}>{children}</div>;
};

Hook Template

Hook模板

tsx
import { useState, useCallback } from 'react';

export const use{{HookName}} = (defaultValue = '') => {
  const [value, setValue] = useState(defaultValue);
  const reset = useCallback(() => setValue(defaultValue), [defaultValue]);
  return { value, setValue, reset };
};
tsx
import { useState, useCallback } from 'react';

export const use{{HookName}} = (defaultValue = '') => {
  const [value, setValue] = useState(defaultValue);
  const reset = useCallback(() => setValue(defaultValue), [defaultValue]);
  return { value, setValue, reset };
};

Test Template

测试模板

tsx
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, it, expect, vi } from 'vitest';

describe('{{ComponentName}}', () => {
  it('should render', () => {
    render(<{{ComponentName}} />);
    expect(screen.getByRole('button')).toBeInTheDocument();
  });

  it('should handle click', async () => {
    const onClick = vi.fn();
    render(<{{ComponentName}} onClick={onClick} />);
    await userEvent.click(screen.getByRole('button'));
    expect(onClick).toHaveBeenCalledTimes(1);
  });
});
tsx
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, it, expect, vi } from 'vitest';

describe('{{ComponentName}}', () => {
  it('should render', () => {
    render(<{{ComponentName}} />);
    expect(screen.getByRole('button')).toBeInTheDocument();
  });

  it('should handle click', async () => {
    const onClick = vi.fn();
    render(<{{ComponentName}} onClick={onClick} />);
    await userEvent.click(screen.getByRole('button'));
    expect(onClick).toHaveBeenCalledTimes(1);
  });
});

Test Commands

测试命令

bash
pnpm test             # 单元测试
pnpm test:coverage    # 带覆盖率 (>=80%)
pnpm test:e2e         # E2E 测试

bash
pnpm test             # 单元测试
pnpm test:coverage    # 覆盖率测试(要求≥80%)
pnpm test:e2e         # E2E测试

Commit Convention

提交规范

<type>(<scope>): <description>

Types: feat | fix | docs | style | refactor | perf | test | chore
Scopes: bubble | editor | workspace | history | plugin | core
Examples:
  • feat(bubble): add streaming text animation
  • fix(editor): resolve cursor position issue
  • test(thought-chain): add unit tests for ToolCall
<type>(<scope>): <description>

Types: feat | fix | docs | style | refactor | perf | test | chore
Scopes: bubble | editor | workspace | history | plugin | core
示例:
  • feat(bubble): add streaming text animation
  • fix(editor): resolve cursor position issue
  • test(thought-chain): add unit tests for ToolCall