@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.
Files changed (33) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/configs/_common/.github/workflows/general-check.yml +1 -1
  3. package/dist/configs/_common/.github/workflows/release.yml +2 -2
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/templates/react-app/__tests__/src/uikit/components/chatMessage/ChatRoot.test.tsx +274 -0
  7. package/dist/templates/react-app/config/IOCIdentifier.ts +3 -0
  8. package/dist/templates/react-app/config/Identifier/components/component.chatMessage.ts +56 -0
  9. package/dist/templates/react-app/config/Identifier/components/component.messageBaseList.ts +103 -0
  10. package/dist/templates/react-app/config/Identifier/pages/index.ts +1 -0
  11. package/dist/templates/react-app/config/Identifier/pages/page.message.ts +20 -0
  12. package/dist/templates/react-app/config/app.router.ts +23 -0
  13. package/dist/templates/react-app/config/i18n/chatMessageI18n.ts +17 -0
  14. package/dist/templates/react-app/config/i18n/messageBaseListI18n.ts +22 -0
  15. package/dist/templates/react-app/config/i18n/messageI18n.ts +14 -0
  16. package/dist/templates/react-app/docs/en/components/chat-message-component.md +314 -0
  17. package/dist/templates/react-app/docs/en/components/chat-message-refactor.md +270 -0
  18. package/dist/templates/react-app/docs/en/components/message-base-list-component.md +172 -0
  19. package/dist/templates/react-app/docs/zh/components/chat-message-component.md +314 -0
  20. package/dist/templates/react-app/docs/zh/components/chat-message-refactor.md +270 -0
  21. package/dist/templates/react-app/docs/zh/components/message-base-list-component.md +172 -0
  22. package/dist/templates/react-app/playwright.config.ts +6 -6
  23. package/dist/templates/react-app/public/locales/en/common.json +44 -1
  24. package/dist/templates/react-app/public/locales/zh/common.json +44 -1
  25. package/dist/templates/react-app/src/pages/base/MessagePage.tsx +40 -0
  26. package/dist/templates/react-app/src/uikit/components/MessageBaseList.tsx +240 -0
  27. package/dist/templates/react-app/src/uikit/components/chatMessage/ChatMessageBridge.ts +176 -0
  28. package/dist/templates/react-app/src/uikit/components/chatMessage/ChatRoot.tsx +21 -0
  29. package/dist/templates/react-app/src/uikit/components/chatMessage/FocusBar.tsx +106 -0
  30. package/dist/templates/react-app/src/uikit/components/chatMessage/MessageApi.ts +271 -0
  31. package/dist/templates/react-app/src/uikit/components/chatMessage/MessageItem.tsx +102 -0
  32. package/dist/templates/react-app/src/uikit/components/chatMessage/MessagesList.tsx +86 -0
  33. package/package.json +1 -1
