fix: open chat when filling agent slots
This commit is contained in:
parent
1d7c4816b0
commit
5648ad12be
@ -3373,6 +3373,26 @@ export default function CanvasEditorLegacyPage({ params }: PageProps) {
|
|||||||
}
|
}
|
||||||
}, [isAgentMode]);
|
}, [isAgentMode]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isVideoMode || typeof window === "undefined") return;
|
||||||
|
|
||||||
|
const handleCanvasChatPanelOpenRequest = () => {
|
||||||
|
setPanelMode("chat");
|
||||||
|
setIsPanelOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener(
|
||||||
|
"canvas-open-chat-panel-request",
|
||||||
|
handleCanvasChatPanelOpenRequest
|
||||||
|
);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener(
|
||||||
|
"canvas-open-chat-panel-request",
|
||||||
|
handleCanvasChatPanelOpenRequest
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}, [isVideoMode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (shouldOpenBatchProcessing && isBatchProcessingEnabled) {
|
if (shouldOpenBatchProcessing && isBatchProcessingEnabled) {
|
||||||
router.replace(`/canvas/${id}/batch`);
|
router.replace(`/canvas/${id}/batch`);
|
||||||
|
|||||||
@ -3594,6 +3594,13 @@ export function CanvasChatPanel({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!effectiveAgentEnabled || typeof window === "undefined") return;
|
if (!effectiveAgentEnabled || typeof window === "undefined") return;
|
||||||
|
type PendingCanvasAgentSlotFillRequest = {
|
||||||
|
nodeId?: string;
|
||||||
|
label?: string;
|
||||||
|
};
|
||||||
|
const targetWindow = window as Window & {
|
||||||
|
__canvasAgentPendingSlotFillRequest?: PendingCanvasAgentSlotFillRequest;
|
||||||
|
};
|
||||||
|
|
||||||
const focusComposerWithPrompt = (prompt: string) => {
|
const focusComposerWithPrompt = (prompt: string) => {
|
||||||
handleSelectGenerationMode("agent");
|
handleSelectGenerationMode("agent");
|
||||||
@ -3618,6 +3625,10 @@ export function CanvasChatPanel({
|
|||||||
|
|
||||||
const handleAgentSlotFillRequest = (event: Event) => {
|
const handleAgentSlotFillRequest = (event: Event) => {
|
||||||
const detail = (event as CustomEvent<{ nodeId?: string; label?: string }>).detail;
|
const detail = (event as CustomEvent<{ nodeId?: string; label?: string }>).detail;
|
||||||
|
const pending = targetWindow.__canvasAgentPendingSlotFillRequest;
|
||||||
|
if (!pending?.nodeId || pending.nodeId === detail?.nodeId) {
|
||||||
|
delete targetWindow.__canvasAgentPendingSlotFillRequest;
|
||||||
|
}
|
||||||
const label = String(detail?.label || "这个槽位").trim();
|
const label = String(detail?.label || "这个槽位").trim();
|
||||||
const prompt = `在${label === "这个槽位" ? label : `「${label}」`}生成一张图`;
|
const prompt = `在${label === "这个槽位" ? label : `「${label}」`}生成一张图`;
|
||||||
|
|
||||||
@ -3660,6 +3671,14 @@ export function CanvasChatPanel({
|
|||||||
"canvas-agent-annotation-edit-request",
|
"canvas-agent-annotation-edit-request",
|
||||||
handleAgentAnnotationEditRequest
|
handleAgentAnnotationEditRequest
|
||||||
);
|
);
|
||||||
|
const pendingSlotFillRequest = targetWindow.__canvasAgentPendingSlotFillRequest;
|
||||||
|
if (pendingSlotFillRequest) {
|
||||||
|
handleAgentSlotFillRequest(
|
||||||
|
new CustomEvent("canvas-agent-slot-fill-request", {
|
||||||
|
detail: pendingSlotFillRequest,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener(
|
window.removeEventListener(
|
||||||
"canvas-agent-slot-fill-request",
|
"canvas-agent-slot-fill-request",
|
||||||
|
|||||||
@ -687,15 +687,28 @@ export function CanvasWorkspace({
|
|||||||
|
|
||||||
const requestFillAgentSlotFromContextMenu = useCallback(() => {
|
const requestFillAgentSlotFromContextMenu = useCallback(() => {
|
||||||
if (!agentSlotContextMenu || typeof window === "undefined") return;
|
if (!agentSlotContextMenu || typeof window === "undefined") return;
|
||||||
|
const detail = {
|
||||||
|
nodeId: agentSlotContextMenu.nodeId,
|
||||||
|
label: agentSlotContextMenu.label,
|
||||||
|
};
|
||||||
|
const targetWindow = window as Window & {
|
||||||
|
__canvasAgentPendingSlotFillRequest?: typeof detail;
|
||||||
|
};
|
||||||
selectNode(agentSlotContextMenu.nodeId, false);
|
selectNode(agentSlotContextMenu.nodeId, false);
|
||||||
window.dispatchEvent(
|
targetWindow.__canvasAgentPendingSlotFillRequest = detail;
|
||||||
new CustomEvent("canvas-agent-slot-fill-request", {
|
targetWindow.dispatchEvent(
|
||||||
|
new CustomEvent("canvas-open-chat-panel-request", {
|
||||||
detail: {
|
detail: {
|
||||||
nodeId: agentSlotContextMenu.nodeId,
|
reason: "agent-slot-fill",
|
||||||
label: agentSlotContextMenu.label,
|
nodeId: detail.nodeId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
targetWindow.dispatchEvent(
|
||||||
|
new CustomEvent("canvas-agent-slot-fill-request", {
|
||||||
|
detail,
|
||||||
|
})
|
||||||
|
);
|
||||||
setAgentSlotContextMenu(null);
|
setAgentSlotContextMenu(null);
|
||||||
}, [agentSlotContextMenu, selectNode]);
|
}, [agentSlotContextMenu, selectNode]);
|
||||||
|
|
||||||
|
|||||||
@ -931,6 +931,7 @@ components/canvas/nodes/AgentSlotNode.tsx
|
|||||||
- “设为图片槽”
|
- “设为图片槽”
|
||||||
- “设为视频槽”
|
- “设为视频槽”
|
||||||
- “允许替换 / 保留版本”
|
- “允许替换 / 保留版本”
|
||||||
|
- “填充此槽位”必须同时打开/切回右侧对话面板;若对话面板 lazy 未挂载,需要缓存一次 pending slot fill request,挂载后自动预填槽位生成 prompt。
|
||||||
|
|
||||||
### 7.4 工具栏新增 slot 工具
|
### 7.4 工具栏新增 slot 工具
|
||||||
|
|
||||||
@ -1524,6 +1525,7 @@ lib/ai/runtime/middlewares/canvas-agent-clarification-gate.ts
|
|||||||
- 新增 `AgentSlotNode.tsx`
|
- 新增 `AgentSlotNode.tsx`
|
||||||
- 工具栏增加图片 slot
|
- 工具栏增加图片 slot
|
||||||
- 右键菜单支持“填充此槽位”
|
- 右键菜单支持“填充此槽位”
|
||||||
|
- 槽位右键填充会展开对话框并在面板未挂载时保留 pending request
|
||||||
- `buildCanvasAgentContext()` 输出 slots
|
- `buildCanvasAgentContext()` 输出 slots
|
||||||
|
|
||||||
验收:
|
验收:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user