Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(poster): generate structured content layouts

tianma-if68f13c14f133
diff --git a/apps/api/src/companion-agent-tools.ts b/apps/api/src/companion-agent-tools.ts
index cb0155f1..48ca3c2a 100644
--- a/apps/api/src/companion-agent-tools.ts
+++ b/apps/api/src/companion-agent-tools.ts
@@ -123,7 +123,7 @@ const TOOL_HINTS: Record<string, string> = {
get_table_records: " Read an existing structured table's fields, record IDs, and revision. Use this before adding a record so cell keys are actual field IDs. Do not infer field IDs from names.",
add_table_record: " Add one requested record to a structured table. First call get_table_records, then use its field IDs and latest revision. Do not invent factual records to fill a new table.",
create_diagram_memo: " Create an editable visual diagram note. kind=mind-map for 思维导图/mind map, flowchart for 流程图, architecture for 架构图. Never use this for 信息图/infographic; call create_infographic_memo. Omit edge ids; EdgeEver generates them. For mind maps, give a root and children with parentId; omit node type. If the user did not name a notebook, omit notebookId. The diagram is saved in the inbox (等待分类). Do not ask which notebook, and do not use the open notebook unless the user named it. Build nodes from the open note body in Focus DATA when the user refers to this note.",
- create_poster_memo: " Create a real editable poster (海报笔记), never poster-style Markdown. Supply short copy; the tool handles canvas layout and encoding. If no notebook was named, omit notebookId and use the inbox. Report failure instead of substituting prose.",
+ create_poster_memo: " Create a real editable poster (海报笔记), never poster-style Markdown. Plan the key takeaway first. For informative topics such as 产业布局, summaries, comparisons and guides, provide 3–6 useful heading/body sections, not just a heading and generic subtitle. Choose grid for categories, list for steps, and a style suited to the subject. Use referenced note content and do not invent figures or sources. Quotes/slogans/minimal covers can omit sections. The tool handles editable canvas layout and encoding. If no notebook was named, omit notebookId and use the inbox. Report failure instead of substituting prose.",
create_infographic_memo: " Create an AntV infographic note (信息图). A share, proportion, or 占比 uses template chart-pie-donut-plain-text and numeric data.values, not a mind map. If the user did not supply the figures, say in data.desc that they are illustrative and are not an official disclosure. If the user did not name a notebook, omit notebookId. The infographic is saved in the inbox (等待分类). Do not ask which notebook, and do not use the open notebook unless the user named it.",
get_poster: " Read the existing poster canvas and elements before editing. Do not use raw Markdown for posters.",
update_poster: " Edit poster text, colors, typography and positions after get_poster. Preserve unmentioned and locked elements. Pass the revision you read.",
diff --git a/apps/api/src/companion-prepare.ts b/apps/api/src/companion-prepare.ts
index 7a404633..f90eb94c 100644
--- a/apps/api/src/companion-prepare.ts
+++ b/apps/api/src/companion-prepare.ts
@@ -47,7 +47,7 @@ search_memos matches note titles and bodies, not notebook names. Query is option
If list_memos or search_memos sets hasMore, say the list is incomplete instead of implying that is everything.
When the user refers to this note, 这篇, 当前, or the open note, use the Open note body in Focus DATA. If that body is truncated, call get_memo. If Focus DATA says the open note is a diagram, call get_diagram. Do not invent structure from the title alone.
When the user asks for a mind map, 思维导图, flowchart, 流程图, architecture diagram, or 架构图 of the open note, build it from that body (or get_memo/get_diagram first). To create a new diagram note, call create_diagram_memo. Do not use create_memo, Markdown outlines, or Mermaid. Preserve an explicitly requested type exactly: 思维导图/mind map means kind=mind-map, 流程图/flowchart means kind=flowchart, and 架构图/architecture diagram means kind=architecture. For mind maps, supply a root node and children with parentId; omit node type. If the user did not name a notebook, omit notebookId so it is saved in the inbox notebook (等待分类). Do not ask which notebook, and do not use the open notebook unless the user named it. Reply with the new note link.
-When the user asks to generate a poster or 海报笔记, call create_poster_memo with concise copy. It creates the actual editable poster type. Never substitute poster-style Markdown, manually encode source, or search local files for the format. Report tool failure honestly. If the user did not name a notebook, omit notebookId. Reply with the new note link.
+When the user asks to generate a poster or 海报笔记, call create_poster_memo after planning the message and visual hierarchy. For informative subjects (industry layouts, explainers, comparisons, guides), supply 3–6 distinct heading/body sections and choose grid for categories or list for steps. A heading plus a generic subtitle is not a complete informative poster. Use supplied content when referenced, never invent statistics or sources, and choose a template suited to the topic. Quotes, slogans and explicitly minimal covers can omit sections. It creates the actual editable poster type. Never substitute poster-style Markdown, manually encode source, or search local files for the format. Report tool failure honestly. If the user did not name a notebook, omit notebookId. Reply with the new note link.
When the user asks for an infographic, 信息图, 資訊圖, or インフォグラフィック, call create_infographic_memo. Do not use create_diagram_memo, create_memo, Markdown, or Mermaid for that request. A share, proportion, or 占比 is a pie infographic: template chart-pie-donut-plain-text and numeric data.values, not a mind map. If the user did not supply the figures, say in data.desc that they are illustrative and are not an official disclosure. If the user did not name a notebook, omit notebookId. Reply with the new note link.
When the user asks for a 多维表格, 多維表格, or structured table, call create_table_memo with explicit fields. Do not use create_memo or a Markdown table. If no records were supplied or requested, leave it empty. If records were requested, call get_table_records for the new table's field IDs and revision before add_table_record. Omit notebookId when no notebook was named. Reply with the new note link.
To find or list posters/海报笔记, call search_memos or list_memos with poster=true; the type is not a title keyword. To read a poster's canvas, call get_poster. For detailed poster design, read get_poster_capabilities for fonts, platform sizes, templates, operation fields and limits; then get_poster and update_poster. Operations support elements, layers, groups and canvas resizing, and typography, crop, stroke and shadow edits. apply_template replaces the layout: use only when the user asks. get_poster_preview and export_poster expose current saved previews and editable source; they do not render new images. For a fresh preview or full browser template, call request_poster_render with expectedRevision (and templateId only when requested), then get_poster_render_job at intervals of at least 5 seconds. An online desktop/Web workspace renders automatically. Pending means waiting for a client; only completed means rendered. After completion call get_poster_preview. Never claim a pending task succeeded. To change a poster/海报, call get_poster then update_poster. Edit only requested text, colors, typography or positions; preserve other elements and locked elements. Never replace poster content with update_memo. To delete a poster, use trash_memos with exact IDs from the query results; it goes to the recycle bin and can be restored with restore_memos.
diff --git a/apps/api/src/companion-tool-actions.test.mjs b/apps/api/src/companion-tool-actions.test.mjs
index 64a61e06..c9e6b579 100644
--- a/apps/api/src/companion-tool-actions.test.mjs
+++ b/apps/api/src/companion-tool-actions.test.mjs
@@ -51,13 +51,14 @@ describe("shared companion MCP adapter", () => {
test("poster CRUD reuses scoped queries, guarded edits, recoverable trash and restoration", async () => {
const f = await setup();
const tools = createCompanionTools({ ...f, scope, signal: new AbortController().signal, assertActive: async () => {}, sources: [] });
- const created = await tools.create_poster_memo.execute({ notebookId: "ideas", title: "Energy poster", heading: "Protect your energy" });
+ const created = await tools.create_poster_memo.execute({ notebookId: "ideas", title: "Energy poster", heading: "Protect your energy", layout: "list", sections: [{ heading: "Rest", body: "Make time to recharge" }, { heading: "Focus", body: "Keep space for important work" }] });
const listed = await tools.list_memos.execute({ poster: true });
expect(listed.memos.map(memo => memo.id)).toContain(created.id);
expect(listed.memos.find(memo => memo.id === created.id).poster).toBe(true);
expect(await tools.get_memo.execute({ memoId: created.id })).toMatchObject({ poster: true, message: expect.stringContaining("get_poster") });
await tools.get_poster.execute({ memoId: created.id });
const poster = await getMemoDetail(f.db, scope.workspaceId, created.id);
+ expect(parsePosterDocument(poster.contentMarkdown).elements.find(element => element.id === "section-1-body").text).toBe("Make time to recharge");
const heading = parsePosterDocument(poster.contentMarkdown).elements.find(element => element.role === "title");
await tools.update_poster.execute({ memoId: created.id, expectedRevision: poster.revision, edits: [{ id: heading.id, patch: { text: "Focus on what matters" } }] });
expect(parsePosterDocument((await getMemoDetail(f.db, scope.workspaceId, created.id)).contentMarkdown).copy.title).toBe("Focus on what matters");
diff --git a/apps/api/src/mcp-poster-tools.test.mjs b/apps/api/src/mcp-poster-tools.test.mjs
index 02918ea9..dc267cde 100644
--- a/apps/api/src/mcp-poster-tools.test.mjs
+++ b/apps/api/src/mcp-poster-tools.test.mjs
@@ -105,3 +105,47 @@ test("poster edits update canonical copy, support background changes and retain
expect(unchanged.changed).toBe(false);
expect(unchanged.document.previewResourceId).toBe("preview");
});
+
+test("informative posters retain each section through editing and source round-trip", () => {
+ const sections = [
+ { heading: "社交", body: "连接用户与日常沟通场景" },
+ { heading: "内容", body: "承载资讯、视频与数字阅读" },
+ { heading: "游戏", body: "连接互动娱乐与数字内容" },
+ { heading: "金融科技", body: "服务支付与金融应用场景" },
+ { heading: "企业服务", body: "提供云与企业协作能力" },
+ ];
+ for (const format of POSTER_FORMATS) {
+ const { document } = compilePosterMemo({ notebookId: "inbox", title: "腾讯产业布局", heading: "腾讯产业布局", subtitle: "以连接为核心的数字生态", badge: "产业观察", footer: "从用户连接,延伸到内容与服务", sections, template: "bold", format: format.id });
+ const restored = parsePosterDocument(serializePosterDocument(document));
+ expect(restored).toEqual(document);
+ for (const element of document.elements) {
+ expect(element.x).toBeGreaterThanOrEqual(0);
+ expect(element.y).toBeGreaterThanOrEqual(0);
+ expect(element.x + element.width).toBeLessThanOrEqual(document.width + 0.001);
+ expect(element.y + element.height).toBeLessThanOrEqual(document.height + 0.001);
+ }
+ sections.forEach((section, index) => {
+ expect(document.elements.find(e => e.id === `section-${index + 1}-body`).text).toBe(section.body);
+ });
+ const edited = applyPosterEdits({ memoId: "memo", expectedRevision: 1, edits: [{ id: "section-1-body", patch: { text: "连接人与沟通场景" } }] }, document).document;
+ expect(edited.elements.find(e => e.id === "section-1-body").text).toBe("连接人与沟通场景");
+ expect(edited.copy.title).toBe("腾讯产业布局");
+ expect(edited.copy.subtitle).toBe("以连接为核心的数字生态");
+ }
+});
+
+test("content layouts adapt columns, reject overflow and leave headline-only callers compatible", () => {
+ const sections = Array.from({ length: 6 }, (_, i) => ({ heading: `要点 ${i + 1}`, body: "简短说明" }));
+ const build = fields => compilePosterMemo({ notebookId: "inbox", title: "Poster", heading: "知识要点", sections, ...fields }).document;
+ const grid = build({ layout: "grid" });
+ const list = build({ layout: "list" });
+ expect(grid.elements.find(e => e.id === "section-2-card").y).toBe(grid.elements.find(e => e.id === "section-1-card").y);
+ expect(list.elements.find(e => e.id === "section-2-card").y).toBeGreaterThan(list.elements.find(e => e.id === "section-1-card").y);
+ expect(build({ format: "story" }).elements.find(e => e.id === "section-2-card").x).toBe(build({ format: "story" }).elements.find(e => e.id === "section-1-card").x);
+ expect(() => build({ format: "wechat", layout: "list", sections: sections.map(section => ({ ...section, body: "说明\n".repeat(30) })) })).toThrow("does not fit");
+ expect(() => build({ sections: [sections[0]] })).toThrow();
+ expect(() => build({ sections: sections.concat(sections[0]) })).toThrow();
+ const legacy = compilePosterMemo({ notebookId: "inbox", title: "Poster", heading: "一句话" }).document;
+ expect(legacy.elements).toHaveLength(3);
+ expect(() => build({ sections: undefined, footer: "Requires sections" })).toThrow("require sections");
+});
diff --git a/apps/api/src/mcp-poster-tools.ts b/apps/api/src/mcp-poster-tools.ts
index ec19d051..f9255d08 100644
--- a/apps/api/src/mcp-poster-tools.ts
+++ b/apps/api/src/mcp-poster-tools.ts
@@ -1,6 +1,7 @@
import { z } from "zod";
import { createPosterDocument, POSTER_FORMATS, POSTER_TEMPLATES, PosterDocumentSchema, PosterGradientSchema, PosterElementSchema, PosterPaintGradientSchema, resizePosterDocument, PLATFORMS, POSTER_FONTS, POSTER_DESIGN_TEMPLATES, type PosterDocument } from "@edgeever/shared";
import { AppError } from "./app-error";
+import { layoutPosterContent } from "./poster-content-layout";
const creation = z.object({
notebookId: z.string().min(1),
@@ -9,6 +10,10 @@ const creation = z.object({
subtitle: z.string().max(240).default(""),
template: z.enum(POSTER_TEMPLATES).default("editorial"),
format: z.enum(["portrait", "square", "wechat", "video", "story"]).default("portrait"),
+ badge: z.string().trim().max(24).default(""),
+ footer: z.string().trim().max(100).default(""),
+ layout: z.enum(["auto", "grid", "list"]).default("auto"),
+ sections: z.array(z.object({ heading: z.string().trim().min(1).max(32), body: z.string().trim().min(1).max(120) }).strict()).min(2).max(6).optional(),
tags: z.array(z.string()).max(100).optional(),
}).strict();
@@ -21,6 +26,11 @@ export function compilePosterMemo(input: unknown) {
const document = createPosterDocument(args.heading, args.subtitle, args.template, format.width, format.height);
document.templateId = args.template;
document.copy = { title: args.heading, subtitle: args.subtitle, badge: "" };
+ if (args.sections) {
+ layoutPosterContent(document, { ...args, sections: args.sections });
+ return { args, document: PosterDocumentSchema.parse(document) };
+ }
+ if (args.badge || args.footer || args.layout !== "auto") throw new AppError("invalid_params", "Structured layout, badge and footer require sections. Omit them for a headline-only poster.", 400);
for (const element of document.elements) {
if (element.type !== "text") continue;
element.role = element.id === "heading" ? "title" : "subtitle";
@@ -212,6 +222,7 @@ export function posterCapabilities() {
return {
templates: POSTER_TEMPLATES.map(id => ({ id, sourceBuilder: "server", imageRenderer: "client" })),
browserDesignTemplates: POSTER_DESIGN_TEMPLATES.filter(template => template.available).map(template => ({ ...template, renderer: "browser", instruction: "Use request_poster_render with templateId and expectedRevision. This ID is not a server apply_template ID." })),
+ contentLayouts: { layouts: ["auto", "grid", "list"], sections: { min: 2, max: 6, headingMaxLength: 32, bodyMaxLength: 120 }, instruction: "For explanatory posters, plan 3–6 concise sections before creating. Use grid for categories/comparison, list for steps/ranked points. badge and footer are optional. Auto adapts columns to the aspect ratio. Headline-only posters may omit sections." },
formats: POSTER_FORMATS,
platforms: PLATFORMS,
fonts: POSTER_FONTS.map(({ family, zh, en }) => ({ family, zh, en })),
diff --git a/apps/api/src/mcp-tools.ts b/apps/api/src/mcp-tools.ts
index 098bc32c..e07c736e 100644
--- a/apps/api/src/mcp-tools.ts
+++ b/apps/api/src/mcp-tools.ts
@@ -368,12 +368,16 @@ const MCP_TOOL_DEFINITIONS = [
},
{
name: "create_poster_memo",
- description: "Create an editable poster note (海报笔记). Use this when asked to generate a poster, not create_memo or update_memo with poster-style prose. Supply concise heading and subtitle; EdgeEver generates valid canvas geometry and encoded source using its built-in templates. Do not inspect other notes or local files to reverse-engineer the poster format. If this tool fails, report the error; never silently substitute an ordinary Markdown note. Use get_poster then update_poster only for subsequent edits.",
+ description: "Create an editable poster note (海报笔记). Use this when asked to generate a poster, not create_memo or update_memo with poster-style prose. First plan the takeaway and content hierarchy. For explanatory topics (industry layouts, knowledge summaries, comparisons or guides), supply 3–6 concise sections with heading/body and choose layout=grid for categories or layout=list for steps. Do not reduce an informative topic to a title and generic subtitle. Use supplied note content when referenced; do not invent statistics, sources or brand relationships. For quotes, slogans or an explicitly minimal cover, omit sections. Choose template deliberately (bold/minimal for technology or business, editorial/quote for literary copy); optional badge/footer require sections. EdgeEver compiles editable elements and fits text to the selected format. Do not inspect other notes or local files to reverse-engineer the poster format. If this tool fails, report the error; never silently substitute an ordinary Markdown note. Use get_poster then update_poster only for subsequent edits.",
inputSchema: {
type: "object", required: ["notebookId", "title", "heading"], additionalProperties: false,
properties: {
notebookId: { type: "string", minLength: 1 }, title: { type: "string", minLength: 1, maxLength: 160 },
heading: { type: "string", minLength: 1, maxLength: 80 }, subtitle: { type: "string", maxLength: 240 },
+ layout: { type: "string", enum: ["auto", "grid", "list"], description: "With sections: grid for categories/comparisons, list for ordered steps; auto adapts to canvas aspect ratio." },
+ badge: { type: "string", maxLength: 24, description: "Optional short topic label; requires sections." },
+ footer: { type: "string", maxLength: 100, description: "Optional takeaway or supplied source; requires sections. Never invent attribution." },
+ sections: { type: "array", minItems: 2, maxItems: 6, description: "Main content for informative posters. Each section must convey a distinct useful point, not repeat the subtitle.", items: { type: "object", additionalProperties: false, required: ["heading", "body"], properties: { heading: { type: "string", minLength: 1, maxLength: 32 }, body: { type: "string", minLength: 1, maxLength: 120 } } } },
template: { type: "string", enum: [...POSTER_TEMPLATES] },
format: { type: "string", enum: POSTER_FORMATS.map(format => format.id) },
tags: { type: "array", maxItems: 100, items: { type: "string" } },
diff --git a/apps/api/src/poster-content-layout.ts b/apps/api/src/poster-content-layout.ts
new file mode 100644
index 00000000..c16ef0c8
--- /dev/null
+++ b/apps/api/src/poster-content-layout.ts
@@ -0,0 +1,77 @@
+import type { PosterDocument, PosterText } from "@edgeever/shared";
+import { AppError } from "./app-error";
+
+export type PosterSection = { heading: string; body: string };
+export type PosterContentPlan = {
+ heading: string;
+ subtitle: string;
+ badge: string;
+ footer: string;
+ layout: "auto" | "grid" | "list";
+ sections: PosterSection[];
+};
+
+// Compile semantic content into ordinary v1 elements: every block remains editable
+// and works with the existing editor, resource renderer and Markdown fallback.
+export function layoutPosterContent(document: PosterDocument, plan: PosterContentPlan) {
+ const { width: w, height: h } = document;
+ const unit = Math.min(w, h);
+ const margin = unit * 0.065;
+ const gap = unit * 0.025;
+ const inner = w - margin * 2;
+ const ink = "#07130b";
+ const dark = document.background === ink;
+ const accent = dark ? "#baf264" : "#16a06e";
+ document.elements = [];
+ const rect = (id: string, x: number, y: number, width: number, height: number, fill: string, groupId?: string) => {
+ document.elements.push({ id, name: id, type: "rect", role: "decor", x, y, width, height, fill, rotation: 0, opacity: 1, ...(groupId ? { groupId } : {}) });
+ };
+ const text = (id: string, content: string, x: number, y: number, width: number, height: number, size: number, fill: string, bold = false, role: PosterText["role"] = "decor", groupId?: string) => {
+ if (!content) return;
+ const lines = (fontSize: number) => content.split("\n").reduce((sum, line) => sum + Math.max(1, Math.ceil(Array.from(line).length * fontSize / width)), 0);
+ let fontSize = Math.max(14, Math.floor(size));
+ while (fontSize > 14 && lines(fontSize) * fontSize * 1.3 > height) fontSize--;
+ if (lines(fontSize) * fontSize * 1.3 > height) {
+ throw new AppError("invalid_params", "Poster content does not fit. Shorten section copy or use fewer sections/a taller format.", 400);
+ }
+ document.elements.push({ id, name: id, type: "text", role, text: content, sourceText: content, x, y, width, height, fontSize, fill, fontFamily: "sans-serif", fontWeight: bold ? "bold" : "normal", textAlign: "left", lineHeight: 1.3, rotation: 0, opacity: 1, ...(groupId ? { groupId } : {}) });
+ };
+ const headerEnd = h * 0.32;
+ rect("content-header", 0, 0, w, headerEnd, ink);
+ rect("accent", margin, h * 0.045, unit * 0.09, unit * 0.008, accent);
+ text("badge", plan.badge, margin + unit * 0.12, h * 0.032, inner - unit * 0.12, h * 0.04, unit * 0.022, accent, true, "badge");
+ text("heading", plan.heading, margin, h * 0.09, inner, h * 0.13, Math.min(w * 0.075, h * 0.065), "#ffffff", true, "title");
+ text("subtitle", plan.subtitle, margin, h * 0.24, inner, h * 0.065, unit * 0.026, "#ffffff", false, "subtitle");
+
+ // Wide canvases need columns; portrait step-by-step copy benefits from rows.
+ const useGrid = plan.layout === "grid" || (plan.layout === "auto" && w / h >= 0.7);
+ const columns = useGrid ? Math.min(plan.sections.length, w / h >= 1.5 ? 3 : 2) : 1;
+ const rows = Math.ceil(plan.sections.length / columns);
+ const top = headerEnd + gap;
+ const bottom = plan.footer ? h * 0.88 : h - margin;
+ const cellHeight = (bottom - top - gap * (rows - 1)) / rows;
+ const cellWidth = (inner - gap * (columns - 1)) / columns;
+ plan.sections.forEach((section, index) => {
+ const row = Math.floor(index / columns);
+ const col = index % columns;
+ const span = index === plan.sections.length - 1 && col < columns - 1;
+ const x = margin + col * (cellWidth + gap);
+ const y = top + row * (cellHeight + gap);
+ const width = span ? inner - col * (cellWidth + gap) : cellWidth;
+ const pad = Math.min(unit * 0.027, cellHeight * 0.09);
+ const group = `section-${index + 1}`;
+ rect(`${group}-card`, x, y, width, cellHeight, dark ? "#14281e" : "#ffffff", group);
+ rect(`${group}-accent`, x, y, unit * 0.005, cellHeight, accent, group);
+ const labelHeight = Math.max(19, Math.min(unit * 0.024, cellHeight * 0.13));
+ const headingHeight = cellHeight * 0.26;
+ text(`${group}-number`, String(index + 1).padStart(2, "0"), x + pad, y + pad, width - pad * 2, labelHeight, labelHeight / 1.3, accent, true, "decor", group);
+ text(`${group}-heading`, section.heading, x + pad, y + pad + labelHeight + pad / 2, width - pad * 2, headingHeight, Math.min(unit * 0.033, headingHeight / 1.3), dark ? "#ffffff" : ink, true, "decor", group);
+ const bodyY = y + pad * 2 + labelHeight + headingHeight;
+ text(`${group}-body`, section.body, x + pad, bodyY, width - pad * 2, y + cellHeight - pad - bodyY, unit * 0.024, dark ? "#d5e8dc" : "#35483c", false, "decor", group);
+ });
+ if (plan.footer) {
+ rect("footer-rule", margin, h * 0.915, inner, Math.max(1, unit * 0.0015), accent);
+ text("footer", plan.footer, margin, h * 0.935, inner, h * 0.045, unit * 0.02, dark ? "#d5e8dc" : "#35483c");
+ }
+ document.copy = { title: plan.heading, subtitle: plan.subtitle, badge: plan.badge };
+}