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-input.md

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

Composer input extensions

ComposerPrimitive.Input is the normal textarea for a composer. This reference covers the cases where it needs a supporting hook, adapter, or primitive: a custom input surface, recalled drafts, dictation, quotes, and pending attachments.

Contents

Headless composer input

import {
  ComposerPrimitive,
  unstable_useComposerInput,
} from "@assistant-ui/react";

function HeadlessComposer() {
  const composer = unstable_useComposerInput();

  return (
    <ComposerPrimitive.Root>
      <textarea
        aria-label="Message"
        value={composer.value}
        disabled={composer.isDisabled}
        onChange={(event) => composer.setText(event.currentTarget.value)}
        onKeyDown={(event) => {
          if (event.nativeEvent.isComposing) return;
          if (event.key === "Enter" && !event.shiftKey && composer.canSend) {
            event.preventDefault();
            composer.send();
          }
        }}
      />
      <ComposerPrimitive.Send />
    </ComposerPrimitive.Root>
  );
}

Use unstable_useComposerInput only when an editor owns its DOM and state, such as a contentEditable implementation. It supplies value, setText, canSend, isDisabled, and send, but it does not recreate autosizing, paste attachments, focus handling, IME handling, trigger popovers, or keyboard shortcuts. Keep the explicit canSend guard in custom handlers because send() is otherwise a no op.

Input history

import {
  ComposerPrimitive,
  unstable_useComposerInputHistory,
} from "@assistant-ui/react";

function ComposerWithHistory() {
  const history = unstable_useComposerInputHistory();

  return (
    <ComposerPrimitive.Root>
      <ComposerPrimitive.Input {...history} />
      <ComposerPrimitive.Send>Send</ComposerPrimitive.Send>
    </ComposerPrimitive.Root>
  );
}

unstable_useComposerInputHistory recalls trimmed user messages with ArrowUp and ArrowDown when the new message composer is empty. It restores the original draft after the newest entry, yields to a mention or slash command popover, and does not affect an edit composer. It is unstable, so keep it near the input that consumes its event handlers.

Dictation

import {
  AssistantRuntimeProvider,
  AuiIf,
  ComposerPrimitive,
  WebSpeechDictationAdapter,
} from "@assistant-ui/react";
import { useChatRuntime } from "@assistant-ui/ai-sdk";

function RuntimeProvider({ children }: { children: React.ReactNode }) {
  const runtime = useChatRuntime({
    adapters: {
      dictation: new WebSpeechDictationAdapter({
        language: "en-US",
        continuous: true,
        interimResults: true,
      }),
    },
  });

  return <AssistantRuntimeProvider runtime={runtime}>{children}</AssistantRuntimeProvider>;
}

function DictationControls() {
  return (
    <>
      <AuiIf condition={(s) => s.composer.dictation == null}>
        <ComposerPrimitive.Dictate>Dictate</ComposerPrimitive.Dictate>
      </AuiIf>
      <AuiIf condition={(s) => s.composer.dictation != null}>
        <ComposerPrimitive.StopDictation>Stop</ComposerPrimitive.StopDictation>
      </AuiIf>
      <AuiIf condition={(s) => s.composer.dictation != null}>
        <ComposerPrimitive.DictationTranscript />
      </AuiIf>
    </>
  );
}

WebSpeechDictationAdapter uses the browser Web Speech API. Check WebSpeechDictationAdapter.isSupported() before advertising voice input when browser support is uncertain. A custom DictationAdapter can supply a server transcription or realtime provider. ComposerPrimitive.Dictate disables itself when no adapter is configured, and a send stops an active session.

Quoting

import {
  ComposerPrimitive,
  MessagePrimitive,
  SelectionToolbarPrimitive,
  ThreadPrimitive,
  useAui,
} from "@assistant-ui/react";

function QuotedThread() {
  return (
    <ThreadPrimitive.Root>
      <ThreadPrimitive.Viewport>
        <MessagePrimitive.Root>
          <p data-aui-quote-selectable>Quoteable assistant response.</p>
        </MessagePrimitive.Root>
      </ThreadPrimitive.Viewport>
      <SelectionToolbarPrimitive.Root>
        <SelectionToolbarPrimitive.Quote>Quote</SelectionToolbarPrimitive.Quote>
      </SelectionToolbarPrimitive.Root>
    </ThreadPrimitive.Root>
  );
}

