@cloudbase/agent-react-ui 0.0.23
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/README.md +135 -0
- package/components.json +21 -0
- package/dist/index.css +4241 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +59 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +2169 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2182 -0
- package/dist/index.mjs.map +1 -0
- package/example/.env.sample +2 -0
- package/example/App.tsx +368 -0
- package/example/app.css +1 -0
- package/example/index.html +12 -0
- package/example/main.tsx +9 -0
- package/example/vite.config.ts +34 -0
- package/package.json +75 -0
- package/postcss.config.cjs +3 -0
- package/src/components/ai-elements/agent.tsx +140 -0
- package/src/components/ai-elements/artifact.tsx +147 -0
- package/src/components/ai-elements/attachments.tsx +421 -0
- package/src/components/ai-elements/audio-player.tsx +228 -0
- package/src/components/ai-elements/canvas.tsx +22 -0
- package/src/components/ai-elements/chain-of-thought.tsx +228 -0
- package/src/components/ai-elements/checkpoint.tsx +71 -0
- package/src/components/ai-elements/code-block.tsx +532 -0
- package/src/components/ai-elements/commit.tsx +448 -0
- package/src/components/ai-elements/confirmation.tsx +176 -0
- package/src/components/ai-elements/connection.tsx +28 -0
- package/src/components/ai-elements/context.tsx +408 -0
- package/src/components/ai-elements/controls.tsx +18 -0
- package/src/components/ai-elements/conversation.tsx +100 -0
- package/src/components/ai-elements/edge.tsx +140 -0
- package/src/components/ai-elements/environment-variables.tsx +295 -0
- package/src/components/ai-elements/file-tree.tsx +258 -0
- package/src/components/ai-elements/image.tsx +24 -0
- package/src/components/ai-elements/inline-citation.tsx +287 -0
- package/src/components/ai-elements/message.tsx +336 -0
- package/src/components/ai-elements/mic-selector.tsx +370 -0
- package/src/components/ai-elements/model-selector.tsx +211 -0
- package/src/components/ai-elements/node.tsx +71 -0
- package/src/components/ai-elements/open-in-chat.tsx +365 -0
- package/src/components/ai-elements/package-info.tsx +233 -0
- package/src/components/ai-elements/panel.tsx +15 -0
- package/src/components/ai-elements/persona.tsx +270 -0
- package/src/components/ai-elements/plan.tsx +142 -0
- package/src/components/ai-elements/prompt-input.tsx +1263 -0
- package/src/components/ai-elements/queue.tsx +274 -0
- package/src/components/ai-elements/reasoning.tsx +193 -0
- package/src/components/ai-elements/sandbox.tsx +126 -0
- package/src/components/ai-elements/schema-display.tsx +458 -0
- package/src/components/ai-elements/shimmer.tsx +64 -0
- package/src/components/ai-elements/snippet.tsx +139 -0
- package/src/components/ai-elements/sources.tsx +77 -0
- package/src/components/ai-elements/speech-input.tsx +301 -0
- package/src/components/ai-elements/stack-trace.tsx +482 -0
- package/src/components/ai-elements/suggestion.tsx +53 -0
- package/src/components/ai-elements/task.tsx +87 -0
- package/src/components/ai-elements/terminal.tsx +261 -0
- package/src/components/ai-elements/test-results.tsx +485 -0
- package/src/components/ai-elements/tool.tsx +174 -0
- package/src/components/ai-elements/toolbar.tsx +16 -0
- package/src/components/ai-elements/transcription.tsx +124 -0
- package/src/components/ai-elements/voice-selector.tsx +479 -0
- package/src/components/ai-elements/web-preview.tsx +263 -0
- package/src/components/chat/Chat.tsx +178 -0
- package/src/components/chat/Input.tsx +98 -0
- package/src/components/chat/Message.tsx +276 -0
- package/src/components/chat/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/components/ui/accordion.tsx +64 -0
- package/src/components/ui/alert.tsx +66 -0
- package/src/components/ui/avatar.tsx +107 -0
- package/src/components/ui/badge.tsx +48 -0
- package/src/components/ui/button-group.tsx +83 -0
- package/src/components/ui/button.tsx +64 -0
- package/src/components/ui/card.tsx +92 -0
- package/src/components/ui/carousel.tsx +239 -0
- package/src/components/ui/collapsible.tsx +31 -0
- package/src/components/ui/command.tsx +184 -0
- package/src/components/ui/dialog.tsx +158 -0
- package/src/components/ui/dropdown-menu.tsx +257 -0
- package/src/components/ui/hover-card.tsx +42 -0
- package/src/components/ui/input-group.tsx +168 -0
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/popover.tsx +87 -0
- package/src/components/ui/progress.tsx +31 -0
- package/src/components/ui/scroll-area.tsx +56 -0
- package/src/components/ui/select.tsx +190 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/spinner.tsx +16 -0
- package/src/components/ui/switch.tsx +33 -0
- package/src/components/ui/tabs.tsx +91 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/tooltip.tsx +61 -0
- package/src/css/global.css +123 -0
- package/src/css/index.css +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-copy-to-clipboard.ts +31 -0
- package/src/index.ts +4 -0
- package/src/lib/utils.ts +6 -0
- package/src/locales/context.ts +8 -0
- package/src/locales/hooks.ts +20 -0
- package/src/locales/index.ts +3 -0
- package/src/locales/langs/en.ts +17 -0
- package/src/locales/langs/index.ts +12 -0
- package/src/locales/langs/zh-cn.ts +18 -0
- package/tsconfig.json +21 -0
- package/tsup.config.ts +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# @cloudbase/agent-react-ui
|
|
2
|
+
|
|
3
|
+
`@cloudbase/agent-react-ui` 提供可直接接入项目的 React 聊天界面组件,适用于希望快速完成 AG-Kit 聊天窗口搭建的场景。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @cloudbase/agent-react-core @cloudbase/agent-react-ui
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 样式引入
|
|
12
|
+
|
|
13
|
+
包入口已经包含样式导入:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import "./css/index.css";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
在常规的 React 构建环境中,直接使用组件即可。如果需要手动引入构建后的样式文件,可以使用:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import "@cloudbase/agent-react-ui/styles.css";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 快速开始
|
|
26
|
+
|
|
27
|
+
`AgKitUI` 依赖 `@cloudbase/agent-react-core` 提供的运行时上下文,因此需要与 `AgKit` 一起使用。
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import cloudbase from "@cloudbase/js-sdk";
|
|
31
|
+
import { AgKit, CloudBaseTransport } from "@cloudbase/agent-react-core";
|
|
32
|
+
import { AgKitUI } from "@cloudbase/agent-react-ui";
|
|
33
|
+
|
|
34
|
+
const app = cloudbase.init({ env: "your-env-id" });
|
|
35
|
+
const transport = new CloudBaseTransport({
|
|
36
|
+
app,
|
|
37
|
+
agentId: "your-agent-id",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export function App() {
|
|
41
|
+
return (
|
|
42
|
+
<AgKit transport={transport}>
|
|
43
|
+
<div style={{ height: "600px" }}>
|
|
44
|
+
<AgKitUI />
|
|
45
|
+
</div>
|
|
46
|
+
</AgKit>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## API 参考
|
|
54
|
+
|
|
55
|
+
### `AgKitUI`
|
|
56
|
+
|
|
57
|
+
核心聊天界面组件,内置了完整的消息渲染、工具调用展示、输入框和国际化支持。
|
|
58
|
+
|
|
59
|
+
#### `AgKitUIProps`
|
|
60
|
+
|
|
61
|
+
| 选项 | 必填 | 类型 | 说明 |
|
|
62
|
+
| --- | --- | --- | --- |
|
|
63
|
+
| `className` | 否 | `string` | 聊天主体布局类名 |
|
|
64
|
+
| `containerClassName` | 否 | `string` | 最外层根容器类名 |
|
|
65
|
+
| `messagesClassName` | 否 | `string` | 消息列表区域类名 |
|
|
66
|
+
| `inputClassName` | 否 | `string` | 输入框包裹层类名 |
|
|
67
|
+
| `emptyTitleClassName` | 否 | `string` | 空状态标题类名 |
|
|
68
|
+
| `inputPlaceholder` | 否 | `string` | 输入框占位文本,未提供时使用 locale 默认值 |
|
|
69
|
+
| `suggestions` | 否 | `string[]` | 聊天为空时显示的建议问题列表 |
|
|
70
|
+
| `locale` | 否 | `LocaleCode` | 内置 UI 文案语言,默认 `"zh-CN"` |
|
|
71
|
+
| `onSuggestionClick` | 否 | `(suggestion: string) => void` | 点击建议问题时触发的回调 |
|
|
72
|
+
|
|
73
|
+
#### 示例:基础用法
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
<AgKitUI />
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### 示例:自定义建议与语言
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
<AgKitUI
|
|
83
|
+
locale="zh-CN"
|
|
84
|
+
inputPlaceholder="输入你的问题"
|
|
85
|
+
suggestions={[
|
|
86
|
+
"帮我总结今天的工作",
|
|
87
|
+
"生成一份周报模板",
|
|
88
|
+
"解释这个接口的用途",
|
|
89
|
+
]}
|
|
90
|
+
onSuggestionClick={(value) => {
|
|
91
|
+
console.log("clicked suggestion:", value);
|
|
92
|
+
}}
|
|
93
|
+
/>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### 示例:自定义样式
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
<AgKitUI
|
|
100
|
+
containerClassName="my-chat-container"
|
|
101
|
+
messagesClassName="my-messages"
|
|
102
|
+
inputClassName="my-input"
|
|
103
|
+
emptyTitleClassName="my-empty-title"
|
|
104
|
+
/>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### `LocaleCode`
|
|
110
|
+
|
|
111
|
+
内置语言类型,用于指定 `AgKitUI` 的 UI 文案语言。
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
type LocaleCode = "zh-CN" | "en-US";
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
| 值 | 说明 |
|
|
118
|
+
| --- | --- |
|
|
119
|
+
| `"zh-CN"` | 简体中文(默认) |
|
|
120
|
+
| `"en-US"` | 英语 |
|
|
121
|
+
|
|
122
|
+
可直接用于业务代码中的类型标注:
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
import { type LocaleCode } from "@cloudbase/agent-react-ui";
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 使用说明
|
|
131
|
+
|
|
132
|
+
接入时通常由 `@cloudbase/agent-react-core` 提供运行时能力,包括消息状态、发送逻辑、工具注册和传输层;`@cloudbase/agent-react-ui` 负责聊天界面展示。
|
|
133
|
+
|
|
134
|
+
如果需要快速接入默认聊天窗口,通常只需完成运行时初始化后渲染 `AgKitUI` 即可。
|
|
135
|
+
|
package/components.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
+
"style": "new-york",
|
|
4
|
+
"rsc": false,
|
|
5
|
+
"tsx": true,
|
|
6
|
+
"tailwind": {
|
|
7
|
+
"config": "",
|
|
8
|
+
"css": "src/styles/globals.css",
|
|
9
|
+
"baseColor": "neutral",
|
|
10
|
+
"cssVariables": true,
|
|
11
|
+
"prefix": ""
|
|
12
|
+
},
|
|
13
|
+
"aliases": {
|
|
14
|
+
"components": "@/components",
|
|
15
|
+
"utils": "@/lib/utils",
|
|
16
|
+
"ui": "@/components/ui",
|
|
17
|
+
"lib": "@/lib",
|
|
18
|
+
"hooks": "@/hooks"
|
|
19
|
+
},
|
|
20
|
+
"iconLibrary": "lucide"
|
|
21
|
+
}
|