@nextblock-cms/cortex 0.15.0 → 0.15.2

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.
@@ -77,7 +77,7 @@ const yn = 1e4, bn = {
77
77
  copyright: i.record(i.string().trim().min(2).max(12), i.string().trim().min(1).max(500)).optional(),
78
78
  languageCode: i.string().trim().min(2).max(80).default("en").describe('Locale code or language name, for example "en", "fr", "English", or "French".'),
79
79
  links: i.array(_e).min(1).max(30).optional()
80
- }), zt = i.strictObject({
80
+ }), Gt = i.strictObject({
81
81
  limit: i.number().int().min(1).max(8).default(4),
82
82
  query: i.string().trim().min(2).max(300)
83
83
  }), we = i.object({
@@ -87,7 +87,7 @@ const yn = 1e4, bn = {
87
87
  query: i.string().describe("The analytical question about orders, products, or revenue."),
88
88
  reportType: i.enum(["revenue", "orders", "products", "general"]).optional().default("general").describe("The focus area of the statistical report."),
89
89
  timeRange: i.enum(["today", "this_month", "last_7_days", "last_30_days", "last_month", "last_90_days", "all_time"]).optional().default("all_time").describe("The time period for the report. Use all_time for current order-status counts unless the user names a specific period.")
90
- }), Gt = i.strictObject({
90
+ }), zt = i.strictObject({
91
91
  contentType: i.enum(["page", "post", "product"]),
92
92
  currentEditor: i.strictObject({
93
93
  blockId: i.union([i.number().int().positive(), i.string().trim().min(1).max(120)]).nullable().optional(),
@@ -145,7 +145,7 @@ const yn = 1e4, bn = {
145
145
  }), ot = i.strictObject({
146
146
  blockType: i.enum(Y),
147
147
  content: i.record(i.string(), i.unknown()).describe(
148
- 'The block content, matching that block type\'s schema. For a `text` block, `html_content` is rendered as real HTML and may include an inline <style> and an inline <script> — so you can add scroll reveals, counters, hover effects, and other motion directly in a block, scoped with your own class names. Inline scripts are stamped with the site CSP nonce automatically. Three rules. (1) The page is React-hydrated, so a script that changes text, classes, or attributes of the surrounding markup MUST wait for hydration or React discards the tree with a hydration mismatch — always wrap DOM work as: function run(){/* ... */} if(document.readyState==="complete"){run()}else{window.addEventListener("load",run)}. Pure additions (appending a new element, binding a listener) are safe either way. (2) `on*` attributes (onclick, onload, …) are stripped, so bind with addEventListener inside the <script>. (3) The script runs once per full page load, not on client-side navigation — for site-wide behaviour use manage_site_script instead.'
148
+ "The block content, matching that block type's schema. For a `text` block, `html_content` is rendered as real HTML and may include an inline <style> and an inline <script> — so you can add scroll reveals, counters, hover effects, and other motion directly in a block. Inline scripts are stamped with the site CSP nonce automatically. Three rules. (1) THE PAGE IS REACT-HYDRATED. Do not change the text, classes, or attributes of surrounding server-rendered markup: React reconciles afterwards and reverts your change (a counter animates then snaps back) or logs a hydration mismatch. Waiting for `load` is NOT sufficient hydration can still be in flight. Safe patterns instead: animate with the Web Animations API (el.animate() touches no attribute); append your own new elements and style those; use CSS for anything CSS can do; and if you must set text, render the FINAL value server-side and only animate toward it once the element scrolls into view. (2) `on*` attributes (onclick, onload, …) are stripped, so bind with addEventListener. (3) The script runs once per full page load, not on client-side navigation — for site-wide behaviour use manage_site_script."
149
149
  ),
150
150
  order: i.number().int().min(0).optional()
151
151
  }), kt = V.extend({
@@ -604,7 +604,7 @@ function Fn(t, e, n) {
604
604
  ]);
605
605
  }
606
606
  function jn(t) {
607
- const e = Gt.safeParse(t?.pageContext);
607
+ const e = zt.safeParse(t?.pageContext);
608
608
  if (!e.success)
609
609
  throw new Error(
610
610
  "No current CMS page context is available. Open a page, post, or product edit screen before using this editing tool."
@@ -709,7 +709,7 @@ function Dn(t, e) {
709
709
  const n = Se(e ?? t.slug);
710
710
  return n ? t.contentType === "page" ? n === "home" ? "/" : `/${n}` : t.contentType === "post" ? `/article/${n}` : `/product/${n}` : null;
711
711
  }
712
- function zn(t) {
712
+ function Gn(t) {
713
713
  const e = String(t.entityId);
714
714
  return t.contentType === "page" ? `/cms/pages/${e}/edit` : t.contentType === "post" ? `/cms/posts/${e}/edit` : `/cms/products/${e}/edit`;
715
715
  }
@@ -717,7 +717,7 @@ function O(t, e, n) {
717
717
  const o = t?.revalidatePath ?? Kt();
718
718
  if (!o)
719
719
  return;
720
- o(zn(e));
720
+ o(Gn(e));
721
721
  const r = Dn(e, n);
722
722
  r && o(r), e.contentType === "page" && r !== "/" && o("/"), e.contentType === "product" && o("/cms/products");
723
723
  }
@@ -728,7 +728,7 @@ function Ee(t) {
728
728
  function b(t) {
729
729
  return t ? typeof t == "object" && "message" in t ? String(t.message || "Unknown database error.") : String(t) : "Unknown database error.";
730
730
  }
731
- async function Gn() {
731
+ async function zn() {
732
732
  return import("./ai-global-agent-ecommerce.es.js");
733
733
  }
734
734
  function Ut(t) {
@@ -764,7 +764,7 @@ function F(t, e) {
764
764
  const n = t[e];
765
765
  return typeof n == "string" && n.trim() ? n.trim() : null;
766
766
  }
767
- function z(t, e) {
767
+ function G(t, e) {
768
768
  const n = Number(t[e]);
769
769
  return Number.isFinite(n) ? n : null;
770
770
  }
@@ -775,13 +775,13 @@ function Vn(t, e) {
775
775
  const n = F(e, "summary");
776
776
  if (n)
777
777
  return n;
778
- const o = F(e, "title"), r = F(e, "slug"), a = F(e, "status"), s = F(e, "contentType"), c = F(e, "field"), u = F(e, "mode"), d = F(e, "languageCode"), l = z(e, "blockCount"), p = z(e, "itemCount"), h = z(e, "affectedCount");
778
+ const o = F(e, "title"), r = F(e, "slug"), a = F(e, "status"), s = F(e, "contentType"), c = F(e, "field"), u = F(e, "mode"), d = F(e, "languageCode"), l = G(e, "blockCount"), p = G(e, "itemCount"), h = G(e, "affectedCount");
779
779
  if (t === "create_cms_page" || t === "create_cms_post")
780
780
  return `Create ${a || "draft"} ${t === "create_cms_page" ? "page" : "post"} "${o || r || "Untitled"}"${r ? ` at slug "${r}"` : ""}${l !== null ? ` with ${U(l, "content block")}` : ""}.`;
781
781
  if (t === "create_cms_product") {
782
- const m = z(e, "imageCount"), f = z(e, "blockCount"), g = [
782
+ const m = G(e, "imageCount"), f = G(e, "blockCount"), g = [
783
783
  m ? U(m, "image") : null,
784
- f ? U(f, "description block") : z(e, "descriptionLength") ? "a full description" : null
784
+ f ? U(f, "description block") : G(e, "descriptionLength") ? "a full description" : null
785
785
  ].filter(Boolean);
786
786
  return `Create ${a || "draft"} product "${o || r || "Untitled"}"${r ? ` at slug "${r}"` : ""}${g.length ? ` with ${g.join(" and ")}` : ""}.`;
787
787
  }
@@ -790,7 +790,7 @@ function Vn(t, e) {
790
790
  if (t === "update_navigation_bar")
791
791
  return `${u === "append" ? "Add" : u === "update" ? "Update" : "Replace"} ${p !== null ? U(p, "navigation item") : "navigation items"} in the ${d || "selected"} header navigation.`;
792
792
  if (t === "update_footer") {
793
- const m = z(e, "linkCount");
793
+ const m = G(e, "linkCount");
794
794
  return `Update the ${d || "selected"} footer${m !== null ? ` with ${U(m, "link")}` : ""}.`;
795
795
  }
796
796
  return t === "update_content_block" ? `Update the selected ${F(e, "blockType") || "content"} block.` : t === "insert_content_block" ? `Insert ${F(e, "blockType") || "content"} block on the ${s || "CMS item"} "${o || r || "selected item"}".` : t === "update_section_column_block" ? `Update the selected nested ${F(e, "nestedBlockType") || "section"} block.` : t === "delete_cms_item" || t === "prepare_delete_cms_item" ? `Delete ${h !== null ? U(h, s || "CMS item") : `the selected ${s || "CMS item"}`}${o || r ? ` for "${o || r}"` : ""}.` : "Complete the requested CMS change.";
@@ -899,7 +899,7 @@ function Pe(t, e, n) {
899
899
  `${n} is a "${e}" block. Refusing to update it as "${t}".`
900
900
  );
901
901
  }
902
- function G(t, e, n, o) {
902
+ function z(t, e, n, o) {
903
903
  const r = Rn(t, e, o);
904
904
  if (!r.isValid)
905
905
  throw new Error(
@@ -952,7 +952,7 @@ function Zn(t, e) {
952
952
  if (!n)
953
953
  return null;
954
954
  const o = it(t, `Nested ${n} block`);
955
- return G(n, o, `Nested ${n} block`, e), {
955
+ return z(n, o, `Nested ${n} block`, e), {
956
956
  block_type: n,
957
957
  content: o,
958
958
  temp_id: pt(n)
@@ -1072,7 +1072,7 @@ async function rr(t) {
1072
1072
  return s[0];
1073
1073
  }
1074
1074
  async function W(t, e) {
1075
- const n = Gt.safeParse(e?.pageContext).success ? e?.pageContext : null, o = t.contentType || n?.contentType;
1075
+ const n = zt.safeParse(e?.pageContext).success ? e?.pageContext : null, o = t.contentType || n?.contentType;
1076
1076
  if (!o)
1077
1077
  throw new Error("Target contentType is required when no current CMS edit context exists.");
1078
1078
  const r = t.entityId !== void 0 || !!t.slug || !!t.title, a = t.entityId ?? (r ? void 0 : n?.entityId), s = t.slug ?? (r ? void 0 : n?.slug ?? void 0), c = t.title ?? (r ? void 0 : n?.title ?? void 0), u = await rr({
@@ -1088,7 +1088,7 @@ async function W(t, e) {
1088
1088
  };
1089
1089
  }
1090
1090
  async function Z(t, e) {
1091
- const n = Gt.safeParse(e?.pageContext);
1091
+ const n = zt.safeParse(e?.pageContext);
1092
1092
  if (n.success)
1093
1093
  return n.data;
1094
1094
  if (!(t !== void 0 && (t.entityId !== void 0 || !!t.slug || !!t.title)))
@@ -1416,14 +1416,14 @@ function Tr(t, e, n) {
1416
1416
  function Re(t, e, n, o) {
1417
1417
  if (t === "section") {
1418
1418
  const a = Tr(e, n, o);
1419
- return G(t, a, n, o), a;
1419
+ return z(t, a, n, o), a;
1420
1420
  }
1421
1421
  const r = K(e);
1422
1422
  if (t === "heading" && (r.text_content = $(r.text_content) || $(r.text) || $(r.title) || $(r.heading) || "Untitled", r.level = typeof r.level == "number" ? r.level : 1), t === "text") {
1423
1423
  const a = $(r.html_content) || $(r.html) || $(r.content) || $(r.text);
1424
1424
  a && (r.html_content = /<\/?[a-z][\s\S]*>/i.test(a) ? a : `<p>${lr(a)}</p>`);
1425
1425
  }
1426
- return t === "button" && (r.text = $(r.text) || $(r.label) || $(r.title) || "Learn More", r.url = $(r.url) || $(r.href) || $(r.link) || "#"), t === "form" && (r.fields = dr(r.fields), r.submit_button_text = $(r.submit_button_text ?? r.submitButtonText ?? r.button_text) || "Send Message", r.success_message = $(r.success_message ?? r.successMessage) || "Thanks for reaching out. We will reply as soon as possible."), G(t, r, n, o), r;
1426
+ return t === "button" && (r.text = $(r.text) || $(r.label) || $(r.title) || "Learn More", r.url = $(r.url) || $(r.href) || $(r.link) || "#"), t === "form" && (r.fields = dr(r.fields), r.submit_button_text = $(r.submit_button_text ?? r.submitButtonText ?? r.button_text) || "Send Message", r.success_message = $(r.success_message ?? r.successMessage) || "Thanks for reaching out. We will reply as soon as possible."), z(t, r, n, o), r;
1427
1427
  }
1428
1428
  function gt(t, e, n) {
1429
1429
  const o = Re(
@@ -1689,7 +1689,7 @@ function de(t, e) {
1689
1689
  ) || t.find((n) => n.trim().length > 0) || "No excerpt available.").slice(0, 500);
1690
1690
  }
1691
1691
  async function xr(t, e) {
1692
- const n = zt.parse(t), o = S(e), r = n.query.toLowerCase().split(/\s+/).map((l) => l.trim()).filter(Boolean), [a, s] = await Promise.all([
1692
+ const n = Gt.parse(t), o = S(e), r = n.query.toLowerCase().split(/\s+/).map((l) => l.trim()).filter(Boolean), [a, s] = await Promise.all([
1693
1693
  o.from("posts").select("id, title, slug, excerpt, subtitle, meta_description, status, updated_at").eq("status", "published").limit(100),
1694
1694
  o.from("pages").select("id, title, slug, meta_description, status, updated_at").eq("status", "published").limit(100)
1695
1695
  ]);
@@ -1726,7 +1726,7 @@ async function xr(t, e) {
1726
1726
  };
1727
1727
  }
1728
1728
  async function Cr(t, e, n = yn) {
1729
- const o = zt.safeParse(t), r = o.success ? o.data.query : "";
1729
+ const o = Gt.safeParse(t), r = o.success ? o.data.query : "";
1730
1730
  return Fn(
1731
1731
  xr(t, e),
1732
1732
  n,
@@ -1984,7 +1984,7 @@ function Rr(t, e) {
1984
1984
  }
1985
1985
  return o;
1986
1986
  }
1987
- async function ze(t, e) {
1987
+ async function Ge(t, e) {
1988
1988
  const n = bt.parse(t), o = S(e), r = await Z(n.cmsTarget, e), a = M(r), s = Rr(n.fields, r), c = Object.keys(s);
1989
1989
  if (c.length === 0)
1990
1990
  throw new Error("update_current_cms_fields requires at least one supported field.");
@@ -2031,7 +2031,7 @@ async function ze(t, e) {
2031
2031
  updatedFields: c
2032
2032
  };
2033
2033
  }
2034
- async function Ge(t, e) {
2034
+ async function ze(t, e) {
2035
2035
  const n = _t.parse(t), o = S(e), r = await Z(n.cmsTarget, e), { data: a, error: s } = await o.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq("id", n.blockId).single();
2036
2036
  if (s || !a)
2037
2037
  throw new Error(`Failed to read block ${n.blockId}: ${b(s)}`);
@@ -2044,7 +2044,7 @@ async function Ge(t, e) {
2044
2044
  n.content,
2045
2045
  e
2046
2046
  );
2047
- G(c, d, `Block ${n.blockId}`, e);
2047
+ z(c, d, `Block ${n.blockId}`, e);
2048
2048
  const l = N({
2049
2049
  action: "UPDATE CONTENT BLOCK",
2050
2050
  context: e,
@@ -2221,7 +2221,7 @@ async function He(t, e) {
2221
2221
  a.content,
2222
2222
  `Parent block ${n.parentBlockId}`
2223
2223
  );
2224
- G(
2224
+ z(
2225
2225
  c,
2226
2226
  u,
2227
2227
  `Parent block ${n.parentBlockId}`,
@@ -2240,7 +2240,7 @@ async function He(t, e) {
2240
2240
  n.blockType,
2241
2241
  p,
2242
2242
  `Nested block ${n.columnIndex}:${n.blockIndex}`
2243
- ), G(
2243
+ ), z(
2244
2244
  p,
2245
2245
  n.content,
2246
2246
  `Nested block ${n.columnIndex}:${n.blockIndex}`,
@@ -2257,7 +2257,7 @@ async function He(t, e) {
2257
2257
  ...u,
2258
2258
  column_blocks: h
2259
2259
  };
2260
- G(
2260
+ z(
2261
2261
  c,
2262
2262
  m,
2263
2263
  `Updated parent block ${n.parentBlockId}`,
@@ -2545,7 +2545,7 @@ async function We(t, e) {
2545
2545
  });
2546
2546
  if (u.result)
2547
2547
  return u.result;
2548
- const { createProduct: d, productSchema: l } = await Gn(), h = n.product_type === "digital" && n.payment_provider === "freemius" ? n.trial_period_days : 0, m = l.parse({
2548
+ const { createProduct: d, productSchema: l } = await zn(), h = n.product_type === "digital" && n.payment_provider === "freemius" ? n.trial_period_days : 0, m = l.parse({
2549
2549
  description_json: jr(n),
2550
2550
  freemius_plan_id: n.freemius_plan_id || "",
2551
2551
  freemius_product_id: n.freemius_product_id || "",
@@ -2667,8 +2667,8 @@ const Dr = /* @__PURE__ */ new Set([
2667
2667
  "sale_price",
2668
2668
  "stock",
2669
2669
  "trial_period_days"
2670
- ]), zr = /* @__PURE__ */ new Set(["is_taxable", "trial_requires_payment_method"]);
2671
- function Gr(t, e) {
2670
+ ]), Gr = /* @__PURE__ */ new Set(["is_taxable", "trial_requires_payment_method"]);
2671
+ function zr(t, e) {
2672
2672
  if (typeof e != "string")
2673
2673
  return e;
2674
2674
  const n = e.trim();
@@ -2680,7 +2680,7 @@ function Gr(t, e) {
2680
2680
  const o = Number(n);
2681
2681
  return Number.isFinite(o) ? o : e;
2682
2682
  }
2683
- if (zr.has(t)) {
2683
+ if (Gr.has(t)) {
2684
2684
  const o = n.toLowerCase();
2685
2685
  if (o === "true")
2686
2686
  return !0;
@@ -2708,7 +2708,7 @@ function Kr(t, e) {
2708
2708
  trial_days: "trial_period_days",
2709
2709
  trial_payment_method_required: "trial_requires_payment_method",
2710
2710
  type: "product_type"
2711
- }[n] || n, a = r === "status" ? Br(e.contentType, t.value) : Gr(r, t.value);
2711
+ }[n] || n, a = r === "status" ? Br(e.contentType, t.value) : zr(r, t.value);
2712
2712
  if (e.contentType !== "product") {
2713
2713
  if (!(e.contentType === "page" ? qe : Me).has(r))
2714
2714
  throw new Error(`Field "${t.field}" cannot be updated for ${e.contentType}.`);
@@ -2993,11 +2993,11 @@ async function me(t, e) {
2993
2993
  case "update_cms_item_field":
2994
2994
  return Je(t.input, e);
2995
2995
  case "update_content_block":
2996
- return Ge(t.input, e);
2996
+ return ze(t.input, e);
2997
2997
  case "insert_content_block":
2998
2998
  return Ke(t.input, e);
2999
2999
  case "update_current_cms_fields":
3000
- return ze(t.input, e);
3000
+ return Ge(t.input, e);
3001
3001
  case "update_footer":
3002
3002
  return je(t.input, e);
3003
3003
  case "update_navigation_bar":
@@ -4257,7 +4257,7 @@ function Po(t) {
4257
4257
  search_documentation: C({
4258
4258
  description: "Search the NextBlock documentation database and return concise source snippets for factual CMS guidance.",
4259
4259
  execute: (e) => Cr(e, t),
4260
- inputSchema: zt,
4260
+ inputSchema: Gt,
4261
4261
  strict: !0
4262
4262
  }),
4263
4263
  fetch_url_content: C({
@@ -4346,7 +4346,7 @@ function Po(t) {
4346
4346
  }),
4347
4347
  update_content_block: C({
4348
4348
  description: 'Update the JSON content of an existing top-level page/post block. The block must belong to the item being edited — the open CMS editor, or the item named by `cmsTarget` (contentType plus slug, entityId, or title) when no editor is open, as with MCP clients. Content is merged with the existing block before validation. For section blocks, add nested blocks with content.append_block or content.append_blocks using objects like { block_type: "button", content: { text: "Contact Us", url: "/contact" } }; existing column_blocks and layout fields are preserved. Mutating: first returns a confirmation phrase; only executes after exact confirmation.',
4349
- execute: (e) => Ge(e, t),
4349
+ execute: (e) => ze(e, t),
4350
4350
  inputSchema: _t,
4351
4351
  strict: !0
4352
4352
  }),
@@ -4358,7 +4358,7 @@ function Po(t) {
4358
4358
  }),
4359
4359
  update_current_cms_fields: C({
4360
4360
  description: "Update validated metadata fields on the current page, post, or product. For products, description_json must be a valid NextBlock editor document JSON object. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
4361
- execute: (e) => ze(e, t),
4361
+ execute: (e) => Ge(e, t),
4362
4362
  inputSchema: bt,
4363
4363
  strict: !0
4364
4364
  }),
@@ -4391,7 +4391,7 @@ function Po(t) {
4391
4391
  export {
4392
4392
  Y as availableCortexAiBlockTypes,
4393
4393
  $o as buildVisibleContactIntroActionPlan,
4394
- Gt as cortexAiPageContextSchema,
4394
+ zt as cortexAiPageContextSchema,
4395
4395
  It as createCmsPageInputSchema,
4396
4396
  vt as createCmsPostInputSchema,
4397
4397
  xt as createCmsProductInputSchema,
@@ -4418,8 +4418,8 @@ export {
4418
4418
  ho as executeTranslateContentBulk,
4419
4419
  dn as executeTranslatePage,
4420
4420
  Je as executeUpdateCmsItemField,
4421
- Ge as executeUpdateContentBlock,
4422
- ze as executeUpdateCurrentCmsFields,
4421
+ ze as executeUpdateContentBlock,
4422
+ Ge as executeUpdateCurrentCmsFields,
4423
4423
  je as executeUpdateFooter,
4424
4424
  Fe as executeUpdateNavigationBar,
4425
4425
  He as executeUpdateSectionColumnBlock,
@@ -4436,7 +4436,7 @@ export {
4436
4436
  Ao as resolveCortexAiStockPhotoProvider,
4437
4437
  re as resolveCortexAiStockPhotoProviders,
4438
4438
  an as rewritePageDraftInputSchema,
4439
- zt as searchDocumentationInputSchema,
4439
+ Gt as searchDocumentationInputSchema,
4440
4440
  on as searchStockPhotosInputSchema,
4441
4441
  kt as setContentImagesInputSchema,
4442
4442
  cn as translateContentBulkInputSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextblock-cms/cortex",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -27,9 +27,9 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@ai-sdk/openai-compatible": "^2.0.42",
30
- "@nextblock-cms/db": "^0.15.0",
31
- "@nextblock-cms/ecommerce": "npm:@nextblock-cms/ecom@^0.15.0",
32
- "@nextblock-cms/utils": "^0.15.0",
30
+ "@nextblock-cms/db": "^0.15.2",
31
+ "@nextblock-cms/ecommerce": "npm:@nextblock-cms/ecom@^0.15.2",
32
+ "@nextblock-cms/utils": "^0.15.2",
33
33
  "ai": "^6.0.170",
34
34
  "zod": "^4.3.6"
35
35
  },