@blueking/chat-x 0.0.50 → 0.0.51-beta.2

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.
Files changed (147) hide show
  1. package/dist/ag-ui/types/contents.d.ts +2 -0
  2. package/dist/ag-ui/types/messages.d.ts +5 -0
  3. package/dist/common/constants.d.ts +1 -1
  4. package/dist/components/ai-buttons/file-upload-btn/file-upload-btn.vue.d.ts +0 -2
  5. package/dist/components/chat-content/file-content/file-content.vue.d.ts +5 -2
  6. package/dist/components/chat-content/file-content/upload-file-item.vue.d.ts +12 -0
  7. package/dist/components/chat-content/file-content/upload-image-item.vue.d.ts +21 -0
  8. package/dist/components/chat-input/ai-slash-editor/ai-slash-editor.vue.d.ts +1 -1
  9. package/dist/components/chat-input/build-default-placeholder.d.ts +7 -0
  10. package/dist/components/chat-input/chat-input.vue.d.ts +1 -1
  11. package/dist/components/chat-message/message-container/message-container.vue.d.ts +1 -0
  12. package/dist/components/chat-message/message-render/message-render.vue.d.ts +2 -0
  13. package/dist/components/chat-message/user-message/user-message.vue.d.ts +3 -1
  14. package/dist/components/index.d.ts +2 -1
  15. package/dist/components/message-tools/message-time/format-message-time.d.ts +8 -0
  16. package/dist/components/message-tools/message-time/message-time.vue.d.ts +8 -0
  17. package/dist/components/message-tools/message-tools.vue.d.ts +11 -1
  18. package/dist/composables/use-custom-tab.d.ts +5 -3
  19. package/dist/composables/use-global-config.d.ts +3 -0
  20. package/dist/composables/use-message-group.d.ts +150 -72
  21. package/dist/icons/execution.d.ts +6 -0
  22. package/dist/icons/tools.d.ts +3 -0
  23. package/dist/index.css +1 -1
  24. package/dist/index.js +3124 -2837
  25. package/dist/index.js.map +1 -1
  26. package/dist/lang/lang.d.ts +8 -7
  27. package/dist/mcp/generated/docs/ai-slash-input.md +2 -0
  28. package/dist/mcp/generated/docs/assistant-message.md +9 -7
  29. package/dist/mcp/generated/docs/chat-container.md +38 -32
  30. package/dist/mcp/generated/docs/chat-input.md +18 -12
  31. package/dist/mcp/generated/docs/cite-content.md +3 -3
  32. package/dist/mcp/generated/docs/desc-panel.md +32 -10
  33. package/dist/mcp/generated/docs/execution-summary.md +3 -3
  34. package/dist/mcp/generated/docs/file-artifact-panel.md +6 -4
  35. package/dist/mcp/generated/docs/file-content.md +89 -73
  36. package/dist/mcp/generated/docs/file-upload-btn.md +16 -18
  37. package/dist/mcp/generated/docs/message-container.md +3 -0
  38. package/dist/mcp/generated/docs/message-render.md +2 -1
  39. package/dist/mcp/generated/docs/message-time.md +180 -0
  40. package/dist/mcp/generated/docs/message-tools.md +47 -12
  41. package/dist/mcp/generated/docs/messages.md +9 -0
  42. package/dist/mcp/generated/docs/toolcall-render.md +82 -43
  43. package/dist/mcp/generated/docs/use-artifact-preview.md +19 -17
  44. package/dist/mcp/generated/docs/use-custom-tab.md +12 -8
  45. package/dist/mcp/generated/docs/use-global-config.md +15 -5
  46. package/dist/mcp/generated/docs/user-message.md +9 -0
  47. package/dist/mcp/generated/docs/user-question-card.md +2 -0
  48. package/dist/mcp/generated/index.json +46 -6
  49. package/dist/types/input.d.ts +6 -0
  50. package/dist/utils/file.d.ts +7 -1
  51. package/dist/utils/index.d.ts +2 -0
  52. package/dist/utils/merge-tools-by-id.d.ts +6 -0
  53. package/dist/utils/upload-file.d.ts +35 -0
  54. package/package.json +3 -2
  55. package/skills/blueking-chat-x/SKILL.md +139 -0
  56. package/skills/blueking-chat-x/references/_index.md +131 -0
  57. package/skills/blueking-chat-x/references/components/activity-layout.md +134 -0
  58. package/skills/blueking-chat-x/references/components/activity-message.md +486 -0
  59. package/skills/blueking-chat-x/references/components/ai-image.md +230 -0
  60. package/skills/blueking-chat-x/references/components/ai-loading.md +131 -0
  61. package/skills/blueking-chat-x/references/components/ai-prompt-list.md +44 -0
  62. package/skills/blueking-chat-x/references/components/ai-selection.md +439 -0
  63. package/skills/blueking-chat-x/references/components/ai-skill-list.md +73 -0
  64. package/skills/blueking-chat-x/references/components/ai-slash-editor.md +43 -0
  65. package/skills/blueking-chat-x/references/components/ai-slash-input.md +56 -0
  66. package/skills/blueking-chat-x/references/components/ai-slash-menu.md +42 -0
  67. package/skills/blueking-chat-x/references/components/animation-text.md +202 -0
  68. package/skills/blueking-chat-x/references/components/assistant-message.md +498 -0
  69. package/skills/blueking-chat-x/references/components/chat-container.md +869 -0
  70. package/skills/blueking-chat-x/references/components/chat-input.md +769 -0
  71. package/skills/blueking-chat-x/references/components/cite-content.md +142 -0
  72. package/skills/blueking-chat-x/references/components/code-content.md +211 -0
  73. package/skills/blueking-chat-x/references/components/common-error-content.md +73 -0
  74. package/skills/blueking-chat-x/references/components/content-render.md +233 -0
  75. package/skills/blueking-chat-x/references/components/delete-tool.md +191 -0
  76. package/skills/blueking-chat-x/references/components/desc-panel.md +162 -0
  77. package/skills/blueking-chat-x/references/components/detail-section.md +91 -0
  78. package/skills/blueking-chat-x/references/components/execution-summary.md +128 -0
  79. package/skills/blueking-chat-x/references/components/file-artifact-panel.md +289 -0
  80. package/skills/blueking-chat-x/references/components/file-content.md +319 -0
  81. package/skills/blueking-chat-x/references/components/file-icon.md +109 -0
  82. package/skills/blueking-chat-x/references/components/file-upload-btn.md +159 -0
  83. package/skills/blueking-chat-x/references/components/flow-agent-content.md +264 -0
  84. package/skills/blueking-chat-x/references/components/flow-agent-node-detail.md +236 -0
  85. package/skills/blueking-chat-x/references/components/highlight-keyword.md +146 -0
  86. package/skills/blueking-chat-x/references/components/image-content.md +182 -0
  87. package/skills/blueking-chat-x/references/components/image-preview-group.md +184 -0
  88. package/skills/blueking-chat-x/references/components/image-preview.md +226 -0
  89. package/skills/blueking-chat-x/references/components/info-message.md +144 -0
  90. package/skills/blueking-chat-x/references/components/input-attachment.md +49 -0
  91. package/skills/blueking-chat-x/references/components/input-info-alert.md +42 -0
  92. package/skills/blueking-chat-x/references/components/interrupt-message.md +212 -0
  93. package/skills/blueking-chat-x/references/components/key-value-content.md +128 -0
  94. package/skills/blueking-chat-x/references/components/knowledge-rag-content.md +122 -0
  95. package/skills/blueking-chat-x/references/components/latex-content.md +200 -0
  96. package/skills/blueking-chat-x/references/components/loading-message.md +192 -0
  97. package/skills/blueking-chat-x/references/components/markdown-content.md +232 -0
  98. package/skills/blueking-chat-x/references/components/mermaid-content.md +189 -0
  99. package/skills/blueking-chat-x/references/components/message-container.md +645 -0
  100. package/skills/blueking-chat-x/references/components/message-loading.md +118 -0
  101. package/skills/blueking-chat-x/references/components/message-render.md +327 -0
  102. package/skills/blueking-chat-x/references/components/message-time.md +177 -0
  103. package/skills/blueking-chat-x/references/components/message-tools.md +416 -0
  104. package/skills/blueking-chat-x/references/components/model-selector.md +155 -0
  105. package/skills/blueking-chat-x/references/components/preview-toolbar.md +42 -0
  106. package/skills/blueking-chat-x/references/components/questions-container.md +85 -0
  107. package/skills/blueking-chat-x/references/components/reasoning-message.md +232 -0
  108. package/skills/blueking-chat-x/references/components/reference-content.md +135 -0
  109. package/skills/blueking-chat-x/references/components/reference-doc-content.md +109 -0
  110. package/skills/blueking-chat-x/references/components/scroll-btn.md +159 -0
  111. package/skills/blueking-chat-x/references/components/selection-footer.md +78 -0
  112. package/skills/blueking-chat-x/references/components/selection-question.md +88 -0
  113. package/skills/blueking-chat-x/references/components/shortcut-btn.md +204 -0
  114. package/skills/blueking-chat-x/references/components/shortcut-btns.md +266 -0
  115. package/skills/blueking-chat-x/references/components/shortcut-render.md +424 -0
  116. package/skills/blueking-chat-x/references/components/simple-table.md +101 -0
  117. package/skills/blueking-chat-x/references/components/text-content.md +77 -0
  118. package/skills/blueking-chat-x/references/components/tool-approval-card.md +183 -0
  119. package/skills/blueking-chat-x/references/components/tool-btn.md +317 -0
  120. package/skills/blueking-chat-x/references/components/tool-message.md +235 -0
  121. package/skills/blueking-chat-x/references/components/toolcall-render.md +348 -0
  122. package/skills/blueking-chat-x/references/components/user-feedback.md +233 -0
  123. package/skills/blueking-chat-x/references/components/user-message.md +424 -0
  124. package/skills/blueking-chat-x/references/components/user-question-answered-card.md +104 -0
  125. package/skills/blueking-chat-x/references/components/user-question-card.md +231 -0
  126. package/skills/blueking-chat-x/references/components/user-question-choice.md +105 -0
  127. package/skills/blueking-chat-x/references/components/user-question-option.md +42 -0
  128. package/skills/blueking-chat-x/references/components/vnode-renderer.md +122 -0
  129. package/skills/blueking-chat-x/references/composables/use-animation-text.md +196 -0
  130. package/skills/blueking-chat-x/references/composables/use-artifact-preview.md +231 -0
  131. package/skills/blueking-chat-x/references/composables/use-clipboard.md +203 -0
  132. package/skills/blueking-chat-x/references/composables/use-command-selection.md +150 -0
  133. package/skills/blueking-chat-x/references/composables/use-container-scroll.md +57 -0
  134. package/skills/blueking-chat-x/references/composables/use-custom-tab.md +158 -0
  135. package/skills/blueking-chat-x/references/composables/use-flow-node-actions.md +157 -0
  136. package/skills/blueking-chat-x/references/composables/use-full-screen.md +112 -0
  137. package/skills/blueking-chat-x/references/composables/use-global-config.md +148 -0
  138. package/skills/blueking-chat-x/references/composables/use-menu-keydown.md +163 -0
  139. package/skills/blueking-chat-x/references/composables/use-message-group.md +247 -0
  140. package/skills/blueking-chat-x/references/composables/use-observer-visible-list.md +188 -0
  141. package/skills/blueking-chat-x/references/composables/use-parent-scrolling.md +46 -0
  142. package/skills/blueking-chat-x/references/theme/theme.md +431 -0
  143. package/skills/blueking-chat-x/references/types/constants.md +307 -0
  144. package/skills/blueking-chat-x/references/types/interrupt.md +379 -0
  145. package/skills/blueking-chat-x/references/types/messages.md +553 -0
  146. package/skills/blueking-chat-x/references/types/schema.md +91 -0
  147. package/skills/blueking-chat-x/scripts/generate-references.mjs +314 -0
