@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,17 +1,21 @@
1
1
  import type { AnalyticsData } from "./types.js";
2
2
  import type { TokenUsage } from "../types/providers.js";
3
3
  import type { ToolCall, ToolResult } from "../types/streamTypes.js";
4
+ /**
5
+ * Raw usage data from Vercel AI SDK (uses different field names)
6
+ */
7
+ interface AISDKUsage {
8
+ promptTokens: number;
9
+ completionTokens: number;
10
+ totalTokens: number;
11
+ }
4
12
  /**
5
13
  * Stream analytics result from Vercel AI SDK streamText
6
14
  */
7
15
  export interface StreamTextResult {
8
16
  textStream: AsyncIterable<string>;
9
17
  text: Promise<string>;
10
- usage: Promise<{
11
- promptTokens: number;
12
- completionTokens: number;
13
- totalTokens: number;
14
- } | undefined>;
18
+ usage: Promise<AISDKUsage | undefined>;
15
19
  response: Promise<{
16
20
  id?: string;
17
21
  model?: string;
@@ -63,3 +67,4 @@ export declare class BaseStreamAnalyticsCollector implements StreamAnalyticsColl
63
67
  * Global instance of stream analytics collector
64
68
  */
65
69
  export declare const streamAnalyticsCollector: BaseStreamAnalyticsCollector;
70
+ export {};
@@ -13,24 +13,24 @@ export class BaseStreamAnalyticsCollector {
13
13
  if (!usage) {
14
14
  logger.debug("No usage data available from stream result");
15
15
  return {
16
- inputTokens: 0,
17
- outputTokens: 0,
18
- totalTokens: 0,
16
+ input: 0,
17
+ output: 0,
18
+ total: 0,
19
19
  };
20
20
  }
21
21
  return {
22
- inputTokens: usage.promptTokens || 0,
23
- outputTokens: usage.completionTokens || 0,
24
- totalTokens: usage.totalTokens ||
22
+ input: usage.promptTokens || 0,
23
+ output: usage.completionTokens || 0,
24
+ total: usage.totalTokens ||
25
25
  (usage.promptTokens || 0) + (usage.completionTokens || 0),
26
26
  };
27
27
  }
28
28
  catch (error) {
29
29
  logger.warn("Failed to collect usage from stream result", { error });
30
30
  return {
31
- inputTokens: 0,
32
- outputTokens: 0,
33
- totalTokens: 0,
31
+ input: 0,
32
+ output: 0,
33
+ total: 0,
34
34
  };
35
35
  }
36
36
  }
@@ -100,7 +100,7 @@ export class BaseStreamAnalyticsCollector {
100
100
  error: error instanceof Error ? error.message : String(error),
101
101
  });
102
102
  // Return minimal analytics on error
