showcase/shell-docs/src/content/reference/vue/components/CopilotChatAssistantMessage.mdx
CopilotChatAssistantMessage is a Vue 3 component that displays assistant messages with Markdown support, tool call rendering, and an action toolbar. Markdown is rendered with streamdown-vue (StreamMarkdown), which supports GitHub Flavored Markdown tables, math expressions (KaTeX styles are loaded automatically), and syntax-highlighted code blocks via Shiki (github-light / github-dark themes). Tables and code blocks include built-in copy and download actions, and images get a hover download button.
The toolbar provides copy, thumbs up, thumbs down, read aloud, and regenerate buttons. Tooltip and aria labels are sourced from the nearest CopilotChatConfigurationProvider (see useCopilotChatConfiguration). The thumbs up, thumbs down, read aloud, and regenerate buttons are only rendered when a listener for the corresponding event is attached; the copy button is always shown when the toolbar is visible.
<script setup lang="ts">
import { CopilotChatAssistantMessage } from "@copilotkit/vue/v2";
</script>
<script setup lang="ts">
import { CopilotChatAssistantMessage } from "@copilotkit/vue/v2";
import type { AssistantMessage } from "@ag-ui/core";
const message: AssistantMessage = {
id: "1",
role: "assistant",
content: "Here is **Markdown** with a `code` sample.",
};
</script>
<template>
<CopilotChatAssistantMessage
:message="message"
@thumbs-up="(msg) => console.log('Thumbs up:', msg.id)"
@thumbs-down="(msg) => console.log('Thumbs down:', msg.id)"
/>
</template>
Each event emits the current message as its payload. Attaching a listener for
thumbs-up, thumbs-down, read-aloud, or regenerate also causes the matching
toolbar button to render; without a listener the button is omitted.
The component exposes named slots so you can override individual pieces of the default layout. Each slot receives scoped props (shown below) that wire its behavior to the message and toolbar handlers.
<PropertyReference name="layout" type="slot"> Replaces the entire component layout. Receives `message`, `content`, `is-running`, `toolbar-visible`, `should-show-toolbar`, the nested slot render functions (`message-renderer`, `toolbar`, `copy-button`, `thumbs-up-button`, `thumbs-down-button`, `read-aloud-button`, `regenerate-button`, `tool-calls-view`), and the handlers `on-copy`, `on-thumbs-up`, `on-thumbs-down`, `on-read-aloud`, and `on-regenerate`. </PropertyReference> <PropertyReference name="message-renderer" type="slot"> Replaces the Markdown renderer. Receives `message` and `content` (the normalized text). Use this to swap out `StreamMarkdown` for a custom renderer. </PropertyReference> <PropertyReference name="tool-calls-view" type="slot"> Replaces the tool calls view. Receives `message` and `messages`. Defaults to `CopilotChatToolCallsView`, which renders the message's tool calls using the closest registered tool renderer. </PropertyReference> <PropertyReference name="toolbar" type="slot"> Replaces the action toolbar container. Receives `message` and `should-show-toolbar`. Only rendered when the toolbar should be shown. </PropertyReference> <PropertyReference name="copy-button" type="slot"> Replaces the copy-to-clipboard button. Receives `on-copy`, `copied` (whether the copied state is currently active), and `label`. </PropertyReference> <PropertyReference name="thumbs-up-button" type="slot"> Replaces the thumbs-up button. Receives `on-thumbs-up` and `label`. Only rendered when a `thumbs-up` listener is attached. </PropertyReference> <PropertyReference name="thumbs-down-button" type="slot"> Replaces the thumbs-down button. Receives `on-thumbs-down` and `label`. Only rendered when a `thumbs-down` listener is attached. </PropertyReference> <PropertyReference name="read-aloud-button" type="slot"> Replaces the read-aloud button. Receives `on-read-aloud` and `label`. Only rendered when a `read-aloud` listener is attached. </PropertyReference> <PropertyReference name="regenerate-button" type="slot"> Replaces the regenerate button. Receives `on-regenerate` and `label`. Only rendered when a `regenerate` listener is attached. </PropertyReference> <PropertyReference name="toolbar-items" type="slot"> Appended to the toolbar after the default buttons. Use this to add custom toolbar actions. Receives no scoped props. </PropertyReference><script setup lang="ts">
import { CopilotChatAssistantMessage } from "@copilotkit/vue/v2";
import type { AssistantMessage } from "@ag-ui/core";
defineProps<{ message: AssistantMessage }>();
</script>
<template>
<CopilotChatAssistantMessage
:message="message"
@thumbs-up="(msg) => console.log('Thumbs up:', msg.id)"
@thumbs-down="(msg) => console.log('Thumbs down:', msg.id)"
/>
</template>
Attaching the listeners makes the corresponding buttons appear automatically.
<script setup lang="ts">
import { CopilotChatAssistantMessage } from "@copilotkit/vue/v2";
import type { AssistantMessage } from "@ag-ui/core";
defineProps<{ message: AssistantMessage }>();
function handleRegenerate(msg: AssistantMessage) {
// re-run the agent for this message
}
function handleReadAloud(msg: AssistantMessage) {
// speak msg.content
}
</script>
<template>
<CopilotChatAssistantMessage
:message="message"
@regenerate="handleRegenerate"
@read-aloud="handleReadAloud"
/>
</template>
<script setup lang="ts">
import { CopilotChatAssistantMessage } from "@copilotkit/vue/v2";
import type { AssistantMessage } from "@ag-ui/core";
defineProps<{ message: AssistantMessage }>();
</script>
<template>
<CopilotChatAssistantMessage :message="message">
<template #toolbar-items>
<button type="button" @click="shareMessage(message)">Share</button>
</template>
</CopilotChatAssistantMessage>
</template>
<script setup lang="ts">
import { CopilotChatAssistantMessage } from "@copilotkit/vue/v2";
import type { AssistantMessage } from "@ag-ui/core";
defineProps<{ message: AssistantMessage }>();
</script>
<template>
<CopilotChatAssistantMessage :message="message" :toolbar-visible="false" />
</template>
<script setup lang="ts">
import { CopilotChatAssistantMessage } from "@copilotkit/vue/v2";
import type { AssistantMessage } from "@ag-ui/core";
defineProps<{ message: AssistantMessage }>();
</script>
<template>
<CopilotChatAssistantMessage :message="message">
<template #message-renderer="{ content }">
<div class="custom-markdown">{{ content }}</div>
</template>
</CopilotChatAssistantMessage>
</template>
<script setup lang="ts">
import { CopilotChatAssistantMessage } from "@copilotkit/vue/v2";
import type { AssistantMessage } from "@ag-ui/core";
defineProps<{ message: AssistantMessage }>();
</script>
<template>
<CopilotChatAssistantMessage
:message="message"
@regenerate="(msg) => regenerate(msg)"
>
<template #regenerate-button="{ onRegenerate, label }">
<button type="button" :title="label" @click="onRegenerate">
Regenerate
</button>
</template>
</CopilotChatAssistantMessage>
</template>
CopilotChatToolCallsView - Renders the tool calls contained in an assistant messageCopilotChatUserMessage - Companion component for user messagesCopilotChatMessageView - Parent component that renders this as the default assistant messageuseCopilotChatConfiguration - Provides the localized toolbar labels