Skip to content
Browse documentation
whisk/ui

MessagePair

Present a user message and assistant response together.

Overview

MessagePair presents one authored user message and its assistant response as a semantic conversation turn. It gives the two parts distinct regions and places optional response actions after the assistant content; application code owns the transcript, streaming, avatars, persistence, and action behavior.

Use when

One user message and the response it prompted belong together as a single, readable conversation turn.

Use instead

Use separate content components when the blocks do not share an exchange, and an application-owned transcript list or scroll surface for conversation history, loading, and scroll-follow behavior.

Usage

Summarize this file.
The file defines the workspace build configuration.
import { MessagePair } from "@smoothie-framework/whisk-react";

<MessagePair
  user="Summarize this file."
  assistant="The file defines the workspace build configuration."
/>

Examples

Add response actions

Pass actions only when they operate on this response, such as copying, retrying, or submitting feedback. MessagePair places them after the assistant content in a labelled native fieldset; callbacks and state remain application-owned.

What changed in this release?
The release adds an accessible project picker and improves build diagnostics.
import { Button, MessagePair, Text } from "@smoothie-framework/whisk-react";

<MessagePair
  user="What changed in this release?"
  assistant="The release adds an accessible project picker and improves build diagnostics."
  actions={<>
    <Button variant="ghost" onClick={copyResponse}>Copy</Button>
    <Button variant="ghost" onClick={submitFeedback}>Helpful</Button>
  </>}
/>

Place streaming text in the assistant region

MessagePair does not manage streaming. Supply StreamingText or another application-owned response renderer as assistant content, and put a concise progress message in a separate status region rather than making the whole response live.

Explain the build result.
The deployment

Generating a response.

import { prepareStreamingText } from "@smoothie-framework/whisk-core/streaming-text";
import { MessagePair, StreamingText, Text } from "@smoothie-framework/whisk-react";

const response = prepareStreamingText([{ text: "The deployment completed successfully." }]);

<>
  <MessagePair
    user="Explain the build result."
    assistant={<StreamingText text={response} revealedWordCount={2} status="streaming" />}
    userVariant="plain"
  />
  <Text role="status">Generating a response.</Text>
</>

Use named parts for a custom turn

The compact MessagePair is the default. Use the named parts when an application needs its own surrounding content or localized region names. They preserve your authored order and do not discover, move, or clone children.

What changed in this release?
The release adds an accessible project picker.
import {
  Button,
  MessagePairActions,
  MessagePairAssistant,
  MessagePairRoot,
  MessagePairUser,
} from "@smoothie-framework/whisk-react";

<MessagePairRoot aria-label="Release review">
  <MessagePairUser variant="plain" aria-label="Developer question">
    What changed in this release?
  </MessagePairUser>
  <MessagePairAssistant aria-label="Release summary">
    The release adds an accessible project picker.
    <MessagePairActions aria-label="Release summary actions">
      <Button variant="ghost">Copy</Button>
    </MessagePairActions>
  </MessagePairAssistant>
</MessagePairRoot>

Props

Component props

PropTypeDefaultDescription
userReactNoderequiredRender the authored user message in the User region.
assistantReactNoderequiredRender the authored assistant response in the Assistant region.
actionsReactNodenoneAdd response-specific Buttons after the assistant content inside a labelled fieldset.
userVariantbubble | plainbubbleChoose a contained user surface or a plain presentation. It changes appearance, not message semantics.
userLabel | assistantLabel | actionsLabelstring | string | stringUser message | Assistant response | Assistant actionsReplace the default local accessible names, for example to localize them or make the role more specific in context.
aria-label | aria-labelledbystringConversation turn | noneName the article that wraps the turn. aria-labelledby takes precedence over the default label.
native article propsHTMLAttributes<HTMLElement>noneAdd an id, direction, data attribute, or application-owned relationship to the turn root.

Accessibility

MessagePair renders an article named Conversation turn by default, with labelled User and Assistant sections. Its optional actions use a native fieldset named Assistant actions; use visible, specific Button labels and change the name only when the surrounding context requires it. The component does not create a live region, log, focus movement, or keyboard model. Announce meaningful generation progress separately, keep author order logical, and do not rely on the user bubble color alone to distinguish who said what.

Content guidance

Keep the user's message as authored. Give each assistant action a specific verb, such as Copy response or Retry generation, and put an in-progress update in a separate concise status message.