Skip to content

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

refactor(assistant-ui): extract shared tool timeline component

Steven Enamakel0c594322bd34
diff --git a/app/src/components/assistant-ui/elements/tool-timeline.tsx b/app/src/components/assistant-ui/elements/tool-timeline.tsx
new file mode 100644
index 0000000000..9eafba5d9e
--- /dev/null
+++ b/app/src/components/assistant-ui/elements/tool-timeline.tsx
@@ -0,0 +1,129 @@
+'use client';
+
+/**
+ * assistant-ui's tool-timeline element: a run of tool calls under one
+ * disclosure whose label shimmers ("Working") while the run streams and
+ * swaps to a summary once it settles.
+ *
+ * Vendored from assistant-ui `packages/ui/src/components/react/assistant-ui/elements/tool-timeline.tsx`
+ * (commit 1abca347). Changes from upstream:
+ * - Radix collapsible (the app's), so the open-state selectors differ.
+ * - Open state may be uncontrolled (`defaultOpen`).
+ * - `children` may replace `steps`: a live chat step is a full tool-call
+ * element (it expands, carries approvals), not only a verb and a chip.
+ * - Step keys are positional; two steps may share a chip.
+ */
+import { ChevronRightIcon, type LucideIcon } from 'lucide-react';
+import type { ReactNode } from 'react';
+
+import { cn } from '@/components/assistant-ui/lib/utils';
+import {
+ Collapsible,
+ CollapsibleContent,
+ CollapsibleTrigger,
+} from '@/components/assistant-ui/ui/collapsible';
+
+import { take } from '../utils/range';
+import { collapsePanel, openRotate, ShimmerLabel, SwapLabel } from './surfaces';
+
+export interface TimelineStep {
+ verb: string;
+ chip: string;
+ icon: LucideIcon;
+}
+
+export interface TimelineStat {
+ file: string;
+ added?: number;
+ removed?: number;
+}
+
+export interface ToolTimelineProps {
+ steps?: readonly TimelineStep[];
+ visibleSteps?: number;
+ children?: ReactNode;
+ streaming: boolean;
+ open?: boolean;
+ defaultOpen?: boolean;
+ onOpenChange?: (open: boolean) => void;
+ restingLabel: string;
+ activeLabel: string;
+ stats?: TimelineStat[];
+ className?: string;
+ 'data-testid'?: string;
+}
+
+export function ToolTimeline({
+ steps = [],
+ visibleSteps = steps.length,
+ children,
+ streaming,
+ open,
+ defaultOpen,
+ onOpenChange,
+ restingLabel,
+ activeLabel,
+ stats = [],
+ className,
+ ...props
+}: ToolTimelineProps) {
+ return (
+ <Collapsible
+ data-slot="tool-timeline"
+ open={open}
+ defaultOpen={defaultOpen}
+ onOpenChange={onOpenChange}
+ className={cn('w-full max-w-sm', className)}
+ {...props}>
+ <CollapsibleTrigger className="group/trigger text-foreground/55 hover:text-foreground/90 flex items-center gap-1.5 rounded-md py-1 text-[13.5px] transition-colors outline-none">
+ <ChevronRightIcon className={cn('size-3.5 shrink-0 opacity-60', openRotate)} />
+ <SwapLabel active={streaming ? 0 : 1} className="text-start tabular-nums">
+ <ShimmerLabel active={streaming} className="relative inline-block leading-none">
+ {activeLabel}
+ </ShimmerLabel>
+ <>{restingLabel}</>
+ </SwapLabel>
+ </CollapsibleTrigger>
+ <CollapsibleContent className={cn(collapsePanel, 'outline-none')}>
+ <div className="flex flex-col gap-2.5 ps-4 pt-2.5">
+ {children ??
+ take(steps, visibleSteps).map((step, index, shown) => {
+ const Icon = step.icon;
+ const active = streaming && index === shown.length - 1;
+
+ return (
+ <div
+ key={`${index}-${step.chip}`}
+ className="fade-in slide-in-from-bottom-1 animate-in fill-mode-both text-foreground/55 flex items-center gap-2 text-[13.5px] duration-300">
+ <Icon className="text-foreground/35 size-3.5 shrink-0" />
+ <ShimmerLabel active={active} className="relative inline-block leading-none">
+ {step.verb}
+ </ShimmerLabel>
+ <span className="bg-foreground/[0.06] text-foreground/70 rounded-md px-1.5 py-0.5 font-mono text-[11px]">
+ {step.chip}
+ </span>
+ </div>
+ );
+ })}
+ {stats.length > 0 && (
+ <div className="flex flex-wrap gap-1.5 pt-1">
+ {stats.map(stat => (
+ <span
+ key={stat.file}
+ className="bg-foreground/[0.06] text-foreground/70 inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 font-mono text-[11px]">
+ <span>{stat.file}</span>
+ {stat.added !== undefined && (
+ <span className="text-emerald-600 dark:text-emerald-400">+{stat.added}</span>
+ )}
+ {stat.removed !== undefined && (
+ <span className="text-red-600 dark:text-red-400">−{stat.removed}</span>
+ )}
+ </span>
+ ))}
+ </div>
+ )}
+ </div>
+ </CollapsibleContent>
+ </Collapsible>
+ );
+}
diff --git a/app/src/components/assistant-ui/elements/web-search.tsx b/app/src/components/assistant-ui/elements/web-search.tsx
new file mode 100644
index 0000000000..0d06f44177
--- /dev/null
+++ b/app/src/components/assistant-ui/elements/web-search.tsx
@@ -0,0 +1,108 @@
+'use client';
+
+/**
+ * assistant-ui's web-search element: the query as a pill, a status line that
+ * shimmers while searching, and the hits with a domain-initial avatar.
+ *
+ * Vendored from assistant-ui `packages/ui/src/components/react/assistant-ui/elements/web-search.tsx`
+ * (commit 1abca347). Changes from upstream:
+ * - The status line is props (`searchingLabel`, `statusLabel`); upstream
+ * hardcodes "Searching" / "Read 3 sources".
+ * - A result may carry a `url`; the row then renders through `renderLink`
+ * so the host decides how an external link opens. A result's `url` is
+ * provider-supplied, so the host must only pass vetted http(s) URLs.
+ * - Result keys include the URL: two hits often share a domain.
+ * - The empty-results floor (`min-h`) applies only while hits are expected.
+ */
+import { SearchIcon } from 'lucide-react';
+import type { ComponentProps, ReactNode } from 'react';
+
+import { cn } from '@/components/assistant-ui/lib/utils';
+
+import { take } from '../utils/range';
+import { field, mono, ShimmerLabel } from './surfaces';
+
+export interface WebSearchResult {
+ title: string;
+ domain: string;
+ url?: string;
+}
+
+const rowClass =
+ 'fade-in slide-in-from-bottom-1 animate-in fill-mode-both hover:bg-foreground/[0.03] -mx-2.5 flex items-center gap-2.5 rounded-xl px-2.5 py-1.5 transition-colors duration-300';
+
+export function WebSearch({
+ query,
+ results,
+ visibleResults,
+ searching,
+ cycle,
+ searchingLabel = 'Searching',
+ statusLabel,
+ renderLink,
+ className,
+ ...props
+}: Omit<
+ ComponentProps<'div'>,
+ 'children' | 'query' | 'results' | 'visibleResults' | 'searching' | 'cycle'
+> & {
+ query: string;
+ results: readonly WebSearchResult[];
+ visibleResults: number;
+ searching: boolean;
+ cycle: number;
+ searchingLabel?: string;
+ statusLabel: string;
+ renderLink?: (props: { href: string; className: string; children: ReactNode }) => ReactNode;
+}) {
+ return (
+ <div
+ data-slot="web-search"
+ className={cn('flex w-full max-w-sm flex-col gap-2.5', className)}
+ {...props}>
+ <span
+ data-slot="web-search-query"
+ className={cn(
+ field,
+ 'text-foreground/70 inline-flex w-fit max-w-full items-center gap-1.5 rounded-full px-3.5 py-2 text-xs'
+ )}>
+ <SearchIcon className="text-foreground/40 size-3 shrink-0" />
+ <span className="truncate">{query}</span>
+ </span>
+ <div data-slot="web-search-status" className="text-foreground/45 text-xs">
+ {searching ? (
+ <ShimmerLabel className="relative inline-block leading-none">
+ {searchingLabel}
+ </ShimmerLabel>
+ ) : (
+ <span className="fade-in animate-in duration-300">{statusLabel}</span>
+ )}
+ </div>
+ <div className={cn('flex flex-col', searching && 'min-h-[5.75rem]')}>
+ {take(results, visibleResults).map(result => {
+ const content = (
+ <>
+ <span className="bg-foreground/[0.06] text-foreground/45 flex size-4 shrink-0 items-center justify-center rounded text-[9px] font-medium">
+ {result.domain.charAt(0).toUpperCase()}
+ </span>
+ <span className="text-foreground/90 min-w-0 flex-1 truncate text-[13.5px]">
+ {result.title}
+ </span>
+ <span className={cn(mono, 'text-foreground/35 shrink-0')}>{result.domain}</span>
+ </>
+ );
+ const key = `${cycle}-${result.url ?? result.domain}-${result.title}`;
+ return result.url && renderLink ? (
+ <span key={key} data-slot="web-search-result" className="contents">
+ {renderLink({ href: result.url, className: rowClass, children: content })}
+ </span>
+ ) : (
+ <div key={key} data-slot="web-search-result" className={rowClass}>
+ {content}
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ );
+}