Quick Start
For rapid development,<C1Chat>
includes a built-in, in-memory store that manages the conversation history. To get started, you only need to provide your backend endpoint’s URL to the apiUrl
prop.
For API implementation, please refer to Conversational API section.
The in-memory store is for development and prototyping. The entire chat history will be cleared when the page is refreshed.
<C1Chat>
Component Props
Full Implementation: fetching thread and thread list from backend
For a production application, user expect a persistent conversation history. This is done by managing threads in your backend and fetching them to the UI. The C1 SDK provides two hooks that handle all the complex state management and data fetching logic for this process.useThreadManager
: Managing a Single Conversation
This hook handles the state and data fetching for a single thread. Its responsibilities include:
- Fetching all messages for a given thread.
- Adding a new
user
message to the state. - Calling your backend API to get an
assistant
response.
useThreadManager
Hook API
useThreadListManager
: Managing the Chat History
This hook handles the state and logic for the list of all threads. Its responsibilities include:
- Fetching the list of a user’s conversations.
- Switching the active thread.
- Creating new threads and deleting old ones.
useThreadListManager
Hook API
Connecting the Hooks to <C1Chat>
To enable persistence, you initialize these hooks and pass their state and handlers to the <C1Chat>
component. This switches <C1Chat>
from its automatic in-memory mode to a “controlled” mode, where all state is managed by you.