@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.
- package/index.cjs.js +1 -1
- package/index.d.ts +3 -0
- package/index.es.js +166 -121
- package/lib/ai-global-agent-db-tools.cjs.js +1 -1
- package/lib/ai-global-agent-db-tools.d.ts +8 -8
- package/lib/ai-global-agent-db-tools.es.js +154 -125
- package/lib/ai-global-agent-tools.cjs.js +2 -2
- package/lib/ai-global-agent-tools.d.ts +116 -97
- package/lib/ai-global-agent-tools.es.js +1223 -1181
- package/lib/mcp-server.cjs.js +1 -0
- package/lib/mcp-server.d.ts +76 -0
- package/lib/mcp-server.es.js +157 -0
- package/lib/mcp-tokens.cjs.js +1 -0
- package/lib/mcp-tokens.d.ts +95 -0
- package/lib/mcp-tokens.es.js +104 -0
- package/lib/mcp-tool-registry.cjs.js +4 -0
- package/lib/mcp-tool-registry.d.ts +234 -0
- package/lib/mcp-tool-registry.es.js +300 -0
- package/package.json +4 -4
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { tool as
|
|
1
|
+
import { tool as w } from "ai";
|
|
2
2
|
import "./zod-config.es.js";
|
|
3
3
|
import { z as n } from "zod";
|
|
4
|
-
const
|
|
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"]),
|
|
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
|
-
}),
|
|
453
|
+
}), W = n.strictObject({
|
|
434
454
|
ascending: n.boolean().default(!0),
|
|
435
455
|
column: n.string().trim().min(1).max(120)
|
|
436
|
-
}),
|
|
456
|
+
}), D = n.strictObject({
|
|
437
457
|
includeReadOnly: n.boolean().default(!0),
|
|
438
458
|
table: n.string().trim().min(1).max(120).optional()
|
|
439
|
-
}),
|
|
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(
|
|
442
|
-
limit: n.number().int().min(1).max(
|
|
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:
|
|
464
|
+
orderBy: W.optional(),
|
|
445
465
|
table: n.string().trim().min(1).max(120)
|
|
446
466
|
}), O = n.strictObject({
|
|
447
|
-
filters: n.array(
|
|
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
|
-
}),
|
|
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
|
|
466
|
-
return e === null || typeof e != "object" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((t) =>
|
|
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
|
|
488
|
+
function q(e) {
|
|
469
489
|
let t = 2166136261;
|
|
470
|
-
const r =
|
|
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
|
|
495
|
+
function K(e) {
|
|
476
496
|
return e.replace(/\s+/g, " ").trim().toUpperCase();
|
|
477
497
|
}
|
|
478
|
-
function
|
|
479
|
-
return `${
|
|
498
|
+
function Y(e, t, r) {
|
|
499
|
+
return `${K(`CONFIRM ${e} ${t}`)} #${q(r)}`;
|
|
480
500
|
}
|
|
481
|
-
function
|
|
501
|
+
function H(e) {
|
|
482
502
|
return {
|
|
483
|
-
confirmationPhrase:
|
|
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
|
|
510
|
+
function z(e) {
|
|
491
511
|
if (e.context?.skipConfirmation)
|
|
492
512
|
return null;
|
|
493
|
-
const t =
|
|
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
|
|
500
|
-
return Object.prototype.hasOwnProperty.call(
|
|
519
|
+
function Z(e) {
|
|
520
|
+
return Object.prototype.hasOwnProperty.call(I, e);
|
|
501
521
|
}
|
|
502
|
-
function
|
|
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 (!
|
|
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
|
|
531
|
+
return I[e];
|
|
512
532
|
}
|
|
513
|
-
function
|
|
533
|
+
function h(e) {
|
|
514
534
|
return /(?:password|token|secret|api[_-]?key|private[_-]?key|credential)/i.test(e);
|
|
515
535
|
}
|
|
516
|
-
function
|
|
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 (
|
|
539
|
+
if (h(t))
|
|
520
540
|
throw new Error(`Column "${t}" is protected and cannot be used through Cortex AI.`);
|
|
521
541
|
}
|
|
522
|
-
function
|
|
542
|
+
function $(e, t = "payload") {
|
|
523
543
|
if (Array.isArray(e)) {
|
|
524
|
-
e.forEach((r, 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 (
|
|
549
|
+
if (h(r))
|
|
530
550
|
throw new Error(`Protected field "${t}.${r}" cannot be written through Cortex AI.`);
|
|
531
|
-
|
|
551
|
+
$(a, `${t}.${r}`);
|
|
532
552
|
}
|
|
533
553
|
}
|
|
534
|
-
function
|
|
554
|
+
function b(e) {
|
|
535
555
|
if (Array.isArray(e))
|
|
536
|
-
return e.map((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] =
|
|
561
|
+
t[r] = h(r) ? P : b(a);
|
|
542
562
|
return t;
|
|
543
563
|
}
|
|
544
|
-
function
|
|
545
|
-
return e.map((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
|
|
574
|
+
function te(e, t) {
|
|
548
575
|
if (e !== "site_settings")
|
|
549
576
|
return;
|
|
550
|
-
|
|
551
|
-
|
|
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
|
|
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
|
|
608
|
+
function v(e, t, r) {
|
|
580
609
|
let a = t;
|
|
581
610
|
for (const o of r)
|
|
582
|
-
|
|
583
|
-
return e === "site_settings" && (a = a.neq("key",
|
|
611
|
+
g(e, o.column), a = re(a, o);
|
|
612
|
+
return e === "site_settings" && (a = a.neq("key", M)), a;
|
|
584
613
|
}
|
|
585
|
-
function
|
|
586
|
-
const r = _(e), a = t?.length ? t : r.columns.filter((o) => !
|
|
587
|
-
return a.forEach((o) =>
|
|
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
|
|
618
|
+
function F(e, t) {
|
|
590
619
|
return t.map((r) => `${r}=${String(e[r] ?? "")}`).join("|");
|
|
591
620
|
}
|
|
592
|
-
async function
|
|
621
|
+
async function U(e, t, r) {
|
|
593
622
|
const a = _(t);
|
|
594
|
-
let o = e.from(t).select(a.primaryKey.join(",")).limit(
|
|
595
|
-
o =
|
|
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 >
|
|
601
|
-
throw new Error(`Refusing to mutate more than ${
|
|
629
|
+
if (d.length > A)
|
|
630
|
+
throw new Error(`Refusing to mutate more than ${A} rows.`);
|
|
602
631
|
return d;
|
|
603
632
|
}
|
|
604
|
-
function
|
|
605
|
-
const t =
|
|
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 (
|
|
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
|
-
|
|
647
|
+
$(i);
|
|
619
648
|
for (const s of Object.keys(i))
|
|
620
|
-
|
|
649
|
+
g(t, s);
|
|
621
650
|
}
|
|
622
651
|
for (const i of e.filters ?? [])
|
|
623
|
-
|
|
652
|
+
g(t, i.column);
|
|
624
653
|
return t;
|
|
625
654
|
}
|
|
626
|
-
function
|
|
627
|
-
const { input: t, table: r, targetRows: a } = e, o = _(r), i = a.map((
|
|
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
|
|
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:
|
|
648
|
-
payload_hash:
|
|
649
|
-
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
|
|
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 =
|
|
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
|
|
669
|
-
const t =
|
|
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) => !
|
|
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
|
|
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
|
|
691
|
-
const r =
|
|
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 =
|
|
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:
|
|
731
|
+
rows: ee(l),
|
|
703
732
|
success: !0,
|
|
704
733
|
table: a
|
|
705
734
|
};
|
|
706
735
|
}
|
|
707
|
-
async function
|
|
708
|
-
const r = O.parse(e), a =
|
|
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 =
|
|
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
|
|
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:
|
|
732
|
-
auditLogged:
|
|
733
|
-
...
|
|
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:
|
|
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 (
|
|
742
|
-
const
|
|
770
|
+
} catch (p) {
|
|
771
|
+
const m = f(p), c = t?.skipAudit ? { auditLogged: !1 } : await x({
|
|
743
772
|
context: t,
|
|
744
|
-
errorMessage:
|
|
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: ${
|
|
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
|
|
764
|
-
const r =
|
|
792
|
+
async function se(e, t) {
|
|
793
|
+
const r = L.parse(e), a = [];
|
|
765
794
|
for (const c of r.actions) {
|
|
766
|
-
const y =
|
|
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:
|
|
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 =
|
|
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
|
|
821
|
+
let p = !1;
|
|
793
822
|
for (const [c, y] of a.entries()) {
|
|
794
|
-
const u = await
|
|
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 && (
|
|
800
|
-
const S = await
|
|
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:
|
|
845
|
+
mutationExecuted: p,
|
|
817
846
|
results: l,
|
|
818
847
|
success: !1
|
|
819
848
|
};
|
|
820
849
|
}
|
|
821
850
|
}
|
|
822
|
-
const
|
|
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:
|
|
834
|
-
...
|
|
835
|
-
mutationExecuted:
|
|
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
|
|
870
|
+
function le(e) {
|
|
842
871
|
return {
|
|
843
|
-
describe_database_schema:
|
|
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) =>
|
|
846
|
-
inputSchema:
|
|
874
|
+
execute: (t) => oe(t),
|
|
875
|
+
inputSchema: D,
|
|
847
876
|
strict: !0
|
|
848
877
|
}),
|
|
849
|
-
execute_database_action_plan:
|
|
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) =>
|
|
852
|
-
inputSchema:
|
|
880
|
+
execute: (t) => se(t, e),
|
|
881
|
+
inputSchema: L,
|
|
853
882
|
strict: !0
|
|
854
883
|
}),
|
|
855
|
-
execute_database_mutation:
|
|
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) =>
|
|
886
|
+
execute: (t) => V(t, e),
|
|
858
887
|
inputSchema: O,
|
|
859
888
|
strict: !0
|
|
860
889
|
}),
|
|
861
|
-
read_database_records:
|
|
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) =>
|
|
864
|
-
inputSchema:
|
|
892
|
+
execute: (t) => ne(t, e),
|
|
893
|
+
inputSchema: N,
|
|
865
894
|
strict: !0
|
|
866
895
|
})
|
|
867
896
|
};
|
|
868
897
|
}
|
|
869
898
|
export {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
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
|
-
|
|
877
|
-
|
|
878
|
-
|
|
905
|
+
oe as executeDescribeDatabaseSchema,
|
|
906
|
+
ne as executeReadDatabaseRecords,
|
|
907
|
+
N as readDatabaseRecordsInputSchema
|
|
879
908
|
};
|