# Message sender

Identify a speaker in a shared conversation.

## Preview

message-sender-preview-1.jsx

```jsx
import { MessageSender } from "@/components/ui/message-sender";

export default function Example() {
  return (
    <div
      style={{
        display: "grid",
        gap: "var(--space-6)",
        width: "100%",
        maxWidth: 576,
      }}
    >
      <div
        style={{
          display: "grid",
          gap: "var(--space-2)",
        }}
      >
        <MessageSender name="Marta Chen" />
        <p
          style={{
            margin: 0,
            paddingInlineStart: "calc(24px + var(--space-2))",
          }}
        >
          What could block Friday’s launch?
        </p>
      </div>
      <div
        style={{
          display: "grid",
          gap: "var(--space-2)",
        }}
      >
        <MessageSender
          kind="agent"
          providerLabel="OpenAI"
          providerMark={openAiMark}
        />
        <p
          style={{
            margin: 0,
            paddingInlineStart: "calc(24px + var(--space-2))",
          }}
        >
          The mobile handoff needs an owner. Ask Priya to confirm coverage
          before the review.
        </p>
      </div>
    </div>
  );
}

function AgentProviderMark({ provider }) {
  if (provider === "openai")
    return (
      <svg viewBox="118 120 485 481" fill="currentColor" aria-hidden="true">
        <path d="M304.246 295.411V249.828C304.246 245.989 305.687 243.109 309.044 241.191L400.692 188.412C413.167 181.215 428.042 177.858 443.394 177.858C500.971 177.858 537.44 222.482 537.44 269.982C537.44 273.34 537.44 277.179 536.959 281.018L441.954 225.358C436.197 222 430.437 222 424.68 225.358L304.246 295.411ZM518.245 472.945V364.024C518.245 357.304 515.364 352.507 509.608 349.149L389.174 279.096L428.519 256.543C431.877 254.626 434.757 254.626 438.115 256.543L529.762 309.323C556.154 324.679 573.905 357.304 573.905 388.971C573.905 425.436 552.315 459.024 518.245 472.941V472.945ZM275.937 376.982L236.592 353.952C233.235 352.034 231.794 349.154 231.794 345.315V239.756C231.794 188.416 271.139 149.548 324.4 149.548C344.555 149.548 363.264 156.268 379.102 168.262L284.578 222.964C278.822 226.321 275.942 231.119 275.942 237.838V376.986L275.937 376.982ZM360.626 425.922L304.246 394.255V327.083L360.626 295.416L417.002 327.083V394.255L360.626 425.922ZM396.852 571.789C376.698 571.789 357.989 565.07 342.151 553.075L436.674 498.374C442.431 495.017 445.311 490.219 445.311 483.499V344.352L485.138 367.382C488.495 369.299 489.936 372.179 489.936 376.018V481.577C489.936 532.917 450.109 571.785 396.852 571.785V571.789ZM283.134 464.79L191.486 412.01C165.094 396.654 147.343 364.029 147.343 332.362C147.343 295.416 169.415 262.309 203.48 248.393V357.791C203.48 364.51 206.361 369.308 212.117 372.665L332.074 442.237L292.729 464.79C289.372 466.707 286.491 466.707 283.134 464.79ZM277.859 543.48C223.639 543.48 183.813 502.695 183.813 452.314C183.813 448.475 184.294 444.636 184.771 440.797L279.295 495.498C285.051 498.856 290.812 498.856 296.568 495.498L417.002 425.927V471.509C417.002 475.349 415.562 478.229 412.204 480.146L320.557 532.926C308.081 540.122 293.206 543.48 277.854 543.48H277.859ZM396.852 600.576C454.911 600.576 503.37 559.313 514.41 504.612C568.149 490.696 602.696 440.315 602.696 388.976C602.696 355.387 588.303 322.762 562.392 299.25C564.791 289.173 566.231 279.096 566.231 269.024C566.231 200.411 510.571 149.067 446.274 149.067C433.322 149.067 420.846 150.984 408.37 155.305C386.775 134.192 357.026 120.758 324.4 120.758C266.342 120.758 217.883 162.02 206.843 216.721C153.104 230.637 118.557 281.018 118.557 332.357C118.557 365.946 132.95 398.571 158.861 422.083C156.462 432.16 155.022 442.237 155.022 452.309C155.022 520.922 210.682 572.266 274.978 572.266C287.931 572.266 300.407 570.349 312.883 566.028C334.473 587.141 364.222 600.576 396.852 600.576Z" />
      </svg>
    );
  return (
    <svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
      <path d="M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z" />
    </svg>
  );
}

var openAiMark = <AgentProviderMark provider="openai" />;

```

