CanvasAnvil is an open source AI diagram maker and flowchart generator - an infinite-canvas diagram editor and self-hosted drawio alternative that writes editable .drawio files. Text to diagram, then fix nodes, layout and labels in place. Also AI presentations, interior design CAD/BOM, posters and infographics.
TypeScript ai-agentsai-diagramai-presentationbomcadcanvasdiagramdiagram-generatordrawioflowchartinfographicspptppt-generatorpresentation-generatorreactsvgedittext-to-diagramtypescriptworkflow
fix(ppt): carry chat-panel images into every slide generation path
codingFeng101d5aaedcfde8b
diff --git a/client/workspaces/ppt/canvas/PptCanvas.tsx b/client/workspaces/ppt/canvas/PptCanvas.tsxindex 92bba51..e5dbce3 100644--- a/client/workspaces/ppt/canvas/PptCanvas.tsx+++ b/client/workspaces/ppt/canvas/PptCanvas.tsx@@ -16,6 +16,8 @@ import {} from "./lib/slide-versions";import {buildSlideMaterialsFromAutoLabels,+ uploadedImageLabel,+ type MaterialLang,} from "./lib/material-tokens";import {creationReducer,@@ -43,6 +45,7 @@ import {BEAUTIFY_RETRY_BASE_DELAY_MS,BEAUTIFY_RETRY_MAX_ATTEMPTS,MODEL_CONCURRENCY,+ UPLOADED_IMAGE_LIMIT,} from "@/workspaces/ppt/canvas/lib/constants";import {deriveTextElementsFromBlocks,@@ -649,8 +652,28 @@ export function PptCanvas({if (incomingSlidesRaw.length === 0) return;const uploadedImages: string[] = Array.isArray(parsed?.uploadedImages)- ? Array.from(new Set((parsed.uploadedImages as any[]).map((x: any) => String(x || "").trim()).filter(Boolean))).slice(0, 2)+ ? Array.from(+ new Set((parsed.uploadedImages as any[]).map((x: any) => String(x || "").trim()).filter(Boolean)),+ ).slice(0, UPLOADED_IMAGE_LIMIT): [];+ /**+ * The chat panel's pictures, named so the prompt can place them.+ *+ * They used to reach only the "edit the existing image" path, which is the+ * one branch that does not redraw the slide -- so a user who attached a+ * picture and asked for it to appear got the redraw branch instead, and+ * the picture went nowhere.+ */+ const uploadedImageRefs = uploadedImages.map((url, i) => ({+ url,+ label: uploadedImageLabel(i + 1, uiLang as MaterialLang),+ }));+ const uploadedImageInstruction = uploadedImageRefs.length > 0+ ? tr(+ `用户在对话中上传了这些参考图:${uploadedImageRefs.map((x) => x.label).join("、")}。请把它们放进画面并保持原貌,不要重画、改色或替换。`,+ `The user attached these reference images in chat: ${uploadedImageRefs.map((x) => x.label).join(", ")}. Place them in the slide as they are; do not redraw, recolour or replace them.`,+ )+ : "";const existingById = new Map(localSlides.map((s) => [s.id, s] as const));const getCurrentSlideImageUrlById = (slideId: string) => {const versions = imageVersions[slideId] || [];@@ -832,8 +855,9 @@ export function PptCanvas({[...styleRefRefs.map((x) => ({ url: x.url, label: x.label })),...materials.getImageRefs(id, page.description || ""),+ ...uploadedImageRefs,],- [instruction.trim(), styleReferenceInstruction].filter(Boolean).join("\n")+ [instruction.trim(), styleReferenceInstruction, uploadedImageInstruction].filter(Boolean).join("\n"));if (rendered) {await pushImageVersionAndProcess(slide, rendered, "generated", instruction.trim() || undefined);@@ -855,8 +879,9 @@ export function PptCanvas({[...styleRefRefs.map((x) => ({ url: x.url, label: x.label })),...materials.getImageRefs(id, page.description || ""),+ ...uploadedImageRefs,],- [instruction.trim(), styleReferenceInstruction].filter(Boolean).join("\n")+ [instruction.trim(), styleReferenceInstruction, uploadedImageInstruction].filter(Boolean).join("\n"));if (rendered) {await pushImageVersionAndProcess(slide, rendered, "generated", instruction.trim() || undefined);@@ -865,7 +890,7 @@ export function PptCanvas({}const editedUrl = await pptService.editPageImage(page,- [instruction.trim(), styleReferenceInstruction].filter(Boolean).join("\n"),+ [instruction.trim(), styleReferenceInstruction, uploadedImageInstruction].filter(Boolean).join("\n"),currentUrl || undefined,templateImage || undefined,Array.from(new Set([@@ -988,6 +1013,7 @@ export function PptCanvas({[...styleRefRefs.map((x) => ({ url: x.url, label: x.label })),...materials.getImageRefs(id, page.description || ""),+ ...uploadedImageRefs,],[kind === "both" && instruction.trim() ? instruction : "",@@ -1004,6 +1030,7 @@ export function PptCanvas({)): "",+ uploadedImageInstruction,].filter(Boolean).join("\n"));if (rendered) {@@ -1043,6 +1070,7 @@ export function PptCanvas({)): "",+ uploadedImageInstruction,].filter(Boolean).join("\n"),currentUrl || undefined,templateImage || undefined,diff --git a/client/workspaces/ppt/canvas/lib/constants.ts b/client/workspaces/ppt/canvas/lib/constants.tsindex c056959..b8fe10a 100644--- a/client/workspaces/ppt/canvas/lib/constants.ts+++ b/client/workspaces/ppt/canvas/lib/constants.ts@@ -25,6 +25,13 @@ export const PRESET_TEMPLATES: PresetTemplate[] = [export const MODEL_CONCURRENCY = 5;export const BEAUTIFY_CONCURRENCY = 5;export const EDITABLE_EXPORT_CONCURRENCY = 3;+/**+ * Pictures one chat message may carry into slide generation.+ *+ * Kept below the generation ceiling so a slide's own materials and the deck+ * template still fit alongside them.+ */+export const UPLOADED_IMAGE_LIMIT = 3;export const EDITABLE_REVIEW_CONCURRENCY = 4;export const BEAUTIFY_RETRY_MAX_ATTEMPTS = 3;export const BEAUTIFY_RETRY_BASE_DELAY_MS = 1200;diff --git a/client/workspaces/ppt/canvas/lib/material-tokens.ts b/client/workspaces/ppt/canvas/lib/material-tokens.tsindex d577827..e63e9a3 100644--- a/client/workspaces/ppt/canvas/lib/material-tokens.ts+++ b/client/workspaces/ppt/canvas/lib/material-tokens.ts@@ -21,6 +21,17 @@ export function materialLabel(index: number, lang: MaterialLang): string {return lang === "zh" ? `第${index}张` : `Image ${index}`;}+/**+ * The name a picture uploaded in the chat panel goes by.+ *+ * Deliberately different from a slide material's label: both kinds can ride+ * along with one slide, and a model told about "Image 1" twice has no way to+ * tell which picture the instruction is about.+ */+export function uploadedImageLabel(index: number, lang: MaterialLang): string {+ return lang === "zh" ? `对话图${index}` : `Chat image ${index}`;+}+export function materialToken(name: string): string {return `{{image:${name}}}`;}diff --git a/tests/ppt-material-references.test.ts b/tests/ppt-material-references.test.tsindex 24563ef..96d146d 100644--- a/tests/ppt-material-references.test.ts+++ b/tests/ppt-material-references.test.ts@@ -1,8 +1,10 @@import assert from "node:assert/strict";import { test } from "node:test";import {+ materialLabel,materialToken,referencedMaterials,+ uploadedImageLabel,} from "../client/workspaces/ppt/canvas/lib/material-tokens";/**@@ -54,3 +56,33 @@ test("a name that only appears as bare text is not a reference", () => {test("no attachments means nothing to send", () => {assert.deepEqual(referencedMaterials(`看 ${materialToken("第1张")}`, []), []);});++/**+ * Pictures attached in the chat panel are named separately from a slide's own+ * materials, because both can ride along with one slide and the prompt has to+ * be able to say which is which.+ */++test("chat pictures and slide materials never share a name", () => {+ const slideNames = [1, 2, 3].map((n) => materialLabel(n, "zh"));+ const chatNames = [1, 2, 3].map((n) => uploadedImageLabel(n, "zh"));+ assert.equal(new Set([...slideNames, ...chatNames]).size, 6);++ const slideEn = [1, 2, 3].map((n) => materialLabel(n, "en"));+ const chatEn = [1, 2, 3].map((n) => uploadedImageLabel(n, "en"));+ assert.equal(new Set([...slideEn, ...chatEn]).size, 6);+});++test("a chat picture's name is stable and numbered from one", () => {+ assert.equal(uploadedImageLabel(1, "zh"), "对话图1");+ assert.equal(uploadedImageLabel(2, "en"), "Chat image 2");+});++test("a chat picture's name is not mistaken for a description reference", () => {+ // The token syntax belongs to slide materials; a chat picture is passed by+ // label alone, so naming one in a description must not pull it in here.+ const picked = referencedMaterials(`看 ${materialToken(uploadedImageLabel(1, "zh"))}`, [+ { name: materialLabel(1, "zh") },+ ]);+ assert.deepEqual(picked, []);+});