@juspay/neurolink 9.54.6 → 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 +2 -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 -0
- 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 +1 -0
- package/dist/client/httpClient.js +13 -0
- package/dist/client/sseClient.d.ts +1 -0
- 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 +6 -0
- 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/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 -0
- 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 +1 -0
- package/dist/lib/client/httpClient.js +13 -0
- package/dist/lib/client/sseClient.d.ts +1 -0
- 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 +6 -0
- 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/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/memoryRetrievalTools.js +182 -141
- package/dist/lib/neurolink.js +236 -40
- package/dist/lib/observability/exporterRegistry.d.ts +3 -21
- package/dist/lib/observability/exporters/sentryExporter.js +1 -0
- package/dist/lib/observability/metricsAggregator.d.ts +1 -31
- 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/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/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/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/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/memoryRetrievalTools.js +182 -141
- package/dist/neurolink.js +236 -40
- package/dist/observability/exporterRegistry.d.ts +3 -21
- package/dist/observability/exporters/sentryExporter.js +1 -0
- package/dist/observability/metricsAggregator.d.ts +1 -31
- 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/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/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/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/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
|
@@ -11,6 +11,7 @@ import { validateToolName, validateToolDescription, } from "../utils/parameterVa
|
|
|
11
11
|
import { withTimeout } from "../utils/errorHandling.js";
|
|
12
12
|
import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
13
13
|
import { tracers } from "../telemetry/tracers.js";
|
|
14
|
+
import { withSpan } from "../telemetry/withSpan.js";
|
|
14
15
|
const mcpTracer = tracers.mcp;
|
|
15
16
|
/**
|
|
16
17
|
* Default timeout for MCP tool execution operations in milliseconds.
|
|
@@ -44,71 +45,83 @@ export class ToolDiscoveryService extends EventEmitter {
|
|
|
44
45
|
* Discover tools from an external MCP server
|
|
45
46
|
*/
|
|
46
47
|
async discoverTools(serverId, client, timeout = DEFAULT_TOOL_TIMEOUT) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
return withSpan({
|
|
49
|
+
name: "neurolink.mcp.discoverTools",
|
|
50
|
+
tracer: tracers.mcp,
|
|
51
|
+
attributes: { "mcp.server_id": serverId },
|
|
52
|
+
}, async (span) => {
|
|
53
|
+
const startTime = Date.now();
|
|
54
|
+
try {
|
|
55
|
+
// Prevent concurrent discovery for same server
|
|
56
|
+
if (this.discoveryInProgress.has(serverId)) {
|
|
57
|
+
return {
|
|
58
|
+
success: false,
|
|
59
|
+
error: `Discovery already in progress for server: ${serverId}`,
|
|
60
|
+
toolCount: 0,
|
|
61
|
+
tools: [],
|
|
62
|
+
duration: Date.now() - startTime,
|
|
63
|
+
serverId,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
this.discoveryInProgress.add(serverId);
|
|
67
|
+
mcpLogger.info(`[ToolDiscoveryService] Starting tool discovery for server: ${serverId}`);
|
|
68
|
+
// Create circuit breaker for tool discovery
|
|
69
|
+
const circuitBreaker = globalCircuitBreakerManager.getBreaker(`tool-discovery-${serverId}`, {
|
|
70
|
+
failureThreshold: 2,
|
|
71
|
+
resetTimeout: 60000,
|
|
72
|
+
operationTimeout: timeout,
|
|
73
|
+
});
|
|
74
|
+
// Discover tools with circuit breaker protection
|
|
75
|
+
const tools = await circuitBreaker.execute(async () => {
|
|
76
|
+
return await this.performToolDiscovery(serverId, client, timeout);
|
|
77
|
+
});
|
|
78
|
+
// Register discovered tools
|
|
79
|
+
const registeredTools = await this.registerDiscoveredTools(serverId, tools);
|
|
80
|
+
span.setAttribute("mcp.tools_discovered", registeredTools.length);
|
|
81
|
+
const result = {
|
|
82
|
+
success: true,
|
|
83
|
+
toolCount: registeredTools.length,
|
|
84
|
+
tools: registeredTools,
|
|
85
|
+
duration: Date.now() - startTime,
|
|
86
|
+
serverId,
|
|
87
|
+
};
|
|
88
|
+
// Emit discovery completed event
|
|
89
|
+
this.emit("discoveryCompleted", {
|
|
90
|
+
serverId,
|
|
91
|
+
toolCount: registeredTools.length,
|
|
92
|
+
duration: result.duration,
|
|
93
|
+
timestamp: new Date(),
|
|
94
|
+
});
|
|
95
|
+
mcpLogger.info(`[ToolDiscoveryService] Discovery completed for ${serverId}: ${registeredTools.length} tools`);
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
100
|
+
span.setStatus({
|
|
101
|
+
code: SpanStatusCode.ERROR,
|
|
102
|
+
message: errorMessage,
|
|
103
|
+
});
|
|
104
|
+
span.recordException(error instanceof Error ? error : new Error(errorMessage));
|
|
105
|
+
mcpLogger.error(`[ToolDiscoveryService] Discovery failed for ${serverId}:`, error);
|
|
106
|
+
// Emit discovery failed event
|
|
107
|
+
this.emit("discoveryFailed", {
|
|
108
|
+
serverId,
|
|
109
|
+
error: errorMessage,
|
|
110
|
+
timestamp: new Date(),
|
|
111
|
+
});
|
|
51
112
|
return {
|
|
52
113
|
success: false,
|
|
53
|
-
error:
|
|
114
|
+
error: errorMessage,
|
|
54
115
|
toolCount: 0,
|
|
55
116
|
tools: [],
|
|
56
117
|
duration: Date.now() - startTime,
|
|
57
118
|
serverId,
|
|
58
119
|
};
|
|
59
120
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
failureThreshold: 2,
|
|
65
|
-
resetTimeout: 60000,
|
|
66
|
-
operationTimeout: timeout,
|
|
67
|
-
});
|
|
68
|
-
// Discover tools with circuit breaker protection
|
|
69
|
-
const tools = await circuitBreaker.execute(async () => {
|
|
70
|
-
return await this.performToolDiscovery(serverId, client, timeout);
|
|
71
|
-
});
|
|
72
|
-
// Register discovered tools
|
|
73
|
-
const registeredTools = await this.registerDiscoveredTools(serverId, tools);
|
|
74
|
-
const result = {
|
|
75
|
-
success: true,
|
|
76
|
-
toolCount: registeredTools.length,
|
|
77
|
-
tools: registeredTools,
|
|
78
|
-
duration: Date.now() - startTime,
|
|
79
|
-
serverId,
|
|
80
|
-
};
|
|
81
|
-
// Emit discovery completed event
|
|
82
|
-
this.emit("discoveryCompleted", {
|
|
83
|
-
serverId,
|
|
84
|
-
toolCount: registeredTools.length,
|
|
85
|
-
duration: result.duration,
|
|
86
|
-
timestamp: new Date(),
|
|
87
|
-
});
|
|
88
|
-
mcpLogger.info(`[ToolDiscoveryService] Discovery completed for ${serverId}: ${registeredTools.length} tools`);
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
93
|
-
mcpLogger.error(`[ToolDiscoveryService] Discovery failed for ${serverId}:`, error);
|
|
94
|
-
// Emit discovery failed event
|
|
95
|
-
this.emit("discoveryFailed", {
|
|
96
|
-
serverId,
|
|
97
|
-
error: errorMessage,
|
|
98
|
-
timestamp: new Date(),
|
|
99
|
-
});
|
|
100
|
-
return {
|
|
101
|
-
success: false,
|
|
102
|
-
error: errorMessage,
|
|
103
|
-
toolCount: 0,
|
|
104
|
-
tools: [],
|
|
105
|
-
duration: Date.now() - startTime,
|
|
106
|
-
serverId,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
finally {
|
|
110
|
-
this.discoveryInProgress.delete(serverId);
|
|
111
|
-
}
|
|
121
|
+
finally {
|
|
122
|
+
this.discoveryInProgress.delete(serverId);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
112
125
|
}
|
|
113
126
|
/**
|
|
114
127
|
* Perform the actual tool discovery
|
|
@@ -12,6 +12,7 @@ import { FlexibleToolValidator } from "./flexibleToolValidator.js";
|
|
|
12
12
|
import { ErrorFactory } from "../utils/errorHandling.js";
|
|
13
13
|
import { HITLUserRejectedError, HITLTimeoutError } from "../hitl/hitlErrors.js";
|
|
14
14
|
import { withSpan, tracers, ATTR } from "../telemetry/index.js";
|
|
15
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
15
16
|
import { getAuthContext } from "../auth/authContext.js";
|
|
16
17
|
export class MCPToolRegistry extends MCPRegistry {
|
|
17
18
|
tools = new Map();
|
|
@@ -251,7 +252,7 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
254
|
return withSpan({
|
|
254
|
-
name: "neurolink.tool.execute",
|
|
255
|
+
name: "neurolink.tool.registry.execute",
|
|
255
256
|
tracer: tracers.mcp,
|
|
256
257
|
attributes: {
|
|
257
258
|
[ATTR.GEN_AI_TOOL_NAME]: toolName,
|
|
@@ -412,6 +413,15 @@ export class MCPToolRegistry extends MCPRegistry {
|
|
|
412
413
|
errMsg.includes("not executable")) {
|
|
413
414
|
throw error;
|
|
414
415
|
}
|
|
416
|
+
// Explicitly set ERROR status — we're returning (not throwing) so withSpan
|
|
417
|
+
// won't automatically detect this as an error (gap T3 fix)
|
|
418
|
+
span.setStatus({
|
|
419
|
+
code: SpanStatusCode.ERROR,
|
|
420
|
+
message: errMsg,
|
|
421
|
+
});
|
|
422
|
+
if (error instanceof Error) {
|
|
423
|
+
span.recordException(error);
|
|
424
|
+
}
|
|
415
425
|
// Return runtime execution errors in ToolResult format
|
|
416
426
|
const errorResult = {
|
|
417
427
|
success: false,
|
|
@@ -7,10 +7,13 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import { tool } from "ai";
|
|
10
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
10
11
|
import { z } from "zod";
|
|
11
12
|
import { logger } from "../utils/logger.js";
|
|
12
13
|
import { withTimeout } from "../utils/errorHandling.js";
|
|
13
14
|
import { SpanSerializer, SpanType, SpanStatus, getMetricsAggregator, } from "../observability/index.js";
|
|
15
|
+
import { withSpan } from "../telemetry/withSpan.js";
|
|
16
|
+
import { tracers } from "../telemetry/tracers.js";
|
|
14
17
|
/** Maximum characters returned per retrieval request */
|
|
15
18
|
const DEFAULT_RETRIEVAL_LIMIT = 50_000;
|
|
16
19
|
/** Hard maximum for user/LLM-supplied limit to prevent massive tool outputs */
|
|
@@ -81,154 +84,192 @@ export function createMemoryRetrievalTools(memoryManager, artifactStore) {
|
|
|
81
84
|
.describe("Regex pattern to search within message content. " +
|
|
82
85
|
"Returns matching lines with line numbers."),
|
|
83
86
|
}),
|
|
84
|
-
execute: async (args) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
87
|
+
execute: async (args) => withSpan({
|
|
88
|
+
name: "neurolink.memory.retrieve_context",
|
|
89
|
+
tracer: tracers.memory,
|
|
90
|
+
attributes: {
|
|
91
|
+
"memory.operation": args.artifactId
|
|
92
|
+
? "artifact.fetch"
|
|
93
|
+
: "session.retrieve",
|
|
94
|
+
"memory.has_artifact_id": Boolean(args.artifactId),
|
|
95
|
+
"memory.has_session_id": Boolean(args.sessionId),
|
|
96
|
+
"memory.role": args.role ?? "any",
|
|
97
|
+
"memory.search": Boolean(args.search),
|
|
98
|
+
},
|
|
99
|
+
}, async (otelSpan) => executeRetrieveContext(args, memoryManager, artifactStore, otelSpan)),
|
|
100
|
+
}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
async function executeRetrieveContext(args, memoryManager, artifactStore, otelSpan) {
|
|
104
|
+
// ── Artifact resolution path ────────────────────────────────────────
|
|
105
|
+
// When the caller supplies an artifactId we short-circuit to the
|
|
106
|
+
// artifact store (bypassing Redis) and return the full payload with
|
|
107
|
+
// optional offset/limit pagination.
|
|
108
|
+
if (args.artifactId) {
|
|
109
|
+
if (!artifactStore) {
|
|
110
|
+
logger.warn("[MemoryRetrievalTools] retrieve_context called with artifactId " +
|
|
111
|
+
"but no ArtifactStore is configured");
|
|
112
|
+
otelSpan.setStatus({
|
|
113
|
+
code: SpanStatusCode.ERROR,
|
|
114
|
+
message: "Artifact store not configured",
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
error: "Artifact store not configured — " +
|
|
118
|
+
"mcp.outputLimits.strategy must be set to 'externalize' to use artifactId retrieval",
|
|
119
|
+
artifactId: args.artifactId,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const content = await withTimeout(artifactStore.retrieve(args.artifactId), 10_000, new Error(`ArtifactStore.retrieve() timed out for artifact "${args.artifactId}"`));
|
|
123
|
+
if (content === null) {
|
|
124
|
+
otelSpan.setStatus({
|
|
125
|
+
code: SpanStatusCode.ERROR,
|
|
126
|
+
message: "Artifact not found or has expired",
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
error: "Artifact not found or has expired",
|
|
130
|
+
artifactId: args.artifactId,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const charLimit = Math.min(args.limit ?? DEFAULT_RETRIEVAL_LIMIT, MAX_RETRIEVAL_LIMIT);
|
|
134
|
+
const start = args.offset ?? 0;
|
|
135
|
+
const slice = content.slice(start, start + charLimit);
|
|
136
|
+
otelSpan.setAttribute("memory.artifact_size", content.length);
|
|
137
|
+
otelSpan.setAttribute("memory.returned_bytes", slice.length);
|
|
138
|
+
return {
|
|
139
|
+
artifactId: args.artifactId,
|
|
140
|
+
content: slice,
|
|
141
|
+
totalSize: content.length,
|
|
142
|
+
hasMore: start + charLimit < content.length,
|
|
143
|
+
offset: start,
|
|
144
|
+
limit: charLimit,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// ── End artifact resolution ─────────────────────────────────────────
|
|
148
|
+
if (!args.sessionId) {
|
|
149
|
+
otelSpan.setStatus({
|
|
150
|
+
code: SpanStatusCode.ERROR,
|
|
151
|
+
message: "sessionId is required when artifactId is not provided",
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
error: "sessionId is required when artifactId is not provided",
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (!memoryManager) {
|
|
158
|
+
otelSpan.setStatus({
|
|
159
|
+
code: SpanStatusCode.ERROR,
|
|
160
|
+
message: "Memory manager not configured",
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
error: "Session history retrieval requires Redis conversation memory — " +
|
|
164
|
+
"enable mcp.conversationMemory with a Redis backend, or use " +
|
|
165
|
+
"artifactId to retrieve an externalized MCP tool output.",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const span = SpanSerializer.createSpan(SpanType.MEMORY, "memory.retrieve", {
|
|
169
|
+
"memory.operation": "retrieve",
|
|
170
|
+
"memory.store": "redis",
|
|
171
|
+
"memory.query": args.search || args.messageId || `lastN:${args.lastN ?? "all"}`,
|
|
172
|
+
});
|
|
173
|
+
const startTime = Date.now();
|
|
174
|
+
// args.sessionId is guaranteed non-null here — we returned early above
|
|
175
|
+
// when it was missing. Cast via string coercion to satisfy eslint.
|
|
176
|
+
const sessionId = String(args.sessionId);
|
|
177
|
+
try {
|
|
178
|
+
const conversation = await withTimeout(memoryManager.getSessionRaw(sessionId), 10_000, new Error(`getSessionRaw() timed out for session "${sessionId}"`));
|
|
179
|
+
if (!conversation) {
|
|
180
|
+
const endedSpan = SpanSerializer.endSpan(span, SpanStatus.ERROR, `Session not found: ${sessionId}`);
|
|
181
|
+
getMetricsAggregator().recordSpan(endedSpan);
|
|
182
|
+
return { error: "Session not found", sessionId };
|
|
183
|
+
}
|
|
184
|
+
let messages = conversation.messages;
|
|
185
|
+
// Filter by specific messageId
|
|
186
|
+
if (args.messageId) {
|
|
187
|
+
const msg = messages.find((m) => m.id === args.messageId);
|
|
188
|
+
if (!msg) {
|
|
189
|
+
const endedSpan = SpanSerializer.endSpan(span, SpanStatus.ERROR, `Message not found: ${args.messageId}`);
|
|
190
|
+
getMetricsAggregator().recordSpan(endedSpan);
|
|
191
|
+
return { error: "Message not found", messageId: args.messageId };
|
|
192
|
+
}
|
|
193
|
+
messages = [msg];
|
|
194
|
+
}
|
|
195
|
+
// Filter by role
|
|
196
|
+
if (args.role) {
|
|
197
|
+
messages = messages.filter((m) => m.role === args.role);
|
|
198
|
+
}
|
|
199
|
+
// Take last N
|
|
200
|
+
if (args.lastN) {
|
|
201
|
+
messages = messages.slice(-args.lastN);
|
|
202
|
+
}
|
|
203
|
+
const charLimit = Math.min(args.limit ?? DEFAULT_RETRIEVAL_LIMIT, MAX_RETRIEVAL_LIMIT);
|
|
204
|
+
const results = messages.map((msg) => {
|
|
205
|
+
const content = msg.content ?? "";
|
|
206
|
+
// Search mode: return matching lines with line numbers
|
|
207
|
+
if (args.search) {
|
|
208
|
+
try {
|
|
209
|
+
const pattern = args.search;
|
|
210
|
+
// Validate regex length to mitigate ReDoS from LLM-provided input
|
|
211
|
+
if (pattern.length > 200) {
|
|
101
212
|
return {
|
|
102
|
-
|
|
103
|
-
|
|
213
|
+
id: msg.id,
|
|
214
|
+
error: "Search pattern too long (max 200 chars)",
|
|
104
215
|
};
|
|
105
216
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
217
|
+
// Treat user input as literal search to prevent ReDoS.
|
|
218
|
+
// Regex metacharacters are escaped so patterns like "foo|bar" match literally.
|
|
219
|
+
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
220
|
+
const regex = new RegExp(escaped, "i");
|
|
221
|
+
const lines = content.split("\n");
|
|
222
|
+
const matches = lines
|
|
223
|
+
.map((line, i) => ({ line: i + 1, text: line }))
|
|
224
|
+
.filter((l) => regex.test(l.text))
|
|
225
|
+
.slice(0, MAX_SEARCH_MATCHES);
|
|
109
226
|
return {
|
|
110
|
-
|
|
111
|
-
|
|
227
|
+
id: msg.id,
|
|
228
|
+
role: msg.role,
|
|
229
|
+
tool: msg.tool,
|
|
230
|
+
matchCount: matches.length,
|
|
231
|
+
matches,
|
|
112
232
|
totalSize: content.length,
|
|
113
|
-
hasMore: start + charLimit < content.length,
|
|
114
|
-
offset: start,
|
|
115
|
-
limit: charLimit,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
// ── End artifact resolution ─────────────────────────────────────────
|
|
119
|
-
if (!args.sessionId) {
|
|
120
|
-
return {
|
|
121
|
-
error: "sessionId is required when artifactId is not provided",
|
|
122
233
|
};
|
|
123
234
|
}
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
error: "Session history retrieval requires Redis conversation memory — " +
|
|
127
|
-
"enable mcp.conversationMemory with a Redis backend, or use " +
|
|
128
|
-
"artifactId to retrieve an externalized MCP tool output.",
|
|
129
|
-
};
|
|
235
|
+
catch {
|
|
236
|
+
return { id: msg.id, error: "Invalid regex pattern" };
|
|
130
237
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
const charLimit = Math.min(args.limit ?? DEFAULT_RETRIEVAL_LIMIT, MAX_RETRIEVAL_LIMIT);
|
|
169
|
-
const results = messages.map((msg) => {
|
|
170
|
-
const content = msg.content ?? "";
|
|
171
|
-
// Search mode: return matching lines with line numbers
|
|
172
|
-
if (args.search) {
|
|
173
|
-
try {
|
|
174
|
-
const pattern = args.search;
|
|
175
|
-
// Validate regex length to mitigate ReDoS from LLM-provided input
|
|
176
|
-
if (pattern.length > 200) {
|
|
177
|
-
return {
|
|
178
|
-
id: msg.id,
|
|
179
|
-
error: "Search pattern too long (max 200 chars)",
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
const regex = new RegExp(pattern, "i"); // no 'g' flag — avoids stateful .test() bug
|
|
183
|
-
const lines = content.split("\n");
|
|
184
|
-
const matches = lines
|
|
185
|
-
.map((line, i) => ({ line: i + 1, text: line }))
|
|
186
|
-
.filter((l) => regex.test(l.text))
|
|
187
|
-
.slice(0, MAX_SEARCH_MATCHES);
|
|
188
|
-
return {
|
|
189
|
-
id: msg.id,
|
|
190
|
-
role: msg.role,
|
|
191
|
-
tool: msg.tool,
|
|
192
|
-
matchCount: matches.length,
|
|
193
|
-
matches,
|
|
194
|
-
totalSize: content.length,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
catch {
|
|
198
|
-
return { id: msg.id, error: "Invalid regex pattern" };
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
// Paginated read mode
|
|
202
|
-
const start = args.offset ?? 0;
|
|
203
|
-
const end = start + charLimit;
|
|
204
|
-
const slice = content.slice(start, end);
|
|
205
|
-
return {
|
|
206
|
-
id: msg.id,
|
|
207
|
-
role: msg.role,
|
|
208
|
-
tool: msg.tool,
|
|
209
|
-
content: slice,
|
|
210
|
-
totalSize: content.length,
|
|
211
|
-
hasMore: end < content.length,
|
|
212
|
-
};
|
|
213
|
-
});
|
|
214
|
-
span.durationMs = Date.now() - startTime;
|
|
215
|
-
const endedSpan = SpanSerializer.endSpan(span, SpanStatus.OK);
|
|
216
|
-
getMetricsAggregator().recordSpan(endedSpan);
|
|
217
|
-
return { messages: results, totalMessages: results.length };
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
span.durationMs = Date.now() - startTime;
|
|
221
|
-
const endedSpan = SpanSerializer.endSpan(span, SpanStatus.ERROR);
|
|
222
|
-
endedSpan.statusMessage =
|
|
223
|
-
error instanceof Error ? error.message : String(error);
|
|
224
|
-
getMetricsAggregator().recordSpan(endedSpan);
|
|
225
|
-
logger.error("[MemoryRetrievalTools] Error retrieving context", {
|
|
226
|
-
error: error instanceof Error ? error.message : String(error),
|
|
227
|
-
});
|
|
228
|
-
return { error: "Failed to retrieve context" };
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
}),
|
|
232
|
-
};
|
|
238
|
+
}
|
|
239
|
+
// Paginated read mode
|
|
240
|
+
const start = args.offset ?? 0;
|
|
241
|
+
const end = start + charLimit;
|
|
242
|
+
const slice = content.slice(start, end);
|
|
243
|
+
return {
|
|
244
|
+
id: msg.id,
|
|
245
|
+
role: msg.role,
|
|
246
|
+
tool: msg.tool,
|
|
247
|
+
content: slice,
|
|
248
|
+
totalSize: content.length,
|
|
249
|
+
hasMore: end < content.length,
|
|
250
|
+
};
|
|
251
|
+
});
|
|
252
|
+
span.durationMs = Date.now() - startTime;
|
|
253
|
+
const endedSpan = SpanSerializer.endSpan(span, SpanStatus.OK);
|
|
254
|
+
getMetricsAggregator().recordSpan(endedSpan);
|
|
255
|
+
otelSpan.setAttribute("memory.message_count", results.length);
|
|
256
|
+
return { messages: results, totalMessages: results.length };
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
span.durationMs = Date.now() - startTime;
|
|
260
|
+
const endedSpan = SpanSerializer.endSpan(span, SpanStatus.ERROR);
|
|
261
|
+
endedSpan.statusMessage =
|
|
262
|
+
error instanceof Error ? error.message : String(error);
|
|
263
|
+
getMetricsAggregator().recordSpan(endedSpan);
|
|
264
|
+
logger.error("[MemoryRetrievalTools] Error retrieving context", {
|
|
265
|
+
error: error instanceof Error ? error.message : String(error),
|
|
266
|
+
});
|
|
267
|
+
otelSpan.setStatus({
|
|
268
|
+
code: SpanStatusCode.ERROR,
|
|
269
|
+
message: error instanceof Error ? error.message : String(error),
|
|
270
|
+
});
|
|
271
|
+
otelSpan.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
272
|
+
return { error: "Failed to retrieve context" };
|
|
273
|
+
}
|
|
233
274
|
}
|
|
234
275
|
//# sourceMappingURL=memoryRetrievalTools.js.map
|