## Design guidance

Show a speaker row when the conversation has multiple people or agents. Omit it for a single human or agent when authorship is already clear. Use [Avatar](/components/avatar) directly when you only need an image or initials. Message sender adds an optional name and accessible agent/provider disclosure; the caller supplies any visible model details.

The name stays accessible when visually hidden. The avatar and provider artwork are decorative; agent kind and a supplied provider label are disclosed as text.

## Installation

```sh
npx shadcn@latest add https://ghost-ui.com/r/message-sender.json
```

## Basic usage

  return <MessageSender name="Marta Chen" />;
}
## Structures

MessageSender is a reusable sender row. MessageHeader owns message placement and grouped visibility; compose MessageSender inside it when you want the avatar and name together. Use MessageAvatar with showName={false} for a separate avatar column. Keep provider disclosure here and message actions in Message.

Named identities use the same Dylan human and Gaze agent defaults as Avatar. Custom images, provider marks, and the unknown-person fallback take precedence. Agents have the shared AI indicator.

MessageSender uses Avatar's identity convenience and composes its public parts when it needs provider artwork. Named humans use Dylan and named agents use Gaze unless avatarUrl is supplied. A blank human name defaults to kind="unknown"; an explicitly unknown named sender keeps that name. Unknown identities ignore image URLs and generated avatars, show the neutral question badge, and use “Unknown sender” when the name is blank. The caller owns names, artwork, disclosure and whether the row appears.

## Examples

### Human

Use a stable person's name. Named people use a stable Dylan avatar by default. A custom image falls back to initials.

message-sender-human-2.jsx

```jsx
import { MessageSender } from "@/components/ui/message-sender";

export default function Example() {
  return (
    <div
      style={{
        display: "grid",
        gap: "var(--space-3)",
      }}
    >
      <MessageSender name="Marta Chen" />
      <MessageSender name="Priya Nair" />
    </div>
  );
}

```

### Agent image

Use a caller-supplied avatar for a person or agent. If it cannot load, Avatar displays the provider mark or initials.

message-sender-agent-image-3.jsx

