@blueking/chat-x 0.0.51-beta.5 → 0.0.52-dev.1
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 +15 -8
- package/dist/ag-ui/types/contents.d.ts +2 -0
- package/dist/ag-ui/types/messages.d.ts +6 -1
- package/dist/common/constants.d.ts +2 -0
- package/dist/components/ai-buttons/add-menu-btn/add-menu-btn.vue.d.ts +24 -0
- package/dist/components/chat-content/collapsible-content/collapsible-content.vue.d.ts +28 -0
- package/dist/components/chat-content/file-content/upload-file-item.vue.d.ts +5 -2
- package/dist/components/chat-content/file-content/upload-image-item.vue.d.ts +1 -0
- package/dist/components/chat-content/flow-agent-content/use-flow-node-actions.d.ts +1 -1
- package/dist/components/chat-input/ai-slash-input/ai-slash-input.vue.d.ts +21 -10
- package/dist/components/chat-input/ai-slash-input/command.d.ts +6 -3
- package/dist/components/chat-input/ai-slash-input/constants.d.ts +2 -0
- package/dist/components/chat-input/ai-slash-input/use-menu-trigger.d.ts +17 -0
- package/dist/components/chat-input/build-default-placeholder.d.ts +9 -3
- package/dist/components/chat-input/chat-input.vue.d.ts +30 -18
- package/dist/components/chat-input/input-menu/constants.d.ts +60 -0
- package/dist/components/chat-input/input-menu/index.d.ts +4 -0
- package/dist/components/chat-input/input-menu/input-menu-option.vue.d.ts +14 -0
- package/dist/components/chat-input/input-menu/input-menu-panel.vue.d.ts +17 -0
- package/dist/components/chat-input/input-menu/use-input-menu.d.ts +22 -0
- package/dist/components/chat-input/model-selector/types.d.ts +3 -2
- package/dist/components/chat-message/message-container/message-container.vue.d.ts +1 -1
- package/dist/components/chat-message/user-message/user-message.vue.d.ts +1 -1
- package/dist/components/mention/create-mention-tippy.d.ts +27 -0
- package/dist/components/mention/index.d.ts +4 -0
- package/dist/components/{chat-input/ai-slash-input/ai-prompt-list/ai-prompt-list.vue.d.ts → mention/mention-popover.vue.d.ts} +3 -2
- package/dist/components/{chat-input/ai-slash-input/ai-skill-list/ai-skill-list.vue.d.ts → mention/mention-tag.vue.d.ts} +7 -3
- package/dist/components/{chat-input/ai-slash-input/ai-slash-menu/ai-slash-menu.vue.d.ts → mention/mention-text.vue.d.ts} +3 -3
- package/dist/components/resource-icon/index.d.ts +1 -0
- package/dist/components/resource-icon/resource-icon.vue.d.ts +11 -0
- package/dist/composables/index.d.ts +1 -0
- package/dist/composables/use-artifact-preview.d.ts +5 -2
- package/dist/composables/use-common.d.ts +0 -9
- package/dist/composables/use-global-config.d.ts +4 -0
- package/dist/composables/use-input-mention.d.ts +13 -0
- package/dist/composables/use-message-group.d.ts +1011 -72
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/input.d.ts +21 -0
- package/dist/icons/menu-item.d.ts +22 -0
- package/dist/index.css +1 -1
- package/dist/index.js +4953 -4429
- package/dist/index.js.map +1 -1
- package/dist/lang/lang.d.ts +13 -3
- package/dist/mcp/generated/docs/activity-message.md +3 -3
- package/dist/mcp/generated/docs/add-menu-btn.md +91 -0
- package/dist/mcp/generated/docs/ai-slash-input.md +72 -26
- package/dist/mcp/generated/docs/assistant-message.md +7 -1
- package/dist/mcp/generated/docs/chat-container.md +45 -6
- package/dist/mcp/generated/docs/chat-input.md +327 -483
- package/dist/mcp/generated/docs/collapsible-content.md +78 -0
- package/dist/mcp/generated/docs/constants.md +36 -3
- package/dist/mcp/generated/docs/execution-summary.md +1 -23
- package/dist/mcp/generated/docs/file-artifact-panel.md +24 -5
- package/dist/mcp/generated/docs/file-content.md +4 -0
- package/dist/mcp/generated/docs/file-upload-btn.md +15 -12
- package/dist/mcp/generated/docs/flow-agent-content.md +10 -12
- package/dist/mcp/generated/docs/input-menu-panel.md +166 -0
- package/dist/mcp/generated/docs/mention-tag.md +83 -0
- package/dist/mcp/generated/docs/mention-text.md +86 -0
- package/dist/mcp/generated/docs/message-container.md +1 -1
- package/dist/mcp/generated/docs/message-render.md +1 -1
- package/dist/mcp/generated/docs/message-tools.md +15 -4
- package/dist/mcp/generated/docs/messages.md +3 -0
- package/dist/mcp/generated/docs/model-selector.md +4 -2
- package/dist/mcp/generated/docs/overflow-tips.md +3 -3
- package/dist/mcp/generated/docs/resource-icon.md +102 -0
- package/dist/mcp/generated/docs/text-content.md +7 -3
- package/dist/mcp/generated/docs/theme.md +27 -35
- package/dist/mcp/generated/docs/use-artifact-preview.md +7 -3
- package/dist/mcp/generated/docs/use-command-selection.md +1 -1
- package/dist/mcp/generated/docs/use-container-scroll.md +2 -1
- package/dist/mcp/generated/docs/use-flow-node-actions.md +8 -15
- package/dist/mcp/generated/docs/use-global-config.md +11 -4
- package/dist/mcp/generated/docs/use-input-mention.md +119 -0
- package/dist/mcp/generated/docs/use-menu-keydown.md +15 -16
- package/dist/mcp/generated/docs/use-message-group.md +3 -6
- package/dist/mcp/generated/docs/user-message.md +39 -17
- package/dist/mcp/generated/index.json +233 -81
- package/dist/types/editor.d.ts +0 -29
- package/dist/types/index.d.ts +1 -0
- package/dist/types/input-menu.d.ts +46 -0
- package/dist/utils/artifact-tags.d.ts +36 -0
- package/dist/utils/collect-message-artifacts.d.ts +14 -0
- package/dist/utils/file.d.ts +3 -3
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/upload-file.d.ts +6 -1
- package/package.json +3 -2
- package/skills/blueking-chat-x/SKILL.md +143 -0
- package/skills/blueking-chat-x/references/_index.md +153 -0
- package/skills/blueking-chat-x/references/components/activity-layout.md +134 -0
- package/skills/blueking-chat-x/references/components/activity-message.md +486 -0
- package/skills/blueking-chat-x/references/components/add-menu-btn.md +88 -0
- package/skills/blueking-chat-x/references/components/ai-image.md +230 -0
- package/skills/blueking-chat-x/references/components/ai-loading.md +131 -0
- package/skills/blueking-chat-x/references/components/ai-selection.md +439 -0
- package/skills/blueking-chat-x/references/components/ai-slash-input.md +102 -0
- package/skills/blueking-chat-x/references/components/animation-text.md +202 -0
- package/skills/blueking-chat-x/references/components/assistant-message.md +504 -0
- package/skills/blueking-chat-x/references/components/chat-container.md +912 -0
- package/skills/blueking-chat-x/references/components/chat-input.md +614 -0
- package/skills/blueking-chat-x/references/components/cite-content.md +142 -0
- package/skills/blueking-chat-x/references/components/code-content.md +211 -0
- package/skills/blueking-chat-x/references/components/collapsible-content.md +76 -0
- package/skills/blueking-chat-x/references/components/common-error-content.md +73 -0
- package/skills/blueking-chat-x/references/components/content-render.md +233 -0
- package/skills/blueking-chat-x/references/components/delete-tool.md +191 -0
- package/skills/blueking-chat-x/references/components/desc-panel.md +162 -0
- package/skills/blueking-chat-x/references/components/detail-section.md +91 -0
- package/skills/blueking-chat-x/references/components/execution-summary.md +150 -0
- package/skills/blueking-chat-x/references/components/file-artifact-panel.md +307 -0
- package/skills/blueking-chat-x/references/components/file-content.md +340 -0
- package/skills/blueking-chat-x/references/components/file-icon.md +109 -0
- package/skills/blueking-chat-x/references/components/file-upload-btn.md +162 -0
- package/skills/blueking-chat-x/references/components/flow-agent-content.md +266 -0
- package/skills/blueking-chat-x/references/components/flow-agent-node-detail.md +236 -0
- package/skills/blueking-chat-x/references/components/highlight-keyword.md +146 -0
- package/skills/blueking-chat-x/references/components/image-content.md +182 -0
- package/skills/blueking-chat-x/references/components/image-preview-group.md +184 -0
- package/skills/blueking-chat-x/references/components/image-preview.md +226 -0
- package/skills/blueking-chat-x/references/components/info-message.md +144 -0
- package/skills/blueking-chat-x/references/components/input-attachment.md +49 -0
- package/skills/blueking-chat-x/references/components/input-info-alert.md +42 -0
- package/skills/blueking-chat-x/references/components/input-menu-panel.md +162 -0
- package/skills/blueking-chat-x/references/components/interrupt-message.md +212 -0
- package/skills/blueking-chat-x/references/components/key-value-content.md +128 -0
- package/skills/blueking-chat-x/references/components/knowledge-rag-content.md +122 -0
- package/skills/blueking-chat-x/references/components/latex-content.md +200 -0
- package/skills/blueking-chat-x/references/components/loading-message.md +192 -0
- package/skills/blueking-chat-x/references/components/markdown-content.md +232 -0
- package/skills/blueking-chat-x/references/components/mention-tag.md +79 -0
- package/skills/blueking-chat-x/references/components/mention-text.md +83 -0
- package/skills/blueking-chat-x/references/components/mermaid-content.md +189 -0
- package/skills/blueking-chat-x/references/components/message-container.md +645 -0
- package/skills/blueking-chat-x/references/components/message-loading.md +118 -0
- package/skills/blueking-chat-x/references/components/message-render.md +327 -0
- package/skills/blueking-chat-x/references/components/message-time.md +177 -0
- package/skills/blueking-chat-x/references/components/message-tools.md +427 -0
- package/skills/blueking-chat-x/references/components/model-selector.md +157 -0
- package/skills/blueking-chat-x/references/components/preview-toolbar.md +42 -0
- package/skills/blueking-chat-x/references/components/questions-container.md +85 -0
- package/skills/blueking-chat-x/references/components/reasoning-message.md +232 -0
- package/skills/blueking-chat-x/references/components/reference-content.md +135 -0
- package/skills/blueking-chat-x/references/components/reference-doc-content.md +109 -0
- package/skills/blueking-chat-x/references/components/resource-icon.md +98 -0
- package/skills/blueking-chat-x/references/components/scroll-btn.md +159 -0
- package/skills/blueking-chat-x/references/components/selection-footer.md +78 -0
- package/skills/blueking-chat-x/references/components/selection-question.md +88 -0
- package/skills/blueking-chat-x/references/components/shortcut-btn.md +204 -0
- package/skills/blueking-chat-x/references/components/shortcut-btns.md +266 -0
- package/skills/blueking-chat-x/references/components/shortcut-render.md +424 -0
- package/skills/blueking-chat-x/references/components/simple-table.md +101 -0
- package/skills/blueking-chat-x/references/components/text-content.md +80 -0
- package/skills/blueking-chat-x/references/components/tool-approval-card.md +183 -0
- package/skills/blueking-chat-x/references/components/tool-btn.md +317 -0
- package/skills/blueking-chat-x/references/components/tool-message.md +235 -0
- package/skills/blueking-chat-x/references/components/toolcall-render.md +348 -0
- package/skills/blueking-chat-x/references/components/user-feedback.md +233 -0
- package/skills/blueking-chat-x/references/components/user-message.md +444 -0
- package/skills/blueking-chat-x/references/components/user-question-answered-card.md +104 -0
- package/skills/blueking-chat-x/references/components/user-question-card.md +231 -0
- package/skills/blueking-chat-x/references/components/user-question-choice.md +105 -0
- package/skills/blueking-chat-x/references/components/user-question-option.md +42 -0
- package/skills/blueking-chat-x/references/components/vnode-renderer.md +122 -0
- package/skills/blueking-chat-x/references/composables/use-animation-text.md +196 -0
- package/skills/blueking-chat-x/references/composables/use-artifact-preview.md +235 -0
- package/skills/blueking-chat-x/references/composables/use-clipboard.md +203 -0
- package/skills/blueking-chat-x/references/composables/use-command-selection.md +150 -0
- package/skills/blueking-chat-x/references/composables/use-container-scroll.md +57 -0
- package/skills/blueking-chat-x/references/composables/use-custom-tab.md +158 -0
- package/skills/blueking-chat-x/references/composables/use-flow-node-actions.md +164 -0
- package/skills/blueking-chat-x/references/composables/use-full-screen.md +112 -0
- package/skills/blueking-chat-x/references/composables/use-global-config.md +155 -0
- package/skills/blueking-chat-x/references/composables/use-input-mention.md +115 -0
- package/skills/blueking-chat-x/references/composables/use-menu-keydown.md +161 -0
- package/skills/blueking-chat-x/references/composables/use-message-group.md +244 -0
- package/skills/blueking-chat-x/references/composables/use-observer-visible-list.md +188 -0
- package/skills/blueking-chat-x/references/composables/use-parent-scrolling.md +46 -0
- package/skills/blueking-chat-x/references/directives/index.md +61 -0
- package/skills/blueking-chat-x/references/directives/overflow-tips.md +205 -0
- package/skills/blueking-chat-x/references/icons/index.md +185 -0
- package/skills/blueking-chat-x/references/plugins/index.md +56 -0
- package/skills/blueking-chat-x/references/plugins/markdown-container.md +55 -0
- package/skills/blueking-chat-x/references/plugins/markdown-latex.md +205 -0
- package/skills/blueking-chat-x/references/plugins/markdown-mermaid.md +247 -0
- package/skills/blueking-chat-x/references/theme/theme.md +423 -0
- package/skills/blueking-chat-x/references/types/constants.md +340 -0
- package/skills/blueking-chat-x/references/types/index.md +120 -0
- package/skills/blueking-chat-x/references/types/interrupt.md +379 -0
- package/skills/blueking-chat-x/references/types/messages.md +556 -0
- package/skills/blueking-chat-x/references/types/schema.md +91 -0
- package/skills/blueking-chat-x/references/utils/index.md +196 -0
- package/skills/blueking-chat-x/scripts/generate-references.mjs +536 -0
- package/dist/components/chat-input/ai-slash-editor/ai-slash-editor.vue.d.ts +0 -28
- package/dist/components/chat-input/ai-slash-editor/theme.d.ts +0 -24
- package/dist/mcp/generated/docs/ai-prompt-list.md +0 -45
- package/dist/mcp/generated/docs/ai-skill-list.md +0 -75
- package/dist/mcp/generated/docs/ai-slash-editor.md +0 -43
- package/dist/mcp/generated/docs/ai-slash-menu.md +0 -42
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# ToolMessage 工具消息
|
|
2
|
+
|
|
3
|
+
> 能力域:消息系统 | 未从包入口导出:内部组件(入口的同名导出是 TS 类型,不是组件) | since 0.0.20
|
|
4
|
+
|
|
5
|
+
渲染工具返回内容;DescPanel 解析 JSON 为 key-value,嵌套值 JSON.stringify 后经 HighlightKeyword 展示。 源码位置:src/components/chat-message/tool-message/tool-message.vue。
|
|
6
|
+
|
|
7
|
+
**关联**:assistant-message(结果常作为 assistant 消息中 toolCall.toolMessage 内联展示)、message-render(独立 tool 角色消息由 MessageRender 渲染为 ToolMessage)、desc-panel(内部使用 DescPanel 展示「返回内容」)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# ToolMessage 工具消息
|
|
12
|
+
|
|
13
|
+
## 源码事实
|
|
14
|
+
|
|
15
|
+
- **源码位置**:`src/components/chat-message/tool-message/tool-message.vue`
|
|
16
|
+
- **能力域**:消息系统
|
|
17
|
+
- **能力说明**:渲染工具返回内容,JSON 场景交给 DescPanel + HighlightKeyword 展示。
|
|
18
|
+
|
|
19
|
+
> **导出说明**:`ToolMessage` **未**从包入口导出(入口同名是 TS interface)。消费方经 `MessageRender` / `ToolcallRender` 使用。下文 `ToolMessageComp` 为文档站内部示例。
|
|
20
|
+
|
|
21
|
+
工具执行结果展示组件。内部通过 `DescPanel` 渲染,标题固定为「返回内容」,可解析 JSON 为 key-value 列表。
|
|
22
|
+
|
|
23
|
+
> **通常不需要直接使用**。`ToolcallRender` 在 `toolCall.toolMessage` 有值时内联渲染;`role: 'tool'` 也可由 `MessageRender` 渲染。
|
|
24
|
+
|
|
25
|
+
## 渲染架构
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
ToolMessage
|
|
29
|
+
└── DescPanel(desc = content || (typeof error === 'string' ? error : undefined),title="返回内容")
|
|
30
|
+
├── JSON.parse 成功且结果为 object/array(排除 null)
|
|
31
|
+
│ └── key-value 列表
|
|
32
|
+
│ · key / value 均经 HighlightKeyword 展示
|
|
33
|
+
│ · 嵌套 object/array:JSON.stringify 后展示(无 overflow-tips)
|
|
34
|
+
└── 其他(parse 失败 / 标量)
|
|
35
|
+
└── HighlightKeyword 纯文本
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 基础用法
|
|
39
|
+
|
|
40
|
+
```vue
|
|
41
|
+
<template>
|
|
42
|
+
<MessageRender :message="message" />
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script setup lang="ts">
|
|
46
|
+
import { MessageRender, MessageRole, MessageStatus } from '@blueking/chat-x';
|
|
47
|
+
|
|
48
|
+
const message = {
|
|
49
|
+
id: 't1',
|
|
50
|
+
messageId: 't1',
|
|
51
|
+
role: MessageRole.Tool,
|
|
52
|
+
status: MessageStatus.Complete,
|
|
53
|
+
toolCallId: 'call_1',
|
|
54
|
+
duration: 850,
|
|
55
|
+
content: JSON.stringify({
|
|
56
|
+
city: '北京',
|
|
57
|
+
temperature: 22,
|
|
58
|
+
weather: '晴',
|
|
59
|
+
humidity: '45%',
|
|
60
|
+
wind: '东北风 3 级',
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
63
|
+
</script>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**JSON 对象内容(key-value 列表)**
|
|
67
|
+
|
|
68
|
+
**纯文本内容**
|
|
69
|
+
|
|
70
|
+
## 错误状态
|
|
71
|
+
|
|
72
|
+
`content` 为空时展示 `error`,由 `content || (typeof error === 'string' ? error : undefined)` 决定。仅当 `error` 为字符串类型时才会展示,非字符串类型的 `error`(如对象)会被忽略:
|
|
73
|
+
|
|
74
|
+
```vue
|
|
75
|
+
<template>
|
|
76
|
+
<MessageRender :message="message" />
|
|
77
|
+
</template>
|
|
78
|
+
|
|
79
|
+
<script setup lang="ts">
|
|
80
|
+
import { MessageRender, MessageRole, MessageStatus } from '@blueking/chat-x';
|
|
81
|
+
|
|
82
|
+
const message = {
|
|
83
|
+
id: 't3',
|
|
84
|
+
messageId: 't3',
|
|
85
|
+
role: MessageRole.Tool,
|
|
86
|
+
status: MessageStatus.Error,
|
|
87
|
+
toolCallId: 'call_3',
|
|
88
|
+
duration: 5000,
|
|
89
|
+
content: '',
|
|
90
|
+
error: 'Connection timeout: database server is unreachable (timeout: 5000ms)',
|
|
91
|
+
};
|
|
92
|
+
</script>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## DescPanel 内容渲染规则
|
|
96
|
+
|
|
97
|
+
`DescPanel` 内部对 `desc`(即 `content || (typeof error === 'string' ? error : undefined)`)进行 `JSON.parse`,然后根据解析结果类型决定渲染方式:
|
|
98
|
+
|
|
99
|
+
| `desc` 内容 | `JSON.parse` 结果 | 渲染方式 |
|
|
100
|
+
| --------------------------- | ------------------------------- | ----------------------------------- |
|
|
101
|
+
| 合法 JSON 对象 `{}` | `object`(非 null) | **key-value 列表**,键为字段名 |
|
|
102
|
+
| 合法 JSON 数组 `[]` | `array`(也是 `object`) | **index-keyed 列表**,键为 0、1、2… |
|
|
103
|
+
| 合法 JSON 基本类型 | `number` / `string` / `boolean` | 纯文本 |
|
|
104
|
+
| `"null"` 字符串 | `null`(`typeof 'object'`) | 空内容区(v-for 遍历 null 无输出) |
|
|
105
|
+
| 解析失败(非法 JSON) | 捕获异常,返回原字符串 | 纯文本 |
|
|
106
|
+
| `content` 和 `error` 均为空 | `''` → 解析失败 | 空内容区 |
|
|
107
|
+
|
|
108
|
+
> **注意**:JSON 数组 `typeof [] === 'object'`,会以 `0:`、`1:`、`2:` 为键渲染为列表,而非整段纯文本。
|
|
109
|
+
|
|
110
|
+
**嵌套对象 / 数组值**:`DescPanel` 用 `JSON.stringify(value)` 转成字符串后交给 `HighlightKeyword`,**不再**使用 overflow-tips。
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// key-value 列表
|
|
114
|
+
const jsonObject = '{"city":"北京","temperature":22}';
|
|
115
|
+
|
|
116
|
+
// index-keyed 列表(0: item1, 1: item2)
|
|
117
|
+
const jsonArray = '["item1","item2","item3"]';
|
|
118
|
+
|
|
119
|
+
// 嵌套值 stringify 展示
|
|
120
|
+
const nested = '{"result":"success","data":{"city":"北京","meta":{"humidity":45}}}';
|
|
121
|
+
|
|
122
|
+
// 标量 / 非法 JSON → 纯文本
|
|
123
|
+
const jsonNumber = '42';
|
|
124
|
+
const plainText = '查询成功,共返回 10 条记录。';
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**嵌套 JSON 渲染效果**
|
|
128
|
+
|
|
129
|
+
## 与 ToolcallRender 的关系
|
|
130
|
+
|
|
131
|
+
`ToolcallRender` 在详情面板展开时,若 `toolCall.toolMessage` 有值,会在底部内联渲染 `ToolMessage`:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// toolcall-render.vue 内部逻辑(简化)
|
|
135
|
+
// <ToolMessage v-if="toolCall?.toolMessage" v-bind="toolCall.toolMessage" />
|
|
136
|
+
|
|
137
|
+
const toolCall = {
|
|
138
|
+
id: 'call_weather',
|
|
139
|
+
type: 'function',
|
|
140
|
+
function: {
|
|
141
|
+
name: 'get_weather',
|
|
142
|
+
arguments: '{"city":"北京"}',
|
|
143
|
+
description: '获取天气信息',
|
|
144
|
+
},
|
|
145
|
+
// 提供此字段后 ToolcallRender 会自动渲染 ToolMessage
|
|
146
|
+
toolMessage: {
|
|
147
|
+
id: '3',
|
|
148
|
+
messageId: '3',
|
|
149
|
+
role: 'tool',
|
|
150
|
+
content: '{"temperature":22,"weather":"晴"}',
|
|
151
|
+
status: 'complete',
|
|
152
|
+
duration: 850,
|
|
153
|
+
toolCallId: 'call_weather',
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## 与 MessageContainer 的关系
|
|
159
|
+
|
|
160
|
+
`MessageContainer` 通过 `toolCallId` 将 `role: 'tool'` 消息注入对应 AssistantMessage 的 `toolCall.toolMessage`,整个过程自动完成,无需手动引入 `ToolMessage`:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const messages = [
|
|
164
|
+
{
|
|
165
|
+
id: '1',
|
|
166
|
+
messageId: '1',
|
|
167
|
+
role: 'assistant',
|
|
168
|
+
content: '好的,我来查询天气。',
|
|
169
|
+
status: 'complete',
|
|
170
|
+
toolCalls: [
|
|
171
|
+
{
|
|
172
|
+
id: 'call_weather',
|
|
173
|
+
type: 'function',
|
|
174
|
+
function: { name: 'get_weather', arguments: '{"city":"北京"}' },
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: '2',
|
|
180
|
+
messageId: '2',
|
|
181
|
+
role: 'tool', // MessageContainer 自动处理
|
|
182
|
+
content: '{"temperature":22,"weather":"晴"}',
|
|
183
|
+
status: 'complete',
|
|
184
|
+
toolCallId: 'call_weather', // ← 通过此字段自动关联并注入上方 toolCall
|
|
185
|
+
duration: 850,
|
|
186
|
+
},
|
|
187
|
+
];
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## API
|
|
191
|
+
|
|
192
|
+
### Props
|
|
193
|
+
|
|
194
|
+
组件 Props 继承自 `Partial<ToolMessage>`,所有字段均可选:
|
|
195
|
+
|
|
196
|
+
| 属性名 | 类型 | 说明 |
|
|
197
|
+
| ---------- | ------------------ | ------------------------------------------------------------------------------- |
|
|
198
|
+
| content | `string` | 工具执行返回内容;与 `error` 通过 `\|\|` 决定优先级,**truthy 时 error 被忽略** |
|
|
199
|
+
| error | `boolean \| string` | 类型上可为 boolean;**仅当为 `string` 且 content 为 falsy 时**才会展示 |
|
|
200
|
+
| toolCallId | `string` | 关联的工具调用 ID(透传,组件内不使用) |
|
|
201
|
+
| duration | `number` | 工具执行耗时(毫秒,透传,组件内不使用) |
|
|
202
|
+
| status | `MessageStatus` | 消息状态(透传,组件内不使用) |
|
|
203
|
+
| id | `string \| number` | 消息 ID(透传,组件内不使用) |
|
|
204
|
+
| messageId | `string \| number` | 消息唯一标识(透传,组件内不使用) |
|
|
205
|
+
|
|
206
|
+
> **说明**:`ToolMessage` 组件内部只使用 `content` 和 `error` 两个字段(传给 `DescPanel`),其他字段均被透传接收但不使用,由父组件(`ToolcallRender` / `MessageContainer`)在外部管理。
|
|
207
|
+
|
|
208
|
+
## 类型定义
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
import { MessageRole, MessageStatus, type ToolMessage } from '@blueking/chat-x';
|
|
212
|
+
|
|
213
|
+
// ToolMessage 继承自 BaseMessage<MessageRole.Tool, string>
|
|
214
|
+
interface ToolMessage {
|
|
215
|
+
id: string | number;
|
|
216
|
+
messageId: string | number;
|
|
217
|
+
role: MessageRole.Tool; // 'tool'
|
|
218
|
+
status: MessageStatus;
|
|
219
|
+
content: string;
|
|
220
|
+
toolCallId: string; // 关联的 ToolCall.id
|
|
221
|
+
duration: number; // 工具执行耗时(毫秒)
|
|
222
|
+
error?: boolean | string; // 仅 string 会展示在 DescPanel
|
|
223
|
+
name?: string;
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Events / Slots / Expose
|
|
228
|
+
|
|
229
|
+
无。
|
|
230
|
+
|
|
231
|
+
## 关联组件
|
|
232
|
+
|
|
233
|
+
- [AssistantMessage](/components/message/assistant-message) — toolCall.toolMessage 内联场景
|
|
234
|
+
- [MessageRender](/components/message/message-render) — 独立 tool 消息派发
|
|
235
|
+
- [DescPanel](/components/rendering/desc-panel) — 返回内容面板
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
# ToolcallRender 工具调用渲染器
|
|
2
|
+
|
|
3
|
+
> 能力域:Agent 能力 | 导入:`import { ToolCallRender } from '@blueking/chat-x'` | since 1.0.0
|
|
4
|
+
|
|
5
|
+
渲染 assistant toolCalls,展示工具调用状态、参数和结果。 源码位置:src/components/tool-call/toolcall-render/toolcall-render.vue。
|
|
6
|
+
|
|
7
|
+
**关联**:desc-panel(详情区展示参数与描述文本)、highlight-keyword(标题与状态文案关键词高亮)、tool-message(详情底部可内联工具返回消息)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# ToolcallRender 工具调用渲染器
|
|
12
|
+
## 源码事实
|
|
13
|
+
|
|
14
|
+
- **源码位置**:`src/components/tool-call/toolcall-render/toolcall-render.vue`
|
|
15
|
+
- **能力域**:Agent 能力
|
|
16
|
+
- **能力说明**:渲染 assistant toolCalls,展示工具调用状态、参数和结果。
|
|
17
|
+
|
|
18
|
+
> **能力域**:Agent 能力
|
|
19
|
+
|
|
20
|
+
展示 AI 调用外部工具 / MCP / Skill 过程与结果的渲染组件。由**单行可折叠头部**和**详情面板**组成:头部是一段弱化的灰色文本(`#979ba5`),按调用类型给出前缀,进行中用文字渐变闪动表示、结束后在工具名右侧补一段状态与耗时;详情面板默认折叠。
|
|
21
|
+
|
|
22
|
+
## 组件结构
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
.ai-toolcall-render(font-size: 12px,line-height: 20px)
|
|
26
|
+
├── .ai-toolcall-render-header(单行,整行可点击切换折叠;class="is-expanded" 表示已展开)
|
|
27
|
+
│ ├── ToolCallIcon(.ai-toolcall-icon,16×16px)
|
|
28
|
+
│ ├── .toolcall-header-text(内联文本块,溢出截断 + overflow-tips)
|
|
29
|
+
│ │ ├── .toolcall-header-title(前缀 + HighlightKeyword(工具名))
|
|
30
|
+
│ │ │ └── .is-loading(进行中,渐变光带闪动)
|
|
31
|
+
│ │ └── .toolcall-header-status(v-if 有状态词;括号与耗时为弱显示)
|
|
32
|
+
│ │ └── .toolcall-header-result(.is-success #2caf5e / .is-error #ea3636)
|
|
33
|
+
│ └── ChevronRightIcon(.ai-chevron-right-icon,10×10px;v-if 非进行中,展开时 rotate(90deg))
|
|
34
|
+
│
|
|
35
|
+
└── .ai-toolcall-render-content(v-show,默认折叠,子项 gap: 8px)
|
|
36
|
+
├── DescPanel(title="描述",desc=function.description)← 始终渲染
|
|
37
|
+
├── DescPanel(title="参数",desc=function.arguments)← 始终渲染
|
|
38
|
+
└── ToolMessage(v-if="toolCall?.toolMessage")← 有结果时渲染
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
> **头部悬停/展开反馈**:头部默认 `#979ba5`;`:hover` 或 `.is-expanded` 时,`ToolCallIcon` 与非闪动态的工具名变为 `#313238`,展开态的箭头同样变为 `#313238`。头部不再有背景色与边框(旧版的 `$toolcallStatusMap` 状态底色已随重构移除)。
|
|
42
|
+
|
|
43
|
+
## 基础用法
|
|
44
|
+
|
|
45
|
+
```vue
|
|
46
|
+
<template>
|
|
47
|
+
<ToolcallRender
|
|
48
|
+
:tool-call="toolCall"
|
|
49
|
+
:status="MessageStatus.Complete"
|
|
50
|
+
/>
|
|
51
|
+
</template>
|
|
52
|
+
|
|
53
|
+
<script setup lang="ts">
|
|
54
|
+
import { ToolcallRender, MessageStatus, MessageContentType, type ToolCall } from '@blueking/chat-x';
|
|
55
|
+
|
|
56
|
+
const toolCall: ToolCall = {
|
|
57
|
+
id: 'call_1',
|
|
58
|
+
type: MessageContentType.Function,
|
|
59
|
+
function: {
|
|
60
|
+
name: 'get_weather',
|
|
61
|
+
arguments: JSON.stringify({ city: '北京', unit: 'celsius' }),
|
|
62
|
+
description: '获取指定城市的实时天气信息',
|
|
63
|
+
},
|
|
64
|
+
toolMessage: {
|
|
65
|
+
content: JSON.stringify({ city: '北京', temperature: 22, weather: '晴' }),
|
|
66
|
+
status: 'complete',
|
|
67
|
+
duration: 1200,
|
|
68
|
+
toolCallId: 'call_1',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
</script>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**渲染效果**
|
|
75
|
+
|
|
76
|
+
## 调用状态
|
|
77
|
+
|
|
78
|
+
组件内部把 `status` 归一为**成功 / 失败 / 进行中**三态,不再逐个 status 匹配底色:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
isSuccess = [complete, completed, success].includes(status);
|
|
82
|
+
isError = status === 'error' || !!toolCall?.toolMessage?.error; // toolMessage.error 可独立判定失败
|
|
83
|
+
isPending = !isSuccess && !isError; // 其余(含 pending / streaming / stop / undefined)统一视为进行中
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
| 归一状态 | 命中条件 | 头部渲染 |
|
|
87
|
+
| -------- | ---------------------------------------------------- | -------------------------------------------------------------- |
|
|
88
|
+
| 进行中 | 非成功且非失败(含未传 `status`) | 前缀替换为「正在调用」(Skill 为「正在读取」),标题带 `is-loading` 闪动,无状态段、无箭头 |
|
|
89
|
+
| 成功 | `complete` / `completed` / `success` | 状态段 `( 成功 )`,状态词 `#2caf5e` |
|
|
90
|
+
| 失败 | `status === 'error'` **或** `toolMessage.error` 为真 | 状态段 `( 失败 )`,状态词 `#ea3636` |
|
|
91
|
+
|
|
92
|
+
关于状态段的三个细节:
|
|
93
|
+
|
|
94
|
+
- **只有状态词着色**:`.toolcall-header-result` 只包住「成功 / 失败」,括号与耗时留在 `.toolcall-header-status` 内保持弱显示
|
|
95
|
+
- **括号写法**:头部渲染用半角括号并在两侧补 ` ` 撑开间距;`overflow-tips` 气泡里的纯文本用全角括号,形如 `调用工具 search(成功,耗时:1.2s)`
|
|
96
|
+
- **失败优先**:`toolMessage.error` 有值时即便 `status` 是成功态也判为失败
|
|
97
|
+
|
|
98
|
+
进行中的「文字 loading」由 CSS 实现:`.toolcall-header-title.is-loading` 用 `linear-gradient` + `background-clip: text` 让一条光带以 `1.8s linear infinite` 循环扫过文字;`prefers-reduced-motion: reduce` 下自动关闭动画。
|
|
99
|
+
|
|
100
|
+
**三种状态对比**
|
|
101
|
+
|
|
102
|
+
## 调用类型前缀
|
|
103
|
+
|
|
104
|
+
非进行中态的前缀由 `function.type` 决定;进行中态工具 / MCP 显示「正在调用」,Skill 显示「正在读取」:
|
|
105
|
+
|
|
106
|
+
| `function.type` | 前缀 | 说明 |
|
|
107
|
+
| ------------------------ | ----------- | ---------------------------------------- |
|
|
108
|
+
| `'function'` / 不传 | 调用工具 | 普通函数调用 |
|
|
109
|
+
| `'mcp'` | 调用 MCP | MCP 调用,通常同时带 `mcpName` |
|
|
110
|
+
| `'skill'` | 读取 Skill | Skill 读取 |
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const callType = fn?.type ?? (fn?.mcpName ? 'mcp' : 'function');
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
- **旧数据兼容**:未下发 `type` 时,有 `mcpName` 仍按 MCP 判定,历史消息展示不变
|
|
117
|
+
- **`type` 优先**:显式 `type: 'function'` 不会被 `mcpName` 覆盖回 MCP,但标题仍是 `{mcpName} / {name}`
|
|
118
|
+
|
|
119
|
+
**三种前缀对比**
|
|
120
|
+
|
|
121
|
+
## 工具标题(toolTitle)
|
|
122
|
+
|
|
123
|
+
头部标题的计算规则:
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
有 mcpName → "{mcpName} / {function.name}"
|
|
127
|
+
无 mcpName → function.name || toolCall.id
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`function.name` 为空字符串时,自动回退到 `toolCall.id` 作为标题。前缀、标题与状态段同处一个内联文本块 `.toolcall-header-text`,整体超出容器宽度时统一截断,并由 overflow-tips 展示完整文案。
|
|
131
|
+
|
|
132
|
+
## 折叠/展开详情面板
|
|
133
|
+
|
|
134
|
+
详情面板**默认折叠**,点击**整行头部**切换折叠状态(旧版仅箭头可点)。折叠状态由 `collapsed`(默认 `true`)和 `superCollapsed` 两个 `shallowRef` 管理,不暴露为 prop/v-model。
|
|
135
|
+
|
|
136
|
+
| 折叠状态 | 箭头 | 头部 class | 详情面板 |
|
|
137
|
+
| ------------ | ----------------------------------- | ------------- | ------------- |
|
|
138
|
+
| 折叠(默认) | `ChevronRightIcon` 朝右 | — | `v-show` 隐藏 |
|
|
139
|
+
| 展开 | `rotate(90deg)` 朝下,颜色 `#313238` | `is-expanded` | 可见 |
|
|
140
|
+
|
|
141
|
+
> **进行中不渲染箭头**:`isPending` 为真时箭头隐藏(此时通常还没有结果可看),但头部点击仍会切换详情面板。
|
|
142
|
+
>
|
|
143
|
+
> **关键词联动**:接入 `useKeywordMatch` 后,若上层正在搜索关键词且用户未手动点过头部(`superCollapsed` 为 `null`),面板会按「命中关键词则展开」自动切换;用户一旦点击,`superCollapsed` 接管并固定为手动选择的状态。
|
|
144
|
+
|
|
145
|
+
详情面板由三块区域构成:
|
|
146
|
+
|
|
147
|
+
| 区块 | 数据来源 | 渲染方式 | 渲染条件 |
|
|
148
|
+
| -------- | ---------------------- | ---------------------------------------------------- | ---------------------------- |
|
|
149
|
+
| 描述 | `function.description` | `DescPanel`(纯文本 / key-value 列表) | **始终渲染**,无值则显示空白 |
|
|
150
|
+
| 参数 | `function.arguments` | `DescPanel`(JSON 对象 → key-value;其他 → 纯文本) | **始终渲染**,无值则显示空白 |
|
|
151
|
+
| 工具结果 | `toolCall.toolMessage` | `ToolMessage` 组件(`v-if="toolCall?.toolMessage"`) | 仅当 `toolMessage` 存在时 |
|
|
152
|
+
|
|
153
|
+
## 调用耗时
|
|
154
|
+
|
|
155
|
+
耗时来源优先级(`||` 运算符):
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
durationDisplay = formatDuration(props.duration || toolCall?.toolMessage?.duration);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
| 场景 | 耗时来源 |
|
|
162
|
+
| ------------------------------------------ | --------------------------- |
|
|
163
|
+
| 传入 `duration` prop | 使用 prop 值 |
|
|
164
|
+
| 未传 `duration`,toolMessage 有 `duration` | 使用 `toolMessage.duration` |
|
|
165
|
+
| 两者均无 | 不显示耗时 |
|
|
166
|
+
|
|
167
|
+
耗时不再单独占一个元素,而是拼进状态段:有耗时时渲染为 `( 成功,耗时:1.2s )`,无耗时时只保留 `( 成功 )`。进行中态没有状态段,因此也不展示耗时。
|
|
168
|
+
|
|
169
|
+
```vue
|
|
170
|
+
<!-- 方式一:直接传 duration prop(优先) -->
|
|
171
|
+
<ToolcallRender :tool-call="toolCall" status="complete" :duration="1200" />
|
|
172
|
+
|
|
173
|
+
<!-- 方式二(推荐):duration 放在 toolMessage 中,无需额外 prop -->
|
|
174
|
+
<ToolcallRender :tool-call="toolCallWithDuration" status="complete" />
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// 推荐:duration 统一由 toolMessage 管理
|
|
179
|
+
const toolCallWithDuration: ToolCall = {
|
|
180
|
+
id: 'call_1',
|
|
181
|
+
type: 'function',
|
|
182
|
+
function: { name: 'get_weather', arguments: '{"city":"北京"}' },
|
|
183
|
+
toolMessage: {
|
|
184
|
+
content: '{"temperature":22}',
|
|
185
|
+
status: 'complete',
|
|
186
|
+
duration: 1200, // ← 组件自动读取,无需额外传 duration prop
|
|
187
|
+
toolCallId: 'call_1',
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## MCP 调用
|
|
193
|
+
|
|
194
|
+
`function.type` 为 `'mcp'`(或旧数据仅有 `mcpName`)时,前缀为「调用 MCP」,标题格式变为 `{mcpName} / {functionName}`:
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
const mcpToolCall: ToolCall = {
|
|
198
|
+
id: 'call_mcp_1',
|
|
199
|
+
type: 'function',
|
|
200
|
+
function: {
|
|
201
|
+
type: 'mcp', // ← 前缀显示「调用 MCP」;缺省时有 mcpName 也会兼容判定为 MCP
|
|
202
|
+
name: 'query_table',
|
|
203
|
+
arguments: JSON.stringify({ table: 'events', limit: 50 }),
|
|
204
|
+
description: '通过 MCP 协议查询蓝鲸数据平台中的事件数据',
|
|
205
|
+
mcpName: 'bk-data-server',
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
// 头部显示:调用 MCP bk-data-server / query_table(成功,耗时:830ms)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 调用失败
|
|
212
|
+
|
|
213
|
+
`toolMessage.error` 有值且 `content` 为空时,`ToolMessage` 内部展示错误信息(由 `content || error` 决定)。头部状态词是否红色由 `status === 'error'` **或** `toolMessage.error` 任一命中决定,因此下例即使不传 `status` 也会显示失败:
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
const failedToolCall: ToolCall = {
|
|
217
|
+
id: 'call_1',
|
|
218
|
+
type: 'function',
|
|
219
|
+
function: {
|
|
220
|
+
name: 'execute_sql',
|
|
221
|
+
arguments: JSON.stringify({ sql: 'SELECT * FROM users' }),
|
|
222
|
+
description: '执行数据库查询',
|
|
223
|
+
},
|
|
224
|
+
toolMessage: {
|
|
225
|
+
content: '', // 空 content → ToolMessage 显示 error
|
|
226
|
+
error: 'Connection timeout: database is unreachable (5000ms)',
|
|
227
|
+
status: 'error',
|
|
228
|
+
duration: 5000,
|
|
229
|
+
toolCallId: 'call_1',
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**渲染效果**
|
|
235
|
+
|
|
236
|
+
## 无 description 场景
|
|
237
|
+
|
|
238
|
+
`function.description` 为可选字段,缺失时"描述"区块仍会渲染(`DescPanel` 始终存在),但内容为空白占位:
|
|
239
|
+
|
|
240
|
+
## 与 AssistantMessage 配合
|
|
241
|
+
|
|
242
|
+
`ToolcallRender` 通常不需要单独使用,将 `toolCalls` 传给 `AssistantMessage`,会自动为每个工具调用渲染 `ToolcallRender`:
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
const assistantMessage = {
|
|
246
|
+
id: '1',
|
|
247
|
+
role: 'assistant',
|
|
248
|
+
content: '好的,我来帮你查询天气。',
|
|
249
|
+
status: 'complete',
|
|
250
|
+
toolCalls: [
|
|
251
|
+
{
|
|
252
|
+
id: 'call_1',
|
|
253
|
+
type: 'function',
|
|
254
|
+
function: {
|
|
255
|
+
name: 'get_weather',
|
|
256
|
+
arguments: '{"city":"北京"}',
|
|
257
|
+
description: '获取天气信息',
|
|
258
|
+
},
|
|
259
|
+
toolMessage: {
|
|
260
|
+
content: '{"temperature":22,"weather":"晴"}',
|
|
261
|
+
status: 'complete',
|
|
262
|
+
duration: 850,
|
|
263
|
+
toolCallId: 'call_1',
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
};
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
需要自定义遍历渲染时:
|
|
271
|
+
|
|
272
|
+
```vue
|
|
273
|
+
<template>
|
|
274
|
+
<ToolcallRender
|
|
275
|
+
v-for="toolCall in assistantMessage.toolCalls"
|
|
276
|
+
:key="toolCall.id"
|
|
277
|
+
:tool-call="toolCall"
|
|
278
|
+
:status="
|
|
279
|
+
!toolCall.toolMessage
|
|
280
|
+
? MessageStatus.Pending
|
|
281
|
+
: toolCall.toolMessage.error
|
|
282
|
+
? MessageStatus.Error
|
|
283
|
+
: (toolCall.toolMessage.status ?? assistantMessage.status)
|
|
284
|
+
"
|
|
285
|
+
/>
|
|
286
|
+
</template>
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
> **多条工具调用**:`AssistantMessage` 把 `toolCalls` 包在 `.ai-assistant-message-toolcalls` 容器内,条目之间固定 `8px` 间距,不受消息区 `12px` 间距影响。
|
|
290
|
+
|
|
291
|
+
## API
|
|
292
|
+
|
|
293
|
+
### Props
|
|
294
|
+
|
|
295
|
+
| 属性名 | 类型 | 默认值 | 说明 |
|
|
296
|
+
| -------- | --------------- | ------ | ----------------------------------------------------------------------------------- |
|
|
297
|
+
| toolCall | `ToolCall` | — | 工具调用信息对象 |
|
|
298
|
+
| status | `MessageStatus` | — | 调用状态,归一为成功 / 失败 / 进行中三态;未传时按进行中渲染(「正在调用」+ 闪动) |
|
|
299
|
+
| duration | `number` | — | 调用耗时(毫秒),优先于 `toolCall.toolMessage?.duration`;均无时状态段不展示耗时 |
|
|
300
|
+
|
|
301
|
+
## 类型定义
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
import {
|
|
305
|
+
MessageStatus,
|
|
306
|
+
MessageContentType,
|
|
307
|
+
type ToolCall,
|
|
308
|
+
type FunctionCall,
|
|
309
|
+
type FunctionCallType,
|
|
310
|
+
type ToolMessage,
|
|
311
|
+
} from '@blueking/chat-x';
|
|
312
|
+
|
|
313
|
+
// ToolCall —— 工具调用对象
|
|
314
|
+
type ToolCall = {
|
|
315
|
+
id: string;
|
|
316
|
+
type: 'function'; // MessageContentType.Function
|
|
317
|
+
function: FunctionCall;
|
|
318
|
+
toolMessage?: Partial<ToolMessage>; // 有值时在详情面板底部内联渲染 ToolMessage
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// FunctionCallType —— 调用类型
|
|
322
|
+
type FunctionCallType = 'function' | 'mcp' | 'skill';
|
|
323
|
+
|
|
324
|
+
// FunctionCall —— 函数调用描述
|
|
325
|
+
type FunctionCall = {
|
|
326
|
+
name: string; // 函数名;为空时标题 fallback 为 toolCall.id
|
|
327
|
+
arguments: string; // 调用参数(通常为 JSON 字符串)
|
|
328
|
+
description?: string; // 工具描述;为空时"描述"区块保留但内容为空白
|
|
329
|
+
mcpName?: string; // MCP 服务名;有值时标题格式变为 "{mcpName} / {name}",缺省 type 时兼容判定为 MCP
|
|
330
|
+
type?: FunctionCallType; // 调用类型,决定头部前缀;不传按 mcpName 兼容判定
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// ToolMessage —— 工具返回消息
|
|
334
|
+
interface ToolMessage {
|
|
335
|
+
role: 'tool';
|
|
336
|
+
content: string; // 返回内容(通常为 JSON 字符串)
|
|
337
|
+
status: MessageStatus;
|
|
338
|
+
duration: number; // 调用耗时(毫秒),被 ToolcallRender 自动读取
|
|
339
|
+
error?: string; // 错误信息(仅当 content 为空时由 ToolMessage 展示)
|
|
340
|
+
toolCallId: string; // 对应 ToolCall.id
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## 关联组件
|
|
345
|
+
|
|
346
|
+
- [DescPanel](/components/rendering/desc-panel) — 描述与参数面板
|
|
347
|
+
- [HighlightKeyword](/components/helper/highlight-keyword) — 标题高亮
|
|
348
|
+
- [ToolMessage](/components/message/tool-message) — 内联工具返回
|