agentic-qe 2.6.4 → 2.6.5
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 +43 -0
- package/README.md +26 -1
- package/dist/cli/commands/providers/index.d.ts +20 -0
- package/dist/cli/commands/providers/index.d.ts.map +1 -0
- package/dist/cli/commands/providers/index.js +143 -0
- package/dist/cli/commands/providers/index.js.map +1 -0
- package/dist/cli/commands/providers/status.d.ts +117 -0
- package/dist/cli/commands/providers/status.d.ts.map +1 -0
- package/dist/cli/commands/providers/status.js +368 -0
- package/dist/cli/commands/providers/status.js.map +1 -0
- package/dist/cli/index.js +8 -62
- package/dist/cli/index.js.map +1 -1
- package/dist/core/memory/HNSWVectorMemory.js +1 -1
- package/dist/mcp/server-instructions.d.ts +1 -1
- package/dist/mcp/server-instructions.js +1 -1
- package/dist/monitoring/ProviderHealthMonitor.d.ts +195 -0
- package/dist/monitoring/ProviderHealthMonitor.d.ts.map +1 -0
- package/dist/monitoring/ProviderHealthMonitor.js +431 -0
- package/dist/monitoring/ProviderHealthMonitor.js.map +1 -0
- package/dist/monitoring/QuotaManager.d.ts +122 -0
- package/dist/monitoring/QuotaManager.d.ts.map +1 -0
- package/dist/monitoring/QuotaManager.js +351 -0
- package/dist/monitoring/QuotaManager.js.map +1 -0
- package/dist/providers/GitHubModelsProvider.d.ts +117 -0
- package/dist/providers/GitHubModelsProvider.d.ts.map +1 -0
- package/dist/providers/GitHubModelsProvider.js +464 -0
- package/dist/providers/GitHubModelsProvider.js.map +1 -0
- package/dist/providers/GroqProvider.d.ts +115 -0
- package/dist/providers/GroqProvider.d.ts.map +1 -0
- package/dist/providers/GroqProvider.js +443 -0
- package/dist/providers/GroqProvider.js.map +1 -0
- package/dist/providers/HybridRouterHealthIntegration.d.ts +191 -0
- package/dist/providers/HybridRouterHealthIntegration.d.ts.map +1 -0
- package/dist/providers/HybridRouterHealthIntegration.js +439 -0
- package/dist/providers/HybridRouterHealthIntegration.js.map +1 -0
- package/dist/providers/index.d.ts +6 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +12 -1
- package/dist/providers/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/cli/commands/providers.d.ts +0 -50
- package/dist/cli/commands/providers.d.ts.map +0 -1
- package/dist/cli/commands/providers.js +0 -403
- package/dist/cli/commands/providers.js.map +0 -1
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* GroqProvider - High-Performance LLM Inference via Groq
|
|
4
|
+
*
|
|
5
|
+
* Provides cloud-based LLM inference through Groq's ultra-fast API with support for:
|
|
6
|
+
* - FREE tier: 14,400 requests/day (10 req/min)
|
|
7
|
+
* - Streaming responses via SSE
|
|
8
|
+
* - Rate limit handling with exponential backoff
|
|
9
|
+
* - Rate limiting (10 req/min free tier)
|
|
10
|
+
* - Multiple model families (LLaMA, Mixtral, DeepSeek)
|
|
11
|
+
* - OpenAI-compatible API format
|
|
12
|
+
*
|
|
13
|
+
* @module providers/GroqProvider
|
|
14
|
+
* @version 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.GroqProvider = void 0;
|
|
18
|
+
const ILLMProvider_1 = require("./ILLMProvider");
|
|
19
|
+
const Logger_1 = require("../utils/Logger");
|
|
20
|
+
/**
|
|
21
|
+
* GroqProvider - High-performance cloud LLM inference
|
|
22
|
+
*
|
|
23
|
+
* This provider enables ultra-fast LLM inference using Groq's specialized
|
|
24
|
+
* LPU (Language Processing Unit) architecture, providing significantly
|
|
25
|
+
* faster inference than traditional GPU-based providers.
|
|
26
|
+
*
|
|
27
|
+
* Supported Models:
|
|
28
|
+
* - llama-3.3-70b-versatile (primary general-purpose model)
|
|
29
|
+
* - deepseek-r1-distill-llama-70b (reasoning-focused)
|
|
30
|
+
* - mixtral-8x7b-32768 (large context window)
|
|
31
|
+
* - llama-3.1-8b-instant (fast lightweight)
|
|
32
|
+
*
|
|
33
|
+
* Rate Limits (FREE tier):
|
|
34
|
+
* - 14,400 requests per day
|
|
35
|
+
* - 10 requests per minute
|
|
36
|
+
* - Automatic retry with exponential backoff
|
|
37
|
+
*/
|
|
38
|
+
class GroqProvider {
|
|
39
|
+
constructor(config = {}) {
|
|
40
|
+
this.logger = Logger_1.Logger.getInstance();
|
|
41
|
+
this.config = {
|
|
42
|
+
name: config.name || 'groq',
|
|
43
|
+
debug: config.debug ?? false,
|
|
44
|
+
timeout: config.timeout ?? 60000, // 60 seconds
|
|
45
|
+
maxRetries: config.maxRetries ?? 3,
|
|
46
|
+
baseUrl: config.baseUrl || 'https://api.groq.com/openai/v1',
|
|
47
|
+
defaultModel: config.defaultModel || 'llama-3.3-70b-versatile',
|
|
48
|
+
rateLimitRetryDelay: config.rateLimitRetryDelay ?? 6000 // 6 seconds
|
|
49
|
+
};
|
|
50
|
+
this.isInitialized = false;
|
|
51
|
+
this.apiKey = config.apiKey || process.env.GROQ_API_KEY || '';
|
|
52
|
+
this.baseUrl = this.config.baseUrl;
|
|
53
|
+
this.requestCount = 0;
|
|
54
|
+
this.lastRequestTime = 0;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Initialize the Groq provider
|
|
58
|
+
*/
|
|
59
|
+
async initialize() {
|
|
60
|
+
if (this.isInitialized) {
|
|
61
|
+
this.logger.warn('GroqProvider already initialized');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
// Validate API key
|
|
66
|
+
if (!this.apiKey) {
|
|
67
|
+
throw new Error('Groq API key is required. Set GROQ_API_KEY environment variable or pass apiKey in config.');
|
|
68
|
+
}
|
|
69
|
+
// Test connection with health check
|
|
70
|
+
const health = await this.healthCheck();
|
|
71
|
+
if (!health.healthy) {
|
|
72
|
+
throw new Error(`Groq API health check failed: ${health.error}`);
|
|
73
|
+
}
|
|
74
|
+
this.isInitialized = true;
|
|
75
|
+
this.logger.info('GroqProvider initialized', {
|
|
76
|
+
baseUrl: this.baseUrl,
|
|
77
|
+
defaultModel: this.config.defaultModel,
|
|
78
|
+
maxRetries: this.config.maxRetries
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw new ILLMProvider_1.LLMProviderError(`Failed to initialize Groq: ${error.message}`, 'groq', 'INIT_ERROR', false, error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Complete a prompt using Groq
|
|
87
|
+
*/
|
|
88
|
+
async complete(options) {
|
|
89
|
+
this.ensureInitialized();
|
|
90
|
+
const startTime = Date.now();
|
|
91
|
+
const model = options.model || this.config.defaultModel;
|
|
92
|
+
let lastError = null;
|
|
93
|
+
let retries = 0;
|
|
94
|
+
while (retries <= this.config.maxRetries) {
|
|
95
|
+
try {
|
|
96
|
+
// Build request payload
|
|
97
|
+
const requestBody = this.buildChatRequest(options, model);
|
|
98
|
+
// Make request to Groq
|
|
99
|
+
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
|
100
|
+
method: 'POST',
|
|
101
|
+
headers: {
|
|
102
|
+
'Content-Type': 'application/json',
|
|
103
|
+
'Authorization': `Bearer ${this.apiKey}`
|
|
104
|
+
},
|
|
105
|
+
body: JSON.stringify(requestBody),
|
|
106
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
107
|
+
});
|
|
108
|
+
// Handle rate limiting
|
|
109
|
+
if (response.status === 429) {
|
|
110
|
+
const retryAfter = this.extractRetryAfter(response);
|
|
111
|
+
const delay = retryAfter || this.config.rateLimitRetryDelay;
|
|
112
|
+
this.logger.warn('Rate limit hit, retrying', {
|
|
113
|
+
retryAfter: delay,
|
|
114
|
+
attempt: retries + 1
|
|
115
|
+
});
|
|
116
|
+
if (retries < this.config.maxRetries) {
|
|
117
|
+
await this.sleep(delay);
|
|
118
|
+
retries++;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
throw new ILLMProvider_1.LLMProviderError('Rate limit exceeded. Free tier: 10 req/min, 14,400 req/day', 'groq', 'RATE_LIMITED', true);
|
|
122
|
+
}
|
|
123
|
+
// Handle authentication errors
|
|
124
|
+
if (response.status === 401) {
|
|
125
|
+
const errorData = await response.json();
|
|
126
|
+
throw new ILLMProvider_1.LLMProviderError(`Authentication failed: ${errorData.error.message}`, 'groq', 'AUTH_ERROR', false);
|
|
127
|
+
}
|
|
128
|
+
// Handle other errors
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
const errorData = await response.json();
|
|
131
|
+
throw new Error(`Groq API error: ${errorData.error.message}`);
|
|
132
|
+
}
|
|
133
|
+
const data = await response.json();
|
|
134
|
+
this.requestCount++;
|
|
135
|
+
this.lastRequestTime = Date.now();
|
|
136
|
+
const latency = Date.now() - startTime;
|
|
137
|
+
// Map to standardized response format
|
|
138
|
+
const usage = {
|
|
139
|
+
input_tokens: data.usage.prompt_tokens,
|
|
140
|
+
output_tokens: data.usage.completion_tokens
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
content: [{
|
|
144
|
+
type: 'text',
|
|
145
|
+
text: data.choices[0].message.content
|
|
146
|
+
}],
|
|
147
|
+
usage,
|
|
148
|
+
model: data.model,
|
|
149
|
+
stop_reason: this.mapStopReason(data.choices[0].finish_reason),
|
|
150
|
+
id: data.id,
|
|
151
|
+
metadata: {
|
|
152
|
+
latency,
|
|
153
|
+
cost: this.trackCost(usage),
|
|
154
|
+
groq_metadata: {
|
|
155
|
+
queue_time: data.usage.queue_time,
|
|
156
|
+
prompt_time: data.usage.prompt_time,
|
|
157
|
+
completion_time: data.usage.completion_time,
|
|
158
|
+
total_time: data.usage.total_time,
|
|
159
|
+
system_fingerprint: data.system_fingerprint
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
lastError = error;
|
|
166
|
+
// Don't retry on auth errors or rate limit errors that exceed max retries
|
|
167
|
+
if (error instanceof ILLMProvider_1.LLMProviderError) {
|
|
168
|
+
if (error.code === 'AUTH_ERROR') {
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
if (error.code === 'RATE_LIMITED' && retries >= this.config.maxRetries) {
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// Retry on network errors with exponential backoff
|
|
176
|
+
if (retries < this.config.maxRetries) {
|
|
177
|
+
const backoffDelay = Math.min(1000 * Math.pow(2, retries), 10000);
|
|
178
|
+
this.logger.warn('Request failed, retrying', {
|
|
179
|
+
error: error.message,
|
|
180
|
+
attempt: retries + 1,
|
|
181
|
+
delay: backoffDelay
|
|
182
|
+
});
|
|
183
|
+
await this.sleep(backoffDelay);
|
|
184
|
+
retries++;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// All retries exhausted
|
|
191
|
+
throw new ILLMProvider_1.LLMProviderError(`Groq completion failed after ${retries} retries: ${lastError?.message}`, 'groq', 'API_ERROR', true, lastError);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Stream a completion using Groq
|
|
195
|
+
*/
|
|
196
|
+
async *streamComplete(options) {
|
|
197
|
+
this.ensureInitialized();
|
|
198
|
+
const model = options.model || this.config.defaultModel;
|
|
199
|
+
try {
|
|
200
|
+
const requestBody = this.buildChatRequest(options, model);
|
|
201
|
+
requestBody.stream = true;
|
|
202
|
+
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
|
203
|
+
method: 'POST',
|
|
204
|
+
headers: {
|
|
205
|
+
'Content-Type': 'application/json',
|
|
206
|
+
'Authorization': `Bearer ${this.apiKey}`
|
|
207
|
+
},
|
|
208
|
+
body: JSON.stringify(requestBody)
|
|
209
|
+
});
|
|
210
|
+
if (response.status === 429) {
|
|
211
|
+
throw new ILLMProvider_1.LLMProviderError('Rate limit exceeded', 'groq', 'RATE_LIMITED', true);
|
|
212
|
+
}
|
|
213
|
+
if (response.status === 401) {
|
|
214
|
+
throw new ILLMProvider_1.LLMProviderError('Authentication failed', 'groq', 'AUTH_ERROR', false);
|
|
215
|
+
}
|
|
216
|
+
if (!response.ok) {
|
|
217
|
+
const errorData = await response.json();
|
|
218
|
+
throw new Error(`Groq API error: ${errorData.error.message}`);
|
|
219
|
+
}
|
|
220
|
+
const reader = response.body?.getReader();
|
|
221
|
+
if (!reader) {
|
|
222
|
+
throw new Error('No response body');
|
|
223
|
+
}
|
|
224
|
+
const decoder = new TextDecoder();
|
|
225
|
+
let buffer = '';
|
|
226
|
+
yield { type: 'message_start' };
|
|
227
|
+
yield { type: 'content_block_start', content_block: { type: 'text', text: '' } };
|
|
228
|
+
while (true) {
|
|
229
|
+
const { done, value } = await reader.read();
|
|
230
|
+
if (done)
|
|
231
|
+
break;
|
|
232
|
+
buffer += decoder.decode(value, { stream: true });
|
|
233
|
+
const lines = buffer.split('\n');
|
|
234
|
+
buffer = lines.pop() || '';
|
|
235
|
+
for (const line of lines) {
|
|
236
|
+
if (line.trim() === '' || line.trim() === 'data: [DONE]')
|
|
237
|
+
continue;
|
|
238
|
+
if (!line.startsWith('data: '))
|
|
239
|
+
continue;
|
|
240
|
+
try {
|
|
241
|
+
const jsonData = line.slice(6); // Remove 'data: ' prefix
|
|
242
|
+
const chunk = JSON.parse(jsonData);
|
|
243
|
+
const delta = chunk.choices[0]?.delta;
|
|
244
|
+
if (delta?.content) {
|
|
245
|
+
yield {
|
|
246
|
+
type: 'content_block_delta',
|
|
247
|
+
delta: { type: 'text_delta', text: delta.content }
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (chunk.choices[0]?.finish_reason) {
|
|
251
|
+
yield { type: 'content_block_stop' };
|
|
252
|
+
yield { type: 'message_stop' };
|
|
253
|
+
this.requestCount++;
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch (parseError) {
|
|
258
|
+
// Skip invalid JSON lines
|
|
259
|
+
this.logger.debug('Failed to parse SSE chunk', { line });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
if (error instanceof ILLMProvider_1.LLMProviderError) {
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
throw new ILLMProvider_1.LLMProviderError(`Groq stream failed: ${error.message}`, 'groq', 'STREAM_ERROR', true, error);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Generate embeddings (not supported by Groq)
|
|
273
|
+
*/
|
|
274
|
+
async embed(options) {
|
|
275
|
+
throw new ILLMProvider_1.LLMProviderError('Groq does not support embeddings. Use a dedicated embedding provider.', 'groq', 'UNSUPPORTED_OPERATION', false);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Count tokens in text (approximate)
|
|
279
|
+
*/
|
|
280
|
+
async countTokens(options) {
|
|
281
|
+
// Approximate token count: 1 token ≈ 4 characters (similar to GPT tokenization)
|
|
282
|
+
return Math.ceil(options.text.length / 4);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Health check - ping Groq API
|
|
286
|
+
*/
|
|
287
|
+
async healthCheck() {
|
|
288
|
+
const startTime = Date.now();
|
|
289
|
+
try {
|
|
290
|
+
// Use a minimal request to test API connectivity
|
|
291
|
+
const response = await fetch(`${this.baseUrl}/models`, {
|
|
292
|
+
method: 'GET',
|
|
293
|
+
headers: {
|
|
294
|
+
'Authorization': `Bearer ${this.apiKey}`
|
|
295
|
+
},
|
|
296
|
+
signal: AbortSignal.timeout(5000)
|
|
297
|
+
});
|
|
298
|
+
const latency = Date.now() - startTime;
|
|
299
|
+
if (response.ok) {
|
|
300
|
+
return {
|
|
301
|
+
healthy: true,
|
|
302
|
+
latency,
|
|
303
|
+
timestamp: new Date(),
|
|
304
|
+
metadata: {
|
|
305
|
+
baseUrl: this.baseUrl,
|
|
306
|
+
requestCount: this.requestCount
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
healthy: false,
|
|
312
|
+
error: `API returned ${response.status}`,
|
|
313
|
+
timestamp: new Date()
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
return {
|
|
318
|
+
healthy: false,
|
|
319
|
+
error: error.message,
|
|
320
|
+
timestamp: new Date()
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get provider metadata
|
|
326
|
+
*/
|
|
327
|
+
getMetadata() {
|
|
328
|
+
return {
|
|
329
|
+
name: 'groq',
|
|
330
|
+
version: '1.0.0',
|
|
331
|
+
models: [
|
|
332
|
+
'llama-3.3-70b-versatile',
|
|
333
|
+
'llama-3.1-70b-versatile',
|
|
334
|
+
'llama-3.1-8b-instant',
|
|
335
|
+
'deepseek-r1-distill-llama-70b',
|
|
336
|
+
'mixtral-8x7b-32768',
|
|
337
|
+
'gemma2-9b-it',
|
|
338
|
+
'llama3-70b-8192',
|
|
339
|
+
'llama3-8b-8192'
|
|
340
|
+
],
|
|
341
|
+
capabilities: {
|
|
342
|
+
streaming: true,
|
|
343
|
+
caching: false, // No caching implementation
|
|
344
|
+
embeddings: false,
|
|
345
|
+
vision: false
|
|
346
|
+
},
|
|
347
|
+
costs: {
|
|
348
|
+
inputPerMillion: 0, // Free tier
|
|
349
|
+
outputPerMillion: 0 // Free tier
|
|
350
|
+
},
|
|
351
|
+
location: 'cloud'
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Shutdown the provider
|
|
356
|
+
*/
|
|
357
|
+
async shutdown() {
|
|
358
|
+
this.isInitialized = false;
|
|
359
|
+
this.logger.info('GroqProvider shutdown', {
|
|
360
|
+
requestCount: this.requestCount
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Track cost (free tier = $0)
|
|
365
|
+
*/
|
|
366
|
+
trackCost(usage) {
|
|
367
|
+
// Groq free tier has no cost
|
|
368
|
+
// For paid tier, costs would be calculated here
|
|
369
|
+
return 0;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Build chat completion request
|
|
373
|
+
*/
|
|
374
|
+
buildChatRequest(options, model) {
|
|
375
|
+
const messages = [];
|
|
376
|
+
// Add system messages
|
|
377
|
+
if (options.system && options.system.length > 0) {
|
|
378
|
+
const systemContent = options.system.map(s => s.text).join('\n\n');
|
|
379
|
+
messages.push({
|
|
380
|
+
role: 'system',
|
|
381
|
+
content: systemContent
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
// Add conversation messages
|
|
385
|
+
for (const message of options.messages) {
|
|
386
|
+
const content = typeof message.content === 'string'
|
|
387
|
+
? message.content
|
|
388
|
+
: message.content.map(c => c.text || '').join('');
|
|
389
|
+
messages.push({
|
|
390
|
+
role: message.role,
|
|
391
|
+
content
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
return {
|
|
395
|
+
model,
|
|
396
|
+
messages,
|
|
397
|
+
temperature: options.temperature ?? 0.7,
|
|
398
|
+
max_tokens: options.maxTokens || 2048,
|
|
399
|
+
stream: false
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Map Groq finish reason to standard stop reason
|
|
404
|
+
*/
|
|
405
|
+
mapStopReason(finishReason) {
|
|
406
|
+
switch (finishReason) {
|
|
407
|
+
case 'stop':
|
|
408
|
+
return 'end_turn';
|
|
409
|
+
case 'length':
|
|
410
|
+
return 'max_tokens';
|
|
411
|
+
case 'content_filter':
|
|
412
|
+
return 'stop_sequence';
|
|
413
|
+
default:
|
|
414
|
+
return 'end_turn';
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Extract retry-after header from rate limit response
|
|
419
|
+
*/
|
|
420
|
+
extractRetryAfter(response) {
|
|
421
|
+
const retryAfter = response.headers.get('retry-after');
|
|
422
|
+
if (!retryAfter)
|
|
423
|
+
return null;
|
|
424
|
+
const seconds = parseInt(retryAfter, 10);
|
|
425
|
+
return isNaN(seconds) ? null : seconds * 1000;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Sleep utility for retry delays
|
|
429
|
+
*/
|
|
430
|
+
sleep(ms) {
|
|
431
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Ensure provider is initialized
|
|
435
|
+
*/
|
|
436
|
+
ensureInitialized() {
|
|
437
|
+
if (!this.isInitialized) {
|
|
438
|
+
throw new ILLMProvider_1.LLMProviderError('GroqProvider not initialized. Call initialize() first.', 'groq', 'NOT_INITIALIZED', false);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
exports.GroqProvider = GroqProvider;
|
|
443
|
+
//# sourceMappingURL=GroqProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GroqProvider.js","sourceRoot":"","sources":["../../src/providers/GroqProvider.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAGH,iDAYwB;AACxB,4CAAyC;AA+FzC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,YAAY;IASvB,YAAY,SAA6B,EAAE;QACzC,IAAI,CAAC,MAAM,GAAG,eAAM,CAAC,WAAW,EAAE,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,MAAM;YAC3B,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,KAAK;YAC5B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,EAAE,aAAa;YAC/C,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,CAAC;YAClC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,gCAAgC;YAC3D,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,yBAAyB;YAC9D,mB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AAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACvD,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAC;QAE7B,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACzC,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC;IAChD,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACK,iBAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM,IAAI,+BAAgB,CACxB,wDAAwD,EACxD,MAAM,EACN,iBAAiB,EACjB,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAvgBD,oCAugBC"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HybridRouterHealthIntegration - Health-aware routing integration for HybridRouter
|
|
3
|
+
*
|
|
4
|
+
* Integrates ProviderHealthMonitor with HybridRouter for:
|
|
5
|
+
* - Real-time health status-based routing decisions
|
|
6
|
+
* - Automatic fallback chain when primary provider is unhealthy
|
|
7
|
+
* - Circuit breaker coordination
|
|
8
|
+
* - Provider ranking by health score
|
|
9
|
+
*
|
|
10
|
+
* @module providers/HybridRouterHealthIntegration
|
|
11
|
+
* @version 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
import { EventEmitter } from 'events';
|
|
14
|
+
import { ProviderHealthMonitor, HealthCheckResult, ProviderHealthConfig } from '../monitoring/ProviderHealthMonitor';
|
|
15
|
+
import { ILLMProvider, LLMCompletionOptions, LLMCompletionResponse } from './ILLMProvider';
|
|
16
|
+
/**
|
|
17
|
+
* Fallback strategy configuration
|
|
18
|
+
*/
|
|
19
|
+
export interface FallbackConfig {
|
|
20
|
+
/** Enable automatic fallback to next healthy provider */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** Maximum number of fallback attempts */
|
|
23
|
+
maxAttempts: number;
|
|
24
|
+
/** Delay between fallback attempts (ms) */
|
|
25
|
+
retryDelay: number;
|
|
26
|
+
/** Prefer providers with lower latency in fallback chain */
|
|
27
|
+
preferLowLatency: boolean;
|
|
28
|
+
/** Prefer providers with higher availability in fallback chain */
|
|
29
|
+
preferHighAvailability: boolean;
|
|
30
|
+
/** Minimum health score (0-1) to consider provider for fallback */
|
|
31
|
+
minHealthScore: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Provider with priority and health info
|
|
35
|
+
*/
|
|
36
|
+
export interface RankedProvider {
|
|
37
|
+
providerId: string;
|
|
38
|
+
provider: ILLMProvider;
|
|
39
|
+
healthScore: number;
|
|
40
|
+
latency: number;
|
|
41
|
+
availability: number;
|
|
42
|
+
isHealthy: boolean;
|
|
43
|
+
circuitState: 'closed' | 'open' | 'half-open';
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Fallback result
|
|
47
|
+
*/
|
|
48
|
+
export interface FallbackResult {
|
|
49
|
+
success: boolean;
|
|
50
|
+
providerId: string;
|
|
51
|
+
attemptCount: number;
|
|
52
|
+
response?: LLMCompletionResponse;
|
|
53
|
+
error?: string;
|
|
54
|
+
fallbackChain: string[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* HybridRouterHealthIntegration - Coordinates health monitoring with routing
|
|
58
|
+
*
|
|
59
|
+
* This class sits between HybridRouter and ProviderHealthMonitor to provide:
|
|
60
|
+
* 1. Health-aware provider selection
|
|
61
|
+
* 2. Intelligent fallback chain based on health metrics
|
|
62
|
+
* 3. Event coordination for health/routing decisions
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const healthMonitor = new ProviderHealthMonitor();
|
|
67
|
+
* const integration = new HybridRouterHealthIntegration(healthMonitor);
|
|
68
|
+
*
|
|
69
|
+
* // Register providers
|
|
70
|
+
* integration.registerProvider('claude', claudeProvider);
|
|
71
|
+
* integration.registerProvider('groq', groqProvider);
|
|
72
|
+
* integration.registerProvider('github-models', githubModelsProvider);
|
|
73
|
+
*
|
|
74
|
+
* // Get ranked providers for routing
|
|
75
|
+
* const ranked = integration.getRankedProviders();
|
|
76
|
+
*
|
|
77
|
+
* // Execute with automatic fallback
|
|
78
|
+
* const result = await integration.executeWithFallback(options);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare class HybridRouterHealthIntegration extends EventEmitter {
|
|
82
|
+
private readonly logger;
|
|
83
|
+
private readonly healthMonitor;
|
|
84
|
+
private readonly fallbackConfig;
|
|
85
|
+
private readonly providers;
|
|
86
|
+
private lastRoutingDecision?;
|
|
87
|
+
constructor(healthMonitor: ProviderHealthMonitor, fallbackConfig?: Partial<FallbackConfig>);
|
|
88
|
+
/**
|
|
89
|
+
* Register a provider for health-aware routing
|
|
90
|
+
*
|
|
91
|
+
* @param providerId - Unique identifier for the provider
|
|
92
|
+
* @param provider - LLM provider instance
|
|
93
|
+
*/
|
|
94
|
+
registerProvider(providerId: string, provider: ILLMProvider): void;
|
|
95
|
+
/**
|
|
96
|
+
* Unregister a provider
|
|
97
|
+
*
|
|
98
|
+
* @param providerId - Provider to unregister
|
|
99
|
+
*/
|
|
100
|
+
unregisterProvider(providerId: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Get all providers ranked by health score
|
|
103
|
+
*
|
|
104
|
+
* Providers are ranked considering:
|
|
105
|
+
* - Current health status
|
|
106
|
+
* - Circuit breaker state
|
|
107
|
+
* - Latency (if preferLowLatency enabled)
|
|
108
|
+
* - Availability (if preferHighAvailability enabled)
|
|
109
|
+
*
|
|
110
|
+
* @returns Array of providers sorted by priority (best first)
|
|
111
|
+
*/
|
|
112
|
+
getRankedProviders(): RankedProvider[];
|
|
113
|
+
/**
|
|
114
|
+
* Get the best available provider based on health
|
|
115
|
+
*
|
|
116
|
+
* @returns Best provider or undefined if none available
|
|
117
|
+
*/
|
|
118
|
+
getBestProvider(): RankedProvider | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* Build fallback chain for a primary provider
|
|
121
|
+
*
|
|
122
|
+
* @param excludeProviderId - Provider ID to exclude (primary)
|
|
123
|
+
* @returns Array of provider IDs in fallback order
|
|
124
|
+
*/
|
|
125
|
+
buildFallbackChain(excludeProviderId?: string): string[];
|
|
126
|
+
/**
|
|
127
|
+
* Execute a completion request with automatic fallback
|
|
128
|
+
*
|
|
129
|
+
* Attempts to execute with the best provider, falling back to
|
|
130
|
+
* alternatives if the primary fails.
|
|
131
|
+
*
|
|
132
|
+
* @param options - Completion options
|
|
133
|
+
* @param preferredProviderId - Optional preferred provider to try first
|
|
134
|
+
* @returns Fallback result with response or error
|
|
135
|
+
*/
|
|
136
|
+
executeWithFallback(options: LLMCompletionOptions, preferredProviderId?: string): Promise<FallbackResult>;
|
|
137
|
+
/**
|
|
138
|
+
* Check if a specific provider is available for use
|
|
139
|
+
*
|
|
140
|
+
* @param providerId - Provider to check
|
|
141
|
+
* @returns True if provider can be used
|
|
142
|
+
*/
|
|
143
|
+
isProviderAvailable(providerId: string): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Get health summary for all providers
|
|
146
|
+
*
|
|
147
|
+
* @returns Map of provider IDs to health status
|
|
148
|
+
*/
|
|
149
|
+
getHealthSummary(): Map<string, {
|
|
150
|
+
healthy: boolean;
|
|
151
|
+
circuitState: string;
|
|
152
|
+
healthScore: number;
|
|
153
|
+
lastCheck: Date;
|
|
154
|
+
}>;
|
|
155
|
+
/**
|
|
156
|
+
* Force health check on all providers
|
|
157
|
+
*
|
|
158
|
+
* @returns Array of health check results
|
|
159
|
+
*/
|
|
160
|
+
forceHealthCheck(): Promise<HealthCheckResult[]>;
|
|
161
|
+
/**
|
|
162
|
+
* Get the last routing decision
|
|
163
|
+
*/
|
|
164
|
+
getLastRoutingDecision(): typeof this.lastRoutingDecision;
|
|
165
|
+
/**
|
|
166
|
+
* Calculate composite health score
|
|
167
|
+
*
|
|
168
|
+
* Score is based on:
|
|
169
|
+
* - Base health status (40%)
|
|
170
|
+
* - Availability (30%)
|
|
171
|
+
* - Latency score (20%)
|
|
172
|
+
* - Circuit state (10%)
|
|
173
|
+
*/
|
|
174
|
+
private calculateHealthScore;
|
|
175
|
+
/**
|
|
176
|
+
* Setup listeners for health monitor events
|
|
177
|
+
*/
|
|
178
|
+
private setupHealthEventListeners;
|
|
179
|
+
/**
|
|
180
|
+
* Delay helper
|
|
181
|
+
*/
|
|
182
|
+
private delay;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Factory function to create integration with default config
|
|
186
|
+
*/
|
|
187
|
+
export declare function createHealthAwareRouter(healthConfig?: Partial<ProviderHealthConfig>, fallbackConfig?: Partial<FallbackConfig>): {
|
|
188
|
+
healthMonitor: ProviderHealthMonitor;
|
|
189
|
+
integration: HybridRouterHealthIntegration;
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=HybridRouterHealthIntegration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HybridRouterHealthIntegration.d.ts","sourceRoot":"","sources":["../../src/providers/HybridRouterHealthIntegration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EACL,qBAAqB,EAErB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EAGtB,MAAM,gBAAgB,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,OAAO,EAAE,OAAO,CAAC;IACjB,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,2CA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