Skip to content

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

fix(conversations): restore tool body rendering for missing cases

Steven Enamakeld35eda808e02
diff --git a/app/src/features/conversations/tools/ToolBodies.tsx b/app/src/features/conversations/tools/ToolBodies.tsx
index 63bded01f8..7f9d828978 100644
--- a/app/src/features/conversations/tools/ToolBodies.tsx
+++ b/app/src/features/conversations/tools/ToolBodies.tsx
@@ -1,150 +1,99 @@
/**
- * Rich bodies for a tool call's expanded row, one per {@link ToolBodyKind}.
+ * Rich bodies for a tool call, built from assistant-ui's elements
+ * (`components/assistant-ui/elements/`): the web-search element for
+ * searches, the terminal block for commands, the web preview for fetched
+ * pages and the code diff for file edits.
*
- * Each body renders from data the call actually produced (arguments, result
- * text, the core's structured payload) and returns `null` when that data is
- * not there, so the caller falls back to the generic Input/Output view rather
- * than showing an empty frame.
+ * This file only adapts OpenHuman's tool data onto those elements; it adds no
+ * styling of its own beyond width. Each adapter returns `null` when the call
+ * left nothing to show, so the caller can fall back to the generic
+ * Request / Result panel.
*/
-import { SearchIcon } from 'lucide-react';
-import { useState } from 'react';
+import type { ReactNode } from 'react';
import { Source } from '../../../components/ai-elements';
-import { cn } from '../../../components/assistant-ui/lib/utils';
-import { useT } from '../../../lib/i18n/I18nContext';
+import { CodeDiff, type DiffLine } from '../../../components/assistant-ui/elements/code-diff';
+import { TerminalBlock } from '../../../components/assistant-ui/elements/terminal-block';
+import { WebPreview } from '../../../components/assistant-ui/elements/web-preview';
+import { WebSearch } from '../../../components/assistant-ui/elements/web-search';
import { BubbleMarkdown } from '../components/AgentMessageBubble';
-import { displayUrl, type ToolArgs } from './toolChips';
-import { parseWebSearchResult, type WebSearchHit } from './parseWebSearchResult';
+import { displayUrl, shortenPath, type ToolArgs } from './toolChips';
+import { parseWebSearchResult } from './parseWebSearchResult';
import { fillPlaceholders } from './toolPhrases';
+import type { Translate } from './toolPresentation';
-const INITIAL_VISIBLE_RESULTS = 4;
+const FULL_WIDTH = 'max-w-none';
+const MAX_LINES = 400;
-/** Deterministic, theme-safe tint for a domain's letter avatar. */
-function avatarHue(domain: string): number {
- let hash = 0;
- for (let i = 0; i < domain.length; i += 1) hash = (hash * 31 + domain.charCodeAt(i)) >>> 0;
- return hash % 360;
-}
-
-function DomainAvatar({ domain }: { domain: string }) {
- const hue = avatarHue(domain);
- return (
- <span
- aria-hidden
- className="flex size-5 shrink-0 items-center justify-center rounded-full text-[10px] font-semibold uppercase"
- style={{
- backgroundColor: `hsl(${hue} 70% 50% / 0.15)`,
- color: `hsl(${hue} 60% 45%)`,
- }}>
- {domain.charAt(0)}
- </span>
- );
-}
-
-function SearchHitRow({ hit, index }: { hit: WebSearchHit; index: number }) {
+function renderSearchLink({
+ href,
+ className,
+ children,
+}: {
+ href: string;
+ className: string;
+ children: ReactNode;
+}) {
+ // `Source` is the app's one external-link anchor; the global link guard
+ // routes it to the OS browser. `href` is an http(s) URL vetted by
+ // `parseWebSearchResult`.
return (
- <li
- className="animate-in fade-in-0 slide-in-from-top-1 fill-mode-both duration-300"
- style={{ animationDelay: `${Math.min(index, 6) * 50}ms` }}>
- <Source
- href={hit.url}
- rel="noreferrer noopener"
- data-testid="web-search-hit"
- className="hover:bg-muted/60 flex items-start gap-2.5 rounded-lg px-2 py-1.5 transition-colors">
- <DomainAvatar domain={hit.domain} />
- <span className="min-w-0 flex-1">
- <span className="text-foreground line-clamp-1 text-[13px] font-medium">{hit.title}</span>
- <span className="text-muted-foreground flex min-w-0 items-center gap-1.5 text-[11px]">
- <span className="truncate font-mono">{hit.domain}</span>
- {hit.published ? <span className="shrink-0">· {hit.published}</span> : null}
- </span>
- {hit.excerpt ? (
- <span className="text-muted-foreground mt-0.5 line-clamp-2 text-xs">{hit.excerpt}</span>
- ) : null}
- </span>
- </Source>
- </li>
+ <Source href={href} rel="noreferrer noopener" className={className} data-testid="web-search-hit">
+ {children}
+ </Source>
);
}
-/**
- * The web-search element: query pill, a status line ("Searching…", "Found 6
- * results via Exa") and the hits, each with a domain-letter avatar. No
- * favicons are fetched, so rendering a result never contacts the result's
- * site.
- */
-export function WebSearchResults({
+/** A web search through assistant-ui's web-search element. */
+export function WebSearchBody({
args,
result,
structured,
searching,
+ t,
}: {
args: ToolArgs;
result: unknown;
structured?: unknown;
searching: boolean;
-}) {
- const { t } = useT();
- const [expanded, setExpanded] = useState(false);
+ t: Translate;
+}): ReactNode {
const parsed = searching ? undefined : parseWebSearchResult(result, structured);
if (!searching && !parsed) return null;
-
- const argQuery = typeof args.query === 'string' ? args.query : undefined;
- const query = parsed?.query ?? argQuery;
+ const argQuery =
+ typeof args.query === 'string'
+ ? args.query
+ : typeof args.objective === 'string'
+ ? args.objective
+ : '';
const hits = parsed?.results ?? [];
- const visible = expanded ? hits : hits.slice(0, INITIAL_VISIBLE_RESULTS);
- const hidden = hits.length - visible.length;
-
- let status: string;
- if (searching) status = t('conversations.tools.search.searching', 'Searching…');
- else if (hits.length === 0) status = t('conversations.tools.search.none', 'No results');
- else
- status = fillPlaceholders(
- hits.length === 1
- ? t('conversations.tools.search.found.one', 'Found {count} result')
- : t('conversations.tools.search.found.other', 'Found {count} results'),
- { count: String(hits.length) }
- );
- const via = parsed?.provider
- ? fillPlaceholders(t('conversations.tools.search.via', 'via {provider}'), {
+ const count =
+ hits.length === 0
+ ? t('conversations.tools.search.none', 'No results')
+ : fillPlaceholders(
+ hits.length === 1
+ ? t('conversations.tools.search.found.one', 'Found {count} result')
+ : t('conversations.tools.search.found.other', 'Found {count} results'),
+ { count: String(hits.length) }
+ );
+ const statusLabel = parsed?.provider
+ ? `${count} · ${fillPlaceholders(t('conversations.tools.search.via', 'via {provider}'), {
provider: parsed.provider,
- })
- : undefined;
-
+ })}`
+ : count;
return (
- <div data-testid="web-search-results" className="space-y-2">
- {query ? (
- <div
- data-testid="web-search-query"
- className="bg-muted/60 text-foreground flex min-w-0 items-center gap-2 rounded-full px-3 py-1.5 text-xs">
- <SearchIcon aria-hidden className="text-muted-foreground size-3.5 shrink-0" />
- <span className="truncate">{query}</span>
- </div>
- ) : null}
- <p className="text-muted-foreground px-1 text-[11px]" data-testid="web-search-status">
- <span className={cn(searching && 'tool-shimmer')}>{status}</span>
- {via ? <span> · {via}</span> : null}
- </p>
- {visible.length > 0 ? (
- <ul className="space-y-0.5">
- {visible.map((hit, index) => (
- <SearchHitRow key={hit.url} hit={hit} index={index} />
- ))}
- </ul>
- ) : null}
- {hidden > 0 || expanded ? (
- <button
- type="button"
- onClick={() => setExpanded(value => !value)}
- className="text-muted-foreground hover:text-foreground px-2 text-[11px] font-medium">
- {expanded
- ? t('conversations.tools.search.showLess', 'Show less')
- : fillPlaceholders(t('conversations.tools.search.showMore', 'Show {count} more'), {
- count: String(hidden),
- })}
- </button>
- ) : null}
- </div>
+ <WebSearch
+ data-testid="web-search-results"
+ className={FULL_WIDTH}
+ query={parsed?.query ?? argQuery}
+ results={hits.map(hit => ({ title: hit.title, domain: hit.domain, url: hit.url }))}
+ visibleResults={hits.length}
+ searching={searching}
+ cycle={0}
+ searchingLabel={t('conversations.tools.search.searching', 'Searching')}
+ statusLabel={statusLabel}
+ renderLink={renderSearchLink}
+ />
);
}
@@ -158,32 +107,43 @@ function stringOf(value: unknown): string | undefined {
}
}
-/** Terminal-styled command and its output. */
-export function ShellBody({ args, result }: { args: ToolArgs; result: unknown }) {
+function linesOf(text: string): string[] {
+ const lines = text.replace(/\s+$/, '').split('\n');
+ return lines.length > MAX_LINES ? [...lines.slice(0, MAX_LINES), '…'] : lines;
+}
+
+/** A command and its output through assistant-ui's terminal block. */
+export function ShellBody({
+ args,
+ result,
+ failed,
+ t,
+}: {
+ args: ToolArgs;
+ result: unknown;
+ failed: boolean;
+ t: Translate;
+}): ReactNode {
const command =
(typeof args.command === 'string' && args.command) ||
(typeof args.subcommand === 'string' && `npm ${args.subcommand}`) ||
(typeof args.script_path === 'string' && args.script_path) ||
(typeof args.inline_code === 'string' && args.inline_code) ||
- undefined;
- const output = stringOf(result)?.trimEnd();
- if (!command && !output) return null;
+ '';
+ const output = stringOf(result) ?? '';
+ if (!command && !output.trim()) return null;
+ const lines = output.trim() ? linesOf(output) : [];
return (
- <div
+ <TerminalBlock
data-testid="tool-body-shell"
- className="overflow-hidden rounded-lg bg-zinc-950 font-mono text-[11.5px] leading-relaxed text-zinc-100">
- {command ? (
- <pre className="border-b border-white/10 px-3 py-2 whitespace-pre-wrap break-all">
- <span className="text-emerald-400 select-none">$ </span>
- {command}
- </pre>
- ) : null}
- {output ? (
- <pre className="max-h-64 overflow-auto px-3 py-2 whitespace-pre-wrap break-all text-zinc-300">
- {output}
- </pre>
- ) : null}
- </div>
+ className={FULL_WIDTH}
+ command={command ? `$ ${command}` : ''}
+ lines={lines}
+ visibleCount={lines.length}
+ done
+ failed={failed}
+ exitLabel={failed ? t('conversations.tools.status.failed') : t('conversations.tools.status.done')}
+ />
);
}
@@ -199,76 +159,81 @@ function splitFetchOutput(text: string): { status?: string; url?: string; body:
};
}
-/** A fetched page: status, where it came from, and the start of its content. */
-export function FetchBody({ args, result }: { args: ToolArgs; result: unknown }) {
+/** A fetched page through assistant-ui's web preview. */
+export function FetchBody({
+ args,
+ result,
+ t,
+ onOpenExternal,
+}: {
+ args: ToolArgs;
+ result: unknown;
+ t: Translate;
+ onOpenExternal?: (url: string) => void;
+}): ReactNode {
const text = typeof result === 'string' ? result : undefined;
if (!text) return null;
const { status, url, body } = splitFetchOutput(text);
const source = url ?? (typeof args.url === 'string' ? args.url : undefined);
- const ok = status ? Number(status) < 400 : true;
+ const origin = [status, source ? displayUrl(source) : undefined].filter(Boolean).join(' · ');
return (
- <div data-testid="tool-body-fetch" className="space-y-1.5">
- {status || source ? (
- <div className="text-muted-foreground flex min-w-0 items-center gap-2 text-[11px]">
- {status ? (
- <span
- className={cn(
- 'rounded px-1.5 py-0.5 font-mono font-medium',
- ok
- ? 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400'
- : 'bg-red-500/10 text-red-600 dark:text-red-400'
- )}>
- {status}
- </span>
- ) : null}
- {source ? <span className="truncate font-mono">{displayUrl(source)}</span> : null}
- </div>
- ) : null}
- {body.trim() ? (
- <div className="bg-muted/40 max-h-56 overflow-auto rounded-md px-2.5 py-2 text-xs">
- <BubbleMarkdown content={body.slice(0, 4000)} />
- </div>
- ) : null}
- </div>
+ <WebPreview
+ data-testid="tool-body-fetch"
+ className={FULL_WIDTH}
+ origin={origin}
+ loading={false}
+ onOpenExternal={source && onOpenExternal ? () => onOpenExternal(source) : undefined}
+ openExternalLabel={t('conversations.tools.openInBrowser')}>
+ <div className="max-h-64 overflow-auto px-3.5 py-2.5 text-xs">
+ <BubbleMarkdown content={(body.trim() ? body : text).slice(0, 4000)} />
+ </div>
+ </WebPreview>
);
}
-/** What changed in a file: removed and added text for an edit, else the content. */
-export function FileBody({ args, result }: { args: ToolArgs; result: unknown }) {
+/** A file edit, write or read through assistant-ui's code diff. */
+export function FileBody({ args, result }: { args: ToolArgs; result: unknown }): ReactNode {
+ const path =
+ typeof args.path === 'string'
+ ? args.path
+ : typeof args.file_path === 'string'
+ ? args.file_path
+ : '';
+ const filename = shortenPath(path);
const oldText = typeof args.old_string === 'string' ? args.old_string : undefined;
const newText = typeof args.new_string === 'string' ? args.new_string : undefined;
if (oldText !== undefined || newText !== undefined) {
+ const removed = oldText ? linesOf(oldText) : [];
+ const added = newText ? linesOf(newText) : [];
+ const lines: DiffLine[] = [
+ ...removed.map(text => ({ kind: 'removed' as const, text })),
+ ...added.map(text => ({ kind: 'added' as const, text })),
+ ];
return (
- <div
+ <CodeDiff
data-testid="tool-body-file-diff"
- className="overflow-hidden rounded-lg border font-mono text-[11.5px] leading-relaxed">
- {oldText ? (
- <pre className="max-h-40 overflow-auto bg-red-500/10 px-3 py-1.5 whitespace-pre-wrap text-red-700 dark:text-red-300">
- {oldText
- .split('\n')
- .map(line => `- ${line}`)
- .join('\n')}
- </pre>
- ) : null}
- {newText ? (
- <pre className="max-h-40 overflow-auto bg-emerald-500/10 px-3 py-1.5 whitespace-pre-wrap text-emerald-700 dark:text-emerald-300">
- {newText
- .split('\n')
- .map(line => `+ ${line}`)
- .join('\n')}
- </pre>
- ) : null}
- </div>
+ className={FULL_WIDTH}
+ filename={filename}
+ additions={added.length}
+ deletions={removed.length}
+ lines={lines}
+ cycle={0}
+ />
);
}
- const content =
- typeof args.content === 'string' ? args.content : typeof result === 'string' ? result : '';
+ const written = typeof args.content === 'string' ? args.content : undefined;
+ const content = written ?? (typeof result === 'string' ? result : '');
if (!content.trim()) return null;
+ const lines = linesOf(content);
return (
- <pre
+ <CodeDiff
data-testid="tool-body-file"
- className="bg-muted/50 max-h-64 overflow-auto rounded-lg px-3 py-2 font-mono text-[11.5px] leading-relaxed whitespace-pre-wrap">
- {content.slice(0, 6000)}
- </pre>
+ className={`${FULL_WIDTH} max-h-72 overflow-auto`}
+ filename={filename}
+ additions={written !== undefined ? lines.length : 0}
+ deletions={0}
+ lines={lines.map(text => ({ kind: written !== undefined ? 'added' : 'context', text }))}
+ cycle={0}
+ />
);
}