@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
|
@@ -23,6 +23,7 @@ import { convertZodToJsonSchema, inlineJsonSchema, } from "../utils/schemaConver
|
|
|
23
23
|
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
|
|
24
24
|
import { estimateTokens } from "../utils/tokenEstimation.js";
|
|
25
25
|
import { resolveToolChoice } from "../utils/toolChoice.js";
|
|
26
|
+
import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
|
|
26
27
|
import { buildNativeConfig, buildNativeToolDeclarations, collectStreamChunks, collectStreamChunksIncremental, computeMaxSteps as computeMaxStepsShared, createTextChannel, executeNativeToolCalls, extractTextFromParts, handleMaxStepsTermination, normalizeToolsForJsonSchemaProvider, pushModelResponseToHistory, sanitizeToolsForGemini, } from "./googleNativeGemini3.js";
|
|
27
28
|
import { getModelId } from "./providerTypeUtils.js";
|
|
28
29
|
// Import proper types for multimodal message handling
|
|
@@ -857,23 +858,19 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
857
858
|
async maybeExecuteNativeGemini3ToolStream(options, analysisSchema, modelName) {
|
|
858
859
|
const wantsStructuredOutput = analysisSchema || options.output?.format === "json" || options.schema;
|
|
859
860
|
const shouldUseTools = !options.disableTools && this.supportsTools() && !wantsStructuredOutput;
|
|
860
|
-
const
|
|
861
|
-
const
|
|
862
|
-
const combinedToolCount = Object.keys(optionTools).length + Object.keys(sdkTools).length;
|
|
863
|
-
const hasTools = shouldUseTools && combinedToolCount > 0;
|
|
861
|
+
const tools = options.tools || {};
|
|
862
|
+
const hasTools = shouldUseTools && Object.keys(tools).length > 0;
|
|
864
863
|
if (!isGemini3Model(modelName) || !hasTools) {
|
|
865
864
|
return null;
|
|
866
865
|
}
|
|
867
866
|
const processedOptions = await this.processCSVFilesForNativeSDK(options);
|
|
868
867
|
const mergedOptions = {
|
|
869
868
|
...processedOptions,
|
|
870
|
-
tools:
|
|
869
|
+
tools: tools,
|
|
871
870
|
};
|
|
872
871
|
logger.info("[GoogleVertex] Routing Gemini 3 to native SDK for tool calling", {
|
|
873
872
|
model: modelName,
|
|
874
|
-
optionToolCount: Object.keys(
|
|
875
|
-
sdkToolCount: Object.keys(sdkTools).length,
|
|
876
|
-
totalToolCount: combinedToolCount,
|
|
873
|
+
optionToolCount: Object.keys(tools).length,
|
|
877
874
|
});
|
|
878
875
|
return this.executeNativeGemini3Stream(mergedOptions);
|
|
879
876
|
}
|
|
@@ -933,9 +930,8 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
933
930
|
}
|
|
934
931
|
async resolveAISDKStreamTools(options, modelName, functionTag) {
|
|
935
932
|
const shouldUseTools = !options.disableTools && this.supportsTools();
|
|
936
|
-
const baseStreamTools = shouldUseTools ? await this.getAllTools() : {};
|
|
937
933
|
const rawTools = shouldUseTools
|
|
938
|
-
?
|
|
934
|
+
? options.tools
|
|
939
935
|
: {};
|
|
940
936
|
const isAnthropic = isAnthropicModel(modelName);
|
|
941
937
|
let tools;
|
|
@@ -963,8 +959,7 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
963
959
|
}
|
|
964
960
|
logger.debug(`${functionTag}: Tools for streaming`, {
|
|
965
961
|
shouldUseTools,
|
|
966
|
-
|
|
967
|
-
externalToolCount: Object.keys(options.tools || {}).length,
|
|
962
|
+
externalToolCount: Object.keys(options.tools ?? {}).length,
|
|
968
963
|
toolCount: Object.keys(tools ?? {}).length,
|
|
969
964
|
toolNames: Object.keys(tools ?? {}),
|
|
970
965
|
});
|
|
@@ -972,7 +967,7 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
972
967
|
shouldUseTools,
|
|
973
968
|
tools,
|
|
974
969
|
isAnthropic,
|
|
975
|
-
baseToolCount:
|
|
970
|
+
baseToolCount: 0,
|
|
976
971
|
};
|
|
977
972
|
}
|
|
978
973
|
buildAISDKStreamOptions(params) {
|
|
@@ -1075,6 +1070,9 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
1075
1070
|
id: toolResult.toolCallId ?? toolResult.toolName,
|
|
1076
1071
|
});
|
|
1077
1072
|
}
|
|
1073
|
+
// Emit tool:end for each completed tool result so Pipeline B
|
|
1074
|
+
// captures telemetry for AI-SDK-driven tool calls (gap S2).
|
|
1075
|
+
emitToolEndFromStepFinish(this.neurolink?.getEventEmitter(), toolResults);
|
|
1078
1076
|
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
1079
1077
|
logger.warn("[GoogleVertexProvider] Failed to store tool executions", {
|
|
1080
1078
|
provider: this.providerName,
|
|
@@ -1516,6 +1514,31 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
1516
1514
|
requestDuration: responseTime,
|
|
1517
1515
|
timestamp: new Date().toISOString(),
|
|
1518
1516
|
});
|
|
1517
|
+
// Emit generation:end so Pipeline B (Langfuse) creates a GENERATION
|
|
1518
|
+
// observation. The native @google/genai stream path on Vertex bypasses the
|
|
1519
|
+
// Vercel AI SDK so experimental_telemetry is never injected; we emit manually.
|
|
1520
|
+
const vertexStreamEmitter = this.neurolink?.getEventEmitter();
|
|
1521
|
+
if (vertexStreamEmitter) {
|
|
1522
|
+
vertexStreamEmitter.emit("generation:end", {
|
|
1523
|
+
provider: this.providerName,
|
|
1524
|
+
responseTime,
|
|
1525
|
+
timestamp: Date.now(),
|
|
1526
|
+
result: {
|
|
1527
|
+
content: "",
|
|
1528
|
+
usage: {
|
|
1529
|
+
input: totalInputTokens,
|
|
1530
|
+
output: totalOutputTokens,
|
|
1531
|
+
total: totalInputTokens + totalOutputTokens,
|
|
1532
|
+
},
|
|
1533
|
+
model: params.modelName,
|
|
1534
|
+
provider: this.providerName,
|
|
1535
|
+
finishReason: step >= params.maxSteps && !completedWithFinalAnswer
|
|
1536
|
+
? "max_steps"
|
|
1537
|
+
: "stop",
|
|
1538
|
+
},
|
|
1539
|
+
success: true,
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1519
1542
|
params.channel.close();
|
|
1520
1543
|
}
|
|
1521
1544
|
catch (error) {
|
|
@@ -1563,14 +1586,13 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
1563
1586
|
logger.warn("[GoogleVertex] Gemini does not support tools and JSON schema output simultaneously. Disabling tools for this request.");
|
|
1564
1587
|
shouldUseTools = false;
|
|
1565
1588
|
}
|
|
1566
|
-
const
|
|
1567
|
-
|
|
1568
|
-
? { ...sdkTools, ...(options.tools || {}) }
|
|
1589
|
+
const tools = shouldUseTools
|
|
1590
|
+
? (options.tools ?? {})
|
|
1569
1591
|
: {};
|
|
1570
1592
|
let toolsConfig;
|
|
1571
1593
|
let executeMap = new Map();
|
|
1572
|
-
if (Object.keys(
|
|
1573
|
-
const result = buildNativeToolDeclarations(
|
|
1594
|
+
if (Object.keys(tools).length > 0) {
|
|
1595
|
+
const result = buildNativeToolDeclarations(tools);
|
|
1574
1596
|
toolsConfig = result.toolsConfig;
|
|
1575
1597
|
executeMap = result.executeMap;
|
|
1576
1598
|
logger.debug("[GoogleVertex] Converted tools for native SDK generate", {
|
|
@@ -1661,6 +1683,29 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
1661
1683
|
span.setAttribute(ATTR.GEN_AI_INPUT_TOKENS, totalInputTokens);
|
|
1662
1684
|
span.setAttribute(ATTR.GEN_AI_OUTPUT_TOKENS, totalOutputTokens);
|
|
1663
1685
|
span.setAttribute(ATTR.GEN_AI_FINISH_REASON, step >= maxSteps ? "max_steps" : "stop");
|
|
1686
|
+
// Emit generation:end so Pipeline B (Langfuse) creates a GENERATION
|
|
1687
|
+
// observation. The native @google/genai path on Vertex bypasses the Vercel
|
|
1688
|
+
// AI SDK so experimental_telemetry is never injected; we emit manually.
|
|
1689
|
+
const vertexGenerateEmitter = this.neurolink?.getEventEmitter();
|
|
1690
|
+
if (vertexGenerateEmitter) {
|
|
1691
|
+
vertexGenerateEmitter.emit("generation:end", {
|
|
1692
|
+
provider: this.providerName,
|
|
1693
|
+
responseTime,
|
|
1694
|
+
timestamp: Date.now(),
|
|
1695
|
+
result: {
|
|
1696
|
+
content: finalText,
|
|
1697
|
+
usage: {
|
|
1698
|
+
input: totalInputTokens,
|
|
1699
|
+
output: totalOutputTokens,
|
|
1700
|
+
total: totalInputTokens + totalOutputTokens,
|
|
1701
|
+
},
|
|
1702
|
+
model: modelName,
|
|
1703
|
+
provider: this.providerName,
|
|
1704
|
+
finishReason: step >= maxSteps ? "max_steps" : "stop",
|
|
1705
|
+
},
|
|
1706
|
+
success: true,
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1664
1709
|
// Build EnhancedGenerateResult
|
|
1665
1710
|
return {
|
|
1666
1711
|
content: finalText,
|
|
@@ -1760,24 +1805,18 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
1760
1805
|
const wantsStructuredOutput = options.output?.format === "json" || !!options.schema;
|
|
1761
1806
|
// Check if we should use native SDK for Gemini 3 with tools
|
|
1762
1807
|
const shouldUseTools = !options.disableTools && this.supportsTools() && !wantsStructuredOutput;
|
|
1763
|
-
const
|
|
1764
|
-
const hasTools = shouldUseTools &&
|
|
1765
|
-
(Object.keys(sdkTools).length > 0 ||
|
|
1766
|
-
(options.tools && Object.keys(options.tools).length > 0));
|
|
1808
|
+
const hasTools = shouldUseTools && options.tools && Object.keys(options.tools).length > 0;
|
|
1767
1809
|
if (isGemini3Model(modelName) && hasTools && !wantsStructuredOutput) {
|
|
1768
1810
|
// Process CSV files before routing to native SDK (bypasses normal message builder)
|
|
1769
1811
|
const processedOptions = await this.processCSVFilesForNativeSDK(options);
|
|
1770
1812
|
// Merge SDK tools into options for native SDK path
|
|
1771
1813
|
const mergedOptions = {
|
|
1772
1814
|
...processedOptions,
|
|
1773
|
-
tools:
|
|
1815
|
+
tools: options.tools || {},
|
|
1774
1816
|
};
|
|
1775
1817
|
logger.info("[GoogleVertex] Routing Gemini 3 generate to native SDK for tool calling", {
|
|
1776
1818
|
model: modelName,
|
|
1777
|
-
|
|
1778
|
-
optionToolCount: Object.keys(processedOptions.tools || {}).length,
|
|
1779
|
-
totalToolCount: Object.keys(sdkTools).length +
|
|
1780
|
-
Object.keys(processedOptions.tools || {}).length,
|
|
1819
|
+
totalToolCount: Object.keys(mergedOptions.tools ?? {}).length,
|
|
1781
1820
|
});
|
|
1782
1821
|
return this.executeNativeGemini3Generate(mergedOptions);
|
|
1783
1822
|
}
|
|
@@ -3,6 +3,7 @@ import { NoOutputGeneratedError, stepCountIs, streamText, } from "ai";
|
|
|
3
3
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
4
4
|
import { DEFAULT_MAX_STEPS } from "../core/constants.js";
|
|
5
5
|
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
6
|
+
import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
|
|
6
7
|
import { logger } from "../utils/logger.js";
|
|
7
8
|
import { createHuggingFaceConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
|
|
8
9
|
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
|
|
@@ -141,6 +142,7 @@ export class HuggingFaceProvider extends BaseProvider {
|
|
|
141
142
|
experimental_telemetry: this.telemetryHandler.getTelemetryConfig(options),
|
|
142
143
|
experimental_repairToolCall: this.getToolCallRepairFn(options),
|
|
143
144
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
145
|
+
emitToolEndFromStepFinish(this.neurolink?.getEventEmitter(), toolResults);
|
|
144
146
|
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
145
147
|
logger.warn("[HuggingFaceProvider] Failed to store tool executions", {
|
|
146
148
|
provider: this.providerName,
|
|
@@ -7,6 +7,7 @@ import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
|
|
|
7
7
|
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
8
8
|
import { AuthenticationError, InvalidModelError, NetworkError, ProviderError, RateLimitError, } from "../types/index.js";
|
|
9
9
|
import { isAbortError } from "../utils/errorHandling.js";
|
|
10
|
+
import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
|
|
10
11
|
import { logger } from "../utils/logger.js";
|
|
11
12
|
import { calculateCost } from "../utils/pricing.js";
|
|
12
13
|
import { getProviderModel } from "../utils/providerConfig.js";
|
|
@@ -190,6 +191,7 @@ export class LiteLLMProvider extends BaseProvider {
|
|
|
190
191
|
chunkCount++;
|
|
191
192
|
},
|
|
192
193
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
194
|
+
emitToolEndFromStepFinish(this.neurolink?.getEventEmitter(), toolResults);
|
|
193
195
|
logger.info("Tool execution completed", { toolResults, toolCalls });
|
|
194
196
|
for (const toolCall of toolCalls) {
|
|
195
197
|
collectedToolCalls.push({
|
|
@@ -4,6 +4,7 @@ import { BaseProvider } from "../core/baseProvider.js";
|
|
|
4
4
|
import { DEFAULT_MAX_STEPS } from "../core/constants.js";
|
|
5
5
|
import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
|
|
6
6
|
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
7
|
+
import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
|
|
7
8
|
import { logger } from "../utils/logger.js";
|
|
8
9
|
import { createMistralConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
|
|
9
10
|
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
|
|
@@ -69,6 +70,7 @@ export class MistralProvider extends BaseProvider {
|
|
|
69
70
|
experimental_telemetry: this.telemetryHandler.getTelemetryConfig(options),
|
|
70
71
|
experimental_repairToolCall: this.getToolCallRepairFn(options),
|
|
71
72
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
73
|
+
emitToolEndFromStepFinish(this.neurolink?.getEventEmitter(), toolResults);
|
|
72
74
|
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
73
75
|
logger.warn("[MistralProvider] Failed to store tool executions", {
|
|
74
76
|
provider: this.providerName,
|
package/dist/providers/ollama.js
CHANGED
|
@@ -9,6 +9,7 @@ import { buildMultimodalOptions } from "../utils/multimodalOptionsBuilder.js";
|
|
|
9
9
|
import { estimateTokens } from "../utils/tokenEstimation.js";
|
|
10
10
|
import { InvalidModelError, NetworkError, ProviderError, } from "../types/index.js";
|
|
11
11
|
import { tracers, ATTR, withClientSpan } from "../telemetry/index.js";
|
|
12
|
+
import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
|
|
12
13
|
import { TimeoutError } from "../utils/timeout.js";
|
|
13
14
|
// Model version constants (configurable via environment)
|
|
14
15
|
const DEFAULT_OLLAMA_MODEL = process.env.OLLAMA_MODEL || "llama3.1:8b";
|
|
@@ -743,13 +744,22 @@ export class OllamaProvider extends BaseProvider {
|
|
|
743
744
|
content: options.input.text,
|
|
744
745
|
});
|
|
745
746
|
}
|
|
747
|
+
// Capture instance references before the stream for use in the finally block.
|
|
748
|
+
const ollamaNeurolink = this.neurolink;
|
|
749
|
+
const ollamaProviderName = this.providerName;
|
|
750
|
+
const ollamaModelName = this.modelName || FALLBACK_OLLAMA_MODEL;
|
|
746
751
|
// Conversation loop for multi-step tool execution
|
|
752
|
+
let totalInputTokens = 0;
|
|
753
|
+
let totalOutputTokens = 0;
|
|
754
|
+
let lastFinishReason;
|
|
755
|
+
let ollamaStreamErrored = false;
|
|
747
756
|
const stream = new ReadableStream({
|
|
748
757
|
start: async (controller) => {
|
|
749
758
|
try {
|
|
750
759
|
while (iteration < maxIterations) {
|
|
751
760
|
logger.debug(`[OllamaProvider] Conversation iteration ${iteration + 1}/${maxIterations}`);
|
|
752
|
-
// Make API request
|
|
761
|
+
// Make API request — request usage in stream_options so
|
|
762
|
+
// Pipeline B gets real token counts for Langfuse cost dashboards.
|
|
753
763
|
const response = await proxyFetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
754
764
|
method: "POST",
|
|
755
765
|
headers: { "Content-Type": "application/json" },
|
|
@@ -759,6 +769,7 @@ export class OllamaProvider extends BaseProvider {
|
|
|
759
769
|
tools: ollamaTools,
|
|
760
770
|
tool_choice: "auto",
|
|
761
771
|
stream: true,
|
|
772
|
+
stream_options: { include_usage: true },
|
|
762
773
|
temperature: options.temperature,
|
|
763
774
|
max_tokens: options.maxTokens,
|
|
764
775
|
}),
|
|
@@ -768,7 +779,15 @@ export class OllamaProvider extends BaseProvider {
|
|
|
768
779
|
throw this.handleProviderError(await createOllamaHttpError(response));
|
|
769
780
|
}
|
|
770
781
|
// Process response stream
|
|
771
|
-
const { content, toolCalls, finishReason } = await this.processOllamaResponse(response, controller);
|
|
782
|
+
const { content, toolCalls, finishReason, usage } = await this.processOllamaResponse(response, controller);
|
|
783
|
+
// Accumulate usage across iterations for Pipeline B
|
|
784
|
+
if (usage) {
|
|
785
|
+
totalInputTokens += usage.input;
|
|
786
|
+
totalOutputTokens += usage.output;
|
|
787
|
+
}
|
|
788
|
+
if (finishReason) {
|
|
789
|
+
lastFinishReason = finishReason;
|
|
790
|
+
}
|
|
772
791
|
// Add assistant message to history
|
|
773
792
|
const assistantMessage = {
|
|
774
793
|
role: "assistant",
|
|
@@ -822,20 +841,53 @@ export class OllamaProvider extends BaseProvider {
|
|
|
822
841
|
}
|
|
823
842
|
}
|
|
824
843
|
if (iteration >= maxIterations) {
|
|
844
|
+
ollamaStreamErrored = true;
|
|
825
845
|
controller.error(new Error(`Ollama conversation exceeded maximum iterations (${maxIterations})`));
|
|
826
846
|
}
|
|
827
847
|
}
|
|
828
848
|
catch (error) {
|
|
849
|
+
ollamaStreamErrored = true;
|
|
829
850
|
controller.error(error);
|
|
830
851
|
}
|
|
831
852
|
finally {
|
|
832
|
-
// Resolve analytics with
|
|
833
|
-
|
|
853
|
+
// Resolve analytics with accumulated token counts so Pipeline A
|
|
854
|
+
// and Pipeline B both get real usage data from Ollama.
|
|
855
|
+
const aggregatedUsage = {
|
|
856
|
+
input: totalInputTokens,
|
|
857
|
+
output: totalOutputTokens,
|
|
858
|
+
total: totalInputTokens + totalOutputTokens,
|
|
859
|
+
};
|
|
860
|
+
resolveAnalytics(createAnalytics(this.providerName, this.modelName || FALLBACK_OLLAMA_MODEL, { usage: aggregatedUsage }, Date.now() - startTime, {
|
|
834
861
|
requestId: `ollama-stream-${Date.now()}`,
|
|
835
862
|
streamingMode: true,
|
|
836
863
|
iterations: iteration,
|
|
837
|
-
note: "Token usage not available from Ollama streaming responses",
|
|
838
864
|
}));
|
|
865
|
+
// Emit generation:end so Pipeline B (Langfuse) creates a GENERATION
|
|
866
|
+
// observation. Ollama bypasses the Vercel AI SDK so
|
|
867
|
+
// experimental_telemetry is never injected; we emit manually.
|
|
868
|
+
const ollamaEmitter = ollamaNeurolink?.getEventEmitter();
|
|
869
|
+
if (ollamaEmitter) {
|
|
870
|
+
// Collect accumulated text from conversation history
|
|
871
|
+
const accumulatedContent = conversationHistory
|
|
872
|
+
.filter((m) => m.role === "assistant")
|
|
873
|
+
.map((m) => m.content)
|
|
874
|
+
.join("");
|
|
875
|
+
ollamaEmitter.emit("generation:end", {
|
|
876
|
+
provider: ollamaProviderName,
|
|
877
|
+
responseTime: Date.now() - startTime,
|
|
878
|
+
timestamp: Date.now(),
|
|
879
|
+
result: {
|
|
880
|
+
content: accumulatedContent,
|
|
881
|
+
usage: aggregatedUsage,
|
|
882
|
+
model: ollamaModelName,
|
|
883
|
+
provider: ollamaProviderName,
|
|
884
|
+
finishReason: ollamaStreamErrored
|
|
885
|
+
? "error"
|
|
886
|
+
: (lastFinishReason ?? "stop"),
|
|
887
|
+
},
|
|
888
|
+
success: !ollamaStreamErrored,
|
|
889
|
+
});
|
|
890
|
+
}
|
|
839
891
|
}
|
|
840
892
|
},
|
|
841
893
|
});
|
|
@@ -1075,6 +1127,7 @@ export class OllamaProvider extends BaseProvider {
|
|
|
1075
1127
|
let aggregatedContent = "";
|
|
1076
1128
|
let aggregatedToolCalls = [];
|
|
1077
1129
|
let finalFinishReason;
|
|
1130
|
+
let finalUsage;
|
|
1078
1131
|
try {
|
|
1079
1132
|
while (true) {
|
|
1080
1133
|
const { done, value } = await reader.read();
|
|
@@ -1092,6 +1145,19 @@ export class OllamaProvider extends BaseProvider {
|
|
|
1092
1145
|
}
|
|
1093
1146
|
try {
|
|
1094
1147
|
const parsed = JSON.parse(dataLine);
|
|
1148
|
+
// OpenAI-compatible usage chunk (Ollama may include usage
|
|
1149
|
+
// in the final chunk when stream_options.include_usage is set,
|
|
1150
|
+
// or as a standalone chunk with empty choices).
|
|
1151
|
+
const parsedUsage = parsed.usage;
|
|
1152
|
+
if (parsedUsage) {
|
|
1153
|
+
const input = parsedUsage.prompt_tokens ?? 0;
|
|
1154
|
+
const output = parsedUsage.completion_tokens ?? 0;
|
|
1155
|
+
finalUsage = {
|
|
1156
|
+
input,
|
|
1157
|
+
output,
|
|
1158
|
+
total: parsedUsage.total_tokens ?? input + output,
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1095
1161
|
const processed = this.processOllamaStreamData(parsed);
|
|
1096
1162
|
if (!processed) {
|
|
1097
1163
|
continue;
|
|
@@ -1129,6 +1195,7 @@ export class OllamaProvider extends BaseProvider {
|
|
|
1129
1195
|
content: aggregatedContent || undefined,
|
|
1130
1196
|
toolCalls: aggregatedToolCalls.length > 0 ? aggregatedToolCalls : undefined,
|
|
1131
1197
|
finishReason: finalFinishReason,
|
|
1198
|
+
usage: finalUsage,
|
|
1132
1199
|
};
|
|
1133
1200
|
}
|
|
1134
1201
|
/**
|
|
@@ -1413,6 +1480,18 @@ export class OllamaProvider extends BaseProvider {
|
|
|
1413
1480
|
});
|
|
1414
1481
|
}
|
|
1415
1482
|
}
|
|
1483
|
+
// Emit tool:end for each completed tool result so Pipeline B
|
|
1484
|
+
// captures telemetry for Ollama-driven tool calls (gap S2).
|
|
1485
|
+
emitToolEndFromStepFinish(this.neurolink?.getEventEmitter(), toolResultsForStorage.map((tr) => {
|
|
1486
|
+
const hasError = tr.result && typeof tr.result === "object" && "error" in tr.result;
|
|
1487
|
+
return {
|
|
1488
|
+
toolName: tr.toolName,
|
|
1489
|
+
result: tr.result,
|
|
1490
|
+
error: hasError
|
|
1491
|
+
? String(tr.result.error)
|
|
1492
|
+
: undefined,
|
|
1493
|
+
};
|
|
1494
|
+
}));
|
|
1416
1495
|
// Store tool executions (similar to Bedrock)
|
|
1417
1496
|
this.handleToolExecutionStorage(toolCallsForStorage, toolResultsForStorage, options, new Date()).catch((error) => {
|
|
1418
1497
|
logger.warn("[OllamaProvider] Failed to store tool executions", {
|
|
@@ -42,6 +42,8 @@ export declare class OpenAIProvider extends BaseProvider {
|
|
|
42
42
|
* Validate tool structure for OpenAI compatibility
|
|
43
43
|
* More lenient validation to avoid filtering out valid tools
|
|
44
44
|
*/
|
|
45
|
+
/** Shared helper: mark a stream span as ERROR, record the exception, and end it. */
|
|
46
|
+
private endStreamSpanWithError;
|
|
45
47
|
private isValidToolStructure;
|
|
46
48
|
/**
|
|
47
49
|
* Validate tool parameters for OpenAI compatibility
|
package/dist/providers/openAI.js
CHANGED
|
@@ -13,6 +13,7 @@ import { createOpenAIConfig, getProviderModel, validateApiKey, } from "../utils/
|
|
|
13
13
|
import { isZodSchema } from "../utils/schemaConversion.js";
|
|
14
14
|
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
|
|
15
15
|
import { resolveToolChoice } from "../utils/toolChoice.js";
|
|
16
|
+
import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
|
|
16
17
|
import { getModelId } from "./providerTypeUtils.js";
|
|
17
18
|
/**
|
|
18
19
|
* Retrieve a tool's schema, handling both AI SDK v6 (`inputSchema`) and
|
|
@@ -154,6 +155,17 @@ export class OpenAIProvider extends BaseProvider {
|
|
|
154
155
|
* Validate tool structure for OpenAI compatibility
|
|
155
156
|
* More lenient validation to avoid filtering out valid tools
|
|
156
157
|
*/
|
|
158
|
+
/** Shared helper: mark a stream span as ERROR, record the exception, and end it. */
|
|
159
|
+
endStreamSpanWithError(span, error) {
|
|
160
|
+
span.setStatus({
|
|
161
|
+
code: SpanStatusCode.ERROR,
|
|
162
|
+
message: error instanceof Error ? error.message : String(error),
|
|
163
|
+
});
|
|
164
|
+
if (error instanceof Error) {
|
|
165
|
+
span.recordException(error);
|
|
166
|
+
}
|
|
167
|
+
span.end();
|
|
168
|
+
}
|
|
157
169
|
isValidToolStructure(tool) {
|
|
158
170
|
if (!tool || typeof tool !== "object") {
|
|
159
171
|
return false;
|
|
@@ -337,6 +349,9 @@ export class OpenAIProvider extends BaseProvider {
|
|
|
337
349
|
toolResults,
|
|
338
350
|
toolCalls,
|
|
339
351
|
});
|
|
352
|
+
// Emit tool:end for each completed tool result so Pipeline B
|
|
353
|
+
// captures telemetry for AI-SDK-driven tool calls (gap S2).
|
|
354
|
+
emitToolEndFromStepFinish(this.neurolink?.getEventEmitter(), toolResults);
|
|
340
355
|
// Handle tool execution storage
|
|
341
356
|
this.handleToolExecutionStorage(toolCalls, toolResults, options, new Date()).catch((error) => {
|
|
342
357
|
logger.warn("[OpenAIProvider] Failed to store tool executions", {
|
|
@@ -348,7 +363,7 @@ export class OpenAIProvider extends BaseProvider {
|
|
|
348
363
|
});
|
|
349
364
|
}
|
|
350
365
|
catch (streamError) {
|
|
351
|
-
|
|
366
|
+
this.endStreamSpanWithError(streamSpan, streamError);
|
|
352
367
|
throw streamError;
|
|
353
368
|
}
|
|
354
369
|
// Collect token usage and finish reason asynchronously when the stream completes,
|
|
@@ -381,11 +396,7 @@ export class OpenAIProvider extends BaseProvider {
|
|
|
381
396
|
streamSpan.end();
|
|
382
397
|
})
|
|
383
398
|
.catch((err) => {
|
|
384
|
-
|
|
385
|
-
code: SpanStatusCode.ERROR,
|
|
386
|
-
message: err instanceof Error ? err.message : String(err),
|
|
387
|
-
});
|
|
388
|
-
streamSpan.end();
|
|
399
|
+
this.endStreamSpanWithError(streamSpan, err);
|
|
389
400
|
});
|
|
390
401
|
timeoutController?.cleanup();
|
|
391
402
|
// Debug the actual result structure
|
|
@@ -6,6 +6,7 @@ import { DEFAULT_MAX_STEPS } from "../core/constants.js";
|
|
|
6
6
|
import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
|
|
7
7
|
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
8
8
|
import { isAbortError } from "../utils/errorHandling.js";
|
|
9
|
+
import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
|
|
9
10
|
import { logger } from "../utils/logger.js";
|
|
10
11
|
import { getProviderModel } from "../utils/providerConfig.js";
|
|
11
12
|
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
|
|
@@ -273,6 +274,7 @@ export class OpenRouterProvider extends BaseProvider {
|
|
|
273
274
|
chunkCount++;
|
|
274
275
|
},
|
|
275
276
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
277
|
+
emitToolEndFromStepFinish(this.neurolink?.getEventEmitter(), toolResults);
|
|
276
278
|
logger.info("Tool execution completed", {
|
|
277
279
|
toolCallCount: toolCalls?.length || 0,
|
|
278
280
|
toolResultCount: toolResults?.length || 0,
|
|
@@ -4,6 +4,7 @@ import { BaseProvider } from "../core/baseProvider.js";
|
|
|
4
4
|
import { DEFAULT_MAX_STEPS } from "../core/constants.js";
|
|
5
5
|
import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
|
|
6
6
|
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
7
|
+
import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
|
|
7
8
|
import { logger } from "../utils/logger.js";
|
|
8
9
|
import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
|
|
9
10
|
import { resolveToolChoice } from "../utils/toolChoice.js";
|
|
@@ -197,6 +198,7 @@ export class OpenAICompatibleProvider extends BaseProvider {
|
|
|
197
198
|
experimental_telemetry: this.telemetryHandler.getTelemetryConfig(options),
|
|
198
199
|
experimental_repairToolCall: this.getToolCallRepairFn(options),
|
|
199
200
|
onStepFinish: (event) => {
|
|
201
|
+
emitToolEndFromStepFinish(this.neurolink?.getEventEmitter(), event.toolResults);
|
|
200
202
|
this.handleToolExecutionStorage([...event.toolCalls], [...event.toolResults], options, new Date()).catch((error) => {
|
|
201
203
|
logger.warn("[OpenAiCompatibleProvider] Failed to store tool executions", {
|
|
202
204
|
provider: this.providerName,
|
|
@@ -4,38 +4,7 @@
|
|
|
4
4
|
* This module provides intelligent detection of SageMaker endpoint capabilities
|
|
5
5
|
* including model type identification and streaming protocol support.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
/**
|
|
9
|
-
* Model type detection result
|
|
10
|
-
*/
|
|
11
|
-
type ModelDetectionResult = {
|
|
12
|
-
/** Primary model type */
|
|
13
|
-
type: StreamingCapability["modelType"];
|
|
14
|
-
/** Detection confidence (0-1) */
|
|
15
|
-
confidence: number;
|
|
16
|
-
/** Evidence used for detection */
|
|
17
|
-
evidence: string[];
|
|
18
|
-
/** Suggested configuration */
|
|
19
|
-
suggestedConfig?: Partial<SageMakerModelConfig>;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Endpoint health and metadata information
|
|
23
|
-
*/
|
|
24
|
-
type EndpointHealth = {
|
|
25
|
-
/** Health status */
|
|
26
|
-
status: "healthy" | "unhealthy" | "unknown";
|
|
27
|
-
/** Response time in milliseconds */
|
|
28
|
-
responseTime: number;
|
|
29
|
-
/** Endpoint metadata if available */
|
|
30
|
-
metadata?: Record<string, unknown>;
|
|
31
|
-
/** Model information if discoverable */
|
|
32
|
-
modelInfo?: {
|
|
33
|
-
name?: string;
|
|
34
|
-
version?: string;
|
|
35
|
-
framework?: string;
|
|
36
|
-
architecture?: string;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
7
|
+
import type { EndpointHealth, ModelDetectionResult, SageMakerConfig, StreamingCapability } from "../../types/index.js";
|
|
39
8
|
/**
|
|
40
9
|
* SageMaker Model Detection and Capability Discovery Service
|
|
41
10
|
*/
|
|
@@ -150,4 +119,3 @@ export declare class SageMakerDetector {
|
|
|
150
119
|
* Create a detector instance with configuration
|
|
151
120
|
*/
|
|
152
121
|
export declare function createSageMakerDetector(config: SageMakerConfig): SageMakerDetector;
|
|
153
|
-
export {};
|
|
@@ -3,30 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides basic diagnostic functions for SageMaker configuration and connectivity.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
* Simple diagnostic result interface
|
|
8
|
-
*/
|
|
9
|
-
type DiagnosticResult = {
|
|
10
|
-
name: string;
|
|
11
|
-
category: "configuration" | "connectivity" | "streaming";
|
|
12
|
-
status: "pass" | "fail" | "warning";
|
|
13
|
-
message: string;
|
|
14
|
-
details?: string;
|
|
15
|
-
recommendation?: string;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Diagnostic report interface
|
|
19
|
-
*/
|
|
20
|
-
type DiagnosticReport = {
|
|
21
|
-
overallStatus: "healthy" | "issues" | "critical";
|
|
22
|
-
results: DiagnosticResult[];
|
|
23
|
-
summary: {
|
|
24
|
-
total: number;
|
|
25
|
-
passed: number;
|
|
26
|
-
failed: number;
|
|
27
|
-
warnings: number;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
6
|
+
import type { DiagnosticReport } from "../../types/index.js";
|
|
30
7
|
/**
|
|
31
8
|
* Run quick diagnostics for SageMaker configuration
|
|
32
9
|
*/
|
|
@@ -35,4 +12,3 @@ export declare function runQuickDiagnostics(endpoint?: string): Promise<Diagnost
|
|
|
35
12
|
* Format diagnostic report for console output
|
|
36
13
|
*/
|
|
37
14
|
export declare function formatDiagnosticReport(report: DiagnosticReport): string;
|
|
38
|
-
export {};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This module implements the LanguageModel interface for Amazon SageMaker
|
|
5
5
|
* integration with the Vercel AI SDK.
|
|
6
6
|
*/
|
|
7
|
-
import type { SageMakerAsLanguageModel, SageMakerConfig, SageMakerModelConfig
|
|
7
|
+
import type { ConnectivityResult, SageMakerAsLanguageModel, SageMakerConfig, SageMakerModelConfig } from "../../types/index.js";
|
|
8
8
|
/**
|
|
9
9
|
* SageMaker Language Model implementing LanguageModel interface
|
|
10
10
|
*
|
|
@@ -136,6 +136,10 @@ function failOnUnresolvedAccountCredentials(obj) {
|
|
|
136
136
|
"Set the required environment variables or provide defaults with ${VAR:-default}.");
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// YAML parsing (dynamic import with fallback)
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
/** Shape of the dynamically-imported `js-yaml` module. */
|
|
139
143
|
/**
|
|
140
144
|
* Parse YAML content into a JS object.
|
|
141
145
|
* Uses `js-yaml` if available (dynamic import), otherwise falls back to
|
package/dist/proxy/proxyEnv.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
type
|
|
2
|
-
type ProxyEnvResolution = {
|
|
3
|
-
path?: string;
|
|
4
|
-
source: ProxyEnvSource;
|
|
5
|
-
required: boolean;
|
|
6
|
-
};
|
|
7
|
-
type ProxyEnvLoadResult = {
|
|
8
|
-
loaded: boolean;
|
|
9
|
-
path?: string;
|
|
10
|
-
source: ProxyEnvSource;
|
|
11
|
-
};
|
|
12
|
-
type ProxyEnvOptions = {
|
|
13
|
-
explicitEnvFile?: string;
|
|
14
|
-
env?: NodeJS.ProcessEnv;
|
|
15
|
-
homeDir?: string;
|
|
16
|
-
};
|
|
1
|
+
import type { ProxyEnvLoadResult, ProxyEnvOptions, ProxyEnvResolution } from "../types/index.js";
|
|
17
2
|
export declare function resolveProxyEnvFile(options?: ProxyEnvOptions): ProxyEnvResolution;
|
|
18
3
|
export declare function loadProxyEnvFile(options?: ProxyEnvOptions): Promise<ProxyEnvLoadResult>;
|
|
19
|
-
export {};
|