@juspay/neurolink 6.0.0 → 6.2.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 (283) hide show
  1. package/CHANGELOG.md +14 -3
  2. package/dist/cli/commands/config.d.ts +13 -13
  3. package/dist/cli/index.js +3 -9
  4. package/dist/core/analytics.d.ts +11 -1
  5. package/dist/core/analytics.js +2 -2
  6. package/dist/core/base-provider.js +4 -18
  7. package/dist/core/dynamic-models.d.ts +8 -8
  8. package/dist/core/factory.js +3 -11
  9. package/dist/index.d.ts +2 -4
  10. package/dist/index.js +2 -11
  11. package/dist/lib/core/analytics.d.ts +11 -1
  12. package/dist/lib/core/analytics.js +2 -2
  13. package/dist/lib/core/base-provider.js +4 -18
  14. package/dist/lib/core/dynamic-models.d.ts +8 -8
  15. package/dist/lib/core/factory.js +3 -11
  16. package/dist/lib/index.d.ts +2 -4
  17. package/dist/lib/index.js +2 -11
  18. package/dist/lib/mcp/factory.d.ts +1 -1
  19. package/dist/lib/mcp/index.d.ts +7 -19
  20. package/dist/lib/mcp/index.js +15 -56
  21. package/dist/lib/neurolink.d.ts +1 -9
  22. package/dist/lib/neurolink.js +21 -70
  23. package/dist/lib/providers/amazon-bedrock.js +5 -16
  24. package/dist/lib/providers/anthropic-baseprovider.js +3 -21
  25. package/dist/lib/providers/anthropic.js +4 -7
  26. package/dist/lib/providers/azure-openai.js +4 -2
  27. package/dist/lib/providers/google-vertex.js +5 -9
  28. package/dist/lib/providers/huggingFace.js +5 -10
  29. package/dist/lib/providers/mistral.js +5 -8
  30. package/dist/lib/providers/openAI.js +4 -7
  31. package/dist/lib/utils/providerConfig.d.ts +117 -0
  32. package/dist/lib/utils/providerConfig.js +353 -0
  33. package/dist/lib/utils/providerUtils.d.ts +2 -1
  34. package/dist/lib/utils/providerUtils.js +53 -36
  35. package/dist/lib/utils/timeout.d.ts +72 -1
  36. package/dist/lib/utils/timeout.js +203 -2
  37. package/dist/mcp/factory.d.ts +1 -1
  38. package/dist/mcp/index.d.ts +7 -19
  39. package/dist/mcp/index.js +15 -56
  40. package/dist/neurolink.d.ts +1 -9
  41. package/dist/neurolink.js +21 -70
  42. package/dist/providers/amazon-bedrock.js +5 -16
  43. package/dist/providers/anthropic-baseprovider.js +3 -21
  44. package/dist/providers/anthropic.js +4 -7
  45. package/dist/providers/azure-openai.js +4 -2
  46. package/dist/providers/google-vertex.js +5 -9
  47. package/dist/providers/huggingFace.js +5 -10
  48. package/dist/providers/mistral.js +5 -8
  49. package/dist/providers/openAI.js +4 -7
  50. package/dist/utils/providerConfig.d.ts +117 -0
  51. package/dist/utils/providerConfig.js +353 -0
  52. package/dist/utils/providerUtils.d.ts +2 -1
  53. package/dist/utils/providerUtils.js +53 -36
  54. package/dist/utils/timeout.d.ts +72 -1
  55. package/dist/utils/timeout.js +203 -2
  56. package/package.json +2 -1
  57. package/dist/chat/client-utils.d.ts +0 -95
  58. package/dist/chat/client-utils.js +0 -315
  59. package/dist/chat/index.d.ts +0 -24
  60. package/dist/chat/index.js +0 -33
  61. package/dist/chat/session-storage.d.ts +0 -77
  62. package/dist/chat/session-storage.js +0 -233
  63. package/dist/chat/session.d.ts +0 -96
  64. package/dist/chat/session.js +0 -257
  65. package/dist/chat/sse-handler.d.ts +0 -49
  66. package/dist/chat/sse-handler.js +0 -259
  67. package/dist/chat/types.d.ts +0 -74
  68. package/dist/chat/types.js +0 -5
  69. package/dist/chat/websocket-chat-handler.d.ts +0 -37
  70. package/dist/chat/websocket-chat-handler.js +0 -262
  71. package/dist/cli/commands/mcp.d.ts +0 -20
  72. package/dist/cli/commands/mcp.js +0 -1272
  73. package/dist/core/defaults.d.ts +0 -19
  74. package/dist/core/defaults.js +0 -29
  75. package/dist/core/evaluation-config.d.ts +0 -29
  76. package/dist/core/evaluation-config.js +0 -144
  77. package/dist/factories/compatibility-factory.d.ts +0 -35
  78. package/dist/factories/compatibility-factory.js +0 -71
  79. package/dist/factories/provider-generate-factory.d.ts +0 -20
  80. package/dist/factories/provider-generate-factory.js +0 -93
  81. package/dist/lib/chat/client-utils.d.ts +0 -95
  82. package/dist/lib/chat/client-utils.js +0 -315
  83. package/dist/lib/chat/index.d.ts +0 -24
  84. package/dist/lib/chat/index.js +0 -33
  85. package/dist/lib/chat/session-storage.d.ts +0 -77
  86. package/dist/lib/chat/session-storage.js +0 -233
  87. package/dist/lib/chat/session.d.ts +0 -96
  88. package/dist/lib/chat/session.js +0 -257
  89. package/dist/lib/chat/sse-handler.d.ts +0 -49
  90. package/dist/lib/chat/sse-handler.js +0 -259
  91. package/dist/lib/chat/types.d.ts +0 -74
  92. package/dist/lib/chat/types.js +0 -5
  93. package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
  94. package/dist/lib/chat/websocket-chat-handler.js +0 -262
  95. package/dist/lib/core/defaults.d.ts +0 -19
  96. package/dist/lib/core/defaults.js +0 -29
  97. package/dist/lib/core/evaluation-config.d.ts +0 -29
  98. package/dist/lib/core/evaluation-config.js +0 -144
  99. package/dist/lib/factories/compatibility-factory.d.ts +0 -35
  100. package/dist/lib/factories/compatibility-factory.js +0 -71
  101. package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
  102. package/dist/lib/factories/provider-generate-factory.js +0 -93
  103. package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
  104. package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
  105. package/dist/lib/mcp/auto-discovery.d.ts +0 -62
  106. package/dist/lib/mcp/auto-discovery.js +0 -149
  107. package/dist/lib/mcp/client.d.ts +0 -68
  108. package/dist/lib/mcp/client.js +0 -248
  109. package/dist/lib/mcp/config.d.ts +0 -31
  110. package/dist/lib/mcp/config.js +0 -99
  111. package/dist/lib/mcp/context-manager.d.ts +0 -171
  112. package/dist/lib/mcp/context-manager.js +0 -362
  113. package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
  114. package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
  115. package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
  116. package/dist/lib/mcp/core/plugin-manager.js +0 -110
  117. package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
  118. package/dist/lib/mcp/demo/plugin-demo.js +0 -118
  119. package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
  120. package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
  121. package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
  122. package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
  123. package/dist/lib/mcp/ecosystem.d.ts +0 -75
  124. package/dist/lib/mcp/ecosystem.js +0 -161
  125. package/dist/lib/mcp/error-manager.d.ts +0 -254
  126. package/dist/lib/mcp/error-manager.js +0 -501
  127. package/dist/lib/mcp/error-recovery.d.ts +0 -159
  128. package/dist/lib/mcp/error-recovery.js +0 -405
  129. package/dist/lib/mcp/external-client.d.ts +0 -88
  130. package/dist/lib/mcp/external-client.js +0 -331
  131. package/dist/lib/mcp/external-manager.d.ts +0 -112
  132. package/dist/lib/mcp/external-manager.js +0 -308
  133. package/dist/lib/mcp/function-calling.d.ts +0 -65
  134. package/dist/lib/mcp/function-calling.js +0 -642
  135. package/dist/lib/mcp/health-monitor.d.ts +0 -257
  136. package/dist/lib/mcp/health-monitor.js +0 -630
  137. package/dist/lib/mcp/initialize-tools.d.ts +0 -29
  138. package/dist/lib/mcp/initialize-tools.js +0 -261
  139. package/dist/lib/mcp/initialize.d.ts +0 -18
  140. package/dist/lib/mcp/initialize.js +0 -62
  141. package/dist/lib/mcp/manager.d.ts +0 -68
  142. package/dist/lib/mcp/manager.js +0 -176
  143. package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
  144. package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
  145. package/dist/lib/mcp/orchestrator.d.ts +0 -302
  146. package/dist/lib/mcp/orchestrator.js +0 -703
  147. package/dist/lib/mcp/plugin-manager.d.ts +0 -98
  148. package/dist/lib/mcp/plugin-manager.js +0 -296
  149. package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
  150. package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
  151. package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
  152. package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
  153. package/dist/lib/mcp/security-manager.d.ts +0 -87
  154. package/dist/lib/mcp/security-manager.js +0 -344
  155. package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
  156. package/dist/lib/mcp/semaphore-manager.js +0 -329
  157. package/dist/lib/mcp/session-manager.d.ts +0 -187
  158. package/dist/lib/mcp/session-manager.js +0 -400
  159. package/dist/lib/mcp/session-persistence.d.ts +0 -93
  160. package/dist/lib/mcp/session-persistence.js +0 -301
  161. package/dist/lib/mcp/tool-integration.d.ts +0 -58
  162. package/dist/lib/mcp/tool-integration.js +0 -203
  163. package/dist/lib/mcp/transport-manager.d.ts +0 -154
  164. package/dist/lib/mcp/transport-manager.js +0 -334
  165. package/dist/lib/mcp/unified-mcp.d.ts +0 -133
  166. package/dist/lib/mcp/unified-mcp.js +0 -251
  167. package/dist/lib/mcp/unified-registry.d.ts +0 -165
  168. package/dist/lib/mcp/unified-registry.js +0 -538
  169. package/dist/lib/providers/analytics-helper.d.ts +0 -38
  170. package/dist/lib/providers/analytics-helper.js +0 -216
  171. package/dist/lib/providers/function-calling-provider.d.ts +0 -142
  172. package/dist/lib/providers/function-calling-provider.js +0 -630
  173. package/dist/lib/providers/mcp-provider.d.ts +0 -75
  174. package/dist/lib/providers/mcp-provider.js +0 -283
  175. package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
  176. package/dist/lib/providers/timeout-wrapper.js +0 -100
  177. package/dist/lib/sdk/tool-extension.d.ts +0 -181
  178. package/dist/lib/sdk/tool-extension.js +0 -284
  179. package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
  180. package/dist/lib/services/streaming/streaming-manager.js +0 -245
  181. package/dist/lib/services/types.d.ts +0 -156
  182. package/dist/lib/services/types.js +0 -2
  183. package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
  184. package/dist/lib/services/websocket/websocket-server.js +0 -305
  185. package/dist/lib/utils/provider-validation.d.ts +0 -36
  186. package/dist/lib/utils/provider-validation.js +0 -625
  187. package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
  188. package/dist/lib/utils/providerUtils-fixed.js +0 -94
  189. package/dist/lib/utils/streaming-utils.d.ts +0 -79
  190. package/dist/lib/utils/streaming-utils.js +0 -198
  191. package/dist/lib/utils/timeout-manager.d.ts +0 -75
  192. package/dist/lib/utils/timeout-manager.js +0 -244
  193. package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
  194. package/dist/mcp/adapters/plugin-bridge.js +0 -89
  195. package/dist/mcp/auto-discovery.d.ts +0 -62
  196. package/dist/mcp/auto-discovery.js +0 -149
  197. package/dist/mcp/client.d.ts +0 -68
  198. package/dist/mcp/client.js +0 -248
  199. package/dist/mcp/config.d.ts +0 -31
  200. package/dist/mcp/config.js +0 -99
  201. package/dist/mcp/context-manager.d.ts +0 -171
  202. package/dist/mcp/context-manager.js +0 -362
  203. package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
  204. package/dist/mcp/contracts/mcp-contract.js +0 -58
  205. package/dist/mcp/core/plugin-manager.d.ts +0 -46
  206. package/dist/mcp/core/plugin-manager.js +0 -110
  207. package/dist/mcp/demo/plugin-demo.d.ts +0 -20
  208. package/dist/mcp/demo/plugin-demo.js +0 -118
  209. package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
  210. package/dist/mcp/dynamic-chain-executor.js +0 -489
  211. package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
  212. package/dist/mcp/dynamic-orchestrator.js +0 -351
  213. package/dist/mcp/ecosystem.d.ts +0 -75
  214. package/dist/mcp/ecosystem.js +0 -162
  215. package/dist/mcp/error-manager.d.ts +0 -254
  216. package/dist/mcp/error-manager.js +0 -501
  217. package/dist/mcp/error-recovery.d.ts +0 -159
  218. package/dist/mcp/error-recovery.js +0 -405
  219. package/dist/mcp/external-client.d.ts +0 -88
  220. package/dist/mcp/external-client.js +0 -331
  221. package/dist/mcp/external-manager.d.ts +0 -112
  222. package/dist/mcp/external-manager.js +0 -308
  223. package/dist/mcp/function-calling.d.ts +0 -65
  224. package/dist/mcp/function-calling.js +0 -642
  225. package/dist/mcp/health-monitor.d.ts +0 -257
  226. package/dist/mcp/health-monitor.js +0 -630
  227. package/dist/mcp/initialize-tools.d.ts +0 -29
  228. package/dist/mcp/initialize-tools.js +0 -262
  229. package/dist/mcp/initialize.d.ts +0 -18
  230. package/dist/mcp/initialize.js +0 -62
  231. package/dist/mcp/manager.d.ts +0 -68
  232. package/dist/mcp/manager.js +0 -176
  233. package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
  234. package/dist/mcp/neurolink-mcp-client.js +0 -462
  235. package/dist/mcp/orchestrator.d.ts +0 -302
  236. package/dist/mcp/orchestrator.js +0 -703
  237. package/dist/mcp/plugin-manager.d.ts +0 -98
  238. package/dist/mcp/plugin-manager.js +0 -297
  239. package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
  240. package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
  241. package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
  242. package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
  243. package/dist/mcp/plugins/filesystem-mcp.js +0 -54
  244. package/dist/mcp/security-manager.d.ts +0 -87
  245. package/dist/mcp/security-manager.js +0 -344
  246. package/dist/mcp/semaphore-manager.d.ts +0 -137
  247. package/dist/mcp/semaphore-manager.js +0 -329
  248. package/dist/mcp/session-manager.d.ts +0 -187
  249. package/dist/mcp/session-manager.js +0 -400
  250. package/dist/mcp/session-persistence.d.ts +0 -93
  251. package/dist/mcp/session-persistence.js +0 -302
  252. package/dist/mcp/tool-integration.d.ts +0 -58
  253. package/dist/mcp/tool-integration.js +0 -203
  254. package/dist/mcp/transport-manager.d.ts +0 -154
  255. package/dist/mcp/transport-manager.js +0 -335
  256. package/dist/mcp/unified-mcp.d.ts +0 -133
  257. package/dist/mcp/unified-mcp.js +0 -251
  258. package/dist/mcp/unified-registry.d.ts +0 -165
  259. package/dist/mcp/unified-registry.js +0 -539
  260. package/dist/providers/analytics-helper.d.ts +0 -38
  261. package/dist/providers/analytics-helper.js +0 -216
  262. package/dist/providers/function-calling-provider.d.ts +0 -142
  263. package/dist/providers/function-calling-provider.js +0 -630
  264. package/dist/providers/mcp-provider.d.ts +0 -75
  265. package/dist/providers/mcp-provider.js +0 -283
  266. package/dist/providers/timeout-wrapper.d.ts +0 -40
  267. package/dist/providers/timeout-wrapper.js +0 -100
  268. package/dist/sdk/tool-extension.d.ts +0 -181
  269. package/dist/sdk/tool-extension.js +0 -284
  270. package/dist/services/streaming/streaming-manager.d.ts +0 -29
  271. package/dist/services/streaming/streaming-manager.js +0 -245
  272. package/dist/services/types.d.ts +0 -156
  273. package/dist/services/types.js +0 -2
  274. package/dist/services/websocket/websocket-server.d.ts +0 -34
  275. package/dist/services/websocket/websocket-server.js +0 -306
  276. package/dist/utils/provider-validation.d.ts +0 -36
  277. package/dist/utils/provider-validation.js +0 -625
  278. package/dist/utils/providerUtils-fixed.d.ts +0 -8
  279. package/dist/utils/providerUtils-fixed.js +0 -94
  280. package/dist/utils/streaming-utils.d.ts +0 -79
  281. package/dist/utils/streaming-utils.js +0 -198
  282. package/dist/utils/timeout-manager.d.ts +0 -75
  283. package/dist/utils/timeout-manager.js +0 -244