function ComposerQuote() {
  return (
    <ComposerPrimitive.Quote>
      <ComposerPrimitive.QuoteText />
      <ComposerPrimitive.QuoteDismiss>Remove quote</ComposerPrimitive.QuoteDismiss>
    </ComposerPrimitive.Quote>
  );
}

function QuoteButton() {
  const aui = useAui();
  return (
    <button
      onClick={() =>
        aui.composer.setQuote({ text: "Quoted text", messageId: "message-id" })
      }
    >
      Quote text
    </button>
  );
}

Place SelectionToolbarPrimitive.Root inside ThreadPrimitive.Root. It creates a quote from a selection in one message part. Mark a text region with data-aui-quote-selectable to limit quoteable content, or set it to "false" to exclude an element. setQuote replaces the one pending quote, and aui.thread.composer().setQuote(...) reaches the thread composer from outside its local composer scope.

Quote metadata is attached to the sent user message, not its text content. Forward it to the model in the AI SDK route:

import { convertToModelMessages, streamText } from "ai";
import { injectQuoteContext } from "@assistant-ui/ai-sdk";

export async function POST(request: Request) {
  const { messages } = await request.json();
  const result = streamText({
    model: myModel,
    messages: await convertToModelMessages(injectQuoteContext(messages)),
  });

  return result.toUIMessageStreamResponse();
}

injectQuoteContext prepends the selected text as quote context before model message conversion. Without it, the quote is visible in the interface but absent from the model input.

Attachments

import {
  AssistantRuntimeProvider,
  AttachmentPrimitive,
  ComposerPrimitive,
  CompositeAttachmentAdapter,
  SimpleImageAttachmentAdapter,
  SimpleTextAttachmentAdapter,
  useAuiEvent,
} from "@assistant-ui/react";
import { useChatRuntime } from "@assistant-ui/ai-sdk";

const attachmentAdapter = new CompositeAttachmentAdapter([
  new SimpleImageAttachmentAdapter(),
  new SimpleTextAttachmentAdapter(),
]);

function RuntimeProvider({ children }: { children: React.ReactNode }) {
  const runtime = useChatRuntime({
    adapters: { attachments: attachmentAdapter },
  });

  return <AssistantRuntimeProvider runtime={runtime}>{children}</AssistantRuntimeProvider>;
}

function AttachmentErrorNotice() {
  useAuiEvent("composer.attachmentAddError", ({ reason, message }) => {
    console.error(reason, message);
  });
  return null;
}

function ComposerAttachments() {
  return (
    <ComposerPrimitive.AttachmentDropzone className="data-[dragging]:bg-muted">
      <ComposerPrimitive.Attachments>
        {() => (
          <AttachmentPrimitive.Root>
            <AttachmentPrimitive.unstable_Thumb />
            <AttachmentPrimitive.Name />
            <AttachmentPrimitive.Remove>Remove</AttachmentPrimitive.Remove>
          </AttachmentPrimitive.Root>
        )}
      </ComposerPrimitive.Attachments>
      <ComposerPrimitive.AddAttachment>Add file</ComposerPrimitive.AddAttachment>
      <ComposerPrimitive.Input />
    </ComposerPrimitive.AttachmentDropzone>
  );
}

useChatRuntime accepts files by default. Use SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, or CompositeAttachmentAdapter when the accepted types must be explicit. For remote files, CloudFileAttachmentAdapter owns the upload lifecycle; implement AttachmentAdapter for another source or validation policy.

ComposerPrimitive.Attachments iterates staged files and AttachmentPrimitive renders one attachment, including removal in a composer. ComposerPrimitive.AttachmentDropzone sets data-dragging while files hover over it. Subscribe to composer.attachmentAddError to surface no-adapter, not-accepted, and adapter-error failures. Sent message attachments are read only: render them with MessagePrimitive.Attachments as described in message.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.