ag-common 0.0.784 → 0.0.785

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.
@@ -0,0 +1,6 @@
1
+ export declare const getAvailableCombinations: (service: string) => {
2
+ service: string;
3
+ key: string;
4
+ }[];
5
+ export declare const blockKeyService: (apiKey: string, service: string) => void;
6
+ export declare const isKeyServiceAvailable: (apiKey: string, service: string) => boolean;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isKeyServiceAvailable = exports.blockKeyService = exports.getAvailableCombinations = void 0;
7
+ const node_cache_1 = __importDefault(require("node-cache"));
8
+ const log_1 = require("../../../common/helpers/log");
9
+ const truncate_1 = require("../../../common/helpers/string/truncate");
10
+ // Initialize NodeCache with 1 hour TTL for blocklisted key combinations
11
+ const blocklist = new node_cache_1.default({ stdTTL: 3600 });
12
+ // Helper to generate blocklist key
13
+ const getBlocklistKey = (apiKey, service) => `${(0, truncate_1.truncate)(apiKey, 10)}_${service}`;
14
+ // Helper to check if a key+service combination is blocklisted
15
+ const isBlocklisted = (apiKey, service) => {
16
+ return blocklist.has(getBlocklistKey(apiKey, service));
17
+ };
18
+ // Helper to add a key+service combination to the blocklist
19
+ const addToBlocklist = (apiKey, service) => {
20
+ blocklist.set(getBlocklistKey(apiKey, service), true);
21
+ };
22
+ // Get available API keys from environment (internal use only)
23
+ const getApiKeys = () => {
24
+ var _a;
25
+ return ((_a = process.env.GOOGLE_API_KEY) !== null && _a !== void 0 ? _a : '')
26
+ .split(',')
27
+ .filter((key) => key.trim() !== '');
28
+ };
29
+ // Get available key+service combinations
30
+ const getAvailableCombinations = (service) => {
31
+ const keys = getApiKeys();
32
+ const combinations = [];
33
+ for (const key of keys) {
34
+ if (!isBlocklisted(key, service)) {
35
+ combinations.push({ service, key });
36
+ }
37
+ }
38
+ // If all combinations are blocklisted, clear the blocklist and try again
39
+ if (combinations.length === 0) {
40
+ (0, log_1.warn)(`All API key + service combinations were blocklisted for ${service}. Clearing blocklist and trying again.`);
41
+ blocklist.flushAll();
42
+ for (const key of keys) {
43
+ combinations.push({ service, key });
44
+ }
45
+ }
46
+ return combinations;
47
+ };
48
+ exports.getAvailableCombinations = getAvailableCombinations;
49
+ // Block a key+service combination
50
+ const blockKeyService = (apiKey, service) => {
51
+ (0, log_1.warn)(`key+service blocklisted: ${(0, truncate_1.truncate)(apiKey, 10)}_${service}`);
52
+ addToBlocklist(apiKey, service);
53
+ };
54
+ exports.blockKeyService = blockKeyService;
55
+ // Check if a key+service combination is available
56
+ const isKeyServiceAvailable = (apiKey, service) => {
57
+ return !isBlocklisted(apiKey, service);
58
+ };
59
+ exports.isKeyServiceAvailable = isKeyServiceAvailable;
@@ -8,30 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.resolveGroundedUrl = exports.geminiPromptDirect = void 0;
16
13
  const genai_1 = require("@google/genai");
17
- const node_cache_1 = __importDefault(require("node-cache"));
18
14
  const log_1 = require("../../../common/helpers/log");
19
- const truncate_1 = require("../../../common/helpers/string/truncate");
15
+ const apikey_1 = require("./apikey");
20
16
  let genAIs;
21
17
  // Available Gemini models
22
18
  const GEMINI_MODELS = ['gemini-2.5-pro', 'gemini-2.5-flash'];
23
- // Initialize NodeCache with 1 hour TTL for blocklisted key+model combinations
24
- const blocklist = new node_cache_1.default({ stdTTL: 3600 });
25
- // Helper to generate blocklist key
26
- const getBlocklistKey = (apiKey, model) => `${(0, truncate_1.truncate)(apiKey, 10)}_${model}`;
27
- // Helper to check if a key+model combination is blocklisted
28
- const isBlocklisted = (apiKey, model) => {
29
- return blocklist.has(getBlocklistKey(apiKey, model));
30
- };
31
- // Helper to add a key+model combination to the blocklist
32
- const addToBlocklist = (apiKey, model) => {
33
- blocklist.set(getBlocklistKey(apiKey, model), true);
34
- };
35
19
  // Helper to sort models based on preference
