feat(webui): localize agent activity
Localize frontend-owned activity presentation while preserving raw tool data and current controls. Include locale-aware model memoization and integration with current main. Co-authored-by: Xubin Ren <52506698+Re-bin@users.noreply.github.com>
This commit is contained in:
1 parent
f57cc3aad2
commit
796e1cb0e6
23 files changed
+1704
-128
No files matched your search
@@ -26,6 +26,7 @@ import { ActivityStep } from "@/components/thread/activity/ActivityStep";
|
||||
import { coalesceActivityMessages } from "@/components/thread/activity/activity-message-model";
|
||||
import {
|
||||
compactActivityPath,
|
||||
formatActivityTarget,
|
||||
redactShellCommand,
|
||||
} from "@/components/thread/activity/activity-text";
|
||||
import { FileEditGroup, type FileEditSummary } from "@/components/thread/activity/FileEditRow";
|
||||
@@ -798,8 +799,9 @@ function ActivityTraceRow({
|
||||
active: boolean;
|
||||
state?: GenericToolState;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const status = state?.status ?? (active ? "running" : "done");
|
||||
const trace = describeTraceLine(line, status, state?.result);
|
||||
const trace = describeTraceLine(line, status, t, state?.result);
|
||||
const rowActive = status === "running" && active;
|
||||
const Icon = trace.icon === "clock" ? Clock3 : (trace.kind === "search"
|
||||
? Search
|
||||
@@ -825,7 +827,7 @@ function ActivityTraceRow({
|
||||
marker={<TraceIconMark trace={trace} fallbackIcon={Icon} active={rowActive} />}
|
||||
active={rowActive && trace.kind !== "done"}
|
||||
tone={status === "error" ? "error" : status === "done" ? "success" : "active"}
|
||||
label={[trace.label, trace.detail].filter(Boolean).join(" ")}
|
||||
label={formatActivityTarget(t, trace.label, trace.detail)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1264,6 +1266,7 @@ function CliRunGroup({
|
||||
}
|
||||
|
||||
function CliRunRow({ run, active, app }: { run: CliRunSummary; active: boolean; app?: CliAppInfo }) {
|
||||
const { t } = useTranslation();
|
||||
const args = compactActivityPath(redactShellCommand(formatCliArgs(run)));
|
||||
const failed = run.status === "error";
|
||||
const rowActive = active && run.status === "running";
|
||||
@@ -1271,8 +1274,10 @@ function CliRunRow({ run, active, app }: { run: CliRunSummary; active: boolean;
|
||||
const logoUrls = useMemo(() => logoFallbackUrls(app?.logo_url), [app?.logo_url]);
|
||||
const { logoUrl, onLogoError, onLogoLoad } = useLogoFallback(logoUrls);
|
||||
const displayName = app?.display_name || titleFromPresetName(run.name);
|
||||
const action = failed ? "Could not use" : rowActive ? "Using" : "Used";
|
||||
const label = `${action} ${displayName}${args ? ` · ${args}` : ""}`;
|
||||
const label = `${t(
|
||||
`message.${failed ? "cliActivityFailedOne" : rowActive ? "cliActivityRunningOne" : "cliActivityRanOne"}`,
|
||||
{ name: displayName },
|
||||
)}${args ? ` · ${args}` : ""}`;
|
||||
|
||||
return (
|
||||
<ActivityStep
|
||||
@@ -1339,6 +1344,7 @@ function McpRunGroup({
|
||||
}
|
||||
|
||||
function McpRunRow({ run, active, preset }: { run: McpRunSummary; active: boolean; preset?: McpPresetInfo }) {
|
||||
const { t } = useTranslation();
|
||||
const failed = run.status === "error";
|
||||
const rowActive = active && run.status === "running";
|
||||
const color = failed ? "#DC2626" : preset?.brand_color || "#6D5DF6";
|
||||
@@ -1349,8 +1355,9 @@ function McpRunRow({ run, active, preset }: { run: McpRunSummary; active: boolea
|
||||
run.toolName,
|
||||
run.args,
|
||||
failed ? "error" : rowActive ? "running" : "done",
|
||||
t,
|
||||
);
|
||||
const label = `${activity.action}${activity.target ? ` ${activity.target}` : ""} · ${displayName}`;
|
||||
const label = `${formatActivityTarget(t, activity.action, activity.target ?? "")} · ${displayName}`;
|
||||
|
||||
return (
|
||||
<ActivityStep
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
ChevronUp,
|
||||
ExternalLink,
|
||||
} from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
|
||||
import { FileReferenceChip } from "@/components/FileReferenceChip";
|
||||
import { codeLanguageFromPath } from "@/lib/code-language";
|
||||
@@ -21,6 +21,7 @@ import type { UIFileDiff, UIFileEdit } from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
import { ActivityStep } from "./ActivityStep";
|
||||
import { formatActivityTarget } from "./activity-text";
|
||||
import { DiffPair } from "./DiffPair";
|
||||
import { DiffSyntaxHighlight } from "./DiffSyntaxHighlight";
|
||||
|
||||
@@ -90,7 +91,7 @@ function FileEditRow({
|
||||
const { t } = useTranslation();
|
||||
const editing = edit.status === "editing";
|
||||
const failed = edit.status === "error";
|
||||
const action = fileEditAction(edit, editing, failed);
|
||||
const action = fileEditAction(edit, editing, failed, t);
|
||||
const hasCountedDiff = !failed && !edit.binary && hasVisibleDiffStats(edit);
|
||||
const showDiff = canRenderDiff(edit, displayMode);
|
||||
|
||||
@@ -101,21 +102,29 @@ function FileEditRow({
|
||||
active={editing}
|
||||
tone={failed ? "error" : editing ? "active" : "success"}
|
||||
className="text-xs"
|
||||
ariaLabel={edit.path ? `${action} ${edit.path}` : action}
|
||||
ariaLabel={formatActivityTarget(t, action, edit.path)}
|
||||
label={edit.pending && !edit.path
|
||||
? t("message.fileEditPreparing", { defaultValue: "Preparing file edit…" })
|
||||
: (
|
||||
<span className="flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap">
|
||||
<span className={cn("shrink-0", failed && "text-destructive/80")}>{action}</span>
|
||||
<FileReferenceChip
|
||||
path={edit.path}
|
||||
previewPath={edit.absolute_path || edit.path}
|
||||
onOpen={onOpenFilePreview}
|
||||
display="path"
|
||||
active={editing}
|
||||
className="min-w-0"
|
||||
textClassName="truncate text-[12px]"
|
||||
testId="activity-file-reference"
|
||||
<Trans
|
||||
i18nKey="message.agentActivity.actionTargetRich"
|
||||
values={{ action }}
|
||||
components={{
|
||||
action: <span className={cn("shrink-0", failed && "text-destructive/80")} />,
|
||||
target: (
|
||||
<FileReferenceChip
|
||||
path={edit.path}
|
||||
previewPath={edit.absolute_path || edit.path}
|
||||
onOpen={onOpenFilePreview}
|
||||
display="path"
|
||||
active={editing}
|
||||
className="min-w-0"
|
||||
textClassName="truncate text-[12px]"
|
||||
testId="activity-file-reference"
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
{hasCountedDiff ? <DiffPair added={edit.added} deleted={edit.deleted} /> : null}
|
||||
</span>
|
||||
@@ -137,11 +146,16 @@ function hasVisibleDiffStats(edit: Pick<FileEditSummary, "added" | "deleted">):
|
||||
return edit.added > 0 || edit.deleted > 0;
|
||||
}
|
||||
|
||||
function fileEditAction(edit: FileEditSummary, editing: boolean, failed: boolean): string {
|
||||
function fileEditAction(
|
||||
edit: FileEditSummary,
|
||||
editing: boolean,
|
||||
failed: boolean,
|
||||
t: ReturnType<typeof useTranslation>["t"],
|
||||
): string {
|
||||
const deleting = edit.operation === "delete";
|
||||
if (failed) return deleting ? "Could not delete" : "Could not edit";
|
||||
if (editing) return deleting ? "Deleting" : "Editing";
|
||||
return deleting ? "Deleted" : "Edited";
|
||||
if (failed) return t(`message.agentActivity.${deleting ? "deleteFileFailed" : "editFileFailedShort"}`);
|
||||
if (editing) return t(`message.agentActivity.${deleting ? "deletingFile" : "editingFileShort"}`);
|
||||
return t(`message.agentActivity.${deleting ? "deletedFile" : "editedFileShort"}`);
|
||||
}
|
||||
|
||||
function canRenderDiff(edit: FileEditSummary, displayMode: FileEditDisplayMode): boolean {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type LucideIcon,
|
||||
} from "lucide-react";
|
||||
import { useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { ActivityStep } from "@/components/thread/activity/ActivityStep";
|
||||
import {
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
type GenericToolStatus,
|
||||
type ToolFamily,
|
||||
} from "@/components/thread/activity/generic-tool-model";
|
||||
import { formatActivityTarget } from "@/components/thread/activity/activity-text";
|
||||
|
||||
interface GenericToolRunModel {
|
||||
status: GenericToolStatus;
|
||||
@@ -26,8 +28,9 @@ interface GenericToolRunModel {
|
||||
}
|
||||
|
||||
export function GenericToolRun({ items }: { items: GenericToolRunItem[] }) {
|
||||
const model = useMemo(() => buildModel(items), [items]);
|
||||
const action = [model.label, model.detail].filter(Boolean).join(" ");
|
||||
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 (
|
||||
@@ -40,9 +43,9 @@ export function GenericToolRun({ items }: { items: GenericToolRunItem[] }) {
|
||||
);
|
||||
}
|
||||
|
||||
function buildModel(items: GenericToolRunItem[]): GenericToolRunModel {
|
||||
function buildModel(items: GenericToolRunItem[], t: ReturnType<typeof useTranslation>["t"]): GenericToolRunModel {
|
||||
const family = items[0]?.trace.family ?? "generic";
|
||||
const presentation = describeGenericToolRun(items);
|
||||
const presentation = describeGenericToolRun(items, t);
|
||||
return {
|
||||
...presentation,
|
||||
icon: activityIcon(family),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AlertCircle, Search } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { ActivityStep } from "@/components/thread/activity/ActivityStep";
|
||||
import { WebActivityRow } from "@/components/thread/activity/WebActivityRow";
|
||||
@@ -8,9 +9,10 @@ import {
|
||||
} from "@/components/thread/activity/web-search-model";
|
||||
|
||||
export function WebSearchRun({ run, turnActive }: { run: WebSearchRunModel; turnActive: boolean }) {
|
||||
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);
|
||||
const label = presentWebSearchAction(run.query, status, run.target, t);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
export function redactActivityText(value: string): string {
|
||||
return value
|
||||
.replace(/(https?:\/\/)[^/@\s]+@/gi, "$1<redacted>@")
|
||||
@@ -48,16 +50,22 @@ export function safeActivityDetail(value: string, maxLength = 96): string {
|
||||
);
|
||||
}
|
||||
|
||||
export function summarizeShellCommand(command: string): string {
|
||||
export function formatActivityTarget(t: TFunction, action: string, target: string): string {
|
||||
return target
|
||||
? t("message.agentActivity.actionTarget", { action, target })
|
||||
: action;
|
||||
}
|
||||
|
||||
export function summarizeShellCommand(command: string, t: TFunction): string {
|
||||
const lines = redactShellCommand(command.replace(/\r\n/g, "\n"))
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean);
|
||||
const firstLine = compactActivityPath(lines[0] || "command");
|
||||
const firstLine = compactActivityPath(lines[0] || t("message.agentActivity.command"));
|
||||
const firstPreview = truncateMiddle(firstLine, 92);
|
||||
return lines.length <= 1
|
||||
? firstPreview
|
||||
: `${firstPreview} · script, ${lines.length} lines`;
|
||||
: `${firstPreview} · ${t("message.agentActivity.scriptLines", { count: lines.length })}`;
|
||||
}
|
||||
|
||||
function truncateMiddle(value: string, maxLength: number): string {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
import { compactActivityPath, redactActivityText } from "./activity-text";
|
||||
|
||||
export type GenericToolStatus = "running" | "done" | "error";
|
||||
@@ -110,16 +112,19 @@ function compactGenericToolPath(value: string): string {
|
||||
return compactActivityPath(normalized);
|
||||
}
|
||||
|
||||
export function describeGenericToolRun(items: GenericToolRunItem[]): GenericToolPresentation {
|
||||
export function describeGenericToolRun(
|
||||
items: GenericToolRunItem[],
|
||||
t: TFunction,
|
||||
): GenericToolPresentation {
|
||||
const status = aggregateStatus(items);
|
||||
const family = items[0]?.trace.family ?? "generic";
|
||||
const name = items[0]?.trace.name ?? "tool";
|
||||
const collected = items.length > 0 && items.every((item) => item.trace.collectedSource);
|
||||
return {
|
||||
status,
|
||||
label: activityLabel(family, status, collected, name, items),
|
||||
label: activityLabel(family, status, collected, name, items, t),
|
||||
detail: activityDetail(items, family, name),
|
||||
aside: activityAside(items, family),
|
||||
aside: activityAside(items, family, t),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -193,67 +198,83 @@ function activityLabel(
|
||||
collected: boolean,
|
||||
name: string,
|
||||
items: GenericToolRunItem[],
|
||||
t: TFunction,
|
||||
): string {
|
||||
if (family === "content-search") {
|
||||
return statusCopy(
|
||||
status,
|
||||
collected ? "Reviewing sources" : "Searching files",
|
||||
collected ? "Reviewed sources" : "Searched files",
|
||||
collected ? "Could not review sources" : "Could not search files",
|
||||
collected ? t("message.agentActivity.reviewingSources") : t("message.agentActivity.searchingFiles"),
|
||||
collected ? t("message.agentActivity.reviewedSources") : t("message.agentActivity.searchedFiles"),
|
||||
collected ? t("message.agentActivity.reviewSourcesFailed") : t("message.agentActivity.searchFilesFailed"),
|
||||
);
|
||||
}
|
||||
if (family === "file-search") {
|
||||
return statusCopy(status, "Finding files", "Found files", "Could not find files");
|
||||
return statusCopy(
|
||||
status,
|
||||
t("message.agentActivity.findingFiles"),
|
||||
t("message.agentActivity.foundFiles"),
|
||||
t("message.agentActivity.findFilesFailed"),
|
||||
);
|
||||
}
|
||||
if (family === "list") {
|
||||
return statusCopy(status, "Listing files", "Listed files", "Could not list files");
|
||||
return statusCopy(
|
||||
status,
|
||||
t("message.agentActivity.listingFiles"),
|
||||
t("message.agentActivity.listedFiles"),
|
||||
t("message.agentActivity.listFilesFailed"),
|
||||
);
|
||||
}
|
||||
if (family === "read") {
|
||||
return statusCopy(
|
||||
status,
|
||||
collected ? "Reading source" : "Reading file",
|
||||
collected ? "Read source" : "Read file",
|
||||
collected ? "Could not read source" : "Could not read file",
|
||||
collected ? t("message.agentActivity.readingSource") : t("message.agentActivity.readingFile"),
|
||||
collected ? t("message.agentActivity.readSource") : t("message.agentActivity.readFile"),
|
||||
collected ? t("message.agentActivity.readSourceFailed") : t("message.agentActivity.readFileFailed"),
|
||||
);
|
||||
}
|
||||
if (family === "memory") {
|
||||
return statusCopy(status, "Searching memory", "Searched memory", "Could not search memory");
|
||||
return statusCopy(
|
||||
status,
|
||||
t("message.agentActivity.searchingMemory"),
|
||||
t("message.agentActivity.searchedMemory"),
|
||||
t("message.agentActivity.searchMemoryFailed"),
|
||||
);
|
||||
}
|
||||
|
||||
const action = fieldValue(items[0]?.trace, "action").toLowerCase();
|
||||
switch (name) {
|
||||
case "generate_image":
|
||||
return statusCopy(status, "Generating image", "Generated image", "Could not generate image");
|
||||
return activityStatus(t, status, "generatingImage", "generatedImage", "generateImageFailed");
|
||||
case "spawn":
|
||||
return statusCopy(status, "Delegating task", "Delegated task", "Could not delegate task");
|
||||
return activityStatus(t, status, "delegatingTask", "delegatedTask", "delegateTaskFailed");
|
||||
case "message":
|
||||
return statusCopy(status, "Sending message", "Sent message", "Could not send message");
|
||||
return activityStatus(t, status, "sendingMessage", "sentMessage", "sendMessageFailed");
|
||||
case "my":
|
||||
return action === "set" || action === "modify"
|
||||
? statusCopy(status, "Updating agent settings", "Updated agent settings", "Could not update agent settings")
|
||||
: statusCopy(status, "Checking agent settings", "Checked agent settings", "Could not check agent settings");
|
||||
? activityStatus(t, status, "updatingAgentSettings", "updatedAgentSettings", "updateAgentSettingsFailed")
|
||||
: activityStatus(t, status, "checkingAgentSettings", "checkedAgentSettings", "checkAgentSettingsFailed");
|
||||
case "cron":
|
||||
if (action === "add") return statusCopy(status, "Scheduling automation", "Scheduled automation", "Could not schedule automation");
|
||||
if (action === "remove") return statusCopy(status, "Removing automation", "Removed automation", "Could not remove automation");
|
||||
return statusCopy(status, "Checking automations", "Checked automations", "Could not check automations");
|
||||
if (action === "add") return activityStatus(t, status, "schedulingAutomation", "scheduledAutomation", "scheduleAutomationFailed");
|
||||
if (action === "remove") return activityStatus(t, status, "removingAutomation", "removedAutomation", "removeAutomationFailed");
|
||||
return activityStatus(t, status, "checkingAutomations", "checkedAutomations", "checkAutomationsFailed");
|
||||
case "create_goal":
|
||||
return statusCopy(status, "Starting long task", "Started long task", "Could not start long task");
|
||||
return activityStatus(t, status, "startingLongTask", "startedLongTask", "startLongTaskFailed");
|
||||
case "update_goal":
|
||||
return statusCopy(status, "Updating long task", "Updated long task", "Could not update long task");
|
||||
return activityStatus(t, status, "updatingLongTask", "updatedLongTask", "updateLongTaskFailed");
|
||||
case "exec_session":
|
||||
return statusCopy(status, "Continuing command", "Continued command", "Could not continue command");
|
||||
return activityStatus(t, status, "continuingCommand", "continuedCommand", "continueCommandFailed");
|
||||
case "list_exec_sessions":
|
||||
return statusCopy(status, "Checking running commands", "Checked running commands", "Could not check running commands");
|
||||
return activityStatus(t, status, "checkingRunningCommands", "checkedRunningCommands", "checkRunningCommandsFailed");
|
||||
case "screenshot":
|
||||
case "capture_screenshot":
|
||||
return statusCopy(status, "Capturing screenshot", "Captured screenshot", "Could not capture screenshot");
|
||||
return activityStatus(t, status, "capturingScreenshot", "capturedScreenshot", "captureScreenshotFailed");
|
||||
default: {
|
||||
const humanName = humanizeToolName(name);
|
||||
return statusCopy(
|
||||
status,
|
||||
`Running ${humanName}`,
|
||||
`Completed ${humanName}`,
|
||||
`Could not complete ${humanName}`,
|
||||
t("message.agentActivity.runningTool", { name: humanName }),
|
||||
t("message.agentActivity.completedTool", { name: humanName }),
|
||||
t("message.agentActivity.completeToolFailed", { name: humanName }),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -301,14 +322,14 @@ function activityDetail(items: GenericToolRunItem[], family: ToolFamily, name: s
|
||||
}
|
||||
}
|
||||
|
||||
function activityAside(items: GenericToolRunItem[], family: ToolFamily): string {
|
||||
function activityAside(items: GenericToolRunItem[], family: ToolFamily, t: TFunction): string {
|
||||
const pathCount = uniqueValues(items, ["path", "file_path"]).length;
|
||||
if (pathCount > 1) return `${pathCount} files`;
|
||||
if (pathCount > 1) return t("message.agentActivity.files", { count: pathCount });
|
||||
if (items.length <= 1) return "";
|
||||
if (family === "content-search" || family === "file-search" || family === "memory") {
|
||||
return `${items.length} searches`;
|
||||
return t("message.agentActivity.searches", { count: items.length });
|
||||
}
|
||||
return `${items.length} actions`;
|
||||
return t("message.agentActivity.actions", { count: items.length });
|
||||
}
|
||||
|
||||
function fieldValue(trace: GenericToolTrace | undefined, key: ToolField["key"]): string {
|
||||
@@ -326,6 +347,21 @@ function statusCopy(status: GenericToolStatus, running: string, done: string, fa
|
||||
return status === "running" ? running : status === "error" ? failed : done;
|
||||
}
|
||||
|
||||
function activityStatus(
|
||||
t: TFunction,
|
||||
status: GenericToolStatus,
|
||||
running: string,
|
||||
done: string,
|
||||
failed: string,
|
||||
): string {
|
||||
return statusCopy(
|
||||
status,
|
||||
t(`message.agentActivity.${running}`),
|
||||
t(`message.agentActivity.${done}`),
|
||||
t(`message.agentActivity.${failed}`),
|
||||
);
|
||||
}
|
||||
|
||||
function compactDetail(value: string): string {
|
||||
return value ? truncateMiddle(compactGenericToolPath(value), 88) : "";
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
import { safeActivityDetail } from "./activity-text";
|
||||
import { formatCompactWebUrl, parseSafeActivityHttpUrl } from "./web-url";
|
||||
|
||||
@@ -12,57 +14,59 @@ export function describeMcpActivity(
|
||||
toolName: string,
|
||||
args: unknown,
|
||||
status: McpActivityStatus,
|
||||
t: TFunction,
|
||||
): McpActivityDescription {
|
||||
const name = toolName.toLowerCase();
|
||||
|
||||
if (matches(name, "navigate", "goto", "open_url", "visit")) {
|
||||
return describe(status, "Opening", "Opened", "Could not open", value(args, ["url"]));
|
||||
return describe(status, t, "opening", "opened", "openFailed", value(args, ["url"]));
|
||||
}
|
||||
if (matches(name, "click", "tap")) {
|
||||
return describe(status, "Clicking", "Clicked", "Could not click", elementTarget(args));
|
||||
return describe(status, t, "clicking", "clicked", "clickFailed", elementTarget(args));
|
||||
}
|
||||
if (matches(name, "type", "fill", "enter_text", "insert_text")) {
|
||||
const target = value(args, ["element", "selector", "ref", "name"]);
|
||||
return describe(status, "Entering text", "Entered text", "Could not enter text", target && `in ${target}`);
|
||||
return describe(status, t, "enteringText", "enteredText", "enterTextFailed", target && t("message.agentActivity.inTarget", { target }));
|
||||
}
|
||||
if (matches(name, "press_key", "keypress")) {
|
||||
return describe(status, "Pressing", "Pressed", "Could not press", value(args, ["key"]));
|
||||
return describe(status, t, "pressing", "pressed", "pressFailed", value(args, ["key"]));
|
||||
}
|
||||
if (matches(name, "hover")) {
|
||||
return describe(status, "Hovering over", "Hovered over", "Could not hover over", elementTarget(args));
|
||||
return describe(status, t, "hovering", "hovered", "hoverFailed", elementTarget(args));
|
||||
}
|
||||
if (matches(name, "select", "select_option")) {
|
||||
return describe(status, "Selecting", "Selected", "Could not select", elementTarget(args));
|
||||
return describe(status, t, "selecting", "selected", "selectFailed", elementTarget(args));
|
||||
}
|
||||
if (matches(name, "snapshot", "inspect", "get_page_content", "page_content")) {
|
||||
return describe(status, "Inspecting page", "Inspected page", "Could not inspect page");
|
||||
return describe(status, t, "inspectingPage", "inspectedPage", "inspectPageFailed");
|
||||
}
|
||||
if (matches(name, "screenshot", "capture_screenshot")) {
|
||||
return describe(status, "Capturing screenshot", "Captured screenshot", "Could not capture screenshot");
|
||||
return describe(status, t, "capturingScreenshot", "capturedScreenshot", "captureScreenshotFailed");
|
||||
}
|
||||
if (matches(name, "wait", "wait_for")) {
|
||||
return describe(status, "Waiting for page", "Waited for page", "Page did not become ready");
|
||||
return describe(status, t, "waitingForPage", "waitedForPage", "pageNotReady");
|
||||
}
|
||||
if (matches(name, "search", "web_search")) {
|
||||
return describe(status, "Searching", "Searched", "Could not search", value(args, ["query", "q"]));
|
||||
return describe(status, t, "searchingPlain", "searchedPlain", "searchFailedPlain", value(args, ["query", "q"]));
|
||||
}
|
||||
|
||||
const action = humanizeToolName(toolName);
|
||||
if (status === "running") return { action: `Running ${action}` };
|
||||
if (status === "error") return { action: `${action} failed` };
|
||||
return { action: `${action} completed` };
|
||||
const action = humanizeToolName(toolName, t);
|
||||
if (status === "running") return { action: t("message.agentActivity.runningTool", { name: action }) };
|
||||
if (status === "error") return { action: t("message.agentActivity.toolFailed", { name: action }) };
|
||||
return { action: t("message.agentActivity.toolCompleted", { name: action }) };
|
||||
}
|
||||
|
||||
function describe(
|
||||
status: McpActivityStatus,
|
||||
t: TFunction,
|
||||
running: string,
|
||||
done: string,
|
||||
failed: string,
|
||||
target?: string,
|
||||
): McpActivityDescription {
|
||||
return {
|
||||
action: status === "running" ? running : status === "error" ? failed : done,
|
||||
target: target ? compactUrl(target) : undefined,
|
||||
action: t(`message.agentActivity.${status === "running" ? running : status === "error" ? failed : done}`),
|
||||
target: target ? compactUrl(target, t) : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -85,14 +89,14 @@ function value(args: unknown, keys: string[]): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function compactUrl(value: string): string {
|
||||
function compactUrl(value: string, t: TFunction): string {
|
||||
const url = parseSafeActivityHttpUrl(value);
|
||||
if (url) return formatCompactWebUrl(url);
|
||||
if (/^https?:\/\//i.test(value.trim())) return "Private address";
|
||||
if (/^https?:\/\//i.test(value.trim())) return t("message.agentActivity.privateAddress");
|
||||
return safeActivityDetail(value, 80);
|
||||
}
|
||||
|
||||
function humanizeToolName(value: string): string {
|
||||
function humanizeToolName(value: string, t: TFunction): string {
|
||||
const words = value
|
||||
.replace(/^(?:browser|page|playwright)[_.-]+/i, "")
|
||||
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
||||
@@ -100,5 +104,5 @@ function humanizeToolName(value: string): string {
|
||||
.replace(/\s+/g, " ")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
return words ? `${words[0].toUpperCase()}${words.slice(1)}` : "Tool call";
|
||||
return words ? `${words[0].toUpperCase()}${words.slice(1)}` : t("message.agentActivity.toolCall");
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
import type { GenericToolStatus } from "./generic-tool-model";
|
||||
import { safeActivityDetail, summarizeShellCommand } from "./activity-text";
|
||||
import { presentWebSearchAction } from "./web-search-model";
|
||||
@@ -15,6 +17,7 @@ export interface TraceDescription {
|
||||
export function describeTraceLine(
|
||||
line: string,
|
||||
status: GenericToolStatus,
|
||||
t: TFunction,
|
||||
result?: unknown,
|
||||
): TraceDescription {
|
||||
const trimmed = line.trim();
|
||||
@@ -30,7 +33,7 @@ export function describeTraceLine(
|
||||
const query = traceFieldFromArgs(args, ["query", "q", "text"]) || args;
|
||||
return {
|
||||
kind: "search",
|
||||
label: presentWebSearchAction(query, status, name === "x_search" ? "x" : "web"),
|
||||
label: presentWebSearchAction(query, status, name === "x_search" ? "x" : "web", t),
|
||||
detail: "",
|
||||
};
|
||||
}
|
||||
@@ -39,20 +42,20 @@ export function describeTraceLine(
|
||||
const pageTitle = parsedUrl ? webPageTitle(result) : "";
|
||||
return {
|
||||
kind: "tool",
|
||||
label: pageTitle || statusCopy(status, "Reading", "Read", "Could not read"),
|
||||
label: pageTitle || activityStatus(t, status, "reading", "read", "readFailed"),
|
||||
detail: webDetail || (/^https?:\/\//i.test(rawTarget.trim())
|
||||
? "Private address"
|
||||
? t("message.agentActivity.privateAddress")
|
||||
: safeActivityDetail(rawTarget)),
|
||||
url: parsedUrl?.href,
|
||||
host: parsedUrl ? displayWebHost(parsedUrl.hostname) : undefined,
|
||||
};
|
||||
}
|
||||
if (isShellTraceName(name)) return describeShellTrace(args, trimmed, status);
|
||||
if (isShellTraceName(name)) return describeShellTrace(args, trimmed, status, t);
|
||||
if (name === "write_file") {
|
||||
return describeFileMutationTrace(args, status, "Writing file", "Wrote file", "Could not write file");
|
||||
return describeFileMutationTrace(args, status, t, "writingFile", "wroteFile", "writeFileFailed");
|
||||
}
|
||||
if (name === "edit_file" || name === "apply_patch") {
|
||||
return describeFileMutationTrace(args, status, "Editing file", "Edited file", "Could not edit file");
|
||||
return describeFileMutationTrace(args, status, t, "editingFile", "editedFile", "editFileFailed");
|
||||
}
|
||||
if (name) {
|
||||
const action = humanizeTraceToolName(name);
|
||||
@@ -60,19 +63,19 @@ export function describeTraceLine(
|
||||
kind: "tool",
|
||||
label: statusCopy(
|
||||
status,
|
||||
`Running ${action}`,
|
||||
`Completed ${action}`,
|
||||
`Could not complete ${action}`,
|
||||
t("message.agentActivity.runningTool", { name: action }),
|
||||
t("message.agentActivity.completedTool", { name: action }),
|
||||
t("message.agentActivity.completeToolFailed", { name: action }),
|
||||
),
|
||||
detail: "",
|
||||
};
|
||||
}
|
||||
if (/done|complete|success/i.test(trimmed)) {
|
||||
return { kind: "done", label: "Completed step", detail: safeActivityDetail(trimmed) };
|
||||
return { kind: "done", label: t("message.agentActivity.completedStep"), detail: safeActivityDetail(trimmed) };
|
||||
}
|
||||
return {
|
||||
kind: status === "done" ? "done" : "trace",
|
||||
label: statusCopy(status, "Working", "Completed step", "Step failed"),
|
||||
label: activityStatus(t, status, "working", "completedStep", "stepFailed"),
|
||||
detail: safeActivityDetail(trimmed),
|
||||
};
|
||||
}
|
||||
@@ -91,31 +94,28 @@ function describeShellTrace(
|
||||
args: string,
|
||||
fallback: string,
|
||||
status: GenericToolStatus,
|
||||
t: TFunction,
|
||||
): TraceDescription {
|
||||
const command = shellCommandFromArgs(args) || fallback;
|
||||
if (/^(?:\/(?:usr\/)?bin\/)?date(?:\s|$)/i.test(command.trim())) {
|
||||
return {
|
||||
kind: "tool",
|
||||
label: statusCopy(
|
||||
status,
|
||||
"Checking current time",
|
||||
"Checked current time",
|
||||
"Could not check current time",
|
||||
),
|
||||
label: activityStatus(t, status, "checkingCurrentTime", "checkedCurrentTime", "checkCurrentTimeFailed"),
|
||||
detail: "",
|
||||
icon: "clock",
|
||||
};
|
||||
}
|
||||
return {
|
||||
kind: "tool",
|
||||
label: statusCopy(status, "Running command", "Ran command", "Command failed"),
|
||||
detail: summarizeShellCommand(command),
|
||||
label: activityStatus(t, status, "runningCommand", "ranCommand", "commandFailed"),
|
||||
detail: summarizeShellCommand(command, t),
|
||||
};
|
||||
}
|
||||
|
||||
function describeFileMutationTrace(
|
||||
args: string,
|
||||
status: GenericToolStatus,
|
||||
t: TFunction,
|
||||
running: string,
|
||||
done: string,
|
||||
failed: string,
|
||||
@@ -123,7 +123,7 @@ function describeFileMutationTrace(
|
||||
const path = traceFieldFromArgs(args, ["path", "file_path"]);
|
||||
return {
|
||||
kind: "tool",
|
||||
label: statusCopy(status, running, done, failed),
|
||||
label: activityStatus(t, status, running, done, failed),
|
||||
detail: path ? safeActivityDetail(path) : "",
|
||||
};
|
||||
}
|
||||
@@ -137,6 +137,21 @@ function statusCopy(
|
||||
return status === "running" ? running : status === "error" ? failed : done;
|
||||
}
|
||||
|
||||
function activityStatus(
|
||||
t: TFunction,
|
||||
status: GenericToolStatus,
|
||||
running: string,
|
||||
done: string,
|
||||
failed: string,
|
||||
): string {
|
||||
return statusCopy(
|
||||
status,
|
||||
t(`message.agentActivity.${running}`),
|
||||
t(`message.agentActivity.${done}`),
|
||||
t(`message.agentActivity.${failed}`),
|
||||
);
|
||||
}
|
||||
|
||||
function traceFieldFromArgs(args: string, keys: string[]): string {
|
||||
const compactArgs = args.trim();
|
||||
if (!compactArgs) return "";
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
import { canonicalToolTrace, formatToolCallTrace } from "@/lib/tool-traces";
|
||||
import type { ToolProgressEvent } from "@/lib/types";
|
||||
|
||||
@@ -94,18 +96,15 @@ export function presentWebSearchAction(
|
||||
query: string,
|
||||
status: WebSearchStatus,
|
||||
target: WebSearchTarget = "web",
|
||||
t: TFunction,
|
||||
): string {
|
||||
const presentation = presentWebSearchQuery(query);
|
||||
const verb = status === "error"
|
||||
? "Could not search"
|
||||
: status === "running"
|
||||
? "Searching"
|
||||
: "Searched";
|
||||
const queryTarget = [presentation.scope, presentation.query].filter(Boolean).join(" · ");
|
||||
if (target === "x") {
|
||||
return queryTarget ? `${verb} X · ${queryTarget}` : `${verb} X`;
|
||||
}
|
||||
return queryTarget ? `${verb} ${queryTarget}` : `${verb} the web`;
|
||||
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 });
|
||||
}
|
||||
|
||||
function mergeWebSearchRun(
|
||||
|
||||
Reference in new issue
Block a user