rt-chat-messages 1.0.0
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 +131 -0
- package/dist/chat-messages.es.js +1151 -0
- package/dist/chat-messages.umd.js +1 -0
- package/dist/style.css +1 -0
- package/dist/types/components/AgentSteps.vue.d.ts +11 -0
- package/dist/types/components/ChatMessageList.vue.d.ts +72 -0
- package/dist/types/components/MarkdownMessage.vue.d.ts +11 -0
- package/dist/types/components/MultimodalMessage.vue.d.ts +25 -0
- package/dist/types/components/ui/Button.vue.d.ts +34 -0
- package/dist/types/components/ui/Dialog.vue.d.ts +38 -0
- package/dist/types/icons/index.d.ts +14 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/types/index.d.ts +21 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# @rongxiaobao/chat-messages
|
|
2
|
+
|
|
3
|
+
AI 对话消息展示组件库,提供开箱即用的 Markdown 渲染、代码高亮、Mermaid 图表、多模态消息(语音/图片/文件)展示功能。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 📦 **开箱即用**:封装了复杂的 Markdown 和流式消息渲染逻辑
|
|
8
|
+
- 🎨 **零 UI 库依赖**:内置基础 UI 组件,不依赖 Element Plus 等庞大组件库
|
|
9
|
+
- 📱 **响应式设计**:完美适配 PC 和移动端
|
|
10
|
+
- 🌙 **深色模式**:内置深色模式支持
|
|
11
|
+
- 🛠 **Mermaid & KaTeX**:内置图表和数学公式支持
|
|
12
|
+
- 🤖 **Agent 支持**:内置 Agent 执行步骤展示
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @rongxiaobao/chat-messages
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 快速使用
|
|
21
|
+
|
|
22
|
+
### 引入样式
|
|
23
|
+
|
|
24
|
+
在你的入口文件 (main.ts) 中引入样式:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import "@rongxiaobao/chat-messages/style.css";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 使用组件
|
|
31
|
+
|
|
32
|
+
```vue
|
|
33
|
+
<template>
|
|
34
|
+
<div class="chat-container">
|
|
35
|
+
<ChatMessageList
|
|
36
|
+
:messages="messages"
|
|
37
|
+
:is-streaming="isStreaming"
|
|
38
|
+
:is-typing="isWaiting"
|
|
39
|
+
app-name="荣小宝"
|
|
40
|
+
@copy="handleCopy"
|
|
41
|
+
/>
|
|
42
|
+
</div>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script setup>
|
|
46
|
+
import { ChatMessageList } from "@rongxiaobao/chat-messages";
|
|
47
|
+
import { ref } from "vue";
|
|
48
|
+
|
|
49
|
+
const messages = ref([
|
|
50
|
+
{ role: "user", content: "你好" },
|
|
51
|
+
{ role: "assistant", content: "你好!我是荣小宝,有什么可以帮你?" },
|
|
52
|
+
]);
|
|
53
|
+
const isStreaming = ref(false);
|
|
54
|
+
const isWaiting = ref(false);
|
|
55
|
+
|
|
56
|
+
const handleCopy = (message) => {
|
|
57
|
+
console.log("Copy:", message.content);
|
|
58
|
+
};
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<style>
|
|
62
|
+
.chat-container {
|
|
63
|
+
height: 600px; /* 必须给容器高度 */
|
|
64
|
+
}
|
|
65
|
+
</style>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 组件 API
|
|
69
|
+
|
|
70
|
+
### ChatMessageList
|
|
71
|
+
|
|
72
|
+
**Props**
|
|
73
|
+
|
|
74
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
75
|
+
| ---------------- | --------------- | ---------- | ------------------------------------ |
|
|
76
|
+
| `messages` | `ChatMessage[]` | `[]` | 消息列表 |
|
|
77
|
+
| `isStreaming` | `boolean` | `false` | 是否正在流式输出(用于优化渲染性能) |
|
|
78
|
+
| `isTyping` | `boolean` | `false` | 是否显示输入的等待动画 |
|
|
79
|
+
| `autoScroll` | `boolean` | `true` | 是否自动跟随内容滚动到底部 |
|
|
80
|
+
| `showWelcome` | `boolean` | `true` | 是否显示欢迎页(当无消息时) |
|
|
81
|
+
| `appName` | `string` | `'AI助手'` | 欢迎页显示的名称 |
|
|
82
|
+
| `appLogo` | `string` | - | 欢迎页 Logo URL |
|
|
83
|
+
| `agentSteps` | `AgentStep[]` | `[]` | Agent 执行步骤数据 |
|
|
84
|
+
| `showAgentSteps` | `boolean` | `true` | 是否显示 Agent 步骤 |
|
|
85
|
+
|
|
86
|
+
**Events**
|
|
87
|
+
|
|
88
|
+
| 事件名 | 参数 | 说明 |
|
|
89
|
+
| --------------- | ------------------------ | ------------------ |
|
|
90
|
+
| `copy` | `(message: ChatMessage)` | 点击复制按钮时触发 |
|
|
91
|
+
| `scroll` | `(event: Event)` | 滚动事件 |
|
|
92
|
+
| `scroll-bottom` | - | 滚动到底部时触发 |
|
|
93
|
+
|
|
94
|
+
### 类型定义
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
export interface ChatMessage {
|
|
98
|
+
id?: string;
|
|
99
|
+
role: "user" | "assistant" | "system" | string;
|
|
100
|
+
content: string;
|
|
101
|
+
metadata?: string | any;
|
|
102
|
+
attachments?: FileAttachment[];
|
|
103
|
+
create_time?: string;
|
|
104
|
+
// 允许其他任意属性
|
|
105
|
+
[key: string]: any;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface FileAttachment {
|
|
109
|
+
name: string;
|
|
110
|
+
size: number;
|
|
111
|
+
type: string;
|
|
112
|
+
fileType?: string;
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### MultimodalMessage / MarkdownMessage
|
|
117
|
+
|
|
118
|
+
这两个组件也可以单独使用,用于渲染单条消息或 Markdown 内容。
|
|
119
|
+
|
|
120
|
+
## 开发
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# 安装依赖
|
|
124
|
+
npm install
|
|
125
|
+
|
|
126
|
+
# 开发模式
|
|
127
|
+
npm run dev
|
|
128
|
+
|
|
129
|
+
# 构建
|
|
130
|
+
npm run build
|
|
131
|
+
```
|