@nextblock-cms/cortex 0.14.4 → 0.14.6

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,7 +1,14 @@
1
- import { tool as v } from "ai";
1
+ import { tool as w } from "ai";
2
2
  import "./zod-config.es.js";
3
3
  import { z as n } from "zod";
4
- const V = 100, J = 20, C = 100, k = 20, M = "[REDACTED]", g = "cortex_ai_openrouter_api_key", j = {
4
+ const G = 100, J = 20, A = 100, k = 20, P = "[REDACTED]", M = "cortex_ai_openrouter_api_key", T = /* @__PURE__ */ new Set([
5
+ M,
6
+ "bot_protection_secret",
7
+ "cortex_ai_pexels_api_key",
8
+ "cortex_ai_unsplash_access_key",
9
+ "email_secret",
10
+ "payment_secret"
11
+ ]), I = {
5
12
  blocks: {
6
13
  columns: ["id", "page_id", "post_id", "language_id", "block_type", "content", "order", "created_at", "updated_at"],
7
14
  description: "CMS page/post content blocks.",
@@ -234,7 +241,11 @@ const V = 100, J = 20, C = 100, k = 20, M = "[REDACTED]", g = "cortex_ai_openrou
234
241
  page_revisions: {
235
242
  columns: ["id", "page_id", "author_id", "version", "revision_type", "content", "created_at"],
236
243
  description: "Page revision history.",
237
- primaryKey: ["id"]
244
+ primaryKey: ["id"],
245
+ // Revision history is an audit trail. The agent may read it, but letting it rewrite or
246
+ // delete rows would let it erase the record of its own edits — and hand-written rows
247
+ // would corrupt the snapshot/diff chain the restore path replays.
248
+ readOnly: !0
238
249
  },
239
250
  pages: {
240
251
  columns: [
@@ -258,7 +269,16 @@ const V = 100, J = 20, C = 100, k = 20, M = "[REDACTED]", g = "cortex_ai_openrou
258
269
  post_revisions: {
259
270
  columns: ["id", "post_id", "author_id", "version", "revision_type", "content", "created_at"],
260
271
  description: "Post revision history.",
261
- primaryKey: ["id"]
272
+ primaryKey: ["id"],
273
+ // See page_revisions.
274
+ readOnly: !0
275
+ },
276
+ product_revisions: {
277
+ columns: ["id", "product_id", "author_id", "version", "revision_type", "content", "created_at"],
278
+ description: "Product revision history.",
279
+ primaryKey: ["id"],
280
+ // See page_revisions.
281
+ readOnly: !0
262
282
  },
263
283
  posts: {
264
284
  columns: [
@@ -426,31 +446,31 @@ const V = 100, J = 20, C = 100, k = 20, M = "[REDACTED]", g = "cortex_ai_openrou
426
446
  description: "Variant to attribute-term join rows.",
427
447
  primaryKey: ["variant_id", "attribute_term_id"]
428
448
  }
429
- }, Q = n.enum(["eq", "neq", "gt", "gte", "lt", "lte", "ilike", "in", "is"]), P = n.strictObject({
449
+ }, Q = n.enum(["eq", "neq", "gt", "gte", "lt", "lte", "ilike", "in", "is"]), R = n.strictObject({
430
450
  column: n.string().trim().min(1).max(120),
431
451
  operator: Q.default("eq"),
432
452
  value: n.unknown()
433
- }), G = n.strictObject({
453
+ }), W = n.strictObject({
434
454
  ascending: n.boolean().default(!0),
435
455
  column: n.string().trim().min(1).max(120)
436
- }), R = n.strictObject({
456
+ }), D = n.strictObject({
437
457
  includeReadOnly: n.boolean().default(!0),
438
458
  table: n.string().trim().min(1).max(120).optional()
439
- }), D = n.strictObject({
459
+ }), N = n.strictObject({
440
460
  columns: n.array(n.string().trim().min(1).max(120)).min(1).max(40).optional(),
441
- filters: n.array(P).max(12).default([]),
442
- limit: n.number().int().min(1).max(V).default(J),
461
+ filters: n.array(R).max(12).default([]),
462
+ limit: n.number().int().min(1).max(G).default(J),
443
463
  offset: n.number().int().min(0).max(1e4).default(0),
444
- orderBy: G.optional(),
464
+ orderBy: W.optional(),
445
465
  table: n.string().trim().min(1).max(120)
446
466
  }), O = n.strictObject({
447
- filters: n.array(P).max(12).optional(),
467
+ filters: n.array(R).max(12).optional(),
448
468
  operation: n.enum(["delete", "insert", "update", "upsert"]),
449
469
  rows: n.array(n.record(n.string(), n.unknown())).min(1).max(k).optional(),
450
470
  summary: n.string().trim().min(1).max(500).optional(),
451
471
  table: n.string().trim().min(1).max(120),
452
472
  values: n.record(n.string(), n.unknown()).optional()
453
- }), N = n.strictObject({
473
+ }), L = n.strictObject({
454
474
  actions: n.array(O).min(1).max(8),
455
475
  summary: n.string().trim().min(1).max(500).optional()
456
476
  });
@@ -462,95 +482,104 @@ function E(e) {
462
482
  function f(e) {
463
483
  return e ? typeof e == "object" && "message" in e ? String(e.message || "Unknown database error.") : String(e) : "Unknown database error.";
464
484
  }
465
- function K(e) {
466
- return e === null || typeof e != "object" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((t) => K(t)).join(",")}]` : `{${Object.keys(e).sort().map((t) => `${JSON.stringify(t)}:${K(e[t])}`).join(",")}}`;
485
+ function C(e) {
486
+ return e === null || typeof e != "object" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((t) => C(t)).join(",")}]` : `{${Object.keys(e).sort().map((t) => `${JSON.stringify(t)}:${C(e[t])}`).join(",")}}`;
467
487
  }
468
- function L(e) {
488
+ function q(e) {
469
489
  let t = 2166136261;
470
- const r = K(e);
490
+ const r = C(e);
471
491
  for (let a = 0; a < r.length; a++)
472
492
  t ^= r.charCodeAt(a), t = Math.imul(t, 16777619);
473
493
  return (t >>> 0).toString(16).padStart(8, "0");
474
494
  }
475
- function $(e) {
495
+ function K(e) {
476
496
  return e.replace(/\s+/g, " ").trim().toUpperCase();
477
497
  }
478
- function W(e, t, r) {
479
- return `${$(`CONFIRM ${e} ${t}`)} #${L(r)}`;
498
+ function Y(e, t, r) {
499
+ return `${K(`CONFIRM ${e} ${t}`)} #${q(r)}`;
480
500
  }
481
- function Y(e) {
501
+ function H(e) {
482
502
  return {
483
- confirmationPhrase: W(e.action, e.subject, e.payload),
503
+ confirmationPhrase: Y(e.action, e.subject, e.payload),
484
504
  mutationExecuted: !1,
485
505
  preview: e.preview,
486
506
  requiresConfirmation: !0,
487
507
  success: !0
488
508
  };
489
509
  }
490
- function q(e) {
510
+ function z(e) {
491
511
  if (e.context?.skipConfirmation)
492
512
  return null;
493
- const t = Y(e), r = $(e.context?.latestUserMessage || ""), a = $(t.confirmationPhrase);
513
+ const t = H(e), r = K(e.context?.latestUserMessage || ""), a = K(t.confirmationPhrase);
494
514
  return r && !r.includes(a) ? {
495
515
  ...t,
496
516
  message: "The database target changed or the confirmation did not match. Please review and confirm again."
497
517
  } : r.includes(a) ? null : t;
498
518
  }
499
- function H(e) {
500
- return Object.prototype.hasOwnProperty.call(j, e);
519
+ function Z(e) {
520
+ return Object.prototype.hasOwnProperty.call(I, e);
501
521
  }
502
- function T(e) {
522
+ function j(e) {
503
523
  const t = e.trim();
504
524
  if (t.includes(".") || t.toLowerCase().startsWith("auth"))
505
525
  throw new Error("Cortex AI cannot access auth schema tables.");
506
- if (!H(t))
526
+ if (!Z(t))
507
527
  throw new Error(`Table "${t}" is not available to Cortex AI database tools.`);
508
528
  return t;
509
529
  }
510
530
  function _(e) {
511
- return j[e];
531
+ return I[e];
512
532
  }
513
- function w(e) {
533
+ function h(e) {
514
534
  return /(?:password|token|secret|api[_-]?key|private[_-]?key|credential)/i.test(e);
515
535
  }
516
- function b(e, t) {
536
+ function g(e, t) {
517
537
  if (!_(e).columns.includes(t))
518
538
  throw new Error(`Column "${t}" is not available on table "${e}".`);
519
- if (w(t))
539
+ if (h(t))
520
540
  throw new Error(`Column "${t}" is protected and cannot be used through Cortex AI.`);
521
541
  }
522
- function I(e, t = "payload") {
542
+ function $(e, t = "payload") {
523
543
  if (Array.isArray(e)) {
524
- e.forEach((r, a) => I(r, `${t}[${a}]`));
544
+ e.forEach((r, a) => $(r, `${t}[${a}]`));
525
545
  return;
526
546
  }
527
547
  if (!(!e || typeof e != "object"))
528
548
  for (const [r, a] of Object.entries(e)) {
529
- if (w(r))
549
+ if (h(r))
530
550
  throw new Error(`Protected field "${t}.${r}" cannot be written through Cortex AI.`);
531
- I(a, `${t}.${r}`);
551
+ $(a, `${t}.${r}`);
532
552
  }
533
553
  }
534
- function h(e) {
554
+ function b(e) {
535
555
  if (Array.isArray(e))
536
- return e.map((r) => h(r));
556
+ return e.map((r) => b(r));
537
557
  if (!e || typeof e != "object")
538
558
  return e;
539
559
  const t = {};
540
560
  for (const [r, a] of Object.entries(e))
541
- t[r] = w(r) ? M : h(a);
561
+ t[r] = h(r) ? P : b(a);
542
562
  return t;
543
563
  }
544
- function Z(e) {
545
- return e.map((t) => t && typeof t == "object" && !Array.isArray(t) && t.key === g ? { key: g, value: M } : h(t));
564
+ function ee(e) {
565
+ return e.map((t) => {
566
+ if (t && typeof t == "object" && !Array.isArray(t)) {
567
+ const r = t.key;
568
+ if (typeof r == "string" && T.has(r))
569
+ return { key: r, value: P };
570
+ }
571
+ return b(t);
572
+ });
546
573
  }
547
- function ee(e, t) {
574
+ function te(e, t) {
548
575
  if (e !== "site_settings")
549
576
  return;
550
- if (JSON.stringify(t).toLowerCase().includes(g))
551
- throw new Error("The Cortex AI OpenRouter API key site setting is protected.");
577
+ const r = JSON.stringify(t).toLowerCase();
578
+ for (const a of T)
579
+ if (r.includes(a))
580
+ throw new Error(`The "${a}" site setting is protected.`);
552
581
  }
553
- function te(e, t) {
582
+ function re(e, t) {
554
583
  switch (t.operator) {
555
584
  case "eq":
556
585
  return e.eq(t.column, t.value);
@@ -576,36 +605,36 @@ function te(e, t) {
576
605
  return e.is(t.column, t.value);
577
606
  }
578
607
  }
579
- function x(e, t, r) {
608
+ function v(e, t, r) {
580
609
  let a = t;
581
610
  for (const o of r)
582
- b(e, o.column), a = te(a, o);
583
- return e === "site_settings" && (a = a.neq("key", g)), a;
611
+ g(e, o.column), a = re(a, o);
612
+ return e === "site_settings" && (a = a.neq("key", M)), a;
584
613
  }
585
- function re(e, t) {
586
- const r = _(e), a = t?.length ? t : r.columns.filter((o) => !w(o));
587
- return a.forEach((o) => b(e, o)), a.join(",");
614
+ function ae(e, t) {
615
+ const r = _(e), a = t?.length ? t : r.columns.filter((o) => !h(o));
616
+ return a.forEach((o) => g(e, o)), a.join(",");
588
617
  }
589
- function z(e, t) {
618
+ function F(e, t) {
590
619
  return t.map((r) => `${r}=${String(e[r] ?? "")}`).join("|");
591
620
  }
592
- async function F(e, t, r) {
621
+ async function U(e, t, r) {
593
622
  const a = _(t);
594
- let o = e.from(t).select(a.primaryKey.join(",")).limit(C + 1);
595
- o = x(t, o, r);
623
+ let o = e.from(t).select(a.primaryKey.join(",")).limit(A + 1);
624
+ o = v(t, o, r);
596
625
  const { data: i, error: s } = await o;
597
626
  if (s)
598
627
  throw new Error(`Failed to preview database mutation: ${f(s)}`);
599
628
  const d = Array.isArray(i) ? i : [];
600
- if (d.length > C)
601
- throw new Error(`Refusing to mutate more than ${C} rows.`);
629
+ if (d.length > A)
630
+ throw new Error(`Refusing to mutate more than ${A} rows.`);
602
631
  return d;
603
632
  }
604
- function U(e) {
605
- const t = T(e.table), r = _(t), a = e.operation;
633
+ function B(e) {
634
+ const t = j(e.table), r = _(t), a = e.operation;
606
635
  if (r.readOnly)
607
636
  throw new Error(`Table "${t}" is read-only for Cortex AI.`);
608
- if (ee(t, e), (a === "update" || a === "delete") && (!e.filters || e.filters.length === 0))
637
+ if (te(t, e), (a === "update" || a === "delete") && (!e.filters || e.filters.length === 0))
609
638
  throw new Error(`${a} operations require at least one filter.`);
610
639
  if ((a === "insert" || a === "upsert") && (!e.rows || e.rows.length === 0))
611
640
  throw new Error(`${a} operations require rows.`);
@@ -615,16 +644,16 @@ function U(e) {
615
644
  throw new Error(`Refusing to mutate more than ${k} input rows.`);
616
645
  const o = e.rows ?? (e.values ? [e.values] : []);
617
646
  for (const i of o) {
618
- I(i);
647
+ $(i);
619
648
  for (const s of Object.keys(i))
620
- b(t, s);
649
+ g(t, s);
621
650
  }
622
651
  for (const i of e.filters ?? [])
623
- b(t, i.column);
652
+ g(t, i.column);
624
653
  return t;
625
654
  }
626
- function B(e) {
627
- const { input: t, table: r, targetRows: a } = e, o = _(r), i = a.map((m) => z(m, o.primaryKey)).sort(), s = t.rows?.length ?? 0, d = t.operation === "insert" || t.operation === "upsert" ? s : a.length, l = t.summary || `${t.operation} ${d} ${d === 1 ? "row" : "rows"} in ${r}.`;
655
+ function X(e) {
656
+ const { input: t, table: r, targetRows: a } = e, o = _(r), i = a.map((p) => F(p, o.primaryKey)).sort(), s = t.rows?.length ?? 0, d = t.operation === "insert" || t.operation === "upsert" ? s : a.length, l = t.summary || `${t.operation} ${d} ${d === 1 ? "row" : "rows"} in ${r}.`;
628
657
  return {
629
658
  affectedCount: d,
630
659
  operation: t.operation,
@@ -634,7 +663,7 @@ function B(e) {
634
663
  targetIds: i
635
664
  };
636
665
  }
637
- async function A(e) {
666
+ async function x(e) {
638
667
  const t = e.context?.actorUserId;
639
668
  if (!t)
640
669
  return { auditError: "Missing actor user id.", auditLogged: !1 };
@@ -644,9 +673,9 @@ async function A(e) {
644
673
  actor_user_id: t,
645
674
  error_message: e.errorMessage ?? null,
646
675
  operation_summary: e.summary,
647
- payload: h(e.input),
648
- payload_hash: L(e.input),
649
- preview: h(e.preview),
676
+ payload: b(e.input),
677
+ payload_hash: q(e.input),
678
+ preview: b(e.preview),
650
679
  status: e.status,
651
680
  target_tables: e.targetTables,
652
681
  tool_name: e.toolName
@@ -656,20 +685,20 @@ async function A(e) {
656
685
  return { auditError: f(r), auditLogged: !1 };
657
686
  }
658
687
  }
659
- async function ae(e, t, r) {
688
+ async function ie(e, t, r) {
660
689
  const o = _(t).primaryKey.join(",");
661
690
  let i;
662
- e.operation === "insert" ? i = r.from(t).insert(e.rows).select(o) : e.operation === "upsert" ? i = r.from(t).upsert(e.rows).select(o) : e.operation === "update" ? (i = r.from(t).update(e.values), i = x(t, i, e.filters ?? []), i = i.select(o)) : (i = r.from(t).delete(), i = x(t, i, e.filters ?? []), i = i.select(o));
691
+ e.operation === "insert" ? i = r.from(t).insert(e.rows).select(o) : e.operation === "upsert" ? i = r.from(t).upsert(e.rows).select(o) : e.operation === "update" ? (i = r.from(t).update(e.values), i = v(t, i, e.filters ?? []), i = i.select(o)) : (i = r.from(t).delete(), i = v(t, i, e.filters ?? []), i = i.select(o));
663
692
  const { data: s, error: d } = await i;
664
693
  if (d)
665
694
  throw new Error(f(d));
666
695
  return Array.isArray(s) ? s : [];
667
696
  }
668
- async function ie(e) {
669
- const t = R.parse(e), a = (t.table ? [T(t.table)] : Object.keys(j)).filter((o) => t.includeReadOnly || !_(o).readOnly).map((o) => {
697
+ async function oe(e) {
698
+ const t = D.parse(e), a = (t.table ? [j(t.table)] : Object.keys(I)).filter((o) => t.includeReadOnly || !_(o).readOnly).map((o) => {
670
699
  const i = _(o);
671
700
  return {
672
- columns: i.columns.filter((s) => !w(s)),
701
+ columns: i.columns.filter((s) => !h(s)),
673
702
  description: i.description,
674
703
  primaryKey: i.primaryKey,
675
704
  readOnly: !!i.readOnly,
@@ -681,16 +710,16 @@ async function ie(e) {
681
710
  "Use read_database_records for reads and execute_database_mutation/action_plan for writes.",
682
711
  "No auth schema access, no arbitrary SQL, no password/secret/API-key fields.",
683
712
  "profiles, user_addresses, and cortex_ai_db_mutation_audit are read-only.",
684
- `site_settings.${g} is protected.`
713
+ `Protected site_settings keys (never readable or writable): ${[...T].sort().join(", ")}.`
685
714
  ],
686
715
  success: !0,
687
716
  tables: a
688
717
  };
689
718
  }
690
- async function oe(e, t) {
691
- const r = D.parse(e), a = T(r.table), o = re(a, r.columns);
719
+ async function ne(e, t) {
720
+ const r = N.parse(e), a = j(r.table), o = ae(a, r.columns);
692
721
  let i = E(t).from(a).select(o).range(r.offset, r.offset + r.limit - 1);
693
- i = x(a, i, r.filters), r.orderBy && (b(a, r.orderBy.column), i = i.order(r.orderBy.column, { ascending: r.orderBy.ascending }));
722
+ i = v(a, i, r.filters), r.orderBy && (g(a, r.orderBy.column), i = i.order(r.orderBy.column, { ascending: r.orderBy.ascending }));
694
723
  const { data: s, error: d } = await i;
695
724
  if (d)
696
725
  throw new Error(`Failed to read database records: ${f(d)}`);
@@ -699,16 +728,16 @@ async function oe(e, t) {
699
728
  columns: o.split(","),
700
729
  limit: r.limit,
701
730
  offset: r.offset,
702
- rows: Z(l),
731
+ rows: ee(l),
703
732
  success: !0,
704
733
  table: a
705
734
  };
706
735
  }
707
- async function X(e, t) {
708
- const r = O.parse(e), a = U(r), o = E(t), i = r.operation === "update" || r.operation === "delete" ? await F(o, a, r.filters ?? []) : [], s = B({ input: r, table: a, targetRows: i }), d = {
736
+ async function V(e, t) {
737
+ const r = O.parse(e), a = B(r), o = E(t), i = r.operation === "update" || r.operation === "delete" ? await U(o, a, r.filters ?? []) : [], s = X({ input: r, table: a, targetRows: i }), d = {
709
738
  input: r,
710
739
  targetIds: s.targetIds
711
- }, l = q({
740
+ }, l = z({
712
741
  action: `DATABASE ${r.operation}`,
713
742
  context: t,
714
743
  payload: d,
@@ -718,7 +747,7 @@ async function X(e, t) {
718
747
  if (l)
719
748
  return l;
720
749
  try {
721
- const m = await ae(r, a, o), p = t?.skipAudit ? { auditLogged: !1 } : await A({
750
+ const p = await ie(r, a, o), m = t?.skipAudit ? { auditLogged: !1 } : await x({
722
751
  context: t,
723
752
  input: d,
724
753
  preview: s,
@@ -728,20 +757,20 @@ async function X(e, t) {
728
757
  toolName: "execute_database_mutation"
729
758
  });
730
759
  return {
731
- affectedCount: m.length || s.affectedCount,
732
- auditLogged: p.auditLogged,
733
- ...p.auditError ? { auditError: p.auditError } : {},
760
+ affectedCount: p.length || s.affectedCount,
761
+ auditLogged: m.auditLogged,
762
+ ...m.auditError ? { auditError: m.auditError } : {},
734
763
  mutationExecuted: !0,
735
764
  operation: r.operation,
736
- sampleTargetIds: m.map((c) => z(c, _(a).primaryKey)).slice(0, 10),
765
+ sampleTargetIds: p.map((c) => F(c, _(a).primaryKey)).slice(0, 10),
737
766
  success: !0,
738
767
  summary: s.summary,
739
768
  table: a
740
769
  };
741
- } catch (m) {
742
- const p = f(m), c = t?.skipAudit ? { auditLogged: !1 } : await A({
770
+ } catch (p) {
771
+ const m = f(p), c = t?.skipAudit ? { auditLogged: !1 } : await x({
743
772
  context: t,
744
- errorMessage: p,
773
+ errorMessage: m,
745
774
  input: d,
746
775
  preview: s,
747
776
  status: "failure",
@@ -752,7 +781,7 @@ async function X(e, t) {
752
781
  return {
753
782
  auditLogged: c.auditLogged,
754
783
  ...c.auditError ? { auditError: c.auditError } : {},
755
- message: `Database mutation failed: ${p}`,
784
+ message: `Database mutation failed: ${m}`,
756
785
  mutationExecuted: !1,
757
786
  operation: r.operation,
758
787
  success: !1,
@@ -760,13 +789,13 @@ async function X(e, t) {
760
789
  };
761
790
  }
762
791
  }
763
- async function ne(e, t) {
764
- const r = N.parse(e), a = [];
792
+ async function se(e, t) {
793
+ const r = L.parse(e), a = [];
765
794
  for (const c of r.actions) {
766
- const y = U(c), u = c.operation === "update" || c.operation === "delete" ? await F(E(t), y, c.filters ?? []) : [];
795
+ const y = B(c), u = c.operation === "update" || c.operation === "delete" ? await U(E(t), y, c.filters ?? []) : [];
767
796
  a.push({
768
797
  input: c,
769
- preview: B({ input: c, table: y, targetRows: u }),
798
+ preview: X({ input: c, table: y, targetRows: u }),
770
799
  table: y
771
800
  });
772
801
  }
@@ -779,7 +808,7 @@ async function ne(e, t) {
779
808
  input: c,
780
809
  table: u,
781
810
  targetIds: y.targetIds
782
- })), d = q({
811
+ })), d = z({
783
812
  action: "DATABASE ACTION PLAN",
784
813
  context: t,
785
814
  payload: s,
@@ -789,15 +818,15 @@ async function ne(e, t) {
789
818
  if (d)
790
819
  return d;
791
820
  const l = [];
792
- let m = !1;
821
+ let p = !1;
793
822
  for (const [c, y] of a.entries()) {
794
- const u = await X(y.input, {
823
+ const u = await V(y.input, {
795
824
  ...t,
796
825
  skipAudit: !0,
797
826
  skipConfirmation: !0
798
827
  });
799
- if (l.push(u), u && typeof u == "object" && u.mutationExecuted === !0 && (m = !0), !u || typeof u != "object" || u.success === !1) {
800
- const S = await A({
828
+ if (l.push(u), u && typeof u == "object" && u.mutationExecuted === !0 && (p = !0), !u || typeof u != "object" || u.success === !1) {
829
+ const S = await x({
801
830
  context: t,
802
831
  errorMessage: u && typeof u == "object" && typeof u.message == "string" ? u.message : `Database action ${c + 1} failed.`,
803
832
  input: s,
@@ -813,13 +842,13 @@ async function ne(e, t) {
813
842
  ...S.auditError ? { auditError: S.auditError } : {},
814
843
  failedActionIndex: c,
815
844
  message: u && typeof u == "object" && typeof u.message == "string" ? u.message : `Database action ${c + 1} failed.`,
816
- mutationExecuted: m,
845
+ mutationExecuted: p,
817
846
  results: l,
818
847
  success: !1
819
848
  };
820
849
  }
821
850
  }
822
- const p = await A({
851
+ const m = await x({
823
852
  context: t,
824
853
  input: s,
825
854
  preview: i,
@@ -830,50 +859,50 @@ async function ne(e, t) {
830
859
  });
831
860
  return {
832
861
  actionCount: a.length,
833
- auditLogged: p.auditLogged,
834
- ...p.auditError ? { auditError: p.auditError } : {},
835
- mutationExecuted: m,
862
+ auditLogged: m.auditLogged,
863
+ ...m.auditError ? { auditError: m.auditError } : {},
864
+ mutationExecuted: p,
836
865
  results: l,
837
866
  success: !0,
838
867
  summary: r.summary ?? null
839
868
  };
840
869
  }
841
- function ue(e) {
870
+ function le(e) {
842
871
  return {
843
- describe_database_schema: v({
872
+ describe_database_schema: w({
844
873
  description: "Describe the public database tables Cortex AI can read or mutate, including read-only tables, primary keys, and writable columns. Use before broad database tasks when unsure about schema.",
845
- execute: (t) => ie(t),
846
- inputSchema: R,
874
+ execute: (t) => oe(t),
875
+ inputSchema: D,
847
876
  strict: !0
848
877
  }),
849
- execute_database_action_plan: v({
878
+ execute_database_action_plan: w({
850
879
  description: "Execute up to 8 typed database mutations as one confirmed plan. Mutating: first returns one combined confirmation preview and Confirm button; after confirmation, runs each action in order and stops on the first failure.",
851
- execute: (t) => ne(t, e),
852
- inputSchema: N,
880
+ execute: (t) => se(t, e),
881
+ inputSchema: L,
853
882
  strict: !0
854
883
  }),
855
- execute_database_mutation: v({
884
+ execute_database_mutation: w({
856
885
  description: "Run one typed insert, update, upsert, or delete against an allowed public database table. Mutating: always previews affected rows and requires exact user confirmation before execution. Does not support arbitrary SQL.",
857
- execute: (t) => X(t, e),
886
+ execute: (t) => V(t, e),
858
887
  inputSchema: O,
859
888
  strict: !0
860
889
  }),
861
- read_database_records: v({
890
+ read_database_records: w({
862
891
  description: "Read records from an allowed public database table with validated columns, filters, ordering, limit, and offset. Read-only and redacts protected secret-like values.",
863
- execute: (t) => oe(t, e),
864
- inputSchema: D,
892
+ execute: (t) => ne(t, e),
893
+ inputSchema: N,
865
894
  strict: !0
866
895
  })
867
896
  };
868
897
  }
869
898
  export {
870
- ue as createCortexDatabaseAgentTools,
871
- R as describeDatabaseSchemaInputSchema,
872
- ne as executeDatabaseActionPlan,
873
- N as executeDatabaseActionPlanInputSchema,
874
- X as executeDatabaseMutation,
899
+ le as createCortexDatabaseAgentTools,
900
+ D as describeDatabaseSchemaInputSchema,
901
+ se as executeDatabaseActionPlan,
902
+ L as executeDatabaseActionPlanInputSchema,
903
+ V as executeDatabaseMutation,
875
904
  O as executeDatabaseMutationInputSchema,
876
- ie as executeDescribeDatabaseSchema,
877
- oe as executeReadDatabaseRecords,
878
- D as readDatabaseRecordsInputSchema
905
+ oe as executeDescribeDatabaseSchema,
906
+ ne as executeReadDatabaseRecords,
907
+ N as readDatabaseRecordsInputSchema
879
908
  };