@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/dist/vertex.js CHANGED
@@ -1,46 +1,7 @@
1
- // src/vertex.ts
2
- import "server-only";
3
- var cachedToken = null;
4
- function base64UrlEncode(input) {
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.2.0",
4
- "description": "Free-by-default AI provider chain (Gemini, OpenRouter, NVIDIA, Vertex) with hedging, cooldowns and deadlines, env-driven model resolution, image generation and prompt-injection guards. Shared by @sahan-sac/blog-kit and @sahan-sac/chat-kit.",
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"