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,7 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { canvasNodeToReferenceImage } from "../src/ui/pages/CanvasWorkspace/canvas/nodeReferenceImages.ts";
|
||||
import { canvasNodeToReferenceImage, lastCanvasNodeIdForReferences, withLastCanvasReferenceAnchor } from "../src/ui/pages/CanvasWorkspace/canvas/nodeReferenceImages.ts";
|
||||
|
||||
test("keeps the SVG source for model preparation and uses WebP for the visible capsule", () => {
|
||||
const reference = canvasNodeToReferenceImage({
|
||||
@@ -24,3 +24,29 @@ test("keeps the SVG source for model preparation and uses WebP for the visible c
|
||||
assert.equal(reference.previewUrl, "https://assets.example/drawing.render.webp");
|
||||
assert.equal(reference.semanticContext, "CAD context");
|
||||
});
|
||||
|
||||
test("anchors generation to the last canvas-backed image capsule", () => {
|
||||
const nodes = [
|
||||
{ id: "image-1", content: "/assets/one.webp" },
|
||||
{ id: "image-2", content: "/assets/two.webp" }
|
||||
];
|
||||
const references = [
|
||||
{ id: "canvas-node:image-1", publicUrl: "/assets/one.webp" },
|
||||
{ id: "upload-external", publicUrl: "/assets/external.webp" },
|
||||
{ id: "canvas-node:image-2", publicUrl: "/assets/two.webp" }
|
||||
];
|
||||
|
||||
assert.equal(lastCanvasNodeIdForReferences(references, nodes), "image-2");
|
||||
assert.equal(lastCanvasNodeIdForReferences(references.slice(0, 2), nodes), "image-1");
|
||||
assert.equal(lastCanvasNodeIdForReferences([{ id: "upload-two", publicUrl: "/assets/two.webp" }], nodes), "image-2");
|
||||
|
||||
const contents = withLastCanvasReferenceAnchor([{ type: "text", text: "generate", textSource: "input" }], references, nodes);
|
||||
assert.deepEqual(contents.at(-1), {
|
||||
type: "text",
|
||||
text: "Reference anchor node: image-2",
|
||||
textSource: "settings"
|
||||
});
|
||||
|
||||
const unanchoredContents = [{ type: "text", text: "generate", textSource: "input" }];
|
||||
assert.equal(withLastCanvasReferenceAnchor(unanchoredContents, [{ id: "upload-external", publicUrl: "/assets/external.webp" }], nodes), unanchoredContents);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user