Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(assistant-ui): make thread list item reusable by host adapters

Steven Enamakelb390234efafc
diff --git a/app/src/components/assistant-ui/thread-list.tsx b/app/src/components/assistant-ui/thread-list.tsx
index d470a9eac7..db19d3fa15 100644
--- a/app/src/components/assistant-ui/thread-list.tsx
+++ b/app/src/components/assistant-ui/thread-list.tsx
@@ -1,48 +1,7 @@
'use client';
-/**
- * Upstream assistant-ui thread list. **Not mounted on `/chat`, and it cannot be
- * without a runtime change** — this note exists so that is not re-derived.
- *
- * It needs a runtime whose thread-list core is backed by a real adapter. The
- * only place it renders is `/dev/assistant-ui`, which runs
- * `useRemoteThreadListRuntime` with an `InMemoryThreadListAdapter`
- * (`pages/dev/assistant-ui-demo/MockRuntimeProvider.tsx`). Live chat runs a
- * different runtime family — `useExternalStoreRuntime`
- * (`providers/AssistantUiRuntimeProvider.tsx`) — whose thread-list core is a
- * stub when the adapter supplies no threads:
- *
- * ```js
- * // @assistant-ui/core, external-store-thread-list-runtime-core.js
- * _threads = DEFAULT_THREADS; // [DEFAULT_THREAD_ID]
- * const newThreadId = adapter.threadId ?? DEFAULT_THREAD_ID;
- * const newThreads = adapter.threads ?? EMPTY_ARRAY;
- * if (previousThreads !== newThreads) this._threads = ...; // same frozen
- * ``` // EMPTY_ARRAY, so
- * // never reassigned
- *
- * `useOpenHumanExternalStore` supplies neither `threads` nor `threadId`, so
- * `threadIds` stays `[DEFAULT_THREAD_ID]`. Mounted on `/chat` this renders
- * exactly ONE untitled row showing its `fallback="New Chat"`, no matter how many
- * threads exist — and `hasThreads` below is permanently true, because 1 > 0. It
- * would not look broken. It would look like data that had not loaded yet, which
- * is why this note is here rather than left to be discovered.
- *
- * Adoption costs one of:
- * 1. Supply `threads` + `threadId` on the external-store adapter, plus
- * switch / archive / new handlers. This includes making `mainThreadId` real
- * — the identity key composer state, thread-list rows and subscription
- * teardown all hang off — which was deliberately declined in #6475 as too
- * broad for the bug at hand. The real thread id currently travels
- * out-of-band through `AuiThreadIdContext` instead.
- * 2. Migrate the chat surface to `useRemoteThreadListRuntime`, as the demo does.
- *
- * Neither buys a capability we lack: `features/conversations/threadList/
- * ThreadList.tsx` is live on `/chat` and already does selection, inline rename,
- * delete and search-filtered rows.
- *
- * Kept rather than deleted because the demo is the only worked reference for
- * what adoption would actually require.
+/** assistant-ui registry thread list, shared by the live sidebar and demo.
+ * Host adapters supply list data and callbacks; optional row slots add product metadata.
*/
import { cn } from '@/components/assistant-ui/lib/utils';
import { Button } from '@/components/assistant-ui/ui/button';
@@ -69,6 +28,7 @@ import {
import {
type ComponentPropsWithoutRef,
type FC,
+ type ReactNode,
forwardRef,
Fragment,
useEffect,
@@ -292,9 +252,17 @@ const ThreadListSkeleton: FC = () => {
);
};
-const ThreadListItem: FC = () => {
+export const ThreadListItem: FC<{
+ className?: string;
+ running?: boolean;
+ trailing?: ReactNode;
+ menuExtras?: ReactNode;
+ showArchive?: boolean;
+ triggerProps?: ComponentPropsWithoutRef<'button'>;
+}> = ({ className, running, trailing, menuExtras, showArchive = true, triggerProps }) => {
const { t } = useT();
- const isRunning = useAuiState(s => s.threadListItem.isRunning);
+ const runtimeRunning = useAuiState(s => s.threadListItem.isRunning);
+ const isRunning = running ?? runtimeRunning;
const [isRenaming, setIsRenaming] = useState(false);
const triggerRef = useRef<HTMLButtonElement>(null);
const restoreFocusRef = useRef(false);
@@ -308,7 +276,7 @@ const ThreadListItem: FC = () => {
return (
<ThreadListItemPrimitive.Root
data-slot="aui_thread-list-item"
- className="group hover:bg-muted focus-visible:bg-muted data-active:bg-muted has-focus-visible:bg-muted has-data-[state=open]:bg-muted relative flex h-8 items-center rounded-md transition-colors focus-visible:outline-none">
+ className={cn('group hover:bg-muted focus-visible:bg-muted data-active:bg-muted has-focus-visible:bg-muted has-data-[state=open]:bg-muted relative flex h-8 items-center rounded-md transition-colors focus-visible:outline-none', className)}>
{isRenaming ? (
<ThreadListItemRename
onDone={restoreFocus => {
@@ -319,6 +287,7 @@ const ThreadListItem: FC = () => {
) : (
<ThreadListItemPrimitive.Trigger
ref={triggerRef}
+ {...triggerProps}
data-slot="aui_thread-list-item-trigger"
className="focus-visible:ring-ring/50 flex h-full min-w-0 flex-1 items-center rounded-md px-2.5 text-start text-sm outline-none group-hover:pe-9 group-has-focus-visible:pe-9 group-has-data-[state=open]:pe-9 group-data-active:pe-9 focus-visible:ring-1">
{isRunning && (
@@ -329,8 +298,9 @@ const ThreadListItem: FC = () => {
/>
)}
<span data-slot="aui_thread-list-item-title" className="min-w-0 flex-1 truncate">
- <ThreadListItemPrimitive.Title fallback="New Chat" />
+ <ThreadListItemPrimitive.Title fallback={t('chat.untitledThread')} />
</span>
+ {trailing}
{isRunning && (
<span className="sr-only">
{t('conversations.backgroundTasks.statusRunning', 'Running')}
@@ -338,7 +308,7 @@ const ThreadListItem: FC = () => {
)}
</ThreadListItemPrimitive.Trigger>
)}
- <ThreadListItemMore onRename={() => setIsRenaming(true)} />
+ <ThreadListItemMore onRename={() => setIsRenaming(true)} showArchive={showArchive} extras={menuExtras} />
</ThreadListItemPrimitive.Root>
);
};
@@ -388,12 +358,14 @@ const ThreadListItemRename: FC<{ onDone: (restoreFocus: boolean) => void }> = ({
ref={inputRef}
autoFocus
data-slot="aui_thread-list-item-rename"
+ data-testid={`thread-title-input-${aui.threadListItem.getState().id}`}
aria-label={t('assistantUi.threadList.renameThread', 'Rename thread')}
value={value}
className="h-7 min-w-0 flex-1 ps-2.5 pe-9 text-sm"
onChange={event => setValue(event.target.value)}
onBlur={() => commit(false)}
onKeyDown={event => {
+ if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return;
if (event.key === 'Enter') {
event.preventDefault();
commit(true);
@@ -406,7 +378,7 @@ const ThreadListItemRename: FC<{ onDone: (restoreFocus: boolean) => void }> = ({
);
};
-const ThreadListItemMore: FC<{ onRename: () => void }> = ({ onRename }) => {
+const ThreadListItemMore: FC<{ onRename: () => void; showArchive: boolean; extras?: ReactNode }> = ({ onRename, showArchive, extras }) => {
const { t } = useT();
return (
<ThreadListItemMorePrimitive.Root sharedFocusGroup>
@@ -435,7 +407,8 @@ const ThreadListItemMore: FC<{ onRename: () => void }> = ({ onRename }) => {
<PencilIcon className="size-4" />
{t('assistantUi.threadList.rename', 'Rename')}
</ThreadListItemMorePrimitive.Item>
- <ThreadListItemPrimitive.Archive
+ {extras}
+ {showArchive && <ThreadListItemPrimitive.Archive
render={
<ThreadListItemMorePrimitive.Item
data-slot="aui_thread-list-item-more-item"
@@ -444,7 +417,7 @@ const ThreadListItemMore: FC<{ onRename: () => void }> = ({ onRename }) => {
}>
<ArchiveIcon className="size-4" />
{t('assistantUi.threadList.archive', 'Archive')}
- </ThreadListItemPrimitive.Archive>
+ </ThreadListItemPrimitive.Archive>}
<ThreadListItemPrimitive.Delete
render={
<ThreadListItemMorePrimitive.Item