webcake-landing-mcp 1.0.48 → 1.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -443,13 +443,13 @@ Both `create_page` and `update_page` **default to `dry_run=true`** (validate and
443
443
  |------|-------------|
444
444
  | `get_generation_guide` | **Read FIRST.** Output shape, coordinate system, event vocabulary, workflow. |
445
445
  | `list_elements` | All element types by category (summary + when-to-use + container?). |
446
- | `get_element` | One type: hints, key `specials`, default skeleton, filled example. |
446
+ | `get_element` | One type (or many at once): hints, key `specials`, a SPARSE skeleton (the exact shape to emit — the server hydrates omitted boilerplate), filled example. |
447
447
  | `get_page_schema` | Full JSON Schema (Draft 2020-12) of a page source. |
448
448
 
449
449
  ### Generation
450
450
  | Tool | Description |
451
451
  |------|-------------|
452
- | `new_element` | A structurally-valid default node for a type (fresh id). |
452
+ | `new_element` | A default node for a type (fresh id) in the SPARSE authoring shape — copy it as-is; omitted boilerplate is hydrated server-side. |
453
453
  | `new_page_skeleton` | An empty but complete top-level source `{ page, popup, settings, options, cartConfigs }`. |
454
454
  | `validate_page` | Structural + semantic validation (ids, event targets, containers, `field_name`). |
455
455
 
@@ -465,7 +465,7 @@ Both `create_page` and `update_page` **default to `dry_run=true`** (validate and
465
465
  | `create_page` | Persist a generated source as a new page (source-only). **Defaults to `dry_run=true`.** |
466
466
  | `list_pages` | List the account's pages (id, name, organization_id, updated_at) to pick one to edit. |
467
467
  | `find_pages` | Search the account's pages by name, domain, and/or page id (AND-combined) to locate one to edit; returns id, name, org, custom/default domain, updated_at. |
468
- | `get_page` | Fetch an existing page's decoded source tree so you can edit it. |
468
+ | `get_page` | Fetch an existing page's decoded source tree, COMPACTED to the sparse authoring shape (factory-default boilerplate stripped — far fewer tokens; `compact:false` for the raw tree). Edit and send back as-is. |
469
469
  | `update_page` | Overwrite an existing page's source with an edited tree. **Defaults to `dry_run=true`.** |
470
470
 
471
471
  ---
@@ -1,4 +1,11 @@
1
1
  [
2
+ {
3
+ "v": "1.0.49",
4
+ "d": "10/06/2026",
5
+ "type": "Changed",
6
+ "en": "get_page now returns a compacted source by default: factory-default boilerplate (properties, runtime, empty events/children, per-breakpoint config,…",
7
+ "vi": "get_page nay trả về source đã compacted theo mặc định: các boilerplate theo factory-default (properties, runtime, events/children rỗng, config theo…"
8
+ },
2
9
  {
3
10
  "v": "1.0.48",
4
11
  "d": "10/06/2026",
@@ -33,12 +40,5 @@
33
40
  "type": "Added",
34
41
  "en": "New find_pages tool searches the account's pages by name, domain (matches custom_domain or default_domain), and/or page id (filters are…",
35
42
  "vi": "Công cụ find_pages mới tìm kiếm các trang trong tài khoản theo tên, domain (khớp với custom_domain hoặc default_domain), và/hoặc page id (các bộ lọc…"
36
- },
37
- {
38
- "v": "1.0.43",
39
- "d": "09/06/2026",
40
- "type": "Changed",
41
- "en": "The GET / web guide page has refreshed copy throughout: updated page title and meta description, simplified FAQ answers in both English and…",
42
- "vi": "Trang hướng dẫn GET / được làm mới toàn bộ nội dung: cập nhật tiêu đề trang và meta description, đơn giản hóa câu trả lời FAQ bằng cả tiếng Anh và…"
43
43
  }
44
44
  ]
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Full-node compaction (the inverse of ./expand.ts).
3
+ *
4
+ * `compactNode` strips from a FULL element node everything that `expandNode`
5
+ * would re-create identically from the type's factory default: `properties`
6
+ * keys equal to the seed (movable/sync/default name), `runtime` when it equals
7
+ * the seed's, empty `events`, empty seed-equal `children`, and each
8
+ * breakpoint's `config`/`styles` keys whose values match the seed (notloaded +
9
+ * the default animation block). What remains is the SPARSE authoring shape the
10
+ * model is asked to emit — so `get_page` can return a compacted tree and the
11
+ * model sees (and learns to write) sparse nodes instead of boilerplate.
12
+ *
13
+ * Invariant (smoke-tested): expand(compact(x)) persists the SAME tree as
14
+ * expand(x). Compaction only removes data the expansion seed restores.
15
+ * Unknown types and non-element values pass through untouched.
16
+ */
17
+ import { base } from "./element.js";
18
+ const STD_KEYS = ["id", "type", "properties", "specials", "runtime", "events", "responsive", "children"];
19
+ const isObj = (v) => v != null && typeof v === "object" && !Array.isArray(v);
20
+ /** JSON-ish deep equality (objects, arrays, primitives — no cycles). */
21
+ export function deepEq(a, b) {
22
+ if (a === b)
23
+ return true;
24
+ if (Array.isArray(a) && Array.isArray(b)) {
25
+ return a.length === b.length && a.every((v, i) => deepEq(v, b[i]));
26
+ }
27
+ if (isObj(a) && isObj(b)) {
28
+ const ka = Object.keys(a);
29
+ const kb = Object.keys(b);
30
+ return ka.length === kb.length && ka.every((k) => deepEq(a[k], b[k]));
31
+ }
32
+ return false;
33
+ }
34
+ /** Keys of `input` whose values differ from `seed`'s; undefined when nothing differs. */
35
+ function diffShallow(input, seed) {
36
+ if (!isObj(input))
37
+ return undefined;
38
+ const out = {};
39
+ const seedObj = isObj(seed) ? seed : {};
40
+ for (const k of Object.keys(input)) {
41
+ if (!deepEq(input[k], seedObj[k]))
42
+ out[k] = input[k];
43
+ }
44
+ return Object.keys(out).length ? out : undefined;
45
+ }
46
+ /** Strip from ONE (full) element node everything its factory seed re-creates. */
47
+ export function compactNode(input, createElement) {
48
+ if (!isObj(input))
49
+ return input;
50
+ const type = input.type;
51
+ if (typeof type !== "string" || type === "")
52
+ return input;
53
+ // Seed with the DEFAULT name (no override): a custom properties.name must
54
+ // survive the diff, because expandNode re-seeds from input.properties.name.
55
+ let seed;
56
+ try {
57
+ seed = createElement(type);
58
+ }
59
+ catch {
60
+ return input;
61
+ }
62
+ const out = {};
63
+ if (typeof input.id === "string")
64
+ out.id = input.id;
65
+ out.type = type;
66
+ const props = diffShallow(input.properties, seed.properties);
67
+ if (props)
68
+ out.properties = props;
69
+ const specials = diffShallow(input.specials, seed.specials);
70
+ if (specials)
71
+ out.specials = specials;
72
+ // runtime/events are replaced WHOLESALE by expandNode when provided, so they
73
+ // can only be dropped when they equal the seed's (typically {} / []).
74
+ if (isObj(input.runtime) && !deepEq(input.runtime, seed.runtime))
75
+ out.runtime = input.runtime;
76
+ if (Array.isArray(input.events) && !deepEq(input.events, seed.events))
77
+ out.events = input.events;
78
+ const responsive = {};
79
+ for (const bp of ["desktop", "mobile"]) {
80
+ const inBp = isObj(input.responsive) ? input.responsive[bp] : undefined;
81
+ if (!isObj(inBp))
82
+ continue; // absent → expand restores the seed breakpoint
83
+ const seedBp = seed.responsive[bp];
84
+ const bpOut = {};
85
+ const cfg = diffShallow(inBp.config, seedBp.config);
86
+ if (cfg)
87
+ bpOut.config = cfg;
88
+ const sty = diffShallow(inBp.styles, seedBp.styles);
89
+ if (sty)
90
+ bpOut.styles = sty;
91
+ for (const k of Object.keys(inBp)) {
92
+ if (k === "config" || k === "styles")
93
+ continue;
94
+ if (!deepEq(inBp[k], seedBp[k]))
95
+ bpOut[k] = inBp[k];
96
+ }
97
+ if (Object.keys(bpOut).length)
98
+ responsive[bp] = bpOut;
99
+ }
100
+ if (Object.keys(responsive).length)
101
+ out.responsive = responsive;
102
+ // children: expandNode falls back to seed.children when omitted, so a
103
+ // seed-equal children array (e.g. an empty []) can be dropped entirely.
104
+ if (Array.isArray(input.children) && !deepEq(input.children, seed.children)) {
105
+ out.children = input.children.map((c) => compactNode(c, createElement));
106
+ }
107
+ // carry over any non-standard keys (expandNode round-trips them too).
108
+ for (const k of Object.keys(input)) {
109
+ if (!STD_KEYS.includes(k))
110
+ out[k] = input[k];
111
+ }
112
+ return out;
113
+ }
114
+ /**
115
+ * The sparse AUTHORING TEMPLATE of a factory node — what get_element/new_element
116
+ * hand the model to copy. Unlike `compactNode` (which diffs against the type's
117
+ * own seed and so reduces a fresh factory node to nothing), this KEEPS the
118
+ * seeded meaningful values — styles, specials, non-default config, children —
119
+ * and drops only the boilerplate the server hydrates on persist: `properties`,
120
+ * `runtime`, empty `events`, and each breakpoint's base config (notloaded +
121
+ * the default animation block). Both breakpoints stay visible: the model must
122
+ * always provide desktop AND mobile styles.
123
+ */
124
+ export function sparseTemplate(node) {
125
+ const blank = base();
126
+ const out = { id: node.id, type: node.type };
127
+ if (isObj(node.specials) && Object.keys(node.specials).length)
128
+ out.specials = node.specials;
129
+ const responsive = {};
130
+ for (const bp of ["desktop", "mobile"]) {
131
+ const nBp = node.responsive[bp];
132
+ const bpOut = {};
133
+ const cfg = diffShallow(nBp?.config, blank.responsive[bp].config);
134
+ if (cfg)
135
+ bpOut.config = cfg;
136
+ bpOut.styles = isObj(nBp?.styles) ? nBp.styles : {};
137
+ responsive[bp] = bpOut;
138
+ }
139
+ out.responsive = responsive;
140
+ if (Array.isArray(node.events) && node.events.length)
141
+ out.events = node.events;
142
+ if (Array.isArray(node.children))
143
+ out.children = node.children.map(sparseTemplate);
144
+ return out;
145
+ }
146
+ /** Compact every node in a page source ({ page, popup, dynamic_pages }). */
147
+ export function compactSource(source, createElement) {
148
+ if (!isObj(source))
149
+ return source;
150
+ const out = { ...source };
151
+ if (Array.isArray(source.page))
152
+ out.page = source.page.map((s) => compactNode(s, createElement));
153
+ if (Array.isArray(source.popup))
154
+ out.popup = source.popup.map((p) => compactNode(p, createElement));
155
+ if (Array.isArray(source.dynamic_pages))
156
+ out.dynamic_pages = source.dynamic_pages.map((p) => compactNode(p, createElement));
157
+ return out;
158
+ }
@@ -22,15 +22,15 @@ export const CONTENT = [
22
22
  el.specials.text = "hello world";
23
23
  el.specials.tag = "p";
24
24
  },
25
+ // Examples are in the SPARSE authoring shape — the server hydrates
26
+ // properties/runtime/events/config from factory defaults on validate/persist.
25
27
  example: {
26
28
  id: "headline1", type: "text-block",
27
- properties: { name: "Headline", movable: true, sync: true },
28
29
  responsive: {
29
- desktop: { config: {}, styles: { top: 80, left: 180, width: 600, fontSize: 44, fontWeight: "bold", color: "rgba(26,32,44,1)", textAlign: "center" } },
30
- mobile: { config: {}, styles: { top: 60, left: 20, width: 380, fontSize: 28, fontWeight: "bold", color: "rgba(26,32,44,1)", textAlign: "center" } },
30
+ desktop: { styles: { top: 80, left: 180, width: 600, fontSize: 44, fontWeight: "bold", color: "rgba(26,32,44,1)", textAlign: "center" } },
31
+ mobile: { styles: { top: 60, left: 20, width: 380, fontSize: 28, fontWeight: "bold", color: "rgba(26,32,44,1)", textAlign: "center" } },
31
32
  },
32
33
  specials: { text: "Bán hàng dễ hơn với Webcake", tag: "h1" },
33
- runtime: {}, events: [],
34
34
  },
35
35
  },
