webcake-landing-mcp 1.13.5 → 1.13.7
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 +6 -4
- package/README.vi.md +6 -4
- package/dist/changelog.json +14 -14
- package/dist/install.js +89 -25
- package/dist/persistence/webcake-client.js +52 -20
- package/dist/tools/persistence.js +73 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,18 +102,20 @@ Zero install, always the latest version, needs Node.js 18+. **One line** grabs y
|
|
|
102
102
|
|
|
103
103
|
```bash
|
|
104
104
|
# Opens the browser — click Connect, your installed IDEs are configured (prod)
|
|
105
|
-
npx -y webcake-landing-mcp install
|
|
105
|
+
npx -y webcake-landing-mcp@latest install
|
|
106
106
|
|
|
107
107
|
# Developers only — step by step: environment, login or JWT, org, IDE(s)
|
|
108
|
-
npx -y webcake-landing-mcp install --dev
|
|
108
|
+
npx -y webcake-landing-mcp@latest install --dev
|
|
109
109
|
|
|
110
110
|
# Scripts and CI — every supported IDE, even ones not installed yet
|
|
111
|
-
npx -y webcake-landing-mcp install --ide all --jwt <your-jwt>
|
|
111
|
+
npx -y webcake-landing-mcp@latest install --ide all --jwt <your-jwt>
|
|
112
112
|
|
|
113
113
|
# Remove the server from every IDE config
|
|
114
|
-
npx -y webcake-landing-mcp uninstall
|
|
114
|
+
npx -y webcake-landing-mcp@latest uninstall
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
> **Troubleshooting (Claude Desktop):** compare the path(s) printed by `install` with **Settings → Developer → Edit Config**, and fully quit Claude Desktop (tray icon → Quit) before reopening.
|
|
118
|
+
|
|
117
119
|
**`install` asks nothing.** It connects to production, opens your browser so you can click *Connect*, then adds the server
|
|
118
120
|
to every AI app it finds on this computer. Your other servers are kept, and any config file it changes is backed up next to
|
|
119
121
|
the original as `<file>.webcake-landing-backup`. No AI app found? It says so and exits with an error: install one and run it again,
|
package/README.vi.md
CHANGED
|
@@ -102,18 +102,20 @@ Không cần cài đặt, luôn bản mới nhất, cần Node.js 18+. **Một d
|
|
|
102
102
|
|
|
103
103
|
```bash
|
|
104
104
|
# Mở trình duyệt — bấm Kết nối, các IDE trên máy được cấu hình tự động (prod)
|
|
105
|
-
npx -y webcake-landing-mcp install
|
|
105
|
+
npx -y webcake-landing-mcp@latest install
|
|
106
106
|
|
|
107
107
|
# Chỉ dành cho dev — từng bước: môi trường, đăng nhập hoặc JWT, org, IDE
|
|
108
|
-
npx -y webcake-landing-mcp install --dev
|
|
108
|
+
npx -y webcake-landing-mcp@latest install --dev
|
|
109
109
|
|
|
110
110
|
# Script và CI — mọi IDE được hỗ trợ, kể cả IDE chưa cài
|
|
111
|
-
npx -y webcake-landing-mcp install --ide all --jwt <your-jwt>
|
|
111
|
+
npx -y webcake-landing-mcp@latest install --ide all --jwt <your-jwt>
|
|
112
112
|
|
|
113
113
|
# Gỡ server khỏi mọi cấu hình IDE
|
|
114
|
-
npx -y webcake-landing-mcp uninstall
|
|
114
|
+
npx -y webcake-landing-mcp@latest uninstall
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
> **Xử lý sự cố (Claude Desktop):** so sánh đường dẫn `install` in ra với **Settings → Developer → Edit Config**, và thoát hẳn Claude Desktop (icon khay → Quit) rồi mở lại.
|
|
118
|
+
|
|
117
119
|
**`install` không hỏi gì cả.** Lệnh kết nối tới production, mở trình duyệt để bạn bấm *Kết nối*, rồi thêm server vào mọi ứng dụng AI
|
|
118
120
|
tìm thấy trên máy. Các server khác của bạn được giữ nguyên, và file cấu hình nào bị đổi đều có bản sao lưu ngay cạnh, tên
|
|
119
121
|
`<file>.webcake-landing-backup`. Không tìm thấy ứng dụng AI nào? Lệnh báo rõ và thoát với lỗi: hãy cài một ứng dụng rồi chạy lại, hoặc chỉ định bằng `--ide`.
|
package/dist/changelog.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "1.13.7",
|
|
4
|
+
"d": "22/11/2026",
|
|
5
|
+
"type": "Fixed",
|
|
6
|
+
"en": "install now writes the Claude Desktop config to every location Claude may read on Windows (Store/MSIX package containers, Claude-Data,…",
|
|
7
|
+
"vi": "install nay ghi config Claude Desktop vào mọi vị trí Claude có thể đọc trên Windows (container gói Store/MSIX, Claude-Data, %APPDATA%\\Claude) thay…"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"v": "1.13.6",
|
|
11
|
+
"d": "20/11/2026",
|
|
12
|
+
"type": "Fixed",
|
|
13
|
+
"en": "update_page/patch_page no longer compute a sections-only diff against a page that has two elements sharing the same id (something the Webcake editor…",
|
|
14
|
+
"vi": "update_page/patch_page nay không còn tính diff theo từng section với một trang có hai element dùng chung id (điều mà chính editor Webcake vẫn cho…"
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"v": "1.13.5",
|
|
4
18
|
"d": "20/11/2026",
|
|
@@ -26,19 +40,5 @@
|
|
|
26
40
|
"type": "Added",
|
|
27
41
|
"en": "A new live-comment element (livestream-style scrolling comment feed above a fake input) is now in the catalog, with full docs in…",
|
|
28
42
|
"vi": "Danh mục có thêm element live-comment (luồng bình luận kiểu livestream cuộn lên trên một ô input giả), kèm tài liệu đầy đủ trong…"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"v": "1.13.1",
|
|
32
|
-
"d": "20/11/2026",
|
|
33
|
-
"type": "Fixed",
|
|
34
|
-
"en": "update_page, patch_page, add_section (legacy fallback path), and completing a cached draft via create_page/patch_page/update_page with a draft_id…",
|
|
35
|
-
"vi": "update_page, patch_page, add_section (đường fallback cho backend cũ), và việc hoàn tất một draft đã cache qua create_page/patch_page/update_page với…"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"v": "1.13.0",
|
|
39
|
-
"d": "19/11/2026",
|
|
40
|
-
"type": "Added",
|
|
41
|
-
"en": "new_element and the get_element/list_elements skeletons now return the exact node the Webcake editor drops for a type — its default colors, font,…",
|
|
42
|
-
"vi": "new_element và skeleton của get_element/list_elements nay trả về đúng node mà editor Webcake thả ra cho type đó — màu, font, viền, kích thước mặc…"
|
|
43
43
|
}
|
|
44
44
|
]
|
package/dist/install.js
CHANGED
|
@@ -116,7 +116,7 @@ function mergeJson(file, launch, env, key = "mcpServers") {
|
|
|
116
116
|
mkdirSync(dirname(file), { recursive: true });
|
|
117
117
|
let cfg = {};
|
|
118
118
|
if (existsSync(file)) {
|
|
119
|
-
const raw = readFileSync(file, "utf8").trim();
|
|
119
|
+
const raw = readFileSync(file, "utf8").replace(/^\uFEFF/, "").trim();
|
|
120
120
|
if (raw) {
|
|
121
121
|
try {
|
|
122
122
|
cfg = JSON.parse(raw);
|
|
@@ -144,7 +144,7 @@ function mergeOpencodeJson(file, launch, env) {
|
|
|
144
144
|
mkdirSync(dirname(file), { recursive: true });
|
|
145
145
|
let cfg = {};
|
|
146
146
|
if (existsSync(file)) {
|
|
147
|
-
const raw = readFileSync(file, "utf8").trim();
|
|
147
|
+
const raw = readFileSync(file, "utf8").replace(/^\uFEFF/, "").trim();
|
|
148
148
|
if (raw) {
|
|
149
149
|
try {
|
|
150
150
|
cfg = JSON.parse(raw);
|
|
@@ -182,29 +182,82 @@ function configureCodex(launch, env) {
|
|
|
182
182
|
writeConfig(cfg, content.trimEnd() + "\n" + block);
|
|
183
183
|
}
|
|
184
184
|
// ── IDE config-file locations ────────────────────────────────────────────────
|
|
185
|
-
|
|
185
|
+
// Every location a Claude Desktop build may read its config from. A machine can have
|
|
186
|
+
// several (MSIX/Store package container, Claude-Data, classic %APPDATA%) and only one is
|
|
187
|
+
// the live one, so on Windows we write to all candidates.
|
|
188
|
+
function findConfigsUnder(dir, depth, out) {
|
|
189
|
+
if (depth < 0)
|
|
190
|
+
return;
|
|
191
|
+
let entries;
|
|
192
|
+
try {
|
|
193
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
for (const e of entries) {
|
|
199
|
+
const full = join(dir, e.name);
|
|
200
|
+
if (e.isFile() && e.name.toLowerCase() === "claude_desktop_config.json")
|
|
201
|
+
out.push(full);
|
|
202
|
+
else if (e.isDirectory())
|
|
203
|
+
findConfigsUnder(full, depth - 1, out);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function claudeDesktopPaths() {
|
|
186
207
|
if (PLAT === "win32") {
|
|
187
|
-
|
|
188
|
-
// its package container, NOT %APPDATA%\Claude. Detect that container first
|
|
189
|
-
// (the package name is Claude_<publisher-hash>, e.g. Claude_pzs8sxrjxfjjc)
|
|
190
|
-
// so installs land in the file the Store app actually loads.
|
|
208
|
+
const found = [];
|
|
191
209
|
const packages = join(LOCALAPPDATA, "Packages");
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
210
|
+
try {
|
|
211
|
+
if (existsSync(packages)) {
|
|
212
|
+
for (const n of readdirSync(packages)) {
|
|
213
|
+
if (!/claude/i.test(n))
|
|
214
|
+
continue;
|
|
215
|
+
const cache = join(packages, n, "LocalCache");
|
|
216
|
+
if (existsSync(cache))
|
|
217
|
+
found.push(join(cache, "Roaming", "Claude", "claude_desktop_config.json"));
|
|
197
218
|
}
|
|
198
219
|
}
|
|
199
|
-
catch {
|
|
200
|
-
/* fall through to the Win32 default */
|
|
201
|
-
}
|
|
202
220
|
}
|
|
203
|
-
|
|
221
|
+
catch {
|
|
222
|
+
/* ignore */
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
const data = join(LOCALAPPDATA, "Claude-Data");
|
|
226
|
+
if (existsSync(data))
|
|
227
|
+
findConfigsUnder(data, 4, found);
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
/* ignore */
|
|
231
|
+
}
|
|
232
|
+
const roaming = join(APPDATA, "Claude");
|
|
233
|
+
if (existsSync(roaming) || found.length === 0)
|
|
234
|
+
found.push(join(roaming, "claude_desktop_config.json"));
|
|
235
|
+
const seen = new Set();
|
|
236
|
+
return found.filter((p) => {
|
|
237
|
+
const k = p.toLowerCase();
|
|
238
|
+
if (seen.has(k))
|
|
239
|
+
return false;
|
|
240
|
+
seen.add(k);
|
|
241
|
+
return true;
|
|
242
|
+
});
|
|
204
243
|
}
|
|
205
244
|
const mac = join(HOME, "Library", "Application Support", "Claude");
|
|
206
245
|
const dir = existsSync(mac) ? mac : join(HOME, ".config", "Claude");
|
|
207
|
-
return join(dir, "claude_desktop_config.json");
|
|
246
|
+
return [join(dir, "claude_desktop_config.json")];
|
|
247
|
+
}
|
|
248
|
+
function claudeDesktopRunning() {
|
|
249
|
+
try {
|
|
250
|
+
if (PLAT === "win32") {
|
|
251
|
+
const r = spawnSync("tasklist", ["/FI", "IMAGENAME eq claude.exe", "/NH"], { stdio: "pipe", encoding: "utf8" });
|
|
252
|
+
return /claude\.exe/i.test(String(r.stdout ?? ""));
|
|
253
|
+
}
|
|
254
|
+
if (PLAT === "darwin")
|
|
255
|
+
return spawnSync("pgrep", ["-x", "Claude"], { stdio: "pipe" }).status === 0;
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
/* ignore */
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
208
261
|
}
|
|
209
262
|
function vscodeUserDir() {
|
|
210
263
|
if (PLAT === "win32")
|
|
@@ -237,7 +290,7 @@ function hasClaudeCli() {
|
|
|
237
290
|
// install needs no IDE question and never creates config for an app the user lacks.
|
|
238
291
|
function detectIdes() {
|
|
239
292
|
const marks = {
|
|
240
|
-
"claude-desktop":
|
|
293
|
+
"claude-desktop": "",
|
|
241
294
|
"claude-code": claudeJsonPath(),
|
|
242
295
|
cursor: join(HOME, ".cursor"),
|
|
243
296
|
windsurf: join(HOME, ".codeium", "windsurf"),
|
|
@@ -249,7 +302,7 @@ function detectIdes() {
|
|
|
249
302
|
kiro: join(HOME, ".kiro"),
|
|
250
303
|
opencode: dirname(opencodePath()),
|
|
251
304
|
};
|
|
252
|
-
return Object.keys(marks).filter((id) => existsSync(marks[id]) || (id === "claude-code" && hasClaudeCli()));
|
|
305
|
+
return Object.keys(marks).filter((id) => (id === "claude-desktop" ? claudeDesktopPaths().some((p) => existsSync(dirname(p))) : existsSync(marks[id])) || (id === "claude-code" && hasClaudeCli()));
|
|
253
306
|
}
|
|
254
307
|
// ── per-IDE configure ────────────────────────────────────────────────────────
|
|
255
308
|
function configureClaudeCode(launch, env) {
|
|
@@ -269,10 +322,21 @@ function configureClaudeCode(launch, env) {
|
|
|
269
322
|
}
|
|
270
323
|
function configureClaudeDesktop(launch, env) {
|
|
271
324
|
info("Claude Desktop…");
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
warn("Restart Claude Desktop to load the server.");
|
|
325
|
+
if (claudeDesktopRunning()) {
|
|
326
|
+
warn("Claude Desktop đang chạy — thoát hẳn (chuột phải icon khay → Quit) rồi mở lại để nạp server");
|
|
275
327
|
}
|
|
328
|
+
const paths = claudeDesktopPaths();
|
|
329
|
+
let wrote = 0;
|
|
330
|
+
for (const p of paths) {
|
|
331
|
+
if (mergeJson(p, launch, env)) {
|
|
332
|
+
ok(`Claude Desktop configured (${p})`);
|
|
333
|
+
wrote++;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (paths.length > 1)
|
|
337
|
+
info("Wrote to every location Claude Desktop may read its config from.");
|
|
338
|
+
if (wrote)
|
|
339
|
+
warn("Restart Claude Desktop to load the server.");
|
|
276
340
|
}
|
|
277
341
|
function configureCursor(launch, env) {
|
|
278
342
|
info("Cursor…");
|
|
@@ -376,7 +440,7 @@ function removeFromJson(file) {
|
|
|
376
440
|
if (!existsSync(file))
|
|
377
441
|
return;
|
|
378
442
|
try {
|
|
379
|
-
const cfg = JSON.parse(readFileSync(file, "utf8"));
|
|
443
|
+
const cfg = JSON.parse(readFileSync(file, "utf8").replace(/^\uFEFF/, ""));
|
|
380
444
|
const holders = [cfg.mcpServers, cfg.servers].filter((s) => s && s[NAME]);
|
|
381
445
|
if (holders.length) {
|
|
382
446
|
for (const s of holders)
|
|
@@ -395,7 +459,7 @@ function uninstall() {
|
|
|
395
459
|
spawnSync("claude", ["mcp", "remove", NAME], { stdio: "ignore" });
|
|
396
460
|
[
|
|
397
461
|
claudeJsonPath(),
|
|
398
|
-
|
|
462
|
+
...claudeDesktopPaths(),
|
|
399
463
|
join(HOME, ".config", "Claude", "claude_desktop_config.json"),
|
|
400
464
|
cursorPath(),
|
|
401
465
|
windsurfPath(),
|
|
@@ -410,7 +474,7 @@ function uninstall() {
|
|
|
410
474
|
const oc = opencodePath();
|
|
411
475
|
if (existsSync(oc)) {
|
|
412
476
|
try {
|
|
413
|
-
const cfg = JSON.parse(readFileSync(oc, "utf8"));
|
|
477
|
+
const cfg = JSON.parse(readFileSync(oc, "utf8").replace(/^\uFEFF/, ""));
|
|
414
478
|
if (cfg.mcp && cfg.mcp[NAME]) {
|
|
415
479
|
delete cfg.mcp[NAME];
|
|
416
480
|
writeFileSync(oc, JSON.stringify(cfg, null, 2) + "\n");
|
|
@@ -99,6 +99,9 @@ const TOP_KEYS = ["settings", "options", "cartConfigs"];
|
|
|
99
99
|
export function sourceOps(before, after) {
|
|
100
100
|
if (!isPlainObj(before) || !isPlainObj(after))
|
|
101
101
|
return undefined;
|
|
102
|
+
// an id held by two nodes: the backend edits the FIRST one it meets, which may not be the one meant
|
|
103
|
+
if (hasDuplicateIds(before) || hasDuplicateIds(after))
|
|
104
|
+
return undefined;
|
|
102
105
|
const acc = { removes: [], sets: [], inserts: [] };
|
|
103
106
|
for (const root of ["page", "popup"])
|
|
104
107
|
if (!listOps(Array.isArray(before[root]) ? before[root] : [], Array.isArray(after[root]) ? after[root] : [], { root }, acc))
|
|
@@ -113,6 +116,11 @@ export function sourceOps(before, after) {
|
|
|
113
116
|
}
|
|
114
117
|
return [...acc.removes, ...acc.sets, ...acc.inserts, ...tops];
|
|
115
118
|
}
|
|
119
|
+
function hasDuplicateIds(src) {
|
|
120
|
+
const seen = new Set();
|
|
121
|
+
const walk = (list) => Array.isArray(list) && list.some((n) => isPlainObj(n) && ((typeof n.id === "string" && (seen.has(n.id) || !seen.add(n.id))) || walk(n.children)));
|
|
122
|
+
return ["page", "popup", "dynamic_pages"].some((r) => walk(src[r]));
|
|
123
|
+
}
|
|
116
124
|
/** Ops for one child list (false: not expressible as list edits — reordered, or a node without an id). */
|
|
117
125
|
function listOps(a, b, where, acc) {
|
|
118
126
|
if ([...a, ...b].some((n) => !isPlainObj(n) || typeof n.id !== "string"))
|
|
@@ -154,37 +162,52 @@ function nodeOps(old, n, acc) {
|
|
|
154
162
|
* so the tree a patch leaves behind can be cached without downloading it again. Throws on an op it cannot apply. */
|
|
155
163
|
export function applyOps(source, ops) {
|
|
156
164
|
const out = structuredClone(source);
|
|
165
|
+
// depth-first pre-order, page then popup — the order LandingPage.Ai.SourcePatch walks
|
|
157
166
|
const find = (id) => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
const walk = (list) => {
|
|
168
|
+
if (!Array.isArray(list))
|
|
169
|
+
return undefined;
|
|
170
|
+
for (let i = 0; i < list.length; i++) {
|
|
171
|
+
if (!isPlainObj(list[i]))
|
|
172
|
+
continue;
|
|
173
|
+
if (list[i].id === id)
|
|
174
|
+
return { list, i };
|
|
175
|
+
const hit = walk(list[i].children);
|
|
176
|
+
if (hit)
|
|
177
|
+
return hit;
|
|
168
178
|
}
|
|
169
|
-
|
|
170
|
-
|
|
179
|
+
return undefined;
|
|
180
|
+
};
|
|
181
|
+
return walk(out.page) ?? walk(out.popup);
|
|
171
182
|
};
|
|
172
183
|
const at = (list, index, node) => (index == null ? list.push(node) : list.splice(index, 0, node));
|
|
184
|
+
const ROOT_TYPE = { page: "section", popup: "popup" };
|
|
173
185
|
for (const op of ops) {
|
|
174
186
|
if (op.op === "top")
|
|
175
187
|
out[op.key] = structuredClone(op.value);
|
|
176
|
-
else if (op.op === "insert" && !op.parent_id)
|
|
177
|
-
|
|
188
|
+
else if (op.op === "insert" && !op.parent_id) {
|
|
189
|
+
const root = op.root ?? "page";
|
|
190
|
+
if (op.node?.type !== ROOT_TYPE[root])
|
|
191
|
+
throw new Error(`applyOps: a top-level ${root} node must be a ${ROOT_TYPE[root]}`);
|
|
192
|
+
at((out[root] ??= []), op.index, structuredClone(op.node));
|
|
193
|
+
}
|
|
178
194
|
else {
|
|
179
195
|
const hit = find(op.op === "insert" ? op.parent_id : op.id);
|
|
180
196
|
if (!hit)
|
|
181
197
|
throw new Error(`applyOps: ${op.op} ${op.id ?? op.parent_id} not found`);
|
|
198
|
+
const node = hit.list[hit.i];
|
|
182
199
|
if (op.op === "remove")
|
|
183
200
|
hit.list.splice(hit.i, 1);
|
|
184
|
-
else if (op.op === "set")
|
|
201
|
+
else if (op.op === "set") {
|
|
202
|
+
if ((node.type === "section" || node.type === "popup") && op.node?.type !== node.type)
|
|
203
|
+
throw new Error(`applyOps: cannot turn ${node.type} ${op.id} into ${op.node?.type}`);
|
|
185
204
|
hit.list[hit.i] = { ...structuredClone(op.node), id: op.id };
|
|
186
|
-
|
|
187
|
-
|
|
205
|
+
}
|
|
206
|
+
else if (op.op === "insert") {
|
|
207
|
+
if (!Array.isArray(node.children))
|
|
208
|
+
throw new Error(`applyOps: ${op.parent_id} has no children list`);
|
|
209
|
+
at(node.children, op.index, structuredClone(op.node));
|
|
210
|
+
}
|
|
188
211
|
}
|
|
189
212
|
}
|
|
190
213
|
return out;
|
|
@@ -393,6 +416,7 @@ export async function createPage(config, name, source, orgId) {
|
|
|
393
416
|
editor_url: toEditorLoginUrl(config, editorPath),
|
|
394
417
|
preview_url: toPreviewUrl(config, previewPath),
|
|
395
418
|
organization_id: (orgId ?? config.orgId) ?? null,
|
|
419
|
+
version: versionOf(data),
|
|
396
420
|
raw: data,
|
|
397
421
|
...(rehost ? { rehost } : {}),
|
|
398
422
|
// Also when only the Google weight links changed it — publish must build what was stored.
|
|
@@ -632,7 +656,14 @@ export async function updatePageSource(config, pageId, source, opts = {}) {
|
|
|
632
656
|
let via = "update";
|
|
633
657
|
let nOps = 0;
|
|
634
658
|
const ops = opts.base && opts.before != null ? sourceOps(opts.before, hostedSource) : undefined;
|
|
635
|
-
// the tree equals the version it was read at: nothing to write (fonts still synced — a sync can fail and be retried)
|
|
659
|
+
// the tree equals the version it was read at: nothing to write (fonts still synced — a sync can fail and be retried).
|
|
660
|
+
// `before` taken from the cache without asking (verified:false) may be stale: then confirm the
|
|
661
|
+
// version first — an empty diff never reaches the backend's own check.
|
|
662
|
+
if (ops && ops.length === 0 && opts.verified === false) {
|
|
663
|
+
const v = await getPageVersion(config, pageId);
|
|
664
|
+
if (v.ok && v.version !== opts.base)
|
|
665
|
+
return { ok: false, status: 409, page_changed: true, live_version: v.version, error: "page_changed: the cached copy is older than the stored page — nothing was written" };
|
|
666
|
+
}
|
|
636
667
|
if (ops && ops.length === 0)
|
|
637
668
|
return {
|
|
638
669
|
ok: true, status: 200, page_id: pageId, version: opts.base, via: "patch", patch_ops: 0, unchanged: true, raw: { unchanged: true },
|
|
@@ -670,7 +701,8 @@ export async function updatePageSource(config, pageId, source, opts = {}) {
|
|
|
670
701
|
}
|
|
671
702
|
}
|
|
672
703
|
catch (e) {
|
|
673
|
-
|
|
704
|
+
// a timed-out save may still land: the draft must hold what it would have stored
|
|
705
|
+
return { ...timeoutOrNetworkError(url, e), rehosted_source: hostedSource };
|
|
674
706
|
}
|
|
675
707
|
const text = await res.text();
|
|
676
708
|
let json = null;
|
|
@@ -683,7 +715,7 @@ export async function updatePageSource(config, pageId, source, opts = {}) {
|
|
|
683
715
|
const data = json?.data ?? json;
|
|
684
716
|
const pageIdOut = data?.page_id;
|
|
685
717
|
if (!res.ok || !pageIdOut)
|
|
686
|
-
return writeFailure(res.status, json, text);
|
|
718
|
+
return { ...writeFailure(res.status, json, text), rehosted_source: hostedSource };
|
|
687
719
|
return {
|
|
688
720
|
ok: true,
|
|
689
721
|
status: res.status,
|
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
* headers (extra.requestInfo.headers) carry the client's own Webcake JWT, so a
|
|
10
10
|
* hosted server is multi-user; in stdio/single-user mode they come from env.
|
|
11
11
|
*/
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import { withGoogleWeightLinks } from "../persistence/html-ingest.js";
|
|
12
14
|
import { z } from "zod";
|
|
13
15
|
import { text, warningsField, autoFixedField } from "../mcp/response.js";
|
|
14
16
|
import { objectOrJson, objectsOrJson } from "../mcp/params.js";
|
|
15
17
|
import { readConfig, configFromHeaders } from "../persistence/config.js";
|
|
16
|
-
import { applyOps, buildRequestRedacted, buildUpdateRequestRedacted, buildAppendRequestRedacted, buildPublishRequestRedacted, buildPageApp, createPage, listOrganizations, listPages, searchPages, listVerifiedDomains, getPageSource, getPageVersion, updatePageSource, appendSection, publishPage, toPreviewUrl, } from "../persistence/webcake-client.js";
|
|
18
|
+
import { sourceOps, applyOps, buildRequestRedacted, buildUpdateRequestRedacted, buildAppendRequestRedacted, buildPublishRequestRedacted, buildPageApp, createPage, listOrganizations, listPages, searchPages, listVerifiedDomains, getPageSource, getPageVersion, updatePageSource, appendSection, publishPage, toPreviewUrl, } from "../persistence/webcake-client.js";
|
|
17
19
|
import { matchAccountDomain, normalizeDomain } from "../persistence/domain-match.js";
|
|
18
20
|
import { healBrokenResizeUrls } from "../persistence/rehost.js";
|
|
19
21
|
import { putDraft, getDraft, updateDraft, deleteDraft } from "../persistence/draft-cache.js";
|
|
@@ -83,10 +85,11 @@ export function registerPersistenceTools(server, domain) {
|
|
|
83
85
|
const readLiveSource = async (config, pageId, opts = {}) => {
|
|
84
86
|
const key = sourceCacheKey(pageId, config.jwt);
|
|
85
87
|
const cv = cachedPageSourceVersion(key);
|
|
86
|
-
|
|
88
|
+
// only an exact (md5) version is trusted: updated_at has 1 s precision
|
|
89
|
+
if (cv && /^[0-9a-f]{32}$/.test(cv) && opts.trust && (opts.trust === true || opts.trust === cv)) {
|
|
87
90
|
const hit = cachedPageSource(key, cv);
|
|
88
91
|
if (hit)
|
|
89
|
-
return { ...hit, source: structuredClone(hit.source), from_cache: true };
|
|
92
|
+
return { ...hit, source: structuredClone(hit.source), from_cache: true, trusted: true };
|
|
90
93
|
}
|
|
91
94
|
if (cachedPageSourceVersion(key)) {
|
|
92
95
|
const probe = await getPageVersion(config, pageId);
|
|
@@ -122,6 +125,25 @@ export function registerPersistenceTools(server, domain) {
|
|
|
122
125
|
if (served.size > 500)
|
|
123
126
|
served.delete(served.keys().next().value); // ponytail: oldest-first cap
|
|
124
127
|
};
|
|
128
|
+
/** Both publish routes store `JSON.stringify(source)` byte for byte: its md5 is the version a publish leaves. */
|
|
129
|
+
const publishedVersion = (source) => createHash("md5").update(JSON.stringify(source)).digest("hex");
|
|
130
|
+
/** A version probe after a re-save is only trusted when it is EXACTLY the bytes we stored — anything
|
|
131
|
+
* else means another save landed in between, so forget instead of re-labelling a stale tree. */
|
|
132
|
+
const probeIs = async (config, pageId, expected) => {
|
|
133
|
+
const v = await getPageVersion(config, pageId).catch(() => null);
|
|
134
|
+
return !!v?.ok && v.version === expected;
|
|
135
|
+
};
|
|
136
|
+
/** A page the model just created: its tree IS the stored version — the create's own (exact, from
|
|
137
|
+
* the response), or the auto-publish re-save's when that ran and the probe proves nothing else landed. */
|
|
138
|
+
const servedAfterCreate = async (config, pageId, created, published) => {
|
|
139
|
+
if (!pageId)
|
|
140
|
+
return;
|
|
141
|
+
if (published === undefined)
|
|
142
|
+
return rememberServed(config, pageId, created.version);
|
|
143
|
+
const expected = publishedVersion(published);
|
|
144
|
+
if (await probeIs(config, pageId, expected))
|
|
145
|
+
rememberServed(config, pageId, expected);
|
|
146
|
+
};
|
|
125
147
|
const isServerToken = (v) => !!v && (/^[0-9a-f]{32}$/.test(v) || /^\d{4}-\d\d-\d\dT/.test(v));
|
|
126
148
|
/** After a write the backend versioned (source_hash / updated_at): the stored tree IS what we sent,
|
|
127
149
|
* so cache it under that version — the next read is a version probe, not a download. */
|
|
@@ -140,6 +162,9 @@ export function registerPersistenceTools(server, domain) {
|
|
|
140
162
|
catch {
|
|
141
163
|
stored = undefined;
|
|
142
164
|
}
|
|
165
|
+
// a patch result is only as exact as its version: never cache one under a 1 s updated_at
|
|
166
|
+
if (outcome.via === "patch" && !/^[0-9a-f]{32}$/.test(outcome.version ?? ""))
|
|
167
|
+
stored = undefined;
|
|
143
168
|
if (outcome.version && stored != null && meta?.ok)
|
|
144
169
|
cachePageSource(sourceCacheKey(pageId, config.jwt), outcome.version, { ...meta, version: outcome.version, source: structuredClone(stored), from_cache: undefined });
|
|
145
170
|
else
|
|
@@ -178,8 +203,14 @@ export function registerPersistenceTools(server, domain) {
|
|
|
178
203
|
return { ok: true };
|
|
179
204
|
// A server version token (from get_page): exact. The write carries it, the backend re-checks it under its lock.
|
|
180
205
|
if (tokenBase && live.version) {
|
|
206
|
+
const before = domain.expand(structuredClone(live.source));
|
|
181
207
|
if (live.version === tokenBase)
|
|
182
|
-
return { ok: true, liveVersion: live.version, base: { base: tokenBase, before:
|
|
208
|
+
return { ok: true, liveVersion: live.version, base: { base: tokenBase, before, verified: !live.trusted }, live };
|
|
209
|
+
// the page moved on but already holds exactly this tree (a timed-out save that did land): done
|
|
210
|
+
// (the save adds the Google weight links itself — compare what it would have stored)
|
|
211
|
+
const landed = sourceOps(before, withGoogleWeightLinks(incoming));
|
|
212
|
+
if (landed && landed.length === 0)
|
|
213
|
+
return { ok: true, liveVersion: live.version, base: { base: live.version, before, verified: true }, live };
|
|
183
214
|
return {
|
|
184
215
|
ok: false,
|
|
185
216
|
payload: {
|
|
@@ -193,6 +224,20 @@ export function registerPersistenceTools(server, domain) {
|
|
|
193
224
|
},
|
|
194
225
|
};
|
|
195
226
|
}
|
|
227
|
+
// The backend versions sources exactly, yet nothing says which version this tree was built
|
|
228
|
+
// from (no base_version, no get_page / create_page in this session): an overwrite cannot be
|
|
229
|
+
// checked, so it is refused rather than allowed when it happens to drop no ids.
|
|
230
|
+
if (!opts.baseVersion && /^[0-9a-f]{32}$/.test(live.version ?? ""))
|
|
231
|
+
return {
|
|
232
|
+
ok: false,
|
|
233
|
+
payload: {
|
|
234
|
+
reason: "unverified_overwrite",
|
|
235
|
+
page_id: pageId,
|
|
236
|
+
live_version: live.version,
|
|
237
|
+
hint: "Nothing ties this source to a version of the page (no get_page of the whole tree in this session, no base_version), so the save cannot be checked against edits made since — it could revert them. " +
|
|
238
|
+
`Do ONE of these: (a) patch_page({ page_id, patches:[…] }) for element edits — it merges into the live tree; (b) get_page({ page_id }) (the whole tree), apply your edit to it, then update_page({ page_id, source }) — or pass that get_page's source_version as update_page's base_version; (c) to overwrite regardless, re-run ${opts.retryHint} with force:true.`,
|
|
239
|
+
},
|
|
240
|
+
};
|
|
196
241
|
// An explicit base_version comes from get_page's source_version — a real read.
|
|
197
242
|
const baseline = opts.baseVersion
|
|
198
243
|
? { fp: opts.baseVersion, origin: "read" }
|
|
@@ -516,6 +561,7 @@ export function registerPersistenceTools(server, domain) {
|
|
|
516
561
|
const publishOutcome = publish === false
|
|
517
562
|
? { published: false, skipped: true, note: "publish:false — created source-only; the preview stays blank until publish_page runs." }
|
|
518
563
|
: await autoPublish(config, outcome.page_id, outcome.rehosted_source ?? parsed);
|
|
564
|
+
await servedAfterCreate(config, outcome.page_id, outcome, publishOutcome?.published ? outcome.rehosted_source ?? parsed : undefined);
|
|
519
565
|
return text({
|
|
520
566
|
created: true,
|
|
521
567
|
...outcome,
|
|
@@ -652,9 +698,10 @@ export function registerPersistenceTools(server, domain) {
|
|
|
652
698
|
// editor after this point cannot be silently overwritten.
|
|
653
699
|
const source_version = res.version ?? sourceFingerprint(res.source);
|
|
654
700
|
rememberPageVersion(page_id, sourceFingerprint(res.source), "read");
|
|
655
|
-
rememberServed(config, page_id, res.version);
|
|
656
701
|
if (outline || element_id)
|
|
657
702
|
return narrow(res.source, { page_id, name: res.name, source_version });
|
|
703
|
+
// only a WHOLE tree handed to the model is a base an update_page tree can come from
|
|
704
|
+
rememberServed(config, page_id, res.version);
|
|
658
705
|
if (compact === false)
|
|
659
706
|
return text({ ...res, source_version });
|
|
660
707
|
return text({
|
|
@@ -732,7 +779,7 @@ export function registerPersistenceTools(server, domain) {
|
|
|
732
779
|
// loses its stale measured height, and only errors this overwrite ADDS refuse it.
|
|
733
780
|
const cfg0 = cfgFor(extra).config;
|
|
734
781
|
// no explicit base: the version of the tree get_page last handed the model
|
|
735
|
-
if (!resolvedBaseVersion && cfg0)
|
|
782
|
+
if (!resolvedBaseVersion && cfg0 && !draft_id)
|
|
736
783
|
resolvedBaseVersion = servedOf(cfg0, resolvedPageId);
|
|
737
784
|
let liveSrc = null;
|
|
738
785
|
if (cfg0 && !draft_id) {
|
|
@@ -822,7 +869,9 @@ export function registerPersistenceTools(server, domain) {
|
|
|
822
869
|
rememberServed(config, resolvedPageId, outcome.version);
|
|
823
870
|
return text({ updated: true, ...outcome, ...warningsField(result.warnings), ...(guard.notice ? { stale_check: guard.notice } : {}) });
|
|
824
871
|
}
|
|
825
|
-
|
|
872
|
+
// what the save would have stored (images re-hosted, font links) — a retry after a save that
|
|
873
|
+
// did land then matches the live tree
|
|
874
|
+
await updateDraft(existingDraftId, outcome.rehosted_source ?? expanded);
|
|
826
875
|
return text({
|
|
827
876
|
updated: false,
|
|
828
877
|
...outcome,
|
|
@@ -1573,6 +1622,8 @@ export function registerPersistenceTools(server, domain) {
|
|
|
1573
1622
|
// A page created via the fix-after-error path gets the same auto-publish
|
|
1574
1623
|
// as a direct create_page (build + publish_html so the preview renders).
|
|
1575
1624
|
const publishOutcome = outcome.ok ? await autoPublish(config, outcome.page_id, outcome.rehosted_source ?? parsed) : undefined;
|
|
1625
|
+
if (outcome.ok)
|
|
1626
|
+
await servedAfterCreate(config, outcome.page_id, outcome, publishOutcome?.published ? outcome.rehosted_source ?? parsed : undefined);
|
|
1576
1627
|
return text({
|
|
1577
1628
|
patched: outcome.ok,
|
|
1578
1629
|
created: outcome.ok,
|
|
@@ -1627,7 +1678,7 @@ export function registerPersistenceTools(server, domain) {
|
|
|
1627
1678
|
}
|
|
1628
1679
|
// against the version just read: only the changed sections travel, and an editor save that
|
|
1629
1680
|
// landed in between is refused by the backend instead of being overwritten
|
|
1630
|
-
const outcome = await updatePageSource(config, page_id, parsed, { base: liveRead?.version, before: before && domain.expand(before) });
|
|
1681
|
+
const outcome = await updatePageSource(config, page_id, parsed, { base: liveRead?.version, before: before && domain.expand(before), verified: !liveRead?.trusted });
|
|
1631
1682
|
if (outcome.page_changed) {
|
|
1632
1683
|
await deleteDraft(liveDraftId);
|
|
1633
1684
|
invalidateSource(config, page_id);
|
|
@@ -1650,8 +1701,8 @@ export function registerPersistenceTools(server, domain) {
|
|
|
1650
1701
|
...warningsField(result.warnings),
|
|
1651
1702
|
});
|
|
1652
1703
|
}
|
|
1653
|
-
// Network failure / timeout: keep the update draft for retry.
|
|
1654
|
-
await updateDraft(liveDraftId, expanded);
|
|
1704
|
+
// Network failure / timeout: keep the update draft for retry — as it would have been stored.
|
|
1705
|
+
await updateDraft(liveDraftId, outcome.rehosted_source ?? expanded);
|
|
1655
1706
|
return text({
|
|
1656
1707
|
patched: false,
|
|
1657
1708
|
patches_applied: applied, ...integrity,
|
|
@@ -1813,6 +1864,18 @@ export function registerPersistenceTools(server, domain) {
|
|
|
1813
1864
|
}
|
|
1814
1865
|
const publishOpts = { ...opts, app, app_css };
|
|
1815
1866
|
const outcome = await publishPage(config, page_id, source, publishOpts);
|
|
1867
|
+
// publish_html re-saves the source it was given (same content, the backend's own bytes → a new md5):
|
|
1868
|
+
// carry the model's base and the cache over to that version, or an update_page that follows is refused
|
|
1869
|
+
if (outcome.ok && res.version) {
|
|
1870
|
+
const expected = publishedVersion(source);
|
|
1871
|
+
if (expected !== res.version && (await probeIs(config, page_id, expected))) {
|
|
1872
|
+
if (servedOf(config, page_id) === res.version)
|
|
1873
|
+
rememberServed(config, page_id, expected);
|
|
1874
|
+
cachePageSource(sourceCacheKey(page_id, config.jwt), expected, { ...res, version: expected, source: structuredClone(source), from_cache: undefined, trusted: undefined });
|
|
1875
|
+
}
|
|
1876
|
+
else if (expected !== res.version)
|
|
1877
|
+
invalidateSource(config, page_id);
|
|
1878
|
+
}
|
|
1816
1879
|
return text({
|
|
1817
1880
|
published: outcome.ok,
|
|
1818
1881
|
// live = the PagePublishedV2 record public serving reads was written
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webcake-landing-mcp",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.7",
|
|
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",
|