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

/thread-list

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

Builds and customizes multiple conversation lists in assistant-ui with the runtime connected ThreadList and ThreadListSidebar elements, ThreadListPrimitive, ThreadListItemPrimitive, ThreadListItemMorePrimitive, useAui, useAuiState, and threads.selectionChanged. Use when adding a conversation sidebar, switching, archiving, renaming, deleting, searching, grouping, paginating, or persisting threads, or when thread state is stale after authentication. Covers AssistantCloud, RemoteThreadListRuntime, and ExternalStoreThreadListAdapter. Use runtime for the active conversation runtime, cloud for managed authentication and persistence, and elements for registry installation and styling.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesremote-adapter.md

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

Remote and External Thread Adapters

Use a RemoteThreadListAdapter when a LocalRuntime based runtime should store thread metadata in the application's backend. Use ExternalStoreThreadListAdapter only when an ExternalStoreRuntime already owns thread and message state.

Contents

Remote Adapter Contract

Keep the adapter reference stable at module scope or with useMemo. Replacing it reloads the list and discards cached threads not present in the replacement page.

Member Required Contract
list Yes (params?: { after?: string }) => Promise<{ threads: RemoteThreadMetadata[]; nextCursor?: string }>. Each row needs status and remoteId. title, externalId, and custom are optional.
initialize Yes (localId: string) => Promise<{ remoteId: string; externalId?: string }>. Creates the remote record and returns its canonical identities.
rename Yes (remoteId: string, title: string) => Promise<void>. Persists an item title.
updateCustom No (remoteId: string, custom: Record<string, unknown> | undefined) => Promise<void>. Persists replacement custom metadata.
archive Yes (remoteId: string) => Promise<void>. Archives a thread.
unarchive Yes (remoteId: string) => Promise<void>. Restores an archived thread.
delete Yes (remoteId: string) => Promise<void>. Permanently removes a thread.
fetch Yes (threadId: string) => Promise<RemoteThreadMetadata>. Fetches item metadata when switching.
generateTitle Yes (remoteId: string, messages: readonly ThreadMessage[]) => Promise<AssistantStream>. Streams a generated title.
unstable_Provider No RemoteThreadListProviderComponent. React component face for thread scoped runtime adapters.
unstable_useAdapters No () => RuntimeAdapters | null | undefined. Hook face for thread scoped runtime adapters.

list() receives no after for its first page. Return nextCursor to enable aui.threads.loadMore(). fetch() and list() should return updated custom fields when another backend path changes metadata.

Store Entry and Background Threads

Use RemoteThreadList as the threads entry in AuiConfig hosts. Wrap the thread factory with withKey from @assistant-ui/tap. History adapters load once per mount, so an unkeyed factory retains the previous thread's messages after a switch.

import { AuiConfig, RemoteThreadList } from "@assistant-ui/react";
import { withKey } from "@assistant-ui/tap";

const config = AuiConfig({
  threads: RemoteThreadList({
    adapter,
    thread: (id) => withKey(id, MyThread({ threadId: id })),
    backgroundThreads: true,
  }),
});

With backgroundThreads: true, every visited thread remains mounted. Its run can continue across a selection change, each item retains live isRunning state, and a newly initialized thread can title itself. This trades memory for continuity. Without it, only the visible thread is mounted.

History Adapter Faces

RemoteThreadListAdapter owns metadata, not messages or attachments. Add per thread adapters through one of two mutually related faces.

Face Who calls it When to use it
unstable_useAdapters RemoteThreadList store entry, and useRemoteThreadListRuntime when unstable_Provider is omitted A hook can provide history, attachments, or other runtime adapters in a client tree
unstable_Provider useRemoteThreadListRuntime only A React wrapper needs to provide adapters around the active thread

The store entry ignores unstable_Provider. A provider must render children synchronously on its first commit. Do not place children behind loading state, Suspense, or an effect.

import {
  RuntimeAdapterProvider,
  useAui,
  type RemoteThreadListAdapter,
} from "@assistant-ui/react";
import { useMemo } from "react";

function useThreadAdapters() {
  const aui = useAui();
  const history = useMemo(
    () => ({
      async load() {
        const { remoteId } = aui.threadListItem.getState();
        if (!remoteId) return { messages: [] };
        return loadMessages(remoteId);
      },
      async append({ message, parentId }: { message: unknown; parentId?: string }) {
        const { remoteId } = await aui.threadListItem.initialize();
        await saveMessage(remoteId, parentId, message);
      },
    }),
    [aui],
  );

  return useMemo(() => ({ history }), [history]);
}

const adapter = {
  ...metadataAdapter,
  unstable_useAdapters: useThreadAdapters,
  unstable_Provider({ children }) {
    const adapters = useThreadAdapters();
    return <RuntimeAdapterProvider adapters={adapters}>{children}</RuntimeAdapterProvider>;
  },
} satisfies RemoteThreadListAdapter;

