fix: reduce canvas agent media duplicate window
This commit is contained in:
parent
50aa93d5f3
commit
38435f9401
@ -5175,6 +5175,12 @@ export function CanvasChatPanel({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hasHydratedHistoryRef.current) return;
|
if (!hasHydratedHistoryRef.current) return;
|
||||||
|
const activeStreamState = streamImageGenerationStateByChatId[activeChatId];
|
||||||
|
const shouldDeferAssistantMediaAutosync =
|
||||||
|
activeStreamState?.phase === "queued" ||
|
||||||
|
activeStreamState?.phase === "processing" ||
|
||||||
|
activeStreamState?.phase === "finalizing";
|
||||||
|
if (shouldDeferAssistantMediaAutosync) return;
|
||||||
|
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
@ -5515,6 +5521,7 @@ export function CanvasChatPanel({
|
|||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [
|
}, [
|
||||||
|
activeChatId,
|
||||||
messages,
|
messages,
|
||||||
addNode,
|
addNode,
|
||||||
nodes,
|
nodes,
|
||||||
@ -5522,6 +5529,7 @@ export function CanvasChatPanel({
|
|||||||
clearStreamImageGenerationStateForChat,
|
clearStreamImageGenerationStateForChat,
|
||||||
focusCanvasOnNode,
|
focusCanvasOnNode,
|
||||||
selectNodes,
|
selectNodes,
|
||||||
|
streamImageGenerationStateByChatId,
|
||||||
updateNode,
|
updateNode,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@ -115,15 +115,32 @@ function buildMediaNode(params: {
|
|||||||
}) {
|
}) {
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
const type = mediaNodeType(params.item);
|
const type = mediaNodeType(params.item);
|
||||||
|
const itemMetadata =
|
||||||
|
params.item.metadata &&
|
||||||
|
typeof params.item.metadata === "object" &&
|
||||||
|
!Array.isArray(params.item.metadata)
|
||||||
|
? params.item.metadata
|
||||||
|
: {};
|
||||||
|
const planMetadata =
|
||||||
|
params.plan.metadata &&
|
||||||
|
typeof params.plan.metadata === "object" &&
|
||||||
|
!Array.isArray(params.plan.metadata)
|
||||||
|
? params.plan.metadata
|
||||||
|
: {};
|
||||||
|
const sourceMessageId = String(
|
||||||
|
itemMetadata.messageId || planMetadata.messageId || ""
|
||||||
|
).trim();
|
||||||
const metadata = {
|
const metadata = {
|
||||||
...(params.plan.metadata || {}),
|
...planMetadata,
|
||||||
...(params.item.metadata || {}),
|
...itemMetadata,
|
||||||
generatedByAgent: true,
|
generatedByAgent: true,
|
||||||
canvasAgentOperationId: params.plan.operationId,
|
canvasAgentOperationId: params.plan.operationId,
|
||||||
canvasAgentOperation: params.plan.operation,
|
canvasAgentOperation: params.plan.operation,
|
||||||
canvasAgentMediaItemId: params.item.mediaItemId,
|
canvasAgentMediaItemId: params.item.mediaItemId,
|
||||||
canvasAgentPlacement: params.plan.placement,
|
canvasAgentPlacement: params.plan.placement,
|
||||||
canvasAgentPlacementStrategy: params.plan.placementStrategy,
|
canvasAgentPlacementStrategy: params.plan.placementStrategy,
|
||||||
|
sourceMessageId: sourceMessageId || undefined,
|
||||||
|
sourceImageKey: type === "image" && sourceMessageId ? params.item.url : undefined,
|
||||||
sourceNodeIds: params.sourceNodeIds,
|
sourceNodeIds: params.sourceNodeIds,
|
||||||
revisionOf:
|
revisionOf:
|
||||||
params.plan.operation === "append_revision"
|
params.plan.operation === "append_revision"
|
||||||
|
|||||||
@ -1095,6 +1095,9 @@ test.describe("canvas chat pure helpers", () => {
|
|||||||
url: "https://cdn.example.com/revision.png",
|
url: "https://cdn.example.com/revision.png",
|
||||||
title: "白底版本",
|
title: "白底版本",
|
||||||
prompt: "换成白底",
|
prompt: "换成白底",
|
||||||
|
metadata: {
|
||||||
|
messageId: "assistant-append-1",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -1118,6 +1121,8 @@ test.describe("canvas chat pure helpers", () => {
|
|||||||
canvasAgentOperationId: "op-append-1",
|
canvasAgentOperationId: "op-append-1",
|
||||||
canvasAgentMediaItemId: "media-append-1",
|
canvasAgentMediaItemId: "media-append-1",
|
||||||
revisionOf: "image-1",
|
revisionOf: "image-1",
|
||||||
|
sourceMessageId: "assistant-append-1",
|
||||||
|
sourceImageKey: "https://cdn.example.com/revision.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user