Files
nanobot/webui/src/components/thread/activity/GenericToolRun.tsx
T
ZhouandXubin Ren 796e1cb0e6 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>
2026-09-25 01:50:12 +08:00

62 lines
1.8 KiB
TypeScript

import {
AlertCircle,
FileSearch,
FolderOpen,
ListTree,
MemoryStick,
Play,
type LucideIcon,
} from "lucide-react";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { ActivityStep } from "@/components/thread/activity/ActivityStep";
import {
describeGenericToolRun,
type GenericToolRunItem,
type GenericToolStatus,
type ToolFamily,
} from "@/components/thread/activity/generic-tool-model";
import { formatActivityTarget } from "@/components/thread/activity/activity-text";
interface GenericToolRunModel {
status: GenericToolStatus;
label: string;
detail: string;
aside: string;
icon: LucideIcon;
}
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}
/>
);
}
function buildModel(items: GenericToolRunItem[], t: ReturnType<typeof useTranslation>["t"]): GenericToolRunModel {
const family = items[0]?.trace.family ?? "generic";
const presentation = describeGenericToolRun(items, t);
return {
...presentation,
icon: activityIcon(family),
};
}
function activityIcon(family: ToolFamily): LucideIcon {
if (family === "content-search" || family === "file-search") return FileSearch;
if (family === "list") return ListTree;
if (family === "read") return FolderOpen;
if (family === "memory") return MemoryStick;
return Play;
}