@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
package/dist/neurolink.js
CHANGED
|
@@ -15,7 +15,7 @@ try {
|
|
|
15
15
|
catch {
|
|
16
16
|
// Environment variables should be set externally in production
|
|
17
17
|
}
|
|
18
|
-
import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
18
|
+
import { SpanKind, SpanStatusCode, context, trace } from "@opentelemetry/api";
|
|
19
19
|
import { AsyncLocalStorage } from "async_hooks";
|
|
20
20
|
import { EventEmitter } from "events";
|
|
21
21
|
import pLimit from "p-limit";
|
|
@@ -133,6 +133,29 @@ function mcpCategoryToErrorCategory(mcpCategory) {
|
|
|
133
133
|
return ErrorCategory.EXECUTION;
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Extract a human-readable error string from an MCP isError result object.
|
|
138
|
+
* Returns an empty string if nothing useful can be extracted.
|
|
139
|
+
*/
|
|
140
|
+
function extractMcpErrorText(raw) {
|
|
141
|
+
try {
|
|
142
|
+
const resultObj = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
143
|
+
if (!resultObj || typeof resultObj !== "object") {
|
|
144
|
+
return "";
|
|
145
|
+
}
|
|
146
|
+
const content = resultObj.content;
|
|
147
|
+
if (!Array.isArray(content)) {
|
|
148
|
+
return "";
|
|
149
|
+
}
|
|
150
|
+
const texts = content
|
|
151
|
+
.filter((c) => c.type === "text" && c.text)
|
|
152
|
+
.map((c) => c.text);
|
|
153
|
+
return texts.join(" ").substring(0, 500);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return "";
|
|
157
|
+
}
|
|
158
|
+
}
|
|
136
159
|
/**
|
|
137
160
|
* Check if an error is a non-retryable provider error that should immediately
|
|
138
161
|
* stop the retry/fallback chain. These errors represent permanent failures
|
|
@@ -179,6 +202,78 @@ function isNonRetryableProviderError(error) {
|
|
|
179
202
|
}
|
|
180
203
|
return false;
|
|
181
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* NeuroLink - Universal AI Development Platform
|
|
207
|
+
*
|
|
208
|
+
* Main SDK class providing unified access to 14+ AI providers with enterprise features:
|
|
209
|
+
* - Multi-provider support (OpenAI, Anthropic, Google AI Studio, Google Vertex, AWS Bedrock, etc.)
|
|
210
|
+
* - MCP (Model Context Protocol) tool integration with 58+ external servers
|
|
211
|
+
* - Human-in-the-Loop (HITL) security workflows for regulated industries
|
|
212
|
+
* - Redis-based conversation memory and persistence
|
|
213
|
+
* - Enterprise middleware system for monitoring and control
|
|
214
|
+
* - Automatic provider fallback and retry logic
|
|
215
|
+
* - Streaming with real-time token delivery
|
|
216
|
+
* - Multimodal support (text, images, PDFs, CSV)
|
|
217
|
+
*
|
|
218
|
+
* @category Core
|
|
219
|
+
*
|
|
220
|
+
* @example Basic usage
|
|
221
|
+
* ```typescript
|
|
222
|
+
* import { NeuroLink } from '@juspay/neurolink';
|
|
223
|
+
*
|
|
224
|
+
* const neurolink = new NeuroLink();
|
|
225
|
+
*
|
|
226
|
+
* const result = await neurolink.generate({
|
|
227
|
+
* input: { text: 'Explain quantum computing' },
|
|
228
|
+
* provider: 'vertex',
|
|
229
|
+
* model: 'gemini-3-flash-preview'
|
|
230
|
+
* });
|
|
231
|
+
*
|
|
232
|
+
* console.log(result.content);
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @example With HITL security
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const neurolink = new NeuroLink({
|
|
238
|
+
* hitl: {
|
|
239
|
+
* enabled: true,
|
|
240
|
+
* requireApproval: ['writeFile', 'executeCode'],
|
|
241
|
+
* confidenceThreshold: 0.85
|
|
242
|
+
* }
|
|
243
|
+
* });
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
* @example With Redis memory
|
|
247
|
+
* ```typescript
|
|
248
|
+
* const neurolink = new NeuroLink({
|
|
249
|
+
* conversationMemory: {
|
|
250
|
+
* enabled: true,
|
|
251
|
+
* redis: {
|
|
252
|
+
* url: 'redis://localhost:6379'
|
|
253
|
+
* }
|
|
254
|
+
* }
|
|
255
|
+
* });
|
|
256
|
+
* ```
|
|
257
|
+
*
|
|
258
|
+
* @example With MCP tools
|
|
259
|
+
* ```typescript
|
|
260
|
+
* const neurolink = new NeuroLink();
|
|
261
|
+
*
|
|
262
|
+
* // Discover available tools
|
|
263
|
+
* const tools = await neurolink.getAvailableTools();
|
|
264
|
+
*
|
|
265
|
+
* // Use tools in generation
|
|
266
|
+
* const result = await neurolink.generate({
|
|
267
|
+
* input: { text: 'Read the README.md file' },
|
|
268
|
+
* tools: ['readFile']
|
|
269
|
+
* });
|
|
270
|
+
* ```
|
|
271
|
+
*
|
|
272
|
+
* @see {@link GenerateOptions} for generation options
|
|
273
|
+
* @see {@link StreamOptions} for streaming options
|
|
274
|
+
* @see {@link NeurolinkConstructorConfig} for configuration options
|
|
275
|
+
* @since 1.0.0
|
|
276
|
+
*/
|
|
182
277
|
/**
|
|
183
278
|
* Module-level AsyncLocalStorage for per-request metrics trace context.
|
|
184
279
|
* Eliminates the race condition where overlapping generate/stream calls on the
|
|
@@ -396,6 +491,24 @@ export class NeuroLink {
|
|
|
396
491
|
return await callback();
|
|
397
492
|
}
|
|
398
493
|
createMetricsTraceContext() {
|
|
494
|
+
// Attempt to reuse the active OTel trace context so Pipeline B spans
|
|
495
|
+
// land in the same Langfuse trace as Pipeline A spans.
|
|
496
|
+
const activeSpan = trace.getSpan(context.active());
|
|
497
|
+
if (activeSpan) {
|
|
498
|
+
const spanCtx = activeSpan.spanContext();
|
|
499
|
+
// Only use the OTel context if it has a valid trace ID.
|
|
500
|
+
// parentSpanId stores the active span's ID as a parent reference;
|
|
501
|
+
// each Pipeline B span must generate its own unique spanId to comply
|
|
502
|
+
// with the OTel/W3C requirement that spanIds are unique per trace.
|
|
503
|
+
if (spanCtx.traceId &&
|
|
504
|
+
spanCtx.traceId !== "00000000000000000000000000000000") {
|
|
505
|
+
return {
|
|
506
|
+
traceId: spanCtx.traceId,
|
|
507
|
+
parentSpanId: spanCtx.spanId,
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
// Fallback: no active OTel context (e.g. standalone Pipeline B usage)
|
|
399
512
|
return {
|
|
400
513
|
traceId: crypto.randomUUID().replace(/-/g, ""),
|
|
401
514
|
parentSpanId: crypto.randomUUID().replace(/-/g, "").substring(0, 16),
|
|
@@ -2192,6 +2305,13 @@ Current user's request: ${currentInput}`;
|
|
|
2192
2305
|
initializeMetricsListeners() {
|
|
2193
2306
|
this.emitter.on("generation:end", ((...args) => {
|
|
2194
2307
|
const data = args[0];
|
|
2308
|
+
// A2 fix: When Pipeline A (AI SDK → @langfuse/otel) already creates a
|
|
2309
|
+
// GENERATION observation, skip the Pipeline B span to avoid duplicates.
|
|
2310
|
+
// Native providers (Bedrock, Ollama, Gemini 3) do NOT set this flag —
|
|
2311
|
+
// Pipeline B remains their only observation source.
|
|
2312
|
+
if (data.pipelineAHandled) {
|
|
2313
|
+
return;
|
|
2314
|
+
}
|
|
2195
2315
|
try {
|
|
2196
2316
|
const result = data.result;
|
|
2197
2317
|
const usage = result?.usage;
|
|
@@ -2211,10 +2331,10 @@ Current user's request: ${currentInput}`;
|
|
|
2211
2331
|
temperature: data.temperature,
|
|
2212
2332
|
maxTokens: data.maxTokens,
|
|
2213
2333
|
});
|
|
2214
|
-
//
|
|
2334
|
+
// Link to the OTel parent span; each Pipeline B span keeps its own
|
|
2335
|
+
// unique spanId to comply with OTel/W3C uniqueness requirements.
|
|
2215
2336
|
if (traceCtx) {
|
|
2216
|
-
span.
|
|
2217
|
-
span.parentSpanId = undefined;
|
|
2337
|
+
span.parentSpanId = traceCtx.parentSpanId;
|
|
2218
2338
|
}
|
|
2219
2339
|
// Mark failed generations with ERROR status so metrics count them correctly
|
|
2220
2340
|
const spanStatus = data.success === false || data.error
|
|
@@ -2222,6 +2342,19 @@ Current user's request: ${currentInput}`;
|
|
|
2222
2342
|
: SpanStatus.OK;
|
|
2223
2343
|
span = SpanSerializer.endSpan(span, spanStatus, data.error ? String(data.error) : undefined);
|
|
2224
2344
|
span.durationMs = responseTime;
|
|
2345
|
+
// G2 fix: Check finishReason and escalate to WARNING for partial failures
|
|
2346
|
+
const finishReason = result?.finishReason ??
|
|
2347
|
+
data.finishReason;
|
|
2348
|
+
if (finishReason) {
|
|
2349
|
+
span.attributes["gen_ai.finish_reason"] = finishReason;
|
|
2350
|
+
if (finishReason === "content-filter" || finishReason === "length") {
|
|
2351
|
+
span = SpanSerializer.endSpan(span, SpanStatus.WARNING, `Generation stopped: finishReason=${finishReason}`);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
// G6 fix: Record retry count on Pipeline B span
|
|
2355
|
+
if (data.retryCount !== undefined) {
|
|
2356
|
+
span.attributes["gen_ai.retry_count"] = data.retryCount;
|
|
2357
|
+
}
|
|
2225
2358
|
if (usage) {
|
|
2226
2359
|
span = SpanSerializer.enrichWithTokenUsage(span, {
|
|
2227
2360
|
promptTokens: usage.input || 0,
|
|
@@ -2283,15 +2416,24 @@ Current user's request: ${currentInput}`;
|
|
|
2283
2416
|
name: `gen_ai.${provider}.stream`,
|
|
2284
2417
|
traceId: traceCtx?.traceId,
|
|
2285
2418
|
});
|
|
2286
|
-
//
|
|
2419
|
+
// Link to the OTel parent span; keep unique spanId per W3C spec.
|
|
2287
2420
|
if (traceCtx) {
|
|
2288
|
-
span.
|
|
2289
|
-
span.parentSpanId = undefined;
|
|
2421
|
+
span.parentSpanId = traceCtx.parentSpanId;
|
|
2290
2422
|
}
|
|
2291
2423
|
span = SpanSerializer.endSpan(span, SpanStatus.OK);
|
|
2292
2424
|
span.durationMs = durationMs;
|
|
2293
2425
|
span.attributes["stream.chunk_count"] = chunkCount;
|
|
2294
2426
|
span.attributes["stream.content_length"] = totalLength;
|
|
2427
|
+
// S3 fix: Record finishReason on Pipeline B stream span
|
|
2428
|
+
const streamFinishReason = metadata?.finishReason ??
|
|
2429
|
+
data.finishReason;
|
|
2430
|
+
if (streamFinishReason) {
|
|
2431
|
+
span.attributes["gen_ai.finish_reason"] = streamFinishReason;
|
|
2432
|
+
if (streamFinishReason === "content-filter" ||
|
|
2433
|
+
streamFinishReason === "length") {
|
|
2434
|
+
span = SpanSerializer.endSpan(span, SpanStatus.WARNING, `Stream stopped: finishReason=${streamFinishReason}`);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2295
2437
|
// Record stream input prompt
|
|
2296
2438
|
if (data.prompt) {
|
|
2297
2439
|
const promptStr = String(data.prompt);
|
|
@@ -2359,9 +2501,13 @@ Current user's request: ${currentInput}`;
|
|
|
2359
2501
|
}, traceCtx?.parentSpanId, traceCtx?.traceId);
|
|
2360
2502
|
span = SpanSerializer.endSpan(span, success ? SpanStatus.OK : SpanStatus.ERROR);
|
|
2361
2503
|
span.durationMs = responseTime;
|
|
2362
|
-
if (!success
|
|
2363
|
-
|
|
2364
|
-
|
|
2504
|
+
if (!success) {
|
|
2505
|
+
if (data.error) {
|
|
2506
|
+
span.statusMessage = String(data.error);
|
|
2507
|
+
}
|
|
2508
|
+
else if (data.result) {
|
|
2509
|
+
span.statusMessage = extractMcpErrorText(data.result);
|
|
2510
|
+
}
|
|
2365
2511
|
}
|
|
2366
2512
|
if (data.result) {
|
|
2367
2513
|
try {
|
|
@@ -2395,15 +2541,22 @@ Current user's request: ${currentInput}`;
|
|
|
2395
2541
|
name: `gen_ai.${provider}.stream.error`,
|
|
2396
2542
|
traceId: traceCtx?.traceId,
|
|
2397
2543
|
});
|
|
2398
|
-
//
|
|
2544
|
+
// Link to the OTel parent span; keep unique spanId per W3C spec.
|
|
2399
2545
|
if (traceCtx) {
|
|
2400
|
-
span.
|
|
2401
|
-
span.parentSpanId = undefined;
|
|
2546
|
+
span.parentSpanId = traceCtx.parentSpanId;
|
|
2402
2547
|
}
|
|
2403
2548
|
span = SpanSerializer.endSpan(span, SpanStatus.ERROR);
|
|
2404
2549
|
span.durationMs = durationMs;
|
|
2405
2550
|
span.statusMessage = `${errorName}: ${errorMessage}`;
|
|
2406
2551
|
span.attributes["stream.chunk_count"] = chunkCount;
|
|
2552
|
+
// S7 fix: Distinguish aborts from errors
|
|
2553
|
+
const isAbort = errorName === "AbortError" ||
|
|
2554
|
+
errorMessage.toLowerCase().includes("aborted") ||
|
|
2555
|
+
errorMessage.toLowerCase().includes("abort");
|
|
2556
|
+
span.attributes["error.type"] = isAbort ? "abort" : errorName;
|
|
2557
|
+
if (isAbort) {
|
|
2558
|
+
span.attributes["stream.aborted"] = true;
|
|
2559
|
+
}
|
|
2407
2560
|
this.metricsAggregator.recordSpan(span);
|
|
2408
2561
|
getMetricsAggregator().recordSpan(span);
|
|
2409
2562
|
}
|
|
@@ -2535,6 +2688,12 @@ Current user's request: ${currentInput}`;
|
|
|
2535
2688
|
code: SpanStatusCode.ERROR,
|
|
2536
2689
|
message: error instanceof Error ? error.message : String(error),
|
|
2537
2690
|
});
|
|
2691
|
+
// G7 fix: Distinguish context overflow errors with dedicated attributes
|
|
2692
|
+
if (error instanceof ContextBudgetExceededError) {
|
|
2693
|
+
generateSpan.setAttribute("neurolink.error.type", "context_overflow");
|
|
2694
|
+
generateSpan.setAttribute("neurolink.context.estimated_tokens", error.estimatedTokens);
|
|
2695
|
+
generateSpan.setAttribute("neurolink.context.available_tokens", error.availableTokens);
|
|
2696
|
+
}
|
|
2538
2697
|
this.emitGenerateErrorEvent(optionsOrPrompt, error);
|
|
2539
2698
|
throw error;
|
|
2540
2699
|
}
|
|
@@ -2749,6 +2908,10 @@ Current user's request: ${currentInput}`;
|
|
|
2749
2908
|
prompt: options.input?.text || options.prompt,
|
|
2750
2909
|
temperature: textOptions.temperature,
|
|
2751
2910
|
maxTokens: textOptions.maxTokens,
|
|
2911
|
+
// A2 fix: Signal that Pipeline A (AI SDK → @langfuse/otel) already
|
|
2912
|
+
// creates a GENERATION observation for this call. The generation:end
|
|
2913
|
+
// listener should skip creating a duplicate Pipeline B span.
|
|
2914
|
+
pipelineAHandled: true,
|
|
2752
2915
|
});
|
|
2753
2916
|
this.emitter.emit("response:end", textResult.content || "");
|
|
2754
2917
|
this.emitter.emit("message", `Generation completed in ${Date.now() - startTime}ms`);
|
|
@@ -2797,6 +2960,12 @@ Current user's request: ${currentInput}`;
|
|
|
2797
2960
|
generateSpan.setAttribute("neurolink.tokens.input", generateResult.usage?.input || 0);
|
|
2798
2961
|
generateSpan.setAttribute("neurolink.tokens.output", generateResult.usage?.output || 0);
|
|
2799
2962
|
generateSpan.setAttribute("neurolink.finish_reason", generateResult.finishReason || "unknown");
|
|
2963
|
+
// G3 fix: Record step count and whether max steps was reached
|
|
2964
|
+
// Read steps from the raw provider result (textResult), not the flattened DTO
|
|
2965
|
+
const stepCount = textResult?.steps?.length ?? 1;
|
|
2966
|
+
const maxSteps = options.maxSteps ?? 200; // DEFAULT_MAX_STEPS
|
|
2967
|
+
generateSpan.setAttribute("neurolink.step_count", stepCount);
|
|
2968
|
+
generateSpan.setAttribute("neurolink.max_steps_reached", stepCount >= maxSteps);
|
|
2800
2969
|
generateSpan.setAttribute("neurolink.result_provider", generateResult.provider || "unknown");
|
|
2801
2970
|
generateSpan.setAttribute("neurolink.result_model", generateResult.model || "unknown");
|
|
2802
2971
|
generateSpan.setAttribute("generate.retry_count", generateResult.retries?.count || 0);
|
|
@@ -4494,6 +4663,7 @@ Current user's request: ${currentInput}`;
|
|
|
4494
4663
|
content: accumulatedContent,
|
|
4495
4664
|
provider: metadata.fallbackProvider ?? providerName,
|
|
4496
4665
|
model: metadata.fallbackModel ?? streamModel ?? enhancedOptions.model,
|
|
4666
|
+
finishReason: streamState.finishReason ?? "stop",
|
|
4497
4667
|
prompt: enhancedOptions.input?.text ||
|
|
4498
4668
|
enhancedOptions.prompt,
|
|
4499
4669
|
metadata: {
|
|
@@ -4502,6 +4672,7 @@ Current user's request: ${currentInput}`;
|
|
|
4502
4672
|
durationMs: Date.now() - streamStartTime,
|
|
4503
4673
|
sessionId,
|
|
4504
4674
|
usage: resolvedUsage,
|
|
4675
|
+
finishReason: streamState.finishReason ?? "stop",
|
|
4505
4676
|
...(metadata.fallbackAttempted && {
|
|
4506
4677
|
primaryProvider: providerName,
|
|
4507
4678
|
primaryModel: enhancedOptions.model,
|
|
@@ -5212,23 +5383,20 @@ Current user's request: ${currentInput}`;
|
|
|
5212
5383
|
logger.error("Stream generation failed, attempting fallback", {
|
|
5213
5384
|
error: error instanceof Error ? error.message : String(error),
|
|
5214
5385
|
});
|
|
5215
|
-
//
|
|
5386
|
+
// S1 fix: Emit stream:error so the Pipeline B listener creates an error span.
|
|
5387
|
+
// S8 fix: The old direct SpanSerializer.createGenerationSpan block is removed —
|
|
5388
|
+
// the stream:error listener now handles span creation, avoiding duplication.
|
|
5216
5389
|
try {
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5390
|
+
this.emitter.emit("stream:error", {
|
|
5391
|
+
content: error instanceof Error ? error.message : String(error),
|
|
5392
|
+
metadata: {
|
|
5393
|
+
errorName: error instanceof Error ? error.name : "UnknownError",
|
|
5394
|
+
durationMs: Date.now() - startTime,
|
|
5395
|
+
chunkCount: 0,
|
|
5396
|
+
},
|
|
5397
|
+
provider: options.provider || "unknown",
|
|
5221
5398
|
model: options.model || "unknown",
|
|
5222
|
-
name: `gen_ai.${failedProvider}.stream.failed`,
|
|
5223
|
-
traceId: traceCtx?.traceId,
|
|
5224
|
-
parentSpanId: traceCtx?.parentSpanId,
|
|
5225
5399
|
});
|
|
5226
|
-
failedSpan = SpanSerializer.endSpan(failedSpan, SpanStatus.ERROR);
|
|
5227
|
-
failedSpan.statusMessage =
|
|
5228
|
-
error instanceof Error ? error.message : String(error);
|
|
5229
|
-
failedSpan.durationMs = Date.now() - startTime;
|
|
5230
|
-
this.metricsAggregator.recordSpan(failedSpan);
|
|
5231
|
-
getMetricsAggregator().recordSpan(failedSpan);
|
|
5232
5400
|
}
|
|
5233
5401
|
catch {
|
|
5234
5402
|
/* non-blocking */
|
|
@@ -5267,6 +5435,25 @@ Current user's request: ${currentInput}`;
|
|
|
5267
5435
|
responseTimeMs: Date.now() - startTime,
|
|
5268
5436
|
contentLength: fallbackAccumulatedContent.length,
|
|
5269
5437
|
});
|
|
5438
|
+
// S6 fix: Emit stream:complete after successful fallback so Pipeline B records it
|
|
5439
|
+
try {
|
|
5440
|
+
self.emitter.emit("stream:complete", {
|
|
5441
|
+
content: fallbackAccumulatedContent,
|
|
5442
|
+
provider: providerName,
|
|
5443
|
+
model: options.model || "unknown",
|
|
5444
|
+
finishReason: "stop",
|
|
5445
|
+
metadata: {
|
|
5446
|
+
durationMs: Date.now() - startTime,
|
|
5447
|
+
chunkCount: 0,
|
|
5448
|
+
totalLength: fallbackAccumulatedContent.length,
|
|
5449
|
+
isFallback: true,
|
|
5450
|
+
finishReason: "stop",
|
|
5451
|
+
},
|
|
5452
|
+
});
|
|
5453
|
+
}
|
|
5454
|
+
catch {
|
|
5455
|
+
/* non-blocking */
|
|
5456
|
+
}
|
|
5270
5457
|
}
|
|
5271
5458
|
// Store memory after fallback stream consumption is complete
|
|
5272
5459
|
// Guard: skip storing if fallback accumulated content is empty
|
|
@@ -6194,6 +6381,7 @@ Current user's request: ${currentInput}`;
|
|
|
6194
6381
|
};
|
|
6195
6382
|
}
|
|
6196
6383
|
async runPreparedToolExecution(toolName, params, prepared, executionContext, toolSpan) {
|
|
6384
|
+
let toolRetryCount = 0;
|
|
6197
6385
|
try {
|
|
6198
6386
|
mcpLogger.debug(`[${executionContext.functionTag}] Executing tool: ${toolName}`, {
|
|
6199
6387
|
toolName,
|
|
@@ -6207,6 +6395,7 @@ Current user's request: ${currentInput}`;
|
|
|
6207
6395
|
delayMs: prepared.finalOptions.retryDelayMs,
|
|
6208
6396
|
isRetriable: isRetriableError,
|
|
6209
6397
|
onRetry: (attempt, error) => {
|
|
6398
|
+
toolRetryCount = attempt;
|
|
6210
6399
|
mcpLogger.warn(`[${executionContext.functionTag}] Retrying tool execution (attempt ${attempt})`, {
|
|
6211
6400
|
toolName,
|
|
6212
6401
|
error: error.message,
|
|
@@ -6215,9 +6404,12 @@ Current user's request: ${currentInput}`;
|
|
|
6215
6404
|
},
|
|
6216
6405
|
});
|
|
6217
6406
|
});
|
|
6407
|
+
toolSpan.setAttribute("tool.retry_count", toolRetryCount);
|
|
6218
6408
|
return await this.handleSuccessfulToolExecution(toolName, result, prepared, executionContext, toolSpan);
|
|
6219
6409
|
}
|
|
6220
6410
|
catch (error) {
|
|
6411
|
+
// Ensure retry count is recorded even on failure
|
|
6412
|
+
toolSpan.setAttribute("tool.retry_count", toolRetryCount);
|
|
6221
6413
|
return this.handleFailedToolExecution(toolName, params, error, prepared, executionContext, toolSpan);
|
|
6222
6414
|
}
|
|
6223
6415
|
}
|
|
@@ -6251,6 +6443,18 @@ Current user's request: ${currentInput}`;
|
|
|
6251
6443
|
: undefined;
|
|
6252
6444
|
const isToolError = (resultObj && "isError" in resultObj && resultObj.isError === true) ||
|
|
6253
6445
|
(resultObj && "success" in resultObj && resultObj.success === false);
|
|
6446
|
+
const contentArr = isToolError
|
|
6447
|
+
? resultObj?.content
|
|
6448
|
+
: undefined;
|
|
6449
|
+
const errorText = isToolError
|
|
6450
|
+
? contentArr
|
|
6451
|
+
?.filter((content) => content.type === "text" && content.text)
|
|
6452
|
+
.map((content) => content.text)
|
|
6453
|
+
.join(" ") ||
|
|
6454
|
+
(typeof resultObj?.error === "string"
|
|
6455
|
+
? resultObj.error
|
|
6456
|
+
: "Unknown error")
|
|
6457
|
+
: undefined;
|
|
6254
6458
|
if (isToolError) {
|
|
6255
6459
|
try {
|
|
6256
6460
|
await prepared.circuitBreaker.execute(async () => {
|
|
@@ -6265,15 +6469,7 @@ Current user's request: ${currentInput}`;
|
|
|
6265
6469
|
circuitBreakerState: prepared.circuitBreaker.getState(),
|
|
6266
6470
|
circuitBreakerFailures: prepared.circuitBreaker.getFailureCount(),
|
|
6267
6471
|
});
|
|
6268
|
-
const
|
|
6269
|
-
const errorText = contentArr
|
|
6270
|
-
?.filter((content) => content.type === "text" && content.text)
|
|
6271
|
-
.map((content) => content.text)
|
|
6272
|
-
.join(" ") ||
|
|
6273
|
-
(typeof resultObj?.error === "string"
|
|
6274
|
-
? resultObj.error
|
|
6275
|
-
: "Unknown error");
|
|
6276
|
-
const errorCategory = classifyMcpErrorMessage(errorText);
|
|
6472
|
+
const errorCategory = classifyMcpErrorMessage(errorText ?? "Unknown error");
|
|
6277
6473
|
const prefix = `[TOOL_ERROR: ${toolName} failed (${errorCategory})] `;
|
|
6278
6474
|
if (resultObj && Array.isArray(contentArr)) {
|
|
6279
6475
|
const clonedContent = contentArr.map((content) => ({ ...content }));
|
|
@@ -6285,11 +6481,11 @@ Current user's request: ${currentInput}`;
|
|
|
6285
6481
|
}
|
|
6286
6482
|
resultObj.content = clonedContent;
|
|
6287
6483
|
}
|
|
6288
|
-
toolSpan.setAttribute("tool.error.message", errorText.substring(0, 500));
|
|
6484
|
+
toolSpan.setAttribute("tool.error.message", (errorText ?? "Unknown error").substring(0, 500));
|
|
6289
6485
|
toolSpan.setAttribute("tool.error.category", errorCategory);
|
|
6290
6486
|
toolSpan.setStatus({
|
|
6291
6487
|
code: SpanStatusCode.ERROR,
|
|
6292
|
-
message: `MCP tool returned isError: ${errorText.substring(0, 200)}`,
|
|
6488
|
+
message: `MCP tool returned isError: ${(errorText ?? "Unknown error").substring(0, 200)}`,
|
|
6293
6489
|
});
|
|
6294
6490
|
prepared.metrics.failedExecutions++;
|
|
6295
6491
|
const prevSuccessful = prepared.metrics.successfulExecutions;
|
|
@@ -6304,7 +6500,7 @@ Current user's request: ${currentInput}`;
|
|
|
6304
6500
|
prepared.metrics.errorCategories[mappedCategory] =
|
|
6305
6501
|
(prepared.metrics.errorCategories[mappedCategory] || 0) + 1;
|
|
6306
6502
|
}
|
|
6307
|
-
this.emitToolEndEvent(toolName, executionContext.executionStartTime, !isToolError, result);
|
|
6503
|
+
this.emitToolEndEvent(toolName, executionContext.executionStartTime, !isToolError, result, isToolError && errorText ? new Error(errorText) : undefined);
|
|
6308
6504
|
toolSpan.setAttribute("tool.result.status", isToolError ? "error" : "success");
|
|
6309
6505
|
toolSpan.setAttribute("tool.duration_ms", executionTime);
|
|
6310
6506
|
return result;
|
|
@@ -6323,7 +6519,7 @@ Current user's request: ${currentInput}`;
|
|
|
6323
6519
|
});
|
|
6324
6520
|
prepared.metrics.errorCategories[ErrorCategory.EXECUTION] =
|
|
6325
6521
|
(prepared.metrics.errorCategories[ErrorCategory.EXECUTION] || 0) + 1;
|
|
6326
|
-
this.emitToolEndEvent(toolName, executionContext.executionStartTime, false, undefined);
|
|
6522
|
+
this.emitToolEndEvent(toolName, executionContext.executionStartTime, false, undefined, new Error(`Circuit breaker open for ${toolName} (state=${error.breakerState}, failures=${error.failureCount})`));
|
|
6327
6523
|
toolSpan.setAttribute("tool.result.status", "circuit_breaker_open");
|
|
6328
6524
|
toolSpan.setAttribute("tool.duration_ms", executionTime);
|
|
6329
6525
|
toolSpan.setAttribute("tool.circuit_breaker.state", error.breakerState);
|
|
@@ -3,24 +3,7 @@
|
|
|
3
3
|
* Manages multiple observability exporters with circuit breaker protection
|
|
4
4
|
*/
|
|
5
5
|
import type { BaseExporter } from "./exporters/baseExporter.js";
|
|
6
|
-
import type { ExporterHealthStatus,
|
|
7
|
-
/**
|
|
8
|
-
* Circuit breaker state for an exporter
|
|
9
|
-
*/
|
|
10
|
-
type CircuitBreakerState = {
|
|
11
|
-
failures: number;
|
|
12
|
-
lastFailure: number;
|
|
13
|
-
state: "closed" | "open" | "half-open";
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Circuit breaker configuration
|
|
17
|
-
*/
|
|
18
|
-
type CircuitBreakerConfig = {
|
|
19
|
-
/** Number of failures before opening the circuit */
|
|
20
|
-
failureThreshold: number;
|
|
21
|
-
/** Time in ms to wait before trying half-open state */
|
|
22
|
-
resetTimeout: number;
|
|
23
|
-
};
|
|
6
|
+
import type { ExportResult, ExporterHealthStatus, ObservabilityCircuitBreakerConfig, ObservabilityCircuitBreakerState, Sampler, SpanData } from "../types/index.js";
|
|
24
7
|
/**
|
|
25
8
|
* Registry for managing multiple observability exporters
|
|
26
9
|
* Includes circuit breaker protection to prevent cascading failures
|
|
@@ -71,7 +54,7 @@ export declare class ExporterRegistry {
|
|
|
71
54
|
* Configure the circuit breaker settings
|
|
72
55
|
* @param config - Partial circuit breaker configuration
|
|
73
56
|
*/
|
|
74
|
-
configureCircuitBreaker(config: Partial<
|
|
57
|
+
configureCircuitBreaker(config: Partial<ObservabilityCircuitBreakerConfig>): void;
|
|
75
58
|
/**
|
|
76
59
|
* Check if circuit is open for an exporter
|
|
77
60
|
* @param exporterName - Name of the exporter
|
|
@@ -94,7 +77,7 @@ export declare class ExporterRegistry {
|
|
|
94
77
|
* @param exporterName - Name of the exporter
|
|
95
78
|
* @returns Circuit breaker state or undefined if not tracked
|
|
96
79
|
*/
|
|
97
|
-
getCircuitBreakerStatus(exporterName: string):
|
|
80
|
+
getCircuitBreakerStatus(exporterName: string): ObservabilityCircuitBreakerState | undefined;
|
|
98
81
|
/**
|
|
99
82
|
* Reset circuit breaker for an exporter
|
|
100
83
|
* @param exporterName - Name of the exporter
|
|
@@ -148,4 +131,3 @@ export declare function getExporterRegistry(): ExporterRegistry;
|
|
|
148
131
|
* Reset the global exporter registry (for testing)
|
|
149
132
|
*/
|
|
150
133
|
export declare function resetExporterRegistry(): void;
|
|
151
|
-
export {};
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { logger } from "../../utils/logger.js";
|
|
6
6
|
import { SpanStatus } from "../../types/index.js";
|
|
7
7
|
import { BaseExporter } from "./baseExporter.js";
|
|
8
|
+
// Sentry types - optional dependency
|
|
8
9
|
/**
|
|
9
10
|
* Sentry exporter for error tracking and performance monitoring
|
|
10
11
|
* Captures AI errors as exceptions and traces as transactions
|
|
@@ -1,34 +1,5 @@
|
|
|
1
1
|
import { TokenTracker } from "./tokenTracker.js";
|
|
2
|
-
import type {
|
|
3
|
-
/**
|
|
4
|
-
* Time window statistics
|
|
5
|
-
*/
|
|
6
|
-
type TimeWindowStats = {
|
|
7
|
-
windowStart: Date;
|
|
8
|
-
windowEnd: Date;
|
|
9
|
-
windowDurationMs: number;
|
|
10
|
-
requestCount: number;
|
|
11
|
-
errorCount: number;
|
|
12
|
-
successRate: number;
|
|
13
|
-
throughput: number;
|
|
14
|
-
latency: LatencyStats;
|
|
15
|
-
tokens: TokenUsageStats;
|
|
16
|
-
costByProvider: Map<string, ProviderCostStats>;
|
|
17
|
-
costByModel: Map<string, ModelCostStats>;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Configuration for the metrics aggregator
|
|
21
|
-
*/
|
|
22
|
-
type MetricsAggregatorConfig = {
|
|
23
|
-
/** Maximum spans to retain in memory */
|
|
24
|
-
maxSpansRetained?: number;
|
|
25
|
-
/** Enable time-window statistics */
|
|
26
|
-
enableTimeWindows?: boolean;
|
|
27
|
-
/** Time window size in milliseconds (default: 60000 = 1 minute) */
|
|
28
|
-
timeWindowMs?: number;
|
|
29
|
-
/** Maximum time windows to retain */
|
|
30
|
-
maxTimeWindows?: number;
|
|
31
|
-
};
|
|
2
|
+
import type { LatencyStats, MetricsAggregatorConfig, MetricsSummary, ModelCostStats, ProviderCostStats, SpanData, TimeWindowStats, TokenUsageStats, TraceView } from "../types/index.js";
|
|
32
3
|
/**
|
|
33
4
|
* Metrics Aggregator for comprehensive telemetry analysis
|
|
34
5
|
* Provides latency percentiles, token aggregation, and cost tracking
|
|
@@ -153,4 +124,3 @@ export declare function getMetricsAggregator(): MetricsAggregator;
|
|
|
153
124
|
* Reset the global metrics aggregator (for testing)
|
|
154
125
|
*/
|
|
155
126
|
export declare function resetMetricsAggregator(): void;
|
|
156
|
-
export {};
|
|
@@ -2,15 +2,7 @@
|
|
|
2
2
|
* Token Usage Tracker
|
|
3
3
|
* Aggregates token usage and cost across spans
|
|
4
4
|
*/
|
|
5
|
-
import type { SpanData, TokenUsageStats } from "../types/index.js";
|
|
6
|
-
/**
|
|
7
|
-
* Model pricing information
|
|
8
|
-
*/
|
|
9
|
-
type ModelPricing = {
|
|
10
|
-
inputPricePerMillion: number;
|
|
11
|
-
outputPricePerMillion: number;
|
|
12
|
-
cachedInputPricePerMillion?: number;
|
|
13
|
-
};
|
|
5
|
+
import type { ObservabilityModelPricing, SpanData, TokenUsageStats } from "../types/index.js";
|
|
14
6
|
/**
|
|
15
7
|
* Token tracker for aggregating usage across spans
|
|
16
8
|
*/
|
|
@@ -22,30 +14,30 @@ export declare class TokenTracker {
|
|
|
22
14
|
* @param modelName - The model name (e.g., "gpt-4o", "claude-3-5-sonnet")
|
|
23
15
|
* @param pricing - The pricing information
|
|
24
16
|
*/
|
|
25
|
-
|
|
17
|
+
setObservabilityModelPricing(modelName: string, pricing: ObservabilityModelPricing): void;
|
|
26
18
|
/**
|
|
27
|
-
* Update pricing for an existing model (alias for
|
|
19
|
+
* Update pricing for an existing model (alias for setObservabilityModelPricing)
|
|
28
20
|
* @param model - The model name
|
|
29
21
|
* @param pricing - The new pricing information
|
|
30
22
|
*/
|
|
31
|
-
updatePricing(model: string, pricing:
|
|
23
|
+
updatePricing(model: string, pricing: ObservabilityModelPricing): void;
|
|
32
24
|
/**
|
|
33
25
|
* Load pricing configuration from a config object
|
|
34
26
|
* Useful for loading pricing from environment or config files
|
|
35
27
|
* @param config - Record of model names to pricing information
|
|
36
28
|
*/
|
|
37
|
-
loadPricingFromConfig(config: Record<string,
|
|
29
|
+
loadPricingFromConfig(config: Record<string, ObservabilityModelPricing>): void;
|
|
38
30
|
/**
|
|
39
31
|
* Get pricing for a specific model
|
|
40
32
|
* @param model - The model name
|
|
41
33
|
* @returns The pricing information or undefined if not found
|
|
42
34
|
*/
|
|
43
|
-
getModelPricing(model: string):
|
|
35
|
+
getModelPricing(model: string): ObservabilityModelPricing | undefined;
|
|
44
36
|
/**
|
|
45
37
|
* Get all available model pricing (custom + built-in)
|
|
46
38
|
* @returns Record of all model pricing
|
|
47
39
|
*/
|
|
48
|
-
getAllPricing(): Record<string,
|
|
40
|
+
getAllPricing(): Record<string, ObservabilityModelPricing>;
|
|
49
41
|
/**
|
|
50
42
|
* Remove custom pricing for a model (falls back to built-in)
|
|
51
43
|
* @param model - The model name to remove custom pricing for
|
|
@@ -115,4 +107,3 @@ export declare function getTokenTracker(): TokenTracker;
|
|
|
115
107
|
* Reset the global token tracker (for testing)
|
|
116
108
|
*/
|
|
117
109
|
export declare function resetTokenTracker(): void;
|
|
118
|
-
export {};
|
|
@@ -88,11 +88,11 @@ export class TokenTracker {
|
|
|
88
88
|
* @param modelName - The model name (e.g., "gpt-4o", "claude-3-5-sonnet")
|
|
89
89
|
* @param pricing - The pricing information
|
|
90
90
|
*/
|
|
91
|
-
|
|
91
|
+
setObservabilityModelPricing(modelName, pricing) {
|
|
92
92
|
this.customPricing.set(modelName, pricing);
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
|
-
* Update pricing for an existing model (alias for
|
|
95
|
+
* Update pricing for an existing model (alias for setObservabilityModelPricing)
|
|
96
96
|
* @param model - The model name
|
|
97
97
|
* @param pricing - The new pricing information
|
|
98
98
|
*/
|
|
@@ -122,7 +122,9 @@ export class TokenTracker {
|
|
|
122
122
|
* @returns Record of all model pricing
|
|
123
123
|
*/
|
|
124
124
|
getAllPricing() {
|
|
125
|
-
const allPricing = {
|
|
125
|
+
const allPricing = {
|
|
126
|
+
...MODEL_PRICING,
|
|
127
|
+
};
|
|
126
128
|
// Custom pricing takes precedence
|
|
127
129
|
const customPricingEntries = Array.from(this.customPricing.entries());
|
|
128
130
|
for (const [model, pricing] of customPricingEntries) {
|
|
@@ -298,7 +300,7 @@ export class TokenTracker {
|
|
|
298
300
|
const tracker = new TokenTracker();
|
|
299
301
|
// Copy custom pricing so windowed calculations use the same rates
|
|
300
302
|
for (const [model, pricing] of this.customPricing) {
|
|
301
|
-
tracker.
|
|
303
|
+
tracker.setObservabilityModelPricing(model, pricing);
|
|
302
304
|
}
|
|
303
305
|
for (const span of spans) {
|
|
304
306
|
tracker.trackSpan(span);
|
|
@@ -8,7 +8,11 @@ import { type LangfuseSpan, type LangSmithRun, type OtelSpan, type SpanAttribute
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class SpanSerializer {
|
|
10
10
|
/**
|
|
11
|
-
* Create a new span with generated IDs
|
|
11
|
+
* Create a new span with generated IDs.
|
|
12
|
+
*
|
|
13
|
+
* When `traceId` / `parentSpanId` are omitted, the method automatically
|
|
14
|
+
* attempts to inherit them from the active OTel context so that Pipeline B
|
|
15
|
+
* spans land inside the same Langfuse trace as Pipeline A spans (fix A5).
|
|
12
16
|
*/
|
|
13
17
|
static createSpan(type: SpanType, name: string, attributes?: Partial<SpanAttributes>, parentSpanId?: string, traceId?: string): SpanData;
|
|
14
18
|
/**
|