103
- return createAnalytics(provider, model, { usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 } }, responseTime, {
103
+ return createAnalytics(provider, model, { usage: { input: 0, output: 0, total: 0 } }, responseTime, {
104
104
  ...metadata,
105
105
  streamingMode: true,
106
106
  analyticsError: true,
@@ -4,16 +4,14 @@ import type { GenerateResult } from "../types/generateTypes.js";
4
4
  import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
5
5
  import type { JsonValue } from "../types/common.js";
6
6
  import type { ChatMessage } from "../types/conversationTypes.js";
7
- import type { AnalyticsData } from "./analytics.js";
7
+ import type { TokenUsage, AnalyticsData } from "../types/providers.js";
8
+ import type { EvaluationData } from "../index.js";
9
+ export type { EvaluationData };
8
10
  export interface TextGenerationResult {
9
11
  content: string;
10
12
  provider?: string;
11
13
  model?: string;
12
- usage?: {
13
- promptTokens?: number;
14
- completionTokens?: number;
15
- totalTokens?: number;
16
- };
14
+ usage?: TokenUsage;
17
15
  responseTime?: number;
18
16
  toolsUsed?: string[];
19
17
  toolExecutions?: Array<{
@@ -30,13 +28,7 @@ export interface TextGenerationResult {
30
28
  category?: string;
31
29
  }>;
32
30
  analytics?: AnalyticsData;
33
- evaluation?: {
34
- relevance: number;
35
- accuracy: number;
36
- completeness: number;
37
- overall: number;
38
- reasoning?: string;
39
- };
31
+ evaluation?: EvaluationData;
40
32
  }
41
33
  /**
42
34
  * Supported AI Provider Names
@@ -105,10 +97,20 @@ export declare enum GoogleAIModels {
105
97
  GEMINI_1_5_FLASH = "gemini-1.5-flash",
106
98
  GEMINI_1_5_FLASH_LITE = "gemini-1.5-flash-lite"
107
99
  }
100
+ /**
101
+ * Supported Models for Anthropic (Direct API)
102
+ */
103
+ export declare enum AnthropicModels {
104
+ CLAUDE_3_5_SONNET = "claude-3-5-sonnet-20241022",
105
+ CLAUDE_3_5_HAIKU = "claude-3-5-haiku-20241022",
106
+ CLAUDE_3_SONNET = "claude-3-sonnet-20240229",
107
+ CLAUDE_3_OPUS = "claude-3-opus-20240229",
108
+ CLAUDE_3_HAIKU = "claude-3-haiku-20240307"
109
+ }
108
110
  /**
109
111
  * Union type of all supported model names
110
112
  */
111
- export type SupportedModelName = BedrockModels | OpenAIModels | VertexModels | GoogleAIModels;
113
+ export type SupportedModelName = BedrockModels | OpenAIModels | VertexModels | GoogleAIModels | AnthropicModels;
112
114
  /**
113
115
  * Provider configuration specifying provider and its available models
114
116
  */
@@ -153,102 +155,10 @@ export interface TextGenerationOptions {
153
155
  content: string;
154
156
  }>;
155
157
  conversationMessages?: ChatMessage[];
158
+ expectedOutcome?: string;
159
+ evaluationCriteria?: string[];
156
160
  }
157
- export type { AnalyticsData };
158
- /**
159
- * Response quality evaluation scores
160
- * Comprehensive evaluation interface for response quality assessment
161
- */
162
- export interface EvaluationData {
163
- relevance: number;
164
- accuracy: number;
165
- completeness: number;
166
- overall: number;
167
- domainAlignment?: number;
168
- terminologyAccuracy?: number;
169
- toolEffectiveness?: number;
170
- isOffTopic: boolean;
171
- alertSeverity: "low" | "medium" | "high" | "none";
172
- reasoning: string;
173
- suggestedImprovements?: string;
174
- evaluationModel: string;
175
- evaluationTime: number;
176
- evaluationDomain?: string;
177
- evaluationProvider?: string;
178
- evaluationAttempt?: number;
179
- evaluationConfig?: {
180
- mode: string;
181
- fallbackUsed: boolean;
182
- costEstimate: number;
183
- };
184
- domainConfig?: {
185
- domainName: string;
186
- domainDescription: string;
187
- keyTerms: string[];
188
- failurePatterns: string[];
189
- successPatterns: string[];
190
- evaluationCriteria?: Record<string, unknown>;
191
- };
192
- domainEvaluation?: {
193
- domainRelevance: number;
194
- terminologyAccuracy: number;
195
- domainExpertise: number;
196
- domainSpecificInsights: string[];
197
- };
198
- }
199
- /**
200
- * BACKWARD COMPATIBILITY: Legacy evaluation interface
201
- * Maintains existing field names for backward compatibility
202
- */
203
- export interface LegacyEvaluationData {
204
- relevance: number;
205
- accuracy: number;
206
- completeness: number;
207
- overall: number;
208
- isOffTopic: boolean;
209
- alertSeverity: "low" | "medium" | "high" | "none";
210
- reasoning: string;
211
- suggestedImprovements?: string;
212
- evaluationModel: string;
213
- evaluationTime: number;
214
- }
215
- /**
216
- * Evaluation system configuration for multi-provider support
217
- */
218
- export interface EvaluationConfig {
219
- provider: string;
220
- model: string;
221
- mode: "fast" | "balanced" | "quality";
222
- fallbackEnabled: boolean;
223
- fallbackProviders: string[];
224
- timeout: number;
225
- maxTokens: number;
226
- temperature: number;
227
- preferCheap: boolean;
228
- maxCostPerEval: number;
229
- retryAttempts: number;
230
- }
231
- /**
232
- * Provider model configuration for evaluation
233
- */
234
- export interface ProviderModelConfig {
235
- provider: string;
236
- models: {
237
- fast: string;
238
- balanced: string;
239
- quality: string;
240
- };
241
- costPerToken: {
242
- input: number;
243
- output: number;
244
- };
245
- requiresApiKey: string[];
246
- performance: {
247
- speed: number;
248
- quality: number;
249
- cost: number;
250
- };
251
- }
161
+ export type { AnalyticsData } from "../types/providers.js";
252
162
  /**
253
163
  * Enhanced result interfaces with optional analytics/evaluation
254
164
  */
@@ -79,6 +79,19 @@ export var GoogleAIModels;
79
79
  GoogleAIModels["GEMINI_1_5_FLASH"] = "gemini-1.5-flash";
80
80
  GoogleAIModels["GEMINI_1_5_FLASH_LITE"] = "gemini-1.5-flash-lite";
81
81
  })(GoogleAIModels || (GoogleAIModels = {}));
82
+ /**
83
+ * Supported Models for Anthropic (Direct API)
84
+ */
85
+ export var AnthropicModels;
86
+ (function (AnthropicModels) {
87
+ // Claude 3.5 Series (Latest)
88
+ AnthropicModels["CLAUDE_3_5_SONNET"] = "claude-3-5-sonnet-20241022";
89
+ AnthropicModels["CLAUDE_3_5_HAIKU"] = "claude-3-5-haiku-20241022";
90
+ // Claude 3 Series (Legacy support)
91
+ AnthropicModels["CLAUDE_3_SONNET"] = "claude-3-sonnet-20240229";
92
+ AnthropicModels["CLAUDE_3_OPUS"] = "claude-3-opus-20240229";
93
+ AnthropicModels["CLAUDE_3_HAIKU"] = "claude-3-haiku-20240307";
94
+ })(AnthropicModels || (AnthropicModels = {}));
82
95
  /**
83
96
  * Default provider configurations
84
97
  */
@@ -54,7 +54,7 @@ export class ProviderFactory {
54
54
  // Try as async factory function first (most providers are async functions)
55
55
  result = await registration.constructor(model, providerName, sdk);
56
56
  }
57
- catch (functionError) {
57
+ catch {
58
58
  // Fallback to constructor - ensure parameters are maintained
59
59
  result = new registration.constructor(model, providerName, sdk);
60
60
  }
package/dist/index.d.ts CHANGED
@@ -83,7 +83,8 @@ export declare function getTelemetryStatus(): {
83
83
  enabled: boolean;
84
84
  initialized: boolean;
85
85
  };
86
- export type { TextGenerationOptions, TextGenerationResult, AnalyticsData, EvaluationData, } from "./core/types.js";
86
+ export type { TextGenerationOptions, TextGenerationResult, AnalyticsData, } from "./core/types.js";
87
+ export type { EvaluationData } from "./types/providers.js";
87
88
  /**
88
89
  * BACKWARD COMPATIBILITY: Legacy generateText function
89
90
  * Provides standalone generateText function for existing code that uses it
@@ -6,6 +6,7 @@ import { promises as fs } from "fs";
6
6
  import path from "path";
7
7
  import crypto from "crypto";
8
8
  import { logger } from "../utils/logger.js";
9
+ import { DEFAULT_CONFIG } from "./types.js";
9
10
  const { readFile, writeFile, readdir, mkdir, unlink, access } = fs;
10
11
  /**
11
12
  * Enhanced Config Manager with automatic backup/restore capabilities
@@ -237,7 +238,6 @@ export default ${JSON.stringify(currentConfig, null, 2)};`;
237
238
  * Generate default configuration
238
239
  */
239
240
  async generateDefaultConfig() {
240
- const { DEFAULT_CONFIG } = await import("./types.js");
241
241
  return {
242
242
  ...DEFAULT_CONFIG,
243
243
  lastUpdated: Date.now(),
@@ -266,7 +266,10 @@ export default ${JSON.stringify(currentConfig, null, 2)};`;
266
266
  throw new Error("Invalid config file format");
267
267
  }
268
268
  catch (error) {
269
- logger.info("Config file not found, generating default...");
269
+ logger.info("Config file not found or invalid, generating default...", {
270
+ error: error instanceof Error ? error.message : String(error),
271
+ configPath: this.configPath,
272
+ });
270
273
  return await this.generateDefaultConfig();
271
274
  }
272
275
  }
@@ -4,30 +4,8 @@
4
4
  * Provides lightweight analytics tracking for AI provider usage,
5
5
  * including tokens, costs, performance metrics, and custom context.
6
6
  */
7
- import type { JsonValue, UnknownRecord } from "../types/common.js";
8
- export interface AnalyticsData {
9
- provider: string;
10
- model: string;
11
- tokens: {
12
- input: number;
13
- output: number;
14
- total: number;
15
- };
16
- cost?: number;
17
- responseTime: number;
18
- context?: Record<string, JsonValue>;
19
- timestamp: string;
20
- evaluation?: {
21
- relevanceScore: number;
22
- accuracyScore: number;
23
- completenessScore: number;
24
- overall: number;
25
- evaluationProvider?: string;
26
- evaluationTime?: number;
27
- evaluationAttempt?: number;
28
- };
29
- costDetails?: UnknownRecord;
30
- }
7
+ import type { AnalyticsData } from "../types/providers.js";
8
+ export type { AnalyticsData, TokenUsage } from "../types/providers.js";
31
9
  /**
32
10
  * Create analytics data structure from AI response
33
11
  */
@@ -19,9 +19,9 @@ export function createAnalytics(provider, model, result, responseTime, context)
19
19
  const analytics = {
20
20
  provider,
21
21
  model,
22
- tokens,
22
+ tokenUsage: tokens,
23
23
  cost,
24
- responseTime,
24
+ requestDuration: responseTime,
25
25
  context: context,
26
26
  timestamp: new Date().toISOString(),
27
27
  };
@@ -40,8 +40,8 @@ export function createAnalytics(provider, model, result, responseTime, context)
40
40
  return {
41
41
  provider,
42
42
  model,
43
- tokens: { input: 0, output: 0, total: 0 },
44
- responseTime,
43
+ tokenUsage: { input: 0, output: 0, total: 0 },
44
+ requestDuration: responseTime,
45
45
  context: context,
46
46
  timestamp: new Date().toISOString(),
47
47
  };
@@ -56,14 +56,11 @@ function extractTokenUsage(result) {
56
56
  typeof result.usage === "object" &&
57
57
  result.usage !== null) {
58
58
  const usage = result.usage;
59
- // Try BaseProvider normalized format first (inputTokens/outputTokens)
60
- if (typeof usage.inputTokens === "number" ||
61
- typeof usage.outputTokens === "number") {
62
- const input = typeof usage.inputTokens === "number" ? usage.inputTokens : 0;
63
- const output = typeof usage.outputTokens === "number" ? usage.outputTokens : 0;
64
- const total = typeof usage.totalTokens === "number"
65
- ? usage.totalTokens
66
- : input + output;
59
+ // Try BaseProvider normalized format first (input/output/total)
60
+ if (typeof usage.input === "number" || typeof usage.output === "number") {
61
+ const input = typeof usage.input === "number" ? usage.input : 0;
62
+ const output = typeof usage.output === "number" ? usage.output : 0;
63
+ const total = typeof usage.total === "number" ? usage.total : input + output;
67
64
  return { input, output, total };
68
65
  }
69
66
  // Try OpenAI/Mistral format (promptTokens/completionTokens)
@@ -71,14 +68,12 @@ function extractTokenUsage(result) {
71
68
  typeof usage.completionTokens === "number") {
72
69
  const input = typeof usage.promptTokens === "number" ? usage.promptTokens : 0;
73
70
  const output = typeof usage.completionTokens === "number" ? usage.completionTokens : 0;
74
- const total = typeof usage.totalTokens === "number"
75
- ? usage.totalTokens
76
- : input + output;
71
+ const total = typeof usage.total === "number" ? usage.total : input + output;
77
72
  return { input, output, total };
78
73
  }
79
74
  // Handle total-only case
80
- if (typeof usage.totalTokens === "number") {
81
- return { input: 0, output: 0, total: usage.totalTokens };
75
+ if (typeof usage.total === "number") {
76
+ return { input: 0, output: 0, total: usage.total };
82
77
  }
83
78
  }
84
79
  // Fallback for edge cases
@@ -1,6 +1,7 @@
1
1
  import type { ValidationSchema } from "../types/typeAliases.js";
2
2
  import type { Tool, LanguageModelV1 } from "ai";
3
- import type { AIProvider, TextGenerationOptions, TextGenerationResult, EnhancedGenerateResult, AnalyticsData, AIProviderName, EvaluationData } from "../core/types.js";
3
+ import type { AIProvider, TextGenerationOptions, TextGenerationResult, EnhancedGenerateResult, AnalyticsData, AIProviderName } from "../core/types.js";
4
+ import type { EvaluationData } from "../index.js";
4
5
  import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
5
6
  import type { UnknownRecord } from "../types/common.js";
6
7
  import type { NeuroLink } from "../neurolink.js";
@@ -76,6 +77,34 @@ export declare abstract class BaseProvider implements AIProvider {
76
77
  * Determine if middleware should be skipped for this request
77
78
  */
78
79
  private shouldSkipMiddleware;
80
+ /**
81
+ * Check if a schema is a Zod schema
82
+ */
83
+ private isZodSchema;
84
+ /**
85
+ * Convert tool execution result from MCP format to standard format
86
+ */
87
+ private convertToolResult;
88
+ /**
89
+ * Create a custom tool from tool definition
90
+ */
91
+ private createCustomToolFromDefinition;
92
+ /**
93
+ * Process custom tools from setupToolExecutor
94
+ */
95
+ private processCustomTools;
96
+ /**
97
+ * Create an external MCP tool
98
+ */
99
+ private createExternalMCPTool;
100
+ /**
101
+ * Process external MCP tools
102
+ */
103
+ private processExternalMCPTools;
104
+ /**
105
+ * Process MCP tools integration
106
+ */
107
+ private processMCPTools;
79
108
  /**
80
109
  * Get all available tools - direct tools are ALWAYS available
81
110
  * MCP tools are added when available (without blocking)