@juspay/neurolink 9.54.6 → 9.54.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -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 +358 -358
- 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 +96 -26
- package/dist/lib/providers/googleVertex.js +66 -27
- 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 +96 -26
- package/dist/providers/googleVertex.js +66 -27
- 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 -8
|
@@ -15,6 +15,8 @@ import { join } from "node:path";
|
|
|
15
15
|
import { buildStableClaudeCodeBillingHeader, CLAUDE_CLI_USER_AGENT, CLAUDE_CODE_OAUTH_BETAS, getOrCreateClaudeCodeIdentity, parseClaudeCodeUserId, } from "../../auth/anthropicOAuth.js";
|
|
16
16
|
import { parseQuotaHeaders, saveAccountQuota, } from "../../proxy/accountQuota.js";
|
|
17
17
|
import { buildClaudeError, ClaudeStreamSerializer, generateToolUseId, parseClaudeRequest, serializeClaudeResponse, } from "../../proxy/claudeFormat.js";
|
|
18
|
+
import { tracers } from "../../telemetry/tracers.js";
|
|
19
|
+
import { withSpan } from "../../telemetry/withSpan.js";
|
|
18
20
|
import { ProxyTracer, recordFallbackAttempt } from "../../proxy/proxyTracer.js";
|
|
19
21
|
import { createRawStreamCapture } from "../../proxy/rawStreamCapture.js";
|
|
20
22
|
import { logBodyCapture, logRequest, logRequestAttempt, logStreamError, } from "../../proxy/requestLogger.js";
|
|
@@ -51,7 +53,7 @@ const MAX_TRANSIENT_SAME_ACCOUNT_RETRIES = 2;
|
|
|
51
53
|
const TRANSIENT_SAME_ACCOUNT_RETRY_DELAYS_MS = [250, 1_000];
|
|
52
54
|
/** Maximum upstream 429 attempts per account before rotating to the next account.
|
|
53
55
|
* Total attempts per account = this + 1 (the initial call plus this many retries). */
|
|
54
|
-
const MAX_RATE_LIMIT_SAME_ACCOUNT_RETRIES =
|
|
56
|
+
const MAX_RATE_LIMIT_SAME_ACCOUNT_RETRIES = 10;
|
|
55
57
|
/** Max time to sleep between 429 retries. Caps large upstream retry-after values
|
|
56
58
|
* so we don't hold the client connection open for minutes. */
|
|
57
59
|
const MAX_RATE_LIMIT_RETRY_DELAY_MS = 30_000;
|
|
@@ -62,6 +64,10 @@ const UPSTREAM_FETCH_TIMEOUT_MS = 15 * 60 * 1000; // 15 minutes
|
|
|
62
64
|
const accountRuntimeState = new Map();
|
|
63
65
|
/** Track whether we've run the one-time startup prune. */
|
|
64
66
|
let startupPruneDone = false;
|
|
67
|
+
/** Default cooling period when retries are exhausted and upstream didn't
|
|
68
|
+
* provide a retry-after header. Short enough to recover quickly, long
|
|
69
|
+
* enough to avoid immediately hammering the same account. */
|
|
70
|
+
const DEFAULT_COOLING_PERIOD_MS = 60_000;
|
|
65
71
|
/** Advance the primary account index when the current primary is exhausted
|
|
66
72
|
* (429 retries exhausted or auth failure). This is what makes fill-first work:
|
|
67
73
|
* we stick to one account until it's unusable. Only advances when the exhausted
|
|
@@ -76,6 +82,33 @@ function advancePrimaryIfCurrent(accountKey, enabledCount, primaryAccountKey) {
|
|
|
76
82
|
}
|
|
77
83
|
primaryAccountIndex = (primaryAccountIndex + 1) % enabledCount;
|
|
78
84
|
}
|
|
85
|
+
/** If the configured home primary (index 0) is no longer cooling, reset
|
|
86
|
+
* primaryAccountIndex back to 0 so traffic returns to the preferred account
|
|
87
|
+
* once its rate limit window expires. Called at the start of each request. */
|
|
88
|
+
function maybeResetPrimaryToHome(enabledAccounts) {
|
|
89
|
+
if (enabledAccounts.length <= 1 || primaryAccountIndex === 0) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const homeState = accountRuntimeState.get(enabledAccounts[0].key);
|
|
93
|
+
if (!homeState ||
|
|
94
|
+
!homeState.coolingUntil ||
|
|
95
|
+
Date.now() >= homeState.coolingUntil) {
|
|
96
|
+
// Home account is no longer cooling — reset to it
|
|
97
|
+
primaryAccountIndex = 0;
|
|
98
|
+
if (homeState?.coolingUntil) {
|
|
99
|
+
homeState.coolingUntil = undefined;
|
|
100
|
+
logger.always(`[proxy] home primary account=${enabledAccounts[0].label} cooling expired, resetting primaryAccountIndex to 0`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Check if an account is currently in its cooling window. */
|
|
105
|
+
function isAccountCooling(accountKey) {
|
|
106
|
+
const state = accountRuntimeState.get(accountKey);
|
|
107
|
+
return !!state?.coolingUntil && Date.now() < state.coolingUntil;
|
|
108
|
+
}
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// OAuth polyfill helpers (extracted to reduce block nesting)
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
79
112
|
const snapshotCache = new Map();
|
|
80
113
|
const SNAPSHOT_CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
81
114
|
const SNAPSHOT_STABLE_HEADERS = new Set([
|
|
@@ -2204,6 +2237,32 @@ async function handleAnthropicAuthRetry(args) {
|
|
|
2204
2237
|
}
|
|
2205
2238
|
const retryStatus = retryResp.status;
|
|
2206
2239
|
const retryBody = await retryResp.text();
|
|
2240
|
+
// Capture full response headers and body for all auth-retry errors.
|
|
2241
|
+
// Redact sensitive headers and cap body size before persisting.
|
|
2242
|
+
const retryRespHeaders = {};
|
|
2243
|
+
retryResp.headers.forEach((value, key) => {
|
|
2244
|
+
retryRespHeaders[key] = value;
|
|
2245
|
+
});
|
|
2246
|
+
const safeRetryHeaders = { ...retryRespHeaders };
|
|
2247
|
+
delete safeRetryHeaders["authorization"];
|
|
2248
|
+
delete safeRetryHeaders["x-api-key"];
|
|
2249
|
+
const cappedRetryBody = retryBody.length > 4000
|
|
2250
|
+
? retryBody.slice(0, 4000) + "...[truncated]"
|
|
2251
|
+
: retryBody;
|
|
2252
|
+
tracer?.logUpstreamResponseHeaders(safeRetryHeaders);
|
|
2253
|
+
tracer?.logUpstreamResponseBody(cappedRetryBody);
|
|
2254
|
+
logProxyBody({
|
|
2255
|
+
phase: "upstream_response",
|
|
2256
|
+
headers: safeRetryHeaders,
|
|
2257
|
+
body: cappedRetryBody,
|
|
2258
|
+
bodySize: Buffer.byteLength(retryBody, "utf8"),
|
|
2259
|
+
contentType: retryRespHeaders["content-type"] ?? "application/json",
|
|
2260
|
+
account: account.label,
|
|
2261
|
+
accountType: account.type,
|
|
2262
|
+
attempt: attemptNumber,
|
|
2263
|
+
responseStatus: retryStatus,
|
|
2264
|
+
durationMs: Date.now() - fetchStartMs,
|
|
2265
|
+
});
|
|
2207
2266
|
authRetryError = `retry ${authRetry + 1}/${MAX_AUTH_RETRIES} failed with status ${retryStatus}`;
|
|
2208
2267
|
currentLastError = retryBody;
|
|
2209
2268
|
logger.debug(`[proxy] retry ${authRetry + 1} failed: ${retryStatus} ${retryBody.substring(0, 120)}`);
|
|
@@ -2775,7 +2834,7 @@ async function prepareAnthropicAccountAttempt(args) {
|
|
|
2775
2834
|
};
|
|
2776
2835
|
}
|
|
2777
2836
|
async function fetchAnthropicAccountResponse(args) {
|
|
2778
|
-
const { url, headers, finalBodyStr, account, accountState: _accountState2, enabledAccounts: _enabledAccounts, orderedAccounts: _orderedAccounts, tracer, logAttempt, currentLastError, currentSawRateLimit, currentSawNetworkError, upstreamSpan, } = args;
|
|
2837
|
+
const { url, headers, finalBodyStr, account, accountState: _accountState2, enabledAccounts: _enabledAccounts, orderedAccounts: _orderedAccounts, tracer, logAttempt, logProxyBody, fetchStartMs, attemptNumber, currentLastError, currentSawRateLimit, currentSawNetworkError, upstreamSpan, } = args;
|
|
2779
2838
|
let lastError = currentLastError;
|
|
2780
2839
|
let sawRateLimit = currentSawRateLimit;
|
|
2781
2840
|
let sawNetworkError = currentSawNetworkError;
|
|
@@ -2816,8 +2875,35 @@ async function fetchAnthropicAccountResponse(args) {
|
|
|
2816
2875
|
sawRateLimit = true;
|
|
2817
2876
|
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
|
|
2818
2877
|
recordAttemptError(account.label, account.type, 429);
|
|
2878
|
+
// Capture full response headers and body for diagnostics (parity with
|
|
2879
|
+
// handleAnthropicNonOkResponse which does this for all other error statuses).
|
|
2880
|
+
const errRespHeaders = {};
|
|
2881
|
+
response.headers.forEach((value, key) => {
|
|
2882
|
+
errRespHeaders[key] = value;
|
|
2883
|
+
});
|
|
2819
2884
|
lastError = await response.text();
|
|
2820
|
-
|
|
2885
|
+
// Redact sensitive headers and cap body before persisting
|
|
2886
|
+
const safe429Headers = { ...errRespHeaders };
|
|
2887
|
+
delete safe429Headers["authorization"];
|
|
2888
|
+
delete safe429Headers["x-api-key"];
|
|
2889
|
+
const capped429Body = String(lastError).length > 4000
|
|
2890
|
+
? String(lastError).slice(0, 4000) + "...[truncated]"
|
|
2891
|
+
: String(lastError);
|
|
2892
|
+
tracer?.logUpstreamResponseHeaders(safe429Headers);
|
|
2893
|
+
tracer?.logUpstreamResponseBody(capped429Body);
|
|
2894
|
+
logProxyBody({
|
|
2895
|
+
phase: "upstream_response",
|
|
2896
|
+
headers: safe429Headers,
|
|
2897
|
+
body: capped429Body,
|
|
2898
|
+
bodySize: Buffer.byteLength(String(lastError), "utf8"),
|
|
2899
|
+
contentType: errRespHeaders["content-type"] ?? "application/json",
|
|
2900
|
+
account: account.label,
|
|
2901
|
+
accountType: account.type,
|
|
2902
|
+
attempt: attemptNumber,
|
|
2903
|
+
responseStatus: 429,
|
|
2904
|
+
durationMs: Date.now() - fetchStartMs,
|
|
2905
|
+
});
|
|
2906
|
+
logger.always(`[proxy] ← 429 account=${account.label} retry-after=${retryAfterMs}ms (upstream) ratelimit-status=${errRespHeaders["anthropic-ratelimit-unified-status"] ?? "unknown"}`);
|
|
2821
2907
|
logAttempt(429, "rate_limit_error", String(lastError));
|
|
2822
2908
|
tracer?.setError("rate_limit_error", String(lastError).slice(0, 500));
|
|
2823
2909
|
tracer?.recordRetry(account.label, "rate_limit");
|
|
@@ -2866,9 +2952,13 @@ async function handleAnthropicRoutedClaudeRequest(args) {
|
|
|
2866
2952
|
attemptNumber: 0,
|
|
2867
2953
|
};
|
|
2868
2954
|
const acctSelectionSpan = tracer?.startAccountSelection();
|
|
2869
|
-
//
|
|
2870
|
-
|
|
2871
|
-
|
|
2955
|
+
// Try to return to the home primary account if its cooling has expired.
|
|
2956
|
+
maybeResetPrimaryToHome(enabledAccounts);
|
|
2957
|
+
// Skip accounts that are still cooling from a recent 429-exhaustion,
|
|
2958
|
+
// but keep them as last-resort if ALL accounts are cooling.
|
|
2959
|
+
const nonCoolingAccounts = orderedAccounts.filter((a) => !isAccountCooling(a.key));
|
|
2960
|
+
const effectiveAccounts = nonCoolingAccounts.length > 0 ? nonCoolingAccounts : orderedAccounts;
|
|
2961
|
+
accountLoop: for (const account of effectiveAccounts) {
|
|
2872
2962
|
const accountState = getOrCreateRuntimeState(account.key);
|
|
2873
2963
|
let transientSameAccountRetries = 0;
|
|
2874
2964
|
let rateLimitSameAccountRetries = 0;
|
|
@@ -2926,6 +3016,9 @@ async function handleAnthropicRoutedClaudeRequest(args) {
|
|
|
2926
3016
|
orderedAccounts,
|
|
2927
3017
|
tracer,
|
|
2928
3018
|
logAttempt,
|
|
3019
|
+
logProxyBody,
|
|
3020
|
+
fetchStartMs: preparedAttempt.fetchStartMs,
|
|
3021
|
+
attemptNumber: loopState.attemptNumber,
|
|
2929
3022
|
currentLastError: loopState.lastError,
|
|
2930
3023
|
currentSawRateLimit: loopState.sawRateLimit,
|
|
2931
3024
|
currentSawNetworkError: loopState.sawNetworkError,
|
|
@@ -2948,8 +3041,11 @@ async function handleAnthropicRoutedClaudeRequest(args) {
|
|
|
2948
3041
|
// Rate-limit retries exhausted for this account — rotate
|
|
2949
3042
|
if (fetchResult.retrySameAccount &&
|
|
2950
3043
|
fetchResult.retryAfterMs !== undefined) {
|
|
3044
|
+
// Mark account as cooling so subsequent requests don't hammer it
|
|
3045
|
+
const coolingMs = Math.min(fetchResult.retryAfterMs || DEFAULT_COOLING_PERIOD_MS, DEFAULT_COOLING_PERIOD_MS);
|
|
3046
|
+
accountState.coolingUntil = Date.now() + coolingMs;
|
|
2951
3047
|
advancePrimaryIfCurrent(account.key, enabledAccounts.length, orderedAccounts[0]?.key);
|
|
2952
|
-
logger.always(`[proxy] exhausted ${MAX_RATE_LIMIT_SAME_ACCOUNT_RETRIES} rate-limit retries for account=${account.label}; rotating`);
|
|
3048
|
+
logger.always(`[proxy] exhausted ${MAX_RATE_LIMIT_SAME_ACCOUNT_RETRIES} rate-limit retries for account=${account.label}; cooling for ${coolingMs}ms, rotating`);
|
|
2953
3049
|
continue accountLoop;
|
|
2954
3050
|
}
|
|
2955
3051
|
// Transient error retry (network errors, 529 overloaded)
|
|
@@ -3052,6 +3148,10 @@ async function handleAnthropicRoutedClaudeRequest(args) {
|
|
|
3052
3148
|
}
|
|
3053
3149
|
break accountLoop;
|
|
3054
3150
|
}
|
|
3151
|
+
// Clear cooling on success — account is healthy again
|
|
3152
|
+
if (accountState.coolingUntil) {
|
|
3153
|
+
accountState.coolingUntil = undefined;
|
|
3154
|
+
}
|
|
3055
3155
|
const successResult = await handleAnthropicSuccessfulResponse({
|
|
3056
3156
|
ctx,
|
|
3057
3157
|
body,
|
|
@@ -3232,7 +3332,11 @@ export function createClaudeProxyRoutes(modelRouter, basePath = "", accountStrat
|
|
|
3232
3332
|
{
|
|
3233
3333
|
method: "GET",
|
|
3234
3334
|
path: `${basePath}/v1/models`,
|
|
3235
|
-
handler: async (_ctx) => {
|
|
3335
|
+
handler: async (_ctx) => withSpan({
|
|
3336
|
+
name: "neurolink.http.claudeProxy.listModels",
|
|
3337
|
+
tracer: tracers.http,
|
|
3338
|
+
attributes: { "http.route": `${basePath}/v1/models` },
|
|
3339
|
+
}, async () => {
|
|
3236
3340
|
const models = [
|
|
3237
3341
|
"claude-sonnet-4-20250514",
|
|
3238
3342
|
"claude-sonnet-4-5-20250929",
|
|
@@ -3248,7 +3352,7 @@ export function createClaudeProxyRoutes(modelRouter, basePath = "", accountStrat
|
|
|
3248
3352
|
owned_by: "anthropic",
|
|
3249
3353
|
})),
|
|
3250
3354
|
};
|
|
3251
|
-
},
|
|
3355
|
+
}),
|
|
3252
3356
|
description: "List available Claude models",
|
|
3253
3357
|
tags: ["claude-proxy", "models"],
|
|
3254
3358
|
},
|
|
@@ -3258,9 +3362,16 @@ export function createClaudeProxyRoutes(modelRouter, basePath = "", accountStrat
|
|
|
3258
3362
|
{
|
|
3259
3363
|
method: "POST",
|
|
3260
3364
|
path: `${basePath}/v1/messages/count_tokens`,
|
|
3261
|
-
handler: async (ctx) => {
|
|
3365
|
+
handler: async (ctx) => withSpan({
|
|
3366
|
+
name: "neurolink.http.claudeProxy.countTokens",
|
|
3367
|
+
tracer: tracers.http,
|
|
3368
|
+
attributes: {
|
|
3369
|
+
"http.route": `${basePath}/v1/messages/count_tokens`,
|
|
3370
|
+
},
|
|
3371
|
+
}, async (span) => {
|
|
3262
3372
|
const body = ctx.body;
|
|
3263
|
-
if (
|
|
3373
|
+
if (typeof body?.model !== "string" ||
|
|
3374
|
+
!Array.isArray(body?.messages)) {
|
|
3264
3375
|
return buildClaudeError(400, "Missing required fields: model, messages");
|
|
3265
3376
|
}
|
|
3266
3377
|
// Simple estimation using character-to-token heuristic
|
|
@@ -3269,8 +3380,11 @@ export function createClaudeProxyRoutes(modelRouter, basePath = "", accountStrat
|
|
|
3269
3380
|
? m.content
|
|
3270
3381
|
: JSON.stringify(m.content))
|
|
3271
3382
|
.join(" ");
|
|
3272
|
-
|
|
3273
|
-
|
|
3383
|
+
const inputTokens = Math.ceil(text.length / 4);
|
|
3384
|
+
span.setAttribute("ai.model", body.model);
|
|
3385
|
+
span.setAttribute("gen_ai.usage.input_tokens", inputTokens);
|
|
3386
|
+
return { input_tokens: inputTokens };
|
|
3387
|
+
}),
|
|
3274
3388
|
description: "Count tokens for a messages request",
|
|
3275
3389
|
tags: ["claude-proxy", "tokens"],
|
|
3276
3390
|
},
|
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
* Health Routes
|
|
3
3
|
* Endpoints for health checks and system status
|
|
4
4
|
*/
|
|
5
|
+
import { withSpan } from "../../telemetry/withSpan.js";
|
|
6
|
+
import { tracers } from "../../telemetry/tracers.js";
|
|
7
|
+
/**
|
|
8
|
+
* Wrap a health-route handler with an OTel span that records the route,
|
|
9
|
+
* request id, and overall health status.
|
|
10
|
+
*/
|
|
11
|
+
function tracedHealthHandler(name, route, fn) {
|
|
12
|
+
return (ctx) => withSpan({
|
|
13
|
+
name,
|
|
14
|
+
tracer: tracers.http,
|
|
15
|
+
attributes: {
|
|
16
|
+
"http.route": route,
|
|
17
|
+
"http.request.id": ctx.requestId ?? "",
|
|
18
|
+
},
|
|
19
|
+
}, () => fn(ctx));
|
|
20
|
+
}
|
|
5
21
|
/**
|
|
6
22
|
* Create health check routes
|
|
7
23
|
*/
|
|
@@ -12,34 +28,41 @@ export function createHealthRoutes(basePath = "/api") {
|
|
|
12
28
|
{
|
|
13
29
|
method: "GET",
|
|
14
30
|
path: `${basePath}/health`,
|
|
15
|
-
handler: async () => {
|
|
31
|
+
handler: tracedHealthHandler("neurolink.http.health.check", `${basePath}/health`, async () => {
|
|
16
32
|
return {
|
|
17
33
|
status: "ok",
|
|
18
34
|
timestamp: new Date().toISOString(),
|
|
19
35
|
uptime: process.uptime() * 1000,
|
|
20
36
|
version: process.env.npm_package_version || "unknown",
|
|
21
37
|
};
|
|
22
|
-
},
|
|
38
|
+
}),
|
|
23
39
|
description: "Basic health check",
|
|
24
40
|
tags: ["health"],
|
|
25
41
|
},
|
|
26
42
|
{
|
|
27
43
|
method: "GET",
|
|
28
44
|
path: `${basePath}/health/live`,
|
|
29
|
-
handler: async () => {
|
|
45
|
+
handler: tracedHealthHandler("neurolink.http.health.live", `${basePath}/health/live`, async () => {
|
|
30
46
|
// Liveness probe - just checks if the server is running
|
|
31
47
|
return {
|
|
32
48
|
status: "alive",
|
|
33
49
|
timestamp: new Date().toISOString(),
|
|
34
50
|
};
|
|
35
|
-
},
|
|
51
|
+
}),
|
|
36
52
|
description: "Kubernetes liveness probe",
|
|
37
53
|
tags: ["health"],
|
|
38
54
|
},
|
|
39
55
|
{
|
|
40
56
|
method: "GET",
|
|
41
57
|
path: `${basePath}/health/ready`,
|
|
42
|
-
handler:
|
|
58
|
+
handler: (ctx) => withSpan({
|
|
59
|
+
name: "neurolink.http.health.ready",
|
|
60
|
+
tracer: tracers.http,
|
|
61
|
+
attributes: {
|
|
62
|
+
"http.route": `${basePath}/health/ready`,
|
|
63
|
+
"http.request.id": ctx.requestId ?? "",
|
|
64
|
+
},
|
|
65
|
+
}, async (span) => {
|
|
43
66
|
// Readiness probe - checks if all dependencies are ready
|
|
44
67
|
const tools = await ctx.toolRegistry.listTools();
|
|
45
68
|
const hasTools = tools.length > 0;
|
|
@@ -56,6 +79,9 @@ export function createHealthRoutes(basePath = "/api") {
|
|
|
56
79
|
}
|
|
57
80
|
}
|
|
58
81
|
const isReady = hasTools || !hasExternalManager || externalServersReady;
|
|
82
|
+
span.setAttribute("health.ready", isReady);
|
|
83
|
+
span.setAttribute("health.tools_count", tools.length);
|
|
84
|
+
span.setAttribute("health.external_servers_ready", externalServersReady);
|
|
59
85
|
return {
|
|
60
86
|
ready: isReady,
|
|
61
87
|
timestamp: new Date().toISOString(),
|
|
@@ -65,16 +91,24 @@ export function createHealthRoutes(basePath = "/api") {
|
|
|
65
91
|
externalServers: externalServersReady,
|
|
66
92
|
},
|
|
67
93
|
};
|
|
68
|
-
},
|
|
94
|
+
}),
|
|
69
95
|
description: "Kubernetes readiness probe",
|
|
70
96
|
tags: ["health"],
|
|
71
97
|
},
|
|
72
98
|
{
|
|
73
99
|
method: "GET",
|
|
74
100
|
path: `${basePath}/health/startup`,
|
|
75
|
-
handler:
|
|
101
|
+
handler: (ctx) => withSpan({
|
|
102
|
+
name: "neurolink.http.health.startup",
|
|
103
|
+
tracer: tracers.http,
|
|
104
|
+
attributes: {
|
|
105
|
+
"http.route": `${basePath}/health/startup`,
|
|
106
|
+
"http.request.id": ctx.requestId ?? "",
|
|
107
|
+
},
|
|
108
|
+
}, async (span) => {
|
|
76
109
|
// Startup probe - checks if the application has started successfully
|
|
77
110
|
const tools = await ctx.toolRegistry.listTools();
|
|
111
|
+
span.setAttribute("health.tools_count", tools.length);
|
|
78
112
|
return {
|
|
79
113
|
started: true,
|
|
80
114
|
timestamp: new Date().toISOString(),
|
|
@@ -84,14 +118,21 @@ export function createHealthRoutes(basePath = "/api") {
|
|
|
84
118
|
externalServerManager: !!ctx.externalServerManager,
|
|
85
119
|
},
|
|
86
120
|
};
|
|
87
|
-
},
|
|
121
|
+
}),
|
|
88
122
|
description: "Kubernetes startup probe",
|
|
89
123
|
tags: ["health"],
|
|
90
124
|
},
|
|
91
125
|
{
|
|
92
126
|
method: "GET",
|
|
93
127
|
path: `${basePath}/health/detailed`,
|
|
94
|
-
handler:
|
|
128
|
+
handler: (ctx) => withSpan({
|
|
129
|
+
name: "neurolink.http.health.detailed",
|
|
130
|
+
tracer: tracers.http,
|
|
131
|
+
attributes: {
|
|
132
|
+
"http.route": `${basePath}/health/detailed`,
|
|
133
|
+
"http.request.id": ctx.requestId ?? "",
|
|
134
|
+
},
|
|
135
|
+
}, async (span) => {
|
|
95
136
|
const tools = await ctx.toolRegistry.listTools();
|
|
96
137
|
// Group tools by source
|
|
97
138
|
const toolsBySource = {};
|
|
@@ -162,23 +203,28 @@ export function createHealthRoutes(basePath = "/api") {
|
|
|
162
203
|
healthyCount: pool.getHealthyCount(),
|
|
163
204
|
strategy: pool.getStrategy(),
|
|
164
205
|
};
|
|
206
|
+
span.setAttribute("health.proxy.accounts", allAccounts.length);
|
|
207
|
+
span.setAttribute("health.proxy.healthy", pool.getHealthyCount());
|
|
165
208
|
}
|
|
209
|
+
span.setAttribute("health.tools_count", tools.length);
|
|
210
|
+
span.setAttribute("health.external_servers_count", externalServers.length);
|
|
211
|
+
span.setAttribute("health.memory.heap_mb", Math.round(process.memoryUsage().heapUsed / 1024 / 1024));
|
|
166
212
|
return healthResponse;
|
|
167
|
-
},
|
|
213
|
+
}),
|
|
168
214
|
description: "Detailed health information",
|
|
169
215
|
tags: ["health"],
|
|
170
216
|
},
|
|
171
217
|
{
|
|
172
218
|
method: "GET",
|
|
173
219
|
path: `${basePath}/version`,
|
|
174
|
-
handler: async () => {
|
|
220
|
+
handler: tracedHealthHandler("neurolink.http.version", `${basePath}/version`, async () => {
|
|
175
221
|
return {
|
|
176
222
|
name: "@juspay/neurolink",
|
|
177
223
|
version: process.env.npm_package_version || "unknown",
|
|
178
224
|
node: process.version,
|
|
179
225
|
timestamp: new Date().toISOString(),
|
|
180
226
|
};
|
|
181
|
-
},
|
|
227
|
+
}),
|
|
182
228
|
description: "Get version information",
|
|
183
229
|
tags: ["health", "version"],
|
|
184
230
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Route Builders
|
|
3
3
|
* Pre-built route definitions for common NeuroLink endpoints
|
|
4
4
|
*/
|
|
5
|
-
import type { RouteDefinition, RouteGroup } from "../../types/index.js";
|
|
5
|
+
import type { CreateRoutesOptions, RouteDefinition, RouteGroup } from "../../types/index.js";
|
|
6
6
|
export { createAgentRoutes } from "./agentRoutes.js";
|
|
7
7
|
export { createClaudeProxyRoutes } from "./claudeProxyRoutes.js";
|
|
8
8
|
export { createHealthRoutes } from "./healthRoutes.js";
|
|
@@ -10,31 +10,6 @@ export { createMCPRoutes } from "./mcpRoutes.js";
|
|
|
10
10
|
export { createMemoryRoutes } from "./memoryRoutes.js";
|
|
11
11
|
export { createOpenApiRoutes } from "./openApiRoutes.js";
|
|
12
12
|
export { createToolRoutes } from "./toolRoutes.js";
|
|
13
|
-
/**
|
|
14
|
-
* Options for creating routes
|
|
15
|
-
*/
|
|
16
|
-
type CreateRoutesOptions = {
|
|
17
|
-
/** Enable OpenAPI/Swagger documentation endpoints (default: false) */
|
|
18
|
-
enableSwagger?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Callback to get registered routes for OpenAPI spec generation.
|
|
21
|
-
* This callback is invoked at request time when the OpenAPI spec is accessed,
|
|
22
|
-
* allowing it to reflect all routes registered with the adapter.
|
|
23
|
-
*
|
|
24
|
-
* When using `registerAllRoutes`, this is automatically bound to `adapter.listRoutes()`
|
|
25
|
-
* if the adapter supports it and no custom callback is provided.
|
|
26
|
-
*
|
|
27
|
-
* If not provided (and adapter doesn't have listRoutes), the spec will use
|
|
28
|
-
* default endpoint definitions.
|
|
29
|
-
*/
|
|
30
|
-
getRoutes?: () => RouteDefinition[];
|
|
31
|
-
/**
|
|
32
|
-
* Enable or disable the Claude-compatible proxy routes.
|
|
33
|
-
* When true, registers /v1/messages, /v1/models, and /v1/messages/count_tokens
|
|
34
|
-
* endpoints that accept Anthropic API format requests.
|
|
35
|
-
*/
|
|
36
|
-
claudeProxy?: boolean;
|
|
37
|
-
};
|
|
38
13
|
/**
|
|
39
14
|
* Create all standard routes
|
|
40
15
|
* Convenience method that combines all route groups
|
|
@@ -2,8 +2,41 @@
|
|
|
2
2
|
* MCP Routes
|
|
3
3
|
* Endpoints for MCP server management
|
|
4
4
|
*/
|
|
5
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
5
6
|
import { z } from "zod";
|
|
7
|
+
import { withSpan } from "../../telemetry/withSpan.js";
|
|
8
|
+
import { tracers } from "../../telemetry/tracers.js";
|
|
6
9
|
import { createErrorResponse, ServerNameParamSchema, ToolArgumentsSchema, validateParams, validateRequest, } from "../utils/validation.js";
|
|
10
|
+
/**
|
|
11
|
+
* Wrap a route handler with an OTel span for HTTP observability.
|
|
12
|
+
*/
|
|
13
|
+
function tracedMcpHandler(name, route, fn) {
|
|
14
|
+
return (ctx) => withSpan({
|
|
15
|
+
name,
|
|
16
|
+
tracer: tracers.http,
|
|
17
|
+
attributes: {
|
|
18
|
+
"http.route": route,
|
|
19
|
+
"http.request.id": ctx.requestId,
|
|
20
|
+
},
|
|
21
|
+
}, async (otelSpan) => {
|
|
22
|
+
const result = await fn(ctx);
|
|
23
|
+
// Detect returned error responses (not thrown) and mark span as failed.
|
|
24
|
+
// Only flag when the error value is truthy to avoid false positives
|
|
25
|
+
// from handlers that always include an `error` key (e.g. handleGetServer).
|
|
26
|
+
if (result && typeof result === "object") {
|
|
27
|
+
const errVal = result.error;
|
|
28
|
+
if (errVal !== undefined && errVal !== null) {
|
|
29
|
+
const errMsg = typeof errVal === "string"
|
|
30
|
+
? errVal
|
|
31
|
+
: typeof errVal?.message === "string"
|
|
32
|
+
? errVal.message
|
|
33
|
+
: "MCP handler error";
|
|
34
|
+
otelSpan.setStatus({ code: SpanStatusCode.ERROR, message: errMsg });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
7
40
|
/**
|
|
8
41
|
* MCP tool execution params schema
|
|
9
42
|
*/
|
|
@@ -291,49 +324,49 @@ export function createMCPRoutes(basePath = "/api") {
|
|
|
291
324
|
{
|
|
292
325
|
method: "GET",
|
|
293
326
|
path: `${basePath}/mcp/servers`,
|
|
294
|
-
handler: handleListServers,
|
|
327
|
+
handler: tracedMcpHandler("neurolink.http.mcp.listServers", `${basePath}/mcp/servers`, handleListServers),
|
|
295
328
|
description: "List all MCP servers",
|
|
296
329
|
tags: ["mcp"],
|
|
297
330
|
},
|
|
298
331
|
{
|
|
299
332
|
method: "GET",
|
|
300
333
|
path: `${basePath}/mcp/servers/:name`,
|
|
301
|
-
handler: handleGetServer,
|
|
334
|
+
handler: tracedMcpHandler("neurolink.http.mcp.getServer", `${basePath}/mcp/servers/:name`, handleGetServer),
|
|
302
335
|
description: "Get MCP server status",
|
|
303
336
|
tags: ["mcp"],
|
|
304
337
|
},
|
|
305
338
|
{
|
|
306
339
|
method: "POST",
|
|
307
340
|
path: `${basePath}/mcp/servers/:name/reconnect`,
|
|
308
|
-
handler: handleReconnectServer,
|
|
341
|
+
handler: tracedMcpHandler("neurolink.http.mcp.reconnectServer", `${basePath}/mcp/servers/:name/reconnect`, handleReconnectServer),
|
|
309
342
|
description: "Reconnect to an MCP server",
|
|
310
343
|
tags: ["mcp"],
|
|
311
344
|
},
|
|
312
345
|
{
|
|
313
346
|
method: "DELETE",
|
|
314
347
|
path: `${basePath}/mcp/servers/:name`,
|
|
315
|
-
handler: handleRemoveServer,
|
|
348
|
+
handler: tracedMcpHandler("neurolink.http.mcp.removeServer", `${basePath}/mcp/servers/:name`, handleRemoveServer),
|
|
316
349
|
description: "Remove an MCP server",
|
|
317
350
|
tags: ["mcp"],
|
|
318
351
|
},
|
|
319
352
|
{
|
|
320
353
|
method: "GET",
|
|
321
354
|
path: `${basePath}/mcp/servers/:name/tools`,
|
|
322
|
-
handler: handleListServerTools,
|
|
355
|
+
handler: tracedMcpHandler("neurolink.http.mcp.listServerTools", `${basePath}/mcp/servers/:name/tools`, handleListServerTools),
|
|
323
356
|
description: "List tools from a specific MCP server",
|
|
324
357
|
tags: ["mcp", "tools"],
|
|
325
358
|
},
|
|
326
359
|
{
|
|
327
360
|
method: "POST",
|
|
328
361
|
path: `${basePath}/mcp/servers/:name/tools/:toolName/execute`,
|
|
329
|
-
handler: handleExecuteTool,
|
|
362
|
+
handler: tracedMcpHandler("neurolink.http.mcp.executeTool", `${basePath}/mcp/servers/:name/tools/:toolName/execute`, handleExecuteTool),
|
|
330
363
|
description: "Execute a tool from a specific MCP server",
|
|
331
364
|
tags: ["mcp", "tools"],
|
|
332
365
|
},
|
|
333
366
|
{
|
|
334
367
|
method: "GET",
|
|
335
368
|
path: `${basePath}/mcp/health`,
|
|
336
|
-
handler: handleMCPHealth,
|
|
369
|
+
handler: tracedMcpHandler("neurolink.http.mcp.health", `${basePath}/mcp/health`, handleMCPHealth),
|
|
337
370
|
description: "Health check for all MCP servers",
|
|
338
371
|
tags: ["mcp", "health"],
|
|
339
372
|
},
|
|
@@ -2,7 +2,22 @@
|
|
|
2
2
|
* Memory Routes
|
|
3
3
|
* Endpoints for conversation memory management
|
|
4
4
|
*/
|
|
5
|
+
import { withSpan } from "../../telemetry/withSpan.js";
|
|
6
|
+
import { tracers } from "../../telemetry/tracers.js";
|
|
5
7
|
import { createErrorResponse, IdParamSchema, SessionIdParamSchema, validateParams, } from "../utils/validation.js";
|
|
8
|
+
/**
|
|
9
|
+
* Wrap a route handler with an OTel span for HTTP observability.
|
|
10
|
+
*/
|
|
11
|
+
function tracedMemoryHandler(name, route, fn) {
|
|
12
|
+
return (ctx) => withSpan({
|
|
13
|
+
name,
|
|
14
|
+
tracer: tracers.http,
|
|
15
|
+
attributes: {
|
|
16
|
+
"http.route": route,
|
|
17
|
+
"http.request.id": ctx.requestId,
|
|
18
|
+
},
|
|
19
|
+
}, () => fn(ctx));
|
|
20
|
+
}
|
|
6
21
|
/**
|
|
7
22
|
* Handler: Get messages for a session
|
|
8
23
|
*/
|
|
@@ -297,7 +312,7 @@ export function createMemoryRoutes(basePath = "/api") {
|
|
|
297
312
|
{
|
|
298
313
|
method: "GET",
|
|
299
314
|
path: `${basePath}/memory/sessions/:id/messages`,
|
|
300
|
-
handler: handleGetSessionMessages,
|
|
315
|
+
handler: tracedMemoryHandler("neurolink.http.memory.getSessionMessages", `${basePath}/memory/sessions/:id/messages`, handleGetSessionMessages),
|
|
301
316
|
description: "Get messages for a session",
|
|
302
317
|
tags: ["memory"],
|
|
303
318
|
},
|
|
@@ -305,7 +320,7 @@ export function createMemoryRoutes(basePath = "/api") {
|
|
|
305
320
|
{
|
|
306
321
|
method: "GET",
|
|
307
322
|
path: `${basePath}/memory/sessions/:id`,
|
|
308
|
-
handler: handleGetSession,
|
|
323
|
+
handler: tracedMemoryHandler("neurolink.http.memory.getSession", `${basePath}/memory/sessions/:id`, handleGetSession),
|
|
309
324
|
description: "Get session by ID",
|
|
310
325
|
tags: ["memory"],
|
|
311
326
|
},
|
|
@@ -313,35 +328,35 @@ export function createMemoryRoutes(basePath = "/api") {
|
|
|
313
328
|
{
|
|
314
329
|
method: "GET",
|
|
315
330
|
path: `${basePath}/memory/sessions`,
|
|
316
|
-
handler: handleListSessions,
|
|
331
|
+
handler: tracedMemoryHandler("neurolink.http.memory.listSessions", `${basePath}/memory/sessions`, handleListSessions),
|
|
317
332
|
description: "List all conversation sessions",
|
|
318
333
|
tags: ["memory"],
|
|
319
334
|
},
|
|
320
335
|
{
|
|
321
336
|
method: "GET",
|
|
322
337
|
path: `${basePath}/memory/stats`,
|
|
323
|
-
handler: handleGetStats,
|
|
338
|
+
handler: tracedMemoryHandler("neurolink.http.memory.stats", `${basePath}/memory/stats`, handleGetStats),
|
|
324
339
|
description: "Get memory statistics",
|
|
325
340
|
tags: ["memory"],
|
|
326
341
|
},
|
|
327
342
|
{
|
|
328
343
|
method: "DELETE",
|
|
329
344
|
path: `${basePath}/memory/sessions/:sessionId`,
|
|
330
|
-
handler: handleClearSession,
|
|
345
|
+
handler: tracedMemoryHandler("neurolink.http.memory.clearSession", `${basePath}/memory/sessions/:sessionId`, handleClearSession),
|
|
331
346
|
description: "Clear a conversation session",
|
|
332
347
|
tags: ["memory"],
|
|
333
348
|
},
|
|
334
349
|
{
|
|
335
350
|
method: "DELETE",
|
|
336
351
|
path: `${basePath}/memory/sessions`,
|
|
337
|
-
handler: handleClearAllSessions,
|
|
352
|
+
handler: tracedMemoryHandler("neurolink.http.memory.clearAllSessions", `${basePath}/memory/sessions`, handleClearAllSessions),
|
|
338
353
|
description: "Clear all conversation sessions",
|
|
339
354
|
tags: ["memory"],
|
|
340
355
|
},
|
|
341
356
|
{
|
|
342
357
|
method: "GET",
|
|
343
358
|
path: `${basePath}/memory/health`,
|
|
344
|
-
handler: handleMemoryHealth,
|
|
359
|
+
handler: tracedMemoryHandler("neurolink.http.memory.health", `${basePath}/memory/health`, handleMemoryHealth),
|
|
345
360
|
description: "Check memory system health",
|
|
346
361
|
tags: ["memory", "health"],
|
|
347
362
|
},
|