showcase/shell-docs/src/content/reference/v1/components/chat/CopilotChat.mdx
{ /*
A chatbot panel component for the CopilotKit framework. The component allows for a high degree of customization through various props and custom CSS.
This component is part of the @copilotkit/react-ui package.
npm install @copilotkit/react-core @copilotkit/react-ui
import { CopilotChat } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
<CopilotChat
labels={{
title: "Your Assistant",
initial: "Hi! 👋 How can I assist you today?",
}}
/>
To monitor user interactions, provide the observabilityHooks prop.
Note: This requires a publicApiKey in the <CopilotKit> provider.
<CopilotKit publicApiKey="YOUR_PUBLIC_API_KEY">
<CopilotChat
observabilityHooks={{
onMessageSent: (message) => {
console.log("Message sent:", message);
},
}}
/>
</CopilotKit>
By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
...
import "@copilotkit/react-ui/styles.css"; // [!code highlight]
export function YourRootComponent() {
return (
<CopilotKit>
...
</CopilotKit>
);
}
For more information about how to customize the styles, check out the Customize Look & Feel guide.
auto (default) - Suggestions are generated automatically:
- When the chat is first opened (empty state)
- After each message exchange completes
- Uses configuration from useCopilotChatSuggestions hooks
manual - Suggestions are controlled programmatically:
- Use setSuggestions() to set custom suggestions
- Use generateSuggestions() to trigger AI generation
- Access via useCopilotChat hook
SuggestionItem[] - Static suggestions array:
- Always shows the same suggestions
- No AI generation involved
</PropertyReference>
@example
<CopilotChat
attachments={{
enabled: true,
accept: "image,application/pdf",
maxSize: 10 1024 1024, // 10MB
onUpload: async (file) => {
const url = await uploadToS3(file);
return { url, mimeType: file.type };
},
}}
/>
Warning: This is a break-glass solution to allow for custom rendering of messages. You are most likely looking to swap out the AssistantMessage and UserMessage components instead which are also props. </PropertyReference>
<PropertyReference name="RenderSuggestionsList" type="React.ComponentType<RenderSuggestionsListProps>" > A custom suggestions list component to use instead of the default. </PropertyReference> <PropertyReference name="Input" type="React.ComponentType<InputProps>" > A custom Input component to use instead of the default. </PropertyReference> <PropertyReference name="className" type="string" > A class name to apply to the root element. </PropertyReference> <PropertyReference name="children" type="React.ReactNode" > Children to render. </PropertyReference> <PropertyReference name="hideStopButton" type="boolean" > </PropertyReference> <PropertyReference name="observabilityHooks" type="CopilotObservabilityHooks" > Event hooks for CopilotKit chat events. These hooks only work when publicApiKey is provided. </PropertyReference> <PropertyReference name="renderError" type="(error: { message: string; operation?: string; timestamp: number; onDismiss: () => void; onRetry?: () => void; }) => React.ReactNode" > Custom error renderer for chat-specific errors. When provided, errors will be displayed inline within the chat interface. </PropertyReference> <PropertyReference name="onError" type="CopilotErrorHandler" > Optional handler for comprehensive debugging and observability. </PropertyReference>