The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(ai-elements): handle empty conversation gracefully
Steven Enamakel972f79d56878
diff --git a/app/src/components/ai-elements/Conversation.test.tsx b/app/src/components/ai-elements/Conversation.test.tsxdeleted file mode 100644index 8578842153..0000000000--- a/app/src/components/ai-elements/Conversation.test.tsx+++ /dev/null@@ -1,60 +0,0 @@-import { render, screen } from '@testing-library/react';-import { createRef } from 'react';-import { describe, expect, it } from 'vitest';--import { Conversation, ConversationContent } from './Conversation';--const RAW_PALETTE =- /\b(?:bg|text|border|ring)-(?:neutral|stone|slate|zinc|gray|canvas|white|black)\b/;--const collectClasses = (root: HTMLElement) =>- [root, ...Array.from(root.querySelectorAll<HTMLElement>('*'))]- .map(el => el.getAttribute('class') ?? '')- .join(' ');--describe('Conversation', () => {- it('exposes the scroll viewport as a log region', () => {- render(<Conversation data-testid="viewport" />);-- const viewport = screen.getByTestId('viewport');- expect(viewport).toHaveAttribute('data-slot', 'conversation');- expect(viewport).toHaveAttribute('role', 'log');- });-- it('forwards its ref, which is how the host wires stick-to-bottom', () => {- const ref = createRef<HTMLDivElement>();- render(<Conversation ref={ref} data-testid="viewport" />);-- expect(ref.current).toBe(screen.getByTestId('viewport'));- });-- it('renders the turn column and its children', () => {- render(- <Conversation>- <ConversationContent data-testid="content">- <span>One turn</span>- </ConversationContent>- </Conversation>- );-- const content = screen.getByTestId('content');- expect(content).toHaveAttribute('data-slot', 'conversation-content');- expect(content).toHaveTextContent('One turn');- });-- it('keeps a caller className alongside the shell classes', () => {- render(<ConversationContent data-testid="content" className="px-5" />);-- expect(screen.getByTestId('content').getAttribute('class')).toContain('px-5');- });-- it('uses no raw palette classes', () => {- const { container } = render(- <Conversation>- <ConversationContent />- </Conversation>- );-- expect(collectClasses(container)).not.toMatch(RAW_PALETTE);- });-});diff --git a/app/src/components/ai-elements/Conversation.tsx b/app/src/components/ai-elements/Conversation.tsxdeleted file mode 100644index 95c619eca4..0000000000--- a/app/src/components/ai-elements/Conversation.tsx+++ /dev/null@@ -1,59 +0,0 @@-/**- * 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.- */-import { type AssistantState, ThreadPrimitive, useAuiState } from '@assistant-ui/react';-import { forwardRef, type HTMLAttributes } from '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) => {- 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.Root className="contents">- <ThreadPrimitive.Viewport autoScroll={false} {...viewportProps} />- </ThreadPrimitive.Root>- ) : (- <div {...viewportProps} />- );- }-);-Conversation.displayName = 'Conversation';--export type ConversationContentProps = HTMLAttributes<HTMLDivElement>;--/** The column of turns inside the viewport. */-export const ConversationContent = forwardRef<HTMLDivElement, ConversationContentProps>(- ({ className, ...props }, ref) => (- <div- ref={ref}- data-slot="conversation-content"- className={cn('flex w-full flex-col', className)}- {...props}- />- )-);-ConversationContent.displayName = 'ConversationContent';diff --git a/app/src/components/ai-elements/Message.test.tsx b/app/src/components/ai-elements/Message.test.tsxdeleted file mode 100644index 3cdddbef39..0000000000--- a/app/src/components/ai-elements/Message.test.tsx+++ /dev/null@@ -1,113 +0,0 @@-import { render, screen } from '@testing-library/react';-import userEvent from '@testing-library/user-event';-import { createRef } from 'react';-import { describe, expect, it, vi } from 'vitest';--import { Message, MessageAction, MessageActions, MessageContent } from './Message';--const RAW_PALETTE =- /\b(?:bg|text|border|ring)-(?:neutral|stone|slate|zinc|gray|canvas|white|black)\b/;--const collectClasses = (root: HTMLElement) =>- [root, ...Array.from(root.querySelectorAll<HTMLElement>('*'))]- .map(el => el.getAttribute('class') ?? '')- .join(' ');--describe('Message', () => {- it('marks a user turn as trailing-aligned', () => {- render(- <Message from="user" data-testid="row">- Hi- </Message>- );-- const row = screen.getByTestId('row');- expect(row).toHaveAttribute('data-slot', 'message');- expect(row).toHaveAttribute('data-from', 'user');- });-- it("treats this app's `agent` spelling as the assistant side", () => {- render(- <Message from="agent" data-testid="row">- Hello- </Message>- );-- expect(screen.getByTestId('row')).toHaveAttribute('data-from', 'assistant');- });-- it('forwards a ref to the row element', () => {- const ref = createRef<HTMLDivElement>();- render(<Message from="assistant" ref={ref} data-testid="row" />);-- expect(ref.current).toBe(screen.getByTestId('row'));- });-- it('keeps caller-supplied attributes such as the transcript test hooks', () => {- render(<Message from="agent" data-testid="chat-message-row" data-sender="agent" />);-- expect(screen.getByTestId('chat-message-row')).toHaveAttribute('data-sender', 'agent');- });-});--describe('MessageContent', () => {- it('renders its children in a content slot', () => {- render(- <MessageContent data-testid="content">- <span>Body</span>- </MessageContent>- );-- const content = screen.getByTestId('content');- expect(content).toHaveAttribute('data-slot', 'message-content');- expect(content).toHaveTextContent('Body');- });-});--describe('MessageActions', () => {- it('groups its affordances in an actions slot', () => {- render(- <MessageActions data-testid="actions">- <MessageAction label="Copy">·</MessageAction>- </MessageActions>- );-- expect(screen.getByTestId('actions')).toHaveAttribute('data-slot', 'message-actions');- expect(screen.getByRole('button', { name: 'Copy' })).toBeInTheDocument();- });-});--describe('MessageAction', () => {- it('names an icon-only button through its label and fires on click', async () => {- const user = userEvent.setup();- const onClick = vi.fn();- render(- <MessageAction label="Copy response" onClick={onClick} analyticsId="chat-message-copy">- <svg />- </MessageAction>- );-- const button = screen.getByRole('button', { name: 'Copy response' });- expect(button).toHaveAttribute('data-slot', 'message-action');- expect(button).toHaveAttribute('type', 'button');- expect(button).toHaveAttribute('title', 'Copy response');- expect(button).toHaveAttribute('data-analytics-id', 'chat-message-copy');-- await user.click(button);- expect(onClick).toHaveBeenCalledTimes(1);- });-- it('uses no raw palette classes anywhere in the family', () => {- const { container } = render(- <Message from="user">- <MessageContent>- <MessageActions>- <MessageAction label="Copy">·</MessageAction>- </MessageActions>- </MessageContent>- </Message>- );-- expect(collectClasses(container)).not.toMatch(RAW_PALETTE);- });-});diff --git a/app/src/components/ai-elements/Message.tsx b/app/src/components/ai-elements/Message.tsxdeleted file mode 100644index d52f027095..0000000000--- a/app/src/components/ai-elements/Message.tsx+++ /dev/null@@ -1,136 +0,0 @@-/**- * Adapted from `message.tsx` in vercel/ai-elements (Apache-2.0).- * Upstream: https://github.com/vercel/ai-elements — registry component `message`.- *- * Port notes (this is an adaptation, not a copy):- * - `UIMessage["role"]` from the `ai` SDK → the local `MessageRole` union. The- * `ai` package is not a dependency here; the transcript only ever renders a- * user turn or an assistant turn, so a two-value union is the whole surface.- * The app's own wire vocabulary calls the assistant `'agent'`, so both- * spellings are accepted and normalised to `data-from="assistant"` — callers- * pass `msg.sender` straight through without a translation step.- * - `@/lib/utils` `cn` → `../../lib/cn`; `@/registry/default/ui/button` →- * OpenHuman's `Button` from `../ui`.- * - Upstream distinguishes the two sides with the marker classes `is-user` /- * `is-assistant` and then styles descendants through- * `group-[.is-user]:…` selectors. That reads as dead weight in a codebase- * whose tests are forbidden from asserting on class strings, so the marker is- * `data-from` instead and the layout difference (`justify-end` vs- * `justify-start`) is applied directly on the row.- * - The group is named `group/msg`, not the bare `group` upstream uses. The- * transcript's hover affordances (the copy button, the reaction opener) are- * already written against `group-hover/msg:`, and a named group is what lets- * a message row nest inside other `group`s without capturing their hovers.- * - `MessageContent` drops upstream's bubble chrome- * (`group-[.is-user]:rounded-lg …bg-secondary`): in this app the bubble is- * painted by `AgentMessageBubble` / the user bubble in `TranscriptRow`, which- * have their own token-based treatment, corner-tucking and attachment rows.- * What is kept is the part the transcript actually needs from it — a- * `relative`, min-width-0 column that the absolutely-positioned actions can- * anchor against.- * - `MessageAction` renders an `aria-label` rather than upstream's- * `<span className="sr-only">`, because this repo requires an accessible name- * on every icon-only button and an `aria-label` is the one screen readers- * announce as the button's name rather than as its content. The upstream- * `tooltip` prop and its `TooltipProvider` wrapper are NOT ported: the- * transcript's actions are absolutely positioned against- * `MessageContent`, and an extra trigger wrapper between them and their- * positioning context would break that anchor. `title` covers the hover hint.- * - `MessageBranch*` is not ported. This app renders concurrent (forked) turns- * as separate labelled bubbles rather than as one switchable slot, so the- * branch selector would be an unused port.- * - `MessageResponse` is not ported: it is a thin wrapper over `streamdown`,- * which is not a dependency here. Markdown rendering goes through- * `features/conversations/components/AgentMessageBubble`'s `BubbleMarkdown`.- * - `data-slot` attributes added throughout so tests assert structure rather- * than class strings.- */-import { type ComponentProps, forwardRef, type HTMLAttributes } from 'react';--import { cn } from '../../lib/cn';-import { Button } from '../ui';--/**- * Who produced the turn. `'agent'` is this app's own spelling of the assistant- * side and is treated as an alias for `'assistant'`.- */-export type MessageRole = 'user' | 'assistant' | 'agent';--export type MessageProps = HTMLAttributes<HTMLDivElement> & { from: MessageRole };--/**- * One row of the transcript: a full-width flex line that pushes its content to- * the trailing edge for a user turn and the leading edge for an assistant turn.- */-export const Message = forwardRef<HTMLDivElement, MessageProps>(- ({ className, from, ...props }, ref) => {- const isUser = from === 'user';- return (- <div- ref={ref}- data-slot="message"- data-from={isUser ? 'user' : 'assistant'}- className={cn('group/msg flex w-full', isUser ? 'justify-end' : 'justify-start', className)}- {...props}- />- );- }-);-Message.displayName = 'Message';--export type MessageContentProps = HTMLAttributes<HTMLDivElement>;--/**- * The turn's body column. `relative` is load-bearing: it is the positioning- * context every `MessageAction` anchors to.- */-export const MessageContent = forwardRef<HTMLDivElement, MessageContentProps>(- ({ className, children, ...props }, ref) => (- <div- ref={ref}- data-slot="message-content"- className={cn('relative flex min-w-0 flex-col', className)}- {...props}>- {children}- </div>- )-);-MessageContent.displayName = 'MessageContent';--export type MessageActionsProps = HTMLAttributes<HTMLDivElement>;--/** A cluster of hover affordances for one turn. */-export const MessageActions = ({ className, children, ...props }: MessageActionsProps) => (- <div data-slot="message-actions" className={cn('flex items-center gap-1', className)} {...props}>- {children}- </div>-);--export type MessageActionProps = Omit<ComponentProps<typeof Button>, 'aria-label'> & {- /** Accessible name. Required — these buttons are always icon-only. */- label: string;-};--/**- * A single icon affordance on a message (copy, share, react …). Sized `xs` and- * `tertiary` so it reads as chrome rather than as an action the turn is- * offering.- */-export const MessageAction = forwardRef<HTMLButtonElement, MessageActionProps>(- ({ label, children, className, variant = 'tertiary', size = 'xs', ...props }, ref) => (- <Button- ref={ref}- data-slot="message-action"- type="button"- variant={variant}- size={size}- iconOnly- aria-label={label}- title={label}- className={className}- {...props}>- {children}- </Button>- )-);-MessageAction.displayName = 'MessageAction';diff --git a/app/src/components/ai-elements/index.ts b/app/src/components/ai-elements/index.tsindex 71e100d7c1..ef58f47c8e 100644--- a/app/src/components/ai-elements/index.ts+++ b/app/src/components/ai-elements/index.ts@@ -35,6 +35,11 @@* - `Tool` — `ToolTimelineBlock` carries run-loop coalescing that upstream has* no equivalent for and stays. Nothing else needs a tool-call renderer.*+ * `Conversation` and `Message` went the same way later: their only caller was+ * the legacy `ChatThreadView` transcript, which was replaced end to end by the+ * assistant-ui `Thread` (`components/assistant-ui/thread.tsx`), whose own+ * viewport and message primitives cover both.+ ** If one of these is wanted later, it is a `git log` away — but it should come* back with a caller in the same change.*/@@ -51,24 +56,5 @@ export {type SourcesTriggerProps,} from './Sources';-// Transcript shell-export {- Conversation,- ConversationContent,- type ConversationContentProps,- type ConversationProps,-} from './Conversation';-export {- Message,- MessageAction,- MessageActions,- MessageContent,- type MessageActionProps,- type MessageActionsProps,- type MessageContentProps,- type MessageProps,- type MessageRole,-} from './Message';-// Iconsexport { BookIcon, ChevronDownIcon } from './icons';