ComponentsMessage Actions

Message Actions

The toolbar under every AI answer — copy, regenerate, feedback, speak, share — plus a ‹ 2/3 › branch switcher for regenerated versions.

Preview

React Server Components run on the server and send a serialized tree to the client, so no JavaScript ships for them unless they render a client component.

React Server Components run on the server and send a serialized tree to the client, so **no JavaScript ships** for them unless they render a client component.

A monorepo keeps every package in one repository, so shared types and tooling stay in sync and refactors land in a single commit.

A **monorepo** keeps every package in one repository, so shared types and tooling stay in sync and refactors land in a single commit.
1/3

To share state between server and client components, keep it in the URL (search params) or pass serializable props down. Client-only state lives in a client component near the leaf.

To share state between server and client components, keep it in the URL (search params) or pass serializable props down. Client-only state lives in a client component near the leaf.
Events
  1. Hover a message and try the actions…

Installation

  1. 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

PropTypeDefaultDescription
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.
tooltipDelaynumber300Tooltip open delay in ms.

MessageActions.Copy

PropTypeDefaultDescription
text*string—Markdown copied on click. Shift+click copies plain text.
plainTextstring—Plain-text version. Derived from text when omitted.
onCopy(text, format: "markdown" | "plain") => void—Called after a successful copy.

MessageActions.Regenerate

PropTypeDefaultDescription
onRegenerate(modelId?: string) => void—Called on click, or with the model picked from the caret menu.
regeneratingboolean—Keeps the icon spinning.
models{ id, label, description? }[]—Turns the button into a split button with a model menu.

MessageActions.Feedback

PropTypeDefaultDescription
value"up" | "down" | null—Controlled value.
defaultValue"up" | "down" | nullnullUncontrolled initial value.
onFeedback(value, reason?, comment?) => void—Called on every change. reason and comment come from the thumbs-down popover.
reasonsstring[]Inaccurate, Not helpful, Too long, Unsafe, OtherReason chips.

Share, Speak, More

PropTypeDefaultDescription
Share · onShare() => void | Promise<void>the Web Share API, falling back to copying the URLCustom share.
Share · urlstringthe current pageURL for the default share.
Speak · text*string—Read aloud with speechSynthesis (markdown is stripped). Toggles to Stop.
Speak · langstring—BCP-47 language, e.g. "en-US".
More · items*{ label, icon?, onSelect, destructive? }[]—Dropdown items.

BranchSwitcher

PropTypeDefaultDescription
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

PropTypeDefaultDescription
current*number—Changing it crossfades the children.

Keyboard

KeyAction
← / →Move between toolbar buttons (roving focus)
Home / EndFirst / last button
Shift + click CopyCopy plain text instead of markdown
← / → on the branch switcherPrevious / next version
↑ / ↓ in menusMove 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.