@nextblock-cms/cortex 0.20.0 → 0.20.1

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.
@@ -1,8 +1,8 @@
1
- import { createCortexGlobalAgentTools as f } from "./ai-global-agent-tools.es.js";
2
- import { availableCortexAiBlockTypes as y } from "./block-content-schemas.es.js";
1
+ import { createCortexGlobalAgentTools as y } from "./ai-global-agent-tools.es.js";
2
+ import { availableCortexAiBlockTypes as v } from "./block-content-schemas.es.js";
3
3
  import "./zod-config.es.js";
4
4
  import { z as w } from "zod";
5
- const n = {
5
+ const s = {
6
6
  create_cms_page: "write",
7
7
  create_cms_post: "write",
8
8
  create_cms_product: "write",
@@ -53,7 +53,53 @@ const n = {
53
53
  update_navigation_bar: "write",
54
54
  update_section_column_block: "write",
55
55
  update_site_identity: "write"
56
- }, u = {
56
+ }, k = {
57
+ create_cms_page: { destructive: !1, idempotent: !0, openWorld: !0 },
58
+ create_cms_post: { destructive: !1, idempotent: !0, openWorld: !0 },
59
+ create_cms_product: { destructive: !1, idempotent: !0, openWorld: !0 },
60
+ create_custom_block: { destructive: !1, idempotent: !1, openWorld: !1 },
61
+ delete_cms_item: { destructive: !0, idempotent: !0, openWorld: !1 },
62
+ delete_custom_block: { destructive: !0, idempotent: !0, openWorld: !1 },
63
+ // A plan can carry delete_cms_item, insert_content_block and set_content_images, so it
64
+ // inherits the worst of each.
65
+ execute_cms_action_plan: { destructive: !0, idempotent: !1, openWorld: !0 },
66
+ execute_database_action_plan: { destructive: !0, idempotent: !1, openWorld: !1 },
67
+ execute_database_mutation: { destructive: !0, idempotent: !1, openWorld: !1 },
68
+ finish_site_build: { destructive: !1, idempotent: !0, openWorld: !1 },
69
+ insert_content_block: { destructive: !1, idempotent: !1, openWorld: !1 },
70
+ manage_language: { destructive: !1, idempotent: !0, openWorld: !1 },
71
+ manage_product_category: { destructive: !0, idempotent: !0, openWorld: !1 },
72
+ manage_product_variants: { destructive: !0, idempotent: !1, openWorld: !1 },
73
+ manage_site_script: { destructive: !0, idempotent: !0, openWorld: !1 },
74
+ manage_site_theme: { destructive: !1, idempotent: !0, openWorld: !1 },
75
+ // Overwrites the live blocks, but snapshots a revision first and consumes the draft,
76
+ // so a second call finds nothing to publish.
77
+ publish_content_draft: { destructive: !1, idempotent: !0, openWorld: !1 },
78
+ reset_site_content: { destructive: !0, idempotent: !0, openWorld: !1 },
79
+ // Logged as a new revision; the rollback can itself be rolled back.
80
+ revert_site_script: { destructive: !1, idempotent: !0, openWorld: !1 },
81
+ rewrite_page_draft: { destructive: !1, idempotent: !0, openWorld: !1 },
82
+ save_site_brief: { destructive: !0, idempotent: !0, openWorld: !1 },
83
+ set_content_images: { destructive: !0, idempotent: !1, openWorld: !0 },
84
+ // Runs the reset, and each call (re)opens the time-boxed build session.
85
+ start_site_build: { destructive: !0, idempotent: !1, openWorld: !1 },
86
+ translate_content_bulk: { destructive: !1, idempotent: !0, openWorld: !1 },
87
+ translate_page: { destructive: !1, idempotent: !0, openWorld: !1 },
88
+ update_cms_item_field: { destructive: !1, idempotent: !0, openWorld: !1 },
89
+ upload_media: { destructive: !1, idempotent: !1, openWorld: !0 },
90
+ update_content_block: { destructive: !1, idempotent: !0, openWorld: !1 },
91
+ update_current_cms_fields: { destructive: !1, idempotent: !0, openWorld: !1 },
92
+ // Regenerates the whole definition from a description; nothing keeps the old layout.
93
+ update_custom_block: { destructive: !0, idempotent: !1, openWorld: !1 },
94
+ update_footer: { destructive: !0, idempotent: !0, openWorld: !1 },
95
+ update_global_css: { destructive: !0, idempotent: !1, openWorld: !1 },
96
+ update_navigation_bar: { destructive: !0, idempotent: !0, openWorld: !1 },
97
+ update_section_column_block: { destructive: !1, idempotent: !0, openWorld: !1 },
98
+ update_site_identity: { destructive: !1, idempotent: !0, openWorld: !1 }
99
+ }, x = /* @__PURE__ */ new Set([
100
+ "fetch_url_content",
101
+ "search_stock_photos"
102
+ ]), d = {
57
103
  create_page_layout: {
58
104
  canonical: "create_cms_page",
59
105
  description: 'Create a new page from a slug, a title and a strictly typed block layout in one call. Every block is normalized and validated against the NextBlock block schema (built-in types from the `cortex://schema/blocks` resource, or a custom block slug from `list_custom_blocks`) before anything is written; an invalid block rejects the whole call. Pass `status: "published"` to go live immediately, or leave the default draft and publish later. To rewrite an existing page instead, use `generate_jsonb_layout`. Alias of `create_cms_page`.',
@@ -85,18 +131,37 @@ const n = {
85
131
  title: "Update site navigation"
86
132
  }
87
133
  };
88
- function _(e) {
89
- return e in u ? u[e].canonical : e in n ? e : null;
134
+ function p(e) {
135
+ return e in d ? d[e].canonical : e in s ? e : null;
90
136
  }
91
- function k(e) {
92
- const t = _(e);
93
- return t ? n[t] : null;
137
+ function C(e) {
138
+ const t = p(e);
139
+ return t ? s[t] : null;
94
140
  }
95
- function d(e, t) {
96
- const a = k(t);
141
+ function _(e) {
142
+ const t = p(e);
143
+ if (!t)
144
+ return null;
145
+ if (s[t] === "read")
146
+ return {
147
+ destructiveHint: !1,
148
+ idempotentHint: !0,
149
+ openWorldHint: x.has(t),
150
+ readOnlyHint: !0
151
+ };
152
+ const a = k[t];
153
+ return {
154
+ destructiveHint: a.destructive,
155
+ idempotentHint: a.idempotent,
156
+ openWorldHint: a.openWorld,
157
+ readOnlyHint: !1
158
+ };
159
+ }
160
+ function u(e, t) {
161
+ const a = C(t);
97
162
  return a ? a === "read" ? e.length > 0 : e.includes("write") : !1;
98
163
  }
99
- function p(e) {
164
+ function m(e) {
100
165
  return e.split("_").map((a, r) => r === 0 ? a.charAt(0).toUpperCase() + a.slice(1) : a).join(" ");
101
166
  }
102
167
  function h(e) {
@@ -116,85 +181,94 @@ function h(e) {
116
181
  return t;
117
182
  }
118
183
  }
119
- function s(e) {
120
- return f(e);
184
+ function c(e) {
185
+ return y(e);
121
186
  }
122
187
  function N(e) {
123
- const t = Object.keys(s(e)), a = Object.keys(n);
188
+ const t = Object.keys(c(e)), a = Object.keys(s);
124
189
  return {
125
190
  missingFromRegistry: a.filter((r) => !t.includes(r)),
126
191
  unclassified: t.filter((r) => !a.includes(r))
127
192
  };
128
193
  }
129
- function M(e) {
130
- const t = s(e.context), a = [];
131
- for (const [r, o] of Object.entries(t))
132
- !(r in n) || !d(e.scopes, r) || a.push({
133
- description: o.description ?? `Cortex AI ${p(r)} tool.`,
134
- inputSchema: h(o.inputSchema),
194
+ function E(e) {
195
+ const t = c(e.context), a = [];
196
+ for (const [r, i] of Object.entries(t)) {
197
+ if (!(r in s) || !u(e.scopes, r))
198
+ continue;
199
+ const o = _(r);
200
+ o && a.push({
201
+ annotations: o,
202
+ description: i.description ?? `Cortex AI ${m(r)} tool.`,
203
+ inputSchema: h(i.inputSchema),
135
204
  name: r,
136
- title: p(r)
205
+ title: m(r)
137
206
  });
138
- for (const [r, o] of Object.entries(u)) {
139
- const i = t[o.canonical];
140
- !i || !d(e.scopes, r) || a.push({
141
- description: o.description,
142
- inputSchema: h(i.inputSchema),
207
+ }
208
+ for (const [r, i] of Object.entries(d)) {
209
+ const o = t[i.canonical];
210
+ if (!o || !u(e.scopes, r))
211
+ continue;
212
+ const n = _(r);
213
+ n && a.push({
214
+ annotations: n,
215
+ description: i.description,
216
+ inputSchema: h(o.inputSchema),
143
217
  name: r,
144
- title: o.title
218
+ title: i.title
145
219
  });
146
220
  }
147
- return a.sort((r, o) => r.name.localeCompare(o.name));
221
+ return a.sort((r, i) => r.name.localeCompare(i.name));
148
222
  }
149
223
  function g(e, t) {
150
224
  return { content: [{ text: e, type: "text" }], isError: t };
151
225
  }
152
- function v(e) {
226
+ function W(e) {
153
227
  return e.issues.map((t) => `${t.path.length > 0 ? t.path.join(".") : "(root)"}: ${t.message}`).join("; ");
154
228
  }
155
- class m extends Error {
229
+ class f extends Error {
156
230
  constructor(t) {
157
231
  super(`Unknown tool: ${t}`), this.name = "CortexMcpUnknownToolError";
158
232
  }
159
233
  }
160
- class x extends Error {
234
+ class T extends Error {
161
235
  constructor(t) {
162
236
  super(
163
237
  `Tool "${t}" requires the "write" scope. This MCP token is read-only — mint a read+write token in CMS Settings → Cortex AI.`
164
238
  ), this.name = "CortexMcpForbiddenToolError";
165
239
  }
166
240
  }
167
- async function O(e) {
168
- const t = _(e.name);
241
+ async function A(e) {
242
+ const t = p(e.name);
169
243
  if (!t)
170
- throw new m(e.name);
171
- if (!d(e.scopes, e.name))
172
- throw new x(e.name);
173
- const r = s(e.context)[t];
244
+ throw new f(e.name);
245
+ if (!u(e.scopes, e.name))
246
+ throw new T(e.name);
247
+ const r = c(e.context)[t];
174
248
  if (!r || typeof r.execute != "function")
175
- throw new m(e.name);
176
- const o = e.args && typeof e.args == "object" ? e.args : {};
249
+ throw new f(e.name);
250
+ const i = e.args && typeof e.args == "object" ? e.args : {};
177
251
  if (r.inputSchema && typeof r.inputSchema.safeParse == "function") {
178
- const i = r.inputSchema.safeParse(o);
179
- if (!i.success)
252
+ const o = r.inputSchema.safeParse(i);
253
+ if (!o.success)
180
254
  return g(
181
- `Invalid arguments for "${e.name}": ${v(i.error)}`,
255
+ `Invalid arguments for "${e.name}": ${W(o.error)}`,
182
256
  !0
183
257
  );
184
258
  }
185
259
  try {
186
- const i = await r.execute(o), c = JSON.stringify(i ?? { success: !0 }, null, 2), l = i && typeof i == "object" && !Array.isArray(i) ? i : null, b = l?.success === !1;
260
+ const o = await r.execute(i), n = JSON.stringify(o ?? { success: !0 }, null, 2), l = o && typeof o == "object" && !Array.isArray(o) ? o : null, b = l?.success === !1;
187
261
  return {
188
- content: [{ text: c, type: "text" }],
262
+ content: [{ text: n, type: "text" }],
189
263
  isError: b,
190
264
  ...l ? { structuredContent: l } : {}
191
265
  };
192
- } catch (i) {
193
- const c = i instanceof Error ? i.message : String(i);
194
- return g(`Tool "${e.name}" failed: ${c}`, !0);
266
+ } catch (o) {
267
+ const n = o instanceof Error ? o.message : String(o);
268
+ return g(`Tool "${e.name}" failed: ${n}`, !0);
195
269
  }
196
270
  }
197
- const A = [
271
+ const P = [
198
272
  {
199
273
  description: "The CMS database structure Cortex AI can read and mutate: tables, columns, primary keys, and read-only flags.",
200
274
  mimeType: "application/json",
@@ -217,8 +291,8 @@ const A = [
217
291
  uri: "cortex://schema/custom-blocks"
218
292
  }
219
293
  ];
220
- async function E(e) {
221
- const t = s(e.context);
294
+ async function L(e) {
295
+ const t = c(e.context);
222
296
  if (e.uri === "cortex://schema/database") {
223
297
  const a = await t.describe_database_schema?.execute?.({ includeReadOnly: !0 });
224
298
  return {
@@ -230,7 +304,7 @@ async function E(e) {
230
304
  if (e.uri === "cortex://schema/blocks")
231
305
  return {
232
306
  mimeType: "application/json",
233
- text: JSON.stringify({ blockTypes: y }, null, 2),
307
+ text: JSON.stringify({ blockTypes: v }, null, 2),
234
308
  uri: e.uri
235
309
  };
236
310
  if (e.uri === "cortex://schema/custom-blocks") {
@@ -243,7 +317,7 @@ async function E(e) {
243
317
  }
244
318
  return null;
245
319
  }
246
- const C = [
320
+ const S = [
247
321
  {
248
322
  arguments: [
249
323
  {
@@ -283,7 +357,7 @@ const C = [
283
357
  name: "translate-content",
284
358
  title: "Translate a page or post"
285
359
  }
286
- ], S = {
360
+ ], O = {
287
361
  "build-site": (e) => [
288
362
  "Build the whole NextBlock site for this client.",
289
363
  "",
@@ -327,8 +401,8 @@ ${e.brief}` : "A site brief may already be saved (get_site_overview returns it u
327
401
  ].join(`
328
402
  `)
329
403
  };
330
- function P(e) {
331
- const t = C.find((r) => r.name === e.name), a = S[e.name];
404
+ function U(e) {
405
+ const t = S.find((r) => r.name === e.name), a = O[e.name];
332
406
  return !t || !a ? null : {
333
407
  description: t.description,
334
408
  messages: [
@@ -337,18 +411,20 @@ function P(e) {
337
411
  };
338
412
  }
339
413
  export {
340
- C as CORTEX_MCP_PROMPTS,
341
- A as CORTEX_MCP_RESOURCES,
342
- u as CORTEX_MCP_TOOL_ALIASES,
343
- n as CORTEX_MCP_TOOL_KINDS,
344
- x as CortexMcpForbiddenToolError,
345
- m as CortexMcpUnknownToolError,
414
+ S as CORTEX_MCP_PROMPTS,
415
+ P as CORTEX_MCP_RESOURCES,
416
+ d as CORTEX_MCP_TOOL_ALIASES,
417
+ s as CORTEX_MCP_TOOL_KINDS,
418
+ k as CORTEX_MCP_WRITE_TOOL_BEHAVIOURS,
419
+ T as CortexMcpForbiddenToolError,
420
+ f as CortexMcpUnknownToolError,
346
421
  N as assertCortexMcpToolCoverage,
347
- M as buildCortexMcpToolDefinitions,
348
- O as callCortexMcpTool,
349
- d as cortexMcpScopesAllow,
350
- P as getCortexMcpPrompt,
351
- k as getCortexMcpToolKind,
352
- E as readCortexMcpResource,
353
- _ as resolveCortexMcpToolName
422
+ E as buildCortexMcpToolDefinitions,
423
+ A as callCortexMcpTool,
424
+ u as cortexMcpScopesAllow,
425
+ U as getCortexMcpPrompt,
426
+ _ as getCortexMcpToolAnnotations,
427
+ C as getCortexMcpToolKind,
428
+ L as readCortexMcpResource,
429
+ p as resolveCortexMcpToolName
354
430
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextblock-cms/cortex",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@ai-sdk/openai-compatible": "^2.0.42",
31
- "@nextblock-cms/db": "^0.20.0",
32
- "@nextblock-cms/ecommerce": "npm:@nextblock-cms/ecom@^0.20.0",
33
- "@nextblock-cms/utils": "^0.20.0",
31
+ "@nextblock-cms/db": "^0.20.1",
32
+ "@nextblock-cms/ecommerce": "npm:@nextblock-cms/ecom@^0.20.1",
33
+ "@nextblock-cms/utils": "^0.20.1",
34
34
  "ai": "^6.0.170",
35
35
  "zod": "^4.3.6"
36
36
  },