36
36
  {
@@ -67,13 +67,11 @@ export const CONTENT = [
67
67
  },
68
68
  example: {
69
69
  id: "hero_img", type: "image-block",
70
- properties: { name: "Image Block", movable: true, sync: true },
71
70
  responsive: {
72
- desktop: { config: {}, styles: { top: 40, left: 540, width: 360, height: 300, position: "absolute" } },
73
- mobile: { config: {}, styles: { top: 260, left: 60, width: 300, height: 240, position: "absolute" } },
71
+ desktop: { styles: { top: 40, left: 540, width: 360, height: 300, position: "absolute" } },
72
+ mobile: { styles: { top: 260, left: 60, width: 300, height: 240, position: "absolute" } },
74
73
  },
75
74
  specials: { src: "https://placehold.co/360x300?text=Product", imageCompression: true },
76
- runtime: {}, events: [],
77
75
  },
78
76
  },
79
77
  {
@@ -117,12 +115,11 @@ export const CONTENT = [
117
115
  },
118
116
  example: {
119
117
  id: "cta_main", type: "button",
120
- properties: { name: "CTA", movable: true, sync: true },
121
118
  responsive: {
122
- desktop: { config: {}, styles: { top: 300, left: 405, width: 150, height: 44, background: "rgba(246,4,87,1)", color: "rgba(255,255,255,1)", borderRadius: "8px", textAlign: "center", fontWeight: "bold" } },
123
- mobile: { config: {}, styles: { top: 200, left: 135, width: 150, height: 44, background: "rgba(246,4,87,1)", color: "rgba(255,255,255,1)", borderRadius: "8px", textAlign: "center", fontWeight: "bold" } },
119
+ desktop: { styles: { top: 300, left: 405, width: 150, height: 44, background: "rgba(246,4,87,1)", color: "rgba(255,255,255,1)", borderRadius: "8px", textAlign: "center", fontWeight: "bold" } },
120
+ mobile: { styles: { top: 200, left: 135, width: 150, height: 44, background: "rgba(246,4,87,1)", color: "rgba(255,255,255,1)", borderRadius: "8px", textAlign: "center", fontWeight: "bold" } },
124
121
  },
125
- specials: { text: "Đăng ký ngay" }, runtime: {},
122
+ specials: { text: "Đăng ký ngay" },
126
123
  events: [{ id: "ev_cta", type: "click", action: "scroll_to", target: "form_section" }],
127
124
  },
128
125
  },
