@nextblock-cms/cortex 0.20.1 → 0.21.0

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.
Files changed (71) hide show
  1. package/client.cjs.js +1 -1
  2. package/client.es.js +3 -7
  3. package/index.cjs.js +1 -1
  4. package/index.es.js +24 -277
  5. package/lib/ai-block-generation.cjs.js +3 -4
  6. package/lib/ai-block-generation.es.js +143 -182
  7. package/lib/ai-client.cjs.js +1 -1
  8. package/lib/ai-client.d.ts +1 -1
  9. package/lib/ai-client.es.js +101 -135
  10. package/lib/ai-config.cjs.js +1 -1
  11. package/lib/ai-config.es.js +89 -108
  12. package/lib/ai-cortex-widget-builder.cjs.js +1 -1
  13. package/lib/ai-cortex-widget-builder.es.js +56 -70
  14. package/lib/ai-global-agent-content-ops-tools.cjs.js +1 -1
  15. package/lib/ai-global-agent-content-ops-tools.d.ts +1943 -68
  16. package/lib/ai-global-agent-content-ops-tools.es.js +185 -199
  17. package/lib/ai-global-agent-custom-block-tools.cjs.js +1 -1
  18. package/lib/ai-global-agent-custom-block-tools.d.ts +2160 -95
  19. package/lib/ai-global-agent-custom-block-tools.es.js +226 -223
  20. package/lib/ai-global-agent-db-tools.cjs.js +1 -1
  21. package/lib/ai-global-agent-db-tools.d.ts +2708 -98
  22. package/lib/ai-global-agent-db-tools.es.js +1013 -986
  23. package/lib/ai-global-agent-ecommerce.cjs.js +1 -1
  24. package/lib/ai-global-agent-ecommerce.es.js +3 -7
  25. package/lib/ai-global-agent-site-tools.cjs.js +2 -3
  26. package/lib/ai-global-agent-site-tools.d.ts +10695 -500
  27. package/lib/ai-global-agent-site-tools.es.js +750 -757
  28. package/lib/ai-global-agent-theming-tools.cjs.js +1 -3
  29. package/lib/ai-global-agent-theming-tools.d.ts +2905 -105
  30. package/lib/ai-global-agent-theming-tools.es.js +326 -396
  31. package/lib/ai-global-agent-tools.cjs.js +2 -2
  32. package/lib/ai-global-agent-tools.d.ts +4 -2230
  33. package/lib/ai-global-agent-tools.es.js +3899 -4328
  34. package/lib/ai-key-crypto.cjs.js +1 -1
  35. package/lib/ai-key-crypto.es.js +63 -82
  36. package/lib/ai-key-verification.cjs.js +1 -1
  37. package/lib/ai-key-verification.es.js +74 -63
  38. package/lib/ai-model-catalog.cjs.js +1 -1
  39. package/lib/ai-model-catalog.es.js +18 -22
  40. package/lib/ai-model-registry.cjs.js +2 -2
  41. package/lib/ai-model-registry.es.js +246 -309
  42. package/lib/ai-seo-metadata.cjs.js +2 -3
  43. package/lib/ai-seo-metadata.es.js +143 -185
  44. package/lib/ai-vision.cjs.js +2 -2
  45. package/lib/ai-vision.d.ts +6 -6
  46. package/lib/ai-vision.es.js +161 -215
  47. package/lib/block-content-schemas.cjs.js +1 -1
  48. package/lib/block-content-schemas.es.js +324 -254
  49. package/lib/cortex-widget-registry.cjs.js +1 -1
  50. package/lib/cortex-widget-registry.es.js +35 -43
  51. package/lib/cortex-widget-schema.cjs.js +2 -3
  52. package/lib/cortex-widget-schema.es.js +280 -309
  53. package/lib/editor-document-from-html.cjs.js +1 -1
  54. package/lib/editor-document-from-html.es.js +334 -278
  55. package/lib/fetch-host-guard.cjs.js +1 -0
  56. package/lib/fetch-host-guard.d.ts +2 -0
  57. package/lib/fetch-host-guard.es.js +30 -0
  58. package/lib/mcp-server.cjs.js +1 -1
  59. package/lib/mcp-server.es.js +155 -173
  60. package/lib/mcp-tokens.cjs.js +1 -1
  61. package/lib/mcp-tokens.es.js +95 -107
  62. package/lib/mcp-tool-registry.cjs.js +5 -6
  63. package/lib/mcp-tool-registry.es.js +533 -411
  64. package/lib/site-brief.cjs.js +2 -2
  65. package/lib/site-brief.es.js +102 -108
  66. package/lib/vision-image-download.cjs.js +1 -0
  67. package/lib/vision-image-download.d.ts +43 -0
  68. package/lib/vision-image-download.es.js +120 -0
  69. package/lib/zod-config.cjs.js +1 -1
  70. package/lib/zod-config.es.js +5 -6
  71. package/package.json +8 -8
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./ai-key-crypto.cjs.js"),i=require("@nextblock-cms/db/secrets"),O="Cortex AI configuration can only be imported from server-side code.";function o(){if(!(typeof window>"u"))throw new Error(O)}const y="cortex-ai",m="NextBlock Cortex AI",R="cortex_ai_openrouter_api_key",K="cortex_ai_openrouter_model_selection",N="cortex_ai_pexels_api_key",I="cortex_ai_unsplash_access_key",l="cortex_ai_unsplash_app_name",a="cortex_ai_agent_settings",p={maxOutputTokens:16e3,maxSteps:8,responseTimeoutMs:12e4,temperature:.1},T={maxOutputTokens:{max:2e5,min:256},maxSteps:{max:100,min:2},responseTimeoutMs:{max:6e5,min:15e3},temperature:{max:2,min:0}};function s(e,t,n,E){const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Math.min(n,Math.max(t,r)):E}function c(e){const t=e&&typeof e=="object"&&!Array.isArray(e)?e:{},n=T,E=p,r=t.maxOutputTokens;return{maxOutputTokens:r===null||r==="unlimited"||r===""?null:s(r,n.maxOutputTokens.min,n.maxOutputTokens.max,E.maxOutputTokens??16e3),maxSteps:Math.round(s(t.maxSteps,n.maxSteps.min,n.maxSteps.max,E.maxSteps)),responseTimeoutMs:Math.round(s(t.responseTimeoutMs,n.responseTimeoutMs.min,n.responseTimeoutMs.max,E.responseTimeoutMs)),temperature:s(t.temperature,n.temperature.min,n.temperature.max,E.temperature)}}async function x(e){if(e)try{const{data:t}=await e.from("site_settings").select("value").eq("key",a).maybeSingle();if(t?.value)return c(t.value)}catch{}return{...p}}function _(e){return process.env[e]?.trim()||null}function C(){return o(),_("PEXELS_API_KEY")}function d(){return o(),_("UNSPLASH_ACCESS_KEY")}function A(){return o(),_("OPENROUTER_API_KEY")}function S(){o();const e=A();return{encryptionKey:_("CORTEX_AI_ENCRYPTION_KEY"),freemiusSandboxKey:_("FREEMIUS_AI_SANDBOX_KEY"),hasEncryptionKey:i.hasSecretEncryptionKey(),hasOpenRouterEnvKey:!!e,openRouterEnvKeyLast4:e?e.slice(-4):null}}function f(){o();const e=i.resolveSecretEncryptionKey();if(!e)throw new Error("An encryption key (NEXTBLOCK_ENCRYPTION_KEY, CORTEX_AI_ENCRYPTION_KEY, or a Supabase service-role key) is required to manage stored OpenRouter keys.");return e}function g(e){return u.encryptOpenRouterApiKey({apiKey:e,encryptionSecret:f()})}function v(e){o();const t=i.tryDecryptWithEnvKey(e);if(t===null)throw new Error("Failed to decrypt stored OpenRouter key.");return t}function P(e){return u.getOpenRouterKeyEnvelopeStatus(e)}function G(){o();const e=S();return{hasEnvOpenRouterKey:e.hasOpenRouterEnvKey,maskedEnvOpenRouterKey:e.openRouterEnvKeyLast4?u.getMaskedOpenRouterKey(e.openRouterEnvKeyLast4):null}}exports.CORTEX_AI_AGENT_SETTINGS_BOUNDS=T;exports.CORTEX_AI_AGENT_SETTINGS_DEFAULTS=p;exports.CORTEX_AI_AGENT_SETTINGS_KEY=a;exports.CORTEX_AI_OPENROUTER_MODEL_SELECTION_SETTING_KEY=K;exports.CORTEX_AI_OPENROUTER_SETTING_KEY=R;exports.CORTEX_AI_PACKAGE_ID=y;exports.CORTEX_AI_PACKAGE_NAME=m;exports.CORTEX_AI_PEXELS_SETTING_KEY=N;exports.CORTEX_AI_UNSPLASH_APP_NAME_SETTING_KEY=l;exports.CORTEX_AI_UNSPLASH_SETTING_KEY=I;exports.decryptStoredOpenRouterApiKey=v;exports.encryptStoredOpenRouterApiKey=g;exports.getCortexAiEnvConfig=S;exports.getEnvOpenRouterKeyStatus=G;exports.getOpenRouterEnvApiKey=A;exports.getPexelsEnvApiKey=C;exports.getStoredOpenRouterKeyStatus=P;exports.getUnsplashEnvApiKey=d;exports.normalizeCortexAiAgentSettings=c;exports.resolveCortexAiAgentSettings=x;
1
+ const e=require("./ai-key-crypto.cjs.js");let t=require("@nextblock-cms/db/secrets");var n=`Cortex AI configuration can only be imported from server-side code.`;function r(){if(typeof window<`u`)throw Error(n)}var i=`cortex-ai`,a=`NextBlock Cortex AI`,o=`cortex_ai_openrouter_api_key`,s=`cortex_ai_openrouter_model_selection`,c=`cortex_ai_pexels_api_key`,l=`cortex_ai_unsplash_access_key`,u=`cortex_ai_unsplash_app_name`,d=`cortex_ai_agent_settings`,f={maxOutputTokens:16e3,maxSteps:8,responseTimeoutMs:12e4,temperature:.1},p={maxOutputTokens:{max:2e5,min:256},maxSteps:{max:100,min:2},responseTimeoutMs:{max:6e5,min:15e3},temperature:{max:2,min:0}};function m(e,t,n,r){let i=typeof e==`number`?e:Number(e);return Number.isFinite(i)?Math.min(n,Math.max(t,i)):r}function h(e){let t=e&&typeof e==`object`&&!Array.isArray(e)?e:{},n=p,r=f,i=t.maxOutputTokens;return{maxOutputTokens:i===null||i===`unlimited`||i===``?null:m(i,n.maxOutputTokens.min,n.maxOutputTokens.max,r.maxOutputTokens??16e3),maxSteps:Math.round(m(t.maxSteps,n.maxSteps.min,n.maxSteps.max,r.maxSteps)),responseTimeoutMs:Math.round(m(t.responseTimeoutMs,n.responseTimeoutMs.min,n.responseTimeoutMs.max,r.responseTimeoutMs)),temperature:m(t.temperature,n.temperature.min,n.temperature.max,r.temperature)}}async function g(e){if(e)try{let{data:t}=await e.from(`site_settings`).select(`value`).eq(`key`,d).maybeSingle();if(t?.value)return h(t.value)}catch{}return{...f}}function _(e){return process.env[e]?.trim()||null}function v(){return r(),_(`PEXELS_API_KEY`)}function y(){return r(),_(`UNSPLASH_ACCESS_KEY`)}function b(){return r(),_(`OPENROUTER_API_KEY`)}function x(){r();let e=b();return{encryptionKey:_(`CORTEX_AI_ENCRYPTION_KEY`),freemiusSandboxKey:_(`FREEMIUS_AI_SANDBOX_KEY`),hasEncryptionKey:(0,t.hasSecretEncryptionKey)(),hasOpenRouterEnvKey:!!e,openRouterEnvKeyLast4:e?e.slice(-4):null}}function S(){r();let e=(0,t.resolveSecretEncryptionKey)();if(!e)throw Error(`An encryption key (NEXTBLOCK_ENCRYPTION_KEY, CORTEX_AI_ENCRYPTION_KEY, or a Supabase service-role key) is required to manage stored OpenRouter keys.`);return e}function C(t){return e.encryptOpenRouterApiKey({apiKey:t,encryptionSecret:S()})}function w(e){r();let n=(0,t.tryDecryptWithEnvKey)(e);if(n===null)throw Error(`Failed to decrypt stored OpenRouter key.`);return n}function T(t){return e.getOpenRouterKeyEnvelopeStatus(t)}function E(){r();let t=x();return{hasEnvOpenRouterKey:t.hasOpenRouterEnvKey,maskedEnvOpenRouterKey:t.openRouterEnvKeyLast4?e.getMaskedOpenRouterKey(t.openRouterEnvKeyLast4):null}}exports.CORTEX_AI_AGENT_SETTINGS_BOUNDS=p,exports.CORTEX_AI_AGENT_SETTINGS_DEFAULTS=f,exports.CORTEX_AI_AGENT_SETTINGS_KEY=d,exports.CORTEX_AI_OPENROUTER_MODEL_SELECTION_SETTING_KEY=s,exports.CORTEX_AI_OPENROUTER_SETTING_KEY=o,exports.CORTEX_AI_PACKAGE_ID=i,exports.CORTEX_AI_PACKAGE_NAME=a,exports.CORTEX_AI_PEXELS_SETTING_KEY=c,exports.CORTEX_AI_UNSPLASH_APP_NAME_SETTING_KEY=u,exports.CORTEX_AI_UNSPLASH_SETTING_KEY=l,exports.decryptStoredOpenRouterApiKey=w,exports.encryptStoredOpenRouterApiKey=C,exports.getCortexAiEnvConfig=x,exports.getEnvOpenRouterKeyStatus=E,exports.getOpenRouterEnvApiKey=b,exports.getPexelsEnvApiKey=v,exports.getStoredOpenRouterKeyStatus=T,exports.getUnsplashEnvApiKey=y,exports.normalizeCortexAiAgentSettings=h,exports.resolveCortexAiAgentSettings=g;
@@ -1,123 +1,104 @@
1
- import { encryptOpenRouterApiKey as a, getMaskedOpenRouterKey as E, getOpenRouterKeyEnvelopeStatus as _ } from "./ai-key-crypto.es.js";
2
- import { tryDecryptWithEnvKey as c, hasSecretEncryptionKey as m, resolveSecretEncryptionKey as y } from "@nextblock-cms/db/secrets";
3
- const T = "Cortex AI configuration can only be imported from server-side code.";
4
- function o() {
5
- if (!(typeof window > "u"))
6
- throw new Error(T);
1
+ import { encryptOpenRouterApiKey as e, getMaskedOpenRouterKey as t, getOpenRouterKeyEnvelopeStatus as n } from "./ai-key-crypto.es.js";
2
+ import { hasSecretEncryptionKey as r, resolveSecretEncryptionKey as i, tryDecryptWithEnvKey as a } from "@nextblock-cms/db/secrets";
3
+ //#region libs/cortex/src/lib/ai-config.ts
4
+ var o = "Cortex AI configuration can only be imported from server-side code.";
5
+ function s() {
6
+ if (typeof window < "u") throw Error(o);
7
7
  }
8
- const I = "cortex-ai", d = "NextBlock Cortex AI", C = "cortex_ai_openrouter_api_key", v = "cortex_ai_openrouter_model_selection", g = "cortex_ai_pexels_api_key", k = "cortex_ai_unsplash_access_key", M = "cortex_ai_unsplash_app_name", O = "cortex_ai_agent_settings", p = {
9
- maxOutputTokens: 16e3,
10
- maxSteps: 8,
11
- responseTimeoutMs: 12e4,
12
- temperature: 0.1
13
- }, S = {
14
- maxOutputTokens: { max: 2e5, min: 256 },
15
- maxSteps: { max: 100, min: 2 },
16
- responseTimeoutMs: { max: 6e5, min: 15e3 },
17
- temperature: { max: 2, min: 0 }
8
+ var c = "cortex-ai", l = "NextBlock Cortex AI", u = "cortex_ai_openrouter_api_key", d = "cortex_ai_openrouter_model_selection", f = "cortex_ai_pexels_api_key", p = "cortex_ai_unsplash_access_key", m = "cortex_ai_unsplash_app_name", h = "cortex_ai_agent_settings", g = {
9
+ maxOutputTokens: 16e3,
10
+ maxSteps: 8,
11
+ responseTimeoutMs: 12e4,
12
+ temperature: .1
13
+ }, _ = {
14
+ maxOutputTokens: {
15
+ max: 2e5,
16
+ min: 256
17
+ },
18
+ maxSteps: {
19
+ max: 100,
20
+ min: 2
21
+ },
22
+ responseTimeoutMs: {
23
+ max: 6e5,
24
+ min: 15e3
25
+ },
26
+ temperature: {
27
+ max: 2,
28
+ min: 0
29
+ }
18
30
  };
19
- function i(e, t, n, s) {
20
- const r = typeof e == "number" ? e : Number(e);
21
- return Number.isFinite(r) ? Math.min(n, Math.max(t, r)) : s;
31
+ function v(e, t, n, r) {
32
+ let i = typeof e == "number" ? e : Number(e);
33
+ return Number.isFinite(i) ? Math.min(n, Math.max(t, i)) : r;
22
34
  }
23
- function A(e) {
24
- const t = e && typeof e == "object" && !Array.isArray(e) ? e : {}, n = S, s = p, r = t.maxOutputTokens;
25
- return {
26
- maxOutputTokens: r === null || r === "unlimited" || r === "" ? null : i(r, n.maxOutputTokens.min, n.maxOutputTokens.max, s.maxOutputTokens ?? 16e3),
27
- maxSteps: Math.round(i(t.maxSteps, n.maxSteps.min, n.maxSteps.max, s.maxSteps)),
28
- responseTimeoutMs: Math.round(
29
- i(t.responseTimeoutMs, n.responseTimeoutMs.min, n.responseTimeoutMs.max, s.responseTimeoutMs)
30
- ),
31
- temperature: i(t.temperature, n.temperature.min, n.temperature.max, s.temperature)
32
- };
35
+ function y(e) {
36
+ let t = e && typeof e == "object" && !Array.isArray(e) ? e : {}, n = _, r = g, i = t.maxOutputTokens;
37
+ return {
38
+ maxOutputTokens: i === null || i === "unlimited" || i === "" ? null : v(i, n.maxOutputTokens.min, n.maxOutputTokens.max, r.maxOutputTokens ?? 16e3),
39
+ maxSteps: Math.round(v(t.maxSteps, n.maxSteps.min, n.maxSteps.max, r.maxSteps)),
40
+ responseTimeoutMs: Math.round(v(t.responseTimeoutMs, n.responseTimeoutMs.min, n.responseTimeoutMs.max, r.responseTimeoutMs)),
41
+ temperature: v(t.temperature, n.temperature.min, n.temperature.max, r.temperature)
42
+ };
33
43
  }
34
- async function P(e) {
35
- if (e)
36
- try {
37
- const { data: t } = await e.from("site_settings").select("value").eq("key", O).maybeSingle();
38
- if (t?.value)
39
- return A(t.value);
40
- } catch {
41
- }
42
- return { ...p };
44
+ async function b(e) {
45
+ if (e) try {
46
+ let { data: t } = await e.from("site_settings").select("value").eq("key", h).maybeSingle();
47
+ if (t?.value) return y(t.value);
48
+ } catch {}
49
+ return { ...g };
43
50
  }
44
- function u(e) {
45
- return process.env[e]?.trim() || null;
51
+ function x(e) {
52
+ return process.env[e]?.trim() || null;
46
53
  }
47
- function h() {
48
- return o(), u("PEXELS_API_KEY");
54
+ function S() {
55
+ return s(), x("PEXELS_API_KEY");
49
56
  }
50
- function Y() {
51
- return o(), u("UNSPLASH_ACCESS_KEY");
57
+ function C() {
58
+ return s(), x("UNSPLASH_ACCESS_KEY");
52
59
  }
53
- function R() {
54
- return o(), u("OPENROUTER_API_KEY");
60
+ function w() {
61
+ return s(), x("OPENROUTER_API_KEY");
55
62
  }
56
- function x() {
57
- o();
58
- const e = R();
59
- return {
60
- encryptionKey: u("CORTEX_AI_ENCRYPTION_KEY"),
61
- freemiusSandboxKey: u("FREEMIUS_AI_SANDBOX_KEY"),
62
- // True when ANY usable key exists: an explicit env key OR the service-role-derived
63
- // fallback — so BYOK works on a one-click Vercel deploy with no extra env var.
64
- hasEncryptionKey: m(),
65
- hasOpenRouterEnvKey: !!e,
66
- openRouterEnvKeyLast4: e ? e.slice(-4) : null
67
- };
63
+ function T() {
64
+ s();
65
+ let e = w();
66
+ return {
67
+ encryptionKey: x("CORTEX_AI_ENCRYPTION_KEY"),
68
+ freemiusSandboxKey: x("FREEMIUS_AI_SANDBOX_KEY"),
69
+ hasEncryptionKey: r(),
70
+ hasOpenRouterEnvKey: !!e,
71
+ openRouterEnvKeyLast4: e ? e.slice(-4) : null
72
+ };
68
73
  }
69
- function K() {
70
- o();
71
- const e = y();
72
- if (!e)
73
- throw new Error(
74
- "An encryption key (NEXTBLOCK_ENCRYPTION_KEY, CORTEX_AI_ENCRYPTION_KEY, or a Supabase service-role key) is required to manage stored OpenRouter keys."
75
- );
76
- return e;
74
+ function E() {
75
+ s();
76
+ let e = i();
77
+ if (!e) throw Error("An encryption key (NEXTBLOCK_ENCRYPTION_KEY, CORTEX_AI_ENCRYPTION_KEY, or a Supabase service-role key) is required to manage stored OpenRouter keys.");
78
+ return e;
77
79
  }
78
- function X(e) {
79
- return a({
80
- apiKey: e,
81
- encryptionSecret: K()
82
- });
80
+ function D(t) {
81
+ return e({
82
+ apiKey: t,
83
+ encryptionSecret: E()
84
+ });
83
85
  }
84
- function G(e) {
85
- o();
86
- const t = c(e);
87
- if (t === null)
88
- throw new Error("Failed to decrypt stored OpenRouter key.");
89
- return t;
86
+ function O(e) {
87
+ s();
88
+ let t = a(e);
89
+ if (t === null) throw Error("Failed to decrypt stored OpenRouter key.");
90
+ return t;
90
91
  }
91
- function L(e) {
92
- return _(e);
92
+ function k(e) {
93
+ return n(e);
93
94
  }
94
- function U() {
95
- o();
96
- const e = x();
97
- return {
98
- hasEnvOpenRouterKey: e.hasOpenRouterEnvKey,
99
- maskedEnvOpenRouterKey: e.openRouterEnvKeyLast4 ? E(e.openRouterEnvKeyLast4) : null
100
- };
95
+ function A() {
96
+ s();
97
+ let e = T();
98
+ return {
99
+ hasEnvOpenRouterKey: e.hasOpenRouterEnvKey,
100
+ maskedEnvOpenRouterKey: e.openRouterEnvKeyLast4 ? t(e.openRouterEnvKeyLast4) : null
101
+ };
101
102
  }
102
- export {
103
- S as CORTEX_AI_AGENT_SETTINGS_BOUNDS,
104
- p as CORTEX_AI_AGENT_SETTINGS_DEFAULTS,
105
- O as CORTEX_AI_AGENT_SETTINGS_KEY,
106
- v as CORTEX_AI_OPENROUTER_MODEL_SELECTION_SETTING_KEY,
107
- C as CORTEX_AI_OPENROUTER_SETTING_KEY,
108
- I as CORTEX_AI_PACKAGE_ID,
109
- d as CORTEX_AI_PACKAGE_NAME,
110
- g as CORTEX_AI_PEXELS_SETTING_KEY,
111
- M as CORTEX_AI_UNSPLASH_APP_NAME_SETTING_KEY,
112
- k as CORTEX_AI_UNSPLASH_SETTING_KEY,
113
- G as decryptStoredOpenRouterApiKey,
114
- X as encryptStoredOpenRouterApiKey,
115
- x as getCortexAiEnvConfig,
116
- U as getEnvOpenRouterKeyStatus,
117
- R as getOpenRouterEnvApiKey,
118
- h as getPexelsEnvApiKey,
119
- L as getStoredOpenRouterKeyStatus,
120
- Y as getUnsplashEnvApiKey,
121
- A as normalizeCortexAiAgentSettings,
122
- P as resolveCortexAiAgentSettings
123
- };
103
+ //#endregion
104
+ export { _ as CORTEX_AI_AGENT_SETTINGS_BOUNDS, g as CORTEX_AI_AGENT_SETTINGS_DEFAULTS, h as CORTEX_AI_AGENT_SETTINGS_KEY, d as CORTEX_AI_OPENROUTER_MODEL_SELECTION_SETTING_KEY, u as CORTEX_AI_OPENROUTER_SETTING_KEY, c as CORTEX_AI_PACKAGE_ID, l as CORTEX_AI_PACKAGE_NAME, f as CORTEX_AI_PEXELS_SETTING_KEY, m as CORTEX_AI_UNSPLASH_APP_NAME_SETTING_KEY, p as CORTEX_AI_UNSPLASH_SETTING_KEY, O as decryptStoredOpenRouterApiKey, D as encryptStoredOpenRouterApiKey, T as getCortexAiEnvConfig, A as getEnvOpenRouterKeyStatus, w as getOpenRouterEnvApiKey, S as getPexelsEnvApiKey, k as getStoredOpenRouterKeyStatus, C as getUnsplashEnvApiKey, y as normalizeCortexAiAgentSettings, b as resolveCortexAiAgentSettings };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("ai"),x=require("./ai-client.cjs.js"),o=require("./ai-model-registry.cjs.js"),r=require("./cortex-widget-schema.cjs.js"),f=6e4;function y(e){const t=o.getHttpStatusCode(e);if(t===401||t===402||t===403)return!1;if(o.isOpenRouterRecoverableRoutingError(e)||t&&t>=500)return!0;const n=e instanceof Error?e.message:String(e);return/NoObjectGenerated|No object generated|structured output|schema|validation|Invalid|aborted|abort|timeout|timed out/i.test(n)}async function I(e){const{apiKey:t,fallbackModelIds:n,modelId:c,modelSelection:m,...g}=e,a=r.cortexWidgetBuildRequestSchema.parse(g),i=await x.createCortexAiOpenRouterClient({apiKey:t,modelSelection:m}),d=o.buildCortexAiRoutingPolicy({credentialSource:i.credentialSource,fallbackModelIds:n,requestedModelId:c??a.modelId,selectedModel:i.modelSelection}),l=await o.runWithCortexAiModelFallback({modelIds:d.modelIds,shouldRetry:y,execute:async s=>{const u=new AbortController,p=setTimeout(()=>u.abort(),f);try{const b=o.omitUnsupportedCortexAiModelOptions({abortSignal:u.signal,maxOutputTokens:7e3,maxRetries:0,output:"no-schema",prompt:r.buildCortexWidgetBuilderPrompt(a),system:r.buildCortexWidgetBuilderSystemPrompt(),temperature:.15},{modelId:s,modelSelection:d.modelSelection}),C=await S.generateObject({...b,model:i.model(s)});return r.validateCortexWidgetDefinitionOutput(C.object)}finally{clearTimeout(p)}}});return{attempts:l.attempts,credentialSource:i.credentialSource,definition:l.result,modelId:l.modelId}}exports.generateCortexWidgetDefinition=I;
1
+ const e=require("./ai-model-registry.cjs.js"),t=require("./ai-client.cjs.js"),n=require("./cortex-widget-schema.cjs.js");let r=require("ai");var i=6e4;function a(t){let n=e.getHttpStatusCode(t);if(n===401||n===402||n===403)return!1;if(e.isOpenRouterRecoverableRoutingError(t)||n&&n>=500)return!0;let r=t instanceof Error?t.message:String(t);return/NoObjectGenerated|No object generated|structured output|schema|validation|Invalid|aborted|abort|timeout|timed out/i.test(r)}async function o(o){let{apiKey:s,fallbackModelIds:c,modelId:l,modelSelection:u,...d}=o,f=n.cortexWidgetBuildRequestSchema.parse(d),p=await t.createCortexAiOpenRouterClient({apiKey:s,modelSelection:u}),m=e.buildCortexAiRoutingPolicy({credentialSource:p.credentialSource,fallbackModelIds:c,requestedModelId:l??f.modelId,selectedModel:p.modelSelection}),h=await e.runWithCortexAiModelFallback({modelIds:m.modelIds,shouldRetry:a,execute:async t=>{let a=new AbortController,o=setTimeout(()=>a.abort(),i);try{let i=e.omitUnsupportedCortexAiModelOptions({abortSignal:a.signal,maxOutputTokens:7e3,maxRetries:0,output:`no-schema`,prompt:n.buildCortexWidgetBuilderPrompt(f),instructions:n.buildCortexWidgetBuilderSystemPrompt(),temperature:.15},{modelId:t,modelSelection:m.modelSelection}),o=await(0,r.generateObject)({...i,model:p.model(t)});return n.validateCortexWidgetDefinitionOutput(o.object)}finally{clearTimeout(o)}}});return{attempts:h.attempts,credentialSource:p.credentialSource,definition:h.result,modelId:h.modelId}}exports.generateCortexWidgetDefinition=o;
@@ -1,72 +1,58 @@
1
- import { generateObject as b } from "ai";
2
- import { createCortexAiOpenRouterClient as f } from "./ai-client.es.js";
3
- import { buildCortexAiRoutingPolicy as C, runWithCortexAiModelFallback as x, omitUnsupportedCortexAiModelOptions as S, getHttpStatusCode as I, isOpenRouterRecoverableRoutingError as y } from "./ai-model-registry.es.js";
4
- import { cortexWidgetBuildRequestSchema as O, buildCortexWidgetBuilderSystemPrompt as R, buildCortexWidgetBuilderPrompt as T, validateCortexWidgetDefinitionOutput as W } from "./cortex-widget-schema.es.js";
5
- const E = 6e4;
6
- function M(e) {
7
- const t = I(e);
8
- if (t === 401 || t === 402 || t === 403)
9
- return !1;
10
- if (y(e) || t && t >= 500)
11
- return !0;
12
- const r = e instanceof Error ? e.message : String(e);
13
- return /NoObjectGenerated|No object generated|structured output|schema|validation|Invalid|aborted|abort|timeout|timed out/i.test(
14
- r
15
- );
1
+ import { buildCortexAiRoutingPolicy as e, getHttpStatusCode as t, isOpenRouterRecoverableRoutingError as n, omitUnsupportedCortexAiModelOptions as r, runWithCortexAiModelFallback as i } from "./ai-model-registry.es.js";
2
+ import { createCortexAiOpenRouterClient as a } from "./ai-client.es.js";
3
+ import { buildCortexWidgetBuilderPrompt as o, buildCortexWidgetBuilderSystemPrompt as s, cortexWidgetBuildRequestSchema as c, validateCortexWidgetDefinitionOutput as l } from "./cortex-widget-schema.es.js";
4
+ import { generateObject as u } from "ai";
5
+ //#region libs/cortex/src/lib/ai-cortex-widget-builder.ts
6
+ var d = 6e4;
7
+ function f(e) {
8
+ let r = t(e);
9
+ if (r === 401 || r === 402 || r === 403) return !1;
10
+ if (n(e) || r && r >= 500) return !0;
11
+ let i = e instanceof Error ? e.message : String(e);
12
+ return /NoObjectGenerated|No object generated|structured output|schema|validation|Invalid|aborted|abort|timeout|timed out/i.test(i);
16
13
  }
17
- async function B(e) {
18
- const { apiKey: t, fallbackModelIds: r, modelId: s, modelSelection: u, ...c } = e, n = O.parse(c), o = await f({ apiKey: t, modelSelection: u }), l = C({
19
- credentialSource: o.credentialSource,
20
- fallbackModelIds: r,
21
- requestedModelId: s ?? n.modelId,
22
- selectedModel: o.modelSelection
23
- }), i = await x({
24
- modelIds: l.modelIds,
25
- shouldRetry: M,
26
- execute: async (d) => {
27
- const a = new AbortController(), m = setTimeout(
28
- () => a.abort(),
29
- E
30
- );
31
- try {
32
- const p = S(
33
- {
34
- abortSignal: a.signal,
35
- maxOutputTokens: 7e3,
36
- maxRetries: 0,
37
- // Use JSON mode WITHOUT a provider-side schema. The widget definition
38
- // is a recursive, discriminated-union structure; sending it as a
39
- // response_format json_schema is rejected by Google Gemini
40
- // ("reference to undefined schema", recursion not supported) and by
41
- // OpenAI ("'oneOf' is not permitted"). We instead describe the shape
42
- // in the prompt and validate the returned JSON with our own Zod
43
- // schema below, which works across every OpenRouter model.
44
- output: "no-schema",
45
- prompt: T(n),
46
- system: R(),
47
- temperature: 0.15
48
- },
49
- {
50
- modelId: d,
51
- modelSelection: l.modelSelection
52
- }
53
- ), g = await b({
54
- ...p,
55
- model: o.model(d)
56
- });
57
- return W(g.object);
58
- } finally {
59
- clearTimeout(m);
60
- }
61
- }
62
- });
63
- return {
64
- attempts: i.attempts,
65
- credentialSource: o.credentialSource,
66
- definition: i.result,
67
- modelId: i.modelId
68
- };
14
+ async function p(t) {
15
+ let { apiKey: n, fallbackModelIds: p, modelId: m, modelSelection: h, ...g } = t, _ = c.parse(g), v = await a({
16
+ apiKey: n,
17
+ modelSelection: h
18
+ }), y = e({
19
+ credentialSource: v.credentialSource,
20
+ fallbackModelIds: p,
21
+ requestedModelId: m ?? _.modelId,
22
+ selectedModel: v.modelSelection
23
+ }), b = await i({
24
+ modelIds: y.modelIds,
25
+ shouldRetry: f,
26
+ execute: async (e) => {
27
+ let t = new AbortController(), n = setTimeout(() => t.abort(), d);
28
+ try {
29
+ let n = r({
30
+ abortSignal: t.signal,
31
+ maxOutputTokens: 7e3,
32
+ maxRetries: 0,
33
+ output: "no-schema",
34
+ prompt: o(_),
35
+ instructions: s(),
36
+ temperature: .15
37
+ }, {
38
+ modelId: e,
39
+ modelSelection: y.modelSelection
40
+ }), i = await u({
41
+ ...n,
42
+ model: v.model(e)
43
+ });
44
+ return l(i.object);
45
+ } finally {
46
+ clearTimeout(n);
47
+ }
48
+ }
49
+ });
50
+ return {
51
+ attempts: b.attempts,
52
+ credentialSource: v.credentialSource,
53
+ definition: b.result,
54
+ modelId: b.modelId
55
+ };
69
56
  }
70
- export {
71
- B as generateCortexWidgetDefinition
72
- };
57
+ //#endregion
58
+ export { p as generateCortexWidgetDefinition };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("ai");require("./zod-config.cjs.js");const r=require("zod"),v="id, file_name, object_key, file_type, width, height, description, folder, created_at";function f(e){if(!e?.supabase)throw new Error("No database connection is available for this tool.");return e.supabase}function c(e){return e?e instanceof Error?e.message:typeof e=="object"&&"message"in e?String(e.message):String(e):"unknown error"}function S(e){return e.normalize("NFD").replace(new RegExp("\\p{Diacritic}","gu"),"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,80)}const y=r.z.strictObject({limit:r.z.number().int().min(1).max(100).default(30),query:r.z.string().trim().max(120).optional().describe('Filter on file name or alt text, e.g. "wormwood" or "laboratory".')}),b=r.z.strictObject({altText:r.z.string().trim().max(300).optional().describe("Alt text describing the image. Write real alt text — it is what screen readers announce and what search engines index."),url:r.z.string().trim().min(1).max(2048).describe("Public https URL of the image to bring into the media library.")});async function z(e,i){const t=y.parse(e);let a=f(i).from("media").select(v).order("created_at",{ascending:!1}).limit(t.limit);if(t.query){const s=`%${t.query}%`;a=a.or(`file_name.ilike.${s},description.ilike.${s}`)}const{data:d,error:l}=await a;if(l)throw new Error(`Could not read the media library: ${c(l)}`);return{count:(d??[]).length,media:d??[],success:!0}}async function $(e,i){const t=b.parse(e),o=i?.importExternalImage;if(!o)throw new Error("Media import is not available on this connection.");const a=await o({...t.altText?{altText:t.altText}:{},url:t.url});if("error"in a)throw new Error(`Could not import that image: ${a.error}`);return{mediaId:a.id,mutationExecuted:!0,success:!0}}const x=r.z.strictObject({code:r.z.string().trim().min(2).max(10).describe('Locale code, e.g. "fr", "es", "de". Re-using an existing code updates that language.'),is_active:r.z.boolean().default(!0).describe("Inactive languages are hidden from the public switcher."),is_default:r.z.boolean().default(!1).describe("Make this the site default. Only one language can be default; setting it clears the others."),name:r.z.string().trim().min(1).max(80).describe('Display name, e.g. "Français".')});async function I(e,i){const t=x.parse(e),o=f(i),a=t.code.toLowerCase(),{data:d}=await o.from("languages").select("id, code").eq("code",a).maybeSingle(),l={code:a,is_active:t.is_active,name:t.name};let s=d?.id;if(s){const{error:u}=await o.from("languages").update(l).eq("id",s);if(u)throw new Error(`Could not update the "${a}" language: ${c(u)}`)}else{const{data:u,error:n}=await o.from("languages").insert(l).select("id").single();if(n||!u?.id)throw new Error(`Could not create the "${a}" language: ${c(n)}`);s=u.id}if(t.is_default){const{error:u}=await o.from("languages").update({is_default:!1}).neq("id",s);if(u)throw new Error(`Could not clear the previous default language: ${c(u)}`);const{error:n}=await o.from("languages").update({is_default:!0}).eq("id",s);if(n)throw new Error(`Could not set the default language: ${c(n)}`)}try{i?.revalidatePath?.("/","layout")}catch{}return{code:a,created:!d,languageId:s,mutationExecuted:!0,success:!0}}const _=r.z.strictObject({action:r.z.enum(["upsert","delete"]).default("upsert"),description:r.z.string().max(1e3).nullable().optional(),name:r.z.string().trim().min(1).max(120).describe('Category name, e.g. "Digestive Health".'),name_translations:r.z.record(r.z.string(),r.z.string()).optional().describe('Translated names keyed by locale code, e.g. { "fr": "Santé digestive" }.'),productSlugs:r.z.array(r.z.string().trim().min(1).max(300)).max(100).optional().describe("Product slugs to place in this category. Replaces the category's current membership."),slug:r.z.string().trim().min(1).max(120).optional().describe("URL slug. Derived from the name when omitted. Re-using a slug updates that category.")});async function L(e,i){const t=_.parse(e),o=f(i),a=t.slug?S(t.slug):S(t.name),{data:d}=await o.from("categories").select("id, name, slug").eq("slug",a).maybeSingle();if(t.action==="delete"){if(!d?.id)return{message:`No category with slug "${a}".`,mutationExecuted:!1,success:!1};const{error:n}=await o.from("categories").delete().eq("id",d.id);if(n)throw new Error(`Could not delete the category: ${c(n)}`);return{action:"delete",mutationExecuted:!0,slug:a,success:!0}}const l={name:t.name,slug:a,...t.description!==void 0?{description:t.description}:{},...t.name_translations?{name_translations:t.name_translations}:{}};let s=d?.id;if(s){const{error:n}=await o.from("categories").update(l).eq("id",s);if(n)throw new Error(`Could not update the category: ${c(n)}`)}else{const{data:n,error:g}=await o.from("categories").insert(l).select("id").single();if(g||!n?.id)throw new Error(`Could not create the category: ${c(g)}`);s=n.id}let u=0;if(t.productSlugs){const{data:n,error:g}=await o.from("products").select("id, slug").in("slug",t.productSlugs);if(g)throw new Error(`Could not resolve those products: ${c(g)}`);const p=n??[],C=t.productSlugs.filter(h=>!p.some(w=>w.slug===h));if(C.length>0)throw new Error(`No product found for slug(s): ${C.join(", ")}.`);const{error:E}=await o.from("product_categories").delete().eq("category_id",s);if(E)throw new Error(`Could not clear the category's products: ${c(E)}`);if(p.length>0){const{error:h}=await o.from("product_categories").insert(p.map(w=>({category_id:s,product_id:w.id})));if(h)throw new Error(`Could not add products to the category: ${c(h)}`);u=p.length}}return{categoryId:s,created:!d,linkedProducts:u,mutationExecuted:!0,slug:a,success:!0}}const M=r.z.strictObject({});async function q(e,i){const t=f(i),{data:o,error:a}=await t.from("categories").select("id, name, slug, description, name_translations").order("name");if(a)throw new Error(`Could not read the categories: ${c(a)}`);return{categories:o??[],count:(o??[]).length,success:!0}}function P(e){return{list_media:m.tool({description:"Browse the media library: file names, alt text, dimensions, and media ids. Read-only. Call this BEFORE importing an image so you reuse what is already stored instead of creating a duplicate — the returned `id` can be passed anywhere a media id or image reference is accepted (feature_image_id, product images, an image block).",execute:i=>z(i,e),inputSchema:y,strict:!0}),list_product_categories:m.tool({description:"List the product categories, with their slugs and translated names. Read-only. Use before creating one so an existing category is reused, and to get ids for a product_grid block filtered by category.",execute:i=>q(i,e),inputSchema:M,strict:!0}),manage_language:m.tool({description:"Add or update a site language, so the CMS can hold content in that locale. Creating the language is the FIRST step of making a site multilingual — translate_page cannot target a locale that does not exist yet. Re-using a code updates that language; set is_default to change the site default.",execute:i=>I(i,e),inputSchema:x,strict:!0}),manage_product_category:m.tool({description:"Create, update, or delete a product category, and optionally set exactly which products belong to it by slug. Categories are what a product_grid block filters on, so create these before building a shop page that shows one section of the catalogue. Passing productSlugs REPLACES the category's membership.",execute:i=>L(i,e),inputSchema:_,strict:!0}),upload_media:m.tool({description:"Import an image from a public https URL into the media library and return its media id, without attaching it to anything. Useful when you want one asset reused across several places — otherwise passing the URL straight to create_cms_product `images` or a page/post `feature_image_id` imports it in the same call. Check list_media first to avoid duplicates.",execute:i=>$(i,e),inputSchema:b,strict:!0})}}exports.createCortexContentOpsTools=P;exports.executeListMedia=z;exports.executeListProductCategories=q;exports.executeManageLanguage=I;exports.executeManageProductCategory=L;exports.executeUploadMedia=$;exports.listMediaInputSchema=y;exports.listProductCategoriesInputSchema=M;exports.manageLanguageInputSchema=x;exports.manageProductCategoryInputSchema=_;exports.uploadMediaInputSchema=b;
1
+ require("./zod-config.cjs.js");let e=require("ai"),t=require("zod");var n=`id, file_name, object_key, file_type, width, height, description, folder, created_at`;function r(e){if(!e?.supabase)throw Error(`No database connection is available for this tool.`);return e.supabase}function i(e){return e?e instanceof Error?e.message:typeof e==`object`&&`message`in e?String(e.message):String(e):`unknown error`}function a(e){return e.normalize(`NFD`).replace(/\p{Diacritic}/gu,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)}var o=t.z.strictObject({limit:t.z.number().int().min(1).max(100).default(30),query:t.z.string().trim().max(120).optional().describe(`Filter on file name or alt text, e.g. "wormwood" or "laboratory".`)}),s=t.z.strictObject({altText:t.z.string().trim().max(300).optional().describe(`Alt text describing the image. Write real alt text — it is what screen readers announce and what search engines index.`),url:t.z.string().trim().min(1).max(2048).describe(`Public https URL of the image to bring into the media library.`)});async function c(e,t){let a=o.parse(e),s=r(t).from(`media`).select(n).order(`created_at`,{ascending:!1}).limit(a.limit);if(a.query){let e=`%${a.query}%`;s=s.or(`file_name.ilike.${e},description.ilike.${e}`)}let{data:c,error:l}=await s;if(l)throw Error(`Could not read the media library: ${i(l)}`);return{count:(c??[]).length,media:c??[],success:!0}}async function l(e,t){let n=s.parse(e),r=t?.importExternalImage;if(!r)throw Error(`Media import is not available on this connection.`);let i=await r({...n.altText?{altText:n.altText}:{},url:n.url});if(`error`in i)throw Error(`Could not import that image: ${i.error}`);return{mediaId:i.id,mutationExecuted:!0,success:!0}}var u=t.z.strictObject({code:t.z.string().trim().min(2).max(10).describe(`Locale code, e.g. "fr", "es", "de". Re-using an existing code updates that language.`),is_active:t.z.boolean().default(!0).describe(`Inactive languages are hidden from the public switcher.`),is_default:t.z.boolean().default(!1).describe(`Make this the site default. Only one language can be default; setting it clears the others.`),name:t.z.string().trim().min(1).max(80).describe(`Display name, e.g. "Français".`)});async function d(e,t){let n=u.parse(e),a=r(t),o=n.code.toLowerCase(),{data:s}=await a.from(`languages`).select(`id, code`).eq(`code`,o).maybeSingle(),c={code:o,is_active:n.is_active,name:n.name},l=s?.id;if(l){let{error:e}=await a.from(`languages`).update(c).eq(`id`,l);if(e)throw Error(`Could not update the "${o}" language: ${i(e)}`)}else{let{data:e,error:t}=await a.from(`languages`).insert(c).select(`id`).single();if(t||!e?.id)throw Error(`Could not create the "${o}" language: ${i(t)}`);l=e.id}if(n.is_default){let{error:e}=await a.from(`languages`).update({is_default:!1}).neq(`id`,l);if(e)throw Error(`Could not clear the previous default language: ${i(e)}`);let{error:t}=await a.from(`languages`).update({is_default:!0}).eq(`id`,l);if(t)throw Error(`Could not set the default language: ${i(t)}`)}try{t?.revalidatePath?.(`/`,`layout`)}catch{}return{code:o,created:!s,languageId:l,mutationExecuted:!0,success:!0}}var f=t.z.strictObject({action:t.z.enum([`upsert`,`delete`]).default(`upsert`),description:t.z.string().max(1e3).nullable().optional(),name:t.z.string().trim().min(1).max(120).describe(`Category name, e.g. "Digestive Health".`),name_translations:t.z.record(t.z.string(),t.z.string()).optional().describe(`Translated names keyed by locale code, e.g. { "fr": "Santé digestive" }.`),productSlugs:t.z.array(t.z.string().trim().min(1).max(300)).max(100).optional().describe(`Product slugs to place in this category. Replaces the category's current membership.`),slug:t.z.string().trim().min(1).max(120).optional().describe(`URL slug. Derived from the name when omitted. Re-using a slug updates that category.`)});async function p(e,t){let n=f.parse(e),o=r(t),s=n.slug?a(n.slug):a(n.name),{data:c}=await o.from(`categories`).select(`id, name, slug`).eq(`slug`,s).maybeSingle();if(n.action===`delete`){if(!c?.id)return{message:`No category with slug "${s}".`,mutationExecuted:!1,success:!1};let{error:e}=await o.from(`categories`).delete().eq(`id`,c.id);if(e)throw Error(`Could not delete the category: ${i(e)}`);return{action:`delete`,mutationExecuted:!0,slug:s,success:!0}}let l={name:n.name,slug:s,...n.description===void 0?{}:{description:n.description},...n.name_translations?{name_translations:n.name_translations}:{}},u=c?.id;if(u){let{error:e}=await o.from(`categories`).update(l).eq(`id`,u);if(e)throw Error(`Could not update the category: ${i(e)}`)}else{let{data:e,error:t}=await o.from(`categories`).insert(l).select(`id`).single();if(t||!e?.id)throw Error(`Could not create the category: ${i(t)}`);u=e.id}let d=0;if(n.productSlugs){let{data:e,error:t}=await o.from(`products`).select(`id, slug`).in(`slug`,n.productSlugs);if(t)throw Error(`Could not resolve those products: ${i(t)}`);let r=e??[],a=n.productSlugs.filter(e=>!r.some(t=>t.slug===e));if(a.length>0)throw Error(`No product found for slug(s): ${a.join(`, `)}.`);let{error:s}=await o.from(`product_categories`).delete().eq(`category_id`,u);if(s)throw Error(`Could not clear the category's products: ${i(s)}`);if(r.length>0){let{error:e}=await o.from(`product_categories`).insert(r.map(e=>({category_id:u,product_id:e.id})));if(e)throw Error(`Could not add products to the category: ${i(e)}`);d=r.length}}return{categoryId:u,created:!c,linkedProducts:d,mutationExecuted:!0,slug:s,success:!0}}var m=t.z.strictObject({});async function h(e,t){let{data:n,error:a}=await r(t).from(`categories`).select(`id, name, slug, description, name_translations`).order(`name`);if(a)throw Error(`Could not read the categories: ${i(a)}`);return{categories:n??[],count:(n??[]).length,success:!0}}function g(t){return{list_media:(0,e.tool)({description:"Browse the media library: file names, alt text, dimensions, and media ids. Read-only. Call this BEFORE importing an image so you reuse what is already stored instead of creating a duplicate — the returned `id` can be passed anywhere a media id or image reference is accepted (feature_image_id, product images, an image block).",execute:e=>c(e,t),inputSchema:o,strict:!0}),list_product_categories:(0,e.tool)({description:`List the product categories, with their slugs and translated names. Read-only. Use before creating one so an existing category is reused, and to get ids for a product_grid block filtered by category.`,execute:e=>h(e,t),inputSchema:m,strict:!0}),manage_language:(0,e.tool)({description:`Add or update a site language, so the CMS can hold content in that locale. Creating the language is the FIRST step of making a site multilingual — translate_page cannot target a locale that does not exist yet. Re-using a code updates that language; set is_default to change the site default.`,execute:e=>d(e,t),inputSchema:u,strict:!0}),manage_product_category:(0,e.tool)({description:`Create, update, or delete a product category, and optionally set exactly which products belong to it by slug. Categories are what a product_grid block filters on, so create these before building a shop page that shows one section of the catalogue. Passing productSlugs REPLACES the category's membership.`,execute:e=>p(e,t),inputSchema:f,strict:!0}),upload_media:(0,e.tool)({description:"Import an image from a public https URL into the media library and return its media id, without attaching it to anything. Useful when you want one asset reused across several places — otherwise passing the URL straight to create_cms_product `images` or a page/post `feature_image_id` imports it in the same call. Check list_media first to avoid duplicates.",execute:e=>l(e,t),inputSchema:s,strict:!0})}}exports.createCortexContentOpsTools=g,exports.executeListMedia=c,exports.executeListProductCategories=h,exports.executeManageLanguage=d,exports.executeManageProductCategory=p,exports.executeUploadMedia=l,exports.listMediaInputSchema=o,exports.listProductCategoriesInputSchema=m,exports.manageLanguageInputSchema=u,exports.manageProductCategoryInputSchema=f,exports.uploadMediaInputSchema=s;