@juspay/neurolink 9.2.0 → 9.3.0
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 +21 -0
- package/README.md +52 -30
- package/dist/agent/directTools.d.ts +8 -8
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/rag.d.ts +19 -0
- package/dist/cli/commands/rag.js +756 -0
- package/dist/cli/factories/commandFactory.js +146 -83
- package/dist/cli/parser.js +4 -1
- package/dist/core/baseProvider.d.ts +43 -30
- package/dist/core/baseProvider.js +98 -138
- package/dist/core/conversationMemoryFactory.d.ts +2 -2
- package/dist/core/conversationMemoryFactory.js +2 -2
- package/dist/core/conversationMemoryInitializer.d.ts +1 -2
- package/dist/core/conversationMemoryInitializer.js +2 -2
- package/dist/core/infrastructure/baseError.d.ts +21 -0
- package/dist/core/infrastructure/baseError.js +22 -0
- package/dist/core/infrastructure/baseFactory.d.ts +21 -0
- package/dist/core/infrastructure/baseFactory.js +54 -0
- package/dist/core/infrastructure/baseRegistry.d.ts +21 -0
- package/dist/core/infrastructure/baseRegistry.js +49 -0
- package/dist/core/infrastructure/index.d.ts +5 -0
- package/dist/core/infrastructure/index.js +5 -0
- package/dist/core/infrastructure/retry.d.ts +7 -0
- package/dist/core/infrastructure/retry.js +20 -0
- package/dist/core/infrastructure/typedEventEmitter.d.ts +8 -0
- package/dist/core/infrastructure/typedEventEmitter.js +23 -0
- package/dist/core/redisConversationMemoryManager.d.ts +1 -6
- package/dist/core/redisConversationMemoryManager.js +7 -19
- package/dist/factories/providerFactory.d.ts +5 -3
- package/dist/factories/providerFactory.js +31 -24
- package/dist/index.d.ts +46 -12
- package/dist/index.js +88 -36
- package/dist/lib/agent/directTools.d.ts +5 -5
- package/dist/lib/core/baseProvider.d.ts +43 -30
- package/dist/lib/core/baseProvider.js +98 -138
- package/dist/lib/core/conversationMemoryFactory.d.ts +2 -2
- package/dist/lib/core/conversationMemoryFactory.js +2 -2
- package/dist/lib/core/conversationMemoryInitializer.d.ts +1 -2
- package/dist/lib/core/conversationMemoryInitializer.js +2 -2
- package/dist/lib/core/infrastructure/baseError.d.ts +21 -0
- package/dist/lib/core/infrastructure/baseError.js +23 -0
- package/dist/lib/core/infrastructure/baseFactory.d.ts +21 -0
- package/dist/lib/core/infrastructure/baseFactory.js +55 -0
- package/dist/lib/core/infrastructure/baseRegistry.d.ts +21 -0
- package/dist/lib/core/infrastructure/baseRegistry.js +50 -0
- package/dist/lib/core/infrastructure/index.d.ts +5 -0
- package/dist/lib/core/infrastructure/index.js +6 -0
- package/dist/lib/core/infrastructure/retry.d.ts +7 -0
- package/dist/lib/core/infrastructure/retry.js +21 -0
- package/dist/lib/core/infrastructure/typedEventEmitter.d.ts +8 -0
- package/dist/lib/core/infrastructure/typedEventEmitter.js +24 -0
- package/dist/lib/core/redisConversationMemoryManager.d.ts +1 -6
- package/dist/lib/core/redisConversationMemoryManager.js +7 -19
- package/dist/lib/factories/providerFactory.d.ts +5 -3
- package/dist/lib/factories/providerFactory.js +31 -24
- package/dist/lib/index.d.ts +46 -12
- package/dist/lib/index.js +88 -36
- package/dist/lib/mcp/index.d.ts +6 -5
- package/dist/lib/mcp/index.js +7 -5
- package/dist/lib/neurolink.d.ts +11 -13
- package/dist/lib/neurolink.js +95 -29
- package/dist/lib/providers/amazonBedrock.d.ts +15 -2
- package/dist/lib/providers/amazonBedrock.js +65 -8
- package/dist/lib/providers/anthropic.d.ts +3 -3
- package/dist/lib/providers/anthropic.js +10 -7
- package/dist/lib/providers/googleAiStudio.d.ts +5 -5
- package/dist/lib/providers/googleAiStudio.js +10 -7
- package/dist/lib/providers/googleVertex.d.ts +16 -4
- package/dist/lib/providers/googleVertex.js +72 -16
- package/dist/lib/providers/litellm.d.ts +3 -3
- package/dist/lib/providers/litellm.js +10 -10
- package/dist/lib/providers/mistral.d.ts +3 -3
- package/dist/lib/providers/mistral.js +7 -6
- package/dist/lib/providers/ollama.d.ts +3 -4
- package/dist/lib/providers/ollama.js +7 -8
- package/dist/lib/providers/openAI.d.ts +14 -2
- package/dist/lib/providers/openAI.js +60 -6
- package/dist/lib/providers/openRouter.d.ts +2 -2
- package/dist/lib/providers/openRouter.js +10 -6
- package/dist/lib/rag/ChunkerFactory.d.ts +91 -0
- package/dist/lib/rag/ChunkerFactory.js +321 -0
- package/dist/lib/rag/ChunkerRegistry.d.ts +91 -0
- package/dist/lib/rag/ChunkerRegistry.js +422 -0
- package/dist/lib/rag/chunkers/BaseChunker.d.ts +53 -0
- package/dist/lib/rag/chunkers/BaseChunker.js +144 -0
- package/dist/lib/rag/chunkers/CharacterChunker.d.ts +18 -0
- package/dist/lib/rag/chunkers/CharacterChunker.js +29 -0
- package/dist/lib/rag/chunkers/HTMLChunker.d.ts +19 -0
- package/dist/lib/rag/chunkers/HTMLChunker.js +39 -0
- package/dist/lib/rag/chunkers/JSONChunker.d.ts +19 -0
- package/dist/lib/rag/chunkers/JSONChunker.js +69 -0
- package/dist/lib/rag/chunkers/LaTeXChunker.d.ts +15 -0
- package/dist/lib/rag/chunkers/LaTeXChunker.js +64 -0
- package/dist/lib/rag/chunkers/MarkdownChunker.d.ts +15 -0
- package/dist/lib/rag/chunkers/MarkdownChunker.js +103 -0
- package/dist/lib/rag/chunkers/RecursiveChunker.d.ts +27 -0
- package/dist/lib/rag/chunkers/RecursiveChunker.js +140 -0
- package/dist/lib/rag/chunkers/SemanticMarkdownChunker.d.ts +22 -0
- package/dist/lib/rag/chunkers/SemanticMarkdownChunker.js +139 -0
- package/dist/lib/rag/chunkers/SentenceChunker.d.ts +19 -0
- package/dist/lib/rag/chunkers/SentenceChunker.js +67 -0
- package/dist/lib/rag/chunkers/TokenChunker.d.ts +19 -0
- package/dist/lib/rag/chunkers/TokenChunker.js +62 -0
- package/dist/lib/rag/chunkers/index.d.ts +15 -0
- package/dist/lib/rag/chunkers/index.js +16 -0
- package/dist/lib/rag/chunking/characterChunker.d.ts +16 -0
- package/dist/lib/rag/chunking/characterChunker.js +143 -0
- package/dist/lib/rag/chunking/chunkerRegistry.d.ts +67 -0
- package/dist/lib/rag/chunking/chunkerRegistry.js +195 -0
- package/dist/lib/rag/chunking/htmlChunker.d.ts +34 -0
- package/dist/lib/rag/chunking/htmlChunker.js +248 -0
- package/dist/lib/rag/chunking/index.d.ts +15 -0
- package/dist/lib/rag/chunking/index.js +18 -0
- package/dist/lib/rag/chunking/jsonChunker.d.ts +20 -0
- package/dist/lib/rag/chunking/jsonChunker.js +282 -0
- package/dist/lib/rag/chunking/latexChunker.d.ts +26 -0
- package/dist/lib/rag/chunking/latexChunker.js +252 -0
- package/dist/lib/rag/chunking/markdownChunker.d.ts +19 -0
- package/dist/lib/rag/chunking/markdownChunker.js +202 -0
- package/dist/lib/rag/chunking/recursiveChunker.d.ts +19 -0
- package/dist/lib/rag/chunking/recursiveChunker.js +149 -0
- package/dist/lib/rag/chunking/semanticChunker.d.ts +41 -0
- package/dist/lib/rag/chunking/semanticChunker.js +307 -0
- package/dist/lib/rag/chunking/sentenceChunker.d.ts +25 -0
- package/dist/lib/rag/chunking/sentenceChunker.js +231 -0
- package/dist/lib/rag/chunking/tokenChunker.d.ts +36 -0
- package/dist/lib/rag/chunking/tokenChunker.js +184 -0
- package/dist/lib/rag/document/MDocument.d.ts +198 -0
- package/dist/lib/rag/document/MDocument.js +393 -0
- package/dist/lib/rag/document/index.d.ts +5 -0
- package/dist/lib/rag/document/index.js +6 -0
- package/dist/lib/rag/document/loaders.d.ts +201 -0
- package/dist/lib/rag/document/loaders.js +501 -0
- package/dist/lib/rag/errors/RAGError.d.ts +244 -0
- package/dist/lib/rag/errors/RAGError.js +275 -0
- package/dist/lib/rag/errors/index.d.ts +6 -0
- package/dist/lib/rag/errors/index.js +7 -0
- package/dist/lib/rag/graphRag/graphRAG.d.ts +115 -0
- package/dist/lib/rag/graphRag/graphRAG.js +385 -0
- package/dist/lib/rag/graphRag/index.d.ts +4 -0
- package/dist/lib/rag/graphRag/index.js +5 -0
- package/dist/lib/rag/index.d.ts +103 -0
- package/dist/lib/rag/index.js +142 -0
- package/dist/lib/rag/metadata/MetadataExtractorFactory.d.ts +157 -0
- package/dist/lib/rag/metadata/MetadataExtractorFactory.js +419 -0
- package/dist/lib/rag/metadata/MetadataExtractorRegistry.d.ts +99 -0
- package/dist/lib/rag/metadata/MetadataExtractorRegistry.js +363 -0
- package/dist/lib/rag/metadata/index.d.ts +6 -0
- package/dist/lib/rag/metadata/index.js +10 -0
- package/dist/lib/rag/metadata/metadataExtractor.d.ts +69 -0
- package/dist/lib/rag/metadata/metadataExtractor.js +278 -0
- package/dist/lib/rag/pipeline/RAGPipeline.d.ts +235 -0
- package/dist/lib/rag/pipeline/RAGPipeline.js +402 -0
- package/dist/lib/rag/pipeline/contextAssembly.d.ts +126 -0
- package/dist/lib/rag/pipeline/contextAssembly.js +338 -0
- package/dist/lib/rag/pipeline/index.d.ts +5 -0
- package/dist/lib/rag/pipeline/index.js +6 -0
- package/dist/lib/rag/ragIntegration.d.ts +38 -0
- package/dist/lib/rag/ragIntegration.js +212 -0
- package/dist/lib/rag/reranker/RerankerFactory.d.ts +184 -0
- package/dist/lib/rag/reranker/RerankerFactory.js +431 -0
- package/dist/lib/rag/reranker/RerankerRegistry.d.ts +119 -0
- package/dist/lib/rag/reranker/RerankerRegistry.js +403 -0
- package/dist/lib/rag/reranker/index.d.ts +6 -0
- package/dist/lib/rag/reranker/index.js +10 -0
- package/dist/lib/rag/reranker/reranker.d.ts +71 -0
- package/dist/lib/rag/reranker/reranker.js +278 -0
- package/dist/lib/rag/resilience/CircuitBreaker.d.ts +215 -0
- package/dist/lib/rag/resilience/CircuitBreaker.js +432 -0
- package/dist/lib/rag/resilience/RetryHandler.d.ts +115 -0
- package/dist/lib/rag/resilience/RetryHandler.js +301 -0
- package/dist/lib/rag/resilience/index.d.ts +7 -0
- package/dist/lib/rag/resilience/index.js +8 -0
- package/dist/lib/rag/retrieval/hybridSearch.d.ts +94 -0
- package/dist/lib/rag/retrieval/hybridSearch.js +314 -0
- package/dist/lib/rag/retrieval/index.d.ts +5 -0
- package/dist/lib/rag/retrieval/index.js +6 -0
- package/dist/lib/rag/retrieval/vectorQueryTool.d.ts +93 -0
- package/dist/lib/rag/retrieval/vectorQueryTool.js +290 -0
- package/dist/lib/rag/types.d.ts +768 -0
- package/dist/lib/rag/types.js +9 -0
- package/dist/lib/server/index.d.ts +15 -11
- package/dist/lib/server/index.js +55 -51
- package/dist/lib/server/utils/validation.d.ts +8 -8
- package/dist/lib/types/common.d.ts +0 -1
- package/dist/lib/types/generateTypes.d.ts +42 -8
- package/dist/lib/types/generateTypes.js +1 -1
- package/dist/lib/types/modelTypes.d.ts +2 -2
- package/dist/lib/types/streamTypes.d.ts +28 -8
- package/dist/lib/types/streamTypes.js +1 -1
- package/dist/lib/utils/modelRouter.d.ts +4 -4
- package/dist/lib/utils/modelRouter.js +4 -4
- package/dist/mcp/index.d.ts +6 -5
- package/dist/mcp/index.js +7 -5
- package/dist/neurolink.d.ts +11 -13
- package/dist/neurolink.js +95 -29
- package/dist/providers/amazonBedrock.d.ts +15 -2
- package/dist/providers/amazonBedrock.js +65 -8
- package/dist/providers/anthropic.d.ts +3 -3
- package/dist/providers/anthropic.js +10 -7
- package/dist/providers/googleAiStudio.d.ts +5 -5
- package/dist/providers/googleAiStudio.js +10 -7
- package/dist/providers/googleVertex.d.ts +16 -4
- package/dist/providers/googleVertex.js +72 -16
- package/dist/providers/litellm.d.ts +3 -3
- package/dist/providers/litellm.js +10 -10
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/mistral.js +7 -6
- package/dist/providers/ollama.d.ts +3 -4
- package/dist/providers/ollama.js +7 -8
- package/dist/providers/openAI.d.ts +14 -2
- package/dist/providers/openAI.js +60 -6
- package/dist/providers/openRouter.d.ts +2 -2
- package/dist/providers/openRouter.js +10 -6
- package/dist/rag/ChunkerFactory.d.ts +91 -0
- package/dist/rag/ChunkerFactory.js +320 -0
- package/dist/rag/ChunkerRegistry.d.ts +91 -0
- package/dist/rag/ChunkerRegistry.js +421 -0
- package/dist/rag/chunkers/BaseChunker.d.ts +53 -0
- package/dist/rag/chunkers/BaseChunker.js +143 -0
- package/dist/rag/chunkers/CharacterChunker.d.ts +18 -0
- package/dist/rag/chunkers/CharacterChunker.js +28 -0
- package/dist/rag/chunkers/HTMLChunker.d.ts +19 -0
- package/dist/rag/chunkers/HTMLChunker.js +38 -0
- package/dist/rag/chunkers/JSONChunker.d.ts +19 -0
- package/dist/rag/chunkers/JSONChunker.js +68 -0
- package/dist/rag/chunkers/LaTeXChunker.d.ts +15 -0
- package/dist/rag/chunkers/LaTeXChunker.js +63 -0
- package/dist/rag/chunkers/MarkdownChunker.d.ts +15 -0
- package/dist/rag/chunkers/MarkdownChunker.js +102 -0
- package/dist/rag/chunkers/RecursiveChunker.d.ts +27 -0
- package/dist/rag/chunkers/RecursiveChunker.js +139 -0
- package/dist/rag/chunkers/SemanticMarkdownChunker.d.ts +22 -0
- package/dist/rag/chunkers/SemanticMarkdownChunker.js +138 -0
- package/dist/rag/chunkers/SentenceChunker.d.ts +19 -0
- package/dist/rag/chunkers/SentenceChunker.js +66 -0
- package/dist/rag/chunkers/TokenChunker.d.ts +19 -0
- package/dist/rag/chunkers/TokenChunker.js +61 -0
- package/dist/rag/chunkers/index.d.ts +15 -0
- package/dist/rag/chunkers/index.js +15 -0
- package/dist/rag/chunking/characterChunker.d.ts +16 -0
- package/dist/rag/chunking/characterChunker.js +142 -0
- package/dist/rag/chunking/chunkerRegistry.d.ts +67 -0
- package/dist/rag/chunking/chunkerRegistry.js +194 -0
- package/dist/rag/chunking/htmlChunker.d.ts +34 -0
- package/dist/rag/chunking/htmlChunker.js +247 -0
- package/dist/rag/chunking/index.d.ts +15 -0
- package/dist/rag/chunking/index.js +17 -0
- package/dist/rag/chunking/jsonChunker.d.ts +20 -0
- package/dist/rag/chunking/jsonChunker.js +281 -0
- package/dist/rag/chunking/latexChunker.d.ts +26 -0
- package/dist/rag/chunking/latexChunker.js +251 -0
- package/dist/rag/chunking/markdownChunker.d.ts +19 -0
- package/dist/rag/chunking/markdownChunker.js +201 -0
- package/dist/rag/chunking/recursiveChunker.d.ts +19 -0
- package/dist/rag/chunking/recursiveChunker.js +148 -0
- package/dist/rag/chunking/semanticChunker.d.ts +41 -0
- package/dist/rag/chunking/semanticChunker.js +306 -0
- package/dist/rag/chunking/sentenceChunker.d.ts +25 -0
- package/dist/rag/chunking/sentenceChunker.js +230 -0
- package/dist/rag/chunking/tokenChunker.d.ts +36 -0
- package/dist/rag/chunking/tokenChunker.js +183 -0
- package/dist/rag/document/MDocument.d.ts +198 -0
- package/dist/rag/document/MDocument.js +392 -0
- package/dist/rag/document/index.d.ts +5 -0
- package/dist/rag/document/index.js +5 -0
- package/dist/rag/document/loaders.d.ts +201 -0
- package/dist/rag/document/loaders.js +500 -0
- package/dist/rag/errors/RAGError.d.ts +244 -0
- package/dist/rag/errors/RAGError.js +274 -0
- package/dist/rag/errors/index.d.ts +6 -0
- package/dist/rag/errors/index.js +6 -0
- package/dist/rag/graphRag/graphRAG.d.ts +115 -0
- package/dist/rag/graphRag/graphRAG.js +384 -0
- package/dist/rag/graphRag/index.d.ts +4 -0
- package/dist/rag/graphRag/index.js +4 -0
- package/dist/rag/index.d.ts +103 -0
- package/dist/rag/index.js +141 -0
- package/dist/rag/metadata/MetadataExtractorFactory.d.ts +157 -0
- package/dist/rag/metadata/MetadataExtractorFactory.js +418 -0
- package/dist/rag/metadata/MetadataExtractorRegistry.d.ts +99 -0
- package/dist/rag/metadata/MetadataExtractorRegistry.js +362 -0
- package/dist/rag/metadata/index.d.ts +6 -0
- package/dist/rag/metadata/index.js +9 -0
- package/dist/rag/metadata/metadataExtractor.d.ts +69 -0
- package/dist/rag/metadata/metadataExtractor.js +277 -0
- package/dist/rag/pipeline/RAGPipeline.d.ts +235 -0
- package/dist/rag/pipeline/RAGPipeline.js +401 -0
- package/dist/rag/pipeline/contextAssembly.d.ts +126 -0
- package/dist/rag/pipeline/contextAssembly.js +337 -0
- package/dist/rag/pipeline/index.d.ts +5 -0
- package/dist/rag/pipeline/index.js +5 -0
- package/dist/rag/ragIntegration.d.ts +38 -0
- package/dist/rag/ragIntegration.js +211 -0
- package/dist/rag/reranker/RerankerFactory.d.ts +184 -0
- package/dist/rag/reranker/RerankerFactory.js +430 -0
- package/dist/rag/reranker/RerankerRegistry.d.ts +119 -0
- package/dist/rag/reranker/RerankerRegistry.js +402 -0
- package/dist/rag/reranker/index.d.ts +6 -0
- package/dist/rag/reranker/index.js +9 -0
- package/dist/rag/reranker/reranker.d.ts +71 -0
- package/dist/rag/reranker/reranker.js +277 -0
- package/dist/rag/resilience/CircuitBreaker.d.ts +215 -0
- package/dist/rag/resilience/CircuitBreaker.js +431 -0
- package/dist/rag/resilience/RetryHandler.d.ts +115 -0
- package/dist/rag/resilience/RetryHandler.js +300 -0
- package/dist/rag/resilience/index.d.ts +7 -0
- package/dist/rag/resilience/index.js +7 -0
- package/dist/rag/retrieval/hybridSearch.d.ts +94 -0
- package/dist/rag/retrieval/hybridSearch.js +313 -0
- package/dist/rag/retrieval/index.d.ts +5 -0
- package/dist/rag/retrieval/index.js +5 -0
- package/dist/rag/retrieval/vectorQueryTool.d.ts +93 -0
- package/dist/rag/retrieval/vectorQueryTool.js +289 -0
- package/dist/rag/types.d.ts +768 -0
- package/dist/rag/types.js +8 -0
- package/dist/server/index.d.ts +15 -11
- package/dist/server/index.js +55 -51
- package/dist/server/utils/validation.d.ts +2 -2
- package/dist/types/common.d.ts +0 -1
- package/dist/types/generateTypes.d.ts +42 -8
- package/dist/types/generateTypes.js +1 -1
- package/dist/types/modelTypes.d.ts +20 -20
- package/dist/types/streamTypes.d.ts +28 -8
- package/dist/types/streamTypes.js +1 -1
- package/dist/utils/modelRouter.d.ts +4 -4
- package/dist/utils/modelRouter.js +4 -4
- package/package.json +1 -1
package/dist/neurolink.js
CHANGED
|
@@ -13,39 +13,35 @@ try {
|
|
|
13
13
|
catch {
|
|
14
14
|
// Environment variables should be set externally in production
|
|
15
15
|
}
|
|
16
|
-
import {
|
|
17
|
-
import { isNonNullObject } from "./utils/typeUtils.js";
|
|
18
|
-
import { isZodSchema } from "./utils/schemaConversion.js";
|
|
19
|
-
import { AIProviderName } from "./constants/enums.js";
|
|
20
|
-
import { mcpLogger } from "./utils/logger.js";
|
|
21
|
-
import { SYSTEM_LIMITS } from "./core/constants.js";
|
|
22
|
-
import { NANOSECOND_TO_MS_DIVISOR, TOOL_TIMEOUTS, RETRY_ATTEMPTS, RETRY_DELAYS, CIRCUIT_BREAKER, CIRCUIT_BREAKER_RESET_MS, MEMORY_THRESHOLDS, PROVIDER_TIMEOUTS, PERFORMANCE_THRESHOLDS, } from "./constants/index.js";
|
|
16
|
+
import { EventEmitter } from "events";
|
|
23
17
|
import pLimit from "p-limit";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
18
|
+
import { CIRCUIT_BREAKER, CIRCUIT_BREAKER_RESET_MS, MEMORY_THRESHOLDS, NANOSECOND_TO_MS_DIVISOR, PERFORMANCE_THRESHOLDS, PROVIDER_TIMEOUTS, RETRY_ATTEMPTS, RETRY_DELAYS, TOOL_TIMEOUTS, } from "./constants/index.js";
|
|
19
|
+
import { SYSTEM_LIMITS } from "./core/constants.js";
|
|
20
|
+
import { AIProviderFactory } from "./core/factory.js";
|
|
27
21
|
import { ProviderRegistry } from "./factories/providerRegistry.js";
|
|
28
|
-
import { createCustomToolServerInfo, detectCategory, } from "./utils/mcpDefaults.js";
|
|
29
|
-
// Factory processing imports
|
|
30
|
-
import { processFactoryOptions, enhanceTextGenerationOptions, validateFactoryConfig, processStreamingFactoryOptions, createCleanStreamOptions, } from "./utils/factoryProcessing.js";
|
|
31
|
-
// Tool detection and execution imports
|
|
32
|
-
// Transformation utilities
|
|
33
|
-
import { transformToolExecutions, transformToolExecutionsForMCP, transformAvailableTools, transformToolsForMCP, transformToolsToExpectedFormat, transformToolsToDescriptions, extractToolNames, transformParamsForLogging, optimizeToolForCollection, } from "./utils/transformationUtils.js";
|
|
34
|
-
// Enhanced error handling imports
|
|
35
|
-
import { ErrorFactory, NeuroLinkError, withTimeout, withRetry, isRetriableError, logStructuredError, CircuitBreaker, } from "./utils/errorHandling.js";
|
|
36
|
-
import { EventEmitter } from "events";
|
|
37
|
-
import { ConversationMemoryManager } from "./core/conversationMemoryManager.js";
|
|
38
|
-
import { RedisConversationMemoryManager } from "./core/redisConversationMemoryManager.js";
|
|
39
|
-
import { getConversationMessages, storeConversationTurn, } from "./utils/conversationMemory.js";
|
|
40
|
-
import { ExternalServerManager } from "./mcp/externalServerManager.js";
|
|
41
22
|
import { HITLManager } from "./hitl/hitlManager.js";
|
|
23
|
+
import { ExternalServerManager } from "./mcp/externalServerManager.js";
|
|
42
24
|
// Import direct tools server for automatic registration
|
|
43
25
|
import { directToolsServer } from "./mcp/servers/agent/directToolsServer.js";
|
|
26
|
+
import { MCPToolRegistry } from "./mcp/toolRegistry.js";
|
|
27
|
+
import { initializeMem0 } from "./memory/mem0Initializer.js";
|
|
28
|
+
import { flushOpenTelemetry, getLangfuseHealthStatus, initializeOpenTelemetry, isOpenTelemetryInitialized, setLangfuseContext, shutdownOpenTelemetry, } from "./services/server/ai/observability/instrumentation.js";
|
|
29
|
+
import { getConversationMessages, storeConversationTurn, } from "./utils/conversationMemory.js";
|
|
30
|
+
// Enhanced error handling imports
|
|
31
|
+
import { CircuitBreaker, ErrorFactory, isRetriableError, logStructuredError, NeuroLinkError, withRetry, withTimeout, } from "./utils/errorHandling.js";
|
|
32
|
+
// Factory processing imports
|
|
33
|
+
import { createCleanStreamOptions, enhanceTextGenerationOptions, processFactoryOptions, processStreamingFactoryOptions, validateFactoryConfig, } from "./utils/factoryProcessing.js";
|
|
34
|
+
import { logger, mcpLogger } from "./utils/logger.js";
|
|
35
|
+
import { createCustomToolServerInfo, detectCategory, } from "./utils/mcpDefaults.js";
|
|
44
36
|
// Import orchestration components
|
|
45
37
|
import { ModelRouter } from "./utils/modelRouter.js";
|
|
38
|
+
import { getBestProvider } from "./utils/providerUtils.js";
|
|
39
|
+
import { isZodSchema } from "./utils/schemaConversion.js";
|
|
46
40
|
import { BinaryTaskClassifier } from "./utils/taskClassifier.js";
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
// Tool detection and execution imports
|
|
42
|
+
// Transformation utilities
|
|
43
|
+
import { extractToolNames, optimizeToolForCollection, transformAvailableTools, transformParamsForLogging, transformToolExecutions, transformToolExecutionsForMCP, transformToolsForMCP, transformToolsToDescriptions, transformToolsToExpectedFormat, } from "./utils/transformationUtils.js";
|
|
44
|
+
import { isNonNullObject } from "./utils/typeUtils.js";
|
|
49
45
|
/**
|
|
50
46
|
* NeuroLink - Universal AI Development Platform
|
|
51
47
|
*
|
|
@@ -1449,6 +1445,39 @@ Current user's request: ${currentInput}`;
|
|
|
1449
1445
|
// Continue with warning rather than throwing - graceful degradation
|
|
1450
1446
|
}
|
|
1451
1447
|
}
|
|
1448
|
+
// RAG Integration: If rag config is provided, prepare the RAG search tool
|
|
1449
|
+
if (options.rag?.files?.length) {
|
|
1450
|
+
try {
|
|
1451
|
+
const { prepareRAGTool } = await import("./rag/ragIntegration.js");
|
|
1452
|
+
const ragResult = await prepareRAGTool(options.rag, options.provider);
|
|
1453
|
+
// Inject the RAG tool into the tools record
|
|
1454
|
+
if (!options.tools) {
|
|
1455
|
+
options.tools = {};
|
|
1456
|
+
}
|
|
1457
|
+
options.tools[ragResult.toolName] =
|
|
1458
|
+
ragResult.tool;
|
|
1459
|
+
// Inject RAG-aware system prompt so the AI uses the RAG tool first
|
|
1460
|
+
const ragSystemInstruction = [
|
|
1461
|
+
`\n\nIMPORTANT: You have a tool called "${ragResult.toolName}" that searches through`,
|
|
1462
|
+
`${ragResult.filesLoaded} loaded document(s) containing ${ragResult.chunksIndexed} indexed chunks.`,
|
|
1463
|
+
`ALWAYS use the "${ragResult.toolName}" tool FIRST to answer the user's question before using any other tools.`,
|
|
1464
|
+
`This tool searches your local knowledge base of pre-loaded documents and is the primary source of truth.`,
|
|
1465
|
+
`Do NOT use websearchGrounding or any web search tools when the answer can be found in the loaded documents.`,
|
|
1466
|
+
].join(" ");
|
|
1467
|
+
options.systemPrompt =
|
|
1468
|
+
(options.systemPrompt || "") + ragSystemInstruction;
|
|
1469
|
+
logger.info("[RAG] Tool injected into generate()", {
|
|
1470
|
+
toolName: ragResult.toolName,
|
|
1471
|
+
filesLoaded: ragResult.filesLoaded,
|
|
1472
|
+
chunksIndexed: ragResult.chunksIndexed,
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
catch (error) {
|
|
1476
|
+
logger.warn("[RAG] Failed to prepare RAG tool, continuing without RAG", {
|
|
1477
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1452
1481
|
// 🔧 CRITICAL FIX: Convert to TextGenerationOptions while preserving the input object for multimodal support
|
|
1453
1482
|
const baseOptions = {
|
|
1454
1483
|
prompt: options.input.text,
|
|
@@ -1459,6 +1488,7 @@ Current user's request: ${currentInput}`;
|
|
|
1459
1488
|
systemPrompt: options.systemPrompt,
|
|
1460
1489
|
schema: options.schema,
|
|
1461
1490
|
output: options.output,
|
|
1491
|
+
tools: options.tools, // Includes RAG tools if rag config was provided
|
|
1462
1492
|
disableTools: options.disableTools,
|
|
1463
1493
|
enableAnalytics: options.enableAnalytics,
|
|
1464
1494
|
enableEvaluation: options.enableEvaluation,
|
|
@@ -2184,6 +2214,39 @@ Current user's request: ${currentInput}`;
|
|
|
2184
2214
|
}
|
|
2185
2215
|
}
|
|
2186
2216
|
}
|
|
2217
|
+
// RAG Integration: If rag config is provided, prepare the RAG search tool (stream)
|
|
2218
|
+
if (options.rag?.files?.length) {
|
|
2219
|
+
try {
|
|
2220
|
+
const { prepareRAGTool } = await import("./rag/ragIntegration.js");
|
|
2221
|
+
const ragResult = await prepareRAGTool(options.rag, options.provider);
|
|
2222
|
+
// Inject the RAG tool into the tools record
|
|
2223
|
+
if (!options.tools) {
|
|
2224
|
+
options.tools = {};
|
|
2225
|
+
}
|
|
2226
|
+
options.tools[ragResult.toolName] =
|
|
2227
|
+
ragResult.tool;
|
|
2228
|
+
// Inject RAG-aware system prompt so the AI uses the RAG tool first
|
|
2229
|
+
const ragStreamInstruction = [
|
|
2230
|
+
`\n\nIMPORTANT: You have a tool called "${ragResult.toolName}" that searches through`,
|
|
2231
|
+
`${ragResult.filesLoaded} loaded document(s) containing ${ragResult.chunksIndexed} indexed chunks.`,
|
|
2232
|
+
`ALWAYS use the "${ragResult.toolName}" tool FIRST to answer the user's question before using any other tools.`,
|
|
2233
|
+
`This tool searches your local knowledge base of pre-loaded documents and is the primary source of truth.`,
|
|
2234
|
+
`Do NOT use websearchGrounding or any web search tools when the answer can be found in the loaded documents.`,
|
|
2235
|
+
].join(" ");
|
|
2236
|
+
options.systemPrompt =
|
|
2237
|
+
(options.systemPrompt || "") + ragStreamInstruction;
|
|
2238
|
+
logger.info("[RAG] Tool injected into stream()", {
|
|
2239
|
+
toolName: ragResult.toolName,
|
|
2240
|
+
filesLoaded: ragResult.filesLoaded,
|
|
2241
|
+
chunksIndexed: ragResult.chunksIndexed,
|
|
2242
|
+
});
|
|
2243
|
+
}
|
|
2244
|
+
catch (error) {
|
|
2245
|
+
logger.warn("[RAG] Failed to prepare RAG tool, continuing without RAG", {
|
|
2246
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2187
2250
|
factoryResult = processStreamingFactoryOptions(options);
|
|
2188
2251
|
enhancedOptions = createCleanStreamOptions(options);
|
|
2189
2252
|
if (options.input?.text) {
|
|
@@ -2330,7 +2393,7 @@ Current user's request: ${currentInput}`;
|
|
|
2330
2393
|
if (self.conversationMemory && enhancedOptions.context?.sessionId) {
|
|
2331
2394
|
const sessionId = enhancedOptions.context?.sessionId;
|
|
2332
2395
|
const userId = enhancedOptions.context?.userId;
|
|
2333
|
-
let providerDetails
|
|
2396
|
+
let providerDetails;
|
|
2334
2397
|
if (enhancedOptions.model) {
|
|
2335
2398
|
providerDetails = {
|
|
2336
2399
|
provider: providerName,
|
|
@@ -2557,7 +2620,7 @@ Current user's request: ${currentInput}`;
|
|
|
2557
2620
|
const sessionId = enhancedOptions?.context?.sessionId;
|
|
2558
2621
|
const userId = enhancedOptions?.context
|
|
2559
2622
|
?.userId;
|
|
2560
|
-
let providerDetails
|
|
2623
|
+
let providerDetails;
|
|
2561
2624
|
if (options.model) {
|
|
2562
2625
|
providerDetails = {
|
|
2563
2626
|
provider: providerName,
|
|
@@ -3907,7 +3970,10 @@ Current user's request: ${currentInput}`;
|
|
|
3907
3970
|
async hasProviderEnvVars(providerName) {
|
|
3908
3971
|
const { ProviderHealthChecker } = await import("./utils/providerHealth.js");
|
|
3909
3972
|
try {
|
|
3910
|
-
const health = await ProviderHealthChecker.checkProviderHealth(providerName, {
|
|
3973
|
+
const health = await ProviderHealthChecker.checkProviderHealth(providerName, {
|
|
3974
|
+
includeConnectivityTest: false,
|
|
3975
|
+
cacheResults: false,
|
|
3976
|
+
});
|
|
3911
3977
|
return health.isConfigured && health.hasApiKey;
|
|
3912
3978
|
}
|
|
3913
3979
|
catch (error) {
|
|
@@ -4511,7 +4577,7 @@ Current user's request: ${currentInput}`;
|
|
|
4511
4577
|
// Import the integration module
|
|
4512
4578
|
const { initializeConversationMemory } = await import("./core/conversationMemoryInitializer.js");
|
|
4513
4579
|
// Use the integration module to create the appropriate memory manager
|
|
4514
|
-
const memoryManager = await initializeConversationMemory(this.conversationMemoryConfig
|
|
4580
|
+
const memoryManager = await initializeConversationMemory(this.conversationMemoryConfig);
|
|
4515
4581
|
// Assign to conversationMemory with proper type to handle both memory manager types
|
|
4516
4582
|
this.conversationMemory = memoryManager;
|
|
4517
4583
|
// Reset the lazy init flag since we've now initialized
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
|
|
2
|
+
import type { AIProviderName } from "../constants/enums.js";
|
|
2
3
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
4
|
+
import type { NeuroLink } from "../neurolink.js";
|
|
3
5
|
import type { EnhancedGenerateResult, TextGenerationOptions } from "../types/index.js";
|
|
4
|
-
import { AIProviderName } from "../constants/enums.js";
|
|
5
6
|
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
6
|
-
import type { NeuroLink } from "../neurolink.js";
|
|
7
7
|
export declare class AmazonBedrockProvider extends BaseProvider {
|
|
8
8
|
private bedrockClient;
|
|
9
9
|
private conversationHistory;
|
|
@@ -17,6 +17,11 @@ export declare class AmazonBedrockProvider extends BaseProvider {
|
|
|
17
17
|
getAISDKModel(): never;
|
|
18
18
|
getProviderName(): AIProviderName;
|
|
19
19
|
getDefaultModel(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Get the default embedding model for Amazon Bedrock
|
|
22
|
+
* @returns The default Bedrock embedding model name
|
|
23
|
+
*/
|
|
24
|
+
protected getDefaultEmbeddingModel(): string;
|
|
20
25
|
generate(optionsOrPrompt: TextGenerationOptions | string): Promise<EnhancedGenerateResult | null>;
|
|
21
26
|
private conversationLoop;
|
|
22
27
|
private callBedrock;
|
|
@@ -40,4 +45,12 @@ export declare class AmazonBedrockProvider extends BaseProvider {
|
|
|
40
45
|
*/
|
|
41
46
|
checkBedrockHealth(): Promise<void>;
|
|
42
47
|
handleProviderError(error: unknown): Error;
|
|
48
|
+
/**
|
|
49
|
+
* Generate embeddings for text using Amazon Bedrock embedding models
|
|
50
|
+
* Uses the native AWS SDK InvokeModel command for Titan embeddings
|
|
51
|
+
* @param text - The text to embed
|
|
52
|
+
* @param modelName - The embedding model to use (default: amazon.titan-embed-text-v2:0)
|
|
53
|
+
* @returns Promise resolving to the embedding vector
|
|
54
|
+
*/
|
|
55
|
+
embed(text: string, modelName?: string): Promise<number[]>;
|
|
43
56
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, ImageFormat, } from "@aws-sdk/client-bedrock-runtime";
|
|
2
1
|
import { BedrockClient, ListFoundationModelsCommand, } from "@aws-sdk/client-bedrock";
|
|
2
|
+
import { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, ImageFormat, } from "@aws-sdk/client-bedrock-runtime";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { createAnalytics } from "../core/analytics.js";
|
|
3
5
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
4
|
-
import {
|
|
6
|
+
import { DEFAULT_MAX_STEPS } from "../core/constants.js";
|
|
5
7
|
import { logger } from "../utils/logger.js";
|
|
6
|
-
import { convertZodToJsonSchema } from "../utils/schemaConversion.js";
|
|
7
8
|
import { buildMultimodalMessagesArray } from "../utils/messageBuilder.js";
|
|
8
9
|
import { buildMultimodalOptions } from "../utils/multimodalOptionsBuilder.js";
|
|
9
|
-
import {
|
|
10
|
-
import { createAnalytics } from "../core/analytics.js";
|
|
11
|
-
import path from "path";
|
|
10
|
+
import { convertZodToJsonSchema } from "../utils/schemaConversion.js";
|
|
12
11
|
// Bedrock-specific types now imported from ../types/providerSpecific.js
|
|
13
12
|
export class AmazonBedrockProvider extends BaseProvider {
|
|
14
13
|
bedrockClient;
|
|
@@ -88,6 +87,15 @@ export class AmazonBedrockProvider extends BaseProvider {
|
|
|
88
87
|
getDefaultModel() {
|
|
89
88
|
return (process.env.BEDROCK_MODEL || "anthropic.claude-3-sonnet-20240229-v1:0");
|
|
90
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the default embedding model for Amazon Bedrock
|
|
92
|
+
* @returns The default Bedrock embedding model name
|
|
93
|
+
*/
|
|
94
|
+
getDefaultEmbeddingModel() {
|
|
95
|
+
return (process.env.BEDROCK_EMBEDDING_MODEL ||
|
|
96
|
+
process.env.AWS_EMBEDDING_MODEL ||
|
|
97
|
+
"amazon.titan-embed-text-v2:0");
|
|
98
|
+
}
|
|
91
99
|
// Override the main generate method to implement conversation management
|
|
92
100
|
async generate(optionsOrPrompt) {
|
|
93
101
|
logger.debug("[AmazonBedrockProvider] generate() called with conversation management");
|
|
@@ -158,7 +166,6 @@ export class AmazonBedrockProvider extends BaseProvider {
|
|
|
158
166
|
logger.debug(`[AmazonBedrockProvider] Handle response result:`, result);
|
|
159
167
|
if (result.shouldContinue) {
|
|
160
168
|
logger.debug(`[AmazonBedrockProvider] Continuing conversation loop...`);
|
|
161
|
-
continue;
|
|
162
169
|
}
|
|
163
170
|
else {
|
|
164
171
|
logger.debug(`[AmazonBedrockProvider] Conversation completed with final text`);
|
|
@@ -876,7 +883,9 @@ export class AmazonBedrockProvider extends BaseProvider {
|
|
|
876
883
|
logger.info(`🔍 [AmazonBedrockProvider] Message ${index}: role=${msg.role}, content=${JSON.stringify(msg.content)}`);
|
|
877
884
|
});
|
|
878
885
|
// Get all available tools
|
|
879
|
-
|
|
886
|
+
// BaseProvider.stream() pre-merges base tools + external tools into options.tools
|
|
887
|
+
const aiTools = options.tools ||
|
|
888
|
+
(await this.getAllTools());
|
|
880
889
|
const allTools = this.convertAISDKToolsToToolDefinitions(aiTools);
|
|
881
890
|
const toolConfig = this.formatToolsForBedrock(allTools);
|
|
882
891
|
const convertedMessages = this.convertToAWSMessages(this.conversationHistory);
|
|
@@ -1177,4 +1186,52 @@ export class AmazonBedrockProvider extends BaseProvider {
|
|
|
1177
1186
|
}
|
|
1178
1187
|
return new Error(`AWS Bedrock error: ${message}`);
|
|
1179
1188
|
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Generate embeddings for text using Amazon Bedrock embedding models
|
|
1191
|
+
* Uses the native AWS SDK InvokeModel command for Titan embeddings
|
|
1192
|
+
* @param text - The text to embed
|
|
1193
|
+
* @param modelName - The embedding model to use (default: amazon.titan-embed-text-v2:0)
|
|
1194
|
+
* @returns Promise resolving to the embedding vector
|
|
1195
|
+
*/
|
|
1196
|
+
async embed(text, modelName) {
|
|
1197
|
+
const embeddingModelName = modelName || "amazon.titan-embed-text-v2:0";
|
|
1198
|
+
logger.debug("Generating embedding", {
|
|
1199
|
+
provider: this.providerName,
|
|
1200
|
+
model: embeddingModelName,
|
|
1201
|
+
textLength: text.length,
|
|
1202
|
+
});
|
|
1203
|
+
try {
|
|
1204
|
+
const { InvokeModelCommand } = await import("@aws-sdk/client-bedrock-runtime");
|
|
1205
|
+
// Titan Embed models expect a specific input format
|
|
1206
|
+
const requestBody = JSON.stringify({
|
|
1207
|
+
inputText: text,
|
|
1208
|
+
});
|
|
1209
|
+
const command = new InvokeModelCommand({
|
|
1210
|
+
modelId: embeddingModelName,
|
|
1211
|
+
contentType: "application/json",
|
|
1212
|
+
accept: "application/json",
|
|
1213
|
+
body: requestBody,
|
|
1214
|
+
});
|
|
1215
|
+
const response = await this.bedrockClient.send(command);
|
|
1216
|
+
// Parse the response
|
|
1217
|
+
const responseBody = JSON.parse(new TextDecoder().decode(response.body));
|
|
1218
|
+
if (!responseBody.embedding || !Array.isArray(responseBody.embedding)) {
|
|
1219
|
+
throw new Error("Invalid embedding response from Bedrock");
|
|
1220
|
+
}
|
|
1221
|
+
logger.debug("Embedding generated successfully", {
|
|
1222
|
+
provider: this.providerName,
|
|
1223
|
+
model: embeddingModelName,
|
|
1224
|
+
embeddingDimension: responseBody.embedding.length,
|
|
1225
|
+
});
|
|
1226
|
+
return responseBody.embedding;
|
|
1227
|
+
}
|
|
1228
|
+
catch (error) {
|
|
1229
|
+
logger.error("Embedding generation failed", {
|
|
1230
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1231
|
+
model: embeddingModelName,
|
|
1232
|
+
textLength: text.length,
|
|
1233
|
+
});
|
|
1234
|
+
throw this.handleProviderError(error);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1180
1237
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type LanguageModelV1 } from "ai";
|
|
2
|
-
import type
|
|
3
|
-
import { AIProviderName } from "../constants/enums.js";
|
|
4
|
-
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
2
|
+
import { type AIProviderName } from "../constants/enums.js";
|
|
5
3
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
4
|
+
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
5
|
+
import type { ValidationSchema } from "../types/typeAliases.js";
|
|
6
6
|
/**
|
|
7
7
|
* Anthropic Provider v2 - BaseProvider Implementation
|
|
8
8
|
* Fixed syntax and enhanced with proper error handling
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
2
2
|
import { streamText } from "ai";
|
|
3
|
-
import {
|
|
3
|
+
import { AnthropicModels } from "../constants/enums.js";
|
|
4
4
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
5
|
-
import { logger } from "../utils/logger.js";
|
|
6
|
-
import { createTimeoutController, TimeoutError } from "../utils/timeout.js";
|
|
7
|
-
import { AuthenticationError, NetworkError, ProviderError, RateLimitError, } from "../types/errors.js";
|
|
8
5
|
import { DEFAULT_MAX_STEPS } from "../core/constants.js";
|
|
9
|
-
import { validateApiKey, createAnthropicConfig, getProviderModel, } from "../utils/providerConfig.js";
|
|
10
6
|
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
7
|
+
import { AuthenticationError, NetworkError, ProviderError, RateLimitError, } from "../types/errors.js";
|
|
8
|
+
import { logger } from "../utils/logger.js";
|
|
9
|
+
import { createAnthropicConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
|
|
10
|
+
import { createTimeoutController, TimeoutError } from "../utils/timeout.js";
|
|
11
11
|
// Configuration helpers - now using consolidated utility
|
|
12
12
|
const getAnthropicApiKey = () => {
|
|
13
13
|
return validateApiKey(createAnthropicConfig());
|
|
@@ -88,9 +88,12 @@ export class AnthropicProvider extends BaseProvider {
|
|
|
88
88
|
const timeout = this.getTimeout(options);
|
|
89
89
|
const timeoutController = createTimeoutController(timeout, this.providerName, "stream");
|
|
90
90
|
try {
|
|
91
|
-
//
|
|
91
|
+
// Get tools - options.tools is pre-merged by BaseProvider.stream() with
|
|
92
|
+
// base tools (MCP/built-in) + user-provided tools (RAG, etc.)
|
|
92
93
|
const shouldUseTools = !options.disableTools && this.supportsTools();
|
|
93
|
-
const tools = shouldUseTools
|
|
94
|
+
const tools = shouldUseTools
|
|
95
|
+
? options.tools || (await this.getAllTools())
|
|
96
|
+
: {};
|
|
94
97
|
// Build message array from options with multimodal support
|
|
95
98
|
// Using protected helper from BaseProvider to eliminate code duplication
|
|
96
99
|
const messages = await this.buildMessagesForStream(options);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type
|
|
3
|
-
import { AIProviderName } from "../constants/enums.js";
|
|
4
|
-
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
5
|
-
import type { TextGenerationOptions, EnhancedGenerateResult } from "../types/generateTypes.js";
|
|
1
|
+
import { type LanguageModelV1, type Schema } from "ai";
|
|
2
|
+
import { type AIProviderName } from "../constants/enums.js";
|
|
6
3
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
4
|
+
import type { EnhancedGenerateResult, TextGenerationOptions } from "../types/generateTypes.js";
|
|
5
|
+
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
6
|
+
import type { ZodUnknownSchema } from "../types/typeAliases.js";
|
|
7
7
|
/**
|
|
8
8
|
* Google AI Studio provider implementation using BaseProvider
|
|
9
9
|
* Migrated from original GoogleAIStudio class to new factory pattern
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
2
2
|
import { streamText } from "ai";
|
|
3
|
-
import {
|
|
4
|
-
import { NeuroLinkError, ERROR_CODES } from "../utils/errorHandling.js";
|
|
3
|
+
import { ErrorCategory, ErrorSeverity, GoogleAIModels, } from "../constants/enums.js";
|
|
5
4
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
6
|
-
import { logger } from "../utils/logger.js";
|
|
7
|
-
import { createTimeoutController, TimeoutError } from "../utils/timeout.js";
|
|
8
|
-
import { AuthenticationError, NetworkError, ProviderError, RateLimitError, } from "../types/errors.js";
|
|
9
5
|
import { DEFAULT_MAX_STEPS, DEFAULT_TOOL_MAX_RETRIES, } from "../core/constants.js";
|
|
10
6
|
import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
|
|
7
|
+
import { AuthenticationError, NetworkError, ProviderError, RateLimitError, } from "../types/errors.js";
|
|
8
|
+
import { ERROR_CODES, NeuroLinkError } from "../utils/errorHandling.js";
|
|
9
|
+
import { logger } from "../utils/logger.js";
|
|
11
10
|
import { isGemini3Model } from "../utils/modelDetection.js";
|
|
12
11
|
import { convertZodToJsonSchema, inlineJsonSchema, isZodSchema, } from "../utils/schemaConversion.js";
|
|
13
12
|
import { createNativeThinkingConfig } from "../utils/thinkingConfig.js";
|
|
13
|
+
import { createTimeoutController, TimeoutError } from "../utils/timeout.js";
|
|
14
14
|
// Google AI Live API types now imported from ../types/providerSpecific.js
|
|
15
15
|
// Import proper types for multimodal message handling
|
|
16
16
|
// Create Google GenAI client
|
|
@@ -424,9 +424,12 @@ export class GoogleAIStudioProvider extends BaseProvider {
|
|
|
424
424
|
const timeout = this.getTimeout(options);
|
|
425
425
|
const timeoutController = createTimeoutController(timeout, this.providerName, "stream");
|
|
426
426
|
try {
|
|
427
|
-
// Get tools consistently with generate method
|
|
427
|
+
// Get tools consistently with generate method (include user-provided RAG tools)
|
|
428
428
|
const shouldUseTools = !options.disableTools && this.supportsTools();
|
|
429
|
-
const
|
|
429
|
+
const baseTools = shouldUseTools ? await this.getAllTools() : {};
|
|
430
|
+
const tools = shouldUseTools
|
|
431
|
+
? { ...baseTools, ...(options.tools || {}) }
|
|
432
|
+
: {};
|
|
430
433
|
// Build message array from options with multimodal support
|
|
431
434
|
// Using protected helper from BaseProvider to eliminate code duplication
|
|
432
435
|
const messages = await this.buildMessagesForStream(options);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { type LanguageModel, type LanguageModelV1, type Schema } from "ai";
|
|
1
2
|
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
|
-
import { type
|
|
3
|
-
import { AIProviderName } from "../constants/enums.js";
|
|
4
|
-
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
5
|
-
import type { TextGenerationOptions, EnhancedGenerateResult } from "../types/generateTypes.js";
|
|
3
|
+
import { type AIProviderName } from "../constants/enums.js";
|
|
6
4
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
5
|
+
import type { EnhancedGenerateResult, TextGenerationOptions } from "../types/generateTypes.js";
|
|
6
|
+
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
7
7
|
/**
|
|
8
8
|
* Google Vertex AI Provider v2 - BaseProvider Implementation
|
|
9
9
|
*
|
|
@@ -64,6 +64,11 @@ export declare class GoogleVertexProvider extends BaseProvider {
|
|
|
64
64
|
constructor(modelName?: string, _providerName?: string, sdk?: unknown, region?: string);
|
|
65
65
|
protected getProviderName(): AIProviderName;
|
|
66
66
|
protected getDefaultModel(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Get the default embedding model for Google Vertex
|
|
69
|
+
* @returns The default Vertex AI embedding model name
|
|
70
|
+
*/
|
|
71
|
+
protected getDefaultEmbeddingModel(): string;
|
|
67
72
|
/**
|
|
68
73
|
* Returns the Vercel AI SDK model instance for Google Vertex
|
|
69
74
|
* Creates fresh model instances for each request
|
|
@@ -237,6 +242,13 @@ export declare class GoogleVertexProvider extends BaseProvider {
|
|
|
237
242
|
* @returns A promise that resolves to the generation result, including the image data.
|
|
238
243
|
*/
|
|
239
244
|
protected executeImageGeneration(options: TextGenerationOptions): Promise<EnhancedGenerateResult>;
|
|
245
|
+
/**
|
|
246
|
+
* Generate embeddings for text using Google Vertex AI text-embedding models
|
|
247
|
+
* @param text - The text to embed
|
|
248
|
+
* @param modelName - The embedding model to use (default: text-embedding-004)
|
|
249
|
+
* @returns Promise resolving to the embedding vector
|
|
250
|
+
*/
|
|
251
|
+
embed(text: string, modelName?: string): Promise<number[]>;
|
|
240
252
|
/**
|
|
241
253
|
* Get model suggestions when a model is not found
|
|
242
254
|
*/
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { createVertex, } from "@ai-sdk/google-vertex";
|
|
2
2
|
import { createVertexAnthropic, } from "@ai-sdk/google-vertex/anthropic";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import { Output, streamText, } from "ai";
|
|
4
|
+
import dns from "dns";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import os from "os";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { ErrorCategory, ErrorSeverity, } from "../constants/enums.js";
|
|
6
9
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
7
|
-
import {
|
|
8
|
-
import { createTimeoutController, TimeoutError } from "../utils/timeout.js";
|
|
9
|
-
import { AuthenticationError, ProviderError } from "../types/errors.js";
|
|
10
|
-
import { DEFAULT_MAX_STEPS, GLOBAL_LOCATION_MODELS, DEFAULT_TOOL_MAX_RETRIES, } from "../core/constants.js";
|
|
10
|
+
import { DEFAULT_MAX_STEPS, DEFAULT_TOOL_MAX_RETRIES, GLOBAL_LOCATION_MODELS, } from "../core/constants.js";
|
|
11
11
|
import { ModelConfigurationManager } from "../core/modelConfiguration.js";
|
|
12
|
-
import {
|
|
12
|
+
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
13
|
+
import { AuthenticationError, ProviderError } from "../types/errors.js";
|
|
14
|
+
import { ERROR_CODES, NeuroLinkError } from "../utils/errorHandling.js";
|
|
15
|
+
import { FileDetector } from "../utils/fileDetector.js";
|
|
16
|
+
import { logger } from "../utils/logger.js";
|
|
13
17
|
import { isGemini3Model } from "../utils/modelDetection.js";
|
|
18
|
+
import { createGoogleAuthConfig, createVertexProjectConfig, validateApiKey, } from "../utils/providerConfig.js";
|
|
14
19
|
import { convertZodToJsonSchema, inlineJsonSchema, } from "../utils/schemaConversion.js";
|
|
15
20
|
import { createNativeThinkingConfig } from "../utils/thinkingConfig.js";
|
|
16
|
-
import
|
|
17
|
-
import path from "path";
|
|
18
|
-
import os from "os";
|
|
19
|
-
import dns from "dns";
|
|
20
|
-
import { createProxyFetch } from "../proxy/proxyFetch.js";
|
|
21
|
-
import { FileDetector } from "../utils/fileDetector.js";
|
|
21
|
+
import { createTimeoutController, TimeoutError } from "../utils/timeout.js";
|
|
22
22
|
// Import proper types for multimodal message handling
|
|
23
23
|
// Enhanced Anthropic support with direct imports
|
|
24
24
|
// Using the dual provider architecture from Vercel AI SDK
|
|
@@ -339,6 +339,15 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
339
339
|
getDefaultModel() {
|
|
340
340
|
return getDefaultVertexModel();
|
|
341
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Get the default embedding model for Google Vertex
|
|
344
|
+
* @returns The default Vertex AI embedding model name
|
|
345
|
+
*/
|
|
346
|
+
getDefaultEmbeddingModel() {
|
|
347
|
+
return (process.env.VERTEX_EMBEDDING_MODEL ||
|
|
348
|
+
process.env.GOOGLE_EMBEDDING_MODEL ||
|
|
349
|
+
"text-embedding-004");
|
|
350
|
+
}
|
|
342
351
|
/**
|
|
343
352
|
* Returns the Vercel AI SDK model instance for Google Vertex
|
|
344
353
|
* Creates fresh model instances for each request
|
|
@@ -702,11 +711,16 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
702
711
|
// Using protected helper from BaseProvider to eliminate code duplication
|
|
703
712
|
const messages = await this.buildMessagesForStream(options);
|
|
704
713
|
const model = await this.getAISDKModelWithMiddleware(options); // This is where network connection happens!
|
|
705
|
-
// Get all available tools (direct + MCP + external) for streaming
|
|
714
|
+
// Get all available tools (direct + MCP + external + user-provided RAG tools) for streaming
|
|
706
715
|
const shouldUseTools = !options.disableTools && this.supportsTools();
|
|
707
|
-
const
|
|
716
|
+
const baseStreamTools = shouldUseTools ? await this.getAllTools() : {};
|
|
717
|
+
const tools = shouldUseTools
|
|
718
|
+
? { ...baseStreamTools, ...(options.tools || {}) }
|
|
719
|
+
: {};
|
|
708
720
|
logger.debug(`${functionTag}: Tools for streaming`, {
|
|
709
721
|
shouldUseTools,
|
|
722
|
+
baseToolCount: Object.keys(baseStreamTools).length,
|
|
723
|
+
externalToolCount: Object.keys(options.tools || {}).length,
|
|
710
724
|
toolCount: Object.keys(tools).length,
|
|
711
725
|
toolNames: Object.keys(tools),
|
|
712
726
|
});
|
|
@@ -2747,6 +2761,48 @@ export class GoogleVertexProvider extends BaseProvider {
|
|
|
2747
2761
|
throw this.handleProviderError(error);
|
|
2748
2762
|
}
|
|
2749
2763
|
}
|
|
2764
|
+
/**
|
|
2765
|
+
* Generate embeddings for text using Google Vertex AI text-embedding models
|
|
2766
|
+
* @param text - The text to embed
|
|
2767
|
+
* @param modelName - The embedding model to use (default: text-embedding-004)
|
|
2768
|
+
* @returns Promise resolving to the embedding vector
|
|
2769
|
+
*/
|
|
2770
|
+
async embed(text, modelName) {
|
|
2771
|
+
const embeddingModelName = modelName || "text-embedding-004";
|
|
2772
|
+
logger.debug("Generating embedding", {
|
|
2773
|
+
provider: this.providerName,
|
|
2774
|
+
model: embeddingModelName,
|
|
2775
|
+
textLength: text.length,
|
|
2776
|
+
});
|
|
2777
|
+
try {
|
|
2778
|
+
// Create embedding model using the AI SDK
|
|
2779
|
+
const { embed } = await import("ai");
|
|
2780
|
+
// Create the Vertex provider with current settings
|
|
2781
|
+
const vertexSettings = await createVertexSettings(this.location);
|
|
2782
|
+
const vertex = createVertex(vertexSettings);
|
|
2783
|
+
// Get the text embedding model
|
|
2784
|
+
const embeddingModel = vertex.textEmbeddingModel(embeddingModelName);
|
|
2785
|
+
// Generate the embedding
|
|
2786
|
+
const result = await embed({
|
|
2787
|
+
model: embeddingModel,
|
|
2788
|
+
value: text,
|
|
2789
|
+
});
|
|
2790
|
+
logger.debug("Embedding generated successfully", {
|
|
2791
|
+
provider: this.providerName,
|
|
2792
|
+
model: embeddingModelName,
|
|
2793
|
+
embeddingDimension: result.embedding.length,
|
|
2794
|
+
});
|
|
2795
|
+
return result.embedding;
|
|
2796
|
+
}
|
|
2797
|
+
catch (error) {
|
|
2798
|
+
logger.error("Embedding generation failed", {
|
|
2799
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2800
|
+
model: embeddingModelName,
|
|
2801
|
+
textLength: text.length,
|
|
2802
|
+
});
|
|
2803
|
+
throw this.handleProviderError(error);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2750
2806
|
/**
|
|
2751
2807
|
* Get model suggestions when a model is not found
|
|
2752
2808
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { type LanguageModelV1, type Schema } from "ai";
|
|
1
2
|
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
|
-
import
|
|
3
|
-
import { AIProviderName } from "../constants/enums.js";
|
|
4
|
-
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
3
|
+
import type { AIProviderName } from "../constants/enums.js";
|
|
5
4
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
5
|
+
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
6
6
|
/**
|
|
7
7
|
* LiteLLM Provider - BaseProvider Implementation
|
|
8
8
|
* Provides access to 100+ models via LiteLLM proxy server
|