@juspay/neurolink 9.54.5 → 9.54.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/action/actionInputs.d.ts +1 -1
- package/dist/adapters/video/directorPipeline.js +6 -0
- package/dist/adapters/video/vertexVideoHandler.js +6 -0
- package/dist/agent/directTools.d.ts +3 -23
- package/dist/auth/AuthProviderFactory.d.ts +1 -3
- package/dist/auth/anthropicOAuth.d.ts +4 -7
- package/dist/auth/anthropicOAuth.js +23 -0
- package/dist/auth/errors.d.ts +1 -1
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +14 -0
- package/dist/auth/middleware/AuthMiddleware.d.ts +5 -60
- package/dist/auth/middleware/AuthMiddleware.js +3 -0
- package/dist/auth/middleware/rateLimitByUser.d.ts +4 -93
- package/dist/auth/middleware/rateLimitByUser.js +4 -0
- package/dist/auth/providers/BaseAuthProvider.d.ts +1 -1
- package/dist/auth/providers/CognitoProvider.js +3 -0
- package/dist/auth/providers/KeycloakProvider.js +3 -0
- package/dist/auth/providers/auth0.d.ts +1 -1
- package/dist/auth/sessionManager.d.ts +2 -0
- package/dist/auth/sessionManager.js +53 -11
- package/dist/auth/tokenStore.d.ts +2 -1
- package/dist/auth/tokenStore.js +45 -4
- package/dist/autoresearch/tools.d.ts +1 -16
- package/dist/browser/neurolink.min.js +353 -353
- package/dist/cli/commands/config.d.ts +3 -123
- package/dist/cli/commands/config.js +4 -2
- package/dist/cli/commands/evaluate.d.ts +1 -19
- package/dist/cli/commands/proxy.d.ts +1 -1
- package/dist/cli/commands/proxy.js +3 -0
- package/dist/cli/commands/rag.js +3 -0
- package/dist/cli/commands/setup-anthropic.d.ts +2 -6
- package/dist/cli/commands/setup-anthropic.js +1 -1
- package/dist/cli/commands/setup-azure.d.ts +2 -6
- package/dist/cli/commands/setup-azure.js +1 -1
- package/dist/cli/commands/setup-bedrock.d.ts +2 -6
- package/dist/cli/commands/setup-bedrock.js +1 -1
- package/dist/cli/commands/setup-gcp.d.ts +2 -6
- package/dist/cli/commands/setup-google-ai.d.ts +2 -6
- package/dist/cli/commands/setup-google-ai.js +1 -1
- package/dist/cli/commands/setup-huggingface.d.ts +1 -5
- package/dist/cli/commands/setup-mistral.d.ts +1 -5
- package/dist/cli/commands/setup-openai.d.ts +2 -6
- package/dist/cli/commands/setup-openai.js +1 -1
- package/dist/cli/commands/setup.d.ts +1 -8
- package/dist/cli/commands/task.js +1 -0
- package/dist/cli/commands/voiceServer.d.ts +1 -4
- package/dist/cli/loop/session.js +31 -10
- package/dist/cli/utils/interactiveSetup.d.ts +2 -15
- package/dist/cli/utils/videoFileUtils.d.ts +1 -15
- package/dist/client/aiSdkAdapter.d.ts +1 -1
- package/dist/client/aiSdkAdapter.js +1 -0
- package/dist/client/httpClient.d.ts +2 -2
- package/dist/client/httpClient.js +13 -0
- package/dist/client/sseClient.d.ts +2 -2
- package/dist/client/sseClient.js +29 -0
- package/dist/client/streamingClient.d.ts +2 -0
- package/dist/client/streamingClient.js +19 -0
- package/dist/client/wsClient.d.ts +7 -2
- package/dist/client/wsClient.js +90 -10
- package/dist/context/budgetChecker.js +3 -1
- package/dist/context/contextCompactor.js +163 -143
- package/dist/context/fileSummarizationService.d.ts +1 -9
- package/dist/context/summarizationEngine.js +29 -16
- package/dist/core/baseProvider.js +124 -153
- package/dist/core/infrastructure/baseRegistry.d.ts +1 -7
- package/dist/core/modules/GenerationHandler.d.ts +3 -2
- package/dist/core/modules/GenerationHandler.js +9 -1
- package/dist/core/modules/StreamHandler.js +9 -0
- package/dist/core/modules/ToolsManager.js +18 -2
- package/dist/core/toolEvents.d.ts +0 -1
- package/dist/evaluation/BatchEvaluator.d.ts +1 -97
- package/dist/evaluation/EvaluationAggregator.d.ts +1 -118
- package/dist/evaluation/EvaluatorFactory.d.ts +1 -13
- package/dist/evaluation/EvaluatorRegistry.d.ts +1 -50
- package/dist/evaluation/errors/EvaluationError.d.ts +2 -27
- package/dist/evaluation/hooks/langfuseAdapter.d.ts +1 -39
- package/dist/evaluation/hooks/observabilityHooks.d.ts +3 -55
- package/dist/evaluation/hooks/observabilityHooks.js +3 -0
- package/dist/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
- package/dist/evaluation/pipeline/strategies/batchStrategy.js +7 -7
- package/dist/evaluation/ragasEvaluator.js +54 -37
- package/dist/evaluation/reporting/metricsCollector.d.ts +1 -60
- package/dist/evaluation/reporting/reportGenerator.d.ts +1 -17
- package/dist/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
- package/dist/evaluation/scorers/rule/formatScorer.d.ts +1 -42
- package/dist/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
- package/dist/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
- package/dist/factories/providerFactory.d.ts +1 -16
- package/dist/factories/providerFactory.js +2 -0
- package/dist/image-gen/ImageGenService.d.ts +3 -0
- package/dist/image-gen/ImageGenService.js +3 -0
- package/dist/lib/action/actionInputs.d.ts +1 -1
- package/dist/lib/adapters/video/directorPipeline.js +6 -0
- package/dist/lib/adapters/video/vertexVideoHandler.js +6 -0
- package/dist/lib/agent/directTools.d.ts +3 -23
- package/dist/lib/auth/AuthProviderFactory.d.ts +1 -3
- package/dist/lib/auth/anthropicOAuth.d.ts +4 -7
- package/dist/lib/auth/anthropicOAuth.js +23 -0
- package/dist/lib/auth/errors.d.ts +1 -1
- package/dist/lib/auth/index.d.ts +11 -0
- package/dist/lib/auth/index.js +14 -0
- package/dist/lib/auth/middleware/AuthMiddleware.d.ts +5 -60
- package/dist/lib/auth/middleware/AuthMiddleware.js +3 -0
- package/dist/lib/auth/middleware/rateLimitByUser.d.ts +4 -93
- package/dist/lib/auth/middleware/rateLimitByUser.js +4 -0
- package/dist/lib/auth/providers/BaseAuthProvider.d.ts +1 -1
- package/dist/lib/auth/providers/CognitoProvider.js +3 -0
- package/dist/lib/auth/providers/KeycloakProvider.js +3 -0
- package/dist/lib/auth/providers/auth0.d.ts +1 -1
- package/dist/lib/auth/sessionManager.d.ts +2 -0
- package/dist/lib/auth/sessionManager.js +53 -11
- package/dist/lib/auth/tokenStore.d.ts +2 -1
- package/dist/lib/auth/tokenStore.js +45 -4
- package/dist/lib/autoresearch/tools.d.ts +1 -16
- package/dist/lib/client/aiSdkAdapter.d.ts +1 -1
- package/dist/lib/client/aiSdkAdapter.js +1 -0
- package/dist/lib/client/httpClient.d.ts +2 -2
- package/dist/lib/client/httpClient.js +13 -0
- package/dist/lib/client/sseClient.d.ts +2 -2
- package/dist/lib/client/sseClient.js +29 -0
- package/dist/lib/client/streamingClient.d.ts +2 -0
- package/dist/lib/client/streamingClient.js +19 -0
- package/dist/lib/client/wsClient.d.ts +7 -2
- package/dist/lib/client/wsClient.js +90 -10
- package/dist/lib/context/budgetChecker.js +3 -1
- package/dist/lib/context/contextCompactor.js +163 -143
- package/dist/lib/context/fileSummarizationService.d.ts +1 -9
- package/dist/lib/context/summarizationEngine.js +29 -16
- package/dist/lib/core/baseProvider.js +124 -153
- package/dist/lib/core/infrastructure/baseRegistry.d.ts +1 -7
- package/dist/lib/core/modules/GenerationHandler.d.ts +3 -2
- package/dist/lib/core/modules/GenerationHandler.js +9 -1
- package/dist/lib/core/modules/StreamHandler.js +9 -0
- package/dist/lib/core/modules/ToolsManager.js +18 -2
- package/dist/lib/core/toolEvents.d.ts +0 -1
- package/dist/lib/evaluation/BatchEvaluator.d.ts +1 -97
- package/dist/lib/evaluation/EvaluationAggregator.d.ts +1 -118
- package/dist/lib/evaluation/EvaluatorFactory.d.ts +1 -13
- package/dist/lib/evaluation/EvaluatorRegistry.d.ts +1 -50
- package/dist/lib/evaluation/errors/EvaluationError.d.ts +2 -27
- package/dist/lib/evaluation/hooks/langfuseAdapter.d.ts +1 -39
- package/dist/lib/evaluation/hooks/observabilityHooks.d.ts +3 -55
- package/dist/lib/evaluation/hooks/observabilityHooks.js +3 -0
- package/dist/lib/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
- package/dist/lib/evaluation/pipeline/strategies/batchStrategy.js +7 -7
- package/dist/lib/evaluation/ragasEvaluator.js +54 -37
- package/dist/lib/evaluation/reporting/metricsCollector.d.ts +1 -60
- package/dist/lib/evaluation/reporting/reportGenerator.d.ts +1 -17
- package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
- package/dist/lib/evaluation/scorers/rule/formatScorer.d.ts +1 -42
- package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
- package/dist/lib/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
- package/dist/lib/factories/providerFactory.d.ts +1 -16
- package/dist/lib/factories/providerFactory.js +2 -0
- package/dist/lib/image-gen/ImageGenService.d.ts +3 -0
- package/dist/lib/image-gen/ImageGenService.js +3 -0
- package/dist/lib/mcp/batching/requestBatcher.js +99 -73
- package/dist/lib/mcp/httpRateLimiter.js +3 -1
- package/dist/lib/mcp/httpRetryHandler.js +3 -1
- package/dist/lib/mcp/mcpClientFactory.js +3 -1
- package/dist/lib/mcp/multiServerManager.d.ts +1 -14
- package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
- package/dist/lib/mcp/toolDiscoveryService.js +70 -57
- package/dist/lib/mcp/toolRegistry.js +11 -1
- package/dist/lib/memory/hippocampusInitializer.d.ts +1 -2
- package/dist/lib/memory/hippocampusInitializer.js +1 -1
- package/dist/lib/memory/memoryRetrievalTools.js +182 -141
- package/dist/lib/models/anthropicModels.d.ts +0 -1
- package/dist/lib/models/anthropicModels.js +1 -0
- package/dist/lib/neurolink.js +237 -41
- package/dist/lib/observability/exporterRegistry.d.ts +3 -22
- package/dist/lib/observability/exporters/sentryExporter.js +1 -0
- package/dist/lib/observability/metricsAggregator.d.ts +1 -31
- package/dist/lib/observability/retryPolicy.d.ts +0 -1
- package/dist/lib/observability/sampling/samplers.d.ts +0 -1
- package/dist/lib/observability/spanProcessor.d.ts +0 -1
- package/dist/lib/observability/tokenTracker.d.ts +7 -16
- package/dist/lib/observability/tokenTracker.js +6 -4
- package/dist/lib/observability/utils/spanSerializer.d.ts +5 -1
- package/dist/lib/observability/utils/spanSerializer.js +24 -4
- package/dist/lib/processors/base/BaseFileProcessor.js +66 -53
- package/dist/lib/processors/document/ExcelProcessor.d.ts +1 -1
- package/dist/lib/processors/errors/errorHelpers.d.ts +1 -31
- package/dist/lib/processors/errors/errorSerializer.d.ts +1 -45
- package/dist/lib/processors/registry/ProcessorRegistry.js +17 -6
- package/dist/lib/providers/amazonBedrock.js +189 -15
- package/dist/lib/providers/amazonSagemaker.js +25 -11
- package/dist/lib/providers/anthropic.js +13 -0
- package/dist/lib/providers/azureOpenai.js +2 -0
- package/dist/lib/providers/googleAiStudio.js +82 -0
- package/dist/lib/providers/googleNativeGemini3.d.ts +1 -2
- package/dist/lib/providers/googleVertex.js +52 -0
- package/dist/lib/providers/huggingFace.js +2 -0
- package/dist/lib/providers/litellm.js +2 -0
- package/dist/lib/providers/mistral.js +2 -0
- package/dist/lib/providers/ollama.js +84 -5
- package/dist/lib/providers/openAI.d.ts +2 -0
- package/dist/lib/providers/openAI.js +17 -6
- package/dist/lib/providers/openRouter.js +2 -0
- package/dist/lib/providers/openaiCompatible.js +2 -0
- package/dist/lib/providers/sagemaker/detection.d.ts +1 -33
- package/dist/lib/providers/sagemaker/diagnostics.d.ts +1 -25
- package/dist/lib/providers/sagemaker/language-model.d.ts +1 -1
- package/dist/lib/proxy/proxyConfig.js +4 -0
- package/dist/lib/proxy/proxyEnv.d.ts +1 -17
- package/dist/lib/proxy/proxyHealth.d.ts +0 -1
- package/dist/lib/proxy/proxyTracer.d.ts +1 -36
- package/dist/lib/proxy/proxyTracer.js +9 -0
- package/dist/lib/proxy/quietDetector.d.ts +1 -7
- package/dist/lib/proxy/rawStreamCapture.d.ts +1 -10
- package/dist/lib/proxy/requestLogger.d.ts +1 -21
- package/dist/lib/proxy/routingPolicy.d.ts +1 -2
- package/dist/lib/proxy/sseInterceptor.d.ts +1 -66
- package/dist/lib/proxy/sseInterceptor.js +6 -0
- package/dist/lib/proxy/updateChecker.d.ts +1 -6
- package/dist/lib/proxy/updateState.d.ts +1 -12
- package/dist/lib/rag/chunkers/BaseChunker.js +36 -22
- package/dist/lib/rag/chunking/jsonChunker.d.ts +1 -1
- package/dist/lib/rag/errors/RAGError.d.ts +1 -2
- package/dist/lib/rag/ragIntegration.js +45 -32
- package/dist/lib/rag/reranker/reranker.js +151 -122
- package/dist/lib/rag/retrieval/vectorQueryTool.js +79 -65
- package/dist/lib/sdk/toolRegistration.d.ts +10 -44
- package/dist/lib/sdk/toolRegistration.js +1 -1
- package/dist/lib/server/middleware/abortSignal.d.ts +1 -11
- package/dist/lib/server/middleware/auth.d.ts +1 -21
- package/dist/lib/server/middleware/auth.js +12 -0
- package/dist/lib/server/middleware/common.js +48 -32
- package/dist/lib/server/middleware/deprecation.d.ts +1 -20
- package/dist/lib/server/middleware/rateLimit.d.ts +1 -75
- package/dist/lib/server/middleware/validation.d.ts +3 -81
- package/dist/lib/server/middleware/validation.js +3 -0
- package/dist/lib/server/openapi/generator.d.ts +1 -47
- package/dist/lib/server/routes/agentRoutes.js +112 -57
- package/dist/lib/server/routes/claudeProxyRoutes.d.ts +1 -6
- package/dist/lib/server/routes/claudeProxyRoutes.js +127 -13
- package/dist/lib/server/routes/healthRoutes.js +58 -12
- package/dist/lib/server/routes/index.d.ts +1 -26
- package/dist/lib/server/routes/mcpRoutes.js +40 -7
- package/dist/lib/server/routes/memoryRoutes.js +22 -7
- package/dist/lib/server/routes/openApiRoutes.js +30 -6
- package/dist/lib/server/routes/toolRoutes.js +140 -68
- package/dist/lib/server/streaming/dataStream.d.ts +1 -35
- package/dist/lib/server/streaming/dataStream.js +15 -0
- package/dist/lib/services/server/ai/observability/instrumentation.js +114 -14
- package/dist/lib/session/globalSessionState.d.ts +1 -10
- package/dist/lib/tasks/tools/taskTools.d.ts +2 -2
- package/dist/lib/telemetry/traceContext.d.ts +9 -0
- package/dist/lib/telemetry/traceContext.js +19 -0
- package/dist/lib/telemetry/tracers.d.ts +2 -0
- package/dist/lib/telemetry/tracers.js +2 -0
- package/dist/lib/types/action.d.ts +2 -0
- package/dist/lib/types/artifact.d.ts +7 -0
- package/dist/lib/types/auth.d.ts +125 -18
- package/dist/lib/types/autoresearch.d.ts +12 -0
- package/dist/lib/types/cli.d.ts +415 -0
- package/dist/lib/types/client.d.ts +34 -0
- package/dist/lib/types/common.d.ts +12 -41
- package/dist/lib/types/context.d.ts +5 -0
- package/dist/lib/types/evaluation.d.ts +332 -1
- package/dist/lib/types/file.d.ts +4 -0
- package/dist/lib/types/mcp.d.ts +102 -2
- package/dist/lib/types/middleware.d.ts +116 -0
- package/dist/lib/types/multimodal.d.ts +65 -0
- package/dist/lib/types/observability.d.ts +81 -0
- package/dist/lib/types/processor.d.ts +47 -0
- package/dist/lib/types/providers.d.ts +120 -16
- package/dist/lib/types/proxy.d.ts +321 -1
- package/dist/lib/types/rag.d.ts +22 -0
- package/dist/lib/types/scorer.d.ts +141 -0
- package/dist/lib/types/server.d.ts +99 -0
- package/dist/lib/types/span.d.ts +2 -1
- package/dist/lib/types/span.js +1 -0
- package/dist/lib/types/tools.d.ts +44 -0
- package/dist/lib/types/tts.d.ts +6 -0
- package/dist/lib/types/utilities.d.ts +22 -0
- package/dist/lib/types/workflow.d.ts +18 -0
- package/dist/lib/utils/async/retry.d.ts +2 -8
- package/dist/lib/utils/async/retry.js +9 -9
- package/dist/lib/utils/imageCompressor.d.ts +1 -21
- package/dist/lib/utils/imageCompressor.js +5 -1
- package/dist/lib/utils/messageBuilder.d.ts +1 -1
- package/dist/lib/utils/redis.d.ts +1 -4
- package/dist/lib/utils/sanitizers/filename.d.ts +0 -1
- package/dist/lib/utils/toolEndEmitter.d.ts +25 -0
- package/dist/lib/utils/toolEndEmitter.js +65 -0
- package/dist/lib/workflow/config.d.ts +7 -32
- package/dist/lib/workflow/core/ensembleExecutor.js +28 -0
- package/dist/lib/workflow/core/judgeScorer.js +23 -0
- package/dist/lib/workflow/core/responseConditioner.js +17 -0
- package/dist/lib/workflow/core/workflowRunner.d.ts +1 -19
- package/dist/lib/workflow/core/workflowRunner.js +202 -147
- package/dist/mcp/batching/requestBatcher.js +99 -73
- package/dist/mcp/httpRateLimiter.js +3 -1
- package/dist/mcp/httpRetryHandler.js +3 -1
- package/dist/mcp/mcpClientFactory.js +3 -1
- package/dist/mcp/multiServerManager.d.ts +1 -14
- package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
- package/dist/mcp/toolDiscoveryService.js +70 -57
- package/dist/mcp/toolRegistry.js +11 -1
- package/dist/memory/hippocampusInitializer.d.ts +1 -2
- package/dist/memory/hippocampusInitializer.js +1 -1
- package/dist/memory/memoryRetrievalTools.js +182 -141
- package/dist/models/anthropicModels.d.ts +0 -1
- package/dist/models/anthropicModels.js +1 -0
- package/dist/neurolink.js +237 -41
- package/dist/observability/exporterRegistry.d.ts +3 -22
- package/dist/observability/exporters/sentryExporter.js +1 -0
- package/dist/observability/metricsAggregator.d.ts +1 -31
- package/dist/observability/retryPolicy.d.ts +0 -1
- package/dist/observability/sampling/samplers.d.ts +0 -1
- package/dist/observability/spanProcessor.d.ts +0 -1
- package/dist/observability/tokenTracker.d.ts +7 -16
- package/dist/observability/tokenTracker.js +6 -4
- package/dist/observability/utils/spanSerializer.d.ts +5 -1
- package/dist/observability/utils/spanSerializer.js +24 -4
- package/dist/processors/base/BaseFileProcessor.js +66 -53
- package/dist/processors/document/ExcelProcessor.d.ts +1 -1
- package/dist/processors/errors/errorHelpers.d.ts +1 -31
- package/dist/processors/errors/errorSerializer.d.ts +1 -45
- package/dist/processors/registry/ProcessorRegistry.js +17 -6
- package/dist/providers/amazonBedrock.js +189 -15
- package/dist/providers/amazonSagemaker.js +25 -11
- package/dist/providers/anthropic.js +13 -0
- package/dist/providers/azureOpenai.js +2 -0
- package/dist/providers/googleAiStudio.js +82 -0
- package/dist/providers/googleNativeGemini3.d.ts +1 -2
- package/dist/providers/googleVertex.js +52 -0
- package/dist/providers/huggingFace.js +2 -0
- package/dist/providers/litellm.js +2 -0
- package/dist/providers/mistral.js +2 -0
- package/dist/providers/ollama.js +84 -5
- package/dist/providers/openAI.d.ts +2 -0
- package/dist/providers/openAI.js +17 -6
- package/dist/providers/openRouter.js +2 -0
- package/dist/providers/openaiCompatible.js +2 -0
- package/dist/providers/sagemaker/detection.d.ts +1 -33
- package/dist/providers/sagemaker/diagnostics.d.ts +1 -25
- package/dist/providers/sagemaker/language-model.d.ts +1 -1
- package/dist/proxy/proxyConfig.js +4 -0
- package/dist/proxy/proxyEnv.d.ts +1 -17
- package/dist/proxy/proxyHealth.d.ts +0 -1
- package/dist/proxy/proxyTracer.d.ts +1 -36
- package/dist/proxy/proxyTracer.js +9 -0
- package/dist/proxy/quietDetector.d.ts +1 -7
- package/dist/proxy/rawStreamCapture.d.ts +1 -10
- package/dist/proxy/requestLogger.d.ts +1 -21
- package/dist/proxy/routingPolicy.d.ts +1 -2
- package/dist/proxy/sseInterceptor.d.ts +1 -66
- package/dist/proxy/sseInterceptor.js +6 -0
- package/dist/proxy/updateChecker.d.ts +1 -6
- package/dist/proxy/updateState.d.ts +1 -12
- package/dist/rag/chunkers/BaseChunker.js +36 -22
- package/dist/rag/chunking/jsonChunker.d.ts +1 -1
- package/dist/rag/errors/RAGError.d.ts +1 -2
- package/dist/rag/ragIntegration.js +45 -32
- package/dist/rag/reranker/reranker.js +151 -122
- package/dist/rag/retrieval/vectorQueryTool.js +79 -65
- package/dist/sdk/toolRegistration.d.ts +10 -44
- package/dist/sdk/toolRegistration.js +1 -1
- package/dist/server/middleware/abortSignal.d.ts +1 -11
- package/dist/server/middleware/auth.d.ts +1 -21
- package/dist/server/middleware/auth.js +12 -0
- package/dist/server/middleware/common.js +48 -32
- package/dist/server/middleware/deprecation.d.ts +1 -20
- package/dist/server/middleware/rateLimit.d.ts +1 -75
- package/dist/server/middleware/validation.d.ts +3 -81
- package/dist/server/middleware/validation.js +3 -0
- package/dist/server/openapi/generator.d.ts +1 -47
- package/dist/server/routes/agentRoutes.js +112 -57
- package/dist/server/routes/claudeProxyRoutes.d.ts +1 -6
- package/dist/server/routes/claudeProxyRoutes.js +127 -13
- package/dist/server/routes/healthRoutes.js +58 -12
- package/dist/server/routes/index.d.ts +1 -26
- package/dist/server/routes/mcpRoutes.js +40 -7
- package/dist/server/routes/memoryRoutes.js +22 -7
- package/dist/server/routes/openApiRoutes.js +30 -6
- package/dist/server/routes/toolRoutes.js +140 -68
- package/dist/server/streaming/dataStream.d.ts +1 -35
- package/dist/server/streaming/dataStream.js +15 -0
- package/dist/services/server/ai/observability/instrumentation.js +114 -14
- package/dist/session/globalSessionState.d.ts +1 -10
- package/dist/tasks/tools/taskTools.d.ts +2 -2
- package/dist/telemetry/traceContext.d.ts +9 -0
- package/dist/telemetry/traceContext.js +18 -0
- package/dist/telemetry/tracers.d.ts +2 -0
- package/dist/telemetry/tracers.js +2 -0
- package/dist/types/action.d.ts +2 -0
- package/dist/types/artifact.d.ts +7 -0
- package/dist/types/auth.d.ts +125 -18
- package/dist/types/autoresearch.d.ts +12 -0
- package/dist/types/cli.d.ts +415 -0
- package/dist/types/client.d.ts +34 -0
- package/dist/types/common.d.ts +12 -41
- package/dist/types/context.d.ts +5 -0
- package/dist/types/evaluation.d.ts +332 -1
- package/dist/types/file.d.ts +4 -0
- package/dist/types/mcp.d.ts +102 -2
- package/dist/types/middleware.d.ts +116 -0
- package/dist/types/multimodal.d.ts +65 -0
- package/dist/types/observability.d.ts +81 -0
- package/dist/types/processor.d.ts +47 -0
- package/dist/types/providers.d.ts +120 -16
- package/dist/types/proxy.d.ts +321 -1
- package/dist/types/rag.d.ts +22 -0
- package/dist/types/scorer.d.ts +141 -0
- package/dist/types/server.d.ts +99 -0
- package/dist/types/span.d.ts +2 -1
- package/dist/types/span.js +1 -0
- package/dist/types/tools.d.ts +44 -0
- package/dist/types/tts.d.ts +6 -0
- package/dist/types/utilities.d.ts +22 -0
- package/dist/types/workflow.d.ts +18 -0
- package/dist/utils/async/retry.d.ts +2 -8
- package/dist/utils/async/retry.js +9 -9
- package/dist/utils/imageCompressor.d.ts +1 -21
- package/dist/utils/imageCompressor.js +5 -1
- package/dist/utils/messageBuilder.d.ts +1 -1
- package/dist/utils/redis.d.ts +1 -4
- package/dist/utils/sanitizers/filename.d.ts +0 -1
- package/dist/utils/toolEndEmitter.d.ts +25 -0
- package/dist/utils/toolEndEmitter.js +64 -0
- package/dist/workflow/config.d.ts +4 -29
- package/dist/workflow/core/ensembleExecutor.js +28 -0
- package/dist/workflow/core/judgeScorer.js +23 -0
- package/dist/workflow/core/responseConditioner.js +17 -0
- package/dist/workflow/core/workflowRunner.d.ts +1 -19
- package/dist/workflow/core/workflowRunner.js +202 -147
- package/package.json +2 -1
|
@@ -12,6 +12,9 @@ import { estimateMessagesTokens } from "../utils/tokenEstimation.js";
|
|
|
12
12
|
import { logger } from "../utils/logger.js";
|
|
13
13
|
import { withTimeout } from "../utils/async/withTimeout.js";
|
|
14
14
|
import { SpanSerializer, SpanType, SpanStatus, getMetricsAggregator, } from "../observability/index.js";
|
|
15
|
+
import { getActiveTraceContext } from "../telemetry/traceContext.js";
|
|
16
|
+
import { withSpan } from "../telemetry/withSpan.js";
|
|
17
|
+
import { tracers } from "../telemetry/tracers.js";
|
|
15
18
|
import { pruneToolOutputs } from "./stages/toolOutputPruner.js";
|
|
16
19
|
import { deduplicateFileReads } from "./stages/fileReadDeduplicator.js";
|
|
17
20
|
import { truncateWithSlidingWindow } from "./stages/slidingWindowTruncator.js";
|
|
@@ -39,167 +42,184 @@ export class ContextCompactor {
|
|
|
39
42
|
* Run the multi-stage compaction pipeline until messages fit within budget.
|
|
40
43
|
*/
|
|
41
44
|
async compact(messages, targetTokens, memoryConfig, requestId) {
|
|
42
|
-
|
|
43
|
-
"context.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
let
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
protectTokens: this.config.pruneProtectTokens,
|
|
63
|
-
minimumSavings: this.config.pruneMinimumSavings,
|
|
64
|
-
protectedTools: this.config.pruneProtectedTools,
|
|
65
|
-
provider,
|
|
66
|
-
});
|
|
67
|
-
if (pruneResult.pruned) {
|
|
68
|
-
currentMessages = pruneResult.messages;
|
|
69
|
-
stagesUsed.push("prune");
|
|
70
|
-
}
|
|
71
|
-
const stageTokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
72
|
-
logger.info("[Compaction] Stage 1 (prune)", {
|
|
45
|
+
return withSpan({
|
|
46
|
+
name: "neurolink.context.compact",
|
|
47
|
+
tracer: tracers.context,
|
|
48
|
+
attributes: {
|
|
49
|
+
"context.target_tokens": targetTokens,
|
|
50
|
+
"context.message_count": messages.length,
|
|
51
|
+
},
|
|
52
|
+
}, async () => {
|
|
53
|
+
const { traceId, parentSpanId } = getActiveTraceContext();
|
|
54
|
+
let span = SpanSerializer.createSpan(SpanType.CONTEXT_COMPACTION, "context.compact", {
|
|
55
|
+
"context.operation": "compact",
|
|
56
|
+
"context.targetTokens": targetTokens,
|
|
57
|
+
}, parentSpanId, traceId);
|
|
58
|
+
const spanStartTime = Date.now();
|
|
59
|
+
try {
|
|
60
|
+
const provider = this.config.provider || undefined;
|
|
61
|
+
const tokensBefore = estimateMessagesTokens(messages, provider);
|
|
62
|
+
const stagesUsed = [];
|
|
63
|
+
let currentMessages = [...messages];
|
|
64
|
+
logger.info("[Compaction] Starting", {
|
|
73
65
|
requestId,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
tokensAfter: stageTokensAfter,
|
|
77
|
-
saved: stageTokensBefore - stageTokensAfter,
|
|
66
|
+
estimatedTokens: tokensBefore,
|
|
67
|
+
budgetTokens: targetTokens,
|
|
78
68
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
ran: dedupResult.deduplicated,
|
|
93
|
-
tokensBefore: stageTokensBefore,
|
|
94
|
-
tokensAfter: stageTokensAfter,
|
|
95
|
-
saved: stageTokensBefore - stageTokensAfter,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
// Stage 3: LLM Summarization
|
|
99
|
-
if (this.config.enableSummarize &&
|
|
100
|
-
estimateMessagesTokens(currentMessages, provider) > targetTokens) {
|
|
101
|
-
const stageTokensBefore = estimateMessagesTokens(currentMessages, provider);
|
|
102
|
-
try {
|
|
103
|
-
const summarizeResult = await withTimeout(summarizeMessages(currentMessages, {
|
|
104
|
-
provider: this.config.summarizationProvider,
|
|
105
|
-
model: this.config.summarizationModel,
|
|
106
|
-
keepRecentRatio: this.config.keepRecentRatio,
|
|
107
|
-
memoryConfig,
|
|
108
|
-
targetTokens,
|
|
109
|
-
}), 120_000, "LLM summarization timed out after 120s");
|
|
110
|
-
if (summarizeResult.summarized) {
|
|
111
|
-
currentMessages = summarizeResult.messages;
|
|
112
|
-
stagesUsed.push("summarize");
|
|
69
|
+
// Stage 1: Tool Output Pruning
|
|
70
|
+
if (this.config.enablePrune &&
|
|
71
|
+
estimateMessagesTokens(currentMessages, provider) > targetTokens) {
|
|
72
|
+
const stageTokensBefore = estimateMessagesTokens(currentMessages, provider);
|
|
73
|
+
const pruneResult = pruneToolOutputs(currentMessages, {
|
|
74
|
+
protectTokens: this.config.pruneProtectTokens,
|
|
75
|
+
minimumSavings: this.config.pruneMinimumSavings,
|
|
76
|
+
protectedTools: this.config.pruneProtectedTools,
|
|
77
|
+
provider,
|
|
78
|
+
});
|
|
79
|
+
if (pruneResult.pruned) {
|
|
80
|
+
currentMessages = pruneResult.messages;
|
|
81
|
+
stagesUsed.push("prune");
|
|
113
82
|
}
|
|
114
83
|
const stageTokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
115
|
-
logger.info("[Compaction] Stage
|
|
84
|
+
logger.info("[Compaction] Stage 1 (prune)", {
|
|
116
85
|
requestId,
|
|
117
|
-
ran:
|
|
86
|
+
ran: pruneResult.pruned,
|
|
118
87
|
tokensBefore: stageTokensBefore,
|
|
119
88
|
tokensAfter: stageTokensAfter,
|
|
120
89
|
saved: stageTokensBefore - stageTokensAfter,
|
|
121
90
|
});
|
|
122
91
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
92
|
+
// Stage 2: File Read Deduplication
|
|
93
|
+
if (this.config.enableDeduplicate &&
|
|
94
|
+
estimateMessagesTokens(currentMessages, provider) > targetTokens) {
|
|
95
|
+
const stageTokensBefore = estimateMessagesTokens(currentMessages, provider);
|
|
96
|
+
const dedupResult = deduplicateFileReads(currentMessages);
|
|
97
|
+
if (dedupResult.deduplicated) {
|
|
98
|
+
currentMessages = dedupResult.messages;
|
|
99
|
+
stagesUsed.push("deduplicate");
|
|
100
|
+
}
|
|
101
|
+
const stageTokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
102
|
+
logger.info("[Compaction] Stage 2 (deduplicate)", {
|
|
126
103
|
requestId,
|
|
127
|
-
|
|
128
|
-
errorName: err.name,
|
|
104
|
+
ran: dedupResult.deduplicated,
|
|
129
105
|
tokensBefore: stageTokensBefore,
|
|
130
|
-
tokensAfter:
|
|
131
|
-
saved:
|
|
132
|
-
});
|
|
133
|
-
// Record failure on the compaction span for trace visibility
|
|
134
|
-
span = SpanSerializer.updateAttributes(span, {
|
|
135
|
-
"compaction.stage3.error": err.message,
|
|
136
|
-
"compaction.stage3.errorName": err.name,
|
|
137
|
-
"compaction.stage3.tokensBefore": stageTokensBefore,
|
|
138
|
-
"compaction.stage3_failed": true,
|
|
106
|
+
tokensAfter: stageTokensAfter,
|
|
107
|
+
saved: stageTokensBefore - stageTokensAfter,
|
|
139
108
|
});
|
|
140
|
-
// Fall through to Stage 4 truncation as before
|
|
141
109
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
110
|
+
// Stage 3: LLM Summarization
|
|
111
|
+
if (this.config.enableSummarize &&
|
|
112
|
+
estimateMessagesTokens(currentMessages, provider) > targetTokens) {
|
|
113
|
+
const stageTokensBefore = estimateMessagesTokens(currentMessages, provider);
|
|
114
|
+
try {
|
|
115
|
+
const summarizeResult = await withTimeout(summarizeMessages(currentMessages, {
|
|
116
|
+
provider: this.config.summarizationProvider,
|
|
117
|
+
model: this.config.summarizationModel,
|
|
118
|
+
keepRecentRatio: this.config.keepRecentRatio,
|
|
119
|
+
memoryConfig,
|
|
120
|
+
targetTokens,
|
|
121
|
+
}), 120_000, "LLM summarization timed out after 120s");
|
|
122
|
+
if (summarizeResult.summarized) {
|
|
123
|
+
currentMessages = summarizeResult.messages;
|
|
124
|
+
stagesUsed.push("summarize");
|
|
125
|
+
}
|
|
126
|
+
const stageTokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
127
|
+
logger.info("[Compaction] Stage 3 (summarize)", {
|
|
128
|
+
requestId,
|
|
129
|
+
ran: summarizeResult.summarized,
|
|
130
|
+
tokensBefore: stageTokensBefore,
|
|
131
|
+
tokensAfter: stageTokensAfter,
|
|
132
|
+
saved: stageTokensBefore - stageTokensAfter,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
137
|
+
logger.warn("[Compaction] Stage 3 (summarize) FAILED", {
|
|
138
|
+
requestId,
|
|
139
|
+
error: err.message,
|
|
140
|
+
errorName: err.name,
|
|
141
|
+
tokensBefore: stageTokensBefore,
|
|
142
|
+
tokensAfter: stageTokensBefore,
|
|
143
|
+
saved: 0,
|
|
144
|
+
});
|
|
145
|
+
// Record failure on the compaction span for trace visibility
|
|
146
|
+
span = SpanSerializer.updateAttributes(span, {
|
|
147
|
+
"compaction.stage3.error": err.message,
|
|
148
|
+
"compaction.stage3.errorName": err.name,
|
|
149
|
+
"compaction.stage3.tokensBefore": stageTokensBefore,
|
|
150
|
+
"compaction.stage3_failed": true,
|
|
151
|
+
});
|
|
152
|
+
// Fall through to Stage 4 truncation as before
|
|
153
|
+
}
|
|
158
154
|
}
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
// Stage 4: Sliding Window Truncation (fallback)
|
|
156
|
+
if (this.config.enableTruncate &&
|
|
157
|
+
estimateMessagesTokens(currentMessages, provider) > targetTokens) {
|
|
158
|
+
const stageTokensBefore = estimateMessagesTokens(currentMessages, provider);
|
|
159
|
+
const truncResult = truncateWithSlidingWindow(currentMessages, {
|
|
160
|
+
fraction: this.config.truncationFraction,
|
|
161
|
+
currentTokens: stageTokensBefore,
|
|
162
|
+
targetTokens: targetTokens,
|
|
163
|
+
provider: provider,
|
|
164
|
+
adaptiveBuffer: 0.15,
|
|
165
|
+
maxIterations: 6,
|
|
166
|
+
});
|
|
167
|
+
if (truncResult.truncated) {
|
|
168
|
+
currentMessages = truncResult.messages;
|
|
169
|
+
stagesUsed.push("truncate");
|
|
170
|
+
}
|
|
171
|
+
const stageTokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
172
|
+
logger.info("[Compaction] Stage 4 (truncate)", {
|
|
173
|
+
requestId,
|
|
174
|
+
ran: truncResult.truncated,
|
|
175
|
+
tokensBefore: stageTokensBefore,
|
|
176
|
+
tokensAfter: stageTokensAfter,
|
|
177
|
+
saved: stageTokensBefore - stageTokensAfter,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
const tokensAfter = estimateMessagesTokens(currentMessages, provider);
|
|
181
|
+
logger.info("[Compaction] Complete", {
|
|
161
182
|
requestId,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
183
|
+
tokensBefore,
|
|
184
|
+
tokensAfter,
|
|
185
|
+
totalSaved: tokensBefore - tokensAfter,
|
|
186
|
+
stagesUsed,
|
|
187
|
+
durationMs: Date.now() - spanStartTime,
|
|
166
188
|
});
|
|
189
|
+
const result = {
|
|
190
|
+
compacted: stagesUsed.length > 0,
|
|
191
|
+
stagesUsed,
|
|
192
|
+
tokensBefore,
|
|
193
|
+
tokensAfter,
|
|
194
|
+
tokensSaved: tokensBefore - tokensAfter,
|
|
195
|
+
messages: currentMessages,
|
|
196
|
+
};
|
|
197
|
+
span.durationMs = Date.now() - spanStartTime;
|
|
198
|
+
const compactionSucceeded = tokensAfter <= targetTokens;
|
|
199
|
+
const finalStatus = compactionSucceeded
|
|
200
|
+
? SpanStatus.OK
|
|
201
|
+
: SpanStatus.WARNING;
|
|
202
|
+
const finalMessage = compactionSucceeded
|
|
203
|
+
? undefined
|
|
204
|
+
: `Compaction insufficient: ${tokensAfter} tokens remain (target: ${targetTokens})`;
|
|
205
|
+
const endedSpan = SpanSerializer.endSpan(SpanSerializer.updateAttributes(span, {
|
|
206
|
+
"context.stage": stagesUsed.join(",") || "none",
|
|
207
|
+
"context.tokensBefore": tokensBefore,
|
|
208
|
+
"context.tokensAfter": tokensAfter,
|
|
209
|
+
"context.tokensSaved": tokensBefore - tokensAfter,
|
|
210
|
+
}), finalStatus, finalMessage);
|
|
211
|
+
getMetricsAggregator().recordSpan(endedSpan);
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
span.durationMs = Date.now() - spanStartTime;
|
|
216
|
+
const endedSpan = SpanSerializer.endSpan(span, SpanStatus.ERROR);
|
|
217
|
+
endedSpan.statusMessage =
|
|
218
|
+
error instanceof Error ? error.message : String(error);
|
|
219
|
+
getMetricsAggregator().recordSpan(endedSpan);
|
|
220
|
+
throw error;
|
|
167
221
|
}
|
|
168
|
-
|
|
169
|
-
logger.info("[Compaction] Complete", {
|
|
170
|
-
requestId,
|
|
171
|
-
tokensBefore,
|
|
172
|
-
tokensAfter,
|
|
173
|
-
totalSaved: tokensBefore - tokensAfter,
|
|
174
|
-
stagesUsed,
|
|
175
|
-
durationMs: Date.now() - spanStartTime,
|
|
176
|
-
});
|
|
177
|
-
const result = {
|
|
178
|
-
compacted: stagesUsed.length > 0,
|
|
179
|
-
stagesUsed,
|
|
180
|
-
tokensBefore,
|
|
181
|
-
tokensAfter,
|
|
182
|
-
tokensSaved: tokensBefore - tokensAfter,
|
|
183
|
-
messages: currentMessages,
|
|
184
|
-
};
|
|
185
|
-
span.durationMs = Date.now() - spanStartTime;
|
|
186
|
-
const endedSpan = SpanSerializer.endSpan(SpanSerializer.updateAttributes(span, {
|
|
187
|
-
"context.stage": stagesUsed.join(",") || "none",
|
|
188
|
-
"context.tokensBefore": tokensBefore,
|
|
189
|
-
"context.tokensAfter": tokensAfter,
|
|
190
|
-
"context.tokensSaved": tokensBefore - tokensAfter,
|
|
191
|
-
}), SpanStatus.OK);
|
|
192
|
-
getMetricsAggregator().recordSpan(endedSpan);
|
|
193
|
-
return result;
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
span.durationMs = Date.now() - spanStartTime;
|
|
197
|
-
const endedSpan = SpanSerializer.endSpan(span, SpanStatus.ERROR);
|
|
198
|
-
endedSpan.statusMessage =
|
|
199
|
-
error instanceof Error ? error.message : String(error);
|
|
200
|
-
getMetricsAggregator().recordSpan(endedSpan);
|
|
201
|
-
throw error;
|
|
202
|
-
}
|
|
222
|
+
}); // end withSpan
|
|
203
223
|
}
|
|
204
224
|
}
|
|
205
225
|
//# sourceMappingURL=contextCompactor.js.map
|
|
@@ -11,14 +11,7 @@
|
|
|
11
11
|
* The LLM is instantiated via a *dynamic import* of NeuroLink to avoid
|
|
12
12
|
* circular dependency issues (NeuroLink → fileSummarizationService → NeuroLink).
|
|
13
13
|
*/
|
|
14
|
-
import type { FileSummarizationCheckParams,
|
|
15
|
-
/** Constructor options. */
|
|
16
|
-
type FileSummarizationServiceOptions = {
|
|
17
|
-
/** Provider used for the summarization LLM call (default: "vertex") */
|
|
18
|
-
provider?: string;
|
|
19
|
-
/** Model used for the summarization LLM call (default: "gemini-2.5-flash") */
|
|
20
|
-
model?: string;
|
|
21
|
-
};
|
|
14
|
+
import type { FileForSummarization, FileSummarizationCheckParams, FileSummarizationServiceOptions, RawFileInput, SummarizedFile } from "../types/index.js";
|
|
22
15
|
export declare class FileSummarizationService {
|
|
23
16
|
private readonly provider;
|
|
24
17
|
private readonly model;
|
|
@@ -50,4 +43,3 @@ export declare class FileSummarizationService {
|
|
|
50
43
|
*/
|
|
51
44
|
summarizeFiles(files: FileForSummarization[], userPrompt: string, budgetParams: FileSummarizationCheckParams): Promise<SummarizedFile[]>;
|
|
52
45
|
}
|
|
53
|
-
export {};
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import { TokenUtils } from "../constants/tokens.js";
|
|
8
8
|
import { buildContextFromPointer, generateSummary, } from "../utils/conversationMemory.js";
|
|
9
9
|
import { RECENT_MESSAGES_RATIO } from "../config/conversationMemory.js";
|
|
10
|
+
import { withSpan } from "../telemetry/withSpan.js";
|
|
11
|
+
import { tracers } from "../telemetry/tracers.js";
|
|
10
12
|
import { logger } from "../utils/logger.js";
|
|
11
13
|
/**
|
|
12
14
|
* Centralized summarization engine for conversation memory.
|
|
@@ -22,22 +24,33 @@ export class SummarizationEngine {
|
|
|
22
24
|
* @returns True if summarization was performed
|
|
23
25
|
*/
|
|
24
26
|
async checkAndSummarize(session, threshold, config, logPrefix = "[SummarizationEngine]", requestId) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
return withSpan({
|
|
28
|
+
name: "neurolink.memory.summarize",
|
|
29
|
+
tracer: tracers.memory,
|
|
30
|
+
attributes: {
|
|
31
|
+
"memory.session_id": session.sessionId ?? "unknown",
|
|
32
|
+
"memory.threshold": threshold,
|
|
33
|
+
},
|
|
34
|
+
}, async (span) => {
|
|
35
|
+
const contextMessages = buildContextFromPointer(session, requestId);
|
|
36
|
+
const tokenCount = this.estimateTokens(contextMessages);
|
|
37
|
+
session.lastTokenCount = tokenCount;
|
|
38
|
+
session.lastCountedAt = Date.now();
|
|
39
|
+
logger.info("[Summarization] Check", {
|
|
40
|
+
requestId,
|
|
41
|
+
sessionId: session.sessionId,
|
|
42
|
+
tokenCount,
|
|
43
|
+
threshold,
|
|
44
|
+
willSummarize: tokenCount >= threshold,
|
|
45
|
+
});
|
|
46
|
+
if (tokenCount >= threshold) {
|
|
47
|
+
await this.summarizeSession(session, threshold, config, logPrefix, requestId);
|
|
48
|
+
span.setAttribute("memory.summarized", true);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
span.setAttribute("memory.summarized", false);
|
|
52
|
+
return false;
|
|
53
|
+
}); // end withSpan
|
|
41
54
|
}
|
|
42
55
|
/**
|
|
43
56
|
* Perform token-based summarization on a session.
|