@blueking/ai-ui-sdk 0.0.7-beta.4 → 0.0.7-beta.6
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/dist/common/util.d.ts +0 -7
- package/dist/hooks/use-chat.d.ts +2 -14
- package/dist/hooks/use-style.d.ts +0 -1
- package/dist/main.js +1657 -20
- package/dist/types/type.d.ts +0 -26
- package/package.json +7 -25
- package/README.md +0 -261
- package/dist/75c2c9345bc27655039f.js +0 -1
package/dist/types/type.d.ts
CHANGED
@@ -34,8 +34,6 @@ export interface ISessionContent {
|
|
34
34
|
rate?: number;
|
35
35
|
status?: SessionContentStatus;
|
36
36
|
sessionCode: string;
|
37
|
-
cite?: string;
|
38
|
-
time?: string;
|
39
37
|
}
|
40
38
|
export interface ISessionPrompt {
|
41
39
|
content: string;
|
@@ -48,33 +46,9 @@ export interface ChatCallbacks {
|
|
48
46
|
handleThink?: (sessionCode: string, sessionContent: ISessionContent) => void;
|
49
47
|
handleEnd?: (sessionCode: string, sessionContent: ISessionContent) => void;
|
50
48
|
handleError?: (sessionCode: string, sessionContent: ISessionContent, code: string | undefined) => void;
|
51
|
-
requestOptions?: {
|
52
|
-
url: string;
|
53
|
-
headers?: Record<string, string>;
|
54
|
-
};
|
55
49
|
}
|
56
50
|
export interface SummaryCallbacks {
|
57
51
|
handleStart?: () => void;
|
58
52
|
handleEnd?: (text: string) => void;
|
59
53
|
handleError?: (message: string, code?: string) => void;
|
60
54
|
}
|
61
|
-
export type BasicChatContent = {
|
62
|
-
message: string;
|
63
|
-
cite?: string;
|
64
|
-
shortcut?: never;
|
65
|
-
};
|
66
|
-
export type ShortcutChatContent = {
|
67
|
-
message: string;
|
68
|
-
cite: string;
|
69
|
-
shortcut: ShortCut;
|
70
|
-
};
|
71
|
-
export interface ShortCut {
|
72
|
-
label: string;
|
73
|
-
key: string;
|
74
|
-
prompt: string;
|
75
|
-
icon?: string;
|
76
|
-
}
|
77
|
-
export type ISendChat = {
|
78
|
-
content: BasicChatContent | ShortcutChatContent;
|
79
|
-
callback?: () => void;
|
80
|
-
};
|
package/package.json
CHANGED
@@ -1,22 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@blueking/ai-ui-sdk",
|
3
|
-
"version": "0.0.7-beta.
|
3
|
+
"version": "0.0.7-beta.6",
|
4
4
|
"description": "蓝鲸AI UI SDK",
|
5
|
-
"
|
6
|
-
"module": "dist/main.es.js",
|
5
|
+
"module": "dist/main.js",
|
7
6
|
"types": "dist/main.d.ts",
|
8
|
-
"exports": {
|
9
|
-
".": {
|
10
|
-
"types": "./dist/main.d.ts",
|
11
|
-
"import": "./dist/main.es.js",
|
12
|
-
"require": "./dist/main.umd.js"
|
13
|
-
},
|
14
|
-
"./css/style.css": "./dist/css/style.css",
|
15
|
-
"./css/iconcool.js": "./dist/css/iconcool.js"
|
16
|
-
},
|
17
7
|
"scripts": {
|
18
|
-
"build": "bk-cli-service-webpack build && tsc --emitDeclarationOnly"
|
19
|
-
"build:vite": "vite build"
|
8
|
+
"build": "bk-cli-service-webpack build && tsc --emitDeclarationOnly"
|
20
9
|
},
|
21
10
|
"files": [
|
22
11
|
"dist"
|
@@ -26,17 +15,10 @@
|
|
26
15
|
"license": "ISC",
|
27
16
|
"dependencies": {
|
28
17
|
"@blueking/cli-service-webpack": "0.0.7-beta.1",
|
29
|
-
"bkui-vue": "^2.0.1-beta.100"
|
30
|
-
|
31
|
-
"peerDependencies": {
|
32
|
-
"vue": "^3.0.0"
|
18
|
+
"bkui-vue": "^2.0.1-beta.100",
|
19
|
+
"vue": "^3.5.13"
|
33
20
|
},
|
34
21
|
"devDependencies": {
|
35
|
-
"
|
36
|
-
"typescript": "^5.5.4",
|
37
|
-
"vite": "^5.0.0",
|
38
|
-
"vite-plugin-dts": "^3.7.0",
|
39
|
-
"terser": "^5.22.0",
|
40
|
-
"vue": "^3.5.13"
|
22
|
+
"typescript": "^5.5.4"
|
41
23
|
}
|
42
|
-
}
|
24
|
+
}
|
package/README.md
DELETED
@@ -1,261 +0,0 @@
|
|
1
|
-
# 蓝鲸 AI UI SDK
|
2
|
-
|
3
|
-
## 介绍
|
4
|
-
|
5
|
-
蓝鲸 AI UI SDK (@blueking/ai-ui-sdk) 是一个用于快速构建 AI 应用前端界面的工具包。它提供了一系列组件和 hooks,帮助开发者简化 AI 聊天界面的开发过程,包括聊天功能、引用资料展示、AI 思考过程可视化等功能。
|
6
|
-
|
7
|
-
## 安装
|
8
|
-
|
9
|
-
```bash
|
10
|
-
npm install @blueking/ai-ui-sdk
|
11
|
-
```
|
12
|
-
|
13
|
-
## 主要功能
|
14
|
-
|
15
|
-
- **聊天功能**:管理 AI 对话的完整生命周期
|
16
|
-
- **引用资料展示**:显示 AI 在回答中引用的文档资料
|
17
|
-
- **思考过程可视化**:展示 AI 的思考过程和推理步骤
|
18
|
-
- **内容总结**:快速对对话内容进行摘要总结
|
19
|
-
- **统一样式**:提供一致的 UI 样式和图标
|
20
|
-
- **可拖拽和缩放的聊天窗口**:支持自定义位置和大小的聊天界面
|
21
|
-
- **快捷指令功能**:支持预设的快捷操作和自定义指令
|
22
|
-
- **多语言支持**:内置国际化支持
|
23
|
-
|
24
|
-
## 使用指南
|
25
|
-
|
26
|
-
### 基本设置
|
27
|
-
|
28
|
-
```typescript
|
29
|
-
import { useStyle, useChat, useClickProxy } from '@blueking/ai-ui-sdk';
|
30
|
-
|
31
|
-
// 引入样式和图标
|
32
|
-
useStyle();
|
33
|
-
|
34
|
-
// 设置全局点击代理事件
|
35
|
-
useClickProxy();
|
36
|
-
|
37
|
-
// 初始化聊天
|
38
|
-
const {
|
39
|
-
currentSession,
|
40
|
-
sessionContents,
|
41
|
-
sendChat,
|
42
|
-
stopChat,
|
43
|
-
setCurrentSession,
|
44
|
-
currentSessionLoading,
|
45
|
-
reGenerateChat,
|
46
|
-
reSendChat,
|
47
|
-
deleteChat,
|
48
|
-
} = useChat({
|
49
|
-
handleStart: () => {
|
50
|
-
console.log('聊天开始');
|
51
|
-
},
|
52
|
-
handleText: () => {
|
53
|
-
console.log('收到文本消息');
|
54
|
-
},
|
55
|
-
handleEnd: () => {
|
56
|
-
console.log('聊天结束');
|
57
|
-
},
|
58
|
-
requestOptions: {
|
59
|
-
url: 'your-api-endpoint',
|
60
|
-
},
|
61
|
-
});
|
62
|
-
```
|
63
|
-
|
64
|
-
### 创建聊天会话
|
65
|
-
|
66
|
-
```typescript
|
67
|
-
// 设置当前会话
|
68
|
-
const session: ISession = {
|
69
|
-
sessionCode: '1',
|
70
|
-
sessionName: 'test',
|
71
|
-
model: '',
|
72
|
-
};
|
73
|
-
setCurrentSession(session);
|
74
|
-
|
75
|
-
// 发送聊天消息
|
76
|
-
sendChat({
|
77
|
-
message: '你的问题',
|
78
|
-
cite: '选中的文本', // 可选,引用的文本内容
|
79
|
-
});
|
80
|
-
|
81
|
-
// 使用快捷指令发送消息
|
82
|
-
sendChat({
|
83
|
-
message: '快捷指令标签',
|
84
|
-
cite: '选中的文本',
|
85
|
-
shortcut: {
|
86
|
-
label: '快捷指令名称',
|
87
|
-
key: 'shortcut-key',
|
88
|
-
prompt: '预设的提示模板',
|
89
|
-
icon: '图标', // 可选
|
90
|
-
},
|
91
|
-
});
|
92
|
-
|
93
|
-
// 停止正在进行的聊天
|
94
|
-
stopChat(session.sessionCode);
|
95
|
-
```
|
96
|
-
|
97
|
-
### 完整的聊天界面示例
|
98
|
-
|
99
|
-
```vue
|
100
|
-
<template>
|
101
|
-
<div class="ai-blueking-wrapper">
|
102
|
-
<vue-draggable-resizable
|
103
|
-
v-if="isShow"
|
104
|
-
:active="isShow"
|
105
|
-
:draggable="true"
|
106
|
-
:h="height"
|
107
|
-
:min-height="minHeight"
|
108
|
-
:min-width="minWidth"
|
109
|
-
:parent="true"
|
110
|
-
:prevent-deactivation="true"
|
111
|
-
:resizable="true"
|
112
|
-
:w="width"
|
113
|
-
:x="left"
|
114
|
-
:y="top"
|
115
|
-
class-name="ai-blueking-container-wrapper"
|
116
|
-
drag-handle=".drag-handle"
|
117
|
-
@dragging="handleDragging"
|
118
|
-
@resizing="handleResizing"
|
119
|
-
>
|
120
|
-
<div class="ai-blueking-container">
|
121
|
-
<!-- 聊天界面内容 -->
|
122
|
-
<div class="content-wrapper">
|
123
|
-
<div class="message-wrapper">
|
124
|
-
<render-message
|
125
|
-
v-for="(message, index) in sessionContents"
|
126
|
-
:key="message.id"
|
127
|
-
:message="message"
|
128
|
-
:index="index"
|
129
|
-
@delete="handleDelete"
|
130
|
-
@regenerate="handleRegenerate"
|
131
|
-
@resend="handleResend"
|
132
|
-
/>
|
133
|
-
</div>
|
134
|
-
|
135
|
-
<div class="chat-input-container">
|
136
|
-
<ChatInputBox
|
137
|
-
v-model="inputMessage"
|
138
|
-
:loading="currentSessionLoading"
|
139
|
-
:shortcuts="shortcuts"
|
140
|
-
@send="handleSendMessage"
|
141
|
-
@shortcut-click="handleShortcutClick"
|
142
|
-
@stop="handleStop"
|
143
|
-
/>
|
144
|
-
</div>
|
145
|
-
</div>
|
146
|
-
</div>
|
147
|
-
</vue-draggable-resizable>
|
148
|
-
</div>
|
149
|
-
</template>
|
150
|
-
```
|
151
|
-
|
152
|
-
### 快捷指令配置
|
153
|
-
|
154
|
-
```typescript
|
155
|
-
// 默认快捷指令示例
|
156
|
-
const DEFAULT_SHORTCUTS: ShortCut[] = [
|
157
|
-
{
|
158
|
-
label: '解释代码',
|
159
|
-
key: 'explain-code',
|
160
|
-
prompt: '请解释以下代码的功能:{ SELECTED_TEXT }',
|
161
|
-
icon: 'code-icon',
|
162
|
-
},
|
163
|
-
// 更多快捷指令...
|
164
|
-
];
|
165
|
-
|
166
|
-
// 在组件中使用
|
167
|
-
const props = defineProps<{
|
168
|
-
shortcuts?: ShortCut[];
|
169
|
-
}>();
|
170
|
-
```
|
171
|
-
|
172
|
-
## 类型定义
|
173
|
-
|
174
|
-
### 会话类型
|
175
|
-
|
176
|
-
```typescript
|
177
|
-
interface ISession {
|
178
|
-
sessionCode: string;
|
179
|
-
sessionName: string;
|
180
|
-
model: string;
|
181
|
-
roleInfo?: {
|
182
|
-
collectionId: number;
|
183
|
-
collectionName: string;
|
184
|
-
content: ISessionPrompt[];
|
185
|
-
variables: any[];
|
186
|
-
};
|
187
|
-
}
|
188
|
-
```
|
189
|
-
|
190
|
-
### 聊天内容类型
|
191
|
-
|
192
|
-
```typescript
|
193
|
-
interface ISessionContent {
|
194
|
-
id?: number;
|
195
|
-
role: SessionContentRole;
|
196
|
-
content: string;
|
197
|
-
status?: SessionContentStatus;
|
198
|
-
sessionCode: string;
|
199
|
-
cite?: string;
|
200
|
-
time?: string;
|
201
|
-
}
|
202
|
-
```
|
203
|
-
|
204
|
-
### 快捷指令类型
|
205
|
-
|
206
|
-
```typescript
|
207
|
-
interface ShortCut {
|
208
|
-
label: string;
|
209
|
-
key: string;
|
210
|
-
prompt: string;
|
211
|
-
icon?: string;
|
212
|
-
}
|
213
|
-
```
|
214
|
-
|
215
|
-
## 高级功能
|
216
|
-
|
217
|
-
### 消息重发和重新生成
|
218
|
-
|
219
|
-
```typescript
|
220
|
-
// 重新生成 AI 回复
|
221
|
-
const handleRegenerate = (index: number) => {
|
222
|
-
reGenerateChat(index);
|
223
|
-
};
|
224
|
-
|
225
|
-
// 重新发送用户消息
|
226
|
-
const handleResend = (index: number, value: { message: string; cite: string }) => {
|
227
|
-
reSendChat(index, value);
|
228
|
-
};
|
229
|
-
```
|
230
|
-
|
231
|
-
### 消息删除
|
232
|
-
|
233
|
-
```typescript
|
234
|
-
const handleDelete = (index: number) => {
|
235
|
-
deleteChat(index);
|
236
|
-
};
|
237
|
-
```
|
238
|
-
|
239
|
-
## 样式定制
|
240
|
-
|
241
|
-
SDK 提供了基础的样式和主题支持,你可以通过覆盖 CSS 变量来自定义界面外观:
|
242
|
-
|
243
|
-
```scss
|
244
|
-
.ai-blueking-container {
|
245
|
-
// 自定义样式
|
246
|
-
}
|
247
|
-
|
248
|
-
.message-wrapper {
|
249
|
-
// 消息列表样式
|
250
|
-
}
|
251
|
-
|
252
|
-
.chat-input-container {
|
253
|
-
// 输入框样式
|
254
|
-
}
|
255
|
-
```
|
256
|
-
|
257
|
-
## 注意事项
|
258
|
-
|
259
|
-
- SDK 依赖 Vue 3,请确保项目中已安装
|
260
|
-
- 建议使用 TypeScript 以获得更好的类型提示
|
261
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
!function(){var i='<svg xmlns="http://www.w3.org/2000/svg" data-name="ai-ui-sdk" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0;visibility:hidden"><symbol id="ai-ui-sdk-angle-up" viewBox="0 0 32 32"><path fill="#63656e" d="M16 11.5l7 7-1.5 1.5-5.5-5.5-5.5 5.5L9 18.5l7-7z"/></symbol><symbol id="ai-ui-sdk-links" viewBox="0 0 1024 1024"><path d="M263.04 760.96a148.48 148.48 0 01-1.92-224l92.48-92.48-45.12-45.76L216 491.2a212.8 212.8 0 001.92 314.88A212.8 212.8 0 00532.8 808l92.48-92.48L579.84 672l-92.48 92.48a148.48 148.48 0 01-224.32-3.52zM491.2 216l-92.48 92.48 45.44 45.12 92.48-92.48a148.48 148.48 0 01224 1.92 148.48 148.48 0 011.92 224L672 579.84l45.12 45.44 92.48-92.48a212.8 212.8 0 00-1.92-314.88A212.8 212.8 0 00491.2 216z"/><path d="M398.786 579.888l181.019-181.02 45.255 45.255-181.02 181.02-45.254-45.255z"/></symbol><symbol id="ai-ui-sdk-zhishiku" viewBox="0 0 1024 1024"><path d="M320.986 203.315H191.622c-17.248 0-31.622 14.503-31.622 31.905v639.542c0 17.403 14.374 31.905 31.622 31.905h129.364c17.249 0 31.623-14.502 31.623-31.905V235.22c0-17.402-14.374-31.905-31.623-31.905zm-35.934 130.52h-57.495c-15.811 0-28.748-13.053-28.748-29.005 0-15.952 12.937-29.004 28.748-29.004h57.495c15.811 0 28.747 13.052 28.747 29.004 0 15.952-12.936 29.004-28.747 29.004zM578.277 96H448.913c-17.249 0-31.622 14.502-31.622 31.905v746.857c0 17.403 14.373 31.905 31.622 31.905h129.364c17.248 0 31.622-14.502 31.622-31.905V127.905C611.337 110.502 596.963 96 578.277 96zM543.78 227.969h-57.495c-15.811 0-28.748-13.052-28.748-29.004 0-15.952 12.937-29.004 28.748-29.004h57.495c15.811 0 28.747 13.052 28.747 29.004 0 15.952-12.936 29.004-28.747 29.004zm383.78 613.438l-120.74-627.94c-4.312-15.952-17.249-26.104-33.06-26.104h-5.75l-126.488 24.654c-17.249 2.9-28.748 20.303-25.873 37.705l122.177 629.39c2.875 15.953 15.811 26.104 31.622 26.104h5.75l126.489-24.653c17.248-4.35 28.748-21.753 25.873-39.156zM762.26 312.081l-57.495 11.602h-5.75c-12.936 0-25.872-10.152-28.747-23.204-2.875-15.952 7.187-31.904 22.998-34.805l57.495-11.601c15.811-2.9 31.623 7.25 34.497 23.203 2.875 15.952-7.187 31.905-22.998 34.805z"/></symbol><symbol id="ai-ui-sdk-sikao" viewBox="0 0 1024 1024"><path d="M528 96c61.856 0 112 50.144 112 112 0 .376-.002.751-.006 1.126C774.73 260.666 870.4 391.16 870.4 544c0 22.55-2.082 44.612-6.066 66.007C883.94 630.144 896 657.663 896 688c0 61.856-50.144 112-112 112a112.7 112.7 0 01-19.49-1.69C699.754 862.65 610.519 902.4 512 902.4s-187.753-39.75-252.539-104.088A112.33 112.33 0 01240 800c-61.856 0-112-50.144-112-112 0-30.337 12.061-57.856 31.65-78.025A361.172 361.172 0 01153.6 544c0-164.845 111.29-303.696 262.836-345.518C421.232 141.079 469.35 96 528 96zm-91.48 176.633l-4.469 1.278C315.47 308.366 230.4 416.249 230.4 544c0 10.923.622 21.7 1.832 32.3l1.623-.134L240 576c61.856 0 112 50.144 112 112 0 26.132-8.95 50.173-23.95 69.226C377.36 799.817 441.67 825.6 512 825.6c70.33 0 134.639-25.783 183.99-68.412C680.95 738.173 672 714.132 672 688c0-61.856 50.144-112 112-112 2.607 0 5.194.09 7.757.264A280.989 280.989 0 00793.6 544c0-119.973-75.025-222.422-180.718-262.99C592.35 304.904 561.938 320 528 320c-37.782 0-71.195-18.708-91.48-47.367z"/></symbol><symbol id="ai-ui-sdk-wenzhang" viewBox="0 0 1024 1024"><path fill="#3D4265" d="M708.923 157.538h275.692c21.752 0 39.385 17.634 39.385 39.385v748.308c0 43.503-35.266 78.769-78.77 78.769H708.924V157.538z"/><path fill="#3A84FF" d="M0 984.615A39.385 39.385 0 0039.385 1024H945.23c-43.503 0-78.77-35.266-78.77-78.77V39.386C866.462 17.633 848.829 0 827.078 0H39.385C17.633 0 0 17.633 0 39.385v945.23z"/><path fill="#FFF" d="M196.923 288.82c-21.751 0-39.385 17.634-39.385 39.385 0 21.752 17.634 39.385 39.385 39.385h157.539c21.751 0 39.384-17.633 39.384-39.385 0-21.751-17.633-39.384-39.384-39.384H196.923zm0 236.308c-21.751 0-39.385 17.633-39.385 39.385 0 21.751 17.634 39.384 39.385 39.384h472.615c21.752 0 39.385-17.633 39.385-39.384 0-21.752-17.633-39.385-39.385-39.385H196.923zm0 236.308c-21.751 0-39.385 17.633-39.385 39.385 0 21.751 17.634 39.384 39.385 39.384h236.308c21.751 0 39.384-17.633 39.384-39.384 0-21.752-17.633-39.385-39.384-39.385H196.923z"/></g></symbol><symbol id="ai-ui-sdk-yanjing-kejian" viewBox="0 0 1024 1024"><path fill-rule="evenodd" d="M512 192c247.4 0 448 143.3 448 320S759.4 832 512 832 64 688.7 64 512s200.6-320 448-320zm0 64c-54.2 0-106.6 7.5-155.9 22.4-46.6 14.1-88.3 34.1-123.7 59.4C165.1 385.9 128 447.8 128 512c0 64.2 37.1 126.1 104.4 174.2 35.4 25.3 77.1 45.3 123.7 59.4C405.4 760.5 457.8 768 512 768s106.6-7.5 155.9-22.4c46.6-14.1 88.3-34.1 123.7-59.4C858.9 638.1 896 576.2 896 512c0-64.2-37.1-126.1-104.4-174.2-35.4-25.3-77.1-45.3-123.7-59.4C618.6 263.5 566.2 256 512 256zm0 96c88.4 0 160 71.6 160 160s-71.6 160-160 160-160-71.6-160-160 71.6-160 160-160zm0 64c-52.9 0-96 43.1-96 96s43.1 96 96 96 96-43.1 96-96-43.1-96-96-96z"/></symbol></svg>';document.body?document.body.insertAdjacentHTML("afterbegin",i):document.addEventListener("DOMContentLoaded",function(){document.body.insertAdjacentHTML("afterbegin",i)})}();
|