@juspay/neurolink 7.29.2 → 7.29.3

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.
Files changed (198) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cli/commands/config.d.ts +83 -83
  3. package/dist/cli/commands/mcp.js +39 -9
  4. package/dist/cli/commands/models.js +25 -21
  5. package/dist/cli/commands/ollama.js +2 -2
  6. package/dist/cli/factories/commandFactory.d.ts +8 -0
  7. package/dist/cli/factories/commandFactory.js +65 -65
  8. package/dist/cli/factories/ollamaCommandFactory.js +3 -1
  9. package/dist/cli/factories/sagemakerCommandFactory.js +3 -2
  10. package/dist/cli/index.d.ts +1 -1
  11. package/dist/cli/index.js +11 -11
  12. package/dist/cli/utils/envManager.js +5 -5
  13. package/dist/cli/utils/ollamaUtils.d.ts +12 -0
  14. package/dist/cli/utils/ollamaUtils.js +58 -42
  15. package/dist/config/configManager.js +5 -2
  16. package/dist/core/analytics.d.ts +2 -24
  17. package/dist/core/analytics.js +12 -17
  18. package/dist/core/baseProvider.d.ts +30 -1
  19. package/dist/core/baseProvider.js +180 -198
  20. package/dist/core/dynamicModels.d.ts +4 -4
  21. package/dist/core/dynamicModels.js +7 -7
  22. package/dist/core/evaluation.d.ts +9 -9
  23. package/dist/core/evaluation.js +117 -65
  24. package/dist/core/evaluationProviders.d.ts +18 -2
  25. package/dist/core/evaluationProviders.js +15 -13
  26. package/dist/core/modelConfiguration.d.ts +63 -0
  27. package/dist/core/modelConfiguration.js +354 -290
  28. package/dist/core/streamAnalytics.d.ts +10 -5
  29. package/dist/core/streamAnalytics.js +10 -10
  30. package/dist/core/types.d.ts +19 -109
  31. package/dist/core/types.js +13 -0
  32. package/dist/factories/providerFactory.js +1 -1
  33. package/dist/index.d.ts +2 -1
  34. package/dist/lib/config/configManager.js +5 -2
  35. package/dist/lib/core/analytics.d.ts +2 -24
  36. package/dist/lib/core/analytics.js +12 -17
  37. package/dist/lib/core/baseProvider.d.ts +30 -1
  38. package/dist/lib/core/baseProvider.js +180 -198
  39. package/dist/lib/core/dynamicModels.js +7 -7
  40. package/dist/lib/core/evaluation.d.ts +9 -9
  41. package/dist/lib/core/evaluation.js +117 -65
  42. package/dist/lib/core/evaluationProviders.d.ts +18 -2
  43. package/dist/lib/core/evaluationProviders.js +15 -13
  44. package/dist/lib/core/modelConfiguration.d.ts +63 -0
  45. package/dist/lib/core/modelConfiguration.js +354 -290
  46. package/dist/lib/core/streamAnalytics.d.ts +10 -5
  47. package/dist/lib/core/streamAnalytics.js +10 -10
  48. package/dist/lib/core/types.d.ts +19 -109
  49. package/dist/lib/core/types.js +13 -0
  50. package/dist/lib/factories/providerFactory.js +1 -1
  51. package/dist/lib/index.d.ts +2 -1
  52. package/dist/lib/mcp/externalServerManager.js +15 -6
  53. package/dist/lib/mcp/factory.js +1 -1
  54. package/dist/lib/mcp/index.d.ts +1 -1
  55. package/dist/lib/mcp/index.js +1 -1
  56. package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
  57. package/dist/lib/mcp/mcpClientFactory.js +3 -0
  58. package/dist/lib/mcp/registry.d.ts +3 -3
  59. package/dist/lib/mcp/registry.js +3 -3
  60. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
  61. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
  62. package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
  63. package/dist/lib/mcp/toolDiscoveryService.js +8 -2
  64. package/dist/lib/mcp/toolRegistry.js +4 -4
  65. package/dist/lib/middleware/builtin/analytics.js +4 -4
  66. package/dist/lib/middleware/builtin/guardrails.js +2 -2
  67. package/dist/lib/middleware/registry.js +11 -2
  68. package/dist/lib/models/modelRegistry.d.ts +1 -1
  69. package/dist/lib/models/modelRegistry.js +3 -3
  70. package/dist/lib/models/modelResolver.d.ts +1 -1
  71. package/dist/lib/models/modelResolver.js +2 -2
  72. package/dist/lib/neurolink.d.ts +116 -0
  73. package/dist/lib/neurolink.js +716 -922
  74. package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
  75. package/dist/lib/providers/amazonSagemaker.js +12 -3
  76. package/dist/lib/providers/anthropic.d.ts +1 -1
  77. package/dist/lib/providers/anthropic.js +7 -6
  78. package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
  79. package/dist/lib/providers/anthropicBaseProvider.js +4 -3
  80. package/dist/lib/providers/azureOpenai.d.ts +1 -1
  81. package/dist/lib/providers/azureOpenai.js +1 -1
  82. package/dist/lib/providers/googleAiStudio.d.ts +1 -1
  83. package/dist/lib/providers/googleAiStudio.js +2 -2
  84. package/dist/lib/providers/googleVertex.d.ts +40 -0
  85. package/dist/lib/providers/googleVertex.js +330 -274
  86. package/dist/lib/providers/huggingFace.js +1 -1
  87. package/dist/lib/providers/mistral.d.ts +1 -1
  88. package/dist/lib/providers/mistral.js +2 -2
  89. package/dist/lib/providers/ollama.d.ts +4 -0
  90. package/dist/lib/providers/ollama.js +38 -18
  91. package/dist/lib/providers/openAI.d.ts +1 -1
  92. package/dist/lib/providers/openAI.js +2 -2
  93. package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
  94. package/dist/lib/providers/sagemaker/client.js +13 -3
  95. package/dist/lib/providers/sagemaker/config.js +5 -1
  96. package/dist/lib/providers/sagemaker/detection.js +19 -9
  97. package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
  98. package/dist/lib/providers/sagemaker/errors.js +103 -20
  99. package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
  100. package/dist/lib/providers/sagemaker/language-model.js +4 -4
  101. package/dist/lib/providers/sagemaker/parsers.js +14 -6
  102. package/dist/lib/providers/sagemaker/streaming.js +14 -3
  103. package/dist/lib/providers/sagemaker/types.d.ts +1 -1
  104. package/dist/lib/proxy/awsProxyIntegration.js +1 -1
  105. package/dist/lib/sdk/toolRegistration.d.ts +1 -1
  106. package/dist/lib/types/cli.d.ts +80 -8
  107. package/dist/lib/types/contextTypes.js +2 -2
  108. package/dist/lib/types/generateTypes.d.ts +4 -6
  109. package/dist/lib/types/providers.d.ts +81 -19
  110. package/dist/lib/types/providers.js +6 -6
  111. package/dist/lib/types/streamTypes.d.ts +4 -6
  112. package/dist/lib/types/typeAliases.d.ts +1 -1
  113. package/dist/lib/utils/analyticsUtils.d.ts +33 -0
  114. package/dist/lib/utils/analyticsUtils.js +76 -0
  115. package/dist/lib/utils/errorHandling.js +4 -1
  116. package/dist/lib/utils/evaluationUtils.d.ts +27 -0
  117. package/dist/lib/utils/evaluationUtils.js +131 -0
  118. package/dist/lib/utils/optionsUtils.js +10 -1
  119. package/dist/lib/utils/performance.d.ts +1 -1
  120. package/dist/lib/utils/performance.js +15 -3
  121. package/dist/lib/utils/providerHealth.d.ts +48 -0
  122. package/dist/lib/utils/providerHealth.js +199 -254
  123. package/dist/lib/utils/providerUtils.js +2 -2
  124. package/dist/lib/utils/timeout.js +8 -3
  125. package/dist/mcp/externalServerManager.js +15 -6
  126. package/dist/mcp/factory.js +1 -1
  127. package/dist/mcp/index.d.ts +1 -1
  128. package/dist/mcp/index.js +1 -1
  129. package/dist/mcp/mcpCircuitBreaker.js +5 -1
  130. package/dist/mcp/mcpClientFactory.js +3 -0
  131. package/dist/mcp/registry.d.ts +3 -3
  132. package/dist/mcp/registry.js +3 -3
  133. package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
  134. package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
  135. package/dist/mcp/servers/utilities/utilityServer.js +1 -1
  136. package/dist/mcp/toolDiscoveryService.js +8 -2
  137. package/dist/mcp/toolRegistry.js +4 -4
  138. package/dist/middleware/builtin/analytics.js +4 -4
  139. package/dist/middleware/builtin/guardrails.js +2 -2
  140. package/dist/middleware/registry.js +11 -2
  141. package/dist/models/modelRegistry.d.ts +1 -1
  142. package/dist/models/modelRegistry.js +3 -3
  143. package/dist/models/modelResolver.d.ts +1 -1
  144. package/dist/models/modelResolver.js +2 -2
  145. package/dist/neurolink.d.ts +116 -0
  146. package/dist/neurolink.js +716 -922
  147. package/dist/providers/amazonSagemaker.d.ts +1 -1
  148. package/dist/providers/amazonSagemaker.js +12 -3
  149. package/dist/providers/anthropic.d.ts +1 -1
  150. package/dist/providers/anthropic.js +7 -6
  151. package/dist/providers/anthropicBaseProvider.d.ts +1 -1
  152. package/dist/providers/anthropicBaseProvider.js +4 -3
  153. package/dist/providers/azureOpenai.d.ts +1 -1
  154. package/dist/providers/azureOpenai.js +1 -1
  155. package/dist/providers/googleAiStudio.d.ts +1 -1
  156. package/dist/providers/googleAiStudio.js +2 -2
  157. package/dist/providers/googleVertex.d.ts +40 -0
  158. package/dist/providers/googleVertex.js +330 -274
  159. package/dist/providers/huggingFace.js +1 -1
  160. package/dist/providers/mistral.d.ts +1 -1
  161. package/dist/providers/mistral.js +2 -2
  162. package/dist/providers/ollama.d.ts +4 -0
  163. package/dist/providers/ollama.js +38 -18
  164. package/dist/providers/openAI.d.ts +1 -1
  165. package/dist/providers/openAI.js +2 -2
  166. package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
  167. package/dist/providers/sagemaker/client.js +13 -3
  168. package/dist/providers/sagemaker/config.js +5 -1
  169. package/dist/providers/sagemaker/detection.js +19 -9
  170. package/dist/providers/sagemaker/errors.d.ts +8 -1
  171. package/dist/providers/sagemaker/errors.js +103 -20
  172. package/dist/providers/sagemaker/language-model.d.ts +3 -3
  173. package/dist/providers/sagemaker/language-model.js +4 -4
  174. package/dist/providers/sagemaker/parsers.js +14 -6
  175. package/dist/providers/sagemaker/streaming.js +14 -3
  176. package/dist/providers/sagemaker/types.d.ts +1 -1
  177. package/dist/proxy/awsProxyIntegration.js +1 -1
  178. package/dist/sdk/toolRegistration.d.ts +1 -1
  179. package/dist/types/cli.d.ts +80 -8
  180. package/dist/types/contextTypes.js +2 -2
  181. package/dist/types/generateTypes.d.ts +4 -6
  182. package/dist/types/providers.d.ts +81 -19
  183. package/dist/types/providers.js +6 -6
  184. package/dist/types/streamTypes.d.ts +4 -6
  185. package/dist/types/typeAliases.d.ts +1 -1
  186. package/dist/utils/analyticsUtils.d.ts +33 -0
  187. package/dist/utils/analyticsUtils.js +76 -0
  188. package/dist/utils/errorHandling.js +4 -1
  189. package/dist/utils/evaluationUtils.d.ts +27 -0
  190. package/dist/utils/evaluationUtils.js +131 -0
  191. package/dist/utils/optionsUtils.js +10 -1
  192. package/dist/utils/performance.d.ts +1 -1
  193. package/dist/utils/performance.js +15 -3
  194. package/dist/utils/providerHealth.d.ts +48 -0
  195. package/dist/utils/providerHealth.js +199 -254
  196. package/dist/utils/providerUtils.js +2 -2
  197. package/dist/utils/timeout.js +8 -3
  198. package/package.json +1 -1
