@juspay/neurolink 5.3.0 → 6.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 (273) hide show
  1. package/CHANGELOG.md +76 -2
  2. package/dist/chat/client-utils.d.ts +3 -0
  3. package/dist/chat/client-utils.js +22 -5
  4. package/dist/chat/index.d.ts +4 -7
  5. package/dist/chat/index.js +0 -8
  6. package/dist/chat/session-storage.d.ts +2 -2
  7. package/dist/chat/session.d.ts +4 -3
  8. package/dist/chat/session.js +1 -1
  9. package/dist/chat/sse-handler.js +13 -21
  10. package/dist/chat/types.d.ts +3 -2
  11. package/dist/chat/websocket-chat-handler.d.ts +4 -3
  12. package/dist/chat/websocket-chat-handler.js +12 -12
  13. package/dist/cli/commands/config.d.ts +2 -2
  14. package/dist/cli/commands/mcp.d.ts +3 -2
  15. package/dist/cli/commands/mcp.js +39 -29
  16. package/dist/cli/commands/ollama.js +8 -4
  17. package/dist/cli/factories/command-factory.d.ts +2 -1
  18. package/dist/cli/index.js +22 -19
  19. package/dist/core/analytics.d.ts +3 -2
  20. package/dist/core/analytics.js +16 -7
  21. package/dist/core/base-provider.d.ts +35 -7
  22. package/dist/core/base-provider.js +36 -13
  23. package/dist/core/defaults.d.ts +2 -1
  24. package/dist/core/evaluation.d.ts +4 -4
  25. package/dist/core/evaluation.js +17 -7
  26. package/dist/core/factory.d.ts +3 -2
  27. package/dist/core/service-registry.d.ts +4 -4
  28. package/dist/core/types.d.ts +11 -4
  29. package/dist/factories/compatibility-factory.d.ts +16 -1
  30. package/dist/factories/compatibility-factory.js +3 -1
  31. package/dist/factories/provider-factory.d.ts +5 -4
  32. package/dist/factories/provider-factory.js +15 -24
  33. package/dist/factories/provider-generate-factory.js +26 -20
  34. package/dist/lib/chat/client-utils.d.ts +3 -0
  35. package/dist/lib/chat/client-utils.js +22 -5
  36. package/dist/lib/chat/index.d.ts +4 -7
  37. package/dist/lib/chat/index.js +0 -8
  38. package/dist/lib/chat/session-storage.d.ts +2 -2
  39. package/dist/lib/chat/session.d.ts +4 -3
  40. package/dist/lib/chat/session.js +1 -1
  41. package/dist/lib/chat/sse-handler.js +13 -21
  42. package/dist/lib/chat/types.d.ts +3 -2
  43. package/dist/lib/chat/websocket-chat-handler.d.ts +4 -3
  44. package/dist/lib/chat/websocket-chat-handler.js +12 -12
  45. package/dist/lib/core/analytics.d.ts +3 -2
  46. package/dist/lib/core/analytics.js +16 -7
  47. package/dist/lib/core/base-provider.d.ts +35 -7
  48. package/dist/lib/core/base-provider.js +36 -13
  49. package/dist/lib/core/defaults.d.ts +2 -1
  50. package/dist/lib/core/evaluation.d.ts +4 -4
  51. package/dist/lib/core/evaluation.js +17 -7
  52. package/dist/lib/core/factory.d.ts +3 -2
  53. package/dist/lib/core/service-registry.d.ts +4 -4
  54. package/dist/lib/core/types.d.ts +11 -4
  55. package/dist/lib/factories/compatibility-factory.d.ts +16 -1
  56. package/dist/lib/factories/compatibility-factory.js +3 -1
  57. package/dist/lib/factories/provider-factory.d.ts +5 -4
  58. package/dist/lib/factories/provider-factory.js +15 -24
  59. package/dist/lib/factories/provider-generate-factory.js +26 -20
  60. package/dist/lib/mcp/adapters/plugin-bridge.d.ts +5 -4
  61. package/dist/lib/mcp/adapters/plugin-bridge.js +13 -6
  62. package/dist/lib/mcp/client.d.ts +2 -1
  63. package/dist/lib/mcp/client.js +12 -10
  64. package/dist/lib/mcp/context-manager.d.ts +1 -1
  65. package/dist/lib/mcp/contracts/mcp-contract.d.ts +15 -8
  66. package/dist/lib/mcp/core/plugin-manager.d.ts +3 -2
  67. package/dist/lib/mcp/core/plugin-manager.js +1 -1
  68. package/dist/lib/mcp/demo/plugin-demo.js +3 -1
  69. package/dist/lib/mcp/dynamic-chain-executor.d.ts +64 -40
  70. package/dist/lib/mcp/dynamic-chain-executor.js +3 -3
  71. package/dist/lib/mcp/dynamic-orchestrator.d.ts +14 -8
  72. package/dist/lib/mcp/ecosystem.d.ts +4 -4
  73. package/dist/lib/mcp/error-manager.d.ts +2 -2
  74. package/dist/lib/mcp/error-recovery.d.ts +4 -3
  75. package/dist/lib/mcp/external-client.d.ts +1 -1
  76. package/dist/lib/mcp/external-client.js +14 -10
  77. package/dist/lib/mcp/external-manager.d.ts +3 -3
  78. package/dist/lib/mcp/external-manager.js +9 -3
  79. package/dist/lib/mcp/factory.d.ts +7 -7
  80. package/dist/lib/mcp/function-calling.d.ts +3 -2
  81. package/dist/lib/mcp/health-monitor.d.ts +2 -1
  82. package/dist/lib/mcp/health-monitor.js +16 -7
  83. package/dist/lib/mcp/index.d.ts +5 -5
  84. package/dist/lib/mcp/initialize-tools.d.ts +2 -1
  85. package/dist/lib/mcp/initialize-tools.js +10 -2
  86. package/dist/lib/mcp/manager.d.ts +2 -1
  87. package/dist/lib/mcp/neurolink-mcp-client.js +1 -1
  88. package/dist/lib/mcp/orchestrator.d.ts +13 -12
  89. package/dist/lib/mcp/orchestrator.js +10 -8
  90. package/dist/lib/mcp/plugin-manager.js +4 -2
  91. package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +3 -2
  92. package/dist/lib/mcp/plugins/core/filesystem-mcp.js +5 -2
  93. package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +2 -1
  94. package/dist/lib/mcp/registry.d.ts +2 -1
  95. package/dist/lib/mcp/registry.js +2 -1
  96. package/dist/lib/mcp/security-manager.d.ts +4 -2
  97. package/dist/lib/mcp/servers/agent/direct-tools-server.js +18 -6
  98. package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -16
  99. package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +21 -17
  100. package/dist/lib/mcp/servers/ai-providers/ai-core-server.d.ts +2 -2
  101. package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +15 -133
  102. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +1 -97
  103. package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +18 -18
  104. package/dist/lib/mcp/session-manager.d.ts +4 -3
  105. package/dist/lib/mcp/session-persistence.js +5 -2
  106. package/dist/lib/mcp/tool-integration.d.ts +3 -2
  107. package/dist/lib/mcp/tool-integration.js +3 -1
  108. package/dist/lib/mcp/tool-registry.d.ts +18 -1
  109. package/dist/lib/mcp/tool-registry.js +11 -8
  110. package/dist/lib/mcp/transport-manager.d.ts +2 -1
  111. package/dist/lib/mcp/transport-manager.js +5 -1
  112. package/dist/lib/mcp/unified-mcp.d.ts +5 -5
  113. package/dist/lib/mcp/unified-registry.d.ts +18 -2
  114. package/dist/lib/mcp/unified-registry.js +52 -3
  115. package/dist/lib/neurolink.d.ts +2 -2
  116. package/dist/lib/neurolink.js +40 -15
  117. package/dist/lib/providers/amazon-bedrock.d.ts +1 -1
  118. package/dist/lib/providers/amazon-bedrock.js +8 -7
  119. package/dist/lib/providers/analytics-helper.d.ts +8 -23
  120. package/dist/lib/providers/analytics-helper.js +95 -33
  121. package/dist/lib/providers/anthropic-baseprovider.d.ts +3 -3
  122. package/dist/lib/providers/anthropic-baseprovider.js +6 -5
  123. package/dist/lib/providers/anthropic.d.ts +2 -2
  124. package/dist/lib/providers/anthropic.js +11 -4
  125. package/dist/lib/providers/azure-openai.d.ts +5 -4
  126. package/dist/lib/providers/azure-openai.js +10 -4
  127. package/dist/lib/providers/function-calling-provider.d.ts +2 -2
  128. package/dist/lib/providers/function-calling-provider.js +1 -1
  129. package/dist/lib/providers/google-ai-studio.d.ts +2 -2
  130. package/dist/lib/providers/google-ai-studio.js +9 -3
  131. package/dist/lib/providers/google-vertex.d.ts +2 -2
  132. package/dist/lib/providers/google-vertex.js +18 -12
  133. package/dist/lib/providers/huggingFace.d.ts +1 -1
  134. package/dist/lib/providers/huggingFace.js +8 -4
  135. package/dist/lib/providers/mcp-provider.d.ts +3 -3
  136. package/dist/lib/providers/mistral.d.ts +34 -27
  137. package/dist/lib/providers/mistral.js +115 -107
  138. package/dist/lib/providers/ollama.d.ts +2 -1
  139. package/dist/lib/providers/ollama.js +43 -3
  140. package/dist/lib/providers/openAI.d.ts +1 -1
  141. package/dist/lib/providers/openAI.js +8 -4
  142. package/dist/lib/proxy/proxy-fetch.js +3 -2
  143. package/dist/lib/sdk/tool-extension.d.ts +12 -12
  144. package/dist/lib/sdk/tool-extension.js +2 -1
  145. package/dist/lib/sdk/tool-registration.d.ts +16 -12
  146. package/dist/lib/sdk/tool-registration.js +3 -2
  147. package/dist/lib/services/types.d.ts +5 -4
  148. package/dist/lib/services/websocket/websocket-server.d.ts +1 -1
  149. package/dist/lib/services/websocket/websocket-server.js +1 -1
  150. package/dist/lib/telemetry/telemetry-service.js +1 -1
  151. package/dist/lib/types/cli.d.ts +247 -0
  152. package/dist/lib/types/cli.js +22 -0
  153. package/dist/lib/types/common.d.ts +76 -0
  154. package/dist/lib/types/common.js +52 -0
  155. package/dist/lib/types/generate-types.d.ts +6 -6
  156. package/dist/lib/types/index.d.ts +12 -0
  157. package/dist/lib/types/index.js +12 -0
  158. package/dist/lib/types/mcp-types.d.ts +7 -7
  159. package/dist/lib/types/providers.d.ts +158 -0
  160. package/dist/lib/types/providers.js +23 -0
  161. package/dist/lib/types/stream-types.d.ts +4 -3
  162. package/dist/lib/types/tools.d.ts +154 -0
  163. package/dist/lib/types/tools.js +24 -0
  164. package/dist/lib/utils/logger.d.ts +5 -5
  165. package/dist/lib/utils/provider-validation.d.ts +2 -1
  166. package/dist/mcp/adapters/plugin-bridge.d.ts +5 -4
  167. package/dist/mcp/adapters/plugin-bridge.js +13 -6
  168. package/dist/mcp/client.d.ts +2 -1
  169. package/dist/mcp/client.js +12 -10
  170. package/dist/mcp/context-manager.d.ts +1 -1
  171. package/dist/mcp/contracts/mcp-contract.d.ts +15 -8
  172. package/dist/mcp/core/plugin-manager.d.ts +3 -2
  173. package/dist/mcp/core/plugin-manager.js +1 -1
  174. package/dist/mcp/demo/plugin-demo.js +3 -1
  175. package/dist/mcp/dynamic-chain-executor.d.ts +64 -40
  176. package/dist/mcp/dynamic-chain-executor.js +3 -3
  177. package/dist/mcp/dynamic-orchestrator.d.ts +14 -8
  178. package/dist/mcp/dynamic-orchestrator.js +1 -1
  179. package/dist/mcp/ecosystem.d.ts +4 -4
  180. package/dist/mcp/error-manager.d.ts +2 -2
  181. package/dist/mcp/error-recovery.d.ts +4 -3
  182. package/dist/mcp/external-client.d.ts +1 -1
  183. package/dist/mcp/external-client.js +14 -10
  184. package/dist/mcp/external-manager.d.ts +3 -3
  185. package/dist/mcp/external-manager.js +9 -3
  186. package/dist/mcp/factory.d.ts +7 -7
  187. package/dist/mcp/function-calling.d.ts +3 -2
  188. package/dist/mcp/health-monitor.d.ts +2 -1
  189. package/dist/mcp/health-monitor.js +16 -7
  190. package/dist/mcp/index.d.ts +5 -5
  191. package/dist/mcp/initialize-tools.d.ts +2 -1
  192. package/dist/mcp/initialize-tools.js +10 -2
  193. package/dist/mcp/manager.d.ts +2 -1
  194. package/dist/mcp/neurolink-mcp-client.js +1 -1
  195. package/dist/mcp/orchestrator.d.ts +13 -12
  196. package/dist/mcp/orchestrator.js +10 -8
  197. package/dist/mcp/plugin-manager.js +4 -2
  198. package/dist/mcp/plugins/core/filesystem-mcp.d.ts +3 -2
  199. package/dist/mcp/plugins/core/filesystem-mcp.js +5 -2
  200. package/dist/mcp/plugins/filesystem-mcp.d.ts +2 -1
  201. package/dist/mcp/registry.d.ts +2 -1
  202. package/dist/mcp/registry.js +2 -1
  203. package/dist/mcp/security-manager.d.ts +4 -2
  204. package/dist/mcp/servers/agent/direct-tools-server.js +19 -6
  205. package/dist/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -16
  206. package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +21 -17
  207. package/dist/mcp/servers/ai-providers/ai-core-server.d.ts +2 -2
  208. package/dist/mcp/servers/ai-providers/ai-core-server.js +15 -132
  209. package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +1 -97
  210. package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +18 -18
  211. package/dist/mcp/session-manager.d.ts +4 -3
  212. package/dist/mcp/session-persistence.js +5 -2
  213. package/dist/mcp/tool-integration.d.ts +3 -2
  214. package/dist/mcp/tool-integration.js +3 -1
  215. package/dist/mcp/tool-registry.d.ts +18 -1
  216. package/dist/mcp/tool-registry.js +11 -8
  217. package/dist/mcp/transport-manager.d.ts +2 -1
  218. package/dist/mcp/transport-manager.js +5 -1
  219. package/dist/mcp/unified-mcp.d.ts +5 -5
  220. package/dist/mcp/unified-registry.d.ts +18 -2
  221. package/dist/mcp/unified-registry.js +52 -3
  222. package/dist/neurolink.d.ts +2 -2
  223. package/dist/neurolink.js +40 -15
  224. package/dist/providers/amazon-bedrock.d.ts +1 -1
  225. package/dist/providers/amazon-bedrock.js +8 -7
  226. package/dist/providers/analytics-helper.d.ts +8 -23
  227. package/dist/providers/analytics-helper.js +95 -33
  228. package/dist/providers/anthropic-baseprovider.d.ts +3 -3
  229. package/dist/providers/anthropic-baseprovider.js +6 -5
  230. package/dist/providers/anthropic.d.ts +2 -2
  231. package/dist/providers/anthropic.js +11 -4
  232. package/dist/providers/azure-openai.d.ts +5 -4
  233. package/dist/providers/azure-openai.js +10 -4
  234. package/dist/providers/function-calling-provider.d.ts +2 -2
  235. package/dist/providers/function-calling-provider.js +1 -1
  236. package/dist/providers/google-ai-studio.d.ts +2 -2
  237. package/dist/providers/google-ai-studio.js +9 -3
  238. package/dist/providers/google-vertex.d.ts +2 -2
  239. package/dist/providers/google-vertex.js +18 -12
  240. package/dist/providers/huggingFace.d.ts +1 -1
  241. package/dist/providers/huggingFace.js +8 -4
  242. package/dist/providers/mcp-provider.d.ts +3 -3
  243. package/dist/providers/mistral.d.ts +34 -27
  244. package/dist/providers/mistral.js +116 -108
  245. package/dist/providers/ollama.d.ts +2 -1
  246. package/dist/providers/ollama.js +43 -3
  247. package/dist/providers/openAI.d.ts +1 -1
  248. package/dist/providers/openAI.js +8 -4
  249. package/dist/proxy/proxy-fetch.js +3 -2
  250. package/dist/sdk/tool-extension.d.ts +12 -12
  251. package/dist/sdk/tool-extension.js +2 -1
  252. package/dist/sdk/tool-registration.d.ts +16 -12
  253. package/dist/sdk/tool-registration.js +3 -2
  254. package/dist/services/types.d.ts +5 -4
  255. package/dist/services/websocket/websocket-server.d.ts +1 -1
  256. package/dist/services/websocket/websocket-server.js +2 -1
  257. package/dist/telemetry/telemetry-service.js +1 -1
  258. package/dist/types/cli.d.ts +247 -0
  259. package/dist/types/cli.js +22 -0
  260. package/dist/types/common.d.ts +76 -0
  261. package/dist/types/common.js +52 -0
  262. package/dist/types/generate-types.d.ts +6 -6
  263. package/dist/types/index.d.ts +12 -0
  264. package/dist/types/index.js +12 -0
  265. package/dist/types/mcp-types.d.ts +7 -7
  266. package/dist/types/providers.d.ts +158 -0
  267. package/dist/types/providers.js +23 -0
  268. package/dist/types/stream-types.d.ts +4 -3
  269. package/dist/types/tools.d.ts +154 -0
  270. package/dist/types/tools.js +25 -0
  271. package/dist/utils/logger.d.ts +5 -5
  272. package/dist/utils/provider-validation.d.ts +2 -1
  273. package/package.json +1 -1
