@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,450 @@
1
+ /**
2
+ * On-Demand File Access Tools
3
+ *
4
+ * Exposes file operations as LLM tools via the Vercel AI SDK `tool()` pattern.
5
+ * These tools allow the LLM to access file content lazily — only reading
6
+ * the specific sections, lines, or search results it needs.
7
+ *
8
+ * Tools:
9
+ * - list_attached_files: List all registered files with metadata
10
+ * - read_file_section: Read specific line range with token budget
11
+ * - search_in_file: Search for patterns within a file
12
+ * - get_file_preview: Get the preview/summary of a file
13
+ * - extract_file_content: Targeted extraction for any file type (video frames,
14
+ * PDF pages, spreadsheet ranges, archive entries, PPTX slides)
15
+ *
16
+ * @module files/fileTools
17
+ */
18
+ import { tool } from "ai";
19
+ import { z } from "zod";
20
+ /**
21
+ * Create file access tools bound to a FileReferenceRegistry instance.
22
+ *
23
+ * These tools follow the same pattern as the existing directAgentTools
24
+ * (getCurrentTime, readFile, etc.) in src/lib/agent/directTools.ts.
25
+ * They use `tool()` from the Vercel AI SDK with zod parameter schemas.
26
+ *
27
+ * @param registry - The FileReferenceRegistry instance to bind to
28
+ * @returns Record of tool name to tool definition
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const registry = new FileReferenceRegistry();
33
+ * const tools = createFileTools(registry);
34
+ * // tools.list_attached_files, tools.read_file_section, etc.
35
+ * ```
36
+ */
37
+ export function createFileTools(registry) {
38
+ return {
39
+ list_attached_files: createListAttachedFilesTool(registry),
40
+ read_file_section: createReadFileSectionTool(registry),
41
+ search_in_file: createSearchInFileTool(registry),
42
+ get_file_preview: createGetFilePreviewTool(registry),
43
+ extract_file_content: createExtractFileContentTool(registry),
44
+ };
45
+ }
46
+ // ---------------------------------------------------------------------------
47
+ // Individual tool factory helpers
48
+ // ---------------------------------------------------------------------------
49
+ /**
50
+ * List all files that have been attached/registered for this conversation.
51
+ * Returns a formatted table with filename, type, size, and status.
52
+ */
53
+ function createListAttachedFilesTool(registry) {
54
+ return tool({
55
+ description: "List all files attached to this conversation with their metadata. " +
56
+ "Shows filename, type, size, estimated tokens, and processing status. " +
57
+ "Each file has a unique UUID 'id' field — use that ID (or the filename) " +
58
+ "as the file_id parameter in read_file_section, search_in_file, and get_file_preview. " +
59
+ "Always call this first to discover available files.",
60
+ parameters: z.object({}),
61
+ execute: async () => {
62
+ try {
63
+ const files = registry.list();
64
+ if (files.length === 0) {
65
+ return {
66
+ success: true,
67
+ message: "No files are attached to this conversation.",
68
+ fileCount: 0,
69
+ };
70
+ }
71
+ const fileList = files.map((f, i) => ({
72
+ index: i + 1,
73
+ id: f.id,
74
+ filename: f.filename,
75
+ type: f.detectedType,
76
+ size: formatSize(f.sizeBytes),
77
+ sizeBytes: f.sizeBytes,
78
+ sizeTier: f.sizeTier,
79
+ estimatedTokens: f.estimatedTokens,
80
+ status: f.status,
81
+ hasPreview: !!f.preview,
82
+ hasSummary: !!f.summary,
83
+ totalLines: f.totalLines ?? null,
84
+ }));
85
+ return {
86
+ success: true,
87
+ fileCount: files.length,
88
+ files: fileList,
89
+ formatted: registry.listFormatted(),
90
+ };
91
+ }
92
+ catch (error) {
93
+ return {
94
+ success: false,
95
+ error: error instanceof Error ? error.message : String(error),
96
+ };
97
+ }
98
+ },
99
+ });
100
+ }
101
+ /**
102
+ * Read a specific section (line range) of an attached file.
103
+ * Supports token budget to prevent reading too much content.
104
+ */
105
+ function createReadFileSectionTool(registry) {
106
+ return tool({
107
+ description: "Read specific lines from an attached file. Specify the file_id " +
108
+ "(UUID from list_attached_files, or the exact filename), start line, and end line. " +
109
+ "Uses a token budget to prevent reading too much content at once. " +
110
+ "For large files, read in sections rather than all at once.",
111
+ parameters: z.object({
112
+ file_id: z
113
+ .string()
114
+ .describe("The file ID (UUID from list_attached_files) or the exact filename"),
115
+ start_line: z
116
+ .number()
117
+ .int()
118
+ .min(1)
119
+ .default(1)
120
+ .describe("Starting line number (1-indexed, default: 1)"),
121
+ end_line: z
122
+ .number()
123
+ .int()
124
+ .min(1)
125
+ .optional()
126
+ .describe("Ending line number (1-indexed, default: read until token budget is exhausted)"),
127
+ token_budget: z
128
+ .number()
129
+ .int()
130
+ .min(100)
131
+ .max(100_000)
132
+ .default(10_000)
133
+ .describe("Maximum tokens to return (default: 10000, max: 100000)"),
134
+ }),
135
+ execute: async ({ file_id, start_line, end_line, token_budget }) => {
136
+ try {
137
+ // Resolve file_id: supports both UUID and filename
138
+ const ref = registry.getByIdOrFilename(file_id);
139
+ if (!ref) {
140
+ return {
141
+ success: false,
142
+ error: `File not found: "${file_id}". Use list_attached_files to see available file IDs.`,
143
+ };
144
+ }
145
+ const resolvedId = ref.id;
146
+ const result = await registry.readSection(resolvedId, start_line, end_line, token_budget);
147
+ return {
148
+ success: true,
149
+ content: result.content,
150
+ startLine: result.startLine,
151
+ endLine: result.endLine,
152
+ totalLines: result.totalLines,
153
+ truncated: result.truncated,
154
+ estimatedTokens: result.estimatedTokens,
155
+ guidance: result.truncated
156
+ ? `Content was truncated at token budget (${token_budget}). ` +
157
+ `Read from line ${result.endLine + 1} to continue.`
158
+ : undefined,
159
+ };
160
+ }
161
+ catch (error) {
162
+ return {
163
+ success: false,
164
+ error: error instanceof Error ? error.message : String(error),
165
+ };
166
+ }
167
+ },
168
+ });
169
+ }
170
+ /**
171
+ * Search for a text pattern or regex within an attached file.
172
+ * Returns matching lines with surrounding context.
173
+ */
174
+ function createSearchInFileTool(registry) {
175
+ return tool({
176
+ description: "Search for a text pattern within an attached file. " +
177
+ "Specify file_id as the UUID from list_attached_files or the exact filename. " +
178
+ "Supports plain text and regex patterns. Returns matching lines " +
179
+ "with context lines before and after each match. " +
180
+ "Use this to find specific content without reading the entire file.",
181
+ parameters: z.object({
182
+ file_id: z
183
+ .string()
184
+ .describe("The file ID (UUID from list_attached_files) or the exact filename"),
185
+ pattern: z
186
+ .string()
187
+ .describe("Text or regex pattern to search for (case-insensitive by default)"),
188
+ max_matches: z
189
+ .number()
190
+ .int()
191
+ .min(1)
192
+ .max(100)
193
+ .default(20)
194
+ .describe("Maximum number of matches to return (default: 20)"),
195
+ }),
196
+ execute: async ({ file_id, pattern, max_matches }) => {
197
+ try {
198
+ // Resolve file_id: supports both UUID and filename
199
+ const ref = registry.getByIdOrFilename(file_id);
200
+ if (!ref) {
201
+ return {
202
+ success: false,
203
+ error: `File not found: "${file_id}". Use list_attached_files to see available file IDs.`,
204
+ };
205
+ }
206
+ const resolvedId = ref.id;
207
+ const result = await registry.search(resolvedId, pattern, max_matches);
208
+ const formattedMatches = result.matches.map((m) => ({
209
+ lineNumber: m.lineNumber,
210
+ line: m.line,
211
+ context: m.contextBefore.length > 0 || m.contextAfter.length > 0
212
+ ? {
213
+ before: m.contextBefore,
214
+ after: m.contextAfter,
215
+ }
216
+ : undefined,
217
+ }));
218
+ return {
219
+ success: true,
220
+ pattern,
221
+ totalMatches: result.totalMatches,
222
+ matchesReturned: result.matches.length,
223
+ truncated: result.truncated,
224
+ matches: formattedMatches,
225
+ };
226
+ }
227
+ catch (error) {
228
+ return {
229
+ success: false,
230
+ error: error instanceof Error ? error.message : String(error),
231
+ };
232
+ }
233
+ },
234
+ });
235
+ }
236
+ /**
237
+ * Get the preview or summary of an attached file.
238
+ * For files that have been summarized, returns the summary.
239
+ * Otherwise returns the initial preview.
240
+ */
241
+ function createGetFilePreviewTool(registry) {
242
+ return tool({
243
+ description: "Get the preview or summary of an attached file. " +
244
+ "Specify file_id as the UUID from list_attached_files or the exact filename. " +
245
+ "Returns the file's initial preview (first ~2000 chars) or its " +
246
+ "LLM-generated summary if available. Includes file metadata.",
247
+ parameters: z.object({
248
+ file_id: z
249
+ .string()
250
+ .describe("The file ID (UUID from list_attached_files) or the exact filename"),
251
+ }),
252
+ execute: async ({ file_id }) => {
253
+ try {
254
+ // Resolve file_id: supports both UUID and filename
255
+ const ref = registry.getByIdOrFilename(file_id);
256
+ if (!ref) {
257
+ return {
258
+ success: false,
259
+ error: `File not found: "${file_id}". Use list_attached_files to see available file IDs.`,
260
+ };
261
+ }
262
+ // Ensure binary files are processed so preview contains real content
263
+ // instead of placeholder metadata like "[PDF document: 4.39 MB]"
264
+ await registry.ensureProcessed(ref.id);
265
+ return {
266
+ success: true,
267
+ filename: ref.filename,
268
+ type: ref.detectedType,
269
+ size: formatSize(ref.sizeBytes),
270
+ sizeBytes: ref.sizeBytes,
271
+ sizeTier: ref.sizeTier,
272
+ mimeType: ref.mimeType,
273
+ estimatedTokens: ref.estimatedTokens,
274
+ status: ref.status,
275
+ totalLines: ref.totalLines ?? null,
276
+ preview: ref.preview,
277
+ summary: ref.summary ?? null,
278
+ hasSummary: !!ref.summary,
279
+ };
280
+ }
281
+ catch (error) {
282
+ return {
283
+ success: false,
284
+ error: error instanceof Error ? error.message : String(error),
285
+ };
286
+ }
287
+ },
288
+ });
289
+ }
290
+ /**
291
+ * Extract targeted content from any attached file type.
292
+ * Supports type-specific parameters for deep content access.
293
+ */
294
+ function createExtractFileContentTool(registry) {
295
+ return tool({
296
+ description: "Extract specific content from an attached file. This is the universal extraction tool " +
297
+ "that handles all file types with type-specific parameters:\n" +
298
+ "- VIDEO: Use start_time/end_time to get frames from a time range\n" +
299
+ "- PDF: Use pages (e.g., [1,3,5]) or page_range to get specific pages\n" +
300
+ "- SPREADSHEET (xlsx): Use sheet, row_range, and columns for targeted data\n" +
301
+ "- PPTX: Use pages to get specific slides\n" +
302
+ "- ARCHIVE (zip): Use entry_path to extract a specific file from the archive\n" +
303
+ "- TEXT/CODE: Use page_range as line range for targeted reading\n\n" +
304
+ "For video extraction, the result includes images (frames) that will be visible to you. " +
305
+ "Always call list_attached_files first to discover file IDs.",
306
+ parameters: z.object({
307
+ file_id: z
308
+ .string()
309
+ .describe("File ID (UUID) or exact filename from list_attached_files"),
310
+ // Video parameters
311
+ start_time: z
312
+ .number()
313
+ .optional()
314
+ .describe("Start timestamp in seconds (video only)"),
315
+ end_time: z
316
+ .number()
317
+ .optional()
318
+ .describe("End timestamp in seconds (video only)"),
319
+ frame_count: z
320
+ .number()
321
+ .int()
322
+ .min(1)
323
+ .max(20)
324
+ .optional()
325
+ .describe("Number of frames to extract in time range (video only, default: 5, max: 20)"),
326
+ // PDF / PPTX parameters
327
+ pages: z
328
+ .array(z.number().int().min(1))
329
+ .optional()
330
+ .describe("Specific page/slide numbers to extract (1-indexed)"),
331
+ page_range: z
332
+ .object({
333
+ start: z.number().int().min(1),
334
+ end: z.number().int().min(1),
335
+ })
336
+ .optional()
337
+ .describe("Page/slide range to extract (1-indexed, inclusive)"),
338
+ // Spreadsheet parameters
339
+ sheet: z
340
+ .string()
341
+ .optional()
342
+ .describe("Sheet name or 0-based index as string e.g. '0', '1' (spreadsheet only, default: first sheet)"),
343
+ row_range: z
344
+ .object({
345
+ start: z.number().int().min(1),
346
+ end: z.number().int().min(1),
347
+ })
348
+ .optional()
349
+ .describe("Row range (1-indexed, spreadsheet only)"),
350
+ columns: z
351
+ .array(z.string())
352
+ .optional()
353
+ .describe("Specific column letters to include (e.g., ['A', 'B', 'D'], spreadsheet only)"),
354
+ // Archive parameters
355
+ entry_path: z
356
+ .string()
357
+ .optional()
358
+ .describe("File path within archive to extract (archive only)"),
359
+ // General
360
+ format: z
361
+ .enum(["text", "detailed", "summary"])
362
+ .optional()
363
+ .describe("Output format hint (default: text)"),
364
+ }),
365
+ execute: async (params) => {
366
+ try {
367
+ // Convert sheet from string to number if it's a numeric index
368
+ const extractParams = {
369
+ ...params,
370
+ sheet: params.sheet !== undefined
371
+ ? /^\d+$/.test(params.sheet)
372
+ ? parseInt(params.sheet, 10)
373
+ : params.sheet
374
+ : undefined,
375
+ };
376
+ const result = await registry.extractContent(extractParams);
377
+ if (!result.success) {
378
+ return {
379
+ success: false,
380
+ error: result.error,
381
+ text: undefined,
382
+ metadata: undefined,
383
+ imageCount: 0,
384
+ _images: undefined,
385
+ };
386
+ }
387
+ return {
388
+ success: true,
389
+ text: result.text,
390
+ metadata: result.metadata,
391
+ imageCount: result.images?.length ?? 0,
392
+ // Store raw buffers for experimental_toToolResultContent to convert
393
+ _images: result.images,
394
+ error: undefined,
395
+ };
396
+ }
397
+ catch (error) {
398
+ return {
399
+ success: false,
400
+ error: error instanceof Error ? error.message : String(error),
401
+ text: undefined,
402
+ metadata: undefined,
403
+ imageCount: 0,
404
+ _images: undefined,
405
+ };
406
+ }
407
+ },
408
+ experimental_toToolResultContent: (result) => {
409
+ const parts = [];
410
+ // Add text content
411
+ if (result.text) {
412
+ parts.push({ type: "text", text: result.text });
413
+ }
414
+ else if (result.error) {
415
+ parts.push({ type: "text", text: `Error: ${result.error}` });
416
+ }
417
+ // Add images as image content parts so the LLM can see them
418
+ if (result._images && result._images.length > 0) {
419
+ for (const img of result._images) {
420
+ parts.push({
421
+ type: "image",
422
+ data: img.toString("base64"),
423
+ mimeType: "image/jpeg",
424
+ });
425
+ }
426
+ }
427
+ // Fallback: always have at least one text part
428
+ if (parts.length === 0) {
429
+ parts.push({ type: "text", text: "(No content extracted)" });
430
+ }
431
+ return parts;
432
+ },
433
+ });
434
+ }
435
+ /**
436
+ * Format byte size as human-readable string.
437
+ */
438
+ function formatSize(bytes) {
439
+ if (bytes < 1024) {
440
+ return `${bytes} B`;
441
+ }
442
+ if (bytes < 1024 * 1024) {
443
+ return `${(bytes / 1024).toFixed(1)} KB`;
444
+ }
445
+ if (bytes < 1024 * 1024 * 1024) {
446
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
447
+ }
448
+ return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
449
+ }
450
+ //# sourceMappingURL=fileTools.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * File Reference Architecture
3
+ *
4
+ * Lazy on-demand file processing system. Files are registered as lightweight
5
+ * references with metadata and previews. Full content is processed on-demand
6
+ * when the LLM requests it via tools.
7
+ *
8
+ * @module files
9
+ */
10
+ export { FileReferenceRegistry } from "./fileReferenceRegistry.js";
11
+ export { createFileTools } from "./fileTools.js";
12
+ export { StreamingReader } from "./streamingReader.js";
13
+ export type { FileReadResult, FileReference, FileReferenceStatus, FileRegistrationOptions, FileRegistryOptions, FileSearchMatch, FileSearchResult, OutlineSection, SizeTier, StreamingReaderOptions, } from "./types.js";
14
+ export { SIZE_TIER_THRESHOLDS } from "./types.js";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * File Reference Architecture
3
+ *
4
+ * Lazy on-demand file processing system. Files are registered as lightweight
5
+ * references with metadata and previews. Full content is processed on-demand
6
+ * when the LLM requests it via tools.
7
+ *
8
+ * @module files
9
+ */
10
+ export { FileReferenceRegistry } from "./fileReferenceRegistry.js";
11
+ export { createFileTools } from "./fileTools.js";
12
+ export { StreamingReader } from "./streamingReader.js";
13
+ export { SIZE_TIER_THRESHOLDS } from "./types.js";
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,93 @@
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 type { FileReadResult, FileSearchResult, StreamingReaderOptions } from "./types.js";
25
+ /**
26
+ * Streaming file reader with token-budget-aware line reading.
27
+ *
28
+ * All methods use Node.js streams to avoid loading entire files into memory.
29
+ * A 2GB CSV file: only the requested lines/matches are read from disk.
30
+ */
31
+ export declare class StreamingReader {
32
+ /**
33
+ * Read lines from a file with a token budget.
34
+ *
35
+ * Uses createReadStream + readline for memory-efficient reading.
36
+ * Stops reading when the token budget is exhausted or endLine is reached.
37
+ *
38
+ * @param filePath - Absolute path to the file
39
+ * @param options - Reading options (startLine, endLine, tokenBudget, provider)
40
+ * @returns FileReadResult with content, line info, and truncation status
41
+ */
42
+ static readLines(filePath: string, options?: StreamingReaderOptions): Promise<FileReadResult>;
43
+ /**
44
+ * Count total lines in a file without reading entire content into memory.
45
+ *
46
+ * @param filePath - Absolute path to the file
47
+ * @param encoding - File encoding (default: utf-8)
48
+ * @returns Total line count
49
+ */
50
+ static countLines(filePath: string, encoding?: BufferEncoding): Promise<number>;
51
+ /**
52
+ * Search for a pattern within a file, returning matching lines with context.
53
+ *
54
+ * Uses streaming to avoid loading the entire file into memory.
55
+ * Returns up to maxMatches results, each with contextBefore/contextAfter lines.
56
+ *
57
+ * @param filePath - Absolute path to the file
58
+ * @param pattern - Regex pattern or string to search for
59
+ * @param options - Search options
60
+ * @returns FileSearchResult with matches, total count, and truncation status
61
+ */
62
+ static searchInFile(filePath: string, pattern: string | RegExp, options?: {
63
+ maxMatches?: number;
64
+ contextLines?: number;
65
+ encoding?: BufferEncoding;
66
+ }): Promise<FileSearchResult>;
67
+ /**
68
+ * Read a preview of a file (first N characters / lines).
69
+ *
70
+ * Optimized for speed: reads only the first chunk of the file.
71
+ *
72
+ * @param filePath - Absolute path to the file
73
+ * @param maxChars - Maximum characters to return (default: 2000)
74
+ * @param encoding - File encoding (default: utf-8)
75
+ * @returns Preview string
76
+ */
77
+ static readPreview(filePath: string, maxChars?: number, encoding?: BufferEncoding): Promise<string>;
78
+ /**
79
+ * Read a file from a Buffer with line range and token budget.
80
+ *
81
+ * For files already in memory (e.g., from URL download or Buffer input).
82
+ * Does NOT use streams — the buffer is already in memory.
83
+ *
84
+ * @param buffer - File content as Buffer
85
+ * @param options - Reading options
86
+ * @returns FileReadResult
87
+ */
88
+ static readFromBuffer(buffer: Buffer, options?: StreamingReaderOptions): FileReadResult;
89
+ /**
90
+ * Escape a string for use in a regular expression.
91
+ */
92
+ private static escapeRegex;
93
+ }