@juspay/neurolink 5.3.0 → 6.1.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 +83 -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 +2 -1
@@ -41,7 +41,8 @@ async function listModelsHandler() {
41
41
  }
42
42
  catch (error) {
43
43
  spinner.fail("Failed to list models. Is Ollama installed?");
44
- console.error(chalk.red("Error:", error.message));
44
+ const errorMessage = error instanceof Error ? error.message : String(error);
45
+ console.error(chalk.red("Error:", errorMessage));
45
46
  console.log(chalk.blue("\nTip: Install Ollama from https://ollama.ai"));
46
47
  process.exit(1);
47
48
  }
@@ -57,7 +58,8 @@ async function pullModelHandler(argv) {
57
58
  }
58
59
  catch (error) {
59
60
  console.error(chalk.red(`\n❌ Failed to download ${model}`));
60
- console.error(chalk.red("Error:", error.message));
61
+ const errorMessage = error instanceof Error ? error.message : String(error);
62
+ console.error(chalk.red("Error:", errorMessage));
61
63
  process.exit(1);
62
64
  }
63
65
  }
@@ -83,7 +85,8 @@ async function removeModelHandler(argv) {
83
85
  }
84
86
  catch (error) {
85
87
  spinner.fail(`Failed to remove ${model}`);
86
- console.error(chalk.red("Error:", error.message));
88
+ const errorMessage = error instanceof Error ? error.message : String(error);
89
+ console.error(chalk.red("Error:", errorMessage));
87
90
  process.exit(1);
88
91
  }
89
92
  }
@@ -163,7 +166,8 @@ async function startHandler() {
163
166
  }
164
167
  catch (error) {
165
168
  console.error(chalk.red("Failed to start Ollama service"));
166
- console.error(chalk.red("Error:", error.message));
169
+ const errorMessage = error instanceof Error ? error.message : String(error);
170
+ console.error(chalk.red("Error:", errorMessage));
167
171
  console.log(chalk.blue("\nTry starting Ollama manually or check installation"));
168
172
  process.exit(1);
169
173
  }
@@ -1,4 +1,5 @@
1
1
  import type { CommandModule } from "yargs";
2
+ import type { UnknownRecord } from "../../lib/types/common.js";
2
3
  /**
3
4
  * CLI Command Factory for generate commands
4
5
  */
