refactor(ui): replace middle-dot separators with clearer hierarchy (#6087)
* refactor(ui): replace middle-dot separators with clearer hierarchy * refactor(ui): use layout instead of punctuation separators
This commit is contained in:
1 parent
d6ddceed99
commit
7cb396788c
82 files changed
+433
-462
No files matched your search
@@ -12,6 +12,8 @@ export interface ActivityStepProps {
|
||||
marker?: ReactNode;
|
||||
showMarker?: boolean;
|
||||
label: ReactNode;
|
||||
detail?: string;
|
||||
detailClassName?: string;
|
||||
tooltipContent?: ReactNode;
|
||||
ariaLabel?: string;
|
||||
active?: boolean;
|
||||
@@ -29,6 +31,8 @@ export function ActivityStep({
|
||||
marker,
|
||||
showMarker = true,
|
||||
label,
|
||||
detail,
|
||||
detailClassName,
|
||||
tooltipContent,
|
||||
ariaLabel,
|
||||
active = false,
|
||||
@@ -42,11 +46,13 @@ export function ActivityStep({
|
||||
}: ActivityStepProps) {
|
||||
const lineRef = useRef<HTMLDivElement>(null);
|
||||
const [hintOpen, setHintOpen] = useState(false);
|
||||
const textLabel = typeof label === "string" ? [label, detail].filter(Boolean).join("\n") : undefined;
|
||||
const line = (
|
||||
<div
|
||||
ref={lineRef}
|
||||
data-testid="activity-line"
|
||||
tabIndex={typeof label === "string" ? 0 : undefined}
|
||||
aria-label={detail && typeof label === "string" ? `${label}, ${detail}` : undefined}
|
||||
className="flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap"
|
||||
>
|
||||
<StreamingLabelSheen
|
||||
@@ -57,7 +63,12 @@ export function ActivityStep({
|
||||
labelClassName,
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
{detail ? (
|
||||
<span className="flex min-w-0 items-baseline gap-2">
|
||||
<span className="max-w-[70%] shrink-0 truncate">{label}</span>{" "}
|
||||
<span className={cn("min-w-0 flex-1 truncate font-normal text-muted-foreground", detailClassName)}>{detail}</span>
|
||||
</span>
|
||||
) : label}
|
||||
</StreamingLabelSheen>
|
||||
</div>
|
||||
);
|
||||
@@ -99,11 +110,11 @@ export function ActivityStep({
|
||||
<Tooltip open={hintOpen} onOpenChange={(open) => {
|
||||
const truncated = Array.from(lineRef.current?.querySelectorAll<HTMLElement>(".truncate") ?? [])
|
||||
.some((element) => element.scrollWidth > element.clientWidth);
|
||||
setHintOpen(open && (truncated || tooltipContent !== undefined && tooltipContent !== label));
|
||||
setHintOpen(open && (truncated || tooltipContent !== undefined && tooltipContent !== textLabel));
|
||||
}}>
|
||||
<TooltipTrigger asChild>{line}</TooltipTrigger>
|
||||
<TooltipContent side="top" className="max-w-[min(32rem,calc(100vw-2rem))] whitespace-pre-wrap break-words">
|
||||
{tooltipContent ?? label}
|
||||
{tooltipContent ?? textLabel}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
|
||||
@@ -37,14 +37,14 @@ export function GenericToolRun({ items }: { items: GenericToolRunItem[] }) {
|
||||
const { t } = useTranslation();
|
||||
const model = useMemo(() => buildModel(items, t), [items, t]);
|
||||
const action = formatActivityTarget(t, model.label, model.detail);
|
||||
const label = model.aside ? `${action} · ${model.aside}` : action;
|
||||
|
||||
return (
|
||||
<ActivityStep
|
||||
icon={model.status === "error" ? AlertCircle : model.icon}
|
||||
active={model.status === "running"}
|
||||
tone={model.status === "error" ? "error" : model.status === "done" ? "success" : "active"}
|
||||
label={label}
|
||||
label={action}
|
||||
detail={model.aside}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ export function ThinkingReasoningShell({
|
||||
onClick={onToggle}
|
||||
aria-expanded={expanded}
|
||||
aria-controls={contentId}
|
||||
aria-label={expanded && collapseLabel ? `${label} · ${collapseLabel}` : label}
|
||||
aria-label={expanded && collapseLabel ? `${label}, ${collapseLabel}` : label}
|
||||
aria-live={active ? "polite" : undefined}
|
||||
>
|
||||
{headerContent}
|
||||
|
||||
@@ -32,7 +32,7 @@ export function WebActivityRow({
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
aria-label={`${title} · ${displayUrl}`}
|
||||
aria-label={`${title}, ${displayUrl}`}
|
||||
className="flex min-w-0 items-center gap-2 overflow-hidden text-foreground/82 hover:text-foreground"
|
||||
>
|
||||
<span className="min-w-0 truncate font-medium">{title}</span>
|
||||
|
||||
@@ -15,7 +15,7 @@ export function WebSearchRun({ run, turnActive }: { run: WebSearchRunModel; turn
|
||||
const { t } = useTranslation();
|
||||
const active = run.status === "running" && turnActive;
|
||||
const status = run.status === "running" && !turnActive ? "done" : run.status;
|
||||
const label = presentWebSearchAction(run.query, status, run.target, t);
|
||||
const presentation = presentWebSearchAction(run.query, status, run.target, t);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -23,7 +23,9 @@ export function WebSearchRun({ run, turnActive }: { run: WebSearchRunModel; turn
|
||||
icon={status === "error" ? AlertCircle : WebSearchIcon}
|
||||
active={active}
|
||||
tone={status === "error" ? "error" : status === "done" ? "success" : "active"}
|
||||
label={label}
|
||||
label={presentation.label}
|
||||
detail={presentation.detail}
|
||||
detailClassName="whitespace-pre-line"
|
||||
/>
|
||||
{run.sources.map((source) => (
|
||||
<WebActivityRow
|
||||
|
||||
@@ -56,16 +56,17 @@ export function formatActivityTarget(t: TFunction, action: string, target: strin
|
||||
: action;
|
||||
}
|
||||
|
||||
export function summarizeShellCommand(command: string, t: TFunction): string {
|
||||
export function summarizeShellCommand(command: string, t: TFunction): { detail: string; aside?: string } {
|
||||
const lines = redactShellCommand(command.replace(/\r\n/g, "\n"))
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean);
|
||||
const firstLine = compactActivityPath(lines[0] || t("message.agentActivity.command"));
|
||||
const firstPreview = truncateMiddle(firstLine, 92);
|
||||
return lines.length <= 1
|
||||
? firstPreview
|
||||
: `${firstPreview} · ${t("message.agentActivity.scriptLines", { count: lines.length })}`;
|
||||
return {
|
||||
detail: firstPreview,
|
||||
...(lines.length > 1 ? { aside: t("message.agentActivity.scriptLines", { count: lines.length }) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function truncateMiddle(value: string, maxLength: number): string {
|
||||
|
||||
@@ -9,6 +9,7 @@ export interface TraceDescription {
|
||||
kind: "search" | "tool" | "done" | "trace";
|
||||
label: string;
|
||||
detail: string;
|
||||
aside?: string;
|
||||
icon?: "clock";
|
||||
url?: string;
|
||||
host?: string;
|
||||
@@ -33,8 +34,7 @@ export function describeTraceLine(
|
||||
const query = traceFieldFromArgs(args, ["query", "q", "text"]) || args;
|
||||
return {
|
||||
kind: "search",
|
||||
label: presentWebSearchAction(query, status, name === "x_search" ? "x" : "web", t),
|
||||
detail: "",
|
||||
...presentWebSearchAction(query, status, name === "x_search" ? "x" : "web", t),
|
||||
};
|
||||
}
|
||||
if (/fetch|read|open/i.test(name) || plainWebReadTrace) {
|
||||
@@ -108,7 +108,7 @@ function describeShellTrace(
|
||||
return {
|
||||
kind: "tool",
|
||||
label: activityStatus(t, status, "runningCommand", "ranCommand", "commandFailed"),
|
||||
detail: summarizeShellCommand(command, t),
|
||||
...summarizeShellCommand(command, t),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -78,12 +78,13 @@ function presentWebSearchQuery(query: string): WebSearchQueryPresentation {
|
||||
const scopes: string[] = [];
|
||||
const safeQuery = redactActivityText(query);
|
||||
const cleanQuery = safeQuery
|
||||
.replace(/(?:^|\s)site:([^\s]+)/gi, (_match, rawSite: string) => {
|
||||
.replace(/(^|\s)site:([^\s]+)/gi, (_match, prefix: string, rawSite: string) => {
|
||||
const scope = webSearchScope(rawSite);
|
||||
if (scope && !scopes.includes(scope)) scopes.push(scope);
|
||||
return " ";
|
||||
return prefix;
|
||||
})
|
||||
.replace(/\s+/g, " ")
|
||||
.replace(/[^\S\n]+/g, " ")
|
||||
.replace(/ *\n */g, "\n")
|
||||
.trim();
|
||||
|
||||
return {
|
||||
@@ -97,14 +98,16 @@ export function presentWebSearchAction(
|
||||
status: WebSearchStatus,
|
||||
target: WebSearchTarget = "web",
|
||||
t: TFunction,
|
||||
): string {
|
||||
): { label: string; detail: string } {
|
||||
const presentation = presentWebSearchQuery(query);
|
||||
const queryTarget = [presentation.scope, presentation.query].filter(Boolean).join(" · ");
|
||||
const key = status === "error" ? "searchFailed" : status === "running" ? "searching" : "searched";
|
||||
const searchTarget = target === "x"
|
||||
? (queryTarget ? `X · ${queryTarget}` : "X")
|
||||
: queryTarget || t("message.agentActivity.web");
|
||||
return t(`message.agentActivity.${key}`, { target: searchTarget });
|
||||
? ["X", presentation.scope].filter(Boolean).join(" ")
|
||||
: presentation.scope || t("message.agentActivity.web");
|
||||
return {
|
||||
label: t(`message.agentActivity.${key}`, { target: searchTarget }),
|
||||
detail: presentation.query,
|
||||
};
|
||||
}
|
||||
|
||||
function mergeWebSearchRun(
|
||||
|
||||
Reference in new issue
Block a user