@@ -1,18 +1,15 @@
1
1
  import { logger } from "../utils/logger.js";
2
2
  import { directAgentTools } from "../agent/direct-tools.js";
3
- // Dynamic imports to break circular dependency
4
- // import { evaluateResponse } from "../core/evaluation.js";
5
- // import { getAvailableFunctionTools } from "../mcp/function-calling.js";
6
- // Analytics helper will be dynamically imported when needed
7
3
  /**
8
4
  * Validates if a result contains a valid toolsObject structure
9
5
  * @param result - The result object to validate
10
6
  * @returns true if the result contains a valid toolsObject, false otherwise
11
7
  */
12
8
  function isValidToolsObject(result) {
13
- return (result &&
9
+ return (result !== null &&
14
10
  typeof result === "object" &&
15
- result.toolsObject &&
11
+ "toolsObject" in result &&
12
+ result.toolsObject !== null &&
16
13
  typeof result.toolsObject === "object" &&
17
14
  Object.keys(result.toolsObject).length > 0);
18
15
  }
@@ -101,7 +98,16 @@ export class BaseProvider {
101
98
  parameters: call.args,
102
99
  id: call.toolCallId,
103
100
  })),
104
- toolResults: result?.toolResults,
101
+ toolResults: result?.toolResults
102
+ ? result.toolResults.map((tr) => ({
103
+ toolName: tr.toolName || "unknown",
104
+ status: (tr.status === "error"
105
+ ? "failure"
106
+ : "success"),
107
+ result: tr.result,
108
+ error: tr.error,
109
+ }))
110
+ : undefined,
105
111
  };
