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:
ZhouandXubin Ren authored and Xubin Ren committed 2026-09-25 01:50:12 +08:00
1 parent f57cc3aad2
commit 796e1cb0e6
23 files changed
+1704 -128

No files matched your search

+30 -2
View File
@@ -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>"],