@juspay/neurolink 11.13.0 → 11.13.2

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 (1906) hide show
  1. package/CHANGELOG.md +2 -6
  2. package/dist/browser/neurolink.min.js +681 -842
  3. package/dist/cli/commands/agent.js +2 -2
  4. package/dist/cli/commands/auth.d.ts +1 -1
  5. package/dist/cli/commands/auth.js +11 -11
  6. package/dist/cli/commands/authProviders.d.ts +1 -1
  7. package/dist/cli/commands/authProviders.js +2 -2
  8. package/dist/cli/commands/autoresearch.js +5 -5
  9. package/dist/cli/commands/config.d.ts +1 -1
  10. package/dist/cli/commands/config.js +4 -4
  11. package/dist/cli/commands/docs.d.ts +1 -1
  12. package/dist/cli/commands/evaluate.d.ts +1 -1
  13. package/dist/cli/commands/evaluate.js +4 -4
  14. package/dist/cli/commands/mcp.js +14 -14
  15. package/dist/cli/commands/models.js +3 -3
  16. package/dist/cli/commands/observability.d.ts +1 -1
  17. package/dist/cli/commands/observability.js +3 -3
  18. package/dist/cli/commands/ollama.js +1 -1
  19. package/dist/cli/commands/proxy.d.ts +2 -2
  20. package/dist/cli/commands/proxy.js +45 -45
  21. package/dist/cli/commands/proxyAnalyze.d.ts +1 -1
  22. package/dist/cli/commands/proxyAnalyze.js +2 -2
  23. package/dist/cli/commands/proxyReplay.d.ts +1 -1
  24. package/dist/cli/commands/proxyReplay.js +2 -2
  25. package/dist/cli/commands/rag.js +10 -10
  26. package/dist/cli/commands/serve.js +7 -7
  27. package/dist/cli/commands/server.js +6 -6
  28. package/dist/cli/commands/setup-anthropic.d.ts +1 -1
  29. package/dist/cli/commands/setup-anthropic.js +3 -3
  30. package/dist/cli/commands/setup-azure.d.ts +1 -1
  31. package/dist/cli/commands/setup-azure.js +3 -3
  32. package/dist/cli/commands/setup-bedrock.d.ts +1 -1
  33. package/dist/cli/commands/setup-bedrock.js +3 -3
  34. package/dist/cli/commands/setup-gcp.d.ts +1 -1
  35. package/dist/cli/commands/setup-gcp.js +1 -1
  36. package/dist/cli/commands/setup-google-ai.d.ts +1 -1
  37. package/dist/cli/commands/setup-google-ai.js +4 -4
  38. package/dist/cli/commands/setup-huggingface.d.ts +1 -1
  39. package/dist/cli/commands/setup-huggingface.js +1 -1
  40. package/dist/cli/commands/setup-mistral.d.ts +1 -1
  41. package/dist/cli/commands/setup-mistral.js +3 -3
  42. package/dist/cli/commands/setup-openai.d.ts +1 -1
  43. package/dist/cli/commands/setup-openai.js +3 -3
  44. package/dist/cli/commands/setup.d.ts +1 -1
  45. package/dist/cli/commands/setup.js +4 -4
  46. package/dist/cli/commands/task.js +4 -4
  47. package/dist/cli/commands/telemetry.d.ts +1 -1
  48. package/dist/cli/commands/telemetry.js +4 -4
  49. package/dist/cli/commands/voiceServer.d.ts +1 -1
  50. package/dist/cli/commands/voiceServer.js +6 -2
  51. package/dist/cli/commands/workflow.js +5 -5
  52. package/dist/cli/errorHandler.js +3 -3
  53. package/dist/cli/factories/commandFactory.js +13 -13
  54. package/dist/cli/factories/ollamaCommandFactory.js +3 -3
  55. package/dist/cli/factories/sagemakerCommandFactory.js +5 -5
  56. package/dist/cli/index.js +1 -1
  57. package/dist/cli/loop/conversationSelector.d.ts +1 -1
  58. package/dist/cli/loop/conversationSelector.js +3 -3
  59. package/dist/cli/loop/optionsSchema.d.ts +1 -1
  60. package/dist/cli/loop/optionsSchema.js +1 -1
  61. package/dist/cli/loop/session.d.ts +1 -1
  62. package/dist/cli/loop/session.js +6 -6
  63. package/dist/cli/parser.js +10 -2
  64. package/dist/cli/proxy-clients/claudeCode.d.ts +1 -1
  65. package/dist/cli/proxy-clients/claudeCode.js +1 -1
  66. package/dist/cli/proxy-clients/codex.d.ts +1 -1
  67. package/dist/cli/proxy-clients/codex.js +1 -1
  68. package/dist/cli/proxy-clients/copilot.d.ts +1 -1
  69. package/dist/cli/proxy-clients/copilot.js +1 -1
  70. package/dist/cli/proxy-clients/openCode.d.ts +1 -1
  71. package/dist/cli/proxy-clients/openCode.js +1 -1
  72. package/dist/cli/proxy-clients/qwenCode.d.ts +1 -1
  73. package/dist/cli/proxy-clients/qwenCode.js +1 -1
  74. package/dist/cli/proxy-clients/registry.d.ts +1 -1
  75. package/dist/cli/proxy-clients/registry.js +1 -1
  76. package/dist/cli/utils/audioFileUtils.d.ts +1 -1
  77. package/dist/cli/utils/audioPlayer.d.ts +1 -1
  78. package/dist/cli/utils/classifierRouterFlags.d.ts +1 -1
  79. package/dist/cli/utils/classifierRouterFlags.js +1 -1
  80. package/dist/cli/utils/completeSetup.d.ts +1 -1
  81. package/dist/cli/utils/completeSetup.js +1 -1
  82. package/dist/cli/utils/envManager.d.ts +1 -1
  83. package/dist/cli/utils/envManager.js +1 -1
  84. package/dist/cli/utils/inputValidation.js +2 -2
  85. package/dist/cli/utils/interactiveSetup.d.ts +2 -2
  86. package/dist/cli/utils/interactiveSetup.js +3 -3
  87. package/dist/cli/utils/ollamaUtils.d.ts +1 -1
  88. package/dist/cli/utils/ollamaUtils.js +1 -1
  89. package/dist/cli/utils/skillsFlags.d.ts +1 -1
  90. package/dist/cli/utils/toolRoutingFlags.d.ts +1 -1
  91. package/dist/cli/utils/toolRoutingFlags.js +1 -1
  92. package/dist/cli/utils/videoFileUtils.d.ts +1 -1
  93. package/dist/processors/data/XmlProcessor.d.ts +14 -0
  94. package/dist/processors/data/XmlProcessor.js +14 -0
  95. package/dist/processors/document/PptxProcessor.d.ts +9 -0
  96. package/dist/processors/document/PptxProcessor.js +9 -0
  97. package/dist/processors/media/VideoProcessor.js +30 -2
  98. package/dist/providers/amazonBedrock/client.js +1 -2
  99. package/dist/providers/googleVertex/index.d.ts +0 -1
  100. package/dist/providers/googleVertex/index.js +0 -1
  101. package/dist/rag/document/loaders.js +49 -21
  102. package/dist/server/abstract/baseServerAdapter.d.ts +13 -0
  103. package/dist/server/abstract/baseServerAdapter.js +39 -1
  104. package/dist/server/adapters/expressAdapter.js +15 -5
  105. package/dist/server/adapters/fastifyAdapter.js +15 -5
  106. package/dist/server/adapters/koaAdapter.js +16 -6
  107. package/dist/types/generate.d.ts +7 -0
  108. package/dist/types/stream.d.ts +1 -1
  109. package/docs-site/mcp-server/search.js +20 -12
  110. package/docs-site/mcp-server/types.d.ts +12 -5
  111. package/docs-site/static/search-index.json +1 -0
  112. package/package.json +16 -16
  113. package/dist/lib/action/actionExecutor.d.ts +0 -29
  114. package/dist/lib/action/actionExecutor.js +0 -291
  115. package/dist/lib/action/actionInputs.d.ts +0 -25
  116. package/dist/lib/action/actionInputs.js +0 -294
  117. package/dist/lib/action/githubIntegration.d.ts +0 -21
  118. package/dist/lib/action/githubIntegration.js +0 -188
  119. package/dist/lib/action/index.d.ts +0 -7
  120. package/dist/lib/action/index.js +0 -13
  121. package/dist/lib/adapters/audioFormatSupport.d.ts +0 -53
  122. package/dist/lib/adapters/audioFormatSupport.js +0 -201
  123. package/dist/lib/adapters/imageFormatSupport.d.ts +0 -75
  124. package/dist/lib/adapters/imageFormatSupport.js +0 -284
  125. package/dist/lib/adapters/providerImageAdapter.d.ts +0 -51
  126. package/dist/lib/adapters/providerImageAdapter.js +0 -704
  127. package/dist/lib/adapters/replicate/auth.d.ts +0 -19
  128. package/dist/lib/adapters/replicate/auth.js +0 -33
  129. package/dist/lib/adapters/replicate/predictionLifecycle.d.ts +0 -46
  130. package/dist/lib/adapters/replicate/predictionLifecycle.js +0 -289
  131. package/dist/lib/adapters/tts/cartesiaHandler.d.ts +0 -12
  132. package/dist/lib/adapters/tts/cartesiaHandler.js +0 -131
  133. package/dist/lib/adapters/tts/googleTTSHandler.d.ts +0 -97
  134. package/dist/lib/adapters/tts/googleTTSHandler.js +0 -353
  135. package/dist/lib/adapters/video/directorPipeline.d.ts +0 -31
  136. package/dist/lib/adapters/video/directorPipeline.js +0 -523
  137. package/dist/lib/adapters/video/ffmpegAdapter.d.ts +0 -84
  138. package/dist/lib/adapters/video/ffmpegAdapter.js +0 -207
  139. package/dist/lib/adapters/video/frameExtractor.d.ts +0 -28
  140. package/dist/lib/adapters/video/frameExtractor.js +0 -144
  141. package/dist/lib/adapters/video/klingVideoHandler.d.ts +0 -37
  142. package/dist/lib/adapters/video/klingVideoHandler.js +0 -306
  143. package/dist/lib/adapters/video/replicateVideoHandler.d.ts +0 -29
  144. package/dist/lib/adapters/video/replicateVideoHandler.js +0 -168
  145. package/dist/lib/adapters/video/runwayVideoHandler.d.ts +0 -32
  146. package/dist/lib/adapters/video/runwayVideoHandler.js +0 -317
  147. package/dist/lib/adapters/video/vertexVideoHandler.d.ts +0 -119
  148. package/dist/lib/adapters/video/vertexVideoHandler.js +0 -804
  149. package/dist/lib/adapters/video/videoAnalyzer.d.ts +0 -26
  150. package/dist/lib/adapters/video/videoAnalyzer.js +0 -239
  151. package/dist/lib/adapters/video/videoMerger.d.ts +0 -22
  152. package/dist/lib/adapters/video/videoMerger.js +0 -172
  153. package/dist/lib/agent/agent.d.ts +0 -104
  154. package/dist/lib/agent/agent.js +0 -433
  155. package/dist/lib/agent/agentNetwork.d.ts +0 -87
  156. package/dist/lib/agent/agentNetwork.js +0 -501
  157. package/dist/lib/agent/agentToolRegistrar.d.ts +0 -48
  158. package/dist/lib/agent/agentToolRegistrar.js +0 -337
  159. package/dist/lib/agent/communication/index.d.ts +0 -9
  160. package/dist/lib/agent/communication/index.js +0 -10
  161. package/dist/lib/agent/communication/message-bus.d.ts +0 -113
  162. package/dist/lib/agent/communication/message-bus.js +0 -407
  163. package/dist/lib/agent/coordination/coordinator.d.ts +0 -83
  164. package/dist/lib/agent/coordination/coordinator.js +0 -599
  165. package/dist/lib/agent/coordination/index.d.ts +0 -10
  166. package/dist/lib/agent/coordination/index.js +0 -11
  167. package/dist/lib/agent/coordination/task-distributor.d.ts +0 -113
  168. package/dist/lib/agent/coordination/task-distributor.js +0 -586
  169. package/dist/lib/agent/directTools.d.ts +0 -306
  170. package/dist/lib/agent/directTools.js +0 -907
  171. package/dist/lib/agent/index.d.ts +0 -41
  172. package/dist/lib/agent/index.js +0 -49
  173. package/dist/lib/agent/isolatedAgentRunner.d.ts +0 -73
  174. package/dist/lib/agent/isolatedAgentRunner.js +0 -947
  175. package/dist/lib/agent/orchestration/index.d.ts +0 -10
  176. package/dist/lib/agent/orchestration/index.js +0 -11
  177. package/dist/lib/agent/orchestration/orchestrator.d.ts +0 -114
  178. package/dist/lib/agent/orchestration/orchestrator.js +0 -479
  179. package/dist/lib/agent/orchestration/topology.d.ts +0 -164
  180. package/dist/lib/agent/orchestration/topology.js +0 -521
  181. package/dist/lib/agent/prompts/routingPrompts.d.ts +0 -63
  182. package/dist/lib/agent/prompts/routingPrompts.js +0 -202
  183. package/dist/lib/agent/structuredRecovery.d.ts +0 -30
  184. package/dist/lib/agent/structuredRecovery.js +0 -105
  185. package/dist/lib/analytics/index.d.ts +0 -7
  186. package/dist/lib/analytics/index.js +0 -8
  187. package/dist/lib/analytics/parseQualityScore.d.ts +0 -9
  188. package/dist/lib/analytics/parseQualityScore.js +0 -30
  189. package/dist/lib/analytics/pricing.d.ts +0 -27
  190. package/dist/lib/analytics/pricing.js +0 -42
  191. package/dist/lib/analytics/service.d.ts +0 -36
  192. package/dist/lib/analytics/service.js +0 -394
  193. package/dist/lib/analytics/storage.d.ts +0 -19
  194. package/dist/lib/analytics/storage.js +0 -33
  195. package/dist/lib/artifacts/artifactStore.d.ts +0 -55
  196. package/dist/lib/artifacts/artifactStore.js +0 -145
  197. package/dist/lib/auth/AuthProviderFactory.d.ts +0 -69
  198. package/dist/lib/auth/AuthProviderFactory.js +0 -112
  199. package/dist/lib/auth/AuthProviderRegistry.d.ts +0 -33
  200. package/dist/lib/auth/AuthProviderRegistry.js +0 -191
  201. package/dist/lib/auth/RequestContext.d.ts +0 -23
  202. package/dist/lib/auth/RequestContext.js +0 -79
  203. package/dist/lib/auth/accountPool.d.ts +0 -68
  204. package/dist/lib/auth/accountPool.js +0 -179
  205. package/dist/lib/auth/anthropicOAuth.d.ts +0 -400
  206. package/dist/lib/auth/anthropicOAuth.js +0 -1143
  207. package/dist/lib/auth/authContext.d.ts +0 -198
  208. package/dist/lib/auth/authContext.js +0 -315
  209. package/dist/lib/auth/codexOAuth.d.ts +0 -67
  210. package/dist/lib/auth/codexOAuth.js +0 -203
  211. package/dist/lib/auth/errors.d.ts +0 -63
  212. package/dist/lib/auth/errors.js +0 -40
  213. package/dist/lib/auth/index.d.ts +0 -41
  214. package/dist/lib/auth/index.js +0 -86
  215. package/dist/lib/auth/middleware/AuthMiddleware.d.ts +0 -127
  216. package/dist/lib/auth/middleware/AuthMiddleware.js +0 -523
  217. package/dist/lib/auth/middleware/rateLimitByUser.d.ts +0 -193
  218. package/dist/lib/auth/middleware/rateLimitByUser.js +0 -559
  219. package/dist/lib/auth/providers/BaseAuthProvider.d.ts +0 -259
  220. package/dist/lib/auth/providers/BaseAuthProvider.js +0 -724
  221. package/dist/lib/auth/providers/CognitoProvider.d.ts +0 -61
  222. package/dist/lib/auth/providers/CognitoProvider.js +0 -308
  223. package/dist/lib/auth/providers/KeycloakProvider.d.ts +0 -61
  224. package/dist/lib/auth/providers/KeycloakProvider.js +0 -396
  225. package/dist/lib/auth/providers/auth0.d.ts +0 -59
  226. package/dist/lib/auth/providers/auth0.js +0 -275
  227. package/dist/lib/auth/providers/betterAuth.d.ts +0 -51
  228. package/dist/lib/auth/providers/betterAuth.js +0 -183
  229. package/dist/lib/auth/providers/clerk.d.ts +0 -65
  230. package/dist/lib/auth/providers/clerk.js +0 -318
  231. package/dist/lib/auth/providers/custom.d.ts +0 -64
  232. package/dist/lib/auth/providers/custom.js +0 -113
  233. package/dist/lib/auth/providers/firebase.d.ts +0 -63
  234. package/dist/lib/auth/providers/firebase.js +0 -231
  235. package/dist/lib/auth/providers/jwt.d.ts +0 -68
  236. package/dist/lib/auth/providers/jwt.js +0 -217
  237. package/dist/lib/auth/providers/oauth2.d.ts +0 -73
  238. package/dist/lib/auth/providers/oauth2.js +0 -304
  239. package/dist/lib/auth/providers/supabase.d.ts +0 -63
  240. package/dist/lib/auth/providers/supabase.js +0 -260
  241. package/dist/lib/auth/providers/workos.d.ts +0 -61
  242. package/dist/lib/auth/providers/workos.js +0 -289
  243. package/dist/lib/auth/serverBridge.d.ts +0 -14
  244. package/dist/lib/auth/serverBridge.js +0 -26
  245. package/dist/lib/auth/sessionManager.d.ts +0 -118
  246. package/dist/lib/auth/sessionManager.js +0 -511
  247. package/dist/lib/auth/tokenStore.d.ts +0 -283
  248. package/dist/lib/auth/tokenStore.js +0 -929
  249. package/dist/lib/autoresearch/config.d.ts +0 -11
  250. package/dist/lib/autoresearch/config.js +0 -109
  251. package/dist/lib/autoresearch/errors.d.ts +0 -40
  252. package/dist/lib/autoresearch/errors.js +0 -21
  253. package/dist/lib/autoresearch/index.d.ts +0 -23
  254. package/dist/lib/autoresearch/index.js +0 -35
  255. package/dist/lib/autoresearch/phasePolicy.d.ts +0 -9
  256. package/dist/lib/autoresearch/phasePolicy.js +0 -70
  257. package/dist/lib/autoresearch/promptCompiler.d.ts +0 -15
  258. package/dist/lib/autoresearch/promptCompiler.js +0 -121
  259. package/dist/lib/autoresearch/repoPolicy.d.ts +0 -32
  260. package/dist/lib/autoresearch/repoPolicy.js +0 -129
  261. package/dist/lib/autoresearch/resultRecorder.d.ts +0 -20
  262. package/dist/lib/autoresearch/resultRecorder.js +0 -131
  263. package/dist/lib/autoresearch/runner.d.ts +0 -10
  264. package/dist/lib/autoresearch/runner.js +0 -109
  265. package/dist/lib/autoresearch/stateStore.d.ts +0 -12
  266. package/dist/lib/autoresearch/stateStore.js +0 -164
  267. package/dist/lib/autoresearch/summaryParser.d.ts +0 -16
  268. package/dist/lib/autoresearch/summaryParser.js +0 -95
  269. package/dist/lib/autoresearch/tools.d.ts +0 -27
  270. package/dist/lib/autoresearch/tools.js +0 -618
  271. package/dist/lib/autoresearch/worker.d.ts +0 -71
  272. package/dist/lib/autoresearch/worker.js +0 -418
  273. package/dist/lib/avatar/index.d.ts +0 -26
  274. package/dist/lib/avatar/index.js +0 -86
  275. package/dist/lib/avatar/providers/DIDAvatar.d.ts +0 -49
  276. package/dist/lib/avatar/providers/DIDAvatar.js +0 -502
  277. package/dist/lib/avatar/providers/HeyGenAvatar.d.ts +0 -30
  278. package/dist/lib/avatar/providers/HeyGenAvatar.js +0 -338
  279. package/dist/lib/avatar/providers/ReplicateAvatar.d.ts +0 -36
  280. package/dist/lib/avatar/providers/ReplicateAvatar.js +0 -268
  281. package/dist/lib/client/aiSdkAdapter.d.ts +0 -196
  282. package/dist/lib/client/aiSdkAdapter.js +0 -498
  283. package/dist/lib/client/auth.d.ts +0 -248
  284. package/dist/lib/client/auth.js +0 -469
  285. package/dist/lib/client/errors.d.ts +0 -298
  286. package/dist/lib/client/errors.js +0 -553
  287. package/dist/lib/client/httpClient.d.ts +0 -296
  288. package/dist/lib/client/httpClient.js +0 -851
  289. package/dist/lib/client/index.d.ts +0 -103
  290. package/dist/lib/client/index.js +0 -174
  291. package/dist/lib/client/interceptors.d.ts +0 -207
  292. package/dist/lib/client/interceptors.js +0 -620
  293. package/dist/lib/client/reactHooks.d.ts +0 -238
  294. package/dist/lib/client/reactHooks.js +0 -1168
  295. package/dist/lib/client/sseClient.d.ts +0 -115
  296. package/dist/lib/client/sseClient.js +0 -575
  297. package/dist/lib/client/streamingClient.d.ts +0 -255
  298. package/dist/lib/client/streamingClient.js +0 -963
  299. package/dist/lib/client/wsClient.d.ts +0 -127
  300. package/dist/lib/client/wsClient.js +0 -450
  301. package/dist/lib/config/configManager.d.ts +0 -60
  302. package/dist/lib/config/configManager.js +0 -304
  303. package/dist/lib/config/conversationMemory.d.ts +0 -51
  304. package/dist/lib/config/conversationMemory.js +0 -87
  305. package/dist/lib/config/modelSpecificPrompts.d.ts +0 -9
  306. package/dist/lib/config/modelSpecificPrompts.js +0 -39
  307. package/dist/lib/config/taskClassificationConfig.d.ts +0 -51
  308. package/dist/lib/config/taskClassificationConfig.js +0 -149
  309. package/dist/lib/constants/contextWindows.d.ts +0 -89
  310. package/dist/lib/constants/contextWindows.js +0 -568
  311. package/dist/lib/constants/enums.d.ts +0 -979
  312. package/dist/lib/constants/enums.js +0 -1247
  313. package/dist/lib/constants/index.d.ts +0 -184
  314. package/dist/lib/constants/index.js +0 -209
  315. package/dist/lib/constants/networkErrorCodes.d.ts +0 -14
  316. package/dist/lib/constants/networkErrorCodes.js +0 -22
  317. package/dist/lib/constants/performance.d.ts +0 -366
  318. package/dist/lib/constants/performance.js +0 -390
  319. package/dist/lib/constants/retry.d.ts +0 -224
  320. package/dist/lib/constants/retry.js +0 -267
  321. package/dist/lib/constants/timeouts.d.ts +0 -225
  322. package/dist/lib/constants/timeouts.js +0 -183
  323. package/dist/lib/constants/tokens.d.ts +0 -294
  324. package/dist/lib/constants/tokens.js +0 -381
  325. package/dist/lib/constants/videoErrors.d.ts +0 -49
  326. package/dist/lib/constants/videoErrors.js +0 -51
  327. package/dist/lib/context/anthropicLoopGuard.d.ts +0 -47
  328. package/dist/lib/context/anthropicLoopGuard.js +0 -186
  329. package/dist/lib/context/budgetChecker.d.ts +0 -33
  330. package/dist/lib/context/budgetChecker.js +0 -132
  331. package/dist/lib/context/contextCompactor.d.ts +0 -19
  332. package/dist/lib/context/contextCompactor.js +0 -258
  333. package/dist/lib/context/effectiveHistory.d.ts +0 -52
  334. package/dist/lib/context/effectiveHistory.js +0 -106
  335. package/dist/lib/context/emergencyTruncation.d.ts +0 -21
  336. package/dist/lib/context/emergencyTruncation.js +0 -89
  337. package/dist/lib/context/errorDetection.d.ts +0 -36
  338. package/dist/lib/context/errorDetection.js +0 -190
  339. package/dist/lib/context/errors.d.ts +0 -19
  340. package/dist/lib/context/errors.js +0 -22
  341. package/dist/lib/context/fileSummarizationService.d.ts +0 -45
  342. package/dist/lib/context/fileSummarizationService.js +0 -256
  343. package/dist/lib/context/fileSummarizer.d.ts +0 -55
  344. package/dist/lib/context/fileSummarizer.js +0 -146
  345. package/dist/lib/context/fileTokenBudget.d.ts +0 -52
  346. package/dist/lib/context/fileTokenBudget.js +0 -128
  347. package/dist/lib/context/geminiLoopGuard.d.ts +0 -54
  348. package/dist/lib/context/geminiLoopGuard.js +0 -141
  349. package/dist/lib/context/loopGuardCore.d.ts +0 -43
  350. package/dist/lib/context/loopGuardCore.js +0 -146
  351. package/dist/lib/context/openaiCompatLoopGuard.d.ts +0 -42
  352. package/dist/lib/context/openaiCompatLoopGuard.js +0 -173
  353. package/dist/lib/context/prompts/summarizationPrompt.d.ts +0 -16
  354. package/dist/lib/context/prompts/summarizationPrompt.js +0 -118
  355. package/dist/lib/context/stages/fileReadDeduplicator.d.ts +0 -8
  356. package/dist/lib/context/stages/fileReadDeduplicator.js +0 -67
  357. package/dist/lib/context/stages/slidingWindowTruncator.d.ts +0 -15
  358. package/dist/lib/context/stages/slidingWindowTruncator.js +0 -237
  359. package/dist/lib/context/stages/structuredSummarizer.d.ts +0 -8
  360. package/dist/lib/context/stages/structuredSummarizer.js +0 -123
  361. package/dist/lib/context/stages/toolOutputPruner.d.ts +0 -8
  362. package/dist/lib/context/stages/toolOutputPruner.js +0 -53
  363. package/dist/lib/context/stepBudgetGuard.d.ts +0 -61
  364. package/dist/lib/context/stepBudgetGuard.js +0 -358
  365. package/dist/lib/context/summarizationEngine.d.ts +0 -45
  366. package/dist/lib/context/summarizationEngine.js +0 -162
  367. package/dist/lib/context/toolOutputLimits.d.ts +0 -36
  368. package/dist/lib/context/toolOutputLimits.js +0 -95
  369. package/dist/lib/context/toolPairRepair.d.ts +0 -43
  370. package/dist/lib/context/toolPairRepair.js +0 -242
  371. package/dist/lib/core/analytics.d.ts +0 -11
  372. package/dist/lib/core/analytics.js +0 -117
  373. package/dist/lib/core/baseProvider.d.ts +0 -500
  374. package/dist/lib/core/baseProvider.js +0 -2081
  375. package/dist/lib/core/constants.d.ts +0 -146
  376. package/dist/lib/core/constants.js +0 -278
  377. package/dist/lib/core/conversationMemoryFactory.d.ts +0 -19
  378. package/dist/lib/core/conversationMemoryFactory.js +0 -147
  379. package/dist/lib/core/conversationMemoryInitializer.d.ts +0 -14
  380. package/dist/lib/core/conversationMemoryInitializer.js +0 -129
  381. package/dist/lib/core/conversationMemoryManager.d.ts +0 -110
  382. package/dist/lib/core/conversationMemoryManager.js +0 -471
  383. package/dist/lib/core/dynamicModels.d.ts +0 -89
  384. package/dist/lib/core/dynamicModels.js +0 -337
  385. package/dist/lib/core/evaluation.d.ts +0 -18
  386. package/dist/lib/core/evaluation.js +0 -310
  387. package/dist/lib/core/evaluationProviders.d.ts +0 -60
  388. package/dist/lib/core/evaluationProviders.js +0 -249
  389. package/dist/lib/core/factory.d.ts +0 -54
  390. package/dist/lib/core/factory.js +0 -364
  391. package/dist/lib/core/geminiLoopAdapter.d.ts +0 -20
  392. package/dist/lib/core/geminiLoopAdapter.js +0 -171
  393. package/dist/lib/core/handlerRegistry.d.ts +0 -29
  394. package/dist/lib/core/handlerRegistry.js +0 -62
  395. package/dist/lib/core/infrastructure/baseError.d.ts +0 -21
  396. package/dist/lib/core/infrastructure/baseError.js +0 -23
  397. package/dist/lib/core/infrastructure/baseFactory.d.ts +0 -16
  398. package/dist/lib/core/infrastructure/baseFactory.js +0 -55
  399. package/dist/lib/core/infrastructure/baseRegistry.d.ts +0 -19
  400. package/dist/lib/core/infrastructure/baseRegistry.js +0 -54
  401. package/dist/lib/core/infrastructure/index.d.ts +0 -5
  402. package/dist/lib/core/infrastructure/index.js +0 -6
  403. package/dist/lib/core/infrastructure/retry.d.ts +0 -2
  404. package/dist/lib/core/infrastructure/retry.js +0 -21
  405. package/dist/lib/core/infrastructure/typedEventEmitter.d.ts +0 -8
  406. package/dist/lib/core/infrastructure/typedEventEmitter.js +0 -24
  407. package/dist/lib/core/loopEngine.d.ts +0 -21
  408. package/dist/lib/core/loopEngine.js +0 -272
  409. package/dist/lib/core/modelConfiguration.d.ts +0 -179
  410. package/dist/lib/core/modelConfiguration.js +0 -549
  411. package/dist/lib/core/modules/GenerationHandler.d.ts +0 -135
  412. package/dist/lib/core/modules/GenerationHandler.js +0 -1028
  413. package/dist/lib/core/modules/MessageBuilder.d.ts +0 -24
  414. package/dist/lib/core/modules/MessageBuilder.js +0 -311
  415. package/dist/lib/core/modules/StreamHandler.d.ts +0 -70
  416. package/dist/lib/core/modules/StreamHandler.js +0 -229
  417. package/dist/lib/core/modules/TelemetryHandler.d.ts +0 -70
  418. package/dist/lib/core/modules/TelemetryHandler.js +0 -229
  419. package/dist/lib/core/modules/ToolsManager.d.ts +0 -105
  420. package/dist/lib/core/modules/ToolsManager.js +0 -737
  421. package/dist/lib/core/modules/Utilities.d.ts +0 -90
  422. package/dist/lib/core/modules/Utilities.js +0 -347
  423. package/dist/lib/core/modules/structuredOutputPolicy.d.ts +0 -91
  424. package/dist/lib/core/modules/structuredOutputPolicy.js +0 -136
  425. package/dist/lib/core/nativeToolFormat.d.ts +0 -33
  426. package/dist/lib/core/nativeToolFormat.js +0 -31
  427. package/dist/lib/core/redisConversationMemoryManager.d.ts +0 -235
  428. package/dist/lib/core/redisConversationMemoryManager.js +0 -1724
  429. package/dist/lib/core/serviceRegistry.d.ts +0 -40
  430. package/dist/lib/core/serviceRegistry.js +0 -113
  431. package/dist/lib/core/streamAnalytics.d.ts +0 -27
  432. package/dist/lib/core/streamAnalytics.js +0 -132
  433. package/dist/lib/core/streamChannel.d.ts +0 -10
  434. package/dist/lib/core/streamChannel.js +0 -77
  435. package/dist/lib/core/toolDedup.d.ts +0 -51
  436. package/dist/lib/core/toolDedup.js +0 -197
  437. package/dist/lib/core/toolEvents.d.ts +0 -2
  438. package/dist/lib/core/toolEvents.js +0 -8
  439. package/dist/lib/core/toolExecutionRecorder.d.ts +0 -76
  440. package/dist/lib/core/toolExecutionRecorder.js +0 -261
  441. package/dist/lib/core/toolRouting.d.ts +0 -68
  442. package/dist/lib/core/toolRouting.js +0 -496
  443. package/dist/lib/core/toolRoutingCache.d.ts +0 -64
  444. package/dist/lib/core/toolRoutingCache.js +0 -155
  445. package/dist/lib/core/toolRoutingEmbedding.d.ts +0 -112
  446. package/dist/lib/core/toolRoutingEmbedding.js +0 -323
  447. package/dist/lib/dynamic/dynamicResolver.d.ts +0 -282
  448. package/dist/lib/dynamic/dynamicResolver.js +0 -634
  449. package/dist/lib/dynamic/index.d.ts +0 -10
  450. package/dist/lib/dynamic/index.js +0 -13
  451. package/dist/lib/dynamic/resolution.d.ts +0 -17
  452. package/dist/lib/dynamic/resolution.js +0 -22
  453. package/dist/lib/evaluation/BatchEvaluator.d.ts +0 -65
  454. package/dist/lib/evaluation/BatchEvaluator.js +0 -271
  455. package/dist/lib/evaluation/EvaluationAggregator.d.ts +0 -156
  456. package/dist/lib/evaluation/EvaluationAggregator.js +0 -378
  457. package/dist/lib/evaluation/EvaluatorFactory.d.ts +0 -102
  458. package/dist/lib/evaluation/EvaluatorFactory.js +0 -281
  459. package/dist/lib/evaluation/EvaluatorRegistry.d.ts +0 -111
  460. package/dist/lib/evaluation/EvaluatorRegistry.js +0 -185
  461. package/dist/lib/evaluation/contextBuilder.d.ts +0 -44
  462. package/dist/lib/evaluation/contextBuilder.js +0 -132
  463. package/dist/lib/evaluation/errors/EvaluationError.d.ts +0 -161
  464. package/dist/lib/evaluation/errors/EvaluationError.js +0 -207
  465. package/dist/lib/evaluation/errors/index.d.ts +0 -4
  466. package/dist/lib/evaluation/errors/index.js +0 -5
  467. package/dist/lib/evaluation/hooks/index.d.ts +0 -6
  468. package/dist/lib/evaluation/hooks/index.js +0 -7
  469. package/dist/lib/evaluation/hooks/langfuseAdapter.d.ts +0 -62
  470. package/dist/lib/evaluation/hooks/langfuseAdapter.js +0 -173
  471. package/dist/lib/evaluation/hooks/observabilityHooks.d.ts +0 -77
  472. package/dist/lib/evaluation/hooks/observabilityHooks.js +0 -187
  473. package/dist/lib/evaluation/index.d.ts +0 -41
  474. package/dist/lib/evaluation/index.js +0 -78
  475. package/dist/lib/evaluation/pipeline/evaluationPipeline.d.ts +0 -83
  476. package/dist/lib/evaluation/pipeline/evaluationPipeline.js +0 -397
  477. package/dist/lib/evaluation/pipeline/index.d.ts +0 -8
  478. package/dist/lib/evaluation/pipeline/index.js +0 -9
  479. package/dist/lib/evaluation/pipeline/pipelineBuilder.d.ts +0 -126
  480. package/dist/lib/evaluation/pipeline/pipelineBuilder.js +0 -261
  481. package/dist/lib/evaluation/pipeline/presets.d.ts +0 -66
  482. package/dist/lib/evaluation/pipeline/presets.js +0 -225
  483. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.d.ts +0 -46
  484. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.js +0 -242
  485. package/dist/lib/evaluation/pipeline/strategies/index.d.ts +0 -6
  486. package/dist/lib/evaluation/pipeline/strategies/index.js +0 -7
  487. package/dist/lib/evaluation/pipeline/strategies/samplingStrategy.d.ts +0 -76
  488. package/dist/lib/evaluation/pipeline/strategies/samplingStrategy.js +0 -247
  489. package/dist/lib/evaluation/prompts.d.ts +0 -22
  490. package/dist/lib/evaluation/prompts.js +0 -74
  491. package/dist/lib/evaluation/ragasEvaluator.d.ts +0 -28
  492. package/dist/lib/evaluation/ragasEvaluator.js +0 -127
  493. package/dist/lib/evaluation/reporting/index.d.ts +0 -6
  494. package/dist/lib/evaluation/reporting/index.js +0 -7
  495. package/dist/lib/evaluation/reporting/metricsCollector.d.ts +0 -88
  496. package/dist/lib/evaluation/reporting/metricsCollector.js +0 -286
  497. package/dist/lib/evaluation/reporting/reportGenerator.d.ts +0 -57
  498. package/dist/lib/evaluation/reporting/reportGenerator.js +0 -375
  499. package/dist/lib/evaluation/retryManager.d.ts +0 -39
  500. package/dist/lib/evaluation/retryManager.js +0 -79
  501. package/dist/lib/evaluation/scorers/baseScorer.d.ts +0 -82
  502. package/dist/lib/evaluation/scorers/baseScorer.js +0 -233
  503. package/dist/lib/evaluation/scorers/customScorerUtils.d.ts +0 -86
  504. package/dist/lib/evaluation/scorers/customScorerUtils.js +0 -382
  505. package/dist/lib/evaluation/scorers/index.d.ts +0 -10
  506. package/dist/lib/evaluation/scorers/index.js +0 -17
  507. package/dist/lib/evaluation/scorers/llm/answerRelevancyScorer.d.ts +0 -12
  508. package/dist/lib/evaluation/scorers/llm/answerRelevancyScorer.js +0 -100
  509. package/dist/lib/evaluation/scorers/llm/baseLLMScorer.d.ts +0 -69
  510. package/dist/lib/evaluation/scorers/llm/baseLLMScorer.js +0 -282
  511. package/dist/lib/evaluation/scorers/llm/biasDetectionScorer.d.ts +0 -12
  512. package/dist/lib/evaluation/scorers/llm/biasDetectionScorer.js +0 -128
  513. package/dist/lib/evaluation/scorers/llm/contextPrecisionScorer.d.ts +0 -12
  514. package/dist/lib/evaluation/scorers/llm/contextPrecisionScorer.js +0 -93
  515. package/dist/lib/evaluation/scorers/llm/contextRelevancyScorer.d.ts +0 -12
  516. package/dist/lib/evaluation/scorers/llm/contextRelevancyScorer.js +0 -108
  517. package/dist/lib/evaluation/scorers/llm/faithfulnessScorer.d.ts +0 -12
  518. package/dist/lib/evaluation/scorers/llm/faithfulnessScorer.js +0 -122
  519. package/dist/lib/evaluation/scorers/llm/hallucinationScorer.d.ts +0 -12
  520. package/dist/lib/evaluation/scorers/llm/hallucinationScorer.js +0 -141
  521. package/dist/lib/evaluation/scorers/llm/index.d.ts +0 -15
  522. package/dist/lib/evaluation/scorers/llm/index.js +0 -17
  523. package/dist/lib/evaluation/scorers/llm/promptAlignmentScorer.d.ts +0 -12
  524. package/dist/lib/evaluation/scorers/llm/promptAlignmentScorer.js +0 -107
  525. package/dist/lib/evaluation/scorers/llm/summarizationScorer.d.ts +0 -12
  526. package/dist/lib/evaluation/scorers/llm/summarizationScorer.js +0 -115
  527. package/dist/lib/evaluation/scorers/llm/toneConsistencyScorer.d.ts +0 -12
  528. package/dist/lib/evaluation/scorers/llm/toneConsistencyScorer.js +0 -107
  529. package/dist/lib/evaluation/scorers/llm/toxicityScorer.d.ts +0 -12
  530. package/dist/lib/evaluation/scorers/llm/toxicityScorer.js +0 -122
  531. package/dist/lib/evaluation/scorers/rule/baseRuleScorer.d.ts +0 -77
  532. package/dist/lib/evaluation/scorers/rule/baseRuleScorer.js +0 -234
  533. package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.d.ts +0 -81
  534. package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.js +0 -353
  535. package/dist/lib/evaluation/scorers/rule/formatScorer.d.ts +0 -107
  536. package/dist/lib/evaluation/scorers/rule/formatScorer.js +0 -471
  537. package/dist/lib/evaluation/scorers/rule/index.d.ts +0 -9
  538. package/dist/lib/evaluation/scorers/rule/index.js +0 -11
  539. package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.d.ts +0 -66
  540. package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.js +0 -348
  541. package/dist/lib/evaluation/scorers/rule/lengthScorer.d.ts +0 -74
  542. package/dist/lib/evaluation/scorers/rule/lengthScorer.js +0 -352
  543. package/dist/lib/evaluation/scorers/scorerBuilder.d.ts +0 -160
  544. package/dist/lib/evaluation/scorers/scorerBuilder.js +0 -421
  545. package/dist/lib/evaluation/scorers/scorerRegistry.d.ts +0 -65
  546. package/dist/lib/evaluation/scorers/scorerRegistry.js +0 -540
  547. package/dist/lib/evaluation/scoring.d.ts +0 -15
  548. package/dist/lib/evaluation/scoring.js +0 -61
  549. package/dist/lib/factories/providerDescriptors.d.ts +0 -18
  550. package/dist/lib/factories/providerDescriptors.js +0 -547
  551. package/dist/lib/factories/providerFactory.d.ts +0 -87
  552. package/dist/lib/factories/providerFactory.js +0 -199
  553. package/dist/lib/factories/providerRegistry.d.ts +0 -58
  554. package/dist/lib/factories/providerRegistry.js +0 -549
  555. package/dist/lib/features/ppt/constants.d.ts +0 -121
  556. package/dist/lib/features/ppt/constants.js +0 -897
  557. package/dist/lib/features/ppt/contentPlanner.d.ts +0 -47
  558. package/dist/lib/features/ppt/contentPlanner.js +0 -558
  559. package/dist/lib/features/ppt/index.d.ts +0 -11
  560. package/dist/lib/features/ppt/index.js +0 -33
  561. package/dist/lib/features/ppt/pptError.d.ts +0 -38
  562. package/dist/lib/features/ppt/pptError.js +0 -54
  563. package/dist/lib/features/ppt/presentationOrchestrator.d.ts +0 -37
  564. package/dist/lib/features/ppt/presentationOrchestrator.js +0 -231
  565. package/dist/lib/features/ppt/slideGenerator.d.ts +0 -56
  566. package/dist/lib/features/ppt/slideGenerator.js +0 -542
  567. package/dist/lib/features/ppt/slideRenderers.d.ts +0 -347
  568. package/dist/lib/features/ppt/slideRenderers.js +0 -2384
  569. package/dist/lib/features/ppt/slideTypeInference.d.ts +0 -91
  570. package/dist/lib/features/ppt/slideTypeInference.js +0 -406
  571. package/dist/lib/features/ppt/utils.d.ts +0 -103
  572. package/dist/lib/features/ppt/utils.js +0 -446
  573. package/dist/lib/files/fileReferenceRegistry.d.ts +0 -275
  574. package/dist/lib/files/fileReferenceRegistry.js +0 -1559
  575. package/dist/lib/files/fileTools.d.ts +0 -176
  576. package/dist/lib/files/fileTools.js +0 -435
  577. package/dist/lib/files/index.d.ts +0 -13
  578. package/dist/lib/files/index.js +0 -14
  579. package/dist/lib/files/streamingReader.d.ts +0 -93
  580. package/dist/lib/files/streamingReader.js +0 -322
  581. package/dist/lib/hitl/hitlErrors.d.ts +0 -38
  582. package/dist/lib/hitl/hitlErrors.js +0 -55
  583. package/dist/lib/hitl/hitlManager.d.ts +0 -100
  584. package/dist/lib/hitl/hitlManager.js +0 -461
  585. package/dist/lib/hitl/index.d.ts +0 -7
  586. package/dist/lib/hitl/index.js +0 -10
  587. package/dist/lib/image-gen/ImageGenService.d.ts +0 -146
  588. package/dist/lib/image-gen/ImageGenService.js +0 -349
  589. package/dist/lib/image-gen/imageGenTools.d.ts +0 -109
  590. package/dist/lib/image-gen/imageGenTools.js +0 -305
  591. package/dist/lib/image-gen/index.d.ts +0 -45
  592. package/dist/lib/image-gen/index.js +0 -49
  593. package/dist/lib/index.d.ts +0 -447
  594. package/dist/lib/index.js +0 -748
  595. package/dist/lib/knowledge/context.d.ts +0 -18
  596. package/dist/lib/knowledge/context.js +0 -92
  597. package/dist/lib/knowledge/defaults.d.ts +0 -24
  598. package/dist/lib/knowledge/defaults.js +0 -30
  599. package/dist/lib/knowledge/engine.d.ts +0 -35
  600. package/dist/lib/knowledge/engine.js +0 -180
  601. package/dist/lib/knowledge/index.d.ts +0 -15
  602. package/dist/lib/knowledge/index.js +0 -16
  603. package/dist/lib/knowledge/indexCache.d.ts +0 -19
  604. package/dist/lib/knowledge/indexCache.js +0 -110
  605. package/dist/lib/knowledge/knowledgeIndex.d.ts +0 -41
  606. package/dist/lib/knowledge/knowledgeIndex.js +0 -205
  607. package/dist/lib/knowledge/normalize.d.ts +0 -32
  608. package/dist/lib/knowledge/normalize.js +0 -75
  609. package/dist/lib/knowledge/resolve.d.ts +0 -18
  610. package/dist/lib/knowledge/resolve.js +0 -157
  611. package/dist/lib/knowledge/retrieval.d.ts +0 -16
  612. package/dist/lib/knowledge/retrieval.js +0 -222
  613. package/dist/lib/mcp/agentExposure.d.ts +0 -83
  614. package/dist/lib/mcp/agentExposure.js +0 -357
  615. package/dist/lib/mcp/auth/index.d.ts +0 -6
  616. package/dist/lib/mcp/auth/index.js +0 -12
  617. package/dist/lib/mcp/auth/oauthClientProvider.d.ts +0 -93
  618. package/dist/lib/mcp/auth/oauthClientProvider.js +0 -331
  619. package/dist/lib/mcp/auth/tokenStorage.d.ts +0 -56
  620. package/dist/lib/mcp/auth/tokenStorage.js +0 -135
  621. package/dist/lib/mcp/batching/index.d.ts +0 -1
  622. package/dist/lib/mcp/batching/index.js +0 -2
  623. package/dist/lib/mcp/batching/requestBatcher.d.ts +0 -130
  624. package/dist/lib/mcp/batching/requestBatcher.js +0 -468
  625. package/dist/lib/mcp/caching/index.d.ts +0 -1
  626. package/dist/lib/mcp/caching/index.js +0 -2
  627. package/dist/lib/mcp/caching/toolCache.d.ts +0 -154
  628. package/dist/lib/mcp/caching/toolCache.js +0 -434
  629. package/dist/lib/mcp/elicitation/elicitationManager.d.ts +0 -169
  630. package/dist/lib/mcp/elicitation/elicitationManager.js +0 -377
  631. package/dist/lib/mcp/elicitation/index.d.ts +0 -1
  632. package/dist/lib/mcp/elicitation/index.js +0 -3
  633. package/dist/lib/mcp/elicitationProtocol.d.ts +0 -139
  634. package/dist/lib/mcp/elicitationProtocol.js +0 -376
  635. package/dist/lib/mcp/enhancedToolDiscovery.d.ts +0 -125
  636. package/dist/lib/mcp/enhancedToolDiscovery.js +0 -482
  637. package/dist/lib/mcp/externalServerManager.d.ts +0 -189
  638. package/dist/lib/mcp/externalServerManager.js +0 -1525
  639. package/dist/lib/mcp/factory.d.ts +0 -60
  640. package/dist/lib/mcp/factory.js +0 -162
  641. package/dist/lib/mcp/flexibleToolValidator.d.ts +0 -46
  642. package/dist/lib/mcp/flexibleToolValidator.js +0 -162
  643. package/dist/lib/mcp/httpRateLimiter.d.ts +0 -152
  644. package/dist/lib/mcp/httpRateLimiter.js +0 -386
  645. package/dist/lib/mcp/httpRetryHandler.d.ts +0 -62
  646. package/dist/lib/mcp/httpRetryHandler.js +0 -180
  647. package/dist/lib/mcp/index.d.ts +0 -60
  648. package/dist/lib/mcp/index.js +0 -82
  649. package/dist/lib/mcp/mcpCircuitBreaker.d.ts +0 -123
  650. package/dist/lib/mcp/mcpCircuitBreaker.js +0 -428
  651. package/dist/lib/mcp/mcpClientFactory.d.ts +0 -109
  652. package/dist/lib/mcp/mcpClientFactory.js +0 -714
  653. package/dist/lib/mcp/mcpOutputNormalizer.d.ts +0 -47
  654. package/dist/lib/mcp/mcpOutputNormalizer.js +0 -183
  655. package/dist/lib/mcp/mcpRegistryClient.d.ts +0 -129
  656. package/dist/lib/mcp/mcpRegistryClient.js +0 -489
  657. package/dist/lib/mcp/mcpServerBase.d.ts +0 -162
  658. package/dist/lib/mcp/mcpServerBase.js +0 -377
  659. package/dist/lib/mcp/multiServerManager.d.ts +0 -182
  660. package/dist/lib/mcp/multiServerManager.js +0 -580
  661. package/dist/lib/mcp/registry.d.ts +0 -94
  662. package/dist/lib/mcp/registry.js +0 -159
  663. package/dist/lib/mcp/routing/index.d.ts +0 -1
  664. package/dist/lib/mcp/routing/index.js +0 -2
  665. package/dist/lib/mcp/routing/toolRouter.d.ts +0 -110
  666. package/dist/lib/mcp/routing/toolRouter.js +0 -417
  667. package/dist/lib/mcp/serverCapabilities.d.ts +0 -175
  668. package/dist/lib/mcp/serverCapabilities.js +0 -503
  669. package/dist/lib/mcp/servers/agent/directToolsServer.d.ts +0 -8
  670. package/dist/lib/mcp/servers/agent/directToolsServer.js +0 -152
  671. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.d.ts +0 -6
  672. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +0 -364
  673. package/dist/lib/mcp/servers/aiProviders/aiCoreServer.d.ts +0 -10
  674. package/dist/lib/mcp/servers/aiProviders/aiCoreServer.js +0 -232
  675. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.d.ts +0 -5
  676. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +0 -584
  677. package/dist/lib/mcp/servers/utilities/utilityServer.d.ts +0 -8
  678. package/dist/lib/mcp/servers/utilities/utilityServer.js +0 -327
  679. package/dist/lib/mcp/toolAnnotations.d.ts +0 -57
  680. package/dist/lib/mcp/toolAnnotations.js +0 -240
  681. package/dist/lib/mcp/toolConverter.d.ts +0 -87
  682. package/dist/lib/mcp/toolConverter.js +0 -259
  683. package/dist/lib/mcp/toolDiscoveryService.d.ts +0 -144
  684. package/dist/lib/mcp/toolDiscoveryService.js +0 -978
  685. package/dist/lib/mcp/toolIntegration.d.ts +0 -92
  686. package/dist/lib/mcp/toolIntegration.js +0 -335
  687. package/dist/lib/mcp/toolRegistry.d.ts +0 -151
  688. package/dist/lib/mcp/toolRegistry.js +0 -755
  689. package/dist/lib/memory/hippocampusInitializer.d.ts +0 -2
  690. package/dist/lib/memory/hippocampusInitializer.js +0 -50
  691. package/dist/lib/memory/memoryRetrievalTools.d.ts +0 -13
  692. package/dist/lib/memory/memoryRetrievalTools.js +0 -267
  693. package/dist/lib/middleware/builtin/analytics.d.ts +0 -16
  694. package/dist/lib/middleware/builtin/analytics.js +0 -133
  695. package/dist/lib/middleware/builtin/autoEvaluation.d.ts +0 -11
  696. package/dist/lib/middleware/builtin/autoEvaluation.js +0 -201
  697. package/dist/lib/middleware/builtin/guardrails.d.ts +0 -7
  698. package/dist/lib/middleware/builtin/guardrails.js +0 -110
  699. package/dist/lib/middleware/builtin/lifecycle.d.ts +0 -2
  700. package/dist/lib/middleware/builtin/lifecycle.js +0 -161
  701. package/dist/lib/middleware/factory.d.ts +0 -69
  702. package/dist/lib/middleware/factory.js +0 -328
  703. package/dist/lib/middleware/index.d.ts +0 -11
  704. package/dist/lib/middleware/index.js +0 -17
  705. package/dist/lib/middleware/registry.d.ts +0 -76
  706. package/dist/lib/middleware/registry.js +0 -296
  707. package/dist/lib/middleware/utils/guardrailsUtils.d.ts +0 -50
  708. package/dist/lib/middleware/utils/guardrailsUtils.js +0 -397
  709. package/dist/lib/models/anthropicModels.d.ts +0 -261
  710. package/dist/lib/models/anthropicModels.js +0 -556
  711. package/dist/lib/models/manifestRegistry.d.ts +0 -33
  712. package/dist/lib/models/manifestRegistry.js +0 -174
  713. package/dist/lib/models/manifests/anthropic.d.ts +0 -9
  714. package/dist/lib/models/manifests/anthropic.js +0 -346
  715. package/dist/lib/models/manifests/azure.d.ts +0 -2
  716. package/dist/lib/models/manifests/azure.js +0 -87
  717. package/dist/lib/models/manifests/bedrock.d.ts +0 -2
  718. package/dist/lib/models/manifests/bedrock.js +0 -75
  719. package/dist/lib/models/manifests/cloudflare.d.ts +0 -8
  720. package/dist/lib/models/manifests/cloudflare.js +0 -19
  721. package/dist/lib/models/manifests/cohere.d.ts +0 -8
  722. package/dist/lib/models/manifests/cohere.js +0 -19
  723. package/dist/lib/models/manifests/deepseek.d.ts +0 -8
  724. package/dist/lib/models/manifests/deepseek.js +0 -19
  725. package/dist/lib/models/manifests/fireworks.d.ts +0 -8
  726. package/dist/lib/models/manifests/fireworks.js +0 -19
  727. package/dist/lib/models/manifests/google-ai.d.ts +0 -2
  728. package/dist/lib/models/manifests/google-ai.js +0 -28
  729. package/dist/lib/models/manifests/groq.d.ts +0 -8
  730. package/dist/lib/models/manifests/groq.js +0 -19
  731. package/dist/lib/models/manifests/huggingface.d.ts +0 -8
  732. package/dist/lib/models/manifests/huggingface.js +0 -19
  733. package/dist/lib/models/manifests/ideogram.d.ts +0 -8
  734. package/dist/lib/models/manifests/ideogram.js +0 -19
  735. package/dist/lib/models/manifests/jina.d.ts +0 -8
  736. package/dist/lib/models/manifests/jina.js +0 -19
  737. package/dist/lib/models/manifests/litellm.d.ts +0 -8
  738. package/dist/lib/models/manifests/litellm.js +0 -19
  739. package/dist/lib/models/manifests/llamacpp.d.ts +0 -8
  740. package/dist/lib/models/manifests/llamacpp.js +0 -19
  741. package/dist/lib/models/manifests/lm-studio.d.ts +0 -8
  742. package/dist/lib/models/manifests/lm-studio.js +0 -19
  743. package/dist/lib/models/manifests/mistral.d.ts +0 -2
  744. package/dist/lib/models/manifests/mistral.js +0 -50
  745. package/dist/lib/models/manifests/nvidia-nim.d.ts +0 -8
  746. package/dist/lib/models/manifests/nvidia-nim.js +0 -19
  747. package/dist/lib/models/manifests/ollama.d.ts +0 -2
  748. package/dist/lib/models/manifests/ollama.js +0 -72
  749. package/dist/lib/models/manifests/openai-compatible.d.ts +0 -8
  750. package/dist/lib/models/manifests/openai-compatible.js +0 -19
  751. package/dist/lib/models/manifests/openai.d.ts +0 -11
  752. package/dist/lib/models/manifests/openai.js +0 -560
  753. package/dist/lib/models/manifests/openrouter.d.ts +0 -8
  754. package/dist/lib/models/manifests/openrouter.js +0 -19
  755. package/dist/lib/models/manifests/perplexity.d.ts +0 -8
  756. package/dist/lib/models/manifests/perplexity.js +0 -19
  757. package/dist/lib/models/manifests/recraft.d.ts +0 -8
  758. package/dist/lib/models/manifests/recraft.js +0 -19
  759. package/dist/lib/models/manifests/replicate.d.ts +0 -8
  760. package/dist/lib/models/manifests/replicate.js +0 -19
  761. package/dist/lib/models/manifests/sagemaker.d.ts +0 -8
  762. package/dist/lib/models/manifests/sagemaker.js +0 -19
  763. package/dist/lib/models/manifests/stability.d.ts +0 -8
  764. package/dist/lib/models/manifests/stability.js +0 -19
  765. package/dist/lib/models/manifests/together-ai.d.ts +0 -8
  766. package/dist/lib/models/manifests/together-ai.js +0 -19
  767. package/dist/lib/models/manifests/vertex.d.ts +0 -8
  768. package/dist/lib/models/manifests/vertex.js +0 -19
  769. package/dist/lib/models/manifests/voyage.d.ts +0 -8
  770. package/dist/lib/models/manifests/voyage.js +0 -19
  771. package/dist/lib/models/manifests/xai.d.ts +0 -8
  772. package/dist/lib/models/manifests/xai.js +0 -19
  773. package/dist/lib/models/modelRegistry.d.ts +0 -74
  774. package/dist/lib/models/modelRegistry.js +0 -2695
  775. package/dist/lib/models/modelResolver.d.ts +0 -74
  776. package/dist/lib/models/modelResolver.js +0 -470
  777. package/dist/lib/music/index.d.ts +0 -27
  778. package/dist/lib/music/index.js +0 -94
  779. package/dist/lib/music/providers/BeatovenMusic.d.ts +0 -31
  780. package/dist/lib/music/providers/BeatovenMusic.js +0 -334
  781. package/dist/lib/music/providers/ElevenLabsMusic.d.ts +0 -30
  782. package/dist/lib/music/providers/ElevenLabsMusic.js +0 -169
  783. package/dist/lib/music/providers/LyriaMusic.d.ts +0 -29
  784. package/dist/lib/music/providers/LyriaMusic.js +0 -173
  785. package/dist/lib/music/providers/ReplicateMusic.d.ts +0 -31
  786. package/dist/lib/music/providers/ReplicateMusic.js +0 -262
  787. package/dist/lib/neurolink.d.ts +0 -2662
  788. package/dist/lib/neurolink.js +0 -12946
  789. package/dist/lib/observability/exporterRegistry.d.ts +0 -133
  790. package/dist/lib/observability/exporterRegistry.js +0 -414
  791. package/dist/lib/observability/exporters/arizeExporter.d.ts +0 -32
  792. package/dist/lib/observability/exporters/arizeExporter.js +0 -139
  793. package/dist/lib/observability/exporters/baseExporter.d.ts +0 -117
  794. package/dist/lib/observability/exporters/baseExporter.js +0 -191
  795. package/dist/lib/observability/exporters/braintrustExporter.d.ts +0 -30
  796. package/dist/lib/observability/exporters/braintrustExporter.js +0 -155
  797. package/dist/lib/observability/exporters/datadogExporter.d.ts +0 -37
  798. package/dist/lib/observability/exporters/datadogExporter.js +0 -197
  799. package/dist/lib/observability/exporters/index.d.ts +0 -13
  800. package/dist/lib/observability/exporters/index.js +0 -14
  801. package/dist/lib/observability/exporters/laminarExporter.d.ts +0 -48
  802. package/dist/lib/observability/exporters/laminarExporter.js +0 -304
  803. package/dist/lib/observability/exporters/langfuseExporter.d.ts +0 -48
  804. package/dist/lib/observability/exporters/langfuseExporter.js +0 -210
  805. package/dist/lib/observability/exporters/langsmithExporter.d.ts +0 -26
  806. package/dist/lib/observability/exporters/langsmithExporter.js +0 -144
  807. package/dist/lib/observability/exporters/otelExporter.d.ts +0 -39
  808. package/dist/lib/observability/exporters/otelExporter.js +0 -165
  809. package/dist/lib/observability/exporters/posthogExporter.d.ts +0 -48
  810. package/dist/lib/observability/exporters/posthogExporter.js +0 -289
  811. package/dist/lib/observability/exporters/sentryExporter.d.ts +0 -32
  812. package/dist/lib/observability/exporters/sentryExporter.js +0 -167
  813. package/dist/lib/observability/index.d.ts +0 -23
  814. package/dist/lib/observability/index.js +0 -32
  815. package/dist/lib/observability/metricsAggregator.d.ts +0 -126
  816. package/dist/lib/observability/metricsAggregator.js +0 -553
  817. package/dist/lib/observability/otelBridge.d.ts +0 -49
  818. package/dist/lib/observability/otelBridge.js +0 -141
  819. package/dist/lib/observability/retryPolicy.d.ts +0 -154
  820. package/dist/lib/observability/retryPolicy.js +0 -384
  821. package/dist/lib/observability/sampling/index.d.ts +0 -4
  822. package/dist/lib/observability/sampling/index.js +0 -5
  823. package/dist/lib/observability/sampling/samplers.d.ts +0 -104
  824. package/dist/lib/observability/sampling/samplers.js +0 -217
  825. package/dist/lib/observability/spanProcessor.d.ts +0 -115
  826. package/dist/lib/observability/spanProcessor.js +0 -304
  827. package/dist/lib/observability/tokenTracker.d.ts +0 -109
  828. package/dist/lib/observability/tokenTracker.js +0 -416
  829. package/dist/lib/observability/utils/index.d.ts +0 -4
  830. package/dist/lib/observability/utils/index.js +0 -5
  831. package/dist/lib/observability/utils/safeMetadata.d.ts +0 -10
  832. package/dist/lib/observability/utils/safeMetadata.js +0 -26
  833. package/dist/lib/observability/utils/spanSerializer.d.ts +0 -119
  834. package/dist/lib/observability/utils/spanSerializer.js +0 -314
  835. package/dist/lib/processors/archive/ArchiveProcessor.d.ts +0 -323
  836. package/dist/lib/processors/archive/ArchiveProcessor.js +0 -1662
  837. package/dist/lib/processors/archive/index.d.ts +0 -33
  838. package/dist/lib/processors/archive/index.js +0 -44
  839. package/dist/lib/processors/archive/zipEntryReader.d.ts +0 -51
  840. package/dist/lib/processors/archive/zipEntryReader.js +0 -81
  841. package/dist/lib/processors/base/BaseFileProcessor.d.ts +0 -309
  842. package/dist/lib/processors/base/BaseFileProcessor.js +0 -769
  843. package/dist/lib/processors/base/index.d.ts +0 -13
  844. package/dist/lib/processors/base/index.js +0 -23
  845. package/dist/lib/processors/cli/fileProcessorCli.d.ts +0 -124
  846. package/dist/lib/processors/cli/fileProcessorCli.js +0 -392
  847. package/dist/lib/processors/cli/index.d.ts +0 -36
  848. package/dist/lib/processors/cli/index.js +0 -53
  849. package/dist/lib/processors/code/ConfigProcessor.d.ts +0 -169
  850. package/dist/lib/processors/code/ConfigProcessor.js +0 -405
  851. package/dist/lib/processors/code/SourceCodeProcessor.d.ts +0 -172
  852. package/dist/lib/processors/code/SourceCodeProcessor.js +0 -309
  853. package/dist/lib/processors/code/index.d.ts +0 -44
  854. package/dist/lib/processors/code/index.js +0 -65
  855. package/dist/lib/processors/config/fileExtensions.d.ts +0 -280
  856. package/dist/lib/processors/config/fileExtensions.js +0 -485
  857. package/dist/lib/processors/config/fileTypeRegistry.d.ts +0 -106
  858. package/dist/lib/processors/config/fileTypeRegistry.js +0 -702
  859. package/dist/lib/processors/config/index.d.ts +0 -33
  860. package/dist/lib/processors/config/index.js +0 -104
  861. package/dist/lib/processors/config/languageMap.d.ts +0 -62
  862. package/dist/lib/processors/config/languageMap.js +0 -414
  863. package/dist/lib/processors/config/mimeConstants.d.ts +0 -373
  864. package/dist/lib/processors/config/mimeConstants.js +0 -348
  865. package/dist/lib/processors/config/sizeLimits.d.ts +0 -198
  866. package/dist/lib/processors/config/sizeLimits.js +0 -262
  867. package/dist/lib/processors/data/JsonProcessor.d.ts +0 -120
  868. package/dist/lib/processors/data/JsonProcessor.js +0 -206
  869. package/dist/lib/processors/data/XmlProcessor.d.ts +0 -158
  870. package/dist/lib/processors/data/XmlProcessor.js +0 -288
  871. package/dist/lib/processors/data/YamlProcessor.d.ts +0 -161
  872. package/dist/lib/processors/data/YamlProcessor.js +0 -297
  873. package/dist/lib/processors/data/index.d.ts +0 -49
  874. package/dist/lib/processors/data/index.js +0 -83
  875. package/dist/lib/processors/document/ExcelProcessor.d.ts +0 -250
  876. package/dist/lib/processors/document/ExcelProcessor.js +0 -615
  877. package/dist/lib/processors/document/OpenDocumentProcessor.d.ts +0 -67
  878. package/dist/lib/processors/document/OpenDocumentProcessor.js +0 -236
  879. package/dist/lib/processors/document/PptxProcessor.d.ts +0 -77
  880. package/dist/lib/processors/document/PptxProcessor.js +0 -262
  881. package/dist/lib/processors/document/RtfProcessor.d.ts +0 -150
  882. package/dist/lib/processors/document/RtfProcessor.js +0 -364
  883. package/dist/lib/processors/document/WordProcessor.d.ts +0 -166
  884. package/dist/lib/processors/document/WordProcessor.js +0 -365
  885. package/dist/lib/processors/document/index.d.ts +0 -55
  886. package/dist/lib/processors/document/index.js +0 -100
  887. package/dist/lib/processors/errors/FileErrorCode.d.ts +0 -86
  888. package/dist/lib/processors/errors/FileErrorCode.js +0 -256
  889. package/dist/lib/processors/errors/errorHelpers.d.ts +0 -121
  890. package/dist/lib/processors/errors/errorHelpers.js +0 -387
  891. package/dist/lib/processors/errors/errorSerializer.d.ts +0 -96
  892. package/dist/lib/processors/errors/errorSerializer.js +0 -508
  893. package/dist/lib/processors/errors/index.d.ts +0 -46
  894. package/dist/lib/processors/errors/index.js +0 -50
  895. package/dist/lib/processors/index.d.ts +0 -79
  896. package/dist/lib/processors/index.js +0 -133
  897. package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +0 -176
  898. package/dist/lib/processors/integration/FileProcessorIntegration.js +0 -279
  899. package/dist/lib/processors/integration/index.d.ts +0 -41
  900. package/dist/lib/processors/integration/index.js +0 -48
  901. package/dist/lib/processors/markup/HtmlProcessor.d.ts +0 -167
  902. package/dist/lib/processors/markup/HtmlProcessor.js +0 -252
  903. package/dist/lib/processors/markup/MarkdownProcessor.d.ts +0 -163
  904. package/dist/lib/processors/markup/MarkdownProcessor.js +0 -249
  905. package/dist/lib/processors/markup/SvgProcessor.d.ts +0 -154
  906. package/dist/lib/processors/markup/SvgProcessor.js +0 -245
  907. package/dist/lib/processors/markup/TextProcessor.d.ts +0 -133
  908. package/dist/lib/processors/markup/TextProcessor.js +0 -191
  909. package/dist/lib/processors/markup/index.d.ts +0 -66
  910. package/dist/lib/processors/markup/index.js +0 -111
  911. package/dist/lib/processors/media/AudioProcessor.d.ts +0 -266
  912. package/dist/lib/processors/media/AudioProcessor.js +0 -712
  913. package/dist/lib/processors/media/VideoProcessor.d.ts +0 -337
  914. package/dist/lib/processors/media/VideoProcessor.js +0 -1154
  915. package/dist/lib/processors/media/index.d.ts +0 -26
  916. package/dist/lib/processors/media/index.js +0 -30
  917. package/dist/lib/processors/registry/ProcessorRegistry.d.ts +0 -347
  918. package/dist/lib/processors/registry/ProcessorRegistry.js +0 -715
  919. package/dist/lib/processors/registry/index.d.ts +0 -2
  920. package/dist/lib/processors/registry/index.js +0 -10
  921. package/dist/lib/providers/amazonBedrock/client.d.ts +0 -93
  922. package/dist/lib/providers/amazonBedrock/client.js +0 -1178
  923. package/dist/lib/providers/amazonBedrock/constants.d.ts +0 -1
  924. package/dist/lib/providers/amazonBedrock/constants.js +0 -3
  925. package/dist/lib/providers/amazonBedrock/index.d.ts +0 -3
  926. package/dist/lib/providers/amazonBedrock/index.js +0 -4
  927. package/dist/lib/providers/amazonBedrock/inferenceProfile.d.ts +0 -72
  928. package/dist/lib/providers/amazonBedrock/inferenceProfile.js +0 -186
  929. package/dist/lib/providers/amazonBedrock/loopAdapter.d.ts +0 -36
  930. package/dist/lib/providers/amazonBedrock/loopAdapter.js +0 -278
  931. package/dist/lib/providers/amazonBedrock/utils.d.ts +0 -1
  932. package/dist/lib/providers/amazonBedrock/utils.js +0 -4
  933. package/dist/lib/providers/amazonSagemaker.d.ts +0 -108
  934. package/dist/lib/providers/amazonSagemaker.js +0 -292
  935. package/dist/lib/providers/anthropic/cacheControl.d.ts +0 -12
  936. package/dist/lib/providers/anthropic/cacheControl.js +0 -15
  937. package/dist/lib/providers/anthropic/client.d.ts +0 -149
  938. package/dist/lib/providers/anthropic/client.js +0 -1862
  939. package/dist/lib/providers/anthropic/constants.d.ts +0 -3
  940. package/dist/lib/providers/anthropic/constants.js +0 -7
  941. package/dist/lib/providers/anthropic/index.d.ts +0 -2
  942. package/dist/lib/providers/anthropic/index.js +0 -3
  943. package/dist/lib/providers/anthropic/loopAdapter.d.ts +0 -26
  944. package/dist/lib/providers/anthropic/loopAdapter.js +0 -326
  945. package/dist/lib/providers/anthropic/rateLimitCapture.d.ts +0 -82
  946. package/dist/lib/providers/anthropic/rateLimitCapture.js +0 -375
  947. package/dist/lib/providers/anthropic/structuredOutput.d.ts +0 -58
  948. package/dist/lib/providers/anthropic/structuredOutput.js +0 -98
  949. package/dist/lib/providers/anthropic/toolOutput.d.ts +0 -9
  950. package/dist/lib/providers/anthropic/toolOutput.js +0 -39
  951. package/dist/lib/providers/anthropicImageBlocks.d.ts +0 -47
  952. package/dist/lib/providers/anthropicImageBlocks.js +0 -223
  953. package/dist/lib/providers/azureOpenai.d.ts +0 -67
  954. package/dist/lib/providers/azureOpenai.js +0 -230
  955. package/dist/lib/providers/cohere.d.ts +0 -54
  956. package/dist/lib/providers/cohere.js +0 -183
  957. package/dist/lib/providers/configuredOpenAICompat.d.ts +0 -24
  958. package/dist/lib/providers/configuredOpenAICompat.js +0 -67
  959. package/dist/lib/providers/deepseek.d.ts +0 -47
  960. package/dist/lib/providers/deepseek.js +0 -121
  961. package/dist/lib/providers/googleAiStudio/client.d.ts +0 -92
  962. package/dist/lib/providers/googleAiStudio/client.js +0 -1661
  963. package/dist/lib/providers/googleAiStudio/index.d.ts +0 -1
  964. package/dist/lib/providers/googleAiStudio/index.js +0 -2
  965. package/dist/lib/providers/googleNativeGemini3/index.d.ts +0 -1
  966. package/dist/lib/providers/googleNativeGemini3/index.js +0 -2
  967. package/dist/lib/providers/googleNativeGemini3/utils.d.ts +0 -482
  968. package/dist/lib/providers/googleNativeGemini3/utils.js +0 -1527
  969. package/dist/lib/providers/googleVertex/client.d.ts +0 -415
  970. package/dist/lib/providers/googleVertex/client.js +0 -7018
  971. package/dist/lib/providers/googleVertex/constants.d.ts +0 -5
  972. package/dist/lib/providers/googleVertex/constants.js +0 -27
  973. package/dist/lib/providers/googleVertex/index.d.ts +0 -3
  974. package/dist/lib/providers/googleVertex/index.js +0 -4
  975. package/dist/lib/providers/googleVertex/utils.d.ts +0 -12
  976. package/dist/lib/providers/googleVertex/utils.js +0 -287
  977. package/dist/lib/providers/huggingFace/client.d.ts +0 -31
  978. package/dist/lib/providers/huggingFace/client.js +0 -103
  979. package/dist/lib/providers/huggingFace/index.d.ts +0 -1
  980. package/dist/lib/providers/huggingFace/index.js +0 -2
  981. package/dist/lib/providers/ideogram.d.ts +0 -34
  982. package/dist/lib/providers/ideogram.js +0 -184
  983. package/dist/lib/providers/jina.d.ts +0 -58
  984. package/dist/lib/providers/jina.js +0 -217
  985. package/dist/lib/providers/litellm/client.d.ts +0 -84
  986. package/dist/lib/providers/litellm/client.js +0 -504
  987. package/dist/lib/providers/litellm/index.d.ts +0 -1
  988. package/dist/lib/providers/litellm/index.js +0 -2
  989. package/dist/lib/providers/llamaCpp.d.ts +0 -24
  990. package/dist/lib/providers/llamaCpp.js +0 -80
  991. package/dist/lib/providers/lmStudio.d.ts +0 -29
  992. package/dist/lib/providers/lmStudio.js +0 -88
  993. package/dist/lib/providers/nvidiaNim/client.d.ts +0 -60
  994. package/dist/lib/providers/nvidiaNim/client.js +0 -291
  995. package/dist/lib/providers/nvidiaNim/constants.d.ts +0 -1
  996. package/dist/lib/providers/nvidiaNim/constants.js +0 -2
  997. package/dist/lib/providers/nvidiaNim/index.d.ts +0 -2
  998. package/dist/lib/providers/nvidiaNim/index.js +0 -3
  999. package/dist/lib/providers/ollama/client.d.ts +0 -71
  1000. package/dist/lib/providers/ollama/client.js +0 -283
  1001. package/dist/lib/providers/ollama/constants.d.ts +0 -4
  1002. package/dist/lib/providers/ollama/constants.js +0 -6
  1003. package/dist/lib/providers/ollama/index.d.ts +0 -2
  1004. package/dist/lib/providers/ollama/index.js +0 -3
  1005. package/dist/lib/providers/openAI/client.d.ts +0 -76
  1006. package/dist/lib/providers/openAI/client.js +0 -503
  1007. package/dist/lib/providers/openAI/index.d.ts +0 -1
  1008. package/dist/lib/providers/openAI/index.js +0 -2
  1009. package/dist/lib/providers/openRouter/client.d.ts +0 -75
  1010. package/dist/lib/providers/openRouter/client.js +0 -402
  1011. package/dist/lib/providers/openRouter/constants.d.ts +0 -1
  1012. package/dist/lib/providers/openRouter/constants.js +0 -2
  1013. package/dist/lib/providers/openRouter/index.d.ts +0 -3
  1014. package/dist/lib/providers/openRouter/index.js +0 -4
  1015. package/dist/lib/providers/openRouter/utils.d.ts +0 -1
  1016. package/dist/lib/providers/openRouter/utils.js +0 -6
  1017. package/dist/lib/providers/openaiChatCompletionsBase.d.ts +0 -212
  1018. package/dist/lib/providers/openaiChatCompletionsBase.js +0 -1154
  1019. package/dist/lib/providers/openaiChatCompletionsClient.d.ts +0 -70
  1020. package/dist/lib/providers/openaiChatCompletionsClient.js +0 -684
  1021. package/dist/lib/providers/openaiCompatCatalog.d.ts +0 -24
  1022. package/dist/lib/providers/openaiCompatCatalog.js +0 -270
  1023. package/dist/lib/providers/openaiCompatible/client.d.ts +0 -21
  1024. package/dist/lib/providers/openaiCompatible/client.js +0 -91
  1025. package/dist/lib/providers/openaiCompatible/constants.d.ts +0 -1
  1026. package/dist/lib/providers/openaiCompatible/constants.js +0 -2
  1027. package/dist/lib/providers/openaiCompatible/index.d.ts +0 -3
  1028. package/dist/lib/providers/openaiCompatible/index.js +0 -4
  1029. package/dist/lib/providers/openaiCompatible/utils.d.ts +0 -5
  1030. package/dist/lib/providers/openaiCompatible/utils.js +0 -17
  1031. package/dist/lib/providers/providerTypeUtils.d.ts +0 -23
  1032. package/dist/lib/providers/providerTypeUtils.js +0 -41
  1033. package/dist/lib/providers/recraft.d.ts +0 -34
  1034. package/dist/lib/providers/recraft.js +0 -197
  1035. package/dist/lib/providers/replicate.d.ts +0 -74
  1036. package/dist/lib/providers/replicate.js +0 -416
  1037. package/dist/lib/providers/sagemaker/adaptive-semaphore.d.ts +0 -74
  1038. package/dist/lib/providers/sagemaker/adaptive-semaphore.js +0 -216
  1039. package/dist/lib/providers/sagemaker/client.d.ts +0 -161
  1040. package/dist/lib/providers/sagemaker/client.js +0 -509
  1041. package/dist/lib/providers/sagemaker/config.d.ts +0 -87
  1042. package/dist/lib/providers/sagemaker/config.js +0 -355
  1043. package/dist/lib/providers/sagemaker/detection.d.ts +0 -121
  1044. package/dist/lib/providers/sagemaker/detection.js +0 -607
  1045. package/dist/lib/providers/sagemaker/diagnostics.d.ts +0 -14
  1046. package/dist/lib/providers/sagemaker/diagnostics.js +0 -138
  1047. package/dist/lib/providers/sagemaker/error-constants.d.ts +0 -78
  1048. package/dist/lib/providers/sagemaker/error-constants.js +0 -228
  1049. package/dist/lib/providers/sagemaker/errors.d.ts +0 -90
  1050. package/dist/lib/providers/sagemaker/errors.js +0 -301
  1051. package/dist/lib/providers/sagemaker/index.d.ts +0 -34
  1052. package/dist/lib/providers/sagemaker/index.js +0 -69
  1053. package/dist/lib/providers/sagemaker/language-model.d.ts +0 -207
  1054. package/dist/lib/providers/sagemaker/language-model.js +0 -805
  1055. package/dist/lib/providers/sagemaker/parsers.d.ts +0 -111
  1056. package/dist/lib/providers/sagemaker/parsers.js +0 -644
  1057. package/dist/lib/providers/sagemaker/streaming.d.ts +0 -48
  1058. package/dist/lib/providers/sagemaker/streaming.js +0 -390
  1059. package/dist/lib/providers/sagemaker/structured-parser.d.ts +0 -117
  1060. package/dist/lib/providers/sagemaker/structured-parser.js +0 -626
  1061. package/dist/lib/providers/stability.d.ts +0 -37
  1062. package/dist/lib/providers/stability.js +0 -191
  1063. package/dist/lib/providers/voyage.d.ts +0 -46
  1064. package/dist/lib/providers/voyage.js +0 -176
  1065. package/dist/lib/proxy/accountCooldown.d.ts +0 -5
  1066. package/dist/lib/proxy/accountCooldown.js +0 -121
  1067. package/dist/lib/proxy/accountQuota.d.ts +0 -84
  1068. package/dist/lib/proxy/accountQuota.js +0 -459
  1069. package/dist/lib/proxy/accountQuotaRefreshCoordinator.d.ts +0 -19
  1070. package/dist/lib/proxy/accountQuotaRefreshCoordinator.js +0 -105
  1071. package/dist/lib/proxy/accountSelection.d.ts +0 -8
  1072. package/dist/lib/proxy/accountSelection.js +0 -26
  1073. package/dist/lib/proxy/accountUsage.d.ts +0 -45
  1074. package/dist/lib/proxy/accountUsage.js +0 -302
  1075. package/dist/lib/proxy/awsProxyIntegration.d.ts +0 -23
  1076. package/dist/lib/proxy/awsProxyIntegration.js +0 -286
  1077. package/dist/lib/proxy/claudeFormat.d.ts +0 -129
  1078. package/dist/lib/proxy/claudeFormat.js +0 -600
  1079. package/dist/lib/proxy/cloaking/index.d.ts +0 -43
  1080. package/dist/lib/proxy/cloaking/index.js +0 -88
  1081. package/dist/lib/proxy/cloaking/plugins/headerScrubber.d.ts +0 -9
  1082. package/dist/lib/proxy/cloaking/plugins/headerScrubber.js +0 -87
  1083. package/dist/lib/proxy/cloaking/plugins/sessionIdentity.d.ts +0 -11
  1084. package/dist/lib/proxy/cloaking/plugins/sessionIdentity.js +0 -42
  1085. package/dist/lib/proxy/cloaking/plugins/systemPromptInjector.d.ts +0 -11
  1086. package/dist/lib/proxy/cloaking/plugins/systemPromptInjector.js +0 -84
  1087. package/dist/lib/proxy/cloaking/plugins/tlsFingerprint.d.ts +0 -14
  1088. package/dist/lib/proxy/cloaking/plugins/tlsFingerprint.js +0 -39
  1089. package/dist/lib/proxy/cloaking/plugins/wordObfuscator.d.ts +0 -9
  1090. package/dist/lib/proxy/cloaking/plugins/wordObfuscator.js +0 -122
  1091. package/dist/lib/proxy/codexAccountUsage.d.ts +0 -26
  1092. package/dist/lib/proxy/codexAccountUsage.js +0 -174
  1093. package/dist/lib/proxy/codexUsage.d.ts +0 -68
  1094. package/dist/lib/proxy/codexUsage.js +0 -247
  1095. package/dist/lib/proxy/globalInstaller.d.ts +0 -19
  1096. package/dist/lib/proxy/globalInstaller.js +0 -242
  1097. package/dist/lib/proxy/logCleanupScheduler.d.ts +0 -12
  1098. package/dist/lib/proxy/logCleanupScheduler.js +0 -74
  1099. package/dist/lib/proxy/logCleanupWorkerEntry.d.ts +0 -1
  1100. package/dist/lib/proxy/logCleanupWorkerEntry.js +0 -15
  1101. package/dist/lib/proxy/modelRouter.d.ts +0 -34
  1102. package/dist/lib/proxy/modelRouter.js +0 -74
  1103. package/dist/lib/proxy/oauthFetch.d.ts +0 -36
  1104. package/dist/lib/proxy/oauthFetch.js +0 -353
  1105. package/dist/lib/proxy/openaiFormat.d.ts +0 -139
  1106. package/dist/lib/proxy/openaiFormat.js +0 -817
  1107. package/dist/lib/proxy/providerTransportCoordinator.d.ts +0 -17
  1108. package/dist/lib/proxy/providerTransportCoordinator.js +0 -156
  1109. package/dist/lib/proxy/proxyActivity.d.ts +0 -8
  1110. package/dist/lib/proxy/proxyActivity.js +0 -117
  1111. package/dist/lib/proxy/proxyAnalysis.d.ts +0 -3
  1112. package/dist/lib/proxy/proxyAnalysis.js +0 -985
  1113. package/dist/lib/proxy/proxyConfig.d.ts +0 -42
  1114. package/dist/lib/proxy/proxyConfig.js +0 -700
  1115. package/dist/lib/proxy/proxyDispatcher.d.ts +0 -5
  1116. package/dist/lib/proxy/proxyDispatcher.js +0 -61
  1117. package/dist/lib/proxy/proxyEnv.d.ts +0 -3
  1118. package/dist/lib/proxy/proxyEnv.js +0 -73
  1119. package/dist/lib/proxy/proxyFetch.d.ts +0 -50
  1120. package/dist/lib/proxy/proxyFetch.js +0 -729
  1121. package/dist/lib/proxy/proxyHealth.d.ts +0 -20
  1122. package/dist/lib/proxy/proxyHealth.js +0 -76
  1123. package/dist/lib/proxy/proxyLifecycle.d.ts +0 -13
  1124. package/dist/lib/proxy/proxyLifecycle.js +0 -383
  1125. package/dist/lib/proxy/proxyPaths.d.ts +0 -17
  1126. package/dist/lib/proxy/proxyPaths.js +0 -42
  1127. package/dist/lib/proxy/proxyReplay.d.ts +0 -10
  1128. package/dist/lib/proxy/proxyReplay.js +0 -765
  1129. package/dist/lib/proxy/proxyTracer.d.ts +0 -128
  1130. package/dist/lib/proxy/proxyTracer.js +0 -748
  1131. package/dist/lib/proxy/proxyTranslationEngine.d.ts +0 -125
  1132. package/dist/lib/proxy/proxyTranslationEngine.js +0 -740
  1133. package/dist/lib/proxy/quietDetector.d.ts +0 -17
  1134. package/dist/lib/proxy/quietDetector.js +0 -125
  1135. package/dist/lib/proxy/quotaHeaders.d.ts +0 -73
  1136. package/dist/lib/proxy/quotaHeaders.js +0 -189
  1137. package/dist/lib/proxy/rawStreamCapture.d.ts +0 -2
  1138. package/dist/lib/proxy/rawStreamCapture.js +0 -129
  1139. package/dist/lib/proxy/requestLogger.d.ts +0 -78
  1140. package/dist/lib/proxy/requestLogger.js +0 -770
  1141. package/dist/lib/proxy/rollingProxyServer.d.ts +0 -3
  1142. package/dist/lib/proxy/rollingProxyServer.js +0 -220
  1143. package/dist/lib/proxy/rollingWorkerProcess.d.ts +0 -2
  1144. package/dist/lib/proxy/rollingWorkerProcess.js +0 -199
  1145. package/dist/lib/proxy/rollingWorkerProtocol.d.ts +0 -5
  1146. package/dist/lib/proxy/rollingWorkerProtocol.js +0 -46
  1147. package/dist/lib/proxy/rollingWorkerSupervisor.d.ts +0 -44
  1148. package/dist/lib/proxy/rollingWorkerSupervisor.js +0 -530
  1149. package/dist/lib/proxy/routingEvidence.d.ts +0 -17
  1150. package/dist/lib/proxy/routingEvidence.js +0 -59
  1151. package/dist/lib/proxy/routingPolicy.d.ts +0 -19
  1152. package/dist/lib/proxy/routingPolicy.js +0 -75
  1153. package/dist/lib/proxy/runtimeConfig.d.ts +0 -27
  1154. package/dist/lib/proxy/runtimeConfig.js +0 -448
  1155. package/dist/lib/proxy/snapshotPersistence.d.ts +0 -2
  1156. package/dist/lib/proxy/snapshotPersistence.js +0 -41
  1157. package/dist/lib/proxy/socketWorkerRuntime.d.ts +0 -14
  1158. package/dist/lib/proxy/socketWorkerRuntime.js +0 -322
  1159. package/dist/lib/proxy/sseInterceptor.d.ts +0 -41
  1160. package/dist/lib/proxy/sseInterceptor.js +0 -496
  1161. package/dist/lib/proxy/streamOutcome.d.ts +0 -5
  1162. package/dist/lib/proxy/streamOutcome.js +0 -104
  1163. package/dist/lib/proxy/systemRelocation.d.ts +0 -21
  1164. package/dist/lib/proxy/systemRelocation.js +0 -51
  1165. package/dist/lib/proxy/tokenRefresh.d.ts +0 -18
  1166. package/dist/lib/proxy/tokenRefresh.js +0 -257
  1167. package/dist/lib/proxy/updateChecker.d.ts +0 -17
  1168. package/dist/lib/proxy/updateChecker.js +0 -98
  1169. package/dist/lib/proxy/updateCoordinator.d.ts +0 -7
  1170. package/dist/lib/proxy/updateCoordinator.js +0 -60
  1171. package/dist/lib/proxy/updateState.d.ts +0 -69
  1172. package/dist/lib/proxy/updateState.js +0 -309
  1173. package/dist/lib/proxy/updaterSupervisor.d.ts +0 -3
  1174. package/dist/lib/proxy/updaterSupervisor.js +0 -58
  1175. package/dist/lib/proxy/usageStats.d.ts +0 -91
  1176. package/dist/lib/proxy/usageStats.js +0 -1154
  1177. package/dist/lib/proxy/utils/noProxyUtils.d.ts +0 -39
  1178. package/dist/lib/proxy/utils/noProxyUtils.js +0 -150
  1179. package/dist/lib/proxy/workerLog.d.ts +0 -6
  1180. package/dist/lib/proxy/workerLog.js +0 -42
  1181. package/dist/lib/rag/ChunkerFactory.d.ts +0 -91
  1182. package/dist/lib/rag/ChunkerFactory.js +0 -321
  1183. package/dist/lib/rag/ChunkerRegistry.d.ts +0 -91
  1184. package/dist/lib/rag/ChunkerRegistry.js +0 -422
  1185. package/dist/lib/rag/chunkers/BaseChunker.d.ts +0 -53
  1186. package/dist/lib/rag/chunkers/BaseChunker.js +0 -158
  1187. package/dist/lib/rag/chunkers/CharacterChunker.d.ts +0 -18
  1188. package/dist/lib/rag/chunkers/CharacterChunker.js +0 -29
  1189. package/dist/lib/rag/chunkers/HTMLChunker.d.ts +0 -19
  1190. package/dist/lib/rag/chunkers/HTMLChunker.js +0 -39
  1191. package/dist/lib/rag/chunkers/JSONChunker.d.ts +0 -19
  1192. package/dist/lib/rag/chunkers/JSONChunker.js +0 -69
  1193. package/dist/lib/rag/chunkers/LaTeXChunker.d.ts +0 -15
  1194. package/dist/lib/rag/chunkers/LaTeXChunker.js +0 -64
  1195. package/dist/lib/rag/chunkers/MarkdownChunker.d.ts +0 -37
  1196. package/dist/lib/rag/chunkers/MarkdownChunker.js +0 -315
  1197. package/dist/lib/rag/chunkers/RecursiveChunker.d.ts +0 -27
  1198. package/dist/lib/rag/chunkers/RecursiveChunker.js +0 -140
  1199. package/dist/lib/rag/chunkers/SemanticMarkdownChunker.d.ts +0 -22
  1200. package/dist/lib/rag/chunkers/SemanticMarkdownChunker.js +0 -139
  1201. package/dist/lib/rag/chunkers/SentenceChunker.d.ts +0 -19
  1202. package/dist/lib/rag/chunkers/SentenceChunker.js +0 -67
  1203. package/dist/lib/rag/chunkers/TokenChunker.d.ts +0 -19
  1204. package/dist/lib/rag/chunkers/TokenChunker.js +0 -62
  1205. package/dist/lib/rag/chunkers/index.d.ts +0 -15
  1206. package/dist/lib/rag/chunkers/index.js +0 -16
  1207. package/dist/lib/rag/chunking/characterChunker.d.ts +0 -16
  1208. package/dist/lib/rag/chunking/characterChunker.js +0 -143
  1209. package/dist/lib/rag/chunking/chunkerRegistry.d.ts +0 -67
  1210. package/dist/lib/rag/chunking/chunkerRegistry.js +0 -195
  1211. package/dist/lib/rag/chunking/htmlChunker.d.ts +0 -34
  1212. package/dist/lib/rag/chunking/htmlChunker.js +0 -248
  1213. package/dist/lib/rag/chunking/index.d.ts +0 -15
  1214. package/dist/lib/rag/chunking/index.js +0 -18
  1215. package/dist/lib/rag/chunking/jsonChunker.d.ts +0 -20
  1216. package/dist/lib/rag/chunking/jsonChunker.js +0 -282
  1217. package/dist/lib/rag/chunking/latexChunker.d.ts +0 -26
  1218. package/dist/lib/rag/chunking/latexChunker.js +0 -252
  1219. package/dist/lib/rag/chunking/markdownChunker.d.ts +0 -35
  1220. package/dist/lib/rag/chunking/markdownChunker.js +0 -383
  1221. package/dist/lib/rag/chunking/recursiveChunker.d.ts +0 -19
  1222. package/dist/lib/rag/chunking/recursiveChunker.js +0 -149
  1223. package/dist/lib/rag/chunking/semanticChunker.d.ts +0 -41
  1224. package/dist/lib/rag/chunking/semanticChunker.js +0 -306
  1225. package/dist/lib/rag/chunking/sentenceChunker.d.ts +0 -25
  1226. package/dist/lib/rag/chunking/sentenceChunker.js +0 -231
  1227. package/dist/lib/rag/chunking/tokenChunker.d.ts +0 -36
  1228. package/dist/lib/rag/chunking/tokenChunker.js +0 -184
  1229. package/dist/lib/rag/document/MDocument.d.ts +0 -198
  1230. package/dist/lib/rag/document/MDocument.js +0 -392
  1231. package/dist/lib/rag/document/index.d.ts +0 -5
  1232. package/dist/lib/rag/document/index.js +0 -6
  1233. package/dist/lib/rag/document/loaders.d.ts +0 -142
  1234. package/dist/lib/rag/document/loaders.js +0 -544
  1235. package/dist/lib/rag/errors/RAGError.d.ts +0 -244
  1236. package/dist/lib/rag/errors/RAGError.js +0 -275
  1237. package/dist/lib/rag/errors/index.d.ts +0 -6
  1238. package/dist/lib/rag/errors/index.js +0 -7
  1239. package/dist/lib/rag/graphRag/graphRAG.d.ts +0 -115
  1240. package/dist/lib/rag/graphRag/graphRAG.js +0 -402
  1241. package/dist/lib/rag/graphRag/index.d.ts +0 -4
  1242. package/dist/lib/rag/graphRag/index.js +0 -5
  1243. package/dist/lib/rag/index.d.ts +0 -104
  1244. package/dist/lib/rag/index.js +0 -144
  1245. package/dist/lib/rag/metadata/MetadataExtractorFactory.d.ts +0 -103
  1246. package/dist/lib/rag/metadata/MetadataExtractorFactory.js +0 -419
  1247. package/dist/lib/rag/metadata/MetadataExtractorRegistry.d.ts +0 -99
  1248. package/dist/lib/rag/metadata/MetadataExtractorRegistry.js +0 -363
  1249. package/dist/lib/rag/metadata/index.d.ts +0 -6
  1250. package/dist/lib/rag/metadata/index.js +0 -10
  1251. package/dist/lib/rag/metadata/metadataExtractor.d.ts +0 -69
  1252. package/dist/lib/rag/metadata/metadataExtractor.js +0 -281
  1253. package/dist/lib/rag/pipeline/RAGPipeline.d.ts +0 -105
  1254. package/dist/lib/rag/pipeline/RAGPipeline.js +0 -436
  1255. package/dist/lib/rag/pipeline/contextAssembly.d.ts +0 -80
  1256. package/dist/lib/rag/pipeline/contextAssembly.js +0 -342
  1257. package/dist/lib/rag/pipeline/index.d.ts +0 -5
  1258. package/dist/lib/rag/pipeline/index.js +0 -6
  1259. package/dist/lib/rag/ragIntegration.d.ts +0 -30
  1260. package/dist/lib/rag/ragIntegration.js +0 -327
  1261. package/dist/lib/rag/reranker/RerankerFactory.d.ts +0 -124
  1262. package/dist/lib/rag/reranker/RerankerFactory.js +0 -431
  1263. package/dist/lib/rag/reranker/RerankerRegistry.d.ts +0 -119
  1264. package/dist/lib/rag/reranker/RerankerRegistry.js +0 -403
  1265. package/dist/lib/rag/reranker/index.d.ts +0 -6
  1266. package/dist/lib/rag/reranker/index.js +0 -10
  1267. package/dist/lib/rag/reranker/reranker.d.ts +0 -70
  1268. package/dist/lib/rag/reranker/reranker.js +0 -307
  1269. package/dist/lib/rag/resilience/CircuitBreaker.d.ts +0 -142
  1270. package/dist/lib/rag/resilience/CircuitBreaker.js +0 -432
  1271. package/dist/lib/rag/resilience/RetryHandler.d.ts +0 -95
  1272. package/dist/lib/rag/resilience/RetryHandler.js +0 -305
  1273. package/dist/lib/rag/resilience/index.d.ts +0 -7
  1274. package/dist/lib/rag/resilience/index.js +0 -8
  1275. package/dist/lib/rag/retrieval/hybridSearch.d.ts +0 -53
  1276. package/dist/lib/rag/retrieval/hybridSearch.js +0 -339
  1277. package/dist/lib/rag/retrieval/index.d.ts +0 -5
  1278. package/dist/lib/rag/retrieval/index.js +0 -6
  1279. package/dist/lib/rag/retrieval/vectorQueryTool.d.ts +0 -72
  1280. package/dist/lib/rag/retrieval/vectorQueryTool.js +0 -325
  1281. package/dist/lib/rag/stores/chroma.d.ts +0 -90
  1282. package/dist/lib/rag/stores/chroma.js +0 -281
  1283. package/dist/lib/rag/stores/index.d.ts +0 -21
  1284. package/dist/lib/rag/stores/index.js +0 -22
  1285. package/dist/lib/rag/stores/pgvector.d.ts +0 -95
  1286. package/dist/lib/rag/stores/pgvector.js +0 -400
  1287. package/dist/lib/rag/stores/pinecone.d.ts +0 -85
  1288. package/dist/lib/rag/stores/pinecone.js +0 -159
  1289. package/dist/lib/routing/classifierRouter.d.ts +0 -52
  1290. package/dist/lib/routing/classifierRouter.js +0 -269
  1291. package/dist/lib/routing/classifierStrategies.d.ts +0 -23
  1292. package/dist/lib/routing/classifierStrategies.js +0 -156
  1293. package/dist/lib/routing/index.d.ts +0 -9
  1294. package/dist/lib/routing/index.js +0 -10
  1295. package/dist/lib/routing/modelPool.d.ts +0 -83
  1296. package/dist/lib/routing/modelPool.js +0 -243
  1297. package/dist/lib/routing/requestRouter.d.ts +0 -30
  1298. package/dist/lib/routing/requestRouter.js +0 -81
  1299. package/dist/lib/sdk/toolRegistration.d.ts +0 -74
  1300. package/dist/lib/sdk/toolRegistration.js +0 -383
  1301. package/dist/lib/server/abstract/baseServerAdapter.d.ts +0 -171
  1302. package/dist/lib/server/abstract/baseServerAdapter.js +0 -575
  1303. package/dist/lib/server/adapters/expressAdapter.d.ts +0 -70
  1304. package/dist/lib/server/adapters/expressAdapter.js +0 -487
  1305. package/dist/lib/server/adapters/fastifyAdapter.d.ts +0 -70
  1306. package/dist/lib/server/adapters/fastifyAdapter.js +0 -473
  1307. package/dist/lib/server/adapters/honoAdapter.d.ts +0 -77
  1308. package/dist/lib/server/adapters/honoAdapter.js +0 -633
  1309. package/dist/lib/server/adapters/index.d.ts +0 -7
  1310. package/dist/lib/server/adapters/index.js +0 -8
  1311. package/dist/lib/server/adapters/koaAdapter.d.ts +0 -79
  1312. package/dist/lib/server/adapters/koaAdapter.js +0 -511
  1313. package/dist/lib/server/errors.d.ts +0 -193
  1314. package/dist/lib/server/errors.js +0 -487
  1315. package/dist/lib/server/factory/serverAdapterFactory.d.ts +0 -73
  1316. package/dist/lib/server/factory/serverAdapterFactory.js +0 -161
  1317. package/dist/lib/server/index.d.ts +0 -46
  1318. package/dist/lib/server/index.js +0 -122
  1319. package/dist/lib/server/middleware/abortSignal.d.ts +0 -52
  1320. package/dist/lib/server/middleware/abortSignal.js +0 -112
  1321. package/dist/lib/server/middleware/auth.d.ts +0 -166
  1322. package/dist/lib/server/middleware/auth.js +0 -404
  1323. package/dist/lib/server/middleware/cache.d.ts +0 -161
  1324. package/dist/lib/server/middleware/cache.js +0 -370
  1325. package/dist/lib/server/middleware/common.d.ts +0 -108
  1326. package/dist/lib/server/middleware/common.js +0 -297
  1327. package/dist/lib/server/middleware/deprecation.d.ts +0 -40
  1328. package/dist/lib/server/middleware/deprecation.js +0 -191
  1329. package/dist/lib/server/middleware/index.d.ts +0 -12
  1330. package/dist/lib/server/middleware/index.js +0 -13
  1331. package/dist/lib/server/middleware/mcpBodyAttachment.d.ts +0 -42
  1332. package/dist/lib/server/middleware/mcpBodyAttachment.js +0 -64
  1333. package/dist/lib/server/middleware/rateLimit.d.ts +0 -70
  1334. package/dist/lib/server/middleware/rateLimit.js +0 -224
  1335. package/dist/lib/server/middleware/validation.d.ts +0 -69
  1336. package/dist/lib/server/middleware/validation.js +0 -393
  1337. package/dist/lib/server/openapi/generator.d.ts +0 -61
  1338. package/dist/lib/server/openapi/generator.js +0 -399
  1339. package/dist/lib/server/openapi/index.d.ts +0 -7
  1340. package/dist/lib/server/openapi/index.js +0 -37
  1341. package/dist/lib/server/openapi/schemas.d.ts +0 -94
  1342. package/dist/lib/server/openapi/schemas.js +0 -696
  1343. package/dist/lib/server/openapi/templates.d.ts +0 -108
  1344. package/dist/lib/server/openapi/templates.js +0 -375
  1345. package/dist/lib/server/routes/agentRoutes.d.ts +0 -9
  1346. package/dist/lib/server/routes/agentRoutes.js +0 -423
  1347. package/dist/lib/server/routes/claudeProxyRoutes.d.ts +0 -491
  1348. package/dist/lib/server/routes/claudeProxyRoutes.js +0 -6455
  1349. package/dist/lib/server/routes/codexProxyRoutes.d.ts +0 -64
  1350. package/dist/lib/server/routes/codexProxyRoutes.js +0 -482
  1351. package/dist/lib/server/routes/healthRoutes.d.ts +0 -9
  1352. package/dist/lib/server/routes/healthRoutes.js +0 -234
  1353. package/dist/lib/server/routes/index.d.ts +0 -25
  1354. package/dist/lib/server/routes/index.js +0 -66
  1355. package/dist/lib/server/routes/mcpRoutes.d.ts +0 -9
  1356. package/dist/lib/server/routes/mcpRoutes.js +0 -376
  1357. package/dist/lib/server/routes/memoryRoutes.d.ts +0 -11
  1358. package/dist/lib/server/routes/memoryRoutes.js +0 -366
  1359. package/dist/lib/server/routes/openApiRoutes.d.ts +0 -34
  1360. package/dist/lib/server/routes/openApiRoutes.js +0 -151
  1361. package/dist/lib/server/routes/openaiProxyRoutes.d.ts +0 -38
  1362. package/dist/lib/server/routes/openaiProxyRoutes.js +0 -404
  1363. package/dist/lib/server/routes/toolRoutes.d.ts +0 -9
  1364. package/dist/lib/server/routes/toolRoutes.js +0 -272
  1365. package/dist/lib/server/streaming/dataStream.d.ts +0 -212
  1366. package/dist/lib/server/streaming/dataStream.js +0 -502
  1367. package/dist/lib/server/streaming/index.d.ts +0 -5
  1368. package/dist/lib/server/streaming/index.js +0 -17
  1369. package/dist/lib/server/utils/redaction.d.ts +0 -68
  1370. package/dist/lib/server/utils/redaction.js +0 -321
  1371. package/dist/lib/server/utils/validation.d.ts +0 -153
  1372. package/dist/lib/server/utils/validation.js +0 -265
  1373. package/dist/lib/server/voice/frameBus.d.ts +0 -8
  1374. package/dist/lib/server/voice/frameBus.js +0 -25
  1375. package/dist/lib/server/voice/tokenCompare.d.ts +0 -14
  1376. package/dist/lib/server/voice/tokenCompare.js +0 -23
  1377. package/dist/lib/server/voice/turnManager.d.ts +0 -15
  1378. package/dist/lib/server/voice/turnManager.js +0 -36
  1379. package/dist/lib/server/voice/voiceServerApp.d.ts +0 -1
  1380. package/dist/lib/server/voice/voiceServerApp.js +0 -177
  1381. package/dist/lib/server/voice/voiceWebSocketHandler.d.ts +0 -24
  1382. package/dist/lib/server/voice/voiceWebSocketHandler.js +0 -669
  1383. package/dist/lib/server/websocket/WebSocketHandler.d.ts +0 -107
  1384. package/dist/lib/server/websocket/WebSocketHandler.js +0 -384
  1385. package/dist/lib/server/websocket/index.d.ts +0 -4
  1386. package/dist/lib/server/websocket/index.js +0 -5
  1387. package/dist/lib/services/server/ai/observability/instrumentation.d.ts +0 -229
  1388. package/dist/lib/services/server/ai/observability/instrumentation.js +0 -1244
  1389. package/dist/lib/session/globalSessionState.d.ts +0 -71
  1390. package/dist/lib/session/globalSessionState.js +0 -235
  1391. package/dist/lib/skills/skillMatcher.d.ts +0 -55
  1392. package/dist/lib/skills/skillMatcher.js +0 -170
  1393. package/dist/lib/skills/skillSessionTracker.d.ts +0 -52
  1394. package/dist/lib/skills/skillSessionTracker.js +0 -150
  1395. package/dist/lib/skills/skillStoreRedis.d.ts +0 -30
  1396. package/dist/lib/skills/skillStoreRedis.js +0 -114
  1397. package/dist/lib/skills/skillStoreS3.d.ts +0 -56
  1398. package/dist/lib/skills/skillStoreS3.js +0 -305
  1399. package/dist/lib/skills/skillStores.d.ts +0 -58
  1400. package/dist/lib/skills/skillStores.js +0 -341
  1401. package/dist/lib/skills/skillTools.d.ts +0 -35
  1402. package/dist/lib/skills/skillTools.js +0 -451
  1403. package/dist/lib/skills/skillsManager.d.ts +0 -78
  1404. package/dist/lib/skills/skillsManager.js +0 -281
  1405. package/dist/lib/tasks/autoresearchTaskExecutor.d.ts +0 -31
  1406. package/dist/lib/tasks/autoresearchTaskExecutor.js +0 -304
  1407. package/dist/lib/tasks/backends/bullmqBackend.d.ts +0 -33
  1408. package/dist/lib/tasks/backends/bullmqBackend.js +0 -206
  1409. package/dist/lib/tasks/backends/nodeTimeoutBackend.d.ts +0 -27
  1410. package/dist/lib/tasks/backends/nodeTimeoutBackend.js +0 -141
  1411. package/dist/lib/tasks/backends/taskBackendRegistry.d.ts +0 -31
  1412. package/dist/lib/tasks/backends/taskBackendRegistry.js +0 -66
  1413. package/dist/lib/tasks/errors.d.ts +0 -33
  1414. package/dist/lib/tasks/errors.js +0 -19
  1415. package/dist/lib/tasks/store/fileTaskStore.d.ts +0 -43
  1416. package/dist/lib/tasks/store/fileTaskStore.js +0 -179
  1417. package/dist/lib/tasks/store/redisTaskStore.d.ts +0 -43
  1418. package/dist/lib/tasks/store/redisTaskStore.js +0 -222
  1419. package/dist/lib/tasks/taskExecutor.d.ts +0 -22
  1420. package/dist/lib/tasks/taskExecutor.js +0 -170
  1421. package/dist/lib/tasks/taskManager.d.ts +0 -65
  1422. package/dist/lib/tasks/taskManager.js +0 -545
  1423. package/dist/lib/tasks/tools/taskTools.d.ts +0 -20
  1424. package/dist/lib/tasks/tools/taskTools.js +0 -265
  1425. package/dist/lib/telemetry/attributes.d.ts +0 -136
  1426. package/dist/lib/telemetry/attributes.js +0 -165
  1427. package/dist/lib/telemetry/index.d.ts +0 -20
  1428. package/dist/lib/telemetry/index.js +0 -28
  1429. package/dist/lib/telemetry/telemetryService.d.ts +0 -58
  1430. package/dist/lib/telemetry/telemetryService.js +0 -387
  1431. package/dist/lib/telemetry/traceContext.d.ts +0 -9
  1432. package/dist/lib/telemetry/traceContext.js +0 -19
  1433. package/dist/lib/telemetry/tracers.d.ts +0 -38
  1434. package/dist/lib/telemetry/tracers.js +0 -40
  1435. package/dist/lib/telemetry/withSpan.d.ts +0 -39
  1436. package/dist/lib/telemetry/withSpan.js +0 -138
  1437. package/dist/lib/tools/toolDiscovery.d.ts +0 -70
  1438. package/dist/lib/tools/toolDiscovery.js +0 -303
  1439. package/dist/lib/tools/toolGate.d.ts +0 -16
  1440. package/dist/lib/tools/toolGate.js +0 -51
  1441. package/dist/lib/tools/toolPolicy.d.ts +0 -40
  1442. package/dist/lib/tools/toolPolicy.js +0 -194
  1443. package/dist/lib/types/action.d.ts +0 -207
  1444. package/dist/lib/types/action.js +0 -7
  1445. package/dist/lib/types/agentNetwork.d.ts +0 -1199
  1446. package/dist/lib/types/agentNetwork.js +0 -8
  1447. package/dist/lib/types/aliases.d.ts +0 -368
  1448. package/dist/lib/types/aliases.js +0 -50
  1449. package/dist/lib/types/analytics.d.ts +0 -215
  1450. package/dist/lib/types/analytics.js +0 -6
  1451. package/dist/lib/types/artifact.d.ts +0 -70
  1452. package/dist/lib/types/artifact.js +0 -11
  1453. package/dist/lib/types/auth.d.ts +0 -1140
  1454. package/dist/lib/types/auth.js +0 -10
  1455. package/dist/lib/types/autoresearch.d.ts +0 -206
  1456. package/dist/lib/types/autoresearch.js +0 -18
  1457. package/dist/lib/types/avatar.d.ts +0 -150
  1458. package/dist/lib/types/avatar.js +0 -20
  1459. package/dist/lib/types/circuitBreakerErrors.d.ts +0 -30
  1460. package/dist/lib/types/circuitBreakerErrors.js +0 -35
  1461. package/dist/lib/types/classifierRouter.d.ts +0 -194
  1462. package/dist/lib/types/classifierRouter.js +0 -17
  1463. package/dist/lib/types/cli.d.ts +0 -1734
  1464. package/dist/lib/types/cli.js +0 -22
  1465. package/dist/lib/types/client.d.ts +0 -1287
  1466. package/dist/lib/types/client.js +0 -11
  1467. package/dist/lib/types/codex.d.ts +0 -95
  1468. package/dist/lib/types/codex.js +0 -15
  1469. package/dist/lib/types/common.d.ts +0 -434
  1470. package/dist/lib/types/common.js +0 -52
  1471. package/dist/lib/types/config.d.ts +0 -506
  1472. package/dist/lib/types/config.js +0 -54
  1473. package/dist/lib/types/content.d.ts +0 -18
  1474. package/dist/lib/types/content.js +0 -20
  1475. package/dist/lib/types/context.d.ts +0 -587
  1476. package/dist/lib/types/context.js +0 -401
  1477. package/dist/lib/types/conversation.d.ts +0 -637
  1478. package/dist/lib/types/conversation.js +0 -48
  1479. package/dist/lib/types/conversationMemoryInterface.d.ts +0 -59
  1480. package/dist/lib/types/conversationMemoryInterface.js +0 -7
  1481. package/dist/lib/types/domain.d.ts +0 -62
  1482. package/dist/lib/types/domain.js +0 -6
  1483. package/dist/lib/types/dynamic.d.ts +0 -110
  1484. package/dist/lib/types/dynamic.js +0 -10
  1485. package/dist/lib/types/elicitation.d.ts +0 -278
  1486. package/dist/lib/types/elicitation.js +0 -11
  1487. package/dist/lib/types/enums.d.ts +0 -9
  1488. package/dist/lib/types/enums.js +0 -10
  1489. package/dist/lib/types/errors.d.ts +0 -188
  1490. package/dist/lib/types/errors.js +0 -262
  1491. package/dist/lib/types/evaluation.d.ts +0 -647
  1492. package/dist/lib/types/evaluation.js +0 -2
  1493. package/dist/lib/types/evaluationProviders.d.ts +0 -104
  1494. package/dist/lib/types/evaluationProviders.js +0 -6
  1495. package/dist/lib/types/exporter.d.ts +0 -257
  1496. package/dist/lib/types/exporter.js +0 -6
  1497. package/dist/lib/types/externalMcp.d.ts +0 -349
  1498. package/dist/lib/types/externalMcp.js +0 -7
  1499. package/dist/lib/types/file.d.ts +0 -616
  1500. package/dist/lib/types/file.js +0 -5
  1501. package/dist/lib/types/fileReference.d.ts +0 -243
  1502. package/dist/lib/types/fileReference.js +0 -22
  1503. package/dist/lib/types/generate.d.ts +0 -1520
  1504. package/dist/lib/types/generate.js +0 -2
  1505. package/dist/lib/types/grounding.d.ts +0 -231
  1506. package/dist/lib/types/grounding.js +0 -12
  1507. package/dist/lib/types/guardrails.d.ts +0 -116
  1508. package/dist/lib/types/guardrails.js +0 -2
  1509. package/dist/lib/types/hitl.d.ts +0 -237
  1510. package/dist/lib/types/hitl.js +0 -9
  1511. package/dist/lib/types/imageGen.d.ts +0 -255
  1512. package/dist/lib/types/imageGen.js +0 -25
  1513. package/dist/lib/types/index.d.ts +0 -86
  1514. package/dist/lib/types/index.js +0 -98
  1515. package/dist/lib/types/ioProcessor.d.ts +0 -119
  1516. package/dist/lib/types/ioProcessor.js +0 -10
  1517. package/dist/lib/types/isolatedAgent.d.ts +0 -365
  1518. package/dist/lib/types/isolatedAgent.js +0 -12
  1519. package/dist/lib/types/knowledge.d.ts +0 -342
  1520. package/dist/lib/types/knowledge.js +0 -30
  1521. package/dist/lib/types/livekit.d.ts +0 -512
  1522. package/dist/lib/types/livekit.js +0 -13
  1523. package/dist/lib/types/loopEngine.d.ts +0 -306
  1524. package/dist/lib/types/loopEngine.js +0 -2
  1525. package/dist/lib/types/mcp.d.ts +0 -2135
  1526. package/dist/lib/types/mcp.js +0 -6
  1527. package/dist/lib/types/mcpOutput.d.ts +0 -40
  1528. package/dist/lib/types/mcpOutput.js +0 -9
  1529. package/dist/lib/types/memory.d.ts +0 -96
  1530. package/dist/lib/types/memory.js +0 -23
  1531. package/dist/lib/types/middleware.d.ts +0 -435
  1532. package/dist/lib/types/middleware.js +0 -2
  1533. package/dist/lib/types/model.d.ts +0 -342
  1534. package/dist/lib/types/model.js +0 -32
  1535. package/dist/lib/types/modelPool.d.ts +0 -47
  1536. package/dist/lib/types/modelPool.js +0 -11
  1537. package/dist/lib/types/multimodal.d.ts +0 -614
  1538. package/dist/lib/types/multimodal.js +0 -144
  1539. package/dist/lib/types/music.d.ts +0 -172
  1540. package/dist/lib/types/music.js +0 -21
  1541. package/dist/lib/types/nativeTools.d.ts +0 -16
  1542. package/dist/lib/types/nativeTools.js +0 -2
  1543. package/dist/lib/types/noOutputSentinel.d.ts +0 -26
  1544. package/dist/lib/types/noOutputSentinel.js +0 -2
  1545. package/dist/lib/types/observability.d.ts +0 -502
  1546. package/dist/lib/types/observability.js +0 -7
  1547. package/dist/lib/types/openaiCompatible.d.ts +0 -287
  1548. package/dist/lib/types/openaiCompatible.js +0 -2
  1549. package/dist/lib/types/ppt.d.ts +0 -1093
  1550. package/dist/lib/types/ppt.js +0 -37
  1551. package/dist/lib/types/processor.d.ts +0 -993
  1552. package/dist/lib/types/processor.js +0 -91
  1553. package/dist/lib/types/providers.d.ts +0 -2155
  1554. package/dist/lib/types/providers.js +0 -112
  1555. package/dist/lib/types/proxy.d.ts +0 -2789
  1556. package/dist/lib/types/proxy.js +0 -17
  1557. package/dist/lib/types/proxyClient.d.ts +0 -54
  1558. package/dist/lib/types/proxyClient.js +0 -2
  1559. package/dist/lib/types/rag.d.ts +0 -1332
  1560. package/dist/lib/types/rag.js +0 -2
  1561. package/dist/lib/types/realtime.d.ts +0 -243
  1562. package/dist/lib/types/realtime.js +0 -70
  1563. package/dist/lib/types/replicate.d.ts +0 -67
  1564. package/dist/lib/types/replicate.js +0 -10
  1565. package/dist/lib/types/requestRouter.d.ts +0 -75
  1566. package/dist/lib/types/requestRouter.js +0 -16
  1567. package/dist/lib/types/safeFetch.d.ts +0 -24
  1568. package/dist/lib/types/safeFetch.js +0 -7
  1569. package/dist/lib/types/scorer.d.ts +0 -564
  1570. package/dist/lib/types/scorer.js +0 -6
  1571. package/dist/lib/types/sdk.d.ts +0 -23
  1572. package/dist/lib/types/sdk.js +0 -9
  1573. package/dist/lib/types/server.d.ts +0 -1192
  1574. package/dist/lib/types/server.js +0 -68
  1575. package/dist/lib/types/service.d.ts +0 -79
  1576. package/dist/lib/types/service.js +0 -6
  1577. package/dist/lib/types/skills.d.ts +0 -427
  1578. package/dist/lib/types/skills.js +0 -17
  1579. package/dist/lib/types/span.d.ts +0 -247
  1580. package/dist/lib/types/span.js +0 -96
  1581. package/dist/lib/types/stream.d.ts +0 -771
  1582. package/dist/lib/types/stream.js +0 -2
  1583. package/dist/lib/types/streamDedup.d.ts +0 -14
  1584. package/dist/lib/types/streamDedup.js +0 -2
  1585. package/dist/lib/types/streaming.d.ts +0 -15
  1586. package/dist/lib/types/streaming.js +0 -2
  1587. package/dist/lib/types/stt.d.ts +0 -585
  1588. package/dist/lib/types/stt.js +0 -90
  1589. package/dist/lib/types/subscription.d.ts +0 -1064
  1590. package/dist/lib/types/subscription.js +0 -10
  1591. package/dist/lib/types/task.d.ts +0 -313
  1592. package/dist/lib/types/task.js +0 -37
  1593. package/dist/lib/types/taskClassification.d.ts +0 -52
  1594. package/dist/lib/types/taskClassification.js +0 -6
  1595. package/dist/lib/types/toolDedup.d.ts +0 -45
  1596. package/dist/lib/types/toolDedup.js +0 -14
  1597. package/dist/lib/types/toolResolution.d.ts +0 -83
  1598. package/dist/lib/types/toolResolution.js +0 -11
  1599. package/dist/lib/types/toolRouting.d.ts +0 -350
  1600. package/dist/lib/types/toolRouting.js +0 -19
  1601. package/dist/lib/types/tools.d.ts +0 -531
  1602. package/dist/lib/types/tools.js +0 -26
  1603. package/dist/lib/types/tts.d.ts +0 -195
  1604. package/dist/lib/types/tts.js +0 -65
  1605. package/dist/lib/types/utilities.d.ts +0 -310
  1606. package/dist/lib/types/utilities.js +0 -5
  1607. package/dist/lib/types/vectorStoreChroma.d.ts +0 -67
  1608. package/dist/lib/types/vectorStoreChroma.js +0 -12
  1609. package/dist/lib/types/vectorStorePinecone.d.ts +0 -48
  1610. package/dist/lib/types/vectorStorePinecone.js +0 -12
  1611. package/dist/lib/types/video.d.ts +0 -89
  1612. package/dist/lib/types/video.js +0 -15
  1613. package/dist/lib/types/voice.d.ts +0 -272
  1614. package/dist/lib/types/voice.js +0 -137
  1615. package/dist/lib/types/workflow.d.ts +0 -598
  1616. package/dist/lib/types/workflow.js +0 -24
  1617. package/dist/lib/utils/analyticsUtils.d.ts +0 -37
  1618. package/dist/lib/utils/analyticsUtils.js +0 -110
  1619. package/dist/lib/utils/anthropicCacheBreakpoints.d.ts +0 -43
  1620. package/dist/lib/utils/anthropicCacheBreakpoints.js +0 -151
  1621. package/dist/lib/utils/anthropicTraceSanitizer.d.ts +0 -7
  1622. package/dist/lib/utils/anthropicTraceSanitizer.js +0 -26
  1623. package/dist/lib/utils/async/delay.d.ts +0 -40
  1624. package/dist/lib/utils/async/delay.js +0 -43
  1625. package/dist/lib/utils/async/index.d.ts +0 -23
  1626. package/dist/lib/utils/async/index.js +0 -24
  1627. package/dist/lib/utils/async/retry.d.ts +0 -107
  1628. package/dist/lib/utils/async/retry.js +0 -172
  1629. package/dist/lib/utils/async/withTimeout.d.ts +0 -85
  1630. package/dist/lib/utils/async/withTimeout.js +0 -144
  1631. package/dist/lib/utils/asyncMutex.d.ts +0 -14
  1632. package/dist/lib/utils/asyncMutex.js +0 -61
  1633. package/dist/lib/utils/audioFormatDetector.d.ts +0 -15
  1634. package/dist/lib/utils/audioFormatDetector.js +0 -34
  1635. package/dist/lib/utils/avatarProcessor.d.ts +0 -78
  1636. package/dist/lib/utils/avatarProcessor.js +0 -173
  1637. package/dist/lib/utils/cloneOptions.d.ts +0 -36
  1638. package/dist/lib/utils/cloneOptions.js +0 -62
  1639. package/dist/lib/utils/conversationMemory.d.ts +0 -80
  1640. package/dist/lib/utils/conversationMemory.js +0 -670
  1641. package/dist/lib/utils/csvProcessor.d.ts +0 -221
  1642. package/dist/lib/utils/csvProcessor.js +0 -1527
  1643. package/dist/lib/utils/csvUtils.d.ts +0 -26
  1644. package/dist/lib/utils/csvUtils.js +0 -85
  1645. package/dist/lib/utils/errorClassifier.d.ts +0 -30
  1646. package/dist/lib/utils/errorClassifier.js +0 -183
  1647. package/dist/lib/utils/errorHandling.d.ts +0 -398
  1648. package/dist/lib/utils/errorHandling.js +0 -1282
  1649. package/dist/lib/utils/evaluationUtils.d.ts +0 -27
  1650. package/dist/lib/utils/evaluationUtils.js +0 -132
  1651. package/dist/lib/utils/factoryProcessing.d.ts +0 -71
  1652. package/dist/lib/utils/factoryProcessing.js +0 -590
  1653. package/dist/lib/utils/fileDetector.d.ts +0 -198
  1654. package/dist/lib/utils/fileDetector.js +0 -2806
  1655. package/dist/lib/utils/generation.d.ts +0 -8
  1656. package/dist/lib/utils/generation.js +0 -9
  1657. package/dist/lib/utils/generationErrors.d.ts +0 -10
  1658. package/dist/lib/utils/generationErrors.js +0 -11
  1659. package/dist/lib/utils/imageCache.d.ts +0 -124
  1660. package/dist/lib/utils/imageCache.js +0 -437
  1661. package/dist/lib/utils/imageDetection.d.ts +0 -15
  1662. package/dist/lib/utils/imageDetection.js +0 -53
  1663. package/dist/lib/utils/imageProcessor.d.ts +0 -296
  1664. package/dist/lib/utils/imageProcessor.js +0 -1158
  1665. package/dist/lib/utils/isoBmff.d.ts +0 -24
  1666. package/dist/lib/utils/isoBmff.js +0 -83
  1667. package/dist/lib/utils/json/coerce.d.ts +0 -30
  1668. package/dist/lib/utils/json/coerce.js +0 -412
  1669. package/dist/lib/utils/json/extract.d.ts +0 -112
  1670. package/dist/lib/utils/json/extract.js +0 -299
  1671. package/dist/lib/utils/json/index.d.ts +0 -36
  1672. package/dist/lib/utils/json/index.js +0 -37
  1673. package/dist/lib/utils/json/safeParse.d.ts +0 -130
  1674. package/dist/lib/utils/json/safeParse.js +0 -191
  1675. package/dist/lib/utils/lifecycleCallbacks.d.ts +0 -56
  1676. package/dist/lib/utils/lifecycleCallbacks.js +0 -100
  1677. package/dist/lib/utils/lifecycleTimeout.d.ts +0 -25
  1678. package/dist/lib/utils/lifecycleTimeout.js +0 -39
  1679. package/dist/lib/utils/logSanitize.d.ts +0 -285
  1680. package/dist/lib/utils/logSanitize.js +0 -555
  1681. package/dist/lib/utils/logger.d.ts +0 -273
  1682. package/dist/lib/utils/logger.js +0 -516
  1683. package/dist/lib/utils/loggingFetch.d.ts +0 -29
  1684. package/dist/lib/utils/loggingFetch.js +0 -60
  1685. package/dist/lib/utils/loopUtils.d.ts +0 -70
  1686. package/dist/lib/utils/loopUtils.js +0 -263
  1687. package/dist/lib/utils/markupSniff.d.ts +0 -37
  1688. package/dist/lib/utils/markupSniff.js +0 -125
  1689. package/dist/lib/utils/mcpDefaults.d.ts +0 -54
  1690. package/dist/lib/utils/mcpDefaults.js +0 -135
  1691. package/dist/lib/utils/mcpErrorText.d.ts +0 -37
  1692. package/dist/lib/utils/mcpErrorText.js +0 -95
  1693. package/dist/lib/utils/mediaDuration.d.ts +0 -23
  1694. package/dist/lib/utils/mediaDuration.js +0 -45
  1695. package/dist/lib/utils/messageBuilder.d.ts +0 -59
  1696. package/dist/lib/utils/messageBuilder.js +0 -2716
  1697. package/dist/lib/utils/mimeTypeHints.d.ts +0 -40
  1698. package/dist/lib/utils/mimeTypeHints.js +0 -122
  1699. package/dist/lib/utils/modelAliasResolver.d.ts +0 -17
  1700. package/dist/lib/utils/modelAliasResolver.js +0 -55
  1701. package/dist/lib/utils/modelChoices.d.ts +0 -75
  1702. package/dist/lib/utils/modelChoices.js +0 -698
  1703. package/dist/lib/utils/modelDetection.d.ts +0 -37
  1704. package/dist/lib/utils/modelDetection.js +0 -131
  1705. package/dist/lib/utils/modelRouter.d.ts +0 -91
  1706. package/dist/lib/utils/modelRouter.js +0 -293
  1707. package/dist/lib/utils/multimodalOptionsBuilder.d.ts +0 -74
  1708. package/dist/lib/utils/multimodalOptionsBuilder.js +0 -74
  1709. package/dist/lib/utils/musicProcessor.d.ts +0 -77
  1710. package/dist/lib/utils/musicProcessor.js +0 -190
  1711. package/dist/lib/utils/noOutputSentinel.d.ts +0 -67
  1712. package/dist/lib/utils/noOutputSentinel.js +0 -180
  1713. package/dist/lib/utils/observabilityHelpers.d.ts +0 -27
  1714. package/dist/lib/utils/observabilityHelpers.js +0 -48
  1715. package/dist/lib/utils/optionsConversion.d.ts +0 -47
  1716. package/dist/lib/utils/optionsConversion.js +0 -128
  1717. package/dist/lib/utils/optionsUtils.d.ts +0 -175
  1718. package/dist/lib/utils/optionsUtils.js +0 -970
  1719. package/dist/lib/utils/parameterValidation.d.ts +0 -200
  1720. package/dist/lib/utils/parameterValidation.js +0 -981
  1721. package/dist/lib/utils/pdfProcessor.d.ts +0 -137
  1722. package/dist/lib/utils/pdfProcessor.js +0 -689
  1723. package/dist/lib/utils/performance.d.ts +0 -93
  1724. package/dist/lib/utils/performance.js +0 -223
  1725. package/dist/lib/utils/piiDetector.d.ts +0 -24
  1726. package/dist/lib/utils/piiDetector.js +0 -221
  1727. package/dist/lib/utils/pricing.d.ts +0 -26
  1728. package/dist/lib/utils/pricing.js +0 -890
  1729. package/dist/lib/utils/promptRedaction.d.ts +0 -22
  1730. package/dist/lib/utils/promptRedaction.js +0 -63
  1731. package/dist/lib/utils/providerConfig.d.ts +0 -393
  1732. package/dist/lib/utils/providerConfig.js +0 -1363
  1733. package/dist/lib/utils/providerErrorClassification.d.ts +0 -58
  1734. package/dist/lib/utils/providerErrorClassification.js +0 -149
  1735. package/dist/lib/utils/providerHealth.d.ts +0 -253
  1736. package/dist/lib/utils/providerHealth.js +0 -1479
  1737. package/dist/lib/utils/providerRetry.d.ts +0 -68
  1738. package/dist/lib/utils/providerRetry.js +0 -230
  1739. package/dist/lib/utils/providerSetupMessages.d.ts +0 -8
  1740. package/dist/lib/utils/providerSetupMessages.js +0 -122
  1741. package/dist/lib/utils/providerUtils.d.ts +0 -38
  1742. package/dist/lib/utils/providerUtils.js +0 -366
  1743. package/dist/lib/utils/rateLimiter.d.ts +0 -75
  1744. package/dist/lib/utils/rateLimiter.js +0 -201
  1745. package/dist/lib/utils/redis.d.ts +0 -119
  1746. package/dist/lib/utils/redis.js +0 -530
  1747. package/dist/lib/utils/responseValidator.d.ts +0 -21
  1748. package/dist/lib/utils/responseValidator.js +0 -354
  1749. package/dist/lib/utils/retryAfter.d.ts +0 -7
  1750. package/dist/lib/utils/retryAfter.js +0 -44
  1751. package/dist/lib/utils/retryHandler.d.ts +0 -82
  1752. package/dist/lib/utils/retryHandler.js +0 -270
  1753. package/dist/lib/utils/retryability.d.ts +0 -27
  1754. package/dist/lib/utils/retryability.js +0 -45
  1755. package/dist/lib/utils/safeFetch.d.ts +0 -26
  1756. package/dist/lib/utils/safeFetch.js +0 -121
  1757. package/dist/lib/utils/sanitizers/filename.d.ts +0 -116
  1758. package/dist/lib/utils/sanitizers/filename.js +0 -366
  1759. package/dist/lib/utils/sanitizers/html.d.ts +0 -170
  1760. package/dist/lib/utils/sanitizers/html.js +0 -326
  1761. package/dist/lib/utils/sanitizers/index.d.ts +0 -26
  1762. package/dist/lib/utils/sanitizers/index.js +0 -30
  1763. package/dist/lib/utils/sanitizers/svg.d.ts +0 -71
  1764. package/dist/lib/utils/sanitizers/svg.js +0 -482
  1765. package/dist/lib/utils/schemaConversion.d.ts +0 -56
  1766. package/dist/lib/utils/schemaConversion.js +0 -656
  1767. package/dist/lib/utils/sizeGuard.d.ts +0 -34
  1768. package/dist/lib/utils/sizeGuard.js +0 -45
  1769. package/dist/lib/utils/ssrfGuard.d.ts +0 -60
  1770. package/dist/lib/utils/ssrfGuard.js +0 -446
  1771. package/dist/lib/utils/sttProcessor.d.ts +0 -125
  1772. package/dist/lib/utils/sttProcessor.js +0 -301
  1773. package/dist/lib/utils/systemMessages.d.ts +0 -29
  1774. package/dist/lib/utils/systemMessages.js +0 -45
  1775. package/dist/lib/utils/taskClassificationUtils.d.ts +0 -55
  1776. package/dist/lib/utils/taskClassificationUtils.js +0 -150
  1777. package/dist/lib/utils/taskClassifier.d.ts +0 -23
  1778. package/dist/lib/utils/taskClassifier.js +0 -95
  1779. package/dist/lib/utils/textEncoding.d.ts +0 -25
  1780. package/dist/lib/utils/textEncoding.js +0 -141
  1781. package/dist/lib/utils/thinkingConfig.d.ts +0 -76
  1782. package/dist/lib/utils/thinkingConfig.js +0 -105
  1783. package/dist/lib/utils/timeout.d.ts +0 -158
  1784. package/dist/lib/utils/timeout.js +0 -427
  1785. package/dist/lib/utils/tokenEstimation.d.ts +0 -90
  1786. package/dist/lib/utils/tokenEstimation.js +0 -187
  1787. package/dist/lib/utils/tokenLimits.d.ts +0 -53
  1788. package/dist/lib/utils/tokenLimits.js +0 -236
  1789. package/dist/lib/utils/tokenUtils.d.ts +0 -101
  1790. package/dist/lib/utils/tokenUtils.js +0 -323
  1791. package/dist/lib/utils/tool.d.ts +0 -8
  1792. package/dist/lib/utils/tool.js +0 -9
  1793. package/dist/lib/utils/toolCallRepair.d.ts +0 -14
  1794. package/dist/lib/utils/toolCallRepair.js +0 -286
  1795. package/dist/lib/utils/toolChoice.d.ts +0 -4
  1796. package/dist/lib/utils/toolChoice.js +0 -7
  1797. package/dist/lib/utils/toolEndEmitter.d.ts +0 -25
  1798. package/dist/lib/utils/toolEndEmitter.js +0 -65
  1799. package/dist/lib/utils/toolUtils.d.ts +0 -40
  1800. package/dist/lib/utils/toolUtils.js +0 -76
  1801. package/dist/lib/utils/transformationUtils.d.ts +0 -218
  1802. package/dist/lib/utils/transformationUtils.js +0 -578
  1803. package/dist/lib/utils/tripwireEvaluator.d.ts +0 -73
  1804. package/dist/lib/utils/tripwireEvaluator.js +0 -285
  1805. package/dist/lib/utils/tryImport.d.ts +0 -35
  1806. package/dist/lib/utils/tryImport.js +0 -95
  1807. package/dist/lib/utils/ttsProcessor.d.ts +0 -159
  1808. package/dist/lib/utils/ttsProcessor.js +0 -293
  1809. package/dist/lib/utils/typeUtils.d.ts +0 -77
  1810. package/dist/lib/utils/typeUtils.js +0 -98
  1811. package/dist/lib/utils/videoAnalysisProcessor.d.ts +0 -24
  1812. package/dist/lib/utils/videoAnalysisProcessor.js +0 -61
  1813. package/dist/lib/utils/videoProcessor.d.ts +0 -64
  1814. package/dist/lib/utils/videoProcessor.js +0 -196
  1815. package/dist/lib/voice/RealtimeVoiceAPI.d.ts +0 -186
  1816. package/dist/lib/voice/RealtimeVoiceAPI.js +0 -431
  1817. package/dist/lib/voice/audio-utils.d.ts +0 -135
  1818. package/dist/lib/voice/audio-utils.js +0 -435
  1819. package/dist/lib/voice/errors.d.ts +0 -123
  1820. package/dist/lib/voice/errors.js +0 -386
  1821. package/dist/lib/voice/index.d.ts +0 -49
  1822. package/dist/lib/voice/index.js +0 -177
  1823. package/dist/lib/voice/livekit/brain.d.ts +0 -21
  1824. package/dist/lib/voice/livekit/brain.js +0 -75
  1825. package/dist/lib/voice/livekit/config.d.ts +0 -52
  1826. package/dist/lib/voice/livekit/config.js +0 -134
  1827. package/dist/lib/voice/livekit/eventBridge.d.ts +0 -27
  1828. package/dist/lib/voice/livekit/eventBridge.js +0 -360
  1829. package/dist/lib/voice/livekit/index.d.ts +0 -22
  1830. package/dist/lib/voice/livekit/index.js +0 -23
  1831. package/dist/lib/voice/livekit/realtimeEventBridge.d.ts +0 -14
  1832. package/dist/lib/voice/livekit/realtimeEventBridge.js +0 -161
  1833. package/dist/lib/voice/livekit/realtimeMcpTools.d.ts +0 -31
  1834. package/dist/lib/voice/livekit/realtimeMcpTools.js +0 -206
  1835. package/dist/lib/voice/livekit/realtimeVoiceAgent.d.ts +0 -26
  1836. package/dist/lib/voice/livekit/realtimeVoiceAgent.js +0 -365
  1837. package/dist/lib/voice/livekit/roomContext.d.ts +0 -23
  1838. package/dist/lib/voice/livekit/roomContext.js +0 -57
  1839. package/dist/lib/voice/livekit/roomDispatch.d.ts +0 -24
  1840. package/dist/lib/voice/livekit/roomDispatch.js +0 -31
  1841. package/dist/lib/voice/livekit/schemaSanitizer.d.ts +0 -26
  1842. package/dist/lib/voice/livekit/schemaSanitizer.js +0 -144
  1843. package/dist/lib/voice/livekit/tokens.d.ts +0 -19
  1844. package/dist/lib/voice/livekit/tokens.js +0 -51
  1845. package/dist/lib/voice/livekit/vertexAuth.d.ts +0 -30
  1846. package/dist/lib/voice/livekit/vertexAuth.js +0 -73
  1847. package/dist/lib/voice/livekit/voiceAgent.d.ts +0 -32
  1848. package/dist/lib/voice/livekit/voiceAgent.js +0 -425
  1849. package/dist/lib/voice/livekit/voiceAgentWorker.d.ts +0 -29
  1850. package/dist/lib/voice/livekit/voiceAgentWorker.js +0 -122
  1851. package/dist/lib/voice/providers/AzureSTT.d.ts +0 -47
  1852. package/dist/lib/voice/providers/AzureSTT.js +0 -345
  1853. package/dist/lib/voice/providers/AzureTTS.d.ts +0 -59
  1854. package/dist/lib/voice/providers/AzureTTS.js +0 -349
  1855. package/dist/lib/voice/providers/CartesiaTTS.d.ts +0 -31
  1856. package/dist/lib/voice/providers/CartesiaTTS.js +0 -189
  1857. package/dist/lib/voice/providers/DeepgramSTT.d.ts +0 -40
  1858. package/dist/lib/voice/providers/DeepgramSTT.js +0 -550
  1859. package/dist/lib/voice/providers/ElevenLabsTTS.d.ts +0 -53
  1860. package/dist/lib/voice/providers/ElevenLabsTTS.js +0 -311
  1861. package/dist/lib/voice/providers/FishAudioTTS.d.ts +0 -27
  1862. package/dist/lib/voice/providers/FishAudioTTS.js +0 -183
  1863. package/dist/lib/voice/providers/GeminiLive.d.ts +0 -52
  1864. package/dist/lib/voice/providers/GeminiLive.js +0 -372
  1865. package/dist/lib/voice/providers/GoogleSTT.d.ts +0 -60
  1866. package/dist/lib/voice/providers/GoogleSTT.js +0 -454
  1867. package/dist/lib/voice/providers/OpenAIRealtime.d.ts +0 -47
  1868. package/dist/lib/voice/providers/OpenAIRealtime.js +0 -412
  1869. package/dist/lib/voice/providers/OpenAISTT.d.ts +0 -41
  1870. package/dist/lib/voice/providers/OpenAISTT.js +0 -286
  1871. package/dist/lib/voice/providers/OpenAITTS.d.ts +0 -55
  1872. package/dist/lib/voice/providers/OpenAITTS.js +0 -285
  1873. package/dist/lib/voice/stream-handler.d.ts +0 -166
  1874. package/dist/lib/voice/stream-handler.js +0 -514
  1875. package/dist/lib/workflow/LAYER-EXAMPLES.d.ts +0 -13
  1876. package/dist/lib/workflow/LAYER-EXAMPLES.js +0 -312
  1877. package/dist/lib/workflow/PROMPT-EXAMPLES.d.ts +0 -117
  1878. package/dist/lib/workflow/PROMPT-EXAMPLES.js +0 -246
  1879. package/dist/lib/workflow/config.d.ts +0 -376
  1880. package/dist/lib/workflow/config.js +0 -399
  1881. package/dist/lib/workflow/core/ensembleExecutor.d.ts +0 -55
  1882. package/dist/lib/workflow/core/ensembleExecutor.js +0 -451
  1883. package/dist/lib/workflow/core/judgeScorer.d.ts +0 -25
  1884. package/dist/lib/workflow/core/judgeScorer.js +0 -568
  1885. package/dist/lib/workflow/core/responseConditioner.d.ts +0 -21
  1886. package/dist/lib/workflow/core/responseConditioner.js +0 -243
  1887. package/dist/lib/workflow/core/workflowRegistry.d.ts +0 -72
  1888. package/dist/lib/workflow/core/workflowRegistry.js +0 -305
  1889. package/dist/lib/workflow/core/workflowRunner.d.ts +0 -61
  1890. package/dist/lib/workflow/core/workflowRunner.js +0 -642
  1891. package/dist/lib/workflow/index.d.ts +0 -21
  1892. package/dist/lib/workflow/index.js +0 -46
  1893. package/dist/lib/workflow/utils/workflowMetrics.d.ts +0 -74
  1894. package/dist/lib/workflow/utils/workflowMetrics.js +0 -312
  1895. package/dist/lib/workflow/utils/workflowValidation.d.ts +0 -29
  1896. package/dist/lib/workflow/utils/workflowValidation.js +0 -421
  1897. package/dist/lib/workflow/workflows/adaptiveWorkflow.d.ts +0 -72
  1898. package/dist/lib/workflow/workflows/adaptiveWorkflow.js +0 -367
  1899. package/dist/lib/workflow/workflows/consensusWorkflow.d.ts +0 -69
  1900. package/dist/lib/workflow/workflows/consensusWorkflow.js +0 -193
  1901. package/dist/lib/workflow/workflows/fallbackWorkflow.d.ts +0 -49
  1902. package/dist/lib/workflow/workflows/fallbackWorkflow.js +0 -226
  1903. package/dist/lib/workflow/workflows/multiJudgeWorkflow.d.ts +0 -70
  1904. package/dist/lib/workflow/workflows/multiJudgeWorkflow.js +0 -352
  1905. package/dist/providers/googleVertex/utils.d.ts +0 -12
  1906. package/dist/providers/googleVertex/utils.js +0 -286
