@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.
Files changed (356) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +29 -25
  3. package/dist/agent/directTools.d.ts +5 -5
  4. package/dist/cli/commands/config.d.ts +9 -9
  5. package/dist/cli/commands/serve.d.ts +37 -0
  6. package/dist/cli/commands/serve.js +302 -229
  7. package/dist/cli/commands/setup-anthropic.d.ts +2 -2
  8. package/dist/cli/commands/setup-azure.d.ts +2 -2
  9. package/dist/cli/commands/setup-bedrock.d.ts +2 -2
  10. package/dist/cli/commands/setup-gcp.d.ts +2 -2
  11. package/dist/cli/commands/setup-google-ai.d.ts +2 -2
  12. package/dist/cli/commands/setup-huggingface.d.ts +2 -2
  13. package/dist/cli/commands/setup-mistral.d.ts +2 -2
  14. package/dist/cli/commands/setup-openai.d.ts +2 -2
  15. package/dist/cli/commands/setup.d.ts +2 -2
  16. package/dist/cli/factories/commandFactory.js +16 -2
  17. package/dist/cli/loop/optionsSchema.d.ts +2 -2
  18. package/dist/cli/loop/session.d.ts +4 -0
  19. package/dist/cli/loop/session.js +49 -4
  20. package/dist/cli/utils/interactiveSetup.d.ts +4 -4
  21. package/dist/config/conversationMemory.d.ts +2 -0
  22. package/dist/config/conversationMemory.js +5 -5
  23. package/dist/constants/contextWindows.d.ts +46 -0
  24. package/dist/constants/contextWindows.js +156 -0
  25. package/dist/context/budgetChecker.d.ts +18 -0
  26. package/dist/context/budgetChecker.js +71 -0
  27. package/dist/context/contextCompactor.d.ts +22 -0
  28. package/dist/context/contextCompactor.js +106 -0
  29. package/dist/context/effectiveHistory.d.ts +52 -0
  30. package/dist/context/effectiveHistory.js +105 -0
  31. package/dist/context/errorDetection.d.ts +14 -0
  32. package/dist/context/errorDetection.js +124 -0
  33. package/dist/context/fileSummarizationService.d.ts +54 -0
  34. package/dist/context/fileSummarizationService.js +255 -0
  35. package/dist/context/fileSummarizer.d.ts +56 -0
  36. package/dist/context/fileSummarizer.js +145 -0
  37. package/dist/context/fileTokenBudget.d.ts +53 -0
  38. package/dist/context/fileTokenBudget.js +127 -0
  39. package/dist/context/prompts/summarizationPrompt.d.ts +17 -0
  40. package/dist/context/prompts/summarizationPrompt.js +110 -0
  41. package/dist/context/stages/fileReadDeduplicator.d.ts +10 -0
  42. package/dist/context/stages/fileReadDeduplicator.js +66 -0
  43. package/dist/context/stages/slidingWindowTruncator.d.ts +11 -0
  44. package/dist/context/stages/slidingWindowTruncator.js +42 -0
  45. package/dist/context/stages/structuredSummarizer.d.ts +10 -0
  46. package/dist/context/stages/structuredSummarizer.js +49 -0
  47. package/dist/context/stages/toolOutputPruner.d.ts +10 -0
  48. package/dist/context/stages/toolOutputPruner.js +52 -0
  49. package/dist/context/summarizationEngine.d.ts +45 -0
  50. package/dist/context/summarizationEngine.js +110 -0
  51. package/dist/context/toolOutputLimits.d.ts +17 -0
  52. package/dist/context/toolOutputLimits.js +84 -0
  53. package/dist/context/toolPairRepair.d.ts +16 -0
  54. package/dist/context/toolPairRepair.js +66 -0
  55. package/dist/core/conversationMemoryManager.d.ts +5 -15
  56. package/dist/core/conversationMemoryManager.js +15 -75
  57. package/dist/core/modules/MessageBuilder.d.ts +1 -1
  58. package/dist/core/modules/MessageBuilder.js +2 -0
  59. package/dist/core/modules/TelemetryHandler.d.ts +2 -3
  60. package/dist/core/modules/TelemetryHandler.js +3 -3
  61. package/dist/core/modules/ToolsManager.d.ts +2 -2
  62. package/dist/core/redisConversationMemoryManager.d.ts +8 -14
  63. package/dist/core/redisConversationMemoryManager.js +69 -78
  64. package/dist/factories/providerFactory.d.ts +2 -2
  65. package/dist/files/fileReferenceRegistry.d.ts +276 -0
  66. package/dist/files/fileReferenceRegistry.js +1543 -0
  67. package/dist/files/fileTools.d.ts +423 -0
  68. package/dist/files/fileTools.js +449 -0
  69. package/dist/files/index.d.ts +14 -0
  70. package/dist/files/index.js +13 -0
  71. package/dist/files/streamingReader.d.ts +93 -0
  72. package/dist/files/streamingReader.js +321 -0
  73. package/dist/files/types.d.ts +23 -0
  74. package/dist/files/types.js +23 -0
  75. package/dist/image-gen/imageGenTools.d.ts +2 -2
  76. package/dist/image-gen/types.d.ts +12 -12
  77. package/dist/lib/agent/directTools.d.ts +7 -7
  78. package/dist/lib/config/conversationMemory.d.ts +2 -0
  79. package/dist/lib/config/conversationMemory.js +5 -5
  80. package/dist/lib/constants/contextWindows.d.ts +46 -0
  81. package/dist/lib/constants/contextWindows.js +157 -0
  82. package/dist/lib/context/budgetChecker.d.ts +18 -0
  83. package/dist/lib/context/budgetChecker.js +72 -0
  84. package/dist/lib/context/contextCompactor.d.ts +22 -0
  85. package/dist/lib/context/contextCompactor.js +107 -0
  86. package/dist/lib/context/effectiveHistory.d.ts +52 -0
  87. package/dist/lib/context/effectiveHistory.js +106 -0
  88. package/dist/lib/context/errorDetection.d.ts +14 -0
  89. package/dist/lib/context/errorDetection.js +125 -0
  90. package/dist/lib/context/fileSummarizationService.d.ts +54 -0
  91. package/dist/lib/context/fileSummarizationService.js +256 -0
  92. package/dist/lib/context/fileSummarizer.d.ts +56 -0
  93. package/dist/lib/context/fileSummarizer.js +146 -0
  94. package/dist/lib/context/fileTokenBudget.d.ts +53 -0
  95. package/dist/lib/context/fileTokenBudget.js +128 -0
  96. package/dist/lib/context/prompts/summarizationPrompt.d.ts +17 -0
  97. package/dist/lib/context/prompts/summarizationPrompt.js +111 -0
  98. package/dist/lib/context/stages/fileReadDeduplicator.d.ts +10 -0
  99. package/dist/lib/context/stages/fileReadDeduplicator.js +67 -0
  100. package/dist/lib/context/stages/slidingWindowTruncator.d.ts +11 -0
  101. package/dist/lib/context/stages/slidingWindowTruncator.js +43 -0
  102. package/dist/lib/context/stages/structuredSummarizer.d.ts +10 -0
  103. package/dist/lib/context/stages/structuredSummarizer.js +50 -0
  104. package/dist/lib/context/stages/toolOutputPruner.d.ts +10 -0
  105. package/dist/lib/context/stages/toolOutputPruner.js +53 -0
  106. package/dist/lib/context/summarizationEngine.d.ts +45 -0
  107. package/dist/lib/context/summarizationEngine.js +111 -0
  108. package/dist/lib/context/toolOutputLimits.d.ts +17 -0
  109. package/dist/lib/context/toolOutputLimits.js +85 -0
  110. package/dist/lib/context/toolPairRepair.d.ts +16 -0
  111. package/dist/lib/context/toolPairRepair.js +67 -0
  112. package/dist/lib/core/conversationMemoryManager.d.ts +5 -15
  113. package/dist/lib/core/conversationMemoryManager.js +15 -75
  114. package/dist/lib/core/modules/MessageBuilder.d.ts +1 -1
  115. package/dist/lib/core/modules/MessageBuilder.js +2 -0
  116. package/dist/lib/core/modules/TelemetryHandler.d.ts +2 -3
  117. package/dist/lib/core/modules/TelemetryHandler.js +3 -3
  118. package/dist/lib/core/modules/ToolsManager.d.ts +2 -2
  119. package/dist/lib/core/redisConversationMemoryManager.d.ts +8 -14
  120. package/dist/lib/core/redisConversationMemoryManager.js +69 -78
  121. package/dist/lib/factories/providerFactory.d.ts +2 -2
  122. package/dist/lib/files/fileReferenceRegistry.d.ts +276 -0
  123. package/dist/lib/files/fileReferenceRegistry.js +1544 -0
  124. package/dist/lib/files/fileTools.d.ts +423 -0
  125. package/dist/lib/files/fileTools.js +450 -0
  126. package/dist/lib/files/index.d.ts +14 -0
  127. package/dist/lib/files/index.js +14 -0
  128. package/dist/lib/files/streamingReader.d.ts +93 -0
  129. package/dist/lib/files/streamingReader.js +322 -0
  130. package/dist/lib/files/types.d.ts +23 -0
  131. package/dist/lib/files/types.js +24 -0
  132. package/dist/lib/image-gen/imageGenTools.d.ts +2 -2
  133. package/dist/lib/image-gen/types.d.ts +12 -12
  134. package/dist/lib/memory/mem0Initializer.d.ts +2 -2
  135. package/dist/lib/neurolink.d.ts +61 -2
  136. package/dist/lib/neurolink.js +619 -307
  137. package/dist/lib/processors/archive/ArchiveProcessor.d.ts +327 -0
  138. package/dist/lib/processors/archive/ArchiveProcessor.js +1309 -0
  139. package/dist/lib/processors/archive/index.d.ts +33 -0
  140. package/dist/lib/processors/archive/index.js +43 -0
  141. package/dist/lib/processors/base/types.d.ts +70 -64
  142. package/dist/lib/processors/base/types.js +6 -0
  143. package/dist/lib/processors/cli/fileProcessorCli.d.ts +8 -8
  144. package/dist/lib/processors/cli/fileProcessorCli.js +5 -5
  145. package/dist/lib/processors/config/mimeTypes.js +25 -0
  146. package/dist/lib/processors/config/sizeLimits.d.ts +52 -40
  147. package/dist/lib/processors/config/sizeLimits.js +56 -44
  148. package/dist/lib/processors/document/ExcelProcessor.d.ts +14 -0
  149. package/dist/lib/processors/document/ExcelProcessor.js +72 -1
  150. package/dist/lib/processors/document/PptxProcessor.d.ts +63 -0
  151. package/dist/lib/processors/document/PptxProcessor.js +158 -0
  152. package/dist/lib/processors/document/index.d.ts +1 -0
  153. package/dist/lib/processors/document/index.js +6 -0
  154. package/dist/lib/processors/errors/FileErrorCode.d.ts +2 -2
  155. package/dist/lib/processors/errors/errorHelpers.d.ts +2 -2
  156. package/dist/lib/processors/errors/errorSerializer.d.ts +4 -4
  157. package/dist/lib/processors/index.d.ts +8 -2
  158. package/dist/lib/processors/index.js +5 -2
  159. package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +8 -8
  160. package/dist/lib/processors/integration/FileProcessorIntegration.js +7 -7
  161. package/dist/lib/processors/media/AudioProcessor.d.ts +328 -0
  162. package/dist/lib/processors/media/AudioProcessor.js +708 -0
  163. package/dist/lib/processors/media/VideoProcessor.d.ts +350 -0
  164. package/dist/lib/processors/media/VideoProcessor.js +992 -0
  165. package/dist/lib/processors/media/index.d.ts +27 -0
  166. package/dist/lib/processors/media/index.js +37 -0
  167. package/dist/lib/processors/registry/ProcessorRegistry.d.ts +19 -5
  168. package/dist/lib/processors/registry/ProcessorRegistry.js +103 -8
  169. package/dist/lib/processors/registry/index.d.ts +1 -1
  170. package/dist/lib/processors/registry/index.js +1 -1
  171. package/dist/lib/processors/registry/types.d.ts +2 -2
  172. package/dist/lib/providers/googleAiStudio.d.ts +34 -0
  173. package/dist/lib/providers/googleAiStudio.js +267 -397
  174. package/dist/lib/providers/googleVertex.d.ts +55 -1
  175. package/dist/lib/providers/googleVertex.js +452 -719
  176. package/dist/lib/providers/sagemaker/detection.d.ts +6 -6
  177. package/dist/lib/providers/sagemaker/diagnostics.d.ts +4 -4
  178. package/dist/lib/providers/sagemaker/parsers.d.ts +4 -4
  179. package/dist/lib/rag/chunkers/RecursiveChunker.js +2 -2
  180. package/dist/lib/rag/document/loaders.d.ts +6 -71
  181. package/dist/lib/rag/document/loaders.js +5 -5
  182. package/dist/lib/rag/graphRag/graphRAG.js +26 -9
  183. package/dist/lib/rag/metadata/MetadataExtractorFactory.d.ts +5 -55
  184. package/dist/lib/rag/metadata/metadataExtractor.js +6 -3
  185. package/dist/lib/rag/pipeline/RAGPipeline.d.ts +8 -126
  186. package/dist/lib/rag/pipeline/RAGPipeline.js +11 -11
  187. package/dist/lib/rag/pipeline/contextAssembly.d.ts +3 -42
  188. package/dist/lib/rag/pipeline/contextAssembly.js +6 -3
  189. package/dist/lib/rag/reranker/RerankerFactory.d.ts +5 -60
  190. package/dist/lib/rag/resilience/CircuitBreaker.d.ts +3 -33
  191. package/dist/lib/rag/resilience/RetryHandler.d.ts +2 -21
  192. package/dist/lib/rag/retrieval/hybridSearch.d.ts +3 -41
  193. package/dist/lib/rag/retrieval/vectorQueryTool.d.ts +2 -13
  194. package/dist/lib/rag/retrieval/vectorQueryTool.js +4 -3
  195. package/dist/lib/rag/types.d.ts +3 -3
  196. package/dist/lib/sdk/toolRegistration.d.ts +2 -2
  197. package/dist/lib/server/middleware/cache.d.ts +2 -2
  198. package/dist/lib/server/middleware/rateLimit.d.ts +2 -2
  199. package/dist/lib/server/routes/mcpRoutes.js +277 -249
  200. package/dist/lib/server/routes/memoryRoutes.js +287 -281
  201. package/dist/lib/server/utils/validation.d.ts +10 -10
  202. package/dist/lib/session/globalSessionState.d.ts +2 -2
  203. package/dist/lib/telemetry/telemetryService.d.ts +2 -2
  204. package/dist/lib/types/common.d.ts +39 -0
  205. package/dist/lib/types/contextTypes.d.ts +255 -0
  206. package/dist/lib/types/contextTypes.js +0 -2
  207. package/dist/lib/types/conversation.d.ts +62 -0
  208. package/dist/lib/types/conversationMemoryInterface.d.ts +27 -0
  209. package/dist/lib/types/conversationMemoryInterface.js +7 -0
  210. package/dist/lib/types/fileReferenceTypes.d.ts +222 -0
  211. package/dist/lib/types/fileReferenceTypes.js +9 -0
  212. package/dist/lib/types/fileTypes.d.ts +26 -3
  213. package/dist/lib/types/generateTypes.d.ts +22 -1
  214. package/dist/lib/types/index.d.ts +4 -5
  215. package/dist/lib/types/index.js +8 -10
  216. package/dist/lib/types/modelTypes.d.ts +2 -2
  217. package/dist/lib/types/processorTypes.d.ts +597 -0
  218. package/dist/lib/types/processorTypes.js +91 -0
  219. package/dist/lib/types/ragTypes.d.ts +481 -0
  220. package/dist/lib/types/ragTypes.js +8 -0
  221. package/dist/lib/types/sdkTypes.d.ts +17 -18
  222. package/dist/lib/types/streamTypes.d.ts +11 -1
  223. package/dist/lib/utils/async/retry.d.ts +2 -2
  224. package/dist/lib/utils/async/withTimeout.js +3 -1
  225. package/dist/lib/utils/conversationMemory.d.ts +12 -6
  226. package/dist/lib/utils/conversationMemory.js +76 -36
  227. package/dist/lib/utils/fileDetector.d.ts +62 -0
  228. package/dist/lib/utils/fileDetector.js +1014 -14
  229. package/dist/lib/utils/json/safeParse.d.ts +2 -2
  230. package/dist/lib/utils/messageBuilder.js +806 -153
  231. package/dist/lib/utils/modelChoices.d.ts +2 -2
  232. package/dist/lib/utils/multimodalOptionsBuilder.d.ts +2 -1
  233. package/dist/lib/utils/multimodalOptionsBuilder.js +1 -0
  234. package/dist/lib/utils/rateLimiter.d.ts +2 -2
  235. package/dist/lib/utils/sanitizers/filename.d.ts +4 -4
  236. package/dist/lib/utils/sanitizers/svg.d.ts +2 -2
  237. package/dist/lib/utils/thinkingConfig.d.ts +6 -6
  238. package/dist/lib/utils/tokenEstimation.d.ts +68 -0
  239. package/dist/lib/utils/tokenEstimation.js +113 -0
  240. package/dist/lib/utils/tokenUtils.d.ts +4 -4
  241. package/dist/lib/utils/ttsProcessor.d.ts +2 -2
  242. package/dist/lib/workflow/config.d.ts +150 -150
  243. package/dist/memory/mem0Initializer.d.ts +2 -2
  244. package/dist/neurolink.d.ts +61 -2
  245. package/dist/neurolink.js +619 -307
  246. package/dist/processors/archive/ArchiveProcessor.d.ts +327 -0
  247. package/dist/processors/archive/ArchiveProcessor.js +1308 -0
  248. package/dist/processors/archive/index.d.ts +33 -0
  249. package/dist/processors/archive/index.js +42 -0
  250. package/dist/processors/base/types.d.ts +70 -64
  251. package/dist/processors/base/types.js +6 -0
  252. package/dist/processors/cli/fileProcessorCli.d.ts +8 -8
  253. package/dist/processors/cli/fileProcessorCli.js +5 -5
  254. package/dist/processors/config/mimeTypes.js +25 -0
  255. package/dist/processors/config/sizeLimits.d.ts +52 -40
  256. package/dist/processors/config/sizeLimits.js +56 -44
  257. package/dist/processors/document/ExcelProcessor.d.ts +14 -0
  258. package/dist/processors/document/ExcelProcessor.js +72 -1
  259. package/dist/processors/document/PptxProcessor.d.ts +63 -0
  260. package/dist/processors/document/PptxProcessor.js +157 -0
  261. package/dist/processors/document/index.d.ts +1 -0
  262. package/dist/processors/document/index.js +6 -0
  263. package/dist/processors/errors/FileErrorCode.d.ts +2 -2
  264. package/dist/processors/errors/errorHelpers.d.ts +2 -2
  265. package/dist/processors/errors/errorSerializer.d.ts +4 -4
  266. package/dist/processors/index.d.ts +8 -2
  267. package/dist/processors/index.js +5 -2
  268. package/dist/processors/integration/FileProcessorIntegration.d.ts +8 -8
  269. package/dist/processors/integration/FileProcessorIntegration.js +7 -7
  270. package/dist/processors/media/AudioProcessor.d.ts +328 -0
  271. package/dist/processors/media/AudioProcessor.js +707 -0
  272. package/dist/processors/media/VideoProcessor.d.ts +350 -0
  273. package/dist/processors/media/VideoProcessor.js +991 -0
  274. package/dist/processors/media/ffprobe-static.d.ts +4 -0
  275. package/dist/processors/media/index.d.ts +27 -0
  276. package/dist/processors/media/index.js +36 -0
  277. package/dist/processors/registry/ProcessorRegistry.d.ts +19 -5
  278. package/dist/processors/registry/ProcessorRegistry.js +103 -8
  279. package/dist/processors/registry/index.d.ts +1 -1
  280. package/dist/processors/registry/index.js +1 -1
  281. package/dist/processors/registry/types.d.ts +2 -2
  282. package/dist/providers/googleAiStudio.d.ts +34 -0
  283. package/dist/providers/googleAiStudio.js +267 -397
  284. package/dist/providers/googleVertex.d.ts +55 -1
  285. package/dist/providers/googleVertex.js +452 -719
  286. package/dist/providers/sagemaker/detection.d.ts +6 -6
  287. package/dist/providers/sagemaker/diagnostics.d.ts +4 -4
  288. package/dist/providers/sagemaker/parsers.d.ts +4 -4
  289. package/dist/rag/chunkers/RecursiveChunker.js +2 -2
  290. package/dist/rag/document/loaders.d.ts +6 -71
  291. package/dist/rag/document/loaders.js +5 -5
  292. package/dist/rag/graphRag/graphRAG.js +26 -9
  293. package/dist/rag/metadata/MetadataExtractorFactory.d.ts +5 -55
  294. package/dist/rag/metadata/metadataExtractor.js +6 -3
  295. package/dist/rag/pipeline/RAGPipeline.d.ts +8 -126
  296. package/dist/rag/pipeline/RAGPipeline.js +11 -11
  297. package/dist/rag/pipeline/contextAssembly.d.ts +3 -42
  298. package/dist/rag/pipeline/contextAssembly.js +6 -3
  299. package/dist/rag/reranker/RerankerFactory.d.ts +5 -60
  300. package/dist/rag/resilience/CircuitBreaker.d.ts +3 -33
  301. package/dist/rag/resilience/RetryHandler.d.ts +2 -21
  302. package/dist/rag/retrieval/hybridSearch.d.ts +3 -41
  303. package/dist/rag/retrieval/vectorQueryTool.d.ts +2 -13
  304. package/dist/rag/retrieval/vectorQueryTool.js +4 -3
  305. package/dist/rag/types.d.ts +3 -3
  306. package/dist/sdk/toolRegistration.d.ts +2 -2
  307. package/dist/server/middleware/cache.d.ts +2 -2
  308. package/dist/server/middleware/rateLimit.d.ts +2 -2
  309. package/dist/server/routes/mcpRoutes.js +277 -249
  310. package/dist/server/routes/memoryRoutes.js +287 -281
  311. package/dist/server/utils/validation.d.ts +4 -4
  312. package/dist/session/globalSessionState.d.ts +2 -2
  313. package/dist/telemetry/telemetryService.d.ts +2 -2
  314. package/dist/types/common.d.ts +39 -0
  315. package/dist/types/contextTypes.d.ts +255 -0
  316. package/dist/types/contextTypes.js +0 -2
  317. package/dist/types/conversation.d.ts +62 -0
  318. package/dist/types/conversationMemoryInterface.d.ts +27 -0
  319. package/dist/types/conversationMemoryInterface.js +6 -0
  320. package/dist/types/fileReferenceTypes.d.ts +222 -0
  321. package/dist/types/fileReferenceTypes.js +8 -0
  322. package/dist/types/fileTypes.d.ts +26 -3
  323. package/dist/types/generateTypes.d.ts +22 -1
  324. package/dist/types/index.d.ts +4 -5
  325. package/dist/types/index.js +8 -10
  326. package/dist/types/processorTypes.d.ts +597 -0
  327. package/dist/types/processorTypes.js +90 -0
  328. package/dist/types/ragTypes.d.ts +481 -0
  329. package/dist/types/ragTypes.js +7 -0
  330. package/dist/types/sdkTypes.d.ts +17 -18
  331. package/dist/types/streamTypes.d.ts +11 -1
  332. package/dist/utils/async/retry.d.ts +2 -2
  333. package/dist/utils/async/withTimeout.js +3 -1
  334. package/dist/utils/conversationMemory.d.ts +12 -6
  335. package/dist/utils/conversationMemory.js +76 -36
  336. package/dist/utils/fileDetector.d.ts +62 -0
  337. package/dist/utils/fileDetector.js +1014 -14
  338. package/dist/utils/json/safeParse.d.ts +2 -2
  339. package/dist/utils/messageBuilder.js +806 -153
  340. package/dist/utils/modelChoices.d.ts +2 -2
  341. package/dist/utils/multimodalOptionsBuilder.d.ts +2 -1
  342. package/dist/utils/multimodalOptionsBuilder.js +1 -0
  343. package/dist/utils/rateLimiter.d.ts +2 -2
  344. package/dist/utils/sanitizers/filename.d.ts +4 -4
  345. package/dist/utils/sanitizers/svg.d.ts +2 -2
  346. package/dist/utils/thinkingConfig.d.ts +6 -6
  347. package/dist/utils/tokenEstimation.d.ts +68 -0
  348. package/dist/utils/tokenEstimation.js +112 -0
  349. package/dist/utils/tokenUtils.d.ts +4 -4
  350. package/dist/utils/ttsProcessor.d.ts +2 -2
  351. package/dist/workflow/config.d.ts +104 -104
  352. package/package.json +18 -6
  353. package/dist/lib/utils/conversationMemoryUtils.d.ts +0 -25
  354. package/dist/lib/utils/conversationMemoryUtils.js +0 -138
  355. package/dist/utils/conversationMemoryUtils.d.ts +0 -25
  356. 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 interface ImageGenToolDefinition {
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 interface ImageGenOptions {
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 interface ImageGenResult {
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 interface ImageGenConfig {
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 interface ImageGenToolParams {
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 interface ImageGenToolResponse {
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 interface ImageGenToolContext {
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" | "overwrite" | "append";
224
+ mode: "create" | "append" | "overwrite";
225
225
  }, {
226
226
  content: string;
227
227
  path: string;
228
- mode?: "create" | "overwrite" | "append" | undefined;
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" | "overwrite" | "append";
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" | "overwrite" | "append";
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" | "overwrite" | "append";
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
- // Deprecated (for backward compatibility)
81
- maxTurnsPerSession: Number(process.env.NEUROLINK_MEMORY_MAX_TURNS_PER_SESSION) ||
82
- DEFAULT_MAX_TURNS_PER_SESSION,
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;