From 9151058d79ad84ab39eef3bdb86087d799aa4d61 Mon Sep 17 00:00:00 2001 From: 134 Date: Tue, 23 Jun 2026 23:20:26 +0800 Subject: [PATCH] fix: keep background removal out of canvas deletion --- lib/canvas/agent-model-planner.ts | 5 +++++ tests/routes/canvas-chat-helpers.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/canvas/agent-model-planner.ts b/lib/canvas/agent-model-planner.ts index fa226c690..852f99911 100644 --- a/lib/canvas/agent-model-planner.ts +++ b/lib/canvas/agent-model-planner.ts @@ -140,6 +140,11 @@ function getDecisionNodeIds(params: { function inferHighRiskOperation(userText: string) { const text = userText.toLowerCase(); + if ( + /删除背景|删掉背景|去掉背景|去背景|移除背景|抠图|去背/.test(text) + ) { + return ""; + } if ( /删除|删掉|删了|删去|移除/.test(text) || /清空(?:画布|选中|当前|节点|对象|元素|这些|全部)/.test(text) || diff --git a/tests/routes/canvas-chat-helpers.test.ts b/tests/routes/canvas-chat-helpers.test.ts index 3d8380db0..38fbc9aff 100644 --- a/tests/routes/canvas-chat-helpers.test.ts +++ b/tests/routes/canvas-chat-helpers.test.ts @@ -696,6 +696,12 @@ test.describe("canvas chat pure helpers", () => { context: plannerContext, }) ).toBe(false); + expect( + shouldConsiderCanvasAgentModelPlanner({ + userText: "删除背景,结果放右边", + context: plannerContext, + }) + ).toBe(false); expect( shouldConsiderCanvasAgentModelPlanner({ userText: "新建一个视频槽位", @@ -1731,6 +1737,22 @@ test.describe("canvas chat pure helpers", () => { riskOperation: "delete_nodes", targetNodeIds: ["image-1", "text-1"], }); + + const removeBackgroundOutcome = normalizeCanvasAgentModelPlannerDecision({ + decision: { + action: "none", + }, + context: plannerContext, + projectId: plannerContext.projectId || "", + messageId: "message-1", + chatId: "chat-1", + userText: "删除背景,结果放右边", + }); + + expect(removeBackgroundOutcome).toEqual({ + kind: "none", + reason: undefined, + }); }); test("builds pending move-node operation from model-planned high-risk layout", () => {