fix(canvas): Agent 面板 - 读清单与看画面分档、操作行折叠动效与时间线标识清理
(cherry picked from commit 6c0cadcf9d0dad48a065598ff57b4bde1e135fcd)
This commit is contained in:
1 parent
0d6f2291f6
commit
a1dc9b2686
10 files changed
+477
-81
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { agentOperationFailed, agentOperationLabel, buildAgentFeedSegments, isAgentCarrierRecord, isAgentOperationRecord } from "@/lib/canvas/agent-operation-feed";
|
||||
import { agentOperationCategory, agentOperationFailed, agentOperationLabel, agentOperationSegmentLabel, buildAgentFeedSegments, isAgentCarrierRecord, isAgentOperationRecord } from "@/lib/canvas/agent-operation-feed";
|
||||
|
||||
type Row = { id: string; role: string; title?: string; text: string; detail?: unknown; planItems?: { id: string }[]; question?: unknown };
|
||||
|
||||
@@ -49,11 +49,11 @@ describe("Agent operation feed", () => {
|
||||
});
|
||||
|
||||
it("reports the latest step, including an in-flight and a failed one", () => {
|
||||
expect(agentOperationLabel(step("t1", "canvas_get_state", "已读取当前画布"))).toBe("已读取当前画布");
|
||||
expect(agentOperationLabel(step("t1", "canvas_get_state", "工具执行成功"))).toBe("已读取画布清单(未查看画面)");
|
||||
expect(agentOperationLabel(step("t2", "canvas_apply_ops", "", {}))).toBe("准备更新画布内容");
|
||||
expect(agentOperationLabel(step("t3", "canvas_apply_ops", "", { eventType: "tool_failed" }))).toBe("更新画布内容失败");
|
||||
expect(agentOperationFailed(step("t3", "canvas_apply_ops", "", { eventType: "tool_failed" }))).toBe(true);
|
||||
expect(agentOperationFailed(step("t1", "canvas_get_state", "已读取当前画布"))).toBe(false);
|
||||
expect(agentOperationFailed(step("t1", "canvas_get_state", "工具执行成功"))).toBe(false);
|
||||
});
|
||||
|
||||
it("reports the retry group instead of a stale completion", () => {
|
||||
@@ -63,3 +63,46 @@ describe("Agent operation feed", () => {
|
||||
expect(agentOperationLabel(recovered)).toBe("自动纠正后已恢复 · 2/3 次尝试");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Agent operation segment label", () => {
|
||||
const viewed = (id: string, title: string, extra: Record<string, unknown> = {}) => step(id, "canvas_inspect_image", "工具执行成功", { eventType: "tool_completed", result: { nodeId: id, title, ...extra } });
|
||||
|
||||
it("aggregates a vision run by the images that really went out", () => {
|
||||
const items = [viewed("n1", "剧照1.png"), viewed("n2", "剧照2.png"), viewed("n3", "封面.png")];
|
||||
expect(agentOperationSegmentLabel(items)).toBe("查看了 3 张画面 · 最新《封面.png》");
|
||||
expect(agentOperationCategory(items[0])).toBe("vision");
|
||||
});
|
||||
|
||||
it("counts a batch receipt once per image instead of once per call", () => {
|
||||
const items = [
|
||||
viewed("n1", "剧照1.png"),
|
||||
step("last", "canvas_inspect_image", "工具执行成功", {
|
||||
eventType: "tool_completed",
|
||||
result: {
|
||||
nodeId: "n3",
|
||||
title: "剧照3.png",
|
||||
batchImages: [
|
||||
{ nodeId: "n1", title: "剧照1.png" },
|
||||
{ nodeId: "n2", title: "剧照2.png" },
|
||||
{ nodeId: "n3", title: "剧照3.png" },
|
||||
],
|
||||
},
|
||||
}),
|
||||
];
|
||||
expect(agentOperationSegmentLabel(items)).toBe("查看了 3 张画面 · 最新《剧照3.png》");
|
||||
});
|
||||
|
||||
it("does not count a reused observation or a read-loop receipt as a delivered picture", () => {
|
||||
const items = [viewed("n1", "剧照1.png", { repeat: true, reuseObservation: true }), viewed("n2", "剧照2.png", { repeat: true, refreshIgnored: true })];
|
||||
// 一张画面都没送出去:退回最新一步自己的摘要,绝不报"查看了 N 张画面"
|
||||
expect(agentOperationSegmentLabel(items)).toBe("本轮重复查看,只回执文字、未附图");
|
||||
expect(agentOperationSegmentLabel(items)).not.toContain("查看了");
|
||||
});
|
||||
|
||||
it("keeps the newest step's own copy when the segment is not about pictures", () => {
|
||||
const items = [step("t1", "canvas_get_state", "工具执行成功"), step("t2", "canvas_apply_ops", "工具执行成功", { eventType: "canvas_updated" })];
|
||||
expect(agentOperationSegmentLabel(items)).toBe("画布内容已保存至服务端");
|
||||
expect(agentOperationCategory(items[1])).toBe("operate");
|
||||
expect(agentOperationSegmentLabel([])).toBe("");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user