@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=require("crypto");var t=`aes-256-gcm`,n=1;function r(t){let n=t.trim();if(!n)throw Error(`CORTEX_AI_ENCRYPTION_KEY is required to manage stored OpenRouter keys.`);return(0,e.createHash)(`sha256`).update(n).digest()}function i(e){if(!e||typeof e!=`object`)throw Error(`Invalid encrypted OpenRouter key payload.`);let t=e;if(t.algorithm!==`aes-256-gcm`||t.version!==1||typeof t.authTag!=`string`||typeof t.ciphertext!=`string`||typeof t.iv!=`string`)throw Error(`Invalid encrypted OpenRouter key payload.`);return{algorithm:t.algorithm,authTag:t.authTag,ciphertext:t.ciphertext,iv:t.iv,last4:typeof t.last4==`string`?t.last4:``,updatedAt:typeof t.updatedAt==`string`?t.updatedAt:``,version:t.version}}function a(e){let t=(e||``).trim();return t?`**** ${t}`:`Stored key`}function o(n){let i=n.apiKey.trim();if(!i)throw Error(`OpenRouter API key is required.`);let a=r(n.encryptionSecret),o=(0,e.randomBytes)(12),s=(0,e.createCipheriv)(t,a,o),c=Buffer.concat([s.update(i,`utf8`),s.final()]);return{algorithm:t,authTag:s.getAuthTag().toString(`base64`),ciphertext:c.toString(`base64`),iv:o.toString(`base64`),last4:i.slice(-4),updatedAt:(n.now||new Date).toISOString(),version:1}}function s(n){let a=i(n.encryptedKey),o=r(n.encryptionSecret);try{let n=(0,e.createDecipheriv)(t,o,Buffer.from(a.iv,`base64`));return n.setAuthTag(Buffer.from(a.authTag,`base64`)),Buffer.concat([n.update(Buffer.from(a.ciphertext,`base64`)),n.final()]).toString(`utf8`)}catch{throw Error(`Failed to decrypt stored OpenRouter key.`)}}function c(e){try{let t=i(e);return{hasStoredKey:!0,last4:t.last4||null,maskedKey:a(t.last4),updatedAt:t.updatedAt||null}}catch{return{hasStoredKey:!1,last4:null,maskedKey:null,updatedAt:null}}}exports.CORTEX_AI_KEY_ALGORITHM=t,exports.CORTEX_AI_KEY_ENVELOPE_VERSION=n,exports.decryptOpenRouterApiKey=s,exports.encryptOpenRouterApiKey=o,exports.getMaskedOpenRouterKey=a,exports.getOpenRouterKeyEnvelopeStatus=c;
|
package/lib/ai-key-crypto.es.js
CHANGED
|
@@ -1,88 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { createCipheriv as e, createDecipheriv as t, createHash as n, randomBytes as r } from "crypto";
|
|
2
|
+
//#region src/lib/ai-key-crypto.ts
|
|
3
|
+
var i = "aes-256-gcm", a = 1;
|
|
4
|
+
function o(e) {
|
|
5
|
+
let t = e.trim();
|
|
6
|
+
if (!t) throw Error("CORTEX_AI_ENCRYPTION_KEY is required to manage stored OpenRouter keys.");
|
|
7
|
+
return n("sha256").update(t).digest();
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
version: e.version
|
|
23
|
-
};
|
|
9
|
+
function s(e) {
|
|
10
|
+
if (!e || typeof e != "object") throw Error("Invalid encrypted OpenRouter key payload.");
|
|
11
|
+
let t = e;
|
|
12
|
+
if (t.algorithm !== "aes-256-gcm" || t.version !== 1 || typeof t.authTag != "string" || typeof t.ciphertext != "string" || typeof t.iv != "string") throw Error("Invalid encrypted OpenRouter key payload.");
|
|
13
|
+
return {
|
|
14
|
+
algorithm: t.algorithm,
|
|
15
|
+
authTag: t.authTag,
|
|
16
|
+
ciphertext: t.ciphertext,
|
|
17
|
+
iv: t.iv,
|
|
18
|
+
last4: typeof t.last4 == "string" ? t.last4 : "",
|
|
19
|
+
updatedAt: typeof t.updatedAt == "string" ? t.updatedAt : "",
|
|
20
|
+
version: t.version
|
|
21
|
+
};
|
|
24
22
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
function c(e) {
|
|
24
|
+
let t = (e || "").trim();
|
|
25
|
+
return t ? `**** ${t}` : "Stored key";
|
|
28
26
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
last4: e.slice(-4),
|
|
43
|
-
updatedAt: (t.now || /* @__PURE__ */ new Date()).toISOString(),
|
|
44
|
-
version: i
|
|
45
|
-
};
|
|
27
|
+
function l(t) {
|
|
28
|
+
let n = t.apiKey.trim();
|
|
29
|
+
if (!n) throw Error("OpenRouter API key is required.");
|
|
30
|
+
let a = o(t.encryptionSecret), s = r(12), c = e(i, a, s), l = Buffer.concat([c.update(n, "utf8"), c.final()]);
|
|
31
|
+
return {
|
|
32
|
+
algorithm: i,
|
|
33
|
+
authTag: c.getAuthTag().toString("base64"),
|
|
34
|
+
ciphertext: l.toString("base64"),
|
|
35
|
+
iv: s.toString("base64"),
|
|
36
|
+
last4: n.slice(-4),
|
|
37
|
+
updatedAt: (t.now || /* @__PURE__ */ new Date()).toISOString(),
|
|
38
|
+
version: 1
|
|
39
|
+
};
|
|
46
40
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return r.setAuthTag(Buffer.from(e.authTag, "base64")), Buffer.concat([
|
|
56
|
-
r.update(Buffer.from(e.ciphertext, "base64")),
|
|
57
|
-
r.final()
|
|
58
|
-
]).toString("utf8");
|
|
59
|
-
} catch {
|
|
60
|
-
throw new Error("Failed to decrypt stored OpenRouter key.");
|
|
61
|
-
}
|
|
41
|
+
function u(e) {
|
|
42
|
+
let n = s(e.encryptedKey), r = o(e.encryptionSecret);
|
|
43
|
+
try {
|
|
44
|
+
let e = t(i, r, Buffer.from(n.iv, "base64"));
|
|
45
|
+
return e.setAuthTag(Buffer.from(n.authTag, "base64")), Buffer.concat([e.update(Buffer.from(n.ciphertext, "base64")), e.final()]).toString("utf8");
|
|
46
|
+
} catch {
|
|
47
|
+
throw Error("Failed to decrypt stored OpenRouter key.");
|
|
48
|
+
}
|
|
62
49
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
50
|
+
function d(e) {
|
|
51
|
+
try {
|
|
52
|
+
let t = s(e);
|
|
53
|
+
return {
|
|
54
|
+
hasStoredKey: !0,
|
|
55
|
+
last4: t.last4 || null,
|
|
56
|
+
maskedKey: c(t.last4),
|
|
57
|
+
updatedAt: t.updatedAt || null
|
|
58
|
+
};
|
|
59
|
+
} catch {
|
|
60
|
+
return {
|
|
61
|
+
hasStoredKey: !1,
|
|
62
|
+
last4: null,
|
|
63
|
+
maskedKey: null,
|
|
64
|
+
updatedAt: null
|
|
65
|
+
};
|
|
66
|
+
}
|
|
80
67
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
i as CORTEX_AI_KEY_ENVELOPE_VERSION,
|
|
84
|
-
m as decryptOpenRouterApiKey,
|
|
85
|
-
E as encryptOpenRouterApiKey,
|
|
86
|
-
h as getMaskedOpenRouterKey,
|
|
87
|
-
v as getOpenRouterKeyEnvelopeStatus
|
|
88
|
-
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { i as CORTEX_AI_KEY_ALGORITHM, a as CORTEX_AI_KEY_ENVELOPE_VERSION, u as decryptOpenRouterApiKey, l as encryptOpenRouterApiKey, c as getMaskedOpenRouterKey, d as getOpenRouterKeyEnvelopeStatus };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
async function e(e,t,n){let r=new AbortController,i=setTimeout(()=>r.abort(),1e4);try{let i=await e(t,{cache:`no-store`,headers:{Accept:`application/json`,...n},signal:r.signal});return{body:await i.json().catch(()=>null),status:i.status}}catch(e){return{failed:e instanceof Error&&e.name===`AbortError`?`The provider did not answer within 10 seconds.`:e instanceof Error?e.message:`The provider could not be reached.`}}finally{clearTimeout(i)}}function t(e,t){return{message:`${e} could not be reached to check the key (${t}). Check the connection and try again.`,ok:!1,reason:`unreachable`}}function n(e){return{message:e,ok:!1,reason:`invalid`}}async function r(r){let i=r.apiKey.trim();if(!i)return n(`Enter an OpenRouter API key.`);if(!i.startsWith(`sk-or-`))return n(`That does not look like an OpenRouter key: they start with "sk-or-".`);let a=await e(r.fetch||globalThis.fetch,`https://openrouter.ai/api/v1/auth/key`,{Authorization:`Bearer ${i}`});if(`failed`in a)return t(`OpenRouter`,a.failed);if(a.status===401||a.status===403)return n(`OpenRouter rejected this key. Copy it again from openrouter.ai/keys.`);if(a.status<200||a.status>=300)return t(`OpenRouter`,`HTTP ${a.status}`);let o=a.body&&typeof a.body==`object`&&`data`in a.body?a.body.data:void 0,s=typeof o?.label==`string`?o.label.trim():``,c=o?.is_free_tier===!0,l=typeof o?.limit_remaining==`number`?o.limit_remaining:null,u=[];return s&&u.push(`key "${s}"`),c?u.push(`free tier: only free models until you add credits`):l!==null&&u.push(`$${l.toFixed(2)} of credit left`),{detail:u.length>0?u.join(` · `):null,isFreeTier:o?c:null,ok:!0}}async function i(r){let i=r.apiKey.trim();if(!i)return n(`Enter a Pexels API key.`);let a=await e(r.fetch||globalThis.fetch,`https://api.pexels.com/v1/curated?per_page=1`,{Authorization:i});return`failed`in a?t(`Pexels`,a.failed):a.status===401||a.status===403?n(`Pexels rejected this key. Copy it again from pexels.com/api.`):a.status===429?{detail:`Pexels accepted the key (its hourly quota is currently exhausted).`,isFreeTier:null,ok:!0}:a.status<200||a.status>=300?t(`Pexels`,`HTTP ${a.status}`):{detail:null,isFreeTier:null,ok:!0}}async function a(r){let i=r.accessKey.trim();if(!i)return n(`Enter an Unsplash access key.`);let a=await e(r.fetch||globalThis.fetch,`https://api.unsplash.com/photos?per_page=1`,{Authorization:`Client-ID ${i}`});return`failed`in a?t(`Unsplash`,a.failed):a.status===401?n(`Unsplash rejected this key. Use the Access Key (not the Secret Key) from unsplash.com/developers.`):a.status===403||a.status===429?{detail:`Unsplash accepted the key (its demo quota is currently exhausted).`,isFreeTier:null,ok:!0}:a.status<200||a.status>=300?t(`Unsplash`,`HTTP ${a.status}`):{detail:null,isFreeTier:null,ok:!0}}exports.verifyOpenRouterApiKey=r,exports.verifyPexelsApiKey=i,exports.verifyUnsplashAccessKey=a;
|
|
@@ -1,69 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
async function e(e, t, n) {
|
|
2
|
+
let r = new AbortController(), i = setTimeout(() => r.abort(), 1e4);
|
|
3
|
+
try {
|
|
4
|
+
let i = await e(t, {
|
|
5
|
+
cache: "no-store",
|
|
6
|
+
headers: {
|
|
7
|
+
Accept: "application/json",
|
|
8
|
+
...n
|
|
9
|
+
},
|
|
10
|
+
signal: r.signal
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
body: await i.json().catch(() => null),
|
|
14
|
+
status: i.status
|
|
15
|
+
};
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return { failed: e instanceof Error && e.name === "AbortError" ? "The provider did not answer within 10 seconds." : e instanceof Error ? e.message : "The provider could not be reached." };
|
|
18
|
+
} finally {
|
|
19
|
+
clearTimeout(i);
|
|
20
|
+
}
|
|
18
21
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
function t(e, t) {
|
|
23
|
+
return {
|
|
24
|
+
message: `${e} could not be reached to check the key (${t}). Check the connection and try again.`,
|
|
25
|
+
ok: !1,
|
|
26
|
+
reason: "unreachable"
|
|
27
|
+
};
|
|
25
28
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
29
|
+
function n(e) {
|
|
30
|
+
return {
|
|
31
|
+
message: e,
|
|
32
|
+
ok: !1,
|
|
33
|
+
reason: "invalid"
|
|
34
|
+
};
|
|
28
35
|
}
|
|
29
|
-
async function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return a("OpenRouter", `HTTP ${e.status}`);
|
|
44
|
-
const n = e.body && typeof e.body == "object" && "data" in e.body ? e.body.data : void 0, u = typeof n?.label == "string" ? n.label.trim() : "", r = n?.is_free_tier === !0, l = typeof n?.limit_remaining == "number" ? n.limit_remaining : null, o = [];
|
|
45
|
-
return u && o.push(`key "${u}"`), r ? o.push("free tier: only free models until you add credits") : l !== null && o.push(`$${l.toFixed(2)} of credit left`), { detail: o.length > 0 ? o.join(" · ") : null, isFreeTier: n ? r : null, ok: !0 };
|
|
36
|
+
async function r(r) {
|
|
37
|
+
let i = r.apiKey.trim();
|
|
38
|
+
if (!i) return n("Enter an OpenRouter API key.");
|
|
39
|
+
if (!i.startsWith("sk-or-")) return n("That does not look like an OpenRouter key: they start with \"sk-or-\".");
|
|
40
|
+
let a = await e(r.fetch || globalThis.fetch, "https://openrouter.ai/api/v1/auth/key", { Authorization: `Bearer ${i}` });
|
|
41
|
+
if ("failed" in a) return t("OpenRouter", a.failed);
|
|
42
|
+
if (a.status === 401 || a.status === 403) return n("OpenRouter rejected this key. Copy it again from openrouter.ai/keys.");
|
|
43
|
+
if (a.status < 200 || a.status >= 300) return t("OpenRouter", `HTTP ${a.status}`);
|
|
44
|
+
let o = a.body && typeof a.body == "object" && "data" in a.body ? a.body.data : void 0, s = typeof o?.label == "string" ? o.label.trim() : "", c = o?.is_free_tier === !0, l = typeof o?.limit_remaining == "number" ? o.limit_remaining : null, u = [];
|
|
45
|
+
return s && u.push(`key "${s}"`), c ? u.push("free tier: only free models until you add credits") : l !== null && u.push(`$${l.toFixed(2)} of credit left`), {
|
|
46
|
+
detail: u.length > 0 ? u.join(" · ") : null,
|
|
47
|
+
isFreeTier: o ? c : null,
|
|
48
|
+
ok: !0
|
|
49
|
+
};
|
|
46
50
|
}
|
|
47
|
-
async function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
async function i(r) {
|
|
52
|
+
let i = r.apiKey.trim();
|
|
53
|
+
if (!i) return n("Enter a Pexels API key.");
|
|
54
|
+
let a = await e(r.fetch || globalThis.fetch, "https://api.pexels.com/v1/curated?per_page=1", { Authorization: i });
|
|
55
|
+
return "failed" in a ? t("Pexels", a.failed) : a.status === 401 || a.status === 403 ? n("Pexels rejected this key. Copy it again from pexels.com/api.") : a.status === 429 ? {
|
|
56
|
+
detail: "Pexels accepted the key (its hourly quota is currently exhausted).",
|
|
57
|
+
isFreeTier: null,
|
|
58
|
+
ok: !0
|
|
59
|
+
} : a.status < 200 || a.status >= 300 ? t("Pexels", `HTTP ${a.status}`) : {
|
|
60
|
+
detail: null,
|
|
61
|
+
isFreeTier: null,
|
|
62
|
+
ok: !0
|
|
63
|
+
};
|
|
55
64
|
}
|
|
56
|
-
async function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
async function a(r) {
|
|
66
|
+
let i = r.accessKey.trim();
|
|
67
|
+
if (!i) return n("Enter an Unsplash access key.");
|
|
68
|
+
let a = await e(r.fetch || globalThis.fetch, "https://api.unsplash.com/photos?per_page=1", { Authorization: `Client-ID ${i}` });
|
|
69
|
+
return "failed" in a ? t("Unsplash", a.failed) : a.status === 401 ? n("Unsplash rejected this key. Use the Access Key (not the Secret Key) from unsplash.com/developers.") : a.status === 403 || a.status === 429 ? {
|
|
70
|
+
detail: "Unsplash accepted the key (its demo quota is currently exhausted).",
|
|
71
|
+
isFreeTier: null,
|
|
72
|
+
ok: !0
|
|
73
|
+
} : a.status < 200 || a.status >= 300 ? t("Unsplash", `HTTP ${a.status}`) : {
|
|
74
|
+
detail: null,
|
|
75
|
+
isFreeTier: null,
|
|
76
|
+
ok: !0
|
|
77
|
+
};
|
|
64
78
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
y as verifyPexelsApiKey,
|
|
68
|
-
k as verifyUnsplashAccessKey
|
|
69
|
-
};
|
|
79
|
+
//#endregion
|
|
80
|
+
export { r as verifyOpenRouterApiKey, i as verifyPexelsApiKey, a as verifyUnsplashAccessKey };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./ai-model-registry.cjs");var t=`Cortex AI OpenRouter model catalog can only be imported from server-side code.`;function n(){if(typeof window<`u`)throw Error(t)}function r(){let t=new URL(`${e.CORTEX_AI_OPENROUTER_BASE_URL}/models`);return t.searchParams.set(`supported_parameters`,e.CORTEX_AI_REQUIRED_MODEL_PARAMETERS.join(`,`)),t.searchParams.set(`output_modalities`,`text`),t.toString()}async function i(t){n();let i=await(t?.fetch||globalThis.fetch)(r(),{cache:`no-store`,headers:{Accept:`application/json`}});if(!i.ok)throw Error(`Failed to load OpenRouter models: ${i.status} ${i.statusText}`);return e.filterCortexAiCompatibleOpenRouterModels(await i.json(),t?.now)}exports.listCortexAiCompatibleOpenRouterModels=i;
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (!(typeof window > "u"))
|
|
5
|
-
throw new Error(s);
|
|
6
|
-
}
|
|
1
|
+
import { CORTEX_AI_OPENROUTER_BASE_URL as e, CORTEX_AI_REQUIRED_MODEL_PARAMETERS as t, filterCortexAiCompatibleOpenRouterModels as n } from "./ai-model-registry.es.js";
|
|
2
|
+
//#region src/lib/ai-model-catalog.ts
|
|
3
|
+
var r = "Cortex AI OpenRouter model catalog can only be imported from server-side code.";
|
|
7
4
|
function i() {
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
if (typeof window < "u") throw Error(r);
|
|
6
|
+
}
|
|
7
|
+
function a() {
|
|
8
|
+
let n = new URL(`${e}/models`);
|
|
9
|
+
return n.searchParams.set("supported_parameters", t.join(",")), n.searchParams.set("output_modalities", "text"), n.toString();
|
|
10
10
|
}
|
|
11
|
-
async function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!t.ok)
|
|
20
|
-
throw new Error(`Failed to load OpenRouter models: ${t.status} ${t.statusText}`);
|
|
21
|
-
return o(await t.json(), e?.now);
|
|
11
|
+
async function o(e) {
|
|
12
|
+
i();
|
|
13
|
+
let t = await (e?.fetch || globalThis.fetch)(a(), {
|
|
14
|
+
cache: "no-store",
|
|
15
|
+
headers: { Accept: "application/json" }
|
|
16
|
+
});
|
|
17
|
+
if (!t.ok) throw Error(`Failed to load OpenRouter models: ${t.status} ${t.statusText}`);
|
|
18
|
+
return n(await t.json(), e?.now);
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { o as listCortexAiCompatibleOpenRouterModels };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
let e=require("ai");var t=`https://openrouter.ai/api/v1`,n=`openrouter/free`,r=[`nvidia/nemotron-3-super-120b-a12b:free`,`nvidia/nemotron-3-ultra-550b-a55b:free`,`thinkingmachines/inkling:free`,`nex-agi/nex-n2.5-pro:free`,`poolside/laguna-s-2.1:free`,`thinkingmachines/inkling-small:free`,`inclusionai/ling-3.0-flash-vl:free`],i=[`tools`,`structured_outputs`],a={frequencyPenalty:`frequency_penalty`,logitBias:`logit_bias`,presencePenalty:`presence_penalty`,seed:`seed`,stopSequences:`stop`,temperature:`temperature`,topK:`top_k`,topP:`top_p`},o={defaultFreeRouter:n,defaultStructuredOutputModel:r[0],defaultToolCallingModel:r[0],freeFallbacks:r,structuredJsonPreferred:r,toolCallingPreferred:r},s=class extends Error{attempts;constructor(e,t,n){super(e),this.name=`CortexAiRoutingError`,this.attempts=t,this.cause=n}};function c(e){return Array.from(new Set(e.filter(Boolean)))}function l(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:null}function u(e){return typeof e==`string`&&e.trim()?e.trim():null}function d(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&e.trim().length>0):[]}function f(e){let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?t:null}function p(e){let t=l(e);return t?Object.fromEntries(Object.entries(t).filter(([,e])=>e!=null).map(([e,t])=>[e,String(t)])):{}}function m(e){let t=new Set(e);return i.every(e=>t.has(e))}function h(e){return d(l(e.architecture)?.output_modalities).includes(`text`)}function g(e){if(e==null)return null;if(typeof e==`number`)return e>1e10?e:e*1e3;if(typeof e==`string`&&e.trim()){let t=Date.parse(e);return Number.isFinite(t)?t:null}return null}function _(e,t){let n=g(e);return n!==null&&n<=t.getTime()}function v(e){let t=l(e.top_provider);return f(e.context_length)??f(e.contextLength)??f(t?.context_length)??null}function y(e){let t=e.expiration_date??e.expirationDate;return typeof t==`string`&&t.trim()?t.trim():null}function b(e){return!!(e&&r.includes(e))}function x(e){let t=l(e);if(!t)return null;let n=u(t.modelId),r=u(t.name),i=d(t.supportedParameters),a=u(t.updatedAt);return!n||!r||!a||!m(i)?null:{contextLength:f(t.contextLength),modelId:n,name:r,pricing:p(t.pricing),supportedParameters:i,updatedAt:a}}function S(e,t=new Date){return{contextLength:e.contextLength,modelId:e.id,name:e.name,pricing:e.pricing,supportedParameters:[...e.supportedParameters],updatedAt:t.toISOString()}}function C(e,t=new Date){let n=l(e),r=Array.isArray(e)?e:Array.isArray(n?.data)?n.data:[],i=[];for(let e of r){let n=l(e),r=u(n?.id),a=u(n?.name),o=d(n?.supported_parameters);n&&r&&a&&h(n)&&!_(n.expiration_date,t)&&m(o)&&i.push({contextLength:v(n),created:f(n.created),expirationDate:y(n),id:r,name:a,pricing:p(n.pricing),supportedParameters:o})}return i.sort((e,t)=>e.name.localeCompare(t.name))}function w(e){return c([e?.modelId||r[0],...e?.fallbackModelIds||r])}function T(e){let t=e.requestedModelId?.trim()||null;if(e.credentialSource===`env`)return{credentialSource:e.credentialSource,ignoredRequestedModelId:t&&!b(t)?t:null,modelIds:[...r],modelSelection:null};let n=c(e.fallbackModelIds?.length?e.fallbackModelIds:r),i=e.credentialSource===`stored`?e.selectedModel?.modelId||n[0]:t||e.selectedModel?.modelId||n[0];return{credentialSource:e.credentialSource,ignoredRequestedModelId:e.credentialSource===`stored`&&t&&t!==i?t:null,modelIds:c([i,...n]),modelSelection:e.selectedModel||null}}function E(e,t){let n=t.modelSelection;if(!n||n.modelId!==t.modelId)return e;let r=new Set(n.supportedParameters),i=Object.entries(a).filter(([t,n])=>t in e&&!r.has(n)).map(([e])=>e);if(i.length===0)return e;let o={...e};for(let e of i)delete o[e];return o}function D(e,t){if(!e||typeof e!=`object`||!(t in e))return null;let n=e[t],r=typeof n==`number`?n:Number(n);return Number.isFinite(r)?r:null}function O(t){if(e.APICallError.isInstance(t))return t.statusCode??null;let n=D(t,`statusCode`)??D(t,`status`);if(n)return n;if(t&&typeof t==`object`&&`response`in t){let e=t.response,n=D(e,`status`);if(n)return n}return t&&typeof t==`object`&&`cause`in t?O(t.cause):null}function k(e){return e!==null&&Number.isInteger(e)&&e>=100&&e<=599}function A(e){if(typeof e!=`string`||!e.trim().startsWith(`{`))return null;try{return l(JSON.parse(e))}catch{return null}}function j(e,t=0){let n=l(e);if(!n||t>8)return null;let r=[n,l(n.data),A(n.responseBody),A(n.text)];for(let e of r){let t=l(e?.error),n=D(t,`code`)??D(t,`status`);if(k(n))return n}return j(n.cause,t+1)}function M(e){let t=O(e);return k(t)?t:j(e)}function N(e){return M(e)===429}var P=[`message`,`error`,`text`,`responseBody`,`data`,`cause`];function F(e,t=0){if(!e||t>8)return``;if(typeof e!=`object`)return String(e);let n=e,r=e instanceof Error?[e.message]:[];for(let i of P)i===`message`&&e instanceof Error||r.push(F(n[i],t+1));return Array.from(new Set(r.filter(Boolean))).join(`
|
|
2
|
+
`)}var I=/No endpoints found|no longer available|not available as a free model|transitioned to a paid model|unavailable for free|paid version is available|is not a valid model ID/i,L=/not found|does not exist|unknown model|no such model/i;function R(e){let t=M(e);if(t===429||t===404)return!0;let n=F(e);return I.test(n)?!0:t===400&&L.test(n)}function z(e,t=900){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1).trimEnd()}...`:n}function B(e){let t=F(e);return t?z(t):`Unknown OpenRouter error.`}function V(e,t=`Cortex AI request failed.`){if(e instanceof s){let t=e.attempts.map(e=>e.errorMessage).filter(e=>!!e?.trim()),n=t[0],r=t[t.length-1],i=z(F(e.cause));return n&&r&&n!==r?`First model error: ${n} Last model error: ${r}`:r||n||i||e.message}return z(F(e))||t}async function H(e){let t=c(e.modelIds),n=e.shouldRetry||R,r=[],i=null;for(let a of t)try{let t=await e.execute(a);return r=[...r,{modelId:a,rateLimited:!1,status:`success`}],{attempts:r,modelId:a,result:t}}catch(e){let t=N(e),o=n(e);if(i=e,r=[...r,{errorMessage:B(e),modelId:a,rateLimited:t,status:t?`rate_limited`:o?`retried`:`failed`}],!o)throw new s(`OpenRouter request failed for model "${a}".`,r,e)}throw new s(`OpenRouter fallback exhausted all configured Cortex AI models.`,r,i)}exports.CORTEX_AI_FREE_MODEL_FALLBACK_REGISTRY=r,exports.CORTEX_AI_MODEL_REGISTRY=o,exports.CORTEX_AI_OPENROUTER_BASE_URL=t,exports.CORTEX_AI_OPENROUTER_FREE_ROUTER_MODEL=n,exports.CORTEX_AI_REQUIRED_MODEL_PARAMETERS=i,exports.CortexAiRoutingError=s,exports.buildCortexAiModelFallbackChain=w,exports.buildCortexAiRoutingPolicy=T,exports.createCortexAiStoredModelSelection=S,exports.filterCortexAiCompatibleOpenRouterModels=C,exports.getHttpStatusCode=O,exports.getOpenRouterErrorStatus=M,exports.isCortexAiFreeModelId=b,exports.isOpenRouterRateLimitError=N,exports.isOpenRouterRecoverableRoutingError=R,exports.omitUnsupportedCortexAiModelOptions=E,exports.runWithCortexAiModelFallback=H,exports.safeParseCortexAiModelSelection=x,exports.summarizeCortexAiRoutingError=V;
|