@@ -77,15 +77,15 @@ export const FORM = [
77
77
  setBox(el, 150, 36);
78
78
  el.specials.field_name = `input_${el.id}`;
79
79
  },
80
+ // Examples are in the SPARSE authoring shape — the server hydrates
81
+ // properties/runtime/events/config from factory defaults on validate/persist.
80
82
  example: {
81
83
  id: "in_phone", type: "input",
82
- properties: { name: "Input", movable: true, sync: true },
83
84
  responsive: {
84
- desktop: { config: {}, styles: { top: 60, left: 20, width: 360, height: 40 } },
85
- mobile: { config: {}, styles: { top: 60, left: 20, width: 360, height: 40 } },
85
+ desktop: { styles: { top: 60, left: 20, width: 360, height: 40 } },
86
+ mobile: { styles: { top: 60, left: 20, width: 360, height: 40 } },
86
87
  },
87
88
  specials: { field_name: "phone", field_placeholder: "Số điện thoại", field_type: "phone", required: true },
88
- runtime: {}, events: [],
89
89
  },
90
90
  },
91
91
  {
@@ -127,10 +127,9 @@ export const FORM = [
127
127
  },
128
128
  example: {
129
129
  id: "sel_attend", type: "select",
130
- properties: { name: "Select", movable: true, sync: true },
131
130
  responsive: {
132
- desktop: { config: {}, styles: { top: 0, left: 0, width: 300, height: 44 } },
133
- mobile: { config: {}, styles: { top: 0, left: 0, width: 280, height: 44 } },
131
+ desktop: { styles: { top: 0, left: 0, width: 300, height: 44 } },
132
+ mobile: { styles: { top: 0, left: 0, width: 280, height: 44 } },
134
133
  },
135
134
  // options use {id, name} — NOT {label, value}. field_placeholder is required.
136
135
  specials: {
@@ -142,7 +141,6 @@ export const FORM = [
142
141
  { id: "opt_no", name: "Rất tiếc, tôi không thể đến" },
143
142
  ],
144
143
  },
145
- runtime: {}, events: [],
146
144
  },
147
145
  },
