@qlover/create-app 0.10.2 → 0.10.3
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 +37 -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 +4 -4
- package/dist/index.js +4 -4
- package/dist/templates/next-app/eslint.config.mjs +5 -1
- package/dist/templates/next-app/package.json +4 -2
- package/dist/templates/next-app/src/base/cases/AdminPageManager.ts +3 -3
- package/dist/templates/next-app/src/base/cases/AppConfig.ts +14 -13
- package/dist/templates/next-app/src/base/cases/Datetime.ts +3 -3
- package/dist/templates/next-app/src/base/cases/DialogErrorPlugin.ts +8 -2
- package/dist/templates/next-app/src/base/cases/DialogHandler.ts +30 -4
- package/dist/templates/next-app/src/base/cases/InversifyContainer.ts +16 -4
- package/dist/templates/next-app/src/base/cases/NavigateBridge.ts +8 -2
- package/dist/templates/next-app/src/base/cases/RequestEncryptPlugin.ts +8 -2
- package/dist/templates/next-app/src/base/cases/ResourceState.ts +3 -3
- package/dist/templates/next-app/src/base/cases/RouterService.ts +24 -6
- package/dist/templates/next-app/src/base/cases/StringEncryptor.ts +14 -2
- package/dist/templates/next-app/src/base/cases/TranslateI18nInterface.ts +1 -1
- package/dist/templates/next-app/src/base/cases/UserServiceApi.ts +20 -5
- package/dist/templates/next-app/src/base/cases/ZodColumnBuilder.ts +31 -8
- package/dist/templates/next-app/src/base/port/AdminLayoutInterface.ts +4 -1
- package/dist/templates/next-app/src/base/port/I18nServiceInterface.ts +27 -7
- package/dist/templates/next-app/src/base/services/AdminPageEvent.ts +1 -1
- package/dist/templates/next-app/src/base/services/AdminPageScheduler.ts +3 -3
- package/dist/templates/next-app/src/base/services/I18nService.ts +20 -10
- package/dist/templates/next-app/src/base/services/ResourceService.ts +32 -11
- package/dist/templates/next-app/src/base/services/UserService.ts +12 -3
- package/dist/templates/next-app/src/base/services/adminApi/AdminLocalesApi.ts +9 -6
- package/dist/templates/next-app/src/base/services/adminApi/AdminUserApi.ts +20 -5
- package/dist/templates/next-app/src/base/services/appApi/AppApiPlugin.ts +21 -4
- package/dist/templates/next-app/src/base/services/appApi/AppUserApi.ts +12 -3
- package/dist/templates/next-app/src/base/services/appApi/AppUserApiBootstrap.ts +10 -2
- package/dist/templates/next-app/src/core/bootstraps/BootstrapClient.ts +2 -2
- package/dist/templates/next-app/src/core/bootstraps/BootstrapServer.ts +25 -7
- package/dist/templates/next-app/src/core/bootstraps/BootstrapsRegistry.ts +6 -3
- package/dist/templates/next-app/src/core/clientIoc/ClientIOC.ts +11 -2
- package/dist/templates/next-app/src/core/clientIoc/ClientIOCRegister.ts +5 -0
- package/dist/templates/next-app/src/core/serverIoc/ServerIOC.ts +13 -4
- package/dist/templates/next-app/src/core/serverIoc/ServerIOCRegister.ts +8 -1
- package/dist/templates/next-app/src/pages/_app.tsx +1 -1
- package/dist/templates/next-app/src/server/AppErrorApi.ts +1 -1
- package/dist/templates/next-app/src/server/AppPageRouteParams.ts +13 -0
- package/dist/templates/next-app/src/server/AppSuccessApi.ts +1 -1
- package/dist/templates/next-app/src/server/NextApiServer.ts +11 -2
- package/dist/templates/next-app/src/server/PagesRouteParams.ts +11 -1
- package/dist/templates/next-app/src/server/PasswordEncrypt.ts +8 -2
- package/dist/templates/next-app/src/server/ServerAuth.ts +20 -5
- package/dist/templates/next-app/src/server/SupabaseBridge.ts +48 -8
- package/dist/templates/next-app/src/server/UserCredentialToken.ts +8 -2
- package/dist/templates/next-app/src/server/controllers/AdminLocalesController.ts +16 -4
- package/dist/templates/next-app/src/server/controllers/AdminUserController.ts +4 -1
- package/dist/templates/next-app/src/server/controllers/LocalesController.ts +4 -1
- package/dist/templates/next-app/src/server/controllers/UserController.ts +12 -3
- package/dist/templates/next-app/src/server/repositorys/LocalesRepository.ts +23 -7
- package/dist/templates/next-app/src/server/repositorys/UserRepository.ts +15 -6
- package/dist/templates/next-app/src/server/services/AIService.ts +3 -1
- package/dist/templates/next-app/src/server/services/AdminAuthPlugin.ts +5 -2
- package/dist/templates/next-app/src/server/services/ApiLocaleService.ts +5 -5
- package/dist/templates/next-app/src/server/services/ApiUserService.ts +1 -1
- package/dist/templates/next-app/src/server/services/UserService.ts +12 -3
- package/dist/templates/next-app/src/server/validators/LocalesValidator.ts +20 -5
- package/dist/templates/next-app/src/server/validators/LoginValidator.ts +16 -4
- package/dist/templates/next-app/src/server/validators/PaginationValidator.ts +8 -2
- package/dist/templates/next-app/src/uikit/components/IOCProvider.tsx +1 -1
- package/dist/templates/next-app/src/uikit/components/localesImportButton/LocalesImportEvent.ts +7 -1
- package/dist/templates/react-app/__tests__/__mocks__/BootstrapTest.ts +3 -1
- package/dist/templates/react-app/__tests__/__mocks__/MockAppConfig.ts +19 -19
- package/dist/templates/react-app/__tests__/__mocks__/MockDialogHandler.ts +8 -8
- package/dist/templates/react-app/__tests__/__mocks__/MockLogger.ts +9 -9
- package/dist/templates/react-app/__tests__/__mocks__/components/TestBootstrapsProvider.tsx +1 -1
- package/dist/templates/react-app/__tests__/__mocks__/i18nextHttpBackend.ts +5 -5
- package/dist/templates/react-app/__tests__/__mocks__/testIOC/TestIOC.ts +9 -5
- package/dist/templates/react-app/__tests__/__mocks__/testIOC/TestIOCRegister.ts +8 -4
- package/dist/templates/react-app/__tests__/src/base/cases/I18nKeyErrorPlugin.test.ts +4 -4
- package/dist/templates/react-app/__tests__/src/base/cases/InversifyContainer.test.ts +5 -5
- package/dist/templates/react-app/__tests__/src/core/bootstraps/BootstrapClient.test.ts +3 -3
- package/dist/templates/react-app/__tests__/src/uikit/components/chatMessage/ChatRoot.test.tsx +1 -1
- package/dist/templates/react-app/docs/en/components/chat-message-component.md +35 -29
- package/dist/templates/react-app/docs/en/components/chat-message-refactor.md +18 -5
- package/dist/templates/react-app/docs/en/components/message-base-list-component.md +11 -12
- package/dist/templates/react-app/docs/en/request.md +1 -3
- package/dist/templates/react-app/docs/zh/components/chat-message-component.md +35 -29
- package/dist/templates/react-app/docs/zh/components/chat-message-refactor.md +18 -5
- package/dist/templates/react-app/docs/zh/components/message-base-list-component.md +11 -12
- package/dist/templates/react-app/docs/zh/request.md +1 -3
- package/dist/templates/react-app/eslint.config.mjs +10 -5
- package/dist/templates/react-app/src/App.tsx +1 -1
- package/dist/templates/react-app/src/base/apis/feApi/FeApi.ts +2 -2
- package/dist/templates/react-app/src/base/apis/feApi/FeApiBootstarp.ts +14 -11
- package/dist/templates/react-app/src/base/apis/userApi/UserApi.ts +10 -16
- package/dist/templates/react-app/src/base/apis/userApi/UserApiBootstarp.ts +12 -10
- package/dist/templates/react-app/src/base/cases/AppConfig.ts +19 -19
- package/dist/templates/react-app/src/base/cases/DialogHandler.ts +28 -5
- package/dist/templates/react-app/src/base/cases/I18nKeyErrorPlugin.ts +5 -2
- package/dist/templates/react-app/src/base/cases/InversifyContainer.ts +16 -4
- package/dist/templates/react-app/src/base/cases/PublicAssetsPath.ts +1 -1
- package/dist/templates/react-app/src/base/cases/RequestLanguages.ts +6 -3
- package/dist/templates/react-app/src/base/cases/RequestLogger.ts +17 -8
- package/dist/templates/react-app/src/base/cases/RequestStatusCatcher.ts +4 -6
- package/dist/templates/react-app/src/base/cases/ResourceState.ts +3 -3
- package/dist/templates/react-app/src/base/cases/RouterLoader.ts +3 -3
- package/dist/templates/react-app/src/base/cases/TranslateI18nInterface.ts +1 -1
- package/dist/templates/react-app/src/base/port/ExecutorPageBridgeInterface.ts +2 -2
- package/dist/templates/react-app/src/base/port/IOCInterface.ts +4 -2
- package/dist/templates/react-app/src/base/port/JSONStoragePageBridgeInterface.ts +5 -5
- package/dist/templates/react-app/src/base/port/RequestPageBridgeInterface.ts +7 -7
- package/dist/templates/react-app/src/base/port/RouteServiceInterface.ts +8 -8
- package/dist/templates/react-app/src/base/port/UserServiceInterface.ts +4 -2
- package/dist/templates/react-app/src/base/services/BaseLayoutService.ts +3 -3
- package/dist/templates/react-app/src/base/services/I18nService.ts +24 -13
- package/dist/templates/react-app/src/base/services/IdentifierService.ts +21 -26
- package/dist/templates/react-app/src/base/services/RouteService.ts +8 -8
- package/dist/templates/react-app/src/base/services/UserBootstrap.ts +2 -2
- package/dist/templates/react-app/src/base/services/UserGatewayPlugin.ts +9 -5
- package/dist/templates/react-app/src/base/services/UserService.ts +10 -4
- package/dist/templates/react-app/src/core/bootstraps/BootstrapClient.ts +3 -1
- package/dist/templates/react-app/src/core/bootstraps/BootstrapsRegistry.ts +5 -2
- package/dist/templates/react-app/src/core/clientIoc/ClientIOC.ts +11 -4
- package/dist/templates/react-app/src/core/clientIoc/ClientIOCRegister.ts +5 -4
- package/dist/templates/react-app/src/pages/base/Layout.tsx +1 -1
- package/dist/templates/react-app/src/styles/css/antd-themes/_common/_default.css +0 -44
- package/dist/templates/react-app/src/styles/css/antd-themes/_common/dark.css +0 -44
- package/dist/templates/react-app/src/styles/css/antd-themes/_common/pink.css +0 -44
- package/dist/templates/react-app/src/styles/css/index.css +1 -1
- package/dist/templates/react-app/src/styles/css/scrollbar.css +34 -0
- package/dist/templates/react-app/src/uikit/bridges/ExecutorPageBridge.ts +2 -2
- package/dist/templates/react-app/src/uikit/bridges/JSONStoragePageBridge.ts +4 -4
- package/dist/templates/react-app/src/uikit/bridges/NavigateBridge.ts +8 -2
- package/dist/templates/react-app/src/uikit/bridges/RequestPageBridge.ts +6 -6
- package/dist/templates/react-app/src/uikit/components/AppRouterProvider.tsx +1 -1
- package/dist/templates/react-app/src/uikit/components/BootstrapsProvider.tsx +1 -3
- package/dist/templates/react-app/src/uikit/components/MessageBaseList.tsx +4 -1
- package/dist/templates/react-app/src/uikit/components/chatMessage/ChatMessageBridge.ts +39 -16
- package/dist/templates/react-app/src/uikit/components/chatMessage/MessageApi.ts +4 -2
- package/package.json +3 -3
- package/dist/templates/react-app/makes/eslint-utils.mjs +0 -195
|
@@ -42,6 +42,7 @@ src/pages/base/
|
|
|
42
42
|
### 1. ChatMessageBridge (Bridge Layer)
|
|
43
43
|
|
|
44
44
|
Bridge connecting UI and data layer, handles:
|
|
45
|
+
|
|
45
46
|
- Message sending logic
|
|
46
47
|
- Draft management
|
|
47
48
|
- State control
|
|
@@ -52,20 +53,23 @@ Bridge connecting UI and data layer, handles:
|
|
|
52
53
|
Simulates backend API, supports three modes:
|
|
53
54
|
|
|
54
55
|
#### Streaming Mode (stream: true)
|
|
56
|
+
|
|
55
57
|
```typescript
|
|
56
58
|
{
|
|
57
|
-
stream: true
|
|
59
|
+
stream: true; // Character-by-character output, stoppable
|
|
58
60
|
}
|
|
59
61
|
```
|
|
60
62
|
|
|
61
63
|
#### Interruptible Normal Mode
|
|
64
|
+
|
|
62
65
|
```typescript
|
|
63
66
|
{
|
|
64
|
-
stream: false
|
|
67
|
+
stream: false; // One-time return, stoppable
|
|
65
68
|
}
|
|
66
69
|
```
|
|
67
70
|
|
|
68
71
|
#### Fast Normal Mode
|
|
72
|
+
|
|
69
73
|
```typescript
|
|
70
74
|
// No options passed, one-time return, non-stoppable
|
|
71
75
|
```
|
|
@@ -73,6 +77,7 @@ Simulates backend API, supports three modes:
|
|
|
73
77
|
### 3. ChatMessageStore (State Management)
|
|
74
78
|
|
|
75
79
|
Manages all message states:
|
|
80
|
+
|
|
76
81
|
- `messages` - History message list
|
|
77
82
|
- `draftMessages` - Draft message list
|
|
78
83
|
- `streaming` - Whether streaming output is in progress
|
|
@@ -104,6 +109,7 @@ export default function ChatMessagePage() {
|
|
|
104
109
|
### Message Styles
|
|
105
110
|
|
|
106
111
|
**User Messages**:
|
|
112
|
+
|
|
107
113
|
- Blue background
|
|
108
114
|
- Right-aligned
|
|
109
115
|
- Max width 80%
|
|
@@ -111,6 +117,7 @@ export default function ChatMessagePage() {
|
|
|
111
117
|
- Has retry button
|
|
112
118
|
|
|
113
119
|
**AI Messages**:
|
|
120
|
+
|
|
114
121
|
- Light background + border
|
|
115
122
|
- Left-aligned
|
|
116
123
|
- Max width 85%
|
|
@@ -132,25 +139,25 @@ export default function ChatMessagePage() {
|
|
|
132
139
|
interface ChatMessageBridgeInterface<T> {
|
|
133
140
|
// Send message
|
|
134
141
|
send(message?: ChatMessage<T>): Promise<ChatMessage<T>>;
|
|
135
|
-
|
|
142
|
+
|
|
136
143
|
// Stop sending
|
|
137
144
|
stop(messageId?: string): boolean;
|
|
138
|
-
|
|
145
|
+
|
|
139
146
|
// Stop all
|
|
140
147
|
stopAll(): void;
|
|
141
|
-
|
|
148
|
+
|
|
142
149
|
// Update content
|
|
143
150
|
onChangeContent(content: T): void;
|
|
144
|
-
|
|
151
|
+
|
|
145
152
|
// Get message store
|
|
146
153
|
getMessageStore(): ChatMessageStore<T>;
|
|
147
|
-
|
|
154
|
+
|
|
148
155
|
// Get first draft message
|
|
149
156
|
getFirstDraftMessage(): ChatMessage<T> | null;
|
|
150
|
-
|
|
157
|
+
|
|
151
158
|
// Get sending message
|
|
152
159
|
getSendingMessage(): ChatMessage<T> | null;
|
|
153
|
-
|
|
160
|
+
|
|
154
161
|
// Is send disabled
|
|
155
162
|
getDisabledSend(): boolean;
|
|
156
163
|
}
|
|
@@ -160,21 +167,18 @@ interface ChatMessageBridgeInterface<T> {
|
|
|
160
167
|
|
|
161
168
|
```typescript
|
|
162
169
|
class MessageApi {
|
|
163
|
-
async sendMessage<M>(
|
|
164
|
-
message: M,
|
|
165
|
-
options?: GatewayOptions<M>
|
|
166
|
-
): Promise<M>;
|
|
170
|
+
async sendMessage<M>(message: M, options?: GatewayOptions<M>): Promise<M>;
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
interface GatewayOptions<M> {
|
|
170
|
-
stream?: boolean;
|
|
171
|
-
signal?: AbortSignal;
|
|
172
|
-
onConnected?: () => void;
|
|
174
|
+
stream?: boolean; // Whether streaming
|
|
175
|
+
signal?: AbortSignal; // Stop signal
|
|
176
|
+
onConnected?: () => void; // Connection success
|
|
173
177
|
onChunk?: (msg: M) => void; // Streaming chunk callback
|
|
174
178
|
onProgress?: (p: number) => void; // Progress callback
|
|
175
|
-
onComplete?: (msg: M) => void;
|
|
176
|
-
onAborted?: (msg: M) => void;
|
|
177
|
-
onError?: (err: any) => void;
|
|
179
|
+
onComplete?: (msg: M) => void; // Completion callback
|
|
180
|
+
onAborted?: (msg: M) => void; // Stop callback
|
|
181
|
+
onError?: (err: any) => void; // Error callback
|
|
178
182
|
}
|
|
179
183
|
```
|
|
180
184
|
|
|
@@ -189,8 +193,8 @@ const [bridge] = useState(() => {
|
|
|
189
193
|
gateway: messageApi,
|
|
190
194
|
logger: logger,
|
|
191
195
|
senderName: 'ChatSender',
|
|
192
|
-
gatewayOptions: {
|
|
193
|
-
stream: true
|
|
196
|
+
gatewayOptions: {
|
|
197
|
+
stream: true // Change to false for normal mode
|
|
194
198
|
}
|
|
195
199
|
}).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
|
|
196
200
|
});
|
|
@@ -199,8 +203,8 @@ const [bridge] = useState(() => {
|
|
|
199
203
|
### 2. Custom Message Component
|
|
200
204
|
|
|
201
205
|
```typescript
|
|
202
|
-
<MessagesList
|
|
203
|
-
bridge={bridge}
|
|
206
|
+
<MessagesList
|
|
207
|
+
bridge={bridge}
|
|
204
208
|
getMessageComponent={(props) => CustomMessageItem}
|
|
205
209
|
/>
|
|
206
210
|
```
|
|
@@ -217,13 +221,13 @@ async sendMessage<M>(message: M, options?: GatewayOptions<M>): Promise<M> {
|
|
|
217
221
|
body: JSON.stringify(message),
|
|
218
222
|
signal: options?.signal
|
|
219
223
|
});
|
|
220
|
-
|
|
224
|
+
|
|
221
225
|
// Handle streaming response
|
|
222
226
|
if (options?.stream) {
|
|
223
227
|
const reader = response.body?.getReader();
|
|
224
228
|
// ... process streaming data
|
|
225
229
|
}
|
|
226
|
-
|
|
230
|
+
|
|
227
231
|
return response.json();
|
|
228
232
|
}
|
|
229
233
|
```
|
|
@@ -233,6 +237,7 @@ async sendMessage<M>(message: M, options?: GatewayOptions<M>): Promise<M> {
|
|
|
233
237
|
### Test Features
|
|
234
238
|
|
|
235
239
|
**Normal Messages**:
|
|
240
|
+
|
|
236
241
|
```
|
|
237
242
|
Hello
|
|
238
243
|
你好
|
|
@@ -240,6 +245,7 @@ Test message
|
|
|
240
245
|
```
|
|
241
246
|
|
|
242
247
|
**Trigger Errors**:
|
|
248
|
+
|
|
243
249
|
```
|
|
244
250
|
error
|
|
245
251
|
Failed
|
|
@@ -247,6 +253,7 @@ test error
|
|
|
247
253
|
```
|
|
248
254
|
|
|
249
255
|
**See Streaming Effect**:
|
|
256
|
+
|
|
250
257
|
- Send any message
|
|
251
258
|
- Watch character-by-character output
|
|
252
259
|
- Click stop button to test interruption
|
|
@@ -277,13 +284,13 @@ MessageSender → MessageApi
|
|
|
277
284
|
↓
|
|
278
285
|
[Streaming Mode]
|
|
279
286
|
onConnected → onChunk(word-by-word) → onComplete
|
|
280
|
-
|
|
287
|
+
|
|
281
288
|
[Normal Mode]
|
|
282
289
|
onConnected → onComplete
|
|
283
|
-
|
|
290
|
+
|
|
284
291
|
[Error]
|
|
285
292
|
onError
|
|
286
|
-
|
|
293
|
+
|
|
287
294
|
[Stop]
|
|
288
295
|
onAborted
|
|
289
296
|
↓
|
|
@@ -311,4 +318,3 @@ UI Auto-updates
|
|
|
311
318
|
## 🎉 Summary
|
|
312
319
|
|
|
313
320
|
ChatMessage is a fully-featured, elegantly designed chat component system, ready to use out of the box, supporting streaming output, error handling, state management, and other core features. Can be used directly in production or extended and customized as needed.
|
|
314
|
-
|
|
@@ -11,12 +11,14 @@ Refactored ChatMessage from a standalone page to a reusable component, integrate
|
|
|
11
11
|
**File:** `src/uikit/components/chatMessage/ChatRoot.tsx`
|
|
12
12
|
|
|
13
13
|
**Changes:**
|
|
14
|
+
|
|
14
15
|
- Removed internal creation of `ChatMessageStore`, `MessageApi`, and `ChatMessageBridge`
|
|
15
16
|
- Changed to accept `bridge` and `tt` (internationalization object) as props
|
|
16
17
|
- Added `ChatRootProps` interface definition
|
|
17
18
|
- Removed internal `useI18nInterface` call
|
|
18
19
|
|
|
19
20
|
**Before:**
|
|
21
|
+
|
|
20
22
|
```typescript
|
|
21
23
|
export function ChatRoot() {
|
|
22
24
|
const messagesStore = useFactory(ChatMessageStore<string>);
|
|
@@ -29,7 +31,7 @@ export function ChatRoot() {
|
|
|
29
31
|
gatewayOptions: { stream: true }
|
|
30
32
|
}).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
|
|
31
33
|
});
|
|
32
|
-
|
|
34
|
+
|
|
33
35
|
return (
|
|
34
36
|
<div data-testid="ChatRoot">
|
|
35
37
|
<MessagesList bridge={bridge} />
|
|
@@ -40,6 +42,7 @@ export function ChatRoot() {
|
|
|
40
42
|
```
|
|
41
43
|
|
|
42
44
|
**After:**
|
|
45
|
+
|
|
43
46
|
```typescript
|
|
44
47
|
export interface ChatRootProps {
|
|
45
48
|
bridge: ChatMessageBridge<string>;
|
|
@@ -61,12 +64,14 @@ export function ChatRoot({ bridge, tt }: ChatRootProps) {
|
|
|
61
64
|
**File:** `src/pages/base/MessagePage.tsx`
|
|
62
65
|
|
|
63
66
|
**Changes:**
|
|
67
|
+
|
|
64
68
|
- Use `useI18nInterface` to get the internationalization object `tt` in MessagePage
|
|
65
69
|
- Create `ChatMessageStore`, `MessageApi`, and `ChatMessageBridge` in MessagePage
|
|
66
70
|
- Pass both `bridge` and `tt` to `ChatRoot` component via props
|
|
67
71
|
- Also integrated the `MessageBaseList` component
|
|
68
72
|
|
|
69
73
|
**Implementation:**
|
|
74
|
+
|
|
70
75
|
```typescript
|
|
71
76
|
import { useFactory } from '@brain-toolkit/react-kit';
|
|
72
77
|
import { chatMessageI18n } from '@config/i18n/chatMessageI18n';
|
|
@@ -112,11 +117,13 @@ export default function MessagePage() {
|
|
|
112
117
|
### 3. Child Component Refactoring (MessagesList, FocusBar, MessageItem)
|
|
113
118
|
|
|
114
119
|
**Changes:**
|
|
120
|
+
|
|
115
121
|
- Removed internal `useI18nInterface` calls from all child components
|
|
116
122
|
- Changed to accept `tt` parameter via props
|
|
117
123
|
- Updated Props interface definitions for each component
|
|
118
124
|
|
|
119
125
|
**Example - MessagesList:**
|
|
126
|
+
|
|
120
127
|
```typescript
|
|
121
128
|
// Before
|
|
122
129
|
export function MessagesList({ bridge, ... }: MessagesListProps) {
|
|
@@ -139,37 +146,44 @@ export function MessagesList({ bridge, tt, ... }: MessagesListProps) {
|
|
|
139
146
|
### 4. Removed Standalone ChatMessagePage
|
|
140
147
|
|
|
141
148
|
**Deleted Files:**
|
|
149
|
+
|
|
142
150
|
- `src/pages/base/ChatMessagePage.tsx`
|
|
143
151
|
- `config/Identifier/pages/page.chat.ts`
|
|
144
152
|
- `config/i18n/chatI18n.ts`
|
|
145
153
|
|
|
146
154
|
**Updated Files:**
|
|
155
|
+
|
|
147
156
|
- `config/app.router.ts` - Removed `/chat` route configuration
|
|
148
157
|
- `config/Identifier/pages/index.ts` - Removed `page.chat` export
|
|
149
158
|
|
|
150
159
|
## Advantages of Refactoring
|
|
151
160
|
|
|
152
161
|
### 1. Improved Component Reusability
|
|
162
|
+
|
|
153
163
|
- `ChatRoot` is now a pure presentational component that can be used anywhere
|
|
154
164
|
- Creation and configuration of `bridge` and `tt` are controlled by parent component for better flexibility
|
|
155
165
|
- Parent component can customize internationalization content, supporting different language environments
|
|
156
166
|
|
|
157
167
|
### 2. Simplified Routing Structure
|
|
168
|
+
|
|
158
169
|
- Reduced unnecessary routing layers
|
|
159
170
|
- Directly integrated chat functionality into message page, aligning with business logic
|
|
160
171
|
|
|
161
172
|
### 3. Better Separation of Concerns
|
|
173
|
+
|
|
162
174
|
- `ChatRoot` and its child components focus only on UI presentation
|
|
163
175
|
- Business logic (store, api, bridge) is managed at the page level
|
|
164
176
|
- Internationalization configuration is centrally managed at the page level
|
|
165
177
|
- Easier to test and maintain
|
|
166
178
|
|
|
167
179
|
### 4. Reduced Boilerplate
|
|
180
|
+
|
|
168
181
|
- No need to create a separate page for chat functionality
|
|
169
182
|
- No need to create separate i18n configuration for the page
|
|
170
183
|
- Child components don't need to repeatedly call `useI18nInterface`
|
|
171
184
|
|
|
172
185
|
### 5. Performance Improvement
|
|
186
|
+
|
|
173
187
|
- Reduced number of hook calls (multiple child components share the same `tt` object)
|
|
174
188
|
- Avoided redundant internationalization configuration parsing
|
|
175
189
|
|
|
@@ -197,7 +211,7 @@ import { MessageApi } from '@/uikit/components/chatMessage/MessageApi';
|
|
|
197
211
|
function MyCustomChatPage() {
|
|
198
212
|
// Get internationalization object
|
|
199
213
|
const tt = useI18nInterface(chatMessageI18n);
|
|
200
|
-
|
|
214
|
+
|
|
201
215
|
const messagesStore = useFactory(ChatMessageStore<string>);
|
|
202
216
|
const messageApi = useFactory(MessageApi, messagesStore);
|
|
203
217
|
|
|
@@ -206,7 +220,7 @@ function MyCustomChatPage() {
|
|
|
206
220
|
gateway: messageApi,
|
|
207
221
|
logger: logger,
|
|
208
222
|
senderName: 'MyCustomSender',
|
|
209
|
-
gatewayOptions: {
|
|
223
|
+
gatewayOptions: {
|
|
210
224
|
stream: true,
|
|
211
225
|
// Can customize other options
|
|
212
226
|
}
|
|
@@ -241,7 +255,7 @@ const customI18n: ChatMessageI18nInterface = {
|
|
|
241
255
|
function MyCustomChatPage() {
|
|
242
256
|
const tt = useI18nInterface(customI18n);
|
|
243
257
|
// ... other logic
|
|
244
|
-
|
|
258
|
+
|
|
245
259
|
return <ChatRoot bridge={bridge} tt={tt} />;
|
|
246
260
|
}
|
|
247
261
|
```
|
|
@@ -267,4 +281,3 @@ function MyCustomChatPage() {
|
|
|
267
281
|
- [ChatMessage Component Documentation](./chat-message-component.md)
|
|
268
282
|
- [MessagePage Simplification Guide](./message-page-简化说明.md)
|
|
269
283
|
- [Development Guide](./development-guide.md)
|
|
270
|
-
|
|
@@ -52,17 +52,17 @@ export default function MessagePage() {
|
|
|
52
52
|
|
|
53
53
|
### Supported Text
|
|
54
54
|
|
|
55
|
-
| Text Item
|
|
56
|
-
|
|
57
|
-
| Title
|
|
58
|
-
| Description
|
|
59
|
-
| Empty State
|
|
60
|
-
| User Label
|
|
61
|
-
| Gateway Label
|
|
62
|
-
| Processing
|
|
63
|
-
| Failed Label
|
|
64
|
-
| Gateway Response | 网关响应
|
|
65
|
-
| Send Button
|
|
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
66
|
|
|
67
67
|
## 🧪 Testing Features
|
|
68
68
|
|
|
@@ -169,4 +169,3 @@ Possible feature expansion directions:
|
|
|
169
169
|
## 🎉 Summary
|
|
170
170
|
|
|
171
171
|
`MessageBaseList` is a fully-featured, beautifully styled message component with complete internationalization support, perfect for testing and demonstrating message gateway functionality.
|
|
172
|
-
|
|
@@ -158,9 +158,7 @@ apiAdapter.usePlugin(new ApiMockPlugin(mockDataJson, logger));
|
|
|
158
158
|
|
|
159
159
|
```typescript
|
|
160
160
|
@injectable()
|
|
161
|
-
export class RequestLogger
|
|
162
|
-
implements ExecutorPlugin<RequestAdapterFetchConfig>
|
|
163
|
-
{
|
|
161
|
+
export class RequestLogger implements ExecutorPlugin<RequestAdapterFetchConfig> {
|
|
164
162
|
readonly pluginName = 'RequestLogger';
|
|
165
163
|
|
|
166
164
|
onBefore(context) {
|
|
@@ -42,6 +42,7 @@ src/pages/base/
|
|
|
42
42
|
### 1. ChatMessageBridge(桥接层)
|
|
43
43
|
|
|
44
44
|
连接 UI 和数据层的桥梁,处理:
|
|
45
|
+
|
|
45
46
|
- 消息发送逻辑
|
|
46
47
|
- 草稿管理
|
|
47
48
|
- 状态控制
|
|
@@ -52,20 +53,23 @@ src/pages/base/
|
|
|
52
53
|
模拟后端 API,支持三种模式:
|
|
53
54
|
|
|
54
55
|
#### 流式模式 (stream: true)
|
|
56
|
+
|
|
55
57
|
```typescript
|
|
56
58
|
{
|
|
57
|
-
stream: true
|
|
59
|
+
stream: true; // 逐字输出,可停止
|
|
58
60
|
}
|
|
59
61
|
```
|
|
60
62
|
|
|
61
63
|
#### 可中断普通模式
|
|
64
|
+
|
|
62
65
|
```typescript
|
|
63
66
|
{
|
|
64
|
-
stream: false
|
|
67
|
+
stream: false; // 一次性返回,可停止
|
|
65
68
|
}
|
|
66
69
|
```
|
|
67
70
|
|
|
68
71
|
#### 快速普通模式
|
|
72
|
+
|
|
69
73
|
```typescript
|
|
70
74
|
// 不传 options,一次性返回,不可停止
|
|
71
75
|
```
|
|
@@ -73,6 +77,7 @@ src/pages/base/
|
|
|
73
77
|
### 3. ChatMessageStore(状态管理)
|
|
74
78
|
|
|
75
79
|
管理所有消息状态:
|
|
80
|
+
|
|
76
81
|
- `messages` - 历史消息列表
|
|
77
82
|
- `draftMessages` - 草稿消息列表
|
|
78
83
|
- `streaming` - 是否正在流式输出
|
|
@@ -104,6 +109,7 @@ export default function ChatMessagePage() {
|
|
|
104
109
|
### 消息样式
|
|
105
110
|
|
|
106
111
|
**用户消息**:
|
|
112
|
+
|
|
107
113
|
- 蓝色背景
|
|
108
114
|
- 右对齐
|
|
109
115
|
- 最大宽度 80%
|
|
@@ -111,6 +117,7 @@ export default function ChatMessagePage() {
|
|
|
111
117
|
- 带重试按钮
|
|
112
118
|
|
|
113
119
|
**AI 消息**:
|
|
120
|
+
|
|
114
121
|
- 浅色背景 + 边框
|
|
115
122
|
- 左对齐
|
|
116
123
|
- 最大宽度 85%
|
|
@@ -132,25 +139,25 @@ export default function ChatMessagePage() {
|
|
|
132
139
|
interface ChatMessageBridgeInterface<T> {
|
|
133
140
|
// 发送消息
|
|
134
141
|
send(message?: ChatMessage<T>): Promise<ChatMessage<T>>;
|
|
135
|
-
|
|
142
|
+
|
|
136
143
|
// 停止发送
|
|
137
144
|
stop(messageId?: string): boolean;
|
|
138
|
-
|
|
145
|
+
|
|
139
146
|
// 停止所有
|
|
140
147
|
stopAll(): void;
|
|
141
|
-
|
|
148
|
+
|
|
142
149
|
// 更新内容
|
|
143
150
|
onChangeContent(content: T): void;
|
|
144
|
-
|
|
151
|
+
|
|
145
152
|
// 获取消息存储
|
|
146
153
|
getMessageStore(): ChatMessageStore<T>;
|
|
147
|
-
|
|
154
|
+
|
|
148
155
|
// 获取第一个草稿消息
|
|
149
156
|
getFirstDraftMessage(): ChatMessage<T> | null;
|
|
150
|
-
|
|
157
|
+
|
|
151
158
|
// 获取正在发送的消息
|
|
152
159
|
getSendingMessage(): ChatMessage<T> | null;
|
|
153
|
-
|
|
160
|
+
|
|
154
161
|
// 是否禁用发送
|
|
155
162
|
getDisabledSend(): boolean;
|
|
156
163
|
}
|
|
@@ -160,21 +167,18 @@ interface ChatMessageBridgeInterface<T> {
|
|
|
160
167
|
|
|
161
168
|
```typescript
|
|
162
169
|
class MessageApi {
|
|
163
|
-
async sendMessage<M>(
|
|
164
|
-
message: M,
|
|
165
|
-
options?: GatewayOptions<M>
|
|
166
|
-
): Promise<M>;
|
|
170
|
+
async sendMessage<M>(message: M, options?: GatewayOptions<M>): Promise<M>;
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
interface GatewayOptions<M> {
|
|
170
|
-
stream?: boolean;
|
|
171
|
-
signal?: AbortSignal;
|
|
172
|
-
onConnected?: () => void;
|
|
174
|
+
stream?: boolean; // 是否流式
|
|
175
|
+
signal?: AbortSignal; // 停止信号
|
|
176
|
+
onConnected?: () => void; // 连接成功
|
|
173
177
|
onChunk?: (msg: M) => void; // 流式块回调
|
|
174
178
|
onProgress?: (p: number) => void; // 进度回调
|
|
175
|
-
onComplete?: (msg: M) => void;
|
|
176
|
-
onAborted?: (msg: M) => void;
|
|
177
|
-
onError?: (err: any) => void;
|
|
179
|
+
onComplete?: (msg: M) => void; // 完成回调
|
|
180
|
+
onAborted?: (msg: M) => void; // 停止回调
|
|
181
|
+
onError?: (err: any) => void; // 错误回调
|
|
178
182
|
}
|
|
179
183
|
```
|
|
180
184
|
|
|
@@ -189,8 +193,8 @@ const [bridge] = useState(() => {
|
|
|
189
193
|
gateway: messageApi,
|
|
190
194
|
logger: logger,
|
|
191
195
|
senderName: 'ChatSender',
|
|
192
|
-
gatewayOptions: {
|
|
193
|
-
stream: true
|
|
196
|
+
gatewayOptions: {
|
|
197
|
+
stream: true // 改为 false 使用普通模式
|
|
194
198
|
}
|
|
195
199
|
}).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
|
|
196
200
|
});
|
|
@@ -199,8 +203,8 @@ const [bridge] = useState(() => {
|
|
|
199
203
|
### 2. 自定义消息组件
|
|
200
204
|
|
|
201
205
|
```typescript
|
|
202
|
-
<MessagesList
|
|
203
|
-
bridge={bridge}
|
|
206
|
+
<MessagesList
|
|
207
|
+
bridge={bridge}
|
|
204
208
|
getMessageComponent={(props) => CustomMessageItem}
|
|
205
209
|
/>
|
|
206
210
|
```
|
|
@@ -217,13 +221,13 @@ async sendMessage<M>(message: M, options?: GatewayOptions<M>): Promise<M> {
|
|
|
217
221
|
body: JSON.stringify(message),
|
|
218
222
|
signal: options?.signal
|
|
219
223
|
});
|
|
220
|
-
|
|
224
|
+
|
|
221
225
|
// 处理流式响应
|
|
222
226
|
if (options?.stream) {
|
|
223
227
|
const reader = response.body?.getReader();
|
|
224
228
|
// ... 处理流式数据
|
|
225
229
|
}
|
|
226
|
-
|
|
230
|
+
|
|
227
231
|
return response.json();
|
|
228
232
|
}
|
|
229
233
|
```
|
|
@@ -233,6 +237,7 @@ async sendMessage<M>(message: M, options?: GatewayOptions<M>): Promise<M> {
|
|
|
233
237
|
### 测试功能
|
|
234
238
|
|
|
235
239
|
**正常消息**:
|
|
240
|
+
|
|
236
241
|
```
|
|
237
242
|
Hello
|
|
238
243
|
你好
|
|
@@ -240,6 +245,7 @@ Hello
|
|
|
240
245
|
```
|
|
241
246
|
|
|
242
247
|
**触发错误**:
|
|
248
|
+
|
|
243
249
|
```
|
|
244
250
|
error
|
|
245
251
|
Failed
|
|
@@ -247,6 +253,7 @@ test error
|
|
|
247
253
|
```
|
|
248
254
|
|
|
249
255
|
**查看流式效果**:
|
|
256
|
+
|
|
250
257
|
- 发送任意消息
|
|
251
258
|
- 观察逐字输出效果
|
|
252
259
|
- 点击停止按钮测试中断
|
|
@@ -277,13 +284,13 @@ MessageSender → MessageApi
|
|
|
277
284
|
↓
|
|
278
285
|
[流式模式]
|
|
279
286
|
onConnected → onChunk(逐字) → onComplete
|
|
280
|
-
|
|
287
|
+
|
|
281
288
|
[普通模式]
|
|
282
289
|
onConnected → onComplete
|
|
283
|
-
|
|
290
|
+
|
|
284
291
|
[错误]
|
|
285
292
|
onError
|
|
286
|
-
|
|
293
|
+
|
|
287
294
|
[停止]
|
|
288
295
|
onAborted
|
|
289
296
|
↓
|
|
@@ -311,4 +318,3 @@ UI 自动更新
|
|
|
311
318
|
## 🎉 总结
|
|
312
319
|
|
|
313
320
|
ChatMessage 是一个功能完整、设计优雅的聊天组件系统,开箱即用,支持流式输出、错误处理、状态管理等核心功能。可以直接用于生产环境,也可以根据需要进行扩展和定制。
|
|
314
|
-
|