feat(webui): show when the agent picks up queued messages (#6719)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-19 16:03:16 +08:00
1 parent 3025a01cf0
commit b453de9cf6
26 files changed
+642 -29

No files matched your search

+85
View File
@@ -376,6 +376,91 @@ describe("MessageBubble", () => {
expect(bubble).toHaveClass("user-message-surface", "bg-secondary/70");
});
it("seals the dashed edge into a solid border when the agent picks up a waiting message", () => {
const message: UIMessage = {
id: "u-pending",
role: "user",
content: "One more detail",
createdAt: Date.now(),
deliveryStatus: "accepted",
};
const { rerender } = render(<MessageBubble message={message} />);
const bubble = screen.getByText(message.content);
const originalClasses = bubble.className;
rerender(<MessageBubble message={{ ...message, processingStatus: "pending" }} />);
expect(bubble).toHaveClass("user-message-surface-dashed");
expect(bubble).toHaveAttribute("data-pending-edge", "pending");
expect(bubble.querySelector("[data-pending-edge-overlay='pending']")).toBeInTheDocument();
const waitingStatus = screen.getByRole("status");
expect(waitingStatus).toHaveClass("sr-only");
expect(waitingStatus).toHaveTextContent("Waiting to be processed");
rerender(<MessageBubble message={{ ...message, processingStatus: "consumed" }} />);
expect(bubble.className).toBe(originalClasses);
expect(bubble).toHaveAttribute("data-pending-edge", "sealing");
const sealingOverlay = bubble.querySelector("[data-pending-edge-overlay='sealing']");
expect(sealingOverlay).toBeInTheDocument();
expect(screen.queryByRole("status")).not.toBeInTheDocument();
const endEvent = new Event("animationend", { bubbles: true });
Object.defineProperty(endEvent, "animationName", { value: "pending-edge-seal" });
fireEvent(sealingOverlay!, endEvent);
expect(bubble).not.toHaveAttribute("data-pending-edge");
expect(bubble.querySelector("[data-pending-edge-overlay]")).not.toBeInTheDocument();
});
it("does not play the seal transition for already-consumed or cancelled user messages", () => {
const { container, rerender } = render(
<MessageBubble
message={{
id: "u-history-consumed",
role: "user",
content: "Already consumed",
createdAt: Date.now(),
processingStatus: "consumed",
}}
/>,
);
expect(container.querySelector("[data-pending-edge-overlay]")).not.toBeInTheDocument();
const pending: UIMessage = {
id: "u-waiting",
role: "user",
content: "Never picked up",
createdAt: Date.now(),
processingStatus: "pending",
};
rerender(<MessageBubble message={pending} />);
expect(container.querySelector("[data-pending-edge-overlay='pending']")).toBeInTheDocument();
rerender(<MessageBubble message={{ ...pending, processingStatus: undefined }} />);
expect(container.querySelector("[data-pending-edge-overlay]")).not.toBeInTheDocument();
});
it("seals media-only waiting user messages when consumed", () => {
const mediaMessage: UIMessage = {
id: "u-media-pending",
role: "user",
content: "",
createdAt: Date.now(),
processingStatus: "pending",
media: [{ kind: "file", name: "notes.txt", url: "/api/files/notes.txt" }],
};
const { container, rerender } = render(<MessageBubble message={mediaMessage} />);
expect(container.querySelector("[data-pending-edge-overlay='pending']")).toBeInTheDocument();
rerender(<MessageBubble message={{ ...mediaMessage, processingStatus: "consumed" }} />);
const sealingOverlay = container.querySelector("[data-pending-edge-overlay='sealing']");
expect(sealingOverlay).toBeInTheDocument();
const endEvent = new Event("animationend", { bubbles: true });
Object.defineProperty(endEvent, "animationName", { value: "pending-edge-seal" });
fireEvent(sealingOverlay!, endEvent);
expect(container.querySelector("[data-pending-edge-overlay]")).not.toBeInTheDocument();
});
it("renders completed message branches with static wrapper classes", async () => {
const messages: UIMessage[] = [
{
+51
View File
@@ -2564,6 +2564,57 @@ describe("useNanobotStream", () => {
]);
});
it("ends the live waiting hint only when a request starts for that input", () => {
const fake = fakeClient();
const chat = "chat-processing";
const { result } = renderHook(() => useNanobotStream(chat, EMPTY_MESSAGES), { wrapper: wrap(fake.client) });
const peerInput = (id: string, waiting = false) => fake.emit(chat, {
event: "user_message", chat_id: chat, turn_id: id, input_id: `user:${id}`,
starts_turn: !waiting, text: "identical prompt", ...(waiting ? { waiting_for_model: true } : {}),
});
let sequence = 0;
const request = (id: string, phase: "started" | "completed" = "started") => fake.emit(chat, {
event: "model_request", chat_id: chat, turn_id: "first", request_id: id, run_id: "run",
sequence: ++sequence, phase, response_input_ids: [`user:${id}`],
});
const state = (id: string) => result.current.messages.find((row) => row.inputId === `user:${id}`)?.processingStatus;
act(() => {
peerInput("first");
peerInput("followup", true);
request("first");
request("first", "completed");
});
expect(state("first")).toBeUndefined();
expect(state("followup")).toBe("pending");
act(() => request("followup"));
expect(state("followup")).toBe("consumed");
act(() => {
request("late-echo");
peerInput("late-echo", true);
});
expect(state("late-echo")).toBeUndefined();
});
it.each(["stop", "cancelled by another tab", "disconnect"])("drops the temporary waiting hint on %s", (event) => {
const fake = fakeClient();
const chat = "chat-processing";
const { result } = renderHook(() => useNanobotStream(chat, EMPTY_MESSAGES), { wrapper: wrap(fake.client) });
let turnId = "";
act(() => { turnId = result.current.send("follow-up")!.turnId; });
act(() => fake.emit(chat, {
event: "message_accepted", chat_id: chat, turn_id: turnId, active_turn_id: "active", waiting_for_model: true,
}));
expect(result.current.messages[0]).toMatchObject({ processingStatus: "pending", deliveryStatus: "accepted" });
act(() => {
if (event === "stop") result.current.stop();
else if (event === "disconnect") fake.emitStatus("reconnecting");
else fake.emit(chat, { event: "turn_end", chat_id: chat, turn_id: "active", outcome: "cancelled" });
});
expect(result.current.messages[0]).toMatchObject({ content: "follow-up", deliveryStatus: "accepted" });
expect(result.current.messages[0].processingStatus).toBeUndefined();
});
it("projects a user turn submitted from another attached client exactly once", () => {
const fake = fakeClient();
const { result } = renderHook(