@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
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { logger } from "../../utils/logger.js";
|
|
6
6
|
import { OpenAPIGenerator } from "../openapi/generator.js";
|
|
7
|
+
import { withSpan } from "../../telemetry/withSpan.js";
|
|
8
|
+
import { tracers } from "../../telemetry/tracers.js";
|
|
7
9
|
/**
|
|
8
10
|
* Create OpenAPI documentation routes
|
|
9
11
|
*
|
|
@@ -44,7 +46,14 @@ export function createOpenApiRoutes(basePath = "/api", getRoutes) {
|
|
|
44
46
|
{
|
|
45
47
|
method: "GET",
|
|
46
48
|
path: `${basePath}/openapi.json`,
|
|
47
|
-
handler: async () => {
|
|
49
|
+
handler: async () => withSpan({
|
|
50
|
+
name: "neurolink.http.openapi.json",
|
|
51
|
+
tracer: tracers.http,
|
|
52
|
+
attributes: {
|
|
53
|
+
"http.route": `${basePath}/openapi.json`,
|
|
54
|
+
"openapi.format": "json",
|
|
55
|
+
},
|
|
56
|
+
}, async (span) => {
|
|
48
57
|
const routes = getRoutes?.() ?? [];
|
|
49
58
|
if (!getRoutes) {
|
|
50
59
|
logger.warn("[OpenAPI] No getRoutes callback provided. OpenAPI spec will use default endpoint definitions. " +
|
|
@@ -53,19 +62,27 @@ export function createOpenApiRoutes(basePath = "/api", getRoutes) {
|
|
|
53
62
|
else if (routes.length === 0) {
|
|
54
63
|
logger.debug("[OpenAPI] getRoutes returned empty array. No custom routes will be documented.");
|
|
55
64
|
}
|
|
65
|
+
span.setAttribute("openapi.route_count", routes.length);
|
|
56
66
|
const generator = new OpenAPIGenerator({
|
|
57
67
|
basePath,
|
|
58
68
|
routes,
|
|
59
69
|
});
|
|
60
70
|
return generator.generate();
|
|
61
|
-
},
|
|
71
|
+
}),
|
|
62
72
|
description: "Get OpenAPI specification as JSON",
|
|
63
73
|
tags: ["openapi", "documentation"],
|
|
64
74
|
},
|
|
65
75
|
{
|
|
66
76
|
method: "GET",
|
|
67
77
|
path: `${basePath}/openapi.yaml`,
|
|
68
|
-
handler: async () => {
|
|
78
|
+
handler: async () => withSpan({
|
|
79
|
+
name: "neurolink.http.openapi.yaml",
|
|
80
|
+
tracer: tracers.http,
|
|
81
|
+
attributes: {
|
|
82
|
+
"http.route": `${basePath}/openapi.yaml`,
|
|
83
|
+
"openapi.format": "yaml",
|
|
84
|
+
},
|
|
85
|
+
}, async (span) => {
|
|
69
86
|
const routes = getRoutes?.() ?? [];
|
|
70
87
|
if (!getRoutes) {
|
|
71
88
|
logger.warn("[OpenAPI] No getRoutes callback provided. OpenAPI spec will use default endpoint definitions. " +
|
|
@@ -74,6 +91,7 @@ export function createOpenApiRoutes(basePath = "/api", getRoutes) {
|
|
|
74
91
|
else if (routes.length === 0) {
|
|
75
92
|
logger.debug("[OpenAPI] getRoutes returned empty array. No custom routes will be documented.");
|
|
76
93
|
}
|
|
94
|
+
span.setAttribute("openapi.route_count", routes.length);
|
|
77
95
|
const generator = new OpenAPIGenerator({
|
|
78
96
|
basePath,
|
|
79
97
|
routes,
|
|
@@ -83,14 +101,20 @@ export function createOpenApiRoutes(basePath = "/api", getRoutes) {
|
|
|
83
101
|
contentType: "text/yaml",
|
|
84
102
|
body: generator.toYAML(),
|
|
85
103
|
};
|
|
86
|
-
},
|
|
104
|
+
}),
|
|
87
105
|
description: "Get OpenAPI specification as YAML",
|
|
88
106
|
tags: ["openapi", "documentation"],
|
|
89
107
|
},
|
|
90
108
|
{
|
|
91
109
|
method: "GET",
|
|
92
110
|
path: `${basePath}/docs`,
|
|
93
|
-
handler: async () => {
|
|
111
|
+
handler: async () => withSpan({
|
|
112
|
+
name: "neurolink.http.openapi.docs",
|
|
113
|
+
tracer: tracers.http,
|
|
114
|
+
attributes: {
|
|
115
|
+
"http.route": `${basePath}/docs`,
|
|
116
|
+
},
|
|
117
|
+
}, async () => {
|
|
94
118
|
const html = `<!DOCTYPE html>
|
|
95
119
|
<html>
|
|
96
120
|
<head>
|
|
@@ -117,7 +141,7 @@ export function createOpenApiRoutes(basePath = "/api", getRoutes) {
|
|
|
117
141
|
contentType: "text/html",
|
|
118
142
|
body: html,
|
|
119
143
|
};
|
|
120
|
-
},
|
|
144
|
+
}),
|
|
121
145
|
description: "Swagger UI documentation page",
|
|
122
146
|
tags: ["openapi", "documentation"],
|
|
123
147
|
},
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Tool Routes
|
|
3
3
|
* Endpoints for tool listing, discovery, and execution
|
|
4
4
|
*/
|
|
5
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
6
|
+
import { withSpan } from "../../telemetry/withSpan.js";
|
|
7
|
+
import { tracers } from "../../telemetry/tracers.js";
|
|
5
8
|
import { createErrorResponse, ToolArgumentsSchema, ToolExecuteRequestSchema, ToolNameParamSchema, validateParams, validateRequest, } from "../utils/validation.js";
|
|
6
9
|
/**
|
|
7
10
|
* Create tool routes
|
|
@@ -19,8 +22,13 @@ export function createToolRoutes(basePath = "/api") {
|
|
|
19
22
|
{
|
|
20
23
|
method: "GET",
|
|
21
24
|
path: `${basePath}/tools`,
|
|
22
|
-
handler: async (ctx) => {
|
|
25
|
+
handler: async (ctx) => withSpan({
|
|
26
|
+
name: "neurolink.http.tools.list",
|
|
27
|
+
tracer: tracers.http,
|
|
28
|
+
attributes: { "http.route": `${basePath}/tools` },
|
|
29
|
+
}, async (span) => {
|
|
23
30
|
const tools = await ctx.toolRegistry.listTools();
|
|
31
|
+
span.setAttribute("tools.count", tools.length);
|
|
24
32
|
return {
|
|
25
33
|
tools: tools.map((tool) => ({
|
|
26
34
|
name: tool.name,
|
|
@@ -30,7 +38,7 @@ export function createToolRoutes(basePath = "/api") {
|
|
|
30
38
|
})),
|
|
31
39
|
total: tools.length,
|
|
32
40
|
};
|
|
33
|
-
},
|
|
41
|
+
}),
|
|
34
42
|
description: "List all available tools",
|
|
35
43
|
tags: ["tools"],
|
|
36
44
|
},
|
|
@@ -38,7 +46,14 @@ export function createToolRoutes(basePath = "/api") {
|
|
|
38
46
|
{
|
|
39
47
|
method: "GET",
|
|
40
48
|
path: `${basePath}/tools/search`,
|
|
41
|
-
handler: async (ctx) => {
|
|
49
|
+
handler: async (ctx) => withSpan({
|
|
50
|
+
name: "neurolink.http.tools.search",
|
|
51
|
+
tracer: tracers.http,
|
|
52
|
+
attributes: {
|
|
53
|
+
"http.route": `${basePath}/tools/search`,
|
|
54
|
+
"tools.search.query": ctx.query.q ?? "",
|
|
55
|
+
},
|
|
56
|
+
}, async () => {
|
|
42
57
|
const { q, source, limit } = ctx.query;
|
|
43
58
|
const tools = await ctx.toolRegistry.listTools();
|
|
44
59
|
let filtered = tools;
|
|
@@ -65,7 +80,7 @@ export function createToolRoutes(basePath = "/api") {
|
|
|
65
80
|
total: filtered.length,
|
|
66
81
|
query: q || null,
|
|
67
82
|
};
|
|
68
|
-
},
|
|
83
|
+
}),
|
|
69
84
|
description: "Search tools by name or description",
|
|
70
85
|
tags: ["tools"],
|
|
71
86
|
},
|
|
@@ -80,38 +95,59 @@ export function createToolRoutes(basePath = "/api") {
|
|
|
80
95
|
return validation.error;
|
|
81
96
|
}
|
|
82
97
|
const request = validation.data;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
return withSpan({
|
|
99
|
+
name: "neurolink.http.tools.execute",
|
|
100
|
+
tracer: tracers.http,
|
|
101
|
+
attributes: {
|
|
102
|
+
"http.route": `${basePath}/tools/execute`,
|
|
103
|
+
"tool.name": request.name,
|
|
104
|
+
},
|
|
105
|
+
}, async (span) => {
|
|
106
|
+
const startTime = Date.now();
|
|
107
|
+
try {
|
|
108
|
+
// Get tool from registry
|
|
109
|
+
const tools = await ctx.toolRegistry.listTools();
|
|
110
|
+
const tool = tools.find((t) => t.name === request.name);
|
|
111
|
+
if (!tool) {
|
|
112
|
+
span.setAttribute("tool.found", false);
|
|
113
|
+
span.setStatus({
|
|
114
|
+
code: SpanStatusCode.ERROR,
|
|
115
|
+
message: `Tool '${request.name}' not found`,
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
error: `Tool '${request.name}' not found`,
|
|
120
|
+
duration: Date.now() - startTime,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// Execute the tool
|
|
124
|
+
const result = await ctx.toolRegistry.executeTool(request.name, request.arguments);
|
|
125
|
+
span.setAttribute("tool.success", true);
|
|
126
|
+
return {
|
|
127
|
+
success: true,
|
|
128
|
+
data: result,
|
|
129
|
+
duration: Date.now() - startTime,
|
|
130
|
+
metadata: {
|
|
131
|
+
toolName: request.name,
|
|
132
|
+
sessionId: request.sessionId || null,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
138
|
+
span.setAttribute("tool.success", false);
|
|
139
|
+
span.setStatus({
|
|
140
|
+
code: SpanStatusCode.ERROR,
|
|
141
|
+
message: errorMessage,
|
|
142
|
+
});
|
|
143
|
+
span.recordException(error instanceof Error ? error : new Error(errorMessage));
|
|
89
144
|
return {
|
|
90
145
|
success: false,
|
|
91
|
-
error:
|
|
146
|
+
error: errorMessage,
|
|
92
147
|
duration: Date.now() - startTime,
|
|
93
148
|
};
|
|
94
149
|
}
|
|
95
|
-
|
|
96
|
-
const result = await ctx.toolRegistry.executeTool(request.name, request.arguments);
|
|
97
|
-
return {
|
|
98
|
-
success: true,
|
|
99
|
-
data: result,
|
|
100
|
-
duration: Date.now() - startTime,
|
|
101
|
-
metadata: {
|
|
102
|
-
toolName: request.name,
|
|
103
|
-
sessionId: request.sessionId || null,
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
109
|
-
return {
|
|
110
|
-
success: false,
|
|
111
|
-
error: errorMessage,
|
|
112
|
-
duration: Date.now() - startTime,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
150
|
+
});
|
|
115
151
|
},
|
|
116
152
|
description: "Execute a tool with arguments",
|
|
117
153
|
tags: ["tools"],
|
|
@@ -133,37 +169,58 @@ export function createToolRoutes(basePath = "/api") {
|
|
|
133
169
|
return bodyValidation.error;
|
|
134
170
|
}
|
|
135
171
|
const args = bodyValidation.data;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
172
|
+
return withSpan({
|
|
173
|
+
name: "neurolink.http.tools.executeByName",
|
|
174
|
+
tracer: tracers.http,
|
|
175
|
+
attributes: {
|
|
176
|
+
"http.route": `${basePath}/tools/:name/execute`,
|
|
177
|
+
"tool.name": name,
|
|
178
|
+
},
|
|
179
|
+
}, async (span) => {
|
|
180
|
+
const startTime = Date.now();
|
|
181
|
+
try {
|
|
182
|
+
// Get tool from registry
|
|
183
|
+
const tools = await ctx.toolRegistry.listTools();
|
|
184
|
+
const tool = tools.find((t) => t.name === name);
|
|
185
|
+
if (!tool) {
|
|
186
|
+
span.setAttribute("tool.found", false);
|
|
187
|
+
span.setStatus({
|
|
188
|
+
code: SpanStatusCode.ERROR,
|
|
189
|
+
message: `Tool '${name}' not found`,
|
|
190
|
+
});
|
|
191
|
+
return {
|
|
192
|
+
success: false,
|
|
193
|
+
error: `Tool '${name}' not found`,
|
|
194
|
+
duration: Date.now() - startTime,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
// Execute the tool
|
|
198
|
+
const result = await ctx.toolRegistry.executeTool(name, args);
|
|
199
|
+
span.setAttribute("tool.success", true);
|
|
200
|
+
return {
|
|
201
|
+
success: true,
|
|
202
|
+
data: result,
|
|
203
|
+
duration: Date.now() - startTime,
|
|
204
|
+
metadata: {
|
|
205
|
+
toolName: name,
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
211
|
+
span.setAttribute("tool.success", false);
|
|
212
|
+
span.setStatus({
|
|
213
|
+
code: SpanStatusCode.ERROR,
|
|
214
|
+
message: errorMessage,
|
|
215
|
+
});
|
|
216
|
+
span.recordException(error instanceof Error ? error : new Error(errorMessage));
|
|
142
217
|
return {
|
|
143
218
|
success: false,
|
|
144
|
-
error:
|
|
219
|
+
error: errorMessage,
|
|
145
220
|
duration: Date.now() - startTime,
|
|
146
221
|
};
|
|
147
222
|
}
|
|
148
|
-
|
|
149
|
-
const result = await ctx.toolRegistry.executeTool(name, args);
|
|
150
|
-
return {
|
|
151
|
-
success: true,
|
|
152
|
-
data: result,
|
|
153
|
-
duration: Date.now() - startTime,
|
|
154
|
-
metadata: {
|
|
155
|
-
toolName: name,
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
catch (error) {
|
|
160
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
161
|
-
return {
|
|
162
|
-
success: false,
|
|
163
|
-
error: errorMessage,
|
|
164
|
-
duration: Date.now() - startTime,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
223
|
+
});
|
|
167
224
|
},
|
|
168
225
|
description: "Execute a specific tool by name",
|
|
169
226
|
tags: ["tools"],
|
|
@@ -179,17 +236,32 @@ export function createToolRoutes(basePath = "/api") {
|
|
|
179
236
|
return paramValidation.error;
|
|
180
237
|
}
|
|
181
238
|
const { name } = paramValidation.data;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
239
|
+
return withSpan({
|
|
240
|
+
name: "neurolink.http.tools.get",
|
|
241
|
+
tracer: tracers.http,
|
|
242
|
+
attributes: {
|
|
243
|
+
"http.route": `${basePath}/tools/:name`,
|
|
244
|
+
"tool.name": name,
|
|
245
|
+
},
|
|
246
|
+
}, async (span) => {
|
|
247
|
+
const tools = await ctx.toolRegistry.listTools();
|
|
248
|
+
const tool = tools.find((t) => t.name === name);
|
|
249
|
+
if (!tool) {
|
|
250
|
+
span.setAttribute("tool.found", false);
|
|
251
|
+
span.setStatus({
|
|
252
|
+
code: SpanStatusCode.ERROR,
|
|
253
|
+
message: `Tool '${name}' not found`,
|
|
254
|
+
});
|
|
255
|
+
return createErrorResponse("TOOL_NOT_FOUND", `Tool '${name}' not found`, undefined, ctx.requestId);
|
|
256
|
+
}
|
|
257
|
+
span.setAttribute("tool.found", true);
|
|
258
|
+
return {
|
|
259
|
+
name: tool.name,
|
|
260
|
+
description: tool.description,
|
|
261
|
+
inputSchema: tool.inputSchema,
|
|
262
|
+
source: tool.source || "built-in",
|
|
263
|
+
};
|
|
264
|
+
});
|
|
193
265
|
},
|
|
194
266
|
description: "Get tool details by name",
|
|
195
267
|
tags: ["tools"],
|
|
@@ -3,20 +3,7 @@
|
|
|
3
3
|
* Implements a protocol for streaming structured data between server and client
|
|
4
4
|
* Compatible with AI SDK's data stream format
|
|
5
5
|
*/
|
|
6
|
-
import type { DataStreamWriter,
|
|
7
|
-
/**
|
|
8
|
-
* Configuration for DataStreamWriter
|
|
9
|
-
*/
|
|
10
|
-
type DataStreamWriterConfig = {
|
|
11
|
-
/** Writer function to send data */
|
|
12
|
-
write: (chunk: string) => void | Promise<void>;
|
|
13
|
-
/** Function to close the stream */
|
|
14
|
-
close?: () => void | Promise<void>;
|
|
15
|
-
/** Format: sse (Server-Sent Events) or ndjson (Newline-delimited JSON) */
|
|
16
|
-
format?: "sse" | "ndjson";
|
|
17
|
-
/** Include timestamps in events */
|
|
18
|
-
includeTimestamps?: boolean;
|
|
19
|
-
};
|
|
6
|
+
import type { CloseHandler, DataStreamResponseConfig, DataStreamWriter, DataStreamWriterConfig, SSEEventOptions } from "../../types/index.js";
|
|
20
7
|
/**
|
|
21
8
|
* Creates a data stream writer
|
|
22
9
|
*/
|
|
@@ -24,16 +11,6 @@ export declare function createDataStreamWriter(config: DataStreamWriterConfig):
|
|
|
24
11
|
/**
|
|
25
12
|
* Configuration for DataStreamResponse
|
|
26
13
|
*/
|
|
27
|
-
type DataStreamResponseConfig = {
|
|
28
|
-
/** Content type header */
|
|
29
|
-
contentType?: "text/event-stream" | "application/x-ndjson";
|
|
30
|
-
/** Initial headers */
|
|
31
|
-
headers?: Record<string, string>;
|
|
32
|
-
/** Keep-alive interval in milliseconds */
|
|
33
|
-
keepAliveInterval?: number;
|
|
34
|
-
/** Include timestamps in events */
|
|
35
|
-
includeTimestamps?: boolean;
|
|
36
|
-
};
|
|
37
14
|
/**
|
|
38
15
|
* Data stream response class
|
|
39
16
|
* Creates a streaming response with writer interface
|
|
@@ -136,16 +113,6 @@ export declare function createNDJSONHeaders(additionalHeaders?: Record<string, s
|
|
|
136
113
|
/**
|
|
137
114
|
* SSE Event options for formatSSEEvent
|
|
138
115
|
*/
|
|
139
|
-
type SSEEventOptions = {
|
|
140
|
-
/** Event type (optional) */
|
|
141
|
-
event?: string;
|
|
142
|
-
/** Event data (required) */
|
|
143
|
-
data: string;
|
|
144
|
-
/** Event ID (optional) */
|
|
145
|
-
id?: string;
|
|
146
|
-
/** Retry interval in milliseconds (optional) */
|
|
147
|
-
retry?: number;
|
|
148
|
-
};
|
|
149
116
|
/**
|
|
150
117
|
* Format a Server-Sent Events (SSE) message
|
|
151
118
|
*
|
|
@@ -243,4 +210,3 @@ export declare class WebStreamWriter extends BaseDataStreamWriter {
|
|
|
243
210
|
writeEvent(eventType: string, data: unknown): void;
|
|
244
211
|
protected doClose(): void;
|
|
245
212
|
}
|
|
246
|
-
export {};
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* Implements a protocol for streaming structured data between server and client
|
|
4
4
|
* Compatible with AI SDK's data stream format
|
|
5
5
|
*/
|
|
6
|
+
// ============================================
|
|
7
|
+
// Data Stream Writer Implementation
|
|
8
|
+
// ============================================
|
|
6
9
|
/**
|
|
7
10
|
* Creates a data stream writer
|
|
8
11
|
*/
|
|
@@ -64,6 +67,12 @@ export function createDataStreamWriter(config) {
|
|
|
64
67
|
},
|
|
65
68
|
};
|
|
66
69
|
}
|
|
70
|
+
// ============================================
|
|
71
|
+
// Data Stream Response
|
|
72
|
+
// ============================================
|
|
73
|
+
/**
|
|
74
|
+
* Configuration for DataStreamResponse
|
|
75
|
+
*/
|
|
67
76
|
/**
|
|
68
77
|
* Data stream response class
|
|
69
78
|
* Creates a streaming response with writer interface
|
|
@@ -305,6 +314,12 @@ export function createNDJSONHeaders(additionalHeaders) {
|
|
|
305
314
|
...additionalHeaders,
|
|
306
315
|
};
|
|
307
316
|
}
|
|
317
|
+
// ============================================
|
|
318
|
+
// SSE Event Formatting (Legacy Compatibility)
|
|
319
|
+
// ============================================
|
|
320
|
+
/**
|
|
321
|
+
* SSE Event options for formatSSEEvent
|
|
322
|
+
*/
|
|
308
323
|
/**
|
|
309
324
|
* Format a Server-Sent Events (SSE) message
|
|
310
325
|
*
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Flow: Vercel AI SDK → OpenTelemetry Spans → LangfuseSpanProcessor → Langfuse Platform
|
|
8
8
|
*/
|
|
9
9
|
import { LangfuseSpanProcessor } from "@langfuse/otel";
|
|
10
|
-
import { metrics, trace } from "@opentelemetry/api";
|
|
10
|
+
import { metrics, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
11
11
|
import { W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
12
12
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
13
13
|
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
@@ -368,24 +368,124 @@ class ContextEnricher {
|
|
|
368
368
|
attributes["ai.model.id"] ||
|
|
369
369
|
attributes["gen_ai.request.model"];
|
|
370
370
|
if (isGenAISpan) {
|
|
371
|
+
const model = attributes["gen_ai.request.model"] ||
|
|
372
|
+
attributes["ai.model.id"];
|
|
373
|
+
const provider = attributes["gen_ai.system"] ||
|
|
374
|
+
attributes["ai.model.provider"];
|
|
371
375
|
logger.debug(`${LOG_PREFIX} GenAI span detected`, {
|
|
372
376
|
spanName: readableSpan.name,
|
|
373
|
-
model
|
|
374
|
-
provider
|
|
377
|
+
model,
|
|
378
|
+
provider,
|
|
375
379
|
});
|
|
376
|
-
//
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
380
|
+
// L4/L6 fix: Set explicit Langfuse observation attributes so
|
|
381
|
+
// cost dashboards and model analytics work correctly.
|
|
382
|
+
try {
|
|
383
|
+
const mAttrs = span.attributes;
|
|
384
|
+
// L6: Model identity
|
|
385
|
+
if (model) {
|
|
386
|
+
mAttrs["gen_ai.response.model"] = model;
|
|
387
|
+
}
|
|
388
|
+
// L4: Usage details — aggregate from AI SDK attributes into a
|
|
389
|
+
// structured JSON object that Langfuse can parse for cost analysis.
|
|
390
|
+
const inputTokens = attributes["gen_ai.usage.input_tokens"] ??
|
|
391
|
+
attributes["ai.usage.promptTokens"];
|
|
392
|
+
const outputTokens = attributes["gen_ai.usage.output_tokens"] ??
|
|
393
|
+
attributes["ai.usage.completionTokens"];
|
|
394
|
+
const totalTokens = attributes["gen_ai.usage.total_tokens"] ??
|
|
395
|
+
(inputTokens !== undefined && outputTokens !== undefined
|
|
396
|
+
? inputTokens + outputTokens
|
|
397
|
+
: undefined);
|
|
398
|
+
const reasoningTokens = attributes["gen_ai.usage.reasoning_tokens"] ??
|
|
399
|
+
attributes["ai.usage.reasoningTokens"];
|
|
400
|
+
const cachedTokens = attributes["gen_ai.usage.input_cached_tokens"];
|
|
401
|
+
if (inputTokens !== undefined || outputTokens !== undefined) {
|
|
402
|
+
const usageDetails = {};
|
|
403
|
+
if (inputTokens !== undefined) {
|
|
404
|
+
usageDetails.input = inputTokens;
|
|
405
|
+
}
|
|
406
|
+
if (outputTokens !== undefined) {
|
|
407
|
+
usageDetails.output = outputTokens;
|
|
408
|
+
}
|
|
409
|
+
if (totalTokens !== undefined) {
|
|
410
|
+
usageDetails.total = totalTokens;
|
|
411
|
+
}
|
|
412
|
+
if (reasoningTokens !== undefined) {
|
|
413
|
+
usageDetails.reasoning_tokens = reasoningTokens;
|
|
414
|
+
}
|
|
415
|
+
if (cachedTokens !== undefined) {
|
|
416
|
+
usageDetails.input_cached_tokens = cachedTokens;
|
|
417
|
+
}
|
|
418
|
+
mAttrs["langfuse.usage_details"] = JSON.stringify(usageDetails);
|
|
419
|
+
logger.debug(`${LOG_PREFIX} Token usage captured`, {
|
|
420
|
+
inputTokens,
|
|
421
|
+
outputTokens,
|
|
422
|
+
totalTokens,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
// L7: Model parameters — surface temperature and max_tokens for
|
|
426
|
+
// generation tuning visibility.
|
|
427
|
+
const temperature = attributes["gen_ai.request.temperature"] ??
|
|
428
|
+
attributes["ai.settings.temperature"];
|
|
429
|
+
const maxTokens = attributes["gen_ai.request.max_tokens"] ??
|
|
430
|
+
attributes["ai.settings.maxTokens"];
|
|
431
|
+
const topP = attributes["gen_ai.request.top_p"] ??
|
|
432
|
+
attributes["ai.settings.topP"];
|
|
433
|
+
if (temperature !== undefined ||
|
|
434
|
+
maxTokens !== undefined ||
|
|
435
|
+
topP !== undefined) {
|
|
436
|
+
const params = {};
|
|
437
|
+
if (temperature !== undefined) {
|
|
438
|
+
params.temperature = temperature;
|
|
439
|
+
}
|
|
440
|
+
if (maxTokens !== undefined) {
|
|
441
|
+
params.max_tokens = maxTokens;
|
|
442
|
+
}
|
|
443
|
+
if (topP !== undefined) {
|
|
444
|
+
params.top_p = topP;
|
|
445
|
+
}
|
|
446
|
+
mAttrs["gen_ai.request.model_parameters"] = JSON.stringify(params);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
catch {
|
|
450
|
+
// Read-only attributes — cannot enrich; Pipeline A will still
|
|
451
|
+
// export the raw GenAI attributes that Langfuse can parse.
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
// P8 fix: Propagate error status to Langfuse-consumable attributes.
|
|
455
|
+
// OTel ReadableSpan attributes may be readonly at onEnd() time; the type
|
|
456
|
+
// cast attempts late mutation. LangfuseSpanProcessor runs after
|
|
457
|
+
// ContextEnricher in the spanProcessors array and reads these attributes,
|
|
458
|
+
// so setting them here allows Langfuse to surface the correct level and
|
|
459
|
+
// status message on the trace/generation.
|
|
460
|
+
const readableStatus = span.status;
|
|
461
|
+
try {
|
|
462
|
+
const mutableAttrs = span.attributes;
|
|
463
|
+
if (readableStatus?.code === SpanStatusCode.ERROR) {
|
|
464
|
+
mutableAttrs["langfuse.level"] = "ERROR";
|
|
465
|
+
if (readableStatus.message) {
|
|
466
|
+
mutableAttrs["langfuse.status_message"] = readableStatus.message;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
// P8 extended: Detect WARNING-level conditions on non-ERROR spans.
|
|
471
|
+
// The AI SDK sets ai.finishReason on its spans; content-filter and
|
|
472
|
+
// length finish reasons indicate partial failures that deserve WARNING.
|
|
473
|
+
const finishReason = mutableAttrs["ai.finishReason"] ??
|
|
474
|
+
mutableAttrs["gen_ai.response.finish_reasons"];
|
|
475
|
+
const reasonStr = Array.isArray(finishReason)
|
|
476
|
+
? finishReason.join(",")
|
|
477
|
+
: String(finishReason ?? "");
|
|
478
|
+
if (reasonStr.includes("content-filter") || reasonStr === "length") {
|
|
479
|
+
mutableAttrs["langfuse.level"] = "WARNING";
|
|
480
|
+
mutableAttrs["langfuse.status_message"] =
|
|
481
|
+
`Generation stopped: finishReason=${reasonStr}`;
|
|
482
|
+
}
|
|
387
483
|
}
|
|
388
484
|
}
|
|
485
|
+
catch {
|
|
486
|
+
// Readonly enforcement by OTel SDK — mutation not possible; log at debug.
|
|
487
|
+
logger.debug(`${LOG_PREFIX} Could not set langfuse.level on span (read-only attributes)`);
|
|
488
|
+
}
|
|
389
489
|
}
|
|
390
490
|
catch (error) {
|
|
391
491
|
// Don't fail span processing on errors
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { NeuroLink } from "../neurolink.js";
|
|
2
|
-
import type { ConversationMemoryConfig } from "../types/index.js";
|
|
3
|
-
type SessionVariableValue = string | number | boolean;
|
|
4
|
-
type LoopSessionState = {
|
|
5
|
-
neurolinkInstance: NeuroLink;
|
|
6
|
-
sessionId: string;
|
|
7
|
-
isActive: boolean;
|
|
8
|
-
conversationMemoryConfig?: ConversationMemoryConfig;
|
|
9
|
-
sessionVariables: Record<string, SessionVariableValue>;
|
|
10
|
-
};
|
|
2
|
+
import type { ConversationMemoryConfig, LoopSessionState, SessionVariableValue } from "../types/index.js";
|
|
11
3
|
export declare class GlobalSessionManager {
|
|
12
4
|
private static instance;
|
|
13
5
|
private loopSession;
|
|
@@ -50,4 +42,3 @@ export declare class GlobalSessionManager {
|
|
|
50
42
|
clearSessionVariables(): void;
|
|
51
43
|
}
|
|
52
44
|
export declare const globalSession: GlobalSessionManager;
|
|
53
|
-
export {};
|
|
@@ -31,7 +31,7 @@ export declare function createTaskTools(manager: TaskManager): {
|
|
|
31
31
|
name: string;
|
|
32
32
|
prompt: string;
|
|
33
33
|
schedule: {
|
|
34
|
-
type: "
|
|
34
|
+
type: "once" | "cron" | "interval";
|
|
35
35
|
expression?: string | undefined;
|
|
36
36
|
timezone?: string | undefined;
|
|
37
37
|
every?: number | undefined;
|
|
@@ -58,7 +58,7 @@ export declare function createTaskTools(manager: TaskManager): {
|
|
|
58
58
|
schedule?: undefined;
|
|
59
59
|
}>;
|
|
60
60
|
listTasks: import("ai").Tool<{
|
|
61
|
-
status?: "failed" | "pending" | "
|
|
61
|
+
status?: "failed" | "pending" | "completed" | "cancelled" | "active" | "paused" | undefined;
|
|
62
62
|
}, {
|
|
63
63
|
success: boolean;
|
|
64
64
|
count: number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract the current OTel trace context for use by Pipeline B spans.
|
|
3
|
+
* Returns undefined values when no OTel context is active, allowing
|
|
4
|
+
* Pipeline B spans to share the same trace as Pipeline A spans.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getActiveTraceContext(): {
|
|
7
|
+
traceId?: string;
|
|
8
|
+
parentSpanId?: string;
|
|
9
|
+
};
|