🚧 Work in Progress 🚧
The Chat UI is a pnpm monorepo with the core UI components located in packages/core. It's built with Vue.js and Vite.
graph TD
A[App.vue] -->|uses| B(Container.vue)
A -->|uses| C(Settings.vue)
A -->|uses| D(ChatWindow.vue)
A -->|uses| E{useChat Composable}
D -->|passes config| F[ChatWindowHeader.vue]
D -->|passes config| G[ChatHistory.vue]
D -->|passes config| H[ChatInput.vue]
E -->|manages| I[Messages State]
E -->|manages| J[Loading State]
E -->|manages| K[Error State]
E -->|handles| L[Send Message Logic]
H -->|emits send-message| D
D -->|emits send-message| A
A -->|calls sendMessage| E
subgraph ChatWindow
direction LR
F
G
H
end
subgraph Core Logic
direction LR
E
end
- Description: The main application component.
- Responsibilities:
- Initializes and uses the
useChatcomposable. - Defines the
ChatConfigobject. - Renders
Container,Settings, andChatWindow. - Handles the
sendMessageevent fromChatWindowand calls thesendMessagefunction fromuseChat.
- Initializes and uses the
- Description: Displays the main chat interface.
- Props:
chatConfig: ChatConfig: Configuration for the chat window (title, avatar, messages, etc.).
- Emits:
sendMessage(message: string): When the user sends a new message.
- Internal Components:
ChatWindowHeader.vue: Displays the chat title, subtitle, and avatar.ChatHistory.vue: Displays the list of messages.ChatInput.vue: Provides the input field for the user to type messages.
- Functionality:
- Receives
chatConfigand provides it to its child components using Vue'sprovide(PROVIDER_KEY_CHAT_CONFIG).
- Receives
- Description: Renders the header of the chat window.
- Consumes (via inject):
chatConfig: To display title, subtitle, avatar.
- Description: Renders the scrollable list of chat messages.
- Consumes (via inject):
chatConfig: Specifically themessages,loading, anderrorMessageproperties.
- Description: The input component for users to type and send messages.
- Emits:
sendMessage(message: string): When the user submits a message.
- Consumes (via inject):
chatConfig: Potentially for sender information or other input-related configurations.
- Description: (Assumed) Allows users to configure chat settings. The exact functionality needs further inspection of
Settings.vue.
- Description: (Assumed) A layout component for padding and structure.
- Description: A Vue composable that encapsulates the core chat logic.
- Exports:
sendMessage(payload: { content: string, streaming: boolean }): Function to send a message.messages: Ref<ChatMessage[]>: Reactive array of chat messages.loading: Ref<boolean>: Reactive flag indicating if a message is being sent/received.errorMessage: Ref<string | null>: Reactive string for any error messages.
- Functionality:
- Manages the state of chat messages.
- Handles the logic for sending messages (likely interacts with a backend service, which needs to be confirmed by looking at
useChat.ts). - Manages loading and error states.
- Initialization:
App.vueinitializesuseChatand createschatConfig.chatConfig(including reactivemessages,loading,errorMessagefromuseChat) is passed as a prop toChatWindow.vue.
- Configuration Propagation:
ChatWindow.vueusesprovideto makechatConfigavailable to its children (ChatWindowHeader,ChatHistory,ChatInput).
- Displaying Data:
ChatWindowHeader.vueinjectschatConfigto display title, subtitle, etc.ChatHistory.vueinjectschatConfigto display themessageslist, and showloadingorerrorMessagestates.
- Sending a Message:
- User types a message in
ChatInput.vue. ChatInput.vueemits asendMessageevent with the message content.ChatWindow.vuelistens for this event and re-emits it.App.vuelistens for this event and calls thesendMessagefunction from theuseChatcomposable, passing the message content and streaming preference.
- User types a message in
- Updating State:
- The
sendMessagefunction inuseChathandles the asynchronous message sending operation. - It updates the
loadingstate. - Upon receiving a response (or streaming updates), it updates the
messagesarray. - If an error occurs, it updates
errorMessage.
- The
- Reactivity:
- Since
messages,loading, anderrorMessageare reactive properties withinchatConfig, any changes made byuseChatwill automatically reflect inChatHistory.vueand other components consuming this data.
- Since
To integrate the chat functionality into another part of the application or a different application:
<script setup lang="ts">
import { ChatWindow } from '@chat-ui/core/components'; // Adjust path as needed
import { useChat } from '@chat-ui/core/composables'; // Adjust path
import type { ChatConfig } from '@chat-ui/core/types';
import { ref } from 'vue';
// 1. Initialize the chat composable
const { sendMessage, messages, loading, errorMessage } = useChat(/* Optional: pass a custom API endpoint or other options here */);
// 2. Define your chat configuration
const myChatConfig = ref<ChatConfig>({
chatTitle: 'My Custom Chat',
chatSubtitle: 'Powered by Chat UI',
chatAvatar: '/path/to/my-avatar.png',
senderLabel: 'Me',
receiverLabel: 'Bot',
streaming: true,
messages, // Pass the reactive messages from useChat
loading, // Pass the reactive loading state
errorMessage, // Pass the reactive error state
// Add any other custom properties your ChatConfig might support
});
// 3. Handle the send message event
const handleUserSendMessage = (message: string) => {
sendMessage({ content: message, streaming: myChatConfig.value.streaming });
};
</script>
<template>
<div>
<!-- Optional: Add your own settings component -->
<!-- <MyCustomSettings v-model:config="myChatConfig" /> -->
<ChatWindow
:chat-config="myChatConfig"
@send-message="handleUserSendMessage"
/>
</div>
</template>packages/core/src/composables/useChat.ts: Needs to be reviewed to understand the backend interaction (API calls, data format).packages/core/src/components/Settings.vue: Needs review to document its specific functionality and props/events.- UI Library (
@/components/ui/card): Understand which UI library is used (e.g., Shadcn UI, custom) for styling and base components. - Error Handling Details: How are different types of errors handled and displayed?
- Streaming Implementation: Details of how message streaming is implemented and managed by
useChat.
This initial documentation provides a good starting point. We can refine it further as we explore the mentioned files.
This is a beta version of the documentation.

