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.

referencespart-grouping.md

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

Message Part Grouping

Organize adjacent message parts into custom groups, and build chain of thought UI (reasoning and tool calls collapsed into a "thinking" accordion).

MessagePrimitive.GroupedParts

groupBy maps each part to a group key path (or null / [] to leave it ungrouped). Adjacent parts that resolve to the same path coalesce into one group node. The children render function receives { part, children } for both group nodes and leaf parts; only group cases should render children, leaf cases render their own UI.

import { MessagePrimitive, groupPartByType } from "@assistant-ui/react";

<MessagePrimitive.GroupedParts
  groupBy={groupPartByType({ "tool-call": ["group-tool"] })}
>
  {({ part, children }) => {
    switch (part.type) {
      case "group-tool":
        return <div className="group">{children}</div>;
      case "tool-call":
        return part.toolUI ?? <ToolFallback {...part} />;
      case "text":
        return <MarkdownText />;
      default:
        return null;
    }
  }}
</MessagePrimitive.GroupedParts>

groupPartByType builds groupBy from a part.type to path map; part types missing from the map are left ungrouped. Group keys must start with group- so the render function can tell synthetic groups from real part types. A group node has the shape:

type GroupPart<TKey extends `group-${string}` = `group-${string}`> = {
  readonly type: TKey;
  readonly status: MessagePartStatus | ToolCallMessagePartStatus;
  readonly indices: readonly number[];
};

Chain of thought

Group consecutive reasoning and tool-call parts under one outer key so they collapse into a single accordion:

import { MessagePrimitive, groupPartByType } from "@assistant-ui/react";
import { MarkdownText } from "@/components/assistant-ui/elements/markdown-text";
import {
  Reasoning, ReasoningContent, ReasoningRoot, ReasoningText, ReasoningTrigger,
} from "@/components/assistant-ui/elements/reasoning.aui";
import { ToolFallback } from "@/components/assistant-ui/elements/tool-fallback.aui";
import {
  ToolGroupContent, ToolGroupRoot, ToolGroupTrigger,
} from "@/components/assistant-ui/elements/tool-group.aui";

const AssistantMessage = () => (
  <MessagePrimitive.Root>
    <MessagePrimitive.GroupedParts
      groupBy={groupPartByType({
        reasoning: ["group-chainOfThought", "group-reasoning"],
        "tool-call": ["group-chainOfThought", "group-tool"],
      })}
    >
      {({ part, children }) => {
        switch (part.type) {
          case "group-chainOfThought":
            return <div className="my-2">{children}</div>;
          case "group-reasoning": {
            const running = part.status.type === "running";
            return (
              <ReasoningRoot streaming={running}>
                <ReasoningTrigger active={running} />
                <ReasoningContent aria-busy={running}>
                  <ReasoningText>{children}</ReasoningText>
                </ReasoningContent>
              </ReasoningRoot>
            );
          }
          case "group-tool":
            return (
              <ToolGroupRoot>
                <ToolGroupTrigger count={part.indices.length} active={part.status.type === "running"} />
                <ToolGroupContent>{children}</ToolGroupContent>
              </ToolGroupRoot>
            );
          case "text":
            return <MarkdownText />;
          case "reasoning":
            return <Reasoning {...part} />;
          case "tool-call":
            return part.toolUI ?? <ToolFallback {...part} />;
          default:
            return null;
        }
      }}
    </MessagePrimitive.GroupedParts>
  </MessagePrimitive.Root>
);

ReasoningRoot, ReasoningTrigger, ReasoningContent, ReasoningText, ToolGroupRoot, ToolGroupTrigger, ToolGroupContent come from the reasoning and tool-group elements (npx assistant-ui@latest add reasoning tool-group). LangGraph does not emit reasoning tokens in the AI SDK reasoning stream shape; to show LangGraph reasoning, emit it as a custom data part and render it with makeAssistantDataUI.

The older components.ChainOfThought prop on MessagePrimitive.Parts, and ChainOfThoughtPrimitive (.Root, .AccordionTrigger, .Parts) with its own AuiIf-driven collapsed state via s.chainOfThought.collapsed, still work but are legacy. Use GroupedParts in new code.

Grouping by parentId or tool name

groupBy is arbitrary; return any key starting with group- and branch on part.type.startsWith(...):

<MessagePrimitive.GroupedParts
  groupBy={(part) => (part.parentId ? [`group-parent-${part.parentId}`] : [])}
>
  {({ part, children }) => {
    if (part.type.startsWith("group-parent-")) {
      return <ParentGroup count={part.indices.length}>{children}</ParentGroup>;
    }
    if (part.type === "text") return <MarkdownText />;
    if (part.type === "tool-call") return part.toolUI ?? <ToolFallback {...part} />;
    return null;
  }}
</MessagePrimitive.GroupedParts>

Group by tool name the same way: groupBy={(part) => part.type === "tool-call" ? [\group-tool-${part.toolName}`] : []}`.

Standalone tool display

Tool UIs fall into three buckets: prompting the user (human in the loop), informing the user (generative UI), and traces of what the model did (routine calls). Mark a tool display: "standalone" to keep its UI out of the grouped trace; human tools and MCP apps are standalone automatically, everything else defaults to "inline".

const toolkit = defineToolkit({
  ask_user: { type: "human", render: AskUI },          // standalone, forced
  search_web: { type: "frontend", render: SearchUI },  // inline trace, default
  checkout: { type: "frontend", render: CheckoutUI, display: "standalone" },
});

The synthetic "standalone-tool-call" key matches all of these; GroupedParts passes the live tool UI registry to groupBy as a second context argument, so the helper resolves it without you threading anything through:

groupPartByType({
  reasoning: ["group-chainOfThought", "group-reasoning"],
  "tool-call": ["group-chainOfThought", "group-tool"],
  "standalone-tool-call": [], // rendered on its own, outside the group
})

The "mcp-app" key was removed in 0.15; "standalone-tool-call" is a superset covering MCP app calls plus any tool call whose registered UI opts into standalone display.

  groupPartByType({
    "tool-call": ["group-tool"],
-   "mcp-app": [],
+   "standalone-tool-call": [],
  })

Legacy: Unstable_PartsGrouped

Predates GroupedParts; accepts a groupingFunction returning non adjacency limited MessagePartGroup[] and a components map (Empty, Text, Reasoning, Source, Image, File, Unstable_Audio, tools, Group). Reach for it only when you need to collect non adjacent parts (for example every part sharing a parent id even with other parts between them) into one group; use GroupedParts for ordinary consecutive reasoning or tool grouping.

type MessagePartGroup = { groupKey: string | undefined; indices: number[] };

Notes

  • GroupedParts groups adjacent runs only; the same key appearing again after a gap starts a new group.
  • Always handle every part type your message can render, or those parts render nothing.
  • Group keys must start with group-.
  • Drive defaultOpen / streaming indicators off part.status.type === "running".

Common Gotchas

A leaf case renders children and throws

  • Leaf parts receive a sentinel children value. Only group cases (the ones you invented, prefixed group-) should render it.

Grouping "resets" partway through a message

  • GroupedParts only coalesces adjacent parts. If an unrelated part interrupts a run of reasoning parts, the next reasoning part starts a new group.

Old "mcp-app" groups stop matching after upgrading

  • That key was removed in 0.15. Replace it with "standalone-tool-call".

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.