@juspay/neurolink 5.0.0 → 5.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.
- package/CHANGELOG.md +20 -7
- package/README.md +160 -172
- package/dist/agent/direct-tools.d.ts +6 -6
- package/dist/chat/sse-handler.js +5 -4
- package/dist/chat/websocket-chat-handler.js +9 -9
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/mcp.js +9 -8
- package/dist/cli/commands/ollama.js +3 -3
- package/dist/cli/factories/command-factory.d.ts +18 -0
- package/dist/cli/factories/command-factory.js +183 -0
- package/dist/cli/index.js +105 -157
- package/dist/cli/utils/interactive-setup.js +2 -2
- package/dist/core/base-provider.d.ts +423 -0
- package/dist/core/base-provider.js +365 -0
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dynamic-models.d.ts +6 -6
- package/dist/core/evaluation.d.ts +19 -80
- package/dist/core/evaluation.js +185 -484
- package/dist/core/factory.d.ts +3 -3
- package/dist/core/factory.js +31 -91
- package/dist/core/service-registry.d.ts +47 -0
- package/dist/core/service-registry.js +112 -0
- package/dist/core/types.d.ts +49 -49
- package/dist/core/types.js +1 -0
- package/dist/factories/compatibility-factory.d.ts +20 -0
- package/dist/factories/compatibility-factory.js +69 -0
- package/dist/factories/provider-factory.d.ts +72 -0
- package/dist/factories/provider-factory.js +144 -0
- package/dist/factories/provider-generate-factory.d.ts +20 -0
- package/dist/factories/provider-generate-factory.js +87 -0
- package/dist/factories/provider-registry.d.ts +38 -0
- package/dist/factories/provider-registry.js +107 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.js +5 -5
- package/dist/lib/agent/direct-tools.d.ts +6 -6
- package/dist/lib/chat/sse-handler.js +5 -4
- package/dist/lib/chat/websocket-chat-handler.js +9 -9
- package/dist/lib/core/base-provider.d.ts +423 -0
- package/dist/lib/core/base-provider.js +365 -0
- package/dist/lib/core/constants.d.ts +1 -1
- package/dist/lib/core/constants.js +1 -1
- package/dist/lib/core/dynamic-models.d.ts +6 -6
- package/dist/lib/core/evaluation.d.ts +19 -80
- package/dist/lib/core/evaluation.js +185 -484
- package/dist/lib/core/factory.d.ts +3 -3
- package/dist/lib/core/factory.js +30 -91
- package/dist/lib/core/service-registry.d.ts +47 -0
- package/dist/lib/core/service-registry.js +112 -0
- package/dist/lib/core/types.d.ts +49 -49
- package/dist/lib/core/types.js +1 -0
- package/dist/lib/factories/compatibility-factory.d.ts +20 -0
- package/dist/lib/factories/compatibility-factory.js +69 -0
- package/dist/lib/factories/provider-factory.d.ts +72 -0
- package/dist/lib/factories/provider-factory.js +144 -0
- package/dist/lib/factories/provider-generate-factory.d.ts +20 -0
- package/dist/lib/factories/provider-generate-factory.js +87 -0
- package/dist/lib/factories/provider-registry.d.ts +38 -0
- package/dist/lib/factories/provider-registry.js +107 -0
- package/dist/lib/index.d.ts +8 -5
- package/dist/lib/index.js +5 -5
- package/dist/lib/mcp/client.js +5 -5
- package/dist/lib/mcp/config.js +28 -3
- package/dist/lib/mcp/dynamic-orchestrator.js +8 -8
- package/dist/lib/mcp/external-client.js +2 -2
- package/dist/lib/mcp/factory.d.ts +1 -1
- package/dist/lib/mcp/factory.js +1 -1
- package/dist/lib/mcp/function-calling.js +1 -1
- package/dist/lib/mcp/initialize-tools.d.ts +1 -1
- package/dist/lib/mcp/initialize-tools.js +45 -1
- package/dist/lib/mcp/initialize.js +16 -6
- package/dist/lib/mcp/neurolink-mcp-client.js +10 -10
- package/dist/lib/mcp/orchestrator.js +4 -4
- package/dist/lib/mcp/servers/agent/direct-tools-server.d.ts +8 -0
- package/dist/lib/mcp/servers/agent/direct-tools-server.js +109 -0
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +10 -10
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +8 -6
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +16 -16
- package/dist/lib/mcp/unified-registry.d.ts +4 -0
- package/dist/lib/mcp/unified-registry.js +42 -9
- package/dist/lib/neurolink.d.ts +161 -174
- package/dist/lib/neurolink.js +723 -397
- package/dist/lib/providers/amazon-bedrock.d.ts +32 -0
- package/dist/lib/providers/amazon-bedrock.js +143 -0
- package/dist/lib/providers/analytics-helper.js +7 -4
- package/dist/lib/providers/anthropic-baseprovider.d.ts +23 -0
- package/dist/lib/providers/anthropic-baseprovider.js +114 -0
- package/dist/lib/providers/anthropic.d.ts +19 -39
- package/dist/lib/providers/anthropic.js +84 -378
- package/dist/lib/providers/azure-openai.d.ts +20 -0
- package/dist/lib/providers/azure-openai.js +89 -0
- package/dist/lib/providers/function-calling-provider.d.ts +14 -12
- package/dist/lib/providers/function-calling-provider.js +114 -64
- package/dist/lib/providers/google-ai-studio.d.ts +23 -0
- package/dist/lib/providers/google-ai-studio.js +107 -0
- package/dist/lib/providers/google-vertex.d.ts +47 -0
- package/dist/lib/providers/google-vertex.js +205 -0
- package/dist/lib/providers/huggingFace.d.ts +33 -27
- package/dist/lib/providers/huggingFace.js +103 -400
- package/dist/lib/providers/index.d.ts +9 -9
- package/dist/lib/providers/index.js +9 -9
- package/dist/lib/providers/mcp-provider.d.ts +13 -8
- package/dist/lib/providers/mcp-provider.js +63 -18
- package/dist/lib/providers/mistral.d.ts +42 -0
- package/dist/lib/providers/mistral.js +160 -0
- package/dist/lib/providers/ollama.d.ts +52 -35
- package/dist/lib/providers/ollama.js +297 -477
- package/dist/lib/providers/openAI.d.ts +21 -21
- package/dist/lib/providers/openAI.js +81 -245
- package/dist/lib/sdk/tool-extension.d.ts +181 -0
- package/dist/lib/sdk/tool-extension.js +283 -0
- package/dist/lib/sdk/tool-registration.d.ts +95 -0
- package/dist/lib/sdk/tool-registration.js +167 -0
- package/dist/lib/types/generate-types.d.ts +80 -0
- package/dist/lib/types/generate-types.js +1 -0
- package/dist/lib/types/mcp-types.d.ts +116 -0
- package/dist/lib/types/mcp-types.js +5 -0
- package/dist/lib/types/stream-types.d.ts +95 -0
- package/dist/lib/types/stream-types.js +1 -0
- package/dist/lib/types/universal-provider-options.d.ts +87 -0
- package/dist/lib/types/universal-provider-options.js +53 -0
- package/dist/lib/utils/providerUtils-fixed.js +1 -1
- package/dist/lib/utils/streaming-utils.d.ts +14 -2
- package/dist/lib/utils/streaming-utils.js +0 -3
- package/dist/mcp/client.js +5 -5
- package/dist/mcp/config.js +28 -3
- package/dist/mcp/dynamic-orchestrator.js +8 -8
- package/dist/mcp/external-client.js +2 -2
- package/dist/mcp/factory.d.ts +1 -1
- package/dist/mcp/factory.js +1 -1
- package/dist/mcp/function-calling.js +1 -1
- package/dist/mcp/initialize-tools.d.ts +1 -1
- package/dist/mcp/initialize-tools.js +45 -1
- package/dist/mcp/initialize.js +16 -6
- package/dist/mcp/neurolink-mcp-client.js +10 -10
- package/dist/mcp/orchestrator.js +4 -4
- package/dist/mcp/servers/agent/direct-tools-server.d.ts +8 -0
- package/dist/mcp/servers/agent/direct-tools-server.js +109 -0
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +10 -10
- package/dist/mcp/servers/ai-providers/ai-core-server.js +8 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +16 -16
- package/dist/mcp/unified-registry.d.ts +4 -0
- package/dist/mcp/unified-registry.js +42 -9
- package/dist/neurolink.d.ts +161 -174
- package/dist/neurolink.js +723 -397
- package/dist/providers/amazon-bedrock.d.ts +32 -0
- package/dist/providers/amazon-bedrock.js +143 -0
- package/dist/providers/analytics-helper.js +7 -4
- package/dist/providers/anthropic-baseprovider.d.ts +23 -0
- package/dist/providers/anthropic-baseprovider.js +114 -0
- package/dist/providers/anthropic.d.ts +19 -39
- package/dist/providers/anthropic.js +83 -377
- package/dist/providers/azure-openai.d.ts +20 -0
- package/dist/providers/azure-openai.js +89 -0
- package/dist/providers/function-calling-provider.d.ts +14 -12
- package/dist/providers/function-calling-provider.js +114 -64
- package/dist/providers/google-ai-studio.d.ts +23 -0
- package/dist/providers/google-ai-studio.js +108 -0
- package/dist/providers/google-vertex.d.ts +47 -0
- package/dist/providers/google-vertex.js +205 -0
- package/dist/providers/huggingFace.d.ts +33 -27
- package/dist/providers/huggingFace.js +102 -399
- package/dist/providers/index.d.ts +9 -9
- package/dist/providers/index.js +9 -9
- package/dist/providers/mcp-provider.d.ts +13 -8
- package/dist/providers/mcp-provider.js +63 -18
- package/dist/providers/mistral.d.ts +42 -0
- package/dist/providers/mistral.js +160 -0
- package/dist/providers/ollama.d.ts +52 -35
- package/dist/providers/ollama.js +297 -476
- package/dist/providers/openAI.d.ts +21 -21
- package/dist/providers/openAI.js +81 -246
- package/dist/sdk/tool-extension.d.ts +181 -0
- package/dist/sdk/tool-extension.js +283 -0
- package/dist/sdk/tool-registration.d.ts +95 -0
- package/dist/sdk/tool-registration.js +168 -0
- package/dist/types/generate-types.d.ts +80 -0
- package/dist/types/generate-types.js +1 -0
- package/dist/types/mcp-types.d.ts +116 -0
- package/dist/types/mcp-types.js +5 -0
- package/dist/types/stream-types.d.ts +95 -0
- package/dist/types/stream-types.js +1 -0
- package/dist/types/universal-provider-options.d.ts +87 -0
- package/dist/types/universal-provider-options.js +53 -0
- package/dist/utils/providerUtils-fixed.js +1 -1
- package/dist/utils/streaming-utils.d.ts +14 -2
- package/dist/utils/streaming-utils.js +0 -3
- package/package.json +15 -10
- package/dist/lib/providers/agent-enhanced-provider.d.ts +0 -89
- package/dist/lib/providers/agent-enhanced-provider.js +0 -614
- package/dist/lib/providers/amazonBedrock.d.ts +0 -19
- package/dist/lib/providers/amazonBedrock.js +0 -334
- package/dist/lib/providers/azureOpenAI.d.ts +0 -39
- package/dist/lib/providers/azureOpenAI.js +0 -436
- package/dist/lib/providers/googleAIStudio.d.ts +0 -49
- package/dist/lib/providers/googleAIStudio.js +0 -333
- package/dist/lib/providers/googleVertexAI.d.ts +0 -38
- package/dist/lib/providers/googleVertexAI.js +0 -519
- package/dist/lib/providers/mistralAI.d.ts +0 -34
- package/dist/lib/providers/mistralAI.js +0 -294
- package/dist/providers/agent-enhanced-provider.d.ts +0 -89
- package/dist/providers/agent-enhanced-provider.js +0 -614
- package/dist/providers/amazonBedrock.d.ts +0 -19
- package/dist/providers/amazonBedrock.js +0 -334
- package/dist/providers/azureOpenAI.d.ts +0 -39
- package/dist/providers/azureOpenAI.js +0 -437
- package/dist/providers/googleAIStudio.d.ts +0 -49
- package/dist/providers/googleAIStudio.js +0 -333
- package/dist/providers/googleVertexAI.d.ts +0 -38
- package/dist/providers/googleVertexAI.js +0 -519
- package/dist/providers/mistralAI.d.ts +0 -34
- package/dist/providers/mistralAI.js +0 -294
package/dist/lib/mcp/factory.js
CHANGED
|
@@ -50,7 +50,7 @@ const ServerConfigSchema = z.object({
|
|
|
50
50
|
* });
|
|
51
51
|
*
|
|
52
52
|
* aiCoreServer.registerTool({
|
|
53
|
-
* name: 'generate
|
|
53
|
+
* name: 'generate',
|
|
54
54
|
* description: 'Generate text using AI providers',
|
|
55
55
|
* execute: async (params, context) => {
|
|
56
56
|
* // Tool implementation
|
|
@@ -58,7 +58,7 @@ export async function getAvailableFunctionTools() {
|
|
|
58
58
|
const toolMap = new Map();
|
|
59
59
|
try {
|
|
60
60
|
// Add overall timeout for the entire function
|
|
61
|
-
const overallTimeoutMs =
|
|
61
|
+
const overallTimeoutMs = process.env.NODE_ENV === "test" ? 30000 : 15000; // 30s for tests, 15s for production
|
|
62
62
|
let overallTimeoutId;
|
|
63
63
|
const overallTimeoutPromise = new Promise((_, reject) => {
|
|
64
64
|
overallTimeoutId = setTimeout(() => {
|
|
@@ -13,7 +13,7 @@ export declare const initializeMCPTools: (sessionId: string, client: NeuroLinkMC
|
|
|
13
13
|
* Get all available tools across all servers
|
|
14
14
|
* Useful for documentation and discovery
|
|
15
15
|
*/
|
|
16
|
-
export declare function getAllAvailableTools(): Promise<Array<{
|
|
16
|
+
export declare function getAllAvailableTools(inMemoryServers?: Map<string, any>): Promise<Array<{
|
|
17
17
|
serverId: string;
|
|
18
18
|
serverTitle: string;
|
|
19
19
|
toolName: string;
|
|
@@ -139,8 +139,52 @@ export const initializeMCPTools = async (sessionId, client, context) => {
|
|
|
139
139
|
* Get all available tools across all servers
|
|
140
140
|
* Useful for documentation and discovery
|
|
141
141
|
*/
|
|
142
|
-
export async function getAllAvailableTools() {
|
|
142
|
+
export async function getAllAvailableTools(inMemoryServers) {
|
|
143
143
|
const tools = [];
|
|
144
|
+
// Add in-memory server tools first
|
|
145
|
+
if (inMemoryServers) {
|
|
146
|
+
for (const [serverId, serverConfig] of inMemoryServers) {
|
|
147
|
+
const server = serverConfig.server;
|
|
148
|
+
if (server && server.tools) {
|
|
149
|
+
// Handle both Map and object formats
|
|
150
|
+
const toolEntries = server.tools instanceof Map
|
|
151
|
+
? Array.from(server.tools.entries())
|
|
152
|
+
: Object.entries(server.tools || {});
|
|
153
|
+
for (const [toolName, toolInfo] of toolEntries) {
|
|
154
|
+
const prefix = `${serverId}_`;
|
|
155
|
+
const finalToolName = toolName.length > 64 - prefix.length
|
|
156
|
+
? toolName.substring(0, 64 - prefix.length)
|
|
157
|
+
: toolName;
|
|
158
|
+
const namespacedName = sanitizeToolName(`${prefix}${finalToolName}`);
|
|
159
|
+
// Handle different tool info structures
|
|
160
|
+
let description = `Tool from ${serverId}`;
|
|
161
|
+
let isImplemented = true;
|
|
162
|
+
if (toolInfo) {
|
|
163
|
+
// Check if it's a tool info object with description
|
|
164
|
+
if (typeof toolInfo.description === "string") {
|
|
165
|
+
description = toolInfo.description;
|
|
166
|
+
}
|
|
167
|
+
else if (typeof toolInfo === "function") {
|
|
168
|
+
// It's a raw function, no description available
|
|
169
|
+
description = `${toolName} from ${serverId}`;
|
|
170
|
+
}
|
|
171
|
+
// Check implementation status
|
|
172
|
+
if (typeof toolInfo.isImplemented === "boolean") {
|
|
173
|
+
isImplemented = toolInfo.isImplemented;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
tools.push({
|
|
177
|
+
serverId,
|
|
178
|
+
serverTitle: server.title || serverId,
|
|
179
|
+
toolName,
|
|
180
|
+
namespacedName,
|
|
181
|
+
description,
|
|
182
|
+
isImplemented,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
144
188
|
const servers = await mcpConfig.getServers();
|
|
145
189
|
servers.forEach((server) => {
|
|
146
190
|
Object.entries(server.tools).forEach(([toolName, tool]) => {
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { toolRegistry, defaultToolRegistry, } from "./tool-registry.js";
|
|
7
7
|
import { mcpLogger } from "./logging.js";
|
|
8
|
+
import { ServiceRegistry } from "../core/service-registry.js";
|
|
8
9
|
let isInitialized = false;
|
|
9
10
|
/**
|
|
10
11
|
* Initialize NeuroLink MCP system by registering built-in servers
|
|
@@ -15,19 +16,28 @@ export async function initializeNeuroLinkMCP(targetRegistry) {
|
|
|
15
16
|
}
|
|
16
17
|
mcpLogger.debug("Initializing built-in MCP servers...");
|
|
17
18
|
try {
|
|
19
|
+
// First, register AIProviderFactory in ServiceRegistry to break circular dependencies
|
|
20
|
+
ServiceRegistry.register("AIProviderFactory", async () => {
|
|
21
|
+
const { AIProviderFactory } = await import("../core/factory.js");
|
|
22
|
+
return AIProviderFactory;
|
|
23
|
+
});
|
|
24
|
+
mcpLogger.debug("Registered AIProviderFactory in ServiceRegistry");
|
|
18
25
|
// Import utility server dynamically to avoid circular dependencies
|
|
19
|
-
// Note: AI core server temporarily disabled due to circular dependency issues
|
|
20
26
|
const { utilityServer } = await import("./servers/utilities/utility-server.js");
|
|
21
27
|
// Register built-in NeuroLink servers with specified registry (or default)
|
|
22
28
|
const registry = targetRegistry || toolRegistry;
|
|
23
29
|
await registry.registerServer(utilityServer.id, utilityServer);
|
|
24
30
|
mcpLogger.debug(`Registered neurolink-utility server with built-in tools in ${targetRegistry ? "target" : "default"} registry`);
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
// Now safe to import and register AI core server
|
|
32
|
+
const { aiCoreServer } = await import("./servers/ai-providers/ai-core-server.js");
|
|
33
|
+
await registry.registerServer(aiCoreServer.id, aiCoreServer);
|
|
34
|
+
mcpLogger.debug("Registered neurolink-ai-core server with AI tools");
|
|
35
|
+
// Register direct tools server
|
|
36
|
+
const { directToolsServer } = await import("./servers/agent/direct-tools-server.js");
|
|
37
|
+
await registry.registerServer(directToolsServer.id, directToolsServer);
|
|
38
|
+
mcpLogger.debug("Registered neurolink-direct server with direct tools");
|
|
29
39
|
const stats = await registry.getStats();
|
|
30
|
-
mcpLogger.info(`Initialization complete: ${stats.totalServers}
|
|
40
|
+
mcpLogger.info(`Initialization complete: ${stats.totalServers} servers, ${stats.totalTools} tools available`);
|
|
31
41
|
isInitialized = true;
|
|
32
42
|
}
|
|
33
43
|
catch (error) {
|
|
@@ -94,14 +94,14 @@ Examples:
|
|
|
94
94
|
|
|
95
95
|
Response (JSON object only):`;
|
|
96
96
|
try {
|
|
97
|
-
const response = await this.provider.
|
|
97
|
+
const response = await this.provider.generate({
|
|
98
98
|
prompt: extractionPrompt,
|
|
99
99
|
temperature: 0,
|
|
100
100
|
maxTokens: 200,
|
|
101
101
|
});
|
|
102
|
-
if (response?.
|
|
102
|
+
if (response?.content) {
|
|
103
103
|
// Extract JSON object from response
|
|
104
|
-
const match = response.
|
|
104
|
+
const match = response.content.match(/\{([^}]*)\}/);
|
|
105
105
|
if (match) {
|
|
106
106
|
try {
|
|
107
107
|
const params = JSON.parse(match[0]);
|
|
@@ -153,14 +153,14 @@ Examples:
|
|
|
153
153
|
|
|
154
154
|
Response (JSON array only):`;
|
|
155
155
|
try {
|
|
156
|
-
const response = await this.provider.
|
|
156
|
+
const response = await this.provider.generate({
|
|
157
157
|
prompt: analysisPrompt,
|
|
158
158
|
temperature: 0,
|
|
159
159
|
maxTokens: 200,
|
|
160
160
|
});
|
|
161
|
-
if (response?.
|
|
161
|
+
if (response?.content) {
|
|
162
162
|
// Extract JSON array from response
|
|
163
|
-
const match = response.
|
|
163
|
+
const match = response.content.match(/\[([^\]]*)\]/);
|
|
164
164
|
if (match) {
|
|
165
165
|
try {
|
|
166
166
|
const toolNames = JSON.parse(match[0]);
|
|
@@ -317,8 +317,8 @@ Response (JSON array only):`;
|
|
|
317
317
|
async generateResponse(prompt, toolResults) {
|
|
318
318
|
// If no tools were used, generate regular response
|
|
319
319
|
if (toolResults.length === 0) {
|
|
320
|
-
const response = await this.provider.
|
|
321
|
-
return response?.
|
|
320
|
+
const response = await this.provider.generate({ prompt });
|
|
321
|
+
return response?.content || "";
|
|
322
322
|
}
|
|
323
323
|
// Extract human-readable results from tool executions
|
|
324
324
|
const toolResultsText = toolResults
|
|
@@ -379,12 +379,12 @@ Tool results: ${toolResultsText}
|
|
|
379
379
|
|
|
380
380
|
Please provide a natural response based on the tool results.`;
|
|
381
381
|
// Generate final response
|
|
382
|
-
const response = await this.provider.
|
|
382
|
+
const response = await this.provider.generate({
|
|
383
383
|
prompt: enhancedPrompt,
|
|
384
384
|
temperature: 0.7,
|
|
385
385
|
maxTokens: DEFAULT_MAX_TOKENS,
|
|
386
386
|
});
|
|
387
|
-
return response?.
|
|
387
|
+
return response?.content || toolResultsText;
|
|
388
388
|
}
|
|
389
389
|
/**
|
|
390
390
|
* Send a prompt and automatically execute any needed tools
|
|
@@ -303,8 +303,8 @@ export class MCPOrchestrator {
|
|
|
303
303
|
}
|
|
304
304
|
// Step 2: Text generation
|
|
305
305
|
steps.push({
|
|
306
|
-
stepId: "generate
|
|
307
|
-
toolName: "generate
|
|
306
|
+
stepId: "generate",
|
|
307
|
+
toolName: "generate",
|
|
308
308
|
params: {
|
|
309
309
|
prompt,
|
|
310
310
|
provider: options.provider,
|
|
@@ -324,7 +324,7 @@ export class MCPOrchestrator {
|
|
|
324
324
|
params: {
|
|
325
325
|
/* tool-specific params */
|
|
326
326
|
},
|
|
327
|
-
dependsOn: ["generate
|
|
327
|
+
dependsOn: ["generate"],
|
|
328
328
|
});
|
|
329
329
|
}
|
|
330
330
|
}
|
|
@@ -336,7 +336,7 @@ export class MCPOrchestrator {
|
|
|
336
336
|
});
|
|
337
337
|
const executionTime = Date.now() - startTime;
|
|
338
338
|
// Extract text generation result
|
|
339
|
-
const textResult = pipelineResult.results.get("generate
|
|
339
|
+
const textResult = pipelineResult.results.get("generate");
|
|
340
340
|
const providerResult = pipelineResult.results.get("select-provider");
|
|
341
341
|
if (!textResult || !textResult.success) {
|
|
342
342
|
throw new Error("Text generation failed");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink Direct Tools Server
|
|
3
|
+
* Wraps the agent direct tools as an MCP server for proper registration
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Direct Tools Server - Agent direct tools for immediate use
|
|
7
|
+
*/
|
|
8
|
+
export declare const directToolsServer: import("../../factory.js").NeuroLinkMCPServer;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NeuroLink Direct Tools Server
|
|
3
|
+
* Wraps the agent direct tools as an MCP server for proper registration
|
|
4
|
+
*/
|
|
5
|
+
import { createMCPServer } from "../../factory.js";
|
|
6
|
+
import { directAgentTools } from "../../../agent/direct-tools.js";
|
|
7
|
+
import { logger } from "../../../utils/logger.js";
|
|
8
|
+
/**
|
|
9
|
+
* Direct Tools Server - Agent direct tools for immediate use
|
|
10
|
+
*/
|
|
11
|
+
export const directToolsServer = createMCPServer({
|
|
12
|
+
id: "neurolink-direct",
|
|
13
|
+
title: "NeuroLink Direct Tools Server",
|
|
14
|
+
description: "Provides direct agent tools for immediate execution",
|
|
15
|
+
category: "integrations",
|
|
16
|
+
version: "1.0.0",
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Wrap each direct tool and register it with the server
|
|
20
|
+
*/
|
|
21
|
+
Object.entries(directAgentTools).forEach(([toolName, toolDef]) => {
|
|
22
|
+
// The toolDef is a Vercel AI SDK Tool object
|
|
23
|
+
// Extract properties from the Tool object
|
|
24
|
+
const toolSpec = toolDef._spec || toolDef;
|
|
25
|
+
const description = toolSpec.description || `Direct tool: ${toolName}`;
|
|
26
|
+
const inputSchema = toolSpec.parameters;
|
|
27
|
+
const execute = toolSpec.execute;
|
|
28
|
+
directToolsServer.registerTool({
|
|
29
|
+
name: toolName,
|
|
30
|
+
description: description,
|
|
31
|
+
category: getToolCategory(toolName),
|
|
32
|
+
inputSchema: inputSchema,
|
|
33
|
+
isImplemented: true,
|
|
34
|
+
execute: async (params, context) => {
|
|
35
|
+
const startTime = Date.now();
|
|
36
|
+
try {
|
|
37
|
+
logger.debug(`[Direct Tools] Executing ${toolName} with params:`, params);
|
|
38
|
+
// Execute the direct tool
|
|
39
|
+
const result = await execute(params);
|
|
40
|
+
// Convert direct tool result to ToolResult format
|
|
41
|
+
if (result.success) {
|
|
42
|
+
return {
|
|
43
|
+
success: true,
|
|
44
|
+
data: result,
|
|
45
|
+
usage: {
|
|
46
|
+
executionTime: Date.now() - startTime,
|
|
47
|
+
},
|
|
48
|
+
metadata: {
|
|
49
|
+
toolName,
|
|
50
|
+
serverId: "neurolink-direct",
|
|
51
|
+
sessionId: context.sessionId,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return {
|
|
57
|
+
success: false,
|
|
58
|
+
data: null,
|
|
59
|
+
error: result.error || "Unknown error",
|
|
60
|
+
usage: {
|
|
61
|
+
executionTime: Date.now() - startTime,
|
|
62
|
+
},
|
|
63
|
+
metadata: {
|
|
64
|
+
toolName,
|
|
65
|
+
serverId: "neurolink-direct",
|
|
66
|
+
sessionId: context.sessionId,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
logger.error(`[Direct Tools] Error executing ${toolName}:`, error);
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
data: null,
|
|
76
|
+
error: error instanceof Error ? error.message : String(error),
|
|
77
|
+
usage: {
|
|
78
|
+
executionTime: Date.now() - startTime,
|
|
79
|
+
},
|
|
80
|
+
metadata: {
|
|
81
|
+
toolName,
|
|
82
|
+
serverId: "neurolink-direct",
|
|
83
|
+
sessionId: context.sessionId,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* Get tool category based on tool name
|
|
92
|
+
*/
|
|
93
|
+
function getToolCategory(toolName) {
|
|
94
|
+
switch (toolName) {
|
|
95
|
+
case "getCurrentTime":
|
|
96
|
+
return "time";
|
|
97
|
+
case "calculateMath":
|
|
98
|
+
return "math";
|
|
99
|
+
case "readFile":
|
|
100
|
+
case "writeFile":
|
|
101
|
+
case "listDirectory":
|
|
102
|
+
case "searchFiles":
|
|
103
|
+
return "filesystem";
|
|
104
|
+
default:
|
|
105
|
+
return "utility";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Log successful registration
|
|
109
|
+
logger.info(`[Direct Tools] Registered ${Object.keys(directAgentTools).length} direct tools`);
|
|
@@ -108,15 +108,15 @@ export const analyzeAIUsageTool = {
|
|
|
108
108
|
- "analysis" should contain: timeRange, totalRequests, totalTokens, and a "providers" object.
|
|
109
109
|
- "insights" should contain: mostUsedProvider, avgCostPerToken, peakUsageHours, costOptimizationPotential, and an array of "recommendations".
|
|
110
110
|
`;
|
|
111
|
-
const result = await provider.
|
|
111
|
+
const result = await provider.generate({
|
|
112
112
|
prompt: analysisPrompt,
|
|
113
113
|
maxTokens: 800,
|
|
114
114
|
temperature: 0.5,
|
|
115
115
|
});
|
|
116
|
-
if (!result || !result.
|
|
116
|
+
if (!result || !result.content) {
|
|
117
117
|
throw new Error("AI provider returned no result for usage analysis.");
|
|
118
118
|
}
|
|
119
|
-
const parsedData = JSON.parse(result.
|
|
119
|
+
const parsedData = JSON.parse(result.content);
|
|
120
120
|
const executionTime = Date.now() - startTime;
|
|
121
121
|
return {
|
|
122
122
|
success: true,
|
|
@@ -190,8 +190,8 @@ export const benchmarkProviderPerformanceTool = {
|
|
|
190
190
|
for (const prompt of testPrompts) {
|
|
191
191
|
for (let i = 0; i < params.iterations; i++) {
|
|
192
192
|
const testStartTime = Date.now();
|
|
193
|
-
const result = await provider.
|
|
194
|
-
prompt,
|
|
193
|
+
const result = await provider.generate({
|
|
194
|
+
prompt: prompt,
|
|
195
195
|
maxTokens: params.maxTokens,
|
|
196
196
|
});
|
|
197
197
|
if (result && result.usage) {
|
|
@@ -274,7 +274,7 @@ export const optimizePromptParametersTool = {
|
|
|
274
274
|
const optimizationResults = [];
|
|
275
275
|
const temperatures = [0.2, 0.7, 1.0]; // Test a range of temperatures
|
|
276
276
|
for (const temp of temperatures) {
|
|
277
|
-
const result = await provider.
|
|
277
|
+
const result = await provider.generate({
|
|
278
278
|
prompt: params.prompt,
|
|
279
279
|
temperature: temp,
|
|
280
280
|
maxTokens: params.targetLength || 250,
|
|
@@ -282,7 +282,7 @@ export const optimizePromptParametersTool = {
|
|
|
282
282
|
if (result) {
|
|
283
283
|
optimizationResults.push({
|
|
284
284
|
parameters: { temperature: temp },
|
|
285
|
-
output: result.
|
|
285
|
+
output: result.content,
|
|
286
286
|
usage: result.usage,
|
|
287
287
|
});
|
|
288
288
|
}
|
|
@@ -300,14 +300,14 @@ export const optimizePromptParametersTool = {
|
|
|
300
300
|
Determine which set of parameters is optimal and provide a recommendation.
|
|
301
301
|
Return a valid JSON object with keys: "optimalParameters", "reasoning", "recommendations".
|
|
302
302
|
`;
|
|
303
|
-
const analysisResult = await analysisProvider.
|
|
303
|
+
const analysisResult = await analysisProvider.generate({
|
|
304
304
|
prompt: analysisPrompt,
|
|
305
305
|
maxTokens: 500,
|
|
306
306
|
});
|
|
307
|
-
if (!analysisResult || !analysisResult.
|
|
307
|
+
if (!analysisResult || !analysisResult.content) {
|
|
308
308
|
throw new Error("Optimization analysis failed.");
|
|
309
309
|
}
|
|
310
|
-
const parsedAnalysis = JSON.parse(analysisResult.
|
|
310
|
+
const parsedAnalysis = JSON.parse(analysisResult.content);
|
|
311
311
|
const executionTime = Date.now() - startTime;
|
|
312
312
|
return {
|
|
313
313
|
success: true,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { createMCPServer } from "../../factory.js";
|
|
8
|
-
import {
|
|
8
|
+
import { ServiceRegistry } from "../../../core/service-registry.js";
|
|
9
9
|
import { getBestProvider, getAvailableProviders, } from "../../../utils/providerUtils.js";
|
|
10
10
|
import { logger } from "../../../utils/logger.js";
|
|
11
11
|
import { analyzeAIUsageTool, benchmarkProviderPerformanceTool, optimizePromptParametersTool, } from "./ai-analysis-tools.js";
|
|
@@ -75,7 +75,7 @@ const ProviderSelectionSchema = z.object({
|
|
|
75
75
|
* Core tool that leverages existing AIProviderFactory for text generation
|
|
76
76
|
*/
|
|
77
77
|
aiCoreServer.registerTool({
|
|
78
|
-
name: "generate
|
|
78
|
+
name: "generate",
|
|
79
79
|
description: "Generate text using AI providers with automatic fallback and provider selection",
|
|
80
80
|
category: "text-generation",
|
|
81
81
|
inputSchema: TextGenerationSchema,
|
|
@@ -86,9 +86,11 @@ aiCoreServer.registerTool({
|
|
|
86
86
|
logger.debug(`[AI-Core] Starting text generation: "${params.prompt.substring(0, 50)}..."`);
|
|
87
87
|
// Use existing AIProviderFactory with best provider selection
|
|
88
88
|
const selectedProvider = params.provider || (await getBestProvider(params.provider));
|
|
89
|
+
// Get AIProviderFactory from ServiceRegistry to avoid circular dependency
|
|
90
|
+
const AIProviderFactory = await ServiceRegistry.get("AIProviderFactory");
|
|
89
91
|
const provider = await AIProviderFactory.createBestProvider(selectedProvider);
|
|
90
92
|
// Generate text using existing NeuroLink patterns
|
|
91
|
-
const result = await provider.
|
|
93
|
+
const result = await provider.generate({
|
|
92
94
|
prompt: params.prompt,
|
|
93
95
|
model: params.model,
|
|
94
96
|
temperature: params.temperature,
|
|
@@ -103,7 +105,7 @@ aiCoreServer.registerTool({
|
|
|
103
105
|
return {
|
|
104
106
|
success: true,
|
|
105
107
|
data: {
|
|
106
|
-
text: result.
|
|
108
|
+
text: result.content,
|
|
107
109
|
model: params.model || "default",
|
|
108
110
|
provider: selectedProvider,
|
|
109
111
|
generatedAt: new Date().toISOString(),
|
|
@@ -115,7 +117,7 @@ aiCoreServer.registerTool({
|
|
|
115
117
|
executionTime,
|
|
116
118
|
},
|
|
117
119
|
metadata: {
|
|
118
|
-
toolName: "generate
|
|
120
|
+
toolName: "generate",
|
|
119
121
|
serverId: "neurolink-ai-core",
|
|
120
122
|
sessionId: context.sessionId,
|
|
121
123
|
timestamp: Date.now(),
|
|
@@ -131,7 +133,7 @@ aiCoreServer.registerTool({
|
|
|
131
133
|
success: false,
|
|
132
134
|
error: errorMessage,
|
|
133
135
|
metadata: {
|
|
134
|
-
toolName: "generate
|
|
136
|
+
toolName: "generate",
|
|
135
137
|
serverId: "neurolink-ai-core",
|
|
136
138
|
sessionId: context.sessionId,
|
|
137
139
|
timestamp: Date.now(),
|
|
@@ -88,14 +88,14 @@ export declare const workflowToolSchemas: {
|
|
|
88
88
|
}, "strip", z.ZodTypeAny, {
|
|
89
89
|
aiOutput: string;
|
|
90
90
|
expectedBehavior: string;
|
|
91
|
-
outputType: "
|
|
91
|
+
outputType: "text" | "code" | "structured-data" | "conversation";
|
|
92
92
|
includeFixSuggestions: boolean;
|
|
93
93
|
context?: string | undefined;
|
|
94
94
|
}, {
|
|
95
95
|
aiOutput: string;
|
|
96
96
|
expectedBehavior: string;
|
|
97
97
|
context?: string | undefined;
|
|
98
|
-
outputType?: "
|
|
98
|
+
outputType?: "text" | "code" | "structured-data" | "conversation" | undefined;
|
|
99
99
|
includeFixSuggestions?: boolean | undefined;
|
|
100
100
|
}>;
|
|
101
101
|
};
|
|
@@ -144,16 +144,16 @@ Return ONLY a valid JSON object with this exact structure:
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
Generate 3-5 comprehensive test cases covering the requested types.`;
|
|
147
|
-
const result = await provider.
|
|
148
|
-
prompt,
|
|
147
|
+
const result = await provider.generate({
|
|
148
|
+
prompt: prompt,
|
|
149
149
|
maxTokens: Math.floor(DEFAULT_MAX_TOKENS * 1.2),
|
|
150
150
|
temperature: 0.3, // Lower temperature for more consistent structured output
|
|
151
151
|
});
|
|
152
|
-
if (!result || !result.
|
|
152
|
+
if (!result || !result.content) {
|
|
153
153
|
throw new Error("AI provider returned no result for test case generation.");
|
|
154
154
|
}
|
|
155
155
|
// Parse AI response
|
|
156
|
-
const aiResponse = JSON.parse(result.
|
|
156
|
+
const aiResponse = JSON.parse(result.content);
|
|
157
157
|
const testCases = aiResponse.testCases || [];
|
|
158
158
|
const executionTime = Date.now() - startTime;
|
|
159
159
|
const responseData = {
|
|
@@ -250,16 +250,16 @@ Return ONLY a valid JSON object with this exact structure:
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
Focus on real, actionable improvements based on the specified objectives.`;
|
|
253
|
-
const result = await provider.
|
|
254
|
-
prompt,
|
|
253
|
+
const result = await provider.generate({
|
|
254
|
+
prompt: prompt,
|
|
255
255
|
maxTokens: DEFAULT_MAX_TOKENS,
|
|
256
256
|
temperature: 0.2, // Very low temperature for consistent refactoring
|
|
257
257
|
});
|
|
258
|
-
if (!result || !result.
|
|
258
|
+
if (!result || !result.content) {
|
|
259
259
|
throw new Error("AI provider returned no result for code refactoring.");
|
|
260
260
|
}
|
|
261
261
|
// Parse AI response
|
|
262
|
-
const aiResponse = JSON.parse(result.
|
|
262
|
+
const aiResponse = JSON.parse(result.content);
|
|
263
263
|
const executionTime = Date.now() - startTime;
|
|
264
264
|
const responseData = {
|
|
265
265
|
refactoredCode: aiResponse.refactoredCode || code,
|
|
@@ -358,16 +358,16 @@ Return ONLY a valid JSON object with this exact structure:
|
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
Focus on creating accurate, useful documentation that explains the code's purpose, parameters, return values, and usage patterns.`;
|
|
361
|
-
const result = await provider.
|
|
362
|
-
prompt,
|
|
361
|
+
const result = await provider.generate({
|
|
362
|
+
prompt: prompt,
|
|
363
363
|
maxTokens: Math.floor(DEFAULT_MAX_TOKENS * 1.2),
|
|
364
364
|
temperature: 0.3, // Moderate temperature for creative but structured documentation
|
|
365
365
|
});
|
|
366
|
-
if (!result || !result.
|
|
366
|
+
if (!result || !result.content) {
|
|
367
367
|
throw new Error("AI provider returned no result for documentation generation.");
|
|
368
368
|
}
|
|
369
369
|
// Parse AI response
|
|
370
|
-
const aiResponse = JSON.parse(result.
|
|
370
|
+
const aiResponse = JSON.parse(result.content);
|
|
371
371
|
const executionTime = Date.now() - startTime;
|
|
372
372
|
const responseData = {
|
|
373
373
|
documentation: aiResponse.documentation || "Documentation generated successfully",
|
|
@@ -483,16 +483,16 @@ Return ONLY a valid JSON object with this exact structure:
|
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
Provide thorough, actionable analysis focused on improving AI output quality.`;
|
|
486
|
-
const result = await provider.
|
|
487
|
-
prompt,
|
|
486
|
+
const result = await provider.generate({
|
|
487
|
+
prompt: prompt,
|
|
488
488
|
maxTokens: DEFAULT_MAX_TOKENS,
|
|
489
489
|
temperature: 0.4, // Moderate temperature for analytical thinking
|
|
490
490
|
});
|
|
491
|
-
if (!result || !result.
|
|
491
|
+
if (!result || !result.content) {
|
|
492
492
|
throw new Error("AI provider returned no result for output debugging.");
|
|
493
493
|
}
|
|
494
494
|
// Parse AI response
|
|
495
|
-
const aiResponse = JSON.parse(result.
|
|
495
|
+
const aiResponse = JSON.parse(result.content);
|
|
496
496
|
const executionTime = Date.now() - startTime;
|
|
497
497
|
const responseData = {
|
|
498
498
|
issues: aiResponse.issues || [],
|
|
@@ -26,6 +26,10 @@ export declare class UnifiedMCPRegistry extends MCPToolRegistry {
|
|
|
26
26
|
* Load servers from .mcp-config.json
|
|
27
27
|
*/
|
|
28
28
|
private loadManualConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Connect to manually configured servers
|
|
31
|
+
*/
|
|
32
|
+
private connectManualServers;
|
|
29
33
|
/**
|
|
30
34
|
* Enable or disable auto-discovery
|
|
31
35
|
*/
|