webcake-storefront-mcp 1.42.0 → 2.1.0
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 +2 -2
- package/README.vi.md +2 -2
- package/dist/api-catalog.generated.json +165 -265
- package/dist/api.js +0 -425
- package/dist/builder/native-first.js +7 -4
- package/dist/builder/page-code.js +150 -0
- package/dist/changelog.json +14 -14
- package/dist/server.js +2 -0
- package/dist/tools/api-gateway.js +24 -4
- package/dist/tools/appointment.js +5 -49
- package/dist/tools/apps-extra.js +0 -28
- package/dist/tools/apps.js +0 -11
- package/dist/tools/builder.js +20 -2
- package/dist/tools/cms-files.js +2 -10
- package/dist/tools/families.js +132 -0
- package/dist/tools/marketing.js +0 -45
- package/dist/tools/multilingual.js +0 -16
- package/dist/tools/orders.js +0 -1
- package/dist/tools/page-code.js +114 -0
- package/dist/tools/pages.js +14 -11
- package/dist/tools/products.js +0 -5
- package/dist/tools/registry.js +48 -23
- package/dist/tools/retired-tools.json +141 -0
- package/dist/tools/reviews.js +0 -5
- package/dist/tools/site-config.js +0 -78
- package/dist/web-guide.js +1 -1
- package/package.json +1 -1
- package/dist/tools/affiliate.js +0 -27
- package/dist/tools/catalog-extras.js +0 -88
- package/dist/tools/media.js +0 -39
- package/dist/tools/sale-channels.js +0 -45
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Custom code of ONE page — page.settings.custom_code, the same four slots as the site's code.
|
|
2
|
+
// builderx_api (PageUtils.get_page_custom_code) renders it after the site's code on that page
|
|
3
|
+
// only: CSS/head code in <head>, body code after <body>, JS in its own <script> at the end, so a
|
|
4
|
+
// broken page script can't take the site script down with it. Settings are copied to the
|
|
5
|
+
// published page on publish_site; the preview reads them straight away.
|
|
6
|
+
import { Script } from "node:vm";
|
|
7
|
+
import { SITE_CODE_FIELDS } from "./native-first.js";
|
|
8
|
+
export const PAGE_CODE_FIELDS = SITE_CODE_FIELDS;
|
|
9
|
+
/** Per page, in chars. Above `soft` a write must name its native gap; past `hard` it is refused. */
|
|
10
|
+
export const PAGE_CODE_BUDGET = {
|
|
11
|
+
script: { soft: 15_000, hard: 50_000 },
|
|
12
|
+
css: { soft: 10_000, hard: 30_000 },
|
|
13
|
+
};
|
|
14
|
+
export const PAGE_CODE_GUIDE = `## Per-page custom code (last resort — NATIVE FIRST still applies)
|
|
15
|
+
Use it when the element schema can't express what the user asked for ON THIS PAGE ONLY (a landing
|
|
16
|
+
page's one-off animation, a calculator that writes into native elements, a tracking event for this
|
|
17
|
+
page). Anything every page needs belongs in the site code (update_site_custom_code); anything an
|
|
18
|
+
element setting can do belongs in that setting.
|
|
19
|
+
Slots (rendered on this page only, after the site's code):
|
|
20
|
+
- code_custom_css — CSS, wrapped in <style> for you. Target #ELEMENT-ID (ids from targets) or a
|
|
21
|
+
specials.custom_class you set on a native element. Media queries: match the site breakpoints.
|
|
22
|
+
- code_custom_javascript — plain JS, NO <script> tag (it gets its own). Runs at the end of <body>,
|
|
23
|
+
after the page's HTML exists; content loaded later (product grids, carts) needs a
|
|
24
|
+
MutationObserver or a retry. Wrap in an IIFE; never document.write.
|
|
25
|
+
- code_before_head — <script src>/<link>/<meta> for this page (e.g. a library only this page uses).
|
|
26
|
+
- code_before_body — markup after the page's content, before its scripts (same spot as the
|
|
27
|
+
site's code_before_body): a noscript pixel, a mount point for a widget.
|
|
28
|
+
Rules: write into native elements (textContent, classList) instead of building UI in JS; data comes
|
|
29
|
+
from a collection / HTTP function (webcake-fn), never hard-coded lists. Syntax is checked before
|
|
30
|
+
saving; #ids that aren't on the page are flagged. Preview right away; publish_site to go live.`;
|
|
31
|
+
/** The page's custom code from its settings (object or JSON string), only known slots, only strings. */
|
|
32
|
+
export function readPageCode(settings) {
|
|
33
|
+
let s = settings;
|
|
34
|
+
if (typeof s === "string") {
|
|
35
|
+
try {
|
|
36
|
+
s = JSON.parse(s);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
s = null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const code = s && typeof s === "object" ? s.custom_code : null;
|
|
43
|
+
const out = {};
|
|
44
|
+
if (code && typeof code === "object")
|
|
45
|
+
for (const f of PAGE_CODE_FIELDS)
|
|
46
|
+
if (typeof code[f] === "string" && code[f].trim())
|
|
47
|
+
out[f] = code[f];
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** Merge an edit into the current code. `append` adds after what is there; "" clears a slot.
|
|
51
|
+
* A <script> wrapper around code_custom_javascript is removed (the renderer adds its own). */
|
|
52
|
+
export function mergePageCode(before, input, mode = "replace") {
|
|
53
|
+
const after = { ...before };
|
|
54
|
+
const notes = [];
|
|
55
|
+
for (const f of PAGE_CODE_FIELDS) {
|
|
56
|
+
let v = input[f];
|
|
57
|
+
if (v === undefined)
|
|
58
|
+
continue;
|
|
59
|
+
if (f === "code_custom_javascript") {
|
|
60
|
+
const m = /^\s*<script\b[^>]*>([\s\S]*)<\/script>\s*$/i.exec(v);
|
|
61
|
+
if (m && !/<script\b/i.test(m[1])) {
|
|
62
|
+
v = m[1].trim();
|
|
63
|
+
notes.push("code_custom_javascript: removed the <script> wrapper — the page renders its own tag.");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const next = mode === "append" && before[f] && v ? `${before[f]}\n${v}` : v;
|
|
67
|
+
if (next.trim())
|
|
68
|
+
after[f] = next;
|
|
69
|
+
else
|
|
70
|
+
delete after[f];
|
|
71
|
+
}
|
|
72
|
+
return { after, notes };
|
|
73
|
+
}
|
|
74
|
+
const ELEMENT_ID = /^[A-Z][A-Z0-9]*(?:-[A-Z0-9]+)*-[A-Za-z0-9]{6,}$/;
|
|
75
|
+
/** Syntax and target checks. errors block the save (a syntax error kills the page's script);
|
|
76
|
+
* warnings point at selectors that match nothing on the page. */
|
|
77
|
+
export function lintPageCode(code, pageIds) {
|
|
78
|
+
const errors = [];
|
|
79
|
+
const warnings = [];
|
|
80
|
+
const compile = (src, where) => {
|
|
81
|
+
try {
|
|
82
|
+
new Script(src, { filename: where });
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
const line = /:(\d+)/.exec(String(e?.stack || ""))?.[1];
|
|
86
|
+
errors.push(`${where}: ${e?.name || "SyntaxError"}: ${e?.message}${line ? ` (line ${line})` : ""} — the whole script would fail to run.`);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
if (code.code_custom_javascript)
|
|
90
|
+
compile(code.code_custom_javascript, "code_custom_javascript");
|
|
91
|
+
for (const f of ["code_before_head", "code_before_body"]) {
|
|
92
|
+
const html = code[f];
|
|
93
|
+
if (!html)
|
|
94
|
+
continue;
|
|
95
|
+
let i = 0;
|
|
96
|
+
for (const m of html.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)) {
|
|
97
|
+
i++;
|
|
98
|
+
if (/\bsrc\s*=/.test(m[1]) || /type\s*=\s*["']?(?!text\/javascript|module|application\/javascript)[^"'\s>]+/i.test(m[1]))
|
|
99
|
+
continue;
|
|
100
|
+
if (m[2].trim())
|
|
101
|
+
compile(m[2], `${f} <script> #${i}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const css = code.code_custom_css;
|
|
105
|
+
if (css) {
|
|
106
|
+
const body = css.replace(/^\s*<style[^>]*>|<\/style>\s*$/gi, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
107
|
+
let depth = 0;
|
|
108
|
+
for (const ch of body) {
|
|
109
|
+
if (ch === "{")
|
|
110
|
+
depth++;
|
|
111
|
+
else if (ch === "}" && --depth < 0)
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
if (depth !== 0)
|
|
115
|
+
errors.push(`code_custom_css: unbalanced braces (${depth > 0 ? "missing }" : "extra }"}) — every rule after it would be dropped.`);
|
|
116
|
+
}
|
|
117
|
+
// Element ids used as selectors / getElementById that aren't on this page.
|
|
118
|
+
const used = new Set();
|
|
119
|
+
const all = PAGE_CODE_FIELDS.map((f) => code[f] || "").join("\n");
|
|
120
|
+
for (const m of all.matchAll(/#([A-Za-z][\w-]*)|getElementById\(\s*["'`]([\w-]+)["'`]\s*\)/g)) {
|
|
121
|
+
const id = m[1] || m[2];
|
|
122
|
+
if (ELEMENT_ID.test(id))
|
|
123
|
+
used.add(id);
|
|
124
|
+
}
|
|
125
|
+
const missing = [...used].filter((id) => !pageIds.has(id));
|
|
126
|
+
if (missing.length)
|
|
127
|
+
warnings.push(`No element with id ${missing.slice(0, 8).map((x) => `#${x}`).join(", ")} on this page — the rule/script will match nothing. Pick ids from targets.`);
|
|
128
|
+
return { errors, warnings };
|
|
129
|
+
}
|
|
130
|
+
/** What code can aim at on this page: every node's id, type, custom_class (compact, capped). */
|
|
131
|
+
export function codeTargets(source, limit = 300) {
|
|
132
|
+
const out = [];
|
|
133
|
+
const ids = new Set();
|
|
134
|
+
const walk = (n) => {
|
|
135
|
+
if (!n || typeof n !== "object")
|
|
136
|
+
return;
|
|
137
|
+
if (n.id) {
|
|
138
|
+
ids.add(n.id);
|
|
139
|
+
if (out.length < limit) {
|
|
140
|
+
const cls = n.specials?.custom_class ? ` .${String(n.specials.custom_class).trim().split(/\s+/).join(".")}` : "";
|
|
141
|
+
out.push(`#${n.id} ${n.type || "?"}${cls}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const c of Array.isArray(n.children) ? n.children : [])
|
|
145
|
+
walk(c);
|
|
146
|
+
};
|
|
147
|
+
for (const s of Array.isArray(source?.sections) ? source.sections : [])
|
|
148
|
+
walk(s);
|
|
149
|
+
return { targets: out, ids, total: ids.size, truncated: ids.size > out.length };
|
|
150
|
+
}
|
package/dist/changelog.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "2.1.0",
|
|
4
|
+
"d": "19/11/2026",
|
|
5
|
+
"type": "Added",
|
|
6
|
+
"en": "New get_page_custom_code and update_page_custom_code tools (family site_code) read and write custom code for ONE page — code_custom_css,…",
|
|
7
|
+
"vi": "Hai tool mới get_page_custom_code và update_page_custom_code (nhóm site_code) đọc và ghi custom code cho MỘT trang — code_custom_css,…"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"v": "2.0.0",
|
|
11
|
+
"d": "19/11/2026",
|
|
12
|
+
"type": "Added",
|
|
13
|
+
"en": "18 new domain tools (page, page_element, page_draft, compose, builder_ref, global_source, global_section, site_code, theme, product,…",
|
|
14
|
+
"vi": "18 tool theo domain mới (page, page_element, page_draft, compose, builder_ref, global_source, global_section, site_code, theme, product,…"
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"v": "1.42.0",
|
|
4
18
|
"d": "19/11/2026",
|
|
@@ -26,19 +40,5 @@
|
|
|
26
40
|
"type": "Added",
|
|
27
41
|
"en": "New preview_page tool screenshots the saved (unpublished) draft at desktop and mobile widths through the editor's own preview host, so a page can be…",
|
|
28
42
|
"vi": "Tool mới preview_page chụp ảnh bản nháp đã lưu (chưa publish) ở cả độ rộng máy tính và điện thoại qua host xem trước của chính editor, nhờ đó có thể…"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"v": "1.38.0",
|
|
32
|
-
"d": "05/11/2026",
|
|
33
|
-
"type": "Changed",
|
|
34
|
-
"en": "The install command no longer asks any questions: it opens the prod browser connect page and configures every AI app it detects on the machine…",
|
|
35
|
-
"vi": "Lệnh install nay không còn hỏi gì: mở thẳng trang kết nối prod trên trình duyệt và ghi cấu hình vào mọi ứng dụng AI phát hiện được trên máy (Claude…"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"v": "1.37.0",
|
|
39
|
-
"d": "04/11/2026",
|
|
40
|
-
"type": "Added",
|
|
41
|
-
"en": "A new native-first guide is now injected into get_build_guide's build guide, get_http_function's and get_site_custom_code's custom-code guide, and…",
|
|
42
|
-
"vi": "Hướng dẫn \"native first\" mới nay được chèn vào build guide của get_build_guide, custom-code guide của get_http_function và get_site_custom_code,…"
|
|
43
43
|
}
|
|
44
44
|
]
|
package/dist/server.js
CHANGED
|
@@ -16,6 +16,8 @@ const INSTRUCTIONS = `You are an AI assistant connected to the WebCake/StoreCake
|
|
|
16
16
|
|
|
17
17
|
IMPORTANT: When the user asks ANY question about their website, store, products, orders, pages, or code — you MUST use the available tools to look up real data before answering. Never guess.
|
|
18
18
|
|
|
19
|
+
Tool families: most tools are grouped by domain (page, page_element, page_draft, compose, builder_ref, global_source, global_section, site_code, theme, product, product_category, promotion, order, blog, collection, cms_function, app, cached_result). Each runs its operations by \`action\`, and the action names are the tool names the guides use — "call new_section" means compose({ action: "new_section", … }), "create_product" means product({ action: "create_product", … }). help:true on any action returns its full documentation and schema.
|
|
20
|
+
|
|
19
21
|
Tool discovery: the common tools (pages, builder, products, orders, blog, customers, apps, publishing) are loaded directly. MANY more capabilities are available on demand — marketing/CRM (email, contacts, subscribers, employees), translations, media library, appointments, affiliate, product reviews, custom domains / SEO redirects / shipping, brands / tags / ribbons / materials, courses, sale channels, automation, and more. If you don't see a directly-loaded tool for the task, call search_tools("keywords") to find it, then run it with invoke_read_tool(name, arguments) if it only reads (list_/get_/search_…), otherwise invoke_tool(name, arguments). Use list_tool_groups to see everything available. If NO tool covers it, the whole backend API is reachable: api_find("keywords") → api_get (reads) / api_call (writes, dry_run first).
|
|
20
22
|
|
|
21
23
|
You can also BUILD pages: use get_build_guide, list_elements, get_element to learn the BuilderX component model, new_section/new_element to compose, validate_page to check, then build_page (dry_run first) to create. Publishing is site-level via publish_site.
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
// (settings merge, page-source validation, native-first, CMS tokens, by_ai…).
|
|
6
6
|
import { readFileSync } from "node:fs";
|
|
7
7
|
import { z } from "zod";
|
|
8
|
+
import { FAMILY_OF } from "./families.js";
|
|
9
|
+
/** How to call a dedicated tool: family members run as an action. */
|
|
10
|
+
const callName = (t) => (FAMILY_OF[t] ? `${FAMILY_OF[t]}{action:"${t}"}` : t);
|
|
8
11
|
let CATALOG = { meta: {}, ops: [] };
|
|
9
12
|
try {
|
|
10
13
|
CATALOG = JSON.parse(readFileSync(new URL("../api-catalog.generated.json", import.meta.url), "utf8"));
|
|
@@ -25,7 +28,7 @@ const words = (s) => s.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase().split(/
|
|
|
25
28
|
export function opLine(o) {
|
|
26
29
|
const keys = o.params ? Object.keys(o.params) : [];
|
|
27
30
|
const shown = keys.slice(0, 6).map((k) => (o.required?.includes(k) ? `${k}*` : k));
|
|
28
|
-
return `${o.id} — ${o.handler}${shown.length ? ` (${shown.join(", ")}${keys.length > 6 ? ", …" : ""})` : ""}${o.tools ? ` ⇒ tool: ${o.tools.slice(0, 3).join(", ")}` : ""}`;
|
|
31
|
+
return `${o.id} — ${o.handler}${shown.length ? ` (${shown.join(", ")}${keys.length > 6 ? ", …" : ""})` : ""}${o.tools ? ` ⇒ tool: ${o.tools.slice(0, 3).map(callName).join(", ")}` : ""}`;
|
|
29
32
|
}
|
|
30
33
|
export function searchOps(query, limit = 15, method) {
|
|
31
34
|
const terms = words(query);
|
|
@@ -66,11 +69,28 @@ export function describeOp(o) {
|
|
|
66
69
|
...(o.required ? { required: o.required } : {}),
|
|
67
70
|
...(o.perms ? { needs_permission: o.perms } : {}),
|
|
68
71
|
...(o.tools
|
|
69
|
-
? { prefer_tool: o.tools, note: o.method === "GET" ? "A dedicated tool covers this route and returns a cleaner result." : "Writes to this route go through the dedicated tool (it carries the guards); api_call refuses them." }
|
|
72
|
+
? { prefer_tool: o.tools.map(callName), note: o.method === "GET" ? "A dedicated tool covers this route and returns a cleaner result." : "Writes to this route go through the dedicated tool (it carries the guards); api_call refuses them." }
|
|
70
73
|
: {}),
|
|
71
74
|
...(DENY[o.id] ? { refused: DENY[o.id] } : {}),
|
|
72
75
|
};
|
|
73
76
|
}
|
|
77
|
+
// Never hand a secret to the model: values under these keys are replaced in every result
|
|
78
|
+
// (a dedicated tool used to whitelist them; the generic gateway has to do it itself).
|
|
79
|
+
const SECRET_KEY = /secret|passw|token|api_?key|private_?key|access_?key|hash_?key|checksum|signature|credential|webhook_key|qr_data/i;
|
|
80
|
+
/** On a route that hands out credentials (…/token, …/api_key), a bare `key` is the secret too. */
|
|
81
|
+
const SECRET_ROUTE = /token|api_key|secret|credential/i;
|
|
82
|
+
export function redactSecrets(v, secretRoute = false, depth = 0) {
|
|
83
|
+
if (depth > 12 || v === null || typeof v !== "object")
|
|
84
|
+
return v;
|
|
85
|
+
if (Array.isArray(v))
|
|
86
|
+
return v.map((x) => redactSecrets(x, secretRoute, depth + 1));
|
|
87
|
+
const out = {};
|
|
88
|
+
for (const [k, x] of Object.entries(v)) {
|
|
89
|
+
const secret = SECRET_KEY.test(k) || (secretRoute && /^(key|value)$/.test(k));
|
|
90
|
+
out[k] = secret && x !== null && x !== "" && typeof x !== "boolean" && typeof x !== "object" ? "[redacted]" : redactSecrets(x, secretRoute, depth + 1);
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
74
94
|
const LIST_KEYS = ["data", "items", "products", "orders", "customers", "articles", "results", "list", "records", "entries"];
|
|
75
95
|
/** Trim a response for the model: keep `pick` fields per item, cap list length. */
|
|
76
96
|
export function trimResult(res, pick, maxItems = 50) {
|
|
@@ -122,7 +142,7 @@ export function registerApiGatewayTools(server, api, handle) {
|
|
|
122
142
|
if (DENY[o.id])
|
|
123
143
|
throw new Error(`Refused: ${DENY[o.id]}.`);
|
|
124
144
|
if (o.method !== "GET" && o.tools)
|
|
125
|
-
throw new Error(`Refused: ${o.id} is written through ${o.tools.join(" / ")} — that tool validates and guards this write. Use it instead.`);
|
|
145
|
+
throw new Error(`Refused: ${o.id} is written through ${o.tools.map(callName).join(" / ")} — that tool validates and guards this write. Use it instead.`);
|
|
126
146
|
const params = { ...(args.path_params || {}) };
|
|
127
147
|
if (params.site_id == null && pathParams(o.path).includes("site_id")) {
|
|
128
148
|
if (!api.siteId)
|
|
@@ -153,7 +173,7 @@ export function registerApiGatewayTools(server, api, handle) {
|
|
|
153
173
|
const msg = e?.message || String(e);
|
|
154
174
|
throw new Error(/API 403/.test(msg) && o.perms ? `${msg} — needs site permission ${o.perms.join(" / ")}.` : msg);
|
|
155
175
|
}
|
|
156
|
-
const out = trimResult(res, args.pick, args.max_items ?? 50);
|
|
176
|
+
const out = trimResult(redactSecrets(res, SECRET_ROUTE.test(o.path)), args.pick, args.max_items ?? 50);
|
|
157
177
|
const text = JSON.stringify(out);
|
|
158
178
|
return {
|
|
159
179
|
...(unknown.length ? { unknown_keys: unknown } : {}),
|
|
@@ -39,16 +39,13 @@ export function registerAppointmentTools(server, api, handle) {
|
|
|
39
39
|
term: z.string().optional().describe("Search term"),
|
|
40
40
|
};
|
|
41
41
|
const unwrap = (res, key) => res?.data?.[key] ?? res?.[key] ?? res?.data ?? res;
|
|
42
|
-
// ── Calendars ──
|
|
43
|
-
server.tool("list_appointment_calendars", "List booking calendars (services with availability rules) for the current site.", listShape, (query) => handle(async () => unwrap(await api.listAppointmentCalendars(query), "appointment_calendars")));
|
|
44
42
|
server.tool("create_appointment_calendar", `Create a booking calendar = ONE employee's (technician's) working schedule. A calendar is per
|
|
45
43
|
employee, not per service: one employee has at most one calendar per site, tied to one address.
|
|
46
|
-
To set up staff schedules:
|
|
47
|
-
|
|
48
|
-
Same hours for many staff? Create one, then duplicate_appointment_calendars and change assignee_id.`, {
|
|
44
|
+
To set up staff schedules: employees, addresses and classifies (services) come first — api_find("appointment employee" / "appointment address" / "appointment classify") → api_get / api_call — then one calendar per employee with its own hours.
|
|
45
|
+
Same hours for many staff? Create one, then duplicate it (api_find "appointment calendar duplicate") and change assignee_id.`, {
|
|
49
46
|
name: z.string().describe("Calendar title, e.g. the technician's name"),
|
|
50
|
-
assignee_id: z.string().describe("Employee id (
|
|
51
|
-
appointment_address_id: z.string().describe("Address/location id (
|
|
47
|
+
assignee_id: z.string().describe("Employee id (api_find 'appointment employee') — one calendar per employee"),
|
|
48
|
+
appointment_address_id: z.string().describe("Address/location id (api_find 'appointment address')"),
|
|
52
49
|
appointment_classifies: z.array(z.object({ id: z.string() })).optional().describe('Services this employee takes, e.g. [{ "id": "..." }]'),
|
|
53
50
|
range_appointment: z.number().int().min(1).max(60).optional().describe("How many days ahead customers can book, 1–60 (default 7)"),
|
|
54
51
|
duration_appointment: z.number().int().optional().describe("Appointment length in minutes; also the slot step (default 30)"),
|
|
@@ -73,49 +70,8 @@ Same hours for many staff? Create one, then duplicate_appointment_calendars and
|
|
|
73
70
|
}));
|
|
74
71
|
server.tool("update_appointment_calendar", `Update a booking calendar (an employee's schedule). Pass \`id\` plus any fields to change, same shape
|
|
75
72
|
as create_appointment_calendar. config_weekdays / config_days REPLACE the whole list — to add one
|
|
76
|
-
day-off, read the calendar (
|
|
73
|
+
day-off, read the calendar (api_find "appointment calendar" → api_get), append, and send the full config_days.`, {
|
|
77
74
|
id: z.string().describe("Calendar id"),
|
|
78
75
|
fields: z.record(z.any()).describe("Fields to update (name, config_weekdays, config_days, assignee_id, appointment_classifies, …)"),
|
|
79
76
|
}, ({ id, fields }) => handle(async () => unwrap(await api.updateAppointmentCalendar({ id, ...normalizeHours(fields) }), "appointment_calendar")));
|
|
80
|
-
server.tool("delete_appointment_calendars", "Delete booking calendars by id.", { ids: z.array(z.string()).min(1).describe("Calendar ids") }, ({ ids }) => handle(() => api.deleteAppointmentCalendars(ids)));
|
|
81
|
-
server.tool("duplicate_appointment_calendars", "Duplicate booking calendars by id (creates copies).", { ids: z.array(z.string()).min(1).describe("Calendar ids to duplicate") }, ({ ids }) => handle(() => api.duplicateAppointmentCalendars(ids)));
|
|
82
|
-
// ── Appointments (bookings) ──
|
|
83
|
-
server.tool("list_appointments", "List booked appointments for the current site.", listShape, (query) => handle(async () => unwrap(await api.listAppointments(query), "appointments")));
|
|
84
|
-
// ── Addresses (locations) ──
|
|
85
|
-
server.tool("list_appointment_addresses", "List appointment locations/addresses.", listShape, (query) => handle(async () => unwrap(await api.listAppointmentAddresses(query), "appointment_addresses")));
|
|
86
|
-
server.tool("create_appointment_address", "Create an appointment location. Region ids are optional (Vietnamese geo ids).", {
|
|
87
|
-
address: z.string().describe("Street / full address text"),
|
|
88
|
-
province_id: z.string().optional().describe("Province geo id"),
|
|
89
|
-
district_id: z.string().optional().describe("District geo id"),
|
|
90
|
-
commune_id: z.string().optional().describe("Commune/ward geo id"),
|
|
91
|
-
}, (fields) => handle(async () => unwrap(await api.createAppointmentAddress(fields), "appointment_address")));
|
|
92
|
-
server.tool("update_appointment_address", "Update an appointment location. Pass `id` plus fields to change.", {
|
|
93
|
-
id: z.string().describe("Address id"),
|
|
94
|
-
fields: z.record(z.any()).describe("Fields to update (address, province_id, district_id, commune_id)"),
|
|
95
|
-
}, ({ id, fields }) => handle(async () => unwrap(await api.updateAppointmentAddress({ id, ...fields }), "appointment_address")));
|
|
96
|
-
server.tool("delete_appointment_addresses", "Delete appointment locations by id.", { ids: z.array(z.string()).min(1).describe("Address ids") }, ({ ids }) => handle(() => api.deleteAppointmentAddresses(ids)));
|
|
97
|
-
// ── Classifies (service types) ──
|
|
98
|
-
server.tool("list_appointment_classifies", "List appointment classifies (service categories/types).", listShape, (query) => handle(async () => unwrap(await api.listAppointmentClassifies(query), "appointment_classifies")));
|
|
99
|
-
server.tool("create_appointment_classify", "Create an appointment classify (service type).", {
|
|
100
|
-
name: z.string().describe("Classify name"),
|
|
101
|
-
description: z.string().optional().describe("Optional description"),
|
|
102
|
-
}, (fields) => handle(async () => unwrap(await api.createAppointmentClassify(fields), "appointment_classify")));
|
|
103
|
-
server.tool("update_appointment_classify", "Update an appointment classify. Pass `id` plus fields to change.", {
|
|
104
|
-
id: z.string().describe("Classify id"),
|
|
105
|
-
fields: z.record(z.any()).describe("Fields to update (name, description)"),
|
|
106
|
-
}, ({ id, fields }) => handle(async () => unwrap(await api.updateAppointmentClassify({ id, ...fields }), "appointment_classify")));
|
|
107
|
-
server.tool("delete_appointment_classifies", "Delete appointment classifies by id.", { ids: z.array(z.string()).min(1).describe("Classify ids") }, ({ ids }) => handle(() => api.deleteAppointmentClassifies(ids)));
|
|
108
|
-
// ── Employees (assignees) ──
|
|
109
|
-
server.tool("list_appointment_employees", "List appointment employees (people that appointments can be assigned to).", listShape, (query) => handle(async () => unwrap(await api.listAppointmentEmployees(query), "appointment_employees")));
|
|
110
|
-
server.tool("create_appointment_employee", "Create an appointment employee (assignee).", {
|
|
111
|
-
full_name: z.string().describe("Employee full name"),
|
|
112
|
-
email: z.string().optional().describe("Email"),
|
|
113
|
-
phone_number: z.string().optional().describe("Phone number"),
|
|
114
|
-
avatar: z.string().optional().describe("Avatar image URL"),
|
|
115
|
-
}, (fields) => handle(async () => unwrap(await api.createAppointmentEmployee(fields), "appointment_employee")));
|
|
116
|
-
server.tool("update_appointment_employee", "Update an appointment employee. Pass `id` plus fields to change.", {
|
|
117
|
-
id: z.string().describe("Employee id"),
|
|
118
|
-
fields: z.record(z.any()).describe("Fields to update (full_name, email, phone_number, avatar)"),
|
|
119
|
-
}, ({ id, fields }) => handle(async () => unwrap(await api.updateAppointmentEmployee({ id, ...fields }), "appointment_employee")));
|
|
120
|
-
server.tool("delete_appointment_employees", "Delete appointment employees by id.", { ids: z.array(z.string()).min(1).describe("Employee ids") }, ({ ids }) => handle(() => api.deleteAppointmentEmployees(ids)));
|
|
121
77
|
}
|
package/dist/tools/apps-extra.js
CHANGED
|
@@ -3,25 +3,6 @@ import { z } from "zod";
|
|
|
3
3
|
// (per-variation print templates), and the Course app. Each requires its app installed.
|
|
4
4
|
export function registerAppsExtraTools(server, api, handle) {
|
|
5
5
|
const unwrap = (res, key) => (key && (res?.data?.[key] ?? res?.[key])) ?? res?.data ?? res;
|
|
6
|
-
// ── Product Design ──
|
|
7
|
-
server.tool("get_device_templates", "Get the device-template groups for the Product Design app.", {}, () => handle(async () => unwrap(await api.getDeviceTemplates(), "group_device")));
|
|
8
|
-
server.tool("create_products_from_device_templates", "Create products from selected device-template groups (Product Design app).", { groups: z.array(z.string()).min(1).describe("Device-template group identifiers") }, ({ groups }) => handle(async () => unwrap(await api.createProductsByDeviceTemplate(groups), "device_templates")));
|
|
9
|
-
// ── Personal Product Design (PPD) ──
|
|
10
|
-
server.tool("list_ppd", "List Personal Product Design assignments (products enabled for personalization).", {
|
|
11
|
-
page: z.number().optional().describe("Page number"),
|
|
12
|
-
limit: z.number().optional().describe("Items per page"),
|
|
13
|
-
term: z.string().optional().describe("Search by product name"),
|
|
14
|
-
}, (query) => handle(async () => unwrap(await api.getAllPpd(query), "result")));
|
|
15
|
-
server.tool("upsert_ppd", "Enable/update Personal Product Design for products (bulk).", { ppds: z.array(z.record(z.any())).min(1).describe("PPD entries, e.g. [{ product_id }]") }, ({ ppds }) => handle(() => api.upsertPpd(ppds)));
|
|
16
|
-
server.tool("remove_ppd", "Disable Personal Product Design for the given ids.", { ids: z.array(z.string()).min(1).describe("PPD ids") }, ({ ids }) => handle(() => api.removePpd(ids)));
|
|
17
|
-
server.tool("get_ppd_variation_template", "Get the per-variation print/design templates for a product (PPD app).", { product_id: z.string().describe("Product id") }, ({ product_id }) => handle(async () => unwrap(await api.getProductVariationTemplate(product_id), "result")));
|
|
18
|
-
// ── Course app ──
|
|
19
|
-
server.tool("list_courses", "List courses (Course app).", {
|
|
20
|
-
page: z.number().optional().describe("Page number"),
|
|
21
|
-
limit: z.number().optional().describe("Items per page"),
|
|
22
|
-
term: z.string().optional().describe("Search term"),
|
|
23
|
-
}, (query) => handle(async () => unwrap(await api.listCourses(query))));
|
|
24
|
-
server.tool("get_course", "Get a course by id (tracks, downloads, etc.).", { id: z.string().describe("Course id") }, ({ id }) => handle(async () => unwrap(await api.getCourse(id))));
|
|
25
6
|
server.tool("create_course", `Create a course linked to a product. \`tracks\` are lessons; \`file_downloads\` are attachments.
|
|
26
7
|
Note: video tracks trigger async HLS processing. A product can only link to one course.`, {
|
|
27
8
|
name: z.string().describe("Course name"),
|
|
@@ -32,13 +13,4 @@ Note: video tracks trigger async HLS processing. A product can only link to one
|
|
|
32
13
|
file_downloads: z.array(z.record(z.any())).optional().describe("Downloadable files"),
|
|
33
14
|
video_demo: z.string().optional().describe("Demo video URL"),
|
|
34
15
|
}, (body) => handle(() => api.createCourse(body)));
|
|
35
|
-
server.tool("update_course", "Update a course by id (partial). Pass `id` plus fields to change.", { id: z.string().describe("Course id"), fields: z.record(z.any()).describe("Fields to update") }, ({ id, fields }) => handle(() => api.updateCourse(id, fields)));
|
|
36
|
-
server.tool("delete_course", "Delete a course by id (also deletes its tracks).", { id: z.string().describe("Course id") }, ({ id }) => handle(() => api.deleteCourse(id)));
|
|
37
|
-
server.tool("delete_courses", "Delete multiple courses by id.", { ids: z.array(z.string()).min(1).describe("Course ids") }, ({ ids }) => handle(() => api.deleteManyCourses(ids)));
|
|
38
|
-
server.tool("get_course_members", "List members (enrolled customers) of a course.", {
|
|
39
|
-
course_id: z.string().describe("Course id"),
|
|
40
|
-
page: z.number().optional().describe("Page number"),
|
|
41
|
-
limit: z.number().optional().describe("Items per page"),
|
|
42
|
-
term: z.string().optional().describe("Search term"),
|
|
43
|
-
}, (query) => handle(async () => unwrap(await api.getCourseMembers(query))));
|
|
44
16
|
}
|
package/dist/tools/apps.js
CHANGED
|
@@ -55,15 +55,4 @@ Pass the app's subscription id — get it from list_apps (the \`id\` field) or g
|
|
|
55
55
|
await api.uninstallApp(id);
|
|
56
56
|
return { id, uninstalled: true };
|
|
57
57
|
}));
|
|
58
|
-
server.tool("update_app", `Update an installed app's configuration. Pass the app subscription id and an \`attrs\` object
|
|
59
|
-
that is merged onto the subscription — usually \`{ settings: {...} }\`, optionally \`{ status }\`.
|
|
60
|
-
For the product-review app, prefer update_app_review (it also propagates shop_info).`, {
|
|
61
|
-
id: z.string().describe("App subscription id (from list_apps / get_app)"),
|
|
62
|
-
attrs: z.record(z.any()).describe('Fields to update, e.g. { "settings": { ... }, "status": 1 }'),
|
|
63
|
-
}, ({ id, attrs }) => handle(() => api.updateApp(id, attrs)));
|
|
64
|
-
server.tool("update_app_review", `Update the product-review app's settings (e.g. shop_info, auto-approve, display options).
|
|
65
|
-
Pass the review app's subscription id (get_app with type "product_review") and the full \`settings\` object.`, {
|
|
66
|
-
id: z.string().describe("Review app subscription id (get_app type=product_review)"),
|
|
67
|
-
settings: z.record(z.any()).describe('Review app settings object, e.g. { "shop_info": { ... }, "auto_approve": true }'),
|
|
68
|
-
}, ({ id, settings }) => handle(() => api.updateAppReview(id, settings)));
|
|
69
58
|
}
|
package/dist/tools/builder.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { checkSiteCode, codeGuard } from "../builder/native-first.js";
|
|
3
|
+
import { PAGE_CODE_ARG, writePageCode } from "./page-code.js";
|
|
4
|
+
import { PAGE_CODE_BUDGET, codeTargets, lintPageCode, mergePageCode } from "../builder/page-code.js";
|
|
2
5
|
import { elementSchema, suggestType, valueRules } from "../builder/element-schema.js";
|
|
3
6
|
import { z } from "zod";
|
|
4
7
|
import { BUILD_GUIDE } from "../builder/guide.js";
|
|
@@ -244,10 +247,18 @@ ONE page per site for type main (homepage) / error / maintain, and slugs are uni
|
|
|
244
247
|
})
|
|
245
248
|
.optional()
|
|
246
249
|
.describe("SEO for this page → settings.seo. Without it the page publishes with an EMPTY title/description. For a store page a good default title is '{{name_product}} | {{name_site}}' (product) or '{{name_category}} | {{name_site}}' (category)."),
|
|
250
|
+
custom_code: PAGE_CODE_ARG,
|
|
251
|
+
native_gap: z.string().min(30).optional().describe("Only if custom_code is refused and no native way exists: the need, what you checked, what it lacks."),
|
|
247
252
|
dry_run: z.boolean().default(true).describe("Preview+validate only (true) or create+save (false)"),
|
|
248
|
-
}, ({ name, slug, source, type, is_homepage, seo, dry_run }) => handle(async () => {
|
|
253
|
+
}, ({ name, slug, source, type, is_homepage, seo, custom_code, native_gap, dry_run }) => handle(async () => {
|
|
249
254
|
const parsed = parseSource(source);
|
|
250
255
|
const validation = validatePage(parsed);
|
|
256
|
+
// Per-page code is judged against THIS source before anything is created.
|
|
257
|
+
const pageCode = custom_code ? Object.fromEntries(Object.entries(custom_code).filter(([, v]) => v !== undefined)) : undefined;
|
|
258
|
+
const codeCheck = pageCode ? lintPageCode(mergePageCode({}, pageCode).after, codeTargets(parsed).ids) : undefined;
|
|
259
|
+
const codeBlock = pageCode ? codeGuard(checkSiteCode({}, mergePageCode({}, pageCode).after, { label: "Page", budget: PAGE_CODE_BUDGET }), native_gap) : null;
|
|
260
|
+
if (codeCheck?.errors.length)
|
|
261
|
+
validation.valid = false;
|
|
251
262
|
// Resolve numeric page type + the site data-source flag a special page needs.
|
|
252
263
|
const kind = type || (is_homepage ? "main" : undefined);
|
|
253
264
|
const typeNum = kind ? PAGE_TYPE_NUM[kind] : undefined;
|
|
@@ -263,6 +274,7 @@ ONE page per site for type main (homepage) / error / maintain, and slugs are uni
|
|
|
263
274
|
dry_run: true,
|
|
264
275
|
...(conflict ? { blocked: true, conflict } : {}),
|
|
265
276
|
validation,
|
|
277
|
+
...(pageCode ? { custom_code: { errors: codeCheck.errors, warnings: codeCheck.warnings, ...(codeBlock ? { blocked: codeBlock } : {}) } } : {}),
|
|
266
278
|
request: { name, slug: cleanSlug ?? null, type: kind ?? null, page_type_num: typeNum ?? null, is_homepage, sections: (parsed && parsed.sections || []).length },
|
|
267
279
|
will_enable_feature: requiredFlag ?? null,
|
|
268
280
|
renders_at_breakpoints: ["bp1", "bp2", "bp3", "bp4"],
|
|
@@ -277,8 +289,10 @@ ONE page per site for type main (homepage) / error / maintain, and slugs are uni
|
|
|
277
289
|
return { error: conflict.error, existing_page: conflict.existing_page };
|
|
278
290
|
}
|
|
279
291
|
if (!validation.valid) {
|
|
280
|
-
return { error: "Validation failed — not saving.", validation };
|
|
292
|
+
return { error: "Validation failed — not saving.", validation, ...(codeCheck?.errors.length ? { custom_code_errors: codeCheck.errors } : {}) };
|
|
281
293
|
}
|
|
294
|
+
if (codeBlock)
|
|
295
|
+
return codeBlock;
|
|
282
296
|
// A special page is useless if its site data-source flag is off (bindings
|
|
283
297
|
// return null). Enable it BEFORE creating the page so the page works on first load.
|
|
284
298
|
let feature = null;
|
|
@@ -300,6 +314,9 @@ ONE page per site for type main (homepage) / error / maintain, and slugs are uni
|
|
|
300
314
|
}
|
|
301
315
|
// slug / homepage / SEO are not applied at create — set them via update_page.
|
|
302
316
|
const metaWarning = await applyPageMeta(api, pageId, { slug: cleanSlug, is_homepage, seo }).then(() => undefined, (e) => `Page saved, but slug/homepage/SEO failed: ${e?.message ?? e}`);
|
|
317
|
+
const codeSaved = pageCode
|
|
318
|
+
? await writePageCode(api, pageId, pageCode, { native_gap, dry_run: false }).catch((e) => ({ error: `Page saved, but its custom code failed: ${e?.message ?? e}` }))
|
|
319
|
+
: undefined;
|
|
303
320
|
return {
|
|
304
321
|
success: true,
|
|
305
322
|
page_id: pageId,
|
|
@@ -308,6 +325,7 @@ ONE page per site for type main (homepage) / error / maintain, and slugs are uni
|
|
|
308
325
|
page_type: kind ?? null,
|
|
309
326
|
...(feature ? { data_source: { flag: feature.flag, newly_enabled: feature.changed } } : {}),
|
|
310
327
|
stats: validation.stats,
|
|
328
|
+
...(codeSaved ? { custom_code: codeSaved } : {}),
|
|
311
329
|
...(metaWarning ? { warning: metaWarning } : {}),
|
|
312
330
|
};
|
|
313
331
|
}));
|
package/dist/tools/cms-files.js
CHANGED
|
@@ -133,7 +133,6 @@ function buildSchemas(collections) {
|
|
|
133
133
|
}));
|
|
134
134
|
}
|
|
135
135
|
export function registerCmsFileTools(server, api, handle) {
|
|
136
|
-
server.tool("list_cms_files", "List all CMS files (HTTP functions, cron jobs, ...) for the site", {}, () => handle(() => api.listCmsFiles()));
|
|
137
136
|
server.tool("create_cms_file", `Create a new CMS file. Types: "http_function", "jobs_config", "default"`, {
|
|
138
137
|
name: z.string().describe("File name"),
|
|
139
138
|
content: z.string().describe("Code content (JavaScript or JSON)"),
|
|
@@ -240,11 +239,6 @@ Example: "get_Products" → function_name="Products", method="GET"`, {
|
|
|
240
239
|
method: z.enum(["GET", "POST", "PUT", "PATCH"]).default("POST").describe("HTTP method"),
|
|
241
240
|
params: z.record(z.any()).optional().describe("Parameters"),
|
|
242
241
|
}, ({ function_name, method, params }) => handle(() => api.runFunction(function_name, method, params)));
|
|
243
|
-
server.tool("debug_function", "Run JS code in debug mode (without deploying). Returns execution result and console logs", {
|
|
244
|
-
content: z.string().describe("JS code to debug"),
|
|
245
|
-
function_name: z.string().describe("Function name to run"),
|
|
246
|
-
params: z.record(z.any()).optional().describe("Test parameters"),
|
|
247
|
-
}, ({ content, function_name, params }) => handle(() => api.debugFunction({ content, functionName: function_name, params })));
|
|
248
242
|
server.tool("save_file_version", "Save a version snapshot of a CMS file for rollback", {
|
|
249
243
|
cms_file_id: z.string().describe("CMS file ID"),
|
|
250
244
|
content: z.string().describe("Content to save"),
|
|
@@ -252,10 +246,9 @@ Example: "get_Products" → function_name="Products", method="GET"`, {
|
|
|
252
246
|
}, ({ cms_file_id, content, is_public }) =>
|
|
253
247
|
// Backend reads `file_id` (it stores it as cms_file_id); a `cms_file_id` key alone is ignored.
|
|
254
248
|
handle(() => api.saveFileVersion({ file_id: cms_file_id, content, is_public })));
|
|
255
|
-
server.tool("get_file_versions", "View version history of a CMS file. Each version includes its saved content — to restore, pass that content back to update_http_function (the http_function file) or update_cms_file, or use restore_file_version.", { cms_file_id: z.string().describe("CMS file ID") }, ({ cms_file_id }) => handle(() => api.getFileVersions({ file_id: cms_file_id })));
|
|
256
249
|
server.tool("restore_file_version", "Roll a CMS file back to a saved version in one step: reads the version's content and writes it back to the file. Omit version_id to restore the most recent snapshot. Tip: save_file_version on the current content first if you want an undo point.", {
|
|
257
250
|
cms_file_id: z.string().describe("CMS file ID to restore"),
|
|
258
|
-
version_id: z.string().optional().describe("Which version to restore (
|
|
251
|
+
version_id: z.string().optional().describe("Which version to restore (api_find 'file versions' → api_get). Omit = latest snapshot."),
|
|
259
252
|
}, ({ cms_file_id, version_id }) => handle(async () => {
|
|
260
253
|
const res = await api.getFileVersions({ file_id: cms_file_id });
|
|
261
254
|
const body = res?.data ?? res;
|
|
@@ -264,7 +257,7 @@ Example: "get_Products" → function_name="Products", method="GET"`, {
|
|
|
264
257
|
throw new Error("No saved versions for this file — nothing to restore.");
|
|
265
258
|
const version = version_id ? list.find((v) => v.id === version_id) : list[0];
|
|
266
259
|
if (!version)
|
|
267
|
-
throw new Error(`Version "${version_id}" not found.
|
|
260
|
+
throw new Error(`Version "${version_id}" not found. List them with api_find("file versions") → api_get.`);
|
|
268
261
|
const content = version.content;
|
|
269
262
|
if (content == null)
|
|
270
263
|
throw new Error("That version has no stored content; cannot restore.");
|
|
@@ -278,5 +271,4 @@ Example: "get_Products" → function_name="Products", method="GET"`, {
|
|
|
278
271
|
note: "File reverted. Run/debug it to confirm, then publish if needed.",
|
|
279
272
|
};
|
|
280
273
|
}));
|
|
281
|
-
server.tool("toggle_debug_render", "Toggle debug render mode for a CMS file", { cms_file_id: z.string().describe("CMS file ID") }, ({ cms_file_id }) => handle(() => api.toggleDebugRender({ cms_file_id })));
|
|
282
274
|
}
|