@juspay/neurolink 6.1.0 → 6.2.1
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.
- package/CHANGELOG.md +16 -6
- package/dist/agent/direct-tools.js +6 -5
- package/dist/cli/commands/config.d.ts +13 -13
- package/dist/cli/index.js +3 -9
- package/dist/config/configManager.js +11 -10
- package/dist/core/analytics.d.ts +11 -1
- package/dist/core/analytics.js +2 -2
- package/dist/core/base-provider.js +4 -18
- package/dist/core/dynamic-models.d.ts +8 -8
- package/dist/core/factory.js +3 -11
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -11
- package/dist/lib/agent/direct-tools.js +6 -5
- package/dist/lib/config/configManager.js +11 -10
- package/dist/lib/core/analytics.d.ts +11 -1
- package/dist/lib/core/analytics.js +2 -2
- package/dist/lib/core/base-provider.js +4 -18
- package/dist/lib/core/dynamic-models.d.ts +8 -8
- package/dist/lib/core/factory.js +3 -11
- package/dist/lib/index.d.ts +2 -4
- package/dist/lib/index.js +2 -11
- package/dist/lib/mcp/factory.d.ts +1 -1
- package/dist/lib/mcp/index.d.ts +9 -21
- package/dist/lib/mcp/index.js +16 -57
- package/dist/lib/mcp/registry.js +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +2 -1
- package/dist/lib/mcp/tool-registry.js +1 -1
- package/dist/lib/neurolink.d.ts +1 -9
- package/dist/lib/neurolink.js +22 -71
- package/dist/lib/providers/amazon-bedrock.js +5 -16
- package/dist/lib/providers/anthropic-baseprovider.js +3 -21
- package/dist/lib/providers/anthropic.js +4 -7
- package/dist/lib/providers/azure-openai.js +6 -3
- package/dist/lib/providers/google-vertex.js +5 -9
- package/dist/lib/providers/huggingFace.js +5 -10
- package/dist/lib/providers/mistral.js +5 -8
- package/dist/lib/providers/openAI.js +4 -7
- package/dist/lib/telemetry/index.js +2 -1
- package/dist/lib/utils/logger.d.ts +62 -2
- package/dist/lib/utils/logger.js +174 -9
- package/dist/lib/utils/providerConfig.d.ts +117 -0
- package/dist/lib/utils/providerConfig.js +353 -0
- package/dist/lib/utils/providerUtils.d.ts +2 -1
- package/dist/lib/utils/providerUtils.js +53 -36
- package/dist/lib/utils/timeout.d.ts +72 -1
- package/dist/lib/utils/timeout.js +203 -2
- package/dist/mcp/factory.d.ts +1 -1
- package/dist/mcp/index.d.ts +9 -21
- package/dist/mcp/index.js +16 -57
- package/dist/mcp/registry.js +1 -1
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +2 -1
- package/dist/mcp/tool-registry.js +1 -1
- package/dist/neurolink.d.ts +1 -9
- package/dist/neurolink.js +22 -71
- package/dist/providers/amazon-bedrock.js +5 -16
- package/dist/providers/anthropic-baseprovider.js +3 -21
- package/dist/providers/anthropic.js +4 -7
- package/dist/providers/azure-openai.js +6 -3
- package/dist/providers/google-vertex.js +5 -9
- package/dist/providers/huggingFace.js +5 -10
- package/dist/providers/mistral.js +5 -8
- package/dist/providers/openAI.js +4 -7
- package/dist/telemetry/index.js +2 -1
- package/dist/utils/logger.d.ts +62 -2
- package/dist/utils/logger.js +174 -9
- package/dist/utils/providerConfig.d.ts +117 -0
- package/dist/utils/providerConfig.js +353 -0
- package/dist/utils/providerUtils.d.ts +2 -1
- package/dist/utils/providerUtils.js +53 -36
- package/dist/utils/timeout.d.ts +72 -1
- package/dist/utils/timeout.js +203 -2
- package/package.json +1 -1
- package/dist/chat/client-utils.d.ts +0 -95
- package/dist/chat/client-utils.js +0 -315
- package/dist/chat/index.d.ts +0 -24
- package/dist/chat/index.js +0 -33
- package/dist/chat/session-storage.d.ts +0 -77
- package/dist/chat/session-storage.js +0 -233
- package/dist/chat/session.d.ts +0 -96
- package/dist/chat/session.js +0 -257
- package/dist/chat/sse-handler.d.ts +0 -49
- package/dist/chat/sse-handler.js +0 -259
- package/dist/chat/types.d.ts +0 -74
- package/dist/chat/types.js +0 -5
- package/dist/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/chat/websocket-chat-handler.js +0 -262
- package/dist/cli/commands/mcp.d.ts +0 -20
- package/dist/cli/commands/mcp.js +0 -1272
- package/dist/core/defaults.d.ts +0 -19
- package/dist/core/defaults.js +0 -29
- package/dist/core/evaluation-config.d.ts +0 -29
- package/dist/core/evaluation-config.js +0 -144
- package/dist/factories/compatibility-factory.d.ts +0 -35
- package/dist/factories/compatibility-factory.js +0 -71
- package/dist/factories/provider-generate-factory.d.ts +0 -20
- package/dist/factories/provider-generate-factory.js +0 -93
- package/dist/lib/chat/client-utils.d.ts +0 -95
- package/dist/lib/chat/client-utils.js +0 -315
- package/dist/lib/chat/index.d.ts +0 -24
- package/dist/lib/chat/index.js +0 -33
- package/dist/lib/chat/session-storage.d.ts +0 -77
- package/dist/lib/chat/session-storage.js +0 -233
- package/dist/lib/chat/session.d.ts +0 -96
- package/dist/lib/chat/session.js +0 -257
- package/dist/lib/chat/sse-handler.d.ts +0 -49
- package/dist/lib/chat/sse-handler.js +0 -259
- package/dist/lib/chat/types.d.ts +0 -74
- package/dist/lib/chat/types.js +0 -5
- package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/lib/chat/websocket-chat-handler.js +0 -262
- package/dist/lib/core/defaults.d.ts +0 -19
- package/dist/lib/core/defaults.js +0 -29
- package/dist/lib/core/evaluation-config.d.ts +0 -29
- package/dist/lib/core/evaluation-config.js +0 -144
- package/dist/lib/factories/compatibility-factory.d.ts +0 -35
- package/dist/lib/factories/compatibility-factory.js +0 -71
- package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
- package/dist/lib/factories/provider-generate-factory.js +0 -93
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/lib/mcp/auto-discovery.d.ts +0 -62
- package/dist/lib/mcp/auto-discovery.js +0 -149
- package/dist/lib/mcp/client.d.ts +0 -68
- package/dist/lib/mcp/client.js +0 -248
- package/dist/lib/mcp/config.d.ts +0 -31
- package/dist/lib/mcp/config.js +0 -99
- package/dist/lib/mcp/context-manager.d.ts +0 -171
- package/dist/lib/mcp/context-manager.js +0 -362
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
- package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/lib/mcp/core/plugin-manager.js +0 -110
- package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/lib/mcp/demo/plugin-demo.js +0 -118
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
- package/dist/lib/mcp/ecosystem.d.ts +0 -75
- package/dist/lib/mcp/ecosystem.js +0 -161
- package/dist/lib/mcp/error-manager.d.ts +0 -254
- package/dist/lib/mcp/error-manager.js +0 -501
- package/dist/lib/mcp/error-recovery.d.ts +0 -159
- package/dist/lib/mcp/error-recovery.js +0 -405
- package/dist/lib/mcp/external-client.d.ts +0 -88
- package/dist/lib/mcp/external-client.js +0 -331
- package/dist/lib/mcp/external-manager.d.ts +0 -112
- package/dist/lib/mcp/external-manager.js +0 -308
- package/dist/lib/mcp/function-calling.d.ts +0 -65
- package/dist/lib/mcp/function-calling.js +0 -642
- package/dist/lib/mcp/health-monitor.d.ts +0 -257
- package/dist/lib/mcp/health-monitor.js +0 -630
- package/dist/lib/mcp/initialize-tools.d.ts +0 -29
- package/dist/lib/mcp/initialize-tools.js +0 -261
- package/dist/lib/mcp/initialize.d.ts +0 -18
- package/dist/lib/mcp/initialize.js +0 -62
- package/dist/lib/mcp/logging.d.ts +0 -38
- package/dist/lib/mcp/logging.js +0 -100
- package/dist/lib/mcp/manager.d.ts +0 -68
- package/dist/lib/mcp/manager.js +0 -176
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
- package/dist/lib/mcp/orchestrator.d.ts +0 -302
- package/dist/lib/mcp/orchestrator.js +0 -703
- package/dist/lib/mcp/plugin-manager.d.ts +0 -98
- package/dist/lib/mcp/plugin-manager.js +0 -296
- package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/lib/mcp/security-manager.d.ts +0 -87
- package/dist/lib/mcp/security-manager.js +0 -344
- package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
- package/dist/lib/mcp/semaphore-manager.js +0 -329
- package/dist/lib/mcp/session-manager.d.ts +0 -187
- package/dist/lib/mcp/session-manager.js +0 -400
- package/dist/lib/mcp/session-persistence.d.ts +0 -93
- package/dist/lib/mcp/session-persistence.js +0 -301
- package/dist/lib/mcp/tool-integration.d.ts +0 -58
- package/dist/lib/mcp/tool-integration.js +0 -203
- package/dist/lib/mcp/transport-manager.d.ts +0 -154
- package/dist/lib/mcp/transport-manager.js +0 -334
- package/dist/lib/mcp/unified-mcp.d.ts +0 -133
- package/dist/lib/mcp/unified-mcp.js +0 -251
- package/dist/lib/mcp/unified-registry.d.ts +0 -165
- package/dist/lib/mcp/unified-registry.js +0 -538
- package/dist/lib/providers/analytics-helper.d.ts +0 -38
- package/dist/lib/providers/analytics-helper.js +0 -216
- package/dist/lib/providers/function-calling-provider.d.ts +0 -142
- package/dist/lib/providers/function-calling-provider.js +0 -630
- package/dist/lib/providers/mcp-provider.d.ts +0 -75
- package/dist/lib/providers/mcp-provider.js +0 -283
- package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
- package/dist/lib/providers/timeout-wrapper.js +0 -100
- package/dist/lib/sdk/tool-extension.d.ts +0 -181
- package/dist/lib/sdk/tool-extension.js +0 -284
- package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/lib/services/streaming/streaming-manager.js +0 -245
- package/dist/lib/services/types.d.ts +0 -156
- package/dist/lib/services/types.js +0 -2
- package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
- package/dist/lib/services/websocket/websocket-server.js +0 -305
- package/dist/lib/utils/provider-validation.d.ts +0 -36
- package/dist/lib/utils/provider-validation.js +0 -625
- package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/lib/utils/providerUtils-fixed.js +0 -94
- package/dist/lib/utils/streaming-utils.d.ts +0 -79
- package/dist/lib/utils/streaming-utils.js +0 -198
- package/dist/lib/utils/timeout-manager.d.ts +0 -75
- package/dist/lib/utils/timeout-manager.js +0 -244
- package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/mcp/auto-discovery.d.ts +0 -62
- package/dist/mcp/auto-discovery.js +0 -149
- package/dist/mcp/client.d.ts +0 -68
- package/dist/mcp/client.js +0 -248
- package/dist/mcp/config.d.ts +0 -31
- package/dist/mcp/config.js +0 -99
- package/dist/mcp/context-manager.d.ts +0 -171
- package/dist/mcp/context-manager.js +0 -362
- package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/mcp/contracts/mcp-contract.js +0 -58
- package/dist/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/mcp/core/plugin-manager.js +0 -110
- package/dist/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/mcp/demo/plugin-demo.js +0 -118
- package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/mcp/dynamic-chain-executor.js +0 -489
- package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/mcp/dynamic-orchestrator.js +0 -351
- package/dist/mcp/ecosystem.d.ts +0 -75
- package/dist/mcp/ecosystem.js +0 -162
- package/dist/mcp/error-manager.d.ts +0 -254
- package/dist/mcp/error-manager.js +0 -501
- package/dist/mcp/error-recovery.d.ts +0 -159
- package/dist/mcp/error-recovery.js +0 -405
- package/dist/mcp/external-client.d.ts +0 -88
- package/dist/mcp/external-client.js +0 -331
- package/dist/mcp/external-manager.d.ts +0 -112
- package/dist/mcp/external-manager.js +0 -308
- package/dist/mcp/function-calling.d.ts +0 -65
- package/dist/mcp/function-calling.js +0 -642
- package/dist/mcp/health-monitor.d.ts +0 -257
- package/dist/mcp/health-monitor.js +0 -630
- package/dist/mcp/initialize-tools.d.ts +0 -29
- package/dist/mcp/initialize-tools.js +0 -262
- package/dist/mcp/initialize.d.ts +0 -18
- package/dist/mcp/initialize.js +0 -62
- package/dist/mcp/logging.d.ts +0 -38
- package/dist/mcp/logging.js +0 -100
- package/dist/mcp/manager.d.ts +0 -68
- package/dist/mcp/manager.js +0 -176
- package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/mcp/neurolink-mcp-client.js +0 -462
- package/dist/mcp/orchestrator.d.ts +0 -302
- package/dist/mcp/orchestrator.js +0 -703
- package/dist/mcp/plugin-manager.d.ts +0 -98
- package/dist/mcp/plugin-manager.js +0 -297
- package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
- package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/mcp/security-manager.d.ts +0 -87
- package/dist/mcp/security-manager.js +0 -344
- package/dist/mcp/semaphore-manager.d.ts +0 -137
- package/dist/mcp/semaphore-manager.js +0 -329
- package/dist/mcp/session-manager.d.ts +0 -187
- package/dist/mcp/session-manager.js +0 -400
- package/dist/mcp/session-persistence.d.ts +0 -93
- package/dist/mcp/session-persistence.js +0 -302
- package/dist/mcp/tool-integration.d.ts +0 -58
- package/dist/mcp/tool-integration.js +0 -203
- package/dist/mcp/transport-manager.d.ts +0 -154
- package/dist/mcp/transport-manager.js +0 -335
- package/dist/mcp/unified-mcp.d.ts +0 -133
- package/dist/mcp/unified-mcp.js +0 -251
- package/dist/mcp/unified-registry.d.ts +0 -165
- package/dist/mcp/unified-registry.js +0 -539
- package/dist/providers/analytics-helper.d.ts +0 -38
- package/dist/providers/analytics-helper.js +0 -216
- package/dist/providers/function-calling-provider.d.ts +0 -142
- package/dist/providers/function-calling-provider.js +0 -630
- package/dist/providers/mcp-provider.d.ts +0 -75
- package/dist/providers/mcp-provider.js +0 -283
- package/dist/providers/timeout-wrapper.d.ts +0 -40
- package/dist/providers/timeout-wrapper.js +0 -100
- package/dist/sdk/tool-extension.d.ts +0 -181
- package/dist/sdk/tool-extension.js +0 -284
- package/dist/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/services/streaming/streaming-manager.js +0 -245
- package/dist/services/types.d.ts +0 -156
- package/dist/services/types.js +0 -2
- package/dist/services/websocket/websocket-server.d.ts +0 -34
- package/dist/services/websocket/websocket-server.js +0 -306
- package/dist/utils/provider-validation.d.ts +0 -36
- package/dist/utils/provider-validation.js +0 -625
- package/dist/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/utils/providerUtils-fixed.js +0 -94
- package/dist/utils/streaming-utils.d.ts +0 -79
- package/dist/utils/streaming-utils.js +0 -198
- package/dist/utils/timeout-manager.d.ts +0 -75
- package/dist/utils/timeout-manager.js +0 -244
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink Dynamic AI-Driven Tool Orchestrator
|
|
3
|
-
* Enables AI to dynamically select and execute tools based on task requirements
|
|
4
|
-
* Based on patterns from reference implementations
|
|
5
|
-
*/
|
|
6
|
-
import { MCPOrchestrator } from "./orchestrator.js";
|
|
7
|
-
import type { ToolResult } from "./factory.js";
|
|
8
|
-
import type { ContextRequest } from "./context-manager.js";
|
|
9
|
-
import type { UnknownRecord } from "../types/common.js";
|
|
10
|
-
import { ErrorManager } from "./error-manager.js";
|
|
11
|
-
import type { MCPToolRegistry } from "./tool-registry.js";
|
|
12
|
-
import type { ContextManager } from "./context-manager.js";
|
|
13
|
-
import type { SemaphoreManager } from "./semaphore-manager.js";
|
|
14
|
-
import type { SessionManager } from "./session-manager.js";
|
|
15
|
-
/**
|
|
16
|
-
* Tool decision made by AI
|
|
17
|
-
*/
|
|
18
|
-
export interface ToolDecision {
|
|
19
|
-
toolName: string;
|
|
20
|
-
args: UnknownRecord;
|
|
21
|
-
reasoning: string;
|
|
22
|
-
confidence: number;
|
|
23
|
-
shouldContinue: boolean;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Dynamic tool chain execution options
|
|
27
|
-
*/
|
|
28
|
-
export interface DynamicToolChainOptions {
|
|
29
|
-
maxIterations?: number;
|
|
30
|
-
requireConfidence?: number;
|
|
31
|
-
includeReasoning?: boolean;
|
|
32
|
-
allowParallel?: boolean;
|
|
33
|
-
customSystemPrompt?: string;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Dynamic tool chain result
|
|
37
|
-
*/
|
|
38
|
-
export interface DynamicToolChainResult {
|
|
39
|
-
success: boolean;
|
|
40
|
-
iterations: number;
|
|
41
|
-
results: ToolResult[];
|
|
42
|
-
decisions: ToolDecision[];
|
|
43
|
-
finalOutput?: string;
|
|
44
|
-
error?: Error;
|
|
45
|
-
totalDuration: number;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Dynamic orchestrator with AI-driven tool selection
|
|
49
|
-
*/
|
|
50
|
-
export declare class DynamicOrchestrator extends MCPOrchestrator {
|
|
51
|
-
constructor(registry?: MCPToolRegistry, contextManager?: ContextManager, semaphoreManager?: SemaphoreManager, sessionManager?: SessionManager, errorManager?: ErrorManager);
|
|
52
|
-
private defaultOptions;
|
|
53
|
-
/**
|
|
54
|
-
* Execute a dynamic tool chain where AI decides which tools to use
|
|
55
|
-
*
|
|
56
|
-
* @param prompt User's task or request
|
|
57
|
-
* @param contextRequest Context creation request
|
|
58
|
-
* @param options Dynamic execution options
|
|
59
|
-
* @returns Dynamic tool chain result
|
|
60
|
-
*/
|
|
61
|
-
executeDynamicToolChain(prompt: string, contextRequest?: ContextRequest, options?: DynamicToolChainOptions): Promise<DynamicToolChainResult>;
|
|
62
|
-
/**
|
|
63
|
-
* Get AI decision on which tool to use next
|
|
64
|
-
*
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
|
-
private getAIToolDecision;
|
|
68
|
-
/**
|
|
69
|
-
* Generate final output based on all execution results
|
|
70
|
-
*
|
|
71
|
-
* @private
|
|
72
|
-
*/
|
|
73
|
-
private generateFinalOutput;
|
|
74
|
-
/**
|
|
75
|
-
* Execute parallel dynamic tool chains for complex tasks
|
|
76
|
-
*
|
|
77
|
-
* @param prompts Multiple prompts to execute in parallel
|
|
78
|
-
* @param contextRequest Shared context request
|
|
79
|
-
* @param options Dynamic execution options
|
|
80
|
-
* @returns Array of dynamic tool chain results
|
|
81
|
-
*/
|
|
82
|
-
executeParallelDynamicChains(prompts: string[], contextRequest?: ContextRequest, options?: DynamicToolChainOptions): Promise<DynamicToolChainResult[]>;
|
|
83
|
-
/**
|
|
84
|
-
* Get statistics including dynamic execution metrics
|
|
85
|
-
*/
|
|
86
|
-
getStats(): {
|
|
87
|
-
dynamicOrchestrator: {
|
|
88
|
-
features: {
|
|
89
|
-
aiToolSelection: boolean;
|
|
90
|
-
iterativeExecution: boolean;
|
|
91
|
-
parallelSupport: boolean;
|
|
92
|
-
reasoningCapture: boolean;
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
registry: UnknownRecord;
|
|
96
|
-
context: UnknownRecord;
|
|
97
|
-
session: UnknownRecord;
|
|
98
|
-
error: UnknownRecord;
|
|
99
|
-
health?: UnknownRecord;
|
|
100
|
-
orchestrator: {
|
|
101
|
-
pipelinesExecuted: number;
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Create a dynamic orchestrator instance
|
|
107
|
-
*
|
|
108
|
-
* @param registry Tool registry
|
|
109
|
-
* @param contextManager Context manager
|
|
110
|
-
* @param semaphoreManager Semaphore manager (optional)
|
|
111
|
-
* @param sessionManager Session manager (optional)
|
|
112
|
-
* @param errorManager Error manager (optional)
|
|
113
|
-
* @returns Dynamic orchestrator instance
|
|
114
|
-
*/
|
|
115
|
-
export declare function createDynamicOrchestrator(registry: MCPToolRegistry, contextManager: ContextManager, semaphoreManager?: SemaphoreManager, sessionManager?: SessionManager, errorManager?: ErrorManager): DynamicOrchestrator;
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink Dynamic AI-Driven Tool Orchestrator
|
|
3
|
-
* Enables AI to dynamically select and execute tools based on task requirements
|
|
4
|
-
* Based on patterns from reference implementations
|
|
5
|
-
*/
|
|
6
|
-
import { MCPOrchestrator } from "./orchestrator.js";
|
|
7
|
-
import { createExecutionContext } from "./context-manager.js";
|
|
8
|
-
import { ErrorCategory, ErrorSeverity, ErrorManager } from "./error-manager.js";
|
|
9
|
-
import { aiCoreServer } from "./servers/ai-providers/ai-core-server.js";
|
|
10
|
-
/**
|
|
11
|
-
* AI prompt templates for tool selection
|
|
12
|
-
*/
|
|
13
|
-
const TOOL_SELECTION_PROMPT = `You are an intelligent tool orchestrator. Analyze the user's request and available tools to determine the best tool to use next.
|
|
14
|
-
|
|
15
|
-
User Request: {prompt}
|
|
16
|
-
|
|
17
|
-
Available Tools:
|
|
18
|
-
{tools}
|
|
19
|
-
|
|
20
|
-
Previous Results:
|
|
21
|
-
{previousResults}
|
|
22
|
-
|
|
23
|
-
Based on the request and previous results, select the most appropriate tool to use next.
|
|
24
|
-
Respond with a JSON object containing:
|
|
25
|
-
- toolName: The exact name of the tool to use
|
|
26
|
-
- args: An object containing the arguments for the tool
|
|
27
|
-
- reasoning: Brief explanation of why this tool was chosen
|
|
28
|
-
- confidence: A number between 0 and 1 indicating your confidence in this choice
|
|
29
|
-
- shouldContinue: Boolean indicating if more tools should be executed after this one
|
|
30
|
-
|
|
31
|
-
Example response:
|
|
32
|
-
{
|
|
33
|
-
"toolName": "search-code",
|
|
34
|
-
"args": {"query": "function calculateTotal", "path": "/src"},
|
|
35
|
-
"reasoning": "Need to find the calculateTotal function to understand the calculation logic",
|
|
36
|
-
"confidence": 0.9,
|
|
37
|
-
"shouldContinue": true
|
|
38
|
-
}`;
|
|
39
|
-
/**
|
|
40
|
-
* Dynamic orchestrator with AI-driven tool selection
|
|
41
|
-
*/
|
|
42
|
-
export class DynamicOrchestrator extends MCPOrchestrator {
|
|
43
|
-
constructor(registry, contextManager, semaphoreManager, sessionManager, errorManager) {
|
|
44
|
-
super(registry, contextManager, semaphoreManager, sessionManager, errorManager);
|
|
45
|
-
}
|
|
46
|
-
defaultOptions = {
|
|
47
|
-
maxIterations: 10,
|
|
48
|
-
requireConfidence: 0.7,
|
|
49
|
-
includeReasoning: true,
|
|
50
|
-
allowParallel: false,
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Execute a dynamic tool chain where AI decides which tools to use
|
|
54
|
-
*
|
|
55
|
-
* @param prompt User's task or request
|
|
56
|
-
* @param contextRequest Context creation request
|
|
57
|
-
* @param options Dynamic execution options
|
|
58
|
-
* @returns Dynamic tool chain result
|
|
59
|
-
*/
|
|
60
|
-
async executeDynamicToolChain(prompt, contextRequest = {}, options = {}) {
|
|
61
|
-
const startTime = Date.now();
|
|
62
|
-
const mergedOptions = { ...this.defaultOptions, ...options };
|
|
63
|
-
const results = [];
|
|
64
|
-
const decisions = [];
|
|
65
|
-
let error;
|
|
66
|
-
let iterations = 0;
|
|
67
|
-
let session;
|
|
68
|
-
try {
|
|
69
|
-
// Create or get session
|
|
70
|
-
const context = await this.contextManager.createContext(contextRequest);
|
|
71
|
-
session = await this.sessionManager.createSession(context);
|
|
72
|
-
// Get available tools
|
|
73
|
-
const availableTools = await this.registry.listTools(context);
|
|
74
|
-
const toolsDescription = availableTools
|
|
75
|
-
.map((tool) => `- ${tool.name}: ${tool.description || "No description"}`)
|
|
76
|
-
.join("\n");
|
|
77
|
-
let shouldContinue = true;
|
|
78
|
-
while (shouldContinue &&
|
|
79
|
-
iterations < (mergedOptions.maxIterations || 10)) {
|
|
80
|
-
iterations++;
|
|
81
|
-
// Prepare context for AI decision
|
|
82
|
-
const previousResultsSummary = results
|
|
83
|
-
.slice(-3) // Last 3 results for context
|
|
84
|
-
.map((r, i) => {
|
|
85
|
-
const resultData = r.success && r.data ? JSON.stringify(r.data) : "No data";
|
|
86
|
-
const summary = resultData.length > 200
|
|
87
|
-
? resultData.slice(0, 200) + "..."
|
|
88
|
-
: resultData;
|
|
89
|
-
return `Result ${i + 1}: ${summary}`;
|
|
90
|
-
})
|
|
91
|
-
.join("\n");
|
|
92
|
-
// Get AI decision on next tool
|
|
93
|
-
const decision = await this.getAIToolDecision(prompt, toolsDescription, previousResultsSummary, mergedOptions.customSystemPrompt);
|
|
94
|
-
// Add decision to array if includeReasoning is true
|
|
95
|
-
if (mergedOptions.includeReasoning) {
|
|
96
|
-
decisions.push(decision);
|
|
97
|
-
}
|
|
98
|
-
// Validate confidence threshold
|
|
99
|
-
if (decision.confidence < (mergedOptions.requireConfidence || 0.7)) {
|
|
100
|
-
if (process.env.NEUROLINK_DEBUG === "true") {
|
|
101
|
-
console.log(`[DynamicOrchestrator] Low confidence (${decision.confidence}), stopping execution`);
|
|
102
|
-
}
|
|
103
|
-
shouldContinue = false;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
shouldContinue = decision.shouldContinue;
|
|
107
|
-
// Execute the selected tool
|
|
108
|
-
try {
|
|
109
|
-
const toolResult = await this.registry.executeTool(decision.toolName, decision.args, context);
|
|
110
|
-
results.push({
|
|
111
|
-
success: true,
|
|
112
|
-
data: toolResult,
|
|
113
|
-
metadata: {
|
|
114
|
-
toolName: decision.toolName,
|
|
115
|
-
executionTime: Date.now() - startTime,
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
// Update session with tool result
|
|
119
|
-
session.toolHistory.push({
|
|
120
|
-
success: true,
|
|
121
|
-
data: toolResult,
|
|
122
|
-
metadata: {
|
|
123
|
-
toolName: decision.toolName,
|
|
124
|
-
executionTime: Date.now() - startTime,
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
catch (toolError) {
|
|
129
|
-
const errorResult = {
|
|
130
|
-
success: false,
|
|
131
|
-
error: toolError instanceof Error
|
|
132
|
-
? toolError
|
|
133
|
-
: new Error(String(toolError)),
|
|
134
|
-
metadata: {
|
|
135
|
-
toolName: decision.toolName,
|
|
136
|
-
executionTime: Date.now() - startTime,
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
results.push(errorResult);
|
|
140
|
-
session.toolHistory.push(errorResult);
|
|
141
|
-
// Let AI decide if it should continue after error
|
|
142
|
-
if (!decision.shouldContinue) {
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// Safety check for infinite loops
|
|
147
|
-
if (iterations >= (mergedOptions.maxIterations || 10)) {
|
|
148
|
-
if (process.env.NEUROLINK_DEBUG === "true") {
|
|
149
|
-
console.log(`[DynamicOrchestrator] Reached max iterations (${mergedOptions.maxIterations})`);
|
|
150
|
-
}
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Generate final output based on all results
|
|
155
|
-
const finalOutput = await this.generateFinalOutput(prompt, results, decisions);
|
|
156
|
-
return {
|
|
157
|
-
success: true,
|
|
158
|
-
iterations,
|
|
159
|
-
results,
|
|
160
|
-
decisions: mergedOptions.includeReasoning ? decisions : [],
|
|
161
|
-
finalOutput,
|
|
162
|
-
totalDuration: Date.now() - startTime,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
catch (err) {
|
|
166
|
-
error = err instanceof Error ? err : new Error(String(err));
|
|
167
|
-
// Record error
|
|
168
|
-
this.errorManager.recordError(error, {
|
|
169
|
-
category: ErrorCategory.TOOL_ERROR,
|
|
170
|
-
severity: ErrorSeverity.HIGH,
|
|
171
|
-
toolName: "dynamic-orchestrator",
|
|
172
|
-
sessionId: session?.id,
|
|
173
|
-
});
|
|
174
|
-
return {
|
|
175
|
-
success: false,
|
|
176
|
-
iterations,
|
|
177
|
-
results,
|
|
178
|
-
decisions: mergedOptions.includeReasoning ? decisions : [],
|
|
179
|
-
error,
|
|
180
|
-
totalDuration: Date.now() - startTime,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
finally {
|
|
184
|
-
// Update session activity if session was created
|
|
185
|
-
if (session) {
|
|
186
|
-
session.lastActivity = Date.now();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Get AI decision on which tool to use next
|
|
192
|
-
*
|
|
193
|
-
* @private
|
|
194
|
-
*/
|
|
195
|
-
async getAIToolDecision(prompt, toolsDescription, previousResults, customSystemPrompt) {
|
|
196
|
-
const systemPrompt = customSystemPrompt ||
|
|
197
|
-
TOOL_SELECTION_PROMPT.replace("{prompt}", prompt)
|
|
198
|
-
.replace("{tools}", toolsDescription)
|
|
199
|
-
.replace("{previousResults}", previousResults || "None yet");
|
|
200
|
-
try {
|
|
201
|
-
// Use AI Core Server to get tool decision
|
|
202
|
-
const generateTool = aiCoreServer.tools["generate"];
|
|
203
|
-
if (!generateTool) {
|
|
204
|
-
throw new Error("generate tool not found");
|
|
205
|
-
}
|
|
206
|
-
const aiResponse = await generateTool.execute({
|
|
207
|
-
prompt: "Select the next tool to execute based on the context provided.",
|
|
208
|
-
systemPrompt,
|
|
209
|
-
provider: "google-ai", // Use fast model for decisions
|
|
210
|
-
model: "gemini-2.5-flash",
|
|
211
|
-
temperature: 0.3, // Lower temperature for more consistent decisions
|
|
212
|
-
maxTokens: 500,
|
|
213
|
-
}, createExecutionContext());
|
|
214
|
-
// Parse AI response
|
|
215
|
-
if (!aiResponse.success) {
|
|
216
|
-
throw new Error(String(aiResponse.error || "AI generation failed"));
|
|
217
|
-
}
|
|
218
|
-
const responseText = aiResponse.data?.text || "";
|
|
219
|
-
// Extract JSON from response (handle markdown code blocks)
|
|
220
|
-
const jsonMatch = responseText.match(/```json\n?([\s\S]*?)\n?```/) ||
|
|
221
|
-
responseText.match(/\{[\s\S]*\}/);
|
|
222
|
-
if (!jsonMatch) {
|
|
223
|
-
throw new Error("AI response did not contain valid JSON");
|
|
224
|
-
}
|
|
225
|
-
const decision = JSON.parse(jsonMatch[1] || jsonMatch[0]);
|
|
226
|
-
// Validate decision structure
|
|
227
|
-
if (!decision.toolName || !decision.args) {
|
|
228
|
-
throw new Error("Invalid tool decision structure");
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
toolName: decision.toolName,
|
|
232
|
-
args: decision.args || {},
|
|
233
|
-
reasoning: decision.reasoning || "No reasoning provided",
|
|
234
|
-
confidence: decision.confidence || 0.8,
|
|
235
|
-
shouldContinue: decision.shouldContinue !== false,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
catch (error) {
|
|
239
|
-
// Fallback decision on error
|
|
240
|
-
if (process.env.NEUROLINK_DEBUG === "true") {
|
|
241
|
-
console.error("[DynamicOrchestrator] Error getting AI decision:", error);
|
|
242
|
-
}
|
|
243
|
-
return {
|
|
244
|
-
toolName: "list-tools", // Safe default
|
|
245
|
-
args: {},
|
|
246
|
-
reasoning: "Error in AI decision, falling back to tool listing",
|
|
247
|
-
confidence: 0.5,
|
|
248
|
-
shouldContinue: false,
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Generate final output based on all execution results
|
|
254
|
-
*
|
|
255
|
-
* @private
|
|
256
|
-
*/
|
|
257
|
-
async generateFinalOutput(prompt, results, decisions) {
|
|
258
|
-
// Prepare summary of execution
|
|
259
|
-
const executionSummary = results
|
|
260
|
-
.map((r, i) => {
|
|
261
|
-
const decision = decisions[i];
|
|
262
|
-
const toolName = r.metadata?.toolName || "unknown";
|
|
263
|
-
const resultData = r.success && r.data ? JSON.stringify(r.data) : "No data";
|
|
264
|
-
const resultSummary = resultData.length > 300
|
|
265
|
-
? resultData.slice(0, 300) + "..."
|
|
266
|
-
: resultData;
|
|
267
|
-
return `Step ${i + 1}: ${toolName}
|
|
268
|
-
Reasoning: ${decision?.reasoning || "N/A"}
|
|
269
|
-
Result: ${r.success ? resultSummary : "Error: " + (r.error instanceof Error ? r.error.message : String(r.error))}`;
|
|
270
|
-
})
|
|
271
|
-
.join("\n\n");
|
|
272
|
-
const summaryPrompt = `Based on the following tool execution results, provide a comprehensive answer to the user's request.
|
|
273
|
-
|
|
274
|
-
User Request: ${prompt}
|
|
275
|
-
|
|
276
|
-
Execution Summary:
|
|
277
|
-
${executionSummary}
|
|
278
|
-
|
|
279
|
-
Provide a clear, concise answer that addresses the user's request based on the tool results.`;
|
|
280
|
-
try {
|
|
281
|
-
// Use AI to generate final summary
|
|
282
|
-
const generateTool = aiCoreServer.tools["generate"];
|
|
283
|
-
if (!generateTool) {
|
|
284
|
-
throw new Error("generate tool not found");
|
|
285
|
-
}
|
|
286
|
-
const aiResponse = await generateTool.execute({
|
|
287
|
-
prompt: summaryPrompt,
|
|
288
|
-
provider: "google-ai",
|
|
289
|
-
model: "gemini-2.5-pro",
|
|
290
|
-
temperature: 0.7,
|
|
291
|
-
maxTokens: 1000,
|
|
292
|
-
}, createExecutionContext());
|
|
293
|
-
if (!aiResponse.success) {
|
|
294
|
-
throw new Error(String(aiResponse.error || "AI generation failed"));
|
|
295
|
-
}
|
|
296
|
-
return aiResponse.data?.text || "";
|
|
297
|
-
}
|
|
298
|
-
catch (error) {
|
|
299
|
-
// Fallback to simple summary
|
|
300
|
-
return `Executed ${results.length} tools to address your request. ${results.filter((r) => r.success).length} succeeded, ${results.filter((r) => !r.success).length} failed.`;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Execute parallel dynamic tool chains for complex tasks
|
|
305
|
-
*
|
|
306
|
-
* @param prompts Multiple prompts to execute in parallel
|
|
307
|
-
* @param contextRequest Shared context request
|
|
308
|
-
* @param options Dynamic execution options
|
|
309
|
-
* @returns Array of dynamic tool chain results
|
|
310
|
-
*/
|
|
311
|
-
async executeParallelDynamicChains(prompts, contextRequest = {}, options = {}) {
|
|
312
|
-
if (!options.allowParallel) {
|
|
313
|
-
throw new Error("Parallel execution not enabled in options");
|
|
314
|
-
}
|
|
315
|
-
// Execute all chains in parallel
|
|
316
|
-
const promises = prompts.map((prompt) => this.executeDynamicToolChain(prompt, contextRequest, options));
|
|
317
|
-
return Promise.all(promises);
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Get statistics including dynamic execution metrics
|
|
321
|
-
*/
|
|
322
|
-
getStats() {
|
|
323
|
-
const baseStats = super.getStats();
|
|
324
|
-
// Add dynamic orchestrator specific stats
|
|
325
|
-
return {
|
|
326
|
-
...baseStats,
|
|
327
|
-
dynamicOrchestrator: {
|
|
328
|
-
// Additional metrics can be added here
|
|
329
|
-
features: {
|
|
330
|
-
aiToolSelection: true,
|
|
331
|
-
iterativeExecution: true,
|
|
332
|
-
parallelSupport: true,
|
|
333
|
-
reasoningCapture: true,
|
|
334
|
-
},
|
|
335
|
-
},
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Create a dynamic orchestrator instance
|
|
341
|
-
*
|
|
342
|
-
* @param registry Tool registry
|
|
343
|
-
* @param contextManager Context manager
|
|
344
|
-
* @param semaphoreManager Semaphore manager (optional)
|
|
345
|
-
* @param sessionManager Session manager (optional)
|
|
346
|
-
* @param errorManager Error manager (optional)
|
|
347
|
-
* @returns Dynamic orchestrator instance
|
|
348
|
-
*/
|
|
349
|
-
export function createDynamicOrchestrator(registry, contextManager, semaphoreManager, sessionManager, errorManager) {
|
|
350
|
-
return new DynamicOrchestrator(registry, contextManager, semaphoreManager, sessionManager, errorManager);
|
|
351
|
-
}
|
package/dist/mcp/ecosystem.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Ecosystem Integration - Bridge Between Research Blueprint and NeuroLink
|
|
3
|
-
* Provides unified interface for plugin management and execution
|
|
4
|
-
*/
|
|
5
|
-
import { MCP } from "./contracts/mcp-contract.js";
|
|
6
|
-
import type { MCPMetadata, ExecutionContext } from "./contracts/mcp-contract.js";
|
|
7
|
-
/**
|
|
8
|
-
* MCP Ecosystem - Main Interface for Plugin Operations
|
|
9
|
-
*/
|
|
10
|
-
export declare class MCPEcosystem {
|
|
11
|
-
private static instance;
|
|
12
|
-
private securityManager;
|
|
13
|
-
private initialized;
|
|
14
|
-
private constructor();
|
|
15
|
-
static getInstance(): MCPEcosystem;
|
|
16
|
-
/**
|
|
17
|
-
* Initialize the MCP ecosystem
|
|
18
|
-
*/
|
|
19
|
-
initialize(): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* List all available MCPs
|
|
22
|
-
*/
|
|
23
|
-
list(): Promise<MCPMetadata[]>;
|
|
24
|
-
/**
|
|
25
|
-
* Get metadata for a specific MCP
|
|
26
|
-
*/
|
|
27
|
-
getMetadata(name: string): Promise<MCPMetadata | null>;
|
|
28
|
-
/**
|
|
29
|
-
* Create and execute an MCP instance
|
|
30
|
-
*/
|
|
31
|
-
execute<T = unknown>(name: string, config: unknown, args: unknown, context?: {
|
|
32
|
-
sessionId?: string;
|
|
33
|
-
userId?: string;
|
|
34
|
-
}): Promise<T>;
|
|
35
|
-
/**
|
|
36
|
-
* Execute filesystem operations using FileSystemMCP
|
|
37
|
-
*/
|
|
38
|
-
filesystem(operation: {
|
|
39
|
-
action: "readFile" | "writeFile" | "listFiles" | "createDir";
|
|
40
|
-
path: string;
|
|
41
|
-
content?: string;
|
|
42
|
-
basePath?: string;
|
|
43
|
-
}): Promise<unknown>;
|
|
44
|
-
/**
|
|
45
|
-
* Get ecosystem statistics
|
|
46
|
-
*/
|
|
47
|
-
getStats(): Promise<{
|
|
48
|
-
initialized: boolean;
|
|
49
|
-
pluginsDiscovered: number;
|
|
50
|
-
pluginsBySource: Record<string, number>;
|
|
51
|
-
availablePlugins: string[];
|
|
52
|
-
}>;
|
|
53
|
-
/**
|
|
54
|
-
* Create an MCP instance for direct use
|
|
55
|
-
*/
|
|
56
|
-
createInstance<T extends MCP>(name: string, config: unknown): Promise<T>;
|
|
57
|
-
/**
|
|
58
|
-
* Create execution context for manual MCP usage
|
|
59
|
-
*/
|
|
60
|
-
createExecutionContext(sessionId: string, userId: string, permissions: string[], basePath?: string): ExecutionContext;
|
|
61
|
-
/**
|
|
62
|
-
* Ensure ecosystem is initialized
|
|
63
|
-
*/
|
|
64
|
-
private ensureInitialized;
|
|
65
|
-
/**
|
|
66
|
-
* Get all tools formatted for AI providers
|
|
67
|
-
*/
|
|
68
|
-
getToolsForAI(): Promise<Record<string, unknown>>;
|
|
69
|
-
/**
|
|
70
|
-
* Dispose of all resources
|
|
71
|
-
*/
|
|
72
|
-
dispose(): Promise<void>;
|
|
73
|
-
}
|
|
74
|
-
export declare const mcpEcosystem: MCPEcosystem;
|
|
75
|
-
export type { MCPMetadata, ExecutionContext, } from "./contracts/mcp-contract.js";
|