Files
moteva/frontend/tests/promptImageReferences.test.mjs
T
root 09b961fcc4 feat(canvas): attach uploaded image names to model prompts
Add modelImageReferences to preprocess agent contents, uploading local
image references and surfacing their names in the prompt so the model can
cite them. Wire the preparer into the canvas agent submission path, pass
imageName through the floating composer references, and relax the prompt
directive parser to accept names containing arbitrary characters.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-15 12:08:43 +08:00

40 lines
1.6 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { parsePromptImageReferences } from "../src/ui/lib/promptImageReferences.ts";
test("parses CAD-derived SVG reference directives with nested parentheses", () => {
const url = "http://localhost:19000/canvas-assets/drawing.svg";
const parts = parsePromptImageReferences(`Reference image (06-5070 R3 2026-05-05(1) (DXF).svg): ${url}\nMake it pink`);
assert.deepEqual(parts, [
{
type: "reference",
reference: {
id: parts[0]?.type === "reference" ? parts[0].reference.id : "",
index: undefined,
name: "06-5070 R3 2026-05-05(1) (DXF).svg",
url
}
},
{ type: "text", text: "\nMake it pink" }
]);
});
test("keeps Chinese CAD reference directives on the attachment path", () => {
const url = "https://assets.example.com/plan.svg";
const parts = parsePromptImageReferences(`参考图 1(花语江南 (DWG).svg):${url}\n继续设计`);
assert.equal(parts[0]?.type, "reference");
assert.equal(parts[0]?.type === "reference" ? parts[0].reference.index : undefined, 1);
assert.equal(parts[0]?.type === "reference" ? parts[0].reference.name : "", "花语江南 (DWG).svg");
assert.equal(parts[0]?.type === "reference" ? parts[0].reference.url : "", url);
});
test("continues to parse raster reference directives", () => {
const parts = parsePromptImageReferences("Reference image 2 (sample.webp): https://assets.example.com/sample.webp");
assert.equal(parts[0]?.type, "reference");
assert.equal(parts[0]?.type === "reference" ? parts[0].reference.name : "", "sample.webp");
});