@blueking/ai-blueking 2.0.0-dev.16 → 2.0.0-dev.18

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 CHANGED
@@ -8,11 +8,98 @@ AI-Blueking V2 是小鲸组件的重构版本,采用全新的三层架构设
8
8
 
9
9
  ### 核心特性
10
10
 
11
- - **模块化设计** - 清晰的职责划分,易于维护和扩展
12
- - **两种使用方式** - 完整组件和可嵌入的 ChatBot
13
- - **业务管理器** - 统一的业务逻辑封装
14
- - **类型安全** - 完整的 TypeScript 类型定义
15
- - **事件驱动** - 灵活的事件系统
11
+ - **模块化设计** - 清晰的职责划分,易于维护和扩展
12
+ - **两种使用方式** - 完整组件(AIBlueking)和可嵌入的 ChatBot
13
+ - **业务管理器** - 统一的业务逻辑封装
14
+ - **类型安全** - 完整的 TypeScript 类型定义
15
+ - **事件驱动** - 灵活的事件系统
16
+
17
+ ## 本地开发
18
+
19
+ ### 前置条件
20
+
21
+ - Node.js 18+
22
+ - pnpm 8+
23
+
24
+ ### 1. 安装依赖
25
+
26
+ 在 monorepo 根目录(`bkui-chat-x/`)执行:
27
+
28
+ ```bash
29
+ pnpm install
30
+ ```
31
+
32
+ ### 2. 配置环境变量
33
+
34
+ 在 `packages/ai-blueking/` 目录下创建 `.env.local` 文件(该文件已被 `.gitignore` 忽略,不会提交):
35
+
36
+ ```bash
37
+ # packages/ai-blueking/.env.local
38
+ VITE_API_URL=https://your-api-endpoint.com/api/
39
+ ```
40
+
41
+ > `VITE_API_URL` 是 AI Agent 后端服务的 API 地址,Playground 页面会读取此变量。
42
+
43
+ ### 3. 启动开发服务器
44
+
45
+ 在 monorepo 根目录执行:
46
+
47
+ ```bash
48
+ pnpm dev:ai
49
+ ```
50
+
51
+ 该命令会按顺序执行:
52
+
53
+ 1. **构建 `@blueking/chat-helper`** — ai-blueking 依赖 chat-helper 的构建产物
54
+ 2. **启动 Vite Dev Server** — 运行 Playground 页面
55
+
56
+ 启动后访问 `http://localhost:8001/`,Playground 包含两个 Tab:
57
+
58
+ | Tab | 说明 |
59
+ |-----|------|
60
+ | **AIBlueking(集成模式)** | 完整组件,含悬浮球、拖拽、划词弹窗等 |
61
+ | **ChatBot(独立模式)** | 仅聊天功能,可嵌入任意页面 |
62
+
63
+ ### 4. 其他常用命令
64
+
65
+ 所有命令均在 monorepo 根目录执行:
66
+
67
+ ```bash
68
+ # 构建 ai-blueking
69
+ pnpm build:ai
70
+
71
+ # 代码检查(ESLint + Stylelint)
72
+ pnpm lint:ai
73
+
74
+ # 构建 chat-helper(ai-blueking 的依赖)
75
+ pnpm build:helper
76
+
77
+ # 开发 chat-x UI 组件库
78
+ pnpm dev:ui
79
+
80
+ # 构建 chat-x
81
+ pnpm build:ui
82
+
83
+ # chat-x 单元测试
84
+ pnpm test:ui
85
+ ```
86
+
87
+ ### Playground 文件结构
88
+
89
+ ```
90
+ playground/
91
+ ├── index.html # 入口 HTML
92
+ ├── main.js # Vue 应用挂载
93
+ └── App.vue # Playground 页面(Tab 切换 AIBlueking / ChatBot)
94
+ ```
95
+
96
+ Playground 的 Vite 配置位于 `scripts/vite.dev.ts`,其中 `envDir: '..'` 指向包根目录以加载 `.env.local`。
97
+
98
+ ### 开发注意事项
99
+
100
+ - **修改 chat-helper 后**需重新执行 `pnpm build:helper`,因为 ai-blueking 引用的是 chat-helper 的构建产物
101
+ - **修改 chat-x 后**会由 Vite 自动热更新(workspace 链接,无需手动构建)
102
+ - **修改 ai-blueking 自身代码**会自动热更新
16
103
 
