MateChat UI Library
repository·dev·Indexed 41 days ago
https://github.com/devcloudfe/matechatA UI library for intelligent, AI-driven frontend scenarios, providing ready-to-use components for chat interfaces and AI assistants. Used in production by Huawei's CodeArts and InsCode AI IDE, it supports Vue 3 and Angular through a Foundation + Adapter design pattern. Includes components such as McBubble, McLayout, and McInput, with built-in support for LLM service integration (e.g., OpenAI) and streaming responses.
What's inside MateChat
- MateChat implements theming based on vue-devui theming. You can customize the visual appearance of the components using the same mechanisms provided by vue-devui.
Control prompt detail levels
devThe level of detail shown for each prompt is determined by the properties present in the prompt object within the
listarray:- Full Detail: Includes
labelanddesc. - Medium Detail: Includes
labelbut omitsdesc(shows only the label). - Minimal Detail: Omits both
labelanddesc, showing only the icon.
// Full Detail { value: 'v1', label: 'Label', desc: 'Description', iconConfig: { ... } } // Medium Detail { value: 'v2', label: 'Label', iconConfig: { ... } } // Minimal Detail { value: 'v3', iconConfig: { ... } }- Full Detail: Includes
Use ThemeTags and FormatContent for advanced input decoration
devYou can decorate the input content using
ThemeTagItemandFormatInputItemvia theformatContentarray inFormatContentOptions:- ThemeTags: Use
ThemeTagItemto configure a prefix theme tag. It supports custom text and popup/tooltip content.- Constraint: Currently, you can only set a maximum of one
ThemeTag, and it must be the first element in theformatContentarray.
- Constraint: Currently, you can only set a maximum of one
- FormatInputItems: Use
FormatInputItemto insert specific input tags into the text area. These are used for default text filling or placeholder hints. Unlike theme tags, you can insert multipleFormatInputItemsat various positions.
- ThemeTags: Use
Integrate MateChat with other frameworks (e.g., React)
devFor integration with frameworks other than Vue or Angular, the following strategies are recommended:
- Web Components: Package MateChat components as Custom Elements to allow invocation from any framework.
- Micro-frontend Architecture: Use solutions like
qiankunormicroAppto load MateChat as an independent sub-application.
Understand the H5-starter directory structure
devThe
@matechat/H5-starterproject follows a modular structure organized by function and view modules:Core Logic
hooks/: Reusable logic and custom hooks.mock-data/: Simulated data for development.router/: Routing configuration.store/: Global state management.types/: Global TypeScript type definitions.utils/: Utility functions.
View Modules (
view/)The UI is divided into several functional modules:
appendix/: Attachments.audio/: Audio features.chat-model/: Chat model configurations.chat-process/: Chat interaction processes.chat-setting/: Chat settings.guess-you-want/: "Guess you want" suggestions.header/: Header component.history/: Chat history.input/: Input field components.online-search/: Online search capabilities.welcome/: Welcome page.chat-view.vue: The main chat module component.
Manage file statuses in McFileList
devYou can control the visual state of each file item by setting the
statusproperty in your file objects. Supported statuses include:success: File is ready (for upload or download).uploading: File is currently being uploaded (usepercentageto show progress).uploadError: Upload failed (useerrorstring to show the error message).downloading: File is currently being downloaded (usepercentageto show progress).downloadError: Download failed (useerrorstring to show the error message).
Example file object with status:
{ uid: 102, name: '功能演示.mp4', size: 1024 * 1024 * 15, type: 'video/mp4', status: 'uploading', percentage: 66 }Use the Layout component structure
devThe
Layoutcomponent is the top-level container used to arrange different modules within the chat interface. It is designed to wrap sub-components such asHeader,Content,Sender, andAsideto create a structured chat UI.Typical layout composition includes:
Header: For top-of-page content.Content: For the central message/content area.Sender: For bottom-of-page input/action areas.Aside: For side-panel content.
Configure McFileList context modes
devThe
contextprop allows you to change the visual style of the file list based on the usage scenario:input: Designed for use below a file upload selector. Each file item displays a delete button in the top-right corner.dialog: Designed for chat history or message bubbles. It features a more compact and streamlined appearance for displaying sent files.
<!-- Input context --> <McFileList :fileItems="inputList" context="input" @remove="handleRemove" /> <!-- Dialog context --> <McFileList :fileItems="dialogList" context="dialog" />Use the Layout component to structure MateChat modules
devThe
Layoutcomponent is the top-level container used to arrange different functional modules within the chat interface. It acts as a wrapper for sub-components likeHeader,Content,Sender, andAsideto create a consistent chat UI structure.<Layout> <Header>...</Header> <Content>...</Content> <Sender>...</Sender> <Aside>...</Aside> </Layout>Implement multi-round chat with stateless LLM APIs
devWhen using stateless LLM APIs (direct connections), multi-round chat is implemented by appending the entire conversation history to the
messagesarray in every subsequent request.Workflow:
- First Round: Send the initial user message.
- Subsequent Rounds:
- Append the previous assistant response to the
messagesarray with the roleassistant. - Append the new user question to the
messagesarray with the roleuser.
- Append the previous assistant response to the
Note: For production applications, it is recommended to use a backend Agent service with a
sessionIdrather than direct LLM connections to manage token consumption and context window limits more efficiently.// Example of messages array for the second round of chat [ {"role": "user", "content": "What's the highest mountain in the world?"}, {"role": "assistant", "content": "The highest mountain in the world is Mount Everest."}, {"role": "user", "content": "What is the second?"} ]Configure typewriter effect for streaming data
devThe component supports a typewriter animation effect, which is useful for streaming data scenarios (like LLM responses). You can configure built-in animation styles, animation speed, and typing intervals.Theme MateChat
devMateChat supports theming based on the vue-devui theming system.