Share the hook between both faces only when the React runtime path also needs the provider. When unstable_Provider is absent, useRemoteThreadListRuntime uses unstable_useAdapters itself.

Initialize Before Writing

The first message can be dispatched before the backend record exists. Await aui.threadListItem.initialize() in a history adapter, external dispatcher, or backend writer that requires a remote identity. The runtime intentionally does not delay the visible message until initialization completes.

async function append(message: unknown, parentId: string | undefined) {
  const { remoteId } = await aui.threadListItem.initialize();
  await saveMessage(remoteId, parentId, message);
}

async function onNew(message: unknown) {
  const { remoteId } = await aui.threadListItem.initialize();
  await sendToBackend(remoteId, message);
}

Repeated initialize() calls for the active thread resolve to the same remoteId.

Reload After Authentication

An adapter whose list() uses an OIDC, NextAuth, Clerk, or better-auth identity may run before that identity resolves. Reload when authentication becomes ready. Recreated adapters on a RemoteThreadList store entry do nothing until this call.

import { useAui } from "@assistant-ui/react";
import { useEffect } from "react";

export function ReloadThreadsAfterAuth({
  isLoading,
  userId,
}: {
  isLoading: boolean;
  userId: string | undefined;
}) {
  const aui = useAui();

  useEffect(() => {
    if (!isLoading && userId) aui.threads.reload();
  }, [aui, isLoading, userId]);

  return null;
}

reload() against the same adapter refreshes metadata and keeps the open thread. A different adapter resets selection and cached records before loading its page. It ignores in flight results from superseded calls.

External Store Adapter

ExternalStoreThreadListAdapter is synchronous and inline. It is not a remote adapter replacement. The application keeps metadata, selected ID, and messages in one external store, then gives the runtime functions that update that store.

import {
  type ExternalStoreThreadListAdapter,
  useExternalStoreRuntime,
} from "@assistant-ui/react";

const threadListAdapter: ExternalStoreThreadListAdapter = {
  threadId: store.selectedThreadId,
  threads: store.threads.filter((thread) => thread.status === "regular"),
  archivedThreads: store.threads.filter((thread) => thread.status === "archived"),
  onSwitchToNewThread: store.createAndSelectThread,
  onSwitchToThread: store.selectThread,
  onRename: store.renameThread,
  onArchive: store.archiveThread,
  onUnarchive: store.unarchiveThread,
  onDelete: store.deleteThread,
};

const runtime = useExternalStoreRuntime({
  messages: store.messagesByThread.get(store.selectedThreadId) ?? [],
  setMessages: (messages) => store.setMessages(store.selectedThreadId, messages),
  onNew: store.sendMessage,
  adapters: { threadList: threadListAdapter },
});

Keep threadId and the external store's selected ID synchronized. If they diverge, messages can appear under the wrong conversation or disappear from the active view. Centralize selection in the store or a shared context, not component local state.

Source: SKILL.md on GitHub

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

    The skill provides a well-structured and safe framework for building conversation thread management interfaces. It correctly follows security best practices by using environment variables for configuration and leveraging official vendor packages. A minor risk is present regarding the processing of thread titles and metadata, which could serve as a surface for indirect prompt injection if an agent interprets them as instructions without validation.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer9mo

    1/3 files flagged

  • 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 3 months ago
  • React
  • TypeScript
  • assistant-ui
  • thread-management
  • chat-ui
  • conversation-history
  • cloud-persistence
  • custom-components

README badge

README badge for assistant-ui/skills/thread-list

Implements multi-thread conversation management for assistant-ui apps using a prebuilt ThreadList component or custom primitives (ThreadListPrimitive, ThreadListItemPrimitive). Handles thread CRUD operations (create, switch, rename, archive, delete) via the useAui API, with optional cloud persistence through AssistantCloud or local in-memory storage.

Generated from the current SKILL.md.

Does this skill work without cloud persistence?
Yes. You can use `useRemoteThreadListRuntime` with `InMemoryThreadListAdapter` for local-only thread management, though threads will not persist across sessions.
Can I build a custom thread list UI?
Yes. Use `ThreadListPrimitive` and `ThreadListItemPrimitive` components to compose a custom sidebar with full control over layout, styling, and actions like archive, delete, and rename.
What thread operations are available?
You can switch threads, create new threads, rename, archive, unarchive, delete, generate titles, and read thread IDs and archived status via the `useAui()` and `useAuiState()` hooks.
Do I need AssistantCloud for thread persistence?
Yes. Cloud-backed persistence requires `AssistantCloud` configured with your auth token and base URL passed to `useChatRuntime`.

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