@@ -10,7 +11,7 @@ export declare class CLICommandFactory {
10
11
  /**
11
12
  * Execute provider status command
12
13
  */
13
- executeProviderStatus(argv: any): Promise<void>;
14
+ executeProviderStatus(argv: UnknownRecord): Promise<void>;
14
15
  /**
15
16
  * Execute the generate command
16
17
  */
package/dist/cli/index.js CHANGED
@@ -23,10 +23,6 @@ import { addMCPCommands } from "./commands/mcp.js";
23
23
  import { addOllamaCommands } from "./commands/ollama.js";
24
24
  import { CLICommandFactory } from "./factories/command-factory.js";
25
25
  import { logger } from "../lib/utils/logger.js";
26
- /**
27
- * Helper functions for displaying analytics and evaluation results
28
- * Addresses DRY principle - extracted shared parts into reusable functions
29
- */
30
26
  function displayDebugInfo(title, data, debug) {
31
27
  if (debug) {
32
28
  console.log(chalk.blue(title));
@@ -45,11 +41,13 @@ function formatAnalytics(analytics) {
45
41
  console.log(` 🚀 Provider: ${analytics.provider}`);
46
42
  console.log(` 🤖 Model: ${analytics.model}`);
47
43
  if (analytics.tokens) {
48
- console.log(` 💬 Tokens: ${analytics.tokens.totalTokens || analytics.tokens.total || "unknown"}`);
44
+ const tokens = analytics.tokens;
45
+ console.log(` 💬 Tokens: ${tokens.totalTokens || tokens.total || "unknown"}`);
49
46
  }
50
47
  console.log(` ⏱️ Response Time: ${analytics.responseTime}ms`);
51
48
  if (analytics.context) {
52
- console.log(` 📋 Context: ${Object.keys(analytics.context).length} fields`);
49
+ const context = analytics.context;
50
+ console.log(` 📋 Context: ${Object.keys(context).length} fields`);
53
51
  }
54
52
  console.log();
55
53
  }
@@ -537,24 +535,27 @@ const cli = yargs(args)
537
535
  console.log("\n" + responseText + "\n");
538
536
  }
539
537
  // Show tool calls if any
540
- if (result &&
541
- result.toolCalls &&
542
- result.toolCalls.length > 0) {
538
+ const typedResultForTools = result;
539
+ if (typedResultForTools &&
540
+ typedResultForTools.toolCalls &&
541
+ typedResultForTools.toolCalls.length > 0) {
543
542
  console.log(chalk.blue("🔧 Tools Called:"));
544
- for (const toolCall of result.toolCalls) {
545
- console.log(`- ${toolCall.toolName}`);
546
- console.log(` Args: ${JSON.stringify(toolCall.args)}`);
543
+ for (const toolCall of typedResultForTools.toolCalls) {
544
+ const toolCallObj = toolCall;
545
+ console.log(`- ${toolCallObj.toolName}`);
546
+ console.log(` Args: ${JSON.stringify(toolCallObj.args)}`);
547
547
  }
548
548
  console.log();
549
549
  }
550
550
  // Show tool results if any
551
- if (result &&
552
- result.toolResults &&
553
- result.toolResults.length > 0) {
551
+ if (typedResultForTools &&
552
+ typedResultForTools.toolResults &&
553
+ typedResultForTools.toolResults.length > 0) {
554
554
  console.log(chalk.blue("📋 Tool Results:"));
555
- for (const toolResult of result.toolResults) {
556
- console.log(`- ${toolResult.toolCallId}`);
557
- console.log(` Result: ${JSON.stringify(toolResult.result).substring(0, 200)}...`);
555
+ for (const toolResult of typedResultForTools.toolResults) {
556
+ const toolResultObj = toolResult;
557
+ console.log(`- ${toolResultObj.toolCallId}`);
558
+ console.log(` Result: ${JSON.stringify(toolResultObj.result).substring(0, 200)}...`);
558
559
  }
559
560
  console.log();
560
561
  }
@@ -578,7 +579,9 @@ const cli = yargs(args)
578
579
  ? result.provider || argv.provider
579
580
  : argv.provider,
580
581
  usage: responseUsage,
581
- responseTime: result ? result.responseTime || 0 : 0,
582
+ responseTime: result
583
+ ? result.responseTime || 0
584
+ : 0,
582
585
  }, null, 2));
583
586
  if (responseUsage.totalTokens) {
584
587
  console.log(chalk.blue(`ℹ️ ${responseUsage.totalTokens} tokens used`));
@@ -4,6 +4,7 @@
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";
7
8
  export interface AnalyticsData {
8
9
  provider: string;
9
10
  model: string;
@@ -14,10 +15,10 @@ export interface AnalyticsData {
14
15
  };
15
16
  cost?: number;
16
17
  responseTime: number;
17
- context?: Record<string, any>;
18
+ context?: Record<string, JsonValue>;
18
19
  timestamp: string;
19
20
  }
20
21
  /**
21
22
  * Create analytics data structure from AI response
22
23
  */
23
- export declare function createAnalytics(provider: string, model: string, result: any, responseTime: number, context?: Record<string, any>): AnalyticsData;
24
+ export declare function createAnalytics(provider: string, model: string, result: UnknownRecord, responseTime: number, context?: Record<string, JsonValue>): AnalyticsData;
@@ -51,23 +51,30 @@ export function createAnalytics(provider, model, result, responseTime, context)
51
51
  */
52
52
  function extractTokenUsage(result) {
53
53
  // Handle different response formats
54
- if (result.usage) {
54
+ if (result.usage &&
55
+ typeof result.usage === "object" &&
56
+ result.usage !== null) {
55
57
  const usage = result.usage;
56
58
  // Standard format
57
- if (usage.promptTokens !== undefined &&
58
- usage.completionTokens !== undefined) {
59
+ if (typeof usage.promptTokens === "number" &&
60
+ typeof usage.completionTokens === "number") {
59
61
  return {
60
62
  input: usage.promptTokens || 0,
61
63
  output: usage.completionTokens || 0,
62
- total: usage.totalTokens || usage.promptTokens + usage.completionTokens,
64
+ total: typeof usage.totalTokens === "number"
65
+ ? usage.totalTokens
66
+ : usage.promptTokens + usage.completionTokens,
63
67
  };
64
68
  }
65
69
  // Alternative formats
66
- if (usage.input_tokens !== undefined && usage.output_tokens !== undefined) {
70
+ if (typeof usage.input_tokens === "number" &&
71
+ typeof usage.output_tokens === "number") {
67
72
  return {
68
73
  input: usage.input_tokens || 0,
69
74
  output: usage.output_tokens || 0,
70
- total: usage.total_tokens || usage.input_tokens + usage.output_tokens,
75
+ total: typeof usage.total_tokens === "number"
76
+ ? usage.total_tokens
77
+ : usage.input_tokens + usage.output_tokens,
71
78
  };
72
79
  }
73
80
  // Generic tokens field
@@ -80,7 +87,9 @@ function extractTokenUsage(result) {
80
87
  }
81
88
  }
82
89
  // Fallback: estimate from text length
83
- const textLength = result.text?.length || result.content?.length || 0;
90
+ const textLength = (typeof result.text === "string" ? result.text.length : 0) ||
91
+ (typeof result.content === "string" ? result.content.length : 0) ||
92
+ 0;
84
93
  const estimatedTokens = Math.ceil(textLength / 4); // ~4 chars per token
85
94
  return {
86
95
  input: 0,
@@ -1,8 +1,35 @@
1
1
  import type { ZodType, ZodTypeDef } from "zod";
2
2
  import type { Schema } from "ai";
3
- import type { Tool } from "ai";
4
- import type { AIProvider, TextGenerationOptions, EnhancedGenerateResult, AnalyticsData, AIProviderName } from "../core/types.js";
3
+ import type { Tool, LanguageModel } from "ai";
4
+ import type { AIProvider, TextGenerationOptions, EnhancedGenerateResult, AnalyticsData, AIProviderName, EvaluationData } from "../core/types.js";
5
5
  import type { StreamOptions, StreamResult } from "../types/stream-types.js";
6
+ import type { JsonValue, UnknownRecord } from "../types/common.js";
7
+ import type { ToolResult } from "../types/tools.js";
8
+ /**
9
+ * Interface for SDK with in-memory MCP servers
10
+ */
11
+ export interface NeuroLinkSDK {
12
+ getInMemoryServers?: () => Map<string, {
13
+ server: {
14
+ title?: string;
15
+ description?: string;
16
+ tools?: Map<string, ToolInfo> | Record<string, ToolInfo>;
17
+ };
18
+ category?: string;
19
+ metadata?: UnknownRecord;
20
+ }>;
21
+ }
22
+ /**
23
+ * Interface for tool information in MCP servers
24
+ */
25
+ interface ToolInfo {
26
+ description?: string;
27
+ inputSchema?: ZodType<JsonValue>;
28
+ parameters?: ZodType<JsonValue>;
29
+ execute: (args: JsonValue) => Promise<JsonValue | ToolResult> | JsonValue | ToolResult;
30
+ isImplemented?: boolean;
31
+ metadata?: UnknownRecord;
32
+ }
6
33
  /**
7
34
  * Abstract base class for all AI providers
8
35
  * Tools are integrated as first-class citizens - always available by default
@@ -354,8 +381,8 @@ export declare abstract class BaseProvider implements AIProvider {
354
381
  protected mcpTools?: Record<string, Tool>;
355
382
  protected sessionId?: string;
356
383
  protected userId?: string;
357
- protected sdk?: any;
358
- constructor(modelName?: string, providerName?: AIProviderName, sdk?: any);
384
+ protected sdk?: NeuroLinkSDK;
385
+ constructor(modelName?: string, providerName?: AIProviderName, sdk?: NeuroLinkSDK);
359
386
  /**
360
387
  * Check if this provider supports tool/function calling
361
388
  * Override in subclasses to disable tools for specific providers or models
@@ -392,7 +419,7 @@ export declare abstract class BaseProvider implements AIProvider {
392
419
  * REQUIRED: Every provider MUST implement this method
393
420
  * Returns the Vercel AI SDK model instance for this provider
394
421
  */
395
- protected abstract getAISDKModel(): any | Promise<any>;
422
+ protected abstract getAISDKModel(): LanguageModel | Promise<LanguageModel>;
396
423
  /**
397
424
  * Get all available tools - direct tools are ALWAYS available
398
425
  * MCP tools are added when available (without blocking)
@@ -405,12 +432,12 @@ export declare abstract class BaseProvider implements AIProvider {
405
432
  /**
406
433
  * Provider-specific error handling
407
434
  */
408
- protected abstract handleProviderError(error: any): Error;
435
+ protected abstract handleProviderError(error: unknown): Error;
409
436
  protected normalizeTextOptions(optionsOrPrompt: TextGenerationOptions | string): TextGenerationOptions;
410
437
  protected normalizeStreamOptions(optionsOrPrompt: StreamOptions | string): StreamOptions;
411
438
  protected enhanceResult(result: EnhancedGenerateResult, options: TextGenerationOptions, startTime: number): Promise<EnhancedGenerateResult>;
412
439
  protected createAnalytics(result: EnhancedGenerateResult, responseTime: number, options: TextGenerationOptions): Promise<AnalyticsData>;
413
- protected createEvaluation(result: EnhancedGenerateResult, options: TextGenerationOptions): Promise<any>;
440
+ protected createEvaluation(result: EnhancedGenerateResult, options: TextGenerationOptions): Promise<EvaluationData>;
414
441
  protected validateOptions(options: TextGenerationOptions): void;
415
442
  protected getProviderInfo(): {
416
443
  provider: string;
@@ -421,3 +448,4 @@ export declare abstract class BaseProvider implements AIProvider {
421
448
  */
422
449
  getTimeout(options: TextGenerationOptions | StreamOptions): number;
423
450
  }
451
+ export {};
@@ -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