36
20
  const sortModelsByPreference = (models, prefer) => {
37
21
  const modelArray = [...models];
@@ -63,28 +47,20 @@ const sortModelsByPreference = (models, prefer) => {
63
47
  return modelArray;
64
48
  };
65
49
  // Helper to get available key+model combinations
66
- const getAvailableCombinations = (prefer) => {
67
- var _a;
50
+ const getAvailableGeminiCombinations = (prefer) => {
68
51
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
69
52
  if (!genAIs) {
70
- const keys = ((_a = process.env.GOOGLE_API_KEY) !== null && _a !== void 0 ? _a : '').split(',');
53
+ const keyServiceCombinations = (0, apikey_1.getAvailableCombinations)('gemini');
54
+ const keys = Object.keys(keyServiceCombinations);
71
55
  genAIs = keys.map((k) => [k, new genai_1.GoogleGenAI({ apiKey: k })]);
72
56
  }
73
57
  const sortedModels = sortModelsByPreference(GEMINI_MODELS, prefer);
74
58
  const combinations = [];
75
59
  for (const [key, ai] of genAIs) {
76
60
  for (const model of sortedModels) {
77
- if (!isBlocklisted(key, model)) {
78
- combinations.push([key, ai, model]);
79
- }
80
- }
81
- }
82
- // If all combinations are blocklisted, clear the blocklist and try again
83
- if (combinations.length === 0) {
84
- (0, log_1.warn)('All API key + model combinations were blocklisted. Clearing blocklist and trying again.');
85
- blocklist.flushAll();
86
- for (const [key, ai] of genAIs) {
87
- for (const model of sortedModels) {
61
+ const keyServiceCombinations = (0, apikey_1.getAvailableCombinations)(`gemini-${model}`);
62
+ const isAvailable = keyServiceCombinations.some((k) => k.key === key);
63
+ if (isAvailable) {
88
64
  combinations.push([key, ai, model]);
89
65
  }
90
66
  }
@@ -93,7 +69,7 @@ const getAvailableCombinations = (prefer) => {
93
69
  };
94
70
  const geminiPromptDirect = (_a) => __awaiter(void 0, [_a], void 0, function* ({ prompt, images = [], ident, prefer, groundedSearch = false, }) {
95
71
  var _b;
96
- const combinations = getAvailableCombinations(prefer);
72
+ const combinations = getAvailableGeminiCombinations(prefer);
97
73
  if (combinations.length === 0) {
98
74
  throw new Error('No available API key and model combinations');
99
75
  }
@@ -129,8 +105,7 @@ const geminiPromptDirect = (_a) => __awaiter(void 0, [_a], void 0, function* ({
129
105
  catch (e) {
130
106
  const em = e.message.toLowerCase();
131
107
  if (em.includes('429') || em.includes('safety')) {
132
- (0, log_1.warn)(`key+model blocklisted: ${(0, truncate_1.truncate)(key, 10)}_${selectedModel}`);
133
- addToBlocklist(key, selectedModel);
108
+ (0, apikey_1.blockKeyService)(key, `gemini-${selectedModel}`);
134
109
  }
135
110
  throw e;
136
111
  }
@@ -0,0 +1,2 @@
1
+ export * from './apikey';
2
+ export * from './gemini';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./apikey"), exports);
18
+ __exportStar(require("./gemini"), exports);
@@ -4,7 +4,7 @@ export * from './aws';
4
4
  export * from './cosmos';
5
5
  export * from './dynamo';
6
6
  export * from './enforceDynamoProvisionCap';
7
- export * from './gemini';
7
+ export * from './google';
8
8
  export * from './s3';
9
9
  export * from './ses';
10
10
  export * from './sqs';
@@ -20,7 +20,7 @@ __exportStar(require("./aws"), exports);
20
20
  __exportStar(require("./cosmos"), exports);
21
21
  __exportStar(require("./dynamo"), exports);
22
22
  __exportStar(require("./enforceDynamoProvisionCap"), exports);
23
- __exportStar(require("./gemini"), exports);
23
+ __exportStar(require("./google"), exports);
24
24
  __exportStar(require("./s3"), exports);
25
25
  __exportStar(require("./ses"), exports);
26
26
  __exportStar(require("./sqs"), exports);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.784",
2
+ "version": "0.0.785",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
@@ -17,28 +17,35 @@
17
17
  "test": "globstar -- node --import tsx --test \"src/**/*.test.ts\""
18
18
  },
19
19
  "dependencies": {
20
+ "eslint": "^9.37.0",
21
+ "eslint-config-e7npm": "^0.1.25",
22
+ "react": "^19.2.0",
23
+ "react-dom": "^19.2.0",
24
+ "tailwind-merge": "^3.3.1",
25
+ "tailwindcss": "^4.1.14",
26
+ "tailwindcss-animate": "^1.0.7",
27
+ "tsx": "^4.20.6",
28
+ "typescript": "^5.9.3",
29
+ "@tailwindcss/postcss": "^4.1.14",
30
+ "autoprefixer": "^10.4.21",
31
+ "class-variance-authority": "^0.7.1",
32
+ "clsx": "^2.1.1",
33
+ "cross-env": "^10.1.0",
34
+ "lucide-react": "^0.545.0"
35
+ },
36
+ "devDependencies": {
20
37
  "@aws-sdk/client-apigatewaymanagementapi": "^3.901.0",
21
- "@aws-sdk/client-dynamodb": "^3.901.0",
38
+ "@aws-sdk/client-dynamodb": "^3.902.0",
22
39
  "@aws-sdk/client-s3": "^3.901.0",
23
40
  "@aws-sdk/client-ses": "^3.901.0",
24
41
  "@aws-sdk/client-sqs": "^3.901.0",
25
42
  "@aws-sdk/client-sts": "^3.901.0",
26
- "@aws-sdk/lib-dynamodb": "^3.901.0",
43
+ "@aws-sdk/lib-dynamodb": "^3.902.0",
27
44
  "@aws-sdk/s3-presigned-post": "^3.901.0",
28
45
  "@azure/cosmos": "^4.5.1",
46
+ "@emotion/react": "^11.14.0",
47
+ "@emotion/styled": "^11.14.1",
29
48
  "@google/genai": "^1.22.0",
30
- "@radix-ui/react-radio-group": "^1.3.8",
31
- "@radix-ui/react-toast": "^1.2.15",
32
- "@storybook/addon-styling-webpack": "^2.0.0",
33
- "@storybook/react-vite": "^9.1.10",
34
- "aws-cdk-lib": "^2.219.0",
35
- "buffer": "^6.0.3",
36
- "jsonwebtoken": "^9.0.2",
37
- "jwks-rsa": "^3.2.0",
38
- "node-cache": "^5.1.2",
39
- "react": "^19.2.0",
40
- "react-dom": "^19.2.0",
41
- "typescript": "^5.9.3",
42
49
  "@radix-ui/react-accordion": "^1.2.12",
43
50
  "@radix-ui/react-avatar": "^1.1.10",
44
51
  "@radix-ui/react-checkbox": "^1.3.3",
@@ -47,44 +54,37 @@
47
54
  "@radix-ui/react-icons": "^1.3.2",
48
55
  "@radix-ui/react-label": "^2.1.7",
49
56
  "@radix-ui/react-popover": "^1.1.15",
57
+ "@radix-ui/react-radio-group": "^1.3.8",
50
58
  "@radix-ui/react-scroll-area": "^1.2.10",
51
59
  "@radix-ui/react-select": "^2.2.6",
52
60
  "@radix-ui/react-slot": "^1.2.3",
53
61
  "@radix-ui/react-switch": "^1.2.6",
54
- "@tailwindcss/postcss": "^4.1.14",
55
- "autoprefixer": "^10.4.21",
56
- "class-variance-authority": "^0.7.1",
57
- "clsx": "^2.1.1",
58
- "eslint": "^9.36.0",
59
- "lucide-react": "^0.545.0",
60
- "tailwind-merge": "^3.3.1",
61
- "tailwindcss": "^4.1.14",
62
- "tailwindcss-animate": "^1.0.7",
63
- "eslint-config-e7npm": "^0.1.25"
64
- },
65
- "devDependencies": {
66
- "@emotion/react": "^11.14.0",
67
- "@emotion/styled": "^11.14.1",
62
+ "@radix-ui/react-toast": "^1.2.15",
68
63
  "@smithy/types": "^4.6.0",
69
64
  "@storybook/addon-docs": "^9.1.10",
70
65
  "@storybook/addon-links": "^9.1.10",
66
+ "@storybook/addon-styling-webpack": "^2.0.0",
71
67
  "@storybook/addons": "^7.6.17",
72
68
  "@storybook/manager-api": "^8.6.14",
73
69
  "@storybook/react": "^9.1.10",
70
+ "@storybook/react-vite": "^9.1.10",
74
71
  "@storybook/react-webpack5": "^9.1.10",
75
72
  "@storybook/theming": "^8.6.14",
76
73
  "@types/jsonwebtoken": "^9.0.10",
77
- "@types/node": "^24.6.2",
78
- "@types/react": "^19.2.0",
79
- "@types/react-dom": "^19.2.0",
80
- "@typescript-eslint/eslint-plugin": "^8.45.0",
81
- "@typescript-eslint/parser": "^8.45.0",
82
- "cross-env": "^10.1.0",
74
+ "@types/node": "^24.7.0",
75
+ "@types/react": "^19.2.2",
76
+ "@types/react-dom": "^19.2.1",
77
+ "@typescript-eslint/eslint-plugin": "^8.46.0",
78
+ "@typescript-eslint/parser": "^8.46.0",
79
+ "aws-cdk-lib": "^2.219.0",
80
+ "buffer": "^6.0.3",
83
81
  "eslint-plugin-storybook": "^9.1.10",
84
82
  "globstar": "^1.0.0",
83
+ "jsonwebtoken": "^9.0.2",
84
+ "jwks-rsa": "^3.2.0",
85
+ "node-cache": "^5.1.2",
85
86
  "rimraf": "^6.0.1",
86
- "storybook": "^9.1.10",
87
- "tsx": "^4.20.6"
87
+ "storybook": "^9.1.10"
88
88
  },
89
89
  "files": [
90
90
  "dist/**/*",