diff --git a/lib/canvas/agent-annotation-prompt.ts b/lib/canvas/agent-annotation-prompt.ts index a98459472..f10ec02db 100644 --- a/lib/canvas/agent-annotation-prompt.ts +++ b/lib/canvas/agent-annotation-prompt.ts @@ -11,8 +11,20 @@ function uniqueStrings(values: Array) { } export function hasCanvasAgentAnnotationEditIntent(userText: string) { - return /按.*(?:批注|标注|箭头|框选|备注)|(?:批注|标注|箭头|框选|圈选|annotation|note)/i.test( - userText + const text = trimText(userText, 1000); + if (!text) return false; + const annotationKeyword = "(?:批注|标注|箭头|框选|圈选|备注|annotation|note)"; + if (new RegExp(`(?:添加|新增|创建|加|写).{0,8}${annotationKeyword}`, "i").test(text)) { + return false; + } + return ( + new RegExp(`(?:按|按照|根据|依据|依照|参考|基于).{0,18}${annotationKeyword}`, "i").test( + text + ) || + new RegExp( + `${annotationKeyword}.{0,24}(?:修改|编辑|修图|改图|处理|调整|去掉|移除|换|生成|出图|执行)`, + "i" + ).test(text) ); } diff --git a/tests/routes/canvas-chat-helpers.test.ts b/tests/routes/canvas-chat-helpers.test.ts index da3030343..5bf78b524 100644 --- a/tests/routes/canvas-chat-helpers.test.ts +++ b/tests/routes/canvas-chat-helpers.test.ts @@ -3050,7 +3050,11 @@ test.describe("canvas chat pure helpers", () => { }; expect(hasCanvasAgentAnnotationEditIntent("按批注修改这张图")).toBe(true); + expect(hasCanvasAgentAnnotationEditIntent("批注里的水印去掉")).toBe(true); expect(hasCanvasAgentAnnotationEditIntent("把背景换成白色")).toBe(false); + expect(hasCanvasAgentAnnotationEditIntent("给选中图片加批注:这里保留")).toBe( + false + ); const prompt = buildCanvasAgentAnnotationEditPrompt({ context, @@ -3069,6 +3073,13 @@ test.describe("canvas chat pure helpers", () => { userText: "把背景换成白色", }) ).toBe(""); + expect( + buildCanvasAgentAnnotationEditPrompt({ + context, + targetNodeIds: ["image-1"], + userText: "给选中图片加批注:这里保留", + }) + ).toBe(""); }); test("labels image note action as an agent annotation entry", () => {