AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(infographic): preserve custom note titles across conversation turns
tianma-ifb39519fb1088
diff --git a/apps/api/src/infographic-agent.ts b/apps/api/src/infographic-agent.tsindex 86d51ec5..c3b988c4 100644--- a/apps/api/src/infographic-agent.ts+++ b/apps/api/src/infographic-agent.ts@@ -17,7 +17,7 @@ export const runInfographicAgent = async (args: {const timelineRequested = infographicRequestsTimeline(input.prompt);const agent = new ToolLoopAgent({model: args.model,- instructions: `You edit one AntV infographic through a conversation. The current infographic content is the source of truth; previous assistant replies may describe changes that were not applied. Understand the user's meaning and previous turns. Keep the current template for content-only changes, including replacing one comparison subject. Change the template when the data relationship changes, even if the user does not name a diagram type. A request for one company's development history needs chronological events in a sequence-timeline template, not the old two-company comparison. Choose only from the allowed template IDs. Prefer a comparison template with a VS divider for two subjects and matched aspects. Preserve information the user did not ask to change. Ask a short clarification only if you cannot make a useful edit. Call one accepted tool before your final concise response, in the user's language. Do not output JSON in your final response.\nCurrent template: ${input.currentTemplate ?? "none"}.\nCurrent infographic content: ${input.currentContent || "none"}.\nAllowed templates: ${input.candidates.join(", ")}.\nData shapes: chart={title,values:[{label,value:number}]}; comparison={title,compares:[{label,children:[{label,desc}]}]}; quadrant={title,compares:[four items]}; hierarchy={title,root:{label,children:[...]}}; relation={title,nodes:[{id,label}],relations:[{from,to}]}; sequence={title,sequences:[{label,desc}]}; list={title,lists:[{label,desc}]}. Binary comparisons need exactly two compares with matching children. Use concise labels and complete content.`,+ instructions: `You edit one AntV infographic through a conversation. The current infographic content is the source of truth; previous assistant replies may describe changes that were not applied. Understand the user's meaning and previous turns. Keep the current template for content-only changes, including replacing one comparison subject. Change the template when the data relationship changes, even if the user does not name a diagram type. A request for one company's development history needs chronological events in a sequence-timeline template, not the old two-company comparison. Choose only from the allowed template IDs. Prefer a comparison template with a VS divider for two subjects and matched aspects. Preserve information the user did not ask to change. data.title is the note title: change it when the subject changes, and keep it when the user only edits details. Ask a short clarification only if you cannot make a useful edit. Call one accepted tool before your final concise response, in the user's language. Do not output JSON in your final response.\nCurrent template: ${input.currentTemplate ?? "none"}.\nCurrent infographic content: ${input.currentContent || "none"}.\nAllowed templates: ${input.candidates.join(", ")}.\nData shapes: chart={title,values:[{label,value:number}]}; comparison={title,compares:[{label,children:[{label,desc}]}]}; quadrant={title,compares:[four items]}; hierarchy={title,root:{label,children:[...]}}; relation={title,nodes:[{id,label}],relations:[{from,to}]}; sequence={title,sequences:[{label,desc}]}; list={title,lists:[{label,desc}]}. Binary comparisons need exactly two compares with matching children. Use concise labels and complete content.`,tools: {propose_infographic: tool({description: "Propose a complete, editable infographic version. Choose an allowed template and its matching data shape.",diff --git a/apps/web/src/components/InfographicEditorPane.test.mjs b/apps/web/src/components/InfographicEditorPane.test.mjsindex 736df3d4..392fe508 100644--- a/apps/web/src/components/InfographicEditorPane.test.mjs+++ b/apps/web/src/components/InfographicEditorPane.test.mjs@@ -35,6 +35,7 @@ describe("infographic editor header", () => {expect(source).toContain("data-ai-assistant-launcher");expect(source).toContain("<AiSidebar");expect(source).toContain("infographic={infographicAssistant}");+ expect(source).toContain("nextInfographicNoteTitle");expect(source).toContain("edgeever-infographic-preview");});});diff --git a/apps/web/src/components/InfographicEditorPane.tsx b/apps/web/src/components/InfographicEditorPane.tsxindex a399a9a3..2e041c66 100644--- a/apps/web/src/components/InfographicEditorPane.tsx+++ b/apps/web/src/components/InfographicEditorPane.tsx@@ -25,7 +25,7 @@ import { buildInfographicLocalAgentContext, collectInfographicLocalAgentText, inimport { formatShortcutBinding, getNotebookMoveOptions, type ShortcutSettings } from "@/lib/app-helpers";import { createLocalEditSession, requiresLocalEditSession } from "@/components/editor/editor-pane-helpers";import { canvasToPngBlob, downloadBlob, frameInfographicExportSvg, infographicExportBasename, rasterizeInfographicSvg, readInfographicSheetColor } from "@/lib/infographic-image-export";-import { buildInfographicSyntax, buildOfficialInfographicSyntax, infographicAgentCandidates, INFOGRAPHIC_TEMPLATES, parseGeneratedOfficialData, type InfographicItem } from "@/lib/infographic-generation";+import { buildInfographicSyntax, buildOfficialInfographicSyntax, infographicAgentCandidates, infographicNoteTitleIsAutomatic, infographicSyntaxTitle, INFOGRAPHIC_TEMPLATES, nextInfographicNoteTitle, parseGeneratedOfficialData, type InfographicItem } from "@/lib/infographic-generation";import { statusSettleMotion } from "@/lib/motion";import type { EdgeEverRepository } from "@/lib/repository";import { cn, parseTagsText } from "@/lib/utils";@@ -202,6 +202,12 @@ export default function InfographicEditorPane({const parsed = useMemo(() => parseInfographicDocument(memo.contentMarkdown), [memo.contentMarkdown]);const initialTags = memo.tags.join(", ");const [title, setTitle] = useState(memo.title ?? "");+ const titleEditedByUserRef = useRef(!infographicNoteTitleIsAutomatic({+ noteTitle: memo.title ?? "",+ graphicTitle: infographicSyntaxTitle(parsed?.syntax ?? ""),+ defaultTitle: t("infographic.name"),+ earlierTitles: (parsed?.history ?? []).map((turn) => turn.resultTitle),+ }));const [tagsText, setTagsText] = useState(initialTags);const [syntax, setSyntax] = useState(parsed?.syntax ?? "");const [history, setHistory] = useState<InfographicConversationTurn[]>(parsed?.history ?? []);@@ -558,6 +564,14 @@ export default function InfographicEditorPane({if (parsedCandidate.errors.length || !parsedCandidate.options.template || !getTemplate(parsedCandidate.options.template)) throw new Error(t("infographic.aiInvalidResponse"));const generatedTitle = String(data.title ?? "");const turnId = crypto.randomUUID();+ const previousGraphicTitle = String(existingOptions.data?.title ?? "");+ const nextTitle = nextInfographicNoteTitle({+ noteTitle: title,+ previousGraphicTitle,+ nextGraphicTitle: generatedTitle,+ defaultTitle: t("infographic.name"),+ keepCustomTitle: titleEditedByUserRef.current,+ });setPreviousGeneration({ title, syntax, turnId });setHistory((turns) => [...turns, {id: turnId, prompt: promptText, createdAt: new Date().toISOString(),@@ -565,8 +579,7 @@ export default function InfographicEditorPane({response: (response.trim() || selected.explanation).slice(0, 4000), decision: selected.explanation.slice(0, 500), template: selected.template,}]);setSyntax(candidate);- const previousGraphicTitle = String(existingOptions.data?.title ?? "").trim();- if (!title.trim() || title.trim() === t("infographic.name") || (previousGraphicTitle && title.trim() === previousGraphicTitle)) setTitle(generatedTitle);+ if (nextTitle !== title) setTitle(nextTitle);} else if (question) {setHistory((turns) => [...turns, { id: crypto.randomUUID(), prompt: promptText, createdAt: new Date().toISOString(), kind: "clarified", resultTitle: "", response: (response.trim() || question).slice(0, 4000) }]);} else throw new Error(t("infographic.aiInvalidResponse"));@@ -627,7 +640,7 @@ export default function InfographicEditorPane({</IconTooltip>)}titleInput={(- <MemoTitleInput className="w-full min-w-0 px-2" value={title} onValueChange={setTitle} placeholder={t("infographic.name")} readOnly={readOnly} />+ <MemoTitleInput className="w-full min-w-0 px-2" value={title} onValueChange={(value) => { titleEditedByUserRef.current = true; setTitle(value); }} placeholder={t("infographic.name")} readOnly={readOnly} />)}/><MemoEditorMetadataRowdiff --git a/apps/web/src/lib/infographic-generation.test.mjs b/apps/web/src/lib/infographic-generation.test.mjsindex c9d992f8..4275c95b 100644--- a/apps/web/src/lib/infographic-generation.test.mjs+++ b/apps/web/src/lib/infographic-generation.test.mjs@@ -9,6 +9,9 @@ import {inferInfographicKind,infographicFamilyChoices,officialTemplateFamily,+ infographicNoteTitleIsAutomatic,+ infographicSyntaxTitle,+ nextInfographicNoteTitle,parseGeneratedInfographicContent,parseGeneratedOfficialData,parseGeneratedOfficialSelection,@@ -228,4 +231,65 @@ describe("infographic generation", () => {expect(candidates).toContain(current);expect(shortlistOfficialTemplates("给我换成字节的发展历程", getTemplates(), current, "sequence").every((id) => id.startsWith("sequence-timeline-"))).toBe(true);});++ test("a conversation that changes the infographic subject renames the note", () => {+ expect(nextInfographicNoteTitle({+ noteTitle: "DIKW 知识层级金字塔",+ previousGraphicTitle: "DIKW 知识层级金字塔",+ nextGraphicTitle: "腾讯与字节跳动对比",+ defaultTitle: "信息图",+ })).toBe("腾讯与字节跳动对比");+ expect(nextInfographicNoteTitle({+ noteTitle: "DIKW 知识层级金字塔",+ previousGraphicTitle: "DIKW 金字塔",+ nextGraphicTitle: "腾讯与字节跳动对比",+ defaultTitle: "信息图",+ })).toBe("腾讯与字节跳动对比");+ expect(nextInfographicNoteTitle({+ noteTitle: "信息图",+ previousGraphicTitle: "",+ nextGraphicTitle: "腾讯与字节跳动对比",+ defaultTitle: "信息图",+ })).toBe("腾讯与字节跳动对比");+ expect(nextInfographicNoteTitle({+ noteTitle: "竞品备忘",+ previousGraphicTitle: "腾讯与字节跳动对比",+ nextGraphicTitle: "腾讯与字节跳动对比",+ defaultTitle: "信息图",+ keepCustomTitle: true,+ })).toBe("竞品备忘");+ expect(nextInfographicNoteTitle({+ noteTitle: "竞品备忘",+ previousGraphicTitle: "",+ nextGraphicTitle: "腾讯与字节跳动对比",+ defaultTitle: "信息图",+ keepCustomTitle: true,+ })).toBe("竞品备忘");+ expect(nextInfographicNoteTitle({+ noteTitle: "DIKW 知识层级金字塔",+ previousGraphicTitle: "腾讯与字节跳动对比",+ nextGraphicTitle: "腾讯与字节跳动对比",+ defaultTitle: "信息图",+ })).toBe("腾讯与字节跳动对比");+ expect(nextInfographicNoteTitle({+ noteTitle: "竞品备忘",+ previousGraphicTitle: "DIKW 知识层级金字塔",+ nextGraphicTitle: "腾讯与字节跳动对比",+ defaultTitle: "信息图",+ keepCustomTitle: true,+ })).toBe("腾讯与字节跳动对比");+ expect(infographicSyntaxTitle("infographic list-row-simple-horizontal-arrow\ndata\n title 发布流程\n lists")).toBe("发布流程");+ expect(infographicNoteTitleIsAutomatic({+ noteTitle: "DIKW 知识层级金字塔",+ graphicTitle: "腾讯与字节跳动对比",+ defaultTitle: "信息图",+ earlierTitles: ["DIKW 知识层级金字塔"],+ })).toBe(true);+ expect(nextInfographicNoteTitle({+ noteTitle: "腾讯与字节跳动对比",+ previousGraphicTitle: "腾讯与字节跳动对比",+ nextGraphicTitle: " ",+ defaultTitle: "信息图",+ })).toBe("腾讯与字节跳动对比");+ });});diff --git a/apps/web/src/lib/infographic-generation.ts b/apps/web/src/lib/infographic-generation.tsindex 58caa3de..179091af 100644--- a/apps/web/src/lib/infographic-generation.ts+++ b/apps/web/src/lib/infographic-generation.ts@@ -251,6 +251,41 @@ export const infographicAgentCandidates = (request: string, templates: string[],const plainLine = (value: string) => value.replace(/\s+/g, " ").trim();+export const infographicSyntaxTitle = (syntax: string) => {+ const line = syntax.split("\n").find((entry) => /^ title \S/.test(entry));+ return line ? plainLine(line.slice(8)) : "";+};++export const infographicNoteTitleIsAutomatic = (input: {+ noteTitle: string;+ graphicTitle: string;+ defaultTitle: string;+ earlierTitles?: string[];+}) => {+ const note = plainLine(input.noteTitle);+ if (!note) return true;+ return [input.defaultTitle, input.graphicTitle, ...(input.earlierTitles ?? [])].some((title) => plainLine(title) === note);+};++// The note title follows the infographic title the conversation just applied.+// A title typed into the note field stays only while that graphic title itself stays put.+export const nextInfographicNoteTitle = (input: {+ noteTitle: string;+ previousGraphicTitle: string;+ nextGraphicTitle: string;+ defaultTitle: string;+ keepCustomTitle?: boolean;+}) => {+ const note = plainLine(input.noteTitle);+ const previous = plainLine(input.previousGraphicTitle);+ const next = plainLine(input.nextGraphicTitle).slice(0, 160);+ const fallback = plainLine(input.defaultTitle);+ if (!next || next === note) return note;+ if (!note || note === fallback || note === previous || !input.keepCustomTitle) return next;+ if (previous && next !== previous) return next;+ return note;+};+export const buildInfographicSyntax = (input: {template: string;title: string;diff --git a/apps/web/src/lib/infographic-local-agent.ts b/apps/web/src/lib/infographic-local-agent.tsindex 3b2f160b..9f286a30 100644--- a/apps/web/src/lib/infographic-local-agent.ts+++ b/apps/web/src/lib/infographic-local-agent.ts@@ -32,7 +32,7 @@ export const buildInfographicLocalAgentContext = (input: {}) => {const history = input.history.slice(-12).map((turn) => `User: ${turn.prompt}\nAssistant: ${turn.response}`).join("\n\n");return [- "You edit one AntV infographic in EdgeEver. The current infographic content is the source of truth. Keep the current template for content-only changes, including replacing one comparison subject. Change the template when the data relationship changes. Choose only from the allowed template IDs. Preserve information the user did not ask to change.",+ "You edit one AntV infographic in EdgeEver. The current infographic content is the source of truth. Keep the current template for content-only changes, including replacing one comparison subject. Change the template when the data relationship changes. Choose only from the allowed template IDs. Preserve information the user did not ask to change. data.title is the note title: change it when the subject changes, and keep it when the user only edits details.",infographicRequestsTimeline(input.prompt)? "The user requested one subject's development history. Choose an allowed sequence-timeline template and chronological events. Do not ask for clarification.": "Ask a short clarification only when you cannot make a useful edit.",