@umbraco-cms/mcp-editor 17.6.0-beta.6 → 17.6.0-beta.8
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/dist/collections.js +1016 -820
- package/dist/collections.js.map +1 -1
- package/dist/index.js +1024 -829
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
import 'dotenv/config';
|
|
3
3
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
4
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
-
import { createMcpClientManager, withStandardDecorators, baseSliceNames, setServerRef, createCollectionConfigLoader, initializeUmbracoFetch, createToolResult, createToolResultError, extractChainedResult,
|
|
5
|
+
import { createMcpClientManager, withStandardDecorators, baseSliceNames, setServerRef, createCollectionConfigLoader, initializeUmbracoFetch, createToolResult, createToolResultError, extractChainedResult, requestApproval, UmbracoManagementClient, encodeCursor, getServerConfig, gatherChainedTools, shouldIncludeTool, createToolAnnotations, useDraft202012ToolSchemas } from '@umbraco-cms/mcp-server-sdk';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { statSync, readFileSync } from 'fs';
|
|
8
8
|
import { resolve } from 'path';
|
|
9
|
-
import { randomUUID } from 'crypto';
|
|
10
9
|
|
|
11
10
|
// package.json
|
|
12
11
|
var package_default = {
|
|
13
|
-
version: "17.6.0-beta.
|
|
12
|
+
version: "17.6.0-beta.8"};
|
|
14
13
|
|
|
15
14
|
// src/auth/chained-deps.generated.ts
|
|
16
15
|
var CHAINED_DEPS = {
|
|
@@ -201,6 +200,12 @@ function extractInnerProblemDetails(result) {
|
|
|
201
200
|
return parsed;
|
|
202
201
|
}
|
|
203
202
|
} catch {
|
|
203
|
+
return {
|
|
204
|
+
type: "Error",
|
|
205
|
+
title: "Chained tool error",
|
|
206
|
+
status: 500,
|
|
207
|
+
detail: `Chained CMS tool returned a non-JSON error: ${text}`
|
|
208
|
+
};
|
|
204
209
|
}
|
|
205
210
|
}
|
|
206
211
|
}
|
|
@@ -211,12 +216,28 @@ function extractInnerProblemDetails(result) {
|
|
|
211
216
|
detail: "Chained CMS tool returned an error with no structured details."
|
|
212
217
|
};
|
|
213
218
|
}
|
|
219
|
+
function truncateAvailableTools(message) {
|
|
220
|
+
const availableToolsIndex = message.indexOf(". Available tools");
|
|
221
|
+
if (availableToolsIndex === -1 || !message.includes("Tool not found:")) {
|
|
222
|
+
return message;
|
|
223
|
+
}
|
|
224
|
+
return message.slice(0, availableToolsIndex + 1);
|
|
225
|
+
}
|
|
226
|
+
async function isCmsToolAvailable(toolName) {
|
|
227
|
+
try {
|
|
228
|
+
const { tools } = await mcpClientManager.listTools("cms");
|
|
229
|
+
return (tools ?? []).some((t) => t.name === toolName);
|
|
230
|
+
} catch {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
214
234
|
async function chainCms(toolName, args) {
|
|
215
235
|
let result;
|
|
216
236
|
try {
|
|
217
237
|
result = await mcpClientManager.callTool("cms", toolName, args);
|
|
218
238
|
} catch (error) {
|
|
219
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
239
|
+
const message = truncateAvailableTools(error instanceof Error ? error.message : String(error));
|
|
240
|
+
console.warn(`Chained CMS tool "${toolName}" failed: ${message}`);
|
|
220
241
|
return {
|
|
221
242
|
ok: false,
|
|
222
243
|
errorResult: createToolResultError({
|
|
@@ -233,78 +254,21 @@ async function chainCms(toolName, args) {
|
|
|
233
254
|
}
|
|
234
255
|
return { ok: true, data: extractChainedResult(result) };
|
|
235
256
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const stripped = stripHtml(text);
|
|
244
|
-
if (!stripped) return 0;
|
|
245
|
-
return stripped.split(/\s+/).filter(Boolean).length;
|
|
246
|
-
}
|
|
247
|
-
function extractTextFromBlockValues(innerValues) {
|
|
248
|
-
const parts = [];
|
|
249
|
-
for (const v of innerValues || []) {
|
|
250
|
-
const text = extractTextFromValue(v.value, v.editorAlias);
|
|
251
|
-
if (text) parts.push(text);
|
|
252
|
-
}
|
|
253
|
-
return parts.join(" ");
|
|
254
|
-
}
|
|
255
|
-
function extractTextFromValue(value, editorAlias) {
|
|
256
|
-
if (typeof value === "string") {
|
|
257
|
-
return stripHtml(value);
|
|
258
|
-
}
|
|
259
|
-
if (value && typeof value === "object" && typeof value.markup === "string") {
|
|
260
|
-
const markupText = stripHtml(value.markup);
|
|
261
|
-
const blockText = extractTextFromContentData(value.blocks?.contentData);
|
|
262
|
-
return [markupText, blockText].filter(Boolean).join(" ");
|
|
263
|
-
}
|
|
264
|
-
if (value && typeof value === "object" && Array.isArray(value.contentData)) {
|
|
265
|
-
return extractTextFromContentData(value.contentData);
|
|
266
|
-
}
|
|
267
|
-
return "";
|
|
268
|
-
}
|
|
269
|
-
function extractTextFromContentData(contentData) {
|
|
270
|
-
const parts = [];
|
|
271
|
-
for (const block of contentData || []) {
|
|
272
|
-
const blockText = extractTextFromBlockValues(block.values || []);
|
|
273
|
-
if (blockText) parts.push(blockText);
|
|
274
|
-
}
|
|
275
|
-
return parts.join(" ");
|
|
276
|
-
}
|
|
277
|
-
function extractTextContent(values) {
|
|
278
|
-
const parts = [];
|
|
279
|
-
for (const v of values || []) {
|
|
280
|
-
const text = extractTextFromValue(v.value, v.editorAlias);
|
|
281
|
-
if (text) parts.push(text);
|
|
282
|
-
}
|
|
283
|
-
return parts.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
|
|
284
|
-
}
|
|
285
|
-
function extractHeadings(html) {
|
|
286
|
-
const headings = [];
|
|
287
|
-
const regex = /<h([1-6])[^>]*>(.*?)<\/h[1-6]>/gi;
|
|
288
|
-
let match;
|
|
289
|
-
while ((match = regex.exec(html)) !== null) {
|
|
290
|
-
headings.push({ level: parseInt(match[1]), text: stripHtml(match[2]) });
|
|
291
|
-
}
|
|
292
|
-
return headings;
|
|
257
|
+
var DEFAULT_PROVIDER_ALIAS = "umbDocumentUrlProvider";
|
|
258
|
+
var URL_BATCH_CHUNK_SIZE = 40;
|
|
259
|
+
function describeChainError(errorResult) {
|
|
260
|
+
const problem = extractInnerProblemDetails(errorResult);
|
|
261
|
+
const title = typeof problem.title === "string" ? problem.title : void 0;
|
|
262
|
+
const detail = typeof problem.detail === "string" ? problem.detail : void 0;
|
|
263
|
+
return [title, detail].filter(Boolean).join(": ") || "unknown error";
|
|
293
264
|
}
|
|
294
|
-
function
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
while ((match = regex.exec(html)) !== null) {
|
|
299
|
-
const srcMatch = match[0].match(/src="([^"]*)"/i);
|
|
300
|
-
const altMatch = match[0].match(/alt="([^"]*)"/i);
|
|
301
|
-
const src = srcMatch?.[1] ?? "";
|
|
302
|
-
const alt = altMatch?.[1] ?? "";
|
|
303
|
-
images.push({ src, alt, hasAlt: !!altMatch && alt.length > 0 });
|
|
265
|
+
function chunkIds(ids, size) {
|
|
266
|
+
const chunks = [];
|
|
267
|
+
for (let i = 0; i < ids.length; i += size) {
|
|
268
|
+
chunks.push(ids.slice(i, i + size));
|
|
304
269
|
}
|
|
305
|
-
return
|
|
270
|
+
return chunks;
|
|
306
271
|
}
|
|
307
|
-
var DEFAULT_PROVIDER_ALIAS = "umbDocumentUrlProvider";
|
|
308
272
|
var cachedBaseUrl = null;
|
|
309
273
|
var cachedMtimeMs = null;
|
|
310
274
|
function readBaseUrlFromEnvFile(envPath) {
|
|
@@ -410,26 +374,131 @@ function flattenPublishedUrls(urls) {
|
|
|
410
374
|
async function fetchPublishedUrls(id) {
|
|
411
375
|
try {
|
|
412
376
|
const result = await chainCms("get-document-urls", { id: [id] });
|
|
413
|
-
if (!result.ok)
|
|
377
|
+
if (!result.ok) {
|
|
378
|
+
console.warn(
|
|
379
|
+
`fetchPublishedUrls: get-document-urls failed for id ${id} \u2014 returning no published URLs: ${describeChainError(result.errorResult)}`
|
|
380
|
+
);
|
|
381
|
+
return [];
|
|
382
|
+
}
|
|
414
383
|
return flattenPublishedUrls(result.data.items);
|
|
415
|
-
} catch {
|
|
384
|
+
} catch (error) {
|
|
385
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
386
|
+
console.warn(
|
|
387
|
+
`fetchPublishedUrls: unexpected error fetching published URLs for id ${id} \u2014 returning no published URLs: ${message}`
|
|
388
|
+
);
|
|
416
389
|
return [];
|
|
417
390
|
}
|
|
418
391
|
}
|
|
419
392
|
async function fetchPublishedUrlsBatch(ids) {
|
|
420
393
|
const out = /* @__PURE__ */ new Map();
|
|
421
394
|
if (ids.length === 0) return out;
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
395
|
+
for (const idChunk of chunkIds(ids, URL_BATCH_CHUNK_SIZE)) {
|
|
396
|
+
try {
|
|
397
|
+
const result = await chainCms("get-document-urls", { id: idChunk });
|
|
398
|
+
if (!result.ok) {
|
|
399
|
+
console.warn(
|
|
400
|
+
`fetchPublishedUrlsBatch: get-document-urls failed for a chunk of ${idChunk.length} ids \u2014 those ids will have no published URL: ${describeChainError(result.errorResult)}`
|
|
401
|
+
);
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
for (const entry of result.data.items ?? []) {
|
|
405
|
+
if (!entry?.id) continue;
|
|
406
|
+
out.set(entry.id, flattenPublishedUrls([entry]));
|
|
407
|
+
}
|
|
408
|
+
} catch (error) {
|
|
409
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
410
|
+
console.warn(
|
|
411
|
+
`fetchPublishedUrlsBatch: unexpected error processing a chunk of ${idChunk.length} ids \u2014 those ids will have no published URL: ${message}`
|
|
412
|
+
);
|
|
428
413
|
}
|
|
429
|
-
} catch {
|
|
430
414
|
}
|
|
431
415
|
return out;
|
|
432
416
|
}
|
|
417
|
+
async function fetchPrimaryPublishedUrl(id) {
|
|
418
|
+
const urls = await fetchPublishedUrls(id);
|
|
419
|
+
return urls[0] ?? "";
|
|
420
|
+
}
|
|
421
|
+
async function fetchPrimaryPublishedUrlsBatch(ids) {
|
|
422
|
+
const batch = await fetchPublishedUrlsBatch(ids);
|
|
423
|
+
const out = /* @__PURE__ */ new Map();
|
|
424
|
+
for (const id of ids) {
|
|
425
|
+
out.set(id, batch.get(id)?.[0] ?? "");
|
|
426
|
+
}
|
|
427
|
+
return out;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// src/umbraco-api/tools/helpers/tree-walker.ts
|
|
431
|
+
function buildChainedCursor(skip, take) {
|
|
432
|
+
return encodeCursor({ s: skip, t: take });
|
|
433
|
+
}
|
|
434
|
+
function stripHtml(html) {
|
|
435
|
+
return (html || "").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
436
|
+
}
|
|
437
|
+
function countWords(text) {
|
|
438
|
+
const stripped = stripHtml(text);
|
|
439
|
+
if (!stripped) return 0;
|
|
440
|
+
return stripped.split(/\s+/).filter(Boolean).length;
|
|
441
|
+
}
|
|
442
|
+
function extractTextFromBlockValues(innerValues) {
|
|
443
|
+
const parts = [];
|
|
444
|
+
for (const v of innerValues || []) {
|
|
445
|
+
const text = extractTextFromValue(v.value, v.editorAlias);
|
|
446
|
+
if (text) parts.push(text);
|
|
447
|
+
}
|
|
448
|
+
return parts.join(" ");
|
|
449
|
+
}
|
|
450
|
+
function extractTextFromValue(value, editorAlias) {
|
|
451
|
+
if (typeof value === "string") {
|
|
452
|
+
return stripHtml(value);
|
|
453
|
+
}
|
|
454
|
+
if (value && typeof value === "object" && typeof value.markup === "string") {
|
|
455
|
+
const markupText = stripHtml(value.markup);
|
|
456
|
+
const blockText = extractTextFromContentData(value.blocks?.contentData);
|
|
457
|
+
return [markupText, blockText].filter(Boolean).join(" ");
|
|
458
|
+
}
|
|
459
|
+
if (value && typeof value === "object" && Array.isArray(value.contentData)) {
|
|
460
|
+
return extractTextFromContentData(value.contentData);
|
|
461
|
+
}
|
|
462
|
+
return "";
|
|
463
|
+
}
|
|
464
|
+
function extractTextFromContentData(contentData) {
|
|
465
|
+
const parts = [];
|
|
466
|
+
for (const block of contentData || []) {
|
|
467
|
+
const blockText = extractTextFromBlockValues(block.values || []);
|
|
468
|
+
if (blockText) parts.push(blockText);
|
|
469
|
+
}
|
|
470
|
+
return parts.join(" ");
|
|
471
|
+
}
|
|
472
|
+
function extractTextContent(values) {
|
|
473
|
+
const parts = [];
|
|
474
|
+
for (const v of values || []) {
|
|
475
|
+
const text = extractTextFromValue(v.value, v.editorAlias);
|
|
476
|
+
if (text) parts.push(text);
|
|
477
|
+
}
|
|
478
|
+
return parts.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
|
|
479
|
+
}
|
|
480
|
+
function extractHeadings(html) {
|
|
481
|
+
const headings = [];
|
|
482
|
+
const regex = /<h([1-6])[^>]*>(.*?)<\/h[1-6]>/gi;
|
|
483
|
+
let match;
|
|
484
|
+
while ((match = regex.exec(html)) !== null) {
|
|
485
|
+
headings.push({ level: parseInt(match[1]), text: stripHtml(match[2]) });
|
|
486
|
+
}
|
|
487
|
+
return headings;
|
|
488
|
+
}
|
|
489
|
+
function extractImages(html) {
|
|
490
|
+
const images = [];
|
|
491
|
+
const regex = /<img[^>]*>/gi;
|
|
492
|
+
let match;
|
|
493
|
+
while ((match = regex.exec(html)) !== null) {
|
|
494
|
+
const srcMatch = match[0].match(/src="([^"]*)"/i);
|
|
495
|
+
const altMatch = match[0].match(/alt="([^"]*)"/i);
|
|
496
|
+
const src = srcMatch?.[1] ?? "";
|
|
497
|
+
const alt = altMatch?.[1] ?? "";
|
|
498
|
+
images.push({ src, alt, hasAlt: !!altMatch && alt.length > 0 });
|
|
499
|
+
}
|
|
500
|
+
return images;
|
|
501
|
+
}
|
|
433
502
|
|
|
434
503
|
// src/umbraco-api/tools/content/get/search-content.ts
|
|
435
504
|
var inputSchema = {
|
|
@@ -448,7 +517,7 @@ var outputSchema = z.object({
|
|
|
448
517
|
});
|
|
449
518
|
var tool = {
|
|
450
519
|
name: "search-content",
|
|
451
|
-
description: "Search for content pages by name or
|
|
520
|
+
description: "Search for content pages by name only \u2014 it does not match body text or other field values (tracked in #234). Returns a list of matching pages with their names and IDs. For body text, use list-children + get-page instead. Use get-page with an ID from the results to retrieve full page content.",
|
|
452
521
|
inputSchema,
|
|
453
522
|
outputSchema,
|
|
454
523
|
slices: ["search"],
|
|
@@ -524,8 +593,10 @@ var tool2 = {
|
|
|
524
593
|
})),
|
|
525
594
|
variants: doc.variants ?? [],
|
|
526
595
|
previewUrl: buildPreviewUrl(doc.id),
|
|
527
|
-
//
|
|
528
|
-
|
|
596
|
+
// The get-document-by-id response doesn't carry `urls` — published
|
|
597
|
+
// URLs come only from the separate get-document-urls endpoint via
|
|
598
|
+
// fetchPublishedUrls.
|
|
599
|
+
publishedUrls: await fetchPublishedUrls(id)
|
|
529
600
|
});
|
|
530
601
|
}
|
|
531
602
|
};
|
|
@@ -571,6 +642,19 @@ var tool3 = {
|
|
|
571
642
|
}
|
|
572
643
|
};
|
|
573
644
|
var list_children_default = withStandardDecorators(tool3);
|
|
645
|
+
|
|
646
|
+
// src/auth/auth-policies.ts
|
|
647
|
+
var sections = {
|
|
648
|
+
settings: "Umb.Section.Settings"};
|
|
649
|
+
|
|
650
|
+
// src/umbraco-api/tools/helpers/settings-access.ts
|
|
651
|
+
async function checkSettingsAccess() {
|
|
652
|
+
const result = await chainCms("get-user-current", {});
|
|
653
|
+
if (!result.ok) return result;
|
|
654
|
+
return { ok: true, hasAccess: result.data.allowedSections?.includes(sections.settings) ?? false };
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/umbraco-api/tools/content/get/list-document-types.ts
|
|
574
658
|
var inputSchema4 = {
|
|
575
659
|
take: z.number().optional().default(50).describe("Number of results to return"),
|
|
576
660
|
skip: z.number().optional().default(0).describe("Number of results to skip")
|
|
@@ -593,11 +677,14 @@ async function collectDocumentTypeIds() {
|
|
|
593
677
|
let result;
|
|
594
678
|
while (true) {
|
|
595
679
|
result = parentId ? await chainCms("get-document-type-children", { parentId, cursor }) : await chainCms("get-document-type-root", { cursor });
|
|
596
|
-
if (!result.ok) return;
|
|
680
|
+
if (!result.ok) return { ok: false, errorResult: result.errorResult };
|
|
597
681
|
const items = result.data.items ?? [];
|
|
598
682
|
for (const item of items) {
|
|
599
683
|
if (item.isFolder) {
|
|
600
|
-
if (item.hasChildren)
|
|
684
|
+
if (item.hasChildren) {
|
|
685
|
+
const childResult = await walk(item.id);
|
|
686
|
+
if (childResult && !childResult.ok) return childResult;
|
|
687
|
+
}
|
|
601
688
|
} else {
|
|
602
689
|
collected.push(item);
|
|
603
690
|
}
|
|
@@ -606,26 +693,35 @@ async function collectDocumentTypeIds() {
|
|
|
606
693
|
if (!nextCursor) break;
|
|
607
694
|
cursor = nextCursor;
|
|
608
695
|
}
|
|
696
|
+
return void 0;
|
|
609
697
|
}
|
|
610
|
-
await walk(void 0);
|
|
611
|
-
return
|
|
698
|
+
const failure = await walk(void 0);
|
|
699
|
+
if (failure && !failure.ok) return failure;
|
|
700
|
+
return { ok: true, nodes: collected };
|
|
612
701
|
}
|
|
613
702
|
async function resolveDocTypeDetails(nodes) {
|
|
614
703
|
const results = await Promise.all(
|
|
615
704
|
nodes.map(async (node) => {
|
|
616
705
|
const detailResult = await chainCms("get-document-type-by-id", { id: node.id });
|
|
617
|
-
if (!detailResult.ok) return
|
|
706
|
+
if (!detailResult.ok) return { ok: false, errorResult: detailResult.errorResult, node };
|
|
618
707
|
const d = detailResult.data;
|
|
619
708
|
return {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
709
|
+
ok: true,
|
|
710
|
+
details: [{
|
|
711
|
+
id: node.id,
|
|
712
|
+
alias: d.alias ?? "",
|
|
713
|
+
name: d.name ?? node.name,
|
|
714
|
+
description: d.description ?? void 0,
|
|
715
|
+
icon: d.icon ?? node.icon
|
|
716
|
+
}],
|
|
717
|
+
node
|
|
625
718
|
};
|
|
626
719
|
})
|
|
627
720
|
);
|
|
628
|
-
|
|
721
|
+
const failed = results.find((r) => !r.ok);
|
|
722
|
+
if (failed && !failed.ok) return { ok: false, errorResult: failed.errorResult };
|
|
723
|
+
const details = results.flatMap((r) => r.ok ? r.details : []);
|
|
724
|
+
return { ok: true, details };
|
|
629
725
|
}
|
|
630
726
|
var tool4 = {
|
|
631
727
|
name: "list-document-types",
|
|
@@ -635,9 +731,22 @@ var tool4 = {
|
|
|
635
731
|
slices: ["list"],
|
|
636
732
|
annotations: { readOnlyHint: true },
|
|
637
733
|
handler: async ({ take, skip }) => {
|
|
638
|
-
const
|
|
734
|
+
const accessCheck = await checkSettingsAccess();
|
|
735
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
736
|
+
if (!accessCheck.hasAccess) {
|
|
737
|
+
return createToolResultError({
|
|
738
|
+
status: 403,
|
|
739
|
+
title: "Settings access required",
|
|
740
|
+
detail: "Listing document types requires the signed-in Umbraco user to have access to the Settings section. Grant Settings-section access to the user's group in the Umbraco backoffice (Users \u2192 [group] \u2192 Sections), then retry."
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
const treeResult = await collectDocumentTypeIds();
|
|
744
|
+
if (!treeResult.ok) return treeResult.errorResult;
|
|
745
|
+
const { nodes } = treeResult;
|
|
639
746
|
const sliced = nodes.slice(skip, skip + take);
|
|
640
|
-
const
|
|
747
|
+
const detailsResult = await resolveDocTypeDetails(sliced);
|
|
748
|
+
if (!detailsResult.ok) return detailsResult.errorResult;
|
|
749
|
+
const { details } = detailsResult;
|
|
641
750
|
return createToolResult({
|
|
642
751
|
items: details.map((d) => ({
|
|
643
752
|
id: d.id,
|
|
@@ -651,6 +760,73 @@ var tool4 = {
|
|
|
651
760
|
}
|
|
652
761
|
};
|
|
653
762
|
var list_document_types_default = withStandardDecorators(tool4);
|
|
763
|
+
|
|
764
|
+
// src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
|
|
765
|
+
async function resolveDocumentTypeProperties(documentTypeId) {
|
|
766
|
+
const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
|
|
767
|
+
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
768
|
+
const data = docTypeResult.data;
|
|
769
|
+
const collected = /* @__PURE__ */ new Map();
|
|
770
|
+
function addProperties(props) {
|
|
771
|
+
for (const p of props) {
|
|
772
|
+
if (p.alias && !collected.has(p.alias)) {
|
|
773
|
+
collected.set(p.alias, p);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function compositionIdsOf(d) {
|
|
778
|
+
return Array.from(
|
|
779
|
+
new Set(
|
|
780
|
+
(d.compositions ?? []).map((c) => c.documentType?.id).filter((id) => typeof id === "string")
|
|
781
|
+
)
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
function describeFailure(errorResult) {
|
|
785
|
+
const text = errorResult.content?.[0]?.type === "text" ? errorResult.content[0].text : void 0;
|
|
786
|
+
if (!text) return "unknown error";
|
|
787
|
+
try {
|
|
788
|
+
const parsed = JSON.parse(text);
|
|
789
|
+
const detail = parsed?.detail;
|
|
790
|
+
return typeof detail === "string" ? detail : text;
|
|
791
|
+
} catch {
|
|
792
|
+
return text;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
addProperties(Array.isArray(data.properties) ? data.properties : []);
|
|
796
|
+
const visited = /* @__PURE__ */ new Set([documentTypeId]);
|
|
797
|
+
const failedCompositionIds = [];
|
|
798
|
+
const failedCompositionDetails = [];
|
|
799
|
+
let frontier = compositionIdsOf(data).filter((id) => !visited.has(id));
|
|
800
|
+
frontier.forEach((id) => visited.add(id));
|
|
801
|
+
while (frontier.length > 0) {
|
|
802
|
+
const results = await Promise.all(frontier.map((id) => chainCms("get-document-type-by-id", { id })));
|
|
803
|
+
const nextFrontier = [];
|
|
804
|
+
results.forEach((r, i) => {
|
|
805
|
+
if (!r.ok) {
|
|
806
|
+
failedCompositionIds.push(frontier[i]);
|
|
807
|
+
failedCompositionDetails.push(describeFailure(r.errorResult));
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
if (Array.isArray(r.data.properties)) addProperties(r.data.properties);
|
|
811
|
+
for (const id of compositionIdsOf(r.data)) {
|
|
812
|
+
if (!visited.has(id)) {
|
|
813
|
+
visited.add(id);
|
|
814
|
+
nextFrontier.push(id);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
frontier = nextFrontier;
|
|
819
|
+
}
|
|
820
|
+
return {
|
|
821
|
+
ok: true,
|
|
822
|
+
documentType: data,
|
|
823
|
+
properties: Array.from(collected.values()),
|
|
824
|
+
failedCompositionIds,
|
|
825
|
+
failedCompositionDetails
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// src/umbraco-api/tools/content/get/get-document-type.ts
|
|
654
830
|
var inputSchema5 = {
|
|
655
831
|
id: z.string().uuid().describe("UUID of the document type to retrieve")
|
|
656
832
|
};
|
|
@@ -678,30 +854,9 @@ var tool5 = {
|
|
|
678
854
|
slices: ["read"],
|
|
679
855
|
annotations: { readOnlyHint: true },
|
|
680
856
|
handler: async ({ id }) => {
|
|
681
|
-
const result = await
|
|
857
|
+
const result = await resolveDocumentTypeProperties(id);
|
|
682
858
|
if (!result.ok) return result.errorResult;
|
|
683
|
-
const data = result
|
|
684
|
-
const collected = /* @__PURE__ */ new Map();
|
|
685
|
-
function addProperties(props) {
|
|
686
|
-
for (const p of props) {
|
|
687
|
-
if (p.alias && !collected.has(p.alias)) {
|
|
688
|
-
collected.set(p.alias, p);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
addProperties(Array.isArray(data.properties) ? data.properties : []);
|
|
693
|
-
const compositionIds = (data.compositions ?? []).map((c) => c.document?.id ?? c.documentType?.id ?? c.id).filter((cid) => typeof cid === "string");
|
|
694
|
-
if (compositionIds.length > 0) {
|
|
695
|
-
const compositions = await Promise.all(
|
|
696
|
-
compositionIds.map(async (cid) => {
|
|
697
|
-
const r = await chainCms("get-document-type-by-id", { id: cid });
|
|
698
|
-
return r.ok ? r.data : null;
|
|
699
|
-
})
|
|
700
|
-
);
|
|
701
|
-
for (const comp of compositions) {
|
|
702
|
-
if (comp && Array.isArray(comp.properties)) addProperties(comp.properties);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
859
|
+
const { documentType: data, properties } = result;
|
|
705
860
|
return createToolResult({
|
|
706
861
|
id: data.id ?? id,
|
|
707
862
|
alias: data.alias ?? "",
|
|
@@ -709,7 +864,7 @@ var tool5 = {
|
|
|
709
864
|
description: data.description || void 0,
|
|
710
865
|
variesByCulture: data.variesByCulture || void 0,
|
|
711
866
|
variesBySegment: data.variesBySegment || void 0,
|
|
712
|
-
properties:
|
|
867
|
+
properties: properties.map((p) => ({
|
|
713
868
|
alias: p.alias ?? "",
|
|
714
869
|
name: p.name ?? p.alias ?? "",
|
|
715
870
|
description: p.description || void 0,
|
|
@@ -721,66 +876,294 @@ var tool5 = {
|
|
|
721
876
|
}
|
|
722
877
|
};
|
|
723
878
|
var get_document_type_default = withStandardDecorators(tool5);
|
|
724
|
-
var
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
previewUrl: previewUrlSchema,
|
|
732
|
-
blockProperties: z.array(z.object({
|
|
733
|
-
propertyAlias: z.string().describe("The document property containing these blocks"),
|
|
734
|
-
editorAlias: z.string().optional(),
|
|
735
|
-
blocks: z.array(z.object({
|
|
736
|
-
contentKey: z.string().describe("The block's unique key \u2014 use this with edit-block"),
|
|
737
|
-
contentTypeKey: z.string().describe("The block's element type ID"),
|
|
738
|
-
properties: z.array(z.object({
|
|
739
|
-
alias: z.string(),
|
|
740
|
-
value: z.any()
|
|
741
|
-
}))
|
|
742
|
-
}))
|
|
743
|
-
}))
|
|
879
|
+
var validationErrorSchema = z.object({
|
|
880
|
+
propertyAlias: z.string().describe(
|
|
881
|
+
"The alias of the property that failed validation, or '__document__' for document-level errors (mandatory cultures, name length, etc.)."
|
|
882
|
+
),
|
|
883
|
+
culture: z.string().nullable().optional().describe("Culture for variant content. Null for invariant."),
|
|
884
|
+
segment: z.string().nullable().optional().describe("Segment for segmented content. Null when none."),
|
|
885
|
+
message: z.string().describe("Human-readable validation error message.")
|
|
744
886
|
});
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
887
|
+
var validationResultSchema = z.object({
|
|
888
|
+
valid: z.boolean().describe("True when the saved document passes server-side validation and is publishable."),
|
|
889
|
+
errors: z.array(validationErrorSchema).describe(
|
|
890
|
+
"Property-level validation errors. Empty when `valid` is true. Each entry names the offending propertyAlias/culture/segment and a human message \u2014 surface these back to the editor so they know what to fix before publishing."
|
|
891
|
+
)
|
|
892
|
+
}).describe(
|
|
893
|
+
"Server-side validation outcome for the saved document. A 200 OK on save does NOT imply publishability \u2014 Umbraco only enforces required fields, regex, length, etc. via this validation endpoint. When `valid` is false the changes ARE persisted as a draft but the document cannot be published until the listed errors are resolved."
|
|
894
|
+
);
|
|
895
|
+
async function validateDocumentState(id, doc) {
|
|
896
|
+
let target = null;
|
|
897
|
+
if (!target) {
|
|
898
|
+
const docResult = await chainCms("get-document-by-id", { id });
|
|
899
|
+
if (!docResult.ok) {
|
|
900
|
+
return {
|
|
901
|
+
valid: false,
|
|
902
|
+
errors: [
|
|
903
|
+
{
|
|
904
|
+
propertyAlias: "__document__",
|
|
905
|
+
message: "Could not refetch document to run validation."
|
|
906
|
+
}
|
|
907
|
+
]
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
target = docResult.data;
|
|
911
|
+
}
|
|
912
|
+
const values = (target.values ?? []).map((v) => ({
|
|
913
|
+
alias: v.alias,
|
|
914
|
+
value: v.value,
|
|
915
|
+
culture: v.culture ?? null,
|
|
916
|
+
segment: v.segment ?? null
|
|
917
|
+
}));
|
|
918
|
+
const variants = (target.variants ?? []).map((v) => ({
|
|
919
|
+
name: v.name,
|
|
920
|
+
culture: v.culture ?? null,
|
|
921
|
+
segment: v.segment ?? null
|
|
922
|
+
}));
|
|
923
|
+
const ancestorsResult = await chainCms("get-document-ancestors", { descendantId: id });
|
|
924
|
+
const parent = ancestorsResult.ok ? (ancestorsResult.data.items ?? []).find((item) => item.id === id)?.parent ?? null : null;
|
|
925
|
+
const result = await chainCms("validate-document", {
|
|
926
|
+
id,
|
|
927
|
+
documentType: { id: target.documentType.id },
|
|
928
|
+
template: target.template ? { id: target.template.id } : null,
|
|
929
|
+
parent,
|
|
930
|
+
values,
|
|
931
|
+
variants
|
|
932
|
+
});
|
|
933
|
+
if (result.ok) {
|
|
934
|
+
return { valid: true, errors: [] };
|
|
935
|
+
}
|
|
936
|
+
return { valid: false, errors: parseValidationErrors(result.errorResult, values) };
|
|
937
|
+
}
|
|
938
|
+
function parseValidationErrors(errorResult, requestValues) {
|
|
939
|
+
const structured = extractStructured(errorResult);
|
|
940
|
+
if (!structured) {
|
|
941
|
+
return [
|
|
942
|
+
{
|
|
943
|
+
propertyAlias: "__document__",
|
|
944
|
+
message: stringifyErrorFallback(errorResult)
|
|
945
|
+
}
|
|
946
|
+
];
|
|
947
|
+
}
|
|
948
|
+
const errors = structured.errors;
|
|
949
|
+
if (!errors || typeof errors !== "object") {
|
|
950
|
+
return [
|
|
951
|
+
{
|
|
952
|
+
propertyAlias: "__document__",
|
|
953
|
+
message: stringifyFromProblemDetails(structured)
|
|
954
|
+
}
|
|
955
|
+
];
|
|
956
|
+
}
|
|
957
|
+
const out = [];
|
|
958
|
+
for (const [jsonPath, messages] of Object.entries(errors)) {
|
|
959
|
+
const messageList = Array.isArray(messages) ? messages : [String(messages)];
|
|
960
|
+
const resolved = resolveJsonPath(jsonPath, requestValues);
|
|
961
|
+
for (const message of messageList) {
|
|
962
|
+
out.push({
|
|
963
|
+
propertyAlias: resolved.propertyAlias,
|
|
964
|
+
culture: resolved.culture,
|
|
965
|
+
segment: resolved.segment,
|
|
966
|
+
message: String(message)
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
if (out.length === 0) {
|
|
971
|
+
out.push({
|
|
972
|
+
propertyAlias: "__document__",
|
|
973
|
+
message: stringifyFromProblemDetails(structured)
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
return out;
|
|
977
|
+
}
|
|
978
|
+
var VALUES_PATH = /^\$\.values\[(\d+)\](?:\.value)?(.*)$/;
|
|
979
|
+
function resolveJsonPath(jsonPath, requestValues) {
|
|
980
|
+
const match = jsonPath.match(VALUES_PATH);
|
|
981
|
+
if (match) {
|
|
982
|
+
const index = Number(match[1]);
|
|
983
|
+
const entry = requestValues[index];
|
|
984
|
+
if (entry) {
|
|
985
|
+
const trailing = match[2]?.replace(/^\./, "");
|
|
986
|
+
return {
|
|
987
|
+
propertyAlias: trailing ? `${entry.alias}${match[2]}` : entry.alias,
|
|
988
|
+
culture: entry.culture,
|
|
989
|
+
segment: entry.segment
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return { propertyAlias: jsonPath, culture: null, segment: null };
|
|
994
|
+
}
|
|
995
|
+
function extractStructured(errorResult) {
|
|
996
|
+
if (!errorResult || typeof errorResult !== "object") return null;
|
|
997
|
+
const r = errorResult;
|
|
998
|
+
if (r.structuredContent && typeof r.structuredContent === "object") {
|
|
999
|
+
return r.structuredContent;
|
|
1000
|
+
}
|
|
1001
|
+
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
1002
|
+
if (text) {
|
|
1003
|
+
try {
|
|
1004
|
+
const parsed = JSON.parse(text);
|
|
1005
|
+
if (parsed && typeof parsed === "object") {
|
|
1006
|
+
return parsed;
|
|
1007
|
+
}
|
|
1008
|
+
} catch {
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
return null;
|
|
1012
|
+
}
|
|
1013
|
+
function stringifyFromProblemDetails(pd) {
|
|
1014
|
+
if (pd.detail && typeof pd.detail === "string") return pd.detail;
|
|
1015
|
+
if (pd.title && typeof pd.title === "string") return pd.title;
|
|
1016
|
+
return "Document failed validation but no detail was returned.";
|
|
1017
|
+
}
|
|
1018
|
+
function stringifyErrorFallback(errorResult) {
|
|
1019
|
+
if (!errorResult || typeof errorResult !== "object") return "Document failed validation.";
|
|
1020
|
+
const r = errorResult;
|
|
1021
|
+
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
1022
|
+
return text ? text : "Document failed validation.";
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
// src/umbraco-api/tools/helpers/block-builder.ts
|
|
1026
|
+
async function toBlockProperties(elementTypeKey, values, culture, segment) {
|
|
1027
|
+
if (values.length === 0) return { ok: true, properties: [] };
|
|
1028
|
+
const docTypeResult = await chainCms("get-document-type-by-id", { id: elementTypeKey });
|
|
1029
|
+
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
1030
|
+
const definitions = new Map(docTypeResult.data.properties.map((p) => [p.alias, p]));
|
|
1031
|
+
return {
|
|
1032
|
+
ok: true,
|
|
1033
|
+
properties: values.map((v) => {
|
|
1034
|
+
const def = definitions.get(v.alias);
|
|
1035
|
+
return {
|
|
1036
|
+
alias: v.alias,
|
|
1037
|
+
value: v.value,
|
|
1038
|
+
culture: def?.variesByCulture ? culture : null,
|
|
1039
|
+
segment: def?.variesBySegment ? segment : null
|
|
1040
|
+
};
|
|
1041
|
+
})
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
async function toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, culture, segment) {
|
|
1045
|
+
const content = await toBlockProperties(contentTypeKey, values, culture, segment);
|
|
1046
|
+
if (!content.ok) return content;
|
|
1047
|
+
if (!settingsTypeKey || !settingsValues) return { ok: true, properties: content.properties };
|
|
1048
|
+
const settings = await toBlockProperties(settingsTypeKey, settingsValues, culture, segment);
|
|
1049
|
+
if (!settings.ok) return settings;
|
|
1050
|
+
return { ok: true, properties: content.properties, settings: { properties: settings.properties } };
|
|
1051
|
+
}
|
|
1052
|
+
function toPlacement(position) {
|
|
1053
|
+
return position.mode === "before" || position.mode === "after" ? { position: position.mode, contentKey: position.anchorContentKey } : { position: position.mode };
|
|
1054
|
+
}
|
|
1055
|
+
async function buildBlockWriteResult(id, pageName, contentKey, baseMessage) {
|
|
1056
|
+
const validation = await validateDocumentState(id);
|
|
1057
|
+
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1058
|
+
return createToolResult({
|
|
1059
|
+
message,
|
|
1060
|
+
id,
|
|
1061
|
+
name: pageName,
|
|
1062
|
+
contentKey,
|
|
1063
|
+
previewUrl: await fetchPreviewUrl(id),
|
|
1064
|
+
validation
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
function isBlockListOrGridValue(value) {
|
|
1068
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
1069
|
+
}
|
|
1070
|
+
function isRteWithBlocks(value) {
|
|
1071
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.markup === "string" && value.blocks !== null && typeof value.blocks === "object" && Array.isArray(value.blocks?.contentData);
|
|
1072
|
+
}
|
|
1073
|
+
function findSettingsKey(container, contentKey) {
|
|
1074
|
+
const layout = container?.layout;
|
|
1075
|
+
if (!layout || typeof layout !== "object") return void 0;
|
|
1076
|
+
return searchLayout(Object.values(layout), contentKey);
|
|
1077
|
+
}
|
|
1078
|
+
function searchLayout(entries, contentKey) {
|
|
1079
|
+
for (const entry of entries) {
|
|
1080
|
+
if (Array.isArray(entry)) {
|
|
1081
|
+
const found = searchLayout(entry, contentKey);
|
|
1082
|
+
if (found) return found;
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1085
|
+
if (!entry || typeof entry !== "object") continue;
|
|
1086
|
+
const candidate = entry;
|
|
1087
|
+
if (candidate.contentKey === contentKey) {
|
|
1088
|
+
return typeof candidate.settingsKey === "string" && candidate.settingsKey.length > 0 ? candidate.settingsKey : void 0;
|
|
1089
|
+
}
|
|
1090
|
+
for (const nested of [candidate.areas, candidate.items]) {
|
|
1091
|
+
if (Array.isArray(nested)) {
|
|
1092
|
+
const found = searchLayout(nested, contentKey);
|
|
1093
|
+
if (found) return found;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
return void 0;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
// src/umbraco-api/tools/content/get/inspect-blocks.ts
|
|
1101
|
+
var inputSchema6 = {
|
|
1102
|
+
id: z.string().uuid().describe("The ID of the page to inspect"),
|
|
1103
|
+
propertyAlias: z.string().optional().describe("Specific property alias to inspect. If omitted, all block-based properties are shown.")
|
|
1104
|
+
};
|
|
1105
|
+
var outputSchema6 = z.object({
|
|
1106
|
+
id: z.string(),
|
|
1107
|
+
name: z.string(),
|
|
1108
|
+
previewUrl: previewUrlSchema,
|
|
1109
|
+
blockProperties: z.array(z.object({
|
|
1110
|
+
propertyAlias: z.string().describe("The document property containing these blocks"),
|
|
1111
|
+
editorAlias: z.string().optional(),
|
|
1112
|
+
blocks: z.array(z.object({
|
|
1113
|
+
contentKey: z.string().describe("The block's unique key \u2014 use this with edit-block"),
|
|
1114
|
+
contentTypeKey: z.string().describe("The block's element type ID"),
|
|
1115
|
+
settingsKey: z.string().optional().describe("The key of the block's settings entry. Absent when the block has no settings."),
|
|
1116
|
+
properties: z.array(z.object({
|
|
1117
|
+
alias: z.string(),
|
|
1118
|
+
value: z.any()
|
|
1119
|
+
}))
|
|
1120
|
+
}))
|
|
1121
|
+
}))
|
|
1122
|
+
});
|
|
1123
|
+
function isBlockListOrGridValue2(value) {
|
|
1124
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
1125
|
+
}
|
|
1126
|
+
function isRteWithBlocks2(value) {
|
|
1127
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.markup === "string" && value.blocks !== null && typeof value.blocks === "object" && Array.isArray(value.blocks?.contentData);
|
|
1128
|
+
}
|
|
1129
|
+
function extractBlocks(contentData, container) {
|
|
1130
|
+
return contentData.map((block) => {
|
|
1131
|
+
const contentKey = block.key ?? "";
|
|
1132
|
+
const settingsKey = findSettingsKey(container, contentKey);
|
|
1133
|
+
return {
|
|
1134
|
+
contentKey,
|
|
1135
|
+
contentTypeKey: block.contentTypeKey ?? "",
|
|
1136
|
+
...settingsKey ? { settingsKey } : {},
|
|
1137
|
+
properties: Array.isArray(block.values) ? block.values.map((v) => ({ alias: v.alias ?? "", value: v.value })) : []
|
|
1138
|
+
};
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
var tool6 = {
|
|
1142
|
+
name: "inspect-blocks",
|
|
1143
|
+
description: "Inspect the block structure of a content page. Shows each block's type, unique key, and property values. Use this to understand how content is structured inside BlockList, BlockGrid, or Rich Text properties before using edit-block to make changes.",
|
|
1144
|
+
inputSchema: inputSchema6,
|
|
1145
|
+
outputSchema: outputSchema6,
|
|
1146
|
+
slices: ["read"],
|
|
1147
|
+
annotations: { readOnlyHint: true },
|
|
1148
|
+
handler: async ({ id, propertyAlias }) => {
|
|
766
1149
|
const result = await chainCms("get-document-by-id", { id });
|
|
767
1150
|
if (!result.ok) return result.errorResult;
|
|
768
1151
|
const doc = result.data;
|
|
769
1152
|
const allValues = doc.values ?? [];
|
|
770
1153
|
const filtered = propertyAlias ? allValues.filter((v) => v.alias === propertyAlias) : allValues;
|
|
771
|
-
const blockProperties = filtered.filter((v) =>
|
|
1154
|
+
const blockProperties = filtered.filter((v) => isBlockListOrGridValue2(v.value) || isRteWithBlocks2(v.value)).map((v) => {
|
|
772
1155
|
const value = v.value;
|
|
773
|
-
if (
|
|
1156
|
+
if (isRteWithBlocks2(value)) {
|
|
774
1157
|
return {
|
|
775
1158
|
propertyAlias: v.alias,
|
|
776
1159
|
editorAlias: "Umbraco.RichText",
|
|
777
|
-
blocks: extractBlocks(value.blocks.contentData)
|
|
1160
|
+
blocks: extractBlocks(value.blocks.contentData, value.blocks)
|
|
778
1161
|
};
|
|
779
1162
|
}
|
|
780
1163
|
return {
|
|
781
1164
|
propertyAlias: v.alias,
|
|
782
1165
|
editorAlias: v.editorAlias ?? void 0,
|
|
783
|
-
blocks: extractBlocks(value.contentData)
|
|
1166
|
+
blocks: extractBlocks(value.contentData, value)
|
|
784
1167
|
};
|
|
785
1168
|
});
|
|
786
1169
|
return createToolResult({
|
|
@@ -1121,150 +1504,76 @@ ${aliases.join("\n")}`
|
|
|
1121
1504
|
}
|
|
1122
1505
|
};
|
|
1123
1506
|
var get_property_value_template_default = withStandardDecorators(tool10);
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
)
|
|
1137
|
-
})
|
|
1138
|
-
|
|
1139
|
-
)
|
|
1140
|
-
|
|
1141
|
-
let target = null;
|
|
1142
|
-
if (!target) {
|
|
1143
|
-
const docResult = await chainCms("get-document-by-id", { id });
|
|
1144
|
-
if (!docResult.ok) {
|
|
1145
|
-
return {
|
|
1146
|
-
valid: false,
|
|
1147
|
-
errors: [
|
|
1148
|
-
{
|
|
1149
|
-
propertyAlias: "__document__",
|
|
1150
|
-
message: "Could not refetch document to run validation."
|
|
1151
|
-
}
|
|
1152
|
-
]
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
target = docResult.data;
|
|
1156
|
-
}
|
|
1157
|
-
const values = (target.values ?? []).map((v) => ({
|
|
1158
|
-
alias: v.alias,
|
|
1159
|
-
value: v.value,
|
|
1160
|
-
culture: v.culture ?? null,
|
|
1161
|
-
segment: v.segment ?? null
|
|
1162
|
-
}));
|
|
1163
|
-
const variants = (target.variants ?? []).map((v) => ({
|
|
1164
|
-
name: v.name,
|
|
1165
|
-
culture: v.culture ?? null,
|
|
1166
|
-
segment: v.segment ?? null
|
|
1167
|
-
}));
|
|
1168
|
-
const ancestorsResult = await chainCms("get-document-ancestors", { descendantId: id });
|
|
1169
|
-
const parent = ancestorsResult.ok ? (ancestorsResult.data.items ?? []).find((item) => item.id === id)?.parent ?? null : null;
|
|
1170
|
-
const result = await chainCms("validate-document", {
|
|
1171
|
-
id,
|
|
1172
|
-
documentType: { id: target.documentType.id },
|
|
1173
|
-
template: target.template ? { id: target.template.id } : null,
|
|
1174
|
-
parent,
|
|
1175
|
-
values,
|
|
1176
|
-
variants
|
|
1177
|
-
});
|
|
1178
|
-
if (result.ok) {
|
|
1179
|
-
return { valid: true, errors: [] };
|
|
1180
|
-
}
|
|
1181
|
-
return { valid: false, errors: parseValidationErrors(result.errorResult, values) };
|
|
1182
|
-
}
|
|
1183
|
-
function parseValidationErrors(errorResult, requestValues) {
|
|
1184
|
-
const structured = extractStructured(errorResult);
|
|
1185
|
-
if (!structured) {
|
|
1186
|
-
return [
|
|
1187
|
-
{
|
|
1188
|
-
propertyAlias: "__document__",
|
|
1189
|
-
message: stringifyErrorFallback(errorResult)
|
|
1190
|
-
}
|
|
1191
|
-
];
|
|
1192
|
-
}
|
|
1193
|
-
const errors = structured.errors;
|
|
1194
|
-
if (!errors || typeof errors !== "object") {
|
|
1195
|
-
return [
|
|
1196
|
-
{
|
|
1197
|
-
propertyAlias: "__document__",
|
|
1198
|
-
message: stringifyFromProblemDetails(structured)
|
|
1199
|
-
}
|
|
1200
|
-
];
|
|
1201
|
-
}
|
|
1202
|
-
const out = [];
|
|
1203
|
-
for (const [jsonPath, messages] of Object.entries(errors)) {
|
|
1204
|
-
const messageList = Array.isArray(messages) ? messages : [String(messages)];
|
|
1205
|
-
const resolved = resolveJsonPath(jsonPath, requestValues);
|
|
1206
|
-
for (const message of messageList) {
|
|
1207
|
-
out.push({
|
|
1208
|
-
propertyAlias: resolved.propertyAlias,
|
|
1209
|
-
culture: resolved.culture,
|
|
1210
|
-
segment: resolved.segment,
|
|
1211
|
-
message: String(message)
|
|
1212
|
-
});
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
if (out.length === 0) {
|
|
1216
|
-
out.push({
|
|
1217
|
-
propertyAlias: "__document__",
|
|
1218
|
-
message: stringifyFromProblemDetails(structured)
|
|
1219
|
-
});
|
|
1220
|
-
}
|
|
1221
|
-
return out;
|
|
1222
|
-
}
|
|
1223
|
-
var VALUES_PATH = /^\$\.values\[(\d+)\](?:\.value)?(.*)$/;
|
|
1224
|
-
function resolveJsonPath(jsonPath, requestValues) {
|
|
1225
|
-
const match = jsonPath.match(VALUES_PATH);
|
|
1226
|
-
if (match) {
|
|
1227
|
-
const index = Number(match[1]);
|
|
1228
|
-
const entry = requestValues[index];
|
|
1229
|
-
if (entry) {
|
|
1230
|
-
const trailing = match[2]?.replace(/^\./, "");
|
|
1231
|
-
return {
|
|
1232
|
-
propertyAlias: trailing ? `${entry.alias}${match[2]}` : entry.alias,
|
|
1233
|
-
culture: entry.culture,
|
|
1234
|
-
segment: entry.segment
|
|
1235
|
-
};
|
|
1507
|
+
async function resolveEditorAliases(documentTypeId, values) {
|
|
1508
|
+
if (!values || values.length === 0) {
|
|
1509
|
+
return { ok: true, values: [] };
|
|
1510
|
+
}
|
|
1511
|
+
const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
|
|
1512
|
+
if (!docTypeResult.ok) return docTypeResult;
|
|
1513
|
+
const dataTypeIds = Array.from(
|
|
1514
|
+
new Set(
|
|
1515
|
+
docTypeResult.properties.map((p) => p.dataType?.id).filter((id) => typeof id === "string")
|
|
1516
|
+
)
|
|
1517
|
+
);
|
|
1518
|
+
const editorAliasByDataTypeId = /* @__PURE__ */ new Map();
|
|
1519
|
+
if (dataTypeIds.length > 0) {
|
|
1520
|
+
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1521
|
+
if (!dataTypesResult.ok) return dataTypesResult;
|
|
1522
|
+
for (const dt of dataTypesResult.data.items) {
|
|
1523
|
+
if (dt.id && dt.editorAlias) editorAliasByDataTypeId.set(dt.id, dt.editorAlias);
|
|
1236
1524
|
}
|
|
1237
1525
|
}
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
}
|
|
1246
|
-
const
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
} catch {
|
|
1526
|
+
const propertyAliases = new Set(
|
|
1527
|
+
docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
|
|
1528
|
+
);
|
|
1529
|
+
const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
|
|
1530
|
+
for (const prop of docTypeResult.properties) {
|
|
1531
|
+
const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
|
|
1532
|
+
if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
|
|
1533
|
+
}
|
|
1534
|
+
const notAProperty = /* @__PURE__ */ new Set();
|
|
1535
|
+
const missingEditorAlias = /* @__PURE__ */ new Set();
|
|
1536
|
+
const resolved = values.map((v) => {
|
|
1537
|
+
const editorAlias = editorAliasByPropertyAlias.get(v.alias);
|
|
1538
|
+
if (!editorAlias) {
|
|
1539
|
+
if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
|
|
1540
|
+
else notAProperty.add(v.alias);
|
|
1254
1541
|
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1542
|
+
return {
|
|
1543
|
+
alias: v.alias,
|
|
1544
|
+
value: v.value,
|
|
1545
|
+
culture: v.culture ?? null,
|
|
1546
|
+
segment: v.segment ?? null,
|
|
1547
|
+
editorAlias: editorAlias ?? ""
|
|
1548
|
+
};
|
|
1549
|
+
});
|
|
1550
|
+
if (notAProperty.size > 0 || missingEditorAlias.size > 0) {
|
|
1551
|
+
const messages = [];
|
|
1552
|
+
if (notAProperty.size > 0) {
|
|
1553
|
+
if (docTypeResult.failedCompositionIds.length > 0) {
|
|
1554
|
+
const failures = docTypeResult.failedCompositionIds.map((id, i) => `${id} (${docTypeResult.failedCompositionDetails[i]})`).join(", ");
|
|
1555
|
+
messages.push(
|
|
1556
|
+
`not found among the resolvable properties on this document type, own or inherited via composition: ${Array.from(notAProperty).join(", ")} \u2014 but ${docTypeResult.failedCompositionIds.length} composition(s) could not be loaded: ${failures}, so one of these aliases may actually be valid and just unverifiable right now. Resolve the composition failure(s) above and retry`
|
|
1557
|
+
);
|
|
1558
|
+
} else {
|
|
1559
|
+
messages.push(
|
|
1560
|
+
`not a property on this document type, own or inherited via composition: ${Array.from(notAProperty).join(", ")}`
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
if (missingEditorAlias.size > 0) {
|
|
1565
|
+
messages.push(
|
|
1566
|
+
`a property on this document type, but its data type has no resolvable editor alias: ${Array.from(missingEditorAlias).join(", ")}`
|
|
1567
|
+
);
|
|
1568
|
+
}
|
|
1569
|
+
return {
|
|
1570
|
+
ok: false,
|
|
1571
|
+
errorResult: createToolResultError(
|
|
1572
|
+
`The following value alias(es) could not be resolved \u2014 ${messages.join("; ")}. Call get-document-type to see the valid property aliases for this document type.`
|
|
1573
|
+
)
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
return { ok: true, values: resolved };
|
|
1268
1577
|
}
|
|
1269
1578
|
|
|
1270
1579
|
// src/umbraco-api/tools/content/post/create-page.ts
|
|
@@ -1294,31 +1603,12 @@ var tool11 = {
|
|
|
1294
1603
|
slices: ["create"],
|
|
1295
1604
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
1296
1605
|
handler: async ({ name, documentTypeId, parentId, values }) => {
|
|
1297
|
-
const
|
|
1298
|
-
if (
|
|
1299
|
-
const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
|
|
1300
|
-
if (!docTypeResult.ok) return docTypeResult.errorResult;
|
|
1301
|
-
const dataTypeIds = Array.from(new Set(docTypeResult.data.properties.map((p) => p.dataType.id)));
|
|
1302
|
-
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1303
|
-
if (!dataTypesResult.ok) return dataTypesResult.errorResult;
|
|
1304
|
-
const editorAliasByDataTypeId = new Map(
|
|
1305
|
-
dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
|
|
1306
|
-
);
|
|
1307
|
-
for (const prop of docTypeResult.data.properties) {
|
|
1308
|
-
const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
|
|
1309
|
-
if (editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1606
|
+
const resolved = await resolveEditorAliases(documentTypeId, values);
|
|
1607
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
1312
1608
|
const createResult = await chainCms("create-document", {
|
|
1313
1609
|
documentTypeId,
|
|
1314
1610
|
name,
|
|
1315
|
-
values:
|
|
1316
|
-
alias: v.alias,
|
|
1317
|
-
value: v.value,
|
|
1318
|
-
culture: v.culture ?? null,
|
|
1319
|
-
segment: v.segment ?? null,
|
|
1320
|
-
editorAlias: editorAliasByPropertyAlias.get(v.alias) ?? ""
|
|
1321
|
-
})),
|
|
1611
|
+
values: resolved.values,
|
|
1322
1612
|
...parentId ? { parentId } : {}
|
|
1323
1613
|
});
|
|
1324
1614
|
if (!createResult.ok) return createResult.errorResult;
|
|
@@ -1355,41 +1645,50 @@ var outputSchema12 = z.object({
|
|
|
1355
1645
|
});
|
|
1356
1646
|
var tool12 = {
|
|
1357
1647
|
name: "create-and-publish-page",
|
|
1358
|
-
description: "Create a new content page and publish it
|
|
1648
|
+
description: "Create a new content page and publish it \u2014 mirrors clicking 'Save and publish' (instead of 'Save') on the create screen in the Umbraco backoffice. This is a single atomic operation when the connected Umbraco instance supports it (17.6+); otherwise a two-call create-then-publish sequence is used. Call list-document-types first to find a valid documentTypeId. Use this as a starting point: pass `name`, `documentTypeId`, optional `parentId`, and at most a small number of simple initial values. Required-property validation runs at publish time, not create time: on the atomic path a validation failure leaves no page behind, but on the fallback path the draft can already have been created before publish fails, leaving an unpublished draft. Either way, check the response `message` before retrying \u2014 don't retry blindly, or you may pile up duplicate drafts. Use create-page followed by save-and-publish instead when you need to build up content across multiple calls before publishing.",
|
|
1359
1649
|
inputSchema: inputSchema12,
|
|
1360
1650
|
outputSchema: outputSchema12,
|
|
1361
1651
|
slices: ["create", "publish"],
|
|
1362
1652
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
1363
1653
|
handler: async ({ name, documentTypeId, parentId, values }) => {
|
|
1364
|
-
const
|
|
1365
|
-
if (
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
);
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1654
|
+
const resolved = await resolveEditorAliases(documentTypeId, values);
|
|
1655
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
1656
|
+
if (await isCmsToolAvailable("create-and-publish-document")) {
|
|
1657
|
+
const createResult = await chainCms("create-and-publish-document", {
|
|
1658
|
+
documentTypeId,
|
|
1659
|
+
name,
|
|
1660
|
+
values: resolved.values,
|
|
1661
|
+
...parentId ? { parentId } : {}
|
|
1662
|
+
});
|
|
1663
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1664
|
+
const createdId2 = createResult.data.id;
|
|
1665
|
+
return createToolResult({
|
|
1666
|
+
message: `Created and published "${name}"`,
|
|
1667
|
+
id: createdId2,
|
|
1668
|
+
name,
|
|
1669
|
+
publishedUrls: createdId2 ? await fetchPublishedUrls(createdId2) : []
|
|
1670
|
+
});
|
|
1378
1671
|
}
|
|
1379
|
-
const
|
|
1672
|
+
const createDocumentResult = await chainCms("create-document", {
|
|
1380
1673
|
documentTypeId,
|
|
1381
1674
|
name,
|
|
1382
|
-
values:
|
|
1383
|
-
alias: v.alias,
|
|
1384
|
-
value: v.value,
|
|
1385
|
-
culture: v.culture ?? null,
|
|
1386
|
-
segment: v.segment ?? null,
|
|
1387
|
-
editorAlias: editorAliasByPropertyAlias.get(v.alias) ?? ""
|
|
1388
|
-
})),
|
|
1675
|
+
values: resolved.values,
|
|
1389
1676
|
...parentId ? { parentId } : {}
|
|
1390
1677
|
});
|
|
1391
|
-
if (!
|
|
1392
|
-
const createdId =
|
|
1678
|
+
if (!createDocumentResult.ok) return createDocumentResult.errorResult;
|
|
1679
|
+
const createdId = createDocumentResult.data.id;
|
|
1680
|
+
const publishResult = await chainCms("publish-document", {
|
|
1681
|
+
id: createdId,
|
|
1682
|
+
data: { publishSchedules: [{ culture: null }] }
|
|
1683
|
+
});
|
|
1684
|
+
if (!publishResult.ok) {
|
|
1685
|
+
return createToolResult({
|
|
1686
|
+
message: `Created "${name}" as a draft but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
|
|
1687
|
+
id: createdId,
|
|
1688
|
+
name,
|
|
1689
|
+
publishedUrls: []
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1393
1692
|
return createToolResult({
|
|
1394
1693
|
message: `Created and published "${name}"`,
|
|
1395
1694
|
id: createdId,
|
|
@@ -1442,70 +1741,6 @@ var tool13 = {
|
|
|
1442
1741
|
}
|
|
1443
1742
|
};
|
|
1444
1743
|
var duplicate_page_default = withStandardDecorators(tool13);
|
|
1445
|
-
|
|
1446
|
-
// src/umbraco-api/tools/helpers/block-builder.ts
|
|
1447
|
-
async function resolveBlockEditorAliases(contentTypeKey) {
|
|
1448
|
-
const docTypeResult = await chainCms("get-document-type-by-id", { id: contentTypeKey });
|
|
1449
|
-
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
1450
|
-
const dataTypeIds = Array.from(new Set(docTypeResult.data.properties.map((p) => p.dataType.id)));
|
|
1451
|
-
if (dataTypeIds.length === 0) {
|
|
1452
|
-
return { ok: true, editorAliasByAlias: /* @__PURE__ */ new Map() };
|
|
1453
|
-
}
|
|
1454
|
-
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1455
|
-
if (!dataTypesResult.ok) return { ok: false, errorResult: dataTypesResult.errorResult };
|
|
1456
|
-
const editorAliasByDataTypeId = new Map(
|
|
1457
|
-
dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
|
|
1458
|
-
);
|
|
1459
|
-
const editorAliasByAlias = /* @__PURE__ */ new Map();
|
|
1460
|
-
for (const prop of docTypeResult.data.properties) {
|
|
1461
|
-
const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
|
|
1462
|
-
if (editorAlias) editorAliasByAlias.set(prop.alias, editorAlias);
|
|
1463
|
-
}
|
|
1464
|
-
return { ok: true, editorAliasByAlias };
|
|
1465
|
-
}
|
|
1466
|
-
function buildBlockEntry(contentKey, contentTypeKey, values, editorAliasByAlias, culture, segment) {
|
|
1467
|
-
return {
|
|
1468
|
-
key: contentKey,
|
|
1469
|
-
contentTypeKey,
|
|
1470
|
-
values: values.map((v) => ({
|
|
1471
|
-
editorAlias: editorAliasByAlias.get(v.alias) ?? "",
|
|
1472
|
-
culture,
|
|
1473
|
-
segment,
|
|
1474
|
-
alias: v.alias,
|
|
1475
|
-
value: v.value
|
|
1476
|
-
}))
|
|
1477
|
-
};
|
|
1478
|
-
}
|
|
1479
|
-
function insertAtPosition(list, item, position, matchAnchor) {
|
|
1480
|
-
if (position.mode === "append") return { ok: true, list: [...list, item] };
|
|
1481
|
-
if (position.mode === "prepend") return { ok: true, list: [item, ...list] };
|
|
1482
|
-
const anchorIndex = list.findIndex(matchAnchor);
|
|
1483
|
-
if (anchorIndex === -1) return { ok: false, reason: "anchor-not-found" };
|
|
1484
|
-
const insertIndex = position.mode === "before" ? anchorIndex : anchorIndex + 1;
|
|
1485
|
-
const next = [...list];
|
|
1486
|
-
next.splice(insertIndex, 0, item);
|
|
1487
|
-
return { ok: true, list: next };
|
|
1488
|
-
}
|
|
1489
|
-
function isBlockListOrGridValue2(value) {
|
|
1490
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
1491
|
-
}
|
|
1492
|
-
function isRteWithBlocks2(value) {
|
|
1493
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.markup === "string" && value.blocks !== null && typeof value.blocks === "object" && Array.isArray(value.blocks?.contentData);
|
|
1494
|
-
}
|
|
1495
|
-
function exposeEntry(contentKey, culture, segment) {
|
|
1496
|
-
return { contentKey, culture, segment };
|
|
1497
|
-
}
|
|
1498
|
-
function removeBlockFromContainer(container, contentKey, layoutKey, newLayoutList, doomedSettingsKey) {
|
|
1499
|
-
return {
|
|
1500
|
-
...container,
|
|
1501
|
-
layout: { ...container.layout ?? {}, [layoutKey]: [...newLayoutList] },
|
|
1502
|
-
contentData: (container.contentData ?? []).filter((entry) => entry.key !== contentKey),
|
|
1503
|
-
settingsData: doomedSettingsKey ? (container.settingsData ?? []).filter((entry) => entry.key !== doomedSettingsKey) : container.settingsData ?? [],
|
|
1504
|
-
expose: (container.expose ?? []).filter((entry) => entry.contentKey !== contentKey)
|
|
1505
|
-
};
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
// src/umbraco-api/tools/content/post/add-blocklist-block.ts
|
|
1509
1744
|
var positionSchema = z.object({
|
|
1510
1745
|
mode: z.enum(["append", "prepend", "before", "after"]).describe("Where to place the new block relative to existing blocks"),
|
|
1511
1746
|
anchorContentKey: z.string().uuid().optional().describe("Required for 'before' or 'after' \u2014 the contentKey of the anchor block")
|
|
@@ -1558,64 +1793,25 @@ var tool14 = {
|
|
|
1558
1793
|
const existingProp = (doc.values ?? []).find(
|
|
1559
1794
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1560
1795
|
);
|
|
1561
|
-
|
|
1562
|
-
layout: { "Umbraco.BlockList": [] },
|
|
1563
|
-
contentData: [],
|
|
1564
|
-
settingsData: [],
|
|
1565
|
-
expose: []
|
|
1566
|
-
};
|
|
1567
|
-
if (existingProp && (!isBlockListOrGridValue2(propValue) || existingProp.editorAlias !== "Umbraco.BlockList")) {
|
|
1796
|
+
if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockList")) {
|
|
1568
1797
|
return createToolResultError({ content: [{ type: "text", text: `Property '${propertyAlias}' on '${pageName}' is not a BlockList. Use inspect-blocks to confirm the editor type, or add-rte-block / add-blockgrid-block as appropriate.` }], isError: true });
|
|
1569
1798
|
}
|
|
1570
|
-
const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
|
|
1571
|
-
if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
|
|
1572
|
-
let settingsEditorAliases = null;
|
|
1573
|
-
if (settingsTypeKey) {
|
|
1574
|
-
const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
|
|
1575
|
-
if (!settingsResult.ok) return settingsResult.errorResult;
|
|
1576
|
-
settingsEditorAliases = settingsResult.editorAliasByAlias;
|
|
1577
|
-
}
|
|
1578
|
-
const newContentKey = randomUUID();
|
|
1579
|
-
const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
|
|
1580
1799
|
const cultureValue = culture ?? null;
|
|
1581
1800
|
const segmentValue = segment ?? null;
|
|
1582
|
-
const
|
|
1583
|
-
|
|
1584
|
-
const
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
layout: { ...propValue.layout ?? {}, [layoutKey]: insertResult.list },
|
|
1594
|
-
contentData: [...propValue.contentData ?? [], newContentEntry],
|
|
1595
|
-
settingsData: newSettingsEntry ? [...propValue.settingsData ?? [], newSettingsEntry] : propValue.settingsData ?? [],
|
|
1596
|
-
expose: [...propValue.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
|
|
1597
|
-
};
|
|
1598
|
-
const updateResult = await chainCms("update-document-properties", {
|
|
1599
|
-
id,
|
|
1600
|
-
properties: [{
|
|
1601
|
-
alias: propertyAlias,
|
|
1602
|
-
value: newValue,
|
|
1603
|
-
culture: cultureValue,
|
|
1604
|
-
segment: segmentValue
|
|
1605
|
-
}]
|
|
1606
|
-
});
|
|
1607
|
-
if (!updateResult.ok) return updateResult.errorResult;
|
|
1608
|
-
const validation = await validateDocumentState(id);
|
|
1609
|
-
const baseMessage = `Added a new block to "${pageName}" (saved, not published)`;
|
|
1610
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1611
|
-
return createToolResult({
|
|
1612
|
-
message,
|
|
1613
|
-
id,
|
|
1614
|
-
name: pageName,
|
|
1615
|
-
contentKey: newContentKey,
|
|
1616
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
1617
|
-
validation
|
|
1801
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1802
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1803
|
+
const createResult = await chainCms("create-document-block", {
|
|
1804
|
+
documentId: id,
|
|
1805
|
+
propertyAlias,
|
|
1806
|
+
culture: cultureValue,
|
|
1807
|
+
segment: segmentValue,
|
|
1808
|
+
contentTypeKey,
|
|
1809
|
+
properties: blockProperties.properties,
|
|
1810
|
+
settings: blockProperties.settings,
|
|
1811
|
+
placement: toPlacement(resolvedPosition)
|
|
1618
1812
|
});
|
|
1813
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1814
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
|
|
1619
1815
|
}
|
|
1620
1816
|
};
|
|
1621
1817
|
var add_blocklist_block_default = withStandardDecorators(tool14);
|
|
@@ -1678,100 +1874,30 @@ var tool15 = {
|
|
|
1678
1874
|
const existingProp = (doc.values ?? []).find(
|
|
1679
1875
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1680
1876
|
);
|
|
1681
|
-
|
|
1682
|
-
layout: { "Umbraco.BlockGrid": [] },
|
|
1683
|
-
contentData: [],
|
|
1684
|
-
settingsData: [],
|
|
1685
|
-
expose: []
|
|
1686
|
-
};
|
|
1687
|
-
if (existingProp && (!isBlockListOrGridValue2(propValue) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
|
|
1877
|
+
if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
|
|
1688
1878
|
return createToolResultError({ content: [{ type: "text", text: `Property '${propertyAlias}' on '${pageName}' is not a BlockGrid. Use inspect-blocks to confirm the editor type, or add-blocklist-block / add-rte-block as appropriate.` }], isError: true });
|
|
1689
1879
|
}
|
|
1690
|
-
const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
|
|
1691
|
-
if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
|
|
1692
|
-
let settingsEditorAliases = null;
|
|
1693
|
-
if (settingsTypeKey) {
|
|
1694
|
-
const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
|
|
1695
|
-
if (!settingsResult.ok) return settingsResult.errorResult;
|
|
1696
|
-
settingsEditorAliases = settingsResult.editorAliasByAlias;
|
|
1697
|
-
}
|
|
1698
|
-
const newContentKey = randomUUID();
|
|
1699
|
-
const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
|
|
1700
1880
|
const cultureValue = culture ?? null;
|
|
1701
1881
|
const segmentValue = segment ?? null;
|
|
1702
|
-
const
|
|
1703
|
-
|
|
1704
|
-
const
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
let nextTopLayout;
|
|
1718
|
-
if (areaKey) {
|
|
1719
|
-
const parentIndex = topLayout.findIndex((item) => item.contentKey === parentContentKey);
|
|
1720
|
-
if (parentIndex === -1) {
|
|
1721
|
-
return createToolResultError({ content: [{ type: "text", text: `Parent block '${parentContentKey}' was not found in '${propertyAlias}'.` }], isError: true });
|
|
1722
|
-
}
|
|
1723
|
-
const parent = topLayout[parentIndex];
|
|
1724
|
-
const areas = Array.isArray(parent.areas) ? parent.areas : [];
|
|
1725
|
-
const areaIndex = areas.findIndex((area2) => area2.key === areaKey);
|
|
1726
|
-
if (areaIndex === -1) {
|
|
1727
|
-
return createToolResultError({ content: [{ type: "text", text: `Area '${areaKey}' was not found on parent block '${parentContentKey}'.` }], isError: true });
|
|
1728
|
-
}
|
|
1729
|
-
const area = areas[areaIndex];
|
|
1730
|
-
const insertResult = insertAtPosition(area.items ?? [], layoutEntry, resolvedPosition, (item) => item.contentKey === resolvedPosition.anchorContentKey);
|
|
1731
|
-
if (!insertResult.ok) {
|
|
1732
|
-
return createToolResultError({ content: [{ type: "text", text: `Anchor block '${resolvedPosition.anchorContentKey}' was not found in area '${areaKey}'.` }], isError: true });
|
|
1733
|
-
}
|
|
1734
|
-
const updatedArea = { ...area, items: insertResult.list };
|
|
1735
|
-
const updatedAreas = areas.slice();
|
|
1736
|
-
updatedAreas[areaIndex] = updatedArea;
|
|
1737
|
-
const updatedParent = { ...parent, areas: updatedAreas };
|
|
1738
|
-
nextTopLayout = topLayout.slice();
|
|
1739
|
-
nextTopLayout[parentIndex] = updatedParent;
|
|
1740
|
-
} else {
|
|
1741
|
-
const insertResult = insertAtPosition(topLayout, layoutEntry, resolvedPosition, (item) => item.contentKey === resolvedPosition.anchorContentKey);
|
|
1742
|
-
if (!insertResult.ok) {
|
|
1743
|
-
return createToolResultError({ content: [{ type: "text", text: `Anchor block '${resolvedPosition.anchorContentKey}' was not found in '${propertyAlias}'.` }], isError: true });
|
|
1882
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1883
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1884
|
+
const createResult = await chainCms("create-document-block", {
|
|
1885
|
+
documentId: id,
|
|
1886
|
+
propertyAlias,
|
|
1887
|
+
culture: cultureValue,
|
|
1888
|
+
segment: segmentValue,
|
|
1889
|
+
contentTypeKey,
|
|
1890
|
+
properties: blockProperties.properties,
|
|
1891
|
+
settings: blockProperties.settings,
|
|
1892
|
+
placement: toPlacement(resolvedPosition),
|
|
1893
|
+
grid: {
|
|
1894
|
+
columnSpan: columnSpan ?? 12,
|
|
1895
|
+
rowSpan: rowSpan ?? 1,
|
|
1896
|
+
...areaKey && parentContentKey ? { areaKey, parentContentKey } : {}
|
|
1744
1897
|
}
|
|
1745
|
-
nextTopLayout = insertResult.list;
|
|
1746
|
-
}
|
|
1747
|
-
const newValue = {
|
|
1748
|
-
...propValue,
|
|
1749
|
-
layout: { ...propValue.layout ?? {}, [layoutKey]: nextTopLayout },
|
|
1750
|
-
contentData: [...propValue.contentData ?? [], newContentEntry],
|
|
1751
|
-
settingsData: newSettingsEntry ? [...propValue.settingsData ?? [], newSettingsEntry] : propValue.settingsData ?? [],
|
|
1752
|
-
expose: [...propValue.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
|
|
1753
|
-
};
|
|
1754
|
-
const updateResult = await chainCms("update-document-properties", {
|
|
1755
|
-
id,
|
|
1756
|
-
properties: [{
|
|
1757
|
-
alias: propertyAlias,
|
|
1758
|
-
value: newValue,
|
|
1759
|
-
culture: cultureValue,
|
|
1760
|
-
segment: segmentValue
|
|
1761
|
-
}]
|
|
1762
|
-
});
|
|
1763
|
-
if (!updateResult.ok) return updateResult.errorResult;
|
|
1764
|
-
const validation = await validateDocumentState(id);
|
|
1765
|
-
const baseMessage = `Added a new block to "${pageName}" (saved, not published)`;
|
|
1766
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1767
|
-
return createToolResult({
|
|
1768
|
-
message,
|
|
1769
|
-
id,
|
|
1770
|
-
name: pageName,
|
|
1771
|
-
contentKey: newContentKey,
|
|
1772
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
1773
|
-
validation
|
|
1774
1898
|
});
|
|
1899
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1900
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
|
|
1775
1901
|
}
|
|
1776
1902
|
};
|
|
1777
1903
|
var add_blockgrid_block_default = withStandardDecorators(tool15);
|
|
@@ -1802,26 +1928,6 @@ var outputSchema16 = z.object({
|
|
|
1802
1928
|
previewUrl: previewUrlSchema,
|
|
1803
1929
|
validation: validationResultSchema
|
|
1804
1930
|
});
|
|
1805
|
-
function buildBlockTag(contentKey) {
|
|
1806
|
-
return `<umb-rte-block data-content-key="${contentKey}"></umb-rte-block>`;
|
|
1807
|
-
}
|
|
1808
|
-
function findAnchorTagRange(markup, anchorKey) {
|
|
1809
|
-
const re = new RegExp(`<umb-rte-block[^>]*data-content-key="${anchorKey}"[^>]*>\\s*</umb-rte-block>`, "i");
|
|
1810
|
-
const match = markup.match(re);
|
|
1811
|
-
if (!match || match.index === void 0) return null;
|
|
1812
|
-
return { start: match.index, end: match.index + match[0].length };
|
|
1813
|
-
}
|
|
1814
|
-
function insertMarkup(markup, newTag, mode, anchorKey) {
|
|
1815
|
-
if (mode === "append") return { ok: true, markup: `${markup}${newTag}` };
|
|
1816
|
-
if (mode === "prepend") return { ok: true, markup: `${newTag}${markup}` };
|
|
1817
|
-
if (!anchorKey) return { ok: false, reason: "missing anchor" };
|
|
1818
|
-
const range = findAnchorTagRange(markup, anchorKey);
|
|
1819
|
-
if (!range) return { ok: false, reason: "anchor not found" };
|
|
1820
|
-
if (mode === "before") {
|
|
1821
|
-
return { ok: true, markup: `${markup.slice(0, range.start)}${newTag}${markup.slice(range.start)}` };
|
|
1822
|
-
}
|
|
1823
|
-
return { ok: true, markup: `${markup.slice(0, range.end)}${newTag}${markup.slice(range.end)}` };
|
|
1824
|
-
}
|
|
1825
1931
|
var tool16 = {
|
|
1826
1932
|
name: "add-rte-block",
|
|
1827
1933
|
description: "Add a new block inside a Rich Text property on a page. Inserts the umb-rte-block tag in the markup at the chosen position and adds the matching content/settings entries. Use inspect-blocks first to find the propertyAlias and a sample contentTypeKey. For non-string property values inside the block (media pickers, content pickers, image cropper, slider, color, date, etc.) call get-property-value-template with the editor alias first to see the expected JSON shape. For BlockList use add-blocklist-block; for BlockGrid use add-blockgrid-block. Changes are saved as a draft, NOT published.",
|
|
@@ -1847,71 +1953,25 @@ var tool16 = {
|
|
|
1847
1953
|
const existingProp = (doc.values ?? []).find(
|
|
1848
1954
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1849
1955
|
);
|
|
1850
|
-
|
|
1851
|
-
markup: "",
|
|
1852
|
-
blocks: { layout: {}, contentData: [], settingsData: [], expose: [] }
|
|
1853
|
-
};
|
|
1854
|
-
if (existingProp && !isRteWithBlocks2(propValue)) {
|
|
1956
|
+
if (existingProp?.value && !isRteWithBlocks(existingProp.value)) {
|
|
1855
1957
|
return createToolResultError({ content: [{ type: "text", text: `Property '${propertyAlias}' on '${pageName}' is not a rich text with blocks. Use inspect-blocks to confirm the editor type, or add-blocklist-block / add-blockgrid-block as appropriate.` }], isError: true });
|
|
1856
1958
|
}
|
|
1857
|
-
const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
|
|
1858
|
-
if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
|
|
1859
|
-
let settingsEditorAliases = null;
|
|
1860
|
-
if (settingsTypeKey) {
|
|
1861
|
-
const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
|
|
1862
|
-
if (!settingsResult.ok) return settingsResult.errorResult;
|
|
1863
|
-
settingsEditorAliases = settingsResult.editorAliasByAlias;
|
|
1864
|
-
}
|
|
1865
|
-
const newContentKey = randomUUID();
|
|
1866
|
-
const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
|
|
1867
1959
|
const cultureValue = culture ?? null;
|
|
1868
1960
|
const segmentValue = segment ?? null;
|
|
1869
|
-
const
|
|
1870
|
-
|
|
1871
|
-
const
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
if (!markupResult.ok) {
|
|
1881
|
-
return createToolResultError({ content: [{ type: "text", text: `Could not insert into markup \u2014 ${markupResult.reason}.` }], isError: true });
|
|
1882
|
-
}
|
|
1883
|
-
const newValue = {
|
|
1884
|
-
...propValue,
|
|
1885
|
-
markup: markupResult.markup,
|
|
1886
|
-
blocks: {
|
|
1887
|
-
...blocks,
|
|
1888
|
-
layout: { ...blocks.layout ?? {}, [layoutKey]: insertLayoutResult.list },
|
|
1889
|
-
contentData: [...blocks.contentData ?? [], newContentEntry],
|
|
1890
|
-
settingsData: newSettingsEntry ? [...blocks.settingsData ?? [], newSettingsEntry] : blocks.settingsData ?? [],
|
|
1891
|
-
expose: [...blocks.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
|
|
1892
|
-
}
|
|
1893
|
-
};
|
|
1894
|
-
const updateResult = await chainCms("update-document-properties", {
|
|
1895
|
-
id,
|
|
1896
|
-
properties: [{
|
|
1897
|
-
alias: propertyAlias,
|
|
1898
|
-
value: newValue,
|
|
1899
|
-
culture: cultureValue,
|
|
1900
|
-
segment: segmentValue
|
|
1901
|
-
}]
|
|
1902
|
-
});
|
|
1903
|
-
if (!updateResult.ok) return updateResult.errorResult;
|
|
1904
|
-
const validation = await validateDocumentState(id);
|
|
1905
|
-
const baseMessage = `Added a new block to "${pageName}" rich text (saved, not published)`;
|
|
1906
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1907
|
-
return createToolResult({
|
|
1908
|
-
message,
|
|
1909
|
-
id,
|
|
1910
|
-
name: pageName,
|
|
1911
|
-
contentKey: newContentKey,
|
|
1912
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
1913
|
-
validation
|
|
1961
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1962
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1963
|
+
const createResult = await chainCms("create-document-block", {
|
|
1964
|
+
documentId: id,
|
|
1965
|
+
propertyAlias,
|
|
1966
|
+
culture: cultureValue,
|
|
1967
|
+
segment: segmentValue,
|
|
1968
|
+
contentTypeKey,
|
|
1969
|
+
properties: blockProperties.properties,
|
|
1970
|
+
settings: blockProperties.settings,
|
|
1971
|
+
placement: toPlacement(resolvedPosition)
|
|
1914
1972
|
});
|
|
1973
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1974
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" rich text (saved, not published)`);
|
|
1915
1975
|
}
|
|
1916
1976
|
};
|
|
1917
1977
|
var add_rte_block_default = withStandardDecorators(tool16);
|
|
@@ -1966,12 +2026,84 @@ var tool17 = {
|
|
|
1966
2026
|
}
|
|
1967
2027
|
};
|
|
1968
2028
|
var edit_page_default = withStandardDecorators(tool17);
|
|
2029
|
+
var MAX_ENRICHED_BLOCKS = 50;
|
|
2030
|
+
var MAX_BLOCK_WALK_DEPTH = 20;
|
|
2031
|
+
function enrichBlockNotFoundError(errorResult, values, options = {}) {
|
|
2032
|
+
const problem = extractInnerProblemDetails(errorResult);
|
|
2033
|
+
const availableBlocks = problem.availableBlocks;
|
|
2034
|
+
if (!Array.isArray(availableBlocks)) return errorResult;
|
|
2035
|
+
const { propertyAlias, note } = options;
|
|
2036
|
+
const filtered = propertyAlias ? values.filter((v) => v.alias === propertyAlias) : values;
|
|
2037
|
+
const typeByKey = /* @__PURE__ */ new Map();
|
|
2038
|
+
for (const v of filtered) {
|
|
2039
|
+
const container = isRteWithBlocks(v.value) ? v.value.blocks : v.value;
|
|
2040
|
+
if (isBlockListOrGridValue(container)) {
|
|
2041
|
+
collectBlockEntryTypes(container, typeByKey, 0);
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
const truncated = availableBlocks.length > MAX_ENRICHED_BLOCKS;
|
|
2045
|
+
const limitedBlocks = truncated ? availableBlocks.slice(0, MAX_ENRICHED_BLOCKS) : availableBlocks;
|
|
2046
|
+
const enrichedBlocks = limitedBlocks.map(
|
|
2047
|
+
(b) => b && typeof b === "object" && typeof b.key === "string" ? { ...b, contentTypeKey: typeByKey.get(b.key) ?? null } : b
|
|
2048
|
+
);
|
|
2049
|
+
return createToolResultError({
|
|
2050
|
+
...problem,
|
|
2051
|
+
availableBlocks: enrichedBlocks,
|
|
2052
|
+
...truncated ? { availableBlocksNote: `Showing ${MAX_ENRICHED_BLOCKS} of ${availableBlocks.length} available blocks \u2014 use inspect-blocks for the full list.` } : {},
|
|
2053
|
+
...note ? { note } : {}
|
|
2054
|
+
});
|
|
2055
|
+
}
|
|
2056
|
+
function collectBlockEntryTypes(container, into, depth) {
|
|
2057
|
+
if (depth > MAX_BLOCK_WALK_DEPTH) return;
|
|
2058
|
+
for (const list of [container.contentData, container.settingsData]) {
|
|
2059
|
+
if (!Array.isArray(list)) continue;
|
|
2060
|
+
for (const block of list) {
|
|
2061
|
+
if (!block || typeof block !== "object") continue;
|
|
2062
|
+
const key = block.key;
|
|
2063
|
+
const contentTypeKey = block.contentTypeKey;
|
|
2064
|
+
if (typeof key === "string" && typeof contentTypeKey === "string") into.set(key, contentTypeKey);
|
|
2065
|
+
const nestedValues = block.values;
|
|
2066
|
+
if (!Array.isArray(nestedValues)) continue;
|
|
2067
|
+
for (const nested of nestedValues) {
|
|
2068
|
+
const nestedRaw = nested?.value;
|
|
2069
|
+
const nestedContainer = isRteWithBlocks(nestedRaw) ? nestedRaw.blocks : nestedRaw;
|
|
2070
|
+
if (isBlockListOrGridValue(nestedContainer)) {
|
|
2071
|
+
collectBlockEntryTypes(nestedContainer, into, depth + 1);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
var blockPropertyAliasSchema = z.string().regex(
|
|
2078
|
+
/^[A-Za-z_][A-Za-z0-9_]*$/,
|
|
2079
|
+
"Property alias must be a valid identifier (letters, digits, underscore; not starting with a digit)"
|
|
2080
|
+
);
|
|
2081
|
+
function classifyBlockUpdateResults(results, requestedCount, requestedAliases = [], expectedEntryCount = 1) {
|
|
2082
|
+
const list = results ?? [];
|
|
2083
|
+
const processedCount = list.reduce((sum, r) => sum + (r.updatedCount ?? 0) + (r.addedCount ?? 0), 0);
|
|
2084
|
+
const updatedEntryCount = list.filter((r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) > 0).length;
|
|
2085
|
+
const errors = list.flatMap((r) => r.errors ?? []);
|
|
2086
|
+
const warnings = list.flatMap((r) => r.warnings ?? []);
|
|
2087
|
+
const failureText = [...errors, ...warnings].join("; ");
|
|
2088
|
+
const unresolvedEntries = list.filter(
|
|
2089
|
+
(r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) === 0 && !r.errors?.length && !r.warnings?.length
|
|
2090
|
+
);
|
|
2091
|
+
const missingEntryCount = Math.max(0, expectedEntryCount - list.length);
|
|
2092
|
+
const unresolvedBlockCount = unresolvedEntries.length + missingEntryCount;
|
|
2093
|
+
const detail = [...errors, ...warnings, ...unresolvedEntries.map((r) => r.message).filter(Boolean)].join("; ") || list.map((r) => r.message).filter(Boolean).join("; ") || "no detail returned";
|
|
2094
|
+
const outcome = processedCount === 0 ? "failed" : processedCount < requestedCount ? "partial" : "clean";
|
|
2095
|
+
const failedFields = requestedAliases.filter((alias) => failureText.includes(`'${alias}'`));
|
|
2096
|
+
const savedFields = unresolvedBlockCount > 0 ? [] : requestedAliases.filter((alias) => !failedFields.includes(alias));
|
|
2097
|
+
return { outcome, processedCount, updatedEntryCount, detail, warnings, savedFields, failedFields, unresolvedBlockCount };
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
// src/umbraco-api/tools/content/put/edit-block.ts
|
|
1969
2101
|
var inputSchema18 = {
|
|
1970
2102
|
id: z.string().uuid().describe("The ID of the page containing the block"),
|
|
1971
2103
|
propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'mainContent'). Use inspect-blocks to find this."),
|
|
1972
2104
|
contentKey: z.string().uuid().describe("The unique key of the block to edit. Use inspect-blocks to find this."),
|
|
1973
2105
|
values: z.array(z.object({
|
|
1974
|
-
alias:
|
|
2106
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
1975
2107
|
value: z.any().describe("The new value for the property")
|
|
1976
2108
|
})).describe("Properties to update within the block"),
|
|
1977
2109
|
blockType: z.enum(["content", "settings"]).optional().describe("Whether to update the block's content or its settings. Defaults to 'content'."),
|
|
@@ -1985,7 +2117,8 @@ var outputSchema18 = z.object({
|
|
|
1985
2117
|
contentKey: z.string(),
|
|
1986
2118
|
updatedFields: z.array(z.string()),
|
|
1987
2119
|
previewUrl: previewUrlSchema,
|
|
1988
|
-
validation: validationResultSchema
|
|
2120
|
+
validation: validationResultSchema,
|
|
2121
|
+
warnings: z.array(z.string()).optional()
|
|
1989
2122
|
});
|
|
1990
2123
|
var tool18 = {
|
|
1991
2124
|
name: "edit-block",
|
|
@@ -2000,6 +2133,20 @@ var tool18 = {
|
|
|
2000
2133
|
const pageName = docResult.data.variants?.[0]?.name ?? "Unknown";
|
|
2001
2134
|
const fieldNames = values.map((v) => v.alias);
|
|
2002
2135
|
const resolvedBlockType = blockType ?? "content";
|
|
2136
|
+
let targetKey = contentKey;
|
|
2137
|
+
if (resolvedBlockType === "settings") {
|
|
2138
|
+
const rawValue = (docResult.data.values ?? []).find(
|
|
2139
|
+
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
2140
|
+
)?.value;
|
|
2141
|
+
const container = isRteWithBlocks(rawValue) ? rawValue.blocks : rawValue;
|
|
2142
|
+
const settingsKey = findSettingsKey(container, contentKey);
|
|
2143
|
+
if (!settingsKey) {
|
|
2144
|
+
return createToolResultError(
|
|
2145
|
+
`Block ${contentKey} in property "${propertyAlias}" has no settings entry, so its settings cannot be edited. Use inspect-blocks to check for a settingsKey, or omit blockType to edit the block's content.`
|
|
2146
|
+
);
|
|
2147
|
+
}
|
|
2148
|
+
targetKey = settingsKey;
|
|
2149
|
+
}
|
|
2003
2150
|
const propsTuple = values.map((v) => ({ alias: v.alias, value: v.value }));
|
|
2004
2151
|
const updateResult = await chainCms("update-block-property", {
|
|
2005
2152
|
documentId: id,
|
|
@@ -2007,12 +2154,41 @@ var tool18 = {
|
|
|
2007
2154
|
culture: culture ?? null,
|
|
2008
2155
|
segment: segment ?? null,
|
|
2009
2156
|
updates: [{
|
|
2010
|
-
contentKey,
|
|
2157
|
+
contentKey: targetKey,
|
|
2011
2158
|
blockType: resolvedBlockType,
|
|
2012
2159
|
properties: propsTuple
|
|
2013
2160
|
}]
|
|
2014
2161
|
});
|
|
2015
|
-
if (!updateResult.ok)
|
|
2162
|
+
if (!updateResult.ok) {
|
|
2163
|
+
return enrichBlockNotFoundError(updateResult.errorResult, docResult.data.values ?? [], {
|
|
2164
|
+
propertyAlias,
|
|
2165
|
+
note: `A block's settingsKey (reported by inspect-blocks) is not a valid contentKey \u2014 pass the block's contentKey together with blockType: "settings" to edit its settings instead.`
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
const results = updateResult.data.results;
|
|
2169
|
+
if (!results || results.length === 0) {
|
|
2170
|
+
return createToolResultError(
|
|
2171
|
+
"update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
2172
|
+
);
|
|
2173
|
+
}
|
|
2174
|
+
const classification = classifyBlockUpdateResults(results, fieldNames.length, fieldNames, 1);
|
|
2175
|
+
if (classification.outcome === "failed") {
|
|
2176
|
+
return createToolResultError(
|
|
2177
|
+
`Block update failed: ${classification.detail || updateResult.data.message || "no detail returned"}`
|
|
2178
|
+
);
|
|
2179
|
+
}
|
|
2180
|
+
if (classification.outcome === "partial") {
|
|
2181
|
+
return createToolResultError({
|
|
2182
|
+
message: `Block update partially failed: ${classification.processedCount} of ${fieldNames.length} field(s) saved \u2014 ${classification.detail}`,
|
|
2183
|
+
savedFields: classification.savedFields,
|
|
2184
|
+
failedFields: classification.failedFields,
|
|
2185
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {},
|
|
2186
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {},
|
|
2187
|
+
validation: await validateDocumentState(id),
|
|
2188
|
+
previewUrl: await fetchPreviewUrl(id)
|
|
2189
|
+
});
|
|
2190
|
+
}
|
|
2191
|
+
const warnings = classification.warnings;
|
|
2016
2192
|
const validation = await validateDocumentState(id);
|
|
2017
2193
|
const target = resolvedBlockType === "settings" ? "settings" : "content";
|
|
2018
2194
|
const baseMessage = `Updated ${fieldNames.length} field(s) in block ${target} on "${pageName}" (saved, not published)`;
|
|
@@ -2024,7 +2200,8 @@ var tool18 = {
|
|
|
2024
2200
|
contentKey,
|
|
2025
2201
|
updatedFields: fieldNames,
|
|
2026
2202
|
previewUrl: await fetchPreviewUrl(id),
|
|
2027
|
-
validation
|
|
2203
|
+
validation,
|
|
2204
|
+
...warnings.length ? { warnings } : {}
|
|
2028
2205
|
});
|
|
2029
2206
|
}
|
|
2030
2207
|
};
|
|
@@ -2077,10 +2254,9 @@ var tool19 = {
|
|
|
2077
2254
|
});
|
|
2078
2255
|
}
|
|
2079
2256
|
const cultureLabel = targetCulture ? ` (${targetCulture})` : "";
|
|
2080
|
-
const confirmed = await
|
|
2257
|
+
const confirmed = await requestApproval(
|
|
2081
2258
|
extra,
|
|
2082
|
-
`Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish
|
|
2083
|
-
{ title: "Confirm rename" }
|
|
2259
|
+
`Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish.`
|
|
2084
2260
|
);
|
|
2085
2261
|
if (!confirmed) {
|
|
2086
2262
|
return createToolResult({
|
|
@@ -2367,68 +2543,26 @@ var outputSchema24 = z.object({
|
|
|
2367
2543
|
previewUrl: previewUrlSchema,
|
|
2368
2544
|
validation: validationResultSchema
|
|
2369
2545
|
});
|
|
2370
|
-
function
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
}
|
|
2375
|
-
for (let i = 0; i < items.length; i++) {
|
|
2376
|
-
const item = items[i];
|
|
2377
|
-
if (!Array.isArray(item.areas)) continue;
|
|
2378
|
-
for (let aIdx = 0; aIdx < item.areas.length; aIdx++) {
|
|
2379
|
-
const inner = findAndRemoveGridItem(item.areas[aIdx].items ?? [], contentKey);
|
|
2380
|
-
if (inner.found) {
|
|
2381
|
-
const updatedAreas = item.areas.slice();
|
|
2382
|
-
updatedAreas[aIdx] = { ...item.areas[aIdx], items: inner.nextItems };
|
|
2383
|
-
const nextItems = items.slice();
|
|
2384
|
-
nextItems[i] = { ...item, areas: updatedAreas };
|
|
2385
|
-
return { found: true, doomedSettingsKey: inner.doomedSettingsKey, nextItems };
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
return { found: false };
|
|
2546
|
+
function gridContainsBlock(items, contentKey) {
|
|
2547
|
+
return items.some(
|
|
2548
|
+
(item) => item.contentKey === contentKey || (item.areas ?? []).some((area) => gridContainsBlock(area.items ?? [], contentKey))
|
|
2549
|
+
);
|
|
2390
2550
|
}
|
|
2391
|
-
function
|
|
2551
|
+
function locateBlock(propValue, editorAlias, propertyAlias, contentKey, pageName) {
|
|
2392
2552
|
const notFound = { ok: false, errorText: `Block '${contentKey}' was not found in property '${propertyAlias}'.` };
|
|
2393
2553
|
const draftSuffix = "Will be saved as a draft, not published.";
|
|
2394
|
-
if (
|
|
2395
|
-
const
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
if (!doomed) return notFound;
|
|
2399
|
-
return {
|
|
2400
|
-
ok: true,
|
|
2401
|
-
newValue: removeBlockFromContainer(propValue, contentKey, layoutKey, layoutList.filter((e) => e.contentKey !== contentKey), doomed.settingsKey),
|
|
2402
|
-
confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockList ${propertyAlias})? ${draftSuffix}`
|
|
2403
|
-
};
|
|
2554
|
+
if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockList") {
|
|
2555
|
+
const layoutList = propValue.layout?.["Umbraco.BlockList"] ?? [];
|
|
2556
|
+
if (!layoutList.some((e) => e.contentKey === contentKey)) return notFound;
|
|
2557
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockList ${propertyAlias})? ${draftSuffix}` };
|
|
2404
2558
|
}
|
|
2405
|
-
if (
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
if (!removed.found) return notFound;
|
|
2409
|
-
return {
|
|
2410
|
-
ok: true,
|
|
2411
|
-
newValue: removeBlockFromContainer(propValue, contentKey, layoutKey, removed.nextItems, removed.doomedSettingsKey),
|
|
2412
|
-
confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockGrid ${propertyAlias})? ${draftSuffix}`
|
|
2413
|
-
};
|
|
2559
|
+
if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockGrid") {
|
|
2560
|
+
if (!gridContainsBlock(propValue.layout?.["Umbraco.BlockGrid"] ?? [], contentKey)) return notFound;
|
|
2561
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockGrid ${propertyAlias})? ${draftSuffix}` };
|
|
2414
2562
|
}
|
|
2415
|
-
if (
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
const layoutList = blocks.layout?.[layoutKey] ?? [];
|
|
2419
|
-
const inContent = (blocks.contentData ?? []).some((e) => e.key === contentKey);
|
|
2420
|
-
if (!inContent) return notFound;
|
|
2421
|
-
const doomedSettingsKey = layoutList.find((e) => e.contentKey === contentKey)?.settingsKey;
|
|
2422
|
-
const tagRe = new RegExp(`<umb-rte-block[^>]*data-content-key="${contentKey}"[^>]*>\\s*</umb-rte-block>`, "gi");
|
|
2423
|
-
return {
|
|
2424
|
-
ok: true,
|
|
2425
|
-
newValue: {
|
|
2426
|
-
...propValue,
|
|
2427
|
-
markup: (propValue.markup ?? "").replace(tagRe, ""),
|
|
2428
|
-
blocks: removeBlockFromContainer(blocks, contentKey, layoutKey, layoutList.filter((e) => e.contentKey !== contentKey), doomedSettingsKey)
|
|
2429
|
-
},
|
|
2430
|
-
confirmMessage: `Remove block ${contentKey} from a Rich Text in "${pageName}" (${propertyAlias})? ${draftSuffix}`
|
|
2431
|
-
};
|
|
2563
|
+
if (isRteWithBlocks(propValue)) {
|
|
2564
|
+
if (!(propValue.blocks.contentData ?? []).some((e) => e.key === contentKey)) return notFound;
|
|
2565
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from a Rich Text in "${pageName}" (${propertyAlias})? ${draftSuffix}` };
|
|
2432
2566
|
}
|
|
2433
2567
|
return { ok: false, errorText: `Property '${propertyAlias}' on '${pageName}' is not a block-bearing property (BlockList, BlockGrid, or Rich Text with blocks). Use inspect-blocks to confirm.` };
|
|
2434
2568
|
}
|
|
@@ -2453,29 +2587,22 @@ var tool24 = {
|
|
|
2453
2587
|
isError: true
|
|
2454
2588
|
});
|
|
2455
2589
|
}
|
|
2456
|
-
const
|
|
2457
|
-
if (!
|
|
2458
|
-
return createToolResultError({ content: [{ type: "text", text:
|
|
2590
|
+
const location = locateBlock(prop.value, prop.editorAlias, propertyAlias, contentKey, pageName);
|
|
2591
|
+
if (!location.ok) {
|
|
2592
|
+
return createToolResultError({ content: [{ type: "text", text: location.errorText }], isError: true });
|
|
2459
2593
|
}
|
|
2460
|
-
if (!await requestApproval(extra,
|
|
2594
|
+
if (!await requestApproval(extra, location.confirmMessage)) {
|
|
2461
2595
|
return createToolResultError({ content: [{ type: "text", text: "Cancelled by user." }], isError: true });
|
|
2462
2596
|
}
|
|
2463
|
-
const
|
|
2464
|
-
id,
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
const baseMessage = `Removed block from "${pageName}" (saved, not published)`;
|
|
2470
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
2471
|
-
return createToolResult({
|
|
2472
|
-
message,
|
|
2473
|
-
id,
|
|
2474
|
-
name: pageName,
|
|
2475
|
-
contentKey,
|
|
2476
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
2477
|
-
validation
|
|
2597
|
+
const deleteResult = await chainCms("delete-document-block", {
|
|
2598
|
+
documentId: id,
|
|
2599
|
+
propertyAlias,
|
|
2600
|
+
culture: culture ?? null,
|
|
2601
|
+
segment: segment ?? null,
|
|
2602
|
+
contentKey
|
|
2478
2603
|
});
|
|
2604
|
+
if (!deleteResult.ok) return deleteResult.errorResult;
|
|
2605
|
+
return buildBlockWriteResult(id, pageName, contentKey, `Removed block from "${pageName}" (saved, not published)`);
|
|
2479
2606
|
}
|
|
2480
2607
|
};
|
|
2481
2608
|
var delete_block_default = withStandardDecorators(tool24);
|
|
@@ -2632,7 +2759,7 @@ function mergeValues(existing, updates) {
|
|
|
2632
2759
|
}
|
|
2633
2760
|
var tool27 = {
|
|
2634
2761
|
name: "save-and-publish",
|
|
2635
|
-
description: "Save property changes and publish a content page
|
|
2762
|
+
description: "Save property changes and publish a content page \u2014 mirrors the 'Save and publish' button in the Umbraco backoffice. If `values` is provided the changes are saved first; then the page is published. This is a single atomic operation when the connected Umbraco instance supports it (17.6+), otherwise a two-call save-then-publish sequence is used. Optionally publish descendants. Call get-page or get-document-type first to discover valid property aliases.",
|
|
2636
2763
|
inputSchema: inputSchema27,
|
|
2637
2764
|
outputSchema: outputSchema27,
|
|
2638
2765
|
slices: ["publish", "update"],
|
|
@@ -2692,20 +2819,53 @@ var tool27 = {
|
|
|
2692
2819
|
}
|
|
2693
2820
|
} else {
|
|
2694
2821
|
const mergedValues = mergeValues(doc.values ?? [], values ?? []);
|
|
2695
|
-
const
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2822
|
+
const variants = (doc.variants ?? []).map((v) => ({
|
|
2823
|
+
culture: v.culture ?? null,
|
|
2824
|
+
segment: v.segment ?? null,
|
|
2825
|
+
name: v.name
|
|
2826
|
+
}));
|
|
2827
|
+
if (await isCmsToolAvailable("update-and-publish-document")) {
|
|
2828
|
+
const updateAndPublishResult = await chainCms("update-and-publish-document", {
|
|
2829
|
+
id,
|
|
2830
|
+
data: {
|
|
2831
|
+
values: mergedValues,
|
|
2832
|
+
variants,
|
|
2833
|
+
template: doc.template ?? null,
|
|
2834
|
+
culturesToPublish: variantCultures.filter((c) => c !== null)
|
|
2835
|
+
}
|
|
2836
|
+
});
|
|
2837
|
+
if (!updateAndPublishResult.ok) return updateAndPublishResult.errorResult;
|
|
2838
|
+
} else {
|
|
2839
|
+
const updateResult = await chainCms("update-document", {
|
|
2840
|
+
id,
|
|
2841
|
+
data: {
|
|
2842
|
+
values: mergedValues,
|
|
2843
|
+
variants,
|
|
2844
|
+
template: doc.template ?? null
|
|
2845
|
+
}
|
|
2846
|
+
});
|
|
2847
|
+
if (!updateResult.ok) return updateResult.errorResult;
|
|
2848
|
+
const publishResult = await chainCms("publish-document", {
|
|
2849
|
+
id,
|
|
2850
|
+
data: {
|
|
2851
|
+
publishSchedules: variantCultures.map((c) => ({ culture: c }))
|
|
2852
|
+
}
|
|
2853
|
+
});
|
|
2854
|
+
if (!publishResult.ok) {
|
|
2855
|
+
if (saved) {
|
|
2856
|
+
return createToolResult({
|
|
2857
|
+
message: `Saved ${fieldNames.length} field(s) on "${pageName}" but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
|
|
2858
|
+
id,
|
|
2859
|
+
name: pageName,
|
|
2860
|
+
saved: true,
|
|
2861
|
+
published: false,
|
|
2862
|
+
updatedFields: fieldNames,
|
|
2863
|
+
publishedUrls: []
|
|
2864
|
+
});
|
|
2865
|
+
}
|
|
2866
|
+
return publishResult.errorResult;
|
|
2706
2867
|
}
|
|
2707
|
-
}
|
|
2708
|
-
if (!updateAndPublishResult.ok) return updateAndPublishResult.errorResult;
|
|
2868
|
+
}
|
|
2709
2869
|
}
|
|
2710
2870
|
if (!includeDescendants) {
|
|
2711
2871
|
const verifyError = await verifyDocumentPublished(id, variantCultures);
|
|
@@ -3557,12 +3717,7 @@ function validateBulkIds(ids) {
|
|
|
3557
3717
|
function parseBulkError(err) {
|
|
3558
3718
|
if (err === null || err === void 0) return "Unknown error";
|
|
3559
3719
|
if (typeof err === "object") {
|
|
3560
|
-
|
|
3561
|
-
const sc = asRecord.structuredContent;
|
|
3562
|
-
if (sc !== null && sc !== void 0 && typeof sc === "object") {
|
|
3563
|
-
return sc;
|
|
3564
|
-
}
|
|
3565
|
-
return err;
|
|
3720
|
+
return extractInnerProblemDetails(err);
|
|
3566
3721
|
}
|
|
3567
3722
|
if (typeof err === "string") {
|
|
3568
3723
|
try {
|
|
@@ -3831,6 +3986,15 @@ var tool46 = {
|
|
|
3831
3986
|
slices: ["list"],
|
|
3832
3987
|
annotations: { readOnlyHint: true },
|
|
3833
3988
|
handler: async ({ parentId, take, skip }) => {
|
|
3989
|
+
const accessCheck = await checkSettingsAccess();
|
|
3990
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
3991
|
+
if (!accessCheck.hasAccess) {
|
|
3992
|
+
return createToolResultError({
|
|
3993
|
+
status: 403,
|
|
3994
|
+
title: "Settings access required",
|
|
3995
|
+
detail: "Listing blueprints requires the signed-in Umbraco user to have access to the Settings section. Grant Settings-section access to the user's group in the Umbraco backoffice (Users \u2192 [group] \u2192 Sections), then retry."
|
|
3996
|
+
});
|
|
3997
|
+
}
|
|
3834
3998
|
const cursor = buildChainedCursor(skip, take);
|
|
3835
3999
|
const result = parentId ? await chainCms("get-document-blueprint-children", { parentId, cursor }) : await chainCms("get-document-blueprint-root", { cursor });
|
|
3836
4000
|
if (!result.ok) return result.errorResult;
|
|
@@ -4729,11 +4893,11 @@ var tool64 = {
|
|
|
4729
4893
|
const headings = extractHeadings(allHtml);
|
|
4730
4894
|
const images = extractImages(allHtml);
|
|
4731
4895
|
const bodyWordCount = countWords(extractTextContent(values));
|
|
4732
|
-
const
|
|
4896
|
+
const url = await fetchPrimaryPublishedUrl(id);
|
|
4733
4897
|
return createToolResult({
|
|
4734
4898
|
id: doc.id,
|
|
4735
4899
|
name: variant?.name ?? "Unknown",
|
|
4736
|
-
url
|
|
4900
|
+
url,
|
|
4737
4901
|
hasTitle: title.length > 0,
|
|
4738
4902
|
hasMetaDescription: metaDescription.length > 0,
|
|
4739
4903
|
titleLength: title.length,
|
|
@@ -4792,12 +4956,12 @@ var tool65 = {
|
|
|
4792
4956
|
const fullBodyText = extractTextContent(values);
|
|
4793
4957
|
const bodyContent = fullBodyText.slice(0, BODY_CONTENT_MAX);
|
|
4794
4958
|
const wordCount = fullBodyText ? fullBodyText.split(/\s+/).filter(Boolean).length : 0;
|
|
4795
|
-
const extra = doc;
|
|
4796
4959
|
const dt = doc.documentType;
|
|
4960
|
+
const url = await fetchPrimaryPublishedUrl(id);
|
|
4797
4961
|
return createToolResult({
|
|
4798
4962
|
id: doc.id,
|
|
4799
4963
|
name: variant?.name ?? "Unknown",
|
|
4800
|
-
url
|
|
4964
|
+
url,
|
|
4801
4965
|
hasMetaDescription: metaDescription.length > 0,
|
|
4802
4966
|
bodyWordCount: wordCount,
|
|
4803
4967
|
metaDescription,
|
|
@@ -4848,6 +5012,9 @@ async function fetchTreeLevel(parentId, depth) {
|
|
|
4848
5012
|
}
|
|
4849
5013
|
async function buildTreeNodes(parentId, depth, maxDepth, pagesPerLevel, totalRef, maxDepthRef) {
|
|
4850
5014
|
const items = await fetchTreeLevel(parentId);
|
|
5015
|
+
const urlsById = await fetchPrimaryPublishedUrlsBatch(
|
|
5016
|
+
items.map((item) => item.id).filter((id) => typeof id === "string")
|
|
5017
|
+
);
|
|
4851
5018
|
const nodes = [];
|
|
4852
5019
|
for (const item of items) {
|
|
4853
5020
|
totalRef.count++;
|
|
@@ -4863,7 +5030,7 @@ async function buildTreeNodes(parentId, depth, maxDepth, pagesPerLevel, totalRef
|
|
|
4863
5030
|
nodes.push({
|
|
4864
5031
|
id: item.id ?? "",
|
|
4865
5032
|
name: item.name ?? item.variants?.[0]?.name ?? "Unknown",
|
|
4866
|
-
url:
|
|
5033
|
+
url: urlsById.get(item.id) ?? "",
|
|
4867
5034
|
documentType: item.documentType?.name ?? item.contentTypeName ?? "",
|
|
4868
5035
|
depth,
|
|
4869
5036
|
childCount: children.length,
|
|
@@ -4931,6 +5098,9 @@ var tool67 = {
|
|
|
4931
5098
|
if (!result.ok) return;
|
|
4932
5099
|
const data = result.data;
|
|
4933
5100
|
const items = data?.items ?? [];
|
|
5101
|
+
const urlsById = await fetchPrimaryPublishedUrlsBatch(
|
|
5102
|
+
items.map((item) => item.id).filter((id) => typeof id === "string")
|
|
5103
|
+
);
|
|
4934
5104
|
for (const item of items) {
|
|
4935
5105
|
if (scannedRef.count >= 500) break;
|
|
4936
5106
|
scannedRef.count++;
|
|
@@ -4939,7 +5109,7 @@ var tool67 = {
|
|
|
4939
5109
|
allPages.push({
|
|
4940
5110
|
id: item.id ?? "",
|
|
4941
5111
|
name,
|
|
4942
|
-
url:
|
|
5112
|
+
url: urlsById.get(item.id) ?? "",
|
|
4943
5113
|
documentType: item.documentType?.name ?? item.contentTypeName ?? "",
|
|
4944
5114
|
depth,
|
|
4945
5115
|
rawDepth: depth,
|
|
@@ -5364,7 +5534,7 @@ var inputSchema73 = {
|
|
|
5364
5534
|
contentTypeKey: z.string().uuid().describe("The block element type key to target. Use inspect-blocks to find this."),
|
|
5365
5535
|
propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'contentRows'). Use inspect-blocks to find this."),
|
|
5366
5536
|
values: z.array(z.object({
|
|
5367
|
-
alias:
|
|
5537
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
5368
5538
|
value: z.any().describe("The new value for the property")
|
|
5369
5539
|
})).min(1).describe("Properties to update on every matching block"),
|
|
5370
5540
|
culture: z.string().nullable().optional().describe("Culture code if the document property is variant"),
|
|
@@ -5380,7 +5550,8 @@ var outputSchema73 = z.object({
|
|
|
5380
5550
|
previousVersionId: z.string().optional(),
|
|
5381
5551
|
error: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
|
|
5382
5552
|
previewUrl: previewUrlSchema.optional(),
|
|
5383
|
-
validation: validationResultSchema.optional()
|
|
5553
|
+
validation: validationResultSchema.optional(),
|
|
5554
|
+
warnings: z.array(z.string()).optional()
|
|
5384
5555
|
})),
|
|
5385
5556
|
successCount: z.number(),
|
|
5386
5557
|
failureCount: z.number(),
|
|
@@ -5424,6 +5595,7 @@ var tool73 = {
|
|
|
5424
5595
|
});
|
|
5425
5596
|
const items = [];
|
|
5426
5597
|
const pageBlocks = /* @__PURE__ */ new Map();
|
|
5598
|
+
const docValuesByItem = /* @__PURE__ */ new Map();
|
|
5427
5599
|
for (const id of ids) {
|
|
5428
5600
|
const docResult = await chainCms("get-document-by-id", { id });
|
|
5429
5601
|
if (!docResult.ok) continue;
|
|
@@ -5437,6 +5609,7 @@ var tool73 = {
|
|
|
5437
5609
|
const currentVersionId = versionData?.items?.[0]?.id ?? "";
|
|
5438
5610
|
items.push({ id, name, currentVersionId });
|
|
5439
5611
|
pageBlocks.set(id, findMatchingBlocks(doc, propertyAlias, contentTypeKey));
|
|
5612
|
+
docValuesByItem.set(id, doc.values ?? []);
|
|
5440
5613
|
}
|
|
5441
5614
|
if (items.length === 0) {
|
|
5442
5615
|
return createToolResult({
|
|
@@ -5509,28 +5682,68 @@ Changes will be saved but not published.`;
|
|
|
5509
5682
|
updates
|
|
5510
5683
|
});
|
|
5511
5684
|
if (!updateResult.ok) {
|
|
5685
|
+
const enriched = enrichBlockNotFoundError(
|
|
5686
|
+
updateResult.errorResult,
|
|
5687
|
+
docValuesByItem.get(item.id) ?? [],
|
|
5688
|
+
{ propertyAlias }
|
|
5689
|
+
);
|
|
5512
5690
|
results.push({
|
|
5513
5691
|
id: item.id,
|
|
5514
5692
|
name: item.name,
|
|
5515
5693
|
success: false,
|
|
5516
5694
|
blocksUpdated: 0,
|
|
5517
5695
|
previousVersionId: item.currentVersionId || void 0,
|
|
5518
|
-
error: parseBulkError(
|
|
5696
|
+
error: parseBulkError(enriched)
|
|
5519
5697
|
});
|
|
5520
5698
|
stopped = true;
|
|
5521
5699
|
} else {
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5700
|
+
const blockResults = updateResult.data.results;
|
|
5701
|
+
if (!blockResults || blockResults.length === 0) {
|
|
5702
|
+
results.push({
|
|
5703
|
+
id: item.id,
|
|
5704
|
+
name: item.name,
|
|
5705
|
+
success: false,
|
|
5706
|
+
blocksUpdated: 0,
|
|
5707
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5708
|
+
error: "update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
5709
|
+
});
|
|
5710
|
+
stopped = true;
|
|
5711
|
+
} else {
|
|
5712
|
+
const classification = classifyBlockUpdateResults(blockResults, blocks.length * values.length, fieldNames, blocks.length);
|
|
5713
|
+
if (classification.outcome === "clean") {
|
|
5714
|
+
totalBlocksUpdated += blocks.length;
|
|
5715
|
+
results.push({
|
|
5716
|
+
id: item.id,
|
|
5717
|
+
name: item.name,
|
|
5718
|
+
success: true,
|
|
5719
|
+
blocksUpdated: blocks.length,
|
|
5720
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5721
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
5722
|
+
});
|
|
5723
|
+
} else {
|
|
5724
|
+
totalBlocksUpdated += classification.updatedEntryCount;
|
|
5725
|
+
const totalProperties = blocks.length * values.length;
|
|
5726
|
+
results.push({
|
|
5727
|
+
id: item.id,
|
|
5728
|
+
name: item.name,
|
|
5729
|
+
success: false,
|
|
5730
|
+
blocksUpdated: classification.updatedEntryCount,
|
|
5731
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5732
|
+
error: classification.outcome === "failed" ? `Block update failed: ${classification.detail}` : {
|
|
5733
|
+
message: `Block update partially failed: ${classification.processedCount} of ${totalProperties} propert${totalProperties === 1 ? "y" : "ies"} saved, across ${classification.updatedEntryCount} of ${blockResults.length} block(s)` + (classification.unresolvedBlockCount > 0 ? ` (${classification.unresolvedBlockCount} matched block(s) could not be located \u2014 likely changed concurrently; rerun this tool to retarget them)` : "") + ` \u2014 ${classification.detail}`,
|
|
5734
|
+
savedFields: classification.savedFields,
|
|
5735
|
+
failedFields: classification.failedFields,
|
|
5736
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {}
|
|
5737
|
+
},
|
|
5738
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
5739
|
+
});
|
|
5740
|
+
stopped = true;
|
|
5741
|
+
}
|
|
5742
|
+
}
|
|
5530
5743
|
}
|
|
5531
5744
|
}
|
|
5532
5745
|
for (const row of results) {
|
|
5533
|
-
if (
|
|
5746
|
+
if (row.blocksUpdated === 0) continue;
|
|
5534
5747
|
row.validation = await validateDocumentState(row.id);
|
|
5535
5748
|
row.previewUrl = await fetchPreviewUrl(row.id);
|
|
5536
5749
|
}
|
|
@@ -5615,12 +5828,10 @@ var tool74 = {
|
|
|
5615
5828
|
var search_members_default = withStandardDecorators(tool74);
|
|
5616
5829
|
|
|
5617
5830
|
// src/umbraco-api/tools/member/sensitive-data-access.ts
|
|
5618
|
-
|
|
5619
|
-
async function hasSensitiveDataAccess() {
|
|
5620
|
-
if (cachedAccess !== void 0) return cachedAccess;
|
|
5831
|
+
async function checkSensitiveDataAccess() {
|
|
5621
5832
|
const result = await chainCms("get-user-current", {});
|
|
5622
|
-
|
|
5623
|
-
return
|
|
5833
|
+
if (!result.ok) return result;
|
|
5834
|
+
return { ok: true, hasAccess: result.data.hasAccessToSensitiveData ?? false };
|
|
5624
5835
|
}
|
|
5625
5836
|
|
|
5626
5837
|
// src/umbraco-api/tools/member/get/get-member.ts
|
|
@@ -5658,7 +5869,8 @@ var tool75 = {
|
|
|
5658
5869
|
const result = await chainCms("get-member", { id });
|
|
5659
5870
|
if (!result.ok) return result.errorResult;
|
|
5660
5871
|
const data = result.data;
|
|
5661
|
-
const
|
|
5872
|
+
const accessCheck = await checkSensitiveDataAccess();
|
|
5873
|
+
const accessible = accessCheck.ok && accessCheck.hasAccess;
|
|
5662
5874
|
return createToolResult({
|
|
5663
5875
|
id: data.id ?? id,
|
|
5664
5876
|
name: data.variants?.[0]?.name ?? "Unknown",
|
|
@@ -5817,12 +6029,16 @@ var tool78 = {
|
|
|
5817
6029
|
slices: ["update"],
|
|
5818
6030
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
5819
6031
|
handler: async ({ id, name, email, username, newPassword, isTwoFactorEnabled, isApproved, isLockedOut, groups, values }, extra) => {
|
|
5820
|
-
if (
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
6032
|
+
if (isApproved !== void 0 || isLockedOut !== void 0 || isTwoFactorEnabled !== void 0) {
|
|
6033
|
+
const accessCheck = await checkSensitiveDataAccess();
|
|
6034
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
6035
|
+
if (!accessCheck.hasAccess) {
|
|
6036
|
+
return createToolResultError({
|
|
6037
|
+
status: 403,
|
|
6038
|
+
title: "Sensitive Data access required",
|
|
6039
|
+
detail: "Updating isApproved, isLockedOut, or isTwoFactorEnabled requires the signed-in Umbraco user to be in the built-in Sensitive Data user group (group key 8C6AD70F-D307-4E4A-AF58-72C2E4E9439D). In the Umbraco backoffice, edit the user's User group under Users and add the Sensitive Data group, then retry. Other update-member fields (name, email, username, groups, values, newPassword) are not affected."
|
|
6040
|
+
});
|
|
6041
|
+
}
|
|
5826
6042
|
}
|
|
5827
6043
|
const memberResult = await chainCms("get-member", { id });
|
|
5828
6044
|
if (!memberResult.ok) return memberResult.errorResult;
|
|
@@ -6535,6 +6751,26 @@ var outputSchema93 = z.object({
|
|
|
6535
6751
|
).describe("Pages that reference this item"),
|
|
6536
6752
|
referenceCount: z.number().describe("Total number of pages referencing this item")
|
|
6537
6753
|
});
|
|
6754
|
+
async function buildReferencedBy(refItems) {
|
|
6755
|
+
const docRefIds = refItems.filter((ref) => ref.$type === "DocumentReferenceResponseModel").map((ref) => ref.id);
|
|
6756
|
+
const urlsById = await fetchPrimaryPublishedUrlsBatch(docRefIds);
|
|
6757
|
+
return refItems.map((ref) => {
|
|
6758
|
+
if (ref.$type === "DocumentReferenceResponseModel") {
|
|
6759
|
+
return {
|
|
6760
|
+
id: ref.id,
|
|
6761
|
+
name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
|
|
6762
|
+
url: urlsById.get(ref.id) ?? "",
|
|
6763
|
+
documentType: ref.documentType?.alias ?? ""
|
|
6764
|
+
};
|
|
6765
|
+
}
|
|
6766
|
+
return {
|
|
6767
|
+
id: ref.id,
|
|
6768
|
+
name: ref.name ?? "(unnamed)",
|
|
6769
|
+
url: "",
|
|
6770
|
+
documentType: ""
|
|
6771
|
+
};
|
|
6772
|
+
});
|
|
6773
|
+
}
|
|
6538
6774
|
var tool93 = {
|
|
6539
6775
|
name: "report-content-references",
|
|
6540
6776
|
description: "Find which pages reference a given content page or media item. Useful before deleting or restructuring content to understand the impact.",
|
|
@@ -6549,32 +6785,11 @@ var tool93 = {
|
|
|
6549
6785
|
chainCms("get-document-by-id-referenced-by", { id })
|
|
6550
6786
|
]);
|
|
6551
6787
|
let name = "Unknown";
|
|
6552
|
-
let url = "";
|
|
6553
6788
|
if (docResult.ok) {
|
|
6554
|
-
|
|
6555
|
-
name = doc.variants?.[0]?.name ?? "Unknown";
|
|
6556
|
-
url = doc.urls?.[0]?.url ?? "";
|
|
6557
|
-
}
|
|
6558
|
-
const referencedBy = [];
|
|
6559
|
-
if (refResult.ok) {
|
|
6560
|
-
for (const ref of refResult.data.items ?? []) {
|
|
6561
|
-
if (ref.$type === "DocumentReferenceResponseModel") {
|
|
6562
|
-
referencedBy.push({
|
|
6563
|
-
id: ref.id,
|
|
6564
|
-
name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
|
|
6565
|
-
url: ref.urls?.[0]?.url ?? ref.url ?? "",
|
|
6566
|
-
documentType: ref.documentType?.alias ?? ""
|
|
6567
|
-
});
|
|
6568
|
-
} else {
|
|
6569
|
-
referencedBy.push({
|
|
6570
|
-
id: ref.id,
|
|
6571
|
-
name: ref.name ?? "(unnamed)",
|
|
6572
|
-
url: "",
|
|
6573
|
-
documentType: ""
|
|
6574
|
-
});
|
|
6575
|
-
}
|
|
6576
|
-
}
|
|
6789
|
+
name = docResult.data.variants?.[0]?.name ?? "Unknown";
|
|
6577
6790
|
}
|
|
6791
|
+
const url = await fetchPrimaryPublishedUrl(id);
|
|
6792
|
+
const referencedBy = refResult.ok ? await buildReferencedBy(refResult.data.items ?? []) : [];
|
|
6578
6793
|
return createToolResult({
|
|
6579
6794
|
id,
|
|
6580
6795
|
name,
|
|
@@ -6598,26 +6813,7 @@ var tool93 = {
|
|
|
6598
6813
|
const entry = urlResult.data.items?.find((u) => u.id === id);
|
|
6599
6814
|
url = entry?.urlInfos?.[0]?.url ?? "";
|
|
6600
6815
|
}
|
|
6601
|
-
const referencedBy = [];
|
|
6602
|
-
if (refResult.ok) {
|
|
6603
|
-
for (const ref of refResult.data.items ?? []) {
|
|
6604
|
-
if (ref.$type === "DocumentReferenceResponseModel") {
|
|
6605
|
-
referencedBy.push({
|
|
6606
|
-
id: ref.id,
|
|
6607
|
-
name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
|
|
6608
|
-
url: ref.urls?.[0]?.url ?? ref.url ?? "",
|
|
6609
|
-
documentType: ref.documentType?.alias ?? ""
|
|
6610
|
-
});
|
|
6611
|
-
} else {
|
|
6612
|
-
referencedBy.push({
|
|
6613
|
-
id: ref.id,
|
|
6614
|
-
name: ref.name ?? "(unnamed)",
|
|
6615
|
-
url: "",
|
|
6616
|
-
documentType: ""
|
|
6617
|
-
});
|
|
6618
|
-
}
|
|
6619
|
-
}
|
|
6620
|
-
}
|
|
6816
|
+
const referencedBy = refResult.ok ? await buildReferencedBy(refResult.data.items ?? []) : [];
|
|
6621
6817
|
return createToolResult({
|
|
6622
6818
|
id,
|
|
6623
6819
|
name,
|
|
@@ -6790,18 +6986,18 @@ async function resolveOutboundIds(candidateIds, excludeId) {
|
|
|
6790
6986
|
const internalPages = [];
|
|
6791
6987
|
const media = [];
|
|
6792
6988
|
const filtered = excludeId ? candidateIds.filter((cid) => cid !== excludeId.toLowerCase()) : candidateIds;
|
|
6989
|
+
const urlsById = await fetchPrimaryPublishedUrlsBatch(filtered);
|
|
6793
6990
|
await Promise.all(
|
|
6794
6991
|
filtered.map(async (refId) => {
|
|
6795
6992
|
try {
|
|
6796
6993
|
const docResult = await chainCms("get-document-by-id", { id: refId });
|
|
6797
6994
|
if (docResult.ok) {
|
|
6798
6995
|
const refDoc = docResult.data;
|
|
6799
|
-
const docExtra = refDoc;
|
|
6800
6996
|
const docType = refDoc.documentType;
|
|
6801
6997
|
internalPages.push({
|
|
6802
6998
|
id: refId,
|
|
6803
6999
|
name: refDoc.variants?.[0]?.name ?? "Unknown",
|
|
6804
|
-
url:
|
|
7000
|
+
url: urlsById.get(refId) ?? "",
|
|
6805
7001
|
documentType: docType?.alias ?? ""
|
|
6806
7002
|
});
|
|
6807
7003
|
return;
|
|
@@ -6875,7 +7071,7 @@ var tool94 = {
|
|
|
6875
7071
|
const doc = result.data;
|
|
6876
7072
|
const variant = doc.variants?.[0];
|
|
6877
7073
|
const name = variant?.name ?? "Unknown";
|
|
6878
|
-
const url =
|
|
7074
|
+
const url = await fetchPrimaryPublishedUrl(id);
|
|
6879
7075
|
const values = doc.values ?? [];
|
|
6880
7076
|
const links = extractLinksFromValues(values);
|
|
6881
7077
|
const { internalPages, media } = await resolveOutboundIds(links.allIds, id);
|
|
@@ -7611,17 +7807,16 @@ Talk like a helpful colleague, not a developer. Many editors are not very techni
|
|
|
7611
7807
|
- If a tool fails, say what went wrong in plain language and suggest the next step the editor can take. Don't dump stack traces or raw error payloads on them.
|
|
7612
7808
|
- It's fine to ask a clarifying question if you genuinely need one \u2014 but only if the answer would change what you do. Otherwise just get on with it.
|
|
7613
7809
|
|
|
7614
|
-
# Confirmations come from the tools, not from you
|
|
7810
|
+
# Confirmations come from the host and the tools, not from you
|
|
7615
7811
|
|
|
7616
|
-
|
|
7812
|
+
Changes such as publishing, unpublishing, deleting, moving, or bulk edits are confirmed by a prompt the editor sees. That's either the tool's own confirmation (in hosts that support MCP elicitation) or the host's own approval step (e.g. ChatGPT's Allow / Deny). The editor is never asked twice. That prompt is their consent:
|
|
7617
7813
|
|
|
7618
|
-
-
|
|
7619
|
-
-
|
|
7620
|
-
-
|
|
7621
|
-
-
|
|
7622
|
-
- If the editor cancels at the prompt, treat that as a clear "no" \u2014 acknowledge it warmly and stop. Don't retry or argue.
|
|
7814
|
+
- Before calling the tool, say accurately and in editorial terms what will happen (e.g. "this will take the Home page off the live website").
|
|
7815
|
+
- Never answer or bypass a prompt on the editor's behalf, and don't bundle actions to avoid prompts.
|
|
7816
|
+
- Only say something is done once the tool has returned success.
|
|
7817
|
+
- If the editor declines, accept it warmly and stop.
|
|
7623
7818
|
|
|
7624
|
-
Being friendly never means being loose with destructive actions.
|
|
7819
|
+
Being friendly never means being loose with destructive actions.
|
|
7625
7820
|
|
|
7626
7821
|
# Never show internal IDs or UUIDs to the editor
|
|
7627
7822
|
|