@juspay/neurolink 3.0.0 → 4.0.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.
Files changed (192) hide show
  1. package/CHANGELOG.md +62 -4
  2. package/README.md +235 -2
  3. package/dist/agent/direct-tools.d.ts +6 -6
  4. package/dist/chat/client-utils.d.ts +92 -0
  5. package/dist/chat/client-utils.js +298 -0
  6. package/dist/chat/index.d.ts +27 -0
  7. package/dist/chat/index.js +41 -0
  8. package/dist/chat/session-storage.d.ts +77 -0
  9. package/dist/chat/session-storage.js +233 -0
  10. package/dist/chat/session.d.ts +95 -0
  11. package/dist/chat/session.js +257 -0
  12. package/dist/chat/sse-handler.d.ts +49 -0
  13. package/dist/chat/sse-handler.js +266 -0
  14. package/dist/chat/types.d.ts +73 -0
  15. package/dist/chat/types.js +5 -0
  16. package/dist/chat/websocket-chat-handler.d.ts +36 -0
  17. package/dist/chat/websocket-chat-handler.js +262 -0
  18. package/dist/cli/commands/config.js +12 -12
  19. package/dist/cli/commands/mcp.js +3 -4
  20. package/dist/cli/index.d.ts +0 -7
  21. package/dist/cli/index.js +256 -27
  22. package/dist/config/configManager.d.ts +60 -0
  23. package/dist/config/configManager.js +300 -0
  24. package/dist/config/types.d.ts +136 -0
  25. package/dist/config/types.js +43 -0
  26. package/dist/core/analytics.d.ts +23 -0
  27. package/dist/core/analytics.js +131 -0
  28. package/dist/core/constants.d.ts +41 -0
  29. package/dist/core/constants.js +50 -0
  30. package/dist/core/defaults.d.ts +18 -0
  31. package/dist/core/defaults.js +29 -0
  32. package/dist/core/evaluation-config.d.ts +29 -0
  33. package/dist/core/evaluation-config.js +144 -0
  34. package/dist/core/evaluation-providers.d.ts +30 -0
  35. package/dist/core/evaluation-providers.js +187 -0
  36. package/dist/core/evaluation.d.ts +117 -0
  37. package/dist/core/evaluation.js +528 -0
  38. package/dist/core/factory.js +33 -25
  39. package/dist/core/types.d.ts +165 -6
  40. package/dist/core/types.js +3 -4
  41. package/dist/index.d.ts +9 -4
  42. package/dist/index.js +25 -4
  43. package/dist/lib/agent/direct-tools.d.ts +6 -6
  44. package/dist/lib/chat/client-utils.d.ts +92 -0
  45. package/dist/lib/chat/client-utils.js +298 -0
  46. package/dist/lib/chat/index.d.ts +27 -0
  47. package/dist/lib/chat/index.js +41 -0
  48. package/dist/lib/chat/session-storage.d.ts +77 -0
  49. package/dist/lib/chat/session-storage.js +233 -0
  50. package/dist/lib/chat/session.d.ts +95 -0
  51. package/dist/lib/chat/session.js +257 -0
  52. package/dist/lib/chat/sse-handler.d.ts +49 -0
  53. package/dist/lib/chat/sse-handler.js +266 -0
  54. package/dist/lib/chat/types.d.ts +73 -0
  55. package/dist/lib/chat/types.js +5 -0
  56. package/dist/lib/chat/websocket-chat-handler.d.ts +36 -0
  57. package/dist/lib/chat/websocket-chat-handler.js +262 -0
  58. package/dist/lib/config/configManager.d.ts +60 -0
  59. package/dist/lib/config/configManager.js +300 -0
  60. package/dist/lib/config/types.d.ts +136 -0
  61. package/dist/lib/config/types.js +43 -0
  62. package/dist/lib/core/analytics.d.ts +23 -0
  63. package/dist/lib/core/analytics.js +131 -0
  64. package/dist/lib/core/constants.d.ts +41 -0
  65. package/dist/lib/core/constants.js +50 -0
  66. package/dist/lib/core/defaults.d.ts +18 -0
  67. package/dist/lib/core/defaults.js +29 -0
  68. package/dist/lib/core/evaluation-config.d.ts +29 -0
  69. package/dist/lib/core/evaluation-config.js +144 -0
  70. package/dist/lib/core/evaluation-providers.d.ts +30 -0
  71. package/dist/lib/core/evaluation-providers.js +187 -0
  72. package/dist/lib/core/evaluation.d.ts +117 -0
  73. package/dist/lib/core/evaluation.js +528 -0
  74. package/dist/lib/core/factory.js +33 -26
  75. package/dist/lib/core/types.d.ts +165 -6
  76. package/dist/lib/core/types.js +3 -4
  77. package/dist/lib/index.d.ts +9 -4
  78. package/dist/lib/index.js +25 -4
  79. package/dist/lib/mcp/contracts/mcpContract.d.ts +118 -0
  80. package/dist/lib/mcp/contracts/mcpContract.js +5 -0
  81. package/dist/lib/mcp/function-calling.js +11 -3
  82. package/dist/lib/mcp/logging.js +5 -0
  83. package/dist/lib/mcp/neurolink-mcp-client.js +2 -1
  84. package/dist/lib/mcp/orchestrator.js +18 -9
  85. package/dist/lib/mcp/registry.d.ts +49 -16
  86. package/dist/lib/mcp/registry.js +80 -6
  87. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
  88. package/dist/lib/mcp/tool-integration.js +1 -1
  89. package/dist/lib/mcp/tool-registry.d.ts +55 -34
  90. package/dist/lib/mcp/tool-registry.js +111 -97
  91. package/dist/lib/mcp/unified-mcp.js +6 -1
  92. package/dist/lib/mcp/unified-registry.d.ts +12 -4
  93. package/dist/lib/mcp/unified-registry.js +17 -4
  94. package/dist/lib/neurolink.d.ts +28 -0
  95. package/dist/lib/neurolink.js +48 -4
  96. package/dist/lib/providers/agent-enhanced-provider.d.ts +11 -2
  97. package/dist/lib/providers/agent-enhanced-provider.js +86 -15
  98. package/dist/lib/providers/amazonBedrock.d.ts +9 -1
  99. package/dist/lib/providers/amazonBedrock.js +26 -2
  100. package/dist/lib/providers/analytics-helper.d.ts +53 -0
  101. package/dist/lib/providers/analytics-helper.js +151 -0
  102. package/dist/lib/providers/anthropic.d.ts +11 -1
  103. package/dist/lib/providers/anthropic.js +29 -4
  104. package/dist/lib/providers/azureOpenAI.d.ts +3 -1
  105. package/dist/lib/providers/azureOpenAI.js +28 -4
  106. package/dist/lib/providers/function-calling-provider.d.ts +9 -1
  107. package/dist/lib/providers/function-calling-provider.js +14 -1
  108. package/dist/lib/providers/googleAIStudio.d.ts +15 -1
  109. package/dist/lib/providers/googleAIStudio.js +32 -2
  110. package/dist/lib/providers/googleVertexAI.d.ts +9 -1
  111. package/dist/lib/providers/googleVertexAI.js +31 -2
  112. package/dist/lib/providers/huggingFace.d.ts +3 -1
  113. package/dist/lib/providers/huggingFace.js +26 -3
  114. package/dist/lib/providers/mcp-provider.d.ts +9 -1
  115. package/dist/lib/providers/mcp-provider.js +12 -0
  116. package/dist/lib/providers/mistralAI.d.ts +3 -1
  117. package/dist/lib/providers/mistralAI.js +25 -2
  118. package/dist/lib/providers/ollama.d.ts +3 -1
  119. package/dist/lib/providers/ollama.js +27 -4
  120. package/dist/lib/providers/openAI.d.ts +15 -1
  121. package/dist/lib/providers/openAI.js +32 -2
  122. package/dist/lib/proxy/proxy-fetch.js +8 -7
  123. package/dist/lib/services/streaming/streaming-manager.d.ts +29 -0
  124. package/dist/lib/services/streaming/streaming-manager.js +244 -0
  125. package/dist/lib/services/types.d.ts +155 -0
  126. package/dist/lib/services/types.js +2 -0
  127. package/dist/lib/services/websocket/websocket-server.d.ts +34 -0
  128. package/dist/lib/services/websocket/websocket-server.js +304 -0
  129. package/dist/lib/telemetry/index.d.ts +15 -0
  130. package/dist/lib/telemetry/index.js +22 -0
  131. package/dist/lib/telemetry/telemetry-service.d.ts +47 -0
  132. package/dist/lib/telemetry/telemetry-service.js +259 -0
  133. package/dist/lib/utils/streaming-utils.d.ts +67 -0
  134. package/dist/lib/utils/streaming-utils.js +201 -0
  135. package/dist/mcp/contracts/mcpContract.d.ts +118 -0
  136. package/dist/mcp/contracts/mcpContract.js +5 -0
  137. package/dist/mcp/function-calling.js +11 -3
  138. package/dist/mcp/logging.js +5 -0
  139. package/dist/mcp/neurolink-mcp-client.js +2 -1
  140. package/dist/mcp/orchestrator.js +18 -9
  141. package/dist/mcp/registry.d.ts +49 -16
  142. package/dist/mcp/registry.js +80 -6
  143. package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
  144. package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +5 -4
  145. package/dist/mcp/tool-integration.js +1 -1
  146. package/dist/mcp/tool-registry.d.ts +55 -34
  147. package/dist/mcp/tool-registry.js +111 -97
  148. package/dist/mcp/unified-mcp.js +6 -1
  149. package/dist/mcp/unified-registry.d.ts +12 -4
  150. package/dist/mcp/unified-registry.js +17 -4
  151. package/dist/neurolink.d.ts +28 -0
  152. package/dist/neurolink.js +48 -4
  153. package/dist/providers/agent-enhanced-provider.d.ts +11 -2
  154. package/dist/providers/agent-enhanced-provider.js +86 -15
  155. package/dist/providers/amazonBedrock.d.ts +9 -1
  156. package/dist/providers/amazonBedrock.js +26 -2
  157. package/dist/providers/analytics-helper.d.ts +53 -0
  158. package/dist/providers/analytics-helper.js +151 -0
  159. package/dist/providers/anthropic.d.ts +11 -1
  160. package/dist/providers/anthropic.js +29 -4
  161. package/dist/providers/azureOpenAI.d.ts +3 -1
  162. package/dist/providers/azureOpenAI.js +29 -4
  163. package/dist/providers/function-calling-provider.d.ts +9 -1
  164. package/dist/providers/function-calling-provider.js +14 -1
  165. package/dist/providers/googleAIStudio.d.ts +15 -1
  166. package/dist/providers/googleAIStudio.js +32 -2
  167. package/dist/providers/googleVertexAI.d.ts +9 -1
  168. package/dist/providers/googleVertexAI.js +31 -2
  169. package/dist/providers/huggingFace.d.ts +3 -1
  170. package/dist/providers/huggingFace.js +26 -3
  171. package/dist/providers/mcp-provider.d.ts +9 -1
  172. package/dist/providers/mcp-provider.js +12 -0
  173. package/dist/providers/mistralAI.d.ts +3 -1
  174. package/dist/providers/mistralAI.js +25 -2
  175. package/dist/providers/ollama.d.ts +3 -1
  176. package/dist/providers/ollama.js +27 -4
  177. package/dist/providers/openAI.d.ts +15 -1
  178. package/dist/providers/openAI.js +33 -2
  179. package/dist/proxy/proxy-fetch.js +8 -7
  180. package/dist/services/streaming/streaming-manager.d.ts +29 -0
  181. package/dist/services/streaming/streaming-manager.js +244 -0
  182. package/dist/services/types.d.ts +155 -0
  183. package/dist/services/types.js +2 -0
  184. package/dist/services/websocket/websocket-server.d.ts +34 -0
  185. package/dist/services/websocket/websocket-server.js +304 -0
  186. package/dist/telemetry/index.d.ts +15 -0
  187. package/dist/telemetry/index.js +22 -0
  188. package/dist/telemetry/telemetry-service.d.ts +47 -0
  189. package/dist/telemetry/telemetry-service.js +261 -0
  190. package/dist/utils/streaming-utils.d.ts +67 -0
  191. package/dist/utils/streaming-utils.js +201 -0
  192. package/package.json +18 -2
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Central configuration constants for NeuroLink
3
+ * Single source of truth for all default values
4
+ */
5
+ // Core AI Generation Defaults
6
+ export const DEFAULT_MAX_TOKENS = 10000;
7
+ export const DEFAULT_TEMPERATURE = 0.7;
8
+ export const DEFAULT_TIMEOUT = 30000;
9
+ // Specialized Use Case Defaults
10
+ export const DEFAULT_EVALUATION_MAX_TOKENS = 500; // Keep evaluation fast
11
+ export const DEFAULT_ANALYSIS_MAX_TOKENS = 800; // For analysis tools
12
+ export const DEFAULT_DOCUMENTATION_MAX_TOKENS = 12000; // For documentation generation
13
+ // Provider-specific configurations
14
+ export const PROVIDER_CONFIG = {
15
+ evaluation: {
16
+ maxTokens: DEFAULT_EVALUATION_MAX_TOKENS,
17
+ model: "gemini-2.5-flash",
18
+ temperature: 0.3, // Lower temperature for consistent evaluation
19
+ },
20
+ analysis: {
21
+ maxTokens: DEFAULT_ANALYSIS_MAX_TOKENS,
22
+ temperature: 0.5,
23
+ },
24
+ documentation: {
25
+ maxTokens: DEFAULT_DOCUMENTATION_MAX_TOKENS,
26
+ temperature: 0.4,
27
+ },
28
+ };
29
+ // CLI Validation Limits
30
+ export const CLI_LIMITS = {
31
+ maxTokens: {
32
+ min: 1,
33
+ max: 50000,
34
+ default: DEFAULT_MAX_TOKENS,
35
+ },
36
+ temperature: {
37
+ min: 0,
38
+ max: 2,
39
+ default: DEFAULT_TEMPERATURE,
40
+ },
41
+ };
42
+ // Environment Variable Support (for future use)
43
+ export const ENV_DEFAULTS = {
44
+ maxTokens: process.env.NEUROLINK_DEFAULT_MAX_TOKENS
45
+ ? parseInt(process.env.NEUROLINK_DEFAULT_MAX_TOKENS, 10)
46
+ : DEFAULT_MAX_TOKENS,
47
+ temperature: process.env.NEUROLINK_DEFAULT_TEMPERATURE
48
+ ? parseFloat(process.env.NEUROLINK_DEFAULT_TEMPERATURE)
49
+ : DEFAULT_TEMPERATURE,
50
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Default value helper functions for NeuroLink
3
+ * Centralized logic for applying defaults across the system
4
+ */
5
+ /**
6
+ * Apply default values to options object
7
+ * User-provided values take precedence over defaults
8
+ */
9
+ export declare function applyDefaults(options: any): any;
10
+ /**
11
+ * Get default max tokens for a specific provider
12
+ * Can be extended for provider-specific overrides in the future
13
+ */
14
+ export declare function getDefaultMaxTokens(provider?: string): number;
15
+ /**
16
+ * Get default temperature for a specific use case
17
+ */
18
+ export declare function getDefaultTemperature(useCase?: string): number;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Default value helper functions for NeuroLink
3
+ * Centralized logic for applying defaults across the system
4
+ */
5
+ import { DEFAULT_MAX_TOKENS, DEFAULT_TEMPERATURE, ENV_DEFAULTS, } from "./constants.js";
6
+ /**
7
+ * Apply default values to options object
8
+ * User-provided values take precedence over defaults
9
+ */
10
+ export function applyDefaults(options) {
11
+ return {
12
+ maxTokens: ENV_DEFAULTS.maxTokens,
13
+ temperature: ENV_DEFAULTS.temperature,
14
+ ...options, // User overrides take precedence
15
+ };
16
+ }
17
+ /**
18
+ * Get default max tokens for a specific provider
19
+ * Can be extended for provider-specific overrides in the future
20
+ */
21
+ export function getDefaultMaxTokens(provider) {
22
+ return ENV_DEFAULTS.maxTokens;
23
+ }
24
+ /**
25
+ * Get default temperature for a specific use case
26
+ */
27
+ export function getDefaultTemperature(useCase) {
28
+ return ENV_DEFAULTS.temperature;
29
+ }
@@ -0,0 +1,29 @@
1
+ import type { EvaluationConfig } from "./types.js";
2
+ /**
3
+ * Parse evaluation configuration from environment variables
4
+ */
5
+ export declare function parseEvaluationConfig(): EvaluationConfig;
6
+ /**
7
+ * Get intelligent provider fallback order
8
+ */
9
+ export declare function getProviderFallbackOrder(config: EvaluationConfig): string[];
10
+ /**
11
+ * Estimate evaluation cost
12
+ */
13
+ export declare function estimateEvaluationCost(providerName: string, mode: string, promptLength: number, expectedResponseLength?: number): number;
14
+ /**
15
+ * Validate evaluation configuration
16
+ */
17
+ export declare function validateEvaluationConfig(config: EvaluationConfig): string[];
18
+ /**
19
+ * Get configuration with validation and defaults
20
+ */
21
+ export declare function getValidatedEvaluationConfig(): EvaluationConfig;
22
+ /**
23
+ * Check if evaluation is enabled for the current configuration
24
+ */
25
+ export declare function isEvaluationEnabled(): boolean;
26
+ /**
27
+ * Get cost-optimized provider based on configuration
28
+ */
29
+ export declare function getCostOptimizedProvider(config: EvaluationConfig): string | null;
@@ -0,0 +1,144 @@
1
+ import { getAvailableProviders, sortProvidersByPreference, getProviderConfig, } from "./evaluation-providers.js";
2
+ import { logger } from "../utils/logger.js";
3
+ /**
4
+ * Parse evaluation configuration from environment variables
5
+ */
6
+ export function parseEvaluationConfig() {
7
+ return {
8
+ provider: process.env.NEUROLINK_EVALUATION_PROVIDER || "google-ai",
9
+ model: process.env.NEUROLINK_EVALUATION_MODEL || "gemini-2.5-flash",
10
+ mode: process.env.NEUROLINK_EVALUATION_MODE || "fast",
11
+ fallbackEnabled: process.env.NEUROLINK_EVALUATION_FALLBACK_ENABLED !== "false",
12
+ fallbackProviders: (process.env.NEUROLINK_EVALUATION_FALLBACK_PROVIDERS ||
13
+ "openai,anthropic,vertex,bedrock").split(","),
14
+ timeout: parseInt(process.env.NEUROLINK_EVALUATION_TIMEOUT || "10000"),
15
+ maxTokens: parseInt(process.env.NEUROLINK_EVALUATION_MAX_TOKENS || "500"),
16
+ temperature: parseFloat(process.env.NEUROLINK_EVALUATION_TEMPERATURE || "0.1"),
17
+ preferCheap: process.env.NEUROLINK_EVALUATION_PREFER_CHEAP !== "false",
18
+ maxCostPerEval: parseFloat(process.env.NEUROLINK_EVALUATION_MAX_COST_PER_EVAL || "0.01"),
19
+ retryAttempts: parseInt(process.env.NEUROLINK_EVALUATION_RETRY_ATTEMPTS || "2"),
20
+ };
21
+ }
22
+ /**
23
+ * Get intelligent provider fallback order
24
+ */
25
+ export function getProviderFallbackOrder(config) {
26
+ const available = getAvailableProviders();
27
+ const sorted = sortProvidersByPreference(available, config.preferCheap);
28
+ // Start with user's preferred provider
29
+ const fallbackOrder = [config.provider];
30
+ // Add configured fallbacks
31
+ config.fallbackProviders.forEach((provider) => {
32
+ if (!fallbackOrder.includes(provider)) {
33
+ fallbackOrder.push(provider);
34
+ }
35
+ });
36
+ // Add remaining available providers
37
+ sorted.forEach((providerConfig) => {
38
+ if (!fallbackOrder.includes(providerConfig.provider)) {
39
+ fallbackOrder.push(providerConfig.provider);
40
+ }
41
+ });
42
+ logger.debug("[EvaluationConfig] Provider fallback order:", fallbackOrder);
43
+ return fallbackOrder;
44
+ }
45
+ /**
46
+ * Estimate evaluation cost
47
+ */
48
+ export function estimateEvaluationCost(providerName, mode, promptLength, expectedResponseLength = 200) {
49
+ const config = getProviderConfig(providerName);
50
+ if (!config || !config.costPerToken) {
51
+ return 0;
52
+ }
53
+ const inputTokens = Math.ceil(promptLength / 4); // Rough token estimation
54
+ const outputTokens = expectedResponseLength / 4;
55
+ return (inputTokens * config.costPerToken.input +
56
+ outputTokens * config.costPerToken.output);
57
+ }
58
+ /**
59
+ * Validate evaluation configuration
60
+ */
61
+ export function validateEvaluationConfig(config) {
62
+ const errors = [];
63
+ // Validate provider
64
+ if (!getProviderConfig(config.provider)) {
65
+ errors.push(`Invalid provider: ${config.provider}`);
66
+ }
67
+ // Validate mode
68
+ if (!["fast", "balanced", "quality"].includes(config.mode)) {
69
+ errors.push(`Invalid mode: ${config.mode}. Must be 'fast', 'balanced', or 'quality'`);
70
+ }
71
+ // Validate timeout
72
+ if (config.timeout <= 0 || config.timeout > 60000) {
73
+ errors.push(`Invalid timeout: ${config.timeout}. Must be between 1 and 60000ms`);
74
+ }
75
+ // Validate max tokens
76
+ if (config.maxTokens <= 0 || config.maxTokens > 4000) {
77
+ errors.push(`Invalid maxTokens: ${config.maxTokens}. Must be between 1 and 4000`);
78
+ }
79
+ // Validate temperature
80
+ if (config.temperature < 0 || config.temperature > 2) {
81
+ errors.push(`Invalid temperature: ${config.temperature}. Must be between 0 and 2`);
82
+ }
83
+ // Validate max cost
84
+ if (config.maxCostPerEval <= 0) {
85
+ errors.push(`Invalid maxCostPerEval: ${config.maxCostPerEval}. Must be greater than 0`);
86
+ }
87
+ // Validate retry attempts
88
+ if (config.retryAttempts < 0 || config.retryAttempts > 5) {
89
+ errors.push(`Invalid retryAttempts: ${config.retryAttempts}. Must be between 0 and 5`);
90
+ }
91
+ return errors;
92
+ }
93
+ /**
94
+ * Get configuration with validation and defaults
95
+ */
96
+ export function getValidatedEvaluationConfig() {
97
+ const config = parseEvaluationConfig();
98
+ const errors = validateEvaluationConfig(config);
99
+ if (errors.length > 0) {
100
+ logger.warn("[EvaluationConfig] Configuration validation errors:", errors);
101
+ // Return default configuration if validation fails
102
+ return {
103
+ provider: "google-ai",
104
+ model: "gemini-2.5-flash",
105
+ mode: "fast",
106
+ fallbackEnabled: true,
107
+ fallbackProviders: ["openai", "anthropic"],
108
+ timeout: 10000,
109
+ maxTokens: 500,
110
+ temperature: 0.1,
111
+ preferCheap: true,
112
+ maxCostPerEval: 0.01,
113
+ retryAttempts: 2,
114
+ };
115
+ }
116
+ return config;
117
+ }
118
+ /**
119
+ * Check if evaluation is enabled for the current configuration
120
+ */
121
+ export function isEvaluationEnabled() {
122
+ // Check if at least one provider is available
123
+ const available = getAvailableProviders();
124
+ return available.length > 0;
125
+ }
126
+ /**
127
+ * Get cost-optimized provider based on configuration
128
+ */
129
+ export function getCostOptimizedProvider(config) {
130
+ const available = getAvailableProviders();
131
+ if (available.length === 0) {
132
+ return null;
133
+ }
134
+ const sorted = sortProvidersByPreference(available, true); // Always prefer cheap for cost optimization
135
+ // Find the cheapest provider that meets cost requirements
136
+ for (const providerConfig of sorted) {
137
+ const estimatedCost = estimateEvaluationCost(providerConfig.provider, config.mode, 1000);
138
+ if (estimatedCost <= config.maxCostPerEval) {
139
+ return providerConfig.provider;
140
+ }
141
+ }
142
+ // If no provider meets cost requirements, return the cheapest one
143
+ return sorted[0].provider;
144
+ }
@@ -0,0 +1,30 @@
1
+ import type { ProviderModelConfig } from "./types.js";
2
+ /**
3
+ * Comprehensive provider configurations for evaluation
4
+ * All 9 NeuroLink providers with cost and performance data
5
+ */
6
+ export declare const EVALUATION_PROVIDER_CONFIGS: Record<string, ProviderModelConfig>;
7
+ /**
8
+ * Get provider configuration by name
9
+ */
10
+ export declare function getProviderConfig(providerName: string): ProviderModelConfig | null;
11
+ /**
12
+ * Get all available providers with required API keys present
13
+ */
14
+ export declare function getAvailableProviders(): ProviderModelConfig[];
15
+ /**
16
+ * Sort providers by preference (cost, speed, quality)
17
+ */
18
+ export declare function sortProvidersByPreference(providers: ProviderModelConfig[], preferCheap?: boolean): ProviderModelConfig[];
19
+ /**
20
+ * Estimate cost for a specific provider and token usage
21
+ */
22
+ export declare function estimateProviderCost(providerName: string, inputTokens: number, outputTokens: number): number;
23
+ /**
24
+ * Check if a provider is available (has required API keys)
25
+ */
26
+ export declare function isProviderAvailable(providerName: string): boolean;
27
+ /**
28
+ * Get the best available provider based on preference
29
+ */
30
+ export declare function getBestAvailableProvider(preferCheap?: boolean): ProviderModelConfig | null;
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Comprehensive provider configurations for evaluation
3
+ * All 9 NeuroLink providers with cost and performance data
4
+ */
5
+ export const EVALUATION_PROVIDER_CONFIGS = {
6
+ "google-ai": {
7
+ provider: "google-ai",
8
+ models: {
9
+ fast: "gemini-2.5-flash",
10
+ balanced: "gemini-2.5-pro",
11
+ quality: "gemini-2.5-pro",
12
+ },
13
+ costPerToken: { input: 0.000075, output: 0.0003 },
14
+ requiresApiKey: ["GOOGLE_AI_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY"],
15
+ performance: { speed: 3, quality: 3, cost: 3 },
16
+ },
17
+ openai: {
18
+ provider: "openai",
19
+ models: {
20
+ fast: "gpt-4o-mini",
21
+ balanced: "gpt-4o",
22
+ quality: "gpt-4o",
23
+ },
24
+ costPerToken: { input: 0.00015, output: 0.0006 },
25
+ requiresApiKey: ["OPENAI_API_KEY"],
26
+ performance: { speed: 2, quality: 3, cost: 2 },
27
+ },
28
+ anthropic: {
29
+ provider: "anthropic",
30
+ models: {
31
+ fast: "claude-3-haiku-20240307",
32
+ balanced: "claude-3-sonnet-20240229",
33
+ quality: "claude-3-opus-20240229",
34
+ },
35
+ costPerToken: { input: 0.00025, output: 0.00125 },
36
+ requiresApiKey: ["ANTHROPIC_API_KEY"],
37
+ performance: { speed: 2, quality: 3, cost: 2 },
38
+ },
39
+ vertex: {
40
+ provider: "vertex",
41
+ models: {
42
+ fast: "gemini-2.5-flash",
43
+ balanced: "gemini-2.5-pro",
44
+ quality: "gemini-2.5-pro",
45
+ },
46
+ costPerToken: { input: 0.000075, output: 0.0003 },
47
+ requiresApiKey: [
48
+ "GOOGLE_VERTEX_PROJECT",
49
+ "GOOGLE_APPLICATION_CREDENTIALS",
50
+ ],
51
+ performance: { speed: 2, quality: 3, cost: 3 },
52
+ },
53
+ bedrock: {
54
+ provider: "bedrock",
55
+ models: {
56
+ fast: "anthropic.claude-3-haiku-20240307-v1:0",
57
+ balanced: "anthropic.claude-3-sonnet-20240229-v1:0",
58
+ quality: "anthropic.claude-3-opus-20240229-v1:0",
59
+ },
60
+ costPerToken: { input: 0.00025, output: 0.00125 },
61
+ requiresApiKey: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"],
62
+ performance: { speed: 2, quality: 3, cost: 2 },
63
+ },
64
+ azure: {
65
+ provider: "azure",
66
+ models: {
67
+ fast: "gpt-4o-mini",
68
+ balanced: "gpt-4o",
69
+ quality: "gpt-4o",
70
+ },
71
+ costPerToken: { input: 0.00015, output: 0.0006 },
72
+ requiresApiKey: ["AZURE_OPENAI_API_KEY", "AZURE_OPENAI_ENDPOINT"],
73
+ performance: { speed: 2, quality: 3, cost: 2 },
74
+ },
75
+ ollama: {
76
+ provider: "ollama",
77
+ models: {
78
+ fast: "llama3.2:latest",
79
+ balanced: "llama3.1:8b",
80
+ quality: "llama3.1:70b",
81
+ },
82
+ costPerToken: { input: 0, output: 0 }, // Local model
83
+ requiresApiKey: [], // No API key needed
84
+ performance: { speed: 1, quality: 2, cost: 3 },
85
+ },
86
+ huggingface: {
87
+ provider: "huggingface",
88
+ models: {
89
+ fast: "microsoft/DialoGPT-medium",
90
+ balanced: "microsoft/DialoGPT-large",
91
+ quality: "meta-llama/Llama-2-7b-chat-hf",
92
+ },
93
+ costPerToken: { input: 0.0002, output: 0.0006 },
94
+ requiresApiKey: ["HUGGINGFACE_API_KEY"],
95
+ performance: { speed: 1, quality: 2, cost: 2 },
96
+ },
97
+ mistral: {
98
+ provider: "mistral",
99
+ models: {
100
+ fast: "mistral-small-latest",
101
+ balanced: "mistral-medium-latest",
102
+ quality: "mistral-large-latest",
103
+ },
104
+ costPerToken: { input: 0.0002, output: 0.0006 },
105
+ requiresApiKey: ["MISTRAL_API_KEY"],
106
+ performance: { speed: 2, quality: 2, cost: 2 },
107
+ },
108
+ };
109
+ /**
110
+ * Get provider configuration by name
111
+ */
112
+ export function getProviderConfig(providerName) {
113
+ return EVALUATION_PROVIDER_CONFIGS[providerName] || null;
114
+ }
115
+ /**
116
+ * Get all available providers with required API keys present
117
+ */
118
+ export function getAvailableProviders() {
119
+ return Object.values(EVALUATION_PROVIDER_CONFIGS).filter((config) => {
120
+ if (config.requiresApiKey.length === 0) {
121
+ return true;
122
+ } // Ollama
123
+ return config.requiresApiKey.some((key) => process.env[key]);
124
+ });
125
+ }
126
+ /**
127
+ * Sort providers by preference (cost, speed, quality)
128
+ */
129
+ export function sortProvidersByPreference(providers, preferCheap = true) {
130
+ return providers.sort((a, b) => {
131
+ if (preferCheap) {
132
+ // Cost > Speed > Quality for cheap preference
133
+ if (a.performance.cost !== b.performance.cost) {
134
+ return b.performance.cost - a.performance.cost;
135
+ }
136
+ if (a.performance.speed !== b.performance.speed) {
137
+ return b.performance.speed - a.performance.speed;
138
+ }
139
+ return b.performance.quality - a.performance.quality;
140
+ }
141
+ else {
142
+ // Quality > Speed > Cost for quality preference
143
+ if (a.performance.quality !== b.performance.quality) {
144
+ return b.performance.quality - a.performance.quality;
145
+ }
146
+ if (a.performance.speed !== b.performance.speed) {
147
+ return b.performance.speed - a.performance.speed;
148
+ }
149
+ return b.performance.cost - a.performance.cost;
150
+ }
151
+ });
152
+ }
153
+ /**
154
+ * Estimate cost for a specific provider and token usage
155
+ */
156
+ export function estimateProviderCost(providerName, inputTokens, outputTokens) {
157
+ const config = getProviderConfig(providerName);
158
+ if (!config || !config.costPerToken) {
159
+ return 0;
160
+ }
161
+ return (inputTokens * config.costPerToken.input +
162
+ outputTokens * config.costPerToken.output);
163
+ }
164
+ /**
165
+ * Check if a provider is available (has required API keys)
166
+ */
167
+ export function isProviderAvailable(providerName) {
168
+ const config = getProviderConfig(providerName);
169
+ if (!config) {
170
+ return false;
171
+ }
172
+ if (config.requiresApiKey.length === 0) {
173
+ return true;
174
+ } // Ollama
175
+ return config.requiresApiKey.some((key) => process.env[key]);
176
+ }
177
+ /**
178
+ * Get the best available provider based on preference
179
+ */
180
+ export function getBestAvailableProvider(preferCheap = true) {
181
+ const availableProviders = getAvailableProviders();
182
+ if (availableProviders.length === 0) {
183
+ return null;
184
+ }
185
+ const sortedProviders = sortProvidersByPreference(availableProviders, preferCheap);
186
+ return sortedProviders[0];
187
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * NeuroLink Unified Evaluation System
3
+ *
4
+ * Combines Universal Evaluation with Lighthouse-Enhanced capabilities
5
+ * - Domain-aware evaluation with sophisticated context handling
6
+ * - Multi-provider support with fallback strategies
7
+ * - Structured output with Zod schema validation
8
+ * - Tool usage and conversation history analysis
9
+ * - Enterprise-grade reliability and performance
10
+ */
11
+ import type { EvaluationData } from "./types.js";
12
+ import { z } from "zod";
13
+ export interface UnifiedEvaluationResult extends EvaluationData {
14
+ domainAlignment?: number;
15
+ terminologyAccuracy?: number;
16
+ toolEffectiveness?: number;
17
+ contextUtilization?: {
18
+ conversationUsed: boolean;
19
+ toolsUsed: boolean;
20
+ domainKnowledgeUsed: boolean;
21
+ };
22
+ evaluationContext?: {
23
+ domain: string;
24
+ toolsEvaluated: string[];
25
+ conversationTurns: number;
26
+ };
27
+ }
28
+ export interface UnifiedEvaluationContext {
29
+ userQuery: string;
30
+ aiResponse: string;
31
+ context?: Record<string, any>;
32
+ primaryDomain?: string;
33
+ assistantRole?: string;
34
+ toolsUsed?: string[];
35
+ toolContext?: string;
36
+ conversationHistory?: Array<{
37
+ role: "user" | "assistant";
38
+ content: string;
39
+ timestamp?: string;
40
+ }>;
41
+ sessionId?: string;
42
+ userId?: string;
43
+ requestId?: string;
44
+ mode?: "simple" | "enhanced" | "lighthouse";
45
+ }
46
+ /**
47
+ * Unified Evaluation Schema (Lighthouse-compatible with extensions)
48
+ */
49
+ export declare const unifiedEvaluationSchema: z.ZodObject<{
50
+ relevanceScore: z.ZodNumber;
51
+ accuracyScore: z.ZodNumber;
52
+ completenessScore: z.ZodNumber;
53
+ domainAlignment: z.ZodOptional<z.ZodNumber>;
54
+ terminologyAccuracy: z.ZodOptional<z.ZodNumber>;
55
+ toolEffectiveness: z.ZodOptional<z.ZodNumber>;
56
+ isOffTopic: z.ZodBoolean;
57
+ reasoning: z.ZodString;
58
+ suggestedImprovements: z.ZodOptional<z.ZodString>;
59
+ alertSeverity: z.ZodEnum<["low", "medium", "high", "none"]>;
60
+ }, "strip", z.ZodTypeAny, {
61
+ relevanceScore: number;
62
+ accuracyScore: number;
63
+ completenessScore: number;
64
+ isOffTopic: boolean;
65
+ reasoning: string;
66
+ alertSeverity: "low" | "medium" | "high" | "none";
67
+ domainAlignment?: number | undefined;
68
+ terminologyAccuracy?: number | undefined;
69
+ toolEffectiveness?: number | undefined;
70
+ suggestedImprovements?: string | undefined;
71
+ }, {
72
+ relevanceScore: number;
73
+ accuracyScore: number;
74
+ completenessScore: number;
75
+ isOffTopic: boolean;
76
+ reasoning: string;
77
+ alertSeverity: "low" | "medium" | "high" | "none";
78
+ domainAlignment?: number | undefined;
79
+ terminologyAccuracy?: number | undefined;
80
+ toolEffectiveness?: number | undefined;
81
+ suggestedImprovements?: string | undefined;
82
+ }>;
83
+ /**
84
+ * Main unified evaluation function
85
+ */
86
+ export declare function performUnifiedEvaluation(context: UnifiedEvaluationContext): Promise<UnifiedEvaluationResult>;
87
+ /**
88
+ * Enhanced evaluation model selection
89
+ */
90
+ export declare function getEvaluationModel(): Promise<{
91
+ provider: any;
92
+ config: any;
93
+ } | null>;
94
+ /**
95
+ * Create simple evaluation context (backward compatibility)
96
+ */
97
+ export declare function createSimpleEvaluationContext(prompt: string, response: string, context?: Record<string, any>): UnifiedEvaluationContext;
98
+ /**
99
+ * Create enhanced evaluation context
100
+ */
101
+ export declare function createEnhancedEvaluationContext(userQuery: string, aiResponse: string, options?: {
102
+ domain?: string;
103
+ role?: string;
104
+ toolsUsed?: string[];
105
+ conversationHistory?: Array<{
106
+ role: "user" | "assistant";
107
+ content: string;
108
+ }>;
109
+ sessionId?: string;
110
+ context?: Record<string, any>;
111
+ }): UnifiedEvaluationContext;
112
+ export declare function evaluateResponse(prompt: string, response: string, context?: Record<string, any>, evaluationDomain?: string, toolUsageContext?: string, conversationHistory?: Array<{
113
+ role: string;
114
+ content: string;
115
+ timestamp?: string;
116
+ }>): Promise<UnifiedEvaluationResult>;
117
+ export type EvaluationResult = UnifiedEvaluationResult;