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.

referencesthread.md

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

ThreadPrimitive

The scrollable message container: viewport management, auto scroll, the messages iterator, and the welcome suggestions grid. Root renders a <div>, Viewport a scrollable <div>, and Messages iterates the thread's messages, resolved by role and edit state.

Parts

Part Renders Notes
.Root <div> Top level container; provides thread context.
.Viewport <div> Scrollable area with auto scroll. See props below.
.ViewportProvider nothing Viewport context without a scrollable element, for a custom scroll container.
.ViewportFooter <div> Sticks to the bottom and registers its height with the auto scroll system. Put the composer here.
.Messages list Renders one component per message via a children render function { message }.
.MessageByIndex one message index plus components={{ Message }}; memoized on index and components identity.
.Unstable_MessageById one message messageId plus the same components surface; unknown ids render null. Experimental.
.ScrollToBottom <button> Auto disabled when already at the bottom.
.Suggestions list Renders the current suggestion set. See suggestions.md.
.SuggestionByIndex one suggestion index plus components={{ Suggestion }}.
.Suggestion <button> Self contained suggestion with prompt and send props (legacy; prefer Suggestions).
.Empty conditional Deprecated. Use AuiIf with s.thread.isEmpty.
.If conditional Deprecated. Use AuiIf.

Viewport and auto scroll

Viewport auto scrolls to the bottom as content streams in, unless the reader has scrolled up manually. Set autoScroll={false} to disable it outright.

<ThreadPrimitive.Viewport autoScroll={true}>
  {/* messages */}
</ThreadPrimitive.Viewport>

With turnAnchor="top", the latest user message anchors to the top of the viewport instead of the reply scrolling the page down, the layout the Thread element uses by default. MessagePrimitive.Root registers the top anchor target automatically; no extra component is needed.

<ThreadPrimitive.Viewport
  turnAnchor="top"
  topAnchorMessageClamp={{ tallerThan: "10em", visibleHeight: "6em" }}
>
  {/* messages */}
</ThreadPrimitive.Viewport>

topAnchorMessageClamp controls how much of a long user message stays visible above the growing response: messages shorter than tallerThan stay fully visible, taller ones clip to visibleHeight of their bottom edge.

Three event specific flags layer on top of autoScroll (all default true): scrollToBottomOnRunStart (fires on thread.runStart), scrollToBottomOnInitialize (on thread.initialize), and scrollToBottomOnThreadSwitch (on threads.selectionChanged). When autoScroll is left unset it defaults to true for turnAnchor="bottom" and false for turnAnchor="top".

<ThreadPrimitive.Viewport
  turnAnchor="top"
  autoScroll={false}
  scrollToBottomOnRunStart={true}
  scrollToBottomOnThreadSwitch={true}
  scrollToBottomOnInitialize={false}
>
  <ThreadPrimitive.Messages>
    {({ message }) => (message.role === "user" ? <UserMessage /> : <AssistantMessage />)}
  </ThreadPrimitive.Messages>
</ThreadPrimitive.Viewport>

ViewportFooter and a custom scroll container

ViewportFooter sticks to the bottom and reserves its own height so auto scroll accounts for it, which is where the composer belongs:

<ThreadPrimitive.Viewport>
  <ThreadPrimitive.Messages>{() => <MyMessage />}</ThreadPrimitive.Messages>
  <ThreadPrimitive.ViewportFooter className="sticky bottom-0">
    <MyComposer />
  </ThreadPrimitive.ViewportFooter>
</ThreadPrimitive.Viewport>

When you own the scroll container yourself (a Radix ScrollArea, a virtualized list, see messages.md), swap Viewport for ViewportProvider: it supplies the same context with no scrollable element of its own.

<ThreadPrimitive.ViewportProvider>
  <div className="flex-1 overflow-y-auto">
    <ThreadPrimitive.Messages>{() => <MyMessage />}</ThreadPrimitive.Messages>
    <ThreadPrimitive.ViewportFooter>
      <MyComposer />
    </ThreadPrimitive.ViewportFooter>
  </div>
