ag-common 0.0.787 → 0.0.788
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.
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.blockKeyService = exports.getAvailableCombinations = void 0;
|
|
7
7
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
8
|
+
const common_1 = require("../../../common");
|
|
8
9
|
const log_1 = require("../../../common/helpers/log");
|
|
9
10
|
const truncate_1 = require("../../../common/helpers/string/truncate");
|
|
10
11
|
// Initialize NodeCache with 1 hour TTL for blocklisted key combinations
|
|
@@ -22,13 +23,12 @@ const addToBlocklist = (apiKey, service) => {
|
|
|
22
23
|
// Get available API keys from environment (internal use only)
|
|
23
24
|
const getApiKeys = () => {
|
|
24
25
|
var _a;
|
|
25
|
-
return ((_a = process.env.GOOGLE_API_KEY) !== null && _a !== void 0 ? _a : '')
|
|
26
|
-
.split(',')
|
|
27
|
-
.filter((key) => key.trim() !== '');
|
|
26
|
+
return ((_a = process.env.GOOGLE_API_KEY) !== null && _a !== void 0 ? _a : '').split(',').filter(common_1.notEmpty);
|
|
28
27
|
};
|
|
29
28
|
// Get available key+service combinations
|
|
30
29
|
const getAvailableCombinations = (service) => {
|
|
31
30
|
const keys = getApiKeys();
|
|
31
|
+
(0, log_1.debug)(`got ${keys.length} GOOGLE_API_KEY keys`);
|
|
32
32
|
const combinations = [];
|
|
33
33
|
for (const key of keys) {
|
|
34
34
|
if (!isBlocklisted(key, service)) {
|
|
@@ -43,6 +43,7 @@ const getAvailableCombinations = (service) => {
|
|
|
43
43
|
combinations.push({ service, key });
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
(0, log_1.debug)(`returning ${combinations.length} google combinations`);
|
|
46
47
|
return combinations;
|
|
47
48
|
};
|
|
48
49
|
exports.getAvailableCombinations = getAvailableCombinations;
|
|
@@ -52,8 +53,3 @@ const blockKeyService = (apiKey, service) => {
|
|
|
52
53
|
addToBlocklist(apiKey, service);
|
|
53
54
|
};
|
|
54
55
|
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;
|
|
@@ -49,9 +49,9 @@ const sortModelsByPreference = (models, prefer) => {
|
|
|
49
49
|
// Helper to get available key+model combinations
|
|
50
50
|
const getAvailableGeminiCombinations = (prefer) => {
|
|
51
51
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
52
|
-
if (!genAIs) {
|
|
52
|
+
if (!genAIs || genAIs.length === 0) {
|
|
53
53
|
const keyServiceCombinations = (0, apikey_1.getAvailableCombinations)('gemini');
|
|
54
|
-
const keys =
|
|
54
|
+
const keys = keyServiceCombinations.map((combo) => combo.key);
|
|
55
55
|
genAIs = keys.map((k) => [k, new genai_1.GoogleGenAI({ apiKey: k })]);
|
|
56
56
|
}
|
|
57
57
|
const sortedModels = sortModelsByPreference(GEMINI_MODELS, prefer);
|
package/package.json
CHANGED