17
104
  ## 架构设计
18
105
 
@@ -39,7 +126,7 @@ AI-Blueking V2 是小鲸组件的重构版本,采用全新的三层架构设
39
126
  └─────────────────┘ └─────────────────┘
40
127
  ```
41
128
 
42
- ## 依赖关系
129
+ ### 依赖关系
43
130
 
44
131
  - `@blueking/chat-helper` - AG-UI SDK,提供数据管理和 Agent 交互能力
45
132
  - `@blueking/chat-x` - 原子化 UI 组件库
@@ -47,26 +134,6 @@ AI-Blueking V2 是小鲸组件的重构版本,采用全新的三层架构设
47
134
  - `vue` - Vue 3.5+
48
135
  - `tippy.js` / `vue-tippy` - Tooltip 功能
49
136
 
50
- ## 安装
51
-
52
- ```bash
53
- # 在 monorepo 根目录
54
- pnpm install
55
- ```
56
-
57
- ## 开发
58
-
59
- ```bash
60
- # 开发模式(启动 playground)
61
- pnpm dev:ai
62
-
63
- # 构建
64
- pnpm build:ai
65
-
66
- # 代码检查
67
- pnpm lint:ai
68
- ```
69
-
70
137
  ## 使用方式
71
138
 
72
139
  ### 方式一:完整组件(AIBlueking)
@@ -105,14 +172,19 @@ const handleClose = () => {
105
172
 
106
173
  ### 方式二:核心组件(ChatBot)
107
174
 
108
- 仅聊天功能,可嵌入到任意页面。
175
+ 仅聊天功能,可嵌入到任意页面。支持两种模式:
176
+
177
+ - **独立模式**:传入 `url`,组件内部创建 chatHelper
178
+ - **集成模式**:传入 `chatHelper` 实例,复用父组件的状态
109
179
 
110
180
  ```vue
111
181
  <template>
112
182
  <ChatBot
113
183
  :url="apiUrl"
114
- :shortcuts="shortcuts"
184
+ height="600px"
185
+ max-width="800px"
115
186
  @send-message="handleSendMessage"
187
+ @error="handleError"
116
188
  />
117
189
  </template>
118
190
 
@@ -121,13 +193,14 @@ import { ref } from 'vue';
121
193
  import { ChatBot } from '@blueking/ai-blueking';
122
194
 
123
195
  const apiUrl = ref('https://your-api-endpoint.com');
124
- const shortcuts = ref([
125
- { label: '快捷操作1', value: '帮我分析这段代码' },
126
- ]);
127
196
 
128
197
  const handleSendMessage = (message: string) => {
129
198
  console.log('Message sent:', message);
130
199
  };
200
+
201
+ const handleError = (error: Error) => {
202
+ console.error('Error:', error);
203
+ };
131
204
  </script>
