rt-chat-messages 1.0.3 → 1.0.5

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
@@ -2,14 +2,21 @@
2
2
 
3
3
  AI 对话消息展示组件库,提供开箱即用的 Markdown 渲染、代码高亮、Mermaid 图表、多模态消息(语音/图片/文件)展示功能。
4
4
 
5
+ ## 预览
6
+
7
+ <p align="center">
8
+ <img src="http://rt-rongmeibao.oss-cn-beijing.aliyuncs.com/trade-platform-web/20260206/80b22313-e3ed-428a-82ac-8ac8dac30e6b.png" alt="消息列表预览" width="320" />
9
+ </p>
10
+
5
11
  ## 特性
6
12
 
7
13
  - 📦 **开箱即用**:封装了复杂的 Markdown 和流式消息渲染逻辑
8
14
  - 🎨 **零 UI 库依赖**:内置基础 UI 组件,不依赖 Element Plus 等庞大组件库
9
15
  - 📱 **响应式设计**:完美适配 PC 和移动端
10
16
  - 🌙 **深色模式**:内置深色模式支持
11
- - 🛠 **Mermaid & KaTeX**:内置图表和数学公式支持
12
- - 🤖 **Agent 支持**:内置 Agent 执行步骤展示
17
+ - 🛠 **Mermaid & KaTeX**:内置图表和数学公式支持
18
+ - 🤖 **Agent 支持**:内置 Agent 执行步骤展示
19
+ - 🧩 **A2UI 支持**:可渲染 A2UI v0.9 结构化 UI,并透出用户交互事件
13
20
 
14
21
  ## 安装
15
22
 
@@ -36,11 +43,12 @@ import "rt-chat-messages/style.css";
36
43
  :messages="messages"
37
44
  :is-streaming="isStreaming"
38
45
  :is-typing="isWaiting"
39
- app-name="荣小宝"
40
- @copy="handleCopy"
41
- />
42
- </div>
43
- </template>
46
+ app-name="荣小宝"
47
+ @copy="handleCopy"
48
+ @a2ui-action="handleA2UIAction"
49
+ />
50
+ </div>
51
+ </template>
44
52
 
45
53
  <script setup>
46
54
  import { ChatMessageList } from "rt-chat-messages";
@@ -53,10 +61,14 @@ const messages = ref([
53
61
  const isStreaming = ref(false);
54
62
  const isWaiting = ref(false);
55
63
 
56
- const handleCopy = (message) => {
57
- console.log("Copy:", message.content);
58
- };
59
- </script>
64
+ const handleCopy = (message) => {
65
+ console.log("Copy:", message.content);
66
+ };
67
+
68
+ const handleA2UIAction = (action) => {
69
+ console.log("A2UI action:", action);
70
+ };
71
+ </script>
60
72
 
61
73
  <style>
62
74
  .chat-container {
@@ -80,10 +92,54 @@ const handleCopy = (message) => {
80
92
  | `showWelcome` | `boolean` | `true` | 是否显示欢迎页(当无消息时) |
81
93
  | `appName` | `string` | `'AI助手'` | 欢迎页显示的名称 |
82
94
  | `appLogo` | `string` | - | 欢迎页 Logo URL |
83
- | `agentSteps` | `AgentStep[]` | `[]` | Agent 执行步骤(用于展示思考过程),格式见下方定义 |
84
- | `showAgentSteps` | `boolean` | `true` | 是否显示 Agent 步骤 |
85
-
86
- #### AgentStep 类型定义
95
+ | `agentSteps` | `AgentStep[]` | `[]` | Agent 执行步骤(用于展示思考过程),格式见下方定义 |
96
+ | `showAgentSteps` | `boolean` | `true` | 是否显示 Agent 步骤 |
97
+ | `enableA2UI` | `boolean` | `true` | 是否启用 A2UI v0.9 结构化 UI 渲染 |
98
+ | `autoProvideA2UI` | `boolean` | `true` | 未在上层配置 A2UI 时,自动注入默认 catalog/theme |
99
+ | `hideA2UIRawContent` | `boolean` | `true` | 当 `content` 本身是 A2UI JSON 时隐藏原始 JSON |
100
+ | `a2uiActionHandler` | `(event) => A2UIMessage[] \| Promise<A2UIMessage[]>` | - | 处理 A2UI 组件动作并返回新的 A2UI 消息 |
101
+
102
+ #### A2UI 消息格式
103
+
104
+ 组件会从 `message.a2ui`、`message.a2uiMessage`、`message.a2uiMessages`、`message.a2ui_message`、`message.a2ui_messages`、`message.metadata` 和纯 JSON `message.content` 中识别 A2UI v0.9 消息。
105
+
106
+ ```ts
107
+ const messages = [
108
+ {
109
+ role: "assistant",
110
+ content: "",
111
+ a2uiMessages: [
112
+ {
113
+ version: "v0.9",
114
+ createSurface: {
115
+ surfaceId: "demo",
116
+ catalogId: "default",
117
+ },
118
+ },
119
+ {
120
+ version: "v0.9",
121
+ updateComponents: {
122
+ surfaceId: "demo",
123
+ components: [
124
+ {
125
+ id: "root",
126
+ component: "Card",
127
+ child: "title",
128
+ },
129
+ {
130
+ id: "title",
131
+ component: "Text",
132
+ text: "A2UI 内容",
133
+ },
134
+ ],
135
+ },
136
+ },
137
+ ],
138
+ },
139
+ ];
140
+ ```
141
+
142
+ #### AgentStep 类型定义
87
143
 
88
144
  ```typescript
89
145
  export interface AgentStep {
@@ -102,19 +158,26 @@ export interface AgentStep {
102
158
 
103
159
  | 事件名 | 参数 | 说明 |
104
160
  | --------------- | ------------------------ | ------------------ |
105
- | `copy` | `(message: ChatMessage)` | 点击复制按钮时触发 |
106
- | `scroll` | `(event: Event)` | 滚动事件 |
107
- | `scroll-bottom` | - | 滚动到底部时触发 |
161
+ | `copy` | `(message: ChatMessage)` | 点击复制按钮时触发 |
162
+ | `scroll` | `(event: Event)` | 滚动事件 |
163
+ | `scroll-bottom` | - | 滚动到底部时触发 |
164
+ | `a2ui-action` | `(action, event)` | A2UI 组件交互动作 |
165
+ | `a2ui-error` | `(error)` | A2UI 渲染或动作处理异常 |
108
166
 
109
167
  ### 类型定义
110
168
 
111
169
  ```ts
112
170
  export interface ChatMessage {
113
171
  id?: string;
114
- role: "user" | "assistant" | "system" | string;
115
- content: string;
116
- metadata?: string | any;
117
- attachments?: FileAttachment[];
172
+ role: "user" | "assistant" | "system" | string;
173
+ content: string;
174
+ a2ui?: unknown;
175
+ a2uiMessage?: unknown;
176
+ a2uiMessages?: unknown;
177
+ a2ui_message?: unknown;
178
+ a2ui_messages?: unknown;
179
+ metadata?: string | any;
180
+ attachments?: FileAttachment[];
118
181
  create_time?: string;
119
182
  // 允许其他任意属性
120
183
  [key: string]: any;