@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
package/lib/ai-config.es.js
CHANGED
|
@@ -1,123 +1,104 @@
|
|
|
1
|
-
import { encryptOpenRouterApiKey as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
45
|
-
|
|
51
|
+
function x(e) {
|
|
52
|
+
return process.env[e]?.trim() || null;
|
|
46
53
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
54
|
+
function S() {
|
|
55
|
+
return s(), x("PEXELS_API_KEY");
|
|
49
56
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
57
|
+
function C() {
|
|
58
|
+
return s(), x("UNSPLASH_ACCESS_KEY");
|
|
52
59
|
}
|
|
53
|
-
function
|
|
54
|
-
|
|
60
|
+
function w() {
|
|
61
|
+
return s(), x("OPENROUTER_API_KEY");
|
|
55
62
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
function D(t) {
|
|
81
|
+
return e({
|
|
82
|
+
apiKey: t,
|
|
83
|
+
encryptionSecret: E()
|
|
84
|
+
});
|
|
83
85
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
|
92
|
-
|
|
92
|
+
function k(e) {
|
|
93
|
+
return n(e);
|
|
93
94
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
103
|
-
|
|
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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./ai-model-registry.cjs"),t=require("./ai-client.cjs"),n=require("./cortex-widget-schema.cjs");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 {
|
|
2
|
-
import { createCortexAiOpenRouterClient as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { p as generateCortexWidgetDefinition };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./zod-config.cjs");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;
|