@nextblock-cms/cortex 0.20.3 → 0.21.1
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/README.md +46 -0
- package/client.cjs +1 -0
- package/client.es.js +3 -7
- package/index.cjs +1 -0
- package/index.es.js +24 -277
- package/lib/ai-block-generation.cjs +4 -0
- package/lib/ai-block-generation.es.js +143 -182
- package/lib/ai-client.cjs +1 -0
- package/lib/ai-client.d.ts +1 -1
- package/lib/ai-client.es.js +101 -135
- package/lib/ai-config.cjs +1 -0
- package/lib/ai-config.es.js +89 -108
- package/lib/ai-cortex-widget-builder.cjs +1 -0
- package/lib/ai-cortex-widget-builder.es.js +56 -70
- package/lib/ai-global-agent-content-ops-tools.cjs +1 -0
- package/lib/ai-global-agent-content-ops-tools.d.ts +1943 -68
- package/lib/ai-global-agent-content-ops-tools.es.js +185 -199
- package/lib/ai-global-agent-custom-block-tools.cjs +1 -0
- package/lib/ai-global-agent-custom-block-tools.d.ts +2160 -95
- package/lib/ai-global-agent-custom-block-tools.es.js +226 -223
- package/lib/ai-global-agent-db-tools.cjs +1 -0
- package/lib/ai-global-agent-db-tools.d.ts +2708 -98
- package/lib/ai-global-agent-db-tools.es.js +1013 -986
- package/lib/ai-global-agent-ecommerce.cjs +1 -0
- package/lib/ai-global-agent-ecommerce.es.js +3 -7
- package/lib/ai-global-agent-site-tools.cjs +2 -0
- package/lib/ai-global-agent-site-tools.d.ts +10695 -500
- package/lib/ai-global-agent-site-tools.es.js +750 -757
- package/lib/ai-global-agent-theming-tools.cjs +1 -0
- package/lib/ai-global-agent-theming-tools.d.ts +2905 -105
- package/lib/ai-global-agent-theming-tools.es.js +326 -396
- package/lib/ai-global-agent-tools.cjs +15 -0
- package/lib/ai-global-agent-tools.d.ts +4 -2230
- package/lib/ai-global-agent-tools.es.js +3899 -4328
- package/lib/ai-key-crypto.cjs +1 -0
- package/lib/ai-key-crypto.es.js +63 -82
- package/lib/ai-key-verification.cjs +1 -0
- package/lib/ai-key-verification.es.js +74 -63
- package/lib/ai-model-catalog.cjs +1 -0
- package/lib/ai-model-catalog.es.js +18 -22
- package/lib/ai-model-registry.cjs +2 -0
- package/lib/ai-model-registry.es.js +246 -309
- package/lib/ai-seo-metadata.cjs +3 -0
- package/lib/ai-seo-metadata.es.js +143 -185
- package/lib/ai-vision.cjs +3 -0
- package/lib/ai-vision.d.ts +6 -6
- package/lib/ai-vision.es.js +161 -215
- package/lib/block-content-schemas.cjs +1 -0
- package/lib/block-content-schemas.es.js +324 -254
- package/lib/cortex-widget-registry.cjs +1 -0
- package/lib/cortex-widget-registry.es.js +35 -43
- package/lib/cortex-widget-schema.cjs +4 -0
- package/lib/cortex-widget-schema.es.js +280 -309
- package/lib/editor-document-from-html.cjs +1 -0
- package/lib/editor-document-from-html.es.js +334 -278
- package/lib/fetch-host-guard.cjs +1 -0
- package/lib/fetch-host-guard.d.ts +2 -0
- package/lib/fetch-host-guard.es.js +30 -0
- package/lib/mcp-server.cjs +1 -0
- package/lib/mcp-server.es.js +155 -173
- package/lib/mcp-tokens.cjs +1 -0
- package/lib/mcp-tokens.es.js +95 -107
- package/lib/mcp-tool-registry.cjs +5 -0
- package/lib/mcp-tool-registry.es.js +533 -411
- package/lib/site-brief.cjs +2 -0
- package/lib/site-brief.es.js +102 -108
- package/lib/vision-image-download.cjs +1 -0
- package/lib/vision-image-download.d.ts +43 -0
- package/lib/vision-image-download.es.js +120 -0
- package/lib/zod-config.cjs +1 -0
- package/lib/zod-config.es.js +5 -6
- package/package.json +13 -12
- package/client.cjs.js +0 -1
- package/index.cjs.js +0 -1
- package/lib/ai-block-generation.cjs.js +0 -5
- package/lib/ai-client.cjs.js +0 -1
- package/lib/ai-config.cjs.js +0 -1
- package/lib/ai-cortex-widget-builder.cjs.js +0 -1
- package/lib/ai-global-agent-content-ops-tools.cjs.js +0 -1
- package/lib/ai-global-agent-custom-block-tools.cjs.js +0 -1
- package/lib/ai-global-agent-db-tools.cjs.js +0 -1
- package/lib/ai-global-agent-ecommerce.cjs.js +0 -1
- package/lib/ai-global-agent-site-tools.cjs.js +0 -3
- package/lib/ai-global-agent-theming-tools.cjs.js +0 -3
- package/lib/ai-global-agent-tools.cjs.js +0 -15
- package/lib/ai-key-crypto.cjs.js +0 -1
- package/lib/ai-key-verification.cjs.js +0 -1
- package/lib/ai-model-catalog.cjs.js +0 -1
- package/lib/ai-model-registry.cjs.js +0 -2
- package/lib/ai-seo-metadata.cjs.js +0 -4
- package/lib/ai-vision.cjs.js +0 -3
- package/lib/block-content-schemas.cjs.js +0 -1
- package/lib/cortex-widget-registry.cjs.js +0 -1
- package/lib/cortex-widget-schema.cjs.js +0 -5
- package/lib/editor-document-from-html.cjs.js +0 -1
- package/lib/mcp-server.cjs.js +0 -1
- package/lib/mcp-tokens.cjs.js +0 -1
- package/lib/mcp-tool-registry.cjs.js +0 -6
- package/lib/site-brief.cjs.js +0 -2
- package/lib/zod-config.cjs.js +0 -1
|
@@ -1,1025 +1,1052 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import "
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
]),
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
]),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import { z as e } from "./zod-config.es.js";
|
|
2
|
+
import { cortexSiteBriefSchema as t } from "./site-brief.es.js";
|
|
3
|
+
import { isValidBlockType as n, loadCustomBlockDefinitions as r, validateCortexBlockContent as i, validateCustomBlockInstanceContent as a } from "./block-content-schemas.es.js";
|
|
4
|
+
import { tool as o } from "ai";
|
|
5
|
+
//#region src/lib/ai-global-agent-db-tools.ts
|
|
6
|
+
var s = 100, c = 20, l = 100, u = 20, d = "[REDACTED]", f = "cortex_ai_openrouter_api_key", p = /* @__PURE__ */ new Set([
|
|
7
|
+
f,
|
|
8
|
+
"bot_protection_secret",
|
|
9
|
+
"cortex_ai_pexels_api_key",
|
|
10
|
+
"cortex_ai_unsplash_access_key",
|
|
11
|
+
"email_secret",
|
|
12
|
+
"payment_secret"
|
|
13
|
+
]), m = /* @__PURE__ */ new Set([
|
|
14
|
+
"cortex_ai_build_session",
|
|
15
|
+
"is_admin_created",
|
|
16
|
+
"migration_baseline_generation",
|
|
17
|
+
"security_settings"
|
|
18
|
+
]), ee = {
|
|
19
|
+
active_logo_id: e.string().uuid().nullable(),
|
|
20
|
+
cortex_ai_site_brief: t,
|
|
21
|
+
footer_copyright: e.record(e.string().trim().min(2).max(12), e.string().max(500)),
|
|
22
|
+
footer_show_attribution: e.boolean(),
|
|
23
|
+
global_css: e.string().max(2e5),
|
|
24
|
+
onboarding_state: e.record(e.string(), e.unknown()),
|
|
25
|
+
site_description: e.string().max(1e3),
|
|
26
|
+
site_keywords: e.string().max(1e3),
|
|
27
|
+
site_title: e.string().max(200)
|
|
28
28
|
};
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
function h(e) {
|
|
30
|
+
return e.map((e) => {
|
|
31
|
+
let t = e.path.map(String).join(".");
|
|
32
|
+
return t ? `${t}: ${e.message}` : e.message;
|
|
33
|
+
}).join("; ");
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const a = r.safeParse(t);
|
|
42
|
-
if (!a.success)
|
|
43
|
-
throw new Error(`Invalid value for site setting "${e}": ${oe(a.error.issues)}`);
|
|
35
|
+
function g(e, t) {
|
|
36
|
+
if (m.has(e)) throw Error(`The "${e}" site setting cannot be written through Cortex AI database tools.`);
|
|
37
|
+
let n = ee[e];
|
|
38
|
+
if (!n) return;
|
|
39
|
+
let r = n.safeParse(t);
|
|
40
|
+
if (!r.success) throw Error(`Invalid value for site setting "${e}": ${h(r.error.issues)}`);
|
|
44
41
|
}
|
|
45
|
-
async function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!a)
|
|
60
|
-
throw new Error(
|
|
61
|
-
`${e.label}: "${t}" is neither a built-in block type nor a custom block slug. Use list_custom_blocks to see the custom block definitions.`
|
|
62
|
-
);
|
|
63
|
-
const n = Z(a, r);
|
|
64
|
-
if (!n.isValid)
|
|
65
|
-
throw new Error(`${e.label}: content is invalid for custom block "${t}": ${n.errors.join("; ")}`);
|
|
42
|
+
async function _(e) {
|
|
43
|
+
let t = typeof e.blockType == "string" ? e.blockType : "";
|
|
44
|
+
if (!t) throw Error(`${e.label}: block_type is required.`);
|
|
45
|
+
if (!e.content || typeof e.content != "object" || Array.isArray(e.content)) throw Error(`${e.label}: content must be a JSON object.`);
|
|
46
|
+
let r = e.content;
|
|
47
|
+
if (n(t)) {
|
|
48
|
+
let n = i(t, r, e.context);
|
|
49
|
+
if (!n.isValid) throw Error(`${e.label}: content is invalid for block type "${t}": ${n.errors.join("; ")}`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
let o = (await e.definitions()).find((e) => e.slug === t);
|
|
53
|
+
if (!o) throw Error(`${e.label}: "${t}" is neither a built-in block type nor a custom block slug. Use list_custom_blocks to see the custom block definitions.`);
|
|
54
|
+
let s = a(o, r);
|
|
55
|
+
if (!s.isValid) throw Error(`${e.label}: content is invalid for custom block "${t}": ${s.errors.join("; ")}`);
|
|
66
56
|
}
|
|
67
|
-
async function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
for (const d of Array.isArray(_) ? _ : [])
|
|
110
|
-
c.add(String(d.block_type ?? ""));
|
|
111
|
-
}
|
|
112
|
-
for (const u of c)
|
|
113
|
-
await R({
|
|
114
|
-
blockType: u,
|
|
115
|
-
content: e.values.content,
|
|
116
|
-
context: r,
|
|
117
|
-
definitions: n,
|
|
118
|
-
label: `values (block_type "${u}")`
|
|
119
|
-
});
|
|
120
|
-
}
|
|
57
|
+
async function v(e, t, n) {
|
|
58
|
+
if (t === "site_settings") {
|
|
59
|
+
for (let t of e.rows ?? []) typeof t.key == "string" && g(t.key, t.value);
|
|
60
|
+
if (e.operation === "update" && e.values) {
|
|
61
|
+
let t = typeof e.values.key == "string" ? e.values.key : null, n = (e.filters ?? []).find((e) => e.column === "key" && e.operator === "eq" && typeof e.value == "string"), r = t ?? (n ? String(n.value) : null);
|
|
62
|
+
r && ("value" in e.values ? g(r, e.values.value) : m.has(r) && g(r, void 0));
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (t !== "blocks") return;
|
|
67
|
+
let i = null, a = () => i ??= r(D(n));
|
|
68
|
+
if (e.operation === "insert" || e.operation === "upsert") {
|
|
69
|
+
for (let [t, r] of (e.rows ?? []).entries()) await _({
|
|
70
|
+
blockType: r.block_type,
|
|
71
|
+
content: r.content ?? {},
|
|
72
|
+
context: n,
|
|
73
|
+
definitions: a,
|
|
74
|
+
label: `rows[${t}]`
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (e.operation === "update" && e.values) {
|
|
79
|
+
let r = "content" in e.values, i = "block_type" in e.values;
|
|
80
|
+
if (!r && !i) return;
|
|
81
|
+
if (i && !r) throw Error("Changing block_type requires the new content for that type in the same update.");
|
|
82
|
+
let o = /* @__PURE__ */ new Set();
|
|
83
|
+
if (i) o.add(String(e.values.block_type));
|
|
84
|
+
else {
|
|
85
|
+
let r = D(n).from("blocks").select("id, block_type").limit(101);
|
|
86
|
+
r = W(t, r, e.filters ?? []);
|
|
87
|
+
let { data: i, error: a } = await r;
|
|
88
|
+
if (a) throw Error(`Failed to read the blocks to update: ${O(a)}`);
|
|
89
|
+
for (let e of Array.isArray(i) ? i : []) o.add(String(e.block_type ?? ""));
|
|
90
|
+
}
|
|
91
|
+
for (let t of o) await _({
|
|
92
|
+
blockType: t,
|
|
93
|
+
content: e.values.content,
|
|
94
|
+
context: n,
|
|
95
|
+
definitions: a,
|
|
96
|
+
label: `values (block_type "${t}")`
|
|
97
|
+
});
|
|
98
|
+
}
|
|
121
99
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
100
|
+
var y = {
|
|
101
|
+
blocks: {
|
|
102
|
+
columns: [
|
|
103
|
+
"id",
|
|
104
|
+
"page_id",
|
|
105
|
+
"post_id",
|
|
106
|
+
"language_id",
|
|
107
|
+
"block_type",
|
|
108
|
+
"content",
|
|
109
|
+
"order",
|
|
110
|
+
"created_at",
|
|
111
|
+
"updated_at"
|
|
112
|
+
],
|
|
113
|
+
description: "CMS page/post content blocks.",
|
|
114
|
+
primaryKey: ["id"]
|
|
115
|
+
},
|
|
116
|
+
coupon_freemius_mappings: {
|
|
117
|
+
columns: [
|
|
118
|
+
"id",
|
|
119
|
+
"coupon_id",
|
|
120
|
+
"product_id",
|
|
121
|
+
"freemius_product_id",
|
|
122
|
+
"freemius_coupon_id",
|
|
123
|
+
"freemius_coupon_code",
|
|
124
|
+
"sync_status",
|
|
125
|
+
"sync_error",
|
|
126
|
+
"remote_payload",
|
|
127
|
+
"last_synced_at",
|
|
128
|
+
"created_at",
|
|
129
|
+
"updated_at"
|
|
130
|
+
],
|
|
131
|
+
description: "Freemius coupon sync mappings.",
|
|
132
|
+
primaryKey: ["id"]
|
|
133
|
+
},
|
|
134
|
+
coupon_products: {
|
|
135
|
+
columns: [
|
|
136
|
+
"coupon_id",
|
|
137
|
+
"product_id",
|
|
138
|
+
"created_at"
|
|
139
|
+
],
|
|
140
|
+
description: "Coupon product allow-list rows.",
|
|
141
|
+
primaryKey: ["coupon_id", "product_id"]
|
|
142
|
+
},
|
|
143
|
+
coupon_redemptions: {
|
|
144
|
+
columns: [
|
|
145
|
+
"id",
|
|
146
|
+
"coupon_id",
|
|
147
|
+
"order_id",
|
|
148
|
+
"coupon_code",
|
|
149
|
+
"provider",
|
|
150
|
+
"discount_total",
|
|
151
|
+
"user_id",
|
|
152
|
+
"customer_email",
|
|
153
|
+
"metadata",
|
|
154
|
+
"redeemed_at"
|
|
155
|
+
],
|
|
156
|
+
description: "Coupon redemption records.",
|
|
157
|
+
primaryKey: ["id"]
|
|
158
|
+
},
|
|
159
|
+
coupons: {
|
|
160
|
+
columns: [
|
|
161
|
+
"id",
|
|
162
|
+
"code",
|
|
163
|
+
"name",
|
|
164
|
+
"internal_note",
|
|
165
|
+
"provider_scope",
|
|
166
|
+
"discount_type",
|
|
167
|
+
"discount_amount",
|
|
168
|
+
"is_active",
|
|
169
|
+
"starts_at",
|
|
170
|
+
"ends_at",
|
|
171
|
+
"redemption_limit",
|
|
172
|
+
"redemptions_count",
|
|
173
|
+
"freemius_sync_status",
|
|
174
|
+
"freemius_sync_error",
|
|
175
|
+
"created_at",
|
|
176
|
+
"updated_at"
|
|
177
|
+
],
|
|
178
|
+
description: "Commerce coupons.",
|
|
179
|
+
primaryKey: ["id"]
|
|
180
|
+
},
|
|
181
|
+
cortex_ai_db_mutation_audit: {
|
|
182
|
+
columns: [
|
|
183
|
+
"id",
|
|
184
|
+
"actor_user_id",
|
|
185
|
+
"tool_name",
|
|
186
|
+
"action_name",
|
|
187
|
+
"target_tables",
|
|
188
|
+
"operation_summary",
|
|
189
|
+
"payload_hash",
|
|
190
|
+
"payload",
|
|
191
|
+
"preview",
|
|
192
|
+
"status",
|
|
193
|
+
"error_message",
|
|
194
|
+
"created_at"
|
|
195
|
+
],
|
|
196
|
+
description: "Read-only Cortex AI database mutation audit trail.",
|
|
197
|
+
primaryKey: ["id"],
|
|
198
|
+
readOnly: !0
|
|
199
|
+
},
|
|
200
|
+
currencies: {
|
|
201
|
+
columns: [
|
|
202
|
+
"id",
|
|
203
|
+
"code",
|
|
204
|
+
"symbol",
|
|
205
|
+
"exchange_rate",
|
|
206
|
+
"is_default",
|
|
207
|
+
"is_active",
|
|
208
|
+
"rounding_mode",
|
|
209
|
+
"rounding_increment",
|
|
210
|
+
"rounding_charm_amount",
|
|
211
|
+
"auto_update_exchange_rate",
|
|
212
|
+
"exchange_rate_updated_at",
|
|
213
|
+
"exchange_rate_source",
|
|
214
|
+
"auto_sync_product_prices",
|
|
215
|
+
"created_at",
|
|
216
|
+
"updated_at"
|
|
217
|
+
],
|
|
218
|
+
description: "Storefront currencies and FX settings.",
|
|
219
|
+
primaryKey: ["id"]
|
|
220
|
+
},
|
|
221
|
+
freemius_plans: {
|
|
222
|
+
columns: [
|
|
223
|
+
"id",
|
|
224
|
+
"product_id",
|
|
225
|
+
"name",
|
|
226
|
+
"title",
|
|
227
|
+
"created_at",
|
|
228
|
+
"updated_at"
|
|
229
|
+
],
|
|
230
|
+
description: "Freemius plan metadata.",
|
|
231
|
+
primaryKey: ["id"]
|
|
232
|
+
},
|
|
233
|
+
freemius_pricing: {
|
|
234
|
+
columns: [
|
|
235
|
+
"id",
|
|
236
|
+
"plan_id",
|
|
237
|
+
"api_monthly_price",
|
|
238
|
+
"api_annual_price",
|
|
239
|
+
"api_lifetime_price",
|
|
240
|
+
"override_monthly_price",
|
|
241
|
+
"override_annual_price",
|
|
242
|
+
"override_lifetime_price",
|
|
243
|
+
"license_quota",
|
|
244
|
+
"is_active",
|
|
245
|
+
"created_at",
|
|
246
|
+
"updated_at"
|
|
247
|
+
],
|
|
248
|
+
description: "Freemius pricing metadata.",
|
|
249
|
+
primaryKey: ["id"]
|
|
250
|
+
},
|
|
251
|
+
inventory_items: {
|
|
252
|
+
columns: [
|
|
253
|
+
"sku",
|
|
254
|
+
"quantity",
|
|
255
|
+
"created_at",
|
|
256
|
+
"updated_at"
|
|
257
|
+
],
|
|
258
|
+
description: "Source-of-truth inventory by SKU.",
|
|
259
|
+
primaryKey: ["sku"]
|
|
260
|
+
},
|
|
261
|
+
languages: {
|
|
262
|
+
columns: [
|
|
263
|
+
"id",
|
|
264
|
+
"code",
|
|
265
|
+
"name",
|
|
266
|
+
"is_default",
|
|
267
|
+
"is_active",
|
|
268
|
+
"created_at",
|
|
269
|
+
"updated_at"
|
|
270
|
+
],
|
|
271
|
+
description: "CMS languages/locales.",
|
|
272
|
+
primaryKey: ["id"]
|
|
273
|
+
},
|
|
274
|
+
logos: {
|
|
275
|
+
columns: [
|
|
276
|
+
"id",
|
|
277
|
+
"name",
|
|
278
|
+
"media_id",
|
|
279
|
+
"created_at"
|
|
280
|
+
],
|
|
281
|
+
description: "Brand logos.",
|
|
282
|
+
primaryKey: ["id"]
|
|
283
|
+
},
|
|
284
|
+
media: {
|
|
285
|
+
columns: [
|
|
286
|
+
"id",
|
|
287
|
+
"uploader_id",
|
|
288
|
+
"file_name",
|
|
289
|
+
"object_key",
|
|
290
|
+
"file_type",
|
|
291
|
+
"size_bytes",
|
|
292
|
+
"description",
|
|
293
|
+
"width",
|
|
294
|
+
"height",
|
|
295
|
+
"blur_data_url",
|
|
296
|
+
"variants",
|
|
297
|
+
"file_path",
|
|
298
|
+
"folder",
|
|
299
|
+
"created_at",
|
|
300
|
+
"updated_at"
|
|
301
|
+
],
|
|
302
|
+
description: "Media metadata for uploaded assets.",
|
|
303
|
+
primaryKey: ["id"]
|
|
304
|
+
},
|
|
305
|
+
navigation_items: {
|
|
306
|
+
columns: [
|
|
307
|
+
"id",
|
|
308
|
+
"language_id",
|
|
309
|
+
"menu_key",
|
|
310
|
+
"label",
|
|
311
|
+
"url",
|
|
312
|
+
"parent_id",
|
|
313
|
+
"order",
|
|
314
|
+
"page_id",
|
|
315
|
+
"translation_group_id",
|
|
316
|
+
"created_at",
|
|
317
|
+
"updated_at"
|
|
318
|
+
],
|
|
319
|
+
description: "CMS navigation tree items.",
|
|
320
|
+
primaryKey: ["id"]
|
|
321
|
+
},
|
|
322
|
+
order_items: {
|
|
323
|
+
columns: [
|
|
324
|
+
"id",
|
|
325
|
+
"order_id",
|
|
326
|
+
"product_id",
|
|
327
|
+
"variant_id",
|
|
328
|
+
"quantity",
|
|
329
|
+
"price_at_purchase"
|
|
330
|
+
],
|
|
331
|
+
description: "Commerce order line items.",
|
|
332
|
+
primaryKey: ["id"]
|
|
333
|
+
},
|
|
334
|
+
orders: {
|
|
335
|
+
columns: /* @__PURE__ */ "id.user_id.status.total.stripe_session_id.payment_intent_id.customer_details.provider.freemius_product_id.freemius_plan_id.freemius_license_id.freemius_subscription_id.freemius_trial_id.freemius_user_id.freemius_trial_ends_at.freemius_last_event_type.freemius_last_synced_at.currency.subtotal.shipping_total.tax_total.tax_details.exchange_rate_at_purchase.inventory_deducted_at.invoice_number.paid_at.created_at.coupon_id.coupon_code.discount_total.discount_details".split("."),
|
|
336
|
+
description: "Commerce orders.",
|
|
337
|
+
primaryKey: ["id"]
|
|
338
|
+
},
|
|
339
|
+
package_activations: {
|
|
340
|
+
columns: [
|
|
341
|
+
"id",
|
|
342
|
+
"license_key",
|
|
343
|
+
"instance_name",
|
|
344
|
+
"package_id",
|
|
345
|
+
"status",
|
|
346
|
+
"meta",
|
|
347
|
+
"last_validated_at",
|
|
348
|
+
"created_at"
|
|
349
|
+
],
|
|
350
|
+
description: "NextBlock package activations.",
|
|
351
|
+
primaryKey: ["id"]
|
|
352
|
+
},
|
|
353
|
+
page_revisions: {
|
|
354
|
+
columns: [
|
|
355
|
+
"id",
|
|
356
|
+
"page_id",
|
|
357
|
+
"author_id",
|
|
358
|
+
"version",
|
|
359
|
+
"revision_type",
|
|
360
|
+
"content",
|
|
361
|
+
"created_at"
|
|
362
|
+
],
|
|
363
|
+
description: "Page revision history.",
|
|
364
|
+
primaryKey: ["id"],
|
|
365
|
+
readOnly: !0
|
|
366
|
+
},
|
|
367
|
+
pages: {
|
|
368
|
+
columns: [
|
|
369
|
+
"id",
|
|
370
|
+
"language_id",
|
|
371
|
+
"author_id",
|
|
372
|
+
"title",
|
|
373
|
+
"slug",
|
|
374
|
+
"status",
|
|
375
|
+
"meta_title",
|
|
376
|
+
"meta_description",
|
|
377
|
+
"feature_image_id",
|
|
378
|
+
"version",
|
|
379
|
+
"translation_group_id",
|
|
380
|
+
"created_at",
|
|
381
|
+
"updated_at"
|
|
382
|
+
],
|
|
383
|
+
description: "CMS pages.",
|
|
384
|
+
primaryKey: ["id"]
|
|
385
|
+
},
|
|
386
|
+
post_revisions: {
|
|
387
|
+
columns: [
|
|
388
|
+
"id",
|
|
389
|
+
"post_id",
|
|
390
|
+
"author_id",
|
|
391
|
+
"version",
|
|
392
|
+
"revision_type",
|
|
393
|
+
"content",
|
|
394
|
+
"created_at"
|
|
395
|
+
],
|
|
396
|
+
description: "Post revision history.",
|
|
397
|
+
primaryKey: ["id"],
|
|
398
|
+
readOnly: !0
|
|
399
|
+
},
|
|
400
|
+
product_revisions: {
|
|
401
|
+
columns: [
|
|
402
|
+
"id",
|
|
403
|
+
"product_id",
|
|
404
|
+
"author_id",
|
|
405
|
+
"version",
|
|
406
|
+
"revision_type",
|
|
407
|
+
"content",
|
|
408
|
+
"created_at"
|
|
409
|
+
],
|
|
410
|
+
description: "Product revision history.",
|
|
411
|
+
primaryKey: ["id"],
|
|
412
|
+
readOnly: !0
|
|
413
|
+
},
|
|
414
|
+
posts: {
|
|
415
|
+
columns: [
|
|
416
|
+
"id",
|
|
417
|
+
"language_id",
|
|
418
|
+
"author_id",
|
|
419
|
+
"title",
|
|
420
|
+
"slug",
|
|
421
|
+
"label",
|
|
422
|
+
"excerpt",
|
|
423
|
+
"subtitle",
|
|
424
|
+
"status",
|
|
425
|
+
"published_at",
|
|
426
|
+
"meta_title",
|
|
427
|
+
"meta_description",
|
|
428
|
+
"feature_image_id",
|
|
429
|
+
"version",
|
|
430
|
+
"translation_group_id",
|
|
431
|
+
"created_at",
|
|
432
|
+
"updated_at"
|
|
433
|
+
],
|
|
434
|
+
description: "CMS posts/articles.",
|
|
435
|
+
primaryKey: ["id"]
|
|
436
|
+
},
|
|
437
|
+
product_attribute_terms: {
|
|
438
|
+
columns: [
|
|
439
|
+
"id",
|
|
440
|
+
"attribute_id",
|
|
441
|
+
"value",
|
|
442
|
+
"slug",
|
|
443
|
+
"sort_order",
|
|
444
|
+
"value_translations",
|
|
445
|
+
"created_at",
|
|
446
|
+
"updated_at"
|
|
447
|
+
],
|
|
448
|
+
description: "Product attribute terms.",
|
|
449
|
+
primaryKey: ["id"]
|
|
450
|
+
},
|
|
451
|
+
product_attributes: {
|
|
452
|
+
columns: [
|
|
453
|
+
"id",
|
|
454
|
+
"name",
|
|
455
|
+
"slug",
|
|
456
|
+
"name_translations",
|
|
457
|
+
"created_at",
|
|
458
|
+
"updated_at"
|
|
459
|
+
],
|
|
460
|
+
description: "Product attribute definitions.",
|
|
461
|
+
primaryKey: ["id"]
|
|
462
|
+
},
|
|
463
|
+
product_media: {
|
|
464
|
+
columns: [
|
|
465
|
+
"product_id",
|
|
466
|
+
"media_id",
|
|
467
|
+
"sort_order"
|
|
468
|
+
],
|
|
469
|
+
description: "Product media join rows.",
|
|
470
|
+
primaryKey: ["product_id", "media_id"]
|
|
471
|
+
},
|
|
472
|
+
product_variants: {
|
|
473
|
+
columns: [
|
|
474
|
+
"id",
|
|
475
|
+
"product_id",
|
|
476
|
+
"sku",
|
|
477
|
+
"price_adjustment",
|
|
478
|
+
"price",
|
|
479
|
+
"prices",
|
|
480
|
+
"sale_price",
|
|
481
|
+
"sale_prices",
|
|
482
|
+
"stock_quantity",
|
|
483
|
+
"upc",
|
|
484
|
+
"main_media_id",
|
|
485
|
+
"created_at",
|
|
486
|
+
"updated_at"
|
|
487
|
+
],
|
|
488
|
+
description: "Sellable product variants.",
|
|
489
|
+
primaryKey: ["id"]
|
|
490
|
+
},
|
|
491
|
+
products: {
|
|
492
|
+
columns: /* @__PURE__ */ "id.language_id.translation_group_id.sku.title.slug.product_type.payment_provider.price.prices.sale_price.sale_prices.stock.status.meta_title.meta_description.short_description.description_json.metadata.freemius_plan_id.freemius_product_id.trial_period_days.trial_requires_payment_method.upc.is_taxable.created_at.updated_at".split("."),
|
|
493
|
+
description: "Product catalog records.",
|
|
494
|
+
primaryKey: ["id"]
|
|
495
|
+
},
|
|
496
|
+
profiles: {
|
|
497
|
+
columns: [
|
|
498
|
+
"id",
|
|
499
|
+
"updated_at",
|
|
500
|
+
"full_name",
|
|
501
|
+
"avatar_url",
|
|
502
|
+
"website",
|
|
503
|
+
"phone",
|
|
504
|
+
"role"
|
|
505
|
+
],
|
|
506
|
+
description: "Read-only user profiles. Never mutate through Cortex AI.",
|
|
507
|
+
primaryKey: ["id"],
|
|
508
|
+
readOnly: !0
|
|
509
|
+
},
|
|
510
|
+
shipping_zone_locations: {
|
|
511
|
+
columns: [
|
|
512
|
+
"id",
|
|
513
|
+
"zone_id",
|
|
514
|
+
"country_code",
|
|
515
|
+
"state_code",
|
|
516
|
+
"postal_code",
|
|
517
|
+
"created_at"
|
|
518
|
+
],
|
|
519
|
+
description: "Shipping zone location match rules.",
|
|
520
|
+
primaryKey: ["id"]
|
|
521
|
+
},
|
|
522
|
+
shipping_zone_methods: {
|
|
523
|
+
columns: [
|
|
524
|
+
"id",
|
|
525
|
+
"zone_id",
|
|
526
|
+
"method_type",
|
|
527
|
+
"cost_amount",
|
|
528
|
+
"cost_currency",
|
|
529
|
+
"min_order_amount",
|
|
530
|
+
"name",
|
|
531
|
+
"name_translations",
|
|
532
|
+
"currency_pricing_mode",
|
|
533
|
+
"cost_amounts",
|
|
534
|
+
"min_order_amounts",
|
|
535
|
+
"created_at",
|
|
536
|
+
"updated_at"
|
|
537
|
+
],
|
|
538
|
+
description: "Shipping methods/rates.",
|
|
539
|
+
primaryKey: ["id"]
|
|
540
|
+
},
|
|
541
|
+
shipping_zones: {
|
|
542
|
+
columns: [
|
|
543
|
+
"id",
|
|
544
|
+
"name",
|
|
545
|
+
"priority_order",
|
|
546
|
+
"created_at",
|
|
547
|
+
"updated_at"
|
|
548
|
+
],
|
|
549
|
+
description: "Shipping zones.",
|
|
550
|
+
primaryKey: ["id"]
|
|
551
|
+
},
|
|
552
|
+
site_settings: {
|
|
553
|
+
columns: ["key", "value"],
|
|
554
|
+
description: "Global site settings. Cortex AI API-key setting row is protected.",
|
|
555
|
+
primaryKey: ["key"]
|
|
556
|
+
},
|
|
557
|
+
tax_rates: {
|
|
558
|
+
columns: [
|
|
559
|
+
"id",
|
|
560
|
+
"country_code",
|
|
561
|
+
"state_code",
|
|
562
|
+
"tax_name",
|
|
563
|
+
"tax_rate",
|
|
564
|
+
"created_at",
|
|
565
|
+
"updated_at"
|
|
566
|
+
],
|
|
567
|
+
description: "Manual tax rates.",
|
|
568
|
+
primaryKey: ["id"]
|
|
569
|
+
},
|
|
570
|
+
translations: {
|
|
571
|
+
columns: [
|
|
572
|
+
"key",
|
|
573
|
+
"translations",
|
|
574
|
+
"created_at",
|
|
575
|
+
"updated_at"
|
|
576
|
+
],
|
|
577
|
+
description: "Shared translation strings.",
|
|
578
|
+
primaryKey: ["key"]
|
|
579
|
+
},
|
|
580
|
+
user_addresses: {
|
|
581
|
+
columns: [
|
|
582
|
+
"id",
|
|
583
|
+
"user_id",
|
|
584
|
+
"address_type",
|
|
585
|
+
"is_default",
|
|
586
|
+
"recipient_name",
|
|
587
|
+
"company_name",
|
|
588
|
+
"line1",
|
|
589
|
+
"line2",
|
|
590
|
+
"city",
|
|
591
|
+
"state",
|
|
592
|
+
"postal_code",
|
|
593
|
+
"country_code",
|
|
594
|
+
"created_at",
|
|
595
|
+
"updated_at"
|
|
596
|
+
],
|
|
597
|
+
description: "Read-only user addresses. Never mutate through Cortex AI.",
|
|
598
|
+
primaryKey: ["id"],
|
|
599
|
+
readOnly: !0
|
|
600
|
+
},
|
|
601
|
+
variant_attribute_mapping: {
|
|
602
|
+
columns: ["variant_id", "attribute_term_id"],
|
|
603
|
+
description: "Variant to attribute-term join rows.",
|
|
604
|
+
primaryKey: ["variant_id", "attribute_term_id"]
|
|
605
|
+
}
|
|
606
|
+
}, b = e.enum([
|
|
607
|
+
"eq",
|
|
608
|
+
"neq",
|
|
609
|
+
"gt",
|
|
610
|
+
"gte",
|
|
611
|
+
"lt",
|
|
612
|
+
"lte",
|
|
613
|
+
"ilike",
|
|
614
|
+
"in",
|
|
615
|
+
"is"
|
|
616
|
+
]), x = e.strictObject({
|
|
617
|
+
column: e.string().trim().min(1).max(120),
|
|
618
|
+
operator: b.default("eq"),
|
|
619
|
+
value: e.unknown()
|
|
620
|
+
}), S = e.strictObject({
|
|
621
|
+
ascending: e.boolean().default(!0),
|
|
622
|
+
column: e.string().trim().min(1).max(120)
|
|
623
|
+
}), C = e.strictObject({
|
|
624
|
+
includeReadOnly: e.boolean().default(!0),
|
|
625
|
+
table: e.string().trim().min(1).max(120).optional()
|
|
626
|
+
}), w = e.strictObject({
|
|
627
|
+
columns: e.array(e.string().trim().min(1).max(120)).min(1).max(40).optional(),
|
|
628
|
+
filters: e.array(x).max(12).default([]),
|
|
629
|
+
limit: e.number().int().min(1).max(s).default(c),
|
|
630
|
+
offset: e.number().int().min(0).max(1e4).default(0),
|
|
631
|
+
orderBy: S.optional(),
|
|
632
|
+
table: e.string().trim().min(1).max(120)
|
|
633
|
+
}), T = e.strictObject({
|
|
634
|
+
filters: e.array(x).max(12).optional(),
|
|
635
|
+
operation: e.enum([
|
|
636
|
+
"delete",
|
|
637
|
+
"insert",
|
|
638
|
+
"update",
|
|
639
|
+
"upsert"
|
|
640
|
+
]),
|
|
641
|
+
rows: e.array(e.record(e.string(), e.unknown())).min(1).max(u).optional(),
|
|
642
|
+
summary: e.string().trim().min(1).max(500).optional(),
|
|
643
|
+
table: e.string().trim().min(1).max(120),
|
|
644
|
+
values: e.record(e.string(), e.unknown()).optional()
|
|
645
|
+
}), E = e.strictObject({
|
|
646
|
+
actions: e.array(T).min(1).max(8),
|
|
647
|
+
summary: e.string().trim().min(1).max(500).optional()
|
|
587
648
|
});
|
|
588
|
-
function
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
return e.supabase;
|
|
649
|
+
function D(e) {
|
|
650
|
+
if (!e?.supabase) throw Error("Cortex AI database tools require a Supabase client.");
|
|
651
|
+
return e.supabase;
|
|
592
652
|
}
|
|
593
|
-
function
|
|
594
|
-
|
|
653
|
+
function O(e) {
|
|
654
|
+
return e ? typeof e == "object" && "message" in e ? String(e.message || "Unknown database error.") : String(e) : "Unknown database error.";
|
|
595
655
|
}
|
|
596
|
-
function
|
|
597
|
-
|
|
656
|
+
function k(e) {
|
|
657
|
+
return typeof e != "object" || !e ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((e) => k(e)).join(",")}]` : `{${Object.keys(e).sort().map((t) => `${JSON.stringify(t)}:${k(e[t])}`).join(",")}}`;
|
|
598
658
|
}
|
|
599
|
-
function
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
t ^= r.charCodeAt(a), t = Math.imul(t, 16777619);
|
|
604
|
-
return (t >>> 0).toString(16).padStart(8, "0");
|
|
659
|
+
function A(e) {
|
|
660
|
+
let t = 2166136261, n = k(e);
|
|
661
|
+
for (let e = 0; e < n.length; e++) t ^= n.charCodeAt(e), t = Math.imul(t, 16777619);
|
|
662
|
+
return (t >>> 0).toString(16).padStart(8, "0");
|
|
605
663
|
}
|
|
606
|
-
function
|
|
607
|
-
|
|
664
|
+
function j(e) {
|
|
665
|
+
return e.replace(/\s+/g, " ").trim().toUpperCase();
|
|
608
666
|
}
|
|
609
|
-
function
|
|
610
|
-
|
|
667
|
+
function te(e, t, n) {
|
|
668
|
+
return `${j(`CONFIRM ${e} ${t}`)} #${A(n)}`;
|
|
611
669
|
}
|
|
612
|
-
function
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
670
|
+
function M(e) {
|
|
671
|
+
return {
|
|
672
|
+
confirmationPhrase: te(e.action, e.subject, e.payload),
|
|
673
|
+
mutationExecuted: !1,
|
|
674
|
+
preview: e.preview,
|
|
675
|
+
requiresConfirmation: !0,
|
|
676
|
+
success: !0
|
|
677
|
+
};
|
|
620
678
|
}
|
|
621
|
-
function
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
} : r.includes(a) ? null : t;
|
|
679
|
+
function N(e) {
|
|
680
|
+
if (e.context?.skipConfirmation) return null;
|
|
681
|
+
let t = M(e), n = j(e.context?.latestUserMessage || ""), r = j(t.confirmationPhrase);
|
|
682
|
+
return n && !n.includes(r) ? {
|
|
683
|
+
...t,
|
|
684
|
+
message: "The database target changed or the confirmation did not match. Please review and confirm again."
|
|
685
|
+
} : n.includes(r) ? null : t;
|
|
629
686
|
}
|
|
630
|
-
function
|
|
631
|
-
|
|
687
|
+
function P(e) {
|
|
688
|
+
return Object.prototype.hasOwnProperty.call(y, e);
|
|
632
689
|
}
|
|
633
|
-
function
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
throw new Error(`Table "${t}" is not available to Cortex AI database tools.`);
|
|
639
|
-
return t;
|
|
690
|
+
function F(e) {
|
|
691
|
+
let t = e.trim();
|
|
692
|
+
if (t.includes(".") || t.toLowerCase().startsWith("auth")) throw Error("Cortex AI cannot access auth schema tables.");
|
|
693
|
+
if (!P(t)) throw Error(`Table "${t}" is not available to Cortex AI database tools.`);
|
|
694
|
+
return t;
|
|
640
695
|
}
|
|
641
|
-
function
|
|
642
|
-
|
|
696
|
+
function I(e) {
|
|
697
|
+
return y[e];
|
|
643
698
|
}
|
|
644
|
-
function
|
|
645
|
-
|
|
699
|
+
function L(e) {
|
|
700
|
+
return /(?:password|token|secret|api[_-]?key|private[_-]?key|credential)/i.test(e);
|
|
646
701
|
}
|
|
647
|
-
function
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
if (v(t))
|
|
651
|
-
throw new Error(`Column "${t}" is protected and cannot be used through Cortex AI.`);
|
|
702
|
+
function R(e, t) {
|
|
703
|
+
if (!I(e).columns.includes(t)) throw Error(`Column "${t}" is not available on table "${e}".`);
|
|
704
|
+
if (L(t)) throw Error(`Column "${t}" is protected and cannot be used through Cortex AI.`);
|
|
652
705
|
}
|
|
653
|
-
function
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
I(a, `${t}.${r}`);
|
|
663
|
-
}
|
|
706
|
+
function z(e, t = "payload") {
|
|
707
|
+
if (Array.isArray(e)) {
|
|
708
|
+
e.forEach((e, n) => z(e, `${t}[${n}]`));
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
if (e && typeof e == "object") for (let [n, r] of Object.entries(e)) {
|
|
712
|
+
if (L(n)) throw Error(`Protected field "${t}.${n}" cannot be written through Cortex AI.`);
|
|
713
|
+
z(r, `${t}.${n}`);
|
|
714
|
+
}
|
|
664
715
|
}
|
|
665
|
-
function
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
for (const [r, a] of Object.entries(e))
|
|
672
|
-
t[r] = v(r) ? D : h(a);
|
|
673
|
-
return t;
|
|
716
|
+
function B(e) {
|
|
717
|
+
if (Array.isArray(e)) return e.map((e) => B(e));
|
|
718
|
+
if (!e || typeof e != "object") return e;
|
|
719
|
+
let t = {};
|
|
720
|
+
for (let [n, r] of Object.entries(e)) t[n] = L(n) ? d : B(r);
|
|
721
|
+
return t;
|
|
674
722
|
}
|
|
675
|
-
function
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
723
|
+
function V(e) {
|
|
724
|
+
return e.map((e) => {
|
|
725
|
+
if (e && typeof e == "object" && !Array.isArray(e)) {
|
|
726
|
+
let t = e.key;
|
|
727
|
+
if (typeof t == "string" && p.has(t)) return {
|
|
728
|
+
key: t,
|
|
729
|
+
value: d
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
return B(e);
|
|
733
|
+
});
|
|
684
734
|
}
|
|
685
|
-
function
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
for (const a of K)
|
|
690
|
-
if (r.includes(a))
|
|
691
|
-
throw new Error(`The "${a}" site setting is protected.`);
|
|
735
|
+
function H(e, t) {
|
|
736
|
+
if (e !== "site_settings") return;
|
|
737
|
+
let n = JSON.stringify(t).toLowerCase();
|
|
738
|
+
for (let e of p) if (n.includes(e)) throw Error(`The "${e}" site setting is protected.`);
|
|
692
739
|
}
|
|
693
|
-
function
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
throw new Error(`Filter "${t.column}" with ilike requires a string value.`);
|
|
710
|
-
return e.ilike(t.column, t.value);
|
|
711
|
-
case "in":
|
|
712
|
-
if (!Array.isArray(t.value))
|
|
713
|
-
throw new Error(`Filter "${t.column}" with in requires an array value.`);
|
|
714
|
-
return e.in(t.column, t.value);
|
|
715
|
-
case "is":
|
|
716
|
-
return e.is(t.column, t.value);
|
|
717
|
-
}
|
|
740
|
+
function U(e, t) {
|
|
741
|
+
switch (t.operator) {
|
|
742
|
+
case "eq": return e.eq(t.column, t.value);
|
|
743
|
+
case "neq": return e.neq(t.column, t.value);
|
|
744
|
+
case "gt": return e.gt(t.column, t.value);
|
|
745
|
+
case "gte": return e.gte(t.column, t.value);
|
|
746
|
+
case "lt": return e.lt(t.column, t.value);
|
|
747
|
+
case "lte": return e.lte(t.column, t.value);
|
|
748
|
+
case "ilike":
|
|
749
|
+
if (typeof t.value != "string") throw Error(`Filter "${t.column}" with ilike requires a string value.`);
|
|
750
|
+
return e.ilike(t.column, t.value);
|
|
751
|
+
case "in":
|
|
752
|
+
if (!Array.isArray(t.value)) throw Error(`Filter "${t.column}" with in requires an array value.`);
|
|
753
|
+
return e.in(t.column, t.value);
|
|
754
|
+
case "is": return e.is(t.column, t.value);
|
|
755
|
+
}
|
|
718
756
|
}
|
|
719
|
-
function
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
return e === "site_settings" && (a = a.neq("key", N)), a;
|
|
757
|
+
function W(e, t, n) {
|
|
758
|
+
let r = t;
|
|
759
|
+
for (let t of n) R(e, t.column), r = U(r, t);
|
|
760
|
+
return e === "site_settings" && (r = r.neq("key", f)), r;
|
|
724
761
|
}
|
|
725
|
-
function
|
|
726
|
-
|
|
727
|
-
|
|
762
|
+
function ne(e, t) {
|
|
763
|
+
let n = I(e), r = t?.length ? t : n.columns.filter((e) => !L(e));
|
|
764
|
+
return r.forEach((t) => R(e, t)), r.join(",");
|
|
728
765
|
}
|
|
729
766
|
function G(e, t) {
|
|
730
|
-
|
|
767
|
+
return t.map((t) => `${t}=${String(e[t] ?? "")}`).join("|");
|
|
731
768
|
}
|
|
732
|
-
async function
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
if (c.length > x)
|
|
741
|
-
throw new Error(`Refusing to mutate more than ${x} rows.`);
|
|
742
|
-
return c;
|
|
769
|
+
async function K(e, t, n) {
|
|
770
|
+
let r = I(t), i = e.from(t).select(r.primaryKey.join(",")).limit(101);
|
|
771
|
+
i = W(t, i, n);
|
|
772
|
+
let { data: a, error: o } = await i;
|
|
773
|
+
if (o) throw Error(`Failed to preview database mutation: ${O(o)}`);
|
|
774
|
+
let s = Array.isArray(a) ? a : [];
|
|
775
|
+
if (s.length > l) throw Error(`Refusing to mutate more than ${l} rows.`);
|
|
776
|
+
return s;
|
|
743
777
|
}
|
|
744
|
-
function
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
I(i);
|
|
759
|
-
for (const s of Object.keys(i))
|
|
760
|
-
b(t, s);
|
|
761
|
-
}
|
|
762
|
-
for (const i of e.filters ?? [])
|
|
763
|
-
b(t, i.column);
|
|
764
|
-
return t;
|
|
778
|
+
function q(e) {
|
|
779
|
+
let t = F(e.table), n = I(t), r = e.operation;
|
|
780
|
+
if (n.readOnly) throw Error(`Table "${t}" is read-only for Cortex AI.`);
|
|
781
|
+
if (H(t, e), (r === "update" || r === "delete") && (!e.filters || e.filters.length === 0)) throw Error(`${r} operations require at least one filter.`);
|
|
782
|
+
if ((r === "insert" || r === "upsert") && (!e.rows || e.rows.length === 0)) throw Error(`${r} operations require rows.`);
|
|
783
|
+
if (r === "update" && (!e.values || Object.keys(e.values).length === 0)) throw Error("update operations require values.");
|
|
784
|
+
if (e.rows && e.rows.length > u) throw Error(`Refusing to mutate more than ${u} input rows.`);
|
|
785
|
+
let i = e.rows ?? (e.values ? [e.values] : []);
|
|
786
|
+
for (let e of i) {
|
|
787
|
+
z(e);
|
|
788
|
+
for (let n of Object.keys(e)) R(t, n);
|
|
789
|
+
}
|
|
790
|
+
for (let n of e.filters ?? []) R(t, n.column);
|
|
791
|
+
return t;
|
|
765
792
|
}
|
|
766
|
-
function
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
793
|
+
function J(e) {
|
|
794
|
+
let { input: t, table: n, targetRows: r } = e, i = I(n), a = r.map((e) => G(e, i.primaryKey)).sort(), o = t.rows?.length ?? 0, s = t.operation === "insert" || t.operation === "upsert" ? o : r.length, c = t.summary || `${t.operation} ${s} ${s === 1 ? "row" : "rows"} in ${n}.`;
|
|
795
|
+
return {
|
|
796
|
+
affectedCount: s,
|
|
797
|
+
operation: t.operation,
|
|
798
|
+
sampleTargetIds: a.slice(0, 10),
|
|
799
|
+
summary: c,
|
|
800
|
+
table: n,
|
|
801
|
+
targetIds: a
|
|
802
|
+
};
|
|
776
803
|
}
|
|
777
|
-
async function
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
804
|
+
async function Y(e) {
|
|
805
|
+
let t = e.context?.actorUserId;
|
|
806
|
+
if (!t) return {
|
|
807
|
+
auditError: "Missing actor user id.",
|
|
808
|
+
auditLogged: !1
|
|
809
|
+
};
|
|
810
|
+
try {
|
|
811
|
+
let { error: n } = await D(e.context).from("cortex_ai_db_mutation_audit").insert({
|
|
812
|
+
action_name: e.toolName,
|
|
813
|
+
actor_user_id: t,
|
|
814
|
+
error_message: e.errorMessage ?? null,
|
|
815
|
+
operation_summary: e.summary,
|
|
816
|
+
payload: B(e.input),
|
|
817
|
+
payload_hash: A(e.input),
|
|
818
|
+
preview: B(e.preview),
|
|
819
|
+
status: e.status,
|
|
820
|
+
target_tables: e.targetTables,
|
|
821
|
+
tool_name: e.toolName
|
|
822
|
+
});
|
|
823
|
+
return n ? {
|
|
824
|
+
auditError: O(n),
|
|
825
|
+
auditLogged: !1
|
|
826
|
+
} : { auditLogged: !0 };
|
|
827
|
+
} catch (e) {
|
|
828
|
+
return {
|
|
829
|
+
auditError: O(e),
|
|
830
|
+
auditLogged: !1
|
|
831
|
+
};
|
|
832
|
+
}
|
|
798
833
|
}
|
|
799
|
-
async function
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
throw new Error(f(c));
|
|
806
|
-
return Array.isArray(s) ? s : [];
|
|
834
|
+
async function re(e, t, n) {
|
|
835
|
+
let r = I(t).primaryKey.join(","), i;
|
|
836
|
+
e.operation === "insert" ? i = n.from(t).insert(e.rows).select(r) : e.operation === "upsert" ? i = n.from(t).upsert(e.rows).select(r) : e.operation === "update" ? (i = n.from(t).update(e.values), i = W(t, i, e.filters ?? []), i = i.select(r)) : (i = n.from(t).delete(), i = W(t, i, e.filters ?? []), i = i.select(r));
|
|
837
|
+
let { data: a, error: o } = await i;
|
|
838
|
+
if (o) throw Error(O(o));
|
|
839
|
+
return Array.isArray(a) ? a : [];
|
|
807
840
|
}
|
|
808
|
-
async function
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
841
|
+
async function X(e) {
|
|
842
|
+
let t = C.parse(e), n = (t.table ? [F(t.table)] : Object.keys(y)).filter((e) => t.includeReadOnly || !I(e).readOnly).map((e) => {
|
|
843
|
+
let t = I(e);
|
|
844
|
+
return {
|
|
845
|
+
columns: t.columns.filter((e) => !L(e)),
|
|
846
|
+
description: t.description,
|
|
847
|
+
primaryKey: t.primaryKey,
|
|
848
|
+
readOnly: !!t.readOnly,
|
|
849
|
+
table: e
|
|
850
|
+
};
|
|
851
|
+
});
|
|
852
|
+
return {
|
|
853
|
+
safetyNotes: [
|
|
854
|
+
"Use read_database_records for reads and execute_database_mutation/action_plan for writes.",
|
|
855
|
+
"No auth schema access, no arbitrary SQL, no password/secret/API-key fields.",
|
|
856
|
+
"profiles, user_addresses, and cortex_ai_db_mutation_audit are read-only.",
|
|
857
|
+
`Protected site_settings keys (never readable or writable): ${[...p].sort().join(", ")}.`,
|
|
858
|
+
`Write-protected site_settings keys (readable, never writable here): ${[...m].sort().join(", ")}.`,
|
|
859
|
+
"blocks.content is validated against its block_type (built-in schema or custom block definition) before any insert, upsert, or update; prefer the typed content tools, which also normalize and record revisions."
|
|
860
|
+
],
|
|
861
|
+
success: !0,
|
|
862
|
+
tables: n
|
|
863
|
+
};
|
|
831
864
|
}
|
|
832
|
-
async function
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
table: a
|
|
847
|
-
};
|
|
865
|
+
async function Z(e, t) {
|
|
866
|
+
let n = w.parse(e), r = F(n.table), i = ne(r, n.columns), a = D(t).from(r).select(i).range(n.offset, n.offset + n.limit - 1);
|
|
867
|
+
a = W(r, a, n.filters), n.orderBy && (R(r, n.orderBy.column), a = a.order(n.orderBy.column, { ascending: n.orderBy.ascending }));
|
|
868
|
+
let { data: o, error: s } = await a;
|
|
869
|
+
if (s) throw Error(`Failed to read database records: ${O(s)}`);
|
|
870
|
+
let c = Array.isArray(o) ? o : [];
|
|
871
|
+
return {
|
|
872
|
+
columns: i.split(","),
|
|
873
|
+
limit: n.limit,
|
|
874
|
+
offset: n.offset,
|
|
875
|
+
rows: V(c),
|
|
876
|
+
success: !0,
|
|
877
|
+
table: r
|
|
878
|
+
};
|
|
848
879
|
}
|
|
849
880
|
async function Q(e, t) {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
881
|
+
let n = T.parse(e), r = q(n), i = D(t);
|
|
882
|
+
await v(n, r, t);
|
|
883
|
+
let a = J({
|
|
884
|
+
input: n,
|
|
885
|
+
table: r,
|
|
886
|
+
targetRows: n.operation === "update" || n.operation === "delete" ? await K(i, r, n.filters ?? []) : []
|
|
887
|
+
}), o = {
|
|
888
|
+
input: n,
|
|
889
|
+
targetIds: a.targetIds
|
|
890
|
+
}, s = N({
|
|
891
|
+
action: `DATABASE ${n.operation}`,
|
|
892
|
+
context: t,
|
|
893
|
+
payload: o,
|
|
894
|
+
preview: a,
|
|
895
|
+
subject: r
|
|
896
|
+
});
|
|
897
|
+
if (s) return s;
|
|
898
|
+
try {
|
|
899
|
+
let e = await re(n, r, i), s = t?.skipAudit ? { auditLogged: !1 } : await Y({
|
|
900
|
+
context: t,
|
|
901
|
+
input: o,
|
|
902
|
+
preview: a,
|
|
903
|
+
status: "success",
|
|
904
|
+
summary: String(a.summary),
|
|
905
|
+
targetTables: [r],
|
|
906
|
+
toolName: "execute_database_mutation"
|
|
907
|
+
});
|
|
908
|
+
return {
|
|
909
|
+
affectedCount: e.length || a.affectedCount,
|
|
910
|
+
auditLogged: s.auditLogged,
|
|
911
|
+
...s.auditError ? { auditError: s.auditError } : {},
|
|
912
|
+
mutationExecuted: !0,
|
|
913
|
+
operation: n.operation,
|
|
914
|
+
sampleTargetIds: e.map((e) => G(e, I(r).primaryKey)).slice(0, 10),
|
|
915
|
+
success: !0,
|
|
916
|
+
summary: a.summary,
|
|
917
|
+
table: r
|
|
918
|
+
};
|
|
919
|
+
} catch (e) {
|
|
920
|
+
let i = O(e), s = t?.skipAudit ? { auditLogged: !1 } : await Y({
|
|
921
|
+
context: t,
|
|
922
|
+
errorMessage: i,
|
|
923
|
+
input: o,
|
|
924
|
+
preview: a,
|
|
925
|
+
status: "failure",
|
|
926
|
+
summary: String(a.summary),
|
|
927
|
+
targetTables: [r],
|
|
928
|
+
toolName: "execute_database_mutation"
|
|
929
|
+
});
|
|
930
|
+
return {
|
|
931
|
+
auditLogged: s.auditLogged,
|
|
932
|
+
...s.auditError ? { auditError: s.auditError } : {},
|
|
933
|
+
message: `Database mutation failed: ${i}`,
|
|
934
|
+
mutationExecuted: !1,
|
|
935
|
+
operation: n.operation,
|
|
936
|
+
success: !1,
|
|
937
|
+
table: r
|
|
938
|
+
};
|
|
939
|
+
}
|
|
906
940
|
}
|
|
907
|
-
async function
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
941
|
+
async function $(e, t) {
|
|
942
|
+
let n = E.parse(e), r = [];
|
|
943
|
+
for (let e of n.actions) {
|
|
944
|
+
let n = q(e);
|
|
945
|
+
await v(e, n, t);
|
|
946
|
+
let i = e.operation === "update" || e.operation === "delete" ? await K(D(t), n, e.filters ?? []) : [];
|
|
947
|
+
r.push({
|
|
948
|
+
input: e,
|
|
949
|
+
preview: J({
|
|
950
|
+
input: e,
|
|
951
|
+
table: n,
|
|
952
|
+
targetRows: i
|
|
953
|
+
}),
|
|
954
|
+
table: n
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
let i = r.map(({ preview: e }) => String(e.summary)), a = {
|
|
958
|
+
actionCount: r.length,
|
|
959
|
+
actionSummaries: i,
|
|
960
|
+
summary: n.summary || `Run ${r.length} confirmed database actions.`,
|
|
961
|
+
tables: Array.from(new Set(r.map((e) => e.table)))
|
|
962
|
+
}, o = r.map(({ input: e, preview: t, table: n }) => ({
|
|
963
|
+
input: e,
|
|
964
|
+
table: n,
|
|
965
|
+
targetIds: t.targetIds
|
|
966
|
+
})), s = N({
|
|
967
|
+
action: "DATABASE ACTION PLAN",
|
|
968
|
+
context: t,
|
|
969
|
+
payload: o,
|
|
970
|
+
preview: a,
|
|
971
|
+
subject: `${r.length} actions`
|
|
972
|
+
});
|
|
973
|
+
if (s) return s;
|
|
974
|
+
let c = [], l = !1;
|
|
975
|
+
for (let [e, n] of r.entries()) {
|
|
976
|
+
let i = await Q(n.input, {
|
|
977
|
+
...t,
|
|
978
|
+
skipAudit: !0,
|
|
979
|
+
skipConfirmation: !0
|
|
980
|
+
});
|
|
981
|
+
if (c.push(i), i && typeof i == "object" && i.mutationExecuted === !0 && (l = !0), !i || typeof i != "object" || i.success === !1) {
|
|
982
|
+
let n = await Y({
|
|
983
|
+
context: t,
|
|
984
|
+
errorMessage: i && typeof i == "object" && typeof i.message == "string" ? i.message : `Database action ${e + 1} failed.`,
|
|
985
|
+
input: o,
|
|
986
|
+
preview: a,
|
|
987
|
+
status: "failure",
|
|
988
|
+
summary: String(a.summary),
|
|
989
|
+
targetTables: a.tables,
|
|
990
|
+
toolName: "execute_database_action_plan"
|
|
991
|
+
});
|
|
992
|
+
return {
|
|
993
|
+
actionCount: r.length,
|
|
994
|
+
auditLogged: n.auditLogged,
|
|
995
|
+
...n.auditError ? { auditError: n.auditError } : {},
|
|
996
|
+
failedActionIndex: e,
|
|
997
|
+
message: i && typeof i == "object" && typeof i.message == "string" ? i.message : `Database action ${e + 1} failed.`,
|
|
998
|
+
mutationExecuted: l,
|
|
999
|
+
results: c,
|
|
1000
|
+
success: !1
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
let u = await Y({
|
|
1005
|
+
context: t,
|
|
1006
|
+
input: o,
|
|
1007
|
+
preview: a,
|
|
1008
|
+
status: "success",
|
|
1009
|
+
summary: String(a.summary),
|
|
1010
|
+
targetTables: a.tables,
|
|
1011
|
+
toolName: "execute_database_action_plan"
|
|
1012
|
+
});
|
|
1013
|
+
return {
|
|
1014
|
+
actionCount: r.length,
|
|
1015
|
+
auditLogged: u.auditLogged,
|
|
1016
|
+
...u.auditError ? { auditError: u.auditError } : {},
|
|
1017
|
+
mutationExecuted: l,
|
|
1018
|
+
results: c,
|
|
1019
|
+
success: !0,
|
|
1020
|
+
summary: n.summary ?? null
|
|
1021
|
+
};
|
|
986
1022
|
}
|
|
987
|
-
function
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1023
|
+
function ie(e) {
|
|
1024
|
+
return {
|
|
1025
|
+
describe_database_schema: o({
|
|
1026
|
+
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.",
|
|
1027
|
+
execute: (e) => X(e),
|
|
1028
|
+
inputSchema: C,
|
|
1029
|
+
strict: !0
|
|
1030
|
+
}),
|
|
1031
|
+
execute_database_action_plan: o({
|
|
1032
|
+
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.",
|
|
1033
|
+
execute: (t) => $(t, e),
|
|
1034
|
+
inputSchema: E,
|
|
1035
|
+
strict: !0
|
|
1036
|
+
}),
|
|
1037
|
+
execute_database_mutation: o({
|
|
1038
|
+
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.",
|
|
1039
|
+
execute: (t) => Q(t, e),
|
|
1040
|
+
inputSchema: T,
|
|
1041
|
+
strict: !0
|
|
1042
|
+
}),
|
|
1043
|
+
read_database_records: o({
|
|
1044
|
+
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.",
|
|
1045
|
+
execute: (t) => Z(t, e),
|
|
1046
|
+
inputSchema: w,
|
|
1047
|
+
strict: !0
|
|
1048
|
+
})
|
|
1049
|
+
};
|
|
1014
1050
|
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
F as describeDatabaseSchemaInputSchema,
|
|
1018
|
-
be as executeDatabaseActionPlan,
|
|
1019
|
-
z as executeDatabaseActionPlanInputSchema,
|
|
1020
|
-
Q as executeDatabaseMutation,
|
|
1021
|
-
P as executeDatabaseMutationInputSchema,
|
|
1022
|
-
fe as executeDescribeDatabaseSchema,
|
|
1023
|
-
ge as executeReadDatabaseRecords,
|
|
1024
|
-
B as readDatabaseRecordsInputSchema
|
|
1025
|
-
};
|
|
1051
|
+
//#endregion
|
|
1052
|
+
export { ie as createCortexDatabaseAgentTools, C as describeDatabaseSchemaInputSchema, $ as executeDatabaseActionPlan, E as executeDatabaseActionPlanInputSchema, Q as executeDatabaseMutation, T as executeDatabaseMutationInputSchema, X as executeDescribeDatabaseSchema, Z as executeReadDatabaseRecords, w as readDatabaseRecordsInputSchema };
|