@glodon-aiot/chat-app-sdk 0.0.1-alpha.0 → 0.0.1-alpha.10
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 +175 -395
- package/libs/cn/691.js +1 -0
- package/libs/cn/82.js +1 -0
- package/libs/cn/index.esm.js +9841 -0
- package/libs/cn/index.js +9833 -25
- package/libs/cn/ui.esm.js +1 -0
- package/libs/cn/ui.js +1 -0
- package/package.json +79 -26
- package/libs/cn/20b3a786936641cfc3f1.woff +0 -0
- package/libs/cn/370.index.js +0 -1
- package/libs/cn/3b463a742eb4fc6af330.woff +0 -0
- package/libs/cn/45e820d30a5fd2cc4e2c.woff +0 -0
- package/libs/cn/499.index.js +0 -1
- package/libs/cn/73b69d998db4040e7a78.ttf +0 -0
- package/libs/cn/75efda37b3ac85df0269.woff +0 -0
- package/libs/cn/9d134b22a904961eccbd.woff +0 -0
- package/libs/cn/a64f8bf72bb0b2fcf276.woff +0 -0
- package/src/index.ts +0 -56
- /package/libs/cn/{0bc2e602cc66a3e54313.ttf → KaTeX_AMS-Regular.ttf} +0 -0
- /package/libs/cn/{2f0974bc562d89351f32.woff → KaTeX_AMS-Regular.woff} +0 -0
- /package/libs/cn/{c495d43a0d46487e1215.woff2 → KaTeX_AMS-Regular.woff2} +0 -0
- /package/libs/cn/{cfa273c698f2f12d58d2.ttf → KaTeX_Caligraphic-Bold.ttf} +0 -0
- /package/libs/cn/{36ed1eb434c4ff55996d.ttf → KaTeX_Caligraphic-Regular.ttf} +0 -0
- /package/libs/cn/{19ff89da475e6a491574.ttf → KaTeX_Fraktur-Bold.ttf} +0 -0
- /package/libs/cn/{d7d858c0440aa348db86.woff → KaTeX_Fraktur-Bold.woff} +0 -0
- /package/libs/cn/{198f31fb0b960668858b.woff2 → KaTeX_Fraktur-Bold.woff2} +0 -0
- /package/libs/cn/{bef6c7c7c32c92df92f6.ttf → KaTeX_Fraktur-Regular.ttf} +0 -0
- /package/libs/cn/{e6e44e34a624a66d312e.woff → KaTeX_Fraktur-Regular.woff} +0 -0
- /package/libs/cn/{b0f052f32c31c2247a25.woff2 → KaTeX_Fraktur-Regular.woff2} +0 -0
- /package/libs/cn/{15cc128ce5f92ead6222.ttf → KaTeX_Main-Bold.ttf} +0 -0
- /package/libs/cn/{6e40d7383e914c04da08.woff → KaTeX_Main-Bold.woff} +0 -0
- /package/libs/cn/{2db73bfd18df63aa52ed.woff2 → KaTeX_Main-Bold.woff2} +0 -0
- /package/libs/cn/{7ae84599b0986b269126.ttf → KaTeX_Main-BoldItalic.ttf} +0 -0
- /package/libs/cn/{a1cb5c3e818dcdc30402.woff → KaTeX_Main-BoldItalic.woff} +0 -0
- /package/libs/cn/{5202dd00c92576ffca6b.woff2 → KaTeX_Main-BoldItalic.woff2} +0 -0
- /package/libs/cn/{0e69b1001a378eda1dbc.ttf → KaTeX_Main-Italic.ttf} +0 -0
- /package/libs/cn/{db4c312540301f0439e4.woff → KaTeX_Main-Italic.woff} +0 -0
- /package/libs/cn/{5774a4f3b6750f9ca2c9.woff2 → KaTeX_Main-Italic.woff2} +0 -0
- /package/libs/cn/{ff353c660240bd430cf7.ttf → KaTeX_Main-Regular.ttf} +0 -0
- /package/libs/cn/{2f948ca8dcb5d45d0adf.woff → KaTeX_Main-Regular.woff} +0 -0
- /package/libs/cn/{10e83d171fe909b7c788.woff2 → KaTeX_Main-Regular.woff2} +0 -0
- /package/libs/cn/{25db0c9fdf5beb90b80f.ttf → KaTeX_Math-BoldItalic.ttf} +0 -0
- /package/libs/cn/{cc04db54842aa3325249.woff → KaTeX_Math-BoldItalic.woff} +0 -0
- /package/libs/cn/{aaaff9d881fcc88398a7.woff2 → KaTeX_Math-BoldItalic.woff2} +0 -0
- /package/libs/cn/{606e58a4b51158c2e5e8.ttf → KaTeX_Math-Italic.ttf} +0 -0
- /package/libs/cn/{1c9e05f1d64d4aae424d.woff → KaTeX_Math-Italic.woff} +0 -0
- /package/libs/cn/{3820262345a90458e023.woff2 → KaTeX_Math-Italic.woff2} +0 -0
- /package/libs/cn/{dbf699c345a4fcb82dbc.ttf → KaTeX_SansSerif-Bold.ttf} +0 -0
- /package/libs/cn/{49fac6666fdc45c32d4c.woff → KaTeX_SansSerif-Bold.woff} +0 -0
- /package/libs/cn/{191c8b57897058906274.woff2 → KaTeX_SansSerif-Bold.woff2} +0 -0
- /package/libs/cn/{8e40cfcedbcf772f22b3.ttf → KaTeX_SansSerif-Italic.ttf} +0 -0
- /package/libs/cn/{ed5269940634eb8f087a.woff → KaTeX_SansSerif-Italic.woff} +0 -0
- /package/libs/cn/{3860d63afacff91e989d.woff2 → KaTeX_SansSerif-Italic.woff2} +0 -0
- /package/libs/cn/{e5fd156ab3c95038cd2d.ttf → KaTeX_SansSerif-Regular.ttf} +0 -0
- /package/libs/cn/{2b93b44796a4f8b26cf6.woff → KaTeX_SansSerif-Regular.woff} +0 -0
- /package/libs/cn/{0b20fb70b00e9978d451.woff2 → KaTeX_SansSerif-Regular.woff2} +0 -0
- /package/libs/cn/{ed3db117a76bdf748332.ttf → KaTeX_Script-Regular.ttf} +0 -0
- /package/libs/cn/{0e4124b737f0eb97855e.woff → KaTeX_Script-Regular.woff} +0 -0
- /package/libs/cn/{fa58920dcf7e22cf8d31.woff2 → KaTeX_Script-Regular.woff2} +0 -0
- /package/libs/cn/{045b7ccec156e6d4b5b0.ttf → KaTeX_Size1-Regular.ttf} +0 -0
- /package/libs/cn/{be3996a0947a66ac0ca6.ttf → KaTeX_Size2-Regular.ttf} +0 -0
- /package/libs/cn/{f360703aab4265f37de0.ttf → KaTeX_Size4-Regular.ttf} +0 -0
- /package/libs/cn/{b7ca898607a9e3565f1b.ttf → KaTeX_Typewriter-Regular.ttf} +0 -0
- /package/libs/cn/{eda854fce5f3a1bd8af9.woff → KaTeX_Typewriter-Regular.woff} +0 -0
- /package/libs/cn/{58548567678bf4ea8267.woff2 → KaTeX_Typewriter-Regular.woff2} +0 -0
- /package/libs/cn/{4912d0c0243be7a163cb.png → image-empty.png} +0 -0
- /package/libs/cn/{148763e32711a32e3556.svg → resize-large.svg} +0 -0
- /package/libs/cn/{87d88a23959ced795e3f.svg → resize.svg} +0 -0
- /package/libs/cn/{836ebe4738d6a87f1d14.png → widget.png} +0 -0
package/README.md
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
# @glodon-aiot/chat-app-sdk
|
|
2
2
|
|
|
3
|
-
Glodon AIoT Chat App SDK - 基于
|
|
3
|
+
Glodon AIoT Chat App SDK - 基于 Coze 平台的智能聊天 SDK,支持浮窗和嵌入两种模式。
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@glodon-aiot/chat-app-sdk)
|
|
6
6
|
[](https://www.npmjs.com/package/@glodon-aiot/chat-app-sdk)
|
|
7
7
|
[](https://github.com/glodon-aiot/chat-app-sdk/blob/main/LICENSE)
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## ✨ 特性
|
|
10
10
|
|
|
11
|
-
- ✅
|
|
12
|
-
- ✅
|
|
13
|
-
- ✅ **品牌定制**:统一到 `@glodon-aiot` 命名空间
|
|
14
|
-
- ✅ **样式扩展**:支持自定义品牌样式覆盖
|
|
11
|
+
- ✅ **多模式支持**:浮窗模式和嵌入模式自由切换
|
|
12
|
+
- ✅ **双重引入**:支持 npm 安装和 CDN 引入
|
|
15
13
|
- ✅ **类型安全**:完整的 TypeScript 类型定义
|
|
16
|
-
- ✅ **多模式支持**:支持浮窗模式和嵌入模式
|
|
17
|
-
- ✅ **CDN 支持**:支持通过 CDN 直接引入使用
|
|
18
14
|
- ✅ **React 友好**:完美支持 React 项目集成
|
|
15
|
+
- ✅ **移动端适配**:自动检测设备类型并适配布局
|
|
19
16
|
|
|
20
|
-
##
|
|
17
|
+
## 📦 安装
|
|
21
18
|
|
|
22
19
|
### NPM 安装
|
|
23
20
|
|
|
24
21
|
```bash
|
|
25
|
-
# 使用 pnpm(推荐)
|
|
26
|
-
pnpm add @glodon-aiot/chat-app-sdk
|
|
27
|
-
|
|
28
22
|
# 使用 npm
|
|
29
23
|
npm install @glodon-aiot/chat-app-sdk
|
|
30
24
|
|
|
25
|
+
# 使用 pnpm
|
|
26
|
+
pnpm add @glodon-aiot/chat-app-sdk
|
|
27
|
+
|
|
31
28
|
# 使用 yarn
|
|
32
29
|
yarn add @glodon-aiot/chat-app-sdk
|
|
33
30
|
```
|
|
@@ -36,65 +33,49 @@ yarn add @glodon-aiot/chat-app-sdk
|
|
|
36
33
|
|
|
37
34
|
```html
|
|
38
35
|
<!-- 最新版本 -->
|
|
39
|
-
<script src="https://unpkg.com/@glodon-aiot/chat-app-sdk/libs/cn/index.js"></script>
|
|
36
|
+
<script src="https://unpkg.com/@glodon-aiot/chat-app-sdk@latest/libs/cn/index.js"></script>
|
|
40
37
|
|
|
41
38
|
<!-- 指定版本 -->
|
|
42
|
-
<script src="https://unpkg.com/@glodon-aiot/chat-app-sdk@0.0.1/libs/cn/index.js"></script>
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### 环境要求
|
|
39
|
+
<script src="https://unpkg.com/@glodon-aiot/chat-app-sdk@0.0.1-alpha.6/libs/cn/index.js"></script>
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
<!-- 或使用 jsDelivr -->
|
|
42
|
+
<script src="https://cdn.jsdelivr.net/npm/@glodon-aiot/chat-app-sdk@latest/libs/cn/index.js"></script>
|
|
43
|
+
```
|
|
50
44
|
|
|
51
45
|
## 🚀 快速开始
|
|
52
46
|
|
|
53
|
-
###
|
|
47
|
+
### NPM 使用
|
|
54
48
|
|
|
55
49
|
```typescript
|
|
56
|
-
import { WebChatClient
|
|
50
|
+
import { WebChatClient } from '@glodon-aiot/chat-app-sdk';
|
|
57
51
|
|
|
58
52
|
// 创建聊天客户端实例
|
|
59
53
|
const client = new WebChatClient({
|
|
60
|
-
//
|
|
61
|
-
mode: 'float', // 'float' | 'inlay'
|
|
62
|
-
|
|
63
|
-
// 尺寸配置(仅 float 模式生效)
|
|
64
|
-
size: {
|
|
65
|
-
width: 400,
|
|
66
|
-
height: 600,
|
|
67
|
-
maxWidth: 800,
|
|
68
|
-
maxHeight: 800,
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
// 容器配置
|
|
72
|
-
getContainer: () => document.getElementById('chat-container'),
|
|
54
|
+
mode: 'float', // 'float' 浮窗模式 | 'inlay' 嵌入模式
|
|
73
55
|
|
|
74
|
-
// Bot 配置
|
|
75
56
|
config: {
|
|
76
|
-
type:
|
|
77
|
-
|
|
78
|
-
|
|
57
|
+
type: 'app',
|
|
58
|
+
appInfo: {
|
|
59
|
+
appId: 'your-app-id',
|
|
60
|
+
workflowId: 'your-workflow-id',
|
|
61
|
+
},
|
|
79
62
|
// 可选:自定义 API 地址
|
|
80
63
|
apiUrl: 'https://your-api-domain.com/api',
|
|
81
64
|
},
|
|
82
65
|
|
|
83
|
-
// 认证配置
|
|
84
66
|
auth: {
|
|
85
|
-
type:
|
|
67
|
+
type: 'token',
|
|
86
68
|
token: 'your-token',
|
|
87
69
|
onRefreshToken: async () => {
|
|
88
|
-
//
|
|
70
|
+
// Token 刷新逻辑
|
|
89
71
|
return 'new-token';
|
|
90
72
|
},
|
|
91
73
|
},
|
|
92
74
|
|
|
93
|
-
// UI 配置
|
|
94
75
|
ui: {
|
|
95
76
|
base: {
|
|
96
|
-
layout:
|
|
97
|
-
lang:
|
|
77
|
+
layout: 'pc', // 'pc' | 'mobile'
|
|
78
|
+
lang: 'zh-CN', // 'zh-CN' | 'en-US'
|
|
98
79
|
},
|
|
99
80
|
chatBot: {
|
|
100
81
|
title: '智能助手',
|
|
@@ -103,107 +84,16 @@ const client = new WebChatClient({
|
|
|
103
84
|
},
|
|
104
85
|
});
|
|
105
86
|
|
|
106
|
-
//
|
|
87
|
+
// 控制显示/隐藏
|
|
107
88
|
client.showChatBot();
|
|
108
|
-
|
|
109
|
-
// 隐藏聊天窗口
|
|
110
89
|
client.hideChatBot();
|
|
111
90
|
|
|
112
91
|
// 销毁实例
|
|
113
92
|
client.destroy();
|
|
114
93
|
```
|
|
115
94
|
|
|
116
|
-
## 🎯 渲染模式
|
|
117
|
-
|
|
118
|
-
SDK 支持两种渲染模式:**浮窗助手模式**(默认)和**嵌入模式**。
|
|
119
|
-
|
|
120
|
-
### 浮窗助手模式(Float)
|
|
121
|
-
|
|
122
|
-
显示悬浮按钮,点击后弹出聊天窗口。这是默认模式。
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
const client = new WebChatClient({
|
|
126
|
-
mode: 'float', // 默认值
|
|
127
|
-
size: { width: 400, height: 600 },
|
|
128
|
-
// ... 其他配置
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### 嵌入模式(Inlay)
|
|
133
|
-
|
|
134
|
-
全屏展示聊天页面,自动打开,无关闭按钮。适合专门的聊天页面。
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
const client = new WebChatClient({
|
|
138
|
-
mode: 'inlay',
|
|
139
|
-
getContainer: () => document.getElementById('chat-container'),
|
|
140
|
-
// ... 其他配置
|
|
141
|
-
});
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
**嵌入模式会自动:**
|
|
145
|
-
- ✅ 隐藏悬浮助手按钮
|
|
146
|
-
- ✅ 隐藏关闭按钮
|
|
147
|
-
- ✅ 全屏填满容器(100% 宽高)
|
|
148
|
-
- ✅ 自动显示聊天窗口
|
|
149
|
-
|
|
150
|
-
### 自定义容器渲染
|
|
151
|
-
|
|
152
|
-
使用 `getContainer` 可以将整个实例(包括按钮和聊天窗口)渲染到指定容器:
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
const client = new WebChatClient({
|
|
156
|
-
mode: 'float',
|
|
157
|
-
getContainer: () => document.getElementById('sidebar')!,
|
|
158
|
-
// ... 其他配置
|
|
159
|
-
});
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### React 中使用
|
|
163
|
-
|
|
164
|
-
```typescript
|
|
165
|
-
import { useEffect, useRef } from 'react';
|
|
166
|
-
import { WebChatClient } from '@glodon-aiot/chat-app-sdk';
|
|
167
|
-
|
|
168
|
-
function ChatPage() {
|
|
169
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
170
|
-
const clientRef = useRef<WebChatClient | null>(null);
|
|
171
|
-
|
|
172
|
-
useEffect(() => {
|
|
173
|
-
if (containerRef.current && !clientRef.current) {
|
|
174
|
-
clientRef.current = new WebChatClient({
|
|
175
|
-
mode: 'inlay',
|
|
176
|
-
getContainer: () => containerRef.current,
|
|
177
|
-
config: {
|
|
178
|
-
appId: 'your-app-id',
|
|
179
|
-
workflowId: 'your-workflow-id',
|
|
180
|
-
},
|
|
181
|
-
auth: {
|
|
182
|
-
type: AuthType.TOKEN,
|
|
183
|
-
onRefreshToken: async () => 'your-token',
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return () => {
|
|
189
|
-
clientRef.current?.destroy();
|
|
190
|
-
clientRef.current = null;
|
|
191
|
-
};
|
|
192
|
-
}, []);
|
|
193
|
-
|
|
194
|
-
return (
|
|
195
|
-
<div
|
|
196
|
-
ref={containerRef}
|
|
197
|
-
style={{ width: '100%', height: '100vh' }}
|
|
198
|
-
/>
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
95
|
### CDN 使用
|
|
204
96
|
|
|
205
|
-
通过 CDN 引入时,SDK 会自动在 `window` 对象上暴露:
|
|
206
|
-
|
|
207
97
|
```html
|
|
208
98
|
<!DOCTYPE html>
|
|
209
99
|
<html>
|
|
@@ -215,16 +105,19 @@ function ChatPage() {
|
|
|
215
105
|
<div id="chat-container" style="width: 100%; height: 100vh;"></div>
|
|
216
106
|
|
|
217
107
|
<!-- 引入 SDK -->
|
|
218
|
-
<script src="https://unpkg.com/@glodon-aiot/chat-app-sdk/libs/cn/index.js"></script>
|
|
108
|
+
<script src="https://unpkg.com/@glodon-aiot/chat-app-sdk@latest/libs/cn/index.js"></script>
|
|
219
109
|
|
|
220
110
|
<script>
|
|
221
|
-
// 使用全局变量
|
|
111
|
+
// 使用全局变量 GlodonAIoT
|
|
222
112
|
const client = new window.GlodonAIoT.WebChatClient({
|
|
223
113
|
mode: 'inlay',
|
|
224
114
|
getContainer: () => document.getElementById('chat-container'),
|
|
225
115
|
config: {
|
|
226
|
-
|
|
227
|
-
|
|
116
|
+
type: 'app',
|
|
117
|
+
appInfo: {
|
|
118
|
+
appId: 'your-app-id',
|
|
119
|
+
workflowId: 'your-workflow-id',
|
|
120
|
+
},
|
|
228
121
|
},
|
|
229
122
|
auth: {
|
|
230
123
|
type: 'token',
|
|
@@ -239,306 +132,205 @@ function ChatPage() {
|
|
|
239
132
|
</html>
|
|
240
133
|
```
|
|
241
134
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
### WebChatClient
|
|
135
|
+
### React 使用
|
|
245
136
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
new WebChatClient(options: CozeChatOptions)
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
**参数说明:**
|
|
253
|
-
|
|
254
|
-
| 参数 | 类型 | 默认值 | 说明 |
|
|
255
|
-
| -------------------- | ----------------------------- | ---------- | -------------------------------------------------------------------------- |
|
|
256
|
-
| options.mode | `'float' \| 'inlay'` | `'float'` | 渲染模式:`'float'` 浮窗助手,`'inlay'` 嵌入模式 |
|
|
257
|
-
| options.size | `SizeProps` | `undefined` | 尺寸配置(仅 float 模式生效) |
|
|
258
|
-
| options.getContainer | `() => HTMLElement \| null` | `undefined` | 容器元素获取方法,返回要渲染的 DOM 元素,默认为 `document.body` |
|
|
259
|
-
| options.config | `object` | - | Bot 配置信息 |
|
|
260
|
-
| options.config.type | `ChatType` | - | 聊天类型:`ChatType.APP` 或 `ChatType.BOT` |
|
|
261
|
-
| options.config.appId | `string` | - | 应用 ID(type 为 APP 时必需) |
|
|
262
|
-
| options.config.workflowId | `string` | - | 工作流 ID(type 为 APP 时必需) |
|
|
263
|
-
| options.config.botId | `string` | - | Bot ID(type 为 BOT 时必需) |
|
|
264
|
-
| options.config.apiUrl| `string` | - | 自定义 API 地址(可选) |
|
|
265
|
-
| options.auth | `AuthProps` | - | 认证配置 |
|
|
266
|
-
| options.auth.type | `'token' \| 'oauth'` | - | 认证类型 |
|
|
267
|
-
| options.auth.token | `string` | - | 访问令牌(token 认证时必需) |
|
|
268
|
-
| options.auth.onRefreshToken | `() => Promise<string>` | - | 令牌刷新回调(可选) |
|
|
269
|
-
| options.ui | `UiProps` | - | UI 配置 |
|
|
270
|
-
| options.userInfo | `OpenUserInfo` | - | 用户信息(可选) |
|
|
271
|
-
| ~~options.el~~ | ~~`HTMLElement`~~ | - | ~~挂载容器(已废弃,请使用 `getContainer`)~~ |
|
|
272
|
-
|
|
273
|
-
#### 实例方法
|
|
274
|
-
|
|
275
|
-
| 方法 | 参数类型 | 返回值 | 说明 |
|
|
276
|
-
| --------------- | -------- | ------ | ------------------ |
|
|
277
|
-
| `showChatBot()` | - | `void` | 显示聊天窗口 |
|
|
278
|
-
| `hideChatBot()` | - | `void` | 隐藏聊天窗口 |
|
|
279
|
-
| `getToken()` | - | `string \| null` | 获取当前令牌 |
|
|
280
|
-
| `destroy()` | - | `void` | 销毁实例,清理资源 |
|
|
281
|
-
|
|
282
|
-
### 类型定义
|
|
283
|
-
|
|
284
|
-
```typescript
|
|
285
|
-
import type {
|
|
286
|
-
CozeChatOptions,
|
|
287
|
-
RenderMode, // 'float' | 'inlay'
|
|
288
|
-
SizeProps, // 尺寸配置
|
|
289
|
-
AuthProps, // 认证配置
|
|
290
|
-
UiProps, // UI 配置
|
|
291
|
-
OpenUserInfo, // 用户信息
|
|
292
|
-
} from '@glodon-aiot/chat-app-sdk';
|
|
293
|
-
|
|
294
|
-
import {
|
|
295
|
-
ChatType, // 聊天类型枚举
|
|
296
|
-
AuthType, // 认证类型枚举
|
|
297
|
-
Layout, // 布局枚举
|
|
298
|
-
Language, // 语言枚举
|
|
299
|
-
} from '@glodon-aiot/chat-app-sdk';
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
### 常用类型说明
|
|
303
|
-
|
|
304
|
-
```typescript
|
|
305
|
-
// 渲染模式
|
|
306
|
-
type RenderMode = 'float' | 'inlay';
|
|
307
|
-
|
|
308
|
-
// 尺寸配置
|
|
309
|
-
interface SizeProps {
|
|
310
|
-
width?: number | string;
|
|
311
|
-
height?: number | string;
|
|
312
|
-
maxWidth?: number | string;
|
|
313
|
-
maxHeight?: number | string;
|
|
314
|
-
minWidth?: number | string;
|
|
315
|
-
minHeight?: number | string;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// 认证配置
|
|
319
|
-
interface AuthProps {
|
|
320
|
-
type: 'token' | 'oauth';
|
|
321
|
-
token?: string;
|
|
322
|
-
onRefreshToken?: () => Promise<string>;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// UI 配置
|
|
326
|
-
interface UiProps {
|
|
327
|
-
base?: {
|
|
328
|
-
layout?: Layout;
|
|
329
|
-
lang?: Language;
|
|
330
|
-
zIndex?: number;
|
|
331
|
-
};
|
|
332
|
-
chatBot?: {
|
|
333
|
-
title?: string;
|
|
334
|
-
width?: number | string;
|
|
335
|
-
uploadable?: boolean;
|
|
336
|
-
};
|
|
337
|
-
header?: {
|
|
338
|
-
isShow?: boolean;
|
|
339
|
-
isNeedClose?: boolean;
|
|
340
|
-
};
|
|
341
|
-
asstBtn?: {
|
|
342
|
-
isNeed?: boolean;
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
完整的类型定义请参考 `@coze-studio/chat-app-sdk` [官方文档](https://github.com/coze-dev/coze-chat-sdk)。
|
|
137
|
+
```tsx
|
|
138
|
+
import React, { useEffect, useRef } from 'react';
|
|
139
|
+
import { WebChatClient } from '@glodon-aiot/chat-app-sdk';
|
|
348
140
|
|
|
349
|
-
|
|
141
|
+
function ChatComponent() {
|
|
142
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
143
|
+
const clientRef = useRef<WebChatClient | null>(null);
|
|
350
144
|
|
|
351
|
-
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (!containerRef.current) return;
|
|
352
147
|
|
|
353
|
-
|
|
148
|
+
clientRef.current = new WebChatClient({
|
|
149
|
+
mode: 'inlay',
|
|
150
|
+
getContainer: () => containerRef.current!,
|
|
151
|
+
config: {
|
|
152
|
+
type: 'app',
|
|
153
|
+
appInfo: {
|
|
154
|
+
appId: 'your-app-id',
|
|
155
|
+
workflowId: 'your-workflow-id',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
auth: {
|
|
159
|
+
type: 'token',
|
|
160
|
+
token: 'your-token',
|
|
161
|
+
onRefreshToken: async () => 'new-token',
|
|
162
|
+
},
|
|
163
|
+
});
|
|
354
164
|
|
|
355
|
-
|
|
165
|
+
return () => {
|
|
166
|
+
clientRef.current?.destroy();
|
|
167
|
+
};
|
|
168
|
+
}, []);
|
|
356
169
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
170
|
+
return (
|
|
171
|
+
<div
|
|
172
|
+
ref={containerRef}
|
|
173
|
+
style={{ width: '100%', height: '100vh' }}
|
|
174
|
+
/>
|
|
175
|
+
);
|
|
362
176
|
}
|
|
363
177
|
```
|
|
364
178
|
|
|
365
|
-
|
|
179
|
+
## 🎯 两种模式
|
|
366
180
|
|
|
367
|
-
|
|
368
|
-
.sidebar {
|
|
369
|
-
position: relative; /* 必需:为 absolute 定位提供参照 */
|
|
370
|
-
width: 300px;
|
|
371
|
-
height: 100vh;
|
|
372
|
-
overflow: hidden; /* 可选:防止内容溢出 */
|
|
373
|
-
}
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
### 容器时序
|
|
181
|
+
### 浮窗模式(Float)
|
|
377
182
|
|
|
378
|
-
|
|
183
|
+
显示悬浮按钮,点击后弹出聊天窗口。适合作为页面辅助功能。
|
|
379
184
|
|
|
380
185
|
```typescript
|
|
381
|
-
// ✅ 正确:使用 ref 确保元素已挂载
|
|
382
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
383
|
-
|
|
384
|
-
useEffect(() => {
|
|
385
|
-
if (containerRef.current) {
|
|
386
|
-
const client = new WebChatClient({
|
|
387
|
-
getContainer: () => containerRef.current,
|
|
388
|
-
// ...
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
}, []);
|
|
392
|
-
|
|
393
|
-
// ❌ 错误:元素可能尚未挂载
|
|
394
186
|
const client = new WebChatClient({
|
|
395
|
-
|
|
396
|
-
|
|
187
|
+
mode: 'float', // 默认模式
|
|
188
|
+
size: {
|
|
189
|
+
width: 400,
|
|
190
|
+
height: 600
|
|
191
|
+
},
|
|
192
|
+
// ... 其他配置
|
|
397
193
|
});
|
|
398
194
|
```
|
|
399
195
|
|
|
400
|
-
###
|
|
196
|
+
### 嵌入模式(Inlay)
|
|
401
197
|
|
|
402
|
-
|
|
198
|
+
全屏展示聊天页面,自动打开。适合专门的聊天页面。
|
|
403
199
|
|
|
404
200
|
```typescript
|
|
405
|
-
// inlay 模式默认隐藏关闭按钮,但可以手动覆盖
|
|
406
201
|
const client = new WebChatClient({
|
|
407
202
|
mode: 'inlay',
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
isNeedClose: true, // 覆盖默认配置,显示关闭按钮
|
|
411
|
-
},
|
|
412
|
-
},
|
|
413
|
-
// ...
|
|
203
|
+
getContainer: () => document.getElementById('chat-container'),
|
|
204
|
+
// ... 其他配置
|
|
414
205
|
});
|
|
415
206
|
```
|
|
416
207
|
|
|
417
|
-
##
|
|
208
|
+
## 📖 配置参数
|
|
209
|
+
|
|
210
|
+
### WebChatClientOptions
|
|
418
211
|
|
|
419
|
-
|
|
212
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
213
|
+
|------|------|------|------|
|
|
214
|
+
| `mode` | `'float' \| 'inlay'` | 是 | 渲染模式 |
|
|
215
|
+
| `config` | `BotConfig` | 是 | Bot 配置信息 |
|
|
216
|
+
| `auth` | `AuthConfig` | 是 | 认证配置 |
|
|
217
|
+
| `ui` | `UIConfig` | 否 | UI 配置 |
|
|
218
|
+
| `getContainer` | `() => HTMLElement` | 否 | 容器元素(inlay 模式必需) |
|
|
219
|
+
| `size` | `SizeConfig` | 否 | 尺寸配置(float 模式有效) |
|
|
420
220
|
|
|
421
|
-
|
|
221
|
+
### BotConfig
|
|
422
222
|
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
223
|
+
```typescript
|
|
224
|
+
{
|
|
225
|
+
type: 'app', // 固定为 'app'
|
|
226
|
+
appInfo: {
|
|
227
|
+
appId: string, // 应用 ID
|
|
228
|
+
workflowId: string, // 工作流 ID
|
|
229
|
+
},
|
|
230
|
+
apiUrl?: string, // 可选:自定义 API 地址
|
|
429
231
|
}
|
|
430
232
|
```
|
|
431
233
|
|
|
432
|
-
###
|
|
433
|
-
|
|
434
|
-
```less
|
|
435
|
-
@import '@glodon-aiot/chat-app-sdk/src/style.less';
|
|
234
|
+
### AuthConfig
|
|
436
235
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
//
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
443
|
-
}
|
|
236
|
+
```typescript
|
|
237
|
+
{
|
|
238
|
+
type: 'token', // 认证类型
|
|
239
|
+
token: string, // 访问令牌
|
|
240
|
+
onRefreshToken: () => string | Promise<string>, // Token 刷新回调
|
|
444
241
|
}
|
|
445
242
|
```
|
|
446
243
|
|
|
447
|
-
###
|
|
244
|
+
### UIConfig
|
|
448
245
|
|
|
449
246
|
```typescript
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
layout: Layout.PC,
|
|
455
|
-
lang: Language.ZH_CN,
|
|
456
|
-
// 自定义主题
|
|
457
|
-
theme: 'dark', // 或 'light'
|
|
458
|
-
},
|
|
247
|
+
{
|
|
248
|
+
base: {
|
|
249
|
+
layout: 'pc' | 'mobile', // 布局模式
|
|
250
|
+
lang: 'zh-CN' | 'en-US', // 语言
|
|
459
251
|
},
|
|
460
|
-
|
|
252
|
+
chatBot: {
|
|
253
|
+
title?: string, // 聊天窗口标题
|
|
254
|
+
uploadable?: boolean, // 是否支持上传
|
|
255
|
+
},
|
|
256
|
+
header: {
|
|
257
|
+
isShow?: boolean, // 是否显示头部
|
|
258
|
+
isNeedClose?: boolean, // 是否显示关闭按钮
|
|
259
|
+
},
|
|
260
|
+
asstBtn: {
|
|
261
|
+
isNeed?: boolean, // 是否显示浮动按钮
|
|
262
|
+
},
|
|
263
|
+
}
|
|
461
264
|
```
|
|
462
265
|
|
|
463
|
-
##
|
|
266
|
+
## 📋 API 方法
|
|
464
267
|
|
|
465
|
-
###
|
|
268
|
+
### WebChatClient 实例方法
|
|
466
269
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
270
|
+
| 方法 | 说明 |
|
|
271
|
+
|------|------|
|
|
272
|
+
| `showChatBot()` | 显示聊天窗口 |
|
|
273
|
+
| `hideChatBot()` | 隐藏聊天窗口 |
|
|
274
|
+
| `destroy()` | 销毁实例,清理资源 |
|
|
470
275
|
|
|
471
|
-
|
|
472
|
-
pnpm dev
|
|
276
|
+
## 🔧 常见问题
|
|
473
277
|
|
|
474
|
-
|
|
475
|
-
pnpm lint
|
|
278
|
+
### Q1: 如何获取 appId 和 workflowId?
|
|
476
279
|
|
|
477
|
-
|
|
478
|
-
|
|
280
|
+
需要从 Coze 平台获取:
|
|
281
|
+
1. 登录 [Coze 平台](https://www.coze.cn/)
|
|
282
|
+
2. 创建或选择你的应用
|
|
283
|
+
3. 在应用设置中找到相应的 ID
|
|
479
284
|
|
|
480
|
-
|
|
481
|
-
pnpm build
|
|
482
|
-
```
|
|
285
|
+
### Q2: CDN 引入后如何使用?
|
|
483
286
|
|
|
484
|
-
|
|
287
|
+
SDK 会在 `window.GlodonAIoT` 上暴露 API:
|
|
485
288
|
|
|
289
|
+
```javascript
|
|
290
|
+
const client = new window.GlodonAIoT.WebChatClient({
|
|
291
|
+
// 配置...
|
|
292
|
+
});
|
|
486
293
|
```
|
|
487
|
-
frontend/packages/glodon/chat-app-sdk/
|
|
488
|
-
├── src/ # 源码目录
|
|
489
|
-
│ ├── index.ts # 主入口文件
|
|
490
|
-
│ └── style.less # 样式文件
|
|
491
|
-
├── dev/ # 开发示例
|
|
492
|
-
│ └── page/
|
|
493
|
-
│ └── Client.tsx # 测试页面
|
|
494
|
-
├── libs/ # 构建产物
|
|
495
|
-
│ └── cn/
|
|
496
|
-
│ └── index.js # UMD 格式输出
|
|
497
|
-
├── rspack-config/ # 构建配置
|
|
498
|
-
├── package.json # 包配置
|
|
499
|
-
└── README.md # 文档
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
### 构建配置
|
|
503
|
-
|
|
504
|
-
- **开发环境**:使用 `rspack serve` 启动开发服务器
|
|
505
|
-
- **生产构建**:使用 `rspack build` 生成 UMD 格式文件
|
|
506
|
-
- **类型定义**:使用 `tsc` 生成 TypeScript 声明文件
|
|
507
|
-
|
|
508
|
-
## 🐛 常见问题
|
|
509
294
|
|
|
510
|
-
###
|
|
295
|
+
### Q3: 支持哪些浏览器?
|
|
511
296
|
|
|
512
|
-
|
|
513
|
-
1. 登录 [Coze 平台](https://www.coze.cn/)
|
|
514
|
-
2. 创建或选择你的应用
|
|
515
|
-
3. 在应用设置中找到 `appId` 和 `workflowId`
|
|
516
|
-
|
|
517
|
-
### Q: 支持哪些浏览器?
|
|
518
|
-
|
|
519
|
-
A: 支持所有现代浏览器:
|
|
297
|
+
支持所有现代浏览器:
|
|
520
298
|
- Chrome >= 88
|
|
521
299
|
- Firefox >= 85
|
|
522
300
|
- Safari >= 14
|
|
523
301
|
- Edge >= 88
|
|
524
302
|
|
|
525
|
-
###
|
|
303
|
+
### Q4: 如何处理 Token 过期?
|
|
526
304
|
|
|
527
|
-
|
|
528
|
-
1. 覆盖 CSS 变量
|
|
529
|
-
2. 导入 Less 文件并覆盖样式
|
|
530
|
-
3. 使用 `ui` 配置项调整 UI 参数
|
|
305
|
+
通过 `onRefreshToken` 回调处理:
|
|
531
306
|
|
|
532
|
-
|
|
307
|
+
```typescript
|
|
308
|
+
auth: {
|
|
309
|
+
type: 'token',
|
|
310
|
+
token: 'current-token',
|
|
311
|
+
onRefreshToken: async () => {
|
|
312
|
+
// 调用你的 API 获取新 token
|
|
313
|
+
const response = await fetch('/api/refresh-token');
|
|
314
|
+
const { token } = await response.json();
|
|
315
|
+
return token;
|
|
316
|
+
},
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Q5: 如何在嵌入模式下设置容器高度?
|
|
321
|
+
|
|
322
|
+
容器会自动填满 100% 高度,确保父元素有明确的高度:
|
|
533
323
|
|
|
534
|
-
|
|
324
|
+
```html
|
|
325
|
+
<div id="chat-container" style="height: 100vh;"></div>
|
|
326
|
+
```
|
|
535
327
|
|
|
536
|
-
|
|
328
|
+
## 🌐 环境要求
|
|
537
329
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
2.
|
|
541
|
-
|
|
330
|
+
- **Node.js**: >= 18
|
|
331
|
+
- **React**: >= 18.2.0 (如果使用 React)
|
|
332
|
+
- **ReactDOM**: >= 18.2.0 (如果使用 React)
|
|
333
|
+
- **浏览器**: 支持 ES6+ 的现代浏览器
|
|
542
334
|
|
|
543
335
|
## 📄 许可证
|
|
544
336
|
|
|
@@ -548,27 +340,15 @@ Apache-2.0
|
|
|
548
340
|
|
|
549
341
|
欢迎提交 Issue 和 Pull Request!
|
|
550
342
|
|
|
551
|
-
### 贡献指南
|
|
552
|
-
|
|
553
|
-
1. Fork 本仓库
|
|
554
|
-
2. 创建特性分支:`git checkout -b feature/amazing-feature`
|
|
555
|
-
3. 提交更改:`git commit -m 'Add amazing feature'`
|
|
556
|
-
4. 推送分支:`git push origin feature/amazing-feature`
|
|
557
|
-
5. 提交 Pull Request
|
|
558
|
-
|
|
559
343
|
## 📞 联系我们
|
|
560
344
|
|
|
561
|
-
如有问题或建议,请联系 Glodon AIoT
|
|
562
|
-
|
|
563
|
-
- 🐛 问题反馈:[GitHub Issues](https://github.com/glodon-aiot/chat-app-sdk/issues)
|
|
564
|
-
- 📖 文档:[项目文档](https://github.com/glodon-aiot/chat-app-sdk)
|
|
345
|
+
如有问题或建议,请联系 Glodon AIoT 团队。
|
|
565
346
|
|
|
566
347
|
## 🔗 相关链接
|
|
567
348
|
|
|
568
349
|
- [Coze 官方文档](https://www.coze.cn/docs/)
|
|
569
|
-
- [
|
|
570
|
-
- [React 官方文档](https://react.dev/)
|
|
350
|
+
- [npm 包地址](https://www.npmjs.com/package/@glodon-aiot/chat-app-sdk)
|
|
571
351
|
|
|
572
352
|
---
|
|
573
353
|
|
|
574
|
-
|
|
354
|
+
**Made with ❤️ by Glodon AIoT Team**
|