Index of every page on this site: llms.txt
All skills
assistant-ui avatar

/primitives

@b0609e6
by assistant-uiassistant-ui/skills29 stars
7
Run it yourself

Builds and customizes assistant-ui chat UI from composable, unstyled @assistant-ui/react primitives: ThreadPrimitive, ComposerPrimitive (with Unstable_TriggerPopover for mentions and slash commands), MessagePrimitive and MessagePartPrimitive, ActionBarPrimitive, BranchPickerPrimitive, AttachmentPrimitive, ErrorPrimitive, AssistantModalPrimitive, ChainOfThoughtPrimitive, SelectionToolbarPrimitive, SuggestionPrimitive, QueueItemPrimitive, and the ThreadList primitives. Use when assembling or styling a custom Thread, Composer, message list, action bar, branch picker, or suggestion grid; wiring composer input, dictation, quoting, or attachments; or handling editing, branching, virtualization, scrolling, or chain of thought UI. Covers MessagePrimitive.Parts render functions per part type, groupPartByType, AuiIf in selector form, and the unstyled gotchas (AssistantRuntimeProvider, className). For prebuilt UI use setup, for the styled catalog use elements, for multi-thread sidebars use thread-list.

Use this Skill: https://skilld.dev/gh/assistant-ui/skills/primitives

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescomposer.md

≈2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

ComposerPrimitive

The interface for composing a new message or editing an existing one: submit behavior, keyboard shortcuts, focus management, attachment and quote state, and streaming status. Root renders a <form>, Input a <textarea>, Send and Cancel <button>s.

Parts

Part Renders Notes
.Root <form> Submits on Enter (Shift+Enter for a newline by default). Accepts compact; see below.
.Input <textarea> submitMode ("enter" default, "ctrlEnter", "none"), cancelOnEscape, unstable_insertNewlineOnTouchEnter, unstable_focusOnRunStart, unstable_focusOnScrollToBottom.
.Send <button> Disabled when the composer cannot send (empty, or gated; see below).
.Cancel <button> Cancels the in flight run, or exits edit mode without resending.
.AddAttachment <button> Opens the file picker.
.Attachments list Children render function { attachment }. See composer-input.md.
.AttachmentByIndex one attachment index plus components={{ Attachment }}.
.AttachmentDropzone <div> Sets data-dragging while a file hovers over it; inert without the attachments capability.
.Dictate / .StopDictation <button> Start and stop a dictation session. See composer-input.md.
.DictationTranscript <span> Interim transcript while dictation is active.
.Quote / .QuoteText / .QuoteDismiss <div> / <span> / <button> Quoted text preview. Only .Quote renders when a quote is set. See composer-input.md.
.Queue queue UI Queued messages sent while a run is in flight; render QueueItemPrimitive inside.
.Unstable_TriggerPopoverRoot / .Unstable_TriggerPopover and friends popover @ mention and / slash command popovers. See mentions.md.
.If conditional Deprecated (editing, dictation only). Use AuiIf.

New message vs edit mode

The same primitives handle both: a Composer inside a ThreadPrimitive.Root composes a new message, and a Composer inside a MessagePrimitive.Root edits that message. Behavior switches automatically based on where it renders.

// New message composer, inside ThreadPrimitive
<ComposerPrimitive.Root>
  <ComposerPrimitive.Input />
  <ComposerPrimitive.Send>Send</ComposerPrimitive.Send>
</ComposerPrimitive.Root>

// Edit composer, inside a MessagePrimitive.Root
<ComposerPrimitive.Root>
  <ComposerPrimitive.Input />
  <ComposerPrimitive.Send>Save</ComposerPrimitive.Send>
  <ComposerPrimitive.Cancel>Cancel</ComposerPrimitive.Cancel>
</ComposerPrimitive.Root>

useAuiState((s) => s.composer.isEditing) reads the same flag from either context, but scoping the edit UI through the message's own render branch (as in the SKILL.md custom thread example) is more idiomatic than a manual check. See messages.md for the full editing flow, including aui.composer.beginEdit().

The asChild pattern

Every part accepts asChild to merge its behavior onto your own element, so keyboard handling, disabled state, and form submission wire onto your design system's component instead of a bare native one:

<ComposerPrimitive.Input asChild>
  <textarea className="my-textarea" placeholder="Type here..." />
</ComposerPrimitive.Input>

<ComposerPrimitive.Send asChild>
  <MyButton variant="primary">Send</MyButton>
</ComposerPrimitive.Send>

Own the input DOM entirely, a contentEditable surface or an editor library asChild cannot express? See composer-input.md for unstable_useComposerInput.

Compact mode

Pass compact on Root to opt into a data-compact attribute: it is set while the input holds at most one line of text and the composer has no attachments, quote, queued messages, or active dictation. The prop only exposes the attribute; style the collapse yourself.

<ComposerPrimitive.Root
  compact
  className="flex flex-col data-[compact]:flex-row data-[compact]:items-center"
>
  <ComposerPrimitive.Input placeholder="Ask anything..." />
  <ComposerPrimitive.Send>Send</ComposerPrimitive.Send>
</ComposerPrimitive.Root>

