@umbraco-cms/mcp-editor 17.6.0-beta.6 → 17.6.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collections.js +812 -652
- package/dist/collections.js.map +1 -1
- package/dist/index.js +820 -661
- 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.7"};
|
|
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({
|
|
@@ -571,6 +592,19 @@ var tool3 = {
|
|
|
571
592
|
}
|
|
572
593
|
};
|
|
573
594
|
var list_children_default = withStandardDecorators(tool3);
|
|
595
|
+
|
|
596
|
+
// src/auth/auth-policies.ts
|
|
597
|
+
var sections = {
|
|
598
|
+
settings: "Umb.Section.Settings"};
|
|
599
|
+
|
|
600
|
+
// src/umbraco-api/tools/helpers/settings-access.ts
|
|
601
|
+
async function checkSettingsAccess() {
|
|
602
|
+
const result = await chainCms("get-user-current", {});
|
|
603
|
+
if (!result.ok) return result;
|
|
604
|
+
return { ok: true, hasAccess: result.data.allowedSections?.includes(sections.settings) ?? false };
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// src/umbraco-api/tools/content/get/list-document-types.ts
|
|
574
608
|
var inputSchema4 = {
|
|
575
609
|
take: z.number().optional().default(50).describe("Number of results to return"),
|
|
576
610
|
skip: z.number().optional().default(0).describe("Number of results to skip")
|
|
@@ -593,11 +627,14 @@ async function collectDocumentTypeIds() {
|
|
|
593
627
|
let result;
|
|
594
628
|
while (true) {
|
|
595
629
|
result = parentId ? await chainCms("get-document-type-children", { parentId, cursor }) : await chainCms("get-document-type-root", { cursor });
|
|
596
|
-
if (!result.ok) return;
|
|
630
|
+
if (!result.ok) return { ok: false, errorResult: result.errorResult };
|
|
597
631
|
const items = result.data.items ?? [];
|
|
598
632
|
for (const item of items) {
|
|
599
633
|
if (item.isFolder) {
|
|
600
|
-
if (item.hasChildren)
|
|
634
|
+
if (item.hasChildren) {
|
|
635
|
+
const childResult = await walk(item.id);
|
|
636
|
+
if (childResult && !childResult.ok) return childResult;
|
|
637
|
+
}
|
|
601
638
|
} else {
|
|
602
639
|
collected.push(item);
|
|
603
640
|
}
|
|
@@ -606,26 +643,35 @@ async function collectDocumentTypeIds() {
|
|
|
606
643
|
if (!nextCursor) break;
|
|
607
644
|
cursor = nextCursor;
|
|
608
645
|
}
|
|
646
|
+
return void 0;
|
|
609
647
|
}
|
|
610
|
-
await walk(void 0);
|
|
611
|
-
return
|
|
648
|
+
const failure = await walk(void 0);
|
|
649
|
+
if (failure && !failure.ok) return failure;
|
|
650
|
+
return { ok: true, nodes: collected };
|
|
612
651
|
}
|
|
613
652
|
async function resolveDocTypeDetails(nodes) {
|
|
614
653
|
const results = await Promise.all(
|
|
615
654
|
nodes.map(async (node) => {
|
|
616
655
|
const detailResult = await chainCms("get-document-type-by-id", { id: node.id });
|
|
617
|
-
if (!detailResult.ok) return
|
|
656
|
+
if (!detailResult.ok) return { ok: false, errorResult: detailResult.errorResult, node };
|
|
618
657
|
const d = detailResult.data;
|
|
619
658
|
return {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
659
|
+
ok: true,
|
|
660
|
+
details: [{
|
|
661
|
+
id: node.id,
|
|
662
|
+
alias: d.alias ?? "",
|
|
663
|
+
name: d.name ?? node.name,
|
|
664
|
+
description: d.description ?? void 0,
|
|
665
|
+
icon: d.icon ?? node.icon
|
|
666
|
+
}],
|
|
667
|
+
node
|
|
625
668
|
};
|
|
626
669
|
})
|
|
627
670
|
);
|
|
628
|
-
|
|
671
|
+
const failed = results.find((r) => !r.ok);
|
|
672
|
+
if (failed && !failed.ok) return { ok: false, errorResult: failed.errorResult };
|
|
673
|
+
const details = results.flatMap((r) => r.ok ? r.details : []);
|
|
674
|
+
return { ok: true, details };
|
|
629
675
|
}
|
|
630
676
|
var tool4 = {
|
|
631
677
|
name: "list-document-types",
|
|
@@ -635,9 +681,22 @@ var tool4 = {
|
|
|
635
681
|
slices: ["list"],
|
|
636
682
|
annotations: { readOnlyHint: true },
|
|
637
683
|
handler: async ({ take, skip }) => {
|
|
638
|
-
const
|
|
684
|
+
const accessCheck = await checkSettingsAccess();
|
|
685
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
686
|
+
if (!accessCheck.hasAccess) {
|
|
687
|
+
return createToolResultError({
|
|
688
|
+
status: 403,
|
|
689
|
+
title: "Settings access required",
|
|
690
|
+
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."
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
const treeResult = await collectDocumentTypeIds();
|
|
694
|
+
if (!treeResult.ok) return treeResult.errorResult;
|
|
695
|
+
const { nodes } = treeResult;
|
|
639
696
|
const sliced = nodes.slice(skip, skip + take);
|
|
640
|
-
const
|
|
697
|
+
const detailsResult = await resolveDocTypeDetails(sliced);
|
|
698
|
+
if (!detailsResult.ok) return detailsResult.errorResult;
|
|
699
|
+
const { details } = detailsResult;
|
|
641
700
|
return createToolResult({
|
|
642
701
|
items: details.map((d) => ({
|
|
643
702
|
id: d.id,
|
|
@@ -651,6 +710,73 @@ var tool4 = {
|
|
|
651
710
|
}
|
|
652
711
|
};
|
|
653
712
|
var list_document_types_default = withStandardDecorators(tool4);
|
|
713
|
+
|
|
714
|
+
// src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
|
|
715
|
+
async function resolveDocumentTypeProperties(documentTypeId) {
|
|
716
|
+
const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
|
|
717
|
+
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
718
|
+
const data = docTypeResult.data;
|
|
719
|
+
const collected = /* @__PURE__ */ new Map();
|
|
720
|
+
function addProperties(props) {
|
|
721
|
+
for (const p of props) {
|
|
722
|
+
if (p.alias && !collected.has(p.alias)) {
|
|
723
|
+
collected.set(p.alias, p);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
function compositionIdsOf(d) {
|
|
728
|
+
return Array.from(
|
|
729
|
+
new Set(
|
|
730
|
+
(d.compositions ?? []).map((c) => c.documentType?.id).filter((id) => typeof id === "string")
|
|
731
|
+
)
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
function describeFailure(errorResult) {
|
|
735
|
+
const text = errorResult.content?.[0]?.type === "text" ? errorResult.content[0].text : void 0;
|
|
736
|
+
if (!text) return "unknown error";
|
|
737
|
+
try {
|
|
738
|
+
const parsed = JSON.parse(text);
|
|
739
|
+
const detail = parsed?.detail;
|
|
740
|
+
return typeof detail === "string" ? detail : text;
|
|
741
|
+
} catch {
|
|
742
|
+
return text;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
addProperties(Array.isArray(data.properties) ? data.properties : []);
|
|
746
|
+
const visited = /* @__PURE__ */ new Set([documentTypeId]);
|
|
747
|
+
const failedCompositionIds = [];
|
|
748
|
+
const failedCompositionDetails = [];
|
|
749
|
+
let frontier = compositionIdsOf(data).filter((id) => !visited.has(id));
|
|
750
|
+
frontier.forEach((id) => visited.add(id));
|
|
751
|
+
while (frontier.length > 0) {
|
|
752
|
+
const results = await Promise.all(frontier.map((id) => chainCms("get-document-type-by-id", { id })));
|
|
753
|
+
const nextFrontier = [];
|
|
754
|
+
results.forEach((r, i) => {
|
|
755
|
+
if (!r.ok) {
|
|
756
|
+
failedCompositionIds.push(frontier[i]);
|
|
757
|
+
failedCompositionDetails.push(describeFailure(r.errorResult));
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
if (Array.isArray(r.data.properties)) addProperties(r.data.properties);
|
|
761
|
+
for (const id of compositionIdsOf(r.data)) {
|
|
762
|
+
if (!visited.has(id)) {
|
|
763
|
+
visited.add(id);
|
|
764
|
+
nextFrontier.push(id);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
frontier = nextFrontier;
|
|
769
|
+
}
|
|
770
|
+
return {
|
|
771
|
+
ok: true,
|
|
772
|
+
documentType: data,
|
|
773
|
+
properties: Array.from(collected.values()),
|
|
774
|
+
failedCompositionIds,
|
|
775
|
+
failedCompositionDetails
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// src/umbraco-api/tools/content/get/get-document-type.ts
|
|
654
780
|
var inputSchema5 = {
|
|
655
781
|
id: z.string().uuid().describe("UUID of the document type to retrieve")
|
|
656
782
|
};
|
|
@@ -678,30 +804,9 @@ var tool5 = {
|
|
|
678
804
|
slices: ["read"],
|
|
679
805
|
annotations: { readOnlyHint: true },
|
|
680
806
|
handler: async ({ id }) => {
|
|
681
|
-
const result = await
|
|
807
|
+
const result = await resolveDocumentTypeProperties(id);
|
|
682
808
|
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
|
-
}
|
|
809
|
+
const { documentType: data, properties } = result;
|
|
705
810
|
return createToolResult({
|
|
706
811
|
id: data.id ?? id,
|
|
707
812
|
alias: data.alias ?? "",
|
|
@@ -709,7 +814,7 @@ var tool5 = {
|
|
|
709
814
|
description: data.description || void 0,
|
|
710
815
|
variesByCulture: data.variesByCulture || void 0,
|
|
711
816
|
variesBySegment: data.variesBySegment || void 0,
|
|
712
|
-
properties:
|
|
817
|
+
properties: properties.map((p) => ({
|
|
713
818
|
alias: p.alias ?? "",
|
|
714
819
|
name: p.name ?? p.alias ?? "",
|
|
715
820
|
description: p.description || void 0,
|
|
@@ -721,6 +826,228 @@ var tool5 = {
|
|
|
721
826
|
}
|
|
722
827
|
};
|
|
723
828
|
var get_document_type_default = withStandardDecorators(tool5);
|
|
829
|
+
var validationErrorSchema = z.object({
|
|
830
|
+
propertyAlias: z.string().describe(
|
|
831
|
+
"The alias of the property that failed validation, or '__document__' for document-level errors (mandatory cultures, name length, etc.)."
|
|
832
|
+
),
|
|
833
|
+
culture: z.string().nullable().optional().describe("Culture for variant content. Null for invariant."),
|
|
834
|
+
segment: z.string().nullable().optional().describe("Segment for segmented content. Null when none."),
|
|
835
|
+
message: z.string().describe("Human-readable validation error message.")
|
|
836
|
+
});
|
|
837
|
+
var validationResultSchema = z.object({
|
|
838
|
+
valid: z.boolean().describe("True when the saved document passes server-side validation and is publishable."),
|
|
839
|
+
errors: z.array(validationErrorSchema).describe(
|
|
840
|
+
"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."
|
|
841
|
+
)
|
|
842
|
+
}).describe(
|
|
843
|
+
"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."
|
|
844
|
+
);
|
|
845
|
+
async function validateDocumentState(id, doc) {
|
|
846
|
+
let target = null;
|
|
847
|
+
if (!target) {
|
|
848
|
+
const docResult = await chainCms("get-document-by-id", { id });
|
|
849
|
+
if (!docResult.ok) {
|
|
850
|
+
return {
|
|
851
|
+
valid: false,
|
|
852
|
+
errors: [
|
|
853
|
+
{
|
|
854
|
+
propertyAlias: "__document__",
|
|
855
|
+
message: "Could not refetch document to run validation."
|
|
856
|
+
}
|
|
857
|
+
]
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
target = docResult.data;
|
|
861
|
+
}
|
|
862
|
+
const values = (target.values ?? []).map((v) => ({
|
|
863
|
+
alias: v.alias,
|
|
864
|
+
value: v.value,
|
|
865
|
+
culture: v.culture ?? null,
|
|
866
|
+
segment: v.segment ?? null
|
|
867
|
+
}));
|
|
868
|
+
const variants = (target.variants ?? []).map((v) => ({
|
|
869
|
+
name: v.name,
|
|
870
|
+
culture: v.culture ?? null,
|
|
871
|
+
segment: v.segment ?? null
|
|
872
|
+
}));
|
|
873
|
+
const ancestorsResult = await chainCms("get-document-ancestors", { descendantId: id });
|
|
874
|
+
const parent = ancestorsResult.ok ? (ancestorsResult.data.items ?? []).find((item) => item.id === id)?.parent ?? null : null;
|
|
875
|
+
const result = await chainCms("validate-document", {
|
|
876
|
+
id,
|
|
877
|
+
documentType: { id: target.documentType.id },
|
|
878
|
+
template: target.template ? { id: target.template.id } : null,
|
|
879
|
+
parent,
|
|
880
|
+
values,
|
|
881
|
+
variants
|
|
882
|
+
});
|
|
883
|
+
if (result.ok) {
|
|
884
|
+
return { valid: true, errors: [] };
|
|
885
|
+
}
|
|
886
|
+
return { valid: false, errors: parseValidationErrors(result.errorResult, values) };
|
|
887
|
+
}
|
|
888
|
+
function parseValidationErrors(errorResult, requestValues) {
|
|
889
|
+
const structured = extractStructured(errorResult);
|
|
890
|
+
if (!structured) {
|
|
891
|
+
return [
|
|
892
|
+
{
|
|
893
|
+
propertyAlias: "__document__",
|
|
894
|
+
message: stringifyErrorFallback(errorResult)
|
|
895
|
+
}
|
|
896
|
+
];
|
|
897
|
+
}
|
|
898
|
+
const errors = structured.errors;
|
|
899
|
+
if (!errors || typeof errors !== "object") {
|
|
900
|
+
return [
|
|
901
|
+
{
|
|
902
|
+
propertyAlias: "__document__",
|
|
903
|
+
message: stringifyFromProblemDetails(structured)
|
|
904
|
+
}
|
|
905
|
+
];
|
|
906
|
+
}
|
|
907
|
+
const out = [];
|
|
908
|
+
for (const [jsonPath, messages] of Object.entries(errors)) {
|
|
909
|
+
const messageList = Array.isArray(messages) ? messages : [String(messages)];
|
|
910
|
+
const resolved = resolveJsonPath(jsonPath, requestValues);
|
|
911
|
+
for (const message of messageList) {
|
|
912
|
+
out.push({
|
|
913
|
+
propertyAlias: resolved.propertyAlias,
|
|
914
|
+
culture: resolved.culture,
|
|
915
|
+
segment: resolved.segment,
|
|
916
|
+
message: String(message)
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
if (out.length === 0) {
|
|
921
|
+
out.push({
|
|
922
|
+
propertyAlias: "__document__",
|
|
923
|
+
message: stringifyFromProblemDetails(structured)
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
return out;
|
|
927
|
+
}
|
|
928
|
+
var VALUES_PATH = /^\$\.values\[(\d+)\](?:\.value)?(.*)$/;
|
|
929
|
+
function resolveJsonPath(jsonPath, requestValues) {
|
|
930
|
+
const match = jsonPath.match(VALUES_PATH);
|
|
931
|
+
if (match) {
|
|
932
|
+
const index = Number(match[1]);
|
|
933
|
+
const entry = requestValues[index];
|
|
934
|
+
if (entry) {
|
|
935
|
+
const trailing = match[2]?.replace(/^\./, "");
|
|
936
|
+
return {
|
|
937
|
+
propertyAlias: trailing ? `${entry.alias}${match[2]}` : entry.alias,
|
|
938
|
+
culture: entry.culture,
|
|
939
|
+
segment: entry.segment
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
return { propertyAlias: jsonPath, culture: null, segment: null };
|
|
944
|
+
}
|
|
945
|
+
function extractStructured(errorResult) {
|
|
946
|
+
if (!errorResult || typeof errorResult !== "object") return null;
|
|
947
|
+
const r = errorResult;
|
|
948
|
+
if (r.structuredContent && typeof r.structuredContent === "object") {
|
|
949
|
+
return r.structuredContent;
|
|
950
|
+
}
|
|
951
|
+
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
952
|
+
if (text) {
|
|
953
|
+
try {
|
|
954
|
+
const parsed = JSON.parse(text);
|
|
955
|
+
if (parsed && typeof parsed === "object") {
|
|
956
|
+
return parsed;
|
|
957
|
+
}
|
|
958
|
+
} catch {
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
return null;
|
|
962
|
+
}
|
|
963
|
+
function stringifyFromProblemDetails(pd) {
|
|
964
|
+
if (pd.detail && typeof pd.detail === "string") return pd.detail;
|
|
965
|
+
if (pd.title && typeof pd.title === "string") return pd.title;
|
|
966
|
+
return "Document failed validation but no detail was returned.";
|
|
967
|
+
}
|
|
968
|
+
function stringifyErrorFallback(errorResult) {
|
|
969
|
+
if (!errorResult || typeof errorResult !== "object") return "Document failed validation.";
|
|
970
|
+
const r = errorResult;
|
|
971
|
+
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
972
|
+
return text ? text : "Document failed validation.";
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// src/umbraco-api/tools/helpers/block-builder.ts
|
|
976
|
+
async function toBlockProperties(elementTypeKey, values, culture, segment) {
|
|
977
|
+
if (values.length === 0) return { ok: true, properties: [] };
|
|
978
|
+
const docTypeResult = await chainCms("get-document-type-by-id", { id: elementTypeKey });
|
|
979
|
+
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
980
|
+
const definitions = new Map(docTypeResult.data.properties.map((p) => [p.alias, p]));
|
|
981
|
+
return {
|
|
982
|
+
ok: true,
|
|
983
|
+
properties: values.map((v) => {
|
|
984
|
+
const def = definitions.get(v.alias);
|
|
985
|
+
return {
|
|
986
|
+
alias: v.alias,
|
|
987
|
+
value: v.value,
|
|
988
|
+
culture: def?.variesByCulture ? culture : null,
|
|
989
|
+
segment: def?.variesBySegment ? segment : null
|
|
990
|
+
};
|
|
991
|
+
})
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
async function toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, culture, segment) {
|
|
995
|
+
const content = await toBlockProperties(contentTypeKey, values, culture, segment);
|
|
996
|
+
if (!content.ok) return content;
|
|
997
|
+
if (!settingsTypeKey || !settingsValues) return { ok: true, properties: content.properties };
|
|
998
|
+
const settings = await toBlockProperties(settingsTypeKey, settingsValues, culture, segment);
|
|
999
|
+
if (!settings.ok) return settings;
|
|
1000
|
+
return { ok: true, properties: content.properties, settings: { properties: settings.properties } };
|
|
1001
|
+
}
|
|
1002
|
+
function toPlacement(position) {
|
|
1003
|
+
return position.mode === "before" || position.mode === "after" ? { position: position.mode, contentKey: position.anchorContentKey } : { position: position.mode };
|
|
1004
|
+
}
|
|
1005
|
+
async function buildBlockWriteResult(id, pageName, contentKey, baseMessage) {
|
|
1006
|
+
const validation = await validateDocumentState(id);
|
|
1007
|
+
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1008
|
+
return createToolResult({
|
|
1009
|
+
message,
|
|
1010
|
+
id,
|
|
1011
|
+
name: pageName,
|
|
1012
|
+
contentKey,
|
|
1013
|
+
previewUrl: await fetchPreviewUrl(id),
|
|
1014
|
+
validation
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
function isBlockListOrGridValue(value) {
|
|
1018
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
1019
|
+
}
|
|
1020
|
+
function isRteWithBlocks(value) {
|
|
1021
|
+
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);
|
|
1022
|
+
}
|
|
1023
|
+
function findSettingsKey(container, contentKey) {
|
|
1024
|
+
const layout = container?.layout;
|
|
1025
|
+
if (!layout || typeof layout !== "object") return void 0;
|
|
1026
|
+
return searchLayout(Object.values(layout), contentKey);
|
|
1027
|
+
}
|
|
1028
|
+
function searchLayout(entries, contentKey) {
|
|
1029
|
+
for (const entry of entries) {
|
|
1030
|
+
if (Array.isArray(entry)) {
|
|
1031
|
+
const found = searchLayout(entry, contentKey);
|
|
1032
|
+
if (found) return found;
|
|
1033
|
+
continue;
|
|
1034
|
+
}
|
|
1035
|
+
if (!entry || typeof entry !== "object") continue;
|
|
1036
|
+
const candidate = entry;
|
|
1037
|
+
if (candidate.contentKey === contentKey) {
|
|
1038
|
+
return typeof candidate.settingsKey === "string" && candidate.settingsKey.length > 0 ? candidate.settingsKey : void 0;
|
|
1039
|
+
}
|
|
1040
|
+
for (const nested of [candidate.areas, candidate.items]) {
|
|
1041
|
+
if (Array.isArray(nested)) {
|
|
1042
|
+
const found = searchLayout(nested, contentKey);
|
|
1043
|
+
if (found) return found;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return void 0;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
// src/umbraco-api/tools/content/get/inspect-blocks.ts
|
|
724
1051
|
var inputSchema6 = {
|
|
725
1052
|
id: z.string().uuid().describe("The ID of the page to inspect"),
|
|
726
1053
|
propertyAlias: z.string().optional().describe("Specific property alias to inspect. If omitted, all block-based properties are shown.")
|
|
@@ -735,6 +1062,7 @@ var outputSchema6 = z.object({
|
|
|
735
1062
|
blocks: z.array(z.object({
|
|
736
1063
|
contentKey: z.string().describe("The block's unique key \u2014 use this with edit-block"),
|
|
737
1064
|
contentTypeKey: z.string().describe("The block's element type ID"),
|
|
1065
|
+
settingsKey: z.string().optional().describe("The key of the block's settings entry. Absent when the block has no settings."),
|
|
738
1066
|
properties: z.array(z.object({
|
|
739
1067
|
alias: z.string(),
|
|
740
1068
|
value: z.any()
|
|
@@ -742,18 +1070,23 @@ var outputSchema6 = z.object({
|
|
|
742
1070
|
}))
|
|
743
1071
|
}))
|
|
744
1072
|
});
|
|
745
|
-
function
|
|
1073
|
+
function isBlockListOrGridValue2(value) {
|
|
746
1074
|
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
747
1075
|
}
|
|
748
|
-
function
|
|
1076
|
+
function isRteWithBlocks2(value) {
|
|
749
1077
|
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);
|
|
750
1078
|
}
|
|
751
|
-
function extractBlocks(contentData) {
|
|
752
|
-
return contentData.map((block) =>
|
|
753
|
-
contentKey
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
1079
|
+
function extractBlocks(contentData, container) {
|
|
1080
|
+
return contentData.map((block) => {
|
|
1081
|
+
const contentKey = block.key ?? "";
|
|
1082
|
+
const settingsKey = findSettingsKey(container, contentKey);
|
|
1083
|
+
return {
|
|
1084
|
+
contentKey,
|
|
1085
|
+
contentTypeKey: block.contentTypeKey ?? "",
|
|
1086
|
+
...settingsKey ? { settingsKey } : {},
|
|
1087
|
+
properties: Array.isArray(block.values) ? block.values.map((v) => ({ alias: v.alias ?? "", value: v.value })) : []
|
|
1088
|
+
};
|
|
1089
|
+
});
|
|
757
1090
|
}
|
|
758
1091
|
var tool6 = {
|
|
759
1092
|
name: "inspect-blocks",
|
|
@@ -768,19 +1101,19 @@ var tool6 = {
|
|
|
768
1101
|
const doc = result.data;
|
|
769
1102
|
const allValues = doc.values ?? [];
|
|
770
1103
|
const filtered = propertyAlias ? allValues.filter((v) => v.alias === propertyAlias) : allValues;
|
|
771
|
-
const blockProperties = filtered.filter((v) =>
|
|
1104
|
+
const blockProperties = filtered.filter((v) => isBlockListOrGridValue2(v.value) || isRteWithBlocks2(v.value)).map((v) => {
|
|
772
1105
|
const value = v.value;
|
|
773
|
-
if (
|
|
1106
|
+
if (isRteWithBlocks2(value)) {
|
|
774
1107
|
return {
|
|
775
1108
|
propertyAlias: v.alias,
|
|
776
1109
|
editorAlias: "Umbraco.RichText",
|
|
777
|
-
blocks: extractBlocks(value.blocks.contentData)
|
|
1110
|
+
blocks: extractBlocks(value.blocks.contentData, value.blocks)
|
|
778
1111
|
};
|
|
779
1112
|
}
|
|
780
1113
|
return {
|
|
781
1114
|
propertyAlias: v.alias,
|
|
782
1115
|
editorAlias: v.editorAlias ?? void 0,
|
|
783
|
-
blocks: extractBlocks(value.contentData)
|
|
1116
|
+
blocks: extractBlocks(value.contentData, value)
|
|
784
1117
|
};
|
|
785
1118
|
});
|
|
786
1119
|
return createToolResult({
|
|
@@ -1121,150 +1454,76 @@ ${aliases.join("\n")}`
|
|
|
1121
1454
|
}
|
|
1122
1455
|
};
|
|
1123
1456
|
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
|
-
|
|
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
|
-
};
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
return { propertyAlias: jsonPath, culture: null, segment: null };
|
|
1239
|
-
}
|
|
1240
|
-
function extractStructured(errorResult) {
|
|
1241
|
-
if (!errorResult || typeof errorResult !== "object") return null;
|
|
1242
|
-
const r = errorResult;
|
|
1243
|
-
if (r.structuredContent && typeof r.structuredContent === "object") {
|
|
1244
|
-
return r.structuredContent;
|
|
1457
|
+
async function resolveEditorAliases(documentTypeId, values) {
|
|
1458
|
+
if (!values || values.length === 0) {
|
|
1459
|
+
return { ok: true, values: [] };
|
|
1460
|
+
}
|
|
1461
|
+
const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
|
|
1462
|
+
if (!docTypeResult.ok) return docTypeResult;
|
|
1463
|
+
const dataTypeIds = Array.from(
|
|
1464
|
+
new Set(
|
|
1465
|
+
docTypeResult.properties.map((p) => p.dataType?.id).filter((id) => typeof id === "string")
|
|
1466
|
+
)
|
|
1467
|
+
);
|
|
1468
|
+
const editorAliasByDataTypeId = /* @__PURE__ */ new Map();
|
|
1469
|
+
if (dataTypeIds.length > 0) {
|
|
1470
|
+
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1471
|
+
if (!dataTypesResult.ok) return dataTypesResult;
|
|
1472
|
+
for (const dt of dataTypesResult.data.items) {
|
|
1473
|
+
if (dt.id && dt.editorAlias) editorAliasByDataTypeId.set(dt.id, dt.editorAlias);
|
|
1474
|
+
}
|
|
1245
1475
|
}
|
|
1246
|
-
const
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1476
|
+
const propertyAliases = new Set(
|
|
1477
|
+
docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
|
|
1478
|
+
);
|
|
1479
|
+
const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
|
|
1480
|
+
for (const prop of docTypeResult.properties) {
|
|
1481
|
+
const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
|
|
1482
|
+
if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
|
|
1483
|
+
}
|
|
1484
|
+
const notAProperty = /* @__PURE__ */ new Set();
|
|
1485
|
+
const missingEditorAlias = /* @__PURE__ */ new Set();
|
|
1486
|
+
const resolved = values.map((v) => {
|
|
1487
|
+
const editorAlias = editorAliasByPropertyAlias.get(v.alias);
|
|
1488
|
+
if (!editorAlias) {
|
|
1489
|
+
if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
|
|
1490
|
+
else notAProperty.add(v.alias);
|
|
1491
|
+
}
|
|
1492
|
+
return {
|
|
1493
|
+
alias: v.alias,
|
|
1494
|
+
value: v.value,
|
|
1495
|
+
culture: v.culture ?? null,
|
|
1496
|
+
segment: v.segment ?? null,
|
|
1497
|
+
editorAlias: editorAlias ?? ""
|
|
1498
|
+
};
|
|
1499
|
+
});
|
|
1500
|
+
if (notAProperty.size > 0 || missingEditorAlias.size > 0) {
|
|
1501
|
+
const messages = [];
|
|
1502
|
+
if (notAProperty.size > 0) {
|
|
1503
|
+
if (docTypeResult.failedCompositionIds.length > 0) {
|
|
1504
|
+
const failures = docTypeResult.failedCompositionIds.map((id, i) => `${id} (${docTypeResult.failedCompositionDetails[i]})`).join(", ");
|
|
1505
|
+
messages.push(
|
|
1506
|
+
`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`
|
|
1507
|
+
);
|
|
1508
|
+
} else {
|
|
1509
|
+
messages.push(
|
|
1510
|
+
`not a property on this document type, own or inherited via composition: ${Array.from(notAProperty).join(", ")}`
|
|
1511
|
+
);
|
|
1252
1512
|
}
|
|
1253
|
-
} catch {
|
|
1254
1513
|
}
|
|
1514
|
+
if (missingEditorAlias.size > 0) {
|
|
1515
|
+
messages.push(
|
|
1516
|
+
`a property on this document type, but its data type has no resolvable editor alias: ${Array.from(missingEditorAlias).join(", ")}`
|
|
1517
|
+
);
|
|
1518
|
+
}
|
|
1519
|
+
return {
|
|
1520
|
+
ok: false,
|
|
1521
|
+
errorResult: createToolResultError(
|
|
1522
|
+
`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.`
|
|
1523
|
+
)
|
|
1524
|
+
};
|
|
1255
1525
|
}
|
|
1256
|
-
return
|
|
1257
|
-
}
|
|
1258
|
-
function stringifyFromProblemDetails(pd) {
|
|
1259
|
-
if (pd.detail && typeof pd.detail === "string") return pd.detail;
|
|
1260
|
-
if (pd.title && typeof pd.title === "string") return pd.title;
|
|
1261
|
-
return "Document failed validation but no detail was returned.";
|
|
1262
|
-
}
|
|
1263
|
-
function stringifyErrorFallback(errorResult) {
|
|
1264
|
-
if (!errorResult || typeof errorResult !== "object") return "Document failed validation.";
|
|
1265
|
-
const r = errorResult;
|
|
1266
|
-
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
1267
|
-
return text ? text : "Document failed validation.";
|
|
1526
|
+
return { ok: true, values: resolved };
|
|
1268
1527
|
}
|
|
1269
1528
|
|
|
1270
1529
|
// src/umbraco-api/tools/content/post/create-page.ts
|
|
@@ -1294,31 +1553,12 @@ var tool11 = {
|
|
|
1294
1553
|
slices: ["create"],
|
|
1295
1554
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
1296
1555
|
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
|
-
}
|
|
1556
|
+
const resolved = await resolveEditorAliases(documentTypeId, values);
|
|
1557
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
1312
1558
|
const createResult = await chainCms("create-document", {
|
|
1313
1559
|
documentTypeId,
|
|
1314
1560
|
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
|
-
})),
|
|
1561
|
+
values: resolved.values,
|
|
1322
1562
|
...parentId ? { parentId } : {}
|
|
1323
1563
|
});
|
|
1324
1564
|
if (!createResult.ok) return createResult.errorResult;
|
|
@@ -1355,41 +1595,50 @@ var outputSchema12 = z.object({
|
|
|
1355
1595
|
});
|
|
1356
1596
|
var tool12 = {
|
|
1357
1597
|
name: "create-and-publish-page",
|
|
1358
|
-
description: "Create a new content page and publish it
|
|
1598
|
+
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
1599
|
inputSchema: inputSchema12,
|
|
1360
1600
|
outputSchema: outputSchema12,
|
|
1361
1601
|
slices: ["create", "publish"],
|
|
1362
1602
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
1363
1603
|
handler: async ({ name, documentTypeId, parentId, values }) => {
|
|
1364
|
-
const
|
|
1365
|
-
if (
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
);
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1604
|
+
const resolved = await resolveEditorAliases(documentTypeId, values);
|
|
1605
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
1606
|
+
if (await isCmsToolAvailable("create-and-publish-document")) {
|
|
1607
|
+
const createResult = await chainCms("create-and-publish-document", {
|
|
1608
|
+
documentTypeId,
|
|
1609
|
+
name,
|
|
1610
|
+
values: resolved.values,
|
|
1611
|
+
...parentId ? { parentId } : {}
|
|
1612
|
+
});
|
|
1613
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1614
|
+
const createdId2 = createResult.data.id;
|
|
1615
|
+
return createToolResult({
|
|
1616
|
+
message: `Created and published "${name}"`,
|
|
1617
|
+
id: createdId2,
|
|
1618
|
+
name,
|
|
1619
|
+
publishedUrls: createdId2 ? await fetchPublishedUrls(createdId2) : []
|
|
1620
|
+
});
|
|
1378
1621
|
}
|
|
1379
|
-
const
|
|
1622
|
+
const createDocumentResult = await chainCms("create-document", {
|
|
1380
1623
|
documentTypeId,
|
|
1381
1624
|
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
|
-
})),
|
|
1625
|
+
values: resolved.values,
|
|
1389
1626
|
...parentId ? { parentId } : {}
|
|
1390
1627
|
});
|
|
1391
|
-
if (!
|
|
1392
|
-
const createdId =
|
|
1628
|
+
if (!createDocumentResult.ok) return createDocumentResult.errorResult;
|
|
1629
|
+
const createdId = createDocumentResult.data.id;
|
|
1630
|
+
const publishResult = await chainCms("publish-document", {
|
|
1631
|
+
id: createdId,
|
|
1632
|
+
data: { publishSchedules: [{ culture: null }] }
|
|
1633
|
+
});
|
|
1634
|
+
if (!publishResult.ok) {
|
|
1635
|
+
return createToolResult({
|
|
1636
|
+
message: `Created "${name}" as a draft but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
|
|
1637
|
+
id: createdId,
|
|
1638
|
+
name,
|
|
1639
|
+
publishedUrls: []
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1393
1642
|
return createToolResult({
|
|
1394
1643
|
message: `Created and published "${name}"`,
|
|
1395
1644
|
id: createdId,
|
|
@@ -1442,70 +1691,6 @@ var tool13 = {
|
|
|
1442
1691
|
}
|
|
1443
1692
|
};
|
|
1444
1693
|
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
1694
|
var positionSchema = z.object({
|
|
1510
1695
|
mode: z.enum(["append", "prepend", "before", "after"]).describe("Where to place the new block relative to existing blocks"),
|
|
1511
1696
|
anchorContentKey: z.string().uuid().optional().describe("Required for 'before' or 'after' \u2014 the contentKey of the anchor block")
|
|
@@ -1558,64 +1743,25 @@ var tool14 = {
|
|
|
1558
1743
|
const existingProp = (doc.values ?? []).find(
|
|
1559
1744
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1560
1745
|
);
|
|
1561
|
-
|
|
1562
|
-
layout: { "Umbraco.BlockList": [] },
|
|
1563
|
-
contentData: [],
|
|
1564
|
-
settingsData: [],
|
|
1565
|
-
expose: []
|
|
1566
|
-
};
|
|
1567
|
-
if (existingProp && (!isBlockListOrGridValue2(propValue) || existingProp.editorAlias !== "Umbraco.BlockList")) {
|
|
1746
|
+
if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockList")) {
|
|
1568
1747
|
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
1748
|
}
|
|
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
1749
|
const cultureValue = culture ?? null;
|
|
1581
1750
|
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
|
|
1751
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1752
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1753
|
+
const createResult = await chainCms("create-document-block", {
|
|
1754
|
+
documentId: id,
|
|
1755
|
+
propertyAlias,
|
|
1756
|
+
culture: cultureValue,
|
|
1757
|
+
segment: segmentValue,
|
|
1758
|
+
contentTypeKey,
|
|
1759
|
+
properties: blockProperties.properties,
|
|
1760
|
+
settings: blockProperties.settings,
|
|
1761
|
+
placement: toPlacement(resolvedPosition)
|
|
1618
1762
|
});
|
|
1763
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1764
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
|
|
1619
1765
|
}
|
|
1620
1766
|
};
|
|
1621
1767
|
var add_blocklist_block_default = withStandardDecorators(tool14);
|
|
@@ -1678,100 +1824,30 @@ var tool15 = {
|
|
|
1678
1824
|
const existingProp = (doc.values ?? []).find(
|
|
1679
1825
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1680
1826
|
);
|
|
1681
|
-
|
|
1682
|
-
layout: { "Umbraco.BlockGrid": [] },
|
|
1683
|
-
contentData: [],
|
|
1684
|
-
settingsData: [],
|
|
1685
|
-
expose: []
|
|
1686
|
-
};
|
|
1687
|
-
if (existingProp && (!isBlockListOrGridValue2(propValue) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
|
|
1827
|
+
if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
|
|
1688
1828
|
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
1829
|
}
|
|
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
1830
|
const cultureValue = culture ?? null;
|
|
1701
1831
|
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 });
|
|
1832
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1833
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1834
|
+
const createResult = await chainCms("create-document-block", {
|
|
1835
|
+
documentId: id,
|
|
1836
|
+
propertyAlias,
|
|
1837
|
+
culture: cultureValue,
|
|
1838
|
+
segment: segmentValue,
|
|
1839
|
+
contentTypeKey,
|
|
1840
|
+
properties: blockProperties.properties,
|
|
1841
|
+
settings: blockProperties.settings,
|
|
1842
|
+
placement: toPlacement(resolvedPosition),
|
|
1843
|
+
grid: {
|
|
1844
|
+
columnSpan: columnSpan ?? 12,
|
|
1845
|
+
rowSpan: rowSpan ?? 1,
|
|
1846
|
+
...areaKey && parentContentKey ? { areaKey, parentContentKey } : {}
|
|
1744
1847
|
}
|
|
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
1848
|
});
|
|
1849
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1850
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
|
|
1775
1851
|
}
|
|
1776
1852
|
};
|
|
1777
1853
|
var add_blockgrid_block_default = withStandardDecorators(tool15);
|
|
@@ -1802,26 +1878,6 @@ var outputSchema16 = z.object({
|
|
|
1802
1878
|
previewUrl: previewUrlSchema,
|
|
1803
1879
|
validation: validationResultSchema
|
|
1804
1880
|
});
|
|
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
1881
|
var tool16 = {
|
|
1826
1882
|
name: "add-rte-block",
|
|
1827
1883
|
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 +1903,25 @@ var tool16 = {
|
|
|
1847
1903
|
const existingProp = (doc.values ?? []).find(
|
|
1848
1904
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1849
1905
|
);
|
|
1850
|
-
|
|
1851
|
-
markup: "",
|
|
1852
|
-
blocks: { layout: {}, contentData: [], settingsData: [], expose: [] }
|
|
1853
|
-
};
|
|
1854
|
-
if (existingProp && !isRteWithBlocks2(propValue)) {
|
|
1906
|
+
if (existingProp?.value && !isRteWithBlocks(existingProp.value)) {
|
|
1855
1907
|
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
1908
|
}
|
|
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
1909
|
const cultureValue = culture ?? null;
|
|
1868
1910
|
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
|
|
1911
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1912
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1913
|
+
const createResult = await chainCms("create-document-block", {
|
|
1914
|
+
documentId: id,
|
|
1915
|
+
propertyAlias,
|
|
1916
|
+
culture: cultureValue,
|
|
1917
|
+
segment: segmentValue,
|
|
1918
|
+
contentTypeKey,
|
|
1919
|
+
properties: blockProperties.properties,
|
|
1920
|
+
settings: blockProperties.settings,
|
|
1921
|
+
placement: toPlacement(resolvedPosition)
|
|
1914
1922
|
});
|
|
1923
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1924
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" rich text (saved, not published)`);
|
|
1915
1925
|
}
|
|
1916
1926
|
};
|
|
1917
1927
|
var add_rte_block_default = withStandardDecorators(tool16);
|
|
@@ -1966,12 +1976,84 @@ var tool17 = {
|
|
|
1966
1976
|
}
|
|
1967
1977
|
};
|
|
1968
1978
|
var edit_page_default = withStandardDecorators(tool17);
|
|
1979
|
+
var MAX_ENRICHED_BLOCKS = 50;
|
|
1980
|
+
var MAX_BLOCK_WALK_DEPTH = 20;
|
|
1981
|
+
function enrichBlockNotFoundError(errorResult, values, options = {}) {
|
|
1982
|
+
const problem = extractInnerProblemDetails(errorResult);
|
|
1983
|
+
const availableBlocks = problem.availableBlocks;
|
|
1984
|
+
if (!Array.isArray(availableBlocks)) return errorResult;
|
|
1985
|
+
const { propertyAlias, note } = options;
|
|
1986
|
+
const filtered = propertyAlias ? values.filter((v) => v.alias === propertyAlias) : values;
|
|
1987
|
+
const typeByKey = /* @__PURE__ */ new Map();
|
|
1988
|
+
for (const v of filtered) {
|
|
1989
|
+
const container = isRteWithBlocks(v.value) ? v.value.blocks : v.value;
|
|
1990
|
+
if (isBlockListOrGridValue(container)) {
|
|
1991
|
+
collectBlockEntryTypes(container, typeByKey, 0);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
const truncated = availableBlocks.length > MAX_ENRICHED_BLOCKS;
|
|
1995
|
+
const limitedBlocks = truncated ? availableBlocks.slice(0, MAX_ENRICHED_BLOCKS) : availableBlocks;
|
|
1996
|
+
const enrichedBlocks = limitedBlocks.map(
|
|
1997
|
+
(b) => b && typeof b === "object" && typeof b.key === "string" ? { ...b, contentTypeKey: typeByKey.get(b.key) ?? null } : b
|
|
1998
|
+
);
|
|
1999
|
+
return createToolResultError({
|
|
2000
|
+
...problem,
|
|
2001
|
+
availableBlocks: enrichedBlocks,
|
|
2002
|
+
...truncated ? { availableBlocksNote: `Showing ${MAX_ENRICHED_BLOCKS} of ${availableBlocks.length} available blocks \u2014 use inspect-blocks for the full list.` } : {},
|
|
2003
|
+
...note ? { note } : {}
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
2006
|
+
function collectBlockEntryTypes(container, into, depth) {
|
|
2007
|
+
if (depth > MAX_BLOCK_WALK_DEPTH) return;
|
|
2008
|
+
for (const list of [container.contentData, container.settingsData]) {
|
|
2009
|
+
if (!Array.isArray(list)) continue;
|
|
2010
|
+
for (const block of list) {
|
|
2011
|
+
if (!block || typeof block !== "object") continue;
|
|
2012
|
+
const key = block.key;
|
|
2013
|
+
const contentTypeKey = block.contentTypeKey;
|
|
2014
|
+
if (typeof key === "string" && typeof contentTypeKey === "string") into.set(key, contentTypeKey);
|
|
2015
|
+
const nestedValues = block.values;
|
|
2016
|
+
if (!Array.isArray(nestedValues)) continue;
|
|
2017
|
+
for (const nested of nestedValues) {
|
|
2018
|
+
const nestedRaw = nested?.value;
|
|
2019
|
+
const nestedContainer = isRteWithBlocks(nestedRaw) ? nestedRaw.blocks : nestedRaw;
|
|
2020
|
+
if (isBlockListOrGridValue(nestedContainer)) {
|
|
2021
|
+
collectBlockEntryTypes(nestedContainer, into, depth + 1);
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
var blockPropertyAliasSchema = z.string().regex(
|
|
2028
|
+
/^[A-Za-z_][A-Za-z0-9_]*$/,
|
|
2029
|
+
"Property alias must be a valid identifier (letters, digits, underscore; not starting with a digit)"
|
|
2030
|
+
);
|
|
2031
|
+
function classifyBlockUpdateResults(results, requestedCount, requestedAliases = [], expectedEntryCount = 1) {
|
|
2032
|
+
const list = results ?? [];
|
|
2033
|
+
const processedCount = list.reduce((sum, r) => sum + (r.updatedCount ?? 0) + (r.addedCount ?? 0), 0);
|
|
2034
|
+
const updatedEntryCount = list.filter((r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) > 0).length;
|
|
2035
|
+
const errors = list.flatMap((r) => r.errors ?? []);
|
|
2036
|
+
const warnings = list.flatMap((r) => r.warnings ?? []);
|
|
2037
|
+
const failureText = [...errors, ...warnings].join("; ");
|
|
2038
|
+
const unresolvedEntries = list.filter(
|
|
2039
|
+
(r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) === 0 && !r.errors?.length && !r.warnings?.length
|
|
2040
|
+
);
|
|
2041
|
+
const missingEntryCount = Math.max(0, expectedEntryCount - list.length);
|
|
2042
|
+
const unresolvedBlockCount = unresolvedEntries.length + missingEntryCount;
|
|
2043
|
+
const detail = [...errors, ...warnings, ...unresolvedEntries.map((r) => r.message).filter(Boolean)].join("; ") || list.map((r) => r.message).filter(Boolean).join("; ") || "no detail returned";
|
|
2044
|
+
const outcome = processedCount === 0 ? "failed" : processedCount < requestedCount ? "partial" : "clean";
|
|
2045
|
+
const failedFields = requestedAliases.filter((alias) => failureText.includes(`'${alias}'`));
|
|
2046
|
+
const savedFields = unresolvedBlockCount > 0 ? [] : requestedAliases.filter((alias) => !failedFields.includes(alias));
|
|
2047
|
+
return { outcome, processedCount, updatedEntryCount, detail, warnings, savedFields, failedFields, unresolvedBlockCount };
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
// src/umbraco-api/tools/content/put/edit-block.ts
|
|
1969
2051
|
var inputSchema18 = {
|
|
1970
2052
|
id: z.string().uuid().describe("The ID of the page containing the block"),
|
|
1971
2053
|
propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'mainContent'). Use inspect-blocks to find this."),
|
|
1972
2054
|
contentKey: z.string().uuid().describe("The unique key of the block to edit. Use inspect-blocks to find this."),
|
|
1973
2055
|
values: z.array(z.object({
|
|
1974
|
-
alias:
|
|
2056
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
1975
2057
|
value: z.any().describe("The new value for the property")
|
|
1976
2058
|
})).describe("Properties to update within the block"),
|
|
1977
2059
|
blockType: z.enum(["content", "settings"]).optional().describe("Whether to update the block's content or its settings. Defaults to 'content'."),
|
|
@@ -1985,7 +2067,8 @@ var outputSchema18 = z.object({
|
|
|
1985
2067
|
contentKey: z.string(),
|
|
1986
2068
|
updatedFields: z.array(z.string()),
|
|
1987
2069
|
previewUrl: previewUrlSchema,
|
|
1988
|
-
validation: validationResultSchema
|
|
2070
|
+
validation: validationResultSchema,
|
|
2071
|
+
warnings: z.array(z.string()).optional()
|
|
1989
2072
|
});
|
|
1990
2073
|
var tool18 = {
|
|
1991
2074
|
name: "edit-block",
|
|
@@ -2000,6 +2083,20 @@ var tool18 = {
|
|
|
2000
2083
|
const pageName = docResult.data.variants?.[0]?.name ?? "Unknown";
|
|
2001
2084
|
const fieldNames = values.map((v) => v.alias);
|
|
2002
2085
|
const resolvedBlockType = blockType ?? "content";
|
|
2086
|
+
let targetKey = contentKey;
|
|
2087
|
+
if (resolvedBlockType === "settings") {
|
|
2088
|
+
const rawValue = (docResult.data.values ?? []).find(
|
|
2089
|
+
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
2090
|
+
)?.value;
|
|
2091
|
+
const container = isRteWithBlocks(rawValue) ? rawValue.blocks : rawValue;
|
|
2092
|
+
const settingsKey = findSettingsKey(container, contentKey);
|
|
2093
|
+
if (!settingsKey) {
|
|
2094
|
+
return createToolResultError(
|
|
2095
|
+
`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.`
|
|
2096
|
+
);
|
|
2097
|
+
}
|
|
2098
|
+
targetKey = settingsKey;
|
|
2099
|
+
}
|
|
2003
2100
|
const propsTuple = values.map((v) => ({ alias: v.alias, value: v.value }));
|
|
2004
2101
|
const updateResult = await chainCms("update-block-property", {
|
|
2005
2102
|
documentId: id,
|
|
@@ -2007,12 +2104,41 @@ var tool18 = {
|
|
|
2007
2104
|
culture: culture ?? null,
|
|
2008
2105
|
segment: segment ?? null,
|
|
2009
2106
|
updates: [{
|
|
2010
|
-
contentKey,
|
|
2107
|
+
contentKey: targetKey,
|
|
2011
2108
|
blockType: resolvedBlockType,
|
|
2012
2109
|
properties: propsTuple
|
|
2013
2110
|
}]
|
|
2014
2111
|
});
|
|
2015
|
-
if (!updateResult.ok)
|
|
2112
|
+
if (!updateResult.ok) {
|
|
2113
|
+
return enrichBlockNotFoundError(updateResult.errorResult, docResult.data.values ?? [], {
|
|
2114
|
+
propertyAlias,
|
|
2115
|
+
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.`
|
|
2116
|
+
});
|
|
2117
|
+
}
|
|
2118
|
+
const results = updateResult.data.results;
|
|
2119
|
+
if (!results || results.length === 0) {
|
|
2120
|
+
return createToolResultError(
|
|
2121
|
+
"update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
2122
|
+
);
|
|
2123
|
+
}
|
|
2124
|
+
const classification = classifyBlockUpdateResults(results, fieldNames.length, fieldNames, 1);
|
|
2125
|
+
if (classification.outcome === "failed") {
|
|
2126
|
+
return createToolResultError(
|
|
2127
|
+
`Block update failed: ${classification.detail || updateResult.data.message || "no detail returned"}`
|
|
2128
|
+
);
|
|
2129
|
+
}
|
|
2130
|
+
if (classification.outcome === "partial") {
|
|
2131
|
+
return createToolResultError({
|
|
2132
|
+
message: `Block update partially failed: ${classification.processedCount} of ${fieldNames.length} field(s) saved \u2014 ${classification.detail}`,
|
|
2133
|
+
savedFields: classification.savedFields,
|
|
2134
|
+
failedFields: classification.failedFields,
|
|
2135
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {},
|
|
2136
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {},
|
|
2137
|
+
validation: await validateDocumentState(id),
|
|
2138
|
+
previewUrl: await fetchPreviewUrl(id)
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
const warnings = classification.warnings;
|
|
2016
2142
|
const validation = await validateDocumentState(id);
|
|
2017
2143
|
const target = resolvedBlockType === "settings" ? "settings" : "content";
|
|
2018
2144
|
const baseMessage = `Updated ${fieldNames.length} field(s) in block ${target} on "${pageName}" (saved, not published)`;
|
|
@@ -2024,7 +2150,8 @@ var tool18 = {
|
|
|
2024
2150
|
contentKey,
|
|
2025
2151
|
updatedFields: fieldNames,
|
|
2026
2152
|
previewUrl: await fetchPreviewUrl(id),
|
|
2027
|
-
validation
|
|
2153
|
+
validation,
|
|
2154
|
+
...warnings.length ? { warnings } : {}
|
|
2028
2155
|
});
|
|
2029
2156
|
}
|
|
2030
2157
|
};
|
|
@@ -2077,10 +2204,9 @@ var tool19 = {
|
|
|
2077
2204
|
});
|
|
2078
2205
|
}
|
|
2079
2206
|
const cultureLabel = targetCulture ? ` (${targetCulture})` : "";
|
|
2080
|
-
const confirmed = await
|
|
2207
|
+
const confirmed = await requestApproval(
|
|
2081
2208
|
extra,
|
|
2082
|
-
`Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish
|
|
2083
|
-
{ title: "Confirm rename" }
|
|
2209
|
+
`Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish.`
|
|
2084
2210
|
);
|
|
2085
2211
|
if (!confirmed) {
|
|
2086
2212
|
return createToolResult({
|
|
@@ -2367,68 +2493,26 @@ var outputSchema24 = z.object({
|
|
|
2367
2493
|
previewUrl: previewUrlSchema,
|
|
2368
2494
|
validation: validationResultSchema
|
|
2369
2495
|
});
|
|
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 };
|
|
2496
|
+
function gridContainsBlock(items, contentKey) {
|
|
2497
|
+
return items.some(
|
|
2498
|
+
(item) => item.contentKey === contentKey || (item.areas ?? []).some((area) => gridContainsBlock(area.items ?? [], contentKey))
|
|
2499
|
+
);
|
|
2390
2500
|
}
|
|
2391
|
-
function
|
|
2501
|
+
function locateBlock(propValue, editorAlias, propertyAlias, contentKey, pageName) {
|
|
2392
2502
|
const notFound = { ok: false, errorText: `Block '${contentKey}' was not found in property '${propertyAlias}'.` };
|
|
2393
2503
|
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
|
-
};
|
|
2504
|
+
if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockList") {
|
|
2505
|
+
const layoutList = propValue.layout?.["Umbraco.BlockList"] ?? [];
|
|
2506
|
+
if (!layoutList.some((e) => e.contentKey === contentKey)) return notFound;
|
|
2507
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockList ${propertyAlias})? ${draftSuffix}` };
|
|
2404
2508
|
}
|
|
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
|
-
};
|
|
2509
|
+
if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockGrid") {
|
|
2510
|
+
if (!gridContainsBlock(propValue.layout?.["Umbraco.BlockGrid"] ?? [], contentKey)) return notFound;
|
|
2511
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockGrid ${propertyAlias})? ${draftSuffix}` };
|
|
2414
2512
|
}
|
|
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
|
-
};
|
|
2513
|
+
if (isRteWithBlocks(propValue)) {
|
|
2514
|
+
if (!(propValue.blocks.contentData ?? []).some((e) => e.key === contentKey)) return notFound;
|
|
2515
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from a Rich Text in "${pageName}" (${propertyAlias})? ${draftSuffix}` };
|
|
2432
2516
|
}
|
|
2433
2517
|
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
2518
|
}
|
|
@@ -2453,29 +2537,22 @@ var tool24 = {
|
|
|
2453
2537
|
isError: true
|
|
2454
2538
|
});
|
|
2455
2539
|
}
|
|
2456
|
-
const
|
|
2457
|
-
if (!
|
|
2458
|
-
return createToolResultError({ content: [{ type: "text", text:
|
|
2540
|
+
const location = locateBlock(prop.value, prop.editorAlias, propertyAlias, contentKey, pageName);
|
|
2541
|
+
if (!location.ok) {
|
|
2542
|
+
return createToolResultError({ content: [{ type: "text", text: location.errorText }], isError: true });
|
|
2459
2543
|
}
|
|
2460
|
-
if (!await requestApproval(extra,
|
|
2544
|
+
if (!await requestApproval(extra, location.confirmMessage)) {
|
|
2461
2545
|
return createToolResultError({ content: [{ type: "text", text: "Cancelled by user." }], isError: true });
|
|
2462
2546
|
}
|
|
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
|
|
2547
|
+
const deleteResult = await chainCms("delete-document-block", {
|
|
2548
|
+
documentId: id,
|
|
2549
|
+
propertyAlias,
|
|
2550
|
+
culture: culture ?? null,
|
|
2551
|
+
segment: segment ?? null,
|
|
2552
|
+
contentKey
|
|
2478
2553
|
});
|
|
2554
|
+
if (!deleteResult.ok) return deleteResult.errorResult;
|
|
2555
|
+
return buildBlockWriteResult(id, pageName, contentKey, `Removed block from "${pageName}" (saved, not published)`);
|
|
2479
2556
|
}
|
|
2480
2557
|
};
|
|
2481
2558
|
var delete_block_default = withStandardDecorators(tool24);
|
|
@@ -2632,7 +2709,7 @@ function mergeValues(existing, updates) {
|
|
|
2632
2709
|
}
|
|
2633
2710
|
var tool27 = {
|
|
2634
2711
|
name: "save-and-publish",
|
|
2635
|
-
description: "Save property changes and publish a content page
|
|
2712
|
+
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
2713
|
inputSchema: inputSchema27,
|
|
2637
2714
|
outputSchema: outputSchema27,
|
|
2638
2715
|
slices: ["publish", "update"],
|
|
@@ -2692,20 +2769,53 @@ var tool27 = {
|
|
|
2692
2769
|
}
|
|
2693
2770
|
} else {
|
|
2694
2771
|
const mergedValues = mergeValues(doc.values ?? [], values ?? []);
|
|
2695
|
-
const
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2772
|
+
const variants = (doc.variants ?? []).map((v) => ({
|
|
2773
|
+
culture: v.culture ?? null,
|
|
2774
|
+
segment: v.segment ?? null,
|
|
2775
|
+
name: v.name
|
|
2776
|
+
}));
|
|
2777
|
+
if (await isCmsToolAvailable("update-and-publish-document")) {
|
|
2778
|
+
const updateAndPublishResult = await chainCms("update-and-publish-document", {
|
|
2779
|
+
id,
|
|
2780
|
+
data: {
|
|
2781
|
+
values: mergedValues,
|
|
2782
|
+
variants,
|
|
2783
|
+
template: doc.template ?? null,
|
|
2784
|
+
culturesToPublish: variantCultures.filter((c) => c !== null)
|
|
2785
|
+
}
|
|
2786
|
+
});
|
|
2787
|
+
if (!updateAndPublishResult.ok) return updateAndPublishResult.errorResult;
|
|
2788
|
+
} else {
|
|
2789
|
+
const updateResult = await chainCms("update-document", {
|
|
2790
|
+
id,
|
|
2791
|
+
data: {
|
|
2792
|
+
values: mergedValues,
|
|
2793
|
+
variants,
|
|
2794
|
+
template: doc.template ?? null
|
|
2795
|
+
}
|
|
2796
|
+
});
|
|
2797
|
+
if (!updateResult.ok) return updateResult.errorResult;
|
|
2798
|
+
const publishResult = await chainCms("publish-document", {
|
|
2799
|
+
id,
|
|
2800
|
+
data: {
|
|
2801
|
+
publishSchedules: variantCultures.map((c) => ({ culture: c }))
|
|
2802
|
+
}
|
|
2803
|
+
});
|
|
2804
|
+
if (!publishResult.ok) {
|
|
2805
|
+
if (saved) {
|
|
2806
|
+
return createToolResult({
|
|
2807
|
+
message: `Saved ${fieldNames.length} field(s) on "${pageName}" but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
|
|
2808
|
+
id,
|
|
2809
|
+
name: pageName,
|
|
2810
|
+
saved: true,
|
|
2811
|
+
published: false,
|
|
2812
|
+
updatedFields: fieldNames,
|
|
2813
|
+
publishedUrls: []
|
|
2814
|
+
});
|
|
2815
|
+
}
|
|
2816
|
+
return publishResult.errorResult;
|
|
2706
2817
|
}
|
|
2707
|
-
}
|
|
2708
|
-
if (!updateAndPublishResult.ok) return updateAndPublishResult.errorResult;
|
|
2818
|
+
}
|
|
2709
2819
|
}
|
|
2710
2820
|
if (!includeDescendants) {
|
|
2711
2821
|
const verifyError = await verifyDocumentPublished(id, variantCultures);
|
|
@@ -3557,12 +3667,7 @@ function validateBulkIds(ids) {
|
|
|
3557
3667
|
function parseBulkError(err) {
|
|
3558
3668
|
if (err === null || err === void 0) return "Unknown error";
|
|
3559
3669
|
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;
|
|
3670
|
+
return extractInnerProblemDetails(err);
|
|
3566
3671
|
}
|
|
3567
3672
|
if (typeof err === "string") {
|
|
3568
3673
|
try {
|
|
@@ -3831,6 +3936,15 @@ var tool46 = {
|
|
|
3831
3936
|
slices: ["list"],
|
|
3832
3937
|
annotations: { readOnlyHint: true },
|
|
3833
3938
|
handler: async ({ parentId, take, skip }) => {
|
|
3939
|
+
const accessCheck = await checkSettingsAccess();
|
|
3940
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
3941
|
+
if (!accessCheck.hasAccess) {
|
|
3942
|
+
return createToolResultError({
|
|
3943
|
+
status: 403,
|
|
3944
|
+
title: "Settings access required",
|
|
3945
|
+
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."
|
|
3946
|
+
});
|
|
3947
|
+
}
|
|
3834
3948
|
const cursor = buildChainedCursor(skip, take);
|
|
3835
3949
|
const result = parentId ? await chainCms("get-document-blueprint-children", { parentId, cursor }) : await chainCms("get-document-blueprint-root", { cursor });
|
|
3836
3950
|
if (!result.ok) return result.errorResult;
|
|
@@ -5364,7 +5478,7 @@ var inputSchema73 = {
|
|
|
5364
5478
|
contentTypeKey: z.string().uuid().describe("The block element type key to target. Use inspect-blocks to find this."),
|
|
5365
5479
|
propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'contentRows'). Use inspect-blocks to find this."),
|
|
5366
5480
|
values: z.array(z.object({
|
|
5367
|
-
alias:
|
|
5481
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
5368
5482
|
value: z.any().describe("The new value for the property")
|
|
5369
5483
|
})).min(1).describe("Properties to update on every matching block"),
|
|
5370
5484
|
culture: z.string().nullable().optional().describe("Culture code if the document property is variant"),
|
|
@@ -5380,7 +5494,8 @@ var outputSchema73 = z.object({
|
|
|
5380
5494
|
previousVersionId: z.string().optional(),
|
|
5381
5495
|
error: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
|
|
5382
5496
|
previewUrl: previewUrlSchema.optional(),
|
|
5383
|
-
validation: validationResultSchema.optional()
|
|
5497
|
+
validation: validationResultSchema.optional(),
|
|
5498
|
+
warnings: z.array(z.string()).optional()
|
|
5384
5499
|
})),
|
|
5385
5500
|
successCount: z.number(),
|
|
5386
5501
|
failureCount: z.number(),
|
|
@@ -5424,6 +5539,7 @@ var tool73 = {
|
|
|
5424
5539
|
});
|
|
5425
5540
|
const items = [];
|
|
5426
5541
|
const pageBlocks = /* @__PURE__ */ new Map();
|
|
5542
|
+
const docValuesByItem = /* @__PURE__ */ new Map();
|
|
5427
5543
|
for (const id of ids) {
|
|
5428
5544
|
const docResult = await chainCms("get-document-by-id", { id });
|
|
5429
5545
|
if (!docResult.ok) continue;
|
|
@@ -5437,6 +5553,7 @@ var tool73 = {
|
|
|
5437
5553
|
const currentVersionId = versionData?.items?.[0]?.id ?? "";
|
|
5438
5554
|
items.push({ id, name, currentVersionId });
|
|
5439
5555
|
pageBlocks.set(id, findMatchingBlocks(doc, propertyAlias, contentTypeKey));
|
|
5556
|
+
docValuesByItem.set(id, doc.values ?? []);
|
|
5440
5557
|
}
|
|
5441
5558
|
if (items.length === 0) {
|
|
5442
5559
|
return createToolResult({
|
|
@@ -5509,28 +5626,68 @@ Changes will be saved but not published.`;
|
|
|
5509
5626
|
updates
|
|
5510
5627
|
});
|
|
5511
5628
|
if (!updateResult.ok) {
|
|
5629
|
+
const enriched = enrichBlockNotFoundError(
|
|
5630
|
+
updateResult.errorResult,
|
|
5631
|
+
docValuesByItem.get(item.id) ?? [],
|
|
5632
|
+
{ propertyAlias }
|
|
5633
|
+
);
|
|
5512
5634
|
results.push({
|
|
5513
5635
|
id: item.id,
|
|
5514
5636
|
name: item.name,
|
|
5515
5637
|
success: false,
|
|
5516
5638
|
blocksUpdated: 0,
|
|
5517
5639
|
previousVersionId: item.currentVersionId || void 0,
|
|
5518
|
-
error: parseBulkError(
|
|
5640
|
+
error: parseBulkError(enriched)
|
|
5519
5641
|
});
|
|
5520
5642
|
stopped = true;
|
|
5521
5643
|
} else {
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5644
|
+
const blockResults = updateResult.data.results;
|
|
5645
|
+
if (!blockResults || blockResults.length === 0) {
|
|
5646
|
+
results.push({
|
|
5647
|
+
id: item.id,
|
|
5648
|
+
name: item.name,
|
|
5649
|
+
success: false,
|
|
5650
|
+
blocksUpdated: 0,
|
|
5651
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5652
|
+
error: "update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
5653
|
+
});
|
|
5654
|
+
stopped = true;
|
|
5655
|
+
} else {
|
|
5656
|
+
const classification = classifyBlockUpdateResults(blockResults, blocks.length * values.length, fieldNames, blocks.length);
|
|
5657
|
+
if (classification.outcome === "clean") {
|
|
5658
|
+
totalBlocksUpdated += blocks.length;
|
|
5659
|
+
results.push({
|
|
5660
|
+
id: item.id,
|
|
5661
|
+
name: item.name,
|
|
5662
|
+
success: true,
|
|
5663
|
+
blocksUpdated: blocks.length,
|
|
5664
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5665
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
5666
|
+
});
|
|
5667
|
+
} else {
|
|
5668
|
+
totalBlocksUpdated += classification.updatedEntryCount;
|
|
5669
|
+
const totalProperties = blocks.length * values.length;
|
|
5670
|
+
results.push({
|
|
5671
|
+
id: item.id,
|
|
5672
|
+
name: item.name,
|
|
5673
|
+
success: false,
|
|
5674
|
+
blocksUpdated: classification.updatedEntryCount,
|
|
5675
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5676
|
+
error: classification.outcome === "failed" ? `Block update failed: ${classification.detail}` : {
|
|
5677
|
+
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}`,
|
|
5678
|
+
savedFields: classification.savedFields,
|
|
5679
|
+
failedFields: classification.failedFields,
|
|
5680
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {}
|
|
5681
|
+
},
|
|
5682
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
5683
|
+
});
|
|
5684
|
+
stopped = true;
|
|
5685
|
+
}
|
|
5686
|
+
}
|
|
5530
5687
|
}
|
|
5531
5688
|
}
|
|
5532
5689
|
for (const row of results) {
|
|
5533
|
-
if (
|
|
5690
|
+
if (row.blocksUpdated === 0) continue;
|
|
5534
5691
|
row.validation = await validateDocumentState(row.id);
|
|
5535
5692
|
row.previewUrl = await fetchPreviewUrl(row.id);
|
|
5536
5693
|
}
|
|
@@ -5615,12 +5772,10 @@ var tool74 = {
|
|
|
5615
5772
|
var search_members_default = withStandardDecorators(tool74);
|
|
5616
5773
|
|
|
5617
5774
|
// src/umbraco-api/tools/member/sensitive-data-access.ts
|
|
5618
|
-
|
|
5619
|
-
async function hasSensitiveDataAccess() {
|
|
5620
|
-
if (cachedAccess !== void 0) return cachedAccess;
|
|
5775
|
+
async function checkSensitiveDataAccess() {
|
|
5621
5776
|
const result = await chainCms("get-user-current", {});
|
|
5622
|
-
|
|
5623
|
-
return
|
|
5777
|
+
if (!result.ok) return result;
|
|
5778
|
+
return { ok: true, hasAccess: result.data.hasAccessToSensitiveData ?? false };
|
|
5624
5779
|
}
|
|
5625
5780
|
|
|
5626
5781
|
// src/umbraco-api/tools/member/get/get-member.ts
|
|
@@ -5658,7 +5813,8 @@ var tool75 = {
|
|
|
5658
5813
|
const result = await chainCms("get-member", { id });
|
|
5659
5814
|
if (!result.ok) return result.errorResult;
|
|
5660
5815
|
const data = result.data;
|
|
5661
|
-
const
|
|
5816
|
+
const accessCheck = await checkSensitiveDataAccess();
|
|
5817
|
+
const accessible = accessCheck.ok && accessCheck.hasAccess;
|
|
5662
5818
|
return createToolResult({
|
|
5663
5819
|
id: data.id ?? id,
|
|
5664
5820
|
name: data.variants?.[0]?.name ?? "Unknown",
|
|
@@ -5817,12 +5973,16 @@ var tool78 = {
|
|
|
5817
5973
|
slices: ["update"],
|
|
5818
5974
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
5819
5975
|
handler: async ({ id, name, email, username, newPassword, isTwoFactorEnabled, isApproved, isLockedOut, groups, values }, extra) => {
|
|
5820
|
-
if (
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5976
|
+
if (isApproved !== void 0 || isLockedOut !== void 0 || isTwoFactorEnabled !== void 0) {
|
|
5977
|
+
const accessCheck = await checkSensitiveDataAccess();
|
|
5978
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
5979
|
+
if (!accessCheck.hasAccess) {
|
|
5980
|
+
return createToolResultError({
|
|
5981
|
+
status: 403,
|
|
5982
|
+
title: "Sensitive Data access required",
|
|
5983
|
+
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."
|
|
5984
|
+
});
|
|
5985
|
+
}
|
|
5826
5986
|
}
|
|
5827
5987
|
const memberResult = await chainCms("get-member", { id });
|
|
5828
5988
|
if (!memberResult.ok) return memberResult.errorResult;
|
|
@@ -7611,17 +7771,16 @@ Talk like a helpful colleague, not a developer. Many editors are not very techni
|
|
|
7611
7771
|
- 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
7772
|
- 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
7773
|
|
|
7614
|
-
# Confirmations come from the tools, not from you
|
|
7774
|
+
# Confirmations come from the host and the tools, not from you
|
|
7615
7775
|
|
|
7616
|
-
|
|
7776
|
+
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
7777
|
|
|
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.
|
|
7778
|
+
- 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").
|
|
7779
|
+
- Never answer or bypass a prompt on the editor's behalf, and don't bundle actions to avoid prompts.
|
|
7780
|
+
- Only say something is done once the tool has returned success.
|
|
7781
|
+
- If the editor declines, accept it warmly and stop.
|
|
7623
7782
|
|
|
7624
|
-
Being friendly never means being loose with destructive actions.
|
|
7783
|
+
Being friendly never means being loose with destructive actions.
|
|
7625
7784
|
|
|
7626
7785
|
# Never show internal IDs or UUIDs to the editor
|
|
7627
7786
|
|