```jsx
import { MessageSender } from "@/components/ui/message-sender";

export default function Example() {
  return (
    <MessageSender
      kind="agent"
      avatarUrl="/avatars/agent-openai.svg"
      providerLabel="OpenAI"
      providerMark={openAiMark}
    />
  );
}

function AgentProviderMark({ provider }) {
  if (provider === "openai")
    return (
      <svg viewBox="118 120 485 481" fill="currentColor" aria-hidden="true">
        <path d="M304.246 295.411V249.828C304.246 245.989 305.687 243.109 309.044 241.191L400.692 188.412C413.167 181.215 428.042 177.858 443.394 177.858C500.971 177.858 537.44 222.482 537.44 269.982C537.44 273.34 537.44 277.179 536.959 281.018L441.954 225.358C436.197 222 430.437 222 424.68 225.358L304.246 295.411ZM518.245 472.945V364.024C518.245 357.304 515.364 352.507 509.608 349.149L389.174 279.096L428.519 256.543C431.877 254.626 434.757 254.626 438.115 256.543L529.762 309.323C556.154 324.679 573.905 357.304 573.905 388.971C573.905 425.436 552.315 459.024 518.245 472.941V472.945ZM275.937 376.982L236.592 353.952C233.235 352.034 231.794 349.154 231.794 345.315V239.756C231.794 188.416 271.139 149.548 324.4 149.548C344.555 149.548 363.264 156.268 379.102 168.262L284.578 222.964C278.822 226.321 275.942 231.119 275.942 237.838V376.986L275.937 376.982ZM360.626 425.922L304.246 394.255V327.083L360.626 295.416L417.002 327.083V394.255L360.626 425.922ZM396.852 571.789C376.698 571.789 357.989 565.07 342.151 553.075L436.674 498.374C442.431 495.017 445.311 490.219 445.311 483.499V344.352L485.138 367.382C488.495 369.299 489.936 372.179 489.936 376.018V481.577C489.936 532.917 450.109 571.785 396.852 571.785V571.789ZM283.134 464.79L191.486 412.01C165.094 396.654 147.343 364.029 147.343 332.362C147.343 295.416 169.415 262.309 203.48 248.393V357.791C203.48 364.51 206.361 369.308 212.117 372.665L332.074 442.237L292.729 464.79C289.372 466.707 286.491 466.707 283.134 464.79ZM277.859 543.48C223.639 543.48 183.813 502.695 183.813 452.314C183.813 448.475 184.294 444.636 184.771 440.797L279.295 495.498C285.051 498.856 290.812 498.856 296.568 495.498L417.002 425.927V471.509C417.002 475.349 415.562 478.229 412.204 480.146L320.557 532.926C308.081 540.122 293.206 543.48 277.854 543.48H277.859ZM396.852 600.576C454.911 600.576 503.37 559.313 514.41 504.612C568.149 490.696 602.696 440.315 602.696 388.976C602.696 355.387 588.303 322.762 562.392 299.25C564.791 289.173 566.231 279.096 566.231 269.024C566.231 200.411 510.571 149.067 446.274 149.067C433.322 149.067 420.846 150.984 408.37 155.305C386.775 134.192 357.026 120.758 324.4 120.758C266.342 120.758 217.883 162.02 206.843 216.721C153.104 230.637 118.557 281.018 118.557 332.357C118.557 365.946 132.95 398.571 158.861 422.083C156.462 432.16 155.022 442.237 155.022 452.309C155.022 520.922 210.682 572.266 274.978 572.266C287.931 572.266 300.407 570.349 312.883 566.028C334.473 587.141 364.222 600.576 396.852 600.576Z" />
      </svg>
    );
  return (
    <svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
      <path d="M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z" />
    </svg>
  );
}

var openAiMark = <AgentProviderMark provider="openai" />;

```

### Name supplied by the message

Set showName={false} when a message header already supplies the visible speaker name; it remains available to assistive technology.

message-sender-name-supplied-by-the-message-4.jsx

```jsx
import { MessageSender } from "@/components/ui/message-sender";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageHeader,
} from "@/components/ui/message";

export default function Example() {
  return (
    <Message actor="user" self={false} align="start">
      <MessageAvatar>
        <MessageSender name="Marta Chen" showName={false} />
      </MessageAvatar>
      <MessageContent>
        <MessageHeader>Marta Chen</MessageHeader>
        <MessageBody>I’ll own the mobile handoff.</MessageBody>
      </MessageContent>
    </Message>
  );
}

```

### Provider disclosure

Supply the provider’s label and artwork. The mark fills the avatar when no image is available; it never appears in a corner badge.

message-sender-provider-disclosure-5.jsx

