@cloudhal/mcp-server 0.3.13 → 0.5.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 +119 -1
- package/dist/src/collection-fields.d.ts +22 -0
- package/dist/src/collection-fields.js +107 -0
- package/dist/src/collection-tools.d.ts +4 -0
- package/dist/src/collection-tools.js +308 -0
- package/dist/src/common.js +9 -0
- package/dist/src/entry-fields.d.ts +35 -0
- package/dist/src/entry-fields.js +233 -0
- package/dist/src/entry-tools.js +46 -9
- package/dist/src/field-hints.d.ts +7 -0
- package/dist/src/field-hints.js +39 -0
- package/dist/src/field-tools.d.ts +6 -0
- package/dist/src/field-tools.js +360 -0
- package/dist/src/permalink-tools.js +3 -1
- package/dist/src/server-instructions.js +5 -1
- package/dist/src/tools.js +6 -0
- package/package.json +9 -9
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0041 §3, §8: typed custom field values over MCP. `create_entry` and `update_entry` check
|
|
3
|
+
* them in `precheck` with the store's own checker (changed keys only, unknown keys, a translation's
|
|
4
|
+
* copy of a non-localized value, `requiredToPublish` for review and published, image and `asset:`
|
|
5
|
+
* references), so a call that the store would refuse never reaches a person. `update_entry` takes
|
|
6
|
+
* `fields` as a merge patch (`null` removes a key), and its approval prompt names each typed change
|
|
7
|
+
* readably: labels, option labels, dates in their zone, values quoted and truncated.
|
|
8
|
+
*/
|
|
9
|
+
import type { ContentEntry, FieldDefinition, Site } from "@cloudhal/core-contracts";
|
|
10
|
+
import { type JsonSchema, type ToolContext } from "./common.js";
|
|
11
|
+
type Values = Record<string, unknown>;
|
|
12
|
+
/** `create_entry`'s `fields`: a static schema cannot vary by site, so it points to list_collections. */
|
|
13
|
+
export declare const FIELDS_INPUT: JsonSchema;
|
|
14
|
+
/** `update_entry`'s `fields`: a merge patch. */
|
|
15
|
+
export declare const FIELDS_PATCH: JsonSchema;
|
|
16
|
+
/** The stored `fields` with `patch` applied: `null` removes a key. */
|
|
17
|
+
export declare function mergeFields(current: Values | undefined, patch: Values): Values;
|
|
18
|
+
/** What an entry write would store, for the check. */
|
|
19
|
+
export interface FieldsCheck {
|
|
20
|
+
site: Site;
|
|
21
|
+
/** The entry as it would be written (its `fields` after the patch). */
|
|
22
|
+
next: Pick<ContentEntry, "id" | "siteId" | "collection" | "fields" | "status" | "translation">;
|
|
23
|
+
/** The stored entry (absent for a new one). */
|
|
24
|
+
stored?: Pick<ContentEntry, "collection" | "fields"> | undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The store's field checks, run before anyone is asked: throws `invalid_fields`, `unknown_field`,
|
|
28
|
+
* `field_not_localized`, `required_field` or `too_large` with every issue at its path.
|
|
29
|
+
*/
|
|
30
|
+
export declare function checkEntryFields(ctx: ToolContext, check: FieldsCheck): Promise<void>;
|
|
31
|
+
/** A value as a person reads it in an approval prompt (agent text quoted and truncated). */
|
|
32
|
+
export declare function describeFieldValue(def: FieldDefinition | undefined, value: unknown, locale: string): string;
|
|
33
|
+
/** "startsAt → 5 Nov 2026 19:30 Istanbul, format → Talk, Workshop, notes removed". */
|
|
34
|
+
export declare function describeFieldPatch(site: Site, collection: string, patch: Values): string;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0041 §3, §8: typed custom field values over MCP. `create_entry` and `update_entry` check
|
|
3
|
+
* them in `precheck` with the store's own checker (changed keys only, unknown keys, a translation's
|
|
4
|
+
* copy of a non-localized value, `requiredToPublish` for review and published, image and `asset:`
|
|
5
|
+
* references), so a call that the store would refuse never reaches a person. `update_entry` takes
|
|
6
|
+
* `fields` as a merge patch (`null` removes a key), and its approval prompt names each typed change
|
|
7
|
+
* readably: labels, option labels, dates in their zone, values quoted and truncated.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
ASSET_ID_PATTERN,
|
|
12
|
+
checkFieldValues,
|
|
13
|
+
checkRequiredToPublish,
|
|
14
|
+
convertContext,
|
|
15
|
+
|
|
16
|
+
fieldDefinitions,
|
|
17
|
+
fieldLabel,
|
|
18
|
+
normalizeThroughMarkers,
|
|
19
|
+
optionLabel,
|
|
20
|
+
refuseFieldIssues,
|
|
21
|
+
} from "@cloudhal/core-ts/fields";
|
|
22
|
+
import { markdownAssetIds } from "@cloudhal/core-ts/media";
|
|
23
|
+
import { quote, } from "./common.js";
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/** `create_entry`'s `fields`: a static schema cannot vary by site, so it points to list_collections. */
|
|
28
|
+
export const FIELDS_INPUT = {
|
|
29
|
+
type: "object",
|
|
30
|
+
description:
|
|
31
|
+
"Typed custom fields of the collection: read its fieldsSchema from list_collections first (keys, types, allowed values, limits). A collection without field definitions takes any JSON here.",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** `update_entry`'s `fields`: a merge patch. */
|
|
35
|
+
export const FIELDS_PATCH = {
|
|
36
|
+
type: "object",
|
|
37
|
+
description:
|
|
38
|
+
"Typed custom fields to change, as a merge patch: given keys are set, null removes a key, others stay. The collection's fieldsSchema (list_collections) lists the keys and allowed values.",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** The stored `fields` with `patch` applied: `null` removes a key. */
|
|
42
|
+
export function mergeFields(current , patch ) {
|
|
43
|
+
const next = { ...(current ?? {}) };
|
|
44
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
45
|
+
if (value === null) delete next[key];
|
|
46
|
+
else next[key] = value;
|
|
47
|
+
}
|
|
48
|
+
return next;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const isTranslation = (e ) =>
|
|
52
|
+
!!e.translation && e.translation.group !== e.id && e.translation.source?.siteId === undefined;
|
|
53
|
+
|
|
54
|
+
/** The same-site original of a translation (as the store reads it). */
|
|
55
|
+
async function originalOf(
|
|
56
|
+
ctx ,
|
|
57
|
+
entry ,
|
|
58
|
+
) {
|
|
59
|
+
if (!isTranslation(entry)) return undefined;
|
|
60
|
+
const original = await ctx.store.getContentEntry(entry.translation?.group );
|
|
61
|
+
return original?.siteId === entry.siteId ? original : undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const ASSET_ID = new RegExp(ASSET_ID_PATTERN);
|
|
65
|
+
|
|
66
|
+
/** `fields.<key>` → asset ids an image or rich-text value refers to. */
|
|
67
|
+
function assetRefs(defs , values ) {
|
|
68
|
+
const out = new Set ();
|
|
69
|
+
for (const def of defs) {
|
|
70
|
+
const value = values?.[def.key];
|
|
71
|
+
if (typeof value !== "string") continue;
|
|
72
|
+
if (def.type === "image" && ASSET_ID.test(value)) out.add(`${def.key}\n${value}`);
|
|
73
|
+
else if (def.type === "richText" && value.includes("asset:"))
|
|
74
|
+
for (const id of markdownAssetIds(value)) out.add(`${def.key}\n${id}`);
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function assetProblem(asset , def , siteId ) {
|
|
80
|
+
if (!asset || asset.siteId !== siteId) return "is not a file of this site";
|
|
81
|
+
if (def.type === "image" && asset.kind !== "image")
|
|
82
|
+
return `is a ${asset.kind} file, not an image`;
|
|
83
|
+
if (asset.status === "retired") return "was retired and cannot be newly used";
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** New references (not held by the stored entry under the same key) name usable files of the site. */
|
|
88
|
+
async function assetIssues(
|
|
89
|
+
ctx ,
|
|
90
|
+
check
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
,
|
|
96
|
+
) {
|
|
97
|
+
const held = assetRefs(check.defs, check.stored);
|
|
98
|
+
const byKey = new Map(check.defs.map((d) => [d.key, d]));
|
|
99
|
+
const out = [];
|
|
100
|
+
for (const ref of assetRefs(check.defs, check.values)) {
|
|
101
|
+
if (held.has(ref)) continue;
|
|
102
|
+
const [key = "", assetId = ""] = ref.split("\n");
|
|
103
|
+
const problem = assetProblem(
|
|
104
|
+
await ctx.store.getAsset(assetId),
|
|
105
|
+
byKey.get(key) ,
|
|
106
|
+
check.siteId,
|
|
107
|
+
);
|
|
108
|
+
if (problem)
|
|
109
|
+
out.push({ path: `fields/${key}`, code: "invalid_value", message: `${assetId} ${problem}` });
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** What an entry write would store, for the check. */
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The store's field checks, run before anyone is asked: throws `invalid_fields`, `unknown_field`,
|
|
125
|
+
* `field_not_localized`, `required_field` or `too_large` with every issue at its path.
|
|
126
|
+
*/
|
|
127
|
+
export async function checkEntryFields(ctx , check ) {
|
|
128
|
+
const { site, stored } = check;
|
|
129
|
+
let next = check.next;
|
|
130
|
+
const defs = fieldDefinitions(site, next.collection);
|
|
131
|
+
// While a field operation runs, a write goes through its marker (as the store normalizes it).
|
|
132
|
+
if (defs.some((d) => d.migration)) {
|
|
133
|
+
const fields = normalizeThroughMarkers(defs, next.fields, {
|
|
134
|
+
convert: convertContext(site),
|
|
135
|
+
translation: isTranslation(next),
|
|
136
|
+
});
|
|
137
|
+
if (fields) next = { ...next, fields };
|
|
138
|
+
}
|
|
139
|
+
const values = next.fields ?? {};
|
|
140
|
+
const previous = stored?.collection === next.collection ? (stored.fields ?? {}) : undefined;
|
|
141
|
+
if (defs.length === 0) {
|
|
142
|
+
if (!previous || JSON.stringify(previous) !== JSON.stringify(values))
|
|
143
|
+
refuseFieldIssues(checkFieldValues([], { values }));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const original = await originalOf(ctx, next);
|
|
147
|
+
const issues = checkFieldValues(defs, {
|
|
148
|
+
values,
|
|
149
|
+
previous,
|
|
150
|
+
original: original ? { id: original.id, values: original.fields ?? {} } : undefined,
|
|
151
|
+
blocks: ctx.store.blocks,
|
|
152
|
+
});
|
|
153
|
+
const invalid = new Set(issues.map((i) => i.path.split("/").slice(0, 2).join("/")));
|
|
154
|
+
const assets = await assetIssues(ctx, { siteId: site.id, defs, values, stored: previous });
|
|
155
|
+
issues.push(...assets.filter((i) => !invalid.has(i.path)));
|
|
156
|
+
issues.push(...checkRequiredToPublish(site, { ...next, fields: values }, original));
|
|
157
|
+
refuseFieldIssues(issues);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** "5 Nov 2026" (a calendar day: no zone). */
|
|
161
|
+
function day(value ) {
|
|
162
|
+
const d = new Date(`${value}T00:00:00Z`);
|
|
163
|
+
if (Number.isNaN(d.getTime())) return quote(value);
|
|
164
|
+
return new Intl.DateTimeFormat("en-GB", {
|
|
165
|
+
day: "numeric",
|
|
166
|
+
month: "short",
|
|
167
|
+
year: "numeric",
|
|
168
|
+
timeZone: "UTC",
|
|
169
|
+
}).format(d);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** "5 Nov 2026 19:30 Istanbul" (the wall clock in the value's own zone). */
|
|
173
|
+
function instant(value ) {
|
|
174
|
+
const v = value ;
|
|
175
|
+
if (typeof v?.at !== "string" || typeof v.timeZone !== "string") return quote(JSON.stringify(v));
|
|
176
|
+
const at = new Date(v.at);
|
|
177
|
+
if (Number.isNaN(at.getTime())) return quote(v.at);
|
|
178
|
+
try {
|
|
179
|
+
const parts = new Intl.DateTimeFormat("en-GB", {
|
|
180
|
+
day: "numeric",
|
|
181
|
+
month: "short",
|
|
182
|
+
year: "numeric",
|
|
183
|
+
hour: "2-digit",
|
|
184
|
+
minute: "2-digit",
|
|
185
|
+
hourCycle: "h23",
|
|
186
|
+
timeZone: v.timeZone,
|
|
187
|
+
}).format(at);
|
|
188
|
+
const city = (v.timeZone.split("/").pop() ?? v.timeZone).replace(/_/g, " ");
|
|
189
|
+
return `${parts.replace(",", "")} ${city}`;
|
|
190
|
+
} catch {
|
|
191
|
+
return `${quote(v.at)} ${quote(v.timeZone)}`;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** A value as a person reads it in an approval prompt (agent text quoted and truncated). */
|
|
196
|
+
export function describeFieldValue(
|
|
197
|
+
def ,
|
|
198
|
+
value ,
|
|
199
|
+
locale ,
|
|
200
|
+
) {
|
|
201
|
+
if (!def) return `"${quote(JSON.stringify(value) ?? "")}"`;
|
|
202
|
+
switch (def.type) {
|
|
203
|
+
case "number":
|
|
204
|
+
return typeof value === "number" ? String(value) : `"${quote(String(value))}"`;
|
|
205
|
+
case "boolean":
|
|
206
|
+
return value === true ? "yes" : "no";
|
|
207
|
+
case "date":
|
|
208
|
+
return typeof value === "string" ? day(value) : `"${quote(String(value))}"`;
|
|
209
|
+
case "datetime":
|
|
210
|
+
return instant(value);
|
|
211
|
+
case "select": {
|
|
212
|
+
const list = Array.isArray(value) ? value : [value];
|
|
213
|
+
return list.map((v) => quote(optionLabel(def, String(v), locale, locale))).join(", ");
|
|
214
|
+
}
|
|
215
|
+
default:
|
|
216
|
+
return `"${quote(typeof value === "string" ? value : JSON.stringify(value))}"`;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** "startsAt → 5 Nov 2026 19:30 Istanbul, format → Talk, Workshop, notes removed". */
|
|
221
|
+
export function describeFieldPatch(site , collection , patch ) {
|
|
222
|
+
const defs = new Map(fieldDefinitions(site, collection).map((d) => [d.key, d]));
|
|
223
|
+
const locale = site.defaultLocale;
|
|
224
|
+
return Object.entries(patch)
|
|
225
|
+
.map(([key, value]) => {
|
|
226
|
+
const def = defs.get(key);
|
|
227
|
+
const name = def ? `"${quote(fieldLabel(def, locale, locale), 40)}" (${key})` : key;
|
|
228
|
+
return value === null
|
|
229
|
+
? `${name} removed`
|
|
230
|
+
: `${name} → ${describeFieldValue(def, value, locale)}`;
|
|
231
|
+
})
|
|
232
|
+
.join(", ");
|
|
233
|
+
}
|
package/dist/src/entry-tools.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
import { requireRegistered } from "./collection-tools.js";
|
|
5
6
|
import {
|
|
6
7
|
autoSnapshot,
|
|
7
8
|
entryLimitCheck,
|
|
@@ -25,6 +26,13 @@ import {
|
|
|
25
26
|
unknownBlocks,
|
|
26
27
|
unknownBlocksOf,
|
|
27
28
|
} from "./content-shared.js";
|
|
29
|
+
import {
|
|
30
|
+
checkEntryFields,
|
|
31
|
+
describeFieldPatch,
|
|
32
|
+
FIELDS_INPUT,
|
|
33
|
+
FIELDS_PATCH,
|
|
34
|
+
mergeFields,
|
|
35
|
+
} from "./entry-fields.js";
|
|
28
36
|
import { entryTerms, reportDeltas } from "./entry-terms.js";
|
|
29
37
|
import { menuHint, menuItemsHiddenBy } from "./menu-tools.js";
|
|
30
38
|
import { assignmentDeltas, describeDeltas, TAGS_INPUT, TERMS_INPUT, termLookup } from "./terms.js";
|
|
@@ -109,7 +117,7 @@ const createEntryTool = {
|
|
|
109
117
|
name: "create_entry",
|
|
110
118
|
title: "Create article",
|
|
111
119
|
description:
|
|
112
|
-
"Create a draft content entry (markdown body), optionally filed under existing terms (`terms`; see list_taxonomies and list_terms). Snapshots afterwards.",
|
|
120
|
+
"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`; see list_taxonomies and list_terms). Typed custom fields go in `fields`, following the collection's fieldsSchema from list_collections; invalid values are refused with their paths. Snapshots afterwards.",
|
|
113
121
|
inputSchema: obj(
|
|
114
122
|
{
|
|
115
123
|
siteId: id,
|
|
@@ -124,7 +132,7 @@ const createEntryTool = {
|
|
|
124
132
|
terms: TERMS_INPUT,
|
|
125
133
|
tags: TAGS_INPUT,
|
|
126
134
|
coverImage: COVER_INPUT,
|
|
127
|
-
fields:
|
|
135
|
+
fields: FIELDS_INPUT,
|
|
128
136
|
},
|
|
129
137
|
["siteId", "slug", "title", "body"],
|
|
130
138
|
),
|
|
@@ -140,6 +148,24 @@ const createEntryTool = {
|
|
|
140
148
|
},
|
|
141
149
|
scopes: ["content:write"],
|
|
142
150
|
own: "entry",
|
|
151
|
+
// RFC-0040 §5: only collections of the registry (a new one goes through create_collection);
|
|
152
|
+
// RFC-0041 §8: field values are checked before anyone is asked.
|
|
153
|
+
precheck: async (a, ctx) => {
|
|
154
|
+
const collection = (a.collection ) ?? "posts";
|
|
155
|
+
await requireRegistered(ctx, a.siteId , collection);
|
|
156
|
+
const site = await ctx.store.getSite(a.siteId );
|
|
157
|
+
if (!site) return;
|
|
158
|
+
await checkEntryFields(ctx, {
|
|
159
|
+
site,
|
|
160
|
+
next: {
|
|
161
|
+
id: "",
|
|
162
|
+
siteId: site.id,
|
|
163
|
+
collection,
|
|
164
|
+
status: "draft",
|
|
165
|
+
fields: (a.fields ) ?? {},
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
},
|
|
143
169
|
handler: async (a, ctx) => {
|
|
144
170
|
const site = await requireSite(ctx, a.siteId );
|
|
145
171
|
await entryLimitCheck(ctx, "create", undefined, {
|
|
@@ -185,7 +211,7 @@ const updateEntryTool = {
|
|
|
185
211
|
name: "update_entry",
|
|
186
212
|
title: "Update article",
|
|
187
213
|
description:
|
|
188
|
-
"Update title, summary, body, slug, status (draft → review → published)
|
|
214
|
+
"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 (`fields`, a merge patch: null removes a key; see the collection's fieldsSchema in list_collections) of an entry. Review and published articles need a primary term in every required taxonomy and every field marked needed to publish. Requires the current `rev`. Changing a published article's slug leaves a redirect. Snapshots afterwards.",
|
|
189
215
|
inputSchema: obj(
|
|
190
216
|
{
|
|
191
217
|
siteId: id,
|
|
@@ -203,6 +229,7 @@ const updateEntryTool = {
|
|
|
203
229
|
description: "Cover image; null removes it",
|
|
204
230
|
},
|
|
205
231
|
status: { type: "string", enum: ["draft", "review", "published", "archived"] },
|
|
232
|
+
fields: FIELDS_PATCH,
|
|
206
233
|
},
|
|
207
234
|
["siteId", "entryId", "rev"],
|
|
208
235
|
),
|
|
@@ -215,15 +242,18 @@ const updateEntryTool = {
|
|
|
215
242
|
},
|
|
216
243
|
scopes: ["content:write"],
|
|
217
244
|
own: "entry",
|
|
218
|
-
// Own-limited callers (Authors, Contributors and their agents) only touch their own articles
|
|
245
|
+
// Own-limited callers (Authors, Contributors and their agents) only touch their own articles;
|
|
246
|
+
// field values (RFC-0041 §8) are checked before anyone is asked.
|
|
219
247
|
precheck: async (a, ctx) => {
|
|
220
|
-
if (!ctx.limit) return;
|
|
221
248
|
const entry = await ctx.store.getContentEntry(a.entryId );
|
|
222
249
|
if (!entry || entry.siteId !== a.siteId) return;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
250
|
+
const status = (a.status ) ?? entry.status;
|
|
251
|
+
if (ctx.limit) await entryLimitCheck(ctx, "update", entry, { author: entry.author, status });
|
|
252
|
+
if (a.fields === undefined && status === entry.status) return;
|
|
253
|
+
const site = await ctx.store.getSite(entry.siteId);
|
|
254
|
+
if (!site) return;
|
|
255
|
+
const fields = mergeFields(entry.fields, (a.fields ) ?? {});
|
|
256
|
+
await checkEntryFields(ctx, { site, next: { ...entry, status, fields }, stored: entry });
|
|
227
257
|
},
|
|
228
258
|
approvalPrompt: async (a, ctx) => {
|
|
229
259
|
const entry = await ctx.store.getContentEntry(a.entryId );
|
|
@@ -243,6 +273,10 @@ const updateEntryTool = {
|
|
|
243
273
|
: "cover image"
|
|
244
274
|
: "",
|
|
245
275
|
].filter(Boolean);
|
|
276
|
+
if (a.fields && site && Object.keys(a.fields).length)
|
|
277
|
+
changes.push(
|
|
278
|
+
`fields: ${describeFieldPatch(site, entry.collection, a.fields )}`,
|
|
279
|
+
);
|
|
246
280
|
if (a.terms || a.tags) {
|
|
247
281
|
try {
|
|
248
282
|
const { terms } = await entryTerms(ctx, site , entry, a);
|
|
@@ -291,6 +325,9 @@ const updateEntryTool = {
|
|
|
291
325
|
...(a.title ? { title: a.title } : {}),
|
|
292
326
|
...(a.summary !== undefined ? { summary: a.summary } : {}),
|
|
293
327
|
...(a.body !== undefined ? { body: { ...entry.body, value: a.body } } : {}),
|
|
328
|
+
...(a.fields !== undefined
|
|
329
|
+
? { fields: mergeFields(entry.fields, a.fields ) }
|
|
330
|
+
: {}),
|
|
294
331
|
...(a.slug ? { slug: a.slug } : {}),
|
|
295
332
|
tags,
|
|
296
333
|
...(terms ? { terms } : {}),
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0041: what an agent does next after a typed-field refusal. Every refusal keeps its issues in
|
|
3
|
+
* `details.issues`, each at its slash path (`fields/startsAt/at`), so the hint only names the tool.
|
|
4
|
+
*/
|
|
5
|
+
import type { InvariantCode } from "@cloudhal/core-ts";
|
|
6
|
+
/** The next step for a field refusal; undefined for codes that are not about fields. */
|
|
7
|
+
export declare function fieldHint(code: InvariantCode, details: Readonly<Record<string, unknown>>): string | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0041: what an agent does next after a typed-field refusal. Every refusal keeps its issues in
|
|
3
|
+
* `details.issues`, each at its slash path (`fields/startsAt/at`), so the hint only names the tool.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const OPERATIONS = "rename_field, change_field_type, set_field_localized or remove_field";
|
|
8
|
+
|
|
9
|
+
const HINTS = {
|
|
10
|
+
invalid_fields:
|
|
11
|
+
"fix the values at the paths in details.issues; list_collections shows the collection's fieldsSchema (types, allowed values, limits)",
|
|
12
|
+
unknown_field:
|
|
13
|
+
"use one of the collection's field keys (list_collections → fieldsSchema); a new field is added with update_collection, which a person approves",
|
|
14
|
+
field_not_localized:
|
|
15
|
+
"that field is shared by every language version: set it on the original entry named in the message, and leave it out of the translation",
|
|
16
|
+
required_field:
|
|
17
|
+
"give the fields named in details.issues a value (update_entry with fields), or keep the entry a draft",
|
|
18
|
+
field_key_reserved:
|
|
19
|
+
"pick another key: built-in entry properties (title, slug, body, …) cannot be field keys",
|
|
20
|
+
field_key_duplicate: "every field key appears once per collection",
|
|
21
|
+
field_option_duplicate: "every option value appears once per select field",
|
|
22
|
+
field_bounds: "a number field's minimum must not be above its maximum",
|
|
23
|
+
too_many_fields:
|
|
24
|
+
"a collection has at most 30 fields, a site 200 and a select 50 options; remove some first",
|
|
25
|
+
field_change_needs_operation: `that change could lose or reinterpret stored values: use ${OPERATIONS} (each shows a dry run and waits for a person; try dryRun: true first)`,
|
|
26
|
+
operation_in_progress:
|
|
27
|
+
"a person can continue or revert it in Studio, or call the same operation tool again with that operationId (it needs a new approval)",
|
|
28
|
+
field_values_unconvertible:
|
|
29
|
+
'details.report.samples shows the values; change them first (update_entry), or call again with onInvalid: "clear" to drop them (the person approving sees how many)',
|
|
30
|
+
field_operation_incomplete:
|
|
31
|
+
"call the operation tool again with its operationId to finish it (a new approval), or ask a person to continue it in Studio",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** The next step for a field refusal; undefined for codes that are not about fields. */
|
|
35
|
+
export function fieldHint(code , details ) {
|
|
36
|
+
if (code === "too_large" && Array.isArray(details.issues))
|
|
37
|
+
return "field values are at most 256 KB per entry and collection settings 256 KB per site; shorten or drop values";
|
|
38
|
+
return HINTS[code];
|
|
39
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type FieldOperation, type FieldOperationReport } from "@cloudhal/core-ts";
|
|
2
|
+
import { type ToolDefinition } from "./common.js";
|
|
3
|
+
/** The approval prompt, built from the dry run (RFC-0041 §6 step 1). */
|
|
4
|
+
export declare function describeOperation(op: FieldOperation, report: FieldOperationReport, locale: string): string;
|
|
5
|
+
/** rename_field … remove_field, after the collection tools. */
|
|
6
|
+
export declare function fieldTools(): ToolDefinition[];
|