@sahan-sac/ai-core 0.2.0 → 0.3.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/CHANGELOG.md +14 -0
- package/README.md +75 -10
- package/dist/adapters.d.ts +6 -0
- package/dist/adapters.js +27 -0
- package/dist/availability.d.ts +8 -3
- package/dist/availability.js +14 -48
- package/dist/chunk-BL4J2JNX.js +48 -0
- package/dist/chunk-MRNQPHWI.js +194 -0
- package/dist/chunk-PMC3UWQ2.js +10 -0
- package/dist/chunk-R3YY2Y7S.js +571 -0
- package/dist/chunk-RBSLNDFW.js +61 -0
- package/dist/chunk-ZIHRZXPE.js +109 -0
- package/dist/env.d.ts +30 -0
- package/dist/env.js +6 -63
- package/dist/guard.d.ts +15 -3
- package/dist/guard.js +0 -0
- package/dist/image.js +14 -236
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -63
- package/dist/log.js +3 -6
- package/dist/models.js +9 -51
- package/dist/providers.d.ts +144 -8
- package/dist/providers.js +23 -422
- package/dist/vertex.js +4 -43
- package/package.json +6 -2
package/dist/vertex.js
CHANGED
|
@@ -1,46 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return Buffer.from(input).toString("base64url");
|
|
6
|
-
}
|
|
7
|
-
async function getVertexAccessToken(account, fetchImpl = fetch) {
|
|
8
|
-
const now = Date.now();
|
|
9
|
-
if (cachedToken && cachedToken.expiresAt - 6e4 > now) return cachedToken.accessToken;
|
|
10
|
-
const { createSign } = await import("crypto");
|
|
11
|
-
const issuedAt = Math.floor(now / 1e3);
|
|
12
|
-
const expiresIn = 3600;
|
|
13
|
-
const header = base64UrlEncode(JSON.stringify({ alg: "RS256", typ: "JWT" }));
|
|
14
|
-
const claims = base64UrlEncode(
|
|
15
|
-
JSON.stringify({
|
|
16
|
-
iss: account.clientEmail,
|
|
17
|
-
scope: "https://www.googleapis.com/auth/cloud-platform",
|
|
18
|
-
aud: account.tokenUri,
|
|
19
|
-
iat: issuedAt,
|
|
20
|
-
exp: issuedAt + expiresIn
|
|
21
|
-
})
|
|
22
|
-
);
|
|
23
|
-
const signingInput = `${header}.${claims}`;
|
|
24
|
-
const signature = createSign("RSA-SHA256").update(signingInput).sign(account.privateKey);
|
|
25
|
-
const jwt = `${signingInput}.${base64UrlEncode(signature)}`;
|
|
26
|
-
const response = await fetchImpl(account.tokenUri, {
|
|
27
|
-
method: "POST",
|
|
28
|
-
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
29
|
-
body: new URLSearchParams({
|
|
30
|
-
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
31
|
-
assertion: jwt
|
|
32
|
-
})
|
|
33
|
-
});
|
|
34
|
-
if (!response.ok) {
|
|
35
|
-
throw new Error(`Vertex token exchange failed: HTTP ${response.status}`);
|
|
36
|
-
}
|
|
37
|
-
const data = await response.json();
|
|
38
|
-
cachedToken = { accessToken: data.access_token, expiresAt: now + data.expires_in * 1e3 };
|
|
39
|
-
return data.access_token;
|
|
40
|
-
}
|
|
41
|
-
function resetVertexTokenCache() {
|
|
42
|
-
cachedToken = null;
|
|
43
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
getVertexAccessToken,
|
|
3
|
+
resetVertexTokenCache
|
|
4
|
+
} from "./chunk-BL4J2JNX.js";
|
|
44
5
|
export {
|
|
45
6
|
getVertexAccessToken,
|
|
46
7
|
resetVertexTokenCache
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sahan-sac/ai-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Free-by-default AI provider chain (Gemini, OpenRouter, NVIDIA, Vertex)
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Free-by-default AI provider chain with fallback (chain of responsibility over provider adapters: Gemini, OpenRouter, NVIDIA, OpenAI, Anthropic, DeepSeek, xAI, Perplexity, any OpenAI-compatible endpoint, Vertex), env-configurable order, hedging, cooldowns and deadlines, image generation and prompt-injection guards. Shared by @sahan-sac/blog-kit and @sahan-sac/chat-kit.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"types": "./dist/models.d.ts",
|
|
36
36
|
"import": "./dist/models.js"
|
|
37
37
|
},
|
|
38
|
+
"./adapters": {
|
|
39
|
+
"types": "./dist/adapters.d.ts",
|
|
40
|
+
"import": "./dist/adapters.js"
|
|
41
|
+
},
|
|
38
42
|
"./providers": {
|
|
39
43
|
"types": "./dist/providers.d.ts",
|
|
40
44
|
"import": "./dist/providers.js"
|