```jsx
import { MessageSender } from "@/components/ui/message-sender";

export default function Example() {
  return (
    <div
      style={{
        display: "grid",
        gap: "var(--space-3)",
      }}
    >
      <MessageSender
        kind="agent"
        providerLabel="OpenAI"
        providerMark={openAiMark}
      />
      <MessageSender
        kind="agent"
        providerLabel="Anthropic Claude"
        providerMark={<AgentProviderMark provider="anthropic" />}
      />
    </div>
  );
}

function AgentProviderMark({ provider }) {
  if (provider === "openai")
    return (
      <svg viewBox="118 120 485 481" fill="currentColor" aria-hidden="true">
        <path d="M304.246 295.411V249.828C304.246 245.989 305.687 243.109 309.044 241.191L400.692 188.412C413.167 181.215 428.042 177.858 443.394 177.858C500.971 177.858 537.44 222.482 537.44 269.982C537.44 273.34 537.44 277.179 536.959 281.018L441.954 225.358C436.197 222 430.437 222 424.68 225.358L304.246 295.411ZM518.245 472.945V364.024C518.245 357.304 515.364 352.507 509.608 349.149L389.174 279.096L428.519 256.543C431.877 254.626 434.757 254.626 438.115 256.543L529.762 309.323C556.154 324.679 573.905 357.304 573.905 388.971C573.905 425.436 552.315 459.024 518.245 472.941V472.945ZM275.937 376.982L236.592 353.952C233.235 352.034 231.794 349.154 231.794 345.315V239.756C231.794 188.416 271.139 149.548 324.4 149.548C344.555 149.548 363.264 156.268 379.102 168.262L284.578 222.964C278.822 226.321 275.942 231.119 275.942 237.838V376.986L275.937 376.982ZM360.626 425.922L304.246 394.255V327.083L360.626 295.416L417.002 327.083V394.255L360.626 425.922ZM396.852 571.789C376.698 571.789 357.989 565.07 342.151 553.075L436.674 498.374C442.431 495.017 445.311 490.219 445.311 483.499V344.352L485.138 367.382C488.495 369.299 489.936 372.179 489.936 376.018V481.577C489.936 532.917 450.109 571.785 396.852 571.785V571.789ZM283.134 464.79L191.486 412.01C165.094 396.654 147.343 364.029 147.343 332.362C147.343 295.416 169.415 262.309 203.48 248.393V357.791C203.48 364.51 206.361 369.308 212.117 372.665L332.074 442.237L292.729 464.79C289.372 466.707 286.491 466.707 283.134 464.79ZM277.859 543.48C223.639 543.48 183.813 502.695 183.813 452.314C183.813 448.475 184.294 444.636 184.771 440.797L279.295 495.498C285.051 498.856 290.812 498.856 296.568 495.498L417.002 425.927V471.509C417.002 475.349 415.562 478.229 412.204 480.146L320.557 532.926C308.081 540.122 293.206 543.48 277.854 543.48H277.859ZM396.852 600.576C454.911 600.576 503.37 559.313 514.41 504.612C568.149 490.696 602.696 440.315 602.696 388.976C602.696 355.387 588.303 322.762 562.392 299.25C564.791 289.173 566.231 279.096 566.231 269.024C566.231 200.411 510.571 149.067 446.274 149.067C433.322 149.067 420.846 150.984 408.37 155.305C386.775 134.192 357.026 120.758 324.4 120.758C266.342 120.758 217.883 162.02 206.843 216.721C153.104 230.637 118.557 281.018 118.557 332.357C118.557 365.946 132.95 398.571 158.861 422.083C156.462 432.16 155.022 442.237 155.022 452.309C155.022 520.922 210.682 572.266 274.978 572.266C287.931 572.266 300.407 570.349 312.883 566.028C334.473 587.141 364.222 600.576 396.852 600.576Z" />
      </svg>
    );
  return (
    <svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
      <path d="M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z" />
    </svg>
  );
}

var openAiMark = <AgentProviderMark provider="openai" />;

```

### Failed image

Avatar shows the provider mark when an image cannot load. Without a mark, it shows initials.

message-sender-failed-image-6.jsx

