fix: route clear canvas requests through confirmation

This commit is contained in:
134 2026-06-23 15:25:02 +08:00
parent 0bb134d3b8
commit 50aa93d5f3
2 changed files with 30 additions and 1 deletions

View File

@ -136,7 +136,13 @@ function getDecisionNodeIds(params: {
function inferHighRiskOperation(userText: string) {
const text = userText.toLowerCase();
if (/删除|删掉|移除/.test(text)) return "delete_nodes";
if (
/删除|删掉|删了|删去|移除/.test(text) ||
/清空(?:画布|选中|当前|节点|对象|元素|这些|全部)/.test(text) ||
/清除(?:选中|当前|节点|对象|元素|这些|全部)/.test(text)
) {
return "delete_nodes";
}
if (/覆盖|替换当前|替换原图|直接替换|覆盖原图/.test(text)) {
return "replace_node_media";
}

View File

@ -266,6 +266,12 @@ test.describe("canvas chat pure helpers", () => {
context: plannerContext,
})
).toBe(true);
expect(
shouldConsiderCanvasAgentModelPlanner({
userText: "清空选中的节点",
context: plannerContext,
})
).toBe(true);
});
test("treats selected agent slots as canvas routing context", () => {
@ -656,6 +662,23 @@ test.describe("canvas chat pure helpers", () => {
riskOperation: "delete_nodes",
targetNodeIds: ["image-1", "text-1"],
});
const clearOutcome = normalizeCanvasAgentModelPlannerDecision({
decision: {
action: "none",
},
context: plannerContext,
projectId: plannerContext.projectId || "",
messageId: "message-1",
chatId: "chat-1",
userText: "清除选中的对象",
});
expect(clearOutcome).toMatchObject({
kind: "confirmation_required",
riskOperation: "delete_nodes",
targetNodeIds: ["image-1", "text-1"],
});
});
test("builds pending move-node operation from model-planned high-risk layout", () => {