@juspay/neurolink 9.1.1 → 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 +27 -0
- package/README.md +106 -37
- package/dist/agent/directTools.d.ts +11 -11
- package/dist/cli/commands/config.d.ts +6 -6
- 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/image-gen/ImageGenService.d.ts +143 -0
- package/dist/image-gen/ImageGenService.js +345 -0
- package/dist/image-gen/imageGenTools.d.ts +126 -0
- package/dist/image-gen/imageGenTools.js +304 -0
- package/dist/image-gen/index.d.ts +46 -0
- package/dist/image-gen/index.js +48 -0
- package/dist/image-gen/types.d.ts +237 -0
- package/dist/image-gen/types.js +24 -0
- package/dist/index.d.ts +46 -12
- package/dist/index.js +88 -36
- package/dist/lib/agent/directTools.d.ts +8 -8
- 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/image-gen/ImageGenService.d.ts +143 -0
- package/dist/lib/image-gen/ImageGenService.js +346 -0
- package/dist/lib/image-gen/imageGenTools.d.ts +126 -0
- package/dist/lib/image-gen/imageGenTools.js +305 -0
- package/dist/lib/image-gen/index.d.ts +46 -0
- package/dist/lib/image-gen/index.js +49 -0
- package/dist/lib/image-gen/types.d.ts +237 -0
- package/dist/lib/image-gen/types.js +25 -0
- 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/processors/base/BaseFileProcessor.d.ts +273 -0
- package/dist/lib/processors/base/BaseFileProcessor.js +614 -0
- package/dist/lib/processors/base/index.d.ts +14 -0
- package/dist/lib/processors/base/index.js +20 -0
- package/dist/lib/processors/base/types.d.ts +593 -0
- package/dist/lib/processors/base/types.js +77 -0
- package/dist/lib/processors/cli/fileProcessorCli.d.ts +163 -0
- package/dist/lib/processors/cli/fileProcessorCli.js +389 -0
- package/dist/lib/processors/cli/index.d.ts +37 -0
- package/dist/lib/processors/cli/index.js +50 -0
- package/dist/lib/processors/code/ConfigProcessor.d.ts +171 -0
- package/dist/lib/processors/code/ConfigProcessor.js +401 -0
- package/dist/lib/processors/code/SourceCodeProcessor.d.ts +174 -0
- package/dist/lib/processors/code/SourceCodeProcessor.js +305 -0
- package/dist/lib/processors/code/index.d.ts +44 -0
- package/dist/lib/processors/code/index.js +61 -0
- package/dist/lib/processors/config/fileTypes.d.ts +283 -0
- package/dist/lib/processors/config/fileTypes.js +521 -0
- package/dist/lib/processors/config/index.d.ts +32 -0
- package/dist/lib/processors/config/index.js +93 -0
- package/dist/lib/processors/config/languageMap.d.ts +66 -0
- package/dist/lib/processors/config/languageMap.js +411 -0
- package/dist/lib/processors/config/mimeTypes.d.ts +376 -0
- package/dist/lib/processors/config/mimeTypes.js +339 -0
- package/dist/lib/processors/config/sizeLimits.d.ts +194 -0
- package/dist/lib/processors/config/sizeLimits.js +247 -0
- package/dist/lib/processors/data/JsonProcessor.d.ts +122 -0
- package/dist/lib/processors/data/JsonProcessor.js +204 -0
- package/dist/lib/processors/data/XmlProcessor.d.ts +160 -0
- package/dist/lib/processors/data/XmlProcessor.js +284 -0
- package/dist/lib/processors/data/YamlProcessor.d.ts +163 -0
- package/dist/lib/processors/data/YamlProcessor.js +295 -0
- package/dist/lib/processors/data/index.d.ts +49 -0
- package/dist/lib/processors/data/index.js +77 -0
- package/dist/lib/processors/document/ExcelProcessor.d.ts +238 -0
- package/dist/lib/processors/document/ExcelProcessor.js +520 -0
- package/dist/lib/processors/document/OpenDocumentProcessor.d.ts +69 -0
- package/dist/lib/processors/document/OpenDocumentProcessor.js +211 -0
- package/dist/lib/processors/document/RtfProcessor.d.ts +152 -0
- package/dist/lib/processors/document/RtfProcessor.js +362 -0
- package/dist/lib/processors/document/WordProcessor.d.ts +168 -0
- package/dist/lib/processors/document/WordProcessor.js +354 -0
- package/dist/lib/processors/document/index.d.ts +54 -0
- package/dist/lib/processors/document/index.js +91 -0
- package/dist/lib/processors/errors/FileErrorCode.d.ts +98 -0
- package/dist/lib/processors/errors/FileErrorCode.js +256 -0
- package/dist/lib/processors/errors/errorHelpers.d.ts +151 -0
- package/dist/lib/processors/errors/errorHelpers.js +379 -0
- package/dist/lib/processors/errors/errorSerializer.d.ts +139 -0
- package/dist/lib/processors/errors/errorSerializer.js +508 -0
- package/dist/lib/processors/errors/index.d.ts +46 -0
- package/dist/lib/processors/errors/index.js +50 -0
- package/dist/lib/processors/index.d.ts +76 -0
- package/dist/lib/processors/index.js +113 -0
- package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +244 -0
- package/dist/lib/processors/integration/FileProcessorIntegration.js +273 -0
- package/dist/lib/processors/integration/index.d.ts +42 -0
- package/dist/lib/processors/integration/index.js +45 -0
- package/dist/lib/processors/markup/HtmlProcessor.d.ts +169 -0
- package/dist/lib/processors/markup/HtmlProcessor.js +250 -0
- package/dist/lib/processors/markup/MarkdownProcessor.d.ts +165 -0
- package/dist/lib/processors/markup/MarkdownProcessor.js +245 -0
- package/dist/lib/processors/markup/SvgProcessor.d.ts +156 -0
- package/dist/lib/processors/markup/SvgProcessor.js +241 -0
- package/dist/lib/processors/markup/TextProcessor.d.ts +135 -0
- package/dist/lib/processors/markup/TextProcessor.js +189 -0
- package/dist/lib/processors/markup/index.d.ts +66 -0
- package/dist/lib/processors/markup/index.js +103 -0
- package/dist/lib/processors/registry/ProcessorRegistry.d.ts +334 -0
- package/dist/lib/processors/registry/ProcessorRegistry.js +609 -0
- package/dist/lib/processors/registry/index.d.ts +12 -0
- package/dist/lib/processors/registry/index.js +17 -0
- package/dist/lib/processors/registry/types.d.ts +53 -0
- package/dist/lib/processors/registry/types.js +11 -0
- 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/providers/sagemaker/language-model.d.ts +2 -2
- 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 +2 -2
- package/dist/lib/types/common.d.ts +0 -1
- package/dist/lib/types/fileTypes.d.ts +1 -1
- package/dist/lib/types/generateTypes.d.ts +42 -8
- package/dist/lib/types/generateTypes.js +1 -1
- package/dist/lib/types/index.d.ts +25 -24
- package/dist/lib/types/index.js +21 -20
- package/dist/lib/types/modelTypes.d.ts +16 -16
- package/dist/lib/types/pptTypes.d.ts +14 -2
- package/dist/lib/types/pptTypes.js +16 -0
- package/dist/lib/types/streamTypes.d.ts +28 -8
- package/dist/lib/types/streamTypes.js +1 -1
- package/dist/lib/utils/async/delay.d.ts +40 -0
- package/dist/lib/utils/async/delay.js +43 -0
- package/dist/lib/utils/async/index.d.ts +23 -0
- package/dist/lib/utils/async/index.js +24 -0
- package/dist/lib/utils/async/retry.d.ts +141 -0
- package/dist/lib/utils/async/retry.js +172 -0
- package/dist/lib/utils/async/withTimeout.d.ts +73 -0
- package/dist/lib/utils/async/withTimeout.js +97 -0
- package/dist/lib/utils/fileDetector.d.ts +7 -1
- package/dist/lib/utils/fileDetector.js +91 -18
- package/dist/lib/utils/json/extract.d.ts +103 -0
- package/dist/lib/utils/json/extract.js +249 -0
- package/dist/lib/utils/json/index.d.ts +36 -0
- package/dist/lib/utils/json/index.js +37 -0
- package/dist/lib/utils/json/safeParse.d.ts +137 -0
- package/dist/lib/utils/json/safeParse.js +191 -0
- package/dist/lib/utils/messageBuilder.d.ts +2 -2
- package/dist/lib/utils/messageBuilder.js +15 -7
- package/dist/lib/utils/modelRouter.d.ts +4 -4
- package/dist/lib/utils/modelRouter.js +4 -4
- package/dist/lib/utils/sanitizers/filename.d.ts +137 -0
- package/dist/lib/utils/sanitizers/filename.js +366 -0
- package/dist/lib/utils/sanitizers/html.d.ts +170 -0
- package/dist/lib/utils/sanitizers/html.js +326 -0
- package/dist/lib/utils/sanitizers/index.d.ts +26 -0
- package/dist/lib/utils/sanitizers/index.js +30 -0
- package/dist/lib/utils/sanitizers/svg.d.ts +81 -0
- package/dist/lib/utils/sanitizers/svg.js +483 -0
- 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/processors/base/BaseFileProcessor.d.ts +273 -0
- package/dist/processors/base/BaseFileProcessor.js +613 -0
- package/dist/processors/base/index.d.ts +14 -0
- package/dist/processors/base/index.js +19 -0
- package/dist/processors/base/types.d.ts +593 -0
- package/dist/processors/base/types.js +76 -0
- package/dist/processors/cli/fileProcessorCli.d.ts +163 -0
- package/dist/processors/cli/fileProcessorCli.js +388 -0
- package/dist/processors/cli/index.d.ts +37 -0
- package/dist/processors/cli/index.js +49 -0
- package/dist/processors/code/ConfigProcessor.d.ts +171 -0
- package/dist/processors/code/ConfigProcessor.js +400 -0
- package/dist/processors/code/SourceCodeProcessor.d.ts +174 -0
- package/dist/processors/code/SourceCodeProcessor.js +304 -0
- package/dist/processors/code/index.d.ts +44 -0
- package/dist/processors/code/index.js +60 -0
- package/dist/processors/config/fileTypes.d.ts +283 -0
- package/dist/processors/config/fileTypes.js +520 -0
- package/dist/processors/config/index.d.ts +32 -0
- package/dist/processors/config/index.js +92 -0
- package/dist/processors/config/languageMap.d.ts +66 -0
- package/dist/processors/config/languageMap.js +410 -0
- package/dist/processors/config/mimeTypes.d.ts +376 -0
- package/dist/processors/config/mimeTypes.js +338 -0
- package/dist/processors/config/sizeLimits.d.ts +194 -0
- package/dist/processors/config/sizeLimits.js +246 -0
- package/dist/processors/data/JsonProcessor.d.ts +122 -0
- package/dist/processors/data/JsonProcessor.js +203 -0
- package/dist/processors/data/XmlProcessor.d.ts +160 -0
- package/dist/processors/data/XmlProcessor.js +283 -0
- package/dist/processors/data/YamlProcessor.d.ts +163 -0
- package/dist/processors/data/YamlProcessor.js +294 -0
- package/dist/processors/data/index.d.ts +49 -0
- package/dist/processors/data/index.js +76 -0
- package/dist/processors/document/ExcelProcessor.d.ts +238 -0
- package/dist/processors/document/ExcelProcessor.js +519 -0
- package/dist/processors/document/OpenDocumentProcessor.d.ts +69 -0
- package/dist/processors/document/OpenDocumentProcessor.js +210 -0
- package/dist/processors/document/RtfProcessor.d.ts +152 -0
- package/dist/processors/document/RtfProcessor.js +361 -0
- package/dist/processors/document/WordProcessor.d.ts +168 -0
- package/dist/processors/document/WordProcessor.js +353 -0
- package/dist/processors/document/index.d.ts +54 -0
- package/dist/processors/document/index.js +90 -0
- package/dist/processors/errors/FileErrorCode.d.ts +98 -0
- package/dist/processors/errors/FileErrorCode.js +255 -0
- package/dist/processors/errors/errorHelpers.d.ts +151 -0
- package/dist/processors/errors/errorHelpers.js +378 -0
- package/dist/processors/errors/errorSerializer.d.ts +139 -0
- package/dist/processors/errors/errorSerializer.js +507 -0
- package/dist/processors/errors/index.d.ts +46 -0
- package/dist/processors/errors/index.js +49 -0
- package/dist/processors/index.d.ts +76 -0
- package/dist/processors/index.js +112 -0
- package/dist/processors/integration/FileProcessorIntegration.d.ts +244 -0
- package/dist/processors/integration/FileProcessorIntegration.js +272 -0
- package/dist/processors/integration/index.d.ts +42 -0
- package/dist/processors/integration/index.js +44 -0
- package/dist/processors/markup/HtmlProcessor.d.ts +169 -0
- package/dist/processors/markup/HtmlProcessor.js +249 -0
- package/dist/processors/markup/MarkdownProcessor.d.ts +165 -0
- package/dist/processors/markup/MarkdownProcessor.js +244 -0
- package/dist/processors/markup/SvgProcessor.d.ts +156 -0
- package/dist/processors/markup/SvgProcessor.js +240 -0
- package/dist/processors/markup/TextProcessor.d.ts +135 -0
- package/dist/processors/markup/TextProcessor.js +188 -0
- package/dist/processors/markup/index.d.ts +66 -0
- package/dist/processors/markup/index.js +102 -0
- package/dist/processors/registry/ProcessorRegistry.d.ts +334 -0
- package/dist/processors/registry/ProcessorRegistry.js +608 -0
- package/dist/processors/registry/index.d.ts +12 -0
- package/dist/processors/registry/index.js +16 -0
- package/dist/processors/registry/types.d.ts +53 -0
- package/dist/processors/registry/types.js +10 -0
- 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 +8 -8
- package/dist/types/common.d.ts +0 -1
- package/dist/types/fileTypes.d.ts +1 -1
- package/dist/types/generateTypes.d.ts +42 -8
- package/dist/types/generateTypes.js +1 -1
- package/dist/types/index.d.ts +25 -24
- package/dist/types/index.js +21 -20
- package/dist/types/modelTypes.d.ts +10 -10
- package/dist/types/pptTypes.d.ts +14 -2
- package/dist/types/pptTypes.js +16 -0
- package/dist/types/streamTypes.d.ts +28 -8
- package/dist/types/streamTypes.js +1 -1
- package/dist/utils/async/delay.d.ts +40 -0
- package/dist/utils/async/delay.js +42 -0
- package/dist/utils/async/index.d.ts +23 -0
- package/dist/utils/async/index.js +23 -0
- package/dist/utils/async/retry.d.ts +141 -0
- package/dist/utils/async/retry.js +171 -0
- package/dist/utils/async/withTimeout.d.ts +73 -0
- package/dist/utils/async/withTimeout.js +96 -0
- package/dist/utils/fileDetector.d.ts +7 -1
- package/dist/utils/fileDetector.js +91 -18
- package/dist/utils/json/extract.d.ts +103 -0
- package/dist/utils/json/extract.js +248 -0
- package/dist/utils/json/index.d.ts +36 -0
- package/dist/utils/json/index.js +36 -0
- package/dist/utils/json/safeParse.d.ts +137 -0
- package/dist/utils/json/safeParse.js +190 -0
- package/dist/utils/messageBuilder.d.ts +2 -2
- package/dist/utils/messageBuilder.js +15 -7
- package/dist/utils/modelRouter.d.ts +4 -4
- package/dist/utils/modelRouter.js +4 -4
- package/dist/utils/sanitizers/filename.d.ts +137 -0
- package/dist/utils/sanitizers/filename.js +365 -0
- package/dist/utils/sanitizers/html.d.ts +170 -0
- package/dist/utils/sanitizers/html.js +325 -0
- package/dist/utils/sanitizers/index.d.ts +26 -0
- package/dist/utils/sanitizers/index.js +29 -0
- package/dist/utils/sanitizers/svg.d.ts +81 -0
- package/dist/utils/sanitizers/svg.js +482 -0
- package/package.json +2 -2
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RAG Circuit Breaker
|
|
3
|
+
*
|
|
4
|
+
* Implements circuit breaker pattern for RAG operations including
|
|
5
|
+
* vector store queries, embeddings, and reranking calls.
|
|
6
|
+
* Provides fault tolerance and prevents cascading failures.
|
|
7
|
+
*/
|
|
8
|
+
import { TypedEventEmitter } from "../../core/infrastructure/index.js";
|
|
9
|
+
import { logger } from "../../utils/logger.js";
|
|
10
|
+
import { RAGCircuitBreakerError, RAGErrorCodes } from "../errors/RAGError.js";
|
|
11
|
+
/**
|
|
12
|
+
* Default configuration
|
|
13
|
+
*/
|
|
14
|
+
const DEFAULT_CONFIG = {
|
|
15
|
+
failureThreshold: 5,
|
|
16
|
+
resetTimeout: 60000,
|
|
17
|
+
halfOpenMaxCalls: 3,
|
|
18
|
+
operationTimeout: 30000,
|
|
19
|
+
minimumCallsBeforeCalculation: 10,
|
|
20
|
+
statisticsWindowSize: 300000,
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* RAG Circuit Breaker
|
|
24
|
+
*
|
|
25
|
+
* Provides circuit breaker pattern implementation for RAG operations
|
|
26
|
+
* with comprehensive statistics and event handling.
|
|
27
|
+
*/
|
|
28
|
+
export class RAGCircuitBreaker extends TypedEventEmitter {
|
|
29
|
+
name;
|
|
30
|
+
state = "closed";
|
|
31
|
+
config;
|
|
32
|
+
callHistory = [];
|
|
33
|
+
lastFailureTime = 0;
|
|
34
|
+
halfOpenCalls = 0;
|
|
35
|
+
lastStateChange = new Date();
|
|
36
|
+
cleanupTimer;
|
|
37
|
+
constructor(name, config = {}) {
|
|
38
|
+
super();
|
|
39
|
+
this.name = name;
|
|
40
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
41
|
+
// Clean up old call records periodically
|
|
42
|
+
this.cleanupTimer = setInterval(() => this.cleanupCallHistory(), 60000);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Execute an operation with circuit breaker protection
|
|
46
|
+
*/
|
|
47
|
+
async execute(operation, operationType) {
|
|
48
|
+
const startTime = Date.now();
|
|
49
|
+
try {
|
|
50
|
+
// Check if circuit is open
|
|
51
|
+
if (this.state === "open") {
|
|
52
|
+
if (Date.now() - this.lastFailureTime < this.config.resetTimeout) {
|
|
53
|
+
const nextRetryTime = new Date(this.lastFailureTime + this.config.resetTimeout);
|
|
54
|
+
throw new RAGCircuitBreakerError(`Circuit breaker '${this.name}' is open. Next retry at ${nextRetryTime.toISOString()}`, {
|
|
55
|
+
code: RAGErrorCodes.CIRCUIT_BREAKER_OPEN,
|
|
56
|
+
circuitName: this.name,
|
|
57
|
+
nextRetryTime,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// Transition to half-open
|
|
61
|
+
this.changeState("half-open", "Reset timeout reached");
|
|
62
|
+
}
|
|
63
|
+
// Check half-open call limit
|
|
64
|
+
if (this.state === "half-open" &&
|
|
65
|
+
this.halfOpenCalls >= this.config.halfOpenMaxCalls) {
|
|
66
|
+
throw new RAGCircuitBreakerError(`Circuit breaker '${this.name}' is half-open but call limit reached`, {
|
|
67
|
+
code: RAGErrorCodes.CIRCUIT_BREAKER_HALF_OPEN_LIMIT,
|
|
68
|
+
circuitName: this.name,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// Execute operation with timeout
|
|
72
|
+
const result = await Promise.race([
|
|
73
|
+
operation(),
|
|
74
|
+
this.timeoutPromise(this.config.operationTimeout),
|
|
75
|
+
]);
|
|
76
|
+
// Record successful call
|
|
77
|
+
this.recordCall(true, Date.now() - startTime, operationType);
|
|
78
|
+
// Handle half-open success
|
|
79
|
+
if (this.state === "half-open") {
|
|
80
|
+
this.halfOpenCalls++;
|
|
81
|
+
// If enough successful calls in half-open, close the circuit
|
|
82
|
+
if (this.halfOpenCalls >= this.config.halfOpenMaxCalls) {
|
|
83
|
+
this.changeState("closed", "Half-open test successful");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
// Record failed call
|
|
90
|
+
const duration = Date.now() - startTime;
|
|
91
|
+
this.recordCall(false, duration, operationType);
|
|
92
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
93
|
+
// Emit failure event
|
|
94
|
+
this.emit("callFailure", {
|
|
95
|
+
error: errorMessage,
|
|
96
|
+
duration,
|
|
97
|
+
timestamp: new Date(),
|
|
98
|
+
operationType,
|
|
99
|
+
});
|
|
100
|
+
// Handle state transitions on failure
|
|
101
|
+
if (this.state === "half-open") {
|
|
102
|
+
// Failure in half-open immediately opens circuit
|
|
103
|
+
this.changeState("open", `Half-open test failed: ${errorMessage}`);
|
|
104
|
+
}
|
|
105
|
+
else if (this.state === "closed") {
|
|
106
|
+
// Check if we should open the circuit
|
|
107
|
+
this.checkFailureThreshold();
|
|
108
|
+
}
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Record a call in the history
|
|
114
|
+
*/
|
|
115
|
+
recordCall(success, duration, operationType) {
|
|
116
|
+
const now = Date.now();
|
|
117
|
+
this.callHistory.push({
|
|
118
|
+
timestamp: now,
|
|
119
|
+
success,
|
|
120
|
+
duration,
|
|
121
|
+
operationType,
|
|
122
|
+
});
|
|
123
|
+
// Emit success event
|
|
124
|
+
if (success) {
|
|
125
|
+
this.emit("callSuccess", {
|
|
126
|
+
duration,
|
|
127
|
+
timestamp: new Date(),
|
|
128
|
+
operationType,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// Update failure time
|
|
132
|
+
if (!success) {
|
|
133
|
+
this.lastFailureTime = now;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Check if failure threshold is exceeded
|
|
138
|
+
*/
|
|
139
|
+
checkFailureThreshold() {
|
|
140
|
+
const windowStart = Date.now() - this.config.statisticsWindowSize;
|
|
141
|
+
const windowCalls = this.callHistory.filter((call) => call.timestamp >= windowStart);
|
|
142
|
+
// Need minimum calls before calculating failure rate
|
|
143
|
+
if (windowCalls.length < this.config.minimumCallsBeforeCalculation) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const failedCalls = windowCalls.filter((call) => !call.success).length;
|
|
147
|
+
const failureRate = failedCalls / windowCalls.length;
|
|
148
|
+
logger.debug(`[RAGCircuitBreaker:${this.name}] Failure rate: ${(failureRate * 100).toFixed(1)}% (${failedCalls}/${windowCalls.length})`);
|
|
149
|
+
// Open circuit if failure count exceeds threshold
|
|
150
|
+
if (failedCalls >= this.config.failureThreshold) {
|
|
151
|
+
this.changeState("open", `Failure threshold exceeded: ${failedCalls} failures`);
|
|
152
|
+
this.emit("circuitOpen", {
|
|
153
|
+
failureRate,
|
|
154
|
+
totalCalls: windowCalls.length,
|
|
155
|
+
timestamp: new Date(),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Change circuit breaker state
|
|
161
|
+
*/
|
|
162
|
+
changeState(newState, reason) {
|
|
163
|
+
const oldState = this.state;
|
|
164
|
+
this.state = newState;
|
|
165
|
+
this.lastStateChange = new Date();
|
|
166
|
+
// Reset counters based on state
|
|
167
|
+
if (newState === "half-open") {
|
|
168
|
+
this.halfOpenCalls = 0;
|
|
169
|
+
this.emit("circuitHalfOpen", { timestamp: new Date() });
|
|
170
|
+
}
|
|
171
|
+
else if (newState === "closed") {
|
|
172
|
+
this.halfOpenCalls = 0;
|
|
173
|
+
this.emit("circuitClosed", { timestamp: new Date() });
|
|
174
|
+
}
|
|
175
|
+
logger.info(`[RAGCircuitBreaker:${this.name}] State changed: ${oldState} -> ${newState} (${reason})`);
|
|
176
|
+
// Emit state change event
|
|
177
|
+
this.emit("stateChange", {
|
|
178
|
+
oldState,
|
|
179
|
+
newState,
|
|
180
|
+
reason,
|
|
181
|
+
timestamp: new Date(),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Create a timeout promise
|
|
186
|
+
*/
|
|
187
|
+
timeoutPromise(timeout) {
|
|
188
|
+
return new Promise((_, reject) => {
|
|
189
|
+
setTimeout(() => {
|
|
190
|
+
reject(new Error(`Operation timed out after ${timeout}ms`));
|
|
191
|
+
}, timeout);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Clean up old call records
|
|
196
|
+
*/
|
|
197
|
+
cleanupCallHistory() {
|
|
198
|
+
const cutoffTime = Date.now() - this.config.statisticsWindowSize;
|
|
199
|
+
const originalLength = this.callHistory.length;
|
|
200
|
+
this.callHistory = this.callHistory.filter((call) => call.timestamp >= cutoffTime);
|
|
201
|
+
const removed = originalLength - this.callHistory.length;
|
|
202
|
+
if (removed > 0) {
|
|
203
|
+
logger.debug(`[RAGCircuitBreaker:${this.name}] Cleaned up ${removed} old call records`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Calculate percentile latency
|
|
208
|
+
*/
|
|
209
|
+
calculatePercentileLatency(percentile) {
|
|
210
|
+
if (this.callHistory.length === 0) {
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
const sortedDurations = this.callHistory
|
|
214
|
+
.filter((call) => call.success)
|
|
215
|
+
.map((call) => call.duration)
|
|
216
|
+
.sort((a, b) => a - b);
|
|
217
|
+
if (sortedDurations.length === 0) {
|
|
218
|
+
return 0;
|
|
219
|
+
}
|
|
220
|
+
const index = Math.ceil((percentile / 100) * sortedDurations.length) - 1;
|
|
221
|
+
return sortedDurations[Math.max(0, index)] ?? 0;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get current statistics
|
|
225
|
+
*/
|
|
226
|
+
getStats() {
|
|
227
|
+
const windowStart = Date.now() - this.config.statisticsWindowSize;
|
|
228
|
+
const windowCalls = this.callHistory.filter((call) => call.timestamp >= windowStart);
|
|
229
|
+
const successfulCalls = windowCalls.filter((call) => call.success).length;
|
|
230
|
+
const failedCalls = windowCalls.length - successfulCalls;
|
|
231
|
+
const failureRate = windowCalls.length > 0 ? failedCalls / windowCalls.length : 0;
|
|
232
|
+
// Calculate average latency for successful calls
|
|
233
|
+
const successfulDurations = windowCalls
|
|
234
|
+
.filter((call) => call.success)
|
|
235
|
+
.map((call) => call.duration);
|
|
236
|
+
const averageLatency = successfulDurations.length > 0
|
|
237
|
+
? successfulDurations.reduce((a, b) => a + b, 0) /
|
|
238
|
+
successfulDurations.length
|
|
239
|
+
: 0;
|
|
240
|
+
return {
|
|
241
|
+
state: this.state,
|
|
242
|
+
totalCalls: this.callHistory.length,
|
|
243
|
+
successfulCalls: this.callHistory.filter((call) => call.success).length,
|
|
244
|
+
failedCalls: this.callHistory.filter((call) => !call.success).length,
|
|
245
|
+
failureRate,
|
|
246
|
+
windowCalls: windowCalls.length,
|
|
247
|
+
lastStateChange: this.lastStateChange,
|
|
248
|
+
nextRetryTime: this.state === "open"
|
|
249
|
+
? new Date(this.lastFailureTime + this.config.resetTimeout)
|
|
250
|
+
: undefined,
|
|
251
|
+
halfOpenCalls: this.halfOpenCalls,
|
|
252
|
+
averageLatency,
|
|
253
|
+
p95Latency: this.calculatePercentileLatency(95),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Manually reset the circuit breaker
|
|
258
|
+
*/
|
|
259
|
+
reset() {
|
|
260
|
+
this.changeState("closed", "Manual reset");
|
|
261
|
+
this.callHistory = [];
|
|
262
|
+
this.lastFailureTime = 0;
|
|
263
|
+
this.halfOpenCalls = 0;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Force open the circuit breaker
|
|
267
|
+
*/
|
|
268
|
+
forceOpen(reason = "Manual force open") {
|
|
269
|
+
this.changeState("open", reason);
|
|
270
|
+
this.lastFailureTime = Date.now();
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Get circuit breaker name
|
|
274
|
+
*/
|
|
275
|
+
getName() {
|
|
276
|
+
return this.name;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Check if circuit is open
|
|
280
|
+
*/
|
|
281
|
+
isOpen() {
|
|
282
|
+
return this.state === "open";
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Check if circuit is closed
|
|
286
|
+
*/
|
|
287
|
+
isClosed() {
|
|
288
|
+
return this.state === "closed";
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Check if circuit is half-open
|
|
292
|
+
*/
|
|
293
|
+
isHalfOpen() {
|
|
294
|
+
return this.state === "half-open";
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get current state
|
|
298
|
+
*/
|
|
299
|
+
getState() {
|
|
300
|
+
return this.state;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Destroy the circuit breaker and clean up resources
|
|
304
|
+
*/
|
|
305
|
+
destroy() {
|
|
306
|
+
if (this.cleanupTimer) {
|
|
307
|
+
clearInterval(this.cleanupTimer);
|
|
308
|
+
this.cleanupTimer = undefined;
|
|
309
|
+
}
|
|
310
|
+
this.removeAllListeners();
|
|
311
|
+
this.callHistory = [];
|
|
312
|
+
logger.debug(`[RAGCircuitBreaker:${this.name}] Destroyed`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Circuit breaker manager for RAG operations
|
|
317
|
+
*/
|
|
318
|
+
export class RAGCircuitBreakerManager {
|
|
319
|
+
breakers = new Map();
|
|
320
|
+
/**
|
|
321
|
+
* Get or create a circuit breaker
|
|
322
|
+
*/
|
|
323
|
+
getBreaker(name, config) {
|
|
324
|
+
if (!this.breakers.has(name)) {
|
|
325
|
+
const breaker = new RAGCircuitBreaker(name, config);
|
|
326
|
+
this.breakers.set(name, breaker);
|
|
327
|
+
logger.debug(`[RAGCircuitBreakerManager] Created circuit breaker: ${name}`);
|
|
328
|
+
}
|
|
329
|
+
const breaker = this.breakers.get(name);
|
|
330
|
+
if (!breaker) {
|
|
331
|
+
throw new Error(`Circuit breaker ${name} not found after creation`);
|
|
332
|
+
}
|
|
333
|
+
return breaker;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Remove a circuit breaker
|
|
337
|
+
*/
|
|
338
|
+
removeBreaker(name) {
|
|
339
|
+
const breaker = this.breakers.get(name);
|
|
340
|
+
if (breaker) {
|
|
341
|
+
breaker.destroy();
|
|
342
|
+
this.breakers.delete(name);
|
|
343
|
+
logger.debug(`[RAGCircuitBreakerManager] Removed circuit breaker: ${name}`);
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Get all circuit breaker names
|
|
350
|
+
*/
|
|
351
|
+
getBreakerNames() {
|
|
352
|
+
return Array.from(this.breakers.keys());
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Get statistics for all circuit breakers
|
|
356
|
+
*/
|
|
357
|
+
getAllStats() {
|
|
358
|
+
const stats = {};
|
|
359
|
+
for (const [name, breaker] of this.breakers) {
|
|
360
|
+
stats[name] = breaker.getStats();
|
|
361
|
+
}
|
|
362
|
+
return stats;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Reset all circuit breakers
|
|
366
|
+
*/
|
|
367
|
+
resetAll() {
|
|
368
|
+
for (const breaker of this.breakers.values()) {
|
|
369
|
+
breaker.reset();
|
|
370
|
+
}
|
|
371
|
+
logger.info("[RAGCircuitBreakerManager] Reset all circuit breakers");
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Get health summary
|
|
375
|
+
*/
|
|
376
|
+
getHealthSummary() {
|
|
377
|
+
let closedBreakers = 0;
|
|
378
|
+
let openBreakers = 0;
|
|
379
|
+
let halfOpenBreakers = 0;
|
|
380
|
+
const unhealthyBreakers = [];
|
|
381
|
+
for (const [name, breaker] of this.breakers) {
|
|
382
|
+
const state = breaker.getState();
|
|
383
|
+
switch (state) {
|
|
384
|
+
case "closed":
|
|
385
|
+
closedBreakers++;
|
|
386
|
+
break;
|
|
387
|
+
case "open":
|
|
388
|
+
openBreakers++;
|
|
389
|
+
unhealthyBreakers.push(name);
|
|
390
|
+
break;
|
|
391
|
+
case "half-open":
|
|
392
|
+
halfOpenBreakers++;
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
totalBreakers: this.breakers.size,
|
|
398
|
+
closedBreakers,
|
|
399
|
+
openBreakers,
|
|
400
|
+
halfOpenBreakers,
|
|
401
|
+
unhealthyBreakers,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Destroy all circuit breakers
|
|
406
|
+
*/
|
|
407
|
+
destroyAll() {
|
|
408
|
+
for (const breaker of this.breakers.values()) {
|
|
409
|
+
breaker.destroy();
|
|
410
|
+
}
|
|
411
|
+
this.breakers.clear();
|
|
412
|
+
logger.info("[RAGCircuitBreakerManager] Destroyed all circuit breakers");
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Global circuit breaker manager for RAG operations
|
|
417
|
+
*/
|
|
418
|
+
export const ragCircuitBreakerManager = new RAGCircuitBreakerManager();
|
|
419
|
+
/**
|
|
420
|
+
* Convenience function to get a circuit breaker
|
|
421
|
+
*/
|
|
422
|
+
export function getCircuitBreaker(name, config) {
|
|
423
|
+
return ragCircuitBreakerManager.getBreaker(name, config);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Convenience function to execute with circuit breaker
|
|
427
|
+
*/
|
|
428
|
+
export async function executeWithCircuitBreaker(breakerName, operation, operationType, config) {
|
|
429
|
+
const breaker = ragCircuitBreakerManager.getBreaker(breakerName, config);
|
|
430
|
+
return breaker.execute(operation, operationType);
|
|
431
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RAG Retry Handler
|
|
3
|
+
*
|
|
4
|
+
* Provides retry logic with exponential backoff and jitter
|
|
5
|
+
* specifically designed for RAG operations including embeddings,
|
|
6
|
+
* vector queries, and LLM-based extraction.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* RAG-specific retry configuration
|
|
10
|
+
*/
|
|
11
|
+
export interface RAGRetryConfig {
|
|
12
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
13
|
+
maxRetries: number;
|
|
14
|
+
/** Initial delay in ms (default: 1000) */
|
|
15
|
+
initialDelay: number;
|
|
16
|
+
/** Maximum delay in ms (default: 30000) */
|
|
17
|
+
maxDelay: number;
|
|
18
|
+
/** Backoff multiplier (default: 2) */
|
|
19
|
+
backoffMultiplier: number;
|
|
20
|
+
/** Whether to add jitter (default: true) */
|
|
21
|
+
jitter: boolean;
|
|
22
|
+
/** Custom function to determine if error is retryable */
|
|
23
|
+
shouldRetry?: (error: Error) => boolean;
|
|
24
|
+
/** Retryable error codes */
|
|
25
|
+
retryableErrorCodes?: string[];
|
|
26
|
+
/** Retryable HTTP status codes */
|
|
27
|
+
retryableStatusCodes?: number[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Default retry configuration
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEFAULT_RAG_RETRY_CONFIG: RAGRetryConfig;
|
|
33
|
+
/**
|
|
34
|
+
* Check if an error is retryable based on configuration
|
|
35
|
+
*/
|
|
36
|
+
export declare function isRetryable(error: unknown, config?: RAGRetryConfig): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Execute a RAG operation with retry logic
|
|
39
|
+
*
|
|
40
|
+
* Implements exponential backoff with jitter to prevent thundering herd.
|
|
41
|
+
* Only retries on errors that are considered retryable.
|
|
42
|
+
*
|
|
43
|
+
* @param operation - Async operation to execute with retries
|
|
44
|
+
* @param config - Partial retry configuration (merged with defaults)
|
|
45
|
+
* @returns Result of the operation
|
|
46
|
+
* @throws Last error if all retry attempts fail
|
|
47
|
+
*/
|
|
48
|
+
export declare function withRAGRetry<T>(operation: () => Promise<T>, config?: Partial<RAGRetryConfig>): Promise<T>;
|
|
49
|
+
/**
|
|
50
|
+
* RAG Retry Handler class for more complex retry scenarios
|
|
51
|
+
*/
|
|
52
|
+
export declare class RAGRetryHandler {
|
|
53
|
+
private config;
|
|
54
|
+
constructor(config?: Partial<RAGRetryConfig>);
|
|
55
|
+
/**
|
|
56
|
+
* Execute an operation with retry logic
|
|
57
|
+
*/
|
|
58
|
+
executeWithRetry<T>(operation: () => Promise<T>, maxRetries?: number): Promise<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Execute multiple operations with retry, collecting results
|
|
61
|
+
* Returns successful results and failed operations with their errors
|
|
62
|
+
*/
|
|
63
|
+
executeBatch<T, R>(items: T[], operation: (item: T, index: number) => Promise<R>, options?: {
|
|
64
|
+
concurrency?: number;
|
|
65
|
+
continueOnError?: boolean;
|
|
66
|
+
}): Promise<{
|
|
67
|
+
successful: Array<{
|
|
68
|
+
item: T;
|
|
69
|
+
result: R;
|
|
70
|
+
index: number;
|
|
71
|
+
}>;
|
|
72
|
+
failed: Array<{
|
|
73
|
+
item: T;
|
|
74
|
+
error: Error;
|
|
75
|
+
index: number;
|
|
76
|
+
}>;
|
|
77
|
+
successRate: number;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Get current configuration
|
|
81
|
+
*/
|
|
82
|
+
getConfig(): RAGRetryConfig;
|
|
83
|
+
/**
|
|
84
|
+
* Update configuration
|
|
85
|
+
*/
|
|
86
|
+
updateConfig(config: Partial<RAGRetryConfig>): void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Specialized retry handler for embedding operations
|
|
90
|
+
*/
|
|
91
|
+
export declare class EmbeddingRetryHandler extends RAGRetryHandler {
|
|
92
|
+
constructor(config?: Partial<RAGRetryConfig>);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Specialized retry handler for vector store operations
|
|
96
|
+
*/
|
|
97
|
+
export declare class VectorStoreRetryHandler extends RAGRetryHandler {
|
|
98
|
+
constructor(config?: Partial<RAGRetryConfig>);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Specialized retry handler for metadata extraction
|
|
102
|
+
*/
|
|
103
|
+
export declare class MetadataExtractionRetryHandler extends RAGRetryHandler {
|
|
104
|
+
constructor(config?: Partial<RAGRetryConfig>);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Create a retry handler with the core infrastructure withRetry
|
|
108
|
+
*/
|
|
109
|
+
export declare function createRetryHandler(config?: Partial<RAGRetryConfig>): (operation: () => Promise<unknown>) => Promise<unknown>;
|
|
110
|
+
/**
|
|
111
|
+
* Global retry handlers for common RAG operations
|
|
112
|
+
*/
|
|
113
|
+
export declare const embeddingRetryHandler: EmbeddingRetryHandler;
|
|
114
|
+
export declare const vectorStoreRetryHandler: VectorStoreRetryHandler;
|
|
115
|
+
export declare const metadataExtractionRetryHandler: MetadataExtractionRetryHandler;
|