This document outlines the implementation of the chat feature in Planeo.
The chat feature displays text messages from AI agents in real-time within the application. It consists of a chat window that displays these messages. By default, the chat window is hidden and can be toggled using a subtle button in the bottom-right corner of the screen.
Message(Domain Model): Defined insrc/domain/message.tsusing a Zod schema. It includesid,userId,text, andtimestampfields.useMessageStore(Zustand Store): Located insrc/stores/messageStore.ts. Manages the state of chat messages, including an array ofMessageobjects and anaddMessageaction.useChatStore(Zustand Store): Located insrc/stores/chatStore.ts. Manages the visibility state of the chat window (isChatVisible) and provides atoggleChatVisibilityaction.useCommunicationStore(Zustand Store): Located insrc/stores/communicationStore.ts. This store combines the responsibilities of the previoususeMessageStoreanduseChatStore. It manages:- An array of
Messageobjects (chat messages). - An
addMessageaction to add new messages. - The visibility state of the chat window (
isChatVisible). - A
toggleChatVisibilityaction to show or hide the chat window.
- An array of
ChatMessage(React Component): Found insrc/components/ChatMessage.tsx. Displays an individual chat message, showing the user ID (or agent name) and message text.ChatWindow(React Component): Located insrc/components/ChatWindow.tsx. Renders the list of chat messages from AI agents. It no longer contains an input field for users to send messages.ChatToggleButton(React Component): Found insrc/app/components/ChatToggleButton.tsx. A small, fixed button that allows the user to show or hide theChatWindow.
The ChatWindow component is integrated into the main application page (src/app/page.tsx). Its visibility is controlled by the ChatToggleButton and the useCommunicationStore. The useAiChat hook, responsible for fetching and displaying AI agent messages, is also initialized on the main page to ensure it operates independently of the chat window's visibility.
To ensure browser audio policies are respected (allowing AI agent speech to play), the main 3D simulation now requires a user interaction to start. A StartOverlay component is displayed initially, and the user must click it to begin the experience. This is managed by the useSimulationStore.
- More sophisticated UI/UX for the chat window and toggle button.
- User-specific notification indicators for new messages when the chat is hidden.