feat(canvas): send the last referenced canvas node as a generation anchor
Resolve the most recent canvas-node reference from the prompt's reference images (by node id or matching asset URL) and append it as a hidden "reference anchor node:" settings directive on agent submissions, so the server can place generated images beside the source. Keep the persisted user-visible copy unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { CanvasNode } from "@/domain/design";
|
||||
import type { AgentContent, CanvasNode } from "@/domain/design";
|
||||
import type { UploadedReferenceImage } from "@/ui/components/PromptComposer";
|
||||
|
||||
const canvasNodeReferencePrefix = "canvas-node:";
|
||||
@@ -21,6 +21,31 @@ export function isCanvasNodeReferenceImage(reference: UploadedReferenceImage) {
|
||||
return reference.id.startsWith(canvasNodeReferencePrefix);
|
||||
}
|
||||
|
||||
export function lastCanvasNodeIdForReferences(references: Array<Pick<UploadedReferenceImage, "id" | "publicUrl">>, nodes: Array<Pick<CanvasNode, "id" | "content">>) {
|
||||
for (let index = references.length - 1; index >= 0; index -= 1) {
|
||||
const reference = references[index];
|
||||
const directNodeId = reference.id.startsWith(canvasNodeReferencePrefix) ? reference.id.slice(canvasNodeReferencePrefix.length) : "";
|
||||
if (directNodeId && nodes.some((node) => node.id === directNodeId)) return directNodeId;
|
||||
const referenceKeys = assetReferenceKeys(reference.publicUrl);
|
||||
const matchedNode = [...nodes].reverse().find((node) => Array.from(assetReferenceKeys(node.content)).some((key) => referenceKeys.has(key)));
|
||||
if (matchedNode) return matchedNode.id;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export function withLastCanvasReferenceAnchor(contents: AgentContent[], references: Array<Pick<UploadedReferenceImage, "id" | "publicUrl">>, nodes: Array<Pick<CanvasNode, "id" | "content">>): AgentContent[] {
|
||||
const anchorNodeId = lastCanvasNodeIdForReferences(references, nodes);
|
||||
if (!anchorNodeId) return contents;
|
||||
return [
|
||||
...contents,
|
||||
{
|
||||
type: "text",
|
||||
text: `Reference anchor node: ${anchorNodeId}`,
|
||||
textSource: "settings"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
export function isAssetReferencedByCanvas(publicUrl: string, nodes: CanvasNode[]) {
|
||||
const targetKeys = assetReferenceKeys(publicUrl);
|
||||
if (targetKeys.size === 0) return false;
|
||||
|
||||
Reference in New Issue
Block a user