@qlover/create-app 0.8.0 → 0.9.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/CHANGELOG.md +17 -0
- package/dist/configs/_common/.github/workflows/general-check.yml +1 -1
- package/dist/configs/_common/.github/workflows/release.yml +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/react-app/__tests__/src/uikit/components/chatMessage/ChatRoot.test.tsx +274 -0
- package/dist/templates/react-app/config/IOCIdentifier.ts +3 -0
- package/dist/templates/react-app/config/Identifier/components/component.chatMessage.ts +56 -0
- package/dist/templates/react-app/config/Identifier/components/component.messageBaseList.ts +103 -0
- package/dist/templates/react-app/config/Identifier/pages/index.ts +1 -0
- package/dist/templates/react-app/config/Identifier/pages/page.message.ts +20 -0
- package/dist/templates/react-app/config/app.router.ts +23 -0
- package/dist/templates/react-app/config/i18n/chatMessageI18n.ts +17 -0
- package/dist/templates/react-app/config/i18n/messageBaseListI18n.ts +22 -0
- package/dist/templates/react-app/config/i18n/messageI18n.ts +14 -0
- package/dist/templates/react-app/docs/en/components/chat-message-component.md +314 -0
- package/dist/templates/react-app/docs/en/components/chat-message-refactor.md +270 -0
- package/dist/templates/react-app/docs/en/components/message-base-list-component.md +172 -0
- package/dist/templates/react-app/docs/zh/components/chat-message-component.md +314 -0
- package/dist/templates/react-app/docs/zh/components/chat-message-refactor.md +270 -0
- package/dist/templates/react-app/docs/zh/components/message-base-list-component.md +172 -0
- package/dist/templates/react-app/playwright.config.ts +6 -6
- package/dist/templates/react-app/public/locales/en/common.json +44 -1
- package/dist/templates/react-app/public/locales/zh/common.json +44 -1
- package/dist/templates/react-app/src/pages/base/MessagePage.tsx +40 -0
- package/dist/templates/react-app/src/uikit/components/MessageBaseList.tsx +240 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/ChatMessageBridge.ts +176 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/ChatRoot.tsx +21 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/FocusBar.tsx +106 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/MessageApi.ts +271 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/MessageItem.tsx +102 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/MessagesList.tsx +86 -0
- package/package.json +1 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# MessageBaseList Component Documentation
|
|
2
|
+
|
|
3
|
+
## 📋 Component Overview
|
|
4
|
+
|
|
5
|
+
`MessageBaseList` is a simple one-way message component for testing message gateway functionality. Users send messages and wait for gateway responses with displayed results.
|
|
6
|
+
|
|
7
|
+
## ✨ Features
|
|
8
|
+
|
|
9
|
+
- ✅ Send messages to gateway
|
|
10
|
+
- ✅ Real-time message status display (sending, success, failure)
|
|
11
|
+
- ✅ Beautiful chat interface styling
|
|
12
|
+
- ✅ Full internationalization support (Chinese/English)
|
|
13
|
+
- ✅ Error handling and retry mechanism
|
|
14
|
+
- ✅ Responsive design
|
|
15
|
+
|
|
16
|
+
## 🎨 Interface Features
|
|
17
|
+
|
|
18
|
+
### Message Display
|
|
19
|
+
|
|
20
|
+
- **User Messages**: Blue bubble, right-aligned
|
|
21
|
+
- **Gateway Responses**:
|
|
22
|
+
- **Processing**: Gray background with animated loading dots
|
|
23
|
+
- **Success**: Green background with response result
|
|
24
|
+
- **Failure**: Red background with error message
|
|
25
|
+
|
|
26
|
+
### Empty State
|
|
27
|
+
|
|
28
|
+
When there are no messages, displays friendly hint text to guide users to send their first message.
|
|
29
|
+
|
|
30
|
+
## 🔧 Usage
|
|
31
|
+
|
|
32
|
+
### Using in a Page
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { MessageBaseList } from '@/uikit/components/MessageBaseList';
|
|
36
|
+
|
|
37
|
+
export default function MessagePage() {
|
|
38
|
+
return (
|
|
39
|
+
<div className="min-h-screen bg-primary py-8 px-4 sm:px-6 lg:px-8">
|
|
40
|
+
<MessageBaseList />
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 🌐 Internationalization Configuration
|
|
47
|
+
|
|
48
|
+
### File Structure
|
|
49
|
+
|
|
50
|
+
- **Identifier Definitions**: `config/Identifier/components/component.messageBaseList.ts`
|
|
51
|
+
- **i18n Configuration**: `config/i18n/messageBaseListI18n.ts`
|
|
52
|
+
|
|
53
|
+
### Supported Text
|
|
54
|
+
|
|
55
|
+
| Text Item | Chinese | English |
|
|
56
|
+
|-----------|---------|---------|
|
|
57
|
+
| Title | 消息网关测试 | Message Gateway Test |
|
|
58
|
+
| Description | 发送消息并等待网关响应 | Send messages and wait for gateway response |
|
|
59
|
+
| Empty State | 暂无消息 | No messages yet |
|
|
60
|
+
| User Label | 你 | You |
|
|
61
|
+
| Gateway Label | 网关 | Gateway |
|
|
62
|
+
| Processing | 处理中... | Processing... |
|
|
63
|
+
| Failed Label | 网关(失败) | Gateway (Failed) |
|
|
64
|
+
| Gateway Response | 网关响应 | Gateway Response |
|
|
65
|
+
| Send Button | 发送 | Send |
|
|
66
|
+
|
|
67
|
+
## 🧪 Testing Features
|
|
68
|
+
|
|
69
|
+
### Simulated Gateway Behavior
|
|
70
|
+
|
|
71
|
+
The component includes a built-in `MessageBaseApi` class that simulates real gateway behavior:
|
|
72
|
+
|
|
73
|
+
- **Normal Response**: 200-1000ms delay, returns confirmation message
|
|
74
|
+
- **Trigger Errors**:
|
|
75
|
+
- Send messages containing "error" or "Failed"
|
|
76
|
+
- Random network errors (when delay is divisible by 5)
|
|
77
|
+
|
|
78
|
+
### Testing Suggestions
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
# Normal messages
|
|
82
|
+
Hello World
|
|
83
|
+
|
|
84
|
+
# Trigger errors
|
|
85
|
+
error
|
|
86
|
+
Failed
|
|
87
|
+
test error message
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 📦 Core Dependencies
|
|
91
|
+
|
|
92
|
+
### @qlover/corekit-bridge
|
|
93
|
+
|
|
94
|
+
- `MessagesStore` - Message state management
|
|
95
|
+
- `MessageSender` - Message sender
|
|
96
|
+
- `SenderStrategyPlugin` - Send strategy plugin
|
|
97
|
+
- `SendFailureStrategy.KEEP_FAILED` - Strategy to keep failed messages
|
|
98
|
+
|
|
99
|
+
### Features
|
|
100
|
+
|
|
101
|
+
1. **Automatic State Management**: Message loading, success, and failure states automatically update
|
|
102
|
+
2. **Failed Message Retention**: Failed messages remain in the list for error review
|
|
103
|
+
3. **Duplicate Send Prevention**: Input and button disabled during sending
|
|
104
|
+
|
|
105
|
+
## 🎯 Styling System
|
|
106
|
+
|
|
107
|
+
### Tailwind CSS Classes
|
|
108
|
+
|
|
109
|
+
Component uses project theme system:
|
|
110
|
+
|
|
111
|
+
- `bg-primary` - Primary background
|
|
112
|
+
- `bg-secondary` - Secondary background
|
|
113
|
+
- `bg-base` - Base background
|
|
114
|
+
- `text-text` - Primary text color
|
|
115
|
+
- `text-text-secondary` - Secondary text color
|
|
116
|
+
- `border-primary` - Primary border color
|
|
117
|
+
|
|
118
|
+
### Responsive Design
|
|
119
|
+
|
|
120
|
+
- Message max width: 70% (adapts to different screens)
|
|
121
|
+
- Message list max height: 96 (approx. 384px)
|
|
122
|
+
- Message list min height: 64 (approx. 256px)
|
|
123
|
+
- Auto scroll: overflow-y-auto
|
|
124
|
+
|
|
125
|
+
## 💡 Use Cases
|
|
126
|
+
|
|
127
|
+
1. **Development Debugging**: Test message gateway functionality
|
|
128
|
+
2. **Demonstrations**: Show message sending and response flow
|
|
129
|
+
3. **Integration Testing**: Verify message system integration
|
|
130
|
+
4. **User Training**: Teaching and training purposes
|
|
131
|
+
|
|
132
|
+
## 🔄 State Flow
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
User enters message
|
|
136
|
+
↓
|
|
137
|
+
Click send / Enter
|
|
138
|
+
↓
|
|
139
|
+
messagesSender.send()
|
|
140
|
+
↓
|
|
141
|
+
Message state: loading = true
|
|
142
|
+
↓
|
|
143
|
+
Call MessageBaseApi.sendMessage()
|
|
144
|
+
↓
|
|
145
|
+
[Success] → status: SENT, result: response content
|
|
146
|
+
[Failure] → status: FAILED, error: error message
|
|
147
|
+
↓
|
|
148
|
+
UI auto-updates display
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 📝 Notes
|
|
152
|
+
|
|
153
|
+
1. **Clear Input**: Input automatically clears after successful send
|
|
154
|
+
2. **Disable Control**: Input and send button disabled during sending
|
|
155
|
+
3. **Error Handling**: Uses `(message as any).error` to access error info (type-safe)
|
|
156
|
+
4. **Style Compatibility**: Uses `wrap-break-word` instead of `break-words`
|
|
157
|
+
|
|
158
|
+
## 🚀 Future Extensions
|
|
159
|
+
|
|
160
|
+
Possible feature expansion directions:
|
|
161
|
+
|
|
162
|
+
- [ ] Support image and file sending
|
|
163
|
+
- [ ] Support message editing and deletion
|
|
164
|
+
- [ ] Support message search
|
|
165
|
+
- [ ] Support message export
|
|
166
|
+
- [ ] Support custom gateway API
|
|
167
|
+
- [ ] Support WebSocket real-time communication
|
|
168
|
+
|
|
169
|
+
## 🎉 Summary
|
|
170
|
+
|
|
171
|
+
`MessageBaseList` is a fully-featured, beautifully styled message component with complete internationalization support, perfect for testing and demonstrating message gateway functionality.
|
|
172
|
+
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# ChatMessage 聊天组件系统
|
|
2
|
+
|
|
3
|
+
## 📋 概述
|
|
4
|
+
|
|
5
|
+
ChatMessage 是一个完整的聊天组件系统,支持实时对话、流式输出、错误处理等功能。适合用于 AI 对话、客服聊天等场景。
|
|
6
|
+
|
|
7
|
+
## ✨ 核心功能
|
|
8
|
+
|
|
9
|
+
- ✅ **流式输出**:支持逐字显示 AI 回复(类似 ChatGPT)
|
|
10
|
+
- ✅ **停止控制**:可随时停止正在生成的消息
|
|
11
|
+
- ✅ **重试机制**:失败消息可一键重试
|
|
12
|
+
- ✅ **草稿管理**:自动保存输入中的草稿消息
|
|
13
|
+
- ✅ **加载状态**:清晰的消息发送和接收状态
|
|
14
|
+
- ✅ **错误处理**:完善的错误提示和处理
|
|
15
|
+
- ✅ **快捷键**:Ctrl+Enter 快速发送
|
|
16
|
+
- ✅ **国际化**:完整的中英文支持
|
|
17
|
+
- ✅ **响应式设计**:适配不同屏幕尺寸
|
|
18
|
+
|
|
19
|
+
## 📁 文件结构
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
src/uikit/components/chatMessage/
|
|
23
|
+
├── ChatRoot.tsx # 根组件(组装所有部分)
|
|
24
|
+
├── MessagesList.tsx # 消息列表组件
|
|
25
|
+
├── MessageItem.tsx # 单个消息项组件
|
|
26
|
+
├── FocusBar.tsx # 输入栏组件
|
|
27
|
+
├── ChatMessageBridge.ts # 桥接层(连接UI和逻辑)
|
|
28
|
+
└── MessageApi.ts # API层(模拟/真实后端)
|
|
29
|
+
|
|
30
|
+
config/
|
|
31
|
+
├── Identifier/components/component.chatMessage.ts # i18n 标识符
|
|
32
|
+
├── i18n/chatMessageI18n.ts # 组件 i18n 配置
|
|
33
|
+
├── Identifier/pages/page.chat.ts # 页面 i18n 标识符
|
|
34
|
+
└── i18n/chatI18n.ts # 页面 i18n 配置
|
|
35
|
+
|
|
36
|
+
src/pages/base/
|
|
37
|
+
└── ChatMessagePage.tsx # 聊天页面
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 🎯 核心概念
|
|
41
|
+
|
|
42
|
+
### 1. ChatMessageBridge(桥接层)
|
|
43
|
+
|
|
44
|
+
连接 UI 和数据层的桥梁,处理:
|
|
45
|
+
- 消息发送逻辑
|
|
46
|
+
- 草稿管理
|
|
47
|
+
- 状态控制
|
|
48
|
+
- 停止机制
|
|
49
|
+
|
|
50
|
+
### 2. MessageApi(网关层)
|
|
51
|
+
|
|
52
|
+
模拟后端 API,支持三种模式:
|
|
53
|
+
|
|
54
|
+
#### 流式模式 (stream: true)
|
|
55
|
+
```typescript
|
|
56
|
+
{
|
|
57
|
+
stream: true // 逐字输出,可停止
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### 可中断普通模式
|
|
62
|
+
```typescript
|
|
63
|
+
{
|
|
64
|
+
stream: false // 一次性返回,可停止
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### 快速普通模式
|
|
69
|
+
```typescript
|
|
70
|
+
// 不传 options,一次性返回,不可停止
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 3. ChatMessageStore(状态管理)
|
|
74
|
+
|
|
75
|
+
管理所有消息状态:
|
|
76
|
+
- `messages` - 历史消息列表
|
|
77
|
+
- `draftMessages` - 草稿消息列表
|
|
78
|
+
- `streaming` - 是否正在流式输出
|
|
79
|
+
- `disabledSend` - 是否禁用发送
|
|
80
|
+
|
|
81
|
+
## 🚀 使用方式
|
|
82
|
+
|
|
83
|
+
### 基本使用
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { ChatRoot } from '@/uikit/components/chatMessage/ChatRoot';
|
|
87
|
+
|
|
88
|
+
export default function ChatMessagePage() {
|
|
89
|
+
return (
|
|
90
|
+
<div className="h-screen">
|
|
91
|
+
<ChatRoot />
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 访问路径
|
|
98
|
+
|
|
99
|
+
- `/en/chat` - 英文
|
|
100
|
+
- `/zh/chat` - 中文
|
|
101
|
+
|
|
102
|
+
## 🎨 界面设计
|
|
103
|
+
|
|
104
|
+
### 消息样式
|
|
105
|
+
|
|
106
|
+
**用户消息**:
|
|
107
|
+
- 蓝色背景
|
|
108
|
+
- 右对齐
|
|
109
|
+
- 最大宽度 80%
|
|
110
|
+
- 显示耗时
|
|
111
|
+
- 带重试按钮
|
|
112
|
+
|
|
113
|
+
**AI 消息**:
|
|
114
|
+
- 浅色背景 + 边框
|
|
115
|
+
- 左对齐
|
|
116
|
+
- 最大宽度 85%
|
|
117
|
+
- 支持流式显示
|
|
118
|
+
- 显示加载状态
|
|
119
|
+
|
|
120
|
+
### 输入栏
|
|
121
|
+
|
|
122
|
+
- 自动调整高度(2-6 行)
|
|
123
|
+
- Ctrl+Enter 发送
|
|
124
|
+
- 禁用状态控制
|
|
125
|
+
- 发送/停止按钮切换
|
|
126
|
+
|
|
127
|
+
## 📝 关键API
|
|
128
|
+
|
|
129
|
+
### ChatMessageBridge 方法
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
interface ChatMessageBridgeInterface<T> {
|
|
133
|
+
// 发送消息
|
|
134
|
+
send(message?: ChatMessage<T>): Promise<ChatMessage<T>>;
|
|
135
|
+
|
|
136
|
+
// 停止发送
|
|
137
|
+
stop(messageId?: string): boolean;
|
|
138
|
+
|
|
139
|
+
// 停止所有
|
|
140
|
+
stopAll(): void;
|
|
141
|
+
|
|
142
|
+
// 更新内容
|
|
143
|
+
onChangeContent(content: T): void;
|
|
144
|
+
|
|
145
|
+
// 获取消息存储
|
|
146
|
+
getMessageStore(): ChatMessageStore<T>;
|
|
147
|
+
|
|
148
|
+
// 获取第一个草稿消息
|
|
149
|
+
getFirstDraftMessage(): ChatMessage<T> | null;
|
|
150
|
+
|
|
151
|
+
// 获取正在发送的消息
|
|
152
|
+
getSendingMessage(): ChatMessage<T> | null;
|
|
153
|
+
|
|
154
|
+
// 是否禁用发送
|
|
155
|
+
getDisabledSend(): boolean;
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### MessageApi 模式
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
class MessageApi {
|
|
163
|
+
async sendMessage<M>(
|
|
164
|
+
message: M,
|
|
165
|
+
options?: GatewayOptions<M>
|
|
166
|
+
): Promise<M>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
interface GatewayOptions<M> {
|
|
170
|
+
stream?: boolean; // 是否流式
|
|
171
|
+
signal?: AbortSignal; // 停止信号
|
|
172
|
+
onConnected?: () => void; // 连接成功
|
|
173
|
+
onChunk?: (msg: M) => void; // 流式块回调
|
|
174
|
+
onProgress?: (p: number) => void; // 进度回调
|
|
175
|
+
onComplete?: (msg: M) => void; // 完成回调
|
|
176
|
+
onAborted?: (msg: M) => void; // 停止回调
|
|
177
|
+
onError?: (err: any) => void; // 错误回调
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## 🔧 自定义配置
|
|
182
|
+
|
|
183
|
+
### 1. 切换发送模式
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
// 修改 ChatRoot.tsx
|
|
187
|
+
const [bridge] = useState(() => {
|
|
188
|
+
return new ChatMessageBridge<string>(messagesStore, {
|
|
189
|
+
gateway: messageApi,
|
|
190
|
+
logger: logger,
|
|
191
|
+
senderName: 'ChatSender',
|
|
192
|
+
gatewayOptions: {
|
|
193
|
+
stream: true // 改为 false 使用普通模式
|
|
194
|
+
}
|
|
195
|
+
}).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 2. 自定义消息组件
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
<MessagesList
|
|
203
|
+
bridge={bridge}
|
|
204
|
+
getMessageComponent={(props) => CustomMessageItem}
|
|
205
|
+
/>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 3. 连接真实 API
|
|
209
|
+
|
|
210
|
+
修改 `MessageApi.ts`:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
async sendMessage<M>(message: M, options?: GatewayOptions<M>): Promise<M> {
|
|
214
|
+
// 替换为真实 API 调用
|
|
215
|
+
const response = await fetch('/api/chat', {
|
|
216
|
+
method: 'POST',
|
|
217
|
+
body: JSON.stringify(message),
|
|
218
|
+
signal: options?.signal
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// 处理流式响应
|
|
222
|
+
if (options?.stream) {
|
|
223
|
+
const reader = response.body?.getReader();
|
|
224
|
+
// ... 处理流式数据
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return response.json();
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## 💡 使用建议
|
|
232
|
+
|
|
233
|
+
### 测试功能
|
|
234
|
+
|
|
235
|
+
**正常消息**:
|
|
236
|
+
```
|
|
237
|
+
Hello
|
|
238
|
+
你好
|
|
239
|
+
测试消息
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**触发错误**:
|
|
243
|
+
```
|
|
244
|
+
error
|
|
245
|
+
Failed
|
|
246
|
+
test error
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**查看流式效果**:
|
|
250
|
+
- 发送任意消息
|
|
251
|
+
- 观察逐字输出效果
|
|
252
|
+
- 点击停止按钮测试中断
|
|
253
|
+
|
|
254
|
+
### 快捷键
|
|
255
|
+
|
|
256
|
+
- `Ctrl + Enter` - 发送消息
|
|
257
|
+
- 输入中自动保存草稿
|
|
258
|
+
|
|
259
|
+
## 🎯 适用场景
|
|
260
|
+
|
|
261
|
+
1. **AI 对话应用**:类似 ChatGPT 的对话界面
|
|
262
|
+
2. **客服系统**:实时客服聊天
|
|
263
|
+
3. **问答系统**:Q&A 交互
|
|
264
|
+
4. **代码助手**:代码生成和解释
|
|
265
|
+
5. **教学助手**:在线学习辅导
|
|
266
|
+
|
|
267
|
+
## 🔄 消息流转
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
用户输入 → 草稿消息
|
|
271
|
+
↓
|
|
272
|
+
点击发送/Ctrl+Enter
|
|
273
|
+
↓
|
|
274
|
+
Bridge.send()
|
|
275
|
+
↓
|
|
276
|
+
MessageSender → MessageApi
|
|
277
|
+
↓
|
|
278
|
+
[流式模式]
|
|
279
|
+
onConnected → onChunk(逐字) → onComplete
|
|
280
|
+
|
|
281
|
+
[普通模式]
|
|
282
|
+
onConnected → onComplete
|
|
283
|
+
|
|
284
|
+
[错误]
|
|
285
|
+
onError
|
|
286
|
+
|
|
287
|
+
[停止]
|
|
288
|
+
onAborted
|
|
289
|
+
↓
|
|
290
|
+
更新 ChatMessageStore
|
|
291
|
+
↓
|
|
292
|
+
UI 自动更新
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## 📊 状态管理
|
|
296
|
+
|
|
297
|
+
### 消息状态
|
|
298
|
+
|
|
299
|
+
- `DRAFT` - 草稿
|
|
300
|
+
- `SENDING` - 发送中
|
|
301
|
+
- `SENT` - 已发送
|
|
302
|
+
- `FAILED` - 失败
|
|
303
|
+
- `STOPPED` - 已停止
|
|
304
|
+
|
|
305
|
+
### 消息角色
|
|
306
|
+
|
|
307
|
+
- `USER` - 用户消息
|
|
308
|
+
- `ASSISTANT` - AI/助手消息
|
|
309
|
+
- `SYSTEM` - 系统消息
|
|
310
|
+
|
|
311
|
+
## 🎉 总结
|
|
312
|
+
|
|
313
|
+
ChatMessage 是一个功能完整、设计优雅的聊天组件系统,开箱即用,支持流式输出、错误处理、状态管理等核心功能。可以直接用于生产环境,也可以根据需要进行扩展和定制。
|
|
314
|
+
|