```jsx
import { MessageSender } from "@/components/ui/message-sender";

export default function Example() {
  return (
    <MessageSender
      kind="agent"
      avatarUrl="data:image/png;base64,broken"
      providerLabel="OpenAI"
      providerMark={openAiMark}
    />
  );
}

function AgentProviderMark({ provider }) {
  if (provider === "openai")
    return (
      <svg viewBox="118 120 485 481" fill="currentColor" aria-hidden="true">
        <path d="M304.246 295.411V249.828C304.246 245.989 305.687 243.109 309.044 241.191L400.692 188.412C413.167 181.215 428.042 177.858 443.394 177.858C500.971 177.858 537.44 222.482 537.44 269.982C537.44 273.34 537.44 277.179 536.959 281.018L441.954 225.358C436.197 222 430.437 222 424.68 225.358L304.246 295.411ZM518.245 472.945V364.024C518.245 357.304 515.364 352.507 509.608 349.149L389.174 279.096L428.519 256.543C431.877 254.626 434.757 254.626 438.115 256.543L529.762 309.323C556.154 324.679 573.905 357.304 573.905 388.971C573.905 425.436 552.315 459.024 518.245 472.941V472.945ZM275.937 376.982L236.592 353.952C233.235 352.034 231.794 349.154 231.794 345.315V239.756C231.794 188.416 271.139 149.548 324.4 149.548C344.555 149.548 363.264 156.268 379.102 168.262L284.578 222.964C278.822 226.321 275.942 231.119 275.942 237.838V376.986L275.937 376.982ZM360.626 425.922L304.246 394.255V327.083L360.626 295.416L417.002 327.083V394.255L360.626 425.922ZM396.852 571.789C376.698 571.789 357.989 565.07 342.151 553.075L436.674 498.374C442.431 495.017 445.311 490.219 445.311 483.499V344.352L485.138 367.382C488.495 369.299 489.936 372.179 489.936 376.018V481.577C489.936 532.917 450.109 571.785 396.852 571.785V571.789ZM283.134 464.79L191.486 412.01C165.094 396.654 147.343 364.029 147.343 332.362C147.343 295.416 169.415 262.309 203.48 248.393V357.791C203.48 364.51 206.361 369.308 212.117 372.665L332.074 442.237L292.729 464.79C289.372 466.707 286.491 466.707 283.134 464.79ZM277.859 543.48C223.639 543.48 183.813 502.695 183.813 452.314C183.813 448.475 184.294 444.636 184.771 440.797L279.295 495.498C285.051 498.856 290.812 498.856 296.568 495.498L417.002 425.927V471.509C417.002 475.349 415.562 478.229 412.204 480.146L320.557 532.926C308.081 540.122 293.206 543.48 277.854 543.48H277.859ZM396.852 600.576C454.911 600.576 503.37 559.313 514.41 504.612C568.149 490.696 602.696 440.315 602.696 388.976C602.696 355.387 588.303 322.762 562.392 299.25C564.791 289.173 566.231 279.096 566.231 269.024C566.231 200.411 510.571 149.067 446.274 149.067C433.322 149.067 420.846 150.984 408.37 155.305C386.775 134.192 357.026 120.758 324.4 120.758C266.342 120.758 217.883 162.02 206.843 216.721C153.104 230.637 118.557 281.018 118.557 332.357C118.557 365.946 132.95 398.571 158.861 422.083C156.462 432.16 155.022 442.237 155.022 452.309C155.022 520.922 210.682 572.266 274.978 572.266C287.931 572.266 300.407 570.349 312.883 566.028C334.473 587.141 364.222 600.576 396.852 600.576Z" />
      </svg>
    );
  return (
    <svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
      <path d="M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z" />
    </svg>
  );
}

var openAiMark = <AgentProviderMark provider="openai" />;

```

### Long name

Names truncate within the available width while the full name stays in the document.

message-sender-long-name-7.jsx

```jsx
import { MessageSender } from "@/components/ui/message-sender";

export default function Example() {
  return (
    <div
      style={{
        width: 192,
        maxWidth: "100%",
      }}
    >
      <MessageSender name="Alexandria Montgomery-Silalahi" />
    </div>
  );
}

```

### Unknown sender

A missing or whitespace-only human name becomes kind="unknown" and displays “Unknown sender”. Set kind="unknown" for a named sender whose identity is not verified; the name stays visible while the avatar remains generic.

message-sender-unknown-sender-8.jsx

```jsx
import { MessageSender } from "@/components/ui/message-sender";

export default function Example() {
  return <MessageSender name=" " />;
}

```

## API reference

Message sender properties

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| name | string | — | Visible speaker name. Whitespace is trimmed. Blank names default to Agent for agents and Unknown sender for humans. |
| kind | human \| agent \| unknown | human | Human names use Dylan; agents use Gaze and have an accessible AI agent disclosure. A blank human name is treated as unknown. Set unknown explicitly for a named but unverified sender; unknown avatars ignore avatarUrl and generated images, and use the neutral question badge. |
| seed | string | — | Stable sender ID for the generated avatar; defaults to the name. |
| size | xs \| sm | sm | Shared Avatar size. Transcript uses xs; message identity rows use sm. |
| avatarUrl | string | — | Optional image URL; Avatar.Fallback remains available while loading or when the image fails. |
| providerLabel | string | — | Provider identity disclosed once as accessible text, including when no artwork is supplied. |
| providerMark | ReactNode | — | Caller-supplied artwork centered in Avatar.Fallback when no image is loaded. Replaces initials; the separate AI indicator identifies agent kind. |
| showName | boolean | true | Hide the visible name when MessageHeader already supplies it; the accessible name remains. |
| className | string | — | Adds a class to the identity row. |