@@ -1,13 +1,14 @@
1
1
  /**
2
- * NeuroLink Unified Evaluation System
2
+ * NeuroLink Evaluation System
3
3
  */
4
4
  import { logger } from "../utils/logger.js";
5
5
  import { AIProviderFactory } from "./factory.js";
6
6
  import { z } from "zod";
7
7
  import { ProviderRegistry } from "../factories/providerRegistry.js";
8
8
  import { modelConfig } from "./modelConfiguration.js";
9
+ import { normalizeEvaluationData } from "../utils/evaluationUtils.js";
9
10
  // Zod schema for validation
10
- const UnifiedEvaluationSchema = z.object({
11
+ const EvaluationSchema = z.object({
11
12
  relevance: z.number().min(1).max(10),
12
13
  accuracy: z.number().min(1).max(10),
13
14
  completeness: z.number().min(1).max(10),
@@ -19,8 +20,8 @@ const UnifiedEvaluationSchema = z.object({
19
20
  /**
20
21
  * Get default evaluation when evaluation fails
21
22
  */
22
- function getDefaultUnifiedEvaluation(reason, evaluationTime, context) {
23
- const functionTag = "getDefaultUnifiedEvaluation";
23
+ function getDefaultEvaluation(reason, evaluationTime, context) {
24
+ const functionTag = "getDefaultEvaluation";
24
25
  logger.debug(`[${functionTag}] Creating default evaluation`, {
25
26
  reason,
26
27
  evaluationTime,
@@ -61,11 +62,14 @@ function getDefaultUnifiedEvaluation(reason, evaluationTime, context) {
61
62
  /**
62
63
  * Parse unified evaluation result from text response
63
64
  */
64
- function parseUnifiedEvaluationResult(response, context) {
65
- const functionTag = "parseUnifiedEvaluationResult";
65
+ function parseEvaluationResult(response, context) {
66
+ const functionTag = "parseEvaluationResult";
66
67
  try {
67
68
  logger.debug(`[${functionTag}] Parsing evaluation response`, {
68
69
  responseLength: response.length,
70
+ domain: context.primaryDomain,
71
+ hasToolUsage: !!context.toolUsage?.length,
72
+ hasConversationHistory: !!context.conversationHistory?.length,
69
73
  });
70
74
  // Try JSON parsing first
71
75
  const jsonMatch = response.match(/\{[^}]*\}/s);
@@ -74,8 +78,11 @@ function parseUnifiedEvaluationResult(response, context) {
74
78
  const parsed = JSON.parse(jsonMatch[0]);
75
79
  return parsed;
76
80
  }
77
- catch (e) {
78
- logger.debug(`[${functionTag}] JSON parsing failed, trying regex`);
81
+ catch (jsonError) {
82
+ logger.debug(`[${functionTag}] JSON parsing failed, trying regex`, {
83
+ error: jsonError instanceof Error ? jsonError.message : String(jsonError),
84
+ jsonContent: jsonMatch[0].substring(0, 100), // First 100 chars for debugging
85
+ });
79
86
  }
80
87
  }
81
88
  // Fallback to regex parsing
@@ -115,14 +122,49 @@ function parseUnifiedEvaluationResult(response, context) {
115
122
  }
116
123
  }
117
124
  }
118
- // Ensure minimum valid scores
119
- return {
125
+ // Ensure minimum valid scores and validate with schema
126
+ // Use context to enhance evaluation data
127
+ const evaluationData = {
120
128
  relevance: result.relevance || 1,
121
129
  accuracy: result.accuracy || 1,
122
130
  completeness: result.completeness || 1,
123
131
  overall: result.overall || 1,
124
- reasoning: result.reasoning || "No detailed reasoning provided",
132
+ domainAlignment: result.domainAlignment || (context.primaryDomain ? 5 : undefined), // Default to 5 if domain-specific
133
+ terminologyAccuracy: result.terminologyAccuracy || (context.primaryDomain ? 5 : undefined),
134
+ toolEffectiveness: result.toolEffectiveness || (context.toolUsage?.length ? 5 : undefined), // Default to 5 if tools were used
125
135
  };
136
+ // Validate against schema
137
+ try {
138
+ const validated = EvaluationSchema.parse(evaluationData);
139
+ // Enhance reasoning with context information
140
+ let enhancedReasoning = result.reasoning || "No detailed reasoning provided";
141
+ if (context.primaryDomain) {
142
+ enhancedReasoning += ` (Domain: ${context.primaryDomain})`;
143
+ }
144
+ if (context.toolUsage?.length) {
145
+ enhancedReasoning += ` (Tools used: ${context.toolUsage.map((t) => t.toolName).join(", ")})`;
146
+ }
147
+ if (context.conversationHistory?.length) {
148
+ enhancedReasoning += ` (Conversation turns: ${context.conversationHistory.length})`;
149
+ }
150
+ return {
151
+ ...validated,
152
+ reasoning: enhancedReasoning,
153
+ };
154
+ }
155
+ catch (validationError) {
156
+ logger.warn(`[${functionTag}] Schema validation failed, using fallback`, {
157
+ validationError,
158
+ originalData: evaluationData,
159
+ });
160
+ return {
161
+ relevance: Math.max(1, Math.min(10, result.relevance || 1)),
162
+ accuracy: Math.max(1, Math.min(10, result.accuracy || 1)),
163
+ completeness: Math.max(1, Math.min(10, result.completeness || 1)),
164
+ overall: Math.max(1, Math.min(10, result.overall || 1)),
165
+ reasoning: result.reasoning || "No detailed reasoning provided",
166
+ };
167
+ }
126
168
  }
127
169
  catch (error) {
128
170
  logger.error(`[${functionTag}] Failed to parse evaluation result`, {
@@ -140,8 +182,8 @@ function parseUnifiedEvaluationResult(response, context) {
140
182
  /**
141
183
  * Main unified evaluation function
142
184
  */
143
- export async function generateUnifiedEvaluation(context) {
144
- const functionTag = "generateUnifiedEvaluation";
185
+ export async function generateEvaluation(context) {
186
+ const functionTag = "generateEvaluation";
145
187
  const startTime = Date.now();
146
188
  logger.debug(`[${functionTag}] Starting evaluation`, {
147
189
  hasUserQuery: !!context.userQuery,
@@ -161,7 +203,7 @@ export async function generateUnifiedEvaluation(context) {
161
203
  const provider = await AIProviderFactory.createProvider(evaluationProvider, evaluationModel);
162
204
  if (!provider) {
163
205
  logger.debug(`[${functionTag}] No evaluation provider available, returning defaults`);
164
- return getDefaultUnifiedEvaluation("no-provider", Date.now() - startTime, context);
206
+ return getDefaultEvaluation("no-provider", Date.now() - startTime, context);
165
207
  }
166
208
  // Create evaluation prompt
167
209
  const prompt = `
@@ -187,68 +229,78 @@ Reasoning: [Provide a detailed explanation of your evaluation, explaining why yo
187
229
  const result = await provider.generate(prompt);
188
230
  if (!result) {
189
231
  logger.debug(`[${functionTag}] No response from provider`);
190
- return getDefaultUnifiedEvaluation("no-response", Date.now() - startTime, context);
232
+ return getDefaultEvaluation("no-response", Date.now() - startTime, context);
191
233
  }
192
234
  // Extract text from result
193
235
  const response = typeof result === "string" ? result : result?.content || String(result);
194
236
  // Parse evaluation result
195
- const parsed = parseUnifiedEvaluationResult(response, context);
196
- // Validate and enhance result
197
- const validatedResult = {
198
- ...parsed,
199
- evaluationModel: `${evaluationProvider}/${evaluationModel}`,
200
- evaluationTime: Date.now() - startTime,
201
- evaluationProvider,
202
- evaluationAttempt: 1,
203
- evaluationConfig: {
204
- mode: "standard",
205
- fallbackUsed: false,
206
- costEstimate: 0.001, // Rough estimate
207
- },
237
+ const parsed = parseEvaluationResult(response, context);
238
+ // Validate and enhance result using schema
239
+ const baseResult = {
240
+ relevance: parsed.relevance || 1,
241
+ accuracy: parsed.accuracy || 1,
242
+ completeness: parsed.completeness || 1,
243
+ overall: parsed.overall || 1,
244
+ domainAlignment: parsed.domainAlignment,
245
+ terminologyAccuracy: parsed.terminologyAccuracy,
246
+ toolEffectiveness: parsed.toolEffectiveness,
208
247
  };
209
- logger.debug(`[${functionTag}] Evaluation completed`, {
210
- relevance: validatedResult.relevance,
211
- accuracy: validatedResult.accuracy,
212
- completeness: validatedResult.completeness,
213
- overall: validatedResult.overall,
214
- evaluationTime: validatedResult.evaluationTime,
215
- });
216
- return validatedResult;
248
+ // Validate against schema before finalizing
249
+ try {
250
+ const validatedScores = EvaluationSchema.parse(baseResult);
251
+ const validatedResult = normalizeEvaluationData({
252
+ ...parsed,
253
+ ...validatedScores,
254
+ evaluationModel: `${evaluationProvider}/${evaluationModel}`,
255
+ evaluationTime: Date.now() - startTime,
256
+ evaluationProvider,
257
+ evaluationAttempt: 1,
258
+ evaluationConfig: {
259
+ mode: "standard",
260
+ fallbackUsed: false,
261
+ costEstimate: 0.001, // Rough estimate
262
+ },
263
+ });
264
+ logger.debug(`[${functionTag}] Schema validation passed`, {
265
+ validatedScores,
266
+ });
267
+ return validatedResult;
268
+ }
269
+ catch (validationError) {
270
+ logger.warn(`[${functionTag}] Schema validation failed in main evaluation`, {
271
+ validationError,
272
+ baseResult,
273
+ });
274
+ // Fallback with clamped values using normalizer
275
+ const validatedResult = normalizeEvaluationData({
276
+ ...parsed,
277
+ relevance: parsed.relevance || 1,
278
+ accuracy: parsed.accuracy || 1,
279
+ completeness: parsed.completeness || 1,
280
+ overall: parsed.overall || 1,
281
+ evaluationModel: `${evaluationProvider}/${evaluationModel}`,
282
+ evaluationTime: Date.now() - startTime,
283
+ evaluationProvider,
284
+ evaluationAttempt: 1,
285
+ evaluationConfig: {
286
+ mode: "standard",
287
+ fallbackUsed: false,
288
+ costEstimate: 0.001, // Rough estimate
289
+ },
290
+ });
291
+ return validatedResult;
292
+ }
217
293
  }
218
294
  catch (error) {
219
295
  logger.error(`[${functionTag}] Evaluation failed`, {
220
296
  error: error instanceof Error ? error.message : String(error),
221
297
  });
222
- return getDefaultUnifiedEvaluation(error instanceof Error ? error.message : "unknown-error", Date.now() - startTime, context);
298
+ return getDefaultEvaluation(error instanceof Error ? error.message : "unknown-error", Date.now() - startTime, context);
223
299
  }
224
300
  }
225
- // Legacy compatibility function with flexible arguments
226
- export async function evaluateResponse(responseOrContext, contextOrUserQuery, userQuery, providedContexts, options, additionalArgs) {
227
- // Handle different call patterns for backward compatibility
228
- let aiResponse;
229
- let context;
230
- if (typeof responseOrContext === "string") {
231
- // Normal call: evaluateResponse(response, context, ...)
232
- aiResponse = responseOrContext;
233
- context = contextOrUserQuery;
234
- }
235
- else {
236
- // Provider call pattern: evaluateResponse(contextObject, userQuery, ...)
237
- context = responseOrContext;
238
- aiResponse =
239
- context?.aiResponse ||
240
- context?.response ||
241
- String(contextOrUserQuery || "");
242
- }
243
- const evalContext = {
244
- userQuery: (typeof userQuery === "string" ? userQuery : "") ||
245
- context?.userQuery ||
246
- (typeof contextOrUserQuery === "string" ? contextOrUserQuery : "") ||
247
- "Generated response",
248
- aiResponse,
249
- context: context,
250
- };
251
- return generateUnifiedEvaluation(evalContext);
301
+ // Simplified evaluation function
302
+ export async function evaluateResponse(context) {
303
+ return generateEvaluation(context);
252
304
  }
253
305
  // Export additional utilities
254
- export { getDefaultUnifiedEvaluation, parseUnifiedEvaluationResult };
306
+ export { getDefaultEvaluation, parseEvaluationResult };
@@ -1,4 +1,19 @@
1
- import type { ProviderModelConfig } from "./types.js";
1
+ interface ProviderModelConfig {
2
+ provider: string;
3
+ models: string[];
4
+ costPerToken?: number | {
5
+ input: number;
6
+ output: number;
7
+ };
8
+ requiresApiKey?: string[];
9
+ performance?: {
10
+ averageLatency?: number;
11
+ reliability?: number;
12
+ speed?: number;
13
+ quality?: number;
14
+ cost?: number;
15
+ };
16
+ }
2
17
  /**
3
18
  * Dynamic provider configurations for evaluation
4
19
  * Now uses configurable system instead of hardcoded values
@@ -22,7 +37,7 @@ export declare function sortProvidersByPreference(providers: ProviderModelConfig
22
37
  * Estimate cost for a specific provider and token usage
23
38
  * Now uses the configurable system
24
39
  */
25
- export declare function estimateProviderCost(providerName: string, inputTokens: number, outputTokens: number): number;
40
+ export declare function estimateProviderCost(providerName: string, input: number, output: number): number;
26
41
  /**
27
42
  * Check if a provider is available (has required API keys)
28
43
  * Now uses the configurable system
@@ -58,3 +73,4 @@ export declare function getProviderPerformanceAnalytics(): Record<string, {
58
73
  * @param providerName - (Optional) The name of the provider to reset. If omitted, resets all providers.
59
74
  */
60
75
  export declare function resetProviderMetrics(providerName?: string): void;
76
+ export {};
@@ -12,7 +12,7 @@ const providerMetrics = new Map();
12
12
  function convertToLegacyFormat(config) {
13
13
  return {
14
14
  provider: config.provider,
15
- models: config.models,
15
+ models: Object.keys(config.models || {}),
16
16
  costPerToken: config.defaultCost,
17
17
  requiresApiKey: config.requiredEnvVars,
18
18
  performance: config.performance,
@@ -57,25 +57,27 @@ export function getAvailableProviders() {
57
57
  */
58
58
  export function sortProvidersByPreference(providers, preferCheap = true) {
59
59
  return providers.sort((a, b) => {
60
+ const aPerf = a.performance || { cost: 0, speed: 0, quality: 0 };
61
+ const bPerf = b.performance || { cost: 0, speed: 0, quality: 0 };
60
62
  if (preferCheap) {
61
63
  // Cost > Speed > Quality for cheap preference
62
- if (a.performance.cost !== b.performance.cost) {
63
- return b.performance.cost - a.performance.cost;
64
+ if ((aPerf.cost || 0) !== (bPerf.cost || 0)) {
65
+ return (bPerf.cost || 0) - (aPerf.cost || 0);
64
66
  }
65
- if (a.performance.speed !== b.performance.speed) {
66
- return b.performance.speed - a.performance.speed;
67
+ if ((aPerf.speed || 0) !== (bPerf.speed || 0)) {
68
+ return (bPerf.speed || 0) - (aPerf.speed || 0);
67
69
  }
68
- return b.performance.quality - a.performance.quality;
70
+ return (bPerf.quality || 0) - (aPerf.quality || 0);
69
71
  }
70
72
  else {
71
73
  // Quality > Speed > Cost for quality preference
72
- if (a.performance.quality !== b.performance.quality) {
73
- return b.performance.quality - a.performance.quality;
74
+ if ((aPerf.quality || 0) !== (bPerf.quality || 0)) {
75
+ return (bPerf.quality || 0) - (aPerf.quality || 0);
74
76
  }
75
- if (a.performance.speed !== b.performance.speed) {
76
- return b.performance.speed - a.performance.speed;
77
+ if ((aPerf.speed || 0) !== (bPerf.speed || 0)) {
78
+ return (bPerf.speed || 0) - (aPerf.speed || 0);
77
79
  }
78
- return b.performance.cost - a.performance.cost;
80
+ return (bPerf.cost || 0) - (aPerf.cost || 0);
79
81
  }
80
82
  });
81
83
  }
@@ -83,12 +85,12 @@ export function sortProvidersByPreference(providers, preferCheap = true) {
83
85
  * Estimate cost for a specific provider and token usage
84
86
  * Now uses the configurable system
85
87
  */
86
- export function estimateProviderCost(providerName, inputTokens, outputTokens) {
88
+ export function estimateProviderCost(providerName, input, output) {
87
89
  const costInfo = modelConfig.getCostInfo(providerName);
88
90
  if (!costInfo) {
89
91
  return 0;
90
92
  }
91
- return inputTokens * costInfo.input + outputTokens * costInfo.output;
93
+ return input * costInfo.input + output * costInfo.output;
92
94
  }
93
95
  /**
94
96
  * Check if a provider is available (has required API keys)
@@ -132,6 +132,50 @@ export declare class ModelConfigurationManager {
132
132
  private lastUpdated;
133
133
  private constructor();
134
134
  static getInstance(): ModelConfigurationManager;
135
+ /**
136
+ * Create Google AI provider configuration
137
+ */
138
+ private createGoogleAIConfig;
139
+ /**
140
+ * Create Google Vertex AI provider configuration
141
+ */
142
+ private createVertexConfig;
143
+ /**
144
+ * Create OpenAI provider configuration
145
+ */
146
+ private createOpenAIConfig;
147
+ /**
148
+ * Create all provider configurations - centralized approach
149
+ */
150
+ private createAllProviderConfigs;
151
+ /**
152
+ * Create Anthropic provider configuration
153
+ */
154
+ private createAnthropicConfig;
155
+ /**
156
+ * Create Vertex alternative provider configuration
157
+ */
158
+ private createVertexAlternativeConfig;
159
+ /**
160
+ * Create Bedrock provider configuration
161
+ */
162
+ private createBedrockConfig;
163
+ /**
164
+ * Create Azure provider configuration
165
+ */
166
+ private createAzureConfig;
167
+ /**
168
+ * Create Ollama provider configuration
169
+ */
170
+ private createOllamaConfig;
171
+ /**
172
+ * Create HuggingFace provider configuration
173
+ */
174
+ private createHuggingFaceConfig;
175
+ /**
176
+ * Create Mistral provider configuration
177
+ */
178
+ private createMistralConfig;
135
179
  /**
136
180
  * Load default configurations (replaces hardcoded values)
137
181
  */
@@ -174,6 +218,25 @@ export declare class ModelConfigurationManager {
174
218
  * Update provider configuration (runtime updates)
175
219
  */
176
220
  updateProviderConfig(provider: string, config: ProviderConfig): void;
221
+ /**
222
+ * Parse YAML content with basic support
223
+ * For full YAML support, would need a proper YAML library
224
+ */
225
+ private parseYAMLContent;
226
+ /**
227
+ * Convert simple YAML to JSON object
228
+ * Handles basic key-value pairs only
229
+ */
230
+ private convertSimpleYAMLToJSON;
231
+ /**
232
+ * Process a single YAML line
233
+ * Returns key-value pair if valid, null otherwise
234
+ */
235
+ private processYAMLLine;
236
+ /**
237
+ * Convert YAML value to appropriate JavaScript type
238
+ */
239
+ private convertYAMLValue;
177
240
  /**
178
241
  * Load configurations from external source
179
242
  */