@cloudhal/mcp-server 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/src/collection-fields.d.ts +15 -5
- package/dist/src/collection-fields.js +64 -24
- package/dist/src/collection-tools.d.ts +2 -1
- package/dist/src/collection-tools.js +23 -5
- package/dist/src/entry-fields-input.d.ts +37 -0
- package/dist/src/entry-fields-input.js +163 -0
- package/dist/src/entry-fields.d.ts +21 -22
- package/dist/src/entry-fields.js +26 -155
- package/dist/src/entry-list.d.ts +11 -1
- package/dist/src/entry-list.js +24 -2
- package/dist/src/entry-tools.js +141 -77
- package/dist/src/field-hints.js +2 -0
- package/dist/src/field-prompts.d.ts +35 -0
- package/dist/src/field-prompts.js +299 -0
- package/dist/src/field-tools.d.ts +2 -1
- package/dist/src/field-tools.js +174 -90
- package/dist/src/reference-tools.d.ts +2 -0
- package/dist/src/reference-tools.js +114 -0
- package/dist/src/schedules-deps.d.ts +4 -0
- package/dist/src/schedules-deps.js +3 -0
- package/dist/src/server-schema.d.ts +2 -1
- package/dist/src/server-schema.js +9 -4
- package/dist/src/server.js +2 -1
- package/dist/src/tools.d.ts +7 -2
- package/dist/src/tools.js +9 -4
- package/dist/src/translation-fields.d.ts +35 -6
- package/dist/src/translation-fields.js +107 -11
- package/dist/src/translation-tools.js +40 -8
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ The playground and the local stdio server (`cloudhal mcp`) take none of these: a
|
|
|
31
31
|
## Tool reference
|
|
32
32
|
|
|
33
33
|
<!-- tools:start (generated by scripts/mcp-tools-doc.ts; do not edit) -->
|
|
34
|
-
**
|
|
34
|
+
**111 tools**, in the order the server lists them.
|
|
35
35
|
|
|
36
36
|
| Tool | Scopes | Kind | Approval | What it does |
|
|
37
37
|
|---|---|---|---|---|
|
|
@@ -48,8 +48,9 @@ The playground and the local stdio server (`cloudhal mcp`) take none of these: a
|
|
|
48
48
|
| `delete_page` | `content:write` | write (destructive) | by the key's mode | Delete a page and remove it from navigation. |
|
|
49
49
|
| `list_entries` | `content:read` | read | — | Content entries, newest first. |
|
|
50
50
|
| `get_entry` | `content:read` | read | — | One content entry with its body and current revision. |
|
|
51
|
+
| `list_references` | `content:read` | read | — | An entry's reference fields in either direction (RFC-0045). |
|
|
51
52
|
| `create_entry` | `content:write` | write | by the key's mode | Create a draft content entry (markdown body) in an existing collection (list_collections; a new one needs create_collection first), optionally filed under existing terms (`terms`;… |
|
|
52
|
-
| `update_entry` | `content:write` | write | by the key's mode | Update title, summary, body, slug, status (draft → review → published), terms (`terms`: add, remove or set categories and tags by id, slug or name) or typed custom fields
|
|
53
|
+
| `update_entry` | `content:write` | write | by the key's mode | Update title, summary, body, slug, status (draft → review → published), terms (`terms`: add, remove or set categories and tags by id, slug or name) or typed custom fields of an en… |
|
|
53
54
|
| `add_correction` | `content:write` | write | by the key's mode | Append a correction, clarification or update notice to an article (RFC-0019 §2) when a published story changed in substance. |
|
|
54
55
|
| `delete_entry` | `content:write` | write (destructive) | by the key's mode | Delete a content entry. |
|
|
55
56
|
| `list_translations` | `content:read` | read | — | Every language version of a page or entry (its translation group): locale, status, method (original, human, machine, machine-reviewed), whether it is stale (its source changed sin… |
|
|
@@ -5,12 +5,20 @@
|
|
|
5
5
|
* the store's guard (`field_change_needs_operation`) and go through the operation tools instead.
|
|
6
6
|
*/
|
|
7
7
|
import type { CollectionSettings, FieldDefinition, Site } from "@cloudhal/core-contracts";
|
|
8
|
+
import { type StrictCost } from "@cloudhal/core-ts/fields";
|
|
8
9
|
import { type JsonSchema } from "./common.js";
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/** Which field types a tool list offers (`defineTools`). */
|
|
11
|
+
export interface FieldTypeOptions {
|
|
12
|
+
/**
|
|
13
|
+
* The store accepts RFC-0045's `reference` and `repeater` (`SiteGraphStoreOptions.fieldTypes`
|
|
14
|
+
* is set). Absent or false: the inputs list the enabled types only, as production does until
|
|
15
|
+
* rollout step 7. The store still decides per site.
|
|
16
|
+
*/
|
|
17
|
+
referenceTypes?: boolean | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** The production input (the enabled types only), and the one a capable store's tools take. */
|
|
13
20
|
export declare const FIELD_DEFINITIONS_INPUT: JsonSchema;
|
|
21
|
+
export declare const FIELD_DEFINITIONS_INPUT_ALL: JsonSchema;
|
|
14
22
|
/**
|
|
15
23
|
* The settings with `fields` replaced by the agent's list. A running operation's marker stays on
|
|
16
24
|
* its field (agents never write it), so editing labels meanwhile is not read as touching it.
|
|
@@ -20,8 +28,10 @@ export declare function withFields(current: CollectionSettings, next: Collection
|
|
|
20
28
|
export declare function canonical(value: unknown): string;
|
|
21
29
|
/** One line for the approval prompt: which fields are added, changed, removed or reordered. */
|
|
22
30
|
export declare function describeFieldEdits(before: readonly FieldDefinition[], after: readonly FieldDefinition[], locale: string): string | undefined;
|
|
23
|
-
/** What `list_collections` adds per collection that has definitions. */
|
|
31
|
+
/** What `list_collections` adds per collection that has definitions (RFC-0041 §8, RFC-0045 §6). */
|
|
24
32
|
export declare function fieldsView(site: Site, key: string, locale: string): {
|
|
25
33
|
fields: FieldDefinition[];
|
|
26
34
|
fieldsSchema: JsonSchema;
|
|
35
|
+
fieldsSchemaStrict: JsonSchema;
|
|
36
|
+
strictCost: StrictCost;
|
|
27
37
|
} | Record<string, never>;
|
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { SiteSchema } from "@cloudhal/core-contracts";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
fieldLabel,
|
|
11
|
+
fieldsJsonSchema,
|
|
12
|
+
isReferenceFieldType,
|
|
13
|
+
|
|
14
|
+
strictSchemaCost,
|
|
15
|
+
} from "@cloudhal/core-ts/fields";
|
|
10
16
|
import { quote } from "./common.js";
|
|
11
17
|
import { defsClosure } from "./schema-transforms.js";
|
|
12
18
|
|
|
@@ -23,30 +29,46 @@ function withoutMarker(variant ) {
|
|
|
23
29
|
return { ...variant, properties };
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/** Which field types a tool list offers (`defineTools`). */
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/** The definitions `update_collection` takes: the offered variants, each without the marker. */
|
|
43
|
+
function fieldDefinition(referenceTypes ) {
|
|
44
|
+
const offered = referenceTypes
|
|
45
|
+
? VARIANTS
|
|
46
|
+
: VARIANTS.filter((v) => !isReferenceFieldType(typeOf(v)));
|
|
47
|
+
return { ...DEFS.FieldDefinition, oneOf: offered.map(withoutMarker) };
|
|
48
|
+
}
|
|
34
49
|
|
|
35
50
|
/**
|
|
36
|
-
* `update_collection`'s `fields`: the
|
|
51
|
+
* `update_collection`'s `fields`: the offered definitions, minus the operation marker, with every
|
|
37
52
|
* `$defs` entry they reach (`defsClosure`), so a contract change cannot leave a `$ref` dangling.
|
|
38
53
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
function fieldDefinitionsInput(referenceTypes ) {
|
|
55
|
+
const definition = fieldDefinition(referenceTypes);
|
|
56
|
+
return {
|
|
57
|
+
type: "array",
|
|
58
|
+
maxItems: 30,
|
|
59
|
+
description:
|
|
60
|
+
"The collection's typed custom fields, the whole list in form order ([] removes them all). Free edits only: add fields, reorder, change labels and help, add select options or change their labels, toggle multiline, searchable or requiredToPublish, change maxLength/minimum/maximum. Renaming a key, changing a type, localized or multiple, and dropping a key or option still in use need rename_field, change_field_type, set_field_localized or remove_field.",
|
|
61
|
+
items: { $ref: "#/$defs/FieldDefinition" },
|
|
62
|
+
$defs: {
|
|
63
|
+
...defsClosure(SiteSchema , definition),
|
|
64
|
+
FieldDefinition: definition,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The production input (the enabled types only), and the one a capable store's tools take. */
|
|
70
|
+
export const FIELD_DEFINITIONS_INPUT = fieldDefinitionsInput(false);
|
|
71
|
+
export const FIELD_DEFINITIONS_INPUT_ALL = fieldDefinitionsInput(true);
|
|
50
72
|
|
|
51
73
|
/**
|
|
52
74
|
* The settings with `fields` replaced by the agent's list. A running operation's marker stays on
|
|
@@ -101,16 +123,34 @@ export function describeFieldEdits(
|
|
|
101
123
|
return parts.length ? ` fields: ${parts.join("; ")}` : undefined;
|
|
102
124
|
}
|
|
103
125
|
|
|
104
|
-
/**
|
|
126
|
+
/** A collection's plural name in `locale` (then the default locale), for the fields schema. */
|
|
127
|
+
const collectionName = (site , locale ) => (key ) => {
|
|
128
|
+
const labels = site.collections?.[key]?.labels;
|
|
129
|
+
return labels?.[locale]?.plural ?? labels?.[site.defaultLocale]?.plural;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** What `list_collections` adds per collection that has definitions (RFC-0041 §8, RFC-0045 §6). */
|
|
105
133
|
export function fieldsView(
|
|
106
134
|
site ,
|
|
107
135
|
key ,
|
|
108
136
|
locale ,
|
|
109
|
-
)
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
{
|
|
110
145
|
const fields = site.collections?.[key]?.fields;
|
|
111
146
|
if (!fields?.length) return {};
|
|
147
|
+
const options = { collectionName: collectionName(site, locale) };
|
|
148
|
+
const open = fieldsJsonSchema(fields, locale, site.defaultLocale, options);
|
|
149
|
+
const strict = fieldsJsonSchema(fields, locale, site.defaultLocale, { ...options, strict: true });
|
|
112
150
|
return {
|
|
113
151
|
fields,
|
|
114
|
-
fieldsSchema:
|
|
152
|
+
fieldsSchema: open ,
|
|
153
|
+
fieldsSchemaStrict: strict ,
|
|
154
|
+
strictCost: strictSchemaCost(strict),
|
|
115
155
|
};
|
|
116
156
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { type FieldTypeOptions } from "./collection-fields.js";
|
|
1
2
|
import { type ToolContext, type ToolDefinition } from "./common.js";
|
|
2
3
|
/** Refuses a collection that is not in the site's registry (`collection_undeclared`). */
|
|
3
4
|
export declare function requireRegistered(ctx: ToolContext, siteId: string, collection: string): Promise<void>;
|
|
4
|
-
export declare function collectionTools(): ToolDefinition[];
|
|
5
|
+
export declare function collectionTools(options?: FieldTypeOptions): ToolDefinition[];
|
|
@@ -15,6 +15,8 @@ import { collectionPermalink } from "@cloudhal/core-ts/permalinks";
|
|
|
15
15
|
import {
|
|
16
16
|
describeFieldEdits,
|
|
17
17
|
FIELD_DEFINITIONS_INPUT,
|
|
18
|
+
FIELD_DEFINITIONS_INPUT_ALL,
|
|
19
|
+
|
|
18
20
|
fieldsView,
|
|
19
21
|
withFields,
|
|
20
22
|
} from "./collection-fields.js";
|
|
@@ -204,6 +206,16 @@ const COLLECTION_OUT = obj(
|
|
|
204
206
|
taxonomies: { type: "array", items: { type: "string" } },
|
|
205
207
|
fields: { type: "array", items: { type: "object" } },
|
|
206
208
|
fieldsSchema: { type: "object" },
|
|
209
|
+
fieldsSchemaStrict: { type: "object" },
|
|
210
|
+
strictCost: obj(
|
|
211
|
+
{
|
|
212
|
+
properties: { type: "integer" },
|
|
213
|
+
depth: { type: "integer" },
|
|
214
|
+
enumValues: { type: "integer" },
|
|
215
|
+
unions: { type: "integer" },
|
|
216
|
+
},
|
|
217
|
+
["properties", "depth", "enumValues", "unions"],
|
|
218
|
+
),
|
|
207
219
|
listFields: { type: "array", items: { type: "object" } },
|
|
208
220
|
structuredData: { type: "object" },
|
|
209
221
|
},
|
|
@@ -214,7 +226,7 @@ const listCollectionsTool = {
|
|
|
214
226
|
name: "list_collections",
|
|
215
227
|
title: "List collections",
|
|
216
228
|
description:
|
|
217
|
-
"The site's collections (RFC-0040): declared ones, ones that already have entries, and posts. Each with its names per locale, icon, entry counts by status, its permalink template, feed/sitemap/sort settings (defaults filled in) and the taxonomies that apply. A collection with typed custom fields (RFC-0041) also has `fields` (the definitions) and `fieldsSchema`, the JSON Schema of an entry's `fields` with labels and help in `locale` (default: the site's default locale): read it before create_entry or update_entry with fields. RFC-0042: `listFields` names the fields list_entries and contentList sections may filter (`where`) and sort (`orderBy`) by, each with its operators (`ops`) and whether it sorts; settings.expiry is the collection's date-driven expiry; `structuredData` is the JSON-LD preset's type with every path it offers (required ones, defaults, the sources and vocabulary each takes) and its warnings. Entries may only be created in these collections; call create_collection for a new one.",
|
|
229
|
+
"The site's collections (RFC-0040): declared ones, ones that already have entries, and posts. Each with its names per locale, icon, entry counts by status, its permalink template, feed/sitemap/sort settings (defaults filled in) and the taxonomies that apply. A collection with typed custom fields (RFC-0041) also has `fields` (the definitions) and `fieldsSchema`, the JSON Schema of an entry's `fields` with labels and help in `locale` (default: the site's default locale): read it before create_entry or update_entry with fields. For strict structured output (every key required, null for \"leave as it is\"), `fieldsSchemaStrict` is the same schema in that profile, written into fieldsStrict, with `strictCost` (properties, depth, enumValues, unions) to check a provider's limits; each property stands alone, so a subset of them is a valid smaller schema (RFC-0045). RFC-0042: `listFields` names the fields list_entries and contentList sections may filter (`where`) and sort (`orderBy`) by, each with its operators (`ops`) and whether it sorts; settings.expiry is the collection's date-driven expiry; `structuredData` is the JSON-LD preset's type with every path it offers (required ones, defaults, the sources and vocabulary each takes) and its warnings. Entries may only be created in these collections; call create_collection for a new one.",
|
|
218
230
|
inputSchema: obj(
|
|
219
231
|
{ siteId: id, locale: str("BCP 47 locale of field labels and help; default the site's") },
|
|
220
232
|
["siteId"],
|
|
@@ -249,7 +261,8 @@ const listCollectionsTool = {
|
|
|
249
261
|
},
|
|
250
262
|
};
|
|
251
263
|
|
|
252
|
-
function writeTool(mode ) {
|
|
264
|
+
function writeTool(mode , options = {}) {
|
|
265
|
+
const fields = options.referenceTypes ? FIELD_DEFINITIONS_INPUT_ALL : FIELD_DEFINITIONS_INPUT;
|
|
253
266
|
const name = `${mode}_collection`;
|
|
254
267
|
return {
|
|
255
268
|
name,
|
|
@@ -266,7 +279,7 @@ function writeTool(mode ) {
|
|
|
266
279
|
maxLength: 64,
|
|
267
280
|
}),
|
|
268
281
|
...SETTINGS_INPUT,
|
|
269
|
-
...(mode === "update" ? { fields
|
|
282
|
+
...(mode === "update" ? { fields, ...LISTINGS_INPUT } : {}),
|
|
270
283
|
...(mode === "create"
|
|
271
284
|
? {
|
|
272
285
|
permalink: str("Template, e.g. /etkinlik/{slug}; default /<key>/{slug}", {
|
|
@@ -325,6 +338,11 @@ function writeTool(mode ) {
|
|
|
325
338
|
};
|
|
326
339
|
}
|
|
327
340
|
|
|
328
|
-
export function collectionTools() {
|
|
329
|
-
return [
|
|
341
|
+
export function collectionTools(options = {}) {
|
|
342
|
+
return [
|
|
343
|
+
listCollectionsTool,
|
|
344
|
+
writeTool("create", options),
|
|
345
|
+
writeTool("update", options),
|
|
346
|
+
previewStructuredDataTool,
|
|
347
|
+
];
|
|
330
348
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0045 §6 for `create_entry` and `update_entry`: the three ways a call gives typed field
|
|
3
|
+
* values, read into one merge patch (`null` removes a key) before the store's checker sees it.
|
|
4
|
+
*
|
|
5
|
+
* - `fields`: the open profile, as before (on update a merge patch: `null` removes a key).
|
|
6
|
+
* - `fieldsStrict`: the strict profile (`fieldsSchemaStrict`), excluding `fields`. `null` or a
|
|
7
|
+
* missing key leaves the value as it is; `null` sub-values in repeater items are stripped and
|
|
8
|
+
* all-null items dropped (`droppedItems`), by core-ts's `readStrictFields`.
|
|
9
|
+
* - `clearFields`: keys to remove, with either input; on update only. Setting and clearing one key
|
|
10
|
+
* is refused (`invalid`), and a key the collection does not define (nor, without definitions,
|
|
11
|
+
* hold) is `unknown_field`. During a `rename_field`, the old and the new key are one field:
|
|
12
|
+
* removing either removes both (`withRenamedRemovals`), in `fields` too, and setting one while
|
|
13
|
+
* removing the other is `invalid`.
|
|
14
|
+
*
|
|
15
|
+
* A given reference or repeater value replaces the whole value in every profile.
|
|
16
|
+
*/
|
|
17
|
+
import type { FieldDefinition } from "@cloudhal/core-contracts";
|
|
18
|
+
import { type DroppedItem } from "@cloudhal/core-ts/fields";
|
|
19
|
+
import { type JsonSchema } from "./common.js";
|
|
20
|
+
type Values = Record<string, unknown>;
|
|
21
|
+
/** `fieldsStrict`: a static schema cannot vary by collection, so it points to list_collections. */
|
|
22
|
+
export declare const FIELDS_STRICT_INPUT: JsonSchema;
|
|
23
|
+
/** `clearFields`. */
|
|
24
|
+
export declare const CLEAR_FIELDS_INPUT: JsonSchema;
|
|
25
|
+
/** `droppedItems` in the answer. */
|
|
26
|
+
export declare const DROPPED_ITEMS_OUTPUT: JsonSchema;
|
|
27
|
+
export interface FieldsInput {
|
|
28
|
+
/** The merge patch to apply (`null` removes a key); undefined when the call gives no fields. */
|
|
29
|
+
patch: Values | undefined;
|
|
30
|
+
droppedItems: DroppedItem[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The call's field values as one merge patch. `defs` are the collection's definitions and
|
|
34
|
+
* `stored` the stored values (absent on create, where `clearFields` is refused).
|
|
35
|
+
*/
|
|
36
|
+
export declare function fieldsInputOf(a: Record<string, unknown>, defs: readonly FieldDefinition[], stored: Values | undefined, mode: "create" | "update"): FieldsInput;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0045 §6 for `create_entry` and `update_entry`: the three ways a call gives typed field
|
|
3
|
+
* values, read into one merge patch (`null` removes a key) before the store's checker sees it.
|
|
4
|
+
*
|
|
5
|
+
* - `fields`: the open profile, as before (on update a merge patch: `null` removes a key).
|
|
6
|
+
* - `fieldsStrict`: the strict profile (`fieldsSchemaStrict`), excluding `fields`. `null` or a
|
|
7
|
+
* missing key leaves the value as it is; `null` sub-values in repeater items are stripped and
|
|
8
|
+
* all-null items dropped (`droppedItems`), by core-ts's `readStrictFields`.
|
|
9
|
+
* - `clearFields`: keys to remove, with either input; on update only. Setting and clearing one key
|
|
10
|
+
* is refused (`invalid`), and a key the collection does not define (nor, without definitions,
|
|
11
|
+
* hold) is `unknown_field`. During a `rename_field`, the old and the new key are one field:
|
|
12
|
+
* removing either removes both (`withRenamedRemovals`), in `fields` too, and setting one while
|
|
13
|
+
* removing the other is `invalid`.
|
|
14
|
+
*
|
|
15
|
+
* A given reference or repeater value replaces the whole value in every profile.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { SiteSchema } from "@cloudhal/core-contracts";
|
|
19
|
+
import {
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
readStrictFields,
|
|
23
|
+
refuseFieldIssues,
|
|
24
|
+
renamedFrom,
|
|
25
|
+
} from "@cloudhal/core-ts/fields";
|
|
26
|
+
import { ToolError } from "./common.js";
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const KEY = (SiteSchema.$defs ).FieldKey ;
|
|
31
|
+
|
|
32
|
+
/** `fieldsStrict`: a static schema cannot vary by collection, so it points to list_collections. */
|
|
33
|
+
export const FIELDS_STRICT_INPUT = {
|
|
34
|
+
type: "object",
|
|
35
|
+
description:
|
|
36
|
+
"Instead of fields, for strict structured output: an object following the collection's fieldsSchemaStrict (list_collections), or any subset of its keys. null, or a key left out, leaves the value as it is (on create: no value); a given value replaces the whole value; inside a repeater item null unsets that sub-value, and an item left empty is dropped (reported in droppedItems). Remove values with clearFields.",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** `clearFields`. */
|
|
40
|
+
export const CLEAR_FIELDS_INPUT = {
|
|
41
|
+
type: "array",
|
|
42
|
+
description:
|
|
43
|
+
"Keys of typed custom fields to remove, with fields or fieldsStrict; a key may not also be set in the same call",
|
|
44
|
+
items: KEY,
|
|
45
|
+
uniqueItems: true,
|
|
46
|
+
maxItems: 100,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** `droppedItems` in the answer. */
|
|
50
|
+
export const DROPPED_ITEMS_OUTPUT = {
|
|
51
|
+
type: "array",
|
|
52
|
+
description: "Repeater items of fieldsStrict whose sub-values were all null: not stored",
|
|
53
|
+
items: {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: { field: { type: "string" }, index: { type: "integer" } },
|
|
56
|
+
required: ["field", "index"],
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
const record = (v ) =>
|
|
67
|
+
v && typeof v === "object" && !Array.isArray(v) ? (v ) : undefined;
|
|
68
|
+
|
|
69
|
+
/** Refuses keys that are neither defined nor (in a collection without definitions) stored. */
|
|
70
|
+
function unknownKeys(
|
|
71
|
+
keys ,
|
|
72
|
+
at ,
|
|
73
|
+
known ,
|
|
74
|
+
) {
|
|
75
|
+
const issues = [];
|
|
76
|
+
keys.forEach((key, i) => {
|
|
77
|
+
if (!known(key))
|
|
78
|
+
issues.push({
|
|
79
|
+
path: at(key, i),
|
|
80
|
+
code: "unknown_field",
|
|
81
|
+
message: `${key} is not a field of this collection (list_collections → fields)`,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
refuseFieldIssues(issues);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The call's field values as one merge patch. `defs` are the collection's definitions and
|
|
89
|
+
* `stored` the stored values (absent on create, where `clearFields` is refused).
|
|
90
|
+
*/
|
|
91
|
+
export function fieldsInputOf(
|
|
92
|
+
a ,
|
|
93
|
+
defs ,
|
|
94
|
+
stored ,
|
|
95
|
+
mode ,
|
|
96
|
+
) {
|
|
97
|
+
const open = record(a.fields);
|
|
98
|
+
const strict = record(a.fieldsStrict);
|
|
99
|
+
const clear = Array.isArray(a.clearFields) ? (a.clearFields ) : [];
|
|
100
|
+
if (a.fields !== undefined && a.fieldsStrict !== undefined)
|
|
101
|
+
throw new ToolError("invalid", "give fields or fieldsStrict, not both");
|
|
102
|
+
if (mode === "create" && a.clearFields !== undefined)
|
|
103
|
+
throw new ToolError("invalid", "clearFields: a new entry has nothing to clear");
|
|
104
|
+
const defined = new Set(defs.map((d) => d.key));
|
|
105
|
+
const renames = renamesOf(defs);
|
|
106
|
+
const known = (key ) =>
|
|
107
|
+
defs.length > 0 ? defined.has(key) || renames.has(key) : Object.hasOwn(stored ?? {}, key);
|
|
108
|
+
unknownKeys(clear, (_k, i) => `clearFields/${i}`, known);
|
|
109
|
+
if (strict && defs.length > 0)
|
|
110
|
+
unknownKeys(
|
|
111
|
+
Object.keys(strict),
|
|
112
|
+
(k) => `fieldsStrict/${k}`,
|
|
113
|
+
(k) => defined.has(k),
|
|
114
|
+
);
|
|
115
|
+
const read = strict ? readStrictFields(defs, strict) : { values: open, droppedItems: [] };
|
|
116
|
+
const set = read.values ?? {};
|
|
117
|
+
const both = clear.filter((k) => Object.hasOwn(set, k) && set[k] !== null);
|
|
118
|
+
if (both.length > 0)
|
|
119
|
+
throw new ToolError("invalid", `set or clear, not both: ${both.join(", ")}`, {
|
|
120
|
+
fields: both,
|
|
121
|
+
});
|
|
122
|
+
if (!read.values && clear.length === 0) return { patch: undefined, droppedItems: [] };
|
|
123
|
+
const cleared = Object.fromEntries(clear.map((k) => [k, null]));
|
|
124
|
+
return {
|
|
125
|
+
patch: withRenamedRemovals({ ...set, ...cleared }, renames),
|
|
126
|
+
droppedItems: read.droppedItems,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** A running top-level `rename_field`'s keys, both ways: old key ↔ new key. */
|
|
131
|
+
function renamesOf(defs ) {
|
|
132
|
+
const out = new Map ();
|
|
133
|
+
for (const def of defs) {
|
|
134
|
+
const from = renamedFrom(def);
|
|
135
|
+
if (from === undefined) continue;
|
|
136
|
+
out.set(from, def.key);
|
|
137
|
+
out.set(def.key, from);
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* While `rename_field` runs, an entry not rewritten yet still holds the value under the old key,
|
|
144
|
+
* and the writer moves it to the new one. Removing either key therefore removes both, so a
|
|
145
|
+
* removal is never undone by the move (and the old key is not refused as unknown).
|
|
146
|
+
*/
|
|
147
|
+
function withRenamedRemovals(patch , renames ) {
|
|
148
|
+
if (renames.size === 0) return patch;
|
|
149
|
+
const extra = [];
|
|
150
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
151
|
+
const other = renames.get(key);
|
|
152
|
+
if (value !== null || other === undefined) continue;
|
|
153
|
+
// The old and the new key are one field while the rename runs: set or clear, not both.
|
|
154
|
+
if (Object.hasOwn(patch, other) && patch[other] !== null)
|
|
155
|
+
throw new ToolError(
|
|
156
|
+
"invalid",
|
|
157
|
+
`set or clear, not both: ${key} and ${other} are one field while rename_field runs`,
|
|
158
|
+
{ fields: [key, other] },
|
|
159
|
+
);
|
|
160
|
+
if (!Object.hasOwn(patch, other)) extra.push([other, null]);
|
|
161
|
+
}
|
|
162
|
+
return extra.length ? { ...patch, ...Object.fromEntries(extra) } : patch;
|
|
163
|
+
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* RFC-0041 §3, §8: typed custom field values over MCP. `create_entry` and
|
|
3
|
-
* them in `precheck` with the store's own
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* RFC-0041 §3, §8 and RFC-0045 §6: typed custom field values over MCP. `create_entry` and
|
|
3
|
+
* `update_entry` check them in `precheck` with the store's own write plan, run as a dry run
|
|
4
|
+
* (`NodeWriteOptions.dryRun`): values of changed keys, unknown keys, a translation's copy of a
|
|
5
|
+
* non-localized value, `requiredToPublish` for review and published, image and `asset:`
|
|
6
|
+
* references, and RFC-0045's reference targets (a group of this site in an allowed collection,
|
|
7
|
+
* not the entry's own, `where`), repeater items and the 100-references cap. So a call that the
|
|
8
|
+
* store would refuse never reaches a person. `update_entry` takes `fields` as a merge patch (`null`
|
|
9
|
+
* removes a key); `fieldsStrict` and `clearFields` are read in `entry-fields-input.ts`, the
|
|
10
|
+
* approval prompt's wording is `field-prompts.ts`.
|
|
8
11
|
*/
|
|
9
|
-
import type { ContentEntry
|
|
12
|
+
import type { ContentEntry } from "@cloudhal/core-contracts";
|
|
13
|
+
import type { Creatable } from "@cloudhal/core-ts";
|
|
10
14
|
import { type JsonSchema, type ToolContext } from "./common.js";
|
|
11
15
|
type Values = Record<string, unknown>;
|
|
12
16
|
/** `create_entry`'s `fields`: a static schema cannot vary by site, so it points to list_collections. */
|
|
@@ -19,21 +23,16 @@ export declare const FIELDS_PATCH: JsonSchema;
|
|
|
19
23
|
* input can carry `__proto__` as an own key, and assigning it would swap the object's prototype.
|
|
20
24
|
*/
|
|
21
25
|
export declare function mergeFields(current: Values | undefined, patch: Values): Values;
|
|
22
|
-
/** What an entry write would store, for the check. */
|
|
23
|
-
export interface FieldsCheck {
|
|
24
|
-
site: Site;
|
|
25
|
-
/** The entry as it would be written (its `fields` after the patch). */
|
|
26
|
-
next: Pick<ContentEntry, "id" | "siteId" | "collection" | "fields" | "status" | "translation">;
|
|
27
|
-
/** The stored entry (absent for a new one). */
|
|
28
|
-
stored?: Pick<ContentEntry, "collection" | "fields"> | undefined;
|
|
29
|
-
}
|
|
30
26
|
/**
|
|
31
|
-
* The store's
|
|
32
|
-
* `
|
|
27
|
+
* The store's plan-time checks of a write, without writing (`dryRun`): throws what the write
|
|
28
|
+
* would, as tool errors (`invalid_fields`, `unknown_field`, `unknown_entry`, `required_field`,
|
|
29
|
+
* `required_term`, …, every issue at its path), else returns the entry as the store would write
|
|
30
|
+
* it (canonical reference ids, values through the markers). `update` is the stored entry with
|
|
31
|
+
* the call's changes.
|
|
33
32
|
*/
|
|
34
|
-
export declare function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
export declare function checkEntryWrite(ctx: ToolContext, write: {
|
|
34
|
+
update: ContentEntry;
|
|
35
|
+
} | {
|
|
36
|
+
create: Creatable<ContentEntry>;
|
|
37
|
+
}): Promise<ContentEntry>;
|
|
39
38
|
export {};
|