@nextblock-cms/cortex 0.18.0 → 0.18.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=1e4,h="https://openrouter.ai/api/v1/auth/key",y="https://api.pexels.com/v1/curated?per_page=1",p="https://api.unsplash.com/photos?per_page=1";async function c(t,s,e){const n=new AbortController,u=setTimeout(()=>n.abort(),f);try{const r=await t(s,{cache:"no-store",headers:{Accept:"application/json",...e},signal:n.signal});return{body:await r.json().catch(()=>null),status:r.status}}catch(r){return{failed:r instanceof Error&&r.name==="AbortError"?"The provider did not answer within 10 seconds.":r instanceof Error?r.message:"The provider could not be reached."}}finally{clearTimeout(u)}}function a(t,s){return{message:`${t} could not be reached to check the key (${s}). Check the connection and try again.`,ok:!1,reason:"unreachable"}}function i(t){return{message:t,ok:!1,reason:"invalid"}}async function d(t){const s=t.apiKey.trim();if(!s)return i("Enter an OpenRouter API key.");if(!s.startsWith("sk-or-"))return i('That does not look like an OpenRouter key: they start with "sk-or-".');const e=await c(t.fetch||globalThis.fetch,h,{Authorization:`Bearer ${s}`});if("failed"in e)return a("OpenRouter",e.failed);if(e.status===401||e.status===403)return i("OpenRouter rejected this key. Copy it again from openrouter.ai/keys.");if(e.status<200||e.status>=300)return a("OpenRouter",`HTTP ${e.status}`);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=[];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,ok:!0}}async function k(t){const s=t.apiKey.trim();if(!s)return i("Enter a Pexels API key.");const e=await c(t.fetch||globalThis.fetch,y,{Authorization:s});return"failed"in e?a("Pexels",e.failed):e.status===401||e.status===403?i("Pexels rejected this key. Copy it again from pexels.com/api."):e.status===429?{detail:"Pexels accepted the key (its hourly quota is currently exhausted).",ok:!0}:e.status<200||e.status>=300?a("Pexels",`HTTP ${e.status}`):{detail:null,ok:!0}}async function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=1e4,h="https://openrouter.ai/api/v1/auth/key",y="https://api.pexels.com/v1/curated?per_page=1",p="https://api.unsplash.com/photos?per_page=1";async function c(t,s,e){const n=new AbortController,u=setTimeout(()=>n.abort(),f);try{const r=await t(s,{cache:"no-store",headers:{Accept:"application/json",...e},signal:n.signal});return{body:await r.json().catch(()=>null),status:r.status}}catch(r){return{failed:r instanceof Error&&r.name==="AbortError"?"The provider did not answer within 10 seconds.":r instanceof Error?r.message:"The provider could not be reached."}}finally{clearTimeout(u)}}function a(t,s){return{message:`${t} could not be reached to check the key (${s}). Check the connection and try again.`,ok:!1,reason:"unreachable"}}function i(t){return{message:t,ok:!1,reason:"invalid"}}async function d(t){const s=t.apiKey.trim();if(!s)return i("Enter an OpenRouter API key.");if(!s.startsWith("sk-or-"))return i('That does not look like an OpenRouter key: they start with "sk-or-".');const e=await c(t.fetch||globalThis.fetch,h,{Authorization:`Bearer ${s}`});if("failed"in e)return a("OpenRouter",e.failed);if(e.status===401||e.status===403)return i("OpenRouter rejected this key. Copy it again from openrouter.ai/keys.");if(e.status<200||e.status>=300)return a("OpenRouter",`HTTP ${e.status}`);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=[];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}}async function k(t){const s=t.apiKey.trim();if(!s)return i("Enter a Pexels API key.");const e=await c(t.fetch||globalThis.fetch,y,{Authorization:s});return"failed"in e?a("Pexels",e.failed):e.status===401||e.status===403?i("Pexels rejected this key. Copy it again from pexels.com/api."):e.status===429?{detail:"Pexels accepted the key (its hourly quota is currently exhausted).",isFreeTier:null,ok:!0}:e.status<200||e.status>=300?a("Pexels",`HTTP ${e.status}`):{detail:null,isFreeTier:null,ok:!0}}async function T(t){const s=t.accessKey.trim();if(!s)return i("Enter an Unsplash access key.");const e=await c(t.fetch||globalThis.fetch,p,{Authorization:`Client-ID ${s}`});return"failed"in e?a("Unsplash",e.failed):e.status===401?i("Unsplash rejected this key. Use the Access Key (not the Secret Key) from unsplash.com/developers."):e.status===403||e.status===429?{detail:"Unsplash accepted the key (its demo quota is currently exhausted).",isFreeTier:null,ok:!0}:e.status<200||e.status>=300?a("Unsplash",`HTTP ${e.status}`):{detail:null,isFreeTier:null,ok:!0}}exports.verifyOpenRouterApiKey=d;exports.verifyPexelsApiKey=k;exports.verifyUnsplashAccessKey=T;
|
|
@@ -16,51 +16,51 @@ async function c(t, s, e) {
|
|
|
16
16
|
clearTimeout(u);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function a(t, s) {
|
|
20
20
|
return {
|
|
21
21
|
message: `${t} could not be reached to check the key (${s}). Check the connection and try again.`,
|
|
22
22
|
ok: !1,
|
|
23
23
|
reason: "unreachable"
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function i(t) {
|
|
27
27
|
return { message: t, ok: !1, reason: "invalid" };
|
|
28
28
|
}
|
|
29
29
|
async function p(t) {
|
|
30
30
|
const s = t.apiKey.trim();
|
|
31
31
|
if (!s)
|
|
32
|
-
return
|
|
32
|
+
return i("Enter an OpenRouter API key.");
|
|
33
33
|
if (!s.startsWith("sk-or-"))
|
|
34
|
-
return
|
|
34
|
+
return i('That does not look like an OpenRouter key: they start with "sk-or-".');
|
|
35
35
|
const e = await c(t.fetch || globalThis.fetch, h, {
|
|
36
36
|
Authorization: `Bearer ${s}`
|
|
37
37
|
});
|
|
38
38
|
if ("failed" in e)
|
|
39
|
-
return
|
|
39
|
+
return a("OpenRouter", e.failed);
|
|
40
40
|
if (e.status === 401 || e.status === 403)
|
|
41
|
-
return
|
|
41
|
+
return i("OpenRouter rejected this key. Copy it again from openrouter.ai/keys.");
|
|
42
42
|
if (e.status < 200 || e.status >= 300)
|
|
43
|
-
return
|
|
43
|
+
return a("OpenRouter", `HTTP ${e.status}`);
|
|
44
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, ok: !0 };
|
|
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 };
|
|
46
46
|
}
|
|
47
47
|
async function y(t) {
|
|
48
48
|
const s = t.apiKey.trim();
|
|
49
49
|
if (!s)
|
|
50
|
-
return
|
|
50
|
+
return i("Enter a Pexels API key.");
|
|
51
51
|
const e = await c(t.fetch || globalThis.fetch, f, {
|
|
52
52
|
Authorization: s
|
|
53
53
|
});
|
|
54
|
-
return "failed" in e ?
|
|
54
|
+
return "failed" in e ? a("Pexels", e.failed) : e.status === 401 || e.status === 403 ? i("Pexels rejected this key. Copy it again from pexels.com/api.") : e.status === 429 ? { detail: "Pexels accepted the key (its hourly quota is currently exhausted).", isFreeTier: null, ok: !0 } : e.status < 200 || e.status >= 300 ? a("Pexels", `HTTP ${e.status}`) : { detail: null, isFreeTier: null, ok: !0 };
|
|
55
55
|
}
|
|
56
56
|
async function k(t) {
|
|
57
57
|
const s = t.accessKey.trim();
|
|
58
58
|
if (!s)
|
|
59
|
-
return
|
|
59
|
+
return i("Enter an Unsplash access key.");
|
|
60
60
|
const e = await c(t.fetch || globalThis.fetch, d, {
|
|
61
61
|
Authorization: `Client-ID ${s}`
|
|
62
62
|
});
|
|
63
|
-
return "failed" in e ?
|
|
63
|
+
return "failed" in e ? a("Unsplash", e.failed) : e.status === 401 ? i("Unsplash rejected this key. Use the Access Key (not the Secret Key) from unsplash.com/developers.") : e.status === 403 || e.status === 429 ? { detail: "Unsplash accepted the key (its demo quota is currently exhausted).", isFreeTier: null, ok: !0 } : e.status < 200 || e.status >= 300 ? a("Unsplash", `HTTP ${e.status}`) : { detail: null, isFreeTier: null, ok: !0 };
|
|
64
64
|
}
|
|
65
65
|
export {
|
|
66
66
|
p as verifyOpenRouterApiKey,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextblock-cms/cortex",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@ai-sdk/openai-compatible": "^2.0.42",
|
|
31
|
-
"@nextblock-cms/db": "^0.18.
|
|
32
|
-
"@nextblock-cms/ecommerce": "npm:@nextblock-cms/ecom@^0.18.
|
|
33
|
-
"@nextblock-cms/utils": "^0.18.
|
|
31
|
+
"@nextblock-cms/db": "^0.18.1",
|
|
32
|
+
"@nextblock-cms/ecommerce": "npm:@nextblock-cms/ecom@^0.18.1",
|
|
33
|
+
"@nextblock-cms/utils": "^0.18.1",
|
|
34
34
|
"ai": "^6.0.170",
|
|
35
35
|
"zod": "^4.3.6"
|
|
36
36
|
},
|