showcase/shell-docs/src/content/snippets/shared/troubleshooting/migrate-to-1.10.X.mdx
CopilotKit 1.10.X introduces a new headless UI system and simplified message formats. Most existing code will continue to work, but you may need to update custom message handling.
What you need to know:
Messages now use plain objects instead of classes for better performance and simpler handling.
const message = new TextMessage({
role: MessageRole.Assistant,
content: "Hello, how are you?",
});
const message = {
role: "assistant",
content: "Hello, how are you?",
};
Message type checking has been streamlined for better developer experience. Instead of using the previous
isTextMessage or adjacent methods, you can now check the role property of the message.
if (message.isTextMessage()) {
if (message.role === "assistant") {
console.log(message.content);
}
if (message.role === "user") {
console.log(message.content);
}
}
if (message.isImageMessage()) {
console.log(message.image);
}
if (message.isActionExecutionMessage()) {
console.log(message.toolCalls);
}
// etc...
if (message.role === "assistant") {
console.log(message.content, message.toolCalls, message.image);
}
if (message.role === "user") {
console.log(message.content, message.image);
}
Previously, you had to use the subComponent property to render custom assistant messages. Now you can use the generativeUI property instead.
Important! Both will continue to work.
import { AssistantMessageProps } from "@copilotkit/react-core/v2";
export const AssistantMessage = (props: AssistantMessageProps) => {
const { message, subComponent } = props;
return <div style={{ marginBottom: "0.5rem" }}>{subComponent}</div>;
};
import { AssistantMessageProps } from "@copilotkit/react-core/v2";
export const AssistantMessage = (props: AssistantMessageProps) => {
const { message } = props;
return <div style={{ marginBottom: "0.5rem" }}>{message.generativeUI}</div>;
};
subComponent (legacy) and generativeUI (new) properties workuseCopilotChat code continues to functionNew useCopilotChatHeadless_c hook provides complete control over chat UI:
Features:
<video src="https://cdn.copilotkit.ai/docs/copilotkit/videos/full-headless-chat.mp4" className="rounded-xl shadow-lg border" loop playsInline autoPlay muted />
An example of how you might use the new Headless UI hook:
const { messages, suggestions, interrupt } = useCopilotChatHeadless_c();
return (
<div>
{suggestions.map((suggestion) => (
<div key={suggestion.id}>{suggestion.title}</div>
))}
{interrupt}
{messages.map((message) => {
switch (message.role) {
case "assistant":
if (message.generativeUI) return message.generativeUI;
return <div key={message.id}>{message.content}</div>;
case "user":
return <div key={message.id}>{message.content}</div>;
}
})}
</div>
);
Read more about the new headless UI hook and get started.
useCopilotChat?With the introduction of the new headless UI hook, we are starting the deprecation of useCopilotChat. While it will remain supported for several months in maintenance mode, all new headless UI features will be added to useCopilotChatHeadless_c.
We recommend migrating to the new hook for new projects. However, please feel free to continue using useCopilotChat until you are ready to migrate.
Continue using useCopilotChat if:
Migrate to useCopilotChatHeadless_c if: