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
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { AgentActivityCluster } from "@/components/thread/AgentActivityCluster";
|
||||
import { preloadMarkdownText } from "@/components/MarkdownText";
|
||||
import { setAppLanguage } from "@/i18n";
|
||||
import { DEFAULT_LOCAL_PREFS, writeLocalPreferences } from "@/lib/local-preferences";
|
||||
import type { CliAppInfo, McpPresetInfo, UIMessage } from "@/lib/types";
|
||||
|
||||
@@ -97,6 +98,77 @@ function installReducedMotion() {
|
||||
}
|
||||
|
||||
describe("AgentActivityCluster", () => {
|
||||
it("updates existing activity when the language changes without altering raw values", async () => {
|
||||
const query = "release notes";
|
||||
const path = "src/app.tsx";
|
||||
const cliLine = 'run_cli_app({"name":"blender","args":["--background","scene.blend"],"json":true})';
|
||||
render(
|
||||
<AgentActivityCluster
|
||||
messages={[
|
||||
{
|
||||
id: "localized-activity",
|
||||
role: "tool",
|
||||
kind: "trace",
|
||||
content: cliLine,
|
||||
traces: [
|
||||
`grep(${JSON.stringify({ pattern: query })})`,
|
||||
`read_file(${JSON.stringify({ path })})`,
|
||||
cliLine,
|
||||
'mcp_browserbase_browser_navigate({"url":"https://example.com"})',
|
||||
"edit_file()",
|
||||
],
|
||||
toolEvents: [{
|
||||
phase: "start",
|
||||
call_id: "localized-browserbase",
|
||||
name: "mcp_browserbase_browser_navigate",
|
||||
arguments: { url: "https://example.com" },
|
||||
}],
|
||||
fileEdits: [{
|
||||
call_id: "localized-file-edit",
|
||||
tool: "edit_file",
|
||||
path,
|
||||
phase: "end",
|
||||
added: 1,
|
||||
deleted: 0,
|
||||
approximate: false,
|
||||
status: "done",
|
||||
}],
|
||||
createdAt: 1,
|
||||
},
|
||||
]}
|
||||
isTurnStreaming
|
||||
hasBodyBelow={false}
|
||||
cliApps={[BLENDER_CLI_APP]}
|
||||
mcpPresets={[BROWSERBASE_MCP]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByText(`Searched files “${query}”`)).toBeInTheDocument();
|
||||
expect(screen.getByText(`Reading file ${path}`)).toBeInTheDocument();
|
||||
expect(screen.getByText("Using Blender · --json --background scene.blend")).toBeInTheDocument();
|
||||
expect(screen.getByText("Opening example.com · Browserbase")).toBeInTheDocument();
|
||||
expect(screen.getByText("Edited")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent(path);
|
||||
|
||||
await act(async () => setAppLanguage("zh-CN"));
|
||||
|
||||
expect(screen.getByText(`已搜索文件 “${query}”`)).toBeInTheDocument();
|
||||
expect(screen.getByText(`正在读取文件 ${path}`)).toBeInTheDocument();
|
||||
expect(screen.getByText("正在使用 Blender · --json --background scene.blend")).toBeInTheDocument();
|
||||
expect(screen.getByText("正在打开 example.com · Browserbase")).toBeInTheDocument();
|
||||
expect(screen.getByText("已编辑")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent(path);
|
||||
|
||||
await act(async () => setAppLanguage("ja"));
|
||||
|
||||
expect(screen.getByText(`“${query}” · ファイルを検索しました`)).toBeInTheDocument();
|
||||
expect(screen.getByText(`${path} · ファイルを読み取り中`)).toBeInTheDocument();
|
||||
expect(screen.getByText("Blender を使用中 · --json --background scene.blend")).toBeInTheDocument();
|
||||
expect(screen.getByText("example.com · 開いています · Browserbase")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference").closest('[data-testid="activity-step"]'))
|
||||
.toHaveTextContent(`${path} · 編集しました`);
|
||||
});
|
||||
|
||||
it("loads deferred trace details only after completed activity is expanded", async () => {
|
||||
const onLoadTraceDetails = vi.fn();
|
||||
render(
|
||||
|
||||
@@ -6,11 +6,12 @@ import {
|
||||
parseGenericToolTrace,
|
||||
type GenericToolStatus,
|
||||
} from "@/components/thread/activity/generic-tool-model";
|
||||
import i18n, { setAppLanguage } from "@/i18n";
|
||||
|
||||
function describeRun(line: string, status: GenericToolStatus = "done") {
|
||||
const trace = parseGenericToolTrace(line);
|
||||
expect(trace).not.toBeNull();
|
||||
return describeGenericToolRun([{ trace: trace!, status }]);
|
||||
return describeGenericToolRun([{ trace: trace!, status }], i18n.t);
|
||||
}
|
||||
|
||||
describe("generic tool activity semantics", () => {
|
||||
@@ -59,7 +60,7 @@ describe("generic tool activity semantics", () => {
|
||||
const presentation = describeGenericToolRun([
|
||||
{ trace: first, status: "done" },
|
||||
{ trace: second, status: "done" },
|
||||
]);
|
||||
], i18n.t);
|
||||
|
||||
expect(presentation).toMatchObject({ label: "Reviewed sources", detail: "", aside: "2 files" });
|
||||
expect(JSON.stringify(presentation)).not.toContain("/Users/test");
|
||||
@@ -80,6 +81,33 @@ describe("generic tool activity semantics", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("localizes labels and counts without translating raw search text", async () => {
|
||||
await setAppLanguage("zh-CN");
|
||||
const first = parseGenericToolTrace('grep({"pattern":"release notes"})')!;
|
||||
const second = parseGenericToolTrace('grep({"pattern":"API changes"})')!;
|
||||
|
||||
expect(describeGenericToolRun([
|
||||
{ trace: first, status: "done" },
|
||||
{ trace: second, status: "done" },
|
||||
], i18n.t)).toMatchObject({
|
||||
label: "已搜索文件",
|
||||
aside: "2 次搜索",
|
||||
});
|
||||
});
|
||||
|
||||
it("localizes command continuation events", async () => {
|
||||
await setAppLanguage("zh-CN");
|
||||
const line = 'exec_session({"session_id":"session-1234567890-secret"})';
|
||||
for (const status of ["running", "done", "error"] as const) {
|
||||
const key = status === "running" ? "continuingCommand"
|
||||
: status === "done" ? "continuedCommand" : "continueCommandFailed";
|
||||
expect(describeRun(line, status)).toMatchObject({
|
||||
label: i18n.t(`message.agentActivity.${key}`),
|
||||
detail: "session…ecret",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
["Authorization: Bearer top-secret-token", "Authorization: <redacted>"],
|
||||
["API_KEY=sk-proj-1234567890abcdef", "API_KEY=<redacted>"],
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { describeMcpActivity } from "@/components/thread/activity/mcp-activity-model";
|
||||
import i18n, { setAppLanguage } from "@/i18n";
|
||||
|
||||
describe("describeMcpActivity", () => {
|
||||
it.each([
|
||||
@@ -10,7 +11,7 @@ describe("describeMcpActivity", () => {
|
||||
["browser_screenshot", {}, "done", "Captured screenshot", undefined],
|
||||
["browser_press_key", { key: "Enter" }, "error", "Could not press", "Enter"],
|
||||
] as const)("turns %s into user-facing activity copy", (tool, args, status, action, target) => {
|
||||
expect(describeMcpActivity(tool, args, status)).toEqual({ action, target });
|
||||
expect(describeMcpActivity(tool, args, status, i18n.t)).toEqual({ action, target });
|
||||
});
|
||||
|
||||
it("does not expose entered text in the activity timeline", () => {
|
||||
@@ -18,6 +19,7 @@ describe("describeMcpActivity", () => {
|
||||
"browser_fill",
|
||||
{ element: "Password", text: "not-for-the-timeline" },
|
||||
"done",
|
||||
i18n.t,
|
||||
)).toEqual({ action: "Entered text", target: "in Password" });
|
||||
});
|
||||
|
||||
@@ -26,12 +28,24 @@ describe("describeMcpActivity", () => {
|
||||
"browser_navigate",
|
||||
{ url: "https://user:password@example.com/docs?token=private#section" },
|
||||
"done",
|
||||
i18n.t,
|
||||
)).toEqual({ action: "Opened", target: "example.com/docs" });
|
||||
});
|
||||
|
||||
it("humanizes unknown tool names instead of exposing function syntax", () => {
|
||||
expect(describeMcpActivity("browser_export_report", {}, "done")).toEqual({
|
||||
expect(describeMcpActivity("browser_export_report", {}, "done", i18n.t)).toEqual({
|
||||
action: "Export report completed",
|
||||
});
|
||||
});
|
||||
|
||||
it("localizes browser actions without translating targets", async () => {
|
||||
await setAppLanguage("zh-CN");
|
||||
|
||||
expect(describeMcpActivity(
|
||||
"browser_fill",
|
||||
{ element: "Password", text: "not-for-the-timeline" },
|
||||
"done",
|
||||
i18n.t,
|
||||
)).toEqual({ action: "已输入文本", target: "至 Password" });
|
||||
});
|
||||
});
|
||||
@@ -2,9 +2,10 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { describeTraceLine } from "@/components/thread/activity/trace-activity-model";
|
||||
import type { GenericToolStatus } from "@/components/thread/activity/generic-tool-model";
|
||||
import i18n, { setAppLanguage } from "@/i18n";
|
||||
|
||||
function describeTrace(line: string, status: GenericToolStatus = "done") {
|
||||
return describeTraceLine(line, status);
|
||||
return describeTraceLine(line, status, i18n.t);
|
||||
}
|
||||
|
||||
describe("trace activity semantics", () => {
|
||||
@@ -66,4 +67,17 @@ describe("trace activity semantics", () => {
|
||||
});
|
||||
expect(result.detail).not.toContain("second-secret-line");
|
||||
});
|
||||
|
||||
it("localizes generated copy while preserving paths and commands", async () => {
|
||||
await setAppLanguage("zh-CN");
|
||||
|
||||
expect(describeTrace('read_file({"path":"src/app.tsx"})')).toMatchObject({
|
||||
label: "已读取",
|
||||
detail: "src/app.tsx",
|
||||
});
|
||||
expect(describeTrace('exec({"command":"bun test"})')).toMatchObject({
|
||||
label: "已运行命令",
|
||||
detail: "bun test",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user