Architecture
@cognipeer/chat-ui is structured as a layered UI library:
- Components: visual building blocks (
Chat,ChatMinimal,ChatMessage,ChatInput, etc.). - Hooks: state and side-effect orchestration (
useChat,useChatHistory). - API Client: network abstraction for session, streaming, and message operations.
- Theme System: CSS variables + theme tokens for dark/light/custom mode.
Data flow
- User submits message via
ChatInput. useChatupdates optimistic local state.- API client starts stream request to backend.
- Incoming chunks update assistant message incrementally.
- Optional tool call payloads are rendered by
ToolCallcomponent. useChatHistorysyncs conversation metadata for sidebar history.
Composition strategy
- Use
Chatfor complete UX (history + full controls). - Use
ChatMinimalfor embedded chat surfaces. - Use lower-level components + hooks only if custom layout is required.
Rendering model
- Message rendering is componentized to keep customization isolated.
- Markdown rendering is encapsulated in message components.
- Tool call rendering is opt-in and remains visually separate from assistant text.
Performance notes
- The library is optimized for typical chat session sizes.
- For long-running sessions, prefer history pagination or backend truncation.
- Keep parent container dimensions explicit to avoid layout thrashing.