148
146
  {
@@ -133,22 +133,22 @@ export const LAYOUT = [
133
133
  el.properties.movable = false;
134
134
  setBox(el, 400, 250);
135
135
  },
136
+ // Example is in the SPARSE authoring shape — the server hydrates
137
+ // properties/runtime/events/config from factory defaults on validate/persist.
136
138
  example: {
137
139
  id: "popthanks", type: "popup",
138
- properties: { name: "Thank you", movable: false, sync: true },
140
+ properties: { name: "Thank you" },
139
141
  responsive: {
140
- desktop: { config: {}, styles: { width: 420, height: 220, background: "rgba(255,255,255,1)", borderRadius: "12px" } },
141
- mobile: { config: {}, styles: { width: 360, height: 220, background: "rgba(255,255,255,1)", borderRadius: "12px" } },
142
+ desktop: { styles: { width: 420, height: 220, background: "rgba(255,255,255,1)", borderRadius: "12px" } },
143
+ mobile: { styles: { width: 360, height: 220, background: "rgba(255,255,255,1)", borderRadius: "12px" } },
142
144
  },
143
- specials: {}, runtime: {}, events: [],
144
145
  children: [
145
146
  { id: "popclose", type: "button",
146
- properties: { name: "Close", movable: true, sync: true },
147
147
  responsive: {
148
- desktop: { config: {}, styles: { top: 150, left: 160, width: 100, height: 40, background: "rgba(76,175,80,1)", color: "rgba(255,255,255,1)", borderRadius: "8px", textAlign: "center" } },
149
- mobile: { config: {}, styles: { top: 150, left: 130, width: 100, height: 40, background: "rgba(76,175,80,1)", color: "rgba(255,255,255,1)", borderRadius: "8px", textAlign: "center" } },
148
+ desktop: { styles: { top: 150, left: 160, width: 100, height: 40, background: "rgba(76,175,80,1)", color: "rgba(255,255,255,1)", borderRadius: "8px", textAlign: "center" } },
149
+ mobile: { styles: { top: 150, left: 130, width: 100, height: 40, background: "rgba(76,175,80,1)", color: "rgba(255,255,255,1)", borderRadius: "8px", textAlign: "center" } },
150
150
  },
151
- specials: { text: "Đóng" }, runtime: {},
151
+ specials: { text: "Đóng" },
152
152
  events: [{ id: "ev1", type: "click", action: "close_popup", target: "popthanks" }] },
153
153
  ],
154
154
  },
@@ -23,7 +23,7 @@ ELEMENT NODE (every element)
23
23
  "specials": { ...type-specific CONTENT... }, "runtime": {}, "events": [],
24
24
  "children": [ ... ] } // children ONLY on container types
25
25
  - Cross-cutting config keys apply to EVERY element via the per-breakpoint config (responsive.<bp>.config): sticky/stickyPosition/stickyTop/stickyBottom/stickyLeft/stickyRight/stickyWidth/stickyHeight/stickyUnpinAtSections…, animation, hide, lock. The full per-element specials reference (every renderer-read key, including the rich select/checkbox-group/radio/survey option-object schema) lives in docs/element-specials-reference.md.