106
112
  }
107
113
  catch (error) {
@@ -154,7 +160,19 @@ export class BaseProvider {
154
160
  },
155
161
  provider: this.providerName,
156
162
  model: this.modelName,
157
- toolCalls: result.toolCalls,
163
+ toolCalls: result.toolCalls
164
+ ? result.toolCalls.map((tc) => ({
165
+ toolCallId: tc.toolCallId ||
166
+ tc.id ||
167
+ "unknown",
168
+ toolName: tc.toolName ||
169
+ tc.name ||
170
+ "unknown",
171
+ args: tc.args ||
172
+ tc.parameters ||
173
+ {},
174
+ }))
175
+ : [],
158
176
  toolResults: result.toolResults,
159
177
  };
160
178
  // Enhanced result with analytics and evaluation
@@ -186,8 +204,7 @@ export class BaseProvider {
186
204
  logger.debug(`[BaseProvider] Direct tools: ${Object.keys(this.directTools).join(", ")}`);
187
205
  // Add custom tools from SDK if available
188
206
  logger.debug(`[BaseProvider] Checking SDK: ${!!this.sdk}, has getInMemoryServers: ${this.sdk && typeof this.sdk.getInMemoryServers}`);
189
- if (this.sdk &&
190
- typeof this.sdk.getInMemoryServers === "function") {
207
+ if (this.sdk && typeof this.sdk.getInMemoryServers === "function") {
191
208
  logger.debug(`[BaseProvider] SDK check passed, loading custom tools`);
192
209
  try {
193
210
  const inMemoryServers = this.sdk.getInMemoryServers();
@@ -223,7 +240,10 @@ export class BaseProvider {
223
240
  return result.data;
224
241
  }
225
242
  else {
226
- throw new Error(result.error || "Tool execution failed");
243
+ const errorMsg = typeof result.error === "string"
244
+ ? result.error
245
+ : "Tool execution failed";
246
+ throw new Error(errorMsg);
227
247
  }
228
248
  }
229
249
  return result;
@@ -249,7 +269,9 @@ export class BaseProvider {
249
269
  this.mcpTools = result.toolsObject;
250
270
  }
251
271
  else {
252
- logger.debug(`Invalid or empty toolsObject for ${this.providerName}: Expected an object with at least one key, but got ${typeof result.toolsObject} with ${result.toolsObject ? Object.keys(result.toolsObject).length : 0} keys. Full result:`, result);
272
+ logger.debug(`Invalid or empty toolsObject for ${this.providerName}: Expected an object with at least one key, but got ${typeof result?.toolsObject} with ${result?.toolsObject
273
+ ? Object.keys(result.toolsObject).length
274
+ : 0} keys. Full result:`, result);
253
275
  }
254
276
  }
255
277
  catch (error) {
@@ -336,7 +358,8 @@ export class BaseProvider {
336
358
  }
337
359
  async createEvaluation(result, options) {
338
360
  const { evaluateResponse } = await import("../core/evaluation.js");
339
- return evaluateResponse(result.content, options.prompt);
361
+ const evaluation = await evaluateResponse(result.content, options.prompt);
362
+ return evaluation;
340
363
  }
341
364
  validateOptions(options) {
342
365
  if (!options.prompt || options.prompt.trim().length === 0) {
@@ -2,11 +2,12 @@
2
2
  * Default value helper functions for NeuroLink
3
3
  * Centralized logic for applying defaults across the system
4
4
  */
5
+ import type { UnknownRecord } from "../types/common.js";
5
6
  /**
6
7
  * Apply default values to options object
7
8
  * User-provided values take precedence over defaults
8
9
  */
9
- export declare function applyDefaults(options: any): any;
10
+ export declare function applyDefaults(options: UnknownRecord): UnknownRecord;
10
11
  /**
11
12
  * Get default max tokens for a specific provider
12
13
  * Can be extended for provider-specific overrides in the future
@@ -23,7 +23,7 @@ export interface UnifiedEvaluationResult extends EvaluationData {
23
23
  export interface UnifiedEvaluationContext {
24
24
  userQuery: string;
25
25
  aiResponse: string;
26
- context?: Record<string, any>;
26
+ context?: Record<string, unknown>;
27
27
  primaryDomain?: string;
28
28
  assistantRole?: string;
29
29
  conversationHistory?: Array<{
@@ -33,8 +33,8 @@ export interface UnifiedEvaluationContext {
33
33
  }>;
34
34
  toolUsage?: Array<{
35
35
  toolName: string;
36
- input: any;
37
- output: any;
36
+ input: unknown;
37
+ output: unknown;
38
38
  executionTime: number;
39
39
  }>;
40
40
  expectedOutcome?: string;
@@ -52,5 +52,5 @@ declare function parseUnifiedEvaluationResult(response: string, context: Unified
52
52
  * Main unified evaluation function
53
53
  */
54
54
  export declare function generateUnifiedEvaluation(context: UnifiedEvaluationContext): Promise<UnifiedEvaluationResult>;
55
- export declare function evaluateResponse(responseOrContext: any, contextOrUserQuery?: any, userQuery?: any, providedContexts?: any, options?: any, additionalArgs?: any): Promise<any>;
55
+ export declare function evaluateResponse(responseOrContext: unknown, contextOrUserQuery?: unknown, userQuery?: unknown, providedContexts?: unknown, options?: unknown, additionalArgs?: unknown): Promise<unknown>;
56
56
  export { getDefaultUnifiedEvaluation, parseUnifiedEvaluationResult };
@@ -90,7 +90,19 @@ function parseUnifiedEvaluationResult(response, context) {
90
90
  if (match) {
91
91
  const value = parseFloat(match[1]);
92
92
  if (value >= 1 && value <= 10) {
93
- result[key] = Math.round(value);
93
+ const roundedValue = Math.round(value);
94
+ if (key === "relevance") {
95
+ result.relevance = roundedValue;
96
+ }
97
+ else if (key === "accuracy") {
98
+ result.accuracy = roundedValue;
99
+ }
100
+ else if (key === "completeness") {
101
+ result.completeness = roundedValue;
102
+ }
103
+ else if (key === "overall") {
104
+ result.overall = roundedValue;
105
+ }
94
106
  }
95
107
  }
96
108
  }
@@ -163,9 +175,7 @@ Overall: [score]
163
175
  return getDefaultUnifiedEvaluation("no-response", Date.now() - startTime, context);
164
176
  }
165
177
  // Extract text from result
166
- const response = typeof result === "string"
167
- ? result
168
- : result.text || String(result);
178
+ const response = typeof result === "string" ? result : result?.content || String(result);
169
179
  // Parse evaluation result
170
180
  const parsed = parseUnifiedEvaluationResult(response, context);
171
181
  // Validate and enhance result
@@ -216,12 +226,12 @@ export async function evaluateResponse(responseOrContext, contextOrUserQuery, us
216
226
  String(contextOrUserQuery || "");
217
227
  }
218
228
  const evalContext = {
219
- userQuery: userQuery ||
229
+ userQuery: (typeof userQuery === "string" ? userQuery : "") ||
220
230
  context?.userQuery ||
221
- contextOrUserQuery ||
231
+ (typeof contextOrUserQuery === "string" ? contextOrUserQuery : "") ||
222
232
  "Generated response",
223
233
  aiResponse,
224
- context,
234
+ context: context,
225
235
  };
226
236
  return generateUnifiedEvaluation(evalContext);
227
237
  }
@@ -1,4 +1,5 @@
1
1
  import type { AIProvider, AIProviderName, SupportedModelName } from "./types.js";
2
+ import type { UnknownRecord } from "../types/common.js";
2
3
  declare const componentIdentifier = "aiProviderFactory";
3
4
  /**
4
5
  * Factory for creating AI provider instances with centralized configuration
@@ -15,7 +16,7 @@ export declare class AIProviderFactory {
15
16
  * @param enableMCP - Optional flag to enable MCP integration (default: true)
16
17
  * @returns AIProvider instance
17
18
  */
18
- static createProvider(providerName: string, modelName?: string | null, enableMCP?: boolean, sdk?: any): Promise<AIProvider>;
19
+ static createProvider(providerName: string, modelName?: string | null, enableMCP?: boolean, sdk?: UnknownRecord): Promise<AIProvider>;
19
20
  /**
20
21
  * Create a provider instance with specific provider enum and model
21
22
  * @param provider - Provider enum value
@@ -30,7 +31,7 @@ export declare class AIProviderFactory {
30
31
  * @param enableMCP - Optional flag to enable MCP integration (default: true)
31
32
  * @returns AIProvider instance
32
33
  */
33
- static createBestProvider(requestedProvider?: string, modelName?: string | null, enableMCP?: boolean, sdk?: any): Promise<AIProvider>;
34
+ static createBestProvider(requestedProvider?: string, modelName?: string | null, enableMCP?: boolean, sdk?: UnknownRecord): Promise<AIProvider>;
34
35
  /**
35
36
  * Create primary and fallback provider instances
36
37
  * @param primaryProvider - Primary provider name
@@ -2,13 +2,13 @@
2
2
  * Service Registry for Dependency Injection
3
3
  * Breaks circular dependencies by providing lazy loading and centralized service management
4
4
  */
5
- export interface ServiceFactory<T = any> {
5
+ export interface ServiceFactory<T = unknown> {
6
6
  (): T | Promise<T>;
7
7
  }
8
- export interface ServiceRegistration {
9
- factory: ServiceFactory;
8
+ export interface ServiceRegistration<T = unknown> {
9
+ factory: ServiceFactory<T>;
10
10
  singleton: boolean;
11
- instance?: any;
11
+ instance?: T;
12
12
  }
13
13
  export declare class ServiceRegistry {
14
14
  private static services;
@@ -2,6 +2,7 @@ import type { ZodType, ZodTypeDef } from "zod";
2
2
  import type { Schema, Tool } from "ai";
3
3
  import type { GenerateResult } from "../types/generate-types.js";
4
4
  import type { StreamOptions, StreamResult } from "../types/stream-types.js";
5
+ import type { JsonValue } from "../types/common.js";
5
6
  export interface TextGenerationResult {
6
7
  content: string;
7
8
  provider?: string;
@@ -26,8 +27,14 @@ export interface TextGenerationResult {
26
27
  server: string;
27
28
  category?: string;
28
29
  }>;
29
- analytics?: any;
30
- evaluation?: any;
30
+ analytics?: AnalyticsData;
31
+ evaluation?: {
32
+ relevance: number;
33
+ accuracy: number;
34
+ completeness: number;
35
+ overall: number;
36
+ reasoning?: string;
37
+ };
31
38
  }
32
39
  /**
33
40
  * Supported AI Provider Names
@@ -118,7 +125,7 @@ export interface TextGenerationOptions {
118
125
  maxSteps?: number;
119
126
  enableEvaluation?: boolean;
120
127
  enableAnalytics?: boolean;
121
- context?: Record<string, any>;
128
+ context?: Record<string, JsonValue>;
122
129
  evaluationDomain?: string;
123
130
  toolUsageContext?: string;
124
131
  conversationHistory?: Array<{
@@ -140,7 +147,7 @@ export interface AnalyticsData {
140
147
  cost?: number;
141
148
  responseTime: number;
142
149
  timestamp: string;
143
- context?: Record<string, any>;
150
+ context?: Record<string, JsonValue>;
144
151
  }
145
152
  /**
146
153
  * Response quality evaluation scores (Lighthouse-Compatible Schema)
@@ -12,7 +12,22 @@ export declare class CompatibilityConversionFactory {
12
12
  /**
13
13
  * Convert GenerateResult to legacy TextGenerationResult format
14
14
  */
15
- static convertGenerateToText(result: GenerateResult): any;
15
+ static convertGenerateToText(result: GenerateResult): {
16
+ content: string;
17
+ provider?: string;
18
+ model?: string;
19
+ usage?: {
20
+ inputTokens: number;
21
+ outputTokens: number;
22
+ totalTokens: number;
23
+ };
24
+ responseTime?: number;
25
+ toolsUsed?: number;
26
+ toolExecutions?: unknown[];
27
+ analytics?: unknown;
28
+ evaluation?: unknown;
29
+ [key: string]: unknown;
30
+ };
16
31
  /**
17
32
  * Convert GenerateOptions to TextGenerationOptions
18
33
  */
@@ -37,7 +37,9 @@ export class CompatibilityConversionFactory {
37
37
  model: result.model,
38
38
  usage: result.usage,
39
39
  responseTime: result.responseTime,
40
- toolsUsed: result.toolsUsed,
40
+ toolsUsed: Array.isArray(result.toolsUsed)
41
+ ? result.toolsUsed.length
42
+ : result.toolsUsed,
41
43
  toolExecutions: result.toolExecutions,
42
44
  enhancedWithTools: result.enhancedWithTools,
43
45
  availableTools: result.availableTools,
@@ -1,10 +1,11 @@
1
1
  import type { AIProvider, AIProviderName } from "../core/types.js";
2
+ import type { UnknownRecord } from "../types/common.js";
2
3
  /**
3
4
  * Provider constructor interface - supports both sync constructors and async factory functions
4
5
  */
5
6
  type ProviderConstructor = {
6
- new (modelName?: string, providerName?: any, sdk?: any): AIProvider;
7
- } | ((modelName?: string, providerName?: any, sdk?: any) => Promise<AIProvider>);
7
+ new (modelName?: string, providerName?: string, sdk?: UnknownRecord): AIProvider;
8
+ } | ((modelName?: string, providerName?: string, sdk?: UnknownRecord) => Promise<AIProvider>);
8
9
  /**
9
10
  * Provider registration entry
10
11
  */
@@ -29,7 +30,7 @@ export declare class ProviderFactory {
29
30
  /**
30
31
  * Create a provider instance
31
32
  */
32
- static createProvider(providerName: AIProviderName | string, modelName?: string, sdk?: any): Promise<AIProvider>;
33
+ static createProvider(providerName: AIProviderName | string, modelName?: string, sdk?: UnknownRecord): Promise<AIProvider>;
33
34
  /**
34
35
  * Check if a provider is registered
35
36
  */
@@ -63,7 +64,7 @@ export declare class ProviderFactory {
63
64
  * Create the best available provider for the given name
64
65
  * Used by NeuroLink SDK for streaming and generation
65
66
  */
66
- static createBestProvider(providerName: AIProviderName | string, modelName?: string, enableMCP?: boolean, sdk?: any): Promise<AIProvider>;
67
+ static createBestProvider(providerName: AIProviderName | string, modelName?: string, enableMCP?: boolean, sdk?: UnknownRecord): Promise<AIProvider>;
67
68
  }
68
69
  /**
69
70
  * Helper function to create providers with backward compatibility
@@ -37,32 +37,23 @@ export class ProviderFactory {
37
37
  }
38
38
  const model = modelName || registration.defaultModel;
39
39
  try {
40
- // Check if constructor is an async factory function or a class constructor
41
- if (typeof registration.constructor === "function") {
42
- // Check if it has a prototype (class constructor) or not (factory function)
43
- if (registration.constructor.prototype &&
44
- registration.constructor.prototype.constructor ===
45
- registration.constructor) {
46
- // It's a class constructor
47
- return new registration.constructor(model, providerName, sdk);
48
- }
49
- else {
50
- // It's a factory function - call it and await if it returns a promise
51
- const result = registration.constructor(model, providerName, sdk);
52
- if (result && typeof result.then === "function") {
53
- // It's a Promise (async factory)
54
- return await result;
55
- }
56
- else {
57
- // It's a sync result, return it
58
- return result;
59
- }
60
- }
40
+ // Try calling as factory function first, then fallback to constructor
41
+ let result;
42
+ try {
43
+ // Try as factory function
44
+ result = registration.constructor(model, providerName, sdk);
61
45
  }
62
- else {
63
- // Fallback - use as class constructor
64
- return new registration.constructor(model, sdk);
46
+ catch (factoryError) {
47
+ // Fallback to constructor
48
+ result = new registration.constructor(model, providerName, sdk);
65
49
  }
50
+ // Only await if result is actually a Promise
51
+ if (result &&
52
+ typeof result === "object" &&
53
+ typeof result.then === "function") {
54
+ return await result;
55
+ }
56
+ return result;
66
57
  }
67
58
  catch (error) {
68
59
  logger.error(`Failed to create provider ${providerName}:`, error);
@@ -37,35 +37,41 @@ export class ProviderGenerateFactory {
37
37
  try {
38
38
  // Use existing generate method for identical performance
39
39
  const textResult = await provider.generate(textOptions);
40
+ if (!textResult) {
41
+ throw new Error("Generate method returned null result");
42
+ }
40
43
  // Convert back to GenerateResult format with type safety
41
44
  const generateResult = {
42
- content: textResult?.content || "",
43
- outputs: { text: textResult?.content || "" },
44
- provider: textResult?.provider,
45
- model: textResult?.model,
46
- usage: textResult?.usage
45
+ content: textResult.content || "",
46
+ outputs: { text: textResult.content || "" },
47
+ provider: textResult.provider,
48
+ model: textResult.model,
49
+ usage: textResult.usage
47
50
  ? {
48
- inputTokens: textResult.usage?.promptTokens || 0,
49
- outputTokens: textResult.usage?.completionTokens || 0,
50
- totalTokens: textResult.usage?.totalTokens || 0,
51
+ inputTokens: textResult.usage.inputTokens || 0,
52
+ outputTokens: textResult.usage.outputTokens || 0,
53
+ totalTokens: textResult.usage.totalTokens || 0,
51
54
  }
52
55
  : undefined,
53
- responseTime: textResult?.responseTime,
54
- toolsUsed: textResult?.toolsUsed,
55
- toolExecutions: textResult?.toolExecutions?.map((te) => ({
56
- name: te.toolName || te.name || "",
57
- input: te.input || {},
58
- output: te.output || te.result,
59
- duration: te.executionTime || te.duration || 0,
60
- })),
61
- enhancedWithTools: textResult?.enhancedWithTools,
62
- availableTools: textResult?.availableTools?.map((at) => ({
56
+ responseTime: textResult.responseTime,
57
+ toolsUsed: textResult.toolsUsed,
58
+ toolExecutions: textResult.toolExecutions?.map((te) => {
59
+ const toolExecution = te;
60
+ return {
61
+ name: toolExecution.toolName || toolExecution.name || "",
62
+ input: toolExecution.input || {},
63
+ output: toolExecution.output || toolExecution.result,
64
+ duration: toolExecution.executionTime || toolExecution.duration || 0,
65
+ };
66
+ }),
67
+ enhancedWithTools: textResult.enhancedWithTools,
68
+ availableTools: textResult.availableTools?.map((at) => ({
63
69
  name: at.name || "",
64
70
  description: at.description || "",
65
71
  parameters: at.parameters || {},
66
72
  })),
67
- analytics: textResult?.analytics,
68
- evaluation: textResult?.evaluation,
73
+ analytics: textResult.analytics,
74
+ evaluation: textResult.evaluation,
69
75
  };
70
76
  return generateResult;
71
77
  }
@@ -3,6 +3,7 @@
3
3
  * Provides compatibility layer for existing MCP integrations
4
4
  */
5
5
  import type { ExecutionContext } from "../contracts/mcp-contract.js";
6
+ import type { JsonValue, UnknownRecord, Unknown } from "../../types/common.js";
6
7
  /**
7
8
  * Bridge interface for legacy MCP compatibility
8
9
  */
@@ -22,18 +23,18 @@ export declare function enhanceExecutionContext(context: ExecutionContext): Exec
22
23
  /**
23
24
  * Utility function to adapt legacy MCP calls
24
25
  */
25
- export declare function adaptLegacyMCPCall(context: ExecutionContext, operation: string, ...args: any[]): Promise<any>;
26
+ export declare function adaptLegacyMCPCall(context: ExecutionContext, operation: string, ...args: JsonValue[]): Promise<Unknown>;
26
27
  /**
27
28
  * Quick plugin factory for simple plugin creation
28
29
  */
29
30
  export declare class QuickPluginFactory {
30
- static create(name: string, config: any): Promise<{
31
+ static create(name: string, config: UnknownRecord): Promise<{
31
32
  name: string;
32
- config: any;
33
+ config: UnknownRecord;
33
34
  initialized: boolean;
34
35
  }>;
35
36
  }
36
37
  /**
37
38
  * Execute plugin with enhanced context
38
39
  */
39
- export declare function executePlugin(plugin: any, context: ExecutionContext, operation: string, ...args: any[]): Promise<any>;
40
+ export declare function executePlugin(plugin: UnknownRecord, context: ExecutionContext, operation: string, ...args: JsonValue[]): Promise<Unknown>;
@@ -46,12 +46,19 @@ export function enhanceExecutionContext(context) {
46
46
  export async function adaptLegacyMCPCall(context, operation, ...args) {
47
47
  const bridge = createLegacyBridge(context);
48
48
  switch (operation) {
49
- case "writeFile":
50
- return bridge.writeFile(args[0], args[1]);
51
- case "readFile":
52
- return bridge.readFile(args[0]);
53
- case "listFiles":
54
- return bridge.listFiles(args[0]);
49
+ case "writeFile": {
50
+ const filePath = typeof args[0] === "string" ? args[0] : String(args[0]);
51
+ const content = typeof args[1] === "string" ? args[1] : String(args[1]);
52
+ return bridge.writeFile(filePath, content);
53
+ }
54
+ case "readFile": {
55
+ const readPath = typeof args[0] === "string" ? args[0] : String(args[0]);
56
+ return bridge.readFile(readPath);
57
+ }
58
+ case "listFiles": {
59
+ const listPath = typeof args[0] === "string" ? args[0] : String(args[0]);
60
+ return bridge.listFiles(listPath);
61
+ }
55
62
  default:
56
63
  throw new Error(`Unsupported legacy operation: ${operation}`);
57
64
  }
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { EventEmitter } from "events";
6
6
  import type { ToolResult, NeuroLinkExecutionContext } from "./factory.js";
7
+ import type { Unknown } from "../types/common.js";
7
8
  /**
8
9
  * MCP Client Configuration
9
10
  */
@@ -28,7 +29,7 @@ export declare class NeuroLinkMCPClient extends EventEmitter {
28
29
  * Register a tool with the MCP client
29
30
  * Following Lighthouse's pattern of namespacing tools with server ID
30
31
  */
31
- registerTool(toolName: string, execute: (name: string, params: Record<string, unknown>) => Promise<any>, description?: string, inputSchema?: unknown): void;
32
+ registerTool(toolName: string, execute: (name: string, params: Record<string, unknown>) => Promise<Unknown>, description?: string, inputSchema?: unknown): void;
32
33
  /**
33
34
  * Get all registered tools
34
35
  */
@@ -49,13 +49,14 @@ export class NeuroLinkMCPClient extends EventEmitter {
49
49
  return result;
50
50
  }
51
51
  // If it's in Lighthouse format with content array
52
- if (result.text &&
53
- Array.isArray(result.text) &&
54
- result.text[0]?.text) {
52
+ const lightouseResult = result;
53
+ if (lightouseResult.text &&
54
+ Array.isArray(lightouseResult.text) &&
55
+ lightouseResult.text[0]?.text) {
55
56
  try {
56
- const data = JSON.parse(result.text[0].text);
57
+ const data = JSON.parse(lightouseResult.text[0].text);
57
58
  return {
58
- success: !result.isError,
59
+ success: !lightouseResult.isError,
59
60
  data,
60
61
  metadata: {
61
62
  toolName,
@@ -68,8 +69,8 @@ export class NeuroLinkMCPClient extends EventEmitter {
68
69
  catch (parseError) {
69
70
  // If JSON parsing fails, return the text as-is
70
71
  return {
71
- success: !result.isError,
72
- data: { text: result.text[0].text },
72
+ success: !lightouseResult.isError,
73
+ data: { text: lightouseResult.text[0].text },
73
74
  metadata: {
74
75
  toolName,
75
76
  serverId,
@@ -80,10 +81,11 @@ export class NeuroLinkMCPClient extends EventEmitter {
80
81
  }
81
82
  }
82
83
  // If it has a direct text property
83
- if (result.text) {
84
+ const textResult = result;
85
+ if (textResult.text) {
84
86
  return {
85
87
  success: true,
86
- data: { text: result.text },
88
+ data: { text: textResult.text },
87
89
  metadata: {
88
90
  toolName,
89
91
  serverId,
@@ -128,7 +130,7 @@ export class NeuroLinkMCPClient extends EventEmitter {
128
130
  */
129
131
  getTools() {
130
132
  const tools = {};
131
- for (const [name, tool] of this.tools) {
133
+ for (const [name, tool] of Array.from(this.tools.entries())) {
132
134
  tools[name] = {
133
135
  name: name, // Include the tool name as a property
134
136
  description: tool.description,
@@ -20,7 +20,7 @@ export interface ContextRequest {
20
20
  frameworkType?: "react" | "vue" | "svelte" | "next" | "nuxt" | "sveltekit";
21
21
  permissions?: string[];
22
22
  securityLevel?: "public" | "private" | "organization";
23
- [key: string]: any;
23
+ [key: string]: unknown;
24
24
  }
25
25
  /**
26
26
  * Context manager for creating and managing execution contexts