Skip to content

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

fix(ui): handle missing tool call arguments in assistant message

Steven Enamakelac468c09c45e
diff --git a/app/src/features/conversations/components/AssistantUiToolCall.tsx b/app/src/features/conversations/components/AssistantUiToolCall.tsx
index 650780af46..2f6ca0a765 100644
--- a/app/src/features/conversations/components/AssistantUiToolCall.tsx
+++ b/app/src/features/conversations/components/AssistantUiToolCall.tsx
@@ -1,5 +1,5 @@
import type { ToolCallMessagePart, ToolCallMessagePartProps } from '@assistant-ui/react';
-import { CheckIcon, ChevronDownIcon, CircleXIcon, Loader2Icon, WrenchIcon } from 'lucide-react';
+import { CheckIcon, ChevronDownIcon, CircleXIcon, Loader2Icon } from 'lucide-react';
import type { FC, ReactNode } from 'react';
import { cn } from '../../../components/assistant-ui/lib/utils';
@@ -8,95 +8,30 @@ import {
CollapsibleContent,
CollapsibleTrigger,
} from '../../../components/assistant-ui/ui/collapsible';
+import { useT } from '../../../lib/i18n/I18nContext';
+import { readOpenHumanToolArtifact } from '../../../providers/assistantUiMessages';
import type {
ToolFailureExplanation,
ToolTimelineEntryStatus,
} from '../../../store/chatRuntimeSlice';
-import { formatToolName } from '../../../utils/toolTimelineFormatting';
-import { BubbleMarkdown } from './AgentMessageBubble';
+import { FetchBody, FileBody, ShellBody, WebSearchResults } from '../tools/ToolBodies';
+import { hasDisplayValue, parsedValue, ToolDataView } from '../tools/ToolDataView';
+import { ToolIcon } from '../tools/ToolIcon';
+import {
+ describeToolCall,
+ parseToolArgs,
+ type ToolCallPresentation,
+ toolLabel,
+} from '../tools/toolPresentation';
import { ToolFailureLines } from './ToolFailureLines';
-function friendlyLabel(key: string): string {
- return key
- .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
- .replace(/[_-]+/g, ' ')
- .replace(/^./, char => char.toUpperCase());
-}
-
-function parsedValue(value: unknown): unknown {
- if (typeof value !== 'string') return value;
- const trimmed = value.trim();
- if (!(trimmed.startsWith('{') || trimmed.startsWith('['))) return value;
- try {
- return JSON.parse(trimmed);
- } catch {
- return value;
- }
-}
-
-function hasDisplayValue(value: unknown): boolean {
- if (value === undefined || value === null || value === '') return false;
- if (Array.isArray(value)) return value.length > 0;
- if (typeof value === 'object') return Object.keys(value as object).length > 0;
- return true;
-}
-
-function ToolDataView({ value }: { value: unknown }) {
- const parsed = parsedValue(value);
- if (Array.isArray(parsed)) {
- return (
- <ul className="space-y-1 text-xs">
- {parsed.map((item, index) => (
- <li key={index} className="bg-muted/50 rounded-md px-2 py-1.5">
- <ToolDataView value={item} />
- </li>
- ))}
- </ul>
- );
- }
- if (parsed && typeof parsed === 'object') {
- const entries = Object.entries(parsed);
- for (const key of ['content', 'output', 'result', 'message', 'query', 'q']) {
- const semantic = entries.find(([candidate]) => candidate === key)?.[1];
- if (hasDisplayValue(semantic)) return <ToolDataView value={semantic} />;
- }
- return (
- <dl className="divide-border bg-muted/40 divide-y rounded-md px-2 text-xs">
- {entries.map(([key, item]) => (
- <div key={key} className="grid grid-cols-[minmax(7rem,auto)_1fr] gap-3 py-1.5">
- <dt className="text-muted-foreground font-medium">{friendlyLabel(key)}</dt>
- <dd className="min-w-0 wrap-break-word">
- <ToolDataView value={item} />
- </dd>
- </div>
- ))}
- </dl>
- );
- }
- if (typeof parsed === 'boolean') return <span>{parsed ? 'Yes' : 'No'}</span>;
- if (typeof parsed === 'string') return <BubbleMarkdown content={parsed} />;
- return <span className="whitespace-pre-wrap">{String(parsed ?? '')}</span>;
-}
-
-function inferredToolLabel(toolName: string, running: boolean, args: unknown, result: unknown) {
- const lowerName = toolName.toLowerCase();
- const parsedArgs = parsedValue(args);
- const argKeys =
- parsedArgs && typeof parsedArgs === 'object' && !Array.isArray(parsedArgs)
- ? Object.keys(parsedArgs as object).map(key => key.toLowerCase())
- : [];
- const renderedResult = typeof result === 'string' ? result : JSON.stringify(result ?? '');
- const looksLikeSearch =
- lowerName.includes('search') ||
- argKeys.some(key => ['query', 'q', 'search_query'].includes(key)) ||
- /(?:^|\n)#?\s*search results\b/i.test(renderedResult);
- const looksLikeFetch =
- lowerName.includes('fetch') ||
- argKeys.some(key => ['url', 'uri'].includes(key)) ||
- /\bstatus=\d{3}\s+url=/i.test(renderedResult);
- if (looksLikeSearch) return running ? 'Searching the web' : 'Searched the web';
- if (looksLikeFetch) return running ? 'Fetching from the web' : 'Fetched from the web';
- return formatToolName(toolName);
+/** `1234` → "1.2s", `850` → "850ms", `75000` → "1m 15s". */
+export function formatElapsed(ms: number): string {
+ if (ms < 1000) return `${Math.max(0, Math.round(ms))}ms`;
+ if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;
+ const minutes = Math.floor(ms / 60_000);
+ const seconds = Math.round((ms % 60_000) / 1000);
+ return `${minutes}m ${seconds}s`;
}
/**
@@ -110,15 +45,46 @@ export function isApprovalPending(approval: ToolCallMessagePart['approval']): bo
return approval != null && approval.approved === undefined && approval.resolution === undefined;
}
+/**
+ * A step's node on the timeline rail: the tool's icon in a ring that sits on
+ * the vertical line `ToolTimeline` draws. Shared with the delegation card so
+ * every step in a group lines up.
+ */
+export function TimelineNode({
+ presentation,
+ state,
+}: {
+ presentation: Pick<ToolCallPresentation, 'icon' | 'integration'>;
+ state: 'running' | 'done' | 'failed' | 'awaiting';
+}) {
+ return (
+ <span
+ aria-hidden
+ data-slot="tool-timeline-node"
+ className={cn(
+ 'bg-background absolute top-1.5 left-0 z-10 flex size-6 items-center justify-center rounded-full ring-1',
+ state === 'running' && 'ring-primary/50 text-foreground',
+ state === 'done' && 'ring-border text-muted-foreground',
+ state === 'failed' && 'text-red-600 ring-red-500/40 dark:text-red-400',
+ state === 'awaiting' && 'text-amber-700 ring-amber-400/60 dark:text-amber-300'
+ )}>
+ <ToolIcon presentation={presentation} className="size-3.5" />
+ </span>
+ );
+}
+
export interface AssistantUiToolCallCardProps {
toolName: string;
args?: unknown;
argsText?: string;
result?: unknown;
status?: ToolTimelineEntryStatus;
+ /** Server label; used only for tools the presentation registry cannot describe. */
displayName?: string;
detail?: string;
elapsedMs?: number;
+ /** Machine-readable result from the core (e.g. structured web-search hits). */
+ structured?: unknown;
failure?: ToolFailureExplanation;
/**
* The call is parked on the user — an ApprovalGate request, or a sub-agent
@@ -130,7 +96,39 @@ export interface AssistantUiToolCallCardProps {
footer?: ReactNode;
}
-/** The single assistant-ui tool-call presentation used at every nesting level. */
+function ToolBody({
+ presentation,
+ args,
+ result,
+ running,
+}: {
+ presentation: ToolCallPresentation;
+ args: Record<string, unknown>;
+ result: unknown;
+ running: boolean;
+}): ReactNode {
+ if (running) return null;
+ switch (presentation.body) {
+ case 'shell':
+ return <ShellBody args={args} result={result} />;
+ case 'webFetch':
+ return <FetchBody args={args} result={result} />;
+ case 'file':
+ return <FileBody args={args} result={result} />;
+ default:
+ return null;
+ }
+}
+
+/**
+ * One tool call, rendered as a step on the tool timeline.
+ *
+ * The icon, the label and the target chip all come from the presentation
+ * registry, so every surface names a call the same way. The label changes
+ * tense as the call settles ("Reading file" → "Read file"), and the step
+ * expands into the tool's own renderer: search results, a terminal, a diff,
+ * a fetched page, or the generic Input/Output view.
+ */
export function AssistantUiToolCallCard({
toolName,
args,
@@ -140,96 +138,138 @@ export function AssistantUiToolCallCard({
displayName,
detail,
elapsedMs,
+ structured,
failure,
awaitingUser = false,
footer,
}: AssistantUiToolCallCardProps) {
+ const { t } = useT();
const running =
awaitingUser ||
(status ? status === 'running' || status === 'awaiting_user' : result === undefined);
+ const effectiveStatus: ToolTimelineEntryStatus =
+ status ?? (awaitingUser ? 'awaiting_user' : running ? 'running' : 'success');
const input = hasDisplayValue(args) ? args : parsedValue(argsText ?? '');
- const output = result === '' && status && !running ? 'No output' : parsedValue(result);
- const suppliedLabel = displayName?.trim();
- const label =
- suppliedLabel && suppliedLabel.toLowerCase() !== 'tool'
- ? suppliedLabel
- : inferredToolLabel(toolName, running, args, result);
- // `awaiting input` was previously reachable only via `status`, which the
- // adapter forwards for `error` / `cancelled` alone — so the label could never
- // render for the case it was written for. A parked call now says so.
- const statusLabel =
- status === 'error'
- ? 'failed'
- : status === 'cancelled'
- ? 'cancelled'
- : awaitingUser || status === 'awaiting_user'
- ? 'awaiting input'
- : running
- ? 'running'
- : 'done';
+ const parsedArgs = parseToolArgs(input);
+ const output = result === '' && status && !running ? t('conversations.tools.noOutput') : result;
+ const presentation = describeToolCall({
+ name: toolName,
+ args: parsedArgs,
+ status: effectiveStatus,
+ serverLabel: displayName,
+ serverDetail: detail,
+ });
+ const label = toolLabel(presentation, t);
const failed = status === 'error';
- // `failed` gates the failure-explanation block, which only an `error` carries.
- // The icon is a wider question: a cancelled call did not succeed either, and
- // before the adapter forwarded a status this branch was unreachable, so the
- // check icon sat next to the word "cancelled".
+ // A cancelled call did not succeed either: it gets the failure icon, not a
+ // check, even though only an `error` carries an explanation block.
const terminalNonSuccess = failed || status === 'cancelled';
+ const awaiting = awaitingUser || status === 'awaiting_user';
+ const statusLabel = failed
+ ? t('conversations.tools.status.failed')
+ : status === 'cancelled'
+ ? t('conversations.tools.status.cancelled')
+ : awaiting
+ ? t('conversations.tools.status.awaiting')
+ : running
+ ? t('conversations.tools.status.running')
+ : t('conversations.tools.status.done');
+ const nodeState = terminalNonSuccess
+ ? 'failed'
+ : awaiting
+ ? 'awaiting'
+ : running
+ ? 'running'
+ : 'done';
+ const richBody = ToolBody({ presentation, args: parsedArgs, result: output, running });
+ const isSearch = presentation.body === 'webSearch';
+ const searchBody = isSearch ? (
+ <WebSearchResults
+ args={parsedArgs}
+ result={output}
+ structured={structured}
+ searching={running}
+ />
+ ) : null;
return (
<Collapsible
data-slot="aui_openhuman-tool-call"
data-testid="assistant-ui-tool-call"
- defaultOpen={running}
+ data-tool={presentation.baseName}
+ data-status={effectiveStatus}
data-awaiting-user={awaitingUser ? 'true' : undefined}
- className={cn(
- 'border-border/60 dark:border-muted-foreground/15 rounded-xl border',
- running && 'border-dashed'
- )}>
- <CollapsibleTrigger className="group/tool text-muted-foreground hover:text-foreground flex w-full items-center gap-2 px-3 py-2 text-sm transition-colors">
- <WrenchIcon className="size-4 shrink-0" />
- <span className="text-foreground text-start font-medium">{label}</span>
- {detail ? (
- <span className="bg-muted min-w-0 truncate rounded px-1.5 py-0.5 font-mono text-[11px]">
- {detail}
+ defaultOpen={awaitingUser}
+ className="group/step relative min-w-0 pl-9">
+ <TimelineNode presentation={presentation} state={nodeState} />
+ <CollapsibleTrigger className="group/tool text-muted-foreground hover:text-foreground flex w-full min-w-0 items-center gap-2 py-1.5 text-sm transition-colors">
+ <span
+ data-testid="tool-call-label"
+ className={cn(
+ 'text-foreground shrink-0 text-start font-medium',
+ running && !awaiting && 'tool-shimmer'
+ )}>
+ {label}
+ </span>
+ {presentation.chip ? (
+ <span
+ data-testid="tool-call-chip"
+ className="bg-muted text-muted-foreground min-w-0 truncate rounded-md px-1.5 py-0.5 font-mono text-[11px]">
+ {presentation.chip}
</span>
) : null}
- <span className="flex shrink-0 items-center gap-1 text-[11px]">
- {running ? (
+ <span className="ml-auto flex shrink-0 items-center gap-1.5 text-[11px]">
+ {running && !awaiting ? (
<Loader2Icon className="size-3 animate-spin [animation-duration:0.6s]" />
) : terminalNonSuccess ? (
- <CircleXIcon className="size-3.5" />
- ) : (
- <CheckIcon className="size-3.5" />
+ <CircleXIcon className="size-3.5 text-red-600 dark:text-red-400" />
+ ) : awaiting ? null : (
+ <CheckIcon className="size-3.5 text-emerald-600 dark:text-emerald-400" />
)}
- {statusLabel}
+ <span
+ data-testid="tool-call-status"
+ className={cn(
+ (running && !awaiting) || (!running && !terminalNonSuccess) ? 'sr-only' : undefined,
+ awaiting && 'text-amber-700 dark:text-amber-300'
+ )}>
+ {statusLabel}
+ </span>
{elapsedMs != null && !running ? (
- <span className="tabular-nums">
- {elapsedMs >= 1000 ? `${(elapsedMs / 1000).toFixed(1)}s` : `${elapsedMs}ms`}
+ <span data-testid="tool-call-elapsed" className="tabular-nums">
+ {formatElapsed(elapsedMs)}
</span>
) : null}
+ <ChevronDownIcon className="size-4 shrink-0 -rotate-90 transition-transform group-data-[state=open]/tool:rotate-0" />
</span>
- <ChevronDownIcon className="ml-auto size-4 shrink-0 -rotate-90 transition-transform group-data-[state=open]/tool:rotate-0" />
</CollapsibleTrigger>
{failed && failure ? (
- <div className="px-3 pb-2">
+ <div className="pb-2">
<ToolFailureLines failure={failure} />
</div>
) : null}
{/* Outside `CollapsibleContent` on purpose: a decision the turn is
blocked on must not be hidden behind a disclosure the user has to
- find and open. */}
+ find and open. Search results are the call's whole point, so they
+ stay visible too. */}
{footer}
- <CollapsibleContent className="space-y-2 px-3 pb-3">
- {hasDisplayValue(input) ? (
+ {searchBody ? <div className="pt-0.5 pb-2">{searchBody}</div> : null}
+ <CollapsibleContent className="space-y-2 pb-3">
+ {richBody}
+ {!richBody && hasDisplayValue(input) ? (
<div data-testid="assistant-ui-tool-input">
- <p className="text-muted-foreground mb-1 text-[11px] font-medium uppercase">Input</p>
+ <p className="text-muted-foreground mb-1 text-[11px] font-medium uppercase">
+ {t('conversations.subagent.input')}
+ </p>
<div className="max-h-48 overflow-auto">
<ToolDataView value={input} />
</div>
</div>
) : null}
- {hasDisplayValue(output) ? (
+ {!richBody && !searchBody && hasDisplayValue(parsedValue(output)) ? (
<div data-testid="assistant-ui-tool-output">
- <p className="text-muted-foreground mb-1 text-[11px] font-medium uppercase">Output</p>
+ <p className="text-muted-foreground mb-1 text-[11px] font-medium uppercase">
+ {t('conversations.subagent.output')}
+ </p>
<div className="max-h-64 overflow-auto">
<ToolDataView value={output} />
</div>
@@ -272,6 +312,10 @@ function toolStatusEnvelope(
* to destructure four fields and drop the rest, which is why a parked call
* rendered as an ordinary running one with no way to answer it.
*
+ * The part's `artifact` carries what the core said about the call (its label
+ * for a dynamic tool, the duration, a structured result). The adapter used to
+ * drop all of it, so the card guessed a label from the tool name.
+ *
* The decision surface itself is passed in rather than built here. It is
* `ApprovalRequestCard`, which needs the thread id and the store's
* `PendingApproval` — neither of which belongs in this file, and both of which
@@ -284,6 +328,7 @@ export const OpenHumanToolCall: FC<
}
> = props => {
const envelope = toolStatusEnvelope(props.result);
+ const artifact = readOpenHumanToolArtifact(props.artifact);
return (
<AssistantUiToolCallCard
toolName={props.toolName}
@@ -292,6 +337,10 @@ export const OpenHumanToolCall: FC<
result={envelope ? envelope.value : props.result}
status={envelope?.status}
failure={envelope?.failure}
+ displayName={artifact?.displayName}
+ detail={artifact?.detail}
+ elapsedMs={artifact?.elapsedMs}
+ structured={artifact?.structured}
awaitingUser={isApprovalPending(props.approval)}
footer={props.approvalCard}
/>