@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,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Processing Error Helpers
|
|
3
|
+
*
|
|
4
|
+
* Utilities for creating consistent, user-friendly file processing errors.
|
|
5
|
+
* Provides factory functions for structured errors, retry determination logic,
|
|
6
|
+
* and HTTP status extraction.
|
|
7
|
+
*
|
|
8
|
+
* @module processors/errors
|
|
9
|
+
*/
|
|
10
|
+
import { ERROR_MESSAGES, FileErrorCode, } from "./FileErrorCode.js";
|
|
11
|
+
/**
|
|
12
|
+
* Create a structured file processing error with user-friendly messaging.
|
|
13
|
+
*
|
|
14
|
+
* @param code - The error code from FileErrorCode enum
|
|
15
|
+
* @param details - Additional context for the error (e.g., file size, format)
|
|
16
|
+
* @param originalError - The original error that caused this failure
|
|
17
|
+
* @returns A structured FileProcessingError with user-friendly messaging
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const error = createFileError(FileErrorCode.FILE_TOO_LARGE, {
|
|
22
|
+
* sizeMB: "15.5",
|
|
23
|
+
* maxMB: "10",
|
|
24
|
+
* filename: "large-document.pdf",
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function createFileError(code, details, originalError) {
|
|
29
|
+
const template = ERROR_MESSAGES[code];
|
|
30
|
+
const result = {
|
|
31
|
+
code,
|
|
32
|
+
message: template.message,
|
|
33
|
+
userMessage: template.userMessage,
|
|
34
|
+
suggestedAction: template.suggestedAction,
|
|
35
|
+
retryable: template.retryable,
|
|
36
|
+
};
|
|
37
|
+
// Add details if provided
|
|
38
|
+
if (details && Object.keys(details).length > 0) {
|
|
39
|
+
result.details = details;
|
|
40
|
+
}
|
|
41
|
+
// Add technical details from original error
|
|
42
|
+
const technicalDetails = originalError?.message || details?.technicalDetails;
|
|
43
|
+
if (technicalDetails) {
|
|
44
|
+
result.technicalDetails = technicalDetails;
|
|
45
|
+
}
|
|
46
|
+
if (originalError) {
|
|
47
|
+
result.originalError = originalError;
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a file processing error with custom messages.
|
|
53
|
+
* Useful when you need to override the default messages with context-specific ones.
|
|
54
|
+
*
|
|
55
|
+
* @param code - The error code from FileErrorCode enum
|
|
56
|
+
* @param customMessage - Custom technical message
|
|
57
|
+
* @param customUserMessage - Custom user-friendly message
|
|
58
|
+
* @param details - Additional context
|
|
59
|
+
* @returns A structured FileProcessingError
|
|
60
|
+
*/
|
|
61
|
+
export function createCustomFileError(code, customMessage, customUserMessage, details) {
|
|
62
|
+
const template = ERROR_MESSAGES[code];
|
|
63
|
+
return {
|
|
64
|
+
code,
|
|
65
|
+
message: customMessage,
|
|
66
|
+
userMessage: customUserMessage,
|
|
67
|
+
suggestedAction: template.suggestedAction,
|
|
68
|
+
retryable: template.retryable,
|
|
69
|
+
details,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Extract HTTP status code from various error types.
|
|
74
|
+
*
|
|
75
|
+
* @param error - The error to extract status from
|
|
76
|
+
* @returns The HTTP status code if found, null otherwise
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const status = extractHttpStatus(error);
|
|
81
|
+
* if (status === 404) {
|
|
82
|
+
* // Handle not found
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export function extractHttpStatus(error) {
|
|
87
|
+
if (!error) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
// Check for Error objects with HTTP status in message
|
|
91
|
+
if (error instanceof Error) {
|
|
92
|
+
// Match patterns like "HTTP 404", "status: 500", "statusCode: 503"
|
|
93
|
+
const patterns = [
|
|
94
|
+
/HTTP\s*(\d{3})/i,
|
|
95
|
+
/status[:\s]+(\d{3})/i,
|
|
96
|
+
/statusCode[:\s]+(\d{3})/i,
|
|
97
|
+
/\b(\d{3})\s+(?:Not Found|Unauthorized|Forbidden|Internal Server Error|Bad Gateway|Service Unavailable|Gateway Timeout)/i,
|
|
98
|
+
];
|
|
99
|
+
for (const pattern of patterns) {
|
|
100
|
+
const match = error.message.match(pattern);
|
|
101
|
+
if (match?.[1]) {
|
|
102
|
+
return parseInt(match[1], 10);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Check for objects with status or statusCode property
|
|
107
|
+
if (typeof error === "object" && error !== null) {
|
|
108
|
+
const errorObj = error;
|
|
109
|
+
if (typeof errorObj.status === "number") {
|
|
110
|
+
return errorObj.status;
|
|
111
|
+
}
|
|
112
|
+
if (typeof errorObj.statusCode === "number") {
|
|
113
|
+
return errorObj.statusCode;
|
|
114
|
+
}
|
|
115
|
+
if (typeof errorObj.response === "object" && errorObj.response !== null) {
|
|
116
|
+
const response = errorObj.response;
|
|
117
|
+
if (typeof response.status === "number") {
|
|
118
|
+
return response.status;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Determine if an error is retryable based on error type and characteristics.
|
|
126
|
+
* Checks for transient errors like 5xx, network errors, and timeouts.
|
|
127
|
+
*
|
|
128
|
+
* @param error - The error to check
|
|
129
|
+
* @returns true if the error is transient and potentially retryable
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* if (isRetryableError(error) && retryCount < maxRetries) {
|
|
134
|
+
* await delay(backoffMs);
|
|
135
|
+
* return retry();
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export function isRetryableError(error) {
|
|
140
|
+
// Check FileProcessingError
|
|
141
|
+
if (isFileProcessingError(error)) {
|
|
142
|
+
return error.retryable ?? false;
|
|
143
|
+
}
|
|
144
|
+
if (error instanceof Error) {
|
|
145
|
+
// Network/timeout errors are retryable
|
|
146
|
+
const retryableNames = ["AbortError", "TimeoutError", "FetchError"];
|
|
147
|
+
if (retryableNames.includes(error.name)) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
const message = error.message.toLowerCase();
|
|
151
|
+
// HTTP 5xx server errors are retryable
|
|
152
|
+
if (/http\s*5\d{2}/i.test(error.message)) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
// HTTP 429 (rate limiting) is retryable
|
|
156
|
+
if (/http\s*429/i.test(error.message) || message.includes("rate limit")) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
// HTTP 408 (request timeout) is retryable
|
|
160
|
+
if (/http\s*408/i.test(error.message)) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
// Connection errors are retryable
|
|
164
|
+
const connectionPatterns = [
|
|
165
|
+
"econnreset",
|
|
166
|
+
"etimedout",
|
|
167
|
+
"econnrefused",
|
|
168
|
+
"enotfound",
|
|
169
|
+
"enetunreach",
|
|
170
|
+
"ehostunreach",
|
|
171
|
+
"epipe",
|
|
172
|
+
"socket hang up",
|
|
173
|
+
"network error",
|
|
174
|
+
"connection refused",
|
|
175
|
+
"connection reset",
|
|
176
|
+
"dns lookup failed",
|
|
177
|
+
];
|
|
178
|
+
if (connectionPatterns.some((pattern) => message.includes(pattern))) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
// Temporary/transient errors are retryable
|
|
182
|
+
if (message.includes("temporary") || message.includes("try again")) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Check HTTP status from error object
|
|
187
|
+
const status = extractHttpStatus(error);
|
|
188
|
+
if (status !== null) {
|
|
189
|
+
// 5xx errors (server errors) are retryable
|
|
190
|
+
if (status >= 500 && status < 600) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
// 408 (Request Timeout) and 429 (Too Many Requests) are retryable
|
|
194
|
+
if (status === 408 || status === 429) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Type guard to check if an error is a FileProcessingError.
|
|
202
|
+
*
|
|
203
|
+
* @param error - The value to check
|
|
204
|
+
* @returns true if error is a FileProcessingError
|
|
205
|
+
*/
|
|
206
|
+
export function isFileProcessingError(error) {
|
|
207
|
+
if (typeof error !== "object" || error === null) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
const e = error;
|
|
211
|
+
return (typeof e.code === "string" &&
|
|
212
|
+
typeof e.message === "string" &&
|
|
213
|
+
typeof e.userMessage === "string" &&
|
|
214
|
+
typeof e.retryable === "boolean");
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Map an error to the appropriate FileErrorCode based on its characteristics.
|
|
218
|
+
*
|
|
219
|
+
* @param error - The error to analyze
|
|
220
|
+
* @returns The most appropriate FileErrorCode
|
|
221
|
+
*/
|
|
222
|
+
export function mapErrorToCode(error) {
|
|
223
|
+
if (!error) {
|
|
224
|
+
return FileErrorCode.UNKNOWN_ERROR;
|
|
225
|
+
}
|
|
226
|
+
// Check HTTP status first
|
|
227
|
+
const status = extractHttpStatus(error);
|
|
228
|
+
if (status !== null) {
|
|
229
|
+
if (status === 401 || status === 403) {
|
|
230
|
+
return FileErrorCode.DOWNLOAD_AUTH_FAILED;
|
|
231
|
+
}
|
|
232
|
+
if (status === 404) {
|
|
233
|
+
return FileErrorCode.FILE_NOT_FOUND;
|
|
234
|
+
}
|
|
235
|
+
if (status === 408) {
|
|
236
|
+
return FileErrorCode.DOWNLOAD_TIMEOUT;
|
|
237
|
+
}
|
|
238
|
+
if (status === 429) {
|
|
239
|
+
return FileErrorCode.RATE_LIMITED;
|
|
240
|
+
}
|
|
241
|
+
if (status >= 500) {
|
|
242
|
+
return FileErrorCode.DOWNLOAD_FAILED;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (error instanceof Error) {
|
|
246
|
+
const message = error.message.toLowerCase();
|
|
247
|
+
const name = error.name;
|
|
248
|
+
// Timeout errors
|
|
249
|
+
if (name === "AbortError" ||
|
|
250
|
+
name === "TimeoutError" ||
|
|
251
|
+
message.includes("timeout")) {
|
|
252
|
+
return FileErrorCode.DOWNLOAD_TIMEOUT;
|
|
253
|
+
}
|
|
254
|
+
// Network errors
|
|
255
|
+
if (message.includes("econnreset") ||
|
|
256
|
+
message.includes("econnrefused") ||
|
|
257
|
+
message.includes("network") ||
|
|
258
|
+
message.includes("socket")) {
|
|
259
|
+
return FileErrorCode.NETWORK_ERROR;
|
|
260
|
+
}
|
|
261
|
+
// Size errors
|
|
262
|
+
if (message.includes("too large") || message.includes("size limit")) {
|
|
263
|
+
return FileErrorCode.FILE_TOO_LARGE;
|
|
264
|
+
}
|
|
265
|
+
// Format/type errors
|
|
266
|
+
if (message.includes("unsupported") || message.includes("not supported")) {
|
|
267
|
+
return FileErrorCode.UNSUPPORTED_TYPE;
|
|
268
|
+
}
|
|
269
|
+
if (message.includes("invalid format") || message.includes("malformed")) {
|
|
270
|
+
return FileErrorCode.INVALID_FORMAT;
|
|
271
|
+
}
|
|
272
|
+
if (message.includes("corrupt")) {
|
|
273
|
+
return FileErrorCode.CORRUPTED_FILE;
|
|
274
|
+
}
|
|
275
|
+
// Parsing errors
|
|
276
|
+
if (message.includes("parse") || message.includes("syntax")) {
|
|
277
|
+
return FileErrorCode.PARSING_FAILED;
|
|
278
|
+
}
|
|
279
|
+
// Encoding errors
|
|
280
|
+
if (message.includes("encoding") ||
|
|
281
|
+
message.includes("utf") ||
|
|
282
|
+
message.includes("decode")) {
|
|
283
|
+
return FileErrorCode.ENCODING_ERROR;
|
|
284
|
+
}
|
|
285
|
+
// Security errors
|
|
286
|
+
if (message.includes("xxe") || message.includes("doctype")) {
|
|
287
|
+
return FileErrorCode.XXE_DETECTED;
|
|
288
|
+
}
|
|
289
|
+
if (message.includes("xss") || message.includes("script")) {
|
|
290
|
+
return FileErrorCode.XSS_DETECTED;
|
|
291
|
+
}
|
|
292
|
+
if (message.includes("zip bomb") || message.includes("compression ratio")) {
|
|
293
|
+
return FileErrorCode.ZIP_BOMB_DETECTED;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return FileErrorCode.UNKNOWN_ERROR;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Format a file processing error for display to users.
|
|
300
|
+
*
|
|
301
|
+
* @param error - The FileProcessingError to format
|
|
302
|
+
* @returns A formatted string suitable for display
|
|
303
|
+
*/
|
|
304
|
+
export function formatFileError(error) {
|
|
305
|
+
let message = error.userMessage;
|
|
306
|
+
if (error.suggestedAction) {
|
|
307
|
+
message += `\n${error.suggestedAction}`;
|
|
308
|
+
}
|
|
309
|
+
return message;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Create a processing summary from arrays of results.
|
|
313
|
+
*
|
|
314
|
+
* @param totalFiles - Total number of files attempted
|
|
315
|
+
* @param processedFiles - Successfully processed files
|
|
316
|
+
* @param failedFiles - Files that failed to process
|
|
317
|
+
* @param skippedFiles - Files that were skipped
|
|
318
|
+
* @param warnings - Non-fatal warnings
|
|
319
|
+
* @returns A FileProcessingSummary object
|
|
320
|
+
*/
|
|
321
|
+
export function createProcessingSummary(totalFiles, processedFiles = [], failedFiles = [], skippedFiles = [], warnings = []) {
|
|
322
|
+
return {
|
|
323
|
+
totalFiles,
|
|
324
|
+
processedFiles,
|
|
325
|
+
failedFiles,
|
|
326
|
+
skippedFiles,
|
|
327
|
+
warnings,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Combine multiple processing summaries into one.
|
|
332
|
+
* Useful when processing different file types separately.
|
|
333
|
+
*
|
|
334
|
+
* @param summaries - Array of summaries to combine
|
|
335
|
+
* @returns A combined FileProcessingSummary
|
|
336
|
+
*/
|
|
337
|
+
export function combineSummaries(summaries) {
|
|
338
|
+
return summaries.reduce((combined, summary) => ({
|
|
339
|
+
totalFiles: combined.totalFiles + summary.totalFiles,
|
|
340
|
+
processedFiles: [...combined.processedFiles, ...summary.processedFiles],
|
|
341
|
+
failedFiles: [...combined.failedFiles, ...summary.failedFiles],
|
|
342
|
+
skippedFiles: [...combined.skippedFiles, ...summary.skippedFiles],
|
|
343
|
+
warnings: [...combined.warnings, ...summary.warnings],
|
|
344
|
+
}), createProcessingSummary(0));
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Get retry delay based on error type and attempt number.
|
|
348
|
+
* Implements exponential backoff with jitter.
|
|
349
|
+
*
|
|
350
|
+
* @param error - The error that occurred
|
|
351
|
+
* @param attempt - Current attempt number (1-based)
|
|
352
|
+
* @param baseDelayMs - Base delay in milliseconds (default: 1000)
|
|
353
|
+
* @returns Delay in milliseconds before next retry
|
|
354
|
+
*/
|
|
355
|
+
export function getRetryDelay(error, attempt, baseDelayMs = 1000) {
|
|
356
|
+
// Check for rate limit with Retry-After header
|
|
357
|
+
if (typeof error === "object" && error !== null) {
|
|
358
|
+
const errorObj = error;
|
|
359
|
+
const retryAfter = (errorObj.retryAfter ??
|
|
360
|
+
errorObj["retry-after"]);
|
|
361
|
+
if (typeof retryAfter === "number") {
|
|
362
|
+
return retryAfter * 1000;
|
|
363
|
+
}
|
|
364
|
+
if (typeof retryAfter === "string") {
|
|
365
|
+
const parsed = Number(retryAfter);
|
|
366
|
+
if (!Number.isNaN(parsed)) {
|
|
367
|
+
return parsed * 1000;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
// Exponential backoff: base * 2^(attempt-1)
|
|
372
|
+
const safeAttempt = Math.max(1, attempt);
|
|
373
|
+
const exponentialDelay = baseDelayMs * 2 ** (safeAttempt - 1);
|
|
374
|
+
// Add jitter (0-25% of delay)
|
|
375
|
+
const jitter = exponentialDelay * 0.25 * Math.random();
|
|
376
|
+
// Cap at 30 seconds
|
|
377
|
+
return Math.min(exponentialDelay + jitter, 30000);
|
|
378
|
+
}
|
|
379
|
+
//# sourceMappingURL=errorHelpers.js.map
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Serializer Utility
|
|
3
|
+
*
|
|
4
|
+
* Safe error serialization with full context preservation.
|
|
5
|
+
* Features:
|
|
6
|
+
* - Handles circular references
|
|
7
|
+
* - Filters sensitive data (PII, credentials)
|
|
8
|
+
* - Generates error fingerprints for deduplication
|
|
9
|
+
* - Preserves custom error properties
|
|
10
|
+
* - Filters stack traces in production
|
|
11
|
+
*
|
|
12
|
+
* @module processors/errors
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Serialized error representation with full context.
|
|
16
|
+
*/
|
|
17
|
+
export interface SerializedError {
|
|
18
|
+
/** Unique error instance ID */
|
|
19
|
+
errorId: string;
|
|
20
|
+
/** Deterministic fingerprint for error aggregation */
|
|
21
|
+
errorFingerprint: string;
|
|
22
|
+
/** Error type/class name */
|
|
23
|
+
errorType: string;
|
|
24
|
+
/** Error message */
|
|
25
|
+
message: string;
|
|
26
|
+
/** Full stack trace */
|
|
27
|
+
stack?: string;
|
|
28
|
+
/** Parsed stack frames */
|
|
29
|
+
stackFrames?: string[];
|
|
30
|
+
/** HTTP status code if applicable */
|
|
31
|
+
statusCode?: number;
|
|
32
|
+
/** Whether the error is operational (expected) vs programmer error */
|
|
33
|
+
isOperational?: boolean;
|
|
34
|
+
/** Whether the error is retryable */
|
|
35
|
+
isRetryable?: boolean;
|
|
36
|
+
/** Error code */
|
|
37
|
+
code?: string;
|
|
38
|
+
/** Additional metadata */
|
|
39
|
+
metadata?: Record<string, unknown>;
|
|
40
|
+
/** Serialized cause error (for error chaining) */
|
|
41
|
+
cause?: SerializedError;
|
|
42
|
+
/** ISO timestamp of when the error was serialized */
|
|
43
|
+
timestamp: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Options for error serialization.
|
|
47
|
+
*/
|
|
48
|
+
export interface SerializeOptions {
|
|
49
|
+
/** Include stack trace in output (default: true) */
|
|
50
|
+
includeStack?: boolean;
|
|
51
|
+
/** Max depth for nested object serialization (default: 5) */
|
|
52
|
+
maxDepth?: number;
|
|
53
|
+
/** Filter stack traces to application frames only (default: true in production) */
|
|
54
|
+
filterStacks?: boolean;
|
|
55
|
+
/** Additional context to include */
|
|
56
|
+
context?: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Safely serialize an error with full context preservation.
|
|
60
|
+
* Handles circular references, redacts sensitive data, and preserves error metadata.
|
|
61
|
+
*
|
|
62
|
+
* @param error - Error instance or unknown value to serialize
|
|
63
|
+
* @param options - Serialization options
|
|
64
|
+
* @returns Serialized error with full context
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* try {
|
|
69
|
+
* await riskyOperation();
|
|
70
|
+
* } catch (error) {
|
|
71
|
+
* const serialized = serializeError(error);
|
|
72
|
+
* logger.error("Operation failed", serialized);
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function serializeError(error: unknown, options?: SerializeOptions): SerializedError;
|
|
77
|
+
/**
|
|
78
|
+
* Generate a deterministic fingerprint for error aggregation.
|
|
79
|
+
* Normalizes dynamic values (IDs, timestamps, paths) to group similar errors together.
|
|
80
|
+
*
|
|
81
|
+
* @param error - Error to fingerprint
|
|
82
|
+
* @param context - Optional context with operation name
|
|
83
|
+
* @returns 16-character hex fingerprint hash
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const fp1 = generateErrorFingerprint(new Error("User 123 not found"));
|
|
88
|
+
* const fp2 = generateErrorFingerprint(new Error("User 456 not found"));
|
|
89
|
+
* // fp1 === fp2 (same error pattern, different IDs)
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function generateErrorFingerprint(error: Error, context?: {
|
|
93
|
+
operation?: string;
|
|
94
|
+
}): string;
|
|
95
|
+
/**
|
|
96
|
+
* Safely stringify an object with circular reference handling.
|
|
97
|
+
*
|
|
98
|
+
* @param obj - Object to stringify
|
|
99
|
+
* @param maxDepth - Maximum depth for nested objects
|
|
100
|
+
* @returns JSON string representation
|
|
101
|
+
*/
|
|
102
|
+
export declare function safeStringify(obj: unknown, maxDepth?: number): string;
|
|
103
|
+
/**
|
|
104
|
+
* Extract safe metadata from an object.
|
|
105
|
+
* Sanitizes sensitive fields and handles truncation.
|
|
106
|
+
*
|
|
107
|
+
* @param obj - Object to extract metadata from
|
|
108
|
+
* @param options - Extraction options
|
|
109
|
+
* @returns Sanitized metadata record
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const metadata = extractSafeMetadata({
|
|
114
|
+
* userId: "123",
|
|
115
|
+
* password: "secret",
|
|
116
|
+
* data: largeObject,
|
|
117
|
+
* });
|
|
118
|
+
* // Result: { userId: "123", password: "[REDACTED]", data: truncated }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function extractSafeMetadata(obj: unknown, options?: {
|
|
122
|
+
/** Maximum size per field */
|
|
123
|
+
maxSize?: number;
|
|
124
|
+
/** Maximum depth for nested objects */
|
|
125
|
+
maxDepth?: number;
|
|
126
|
+
}): Record<string, unknown>;
|
|
127
|
+
/**
|
|
128
|
+
* Create a minimal error representation for logging.
|
|
129
|
+
* Useful when you need just the essentials without full serialization.
|
|
130
|
+
*
|
|
131
|
+
* @param error - Error to summarize
|
|
132
|
+
* @returns Minimal error representation
|
|
133
|
+
*/
|
|
134
|
+
export declare function summarizeError(error: unknown): {
|
|
135
|
+
type: string;
|
|
136
|
+
message: string;
|
|
137
|
+
code?: string;
|
|
138
|
+
fingerprint: string;
|
|
139
|
+
};
|