@@ -0,0 +1,17 @@
1
+ import * as i18nKeys from '../Identifier/components/component.chatMessage';
2
+
3
+ /**
4
+ * ChatMessage component i18n interface
5
+ */
6
+ export type ChatMessageI18nInterface = typeof chatMessageI18n;
7
+
8
+ export const chatMessageI18n = Object.freeze({
9
+ send: i18nKeys.COMPONENT_CHAT_SEND,
10
+ stop: i18nKeys.COMPONENT_CHAT_STOP,
11
+ loading: i18nKeys.COMPONENT_CHAT_LOADING,
12
+ inputPlaceholder: i18nKeys.COMPONENT_CHAT_INPUT_PLACEHOLDER,
13
+ empty: i18nKeys.COMPONENT_CHAT_EMPTY,
14
+ start: i18nKeys.COMPONENT_CHAT_START,
15
+ retry: i18nKeys.COMPONENT_CHAT_RETRY,
16
+ duration: i18nKeys.COMPONENT_CHAT_DURATION
17
+ });
@@ -0,0 +1,22 @@
1
+ import * as i18nKeys from '../Identifier/components/component.messageBaseList';
2
+
3
+ /**
4
+ * MessageBaseList component i18n interface
5
+ */
6
+ export type MessageBaseListI18nInterface = typeof messageBaseListI18n;
7
+
8
+ export const messageBaseListI18n = Object.freeze({
9
+ title: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_TITLE,
10
+ description: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_DESCRIPTION,
11
+ noMessages: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_NO_MESSAGES,
12
+ getStarted: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_GET_STARTED,
13
+ user: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_USER,
14
+ gateway: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_GATEWAY,
15
+ processing: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_PROCESSING,
16
+ gatewayFailed: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_GATEWAY_FAILED,
17
+ sendFailed: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_SEND_FAILED,
18
+ gatewayResponse: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_GATEWAY_RESPONSE,
19
+ inputPlaceholder: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_INPUT_PLACEHOLDER,
20
+ sendButton: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_SEND_BUTTON,
21
+ errorTip: i18nKeys.COMPONENT_MESSAGE_BASE_LIST_ERROR_TIP
22
+ });
@@ -0,0 +1,14 @@
1
+ import * as i18nKeys from '../Identifier/pages/page.message';
2
+
3
+ /**
4
+ * Message page i18n interface
5
+ */
6
+ export type MessageI18nInterface = typeof messageI18n;
7
+
8
+ export const messageI18n = Object.freeze({
9
+ // basic meta properties
10
+ title: i18nKeys.PAGE_MESSAGE_TITLE,
11
+ description: i18nKeys.PAGE_MESSAGE_DESCRIPTION,
12
+ content: i18nKeys.PAGE_MESSAGE_DESCRIPTION,
13
+ keywords: i18nKeys.PAGE_MESSAGE_KEYWORDS
14
+ });
@@ -0,0 +1,314 @@
1
+ # ChatMessage Chat Component System
2
+
3
+ ## 📋 Overview
4
+
5
+ ChatMessage is a complete chat component system that supports real-time conversations, streaming output, error handling, and more. Suitable for AI dialogue, customer service chat, and other scenarios.
6
+
7
+ ## ✨ Core Features
8
+
9
+ - ✅ **Streaming Output**: Supports character-by-character AI reply display (like ChatGPT)
10
+ - ✅ **Stop Control**: Can stop message generation at any time
11
+ - ✅ **Retry Mechanism**: Failed messages can be retried with one click
12
+ - ✅ **Draft Management**: Automatically saves draft messages being input
13
+ - ✅ **Loading States**: Clear message sending and receiving states
14
+ - ✅ **Error Handling**: Comprehensive error prompts and handling
15
+ - ✅ **Shortcuts**: Ctrl+Enter for quick send
16
+ - ✅ **Internationalization**: Full Chinese/English support
17
+ - ✅ **Responsive Design**: Adapts to different screen sizes
18
+
19
+ ## 📁 File Structure
20
+
21
+ ```
22
+ src/uikit/components/chatMessage/
23
+ ├── ChatRoot.tsx # Root component (assembles all parts)
24
+ ├── MessagesList.tsx # Message list component
25
+ ├── MessageItem.tsx # Single message item component
26
+ ├── FocusBar.tsx # Input bar component
27
+ ├── ChatMessageBridge.ts # Bridge layer (connects UI and logic)
28
+ └── MessageApi.ts # API layer (mock/real backend)
29
+
30
+ config/
31
+ ├── Identifier/components/component.chatMessage.ts # i18n identifiers
32
+ ├── i18n/chatMessageI18n.ts # Component i18n config
33
+ ├── Identifier/pages/page.chat.ts # Page i18n identifiers
34
+ └── i18n/chatI18n.ts # Page i18n config
35
+
36
+ src/pages/base/
37
+ └── ChatMessagePage.tsx # Chat page
38
+ ```
39
+
40
+ ## đŸŽ¯ Core Concepts
41
+
42
+ ### 1. ChatMessageBridge (Bridge Layer)
43
+
44
+ Bridge connecting UI and data layer, handles:
45
+ - Message sending logic
46
+ - Draft management
47
+ - State control
48
+ - Stop mechanism
49
+
50
+ ### 2. MessageApi (Gateway Layer)
51
+
52
+ Simulates backend API, supports three modes:
53
+
54
+ #### Streaming Mode (stream: true)
55
+ ```typescript
56
+ {
57
+ stream: true // Character-by-character output, stoppable
58
+ }
59
+ ```
60
+
61
+ #### Interruptible Normal Mode
62
+ ```typescript
63
+ {
64
+ stream: false // One-time return, stoppable
65
+ }
66
+ ```
67
+
68
+ #### Fast Normal Mode
69
+ ```typescript
70
+ // No options passed, one-time return, non-stoppable
71
+ ```
72
+
73
+ ### 3. ChatMessageStore (State Management)
74
+
75
+ Manages all message states:
76
+ - `messages` - History message list
77
+ - `draftMessages` - Draft message list
78
+ - `streaming` - Whether streaming output is in progress
79
+ - `disabledSend` - Whether sending is disabled
80
+
81
+ ## 🚀 Usage
82
+
83
+ ### Basic Usage
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
+ ### Access Paths
98
+
99
+ - `/en/chat` - English
100
+ - `/zh/chat` - Chinese
101
+
102
+ ## 🎨 Interface Design
103
+
104
+ ### Message Styles
105
+
106
+ **User Messages**:
107
+ - Blue background
108
+ - Right-aligned
109
+ - Max width 80%
110
+ - Shows duration
111
+ - Has retry button
112
+
113
+ **AI Messages**:
114
+ - Light background + border
115
+ - Left-aligned
116
+ - Max width 85%
117
+ - Supports streaming display
118
+ - Shows loading state
119
+
120
+ ### Input Bar
121
+
122
+ - Auto-adjusts height (2-6 rows)
123
+ - Ctrl+Enter to send
124
+ - Disabled state control
125
+ - Send/Stop button toggle
126
+
127
+ ## 📝 Key APIs
128
+
129
+ ### ChatMessageBridge Methods
130
+
131
+ ```typescript
132
+ interface ChatMessageBridgeInterface<T> {
133
+ // Send message
134
+ send(message?: ChatMessage<T>): Promise<ChatMessage<T>>;
135
+
136
+ // Stop sending
137
+ stop(messageId?: string): boolean;
138
+
139
+ // Stop all
140
+ stopAll(): void;
141
+
142
+ // Update content
143
+ onChangeContent(content: T): void;
144
+
145
+ // Get message store
146
+ getMessageStore(): ChatMessageStore<T>;
147
+
148
+ // Get first draft message
149
+ getFirstDraftMessage(): ChatMessage<T> | null;
150
+
151
+ // Get sending message
152
+ getSendingMessage(): ChatMessage<T> | null;
153
+
154
+ // Is send disabled
155
+ getDisabledSend(): boolean;
156
+ }
157
+ ```
158
+
159
+ ### MessageApi Modes
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; // Whether streaming
171
+ signal?: AbortSignal; // Stop signal
172
+ onConnected?: () => void; // Connection success
173
+ onChunk?: (msg: M) => void; // Streaming chunk callback
174
+ onProgress?: (p: number) => void; // Progress callback
175
+ onComplete?: (msg: M) => void; // Completion callback
176
+ onAborted?: (msg: M) => void; // Stop callback
177
+ onError?: (err: any) => void; // Error callback
178
+ }
179
+ ```
180
+
181
+ ## 🔧 Custom Configuration
182
+
183
+ ### 1. Switch Send Mode
184
+
185
+ ```typescript
186
+ // Modify 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 // Change to false for normal mode
194
+ }
195
+ }).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
196
+ });
197
+ ```
198
+
199
+ ### 2. Custom Message Component
200
+
201
+ ```typescript
202
+ <MessagesList
203
+ bridge={bridge}
204
+ getMessageComponent={(props) => CustomMessageItem}
205
+ />
206
+ ```
207
+
208
+ ### 3. Connect Real API
209
+
210
+ Modify `MessageApi.ts`:
211
+
212
+ ```typescript
213
+ async sendMessage<M>(message: M, options?: GatewayOptions<M>): Promise<M> {
214
+ // Replace with real API call
215
+ const response = await fetch('/api/chat', {
216
+ method: 'POST',
217
+ body: JSON.stringify(message),
218
+ signal: options?.signal
219
+ });
220
+
221
+ // Handle streaming response
222
+ if (options?.stream) {
223
+ const reader = response.body?.getReader();
224
+ // ... process streaming data
225
+ }
226
+
227
+ return response.json();
228
+ }
229
+ ```
230
+
231
+ ## 💡 Usage Tips
232
+
233
+ ### Test Features
234
+
235
+ **Normal Messages**:
236
+ ```
237
+ Hello
238
+ äŊ åĨŊ
239
+ Test message
240
+ ```
241
+
242
+ **Trigger Errors**:
243
+ ```
244
+ error
245
+ Failed
246
+ test error
247
+ ```
248
+
249
+ **See Streaming Effect**:
250
+ - Send any message
251
+ - Watch character-by-character output
252
+ - Click stop button to test interruption
253
+
254
+ ### Shortcuts
255
+
256
+ - `Ctrl + Enter` - Send message
257
+ - Auto-save draft while typing
258
+
259
+ ## đŸŽ¯ Use Cases
260
+
261
+ 1. **AI Dialogue Apps**: ChatGPT-like dialogue interface
262
+ 2. **Customer Service**: Real-time customer service chat
263
+ 3. **Q&A Systems**: Q&A interaction
264
+ 4. **Code Assistant**: Code generation and explanation
265
+ 5. **Teaching Assistant**: Online learning tutoring
266
+
267
+ ## 🔄 Message Flow
268
+
269
+ ```
270
+ User Input → Draft Message
271
+ ↓
272
+ Click Send/Ctrl+Enter
273
+ ↓
274
+ Bridge.send()
275
+ ↓
276
+ MessageSender → MessageApi
277
+ ↓
278
+ [Streaming Mode]
279
+ onConnected → onChunk(word-by-word) → onComplete
280
+
281
+ [Normal Mode]
282
+ onConnected → onComplete
283
+
284
+ [Error]
285
+ onError
286
+
287
+ [Stop]
288
+ onAborted
289
+ ↓
290
+ Update ChatMessageStore
291
+ ↓
292
+ UI Auto-updates
293
+ ```
294
+
295
+ ## 📊 State Management
296
+
297
+ ### Message States
298
+
299
+ - `DRAFT` - Draft
300
+ - `SENDING` - Sending
301
+ - `SENT` - Sent
302
+ - `FAILED` - Failed
303
+ - `STOPPED` - Stopped
304
+
305
+ ### Message Roles
306
+
307
+ - `USER` - User message
308
+ - `ASSISTANT` - AI/Assistant message
309
+ - `SYSTEM` - System message
310
+
311
+ ## 🎉 Summary
312
+
313
+ 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
+
@@ -0,0 +1,270 @@
1
+ # ChatMessage Refactoring Guide
2
+
3
+ ## Refactoring Overview
4
+
5
+ Refactored ChatMessage from a standalone page to a reusable component, integrated into MessagePage. Passed the internationalization object `tt` through props to ensure high component reusability.
6
+
7
+ ## Changes
8
+
9
+ ### 1. ChatRoot Component Refactoring
10
+
11
+ **File:** `src/uikit/components/chatMessage/ChatRoot.tsx`
12
+
13
+ **Changes:**
14
+ - Removed internal creation of `ChatMessageStore`, `MessageApi`, and `ChatMessageBridge`
15
+ - Changed to accept `bridge` and `tt` (internationalization object) as props
16
+ - Added `ChatRootProps` interface definition
17
+ - Removed internal `useI18nInterface` call
18
+
19
+ **Before:**
20
+ ```typescript
21
+ export function ChatRoot() {
22
+ const messagesStore = useFactory(ChatMessageStore<string>);
23
+ const messageApi = useFactory(MessageApi, messagesStore);
24
+ const [bridge] = useState(() => {
25
+ return new ChatMessageBridge<string>(messagesStore, {
26
+ gateway: messageApi,
27
+ logger: logger,
28
+ senderName: 'ChatSender',
29
+ gatewayOptions: { stream: true }
30
+ }).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
31
+ });
32
+
33
+ return (
34
+ <div data-testid="ChatRoot">
35
+ <MessagesList bridge={bridge} />
36
+ <FocusBar bridge={bridge} />
37
+ </div>
38
+ );
39
+ }
40
+ ```
41
+
42
+ **After:**
43
+ ```typescript
44
+ export interface ChatRootProps {
45
+ bridge: ChatMessageBridge<string>;
46
+ tt: ChatMessageI18nInterface;
47
+ }
48
+
49
+ export function ChatRoot({ bridge, tt }: ChatRootProps) {
50
+ return (
51
+ <div data-testid="ChatRoot">
52
+ <MessagesList bridge={bridge} tt={tt} />
53
+ <FocusBar bridge={bridge} tt={tt} />
54
+ </div>
55
+ );
56
+ }
57
+ ```
58
+
59
+ ### 2. Integrating ChatRoot into MessagePage
60
+
61
+ **File:** `src/pages/base/MessagePage.tsx`
62
+
63
+ **Changes:**
64
+ - Use `useI18nInterface` to get the internationalization object `tt` in MessagePage
65
+ - Create `ChatMessageStore`, `MessageApi`, and `ChatMessageBridge` in MessagePage
66
+ - Pass both `bridge` and `tt` to `ChatRoot` component via props
67
+ - Also integrated the `MessageBaseList` component
68
+
69
+ **Implementation:**
70
+ ```typescript
71
+ import { useFactory } from '@brain-toolkit/react-kit';
72
+ import { chatMessageI18n } from '@config/i18n/chatMessageI18n';
73
+ import {
74
+ ChatMessageStore,
75
+ ChatSenderStrategy,
76
+ SendFailureStrategy
77
+ } from '@qlover/corekit-bridge';
78
+ import { useState } from 'react';
79
+ import { logger } from '@/core/globals';
80
+ import { ChatMessageBridge } from '@/uikit/components/chatMessage/ChatMessageBridge';
81
+ import { ChatRoot } from '@/uikit/components/chatMessage/ChatRoot';
82
+ import { MessageApi } from '@/uikit/components/chatMessage/MessageApi';
83
+ import { MessageBaseList } from '@/uikit/components/MessageBaseList';
84
+ import { useI18nInterface } from '@/uikit/hooks/useI18nInterface';
85
+
86
+ export default function MessagePage() {
87
+ const tt = useI18nInterface(chatMessageI18n);
88
+ const messagesStore = useFactory(ChatMessageStore<string>);
89
+ const messageApi = useFactory(MessageApi, messagesStore);
90
+
91
+ const [bridge] = useState(() => {
92
+ return new ChatMessageBridge<string>(messagesStore, {
93
+ gateway: messageApi,
94
+ logger: logger,
95
+ senderName: 'ChatSender',
96
+ gatewayOptions: { stream: true }
97
+ }).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
98
+ });
99
+
100
+ return (
101
+ <div
102
+ data-testid="MessagePage"
103
+ className="min-h-screen bg-primary py-8 px-4 sm:px-6 lg:px-8"
104
+ >
105
+ <MessageBaseList />
106
+ <ChatRoot bridge={bridge} tt={tt} />
107
+ </div>
108
+ );
109
+ }
110
+ ```
111
+
112
+ ### 3. Child Component Refactoring (MessagesList, FocusBar, MessageItem)
113
+
114
+ **Changes:**
115
+ - Removed internal `useI18nInterface` calls from all child components
116
+ - Changed to accept `tt` parameter via props
117
+ - Updated Props interface definitions for each component
118
+
119
+ **Example - MessagesList:**
120
+ ```typescript
121
+ // Before
122
+ export function MessagesList({ bridge, ... }: MessagesListProps) {
123
+ const tt = useI18nInterface(chatMessageI18n);
124
+ // ...
125
+ }
126
+
127
+ // After
128
+ export interface MessagesListProps {
129
+ bridge: ChatMessageBridgeInterface<T>;
130
+ tt: ChatMessageI18nInterface;
131
+ // ...
132
+ }
133
+
134
+ export function MessagesList({ bridge, tt, ... }: MessagesListProps) {
135
+ // Use the passed tt directly
136
+ }
137
+ ```
138
+
139
+ ### 4. Removed Standalone ChatMessagePage
140
+
141
+ **Deleted Files:**
142
+ - `src/pages/base/ChatMessagePage.tsx`
143
+ - `config/Identifier/pages/page.chat.ts`
144
+ - `config/i18n/chatI18n.ts`
145
+
146
+ **Updated Files:**
147
+ - `config/app.router.ts` - Removed `/chat` route configuration
148
+ - `config/Identifier/pages/index.ts` - Removed `page.chat` export
149
+
150
+ ## Advantages of Refactoring
151
+
152
+ ### 1. Improved Component Reusability
153
+ - `ChatRoot` is now a pure presentational component that can be used anywhere
154
+ - Creation and configuration of `bridge` and `tt` are controlled by parent component for better flexibility
155
+ - Parent component can customize internationalization content, supporting different language environments
156
+
157
+ ### 2. Simplified Routing Structure
158
+ - Reduced unnecessary routing layers
159
+ - Directly integrated chat functionality into message page, aligning with business logic
160
+
161
+ ### 3. Better Separation of Concerns
162
+ - `ChatRoot` and its child components focus only on UI presentation
163
+ - Business logic (store, api, bridge) is managed at the page level
164
+ - Internationalization configuration is centrally managed at the page level
165
+ - Easier to test and maintain
166
+
167
+ ### 4. Reduced Boilerplate
168
+ - No need to create a separate page for chat functionality
169
+ - No need to create separate i18n configuration for the page
170
+ - Child components don't need to repeatedly call `useI18nInterface`
171
+
172
+ ### 5. Performance Improvement
173
+ - Reduced number of hook calls (multiple child components share the same `tt` object)
174
+ - Avoided redundant internationalization configuration parsing
175
+
176
+ ## Usage Example
177
+
178
+ ### Basic Usage
179
+
180
+ If you need to use `ChatRoot` elsewhere:
181
+
182
+ ```typescript
183
+ import { useFactory } from '@brain-toolkit/react-kit';
184
+ import { chatMessageI18n } from '@config/i18n/chatMessageI18n';
185
+ import {
186
+ ChatMessageStore,
187
+ ChatSenderStrategy,
188
+ SendFailureStrategy
189
+ } from '@qlover/corekit-bridge';
190
+ import { useState } from 'react';
191
+ import { logger } from '@/core/globals';
192
+ import { useI18nInterface } from '@/uikit/hooks/useI18nInterface';
193
+ import { ChatMessageBridge } from '@/uikit/components/chatMessage/ChatMessageBridge';
194
+ import { ChatRoot } from '@/uikit/components/chatMessage/ChatRoot';
195
+ import { MessageApi } from '@/uikit/components/chatMessage/MessageApi';
196
+
197
+ function MyCustomChatPage() {
198
+ // Get internationalization object
199
+ const tt = useI18nInterface(chatMessageI18n);
200
+
201
+ const messagesStore = useFactory(ChatMessageStore<string>);
202
+ const messageApi = useFactory(MessageApi, messagesStore);
203
+
204
+ const [bridge] = useState(() => {
205
+ return new ChatMessageBridge<string>(messagesStore, {
206
+ gateway: messageApi,
207
+ logger: logger,
208
+ senderName: 'MyCustomSender',
209
+ gatewayOptions: {
210
+ stream: true,
211
+ // Can customize other options
212
+ }
213
+ }).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
214
+ });
215
+
216
+ return (
217
+ <div>
218
+ <h1>My Custom Chat</h1>
219
+ <ChatRoot bridge={bridge} tt={tt} />
220
+ </div>
221
+ );
222
+ }
223
+ ```
224
+
225
+ ### Custom Internationalization
226
+
227
+ If you need to use custom internationalization configuration:
228
+
229
+ ```typescript
230
+ import { useState } from 'react';
231
+ import type { ChatMessageI18nInterface } from '@config/i18n/chatMessageI18n';
232
+
233
+ // Custom internationalization object
234
+ const customI18n: ChatMessageI18nInterface = {
235
+ title: 'custom.chat.title',
236
+ empty: 'custom.chat.empty',
237
+ start: 'custom.chat.start',
238
+ // ... other configurations
239
+ };
240
+
241
+ function MyCustomChatPage() {
242
+ const tt = useI18nInterface(customI18n);
243
+ // ... other logic
244
+
245
+ return <ChatRoot bridge={bridge} tt={tt} />;
246
+ }
247
+ ```
248
+
249
+ ## Notes
250
+
251
+ 1. `ChatRoot` component requires two required parameters via props:
252
+ - `bridge`: `ChatMessageBridge` instance
253
+ - `tt`: `ChatMessageI18nInterface` internationalization object
254
+
255
+ 2. Creation and configuration of `bridge` should be done in the parent component
256
+
257
+ 3. Ensure `bridge` is created using `useState` to avoid re-initialization
258
+
259
+ 4. Internationalization object `tt` should be obtained using `useI18nInterface` in the parent component, then passed to `ChatRoot`
260
+
261
+ 5. All child components (`MessagesList`, `FocusBar`, `MessageItem`) used by `ChatRoot` receive both `bridge` and `tt` via props
262
+
263
+ 6. All child components no longer call `useI18nInterface` themselves, but use the `tt` passed from the parent component
264
+
265
+ ## Related Documentation
266
+
267
+ - [ChatMessage Component Documentation](./chat-message-component.md)
268
+ - [MessagePage Simplification Guide](./message-page-įŽ€åŒ–č¯´æ˜Ž.md)
269
+ - [Development Guide](./development-guide.md)
270
+