
Preview
Supported Features
Embedding the Copilot
First, make sure your Chainlit server is running. Then, add the following script at the end of your website’s<body> tag:
This example assumes your Chainlit server is running on
http://localhost:8000window.toggleChainlitCopilot().
Thread Persistence
The Copilot now supports persistent storage of thethreadId in the browser’s localStorage, enabling chat restoration after a page reload. This feature provides two JavaScript utility functions for managing thread persistence:
getChainlitCopilotThreadId()
Retrieves the current threadId from localStorage. Returns:string | null - The current threadId or null if not found
clearChainlitCopilotThreadId(newThreadId?)
Clears the existing threadId from localStorage. Optionally sets a new one. Parameters:newThreadId?(optional):string- A new threadId to set after clearing
Widget Configuration
ThemountChainlitWidget function accepts the following options:
Sidebar Mode
By default the copilot renders as a floating popover. SetdisplayMode to "sidebar" to render it as a full-height side panel anchored to the right edge of the viewport. The panel pushes the host page content to make room and includes a drag handle on its left edge for resizing (300 px min, 50 % viewport max).
Users can switch between sidebar and floating modes via a dropdown in the copilot header. The selected mode and sidebar width are persisted in localStorage across sessions. An explicit displayMode in mountChainlitWidget() takes priority over the stored value.
Since version 2.11.0.
Function Calling
The Copilot can call functions on your website. This is useful for taking actions on behalf of the user. For example, you can call a function to create a new document, or to open a modal. First, create aCopilotFunction in your Chainlit server:
Send a Message
The Copilot can also send messages directly to the Chainlit server. This is useful for sending context information or user actions to the Chainlit server (like the user selected from cell A1 to B1 on a table). First, update the@cl.on_message decorated function to your Chainlit server:
Security
Cross Origin Resource Sharing (CORS)
Don’t forget to add the origin of the host website to the allow_origins config field to a list of allowed origins.Authentication
If you want to authenticate users on the Copilot, you can enable authentication on the Chainlit server. While the standalone Chainlit application handles the authentication process, the Copilot needs to be configured with an access token. This token is used to authenticate the user with the Chainlit server. The host app/website is responsible for generating the token and passing it to the asaccessToken. Here are examples of how to generate the token in different languages:
You will need the
CHAINLIT_AUTH_SECRET you generated when configuring
authentication.