fix(webui): correct activity duration display

This commit is contained in:
chengyongru
2026-06-18 00:03:18 +08:00
committed by Xubin Ren
parent b46aac0554
commit 472c67722e
13 changed files with 109 additions and 18 deletions
@@ -359,6 +359,20 @@ describe("AgentActivityCluster", () => {
expect(screen.getByText("Thought for 12s")).toBeInTheDocument();
});
it("labels mixed tool activity as work instead of thought", () => {
render(
<AgentActivityCluster
messages={activityMessages()}
isTurnStreaming={false}
hasBodyBelow
turnLatencyMs={12_400}
/>,
);
expect(screen.getByText("Worked for 12s")).toBeInTheDocument();
expect(screen.queryByText("Thought for 12s")).not.toBeInTheDocument();
});
it("omits the duration when completed history has no reliable timing", () => {
render(
<AgentActivityCluster
+40 -3
View File
@@ -308,10 +308,47 @@ describe("ThreadMessages", () => {
render(<ThreadMessages messages={messages} isStreaming={false} />);
expect(screen.queryByRole("button", { name: /^thinking$/i })).not.toBeInTheDocument();
expect(screen.getByText("Thought for 9s")).toBeInTheDocument();
expect(screen.getByText("Worked for 9s")).toBeInTheDocument();
expect(screen.getByText("final answer")).toBeInTheDocument();
});
it("uses final turn latency when an earlier reasoning segment has its own latency", () => {
const messages: UIMessage[] = [
{
id: "r1",
role: "assistant",
content: "",
reasoning: "plan",
reasoningStreaming: false,
latencyMs: 3_000,
createdAt: 1,
},
{
id: "t1",
role: "tool",
kind: "trace",
content: "shell()",
traces: ["shell()"],
createdAt: 2,
},
{
id: "a1",
role: "assistant",
content: "done",
latencyMs: 20_000,
createdAt: 3,
},
];
const units = buildDisplayUnits(messages);
expect(units[0].type === "activity" ? units[0].turnLatencyMs : undefined).toBe(20_000);
render(<ThreadMessages messages={messages} isStreaming={false} />);
expect(screen.getByText("Worked for 20s")).toBeInTheDocument();
expect(screen.queryByText("Worked for 3s")).not.toBeInTheDocument();
});
it("keeps late activity after the live assistant answer while streaming", () => {
const messages: UIMessage[] = [
{
@@ -626,8 +663,8 @@ describe("ThreadMessages", () => {
render(<ThreadMessages messages={messages} isStreaming={false} />);
expect(screen.getByText("Thought for 15s")).toBeInTheDocument();
expect(screen.queryByText("Thought for 0s")).not.toBeInTheDocument();
expect(screen.getByText("Worked for 15s")).toBeInTheDocument();
expect(screen.queryByText("Worked for 0s")).not.toBeInTheDocument();
});
it("shows copy only on the last assistant slice before the next user turn", () => {