@juspay/neurolink 9.54.5 → 9.54.7
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 +4 -0
- package/dist/action/actionInputs.d.ts +1 -1
- package/dist/adapters/video/directorPipeline.js +6 -0
- package/dist/adapters/video/vertexVideoHandler.js +6 -0
- package/dist/agent/directTools.d.ts +3 -23
- package/dist/auth/AuthProviderFactory.d.ts +1 -3
- package/dist/auth/anthropicOAuth.d.ts +4 -7
- package/dist/auth/anthropicOAuth.js +23 -0
- package/dist/auth/errors.d.ts +1 -1
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +14 -0
- package/dist/auth/middleware/AuthMiddleware.d.ts +5 -60
- package/dist/auth/middleware/AuthMiddleware.js +3 -0
- package/dist/auth/middleware/rateLimitByUser.d.ts +4 -93
- package/dist/auth/middleware/rateLimitByUser.js +4 -0
- package/dist/auth/providers/BaseAuthProvider.d.ts +1 -1
- package/dist/auth/providers/CognitoProvider.js +3 -0
- package/dist/auth/providers/KeycloakProvider.js +3 -0
- package/dist/auth/providers/auth0.d.ts +1 -1
- package/dist/auth/sessionManager.d.ts +2 -0
- package/dist/auth/sessionManager.js +53 -11
- package/dist/auth/tokenStore.d.ts +2 -1
- package/dist/auth/tokenStore.js +45 -4
- package/dist/autoresearch/tools.d.ts +1 -16
- package/dist/browser/neurolink.min.js +353 -353
- package/dist/cli/commands/config.d.ts +3 -123
- package/dist/cli/commands/config.js +4 -2
- package/dist/cli/commands/evaluate.d.ts +1 -19
- package/dist/cli/commands/proxy.d.ts +1 -1
- package/dist/cli/commands/proxy.js +3 -0
- package/dist/cli/commands/rag.js +3 -0
- package/dist/cli/commands/setup-anthropic.d.ts +2 -6
- package/dist/cli/commands/setup-anthropic.js +1 -1
- package/dist/cli/commands/setup-azure.d.ts +2 -6
- package/dist/cli/commands/setup-azure.js +1 -1
- package/dist/cli/commands/setup-bedrock.d.ts +2 -6
- package/dist/cli/commands/setup-bedrock.js +1 -1
- package/dist/cli/commands/setup-gcp.d.ts +2 -6
- package/dist/cli/commands/setup-google-ai.d.ts +2 -6
- package/dist/cli/commands/setup-google-ai.js +1 -1
- package/dist/cli/commands/setup-huggingface.d.ts +1 -5
- package/dist/cli/commands/setup-mistral.d.ts +1 -5
- package/dist/cli/commands/setup-openai.d.ts +2 -6
- package/dist/cli/commands/setup-openai.js +1 -1
- package/dist/cli/commands/setup.d.ts +1 -8
- package/dist/cli/commands/task.js +1 -0
- package/dist/cli/commands/voiceServer.d.ts +1 -4
- package/dist/cli/loop/session.js +31 -10
- package/dist/cli/utils/interactiveSetup.d.ts +2 -15
- package/dist/cli/utils/videoFileUtils.d.ts +1 -15
- package/dist/client/aiSdkAdapter.d.ts +1 -1
- package/dist/client/aiSdkAdapter.js +1 -0
- package/dist/client/httpClient.d.ts +2 -2
- package/dist/client/httpClient.js +13 -0
- package/dist/client/sseClient.d.ts +2 -2
- package/dist/client/sseClient.js +29 -0
- package/dist/client/streamingClient.d.ts +2 -0
- package/dist/client/streamingClient.js +19 -0
- package/dist/client/wsClient.d.ts +7 -2
- package/dist/client/wsClient.js +90 -10
- package/dist/context/budgetChecker.js +3 -1
- package/dist/context/contextCompactor.js +163 -143
- package/dist/context/fileSummarizationService.d.ts +1 -9
- package/dist/context/summarizationEngine.js +29 -16
- package/dist/core/baseProvider.js +124 -153
- package/dist/core/infrastructure/baseRegistry.d.ts +1 -7
- package/dist/core/modules/GenerationHandler.d.ts +3 -2
- package/dist/core/modules/GenerationHandler.js +9 -1
- package/dist/core/modules/StreamHandler.js +9 -0
- package/dist/core/modules/ToolsManager.js +18 -2
- package/dist/core/toolEvents.d.ts +0 -1
- package/dist/evaluation/BatchEvaluator.d.ts +1 -97
- package/dist/evaluation/EvaluationAggregator.d.ts +1 -118
- package/dist/evaluation/EvaluatorFactory.d.ts +1 -13
- package/dist/evaluation/EvaluatorRegistry.d.ts +1 -50
- package/dist/evaluation/errors/EvaluationError.d.ts +2 -27
- package/dist/evaluation/hooks/langfuseAdapter.d.ts +1 -39
- package/dist/evaluation/hooks/observabilityHooks.d.ts +3 -55
- package/dist/evaluation/hooks/observabilityHooks.js +3 -0
- package/dist/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
- package/dist/evaluation/pipeline/strategies/batchStrategy.js +7 -7
- package/dist/evaluation/ragasEvaluator.js +54 -37
- package/dist/evaluation/reporting/metricsCollector.d.ts +1 -60
- package/dist/evaluation/reporting/reportGenerator.d.ts +1 -17
- package/dist/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
- package/dist/evaluation/scorers/rule/formatScorer.d.ts +1 -42
- package/dist/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
- package/dist/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
- package/dist/factories/providerFactory.d.ts +1 -16
- package/dist/factories/providerFactory.js +2 -0
- package/dist/image-gen/ImageGenService.d.ts +3 -0
- package/dist/image-gen/ImageGenService.js +3 -0
- package/dist/lib/action/actionInputs.d.ts +1 -1
- package/dist/lib/adapters/video/directorPipeline.js +6 -0
- package/dist/lib/adapters/video/vertexVideoHandler.js +6 -0
- package/dist/lib/agent/directTools.d.ts +3 -23
- package/dist/lib/auth/AuthProviderFactory.d.ts +1 -3
- package/dist/lib/auth/anthropicOAuth.d.ts +4 -7
- package/dist/lib/auth/anthropicOAuth.js +23 -0
- package/dist/lib/auth/errors.d.ts +1 -1
- package/dist/lib/auth/index.d.ts +11 -0
- package/dist/lib/auth/index.js +14 -0
- package/dist/lib/auth/middleware/AuthMiddleware.d.ts +5 -60
- package/dist/lib/auth/middleware/AuthMiddleware.js +3 -0
- package/dist/lib/auth/middleware/rateLimitByUser.d.ts +4 -93
- package/dist/lib/auth/middleware/rateLimitByUser.js +4 -0
- package/dist/lib/auth/providers/BaseAuthProvider.d.ts +1 -1
- package/dist/lib/auth/providers/CognitoProvider.js +3 -0
- package/dist/lib/auth/providers/KeycloakProvider.js +3 -0
- package/dist/lib/auth/providers/auth0.d.ts +1 -1
- package/dist/lib/auth/sessionManager.d.ts +2 -0
- package/dist/lib/auth/sessionManager.js +53 -11
- package/dist/lib/auth/tokenStore.d.ts +2 -1
- package/dist/lib/auth/tokenStore.js +45 -4
- package/dist/lib/autoresearch/tools.d.ts +1 -16
- package/dist/lib/client/aiSdkAdapter.d.ts +1 -1
- package/dist/lib/client/aiSdkAdapter.js +1 -0
- package/dist/lib/client/httpClient.d.ts +2 -2
- package/dist/lib/client/httpClient.js +13 -0
- package/dist/lib/client/sseClient.d.ts +2 -2
- package/dist/lib/client/sseClient.js +29 -0
- package/dist/lib/client/streamingClient.d.ts +2 -0
- package/dist/lib/client/streamingClient.js +19 -0
- package/dist/lib/client/wsClient.d.ts +7 -2
- package/dist/lib/client/wsClient.js +90 -10
- package/dist/lib/context/budgetChecker.js +3 -1
- package/dist/lib/context/contextCompactor.js +163 -143
- package/dist/lib/context/fileSummarizationService.d.ts +1 -9
- package/dist/lib/context/summarizationEngine.js +29 -16
- package/dist/lib/core/baseProvider.js +124 -153
- package/dist/lib/core/infrastructure/baseRegistry.d.ts +1 -7
- package/dist/lib/core/modules/GenerationHandler.d.ts +3 -2
- package/dist/lib/core/modules/GenerationHandler.js +9 -1
- package/dist/lib/core/modules/StreamHandler.js +9 -0
- package/dist/lib/core/modules/ToolsManager.js +18 -2
- package/dist/lib/core/toolEvents.d.ts +0 -1
- package/dist/lib/evaluation/BatchEvaluator.d.ts +1 -97
- package/dist/lib/evaluation/EvaluationAggregator.d.ts +1 -118
- package/dist/lib/evaluation/EvaluatorFactory.d.ts +1 -13
- package/dist/lib/evaluation/EvaluatorRegistry.d.ts +1 -50
- package/dist/lib/evaluation/errors/EvaluationError.d.ts +2 -27
- package/dist/lib/evaluation/hooks/langfuseAdapter.d.ts +1 -39
- package/dist/lib/evaluation/hooks/observabilityHooks.d.ts +3 -55
- package/dist/lib/evaluation/hooks/observabilityHooks.js +3 -0
- package/dist/lib/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
- package/dist/lib/evaluation/pipeline/strategies/batchStrategy.js +7 -7
- package/dist/lib/evaluation/ragasEvaluator.js +54 -37
- package/dist/lib/evaluation/reporting/metricsCollector.d.ts +1 -60
- package/dist/lib/evaluation/reporting/reportGenerator.d.ts +1 -17
- package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
- package/dist/lib/evaluation/scorers/rule/formatScorer.d.ts +1 -42
- package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
- package/dist/lib/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
- package/dist/lib/factories/providerFactory.d.ts +1 -16
- package/dist/lib/factories/providerFactory.js +2 -0
- package/dist/lib/image-gen/ImageGenService.d.ts +3 -0
- package/dist/lib/image-gen/ImageGenService.js +3 -0
- package/dist/lib/mcp/batching/requestBatcher.js +99 -73
- package/dist/lib/mcp/httpRateLimiter.js +3 -1
- package/dist/lib/mcp/httpRetryHandler.js +3 -1
- package/dist/lib/mcp/mcpClientFactory.js +3 -1
- package/dist/lib/mcp/multiServerManager.d.ts +1 -14
- package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
- package/dist/lib/mcp/toolDiscoveryService.js +70 -57
- package/dist/lib/mcp/toolRegistry.js +11 -1
- package/dist/lib/memory/hippocampusInitializer.d.ts +1 -2
- package/dist/lib/memory/hippocampusInitializer.js +1 -1
- package/dist/lib/memory/memoryRetrievalTools.js +182 -141
- package/dist/lib/models/anthropicModels.d.ts +0 -1
- package/dist/lib/models/anthropicModels.js +1 -0
- package/dist/lib/neurolink.js +237 -41
- package/dist/lib/observability/exporterRegistry.d.ts +3 -22
- package/dist/lib/observability/exporters/sentryExporter.js +1 -0
- package/dist/lib/observability/metricsAggregator.d.ts +1 -31
- package/dist/lib/observability/retryPolicy.d.ts +0 -1
- package/dist/lib/observability/sampling/samplers.d.ts +0 -1
- package/dist/lib/observability/spanProcessor.d.ts +0 -1
- package/dist/lib/observability/tokenTracker.d.ts +7 -16
- package/dist/lib/observability/tokenTracker.js +6 -4
- package/dist/lib/observability/utils/spanSerializer.d.ts +5 -1
- package/dist/lib/observability/utils/spanSerializer.js +24 -4
- package/dist/lib/processors/base/BaseFileProcessor.js +66 -53
- package/dist/lib/processors/document/ExcelProcessor.d.ts +1 -1
- package/dist/lib/processors/errors/errorHelpers.d.ts +1 -31
- package/dist/lib/processors/errors/errorSerializer.d.ts +1 -45
- package/dist/lib/processors/registry/ProcessorRegistry.js +17 -6
- package/dist/lib/providers/amazonBedrock.js +189 -15
- package/dist/lib/providers/amazonSagemaker.js +25 -11
- package/dist/lib/providers/anthropic.js +13 -0
- package/dist/lib/providers/azureOpenai.js +2 -0
- package/dist/lib/providers/googleAiStudio.js +82 -0
- package/dist/lib/providers/googleNativeGemini3.d.ts +1 -2
- package/dist/lib/providers/googleVertex.js +52 -0
- package/dist/lib/providers/huggingFace.js +2 -0
- package/dist/lib/providers/litellm.js +2 -0
- package/dist/lib/providers/mistral.js +2 -0
- package/dist/lib/providers/ollama.js +84 -5
- package/dist/lib/providers/openAI.d.ts +2 -0
- package/dist/lib/providers/openAI.js +17 -6
- package/dist/lib/providers/openRouter.js +2 -0
- package/dist/lib/providers/openaiCompatible.js +2 -0
- package/dist/lib/providers/sagemaker/detection.d.ts +1 -33
- package/dist/lib/providers/sagemaker/diagnostics.d.ts +1 -25
- package/dist/lib/providers/sagemaker/language-model.d.ts +1 -1
- package/dist/lib/proxy/proxyConfig.js +4 -0
- package/dist/lib/proxy/proxyEnv.d.ts +1 -17
- package/dist/lib/proxy/proxyHealth.d.ts +0 -1
- package/dist/lib/proxy/proxyTracer.d.ts +1 -36
- package/dist/lib/proxy/proxyTracer.js +9 -0
- package/dist/lib/proxy/quietDetector.d.ts +1 -7
- package/dist/lib/proxy/rawStreamCapture.d.ts +1 -10
- package/dist/lib/proxy/requestLogger.d.ts +1 -21
- package/dist/lib/proxy/routingPolicy.d.ts +1 -2
- package/dist/lib/proxy/sseInterceptor.d.ts +1 -66
- package/dist/lib/proxy/sseInterceptor.js +6 -0
- package/dist/lib/proxy/updateChecker.d.ts +1 -6
- package/dist/lib/proxy/updateState.d.ts +1 -12
- package/dist/lib/rag/chunkers/BaseChunker.js +36 -22
- package/dist/lib/rag/chunking/jsonChunker.d.ts +1 -1
- package/dist/lib/rag/errors/RAGError.d.ts +1 -2
- package/dist/lib/rag/ragIntegration.js +45 -32
- package/dist/lib/rag/reranker/reranker.js +151 -122
- package/dist/lib/rag/retrieval/vectorQueryTool.js +79 -65
- package/dist/lib/sdk/toolRegistration.d.ts +10 -44
- package/dist/lib/sdk/toolRegistration.js +1 -1
- package/dist/lib/server/middleware/abortSignal.d.ts +1 -11
- package/dist/lib/server/middleware/auth.d.ts +1 -21
- package/dist/lib/server/middleware/auth.js +12 -0
- package/dist/lib/server/middleware/common.js +48 -32
- package/dist/lib/server/middleware/deprecation.d.ts +1 -20
- package/dist/lib/server/middleware/rateLimit.d.ts +1 -75
- package/dist/lib/server/middleware/validation.d.ts +3 -81
- package/dist/lib/server/middleware/validation.js +3 -0
- package/dist/lib/server/openapi/generator.d.ts +1 -47
- package/dist/lib/server/routes/agentRoutes.js +112 -57
- package/dist/lib/server/routes/claudeProxyRoutes.d.ts +1 -6
- package/dist/lib/server/routes/claudeProxyRoutes.js +127 -13
- package/dist/lib/server/routes/healthRoutes.js +58 -12
- package/dist/lib/server/routes/index.d.ts +1 -26
- package/dist/lib/server/routes/mcpRoutes.js +40 -7
- package/dist/lib/server/routes/memoryRoutes.js +22 -7
- package/dist/lib/server/routes/openApiRoutes.js +30 -6
- package/dist/lib/server/routes/toolRoutes.js +140 -68
- package/dist/lib/server/streaming/dataStream.d.ts +1 -35
- package/dist/lib/server/streaming/dataStream.js +15 -0
- package/dist/lib/services/server/ai/observability/instrumentation.js +114 -14
- package/dist/lib/session/globalSessionState.d.ts +1 -10
- package/dist/lib/tasks/tools/taskTools.d.ts +2 -2
- package/dist/lib/telemetry/traceContext.d.ts +9 -0
- package/dist/lib/telemetry/traceContext.js +19 -0
- package/dist/lib/telemetry/tracers.d.ts +2 -0
- package/dist/lib/telemetry/tracers.js +2 -0
- package/dist/lib/types/action.d.ts +2 -0
- package/dist/lib/types/artifact.d.ts +7 -0
- package/dist/lib/types/auth.d.ts +125 -18
- package/dist/lib/types/autoresearch.d.ts +12 -0
- package/dist/lib/types/cli.d.ts +415 -0
- package/dist/lib/types/client.d.ts +34 -0
- package/dist/lib/types/common.d.ts +12 -41
- package/dist/lib/types/context.d.ts +5 -0
- package/dist/lib/types/evaluation.d.ts +332 -1
- package/dist/lib/types/file.d.ts +4 -0
- package/dist/lib/types/mcp.d.ts +102 -2
- package/dist/lib/types/middleware.d.ts +116 -0
- package/dist/lib/types/multimodal.d.ts +65 -0
- package/dist/lib/types/observability.d.ts +81 -0
- package/dist/lib/types/processor.d.ts +47 -0
- package/dist/lib/types/providers.d.ts +120 -16
- package/dist/lib/types/proxy.d.ts +321 -1
- package/dist/lib/types/rag.d.ts +22 -0
- package/dist/lib/types/scorer.d.ts +141 -0
- package/dist/lib/types/server.d.ts +99 -0
- package/dist/lib/types/span.d.ts +2 -1
- package/dist/lib/types/span.js +1 -0
- package/dist/lib/types/tools.d.ts +44 -0
- package/dist/lib/types/tts.d.ts +6 -0
- package/dist/lib/types/utilities.d.ts +22 -0
- package/dist/lib/types/workflow.d.ts +18 -0
- package/dist/lib/utils/async/retry.d.ts +2 -8
- package/dist/lib/utils/async/retry.js +9 -9
- package/dist/lib/utils/imageCompressor.d.ts +1 -21
- package/dist/lib/utils/imageCompressor.js +5 -1
- package/dist/lib/utils/messageBuilder.d.ts +1 -1
- package/dist/lib/utils/redis.d.ts +1 -4
- package/dist/lib/utils/sanitizers/filename.d.ts +0 -1
- package/dist/lib/utils/toolEndEmitter.d.ts +25 -0
- package/dist/lib/utils/toolEndEmitter.js +65 -0
- package/dist/lib/workflow/config.d.ts +7 -32
- package/dist/lib/workflow/core/ensembleExecutor.js +28 -0
- package/dist/lib/workflow/core/judgeScorer.js +23 -0
- package/dist/lib/workflow/core/responseConditioner.js +17 -0
- package/dist/lib/workflow/core/workflowRunner.d.ts +1 -19
- package/dist/lib/workflow/core/workflowRunner.js +202 -147
- package/dist/mcp/batching/requestBatcher.js +99 -73
- package/dist/mcp/httpRateLimiter.js +3 -1
- package/dist/mcp/httpRetryHandler.js +3 -1
- package/dist/mcp/mcpClientFactory.js +3 -1
- package/dist/mcp/multiServerManager.d.ts +1 -14
- package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
- package/dist/mcp/toolDiscoveryService.js +70 -57
- package/dist/mcp/toolRegistry.js +11 -1
- package/dist/memory/hippocampusInitializer.d.ts +1 -2
- package/dist/memory/hippocampusInitializer.js +1 -1
- package/dist/memory/memoryRetrievalTools.js +182 -141
- package/dist/models/anthropicModels.d.ts +0 -1
- package/dist/models/anthropicModels.js +1 -0
- package/dist/neurolink.js +237 -41
- package/dist/observability/exporterRegistry.d.ts +3 -22
- package/dist/observability/exporters/sentryExporter.js +1 -0
- package/dist/observability/metricsAggregator.d.ts +1 -31
- package/dist/observability/retryPolicy.d.ts +0 -1
- package/dist/observability/sampling/samplers.d.ts +0 -1
- package/dist/observability/spanProcessor.d.ts +0 -1
- package/dist/observability/tokenTracker.d.ts +7 -16
- package/dist/observability/tokenTracker.js +6 -4
- package/dist/observability/utils/spanSerializer.d.ts +5 -1
- package/dist/observability/utils/spanSerializer.js +24 -4
- package/dist/processors/base/BaseFileProcessor.js +66 -53
- package/dist/processors/document/ExcelProcessor.d.ts +1 -1
- package/dist/processors/errors/errorHelpers.d.ts +1 -31
- package/dist/processors/errors/errorSerializer.d.ts +1 -45
- package/dist/processors/registry/ProcessorRegistry.js +17 -6
- package/dist/providers/amazonBedrock.js +189 -15
- package/dist/providers/amazonSagemaker.js +25 -11
- package/dist/providers/anthropic.js +13 -0
- package/dist/providers/azureOpenai.js +2 -0
- package/dist/providers/googleAiStudio.js +82 -0
- package/dist/providers/googleNativeGemini3.d.ts +1 -2
- package/dist/providers/googleVertex.js +52 -0
- package/dist/providers/huggingFace.js +2 -0
- package/dist/providers/litellm.js +2 -0
- package/dist/providers/mistral.js +2 -0
- package/dist/providers/ollama.js +84 -5
- package/dist/providers/openAI.d.ts +2 -0
- package/dist/providers/openAI.js +17 -6
- package/dist/providers/openRouter.js +2 -0
- package/dist/providers/openaiCompatible.js +2 -0
- package/dist/providers/sagemaker/detection.d.ts +1 -33
- package/dist/providers/sagemaker/diagnostics.d.ts +1 -25
- package/dist/providers/sagemaker/language-model.d.ts +1 -1
- package/dist/proxy/proxyConfig.js +4 -0
- package/dist/proxy/proxyEnv.d.ts +1 -17
- package/dist/proxy/proxyHealth.d.ts +0 -1
- package/dist/proxy/proxyTracer.d.ts +1 -36
- package/dist/proxy/proxyTracer.js +9 -0
- package/dist/proxy/quietDetector.d.ts +1 -7
- package/dist/proxy/rawStreamCapture.d.ts +1 -10
- package/dist/proxy/requestLogger.d.ts +1 -21
- package/dist/proxy/routingPolicy.d.ts +1 -2
- package/dist/proxy/sseInterceptor.d.ts +1 -66
- package/dist/proxy/sseInterceptor.js +6 -0
- package/dist/proxy/updateChecker.d.ts +1 -6
- package/dist/proxy/updateState.d.ts +1 -12
- package/dist/rag/chunkers/BaseChunker.js +36 -22
- package/dist/rag/chunking/jsonChunker.d.ts +1 -1
- package/dist/rag/errors/RAGError.d.ts +1 -2
- package/dist/rag/ragIntegration.js +45 -32
- package/dist/rag/reranker/reranker.js +151 -122
- package/dist/rag/retrieval/vectorQueryTool.js +79 -65
- package/dist/sdk/toolRegistration.d.ts +10 -44
- package/dist/sdk/toolRegistration.js +1 -1
- package/dist/server/middleware/abortSignal.d.ts +1 -11
- package/dist/server/middleware/auth.d.ts +1 -21
- package/dist/server/middleware/auth.js +12 -0
- package/dist/server/middleware/common.js +48 -32
- package/dist/server/middleware/deprecation.d.ts +1 -20
- package/dist/server/middleware/rateLimit.d.ts +1 -75
- package/dist/server/middleware/validation.d.ts +3 -81
- package/dist/server/middleware/validation.js +3 -0
- package/dist/server/openapi/generator.d.ts +1 -47
- package/dist/server/routes/agentRoutes.js +112 -57
- package/dist/server/routes/claudeProxyRoutes.d.ts +1 -6
- package/dist/server/routes/claudeProxyRoutes.js +127 -13
- package/dist/server/routes/healthRoutes.js +58 -12
- package/dist/server/routes/index.d.ts +1 -26
- package/dist/server/routes/mcpRoutes.js +40 -7
- package/dist/server/routes/memoryRoutes.js +22 -7
- package/dist/server/routes/openApiRoutes.js +30 -6
- package/dist/server/routes/toolRoutes.js +140 -68
- package/dist/server/streaming/dataStream.d.ts +1 -35
- package/dist/server/streaming/dataStream.js +15 -0
- package/dist/services/server/ai/observability/instrumentation.js +114 -14
- package/dist/session/globalSessionState.d.ts +1 -10
- package/dist/tasks/tools/taskTools.d.ts +2 -2
- package/dist/telemetry/traceContext.d.ts +9 -0
- package/dist/telemetry/traceContext.js +18 -0
- package/dist/telemetry/tracers.d.ts +2 -0
- package/dist/telemetry/tracers.js +2 -0
- package/dist/types/action.d.ts +2 -0
- package/dist/types/artifact.d.ts +7 -0
- package/dist/types/auth.d.ts +125 -18
- package/dist/types/autoresearch.d.ts +12 -0
- package/dist/types/cli.d.ts +415 -0
- package/dist/types/client.d.ts +34 -0
- package/dist/types/common.d.ts +12 -41
- package/dist/types/context.d.ts +5 -0
- package/dist/types/evaluation.d.ts +332 -1
- package/dist/types/file.d.ts +4 -0
- package/dist/types/mcp.d.ts +102 -2
- package/dist/types/middleware.d.ts +116 -0
- package/dist/types/multimodal.d.ts +65 -0
- package/dist/types/observability.d.ts +81 -0
- package/dist/types/processor.d.ts +47 -0
- package/dist/types/providers.d.ts +120 -16
- package/dist/types/proxy.d.ts +321 -1
- package/dist/types/rag.d.ts +22 -0
- package/dist/types/scorer.d.ts +141 -0
- package/dist/types/server.d.ts +99 -0
- package/dist/types/span.d.ts +2 -1
- package/dist/types/span.js +1 -0
- package/dist/types/tools.d.ts +44 -0
- package/dist/types/tts.d.ts +6 -0
- package/dist/types/utilities.d.ts +22 -0
- package/dist/types/workflow.d.ts +18 -0
- package/dist/utils/async/retry.d.ts +2 -8
- package/dist/utils/async/retry.js +9 -9
- package/dist/utils/imageCompressor.d.ts +1 -21
- package/dist/utils/imageCompressor.js +5 -1
- package/dist/utils/messageBuilder.d.ts +1 -1
- package/dist/utils/redis.d.ts +1 -4
- package/dist/utils/sanitizers/filename.d.ts +0 -1
- package/dist/utils/toolEndEmitter.d.ts +25 -0
- package/dist/utils/toolEndEmitter.js +64 -0
- package/dist/workflow/config.d.ts +4 -29
- package/dist/workflow/core/ensembleExecutor.js +28 -0
- package/dist/workflow/core/judgeScorer.js +23 -0
- package/dist/workflow/core/responseConditioner.js +17 -0
- package/dist/workflow/core/workflowRunner.d.ts +1 -19
- package/dist/workflow/core/workflowRunner.js +202 -147
- package/package.json +2 -1
|
@@ -2,65 +2,7 @@
|
|
|
2
2
|
* @file Metrics Collector
|
|
3
3
|
* Collect and aggregate evaluation metrics
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
6
|
-
/**
|
|
7
|
-
* Scorer metrics
|
|
8
|
-
*/
|
|
9
|
-
type ScorerMetrics = {
|
|
10
|
-
scorerId: string;
|
|
11
|
-
scorerName: string;
|
|
12
|
-
totalExecutions: number;
|
|
13
|
-
successfulExecutions: number;
|
|
14
|
-
failedExecutions: number;
|
|
15
|
-
passedCount: number;
|
|
16
|
-
failedCount: number;
|
|
17
|
-
totalScore: number;
|
|
18
|
-
minScore: number;
|
|
19
|
-
maxScore: number;
|
|
20
|
-
totalDuration: number;
|
|
21
|
-
averageDuration: number;
|
|
22
|
-
averageScore: number;
|
|
23
|
-
passRate: number;
|
|
24
|
-
lastExecutionTime: number;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Pipeline metrics
|
|
28
|
-
*/
|
|
29
|
-
type PipelineMetrics = {
|
|
30
|
-
pipelineName: string;
|
|
31
|
-
totalExecutions: number;
|
|
32
|
-
passedCount: number;
|
|
33
|
-
failedCount: number;
|
|
34
|
-
totalScore: number;
|
|
35
|
-
minScore: number;
|
|
36
|
-
maxScore: number;
|
|
37
|
-
totalDuration: number;
|
|
38
|
-
averageDuration: number;
|
|
39
|
-
averageScore: number;
|
|
40
|
-
passRate: number;
|
|
41
|
-
lastExecutionTime: number;
|
|
42
|
-
scorerMetrics: Map<string, ScorerMetrics>;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Aggregated metrics
|
|
46
|
-
*/
|
|
47
|
-
type AggregatedMetrics = {
|
|
48
|
-
totalEvaluations: number;
|
|
49
|
-
overallPassRate: number;
|
|
50
|
-
averageScore: number;
|
|
51
|
-
averageDuration: number;
|
|
52
|
-
scoreDistribution: {
|
|
53
|
-
excellent: number;
|
|
54
|
-
good: number;
|
|
55
|
-
fair: number;
|
|
56
|
-
poor: number;
|
|
57
|
-
failing: number;
|
|
58
|
-
};
|
|
59
|
-
pipelineMetrics: Map<string, PipelineMetrics>;
|
|
60
|
-
scorerMetrics: Map<string, ScorerMetrics>;
|
|
61
|
-
collectionStartTime: number;
|
|
62
|
-
lastUpdateTime: number;
|
|
63
|
-
};
|
|
5
|
+
import type { AggregatedMetrics, PipelineMetrics, PipelineResult, ScoreResult, ScorerMetrics } from "../../types/index.js";
|
|
64
6
|
/**
|
|
65
7
|
* Metrics collector for evaluation data
|
|
66
8
|
*/
|
|
@@ -144,4 +86,3 @@ export declare function createMetricsCollector(): MetricsCollector;
|
|
|
144
86
|
* Global metrics collector instance
|
|
145
87
|
*/
|
|
146
88
|
export declare const globalMetricsCollector: MetricsCollector;
|
|
147
|
-
export {};
|
|
@@ -2,22 +2,7 @@
|
|
|
2
2
|
* @file Report Generator
|
|
3
3
|
* Generate evaluation reports in various formats
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
6
|
-
/**
|
|
7
|
-
* Generated report
|
|
8
|
-
*/
|
|
9
|
-
type GeneratedReport = {
|
|
10
|
-
/** Report format */
|
|
11
|
-
format: ReportFormat;
|
|
12
|
-
/** Report content */
|
|
13
|
-
content: string;
|
|
14
|
-
/** Metadata */
|
|
15
|
-
metadata: {
|
|
16
|
-
generatedAt: number;
|
|
17
|
-
format: ReportFormat;
|
|
18
|
-
config: ReportConfig;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
5
|
+
import type { GeneratedReport, ReportConfig, ReportData } from "../../types/index.js";
|
|
21
6
|
/**
|
|
22
7
|
* Report generator class
|
|
23
8
|
*/
|
|
@@ -70,4 +55,3 @@ export declare const Reports: {
|
|
|
70
55
|
/** Generate HTML report */
|
|
71
56
|
html: (data: ReportData) => GeneratedReport;
|
|
72
57
|
};
|
|
73
|
-
export {};
|
|
@@ -2,35 +2,8 @@
|
|
|
2
2
|
* @file Content Similarity Scorer
|
|
3
3
|
* Evaluates text similarity using various metrics (Jaccard, cosine, Levenshtein)
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
5
|
+
import type { ContentSimilarityConfig, ScoreResult, ScorerInput } from "../../../types/index.js";
|
|
6
6
|
import { BaseScorer } from "../baseScorer.js";
|
|
7
|
-
/**
|
|
8
|
-
* Similarity metric types
|
|
9
|
-
*/
|
|
10
|
-
type SimilarityMetric = "jaccard" | "cosine" | "levenshtein" | "dice" | "overlap";
|
|
11
|
-
/**
|
|
12
|
-
* Configuration specific to content similarity scoring
|
|
13
|
-
*/
|
|
14
|
-
type ContentSimilarityConfig = RuleScorerConfig & {
|
|
15
|
-
/** Similarity metric to use */
|
|
16
|
-
metric?: SimilarityMetric;
|
|
17
|
-
/** Multiple metrics to combine */
|
|
18
|
-
metrics?: SimilarityMetric[];
|
|
19
|
-
/** How to combine multiple metrics */
|
|
20
|
-
metricCombination?: "average" | "min" | "max" | "weighted";
|
|
21
|
-
/** Weights for each metric (if weighted combination) */
|
|
22
|
-
metricWeights?: Record<SimilarityMetric, number>;
|
|
23
|
-
/** Whether to normalize text before comparison */
|
|
24
|
-
normalizeText?: boolean;
|
|
25
|
-
/** Whether to use word-level or character-level comparison */
|
|
26
|
-
tokenLevel?: "word" | "character" | "ngram";
|
|
27
|
-
/** N-gram size if using ngram tokenization */
|
|
28
|
-
ngramSize?: number;
|
|
29
|
-
/** Compare against ground truth, context, or custom reference */
|
|
30
|
-
compareWith?: "groundTruth" | "context" | "custom";
|
|
31
|
-
/** Custom reference text if compareWith is "custom" */
|
|
32
|
-
referenceText?: string;
|
|
33
|
-
};
|
|
34
7
|
/**
|
|
35
8
|
* ContentSimilarityScorer evaluates how similar the response is to a reference text
|
|
36
9
|
*/
|
|
@@ -106,4 +79,3 @@ export declare class ContentSimilarityScorer extends BaseScorer {
|
|
|
106
79
|
* Factory function for creating ContentSimilarityScorer instances
|
|
107
80
|
*/
|
|
108
81
|
export declare function createContentSimilarityScorer(config?: ContentSimilarityConfig): Promise<ContentSimilarityScorer>;
|
|
109
|
-
export {};
|
|
@@ -2,48 +2,8 @@
|
|
|
2
2
|
* @file Format Scorer
|
|
3
3
|
* Evaluates response format compliance (JSON, markdown, code, etc.)
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
5
|
+
import type { FormatScorerConfig, ScoreResult, ScorerInput, ScorerRule } from "../../../types/index.js";
|
|
6
6
|
import { BaseRuleScorer } from "./baseRuleScorer.js";
|
|
7
|
-
/**
|
|
8
|
-
* Expected format types
|
|
9
|
-
*/
|
|
10
|
-
type FormatType = "json" | "markdown" | "code" | "list" | "numbered-list" | "bullet-list" | "table" | "yaml" | "xml" | "plain" | "html" | "custom";
|
|
11
|
-
/**
|
|
12
|
-
* Code language types for code format validation
|
|
13
|
-
*/
|
|
14
|
-
type CodeLanguage = "javascript" | "typescript" | "python" | "java" | "c" | "cpp" | "csharp" | "go" | "rust" | "sql" | "bash" | "any";
|
|
15
|
-
/**
|
|
16
|
-
* Configuration specific to format scoring
|
|
17
|
-
*/
|
|
18
|
-
type FormatScorerConfig = RuleScorerConfig & {
|
|
19
|
-
/** Expected format type */
|
|
20
|
-
expectedFormat?: FormatType;
|
|
21
|
-
/** Multiple allowed formats */
|
|
22
|
-
allowedFormats?: FormatType[];
|
|
23
|
-
/** For code format: expected language */
|
|
24
|
-
codeLanguage?: CodeLanguage;
|
|
25
|
-
/** For JSON format: validate against schema */
|
|
26
|
-
jsonSchema?: object;
|
|
27
|
-
/** For markdown: required elements */
|
|
28
|
-
markdownRequirements?: {
|
|
29
|
-
hasHeadings?: boolean;
|
|
30
|
-
hasCodeBlocks?: boolean;
|
|
31
|
-
hasLinks?: boolean;
|
|
32
|
-
hasLists?: boolean;
|
|
33
|
-
minHeadingLevel?: number;
|
|
34
|
-
maxHeadingLevel?: number;
|
|
35
|
-
};
|
|
36
|
-
/** For list format: requirements */
|
|
37
|
-
listRequirements?: {
|
|
38
|
-
minItems?: number;
|
|
39
|
-
maxItems?: number;
|
|
40
|
-
itemPattern?: string;
|
|
41
|
-
};
|
|
42
|
-
/** Custom format regex pattern */
|
|
43
|
-
customPattern?: string;
|
|
44
|
-
/** Whether format must be exclusive (no other content) */
|
|
45
|
-
strictFormat?: boolean;
|
|
46
|
-
};
|
|
47
7
|
/**
|
|
48
8
|
* FormatScorer evaluates response format against expected formats
|
|
49
9
|
*/
|
|
@@ -145,4 +105,3 @@ export declare const FormatScorerPresets: {
|
|
|
145
105
|
/** Plain text only */
|
|
146
106
|
readonly plainText: () => FormatScorer;
|
|
147
107
|
};
|
|
148
|
-
export {};
|
|
@@ -2,25 +2,8 @@
|
|
|
2
2
|
* @file Keyword Coverage Scorer
|
|
3
3
|
* Evaluates how well the response covers expected keywords or topics
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
5
|
+
import type { KeywordCoverageConfig, ScoreResult, ScorerInput, ScorerRule } from "../../../types/index.js";
|
|
6
6
|
import { BaseRuleScorer } from "./baseRuleScorer.js";
|
|
7
|
-
/**
|
|
8
|
-
* Configuration specific to keyword coverage scoring
|
|
9
|
-
*/
|
|
10
|
-
type KeywordCoverageConfig = RuleScorerConfig & {
|
|
11
|
-
/** Keywords to check for */
|
|
12
|
-
keywords?: string[];
|
|
13
|
-
/** Minimum coverage ratio (0-1) to pass */
|
|
14
|
-
minCoverage?: number;
|
|
15
|
-
/** Whether to use case-insensitive matching */
|
|
16
|
-
caseInsensitive?: boolean;
|
|
17
|
-
/** Whether to use word boundary matching */
|
|
18
|
-
wordBoundary?: boolean;
|
|
19
|
-
/** Synonyms map for flexible matching */
|
|
20
|
-
synonyms?: Record<string, string[]>;
|
|
21
|
-
/** Weight different keywords differently */
|
|
22
|
-
keywordWeights?: Record<string, number>;
|
|
23
|
-
};
|
|
24
7
|
/**
|
|
25
8
|
* KeywordCoverageScorer evaluates how well a response covers expected keywords
|
|
26
9
|
*/
|
|
@@ -81,4 +64,3 @@ export declare class KeywordCoverageScorer extends BaseRuleScorer {
|
|
|
81
64
|
* Factory function for creating KeywordCoverageScorer instances
|
|
82
65
|
*/
|
|
83
66
|
export declare function createKeywordCoverageScorer(config?: KeywordCoverageConfig): Promise<KeywordCoverageScorer>;
|
|
84
|
-
export {};
|
|
@@ -2,39 +2,8 @@
|
|
|
2
2
|
* @file Length Scorer
|
|
3
3
|
* Evaluates response length against configured constraints
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
5
|
+
import type { LengthScorerConfig, ScoreResult, ScorerInput, ScorerRule } from "../../../types/index.js";
|
|
6
6
|
import { BaseRuleScorer } from "./baseRuleScorer.js";
|
|
7
|
-
/**
|
|
8
|
-
* Length measurement unit
|
|
9
|
-
*/
|
|
10
|
-
type LengthUnit = "words" | "characters" | "sentences" | "paragraphs" | "tokens";
|
|
11
|
-
/**
|
|
12
|
-
* Length constraint type
|
|
13
|
-
*/
|
|
14
|
-
type LengthConstraintType = "exact" | "range" | "minimum" | "maximum" | "ratio";
|
|
15
|
-
/**
|
|
16
|
-
* Configuration specific to length scoring
|
|
17
|
-
*/
|
|
18
|
-
type LengthScorerConfig = RuleScorerConfig & {
|
|
19
|
-
/** Unit of measurement */
|
|
20
|
-
unit?: LengthUnit;
|
|
21
|
-
/** Constraint type */
|
|
22
|
-
constraintType?: LengthConstraintType;
|
|
23
|
-
/** Minimum length (for range/minimum constraints) */
|
|
24
|
-
minLength?: number;
|
|
25
|
-
/** Maximum length (for range/maximum constraints) */
|
|
26
|
-
maxLength?: number;
|
|
27
|
-
/** Exact length (for exact constraint) */
|
|
28
|
-
exactLength?: number;
|
|
29
|
-
/** Tolerance for exact length (as percentage) */
|
|
30
|
-
tolerance?: number;
|
|
31
|
-
/** Compare ratio with query/context length */
|
|
32
|
-
ratioTarget?: number;
|
|
33
|
-
/** Ratio reference: compare against query or context */
|
|
34
|
-
ratioReference?: "query" | "context";
|
|
35
|
-
/** Scoring mode: binary (pass/fail) or proportional */
|
|
36
|
-
scoringMode?: "binary" | "proportional";
|
|
37
|
-
};
|
|
38
7
|
/**
|
|
39
8
|
* LengthScorer evaluates response length against configurable constraints
|
|
40
9
|
*/
|
|
@@ -103,4 +72,3 @@ export declare const LengthScorerPresets: {
|
|
|
103
72
|
/** Tweet-length (max 280 characters) */
|
|
104
73
|
readonly tweet: () => LengthScorer;
|
|
105
74
|
};
|
|
106
|
-
export {};
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import type { AIProviderName } from "../constants/enums.js";
|
|
2
|
-
import type {
|
|
3
|
-
/**
|
|
4
|
-
* Provider constructor interface - supports both sync constructors and async factory functions
|
|
5
|
-
*/
|
|
6
|
-
type ProviderConstructor = {
|
|
7
|
-
new (modelName?: string, providerName?: string, sdk?: UnknownRecord, region?: string): AIProvider;
|
|
8
|
-
} | ((modelName?: string, providerName?: string, sdk?: UnknownRecord, region?: string) => Promise<AIProvider>);
|
|
9
|
-
/**
|
|
10
|
-
* Provider registration entry
|
|
11
|
-
*/
|
|
12
|
-
type ProviderRegistration = {
|
|
13
|
-
constructor: ProviderConstructor;
|
|
14
|
-
defaultModel?: string;
|
|
15
|
-
aliases?: string[];
|
|
16
|
-
};
|
|
2
|
+
import type { AIProvider, NeurolinkCredentials, ProviderConstructor, ProviderRegistration, UnknownRecord } from "../types/index.js";
|
|
17
3
|
/**
|
|
18
4
|
* True Factory Pattern implementation for AI Providers
|
|
19
5
|
* Uses registration-based approach to eliminate switch statements
|
|
@@ -72,4 +58,3 @@ export declare class ProviderFactory {
|
|
|
72
58
|
* Helper function to create providers with backward compatibility
|
|
73
59
|
*/
|
|
74
60
|
export declare function createAIProvider(providerName: AIProviderName | string, modelName?: string, credentials?: NeurolinkCredentials): Promise<AIProvider>;
|
|
75
|
-
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { logger } from "../utils/logger.js";
|
|
2
|
+
// Pure factory pattern with no hardcoded imports
|
|
3
|
+
// All providers loaded dynamically via registry to avoid circular dependencies
|
|
2
4
|
/**
|
|
3
5
|
* True Factory Pattern implementation for AI Providers
|
|
4
6
|
* Uses registration-based approach to eliminate switch statements
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import { withTimeout } from "../utils/errorHandling.js";
|
|
29
29
|
import { DEFAULT_IMAGE_GEN_CONFIG } from "../types/index.js";
|
|
30
|
+
/**
|
|
31
|
+
* NeuroLink instance type (avoiding circular dependencies)
|
|
32
|
+
*/
|
|
30
33
|
/**
|
|
31
34
|
* Image generation service for AI-powered image creation
|
|
32
35
|
*
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
import { EventEmitter } from "events";
|
|
11
11
|
import { logger } from "../../utils/logger.js";
|
|
12
12
|
import { ErrorFactory } from "../../utils/errorHandling.js";
|
|
13
|
+
import { withSpan } from "../../telemetry/withSpan.js";
|
|
14
|
+
import { tracers } from "../../telemetry/tracers.js";
|
|
13
15
|
/**
|
|
14
16
|
* Request Batcher - Efficient batch processing for MCP tool calls
|
|
15
17
|
*
|
|
@@ -217,85 +219,109 @@ export class RequestBatcher extends EventEmitter {
|
|
|
217
219
|
const startTime = Date.now();
|
|
218
220
|
this.activeBatches++;
|
|
219
221
|
this.emit("batchStarted", { batchId, size: batchRequests.length });
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
timeoutHandle = setTimeout(() => reject(ErrorFactory.toolTimeout("batchExecution", timeoutMs)), timeoutMs);
|
|
237
|
-
});
|
|
238
|
-
const results = await Promise.race([
|
|
239
|
-
executorPromise,
|
|
240
|
-
timeoutPromise,
|
|
241
|
-
]).finally(() => {
|
|
242
|
-
if (timeoutHandle) {
|
|
243
|
-
clearTimeout(timeoutHandle);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
// Process results
|
|
247
|
-
const batchResults = [];
|
|
248
|
-
for (let i = 0; i < batchRequests.length; i++) {
|
|
249
|
-
const request = batchRequests[i];
|
|
250
|
-
const result = results[i];
|
|
251
|
-
const executionTime = Date.now() - startTime;
|
|
252
|
-
if (!result) {
|
|
253
|
-
const noResultError = ErrorFactory.toolExecutionFailed(request.tool, new Error(`Batch executor returned no result for request ${i}`));
|
|
254
|
-
request.reject(noResultError);
|
|
255
|
-
batchResults.push({
|
|
256
|
-
id: request.id,
|
|
257
|
-
success: false,
|
|
258
|
-
error: noResultError,
|
|
259
|
-
executionTime,
|
|
222
|
+
await withSpan({
|
|
223
|
+
name: "neurolink.mcp.batch.execute",
|
|
224
|
+
tracer: tracers.mcp,
|
|
225
|
+
attributes: {
|
|
226
|
+
"mcp.batch.id": batchId,
|
|
227
|
+
"mcp.batch.size": batchRequests.length,
|
|
228
|
+
"mcp.batch.active_batches": this.activeBatches,
|
|
229
|
+
},
|
|
230
|
+
}, async (span) => {
|
|
231
|
+
let successCount = 0;
|
|
232
|
+
let errorCount = 0;
|
|
233
|
+
try {
|
|
234
|
+
// Guard against missing executor
|
|
235
|
+
if (!this.executor) {
|
|
236
|
+
throw ErrorFactory.missingConfiguration("batchExecutor", {
|
|
237
|
+
hint: "Call setExecutor() before executing batches",
|
|
260
238
|
});
|
|
261
|
-
continue;
|
|
262
239
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
240
|
+
// Execute the batch with a timeout to prevent indefinite hangs
|
|
241
|
+
const executorPromise = this.executor(batchRequests.map((r) => ({
|
|
242
|
+
tool: r.tool,
|
|
243
|
+
args: r.args,
|
|
244
|
+
serverId: r.serverId,
|
|
245
|
+
})));
|
|
246
|
+
const timeoutMs = Math.max(5000, Number(process.env.MCP_TOOL_TIMEOUT) || 60000);
|
|
247
|
+
let timeoutHandle;
|
|
248
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
249
|
+
timeoutHandle = setTimeout(() => reject(ErrorFactory.toolTimeout("batchExecution", timeoutMs)), timeoutMs);
|
|
250
|
+
});
|
|
251
|
+
// Suppress unhandled rejection if executorPromise rejects after timeout wins
|
|
252
|
+
void executorPromise.catch((_e) => {
|
|
253
|
+
// Intentionally swallowed — timeout already handled the failure
|
|
254
|
+
});
|
|
255
|
+
const results = await Promise.race([
|
|
256
|
+
executorPromise,
|
|
257
|
+
timeoutPromise,
|
|
258
|
+
]).finally(() => {
|
|
259
|
+
if (timeoutHandle) {
|
|
260
|
+
clearTimeout(timeoutHandle);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
// Process results
|
|
264
|
+
const batchResults = [];
|
|
265
|
+
for (let i = 0; i < batchRequests.length; i++) {
|
|
266
|
+
const request = batchRequests[i];
|
|
267
|
+
const result = results[i];
|
|
268
|
+
const executionTime = Date.now() - startTime;
|
|
269
|
+
if (!result) {
|
|
270
|
+
const noResultError = ErrorFactory.toolExecutionFailed(request.tool, new Error(`Batch executor returned no result for request ${i}`));
|
|
271
|
+
request.reject(noResultError);
|
|
272
|
+
batchResults.push({
|
|
273
|
+
id: request.id,
|
|
274
|
+
success: false,
|
|
275
|
+
error: noResultError,
|
|
276
|
+
executionTime,
|
|
277
|
+
});
|
|
278
|
+
errorCount++;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (result.success) {
|
|
282
|
+
request.resolve(result.result);
|
|
283
|
+
batchResults.push({
|
|
284
|
+
id: request.id,
|
|
285
|
+
success: true,
|
|
286
|
+
result: result.result,
|
|
287
|
+
executionTime,
|
|
288
|
+
});
|
|
289
|
+
successCount++;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
const error = result.error ??
|
|
293
|
+
ErrorFactory.toolExecutionFailed(request.tool, new Error("Unknown batch execution error"));
|
|
294
|
+
request.reject(error);
|
|
295
|
+
batchResults.push({
|
|
296
|
+
id: request.id,
|
|
297
|
+
success: false,
|
|
298
|
+
error,
|
|
299
|
+
executionTime,
|
|
300
|
+
});
|
|
301
|
+
errorCount++;
|
|
302
|
+
}
|
|
271
303
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
304
|
+
span.setAttribute("mcp.batch.success_count", successCount);
|
|
305
|
+
span.setAttribute("mcp.batch.error_count", errorCount);
|
|
306
|
+
this.emit("batchCompleted", { batchId, results: batchResults });
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
// Batch-level failure - reject all requests
|
|
310
|
+
const batchError = error instanceof Error
|
|
311
|
+
? error
|
|
312
|
+
: ErrorFactory.toolExecutionFailed("batch", new Error(String(error)));
|
|
313
|
+
for (const request of batchRequests) {
|
|
314
|
+
request.reject(batchError);
|
|
282
315
|
}
|
|
316
|
+
this.emit("batchFailed", { batchId, error: batchError });
|
|
317
|
+
throw batchError;
|
|
283
318
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
catch (error) {
|
|
287
|
-
// Batch-level failure - reject all requests
|
|
288
|
-
const batchError = error instanceof Error
|
|
289
|
-
? error
|
|
290
|
-
: ErrorFactory.toolExecutionFailed("batch", new Error(String(error)));
|
|
291
|
-
for (const request of batchRequests) {
|
|
292
|
-
request.reject(batchError);
|
|
319
|
+
finally {
|
|
320
|
+
this.activeBatches--;
|
|
293
321
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
this.activeBatches--;
|
|
298
|
-
}
|
|
322
|
+
}).catch((error) => {
|
|
323
|
+
logger.error("Batch span execution failed:", error);
|
|
324
|
+
});
|
|
299
325
|
// Schedule next batch if there are more pending requests
|
|
300
326
|
if (this.pending.size > 0) {
|
|
301
327
|
this.clearFlushTimer();
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { mcpLogger } from "../utils/logger.js";
|
|
7
7
|
import { SpanSerializer, SpanType, SpanStatus, getMetricsAggregator, } from "../observability/index.js";
|
|
8
|
+
import { getActiveTraceContext } from "../telemetry/traceContext.js";
|
|
8
9
|
/**
|
|
9
10
|
* Default rate limit configuration
|
|
10
11
|
* Provides sensible defaults for most MCP HTTP transport use cases
|
|
@@ -72,12 +73,13 @@ export class HTTPRateLimiter {
|
|
|
72
73
|
* @throws Error if the wait queue is too long
|
|
73
74
|
*/
|
|
74
75
|
async acquire() {
|
|
76
|
+
const { traceId, parentSpanId } = getActiveTraceContext();
|
|
75
77
|
const span = SpanSerializer.createSpan(SpanType.MCP_TRANSPORT, "mcp.rateLimit", {
|
|
76
78
|
"mcp.transport": "http",
|
|
77
79
|
"mcp.operation": "rateLimit",
|
|
78
80
|
"mcp.rateLimit.tokensAvailable": this.tokens,
|
|
79
81
|
"mcp.rateLimit.maxBurst": this.config.maxBurst,
|
|
80
|
-
});
|
|
82
|
+
}, parentSpanId, traceId);
|
|
81
83
|
const startTime = Date.now();
|
|
82
84
|
try {
|
|
83
85
|
// First, try to acquire without waiting
|
|
@@ -8,6 +8,7 @@ import { isAbortError } from "../utils/errorHandling.js";
|
|
|
8
8
|
import { calculateBackoffDelay } from "../utils/retryHandler.js";
|
|
9
9
|
import { logger } from "../utils/logger.js";
|
|
10
10
|
import { SpanSerializer, SpanType, SpanStatus, getMetricsAggregator, } from "../observability/index.js";
|
|
11
|
+
import { getActiveTraceContext } from "../telemetry/traceContext.js";
|
|
11
12
|
/**
|
|
12
13
|
* Default HTTP retry configuration
|
|
13
14
|
*/
|
|
@@ -130,11 +131,12 @@ export async function withHTTPRetry(operation, config = {}) {
|
|
|
130
131
|
...DEFAULT_HTTP_RETRY_CONFIG,
|
|
131
132
|
...config,
|
|
132
133
|
};
|
|
134
|
+
const { traceId, parentSpanId } = getActiveTraceContext();
|
|
133
135
|
const span = SpanSerializer.createSpan(SpanType.MCP_TRANSPORT, "mcp.retry", {
|
|
134
136
|
"mcp.transport": "http",
|
|
135
137
|
"mcp.operation": "retry",
|
|
136
138
|
"mcp.maxAttempts": mergedConfig.maxAttempts,
|
|
137
|
-
});
|
|
139
|
+
}, parentSpanId, traceId);
|
|
138
140
|
const startTime = Date.now();
|
|
139
141
|
let lastError;
|
|
140
142
|
let actualAttempts = 0;
|
|
@@ -17,6 +17,7 @@ import { withHTTPRetry, DEFAULT_HTTP_RETRY_CONFIG, } from "./httpRetryHandler.js
|
|
|
17
17
|
import { globalRateLimiterManager } from "./httpRateLimiter.js";
|
|
18
18
|
import { NeuroLinkOAuthProvider, InMemoryTokenStorage } from "./auth/index.js";
|
|
19
19
|
import { SpanSerializer, SpanType, SpanStatus, getMetricsAggregator, } from "../observability/index.js";
|
|
20
|
+
import { getActiveTraceContext } from "../telemetry/traceContext.js";
|
|
20
21
|
/**
|
|
21
22
|
* Default timeout for MCP client creation in milliseconds.
|
|
22
23
|
* Configurable via MCP_CLIENT_TIMEOUT env var.
|
|
@@ -46,11 +47,12 @@ export class MCPClientFactory {
|
|
|
46
47
|
*/
|
|
47
48
|
static async createClient(config, timeout = DEFAULT_CLIENT_TIMEOUT) {
|
|
48
49
|
const startTime = Date.now();
|
|
50
|
+
const { traceId, parentSpanId } = getActiveTraceContext();
|
|
49
51
|
const obsSpan = SpanSerializer.createSpan(SpanType.MCP_TRANSPORT, "mcp.connect", {
|
|
50
52
|
"mcp.transport": config.transport,
|
|
51
53
|
"mcp.operation": "connect",
|
|
52
54
|
"mcp.server_id": config.id,
|
|
53
|
-
});
|
|
55
|
+
}, parentSpanId, traceId);
|
|
54
56
|
try {
|
|
55
57
|
mcpLogger.info(`[MCPClientFactory] Creating client for ${config.id}`, {
|
|
56
58
|
transport: config.transport,
|
|
@@ -15,19 +15,7 @@
|
|
|
15
15
|
* @since 8.39.0
|
|
16
16
|
*/
|
|
17
17
|
import { EventEmitter } from "events";
|
|
18
|
-
import type {
|
|
19
|
-
/**
|
|
20
|
-
* Server metrics for load balancing
|
|
21
|
-
*/
|
|
22
|
-
type ServerMetrics = {
|
|
23
|
-
activeRequests: number;
|
|
24
|
-
totalRequests: number;
|
|
25
|
-
completedRequests: number;
|
|
26
|
-
averageResponseTime: number;
|
|
27
|
-
errorRate: number;
|
|
28
|
-
lastHealthCheck?: Date;
|
|
29
|
-
isHealthy: boolean;
|
|
30
|
-
};
|
|
18
|
+
import type { JsonObject, MCPServerInfo, MultiServerManagerConfig, ServerGroup, ServerMetrics, UnifiedTool } from "../types/index.js";
|
|
31
19
|
/**
|
|
32
20
|
* Multi-Server Manager
|
|
33
21
|
*
|
|
@@ -192,4 +180,3 @@ export declare class MultiServerManager extends EventEmitter {
|
|
|
192
180
|
* Global multi-server manager instance
|
|
193
181
|
*/
|
|
194
182
|
export declare const globalMultiServerManager: MultiServerManager;
|
|
195
|
-
export {};
|
|
@@ -8,7 +8,11 @@ import { AIProviderFactory } from "../../../core/factory.js";
|
|
|
8
8
|
import { getBestProvider, getAvailableProviders, } from "../../../utils/providerUtils.js";
|
|
9
9
|
import { logger } from "../../../utils/logger.js";
|
|
10
10
|
/**
|
|
11
|
-
* Input Schemas for AI Analysis Tools
|
|
11
|
+
* Input Schemas for AI Analysis Tools.
|
|
12
|
+
*
|
|
13
|
+
* Each schema is annotated with `z.ZodType<CanonicalParams>` so any drift
|
|
14
|
+
* between the structural type (declared in src/lib/types/mcp.ts) and the
|
|
15
|
+
* runtime zod schema fails at compile time.
|
|
12
16
|
*/
|
|
13
17
|
const AnalyzeUsageSchema = z.object({
|
|
14
18
|
sessionId: z.string().optional(),
|