132
205
  ```
133
206
 
@@ -149,10 +222,19 @@ const handleSendMessage = (message: string) => {
149
222
 
150
223
  | 属性 | 类型 | 默认值 | 说明 |
151
224
  |------|------|--------|------|
152
- | `url` | `string` | - | API 端点 URL |
225
+ | `url` | `string` | - | API 端点 URL(独立模式) |
226
+ | `chatHelper` | `IChatHelper` | - | ChatHelper 实例(集成模式) |
227
+ | `height` | `string \| number` | - | 组件高度 |
228
+ | `maxWidth` | `string \| number` | - | 最大宽度 |
153
229
  | `shortcuts` | `Shortcut[]` | `[]` | 快捷操作列表 |
154
- | `placeholder` | `string` | `'请输入消息...'` | 输入框占位符 |
230
+ | `shortcutLimit` | `number` | `10` | 快捷方式数量限制 |
231
+ | `placeholder` | `string` | - | 输入框占位符 |
155
232
  | `autoLoad` | `boolean` | `true` | 是否自动加载会话 |
233
+ | `sessionCode` | `string` | - | 指定会话编码 |
234
+ | `enableSelection` | `boolean` | `false` | 是否启用消息选择 |
235
+ | `helloText` | `string` | - | 欢迎语 |
236
+ | `prompts` | `string[]` | - | 预设提示词列表 |
237
+ | `resources` | `IAiSlashMenuItem[]` | - | 资源列表(@ 触发) |
156
238
 
157
239
  ## Events
158
240
 
@@ -163,42 +245,57 @@ const handleSendMessage = (message: string) => {
163
245
  | `send-message` | `message: string` | 发送消息时触发 |
164
246
  | `receive-start` | - | 开始接收消息时触发 |
165
247
  | `receive-end` | - | 接收消息结束时触发 |
166
- | `session-initialized` | `session` | 会话初始化完成时触发 |
248
+ | `error` | `error: Error` | 发生错误时触发 |
249
+ | `agent-info-loaded` | `chatHelper: IChatHelper` | Agent 信息加载完成 |
250
+ | `session-switched` | `session: ISession` | 会话切换完成 |
251
+ | `shortcut-click` | `{ shortcut, source }` | 快捷指令被点击 |
252
+ | `feedback` | `tool, message, reasonList, otherReason` | 用户反馈 |
167
253
 
168
254
  ## 目录结构
169
255
 
170
256
  ```
171
- src/
172
- ├── ai-blueking.vue # 主组件入口
173
- ├── index.ts # 模块导出
174
- ├── vue2.ts # Vue2 入口(兼容层)
175
- ├── vue3.ts # Vue3 入口
176
- ├── types.ts # 全局类型定义
177
- ├── components/ # UI 组件
178
- │ ├── chat-bot.vue # ChatBot 核心组件
179
- ├── ai-header/ # 头部组件
180
- ├── selection-footer/ # 选择模式底部操作栏
181
- └── types.ts
182
- ├── composables/ # 可复用逻辑
183
- │ ├── use-chat-bootstrap.ts
184
- │ ├── use-event-bridge.ts
185
- └── ...
186
- ├── config/ # 配置文件
187
- │ ├── prop-defaults.ts
188
- └── protocol-config.ts
189
- ├── containers/ # 容器组件
190
- │ └── draggable-container.vue
191
- ├── manager/ # 管理器层
192
- │ ├── component-manager.ts
193
- │ ├── event-types.ts
194
- └── business/ # 业务管理器
195
- ├── chat-business-manager.ts
196
- ├── session-business-manager.ts
197
- └── shortcut-manager.ts # 快捷指令统一管理
198
- ├── styles/ # 样式文件
199
- ├── utils/ # 工具函数
200
- └── views/ # 视图组件
201
- └── nimbus.vue # 悬浮球
257
+ packages/ai-blueking/
258
+ ├── playground/ # 本地开发 Playground
259
+ ├── index.html
260
+ ├── main.js
261
+ │ └── App.vue
262
+ ├── scripts/ # 构建/开发脚本
263
+ ├── vite.dev.ts # 开发服务器配置
264
+ │ ├── vite.build.ts # 生产构建配置
265
+ └── vite.utils.ts # 共享配置
266
+ ├── src/
267
+ ├── ai-blueking.vue # 主组件入口(应用层)
268
+ ├── index.ts # 模块导出
269
+ │ ├── vue2.ts # Vue2 入口(兼容层)
270
+ │ ├── vue3.ts # Vue3 入口
271
+ ├── types.ts # 全局类型定义
272
+ ├── components/ # UI 组件层
273
+ ├── chat-bot.vue # ChatBot 核心聊天组件
274
+ │ ├── ai-header/ # 头部组件(含历史会话下拉)
275
+ │ │ ├── selection-footer/# 选择模式底部操作栏
276
+ └── types.ts
277
+ ├── composables/ # 可复用组合式逻辑
278
+ ├── use-chat-bootstrap.ts
279
+ ├── use-event-bridge.ts
280
+ │ ├── use-history-panel.ts
281
+ │ └── ...
282
+ ├── config/ # 配置文件
283
+ │ ├── prop-defaults.ts
284
+ │ │ └── protocol-config.ts
285
+ ├── containers/ # 容器组件(拖拽等)
286
+ │ ├── manager/ # 管理器层
287
+ │ │ ├── component-manager.ts
288
+ │ │ ├── event-types.ts
289
+ │ │ └── business/ # 业务管理器
290
+ │ │ ├── chat-business-manager.ts
291
+ │ │ ├── session-business-manager.ts
292
+ │ │ └── shortcut-manager.ts
293
+ │ ├── styles/ # 样式文件
294
+ │ ├── utils/ # 工具函数
295
+ │ └── views/ # 视图组件
296
+ │ └── nimbus.vue # 悬浮球
297
+ ├── .env.local # 本地环境变量(git 忽略)
298
+ └── package.json
202
299
  ```
203
300
 
204
301
  ## 划词选择功能
@@ -207,7 +304,6 @@ src/
207
304
 
208
305
  ```vue