Once the text wraps to a second line the composer expands and stays expanded until the input clears, so the layout does not oscillate right at the wrap boundary.

Patterns

Custom submit behavior

<ComposerPrimitive.Root
  onSubmit={(e) => {
    // runs before the message sends; call e.preventDefault() to cancel
  }}
>
  <ComposerPrimitive.Input />
  <ComposerPrimitive.Send>Send</ComposerPrimitive.Send>
</ComposerPrimitive.Root>

Gate sending on external state

Disabling the whole thread via isDisabled also disables the text input, which feels broken while the user is still allowed to type. Set isSendDisabled on the runtime adapter instead, so typing stays available while sending is blocked (loading tools, pending auth, and so on):

const runtime = useExternalStoreRuntime({
  isSendDisabled: !toolsLoaded,
  onNew,
  messages,
});

While isSendDisabled is true, composer.canSend is false, ComposerPrimitive.Send is disabled, Enter and the steer hotkey become no ops, and aui.composer.send() short circuits at the runtime so no direct call can escape the gate. It only gates the thread composer; saving an in progress edit is unaffected. Read the same flag for an inline hint:

<AuiIf condition={(s) => !s.composer.canSend}>
  <p className="text-sm text-muted-foreground">Loading tools, hang on...</p>
</AuiIf>

Ctrl+Enter to submit

<ComposerPrimitive.Input submitMode="ctrlEnter" />

Plain Enter inserts a newline; Ctrl (Cmd) plus Enter submits.

Mobile and touch devices

<ComposerPrimitive.Input unstable_insertNewlineOnTouchEnter />

On touch primary devices ((pointer: coarse) and (not (any-pointer: fine))), Enter inserts a newline instead of sending, so the on screen Return key never fires a half finished message; submission moves to the explicit Send button, matching WhatsApp, Slack, Discord, iMessage, ChatGPT, and Claude.ai. Desktop behavior, and a tablet with a hardware keyboard under an explicit submitMode, are unchanged.

Floating composer

function FloatingComposer() {
  return (
    <div className="fixed bottom-6 left-1/2 z-40 w-full max-w-md -translate-x-1/2">
      <ComposerPrimitive.Root>
        <div className="rounded-xl border bg-background/80 shadow-lg backdrop-blur-sm">
          <ComposerPrimitive.Input
            asChild
            unstable_focusOnRunStart={false}
            unstable_focusOnScrollToBottom={false}
          >
            <textarea
              placeholder="Ask a question..."
              className="w-full resize-none bg-transparent px-3 py-2.5 text-sm focus:outline-none"
              rows={1}
            />
          </ComposerPrimitive.Input>
        </div>
      </ComposerPrimitive.Root>
    </div>
  );
}

ComposerPrimitive is not bound to any layout. The two unstable_focusOn* flags stop a composer living outside the main thread scroll flow from stealing focus on run start or scroll to bottom.

Common Gotchas

Send button stays disabled

  • canSend requires editing mode plus non empty content plus isSendDisabled not set. An in flight run without queue support also disables Send directly; check s.thread.isRunning and whether your runtime supports queued sends.

ComposerPrimitive.If ignores most conditions

  • It only understands editing and dictation. Use AuiIf (s.composer.isEditing, s.composer.dictation != null) for anything else.

Attachments, quoting, dictation, or input history need more setup than the bare primitive

  • Those parts render the right DOM, but the surrounding adapters and hooks live in composer-input.md.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides comprehensive documentation and React code examples for building chat interfaces using the assistant-ui library. It covers various UI primitives for threads, composers, and message rendering. No security risks or malicious patterns were identified during the analysis.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer9mo

    5 files scanned · No issues

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at b0609e6. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 weeks ago.

Activeupdated 2 months ago
  • React
  • assistant-ui
  • primitives
  • radix-ui
  • unstyled-components
  • chat-ui
  • composer
  • message-rendering
  • thread

README badge

README badge for assistant-ui/skills/primitives

Builds custom assistant chat UIs from composable, unstyled @assistant-ui/react primitives (ThreadPrimitive, ComposerPrimitive, MessagePrimitive, ActionBarPrimitive, and others) following Radix UI patterns. Use when you need fine-grained control over thread rendering, message parts (text, image, reasoning, tool-call), composer behavior, and action bars, and are willing to supply your own styling via className.

Generated from the current SKILL.md.

Are these components styled by default?
No. The primitives ship unstyled and require you to add className and apply your own Tailwind, CSS, or styling system.
What do I need to wrap primitives in?
Primitives must be wrapped in AssistantRuntimeProvider, and child primitives require their parent primitive to provide context.
How do I render different message types like text, images, and tool calls?
Use MessagePrimitive.Parts with a children render function that switches on part.type (text, image, reasoning, tool-call) and returns appropriate JSX for each.
Should I use .If or AuiIf for conditional rendering?
Prefer AuiIf for new code; the .If components on primitives are deprecated but still functional.
What's the difference between MessagePrimitive.Parts and MessagePrimitive.Content?
MessagePrimitive.Parts is the canonical API; MessagePrimitive.Content is a deprecated alias for the same functionality.

Generated from the current SKILL.md. These answers refresh after source changes.