@juspay/neurolink 4.1.1 → 4.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 +8 -2
- package/README.md +1 -12
- package/dist/cli/commands/mcp.d.ts +11 -0
- package/dist/cli/commands/mcp.js +332 -223
- package/dist/cli/index.js +69 -8
- package/dist/core/factory.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/core/factory.js +2 -2
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/mcp/context-manager.d.ts +6 -0
- package/dist/lib/mcp/context-manager.js +8 -0
- package/dist/lib/mcp/contracts/mcpContract.d.ts +1 -0
- package/dist/lib/mcp/external-client.js +6 -2
- package/dist/lib/mcp/initialize.d.ts +2 -1
- package/dist/lib/mcp/initialize.js +8 -7
- package/dist/lib/mcp/orchestrator.js +9 -0
- package/dist/lib/mcp/registry.d.ts +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +3 -3
- 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 +1 -1
- package/dist/lib/mcp/session-manager.js +1 -1
- package/dist/lib/mcp/session-persistence.js +1 -1
- package/dist/lib/mcp/tool-registry.d.ts +31 -11
- package/dist/lib/mcp/tool-registry.js +226 -38
- package/dist/lib/mcp/unified-mcp.d.ts +12 -2
- package/dist/lib/mcp/unified-registry.d.ts +21 -7
- package/dist/lib/mcp/unified-registry.js +179 -17
- package/dist/lib/neurolink.js +17 -25
- package/dist/lib/providers/googleVertexAI.js +19 -1
- package/dist/lib/providers/openAI.js +18 -1
- package/dist/lib/utils/provider-setup-messages.d.ts +8 -0
- package/dist/lib/utils/provider-setup-messages.js +120 -0
- package/dist/lib/utils/provider-validation.d.ts +35 -0
- package/dist/lib/utils/provider-validation.js +625 -0
- package/dist/lib/utils/providerUtils-fixed.js +20 -1
- package/dist/lib/utils/providerUtils.d.ts +2 -2
- package/dist/lib/utils/providerUtils.js +38 -7
- package/dist/lib/utils/timeout-manager.d.ts +75 -0
- package/dist/lib/utils/timeout-manager.js +244 -0
- package/dist/mcp/context-manager.d.ts +6 -0
- package/dist/mcp/context-manager.js +8 -0
- package/dist/mcp/contracts/mcpContract.d.ts +1 -0
- package/dist/mcp/external-client.js +6 -2
- package/dist/mcp/initialize.d.ts +2 -1
- package/dist/mcp/initialize.js +8 -7
- package/dist/mcp/orchestrator.js +9 -0
- package/dist/mcp/registry.d.ts +1 -1
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +1 -1
- package/dist/mcp/servers/ai-providers/ai-core-server.js +3 -3
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +2 -2
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +1 -1
- package/dist/mcp/session-manager.js +1 -1
- package/dist/mcp/session-persistence.js +1 -1
- package/dist/mcp/tool-registry.d.ts +31 -11
- package/dist/mcp/tool-registry.js +226 -38
- package/dist/mcp/unified-mcp.d.ts +12 -2
- package/dist/mcp/unified-registry.d.ts +21 -7
- package/dist/mcp/unified-registry.js +179 -17
- package/dist/neurolink.js +17 -25
- package/dist/providers/googleVertexAI.js +19 -1
- package/dist/providers/openAI.js +18 -1
- package/dist/utils/provider-setup-messages.d.ts +8 -0
- package/dist/utils/provider-setup-messages.js +120 -0
- package/dist/utils/provider-validation.d.ts +35 -0
- package/dist/utils/provider-validation.js +625 -0
- package/dist/utils/providerUtils-fixed.js +20 -1
- package/dist/utils/providerUtils.d.ts +2 -2
- package/dist/utils/providerUtils.js +38 -7
- package/dist/utils/timeout-manager.d.ts +75 -0
- package/dist/utils/timeout-manager.js +244 -0
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -291,12 +291,11 @@ const cli = yargs(args)
|
|
|
291
291
|
exitProcess(); // Default exit
|
|
292
292
|
})
|
|
293
293
|
// Generate Text Command
|
|
294
|
-
.command(["generate-text
|
|
295
|
-
.usage("Usage: $0 generate-text
|
|
294
|
+
.command(["generate-text [prompt]", "generate [prompt]", "gen [prompt]"], "Generate text using AI providers", (yargsInstance) => yargsInstance
|
|
295
|
+
.usage("Usage: $0 generate-text [prompt] [options]")
|
|
296
296
|
.positional("prompt", {
|
|
297
297
|
type: "string",
|
|
298
|
-
description: "Text prompt for AI generation",
|
|
299
|
-
demandOption: true,
|
|
298
|
+
description: "Text prompt for AI generation (or read from stdin)",
|
|
300
299
|
})
|
|
301
300
|
.option("provider", {
|
|
302
301
|
choices: [
|
|
@@ -384,6 +383,53 @@ const cli = yargs(args)
|
|
|
384
383
|
.example('$0 generate-text "Write a story" --provider openai', "Use specific provider")
|
|
385
384
|
.example('$0 generate-text "What time is it?"', "Use with natural tool integration (default)")
|
|
386
385
|
.example('$0 generate-text "Hello world" --disable-tools', "Use without tool integration"), async (argv) => {
|
|
386
|
+
// SOLUTION 1: Handle stdin input if no prompt provided
|
|
387
|
+
if (!argv.prompt && !process.stdin.isTTY) {
|
|
388
|
+
// Read from stdin
|
|
389
|
+
let stdinData = "";
|
|
390
|
+
process.stdin.setEncoding("utf8");
|
|
391
|
+
for await (const chunk of process.stdin) {
|
|
392
|
+
stdinData += chunk;
|
|
393
|
+
}
|
|
394
|
+
argv.prompt = stdinData.trim();
|
|
395
|
+
if (!argv.prompt) {
|
|
396
|
+
throw new Error("No input received from stdin");
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else if (!argv.prompt) {
|
|
400
|
+
throw new Error('Prompt required. Use: neurolink generate "your prompt" or echo "prompt" | neurolink generate');
|
|
401
|
+
}
|
|
402
|
+
// SOLUTION 2: Parameter validation
|
|
403
|
+
const errors = [];
|
|
404
|
+
// Validate max-tokens
|
|
405
|
+
if (argv.maxTokens !== undefined) {
|
|
406
|
+
if (!Number.isInteger(argv.maxTokens) || argv.maxTokens < 1) {
|
|
407
|
+
errors.push(`max-tokens must be a positive integer >= 1, got: ${argv.maxTokens}`);
|
|
408
|
+
}
|
|
409
|
+
if (argv.maxTokens > 100000) {
|
|
410
|
+
errors.push(`max-tokens too large (>100000), got: ${argv.maxTokens}`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
// Validate temperature
|
|
414
|
+
if (argv.temperature !== undefined) {
|
|
415
|
+
if (typeof argv.temperature !== "number" ||
|
|
416
|
+
argv.temperature < 0 ||
|
|
417
|
+
argv.temperature > 1) {
|
|
418
|
+
errors.push(`temperature must be between 0.0 and 1.0, got: ${argv.temperature}`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// Validate timeout
|
|
422
|
+
if (argv.timeout !== undefined) {
|
|
423
|
+
if (!Number.isInteger(argv.timeout) || argv.timeout < 1) {
|
|
424
|
+
errors.push(`timeout must be a positive integer >= 1 second, got: ${argv.timeout}`);
|
|
425
|
+
}
|
|
426
|
+
if (argv.timeout > 600) {
|
|
427
|
+
errors.push(`timeout too large (>600s), got: ${argv.timeout}s`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (errors.length > 0) {
|
|
431
|
+
throw new Error(`Parameter validation failed:\n${errors.map((e) => ` • ${e}`).join("\n")}\n\nUse --help for valid parameter ranges.`);
|
|
432
|
+
}
|
|
387
433
|
// Check if generate-text was used specifically (for deprecation warning)
|
|
388
434
|
const usedCommand = argv._[0];
|
|
389
435
|
if (usedCommand === "generate-text" && !argv.quiet) {
|
|
@@ -591,12 +637,11 @@ const cli = yargs(args)
|
|
|
591
637
|
}
|
|
592
638
|
})
|
|
593
639
|
// Stream Text Command
|
|
594
|
-
.command("stream
|
|
595
|
-
.usage("Usage: $0 stream
|
|
640
|
+
.command("stream [prompt]", "Stream text generation in real-time", (yargsInstance) => yargsInstance
|
|
641
|
+
.usage("Usage: $0 stream [prompt] [options]")
|
|
596
642
|
.positional("prompt", {
|
|
597
643
|
type: "string",
|
|
598
|
-
description: "Text prompt for streaming",
|
|
599
|
-
demandOption: true,
|
|
644
|
+
description: "Text prompt for streaming (or read from stdin)",
|
|
600
645
|
})
|
|
601
646
|
.option("provider", {
|
|
602
647
|
choices: [
|
|
@@ -668,6 +713,22 @@ const cli = yargs(args)
|
|
|
668
713
|
.example('$0 stream "Tell me a story"', "Stream a story in real-time")
|
|
669
714
|
.example('$0 stream "What time is it?"', "Stream with natural tool integration (default)")
|
|
670
715
|
.example('$0 stream "Tell me a story" --disable-tools', "Stream without tool integration"), async (argv) => {
|
|
716
|
+
// SOLUTION 1: Handle stdin input if no prompt provided
|
|
717
|
+
if (!argv.prompt && !process.stdin.isTTY) {
|
|
718
|
+
// Read from stdin
|
|
719
|
+
let stdinData = "";
|
|
720
|
+
process.stdin.setEncoding("utf8");
|
|
721
|
+
for await (const chunk of process.stdin) {
|
|
722
|
+
stdinData += chunk;
|
|
723
|
+
}
|
|
724
|
+
argv.prompt = stdinData.trim();
|
|
725
|
+
if (!argv.prompt) {
|
|
726
|
+
throw new Error("No input received from stdin");
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
else if (!argv.prompt) {
|
|
730
|
+
throw new Error('Prompt required. Use: neurolink stream "your prompt" or echo "prompt" | neurolink stream');
|
|
731
|
+
}
|
|
671
732
|
// Default mode: Simple streaming message
|
|
672
733
|
// Debug mode: More detailed information
|
|
673
734
|
if (!argv.quiet && !argv.debug) {
|
package/dist/core/factory.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GoogleVertexAI, AmazonBedrock, OpenAI, AnthropicProvider, AzureOpenAIProvider, GoogleAIStudio, HuggingFace, Ollama, MistralAI, } from "../providers/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getBestProvider } from "../utils/providerUtils.js";
|
|
3
3
|
import { logger } from "../utils/logger.js";
|
|
4
4
|
import { dynamicModelProvider } from "./dynamic-models.js";
|
|
5
5
|
const componentIdentifier = "aiProviderFactory";
|
|
@@ -240,7 +240,7 @@ export class AIProviderFactory {
|
|
|
240
240
|
static async createBestProvider(requestedProvider, modelName, enableMCP = true) {
|
|
241
241
|
const functionTag = "AIProviderFactory.createBestProvider";
|
|
242
242
|
try {
|
|
243
|
-
const bestProvider =
|
|
243
|
+
const bestProvider = await getBestProvider(requestedProvider);
|
|
244
244
|
logger.debug(`[${functionTag}] Best provider selected`, {
|
|
245
245
|
requestedProvider: requestedProvider || "auto",
|
|
246
246
|
selectedProvider: bestProvider,
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { BedrockModels, OpenAIModels, VertexModels, DEFAULT_PROVIDER_CONFIGS, }
|
|
|
13
13
|
export { GoogleVertexAI, AmazonBedrock, OpenAI, AnthropicProvider, AzureOpenAIProvider, } from "./providers/index.js";
|
|
14
14
|
export type { ProviderName } from "./providers/index.js";
|
|
15
15
|
export { PROVIDERS, AVAILABLE_PROVIDERS } from "./providers/index.js";
|
|
16
|
-
export {
|
|
16
|
+
export { getBestProvider, getAvailableProviders, isValidProvider, } from "./utils/providerUtils.js";
|
|
17
17
|
export { NeuroLink } from "./neurolink.js";
|
|
18
18
|
export type { TextGenerationOptions, StreamTextOptions, TextGenerationResult, } from "./neurolink.js";
|
|
19
19
|
export declare const VERSION = "1.0.0";
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export { BedrockModels, OpenAIModels, VertexModels, DEFAULT_PROVIDER_CONFIGS, }
|
|
|
15
15
|
export { GoogleVertexAI, AmazonBedrock, OpenAI, AnthropicProvider, AzureOpenAIProvider, } from "./providers/index.js";
|
|
16
16
|
export { PROVIDERS, AVAILABLE_PROVIDERS } from "./providers/index.js";
|
|
17
17
|
// Utility exports
|
|
18
|
-
export {
|
|
18
|
+
export { getBestProvider, getAvailableProviders, isValidProvider, } from "./utils/providerUtils.js";
|
|
19
19
|
// Main NeuroLink wrapper class
|
|
20
20
|
export { NeuroLink } from "./neurolink.js";
|
|
21
21
|
// Version
|
package/dist/lib/core/factory.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GoogleVertexAI, AmazonBedrock, OpenAI, AnthropicProvider, AzureOpenAIProvider, GoogleAIStudio, HuggingFace, Ollama, MistralAI, } from "../providers/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getBestProvider } from "../utils/providerUtils.js";
|
|
3
3
|
import { logger } from "../utils/logger.js";
|
|
4
4
|
const componentIdentifier = "aiProviderFactory";
|
|
5
5
|
/**
|
|
@@ -239,7 +239,7 @@ export class AIProviderFactory {
|
|
|
239
239
|
static async createBestProvider(requestedProvider, modelName, enableMCP = true) {
|
|
240
240
|
const functionTag = "AIProviderFactory.createBestProvider";
|
|
241
241
|
try {
|
|
242
|
-
const bestProvider =
|
|
242
|
+
const bestProvider = await getBestProvider(requestedProvider);
|
|
243
243
|
logger.debug(`[${functionTag}] Best provider selected`, {
|
|
244
244
|
requestedProvider: requestedProvider || "auto",
|
|
245
245
|
selectedProvider: bestProvider,
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { BedrockModels, OpenAIModels, VertexModels, DEFAULT_PROVIDER_CONFIGS, }
|
|
|
13
13
|
export { GoogleVertexAI, AmazonBedrock, OpenAI, AnthropicProvider, AzureOpenAIProvider, } from "./providers/index.js";
|
|
14
14
|
export type { ProviderName } from "./providers/index.js";
|
|
15
15
|
export { PROVIDERS, AVAILABLE_PROVIDERS } from "./providers/index.js";
|
|
16
|
-
export {
|
|
16
|
+
export { getBestProvider, getAvailableProviders, isValidProvider, } from "./utils/providerUtils.js";
|
|
17
17
|
export { NeuroLink } from "./neurolink.js";
|
|
18
18
|
export type { TextGenerationOptions, StreamTextOptions, TextGenerationResult, } from "./neurolink.js";
|
|
19
19
|
export declare const VERSION = "1.0.0";
|
package/dist/lib/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export { BedrockModels, OpenAIModels, VertexModels, DEFAULT_PROVIDER_CONFIGS, }
|
|
|
15
15
|
export { GoogleVertexAI, AmazonBedrock, OpenAI, AnthropicProvider, AzureOpenAIProvider, } from "./providers/index.js";
|
|
16
16
|
export { PROVIDERS, AVAILABLE_PROVIDERS } from "./providers/index.js";
|
|
17
17
|
// Utility exports
|
|
18
|
-
export {
|
|
18
|
+
export { getBestProvider, getAvailableProviders, isValidProvider, } from "./utils/providerUtils.js";
|
|
19
19
|
// Main NeuroLink wrapper class
|
|
20
20
|
export { NeuroLink } from "./neurolink.js";
|
|
21
21
|
// Version
|
|
@@ -79,6 +79,12 @@ export declare class ContextManager {
|
|
|
79
79
|
* @param updates Partial context updates
|
|
80
80
|
*/
|
|
81
81
|
updateContext(sessionId: string, updates: Partial<NeuroLinkExecutionContext>): void;
|
|
82
|
+
/**
|
|
83
|
+
* Store context directly (used when session ID changes)
|
|
84
|
+
*
|
|
85
|
+
* @param context Complete execution context to store
|
|
86
|
+
*/
|
|
87
|
+
storeContext(context: NeuroLinkExecutionContext): void;
|
|
82
88
|
/**
|
|
83
89
|
* Remove context from active tracking
|
|
84
90
|
*
|
|
@@ -196,6 +196,14 @@ export class ContextManager {
|
|
|
196
196
|
this.activeContexts.set(sessionId, updatedContext);
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Store context directly (used when session ID changes)
|
|
201
|
+
*
|
|
202
|
+
* @param context Complete execution context to store
|
|
203
|
+
*/
|
|
204
|
+
storeContext(context) {
|
|
205
|
+
this.activeContexts.set(context.sessionId, context);
|
|
206
|
+
}
|
|
199
207
|
/**
|
|
200
208
|
* Remove context from active tracking
|
|
201
209
|
*
|
|
@@ -40,6 +40,10 @@ export class ExternalMCPClient extends EventEmitter {
|
|
|
40
40
|
stdio: ["pipe", "pipe", "pipe"],
|
|
41
41
|
env: { ...process.env, ...this.config.env },
|
|
42
42
|
});
|
|
43
|
+
// 🔧 FIX: Register for cleanup
|
|
44
|
+
process.once("beforeExit", () => this.disconnect());
|
|
45
|
+
process.once("SIGINT", () => this.disconnect());
|
|
46
|
+
process.once("SIGTERM", () => this.disconnect());
|
|
43
47
|
if (!this.process.stdout || !this.process.stdin || !this.process.stderr) {
|
|
44
48
|
throw new Error("Failed to create stdio pipes");
|
|
45
49
|
}
|
|
@@ -279,7 +283,7 @@ export class ExternalMCPClient extends EventEmitter {
|
|
|
279
283
|
pending.reject(new Error("Connection closed"));
|
|
280
284
|
}
|
|
281
285
|
this.pendingRequests.clear();
|
|
282
|
-
//
|
|
286
|
+
// 🔧 FIX: Enhanced process cleanup
|
|
283
287
|
if (this.process) {
|
|
284
288
|
this.process.kill("SIGTERM");
|
|
285
289
|
// Force kill after timeout
|
|
@@ -287,7 +291,7 @@ export class ExternalMCPClient extends EventEmitter {
|
|
|
287
291
|
if (this.process && !this.process.killed) {
|
|
288
292
|
this.process.kill("SIGKILL");
|
|
289
293
|
}
|
|
290
|
-
},
|
|
294
|
+
}, 1000); // Reduced from 5000ms to 1000ms
|
|
291
295
|
this.process = null;
|
|
292
296
|
}
|
|
293
297
|
this.isConnected = false;
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* Automatically registers built-in NeuroLink servers with the default registry
|
|
4
4
|
* Ensures built-in tools are always available without manual configuration
|
|
5
5
|
*/
|
|
6
|
+
import { type MCPToolRegistry } from "./tool-registry.js";
|
|
6
7
|
/**
|
|
7
8
|
* Initialize NeuroLink MCP system by registering built-in servers
|
|
8
9
|
*/
|
|
9
|
-
export declare function initializeNeuroLinkMCP(): Promise<void>;
|
|
10
|
+
export declare function initializeNeuroLinkMCP(targetRegistry?: MCPToolRegistry): Promise<void>;
|
|
10
11
|
/**
|
|
11
12
|
* Get initialization status
|
|
12
13
|
*/
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* Automatically registers built-in NeuroLink servers with the default registry
|
|
4
4
|
* Ensures built-in tools are always available without manual configuration
|
|
5
5
|
*/
|
|
6
|
-
import { toolRegistry, defaultToolRegistry } from "./tool-registry.js";
|
|
6
|
+
import { toolRegistry, defaultToolRegistry, } from "./tool-registry.js";
|
|
7
7
|
import { mcpLogger } from "./logging.js";
|
|
8
8
|
let isInitialized = false;
|
|
9
9
|
/**
|
|
10
10
|
* Initialize NeuroLink MCP system by registering built-in servers
|
|
11
11
|
*/
|
|
12
|
-
export async function initializeNeuroLinkMCP() {
|
|
12
|
+
export async function initializeNeuroLinkMCP(targetRegistry) {
|
|
13
13
|
if (isInitialized) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
@@ -18,14 +18,15 @@ export async function initializeNeuroLinkMCP() {
|
|
|
18
18
|
// Import utility server dynamically to avoid circular dependencies
|
|
19
19
|
// Note: AI core server temporarily disabled due to circular dependency issues
|
|
20
20
|
const { utilityServer } = await import("./servers/utilities/utility-server.js");
|
|
21
|
-
// Register built-in NeuroLink servers with
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
// Register built-in NeuroLink servers with specified registry (or default)
|
|
22
|
+
const registry = targetRegistry || toolRegistry;
|
|
23
|
+
await registry.registerServer(utilityServer.id, utilityServer);
|
|
24
|
+
mcpLogger.debug(`Registered neurolink-utility server with built-in tools in ${targetRegistry ? "target" : "default"} registry`);
|
|
24
25
|
// TODO: Re-enable AI core server once circular dependencies are resolved
|
|
25
26
|
// const { aiCoreServer } = await import('./servers/ai-providers/ai-core-server.js');
|
|
26
|
-
// await
|
|
27
|
+
// await registry.registerServer(aiCoreServer.id, aiCoreServer);
|
|
27
28
|
// mcpLogger.debug('Registered neurolink-ai-core server with AI tools');
|
|
28
|
-
const stats = await
|
|
29
|
+
const stats = await registry.getStats();
|
|
29
30
|
mcpLogger.info(`Initialization complete: ${stats.totalServers} server, ${stats.totalTools} tools available`);
|
|
30
31
|
isInitialized = true;
|
|
31
32
|
}
|
|
@@ -70,7 +70,14 @@ export class MCPOrchestrator {
|
|
|
70
70
|
// Create new session with options
|
|
71
71
|
session = await this.sessionManager.createSession(context, options.sessionOptions);
|
|
72
72
|
// Update context with new session ID
|
|
73
|
+
const oldSessionId = context.sessionId;
|
|
73
74
|
context.sessionId = session.id;
|
|
75
|
+
// Remove old context and store updated context in context manager
|
|
76
|
+
if (oldSessionId) {
|
|
77
|
+
this.contextManager.removeContext(oldSessionId);
|
|
78
|
+
}
|
|
79
|
+
// Store the updated context with the new session ID
|
|
80
|
+
this.contextManager.storeContext(context);
|
|
74
81
|
}
|
|
75
82
|
if (process.env.NEUROLINK_DEBUG === "true") {
|
|
76
83
|
console.log(`[Orchestrator] Executing tool '${toolName}' in session ${context.sessionId}`);
|
|
@@ -80,6 +87,8 @@ export class MCPOrchestrator {
|
|
|
80
87
|
const semaphoreKey = `tool:${toolName}`;
|
|
81
88
|
const semaphoreResult = await this.semaphoreManager.acquire(semaphoreKey, async () => {
|
|
82
89
|
try {
|
|
90
|
+
// Add tool to the execution chain
|
|
91
|
+
this.contextManager.addToToolChain(context, toolName);
|
|
83
92
|
// Execute tool through registry
|
|
84
93
|
const result = await this.registry.executeTool(toolName, params, context);
|
|
85
94
|
if (process.env.NEUROLINK_DEBUG === "true") {
|
|
@@ -15,7 +15,7 @@ export interface McpRegistry {
|
|
|
15
15
|
* Maintains backward compatibility with existing code
|
|
16
16
|
*/
|
|
17
17
|
export declare class MCPRegistry implements McpRegistry {
|
|
18
|
-
|
|
18
|
+
plugins: Map<string, DiscoveredMcp<Record<string, unknown>>>;
|
|
19
19
|
/**
|
|
20
20
|
* Register a plugin
|
|
21
21
|
*/
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { AIProviderFactory } from "../../../core/factory.js";
|
|
8
|
-
import {
|
|
8
|
+
import { getBestProvider, getAvailableProviders, } from "../../../utils/providerUtils.js";
|
|
9
9
|
/**
|
|
10
10
|
* Input Schemas for AI Analysis Tools
|
|
11
11
|
*/
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { createMCPServer } from "../../factory.js";
|
|
8
8
|
import { AIProviderFactory } from "../../../core/factory.js";
|
|
9
|
-
import {
|
|
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";
|
|
12
12
|
import { generateTestCasesTool, refactorCodeTool, generateDocumentationTool, debugAIOutputTool, } from "./ai-workflow-tools.js";
|
|
@@ -85,7 +85,7 @@ aiCoreServer.registerTool({
|
|
|
85
85
|
try {
|
|
86
86
|
logger.debug(`[AI-Core] Starting text generation: "${params.prompt.substring(0, 50)}..."`);
|
|
87
87
|
// Use existing AIProviderFactory with best provider selection
|
|
88
|
-
const selectedProvider = params.provider || getBestProvider(params.provider);
|
|
88
|
+
const selectedProvider = params.provider || (await getBestProvider(params.provider));
|
|
89
89
|
const provider = await AIProviderFactory.createBestProvider(selectedProvider);
|
|
90
90
|
// Generate text using existing NeuroLink patterns
|
|
91
91
|
const result = await provider.generateText({
|
|
@@ -157,7 +157,7 @@ aiCoreServer.registerTool({
|
|
|
157
157
|
logger.debug(`[AI-Core] Selecting provider with requirements:`, params.requirements);
|
|
158
158
|
// Use existing provider selection logic
|
|
159
159
|
const availableProviders = getAvailableProviders();
|
|
160
|
-
const selectedProvider = getBestProvider(params.preferred);
|
|
160
|
+
const selectedProvider = await getBestProvider(params.preferred);
|
|
161
161
|
// Get provider capabilities
|
|
162
162
|
const getProviderCapabilities = (provider) => ({
|
|
163
163
|
multimodal: provider === "openai" ||
|
|
@@ -30,13 +30,13 @@ export declare const workflowToolSchemas: {
|
|
|
30
30
|
includeAsyncTests: z.ZodDefault<z.ZodBoolean>;
|
|
31
31
|
}, "strip", z.ZodTypeAny, {
|
|
32
32
|
codeFunction: string;
|
|
33
|
-
testTypes: ("integration" | "
|
|
33
|
+
testTypes: ("integration" | "performance" | "unit" | "edge-cases" | "security")[];
|
|
34
34
|
framework: "jest" | "mocha" | "vitest" | "pytest" | "unittest" | "rspec";
|
|
35
35
|
coverageTarget: number;
|
|
36
36
|
includeAsyncTests: boolean;
|
|
37
37
|
}, {
|
|
38
38
|
codeFunction: string;
|
|
39
|
-
testTypes?: ("integration" | "
|
|
39
|
+
testTypes?: ("integration" | "performance" | "unit" | "edge-cases" | "security")[] | undefined;
|
|
40
40
|
framework?: "jest" | "mocha" | "vitest" | "pytest" | "unittest" | "rspec" | undefined;
|
|
41
41
|
coverageTarget?: number | undefined;
|
|
42
42
|
includeAsyncTests?: boolean | undefined;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { AIProviderFactory } from "../../../core/factory.js";
|
|
7
|
-
import {
|
|
7
|
+
import { getBestProvider } from "../../../utils/providerUtils.js";
|
|
8
8
|
import { DEFAULT_MAX_TOKENS } from "../../../core/constants.js";
|
|
9
9
|
// Tool-specific schemas with comprehensive validation
|
|
10
10
|
const generateTestCasesSchema = z.object({
|
|
@@ -94,7 +94,7 @@ export class SessionManager {
|
|
|
94
94
|
* @returns Session if found and not expired
|
|
95
95
|
*/
|
|
96
96
|
getSession(sessionId, extend = true) {
|
|
97
|
-
|
|
97
|
+
const session = this.sessions.get(sessionId) || null;
|
|
98
98
|
// For sync compatibility, skip disk loading in getSession
|
|
99
99
|
// Use async getSessionAsync() for full persistence features
|
|
100
100
|
if (!session) {
|
|
@@ -20,23 +20,37 @@ export interface ToolExecutionOptions {
|
|
|
20
20
|
}
|
|
21
21
|
export declare class MCPToolRegistry extends MCPRegistry {
|
|
22
22
|
private tools;
|
|
23
|
+
private toolImpls;
|
|
23
24
|
private toolExecutionStats;
|
|
24
25
|
/**
|
|
25
26
|
* Register a server with its tools (updated signature)
|
|
26
27
|
*/
|
|
27
|
-
registerServer(
|
|
28
|
+
registerServer(serverOrId: string | any, serverConfig?: unknown, context?: ExecutionContext): Promise<void>;
|
|
28
29
|
/**
|
|
29
30
|
* Execute a tool with enhanced context
|
|
30
31
|
*/
|
|
31
32
|
executeTool<T = unknown>(toolName: string, args?: unknown, context?: ExecutionContext): Promise<T>;
|
|
32
33
|
/**
|
|
33
|
-
* List all available tools (updated signature)
|
|
34
|
+
* List all available tools (updated signature with filtering)
|
|
34
35
|
*/
|
|
35
|
-
listTools(
|
|
36
|
+
listTools(): Promise<ToolInfo[]>;
|
|
37
|
+
listTools(context: ExecutionContext): Promise<ToolInfo[]>;
|
|
38
|
+
listTools(filter: {
|
|
39
|
+
category?: string;
|
|
40
|
+
serverId?: string;
|
|
41
|
+
serverCategory?: string;
|
|
42
|
+
permissions?: string[];
|
|
43
|
+
context?: ExecutionContext;
|
|
44
|
+
}): Promise<ToolInfo[]>;
|
|
36
45
|
/**
|
|
37
|
-
* Get tool information
|
|
46
|
+
* Get tool information with server details
|
|
38
47
|
*/
|
|
39
|
-
getToolInfo(toolName: string):
|
|
48
|
+
getToolInfo(toolName: string): {
|
|
49
|
+
tool: ToolInfo;
|
|
50
|
+
server: {
|
|
51
|
+
id: string;
|
|
52
|
+
};
|
|
53
|
+
} | undefined;
|
|
40
54
|
/**
|
|
41
55
|
* Update execution statistics
|
|
42
56
|
*/
|
|
@@ -70,13 +84,19 @@ export declare class MCPToolRegistry extends MCPRegistry {
|
|
|
70
84
|
*/
|
|
71
85
|
getToolCount(): number;
|
|
72
86
|
/**
|
|
73
|
-
* Get statistics
|
|
87
|
+
* Get comprehensive statistics
|
|
74
88
|
*/
|
|
75
|
-
getStats():
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
getStats(): {
|
|
90
|
+
totalServers: number;
|
|
91
|
+
totalTools: number;
|
|
92
|
+
serversByCategory: Record<string, number>;
|
|
93
|
+
toolsByCategory: Record<string, number>;
|
|
94
|
+
executionStats: Record<string, {
|
|
95
|
+
count: number;
|
|
96
|
+
averageTime: number;
|
|
97
|
+
totalTime: number;
|
|
98
|
+
}>;
|
|
99
|
+
};
|
|
80
100
|
/**
|
|
81
101
|
* Unregister a server
|
|
82
102
|
*/
|