@splashcodex/api-key-manager 5.0.2 → 5.2.0

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,84 +1,84 @@
1
- /**
2
- * Gemini Preset — One-line Gemini API key management
3
- *
4
- * Pre-configured singleton with:
5
- * - Reads `GOOGLE_GEMINI_API_KEY` or `GEMINI_API_KEY` from env
6
- * - LatencyStrategy for optimal key selection
7
- * - File persistence (survives restarts)
8
- * - Health checks every 5 minutes
9
- * - Concurrency limit of 20
10
- *
11
- * @module presets/gemini
12
- *
13
- * @example
14
- * ```ts
15
- * import { GeminiManager } from '@splashcodex/api-key-manager/presets/gemini';
16
- *
17
- * // Initialize once (reads keys from process.env automatically)
18
- * const result = GeminiManager.getInstance();
19
- * if (!result.success) throw result.error;
20
- * const gemini = result.data;
21
- *
22
- * // Use the execute() wrapper for automatic key rotation + retries
23
- * const response = await gemini.execute(async (key) => {
24
- * const genAI = new GoogleGenerativeAI(key);
25
- * const model = genAI.getGenerativeModel({ model: 'gemini-2.0-flash' });
26
- * const res = await model.generateContent('Hello, world!');
27
- * return res.response.text();
28
- * }, { maxRetries: 3, timeoutMs: 30000 });
29
- * ```
30
- */
31
-
32
- import { BasePreset, PresetOptions, Result } from './base';
33
-
34
- export class GeminiManager extends BasePreset {
35
- private static readonly PROVIDER = 'gemini';
36
-
37
- private constructor(keys: string[], options: PresetOptions) {
38
- super(keys, options);
39
- }
40
-
41
- /**
42
- * Default configuration for Gemini presets.
43
- */
44
- private static getDefaultOptions(): Partial<PresetOptions> {
45
- return {
46
- envKeys: ['GOOGLE_GEMINI_API_KEY', 'GEMINI_API_KEY'],
47
- provider: GeminiManager.PROVIDER,
48
- concurrency: 20,
49
- healthCheckIntervalMs: 300_000, // 5 minutes
50
- };
51
- }
52
-
53
- /**
54
- * Get or create the singleton GeminiManager instance.
55
- *
56
- * @param overrides - Optional configuration overrides
57
- * @returns Result<GeminiManager> — safely check `.success` before using `.data`
58
- *
59
- * @example
60
- * ```ts
61
- * const result = GeminiManager.getInstance();
62
- * if (result.success) {
63
- * const gemini = result.data;
64
- * const text = await gemini.execute(apiCall, { maxRetries: 3 });
65
- * }
66
- * ```
67
- */
68
- static getInstance(overrides?: Partial<PresetOptions>): Result<GeminiManager> {
69
- return BasePreset.createInstance(
70
- GeminiManager as unknown as new (keys: string[], options: PresetOptions) => GeminiManager,
71
- GeminiManager.getDefaultOptions(),
72
- overrides
73
- ) as Result<GeminiManager>;
74
- }
75
-
76
- /**
77
- * Reset the singleton instance. Primarily for testing.
78
- */
79
- static reset(): void {
80
- BasePreset.resetInstance(GeminiManager.PROVIDER);
81
- }
82
- }
83
-
84
- export { Result } from './base';
1
+ /**
2
+ * Gemini Preset — One-line Gemini API key management
3
+ *
4
+ * Pre-configured singleton with:
5
+ * - Reads `GOOGLE_GEMINI_API_KEY` or `GEMINI_API_KEY` from env
6
+ * - LatencyStrategy for optimal key selection
7
+ * - File persistence (survives restarts)
8
+ * - Health checks every 5 minutes
9
+ * - Concurrency limit of 20
10
+ *
11
+ * @module presets/gemini
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { GeminiManager } from '@splashcodex/api-key-manager/presets/gemini';
16
+ *
17
+ * // Initialize once (reads keys from process.env automatically)
18
+ * const result = GeminiManager.getInstance();
19
+ * if (!result.success) throw result.error;
20
+ * const gemini = result.data;
21
+ *
22
+ * // Use the execute() wrapper for automatic key rotation + retries
23
+ * const response = await gemini.execute(async (key) => {
24
+ * const genAI = new GoogleGenerativeAI(key);
25
+ * const model = genAI.getGenerativeModel({ model: 'gemini-2.0-flash' });
26
+ * const res = await model.generateContent('Hello, world!');
27
+ * return res.response.text();
28
+ * }, { maxRetries: 3, timeoutMs: 30000 });
29
+ * ```
30
+ */
31
+
32
+ import { BasePreset, PresetOptions, Result } from './base';
33
+
34
+ export class GeminiManager extends BasePreset {
35
+ private static readonly PROVIDER = 'gemini';
36
+
37
+ private constructor(keys: string[], options: PresetOptions) {
38
+ super(keys, options);
39
+ }
40
+
41
+ /**
42
+ * Default configuration for Gemini presets.
43
+ */
44
+ private static getDefaultOptions(): Partial<PresetOptions> {
45
+ return {
46
+ envKeys: ['GOOGLE_GEMINI_API_KEY', 'GEMINI_API_KEY'],
47
+ provider: GeminiManager.PROVIDER,
48
+ concurrency: 20,
49
+ healthCheckIntervalMs: 300_000, // 5 minutes
50
+ };
51
+ }
52
+
53
+ /**
54
+ * Get or create the singleton GeminiManager instance.
55
+ *
56
+ * @param overrides - Optional configuration overrides
57
+ * @returns Result<GeminiManager> — safely check `.success` before using `.data`
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const result = GeminiManager.getInstance();
62
+ * if (result.success) {
63
+ * const gemini = result.data;
64
+ * const text = await gemini.execute(apiCall, { maxRetries: 3 });
65
+ * }
66
+ * ```
67
+ */
68
+ static getInstance(overrides?: Partial<PresetOptions>): Result<GeminiManager> {
69
+ return BasePreset.createInstance(
70
+ GeminiManager as unknown as new (keys: string[], options: PresetOptions) => GeminiManager,
71
+ GeminiManager.getDefaultOptions(),
72
+ overrides
73
+ ) as Result<GeminiManager>;
74
+ }
75
+
76
+ /**
77
+ * Reset the singleton instance. Primarily for testing.
78
+ */
79
+ static reset(): void {
80
+ BasePreset.resetInstance(GeminiManager.PROVIDER);
81
+ }
82
+ }
83
+
84
+ export { Result } from './base';
@@ -1,10 +1,11 @@
1
- /**
2
- * Presets — Batteries-included provider managers
3
- * @module presets
4
- */
5
- export { BasePreset } from './base';
6
- export type { PresetOptions, PresetLogger, Result } from './base';
7
- export { GeminiManager } from './gemini';
8
- export { OpenAIManager } from './openai';
9
- export { MultiManager } from './multi';
10
- export type { ProviderConfig, MultiManagerOptions } from './multi';
1
+ /**
2
+ * Presets — Batteries-included provider managers
3
+ * @module presets
4
+ */
5
+ export { BasePreset } from './base';
6
+ export type { PresetOptions, PresetLogger, Result } from './base';
7
+ export { GeminiManager } from './gemini';
8
+ export { OpenAIManager } from './openai';
9
+ export { AnthropicManager } from './anthropic';
10
+ export { MultiManager } from './multi';
11
+ export type { ProviderConfig, MultiManagerOptions } from './multi';