@blueking/chat-x 0.0.24 → 0.0.26
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/ag-ui/types/constants.d.ts +1 -0
- package/dist/ag-ui/types/messages.d.ts +1 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/components/chat-content/flow-agent-content/flow-agent-content.vue.d.ts +1 -0
- package/dist/components/chat-content/flow-agent-content/flow-agent-node-detail.vue.d.ts +11 -1
- package/dist/components/chat-content/knowledge-rag-content/knowledge-rag-content.vue.d.ts +1 -0
- package/dist/components/chat-content/reference-doc-content/reference-doc-content.vue.d.ts +1 -0
- package/dist/components/execution-summary/execution-summary.vue.d.ts +2 -2
- package/dist/composables/use-custom-tab.d.ts +6 -2
- package/dist/composables/use-message-group.d.ts +72 -3
- package/dist/index.css +1 -1
- package/dist/index.js +1782 -1727
- package/dist/index.js.map +1 -1
- package/dist/mcp/generated/docs/activity-message.md +2 -0
- package/dist/mcp/generated/docs/chat-container.md +20 -8
- package/dist/mcp/generated/docs/chat-input.md +2 -2
- package/dist/mcp/generated/docs/code-content.md +10 -14
- package/dist/mcp/generated/docs/constants.md +242 -0
- package/dist/mcp/generated/docs/execution-summary.md +4 -4
- package/dist/mcp/generated/docs/markdown-container.md +56 -0
- package/dist/mcp/generated/docs/markdown-latex.md +208 -0
- package/dist/mcp/generated/docs/markdown-mermaid.md +250 -0
- package/dist/mcp/generated/docs/message-container.md +9 -8
- package/dist/mcp/generated/docs/messages.md +475 -0
- package/dist/mcp/generated/docs/theme.md +388 -0
- package/dist/mcp/generated/docs/use-custom-tab.md +2 -1
- package/dist/mcp/generated/docs/use-message-group.md +18 -7
- package/dist/mcp/generated/index.json +1293 -0
- package/dist/types/custom.d.ts +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
<!-- AI SUMMARY -->
|
|
2
|
+
## 快速了解
|
|
3
|
+
|
|
4
|
+
文档说明 Message 联合类型、BaseMessage、MessageRole、MessageStatus、User/Assistant/Tool/Activity/Reasoning 等具体形态及 MessageContentType。 业务构造 messages 数组供 ChatContainer/MessageContainer 渲染;Tool 消息经 useMessageGroup 注入 Assistant。可声明合并扩展 AIBluekingMessageMap。
|
|
5
|
+
|
|
6
|
+
### 关联组件
|
|
7
|
+
- **message-container** — 列表渲染与工具栏
|
|
8
|
+
- **message-render** — 按 role 分发渲染
|
|
9
|
+
- **chat-container** — 数据源与交互入口
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
<!-- FULL DOC -->
|
|
13
|
+
|
|
14
|
+
# 消息类型
|
|
15
|
+
|
|
16
|
+
> **分类**:type
|
|
17
|
+
|
|
18
|
+
`@blueking/chat-x` 提供了完整的消息类型定义,用于构建 AI 对话消息。
|
|
19
|
+
|
|
20
|
+
## 消息基础类型
|
|
21
|
+
|
|
22
|
+
### Message
|
|
23
|
+
|
|
24
|
+
所有消息类型的联合类型:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
type Message = MessageMap[MessageType];
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### BaseMessage
|
|
31
|
+
|
|
32
|
+
消息基础接口:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
interface BaseMessage<T extends MessageType, C = string> {
|
|
36
|
+
// 消息唯一 ID(客户端生成)
|
|
37
|
+
id: number | string;
|
|
38
|
+
|
|
39
|
+
// 消息 ID(服务端返回)
|
|
40
|
+
messageId: number | string;
|
|
41
|
+
|
|
42
|
+
// 消息角色
|
|
43
|
+
role: T;
|
|
44
|
+
|
|
45
|
+
// 消息内容
|
|
46
|
+
content: C;
|
|
47
|
+
|
|
48
|
+
// 消息状态
|
|
49
|
+
status: MessageStatus;
|
|
50
|
+
|
|
51
|
+
// 可选:单条消息实例唯一标识(`useMessageGroup` 在缺失时会自动生成并写回)
|
|
52
|
+
uid?: string;
|
|
53
|
+
|
|
54
|
+
// 消息名称(可选)
|
|
55
|
+
name?: string;
|
|
56
|
+
|
|
57
|
+
// 消息属性(可选)
|
|
58
|
+
property?: {
|
|
59
|
+
extra?: {
|
|
60
|
+
// 引用内容
|
|
61
|
+
cite:
|
|
62
|
+
| string
|
|
63
|
+
| {
|
|
64
|
+
title: string;
|
|
65
|
+
data: { key: string; value: string }[];
|
|
66
|
+
type: 'structured';
|
|
67
|
+
};
|
|
68
|
+
// 快捷指令名称
|
|
69
|
+
command: string;
|
|
70
|
+
// 上下文信息
|
|
71
|
+
context: Record<string, any>[];
|
|
72
|
+
// 快捷指令配置
|
|
73
|
+
shortcut?: Shortcut;
|
|
74
|
+
// 暂停标记:为 true 时该消息所在消息组不显示 MessageTools 工具栏
|
|
75
|
+
pause?: boolean;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 消息角色
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
enum MessageRole {
|
|
85
|
+
// 用户消息
|
|
86
|
+
User = 'user',
|
|
87
|
+
|
|
88
|
+
// AI 助手消息
|
|
89
|
+
Assistant = 'assistant',
|
|
90
|
+
|
|
91
|
+
// 系统消息
|
|
92
|
+
System = 'system',
|
|
93
|
+
|
|
94
|
+
// 开发者消息
|
|
95
|
+
Developer = 'developer',
|
|
96
|
+
|
|
97
|
+
// 引导消息
|
|
98
|
+
Guide = 'guide',
|
|
99
|
+
|
|
100
|
+
// 隐藏消息(不显示)
|
|
101
|
+
Hidden = 'hidden',
|
|
102
|
+
HiddenAssistant = 'hidden-assistant',
|
|
103
|
+
HiddenGuide = 'hidden-guide',
|
|
104
|
+
HiddenSystem = 'hidden-system',
|
|
105
|
+
HiddenUser = 'hidden-user',
|
|
106
|
+
|
|
107
|
+
// 信息消息
|
|
108
|
+
Info = 'info',
|
|
109
|
+
|
|
110
|
+
// 加载中消息
|
|
111
|
+
Loading = 'loading',
|
|
112
|
+
|
|
113
|
+
// 暂停消息
|
|
114
|
+
Pause = 'pause',
|
|
115
|
+
|
|
116
|
+
// 占位消息
|
|
117
|
+
Placeholder = 'placeholder',
|
|
118
|
+
|
|
119
|
+
// 推理过程消息
|
|
120
|
+
Reasoning = 'reasoning',
|
|
121
|
+
|
|
122
|
+
// 模板消息
|
|
123
|
+
TemplateAssistant = 'template-assistant',
|
|
124
|
+
TemplateGuide = 'template-guide',
|
|
125
|
+
TemplateHidden = 'template-hidden',
|
|
126
|
+
TemplateSystem = 'template-system',
|
|
127
|
+
TemplateUser = 'template-user',
|
|
128
|
+
|
|
129
|
+
// 工具调用消息
|
|
130
|
+
Tool = 'tool',
|
|
131
|
+
|
|
132
|
+
// 活动消息(如引用文档)
|
|
133
|
+
Activity = 'activity',
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## 消息状态
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
enum MessageStatus {
|
|
141
|
+
// 等待中
|
|
142
|
+
Pending = 'pending',
|
|
143
|
+
|
|
144
|
+
// 流式输出中
|
|
145
|
+
Streaming = 'streaming',
|
|
146
|
+
|
|
147
|
+
// 已完成
|
|
148
|
+
Complete = 'complete',
|
|
149
|
+
|
|
150
|
+
// 错误
|
|
151
|
+
Error = 'error',
|
|
152
|
+
|
|
153
|
+
// 已停止
|
|
154
|
+
Stop = 'stop',
|
|
155
|
+
|
|
156
|
+
// 已禁用
|
|
157
|
+
Disabled = 'disabled',
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## 具体消息类型
|
|
162
|
+
|
|
163
|
+
### UserMessage
|
|
164
|
+
|
|
165
|
+
用户消息:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
type UserMessage = BaseMessage<MessageRole.User, InputContent[] | string>;
|
|
169
|
+
|
|
170
|
+
// 示例
|
|
171
|
+
const userMessage: UserMessage = {
|
|
172
|
+
id: '1',
|
|
173
|
+
messageId: 1,
|
|
174
|
+
role: MessageRole.User,
|
|
175
|
+
content: '你好',
|
|
176
|
+
status: MessageStatus.Complete,
|
|
177
|
+
};
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### AssistantMessage
|
|
181
|
+
|
|
182
|
+
AI 助手消息:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
interface AssistantMessage extends BaseMessage<MessageRole.Assistant> {
|
|
186
|
+
// 工具调用列表
|
|
187
|
+
toolCalls?: ToolCall[];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// 工具调用
|
|
191
|
+
type ToolCall = {
|
|
192
|
+
id: string;
|
|
193
|
+
type: MessageContentType.Function;
|
|
194
|
+
function: FunctionCall;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
type FunctionCall = {
|
|
198
|
+
name: string;
|
|
199
|
+
arguments: string;
|
|
200
|
+
description?: string;
|
|
201
|
+
mcpName?: string;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// 示例
|
|
205
|
+
const assistantMessage: AssistantMessage = {
|
|
206
|
+
id: '2',
|
|
207
|
+
messageId: 2,
|
|
208
|
+
role: MessageRole.Assistant,
|
|
209
|
+
content: '你好!有什么可以帮助你的?',
|
|
210
|
+
status: MessageStatus.Complete,
|
|
211
|
+
toolCalls: [
|
|
212
|
+
{
|
|
213
|
+
id: 'call_1',
|
|
214
|
+
type: MessageContentType.Function,
|
|
215
|
+
function: {
|
|
216
|
+
name: 'get_weather',
|
|
217
|
+
arguments: '{"city": "北京"}',
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
};
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### ReasoningMessage
|
|
225
|
+
|
|
226
|
+
推理过程消息:
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
interface ReasoningMessage extends BaseMessage<MessageRole.Reasoning, string[]> {
|
|
230
|
+
// 推理耗时(毫秒)
|
|
231
|
+
duration?: number;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 示例
|
|
235
|
+
const reasoningMessage: ReasoningMessage = {
|
|
236
|
+
id: '3',
|
|
237
|
+
messageId: 3,
|
|
238
|
+
role: MessageRole.Reasoning,
|
|
239
|
+
content: ['让我分析一下这个问题...', '首先,需要考虑以下几点:', '1. 技术可行性'],
|
|
240
|
+
status: MessageStatus.Complete,
|
|
241
|
+
duration: 3500,
|
|
242
|
+
};
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### ToolMessage
|
|
246
|
+
|
|
247
|
+
工具调用结果消息:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
interface ToolMessage extends BaseMessage<MessageRole.Tool, string> {
|
|
251
|
+
// 工具调用 ID(对应 AssistantMessage 中的 toolCalls[].id)
|
|
252
|
+
toolCallId: string;
|
|
253
|
+
|
|
254
|
+
// 执行耗时(毫秒)
|
|
255
|
+
duration: number;
|
|
256
|
+
|
|
257
|
+
// 错误信息
|
|
258
|
+
error?: string;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// 示例
|
|
262
|
+
const toolMessage: ToolMessage = {
|
|
263
|
+
id: '4',
|
|
264
|
+
messageId: 4,
|
|
265
|
+
role: MessageRole.Tool,
|
|
266
|
+
content: '{"temperature": 25, "weather": "晴天"}',
|
|
267
|
+
status: MessageStatus.Complete,
|
|
268
|
+
toolCallId: 'call_1',
|
|
269
|
+
duration: 1200,
|
|
270
|
+
};
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### ActivityMessage
|
|
274
|
+
|
|
275
|
+
活动消息(如引用文档、知识检索):
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
// 引用文档内容类型
|
|
279
|
+
type ReferenceDocumentContent = {
|
|
280
|
+
name: string;
|
|
281
|
+
originFile: string;
|
|
282
|
+
url: string;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// 知识检索内容类型
|
|
286
|
+
type KnowledgeRagContent = {
|
|
287
|
+
content: string;
|
|
288
|
+
referenceDocument: ReferenceDocumentContent[];
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
interface ActivityMessage extends BaseMessage<MessageRole.Activity, KnowledgeRagContent | ReferenceDocumentContent[]> {
|
|
292
|
+
activityType: MessageContentType.KnowledgeRag | MessageContentType.ReferenceDocument | string;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// 示例 1:引用文档
|
|
296
|
+
const referenceMessage: ActivityMessage = {
|
|
297
|
+
id: '5',
|
|
298
|
+
messageId: 5,
|
|
299
|
+
role: MessageRole.Activity,
|
|
300
|
+
content: [
|
|
301
|
+
{ name: '参考文档 1', url: 'https://example.com/1', originFile: 'https://example.com/origin/1' },
|
|
302
|
+
{ name: '参考文档 2', url: 'https://example.com/2', originFile: 'https://example.com/origin/2' },
|
|
303
|
+
],
|
|
304
|
+
status: MessageStatus.Complete,
|
|
305
|
+
activityType: 'reference',
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// 示例 2:知识检索(knowledge_rag)
|
|
309
|
+
const knowledgeRagMessage: ActivityMessage = {
|
|
310
|
+
id: '6',
|
|
311
|
+
messageId: 6,
|
|
312
|
+
role: MessageRole.Activity,
|
|
313
|
+
content: {
|
|
314
|
+
content: '开始召回知识\n重排召回结果中\n完成召回并分类\n',
|
|
315
|
+
referenceDocument: [
|
|
316
|
+
{ name: '知识文档 1', url: 'https://example.com/doc1', originFile: 'https://example.com/origin/doc1' },
|
|
317
|
+
{ name: '知识文档 2', url: 'https://example.com/doc2', originFile: 'https://example.com/origin/doc2' },
|
|
318
|
+
],
|
|
319
|
+
},
|
|
320
|
+
status: MessageStatus.Complete,
|
|
321
|
+
activityType: 'knowledge_rag',
|
|
322
|
+
};
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
**ActivityMessage 类型说明:**
|
|
326
|
+
|
|
327
|
+
| activityType | content 类型 | 说明 |
|
|
328
|
+
| ----------------- | ---------------------------- | ---------------------------------------- |
|
|
329
|
+
| `'reference'` | `ReferenceDocumentContent[]` | 引用文档列表 |
|
|
330
|
+
| `'knowledge_rag'` | `KnowledgeRagContent` | 知识检索结果,包含检索过程内容和引用文档 |
|
|
331
|
+
|
|
332
|
+
**ReferenceDocumentContent 字段说明:**
|
|
333
|
+
|
|
334
|
+
| 字段 | 类型 | 说明 |
|
|
335
|
+
| ------------ | -------- | ---------------- |
|
|
336
|
+
| `name` | `string` | 文档名称 |
|
|
337
|
+
| `url` | `string` | 文档预览链接 |
|
|
338
|
+
| `originFile` | `string` | 文档原始文件链接 |
|
|
339
|
+
|
|
340
|
+
### InfoMessage
|
|
341
|
+
|
|
342
|
+
信息消息:
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
type InfoMessage = BaseMessage<MessageRole.Info, string>;
|
|
346
|
+
|
|
347
|
+
// 示例
|
|
348
|
+
const infoMessage: InfoMessage = {
|
|
349
|
+
id: '6',
|
|
350
|
+
messageId: 6,
|
|
351
|
+
role: MessageRole.Info,
|
|
352
|
+
content: '会话已开始',
|
|
353
|
+
status: MessageStatus.Complete,
|
|
354
|
+
};
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### LoadingMessage
|
|
358
|
+
|
|
359
|
+
加载中消息,用于在等待 AI 响应时显示加载状态:
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
type LoadingMessage = BaseMessage<MessageRole.Loading, string>;
|
|
363
|
+
|
|
364
|
+
// 示例
|
|
365
|
+
const loadingMessage: LoadingMessage = {
|
|
366
|
+
id: 'loading',
|
|
367
|
+
messageId: '',
|
|
368
|
+
role: MessageRole.Loading,
|
|
369
|
+
content: '',
|
|
370
|
+
status: MessageStatus.Pending,
|
|
371
|
+
};
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## 消息内容类型
|
|
375
|
+
|
|
376
|
+
```typescript
|
|
377
|
+
enum MessageContentType {
|
|
378
|
+
// 二进制内容
|
|
379
|
+
Binary = 'binary',
|
|
380
|
+
|
|
381
|
+
// 函数调用
|
|
382
|
+
Function = 'function',
|
|
383
|
+
|
|
384
|
+
// 键值对
|
|
385
|
+
KeyValue = 'key-value',
|
|
386
|
+
|
|
387
|
+
// 知识检索
|
|
388
|
+
KnowledgeRag = 'knowledge-rag',
|
|
389
|
+
|
|
390
|
+
// 其他
|
|
391
|
+
Other = 'other',
|
|
392
|
+
|
|
393
|
+
// 引用文档
|
|
394
|
+
ReferenceDocument = 'reference-document',
|
|
395
|
+
|
|
396
|
+
// 文本
|
|
397
|
+
Text = 'text',
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
## 类型扩展
|
|
402
|
+
|
|
403
|
+
支持通过声明合并扩展消息类型:
|
|
404
|
+
|
|
405
|
+
```typescript
|
|
406
|
+
// 在项目中扩展
|
|
407
|
+
declare global {
|
|
408
|
+
interface AIBluekingMessageMap {
|
|
409
|
+
'custom-role': CustomMessage;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
interface CustomMessage extends BaseMessage<'custom-role'> {
|
|
414
|
+
customField: string;
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
## 使用示例
|
|
419
|
+
|
|
420
|
+
```vue
|
|
421
|
+
<template>
|
|
422
|
+
<MessageContainer
|
|
423
|
+
:messages="messages"
|
|
424
|
+
:message-status="messageStatus"
|
|
425
|
+
:on-agent-action="handleAgentAction"
|
|
426
|
+
:on-user-action="handleUserAction"
|
|
427
|
+
/>
|
|
428
|
+
</template>
|
|
429
|
+
|
|
430
|
+
<script setup lang="ts">
|
|
431
|
+
import { ref } from 'vue';
|
|
432
|
+
import { MessageContainer, MessageRole, MessageStatus, type Message } from '@blueking/chat-x';
|
|
433
|
+
|
|
434
|
+
const messageStatus = ref<MessageStatus>(MessageStatus.Complete);
|
|
435
|
+
|
|
436
|
+
const messages = ref<Message[]>([
|
|
437
|
+
{
|
|
438
|
+
id: '1',
|
|
439
|
+
messageId: 1,
|
|
440
|
+
role: MessageRole.User,
|
|
441
|
+
content: '你好',
|
|
442
|
+
status: MessageStatus.Complete,
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
id: '2',
|
|
446
|
+
messageId: 2,
|
|
447
|
+
role: MessageRole.Reasoning,
|
|
448
|
+
content: ['思考中...', '分析问题...'],
|
|
449
|
+
status: MessageStatus.Complete,
|
|
450
|
+
duration: 2000,
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
id: '3',
|
|
454
|
+
messageId: 3,
|
|
455
|
+
role: MessageRole.Assistant,
|
|
456
|
+
content: '你好!有什么可以帮助你的?',
|
|
457
|
+
status: MessageStatus.Complete,
|
|
458
|
+
},
|
|
459
|
+
]);
|
|
460
|
+
|
|
461
|
+
const handleAgentAction = async tool => {
|
|
462
|
+
console.log('Agent action:', tool);
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
const handleUserAction = async tool => {
|
|
466
|
+
console.log('User action:', tool);
|
|
467
|
+
};
|
|
468
|
+
</script>
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## 关联组件
|
|
472
|
+
|
|
473
|
+
- [MessageContainer](../components/molecular/message-container.md) — 消息列表
|
|
474
|
+
- [MessageRender](../components/molecular/message-render.md) — 单条消息渲染
|
|
475
|
+
- [ChatContainer](../components/molecular/chat-container.md) — 聊天容器
|