@juspay/neurolink 9.5.2 → 9.6.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 +16 -0
- package/README.md +29 -25
- package/dist/agent/directTools.d.ts +5 -5
- package/dist/cli/commands/config.d.ts +9 -9
- package/dist/cli/commands/serve.d.ts +37 -0
- package/dist/cli/commands/serve.js +302 -229
- package/dist/cli/commands/setup-anthropic.d.ts +2 -2
- package/dist/cli/commands/setup-azure.d.ts +2 -2
- package/dist/cli/commands/setup-bedrock.d.ts +2 -2
- package/dist/cli/commands/setup-gcp.d.ts +2 -2
- package/dist/cli/commands/setup-google-ai.d.ts +2 -2
- package/dist/cli/commands/setup-huggingface.d.ts +2 -2
- package/dist/cli/commands/setup-mistral.d.ts +2 -2
- package/dist/cli/commands/setup-openai.d.ts +2 -2
- package/dist/cli/commands/setup.d.ts +2 -2
- package/dist/cli/factories/commandFactory.js +16 -2
- package/dist/cli/loop/optionsSchema.d.ts +2 -2
- package/dist/cli/loop/session.d.ts +4 -0
- package/dist/cli/loop/session.js +49 -4
- package/dist/cli/utils/interactiveSetup.d.ts +4 -4
- package/dist/config/conversationMemory.d.ts +2 -0
- package/dist/config/conversationMemory.js +5 -5
- package/dist/constants/contextWindows.d.ts +46 -0
- package/dist/constants/contextWindows.js +156 -0
- package/dist/context/budgetChecker.d.ts +18 -0
- package/dist/context/budgetChecker.js +71 -0
- package/dist/context/contextCompactor.d.ts +22 -0
- package/dist/context/contextCompactor.js +106 -0
- package/dist/context/effectiveHistory.d.ts +52 -0
- package/dist/context/effectiveHistory.js +105 -0
- package/dist/context/errorDetection.d.ts +14 -0
- package/dist/context/errorDetection.js +124 -0
- package/dist/context/fileSummarizationService.d.ts +54 -0
- package/dist/context/fileSummarizationService.js +255 -0
- package/dist/context/fileSummarizer.d.ts +56 -0
- package/dist/context/fileSummarizer.js +145 -0
- package/dist/context/fileTokenBudget.d.ts +53 -0
- package/dist/context/fileTokenBudget.js +127 -0
- package/dist/context/prompts/summarizationPrompt.d.ts +17 -0
- package/dist/context/prompts/summarizationPrompt.js +110 -0
- package/dist/context/stages/fileReadDeduplicator.d.ts +10 -0
- package/dist/context/stages/fileReadDeduplicator.js +66 -0
- package/dist/context/stages/slidingWindowTruncator.d.ts +11 -0
- package/dist/context/stages/slidingWindowTruncator.js +42 -0
- package/dist/context/stages/structuredSummarizer.d.ts +10 -0
- package/dist/context/stages/structuredSummarizer.js +49 -0
- package/dist/context/stages/toolOutputPruner.d.ts +10 -0
- package/dist/context/stages/toolOutputPruner.js +52 -0
- package/dist/context/summarizationEngine.d.ts +45 -0
- package/dist/context/summarizationEngine.js +110 -0
- package/dist/context/toolOutputLimits.d.ts +17 -0
- package/dist/context/toolOutputLimits.js +84 -0
- package/dist/context/toolPairRepair.d.ts +16 -0
- package/dist/context/toolPairRepair.js +66 -0
- package/dist/core/conversationMemoryManager.d.ts +5 -15
- package/dist/core/conversationMemoryManager.js +15 -75
- package/dist/core/modules/MessageBuilder.d.ts +1 -1
- package/dist/core/modules/MessageBuilder.js +2 -0
- package/dist/core/modules/TelemetryHandler.d.ts +2 -3
- package/dist/core/modules/TelemetryHandler.js +3 -3
- package/dist/core/modules/ToolsManager.d.ts +2 -2
- package/dist/core/redisConversationMemoryManager.d.ts +8 -14
- package/dist/core/redisConversationMemoryManager.js +69 -78
- package/dist/factories/providerFactory.d.ts +2 -2
- package/dist/files/fileReferenceRegistry.d.ts +276 -0
- package/dist/files/fileReferenceRegistry.js +1543 -0
- package/dist/files/fileTools.d.ts +423 -0
- package/dist/files/fileTools.js +449 -0
- package/dist/files/index.d.ts +14 -0
- package/dist/files/index.js +13 -0
- package/dist/files/streamingReader.d.ts +93 -0
- package/dist/files/streamingReader.js +321 -0
- package/dist/files/types.d.ts +23 -0
- package/dist/files/types.js +23 -0
- package/dist/image-gen/imageGenTools.d.ts +2 -2
- package/dist/image-gen/types.d.ts +12 -12
- package/dist/lib/agent/directTools.d.ts +7 -7
- package/dist/lib/config/conversationMemory.d.ts +2 -0
- package/dist/lib/config/conversationMemory.js +5 -5
- package/dist/lib/constants/contextWindows.d.ts +46 -0
- package/dist/lib/constants/contextWindows.js +157 -0
- package/dist/lib/context/budgetChecker.d.ts +18 -0
- package/dist/lib/context/budgetChecker.js +72 -0
- package/dist/lib/context/contextCompactor.d.ts +22 -0
- package/dist/lib/context/contextCompactor.js +107 -0
- package/dist/lib/context/effectiveHistory.d.ts +52 -0
- package/dist/lib/context/effectiveHistory.js +106 -0
- package/dist/lib/context/errorDetection.d.ts +14 -0
- package/dist/lib/context/errorDetection.js +125 -0
- package/dist/lib/context/fileSummarizationService.d.ts +54 -0
- package/dist/lib/context/fileSummarizationService.js +256 -0
- package/dist/lib/context/fileSummarizer.d.ts +56 -0
- package/dist/lib/context/fileSummarizer.js +146 -0
- package/dist/lib/context/fileTokenBudget.d.ts +53 -0
- package/dist/lib/context/fileTokenBudget.js +128 -0
- package/dist/lib/context/prompts/summarizationPrompt.d.ts +17 -0
- package/dist/lib/context/prompts/summarizationPrompt.js +111 -0
- package/dist/lib/context/stages/fileReadDeduplicator.d.ts +10 -0
- package/dist/lib/context/stages/fileReadDeduplicator.js +67 -0
- package/dist/lib/context/stages/slidingWindowTruncator.d.ts +11 -0
- package/dist/lib/context/stages/slidingWindowTruncator.js +43 -0
- package/dist/lib/context/stages/structuredSummarizer.d.ts +10 -0
- package/dist/lib/context/stages/structuredSummarizer.js +50 -0
- package/dist/lib/context/stages/toolOutputPruner.d.ts +10 -0
- package/dist/lib/context/stages/toolOutputPruner.js +53 -0
- package/dist/lib/context/summarizationEngine.d.ts +45 -0
- package/dist/lib/context/summarizationEngine.js +111 -0
- package/dist/lib/context/toolOutputLimits.d.ts +17 -0
- package/dist/lib/context/toolOutputLimits.js +85 -0
- package/dist/lib/context/toolPairRepair.d.ts +16 -0
- package/dist/lib/context/toolPairRepair.js +67 -0
- package/dist/lib/core/conversationMemoryManager.d.ts +5 -15
- package/dist/lib/core/conversationMemoryManager.js +15 -75
- package/dist/lib/core/modules/MessageBuilder.d.ts +1 -1
- package/dist/lib/core/modules/MessageBuilder.js +2 -0
- package/dist/lib/core/modules/TelemetryHandler.d.ts +2 -3
- package/dist/lib/core/modules/TelemetryHandler.js +3 -3
- package/dist/lib/core/modules/ToolsManager.d.ts +2 -2
- package/dist/lib/core/redisConversationMemoryManager.d.ts +8 -14
- package/dist/lib/core/redisConversationMemoryManager.js +69 -78
- package/dist/lib/factories/providerFactory.d.ts +2 -2
- package/dist/lib/files/fileReferenceRegistry.d.ts +276 -0
- package/dist/lib/files/fileReferenceRegistry.js +1544 -0
- package/dist/lib/files/fileTools.d.ts +423 -0
- package/dist/lib/files/fileTools.js +450 -0
- package/dist/lib/files/index.d.ts +14 -0
- package/dist/lib/files/index.js +14 -0
- package/dist/lib/files/streamingReader.d.ts +93 -0
- package/dist/lib/files/streamingReader.js +322 -0
- package/dist/lib/files/types.d.ts +23 -0
- package/dist/lib/files/types.js +24 -0
- package/dist/lib/image-gen/imageGenTools.d.ts +2 -2
- package/dist/lib/image-gen/types.d.ts +12 -12
- package/dist/lib/memory/mem0Initializer.d.ts +2 -2
- package/dist/lib/neurolink.d.ts +61 -2
- package/dist/lib/neurolink.js +619 -307
- package/dist/lib/processors/archive/ArchiveProcessor.d.ts +327 -0
- package/dist/lib/processors/archive/ArchiveProcessor.js +1309 -0
- package/dist/lib/processors/archive/index.d.ts +33 -0
- package/dist/lib/processors/archive/index.js +43 -0
- package/dist/lib/processors/base/types.d.ts +70 -64
- package/dist/lib/processors/base/types.js +6 -0
- package/dist/lib/processors/cli/fileProcessorCli.d.ts +8 -8
- package/dist/lib/processors/cli/fileProcessorCli.js +5 -5
- package/dist/lib/processors/config/mimeTypes.js +25 -0
- package/dist/lib/processors/config/sizeLimits.d.ts +52 -40
- package/dist/lib/processors/config/sizeLimits.js +56 -44
- package/dist/lib/processors/document/ExcelProcessor.d.ts +14 -0
- package/dist/lib/processors/document/ExcelProcessor.js +72 -1
- package/dist/lib/processors/document/PptxProcessor.d.ts +63 -0
- package/dist/lib/processors/document/PptxProcessor.js +158 -0
- package/dist/lib/processors/document/index.d.ts +1 -0
- package/dist/lib/processors/document/index.js +6 -0
- package/dist/lib/processors/errors/FileErrorCode.d.ts +2 -2
- package/dist/lib/processors/errors/errorHelpers.d.ts +2 -2
- package/dist/lib/processors/errors/errorSerializer.d.ts +4 -4
- package/dist/lib/processors/index.d.ts +8 -2
- package/dist/lib/processors/index.js +5 -2
- package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +8 -8
- package/dist/lib/processors/integration/FileProcessorIntegration.js +7 -7
- package/dist/lib/processors/media/AudioProcessor.d.ts +328 -0
- package/dist/lib/processors/media/AudioProcessor.js +708 -0
- package/dist/lib/processors/media/VideoProcessor.d.ts +350 -0
- package/dist/lib/processors/media/VideoProcessor.js +992 -0
- package/dist/lib/processors/media/index.d.ts +27 -0
- package/dist/lib/processors/media/index.js +37 -0
- package/dist/lib/processors/registry/ProcessorRegistry.d.ts +19 -5
- package/dist/lib/processors/registry/ProcessorRegistry.js +103 -8
- package/dist/lib/processors/registry/index.d.ts +1 -1
- package/dist/lib/processors/registry/index.js +1 -1
- package/dist/lib/processors/registry/types.d.ts +2 -2
- package/dist/lib/providers/googleAiStudio.d.ts +34 -0
- package/dist/lib/providers/googleAiStudio.js +267 -397
- package/dist/lib/providers/googleVertex.d.ts +55 -1
- package/dist/lib/providers/googleVertex.js +452 -719
- package/dist/lib/providers/sagemaker/detection.d.ts +6 -6
- package/dist/lib/providers/sagemaker/diagnostics.d.ts +4 -4
- package/dist/lib/providers/sagemaker/parsers.d.ts +4 -4
- package/dist/lib/rag/chunkers/RecursiveChunker.js +2 -2
- package/dist/lib/rag/document/loaders.d.ts +6 -71
- package/dist/lib/rag/document/loaders.js +5 -5
- package/dist/lib/rag/graphRag/graphRAG.js +26 -9
- package/dist/lib/rag/metadata/MetadataExtractorFactory.d.ts +5 -55
- package/dist/lib/rag/metadata/metadataExtractor.js +6 -3
- package/dist/lib/rag/pipeline/RAGPipeline.d.ts +8 -126
- package/dist/lib/rag/pipeline/RAGPipeline.js +11 -11
- package/dist/lib/rag/pipeline/contextAssembly.d.ts +3 -42
- package/dist/lib/rag/pipeline/contextAssembly.js +6 -3
- package/dist/lib/rag/reranker/RerankerFactory.d.ts +5 -60
- package/dist/lib/rag/resilience/CircuitBreaker.d.ts +3 -33
- package/dist/lib/rag/resilience/RetryHandler.d.ts +2 -21
- package/dist/lib/rag/retrieval/hybridSearch.d.ts +3 -41
- package/dist/lib/rag/retrieval/vectorQueryTool.d.ts +2 -13
- package/dist/lib/rag/retrieval/vectorQueryTool.js +4 -3
- package/dist/lib/rag/types.d.ts +3 -3
- package/dist/lib/sdk/toolRegistration.d.ts +2 -2
- package/dist/lib/server/middleware/cache.d.ts +2 -2
- package/dist/lib/server/middleware/rateLimit.d.ts +2 -2
- package/dist/lib/server/routes/mcpRoutes.js +277 -249
- package/dist/lib/server/routes/memoryRoutes.js +287 -281
- package/dist/lib/server/utils/validation.d.ts +10 -10
- package/dist/lib/session/globalSessionState.d.ts +2 -2
- package/dist/lib/telemetry/telemetryService.d.ts +2 -2
- package/dist/lib/types/common.d.ts +39 -0
- package/dist/lib/types/contextTypes.d.ts +255 -0
- package/dist/lib/types/contextTypes.js +0 -2
- package/dist/lib/types/conversation.d.ts +62 -0
- package/dist/lib/types/conversationMemoryInterface.d.ts +27 -0
- package/dist/lib/types/conversationMemoryInterface.js +7 -0
- package/dist/lib/types/fileReferenceTypes.d.ts +222 -0
- package/dist/lib/types/fileReferenceTypes.js +9 -0
- package/dist/lib/types/fileTypes.d.ts +26 -3
- package/dist/lib/types/generateTypes.d.ts +22 -1
- package/dist/lib/types/index.d.ts +4 -5
- package/dist/lib/types/index.js +8 -10
- package/dist/lib/types/modelTypes.d.ts +2 -2
- package/dist/lib/types/processorTypes.d.ts +597 -0
- package/dist/lib/types/processorTypes.js +91 -0
- package/dist/lib/types/ragTypes.d.ts +481 -0
- package/dist/lib/types/ragTypes.js +8 -0
- package/dist/lib/types/sdkTypes.d.ts +17 -18
- package/dist/lib/types/streamTypes.d.ts +11 -1
- package/dist/lib/utils/async/retry.d.ts +2 -2
- package/dist/lib/utils/async/withTimeout.js +3 -1
- package/dist/lib/utils/conversationMemory.d.ts +12 -6
- package/dist/lib/utils/conversationMemory.js +76 -36
- package/dist/lib/utils/fileDetector.d.ts +62 -0
- package/dist/lib/utils/fileDetector.js +1014 -14
- package/dist/lib/utils/json/safeParse.d.ts +2 -2
- package/dist/lib/utils/messageBuilder.js +806 -153
- package/dist/lib/utils/modelChoices.d.ts +2 -2
- package/dist/lib/utils/multimodalOptionsBuilder.d.ts +2 -1
- package/dist/lib/utils/multimodalOptionsBuilder.js +1 -0
- package/dist/lib/utils/rateLimiter.d.ts +2 -2
- package/dist/lib/utils/sanitizers/filename.d.ts +4 -4
- package/dist/lib/utils/sanitizers/svg.d.ts +2 -2
- package/dist/lib/utils/thinkingConfig.d.ts +6 -6
- package/dist/lib/utils/tokenEstimation.d.ts +68 -0
- package/dist/lib/utils/tokenEstimation.js +113 -0
- package/dist/lib/utils/tokenUtils.d.ts +4 -4
- package/dist/lib/utils/ttsProcessor.d.ts +2 -2
- package/dist/lib/workflow/config.d.ts +150 -150
- package/dist/memory/mem0Initializer.d.ts +2 -2
- package/dist/neurolink.d.ts +61 -2
- package/dist/neurolink.js +619 -307
- package/dist/processors/archive/ArchiveProcessor.d.ts +327 -0
- package/dist/processors/archive/ArchiveProcessor.js +1308 -0
- package/dist/processors/archive/index.d.ts +33 -0
- package/dist/processors/archive/index.js +42 -0
- package/dist/processors/base/types.d.ts +70 -64
- package/dist/processors/base/types.js +6 -0
- package/dist/processors/cli/fileProcessorCli.d.ts +8 -8
- package/dist/processors/cli/fileProcessorCli.js +5 -5
- package/dist/processors/config/mimeTypes.js +25 -0
- package/dist/processors/config/sizeLimits.d.ts +52 -40
- package/dist/processors/config/sizeLimits.js +56 -44
- package/dist/processors/document/ExcelProcessor.d.ts +14 -0
- package/dist/processors/document/ExcelProcessor.js +72 -1
- package/dist/processors/document/PptxProcessor.d.ts +63 -0
- package/dist/processors/document/PptxProcessor.js +157 -0
- package/dist/processors/document/index.d.ts +1 -0
- package/dist/processors/document/index.js +6 -0
- package/dist/processors/errors/FileErrorCode.d.ts +2 -2
- package/dist/processors/errors/errorHelpers.d.ts +2 -2
- package/dist/processors/errors/errorSerializer.d.ts +4 -4
- package/dist/processors/index.d.ts +8 -2
- package/dist/processors/index.js +5 -2
- package/dist/processors/integration/FileProcessorIntegration.d.ts +8 -8
- package/dist/processors/integration/FileProcessorIntegration.js +7 -7
- package/dist/processors/media/AudioProcessor.d.ts +328 -0
- package/dist/processors/media/AudioProcessor.js +707 -0
- package/dist/processors/media/VideoProcessor.d.ts +350 -0
- package/dist/processors/media/VideoProcessor.js +991 -0
- package/dist/processors/media/ffprobe-static.d.ts +4 -0
- package/dist/processors/media/index.d.ts +27 -0
- package/dist/processors/media/index.js +36 -0
- package/dist/processors/registry/ProcessorRegistry.d.ts +19 -5
- package/dist/processors/registry/ProcessorRegistry.js +103 -8
- package/dist/processors/registry/index.d.ts +1 -1
- package/dist/processors/registry/index.js +1 -1
- package/dist/processors/registry/types.d.ts +2 -2
- package/dist/providers/googleAiStudio.d.ts +34 -0
- package/dist/providers/googleAiStudio.js +267 -397
- package/dist/providers/googleVertex.d.ts +55 -1
- package/dist/providers/googleVertex.js +452 -719
- package/dist/providers/sagemaker/detection.d.ts +6 -6
- package/dist/providers/sagemaker/diagnostics.d.ts +4 -4
- package/dist/providers/sagemaker/parsers.d.ts +4 -4
- package/dist/rag/chunkers/RecursiveChunker.js +2 -2
- package/dist/rag/document/loaders.d.ts +6 -71
- package/dist/rag/document/loaders.js +5 -5
- package/dist/rag/graphRag/graphRAG.js +26 -9
- package/dist/rag/metadata/MetadataExtractorFactory.d.ts +5 -55
- package/dist/rag/metadata/metadataExtractor.js +6 -3
- package/dist/rag/pipeline/RAGPipeline.d.ts +8 -126
- package/dist/rag/pipeline/RAGPipeline.js +11 -11
- package/dist/rag/pipeline/contextAssembly.d.ts +3 -42
- package/dist/rag/pipeline/contextAssembly.js +6 -3
- package/dist/rag/reranker/RerankerFactory.d.ts +5 -60
- package/dist/rag/resilience/CircuitBreaker.d.ts +3 -33
- package/dist/rag/resilience/RetryHandler.d.ts +2 -21
- package/dist/rag/retrieval/hybridSearch.d.ts +3 -41
- package/dist/rag/retrieval/vectorQueryTool.d.ts +2 -13
- package/dist/rag/retrieval/vectorQueryTool.js +4 -3
- package/dist/rag/types.d.ts +3 -3
- package/dist/sdk/toolRegistration.d.ts +2 -2
- package/dist/server/middleware/cache.d.ts +2 -2
- package/dist/server/middleware/rateLimit.d.ts +2 -2
- package/dist/server/routes/mcpRoutes.js +277 -249
- package/dist/server/routes/memoryRoutes.js +287 -281
- package/dist/server/utils/validation.d.ts +4 -4
- package/dist/session/globalSessionState.d.ts +2 -2
- package/dist/telemetry/telemetryService.d.ts +2 -2
- package/dist/types/common.d.ts +39 -0
- package/dist/types/contextTypes.d.ts +255 -0
- package/dist/types/contextTypes.js +0 -2
- package/dist/types/conversation.d.ts +62 -0
- package/dist/types/conversationMemoryInterface.d.ts +27 -0
- package/dist/types/conversationMemoryInterface.js +6 -0
- package/dist/types/fileReferenceTypes.d.ts +222 -0
- package/dist/types/fileReferenceTypes.js +8 -0
- package/dist/types/fileTypes.d.ts +26 -3
- package/dist/types/generateTypes.d.ts +22 -1
- package/dist/types/index.d.ts +4 -5
- package/dist/types/index.js +8 -10
- package/dist/types/processorTypes.d.ts +597 -0
- package/dist/types/processorTypes.js +90 -0
- package/dist/types/ragTypes.d.ts +481 -0
- package/dist/types/ragTypes.js +7 -0
- package/dist/types/sdkTypes.d.ts +17 -18
- package/dist/types/streamTypes.d.ts +11 -1
- package/dist/utils/async/retry.d.ts +2 -2
- package/dist/utils/async/withTimeout.js +3 -1
- package/dist/utils/conversationMemory.d.ts +12 -6
- package/dist/utils/conversationMemory.js +76 -36
- package/dist/utils/fileDetector.d.ts +62 -0
- package/dist/utils/fileDetector.js +1014 -14
- package/dist/utils/json/safeParse.d.ts +2 -2
- package/dist/utils/messageBuilder.js +806 -153
- package/dist/utils/modelChoices.d.ts +2 -2
- package/dist/utils/multimodalOptionsBuilder.d.ts +2 -1
- package/dist/utils/multimodalOptionsBuilder.js +1 -0
- package/dist/utils/rateLimiter.d.ts +2 -2
- package/dist/utils/sanitizers/filename.d.ts +4 -4
- package/dist/utils/sanitizers/svg.d.ts +2 -2
- package/dist/utils/thinkingConfig.d.ts +6 -6
- package/dist/utils/tokenEstimation.d.ts +68 -0
- package/dist/utils/tokenEstimation.js +112 -0
- package/dist/utils/tokenUtils.d.ts +4 -4
- package/dist/utils/ttsProcessor.d.ts +2 -2
- package/dist/workflow/config.d.ts +104 -104
- package/package.json +18 -6
- package/dist/lib/utils/conversationMemoryUtils.d.ts +0 -25
- package/dist/lib/utils/conversationMemoryUtils.js +0 -138
- package/dist/utils/conversationMemoryUtils.d.ts +0 -25
- package/dist/utils/conversationMemoryUtils.js +0 -137
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming File Reader
|
|
3
|
+
*
|
|
4
|
+
* Reads files with token-budget awareness using Node.js streams.
|
|
5
|
+
* Memory usage is proportional to what's returned, not what's on disk.
|
|
6
|
+
*
|
|
7
|
+
* Inspired by Kilocode's token-budget streaming reader pattern:
|
|
8
|
+
* uses createReadStream + readline, counts tokens per line,
|
|
9
|
+
* stops when budget is exhausted.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Read lines 100-200 of a large file with a 5000 token budget
|
|
14
|
+
* const result = await StreamingReader.readLines('/path/to/file.csv', {
|
|
15
|
+
* startLine: 100,
|
|
16
|
+
* endLine: 200,
|
|
17
|
+
* tokenBudget: 5000,
|
|
18
|
+
* provider: 'anthropic',
|
|
19
|
+
* });
|
|
20
|
+
* // result.content = "line 100 content\nline 101 content\n..."
|
|
21
|
+
* // result.truncated = true if budget was hit before line 200
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import { createReadStream } from "node:fs";
|
|
25
|
+
import { stat } from "node:fs/promises";
|
|
26
|
+
import { createInterface } from "node:readline";
|
|
27
|
+
import { CHARS_PER_TOKEN, estimateTokens } from "../utils/tokenEstimation.js";
|
|
28
|
+
/** Default token budget if none specified */
|
|
29
|
+
const DEFAULT_TOKEN_BUDGET = 50_000;
|
|
30
|
+
/** Maximum context lines before/after a search match */
|
|
31
|
+
const DEFAULT_SEARCH_CONTEXT = 3;
|
|
32
|
+
/** Maximum search matches to return */
|
|
33
|
+
const DEFAULT_MAX_MATCHES = 50;
|
|
34
|
+
/**
|
|
35
|
+
* Streaming file reader with token-budget-aware line reading.
|
|
36
|
+
*
|
|
37
|
+
* All methods use Node.js streams to avoid loading entire files into memory.
|
|
38
|
+
* A 2GB CSV file: only the requested lines/matches are read from disk.
|
|
39
|
+
*/
|
|
40
|
+
export class StreamingReader {
|
|
41
|
+
/**
|
|
42
|
+
* Read lines from a file with a token budget.
|
|
43
|
+
*
|
|
44
|
+
* Uses createReadStream + readline for memory-efficient reading.
|
|
45
|
+
* Stops reading when the token budget is exhausted or endLine is reached.
|
|
46
|
+
*
|
|
47
|
+
* @param filePath - Absolute path to the file
|
|
48
|
+
* @param options - Reading options (startLine, endLine, tokenBudget, provider)
|
|
49
|
+
* @returns FileReadResult with content, line info, and truncation status
|
|
50
|
+
*/
|
|
51
|
+
static async readLines(filePath, options = {}) {
|
|
52
|
+
const { tokenBudget = DEFAULT_TOKEN_BUDGET, startLine = 1, endLine, encoding = "utf-8", provider, } = options;
|
|
53
|
+
// Validate file exists
|
|
54
|
+
await stat(filePath);
|
|
55
|
+
const lines = [];
|
|
56
|
+
let currentLine = 0;
|
|
57
|
+
let totalLines = 0;
|
|
58
|
+
let usedTokens = 0;
|
|
59
|
+
let truncated = false;
|
|
60
|
+
const actualStartLine = startLine;
|
|
61
|
+
let actualEndLine = startLine;
|
|
62
|
+
const readStream = createReadStream(filePath, { encoding });
|
|
63
|
+
const rl = createInterface({
|
|
64
|
+
input: readStream,
|
|
65
|
+
crlfDelay: Infinity,
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
for await (const line of rl) {
|
|
69
|
+
currentLine++;
|
|
70
|
+
totalLines = currentLine;
|
|
71
|
+
// Skip lines before startLine
|
|
72
|
+
if (currentLine < startLine) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
// Stop at endLine if specified
|
|
76
|
+
if (endLine !== undefined && currentLine > endLine) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
// Estimate tokens for this line (include newline char)
|
|
80
|
+
const lineTokens = Math.ceil((line.length + 1) / CHARS_PER_TOKEN);
|
|
81
|
+
// Check if adding this line would exceed budget
|
|
82
|
+
if (usedTokens + lineTokens > tokenBudget && lines.length > 0) {
|
|
83
|
+
truncated = true;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
lines.push(line);
|
|
87
|
+
usedTokens += lineTokens;
|
|
88
|
+
actualEndLine = currentLine;
|
|
89
|
+
// Apply provider multiplier periodically (every 100 lines) for efficiency
|
|
90
|
+
if (lines.length % 100 === 0) {
|
|
91
|
+
const adjustedTokens = estimateTokens(lines.join("\n"), provider);
|
|
92
|
+
if (adjustedTokens > tokenBudget) {
|
|
93
|
+
truncated = true;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
rl.close();
|
|
101
|
+
readStream.destroy();
|
|
102
|
+
}
|
|
103
|
+
// If we didn't reach EOF, count remaining lines
|
|
104
|
+
if (truncated || (endLine !== undefined && currentLine <= (endLine || 0))) {
|
|
105
|
+
// We need total line count — do a quick count of remaining lines
|
|
106
|
+
if (!truncated && !endLine) {
|
|
107
|
+
// Already counted all lines
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
totalLines = await StreamingReader.countLines(filePath, encoding);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const content = lines.join("\n");
|
|
114
|
+
const estimatedTokensFinal = estimateTokens(content, provider);
|
|
115
|
+
return {
|
|
116
|
+
content,
|
|
117
|
+
startLine: actualStartLine,
|
|
118
|
+
endLine: actualEndLine,
|
|
119
|
+
totalLines,
|
|
120
|
+
truncated,
|
|
121
|
+
estimatedTokens: estimatedTokensFinal,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Count total lines in a file without reading entire content into memory.
|
|
126
|
+
*
|
|
127
|
+
* @param filePath - Absolute path to the file
|
|
128
|
+
* @param encoding - File encoding (default: utf-8)
|
|
129
|
+
* @returns Total line count
|
|
130
|
+
*/
|
|
131
|
+
static async countLines(filePath, encoding = "utf-8") {
|
|
132
|
+
let count = 0;
|
|
133
|
+
const readStream = createReadStream(filePath, { encoding });
|
|
134
|
+
const rl = createInterface({
|
|
135
|
+
input: readStream,
|
|
136
|
+
crlfDelay: Infinity,
|
|
137
|
+
});
|
|
138
|
+
try {
|
|
139
|
+
for await (const _line of rl) {
|
|
140
|
+
count++;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
rl.close();
|
|
145
|
+
readStream.destroy();
|
|
146
|
+
}
|
|
147
|
+
return count;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Search for a pattern within a file, returning matching lines with context.
|
|
151
|
+
*
|
|
152
|
+
* Uses streaming to avoid loading the entire file into memory.
|
|
153
|
+
* Returns up to maxMatches results, each with contextBefore/contextAfter lines.
|
|
154
|
+
*
|
|
155
|
+
* @param filePath - Absolute path to the file
|
|
156
|
+
* @param pattern - Regex pattern or string to search for
|
|
157
|
+
* @param options - Search options
|
|
158
|
+
* @returns FileSearchResult with matches, total count, and truncation status
|
|
159
|
+
*/
|
|
160
|
+
static async searchInFile(filePath, pattern, options = {}) {
|
|
161
|
+
const { maxMatches = DEFAULT_MAX_MATCHES, contextLines = DEFAULT_SEARCH_CONTEXT, encoding = "utf-8", } = options;
|
|
162
|
+
// Validate file exists
|
|
163
|
+
await stat(filePath);
|
|
164
|
+
const regex = pattern instanceof RegExp
|
|
165
|
+
? pattern
|
|
166
|
+
: new RegExp(StreamingReader.escapeRegex(pattern), "i");
|
|
167
|
+
const matches = [];
|
|
168
|
+
let totalMatches = 0;
|
|
169
|
+
let truncated = false;
|
|
170
|
+
// Ring buffer for context-before lines
|
|
171
|
+
const contextBuffer = [];
|
|
172
|
+
let currentLine = 0;
|
|
173
|
+
// Track lines already captured as context-after for previous matches
|
|
174
|
+
// to avoid re-processing
|
|
175
|
+
let pendingContextAfter = null;
|
|
176
|
+
const readStream = createReadStream(filePath, { encoding });
|
|
177
|
+
const rl = createInterface({
|
|
178
|
+
input: readStream,
|
|
179
|
+
crlfDelay: Infinity,
|
|
180
|
+
});
|
|
181
|
+
try {
|
|
182
|
+
for await (const line of rl) {
|
|
183
|
+
currentLine++;
|
|
184
|
+
// Fill context-after for previous match
|
|
185
|
+
if (pendingContextAfter && pendingContextAfter.remaining > 0) {
|
|
186
|
+
pendingContextAfter.match.contextAfter.push(line);
|
|
187
|
+
pendingContextAfter.remaining--;
|
|
188
|
+
if (pendingContextAfter.remaining === 0) {
|
|
189
|
+
pendingContextAfter = null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Test for match
|
|
193
|
+
if (regex.test(line)) {
|
|
194
|
+
totalMatches++;
|
|
195
|
+
if (matches.length < maxMatches) {
|
|
196
|
+
const match = {
|
|
197
|
+
lineNumber: currentLine,
|
|
198
|
+
line,
|
|
199
|
+
contextBefore: [...contextBuffer],
|
|
200
|
+
contextAfter: [],
|
|
201
|
+
};
|
|
202
|
+
matches.push(match);
|
|
203
|
+
// Set up context-after collection
|
|
204
|
+
if (contextLines > 0) {
|
|
205
|
+
pendingContextAfter = {
|
|
206
|
+
match,
|
|
207
|
+
remaining: contextLines,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
truncated = true;
|
|
213
|
+
// Continue counting total matches but don't store details
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Update context buffer (ring buffer for before-context)
|
|
217
|
+
contextBuffer.push(line);
|
|
218
|
+
if (contextBuffer.length > contextLines) {
|
|
219
|
+
contextBuffer.shift();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
rl.close();
|
|
225
|
+
readStream.destroy();
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
matches,
|
|
229
|
+
totalMatches,
|
|
230
|
+
truncated,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Read a preview of a file (first N characters / lines).
|
|
235
|
+
*
|
|
236
|
+
* Optimized for speed: reads only the first chunk of the file.
|
|
237
|
+
*
|
|
238
|
+
* @param filePath - Absolute path to the file
|
|
239
|
+
* @param maxChars - Maximum characters to return (default: 2000)
|
|
240
|
+
* @param encoding - File encoding (default: utf-8)
|
|
241
|
+
* @returns Preview string
|
|
242
|
+
*/
|
|
243
|
+
static async readPreview(filePath, maxChars = 2000, encoding = "utf-8") {
|
|
244
|
+
// For preview, read a small chunk directly — no need for line-by-line
|
|
245
|
+
const readStream = createReadStream(filePath, {
|
|
246
|
+
encoding,
|
|
247
|
+
start: 0,
|
|
248
|
+
end: maxChars + 100, // Read a bit extra to avoid cutting mid-line
|
|
249
|
+
});
|
|
250
|
+
let content = "";
|
|
251
|
+
try {
|
|
252
|
+
for await (const chunk of readStream) {
|
|
253
|
+
content += chunk;
|
|
254
|
+
if (content.length >= maxChars) {
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
finally {
|
|
260
|
+
readStream.destroy();
|
|
261
|
+
}
|
|
262
|
+
// Truncate to maxChars, preferring to break at line boundary
|
|
263
|
+
if (content.length > maxChars) {
|
|
264
|
+
const lastNewline = content.lastIndexOf("\n", maxChars);
|
|
265
|
+
if (lastNewline > maxChars * 0.8) {
|
|
266
|
+
content = content.substring(0, lastNewline);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
content = content.substring(0, maxChars);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return content;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Read a file from a Buffer with line range and token budget.
|
|
276
|
+
*
|
|
277
|
+
* For files already in memory (e.g., from URL download or Buffer input).
|
|
278
|
+
* Does NOT use streams — the buffer is already in memory.
|
|
279
|
+
*
|
|
280
|
+
* @param buffer - File content as Buffer
|
|
281
|
+
* @param options - Reading options
|
|
282
|
+
* @returns FileReadResult
|
|
283
|
+
*/
|
|
284
|
+
static readFromBuffer(buffer, options = {}) {
|
|
285
|
+
const { tokenBudget = DEFAULT_TOKEN_BUDGET, startLine = 1, endLine, encoding = "utf-8", provider, } = options;
|
|
286
|
+
const text = buffer.toString(encoding);
|
|
287
|
+
const allLines = text.split("\n");
|
|
288
|
+
const totalLines = allLines.length;
|
|
289
|
+
const start = Math.max(0, startLine - 1); // Convert to 0-indexed
|
|
290
|
+
const end = endLine !== undefined ? Math.min(endLine, totalLines) : totalLines;
|
|
291
|
+
let usedTokens = 0;
|
|
292
|
+
let truncated = false;
|
|
293
|
+
const lines = [];
|
|
294
|
+
for (let i = start; i < end; i++) {
|
|
295
|
+
const line = allLines[i];
|
|
296
|
+
const lineTokens = Math.ceil((line.length + 1) / CHARS_PER_TOKEN);
|
|
297
|
+
if (usedTokens + lineTokens > tokenBudget && lines.length > 0) {
|
|
298
|
+
truncated = true;
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
lines.push(line);
|
|
302
|
+
usedTokens += lineTokens;
|
|
303
|
+
}
|
|
304
|
+
const content = lines.join("\n");
|
|
305
|
+
const estimatedTokensFinal = estimateTokens(content, provider);
|
|
306
|
+
return {
|
|
307
|
+
content,
|
|
308
|
+
startLine,
|
|
309
|
+
endLine: start + lines.length,
|
|
310
|
+
totalLines,
|
|
311
|
+
truncated,
|
|
312
|
+
estimatedTokens: estimatedTokensFinal,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Escape a string for use in a regular expression.
|
|
317
|
+
*/
|
|
318
|
+
static escapeRegex(str) {
|
|
319
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Reference Architecture Types
|
|
3
|
+
*
|
|
4
|
+
* Types for the lazy on-demand file processing system.
|
|
5
|
+
* Files are registered as lightweight references with metadata and previews.
|
|
6
|
+
* Full content is processed on-demand when the LLM requests it via tools.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Size tier thresholds in bytes
|
|
10
|
+
*/
|
|
11
|
+
export declare const SIZE_TIER_THRESHOLDS: {
|
|
12
|
+
/** < 10 KB: inline in prompt */
|
|
13
|
+
readonly TINY_MAX: number;
|
|
14
|
+
/** 10 KB – 100 KB: full load with truncation */
|
|
15
|
+
readonly SMALL_MAX: number;
|
|
16
|
+
/** 100 KB – 5 MB: outline + on-demand */
|
|
17
|
+
readonly MEDIUM_MAX: number;
|
|
18
|
+
/** 5 MB – 100 MB: streaming + chunked summarization */
|
|
19
|
+
readonly LARGE_MAX: number;
|
|
20
|
+
/** 100 MB – 2 GB: reference only */
|
|
21
|
+
readonly HUGE_MAX: number;
|
|
22
|
+
};
|
|
23
|
+
export type { SizeTier, FileReferenceStatus, OutlineSection, FileReference, FileRegistrationOptions, FileReadResult, FileSearchResult, FileSearchMatch, StreamingReaderOptions, FileExtractionParams, FileExtractionResult, FileRegistryOptions, } from "../types/fileReferenceTypes.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Reference Architecture Types
|
|
3
|
+
*
|
|
4
|
+
* Types for the lazy on-demand file processing system.
|
|
5
|
+
* Files are registered as lightweight references with metadata and previews.
|
|
6
|
+
* Full content is processed on-demand when the LLM requests it via tools.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Size tier thresholds in bytes
|
|
10
|
+
*/
|
|
11
|
+
export const SIZE_TIER_THRESHOLDS = {
|
|
12
|
+
/** < 10 KB: inline in prompt */
|
|
13
|
+
TINY_MAX: 10 * 1024,
|
|
14
|
+
/** 10 KB – 100 KB: full load with truncation */
|
|
15
|
+
SMALL_MAX: 100 * 1024,
|
|
16
|
+
/** 100 KB – 5 MB: outline + on-demand */
|
|
17
|
+
MEDIUM_MAX: 5 * 1024 * 1024,
|
|
18
|
+
/** 5 MB – 100 MB: streaming + chunked summarization */
|
|
19
|
+
LARGE_MAX: 100 * 1024 * 1024,
|
|
20
|
+
/** 100 MB – 2 GB: reference only */
|
|
21
|
+
HUGE_MAX: 2 * 1024 * 1024 * 1024,
|
|
22
|
+
// > 2 GB: oversized, rejected
|
|
23
|
+
};
|
|
@@ -25,7 +25,7 @@ import type { ImageGenConfig, ImageGenToolContext, ImageGenToolParams, ImageGenT
|
|
|
25
25
|
/**
|
|
26
26
|
* Tool definition interface compatible with AI SDK / MCP
|
|
27
27
|
*/
|
|
28
|
-
export
|
|
28
|
+
export type ImageGenToolDefinition = {
|
|
29
29
|
name: string;
|
|
30
30
|
description: string;
|
|
31
31
|
inputSchema: {
|
|
@@ -38,7 +38,7 @@ export interface ImageGenToolDefinition {
|
|
|
38
38
|
required: string[];
|
|
39
39
|
};
|
|
40
40
|
execute: (params: ImageGenToolParams, context?: ImageGenToolContext) => Promise<ImageGenToolResponse>;
|
|
41
|
-
}
|
|
41
|
+
};
|
|
42
42
|
/**
|
|
43
43
|
* Create an image generation tool for use with AI models
|
|
44
44
|
*
|
|
@@ -23,7 +23,7 @@ export type StylePreset = "realistic" | "photorealistic" | "artistic" | "cartoon
|
|
|
23
23
|
/**
|
|
24
24
|
* Options for image generation requests
|
|
25
25
|
*/
|
|
26
|
-
export
|
|
26
|
+
export type ImageGenOptions = {
|
|
27
27
|
/**
|
|
28
28
|
* Text prompt describing the image to generate
|
|
29
29
|
* Should be detailed and specific for best results
|
|
@@ -79,11 +79,11 @@ export interface ImageGenOptions {
|
|
|
79
79
|
* Higher values = more creative/random
|
|
80
80
|
*/
|
|
81
81
|
temperature?: number;
|
|
82
|
-
}
|
|
82
|
+
};
|
|
83
83
|
/**
|
|
84
84
|
* Result of an image generation request
|
|
85
85
|
*/
|
|
86
|
-
export
|
|
86
|
+
export type ImageGenResult = {
|
|
87
87
|
/**
|
|
88
88
|
* Whether generation was successful
|
|
89
89
|
*/
|
|
@@ -121,11 +121,11 @@ export interface ImageGenResult {
|
|
|
121
121
|
* Additional metadata from the provider
|
|
122
122
|
*/
|
|
123
123
|
metadata?: Record<string, unknown>;
|
|
124
|
-
}
|
|
124
|
+
};
|
|
125
125
|
/**
|
|
126
126
|
* Configuration for the ImageGenService
|
|
127
127
|
*/
|
|
128
|
-
export
|
|
128
|
+
export type ImageGenConfig = {
|
|
129
129
|
/**
|
|
130
130
|
* Whether image generation is enabled
|
|
131
131
|
*/
|
|
@@ -162,7 +162,7 @@ export interface ImageGenConfig {
|
|
|
162
162
|
* Maximum number of reference PDFs allowed
|
|
163
163
|
*/
|
|
164
164
|
maxReferencePdfs?: number;
|
|
165
|
-
}
|
|
165
|
+
};
|
|
166
166
|
/**
|
|
167
167
|
* Default configuration for image generation
|
|
168
168
|
*/
|
|
@@ -170,7 +170,7 @@ export declare const DEFAULT_IMAGE_GEN_CONFIG: ImageGenConfig;
|
|
|
170
170
|
/**
|
|
171
171
|
* Tool parameters for AI model use
|
|
172
172
|
*/
|
|
173
|
-
export
|
|
173
|
+
export type ImageGenToolParams = {
|
|
174
174
|
/**
|
|
175
175
|
* Detailed description of the image to generate
|
|
176
176
|
*/
|
|
@@ -187,11 +187,11 @@ export interface ImageGenToolParams {
|
|
|
187
187
|
* Style like "realistic", "artistic", "cartoon" (optional)
|
|
188
188
|
*/
|
|
189
189
|
style?: StylePreset | string;
|
|
190
|
-
}
|
|
190
|
+
};
|
|
191
191
|
/**
|
|
192
192
|
* Response from the image generation tool
|
|
193
193
|
*/
|
|
194
|
-
export
|
|
194
|
+
export type ImageGenToolResponse = {
|
|
195
195
|
/**
|
|
196
196
|
* Whether the tool execution was successful
|
|
197
197
|
*/
|
|
@@ -209,11 +209,11 @@ export interface ImageGenToolResponse {
|
|
|
209
209
|
* Error message if execution failed
|
|
210
210
|
*/
|
|
211
211
|
error?: string;
|
|
212
|
-
}
|
|
212
|
+
};
|
|
213
213
|
/**
|
|
214
214
|
* Context for tool execution (optional)
|
|
215
215
|
*/
|
|
216
|
-
export
|
|
216
|
+
export type ImageGenToolContext = {
|
|
217
217
|
/**
|
|
218
218
|
* Reference images to use for generation
|
|
219
219
|
*/
|
|
@@ -234,4 +234,4 @@ export interface ImageGenToolContext {
|
|
|
234
234
|
* Additional metadata
|
|
235
235
|
*/
|
|
236
236
|
metadata?: Record<string, unknown>;
|
|
237
|
-
}
|
|
237
|
+
};
|
|
@@ -221,11 +221,11 @@ export declare const directAgentTools: {
|
|
|
221
221
|
}, "strip", z.ZodTypeAny, {
|
|
222
222
|
content: string;
|
|
223
223
|
path: string;
|
|
224
|
-
mode: "create" | "
|
|
224
|
+
mode: "create" | "append" | "overwrite";
|
|
225
225
|
}, {
|
|
226
226
|
content: string;
|
|
227
227
|
path: string;
|
|
228
|
-
mode?: "create" | "
|
|
228
|
+
mode?: "create" | "append" | "overwrite" | undefined;
|
|
229
229
|
}>, {
|
|
230
230
|
success: boolean;
|
|
231
231
|
error: string;
|
|
@@ -236,7 +236,7 @@ export declare const directAgentTools: {
|
|
|
236
236
|
} | {
|
|
237
237
|
success: boolean;
|
|
238
238
|
path: string;
|
|
239
|
-
mode: "create" | "
|
|
239
|
+
mode: "create" | "append" | "overwrite";
|
|
240
240
|
size: number;
|
|
241
241
|
written: number;
|
|
242
242
|
error?: undefined;
|
|
@@ -251,7 +251,7 @@ export declare const directAgentTools: {
|
|
|
251
251
|
execute: (args: {
|
|
252
252
|
content: string;
|
|
253
253
|
path: string;
|
|
254
|
-
mode: "create" | "
|
|
254
|
+
mode: "create" | "append" | "overwrite";
|
|
255
255
|
}, options: import("ai").ToolExecutionOptions) => PromiseLike<{
|
|
256
256
|
success: boolean;
|
|
257
257
|
error: string;
|
|
@@ -262,7 +262,7 @@ export declare const directAgentTools: {
|
|
|
262
262
|
} | {
|
|
263
263
|
success: boolean;
|
|
264
264
|
path: string;
|
|
265
|
-
mode: "create" | "
|
|
265
|
+
mode: "create" | "append" | "overwrite";
|
|
266
266
|
size: number;
|
|
267
267
|
written: number;
|
|
268
268
|
error?: undefined;
|
|
@@ -282,8 +282,8 @@ export declare const directAgentTools: {
|
|
|
282
282
|
maxRows: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
283
283
|
}, "strip", z.ZodTypeAny, {
|
|
284
284
|
operation: "count_by_column" | "sum_by_column" | "average_by_column" | "min_max_by_column" | "describe";
|
|
285
|
-
maxRows: number;
|
|
286
285
|
filePath: string;
|
|
286
|
+
maxRows: number;
|
|
287
287
|
column: string;
|
|
288
288
|
}, {
|
|
289
289
|
operation: "count_by_column" | "sum_by_column" | "average_by_column" | "min_max_by_column" | "describe";
|
|
@@ -309,8 +309,8 @@ export declare const directAgentTools: {
|
|
|
309
309
|
}> & {
|
|
310
310
|
execute: (args: {
|
|
311
311
|
operation: "count_by_column" | "sum_by_column" | "average_by_column" | "min_max_by_column" | "describe";
|
|
312
|
-
maxRows: number;
|
|
313
312
|
filePath: string;
|
|
313
|
+
maxRows: number;
|
|
314
314
|
column: string;
|
|
315
315
|
}, options: import("ai").ToolExecutionOptions) => PromiseLike<{
|
|
316
316
|
success: boolean;
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
import type { ConversationMemoryConfig } from "../types/conversation.js";
|
|
6
6
|
/**
|
|
7
7
|
* Default maximum number of turns per session
|
|
8
|
+
* @deprecated Use tokenThreshold-based memory management instead.
|
|
9
|
+
* This constant is kept for backward compatibility with legacy turn-based memory.
|
|
8
10
|
*/
|
|
9
11
|
export declare const DEFAULT_MAX_TURNS_PER_SESSION = 50;
|
|
10
12
|
/**
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Default maximum number of turns per session
|
|
7
|
+
* @deprecated Use tokenThreshold-based memory management instead.
|
|
8
|
+
* This constant is kept for backward compatibility with legacy turn-based memory.
|
|
7
9
|
*/
|
|
8
10
|
export const DEFAULT_MAX_TURNS_PER_SESSION = 50;
|
|
9
11
|
/**
|
|
@@ -77,11 +79,9 @@ export function getConversationMemoryDefaults() {
|
|
|
77
79
|
: undefined,
|
|
78
80
|
summarizationProvider: process.env.NEUROLINK_SUMMARIZATION_PROVIDER || "vertex",
|
|
79
81
|
summarizationModel: process.env.NEUROLINK_SUMMARIZATION_MODEL || "gemini-2.5-flash",
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
summarizationThresholdTurns: Number(process.env.NEUROLINK_SUMMARIZATION_THRESHOLD_TURNS) || 20,
|
|
84
|
-
summarizationTargetTurns: Number(process.env.NEUROLINK_SUMMARIZATION_TARGET_TURNS) || 10,
|
|
82
|
+
// @deprecated — Turn-based fields are superseded by tokenThreshold-based memory.
|
|
83
|
+
// Kept for backward compatibility; will be removed in a future major version.
|
|
84
|
+
maxTurnsPerSession: DEFAULT_MAX_TURNS_PER_SESSION,
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
//# sourceMappingURL=conversationMemory.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Window Registry
|
|
3
|
+
*
|
|
4
|
+
* Accurate per-provider, per-model context window sizes (INPUT token limits).
|
|
5
|
+
* These are distinct from OUTPUT token limits in tokens.ts.
|
|
6
|
+
*
|
|
7
|
+
* Sources:
|
|
8
|
+
* - Anthropic: https://docs.anthropic.com/en/docs/about-claude/models
|
|
9
|
+
* - OpenAI: https://platform.openai.com/docs/models
|
|
10
|
+
* - Google: https://ai.google.dev/gemini-api/docs/models
|
|
11
|
+
* - Others: Provider documentation as of Feb 2026
|
|
12
|
+
*/
|
|
13
|
+
/** Default context window when provider/model is unknown */
|
|
14
|
+
export declare const DEFAULT_CONTEXT_WINDOW = 128000;
|
|
15
|
+
/** Maximum output reserve when maxTokens not specified */
|
|
16
|
+
export declare const MAX_DEFAULT_OUTPUT_RESERVE = 64000;
|
|
17
|
+
/** Default output reserve ratio (35% of context) */
|
|
18
|
+
export declare const DEFAULT_OUTPUT_RESERVE_RATIO = 0.35;
|
|
19
|
+
/**
|
|
20
|
+
* Per-provider, per-model context window sizes.
|
|
21
|
+
* The "_default" key is the fallback for unknown models within a provider.
|
|
22
|
+
*/
|
|
23
|
+
export declare const MODEL_CONTEXT_WINDOWS: Record<string, Record<string, number>>;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve context window size for a provider/model combination.
|
|
26
|
+
*
|
|
27
|
+
* Priority:
|
|
28
|
+
* 1. Exact model match under provider
|
|
29
|
+
* 2. Provider's _default
|
|
30
|
+
* 3. Global DEFAULT_CONTEXT_WINDOW
|
|
31
|
+
*/
|
|
32
|
+
export declare function getContextWindowSize(provider: string, model?: string): number;
|
|
33
|
+
/**
|
|
34
|
+
* Calculate output token reserve for a given context window.
|
|
35
|
+
*
|
|
36
|
+
* @param contextWindow - Total context window size
|
|
37
|
+
* @param maxTokens - Explicit maxTokens from user config (if set)
|
|
38
|
+
* @returns Number of tokens reserved for output
|
|
39
|
+
*/
|
|
40
|
+
export declare function getOutputReserve(contextWindow: number, maxTokens?: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Calculate available input tokens for a given provider/model.
|
|
43
|
+
*
|
|
44
|
+
* available = contextWindow - outputReserve
|
|
45
|
+
*/
|
|
46
|
+
export declare function getAvailableInputTokens(provider: string, model?: string, maxTokens?: number): number;
|