@juspay/neurolink 9.54.6 → 9.54.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/action/actionInputs.d.ts +1 -1
- package/dist/adapters/video/directorPipeline.js +6 -0
- package/dist/adapters/video/vertexVideoHandler.js +6 -0
- package/dist/agent/directTools.d.ts +3 -23
- package/dist/auth/AuthProviderFactory.d.ts +1 -3
- package/dist/auth/anthropicOAuth.d.ts +4 -7
- package/dist/auth/anthropicOAuth.js +23 -0
- package/dist/auth/errors.d.ts +1 -1
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +14 -0
- package/dist/auth/middleware/AuthMiddleware.d.ts +5 -60
- package/dist/auth/middleware/AuthMiddleware.js +3 -0
- package/dist/auth/middleware/rateLimitByUser.d.ts +4 -93
- package/dist/auth/middleware/rateLimitByUser.js +4 -0
- package/dist/auth/providers/BaseAuthProvider.d.ts +1 -1
- package/dist/auth/providers/CognitoProvider.js +3 -0
- package/dist/auth/providers/KeycloakProvider.js +3 -0
- package/dist/auth/providers/auth0.d.ts +1 -1
- package/dist/auth/sessionManager.d.ts +2 -0
- package/dist/auth/sessionManager.js +53 -11
- package/dist/auth/tokenStore.d.ts +2 -0
- package/dist/auth/tokenStore.js +45 -4
- package/dist/autoresearch/tools.d.ts +1 -16
- package/dist/browser/neurolink.min.js +353 -353
- package/dist/cli/commands/config.d.ts +3 -123
- package/dist/cli/commands/config.js +4 -2
- package/dist/cli/commands/evaluate.d.ts +1 -19
- package/dist/cli/commands/proxy.d.ts +1 -1
- package/dist/cli/commands/proxy.js +3 -0
- package/dist/cli/commands/rag.js +3 -0
- package/dist/cli/commands/setup-anthropic.d.ts +2 -6
- package/dist/cli/commands/setup-anthropic.js +1 -1
- package/dist/cli/commands/setup-azure.d.ts +2 -6
- package/dist/cli/commands/setup-azure.js +1 -1
- package/dist/cli/commands/setup-bedrock.d.ts +2 -6
- package/dist/cli/commands/setup-bedrock.js +1 -1
- package/dist/cli/commands/setup-gcp.d.ts +2 -6
- package/dist/cli/commands/setup-google-ai.d.ts +2 -6
- package/dist/cli/commands/setup-google-ai.js +1 -1
- package/dist/cli/commands/setup-huggingface.d.ts +1 -5
- package/dist/cli/commands/setup-mistral.d.ts +1 -5
- package/dist/cli/commands/setup-openai.d.ts +2 -6
- package/dist/cli/commands/setup-openai.js +1 -1
- package/dist/cli/commands/setup.d.ts +1 -8
- package/dist/cli/commands/task.js +1 -0
- package/dist/cli/commands/voiceServer.d.ts +1 -4
- package/dist/cli/loop/session.js +31 -10
- package/dist/cli/utils/interactiveSetup.d.ts +2 -15
- package/dist/cli/utils/videoFileUtils.d.ts +1 -15
- package/dist/client/aiSdkAdapter.d.ts +1 -1
- package/dist/client/aiSdkAdapter.js +1 -0
- package/dist/client/httpClient.d.ts +1 -0
- package/dist/client/httpClient.js +13 -0
- package/dist/client/sseClient.d.ts +1 -0
- package/dist/client/sseClient.js +29 -0
- package/dist/client/streamingClient.d.ts +2 -0
- package/dist/client/streamingClient.js +19 -0
- package/dist/client/wsClient.d.ts +6 -0
- package/dist/client/wsClient.js +90 -10
- package/dist/context/budgetChecker.js +3 -1
- package/dist/context/contextCompactor.js +163 -143
- package/dist/context/fileSummarizationService.d.ts +1 -9
- package/dist/context/summarizationEngine.js +29 -16
- package/dist/core/baseProvider.js +124 -153
- package/dist/core/infrastructure/baseRegistry.d.ts +1 -7
- package/dist/core/modules/GenerationHandler.d.ts +3 -2
- package/dist/core/modules/GenerationHandler.js +9 -1
- package/dist/core/modules/StreamHandler.js +9 -0
- package/dist/core/modules/ToolsManager.js +18 -2
- package/dist/evaluation/BatchEvaluator.d.ts +1 -97
- package/dist/evaluation/EvaluationAggregator.d.ts +1 -118
- package/dist/evaluation/EvaluatorFactory.d.ts +1 -13
- package/dist/evaluation/EvaluatorRegistry.d.ts +1 -50
- package/dist/evaluation/errors/EvaluationError.d.ts +2 -27
- package/dist/evaluation/hooks/langfuseAdapter.d.ts +1 -39
- package/dist/evaluation/hooks/observabilityHooks.d.ts +3 -55
- package/dist/evaluation/hooks/observabilityHooks.js +3 -0
- package/dist/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
- package/dist/evaluation/pipeline/strategies/batchStrategy.js +7 -7
- package/dist/evaluation/ragasEvaluator.js +54 -37
- package/dist/evaluation/reporting/metricsCollector.d.ts +1 -60
- package/dist/evaluation/reporting/reportGenerator.d.ts +1 -17
- package/dist/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
- package/dist/evaluation/scorers/rule/formatScorer.d.ts +1 -42
- package/dist/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
- package/dist/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
- package/dist/factories/providerFactory.d.ts +1 -16
- package/dist/factories/providerFactory.js +2 -0
- package/dist/image-gen/ImageGenService.d.ts +3 -0
- package/dist/image-gen/ImageGenService.js +3 -0
- package/dist/lib/action/actionInputs.d.ts +1 -1
- package/dist/lib/adapters/video/directorPipeline.js +6 -0
- package/dist/lib/adapters/video/vertexVideoHandler.js +6 -0
- package/dist/lib/agent/directTools.d.ts +3 -23
- package/dist/lib/auth/AuthProviderFactory.d.ts +1 -3
- package/dist/lib/auth/anthropicOAuth.d.ts +4 -7
- package/dist/lib/auth/anthropicOAuth.js +23 -0
- package/dist/lib/auth/errors.d.ts +1 -1
- package/dist/lib/auth/index.d.ts +11 -0
- package/dist/lib/auth/index.js +14 -0
- package/dist/lib/auth/middleware/AuthMiddleware.d.ts +5 -60
- package/dist/lib/auth/middleware/AuthMiddleware.js +3 -0
- package/dist/lib/auth/middleware/rateLimitByUser.d.ts +4 -93
- package/dist/lib/auth/middleware/rateLimitByUser.js +4 -0
- package/dist/lib/auth/providers/BaseAuthProvider.d.ts +1 -1
- package/dist/lib/auth/providers/CognitoProvider.js +3 -0
- package/dist/lib/auth/providers/KeycloakProvider.js +3 -0
- package/dist/lib/auth/providers/auth0.d.ts +1 -1
- package/dist/lib/auth/sessionManager.d.ts +2 -0
- package/dist/lib/auth/sessionManager.js +53 -11
- package/dist/lib/auth/tokenStore.d.ts +2 -0
- package/dist/lib/auth/tokenStore.js +45 -4
- package/dist/lib/autoresearch/tools.d.ts +1 -16
- package/dist/lib/client/aiSdkAdapter.d.ts +1 -1
- package/dist/lib/client/aiSdkAdapter.js +1 -0
- package/dist/lib/client/httpClient.d.ts +1 -0
- package/dist/lib/client/httpClient.js +13 -0
- package/dist/lib/client/sseClient.d.ts +1 -0
- package/dist/lib/client/sseClient.js +29 -0
- package/dist/lib/client/streamingClient.d.ts +2 -0
- package/dist/lib/client/streamingClient.js +19 -0
- package/dist/lib/client/wsClient.d.ts +6 -0
- package/dist/lib/client/wsClient.js +90 -10
- package/dist/lib/context/budgetChecker.js +3 -1
- package/dist/lib/context/contextCompactor.js +163 -143
- package/dist/lib/context/fileSummarizationService.d.ts +1 -9
- package/dist/lib/context/summarizationEngine.js +29 -16
- package/dist/lib/core/baseProvider.js +124 -153
- package/dist/lib/core/infrastructure/baseRegistry.d.ts +1 -7
- package/dist/lib/core/modules/GenerationHandler.d.ts +3 -2
- package/dist/lib/core/modules/GenerationHandler.js +9 -1
- package/dist/lib/core/modules/StreamHandler.js +9 -0
- package/dist/lib/core/modules/ToolsManager.js +18 -2
- package/dist/lib/evaluation/BatchEvaluator.d.ts +1 -97
- package/dist/lib/evaluation/EvaluationAggregator.d.ts +1 -118
- package/dist/lib/evaluation/EvaluatorFactory.d.ts +1 -13
- package/dist/lib/evaluation/EvaluatorRegistry.d.ts +1 -50
- package/dist/lib/evaluation/errors/EvaluationError.d.ts +2 -27
- package/dist/lib/evaluation/hooks/langfuseAdapter.d.ts +1 -39
- package/dist/lib/evaluation/hooks/observabilityHooks.d.ts +3 -55
- package/dist/lib/evaluation/hooks/observabilityHooks.js +3 -0
- package/dist/lib/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
- package/dist/lib/evaluation/pipeline/strategies/batchStrategy.js +7 -7
- package/dist/lib/evaluation/ragasEvaluator.js +54 -37
- package/dist/lib/evaluation/reporting/metricsCollector.d.ts +1 -60
- package/dist/lib/evaluation/reporting/reportGenerator.d.ts +1 -17
- package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
- package/dist/lib/evaluation/scorers/rule/formatScorer.d.ts +1 -42
- package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
- package/dist/lib/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
- package/dist/lib/factories/providerFactory.d.ts +1 -16
- package/dist/lib/factories/providerFactory.js +2 -0
- package/dist/lib/image-gen/ImageGenService.d.ts +3 -0
- package/dist/lib/image-gen/ImageGenService.js +3 -0
- package/dist/lib/mcp/batching/requestBatcher.js +99 -73
- package/dist/lib/mcp/httpRateLimiter.js +3 -1
- package/dist/lib/mcp/httpRetryHandler.js +3 -1
- package/dist/lib/mcp/mcpClientFactory.js +3 -1
- package/dist/lib/mcp/multiServerManager.d.ts +1 -14
- package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
- package/dist/lib/mcp/toolDiscoveryService.js +70 -57
- package/dist/lib/mcp/toolRegistry.js +11 -1
- package/dist/lib/memory/memoryRetrievalTools.js +182 -141
- package/dist/lib/neurolink.js +236 -40
- package/dist/lib/observability/exporterRegistry.d.ts +3 -21
- package/dist/lib/observability/exporters/sentryExporter.js +1 -0
- package/dist/lib/observability/metricsAggregator.d.ts +1 -31
- package/dist/lib/observability/tokenTracker.d.ts +7 -16
- package/dist/lib/observability/tokenTracker.js +6 -4
- package/dist/lib/observability/utils/spanSerializer.d.ts +5 -1
- package/dist/lib/observability/utils/spanSerializer.js +24 -4
- package/dist/lib/processors/base/BaseFileProcessor.js +66 -53
- package/dist/lib/processors/document/ExcelProcessor.d.ts +1 -1
- package/dist/lib/processors/errors/errorHelpers.d.ts +1 -31
- package/dist/lib/processors/errors/errorSerializer.d.ts +1 -45
- package/dist/lib/processors/registry/ProcessorRegistry.js +17 -6
- package/dist/lib/providers/amazonBedrock.js +189 -15
- package/dist/lib/providers/amazonSagemaker.js +25 -11
- package/dist/lib/providers/anthropic.js +13 -0
- package/dist/lib/providers/azureOpenai.js +2 -0
- package/dist/lib/providers/googleAiStudio.js +82 -0
- package/dist/lib/providers/googleVertex.js +52 -0
- package/dist/lib/providers/huggingFace.js +2 -0
- package/dist/lib/providers/litellm.js +2 -0
- package/dist/lib/providers/mistral.js +2 -0
- package/dist/lib/providers/ollama.js +84 -5
- package/dist/lib/providers/openAI.d.ts +2 -0
- package/dist/lib/providers/openAI.js +17 -6
- package/dist/lib/providers/openRouter.js +2 -0
- package/dist/lib/providers/openaiCompatible.js +2 -0
- package/dist/lib/providers/sagemaker/detection.d.ts +1 -33
- package/dist/lib/providers/sagemaker/diagnostics.d.ts +1 -25
- package/dist/lib/providers/sagemaker/language-model.d.ts +1 -1
- package/dist/lib/proxy/proxyConfig.js +4 -0
- package/dist/lib/proxy/proxyEnv.d.ts +1 -17
- package/dist/lib/proxy/proxyTracer.d.ts +1 -36
- package/dist/lib/proxy/proxyTracer.js +9 -0
- package/dist/lib/proxy/quietDetector.d.ts +1 -7
- package/dist/lib/proxy/rawStreamCapture.d.ts +1 -10
- package/dist/lib/proxy/requestLogger.d.ts +1 -21
- package/dist/lib/proxy/sseInterceptor.d.ts +1 -66
- package/dist/lib/proxy/sseInterceptor.js +6 -0
- package/dist/lib/proxy/updateChecker.d.ts +1 -6
- package/dist/lib/proxy/updateState.d.ts +1 -12
- package/dist/lib/rag/chunkers/BaseChunker.js +36 -22
- package/dist/lib/rag/chunking/jsonChunker.d.ts +1 -1
- package/dist/lib/rag/errors/RAGError.d.ts +1 -2
- package/dist/lib/rag/ragIntegration.js +45 -32
- package/dist/lib/rag/reranker/reranker.js +151 -122
- package/dist/lib/rag/retrieval/vectorQueryTool.js +79 -65
- package/dist/lib/sdk/toolRegistration.d.ts +10 -44
- package/dist/lib/sdk/toolRegistration.js +1 -1
- package/dist/lib/server/middleware/abortSignal.d.ts +1 -11
- package/dist/lib/server/middleware/auth.d.ts +1 -21
- package/dist/lib/server/middleware/auth.js +12 -0
- package/dist/lib/server/middleware/common.js +48 -32
- package/dist/lib/server/middleware/deprecation.d.ts +1 -20
- package/dist/lib/server/middleware/rateLimit.d.ts +1 -75
- package/dist/lib/server/middleware/validation.d.ts +3 -81
- package/dist/lib/server/middleware/validation.js +3 -0
- package/dist/lib/server/openapi/generator.d.ts +1 -47
- package/dist/lib/server/routes/agentRoutes.js +112 -57
- package/dist/lib/server/routes/claudeProxyRoutes.d.ts +1 -6
- package/dist/lib/server/routes/claudeProxyRoutes.js +127 -13
- package/dist/lib/server/routes/healthRoutes.js +58 -12
- package/dist/lib/server/routes/index.d.ts +1 -26
- package/dist/lib/server/routes/mcpRoutes.js +40 -7
- package/dist/lib/server/routes/memoryRoutes.js +22 -7
- package/dist/lib/server/routes/openApiRoutes.js +30 -6
- package/dist/lib/server/routes/toolRoutes.js +140 -68
- package/dist/lib/server/streaming/dataStream.d.ts +1 -35
- package/dist/lib/server/streaming/dataStream.js +15 -0
- package/dist/lib/services/server/ai/observability/instrumentation.js +114 -14
- package/dist/lib/session/globalSessionState.d.ts +1 -10
- package/dist/lib/tasks/tools/taskTools.d.ts +2 -2
- package/dist/lib/telemetry/traceContext.d.ts +9 -0
- package/dist/lib/telemetry/traceContext.js +19 -0
- package/dist/lib/telemetry/tracers.d.ts +2 -0
- package/dist/lib/telemetry/tracers.js +2 -0
- package/dist/lib/types/action.d.ts +2 -0
- package/dist/lib/types/artifact.d.ts +7 -0
- package/dist/lib/types/auth.d.ts +125 -18
- package/dist/lib/types/autoresearch.d.ts +12 -0
- package/dist/lib/types/cli.d.ts +415 -0
- package/dist/lib/types/client.d.ts +34 -0
- package/dist/lib/types/common.d.ts +12 -41
- package/dist/lib/types/context.d.ts +5 -0
- package/dist/lib/types/evaluation.d.ts +332 -1
- package/dist/lib/types/file.d.ts +4 -0
- package/dist/lib/types/mcp.d.ts +102 -2
- package/dist/lib/types/middleware.d.ts +116 -0
- package/dist/lib/types/multimodal.d.ts +65 -0
- package/dist/lib/types/observability.d.ts +81 -0
- package/dist/lib/types/processor.d.ts +47 -0
- package/dist/lib/types/providers.d.ts +120 -16
- package/dist/lib/types/proxy.d.ts +321 -1
- package/dist/lib/types/rag.d.ts +22 -0
- package/dist/lib/types/scorer.d.ts +141 -0
- package/dist/lib/types/server.d.ts +99 -0
- package/dist/lib/types/span.d.ts +2 -1
- package/dist/lib/types/span.js +1 -0
- package/dist/lib/types/tools.d.ts +44 -0
- package/dist/lib/types/tts.d.ts +6 -0
- package/dist/lib/types/utilities.d.ts +22 -0
- package/dist/lib/types/workflow.d.ts +18 -0
- package/dist/lib/utils/async/retry.d.ts +2 -8
- package/dist/lib/utils/async/retry.js +9 -9
- package/dist/lib/utils/imageCompressor.d.ts +1 -21
- package/dist/lib/utils/imageCompressor.js +5 -1
- package/dist/lib/utils/messageBuilder.d.ts +1 -1
- package/dist/lib/utils/redis.d.ts +1 -4
- package/dist/lib/utils/toolEndEmitter.d.ts +25 -0
- package/dist/lib/utils/toolEndEmitter.js +65 -0
- package/dist/lib/workflow/config.d.ts +7 -32
- package/dist/lib/workflow/core/ensembleExecutor.js +28 -0
- package/dist/lib/workflow/core/judgeScorer.js +23 -0
- package/dist/lib/workflow/core/responseConditioner.js +17 -0
- package/dist/lib/workflow/core/workflowRunner.d.ts +1 -19
- package/dist/lib/workflow/core/workflowRunner.js +202 -147
- package/dist/mcp/batching/requestBatcher.js +99 -73
- package/dist/mcp/httpRateLimiter.js +3 -1
- package/dist/mcp/httpRetryHandler.js +3 -1
- package/dist/mcp/mcpClientFactory.js +3 -1
- package/dist/mcp/multiServerManager.d.ts +1 -14
- package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
- package/dist/mcp/toolDiscoveryService.js +70 -57
- package/dist/mcp/toolRegistry.js +11 -1
- package/dist/memory/memoryRetrievalTools.js +182 -141
- package/dist/neurolink.js +236 -40
- package/dist/observability/exporterRegistry.d.ts +3 -21
- package/dist/observability/exporters/sentryExporter.js +1 -0
- package/dist/observability/metricsAggregator.d.ts +1 -31
- package/dist/observability/tokenTracker.d.ts +7 -16
- package/dist/observability/tokenTracker.js +6 -4
- package/dist/observability/utils/spanSerializer.d.ts +5 -1
- package/dist/observability/utils/spanSerializer.js +24 -4
- package/dist/processors/base/BaseFileProcessor.js +66 -53
- package/dist/processors/document/ExcelProcessor.d.ts +1 -1
- package/dist/processors/errors/errorHelpers.d.ts +1 -31
- package/dist/processors/errors/errorSerializer.d.ts +1 -45
- package/dist/processors/registry/ProcessorRegistry.js +17 -6
- package/dist/providers/amazonBedrock.js +189 -15
- package/dist/providers/amazonSagemaker.js +25 -11
- package/dist/providers/anthropic.js +13 -0
- package/dist/providers/azureOpenai.js +2 -0
- package/dist/providers/googleAiStudio.js +82 -0
- package/dist/providers/googleVertex.js +52 -0
- package/dist/providers/huggingFace.js +2 -0
- package/dist/providers/litellm.js +2 -0
- package/dist/providers/mistral.js +2 -0
- package/dist/providers/ollama.js +84 -5
- package/dist/providers/openAI.d.ts +2 -0
- package/dist/providers/openAI.js +17 -6
- package/dist/providers/openRouter.js +2 -0
- package/dist/providers/openaiCompatible.js +2 -0
- package/dist/providers/sagemaker/detection.d.ts +1 -33
- package/dist/providers/sagemaker/diagnostics.d.ts +1 -25
- package/dist/providers/sagemaker/language-model.d.ts +1 -1
- package/dist/proxy/proxyConfig.js +4 -0
- package/dist/proxy/proxyEnv.d.ts +1 -17
- package/dist/proxy/proxyTracer.d.ts +1 -36
- package/dist/proxy/proxyTracer.js +9 -0
- package/dist/proxy/quietDetector.d.ts +1 -7
- package/dist/proxy/rawStreamCapture.d.ts +1 -10
- package/dist/proxy/requestLogger.d.ts +1 -21
- package/dist/proxy/sseInterceptor.d.ts +1 -66
- package/dist/proxy/sseInterceptor.js +6 -0
- package/dist/proxy/updateChecker.d.ts +1 -6
- package/dist/proxy/updateState.d.ts +1 -12
- package/dist/rag/chunkers/BaseChunker.js +36 -22
- package/dist/rag/chunking/jsonChunker.d.ts +1 -1
- package/dist/rag/errors/RAGError.d.ts +1 -2
- package/dist/rag/ragIntegration.js +45 -32
- package/dist/rag/reranker/reranker.js +151 -122
- package/dist/rag/retrieval/vectorQueryTool.js +79 -65
- package/dist/sdk/toolRegistration.d.ts +10 -44
- package/dist/sdk/toolRegistration.js +1 -1
- package/dist/server/middleware/abortSignal.d.ts +1 -11
- package/dist/server/middleware/auth.d.ts +1 -21
- package/dist/server/middleware/auth.js +12 -0
- package/dist/server/middleware/common.js +48 -32
- package/dist/server/middleware/deprecation.d.ts +1 -20
- package/dist/server/middleware/rateLimit.d.ts +1 -75
- package/dist/server/middleware/validation.d.ts +3 -81
- package/dist/server/middleware/validation.js +3 -0
- package/dist/server/openapi/generator.d.ts +1 -47
- package/dist/server/routes/agentRoutes.js +112 -57
- package/dist/server/routes/claudeProxyRoutes.d.ts +1 -6
- package/dist/server/routes/claudeProxyRoutes.js +127 -13
- package/dist/server/routes/healthRoutes.js +58 -12
- package/dist/server/routes/index.d.ts +1 -26
- package/dist/server/routes/mcpRoutes.js +40 -7
- package/dist/server/routes/memoryRoutes.js +22 -7
- package/dist/server/routes/openApiRoutes.js +30 -6
- package/dist/server/routes/toolRoutes.js +140 -68
- package/dist/server/streaming/dataStream.d.ts +1 -35
- package/dist/server/streaming/dataStream.js +15 -0
- package/dist/services/server/ai/observability/instrumentation.js +114 -14
- package/dist/session/globalSessionState.d.ts +1 -10
- package/dist/tasks/tools/taskTools.d.ts +2 -2
- package/dist/telemetry/traceContext.d.ts +9 -0
- package/dist/telemetry/traceContext.js +18 -0
- package/dist/telemetry/tracers.d.ts +2 -0
- package/dist/telemetry/tracers.js +2 -0
- package/dist/types/action.d.ts +2 -0
- package/dist/types/artifact.d.ts +7 -0
- package/dist/types/auth.d.ts +125 -18
- package/dist/types/autoresearch.d.ts +12 -0
- package/dist/types/cli.d.ts +415 -0
- package/dist/types/client.d.ts +34 -0
- package/dist/types/common.d.ts +12 -41
- package/dist/types/context.d.ts +5 -0
- package/dist/types/evaluation.d.ts +332 -1
- package/dist/types/file.d.ts +4 -0
- package/dist/types/mcp.d.ts +102 -2
- package/dist/types/middleware.d.ts +116 -0
- package/dist/types/multimodal.d.ts +65 -0
- package/dist/types/observability.d.ts +81 -0
- package/dist/types/processor.d.ts +47 -0
- package/dist/types/providers.d.ts +120 -16
- package/dist/types/proxy.d.ts +321 -1
- package/dist/types/rag.d.ts +22 -0
- package/dist/types/scorer.d.ts +141 -0
- package/dist/types/server.d.ts +99 -0
- package/dist/types/span.d.ts +2 -1
- package/dist/types/span.js +1 -0
- package/dist/types/tools.d.ts +44 -0
- package/dist/types/tts.d.ts +6 -0
- package/dist/types/utilities.d.ts +22 -0
- package/dist/types/workflow.d.ts +18 -0
- package/dist/utils/async/retry.d.ts +2 -8
- package/dist/utils/async/retry.js +9 -9
- package/dist/utils/imageCompressor.d.ts +1 -21
- package/dist/utils/imageCompressor.js +5 -1
- package/dist/utils/messageBuilder.d.ts +1 -1
- package/dist/utils/redis.d.ts +1 -4
- package/dist/utils/toolEndEmitter.d.ts +25 -0
- package/dist/utils/toolEndEmitter.js +64 -0
- package/dist/workflow/config.d.ts +4 -29
- package/dist/workflow/core/ensembleExecutor.js +28 -0
- package/dist/workflow/core/judgeScorer.js +23 -0
- package/dist/workflow/core/responseConditioner.js +17 -0
- package/dist/workflow/core/workflowRunner.d.ts +1 -19
- package/dist/workflow/core/workflowRunner.js +202 -147
- package/package.json +2 -1
|
@@ -3,12 +3,9 @@ import { generateText } from "ai";
|
|
|
3
3
|
import { directAgentTools } from "../agent/directTools.js";
|
|
4
4
|
import { IMAGE_GENERATION_MODELS } from "../core/constants.js";
|
|
5
5
|
import { MiddlewareFactory } from "../middleware/factory.js";
|
|
6
|
-
import { SpanStatus, SpanType } from "../types/index.js";
|
|
7
|
-
import { SpanSerializer } from "../observability/utils/spanSerializer.js";
|
|
8
6
|
import { ATTR, tracers } from "../telemetry/index.js";
|
|
9
7
|
import { isAbortError } from "../utils/errorHandling.js";
|
|
10
8
|
import { logger } from "../utils/logger.js";
|
|
11
|
-
import { calculateCost } from "../utils/pricing.js";
|
|
12
9
|
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
|
|
13
10
|
import { shouldDisableBuiltinTools } from "../utils/toolUtils.js";
|
|
14
11
|
import { getKeyCount, getKeysAsString } from "../utils/transformationUtils.js";
|
|
@@ -61,7 +58,7 @@ export class BaseProvider {
|
|
|
61
58
|
this.messageBuilder = new MessageBuilder(this.providerName, this.modelName);
|
|
62
59
|
this.streamHandler = new StreamHandler(this.providerName, this.modelName);
|
|
63
60
|
this.telemetryHandler = new TelemetryHandler(this.providerName, this.modelName, this.neurolink);
|
|
64
|
-
this.generationHandler = new GenerationHandler(this.providerName, this.modelName, () => this.supportsTools(), (options, type) => this.telemetryHandler.getTelemetryConfig(options, type), (toolCalls, toolResults, options, timestamp) => this.handleToolExecutionStorage(toolCalls, toolResults, options, timestamp));
|
|
61
|
+
this.generationHandler = new GenerationHandler(this.providerName, this.modelName, () => this.supportsTools(), (options, type) => this.telemetryHandler.getTelemetryConfig(options, type), (toolCalls, toolResults, options, timestamp) => this.handleToolExecutionStorage(toolCalls, toolResults, options, timestamp), () => this.neurolink?.getEventEmitter());
|
|
65
62
|
this.utilities = new Utilities(this.providerName, this.modelName, this.defaultTimeout, this.middlewareOptions);
|
|
66
63
|
this.toolsManager = new ToolsManager(this.providerName, this.directTools, this.neurolink, {
|
|
67
64
|
isZodSchema: (schema) => this.isZodSchema(schema),
|
|
@@ -87,135 +84,103 @@ export class BaseProvider {
|
|
|
87
84
|
*/
|
|
88
85
|
async stream(optionsOrPrompt, analysisSchema) {
|
|
89
86
|
let options = this.normalizeStreamOptions(optionsOrPrompt);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const otelStreamSpan = tracers.provider.startSpan("neurolink.provider.stream", {
|
|
100
|
-
kind: SpanKind.CLIENT,
|
|
101
|
-
attributes: {
|
|
102
|
-
[ATTR.GEN_AI_SYSTEM]: this.providerName || "unknown",
|
|
103
|
-
[ATTR.GEN_AI_MODEL]: this.modelName || options.model || "unknown",
|
|
104
|
-
[ATTR.GEN_AI_OPERATION]: "stream",
|
|
105
|
-
[ATTR.NL_PROVIDER]: this.providerName || "unknown",
|
|
106
|
-
},
|
|
87
|
+
logger.info(`Starting stream`, {
|
|
88
|
+
provider: this.providerName,
|
|
89
|
+
hasTools: !options.disableTools && this.supportsTools(),
|
|
90
|
+
disableTools: !!options.disableTools,
|
|
91
|
+
supportsTools: this.supportsTools(),
|
|
92
|
+
inputLength: options.input?.text?.length || 0,
|
|
93
|
+
maxTokens: options.maxTokens,
|
|
94
|
+
temperature: options.temperature,
|
|
95
|
+
timestamp: Date.now(),
|
|
107
96
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
temperature: options.temperature,
|
|
117
|
-
timestamp: Date.now(),
|
|
118
|
-
});
|
|
119
|
-
// ===== EARLY MULTIMODAL DETECTION =====
|
|
120
|
-
const hasFileInput = !!options.input?.files?.length || !!options.input?.videoFiles?.length;
|
|
121
|
-
if (hasFileInput) {
|
|
122
|
-
// ===== VIDEO ANALYSIS DETECTION =====
|
|
123
|
-
// Check if video frames are present and handle with fake streaming
|
|
124
|
-
const messages = await this.buildMessagesForStream(options);
|
|
125
|
-
if (hasVideoFrames(messages)) {
|
|
126
|
-
logger.info(`Video frames detected in stream, using fake streaming for video analysis`, {
|
|
127
|
-
provider: this.providerName,
|
|
128
|
-
model: this.modelName,
|
|
129
|
-
});
|
|
130
|
-
return await this.executeFakeStreaming(options, analysisSchema);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
// CRITICAL: Image generation models don't support real streaming
|
|
134
|
-
// Force fake streaming for image models to ensure image output is yielded.
|
|
135
|
-
// Skip this path when the caller explicitly requests non-image output (e.g.
|
|
136
|
-
// JSON analysis) so dual-mode models like gemini-3.1-flash-image-preview
|
|
137
|
-
// can still perform text/structured generation.
|
|
138
|
-
const isImageModel = IMAGE_GENERATION_MODELS.some((m) => this.modelName.includes(m));
|
|
139
|
-
const requestsNonImageOutput = options.output?.format === "json" ||
|
|
140
|
-
options.output?.format === "structured" ||
|
|
141
|
-
options.output?.format === "text";
|
|
142
|
-
if (isImageModel && !requestsNonImageOutput) {
|
|
143
|
-
logger.info(`Image model detected, forcing fake streaming`, {
|
|
97
|
+
// ===== EARLY MULTIMODAL DETECTION =====
|
|
98
|
+
const hasFileInput = !!options.input?.files?.length || !!options.input?.videoFiles?.length;
|
|
99
|
+
if (hasFileInput) {
|
|
100
|
+
// ===== VIDEO ANALYSIS DETECTION =====
|
|
101
|
+
// Check if video frames are present and handle with fake streaming
|
|
102
|
+
const messages = await this.buildMessagesForStream(options);
|
|
103
|
+
if (hasVideoFrames(messages)) {
|
|
104
|
+
logger.info(`Video frames detected in stream, using fake streaming for video analysis`, {
|
|
144
105
|
provider: this.providerName,
|
|
145
106
|
model: this.modelName,
|
|
146
|
-
reason: "Image generation requires fake streaming to yield image output",
|
|
147
107
|
});
|
|
148
|
-
// Skip real streaming, go directly to fake streaming
|
|
149
108
|
return await this.executeFakeStreaming(options, analysisSchema);
|
|
150
109
|
}
|
|
151
|
-
// Central tool merge: Pre-merge base tools (MCP/built-in) with user-provided
|
|
152
|
-
// tools (e.g. RAG tools) into options.tools. This way, every provider's
|
|
153
|
-
// executeStream() can simply use options.tools (or getAllTools() + options.tools)
|
|
154
|
-
// and get the complete tool set without needing per-provider merge logic.
|
|
155
|
-
if (!options.disableTools && this.supportsTools()) {
|
|
156
|
-
const mergedTools = await this.getToolsForStream(options);
|
|
157
|
-
options = { ...options, tools: mergedTools };
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
options = { ...options, tools: {} };
|
|
161
|
-
}
|
|
162
|
-
// CRITICAL FIX: Always prefer real streaming over fake streaming
|
|
163
|
-
// Try real streaming first, use fake streaming only as fallback
|
|
164
|
-
try {
|
|
165
|
-
logger.debug(`Attempting real streaming`, {
|
|
166
|
-
provider: this.providerName,
|
|
167
|
-
timestamp: Date.now(),
|
|
168
|
-
});
|
|
169
|
-
const realStreamResult = await this.executeStream(options, analysisSchema);
|
|
170
|
-
logger.info(`Real streaming succeeded`, {
|
|
171
|
-
provider: this.providerName,
|
|
172
|
-
timestamp: Date.now(),
|
|
173
|
-
});
|
|
174
|
-
// If real streaming succeeds, return it (with tools support via Vercel AI SDK)
|
|
175
|
-
return realStreamResult;
|
|
176
|
-
}
|
|
177
|
-
catch (realStreamError) {
|
|
178
|
-
logger.warn(`Real streaming failed for ${this.providerName}, falling back to fake streaming:`, {
|
|
179
|
-
error: realStreamError instanceof Error
|
|
180
|
-
? realStreamError.message
|
|
181
|
-
: String(realStreamError),
|
|
182
|
-
timestamp: Date.now(),
|
|
183
|
-
});
|
|
184
|
-
// Fallback to fake streaming only if real streaming fails AND tools are enabled
|
|
185
|
-
if (!options.disableTools && this.supportsTools()) {
|
|
186
|
-
return await this.executeFakeStreaming(options, analysisSchema);
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
// If real streaming failed and no tools are enabled, re-throw the original error
|
|
190
|
-
logger.error(`Real streaming failed for ${this.providerName}:`, realStreamError);
|
|
191
|
-
throw this.handleProviderError(realStreamError);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
110
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
111
|
+
// CRITICAL: Image generation models don't support real streaming
|
|
112
|
+
// Force fake streaming for image models to ensure image output is yielded.
|
|
113
|
+
// Skip this path when the caller explicitly requests non-image output (e.g.
|
|
114
|
+
// JSON analysis) so dual-mode models like gemini-3.1-flash-image-preview
|
|
115
|
+
// can still perform text/structured generation.
|
|
116
|
+
const isImageModel = IMAGE_GENERATION_MODELS.some((m) => this.modelName.includes(m));
|
|
117
|
+
const requestsNonImageOutput = options.output?.format === "json" ||
|
|
118
|
+
options.output?.format === "structured" ||
|
|
119
|
+
options.output?.format === "text";
|
|
120
|
+
if (isImageModel && !requestsNonImageOutput) {
|
|
121
|
+
logger.info(`Image model detected, forcing fake streaming`, {
|
|
122
|
+
provider: this.providerName,
|
|
123
|
+
model: this.modelName,
|
|
124
|
+
reason: "Image generation requires fake streaming to yield image output",
|
|
204
125
|
});
|
|
205
|
-
|
|
206
|
-
|
|
126
|
+
// Skip real streaming, go directly to fake streaming
|
|
127
|
+
return await this.executeFakeStreaming(options, analysisSchema);
|
|
207
128
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
129
|
+
// Central tool merge: Pre-merge base tools (MCP/built-in) with user-provided
|
|
130
|
+
// tools (e.g. RAG tools) into options.tools. This way, every provider's
|
|
131
|
+
// executeStream() can simply use options.tools (or getAllTools() + options.tools)
|
|
132
|
+
// and get the complete tool set without needing per-provider merge logic.
|
|
133
|
+
if (!options.disableTools && this.supportsTools()) {
|
|
134
|
+
const mergedTools = await this.getToolsForStream(options);
|
|
135
|
+
options = { ...options, tools: mergedTools };
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
options = { ...options, tools: {} };
|
|
139
|
+
}
|
|
140
|
+
// CRITICAL FIX: Always prefer real streaming over fake streaming
|
|
141
|
+
// Try real streaming first, use fake streaming only as fallback
|
|
142
|
+
try {
|
|
143
|
+
logger.debug(`Attempting real streaming`, {
|
|
144
|
+
provider: this.providerName,
|
|
145
|
+
timestamp: Date.now(),
|
|
146
|
+
});
|
|
147
|
+
const realStreamResult = await this.executeStream(options, analysisSchema);
|
|
148
|
+
logger.info(`Real streaming succeeded`, {
|
|
149
|
+
provider: this.providerName,
|
|
150
|
+
timestamp: Date.now(),
|
|
151
|
+
});
|
|
152
|
+
// If real streaming succeeds, return it (with tools support via Vercel AI SDK)
|
|
153
|
+
return realStreamResult;
|
|
154
|
+
}
|
|
155
|
+
catch (realStreamError) {
|
|
156
|
+
// Don't retry on terminal/abort errors — only fall back for
|
|
157
|
+
// "real streaming with tools is unsupported" style failures.
|
|
158
|
+
const errMsg = realStreamError instanceof Error
|
|
159
|
+
? realStreamError.message
|
|
160
|
+
: String(realStreamError);
|
|
161
|
+
const errName = realStreamError instanceof Error ? realStreamError.name : "";
|
|
162
|
+
if (errName === "AbortError" ||
|
|
163
|
+
errMsg.includes("abort") ||
|
|
164
|
+
errMsg.includes("timeout") ||
|
|
165
|
+
errMsg.includes("401") ||
|
|
166
|
+
errMsg.includes("403") ||
|
|
167
|
+
errMsg.includes("quota") ||
|
|
168
|
+
errMsg.includes("rate limit") ||
|
|
169
|
+
errMsg.includes("authentication")) {
|
|
170
|
+
throw this.handleProviderError(realStreamError);
|
|
214
171
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
172
|
+
logger.warn(`Real streaming failed for ${this.providerName}, falling back to fake streaming:`, {
|
|
173
|
+
error: errMsg,
|
|
174
|
+
timestamp: Date.now(),
|
|
175
|
+
});
|
|
176
|
+
// Fallback to fake streaming only if real streaming fails AND tools are enabled
|
|
177
|
+
if (!options.disableTools && this.supportsTools()) {
|
|
178
|
+
return await this.executeFakeStreaming(options, analysisSchema);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
// If real streaming failed and no tools are enabled, re-throw the original error
|
|
182
|
+
logger.error(`Real streaming failed for ${this.providerName}:`, realStreamError);
|
|
183
|
+
throw this.handleProviderError(realStreamError);
|
|
219
184
|
}
|
|
220
185
|
}
|
|
221
186
|
}
|
|
@@ -508,13 +473,6 @@ export class BaseProvider {
|
|
|
508
473
|
const options = this.normalizeTextOptions(optionsOrPrompt);
|
|
509
474
|
this.validateOptions(options);
|
|
510
475
|
const startTime = Date.now();
|
|
511
|
-
// Observability: create metrics span for provider.generate
|
|
512
|
-
const metricsSpan = SpanSerializer.createSpan(SpanType.MODEL_GENERATION, "provider.generate", {
|
|
513
|
-
"ai.provider": this.providerName || "unknown",
|
|
514
|
-
"ai.model": this.modelName || options.model || "unknown",
|
|
515
|
-
"ai.temperature": options.temperature,
|
|
516
|
-
"ai.max_tokens": options.maxTokens,
|
|
517
|
-
}, this._traceContext?.parentSpanId, this._traceContext?.traceId);
|
|
518
476
|
// OTEL span for provider-level generate tracing
|
|
519
477
|
// Use startActiveSpan pattern via context.with() so child spans become descendants
|
|
520
478
|
const otelSpan = tracers.provider.startSpan("neurolink.provider.generate", {
|
|
@@ -529,7 +487,7 @@ export class BaseProvider {
|
|
|
529
487
|
// Set this span as the active context so child spans (GenerationHandler, etc.) become descendants
|
|
530
488
|
const activeCtx = trace.setSpan(context.active(), otelSpan);
|
|
531
489
|
const otelSpanState = { ended: false };
|
|
532
|
-
return await context.with(activeCtx, async () => this.runGenerateInActiveContext(options, startTime,
|
|
490
|
+
return await context.with(activeCtx, async () => this.runGenerateInActiveContext(options, startTime, otelSpan, otelSpanState));
|
|
533
491
|
}
|
|
534
492
|
/**
|
|
535
493
|
* Alias for generate method - implements AIProvider interface
|
|
@@ -537,7 +495,7 @@ export class BaseProvider {
|
|
|
537
495
|
async gen(optionsOrPrompt, analysisSchema) {
|
|
538
496
|
return this.generate(optionsOrPrompt, analysisSchema);
|
|
539
497
|
}
|
|
540
|
-
async runGenerateInActiveContext(options, startTime,
|
|
498
|
+
async runGenerateInActiveContext(options, startTime, otelSpan, otelSpanState) {
|
|
541
499
|
try {
|
|
542
500
|
if (options.output?.mode === "video") {
|
|
543
501
|
return await this.handleVideoGeneration(options, startTime);
|
|
@@ -563,10 +521,9 @@ export class BaseProvider {
|
|
|
563
521
|
if (videoFrameResult) {
|
|
564
522
|
return videoFrameResult;
|
|
565
523
|
}
|
|
566
|
-
return await this.executeStandardGenerateFlow(options, startTime,
|
|
524
|
+
return await this.executeStandardGenerateFlow(options, startTime, model, messages, tools);
|
|
567
525
|
}
|
|
568
526
|
catch (error) {
|
|
569
|
-
SpanSerializer.endSpan(metricsSpan, SpanStatus.ERROR, error instanceof Error ? error.message : String(error));
|
|
570
527
|
otelSpan.setStatus({
|
|
571
528
|
code: SpanStatusCode.ERROR,
|
|
572
529
|
message: error instanceof Error ? error.message : String(error),
|
|
@@ -673,7 +630,7 @@ export class BaseProvider {
|
|
|
673
630
|
usage,
|
|
674
631
|
}, options, startTime);
|
|
675
632
|
}
|
|
676
|
-
async executeStandardGenerateFlow(options, startTime,
|
|
633
|
+
async executeStandardGenerateFlow(options, startTime, model, messages, tools) {
|
|
677
634
|
const timeoutController = createTimeoutController(options.timeout, this.providerName, "generate");
|
|
678
635
|
const composedSignal = composeAbortSignals(options.abortSignal, timeoutController?.controller.signal);
|
|
679
636
|
const composedOptions = composedSignal
|
|
@@ -693,23 +650,6 @@ export class BaseProvider {
|
|
|
693
650
|
const { toolsUsed, toolExecutions } = this.extractToolInformation(generateResult);
|
|
694
651
|
let enhancedResult = this.formatEnhancedResult(generateResult, tools, toolsUsed, toolExecutions, options);
|
|
695
652
|
enhancedResult = await this.synthesizeAIResponseIfNeeded(enhancedResult, options);
|
|
696
|
-
let enrichedGenerateSpan = { ...metricsSpan };
|
|
697
|
-
if (enhancedResult?.usage) {
|
|
698
|
-
enrichedGenerateSpan = SpanSerializer.enrichWithTokenUsage(enrichedGenerateSpan, {
|
|
699
|
-
promptTokens: enhancedResult.usage.input || 0,
|
|
700
|
-
completionTokens: enhancedResult.usage.output || 0,
|
|
701
|
-
totalTokens: enhancedResult.usage.total || 0,
|
|
702
|
-
});
|
|
703
|
-
const cost = calculateCost(this.providerName, this.modelName, {
|
|
704
|
-
input: enhancedResult.usage.input || 0,
|
|
705
|
-
output: enhancedResult.usage.output || 0,
|
|
706
|
-
total: enhancedResult.usage.total || 0,
|
|
707
|
-
});
|
|
708
|
-
if (cost && cost > 0) {
|
|
709
|
-
enrichedGenerateSpan = SpanSerializer.enrichWithCost(enrichedGenerateSpan, { totalCost: cost });
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
SpanSerializer.endSpan(enrichedGenerateSpan, SpanStatus.OK);
|
|
713
653
|
return this.enhanceResult(enhancedResult, options, startTime);
|
|
714
654
|
}
|
|
715
655
|
async synthesizeAIResponseIfNeeded(enhancedResult, options) {
|
|
@@ -1000,7 +940,38 @@ export class BaseProvider {
|
|
|
1000
940
|
? error
|
|
1001
941
|
: new DOMException("The operation was aborted", "AbortError");
|
|
1002
942
|
}
|
|
1003
|
-
|
|
943
|
+
const formatted = this.formatProviderError(error);
|
|
944
|
+
// P3 fix: Classify error and set error.type on the active OTel span
|
|
945
|
+
try {
|
|
946
|
+
const activeSpan = trace.getSpan(context.active());
|
|
947
|
+
if (activeSpan) {
|
|
948
|
+
let errorType = "provider_error";
|
|
949
|
+
const errName = formatted?.constructor?.name ?? "";
|
|
950
|
+
if (errName === "RateLimitError") {
|
|
951
|
+
errorType = "rate_limit";
|
|
952
|
+
}
|
|
953
|
+
else if (errName === "AuthenticationError") {
|
|
954
|
+
errorType = "auth_failure";
|
|
955
|
+
}
|
|
956
|
+
else if (errName === "NetworkError") {
|
|
957
|
+
errorType = "network";
|
|
958
|
+
}
|
|
959
|
+
else if (errName === "InvalidModelError") {
|
|
960
|
+
errorType = "invalid_model";
|
|
961
|
+
}
|
|
962
|
+
else if (errName === "TimeoutError") {
|
|
963
|
+
errorType = "timeout";
|
|
964
|
+
}
|
|
965
|
+
activeSpan.setAttribute("error.type", errorType);
|
|
966
|
+
if (formatted instanceof Error) {
|
|
967
|
+
activeSpan.setAttribute("error.message", formatted.message.substring(0, 500));
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
catch {
|
|
972
|
+
// Non-blocking — telemetry failures shouldn't mask the original error
|
|
973
|
+
}
|
|
974
|
+
return formatted;
|
|
1004
975
|
}
|
|
1005
976
|
/**
|
|
1006
977
|
* Image generation method. Providers that support it should override this.
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { InfraRegistryEntry } from "../../types/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Local alias: the canonical type was renamed to InfraRegistryEntry to avoid
|
|
4
|
-
* collision with other RegistryEntry types in the codebase.
|
|
5
|
-
*/
|
|
6
|
-
type RegistryEntry<TItem, TMetadata = unknown> = InfraRegistryEntry<TItem, TMetadata>;
|
|
7
2
|
export declare abstract class BaseRegistry<TItem, TMetadata = unknown> {
|
|
8
|
-
protected items: Map<string,
|
|
3
|
+
protected items: Map<string, InfraRegistryEntry<TItem, TMetadata>>;
|
|
9
4
|
protected initialized: boolean;
|
|
10
5
|
protected initPromise: Promise<void> | null;
|
|
11
6
|
protected abstract registerAll(): Promise<void>;
|
|
@@ -22,4 +17,3 @@ export declare abstract class BaseRegistry<TItem, TMetadata = unknown> {
|
|
|
22
17
|
clear(): void;
|
|
23
18
|
isInitialized(): boolean;
|
|
24
19
|
}
|
|
25
|
-
export {};
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import type { LanguageModel, ModelMessage, Tool } from "ai";
|
|
16
16
|
import { generateText } from "ai";
|
|
17
|
-
import type { AIProviderName, EnhancedGenerateResult, StandardRecord, TextGenerationOptions } from "../../types/index.js";
|
|
17
|
+
import type { AIProviderName, EnhancedGenerateResult, NeuroLinkEvents, StandardRecord, TextGenerationOptions, TypedEventEmitter } from "../../types/index.js";
|
|
18
18
|
/**
|
|
19
19
|
* GenerationHandler class - Handles text generation operations for AI providers
|
|
20
20
|
*/
|
|
@@ -24,11 +24,12 @@ export declare class GenerationHandler {
|
|
|
24
24
|
private readonly supportsToolsFn;
|
|
25
25
|
private readonly getTelemetryConfigFn;
|
|
26
26
|
private readonly handleToolStorageFn;
|
|
27
|
+
private readonly getEmitterFn?;
|
|
27
28
|
constructor(providerName: AIProviderName, modelName: string, supportsToolsFn: () => boolean, getTelemetryConfigFn: (options: TextGenerationOptions, type: string) => {
|
|
28
29
|
isEnabled: boolean;
|
|
29
30
|
functionId?: string;
|
|
30
31
|
metadata?: Record<string, string | number | boolean>;
|
|
31
|
-
} | undefined, handleToolStorageFn: (toolCalls: unknown[], toolResults: unknown[], options: TextGenerationOptions, timestamp: Date) => Promise<void>);
|
|
32
|
+
} | undefined, handleToolStorageFn: (toolCalls: unknown[], toolResults: unknown[], options: TextGenerationOptions, timestamp: Date) => Promise<void>, getEmitterFn?: (() => TypedEventEmitter<NeuroLinkEvents> | undefined) | undefined);
|
|
32
33
|
/**
|
|
33
34
|
* Helper method to call generateText with optional structured output
|
|
34
35
|
* @private
|
|
@@ -17,6 +17,7 @@ import { generateText, NoObjectGeneratedError, Output, stepCountIs } from "ai";
|
|
|
17
17
|
import { getModelId } from "../../providers/providerTypeUtils.js";
|
|
18
18
|
import { tracers } from "../../telemetry/tracers.js";
|
|
19
19
|
import { logger } from "../../utils/logger.js";
|
|
20
|
+
import { emitToolEndFromStepFinish } from "../../utils/toolEndEmitter.js";
|
|
20
21
|
import { calculateCost } from "../../utils/pricing.js";
|
|
21
22
|
import { withProviderRetry } from "../../utils/providerRetry.js";
|
|
22
23
|
import { calculateCacheSavingsPercent, extractCacheCreationTokens, extractCacheReadTokens, extractTokenUsage, } from "../../utils/tokenUtils.js";
|
|
@@ -47,12 +48,14 @@ export class GenerationHandler {
|
|
|
47
48
|
supportsToolsFn;
|
|
48
49
|
getTelemetryConfigFn;
|
|
49
50
|
handleToolStorageFn;
|
|
50
|
-
|
|
51
|
+
getEmitterFn;
|
|
52
|
+
constructor(providerName, modelName, supportsToolsFn, getTelemetryConfigFn, handleToolStorageFn, getEmitterFn) {
|
|
51
53
|
this.providerName = providerName;
|
|
52
54
|
this.modelName = modelName;
|
|
53
55
|
this.supportsToolsFn = supportsToolsFn;
|
|
54
56
|
this.getTelemetryConfigFn = getTelemetryConfigFn;
|
|
55
57
|
this.handleToolStorageFn = handleToolStorageFn;
|
|
58
|
+
this.getEmitterFn = getEmitterFn;
|
|
56
59
|
}
|
|
57
60
|
/**
|
|
58
61
|
* Helper method to call generateText with optional structured output
|
|
@@ -154,6 +157,11 @@ export class GenerationHandler {
|
|
|
154
157
|
experimental_telemetry: this.getTelemetryConfigFn(options, "generate"),
|
|
155
158
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
156
159
|
logger.info("Tool execution completed", { toolResults, toolCalls });
|
|
160
|
+
// Emit tool:end events for Pipeline B (metrics aggregator).
|
|
161
|
+
// This surfaces AI-SDK-driven tool completions as telemetry events
|
|
162
|
+
// so that tool spans are created even when the SDK runs tools
|
|
163
|
+
// internally (gaps G5 / S2).
|
|
164
|
+
emitToolEndFromStepFinish(this.getEmitterFn?.(), toolResults);
|
|
157
165
|
// Handle tool execution storage
|
|
158
166
|
this.handleToolStorageFn(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
159
167
|
logger.warn("[GenerationHandler] Failed to store tool executions", {
|
|
@@ -113,6 +113,15 @@ export class StreamHandler {
|
|
|
113
113
|
// rather than crashing the process with an unhandled rejection.
|
|
114
114
|
if (NoOutputGeneratedError.isInstance(error)) {
|
|
115
115
|
logger.warn(`${providerName}: Stream produced no output (NoOutputGeneratedError), returning empty stream`);
|
|
116
|
+
// S4 fix: yield a sentinel chunk so Pipeline B can detect the empty stream
|
|
117
|
+
// and set the span to WARNING status instead of OK
|
|
118
|
+
yield {
|
|
119
|
+
content: "",
|
|
120
|
+
metadata: {
|
|
121
|
+
noOutput: true,
|
|
122
|
+
errorType: "NoOutputGeneratedError",
|
|
123
|
+
},
|
|
124
|
+
};
|
|
116
125
|
}
|
|
117
126
|
else {
|
|
118
127
|
throw error;
|
|
@@ -442,7 +442,15 @@ export class ToolsManager {
|
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
444
|
customToolSpan.setAttribute("tool.result.status", errorResult ? "error" : "success");
|
|
445
|
-
|
|
445
|
+
if (errorResult) {
|
|
446
|
+
customToolSpan.setStatus({
|
|
447
|
+
code: SpanStatusCode.ERROR,
|
|
448
|
+
message: `Tool ${toolName} returned isError: true`,
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
customToolSpan.setStatus({ code: SpanStatusCode.OK });
|
|
453
|
+
}
|
|
446
454
|
return convertedResult;
|
|
447
455
|
}
|
|
448
456
|
// Fallback: direct execution (standalone usage without NeuroLink SDK)
|
|
@@ -472,7 +480,15 @@ export class ToolsManager {
|
|
|
472
480
|
}
|
|
473
481
|
customToolSpan.setAttribute("tool.duration_ms", endTime - startTime);
|
|
474
482
|
customToolSpan.setAttribute("tool.result.status", errorResult ? "error" : "success");
|
|
475
|
-
|
|
483
|
+
if (errorResult) {
|
|
484
|
+
customToolSpan.setStatus({
|
|
485
|
+
code: SpanStatusCode.ERROR,
|
|
486
|
+
message: `Tool ${toolName} returned isError: true`,
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
customToolSpan.setStatus({ code: SpanStatusCode.OK });
|
|
491
|
+
}
|
|
476
492
|
return convertedResult;
|
|
477
493
|
}
|
|
478
494
|
catch (error) {
|
|
@@ -2,102 +2,7 @@
|
|
|
2
2
|
* @file BatchEvaluator - Supports batch evaluation of multiple responses.
|
|
3
3
|
* Enables parallel evaluation with configurable concurrency and error handling.
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
6
|
-
import type { GenerateResult, EvaluationConfig, EvaluationData, AutoEvaluationConfig } from "../types/index.js";
|
|
7
|
-
/**
|
|
8
|
-
* Configuration for batch evaluation.
|
|
9
|
-
*/
|
|
10
|
-
type BatchEvaluationConfig = EvaluationConfig & {
|
|
11
|
-
/** Maximum number of concurrent evaluations (default: 5) */
|
|
12
|
-
concurrency?: number;
|
|
13
|
-
/** Whether to continue on individual failures (default: true) */
|
|
14
|
-
continueOnError?: boolean;
|
|
15
|
-
/** Maximum retries for retryable errors (default: 2) */
|
|
16
|
-
maxRetries?: number;
|
|
17
|
-
/** Delay between retries in milliseconds (default: 1000) */
|
|
18
|
-
retryDelay?: number;
|
|
19
|
-
/** Callback for progress updates */
|
|
20
|
-
onProgress?: (progress: BatchProgress) => void;
|
|
21
|
-
/** Callback for individual evaluation completion */
|
|
22
|
-
onItemComplete?: (result: BatchEvaluationItemResult) => void;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Progress information for batch evaluation.
|
|
26
|
-
*/
|
|
27
|
-
type BatchProgress = {
|
|
28
|
-
/** Total items to evaluate */
|
|
29
|
-
total: number;
|
|
30
|
-
/** Items completed (success + failed) */
|
|
31
|
-
completed: number;
|
|
32
|
-
/** Items that succeeded */
|
|
33
|
-
succeeded: number;
|
|
34
|
-
/** Items that failed */
|
|
35
|
-
failed: number;
|
|
36
|
-
/** Items still pending */
|
|
37
|
-
pending: number;
|
|
38
|
-
/** Percentage complete */
|
|
39
|
-
percentComplete: number;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Input item for batch evaluation.
|
|
43
|
-
*/
|
|
44
|
-
type BatchEvaluationItem = {
|
|
45
|
-
/** Unique identifier for this item */
|
|
46
|
-
id: string;
|
|
47
|
-
/** The generation options */
|
|
48
|
-
options: LanguageModelV3CallOptions;
|
|
49
|
-
/** The generation result to evaluate */
|
|
50
|
-
result: GenerateResult;
|
|
51
|
-
/** Optional item-specific threshold override */
|
|
52
|
-
threshold?: number;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Result for a single item in batch evaluation.
|
|
56
|
-
*/
|
|
57
|
-
type BatchEvaluationItemResult = {
|
|
58
|
-
/** The item ID */
|
|
59
|
-
id: string;
|
|
60
|
-
/** Whether the evaluation succeeded */
|
|
61
|
-
success: boolean;
|
|
62
|
-
/** The evaluation data (if successful) */
|
|
63
|
-
data?: EvaluationData;
|
|
64
|
-
/** Error information (if failed) */
|
|
65
|
-
error?: {
|
|
66
|
-
message: string;
|
|
67
|
-
code?: string;
|
|
68
|
-
retryable?: boolean;
|
|
69
|
-
};
|
|
70
|
-
/** Time taken for this evaluation in milliseconds */
|
|
71
|
-
duration: number;
|
|
72
|
-
/** Number of retry attempts (if any) */
|
|
73
|
-
retryCount: number;
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Result of a batch evaluation operation.
|
|
77
|
-
*/
|
|
78
|
-
type BatchEvaluationResult = {
|
|
79
|
-
/** All item results */
|
|
80
|
-
results: BatchEvaluationItemResult[];
|
|
81
|
-
/** Summary statistics */
|
|
82
|
-
summary: {
|
|
83
|
-
/** Total items evaluated */
|
|
84
|
-
total: number;
|
|
85
|
-
/** Number of successful evaluations */
|
|
86
|
-
succeeded: number;
|
|
87
|
-
/** Number of failed evaluations */
|
|
88
|
-
failed: number;
|
|
89
|
-
/** Average evaluation score (for successful items) */
|
|
90
|
-
averageScore: number;
|
|
91
|
-
/** Average evaluation time in milliseconds */
|
|
92
|
-
averageDuration: number;
|
|
93
|
-
/** Total time for batch evaluation */
|
|
94
|
-
totalDuration: number;
|
|
95
|
-
/** Passing rate (percentage of items meeting threshold) */
|
|
96
|
-
passingRate: number;
|
|
97
|
-
};
|
|
98
|
-
/** Whether all evaluations succeeded */
|
|
99
|
-
allSucceeded: boolean;
|
|
100
|
-
};
|
|
5
|
+
import type { AutoEvaluationConfig, BatchEvaluationConfig, BatchEvaluationItem, BatchEvaluationResult } from "../types/index.js";
|
|
101
6
|
/**
|
|
102
7
|
* BatchEvaluator - Performs evaluation on multiple items in parallel.
|
|
103
8
|
* Supports configurable concurrency, retry logic, and progress tracking.
|
|
@@ -158,4 +63,3 @@ export declare class BatchEvaluator {
|
|
|
158
63
|
*/
|
|
159
64
|
private delay;
|
|
160
65
|
}
|
|
161
|
-
export {};
|