polpo-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePolpo UI
Polpo UI
Composable React chat components for Polpo AI agents. Three composition levels, three installation methods.
专为Polpo AI Agent打造的可组合React聊天组件,提供三种组合层级与三种安装方式。
Install
安装
New project
新建项目
bash
undefinedbash
undefinedInteractive
交互式
npx create-polpo-app
npx create-polpo-app
Non-interactive (CI / AI agents)
非交互式(CI / AI Agent场景)
npx create-polpo-app my-app -t chat -y
npx create-polpo-app my-app -t chat-widget -y
npx create-polpo-app my-app -t multi-agent -y
undefinednpx create-polpo-app my-app -t chat -y
npx create-polpo-app my-app -t chat-widget -y
npx create-polpo-app my-app -t multi-agent -y
undefinedAdd to existing project (shadcn-style, copies source)
添加到现有项目(shadcn风格,复制源码)
bash
undefinedbash
undefinedInteractive multi-select
交互式多选
npx @polpo-ai/ui add
npx @polpo-ai/ui add
Non-interactive
非交互式
npx @polpo-ai/ui add --all
npx @polpo-ai/ui add tools hooks --overwrite
undefinednpx @polpo-ai/ui add --all
npx @polpo-ai/ui add tools hooks --overwrite
undefinednpm package (compiled)
npm包(已编译)
bash
npm install @polpo-ai/chat @polpo-ai/sdk @polpo-ai/react react-virtuoso lucide-react streamdownConsumer adds Tailwind scanning:
css
/* Tailwind v4 */
@source "../node_modules/@polpo-ai/chat/dist/**/*.js";js
// Tailwind v3 — tailwind.config.js
content: ["./node_modules/@polpo-ai/chat/dist/**/*.js"]bash
npm install @polpo-ai/chat @polpo-ai/sdk @polpo-ai/react react-virtuoso lucide-react streamdown使用者需要添加Tailwind扫描规则:
css
/* Tailwind v4 */
@source "../node_modules/@polpo-ai/chat/dist/**/*.js";js
// Tailwind v3 — tailwind.config.js
content: ["./node_modules/@polpo-ai/chat/dist/**/*.js"]Provider Setup
Provider配置
tsx
import { PolpoProvider } from "@polpo-ai/react";
// baseUrl is root URL — SDK appends /v1/ internally. Do NOT add /v1/.
<PolpoProvider baseUrl="https://api.polpo.sh" apiKey={process.env.NEXT_PUBLIC_POLPO_API_KEY} autoConnect={false}>
{children}
</PolpoProvider>tsx
import { PolpoProvider } from "@polpo-ai/react";
// baseUrl是根地址 — SDK内部会自动拼接 /v1/,请勿自行添加 /v1/
<PolpoProvider baseUrl="https://api.polpo.sh" apiKey={process.env.NEXT_PUBLIC_POLPO_API_KEY} autoConnect={false}>
{children}
</PolpoProvider>Composition Levels
组合层级
Level 1 — Zero Config
层级1 — 零配置
tsx
<Chat agent="coder" sessionId="session_abc" />tsx
<Chat agent="coder" sessionId="session_abc" />Level 2 — Compose (children replace default input)
层级2 — 自定义组合(children替换默认输入框)
tsx
<Chat agent="coder" avatar={<Avatar />}>
<MyCustomInput />
</Chat>tsx
<Chat agent="coder" avatar={<Avatar />}>
<MyCustomInput />
</Chat>Level 3 — Primitives
层级3 — 基础原语
tsx
import { ChatMessage, ChatSkeleton } from "@polpo-ai/chat";
import { useChat } from "@polpo-ai/react";tsx
import { ChatMessage, ChatSkeleton } from "@polpo-ai/chat";
import { useChat } from "@polpo-ai/react";Render Function Pattern
渲染函数模式
tsx
<Chat agent="coder" onSessionCreated={(id) => router.replace(`/chat/${id}`)}>
{({ hasMessages }) => hasMessages ? <ChatInput /> : <LandingPage />}
</Chat>tsx
<Chat agent="coder" onSessionCreated={(id) => router.replace(`/chat/${id}`)}>
{({ hasMessages }) => hasMessages ? <ChatInput /> : <LandingPage />}
</Chat>Session Navigation
会话导航
Package does NOT handle routing. Use callback:
onSessionCreatedtsx
<Chat onSessionCreated={(id) => router.push(`/chat/${id}`)} />本包不处理路由逻辑,请使用回调:
onSessionCreatedtsx
<Chat onSessionCreated={(id) => router.push(`/chat/${id}`)} />Components
组件
| Component | Purpose |
|---|---|
| Root compound — Provider + Messages + Input |
| Textarea + submit + file attach + drag & drop |
| Message dispatcher (user/assistant) |
| Virtuoso list with auto-scroll |
| Context wrapping useChat + useFiles |
| Flat session list with select/delete |
| Sessions grouped by agent |
| Agent picker dropdown |
| Suggestion button grid |
| Ask-user-question wizard |
| Landing + greeting + input + suggestions |
| Scroll-to-bottom indicator |
| Loading skeleton |
| Typing dots |
| Auto-dispatching tool renderer |
| Base tool renderer with expand/collapse |
| 组件名 | 用途 |
|---|---|
| 根复合组件 — Provider + 消息列表 + 输入框 |
| 文本域 + 提交 + 附件上传 + 拖拽功能 |
| 消息分发器(用户/助手) |
| 支持自动滚动的Virtuoso列表 |
| 封装useChat + useFiles的上下文 |
| 支持选择/删除的扁平会话列表 |
| 按Agent分组的会话列表 |
| Agent选择下拉框 |
| 建议按钮网格 |
| 询问用户问题的向导组件 |
| 落地页 + 问候语 + 输入框 + 建议 |
| 滚动到底部指示器 |
| 加载骨架屏 |
| 输入中动画点 |
| 自动分发的工具渲染器 |
| 支持展开/收起的基础工具渲染器 |
Hooks
Hooks
tsx
const { messages, sendMessage, isStreaming, abort, uploadFile, pendingToolCall } = useChatContext();
const handleSubmit = useSubmitHandler(sendMessage, uploadFile);
const dragging = useDocumentDrag();tsx
const { messages, sendMessage, isStreaming, abort, uploadFile, pendingToolCall } = useChatContext();
const handleSubmit = useSubmitHandler(sendMessage, uploadFile);
const dragging = useDocumentDrag();References
参考文档
- Component props: references/components.md — full props for every component
- Composition patterns: references/patterns.md — app assembly, ask-user, sessions, custom tools
- CLI commands: references/cli.md — create-polpo-app, @polpo-ai/ui, flags
- Theming: references/theming.md — colors, dark mode, fonts, Tailwind config
- 组件属性:references/components.md — 所有组件的完整属性说明
- 组合模式:references/patterns.md — 应用组装、用户询问、会话管理、自定义工具相关内容
- CLI命令:references/cli.md — create-polpo-app、@polpo-ai/ui 及相关参数说明
- 主题配置:references/theming.md — 颜色、暗黑模式、字体、Tailwind配置相关内容