@@ -1,99 +0,0 @@
1
- /**
2
- * NeuroLink MCP Configuration
3
- * Central registry for all MCP servers following Lighthouse patterns
4
- * Handles built-in servers only - auto-discovery handled by unified registry
5
- */
6
- import { utilityServer } from "./servers/utilities/utility-server.js";
7
- import { logger } from "../utils/logger.js";
8
- /**
9
- * Lazy-loaded AI Core Server to avoid circular dependencies
10
- */
11
- let aiCoreServerCache = null;
12
- async function getAICoreServer() {
13
- if (!aiCoreServerCache) {
14
- const { aiCoreServer } = await import("./servers/ai-providers/ai-core-server.js");
15
- aiCoreServerCache = aiCoreServer;
16
- }
17
- return aiCoreServerCache;
18
- }
19
- /**
20
- * Lazy-loaded Direct Tools Server to avoid circular dependencies
21
- */
22
- let directToolsServerCache = null;
23
- async function getDirectToolsServer() {
24
- if (!directToolsServerCache) {
25
- const { directToolsServer } = await import("./servers/agent/direct-tools-server.js");
26
- directToolsServerCache = directToolsServer;
27
- }
28
- return directToolsServerCache;
29
- }
30
- /**
31
- * Built-in MCP servers (kept for backward compatibility)
32
- * Add new servers here as they are created
33
- */
34
- export const allServers = [
35
- // aiCoreServer will be added dynamically in getServers()
36
- utilityServer,
37
- // Add more servers as they are created
38
- ];
39
- /**
40
- * MCP Configuration following Lighthouse patterns
41
- * Handles built-in servers - auto-discovery is handled by unified registry
42
- */
43
- export const mcpConfig = {
44
- /**
45
- * Get list of active built-in MCP servers with implemented tools
46
- */
47
- getServers: async () => {
48
- const activeServers = [];
49
- // Get all servers including dynamically loaded ones
50
- const aiCoreServer = await getAICoreServer();
51
- const directToolsServer = await getDirectToolsServer();
52
- const servers = [aiCoreServer, directToolsServer, ...allServers];
53
- // Include built-in servers with filtering
54
- for (const server of servers) {
55
- const implementedTools = {};
56
- let hasImplementedTools = false;
57
- for (const toolName in server.tools) {
58
- const tool = server.tools[toolName];
59
- // Only include tools that are implemented (default to true if not specified)
60
- if (tool.isImplemented !== false) {
61
- implementedTools[toolName] = tool;
62
- hasImplementedTools = true;
63
- }
64
- }
65
- // Only include servers that have at least one implemented tool
66
- if (hasImplementedTools) {
67
- activeServers.push({
68
- ...server,
69
- tools: implementedTools,
70
- });
71
- }
72
- }
73
- logger.debug("[MCP Config] Built-in servers:", {
74
- total: activeServers.length,
75
- serverIds: activeServers.map((s) => s.id),
76
- });
77
- return activeServers;
78
- },
79
- /**
80
- * Get all available tools across all servers
81
- */
82
- getAllTools: async () => {
83
- const servers = await mcpConfig.getServers();
84
- const allTools = [];
85
- for (const server of servers) {
86
- for (const toolName in server.tools) {
87
- const tool = server.tools[toolName];
88
- allTools.push({
89
- name: toolName,
90
- description: tool.description,
91
- serverId: server.id,
92
- serverTitle: server.title,
93
- category: tool.category,
94
- });
95
- }
96
- }
97
- return allTools;
98
- },
99
- };
@@ -1,171 +0,0 @@
1
- /**
2
- * NeuroLink MCP Context Management System
3
- * Unified context creation and management for all tool executions
4
- * Ensures rich context flows through tool chain with session tracking
5
- */
6
- import type { NeuroLinkExecutionContext } from "./factory.js";
7
- /**
8
- * Context creation request interface
9
- */
10
- export interface ContextRequest {
11
- sessionId?: string;
12
- userId?: string;
13
- aiProvider?: string;
14
- modelId?: string;
15
- temperature?: number;
16
- maxTokens?: number;
17
- organizationId?: string;
18
- projectId?: string;
19
- environmentType?: "development" | "staging" | "production";
20
- frameworkType?: "react" | "vue" | "svelte" | "next" | "nuxt" | "sveltekit";
21
- permissions?: string[];
22
- securityLevel?: "public" | "private" | "organization";
23
- [key: string]: unknown;
24
- }
25
- /**
26
- * Context manager for creating and managing execution contexts
27
- * Provides rich context for all tool executions with session tracking
28
- */
29
- export declare class ContextManager {
30
- private sessionCounter;
31
- private activeContexts;
32
- private static cachedLogger;
33
- /**
34
- * Create a new execution context with rich information
35
- *
36
- * @param request Context creation request with optional fields
37
- * @returns Complete execution context ready for tool chain
38
- */
39
- createContext(request?: ContextRequest): NeuroLinkExecutionContext;
40
- /**
41
- * Add a tool to the execution chain
42
- *
43
- * @param context Execution context to modify
44
- * @param toolName Name of the tool being executed
45
- */
46
- addToToolChain(context: NeuroLinkExecutionContext, toolName: string): void;
47
- /**
48
- * Get the current tool chain for a context
49
- *
50
- * @param context Execution context
51
- * @returns Array of tool names in execution order
52
- */
53
- getToolChain(context: NeuroLinkExecutionContext): string[];
54
- /**
55
- * Set parent tool for nested tool execution
56
- *
57
- * @param context Execution context to modify
58
- * @param parentToolId ID of the parent tool
59
- */
60
- setParentTool(context: NeuroLinkExecutionContext, parentToolId: string): void;
61
- /**
62
- * Create child context for nested tool execution
63
- *
64
- * @param parentContext Parent execution context
65
- * @param childToolName Name of the child tool
66
- * @returns New child context with inherited properties
67
- */
68
- createChildContext(parentContext: NeuroLinkExecutionContext, childToolName: string): NeuroLinkExecutionContext;
69
- /**
70
- * Get context by session ID
71
- *
72
- * @param sessionId Session identifier
73
- * @returns Execution context or undefined if not found
74
- */
75
- getContext(sessionId: string): NeuroLinkExecutionContext | undefined;
76
- /**
77
- * Update context with new information
78
- *
79
- * @param sessionId Session identifier
80
- * @param updates Partial context updates
81
- */
82
- updateContext(sessionId: string, updates: Partial<NeuroLinkExecutionContext>): void;
83
- /**
84
- * Store context directly (used when session ID changes)
85
- *
86
- * @param context Complete execution context to store
87
- */
88
- storeContext(context: NeuroLinkExecutionContext): void;
89
- /**
90
- * Remove context from active tracking
91
- *
92
- * @param sessionId Session identifier
93
- */
94
- removeContext(sessionId: string): void;
95
- /**
96
- * Get all active contexts (for debugging/monitoring)
97
- *
98
- * @returns Array of all active contexts
99
- */
100
- getActiveContexts(): NeuroLinkExecutionContext[];
101
- /**
102
- * Clear all active contexts
103
- */
104
- clearAllContexts(): void;
105
- /**
106
- * Get context statistics
107
- *
108
- * @returns Context usage statistics
109
- */
110
- getStats(): {
111
- activeContexts: number;
112
- totalSessionsCreated: number;
113
- averageToolChainLength: number;
114
- };
115
- /**
116
- * Generate unique session ID
117
- *
118
- * @returns Unique session identifier
119
- */
120
- private generateSessionId;
121
- /**
122
- * Extract custom fields from request (excluding known fields)
123
- *
124
- * @param request Context creation request
125
- * @returns Custom fields object
126
- */
127
- private extractCustomFields;
128
- }
129
- /**
130
- * Default context manager instance
131
- * Can be used across the application for consistent context management
132
- */
133
- export declare const defaultContextManager: ContextManager;
134
- /**
135
- * Utility function to create context with defaults
136
- *
137
- * @param request Optional context request
138
- * @returns Execution context with sensible defaults
139
- */
140
- export declare function createExecutionContext(request?: ContextRequest): NeuroLinkExecutionContext;
141
- /**
142
- * Utility function to add tool to default context manager
143
- *
144
- * @param context Execution context
145
- * @param toolName Tool name to add
146
- */
147
- export declare function addToolToChain(context: NeuroLinkExecutionContext, toolName: string): void;
148
- /**
149
- * Context validation utilities
150
- */
151
- export declare class ContextValidator {
152
- /**
153
- * Validate context has required fields for tool execution
154
- *
155
- * @param context Execution context to validate
156
- * @returns Validation result with details
157
- */
158
- static validateContext(context: NeuroLinkExecutionContext): {
159
- isValid: boolean;
160
- errors: string[];
161
- warnings: string[];
162
- };
163
- /**
164
- * Validate context permissions for tool execution
165
- *
166
- * @param context Execution context
167
- * @param requiredPermissions Permissions required by tool
168
- * @returns Whether context has required permissions
169
- */
170
- static hasPermissions(context: NeuroLinkExecutionContext, requiredPermissions: string[]): boolean;
171
- }
@@ -1,362 +0,0 @@
1
- /**
2
- * NeuroLink MCP Context Management System
3
- * Unified context creation and management for all tool executions
4
- * Ensures rich context flows through tool chain with session tracking
5
- */
6
- /**
7
- * Context manager for creating and managing execution contexts
8
- * Provides rich context for all tool executions with session tracking
9
- */
10
- export class ContextManager {
11
- sessionCounter = 0;
12
- activeContexts = new Map();
13
- static cachedLogger = null;
14
- /**
15
- * Create a new execution context with rich information
16
- *
17
- * @param request Context creation request with optional fields
18
- * @returns Complete execution context ready for tool chain
19
- */
20
- createContext(request = {}) {
21
- // Generate session ID if not provided
22
- const sessionId = request.sessionId || this.generateSessionId();
23
- // Create comprehensive context
24
- const context = {
25
- // Session Management
26
- sessionId,
27
- userId: request.userId || "unknown-user",
28
- // Required ExecutionContext properties
29
- secureFS: {
30
- readFile: async (path, encoding) => {
31
- const fs = await import("fs/promises");
32
- if (encoding) {
33
- return fs.readFile(path, { encoding: encoding });
34
- }
35
- else {
36
- return fs.readFile(path);
37
- }
38
- },
39
- writeFile: async (path, content) => {
40
- const fs = await import("fs/promises");
41
- return fs.writeFile(path, content);
42
- },
43
- readdir: async (path) => {
44
- const fs = await import("fs/promises");
45
- return fs.readdir(path);
46
- },
47
- stat: async (path) => {
48
- const fs = await import("fs/promises");
49
- return fs.stat(path);
50
- },
51
- mkdir: async (path, options) => {
52
- const fs = await import("fs/promises");
53
- await fs.mkdir(path, options);
54
- },
55
- exists: async (path) => {
56
- const fs = await import("fs/promises");
57
- try {
58
- await fs.access(path);
59
- return true;
60
- }
61
- catch {
62
- return false;
63
- }
64
- },
65
- },
66
- path: {
67
- join: (...paths) => {
68
- // Use dynamic require for synchronous path operations
69
- const path = require("path");
70
- return path.join(...paths);
71
- },
72
- resolve: (...paths) => {
73
- const path = require("path");
74
- return path.resolve(...paths);
75
- },
76
- relative: (from, to) => {
77
- const path = require("path");
78
- return path.relative(from, to);
79
- },
80
- dirname: (path) => {
81
- const pathModule = require("path");
82
- return pathModule.dirname(path);
83
- },
84
- basename: (path, ext) => {
85
- const pathModule = require("path");
86
- return pathModule.basename(path, ext);
87
- },
88
- },
89
- grantedPermissions: request.permissions || [],
90
- log: async (level, message, data) => {
91
- // Use cached logger if available, otherwise import and cache
92
- try {
93
- if (!ContextManager.cachedLogger) {
94
- ContextManager.cachedLogger = await import("../utils/logger.js").then(({ logger }) => logger);
95
- }
96
- ContextManager.cachedLogger[level](message, data);
97
- }
98
- catch {
99
- console[level === "debug" ? "log" : level](message, data);
100
- }
101
- },
102
- // AI Provider Context (from existing NeuroLink)
103
- aiProvider: request.aiProvider,
104
- modelId: request.modelId,
105
- temperature: request.temperature,
106
- maxTokens: request.maxTokens,
107
- // Business Context (new for MCP)
108
- organizationId: request.organizationId,
109
- projectId: request.projectId,
110
- environmentType: request.environmentType || "development",
111
- // Framework Context (new for MCP)
112
- frameworkType: request.frameworkType,
113
- // Tool Execution Context (initialized empty)
114
- toolChain: [],
115
- parentToolId: undefined,
116
- // Security & Permissions
117
- permissions: request.permissions || [],
118
- securityLevel: request.securityLevel || "private",
119
- // Copy any additional custom fields
120
- ...this.extractCustomFields(request),
121
- };
122
- // Store context for session management
123
- this.activeContexts.set(sessionId, context);
124
- return context;
125
- }
126
- /**
127
- * Add a tool to the execution chain
128
- *
129
- * @param context Execution context to modify
130
- * @param toolName Name of the tool being executed
131
- */
132
- addToToolChain(context, toolName) {
133
- if (!context.toolChain) {
134
- context.toolChain = [];
135
- }
136
- context.toolChain.push(toolName);
137
- // Update the active context
138
- this.activeContexts.set(context.sessionId, context);
139
- }
140
- /**
141
- * Get the current tool chain for a context
142
- *
143
- * @param context Execution context
144
- * @returns Array of tool names in execution order
145
- */
146
- getToolChain(context) {
147
- return context.toolChain || [];
148
- }
149
- /**
150
- * Set parent tool for nested tool execution
151
- *
152
- * @param context Execution context to modify
153
- * @param parentToolId ID of the parent tool
154
- */
155
- setParentTool(context, parentToolId) {
156
- context.parentToolId = parentToolId;
157
- this.activeContexts.set(context.sessionId, context);
158
- }
159
- /**
160
- * Create child context for nested tool execution
161
- *
162
- * @param parentContext Parent execution context
163
- * @param childToolName Name of the child tool
164
- * @returns New child context with inherited properties
165
- */
166
- createChildContext(parentContext, childToolName) {
167
- const childContext = {
168
- // Inherit all parent context
169
- ...parentContext,
170
- // Create new session ID for child
171
- sessionId: this.generateSessionId(),
172
- // Set parent tool reference
173
- parentToolId: parentContext.toolChain?.[parentContext.toolChain.length - 1],
174
- // Reset tool chain for child (will be populated as child executes tools)
175
- toolChain: [],
176
- };
177
- // Store child context
178
- this.activeContexts.set(childContext.sessionId, childContext);
179
- return childContext;
180
- }
181
- /**
182
- * Get context by session ID
183
- *
184
- * @param sessionId Session identifier
185
- * @returns Execution context or undefined if not found
186
- */
187
- getContext(sessionId) {
188
- return this.activeContexts.get(sessionId);
189
- }
190
- /**
191
- * Update context with new information
192
- *
193
- * @param sessionId Session identifier
194
- * @param updates Partial context updates
195
- */
196
- updateContext(sessionId, updates) {
197
- const context = this.activeContexts.get(sessionId);
198
- if (context) {
199
- const updatedContext = { ...context, ...updates };
200
- this.activeContexts.set(sessionId, updatedContext);
201
- }
202
- }
203
- /**
204
- * Store context directly (used when session ID changes)
205
- *
206
- * @param context Complete execution context to store
207
- */
208
- storeContext(context) {
209
- this.activeContexts.set(context.sessionId, context);
210
- }
211
- /**
212
- * Remove context from active tracking
213
- *
214
- * @param sessionId Session identifier
215
- */
216
- removeContext(sessionId) {
217
- this.activeContexts.delete(sessionId);
218
- }
219
- /**
220
- * Get all active contexts (for debugging/monitoring)
221
- *
222
- * @returns Array of all active contexts
223
- */
224
- getActiveContexts() {
225
- return Array.from(this.activeContexts.values());
226
- }
227
- /**
228
- * Clear all active contexts
229
- */
230
- clearAllContexts() {
231
- this.activeContexts.clear();
232
- this.sessionCounter = 0;
233
- }
234
- /**
235
- * Get context statistics
236
- *
237
- * @returns Context usage statistics
238
- */
239
- getStats() {
240
- const contexts = Array.from(this.activeContexts.values());
241
- const totalToolChainLength = contexts.reduce((sum, ctx) => sum + (ctx.toolChain?.length || 0), 0);
242
- return {
243
- activeContexts: contexts.length,
244
- totalSessionsCreated: this.sessionCounter,
245
- averageToolChainLength: contexts.length > 0 ? totalToolChainLength / contexts.length : 0,
246
- };
247
- }
248
- /**
249
- * Generate unique session ID
250
- *
251
- * @returns Unique session identifier
252
- */
253
- generateSessionId() {
254
- this.sessionCounter++;
255
- const timestamp = Date.now();
256
- const random = Math.random().toString(36).substring(2, 8);
257
- return `nlmcp-${timestamp}-${this.sessionCounter}-${random}`;
258
- }
259
- /**
260
- * Extract custom fields from request (excluding known fields)
261
- *
262
- * @param request Context creation request
263
- * @returns Custom fields object
264
- */
265
- extractCustomFields(request) {
266
- const knownFields = new Set([
267
- "sessionId",
268
- "userId",
269
- "aiProvider",
270
- "modelId",
271
- "temperature",
272
- "maxTokens",
273
- "organizationId",
274
- "projectId",
275
- "environmentType",
276
- "frameworkType",
277
- "permissions",
278
- "securityLevel",
279
- ]);
280
- const customFields = {};
281
- for (const [key, value] of Object.entries(request)) {
282
- if (!knownFields.has(key)) {
283
- customFields[key] = value;
284
- }
285
- }
286
- return customFields;
287
- }
288
- }
289
- /**
290
- * Default context manager instance
291
- * Can be used across the application for consistent context management
292
- */
293
- export const defaultContextManager = new ContextManager();
294
- /**
295
- * Utility function to create context with defaults
296
- *
297
- * @param request Optional context request
298
- * @returns Execution context with sensible defaults
299
- */
300
- export function createExecutionContext(request = {}) {
301
- return defaultContextManager.createContext(request);
302
- }
303
- /**
304
- * Utility function to add tool to default context manager
305
- *
306
- * @param context Execution context
307
- * @param toolName Tool name to add
308
- */
309
- export function addToolToChain(context, toolName) {
310
- defaultContextManager.addToToolChain(context, toolName);
311
- }
312
- /**
313
- * Context validation utilities
314
- */
315
- export class ContextValidator {
316
- /**
317
- * Validate context has required fields for tool execution
318
- *
319
- * @param context Execution context to validate
320
- * @returns Validation result with details
321
- */
322
- static validateContext(context) {
323
- const errors = [];
324
- const warnings = [];
325
- // Required field validation
326
- if (!context.sessionId) {
327
- errors.push("sessionId is required");
328
- }
329
- // Optional field validation with warnings
330
- if (!context.environmentType) {
331
- warnings.push("environmentType not specified, defaulting to development");
332
- }
333
- if (!context.securityLevel) {
334
- warnings.push("securityLevel not specified, defaulting to private");
335
- }
336
- // Tool chain validation
337
- if (context.toolChain && context.toolChain.length > 10) {
338
- warnings.push("Tool chain is getting long (>10 tools), consider breaking into smaller workflows");
339
- }
340
- return {
341
- isValid: errors.length === 0,
342
- errors,
343
- warnings,
344
- };
345
- }
346
- /**
347
- * Validate context permissions for tool execution
348
- *
349
- * @param context Execution context
350
- * @param requiredPermissions Permissions required by tool
351
- * @returns Whether context has required permissions
352
- */
353
- static hasPermissions(context, requiredPermissions) {
354
- if (!requiredPermissions || requiredPermissions.length === 0) {
355
- return true;
356
- }
357
- const contextPermissions = context.permissions || [];
358
- // Check if context has all required permissions
359
- return requiredPermissions.every((permission) => contextPermissions.includes(permission) ||
360
- contextPermissions.includes("*"));
361
- }
362
- }