26
- - COMPACT AUTHORING (emit FEWER tokens): the server hydrates each element from its type's factory defaults, so you may OMIT boilerplate — \`properties\`, \`runtime\`, empty \`events\`/\`children\`, and each breakpoint's \`config\` (the default animation). Emit only id, type, the meaningful responsive.<bp>.styles for BOTH breakpoints, specials, and events when present. e.g. { "type":"text-block","id":"h1","responsive":{"desktop":{"styles":{"top":120,"left":80,"width":500,"height":70,"fontSize":48,"color":"rgba(20,30,25,1)"}},"mobile":{"styles":{"top":100,"left":20,"width":380,"height":60,"fontSize":32}}},"specials":{"text":"…"} } hydrates into the full node. A complete node still works.
26
+ - COMPACT AUTHORING (emit FEWER tokens): the server hydrates each element from its type's factory defaults, so you may OMIT boilerplate — \`properties\`, \`runtime\`, empty \`events\`/\`children\`, and each breakpoint's \`config\` (the default animation). Emit only id, type, the meaningful responsive.<bp>.styles for BOTH breakpoints, specials, and events when present. e.g. { "type":"text-block","id":"h1","responsive":{"desktop":{"styles":{"top":120,"left":80,"width":500,"height":70,"fontSize":48,"color":"rgba(20,30,25,1)"}},"mobile":{"styles":{"top":100,"left":20,"width":380,"height":60,"fontSize":32}}},"specials":{"text":"…"} } hydrates into the full node. A complete node still works. The whole loop is sparse: get_element skeletons/examples + new_element already come in this shape (copy them as-is), and get_page returns sources COMPACTED the same way — edit and send back without re-adding boilerplate.
27
27
 
28
28
  COORDINATE SYSTEM (critical)
29
29
  - Absolute-positioning canvas (NOT flexbox). Children carry top/left/width/height in px (numbers).
@@ -5,6 +5,7 @@ import { LIBRARY, ELEMENT_TYPES, CONTAINER_TYPES, FIELD_TYPES, createElement } f
5
5
  import { createPageSource } from "./page.js";
6
6
  import { validatePage, coercePage, pageSchema } from "./validate.js";
7
7
  import { expandSource } from "../../core/expand.js";
8
+ import { compactSource } from "../../core/compact.js";
8
9
  /** The payload returned by the get_generation_guide tool. */
9
10
  export const guidePayload = {
10
11
  guide: GENERATION_GUIDE,
@@ -36,5 +37,13 @@ export const landingDomain = {
36
37
  return input; // bad JSON — let validate report it
37
38
  }
38
39
  },
40
+ compact: (input) => {
41
+ try {
42
+ return compactSource(coercePage(input), createElement);
43
+ }
44
+ catch {
45
+ return input; // bad JSON — return as-is
46
+ }
47
+ },
39
48
  schema: pageSchema,
40
49
  };
@@ -24,7 +24,7 @@ RULES (follow for every request):
24
24
  MODEL (essentials):
25
25
  - Top-level: { page:[sections], popup:[popups], dynamic_pages:[], settings:{}, options:{mobileOnly,versionID}, cartConfigs:{isActive:false}, svariations:[] }. Popups are a SEPARATE top-level array, NOT inside page; currency lives in settings.currency (not options). Leave dynamic_pages/svariations as [] for a static page, but keep them on edit round-trips.
26
26
  - Element: { id, type, properties, responsive:{desktop,mobile:{config,styles}}, specials, children, runtime, events }. Absolute canvas: children carry numeric top/left/width/height (px) per breakpoint (canvas width desktop=960, mobile=420); sections own a height.
27
- - COMPACT AUTHORING (emit FEWER tokens — faster, cheaper): the server HYDRATES every element from its type's factory defaults, so OMIT the boilerplate. Send only: id, type, the meaningful responsive.desktop.styles + responsive.mobile.styles (positions/sizes/colors/font — provide BOTH breakpoints), specials (text/src/field_name…), and events ONLY when the element actually has them. You may DROP: properties, runtime, empty events/children, and each breakpoint's config (animation). A full node still works (it's just overlaid on the seed). Applies to create_page, update_page, add_section, validate_page — ~halves the JSON you emit per element.
27
+ - COMPACT AUTHORING (emit FEWER tokens — faster, cheaper): the server HYDRATES every element from its type's factory defaults, so OMIT the boilerplate. Send only: id, type, the meaningful responsive.desktop.styles + responsive.mobile.styles (positions/sizes/colors/font — provide BOTH breakpoints), specials (text/src/field_name…), and events ONLY when the element actually has them. You may DROP: properties, runtime, empty events/children, and each breakpoint's config (animation). A full node still works (it's just overlaid on the seed). Applies to create_page, update_page, add_section, patch_page, validate_page — ~halves the JSON you emit per element. The whole loop is sparse: get_element skeletons/examples and new_element already come in this shape (copy them as-is), and get_page returns sources COMPACTED the same way — edit the compacted tree and send it back without re-adding boilerplate.
28
28
  - CENTERING (the #1 layout defect — do the math, don't eyeball): to center a box compute left = round((canvas - width)/2) — 960 desktop, 420 mobile. textAlign:center only centers text inside the box, not the box itself. For a row of N items, center the whole row block (startLeft = round((canvas - (N*item + (N-1)*gap))/2)). Keep 0 ≤ left and left+width ≤ canvas on each breakpoint.
29
29
  - PAGE MARGIN (one shared axis — fixes the ragged/header-misaligned look): every section AND the header use the SAME column — left edge at 80 desktop / 20 mobile, right edge at 880 / 400 (content width 800 / 380). Header: logo at left=80, CTA right edge at 880 (its left = 880 − width). Never let one band start at left=80 and the next at left=140.
30
30
  - PREMIUM CRAFT (read "sang"): generous whitespace (don't cram; ~48–72px above each band's first element, ≥16–24px between elements); clear type scale (H1 40–56 / body 16–18, big jump); ONE accent used sparingly + neutrals; snap spacing to an 8px grid; reuse the same content width / margin / card+button radius across sections.
package/dist/smoke.js CHANGED
@@ -5,6 +5,7 @@
5
5
  import { createElement, CONTAINER_TYPES, FIELD_TYPES, LIBRARY, ELEMENT_TYPES, ELEMENTS, } from "./domains/landing/elements/index.js";
6
6
  import { validatePage, pageSchema } from "./domains/landing/validate.js";
7
7
  import { expandSource } from "./core/expand.js";
8
+ import { compactSource, deepEq, sparseTemplate } from "./core/compact.js";
8
9
  import { parseHtml } from "./persistence/html-ingest.js";
9
10
  import { readConfig, resolveEnv, ENV_NAMES } from "./persistence/config.js";
10
11
  import { toEditorUrl } from "./persistence/webcake-client.js";
@@ -162,6 +163,35 @@ check("expand preserves provided styles", eTxt.responsive.desktop.styles.fontSiz
162
163
  check("expand keeps id/type/specials", eTxt.id === "t_h1" && eTxt.type === "text-block" && eTxt.specials.text === "Sparse hero", eTxt);
163
164
  check("expanded sparse page validates", validatePage(exp).valid, validatePage(exp).errors);
164
165
  check("expand(full good page) still valid", validatePage(expandSource(good, createElement)).valid);
166
+ console.log("== compact: the inverse of expand (round-trip persists the same tree) ==");
167
+ {
168
+ const cGood = compactSource(good, createElement);
169
+ const cBtn = cGood.page[0].children[0];
170
+ check("compact strips runtime + breakpoint config boilerplate", cBtn.runtime === undefined && cBtn.responsive.desktop.config === undefined, cBtn);
171
+ check("compact keeps real events", Array.isArray(cBtn.events) && cBtn.events.length === 1, cBtn.events);
172
+ check("compact keeps only non-default properties (custom name)", deepEq(cBtn.properties, { name: "CTA" }), cBtn.properties);
173
+ check("compact drops empty popup events/children/specials", cGood.page[1].events === undefined && cGood.page[1].children === undefined && cGood.page[1].specials === undefined, cGood.page[1]);
174
+ check("round-trip: expand(compact(x)) deep-equals expand(x)", deepEq(expandSource(cGood, createElement), expandSource(good, createElement)));
175
+ const cmpSparse = compactSource(exp, createElement); // compact(expand(sparse))
176
+ check("round-trip from sparse: expand(compact(expand(s))) == expand(s)", deepEq(expandSource(cmpSparse, createElement), expandSource(sparse, createElement)));
177
+ check("compact tolerates unknown types (pass-through)", compactSource({ page: [{ id: "x", type: "nope" }] }, createElement).page[0].id === "x");
178
+ }
179
+ console.log("== sparseTemplate: the authoring shape get_element/new_element hand out ==");
180
+ {
181
+ const tplText = sparseTemplate(createElement("text-block"));
182
+ check("template strips properties/runtime/empty events", tplText.properties === undefined && tplText.runtime === undefined && tplText.events === undefined, tplText);
183
+ check("template keeps seeded styles + specials on BOTH breakpoints", tplText.responsive.desktop.styles.width === 200 && tplText.responsive.mobile.styles.width === 200 && tplText.specials.text === "hello world", tplText);
184
+ check("template drops base config (notloaded/animation)", tplText.responsive.desktop.config === undefined, tplText.responsive.desktop);
185
+ const tplList = sparseTemplate(createElement("list-paragraph"));
186
+ check("template keeps non-default seeded config (list icons)", tplList.responsive.desktop.config?.iconSize === 12, tplList.responsive.desktop.config);
187
+ check("template keeps container children", Array.isArray(sparseTemplate(createElement("form")).children));
188
+ const wrapped = {
189
+ page: [{ id: "tsec", type: "section", responsive: { desktop: { styles: { height: 800 } }, mobile: { styles: { height: 800 } } }, children: [{ ...tplText, id: "ttext" }] }],
190
+ settings: { title: "t", description: "d", keywords: "k", lang: "vi" },
191
+ };
192
+ const tr = validatePage(expandSource(wrapped, createElement));
193
+ check("template node expands to a valid page", tr.valid, tr.errors);
194
+ }
165
195
  console.log("== ingest: parseHtml extracts a compact AST ==");
166
196
  const sampleHtml = `<!DOCTYPE html><html lang="en"><head>
