fix: open chat for annotation edits

This commit is contained in:
134 2026-06-23 17:34:35 +08:00
parent 5648ad12be
commit c033e75ba1
3 changed files with 40 additions and 5 deletions

View File

@ -3598,8 +3598,14 @@ export function CanvasChatPanel({
nodeId?: string; nodeId?: string;
label?: string; label?: string;
}; };
type PendingCanvasAgentAnnotationEditRequest = {
nodeId?: string;
title?: string;
annotationCount?: number;
};
const targetWindow = window as Window & { const targetWindow = window as Window & {
__canvasAgentPendingSlotFillRequest?: PendingCanvasAgentSlotFillRequest; __canvasAgentPendingSlotFillRequest?: PendingCanvasAgentSlotFillRequest;
__canvasAgentPendingAnnotationEditRequest?: PendingCanvasAgentAnnotationEditRequest;
}; };
const focusComposerWithPrompt = (prompt: string) => { const focusComposerWithPrompt = (prompt: string) => {
@ -3645,6 +3651,10 @@ export function CanvasChatPanel({
annotationCount?: number; annotationCount?: number;
}> }>
).detail; ).detail;
const pending = targetWindow.__canvasAgentPendingAnnotationEditRequest;
if (!pending?.nodeId || pending.nodeId === detail?.nodeId) {
delete targetWindow.__canvasAgentPendingAnnotationEditRequest;
}
const nodeId = String(detail?.nodeId || "").trim(); const nodeId = String(detail?.nodeId || "").trim();
if (nodeId) { if (nodeId) {
pendingCanvasAgentAnnotationEditTargetRef.current = { pendingCanvasAgentAnnotationEditTargetRef.current = {
@ -3679,6 +3689,15 @@ export function CanvasChatPanel({
}) })
); );
} }
const pendingAnnotationEditRequest =
targetWindow.__canvasAgentPendingAnnotationEditRequest;
if (pendingAnnotationEditRequest) {
handleAgentAnnotationEditRequest(
new CustomEvent("canvas-agent-annotation-edit-request", {
detail: pendingAnnotationEditRequest,
})
);
}
return () => { return () => {
window.removeEventListener( window.removeEventListener(
"canvas-agent-slot-fill-request", "canvas-agent-slot-fill-request",

View File

@ -6680,16 +6680,30 @@ export function ImageNode({
return; return;
} }
const detail = {
nodeId: node.id,
title: displayTitle,
annotationCount: canvasAgentAnnotations.length,
};
const targetWindow = window as Window & {
__canvasAgentPendingAnnotationEditRequest?: typeof detail;
};
selectNode(node.id, false); selectNode(node.id, false);
window.dispatchEvent( targetWindow.__canvasAgentPendingAnnotationEditRequest = detail;
new CustomEvent("canvas-agent-annotation-edit-request", { targetWindow.dispatchEvent(
new CustomEvent("canvas-open-chat-panel-request", {
detail: { detail: {
nodeId: node.id, reason: "agent-annotation-edit",
title: displayTitle, nodeId: detail.nodeId,
annotationCount: canvasAgentAnnotations.length,
}, },
}) })
); );
targetWindow.dispatchEvent(
new CustomEvent("canvas-agent-annotation-edit-request", {
detail,
})
);
}, [ }, [
canvasAgentAnnotations.length, canvasAgentAnnotations.length,
displayTitle, displayTitle,

View File

@ -1388,6 +1388,7 @@ metadata: {
2. 将 annotations 放入 `CanvasAgentContext`。 2. 将 annotations 放入 `CanvasAgentContext`。
3. 自动在输入框插入一句:“按这张图上的批注修改”。 3. 自动在输入框插入一句:“按这张图上的批注修改”。
4. 用户可直接发送,也可补充文字。 4. 用户可直接发送,也可补充文字。
5. 若右侧对话面板关闭或 lazy 未挂载,需要先展开对话框,并缓存一次 pending annotation edit request,确保 prompt 与目标图不丢。
### 10.3 Agent 规则 ### 10.3 Agent 规则
@ -1621,6 +1622,7 @@ lib/ai/runtime/middlewares/canvas-agent-clarification-gate.ts
- 图片节点 metadata 支持 annotations - 图片节点 metadata 支持 annotations
- 图片节点 UI 支持添加文本批注/框选批注 - 图片节点 UI 支持添加文本批注/框选批注
- `CanvasAgentContext` 输出 annotations - `CanvasAgentContext` 输出 annotations
- “按批注修改”会展开对话框并在面板未挂载时保留 pending request
- Agent prompt 加入标注编辑规则 - Agent prompt 加入标注编辑规则
- 编辑结果使用 `append_revision` - 编辑结果使用 `append_revision`