@@ -1,2716 +0,0 @@
1
- import { existsSync, readFileSync, statSync } from "fs";
2
- import { readFile as readFileAsync, stat as statAsync } from "fs/promises";
3
- import { getGlobalDispatcher, interceptors, request } from "undici";
4
- import { MultimodalLogger, ProviderImageAdapter, } from "../adapters/providerImageAdapter.js";
5
- import { CONVERSATION_INSTRUCTIONS, STRUCTURED_OUTPUT_INSTRUCTIONS, } from "../config/conversationMemory.js";
6
- import { getAvailableInputTokens } from "../constants/contextWindows.js";
7
- import { PDF_LIMITS } from "../core/constants.js";
8
- import { enforceAggregateFileBudget, FILE_READ_BUDGET_PERCENT, } from "../context/fileTokenBudget.js";
9
- import { isCSVContent, SIZE_TIER_THRESHOLDS } from "../types/index.js";
10
- import { tracers, ATTR, withSpan } from "../telemetry/index.js";
11
- import { needsVisionTranscode, toVisionCompatibleImage, } from "../adapters/imageFormatSupport.js";
12
- import { FILE_TYPE_REGISTRY, lookupByExtension, } from "../processors/config/fileTypeRegistry.js";
13
- import { ErrorFactory, NeuroLinkError, withTimeout } from "./errorHandling.js";
14
- import { FileDetector } from "./fileDetector.js";
15
- import { detectIsoBmffImageMimeType } from "./isoBmff.js";
16
- import { needsAudioTranscode, supportsNativeAudio, toProviderCompatibleAudio, } from "../adapters/audioFormatSupport.js";
17
- import { getImageCache } from "./imageCache.js";
18
- import { ImageProcessor, imageUtils } from "./imageProcessor.js";
19
- import { logger } from "./logger.js";
20
- import { looksLikeSvgMarkup } from "./markupSniff.js";
21
- import { redactUrlForError } from "./logSanitize.js";
22
- import { PDFImageConverter, PDFProcessor } from "./pdfProcessor.js";
23
- import { urlDownloadRateLimiter } from "./rateLimiter.js";
24
- import { estimateTokens } from "./tokenEstimation.js";
25
- // ---------------------------------------------------------------------------
26
- // SDK-7: Lightweight file-type inference helpers for budget estimation
27
- // These avoid calling the full FileDetector pipeline — they only need to
28
- // classify files into broad categories (video, audio, image, etc.) so
29
- // estimatePostProcessingTokens() can use type-aware estimates.
30
- // ---------------------------------------------------------------------------
31
- /**
32
- * Extension → file type for budget estimation.
33
- *
34
- * Derived from the canonical registry rather than hand-listed: this was a
35
- * fourth copy of the same knowledge, and it disagreed with the detector it is
36
- * supposed to predict — it had no entry for .mpg/.mpeg/.3gp/.aiff and so on, so
37
- * estimatePostProcessingTokens() silently fell back to a generic estimate for
38
- * exactly the large media files whose estimate matters most.
39
- */
40
- const EXTENSION_TYPE_MAP = Object.fromEntries(FILE_TYPE_REGISTRY.flatMap((entry) => entry.extensions.map((ext) => [ext.slice(1), entry.fileType])));
41
- /**
42
- * MIME type → routing type, derived from the same registry as
43
- * {@link EXTENSION_TYPE_MAP} so the two can never disagree about a format.
44
- */
45
- const MIMETYPE_TYPE_MAP = Object.fromEntries(FILE_TYPE_REGISTRY.flatMap((entry) => entry.mimeTypes.map((mime) => [mime.toLowerCase(), entry.fileType])));
46
- /**
47
- * Infer file type from extension in a file path or URL.
48
- * Returns undefined if no extension or unrecognized.
49
- */
50
- function inferFileTypeFromExtension(filePath) {
51
- // Strip query string / fragment for URLs
52
- const cleaned = filePath.split("?")[0].split("#")[0];
53
- const lastDot = cleaned.lastIndexOf(".");
54
- if (lastDot === -1) {
55
- return undefined;
56
- }
57
- const ext = cleaned.slice(lastDot + 1).toLowerCase();
58
- return EXTENSION_TYPE_MAP[ext];
59
- }
60
- /**
61
- * Infer file type from the first few magic bytes of a Buffer.
62
- * Only checks the most common binary types — text types default to undefined.
63
- */
64
- function inferFileTypeFromBuffer(buf) {
65
- if (buf.length < 4) {
66
- return undefined;
67
- }
68
- // SVG is markup and has no magic number, so every signature check below
69
- // misses it and a raw SVG Buffer classified as `undefined` — which meant the
70
- // lazy path, which previews markup away. Checked first because the sniff is
71
- // a cheap look at the head and cannot collide with a binary signature.
72
- //
73
- // Deliberately a substring scan over the head rather than a prolog-stripping
74
- // regex: the obvious pattern for skipping comments and a DOCTYPE is two
75
- // nested quantifiers, which is a ReDoS waiting to happen inside what is
76
- // supposed to be a cheap type check. Over-matching is harmless here — the
77
- // only consequence of a false positive is that a file is processed eagerly.
78
- if (buf.subarray(0, 1024).toString("latin1").includes("<svg")) {
79
- return "svg";
80
- }
81
- // PNG
82
- if (buf[0] === 0x89 &&
83
- buf[1] === 0x50 &&
84
- buf[2] === 0x4e &&
85
- buf[3] === 0x47) {
86
- return "image";
87
- }
88
- // JPEG
89
- if (buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) {
90
- return "image";
91
- }
92
- // GIF
93
- if (buf[0] === 0x47 && buf[1] === 0x49 && buf[2] === 0x46) {
94
- return "image";
95
- }
96
- // WebP (RIFF + WEBP)
97
- if (buf.length >= 12 &&
98
- buf[0] === 0x52 &&
99
- buf[1] === 0x49 &&
100
- buf[2] === 0x46 &&
101
- buf[3] === 0x46 &&
102
- buf[8] === 0x57 &&
103
- buf[9] === 0x45 &&
104
- buf[10] === 0x42 &&
105
- buf[11] === 0x50) {
106
- return "image";
107
- }
108
- // PDF
109
- if (buf[0] === 0x25 &&
110
- buf[1] === 0x50 &&
111
- buf[2] === 0x44 &&
112
- buf[3] === 0x46) {
113
- return "pdf";
114
- }
115
- // MP4/MOV (ftyp at offset 4)
116
- if (buf.length >= 8 &&
117
- buf[4] === 0x66 &&
118
- buf[5] === 0x74 &&
119
- buf[6] === 0x79 &&
120
- buf[7] === 0x70) {
121
- return "video";
122
- }
123
- // MKV/WebM (EBML)
124
- if (buf[0] === 0x1a &&
125
- buf[1] === 0x45 &&
126
- buf[2] === 0xdf &&
127
- buf[3] === 0xa3) {
128
- return "video";
129
- }
130
- // AVI (RIFF + AVI)
131
- if (buf.length >= 12 &&
132
- buf[0] === 0x52 &&
133
- buf[1] === 0x49 &&
134
- buf[2] === 0x46 &&
135
- buf[3] === 0x46 &&
136
- buf[8] === 0x41 &&
137
- buf[9] === 0x56 &&
138
- buf[10] === 0x49 &&
139
- buf[11] === 0x20) {
140
- return "video";
141
- }
142
- // WAV (RIFF + WAVE)
143
- if (buf.length >= 12 &&
144
- buf[0] === 0x52 &&
145
- buf[1] === 0x49 &&
146
- buf[2] === 0x46 &&
147
- buf[3] === 0x46 &&
148
- buf[8] === 0x57 &&
149
- buf[9] === 0x41 &&
150
- buf[10] === 0x56 &&
151
- buf[11] === 0x45) {
152
- return "audio";
153
- }
154
- // MP3 (ID3 tag)
155
- if (buf[0] === 0x49 && buf[1] === 0x44 && buf[2] === 0x33) {
156
- return "audio";
157
- }
158
- // FLAC
159
- if (buf[0] === 0x66 &&
160
- buf[1] === 0x4c &&
161
- buf[2] === 0x61 &&
162
- buf[3] === 0x43) {
163
- return "audio";
164
- }
165
- // OGG
166
- if (buf[0] === 0x4f &&
167
- buf[1] === 0x67 &&
168
- buf[2] === 0x67 &&
169
- buf[3] === 0x53) {
170
- return "audio";
171
- }
172
- // ZIP (also .xlsx, .docx, .pptx — but without extension we default to archive)
173
- if (buf[0] === 0x50 &&
174
- buf[1] === 0x4b &&
175
- buf[2] === 0x03 &&
176
- buf[3] === 0x04) {
177
- return "archive";
178
- }
179
- // GZIP
180
- if (buf[0] === 0x1f && buf[1] === 0x8b) {
181
- return "archive";
182
- }
183
- // RAR
184
- if (buf[0] === 0x52 &&
185
- buf[1] === 0x61 &&
186
- buf[2] === 0x72 &&
187
- buf[3] === 0x21) {
188
- return "archive";
189
- }
190
- return undefined;
191
- }
192
- /**
193
- * Type guard to check if an image input has alt text
194
- */
195
- function isImageWithAltText(image) {
196
- return (typeof image === "object" && !Buffer.isBuffer(image) && "data" in image);
197
- }
198
- /**
199
- * Extract image data from an image input (handles both simple and alt text formats)
200
- */
201
- function extractImageData(image) {
202
- if (isImageWithAltText(image)) {
203
- return image.data;
204
- }
205
- return image;
206
- }
207
- /**
208
- * Extract alt text from an image input if available
209
- */
210
- function extractAltText(image) {
211
- if (isImageWithAltText(image)) {
212
- return image.altText;
213
- }
214
- return undefined;
215
- }
216
- /**
217
- * Type guard for validating message roles
218
- */
219
- function isValidRole(role) {
220
- return (typeof role === "string" &&
221
- (role === "user" || role === "assistant" || role === "system"));
222
- }
223
- /**
224
- * Type guard for validating content items
225
- */
226
- function isValidContentItem(item) {
227
- if (!item || typeof item !== "object") {
228
- return false;
229
- }
230
- const contentItem = item;
231
- if (contentItem.type === "text") {
232
- return typeof contentItem.text === "string";
233
- }
234
- if (contentItem.type === "image") {
235
- return (typeof contentItem.image === "string" &&
236
- (contentItem.mimeType === undefined ||
237
- typeof contentItem.mimeType === "string"));
238
- }
239
- if (contentItem.type === "file") {
240
- return (Buffer.isBuffer(contentItem.data) &&
241
- typeof contentItem.mimeType === "string");
242
- }
243
- return false;
244
- }
245
- /**
246
- * Safely convert content item to AI SDK content format
247
- */
248
- function convertContentItem(item) {
249
- if (!isValidContentItem(item)) {
250
- return null;
251
- }
252
- const contentItem = item;
253
- if (contentItem.type === "text" && typeof contentItem.text === "string") {
254
- return { type: "text", text: contentItem.text };
255
- }
256
- if (contentItem.type === "image" && typeof contentItem.image === "string") {
257
- return {
258
- type: "image",
259
- image: contentItem.image,
260
- ...(contentItem.mimeType && { mediaType: contentItem.mimeType }),
261
- };
262
- }
263
- if (contentItem.type === "file" &&
264
- Buffer.isBuffer(contentItem.data) &&
265
- contentItem.mimeType) {
266
- return {
267
- type: "file",
268
- data: contentItem.data,
269
- mediaType: contentItem.mimeType,
270
- };
271
- }
272
- return null;
273
- }
274
- /**
275
- * Type-safe conversion from MultimodalChatMessage[] to ModelMessage[]
276
- * Filters out invalid content and ensures strict ModelMessage contract compliance
277
- */
278
- export function convertToModelMessages(messages) {
279
- return messages
280
- .map((msg) => {
281
- // Validate role
282
- if (!isValidRole(msg.role)) {
283
- logger.warn("Invalid message role found, skipping", { role: msg.role });
284
- return null;
285
- }
286
- // Handle string content
287
- if (typeof msg.content === "string") {
288
- // Create properly typed discriminated union messages
289
- if (msg.role === "system") {
290
- return {
291
- role: "system",
292
- content: msg.content,
293
- };
294
- }
295
- else if (msg.role === "user") {
296
- return {
297
- role: "user",
298
- content: msg.content,
299
- };
300
- }
301
- else if (msg.role === "assistant") {
302
- return {
303
- role: "assistant",
304
- content: msg.content,
305
- };
306
- }
307
- }
308
- // Handle array content (multimodal) - only user messages support full multimodal content
309
- if (Array.isArray(msg.content)) {
310
- const validContent = msg.content
311
- .map(convertContentItem)
312
- .filter((item) => item !== null);
313
- // If no valid content items, skip the message
314
- if (validContent.length === 0) {
315
- logger.warn("No valid content items found in multimodal message, skipping");
316
- return null;
317
- }
318
- if (msg.role === "user") {
319
- // User messages support both text and image content
320
- return {
321
- role: "user",
322
- content: validContent,
323
- };
324
- }
325
- else if (msg.role === "assistant") {
326
- // Assistant messages only support text content, filter out images
327
- const textOnlyContent = validContent.filter((item) => item.type === "text");
328
- if (textOnlyContent.length === 0) {
329
- // No text content (e.g., only images/files) — skip message
330
- // to avoid sending empty content to providers like Claude
331
- return null;
332
- }
333
- else if (textOnlyContent.length === 1) {
334
- // Single text item, use string content
335
- return {
336
- role: "assistant",
337
- content: textOnlyContent[0].text,
338
- };
339
- }
340
- else {
341
- // Multiple text items, concatenate them
342
- const combinedText = textOnlyContent
343
- .map((item) => item.text)
344
- .join(" ");
345
- return {
346
- role: "assistant",
347
- content: combinedText,
348
- };
349
- }
350
- }
351
- else {
352
- // System messages cannot have multimodal content, convert to text
353
- const textContent = validContent.find((item) => item.type === "text")?.text || "";
354
- return {
355
- role: "system",
356
- content: textContent,
357
- };
358
- }
359
- }
360
- // Invalid content type
361
- logger.warn("Invalid message content type found, skipping", {
362
- contentType: typeof msg.content,
363
- });
364
- return null;
365
- })
366
- .filter((msg) => msg !== null);
367
- }
368
- /**
369
- * Convert ChatMessage to ModelMessage for AI SDK compatibility
370
- */
371
- function toModelMessage(message) {
372
- // Only include messages with roles supported by AI SDK
373
- if (message.role === "user" ||
374
- message.role === "assistant" ||
375
- message.role === "system") {
376
- if (message.content.trim() === "") {
377
- return null;
378
- }
379
- return {
380
- role: message.role,
381
- content: message.content,
382
- };
383
- }
384
- return null; // Filter out tool_call and tool_result messages
385
- }
386
- /**
387
- * Format CSV metadata for LLM consumption
388
- */
389
- function formatCSVMetadata(metadata) {
390
- const parts = [];
391
- if (metadata.rowCount !== undefined) {
392
- parts.push(`${metadata.rowCount} data rows`);
393
- }
394
- if (metadata.columnCount !== undefined) {
395
- parts.push(`${metadata.columnCount} columns`);
396
- }
397
- if (metadata.columnNames && metadata.columnNames.length > 0) {
398
- const columns = metadata.columnNames.join(", ");
399
- parts.push(`Columns: [${columns}]`);
400
- }
401
- if (metadata.hasEmptyColumns) {
402
- parts.push(`⚠️ Contains empty column names`);
403
- }
404
- return parts.length > 0 ? `**Metadata**: ${parts.join(" | ")}` : "";
405
- }
406
- /**
407
- * Check if structured output mode should be enabled
408
- * Structured output is used when a schema is provided with json/structured format
409
- */
410
- function shouldUseStructuredOutput(options) {
411
- return (!!options.schema &&
412
- (options.output?.format === "json" ||
413
- options.output?.format === "structured"));
414
- }
415
- /**
416
- * Log structural metadata about a composed message array without logging content.
417
- * Only logs a compact summary (role counts, total chars, estimated tokens).
418
- * Per-message breakdown is intentionally omitted to avoid log noise
419
- * (~600 lines per retry cascade with many messages).
420
- */
421
- function logMessageComposition(messages, requestId) {
422
- if (!logger.shouldLog("debug")) {
423
- return;
424
- }
425
- const roles = {};
426
- let totalChars = 0;
427
- for (const msg of messages) {
428
- const chars = typeof msg.content === "string" ? msg.content.length : 0;
429
- roles[msg.role] = (roles[msg.role] || 0) + 1;
430
- totalChars += chars;
431
- }
432
- logger.debug("[MessageBuilder] Composed", {
433
- requestId,
434
- totalMessages: messages.length,
435
- roles,
436
- totalChars,
437
- estimatedTokens: Math.ceil(totalChars / 4),
438
- });
439
- }
440
- /**
441
- * Build a properly formatted message array for AI providers
442
- * Combines system prompt, conversation history, and current user prompt
443
- * Supports both TextGenerationOptions and StreamOptions
444
- * Enhanced with CSV file processing support
445
- */
446
- export async function buildMessagesArray(options) {
447
- const messages = [];
448
- // Check if conversation history exists
449
- const hasConversationHistory = options.conversationMessages && options.conversationMessages.length > 0;
450
- // Build enhanced system prompt
451
- let systemPrompt = options.systemPrompt?.trim() || "";
452
- // Add conversation-aware instructions when history exists
453
- if (hasConversationHistory) {
454
- systemPrompt = `${systemPrompt.trim()}${CONVERSATION_INSTRUCTIONS}`;
455
- }
456
- // Add structured output instructions when schema is provided with json/structured format
457
- if (shouldUseStructuredOutput(options)) {
458
- systemPrompt = `${systemPrompt.trim()}${STRUCTURED_OUTPUT_INSTRUCTIONS}`;
459
- }
460
- // Add system message if we have one
461
- if (systemPrompt.trim()) {
462
- messages.push({
463
- role: "system",
464
- content: systemPrompt.trim(),
465
- providerOptions: {
466
- anthropic: { cacheControl: { type: "ephemeral" } },
467
- },
468
- });
469
- }
470
- // Add conversation history if available
471
- // Convert ChatMessages to ModelMessages and filter out tool messages
472
- if (hasConversationHistory && options.conversationMessages) {
473
- for (const chatMessage of options.conversationMessages) {
474
- const coreMessage = toModelMessage(chatMessage);
475
- if (coreMessage) {
476
- messages.push(coreMessage);
477
- }
478
- }
479
- }
480
- // Add current user prompt (required)
481
- // Handle both TextGenerationOptions (prompt field) and StreamOptions (input.text field)
482
- let currentPrompt;
483
- if ("prompt" in options && options.prompt) {
484
- currentPrompt = options.prompt;
485
- }
486
- else if ("input" in options && options.input?.text) {
487
- currentPrompt = options.input.text;
488
- }
489
- // Process CSV files if present and inject into prompt using proper CSV parser
490
- if ("input" in options && options.input) {
491
- const input = options.input;
492
- let csvContent = "";
493
- const csvOptions = "csvOptions" in options ? options.csvOptions : undefined;
494
- // Process explicit csvFiles array
495
- if (input.csvFiles && input.csvFiles.length > 0) {
496
- for (let i = 0; i < input.csvFiles.length; i++) {
497
- const csvFile = input.csvFiles[i];
498
- const filename = extractFilename(csvFile, i);
499
- const filePath = typeof csvFile === "string" ? csvFile : filename;
500
- try {
501
- const result = await FileDetector.detectAndProcess(csvFile, {
502
- allowedTypes: ["csv"],
503
- csvOptions: csvOptions,
504
- });
505
- let csvSection = `\n\n## CSV Data from "${filename}":\n`;
506
- // Add metadata from csv-parser library
507
- if (result.metadata) {
508
- const metadataText = formatCSVMetadata(result.metadata);
509
- if (metadataText) {
510
- csvSection += metadataText + `\n\n`;
511
- }
512
- }
513
- // Put the actual CSV content BEFORE the tool instructions —
514
- // buildCSVToolInstructions references "the CSV data shown above"
515
- // and the trailing position keeps that reference accurate.
516
- // Vertex Gemini misreads CSV-only prompts as "no files attached"
517
- // when the NOTE-then-data order makes the reference dangle.
518
- csvSection += result.content;
519
- csvSection += buildCSVToolInstructions(filePath);
520
- csvContent += csvSection;
521
- logger.info(`[CSV] ✅ Processed: ${filename}`, result.metadata);
522
- }
523
- catch (error) {
524
- logger.error(`[CSV] ❌ Failed to process ${filename}:`, error);
525
- csvContent += `\n\n## CSV Data Error: Failed to process "${filename}"\nReason: ${error instanceof Error ? error.message : "Unknown error"}`;
526
- }
527
- }
528
- }
529
- // Process unified files array (auto-detect CSV)
530
- if (input.files && input.files.length > 0) {
531
- for (const file of input.files) {
532
- const filename = extractFilename(file);
533
- try {
534
- const result = await FileDetector.detectAndProcess(file, {
535
- maxSize: 50 * 1024 * 1024,
536
- allowedTypes: ["csv"],
537
- csvOptions: csvOptions,
538
- mimetypeHint: isFileWithMetadata(file) ? file.mimetype : undefined,
539
- });
540
- if (result.type === "csv") {
541
- let csvSection = `\n\n## CSV Data from "${filename}":\n`;
542
- // Add metadata from csv-parser library
543
- if (result.metadata) {
544
- const metadataText = formatCSVMetadata(result.metadata);
545
- if (metadataText) {
546
- csvSection += metadataText + `\n\n`;
547
- }
548
- }
549
- csvSection += result.content;
550
- csvContent += csvSection;
551
- logger.info(`[FileDetector] ✅ CSV: ${filename}`, result.metadata);
552
- }
553
- }
554
- catch (error) {
555
- // Silently skip non-CSV files in auto-detect mode
556
- logger.debug(`[FileDetector] Skipped ${filename}: ${error instanceof Error ? error.message : String(error)}`);
557
- }
558
- }
559
- }
560
- // Prepend CSV content to current prompt
561
- if (csvContent) {
562
- currentPrompt = csvContent + (currentPrompt || "");
563
- }
564
- }
565
- if (currentPrompt?.trim()) {
566
- messages.push({
567
- role: "user",
568
- content: currentPrompt.trim(),
569
- });
570
- }
571
- const reqId = options.context
572
- ?.requestId;
573
- logMessageComposition(messages, reqId);
574
- return messages;
575
- }
576
- /**
577
- * Enforce aggregate file budget, excluding files that would exceed the context window.
578
- * Mutates options.input.files and options.input.text as needed.
579
- */
580
- function enforceFileBudget(options, provider, model) {
581
- options.input ??= {};
582
- if (!options.input.files || options.input.files.length === 0) {
583
- return;
584
- }
585
- const availableTokens = getAvailableInputTokens(provider, model);
586
- const budgetFiles = options.input.files.map((file, idx) => {
587
- let sizeBytes;
588
- let fileType;
589
- if (Buffer.isBuffer(file)) {
590
- sizeBytes = file.length;
591
- fileType = inferFileTypeFromBuffer(file);
592
- }
593
- else if (typeof file === "string") {
594
- if (existsSync(file)) {
595
- try {
596
- sizeBytes = statSync(file).size;
597
- }
598
- catch {
599
- sizeBytes = 0;
600
- }
601
- }
602
- else {
603
- sizeBytes = file.length;
604
- }
605
- fileType = inferFileTypeFromExtension(file);
606
- }
607
- else {
608
- sizeBytes = 0;
609
- }
610
- return {
611
- name: typeof file === "string" ? file : `file-${idx}`,
612
- sizeBytes,
613
- fileType,
614
- originalIndex: idx,
615
- };
616
- });
617
- const budgetResult = enforceAggregateFileBudget(budgetFiles.map((f) => ({
618
- name: f.name,
619
- sizeBytes: f.sizeBytes,
620
- fileType: f.fileType,
621
- })), availableTokens);
622
- if (budgetResult.excluded.length > 0) {
623
- const includedIndices = new Set(budgetResult.included.map((f) => {
624
- return budgetFiles.findIndex((bf) => bf.name === f.name);
625
- }));
626
- options.input.files = options.input.files.filter((_file, idx) => {
627
- return includedIndices.has(idx);
628
- });
629
- options.input.text =
630
- (options.input.text || "") + "\n\n" + budgetResult.notices.join("\n");
631
- logger.warn(`[FileDetector] Aggregate file budget enforcement: excluded ${budgetResult.excluded.length} file(s)`);
632
- }
633
- }
634
- /**
635
- * Per input, the file entries already folded into text and media.
636
- *
637
- * A WeakMap so a long-lived process cannot accumulate references to request
638
- * payloads: the record vanishes with the input object it is keyed on.
639
- */
640
- const PREPROCESSED_FILES = new WeakMap();
641
- /**
642
- * Ceiling on reading one already-detected local file back off disk.
643
- *
644
- * Sized for the 100 MB this path admits from cold storage, not for the warm
645
- * page cache the read usually hits — detection has just read the same bytes.
646
- */
647
- const FILE_READ_TIMEOUT_MS = 30_000;
648
- /**
649
- * Read a file input's bytes, or null when they cannot be had.
650
- *
651
- * Asynchronous because this path admits files up to 100 MB: a synchronous read
652
- * of one blocks the event loop for every other in-flight request on the
653
- * process, which for a server handling concurrent generations is not a
654
- * micro-optimisation to trade away.
655
- *
656
- * A URL or data URI yields null rather than a fetch: those arrive already
657
- * materialised by the time detection runs, and re-fetching a remote URL here
658
- * would issue a second network request behind the caller's back.
659
- */
660
- async function readFileInputBytes(file) {
661
- try {
662
- if (isFileWithMetadata(file)) {
663
- return file.buffer;
664
- }
665
- if (Buffer.isBuffer(file)) {
666
- return file;
667
- }
668
- if (typeof file === "string") {
669
- const { readFile, stat } = await import("node:fs/promises");
670
- // Two different hangs live here, and they need different guards.
671
- //
672
- // A FIFO or device node blocks inside the read syscall, where neither a
673
- // timeout nor an abort can reach it — measured: with a signal attached,
674
- // a blocked FIFO read stays pending through both open and mid-read. The
675
- // timeout would return while that read sat there forever. So refuse
676
- // anything that is not a regular file up front; that is the only thing
677
- // that actually prevents this case.
678
- //
679
- // A regular file on a slow or hung mount does return control between
680
- // chunks, so there the signal works (measured: rejects with AbortError
681
- // in flight) — and it matters, because racing the promise alone leaves
682
- // the read filling a buffer nobody will collect. Aborting in `finally`
683
- // covers both exits; after a resolved read it is a no-op.
684
- //
685
- // stat-then-read is a TOCTOU window, but a narrow one, and it is strictly
686
- // better than the unbounded read it replaces.
687
- const stats = await withTimeout(stat(file), FILE_READ_TIMEOUT_MS);
688
- if (!stats.isFile()) {
689
- return null;
690
- }
691
- const controller = new AbortController();
692
- try {
693
- return await withTimeout(readFile(file, { signal: controller.signal }), FILE_READ_TIMEOUT_MS);
694
- }
695
- finally {
696
- controller.abort();
697
- }
698
- }
699
- }
700
- catch {
701
- // An unreadable file is not an error here: the metadata summary was
702
- // already appended, so the caller degrades to previous behaviour. This
703
- // covers the missing-file case that an `existsSync` pre-check used to
704
- // (without the TOCTOU gap between check and read) and the timeout above.
705
- }
706
- return null;
707
- }
708
- /**
709
- * Append a detected file result to options.input based on its type.
710
- * Handles CSV, SVG, image, PDF, video, audio, archive, xlsx, docx, pptx, text, and unknown types.
711
- */
712
- async function appendDetectedFileResult(result, file, options) {
713
- options.input ??= {};
714
- const filename = extractFilename(file);
715
- if (result.type === "csv") {
716
- const filePath = typeof file === "string" ? file : filename;
717
- let csvSection = `\n\n## CSV Data from "${filename}":\n`;
718
- if (result.metadata) {
719
- const metadataText = formatCSVMetadata(result.metadata);
720
- if (metadataText) {
721
- csvSection += metadataText + `\n\n`;
722
- }
723
- }
724
- // Put the actual CSV content BEFORE the tool instructions —
725
- // buildCSVToolInstructions references "the CSV data shown above" and
726
- // the trailing position keeps that reference accurate.
727
- csvSection += result.content;
728
- csvSection += buildCSVToolInstructions(filePath);
729
- options.input.text += csvSection;
730
- logger.info(`[FileDetector] ✅ CSV: ${filename}`);
731
- }
732
- else if (result.type === "svg") {
733
- const svgSection = `\n\n## SVG Content from "${filename}":\n\`\`\`xml\n${result.content}\n\`\`\`\n`;
734
- options.input.text += svgSection;
735
- logger.info(`[FileDetector] ✅ SVG (as text): ${filename}`);
736
- }
737
- else if (result.type === "image") {
738
- options.input.images = [...(options.input.images || []), result.content];
739
- logger.info(`[FileDetector] ✅ Image: ${result.mimeType}`);
740
- }
741
- else if (result.type === "pdf") {
742
- options.input.pdfFiles = [
743
- ...(options.input.pdfFiles || []),
744
- result.content,
745
- ];
746
- logger.info(`[FileDetector] ✅ PDF: ${filename}`);
747
- }
748
- else if (result.type === "video") {
749
- if (result.content) {
750
- options.input.text += `\n\n## Video File: "${filename}"\n${result.content}\n`;
751
- }
752
- if (result.images && result.images.length > 0) {
753
- options.input.images = [
754
- ...(options.input.images || []),
755
- ...result.images,
756
- ];
757
- logger.info(`[FileDetector] Added ${result.images.length} video keyframes as images`);
758
- }
759
- logger.info(`[FileDetector] ✅ Video: ${filename}`);
760
- }
761
- else if (result.type === "audio") {
762
- if (result.content) {
763
- options.input.text += `\n\n## Audio File: "${filename}"\n${result.content}\n`;
764
- }
765
- // Carry the bytes forward as well as the summary. Whether they are used is
766
- // decided later, per provider: one that can listen receives the audio, one
767
- // that cannot still gets the summary above and is no worse off than before.
768
- const audioBytes = await readFileInputBytes(file);
769
- if (audioBytes) {
770
- options.input.nativeAudioFiles = [
771
- ...(options.input.nativeAudioFiles || []),
772
- { buffer: audioBytes, filename, mimeType: result.mimeType },
773
- ];
774
- }
775
- if (result.images && result.images.length > 0) {
776
- options.input.images = [
777
- ...(options.input.images || []),
778
- ...result.images,
779
- ];
780
- logger.info(`[FileDetector] Added audio cover art as image`);
781
- }
782
- logger.info(`[FileDetector] ✅ Audio: ${filename}`);
783
- }
784
- else if (result.type === "archive") {
785
- if (result.content) {
786
- options.input.text += `\n\n## Archive File: "${filename}"\n${result.content}\n`;
787
- }
788
- logger.info(`[FileDetector] ✅ Archive: ${filename}`);
789
- }
790
- else if (result.type === "xlsx") {
791
- if (result.content) {
792
- options.input.text += `\n\n## Spreadsheet: "${filename}"\n${result.content}\n`;
793
- }
794
- logger.info(`[FileDetector] ✅ Spreadsheet: ${filename}`);
795
- }
796
- else if (result.type === "docx") {
797
- if (result.content) {
798
- options.input.text += `\n\n## Document: "${filename}"\n${result.content}\n`;
799
- }
800
- logger.info(`[FileDetector] ✅ Document: ${filename}`);
801
- }
802
- else if (result.type === "pptx") {
803
- if (result.content) {
804
- options.input.text += `\n\n## Presentation: "${filename}"\n${result.content}\n`;
805
- }
806
- logger.info(`[FileDetector] ✅ Presentation: ${filename}`);
807
- }
808
- else if (result.type === "text") {
809
- if (result.content) {
810
- const langHint = getLanguageHint(result.mimeType, filename);
811
- const MAX_TEXT_FILE_CHARS = 200_000;
812
- let fileContent = result.content;
813
- let truncated = false;
814
- if (fileContent.length > MAX_TEXT_FILE_CHARS) {
815
- const headChars = Math.floor(MAX_TEXT_FILE_CHARS * 0.75);
816
- const tailChars = Math.floor(MAX_TEXT_FILE_CHARS * 0.25);
817
- const omittedChars = fileContent.length - headChars - tailChars;
818
- fileContent =
819
- fileContent.slice(0, headChars) +
820
- `\n\n... [${omittedChars.toLocaleString()} characters omitted — file truncated to fit context window] ...\n\n` +
821
- fileContent.slice(-tailChars);
822
- truncated = true;
823
- }
824
- const textSection = langHint
825
- ? `\n\n## File: "${filename}"\n\`\`\`${langHint}\n${fileContent}\n\`\`\`\n`
826
- : `\n\n## File: "${filename}"\n${fileContent}\n`;
827
- options.input.text += textSection;
828
- if (truncated) {
829
- logger.warn(`[FileDetector] Large text file "${filename}" truncated from ${result.content.length.toLocaleString()} to ${MAX_TEXT_FILE_CHARS.toLocaleString()} chars`);
830
- }
831
- }
832
- logger.info(`[FileDetector] ✅ Text: ${filename}`);
833
- }
834
- else if (result.type === "unknown") {
835
- if (result.content) {
836
- options.input.text += `\n\n## Attached File: "${filename}"\n${result.content}\n`;
837
- }
838
- logger.info(`[FileDetector] ⚠️ Unknown format (metadata extracted): ${filename}`);
839
- }
840
- }
841
- /**
842
- * Fold the `audioFiles` / `videoFiles` aliases into the unified `files` array.
843
- *
844
- * #284 gave audio and video their own input fields, but neither has a
845
- * dedicated processor — both are meant to travel through the same
846
- * auto-detecting `files` pipeline that already understands "audio"/"video"
847
- * FileDetector results (see `appendDetectedFileResult`). The fold used to live
848
- * inline in `buildMultimodalMessagesArray`, which meant any path that bypassed
849
- * that builder never performed it and dropped the files silently: the model
850
- * received the prompt alone and answered as though nothing were attached
851
- * (#1259). GoogleVertex's native SDK path and `buildMultimodalOptions`
852
- * (Bedrock) are both such paths, so the fold has to be callable from them.
853
- *
854
- * The aliases are cleared once merged, which makes the call idempotent: a
855
- * provider override and the shared builder can both call this on the same
856
- * options object without attaching every file twice.
857
- *
858
- * Mutates in place, matching `processUnifiedFilesArray` below — downstream
859
- * stages all read `options.input.files`.
860
- */
861
- export function mergeMediaFileAliases(input) {
862
- if (!input.audioFiles?.length && !input.videoFiles?.length) {
863
- return;
864
- }
865
- input.files = [
866
- ...(input.files ?? []),
867
- ...(input.audioFiles ?? []),
868
- ...(input.videoFiles ?? []),
869
- ];
870
- input.audioFiles = undefined;
871
- input.videoFiles = undefined;
872
- }
873
- /**
874
- * #478: `transcribeAudio` (CLI `--transcribe-audio`) is accepted by the options
875
- * surface but no video-audio transcription exists yet — VideoProcessor extracts
876
- * keyframes and embedded subtitle tracks only, and the transcription step is
877
- * still open as #433. Say so once per request rather than letting the caller
878
- * believe a transcript was produced and silently omitted.
879
- */
880
- function warnIfVideoTranscriptionRequested(videoOptions) {
881
- if (videoOptions?.transcribeAudio) {
882
- logger.warn("[NEUROLINK] Video audio transcription was requested but is not implemented yet " +
883
- "(tracked as #433). Keyframes and any embedded subtitle tracks are still extracted; " +
884
- "spoken audio will not be transcribed.");
885
- }
886
- }
887
- /**
888
- * Process the unified files array with auto-detection.
889
- * Handles lazy file registration, full processing, and preview injection.
890
- *
891
- * Exported so providers that bypass BaseProvider.generate() (e.g.
892
- * GoogleVertex's native @google/genai path) can still preprocess
893
- * `input.files` — without this, mimetype-hint and text-file inputs
894
- * would silently never reach the model on those paths.
895
- */
896
- /**
897
- * Record that one file entry has been folded into an input.
898
- *
899
- * Marked per entry as each completes, not per run: the loop throws on the
900
- * first file it cannot process (#273, fail loud), and the SDK's own retry path
901
- * re-invokes this function with the same input. Marking the whole run on entry
902
- * would make that retry a silent no-op — permanently skipping the failed file
903
- * and shipping a half-populated request with nothing surfaced. Marking the
904
- * whole run on exit would instead re-process the files that had already
905
- * succeeded, duplicating them. Per entry is the only version that is right in
906
- * both directions.
907
- */
908
- function markFileProcessed(input, entry) {
909
- const processed = PREPROCESSED_FILES.get(input) ?? new Set();
910
- processed.add(entry);
911
- PREPROCESSED_FILES.set(input, processed);
912
- }
913
- export async function processUnifiedFilesArray(options, maxSize, provider) {
914
- options.input ??= {};
915
- if (!options.input.files || options.input.files.length === 0) {
916
- return;
917
- }
918
- // Every result this function produces is *appended* — the summary onto
919
- // `text`, the bytes onto `nativeAudioFiles`/`images`/`pdfFiles` — and
920
- // `files` is only ever read, never consumed. Running it twice over the same
921
- // entry therefore doubles the injected text and attaches the same recording
922
- // twice, which a provider sees as two distinct files.
923
- //
924
- // That is reachable: providers whose native paths preprocess in both
925
- // `generate()` and `executeStream()` share one `options.input` reference
926
- // with `BaseProvider`'s real-stream → fake-stream fallback, so a retried
927
- // stream runs this a second time over the same object.
928
- //
929
- // Tracked per *entry* rather than per input, because a caller that appends a
930
- // file to an input it has already used must still get the new one processed
931
- // — treating the whole input as done would silently drop it. Entries are
932
- // compared by identity (or by value for a path string), which is what a
933
- // repeat of the same attachment actually looks like.
934
- const alreadyProcessed = PREPROCESSED_FILES.get(options.input) ?? new Set();
935
- const pending = options.input.files.filter((entry) => !alreadyProcessed.has(entry));
936
- if (pending.length === 0) {
937
- logger.debug("[NEUROLINK] Every attached file has already been processed for this input — skipping to avoid duplicate attachments");
938
- return;
939
- }
940
- const totalFiles = pending.length;
941
- const files = pending;
942
- warnIfVideoTranscriptionRequested(options.videoOptions);
943
- return withSpan({
944
- name: "neurolink.file.process_all",
945
- tracer: tracers.file,
946
- attributes: {
947
- [ATTR.FILE_TOTAL_COUNT]: totalFiles,
948
- [ATTR.NL_PROVIDER]: provider,
949
- },
950
- }, async (span) => {
951
- logger.info(`[NEUROLINK] Processing ${totalFiles} file(s) with auto-detection`);
952
- // `options.input` was guaranteed non-null by the `??= {}` guard at the
953
- // top of processUnifiedFilesArray; re-assert here so TypeScript is happy
954
- // inside this withSpan closure (it doesn't track mutations across closures).
955
- options.input ??= {};
956
- const inp2 = options.input;
957
- inp2.text = inp2.text || "";
958
- let includedCount = 0;
959
- const fileRegistry = options.fileRegistry;
960
- for (let fileIdx = 0; fileIdx < files.length; fileIdx++) {
961
- const file = files[fileIdx];
962
- const filename = extractFilename(file, fileIdx);
963
- try {
964
- // ─── Lazy file registration path ──────────────────────────────
965
- const fileSize = fileRegistry ? getFileSize(file) : 0;
966
- if (fileRegistry &&
967
- fileSize > SIZE_TIER_THRESHOLDS.TINY_MAX &&
968
- !isEagerMultimodalFile(file)) {
969
- const registered = await tryRegisterFileReference(file, fileSize, fileRegistry, fileIdx);
970
- if (registered) {
971
- logger.info(`[NEUROLINK] File lazily registered: ${filename} (${fileSize} bytes) — deferred processing`);
972
- includedCount++;
973
- markFileProcessed(inp2, file);
974
- continue;
975
- }
976
- }
977
- // ─── Full processing path (current behavior) ──────────────────
978
- const genericFileMaxSize = Math.max(maxSize, 100 * 1024 * 1024);
979
- const rawFileInput = isFileWithMetadata(file) ? file.buffer : file;
980
- // Forward the caller's mimetype hint (Slack/Curator-style
981
- // extension-less buffers) so the eager path classifies correctly
982
- // for tiny files — the lazy registry path has its own hint wiring.
983
- const fileMimetypeHint = isFileWithMetadata(file)
984
- ? file.mimetype
985
- : undefined;
986
- // The name has to travel the same way, and for the same reason: the
987
- // line above unwraps the object to its buffer, so by the time
988
- // detection resolves an extension there is no name left to read one
989
- // from. Without this a `.tar` supplied as bytes-plus-name is
990
- // unidentifiable — its "ustar" marker sits at byte 257, not at
991
- // offset 0 — and reports "Could not extract content" for an archive
992
- // that extracts perfectly when handed its filename.
993
- const fileFilenameHint = isFileWithMetadata(file)
994
- ? file.filename
995
- : undefined;
996
- const result = await FileDetector.detectAndProcess(rawFileInput, {
997
- maxSize: genericFileMaxSize,
998
- allowedTypes: [
999
- "csv",
1000
- "image",
1001
- "pdf",
1002
- "svg",
1003
- "video",
1004
- "audio",
1005
- "archive",
1006
- "xlsx",
1007
- "docx",
1008
- "pptx",
1009
- "text",
1010
- "unknown",
1011
- ],
1012
- csvOptions: options.csvOptions,
1013
- // #478: videos arrive through this unified `files` path, so this is
1014
- // where the CLI's frame/quality/format request has to be handed on.
1015
- videoOptions: options.videoOptions
1016
- ? {
1017
- frames: options.videoOptions.frames,
1018
- quality: options.videoOptions.quality,
1019
- format: options.videoOptions.format,
1020
- }
1021
- : undefined,
1022
- provider: provider,
1023
- mimetypeHint: fileMimetypeHint,
1024
- filenameHint: fileFilenameHint,
1025
- });
1026
- await appendDetectedFileResult(result, file, options);
1027
- includedCount++;
1028
- // Log what content type was added to the message
1029
- const contentType = result.type === "image" ? "image" : "text";
1030
- logger.info(`[NEUROLINK] File added to message: ${filename} as ${contentType} (type: ${result.type})`);
1031
- markFileProcessed(inp2, file);
1032
- }
1033
- catch (error) {
1034
- const errMsg = error instanceof Error ? error.message : String(error);
1035
- // #273: don't silently drop a failed file — log, then throw so the
1036
- // caller learns the file couldn't be processed (matches the explicit
1037
- // pdf/csv paths' fail-loud behavior).
1038
- logger.error(`[NEUROLINK] File processing failed: ${filename} — reason: ${errMsg}`);
1039
- throw ErrorFactory.fileProcessingFailed(filename, error instanceof Error ? error : new Error(errMsg));
1040
- }
1041
- }
1042
- span.setAttribute(ATTR.FILE_INCLUDED_COUNT, includedCount);
1043
- // After processing all files, inject previews for any lazily-registered files
1044
- if (fileRegistry && fileRegistry.size > 0) {
1045
- const previewText = await fileRegistry.generatePromptPreview();
1046
- if (previewText) {
1047
- inp2.text = (inp2.text || "") + previewText;
1048
- logger.info(`[FileDetector] Injected previews for ${fileRegistry.size} lazily-registered file(s)`);
1049
- }
1050
- const registeredFiles = fileRegistry.list();
1051
- for (const ref of registeredFiles) {
1052
- if (ref.extractedImages && ref.extractedImages.length > 0) {
1053
- inp2.images = [...(inp2.images || []), ...ref.extractedImages];
1054
- logger.info(`[FileDetector] Injected ${ref.extractedImages.length} extracted images from "${ref.filename}"`);
1055
- }
1056
- }
1057
- }
1058
- logger.info(`[NEUROLINK] File processing complete: ${includedCount}/${totalFiles} files included in message`);
1059
- // Augment options.systemPrompt with file-handling guidance so providers
1060
- // that bypass the message-builder's system message and read
1061
- // `options.systemPrompt` directly (e.g. GoogleVertex's native @google/genai
1062
- // path uses `config.systemInstruction = options.systemPrompt`) still see
1063
- // the "treat inlined CSV/PDF as the actual file" guidance. Without this,
1064
- // Vertex Gemini 2.5 reliably responds with "no files attached" even
1065
- // though the CSV content is fully embedded in the user prompt.
1066
- if (includedCount > 0) {
1067
- const filePromptAugmentation = `\n\nIMPORTANT FILE HANDLING INSTRUCTIONS:
1068
- - The full content of the user's local file(s) is INLINED in this message under "## CSV Data from ..." / "## PDF Data from ..." / "## File: ..." headings — it is the actual file the user is asking about.
1069
- - TREAT THE INLINED CONTENT AS IF IT WERE AN ATTACHMENT. Do NOT respond with "no files attached" or ask the user to re-upload — the data is already here.
1070
- - DO NOT use GitHub tools (get_file_contents, search_code, etc.) for local files - they only work for remote repository files.
1071
- - Analyze the inlined file content directly without attempting to fetch or read files using tools.`;
1072
- const existingSystem = (options.systemPrompt || "").trim();
1073
- options.systemPrompt = existingSystem
1074
- ? `${existingSystem}${filePromptAugmentation}`
1075
- : filePromptAugmentation.trim();
1076
- // Keep options.prompt in sync with the enriched input.text.
1077
- // neurolink.ts snapshots `prompt: options.input?.text` at baseOptions
1078
- // creation — BEFORE this function appends file content — and some
1079
- // native paths (executeNativeAnthropicGenerate historically) read
1080
- // `options.prompt` first. Leaving the stale snapshot in place means
1081
- // every appended file is silently dropped on those paths and the model
1082
- // answers "no file attached". Same dual-write processCSVFilesForNativeSDK
1083
- // already documents for exactly this trap.
1084
- const promptCarrier = options;
1085
- if (typeof promptCarrier.prompt === "string") {
1086
- promptCarrier.prompt = inp2.text;
1087
- }
1088
- }
1089
- });
1090
- }
1091
- /**
1092
- * Process explicit CSV files array and append to options.input.text.
1093
- */
1094
- async function processExplicitCsvFiles(options) {
1095
- options.input ??= {};
1096
- if (!options.input.csvFiles || options.input.csvFiles.length === 0) {
1097
- return;
1098
- }
1099
- logger.info(`[CSV] Processing ${options.input.csvFiles.length} explicit CSV file(s)`);
1100
- options.input.text = options.input.text || "";
1101
- for (let i = 0; i < options.input.csvFiles.length; i++) {
1102
- const csvFile = options.input.csvFiles[i];
1103
- try {
1104
- const result = await FileDetector.detectAndProcess(csvFile, {
1105
- allowedTypes: ["csv"],
1106
- csvOptions: options.csvOptions,
1107
- });
1108
- const filename = extractFilename(csvFile, i);
1109
- const filePath = typeof csvFile === "string" ? csvFile : filename;
1110
- let csvSection = `\n\n## CSV Data from "${filename}":\n`;
1111
- if (result.metadata) {
1112
- const metadataText = formatCSVMetadata(result.metadata);
1113
- if (metadataText) {
1114
- csvSection += metadataText + `\n\n`;
1115
- }
1116
- }
1117
- // Put the actual CSV content BEFORE the tool instructions —
1118
- // buildCSVToolInstructions references "the CSV data shown above"
1119
- // and the trailing position keeps that reference accurate.
1120
- csvSection += result.content;
1121
- csvSection += buildCSVToolInstructions(filePath);
1122
- options.input.text += csvSection;
1123
- logger.info(`[CSV] ✅ Processed: ${filename}`);
1124
- }
1125
- catch (error) {
1126
- const filename = extractFilename(csvFile, i);
1127
- const errMsg = error instanceof Error ? error.message : String(error);
1128
- // #273: fail loud instead of embedding the error into the prompt text
1129
- // (which the model would then "analyze"). Log, then throw.
1130
- logger.error(`[CSV] ❌ Failed to process ${filename}: ${errMsg}`);
1131
- throw ErrorFactory.csvProcessingFailed(filename, error instanceof Error ? error : new Error(errMsg));
1132
- }
1133
- }
1134
- }
1135
- /**
1136
- * Enforce post-processing budget on accumulated text content and log token usage.
1137
- */
1138
- function enforcePostProcessingBudget(options, provider, model) {
1139
- options.input ??= {};
1140
- if (!options.input.text) {
1141
- return;
1142
- }
1143
- const availableTokens = getAvailableInputTokens(provider, model);
1144
- const textTokenBudget = Math.floor(availableTokens * FILE_READ_BUDGET_PERCENT);
1145
- const actualTextTokens = estimateTokens(options.input.text, provider);
1146
- if (actualTextTokens > textTokenBudget && textTokenBudget > 0) {
1147
- const maxChars = textTokenBudget * 4;
1148
- if (options.input.text.length > maxChars) {
1149
- const headChars = Math.floor(maxChars * 0.75);
1150
- const tailChars = Math.floor(maxChars * 0.25);
1151
- const head = options.input.text.slice(0, headChars);
1152
- const tail = options.input.text.slice(-tailChars);
1153
- const truncatedTokens = actualTextTokens - textTokenBudget;
1154
- options.input.text =
1155
- head +
1156
- `\n\n[... ${truncatedTokens.toLocaleString()} tokens of file content truncated to fit context window ...]\n\n` +
1157
- tail;
1158
- logger.warn(`[FileDetector] Post-processing budget enforcement: truncated ~${truncatedTokens.toLocaleString()} tokens of file content to fit ${textTokenBudget.toLocaleString()} token budget`);
1159
- }
1160
- }
1161
- // Token usage breakdown logging
1162
- const textTokens = estimateTokens(options.input.text, provider);
1163
- const imageCount = (options.input.images?.length ?? 0) +
1164
- (options.input.content?.filter((c) => c.type === "image").length ?? 0);
1165
- const imageTokens = imageCount * 1500;
1166
- const totalContentTokens = textTokens + imageTokens;
1167
- const contextWindow = getAvailableInputTokens(provider, model);
1168
- logger.info(`[TokenUsage] Content breakdown: text=${textTokens.toLocaleString()} tokens, ` +
1169
- `images=${imageCount} (~${imageTokens.toLocaleString()} tokens), ` +
1170
- `total=${totalContentTokens.toLocaleString()} tokens, ` +
1171
- `budget=${contextWindow.toLocaleString()} tokens, ` +
1172
- `utilization=${contextWindow > 0 ? ((totalContentTokens / contextWindow) * 100).toFixed(1) : "N/A"}%`);
1173
- }
1174
- /**
1175
- * #309: enforce the provider's page/size ceilings across ALL PDFs in a request,
1176
- * not just per-file. N files each just under the single-file limit can still
1177
- * blow past it in aggregate (e.g. three 40-page PDFs → 120 pages for a
1178
- * 100-page API).
1179
- *
1180
- * Shared by both PDF submission surfaces: `input.pdfFiles` (via
1181
- * `processExplicitPdfFiles`) and `input.content` with `type: "pdf"` (via
1182
- * `convertContentToProviderFormat`). The latter previously built its own
1183
- * `pdfFiles` array and reached the provider without ever calling this guard,
1184
- * so the limit was bypassable by moving the same payload to `input.content`.
1185
- */
1186
- /**
1187
- * Basename that strips BOTH separators regardless of host platform.
1188
- *
1189
- * `path.basename` only understands the host's separator, so on a POSIX server
1190
- * a Windows-style filename (`C:\Users\alice\q3-merger.pdf`) comes back
1191
- * completely unchanged — defeating the point of trimming it before it reaches
1192
- * a log line, since caller-controlled paths can carry usernames and internal
1193
- * directory structure.
1194
- */
1195
- function safeBasename(filename) {
1196
- const lastSeparator = Math.max(filename.lastIndexOf("/"), filename.lastIndexOf("\\"));
1197
- const trimmed = lastSeparator === -1 ? filename : filename.slice(lastSeparator + 1);
1198
- return trimmed || "<unnamed file>";
1199
- }
1200
- async function enforceAggregatePdfLimits(pdfFiles, provider, { trustSuppliedPageCounts }) {
1201
- const aggregateConfig = PDFProcessor.getProviderConfig(provider);
1202
- // Only an empty set is exempt. A single PDF must still be checked: on the
1203
- // `input.content` path nothing else validates it (that path never goes
1204
- // through FileDetector.detectAndProcess / PDFProcessor.process), so bailing
1205
- // at length <= 1 let one 200-page document through untouched.
1206
- if (!aggregateConfig || pdfFiles.length === 0) {
1207
- return;
1208
- }
1209
- // Byte total is free to compute — enforce it BEFORE parsing anything, so an
1210
- // oversized request is rejected without first spending parser CPU/memory on
1211
- // every document in it.
1212
- const totalMB = pdfFiles.reduce((sum, f) => sum + f.buffer.length, 0) / (1024 * 1024);
1213
- if (totalMB > aggregateConfig.maxSizeMB) {
1214
- throw ErrorFactory.pdfAggregateSizeLimitExceeded(pdfFiles.length, totalMB, aggregateConfig.maxSizeMB, provider);
1215
- }
1216
- // `trustSuppliedPageCounts` is the difference between the two surfaces.
1217
- // On `input.pdfFiles` the count comes from FileDetector's own detection, so
1218
- // it is authoritative. On `input.content` it is `metadata.pages` — plain
1219
- // caller input — and trusting it lets a request declare `pages: 1` for each
1220
- // of three 40-page PDFs and sail past the ceiling. There, the count is
1221
- // always re-derived from the bytes and the supplied value is ignored.
1222
- const pageCounts = await Promise.all(pdfFiles.map(async (f) => trustSuppliedPageCounts && typeof f.pageCount === "number"
1223
- ? f.pageCount
1224
- : await PDFProcessor.resolvePageCount(f.buffer)));
1225
- // Filenames are caller-controlled and may be full paths carrying
1226
- // PII/internal directory segments — surface only the basename, stripping
1227
- // both separators so a Windows path is trimmed on a POSIX host too.
1228
- const unknownFileNames = pdfFiles
1229
- .filter((_, i) => typeof pageCounts[i] !== "number")
1230
- .map((f) => (f.filename ? safeBasename(f.filename) : "<unnamed file>"));
1231
- const totalPages = pageCounts.reduce((sum, p) => sum + (typeof p === "number" ? p : 0), 0);
1232
- if (unknownFileNames.length > 0) {
1233
- if (!trustSuppliedPageCounts) {
1234
- // Untrusted surface: an unreadable count is indistinguishable from an
1235
- // evasion attempt, and counting it as zero is precisely the hole. Fail
1236
- // closed rather than admit an unverifiable document.
1237
- throw ErrorFactory.pdfPageCountUnverifiable(unknownFileNames, provider);
1238
- }
1239
- // Trusted surface: detection already vetted these, so one unreadable
1240
- // count must not fail an otherwise valid request — but it must not be
1241
- // silent either, since the known sum may undercount the true total.
1242
- logger.warn(`[PDF] Aggregate page-limit check across ${pdfFiles.length} PDFs could only be ` +
1243
- `partially verified: ${unknownFileNames.length} file(s) have an unknown ` +
1244
- `page count (${unknownFileNames.join(", ")}), so the known total (${totalPages}) may ` +
1245
- `undercount the true combined page count.`);
1246
- }
1247
- if (totalPages > aggregateConfig.maxPages) {
1248
- throw ErrorFactory.pdfAggregatePageLimitExceeded(pdfFiles.length, totalPages, aggregateConfig.maxPages, provider);
1249
- }
1250
- }
1251
- /**
1252
- * Process explicit PDF files and return structured PDF entries for multimodal processing.
1253
- */
1254
- async function processExplicitPdfFiles(options, maxSize, provider) {
1255
- options.input ??= {};
1256
- const pdfFiles = [];
1257
- if (!options.input.pdfFiles || options.input.pdfFiles.length === 0) {
1258
- return pdfFiles;
1259
- }
1260
- logger.info(`[PDF] Processing ${options.input.pdfFiles.length} explicit PDF file(s) for ${provider}`);
1261
- for (let i = 0; i < options.input.pdfFiles.length; i++) {
1262
- const pdfFile = options.input.pdfFiles[i];
1263
- const filename = extractFilename(pdfFile, i);
1264
- try {
1265
- const result = await FileDetector.detectAndProcess(pdfFile, {
1266
- maxSize,
1267
- allowedTypes: ["pdf"],
1268
- provider: provider,
1269
- });
1270
- if (Buffer.isBuffer(result.content)) {
1271
- pdfFiles.push({
1272
- buffer: result.content,
1273
- filename,
1274
- pageCount: result.metadata?.estimatedPages ?? null,
1275
- // #258: carry the password so the image-fallback conversion can
1276
- // decrypt an encrypted PDF for providers without native PDF support.
1277
- password: options.pdfOptions?.password,
1278
- // #260: carry the per-page canvas-pixel ceiling so the caller can
1279
- // raise (or lower) the memory guard for the image-fallback render.
1280
- maxCanvasPixels: options.pdfOptions?.maxCanvasPixels,
1281
- // #297: render scale / page ceiling, so the lowered default is
1282
- // actually reachable and callers can trade sharpness for memory.
1283
- scale: options.pdfOptions?.scale,
1284
- maxPages: options.pdfOptions?.maxPages,
1285
- });
1286
- logger.info(`[PDF] ✅ Queued for multimodal: ${filename} (${result.metadata?.estimatedPages ?? "unknown"} pages)`);
1287
- }
1288
- }
1289
- catch (error) {
1290
- logger.error(`[PDF] ❌ Failed to process ${filename}:`, error);
1291
- throw error;
1292
- }
1293
- }
1294
- // Counts here come from FileDetector's detection, so they are authoritative.
1295
- await enforceAggregatePdfLimits(pdfFiles, provider, {
1296
- trustSuppliedPageCounts: true,
1297
- });
1298
- return pdfFiles;
1299
- }
1300
- /**
1301
- * Build the enhanced system prompt for multimodal messages, including
1302
- * conversation instructions, structured output instructions, and file handling guidance.
1303
- */
1304
- function buildMultimodalSystemPrompt(options, hasPDFFiles) {
1305
- options.input ??= {};
1306
- let systemPrompt = options.systemPrompt?.trim() || "";
1307
- const hasConversationHistory = options.conversationHistory && options.conversationHistory.length > 0;
1308
- if (hasConversationHistory) {
1309
- systemPrompt = `${systemPrompt.trim()}${CONVERSATION_INSTRUCTIONS}`;
1310
- }
1311
- if (shouldUseStructuredOutput(options)) {
1312
- systemPrompt = `${systemPrompt.trim()}${STRUCTURED_OUTPUT_INSTRUCTIONS}`;
1313
- }
1314
- const inp = options.input;
1315
- const hasCSVFiles = (inp.csvFiles && inp.csvFiles.length > 0) ||
1316
- (inp.files &&
1317
- inp.files.some((f) => typeof f === "string" ? f.toLowerCase().endsWith(".csv") : false));
1318
- if (hasCSVFiles || hasPDFFiles) {
1319
- const fileTypes = [];
1320
- if (hasPDFFiles) {
1321
- fileTypes.push("PDFs");
1322
- }
1323
- if (hasCSVFiles) {
1324
- fileTypes.push("CSVs");
1325
- }
1326
- systemPrompt += `\n\nIMPORTANT FILE HANDLING INSTRUCTIONS:
1327
- - The full content of the user's local ${fileTypes.join(", ")} (and any images) is INLINED in this message under the "## CSV Data from ..." / "## PDF Data from ..." headings — it is the actual file the user is asking about.
1328
- - TREAT THE INLINED CONTENT AS IF IT WERE AN ATTACHMENT. Do NOT respond with "no files attached" or ask the user to re-upload — the data is already here.
1329
- - DO NOT use GitHub tools (get_file_contents, search_code, etc.) for local files - they only work for remote repository files
1330
- - Analyze the provided file content directly without attempting to fetch or read files using tools
1331
- - GitHub MCP tools are ONLY for remote repository operations, not local filesystem access
1332
- - Use the file content shown in this message for your analysis`;
1333
- }
1334
- return systemPrompt;
1335
- }
1336
- /**
1337
- * Build multimodal message array with image support
1338
- * Detects when images are present and routes through provider adapter
1339
- */
1340
- export async function buildMultimodalMessagesArray(options, provider, model) {
1341
- // Media-only callers (avatar / music / video) may omit `input` entirely.
1342
- // Normalise to an empty object so all sub-functions can access input.*
1343
- // without defensive null checks on every field access.
1344
- if (!options.input) {
1345
- options.input = {};
1346
- }
1347
- // After normalisation `input` is guaranteed non-undefined. Capture it in a
1348
- // local const so TypeScript sees the definite (non-optional) type in the
1349
- // rest of this function, avoiding 60+ "possibly undefined" errors.
1350
- const inp = options.input;
1351
- mergeMediaFileAliases(inp);
1352
- // Compute provider-specific max PDF size once for consistent validation
1353
- const pdfConfig = PDFProcessor.getProviderConfig(provider);
1354
- const maxSize = pdfConfig
1355
- ? pdfConfig.maxSizeMB * 1024 * 1024
1356
- : 10 * 1024 * 1024;
1357
- // Aggregate file budget enforcement
1358
- enforceFileBudget(options, provider, model);
1359
- // Process unified files array (auto-detect)
1360
- await processUnifiedFilesArray(options, maxSize, provider);
1361
- // Detection can append images (PDF page renders, video keyframes, a HEIC
1362
- // photo), so compatibility conversion has to run after it, not before.
1363
- await normalizeVisionImageFormats(inp);
1364
- // Process explicit CSV files array
1365
- await processExplicitCsvFiles(options);
1366
- // Post-processing budget enforcement and token usage logging
1367
- enforcePostProcessingBudget(options, provider, model);
1368
- // Process explicit PDF files
1369
- const pdfFiles = await processExplicitPdfFiles(options, maxSize, provider);
1370
- // Check if this is a multimodal request
1371
- const hasImages = (inp.images && inp.images.length > 0) ||
1372
- (inp.content && inp.content.some((c) => c.type === "image"));
1373
- // A PDF supplied only via input.content (type: "pdf", no explicit
1374
- // input.pdfFiles and no image alongside it) must still route through the
1375
- // multimodal path below — otherwise it silently falls through to the
1376
- // text-only branch and the PDF (and any pdfOptions) never reaches
1377
- // convertContentToProviderFormat at all.
1378
- const hasPDFs = pdfFiles.length > 0 ||
1379
- !!(inp.content && inp.content.some((c) => c.type === "pdf"));
1380
- // Audio that is to be delivered natively is multimodal for the same reason a
1381
- // PDF is: it becomes a non-text part. Without this an audio-only turn — the
1382
- // ordinary "transcribe this recording" request — took the text-only branch
1383
- // below, where the collected bytes have nowhere to go and only the metadata
1384
- // summary survives.
1385
- const hasNativeAudio = (inp.nativeAudioFiles?.length ?? 0) > 0 && supportsNativeAudio(provider);
1386
- // If no images, PDFs or audio, use standard message building and convert to MultimodalChatMessage[]
1387
- if (!hasImages && !hasPDFs && !hasNativeAudio) {
1388
- // #289: CSV content[] items don't need vision, so they never reach the
1389
- // multimodal converter below — process them into the prompt text here
1390
- // (otherwise a `content: [{type:"csv"}]`-only request silently drops it).
1391
- const csvContentItems = inp.content?.filter(isCSVContent) ?? [];
1392
- if (csvContentItems.length > 0) {
1393
- inp.text = await appendCsvContentToText(csvContentItems, inp.text ?? "");
1394
- }
1395
- if (inp.csvFiles) {
1396
- inp.csvFiles = [];
1397
- }
1398
- if (inp.pdfFiles) {
1399
- inp.pdfFiles = [];
1400
- }
1401
- if (inp.files) {
1402
- inp.files = [];
1403
- }
1404
- const standardMessages = await buildMessagesArray(options);
1405
- return standardMessages.map((msg) => {
1406
- const msgProviderOptions = msg
1407
- .providerOptions;
1408
- return {
1409
- role: msg.role,
1410
- content: msg.content,
1411
- ...(msgProviderOptions && { providerOptions: msgProviderOptions }),
1412
- };
1413
- });
1414
- }
1415
- // Validate provider supports vision
1416
- if (!ProviderImageAdapter.supportsVision(provider, model)) {
1417
- throw new Error(`Provider ${provider} with model ${model} does not support vision processing. ` +
1418
- `Supported providers: ${ProviderImageAdapter.getVisionProviders().join(", ")}`);
1419
- }
1420
- const messages = [];
1421
- // Build enhanced system prompt. Gate on the same `hasPDFs` predicate used
1422
- // for routing above — a PDF supplied only via input.content (no explicit
1423
- // input.pdfFiles) must still get the "treat inlined content as an
1424
- // attachment" instruction, or the model can claim no files were attached.
1425
- const systemPrompt = buildMultimodalSystemPrompt(options, hasPDFs);
1426
- if (systemPrompt.trim()) {
1427
- messages.push({
1428
- role: "system",
1429
- content: systemPrompt.trim(),
1430
- providerOptions: {
1431
- anthropic: { cacheControl: { type: "ephemeral" } },
1432
- },
1433
- });
1434
- }
1435
- // Add conversation history if available
1436
- const hasConversationHistory = options.conversationHistory && options.conversationHistory.length > 0;
1437
- if (hasConversationHistory && options.conversationHistory) {
1438
- for (const msg of options.conversationHistory) {
1439
- // Filter out tool_call and tool_result roles — only user/assistant/system are valid for AI providers
1440
- if (msg.role === "user" ||
1441
- msg.role === "assistant" ||
1442
- msg.role === "system") {
1443
- const providerOptions = msg.providerOptions;
1444
- // Sanitize assistant array content: strip tool_use/tool_result blocks
1445
- // that providers cannot handle. If an assistant message ends up empty
1446
- // after stripping, skip it to avoid sending content: "" to Claude.
1447
- // Only assistant messages need this — user messages may contain valid
1448
- // image/file blocks that must pass through unchanged.
1449
- let sanitizedContent = msg.content;
1450
- if (msg.role === "assistant" && Array.isArray(msg.content)) {
1451
- const textParts = msg.content.filter((item) => !!item &&
1452
- typeof item === "object" &&
1453
- item.type === "text" &&
1454
- typeof item.text === "string");
1455
- if (textParts.length === 0) {
1456
- // All content was tool_use/tool_result/non-text — skip message
1457
- continue;
1458
- }
1459
- // Check if any retained text part carries providerOptions
1460
- // (e.g. Anthropic cache_control). If so, preserve them as
1461
- // array content to avoid losing per-block metadata.
1462
- const hasItemProviderOptions = textParts.some((item) => !!item.providerOptions);
1463
- if (hasItemProviderOptions) {
1464
- sanitizedContent = textParts;
1465
- }
1466
- else {
1467
- sanitizedContent =
1468
- textParts.length === 1
1469
- ? textParts[0].text
1470
- : textParts
1471
- .map((p) => p.text)
1472
- .join(" ");
1473
- }
1474
- }
1475
- // Skip empty string content to avoid Claude API rejection
1476
- if (sanitizedContent === "") {
1477
- continue;
1478
- }
1479
- messages.push({
1480
- role: msg.role,
1481
- content: sanitizedContent,
1482
- ...(providerOptions && { providerOptions }),
1483
- });
1484
- }
1485
- }
1486
- }
1487
- // Handle multimodal content
1488
- try {
1489
- let userContent;
1490
- if (inp.content && inp.content.length > 0) {
1491
- // Audio detected from `input.files` has to reach this branch too. A
1492
- // caller that supplies structured `content` AND attaches an audio file
1493
- // is not asking for the audio to be discarded — but this branch bypasses
1494
- // the multimodal converter below, so the bytes were dropped and only the
1495
- // metadata summary folded into `text` survived. Exactly the failure this
1496
- // change exists to remove, reintroduced through the other door.
1497
- userContent = await convertContentToProviderFormat(inp.content, provider, model, options.pdfOptions, inp.nativeAudioFiles ?? []);
1498
- }
1499
- else if ((inp.images && inp.images.length > 0) ||
1500
- pdfFiles.length > 0 ||
1501
- // Audio alone must still take the multimodal path. Without this clause an
1502
- // audio-only turn fell through to the plain-text branch below, so the
1503
- // recording was dropped and only its metadata summary — already folded
1504
- // into `text` — ever reached the model.
1505
- (inp.nativeAudioFiles?.length ?? 0) > 0) {
1506
- userContent = await convertMultimodalToProviderFormat(inp.text ?? "", inp.images || [], pdfFiles, provider, model, inp.nativeAudioFiles ?? []);
1507
- }
1508
- else {
1509
- userContent = inp.text;
1510
- }
1511
- if (typeof userContent === "string") {
1512
- messages.push({
1513
- role: "user",
1514
- content: userContent,
1515
- });
1516
- }
1517
- else {
1518
- messages.push({
1519
- role: "user",
1520
- content: userContent,
1521
- });
1522
- }
1523
- const reqId = options.context
1524
- ?.requestId;
1525
- logMessageComposition(messages, reqId);
1526
- return messages;
1527
- }
1528
- catch (error) {
1529
- MultimodalLogger.logError("MULTIMODAL_BUILD", error, {
1530
- provider,
1531
- model,
1532
- hasImages,
1533
- imageCount: inp.images?.length || 0,
1534
- });
1535
- throw error;
1536
- }
1537
- }
1538
- /**
1539
- * Timeout for detecting/parsing an in-memory CSV `content[]` buffer (#325
1540
- * review, round 2). Bounds a stalled detector rather than blocking the
1541
- * request indefinitely.
1542
- */
1543
- const CSV_CONTENT_DETECTION_TIMEOUT_MS = 30_000;
1544
- /**
1545
- * #289: process CSV `content[]` items into appended prompt text. CSV is
1546
- * delivered to the model as text (like the explicit `csvFiles` path), so this
1547
- * is shared by both the no-vision gate and the multimodal converter.
1548
- */
1549
- async function appendCsvContentToText(csvItems, baseText) {
1550
- let text = baseText;
1551
- for (const csv of csvItems) {
1552
- const raw = csv.data;
1553
- if (raw === undefined) {
1554
- continue;
1555
- }
1556
- // #325: raw CSV text (e.g. "a,b\n1,2") is not base64 — decoding it as
1557
- // base64 silently corrupts the content. Only treat the string as base64
1558
- // when it actually validates as such; otherwise treat it as literal
1559
- // UTF-8 CSV text, matching how Buffer inputs are already handled as-is.
1560
- const buffer = typeof raw === "string"
1561
- ? imageUtils.isValidBase64(raw)
1562
- ? Buffer.from(raw, "base64")
1563
- : Buffer.from(raw, "utf-8")
1564
- : raw;
1565
- const name = csv.metadata?.filename || "data.csv";
1566
- // #325 review (round 2): a stalled/hung detector must not block the
1567
- // request indefinitely — wrap with the project's standard withTimeout.
1568
- const result = await withTimeout(FileDetector.detectAndProcess(buffer, {
1569
- allowedTypes: ["csv"],
1570
- csvOptions: {
1571
- maxRows: csv.metadata?.maxRows,
1572
- formatStyle: csv.metadata?.formatStyle,
1573
- },
1574
- }), CSV_CONTENT_DETECTION_TIMEOUT_MS, new Error(`Timed out processing CSV content "${name}" after ${CSV_CONTENT_DETECTION_TIMEOUT_MS}ms`));
1575
- text += `${text ? "\n\n" : ""}## CSV Data from ${name}\n${result.content}`;
1576
- }
1577
- return text;
1578
- }
1579
- /**
1580
- * Convert advanced content format to provider-specific format
1581
- */
1582
- async function convertContentToProviderFormat(content, provider, _model, pdfOptions, audioFiles = []) {
1583
- const textContent = content.find((c) => c.type === "text");
1584
- const imageContent = content.filter((c) => c.type === "image");
1585
- const pdfContent = content.filter((c) => c.type === "pdf");
1586
- const csvContent = content.filter(isCSVContent);
1587
- // Allow empty text when multimodal content is present (enables image-only or PDF-only queries)
1588
- let text = textContent?.text || "";
1589
- // #289: CSV content[] items were silently dropped — fold each into the text.
1590
- if (csvContent.length > 0) {
1591
- text = await appendCsvContentToText(csvContent, text);
1592
- }
1593
- // Audio the provider can actually read counts as multimodal content, on both
1594
- // of the checks below. Computed before the validation rather than after it:
1595
- // a request whose structured `content` carries no text but does carry an
1596
- // attached recording is a complete request, and leaving audio out of
1597
- // `hasMultimodal` rejected it as empty before delivery could be considered.
1598
- //
1599
- // The same flag then keeps it off the text-only early return, which would
1600
- // otherwise hand back a plain string and lose the bytes — the exact drop this
1601
- // change exists to stop, reached through a different branch. Gated on the
1602
- // provider accepting audio so one that cannot keeps the cheaper plain-text
1603
- // shape rather than an array carrying a part it will ignore.
1604
- const deliversAudio = audioFiles.length > 0 && supportsNativeAudio(provider);
1605
- const hasMultimodal = imageContent.length > 0 || pdfContent.length > 0 || deliversAudio;
1606
- // Validate that we have at least some content
1607
- if (!hasMultimodal && !text) {
1608
- throw new Error("Content must include either text or multimodal content");
1609
- }
1610
- // Text-only case (CSV has already been folded into `text`).
1611
- if (!hasMultimodal) {
1612
- return text;
1613
- }
1614
- // Extract images as Buffer | string array
1615
- const images = imageContent.map((img) => img.data);
1616
- // Extract PDFs in the expected format
1617
- const pdfFiles = pdfContent.map((pdf) => ({
1618
- buffer: typeof pdf.data === "string" ? Buffer.from(pdf.data, "base64") : pdf.data,
1619
- filename: pdf.metadata?.filename || "document.pdf",
1620
- pageCount: pdf.metadata?.pages ?? null,
1621
- // #258/#260: carry password + canvas-pixel ceiling so a PDF supplied via
1622
- // the advanced `input.content` array gets the same decryption/memory
1623
- // guard as the `input.pdfFiles` path (see `processExplicitPdfFiles`).
1624
- password: pdfOptions?.password,
1625
- maxCanvasPixels: pdfOptions?.maxCanvasPixels,
1626
- scale: pdfOptions?.scale,
1627
- maxPages: pdfOptions?.maxPages,
1628
- }));
1629
- // #309: same aggregate ceiling as `input.pdfFiles`. Without this, moving an
1630
- // over-limit payload from `input.pdfFiles` to `input.content` skipped the
1631
- // check entirely and the request went straight to the provider.
1632
- await enforceAggregatePdfLimits(pdfFiles, provider, {
1633
- trustSuppliedPageCounts: false,
1634
- });
1635
- return await convertMultimodalToProviderFormat(text, images, pdfFiles, provider, _model, audioFiles);
1636
- }
1637
- /**
1638
- * Check if a string is an internet URL
1639
- */
1640
- function isInternetUrl(input) {
1641
- // Scheme is case-insensitive (RFC 3986) — "HTTPS://..." must still be a URL,
1642
- // not fall through to the file-path branch and produce a confusing error.
1643
- const lower = input.toLowerCase();
1644
- return lower.startsWith("http://") || lower.startsWith("https://");
1645
- }
1646
- /**
1647
- * Download image from URL and convert to base64 data URI
1648
- * Rate-limited to 10 downloads per second to prevent DoS
1649
- * Uses LRU cache to avoid redundant downloads of the same URL
1650
- */
1651
- async function downloadImageFromUrl(url) {
1652
- // Check cache first (before rate limiting)
1653
- const cache = getImageCache();
1654
- const cached = cache.get(url);
1655
- if (cached) {
1656
- logger.debug("Using cached image for URL", { url: url.substring(0, 50) });
1657
- return cached.dataUri;
1658
- }
1659
- // Apply rate limiting only if cache missed
1660
- await urlDownloadRateLimiter.acquire();
1661
- try {
1662
- const response = await request(url, {
1663
- dispatcher: getGlobalDispatcher().compose(interceptors.redirect({ maxRedirections: 5 })),
1664
- method: "GET",
1665
- headersTimeout: 10000, // 10 second timeout for headers
1666
- bodyTimeout: 30000, // 30 second timeout for body,
1667
- });
1668
- if (response.statusCode !== 200) {
1669
- throw new Error(`HTTP ${response.statusCode}: Failed to download image from ${url}`);
1670
- }
1671
- // Get content type from headers
1672
- const contentType = response.headers["content-type"] || "image/jpeg";
1673
- // Validate it's an image
1674
- if (!contentType.startsWith("image/")) {
1675
- throw new Error(`URL does not point to an image. Content-Type: ${contentType}`);
1676
- }
1677
- // Read the response body, enforcing the size cap INCREMENTALLY: a
1678
- // misbehaving/malicious server on a user-supplied URL must not be able to
1679
- // force unbounded memory growth by streaming gigabytes before we ever
1680
- // check the total (the previous code concat'd everything first).
1681
- const maxSize = 10 * 1024 * 1024; // 10MB
1682
- const chunks = [];
1683
- let totalSize = 0;
1684
- for await (const chunk of response.body) {
1685
- totalSize += chunk.length;
1686
- if (totalSize > maxSize) {
1687
- throw new Error(`Image too large: exceeds ${maxSize} bytes while downloading from ${url}`);
1688
- }
1689
- chunks.push(chunk);
1690
- }
1691
- const buffer = Buffer.concat(chunks);
1692
- // Convert to base64 data URI
1693
- const base64 = buffer.toString("base64");
1694
- const dataUri = `data:${contentType};base64,${base64}`;
1695
- // Store in cache for future use
1696
- cache.set(url, dataUri, contentType, buffer);
1697
- return dataUri;
1698
- }
1699
- catch (error) {
1700
- MultimodalLogger.logError("URL_DOWNLOAD_FAILED", error, { url });
1701
- throw new Error(`Failed to download image from ${url}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
1702
- }
1703
- }
1704
- /**
1705
- * Get MIME type from an image file extension.
1706
- *
1707
- * Delegates to the canonical registry instead of the six-case switch this used
1708
- * to be. That switch covered png/gif/webp/bmp/tiff and defaulted *everything
1709
- * else* to image/jpeg, so a .heic, .avif, .ico or .jp2 path was labelled JPEG
1710
- * — which meant `needsVisionTranscode()` never fired for it and the raw bytes
1711
- * went to the provider under a MIME type that was simply untrue. Exactly the
1712
- * kind of hand-maintained table this registry exists to delete.
1713
- *
1714
- * The image/jpeg fallback is kept only for genuinely unknown extensions, since
1715
- * callers here have already established they are handling an image.
1716
- */
1717
- function getMimeTypeFromExtension(filePath) {
1718
- const entry = lookupByExtension(filePath);
1719
- if (entry?.modality === "image") {
1720
- return entry.mimeTypes[0];
1721
- }
1722
- return "image/jpeg";
1723
- }
1724
- /**
1725
- * Detect MIME type from buffer magic bytes
1726
- * Returns undefined if format cannot be detected
1727
- */
1728
- function detectMimeTypeFromBuffer(buffer) {
1729
- // JPEG: FF D8 FF
1730
- if (buffer.length >= 3 &&
1731
- buffer[0] === 0xff &&
1732
- buffer[1] === 0xd8 &&
1733
- buffer[2] === 0xff) {
1734
- return "image/jpeg";
1735
- }
1736
- // PNG: 89 50 4E 47 0D 0A 1A 0A
1737
- if (buffer.length >= 8 &&
1738
- buffer[0] === 0x89 &&
1739
- buffer[1] === 0x50 &&
1740
- buffer[2] === 0x4e &&
1741
- buffer[3] === 0x47 &&
1742
- buffer[4] === 0x0d &&
1743
- buffer[5] === 0x0a &&
1744
- buffer[6] === 0x1a &&
1745
- buffer[7] === 0x0a) {
1746
- return "image/png";
1747
- }
1748
- // GIF: 47 49 46 38 (37|39) 61
1749
- if (buffer.length >= 6 &&
1750
- buffer[0] === 0x47 &&
1751
- buffer[1] === 0x49 &&
1752
- buffer[2] === 0x46 &&
1753
- buffer[3] === 0x38 &&
1754
- (buffer[4] === 0x37 || buffer[4] === 0x39) &&
1755
- buffer[5] === 0x61) {
1756
- return "image/gif";
1757
- }
1758
- // WebP: 52 49 46 46 ?? ?? ?? ?? 57 45 42 50
1759
- if (buffer.length >= 12 &&
1760
- buffer[0] === 0x52 &&
1761
- buffer[1] === 0x49 &&
1762
- buffer[2] === 0x46 &&
1763
- buffer[3] === 0x46 &&
1764
- buffer[8] === 0x57 &&
1765
- buffer[9] === 0x45 &&
1766
- buffer[10] === 0x42 &&
1767
- buffer[11] === 0x50) {
1768
- return "image/webp";
1769
- }
1770
- // BMP: 42 4D
1771
- if (buffer.length >= 2 && buffer[0] === 0x42 && buffer[1] === 0x4d) {
1772
- return "image/bmp";
1773
- }
1774
- // TIFF: (49 49 2A 00) or (4D 4D 00 2A)
1775
- if (buffer.length >= 4 &&
1776
- ((buffer[0] === 0x49 &&
1777
- buffer[1] === 0x49 &&
1778
- buffer[2] === 0x2a &&
1779
- buffer[3] === 0x00) ||
1780
- (buffer[0] === 0x4d &&
1781
- buffer[1] === 0x4d &&
1782
- buffer[2] === 0x00 &&
1783
- buffer[3] === 0x2a))) {
1784
- return "image/tiff";
1785
- }
1786
- // The formats above are the ones a provider accepts (or that sharp handles
1787
- // trivially). Everything below is a format NO vision provider accepts, and
1788
- // recognising it here is what lets `needsVisionTranscode()` fire — a Buffer
1789
- // whose format was unrecognised fell through to the image/jpeg default and
1790
- // was shipped to the provider unconverted under a MIME type that was false.
1791
- // Raw Buffers are the most direct way a backend attaches an image, so this
1792
- // was the single biggest hole in the vision-compatibility path.
1793
- // HEIC / HEIF / AVIF: ISO-BMFF `ftyp` box, distinguished by major brand.
1794
- // Shared with the FileDetector so the two cannot drift on brand tables.
1795
- const isoBmffImage = detectIsoBmffImageMimeType(buffer);
1796
- if (isoBmffImage) {
1797
- return isoBmffImage;
1798
- }
1799
- // ICO: 00 00 01 00. Checked after the ftyp probe because an ISO-BMFF file
1800
- // also starts with a zero byte.
1801
- if (buffer.length >= 4 &&
1802
- buffer[0] === 0x00 &&
1803
- buffer[1] === 0x00 &&
1804
- buffer[2] === 0x01 &&
1805
- buffer[3] === 0x00) {
1806
- return "image/x-icon";
1807
- }
1808
- // SVG is markup, so it has no byte signature — and without this probe a raw
1809
- // SVG buffer matched nothing, kept processImageToBase64's "image/jpeg"
1810
- // default, and was shipped to the provider as XML labelled as a JPEG.
1811
- // Shared forward scan rather than a local regex: the regex form of this
1812
- // check is a CodeQL js/redos finding (see markupSniff).
1813
- if (looksLikeSvgMarkup(buffer)) {
1814
- return "image/svg+xml";
1815
- }
1816
- // JPEG 2000: the full 12-byte signature box, trailing 0D 0A 87 0A included.
1817
- // Those four bytes are a line-ending probe that a transfer mangling newlines
1818
- // or stripping the eighth bit corrupts, so checking only length and brand
1819
- // accepts exactly the damaged files the signature exists to reject.
1820
- if (buffer.length >= 12 &&
1821
- buffer[0] === 0x00 &&
1822
- buffer[1] === 0x00 &&
1823
- buffer[2] === 0x00 &&
1824
- buffer[3] === 0x0c &&
1825
- buffer.toString("latin1", 4, 8) === "jP " &&
1826
- buffer[8] === 0x0d &&
1827
- buffer[9] === 0x0a &&
1828
- buffer[10] === 0x87 &&
1829
- buffer[11] === 0x0a) {
1830
- return "image/jp2";
1831
- }
1832
- return undefined;
1833
- }
1834
- /**
1835
- * Convert file path to raw base64 string.
1836
- * Returns raw base64 (not a data: URI) to avoid SSRF validation in AI SDK v6.
1837
- * Uses async fs so a large/slow-filesystem image never blocks the event loop
1838
- * while the size guard (below) or the read itself is in flight.
1839
- */
1840
- async function convertFilePathToBase64(filePath) {
1841
- let stats;
1842
- try {
1843
- stats = await statAsync(filePath);
1844
- }
1845
- catch (error) {
1846
- // Only ENOENT means "not found" — EACCES/ELOOP/etc. are real access or
1847
- // filesystem problems that must not be misreported as a missing file.
1848
- const code = error instanceof Error
1849
- ? error.code
1850
- : undefined;
1851
- if (code === "ENOENT") {
1852
- throw new Error(`Image file not found: ${filePath}`, { cause: error });
1853
- }
1854
- throw new Error(`Cannot access image file ${filePath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
1855
- }
1856
- if (!stats.isFile()) {
1857
- throw new Error(`Image path is not a file: ${filePath}`);
1858
- }
1859
- // #257: check the file size via stat BEFORE reading it into memory, so a
1860
- // huge image path never triggers an unbounded read + base64 allocation.
1861
- // Delegates to ImageProcessor's shared guard (no local reimplementation).
1862
- const context = `image file "${filePath}"`;
1863
- ImageProcessor.validateSize(stats.size, context);
1864
- const buffer = await readFileAsync(filePath);
1865
- // TOCTOU: the file can grow, or a symlink can be swapped, between the stat
1866
- // above and this read completing. Re-validate the bytes actually read
1867
- // (not just the pre-read stat) before the base64 allocation.
1868
- return ImageProcessor.safeBase64Convert(buffer, context);
1869
- }
1870
- /**
1871
- * Process a single image input and convert to raw base64 format.
1872
- * IMPORTANT: Returns raw base64 (not a data: URI) to avoid SSRF validation
1873
- * in Vercel AI SDK v6. The SDK calls `new URL(image)` on string values;
1874
- * a data: URI is a valid URL, causing the SDK to "download" it and hit
1875
- * validateDownloadUrl which throws "URL scheme must be http or https, got data:".
1876
- * Passing raw base64 avoids this because `new URL(base64string)` throws and
1877
- * the SDK treats the string as inline base64 data instead.
1878
- */
1879
- async function processImageToBase64(image, index) {
1880
- let imageData;
1881
- let mimeType = "image/jpeg"; // Default mime type
1882
- if (typeof image === "string") {
1883
- if (image.startsWith("data:")) {
1884
- // Data URI (including downloaded URLs) - extract mime type and raw base64
1885
- const match = image.match(/^data:([^;]+);base64,(.+)$/);
1886
- if (match) {
1887
- const declaredMime = match[1];
1888
- // #348: only accept image/* data URIs; reject a non-image MIME before
1889
- // it reaches a provider API rather than passing it through unchecked.
1890
- if (!declaredMime.startsWith("image/")) {
1891
- throw new Error(`Unsupported data URI MIME type for image input at index ${index}: "${declaredMime}" (expected image/*)`);
1892
- }
1893
- mimeType = declaredMime;
1894
- imageData = match[2]; // Raw base64 only — NOT the full data: URI
1895
- }
1896
- else {
1897
- // #270: a malformed data: URI must fail loudly, not silently pass the
1898
- // raw string through as if it were valid base64 (which corrupts the
1899
- // request and surfaces as an opaque provider error later).
1900
- throw new Error(`Malformed image data URI at index ${index} (expected "data:<image/...>;base64,<data>")`);
1901
- }
1902
- }
1903
- else if (isInternetUrl(image)) {
1904
- // This should not happen as URLs are processed separately
1905
- throw new Error(`Unprocessed URL found in actualImages: ${image}`);
1906
- }
1907
- else {
1908
- // File path string - convert to raw base64
1909
- try {
1910
- imageData = await convertFilePathToBase64(image);
1911
- mimeType = getMimeTypeFromExtension(image);
1912
- }
1913
- catch (error) {
1914
- MultimodalLogger.logError("FILE_PATH_CONVERSION", error, {
1915
- index,
1916
- filePath: image,
1917
- });
1918
- // Preserve typed errors (e.g. IMAGE_TOO_LARGE) as-is — don't flatten
1919
- // them into a generic Error and lose the error `code` for callers.
1920
- if (error instanceof NeuroLinkError) {
1921
- throw error;
1922
- }
1923
- throw new Error(`Failed to convert file path to base64: ${image}. ${error}`, { cause: error });
1924
- }
1925
- }
1926
- }
1927
- else {
1928
- // Buffer - convert to raw base64 with proper MIME type detection
1929
- const detectedMimeType = detectMimeTypeFromBuffer(image);
1930
- if (detectedMimeType) {
1931
- mimeType = detectedMimeType;
1932
- }
1933
- // #257: guard the buffer size before the unbounded base64 conversion.
1934
- // Delegates to ImageProcessor's shared guard (no local reimplementation).
1935
- ImageProcessor.validateBufferSize(image, `image input at index ${index}`);
1936
- imageData = image.toString("base64");
1937
- }
1938
- // Last line of defence for vision-format compatibility. `normalizeVisionImageFormats`
1939
- // handles `input.images` eagerly so the providers that read that array
1940
- // directly (Google AI Studio, Bedrock) see converted bytes, but images that
1941
- // arrive as URLs are downloaded further downstream and only become bytes
1942
- // here. A no-op for the universal formats, so the common path is unaffected.
1943
- if (needsVisionTranscode(mimeType)) {
1944
- // Guard the decoded bytes, not just the Buffer input. The buffer branch
1945
- // above is already checked, but a data: URI reaches here having only been
1946
- // regex-matched — so an oversized one was handed straight to sharp/ffmpeg,
1947
- // which decode it in full.
1948
- //
1949
- // Sized before the decode rather than after: checking the Buffer would mean
1950
- // allocating the very thing the limit exists to refuse.
1951
- const context = `image input at index ${index}`;
1952
- ImageProcessor.validateSize(base64DecodedByteLength(imageData), context);
1953
- const rawImage = Buffer.from(imageData, "base64");
1954
- const compatible = await toVisionCompatibleImage(rawImage, mimeType);
1955
- if (compatible.converted) {
1956
- imageData = compatible.buffer.toString("base64");
1957
- mimeType = compatible.mimeType;
1958
- }
1959
- }
1960
- return { imageData, mimeType };
1961
- }
1962
- /**
1963
- * Transcode any image in `input.images` that no vision provider accepts,
1964
- * rewriting the entry in place as a PNG data URI.
1965
- *
1966
- * Mutates in place and is idempotent, matching `processUnifiedFilesArray` and
1967
- * `foldMediaAliasesIntoFiles`: the shared multimodal builder and the providers
1968
- * that bypass it (Google AI Studio's and Vertex's native SDK paths, Bedrock's
1969
- * Converse path) can all call it on the same options object without converting
1970
- * anything twice.
1971
- *
1972
- * Entries that are `http(s)` URLs are left alone — they have no bytes yet, and
1973
- * `processImageToBase64` converts them once they are downloaded.
1974
- */
1975
- export async function normalizeVisionImageFormats(input) {
1976
- const images = input?.images;
1977
- if (!images || images.length === 0) {
1978
- return;
1979
- }
1980
- for (let index = 0; index < images.length; index++) {
1981
- const entry = images[index];
1982
- // ImageWithAltText wraps the payload in `.data`; convert that and keep the
1983
- // alt text attached rather than dropping the wrapper.
1984
- const isWrapped = typeof entry === "object" && entry !== null && !Buffer.isBuffer(entry);
1985
- const payload = isWrapped
1986
- ? entry.data
1987
- : entry;
1988
- const source = await readImageSourceForConversion(payload);
1989
- if (!source || !needsVisionTranscode(source.mimeType)) {
1990
- continue;
1991
- }
1992
- const compatible = await toVisionCompatibleImage(source.buffer, source.mimeType);
1993
- if (!compatible.converted) {
1994
- continue;
1995
- }
1996
- const dataUri = `data:${compatible.mimeType};base64,${compatible.buffer.toString("base64")}`;
1997
- images[index] = isWrapped
1998
- ? { ...entry, data: dataUri }
1999
- : dataUri;
2000
- }
2001
- }
2002
- /**
2003
- * Resolve one `input.images` entry to bytes plus a MIME type, or undefined when
2004
- * it cannot be resolved without a network call.
2005
- *
2006
- * File paths are only read when their extension says the format would need
2007
- * conversion. Reading every attached .png off disk just to confirm it is
2008
- * already compatible would double the I/O of the common case for no benefit.
2009
- */
2010
- /**
2011
- * Byte length `Buffer.from(b64, "base64")` will allocate, computed without
2012
- * allocating it.
2013
- *
2014
- * Base64 encodes 3 bytes per 4 characters, so the encoded length settles the
2015
- * decoded length up front. The point is ordering: a size guard applied to the
2016
- * decoded Buffer has already paid for the allocation it exists to prevent, so
2017
- * every base64 site here checks this first and decodes second — the same shape
2018
- * as the file-path branch, which stats before it reads.
2019
- *
2020
- * This bounds the decode, not the whole request: the encoded string is already
2021
- * resident by the time we see it, so an oversized payload still costs its own
2022
- * length in memory. What it removes is the second, larger allocation on top.
2023
- *
2024
- * Whitespace is skipped because the decoder ignores it, which keeps the count
2025
- * exact rather than a conservative over-estimate that would reject legitimate
2026
- * payloads sitting just under the limit.
2027
- */
2028
- function base64DecodedByteLength(base64) {
2029
- let significant = 0;
2030
- let padding = 0;
2031
- for (let i = 0; i < base64.length; i++) {
2032
- const code = base64.charCodeAt(i);
2033
- if (code === 32 || code === 9 || code === 10 || code === 13) {
2034
- continue;
2035
- }
2036
- significant++;
2037
- if (code === 61) {
2038
- padding++;
2039
- }
2040
- }
2041
- return Math.max(0, Math.floor(significant / 4) * 3 - padding);
2042
- }
2043
- /**
2044
- * Whether a payload is small enough to hand to an image decoder, reported
2045
- * rather than thrown. See {@link readImageSourceForConversion} for why this
2046
- * pass degrades instead of failing.
2047
- */
2048
- function withinConversionByteLimit(bytes, context) {
2049
- try {
2050
- ImageProcessor.validateSize(bytes, context);
2051
- return true;
2052
- }
2053
- catch (error) {
2054
- logger.warn(`[messageBuilder] Skipping vision-format conversion for ${context}: ` +
2055
- `${error instanceof Error ? error.message : String(error)}`);
2056
- return false;
2057
- }
2058
- }
2059
- function withinConversionLimit(buffer, context) {
2060
- return withinConversionByteLimit(buffer.length, context);
2061
- }
2062
- async function readImageSourceForConversion(payload) {
2063
- // Both in-memory shapes are size-checked before they can reach a decoder,
2064
- // the same way the file-path branch below is. `withinConversionLimit`
2065
- // reports rather than throws, because this whole pass is best-effort: an
2066
- // image too large to convert is left in its original format for the
2067
- // downstream guard to reject, which is what an unconvertible image already
2068
- // does. Throwing here would turn a normalisation step into a hard failure.
2069
- if (Buffer.isBuffer(payload)) {
2070
- const mimeType = detectMimeTypeFromBuffer(payload);
2071
- if (!mimeType || !withinConversionLimit(payload, "image buffer")) {
2072
- return undefined;
2073
- }
2074
- return { buffer: payload, mimeType };
2075
- }
2076
- if (typeof payload !== "string") {
2077
- return undefined;
2078
- }
2079
- if (payload.startsWith("data:")) {
2080
- const match = payload.match(/^data:([^;]+);base64,(.+)$/);
2081
- if (!match) {
2082
- return undefined;
2083
- }
2084
- if (!withinConversionByteLimit(base64DecodedByteLength(match[2]), "image data URI")) {
2085
- return undefined;
2086
- }
2087
- return { buffer: Buffer.from(match[2], "base64"), mimeType: match[1] };
2088
- }
2089
- if (isInternetUrl(payload)) {
2090
- return undefined;
2091
- }
2092
- const mimeType = getMimeTypeFromExtension(payload);
2093
- if (!needsVisionTranscode(mimeType)) {
2094
- return undefined;
2095
- }
2096
- try {
2097
- // Preflight the size before reading. Conversion replaces the entry with a
2098
- // data URI, which bypasses processImageToBase64's buffer-size guard — so
2099
- // without this a large local HEIC/TIFF/BMP was read fully into memory and
2100
- // then re-encoded, with no limit applied at either step.
2101
- const { size } = await statAsync(payload);
2102
- ImageProcessor.validateSize(size, `image at ${safeBasename(payload)}`);
2103
- const buffer = await readFileAsync(payload);
2104
- ImageProcessor.validateBufferSize(buffer, `image at ${safeBasename(payload)}`);
2105
- return { buffer, mimeType };
2106
- }
2107
- catch (error) {
2108
- // The path may be a signed URL or carry credentials in query params, so it
2109
- // is redacted rather than interpolated verbatim (see logSanitize).
2110
- logger.warn(`[messageBuilder] Could not read ${redactUrlForError(payload)} for image ` +
2111
- `format conversion: ${error instanceof Error ? error.message : String(error)}`);
2112
- return undefined;
2113
- }
2114
- }
2115
- /**
2116
- * Convert simple images format to Vercel AI SDK format with smart auto-detection
2117
- * - URLs: Downloaded and converted to base64 for Vercel AI SDK compatibility
2118
- * - Local files: Converted to base64 for Vercel AI SDK compatibility
2119
- * - Buffers/Data URIs: Processed normally
2120
- * - Supports alt text for accessibility (included as context in text parts)
2121
- */
2122
- async function convertSimpleImagesToProviderFormat(text, images, provider, _model) {
2123
- // Validate image count against provider-specific limits before processing
2124
- ProviderImageAdapter.validateImageCount(images.length, provider, _model);
2125
- // For Vercel AI SDK, we need to return the content in the standard format
2126
- // The Vercel AI SDK will handle provider-specific formatting internally
2127
- // IMPORTANT: Generate alt text descriptions BEFORE URL downloading to maintain correct image numbering
2128
- // This ensures image numbers match the original order provided by users, even if some URLs fail to download
2129
- const altTextDescriptions = images
2130
- .map((image, idx) => {
2131
- const altText = extractAltText(image);
2132
- return altText ? `[Image ${idx + 1}: ${altText}]` : null;
2133
- })
2134
- .filter(Boolean);
2135
- // Build enhanced text with alt text context for accessibility
2136
- // NOTE: Alt text is appended to the user's prompt as contextual information because most AI providers
2137
- // don't have native alt text fields in their APIs. This approach ensures accessibility metadata
2138
- // is preserved and helps AI models better understand image content.
2139
- const enhancedText = altTextDescriptions.length > 0
2140
- ? `${text}\n\nImage descriptions for context: ${altTextDescriptions.join(" ")}`
2141
- : text;
2142
- // Smart auto-detection: separate URLs from actual image data
2143
- // Also track alt text for each image
2144
- const urlImages = [];
2145
- const actualImages = [];
2146
- images.forEach((image, _index) => {
2147
- const imageData = extractImageData(image);
2148
- const altText = extractAltText(image);
2149
- if (typeof imageData === "string" && isInternetUrl(imageData)) {
2150
- // Internet URL - will be downloaded and converted to base64
2151
- urlImages.push({ url: imageData, altText });
2152
- }
2153
- else {
2154
- // Actual image data (file path, Buffer, data URI) - process for Vercel AI SDK
2155
- actualImages.push({ data: imageData, altText });
2156
- }
2157
- });
2158
- // Download URL images and add to actual images
2159
- for (const { url, altText } of urlImages) {
2160
- try {
2161
- const downloadedDataUri = await downloadImageFromUrl(url);
2162
- actualImages.push({ data: downloadedDataUri, altText });
2163
- }
2164
- catch (error) {
2165
- MultimodalLogger.logError("URL_DOWNLOAD_FAILED_SKIPPING", error, { url });
2166
- // Continue processing other images even if one URL fails
2167
- logger.warn(`Failed to download image from ${url}, skipping: ${error instanceof Error ? error.message : String(error)}`);
2168
- }
2169
- }
2170
- const content = [
2171
- { type: "text", text: enhancedText },
2172
- ];
2173
- // Process all images (including downloaded URLs) for Vercel AI SDK.
2174
- // Sequential for...of (not Promise.all) to preserve image ordering and
2175
- // keep the original forEach's one-at-a-time error semantics.
2176
- for (const [index, { data: image }] of actualImages.entries()) {
2177
- try {
2178
- // Use helper function to process image and reduce nesting depth
2179
- const { imageData, mimeType } = await processImageToBase64(image, index);
2180
- content.push({
2181
- type: "image",
2182
- image: imageData,
2183
- mimeType: mimeType,
2184
- });
2185
- }
2186
- catch (error) {
2187
- MultimodalLogger.logError("ADD_IMAGE_TO_CONTENT", error, {
2188
- index,
2189
- provider,
2190
- });
2191
- throw error;
2192
- }
2193
- }
2194
- return content;
2195
- }
2196
- /**
2197
- * Convert multimodal content (images + PDFs) to provider format
2198
- */
2199
- async function convertMultimodalToProviderFormat(text, images,
2200
- // The canonical entry shape (#309) rather than a fourth copy of it inline —
2201
- // which is what let the render knobs stop short of this function.
2202
- pdfFiles, provider, model, audioFiles = []) {
2203
- const content = [
2204
- { type: "text", text },
2205
- ];
2206
- // Add images if present
2207
- if (images.length > 0) {
2208
- const imageContent = await convertSimpleImagesToProviderFormat("", images, provider, model);
2209
- if (Array.isArray(imageContent)) {
2210
- imageContent.forEach((item) => {
2211
- if (item.type !== "text") {
2212
- content.push(item);
2213
- }
2214
- });
2215
- }
2216
- }
2217
- // Attach audio to providers that can listen. The metadata summary was
2218
- // already appended to `text` during detection, so this adds the recording
2219
- // itself rather than replacing the description — a model asked "how long is
2220
- // this?" keeps the exact answer, and one asked "what is said?" can now
2221
- // answer at all.
2222
- if (audioFiles.length > 0 && supportsNativeAudio(provider)) {
2223
- for (const audio of audioFiles) {
2224
- // Derived from the trimmed basename so a directory containing a dot
2225
- // (`/srv/v1.2/recording`) cannot be mistaken for the file's extension.
2226
- const base = safeBasename(audio.filename);
2227
- const dot = base.lastIndexOf(".");
2228
- const extension = dot > 0 ? base.slice(dot) : ".bin";
2229
- const compatible = await toProviderCompatibleAudio(audio.buffer, audio.mimeType, extension);
2230
- // A conversion that could not run leaves a container the provider does
2231
- // not accept. Sending it anyway turns a metadata answer into an opaque
2232
- // HTTP 400, so it is skipped and the summary stands.
2233
- if (needsAudioTranscode(compatible.mimeType)) {
2234
- logger.warn(`[Audio] Skipping native delivery of ${base}: ` +
2235
- `${compatible.mimeType} is not accepted by ${provider} and could ` +
2236
- `not be converted. The metadata summary was still included.`);
2237
- continue;
2238
- }
2239
- content.push({
2240
- type: "file",
2241
- data: compatible.buffer,
2242
- mediaType: compatible.mimeType,
2243
- });
2244
- logger.info(`[Audio] ✅ Added to content (native audio): ${base}` +
2245
- `${compatible.converted ? ` (converted to ${compatible.mimeType})` : ""}`);
2246
- }
2247
- }
2248
- // Check if provider supports native PDF processing
2249
- const supportsNativePDF = PDFProcessor.supportsNativePDF(provider);
2250
- if (supportsNativePDF) {
2251
- // Add PDFs using Vercel AI SDK standard format (works for providers with native PDF support)
2252
- content.push(...pdfFiles.map((pdf) => {
2253
- logger.info(`[PDF] ✅ Added to content (native PDF format): ${pdf.filename}`);
2254
- return {
2255
- type: "file",
2256
- data: pdf.buffer,
2257
- mediaType: "application/pdf",
2258
- };
2259
- }));
2260
- }
2261
- else {
2262
- // Provider doesn't support native PDF - convert PDF pages to images
2263
- // This enables PDF processing for providers like Mistral, Ollama that support images but not PDFs
2264
- logger.info(`[PDF→Image] Provider ${provider} doesn't support native PDF. Converting ${pdfFiles.length} PDF(s) to images...`);
2265
- for (const pdf of pdfFiles) {
2266
- try {
2267
- const effectiveMaxPages = pdf.maxPages ?? PDF_LIMITS.DEFAULT_MAX_PAGES;
2268
- const conversionResult = await PDFImageConverter.convertToImages(pdf.buffer, {
2269
- // #297: this is the only PDF→image call the product actually makes,
2270
- // and it used to hardcode scale 2.0 — silently overriding the
2271
- // lowered PDF_LIMITS.DEFAULT_SCALE and keeping the memory cost the
2272
- // issue reports (a 100-page render at 2.0 is ~776MB; 1.5 is ~44%
2273
- // fewer pixels per page). Callers can raise it back per request.
2274
- scale: pdf.scale ?? PDF_LIMITS.DEFAULT_SCALE,
2275
- // Page ceiling guards token overflow; also now caller-adjustable
2276
- // rather than a constant nothing could reach.
2277
- maxPages: effectiveMaxPages,
2278
- ...(pdf.password ? { password: pdf.password } : {}), // #258
2279
- ...(pdf.maxCanvasPixels
2280
- ? { maxCanvasPixels: pdf.maxCanvasPixels }
2281
- : {}), // #260
2282
- });
2283
- // The renderer stops at maxPages, so a longer document is silently
2284
- // truncated — say so rather than letting the model answer from a
2285
- // partial document as though it had the whole thing.
2286
- //
2287
- // Keyed on the cap being reached, not on pdf.pageCount: that field is
2288
- // null whenever `input.content` omits `metadata.pages`, which is the
2289
- // common case, so a page-count comparison would simply never fire
2290
- // there. Reaching the cap is also unambiguous — a short count caused by
2291
- // per-page render failures (#294 isolates those into `errors`) would
2292
- // otherwise be misreported as a maxPages truncation.
2293
- if (conversionResult.pageCount >= effectiveMaxPages) {
2294
- logger.warn(`[PDF→Image] ${safeBasename(pdf.filename)} hit the ${effectiveMaxPages}-page ` +
2295
- `conversion limit. Any pages beyond that were not sent — the model may be ` +
2296
- `answering from a partial document. Raise pdfOptions.maxPages or split the file.`);
2297
- }
2298
- if (conversionResult.errors && conversionResult.errors.length > 0) {
2299
- logger.warn(`[PDF→Image] ${safeBasename(pdf.filename)}: ${conversionResult.errors.length} page(s) ` +
2300
- `failed to render and were omitted (page ${conversionResult.errors.map((e) => e.page).join(", ")}).`);
2301
- }
2302
- logger.info(`[PDF→Image] ✅ Converted ${pdf.filename}: ${conversionResult.pageCount} page(s) → images`);
2303
- // Add each page as an ImagePart (raw base64, not data: URI — see SSRF note above)
2304
- conversionResult.images.forEach((base64Image, pageIndex) => {
2305
- content.push({
2306
- type: "image",
2307
- image: base64Image,
2308
- mimeType: "image/png",
2309
- });
2310
- logger.debug(`[PDF→Image] Added page ${pageIndex + 1}/${conversionResult.pageCount} of ${pdf.filename}`);
2311
- });
2312
- // Log any warnings from conversion
2313
- if (conversionResult.warnings) {
2314
- conversionResult.warnings.forEach((warning) => {
2315
- logger.warn(`[PDF→Image] ${warning}`);
2316
- });
2317
- }
2318
- }
2319
- catch (error) {
2320
- const errorMessage = error instanceof Error ? error.message : String(error);
2321
- logger.error(`[PDF→Image] ❌ Failed to convert ${pdf.filename}: ${errorMessage}`);
2322
- // #258: password errors are already actionable typed errors — re-throw
2323
- // them unwrapped so the "supply a password" guidance isn't buried.
2324
- const code = error?.code;
2325
- if (code === "PDF_PASSWORD_REQUIRED" ||
2326
- code === "PDF_INCORRECT_PASSWORD") {
2327
- throw error;
2328
- }
2329
- // Re-throw so the user knows PDF processing failed
2330
- throw new Error(`PDF to image conversion failed for ${pdf.filename}: ${errorMessage}. ` +
2331
- `Provider ${provider} doesn't support native PDFs and image conversion failed.`, { cause: error });
2332
- }
2333
- }
2334
- }
2335
- return content;
2336
- }
2337
- /**
2338
- * Type guard for FileWithMetadata objects.
2339
- */
2340
- function isFileWithMetadata(file) {
2341
- return (typeof file === "object" &&
2342
- !Buffer.isBuffer(file) &&
2343
- "buffer" in file &&
2344
- "filename" in file);
2345
- }
2346
- /**
2347
- * Extract filename from file input.
2348
- * Supports Buffers (generic name), strings (path/URL), and FileWithMetadata objects.
2349
- */
2350
- function extractFilename(file, index = 0) {
2351
- if (isFileWithMetadata(file)) {
2352
- return file.filename;
2353
- }
2354
- if (typeof file === "string") {
2355
- if (file.startsWith("http")) {
2356
- try {
2357
- const url = new URL(file);
2358
- return url.pathname.split("/").pop() || `file-${index + 1}`;
2359
- }
2360
- catch {
2361
- return `file-${index + 1}`;
2362
- }
2363
- }
2364
- return (file.split("/").pop() || file.split("\\").pop() || `file-${index + 1}`);
2365
- }
2366
- return `file-${index + 1}`;
2367
- }
2368
- /**
2369
- * Get the byte size of a file input.
2370
- * For FileWithMetadata: returns buffer.length.
2371
- * For Buffers: returns buffer.length.
2372
- * For strings that are file paths: returns the stat size.
2373
- * For URLs/data URIs: returns a rough estimate from string length.
2374
- */
2375
- function getFileSize(file) {
2376
- if (isFileWithMetadata(file)) {
2377
- return file.buffer.length;
2378
- }
2379
- if (Buffer.isBuffer(file)) {
2380
- return file.length;
2381
- }
2382
- if (typeof file === "string" && existsSync(file)) {
2383
- try {
2384
- return statSync(file).size;
2385
- }
2386
- catch {
2387
- return 0;
2388
- }
2389
- }
2390
- // For URLs and data URIs, use string length as rough estimate
2391
- return typeof file === "string" ? file.length : 0;
2392
- }
2393
- /**
2394
- * Get a Buffer from a file input.
2395
- * For FileWithMetadata: returns the buffer property.
2396
- * For Buffers: returns as-is.
2397
- * For file paths: reads the file.
2398
- * For URLs/data URIs: returns null (not supported for lazy registration).
2399
- */
2400
- async function getFileBuffer(file) {
2401
- if (isFileWithMetadata(file)) {
2402
- return file.buffer;
2403
- }
2404
- if (Buffer.isBuffer(file)) {
2405
- return file;
2406
- }
2407
- if (typeof file === "string" && existsSync(file)) {
2408
- try {
2409
- return readFileSync(file);
2410
- }
2411
- catch {
2412
- return null;
2413
- }
2414
- }
2415
- // URLs and data URIs can't be lazily registered (need download first)
2416
- return null;
2417
- }
2418
- /**
2419
- * Determine the source type of a file input.
2420
- */
2421
- function getFileSource(file) {
2422
- if (isFileWithMetadata(file)) {
2423
- return "buffer";
2424
- }
2425
- if (Buffer.isBuffer(file)) {
2426
- return "buffer";
2427
- }
2428
- if (typeof file === "string") {
2429
- if (file.startsWith("data:")) {
2430
- return "datauri";
2431
- }
2432
- if (file.startsWith("http://") || file.startsWith("https://")) {
2433
- return "url";
2434
- }
2435
- if (existsSync(file)) {
2436
- return "path";
2437
- }
2438
- }
2439
- return "buffer";
2440
- }
2441
- /**
2442
- * Whether a file must be processed eagerly rather than lazily referenced.
2443
- *
2444
- * The lazy path registers a file and injects a short textual *preview* in place
2445
- * of the file itself. Whether that is an acceptable trade depends entirely on
2446
- * whether a description of the file can answer questions about it:
2447
- *
2448
- * pdf lazy -> preview carries the extracted text ✔ content survives
2449
- * image lazy -> preview carries ~98 chars of prose ✘ the pixels are gone
2450
- *
2451
- * An image is the case where the bytes ARE the content: no prose summary
2452
- * substitutes for them, so the model receives a description of a file instead
2453
- * of the file. Measured end-to-end on `release`, asking "what number is
2454
- * written in this image?":
2455
- *
2456
- * tiny.png 1.6 KB -> "7391" (under TINY_MAX, eager, correct)
2457
- * big.png 11 KB -> NOTHING_RECEIVED (lazy, image never arrived)
2458
- * big.jpg 19 KB -> NOTHING_RECEIVED
2459
- *
2460
- * 10 KB is far below any real photo, so this affected essentially every image
2461
- * attached by path — an ordinary JPEG, not just unusual formats.
2462
- *
2463
- * Images were only the most visible case. The same reasoning generalises to
2464
- * every type whose content is not text, which is why the rule below is stated
2465
- * as an exclusion — preview lazily what a text slice can faithfully represent,
2466
- * process everything else — rather than as a list of media types. See
2467
- * {@link isEagerType} for what that costs and buys per modality.
2468
- *
2469
- * Audio deserves a note because it is the case most likely to look fine while
2470
- * being broken: its message carries a metadata block — duration, codec, sample
2471
- * rate — that answers exactly the questions ("how long is it?", "what sample
2472
- * rate?") a test is most tempted to ask, and answers them correctly with no
2473
- * audio whatsoever attached. A test asking those questions passes against a
2474
- * model that received nothing.
2475
- *
2476
- * Note this costs no extra memory: `tryRegisterFileReference` already calls
2477
- * `getFileBuffer()` and reads the whole file to register it. The lazy path was
2478
- * never lazy about reading — only about processing — so the difference here is
2479
- * simply whether the bytes survive.
2480
- */
2481
- function isEagerMultimodalFile(file) {
2482
- if (typeof file === "string") {
2483
- return isEagerType(inferFileTypeFromExtension(file));
2484
- }
2485
- if (Buffer.isBuffer(file)) {
2486
- return isEagerType(inferFileTypeFromBuffer(file));
2487
- }
2488
- // A `FileWithMetadata` carries two independent declarations, and either is
2489
- // enough on its own: the shape exists for Slack/Curator-style uploads that
2490
- // arrive as bytes plus a mimetype, so its `filename` may be extensionless or
2491
- // simply wrong. Reading them as a `??` chain let the first *recognised* name
2492
- // win outright — `recording.txt` with `mimetype: "audio/mpeg"` classified as
2493
- // text, stayed lazy, and never reached the native-audio path this change
2494
- // exists to feed. A file is kept lazy only when nothing about it disagrees.
2495
- const declared = [
2496
- inferFileTypeFromExtension(file.filename),
2497
- inferFileTypeFromMimetype(file.mimetype),
2498
- ];
2499
- if (declared.some(isEagerType)) {
2500
- return true;
2501
- }
2502
- // The buffer sniff is a last resort rather than a third vote, because it is
2503
- // partly a substring scan: an HTML page with an inline `<svg>` icon in its
2504
- // head would otherwise be pulled onto the eager path and sent in full, which
2505
- // is the opposite of what the size tiers are for. It speaks only when neither
2506
- // declaration did.
2507
- return declared.every((type) => type === undefined)
2508
- ? isEagerType(inferFileTypeFromBuffer(file.buffer))
2509
- : false;
2510
- }
2511
- /**
2512
- * Whether a routing type must be processed rather than previewed.
2513
- *
2514
- * "svg" is a separate routing type rather than a sub-case of "image" (it goes
2515
- * to the sanitizer, not to a vision encoder), but it is still an image as far
2516
- * as this decision is concerned: its markup IS its content, and previewing it
2517
- * away leaves the model with nothing. Accepting both keeps this correct
2518
- * whichever of the two type vocabularies the caller's map uses.
2519
- *
2520
- * Audio and video join them, for one shared reason: the lazy path never runs
2521
- * the detection branch that produces their model-visible content — the decoded
2522
- * audio buffer, the extracted video keyframes — so a lazily registered file is
2523
- * summarised away no matter what the dispatch side is willing to send.
2524
- *
2525
- * Video is the clearest demonstration that this is a delivery problem and not a
2526
- * format one. Keyframe extraction is identical across containers (three frames,
2527
- * ~38 KB each, for every one of mp4/wmv/flv/mpg/m2ts), and a frame pulled from
2528
- * any of them shows the test token perfectly legibly. Yet only mp4 answered
2529
- * correctly, because Gemini accepts an mp4 natively and never needed the
2530
- * frames; every container it cannot decode returned NOTHING_RECEIVED, since the
2531
- * frames that would have carried the answer were never extracted. Making video
2532
- * eager fixed all four at once.
2533
- *
2534
- * Documents and archives are here for the same reason once removed. The lazy
2535
- * preview is a truncated slice of the raw bytes, so it is only ever faithful
2536
- * for a file that IS text. A .rtf sliced raw is RTF control words, and a
2537
- * .bz2/.xz/.zst is compressed bytes — the model was told "binary file of
2538
- * unknown type" about files whose processors extract them cleanly.
2539
- *
2540
- * Which leaves plain text and CSV on the lazy path, and they are exactly the
2541
- * cases it was built for: a truncated sample of a large CSV is a faithful
2542
- * sample, and the file tools can read the rest on demand.
2543
- */
2544
- function isEagerType(type) {
2545
- return type !== undefined && type !== "text" && type !== "csv";
2546
- }
2547
- /**
2548
- * Infer a routing type from a caller-declared mimetype.
2549
- *
2550
- * Only images matter here — this exists so the eager/lazy decision can read a
2551
- * mimetype hint — and "application/octet-stream" is deliberately ignored,
2552
- * because it is the opaque sentinel a caller sends when it knows nothing, not
2553
- * a claim about content.
2554
- */
2555
- function inferFileTypeFromMimetype(mimetype) {
2556
- if (!mimetype) {
2557
- return undefined;
2558
- }
2559
- const normalized = mimetype.split(";")[0].trim().toLowerCase();
2560
- // "application/octet-stream" is deliberately absent from the registry side of
2561
- // this lookup: it is the opaque sentinel a caller sends when it knows
2562
- // nothing, not a claim about content, and treating it as one would let a
2563
- // shrugging uploader force a routing decision.
2564
- if (normalized === "application/octet-stream") {
2565
- return undefined;
2566
- }
2567
- const exact = MIMETYPE_TYPE_MAP[normalized];
2568
- if (exact) {
2569
- return exact;
2570
- }
2571
- // A family fallback for types the registry does not enumerate — `audio/webm`,
2572
- // `image/x-something`. The leading segment is enough to decide eager vs lazy
2573
- // even when the exact codec is unknown to us.
2574
- const family = normalized.split("/")[0];
2575
- return family === "image" || family === "audio" || family === "video"
2576
- ? family
2577
- : undefined;
2578
- }
2579
- /**
2580
- * Try to register a file with the FileReferenceRegistry for lazy processing.
2581
- * Returns true if registration succeeded, false if it failed (caller should
2582
- * fall through to full processing).
2583
- */
2584
- async function tryRegisterFileReference(file, fileSize, registry, index = 0) {
2585
- try {
2586
- const buffer = await getFileBuffer(file);
2587
- if (!buffer) {
2588
- return false;
2589
- }
2590
- const filename = extractFilename(file, index);
2591
- const mimetype = typeof file === "object" && !Buffer.isBuffer(file)
2592
- ? file.mimetype
2593
- : undefined;
2594
- await registry.register(buffer, getFileSource(file), {
2595
- filename,
2596
- mimetype,
2597
- });
2598
- logger.info(`[FileDetector] Registered "${filename}" (${(fileSize / 1024).toFixed(0)} KB) ` +
2599
- `as lazy reference — skipping upfront processing`);
2600
- return true;
2601
- }
2602
- catch (regError) {
2603
- logger.warn(`[FileDetector] Failed to register file as reference, falling back to full processing: ${regError instanceof Error ? regError.message : String(regError)}`);
2604
- return false;
2605
- }
2606
- }
2607
- /**
2608
- * Get a language hint for code fencing based on MIME type or filename extension.
2609
- * Returns the language identifier for markdown code blocks, or null for generic text.
2610
- */
2611
- function getLanguageHint(mimeType, filename) {
2612
- // Try MIME type first
2613
- const mimeMap = {
2614
- "text/javascript": "javascript",
2615
- "text/typescript": "typescript",
2616
- "text/x-python": "python",
2617
- "text/x-java-source": "java",
2618
- "text/x-go": "go",
2619
- "text/x-rustsrc": "rust",
2620
- "text/x-ruby": "ruby",
2621
- "text/x-php": "php",
2622
- "text/x-c": "c",
2623
- "text/x-c++": "cpp",
2624
- "text/x-csharp": "csharp",
2625
- "text/x-swift": "swift",
2626
- "text/x-kotlin": "kotlin",
2627
- "text/x-scala": "scala",
2628
- "text/x-shellscript": "bash",
2629
- "text/x-powershell": "powershell",
2630
- "text/x-sql": "sql",
2631
- "text/x-r": "r",
2632
- "text/x-lua": "lua",
2633
- "text/x-perl": "perl",
2634
- "text/x-dart": "dart",
2635
- "text/x-elixir": "elixir",
2636
- "text/x-erlang": "erlang",
2637
- "text/x-haskell": "haskell",
2638
- "text/x-clojure": "clojure",
2639
- "text/x-lisp": "lisp",
2640
- "text/html": "html",
2641
- "text/css": "css",
2642
- "text/markdown": "markdown",
2643
- "application/json": "json",
2644
- "application/xml": "xml",
2645
- "text/xml": "xml",
2646
- "application/yaml": "yaml",
2647
- "application/x-yaml": "yaml",
2648
- };
2649
- const lower = mimeType.toLowerCase().split(";")[0].trim();
2650
- if (mimeMap[lower]) {
2651
- return mimeMap[lower];
2652
- }
2653
- // Fallback: try extension from filename
2654
- const ext = filename.split(".").pop()?.toLowerCase();
2655
- if (!ext) {
2656
- return null;
2657
- }
2658
- const extMap = {
2659
- js: "javascript",
2660
- mjs: "javascript",
2661
- cjs: "javascript",
2662
- jsx: "javascript",
2663
- ts: "typescript",
2664
- tsx: "typescript",
2665
- py: "python",
2666
- java: "java",
2667
- go: "go",
2668
- rs: "rust",
2669
- rb: "ruby",
2670
- php: "php",
2671
- c: "c",
2672
- cpp: "cpp",
2673
- cc: "cpp",
2674
- h: "c",
2675
- hpp: "cpp",
2676
- cs: "csharp",
2677
- swift: "swift",
2678
- kt: "kotlin",
2679
- kts: "kotlin",
2680
- scala: "scala",
2681
- sh: "bash",
2682
- bash: "bash",
2683
- zsh: "bash",
2684
- ps1: "powershell",
2685
- sql: "sql",
2686
- r: "r",
2687
- lua: "lua",
2688
- pl: "perl",
2689
- perl: "perl",
2690
- dart: "dart",
2691
- ex: "elixir",
2692
- exs: "elixir",
2693
- erl: "erlang",
2694
- hs: "haskell",
2695
- clj: "clojure",
2696
- lisp: "lisp",
2697
- vim: "vim",
2698
- html: "html",
2699
- htm: "html",
2700
- css: "css",
2701
- md: "markdown",
2702
- markdown: "markdown",
2703
- json: "json",
2704
- xml: "xml",
2705
- yaml: "yaml",
2706
- yml: "yaml",
2707
- toml: "toml",
2708
- ini: "ini",
2709
- cfg: "ini",
2710
- };
2711
- return extMap[ext] || null;
2712
- }
2713
- function buildCSVToolInstructions(filePath) {
2714
- return `\n**NOTE**: You can perform calculations directly on the CSV data shown above. For advanced operations on the full file (counting by column, grouping, etc.), you may optionally use the analyzeCSV tool with filePath="${filePath}".\n\nExample: analyzeCSV(filePath="${filePath}", operation="count_by_column", column="merchant_id")\n\n`;
2715
- }
2716
- //# sourceMappingURL=messageBuilder.js.map