209
306
  <template>
210
- <!-- 启用划词选择 -->
211
307
  <AIBlueking
212
308
  :url="apiUrl"
213
309
  :shortcuts="shortcuts"
@@ -230,15 +326,6 @@ src/
230
326
  - 显示对应的快捷指令表单
231
327
  - 将选中文本填充到 `fillBack` 字段
232
328
 
233
- ## 开发规范
234
-
235
- 开发时请遵循 [AI-Blueking V2 开发规范](https://github.com/TencentBlueKing/bk-aidev-agent/blob/main/.cursor/rules/ai-blueking-v2-development.mdc):
236
-
237
- 1. **遵循分层架构** - 严格遵守应用层 → 组件层 → 管理器层 → SDK层 的调用顺序
238
- 2. **事件驱动通信** - 跨组件通信必须使用事件系统
239
- 3. **类型安全** - 所有导出 API 必须有完整的类型定义
240
- 4. **避免重复** - 复用 chat-x 和 chat-helper 的功能
241
-
242
329
  ## 构建产物
243
330
 
244
331
  构建后的文件位于 `dist/` 目录:
@@ -259,12 +346,8 @@ dist/
259
346
  ## 版本兼容
260
347
 
261
348
  - **Vue 3.5+**: 完全支持(推荐)
262
- - **Vue 2.x**: 需要额外的兼容层(当前未实现)
349
+ - **Vue 2.x**: 需要额外的兼容层
263
350
 
264
351
  ## License
265
352
 
266
353
  MIT
267
-
268
- ## 作者
269
-
270
- Tencent BlueKing Team
@@ -1 +1 @@
1
- {"version":3,"file":"chat-bot.vue.d.ts","sourceRoot":"","sources":["../../src/components/chat-bot.vue"],"names":[],"mappings":"AAmpCE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,WA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;;;;6EAKd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AAWzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -27844,7 +27844,10 @@ var UIStateManager = class {
27844
27844
  Ug.value = [[]], Wg.value = "", a("send-message", typeof e == "string" ? e : ""), await Bg.sendMessage(e, r, n);
27845
27845
  }, l_ = async (e) => {
27846
27846
  let n = I?.session.current?.value?.sessionCode;
27847
- return n && await I.session.uploadFile(n, e) || {};
27847
+ if (!n) throw Error("[ChatBot] Cannot upload: no active session");
27848
+ let r = await I.session.uploadFile(n, e);
27849
+ if (!r?.download_url) throw Error("[ChatBot] Upload failed: no download URL returned");
27850
+ return r;
27848
27851
  }, u_ = async (e, n) => {
27849
27852
  try {
27850
27853
  await c_(e, Wg.value ? { property: { extra: { cite: Wg.value } } } : {});