@nextblock-cms/cortex 0.14.5 → 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.
@@ -105,7 +105,7 @@ export declare function executeDescribeDatabaseSchema(input: z.input<typeof desc
105
105
  description: string;
106
106
  primaryKey: readonly string[];
107
107
  readOnly: boolean;
108
- table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping" | "product_revisions";
108
+ table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "product_revisions" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping";
109
109
  }[];
110
110
  }>;
111
111
  export declare function executeReadDatabaseRecords(input: z.input<typeof readDatabaseRecordsInputSchema>, context?: ToolExecutionContext): Promise<{
@@ -114,7 +114,7 @@ export declare function executeReadDatabaseRecords(input: z.input<typeof readDat
114
114
  offset: number;
115
115
  rows: unknown[];
116
116
  success: boolean;
117
- table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping" | "product_revisions";
117
+ table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "product_revisions" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping";
118
118
  }>;
119
119
  export declare function executeDatabaseMutation(input: ExecuteDatabaseMutationInput, context?: ToolExecutionContext): Promise<{
120
120
  confirmationPhrase: string;
@@ -128,7 +128,7 @@ export declare function executeDatabaseMutation(input: ExecuteDatabaseMutationIn
128
128
  sampleTargetIds: string[];
129
129
  success: boolean;
130
130
  summary: string;
131
- table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping" | "product_revisions";
131
+ table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "product_revisions" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping";
132
132
  auditError?: string | undefined;
133
133
  affectedCount: number;
134
134
  auditLogged: boolean;
@@ -137,7 +137,7 @@ export declare function executeDatabaseMutation(input: ExecuteDatabaseMutationIn
137
137
  mutationExecuted: boolean;
138
138
  operation: "delete" | "update" | "insert" | "upsert";
139
139
  success: boolean;
140
- table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping" | "product_revisions";
140
+ table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "product_revisions" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping";
141
141
  auditError?: string | undefined;
142
142
  auditLogged: boolean;
143
143
  }>;
@@ -177,7 +177,7 @@ export declare function createCortexDatabaseAgentTools(context?: ToolExecutionCo
177
177
  description: string;
178
178
  primaryKey: readonly string[];
179
179
  readOnly: boolean;
180
- table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping" | "product_revisions";
180
+ table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "product_revisions" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping";
181
181
  }[];
182
182
  }>;
183
183
  execute_database_action_plan: import('ai').Tool<{
@@ -241,7 +241,7 @@ export declare function createCortexDatabaseAgentTools(context?: ToolExecutionCo
241
241
  sampleTargetIds: string[];
242
242
  success: boolean;
243
243
  summary: string;
244
- table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping" | "product_revisions";
244
+ table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "product_revisions" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping";
245
245
  auditError?: string | undefined;
246
246
  affectedCount: number;
247
247
  auditLogged: boolean;
@@ -250,7 +250,7 @@ export declare function createCortexDatabaseAgentTools(context?: ToolExecutionCo
250
250
  mutationExecuted: boolean;
251
251
  operation: "delete" | "update" | "insert" | "upsert";
252
252
  success: boolean;
253
- table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping" | "product_revisions";
253
+ table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "product_revisions" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping";
254
254
  auditError?: string | undefined;
255
255
  auditLogged: boolean;
256
256
  }>;
@@ -274,7 +274,7 @@ export declare function createCortexDatabaseAgentTools(context?: ToolExecutionCo
274
274
  offset: number;
275
275
  rows: unknown[];
276
276
  success: boolean;
277
- table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping" | "product_revisions";
277
+ table: "site_settings" | "languages" | "pages" | "posts" | "products" | "profiles" | "coupons" | "orders" | "freemius_plans" | "media" | "navigation_items" | "product_variants" | "product_attributes" | "shipping_zones" | "product_attribute_terms" | "blocks" | "cortex_ai_db_mutation_audit" | "coupon_freemius_mappings" | "coupon_products" | "coupon_redemptions" | "currencies" | "freemius_pricing" | "inventory_items" | "logos" | "order_items" | "package_activations" | "page_revisions" | "post_revisions" | "product_media" | "product_revisions" | "shipping_zone_locations" | "shipping_zone_methods" | "tax_rates" | "translations" | "user_addresses" | "variant_attribute_mapping";
278
278
  }>;
279
279
  };
280
280
  export {};
@@ -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", O = {
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.",
@@ -439,32 +446,32 @@ const V = 100, J = 20, C = 100, k = 20, M = "[REDACTED]", g = "cortex_ai_openrou
439
446
  description: "Variant to attribute-term join rows.",
440
447
  primaryKey: ["variant_id", "attribute_term_id"]
441
448
  }
442
- }, 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({
443
450
  column: n.string().trim().min(1).max(120),
444
451
  operator: Q.default("eq"),
445
452
  value: n.unknown()
446
- }), G = n.strictObject({
453
+ }), W = n.strictObject({
447
454
  ascending: n.boolean().default(!0),
448
455
  column: n.string().trim().min(1).max(120)
449
- }), R = n.strictObject({
456
+ }), D = n.strictObject({
450
457
  includeReadOnly: n.boolean().default(!0),
451
458
  table: n.string().trim().min(1).max(120).optional()
452
- }), D = n.strictObject({
459
+ }), N = n.strictObject({
453
460
  columns: n.array(n.string().trim().min(1).max(120)).min(1).max(40).optional(),
454
- filters: n.array(P).max(12).default([]),
455
- 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),
456
463
  offset: n.number().int().min(0).max(1e4).default(0),
457
- orderBy: G.optional(),
464
+ orderBy: W.optional(),
458
465
  table: n.string().trim().min(1).max(120)
459
- }), j = n.strictObject({
460
- filters: n.array(P).max(12).optional(),
466
+ }), O = n.strictObject({
467
+ filters: n.array(R).max(12).optional(),
461
468
  operation: n.enum(["delete", "insert", "update", "upsert"]),
462
469
  rows: n.array(n.record(n.string(), n.unknown())).min(1).max(k).optional(),
463
470
  summary: n.string().trim().min(1).max(500).optional(),
464
471
  table: n.string().trim().min(1).max(120),
465
472
  values: n.record(n.string(), n.unknown()).optional()
466
- }), N = n.strictObject({
467
- actions: n.array(j).min(1).max(8),
473
+ }), L = n.strictObject({
474
+ actions: n.array(O).min(1).max(8),
468
475
  summary: n.string().trim().min(1).max(500).optional()
469
476
  });