</ThreadPrimitive.ViewportProvider>

Messages iterator

Messages takes a children render function over { message } so you can branch on role and edit state inline, including swapping in an edit composer:

<ThreadPrimitive.Messages>
  {({ message }) => {
    if (message.composer.isEditing) return <MyEditComposer />;
    if (message.role === "user") return <MyUserMessage />;
    return <MyAssistantMessage />;
  }}
</ThreadPrimitive.Messages>

The deprecated components prop still works but only accepts a fixed { UserMessage, AssistantMessage, EditComposer, ... } map; prefer children for new code, since it lets you inspect the message before choosing a component. For a thread with hundreds or thousands of messages, render by id instead of relying on the built in iterator: see Virtualization.

ScrollToBottom and Suggestions

<ThreadPrimitive.ScrollToBottom className="rounded-full bg-background p-2 shadow-md">
  <ArrowDownIcon />
</ThreadPrimitive.ScrollToBottom>

ScrollToBottom renders null while the viewport is already pinned to the bottom, so it needs no manual visibility check.

<ThreadPrimitive.Suggestions>
  {({ suggestion }) => <MySuggestionButton prompt={suggestion.prompt} />}
</ThreadPrimitive.Suggestions>

Suggestions and SuggestionByIndex render whatever the suggestions scope currently holds, static welcome prompts or runtime driven follow ups. The full configuration surface, the SuggestionPrimitive parts, and the suggestion adapter live in suggestions.md.

Patterns

Welcome screen with suggestions

<AuiIf condition={(s) => s.thread.isEmpty}>
  <div className="flex flex-col items-center gap-4 text-center">
    <h2>What can I help with?</h2>
    <div className="grid grid-cols-2 gap-2">
      <ThreadPrimitive.Suggestions>{() => <MySuggestionButton />}</ThreadPrimitive.Suggestions>
    </div>
  </div>
</AuiIf>

Turn anchor top layout

<ThreadPrimitive.Root className="flex h-full flex-col">
  <ThreadPrimitive.Viewport turnAnchor="top" className="flex-1 overflow-y-auto">
    <ThreadPrimitive.Messages>
      {({ message }) => (message.role === "user" ? <UserMessage /> : <AssistantMessage />)}
    </ThreadPrimitive.Messages>
    <ThreadPrimitive.ViewportFooter className="sticky bottom-0">
      <MyComposer />
    </ThreadPrimitive.ViewportFooter>
  </ThreadPrimitive.Viewport>
</ThreadPrimitive.Root>

Custom message components

<ThreadPrimitive.Messages>
  {({ message }) => {
    if (message.role === "user") {
      return (
        <MessagePrimitive.Root>
          <div className="ml-auto rounded-xl bg-blue-500 p-3 text-white">
            <MessagePrimitive.Parts />
          </div>
        </MessagePrimitive.Root>
      );
    }
    return (
      <MessagePrimitive.Root>
        <div className="rounded-xl bg-gray-100 p-3">
          <MessagePrimitive.Parts />
        </div>
      </MessagePrimitive.Root>
    );
  }}
</ThreadPrimitive.Messages>

Common Gotchas

ViewportSlack import fails

  • ThreadPrimitive.ViewportSlack was removed from the public API. Top anchor registration is automatic inside MessagePrimitive.Root when turnAnchor="top"; move any fillClampThreshold / fillClampOffset customization to topAnchorMessageClamp on Viewport.

Welcome screen and skeleton both trying to show at once

  • Treat "no messages" and "still loading" as different states: the Thread element shows the welcome screen only when there are no messages and either nothing is loading or the whole thread list is still loading, and reserves a history skeleton for a thread switch whose own history is still in flight.

ThreadPrimitive.Empty / .If render stale content

  • Both are deprecated wrappers around a fixed set of conditions. Replace them with AuiIf (s.thread.isEmpty, s.thread.isRunning, s.thread.isDisabled), which accepts any selector over the full assistant state.

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.