Message Actions
The toolbar under every AI answer — copy, regenerate, feedback, speak, share — plus a ‹ 2/3 › branch switcher for regenerated versions.
Preview
Events
- Hover a message and try the actions…
Installation
- 1
Run the following command
npx shadcn@latest add https://localhostui.com/r/message-actions.json
Also copy branch-switcher.tsx from the same folder.
Usage
import { MessageActions, BranchSwitcher, BranchContent } from "@/components/lokalhost_io/micro-ai-components/message-actions/message-actions";
<Message>
<BranchContent current={version}>
<Message.Content content={versions[version - 1]} />
</BranchContent>
<div className="flex items-center gap-1">
<BranchSwitcher current={version} total={versions.length} onChange={setVersion} />
<MessageActions visibility={isLatest ? "always" : "hover"}>
<MessageActions.Copy text={versions[version - 1]} />
<MessageActions.Feedback onFeedback={onFeedback} />
</MessageActions>
</div>
</Message>visibility="hover" relies on an ancestor with Tailwind's group/message class — <Message> adds it for you. If you use your own wrapper, add className="group/message" to it.
Persisting feedback
const onFeedback = async (value: "up" | "down" | null, reason?: string, comment?: string) => {
await fetch(`/api/messages/${messageId}/feedback`, {
method: "POST",
body: JSON.stringify({ value, reason, comment }),
});
};Branch data model
Keep every version of a message and the index the user is looking at:
type MessageBranch = {
messageId: string;
current: number; // 1-based
versions: { id: string; content: string; model: string; createdAt: string }[];
};Regenerating pushes a new version and moves current to it; editing a user message creates a new branch for everything after it.
Props
MessageActions
| Prop | Type | Default | Description |
|---|---|---|---|
visibility | "always""hover" | "always" | hover fades the bar in when an ancestor with the group/message class (added by <Message>) is hovered or focused. Always visible on touch devices. |
tooltipDelay | number | 300 | Tooltip open delay in ms. |
MessageActions.Copy
| Prop | Type | Default | Description |
|---|---|---|---|
text* | string | — | Markdown copied on click. Shift+click copies plain text. |
plainText | string | — | Plain-text version. Derived from text when omitted. |
onCopy | (text, format: "markdown" | "plain") => void | — | Called after a successful copy. |
MessageActions.Regenerate
| Prop | Type | Default | Description |
|---|---|---|---|
onRegenerate | (modelId?: string) => void | — | Called on click, or with the model picked from the caret menu. |
regenerating | boolean | — | Keeps the icon spinning. |
models | { id, label, description? }[] | — | Turns the button into a split button with a model menu. |
MessageActions.Feedback
| Prop | Type | Default | Description |
|---|---|---|---|
value | "up" | "down" | null | — | Controlled value. |
defaultValue | "up" | "down" | null | null | Uncontrolled initial value. |
onFeedback | (value, reason?, comment?) => void | — | Called on every change. reason and comment come from the thumbs-down popover. |
reasons | string[] | Inaccurate, Not helpful, Too long, Unsafe, Other | Reason chips. |
Share, Speak, More
| Prop | Type | Default | Description |
|---|---|---|---|
Share · onShare | () => void | Promise<void> | the Web Share API, falling back to copying the URL | Custom share. |
Share · url | string | the current page | URL for the default share. |
Speak · text* | string | — | Read aloud with speechSynthesis (markdown is stripped). Toggles to Stop. |
Speak · lang | string | — | BCP-47 language, e.g. "en-US". |
More · items* | { label, icon?, onSelect, destructive? }[] | — | Dropdown items. |
BranchSwitcher
| Prop | Type | Default | Description |
|---|---|---|---|
current* | number | — | 1-based visible version. |
total* | number | — | Number of versions. Renders nothing when 1. |
onChange | (next: number) => void | — | Called with the new 1-based index. |
BranchContent
| Prop | Type | Default | Description |
|---|---|---|---|
current* | number | — | Changing it crossfades the children. |
Keyboard
| Key | Action |
|---|---|
← / → | Move between toolbar buttons (roving focus) |
Home / End | First / last button |
Shift + click Copy | Copy plain text instead of markdown |
← / → on the branch switcher | Previous / next version |
↑ / ↓ in menus | Move between items |
Accessibility
- The bar is a
role="toolbar"with one tab stop and arrow-key roving focus. - Feedback buttons expose
aria-pressed; copy success is announced through a live region. - Every icon button has a label and a tooltip after 300ms.
- With reduced motion: no particles, no spinning, icons swap with a simple fade.