@juspay/neurolink 7.29.1 → 7.29.3
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 +12 -0
- package/dist/cli/commands/config.d.ts +86 -86
- package/dist/cli/commands/mcp.js +64 -9
- package/dist/cli/commands/models.js +25 -21
- package/dist/cli/commands/ollama.js +2 -2
- package/dist/cli/factories/commandFactory.d.ts +9 -0
- package/dist/cli/factories/commandFactory.js +177 -83
- package/dist/cli/factories/ollamaCommandFactory.js +3 -1
- package/dist/cli/factories/sagemakerCommandFactory.js +3 -2
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +19 -11
- package/dist/cli/utils/envManager.js +5 -5
- package/dist/cli/utils/ollamaUtils.d.ts +12 -0
- package/dist/cli/utils/ollamaUtils.js +58 -42
- package/dist/config/configManager.js +5 -2
- package/dist/core/analytics.d.ts +2 -24
- package/dist/core/analytics.js +12 -17
- package/dist/core/baseProvider.d.ts +30 -1
- package/dist/core/baseProvider.js +180 -198
- package/dist/core/dynamicModels.d.ts +4 -4
- package/dist/core/dynamicModels.js +7 -7
- package/dist/core/evaluation.d.ts +9 -9
- package/dist/core/evaluation.js +117 -65
- package/dist/core/evaluationProviders.d.ts +18 -2
- package/dist/core/evaluationProviders.js +15 -13
- package/dist/core/factory.js +77 -4
- package/dist/core/modelConfiguration.d.ts +63 -0
- package/dist/core/modelConfiguration.js +354 -290
- package/dist/core/streamAnalytics.d.ts +10 -5
- package/dist/core/streamAnalytics.js +10 -10
- package/dist/core/types.d.ts +19 -109
- package/dist/core/types.js +13 -0
- package/dist/factories/providerFactory.js +4 -1
- package/dist/factories/providerRegistry.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/lib/config/configManager.js +5 -2
- package/dist/lib/core/analytics.d.ts +2 -24
- package/dist/lib/core/analytics.js +12 -17
- package/dist/lib/core/baseProvider.d.ts +30 -1
- package/dist/lib/core/baseProvider.js +180 -198
- package/dist/lib/core/dynamicModels.js +7 -7
- package/dist/lib/core/evaluation.d.ts +9 -9
- package/dist/lib/core/evaluation.js +117 -65
- package/dist/lib/core/evaluationProviders.d.ts +18 -2
- package/dist/lib/core/evaluationProviders.js +15 -13
- package/dist/lib/core/factory.js +77 -4
- package/dist/lib/core/modelConfiguration.d.ts +63 -0
- package/dist/lib/core/modelConfiguration.js +354 -290
- package/dist/lib/core/streamAnalytics.d.ts +10 -5
- package/dist/lib/core/streamAnalytics.js +10 -10
- package/dist/lib/core/types.d.ts +19 -109
- package/dist/lib/core/types.js +13 -0
- package/dist/lib/factories/providerFactory.js +4 -1
- package/dist/lib/factories/providerRegistry.js +2 -2
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/mcp/externalServerManager.js +14 -6
- package/dist/lib/mcp/factory.js +1 -1
- package/dist/lib/mcp/flexibleToolValidator.d.ts +50 -0
- package/dist/lib/mcp/flexibleToolValidator.js +161 -0
- package/dist/lib/mcp/index.d.ts +1 -1
- package/dist/lib/mcp/index.js +1 -1
- package/dist/lib/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/lib/mcp/mcpClientFactory.js +3 -0
- package/dist/lib/mcp/registry.d.ts +3 -3
- package/dist/lib/mcp/registry.js +3 -3
- package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/lib/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/lib/mcp/toolDiscoveryService.js +8 -2
- package/dist/lib/mcp/toolRegistry.d.ts +2 -2
- package/dist/lib/mcp/toolRegistry.js +29 -54
- package/dist/lib/middleware/builtin/analytics.js +4 -4
- package/dist/lib/middleware/builtin/guardrails.js +2 -2
- package/dist/lib/middleware/registry.js +11 -2
- package/dist/lib/models/modelRegistry.d.ts +1 -1
- package/dist/lib/models/modelRegistry.js +3 -3
- package/dist/lib/models/modelResolver.d.ts +1 -1
- package/dist/lib/models/modelResolver.js +2 -2
- package/dist/lib/neurolink.d.ts +118 -0
- package/dist/lib/neurolink.js +814 -952
- package/dist/lib/providers/amazonBedrock.d.ts +47 -6
- package/dist/lib/providers/amazonBedrock.js +282 -23
- package/dist/lib/providers/amazonSagemaker.d.ts +1 -1
- package/dist/lib/providers/amazonSagemaker.js +12 -3
- package/dist/lib/providers/anthropic.d.ts +1 -1
- package/dist/lib/providers/anthropic.js +7 -6
- package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/lib/providers/anthropicBaseProvider.js +4 -3
- package/dist/lib/providers/aws/credentialProvider.d.ts +58 -0
- package/dist/lib/providers/aws/credentialProvider.js +267 -0
- package/dist/lib/providers/aws/credentialTester.d.ts +49 -0
- package/dist/lib/providers/aws/credentialTester.js +394 -0
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/azureOpenai.js +1 -1
- package/dist/lib/providers/googleAiStudio.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.js +2 -2
- package/dist/lib/providers/googleVertex.d.ts +40 -0
- package/dist/lib/providers/googleVertex.js +330 -274
- package/dist/lib/providers/huggingFace.js +1 -1
- package/dist/lib/providers/mistral.d.ts +1 -1
- package/dist/lib/providers/mistral.js +2 -2
- package/dist/lib/providers/ollama.d.ts +4 -0
- package/dist/lib/providers/ollama.js +38 -18
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +2 -2
- package/dist/lib/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/lib/providers/sagemaker/client.js +13 -3
- package/dist/lib/providers/sagemaker/config.js +5 -1
- package/dist/lib/providers/sagemaker/detection.js +19 -9
- package/dist/lib/providers/sagemaker/errors.d.ts +8 -1
- package/dist/lib/providers/sagemaker/errors.js +103 -20
- package/dist/lib/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/lib/providers/sagemaker/language-model.js +4 -4
- package/dist/lib/providers/sagemaker/parsers.js +14 -6
- package/dist/lib/providers/sagemaker/streaming.js +14 -3
- package/dist/lib/providers/sagemaker/types.d.ts +1 -1
- package/dist/lib/proxy/awsProxyIntegration.d.ts +23 -0
- package/dist/lib/proxy/awsProxyIntegration.js +285 -0
- package/dist/lib/proxy/proxyFetch.d.ts +9 -5
- package/dist/lib/proxy/proxyFetch.js +232 -98
- package/dist/lib/proxy/utils/noProxyUtils.d.ts +39 -0
- package/dist/lib/proxy/utils/noProxyUtils.js +149 -0
- package/dist/lib/sdk/toolRegistration.d.ts +1 -1
- package/dist/lib/types/cli.d.ts +80 -8
- package/dist/lib/types/contextTypes.js +2 -2
- package/dist/lib/types/generateTypes.d.ts +4 -6
- package/dist/lib/types/providers.d.ts +124 -19
- package/dist/lib/types/providers.js +6 -6
- package/dist/lib/types/streamTypes.d.ts +4 -6
- package/dist/lib/types/typeAliases.d.ts +1 -1
- package/dist/lib/utils/analyticsUtils.d.ts +33 -0
- package/dist/lib/utils/analyticsUtils.js +76 -0
- package/dist/lib/utils/errorHandling.js +4 -1
- package/dist/lib/utils/evaluationUtils.d.ts +27 -0
- package/dist/lib/utils/evaluationUtils.js +131 -0
- package/dist/lib/utils/optionsUtils.js +10 -1
- package/dist/lib/utils/performance.d.ts +1 -1
- package/dist/lib/utils/performance.js +15 -3
- package/dist/lib/utils/providerConfig.d.ts +1 -0
- package/dist/lib/utils/providerConfig.js +2 -1
- package/dist/lib/utils/providerHealth.d.ts +48 -0
- package/dist/lib/utils/providerHealth.js +221 -158
- package/dist/lib/utils/providerUtils.js +2 -2
- package/dist/lib/utils/timeout.js +8 -3
- package/dist/mcp/externalServerManager.js +14 -6
- package/dist/mcp/factory.js +1 -1
- package/dist/mcp/flexibleToolValidator.d.ts +50 -0
- package/dist/mcp/flexibleToolValidator.js +161 -0
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/mcpCircuitBreaker.js +5 -1
- package/dist/mcp/mcpClientFactory.js +3 -0
- package/dist/mcp/registry.d.ts +3 -3
- package/dist/mcp/registry.js +3 -3
- package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -5
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +6 -6
- package/dist/mcp/servers/utilities/utilityServer.js +1 -1
- package/dist/mcp/toolDiscoveryService.js +8 -2
- package/dist/mcp/toolRegistry.d.ts +2 -2
- package/dist/mcp/toolRegistry.js +29 -54
- package/dist/middleware/builtin/analytics.js +4 -4
- package/dist/middleware/builtin/guardrails.js +2 -2
- package/dist/middleware/registry.js +11 -2
- package/dist/models/modelRegistry.d.ts +1 -1
- package/dist/models/modelRegistry.js +3 -3
- package/dist/models/modelResolver.d.ts +1 -1
- package/dist/models/modelResolver.js +2 -2
- package/dist/neurolink.d.ts +118 -0
- package/dist/neurolink.js +814 -952
- package/dist/providers/amazonBedrock.d.ts +47 -6
- package/dist/providers/amazonBedrock.js +282 -23
- package/dist/providers/amazonSagemaker.d.ts +1 -1
- package/dist/providers/amazonSagemaker.js +12 -3
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +7 -6
- package/dist/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/providers/anthropicBaseProvider.js +4 -3
- package/dist/providers/aws/credentialProvider.d.ts +58 -0
- package/dist/providers/aws/credentialProvider.js +267 -0
- package/dist/providers/aws/credentialTester.d.ts +49 -0
- package/dist/providers/aws/credentialTester.js +394 -0
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/azureOpenai.js +1 -1
- package/dist/providers/googleAiStudio.d.ts +1 -1
- package/dist/providers/googleAiStudio.js +2 -2
- package/dist/providers/googleVertex.d.ts +40 -0
- package/dist/providers/googleVertex.js +330 -274
- package/dist/providers/huggingFace.js +1 -1
- package/dist/providers/mistral.d.ts +1 -1
- package/dist/providers/mistral.js +2 -2
- package/dist/providers/ollama.d.ts +4 -0
- package/dist/providers/ollama.js +38 -18
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +2 -2
- package/dist/providers/sagemaker/adaptive-semaphore.js +7 -4
- package/dist/providers/sagemaker/client.js +13 -3
- package/dist/providers/sagemaker/config.js +5 -1
- package/dist/providers/sagemaker/detection.js +19 -9
- package/dist/providers/sagemaker/errors.d.ts +8 -1
- package/dist/providers/sagemaker/errors.js +103 -20
- package/dist/providers/sagemaker/language-model.d.ts +3 -3
- package/dist/providers/sagemaker/language-model.js +4 -4
- package/dist/providers/sagemaker/parsers.js +14 -6
- package/dist/providers/sagemaker/streaming.js +14 -3
- package/dist/providers/sagemaker/types.d.ts +1 -1
- package/dist/proxy/awsProxyIntegration.d.ts +23 -0
- package/dist/proxy/awsProxyIntegration.js +285 -0
- package/dist/proxy/proxyFetch.d.ts +9 -5
- package/dist/proxy/proxyFetch.js +232 -98
- package/dist/proxy/utils/noProxyUtils.d.ts +39 -0
- package/dist/proxy/utils/noProxyUtils.js +149 -0
- package/dist/sdk/toolRegistration.d.ts +1 -1
- package/dist/types/cli.d.ts +80 -8
- package/dist/types/contextTypes.js +2 -2
- package/dist/types/generateTypes.d.ts +4 -6
- package/dist/types/providers.d.ts +124 -19
- package/dist/types/providers.js +6 -6
- package/dist/types/streamTypes.d.ts +4 -6
- package/dist/types/typeAliases.d.ts +1 -1
- package/dist/utils/analyticsUtils.d.ts +33 -0
- package/dist/utils/analyticsUtils.js +76 -0
- package/dist/utils/errorHandling.js +4 -1
- package/dist/utils/evaluationUtils.d.ts +27 -0
- package/dist/utils/evaluationUtils.js +131 -0
- package/dist/utils/optionsUtils.js +10 -1
- package/dist/utils/performance.d.ts +1 -1
- package/dist/utils/performance.js +15 -3
- package/dist/utils/providerConfig.d.ts +1 -0
- package/dist/utils/providerConfig.js +2 -1
- package/dist/utils/providerHealth.d.ts +48 -0
- package/dist/utils/providerHealth.js +221 -158
- package/dist/utils/providerUtils.js +2 -2
- package/dist/utils/timeout.js +8 -3
- package/package.json +5 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import { MiddlewareFactory } from "../middleware/factory.js";
|
|
3
2
|
import { logger } from "../utils/logger.js";
|
|
4
3
|
import { DEFAULT_MAX_STEPS, STEP_LIMITS } from "../core/constants.js";
|
|
@@ -320,9 +319,9 @@ export class BaseProvider {
|
|
|
320
319
|
const enhancedResult = {
|
|
321
320
|
content: result.text,
|
|
322
321
|
usage: {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
322
|
+
input: result.usage?.promptTokens || 0,
|
|
323
|
+
output: result.usage?.completionTokens || 0,
|
|
324
|
+
total: result.usage?.totalTokens || 0,
|
|
326
325
|
},
|
|
327
326
|
provider: this.providerName,
|
|
328
327
|
model: this.modelName,
|
|
@@ -389,9 +388,9 @@ export class BaseProvider {
|
|
|
389
388
|
provider: result.provider || this.providerName,
|
|
390
389
|
model: result.model || this.modelName,
|
|
391
390
|
usage: result.usage || {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
391
|
+
input: 0,
|
|
392
|
+
output: 0,
|
|
393
|
+
total: 0,
|
|
395
394
|
},
|
|
396
395
|
responseTime: 0, // BaseProvider doesn't track response time directly
|
|
397
396
|
toolsUsed: result.toolsUsed || [],
|
|
@@ -483,211 +482,152 @@ export class BaseProvider {
|
|
|
483
482
|
// TOOL MANAGEMENT
|
|
484
483
|
// ===================
|
|
485
484
|
/**
|
|
486
|
-
*
|
|
487
|
-
* MCP tools are added when available (without blocking)
|
|
485
|
+
* Check if a schema is a Zod schema
|
|
488
486
|
*/
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
//
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
"execute" in toolDef &&
|
|
511
|
-
typeof toolDef.execute === "function") {
|
|
512
|
-
try {
|
|
513
|
-
const { tool: createAISDKTool } = await import("ai");
|
|
514
|
-
const typedToolDef = toolDef;
|
|
515
|
-
tools[toolName] = createAISDKTool({
|
|
516
|
-
description: typedToolDef.description || `Custom tool ${toolName}`,
|
|
517
|
-
parameters: z.object({}), // Use empty schema for custom tools
|
|
518
|
-
execute: async (params) => {
|
|
519
|
-
logger.debug(`[BaseProvider] Executing custom tool: ${toolName}`, { params });
|
|
520
|
-
try {
|
|
521
|
-
// Use the tool executor if available (from setupToolExecutor)
|
|
522
|
-
let result;
|
|
523
|
-
if (this.toolExecutor) {
|
|
524
|
-
result = await this.toolExecutor(toolName, params);
|
|
525
|
-
}
|
|
526
|
-
else {
|
|
527
|
-
result = await typedToolDef.execute(params);
|
|
528
|
-
}
|
|
529
|
-
// Log successful execution
|
|
530
|
-
logger.debug(`[BaseProvider] Tool execution successful: ${toolName}`, {
|
|
531
|
-
resultType: typeof result,
|
|
532
|
-
hasResult: result !== null && result !== undefined,
|
|
533
|
-
toolName,
|
|
534
|
-
});
|
|
535
|
-
return result;
|
|
536
|
-
}
|
|
537
|
-
catch (error) {
|
|
538
|
-
logger.warn(`[BaseProvider] Tool execution failed: ${toolName}`, {
|
|
539
|
-
error: error instanceof Error ? error.message : String(error),
|
|
540
|
-
params,
|
|
541
|
-
toolName,
|
|
542
|
-
});
|
|
543
|
-
// GENERIC ERROR HANDLING FOR ALL MCP TOOLS:
|
|
544
|
-
// Return a generic error object that works with any MCP server
|
|
545
|
-
// The AI can interpret this and try different approaches
|
|
546
|
-
return {
|
|
547
|
-
_neurolinkToolError: true,
|
|
548
|
-
toolName: toolName,
|
|
549
|
-
error: error instanceof Error ? error.message : String(error),
|
|
550
|
-
timestamp: new Date().toISOString(),
|
|
551
|
-
params: params,
|
|
552
|
-
// Keep it simple - just indicate an error occurred
|
|
553
|
-
message: `Error calling ${toolName}: ${error instanceof Error ? error.message : String(error)}`,
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
},
|
|
557
|
-
});
|
|
558
|
-
logger.debug(`[BaseProvider] Successfully added custom tool: ${toolName}`);
|
|
559
|
-
}
|
|
560
|
-
catch (error) {
|
|
561
|
-
logger.error(`[BaseProvider] Failed to add custom tool: ${toolName}`, error);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
else {
|
|
565
|
-
logger.warn(`[BaseProvider] Invalid custom tool format: ${toolName}`, {
|
|
566
|
-
toolDef: typeof toolDef,
|
|
567
|
-
hasExecute: toolDef && typeof toolDef === "object" && "execute" in toolDef,
|
|
568
|
-
executeType: toolDef && typeof toolDef === "object" && "execute" in toolDef
|
|
569
|
-
? typeof toolDef.execute
|
|
570
|
-
: "N/A",
|
|
571
|
-
});
|
|
572
|
-
}
|
|
487
|
+
isZodSchema(schema) {
|
|
488
|
+
return (typeof schema === "object" &&
|
|
489
|
+
schema !== null &&
|
|
490
|
+
// Most Zod schemas have an internal _def and a parse method
|
|
491
|
+
typeof schema.parse === "function");
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Convert tool execution result from MCP format to standard format
|
|
495
|
+
*/
|
|
496
|
+
async convertToolResult(result) {
|
|
497
|
+
// Handle MCP-style results
|
|
498
|
+
if (result && typeof result === "object" && "success" in result) {
|
|
499
|
+
const mcpResult = result;
|
|
500
|
+
if (mcpResult.success) {
|
|
501
|
+
return mcpResult.data;
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
const errorMsg = typeof mcpResult.error === "string"
|
|
505
|
+
? mcpResult.error
|
|
506
|
+
: "Tool execution failed";
|
|
507
|
+
throw new Error(errorMsg);
|
|
573
508
|
}
|
|
574
509
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
return result;
|
|
626
|
-
},
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
catch (toolCreationError) {
|
|
630
|
-
logger.error(`Failed to create tool: ${toolName}`, toolCreationError);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
510
|
+
return result;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Create a custom tool from tool definition
|
|
514
|
+
*/
|
|
515
|
+
async createCustomToolFromDefinition(toolName, toolInfo) {
|
|
516
|
+
try {
|
|
517
|
+
logger.debug(`[BaseProvider] Converting custom tool: ${toolName}`);
|
|
518
|
+
// Convert to AI SDK tool format
|
|
519
|
+
const { tool: createAISDKTool } = await import("ai");
|
|
520
|
+
const { z } = await import("zod");
|
|
521
|
+
return createAISDKTool({
|
|
522
|
+
description: toolInfo.description || `Tool ${toolName}`,
|
|
523
|
+
parameters: this.isZodSchema(toolInfo.parameters)
|
|
524
|
+
? toolInfo.parameters
|
|
525
|
+
: z.object({}),
|
|
526
|
+
execute: async (params) => {
|
|
527
|
+
const result = await toolInfo.execute(params);
|
|
528
|
+
return await this.convertToolResult(result);
|
|
529
|
+
},
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
catch (toolCreationError) {
|
|
533
|
+
logger.error(`Failed to create tool: ${toolName}`, toolCreationError);
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Process custom tools from setupToolExecutor
|
|
539
|
+
*/
|
|
540
|
+
async processCustomTools(tools) {
|
|
541
|
+
if (!this.customTools || this.customTools.size === 0) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
logger.debug(`[BaseProvider] Loading ${this.customTools.size} custom tools from setupToolExecutor`);
|
|
545
|
+
for (const [toolName, toolDef] of this.customTools.entries()) {
|
|
546
|
+
logger.debug(`[BaseProvider] Processing custom tool: ${toolName}`, {
|
|
547
|
+
toolDef: typeof toolDef,
|
|
548
|
+
hasExecute: toolDef && typeof toolDef === "object" && "execute" in toolDef,
|
|
549
|
+
hasName: toolDef && typeof toolDef === "object" && "name" in toolDef,
|
|
550
|
+
});
|
|
551
|
+
// Validate tool definition has required execute function
|
|
552
|
+
const toolInfo = toolDef ||
|
|
553
|
+
{};
|
|
554
|
+
if (toolInfo && typeof toolInfo.execute === "function") {
|
|
555
|
+
const tool = await this.createCustomToolFromDefinition(toolName, toolInfo);
|
|
556
|
+
if (tool) {
|
|
557
|
+
tools[toolName] = tool;
|
|
636
558
|
}
|
|
637
559
|
}
|
|
638
|
-
catch (error) {
|
|
639
|
-
logger.debug(`Failed to load custom tools for ${this.providerName}:`, error);
|
|
640
|
-
// Not an error - custom tools are optional
|
|
641
|
-
}
|
|
642
560
|
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
else {
|
|
665
|
-
throw new Error(`Cannot execute external MCP tool: NeuroLink executeExternalMCPTool not available`);
|
|
666
|
-
}
|
|
667
|
-
},
|
|
668
|
-
});
|
|
669
|
-
logger.debug(`[BaseProvider] Successfully added external MCP tool: ${tool.name}`);
|
|
561
|
+
logger.debug(`[BaseProvider] Custom tools processing complete`, {
|
|
562
|
+
customToolsProcessed: this.customTools.size,
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Create an external MCP tool
|
|
567
|
+
*/
|
|
568
|
+
async createExternalMCPTool(tool) {
|
|
569
|
+
try {
|
|
570
|
+
logger.debug(`[BaseProvider] Converting external MCP tool: ${tool.name}`);
|
|
571
|
+
// Convert to AI SDK tool format
|
|
572
|
+
const { tool: createAISDKTool } = await import("ai");
|
|
573
|
+
return createAISDKTool({
|
|
574
|
+
description: tool.description || `External MCP tool ${tool.name}`,
|
|
575
|
+
parameters: await this.convertMCPSchemaToZod(tool.inputSchema),
|
|
576
|
+
execute: async (params) => {
|
|
577
|
+
logger.debug(`[BaseProvider] Executing external MCP tool: ${tool.name}`, { params });
|
|
578
|
+
// Execute via NeuroLink's direct tool execution
|
|
579
|
+
if (this.neurolink &&
|
|
580
|
+
typeof this.neurolink.executeExternalMCPTool === "function") {
|
|
581
|
+
return await this.neurolink.executeExternalMCPTool(tool.serverId || "unknown", tool.name, params);
|
|
670
582
|
}
|
|
671
|
-
|
|
672
|
-
|
|
583
|
+
else {
|
|
584
|
+
throw new Error(`Cannot execute external MCP tool: NeuroLink executeExternalMCPTool not available`);
|
|
673
585
|
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
totalToolsAdded: externalTools.length,
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
catch (error) {
|
|
680
|
-
logger.error(`[BaseProvider] Failed to load external MCP tools for ${this.providerName}:`, error);
|
|
681
|
-
// Not an error - external tools are optional
|
|
682
|
-
}
|
|
586
|
+
},
|
|
587
|
+
});
|
|
683
588
|
}
|
|
684
|
-
|
|
589
|
+
catch (toolCreationError) {
|
|
590
|
+
logger.error(`Failed to create external MCP tool: ${tool.name}`, toolCreationError);
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Process external MCP tools
|
|
596
|
+
*/
|
|
597
|
+
async processExternalMCPTools(tools) {
|
|
598
|
+
if (!this.neurolink ||
|
|
599
|
+
typeof this.neurolink.getExternalMCPTools !== "function") {
|
|
685
600
|
logger.debug(`[BaseProvider] No external MCP tool interface available`, {
|
|
686
601
|
hasNeuroLink: !!this.neurolink,
|
|
687
602
|
hasGetExternalMCPTools: this.neurolink &&
|
|
688
603
|
typeof this.neurolink.getExternalMCPTools === "function",
|
|
689
604
|
});
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
try {
|
|
608
|
+
logger.debug(`[BaseProvider] Loading external MCP tools for ${this.providerName}`);
|
|
609
|
+
const externalTools = await this.neurolink.getExternalMCPTools();
|
|
610
|
+
logger.debug(`[BaseProvider] Found ${externalTools.length} external MCP tools`);
|
|
611
|
+
for (const tool of externalTools) {
|
|
612
|
+
const mcpTool = await this.createExternalMCPTool(tool);
|
|
613
|
+
if (mcpTool) {
|
|
614
|
+
tools[tool.name] = mcpTool;
|
|
615
|
+
logger.debug(`[BaseProvider] Successfully added external MCP tool: ${tool.name}`);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
logger.debug(`[BaseProvider] External MCP tools loading complete`, {
|
|
619
|
+
totalToolsAdded: externalTools.length,
|
|
620
|
+
});
|
|
690
621
|
}
|
|
622
|
+
catch (error) {
|
|
623
|
+
logger.error(`[BaseProvider] Failed to load external MCP tools for ${this.providerName}:`, error);
|
|
624
|
+
// Not an error - external tools are optional
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Process MCP tools integration
|
|
629
|
+
*/
|
|
630
|
+
async processMCPTools(tools) {
|
|
691
631
|
// MCP tools loading simplified - removed functionCalling dependency
|
|
692
632
|
if (!this.mcpTools) {
|
|
693
633
|
// Set empty tools object - MCP tools are handled at a higher level
|
|
@@ -697,6 +637,25 @@ export class BaseProvider {
|
|
|
697
637
|
if (this.mcpTools) {
|
|
698
638
|
Object.assign(tools, this.mcpTools);
|
|
699
639
|
}
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Get all available tools - direct tools are ALWAYS available
|
|
643
|
+
* MCP tools are added when available (without blocking)
|
|
644
|
+
*/
|
|
645
|
+
async getAllTools() {
|
|
646
|
+
const tools = {
|
|
647
|
+
...this.directTools, // Always include direct tools
|
|
648
|
+
};
|
|
649
|
+
logger.debug(`[BaseProvider] getAllTools called for ${this.providerName}`, {
|
|
650
|
+
neurolinkAvailable: !!this.neurolink,
|
|
651
|
+
neurolinkType: typeof this.neurolink,
|
|
652
|
+
directToolsCount: getKeyCount(this.directTools),
|
|
653
|
+
});
|
|
654
|
+
logger.debug(`[BaseProvider] Direct tools: ${getKeysAsString(this.directTools)}`);
|
|
655
|
+
// Process all tool types using dedicated helper methods
|
|
656
|
+
await this.processCustomTools(tools);
|
|
657
|
+
await this.processExternalMCPTools(tools);
|
|
658
|
+
await this.processMCPTools(tools);
|
|
700
659
|
logger.debug(`[BaseProvider] getAllTools returning tools: ${getKeysAsString(tools)}`);
|
|
701
660
|
return tools;
|
|
702
661
|
}
|
|
@@ -992,7 +951,30 @@ export class BaseProvider {
|
|
|
992
951
|
}
|
|
993
952
|
async createEvaluation(result, options) {
|
|
994
953
|
const { evaluateResponse } = await import("../core/evaluation.js");
|
|
995
|
-
const
|
|
954
|
+
const context = {
|
|
955
|
+
userQuery: options.prompt || options.input?.text || "Generated response",
|
|
956
|
+
aiResponse: result.content,
|
|
957
|
+
context: options.context,
|
|
958
|
+
primaryDomain: options.evaluationDomain,
|
|
959
|
+
assistantRole: "AI assistant",
|
|
960
|
+
conversationHistory: options.conversationHistory?.map((msg) => ({
|
|
961
|
+
role: msg.role,
|
|
962
|
+
content: msg.content,
|
|
963
|
+
})),
|
|
964
|
+
toolUsage: options.toolUsageContext
|
|
965
|
+
? [
|
|
966
|
+
{
|
|
967
|
+
toolName: options.toolUsageContext,
|
|
968
|
+
input: {},
|
|
969
|
+
output: {},
|
|
970
|
+
executionTime: 0,
|
|
971
|
+
},
|
|
972
|
+
]
|
|
973
|
+
: undefined,
|
|
974
|
+
expectedOutcome: options.expectedOutcome,
|
|
975
|
+
evaluationCriteria: options.evaluationCriteria,
|
|
976
|
+
};
|
|
977
|
+
const evaluation = await evaluateResponse(context);
|
|
996
978
|
return evaluation;
|
|
997
979
|
}
|
|
998
980
|
validateOptions(options) {
|
|
@@ -100,12 +100,6 @@ export class DynamicModelProvider {
|
|
|
100
100
|
// Setup timeout and abort controller
|
|
101
101
|
const controller = new AbortController();
|
|
102
102
|
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
103
|
-
// Load from URL
|
|
104
|
-
const response = await fetch(source, {
|
|
105
|
-
headers: {
|
|
106
|
-
"User-Agent": "NeuroLink/1.0 (+https://github.com/juspay/neurolink)",
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
103
|
try {
|
|
110
104
|
// Add health check for localhost before attempting full request
|
|
111
105
|
if (source.includes("localhost") || source.includes("127.0.0.1")) {
|
|
@@ -113,7 +107,7 @@ export class DynamicModelProvider {
|
|
|
113
107
|
}
|
|
114
108
|
const response = await fetch(source, {
|
|
115
109
|
headers: {
|
|
116
|
-
"User-Agent": "NeuroLink/1.0 (+https://github.com/
|
|
110
|
+
"User-Agent": "NeuroLink/1.0 (+https://github.com/juspay/neurolink)",
|
|
117
111
|
Accept: "application/json",
|
|
118
112
|
"Cache-Control": "no-cache",
|
|
119
113
|
},
|
|
@@ -242,6 +236,9 @@ export class DynamicModelProvider {
|
|
|
242
236
|
searchByCapability(capability, options = {}) {
|
|
243
237
|
this.ensureInitialized();
|
|
244
238
|
const results = [];
|
|
239
|
+
if (!this.modelRegistry) {
|
|
240
|
+
return results;
|
|
241
|
+
}
|
|
245
242
|
for (const [providerName, models] of Object.entries(this.modelRegistry.models)) {
|
|
246
243
|
if (options.provider && providerName !== options.provider) {
|
|
247
244
|
continue;
|
|
@@ -301,6 +298,9 @@ export class DynamicModelProvider {
|
|
|
301
298
|
getAllModels() {
|
|
302
299
|
this.ensureInitialized();
|
|
303
300
|
const results = [];
|
|
301
|
+
if (!this.modelRegistry) {
|
|
302
|
+
return results;
|
|
303
|
+
}
|
|
304
304
|
for (const [providerName, models] of Object.entries(this.modelRegistry.models)) {
|
|
305
305
|
for (const [modelName, modelConfig] of Object.entries(models)) {
|
|
306
306
|
results.push({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* NeuroLink
|
|
2
|
+
* NeuroLink Evaluation System
|
|
3
3
|
*/
|
|
4
|
-
import type { EvaluationData } from "
|
|
5
|
-
export interface
|
|
4
|
+
import type { EvaluationData } from "../index.js";
|
|
5
|
+
export interface EvaluationResult extends EvaluationData {
|
|
6
6
|
domainAlignment?: number;
|
|
7
7
|
terminologyAccuracy?: number;
|
|
8
8
|
toolEffectiveness?: number;
|
|
@@ -20,7 +20,7 @@ export interface UnifiedEvaluationResult extends EvaluationData {
|
|
|
20
20
|
alertSeverity: "low" | "medium" | "high" | "none";
|
|
21
21
|
reasoning: string;
|
|
22
22
|
}
|
|
23
|
-
export interface
|
|
23
|
+
export interface EvaluationContext {
|
|
24
24
|
userQuery: string;
|
|
25
25
|
aiResponse: string;
|
|
26
26
|
context?: Record<string, unknown>;
|
|
@@ -43,14 +43,14 @@ export interface UnifiedEvaluationContext {
|
|
|
43
43
|
/**
|
|
44
44
|
* Get default evaluation when evaluation fails
|
|
45
45
|
*/
|
|
46
|
-
declare function
|
|
46
|
+
declare function getDefaultEvaluation(reason: string, evaluationTime: number, context: EvaluationContext): EvaluationResult;
|
|
47
47
|
/**
|
|
48
48
|
* Parse unified evaluation result from text response
|
|
49
49
|
*/
|
|
50
|
-
declare function
|
|
50
|
+
declare function parseEvaluationResult(response: string, context: EvaluationContext): Partial<EvaluationResult>;
|
|
51
51
|
/**
|
|
52
52
|
* Main unified evaluation function
|
|
53
53
|
*/
|
|
54
|
-
export declare function
|
|
55
|
-
export declare function evaluateResponse(
|
|
56
|
-
export {
|
|
54
|
+
export declare function generateEvaluation(context: EvaluationContext): Promise<EvaluationResult>;
|
|
55
|
+
export declare function evaluateResponse(context: EvaluationContext): Promise<EvaluationResult>;
|
|
56
|
+
export { getDefaultEvaluation, parseEvaluationResult };
|