@@ -0,0 +1,236 @@
1
+ # FlowAgentNodeDetail FlowAgent 节点详情
2
+
3
+ > 能力域:Agent 能力 | 导入:`import { FlowAgentNodeDetail } from '@blueking/chat-x'` | since 1.0.0
4
+
5
+ 展示 FlowAgent 节点输入、输出、异常、耗时等详情。 源码位置:src/components/chat-content/flow-agent-content/flow-agent-node-detail.vue。
6
+
7
+ **关联**:flow-agent-content(节点详情入口由 FlowAgentContent 挂载到自定义 Tab)、detail-section(详情页内部分段容器)、simple-table(展示输入参数、插件输出定义与结构化输出)、chat-container(应用层通过 onCustomTabChange 拉取节点详情并回填)
8
+
9
+ ---
10
+
11
+ # FlowAgentNodeDetail FlowAgent 节点详情
12
+
13
+ > **能力域**:Agent 能力
14
+
15
+ `FlowAgentNodeDetail` 用于展示 FlowAgent 单个节点的配置与输出详情。它通常被 `FlowAgentContent` 通过自定义 Tab 挂载到侧栏,应用层再根据 `messageUid`、`task_id`、`node_id` 拉取真实节点详情并回填到 `data`。
16
+
17
+ 组件自身只负责详情展示,不负责接口请求、Tab 生命周期或消息定位逻辑。
18
+
19
+ ## 源码事实
20
+
21
+ - **源码位置**:`src/components/chat-content/flow-agent-content/flow-agent-node-detail.vue`
22
+ - **能力说明**:展示 FlowAgent 节点输入、输出、异常、耗时等详情。
23
+
24
+ ## 核心能力
25
+
26
+ - **双 Tab 展示**:内置“节点配置”和“节点输出”两个页签,默认展示“节点配置”
27
+ - **配置详情**:展示流程模板、节点名称、步骤名称、是否可选、失败处理和超时控制
28
+ - **参数表格**:使用 `SimpleTable` 展示输入参数、插件输出定义和结构化输出
29
+ - **加载骨架屏**:`loading` 为 `true` 时展示标题和内容骨架,不渲染真实数据
30
+ - **定位插槽**:提供 `locateButton` 插槽,允许侧栏注入“在对话中定位”等操作按钮
31
+ - **值格式化**:`null` / `undefined` 显示为 `--`,对象值通过 `JSON.stringify` 转为字符串
32
+
33
+ ## 基础用法
34
+
35
+ ```vue
36
+ <template>
37
+ <FlowAgentNodeDetail
38
+ :data="nodeDetailData"
39
+ :loading="false"
40
+ node_id="n1"
41
+ node_name="采集主机指标"
42
+ :task_id="100"
43
+ task_name="主机巡检流程"
44
+ >
45
+ <template #locateButton>
46
+ <button type="button">定位</button>
47
+ </template>
48
+ </FlowAgentNodeDetail>
49
+ </template>
50
+
51
+ <script setup lang="ts">
52
+ import FlowAgentNodeDetail from '@blueking/chat-x/src/components/chat-content/flow-agent-content/flow-agent-node-detail.vue';
53
+ import type { NodeDetailData } from '@blueking/chat-x';
54
+
55
+ const nodeDetailData: Partial<NodeDetailData> = {
56
+ basic_info: {
57
+ node_name: '采集主机指标',
58
+ template_name: '主机巡检流程',
59
+ stage_name: '巡检准备',
60
+ optional: false,
61
+ skippable: true,
62
+ retryable: true,
63
+ error_ignorable: false,
64
+ auto_retry: { enable: true, interval: 30, times: 2 },
65
+ timeout_config: { enable: true, seconds: 300, action: 'forced_fail' },
66
+ },
67
+ inputs: {
68
+ bk_host_id: 10001,
69
+ collect_items: ['cpu', 'memory', 'disk'],
70
+ },
71
+ plugin_output: [
72
+ {
73
+ key: '${cpu_usage}',
74
+ name: 'CPU 使用率',
75
+ type: 'number',
76
+ schema: { description: '当前主机 CPU 使用率', enum: [], type: 'number' },
77
+ },
78
+ ],
79
+ outputs: [{ key: 'cpu_usage', preset: false, value: 23.5 }],
80
+ };
81
+ </script>
82
+ ```
83
+
84
+ **渲染效果**
85
+
86
+ ## 加载态
87
+
88
+ `loading` 为 `true` 时,组件展示骨架屏,标题中的节点名和内容区均不会读取 `data` 展示。
89
+
90
+ ## 空数据
91
+
92
+ 当输入参数、插件输出定义或结构化输出为空时,对应 `SimpleTable` 渲染 `--` 占位行。
93
+
94
+ ## Tab 内容
95
+
96
+ | Tab | 内容 |
97
+ | ---------- | ------------------------------------------------------------ |
98
+ | 节点配置 | 基础信息、失败处理、超时控制、输入参数、插件输出定义 |
99
+ | 节点输出 | 结构化输出,来自 `data.outputs` |
100
+
101
+ `activeTab` 是组件内部状态,不通过 prop 或 expose 暴露。
102
+
103
+ ## 字段展示规则
104
+
105
+ | 区域 | 数据来源 | 展示规则 |
106
+ | ------------ | -------------------------------- | --------------------------------------------- |
107
+ | 流程模板 | `data.basic_info.template_name` | 空值显示 `--` |
108
+ | 节点名称 | `data.basic_info.node_name` | 空值显示 `--` |
109
+ | 步骤名称 | `data.basic_info.stage_name` | 空值显示 `--` |
110
+ | 是否可选 | `data.basic_info.optional` | `true` 显示“是”,否则显示“否” |
111
+ | 失败处理 | `skippable` / `auto_retry.enable` | 支持“手动跳过”和“自动重试”;均无时显示 `--` |
112
+ | 超时控制 | `timeout_config` | 未启用时显示 `--`;`forced_fail` 显示“强制失败” |
113
+ | 输入参数 | `data.inputs` | 对象条目转为 `{ key, value }` 表格 |
114
+ | 插件输出定义 | `data.plugin_output` | 展示名称、变量说明和 KEY |
115
+ | 结构化输出 | `data.outputs` | 展示输出 key 与格式化后的 value |
116
+
117
+ ## 自定义 Tab 联动
118
+
119
+ `FlowAgentContent` 点击节点“详情”时,会将本组件挂载到自定义 Tab,并先传入 `loading: true` 和节点定位参数:
120
+
121
+ ```typescript
122
+ addCustomTab?.({
123
+ label: node.name,
124
+ name: `${task.task_id}|${node.id}|${node.name}`,
125
+ data: {
126
+ component: BkFlowNodeDetail,
127
+ messageUid: props.messageUid,
128
+ props: {
129
+ loading: true,
130
+ node_id: node.id,
131
+ node_name: node.name,
132
+ task_id: task.task_id,
133
+ task_name: task.task_name,
134
+ data: {},
135
+ },
136
+ },
137
+ });
138
+ ```
139
+
140
+ 应用层通常在 `ChatContainer` 的 `onCustomTabChange` 中读取这些参数,请求节点详情后返回新的 `props.data` 和 `props.loading`。
141
+
142
+ ## API
143
+
144
+ ### Props
145
+
146
+ | 属性名 | 类型 | 必填 | 默认值 | 说明 |
147
+ | --------- | -------------------------- | ---- | ------ | ---------------------------- |
148
+ | data | `Partial<NodeDetailData>` | 是 | — | 节点详情数据 |
149
+ | loading | `boolean` | 否 | — | 是否显示骨架屏 |
150
+ | node_id | `string` | 否 | — | 节点 ID,来自自定义 Tab 参数 |
151
+ | node_name | `string` | 否 | — | 节点名称 |
152
+ | task_id | `number` | 否 | — | 任务 ID |
153
+ | task_name | `string` | 否 | — | 任务名称 |
154
+
155
+ > Props 类型来自 `CustomBkFlowTabData['props'] & { data: Partial<NodeDetailData> }`。
156
+
157
+ ### Emits
158
+
159
+ - 无。
160
+
161
+ ### Slots
162
+
163
+ | 插槽名 | 说明 |
164
+ | ------------ | ---------------------------- |
165
+ | locateButton | 标题栏右侧操作区,如定位按钮 |
166
+
167
+ ### Expose
168
+
169
+ - 无。
170
+
171
+ ## 类型定义
172
+
173
+ ```typescript
174
+ export type CustomBkFlowTabData = CustomTabData<{
175
+ data?: Partial<NodeDetailData>;
176
+ loading?: boolean;
177
+ node_id?: string;
178
+ node_name?: string;
179
+ task_id?: number;
180
+ task_name?: string;
181
+ }>;
182
+
183
+ export interface NodeDetailData {
184
+ inputs: Record<string, unknown>;
185
+ node_id: string;
186
+ task_id: number;
187
+ basic_info: {
188
+ auto_retry: {
189
+ enable: boolean;
190
+ interval: number;
191
+ times: number;
192
+ };
193
+ error_ignorable: boolean;
194
+ node_name: string;
195
+ optional: boolean;
196
+ retryable: boolean;
197
+ skippable: boolean;
198
+ stage_name: string;
199
+ template_name: string;
200
+ timeout_config: {
201
+ action: string;
202
+ enable: boolean;
203
+ seconds: number;
204
+ };
205
+ };
206
+ outputs: Array<{
207
+ key: string;
208
+ preset: boolean;
209
+ value: unknown;
210
+ }>;
211
+ plugin_output: Array<{
212
+ key: string;
213
+ name: string;
214
+ schema: {
215
+ description: string;
216
+ enum: unknown[];
217
+ properties?: Record<string, unknown>;
218
+ type: string;
219
+ };
220
+ type: string;
221
+ }>;
222
+ }
223
+ ```
224
+
225
+ ## 使用建议
226
+
227
+ - 优先由 [FlowAgentContent](./flow-agent-content.md) 通过自定义 Tab 挂载,不建议业务组件手动拼装 Tab 生命周期。
228
+ - 接口请求与数据回填应放在应用层 `ChatContainer` 的 `onCustomTabChange` 链路中处理。
229
+ - `data` 可传 `Partial<NodeDetailData>`,但真实展示依赖 `basic_info`、`inputs`、`plugin_output`、`outputs` 等字段;缺字段时对应区域会降级为空表格或 `--`。
230
+
231
+ ## 关联组件
232
+
233
+ - [FlowAgentContent](./flow-agent-content.md) — 节点详情入口。
234
+ - [DetailSection](./detail-section.md) — 详情分段容器。
235
+ - [SimpleTable](./simple-table.md) — 详情表格。
236
+ - [ChatContainer](../setup/chat-container.md) — 自定义 Tab 数据回填入口。
@@ -0,0 +1,146 @@
1
+ # HighlightKeyword 关键词高亮
2
+
3
+ > 能力域:辅助能力 | 导入:`import { HighlightKeyword } from '@blueking/chat-x'` | since 1.0.0
4
+
5
+ 根据注入关键词高亮文本片段。 源码位置:src/components/highlight-keyword/highlight-keyword.ts。
6
+
7
+ **关联**:toolcall-render(工具调用标题与状态文案高亮)、desc-panel(工具详情键值与描述文本高亮)、execution-summary(执行摘要搜索过滤与列表高亮)
8
+
9
+ ---
10
+
11
+ # HighlightKeyword 关键词高亮
12
+ ## 源码事实
13
+
14
+ - **源码位置**:`src/components/highlight-keyword/highlight-keyword.ts`
15
+ - **能力域**:辅助能力
16
+ - **能力说明**:根据注入关键词高亮文本片段。
17
+
18
+ > **能力域**:辅助能力
19
+
20
+ 函数式组件,用于在文本中高亮匹配的搜索关键词。通过 `useKeywordInject` 从上层注入关键词,自动将匹配部分包裹在带高亮样式的 `<span>` 中。
21
+
22
+ 主要配合 `ExecutionSummary` 的搜索功能使用,实现搜索结果的视觉高亮。
23
+
24
+ ## 工作原理
25
+
26
+ ```
27
+ props.text + inject(keyword)
28
+
29
+ ├── keyword 为空 → 直接渲染原文本
30
+
31
+ └── keyword 非空
32
+ ├── 正则 split 文本为 parts[]
33
+ ├── parts.length === 1 → 无匹配,渲染原文本
34
+ └── parts.length > 1 → 匹配部分用 <span class="highlight"> 包裹
35
+ ```
36
+
37
+ 组件使用 `defineComponent` + `h()` 渲染函数实现,不依赖模板。
38
+
39
+ ## 基础用法
40
+
41
+ ```vue
42
+ <template>
43
+ <HighlightKeyword :text="text" />
44
+ </template>
45
+
46
+ <script setup lang="ts">
47
+ import { HighlightKeyword } from '@blueking/chat-x';
48
+
49
+ const text = '这是一段包含 Vue 3 Composition API 的示例文本';
50
+ </script>
51
+ ```
52
+
53
+ > **注意**:关键词通过 `useKeywordProvider` / `useKeywordInject`(`provide/inject`)注入,不通过 props 传入。上层需先调用 `useKeywordProvider()` 设置关键词。
54
+
55
+ **渲染效果**(在输入框中输入关键词,观察文本高亮变化)
56
+
57
+ ## 关键词高亮示例
58
+
59
+ 预设关键词为 `API`,文本中所有匹配部分会以高亮背景显示:
60
+
61
+ ## 与 ExecutionSummary 配合
62
+
63
+ `ExecutionSummary` 内部通过 `useKeywordProvider` 提供搜索关键词,后代组件中的 `HighlightKeyword` 自动响应:
64
+
65
+ ```
66
+ ExecutionSummary
67
+ ├── useKeywordProvider(keyword) ← Input 绑定
68
+ └── MessageRender
69
+ └── AssistantMessage
70
+ └── ToolcallRender
71
+ └── HighlightKeyword(:text) ← inject(keyword)
72
+ ```
73
+
74
+ ## 配套 Composables
75
+
76
+ ### useKeywordProvider
77
+
78
+ 在上层组件中创建关键词并 `provide`,后代组件通过 `useKeywordInject` 消费:
79
+
80
+ ```typescript
81
+ import { useKeywordProvider } from '@blueking/chat-x';
82
+
83
+ const { keyword } = useKeywordProvider();
84
+ keyword.value = '搜索词';
85
+ ```
86
+
87
+ ### useKeywordInject
88
+
89
+ 在后代组件中注入关键词,返回 `ComputedRef<string> | undefined`:
90
+
91
+ ```typescript
92
+ import { useKeywordInject } from '@blueking/chat-x';
93
+
94
+ const keyword = useKeywordInject();
95
+ console.log(keyword?.value); // 当前搜索关键词
96
+ ```
97
+
98
+ ### useKeywordMatch
99
+
100
+ 用于判断组件的可搜索文本是否与当前关键词匹配。内部调用 `useKeywordInject` 获取关键词,根据传入的文本提取函数判断是否命中:
101
+
102
+ ```typescript
103
+ import { useKeywordMatch } from '@blueking/chat-x';
104
+
105
+ const { keywordMatched } = useKeywordMatch(() => [props.title, props.description, props.content]);
106
+
107
+ // keywordMatched.value === true 表示命中搜索
108
+ // keywordMatched.value === false 表示未命中(可据此隐藏组件)
109
+ // keyword 为空时始终返回 true
110
+ ```
111
+
112
+ `useKeywordMatch` 的典型用途是在 `ExecutionSummary` 的搜索过滤中,让组件自行判断是否匹配搜索词,与 `HighlightKeyword` 配合实现搜索 + 高亮。
113
+
114
+ ## API
115
+
116
+ ### Props
117
+
118
+ | 属性名 | 类型 | 必填 | 说明 |
119
+ | ------ | -------- | ---- | ---------- |
120
+ | text | `string` | ✓ | 待高亮文本 |
121
+
122
+ ### 依赖注入
123
+
124
+ | 注入项 | 提供方 | 说明 |
125
+ | ------- | -------------------- | ---------------------- |
126
+ | keyword | `useKeywordProvider` | 搜索关键词,响应式更新 |
127
+
128
+ ### 配套 Composables
129
+
130
+ | 函数名 | 参数 | 返回值 | 说明 |
131
+ | -------------------- | ----------------------------------------------- | ------------------------------------------ | --------------------------------------------- |
132
+ | `useKeywordProvider` | — | `{ keyword: ShallowRef<string> }` | 创建并 `provide` 关键词,用于上层组件 |
133
+ | `useKeywordInject` | — | `ComputedRef<string> \| undefined` | 注入关键词,用于后代组件 |
134
+ | `useKeywordMatch` | `getSearchTexts: () => (string \| undefined)[]` | `{ keywordMatched: ComputedRef<boolean> }` | 判断组件文本是否匹配关键词,空关键词返回 true |
135
+
136
+ ### CSS 类名
137
+
138
+ | 类名 | 说明 |
139
+ | ----------------------- | ----------------------------------- |
140
+ | `.ai-highlight-keyword` | 匹配文本的高亮样式(背景色 + 圆角) |
141
+
142
+ ## 关联组件
143
+
144
+ - [ToolcallRender](/components/agent/toolcall-render) — 工具调用头部高亮
145
+ - [DescPanel](/components/rendering/desc-panel) — 详情面板键值高亮
146
+ - [ExecutionSummary](/components/agent/execution-summary) — 执行摘要搜索
@@ -0,0 +1,182 @@
1
+ # ImageContent 图片内容
2
+
3
+ > 能力域:媒体文件 | 导入:`import { ImageContent } from '@blueking/chat-x'` | since 1.0.0
4
+
5
+ 渲染 Markdown 图片 token。 源码位置:src/components/markdown-token/image-content/image-content.vue。
6
+
7
+ **关联**:markdown-content(解析图片 token 后挂载本组件)
8
+
9
+ ---
10
+
11
+ # ImageContent 图片渲染
12
+ ## 源码事实
13
+
14
+ - **源码位置**:`src/components/markdown-token/image-content/image-content.vue`
15
+ - **能力域**:媒体文件
16
+ - **能力说明**:渲染 Markdown 图片 token。
17
+
18
+ > **能力域**:媒体文件
19
+
20
+ Markdown Token 层的图片渲染基础组件,被 `MarkdownContent` 在解析到图片 token 时自动调用,通常无需手动引入。
21
+
22
+ 核心能力:**流式 URL 防闪烁**(debounce 稳定判断 + throttle 预加载)、**全局缓存**(模块级 `Set` 跨实例共享)、**三态渲染**(加载中 / 成功 / 失败)。
23
+
24
+ ## 组件结构
25
+
26
+ ```
27
+ span.ai-md-image-wrapper(inline-block,vertical-align: middle)
28
+ ├── [showLoading] span.md-image-loading(inline-flex,gap: 6px,padding: 4px 8px,bg: #f5f7fa)
29
+ │ ├── bkui-vue Loading(spin,mini,primary)
30
+ │ └── "图片加载中..."
31
+ ├── [showError] span.md-image-error(同上,color: #ea3636,bg: #fee)
32
+ │ ├── span.md-image-error-icon → ⚠️(font-size: 14px)
33
+ │ └── span.md-image-error-text → alt || "图片加载失败"
34
+ └── [else] img.md-image(max-width: 100%,height: auto,loading="lazy")
35
+ :src="src" :alt="alt"
36
+ ```
37
+
38
+ > **错误文本**:优先显示 `alt`,未传 `alt` 时才显示 "图片加载失败"。
39
+
40
+ ## 状态机
41
+
42
+ 组件内部维护三个 `shallowRef`:`isLoading`、`hasError`、`isUrlStable`,以及两个 computed 控制显示:
43
+
44
+ ```
45
+ showLoading 为 true 的条件(按优先级):
46
+ 1. isCached(全局缓存命中)→ false,直接显示图片
47
+ 2. !isValidUrl → true(URL 无效或正在输入中)
48
+ 3. isLoading → true(正在预加载)
49
+ 4. !isUrlStable && hasError → true(URL 仍在变化,忽略旧错误)
50
+
51
+ showError 为 true 的条件(需全部满足):
52
+ isUrlStable && hasError && !isLoading
53
+ ```
54
+
55
+ ### URL 有效性(isValidUrl)
56
+
57
+ ```
58
+ src 被判定为无效的情况(显示 Loading):
59
+ · 空字符串 / '#' / '#)'
60
+ · 以 '#' 或 '#)' 结尾(Markdown 语法补全占位符)
61
+ · 无协议且不是相对路径/带图片扩展名的路径
62
+ · https?:// 开头但域名中无 '.' 且不是 localhost
63
+
64
+ 合法 URL 格式:
65
+ · https?://、// → 协议 URL(域名需含 '.' 或为 localhost)
66
+ · data:、blob: → Data URL / Blob URL
67
+ · /path 或 ./path → 绝对/相对路径
68
+ · image.png、a.jpg?v=1 → 带图片扩展名的文件名
69
+ ```
70
+
71
+ ### 流式防抖与节流
72
+
73
+ | 机制 | 参数 | 作用 |
74
+ | --------------------------- | ------------------------- | ---------------------------------------------------------------- |
75
+ | `markUrlStable`(debounce) | 500ms | URL 停止变化 500ms 后置 `isUrlStable = true`,此后才允许显示错误 |
76
+ | `preloadImage`(throttle) | 100ms,leading + trailing | 限制 `new Image()` 预加载频率,流式输入时不会每个字符都发请求 |
77
+
78
+ ### 全局缓存
79
+
80
+ `loadedImageCache` 是**模块级 `Set<string>`**,所有 `ImageContent` 实例共享:
81
+
82
+ - 图片加载成功后 → `loadedImageCache.add(url)`
83
+ - 组件初始化时若命中缓存 → `isLoading = false`,`isUrlStable = true`,跳过所有预加载逻辑,直接渲染 `<img>`
84
+ - 页面刷新后缓存清空(仅内存缓存)
85
+
86
+ ## 基础用法
87
+
88
+ ```vue
89
+ <template>
90
+ <ImageContent
91
+ src="https://picsum.photos/seed/demo/400/200"
92
+ alt="示例图片"
93
+ />
94
+ </template>
95
+
96
+ <script setup lang="ts">
97
+ import { ImageContent } from '@blueking/chat-x';
98
+ </script>
99
+ ```
100
+
101
+ ## 加载失败
102
+
103
+ URL 稳定后(500ms 无变化)加载失败,显示 `⚠️ + alt文本`(无 alt 时显示"图片加载失败"):
104
+
105
+ ## Data URL
106
+
107
+ 支持 Base64 / SVG Data URL,不经过 `isValidUrl` 的网络检测,直接进入预加载:
108
+
109
+ ```vue
110
+ <template>
111
+ <ImageContent
112
+ src="data:image/svg+xml,..."
113
+ alt="内联 SVG"
114
+ />
115
+ </template>
116
+ ```
117
+
118
+ ## 流式输入防闪烁
119
+
120
+ 流式 Markdown 渲染时 URL 逐字符拼接,组件通过 debounce + throttle 避免频繁请求和闪烁:
121
+
122
+ ```vue
123
+ <template>
124
+ <button
125
+ @click="simulateStreaming"
126
+ :disabled="isStreaming"
127
+ >
128
+ {{ isStreaming ? '输入中...' : '模拟流式输入' }}
129
+ </button>
130
+ <ImageContent
131
+ :src="streamingUrl"
132
+ alt="流式图片"
133
+ />
134
+ </template>
135
+
136
+ <script setup lang="ts">
137
+ import { ref } from 'vue';
138
+ import { ImageContent } from '@blueking/chat-x';
139
+
140
+ const streamingUrl = ref('');
141
+ const isStreaming = ref(false);
142
+
143
+ const simulateStreaming = async () => {
144
+ const url = 'https://picsum.photos/seed/chat-x-stream/400/200';
145
+ streamingUrl.value = '';
146
+ isStreaming.value = true;
147
+ for (let i = 0; i <= url.length; i++) {
148
+ await new Promise(r => setTimeout(r, 60));
149
+ streamingUrl.value = url.slice(0, i);
150
+ }
151
+ isStreaming.value = false;
152
+ };
153
+ </script>
154
+ ```
155
+
156
+ **流式过程中的状态变化**:
157
+
158
+ ```
159
+ URL = '' → isValidUrl=false → showLoading=true(Loading)
160
+ URL = 'https://' → isValidUrl=false → showLoading=true(域名不完整)
161
+ URL = 'https://p…' → isValidUrl=false → showLoading=true(域名无 '.')
162
+ URL = 完整 URL → isValidUrl=true → throttle 触发 preloadImage
163
+ debounce 500ms → isUrlStable=true
164
+ onload → cache → showLoading=false → 显示图片
165
+ ```
166
+
167
+ ## API
168
+
169
+ ### Props
170
+
171
+ | 属性名 | 类型 | 必填 | 说明 |
172
+ | ------ | -------- | ---- | ---------------------------------------------------------------------------- |
173
+ | src | `string` | ✓ | 图片 URL,支持 https / http / // / data: / blob: / 相对路径 / 带扩展名文件名 |
174
+ | alt | `string` | — | 替代文本;加载失败时优先显示此文本,未传时显示"图片加载失败" |
175
+
176
+ ## 使用场景
177
+
178
+ `ImageContent` 由 `MarkdownContent` 在渲染 `image` token 时自动调用,通常不需要手动引入。如需在 Markdown 以外的场景渲染带流式防抖保护的图片,可单独使用。
179
+
180
+ ## 关联组件
181
+
182
+ - [MarkdownContent](/components/rendering/markdown-content) — 图片 token 渲染入口