@nextblock-cms/cortex 0.13.3 → 0.13.5

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,9 +1,10 @@
1
- import { tool as T } from "ai";
2
- import { createCortexDatabaseAgentTools as Vt } from "./ai-global-agent-db-tools.es.js";
3
- import { createCortexCustomBlockTools as Ht } from "./ai-global-agent-custom-block-tools.es.js";
1
+ import { tool as x } from "ai";
2
+ import { createCortexDatabaseAgentTools as on } from "./ai-global-agent-db-tools.es.js";
3
+ import { createCortexCustomBlockTools as an } from "./ai-global-agent-custom-block-tools.es.js";
4
+ import { editorDocumentFromHtml as dt } from "./editor-document-from-html.es.js";
4
5
  import "./zod-config.es.js";
5
6
  import { z as i } from "zod";
6
- const M = [
7
+ const G = [
7
8
  "text",
8
9
  "heading",
9
10
  "image",
@@ -18,7 +19,7 @@ const M = [
18
19
  "cart",
19
20
  "checkout",
20
21
  "product_details"
21
- ], Wt = 1e4, Jt = {
22
+ ], sn = 1e4, ln = {
22
23
  arabic: "ar",
23
24
  chinese: "zh",
24
25
  dutch: "nl",
@@ -33,40 +34,40 @@ const M = [
33
34
  portuguese: "pt",
34
35
  russian: "ru",
35
36
  spanish: "es"
36
- }, ot = i.string().trim().min(1).max(2048).refine(
37
+ }, pt = i.string().trim().min(1).max(2048).refine(
37
38
  (e) => e.startsWith("/") || e.startsWith("#") || e.startsWith("http://") || e.startsWith("https://") || e.startsWith("mailto:") || e.startsWith("tel:"),
38
39
  "URL must be a relative path, hash link, http(s) URL, mailto URL, or tel URL."
39
- ), Ke = i.strictObject({
40
+ ), Ye = i.strictObject({
40
41
  label: i.string().trim().min(1).max(120),
41
42
  target: i.enum(["_self", "_blank"]).optional(),
42
- url: ot
43
- }), it = Ke.extend({
44
- children: i.array(Ke).max(20).optional()
45
- }), Yt = i.strictObject({
43
+ url: pt
44
+ }), mt = Ye.extend({
45
+ children: i.array(Ye).max(20).optional()
46
+ }), cn = i.strictObject({
46
47
  label: i.string().trim().min(1).max(120).optional(),
47
- url: ot.optional()
48
+ url: pt.optional()
48
49
  }).refine((e) => !!(e.label || e.url), {
49
50
  message: "Navigation item match requires label or url."
50
- }), se = i.strictObject({
51
- items: i.array(it).min(1).max(30),
51
+ }), de = i.strictObject({
52
+ items: i.array(mt).min(1).max(30),
52
53
  languageCode: i.string().trim().min(2).max(80).default("en").describe('Locale code or language name, for example "en", "fr", "English", or "French".'),
53
- match: Yt.optional().describe('For mode "update", identifies the existing navigation item to update.'),
54
+ match: cn.optional().describe('For mode "update", identifies the existing navigation item to update.'),
54
55
  mode: i.enum(["append", "replace", "update"]).default("append")
55
- }), le = i.strictObject({
56
+ }), pe = i.strictObject({
56
57
  copyright: i.record(i.string().trim().min(2).max(12), i.string().trim().min(1).max(500)).optional(),
57
58
  languageCode: i.string().trim().min(2).max(80).default("en").describe('Locale code or language name, for example "en", "fr", "English", or "French".'),
58
- links: i.array(it).min(1).max(30).optional()
59
- }), Pe = i.strictObject({
59
+ links: i.array(mt).min(1).max(30).optional()
60
+ }), Fe = i.strictObject({
60
61
  limit: i.number().int().min(1).max(8).default(4),
61
62
  query: i.string().trim().min(2).max(300)
62
- }), at = i.object({
63
+ }), gt = i.object({
63
64
  currency: i.string().trim().min(3).max(3).optional().describe(
64
65
  "Optional currency code for currency-specific monetary reports (e.g., USD, CAD). Do not set this for plain order-status counts unless the user asks for a currency."
65
66
  ),
66
67
  query: i.string().describe("The analytical question about orders, products, or revenue."),
67
68
  reportType: i.enum(["revenue", "orders", "products", "general"]).optional().default("general").describe("The focus area of the statistical report."),
68
69
  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.")
69
- }), st = i.strictObject({
70
+ }), ft = i.strictObject({
70
71
  contentType: i.enum(["page", "post", "product"]),
71
72
  currentEditor: i.strictObject({
72
73
  blockId: i.union([i.number().int().positive(), i.string().trim().min(1).max(120)]).nullable().optional(),
@@ -78,11 +79,13 @@ const M = [
78
79
  slug: i.string().trim().min(1).max(300).nullable().optional(),
79
80
  title: i.string().trim().min(1).max(300).nullable().optional(),
80
81
  translationGroupId: i.string().trim().min(1).max(120).nullable().optional()
81
- }), lt = i.strictObject({
82
+ }), ht = i.strictObject({
82
83
  includeBlockContent: i.boolean().default(!1),
83
84
  includeBlocks: i.boolean().default(!0)
84
- }), ce = i.strictObject({
85
+ }), me = i.strictObject({
85
86
  fields: i.strictObject({
87
+ // Accepts an HTML string as well as an editor document — see
88
+ // validateProductDescriptionJson.
86
89
  description_json: i.unknown().optional(),
87
90
  excerpt: i.string().max(2e3).nullable().optional(),
88
91
  feature_image_id: i.string().trim().min(1).max(2048).nullable().optional(),
@@ -96,32 +99,36 @@ const M = [
96
99
  subtitle: i.string().max(300).nullable().optional(),
97
100
  title: i.string().trim().min(1).max(300).optional()
98
101
  }).partial()
99
- }), ue = i.strictObject({
102
+ }), ge = i.strictObject({
100
103
  blockId: i.number().int().positive(),
101
- blockType: i.enum(M).optional(),
104
+ blockType: i.enum(G).optional(),
102
105
  content: i.record(i.string(), i.unknown())
103
- }), de = i.strictObject({
106
+ }), fe = i.strictObject({
104
107
  blockIndex: i.number().int().min(0),
105
- blockType: i.enum(M).optional(),
108
+ blockType: i.enum(G).optional(),
106
109
  columnIndex: i.number().int().min(0),
107
110
  content: i.record(i.string(), i.unknown()),
108
111
  parentBlockId: i.number().int().positive()
109
- }), Xt = i.enum(["page", "post", "product"]), W = i.strictObject({
110
- contentType: Xt.optional(),
112
+ }), un = i.enum(["page", "post", "product"]), K = i.strictObject({
113
+ contentType: un.optional(),
111
114
  entityId: i.union([i.number().int().positive(), i.string().trim().min(1).max(120)]).optional(),
112
115
  slug: i.string().trim().min(1).max(300).optional(),
113
116
  title: i.string().trim().min(1).max(300).optional()
114
- }), pe = i.strictObject({
115
- blockType: i.enum(M),
117
+ }), Q = i.strictObject({
118
+ blockType: i.enum(G),
116
119
  content: i.record(i.string(), i.unknown()),
117
120
  order: i.number().int().min(0).optional()
118
- }), me = W.extend({
121
+ }), he = K.extend({
122
+ images: i.array(i.string().trim().min(1).max(2048)).min(1).max(12).describe(
123
+ "External https image URLs (imported into the media library automatically) and/or existing media library ids. The first entry is the feature image (pages/posts) or the main product image (products)."
124
+ )
125
+ }), ye = K.extend({
119
126
  anchorBlockId: i.number().int().positive().optional(),
120
- anchorBlockType: i.enum(M).optional(),
121
- block: pe,
127
+ anchorBlockType: i.enum(G).optional(),
128
+ block: Q,
122
129
  position: i.enum(["before", "after", "start", "end"]).default("end")
123
- }), ge = i.strictObject({
124
- blocks: i.array(pe).max(20).optional(),
130
+ }), _e = i.strictObject({
131
+ blocks: i.array(Q).max(20).optional(),
125
132
  contactEmail: i.string().email().optional(),
126
133
  feature_image_id: i.string().trim().min(1).max(2048).nullable().optional(),
127
134
  languageCode: i.string().trim().min(2).max(80).optional(),
@@ -131,8 +138,8 @@ const M = [
131
138
  status: i.enum(["draft", "published", "archived"]).default("draft"),
132
139
  title: i.string().trim().min(1).max(300),
133
140
  translationGroupId: i.string().trim().min(1).max(120).optional()
134
- }), fe = i.strictObject({
135
- blocks: i.array(pe).max(20).optional(),
141
+ }), be = i.strictObject({
142
+ blocks: i.array(Q).max(20).optional(),
136
143
  excerpt: i.string().max(2e3).nullable().optional(),
137
144
  feature_image_id: i.string().trim().min(1).max(2048).nullable().optional(),
138
145
  label: i.string().max(120).nullable().optional(),
@@ -145,10 +152,24 @@ const M = [
145
152
  subtitle: i.string().max(300).nullable().optional(),
146
153
  title: i.string().trim().min(1).max(300),
147
154
  translationGroupId: i.string().trim().min(1).max(120).optional()
148
- }), he = i.strictObject({
155
+ }), ke = i.strictObject({
156
+ // Products render "Product Description Blocks" exactly like pages/posts render
157
+ // their blocks (blocks.product_id). This is the richest body and takes
158
+ // precedence over description_html on the public product page.
159
+ blocks: i.array(Q).max(20).optional().describe(
160
+ "Content blocks for the product description area, same block vocabulary as create_cms_page. Rendered on the public product page in place of the plain description."
161
+ ),
162
+ // Fallback body input. A plain string is something every model can produce
163
+ // under a strict tool schema, unlike the untyped description_json below.
164
+ description_html: i.string().max(6e4).optional().describe(
165
+ "The product body as an HTML fragment (headings, paragraphs, lists, bold/italic/links). Converted to the editor document automatically. Prefer this over description_json."
166
+ ),
149
167
  description_json: i.unknown().optional(),
150
168
  freemius_plan_id: i.string().optional(),
151
169
  freemius_product_id: i.string().optional(),
170
+ images: i.array(i.string().trim().min(1).max(2048)).max(12).optional().describe(
171
+ "Product images, in order: the first becomes the main product image and the rest the gallery. Each entry is either an external https image URL (imported into the media library automatically) or an existing media library id."
172
+ ),
152
173
  is_taxable: i.boolean().default(!0),
153
174
  languageCode: i.string().trim().min(2).max(80).optional(),
154
175
  meta_description: i.string().max(500).nullable().optional(),
@@ -169,51 +190,53 @@ const M = [
169
190
  trial_requires_payment_method: i.boolean().default(!1),
170
191
  translationGroupId: i.string().trim().min(1).max(120).optional(),
171
192
  upc: i.string().max(120).nullable().optional()
172
- }), _e = W.extend({
193
+ }), we = K.extend({
173
194
  currencyCode: i.string().trim().min(3).max(3).optional(),
174
195
  endsAt: i.string().max(80).nullable().optional(),
175
196
  field: i.string().trim().min(1).max(120),
176
197
  startsAt: i.string().max(80).nullable().optional(),
177
198
  value: i.unknown()
178
- }), ct = W, ye = W, ut = i.discriminatedUnion("tool", [
179
- i.strictObject({ input: ge, tool: i.literal("create_cms_page") }),
180
- i.strictObject({ input: fe, tool: i.literal("create_cms_post") }),
181
- i.strictObject({ input: he, tool: i.literal("create_cms_product") }),
182
- i.strictObject({ input: ye, tool: i.literal("delete_cms_item") }),
183
- i.strictObject({ input: _e, tool: i.literal("update_cms_item_field") }),
184
- i.strictObject({ input: ue, tool: i.literal("update_content_block") }),
185
- i.strictObject({ input: me, tool: i.literal("insert_content_block") }),
186
- i.strictObject({ input: ce, tool: i.literal("update_current_cms_fields") }),
187
- i.strictObject({ input: le, tool: i.literal("update_footer") }),
188
- i.strictObject({ input: se, tool: i.literal("update_navigation_bar") }),
189
- i.strictObject({ input: de, tool: i.literal("update_section_column_block") })
190
- ]), Qt = i.union([
191
- ge.extend({ tool: i.literal("create_cms_page") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
192
- fe.extend({ tool: i.literal("create_cms_post") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
193
- he.extend({ tool: i.literal("create_cms_product") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
194
- ye.extend({ tool: i.literal("delete_cms_item") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
195
- _e.extend({ tool: i.literal("update_cms_item_field") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
196
- ue.extend({ tool: i.literal("update_content_block") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
197
- me.extend({ tool: i.literal("insert_content_block") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
198
- ce.extend({ tool: i.literal("update_current_cms_fields") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
199
- le.extend({ tool: i.literal("update_footer") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
200
- se.extend({ tool: i.literal("update_navigation_bar") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
201
- de.extend({ tool: i.literal("update_section_column_block") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e }))
202
- ]), Zt = i.string().transform((e, t) => {
203
- const n = on(e);
199
+ }), yt = K, Ie = K, _t = i.discriminatedUnion("tool", [
200
+ i.strictObject({ input: _e, tool: i.literal("create_cms_page") }),
201
+ i.strictObject({ input: be, tool: i.literal("create_cms_post") }),
202
+ i.strictObject({ input: ke, tool: i.literal("create_cms_product") }),
203
+ i.strictObject({ input: Ie, tool: i.literal("delete_cms_item") }),
204
+ i.strictObject({ input: we, tool: i.literal("update_cms_item_field") }),
205
+ i.strictObject({ input: ge, tool: i.literal("update_content_block") }),
206
+ i.strictObject({ input: ye, tool: i.literal("insert_content_block") }),
207
+ i.strictObject({ input: me, tool: i.literal("update_current_cms_fields") }),
208
+ i.strictObject({ input: pe, tool: i.literal("update_footer") }),
209
+ i.strictObject({ input: de, tool: i.literal("update_navigation_bar") }),
210
+ i.strictObject({ input: fe, tool: i.literal("update_section_column_block") }),
211
+ i.strictObject({ input: he, tool: i.literal("set_content_images") })
212
+ ]), dn = i.union([
213
+ _e.extend({ tool: i.literal("create_cms_page") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
214
+ be.extend({ tool: i.literal("create_cms_post") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
215
+ ke.extend({ tool: i.literal("create_cms_product") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
216
+ Ie.extend({ tool: i.literal("delete_cms_item") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
217
+ we.extend({ tool: i.literal("update_cms_item_field") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
218
+ ge.extend({ tool: i.literal("update_content_block") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
219
+ ye.extend({ tool: i.literal("insert_content_block") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
220
+ me.extend({ tool: i.literal("update_current_cms_fields") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
221
+ pe.extend({ tool: i.literal("update_footer") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
222
+ de.extend({ tool: i.literal("update_navigation_bar") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
223
+ fe.extend({ tool: i.literal("update_section_column_block") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
224
+ he.extend({ tool: i.literal("set_content_images") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e }))
225
+ ]), pn = i.string().transform((e, t) => {
226
+ const n = yn(e);
204
227
  return n.success ? n.action : (t.addIssue({
205
228
  code: "custom",
206
229
  message: n.message
207
230
  }), i.NEVER);
208
- }), en = i.union([
209
- ut,
210
- Qt,
211
- Zt
212
- ]), dt = i.strictObject({
213
- actions: i.array(en).min(1).max(8),
231
+ }), mn = i.union([
232
+ _t,
233
+ dn,
234
+ pn
235
+ ]), bt = i.strictObject({
236
+ actions: i.array(mn).min(1).max(8),
214
237
  summary: i.string().trim().min(1).max(500).optional()
215
238
  });
216
- function tn(e) {
239
+ function gn(e) {
217
240
  const t = [];
218
241
  let n = "", r = 0, o = null, a = !1;
219
242
  for (const s of e) {
@@ -241,7 +264,7 @@ function tn(e) {
241
264
  }
242
265
  return n.trim() && t.push(n.trim()), t;
243
266
  }
244
- function Ve(e) {
267
+ function Xe(e) {
245
268
  let t = "";
246
269
  for (let n = 0; n < e.length; n++) {
247
270
  const r = e[n];
@@ -268,24 +291,24 @@ function Ve(e) {
268
291
  }
269
292
  return t.replace(/\bTrue\b/g, "true").replace(/\bFalse\b/g, "false").replace(/\bNone\b/g, "null");
270
293
  }
271
- function nn(e) {
294
+ function fn(e) {
272
295
  const t = e.trim();
273
- return t.startsWith("'") && t.endsWith("'") || t.startsWith('"') && t.endsWith('"') || t.startsWith("[") || t.startsWith("{") ? JSON.parse(Ve(t)) : /^-?\d+(?:\.\d+)?$/.test(t) ? Number(t) : t === "true" || t === "True" ? !0 : t === "false" || t === "False" ? !1 : t === "null" || t === "None" ? null : t;
296
+ return t.startsWith("'") && t.endsWith("'") || t.startsWith('"') && t.endsWith('"') || t.startsWith("[") || t.startsWith("{") ? JSON.parse(Xe(t)) : /^-?\d+(?:\.\d+)?$/.test(t) ? Number(t) : t === "true" || t === "True" ? !0 : t === "false" || t === "False" ? !1 : t === "null" || t === "None" ? null : t;
274
297
  }
275
- function rn(e) {
298
+ function hn(e) {
276
299
  const t = {};
277
- for (const n of tn(e)) {
300
+ for (const n of gn(e)) {
278
301
  const r = n.indexOf("=");
279
302
  if (r <= 0)
280
303
  throw new Error(`Expected key=value argument, received "${n}".`);
281
304
  const o = n.slice(0, r).trim();
282
305
  if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(o))
283
306
  throw new Error(`Invalid argument name "${o}".`);
284
- t[o] = nn(n.slice(r + 1));
307
+ t[o] = fn(n.slice(r + 1));
285
308
  }
286
309
  return t;
287
310
  }
288
- function on(e) {
311
+ function yn(e) {
289
312
  const n = e.trim().match(/^([a-z_]+)\(([\s\S]*)\)$/);
290
313
  if (!n)
291
314
  return {
@@ -295,14 +318,14 @@ function on(e) {
295
318
  const r = n[1];
296
319
  let o;
297
320
  try {
298
- o = rn(n[2]);
321
+ o = hn(n[2]);
299
322
  } catch (l) {
300
323
  return {
301
324
  message: l instanceof Error ? l.message : "Could not parse action-plan command arguments.",
302
325
  success: !1
303
326
  };
304
327
  }
305
- const a = { input: o, tool: r }, s = ut.safeParse(a);
328
+ const a = { input: o, tool: r }, s = _t.safeParse(a);
306
329
  return s.success ? {
307
330
  action: s.data,
308
331
  success: !0
@@ -311,21 +334,21 @@ function on(e) {
311
334
  success: !1
312
335
  };
313
336
  }
314
- function an(e) {
337
+ function _n(e) {
315
338
  return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, " ").trim();
316
339
  }
317
- function Q(e, t) {
340
+ function ne(e, t) {
318
341
  return t.some((n) => e.includes(n));
319
342
  }
320
- function Dr(e) {
321
- const t = an(e), n = Q(t, ["add ", "insert ", "put ", "create "]), r = Q(t, [
343
+ function ao(e) {
344
+ const t = _n(e), n = ne(t, ["add ", "insert ", "put ", "create "]), r = ne(t, [
322
345
  "title",
323
346
  "heading",
324
347
  "description",
325
348
  "intro",
326
349
  "copy",
327
350
  "paragraph"
328
- ]), o = t.includes("form") && Q(t, ["above", "before"]), a = t.includes("contact page") || t.includes("contact pages") || t.includes("contact us") || t.includes("contactez-nous"), s = t.includes("english") && Q(t, ["french", "francais", "francaise"]);
351
+ ]), o = t.includes("form") && ne(t, ["above", "before"]), a = t.includes("contact page") || t.includes("contact pages") || t.includes("contact us") || t.includes("contactez-nous"), s = t.includes("english") && ne(t, ["french", "francais", "francaise"]);
329
352
  return !n || !r || !o || !a || !s ? null : {
330
353
  actions: [
331
354
  {
@@ -362,12 +385,12 @@ function Dr(e) {
362
385
  summary: "Add visible title and description copy above the forms on the English and French Contact pages."
363
386
  };
364
387
  }
365
- const sn = i.enum(M), He = i.object({
388
+ const bn = i.enum(G), Qe = i.object({
366
389
  direction: i.string().optional(),
367
390
  stops: i.array(i.object({ color: i.string(), position: i.number() })),
368
391
  type: i.enum(["linear", "radial"])
369
- }), ln = i.object({
370
- gradient: He.optional(),
392
+ }), kn = i.object({
393
+ gradient: Qe.optional(),
371
394
  image: i.object({
372
395
  alt_text: i.string().optional(),
373
396
  blur_data_url: i.string().optional(),
@@ -376,7 +399,7 @@ const sn = i.enum(M), He = i.object({
376
399
  media_id: i.string().optional(),
377
400
  object_key: i.string().optional(),
378
401
  overlay: i.object({
379
- gradient: He,
402
+ gradient: Qe,
380
403
  type: i.literal("gradient")
381
404
  }).optional(),
382
405
  position: i.enum(["center", "top", "bottom", "left", "right"]),
@@ -388,13 +411,13 @@ const sn = i.enum(M), He = i.object({
388
411
  solid_color: i.string().optional(),
389
412
  theme: i.enum(["primary", "secondary", "muted", "accent", "destructive"]).optional(),
390
413
  type: i.enum(["none", "theme", "solid", "gradient", "image"])
391
- }), cn = i.object({
392
- block_type: sn,
414
+ }), wn = i.object({
415
+ block_type: bn,
393
416
  content: i.record(i.string(), i.any()),
394
417
  temp_id: i.string().optional()
395
- }), un = i.object({
396
- background: ln,
397
- column_blocks: i.array(i.array(cn)),
418
+ }), In = i.object({
419
+ background: kn,
420
+ column_blocks: i.array(i.array(wn)),
398
421
  column_gap: i.enum(["none", "sm", "md", "lg", "xl"]),
399
422
  container_type: i.enum(["full-width", "container", "container-sm", "container-lg", "container-xl"]),
400
423
  padding: i.object({
@@ -407,7 +430,7 @@ const sn = i.enum(M), He = i.object({
407
430
  tablet: i.union([i.literal(1), i.literal(2), i.literal(3)])
408
431
  }),
409
432
  vertical_alignment: i.enum(["start", "center", "end", "stretch"]).optional()
410
- }), dn = {
433
+ }), Tn = {
411
434
  button: i.object({
412
435
  position: i.enum(["left", "center", "right"]).optional(),
413
436
  size: i.enum(["default", "sm", "lg", "full"]).optional(),
@@ -465,7 +488,7 @@ const sn = i.enum(M), He = i.object({
465
488
  title: i.string().optional(),
466
489
  type: i.enum(["latest", "category"]).default("latest")
467
490
  }),
468
- section: un,
491
+ section: In,
469
492
  testimonial: i.object({
470
493
  author_name: i.string().min(1),
471
494
  author_title: i.string().optional(),
@@ -482,17 +505,17 @@ const sn = i.enum(M), He = i.object({
482
505
  url: i.string()
483
506
  })
484
507
  };
485
- function pn(e) {
486
- return M.includes(e);
508
+ function xn(e) {
509
+ return G.includes(e);
487
510
  }
488
- function mn(e) {
511
+ function Cn(e) {
489
512
  return typeof e?.validateBlockContent == "function" ? e.validateBlockContent : null;
490
513
  }
491
- function gn(e, t, n) {
492
- const r = mn(n);
514
+ function vn(e, t, n) {
515
+ const r = Cn(n);
493
516
  if (r)
494
517
  return r(e, t);
495
- const o = dn[e].safeParse(t);
518
+ const o = Tn[e].safeParse(t);
496
519
  return o.success ? { errors: [], isValid: !0, warnings: [] } : {
497
520
  errors: o.error.issues.map((a) => {
498
521
  const s = a.path.join(".");
@@ -502,13 +525,13 @@ function gn(e, t, n) {
502
525
  warnings: []
503
526
  };
504
527
  }
505
- function fn() {
528
+ function Ze() {
506
529
  return i.object({
507
530
  content: i.array(i.any()).optional(),
508
531
  type: i.literal("doc")
509
532
  });
510
533
  }
511
- function Ne() {
534
+ function je() {
512
535
  try {
513
536
  const { revalidatePath: e } = require("next/cache");
514
537
  return e;
@@ -516,12 +539,12 @@ function Ne() {
516
539
  return null;
517
540
  }
518
541
  }
519
- function I(e) {
542
+ function T(e) {
520
543
  if (!e?.supabase)
521
544
  throw new Error("A Supabase service client is required to execute Cortex AI global tools.");
522
545
  return e.supabase;
523
546
  }
524
- function hn(e, t, n) {
547
+ function Sn(e, t, n) {
525
548
  let r;
526
549
  const o = new Promise((a) => {
527
550
  r = setTimeout(() => a(n()), t);
@@ -533,38 +556,38 @@ function hn(e, t, n) {
533
556
  o
534
557
  ]);
535
558
  }
536
- function D(e) {
537
- const t = st.safeParse(e?.pageContext);
559
+ function H(e) {
560
+ const t = ft.safeParse(e?.pageContext);
538
561
  if (!t.success)
539
562
  throw new Error(
540
563
  "No current CMS page context is available. Open a page, post, or product edit screen before using this editing tool."
541
564
  );
542
565
  return t.data;
543
566
  }
544
- function Ue(e) {
567
+ function Le(e) {
545
568
  const t = typeof e.entityId == "number" ? e.entityId : Number.parseInt(e.entityId, 10);
546
569
  if (!Number.isInteger(t) || t <= 0)
547
570
  throw new Error(`Current ${e.contentType} id must be a positive integer.`);
548
571
  return t;
549
572
  }
550
- function _n(e) {
573
+ function kt(e) {
551
574
  const t = String(e.entityId || "").trim();
552
575
  if (!t)
553
576
  throw new Error(`Current ${e.contentType} id is missing.`);
554
577
  return t;
555
578
  }
556
- function be(e) {
557
- return e.contentType === "product" ? _n(e) : Ue(e);
579
+ function Te(e) {
580
+ return e.contentType === "product" ? kt(e) : Le(e);
558
581
  }
559
- const yn = /^https?:\/\//i, bn = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
560
- async function J(e, t, n) {
582
+ const En = /^https?:\/\//i, $n = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
583
+ async function Z(e, t, n) {
561
584
  if (typeof e != "string")
562
585
  return null;
563
586
  const r = e.trim();
564
587
  if (!r)
565
588
  return null;
566
- if (!yn.test(r)) {
567
- if (bn.test(r))
589
+ if (!En.test(r)) {
590
+ if ($n.test(r))
568
591
  return r;
569
592
  throw new Error(
570
593
  `"${r}" is not a usable image reference — provide an https:// image URL or a media library id.`
@@ -580,54 +603,85 @@ async function J(e, t, n) {
580
603
  throw new Error(`I could not import the image from that URL: ${a.error}`);
581
604
  return a.id;
582
605
  }
583
- function pt(e) {
606
+ async function wt(e, t, n) {
607
+ const r = [];
608
+ for (let o = 0; o < e.length; o += 1) {
609
+ const a = await Z(
610
+ e[o],
611
+ t,
612
+ `${n} image ${o + 1}`
613
+ );
614
+ a && r.push(a);
615
+ }
616
+ return r;
617
+ }
618
+ async function An(e) {
619
+ const t = [...new Set(e.mediaIds)], { error: n } = await e.supabase.from("product_media").delete().eq("product_id", e.productId);
620
+ if (n)
621
+ throw new Error(
622
+ `Could not clear the product's existing images: ${_(n)}`
623
+ );
624
+ if (t.length > 0) {
625
+ const { error: r } = await e.supabase.from("product_media").insert(
626
+ t.map((o, a) => ({
627
+ media_id: o,
628
+ product_id: e.productId,
629
+ sort_order: a
630
+ }))
631
+ );
632
+ if (r)
633
+ throw new Error(`Could not save the product images: ${_(r)}`);
634
+ }
635
+ return t;
636
+ }
637
+ function It(e) {
584
638
  return typeof e == "string" ? e.trim().replace(/^\/+|\/+$/g, "") : "";
585
639
  }
586
- function kn(e, t) {
587
- const n = pt(t ?? e.slug);
640
+ function Pn(e, t) {
641
+ const n = It(t ?? e.slug);
588
642
  return n ? e.contentType === "page" ? n === "home" ? "/" : `/${n}` : e.contentType === "post" ? `/article/${n}` : `/product/${n}` : null;
589
643
  }
590
- function wn(e) {
644
+ function Nn(e) {
591
645
  const t = String(e.entityId);
592
646
  return e.contentType === "page" ? `/cms/pages/${t}/edit` : e.contentType === "post" ? `/cms/posts/${t}/edit` : `/cms/products/${t}/edit`;
593
647
  }
594
- function N(e, t, n) {
595
- const r = e?.revalidatePath ?? Ne();
648
+ function U(e, t, n) {
649
+ const r = e?.revalidatePath ?? je();
596
650
  if (!r)
597
651
  return;
598
- r(wn(t));
599
- const o = kn(t, n);
652
+ r(Nn(t));
653
+ const o = Pn(t, n);
600
654
  o && r(o), t.contentType === "page" && o !== "/" && r("/"), t.contentType === "product" && r("/cms/products");
601
655
  }
602
- function mt(e) {
603
- const t = e?.revalidatePath ?? Ne();
656
+ function Tt(e) {
657
+ const t = e?.revalidatePath ?? je();
604
658
  t && (t("/", "layout"), t("/cms/navigation"));
605
659
  }
606
- function h(e) {
660
+ function _(e) {
607
661
  return e ? typeof e == "object" && "message" in e ? String(e.message || "Unknown database error.") : String(e) : "Unknown database error.";
608
662
  }
609
- async function In() {
663
+ async function Un() {
610
664
  return import("./ai-global-agent-ecommerce.es.js");
611
665
  }
612
- function Te(e) {
613
- return e === null || typeof e != "object" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((t) => Te(t)).join(",")}]` : `{${Object.keys(e).filter((t) => t !== "temp_id").sort().map((t) => `${JSON.stringify(t)}:${Te(e[t])}`).join(",")}}`;
666
+ function Se(e) {
667
+ return e === null || typeof e != "object" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((t) => Se(t)).join(",")}]` : `{${Object.keys(e).filter((t) => t !== "temp_id").sort().map((t) => `${JSON.stringify(t)}:${Se(e[t])}`).join(",")}}`;
614
668
  }
615
- function Tn(e) {
669
+ function On(e) {
616
670
  let t = 2166136261;
617
- const n = Te(e);
671
+ const n = Se(e);
618
672
  for (let r = 0; r < n.length; r++)
619
673
  t ^= n.charCodeAt(r), t = Math.imul(t, 16777619);
620
674
  return (t >>> 0).toString(16).padStart(8, "0");
621
675
  }
622
- function xe(e) {
676
+ function Ee(e) {
623
677
  return e.replace(/\s+/g, " ").trim().toUpperCase();
624
678
  }
625
- function xn(e, t, n) {
626
- return `${xe(`CONFIRM ${e} ${t}`)} #${Tn(n)}`;
679
+ function Fn(e, t, n) {
680
+ return `${Ee(`CONFIRM ${e} ${t}`)} #${On(n)}`;
627
681
  }
628
- function gt(e) {
682
+ function xt(e) {
629
683
  return {
630
- confirmationPhrase: xn(
684
+ confirmationPhrase: Fn(
631
685
  e.action,
632
686
  e.subject,
633
687
  e.payload
@@ -638,58 +692,63 @@ function gt(e) {
638
692
  success: !0
639
693
  };
640
694
  }
641
- function U(e, t) {
695
+ function O(e, t) {
642
696
  const n = e[t];
643
697
  return typeof n == "string" && n.trim() ? n.trim() : null;
644
698
  }
645
- function Z(e, t) {
699
+ function M(e, t) {
646
700
  const n = Number(e[t]);
647
701
  return Number.isFinite(n) ? n : null;
648
702
  }
649
- function F(e, t, n = `${t}s`) {
703
+ function N(e, t, n = `${t}s`) {
650
704
  return `${e} ${e === 1 ? t : n}`;
651
705
  }
652
- function Cn(e, t) {
653
- const n = U(t, "summary");
706
+ function jn(e, t) {
707
+ const n = O(t, "summary");
654
708
  if (n)
655
709
  return n;
656
- const r = U(t, "title"), o = U(t, "slug"), a = U(t, "status"), s = U(t, "contentType"), l = U(t, "field"), u = U(t, "mode"), d = U(t, "languageCode"), c = Z(t, "blockCount"), p = Z(t, "itemCount"), g = Z(t, "affectedCount");
710
+ const r = O(t, "title"), o = O(t, "slug"), a = O(t, "status"), s = O(t, "contentType"), l = O(t, "field"), u = O(t, "mode"), d = O(t, "languageCode"), c = M(t, "blockCount"), p = M(t, "itemCount"), h = M(t, "affectedCount");
657
711
  if (e === "create_cms_page" || e === "create_cms_post")
658
- return `Create ${a || "draft"} ${e === "create_cms_page" ? "page" : "post"} "${r || o || "Untitled"}"${o ? ` at slug "${o}"` : ""}${c !== null ? ` with ${F(c, "content block")}` : ""}.`;
659
- if (e === "create_cms_product")
660
- return `Create ${a || "draft"} product "${r || o || "Untitled"}"${o ? ` at slug "${o}"` : ""}.`;
712
+ return `Create ${a || "draft"} ${e === "create_cms_page" ? "page" : "post"} "${r || o || "Untitled"}"${o ? ` at slug "${o}"` : ""}${c !== null ? ` with ${N(c, "content block")}` : ""}.`;
713
+ if (e === "create_cms_product") {
714
+ const m = M(t, "imageCount"), g = M(t, "blockCount"), f = [
715
+ m ? N(m, "image") : null,
716
+ g ? N(g, "description block") : M(t, "descriptionLength") ? "a full description" : null
717
+ ].filter(Boolean);
718
+ return `Create ${a || "draft"} product "${r || o || "Untitled"}"${o ? ` at slug "${o}"` : ""}${f.length ? ` with ${f.join(" and ")}` : ""}.`;
719
+ }
661
720
  if (e === "update_cms_item_field")
662
721
  return `Update ${l || "one field"} on the ${s || "CMS item"} "${r || o || "selected item"}".`;
663
722
  if (e === "update_navigation_bar")
664
- return `${u === "append" ? "Add" : u === "update" ? "Update" : "Replace"} ${p !== null ? F(p, "navigation item") : "navigation items"} in the ${d || "selected"} header navigation.`;
723
+ return `${u === "append" ? "Add" : u === "update" ? "Update" : "Replace"} ${p !== null ? N(p, "navigation item") : "navigation items"} in the ${d || "selected"} header navigation.`;
665
724
  if (e === "update_footer") {
666
- const m = Z(t, "linkCount");
667
- return `Update the ${d || "selected"} footer${m !== null ? ` with ${F(m, "link")}` : ""}.`;
725
+ const m = M(t, "linkCount");
726
+ return `Update the ${d || "selected"} footer${m !== null ? ` with ${N(m, "link")}` : ""}.`;
668
727
  }
669
- return e === "update_content_block" ? `Update the selected ${U(t, "blockType") || "content"} block.` : e === "insert_content_block" ? `Insert ${U(t, "blockType") || "content"} block on the ${s || "CMS item"} "${r || o || "selected item"}".` : e === "update_section_column_block" ? `Update the selected nested ${U(t, "nestedBlockType") || "section"} block.` : e === "delete_cms_item" || e === "prepare_delete_cms_item" ? `Delete ${g !== null ? F(g, s || "CMS item") : `the selected ${s || "CMS item"}`}${r || o ? ` for "${r || o}"` : ""}.` : "Complete the requested CMS change.";
728
+ return e === "update_content_block" ? `Update the selected ${O(t, "blockType") || "content"} block.` : e === "insert_content_block" ? `Insert ${O(t, "blockType") || "content"} block on the ${s || "CMS item"} "${r || o || "selected item"}".` : e === "update_section_column_block" ? `Update the selected nested ${O(t, "nestedBlockType") || "section"} block.` : e === "delete_cms_item" || e === "prepare_delete_cms_item" ? `Delete ${h !== null ? N(h, s || "CMS item") : `the selected ${s || "CMS item"}`}${r || o ? ` for "${r || o}"` : ""}.` : "Complete the requested CMS change.";
670
729
  }
671
730
  function P(e) {
672
731
  if (e.context?.skipConfirmation)
673
732
  return null;
674
- const t = gt(e), n = xe(e.context?.latestUserMessage || ""), r = xe(t.confirmationPhrase);
733
+ const t = xt(e), n = Ee(e.context?.latestUserMessage || ""), r = Ee(t.confirmationPhrase);
675
734
  return n.includes(r) ? null : t;
676
735
  }
677
- function Fe(e) {
736
+ function Be(e) {
678
737
  const t = e?.actorUserId;
679
738
  if (!t)
680
739
  throw new Error("A confirmed CMS mutation requires an authenticated admin actor.");
681
740
  return t;
682
741
  }
683
- function Oe() {
742
+ function Re() {
684
743
  return globalThis.crypto?.randomUUID?.() || `id-${Date.now()}-${Math.random().toString(36).slice(2)}`;
685
744
  }
686
- function Y(e) {
745
+ function R(e) {
687
746
  return e.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 300);
688
747
  }
689
- function je(e) {
748
+ function qe(e) {
690
749
  return (e || "USD").trim().toUpperCase();
691
750
  }
692
- const vn = /* @__PURE__ */ new Set([
751
+ const Ln = /* @__PURE__ */ new Set([
693
752
  "BIF",
694
753
  "CLP",
695
754
  "DJF",
@@ -707,128 +766,131 @@ const vn = /* @__PURE__ */ new Set([
707
766
  "XOF",
708
767
  "XPF"
709
768
  ]);
710
- function Sn(e) {
711
- return vn.has(je(e)) ? 0 : 2;
769
+ function Bn(e) {
770
+ return Ln.has(qe(e)) ? 0 : 2;
712
771
  }
713
- function ft(e, t) {
714
- return Math.round(e * 10 ** Sn(t));
772
+ function Ct(e, t) {
773
+ return Math.round(e * 10 ** Bn(t));
715
774
  }
716
- function En(e, t) {
775
+ function Rn(e, t) {
717
776
  return !e || typeof e != "object" || Array.isArray(e) ? {} : Object.entries(e).reduce(
718
777
  (n, [r, o]) => {
719
778
  if (typeof o == "number" && Number.isFinite(o) && o >= 0) {
720
- const a = je(r || t);
721
- n[a] = ft(o, a);
779
+ const a = qe(r || t);
780
+ n[a] = Ct(o, a);
722
781
  }
723
782
  return n;
724
783
  },
725
784
  {}
726
785
  );
727
786
  }
728
- function X(e, t) {
787
+ function ee(e, t) {
729
788
  if (!A(e))
730
789
  throw new Error(`${t} content must be a JSON object.`);
731
790
  return JSON.parse(JSON.stringify(e));
732
791
  }
733
- function H(e) {
792
+ function X(e) {
734
793
  return JSON.parse(JSON.stringify(e));
735
794
  }
736
795
  function A(e) {
737
796
  return !!(e && typeof e == "object" && !Array.isArray(e));
738
797
  }
739
- function Ce(e, t) {
740
- const n = H(e);
798
+ function $e(e, t) {
799
+ const n = X(e);
741
800
  for (const [r, o] of Object.entries(t))
742
801
  if (o !== void 0) {
743
802
  if (A(o) && A(n[r])) {
744
- n[r] = Ce(n[r], o);
803
+ n[r] = $e(n[r], o);
745
804
  continue;
746
805
  }
747
- n[r] = H(o);
806
+ n[r] = X(o);
748
807
  }
749
808
  return n;
750
809
  }
751
- function ht(e, t) {
752
- if (t.contentType === "product")
753
- throw new Error("Products do not have page/post content blocks in this editor context.");
754
- const n = Ue(t);
810
+ function vt(e, t) {
811
+ if (t.contentType === "product") {
812
+ if (String(e.product_id ?? "") !== String(kt(t)))
813
+ throw new Error(`Block ${e.id} does not belong to the current product being edited.`);
814
+ return;
815
+ }
816
+ const n = Le(t);
755
817
  if ((t.contentType === "page" ? Number(e.page_id) : Number(e.post_id)) !== n)
756
818
  throw new Error(
757
819
  `Block ${e.id} does not belong to the current ${t.contentType} being edited.`
758
820
  );
759
821
  }
760
- function re(e, t) {
822
+ function ae(e, t) {
761
823
  const n = typeof e == "string" ? e : "";
762
- if (!pn(n))
824
+ if (!xn(n))
763
825
  throw new Error(`${t} has unsupported block type "${n || "unknown"}".`);
764
826
  return n;
765
827
  }
766
- function _t(e, t, n) {
828
+ function St(e, t, n) {
767
829
  if (e && e !== t)
768
830
  throw new Error(
769
831
  `${n} is a "${t}" block. Refusing to update it as "${e}".`
770
832
  );
771
833
  }
772
- function L(e, t, n, r) {
773
- const o = gn(e, t, r);
834
+ function D(e, t, n, r) {
835
+ const o = vn(e, t, r);
774
836
  if (!o.isValid)
775
837
  throw new Error(
776
838
  `${n} content is invalid for block type "${e}": ${o.errors.join("; ")}`
777
839
  );
778
840
  }
779
- function yt(e) {
841
+ function Et(e) {
780
842
  return e === "section";
781
843
  }
782
- function $n(e) {
844
+ function qn(e) {
783
845
  return typeof e.html_content == "string" ? "text" : typeof e.text == "string" && typeof e.url == "string" ? "button" : typeof e.text_content == "string" ? "heading" : "media_id" in e || "object_key" in e || "external_url" in e ? "image" : typeof e.quote == "string" && typeof e.author_name == "string" ? "testimonial" : typeof e.url == "string" && ("controls" in e || "autoplay" in e || "title" in e) ? "video_embed" : Array.isArray(e.fields) || typeof e.recipient_email == "string" ? "form" : "postsPerPage" in e || "showPagination" in e ? "posts_grid" : typeof e.productId == "string" ? "featured_product" : "limit" in e && "type" in e ? "product_grid" : null;
784
846
  }
785
- function oe(e) {
847
+ function se(e) {
786
848
  return `ai-${e}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
787
849
  }
788
- function ve(e, t, n) {
850
+ function Ae(e, t, n) {
789
851
  if (!A(e))
790
852
  throw new Error(`${t} must be a JSON object.`);
791
- const r = e.block_type ?? e.blockType, o = re(r, t);
792
- if (yt(o))
853
+ const r = e.block_type ?? e.blockType, o = ae(r, t);
854
+ if (Et(o))
793
855
  throw new Error(`${t} cannot be a nested ${o} block.`);
794
- const a = It(
856
+ const a = Nt(
795
857
  o,
796
- X(e.content, t),
858
+ ee(e.content, t),
797
859
  t,
798
860
  n
799
- ), s = e.temp_id ?? e.tempId, l = typeof s == "string" && s.trim() ? s : oe(o);
861
+ ), s = e.temp_id ?? e.tempId, l = typeof s == "string" && s.trim() ? s : se(o);
800
862
  return {
801
863
  block_type: o,
802
864
  content: a,
803
865
  temp_id: l
804
866
  };
805
867
  }
806
- function An(e, t) {
868
+ function Mn(e, t) {
807
869
  const n = [];
808
- if ("append_block" in e && n.push(ve(e.append_block, "Nested block to append", t)), "append_blocks" in e) {
870
+ if ("append_block" in e && n.push(Ae(e.append_block, "Nested block to append", t)), "append_blocks" in e) {
809
871
  const r = e.append_blocks;
810
872
  if (!Array.isArray(r))
811
873
  throw new Error("append_blocks must be an array of nested block objects.");
812
874
  r.forEach((o, a) => {
813
- n.push(ve(o, `Nested block to append ${a}`, t));
875
+ n.push(Ae(o, `Nested block to append ${a}`, t));
814
876
  });
815
877
  }
816
878
  return n;
817
879
  }
818
- function Pn(e, t) {
880
+ function Dn(e, t) {
819
881
  if ("append_block" in e || "append_blocks" in e || "background" in e || "column_blocks" in e || "column_gap" in e || "container_type" in e || "padding" in e || "responsive_columns" in e || "vertical_alignment" in e)
820
882
  return null;
821
- const n = $n(e);
883
+ const n = qn(e);
822
884
  if (!n)
823
885
  return null;
824
- const r = X(e, `Nested ${n} block`);
825
- return L(n, r, `Nested ${n} block`, t), {
886
+ const r = ee(e, `Nested ${n} block`);
887
+ return D(n, r, `Nested ${n} block`, t), {
826
888
  block_type: n,
827
889
  content: r,
828
- temp_id: oe(n)
890
+ temp_id: se(n)
829
891
  };
830
892
  }
831
- function Nn(e, t) {
893
+ function zn(e, t) {
832
894
  const n = e.append_column_index ?? e.column_index;
833
895
  if (n === void 0)
834
896
  return 0;
@@ -840,14 +902,14 @@ function Nn(e, t) {
840
902
  );
841
903
  return n;
842
904
  }
843
- function Un(e, t, n, r) {
844
- if (!yt(e))
845
- return Ce(t, n);
846
- const o = { ...n }, a = An(o, r), s = Pn(o, r);
905
+ function Gn(e, t, n, r) {
906
+ if (!Et(e))
907
+ return $e(t, n);
908
+ const o = { ...n }, a = Mn(o, r), s = Dn(o, r);
847
909
  s && a.push(s), delete o.append_block, delete o.append_blocks, delete o.append_column_index, delete o.column_index;
848
- const l = Ce(t, o);
910
+ const l = $e(t, o);
849
911
  if (a.length > 0) {
850
- const u = Array.isArray(t.column_blocks) ? H(t.column_blocks) : [], d = Nn(n, u.length), c = u.length > 0 ? u : [[]];
912
+ const u = Array.isArray(t.column_blocks) ? X(t.column_blocks) : [], d = zn(n, u.length), c = u.length > 0 ? u : [[]];
851
913
  for (; c.length <= d; )
852
914
  c.push([]);
853
915
  c[d] = [
@@ -857,7 +919,7 @@ function Un(e, t, n, r) {
857
919
  }
858
920
  return l;
859
921
  }
860
- function Fn(e, t) {
922
+ function Kn(e, t) {
861
923
  return {
862
924
  blockType: e.block_type,
863
925
  content: t ? e.content : void 0,
@@ -868,25 +930,25 @@ function Fn(e, t) {
868
930
  postId: e.post_id
869
931
  };
870
932
  }
871
- function R(e) {
933
+ function z(e) {
872
934
  return typeof e == "string" ? e.trim().toLowerCase() : "";
873
935
  }
874
- function We(e) {
936
+ function et(e) {
875
937
  return typeof e == "string" ? e.trim().toLowerCase() : "";
876
938
  }
877
- function bt(e) {
939
+ function $t(e) {
878
940
  return e.reduce((t, n) => t + 1 + (n.children?.length || 0), 0);
879
941
  }
880
- function ne(e) {
942
+ function ie(e) {
881
943
  return typeof e == "string" ? e.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "") : "";
882
944
  }
883
- async function G(e, t) {
884
- const n = t.trim(), r = ne(n), o = Jt[r], { data: a, error: s } = await e.from("languages").select("id, code, name, is_active");
945
+ async function V(e, t) {
946
+ const n = t.trim(), r = ie(n), o = ln[r], { data: a, error: s } = await e.from("languages").select("id, code, name, is_active");
885
947
  if (s)
886
- throw new Error(`Failed to load language "${t}": ${h(s)}`);
948
+ throw new Error(`Failed to load language "${t}": ${_(s)}`);
887
949
  const u = (Array.isArray(a) ? a : []).filter((c) => c.is_active !== !1), d = u.find((c) => {
888
- const p = ne(c.code), g = ne(c.name);
889
- return p === r || p === o || g === r;
950
+ const p = ie(c.code), h = ie(c.name);
951
+ return p === r || p === o || h === r;
890
952
  });
891
953
  if (!d?.id || !d?.code) {
892
954
  const c = u.map((p) => p.code).filter(Boolean).join(", ");
@@ -899,15 +961,15 @@ async function G(e, t) {
899
961
  id: Number(d.id)
900
962
  };
901
963
  }
902
- async function ke(e, t) {
964
+ async function xe(e, t) {
903
965
  if (t)
904
- return G(e, t);
966
+ return V(e, t);
905
967
  const { data: n, error: r } = await e.from("languages").select("id, code, name, is_active, is_default");
906
968
  if (r)
907
- throw new Error(`Failed to load active languages: ${h(r)}`);
969
+ throw new Error(`Failed to load active languages: ${_(r)}`);
908
970
  const o = (Array.isArray(n) ? n : []).filter(
909
971
  (s) => s.is_active !== !1
910
- ), a = o.find((s) => s.is_default) || o.find((s) => ne(s.code) === "en") || o[0];
972
+ ), a = o.find((s) => s.is_default) || o.find((s) => ie(s.code) === "en") || o[0];
911
973
  if (!a?.id || !a?.code)
912
974
  throw new Error("No active CMS language is available for Cortex AI content creation.");
913
975
  return {
@@ -915,25 +977,25 @@ async function ke(e, t) {
915
977
  id: Number(a.id)
916
978
  };
917
979
  }
918
- async function Je(e) {
980
+ async function tt(e) {
919
981
  try {
920
982
  const { data: t, error: n } = await e.from("currencies").select("code, is_default, is_active").eq("is_active", !0);
921
983
  if (n)
922
984
  return "USD";
923
985
  const r = Array.isArray(t) ? t : [], o = r.find((a) => a.is_default) || r[0];
924
- return je(o?.code || "USD");
986
+ return qe(o?.code || "USD");
925
987
  } catch {
926
988
  return "USD";
927
989
  }
928
990
  }
929
- async function On(e) {
991
+ async function Hn(e) {
930
992
  const t = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products";
931
993
  let n = "id", r = e.entityId;
932
994
  if (r === void 0 && e.slug && (n = "slug", r = e.slug), r === void 0 && e.title && (n = "title", r = e.title), r === void 0)
933
995
  throw new Error(`A ${e.contentType} target requires an id, slug, title, or current edit context.`);
934
996
  const { data: o, error: a } = await e.supabase.from(t).select("*").eq(n, r);
935
997
  if (a)
936
- throw new Error(`Failed to resolve ${e.contentType}: ${h(a)}`);
998
+ throw new Error(`Failed to resolve ${e.contentType}: ${_(a)}`);
937
999
  const s = Array.isArray(o) ? o : o ? [o] : [];
938
1000
  if (s.length !== 1)
939
1001
  throw new Error(
@@ -941,15 +1003,15 @@ async function On(e) {
941
1003
  );
942
1004
  return s[0];
943
1005
  }
944
- async function we(e, t) {
945
- const n = st.safeParse(t?.pageContext).success ? t?.pageContext : null, r = e.contentType || n?.contentType;
1006
+ async function te(e, t) {
1007
+ const n = ft.safeParse(t?.pageContext).success ? t?.pageContext : null, r = e.contentType || n?.contentType;
946
1008
  if (!r)
947
1009
  throw new Error("Target contentType is required when no current CMS edit context exists.");
948
- const o = e.entityId !== void 0 || !!e.slug || !!e.title, a = e.entityId ?? (o ? void 0 : n?.entityId), s = e.slug ?? (o ? void 0 : n?.slug ?? void 0), l = e.title ?? (o ? void 0 : n?.title ?? void 0), u = await On({
1010
+ const o = e.entityId !== void 0 || !!e.slug || !!e.title, a = e.entityId ?? (o ? void 0 : n?.entityId), s = e.slug ?? (o ? void 0 : n?.slug ?? void 0), l = e.title ?? (o ? void 0 : n?.title ?? void 0), u = await Hn({
949
1011
  contentType: r,
950
1012
  entityId: a,
951
1013
  slug: a === void 0 && s || void 0,
952
- supabase: I(t),
1014
+ supabase: T(t),
953
1015
  title: a === void 0 && !s && l || void 0
954
1016
  });
955
1017
  return {
@@ -957,8 +1019,8 @@ async function we(e, t) {
957
1019
  item: u
958
1020
  };
959
1021
  }
960
- async function ie(e) {
961
- const t = await qn({
1022
+ async function le(e) {
1023
+ const t = await Jn({
962
1024
  item: e.item,
963
1025
  languageId: e.languageId,
964
1026
  menuKey: e.menuKey,
@@ -974,41 +1036,41 @@ async function ie(e) {
974
1036
  url: e.item.url
975
1037
  }, { data: r, error: o } = await e.supabase.from("navigation_items").insert(n).select("id").single();
976
1038
  if (o)
977
- throw new Error(`Failed to insert ${e.menuKey} navigation item: ${h(o)}`);
1039
+ throw new Error(`Failed to insert ${e.menuKey} navigation item: ${_(o)}`);
978
1040
  return Number(r.id);
979
1041
  }
980
- function jn(e) {
1042
+ function Vn(e) {
981
1043
  const t = e.trim();
982
1044
  if (!t.startsWith("/") || t.startsWith("//"))
983
1045
  return null;
984
1046
  const n = t.split("?")[0]?.split("#")[0] || "", r = n === "/" ? "home" : n.replace(/^\/+|\/+$/g, "");
985
1047
  return r && !r.includes("/") ? r : null;
986
1048
  }
987
- async function qn(e) {
988
- const t = jn(e.item.url);
1049
+ async function Jn(e) {
1050
+ const t = Vn(e.item.url);
989
1051
  if (!t)
990
1052
  return null;
991
1053
  const { data: n, error: r } = await e.supabase.from("pages").select("id, slug, translation_group_id, language_id").eq("slug", t).eq("language_id", e.languageId);
992
1054
  if (r)
993
- throw new Error(`Failed to resolve linked page for navigation item: ${h(r)}`);
1055
+ throw new Error(`Failed to resolve linked page for navigation item: ${_(r)}`);
994
1056
  const o = Array.isArray(n) ? n[0] : n;
995
1057
  if (!o?.id)
996
1058
  return null;
997
- let a = Oe();
1059
+ let a = Re();
998
1060
  if (o.translation_group_id) {
999
1061
  const { data: s, error: l } = await e.supabase.from("pages").select("id").eq("translation_group_id", o.translation_group_id);
1000
1062
  if (l)
1001
1063
  throw new Error(
1002
- `Failed to inspect linked page translations for navigation item: ${h(l)}`
1064
+ `Failed to inspect linked page translations for navigation item: ${_(l)}`
1003
1065
  );
1004
1066
  const u = new Set(
1005
- (Array.isArray(s) ? s : []).map((g) => String(g.id)).filter(Boolean)
1067
+ (Array.isArray(s) ? s : []).map((h) => String(h.id)).filter(Boolean)
1006
1068
  ), { data: d, error: c } = await e.supabase.from("navigation_items").select("id, page_id, translation_group_id, menu_key").eq("menu_key", e.menuKey);
1007
1069
  if (c)
1008
1070
  throw new Error(
1009
- `Failed to inspect related navigation translations: ${h(c)}`
1071
+ `Failed to inspect related navigation translations: ${_(c)}`
1010
1072
  );
1011
- const p = (Array.isArray(d) ? d : []).find((g) => g.translation_group_id && u.has(String(g.page_id)));
1073
+ const p = (Array.isArray(d) ? d : []).find((h) => h.translation_group_id && u.has(String(h.page_id)));
1012
1074
  p?.translation_group_id && (a = p.translation_group_id);
1013
1075
  }
1014
1076
  return {
@@ -1016,14 +1078,14 @@ async function qn(e) {
1016
1078
  pageId: Number(o.id)
1017
1079
  };
1018
1080
  }
1019
- async function kt(e) {
1020
- const t = await G(e.supabase, e.languageCode), { data: n, error: r } = await e.supabase.from("navigation_items").select("id, parent_id").eq("menu_key", e.menuKey).eq("language_id", t.id);
1081
+ async function At(e) {
1082
+ const t = await V(e.supabase, e.languageCode), { data: n, error: r } = await e.supabase.from("navigation_items").select("id, parent_id").eq("menu_key", e.menuKey).eq("language_id", t.id);
1021
1083
  if (r)
1022
1084
  throw new Error(
1023
- `Failed to inspect existing ${e.menuKey} navigation items: ${h(r)}`
1085
+ `Failed to inspect existing ${e.menuKey} navigation items: ${_(r)}`
1024
1086
  );
1025
- const o = Array.isArray(n) ? n : [], a = o.filter((d) => d.parent_id == null).length, s = bt(e.items);
1026
- wt({
1087
+ const o = Array.isArray(n) ? n : [], a = o.filter((d) => d.parent_id == null).length, s = $t(e.items);
1088
+ Pt({
1027
1089
  existingItemCount: o.length,
1028
1090
  existingTopLevelCount: a,
1029
1091
  languageCode: t.code,
@@ -1032,10 +1094,10 @@ async function kt(e) {
1032
1094
  });
1033
1095
  const { error: l } = await e.supabase.from("navigation_items").delete().eq("menu_key", e.menuKey).eq("language_id", t.id);
1034
1096
  if (l)
1035
- throw new Error(`Failed to clear ${e.menuKey} navigation items: ${h(l)}`);
1097
+ throw new Error(`Failed to clear ${e.menuKey} navigation items: ${_(l)}`);
1036
1098
  let u = 0;
1037
1099
  for (const [d, c] of e.items.entries()) {
1038
- const p = await ie({
1100
+ const p = await le({
1039
1101
  item: c,
1040
1102
  languageId: t.id,
1041
1103
  menuKey: e.menuKey,
@@ -1043,12 +1105,12 @@ async function kt(e) {
1043
1105
  supabase: e.supabase
1044
1106
  });
1045
1107
  u++;
1046
- for (const [g, m] of (c.children ?? []).entries())
1047
- await ie({
1108
+ for (const [h, m] of (c.children ?? []).entries())
1109
+ await le({
1048
1110
  item: m,
1049
1111
  languageId: t.id,
1050
1112
  menuKey: e.menuKey,
1051
- order: g,
1113
+ order: h,
1052
1114
  parentId: p,
1053
1115
  supabase: e.supabase
1054
1116
  }), u++;
@@ -1061,38 +1123,38 @@ async function kt(e) {
1061
1123
  updatedCount: 0
1062
1124
  };
1063
1125
  }
1064
- function wt(e) {
1126
+ function Pt(e) {
1065
1127
  if (!(e.existingItemCount === 0 || e.replacementItemCount >= e.existingItemCount))
1066
1128
  throw new Error(
1067
1129
  `Refusing destructive ${e.menuKey} navigation replacement for ${e.languageCode}: existing menu has ${e.existingItemCount} items (${e.existingTopLevelCount} top-level), but the replacement only contains ${e.replacementItemCount}. Use mode "update" for renaming or changing a single link, or provide the full menu.`
1068
1130
  );
1069
1131
  }
1070
- async function Bn(e) {
1071
- const t = await G(e.supabase, e.languageCode), { data: n, error: r } = await e.supabase.from("navigation_items").select("id, parent_id").eq("menu_key", e.menuKey).eq("language_id", t.id);
1132
+ async function Wn(e) {
1133
+ const t = await V(e.supabase, e.languageCode), { data: n, error: r } = await e.supabase.from("navigation_items").select("id, parent_id").eq("menu_key", e.menuKey).eq("language_id", t.id);
1072
1134
  if (r)
1073
1135
  throw new Error(
1074
- `Failed to inspect existing ${e.menuKey} navigation items: ${h(r)}`
1136
+ `Failed to inspect existing ${e.menuKey} navigation items: ${_(r)}`
1075
1137
  );
1076
1138
  const o = Array.isArray(n) ? n : [];
1077
- wt({
1139
+ Pt({
1078
1140
  existingItemCount: o.length,
1079
1141
  existingTopLevelCount: o.filter((a) => a.parent_id == null).length,
1080
1142
  languageCode: t.code,
1081
1143
  menuKey: e.menuKey,
1082
- replacementItemCount: bt(e.items)
1144
+ replacementItemCount: $t(e.items)
1083
1145
  });
1084
1146
  }
1085
- async function Ln(e) {
1147
+ async function Yn(e) {
1086
1148
  if (e.items.length !== 1)
1087
1149
  throw new Error('mode "update" requires exactly one navigation item.');
1088
- const t = await G(e.supabase, e.languageCode), n = e.items[0], r = R(e.match?.url) || R(n.url), o = We(e.match?.label), { data: a, error: s } = await e.supabase.from("navigation_items").select("id, label, url, parent_id, order").eq("menu_key", e.menuKey).eq("language_id", t.id);
1150
+ const t = await V(e.supabase, e.languageCode), n = e.items[0], r = z(e.match?.url) || z(n.url), o = et(e.match?.label), { data: a, error: s } = await e.supabase.from("navigation_items").select("id, label, url, parent_id, order").eq("menu_key", e.menuKey).eq("language_id", t.id);
1089
1151
  if (s)
1090
1152
  throw new Error(
1091
- `Failed to load existing ${e.menuKey} navigation items: ${h(s)}`
1153
+ `Failed to load existing ${e.menuKey} navigation items: ${_(s)}`
1092
1154
  );
1093
1155
  const u = (Array.isArray(a) ? a : []).find((c) => {
1094
- const p = R(c.url), g = We(c.label);
1095
- return !!(r && p === r || o && g === o);
1156
+ const p = z(c.url), h = et(c.label);
1157
+ return !!(r && p === r || o && h === o);
1096
1158
  });
1097
1159
  if (!u?.id)
1098
1160
  throw new Error(
@@ -1103,7 +1165,7 @@ async function Ln(e) {
1103
1165
  url: n.url
1104
1166
  }).eq("id", u.id);
1105
1167
  if (d)
1106
- throw new Error(`Failed to update ${e.menuKey} navigation item: ${h(d)}`);
1168
+ throw new Error(`Failed to update ${e.menuKey} navigation item: ${_(d)}`);
1107
1169
  return {
1108
1170
  insertedCount: 0,
1109
1171
  languageCode: t.code,
@@ -1112,24 +1174,24 @@ async function Ln(e) {
1112
1174
  updatedCount: 1
1113
1175
  };
1114
1176
  }
1115
- async function Rn(e) {
1116
- const t = await G(e.supabase, e.languageCode), { data: n, error: r } = await e.supabase.from("navigation_items").select("id, url, parent_id, order").eq("menu_key", e.menuKey).eq("language_id", t.id);
1177
+ async function Xn(e) {
1178
+ const t = await V(e.supabase, e.languageCode), { data: n, error: r } = await e.supabase.from("navigation_items").select("id, url, parent_id, order").eq("menu_key", e.menuKey).eq("language_id", t.id);
1117
1179
  if (r)
1118
1180
  throw new Error(
1119
- `Failed to load existing ${e.menuKey} navigation items: ${h(r)}`
1181
+ `Failed to load existing ${e.menuKey} navigation items: ${_(r)}`
1120
1182
  );
1121
1183
  let o = 0, a = 0;
1122
1184
  const s = Array.isArray(n) ? n : [], l = new Set(
1123
- s.map((c) => R(c.url)).filter(Boolean)
1185
+ s.map((c) => z(c.url)).filter(Boolean)
1124
1186
  ), u = s.filter((c) => c.parent_id == null).map((c) => Number(c.order)).filter(Number.isFinite);
1125
1187
  let d = u.length > 0 ? Math.max(...u) + 1 : s.length;
1126
1188
  for (const c of e.items) {
1127
- const p = R(c.url);
1189
+ const p = z(c.url);
1128
1190
  if (p && l.has(p)) {
1129
1191
  a++;
1130
1192
  continue;
1131
1193
  }
1132
- const g = await ie({
1194
+ const h = await le({
1133
1195
  item: c,
1134
1196
  languageId: t.id,
1135
1197
  menuKey: e.menuKey,
@@ -1138,20 +1200,20 @@ async function Rn(e) {
1138
1200
  });
1139
1201
  o++, d++, p && l.add(p);
1140
1202
  let m = 0;
1141
- for (const f of c.children ?? []) {
1142
- const _ = R(f.url);
1143
- if (_ && l.has(_)) {
1203
+ for (const g of c.children ?? []) {
1204
+ const f = z(g.url);
1205
+ if (f && l.has(f)) {
1144
1206
  a++;
1145
1207
  continue;
1146
1208
  }
1147
- await ie({
1148
- item: f,
1209
+ await le({
1210
+ item: g,
1149
1211
  languageId: t.id,
1150
1212
  menuKey: e.menuKey,
1151
1213
  order: m,
1152
- parentId: g,
1214
+ parentId: h,
1153
1215
  supabase: e.supabase
1154
- }), o++, m++, _ && l.add(_);
1216
+ }), o++, m++, f && l.add(f);
1155
1217
  }
1156
1218
  }
1157
1219
  return {
@@ -1162,50 +1224,50 @@ async function Rn(e) {
1162
1224
  updatedCount: 0
1163
1225
  };
1164
1226
  }
1165
- function x(e) {
1227
+ function C(e) {
1166
1228
  return typeof e == "string" && e.trim() ? e.trim() : "";
1167
1229
  }
1168
- function Mn(e) {
1230
+ function Qn(e) {
1169
1231
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1170
1232
  }
1171
- function Dn(e) {
1172
- const t = x(e.field_type ?? e.fieldType ?? e.type ?? e.input_type).toLowerCase().replace(/\s+/g, "_"), n = x(e.label ?? e.name ?? e.placeholder).toLowerCase();
1233
+ function Zn(e) {
1234
+ const t = C(e.field_type ?? e.fieldType ?? e.type ?? e.input_type).toLowerCase().replace(/\s+/g, "_"), n = C(e.label ?? e.name ?? e.placeholder).toLowerCase();
1173
1235
  return ["email", "textarea", "select", "radio", "checkbox", "text"].includes(t) ? t : n.includes("email") ? "email" : n.includes("message") || n.includes("comment") || n.includes("details") ? "textarea" : "text";
1174
1236
  }
1175
- function Gn(e) {
1237
+ function er(e) {
1176
1238
  return (Array.isArray(e) && e.length > 0 ? e : [
1177
1239
  { field_type: "text", is_required: !0, label: "Name", placeholder: "Your name" },
1178
1240
  { field_type: "email", is_required: !0, label: "Email", placeholder: "you@example.com" },
1179
1241
  { field_type: "textarea", is_required: !0, label: "Message", placeholder: "How can we help?" }
1180
1242
  ]).map((n, r) => {
1181
- const o = A(n) ? n : {}, a = x(o.label ?? o.name) || (r === 0 ? "Name" : r === 1 ? "Email" : "Message"), s = Dn({ ...o, label: a }), l = o.is_required ?? o.isRequired ?? o.required;
1243
+ const o = A(n) ? n : {}, a = C(o.label ?? o.name) || (r === 0 ? "Name" : r === 1 ? "Email" : "Message"), s = Zn({ ...o, label: a }), l = o.is_required ?? o.isRequired ?? o.required;
1182
1244
  return {
1183
1245
  field_type: s,
1184
1246
  is_required: typeof l == "boolean" ? l : !0,
1185
1247
  label: a,
1186
1248
  options: Array.isArray(o.options) ? o.options : void 0,
1187
- placeholder: x(o.placeholder) || void 0,
1188
- temp_id: x(o.temp_id ?? o.tempId ?? o.id) || `field-${r + 1}`
1249
+ placeholder: C(o.placeholder) || void 0,
1250
+ temp_id: C(o.temp_id ?? o.tempId ?? o.id) || `field-${r + 1}`
1189
1251
  };
1190
1252
  });
1191
1253
  }
1192
- const zn = /* @__PURE__ */ new Set(["none", "sm", "md", "lg", "xl"]), Ye = /* @__PURE__ */ new Set(["none", "sm", "md", "lg", "xl"]), Kn = /* @__PURE__ */ new Set([
1254
+ const tr = /* @__PURE__ */ new Set(["none", "sm", "md", "lg", "xl"]), nt = /* @__PURE__ */ new Set(["none", "sm", "md", "lg", "xl"]), nr = /* @__PURE__ */ new Set([
1193
1255
  "full-width",
1194
1256
  "container",
1195
1257
  "container-sm",
1196
1258
  "container-lg",
1197
1259
  "container-xl"
1198
- ]), Vn = /* @__PURE__ */ new Set(["start", "center", "end", "stretch"]), Hn = /* @__PURE__ */ new Set(["none", "theme", "solid", "gradient", "image"]), Wn = /* @__PURE__ */ new Set(["primary", "secondary", "muted", "accent", "destructive"]), Jn = /* @__PURE__ */ new Set(["center", "top", "bottom", "left", "right"]);
1199
- function Yn(e) {
1260
+ ]), rr = /* @__PURE__ */ new Set(["start", "center", "end", "stretch"]), or = /* @__PURE__ */ new Set(["none", "theme", "solid", "gradient", "image"]), ir = /* @__PURE__ */ new Set(["primary", "secondary", "muted", "accent", "destructive"]), ar = /* @__PURE__ */ new Set(["center", "top", "bottom", "left", "right"]);
1261
+ function sr(e) {
1200
1262
  return typeof e == "string" && /^https?:\/\//i.test(e.trim());
1201
1263
  }
1202
- function q(e, t, n) {
1264
+ function B(e, t, n) {
1203
1265
  return typeof e == "string" && t.has(e) ? e : n;
1204
1266
  }
1205
- function Xn(e) {
1267
+ function lr(e) {
1206
1268
  return Number.isFinite(e) ? Math.min(4, Math.max(1, Math.round(e))) : 1;
1207
1269
  }
1208
- function Qn(e) {
1270
+ function cr(e) {
1209
1271
  const t = [
1210
1272
  { color: "#1e3a8a", position: 0 },
1211
1273
  { color: "#3b82f6", position: 100 }
@@ -1215,23 +1277,23 @@ function Qn(e) {
1215
1277
  const n = e.type === "radial" ? "radial" : "linear", r = Array.isArray(e.stops) && e.stops.length >= 2 ? e.stops : t;
1216
1278
  return { direction: typeof e.direction == "string" && e.direction.trim() ? e.direction : n === "radial" ? "circle at center" : "to bottom right", stops: r, type: n };
1217
1279
  }
1218
- function Zn(e) {
1280
+ function ur(e) {
1219
1281
  if (!A(e))
1220
1282
  return { type: "none" };
1221
- const t = q(e.type, Hn, "none"), n = typeof e.min_height == "string" && e.min_height.trim() ? { min_height: e.min_height } : {};
1283
+ const t = B(e.type, or, "none"), n = typeof e.min_height == "string" && e.min_height.trim() ? { min_height: e.min_height } : {};
1222
1284
  if (t === "theme")
1223
- return { theme: q(e.theme, Wn, "muted"), type: t, ...n };
1285
+ return { theme: B(e.theme, ir, "muted"), type: t, ...n };
1224
1286
  if (t === "solid")
1225
1287
  return typeof e.solid_color == "string" && e.solid_color.trim() ? { solid_color: e.solid_color, type: t, ...n } : { type: "none" };
1226
1288
  if (t === "gradient")
1227
- return { gradient: Qn(e.gradient), type: t, ...n };
1289
+ return { gradient: cr(e.gradient), type: t, ...n };
1228
1290
  if (t === "image") {
1229
- const r = A(e.image) ? e.image : null, o = r && Yn(r.external_url) ? r.external_url.trim() : null, a = !!(r && typeof r.media_id == "string" && r.media_id.trim() && typeof r.object_key == "string" && r.object_key.trim());
1291
+ const r = A(e.image) ? e.image : null, o = r && sr(r.external_url) ? r.external_url.trim() : null, a = !!(r && typeof r.media_id == "string" && r.media_id.trim() && typeof r.object_key == "string" && r.object_key.trim());
1230
1292
  return r && (o || a) ? {
1231
1293
  image: {
1232
1294
  ...r,
1233
1295
  ...o ? { external_url: o } : {},
1234
- position: q(r.position, Jn, "center"),
1296
+ position: B(r.position, ar, "center"),
1235
1297
  size: r.size === "contain" ? "contain" : "cover"
1236
1298
  },
1237
1299
  type: t,
@@ -1240,47 +1302,47 @@ function Zn(e) {
1240
1302
  }
1241
1303
  return { type: "none", ...n };
1242
1304
  }
1243
- function er(e, t, n) {
1305
+ function dr(e, t, n) {
1244
1306
  const r = e.is_hero === !0;
1245
1307
  let o = Array.isArray(e.column_blocks) ? e.column_blocks : [];
1246
- o.length > 0 && o.every((_) => A(_) && !Array.isArray(_)) && (o = [o]);
1247
- const a = o.map((_, k) => (Array.isArray(_) ? _ : []).map(
1248
- (E, y) => ve(E, `${t} column ${k} block ${y}`, n)
1249
- )), s = a.length > 0 ? a : [[]], l = Xn(s.length), u = A(e.responsive_columns) ? e.responsive_columns : {}, d = Number(u.tablet), c = Number(u.mobile), p = Number.isFinite(d) ? Math.min(3, Math.max(1, Math.min(l, d))) : Math.min(3, l), g = Number.isFinite(c) ? Math.min(2, Math.max(1, c)) : 1, m = A(e.padding) ? e.padding : {}, f = {
1308
+ o.length > 0 && o.every((f) => A(f) && !Array.isArray(f)) && (o = [o]);
1309
+ const a = o.map((f, k) => (Array.isArray(f) ? f : []).map(
1310
+ (w, b) => Ae(w, `${t} column ${k} block ${b}`, n)
1311
+ )), s = a.length > 0 ? a : [[]], l = lr(s.length), u = A(e.responsive_columns) ? e.responsive_columns : {}, d = Number(u.tablet), c = Number(u.mobile), p = Number.isFinite(d) ? Math.min(3, Math.max(1, Math.min(l, d))) : Math.min(3, l), h = Number.isFinite(c) ? Math.min(2, Math.max(1, c)) : 1, m = A(e.padding) ? e.padding : {}, g = {
1250
1312
  ...e,
1251
- background: Zn(e.background),
1313
+ background: ur(e.background),
1252
1314
  column_blocks: s,
1253
- column_gap: q(e.column_gap, zn, "lg"),
1254
- container_type: q(e.container_type, Kn, "container"),
1315
+ column_gap: B(e.column_gap, tr, "lg"),
1316
+ container_type: B(e.container_type, nr, "container"),
1255
1317
  padding: {
1256
- bottom: q(m.bottom, Ye, "xl"),
1257
- top: q(m.top, Ye, "xl")
1318
+ bottom: B(m.bottom, nt, "xl"),
1319
+ top: B(m.top, nt, "xl")
1258
1320
  },
1259
- responsive_columns: { desktop: l, mobile: g, tablet: p },
1260
- vertical_alignment: q(
1321
+ responsive_columns: { desktop: l, mobile: h, tablet: p },
1322
+ vertical_alignment: B(
1261
1323
  e.vertical_alignment,
1262
- Vn,
1324
+ rr,
1263
1325
  r ? "center" : "start"
1264
1326
  )
1265
1327
  };
1266
- return f.slider === !0 && !(Array.isArray(f.slides) && f.slides.length > 0) && (f.slider = !1), f;
1328
+ return g.slider === !0 && !(Array.isArray(g.slides) && g.slides.length > 0) && (g.slider = !1), g;
1267
1329
  }
1268
- function It(e, t, n, r) {
1330
+ function Nt(e, t, n, r) {
1269
1331
  if (e === "section") {
1270
- const a = er(t, n, r);
1271
- return L(e, a, n, r), a;
1332
+ const a = dr(t, n, r);
1333
+ return D(e, a, n, r), a;
1272
1334
  }
1273
- const o = H(t);
1274
- if (e === "heading" && (o.text_content = x(o.text_content) || x(o.text) || x(o.title) || x(o.heading) || "Untitled", o.level = typeof o.level == "number" ? o.level : 1), e === "text") {
1275
- const a = x(o.html_content) || x(o.html) || x(o.content) || x(o.text);
1276
- a && (o.html_content = /<\/?[a-z][\s\S]*>/i.test(a) ? a : `<p>${Mn(a)}</p>`);
1335
+ const o = X(t);
1336
+ if (e === "heading" && (o.text_content = C(o.text_content) || C(o.text) || C(o.title) || C(o.heading) || "Untitled", o.level = typeof o.level == "number" ? o.level : 1), e === "text") {
1337
+ const a = C(o.html_content) || C(o.html) || C(o.content) || C(o.text);
1338
+ a && (o.html_content = /<\/?[a-z][\s\S]*>/i.test(a) ? a : `<p>${Qn(a)}</p>`);
1277
1339
  }
1278
- return e === "button" && (o.text = x(o.text) || x(o.label) || x(o.title) || "Learn More", o.url = x(o.url) || x(o.href) || x(o.link) || "#"), e === "form" && (o.fields = Gn(o.fields), o.submit_button_text = x(o.submit_button_text ?? o.submitButtonText ?? o.button_text) || "Send Message", o.success_message = x(o.success_message ?? o.successMessage) || "Thanks for reaching out. We will reply as soon as possible."), L(e, o, n, r), o;
1340
+ return e === "button" && (o.text = C(o.text) || C(o.label) || C(o.title) || "Learn More", o.url = C(o.url) || C(o.href) || C(o.link) || "#"), e === "form" && (o.fields = er(o.fields), o.submit_button_text = C(o.submit_button_text ?? o.submitButtonText ?? o.button_text) || "Send Message", o.success_message = C(o.success_message ?? o.successMessage) || "Thanks for reaching out. We will reply as soon as possible."), D(e, o, n, r), o;
1279
1341
  }
1280
- function ae(e, t, n) {
1281
- const r = It(
1342
+ function ce(e, t, n) {
1343
+ const r = Nt(
1282
1344
  e.blockType,
1283
- X(e.content, `Block ${t}`),
1345
+ ee(e.content, `Block ${t}`),
1284
1346
  `Block ${t}`,
1285
1347
  n
1286
1348
  );
@@ -1290,9 +1352,9 @@ function ae(e, t, n) {
1290
1352
  order: e.order ?? t
1291
1353
  };
1292
1354
  }
1293
- function tr(e, t = "Contact Us", n) {
1355
+ function pr(e, t = "Contact Us", n) {
1294
1356
  return [
1295
- ae(
1357
+ ce(
1296
1358
  {
1297
1359
  blockType: "section",
1298
1360
  content: {
@@ -1307,14 +1369,14 @@ function tr(e, t = "Contact Us", n) {
1307
1369
  textAlign: "center",
1308
1370
  text_content: t
1309
1371
  },
1310
- temp_id: oe("heading")
1372
+ temp_id: se("heading")
1311
1373
  },
1312
1374
  {
1313
1375
  block_type: "text",
1314
1376
  content: {
1315
1377
  html_content: "<p>Have a question, project, or support request? Send us a note and we will get back to you soon.</p>"
1316
1378
  },
1317
- temp_id: oe("text")
1379
+ temp_id: se("text")
1318
1380
  }
1319
1381
  ]
1320
1382
  ],
@@ -1328,7 +1390,7 @@ function tr(e, t = "Contact Us", n) {
1328
1390
  0,
1329
1391
  n
1330
1392
  ),
1331
- ae(
1393
+ ce(
1332
1394
  {
1333
1395
  blockType: "form",
1334
1396
  content: {
@@ -1365,13 +1427,13 @@ function tr(e, t = "Contact Us", n) {
1365
1427
  )
1366
1428
  ];
1367
1429
  }
1368
- function qe(e, t, n, r) {
1369
- return (!e || e.length === 0) && t ? tr(t, n, r) : (e || []).map((o, a) => ae(o, a, r));
1430
+ function Ce(e, t, n, r) {
1431
+ return (!e || e.length === 0) && t ? pr(t, n, r) : (e || []).map((o, a) => ce(o, a, r));
1370
1432
  }
1371
- async function Be(e) {
1433
+ async function Me(e) {
1372
1434
  const t = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products", { data: n, error: r } = await e.supabase.from(t).select("id, title, slug, language_id").eq("slug", e.slug).eq("language_id", e.languageId);
1373
1435
  if (r)
1374
- throw new Error(`Failed to check ${e.contentType} slug uniqueness: ${h(r)}`);
1436
+ throw new Error(`Failed to check ${e.contentType} slug uniqueness: ${_(r)}`);
1375
1437
  const o = Array.isArray(n) ? n : [];
1376
1438
  return o.length > 0 ? {
1377
1439
  duplicate: !0,
@@ -1381,7 +1443,7 @@ async function Be(e) {
1381
1443
  message: `A ${e.contentType} with slug "${e.slug}" already exists for this language.`
1382
1444
  } : null;
1383
1445
  }
1384
- async function Le(e) {
1446
+ async function De(e) {
1385
1447
  if (!e.suppliedTranslationGroupId)
1386
1448
  return {
1387
1449
  translationGroupId: void 0
@@ -1389,7 +1451,7 @@ async function Le(e) {
1389
1451
  const t = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products", { data: n, error: r } = await e.supabase.from(t).select("id, title, slug, language_id, translation_group_id").eq("translation_group_id", e.suppliedTranslationGroupId);
1390
1452
  if (r)
1391
1453
  throw new Error(
1392
- `Failed to inspect ${e.contentType} translation group: ${h(r)}`
1454
+ `Failed to inspect ${e.contentType} translation group: ${_(r)}`
1393
1455
  );
1394
1456
  const o = Array.isArray(n) ? n : [];
1395
1457
  if (o.length === 0)
@@ -1417,7 +1479,7 @@ async function Le(e) {
1417
1479
  translationGroupId: e.suppliedTranslationGroupId
1418
1480
  };
1419
1481
  }
1420
- async function Tt(e) {
1482
+ async function ze(e) {
1421
1483
  if (e.blocks.length === 0)
1422
1484
  return [];
1423
1485
  const t = e.blocks.map((o, a) => ({
@@ -1426,25 +1488,26 @@ async function Tt(e) {
1426
1488
  language_id: e.languageId,
1427
1489
  order: o.order ?? a,
1428
1490
  page_id: e.contentType === "page" ? e.itemId : null,
1429
- post_id: e.contentType === "post" ? e.itemId : null
1491
+ post_id: e.contentType === "post" ? e.itemId : null,
1492
+ product_id: e.contentType === "product" ? e.itemId : null
1430
1493
  })), { data: n, error: r } = await e.supabase.from("blocks").insert(t).select("*");
1431
1494
  if (r)
1432
- throw new Error(`Failed to insert ${e.contentType} blocks: ${h(r)}`);
1433
- return Ie(e.blocks, e.supabase), Array.isArray(n) ? n : [];
1495
+ throw new Error(`Failed to insert ${e.contentType} blocks: ${_(r)}`);
1496
+ return ve(e.blocks, e.supabase), Array.isArray(n) ? n : [];
1434
1497
  }
1435
- async function xt(e) {
1436
- const t = e.contentType === "page" ? "pages" : "posts";
1498
+ async function Ge(e) {
1499
+ const t = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products";
1437
1500
  await e.supabase.from(t).delete().eq("id", e.itemId);
1438
1501
  }
1439
- function Re(e, t) {
1502
+ function Ke(e, t) {
1440
1503
  return e === "page" ? `/cms/pages/${t}/edit` : e === "post" ? `/cms/posts/${t}/edit` : `/cms/products/${t}/edit`;
1441
1504
  }
1442
- function Xe(e) {
1505
+ function rt(e) {
1443
1506
  return e === "page" ? "/cms/pages" : e === "post" ? "/cms/posts" : "/cms/products";
1444
1507
  }
1445
- async function Ct(e, t) {
1446
- const n = se.parse(e), r = I(t);
1447
- n.mode === "replace" && await Bn({
1508
+ async function Ut(e, t) {
1509
+ const n = de.parse(e), r = T(t);
1510
+ n.mode === "replace" && await Wn({
1448
1511
  items: n.items,
1449
1512
  languageCode: n.languageCode,
1450
1513
  menuKey: "HEADER",
@@ -1464,35 +1527,35 @@ async function Ct(e, t) {
1464
1527
  });
1465
1528
  if (o)
1466
1529
  return o;
1467
- const a = n.mode === "update" ? await Ln({
1530
+ const a = n.mode === "update" ? await Yn({
1468
1531
  items: n.items,
1469
1532
  languageCode: n.languageCode,
1470
1533
  match: n.match,
1471
1534
  menuKey: "HEADER",
1472
1535
  supabase: r
1473
- }) : n.mode === "append" ? await Rn({
1536
+ }) : n.mode === "append" ? await Xn({
1474
1537
  items: n.items,
1475
1538
  languageCode: n.languageCode,
1476
1539
  menuKey: "HEADER",
1477
1540
  supabase: r
1478
- }) : await kt({
1541
+ }) : await At({
1479
1542
  items: n.items,
1480
1543
  languageCode: n.languageCode,
1481
1544
  menuKey: "HEADER",
1482
1545
  supabase: r
1483
1546
  });
1484
- return mt(t), {
1547
+ return Tt(t), {
1485
1548
  ...a,
1486
1549
  mutationExecuted: !0,
1487
1550
  mode: n.mode,
1488
1551
  success: !0
1489
1552
  };
1490
1553
  }
1491
- async function vt(e, t) {
1492
- const n = le.parse(e);
1554
+ async function Ot(e, t) {
1555
+ const n = pe.parse(e);
1493
1556
  if (!n.links?.length && !n.copyright)
1494
1557
  throw new Error("update_footer requires links or copyright.");
1495
- const r = I(t), o = P({
1558
+ const r = T(t), o = P({
1496
1559
  action: "UPDATE FOOTER",
1497
1560
  context: t,
1498
1561
  payload: { input: n, tool: "update_footer" },
@@ -1507,7 +1570,7 @@ async function vt(e, t) {
1507
1570
  if (o)
1508
1571
  return o;
1509
1572
  let a = null;
1510
- if (n.links?.length && (a = await kt({
1573
+ if (n.links?.length && (a = await At({
1511
1574
  items: n.links,
1512
1575
  languageCode: n.languageCode,
1513
1576
  menuKey: "FOOTER",
@@ -1518,38 +1581,38 @@ async function vt(e, t) {
1518
1581
  value: n.copyright
1519
1582
  });
1520
1583
  if (s)
1521
- throw new Error(`Failed to update footer copyright: ${h(s)}`);
1584
+ throw new Error(`Failed to update footer copyright: ${_(s)}`);
1522
1585
  }
1523
- return mt(t), {
1586
+ return Tt(t), {
1524
1587
  copyrightUpdated: !!n.copyright,
1525
1588
  footerNavigation: a,
1526
1589
  mutationExecuted: !0,
1527
1590
  success: !0
1528
1591
  };
1529
1592
  }
1530
- function St(e) {
1593
+ function Ft(e) {
1531
1594
  return typeof e == "string" ? e.toLowerCase() : "";
1532
1595
  }
1533
- function nr(e, t) {
1534
- const n = t.map(St).join(" ");
1596
+ function mr(e, t) {
1597
+ const n = t.map(Ft).join(" ");
1535
1598
  return e.reduce((r, o) => r + (n.includes(o) ? 1 : 0), 0);
1536
1599
  }
1537
- function Qe(e, t) {
1600
+ function ot(e, t) {
1538
1601
  return (e.find(
1539
- (n) => t.some((r) => St(n).includes(r))
1602
+ (n) => t.some((r) => Ft(n).includes(r))
1540
1603
  ) || e.find((n) => n.trim().length > 0) || "No excerpt available.").slice(0, 500);
1541
1604
  }
1542
- async function rr(e, t) {
1543
- const n = Pe.parse(e), r = I(t), o = n.query.toLowerCase().split(/\s+/).map((c) => c.trim()).filter(Boolean), [a, s] = await Promise.all([
1605
+ async function gr(e, t) {
1606
+ const n = Fe.parse(e), r = T(t), o = n.query.toLowerCase().split(/\s+/).map((c) => c.trim()).filter(Boolean), [a, s] = await Promise.all([
1544
1607
  r.from("posts").select("id, title, slug, excerpt, subtitle, meta_description, status, updated_at").eq("status", "published").limit(100),
1545
1608
  r.from("pages").select("id, title, slug, meta_description, status, updated_at").eq("status", "published").limit(100)
1546
1609
  ]);
1547
1610
  if (a.error)
1548
- throw new Error(`Failed to search documentation posts: ${h(a.error)}`);
1611
+ throw new Error(`Failed to search documentation posts: ${_(a.error)}`);
1549
1612
  if (s.error)
1550
- throw new Error(`Failed to search documentation pages: ${h(s.error)}`);
1613
+ throw new Error(`Failed to search documentation pages: ${_(s.error)}`);
1551
1614
  const l = (a.data ?? []).map((c) => ({
1552
- excerpt: Qe(
1615
+ excerpt: ot(
1553
1616
  [c.excerpt, c.subtitle, c.meta_description, c.slug].filter(Boolean),
1554
1617
  o
1555
1618
  ),
@@ -1557,13 +1620,13 @@ async function rr(e, t) {
1557
1620
  title: c.title,
1558
1621
  url: `/article/${c.slug}`
1559
1622
  })), u = (s.data ?? []).map((c) => ({
1560
- excerpt: Qe([c.meta_description, c.slug].filter(Boolean), o),
1623
+ excerpt: ot([c.meta_description, c.slug].filter(Boolean), o),
1561
1624
  source: "page",
1562
1625
  title: c.title,
1563
1626
  url: c.slug === "home" ? "/" : `/${c.slug}`
1564
1627
  })), d = [...l, ...u].map((c) => ({
1565
1628
  ...c,
1566
- score: nr(o, [c.title, c.excerpt, c.url])
1629
+ score: mr(o, [c.title, c.excerpt, c.url])
1567
1630
  })).filter((c) => c.score > 0).sort((c, p) => p.score - c.score).slice(0, n.limit).map((c) => ({
1568
1631
  excerpt: c.excerpt,
1569
1632
  source: c.source,
@@ -1576,10 +1639,10 @@ async function rr(e, t) {
1576
1639
  success: !0
1577
1640
  };
1578
1641
  }
1579
- async function or(e, t, n = Wt) {
1580
- const r = Pe.safeParse(e), o = r.success ? r.data.query : "";
1581
- return hn(
1582
- rr(e, t),
1642
+ async function fr(e, t, n = sn) {
1643
+ const r = Fe.safeParse(e), o = r.success ? r.data.query : "";
1644
+ return Sn(
1645
+ gr(e, t),
1583
1646
  n,
1584
1647
  () => ({
1585
1648
  message: "Documentation search took too long to respond. Please try again or ask a more specific question.",
@@ -1590,7 +1653,7 @@ async function or(e, t, n = Wt) {
1590
1653
  })
1591
1654
  );
1592
1655
  }
1593
- const ir = [
1656
+ const hr = [
1594
1657
  "pending",
1595
1658
  "trial",
1596
1659
  "paid",
@@ -1598,7 +1661,7 @@ const ir = [
1598
1661
  "cancelled",
1599
1662
  "refunded",
1600
1663
  "failed"
1601
- ], ar = {
1664
+ ], yr = {
1602
1665
  awaiting: "pending",
1603
1666
  canceled: "cancelled",
1604
1667
  cancelled: "cancelled",
@@ -1615,34 +1678,34 @@ const ir = [
1615
1678
  trial: "trial",
1616
1679
  trials: "trial"
1617
1680
  };
1618
- function sr(e) {
1681
+ function _r(e) {
1619
1682
  return String(e ?? "unknown").trim().toLowerCase() || "unknown";
1620
1683
  }
1621
- function Ze(e) {
1684
+ function it(e) {
1622
1685
  const t = Object.fromEntries(
1623
- ir.map((n) => [n, 0])
1686
+ hr.map((n) => [n, 0])
1624
1687
  );
1625
1688
  for (const n of e) {
1626
- const r = sr(n.status);
1689
+ const r = _r(n.status);
1627
1690
  t[r] = (t[r] ?? 0) + 1;
1628
1691
  }
1629
1692
  return t;
1630
1693
  }
1631
- function lr(e) {
1694
+ function br(e) {
1632
1695
  const n = e.toLowerCase().replace(/[^a-z0-9_]+/g, " ").split(/\s+/).filter(Boolean);
1633
1696
  for (const r of n) {
1634
- const o = ar[r];
1697
+ const o = yr[r];
1635
1698
  if (o)
1636
1699
  return o;
1637
1700
  }
1638
1701
  return null;
1639
1702
  }
1640
- function V(e) {
1703
+ function Y(e) {
1641
1704
  const t = Number(e);
1642
1705
  return Number.isFinite(t) ? t : 0;
1643
1706
  }
1644
- async function cr(e, t) {
1645
- const n = at.parse(e), r = I(t), o = /* @__PURE__ */ new Date();
1707
+ async function kr(e, t) {
1708
+ const n = gt.parse(e), r = T(t), o = /* @__PURE__ */ new Date();
1646
1709
  let a = null, s = null;
1647
1710
  switch (n.timeRange) {
1648
1711
  case "today":
@@ -1667,7 +1730,7 @@ async function cr(e, t) {
1667
1730
  a = null;
1668
1731
  break;
1669
1732
  }
1670
- const l = n.currency?.toUpperCase(), u = lr(n.query), d = r.from("orders").select("id, status, total, currency, created_at, paid_at");
1733
+ const l = n.currency?.toUpperCase(), u = br(n.query), d = r.from("orders").select("id, status, total, currency, created_at, paid_at");
1671
1734
  l && d.eq("currency", l), a && d.gte("created_at", a.toISOString()), s && d.lte("created_at", s.toISOString());
1672
1735
  const p = n.reportType === "products" || n.reportType === "revenue" || n.reportType === "general" ? r.from("order_items").select(`
1673
1736
  quantity,
@@ -1688,79 +1751,79 @@ async function cr(e, t) {
1688
1751
  const m = n.timeRange !== "all_time" && (n.reportType === "orders" || u) ? r.from("orders").select("id, status, currency") : null;
1689
1752
  m && l && m.eq("currency", l);
1690
1753
  const [
1691
- { data: f, error: _ },
1692
- { data: k, error: w },
1693
- E
1754
+ { data: g, error: f },
1755
+ { data: k, error: y },
1756
+ w
1694
1757
  ] = await Promise.all([
1695
1758
  d,
1696
1759
  p ?? Promise.resolve({ data: [], error: null }),
1697
1760
  m ?? Promise.resolve({ data: null, error: null })
1698
1761
  ]);
1699
- if (_)
1700
- throw new Error(`Failed to fetch ecommerce stats: ${h(_)}`);
1701
- if (w)
1702
- throw new Error(`Failed to fetch ecommerce stats: ${h(w)}`);
1703
- if (E.error)
1704
- throw new Error(`Failed to fetch ecommerce stats: ${h(E.error)}`);
1705
- const y = Array.isArray(f) ? f : [], C = Array.isArray(k) ? k : [], v = Ze(y), S = Array.isArray(E.data) ? E.data : null, j = S ? Ze(S) : null, B = {};
1706
- for (const b of C) {
1707
- const $ = Array.isArray(b.orders) ? b.orders[0] : b.orders, O = String($?.currency || l || "unknown").toUpperCase();
1708
- B[O] = (B[O] ?? 0) + V(b.quantity) * V(b.price_at_purchase) / 100;
1762
+ if (f)
1763
+ throw new Error(`Failed to fetch ecommerce stats: ${_(f)}`);
1764
+ if (y)
1765
+ throw new Error(`Failed to fetch ecommerce stats: ${_(y)}`);
1766
+ if (w.error)
1767
+ throw new Error(`Failed to fetch ecommerce stats: ${_(w.error)}`);
1768
+ const b = Array.isArray(g) ? g : [], v = Array.isArray(k) ? k : [], S = it(b), E = Array.isArray(w.data) ? w.data : null, L = E ? it(E) : null, q = {};
1769
+ for (const I of v) {
1770
+ const $ = Array.isArray(I.orders) ? I.orders[0] : I.orders, j = String($?.currency || l || "unknown").toUpperCase();
1771
+ q[j] = (q[j] ?? 0) + Y(I.quantity) * Y(I.price_at_purchase) / 100;
1709
1772
  }
1710
- const z = {
1773
+ const J = {
1711
1774
  currency: l ?? null,
1712
1775
  currencyFiltered: !!l,
1713
- orderStatusCounts: v,
1714
- paidOrderCount: v.paid ?? 0,
1776
+ orderStatusCounts: S,
1777
+ paidOrderCount: S.paid ?? 0,
1715
1778
  query: n.query,
1716
1779
  reportType: n.reportType,
1717
- revenueByCurrency: B,
1780
+ revenueByCurrency: q,
1718
1781
  timeRange: n.timeRange,
1719
- totalOrders: y.length,
1720
- totalRevenue: Object.values(B).reduce(
1721
- (b, $) => b + $,
1782
+ totalOrders: b.length,
1783
+ totalRevenue: Object.values(q).reduce(
1784
+ (I, $) => I + $,
1722
1785
  0
1723
1786
  )
1724
1787
  };
1725
- if (j && (z.allTimeOrderStatusCounts = j), u && (z.matchingOrderStatus = {
1726
- allTimeCount: j?.[u] ?? v[u] ?? 0,
1727
- count: v[u] ?? 0,
1788
+ if (L && (J.allTimeOrderStatusCounts = L), u && (J.matchingOrderStatus = {
1789
+ allTimeCount: L?.[u] ?? S[u] ?? 0,
1790
+ count: S[u] ?? 0,
1728
1791
  status: u,
1729
1792
  timeRange: n.timeRange
1730
1793
  }), n.reportType === "products" || n.reportType === "revenue" || n.reportType === "general") {
1731
- const b = {};
1732
- for (const $ of C) {
1733
- const O = Array.isArray($.products) ? $.products[0] : $.products;
1734
- if (!O?.id)
1794
+ const I = {};
1795
+ for (const $ of v) {
1796
+ const j = Array.isArray($.products) ? $.products[0] : $.products;
1797
+ if (!j?.id)
1735
1798
  continue;
1736
- const K = O.id;
1737
- b[K] || (b[K] = {
1738
- id: K,
1799
+ const W = j.id;
1800
+ I[W] || (I[W] = {
1801
+ id: W,
1739
1802
  quantity: 0,
1740
1803
  revenue: 0,
1741
- title: O.title,
1742
- type: O.product_type
1743
- }), b[K].quantity += V($.quantity), b[K].revenue += V($.quantity) * V($.price_at_purchase) / 100;
1804
+ title: j.title,
1805
+ type: j.product_type
1806
+ }), I[W].quantity += Y($.quantity), I[W].revenue += Y($.quantity) * Y($.price_at_purchase) / 100;
1744
1807
  }
1745
- z.topProducts = Object.values(b).sort(($, O) => O.revenue - $.revenue).slice(0, 10);
1808
+ J.topProducts = Object.values(I).sort(($, j) => j.revenue - $.revenue).slice(0, 10);
1746
1809
  }
1747
1810
  return {
1748
- report: z,
1811
+ report: J,
1749
1812
  success: !0
1750
1813
  };
1751
1814
  }
1752
- async function ur(e, t) {
1753
- const n = lt.parse(e), r = I(t), o = D(t), a = be(o), s = o.contentType === "page" ? "pages" : o.contentType === "post" ? "posts" : "products", { data: l, error: u } = await r.from(s).select("*").eq("id", a).single();
1815
+ async function wr(e, t) {
1816
+ const n = ht.parse(e), r = T(t), o = H(t), a = Te(o), s = o.contentType === "page" ? "pages" : o.contentType === "post" ? "posts" : "products", { data: l, error: u } = await r.from(s).select("*").eq("id", a).single();
1754
1817
  if (u || !l)
1755
1818
  throw new Error(
1756
- `Failed to read current ${o.contentType}: ${h(u)}`
1819
+ `Failed to read current ${o.contentType}: ${_(u)}`
1757
1820
  );
1758
1821
  let d = [];
1759
- if (n.includeBlocks && o.contentType !== "product") {
1760
- const c = o.contentType === "page" ? "page_id" : "post_id", { data: p, error: g } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq(c, a);
1761
- if (g)
1762
- throw new Error(`Failed to read current ${o.contentType} blocks: ${h(g)}`);
1763
- d = (Array.isArray(p) ? p : []).slice().sort((m, f) => Number(m.order) - Number(f.order)).map((m) => Fn(m, n.includeBlockContent));
1822
+ if (n.includeBlocks) {
1823
+ const c = o.contentType === "page" ? "page_id" : o.contentType === "post" ? "post_id" : "product_id", { data: p, error: h } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq(c, a);
1824
+ if (h)
1825
+ throw new Error(`Failed to read current ${o.contentType} blocks: ${_(h)}`);
1826
+ d = (Array.isArray(p) ? p : []).slice().sort((m, g) => Number(m.order) - Number(g.order)).map((m) => Kn(m, n.includeBlockContent));
1764
1827
  }
1765
1828
  return {
1766
1829
  blocks: d,
@@ -1769,7 +1832,7 @@ async function ur(e, t) {
1769
1832
  success: !0
1770
1833
  };
1771
1834
  }
1772
- const Et = /* @__PURE__ */ new Set([
1835
+ const jt = /* @__PURE__ */ new Set([
1773
1836
  "feature_image_id",
1774
1837
  "language_id",
1775
1838
  "meta_description",
@@ -1777,7 +1840,7 @@ const Et = /* @__PURE__ */ new Set([
1777
1840
  "slug",
1778
1841
  "status",
1779
1842
  "title"
1780
- ]), $t = /* @__PURE__ */ new Set([
1843
+ ]), Lt = /* @__PURE__ */ new Set([
1781
1844
  "excerpt",
1782
1845
  "feature_image_id",
1783
1846
  "label",
@@ -1789,7 +1852,7 @@ const Et = /* @__PURE__ */ new Set([
1789
1852
  "status",
1790
1853
  "subtitle",
1791
1854
  "title"
1792
- ]), dr = /* @__PURE__ */ new Set([
1855
+ ]), Ir = /* @__PURE__ */ new Set([
1793
1856
  "description_json",
1794
1857
  "language_id",
1795
1858
  "meta_description",
@@ -1798,7 +1861,7 @@ const Et = /* @__PURE__ */ new Set([
1798
1861
  "slug",
1799
1862
  "status",
1800
1863
  "title"
1801
- ]), pr = /* @__PURE__ */ new Set([
1864
+ ]), Tr = /* @__PURE__ */ new Set([
1802
1865
  "excerpt",
1803
1866
  "feature_image_id",
1804
1867
  "label",
@@ -1808,13 +1871,13 @@ const Et = /* @__PURE__ */ new Set([
1808
1871
  "short_description",
1809
1872
  "subtitle"
1810
1873
  ]);
1811
- function mr(e) {
1812
- return e === "page" ? Et : e === "post" ? $t : dr;
1874
+ function xr(e) {
1875
+ return e === "page" ? jt : e === "post" ? Lt : Ir;
1813
1876
  }
1814
- function At(e, t) {
1815
- return pr.has(e) && t === "" ? null : t;
1877
+ function Bt(e, t) {
1878
+ return Tr.has(e) && t === "" ? null : t;
1816
1879
  }
1817
- function Se(e, t) {
1880
+ function Pe(e, t) {
1818
1881
  if (typeof t != "string")
1819
1882
  return;
1820
1883
  const n = e === "product" ? ["active", "archived", "draft"] : ["archived", "draft", "published"];
@@ -1823,20 +1886,20 @@ function Se(e, t) {
1823
1886
  `Status "${t}" is not valid for ${e}. Allowed statuses: ${n.join(", ")}.`
1824
1887
  );
1825
1888
  }
1826
- function gr(e, t) {
1827
- const n = mr(t.contentType), r = {};
1889
+ function Cr(e, t) {
1890
+ const n = xr(t.contentType), r = {};
1828
1891
  for (const [o, a] of Object.entries(e))
1829
1892
  if (a !== void 0) {
1830
1893
  if (!n.has(o))
1831
1894
  throw new Error(
1832
1895
  `Field "${o}" cannot be updated for ${t.contentType} content.`
1833
1896
  );
1834
- o === "status" && Se(t.contentType, a), r[o] = At(o, a);
1897
+ o === "status" && Pe(t.contentType, a), r[o] = Bt(o, a);
1835
1898
  }
1836
1899
  return r;
1837
1900
  }
1838
- async function Pt(e, t) {
1839
- const n = ce.parse(e), r = I(t), o = D(t), a = be(o), s = gr(n.fields, o), l = Object.keys(s);
1901
+ async function Rt(e, t) {
1902
+ const n = me.parse(e), r = T(t), o = H(t), a = Te(o), s = Cr(n.fields, o), l = Object.keys(s);
1840
1903
  if (l.length === 0)
1841
1904
  throw new Error("update_current_cms_fields requires at least one supported field.");
1842
1905
  const u = P({
@@ -1859,7 +1922,7 @@ async function Pt(e, t) {
1859
1922
  });
1860
1923
  if (u)
1861
1924
  return u;
1862
- typeof s.feature_image_id == "string" && (s.feature_image_id = await J(
1925
+ typeof s.feature_image_id == "string" && (s.feature_image_id = await Z(
1863
1926
  s.feature_image_id,
1864
1927
  t,
1865
1928
  typeof o.title == "string" ? o.title : void 0
@@ -1870,9 +1933,9 @@ async function Pt(e, t) {
1870
1933
  }).eq("id", a).select("id, language_id, slug, status, title").single();
1871
1934
  if (p || !c)
1872
1935
  throw new Error(
1873
- `Failed to update current ${o.contentType}: ${h(p)}`
1936
+ `Failed to update current ${o.contentType}: ${_(p)}`
1874
1937
  );
1875
- return N(t, o, c.slug), {
1938
+ return U(t, o, c.slug), {
1876
1939
  contentType: o.contentType,
1877
1940
  entityId: a,
1878
1941
  mutationExecuted: !0,
@@ -1881,20 +1944,20 @@ async function Pt(e, t) {
1881
1944
  updatedFields: l
1882
1945
  };
1883
1946
  }
1884
- async function Nt(e, t) {
1885
- const n = ue.parse(e), r = I(t), o = D(t), { data: a, error: s } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq("id", n.blockId).single();
1947
+ async function qt(e, t) {
1948
+ const n = ge.parse(e), r = T(t), o = H(t), { data: a, error: s } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq("id", n.blockId).single();
1886
1949
  if (s || !a)
1887
- throw new Error(`Failed to read block ${n.blockId}: ${h(s)}`);
1888
- ht(a, o);
1889
- const l = re(a.block_type, `Block ${n.blockId}`);
1890
- _t(n.blockType, l, `Block ${n.blockId}`);
1891
- const u = X(a.content, `Block ${n.blockId}`), d = Un(
1950
+ throw new Error(`Failed to read block ${n.blockId}: ${_(s)}`);
1951
+ vt(a, o);
1952
+ const l = ae(a.block_type, `Block ${n.blockId}`);
1953
+ St(n.blockType, l, `Block ${n.blockId}`);
1954
+ const u = ee(a.content, `Block ${n.blockId}`), d = Gn(
1892
1955
  l,
1893
1956
  u,
1894
1957
  n.content,
1895
1958
  t
1896
1959
  );
1897
- L(l, d, `Block ${n.blockId}`, t);
1960
+ D(l, d, `Block ${n.blockId}`, t);
1898
1961
  const c = P({
1899
1962
  action: "UPDATE CONTENT BLOCK",
1900
1963
  context: t,
@@ -1908,19 +1971,19 @@ async function Nt(e, t) {
1908
1971
  blockId: n.blockId,
1909
1972
  blockType: l,
1910
1973
  contentType: o.contentType,
1911
- entityId: be(o)
1974
+ entityId: Te(o)
1912
1975
  },
1913
1976
  subject: `${l} block ${n.blockId}`
1914
1977
  });
1915
1978
  if (c)
1916
1979
  return c;
1917
- const { data: p, error: g } = await r.from("blocks").update({
1980
+ const { data: p, error: h } = await r.from("blocks").update({
1918
1981
  content: d,
1919
1982
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
1920
1983
  }).eq("id", n.blockId).select("id, block_type, order").single();
1921
- if (g || !p)
1922
- throw new Error(`Failed to update block ${n.blockId}: ${h(g)}`);
1923
- return Ie([{ content: d }], r), N(t, o), {
1984
+ if (h || !p)
1985
+ throw new Error(`Failed to update block ${n.blockId}: ${_(h)}`);
1986
+ return ve([{ content: d }], r), U(t, o), {
1924
1987
  blockId: p.id,
1925
1988
  blockType: p.block_type,
1926
1989
  contentUpdated: !0,
@@ -1928,32 +1991,29 @@ async function Nt(e, t) {
1928
1991
  success: !0
1929
1992
  };
1930
1993
  }
1931
- async function Ut(e, t) {
1932
- const n = me.parse(e), r = I(t), o = await we(n, t);
1933
- if (o.contentType === "product")
1934
- throw new Error("Products do not have page/post content blocks in this editor context.");
1935
- const a = Number(o.item.id), s = o.contentType === "page" ? "page_id" : "post_id", l = async () => {
1936
- const { data: y, error: C } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq(s, a);
1937
- if (C)
1938
- throw new Error(`Failed to read ${o.contentType} blocks: ${h(C)}`);
1939
- return (Array.isArray(y) ? y : []).sort(
1940
- (v, S) => Number(v.order) - Number(S.order)
1994
+ async function Mt(e, t) {
1995
+ const n = ye.parse(e), r = T(t), o = await te(n, t), a = o.contentType === "product" ? o.item.id : Number(o.item.id), s = o.contentType === "page" ? "page_id" : o.contentType === "post" ? "post_id" : "product_id", l = async () => {
1996
+ const { data: b, error: v } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq(s, a);
1997
+ if (v)
1998
+ throw new Error(`Failed to read ${o.contentType} blocks: ${_(v)}`);
1999
+ return (Array.isArray(b) ? b : []).sort(
2000
+ (S, E) => Number(S.order) - Number(E.order)
1941
2001
  );
1942
- }, u = (y) => {
2002
+ }, u = (b) => {
1943
2003
  if (n.position === "start")
1944
2004
  return 0;
1945
2005
  if (n.position === "end") {
1946
- const S = y.map((j) => Number(j.order)).filter(Number.isFinite);
1947
- return S.length > 0 ? Math.max(...S) + 1 : 0;
2006
+ const E = b.map((L) => Number(L.order)).filter(Number.isFinite);
2007
+ return E.length > 0 ? Math.max(...E) + 1 : 0;
1948
2008
  }
1949
- const C = n.anchorBlockId ? y.find((S) => Number(S.id) === n.anchorBlockId) : n.anchorBlockType ? y.find((S) => S.block_type === n.anchorBlockType) : null;
1950
- if (!C)
2009
+ const v = n.anchorBlockId ? b.find((E) => Number(E.id) === n.anchorBlockId) : n.anchorBlockType ? b.find((E) => E.block_type === n.anchorBlockType) : null;
2010
+ if (!v)
1951
2011
  throw new Error(
1952
2012
  n.anchorBlockType ? `Could not find a ${n.anchorBlockType} block to insert ${n.position}.` : `Could not find block ${n.anchorBlockId} to insert ${n.position}.`
1953
2013
  );
1954
- const v = Number(C.order);
1955
- return n.position === "before" ? v : v + 1;
1956
- }, d = ae(n.block, 0, t), c = await l(), p = u(c), g = {
2014
+ const S = Number(v.order);
2015
+ return n.position === "before" ? S : S + 1;
2016
+ }, d = ce(n.block, 0, t), c = await l(), p = u(c), h = {
1957
2017
  contentType: o.contentType,
1958
2018
  entityId: o.item.id,
1959
2019
  languageId: o.item.language_id,
@@ -1988,43 +2048,44 @@ async function Ut(e, t) {
1988
2048
  });
1989
2049
  if (m)
1990
2050
  return m;
1991
- const f = await l(), _ = u(f), k = f.filter((y) => Number(y.order) >= _).sort((y, C) => Number(C.order) - Number(y.order));
1992
- for (const y of k) {
1993
- const { error: C } = await r.from("blocks").update({
1994
- order: Number(y.order) + 1,
2051
+ const g = await l(), f = u(g), k = g.filter((b) => Number(b.order) >= f).sort((b, v) => Number(v.order) - Number(b.order));
2052
+ for (const b of k) {
2053
+ const { error: v } = await r.from("blocks").update({
2054
+ order: Number(b.order) + 1,
1995
2055
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
1996
- }).eq("id", y.id);
1997
- if (C)
1998
- throw new Error(`Failed to shift block ${y.id}: ${h(C)}`);
2056
+ }).eq("id", b.id);
2057
+ if (v)
2058
+ throw new Error(`Failed to shift block ${b.id}: ${_(v)}`);
1999
2059
  }
2000
- const { data: w, error: E } = await r.from("blocks").insert({
2060
+ const { data: y, error: w } = await r.from("blocks").insert({
2001
2061
  block_type: d.block_type,
2002
2062
  content: d.content,
2003
2063
  language_id: o.item.language_id,
2004
- order: _,
2064
+ order: f,
2005
2065
  page_id: o.contentType === "page" ? a : null,
2006
- post_id: o.contentType === "post" ? a : null
2066
+ post_id: o.contentType === "post" ? a : null,
2067
+ product_id: o.contentType === "product" ? a : null
2007
2068
  }).select("id, block_type, order").single();
2008
- if (E || !w)
2009
- throw new Error(`Failed to insert content block: ${h(E)}`);
2010
- return Ie([d], r), N(t, g), {
2011
- blockId: w.id,
2012
- blockType: w.block_type,
2069
+ if (w || !y)
2070
+ throw new Error(`Failed to insert content block: ${_(w)}`);
2071
+ return ve([d], r), U(t, h), {
2072
+ blockId: y.id,
2073
+ blockType: y.block_type,
2013
2074
  contentType: o.contentType,
2014
2075
  entityId: o.item.id,
2015
2076
  mutationExecuted: !0,
2016
- order: w.order,
2077
+ order: y.order,
2017
2078
  success: !0
2018
2079
  };
2019
2080
  }
2020
- async function Ft(e, t) {
2021
- const n = de.parse(e), r = I(t), o = D(t), { data: a, error: s } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq("id", n.parentBlockId).single();
2081
+ async function Dt(e, t) {
2082
+ const n = fe.parse(e), r = T(t), o = H(t), { data: a, error: s } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq("id", n.parentBlockId).single();
2022
2083
  if (s || !a)
2023
2084
  throw new Error(
2024
- `Failed to read parent block ${n.parentBlockId}: ${h(s)}`
2085
+ `Failed to read parent block ${n.parentBlockId}: ${_(s)}`
2025
2086
  );
2026
- ht(a, o);
2027
- const l = re(
2087
+ vt(a, o);
2088
+ const l = ae(
2028
2089
  a.block_type,
2029
2090
  `Parent block ${n.parentBlockId}`
2030
2091
  );
@@ -2032,11 +2093,11 @@ async function Ft(e, t) {
2032
2093
  throw new Error(
2033
2094
  `Parent block ${n.parentBlockId} must be a section block, not "${l}".`
2034
2095
  );
2035
- const u = X(
2096
+ const u = ee(
2036
2097
  a.content,
2037
2098
  `Parent block ${n.parentBlockId}`
2038
2099
  );
2039
- L(
2100
+ D(
2040
2101
  l,
2041
2102
  u,
2042
2103
  `Parent block ${n.parentBlockId}`,
@@ -2047,38 +2108,38 @@ async function Ft(e, t) {
2047
2108
  throw new Error(
2048
2109
  `Nested block was not found at column ${n.columnIndex}, index ${n.blockIndex}.`
2049
2110
  );
2050
- const p = re(
2111
+ const p = ae(
2051
2112
  c.block_type,
2052
2113
  `Nested block ${n.columnIndex}:${n.blockIndex}`
2053
2114
  );
2054
- _t(
2115
+ St(
2055
2116
  n.blockType,
2056
2117
  p,
2057
2118
  `Nested block ${n.columnIndex}:${n.blockIndex}`
2058
- ), L(
2119
+ ), D(
2059
2120
  p,
2060
2121
  n.content,
2061
2122
  `Nested block ${n.columnIndex}:${n.blockIndex}`,
2062
2123
  t
2063
2124
  );
2064
- const g = u.column_blocks.map(
2065
- (w, E) => E === n.columnIndex ? w.map(
2066
- (y, C) => C === n.blockIndex ? {
2067
- ...y,
2125
+ const h = u.column_blocks.map(
2126
+ (y, w) => w === n.columnIndex ? y.map(
2127
+ (b, v) => v === n.blockIndex ? {
2128
+ ...b,
2068
2129
  content: n.content
2069
- } : y
2070
- ) : w
2130
+ } : b
2131
+ ) : y
2071
2132
  ), m = {
2072
2133
  ...u,
2073
- column_blocks: g
2134
+ column_blocks: h
2074
2135
  };
2075
- L(
2136
+ D(
2076
2137
  l,
2077
2138
  m,
2078
2139
  `Updated parent block ${n.parentBlockId}`,
2079
2140
  t
2080
2141
  );
2081
- const f = P({
2142
+ const g = P({
2082
2143
  action: "UPDATE NESTED BLOCK",
2083
2144
  context: t,
2084
2145
  payload: {
@@ -2098,28 +2159,28 @@ async function Ft(e, t) {
2098
2159
  },
2099
2160
  subject: `${p} nested block ${n.columnIndex}:${n.blockIndex}`
2100
2161
  });
2101
- if (f)
2102
- return f;
2103
- const { data: _, error: k } = await r.from("blocks").update({
2162
+ if (g)
2163
+ return g;
2164
+ const { data: f, error: k } = await r.from("blocks").update({
2104
2165
  content: m,
2105
2166
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
2106
2167
  }).eq("id", n.parentBlockId).select("id, block_type").single();
2107
- if (k || !_)
2168
+ if (k || !f)
2108
2169
  throw new Error(
2109
- `Failed to update parent block ${n.parentBlockId}: ${h(k)}`
2170
+ `Failed to update parent block ${n.parentBlockId}: ${_(k)}`
2110
2171
  );
2111
- return N(t, o), {
2172
+ return U(t, o), {
2112
2173
  blockIndex: n.blockIndex,
2113
2174
  columnIndex: n.columnIndex,
2114
2175
  mutationExecuted: !0,
2115
2176
  nestedBlockType: p,
2116
- parentBlockId: _.id,
2117
- parentBlockType: _.block_type,
2177
+ parentBlockId: f.id,
2178
+ parentBlockType: f.block_type,
2118
2179
  success: !0
2119
2180
  };
2120
2181
  }
2121
- async function Me(e, t) {
2122
- const n = ge.parse(e), r = I(t), o = Fe(t), a = await ke(r, n.languageCode), s = Y(n.slug || n.title), l = qe(n.blocks, n.contactEmail, n.title, t), u = await Be({
2182
+ async function He(e, t) {
2183
+ const n = _e.parse(e), r = T(t), o = Be(t), a = await xe(r, n.languageCode), s = R(n.slug || n.title), l = Ce(n.blocks, n.contactEmail, n.title, t), u = await Me({
2123
2184
  contentType: "page",
2124
2185
  languageId: a.id,
2125
2186
  slug: s,
@@ -2127,7 +2188,7 @@ async function Me(e, t) {
2127
2188
  });
2128
2189
  if (u)
2129
2190
  return u;
2130
- const d = await Le({
2191
+ const d = await De({
2131
2192
  contentType: "page",
2132
2193
  languageCode: a.code,
2133
2194
  languageId: a.id,
@@ -2165,47 +2226,47 @@ async function Me(e, t) {
2165
2226
  });
2166
2227
  if (p)
2167
2228
  return p;
2168
- const g = d.translationGroupId || Oe(), m = await J(
2229
+ const h = d.translationGroupId || Re(), m = await Z(
2169
2230
  c.item.feature_image_id,
2170
2231
  t,
2171
2232
  n.title
2172
- ), { data: f, error: _ } = await r.from("pages").insert({
2233
+ ), { data: g, error: f } = await r.from("pages").insert({
2173
2234
  ...c.item,
2174
2235
  author_id: o,
2175
2236
  feature_image_id: m,
2176
- translation_group_id: g
2237
+ translation_group_id: h
2177
2238
  }).select("id, language_id, slug, status, title, translation_group_id").single();
2178
- if (_ || !f?.id)
2179
- throw new Error(`Failed to create page: ${h(_)}`);
2239
+ if (f || !g?.id)
2240
+ throw new Error(`Failed to create page: ${_(f)}`);
2180
2241
  try {
2181
- await Tt({
2242
+ await ze({
2182
2243
  blocks: l,
2183
2244
  contentType: "page",
2184
- itemId: Number(f.id),
2245
+ itemId: Number(g.id),
2185
2246
  languageId: a.id,
2186
2247
  supabase: r
2187
2248
  });
2188
2249
  } catch (k) {
2189
- throw await xt({ contentType: "page", itemId: Number(f.id), supabase: r }), k;
2250
+ throw await Ge({ contentType: "page", itemId: Number(g.id), supabase: r }), k;
2190
2251
  }
2191
- return N(
2252
+ return U(
2192
2253
  t,
2193
- { contentType: "page", entityId: Number(f.id), languageId: a.id, slug: s, title: n.title },
2254
+ { contentType: "page", entityId: Number(g.id), languageId: a.id, slug: s, title: n.title },
2194
2255
  s
2195
2256
  ), t?.revalidatePath?.("/cms/pages"), {
2196
2257
  blockCount: l.length,
2197
2258
  contentType: "page",
2198
- editPath: Re("page", f.id),
2199
- entityId: f.id,
2259
+ editPath: Ke("page", g.id),
2260
+ entityId: g.id,
2200
2261
  mutationExecuted: !0,
2201
2262
  slug: s,
2202
2263
  success: !0,
2203
2264
  title: n.title,
2204
- translationGroupId: f.translation_group_id
2265
+ translationGroupId: g.translation_group_id
2205
2266
  };
2206
2267
  }
2207
- async function De(e, t) {
2208
- const n = fe.parse(e), r = I(t), o = Fe(t), a = await ke(r, n.languageCode), s = Y(n.slug || n.title), l = qe(n.blocks, void 0, void 0, t), u = await Be({
2268
+ async function Ve(e, t) {
2269
+ const n = be.parse(e), r = T(t), o = Be(t), a = await xe(r, n.languageCode), s = R(n.slug || n.title), l = Ce(n.blocks, void 0, void 0, t), u = await Me({
2209
2270
  contentType: "post",
2210
2271
  languageId: a.id,
2211
2272
  slug: s,
@@ -2213,7 +2274,7 @@ async function De(e, t) {
2213
2274
  });
2214
2275
  if (u)
2215
2276
  return u;
2216
- const d = await Le({
2277
+ const d = await De({
2217
2278
  contentType: "post",
2218
2279
  languageCode: a.code,
2219
2280
  languageId: a.id,
@@ -2239,7 +2300,7 @@ async function De(e, t) {
2239
2300
  translation_group_id: d.translationGroupId
2240
2301
  },
2241
2302
  tool: "create_cms_post"
2242
- }, g = P({
2303
+ }, h = P({
2243
2304
  action: "CREATE POST",
2244
2305
  context: t,
2245
2306
  payload: p,
@@ -2253,80 +2314,98 @@ async function De(e, t) {
2253
2314
  },
2254
2315
  subject: s
2255
2316
  });
2256
- if (g)
2257
- return g;
2258
- const m = d.translationGroupId || Oe(), f = await J(
2317
+ if (h)
2318
+ return h;
2319
+ const m = d.translationGroupId || Re(), g = await Z(
2259
2320
  p.item.feature_image_id,
2260
2321
  t,
2261
2322
  n.title
2262
- ), { data: _, error: k } = await r.from("posts").insert({
2323
+ ), { data: f, error: k } = await r.from("posts").insert({
2263
2324
  ...p.item,
2264
2325
  author_id: o,
2265
- feature_image_id: f,
2326
+ feature_image_id: g,
2266
2327
  translation_group_id: m
2267
2328
  }).select("id, language_id, slug, status, title, translation_group_id").single();
2268
- if (k || !_?.id)
2269
- throw new Error(`Failed to create post: ${h(k)}`);
2329
+ if (k || !f?.id)
2330
+ throw new Error(`Failed to create post: ${_(k)}`);
2270
2331
  try {
2271
- await Tt({
2332
+ await ze({
2272
2333
  blocks: l,
2273
2334
  contentType: "post",
2274
- itemId: Number(_.id),
2335
+ itemId: Number(f.id),
2275
2336
  languageId: a.id,
2276
2337
  supabase: r
2277
2338
  });
2278
- } catch (w) {
2279
- throw await xt({ contentType: "post", itemId: Number(_.id), supabase: r }), w;
2339
+ } catch (y) {
2340
+ throw await Ge({ contentType: "post", itemId: Number(f.id), supabase: r }), y;
2280
2341
  }
2281
- return N(
2342
+ return U(
2282
2343
  t,
2283
- { contentType: "post", entityId: Number(_.id), languageId: a.id, slug: s, title: n.title },
2344
+ { contentType: "post", entityId: Number(f.id), languageId: a.id, slug: s, title: n.title },
2284
2345
  s
2285
2346
  ), t?.revalidatePath?.("/cms/posts"), t?.revalidatePath?.("/articles"), {
2286
2347
  blockCount: l.length,
2287
2348
  contentType: "post",
2288
- editPath: Re("post", _.id),
2289
- entityId: _.id,
2349
+ editPath: Ke("post", f.id),
2350
+ entityId: f.id,
2290
2351
  mutationExecuted: !0,
2291
2352
  slug: s,
2292
2353
  success: !0,
2293
2354
  title: n.title,
2294
- translationGroupId: _.translation_group_id
2355
+ translationGroupId: f.translation_group_id
2295
2356
  };
2296
2357
  }
2297
- function fr(e, t) {
2298
- return (t || Y(e) || "product").replace(/-/g, "").slice(0, 24).toUpperCase();
2358
+ function vr(e, t) {
2359
+ return (t || R(e) || "product").replace(/-/g, "").slice(0, 24).toUpperCase();
2299
2360
  }
2300
- function Ot(e) {
2301
- if (e === void 0)
2361
+ function zt(e) {
2362
+ if (e == null)
2302
2363
  return;
2303
- const t = fn().safeParse(e);
2304
- if (!t.success)
2364
+ if (typeof e == "string")
2365
+ return dt(e) ?? void 0;
2366
+ const t = Array.isArray(e) ? { content: e, type: "doc" } : A(e) && e.type !== "doc" && Array.isArray(e.content) ? { ...e, type: "doc" } : e, n = Ze().safeParse(t);
2367
+ if (!n.success) {
2368
+ if (A(e) && typeof e.type == "string") {
2369
+ const r = Ze().safeParse({
2370
+ content: [e],
2371
+ type: "doc"
2372
+ });
2373
+ if (r.success)
2374
+ return r.data;
2375
+ }
2305
2376
  throw new Error(
2306
- `Product description_json failed editor document validation: ${t.error.issues.map((n) => n.message).join("; ")}`
2377
+ `Product description_json must be an editor document like { "type": "doc", "content": [ { "type": "paragraph", "content": [ { "type": "text", "text": "..." } ] } ] }, or simply an HTML string. Received: ${n.error.issues.map((r) => r.message).join("; ")}`
2307
2378
  );
2308
- return t.data;
2379
+ }
2380
+ return n.data;
2381
+ }
2382
+ function Sr(e) {
2383
+ const t = (o) => !!(o && Array.isArray(o.content) && o.content.length > 0), n = zt(e.description_json);
2384
+ if (t(n))
2385
+ return n;
2386
+ const r = e.description_html ? dt(e.description_html) : null;
2387
+ return t(r) ? r : void 0;
2309
2388
  }
2310
- async function jt(e, t) {
2311
- const n = he.parse(e), r = I(t), o = await ke(r, n.languageCode), a = Y(n.slug || n.title), s = await Be({
2389
+ async function Gt(e, t) {
2390
+ const n = ke.parse(e), r = T(t), o = await xe(r, n.languageCode), a = R(n.slug || n.title), s = Ce(n.blocks, void 0, void 0, t), l = await Me({
2312
2391
  contentType: "product",
2313
2392
  languageId: o.id,
2314
2393
  slug: a,
2315
2394
  supabase: r
2316
2395
  });
2317
- if (s)
2318
- return s;
2319
- const l = await Le({
2396
+ if (l)
2397
+ return l;
2398
+ const u = await De({
2320
2399
  contentType: "product",
2321
2400
  languageCode: o.code,
2322
2401
  languageId: o.id,
2323
2402
  suppliedTranslationGroupId: n.translationGroupId,
2324
2403
  supabase: r
2325
2404
  });
2326
- if (l.result)
2327
- return l.result;
2328
- const { createProduct: u, productSchema: d } = await In(), p = n.product_type === "digital" && n.payment_provider === "freemius" ? n.trial_period_days : 0, g = d.parse({
2329
- description_json: Ot(n.description_json),
2405
+ if (u.result)
2406
+ return u.result;
2407
+ const { createProduct: d, productSchema: c } = await Un(), h = n.product_type === "digital" && n.payment_provider === "freemius" ? n.trial_period_days : 0, m = c.parse({
2408
+ description_json: Sr(n),
2330
2409
  freemius_plan_id: n.freemius_plan_id || "",
2331
2410
  freemius_product_id: n.freemius_product_id || "",
2332
2411
  is_taxable: n.is_taxable,
@@ -2341,79 +2420,108 @@ async function jt(e, t) {
2341
2420
  sale_price: n.sale_price ?? null,
2342
2421
  sale_prices: n.sale_prices || {},
2343
2422
  short_description: n.short_description ?? "",
2344
- sku: n.sku || fr(n.title, a),
2423
+ sku: n.sku || vr(n.title, a),
2345
2424
  slug: a,
2346
2425
  status: n.status,
2347
2426
  stock: n.stock,
2348
2427
  title: n.title,
2349
- trial_period_days: p,
2350
- trial_requires_payment_method: p > 0 ? n.trial_requires_payment_method : !1,
2351
- translation_group_id: l.translationGroupId,
2428
+ trial_period_days: h,
2429
+ trial_requires_payment_method: h > 0 ? n.trial_requires_payment_method : !1,
2430
+ translation_group_id: u.translationGroupId,
2352
2431
  upc: n.upc ?? "",
2353
2432
  variation_attributes: [],
2354
2433
  variants: []
2355
- }), m = P({
2434
+ }), g = n.images ?? [], f = P({
2356
2435
  action: "CREATE PRODUCT",
2357
2436
  context: t,
2358
- payload: { item: g, tool: "create_cms_product" },
2437
+ payload: { blocks: s, images: g, item: m, tool: "create_cms_product" },
2359
2438
  preview: {
2439
+ blockCount: s.length,
2440
+ descriptionLength: m.description_json ? JSON.stringify(m.description_json).length : 0,
2441
+ imageCount: g.length,
2360
2442
  languageCode: o.code,
2361
- price: g.price,
2362
- sku: g.sku,
2443
+ price: m.price,
2444
+ sku: m.sku,
2363
2445
  slug: a,
2364
- status: g.status,
2365
- stock: g.stock,
2366
- title: g.title,
2367
- translationGroupId: l.translationGroupId
2446
+ status: m.status,
2447
+ stock: m.stock,
2448
+ title: m.title,
2449
+ translationGroupId: u.translationGroupId
2368
2450
  },
2369
2451
  subject: a
2370
2452
  });
2371
- if (m)
2372
- return m;
2373
- const f = await u(r, g);
2374
- if (!f?.id)
2453
+ if (f)
2454
+ return f;
2455
+ let k = [], y = null;
2456
+ if (g.length > 0)
2457
+ try {
2458
+ if (k = [...new Set(await wt(g, t, n.title))], k.length === 0)
2459
+ throw new Error("None of the provided images could be resolved to a media item.");
2460
+ } catch (b) {
2461
+ y = b instanceof Error ? b.message : String(b);
2462
+ }
2463
+ const w = await d(r, {
2464
+ ...m,
2465
+ // First entry is the main product image; the rest become the gallery in order.
2466
+ product_media: k.map((b) => ({ media_id: b }))
2467
+ });
2468
+ if (!w?.id)
2375
2469
  throw new Error("Failed to create product.");
2376
- return N(
2470
+ try {
2471
+ await ze({
2472
+ blocks: s,
2473
+ contentType: "product",
2474
+ itemId: w.id,
2475
+ languageId: o.id,
2476
+ supabase: r
2477
+ });
2478
+ } catch (b) {
2479
+ throw await Ge({ contentType: "product", itemId: w.id, supabase: r }), b;
2480
+ }
2481
+ return U(
2377
2482
  t,
2378
- { contentType: "product", entityId: f.id, languageId: o.id, slug: a, title: n.title },
2483
+ { contentType: "product", entityId: w.id, languageId: o.id, slug: a, title: n.title },
2379
2484
  a
2380
2485
  ), t?.revalidatePath?.("/cms/products"), {
2486
+ blockCount: s.length,
2381
2487
  contentType: "product",
2382
- editPath: Re("product", f.id),
2383
- entityId: f.id,
2488
+ editPath: Ke("product", w.id),
2489
+ entityId: w.id,
2490
+ imageCount: k.length,
2491
+ ...y ? { imageError: y } : {},
2384
2492
  mutationExecuted: !0,
2385
2493
  slug: a,
2386
2494
  success: !0,
2387
2495
  title: n.title,
2388
- translationGroupId: f.translation_group_id
2496
+ translationGroupId: w.translation_group_id
2389
2497
  };
2390
2498
  }
2391
- function Ge(e) {
2499
+ function Je(e) {
2392
2500
  return e.trim().replace(/[\s-]+/g, "_").toLowerCase();
2393
2501
  }
2394
- function hr(e, t) {
2395
- const n = typeof t == "string" ? Ge(t) : t;
2502
+ function Er(e, t) {
2503
+ const n = typeof t == "string" ? Je(t) : t;
2396
2504
  return e === "product" ? n === "public" || n === "publish" || n === "published" ? "active" : n : n === "public" || n === "active" || n === "publish" ? "published" : n;
2397
2505
  }
2398
- function _r(e) {
2399
- const t = Ge(e.field);
2506
+ function $r(e) {
2507
+ const t = Je(e.field);
2400
2508
  return !!(e.startsAt || e.endsAt || t.includes("start") || t.includes("end") || t.includes("schedule") || t.includes("special_date"));
2401
2509
  }
2402
- async function yr(e, t, n) {
2510
+ async function Ar(e, t, n) {
2403
2511
  if (e === "price" || e === "sale_price") {
2404
2512
  if (t == null)
2405
2513
  return { [e]: null };
2406
- const r = await Je(n);
2407
- return { [e]: ft(Number(t), r) };
2514
+ const r = await tt(n);
2515
+ return { [e]: Ct(Number(t), r) };
2408
2516
  }
2409
2517
  if (e === "prices" || e === "sale_prices") {
2410
- const r = await Je(n);
2411
- return { [e]: En(t, r) };
2518
+ const r = await tt(n);
2519
+ return { [e]: Rn(t, r) };
2412
2520
  }
2413
- return e === "description_json" ? { description_json: Ot(t) } : { [e]: t };
2521
+ return e === "description_json" ? { description_json: zt(t) } : { [e]: t };
2414
2522
  }
2415
- function br(e, t) {
2416
- const n = Ge(e.field), r = n === "status" ? hr(t.contentType, e.value) : e.value, a = {
2523
+ function Pr(e, t) {
2524
+ const n = Je(e.field), r = n === "status" ? Er(t.contentType, e.value) : e.value, a = {
2417
2525
  description: "description_json",
2418
2526
  feature_image: "feature_image_id",
2419
2527
  feature_image_id: "feature_image_id",
@@ -2433,12 +2541,12 @@ function br(e, t) {
2433
2541
  type: "product_type"
2434
2542
  }[n] || n;
2435
2543
  if (t.contentType !== "product") {
2436
- if (!(t.contentType === "page" ? Et : $t).has(a))
2544
+ if (!(t.contentType === "page" ? jt : Lt).has(a))
2437
2545
  throw new Error(`Field "${e.field}" cannot be updated for ${t.contentType}.`);
2438
- return a === "status" && Se(t.contentType, r), {
2546
+ return a === "status" && Pe(t.contentType, r), {
2439
2547
  field: a,
2440
2548
  payload: {
2441
- [a]: At(a, r)
2549
+ [a]: Bt(a, r)
2442
2550
  }
2443
2551
  };
2444
2552
  }
@@ -2467,7 +2575,7 @@ function br(e, t) {
2467
2575
  "upc"
2468
2576
  ])).has(a))
2469
2577
  throw new Error(`Field "${e.field}" cannot be updated for product.`);
2470
- if (a === "status" && Se("product", r), (a === "price" || a === "sale_price") && r !== null && (typeof r != "number" || r < 0))
2578
+ if (a === "status" && Pe("product", r), (a === "price" || a === "sale_price") && r !== null && (typeof r != "number" || r < 0))
2471
2579
  throw new Error(`${a} must be a non-negative number or null.`);
2472
2580
  if (a === "stock" && (!Number.isInteger(r) || Number(r) < 0))
2473
2581
  throw new Error("stock must be a non-negative integer.");
@@ -2482,19 +2590,19 @@ function br(e, t) {
2482
2590
  }
2483
2591
  };
2484
2592
  }
2485
- async function qt(e, t) {
2486
- const n = _e.parse(e);
2487
- if (_r(n))
2593
+ async function Kt(e, t) {
2594
+ const n = we.parse(e);
2595
+ if ($r(n))
2488
2596
  return {
2489
2597
  message: "Scheduled product specials are not supported by the current product schema yet. I can set or clear sale_price now, but not start/end dates.",
2490
2598
  mutationExecuted: !1,
2491
2599
  success: !1,
2492
2600
  unsupported: !0
2493
2601
  };
2494
- const r = await we(n, t), o = br(n, r), a = o.field;
2602
+ const r = await te(n, t), o = Pr(n, r), a = o.field;
2495
2603
  let s = o.payload;
2496
2604
  if (a === "language_id" && typeof s.language_id == "string") {
2497
- const p = await G(I(t), s.language_id);
2605
+ const p = await V(T(t), s.language_id);
2498
2606
  s = {
2499
2607
  ...s,
2500
2608
  language_id: p.id
@@ -2523,13 +2631,13 @@ async function qt(e, t) {
2523
2631
  if (l)
2524
2632
  return l;
2525
2633
  if (r.contentType === "product") {
2526
- const p = I(t), g = await yr(a, s[a], p), { data: m, error: f } = await p.from("products").update({
2527
- ...g,
2634
+ const p = T(t), h = await Ar(a, s[a], p), { data: m, error: g } = await p.from("products").update({
2635
+ ...h,
2528
2636
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
2529
2637
  }).eq("id", r.item.id).select("id, language_id, slug, status, title").single();
2530
- if (f || !m)
2531
- throw new Error(`Failed to update product: ${h(f)}`);
2532
- return N(
2638
+ if (g || !m)
2639
+ throw new Error(`Failed to update product: ${_(g)}`);
2640
+ return U(
2533
2641
  t,
2534
2642
  {
2535
2643
  contentType: "product",
@@ -2551,19 +2659,19 @@ async function qt(e, t) {
2551
2659
  }
2552
2660
  a === "feature_image_id" && typeof s.feature_image_id == "string" && (s = {
2553
2661
  ...s,
2554
- feature_image_id: await J(
2662
+ feature_image_id: await Z(
2555
2663
  s.feature_image_id,
2556
2664
  t,
2557
2665
  typeof r.item.title == "string" ? r.item.title : void 0
2558
2666
  )
2559
2667
  });
2560
- const u = r.contentType === "page" ? "pages" : "posts", { data: d, error: c } = await I(t).from(u).update({
2668
+ const u = r.contentType === "page" ? "pages" : "posts", { data: d, error: c } = await T(t).from(u).update({
2561
2669
  ...s,
2562
2670
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
2563
2671
  }).eq("id", r.item.id).select("id, language_id, slug, status, title").single();
2564
2672
  if (c || !d)
2565
- throw new Error(`Failed to update ${r.contentType}: ${h(c)}`);
2566
- return N(
2673
+ throw new Error(`Failed to update ${r.contentType}: ${_(c)}`);
2674
+ return U(
2567
2675
  t,
2568
2676
  {
2569
2677
  contentType: r.contentType,
@@ -2583,53 +2691,53 @@ async function qt(e, t) {
2583
2691
  updatedFields: [a]
2584
2692
  };
2585
2693
  }
2586
- async function Bt(e, t) {
2587
- const n = ct.parse(e), r = await we(n, t);
2694
+ async function Ht(e, t) {
2695
+ const n = yt.parse(e), r = await te(n, t);
2588
2696
  if (r.contentType === "product")
2589
2697
  return {
2590
2698
  affectedCount: 1,
2591
- collectionPath: Xe("product"),
2699
+ collectionPath: rt("product"),
2592
2700
  contentType: "product",
2593
2701
  item: r.item,
2594
2702
  navigationLinkCount: 0,
2595
2703
  publicPaths: r.item.slug ? [`/product/${r.item.slug}`] : [],
2596
2704
  targetIds: [r.item.id]
2597
2705
  };
2598
- const o = r.contentType === "page" ? "pages" : "posts", { data: a, error: s } = await I(t).from(o).select("id, slug, title, translation_group_id").eq("translation_group_id", r.item.translation_group_id);
2706
+ const o = r.contentType === "page" ? "pages" : "posts", { data: a, error: s } = await T(t).from(o).select("id, slug, title, translation_group_id").eq("translation_group_id", r.item.translation_group_id);
2599
2707
  if (s)
2600
- throw new Error(`Failed to inspect related ${r.contentType}s: ${h(s)}`);
2708
+ throw new Error(`Failed to inspect related ${r.contentType}s: ${_(s)}`);
2601
2709
  const l = Array.isArray(a) ? a : [], u = l.map(
2602
2710
  (m) => r.contentType === "page" ? m.slug === "home" ? "/" : `/${m.slug}` : `/article/${m.slug}`
2603
- ).filter(Boolean), d = new Set(u), { data: c, error: p } = await I(t).from("navigation_items").select("id, url");
2711
+ ).filter(Boolean), d = new Set(u), { data: c, error: p } = await T(t).from("navigation_items").select("id, url");
2604
2712
  if (p)
2605
- throw new Error(`Failed to inspect related navigation links: ${h(p)}`);
2606
- const g = (Array.isArray(c) ? c : []).filter(
2713
+ throw new Error(`Failed to inspect related navigation links: ${_(p)}`);
2714
+ const h = (Array.isArray(c) ? c : []).filter(
2607
2715
  (m) => d.has(m.url)
2608
2716
  ).length;
2609
2717
  return {
2610
2718
  affectedCount: l.length,
2611
- collectionPath: Xe(r.contentType),
2719
+ collectionPath: rt(r.contentType),
2612
2720
  contentType: r.contentType,
2613
2721
  item: r.item,
2614
- navigationLinkCount: g,
2722
+ navigationLinkCount: h,
2615
2723
  publicPaths: u,
2616
2724
  targetIds: l.map((m) => m.id)
2617
2725
  };
2618
2726
  }
2619
- function Lt(e) {
2727
+ function Vt(e) {
2620
2728
  const t = e.item.title || e.item.slug || "selected item", n = e.item.slug ? ` (${e.item.slug})` : "";
2621
2729
  if (e.contentType === "product")
2622
2730
  return `Delete product "${t}"${n}.`;
2623
2731
  const r = [
2624
- `${F(e.affectedCount, "language version")}`,
2625
- e.navigationLinkCount > 0 ? `${F(e.navigationLinkCount, "navigation link")}` : null
2732
+ `${N(e.affectedCount, "language version")}`,
2733
+ e.navigationLinkCount > 0 ? `${N(e.navigationLinkCount, "navigation link")}` : null
2626
2734
  ].filter(Boolean);
2627
2735
  return `Delete ${e.contentType} "${t}"${n}, including ${r.join(" and ")}.`;
2628
2736
  }
2629
- async function kr(e, t) {
2630
- const n = await Bt(e, t);
2737
+ async function Nr(e, t) {
2738
+ const n = await Ht(e, t);
2631
2739
  return {
2632
- ...gt({
2740
+ ...xt({
2633
2741
  action: `DELETE ${n.contentType}`,
2634
2742
  payload: {
2635
2743
  affectedCount: n.affectedCount,
@@ -2644,7 +2752,7 @@ async function kr(e, t) {
2644
2752
  navigationLinkCount: n.navigationLinkCount,
2645
2753
  publicPaths: n.publicPaths,
2646
2754
  slug: n.item.slug,
2647
- summary: Lt(n),
2755
+ summary: Vt(n),
2648
2756
  title: n.item.title
2649
2757
  },
2650
2758
  subject: `${n.item.id} ${n.item.slug || ""}`
@@ -2652,8 +2760,8 @@ async function kr(e, t) {
2652
2760
  preparedDelete: !0
2653
2761
  };
2654
2762
  }
2655
- async function Rt(e, t) {
2656
- const n = ye.parse(e), r = await Bt(n, t), o = P({
2763
+ async function Jt(e, t) {
2764
+ const n = Ie.parse(e), r = await Ht(n, t), o = P({
2657
2765
  action: `DELETE ${r.contentType}`,
2658
2766
  context: t,
2659
2767
  payload: {
@@ -2669,26 +2777,26 @@ async function Rt(e, t) {
2669
2777
  navigationLinkCount: r.navigationLinkCount,
2670
2778
  publicPaths: r.publicPaths,
2671
2779
  slug: r.item.slug,
2672
- summary: Lt(r),
2780
+ summary: Vt(r),
2673
2781
  title: r.item.title
2674
2782
  },
2675
2783
  subject: `${r.item.id} ${r.item.slug || ""}`
2676
2784
  });
2677
2785
  if (o)
2678
2786
  return o;
2679
- const a = I(t);
2787
+ const a = T(t);
2680
2788
  if (r.contentType === "product") {
2681
2789
  const { error: l } = await a.from("products").delete().eq("id", r.item.id);
2682
2790
  if (l)
2683
- throw new Error(`Failed to delete product: ${h(l)}`);
2791
+ throw new Error(`Failed to delete product: ${_(l)}`);
2684
2792
  } else {
2685
2793
  for (const d of r.publicPaths)
2686
2794
  await a.from("navigation_items").delete().eq("url", d);
2687
2795
  const l = r.contentType === "page" ? "pages" : "posts", { error: u } = await a.from(l).delete().eq("translation_group_id", r.item.translation_group_id);
2688
2796
  if (u)
2689
- throw new Error(`Failed to delete ${r.contentType}: ${h(u)}`);
2797
+ throw new Error(`Failed to delete ${r.contentType}: ${_(u)}`);
2690
2798
  }
2691
- const s = t?.revalidatePath ?? Ne();
2799
+ const s = t?.revalidatePath ?? je();
2692
2800
  return s && (s(r.collectionPath), s("/cms/navigation"), r.publicPaths.forEach((l) => s(l))), {
2693
2801
  affectedCount: r.affectedCount,
2694
2802
  collectionPath: r.collectionPath,
@@ -2698,33 +2806,35 @@ async function Rt(e, t) {
2698
2806
  success: !0
2699
2807
  };
2700
2808
  }
2701
- async function et(e, t) {
2809
+ async function at(e, t) {
2702
2810
  switch (e.tool) {
2703
2811
  case "create_cms_page":
2704
- return Me(e.input, t);
2812
+ return He(e.input, t);
2705
2813
  case "create_cms_post":
2706
- return De(e.input, t);
2814
+ return Ve(e.input, t);
2707
2815
  case "create_cms_product":
2708
- return jt(e.input, t);
2816
+ return Gt(e.input, t);
2709
2817
  case "delete_cms_item":
2710
- return Rt(e.input, t);
2818
+ return Jt(e.input, t);
2711
2819
  case "update_cms_item_field":
2712
- return qt(e.input, t);
2820
+ return Kt(e.input, t);
2713
2821
  case "update_content_block":
2714
- return Nt(e.input, t);
2822
+ return qt(e.input, t);
2715
2823
  case "insert_content_block":
2716
- return Ut(e.input, t);
2824
+ return Mt(e.input, t);
2717
2825
  case "update_current_cms_fields":
2718
- return Pt(e.input, t);
2826
+ return Rt(e.input, t);
2719
2827
  case "update_footer":
2720
- return vt(e.input, t);
2828
+ return Ot(e.input, t);
2721
2829
  case "update_navigation_bar":
2722
- return Ct(e.input, t);
2830
+ return Ut(e.input, t);
2723
2831
  case "update_section_column_block":
2724
- return Ft(e.input, t);
2832
+ return Dt(e.input, t);
2833
+ case "set_content_images":
2834
+ return rn(e.input, t);
2725
2835
  }
2726
2836
  }
2727
- function wr(e, t) {
2837
+ function Ur(e, t) {
2728
2838
  if (e.tool !== "create_cms_page" && e.tool !== "create_cms_post" && e.tool !== "create_cms_product" || e.input.translationGroupId || !e.input.languageCode)
2729
2839
  return e;
2730
2840
  const n = t[e.tool];
@@ -2736,80 +2846,134 @@ function wr(e, t) {
2736
2846
  }
2737
2847
  } : e;
2738
2848
  }
2739
- async function Ir(e, t) {
2740
- const n = dt.parse(e);
2849
+ function st(e) {
2850
+ return e === "create_cms_page" ? "page" : e === "create_cms_post" ? "post" : "product";
2851
+ }
2852
+ function Or(e, t, n) {
2853
+ if (e.tool !== "set_content_images")
2854
+ return e;
2855
+ const r = e.input;
2856
+ if (r.entityId !== void 0)
2857
+ return e;
2858
+ const o = r.slug ? t.get(
2859
+ `${r.contentType || "product"}:${R(r.slug)}`
2860
+ ) : n;
2861
+ return o ? {
2862
+ ...e,
2863
+ input: {
2864
+ ...r,
2865
+ contentType: o.contentType,
2866
+ entityId: o.entityId
2867
+ }
2868
+ } : e;
2869
+ }
2870
+ async function Fr(e, t) {
2871
+ const n = bt.parse(e), r = new Set(
2872
+ n.actions.filter(
2873
+ (m) => m.tool === "create_cms_page" || m.tool === "create_cms_post" || m.tool === "create_cms_product"
2874
+ ).map((m) => {
2875
+ const g = m.input;
2876
+ return `${st(m.tool)}:${R(g.slug || g.title || "")}`;
2877
+ })
2878
+ ), o = (m) => {
2879
+ if (m.tool !== "set_content_images")
2880
+ return !1;
2881
+ const g = m.input;
2882
+ return g.slug ? r.has(
2883
+ `${g.contentType || "product"}:${R(g.slug)}`
2884
+ ) : r.size > 0;
2885
+ };
2741
2886
  if (!t?.skipConfirmation) {
2742
- const d = [];
2743
- for (const g of n.actions) {
2744
- const m = await et(g, {
2887
+ const m = [];
2888
+ for (const k of n.actions) {
2889
+ if (o(k)) {
2890
+ const w = k.input;
2891
+ m.push(
2892
+ `Set ${N(w.images.length, "image")} on the ${w.slug ? `"${w.slug}"` : "new"} item created in this plan.`
2893
+ );
2894
+ continue;
2895
+ }
2896
+ const y = await at(k, {
2745
2897
  ...t,
2746
2898
  latestUserMessage: null
2747
2899
  });
2748
- if (!m || typeof m != "object")
2900
+ if (!y || typeof y != "object")
2749
2901
  return {
2750
- message: `Could not prepare action ${d.length + 1}.`,
2902
+ message: `Could not prepare action ${m.length + 1}.`,
2751
2903
  mutationExecuted: !1,
2752
2904
  success: !1
2753
2905
  };
2754
- if (m.success === !1 || m.unsupported === !0)
2755
- return m;
2756
- m.requiresConfirmation === !0 && m.preview ? d.push(
2757
- Cn(g.tool, m.preview)
2758
- ) : d.push(`Run ${g.tool.replace(/_/g, " ")}.`);
2906
+ if (y.success === !1 || y.unsupported === !0)
2907
+ return y;
2908
+ y.requiresConfirmation === !0 && y.preview ? m.push(
2909
+ jn(k.tool, y.preview)
2910
+ ) : m.push(`Run ${k.tool.replace(/_/g, " ")}.`);
2759
2911
  }
2760
- const c = n.summary || `Complete ${F(n.actions.length, "CMS action")}.`, p = P({
2912
+ const g = n.summary || `Complete ${N(n.actions.length, "CMS action")}.`, f = P({
2761
2913
  action: "EXECUTE CMS ACTION PLAN",
2762
2914
  context: t,
2763
2915
  payload: { actions: n.actions, tool: "execute_cms_action_plan" },
2764
2916
  preview: {
2765
2917
  actionCount: n.actions.length,
2766
- actionSummaries: d,
2767
- summary: c
2918
+ actionSummaries: m,
2919
+ summary: g
2768
2920
  },
2769
2921
  subject: `${n.actions.length} actions`
2770
2922
  });
2771
- if (p)
2772
- return p;
2923
+ if (f)
2924
+ return f;
2773
2925
  }
2774
- const r = {
2926
+ const a = {
2775
2927
  ...t,
2776
2928
  skipConfirmation: !0
2777
- }, o = [];
2778
- let a = !1, s = null, l = null;
2779
- const u = {};
2780
- for (const [d, c] of n.actions.entries()) {
2781
- const p = wr(c, u), g = await et(p, r);
2782
- if (o.push({ output: g, tool: p.tool }), g && typeof g == "object") {
2783
- const m = g;
2784
- if (m.mutationExecuted === !0 && (a = !0), !s && typeof m.editPath == "string" && (s = m.editPath), typeof m.redirectPath == "string" && (l = m.redirectPath), (p.tool === "create_cms_page" || p.tool === "create_cms_post" || p.tool === "create_cms_product") && typeof m.translationGroupId == "string" && (u[p.tool] = m.translationGroupId), m.success === !1 || m.unsupported === !0)
2929
+ }, s = [];
2930
+ let l = !1, u = null, d = null;
2931
+ const c = {}, p = /* @__PURE__ */ new Map();
2932
+ let h = null;
2933
+ for (const [m, g] of n.actions.entries()) {
2934
+ const f = Or(
2935
+ Ur(g, c),
2936
+ p,
2937
+ h
2938
+ ), k = await at(f, a);
2939
+ if (s.push({ output: k, tool: f.tool }), k && typeof k == "object") {
2940
+ const y = k;
2941
+ if (y.mutationExecuted === !0 && (l = !0), !u && typeof y.editPath == "string" && (u = y.editPath), typeof y.redirectPath == "string" && (d = y.redirectPath), (f.tool === "create_cms_page" || f.tool === "create_cms_post" || f.tool === "create_cms_product") && (typeof y.translationGroupId == "string" && (c[f.tool] = y.translationGroupId), y.entityId !== void 0 && y.entityId !== null)) {
2942
+ const w = st(f.tool), b = {
2943
+ contentType: w,
2944
+ entityId: y.entityId
2945
+ };
2946
+ h = b, typeof y.slug == "string" && p.set(`${w}:${y.slug}`, b);
2947
+ }
2948
+ if (y.success === !1 || y.unsupported === !0)
2785
2949
  return {
2786
2950
  actionCount: n.actions.length,
2787
- failedActionIndex: d,
2788
- failedTool: p.tool,
2789
- message: typeof m.message == "string" ? m.message : `Action ${d + 1} failed.`,
2790
- mutationExecuted: a,
2791
- results: o,
2951
+ failedActionIndex: m,
2952
+ failedTool: f.tool,
2953
+ message: typeof y.message == "string" ? y.message : `Action ${m + 1} failed.`,
2954
+ mutationExecuted: l,
2955
+ results: s,
2792
2956
  success: !1,
2793
- ...s ? { editPath: s } : {},
2794
- ...l ? { redirectPath: l } : {}
2957
+ ...u ? { editPath: u } : {},
2958
+ ...d ? { redirectPath: d } : {}
2795
2959
  };
2796
2960
  }
2797
2961
  }
2798
2962
  return {
2799
2963
  actionCount: n.actions.length,
2800
- editPath: l ? void 0 : s ?? void 0,
2801
- mutationExecuted: a,
2802
- redirectPath: l ?? void 0,
2803
- results: o,
2964
+ editPath: d ? void 0 : u ?? void 0,
2965
+ mutationExecuted: l,
2966
+ redirectPath: d ?? void 0,
2967
+ results: s,
2804
2968
  success: !0,
2805
2969
  summary: n.summary ?? null
2806
2970
  };
2807
2971
  }
2808
- const Mt = i.strictObject({
2972
+ const Wt = i.strictObject({
2809
2973
  maxChars: i.number().int().min(500).max(2e4).default(8e3).describe("Maximum characters of readable body text to return."),
2810
2974
  url: i.string().trim().min(1).max(2048).refine((e) => /^https?:\/\//i.test(e), "URL must start with http:// or https://.")
2811
- }), Tr = 12e3, tt = 2e6;
2812
- function nt(e) {
2975
+ }), jr = 12e3, lt = 2e6;
2976
+ function ct(e) {
2813
2977
  const t = e.trim().toLowerCase().replace(/\.$/, "").replace(/^\[|\]$/g, "");
2814
2978
  if (!t || t === "localhost" || t.endsWith(".localhost") || t.endsWith(".local") || t.endsWith(".internal") || t === "metadata.google.internal" || t === "0.0.0.0" || t === "::1" || t.startsWith("fe80:") || t.startsWith("fc") || t.startsWith("fd"))
2815
2979
  return !0;
@@ -2821,21 +2985,166 @@ function nt(e) {
2821
2985
  }
2822
2986
  return !1;
2823
2987
  }
2824
- function ee(e) {
2988
+ function re(e) {
2825
2989
  return e.replace(/<[^>]+>/g, " ").replace(/&nbsp;/gi, " ").replace(/&amp;/gi, "&").replace(/&lt;/gi, "<").replace(/&gt;/gi, ">").replace(/&quot;/gi, '"').replace(/&#39;/gi, "'").replace(/\s+/g, " ").trim();
2826
2990
  }
2827
- function xr(e, t) {
2828
- const n = e.replace(/<script\b[\s\S]*?<\/script>/gi, " ").replace(/<style\b[\s\S]*?<\/style>/gi, " ").replace(/<noscript\b[\s\S]*?<\/noscript>/gi, " ").replace(/<svg\b[\s\S]*?<\/svg>/gi, " "), r = e.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i), o = e.match(/<meta[^>]+name=["']description["'][^>]*content=["']([^"']*)["'][^>]*>/i) || e.match(/<meta[^>]+content=["']([^"']*)["'][^>]*name=["']description["'][^>]*>/i), a = [...n.matchAll(/<h([1-3])\b[^>]*>([\s\S]*?)<\/h\1>/gi)].map((u) => ee(u[2])).filter(Boolean).slice(0, 40), s = n.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i), l = ee(s?.[1] ?? n);
2991
+ function Lr(e) {
2992
+ return e.trim().replace(/&amp;/gi, "&").replace(/&#38;/g, "&").replace(/&quot;/gi, '"').replace(/&#39;/g, "'");
2993
+ }
2994
+ const Yt = /\.(avif|gif|jpe?g|png|webp)(?:[?#]|$)/i, Xt = /(?:^|[/_-])(?:sprite|icon|favicon|logo|placeholder|pixel|spacer|blank|avatar|badge|flag|loader|spinner|1x1|transparent|watermark|payment|visa|mastercard|paypal|amex|social|share|facebook|twitter|instagram|youtube|pinterest|linkedin)(?:[/_.-]|$)/i;
2995
+ function ue(e, t) {
2996
+ if (typeof e != "string")
2997
+ return null;
2998
+ const n = Lr(e);
2999
+ if (!n || n.startsWith("data:"))
3000
+ return null;
3001
+ try {
3002
+ const r = new URL(n, t);
3003
+ return r.protocol !== "http:" && r.protocol !== "https:" ? null : r.toString();
3004
+ } catch {
3005
+ return null;
3006
+ }
3007
+ }
3008
+ function Br(e) {
3009
+ let t = null;
3010
+ for (const n of e.split(",")) {
3011
+ const r = n.trim().split(/\s+/), o = r[0];
3012
+ if (!o)
3013
+ continue;
3014
+ const a = r[1] || "", s = a.match(/^(\d+(?:\.\d+)?)w$/i), l = a.match(/^(\d+(?:\.\d+)?)x$/i), u = s ? Number(s[1]) : l ? Number(l[1]) * 1e3 : 1;
3015
+ (!t || u > t.weight) && (t = { url: o, weight: u });
3016
+ }
3017
+ return t?.url ?? null;
3018
+ }
3019
+ function F(e, t) {
3020
+ const n = e.match(
3021
+ new RegExp(`\\b${t}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i")
3022
+ );
3023
+ return n ? n[1] ?? n[2] ?? n[3] ?? null : null;
3024
+ }
3025
+ function Rr(e, t) {
3026
+ const n = [], r = [], o = (l, u) => {
3027
+ if (typeof l == "string") {
3028
+ const d = ue(l, t);
3029
+ d && u.push(d);
3030
+ return;
3031
+ }
3032
+ if (Array.isArray(l)) {
3033
+ for (const d of l)
3034
+ o(d, u);
3035
+ return;
3036
+ }
3037
+ l && typeof l == "object" && (o(l.url, u), o(l.contentUrl, u));
3038
+ }, a = (l, u) => {
3039
+ if (u > 8 || !l || typeof l != "object")
3040
+ return;
3041
+ if (Array.isArray(l)) {
3042
+ for (const m of l)
3043
+ a(m, u + 1);
3044
+ return;
3045
+ }
3046
+ const d = l, c = d["@type"], h = (Array.isArray(c) ? c : [c]).filter((m) => typeof m == "string").map((m) => m.toLowerCase()).some(
3047
+ (m) => m === "product" || m === "productgroup" || m === "itempage"
3048
+ );
3049
+ "image" in d && o(d.image, h ? n : r);
3050
+ for (const m of Object.values(d))
3051
+ a(m, u + 1);
3052
+ }, s = e.matchAll(
3053
+ /<script\b[^>]*type\s*=\s*["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi
3054
+ );
3055
+ for (const l of s) {
3056
+ const u = (l[1] || "").trim();
3057
+ if (u)
3058
+ try {
3059
+ a(JSON.parse(u), 0);
3060
+ } catch {
3061
+ }
3062
+ }
3063
+ return [...n, ...r];
3064
+ }
3065
+ const Qt = /(?:^|[/_-])(?:thumbnails?|thumbs?|small|mini)(?:[/_.-]|$)/i;
3066
+ function Zt(e) {
3067
+ try {
3068
+ const { pathname: t } = new URL(e);
3069
+ return decodeURIComponent(t.slice(t.lastIndexOf("/") + 1)).toLowerCase() || null;
3070
+ } catch {
3071
+ return null;
3072
+ }
3073
+ }
3074
+ function qr(e, t) {
3075
+ const n = /* @__PURE__ */ new Map();
3076
+ for (const r of e.matchAll(/<a\b[^>]*>/gi)) {
3077
+ const o = ue(F(r[0], "href"), t);
3078
+ if (!o || !Yt.test(o) || Qt.test(o) || Xt.test(o))
3079
+ continue;
3080
+ const a = Zt(o);
3081
+ a && !n.has(a) && n.set(a, o);
3082
+ }
3083
+ return n;
3084
+ }
3085
+ function Mr(e, t) {
3086
+ const n = [...Rr(e, t)], r = [
3087
+ /<meta\b[^>]*\b(?:property|name)\s*=\s*["'](?:og:image:secure_url|og:image:url|og:image)["'][^>]*>/gi,
3088
+ /<meta\b[^>]*\b(?:property|name)\s*=\s*["'](?:twitter:image:src|twitter:image)["'][^>]*>/gi,
3089
+ /<meta\b[^>]*\bitemprop\s*=\s*["']image["'][^>]*>/gi,
3090
+ /<link\b[^>]*\brel\s*=\s*["']image_src["'][^>]*>/gi
3091
+ ];
3092
+ for (const c of r)
3093
+ for (const p of e.matchAll(c)) {
3094
+ const h = p[0], m = ue(
3095
+ F(h, "content") || F(h, "href"),
3096
+ t
3097
+ );
3098
+ m && n.push(m);
3099
+ }
3100
+ const o = [];
3101
+ for (const c of e.matchAll(/<img\b[^>]*>/gi)) {
3102
+ const p = c[0], h = F(p, "srcset") || F(p, "data-srcset"), m = [
3103
+ h ? Br(h) : null,
3104
+ F(p, "src"),
3105
+ F(p, "data-src"),
3106
+ F(p, "data-original"),
3107
+ F(p, "data-lazy-src"),
3108
+ F(p, "data-image")
3109
+ ];
3110
+ let g = null;
3111
+ for (const k of m)
3112
+ if (g = ue(k, t), g)
3113
+ break;
3114
+ if (!g || Xt.test(g))
3115
+ continue;
3116
+ const f = Number(F(p, "width"));
3117
+ Number.isFinite(f) && f > 0 && f < 200 || o.push(g);
3118
+ }
3119
+ const a = (c) => Yt.test(c);
3120
+ n.push(...o.filter(a), ...o.filter((c) => !a(c)));
3121
+ const s = qr(e, t), l = (c) => {
3122
+ if (!Qt.test(c))
3123
+ return c;
3124
+ const p = Zt(c);
3125
+ return p && s.get(p) || c;
3126
+ }, u = /* @__PURE__ */ new Set(), d = [];
3127
+ for (const c of n) {
3128
+ const p = l(c);
3129
+ if (!u.has(p) && (u.add(p), d.push(p), d.length >= 12))
3130
+ break;
3131
+ }
3132
+ return { images: d, mainImage: d[0] ?? null };
3133
+ }
3134
+ function Dr(e, t, n) {
3135
+ const r = e.replace(/<script\b[\s\S]*?<\/script>/gi, " ").replace(/<style\b[\s\S]*?<\/style>/gi, " ").replace(/<noscript\b[\s\S]*?<\/noscript>/gi, " ").replace(/<svg\b[\s\S]*?<\/svg>/gi, " "), { images: o, mainImage: a } = Mr(e, n), s = e.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i), l = e.match(/<meta[^>]+name=["']description["'][^>]*content=["']([^"']*)["'][^>]*>/i) || e.match(/<meta[^>]+content=["']([^"']*)["'][^>]*name=["']description["'][^>]*>/i), u = [...r.matchAll(/<h([1-3])\b[^>]*>([\s\S]*?)<\/h\1>/gi)].map((p) => re(p[2])).filter(Boolean).slice(0, 40), d = r.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i), c = re(d?.[1] ?? r);
2829
3136
  return {
2830
- description: o ? ee(o[1]) : "",
2831
- headings: a,
2832
- text: l.slice(0, t),
2833
- title: r ? ee(r[1]) : "",
2834
- truncated: l.length > t
3137
+ description: l ? re(l[1]) : "",
3138
+ headings: u,
3139
+ images: o,
3140
+ mainImage: a,
3141
+ text: c.slice(0, t),
3142
+ title: s ? re(s[1]) : "",
3143
+ truncated: c.length > t
2835
3144
  };
2836
3145
  }
2837
- async function Cr(e) {
2838
- const t = Mt.parse(e);
3146
+ async function zr(e) {
3147
+ const t = Wt.parse(e);
2839
3148
  let n;
2840
3149
  try {
2841
3150
  n = new URL(t.url);
@@ -2844,13 +3153,13 @@ async function Cr(e) {
2844
3153
  }
2845
3154
  if (n.protocol !== "http:" && n.protocol !== "https:")
2846
3155
  return { message: "Only http and https URLs can be fetched.", success: !1, url: t.url };
2847
- if (nt(n.hostname))
3156
+ if (ct(n.hostname))
2848
3157
  return {
2849
3158
  message: "Refusing to fetch a local, private, or internal address.",
2850
3159
  success: !1,
2851
3160
  url: t.url
2852
3161
  };
2853
- const r = new AbortController(), o = setTimeout(() => r.abort(), Tr);
3162
+ const r = new AbortController(), o = setTimeout(() => r.abort(), jr);
2854
3163
  try {
2855
3164
  const a = await fetch(n.toString(), {
2856
3165
  headers: {
@@ -2869,7 +3178,7 @@ async function Cr(e) {
2869
3178
  };
2870
3179
  const s = a.url || n.toString();
2871
3180
  try {
2872
- if (nt(new URL(s).hostname))
3181
+ if (ct(new URL(s).hostname))
2873
3182
  return {
2874
3183
  message: "The URL redirected to a blocked internal address.",
2875
3184
  success: !1,
@@ -2885,11 +3194,17 @@ async function Cr(e) {
2885
3194
  success: !1,
2886
3195
  url: t.url
2887
3196
  };
2888
- const u = await a.text(), d = u.length > tt ? u.slice(0, tt) : u, c = xr(d, t.maxChars);
3197
+ const u = await a.text(), d = u.length > lt ? u.slice(0, lt) : u, c = Dr(d, t.maxChars, s);
2889
3198
  return !c.text && !c.title ? { message: "The URL returned no readable text content.", success: !1, url: t.url } : {
2890
3199
  description: c.description,
2891
3200
  finalUrl: s,
2892
3201
  headings: c.headings,
3202
+ // Ranked best-first (schema.org Product image > og:image > in-body <img>).
3203
+ // `mainImage` is the page's subject image and can be passed straight into
3204
+ // create_cms_product `images` / feature_image_id — it is imported into the
3205
+ // media library automatically.
3206
+ images: c.images,
3207
+ mainImage: c.mainImage,
2893
3208
  success: !0,
2894
3209
  text: c.text,
2895
3210
  title: c.title,
@@ -2898,7 +3213,7 @@ async function Cr(e) {
2898
3213
  };
2899
3214
  } catch (a) {
2900
3215
  return {
2901
- message: a instanceof Error && (a.name === "AbortError" || /abort/i.test(a.message)) ? "Fetching the URL timed out." : `Failed to fetch the URL: ${h(a)}`,
3216
+ message: a instanceof Error && (a.name === "AbortError" || /abort/i.test(a.message)) ? "Fetching the URL timed out." : `Failed to fetch the URL: ${_(a)}`,
2902
3217
  success: !1,
2903
3218
  url: t.url
2904
3219
  };
@@ -2906,12 +3221,12 @@ async function Cr(e) {
2906
3221
  clearTimeout(o);
2907
3222
  }
2908
3223
  }
2909
- const Dt = i.strictObject({
3224
+ const en = i.strictObject({
2910
3225
  count: i.number().int().min(1).max(15).default(6),
2911
3226
  orientation: i.enum(["landscape", "portrait", "square"]).optional().describe("Preferred image orientation. Use landscape for hero/section backgrounds."),
2912
3227
  query: i.string().trim().min(2).max(200).describe('What the photos should depict, e.g. "herbal supplements".')
2913
- }), vr = 12e3;
2914
- async function ze(e) {
3228
+ }), Gr = 12e3;
3229
+ async function We(e) {
2915
3230
  let t = null, n = null;
2916
3231
  if (e)
2917
3232
  try {
@@ -2932,10 +3247,10 @@ async function ze(e) {
2932
3247
  const r = [];
2933
3248
  return t && r.push({ apiKey: t, provider: "pexels" }), n && r.push({ apiKey: n, provider: "unsplash" }), r;
2934
3249
  }
2935
- async function Gr(e) {
2936
- return (await ze(e))[0] ?? null;
3250
+ async function so(e) {
3251
+ return (await We(e))[0] ?? null;
2937
3252
  }
2938
- async function Sr(e) {
3253
+ async function Kr(e) {
2939
3254
  if (e)
2940
3255
  try {
2941
3256
  const { CORTEX_AI_UNSPLASH_APP_NAME_SETTING_KEY: t } = await import("./ai-config.es.js"), { data: n } = await e.from("site_settings").select("value").eq("key", t).maybeSingle(), r = n?.value;
@@ -2945,8 +3260,8 @@ async function Sr(e) {
2945
3260
  }
2946
3261
  return process.env.UNSPLASH_APP_NAME?.trim() || null;
2947
3262
  }
2948
- async function rt(e, t) {
2949
- const n = new AbortController(), r = setTimeout(() => n.abort(), vr);
3263
+ async function ut(e, t) {
3264
+ const n = new AbortController(), r = setTimeout(() => n.abort(), Gr);
2950
3265
  try {
2951
3266
  const o = await fetch(e, { headers: t, signal: n.signal });
2952
3267
  if (!o.ok)
@@ -2956,11 +3271,11 @@ async function rt(e, t) {
2956
3271
  clearTimeout(r);
2957
3272
  }
2958
3273
  }
2959
- function te(e) {
3274
+ function oe(e) {
2960
3275
  const t = Number(e);
2961
3276
  return Number.isFinite(t) && t > 0 ? t : null;
2962
3277
  }
2963
- function Ee(e, t) {
3278
+ function Ne(e, t) {
2964
3279
  if (!A(e))
2965
3280
  return;
2966
3281
  const n = (r) => {
@@ -2970,20 +3285,20 @@ function Ee(e, t) {
2970
3285
  for (const r of e.column_blocks)
2971
3286
  if (Array.isArray(r))
2972
3287
  for (const o of r)
2973
- A(o) && Ee(o.content, t);
3288
+ A(o) && Ne(o.content, t);
2974
3289
  }
2975
3290
  if (Array.isArray(e.slides))
2976
3291
  for (const r of e.slides)
2977
- Ee(r, t);
3292
+ Ne(r, t);
2978
3293
  }
2979
- async function Ie(e, t) {
3294
+ async function ve(e, t) {
2980
3295
  try {
2981
3296
  const n = /* @__PURE__ */ new Set();
2982
3297
  for (const a of e)
2983
- Ee(a?.content, n);
3298
+ Ne(a?.content, n);
2984
3299
  if (n.size === 0)
2985
3300
  return;
2986
- const o = (await ze(t)).find((a) => a.provider === "unsplash");
3301
+ const o = (await We(t)).find((a) => a.provider === "unsplash");
2987
3302
  if (!o)
2988
3303
  return;
2989
3304
  await Promise.all(
@@ -2997,13 +3312,13 @@ async function Ie(e, t) {
2997
3312
  } catch {
2998
3313
  }
2999
3314
  }
3000
- async function Er(e, t, n) {
3315
+ async function Hr(e, t, n) {
3001
3316
  const r = new URLSearchParams({
3002
3317
  per_page: String(t.count),
3003
3318
  query: t.query
3004
3319
  });
3005
3320
  if (t.orientation && r.set("orientation", t.orientation), e.provider === "pexels") {
3006
- const a = await rt(
3321
+ const a = await ut(
3007
3322
  `https://api.pexels.com/v1/search?${r.toString()}`,
3008
3323
  { Authorization: e.apiKey }
3009
3324
  );
@@ -3013,18 +3328,18 @@ async function Er(e, t, n) {
3013
3328
  alt: typeof s?.alt == "string" && s.alt.trim() ? s.alt.trim() : t.query,
3014
3329
  credit: l ? `Photo by ${l} on Pexels` : "Photo on Pexels",
3015
3330
  downloadLocation: null,
3016
- height: te(s?.height),
3331
+ height: oe(s?.height),
3017
3332
  photographer: l,
3018
3333
  photographerUrl: typeof s?.photographer_url == "string" ? s.photographer_url : null,
3019
3334
  provider: "pexels",
3020
3335
  sourceUrl: typeof s?.url == "string" ? s.url : null,
3021
3336
  thumbnailUrl: s?.src?.medium || s?.src?.large || null,
3022
3337
  url: s?.src?.large2x || s?.src?.large || s?.src?.original || null,
3023
- width: te(s?.width)
3338
+ width: oe(s?.width)
3024
3339
  };
3025
3340
  }).filter((s) => typeof s.url == "string");
3026
3341
  }
3027
- const o = await rt(
3342
+ const o = await ut(
3028
3343
  `https://api.unsplash.com/search/photos?${r.toString()}`,
3029
3344
  { Authorization: `Client-ID ${e.apiKey}` }
3030
3345
  );
@@ -3036,7 +3351,7 @@ async function Er(e, t, n) {
3036
3351
  // Unsplash requires triggering this endpoint when the photo is actually
3037
3352
  // used; carry it so the block-persist path can fire it.
3038
3353
  downloadLocation: typeof a?.links?.download_location == "string" ? a.links.download_location : null,
3039
- height: te(a?.height),
3354
+ height: oe(a?.height),
3040
3355
  photographer: s,
3041
3356
  photographerUrl: typeof a?.user?.links?.html == "string" ? a.user.links.html : null,
3042
3357
  provider: "unsplash",
@@ -3045,24 +3360,24 @@ async function Er(e, t, n) {
3045
3360
  url: a?.urls?.regular || a?.urls?.full || a?.urls?.raw || null,
3046
3361
  // The operator's registered Unsplash app name for the attribution utm_source.
3047
3362
  utmSource: n || null,
3048
- width: te(a?.width)
3363
+ width: oe(a?.width)
3049
3364
  };
3050
3365
  }).filter((a) => typeof a.url == "string");
3051
3366
  }
3052
- async function $r(e, t) {
3053
- const n = Dt.parse(e), r = await ze(t?.supabase);
3367
+ async function Vr(e, t) {
3368
+ const n = en.parse(e), r = await We(t?.supabase);
3054
3369
  if (r.length === 0)
3055
3370
  return {
3056
3371
  message: "No stock photo provider is configured. Add a free Pexels or Unsplash API key in /cms/settings/cortex-ai (or set PEXELS_API_KEY / UNSPLASH_ACCESS_KEY).",
3057
3372
  photos: [],
3058
3373
  success: !1
3059
3374
  };
3060
- const o = r.some((l) => l.provider === "unsplash") ? await Sr(t?.supabase) : null, a = [];
3375
+ const o = r.some((l) => l.provider === "unsplash") ? await Kr(t?.supabase) : null, a = [];
3061
3376
  let s = null;
3062
3377
  for (const l of r) {
3063
3378
  a.push(l.provider);
3064
3379
  try {
3065
- const u = await Er(l, n, o);
3380
+ const u = await Hr(l, n, o);
3066
3381
  if (u.length > 0)
3067
3382
  return {
3068
3383
  attemptedProviders: a,
@@ -3078,13 +3393,13 @@ async function $r(e, t) {
3078
3393
  }
3079
3394
  return {
3080
3395
  attemptedProviders: a,
3081
- message: s ? `Stock photo search failed across ${a.join(", ")}: ${h(s)}` : `No matching stock photos found for "${n.query}".`,
3396
+ message: s ? `Stock photo search failed across ${a.join(", ")}: ${_(s)}` : `No matching stock photos found for "${n.query}".`,
3082
3397
  photos: [],
3083
3398
  success: !1
3084
3399
  };
3085
3400
  }
3086
- const Gt = W.extend({
3087
- blocks: i.array(pe).min(1).max(20),
3401
+ const tn = K.extend({
3402
+ blocks: i.array(Q).min(1).max(20),
3088
3403
  meta: i.strictObject({
3089
3404
  meta_description: i.string().max(500).nullable().optional(),
3090
3405
  meta_title: i.string().max(160).nullable().optional(),
@@ -3092,7 +3407,7 @@ const Gt = W.extend({
3092
3407
  status: i.enum(["draft", "published", "archived"]).optional(),
3093
3408
  title: i.string().trim().min(1).max(300).optional()
3094
3409
  }).partial().optional()
3095
- }), Ar = [
3410
+ }), Jr = [
3096
3411
  "custom_canonical",
3097
3412
  "excerpt",
3098
3413
  "feature_image_id",
@@ -3107,20 +3422,20 @@ const Gt = W.extend({
3107
3422
  "title",
3108
3423
  "translation_group_id"
3109
3424
  ];
3110
- function Pr(e) {
3425
+ function Wr(e) {
3111
3426
  const t = {};
3112
- for (const n of Ar)
3427
+ for (const n of Jr)
3113
3428
  n in e && e[n] !== void 0 && (t[n] = e[n]);
3114
3429
  return t;
3115
3430
  }
3116
- function Nr(e, t) {
3431
+ function Yr(e, t) {
3117
3432
  if (!t)
3118
3433
  return null;
3119
3434
  const n = e === "page" ? t === "home" ? "/" : `/${t}` : `/article/${t}`;
3120
3435
  return `/api/draft/start?path=${encodeURIComponent(n)}`;
3121
3436
  }
3122
- async function Ur(e, t) {
3123
- const n = Gt.parse(e), r = I(t), o = Fe(t), a = await we(n, t);
3437
+ async function Xr(e, t) {
3438
+ const n = tn.parse(e), r = T(t), o = Be(t), a = await te(n, t);
3124
3439
  if (a.contentType === "product")
3125
3440
  throw new Error(
3126
3441
  "rewrite_page_draft supports pages and posts only. Products use description_json, not page blocks."
@@ -3131,21 +3446,21 @@ async function Ur(e, t) {
3131
3446
  const u = Number(a.item.language_id);
3132
3447
  if (!Number.isInteger(u) || u <= 0)
3133
3448
  throw new Error("The target page/post is missing a language id.");
3134
- const c = qe(n.blocks, void 0, void 0, t).map((v, S) => ({
3135
- block_type: v.block_type,
3136
- content: v.content,
3449
+ const c = Ce(n.blocks, void 0, void 0, t).map((S, E) => ({
3450
+ block_type: S.block_type,
3451
+ content: S.content,
3137
3452
  language_id: u,
3138
- order: S,
3453
+ order: E,
3139
3454
  page_id: s === "page" ? l : null,
3140
3455
  post_id: s === "post" ? l : null,
3141
3456
  product_id: null
3142
- })), p = Pr(a.item);
3457
+ })), p = Wr(a.item);
3143
3458
  if (n.meta)
3144
- for (const [v, S] of Object.entries(n.meta))
3145
- S !== void 0 && (p[v] = S);
3146
- const g = pt(
3459
+ for (const [S, E] of Object.entries(n.meta))
3460
+ E !== void 0 && (p[S] = E);
3461
+ const h = It(
3147
3462
  typeof p.slug == "string" ? p.slug : a.item.slug
3148
- ), m = typeof p.title == "string" && p.title.trim() ? p.title : String(a.item.title || g || "Untitled"), f = s === "page" ? `/cms/pages/${l}/edit` : `/cms/posts/${l}/edit`, _ = Nr(s, g), w = P({
3463
+ ), m = typeof p.title == "string" && p.title.trim() ? p.title : String(a.item.title || h || "Untitled"), g = s === "page" ? `/cms/pages/${l}/edit` : `/cms/posts/${l}/edit`, f = Yr(s, h), y = P({
3149
3464
  action: "REWRITE DRAFT",
3150
3465
  context: t,
3151
3466
  payload: {
@@ -3158,8 +3473,8 @@ async function Ur(e, t) {
3158
3473
  preview: {
3159
3474
  blockCount: c.length,
3160
3475
  contentType: s,
3161
- slug: g,
3162
- summary: `Stage a Live Draft that replaces the ${s} "${m}" with ${F(
3476
+ slug: h,
3477
+ summary: `Stage a Live Draft that replaces the ${s} "${m}" with ${N(
3163
3478
  c.length,
3164
3479
  "new block"
3165
3480
  )}. Nothing goes live until you review the draft and click Publish (which also saves a revision snapshot).`,
@@ -3167,39 +3482,39 @@ async function Ur(e, t) {
3167
3482
  },
3168
3483
  subject: `${s}-${l}`
3169
3484
  });
3170
- if (w)
3171
- return w;
3172
- const E = Number(a.item.version) || 1, { error: y } = await r.from("content_drafts").delete().eq("parent_type", s).eq("parent_id", l);
3173
3485
  if (y)
3174
- throw new Error(`Failed to clear the existing draft: ${h(y)}`);
3175
- const { error: C } = await r.from("content_drafts").insert({
3486
+ return y;
3487
+ const w = Number(a.item.version) || 1, { error: b } = await r.from("content_drafts").delete().eq("parent_type", s).eq("parent_id", l);
3488
+ if (b)
3489
+ throw new Error(`Failed to clear the existing draft: ${_(b)}`);
3490
+ const { error: v } = await r.from("content_drafts").insert({
3176
3491
  author_id: o,
3177
- base_version: E,
3492
+ base_version: w,
3178
3493
  blocks: c,
3179
3494
  meta: p,
3180
3495
  parent_id: l,
3181
3496
  parent_type: s
3182
3497
  });
3183
- if (C)
3184
- throw new Error(`Failed to save the draft: ${h(C)}`);
3185
- return Ie(c, r), N(
3498
+ if (v)
3499
+ throw new Error(`Failed to save the draft: ${_(v)}`);
3500
+ return ve(c, r), U(
3186
3501
  t,
3187
- { contentType: s, entityId: l, slug: g },
3188
- g
3502
+ { contentType: s, entityId: l, slug: h },
3503
+ h
3189
3504
  ), {
3190
3505
  blockCount: c.length,
3191
3506
  contentType: s,
3192
- draftPreviewPath: _,
3193
- editPath: f,
3507
+ draftPreviewPath: f,
3508
+ editPath: g,
3194
3509
  entityId: l,
3195
3510
  isDraft: !0,
3196
3511
  mutationExecuted: !0,
3197
- slug: g,
3512
+ slug: h,
3198
3513
  success: !0,
3199
3514
  title: m
3200
3515
  };
3201
3516
  }
3202
- const Fr = /* @__PURE__ */ new Set([
3517
+ const Qr = /* @__PURE__ */ new Set([
3203
3518
  "alt_text",
3204
3519
  "author_name",
3205
3520
  "author_title",
@@ -3214,7 +3529,7 @@ const Fr = /* @__PURE__ */ new Set([
3214
3529
  "text_content",
3215
3530
  "title"
3216
3531
  ]);
3217
- function $e(e, t, n) {
3532
+ function Ue(e, t, n) {
3218
3533
  if (!e)
3219
3534
  return e;
3220
3535
  if (Object.prototype.hasOwnProperty.call(t, e))
@@ -3227,357 +3542,363 @@ function $e(e, t, n) {
3227
3542
  a && o.includes(a) && (o = o.split(a).join(s));
3228
3543
  return o;
3229
3544
  }
3230
- function Ae(e, t, n) {
3545
+ function Oe(e, t, n) {
3231
3546
  if (Array.isArray(e))
3232
- return e.map((r) => Ae(r, t, n));
3547
+ return e.map((r) => Oe(r, t, n));
3233
3548
  if (e && typeof e == "object") {
3234
3549
  const r = {};
3235
3550
  for (const [o, a] of Object.entries(e))
3236
- typeof a == "string" && Fr.has(o) ? r[o] = $e(a, t, n) : a && typeof a == "object" ? r[o] = Ae(a, t, n) : r[o] = a;
3551
+ typeof a == "string" && Qr.has(o) ? r[o] = Ue(a, t, n) : a && typeof a == "object" ? r[o] = Oe(a, t, n) : r[o] = a;
3237
3552
  return r;
3238
3553
  }
3239
3554
  return e;
3240
3555
  }
3241
- const zt = i.strictObject({
3556
+ const nn = i.strictObject({
3242
3557
  targetLanguageCode: i.string().trim().min(2).max(80).describe('Target language code or name, e.g. "fr" or "French".'),
3243
3558
  title: i.string().trim().min(1).max(300).optional().describe("Translated page title (defaults to translating the source title)."),
3244
3559
  translations: i.record(i.string(), i.string()).describe(
3245
3560
  'Map of every visible source string to its translation, e.g. { "Explore Our Products": "Explorez nos produits" }. Include headings, paragraph text, button labels, image alt text, captions, and form labels.'
3246
3561
  )
3247
3562
  });
3248
- async function Or(e, t) {
3249
- const n = zt.parse(e), r = D(t);
3563
+ async function Zr(e, t) {
3564
+ const n = nn.parse(e), r = H(t);
3250
3565
  if (r.contentType === "product")
3251
3566
  throw new Error("translate_page supports pages and posts only.");
3252
- const o = I(t), a = Ue(r), s = r.contentType === "page" ? "pages" : "posts", l = r.contentType === "page" ? "page_id" : "post_id", { data: u, error: d } = await o.from(s).select("*").eq("id", a).single();
3567
+ const o = T(t), a = Le(r), s = r.contentType === "page" ? "pages" : "posts", l = r.contentType === "page" ? "page_id" : "post_id", { data: u, error: d } = await o.from(s).select("*").eq("id", a).single();
3253
3568
  if (d || !u)
3254
3569
  throw new Error(
3255
- `Could not read the source ${r.contentType} to translate: ${h(d)}`
3570
+ `Could not read the source ${r.contentType} to translate: ${_(d)}`
3256
3571
  );
3257
3572
  const { data: c, error: p } = await o.from("blocks").select("id, block_type, content, order").eq(l, a);
3258
3573
  if (p)
3259
- throw new Error(`Could not read the source blocks: ${h(p)}`);
3260
- const g = (Array.isArray(c) ? c : []).slice().sort((b, $) => Number(b.order) - Number($.order));
3261
- if (g.length === 0)
3574
+ throw new Error(`Could not read the source blocks: ${_(p)}`);
3575
+ const h = (Array.isArray(c) ? c : []).slice().sort((I, $) => Number(I.order) - Number($.order));
3576
+ if (h.length === 0)
3262
3577
  throw new Error(`The source ${r.contentType} has no content blocks to translate.`);
3263
- const m = n.translations || {}, f = Object.entries(m).filter(([b]) => !!b).sort((b, $) => $[0].length - b[0].length), _ = g.map((b, $) => ({
3264
- blockType: b.block_type,
3265
- content: Ae(H(b.content), m, f),
3578
+ const m = n.translations || {}, g = Object.entries(m).filter(([I]) => !!I).sort((I, $) => $[0].length - I[0].length), f = h.map((I, $) => ({
3579
+ blockType: I.block_type,
3580
+ content: Oe(X(I.content), m, g),
3266
3581
  order: $
3267
- })), k = await ke(o, n.targetLanguageCode), w = String(u.title || ""), E = n.title || $e(w, m, f) || w || "Untitled", y = (b) => typeof b == "string" && b.trim() ? $e(b, m, f) : void 0, C = Y(E) || u.slug || "translated-page", v = {
3268
- blocks: _,
3582
+ })), k = await xe(o, n.targetLanguageCode), y = String(u.title || ""), w = n.title || Ue(y, m, g) || y || "Untitled", b = (I) => typeof I == "string" && I.trim() ? Ue(I, m, g) : void 0, v = R(w) || u.slug || "translated-page", S = {
3583
+ blocks: f,
3269
3584
  feature_image_id: u.feature_image_id ?? void 0,
3270
3585
  languageCode: k.code,
3271
- meta_description: y(u.meta_description),
3272
- meta_title: y(u.meta_title),
3273
- slug: C,
3586
+ meta_description: b(u.meta_description),
3587
+ meta_title: b(u.meta_title),
3588
+ slug: v,
3274
3589
  // Publish the translation immediately so it goes live the moment the owner
3275
3590
  // confirms — the localized homepage/page is then reachable and the public
3276
3591
  // language switcher can find it (drafts are filtered out of public lookups).
3277
3592
  status: "published",
3278
- title: E,
3593
+ title: w,
3279
3594
  translationGroupId: u.translation_group_id || void 0
3280
- }, S = r.contentType === "post" ? {
3281
- ...v,
3282
- excerpt: y(u.excerpt),
3283
- label: y(u.label),
3595
+ }, E = r.contentType === "post" ? {
3596
+ ...S,
3597
+ excerpt: b(u.excerpt),
3598
+ label: b(u.label),
3284
3599
  // Inherit the source post's publish date (or "now" if it has none) so a
3285
3600
  // published translation sorts alongside its original in the article list
3286
3601
  // instead of jumping to the top with a null published_at.
3287
3602
  published_at: u.published_at ?? (/* @__PURE__ */ new Date()).toISOString(),
3288
- subtitle: y(u.subtitle)
3289
- } : v, j = P({
3603
+ subtitle: b(u.subtitle)
3604
+ } : S, L = P({
3290
3605
  action: "TRANSLATE",
3291
3606
  context: t,
3292
- payload: { createInput: S, sourceId: u.id, tool: "translate_page" },
3607
+ payload: { createInput: E, sourceId: u.id, tool: "translate_page" },
3293
3608
  preview: {
3294
- blockCount: _.length,
3609
+ blockCount: f.length,
3295
3610
  contentType: r.contentType,
3296
3611
  languageCode: k.code,
3297
- slug: v.slug,
3298
- status: v.status,
3299
- summary: `Publish a ${k.code.toUpperCase()} translation of "${w}" — it goes live immediately, linked to the original ${r.contentType}, at /${v.slug} with ${F(
3300
- _.length,
3612
+ slug: S.slug,
3613
+ status: S.status,
3614
+ summary: `Publish a ${k.code.toUpperCase()} translation of "${y}" — it goes live immediately, linked to the original ${r.contentType}, at /${S.slug} with ${N(
3615
+ f.length,
3301
3616
  "translated block"
3302
3617
  )}.`,
3303
- title: E
3618
+ title: w
3304
3619
  },
3305
3620
  subject: `translate ${r.contentType} ${u.id} to ${k.code}`
3306
3621
  });
3307
- if (j)
3308
- return j;
3309
- const B = { ...t, skipConfirmation: !0 };
3310
- return { ...r.contentType === "post" ? await De(S, B) : await Me(S, B), isTranslation: !0, languageCode: k.code };
3311
- }
3312
- const Kt = i.strictObject({
3313
- images: i.array(i.string().trim().min(1).max(2048)).min(1).max(12)
3314
- });
3315
- async function jr(e, t) {
3316
- const n = Kt.parse(e), r = D(t), o = I(t), a = be(r), s = r.title || r.slug || "current item", l = r.contentType === "product", u = P({
3622
+ if (L)
3623
+ return L;
3624
+ const q = { ...t, skipConfirmation: !0 };
3625
+ return { ...r.contentType === "post" ? await Ve(E, q) : await He(E, q), isTranslation: !0, languageCode: k.code };
3626
+ }
3627
+ async function rn(e, t) {
3628
+ const n = he.parse(e), r = n.entityId !== void 0 || !!n.slug || !!n.title, o = T(t);
3629
+ let a, s;
3630
+ if (r) {
3631
+ const g = await te(
3632
+ {
3633
+ contentType: n.contentType,
3634
+ entityId: n.entityId,
3635
+ slug: n.slug,
3636
+ title: n.title
3637
+ },
3638
+ t
3639
+ ), f = g.item;
3640
+ s = f.id, a = {
3641
+ contentType: g.contentType,
3642
+ entityId: s,
3643
+ slug: typeof f.slug == "string" ? f.slug : "",
3644
+ title: typeof f.title == "string" ? f.title : ""
3645
+ };
3646
+ } else
3647
+ a = H(t), s = Te(a);
3648
+ const l = a.title || a.slug || "current item", u = a.contentType === "product", d = P({
3317
3649
  action: "SET IMAGES",
3318
3650
  context: t,
3319
- payload: { images: n.images, tool: "set_content_images" },
3651
+ payload: {
3652
+ contentType: a.contentType,
3653
+ entityId: String(s),
3654
+ images: n.images,
3655
+ tool: "set_content_images"
3656
+ },
3320
3657
  preview: {
3321
- contentType: r.contentType,
3658
+ contentType: a.contentType,
3322
3659
  imageCount: n.images.length,
3323
- slug: r.slug,
3324
- summary: l ? `Set ${F(
3660
+ slug: a.slug,
3661
+ summary: u ? `Set ${N(
3325
3662
  n.images.length,
3326
3663
  "image"
3327
- )} on product "${s}" (the first becomes the main product image, the rest the gallery).` : `Set the feature image on the ${r.contentType} "${s}".`,
3328
- title: r.title
3664
+ )} on product "${l}" (the first becomes the main product image, the rest the gallery).` : `Set the feature image on the ${a.contentType} "${l}".`,
3665
+ title: a.title
3329
3666
  },
3330
- subject: `set images on ${r.contentType} ${String(a)}`
3667
+ subject: `set images on ${a.contentType} ${String(s)}`
3331
3668
  });
3332
- if (u)
3333
- return u;
3334
- const d = [];
3335
- for (let m = 0; m < n.images.length; m += 1) {
3336
- const f = await J(
3337
- n.images[m],
3338
- t,
3339
- `${s} image ${m + 1}`
3340
- );
3341
- f && d.push(f);
3342
- }
3343
- if (d.length === 0)
3669
+ if (d)
3670
+ return d;
3671
+ const c = await wt(n.images, t, l);
3672
+ if (c.length === 0)
3344
3673
  throw new Error("None of the provided images could be resolved to a media item.");
3345
- if (l) {
3346
- const { data: m, error: f } = await o.from("products").select("id, slug, language_id, title").eq("id", a).maybeSingle();
3347
- if (f || !m)
3348
- throw new Error(
3349
- `Could not load the product to set images: ${h(f)}`
3350
- );
3351
- const _ = [...new Set(d)], { error: k } = await o.from("product_media").delete().eq("product_id", a);
3352
- if (k)
3674
+ if (u) {
3675
+ const { data: g, error: f } = await o.from("products").select("id, slug, language_id, title").eq("id", s).maybeSingle();
3676
+ if (f || !g)
3353
3677
  throw new Error(
3354
- `Could not clear the product's existing images: ${h(k)}`
3678
+ `Could not load the product to set images: ${_(f)}`
3355
3679
  );
3356
- const { error: w } = await o.from("product_media").insert(
3357
- _.map((E, y) => ({
3358
- media_id: E,
3359
- product_id: a,
3360
- sort_order: y
3361
- }))
3362
- );
3363
- if (w)
3364
- throw new Error(`Could not save the product images: ${h(w)}`);
3365
- return N(
3680
+ const k = await An({
3681
+ mediaIds: c,
3682
+ productId: s,
3683
+ supabase: o
3684
+ });
3685
+ return U(
3366
3686
  t,
3367
3687
  {
3368
3688
  contentType: "product",
3369
- entityId: String(a),
3370
- languageId: m.language_id,
3371
- slug: m.slug,
3372
- title: m.title
3689
+ entityId: String(s),
3690
+ languageId: g.language_id,
3691
+ slug: g.slug,
3692
+ title: g.title
3373
3693
  },
3374
- m.slug
3694
+ g.slug
3375
3695
  ), t?.revalidatePath?.("/cms/products"), {
3376
3696
  contentType: "product",
3377
- entityId: a,
3378
- imageCount: _.length,
3697
+ entityId: s,
3698
+ imageCount: k.length,
3379
3699
  mutationExecuted: !0,
3380
- slug: m.slug,
3700
+ slug: g.slug,
3381
3701
  success: !0
3382
3702
  };
3383
3703
  }
3384
- const c = r.contentType === "page" ? "pages" : "posts", { data: p, error: g } = await o.from(c).update({
3385
- feature_image_id: d[0],
3704
+ const p = a.contentType === "page" ? "pages" : "posts", { data: h, error: m } = await o.from(p).update({
3705
+ feature_image_id: c[0],
3386
3706
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
3387
- }).eq("id", a).select("id, language_id, slug, status, title").single();
3388
- if (g || !p)
3389
- throw new Error(`Failed to set the feature image: ${h(g)}`);
3390
- return N(t, r, p.slug), {
3391
- contentType: r.contentType,
3392
- entityId: a,
3393
- extraImagesIgnored: d.length - 1,
3707
+ }).eq("id", s).select("id, language_id, slug, status, title").single();
3708
+ if (m || !h)
3709
+ throw new Error(`Failed to set the feature image: ${_(m)}`);
3710
+ return U(t, a, h.slug), {
3711
+ contentType: a.contentType,
3712
+ entityId: s,
3713
+ extraImagesIgnored: c.length - 1,
3394
3714
  imageCount: 1,
3395
3715
  mutationExecuted: !0,
3396
- slug: p.slug,
3716
+ slug: h.slug,
3397
3717
  success: !0
3398
3718
  };
3399
3719
  }
3400
- function zr(e) {
3720
+ function lo(e) {
3401
3721
  return {
3402
- ...Vt(e),
3403
- ...Ht(e),
3404
- fetch_ecommerce_stats: T({
3722
+ ...on(e),
3723
+ ...an(e),
3724
+ fetch_ecommerce_stats: x({
3405
3725
  description: "Fetch quantitative ecommerce statistics and reports from the database. Use this to answer questions about revenue, order counts, order status counts such as pending or trial, and top-selling products over a time range. This tool is read-only and does not require confirmation.",
3406
- execute: (t) => cr(t, e),
3407
- inputSchema: at,
3726
+ execute: (t) => kr(t, e),
3727
+ inputSchema: gt,
3408
3728
  strict: !0
3409
3729
  }),
3410
- read_current_cms_item: T({
3730
+ read_current_cms_item: x({
3411
3731
  description: "Read the CMS item currently being edited. Requires pageContext and returns page/post/product metadata plus page/post block summaries or content.",
3412
- execute: (t) => ur(t, e),
3413
- inputSchema: lt,
3732
+ execute: (t) => wr(t, e),
3733
+ inputSchema: ht,
3414
3734
  strict: !0
3415
3735
  }),
3416
- search_documentation: T({
3736
+ search_documentation: x({
3417
3737
  description: "Search the NextBlock documentation database and return concise source snippets for factual CMS guidance.",
3418
- execute: (t) => or(t, e),
3419
- inputSchema: Pe,
3738
+ execute: (t) => fr(t, e),
3739
+ inputSchema: Fe,
3420
3740
  strict: !0
3421
3741
  }),
3422
- fetch_url_content: T({
3423
- description: 'Fetch the readable content (title, meta description, headings, and body text) of an external web page so you can base new CMS content on it. Read-only, no confirmation. Use this first whenever the user references an external URL to copy, adapt, or draw inspiration from, e.g. "rewrite my home page based on https://example.com".',
3424
- execute: (t) => Cr(t),
3425
- inputSchema: Mt,
3742
+ fetch_url_content: x({
3743
+ description: "Fetch an external web page and return its title, meta description, headings, body text, AND its images: `mainImage` (the page's subject image schema.org Product image, else og:image, else the best in-body <img>) plus a ranked `images` list, all as absolute URLs. Read-only, no confirmation. Use this first whenever the user references an external URL to copy, adapt, clone, or draw inspiration from. To reuse the source page's image, pass `mainImage` straight into create_cms_product `images` or a page/post `feature_image_id` it is imported into the media library automatically. Never invent an image URL: if `mainImage` is null, the page had none.",
3744
+ execute: (t) => zr(t),
3745
+ inputSchema: Wt,
3426
3746
  strict: !0
3427
3747
  }),
3428
- search_stock_photos: T({
3748
+ search_stock_photos: x({
3429
3749
  description: "Find relevant, free, high-quality stock photos (Unsplash/Pexels) for page imagery. Returns a list of photos each with a direct image `url`, `width`, `height`, `alt`, and `photographer`. Read-only, zero cost. Use the returned `url` directly as an image block's external_url or a section image background's image.external_url when building or revamping pages, so layouts show real photos instantly. Set orientation \"landscape\" for hero/section backgrounds.",
3430
- execute: (t) => $r(t, e),
3431
- inputSchema: Dt,
3750
+ execute: (t) => Vr(t, e),
3751
+ inputSchema: en,
3432
3752
  strict: !0
3433
3753
  }),
3434
- rewrite_page_draft: T({
3754
+ rewrite_page_draft: x({
3435
3755
  description: 'Replace ALL blocks of an existing page or post with a brand-new set of blocks, staged as a Live Draft (content_drafts) that the user previews before publishing. Use this for whole-page redesigns/rewrites such as "rewrite my home page with 5 sections". Provide the complete new list of top-level blocks in `blocks` (usually section blocks for a landing/home page, each with nested heading/text/button blocks). Nothing goes live until the user publishes the draft, and publishing auto-creates a revision snapshot so the change is reversible. Mutating: first returns a confirmation phrase; only stages the draft after the user replies with the exact phrase.',
3436
- execute: (t) => Ur(t, e),
3437
- inputSchema: Gt,
3756
+ execute: (t) => Xr(t, e),
3757
+ inputSchema: tn,
3438
3758
  strict: !0
3439
3759
  }),
3440
- translate_page: T({
3760
+ translate_page: x({
3441
3761
  description: 'Translate the CURRENT page or post into another language. This copies the source page\'s entire structure, layout, and images automatically and links the new page to the original as a translation — you ONLY supply the text translations. Provide targetLanguageCode (e.g. "fr") and a `translations` map of every visible source string to its translation (headings, paragraph text, button labels, image alt text, captions, form labels). Do NOT rebuild the layout or call search_stock_photos for a translation. Requires an open page/post. Mutating: first returns a confirmation phrase; only creates the translation after exact confirmation.',
3442
- execute: (t) => Or(t, e),
3443
- inputSchema: zt,
3762
+ execute: (t) => Zr(t, e),
3763
+ inputSchema: nn,
3444
3764
  strict: !0
3445
3765
  }),
3446
- set_content_images: T({
3447
- description: "Set the feature image for the CURRENT page or post, or the image gallery for the CURRENT product. Pass `images`: a list of image URLs (e.g. `url` values returned by search_stock_photos) and/or existing media library IDs. External URLs are imported into the media library automatically — NEVER put an image URL directly into feature_image_id. The FIRST image becomes the feature image (pages/posts) or the main product image (products); for a product the remaining images become its gallery in order (this REPLACES the product's current images). Requires an open page/post/product. Mutating: first returns a confirmation phrase; only applies after exact confirmation.",
3448
- execute: (t) => jr(t, e),
3449
- inputSchema: Kt,
3766
+ set_content_images: x({
3767
+ description: "Set the feature image for a page or post, or the image gallery for a product. Pass `images`: a list of image URLs (e.g. `mainImage` from fetch_url_content or `url` values from search_stock_photos) and/or existing media library IDs. External URLs are imported into the media library automatically — NEVER put an image URL directly into feature_image_id. The FIRST image becomes the feature image (pages/posts) or the main product image (products); for a product the remaining images become its gallery in order (this REPLACES the product's current images). Targets the currently open page/post/product by default; to target any other item (for example a product you just created from the dashboard) pass contentType plus slug, entityId, or title — no open editor needed. Mutating: first returns a confirmation phrase; only applies after exact confirmation.",
3768
+ execute: (t) => rn(t, e),
3769
+ inputSchema: he,
3450
3770
  strict: !0
3451
3771
  }),
3452
- create_cms_page: T({
3772
+ create_cms_page: x({
3453
3773
  description: "Create a new CMS page with metadata and optional validated page blocks. Mutating: first returns a confirmation phrase; only executes after the user replies with the exact phrase. For translations, pass translationGroupId from the source page/post/product context so the new language is linked to the same backend translation group. For contact pages, provide contactEmail or a form block with recipient_email and fields.",
3454
- execute: (t) => Me(t, e),
3455
- inputSchema: ge,
3774
+ execute: (t) => He(t, e),
3775
+ inputSchema: _e,
3456
3776
  strict: !0
3457
3777
  }),
3458
- create_cms_post: T({
3778
+ create_cms_post: x({
3459
3779
  description: "Create a new CMS post with metadata and optional validated post blocks. Mutating: first returns a confirmation phrase; only executes after the user replies with the exact phrase. For translations, pass translationGroupId from the source post context so the new language is linked to the same backend translation group.",
3460
- execute: (t) => De(t, e),
3461
- inputSchema: fe,
3780
+ execute: (t) => Ve(t, e),
3781
+ inputSchema: be,
3462
3782
  strict: !0
3463
3783
  }),
3464
- create_cms_product: T({
3465
- description: "Create a new draft-capable product. Defaults missing product fields safely: physical Stripe product, generated SKU, price 0, stock 0, taxable, draft. For translations, pass translationGroupId from the source product context. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
3466
- execute: (t) => jt(t, e),
3467
- inputSchema: he,
3784
+ create_cms_product: x({
3785
+ description: "Create a new draft-capable product, complete with its images and its body copy in ONE call. Pass `images` to set the main product image and gallery (external https URLs are imported into the media library automatically — use `mainImage` from fetch_url_content to reuse a source page's photo). Pass `blocks` to build the product's \"Product Description Blocks\" — the SAME block vocabulary and section-based design rules as create_cms_page, rendered on the public product page. This is the richest product body and is what you should produce whenever the user asks to copy or write real product content. Also pass `short_description` for the one-line summary shown on product cards. `description_html` is a plain-HTML fallback body used only when no blocks are supplied. Defaults missing fields safely: physical Stripe product, generated SKU, price 0, stock 0, taxable, draft. `price` is in major units (25 = $25.00). For translations, pass translationGroupId from the source product context. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
3786
+ execute: (t) => Gt(t, e),
3787
+ inputSchema: ke,
3468
3788
  strict: !0
3469
3789
  }),
3470
- delete_cms_item: T({
3790
+ delete_cms_item: x({
3471
3791
  description: "Delete a resolved page, post, or product after exact confirmation. Pages/posts delete all translations in the translation group and related navigation links. Mutating: refuses unless the latest user message includes the exact confirmation phrase.",
3472
- execute: (t) => Rt(t, e),
3473
- inputSchema: ye,
3792
+ execute: (t) => Jt(t, e),
3793
+ inputSchema: Ie,
3474
3794
  strict: !0
3475
3795
  }),
3476
- prepare_delete_cms_item: T({
3796
+ prepare_delete_cms_item: x({
3477
3797
  description: "Inspect the page, post, or product that would be deleted and return the exact confirmation phrase. This tool does not mutate data.",
3478
- execute: (t) => kr(t, e),
3479
- inputSchema: ct,
3798
+ execute: (t) => Nr(t, e),
3799
+ inputSchema: yt,
3480
3800
  strict: !0
3481
3801
  }),
3482
- update_footer: T({
3802
+ update_footer: x({
3483
3803
  description: "Replace the public footer links and/or footer copyright settings for a locale. Use links for footer navigation and copyright for locale text templates. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
3484
- execute: (t) => vt(t, e),
3485
- inputSchema: le,
3804
+ execute: (t) => Ot(t, e),
3805
+ inputSchema: pe,
3486
3806
  strict: !0
3487
3807
  }),
3488
- update_content_block: T({
3808
+ update_content_block: x({
3489
3809
  description: 'Update the JSON content of an existing top-level page/post block that belongs to the current CMS edit context. 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.',
3490
- execute: (t) => Nt(t, e),
3491
- inputSchema: ue,
3810
+ execute: (t) => qt(t, e),
3811
+ inputSchema: ge,
3492
3812
  strict: !0
3493
3813
  }),
3494
- insert_content_block: T({
3814
+ insert_content_block: x({
3495
3815
  description: 'Insert a new validated top-level page/post block before or after an existing block, or at the start/end. Use this for visible content additions like adding a rich text title and paragraph above a form. For "above the form", use position "before" with anchorBlockType "form" and blockType "text" containing html_content. Mutating: first returns a confirmation phrase; only executes after exact confirmation.',
3496
- execute: (t) => Ut(t, e),
3497
- inputSchema: me,
3816
+ execute: (t) => Mt(t, e),
3817
+ inputSchema: ye,
3498
3818
  strict: !0
3499
3819
  }),
3500
- update_current_cms_fields: T({
3820
+ update_current_cms_fields: x({
3501
3821
  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.",
3502
- execute: (t) => Pt(t, e),
3503
- inputSchema: ce,
3822
+ execute: (t) => Rt(t, e),
3823
+ inputSchema: me,
3504
3824
  strict: !0
3505
3825
  }),
3506
- update_cms_item_field: T({
3826
+ update_cms_item_field: x({
3507
3827
  description: "Update one field on a page, post, or product, resolving by current edit context, id, slug, or exact title. Use this for requests like changing price, stock, title, slug, status, sale_price, or meta fields. Interpret public as published for pages/posts and active for products. Scheduled sale date ranges are not supported and will be refused without mutation. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
3508
- execute: (t) => qt(t, e),
3509
- inputSchema: _e,
3828
+ execute: (t) => Kt(t, e),
3829
+ inputSchema: we,
3510
3830
  strict: !0
3511
3831
  }),
3512
- update_navigation_bar: T({
3832
+ update_navigation_bar: x({
3513
3833
  description: 'Update the public header navigation bar for a locale. Use mode "append" when adding links while preserving existing navigation. Use mode "update" when renaming or changing an existing single link. Use mode "replace" only when the user asks to rebuild the complete header and you provide the full menu; destructive partial replacements are refused. Mutating: first returns a confirmation phrase; only executes after exact confirmation.',
3514
- execute: (t) => Ct(t, e),
3515
- inputSchema: se,
3834
+ execute: (t) => Ut(t, e),
3835
+ inputSchema: de,
3516
3836
  strict: !0
3517
3837
  }),
3518
- update_section_column_block: T({
3838
+ update_section_column_block: x({
3519
3839
  description: "Update the content of one existing nested block inside a section block that belongs to the current CMS edit context. This tool must not change the nested block type. To add a new nested block, update the parent section with update_content_block and preserve existing column_blocks. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
3520
- execute: (t) => Ft(t, e),
3521
- inputSchema: de,
3840
+ execute: (t) => Dt(t, e),
3841
+ inputSchema: fe,
3522
3842
  strict: !0
3523
3843
  }),
3524
- execute_cms_action_plan: T({
3844
+ execute_cms_action_plan: x({
3525
3845
  description: "Execute multiple CMS mutations as one confirmed plan. Use this whenever the user asks for more than one change in the same prompt, such as creating a page and adding a navigation link. First returns one combined confirmation preview and Confirm button; after confirmation, runs each action in order and stops on the first failure.",
3526
- execute: (t) => Ir(t, e),
3527
- inputSchema: dt,
3846
+ execute: (t) => Fr(t, e),
3847
+ inputSchema: bt,
3528
3848
  strict: !0
3529
3849
  })
3530
3850
  };
3531
3851
  }
3532
3852
  export {
3533
- M as availableCortexAiBlockTypes,
3534
- Dr as buildVisibleContactIntroActionPlan,
3535
- st as cortexAiPageContextSchema,
3536
- ge as createCmsPageInputSchema,
3537
- fe as createCmsPostInputSchema,
3538
- he as createCmsProductInputSchema,
3539
- zr as createCortexGlobalAgentTools,
3540
- ye as deleteCmsItemInputSchema,
3541
- Ir as executeCmsActionPlan,
3542
- dt as executeCmsActionPlanInputSchema,
3543
- Me as executeCreateCmsPage,
3544
- De as executeCreateCmsPost,
3545
- jt as executeCreateCmsProduct,
3546
- Rt as executeDeleteCmsItem,
3547
- cr as executeFetchEcommerceStats,
3548
- Cr as executeFetchUrlContent,
3549
- Ut as executeInsertContentBlock,
3550
- kr as executePrepareDeleteCmsItem,
3551
- ur as executeReadCurrentCmsItem,
3552
- Ur as executeRewritePageDraft,
3553
- rr as executeSearchDocumentation,
3554
- or as executeSearchDocumentationWithTimeout,
3555
- $r as executeSearchStockPhotos,
3556
- jr as executeSetContentImages,
3557
- Or as executeTranslatePage,
3558
- qt as executeUpdateCmsItemField,
3559
- Nt as executeUpdateContentBlock,
3560
- Pt as executeUpdateCurrentCmsFields,
3561
- vt as executeUpdateFooter,
3562
- Ct as executeUpdateNavigationBar,
3563
- Ft as executeUpdateSectionColumnBlock,
3564
- at as fetchEcommerceStatsInputSchema,
3565
- Mt as fetchUrlContentInputSchema,
3566
- me as insertContentBlockInputSchema,
3567
- Ie as maybeTriggerStockPhotoDownloads,
3568
- it as navigationItemInputSchema,
3569
- ct as prepareDeleteCmsItemInputSchema,
3570
- lt as readCurrentCmsItemInputSchema,
3571
- Gr as resolveCortexAiStockPhotoProvider,
3572
- ze as resolveCortexAiStockPhotoProviders,
3573
- Gt as rewritePageDraftInputSchema,
3574
- Pe as searchDocumentationInputSchema,
3575
- Dt as searchStockPhotosInputSchema,
3576
- zt as translatePageInputSchema,
3577
- _e as updateCmsItemFieldInputSchema,
3578
- ue as updateContentBlockInputSchema,
3579
- ce as updateCurrentCmsFieldsInputSchema,
3580
- le as updateFooterInputSchema,
3581
- se as updateNavigationBarInputSchema,
3582
- de as updateSectionColumnBlockInputSchema
3853
+ G as availableCortexAiBlockTypes,
3854
+ ao as buildVisibleContactIntroActionPlan,
3855
+ ft as cortexAiPageContextSchema,
3856
+ _e as createCmsPageInputSchema,
3857
+ be as createCmsPostInputSchema,
3858
+ ke as createCmsProductInputSchema,
3859
+ lo as createCortexGlobalAgentTools,
3860
+ Ie as deleteCmsItemInputSchema,
3861
+ Fr as executeCmsActionPlan,
3862
+ bt as executeCmsActionPlanInputSchema,
3863
+ He as executeCreateCmsPage,
3864
+ Ve as executeCreateCmsPost,
3865
+ Gt as executeCreateCmsProduct,
3866
+ Jt as executeDeleteCmsItem,
3867
+ kr as executeFetchEcommerceStats,
3868
+ zr as executeFetchUrlContent,
3869
+ Mt as executeInsertContentBlock,
3870
+ Nr as executePrepareDeleteCmsItem,
3871
+ wr as executeReadCurrentCmsItem,
3872
+ Xr as executeRewritePageDraft,
3873
+ gr as executeSearchDocumentation,
3874
+ fr as executeSearchDocumentationWithTimeout,
3875
+ Vr as executeSearchStockPhotos,
3876
+ rn as executeSetContentImages,
3877
+ Zr as executeTranslatePage,
3878
+ Kt as executeUpdateCmsItemField,
3879
+ qt as executeUpdateContentBlock,
3880
+ Rt as executeUpdateCurrentCmsFields,
3881
+ Ot as executeUpdateFooter,
3882
+ Ut as executeUpdateNavigationBar,
3883
+ Dt as executeUpdateSectionColumnBlock,
3884
+ gt as fetchEcommerceStatsInputSchema,
3885
+ Wt as fetchUrlContentInputSchema,
3886
+ ye as insertContentBlockInputSchema,
3887
+ ve as maybeTriggerStockPhotoDownloads,
3888
+ mt as navigationItemInputSchema,
3889
+ yt as prepareDeleteCmsItemInputSchema,
3890
+ ht as readCurrentCmsItemInputSchema,
3891
+ so as resolveCortexAiStockPhotoProvider,
3892
+ We as resolveCortexAiStockPhotoProviders,
3893
+ tn as rewritePageDraftInputSchema,
3894
+ Fe as searchDocumentationInputSchema,
3895
+ en as searchStockPhotosInputSchema,
3896
+ he as setContentImagesInputSchema,
3897
+ nn as translatePageInputSchema,
3898
+ we as updateCmsItemFieldInputSchema,
3899
+ ge as updateContentBlockInputSchema,
3900
+ me as updateCurrentCmsFieldsInputSchema,
3901
+ pe as updateFooterInputSchema,
3902
+ de as updateNavigationBarInputSchema,
3903
+ fe as updateSectionColumnBlockInputSchema
3583
3904
  };