167
197
  <title>Brew Coffee</title>
@@ -209,10 +239,12 @@ check("ingest: empty input → warning", (empty.warnings?.length ?? 0) > 0, empt
209
239
  const csr = parseHtml(`<html><head><title>SPA</title></head><body><div id="root"></div></body></html>`);
210
240
  check("ingest: CSR shell → warning", (csr.warnings?.[0] ?? "").includes("client-rendered"), csr.warnings);
211
241
  check("ingest: CSR shell → title still extracted", csr.title === "SPA", csr.title);
212
- console.log("== library: each example validates as a single element subtree ==");
242
+ console.log("== library: each (sparse) example expands to a valid element subtree ==");
213
243
  for (const [type, doc] of Object.entries(LIBRARY)) {
214
244
  if (!doc.example)
215
245
  continue;
246
+ // Examples are authored SPARSE (the shape the model should emit), so they go
247
+ // through expand first — the same path validate_page/create_page take.
216
248
  const wrapped = {
217
249
  page: [
218
250
  {
@@ -227,7 +259,7 @@ for (const [type, doc] of Object.entries(LIBRARY)) {
227
259
  },
228
260
  ],
229
261
  };
230
- const rr = validatePage(wrapped);
262
+ const rr = validatePage(expandSource(wrapped, createElement));
231
263
  check(`example ${type} valid`, rr.valid, rr.errors);
232
264
  }
233
265
  console.log("== schema enum stays in sync with LIBRARY (single source of truth) ==");
@@ -4,17 +4,21 @@
4
4
  * the injected Domain.
5
5
  */
6
6
  import { z } from "zod";
7
+ import { sparseTemplate } from "../core/compact.js";
7
8
  import { text } from "../mcp/response.js";
8
9
  export function registerGenerationTools(server, domain) {
9
10
  // 5) New element ------------------------------------------------------------
10
- server.tool("new_element", "Returns a structurally-valid default element node for a type (correct properties/responsive/specials/sizes), with a fresh id. The caller fills in specials + top/left coordinates.", {
11
+ server.tool("new_element", "Returns a default element node for a type in the SPARSE authoring shape (fresh id, both breakpoints' seeded styles, seeded specials). Emit elements exactly like this — fill in specials + top/left coordinates; OMIT properties/runtime/empty events/config (the server hydrates them from factory defaults on validate/persist).", {
11
12
  type: z.string().describe("Element type to create."),
12
13
  name: z.string().optional().describe("Optional properties.name override (layer label)."),
13
14
  }, { title: "New Element Node", readOnlyHint: true, openWorldHint: false }, async ({ type, name }) => {
14
15
  if (!domain.catalog[type]) {
15
16
  return text({ error: `Unknown element type "${type}".`, valid_types: domain.elementTypes });
16
17
  }
17
- return text(domain.createElement(type, name ? { name } : {}));
18
+ const el = sparseTemplate(domain.createElement(type));
19
+ if (name)
20
+ el.properties = { name };
21
+ return text(el);
18
22
  });
19
23
  // 6) New page skeleton ------------------------------------------------------
20
24
  server.tool("new_page_skeleton", "Returns an empty but complete top-level page source { page:[], popup:[], settings:{...defaults}, options:{...}, cartConfigs:{} } matching the real editor shape.", { mobileOnly: z.boolean().optional().describe("true if the page renders mobile-only.") }, { title: "New Page Skeleton", readOnlyHint: true, openWorldHint: false }, async ({ mobileOnly }) => text(domain.createPageSource({ mobileOnly: mobileOnly ?? false })));
@@ -34,7 +34,7 @@ export function registerPersistenceTools(server, domain) {
34
34
  server.tool("create_page", "Persists a page source to the configured Webcake backend: creates a NEW page and saves the source (source-only — opens in the editor where re-saving renders it). Validates first. DEFAULTS to dry_run=true (returns the HTTP request it WOULD send, token masked); dry_run=false to actually create. The page lands in `organization_id` if given; without an org the page is personal (org=null). Real writes need WEBCAKE_API_BASE + WEBCAKE_JWT.", {
35
35
  source: z
36
36
  .any()
37
- .describe("Full page source { page, popup, settings, options, cartConfigs } (object or JSON string)."),
37
+ .describe("Page source { page, popup, settings, options, cartConfigs } (object or JSON string). Author elements SPARSE — only id, type, responsive.<bp>.styles for BOTH breakpoints, specials, and real events; OMIT properties/runtime/empty events+children/per-breakpoint config — the server hydrates them from factory defaults (a full node also works)."),
38
38
  name: z.string().optional().describe("Page name (default 'AI Page')."),
39
39
  organization_id: z
40
40
  .union([z.string(), z.number()])
@@ -160,18 +160,32 @@ export function registerPersistenceTools(server, domain) {
160
160
  });
161
161
  });
162
162
  // 11) Get page (read source) ------------------------------------------------
163
- server.tool("get_page", "Fetches an existing page's decoded source tree { page, popup, settings, options, cartConfigs } plus name and organization_id. Needs WEBCAKE_API_BASE + WEBCAKE_JWT.", { page_id: z.string().describe("The page id (from list_pages or a URL).") }, { title: "Get Webcake Page Source", readOnlyHint: true, openWorldHint: true }, async ({ page_id }, extra) => {
163
+ server.tool("get_page", "Fetches an existing page's decoded source tree { page, popup, settings, options, cartConfigs } plus name and organization_id. By DEFAULT the source is COMPACTED: boilerplate every element shares (properties/runtime/empty events+children/per-breakpoint config + factory-default style keys) is stripped, leaving the sparse authoring shape edit it and send it back as-is; update_page/patch_page re-hydrate from factory defaults. Pass compact:false for the raw stored tree. Needs WEBCAKE_API_BASE + WEBCAKE_JWT.", {
164
+ page_id: z.string().describe("The page id (from list_pages or a URL)."),
165
+ compact: z
166
+ .boolean()
167
+ .optional()
168
+ .describe("Default TRUE — strip factory-default boilerplate from every element (sparse shape, far fewer tokens). false returns the raw stored tree."),
169
+ }, { title: "Get Webcake Page Source", readOnlyHint: true, openWorldHint: true }, async ({ page_id, compact }, extra) => {
164
170
  const { config, missing } = cfgFor(extra);
165
171
  if (!config)
166
172
  return text({ ok: false, reason: "missing_env", missing_env: missing });
167
- return text(await getPageSource(config, page_id));
173
+ const res = await getPageSource(config, page_id);
174
+ if (!res.ok || compact === false || res.source == null)
175
+ return text(res);
176
+ return text({
177
+ ...res,
178
+ source: domain.compact(res.source),
179
+ compacted: true,
180
+ note: "Source is COMPACTED (factory-default boilerplate stripped). Edit elements in this same sparse shape — keep ids — and send the edited tree back to update_page (or use patch_page for small edits); the server re-hydrates omitted boilerplate.",
181
+ });
168
182
  });
169
183
  // 12) Update page (edit existing) -------------------------------------------
170
184
  server.tool("update_page", "Overwrites an EXISTING page's source with an edited tree (source-only; re-render in the editor for preview/publish). Validates first. DEFAULTS to dry_run=true (preview the request, token masked); dry_run=false to actually save. Needs WEBCAKE_API_BASE + WEBCAKE_JWT.", {
171
185
  page_id: z.string().describe("The page id to update (must be owned by the account)."),
172
186
  source: z
173
187
  .any()
174
- .describe("The full edited page source { page, popup, settings, options, cartConfigs } (object or JSON string)."),
188
+ .describe("The edited page source { page, popup, settings, options, cartConfigs } (object or JSON string). The compacted tree from get_page can be edited and sent back AS-IS — sparse nodes are re-hydrated from factory defaults (a full tree also works)."),
175
189
  dry_run: z.boolean().optional().describe("Default TRUE — preview without sending. Set false to actually save."),
176
190
  }, { title: "Update Webcake Page (Overwrite)", readOnlyHint: false, destructiveHint: true, openWorldHint: true }, async ({ page_id, source, dry_run }, extra) => {
177
191
  const isDry = dry_run !== false;
@@ -243,7 +257,7 @@ export function registerPersistenceTools(server, domain) {
243
257
  page_id: z.string().describe("The page id to append to (from create_page or list_pages; must be owned by the account)."),
244
258
  sections: z
245
259
  .any()
246
- .describe("One section node, or an array of section nodes, to append to the END of `page` (object/array or JSON string). Each is a normal section element { id, type:'section', responsive, children, … } with a UNIQUE id; they stack vertically after the existing sections."),
260
+ .describe("One section node, or an array of section nodes, to append to the END of `page` (object/array or JSON string). Each is a normal section element { id, type:'section', responsive, children, … } with a UNIQUE id; they stack vertically after the existing sections. Author SPARSE nodes — omit properties/runtime/empty events+children/per-breakpoint config; the server hydrates them from factory defaults."),
247
261
  dry_run: z
248
262
  .boolean()
249
263
  .optional()
@@ -441,7 +455,7 @@ export function registerPersistenceTools(server, domain) {
441
455
  draft_id: z.string().optional().describe("Fix a CACHED source from a create_page that failed validation (the create_page error returns draft_id). The patched tree is created as a new page once valid. Provide page_id OR draft_id."),
442
456
  patches: z
443
457
  .any()
444
- .describe("One op object or an array of them (object/array or JSON string). Each targets an element by id: {op:'update',id,type?,specials?,styles?:{desktop?,mobile?},config?:{desktop?,mobile?},events?,properties?} merges fields into the element (op may be omitted; set `type` to fix a wrong element type); {op:'replace',id,element} swaps the node; {op:'remove',id} deletes it; {op:'add',parent_id,element} appends a child to a container."),
458
+ .describe("One op object or an array of them (object/array or JSON string). Each targets an element by id: {op:'update',id,type?,specials?,styles?:{desktop?,mobile?},config?:{desktop?,mobile?},events?,properties?} merges fields into the element (op may be omitted; set `type` to fix a wrong element type); {op:'replace',id,element} swaps the node; {op:'remove',id} deletes it; {op:'add',parent_id,element} appends a child to a container. `element` may be a SPARSE node (id/type/styles/specials/events only) — the server hydrates omitted boilerplate from factory defaults."),
445
459
  dry_run: z
446
460
  .boolean()
447
461
  .optional()
@@ -4,7 +4,9 @@
4
4
  * Schema. All driven by the injected Domain, so they work for any domain.
5
5
  */
6
6
  import { z } from "zod";
7
+ import { sparseTemplate } from "../core/compact.js";
7
8
  import { text } from "../mcp/response.js";
9
+ const SPARSE_NOTE = "Skeletons and examples are in the SPARSE authoring shape — emit elements exactly like this (id, type, BOTH breakpoints' styles, specials, real events). OMIT properties/runtime/empty events+children/config: the server hydrates them from factory defaults on validate/persist.";
8
10
  export function registerReferenceTools(server, domain) {
9
11
  // 1) Generation guide -------------------------------------------------------
10
12
  server.tool("get_generation_guide", "Returns the page-building conventions reference: output shape, the absolute-positioning coordinate system, event vocabulary, and the recommended workflow.", { title: "Get Generation Guide", readOnlyHint: true, openWorldHint: false }, async () => text(domain.guide));
@@ -23,7 +25,7 @@ export function registerReferenceTools(server, domain) {
23
25
  return text({ total: domain.elementTypes.length, categories: byCategory });
24
26
  });
25
27
  // 3) Get element ------------------------------------------------------------
26
- server.tool("get_element", "Returns detailed usage for one element type — or for many in a single call (BATCH MODE): summary, when to use it, key `specials` fields, a default skeleton node, and (for common types) a filled example. Pass `types: [...]` to fetch a whole section's worth of element types at once (e.g. ['section','text-block','image-block','button']) — returns { elements: { [type]: details } } and saves a round-trip per type. `type` (single) returns the doc directly for backward compatibility.", {
28
+ server.tool("get_element", "Returns detailed usage for one element type — or for many in a single call (BATCH MODE): summary, when to use it, key `specials` fields, a SPARSE skeleton node (the exact shape to emit — the server hydrates omitted boilerplate), and (for common types) a filled example. Pass `types: [...]` to fetch a whole section's worth of element types at once (e.g. ['section','text-block','image-block','button']) — returns { elements: { [type]: details } } and saves a round-trip per type. `type` (single) returns the doc directly for backward compatibility.", {
27
29
  type: z.string().optional().describe("Single element type — backward-compat. Prefer `types` when fetching more than one."),
28
30
  types: z
29
31
  .array(z.string())
@@ -49,7 +51,7 @@ export function registerReferenceTools(server, domain) {
49
51
  summary: doc.summary,
50
52
  useWhen: doc.useWhen,
51
53
  keySpecials: doc.keySpecials,
52
- skeleton: domain.createElement(t),
54
+ skeleton: sparseTemplate(domain.createElement(t)),
53
55
  example: doc.example ?? null,
54
56
  };
55
57
  }
@@ -57,9 +59,10 @@ export function registerReferenceTools(server, domain) {
57
59
  if (!types && type) {
58
60
  if (unknown.length)
59
61
  return text({ error: `Unknown element type "${unknown[0]}".`, valid_types: domain.elementTypes });
60
- return text(elements[type]);
62
+ return text({ ...elements[type], authoring: SPARSE_NOTE });
61
63
  }
62
64
  return text({
65
+ authoring: SPARSE_NOTE,
63
66
  elements,
64
67
  unknown: unknown.length ? unknown : undefined,
65
68
  valid_types: unknown.length ? domain.elementTypes : undefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webcake-landing-mcp",
3
- "version": "1.0.48",
3
+ "version": "1.0.49",
4
4
  "description": "MCP server exposing Webcake landing-page element schemas + AI usage hints, and persisting LLM-generated page sources to a Webcake backend.",
5
5
  "mcpName": "io.github.vuluu2k/webcake-landing-mcp",
6
6
  "type": "module",