470
477
  function E(e) {
@@ -475,95 +482,104 @@ function E(e) {
475
482
  function f(e) {
476
483
  return e ? typeof e == "object" && "message" in e ? String(e.message || "Unknown database error.") : String(e) : "Unknown database error.";
477
484
  }
478
- function K(e) {
479
- 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(",")}}`;
480
487
  }
481
- function L(e) {
488
+ function q(e) {
482
489
  let t = 2166136261;
483
- const r = K(e);
490
+ const r = C(e);
484
491
  for (let a = 0; a < r.length; a++)
485
492
  t ^= r.charCodeAt(a), t = Math.imul(t, 16777619);
486
493
  return (t >>> 0).toString(16).padStart(8, "0");
487
494
  }
488
- function $(e) {
495
+ function K(e) {
489
496
  return e.replace(/\s+/g, " ").trim().toUpperCase();
490
497
  }
491
- function W(e, t, r) {
492
- return `${$(`CONFIRM ${e} ${t}`)} #${L(r)}`;
498
+ function Y(e, t, r) {
499
+ return `${K(`CONFIRM ${e} ${t}`)} #${q(r)}`;
493
500
  }
494
- function Y(e) {
501
+ function H(e) {
495
502
  return {
496
- confirmationPhrase: W(e.action, e.subject, e.payload),
503
+ confirmationPhrase: Y(e.action, e.subject, e.payload),
497
504
  mutationExecuted: !1,
498
505
  preview: e.preview,
499
506
  requiresConfirmation: !0,
500
507
  success: !0
501
508
  };
502
509
  }
503
- function q(e) {
510
+ function z(e) {
504
511
  if (e.context?.skipConfirmation)
505
512
  return null;
506
- 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);
507
514
  return r && !r.includes(a) ? {
508
515
  ...t,
509
516
  message: "The database target changed or the confirmation did not match. Please review and confirm again."
510
517
  } : r.includes(a) ? null : t;
511
518
  }
512
- function H(e) {
513
- return Object.prototype.hasOwnProperty.call(O, e);
519
+ function Z(e) {
520
+ return Object.prototype.hasOwnProperty.call(I, e);
514
521
  }
515
- function T(e) {
522
+ function j(e) {
516
523
  const t = e.trim();
517
524
  if (t.includes(".") || t.toLowerCase().startsWith("auth"))
518
525
  throw new Error("Cortex AI cannot access auth schema tables.");
519
- if (!H(t))
526
+ if (!Z(t))
520
527
  throw new Error(`Table "${t}" is not available to Cortex AI database tools.`);
521
528
  return t;
522
529
  }
523
530
  function _(e) {
524
- return O[e];
531
+ return I[e];
525
532
  }
526
- function w(e) {
533
+ function h(e) {
527
534
  return /(?:password|token|secret|api[_-]?key|private[_-]?key|credential)/i.test(e);
528
535
  }
529
- function b(e, t) {
536
+ function g(e, t) {
530
537
  if (!_(e).columns.includes(t))
531
538
  throw new Error(`Column "${t}" is not available on table "${e}".`);
532
- if (w(t))
539
+ if (h(t))
533
540
  throw new Error(`Column "${t}" is protected and cannot be used through Cortex AI.`);
534
541
  }
535
- function I(e, t = "payload") {
542
+ function $(e, t = "payload") {
536
543
  if (Array.isArray(e)) {
537
- e.forEach((r, a) => I(r, `${t}[${a}]`));
544
+ e.forEach((r, a) => $(r, `${t}[${a}]`));
538
545
  return;
539
546
  }
540
547
  if (!(!e || typeof e != "object"))
541
548
  for (const [r, a] of Object.entries(e)) {
542
- if (w(r))
549
+ if (h(r))
543
550
  throw new Error(`Protected field "${t}.${r}" cannot be written through Cortex AI.`);
544
- I(a, `${t}.${r}`);
551
+ $(a, `${t}.${r}`);
545
552
  }
546
553
  }
547
- function h(e) {
554
+ function b(e) {
548
555
  if (Array.isArray(e))
549
- return e.map((r) => h(r));
556
+ return e.map((r) => b(r));
550
557
  if (!e || typeof e != "object")
551
558
  return e;
552
559
  const t = {};
553
560
  for (const [r, a] of Object.entries(e))
554
- t[r] = w(r) ? M : h(a);
561
+ t[r] = h(r) ? P : b(a);
555
562
  return t;
556
563
  }
557
- function Z(e) {
558
- 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
+ });
559
573
  }
560
- function ee(e, t) {
574
+ function te(e, t) {
561
575
  if (e !== "site_settings")
562
576
  return;
563
- if (JSON.stringify(t).toLowerCase().includes(g))
564
- 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.`);
565
581
  }
566
- function te(e, t) {
582
+ function re(e, t) {
567
583
  switch (t.operator) {
568
584
  case "eq":
569
585
  return e.eq(t.column, t.value);
@@ -589,36 +605,36 @@ function te(e, t) {
589
605
  return e.is(t.column, t.value);
590
606
  }
591
607
  }
592
- function x(e, t, r) {
608
+ function v(e, t, r) {
593
609
  let a = t;
594
610
  for (const o of r)
595
- b(e, o.column), a = te(a, o);
596
- 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;
597
613
  }
598
- function re(e, t) {
599
- const r = _(e), a = t?.length ? t : r.columns.filter((o) => !w(o));
600
- 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(",");
601
617
  }
602
- function z(e, t) {
618
+ function F(e, t) {
603
619
  return t.map((r) => `${r}=${String(e[r] ?? "")}`).join("|");
604
620
  }
605
- async function F(e, t, r) {
621
+ async function U(e, t, r) {
606
622
  const a = _(t);
607
- let o = e.from(t).select(a.primaryKey.join(",")).limit(C + 1);
608
- o = x(t, o, r);
623
+ let o = e.from(t).select(a.primaryKey.join(",")).limit(A + 1);
624
+ o = v(t, o, r);
609
625
  const { data: i, error: s } = await o;
610
626
  if (s)
611
627
  throw new Error(`Failed to preview database mutation: ${f(s)}`);
612
628
  const d = Array.isArray(i) ? i : [];
613
- if (d.length > C)
614
- 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.`);
615
631
  return d;
616
632
  }
617
- function U(e) {
618
- 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;
619
635
  if (r.readOnly)
620
636
  throw new Error(`Table "${t}" is read-only for Cortex AI.`);
621
- 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))
622
638
  throw new Error(`${a} operations require at least one filter.`);
623
639
  if ((a === "insert" || a === "upsert") && (!e.rows || e.rows.length === 0))
624
640
  throw new Error(`${a} operations require rows.`);
@@ -628,16 +644,16 @@ function U(e) {
628
644
  throw new Error(`Refusing to mutate more than ${k} input rows.`);
629
645
  const o = e.rows ?? (e.values ? [e.values] : []);
630
646
  for (const i of o) {
631
- I(i);
647
+ $(i);
632
648
  for (const s of Object.keys(i))
633
- b(t, s);
649
+ g(t, s);
634
650
  }
635
651
  for (const i of e.filters ?? [])
636
- b(t, i.column);
652
+ g(t, i.column);
637
653
  return t;
638
654
  }
639
- function B(e) {
640
- 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}.`;
641
657
  return {
642
658
  affectedCount: d,
643
659
  operation: t.operation,
@@ -647,7 +663,7 @@ function B(e) {
647
663
  targetIds: i
648
664
  };
649
665
  }
650
- async function A(e) {
666
+ async function x(e) {
651
667
  const t = e.context?.actorUserId;
652
668
  if (!t)
653
669
  return { auditError: "Missing actor user id.", auditLogged: !1 };
@@ -657,9 +673,9 @@ async function A(e) {
657
673
  actor_user_id: t,
658
674
  error_message: e.errorMessage ?? null,
659
675
  operation_summary: e.summary,
660
- payload: h(e.input),
661
- payload_hash: L(e.input),
662
- preview: h(e.preview),
676
+ payload: b(e.input),
677
+ payload_hash: q(e.input),
678
+ preview: b(e.preview),
663
679
  status: e.status,
664
680
  target_tables: e.targetTables,
665
681
  tool_name: e.toolName
@@ -669,20 +685,20 @@ async function A(e) {
669
685
  return { auditError: f(r), auditLogged: !1 };
670
686
  }
671
687
  }
672
- async function ae(e, t, r) {
688
+ async function ie(e, t, r) {
673
689
  const o = _(t).primaryKey.join(",");
674
690
  let i;
675
- 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));
676
692
  const { data: s, error: d } = await i;
677
693
  if (d)
678
694
  throw new Error(f(d));
679
695
  return Array.isArray(s) ? s : [];
680
696
  }
681
- async function ie(e) {
682
- const t = R.parse(e), a = (t.table ? [T(t.table)] : Object.keys(O)).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) => {
683
699
  const i = _(o);
684
700
  return {
685
- columns: i.columns.filter((s) => !w(s)),
701
+ columns: i.columns.filter((s) => !h(s)),
686
702
  description: i.description,
687
703
  primaryKey: i.primaryKey,
688
704
  readOnly: !!i.readOnly,
@@ -694,16 +710,16 @@ async function ie(e) {
694
710
  "Use read_database_records for reads and execute_database_mutation/action_plan for writes.",
695
711
  "No auth schema access, no arbitrary SQL, no password/secret/API-key fields.",
696
712
  "profiles, user_addresses, and cortex_ai_db_mutation_audit are read-only.",
697
- `site_settings.${g} is protected.`
713
+ `Protected site_settings keys (never readable or writable): ${[...T].sort().join(", ")}.`
698
714
  ],
699
715
  success: !0,
700
716
  tables: a
701
717
  };
702
718
  }
703
- async function oe(e, t) {
704
- 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);
705
721
  let i = E(t).from(a).select(o).range(r.offset, r.offset + r.limit - 1);
706
- 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 }));
707
723
  const { data: s, error: d } = await i;
708
724
  if (d)
709
725
  throw new Error(`Failed to read database records: ${f(d)}`);
@@ -712,16 +728,16 @@ async function oe(e, t) {
712
728
  columns: o.split(","),
713
729
  limit: r.limit,
714
730
  offset: r.offset,
715
- rows: Z(l),
731
+ rows: ee(l),
716
732
  success: !0,
717
733
  table: a
718
734
  };
719
735
  }
720
- async function X(e, t) {
721
- const r = j.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 = {
722
738
  input: r,
723
739
  targetIds: s.targetIds
724
- }, l = q({
740
+ }, l = z({
725
741
  action: `DATABASE ${r.operation}`,
726
742
  context: t,
727
743
  payload: d,
@@ -731,7 +747,7 @@ async function X(e, t) {
731
747
  if (l)
732
748
  return l;
733
749
  try {
734
- 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({
735
751
  context: t,
736
752
  input: d,
737
753
  preview: s,
@@ -741,20 +757,20 @@ async function X(e, t) {
741
757
  toolName: "execute_database_mutation"
742
758
  });
743
759
  return {
744
- affectedCount: m.length || s.affectedCount,
745
- auditLogged: p.auditLogged,
746
- ...p.auditError ? { auditError: p.auditError } : {},
760
+ affectedCount: p.length || s.affectedCount,
761
+ auditLogged: m.auditLogged,
762
+ ...m.auditError ? { auditError: m.auditError } : {},
747
763
  mutationExecuted: !0,
748
764
  operation: r.operation,
749
- sampleTargetIds: m.map((c) => z(c, _(a).primaryKey)).slice(0, 10),
765
+ sampleTargetIds: p.map((c) => F(c, _(a).primaryKey)).slice(0, 10),
750
766
  success: !0,
751
767
  summary: s.summary,
752
768
  table: a
753
769
  };
754
- } catch (m) {
755
- 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({
756
772
  context: t,
757
- errorMessage: p,
773
+ errorMessage: m,
758
774
  input: d,
759
775
  preview: s,
760
776
  status: "failure",
@@ -765,7 +781,7 @@ async function X(e, t) {
765
781
  return {
766
782
  auditLogged: c.auditLogged,
767
783
  ...c.auditError ? { auditError: c.auditError } : {},
768
- message: `Database mutation failed: ${p}`,
784
+ message: `Database mutation failed: ${m}`,
769
785
  mutationExecuted: !1,
770
786
  operation: r.operation,
771
787
  success: !1,
@@ -773,13 +789,13 @@ async function X(e, t) {
773
789
  };
774
790
  }
775
791
  }
776
- async function ne(e, t) {
777
- const r = N.parse(e), a = [];
792
+ async function se(e, t) {
793
+ const r = L.parse(e), a = [];
778
794
  for (const c of r.actions) {
779
- 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 ?? []) : [];
780
796
  a.push({
781
797
  input: c,
782
- preview: B({ input: c, table: y, targetRows: u }),
798
+ preview: X({ input: c, table: y, targetRows: u }),
783
799
  table: y
784
800
  });
785
801
  }
@@ -792,7 +808,7 @@ async function ne(e, t) {
792
808
  input: c,
793
809
  table: u,
794
810
  targetIds: y.targetIds
795
- })), d = q({
811
+ })), d = z({
796
812
  action: "DATABASE ACTION PLAN",
797
813
  context: t,
798
814
  payload: s,
@@ -802,15 +818,15 @@ async function ne(e, t) {
802
818
  if (d)
803
819
  return d;
804
820
  const l = [];
805
- let m = !1;
821
+ let p = !1;
806
822
  for (const [c, y] of a.entries()) {
807
- const u = await X(y.input, {
823
+ const u = await V(y.input, {
808
824
  ...t,
809
825
  skipAudit: !0,
810
826
  skipConfirmation: !0
811
827
  });
812
- if (l.push(u), u && typeof u == "object" && u.mutationExecuted === !0 && (m = !0), !u || typeof u != "object" || u.success === !1) {
813
- 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({
814
830
  context: t,
815
831
  errorMessage: u && typeof u == "object" && typeof u.message == "string" ? u.message : `Database action ${c + 1} failed.`,
816
832
  input: s,
@@ -826,13 +842,13 @@ async function ne(e, t) {
826
842
  ...S.auditError ? { auditError: S.auditError } : {},
827
843
  failedActionIndex: c,
828
844
  message: u && typeof u == "object" && typeof u.message == "string" ? u.message : `Database action ${c + 1} failed.`,
829
- mutationExecuted: m,
845
+ mutationExecuted: p,
830
846
  results: l,
831
847
  success: !1
832
848
  };
833
849
  }
834
850
  }
835
- const p = await A({
851
+ const m = await x({
836
852
  context: t,
837
853
  input: s,
838
854
  preview: i,
@@ -843,50 +859,50 @@ async function ne(e, t) {
843
859
  });
844
860
  return {
845
861
  actionCount: a.length,
846
- auditLogged: p.auditLogged,
847
- ...p.auditError ? { auditError: p.auditError } : {},
848
- mutationExecuted: m,
862
+ auditLogged: m.auditLogged,
863
+ ...m.auditError ? { auditError: m.auditError } : {},
864
+ mutationExecuted: p,
849
865
  results: l,
850
866
  success: !0,
851
867
  summary: r.summary ?? null
852
868
  };
853
869
  }
854
- function ue(e) {
870
+ function le(e) {
855
871
  return {
856
- describe_database_schema: v({
872
+ describe_database_schema: w({
857
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.",
858
- execute: (t) => ie(t),
859
- inputSchema: R,
874
+ execute: (t) => oe(t),
875
+ inputSchema: D,
860
876
  strict: !0
861
877
  }),
862
- execute_database_action_plan: v({
878
+ execute_database_action_plan: w({
863
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.",
864
- execute: (t) => ne(t, e),
865
- inputSchema: N,
880
+ execute: (t) => se(t, e),
881
+ inputSchema: L,
866
882
  strict: !0
867
883
  }),
868
- execute_database_mutation: v({
884
+ execute_database_mutation: w({
869
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.",
870
- execute: (t) => X(t, e),
871
- inputSchema: j,
886
+ execute: (t) => V(t, e),
887
+ inputSchema: O,
872
888
  strict: !0
873
889
  }),
874
- read_database_records: v({
890
+ read_database_records: w({
875
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.",
876
- execute: (t) => oe(t, e),
877
- inputSchema: D,
892
+ execute: (t) => ne(t, e),
893
+ inputSchema: N,
878
894
  strict: !0
879
895
  })
880
896
  };
881
897
  }
882
898
  export {
883
- ue as createCortexDatabaseAgentTools,
884
- R as describeDatabaseSchemaInputSchema,
885
- ne as executeDatabaseActionPlan,
886
- N as executeDatabaseActionPlanInputSchema,
887
- X as executeDatabaseMutation,
888
- j as executeDatabaseMutationInputSchema,
889
- ie as executeDescribeDatabaseSchema,
890
- oe as executeReadDatabaseRecords,
891
- D as readDatabaseRecordsInputSchema
899
+ le as createCortexDatabaseAgentTools,
900
+ D as describeDatabaseSchemaInputSchema,
901
+ se as executeDatabaseActionPlan,
902
+ L as executeDatabaseActionPlanInputSchema,
903
+ V as executeDatabaseMutation,
904
+ O as executeDatabaseMutationInputSchema,
905
+ oe as executeDescribeDatabaseSchema,
906
+ ne as executeReadDatabaseRecords,
907
+ N as readDatabaseRecordsInputSchema
892
908
  };