Skip to content

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

feat(conversation): wrap transcript rows in assistant-ui message scope

Steven Enamakel84736761c9a8
diff --git a/app/src/components/ai-elements/Conversation.tsx b/app/src/components/ai-elements/Conversation.tsx
index 010500c051..c85e17dbc7 100644
--- a/app/src/components/ai-elements/Conversation.tsx
+++ b/app/src/components/ai-elements/Conversation.tsx
@@ -1,60 +1,44 @@
/**
- * Adapted from `conversation.tsx` in vercel/ai-elements (Apache-2.0).
- * Upstream: https://github.com/vercel/ai-elements — registry component
- * `conversation`.
+ * The conversation viewport is assistant-ui's core `ThreadPrimitive.Viewport`
+ * when a runtime is available. The small DOM fallback keeps this shared shell
+ * usable by isolated render tests and non-chat previews that intentionally do
+ * not mount an assistant-ui runtime.
*
- * Port notes (this is an adaptation, not a copy):
- * - Upstream is built on the `use-stick-to-bottom` package: `Conversation` IS
- * `<StickToBottom>` and `ConversationContent` IS `<StickToBottom.Content>`.
- * That package is not a dependency here — this app already owns
- * `hooks/useStickToBottom`, which pins the same behaviour (thread-swap snap,
- * scroll-up disengage, ResizeObserver on streamed growth) and hands back a
- * container ref. So `Conversation` is a plain scroll container that FORWARDS
- * ITS REF, and the host wires that ref to the hook. The anchoring stays the
- * host's, which matters: the hook's contract is keyed on the message array
- * and the thread id, neither of which this component can see.
- * - `overflow-y-hidden` upstream becomes `overflow-y-auto` for the same reason:
- * the package moves the scroll onto its own inner content element, and
- * without it the scroll belongs to this container.
- * - `min-h-0` added. This is a `flex-1` child of a column flex parent, and
- * without it the basis-0 child refuses to shrink below its content height,
- * so a short window pushes the composer off-screen instead of scrolling
- * (#3785).
- * - `role="log"` is upstream's and is kept: it is what makes a screen reader
- * announce arriving turns.
- * - `ConversationScrollButton` is NOT ported. It reads `isAtBottom` from
- * `useStickToBottomContext`, and this app's hook deliberately keeps its
- * "am I stuck to the bottom" state in a ref (it is read inside a scroll
- * handler and must not re-render the transcript on every scroll frame), so
- * there is nothing to render the button off. Reinstating it means giving the
- * hook a throttled piece of state first.
- * - `ConversationDownload` / `messagesToMarkdown` are NOT ported: they are
- * typed on the `ai` SDK's `UIMessage` and there is no download affordance in
- * this product.
- * - `ConversationEmptyState` is NOT ported: every host of the transcript passes
- * its own `emptyContent` element, so a second empty state would be dead code.
- * - `data-slot` attributes added so tests assert structure, not class strings.
*/
import { forwardRef, type HTMLAttributes } from 'react';
+import { type AssistantState, ThreadPrimitive, useAuiState } from '@assistant-ui/react';
import { cn } from '../../lib/cn';
export type ConversationProps = HTMLAttributes<HTMLDivElement>;
+const selectHasThreadRuntime = (state: AssistantState) => state.optional.thread != null;
+
/**
* The transcript's scroll viewport. Attach the ref returned by
* `useStickToBottom` to keep it pinned as turns arrive.
*/
export const Conversation = forwardRef<HTMLDivElement, ConversationProps>(
- ({ className, ...props }, ref) => (
- <div
- ref={ref}
- data-slot="conversation"
- role="log"
- className={cn('relative min-h-0 flex-1 overflow-y-auto', className)}
- {...props}
- />
- )
+ ({ className, ...props }, ref) => {
+ const hasThreadRuntime = useAuiState(selectHasThreadRuntime);
+ const viewportProps = {
+ ref,
+ 'data-slot': 'conversation',
+ role: 'log',
+ className: cn('relative min-h-0 flex-1 overflow-y-auto', className),
+ ...props,
+ };
+
+ // OpenHuman's richer transcript has tool timelines and streamed content
+ // outside assistant-ui's message list. Its existing hook remains the
+ // scroll authority; this viewport supplies assistant-ui's thread context
+ // and future core affordances without competing auto-scroll behavior.
+ return hasThreadRuntime ? (
+ <ThreadPrimitive.Viewport autoScroll={false} {...viewportProps} />
+ ) : (
+ <div {...viewportProps} />
+ );
+ }
);
Conversation.displayName = 'Conversation';
diff --git a/app/src/features/conversations/components/ChatThreadView.tsx b/app/src/features/conversations/components/ChatThreadView.tsx
index 1773094638..6feee66ac0 100644
--- a/app/src/features/conversations/components/ChatThreadView.tsx
+++ b/app/src/features/conversations/components/ChatThreadView.tsx
@@ -8,6 +8,12 @@ import {
useRef,
useState,
} from 'react';
+import {
+ type AssistantState,
+ MessagePrimitive,
+ ThreadPrimitive,
+ useAuiState,
+} from '@assistant-ui/react';
import { Conversation, ConversationContent } from '../../../components/ai-elements';
import { useStickToBottom } from '../../../hooks/useStickToBottom';
@@ -56,6 +62,28 @@ const EMPTY_TRANSCRIPT_ENTRIES: ToolTimelineEntry[] = [];
const EMPTY_TOOL_TIMELINE: ToolTimelineEntry[] = [];
const EMPTY_PROCESSING: ProcessingTranscriptItem[] = [];
+function AssistantMessageScope({ messageId, children }: { messageId: string; children: ReactNode }) {
+ const hasRuntimeMessage = useAuiState(
+ useCallback(
+ (state: AssistantState) =>
+ state.optional.thread?.messages.some(message => message.id === messageId) ?? false,
+ [messageId]
+ )
+ );
+
+ // The runtime deliberately contains only persisted chat messages plus its
+ // streaming tail. Tool timelines, interim narration, and parallel previews
+ // remain OpenHuman-specific siblings, but every settled turn now gets the
+ // core assistant-ui message scope for native hover/action/branch features.
+ if (!hasRuntimeMessage) return <>{children}</>;
+
+ return (
+ <ThreadPrimitive.Unstable_MessageById messageId={messageId}>
+ <MessagePrimitive.Root className="contents">{children}</MessagePrimitive.Root>
+ </ThreadPrimitive.Unstable_MessageById>
+ );
+}
+
export interface ChatThreadViewHandle {
/** Opens the detached background sub-agents panel — called from the host
* header's background-processes badge (`Conversations`' own copy of the
@@ -483,19 +511,21 @@ export const ChatThreadView = forwardRef<ChatThreadViewHandle, ChatThreadViewPro
`BranchPickerPrimitive` would attach INSIDE the row when
the adapter grows `onEdit` / `setMessages` — see
`EDIT_AND_BRANCH_SEAM` in `./aui/auiThreadState`. */}
- <TranscriptRow
- msg={msg}
- threadId={threadId}
- agentMessageViewMode={agentMessageViewMode}
- isLatestVisible={latestVisibleMessage?.id === msg.id}
- isCopied={copiedMessageId === msg.id}
- isReactionPickerOpen={reactionPickerMsgId === msg.id}
- pastTurn={pastTurnAnchors[msg.id]}
- shareAgentName={shareAgentName}
- onCopy={handleCopyMessage}
- onReact={handleReact}
- onOpenReactionPicker={setReactionPickerMsgId}
- />
+ <AssistantMessageScope messageId={msg.id}>
+ <TranscriptRow
+ msg={msg}
+ threadId={threadId}
+ agentMessageViewMode={agentMessageViewMode}
+ isLatestVisible={latestVisibleMessage?.id === msg.id}
+ isCopied={copiedMessageId === msg.id}
+ isReactionPickerOpen={reactionPickerMsgId === msg.id}
+ pastTurn={pastTurnAnchors[msg.id]}
+ shareAgentName={shareAgentName}
+ onCopy={handleCopyMessage}
+ onReact={handleReact}
+ onOpenReactionPicker={setReactionPickerMsgId}
+ />
+ </AssistantMessageScope>
{msg.id === lastUserMessageId ? agentInsights : null}
</Fragment>
))}