@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
|
@@ -14,42 +14,7 @@
|
|
|
14
14
|
* - TelemetryService for metrics recording
|
|
15
15
|
*/
|
|
16
16
|
import { type Span } from "@opentelemetry/api";
|
|
17
|
-
type ProxyRequestContext
|
|
18
|
-
requestId: string;
|
|
19
|
-
method: string;
|
|
20
|
-
path: string;
|
|
21
|
-
model: string;
|
|
22
|
-
stream: boolean;
|
|
23
|
-
toolCount: number;
|
|
24
|
-
sessionId?: string;
|
|
25
|
-
userAgent?: string;
|
|
26
|
-
clientApp?: string;
|
|
27
|
-
};
|
|
28
|
-
type AccountSelectionContext = {
|
|
29
|
-
strategy: string;
|
|
30
|
-
accountsTotal: number;
|
|
31
|
-
accountsHealthy: number;
|
|
32
|
-
selectedAccount: string;
|
|
33
|
-
accountType: string;
|
|
34
|
-
rateLimitBefore5h?: number;
|
|
35
|
-
rateLimitBefore7d?: number;
|
|
36
|
-
};
|
|
37
|
-
type UpstreamAttemptContext = {
|
|
38
|
-
attempt: number;
|
|
39
|
-
account: string;
|
|
40
|
-
polyfillHeaders: boolean;
|
|
41
|
-
polyfillBody: boolean;
|
|
42
|
-
upstreamUrl: string;
|
|
43
|
-
};
|
|
44
|
-
type UsageContext = {
|
|
45
|
-
inputTokens: number;
|
|
46
|
-
outputTokens: number;
|
|
47
|
-
cacheCreationTokens: number;
|
|
48
|
-
cacheReadTokens: number;
|
|
49
|
-
reasoningTokens?: number;
|
|
50
|
-
rateLimitAfter5h?: number;
|
|
51
|
-
rateLimitAfter7d?: number;
|
|
52
|
-
};
|
|
17
|
+
import type { AccountSelectionContext, ProxyRequestContext, UpstreamAttemptContext, UsageContext } from "../types/index.js";
|
|
53
18
|
declare class ProxyTracer {
|
|
54
19
|
private readonly rootSpan;
|
|
55
20
|
private readonly proxyTracer;
|
|
@@ -20,6 +20,15 @@ import { calculateCost } from "../utils/pricing.js";
|
|
|
20
20
|
import { TelemetryService } from "../telemetry/telemetryService.js";
|
|
21
21
|
import { logger } from "../utils/logger.js";
|
|
22
22
|
const LOG_PREFIX = "[ProxyTracer]";
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// OTEL Metric Instruments — lazy singleton
|
|
25
|
+
//
|
|
26
|
+
// The MeterProvider is registered in initializeOpenTelemetry() which runs
|
|
27
|
+
// *after* module import time. @opentelemetry/api v1.x getMeter() returns a
|
|
28
|
+
// NoopMeter if called before a real MeterProvider is set. We therefore
|
|
29
|
+
// defer instrument creation until the first ProxyTracer.end() call, at which
|
|
30
|
+
// point the MeterProvider is guaranteed to be registered.
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
23
32
|
let _metrics = null;
|
|
24
33
|
function getProxyMetrics() {
|
|
25
34
|
if (_metrics) {
|
|
@@ -4,12 +4,7 @@
|
|
|
4
4
|
* threshold by efficiently reading only the tail of today's debug log file.
|
|
5
5
|
* Used by the auto-update system to find safe windows for restarts.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
type QuietStatus = {
|
|
9
|
-
isQuiet: boolean;
|
|
10
|
-
lastActivityAt: Date | null;
|
|
11
|
-
silenceDurationMs: number;
|
|
12
|
-
};
|
|
7
|
+
import type { QuietStatus } from "../types/index.js";
|
|
13
8
|
/**
|
|
14
9
|
* Check whether proxy traffic has been quiet (no requests) for at least
|
|
15
10
|
* `quietThresholdMs` milliseconds.
|
|
@@ -20,4 +15,3 @@ type QuietStatus = {
|
|
|
20
15
|
* @returns QuietStatus with the idle analysis.
|
|
21
16
|
*/
|
|
22
17
|
export declare function checkTrafficQuiet(quietThresholdMs?: number): QuietStatus;
|
|
23
|
-
export {};
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
type
|
|
2
|
-
totalBytes: number;
|
|
3
|
-
text: string;
|
|
4
|
-
truncated: boolean;
|
|
5
|
-
};
|
|
6
|
-
type RawStreamCaptureResult = {
|
|
7
|
-
stream: TransformStream<Uint8Array, Uint8Array>;
|
|
8
|
-
capture: Promise<RawStreamCapture>;
|
|
9
|
-
};
|
|
1
|
+
import type { RawStreamCaptureResult } from "../types/index.js";
|
|
10
2
|
export declare function createRawStreamCapture(): RawStreamCaptureResult;
|
|
11
|
-
export {};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* when a LoggerProvider is configured via OpenTelemetry instrumentation.
|
|
6
6
|
* Useful for debugging and auditing proxy traffic.
|
|
7
7
|
*/
|
|
8
|
-
import type { RequestAttemptLogEntry, RequestLogEntry } from "../types/index.js";
|
|
8
|
+
import type { ProxyBodyCaptureEntry, RequestAttemptLogEntry, RequestLogEntry } from "../types/index.js";
|
|
9
9
|
export declare function initRequestLogger(enabled?: boolean, customLogsDir?: string): void;
|
|
10
10
|
export declare function logRequest(entry: RequestLogEntry): Promise<void>;
|
|
11
11
|
/**
|
|
@@ -15,25 +15,6 @@ export declare function logRequest(entry: RequestLogEntry): Promise<void>;
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function logRequestAttempt(entry: RequestAttemptLogEntry): Promise<void>;
|
|
17
17
|
export declare function getLogDir(): string | null;
|
|
18
|
-
type ProxyBodyCaptureEntry = {
|
|
19
|
-
timestamp: string;
|
|
20
|
-
requestId: string;
|
|
21
|
-
phase: string;
|
|
22
|
-
model: string;
|
|
23
|
-
stream: boolean;
|
|
24
|
-
headers?: Record<string, string>;
|
|
25
|
-
body?: unknown;
|
|
26
|
-
bodySize?: number;
|
|
27
|
-
contentType?: string;
|
|
28
|
-
responseStatus?: number;
|
|
29
|
-
durationMs?: number;
|
|
30
|
-
account?: string;
|
|
31
|
-
accountType?: string;
|
|
32
|
-
attempt?: number;
|
|
33
|
-
traceId?: string;
|
|
34
|
-
spanId?: string;
|
|
35
|
-
metadata?: Record<string, unknown>;
|
|
36
|
-
};
|
|
37
18
|
export declare function logBodyCapture(entry: ProxyBodyCaptureEntry): Promise<void>;
|
|
38
19
|
/**
|
|
39
20
|
* Log the FULL raw request and response for debugging.
|
|
@@ -74,4 +55,3 @@ export declare function logStreamError(entry: {
|
|
|
74
55
|
* Non-fatal — proxy keeps working even if cleanup fails.
|
|
75
56
|
*/
|
|
76
57
|
export declare function cleanupLogs(maxAgeDays?: number, maxSizeMb?: number): void;
|
|
77
|
-
export {};
|
|
@@ -15,71 +15,7 @@
|
|
|
15
15
|
* upstreamResponse.body.pipeThrough(stream).pipeTo(clientWritable);
|
|
16
16
|
* const data = await telemetry; // resolves on stream end
|
|
17
17
|
*/
|
|
18
|
-
type
|
|
19
|
-
index: number;
|
|
20
|
-
type: "text" | "thinking" | "tool_use" | "tool_result";
|
|
21
|
-
/** Accumulated text for text blocks. Capped at MAX_BLOCK_CONTENT_BYTES. */
|
|
22
|
-
text?: string;
|
|
23
|
-
/** Accumulated thinking content. Capped at MAX_BLOCK_CONTENT_BYTES. */
|
|
24
|
-
thinking?: string;
|
|
25
|
-
/** Tool name for tool_use blocks. */
|
|
26
|
-
toolName?: string;
|
|
27
|
-
/** Tool call id for tool_use blocks. */
|
|
28
|
-
toolId?: string;
|
|
29
|
-
/** Accumulated partial JSON input for tool_use blocks. Capped at MAX_BLOCK_CONTENT_BYTES. */
|
|
30
|
-
toolInput?: string;
|
|
31
|
-
};
|
|
32
|
-
type SSETelemetry = {
|
|
33
|
-
/** Message id from message_start. */
|
|
34
|
-
messageId: string;
|
|
35
|
-
/** Model string from message_start. */
|
|
36
|
-
model: string;
|
|
37
|
-
/** Token usage aggregated from message_start + message_delta. */
|
|
38
|
-
usage: {
|
|
39
|
-
inputTokens: number;
|
|
40
|
-
outputTokens: number;
|
|
41
|
-
cacheCreationInputTokens: number;
|
|
42
|
-
cacheReadInputTokens: number;
|
|
43
|
-
totalTokens: number;
|
|
44
|
-
};
|
|
45
|
-
/** All content blocks accumulated during the stream. */
|
|
46
|
-
contentBlocks: SSEContentBlock[];
|
|
47
|
-
/** Stop reason from message_delta, e.g. "end_turn". */
|
|
48
|
-
stopReason: string | null;
|
|
49
|
-
/** Stop sequence from message_delta, if any. */
|
|
50
|
-
stopSequence: string | null;
|
|
51
|
-
/** Total number of SSE events observed. */
|
|
52
|
-
eventCount: number;
|
|
53
|
-
/** Wall-clock duration from first byte to stream end (ms). */
|
|
54
|
-
streamDurationMs: number;
|
|
55
|
-
/** Total bytes received from upstream (raw SSE stream size). */
|
|
56
|
-
totalBytesReceived: number;
|
|
57
|
-
/**
|
|
58
|
-
* Raw SSE event log. For content_block_delta events only the type is
|
|
59
|
-
* stored (not the full data payload) to avoid excessive memory use.
|
|
60
|
-
* All other events store the full data string.
|
|
61
|
-
*/
|
|
62
|
-
events: Array<{
|
|
63
|
-
type: string;
|
|
64
|
-
timestamp: number;
|
|
65
|
-
data: string;
|
|
66
|
-
}>;
|
|
67
|
-
/** Full raw SSE transcript, when captureRawText is enabled. */
|
|
68
|
-
rawText?: string;
|
|
69
|
-
};
|
|
70
|
-
type SSEInterceptorResult = {
|
|
71
|
-
/** Pipe the upstream response through this stream. */
|
|
72
|
-
stream: TransformStream<Uint8Array, Uint8Array>;
|
|
73
|
-
/**
|
|
74
|
-
* Resolves with the accumulated telemetry when the stream finishes.
|
|
75
|
-
* If the stream errors, the promise resolves with whatever telemetry
|
|
76
|
-
* was gathered up to that point (never rejects).
|
|
77
|
-
*/
|
|
78
|
-
telemetry: Promise<SSETelemetry>;
|
|
79
|
-
};
|
|
80
|
-
type SSEInterceptorOptions = {
|
|
81
|
-
captureRawText?: boolean;
|
|
82
|
-
};
|
|
18
|
+
import type { SSEInterceptorOptions, SSEInterceptorResult } from "../types/index.js";
|
|
83
19
|
/**
|
|
84
20
|
* Create an SSE interceptor that extracts telemetry from an Anthropic
|
|
85
21
|
* streaming response while passing all bytes through unmodified.
|
|
@@ -95,4 +31,3 @@ type SSEInterceptorOptions = {
|
|
|
95
31
|
* ```
|
|
96
32
|
*/
|
|
97
33
|
export declare function createSSEInterceptor(options?: SSEInterceptorOptions): SSEInterceptorResult;
|
|
98
|
-
export {};
|
|
@@ -69,6 +69,9 @@ function extractSSEEvents(buffer) {
|
|
|
69
69
|
}
|
|
70
70
|
return { events, remainder: buffer.slice(cursor) };
|
|
71
71
|
}
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// Telemetry accumulator
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
72
75
|
function createAccumulator(captureRawText) {
|
|
73
76
|
return {
|
|
74
77
|
messageId: "",
|
|
@@ -338,6 +341,9 @@ function processEvent(acc, event) {
|
|
|
338
341
|
break;
|
|
339
342
|
}
|
|
340
343
|
}
|
|
344
|
+
// ---------------------------------------------------------------------------
|
|
345
|
+
// Public API
|
|
346
|
+
// ---------------------------------------------------------------------------
|
|
341
347
|
/**
|
|
342
348
|
* Create an SSE interceptor that extracts telemetry from an Anthropic
|
|
343
349
|
* streaming response while passing all bytes through unmodified.
|
|
@@ -6,11 +6,7 @@
|
|
|
6
6
|
* Designed to be non-blocking and failure-tolerant — any error (network,
|
|
7
7
|
* timeout, parse) silently returns `updateAvailable: false`.
|
|
8
8
|
*/
|
|
9
|
-
type UpdateCheckResult
|
|
10
|
-
currentVersion: string;
|
|
11
|
-
latestVersion: string;
|
|
12
|
-
updateAvailable: boolean;
|
|
13
|
-
};
|
|
9
|
+
import type { UpdateCheckResult } from "../types/index.js";
|
|
14
10
|
/**
|
|
15
11
|
* Query npm for the latest version of `@juspay/neurolink` and compare it
|
|
16
12
|
* against {@link currentVersion}.
|
|
@@ -19,4 +15,3 @@ type UpdateCheckResult = {
|
|
|
19
15
|
* `{ updateAvailable: false, latestVersion: currentVersion }`.
|
|
20
16
|
*/
|
|
21
17
|
export declare function checkForUpdate(currentVersion: string): Promise<UpdateCheckResult>;
|
|
22
|
-
export {};
|
|
@@ -6,17 +6,7 @@
|
|
|
6
6
|
* State file location: ~/.neurolink/update-state.json
|
|
7
7
|
* Suppressed versions expire after 24 hours.
|
|
8
8
|
*/
|
|
9
|
-
type
|
|
10
|
-
suppressedAt: string;
|
|
11
|
-
reason: string;
|
|
12
|
-
};
|
|
13
|
-
type UpdateState = {
|
|
14
|
-
lastCheckAt: string;
|
|
15
|
-
lastCheckVersion: string;
|
|
16
|
-
suppressedVersions: Record<string, SuppressedVersion>;
|
|
17
|
-
lastUpdateAt: string | null;
|
|
18
|
-
lastUpdateVersion: string | null;
|
|
19
|
-
};
|
|
9
|
+
import type { UpdateState } from "../types/index.js";
|
|
20
10
|
/**
|
|
21
11
|
* Return an empty/initial UpdateState.
|
|
22
12
|
*/
|
|
@@ -65,4 +55,3 @@ export declare function recordSuccessfulUpdate(version: string, stateFilePath?:
|
|
|
65
55
|
* @param stateFilePath - Override path for testing
|
|
66
56
|
*/
|
|
67
57
|
export declare function recordCheck(latestVersion: string, stateFilePath?: string): void;
|
|
68
|
-
export {};
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { v4 as uuidv4 } from "uuid";
|
|
8
8
|
import { ChunkingError, RAGErrorCodes } from "../errors/RAGError.js";
|
|
9
|
+
import { withSpan } from "../../telemetry/withSpan.js";
|
|
10
|
+
import { tracers } from "../../telemetry/tracers.js";
|
|
9
11
|
/**
|
|
10
12
|
* Default chunker configuration
|
|
11
13
|
*/
|
|
@@ -64,29 +66,41 @@ export class BaseChunker {
|
|
|
64
66
|
* Chunk content into smaller pieces
|
|
65
67
|
*/
|
|
66
68
|
async chunk(content, config) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
strategy: this.strategy,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
return withSpan({
|
|
70
|
+
name: "neurolink.rag.chunk",
|
|
71
|
+
tracer: tracers.rag,
|
|
72
|
+
attributes: {
|
|
73
|
+
"rag.chunker.strategy": this.strategy,
|
|
74
|
+
"rag.chunker.content_chars": content.length,
|
|
75
|
+
"rag.chunker.content_bytes": Buffer.byteLength(content, "utf8"),
|
|
76
|
+
},
|
|
77
|
+
}, async (span) => {
|
|
78
|
+
const effectiveConfig = { ...this.config, ...config };
|
|
79
|
+
if (!content || content.trim().length === 0) {
|
|
80
|
+
throw new ChunkingError("Content is empty", {
|
|
81
|
+
code: RAGErrorCodes.CHUNKING_EMPTY_CONTENT,
|
|
82
|
+
strategy: this.strategy,
|
|
83
|
+
contentLength: 0,
|
|
84
|
+
});
|
|
82
85
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
86
|
+
try {
|
|
87
|
+
const chunks = await this.doChunk(content, effectiveConfig);
|
|
88
|
+
const result = this.filterChunks(chunks, effectiveConfig);
|
|
89
|
+
span.setAttribute("rag.chunker.chunk_count", result.length);
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (error instanceof ChunkingError) {
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
throw new ChunkingError(`Chunking failed: ${error instanceof Error ? error.message : String(error)}`, {
|
|
97
|
+
code: RAGErrorCodes.CHUNKING_ERROR,
|
|
98
|
+
cause: error instanceof Error ? error : undefined,
|
|
99
|
+
strategy: this.strategy,
|
|
100
|
+
contentLength: content.length,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}); // end withSpan
|
|
90
104
|
}
|
|
91
105
|
/**
|
|
92
106
|
* Filter chunks based on minimum size
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Splits JSON documents based on structure (arrays, objects, keys).
|
|
5
5
|
* Best for API responses, configuration files, and structured data.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
7
|
+
import type { BaseChunkerConfig, Chunk, Chunker, ChunkerValidationResult, JSONChunkerConfig } from "../../types/index.js";
|
|
8
8
|
/**
|
|
9
9
|
* JSON-aware chunker implementation
|
|
10
10
|
* Splits based on JSON structure
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* Uses the NeuroLinkFeatureError pattern for consistency.
|
|
7
7
|
*/
|
|
8
8
|
import { NeuroLinkFeatureError } from "../../core/infrastructure/index.js";
|
|
9
|
+
import type { RAGErrorCode } from "../../types/index.js";
|
|
9
10
|
/**
|
|
10
11
|
* RAG error codes for all RAG-related operations
|
|
11
12
|
*/
|
|
@@ -43,7 +44,6 @@ export declare const RAGErrorCodes: {
|
|
|
43
44
|
readonly RETRY_EXHAUSTED: "RAG_RETRY_EXHAUSTED";
|
|
44
45
|
readonly INVALID_CONFIGURATION: "RAG_INVALID_CONFIGURATION";
|
|
45
46
|
};
|
|
46
|
-
type RAGErrorCode = (typeof RAGErrorCodes)[keyof typeof RAGErrorCodes];
|
|
47
47
|
/**
|
|
48
48
|
* RAG error factory using the infrastructure pattern
|
|
49
49
|
*/
|
|
@@ -242,4 +242,3 @@ export declare function isRetryableRAGError(error: unknown): boolean;
|
|
|
242
242
|
* Type guard for partial failure errors
|
|
243
243
|
*/
|
|
244
244
|
export declare function isPartialFailure(error: unknown): error is PipelineError;
|
|
245
|
-
export {};
|
|
@@ -13,6 +13,8 @@ import { SpanSerializer, SpanType, SpanStatus, getMetricsAggregator, } from "../
|
|
|
13
13
|
import { logger } from "../utils/logger.js";
|
|
14
14
|
import { createChunker } from "./ChunkerFactory.js";
|
|
15
15
|
import { createVectorQueryTool, InMemoryVectorStore, } from "./retrieval/vectorQueryTool.js";
|
|
16
|
+
import { withSpan } from "../telemetry/withSpan.js";
|
|
17
|
+
import { tracers } from "../telemetry/tracers.js";
|
|
16
18
|
/**
|
|
17
19
|
* Maps file extensions to recommended chunking strategies
|
|
18
20
|
*/
|
|
@@ -272,40 +274,51 @@ async function _prepareRAGToolInner(ragConfig, fallbackProvider) {
|
|
|
272
274
|
.describe("The search query to find relevant information"),
|
|
273
275
|
}),
|
|
274
276
|
execute: async ({ query }) => {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
?
|
|
288
|
-
|
|
289
|
-
|
|
277
|
+
return withSpan({
|
|
278
|
+
name: "neurolink.rag.search",
|
|
279
|
+
tracer: tracers.rag,
|
|
280
|
+
attributes: {
|
|
281
|
+
"rag.query_length": query ? String(query).length : 0,
|
|
282
|
+
"rag.top_k": topK ?? 5,
|
|
283
|
+
},
|
|
284
|
+
}, async (span) => {
|
|
285
|
+
// For the in-memory store with simple embeddings,
|
|
286
|
+
// generate a query embedding using the same method
|
|
287
|
+
const queryEmbedding = generateSimpleEmbedding(query, EMBEDDING_DIMENSION);
|
|
288
|
+
// Fetch more candidates than needed so diversity can select across files
|
|
289
|
+
const fetchK = fileContents.length > 1 ? topK * 3 : topK;
|
|
290
|
+
const rawResults = await vectorStore.query({
|
|
291
|
+
indexName,
|
|
292
|
+
queryVector: queryEmbedding,
|
|
293
|
+
topK: fetchK,
|
|
294
|
+
});
|
|
295
|
+
// Apply source-file diversity for multi-file RAG
|
|
296
|
+
const results = fileContents.length > 1
|
|
297
|
+
? diversifyResults(rawResults, topK)
|
|
298
|
+
: rawResults.slice(0, topK);
|
|
299
|
+
if (results.length === 0) {
|
|
300
|
+
span.setAttribute("rag.results_count", 0);
|
|
301
|
+
return {
|
|
302
|
+
relevantContext: "No relevant documents found for the query.",
|
|
303
|
+
sources: [],
|
|
304
|
+
totalResults: 0,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
const relevantContext = results
|
|
308
|
+
.map((r, i) => `[${i + 1}] ${r.metadata?.text || r.text || ""}`)
|
|
309
|
+
.join("\n\n");
|
|
310
|
+
span.setAttribute("rag.results_count", results.length);
|
|
290
311
|
return {
|
|
291
|
-
relevantContext
|
|
292
|
-
sources:
|
|
293
|
-
|
|
312
|
+
relevantContext,
|
|
313
|
+
sources: results.map((r) => ({
|
|
314
|
+
id: r.id,
|
|
315
|
+
score: r.score,
|
|
316
|
+
source: r.metadata?.source,
|
|
317
|
+
text: (r.metadata?.text || r.text || "").slice(0, 200),
|
|
318
|
+
})),
|
|
319
|
+
totalResults: results.length,
|
|
294
320
|
};
|
|
295
|
-
}
|
|
296
|
-
const relevantContext = results
|
|
297
|
-
.map((r, i) => `[${i + 1}] ${r.metadata?.text || r.text || ""}`)
|
|
298
|
-
.join("\n\n");
|
|
299
|
-
return {
|
|
300
|
-
relevantContext,
|
|
301
|
-
sources: results.map((r) => ({
|
|
302
|
-
id: r.id,
|
|
303
|
-
score: r.score,
|
|
304
|
-
source: r.metadata?.source,
|
|
305
|
-
text: (r.metadata?.text || r.text || "").slice(0, 200),
|
|
306
|
-
})),
|
|
307
|
-
totalResults: results.length,
|
|
308
|
-
};
|
|
321
|
+
});
|
|
309
322
|
},
|
|
310
323
|
};
|
|
311
324
|
return {
|