polpo-react
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为根URL — 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 — 自定义组合(子组件替换默认输入框)
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配置