fix(webui): clarify command session activity

This commit is contained in:
chengyongru authored and chengyongru committed 2026-11-13 22:30:27 +08:00
1 parent c80ae65746
commit de9cce45b4
28 files changed
+1174 -68

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
import { useState } from "react";
import { AgentActivityCluster } from "@/components/thread/AgentActivityCluster";
import { ExecSessionCommandsContext } from "@/components/thread/activity/exec-session-context";
import { execSessionCommands } from "@/components/thread/activity/exec-session-model";
import { formatToolCallTrace } from "@/lib/tool-traces";
import type { ToolProgressEvent, UIMessage } from "@/lib/types";
const id = "012345abcdef";
const running = `Process running. session_id: ${id}\nRuntime remaining: 100.0s\nElapsed: 1.0s`;
const history: UIMessage[] = [{
id: "source", role: "tool", kind: "trace", content: "exec()", createdAt: 1,
toolEvents: [{ name: "exec", call_id: "source", phase: "end", arguments: { command: "curl -u alice:secret-value https://example.invalid" },
result: `${running}\nInitial wait ended; session remains active.` }],
}];
const commands = execSessionCommands(history);
type Stage = "waiting" | "running" | "input" | "failed" | "many";
function sessionMessage(stage: Stage): UIMessage {
let events: ToolProgressEvent[];
if (stage === "many") {
events = Array.from({ length: 25 }, (_, index) => ({
name: "exec_session", call_id: `poll-${index}`, phase: "end", arguments: { session_id: id }, result: running,
}));
} else {
events = [{ name: "exec_session", call_id: "poll", arguments: { session_id: id, ...(stage === "input" ? { input: "private-stdin" } : {}) },
phase: stage === "waiting" ? "start" : "end",
...(stage === "waiting" ? {} : { result: stage === "failed" ? "Exit code: 7\nElapsed: 2.0s" : running }) }];
}
const traces = events.map((event) => formatToolCallTrace(event)!);
return { id: "trace", role: "tool", kind: "trace", content: traces[0], traces, toolEvents: events, createdAt: 2 };
}
export function ExecSessionFixture() {
const [stage, setStage] = useState<Stage>("waiting");
return <main className="mx-auto max-w-2xl space-y-6 p-6">
<nav className="flex flex-wrap gap-3" aria-label="Fixture controls">
{(["waiting", "running", "input", "failed", "many"] as const).map((value) => (
<button key={value} onClick={() => setStage(value)}>{value}</button>
))}
</nav>
<section aria-label="Command activity">
<ExecSessionCommandsContext.Provider value={commands}>
<AgentActivityCluster messages={[sessionMessage(stage)]} isTurnStreaming hasBodyBelow={false} />
</ExecSessionCommandsContext.Provider>
</section>
</main>;
}
+30
View File
@@ -0,0 +1,30 @@
import { expect, test } from "@playwright/test";
for (const width of [1280, 360]) {
test(`shows command activity and keeps long check histories inspectable at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 720 });
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en"));
await page.goto("/browser/fixture.html?case=exec-session");
const activity = page.getByRole("region", { name: "Command activity" });
await expect(activity).toContainText("Waiting for command result curl -u •••• https://example.invalid");
await page.getByRole("button", { name: "running", exact: true }).click();
await expect(activity).toContainText("Command was still running at the last check curl -u •••• https://example.invalid");
await page.getByRole("button", { name: "input", exact: true }).click();
await expect(activity).toContainText("Sent input curl -u •••• https://example.invalid");
await page.getByRole("button", { name: "failed", exact: true }).click();
await expect(activity).toContainText("Command failed (exit code 7) curl -u •••• https://example.invalid");
await page.getByRole("button", { name: "many", exact: true }).click();
const disclosure = activity.getByRole("button", { name: "Show earlier command checks (24)" });
await expect(activity.getByTestId("activity-step")).toHaveCount(1);
await disclosure.click();
await expect(activity.getByTestId("activity-step")).toHaveCount(25);
await activity.getByRole("button", { name: "Hide earlier command checks (24)" }).click();
await expect(activity.getByTestId("activity-step")).toHaveCount(1);
await expect(activity).not.toContainText("012345abcdef");
await expect(activity).not.toContainText("private-stdin");
await expect(activity).not.toContainText("secret-value");
expect(await activity.innerHTML()).not.toContain("secret-value");
expect(await activity.innerHTML()).not.toContain("012345abcdef");
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBe(width);
});
}
+3
View File
@@ -33,6 +33,7 @@ import { ThreadLoadingFixture } from "./thread-loading-fixture";
import { AnswerOrderFixture } from "./answer-order-fixture";
import { SidebarActivityFixture } from "./sidebar-activity-fixture";
import { ActivityLogosFixture } from "./activity-logos-fixture";
import { ExecSessionFixture } from "./exec-session-fixture";
import { HistoryHydrationFixture } from "./history-hydration-fixture";
import { IdleCompactionFixture, installIdleCompactionApi } from "./idle-compaction-fixture";
import { FileEditPathFixture } from "./file-edit-path-fixture";
@@ -262,6 +263,8 @@ createRoot(document.getElementById("root")!).render(<TooltipProvider>
? <AnswerOrderFixture />
: parameters.get("case") === "activity-logos"
? <ActivityLogosFixture parameters={parameters} />
: parameters.get("case") === "exec-session"
? <ExecSessionFixture />
: parameters.get("case") === "sidebar-activity"
? <SidebarActivityFixture />
: parameters.get("case") === "chat-failure"