@juspay/neurolink 11.12.0 → 11.13.1

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 (1921) hide show
  1. package/CHANGELOG.md +13 -3
  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 +87 -45
  21. package/dist/cli/commands/proxyAnalyze.d.ts +1 -1
  22. package/dist/cli/commands/proxyAnalyze.js +12 -3
  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 +5 -2
  64. package/dist/cli/proxy-clients/claudeCode.d.ts +1 -1
  65. package/dist/cli/proxy-clients/claudeCode.js +43 -11
  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 +38 -16
  72. package/dist/cli/proxy-clients/qwenCode.d.ts +1 -1
  73. package/dist/cli/proxy-clients/qwenCode.js +34 -10
  74. package/dist/cli/proxy-clients/registry.d.ts +1 -1
  75. package/dist/cli/proxy-clients/registry.js +10 -2
  76. package/dist/cli/proxy-clients/snapshot.d.ts +52 -0
  77. package/dist/cli/proxy-clients/snapshot.js +98 -0
  78. package/dist/cli/utils/audioFileUtils.d.ts +1 -1
  79. package/dist/cli/utils/audioPlayer.d.ts +1 -1
  80. package/dist/cli/utils/classifierRouterFlags.d.ts +1 -1
  81. package/dist/cli/utils/classifierRouterFlags.js +1 -1
  82. package/dist/cli/utils/completeSetup.d.ts +1 -1
  83. package/dist/cli/utils/completeSetup.js +1 -1
  84. package/dist/cli/utils/envManager.d.ts +1 -1
  85. package/dist/cli/utils/envManager.js +1 -1
  86. package/dist/cli/utils/inputValidation.js +2 -2
  87. package/dist/cli/utils/interactiveSetup.d.ts +2 -2
  88. package/dist/cli/utils/interactiveSetup.js +3 -3
  89. package/dist/cli/utils/ollamaUtils.d.ts +1 -1
  90. package/dist/cli/utils/ollamaUtils.js +1 -1
  91. package/dist/cli/utils/skillsFlags.d.ts +1 -1
  92. package/dist/cli/utils/toolRoutingFlags.d.ts +1 -1
  93. package/dist/cli/utils/toolRoutingFlags.js +1 -1
  94. package/dist/cli/utils/videoFileUtils.d.ts +1 -1
  95. package/dist/processors/data/XmlProcessor.d.ts +14 -0
  96. package/dist/processors/data/XmlProcessor.js +14 -0
  97. package/dist/processors/document/PptxProcessor.d.ts +9 -0
  98. package/dist/processors/document/PptxProcessor.js +9 -0
  99. package/dist/processors/media/VideoProcessor.js +30 -2
  100. package/dist/providers/amazonBedrock/client.js +1 -2
  101. package/dist/providers/googleAiStudio/client.js +6 -3
  102. package/dist/providers/googleVertex/client.js +6 -3
  103. package/dist/providers/googleVertex/index.d.ts +0 -1
  104. package/dist/providers/googleVertex/index.js +0 -1
  105. package/dist/proxy/codexUsage.d.ts +68 -0
  106. package/dist/proxy/codexUsage.js +246 -0
  107. package/dist/proxy/proxyAnalysis.js +87 -3
  108. package/dist/proxy/proxyFetch.d.ts +1 -0
  109. package/dist/proxy/proxyFetch.js +29 -0
  110. package/dist/proxy/proxyTracer.d.ts +13 -2
  111. package/dist/proxy/proxyTracer.js +29 -7
  112. package/dist/proxy/proxyTranslationEngine.js +22 -5
  113. package/dist/rag/document/loaders.js +49 -21
  114. package/dist/server/abstract/baseServerAdapter.d.ts +13 -0
  115. package/dist/server/abstract/baseServerAdapter.js +39 -1
  116. package/dist/server/adapters/expressAdapter.js +15 -5
  117. package/dist/server/adapters/fastifyAdapter.js +15 -5
  118. package/dist/server/adapters/koaAdapter.js +16 -6
  119. package/dist/server/routes/codexProxyRoutes.js +29 -1
  120. package/dist/server/routes/openaiProxyRoutes.js +5 -0
  121. package/dist/types/generate.d.ts +7 -0
  122. package/dist/types/proxy.d.ts +65 -0
  123. package/dist/types/stream.d.ts +1 -1
  124. package/dist/utils/pricing.d.ts +9 -0
  125. package/dist/utils/pricing.js +136 -1
  126. package/docs-site/mcp-server/search.js +20 -12
  127. package/docs-site/mcp-server/types.d.ts +12 -5
  128. package/docs-site/static/search-index.json +1 -0
  129. package/package.json +5 -6
  130. package/dist/lib/action/actionExecutor.d.ts +0 -29
  131. package/dist/lib/action/actionExecutor.js +0 -291
  132. package/dist/lib/action/actionInputs.d.ts +0 -25
  133. package/dist/lib/action/actionInputs.js +0 -294
  134. package/dist/lib/action/githubIntegration.d.ts +0 -21
  135. package/dist/lib/action/githubIntegration.js +0 -188
  136. package/dist/lib/action/index.d.ts +0 -7
  137. package/dist/lib/action/index.js +0 -13
  138. package/dist/lib/adapters/audioFormatSupport.d.ts +0 -53
  139. package/dist/lib/adapters/audioFormatSupport.js +0 -201
  140. package/dist/lib/adapters/imageFormatSupport.d.ts +0 -75
  141. package/dist/lib/adapters/imageFormatSupport.js +0 -284
  142. package/dist/lib/adapters/providerImageAdapter.d.ts +0 -51
  143. package/dist/lib/adapters/providerImageAdapter.js +0 -704
  144. package/dist/lib/adapters/replicate/auth.d.ts +0 -19
  145. package/dist/lib/adapters/replicate/auth.js +0 -33
  146. package/dist/lib/adapters/replicate/predictionLifecycle.d.ts +0 -46
  147. package/dist/lib/adapters/replicate/predictionLifecycle.js +0 -289
  148. package/dist/lib/adapters/tts/cartesiaHandler.d.ts +0 -12
  149. package/dist/lib/adapters/tts/cartesiaHandler.js +0 -131
  150. package/dist/lib/adapters/tts/googleTTSHandler.d.ts +0 -97
  151. package/dist/lib/adapters/tts/googleTTSHandler.js +0 -353
  152. package/dist/lib/adapters/video/directorPipeline.d.ts +0 -31
  153. package/dist/lib/adapters/video/directorPipeline.js +0 -523
  154. package/dist/lib/adapters/video/ffmpegAdapter.d.ts +0 -84
  155. package/dist/lib/adapters/video/ffmpegAdapter.js +0 -207
  156. package/dist/lib/adapters/video/frameExtractor.d.ts +0 -28
  157. package/dist/lib/adapters/video/frameExtractor.js +0 -144
  158. package/dist/lib/adapters/video/klingVideoHandler.d.ts +0 -37
  159. package/dist/lib/adapters/video/klingVideoHandler.js +0 -306
  160. package/dist/lib/adapters/video/replicateVideoHandler.d.ts +0 -29
  161. package/dist/lib/adapters/video/replicateVideoHandler.js +0 -168
  162. package/dist/lib/adapters/video/runwayVideoHandler.d.ts +0 -32
  163. package/dist/lib/adapters/video/runwayVideoHandler.js +0 -317
  164. package/dist/lib/adapters/video/vertexVideoHandler.d.ts +0 -119
  165. package/dist/lib/adapters/video/vertexVideoHandler.js +0 -804
  166. package/dist/lib/adapters/video/videoAnalyzer.d.ts +0 -26
  167. package/dist/lib/adapters/video/videoAnalyzer.js +0 -239
  168. package/dist/lib/adapters/video/videoMerger.d.ts +0 -22
  169. package/dist/lib/adapters/video/videoMerger.js +0 -172
  170. package/dist/lib/agent/agent.d.ts +0 -104
  171. package/dist/lib/agent/agent.js +0 -433
  172. package/dist/lib/agent/agentNetwork.d.ts +0 -87
  173. package/dist/lib/agent/agentNetwork.js +0 -501
  174. package/dist/lib/agent/agentToolRegistrar.d.ts +0 -48
  175. package/dist/lib/agent/agentToolRegistrar.js +0 -337
  176. package/dist/lib/agent/communication/index.d.ts +0 -9
  177. package/dist/lib/agent/communication/index.js +0 -10
  178. package/dist/lib/agent/communication/message-bus.d.ts +0 -113
  179. package/dist/lib/agent/communication/message-bus.js +0 -407
  180. package/dist/lib/agent/coordination/coordinator.d.ts +0 -83
  181. package/dist/lib/agent/coordination/coordinator.js +0 -599
  182. package/dist/lib/agent/coordination/index.d.ts +0 -10
  183. package/dist/lib/agent/coordination/index.js +0 -11
  184. package/dist/lib/agent/coordination/task-distributor.d.ts +0 -113
  185. package/dist/lib/agent/coordination/task-distributor.js +0 -586
  186. package/dist/lib/agent/directTools.d.ts +0 -306
  187. package/dist/lib/agent/directTools.js +0 -907
  188. package/dist/lib/agent/index.d.ts +0 -41
  189. package/dist/lib/agent/index.js +0 -49
  190. package/dist/lib/agent/isolatedAgentRunner.d.ts +0 -73
  191. package/dist/lib/agent/isolatedAgentRunner.js +0 -947
  192. package/dist/lib/agent/orchestration/index.d.ts +0 -10
  193. package/dist/lib/agent/orchestration/index.js +0 -11
  194. package/dist/lib/agent/orchestration/orchestrator.d.ts +0 -114
  195. package/dist/lib/agent/orchestration/orchestrator.js +0 -479
  196. package/dist/lib/agent/orchestration/topology.d.ts +0 -164
  197. package/dist/lib/agent/orchestration/topology.js +0 -521
  198. package/dist/lib/agent/prompts/routingPrompts.d.ts +0 -63
  199. package/dist/lib/agent/prompts/routingPrompts.js +0 -202
  200. package/dist/lib/agent/structuredRecovery.d.ts +0 -30
  201. package/dist/lib/agent/structuredRecovery.js +0 -105
  202. package/dist/lib/analytics/index.d.ts +0 -7
  203. package/dist/lib/analytics/index.js +0 -8
  204. package/dist/lib/analytics/parseQualityScore.d.ts +0 -9
  205. package/dist/lib/analytics/parseQualityScore.js +0 -30
  206. package/dist/lib/analytics/pricing.d.ts +0 -27
  207. package/dist/lib/analytics/pricing.js +0 -42
  208. package/dist/lib/analytics/service.d.ts +0 -36
  209. package/dist/lib/analytics/service.js +0 -394
  210. package/dist/lib/analytics/storage.d.ts +0 -19
  211. package/dist/lib/analytics/storage.js +0 -33
  212. package/dist/lib/artifacts/artifactStore.d.ts +0 -55
  213. package/dist/lib/artifacts/artifactStore.js +0 -145
  214. package/dist/lib/auth/AuthProviderFactory.d.ts +0 -69
  215. package/dist/lib/auth/AuthProviderFactory.js +0 -112
  216. package/dist/lib/auth/AuthProviderRegistry.d.ts +0 -33
  217. package/dist/lib/auth/AuthProviderRegistry.js +0 -191
  218. package/dist/lib/auth/RequestContext.d.ts +0 -23
  219. package/dist/lib/auth/RequestContext.js +0 -79
  220. package/dist/lib/auth/accountPool.d.ts +0 -68
  221. package/dist/lib/auth/accountPool.js +0 -179
  222. package/dist/lib/auth/anthropicOAuth.d.ts +0 -400
  223. package/dist/lib/auth/anthropicOAuth.js +0 -1143
  224. package/dist/lib/auth/authContext.d.ts +0 -198
  225. package/dist/lib/auth/authContext.js +0 -315
  226. package/dist/lib/auth/codexOAuth.d.ts +0 -67
  227. package/dist/lib/auth/codexOAuth.js +0 -203
  228. package/dist/lib/auth/errors.d.ts +0 -63
  229. package/dist/lib/auth/errors.js +0 -40
  230. package/dist/lib/auth/index.d.ts +0 -41
  231. package/dist/lib/auth/index.js +0 -86
  232. package/dist/lib/auth/middleware/AuthMiddleware.d.ts +0 -127
  233. package/dist/lib/auth/middleware/AuthMiddleware.js +0 -523
  234. package/dist/lib/auth/middleware/rateLimitByUser.d.ts +0 -193
  235. package/dist/lib/auth/middleware/rateLimitByUser.js +0 -559
  236. package/dist/lib/auth/providers/BaseAuthProvider.d.ts +0 -259
  237. package/dist/lib/auth/providers/BaseAuthProvider.js +0 -724
  238. package/dist/lib/auth/providers/CognitoProvider.d.ts +0 -61
  239. package/dist/lib/auth/providers/CognitoProvider.js +0 -308
  240. package/dist/lib/auth/providers/KeycloakProvider.d.ts +0 -61
  241. package/dist/lib/auth/providers/KeycloakProvider.js +0 -396
  242. package/dist/lib/auth/providers/auth0.d.ts +0 -59
  243. package/dist/lib/auth/providers/auth0.js +0 -275
  244. package/dist/lib/auth/providers/betterAuth.d.ts +0 -51
  245. package/dist/lib/auth/providers/betterAuth.js +0 -183
  246. package/dist/lib/auth/providers/clerk.d.ts +0 -65
  247. package/dist/lib/auth/providers/clerk.js +0 -318
  248. package/dist/lib/auth/providers/custom.d.ts +0 -64
  249. package/dist/lib/auth/providers/custom.js +0 -113
  250. package/dist/lib/auth/providers/firebase.d.ts +0 -63
  251. package/dist/lib/auth/providers/firebase.js +0 -231
  252. package/dist/lib/auth/providers/jwt.d.ts +0 -68
  253. package/dist/lib/auth/providers/jwt.js +0 -217
  254. package/dist/lib/auth/providers/oauth2.d.ts +0 -73
  255. package/dist/lib/auth/providers/oauth2.js +0 -304
  256. package/dist/lib/auth/providers/supabase.d.ts +0 -63
  257. package/dist/lib/auth/providers/supabase.js +0 -260
  258. package/dist/lib/auth/providers/workos.d.ts +0 -61
  259. package/dist/lib/auth/providers/workos.js +0 -289
  260. package/dist/lib/auth/serverBridge.d.ts +0 -14
  261. package/dist/lib/auth/serverBridge.js +0 -26
  262. package/dist/lib/auth/sessionManager.d.ts +0 -118
  263. package/dist/lib/auth/sessionManager.js +0 -511
  264. package/dist/lib/auth/tokenStore.d.ts +0 -283
  265. package/dist/lib/auth/tokenStore.js +0 -929
  266. package/dist/lib/autoresearch/config.d.ts +0 -11
  267. package/dist/lib/autoresearch/config.js +0 -109
  268. package/dist/lib/autoresearch/errors.d.ts +0 -40
  269. package/dist/lib/autoresearch/errors.js +0 -21
  270. package/dist/lib/autoresearch/index.d.ts +0 -23
  271. package/dist/lib/autoresearch/index.js +0 -35
  272. package/dist/lib/autoresearch/phasePolicy.d.ts +0 -9
  273. package/dist/lib/autoresearch/phasePolicy.js +0 -70
  274. package/dist/lib/autoresearch/promptCompiler.d.ts +0 -15
  275. package/dist/lib/autoresearch/promptCompiler.js +0 -121
  276. package/dist/lib/autoresearch/repoPolicy.d.ts +0 -32
  277. package/dist/lib/autoresearch/repoPolicy.js +0 -129
  278. package/dist/lib/autoresearch/resultRecorder.d.ts +0 -20
  279. package/dist/lib/autoresearch/resultRecorder.js +0 -131
  280. package/dist/lib/autoresearch/runner.d.ts +0 -10
  281. package/dist/lib/autoresearch/runner.js +0 -109
  282. package/dist/lib/autoresearch/stateStore.d.ts +0 -12
  283. package/dist/lib/autoresearch/stateStore.js +0 -164
  284. package/dist/lib/autoresearch/summaryParser.d.ts +0 -16
  285. package/dist/lib/autoresearch/summaryParser.js +0 -95
  286. package/dist/lib/autoresearch/tools.d.ts +0 -27
  287. package/dist/lib/autoresearch/tools.js +0 -618
  288. package/dist/lib/autoresearch/worker.d.ts +0 -71
  289. package/dist/lib/autoresearch/worker.js +0 -418
  290. package/dist/lib/avatar/index.d.ts +0 -26
  291. package/dist/lib/avatar/index.js +0 -86
  292. package/dist/lib/avatar/providers/DIDAvatar.d.ts +0 -49
  293. package/dist/lib/avatar/providers/DIDAvatar.js +0 -502
  294. package/dist/lib/avatar/providers/HeyGenAvatar.d.ts +0 -30
  295. package/dist/lib/avatar/providers/HeyGenAvatar.js +0 -338
  296. package/dist/lib/avatar/providers/ReplicateAvatar.d.ts +0 -36
  297. package/dist/lib/avatar/providers/ReplicateAvatar.js +0 -268
  298. package/dist/lib/client/aiSdkAdapter.d.ts +0 -196
  299. package/dist/lib/client/aiSdkAdapter.js +0 -498
  300. package/dist/lib/client/auth.d.ts +0 -248
  301. package/dist/lib/client/auth.js +0 -469
  302. package/dist/lib/client/errors.d.ts +0 -298
  303. package/dist/lib/client/errors.js +0 -553
  304. package/dist/lib/client/httpClient.d.ts +0 -296
  305. package/dist/lib/client/httpClient.js +0 -851
  306. package/dist/lib/client/index.d.ts +0 -103
  307. package/dist/lib/client/index.js +0 -174
  308. package/dist/lib/client/interceptors.d.ts +0 -207
  309. package/dist/lib/client/interceptors.js +0 -620
  310. package/dist/lib/client/reactHooks.d.ts +0 -238
  311. package/dist/lib/client/reactHooks.js +0 -1168
  312. package/dist/lib/client/sseClient.d.ts +0 -115
  313. package/dist/lib/client/sseClient.js +0 -575
  314. package/dist/lib/client/streamingClient.d.ts +0 -255
  315. package/dist/lib/client/streamingClient.js +0 -963
  316. package/dist/lib/client/wsClient.d.ts +0 -127
  317. package/dist/lib/client/wsClient.js +0 -450
  318. package/dist/lib/config/configManager.d.ts +0 -60
  319. package/dist/lib/config/configManager.js +0 -304
  320. package/dist/lib/config/conversationMemory.d.ts +0 -51
  321. package/dist/lib/config/conversationMemory.js +0 -87
  322. package/dist/lib/config/modelSpecificPrompts.d.ts +0 -9
  323. package/dist/lib/config/modelSpecificPrompts.js +0 -39
  324. package/dist/lib/config/taskClassificationConfig.d.ts +0 -51
  325. package/dist/lib/config/taskClassificationConfig.js +0 -149
  326. package/dist/lib/constants/contextWindows.d.ts +0 -89
  327. package/dist/lib/constants/contextWindows.js +0 -568
  328. package/dist/lib/constants/enums.d.ts +0 -979
  329. package/dist/lib/constants/enums.js +0 -1247
  330. package/dist/lib/constants/index.d.ts +0 -184
  331. package/dist/lib/constants/index.js +0 -209
  332. package/dist/lib/constants/networkErrorCodes.d.ts +0 -14
  333. package/dist/lib/constants/networkErrorCodes.js +0 -22
  334. package/dist/lib/constants/performance.d.ts +0 -366
  335. package/dist/lib/constants/performance.js +0 -390
  336. package/dist/lib/constants/retry.d.ts +0 -224
  337. package/dist/lib/constants/retry.js +0 -267
  338. package/dist/lib/constants/timeouts.d.ts +0 -225
  339. package/dist/lib/constants/timeouts.js +0 -183
  340. package/dist/lib/constants/tokens.d.ts +0 -294
  341. package/dist/lib/constants/tokens.js +0 -381
  342. package/dist/lib/constants/videoErrors.d.ts +0 -49
  343. package/dist/lib/constants/videoErrors.js +0 -51
  344. package/dist/lib/context/anthropicLoopGuard.d.ts +0 -47
  345. package/dist/lib/context/anthropicLoopGuard.js +0 -186
  346. package/dist/lib/context/budgetChecker.d.ts +0 -33
  347. package/dist/lib/context/budgetChecker.js +0 -132
  348. package/dist/lib/context/contextCompactor.d.ts +0 -19
  349. package/dist/lib/context/contextCompactor.js +0 -258
  350. package/dist/lib/context/effectiveHistory.d.ts +0 -52
  351. package/dist/lib/context/effectiveHistory.js +0 -106
  352. package/dist/lib/context/emergencyTruncation.d.ts +0 -21
  353. package/dist/lib/context/emergencyTruncation.js +0 -89
  354. package/dist/lib/context/errorDetection.d.ts +0 -36
  355. package/dist/lib/context/errorDetection.js +0 -190
  356. package/dist/lib/context/errors.d.ts +0 -19
  357. package/dist/lib/context/errors.js +0 -22
  358. package/dist/lib/context/fileSummarizationService.d.ts +0 -45
  359. package/dist/lib/context/fileSummarizationService.js +0 -256
  360. package/dist/lib/context/fileSummarizer.d.ts +0 -55
  361. package/dist/lib/context/fileSummarizer.js +0 -146
  362. package/dist/lib/context/fileTokenBudget.d.ts +0 -52
  363. package/dist/lib/context/fileTokenBudget.js +0 -128
  364. package/dist/lib/context/geminiLoopGuard.d.ts +0 -54
  365. package/dist/lib/context/geminiLoopGuard.js +0 -141
  366. package/dist/lib/context/loopGuardCore.d.ts +0 -43
  367. package/dist/lib/context/loopGuardCore.js +0 -146
  368. package/dist/lib/context/openaiCompatLoopGuard.d.ts +0 -42
  369. package/dist/lib/context/openaiCompatLoopGuard.js +0 -173
  370. package/dist/lib/context/prompts/summarizationPrompt.d.ts +0 -16
  371. package/dist/lib/context/prompts/summarizationPrompt.js +0 -118
  372. package/dist/lib/context/stages/fileReadDeduplicator.d.ts +0 -8
  373. package/dist/lib/context/stages/fileReadDeduplicator.js +0 -67
  374. package/dist/lib/context/stages/slidingWindowTruncator.d.ts +0 -15
  375. package/dist/lib/context/stages/slidingWindowTruncator.js +0 -237
  376. package/dist/lib/context/stages/structuredSummarizer.d.ts +0 -8
  377. package/dist/lib/context/stages/structuredSummarizer.js +0 -123
  378. package/dist/lib/context/stages/toolOutputPruner.d.ts +0 -8
  379. package/dist/lib/context/stages/toolOutputPruner.js +0 -53
  380. package/dist/lib/context/stepBudgetGuard.d.ts +0 -61
  381. package/dist/lib/context/stepBudgetGuard.js +0 -358
  382. package/dist/lib/context/summarizationEngine.d.ts +0 -45
  383. package/dist/lib/context/summarizationEngine.js +0 -162
  384. package/dist/lib/context/toolOutputLimits.d.ts +0 -36
  385. package/dist/lib/context/toolOutputLimits.js +0 -95
  386. package/dist/lib/context/toolPairRepair.d.ts +0 -43
  387. package/dist/lib/context/toolPairRepair.js +0 -242
  388. package/dist/lib/core/analytics.d.ts +0 -11
  389. package/dist/lib/core/analytics.js +0 -117
  390. package/dist/lib/core/baseProvider.d.ts +0 -500
  391. package/dist/lib/core/baseProvider.js +0 -2081
  392. package/dist/lib/core/constants.d.ts +0 -146
  393. package/dist/lib/core/constants.js +0 -278
  394. package/dist/lib/core/conversationMemoryFactory.d.ts +0 -19
  395. package/dist/lib/core/conversationMemoryFactory.js +0 -147
  396. package/dist/lib/core/conversationMemoryInitializer.d.ts +0 -14
  397. package/dist/lib/core/conversationMemoryInitializer.js +0 -129
  398. package/dist/lib/core/conversationMemoryManager.d.ts +0 -110
  399. package/dist/lib/core/conversationMemoryManager.js +0 -471
  400. package/dist/lib/core/dynamicModels.d.ts +0 -89
  401. package/dist/lib/core/dynamicModels.js +0 -337
  402. package/dist/lib/core/evaluation.d.ts +0 -18
  403. package/dist/lib/core/evaluation.js +0 -310
  404. package/dist/lib/core/evaluationProviders.d.ts +0 -60
  405. package/dist/lib/core/evaluationProviders.js +0 -249
  406. package/dist/lib/core/factory.d.ts +0 -54
  407. package/dist/lib/core/factory.js +0 -364
  408. package/dist/lib/core/geminiLoopAdapter.d.ts +0 -20
  409. package/dist/lib/core/geminiLoopAdapter.js +0 -171
  410. package/dist/lib/core/handlerRegistry.d.ts +0 -29
  411. package/dist/lib/core/handlerRegistry.js +0 -62
  412. package/dist/lib/core/infrastructure/baseError.d.ts +0 -21
  413. package/dist/lib/core/infrastructure/baseError.js +0 -23
  414. package/dist/lib/core/infrastructure/baseFactory.d.ts +0 -16
  415. package/dist/lib/core/infrastructure/baseFactory.js +0 -55
  416. package/dist/lib/core/infrastructure/baseRegistry.d.ts +0 -19
  417. package/dist/lib/core/infrastructure/baseRegistry.js +0 -54
  418. package/dist/lib/core/infrastructure/index.d.ts +0 -5
  419. package/dist/lib/core/infrastructure/index.js +0 -6
  420. package/dist/lib/core/infrastructure/retry.d.ts +0 -2
  421. package/dist/lib/core/infrastructure/retry.js +0 -21
  422. package/dist/lib/core/infrastructure/typedEventEmitter.d.ts +0 -8
  423. package/dist/lib/core/infrastructure/typedEventEmitter.js +0 -24
  424. package/dist/lib/core/loopEngine.d.ts +0 -21
  425. package/dist/lib/core/loopEngine.js +0 -272
  426. package/dist/lib/core/modelConfiguration.d.ts +0 -179
  427. package/dist/lib/core/modelConfiguration.js +0 -549
  428. package/dist/lib/core/modules/GenerationHandler.d.ts +0 -135
  429. package/dist/lib/core/modules/GenerationHandler.js +0 -1028
  430. package/dist/lib/core/modules/MessageBuilder.d.ts +0 -24
  431. package/dist/lib/core/modules/MessageBuilder.js +0 -311
  432. package/dist/lib/core/modules/StreamHandler.d.ts +0 -70
  433. package/dist/lib/core/modules/StreamHandler.js +0 -229
  434. package/dist/lib/core/modules/TelemetryHandler.d.ts +0 -70
  435. package/dist/lib/core/modules/TelemetryHandler.js +0 -229
  436. package/dist/lib/core/modules/ToolsManager.d.ts +0 -105
  437. package/dist/lib/core/modules/ToolsManager.js +0 -737
  438. package/dist/lib/core/modules/Utilities.d.ts +0 -90
  439. package/dist/lib/core/modules/Utilities.js +0 -347
  440. package/dist/lib/core/modules/structuredOutputPolicy.d.ts +0 -91
  441. package/dist/lib/core/modules/structuredOutputPolicy.js +0 -136
  442. package/dist/lib/core/nativeToolFormat.d.ts +0 -33
  443. package/dist/lib/core/nativeToolFormat.js +0 -31
  444. package/dist/lib/core/redisConversationMemoryManager.d.ts +0 -235
  445. package/dist/lib/core/redisConversationMemoryManager.js +0 -1724
  446. package/dist/lib/core/serviceRegistry.d.ts +0 -40
  447. package/dist/lib/core/serviceRegistry.js +0 -113
  448. package/dist/lib/core/streamAnalytics.d.ts +0 -27
  449. package/dist/lib/core/streamAnalytics.js +0 -132
  450. package/dist/lib/core/streamChannel.d.ts +0 -10
  451. package/dist/lib/core/streamChannel.js +0 -77
  452. package/dist/lib/core/toolDedup.d.ts +0 -51
  453. package/dist/lib/core/toolDedup.js +0 -197
  454. package/dist/lib/core/toolEvents.d.ts +0 -2
  455. package/dist/lib/core/toolEvents.js +0 -8
  456. package/dist/lib/core/toolExecutionRecorder.d.ts +0 -76
  457. package/dist/lib/core/toolExecutionRecorder.js +0 -261
  458. package/dist/lib/core/toolRouting.d.ts +0 -68
  459. package/dist/lib/core/toolRouting.js +0 -496
  460. package/dist/lib/core/toolRoutingCache.d.ts +0 -64
  461. package/dist/lib/core/toolRoutingCache.js +0 -155
  462. package/dist/lib/core/toolRoutingEmbedding.d.ts +0 -112
  463. package/dist/lib/core/toolRoutingEmbedding.js +0 -323
  464. package/dist/lib/dynamic/dynamicResolver.d.ts +0 -282
  465. package/dist/lib/dynamic/dynamicResolver.js +0 -634
  466. package/dist/lib/dynamic/index.d.ts +0 -10
  467. package/dist/lib/dynamic/index.js +0 -13
  468. package/dist/lib/dynamic/resolution.d.ts +0 -17
  469. package/dist/lib/dynamic/resolution.js +0 -22
  470. package/dist/lib/evaluation/BatchEvaluator.d.ts +0 -65
  471. package/dist/lib/evaluation/BatchEvaluator.js +0 -271
  472. package/dist/lib/evaluation/EvaluationAggregator.d.ts +0 -156
  473. package/dist/lib/evaluation/EvaluationAggregator.js +0 -378
  474. package/dist/lib/evaluation/EvaluatorFactory.d.ts +0 -102
  475. package/dist/lib/evaluation/EvaluatorFactory.js +0 -281
  476. package/dist/lib/evaluation/EvaluatorRegistry.d.ts +0 -111
  477. package/dist/lib/evaluation/EvaluatorRegistry.js +0 -185
  478. package/dist/lib/evaluation/contextBuilder.d.ts +0 -44
  479. package/dist/lib/evaluation/contextBuilder.js +0 -132
  480. package/dist/lib/evaluation/errors/EvaluationError.d.ts +0 -161
  481. package/dist/lib/evaluation/errors/EvaluationError.js +0 -207
  482. package/dist/lib/evaluation/errors/index.d.ts +0 -4
  483. package/dist/lib/evaluation/errors/index.js +0 -5
  484. package/dist/lib/evaluation/hooks/index.d.ts +0 -6
  485. package/dist/lib/evaluation/hooks/index.js +0 -7
  486. package/dist/lib/evaluation/hooks/langfuseAdapter.d.ts +0 -62
  487. package/dist/lib/evaluation/hooks/langfuseAdapter.js +0 -173
  488. package/dist/lib/evaluation/hooks/observabilityHooks.d.ts +0 -77
  489. package/dist/lib/evaluation/hooks/observabilityHooks.js +0 -187
  490. package/dist/lib/evaluation/index.d.ts +0 -41
  491. package/dist/lib/evaluation/index.js +0 -78
  492. package/dist/lib/evaluation/pipeline/evaluationPipeline.d.ts +0 -83
  493. package/dist/lib/evaluation/pipeline/evaluationPipeline.js +0 -397
  494. package/dist/lib/evaluation/pipeline/index.d.ts +0 -8
  495. package/dist/lib/evaluation/pipeline/index.js +0 -9
  496. package/dist/lib/evaluation/pipeline/pipelineBuilder.d.ts +0 -126
  497. package/dist/lib/evaluation/pipeline/pipelineBuilder.js +0 -261
  498. package/dist/lib/evaluation/pipeline/presets.d.ts +0 -66
  499. package/dist/lib/evaluation/pipeline/presets.js +0 -225
  500. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.d.ts +0 -46
  501. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.js +0 -242
  502. package/dist/lib/evaluation/pipeline/strategies/index.d.ts +0 -6
  503. package/dist/lib/evaluation/pipeline/strategies/index.js +0 -7
  504. package/dist/lib/evaluation/pipeline/strategies/samplingStrategy.d.ts +0 -76
  505. package/dist/lib/evaluation/pipeline/strategies/samplingStrategy.js +0 -247
  506. package/dist/lib/evaluation/prompts.d.ts +0 -22
  507. package/dist/lib/evaluation/prompts.js +0 -74
  508. package/dist/lib/evaluation/ragasEvaluator.d.ts +0 -28
  509. package/dist/lib/evaluation/ragasEvaluator.js +0 -127
  510. package/dist/lib/evaluation/reporting/index.d.ts +0 -6
  511. package/dist/lib/evaluation/reporting/index.js +0 -7
  512. package/dist/lib/evaluation/reporting/metricsCollector.d.ts +0 -88
  513. package/dist/lib/evaluation/reporting/metricsCollector.js +0 -286
  514. package/dist/lib/evaluation/reporting/reportGenerator.d.ts +0 -57
  515. package/dist/lib/evaluation/reporting/reportGenerator.js +0 -375
  516. package/dist/lib/evaluation/retryManager.d.ts +0 -39
  517. package/dist/lib/evaluation/retryManager.js +0 -79
  518. package/dist/lib/evaluation/scorers/baseScorer.d.ts +0 -82
  519. package/dist/lib/evaluation/scorers/baseScorer.js +0 -233
  520. package/dist/lib/evaluation/scorers/customScorerUtils.d.ts +0 -86
  521. package/dist/lib/evaluation/scorers/customScorerUtils.js +0 -382
  522. package/dist/lib/evaluation/scorers/index.d.ts +0 -10
  523. package/dist/lib/evaluation/scorers/index.js +0 -17
  524. package/dist/lib/evaluation/scorers/llm/answerRelevancyScorer.d.ts +0 -12
  525. package/dist/lib/evaluation/scorers/llm/answerRelevancyScorer.js +0 -100
  526. package/dist/lib/evaluation/scorers/llm/baseLLMScorer.d.ts +0 -69
  527. package/dist/lib/evaluation/scorers/llm/baseLLMScorer.js +0 -282
  528. package/dist/lib/evaluation/scorers/llm/biasDetectionScorer.d.ts +0 -12
  529. package/dist/lib/evaluation/scorers/llm/biasDetectionScorer.js +0 -128
  530. package/dist/lib/evaluation/scorers/llm/contextPrecisionScorer.d.ts +0 -12
  531. package/dist/lib/evaluation/scorers/llm/contextPrecisionScorer.js +0 -93
  532. package/dist/lib/evaluation/scorers/llm/contextRelevancyScorer.d.ts +0 -12
  533. package/dist/lib/evaluation/scorers/llm/contextRelevancyScorer.js +0 -108
  534. package/dist/lib/evaluation/scorers/llm/faithfulnessScorer.d.ts +0 -12
  535. package/dist/lib/evaluation/scorers/llm/faithfulnessScorer.js +0 -122
  536. package/dist/lib/evaluation/scorers/llm/hallucinationScorer.d.ts +0 -12
  537. package/dist/lib/evaluation/scorers/llm/hallucinationScorer.js +0 -141
  538. package/dist/lib/evaluation/scorers/llm/index.d.ts +0 -15
  539. package/dist/lib/evaluation/scorers/llm/index.js +0 -17
  540. package/dist/lib/evaluation/scorers/llm/promptAlignmentScorer.d.ts +0 -12
  541. package/dist/lib/evaluation/scorers/llm/promptAlignmentScorer.js +0 -107
  542. package/dist/lib/evaluation/scorers/llm/summarizationScorer.d.ts +0 -12
  543. package/dist/lib/evaluation/scorers/llm/summarizationScorer.js +0 -115
  544. package/dist/lib/evaluation/scorers/llm/toneConsistencyScorer.d.ts +0 -12
  545. package/dist/lib/evaluation/scorers/llm/toneConsistencyScorer.js +0 -107
  546. package/dist/lib/evaluation/scorers/llm/toxicityScorer.d.ts +0 -12
  547. package/dist/lib/evaluation/scorers/llm/toxicityScorer.js +0 -122
  548. package/dist/lib/evaluation/scorers/rule/baseRuleScorer.d.ts +0 -77
  549. package/dist/lib/evaluation/scorers/rule/baseRuleScorer.js +0 -234
  550. package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.d.ts +0 -81
  551. package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.js +0 -353
  552. package/dist/lib/evaluation/scorers/rule/formatScorer.d.ts +0 -107
  553. package/dist/lib/evaluation/scorers/rule/formatScorer.js +0 -471
  554. package/dist/lib/evaluation/scorers/rule/index.d.ts +0 -9
  555. package/dist/lib/evaluation/scorers/rule/index.js +0 -11
  556. package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.d.ts +0 -66
  557. package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.js +0 -348
  558. package/dist/lib/evaluation/scorers/rule/lengthScorer.d.ts +0 -74
  559. package/dist/lib/evaluation/scorers/rule/lengthScorer.js +0 -352
  560. package/dist/lib/evaluation/scorers/scorerBuilder.d.ts +0 -160
  561. package/dist/lib/evaluation/scorers/scorerBuilder.js +0 -421
  562. package/dist/lib/evaluation/scorers/scorerRegistry.d.ts +0 -65
  563. package/dist/lib/evaluation/scorers/scorerRegistry.js +0 -540
  564. package/dist/lib/evaluation/scoring.d.ts +0 -15
  565. package/dist/lib/evaluation/scoring.js +0 -61
  566. package/dist/lib/factories/providerDescriptors.d.ts +0 -18
  567. package/dist/lib/factories/providerDescriptors.js +0 -547
  568. package/dist/lib/factories/providerFactory.d.ts +0 -87
  569. package/dist/lib/factories/providerFactory.js +0 -199
  570. package/dist/lib/factories/providerRegistry.d.ts +0 -58
  571. package/dist/lib/factories/providerRegistry.js +0 -549
  572. package/dist/lib/features/ppt/constants.d.ts +0 -121
  573. package/dist/lib/features/ppt/constants.js +0 -897
  574. package/dist/lib/features/ppt/contentPlanner.d.ts +0 -47
  575. package/dist/lib/features/ppt/contentPlanner.js +0 -558
  576. package/dist/lib/features/ppt/index.d.ts +0 -11
  577. package/dist/lib/features/ppt/index.js +0 -33
  578. package/dist/lib/features/ppt/pptError.d.ts +0 -38
  579. package/dist/lib/features/ppt/pptError.js +0 -54
  580. package/dist/lib/features/ppt/presentationOrchestrator.d.ts +0 -37
  581. package/dist/lib/features/ppt/presentationOrchestrator.js +0 -231
  582. package/dist/lib/features/ppt/slideGenerator.d.ts +0 -56
  583. package/dist/lib/features/ppt/slideGenerator.js +0 -542
  584. package/dist/lib/features/ppt/slideRenderers.d.ts +0 -347
  585. package/dist/lib/features/ppt/slideRenderers.js +0 -2384
  586. package/dist/lib/features/ppt/slideTypeInference.d.ts +0 -91
  587. package/dist/lib/features/ppt/slideTypeInference.js +0 -406
  588. package/dist/lib/features/ppt/utils.d.ts +0 -103
  589. package/dist/lib/features/ppt/utils.js +0 -446
  590. package/dist/lib/files/fileReferenceRegistry.d.ts +0 -275
  591. package/dist/lib/files/fileReferenceRegistry.js +0 -1559
  592. package/dist/lib/files/fileTools.d.ts +0 -176
  593. package/dist/lib/files/fileTools.js +0 -435
  594. package/dist/lib/files/index.d.ts +0 -13
  595. package/dist/lib/files/index.js +0 -14
  596. package/dist/lib/files/streamingReader.d.ts +0 -93
  597. package/dist/lib/files/streamingReader.js +0 -322
  598. package/dist/lib/hitl/hitlErrors.d.ts +0 -38
  599. package/dist/lib/hitl/hitlErrors.js +0 -55
  600. package/dist/lib/hitl/hitlManager.d.ts +0 -100
  601. package/dist/lib/hitl/hitlManager.js +0 -461
  602. package/dist/lib/hitl/index.d.ts +0 -7
  603. package/dist/lib/hitl/index.js +0 -10
  604. package/dist/lib/image-gen/ImageGenService.d.ts +0 -146
  605. package/dist/lib/image-gen/ImageGenService.js +0 -349
  606. package/dist/lib/image-gen/imageGenTools.d.ts +0 -109
  607. package/dist/lib/image-gen/imageGenTools.js +0 -305
  608. package/dist/lib/image-gen/index.d.ts +0 -45
  609. package/dist/lib/image-gen/index.js +0 -49
  610. package/dist/lib/index.d.ts +0 -447
  611. package/dist/lib/index.js +0 -748
  612. package/dist/lib/knowledge/context.d.ts +0 -18
  613. package/dist/lib/knowledge/context.js +0 -92
  614. package/dist/lib/knowledge/defaults.d.ts +0 -24
  615. package/dist/lib/knowledge/defaults.js +0 -30
  616. package/dist/lib/knowledge/engine.d.ts +0 -35
  617. package/dist/lib/knowledge/engine.js +0 -180
  618. package/dist/lib/knowledge/index.d.ts +0 -15
  619. package/dist/lib/knowledge/index.js +0 -16
  620. package/dist/lib/knowledge/indexCache.d.ts +0 -19
  621. package/dist/lib/knowledge/indexCache.js +0 -110
  622. package/dist/lib/knowledge/knowledgeIndex.d.ts +0 -41
  623. package/dist/lib/knowledge/knowledgeIndex.js +0 -205
  624. package/dist/lib/knowledge/normalize.d.ts +0 -32
  625. package/dist/lib/knowledge/normalize.js +0 -75
  626. package/dist/lib/knowledge/resolve.d.ts +0 -18
  627. package/dist/lib/knowledge/resolve.js +0 -157
  628. package/dist/lib/knowledge/retrieval.d.ts +0 -16
  629. package/dist/lib/knowledge/retrieval.js +0 -222
  630. package/dist/lib/mcp/agentExposure.d.ts +0 -83
  631. package/dist/lib/mcp/agentExposure.js +0 -357
  632. package/dist/lib/mcp/auth/index.d.ts +0 -6
  633. package/dist/lib/mcp/auth/index.js +0 -12
  634. package/dist/lib/mcp/auth/oauthClientProvider.d.ts +0 -93
  635. package/dist/lib/mcp/auth/oauthClientProvider.js +0 -331
  636. package/dist/lib/mcp/auth/tokenStorage.d.ts +0 -56
  637. package/dist/lib/mcp/auth/tokenStorage.js +0 -135
  638. package/dist/lib/mcp/batching/index.d.ts +0 -1
  639. package/dist/lib/mcp/batching/index.js +0 -2
  640. package/dist/lib/mcp/batching/requestBatcher.d.ts +0 -130
  641. package/dist/lib/mcp/batching/requestBatcher.js +0 -468
  642. package/dist/lib/mcp/caching/index.d.ts +0 -1
  643. package/dist/lib/mcp/caching/index.js +0 -2
  644. package/dist/lib/mcp/caching/toolCache.d.ts +0 -154
  645. package/dist/lib/mcp/caching/toolCache.js +0 -434
  646. package/dist/lib/mcp/elicitation/elicitationManager.d.ts +0 -169
  647. package/dist/lib/mcp/elicitation/elicitationManager.js +0 -377
  648. package/dist/lib/mcp/elicitation/index.d.ts +0 -1
  649. package/dist/lib/mcp/elicitation/index.js +0 -3
  650. package/dist/lib/mcp/elicitationProtocol.d.ts +0 -139
  651. package/dist/lib/mcp/elicitationProtocol.js +0 -376
  652. package/dist/lib/mcp/enhancedToolDiscovery.d.ts +0 -125
  653. package/dist/lib/mcp/enhancedToolDiscovery.js +0 -482
  654. package/dist/lib/mcp/externalServerManager.d.ts +0 -189
  655. package/dist/lib/mcp/externalServerManager.js +0 -1525
  656. package/dist/lib/mcp/factory.d.ts +0 -60
  657. package/dist/lib/mcp/factory.js +0 -162
  658. package/dist/lib/mcp/flexibleToolValidator.d.ts +0 -46
  659. package/dist/lib/mcp/flexibleToolValidator.js +0 -162
  660. package/dist/lib/mcp/httpRateLimiter.d.ts +0 -152
  661. package/dist/lib/mcp/httpRateLimiter.js +0 -386
  662. package/dist/lib/mcp/httpRetryHandler.d.ts +0 -62
  663. package/dist/lib/mcp/httpRetryHandler.js +0 -180
  664. package/dist/lib/mcp/index.d.ts +0 -60
  665. package/dist/lib/mcp/index.js +0 -82
  666. package/dist/lib/mcp/mcpCircuitBreaker.d.ts +0 -123
  667. package/dist/lib/mcp/mcpCircuitBreaker.js +0 -428
  668. package/dist/lib/mcp/mcpClientFactory.d.ts +0 -109
  669. package/dist/lib/mcp/mcpClientFactory.js +0 -714
  670. package/dist/lib/mcp/mcpOutputNormalizer.d.ts +0 -47
  671. package/dist/lib/mcp/mcpOutputNormalizer.js +0 -183
  672. package/dist/lib/mcp/mcpRegistryClient.d.ts +0 -129
  673. package/dist/lib/mcp/mcpRegistryClient.js +0 -489
  674. package/dist/lib/mcp/mcpServerBase.d.ts +0 -162
  675. package/dist/lib/mcp/mcpServerBase.js +0 -377
  676. package/dist/lib/mcp/multiServerManager.d.ts +0 -182
  677. package/dist/lib/mcp/multiServerManager.js +0 -580
  678. package/dist/lib/mcp/registry.d.ts +0 -94
  679. package/dist/lib/mcp/registry.js +0 -159
  680. package/dist/lib/mcp/routing/index.d.ts +0 -1
  681. package/dist/lib/mcp/routing/index.js +0 -2
  682. package/dist/lib/mcp/routing/toolRouter.d.ts +0 -110
  683. package/dist/lib/mcp/routing/toolRouter.js +0 -417
  684. package/dist/lib/mcp/serverCapabilities.d.ts +0 -175
  685. package/dist/lib/mcp/serverCapabilities.js +0 -503
  686. package/dist/lib/mcp/servers/agent/directToolsServer.d.ts +0 -8
  687. package/dist/lib/mcp/servers/agent/directToolsServer.js +0 -152
  688. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.d.ts +0 -6
  689. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +0 -364
  690. package/dist/lib/mcp/servers/aiProviders/aiCoreServer.d.ts +0 -10
  691. package/dist/lib/mcp/servers/aiProviders/aiCoreServer.js +0 -232
  692. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.d.ts +0 -5
  693. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +0 -584
  694. package/dist/lib/mcp/servers/utilities/utilityServer.d.ts +0 -8
  695. package/dist/lib/mcp/servers/utilities/utilityServer.js +0 -327
  696. package/dist/lib/mcp/toolAnnotations.d.ts +0 -57
  697. package/dist/lib/mcp/toolAnnotations.js +0 -240
  698. package/dist/lib/mcp/toolConverter.d.ts +0 -87
  699. package/dist/lib/mcp/toolConverter.js +0 -259
  700. package/dist/lib/mcp/toolDiscoveryService.d.ts +0 -144
  701. package/dist/lib/mcp/toolDiscoveryService.js +0 -978
  702. package/dist/lib/mcp/toolIntegration.d.ts +0 -92
  703. package/dist/lib/mcp/toolIntegration.js +0 -335
  704. package/dist/lib/mcp/toolRegistry.d.ts +0 -151
  705. package/dist/lib/mcp/toolRegistry.js +0 -755
  706. package/dist/lib/memory/hippocampusInitializer.d.ts +0 -2
  707. package/dist/lib/memory/hippocampusInitializer.js +0 -50
  708. package/dist/lib/memory/memoryRetrievalTools.d.ts +0 -13
  709. package/dist/lib/memory/memoryRetrievalTools.js +0 -267
  710. package/dist/lib/middleware/builtin/analytics.d.ts +0 -16
  711. package/dist/lib/middleware/builtin/analytics.js +0 -133
  712. package/dist/lib/middleware/builtin/autoEvaluation.d.ts +0 -11
  713. package/dist/lib/middleware/builtin/autoEvaluation.js +0 -201
  714. package/dist/lib/middleware/builtin/guardrails.d.ts +0 -7
  715. package/dist/lib/middleware/builtin/guardrails.js +0 -110
  716. package/dist/lib/middleware/builtin/lifecycle.d.ts +0 -2
  717. package/dist/lib/middleware/builtin/lifecycle.js +0 -161
  718. package/dist/lib/middleware/factory.d.ts +0 -69
  719. package/dist/lib/middleware/factory.js +0 -328
  720. package/dist/lib/middleware/index.d.ts +0 -11
  721. package/dist/lib/middleware/index.js +0 -17
  722. package/dist/lib/middleware/registry.d.ts +0 -76
  723. package/dist/lib/middleware/registry.js +0 -296
  724. package/dist/lib/middleware/utils/guardrailsUtils.d.ts +0 -50
  725. package/dist/lib/middleware/utils/guardrailsUtils.js +0 -397
  726. package/dist/lib/models/anthropicModels.d.ts +0 -261
  727. package/dist/lib/models/anthropicModels.js +0 -556
  728. package/dist/lib/models/manifestRegistry.d.ts +0 -33
  729. package/dist/lib/models/manifestRegistry.js +0 -174
  730. package/dist/lib/models/manifests/anthropic.d.ts +0 -9
  731. package/dist/lib/models/manifests/anthropic.js +0 -346
  732. package/dist/lib/models/manifests/azure.d.ts +0 -2
  733. package/dist/lib/models/manifests/azure.js +0 -87
  734. package/dist/lib/models/manifests/bedrock.d.ts +0 -2
  735. package/dist/lib/models/manifests/bedrock.js +0 -75
  736. package/dist/lib/models/manifests/cloudflare.d.ts +0 -8
  737. package/dist/lib/models/manifests/cloudflare.js +0 -19
  738. package/dist/lib/models/manifests/cohere.d.ts +0 -8
  739. package/dist/lib/models/manifests/cohere.js +0 -19
  740. package/dist/lib/models/manifests/deepseek.d.ts +0 -8
  741. package/dist/lib/models/manifests/deepseek.js +0 -19
  742. package/dist/lib/models/manifests/fireworks.d.ts +0 -8
  743. package/dist/lib/models/manifests/fireworks.js +0 -19
  744. package/dist/lib/models/manifests/google-ai.d.ts +0 -2
  745. package/dist/lib/models/manifests/google-ai.js +0 -28
  746. package/dist/lib/models/manifests/groq.d.ts +0 -8
  747. package/dist/lib/models/manifests/groq.js +0 -19
  748. package/dist/lib/models/manifests/huggingface.d.ts +0 -8
  749. package/dist/lib/models/manifests/huggingface.js +0 -19
  750. package/dist/lib/models/manifests/ideogram.d.ts +0 -8
  751. package/dist/lib/models/manifests/ideogram.js +0 -19
  752. package/dist/lib/models/manifests/jina.d.ts +0 -8
  753. package/dist/lib/models/manifests/jina.js +0 -19
  754. package/dist/lib/models/manifests/litellm.d.ts +0 -8
  755. package/dist/lib/models/manifests/litellm.js +0 -19
  756. package/dist/lib/models/manifests/llamacpp.d.ts +0 -8
  757. package/dist/lib/models/manifests/llamacpp.js +0 -19
  758. package/dist/lib/models/manifests/lm-studio.d.ts +0 -8
  759. package/dist/lib/models/manifests/lm-studio.js +0 -19
  760. package/dist/lib/models/manifests/mistral.d.ts +0 -2
  761. package/dist/lib/models/manifests/mistral.js +0 -50
  762. package/dist/lib/models/manifests/nvidia-nim.d.ts +0 -8
  763. package/dist/lib/models/manifests/nvidia-nim.js +0 -19
  764. package/dist/lib/models/manifests/ollama.d.ts +0 -2
  765. package/dist/lib/models/manifests/ollama.js +0 -72
  766. package/dist/lib/models/manifests/openai-compatible.d.ts +0 -8
  767. package/dist/lib/models/manifests/openai-compatible.js +0 -19
  768. package/dist/lib/models/manifests/openai.d.ts +0 -11
  769. package/dist/lib/models/manifests/openai.js +0 -560
  770. package/dist/lib/models/manifests/openrouter.d.ts +0 -8
  771. package/dist/lib/models/manifests/openrouter.js +0 -19
  772. package/dist/lib/models/manifests/perplexity.d.ts +0 -8
  773. package/dist/lib/models/manifests/perplexity.js +0 -19
  774. package/dist/lib/models/manifests/recraft.d.ts +0 -8
  775. package/dist/lib/models/manifests/recraft.js +0 -19
  776. package/dist/lib/models/manifests/replicate.d.ts +0 -8
  777. package/dist/lib/models/manifests/replicate.js +0 -19
  778. package/dist/lib/models/manifests/sagemaker.d.ts +0 -8
  779. package/dist/lib/models/manifests/sagemaker.js +0 -19
  780. package/dist/lib/models/manifests/stability.d.ts +0 -8
  781. package/dist/lib/models/manifests/stability.js +0 -19
  782. package/dist/lib/models/manifests/together-ai.d.ts +0 -8
  783. package/dist/lib/models/manifests/together-ai.js +0 -19
  784. package/dist/lib/models/manifests/vertex.d.ts +0 -8
  785. package/dist/lib/models/manifests/vertex.js +0 -19
  786. package/dist/lib/models/manifests/voyage.d.ts +0 -8
  787. package/dist/lib/models/manifests/voyage.js +0 -19
  788. package/dist/lib/models/manifests/xai.d.ts +0 -8
  789. package/dist/lib/models/manifests/xai.js +0 -19
  790. package/dist/lib/models/modelRegistry.d.ts +0 -74
  791. package/dist/lib/models/modelRegistry.js +0 -2695
  792. package/dist/lib/models/modelResolver.d.ts +0 -74
  793. package/dist/lib/models/modelResolver.js +0 -470
  794. package/dist/lib/music/index.d.ts +0 -27
  795. package/dist/lib/music/index.js +0 -94
  796. package/dist/lib/music/providers/BeatovenMusic.d.ts +0 -31
  797. package/dist/lib/music/providers/BeatovenMusic.js +0 -334
  798. package/dist/lib/music/providers/ElevenLabsMusic.d.ts +0 -30
  799. package/dist/lib/music/providers/ElevenLabsMusic.js +0 -169
  800. package/dist/lib/music/providers/LyriaMusic.d.ts +0 -29
  801. package/dist/lib/music/providers/LyriaMusic.js +0 -173
  802. package/dist/lib/music/providers/ReplicateMusic.d.ts +0 -31
  803. package/dist/lib/music/providers/ReplicateMusic.js +0 -262
  804. package/dist/lib/neurolink.d.ts +0 -2662
  805. package/dist/lib/neurolink.js +0 -12946
  806. package/dist/lib/observability/exporterRegistry.d.ts +0 -133
  807. package/dist/lib/observability/exporterRegistry.js +0 -414
  808. package/dist/lib/observability/exporters/arizeExporter.d.ts +0 -32
  809. package/dist/lib/observability/exporters/arizeExporter.js +0 -139
  810. package/dist/lib/observability/exporters/baseExporter.d.ts +0 -117
  811. package/dist/lib/observability/exporters/baseExporter.js +0 -191
  812. package/dist/lib/observability/exporters/braintrustExporter.d.ts +0 -30
  813. package/dist/lib/observability/exporters/braintrustExporter.js +0 -155
  814. package/dist/lib/observability/exporters/datadogExporter.d.ts +0 -37
  815. package/dist/lib/observability/exporters/datadogExporter.js +0 -197
  816. package/dist/lib/observability/exporters/index.d.ts +0 -13
  817. package/dist/lib/observability/exporters/index.js +0 -14
  818. package/dist/lib/observability/exporters/laminarExporter.d.ts +0 -48
  819. package/dist/lib/observability/exporters/laminarExporter.js +0 -304
  820. package/dist/lib/observability/exporters/langfuseExporter.d.ts +0 -48
  821. package/dist/lib/observability/exporters/langfuseExporter.js +0 -210
  822. package/dist/lib/observability/exporters/langsmithExporter.d.ts +0 -26
  823. package/dist/lib/observability/exporters/langsmithExporter.js +0 -144
  824. package/dist/lib/observability/exporters/otelExporter.d.ts +0 -39
  825. package/dist/lib/observability/exporters/otelExporter.js +0 -165
  826. package/dist/lib/observability/exporters/posthogExporter.d.ts +0 -48
  827. package/dist/lib/observability/exporters/posthogExporter.js +0 -289
  828. package/dist/lib/observability/exporters/sentryExporter.d.ts +0 -32
  829. package/dist/lib/observability/exporters/sentryExporter.js +0 -167
  830. package/dist/lib/observability/index.d.ts +0 -23
  831. package/dist/lib/observability/index.js +0 -32
  832. package/dist/lib/observability/metricsAggregator.d.ts +0 -126
  833. package/dist/lib/observability/metricsAggregator.js +0 -553
  834. package/dist/lib/observability/otelBridge.d.ts +0 -49
  835. package/dist/lib/observability/otelBridge.js +0 -141
  836. package/dist/lib/observability/retryPolicy.d.ts +0 -154
  837. package/dist/lib/observability/retryPolicy.js +0 -384
  838. package/dist/lib/observability/sampling/index.d.ts +0 -4
  839. package/dist/lib/observability/sampling/index.js +0 -5
  840. package/dist/lib/observability/sampling/samplers.d.ts +0 -104
  841. package/dist/lib/observability/sampling/samplers.js +0 -217
  842. package/dist/lib/observability/spanProcessor.d.ts +0 -115
  843. package/dist/lib/observability/spanProcessor.js +0 -304
  844. package/dist/lib/observability/tokenTracker.d.ts +0 -109
  845. package/dist/lib/observability/tokenTracker.js +0 -416
  846. package/dist/lib/observability/utils/index.d.ts +0 -4
  847. package/dist/lib/observability/utils/index.js +0 -5
  848. package/dist/lib/observability/utils/safeMetadata.d.ts +0 -10
  849. package/dist/lib/observability/utils/safeMetadata.js +0 -26
  850. package/dist/lib/observability/utils/spanSerializer.d.ts +0 -119
  851. package/dist/lib/observability/utils/spanSerializer.js +0 -314
  852. package/dist/lib/processors/archive/ArchiveProcessor.d.ts +0 -323
  853. package/dist/lib/processors/archive/ArchiveProcessor.js +0 -1662
  854. package/dist/lib/processors/archive/index.d.ts +0 -33
  855. package/dist/lib/processors/archive/index.js +0 -44
  856. package/dist/lib/processors/archive/zipEntryReader.d.ts +0 -51
  857. package/dist/lib/processors/archive/zipEntryReader.js +0 -81
  858. package/dist/lib/processors/base/BaseFileProcessor.d.ts +0 -309
  859. package/dist/lib/processors/base/BaseFileProcessor.js +0 -769
  860. package/dist/lib/processors/base/index.d.ts +0 -13
  861. package/dist/lib/processors/base/index.js +0 -23
  862. package/dist/lib/processors/cli/fileProcessorCli.d.ts +0 -124
  863. package/dist/lib/processors/cli/fileProcessorCli.js +0 -392
  864. package/dist/lib/processors/cli/index.d.ts +0 -36
  865. package/dist/lib/processors/cli/index.js +0 -53
  866. package/dist/lib/processors/code/ConfigProcessor.d.ts +0 -169
  867. package/dist/lib/processors/code/ConfigProcessor.js +0 -405
  868. package/dist/lib/processors/code/SourceCodeProcessor.d.ts +0 -172
  869. package/dist/lib/processors/code/SourceCodeProcessor.js +0 -309
  870. package/dist/lib/processors/code/index.d.ts +0 -44
  871. package/dist/lib/processors/code/index.js +0 -65
  872. package/dist/lib/processors/config/fileExtensions.d.ts +0 -280
  873. package/dist/lib/processors/config/fileExtensions.js +0 -485
  874. package/dist/lib/processors/config/fileTypeRegistry.d.ts +0 -106
  875. package/dist/lib/processors/config/fileTypeRegistry.js +0 -702
  876. package/dist/lib/processors/config/index.d.ts +0 -33
  877. package/dist/lib/processors/config/index.js +0 -104
  878. package/dist/lib/processors/config/languageMap.d.ts +0 -62
  879. package/dist/lib/processors/config/languageMap.js +0 -414
  880. package/dist/lib/processors/config/mimeConstants.d.ts +0 -373
  881. package/dist/lib/processors/config/mimeConstants.js +0 -348
  882. package/dist/lib/processors/config/sizeLimits.d.ts +0 -198
  883. package/dist/lib/processors/config/sizeLimits.js +0 -262
  884. package/dist/lib/processors/data/JsonProcessor.d.ts +0 -120
  885. package/dist/lib/processors/data/JsonProcessor.js +0 -206
  886. package/dist/lib/processors/data/XmlProcessor.d.ts +0 -158
  887. package/dist/lib/processors/data/XmlProcessor.js +0 -288
  888. package/dist/lib/processors/data/YamlProcessor.d.ts +0 -161
  889. package/dist/lib/processors/data/YamlProcessor.js +0 -297
  890. package/dist/lib/processors/data/index.d.ts +0 -49
  891. package/dist/lib/processors/data/index.js +0 -83
  892. package/dist/lib/processors/document/ExcelProcessor.d.ts +0 -250
  893. package/dist/lib/processors/document/ExcelProcessor.js +0 -615
  894. package/dist/lib/processors/document/OpenDocumentProcessor.d.ts +0 -67
  895. package/dist/lib/processors/document/OpenDocumentProcessor.js +0 -236
  896. package/dist/lib/processors/document/PptxProcessor.d.ts +0 -77
  897. package/dist/lib/processors/document/PptxProcessor.js +0 -262
  898. package/dist/lib/processors/document/RtfProcessor.d.ts +0 -150
  899. package/dist/lib/processors/document/RtfProcessor.js +0 -364
  900. package/dist/lib/processors/document/WordProcessor.d.ts +0 -166
  901. package/dist/lib/processors/document/WordProcessor.js +0 -365
  902. package/dist/lib/processors/document/index.d.ts +0 -55
  903. package/dist/lib/processors/document/index.js +0 -100
  904. package/dist/lib/processors/errors/FileErrorCode.d.ts +0 -86
  905. package/dist/lib/processors/errors/FileErrorCode.js +0 -256
  906. package/dist/lib/processors/errors/errorHelpers.d.ts +0 -121
  907. package/dist/lib/processors/errors/errorHelpers.js +0 -387
  908. package/dist/lib/processors/errors/errorSerializer.d.ts +0 -96
  909. package/dist/lib/processors/errors/errorSerializer.js +0 -508
  910. package/dist/lib/processors/errors/index.d.ts +0 -46
  911. package/dist/lib/processors/errors/index.js +0 -50
  912. package/dist/lib/processors/index.d.ts +0 -79
  913. package/dist/lib/processors/index.js +0 -133
  914. package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +0 -176
  915. package/dist/lib/processors/integration/FileProcessorIntegration.js +0 -279
  916. package/dist/lib/processors/integration/index.d.ts +0 -41
  917. package/dist/lib/processors/integration/index.js +0 -48
  918. package/dist/lib/processors/markup/HtmlProcessor.d.ts +0 -167
  919. package/dist/lib/processors/markup/HtmlProcessor.js +0 -252
  920. package/dist/lib/processors/markup/MarkdownProcessor.d.ts +0 -163
  921. package/dist/lib/processors/markup/MarkdownProcessor.js +0 -249
  922. package/dist/lib/processors/markup/SvgProcessor.d.ts +0 -154
  923. package/dist/lib/processors/markup/SvgProcessor.js +0 -245
  924. package/dist/lib/processors/markup/TextProcessor.d.ts +0 -133
  925. package/dist/lib/processors/markup/TextProcessor.js +0 -191
  926. package/dist/lib/processors/markup/index.d.ts +0 -66
  927. package/dist/lib/processors/markup/index.js +0 -111
  928. package/dist/lib/processors/media/AudioProcessor.d.ts +0 -266
  929. package/dist/lib/processors/media/AudioProcessor.js +0 -712
  930. package/dist/lib/processors/media/VideoProcessor.d.ts +0 -337
  931. package/dist/lib/processors/media/VideoProcessor.js +0 -1154
  932. package/dist/lib/processors/media/index.d.ts +0 -26
  933. package/dist/lib/processors/media/index.js +0 -30
  934. package/dist/lib/processors/registry/ProcessorRegistry.d.ts +0 -347
  935. package/dist/lib/processors/registry/ProcessorRegistry.js +0 -715
  936. package/dist/lib/processors/registry/index.d.ts +0 -2
  937. package/dist/lib/processors/registry/index.js +0 -10
  938. package/dist/lib/providers/amazonBedrock/client.d.ts +0 -93
  939. package/dist/lib/providers/amazonBedrock/client.js +0 -1178
  940. package/dist/lib/providers/amazonBedrock/constants.d.ts +0 -1
  941. package/dist/lib/providers/amazonBedrock/constants.js +0 -3
  942. package/dist/lib/providers/amazonBedrock/index.d.ts +0 -3
  943. package/dist/lib/providers/amazonBedrock/index.js +0 -4
  944. package/dist/lib/providers/amazonBedrock/inferenceProfile.d.ts +0 -72
  945. package/dist/lib/providers/amazonBedrock/inferenceProfile.js +0 -186
  946. package/dist/lib/providers/amazonBedrock/loopAdapter.d.ts +0 -36
  947. package/dist/lib/providers/amazonBedrock/loopAdapter.js +0 -278
  948. package/dist/lib/providers/amazonBedrock/utils.d.ts +0 -1
  949. package/dist/lib/providers/amazonBedrock/utils.js +0 -4
  950. package/dist/lib/providers/amazonSagemaker.d.ts +0 -108
  951. package/dist/lib/providers/amazonSagemaker.js +0 -292
  952. package/dist/lib/providers/anthropic/cacheControl.d.ts +0 -12
  953. package/dist/lib/providers/anthropic/cacheControl.js +0 -15
  954. package/dist/lib/providers/anthropic/client.d.ts +0 -149
  955. package/dist/lib/providers/anthropic/client.js +0 -1862
  956. package/dist/lib/providers/anthropic/constants.d.ts +0 -3
  957. package/dist/lib/providers/anthropic/constants.js +0 -7
  958. package/dist/lib/providers/anthropic/index.d.ts +0 -2
  959. package/dist/lib/providers/anthropic/index.js +0 -3
  960. package/dist/lib/providers/anthropic/loopAdapter.d.ts +0 -26
  961. package/dist/lib/providers/anthropic/loopAdapter.js +0 -326
  962. package/dist/lib/providers/anthropic/rateLimitCapture.d.ts +0 -82
  963. package/dist/lib/providers/anthropic/rateLimitCapture.js +0 -375
  964. package/dist/lib/providers/anthropic/structuredOutput.d.ts +0 -58
  965. package/dist/lib/providers/anthropic/structuredOutput.js +0 -98
  966. package/dist/lib/providers/anthropic/toolOutput.d.ts +0 -9
  967. package/dist/lib/providers/anthropic/toolOutput.js +0 -39
  968. package/dist/lib/providers/anthropicImageBlocks.d.ts +0 -47
  969. package/dist/lib/providers/anthropicImageBlocks.js +0 -223
  970. package/dist/lib/providers/azureOpenai.d.ts +0 -67
  971. package/dist/lib/providers/azureOpenai.js +0 -230
  972. package/dist/lib/providers/cohere.d.ts +0 -54
  973. package/dist/lib/providers/cohere.js +0 -183
  974. package/dist/lib/providers/configuredOpenAICompat.d.ts +0 -24
  975. package/dist/lib/providers/configuredOpenAICompat.js +0 -67
  976. package/dist/lib/providers/deepseek.d.ts +0 -47
  977. package/dist/lib/providers/deepseek.js +0 -121
  978. package/dist/lib/providers/googleAiStudio/client.d.ts +0 -92
  979. package/dist/lib/providers/googleAiStudio/client.js +0 -1658
  980. package/dist/lib/providers/googleAiStudio/index.d.ts +0 -1
  981. package/dist/lib/providers/googleAiStudio/index.js +0 -2
  982. package/dist/lib/providers/googleNativeGemini3/index.d.ts +0 -1
  983. package/dist/lib/providers/googleNativeGemini3/index.js +0 -2
  984. package/dist/lib/providers/googleNativeGemini3/utils.d.ts +0 -482
  985. package/dist/lib/providers/googleNativeGemini3/utils.js +0 -1527
  986. package/dist/lib/providers/googleVertex/client.d.ts +0 -415
  987. package/dist/lib/providers/googleVertex/client.js +0 -7015
  988. package/dist/lib/providers/googleVertex/constants.d.ts +0 -5
  989. package/dist/lib/providers/googleVertex/constants.js +0 -27
  990. package/dist/lib/providers/googleVertex/index.d.ts +0 -3
  991. package/dist/lib/providers/googleVertex/index.js +0 -4
  992. package/dist/lib/providers/googleVertex/utils.d.ts +0 -12
  993. package/dist/lib/providers/googleVertex/utils.js +0 -287
  994. package/dist/lib/providers/huggingFace/client.d.ts +0 -31
  995. package/dist/lib/providers/huggingFace/client.js +0 -103
  996. package/dist/lib/providers/huggingFace/index.d.ts +0 -1
  997. package/dist/lib/providers/huggingFace/index.js +0 -2
  998. package/dist/lib/providers/ideogram.d.ts +0 -34
  999. package/dist/lib/providers/ideogram.js +0 -184
  1000. package/dist/lib/providers/jina.d.ts +0 -58
  1001. package/dist/lib/providers/jina.js +0 -217
  1002. package/dist/lib/providers/litellm/client.d.ts +0 -84
  1003. package/dist/lib/providers/litellm/client.js +0 -504
  1004. package/dist/lib/providers/litellm/index.d.ts +0 -1
  1005. package/dist/lib/providers/litellm/index.js +0 -2
  1006. package/dist/lib/providers/llamaCpp.d.ts +0 -24
  1007. package/dist/lib/providers/llamaCpp.js +0 -80
  1008. package/dist/lib/providers/lmStudio.d.ts +0 -29
  1009. package/dist/lib/providers/lmStudio.js +0 -88
  1010. package/dist/lib/providers/nvidiaNim/client.d.ts +0 -60
  1011. package/dist/lib/providers/nvidiaNim/client.js +0 -291
  1012. package/dist/lib/providers/nvidiaNim/constants.d.ts +0 -1
  1013. package/dist/lib/providers/nvidiaNim/constants.js +0 -2
  1014. package/dist/lib/providers/nvidiaNim/index.d.ts +0 -2
  1015. package/dist/lib/providers/nvidiaNim/index.js +0 -3
  1016. package/dist/lib/providers/ollama/client.d.ts +0 -71
  1017. package/dist/lib/providers/ollama/client.js +0 -283
  1018. package/dist/lib/providers/ollama/constants.d.ts +0 -4
  1019. package/dist/lib/providers/ollama/constants.js +0 -6
  1020. package/dist/lib/providers/ollama/index.d.ts +0 -2
  1021. package/dist/lib/providers/ollama/index.js +0 -3
  1022. package/dist/lib/providers/openAI/client.d.ts +0 -76
  1023. package/dist/lib/providers/openAI/client.js +0 -503
  1024. package/dist/lib/providers/openAI/index.d.ts +0 -1
  1025. package/dist/lib/providers/openAI/index.js +0 -2
  1026. package/dist/lib/providers/openRouter/client.d.ts +0 -75
  1027. package/dist/lib/providers/openRouter/client.js +0 -402
  1028. package/dist/lib/providers/openRouter/constants.d.ts +0 -1
  1029. package/dist/lib/providers/openRouter/constants.js +0 -2
  1030. package/dist/lib/providers/openRouter/index.d.ts +0 -3
  1031. package/dist/lib/providers/openRouter/index.js +0 -4
  1032. package/dist/lib/providers/openRouter/utils.d.ts +0 -1
  1033. package/dist/lib/providers/openRouter/utils.js +0 -6
  1034. package/dist/lib/providers/openaiChatCompletionsBase.d.ts +0 -212
  1035. package/dist/lib/providers/openaiChatCompletionsBase.js +0 -1154
  1036. package/dist/lib/providers/openaiChatCompletionsClient.d.ts +0 -70
  1037. package/dist/lib/providers/openaiChatCompletionsClient.js +0 -684
  1038. package/dist/lib/providers/openaiCompatCatalog.d.ts +0 -24
  1039. package/dist/lib/providers/openaiCompatCatalog.js +0 -270
  1040. package/dist/lib/providers/openaiCompatible/client.d.ts +0 -21
  1041. package/dist/lib/providers/openaiCompatible/client.js +0 -91
  1042. package/dist/lib/providers/openaiCompatible/constants.d.ts +0 -1
  1043. package/dist/lib/providers/openaiCompatible/constants.js +0 -2
  1044. package/dist/lib/providers/openaiCompatible/index.d.ts +0 -3
  1045. package/dist/lib/providers/openaiCompatible/index.js +0 -4
  1046. package/dist/lib/providers/openaiCompatible/utils.d.ts +0 -5
  1047. package/dist/lib/providers/openaiCompatible/utils.js +0 -17
  1048. package/dist/lib/providers/providerTypeUtils.d.ts +0 -23
  1049. package/dist/lib/providers/providerTypeUtils.js +0 -41
  1050. package/dist/lib/providers/recraft.d.ts +0 -34
  1051. package/dist/lib/providers/recraft.js +0 -197
  1052. package/dist/lib/providers/replicate.d.ts +0 -74
  1053. package/dist/lib/providers/replicate.js +0 -416
  1054. package/dist/lib/providers/sagemaker/adaptive-semaphore.d.ts +0 -74
  1055. package/dist/lib/providers/sagemaker/adaptive-semaphore.js +0 -216
  1056. package/dist/lib/providers/sagemaker/client.d.ts +0 -161
  1057. package/dist/lib/providers/sagemaker/client.js +0 -509
  1058. package/dist/lib/providers/sagemaker/config.d.ts +0 -87
  1059. package/dist/lib/providers/sagemaker/config.js +0 -355
  1060. package/dist/lib/providers/sagemaker/detection.d.ts +0 -121
  1061. package/dist/lib/providers/sagemaker/detection.js +0 -607
  1062. package/dist/lib/providers/sagemaker/diagnostics.d.ts +0 -14
  1063. package/dist/lib/providers/sagemaker/diagnostics.js +0 -138
  1064. package/dist/lib/providers/sagemaker/error-constants.d.ts +0 -78
  1065. package/dist/lib/providers/sagemaker/error-constants.js +0 -228
  1066. package/dist/lib/providers/sagemaker/errors.d.ts +0 -90
  1067. package/dist/lib/providers/sagemaker/errors.js +0 -301
  1068. package/dist/lib/providers/sagemaker/index.d.ts +0 -34
  1069. package/dist/lib/providers/sagemaker/index.js +0 -69
  1070. package/dist/lib/providers/sagemaker/language-model.d.ts +0 -207
  1071. package/dist/lib/providers/sagemaker/language-model.js +0 -805
  1072. package/dist/lib/providers/sagemaker/parsers.d.ts +0 -111
  1073. package/dist/lib/providers/sagemaker/parsers.js +0 -644
  1074. package/dist/lib/providers/sagemaker/streaming.d.ts +0 -48
  1075. package/dist/lib/providers/sagemaker/streaming.js +0 -390
  1076. package/dist/lib/providers/sagemaker/structured-parser.d.ts +0 -117
  1077. package/dist/lib/providers/sagemaker/structured-parser.js +0 -626
  1078. package/dist/lib/providers/stability.d.ts +0 -37
  1079. package/dist/lib/providers/stability.js +0 -191
  1080. package/dist/lib/providers/voyage.d.ts +0 -46
  1081. package/dist/lib/providers/voyage.js +0 -176
  1082. package/dist/lib/proxy/accountCooldown.d.ts +0 -5
  1083. package/dist/lib/proxy/accountCooldown.js +0 -121
  1084. package/dist/lib/proxy/accountQuota.d.ts +0 -84
  1085. package/dist/lib/proxy/accountQuota.js +0 -459
  1086. package/dist/lib/proxy/accountQuotaRefreshCoordinator.d.ts +0 -19
  1087. package/dist/lib/proxy/accountQuotaRefreshCoordinator.js +0 -105
  1088. package/dist/lib/proxy/accountSelection.d.ts +0 -8
  1089. package/dist/lib/proxy/accountSelection.js +0 -26
  1090. package/dist/lib/proxy/accountUsage.d.ts +0 -45
  1091. package/dist/lib/proxy/accountUsage.js +0 -302
  1092. package/dist/lib/proxy/awsProxyIntegration.d.ts +0 -23
  1093. package/dist/lib/proxy/awsProxyIntegration.js +0 -286
  1094. package/dist/lib/proxy/claudeFormat.d.ts +0 -129
  1095. package/dist/lib/proxy/claudeFormat.js +0 -600
  1096. package/dist/lib/proxy/cloaking/index.d.ts +0 -43
  1097. package/dist/lib/proxy/cloaking/index.js +0 -88
  1098. package/dist/lib/proxy/cloaking/plugins/headerScrubber.d.ts +0 -9
  1099. package/dist/lib/proxy/cloaking/plugins/headerScrubber.js +0 -87
  1100. package/dist/lib/proxy/cloaking/plugins/sessionIdentity.d.ts +0 -11
  1101. package/dist/lib/proxy/cloaking/plugins/sessionIdentity.js +0 -42
  1102. package/dist/lib/proxy/cloaking/plugins/systemPromptInjector.d.ts +0 -11
  1103. package/dist/lib/proxy/cloaking/plugins/systemPromptInjector.js +0 -84
  1104. package/dist/lib/proxy/cloaking/plugins/tlsFingerprint.d.ts +0 -14
  1105. package/dist/lib/proxy/cloaking/plugins/tlsFingerprint.js +0 -39
  1106. package/dist/lib/proxy/cloaking/plugins/wordObfuscator.d.ts +0 -9
  1107. package/dist/lib/proxy/cloaking/plugins/wordObfuscator.js +0 -122
  1108. package/dist/lib/proxy/codexAccountUsage.d.ts +0 -26
  1109. package/dist/lib/proxy/codexAccountUsage.js +0 -174
  1110. package/dist/lib/proxy/globalInstaller.d.ts +0 -19
  1111. package/dist/lib/proxy/globalInstaller.js +0 -242
  1112. package/dist/lib/proxy/logCleanupScheduler.d.ts +0 -12
  1113. package/dist/lib/proxy/logCleanupScheduler.js +0 -74
  1114. package/dist/lib/proxy/logCleanupWorkerEntry.d.ts +0 -1
  1115. package/dist/lib/proxy/logCleanupWorkerEntry.js +0 -15
  1116. package/dist/lib/proxy/modelRouter.d.ts +0 -34
  1117. package/dist/lib/proxy/modelRouter.js +0 -74
  1118. package/dist/lib/proxy/oauthFetch.d.ts +0 -36
  1119. package/dist/lib/proxy/oauthFetch.js +0 -353
  1120. package/dist/lib/proxy/openaiFormat.d.ts +0 -139
  1121. package/dist/lib/proxy/openaiFormat.js +0 -817
  1122. package/dist/lib/proxy/providerTransportCoordinator.d.ts +0 -17
  1123. package/dist/lib/proxy/providerTransportCoordinator.js +0 -156
  1124. package/dist/lib/proxy/proxyActivity.d.ts +0 -8
  1125. package/dist/lib/proxy/proxyActivity.js +0 -117
  1126. package/dist/lib/proxy/proxyAnalysis.d.ts +0 -3
  1127. package/dist/lib/proxy/proxyAnalysis.js +0 -901
  1128. package/dist/lib/proxy/proxyConfig.d.ts +0 -42
  1129. package/dist/lib/proxy/proxyConfig.js +0 -700
  1130. package/dist/lib/proxy/proxyDispatcher.d.ts +0 -5
  1131. package/dist/lib/proxy/proxyDispatcher.js +0 -61
  1132. package/dist/lib/proxy/proxyEnv.d.ts +0 -3
  1133. package/dist/lib/proxy/proxyEnv.js +0 -73
  1134. package/dist/lib/proxy/proxyFetch.d.ts +0 -49
  1135. package/dist/lib/proxy/proxyFetch.js +0 -700
  1136. package/dist/lib/proxy/proxyHealth.d.ts +0 -20
  1137. package/dist/lib/proxy/proxyHealth.js +0 -76
  1138. package/dist/lib/proxy/proxyLifecycle.d.ts +0 -13
  1139. package/dist/lib/proxy/proxyLifecycle.js +0 -383
  1140. package/dist/lib/proxy/proxyPaths.d.ts +0 -17
  1141. package/dist/lib/proxy/proxyPaths.js +0 -42
  1142. package/dist/lib/proxy/proxyReplay.d.ts +0 -10
  1143. package/dist/lib/proxy/proxyReplay.js +0 -765
  1144. package/dist/lib/proxy/proxyTracer.d.ts +0 -117
  1145. package/dist/lib/proxy/proxyTracer.js +0 -726
  1146. package/dist/lib/proxy/proxyTranslationEngine.d.ts +0 -125
  1147. package/dist/lib/proxy/proxyTranslationEngine.js +0 -723
  1148. package/dist/lib/proxy/quietDetector.d.ts +0 -17
  1149. package/dist/lib/proxy/quietDetector.js +0 -125
  1150. package/dist/lib/proxy/quotaHeaders.d.ts +0 -73
  1151. package/dist/lib/proxy/quotaHeaders.js +0 -189
  1152. package/dist/lib/proxy/rawStreamCapture.d.ts +0 -2
  1153. package/dist/lib/proxy/rawStreamCapture.js +0 -129
  1154. package/dist/lib/proxy/requestLogger.d.ts +0 -78
  1155. package/dist/lib/proxy/requestLogger.js +0 -770
  1156. package/dist/lib/proxy/rollingProxyServer.d.ts +0 -3
  1157. package/dist/lib/proxy/rollingProxyServer.js +0 -220
  1158. package/dist/lib/proxy/rollingWorkerProcess.d.ts +0 -2
  1159. package/dist/lib/proxy/rollingWorkerProcess.js +0 -199
  1160. package/dist/lib/proxy/rollingWorkerProtocol.d.ts +0 -5
  1161. package/dist/lib/proxy/rollingWorkerProtocol.js +0 -46
  1162. package/dist/lib/proxy/rollingWorkerSupervisor.d.ts +0 -44
  1163. package/dist/lib/proxy/rollingWorkerSupervisor.js +0 -530
  1164. package/dist/lib/proxy/routingEvidence.d.ts +0 -17
  1165. package/dist/lib/proxy/routingEvidence.js +0 -59
  1166. package/dist/lib/proxy/routingPolicy.d.ts +0 -19
  1167. package/dist/lib/proxy/routingPolicy.js +0 -75
  1168. package/dist/lib/proxy/runtimeConfig.d.ts +0 -27
  1169. package/dist/lib/proxy/runtimeConfig.js +0 -448
  1170. package/dist/lib/proxy/snapshotPersistence.d.ts +0 -2
  1171. package/dist/lib/proxy/snapshotPersistence.js +0 -41
  1172. package/dist/lib/proxy/socketWorkerRuntime.d.ts +0 -14
  1173. package/dist/lib/proxy/socketWorkerRuntime.js +0 -322
  1174. package/dist/lib/proxy/sseInterceptor.d.ts +0 -41
  1175. package/dist/lib/proxy/sseInterceptor.js +0 -496
  1176. package/dist/lib/proxy/streamOutcome.d.ts +0 -5
  1177. package/dist/lib/proxy/streamOutcome.js +0 -104
  1178. package/dist/lib/proxy/systemRelocation.d.ts +0 -21
  1179. package/dist/lib/proxy/systemRelocation.js +0 -51
  1180. package/dist/lib/proxy/tokenRefresh.d.ts +0 -18
  1181. package/dist/lib/proxy/tokenRefresh.js +0 -257
  1182. package/dist/lib/proxy/updateChecker.d.ts +0 -17
  1183. package/dist/lib/proxy/updateChecker.js +0 -98
  1184. package/dist/lib/proxy/updateCoordinator.d.ts +0 -7
  1185. package/dist/lib/proxy/updateCoordinator.js +0 -60
  1186. package/dist/lib/proxy/updateState.d.ts +0 -69
  1187. package/dist/lib/proxy/updateState.js +0 -309
  1188. package/dist/lib/proxy/updaterSupervisor.d.ts +0 -3
  1189. package/dist/lib/proxy/updaterSupervisor.js +0 -58
  1190. package/dist/lib/proxy/usageStats.d.ts +0 -91
  1191. package/dist/lib/proxy/usageStats.js +0 -1154
  1192. package/dist/lib/proxy/utils/noProxyUtils.d.ts +0 -39
  1193. package/dist/lib/proxy/utils/noProxyUtils.js +0 -150
  1194. package/dist/lib/proxy/workerLog.d.ts +0 -6
  1195. package/dist/lib/proxy/workerLog.js +0 -42
  1196. package/dist/lib/rag/ChunkerFactory.d.ts +0 -91
  1197. package/dist/lib/rag/ChunkerFactory.js +0 -321
  1198. package/dist/lib/rag/ChunkerRegistry.d.ts +0 -91
  1199. package/dist/lib/rag/ChunkerRegistry.js +0 -422
  1200. package/dist/lib/rag/chunkers/BaseChunker.d.ts +0 -53
  1201. package/dist/lib/rag/chunkers/BaseChunker.js +0 -158
  1202. package/dist/lib/rag/chunkers/CharacterChunker.d.ts +0 -18
  1203. package/dist/lib/rag/chunkers/CharacterChunker.js +0 -29
  1204. package/dist/lib/rag/chunkers/HTMLChunker.d.ts +0 -19
  1205. package/dist/lib/rag/chunkers/HTMLChunker.js +0 -39
  1206. package/dist/lib/rag/chunkers/JSONChunker.d.ts +0 -19
  1207. package/dist/lib/rag/chunkers/JSONChunker.js +0 -69
  1208. package/dist/lib/rag/chunkers/LaTeXChunker.d.ts +0 -15
  1209. package/dist/lib/rag/chunkers/LaTeXChunker.js +0 -64
  1210. package/dist/lib/rag/chunkers/MarkdownChunker.d.ts +0 -37
  1211. package/dist/lib/rag/chunkers/MarkdownChunker.js +0 -315
  1212. package/dist/lib/rag/chunkers/RecursiveChunker.d.ts +0 -27
  1213. package/dist/lib/rag/chunkers/RecursiveChunker.js +0 -140
  1214. package/dist/lib/rag/chunkers/SemanticMarkdownChunker.d.ts +0 -22
  1215. package/dist/lib/rag/chunkers/SemanticMarkdownChunker.js +0 -139
  1216. package/dist/lib/rag/chunkers/SentenceChunker.d.ts +0 -19
  1217. package/dist/lib/rag/chunkers/SentenceChunker.js +0 -67
  1218. package/dist/lib/rag/chunkers/TokenChunker.d.ts +0 -19
  1219. package/dist/lib/rag/chunkers/TokenChunker.js +0 -62
  1220. package/dist/lib/rag/chunkers/index.d.ts +0 -15
  1221. package/dist/lib/rag/chunkers/index.js +0 -16
  1222. package/dist/lib/rag/chunking/characterChunker.d.ts +0 -16
  1223. package/dist/lib/rag/chunking/characterChunker.js +0 -143
  1224. package/dist/lib/rag/chunking/chunkerRegistry.d.ts +0 -67
  1225. package/dist/lib/rag/chunking/chunkerRegistry.js +0 -195
  1226. package/dist/lib/rag/chunking/htmlChunker.d.ts +0 -34
  1227. package/dist/lib/rag/chunking/htmlChunker.js +0 -248
  1228. package/dist/lib/rag/chunking/index.d.ts +0 -15
  1229. package/dist/lib/rag/chunking/index.js +0 -18
  1230. package/dist/lib/rag/chunking/jsonChunker.d.ts +0 -20
  1231. package/dist/lib/rag/chunking/jsonChunker.js +0 -282
  1232. package/dist/lib/rag/chunking/latexChunker.d.ts +0 -26
  1233. package/dist/lib/rag/chunking/latexChunker.js +0 -252
  1234. package/dist/lib/rag/chunking/markdownChunker.d.ts +0 -35
  1235. package/dist/lib/rag/chunking/markdownChunker.js +0 -383
  1236. package/dist/lib/rag/chunking/recursiveChunker.d.ts +0 -19
  1237. package/dist/lib/rag/chunking/recursiveChunker.js +0 -149
  1238. package/dist/lib/rag/chunking/semanticChunker.d.ts +0 -41
  1239. package/dist/lib/rag/chunking/semanticChunker.js +0 -306
  1240. package/dist/lib/rag/chunking/sentenceChunker.d.ts +0 -25
  1241. package/dist/lib/rag/chunking/sentenceChunker.js +0 -231
  1242. package/dist/lib/rag/chunking/tokenChunker.d.ts +0 -36
  1243. package/dist/lib/rag/chunking/tokenChunker.js +0 -184
  1244. package/dist/lib/rag/document/MDocument.d.ts +0 -198
  1245. package/dist/lib/rag/document/MDocument.js +0 -392
  1246. package/dist/lib/rag/document/index.d.ts +0 -5
  1247. package/dist/lib/rag/document/index.js +0 -6
  1248. package/dist/lib/rag/document/loaders.d.ts +0 -142
  1249. package/dist/lib/rag/document/loaders.js +0 -544
  1250. package/dist/lib/rag/errors/RAGError.d.ts +0 -244
  1251. package/dist/lib/rag/errors/RAGError.js +0 -275
  1252. package/dist/lib/rag/errors/index.d.ts +0 -6
  1253. package/dist/lib/rag/errors/index.js +0 -7
  1254. package/dist/lib/rag/graphRag/graphRAG.d.ts +0 -115
  1255. package/dist/lib/rag/graphRag/graphRAG.js +0 -402
  1256. package/dist/lib/rag/graphRag/index.d.ts +0 -4
  1257. package/dist/lib/rag/graphRag/index.js +0 -5
  1258. package/dist/lib/rag/index.d.ts +0 -104
  1259. package/dist/lib/rag/index.js +0 -144
  1260. package/dist/lib/rag/metadata/MetadataExtractorFactory.d.ts +0 -103
  1261. package/dist/lib/rag/metadata/MetadataExtractorFactory.js +0 -419
  1262. package/dist/lib/rag/metadata/MetadataExtractorRegistry.d.ts +0 -99
  1263. package/dist/lib/rag/metadata/MetadataExtractorRegistry.js +0 -363
  1264. package/dist/lib/rag/metadata/index.d.ts +0 -6
  1265. package/dist/lib/rag/metadata/index.js +0 -10
  1266. package/dist/lib/rag/metadata/metadataExtractor.d.ts +0 -69
  1267. package/dist/lib/rag/metadata/metadataExtractor.js +0 -281
  1268. package/dist/lib/rag/pipeline/RAGPipeline.d.ts +0 -105
  1269. package/dist/lib/rag/pipeline/RAGPipeline.js +0 -436
  1270. package/dist/lib/rag/pipeline/contextAssembly.d.ts +0 -80
  1271. package/dist/lib/rag/pipeline/contextAssembly.js +0 -342
  1272. package/dist/lib/rag/pipeline/index.d.ts +0 -5
  1273. package/dist/lib/rag/pipeline/index.js +0 -6
  1274. package/dist/lib/rag/ragIntegration.d.ts +0 -30
  1275. package/dist/lib/rag/ragIntegration.js +0 -327
  1276. package/dist/lib/rag/reranker/RerankerFactory.d.ts +0 -124
  1277. package/dist/lib/rag/reranker/RerankerFactory.js +0 -431
  1278. package/dist/lib/rag/reranker/RerankerRegistry.d.ts +0 -119
  1279. package/dist/lib/rag/reranker/RerankerRegistry.js +0 -403
  1280. package/dist/lib/rag/reranker/index.d.ts +0 -6
  1281. package/dist/lib/rag/reranker/index.js +0 -10
  1282. package/dist/lib/rag/reranker/reranker.d.ts +0 -70
  1283. package/dist/lib/rag/reranker/reranker.js +0 -307
  1284. package/dist/lib/rag/resilience/CircuitBreaker.d.ts +0 -142
  1285. package/dist/lib/rag/resilience/CircuitBreaker.js +0 -432
  1286. package/dist/lib/rag/resilience/RetryHandler.d.ts +0 -95
  1287. package/dist/lib/rag/resilience/RetryHandler.js +0 -305
  1288. package/dist/lib/rag/resilience/index.d.ts +0 -7
  1289. package/dist/lib/rag/resilience/index.js +0 -8
  1290. package/dist/lib/rag/retrieval/hybridSearch.d.ts +0 -53
  1291. package/dist/lib/rag/retrieval/hybridSearch.js +0 -339
  1292. package/dist/lib/rag/retrieval/index.d.ts +0 -5
  1293. package/dist/lib/rag/retrieval/index.js +0 -6
  1294. package/dist/lib/rag/retrieval/vectorQueryTool.d.ts +0 -72
  1295. package/dist/lib/rag/retrieval/vectorQueryTool.js +0 -325
  1296. package/dist/lib/rag/stores/chroma.d.ts +0 -90
  1297. package/dist/lib/rag/stores/chroma.js +0 -281
  1298. package/dist/lib/rag/stores/index.d.ts +0 -21
  1299. package/dist/lib/rag/stores/index.js +0 -22
  1300. package/dist/lib/rag/stores/pgvector.d.ts +0 -95
  1301. package/dist/lib/rag/stores/pgvector.js +0 -400
  1302. package/dist/lib/rag/stores/pinecone.d.ts +0 -85
  1303. package/dist/lib/rag/stores/pinecone.js +0 -159
  1304. package/dist/lib/routing/classifierRouter.d.ts +0 -52
  1305. package/dist/lib/routing/classifierRouter.js +0 -269
  1306. package/dist/lib/routing/classifierStrategies.d.ts +0 -23
  1307. package/dist/lib/routing/classifierStrategies.js +0 -156
  1308. package/dist/lib/routing/index.d.ts +0 -9
  1309. package/dist/lib/routing/index.js +0 -10
  1310. package/dist/lib/routing/modelPool.d.ts +0 -83
  1311. package/dist/lib/routing/modelPool.js +0 -243
  1312. package/dist/lib/routing/requestRouter.d.ts +0 -30
  1313. package/dist/lib/routing/requestRouter.js +0 -81
  1314. package/dist/lib/sdk/toolRegistration.d.ts +0 -74
  1315. package/dist/lib/sdk/toolRegistration.js +0 -383
  1316. package/dist/lib/server/abstract/baseServerAdapter.d.ts +0 -171
  1317. package/dist/lib/server/abstract/baseServerAdapter.js +0 -575
  1318. package/dist/lib/server/adapters/expressAdapter.d.ts +0 -70
  1319. package/dist/lib/server/adapters/expressAdapter.js +0 -487
  1320. package/dist/lib/server/adapters/fastifyAdapter.d.ts +0 -70
  1321. package/dist/lib/server/adapters/fastifyAdapter.js +0 -473
  1322. package/dist/lib/server/adapters/honoAdapter.d.ts +0 -77
  1323. package/dist/lib/server/adapters/honoAdapter.js +0 -633
  1324. package/dist/lib/server/adapters/index.d.ts +0 -7
  1325. package/dist/lib/server/adapters/index.js +0 -8
  1326. package/dist/lib/server/adapters/koaAdapter.d.ts +0 -79
  1327. package/dist/lib/server/adapters/koaAdapter.js +0 -511
  1328. package/dist/lib/server/errors.d.ts +0 -193
  1329. package/dist/lib/server/errors.js +0 -487
  1330. package/dist/lib/server/factory/serverAdapterFactory.d.ts +0 -73
  1331. package/dist/lib/server/factory/serverAdapterFactory.js +0 -161
  1332. package/dist/lib/server/index.d.ts +0 -46
  1333. package/dist/lib/server/index.js +0 -122
  1334. package/dist/lib/server/middleware/abortSignal.d.ts +0 -52
  1335. package/dist/lib/server/middleware/abortSignal.js +0 -112
  1336. package/dist/lib/server/middleware/auth.d.ts +0 -166
  1337. package/dist/lib/server/middleware/auth.js +0 -404
  1338. package/dist/lib/server/middleware/cache.d.ts +0 -161
  1339. package/dist/lib/server/middleware/cache.js +0 -370
  1340. package/dist/lib/server/middleware/common.d.ts +0 -108
  1341. package/dist/lib/server/middleware/common.js +0 -297
  1342. package/dist/lib/server/middleware/deprecation.d.ts +0 -40
  1343. package/dist/lib/server/middleware/deprecation.js +0 -191
  1344. package/dist/lib/server/middleware/index.d.ts +0 -12
  1345. package/dist/lib/server/middleware/index.js +0 -13
  1346. package/dist/lib/server/middleware/mcpBodyAttachment.d.ts +0 -42
  1347. package/dist/lib/server/middleware/mcpBodyAttachment.js +0 -64
  1348. package/dist/lib/server/middleware/rateLimit.d.ts +0 -70
  1349. package/dist/lib/server/middleware/rateLimit.js +0 -224
  1350. package/dist/lib/server/middleware/validation.d.ts +0 -69
  1351. package/dist/lib/server/middleware/validation.js +0 -393
  1352. package/dist/lib/server/openapi/generator.d.ts +0 -61
  1353. package/dist/lib/server/openapi/generator.js +0 -399
  1354. package/dist/lib/server/openapi/index.d.ts +0 -7
  1355. package/dist/lib/server/openapi/index.js +0 -37
  1356. package/dist/lib/server/openapi/schemas.d.ts +0 -94
  1357. package/dist/lib/server/openapi/schemas.js +0 -696
  1358. package/dist/lib/server/openapi/templates.d.ts +0 -108
  1359. package/dist/lib/server/openapi/templates.js +0 -375
  1360. package/dist/lib/server/routes/agentRoutes.d.ts +0 -9
  1361. package/dist/lib/server/routes/agentRoutes.js +0 -423
  1362. package/dist/lib/server/routes/claudeProxyRoutes.d.ts +0 -491
  1363. package/dist/lib/server/routes/claudeProxyRoutes.js +0 -6455
  1364. package/dist/lib/server/routes/codexProxyRoutes.d.ts +0 -64
  1365. package/dist/lib/server/routes/codexProxyRoutes.js +0 -454
  1366. package/dist/lib/server/routes/healthRoutes.d.ts +0 -9
  1367. package/dist/lib/server/routes/healthRoutes.js +0 -234
  1368. package/dist/lib/server/routes/index.d.ts +0 -25
  1369. package/dist/lib/server/routes/index.js +0 -66
  1370. package/dist/lib/server/routes/mcpRoutes.d.ts +0 -9
  1371. package/dist/lib/server/routes/mcpRoutes.js +0 -376
  1372. package/dist/lib/server/routes/memoryRoutes.d.ts +0 -11
  1373. package/dist/lib/server/routes/memoryRoutes.js +0 -366
  1374. package/dist/lib/server/routes/openApiRoutes.d.ts +0 -34
  1375. package/dist/lib/server/routes/openApiRoutes.js +0 -151
  1376. package/dist/lib/server/routes/openaiProxyRoutes.d.ts +0 -38
  1377. package/dist/lib/server/routes/openaiProxyRoutes.js +0 -399
  1378. package/dist/lib/server/routes/toolRoutes.d.ts +0 -9
  1379. package/dist/lib/server/routes/toolRoutes.js +0 -272
  1380. package/dist/lib/server/streaming/dataStream.d.ts +0 -212
  1381. package/dist/lib/server/streaming/dataStream.js +0 -502
  1382. package/dist/lib/server/streaming/index.d.ts +0 -5
  1383. package/dist/lib/server/streaming/index.js +0 -17
  1384. package/dist/lib/server/utils/redaction.d.ts +0 -68
  1385. package/dist/lib/server/utils/redaction.js +0 -321
  1386. package/dist/lib/server/utils/validation.d.ts +0 -153
  1387. package/dist/lib/server/utils/validation.js +0 -265
  1388. package/dist/lib/server/voice/frameBus.d.ts +0 -8
  1389. package/dist/lib/server/voice/frameBus.js +0 -25
  1390. package/dist/lib/server/voice/tokenCompare.d.ts +0 -14
  1391. package/dist/lib/server/voice/tokenCompare.js +0 -23
  1392. package/dist/lib/server/voice/turnManager.d.ts +0 -15
  1393. package/dist/lib/server/voice/turnManager.js +0 -36
  1394. package/dist/lib/server/voice/voiceServerApp.d.ts +0 -1
  1395. package/dist/lib/server/voice/voiceServerApp.js +0 -177
  1396. package/dist/lib/server/voice/voiceWebSocketHandler.d.ts +0 -24
  1397. package/dist/lib/server/voice/voiceWebSocketHandler.js +0 -669
  1398. package/dist/lib/server/websocket/WebSocketHandler.d.ts +0 -107
  1399. package/dist/lib/server/websocket/WebSocketHandler.js +0 -384
  1400. package/dist/lib/server/websocket/index.d.ts +0 -4
  1401. package/dist/lib/server/websocket/index.js +0 -5
  1402. package/dist/lib/services/server/ai/observability/instrumentation.d.ts +0 -229
  1403. package/dist/lib/services/server/ai/observability/instrumentation.js +0 -1244
  1404. package/dist/lib/session/globalSessionState.d.ts +0 -71
  1405. package/dist/lib/session/globalSessionState.js +0 -235
  1406. package/dist/lib/skills/skillMatcher.d.ts +0 -55
  1407. package/dist/lib/skills/skillMatcher.js +0 -170
  1408. package/dist/lib/skills/skillSessionTracker.d.ts +0 -52
  1409. package/dist/lib/skills/skillSessionTracker.js +0 -150
  1410. package/dist/lib/skills/skillStoreRedis.d.ts +0 -30
  1411. package/dist/lib/skills/skillStoreRedis.js +0 -114
  1412. package/dist/lib/skills/skillStoreS3.d.ts +0 -56
  1413. package/dist/lib/skills/skillStoreS3.js +0 -305
  1414. package/dist/lib/skills/skillStores.d.ts +0 -58
  1415. package/dist/lib/skills/skillStores.js +0 -341
  1416. package/dist/lib/skills/skillTools.d.ts +0 -35
  1417. package/dist/lib/skills/skillTools.js +0 -451
  1418. package/dist/lib/skills/skillsManager.d.ts +0 -78
  1419. package/dist/lib/skills/skillsManager.js +0 -281
  1420. package/dist/lib/tasks/autoresearchTaskExecutor.d.ts +0 -31
  1421. package/dist/lib/tasks/autoresearchTaskExecutor.js +0 -304
  1422. package/dist/lib/tasks/backends/bullmqBackend.d.ts +0 -33
  1423. package/dist/lib/tasks/backends/bullmqBackend.js +0 -206
  1424. package/dist/lib/tasks/backends/nodeTimeoutBackend.d.ts +0 -27
  1425. package/dist/lib/tasks/backends/nodeTimeoutBackend.js +0 -141
  1426. package/dist/lib/tasks/backends/taskBackendRegistry.d.ts +0 -31
  1427. package/dist/lib/tasks/backends/taskBackendRegistry.js +0 -66
  1428. package/dist/lib/tasks/errors.d.ts +0 -33
  1429. package/dist/lib/tasks/errors.js +0 -19
  1430. package/dist/lib/tasks/store/fileTaskStore.d.ts +0 -43
  1431. package/dist/lib/tasks/store/fileTaskStore.js +0 -179
  1432. package/dist/lib/tasks/store/redisTaskStore.d.ts +0 -43
  1433. package/dist/lib/tasks/store/redisTaskStore.js +0 -222
  1434. package/dist/lib/tasks/taskExecutor.d.ts +0 -22
  1435. package/dist/lib/tasks/taskExecutor.js +0 -170
  1436. package/dist/lib/tasks/taskManager.d.ts +0 -65
  1437. package/dist/lib/tasks/taskManager.js +0 -545
  1438. package/dist/lib/tasks/tools/taskTools.d.ts +0 -20
  1439. package/dist/lib/tasks/tools/taskTools.js +0 -265
  1440. package/dist/lib/telemetry/attributes.d.ts +0 -136
  1441. package/dist/lib/telemetry/attributes.js +0 -165
  1442. package/dist/lib/telemetry/index.d.ts +0 -20
  1443. package/dist/lib/telemetry/index.js +0 -28
  1444. package/dist/lib/telemetry/telemetryService.d.ts +0 -58
  1445. package/dist/lib/telemetry/telemetryService.js +0 -387
  1446. package/dist/lib/telemetry/traceContext.d.ts +0 -9
  1447. package/dist/lib/telemetry/traceContext.js +0 -19
  1448. package/dist/lib/telemetry/tracers.d.ts +0 -38
  1449. package/dist/lib/telemetry/tracers.js +0 -40
  1450. package/dist/lib/telemetry/withSpan.d.ts +0 -39
  1451. package/dist/lib/telemetry/withSpan.js +0 -138
  1452. package/dist/lib/tools/toolDiscovery.d.ts +0 -70
  1453. package/dist/lib/tools/toolDiscovery.js +0 -303
  1454. package/dist/lib/tools/toolGate.d.ts +0 -16
  1455. package/dist/lib/tools/toolGate.js +0 -51
  1456. package/dist/lib/tools/toolPolicy.d.ts +0 -40
  1457. package/dist/lib/tools/toolPolicy.js +0 -194
  1458. package/dist/lib/types/action.d.ts +0 -207
  1459. package/dist/lib/types/action.js +0 -7
  1460. package/dist/lib/types/agentNetwork.d.ts +0 -1199
  1461. package/dist/lib/types/agentNetwork.js +0 -8
  1462. package/dist/lib/types/aliases.d.ts +0 -368
  1463. package/dist/lib/types/aliases.js +0 -50
  1464. package/dist/lib/types/analytics.d.ts +0 -215
  1465. package/dist/lib/types/analytics.js +0 -6
  1466. package/dist/lib/types/artifact.d.ts +0 -70
  1467. package/dist/lib/types/artifact.js +0 -11
  1468. package/dist/lib/types/auth.d.ts +0 -1140
  1469. package/dist/lib/types/auth.js +0 -10
  1470. package/dist/lib/types/autoresearch.d.ts +0 -206
  1471. package/dist/lib/types/autoresearch.js +0 -18
  1472. package/dist/lib/types/avatar.d.ts +0 -150
  1473. package/dist/lib/types/avatar.js +0 -20
  1474. package/dist/lib/types/circuitBreakerErrors.d.ts +0 -30
  1475. package/dist/lib/types/circuitBreakerErrors.js +0 -35
  1476. package/dist/lib/types/classifierRouter.d.ts +0 -194
  1477. package/dist/lib/types/classifierRouter.js +0 -17
  1478. package/dist/lib/types/cli.d.ts +0 -1734
  1479. package/dist/lib/types/cli.js +0 -22
  1480. package/dist/lib/types/client.d.ts +0 -1287
  1481. package/dist/lib/types/client.js +0 -11
  1482. package/dist/lib/types/codex.d.ts +0 -95
  1483. package/dist/lib/types/codex.js +0 -15
  1484. package/dist/lib/types/common.d.ts +0 -434
  1485. package/dist/lib/types/common.js +0 -52
  1486. package/dist/lib/types/config.d.ts +0 -506
  1487. package/dist/lib/types/config.js +0 -54
  1488. package/dist/lib/types/content.d.ts +0 -18
  1489. package/dist/lib/types/content.js +0 -20
  1490. package/dist/lib/types/context.d.ts +0 -587
  1491. package/dist/lib/types/context.js +0 -401
  1492. package/dist/lib/types/conversation.d.ts +0 -637
  1493. package/dist/lib/types/conversation.js +0 -48
  1494. package/dist/lib/types/conversationMemoryInterface.d.ts +0 -59
  1495. package/dist/lib/types/conversationMemoryInterface.js +0 -7
  1496. package/dist/lib/types/domain.d.ts +0 -62
  1497. package/dist/lib/types/domain.js +0 -6
  1498. package/dist/lib/types/dynamic.d.ts +0 -110
  1499. package/dist/lib/types/dynamic.js +0 -10
  1500. package/dist/lib/types/elicitation.d.ts +0 -278
  1501. package/dist/lib/types/elicitation.js +0 -11
  1502. package/dist/lib/types/enums.d.ts +0 -9
  1503. package/dist/lib/types/enums.js +0 -10
  1504. package/dist/lib/types/errors.d.ts +0 -188
  1505. package/dist/lib/types/errors.js +0 -262
  1506. package/dist/lib/types/evaluation.d.ts +0 -647
  1507. package/dist/lib/types/evaluation.js +0 -2
  1508. package/dist/lib/types/evaluationProviders.d.ts +0 -104
  1509. package/dist/lib/types/evaluationProviders.js +0 -6
  1510. package/dist/lib/types/exporter.d.ts +0 -257
  1511. package/dist/lib/types/exporter.js +0 -6
  1512. package/dist/lib/types/externalMcp.d.ts +0 -349
  1513. package/dist/lib/types/externalMcp.js +0 -7
  1514. package/dist/lib/types/file.d.ts +0 -616
  1515. package/dist/lib/types/file.js +0 -5
  1516. package/dist/lib/types/fileReference.d.ts +0 -243
  1517. package/dist/lib/types/fileReference.js +0 -22
  1518. package/dist/lib/types/generate.d.ts +0 -1520
  1519. package/dist/lib/types/generate.js +0 -2
  1520. package/dist/lib/types/grounding.d.ts +0 -231
  1521. package/dist/lib/types/grounding.js +0 -12
  1522. package/dist/lib/types/guardrails.d.ts +0 -116
  1523. package/dist/lib/types/guardrails.js +0 -2
  1524. package/dist/lib/types/hitl.d.ts +0 -237
  1525. package/dist/lib/types/hitl.js +0 -9
  1526. package/dist/lib/types/imageGen.d.ts +0 -255
  1527. package/dist/lib/types/imageGen.js +0 -25
  1528. package/dist/lib/types/index.d.ts +0 -86
  1529. package/dist/lib/types/index.js +0 -98
  1530. package/dist/lib/types/ioProcessor.d.ts +0 -119
  1531. package/dist/lib/types/ioProcessor.js +0 -10
  1532. package/dist/lib/types/isolatedAgent.d.ts +0 -365
  1533. package/dist/lib/types/isolatedAgent.js +0 -12
  1534. package/dist/lib/types/knowledge.d.ts +0 -342
  1535. package/dist/lib/types/knowledge.js +0 -30
  1536. package/dist/lib/types/livekit.d.ts +0 -512
  1537. package/dist/lib/types/livekit.js +0 -13
  1538. package/dist/lib/types/loopEngine.d.ts +0 -306
  1539. package/dist/lib/types/loopEngine.js +0 -2
  1540. package/dist/lib/types/mcp.d.ts +0 -2135
  1541. package/dist/lib/types/mcp.js +0 -6
  1542. package/dist/lib/types/mcpOutput.d.ts +0 -40
  1543. package/dist/lib/types/mcpOutput.js +0 -9
  1544. package/dist/lib/types/memory.d.ts +0 -96
  1545. package/dist/lib/types/memory.js +0 -23
  1546. package/dist/lib/types/middleware.d.ts +0 -435
  1547. package/dist/lib/types/middleware.js +0 -2
  1548. package/dist/lib/types/model.d.ts +0 -342
  1549. package/dist/lib/types/model.js +0 -32
  1550. package/dist/lib/types/modelPool.d.ts +0 -47
  1551. package/dist/lib/types/modelPool.js +0 -11
  1552. package/dist/lib/types/multimodal.d.ts +0 -614
  1553. package/dist/lib/types/multimodal.js +0 -144
  1554. package/dist/lib/types/music.d.ts +0 -172
  1555. package/dist/lib/types/music.js +0 -21
  1556. package/dist/lib/types/nativeTools.d.ts +0 -16
  1557. package/dist/lib/types/nativeTools.js +0 -2
  1558. package/dist/lib/types/noOutputSentinel.d.ts +0 -26
  1559. package/dist/lib/types/noOutputSentinel.js +0 -2
  1560. package/dist/lib/types/observability.d.ts +0 -502
  1561. package/dist/lib/types/observability.js +0 -7
  1562. package/dist/lib/types/openaiCompatible.d.ts +0 -287
  1563. package/dist/lib/types/openaiCompatible.js +0 -2
  1564. package/dist/lib/types/ppt.d.ts +0 -1093
  1565. package/dist/lib/types/ppt.js +0 -37
  1566. package/dist/lib/types/processor.d.ts +0 -993
  1567. package/dist/lib/types/processor.js +0 -91
  1568. package/dist/lib/types/providers.d.ts +0 -2155
  1569. package/dist/lib/types/providers.js +0 -112
  1570. package/dist/lib/types/proxy.d.ts +0 -2724
  1571. package/dist/lib/types/proxy.js +0 -17
  1572. package/dist/lib/types/proxyClient.d.ts +0 -54
  1573. package/dist/lib/types/proxyClient.js +0 -2
  1574. package/dist/lib/types/rag.d.ts +0 -1332
  1575. package/dist/lib/types/rag.js +0 -2
  1576. package/dist/lib/types/realtime.d.ts +0 -243
  1577. package/dist/lib/types/realtime.js +0 -70
  1578. package/dist/lib/types/replicate.d.ts +0 -67
  1579. package/dist/lib/types/replicate.js +0 -10
  1580. package/dist/lib/types/requestRouter.d.ts +0 -75
  1581. package/dist/lib/types/requestRouter.js +0 -16
  1582. package/dist/lib/types/safeFetch.d.ts +0 -24
  1583. package/dist/lib/types/safeFetch.js +0 -7
  1584. package/dist/lib/types/scorer.d.ts +0 -564
  1585. package/dist/lib/types/scorer.js +0 -6
  1586. package/dist/lib/types/sdk.d.ts +0 -23
  1587. package/dist/lib/types/sdk.js +0 -9
  1588. package/dist/lib/types/server.d.ts +0 -1192
  1589. package/dist/lib/types/server.js +0 -68
  1590. package/dist/lib/types/service.d.ts +0 -79
  1591. package/dist/lib/types/service.js +0 -6
  1592. package/dist/lib/types/skills.d.ts +0 -427
  1593. package/dist/lib/types/skills.js +0 -17
  1594. package/dist/lib/types/span.d.ts +0 -247
  1595. package/dist/lib/types/span.js +0 -96
  1596. package/dist/lib/types/stream.d.ts +0 -771
  1597. package/dist/lib/types/stream.js +0 -2
  1598. package/dist/lib/types/streamDedup.d.ts +0 -14
  1599. package/dist/lib/types/streamDedup.js +0 -2
  1600. package/dist/lib/types/streaming.d.ts +0 -15
  1601. package/dist/lib/types/streaming.js +0 -2
  1602. package/dist/lib/types/stt.d.ts +0 -585
  1603. package/dist/lib/types/stt.js +0 -90
  1604. package/dist/lib/types/subscription.d.ts +0 -1064
  1605. package/dist/lib/types/subscription.js +0 -10
  1606. package/dist/lib/types/task.d.ts +0 -313
  1607. package/dist/lib/types/task.js +0 -37
  1608. package/dist/lib/types/taskClassification.d.ts +0 -52
  1609. package/dist/lib/types/taskClassification.js +0 -6
  1610. package/dist/lib/types/toolDedup.d.ts +0 -45
  1611. package/dist/lib/types/toolDedup.js +0 -14
  1612. package/dist/lib/types/toolResolution.d.ts +0 -83
  1613. package/dist/lib/types/toolResolution.js +0 -11
  1614. package/dist/lib/types/toolRouting.d.ts +0 -350
  1615. package/dist/lib/types/toolRouting.js +0 -19
  1616. package/dist/lib/types/tools.d.ts +0 -531
  1617. package/dist/lib/types/tools.js +0 -26
  1618. package/dist/lib/types/tts.d.ts +0 -195
  1619. package/dist/lib/types/tts.js +0 -65
  1620. package/dist/lib/types/utilities.d.ts +0 -310
  1621. package/dist/lib/types/utilities.js +0 -5
  1622. package/dist/lib/types/vectorStoreChroma.d.ts +0 -67
  1623. package/dist/lib/types/vectorStoreChroma.js +0 -12
  1624. package/dist/lib/types/vectorStorePinecone.d.ts +0 -48
  1625. package/dist/lib/types/vectorStorePinecone.js +0 -12
  1626. package/dist/lib/types/video.d.ts +0 -89
  1627. package/dist/lib/types/video.js +0 -15
  1628. package/dist/lib/types/voice.d.ts +0 -272
  1629. package/dist/lib/types/voice.js +0 -137
  1630. package/dist/lib/types/workflow.d.ts +0 -598
  1631. package/dist/lib/types/workflow.js +0 -24
  1632. package/dist/lib/utils/analyticsUtils.d.ts +0 -37
  1633. package/dist/lib/utils/analyticsUtils.js +0 -110
  1634. package/dist/lib/utils/anthropicCacheBreakpoints.d.ts +0 -43
  1635. package/dist/lib/utils/anthropicCacheBreakpoints.js +0 -151
  1636. package/dist/lib/utils/anthropicTraceSanitizer.d.ts +0 -7
  1637. package/dist/lib/utils/anthropicTraceSanitizer.js +0 -26
  1638. package/dist/lib/utils/async/delay.d.ts +0 -40
  1639. package/dist/lib/utils/async/delay.js +0 -43
  1640. package/dist/lib/utils/async/index.d.ts +0 -23
  1641. package/dist/lib/utils/async/index.js +0 -24
  1642. package/dist/lib/utils/async/retry.d.ts +0 -107
  1643. package/dist/lib/utils/async/retry.js +0 -172
  1644. package/dist/lib/utils/async/withTimeout.d.ts +0 -85
  1645. package/dist/lib/utils/async/withTimeout.js +0 -144
  1646. package/dist/lib/utils/asyncMutex.d.ts +0 -14
  1647. package/dist/lib/utils/asyncMutex.js +0 -61
  1648. package/dist/lib/utils/audioFormatDetector.d.ts +0 -15
  1649. package/dist/lib/utils/audioFormatDetector.js +0 -34
  1650. package/dist/lib/utils/avatarProcessor.d.ts +0 -78
  1651. package/dist/lib/utils/avatarProcessor.js +0 -173
  1652. package/dist/lib/utils/cloneOptions.d.ts +0 -36
  1653. package/dist/lib/utils/cloneOptions.js +0 -62
  1654. package/dist/lib/utils/conversationMemory.d.ts +0 -80
  1655. package/dist/lib/utils/conversationMemory.js +0 -670
  1656. package/dist/lib/utils/csvProcessor.d.ts +0 -221
  1657. package/dist/lib/utils/csvProcessor.js +0 -1527
  1658. package/dist/lib/utils/csvUtils.d.ts +0 -26
  1659. package/dist/lib/utils/csvUtils.js +0 -85
  1660. package/dist/lib/utils/errorClassifier.d.ts +0 -30
  1661. package/dist/lib/utils/errorClassifier.js +0 -183
  1662. package/dist/lib/utils/errorHandling.d.ts +0 -398
  1663. package/dist/lib/utils/errorHandling.js +0 -1282
  1664. package/dist/lib/utils/evaluationUtils.d.ts +0 -27
  1665. package/dist/lib/utils/evaluationUtils.js +0 -132
  1666. package/dist/lib/utils/factoryProcessing.d.ts +0 -71
  1667. package/dist/lib/utils/factoryProcessing.js +0 -590
  1668. package/dist/lib/utils/fileDetector.d.ts +0 -198
  1669. package/dist/lib/utils/fileDetector.js +0 -2806
  1670. package/dist/lib/utils/generation.d.ts +0 -8
  1671. package/dist/lib/utils/generation.js +0 -9
  1672. package/dist/lib/utils/generationErrors.d.ts +0 -10
  1673. package/dist/lib/utils/generationErrors.js +0 -11
  1674. package/dist/lib/utils/imageCache.d.ts +0 -124
  1675. package/dist/lib/utils/imageCache.js +0 -437
  1676. package/dist/lib/utils/imageDetection.d.ts +0 -15
  1677. package/dist/lib/utils/imageDetection.js +0 -53
  1678. package/dist/lib/utils/imageProcessor.d.ts +0 -296
  1679. package/dist/lib/utils/imageProcessor.js +0 -1158
  1680. package/dist/lib/utils/isoBmff.d.ts +0 -24
  1681. package/dist/lib/utils/isoBmff.js +0 -83
  1682. package/dist/lib/utils/json/coerce.d.ts +0 -30
  1683. package/dist/lib/utils/json/coerce.js +0 -412
  1684. package/dist/lib/utils/json/extract.d.ts +0 -112
  1685. package/dist/lib/utils/json/extract.js +0 -299
  1686. package/dist/lib/utils/json/index.d.ts +0 -36
  1687. package/dist/lib/utils/json/index.js +0 -37
  1688. package/dist/lib/utils/json/safeParse.d.ts +0 -130
  1689. package/dist/lib/utils/json/safeParse.js +0 -191
  1690. package/dist/lib/utils/lifecycleCallbacks.d.ts +0 -56
  1691. package/dist/lib/utils/lifecycleCallbacks.js +0 -100
  1692. package/dist/lib/utils/lifecycleTimeout.d.ts +0 -25
  1693. package/dist/lib/utils/lifecycleTimeout.js +0 -39
  1694. package/dist/lib/utils/logSanitize.d.ts +0 -285
  1695. package/dist/lib/utils/logSanitize.js +0 -555
  1696. package/dist/lib/utils/logger.d.ts +0 -273
  1697. package/dist/lib/utils/logger.js +0 -516
  1698. package/dist/lib/utils/loggingFetch.d.ts +0 -29
  1699. package/dist/lib/utils/loggingFetch.js +0 -60
  1700. package/dist/lib/utils/loopUtils.d.ts +0 -70
  1701. package/dist/lib/utils/loopUtils.js +0 -263
  1702. package/dist/lib/utils/markupSniff.d.ts +0 -37
  1703. package/dist/lib/utils/markupSniff.js +0 -125
  1704. package/dist/lib/utils/mcpDefaults.d.ts +0 -54
  1705. package/dist/lib/utils/mcpDefaults.js +0 -135
  1706. package/dist/lib/utils/mcpErrorText.d.ts +0 -37
  1707. package/dist/lib/utils/mcpErrorText.js +0 -95
  1708. package/dist/lib/utils/mediaDuration.d.ts +0 -23
  1709. package/dist/lib/utils/mediaDuration.js +0 -45
  1710. package/dist/lib/utils/messageBuilder.d.ts +0 -59
  1711. package/dist/lib/utils/messageBuilder.js +0 -2716
  1712. package/dist/lib/utils/mimeTypeHints.d.ts +0 -40
  1713. package/dist/lib/utils/mimeTypeHints.js +0 -122
  1714. package/dist/lib/utils/modelAliasResolver.d.ts +0 -17
  1715. package/dist/lib/utils/modelAliasResolver.js +0 -55
  1716. package/dist/lib/utils/modelChoices.d.ts +0 -75
  1717. package/dist/lib/utils/modelChoices.js +0 -698
  1718. package/dist/lib/utils/modelDetection.d.ts +0 -37
  1719. package/dist/lib/utils/modelDetection.js +0 -131
  1720. package/dist/lib/utils/modelRouter.d.ts +0 -91
  1721. package/dist/lib/utils/modelRouter.js +0 -293
  1722. package/dist/lib/utils/multimodalOptionsBuilder.d.ts +0 -74
  1723. package/dist/lib/utils/multimodalOptionsBuilder.js +0 -74
  1724. package/dist/lib/utils/musicProcessor.d.ts +0 -77
  1725. package/dist/lib/utils/musicProcessor.js +0 -190
  1726. package/dist/lib/utils/noOutputSentinel.d.ts +0 -67
  1727. package/dist/lib/utils/noOutputSentinel.js +0 -180
  1728. package/dist/lib/utils/observabilityHelpers.d.ts +0 -27
  1729. package/dist/lib/utils/observabilityHelpers.js +0 -48
  1730. package/dist/lib/utils/optionsConversion.d.ts +0 -47
  1731. package/dist/lib/utils/optionsConversion.js +0 -128
  1732. package/dist/lib/utils/optionsUtils.d.ts +0 -175
  1733. package/dist/lib/utils/optionsUtils.js +0 -970
  1734. package/dist/lib/utils/parameterValidation.d.ts +0 -200
  1735. package/dist/lib/utils/parameterValidation.js +0 -981
  1736. package/dist/lib/utils/pdfProcessor.d.ts +0 -137
  1737. package/dist/lib/utils/pdfProcessor.js +0 -689
  1738. package/dist/lib/utils/performance.d.ts +0 -93
  1739. package/dist/lib/utils/performance.js +0 -223
  1740. package/dist/lib/utils/piiDetector.d.ts +0 -24
  1741. package/dist/lib/utils/piiDetector.js +0 -221
  1742. package/dist/lib/utils/pricing.d.ts +0 -17
  1743. package/dist/lib/utils/pricing.js +0 -755
  1744. package/dist/lib/utils/promptRedaction.d.ts +0 -22
  1745. package/dist/lib/utils/promptRedaction.js +0 -63
  1746. package/dist/lib/utils/providerConfig.d.ts +0 -393
  1747. package/dist/lib/utils/providerConfig.js +0 -1363
  1748. package/dist/lib/utils/providerErrorClassification.d.ts +0 -58
  1749. package/dist/lib/utils/providerErrorClassification.js +0 -149
  1750. package/dist/lib/utils/providerHealth.d.ts +0 -253
  1751. package/dist/lib/utils/providerHealth.js +0 -1479
  1752. package/dist/lib/utils/providerRetry.d.ts +0 -68
  1753. package/dist/lib/utils/providerRetry.js +0 -230
  1754. package/dist/lib/utils/providerSetupMessages.d.ts +0 -8
  1755. package/dist/lib/utils/providerSetupMessages.js +0 -122
  1756. package/dist/lib/utils/providerUtils.d.ts +0 -38
  1757. package/dist/lib/utils/providerUtils.js +0 -366
  1758. package/dist/lib/utils/rateLimiter.d.ts +0 -75
  1759. package/dist/lib/utils/rateLimiter.js +0 -201
  1760. package/dist/lib/utils/redis.d.ts +0 -119
  1761. package/dist/lib/utils/redis.js +0 -530
  1762. package/dist/lib/utils/responseValidator.d.ts +0 -21
  1763. package/dist/lib/utils/responseValidator.js +0 -354
  1764. package/dist/lib/utils/retryAfter.d.ts +0 -7
  1765. package/dist/lib/utils/retryAfter.js +0 -44
  1766. package/dist/lib/utils/retryHandler.d.ts +0 -82
  1767. package/dist/lib/utils/retryHandler.js +0 -270
  1768. package/dist/lib/utils/retryability.d.ts +0 -27
  1769. package/dist/lib/utils/retryability.js +0 -45
  1770. package/dist/lib/utils/safeFetch.d.ts +0 -26
  1771. package/dist/lib/utils/safeFetch.js +0 -121
  1772. package/dist/lib/utils/sanitizers/filename.d.ts +0 -116
  1773. package/dist/lib/utils/sanitizers/filename.js +0 -366
  1774. package/dist/lib/utils/sanitizers/html.d.ts +0 -170
  1775. package/dist/lib/utils/sanitizers/html.js +0 -326
  1776. package/dist/lib/utils/sanitizers/index.d.ts +0 -26
  1777. package/dist/lib/utils/sanitizers/index.js +0 -30
  1778. package/dist/lib/utils/sanitizers/svg.d.ts +0 -71
  1779. package/dist/lib/utils/sanitizers/svg.js +0 -482
  1780. package/dist/lib/utils/schemaConversion.d.ts +0 -56
  1781. package/dist/lib/utils/schemaConversion.js +0 -656
  1782. package/dist/lib/utils/sizeGuard.d.ts +0 -34
  1783. package/dist/lib/utils/sizeGuard.js +0 -45
  1784. package/dist/lib/utils/ssrfGuard.d.ts +0 -60
  1785. package/dist/lib/utils/ssrfGuard.js +0 -446
  1786. package/dist/lib/utils/sttProcessor.d.ts +0 -125
  1787. package/dist/lib/utils/sttProcessor.js +0 -301
  1788. package/dist/lib/utils/systemMessages.d.ts +0 -29
  1789. package/dist/lib/utils/systemMessages.js +0 -45
  1790. package/dist/lib/utils/taskClassificationUtils.d.ts +0 -55
  1791. package/dist/lib/utils/taskClassificationUtils.js +0 -150
  1792. package/dist/lib/utils/taskClassifier.d.ts +0 -23
  1793. package/dist/lib/utils/taskClassifier.js +0 -95
  1794. package/dist/lib/utils/textEncoding.d.ts +0 -25
  1795. package/dist/lib/utils/textEncoding.js +0 -141
  1796. package/dist/lib/utils/thinkingConfig.d.ts +0 -76
  1797. package/dist/lib/utils/thinkingConfig.js +0 -105
  1798. package/dist/lib/utils/timeout.d.ts +0 -158
  1799. package/dist/lib/utils/timeout.js +0 -427
  1800. package/dist/lib/utils/tokenEstimation.d.ts +0 -90
  1801. package/dist/lib/utils/tokenEstimation.js +0 -187
  1802. package/dist/lib/utils/tokenLimits.d.ts +0 -53
  1803. package/dist/lib/utils/tokenLimits.js +0 -236
  1804. package/dist/lib/utils/tokenUtils.d.ts +0 -101
  1805. package/dist/lib/utils/tokenUtils.js +0 -323
  1806. package/dist/lib/utils/tool.d.ts +0 -8
  1807. package/dist/lib/utils/tool.js +0 -9
  1808. package/dist/lib/utils/toolCallRepair.d.ts +0 -14
  1809. package/dist/lib/utils/toolCallRepair.js +0 -286
  1810. package/dist/lib/utils/toolChoice.d.ts +0 -4
  1811. package/dist/lib/utils/toolChoice.js +0 -7
  1812. package/dist/lib/utils/toolEndEmitter.d.ts +0 -25
  1813. package/dist/lib/utils/toolEndEmitter.js +0 -65
  1814. package/dist/lib/utils/toolUtils.d.ts +0 -40
  1815. package/dist/lib/utils/toolUtils.js +0 -76
  1816. package/dist/lib/utils/transformationUtils.d.ts +0 -218
  1817. package/dist/lib/utils/transformationUtils.js +0 -578
  1818. package/dist/lib/utils/tripwireEvaluator.d.ts +0 -73
  1819. package/dist/lib/utils/tripwireEvaluator.js +0 -285
  1820. package/dist/lib/utils/tryImport.d.ts +0 -35
  1821. package/dist/lib/utils/tryImport.js +0 -95
  1822. package/dist/lib/utils/ttsProcessor.d.ts +0 -159
  1823. package/dist/lib/utils/ttsProcessor.js +0 -293
  1824. package/dist/lib/utils/typeUtils.d.ts +0 -77
  1825. package/dist/lib/utils/typeUtils.js +0 -98
  1826. package/dist/lib/utils/videoAnalysisProcessor.d.ts +0 -24
  1827. package/dist/lib/utils/videoAnalysisProcessor.js +0 -61
  1828. package/dist/lib/utils/videoProcessor.d.ts +0 -64
  1829. package/dist/lib/utils/videoProcessor.js +0 -196
  1830. package/dist/lib/voice/RealtimeVoiceAPI.d.ts +0 -186
  1831. package/dist/lib/voice/RealtimeVoiceAPI.js +0 -431
  1832. package/dist/lib/voice/audio-utils.d.ts +0 -135
  1833. package/dist/lib/voice/audio-utils.js +0 -435
  1834. package/dist/lib/voice/errors.d.ts +0 -123
  1835. package/dist/lib/voice/errors.js +0 -386
  1836. package/dist/lib/voice/index.d.ts +0 -49
  1837. package/dist/lib/voice/index.js +0 -177
  1838. package/dist/lib/voice/livekit/brain.d.ts +0 -21
  1839. package/dist/lib/voice/livekit/brain.js +0 -75
  1840. package/dist/lib/voice/livekit/config.d.ts +0 -52
  1841. package/dist/lib/voice/livekit/config.js +0 -134
  1842. package/dist/lib/voice/livekit/eventBridge.d.ts +0 -27
  1843. package/dist/lib/voice/livekit/eventBridge.js +0 -360
  1844. package/dist/lib/voice/livekit/index.d.ts +0 -22
  1845. package/dist/lib/voice/livekit/index.js +0 -23
  1846. package/dist/lib/voice/livekit/realtimeEventBridge.d.ts +0 -14
  1847. package/dist/lib/voice/livekit/realtimeEventBridge.js +0 -161
  1848. package/dist/lib/voice/livekit/realtimeMcpTools.d.ts +0 -31
  1849. package/dist/lib/voice/livekit/realtimeMcpTools.js +0 -206
  1850. package/dist/lib/voice/livekit/realtimeVoiceAgent.d.ts +0 -26
  1851. package/dist/lib/voice/livekit/realtimeVoiceAgent.js +0 -365
  1852. package/dist/lib/voice/livekit/roomContext.d.ts +0 -23
  1853. package/dist/lib/voice/livekit/roomContext.js +0 -57
  1854. package/dist/lib/voice/livekit/roomDispatch.d.ts +0 -24
  1855. package/dist/lib/voice/livekit/roomDispatch.js +0 -31
  1856. package/dist/lib/voice/livekit/schemaSanitizer.d.ts +0 -26
  1857. package/dist/lib/voice/livekit/schemaSanitizer.js +0 -144
  1858. package/dist/lib/voice/livekit/tokens.d.ts +0 -19
  1859. package/dist/lib/voice/livekit/tokens.js +0 -51
  1860. package/dist/lib/voice/livekit/vertexAuth.d.ts +0 -30
  1861. package/dist/lib/voice/livekit/vertexAuth.js +0 -73
  1862. package/dist/lib/voice/livekit/voiceAgent.d.ts +0 -32
  1863. package/dist/lib/voice/livekit/voiceAgent.js +0 -425
  1864. package/dist/lib/voice/livekit/voiceAgentWorker.d.ts +0 -29
  1865. package/dist/lib/voice/livekit/voiceAgentWorker.js +0 -122
  1866. package/dist/lib/voice/providers/AzureSTT.d.ts +0 -47
  1867. package/dist/lib/voice/providers/AzureSTT.js +0 -345
  1868. package/dist/lib/voice/providers/AzureTTS.d.ts +0 -59
  1869. package/dist/lib/voice/providers/AzureTTS.js +0 -349
  1870. package/dist/lib/voice/providers/CartesiaTTS.d.ts +0 -31
  1871. package/dist/lib/voice/providers/CartesiaTTS.js +0 -189
  1872. package/dist/lib/voice/providers/DeepgramSTT.d.ts +0 -40
  1873. package/dist/lib/voice/providers/DeepgramSTT.js +0 -550
  1874. package/dist/lib/voice/providers/ElevenLabsTTS.d.ts +0 -53
  1875. package/dist/lib/voice/providers/ElevenLabsTTS.js +0 -311
  1876. package/dist/lib/voice/providers/FishAudioTTS.d.ts +0 -27
  1877. package/dist/lib/voice/providers/FishAudioTTS.js +0 -183
  1878. package/dist/lib/voice/providers/GeminiLive.d.ts +0 -52
  1879. package/dist/lib/voice/providers/GeminiLive.js +0 -372
  1880. package/dist/lib/voice/providers/GoogleSTT.d.ts +0 -60
  1881. package/dist/lib/voice/providers/GoogleSTT.js +0 -454
  1882. package/dist/lib/voice/providers/OpenAIRealtime.d.ts +0 -47
  1883. package/dist/lib/voice/providers/OpenAIRealtime.js +0 -412
  1884. package/dist/lib/voice/providers/OpenAISTT.d.ts +0 -41
  1885. package/dist/lib/voice/providers/OpenAISTT.js +0 -286
  1886. package/dist/lib/voice/providers/OpenAITTS.d.ts +0 -55
  1887. package/dist/lib/voice/providers/OpenAITTS.js +0 -285
  1888. package/dist/lib/voice/stream-handler.d.ts +0 -166
  1889. package/dist/lib/voice/stream-handler.js +0 -514
  1890. package/dist/lib/workflow/LAYER-EXAMPLES.d.ts +0 -13
  1891. package/dist/lib/workflow/LAYER-EXAMPLES.js +0 -312
  1892. package/dist/lib/workflow/PROMPT-EXAMPLES.d.ts +0 -117
  1893. package/dist/lib/workflow/PROMPT-EXAMPLES.js +0 -246
  1894. package/dist/lib/workflow/config.d.ts +0 -376
  1895. package/dist/lib/workflow/config.js +0 -399
  1896. package/dist/lib/workflow/core/ensembleExecutor.d.ts +0 -55
  1897. package/dist/lib/workflow/core/ensembleExecutor.js +0 -451
  1898. package/dist/lib/workflow/core/judgeScorer.d.ts +0 -25
  1899. package/dist/lib/workflow/core/judgeScorer.js +0 -568
  1900. package/dist/lib/workflow/core/responseConditioner.d.ts +0 -21
  1901. package/dist/lib/workflow/core/responseConditioner.js +0 -243
  1902. package/dist/lib/workflow/core/workflowRegistry.d.ts +0 -72
  1903. package/dist/lib/workflow/core/workflowRegistry.js +0 -305
  1904. package/dist/lib/workflow/core/workflowRunner.d.ts +0 -61
  1905. package/dist/lib/workflow/core/workflowRunner.js +0 -642
  1906. package/dist/lib/workflow/index.d.ts +0 -21
  1907. package/dist/lib/workflow/index.js +0 -46
  1908. package/dist/lib/workflow/utils/workflowMetrics.d.ts +0 -74
  1909. package/dist/lib/workflow/utils/workflowMetrics.js +0 -312
  1910. package/dist/lib/workflow/utils/workflowValidation.d.ts +0 -29
  1911. package/dist/lib/workflow/utils/workflowValidation.js +0 -421
  1912. package/dist/lib/workflow/workflows/adaptiveWorkflow.d.ts +0 -72
  1913. package/dist/lib/workflow/workflows/adaptiveWorkflow.js +0 -367
  1914. package/dist/lib/workflow/workflows/consensusWorkflow.d.ts +0 -69
  1915. package/dist/lib/workflow/workflows/consensusWorkflow.js +0 -193
  1916. package/dist/lib/workflow/workflows/fallbackWorkflow.d.ts +0 -49
  1917. package/dist/lib/workflow/workflows/fallbackWorkflow.js +0 -226
  1918. package/dist/lib/workflow/workflows/multiJudgeWorkflow.d.ts +0 -70
  1919. package/dist/lib/workflow/workflows/multiJudgeWorkflow.js +0 -352
  1920. package/dist/providers/googleVertex/utils.d.ts +0 -12
  1921. package/dist/providers/googleVertex/utils.js +0 -286
@@ -1,2806 +0,0 @@
1
- /**
2
- * File Type Detection Utility
3
- * Centralized file detection for all multimodal file types
4
- * Uses multi-strategy approach for reliable type identification
5
- */
6
- import { open, readFile, realpath } from "fs/promises";
7
- import { basename, isAbsolute as isAbsolutePath, relative as relativePath, resolve as resolvePath, sep, } from "path";
8
- import { getGlobalDispatcher, interceptors, request } from "undici";
9
- // Lazy-loaded processor singletons — avoids loading heavy media deps
10
- // (mediabunny, fluent-ffmpeg, music-metadata, adm-zip) on every generate() call.
11
- async function getVideoProcessor() {
12
- const mod = await import("../processors/media/VideoProcessor.js");
13
- return mod.videoProcessor;
14
- }
15
- async function getAudioProcessor() {
16
- const mod = await import("../processors/media/AudioProcessor.js");
17
- return mod.audioProcessor;
18
- }
19
- async function getArchiveProcessor() {
20
- const mod = await import("../processors/archive/ArchiveProcessor.js");
21
- return mod.archiveProcessor;
22
- }
23
- import { tracers, ATTR, withSpan } from "../telemetry/index.js";
24
- import { CONFIG_EXTENSIONS } from "../processors/config/fileExtensions.js";
25
- import { fileTypeForExtension, lookupByMimeType, normalizeExtension, } from "../processors/config/fileTypeRegistry.js";
26
- import { LANGUAGE_MAP } from "../processors/config/languageMap.js";
27
- import { getMimeTypeForExtension, TEXT_EXTENSION_MIME_MAP, } from "../processors/config/mimeConstants.js";
28
- import { CSVProcessor } from "./csvProcessor.js";
29
- import { withRetry } from "../core/infrastructure/retry.js";
30
- import { ImageProcessor } from "./imageProcessor.js";
31
- import { detectIsoBmffImageMimeType, hasFtypBoxSignature } from "./isoBmff.js";
32
- import { logger } from "./logger.js";
33
- import { looksLikeSvgMarkup } from "./markupSniff.js";
34
- import { withTimeout } from "./errorHandling.js";
35
- import { normalizeUrlForCache, redactUrlForError, sanitizeErrorCause, } from "./logSanitize.js";
36
- import { mimeHintToExtension, mimeHintToFileType, normalizeMimeHint, } from "./mimeTypeHints.js";
37
- import { PDFProcessor } from "./pdfProcessor.js";
38
- /**
39
- * Short-TTL cache of URL → Content-Type (#323). A URL is commonly detected more
40
- * than once (repeated multimodal prompts reuse the same asset URL); caching the
41
- * HEAD's content-type avoids re-issuing the HEAD each time. `loadFromURL` also
42
- * populates it from its GET response, so once a URL's body has been fetched a
43
- * subsequent detection needs no network round-trip at all.
44
- *
45
- * Trade-off (round-2 review): this is a module-level cache shared by every
46
- * request in the process, and correctness relies solely on the 60s TTL — a
47
- * signed URL whose response changes at the same path within that window would
48
- * read stale. That is an intentional, bounded trade-off (60s of possible
49
- * staleness for far fewer HEAD round-trips), not a freshness guarantee.
50
- * Expired entries are removed lazily on their next `get()` (see
51
- * `getCachedUrlContentType`); `setCachedUrlContentType` additionally sweeps
52
- * expired entries opportunistically once the cache hits its size cap, so a
53
- * URL that is cached once and never looked up again doesn't linger until the
54
- * FIFO eviction below forces it out.
55
- */
56
- const URL_CONTENT_TYPE_TTL_MS = 60_000;
57
- const URL_CONTENT_TYPE_CACHE_MAX_SIZE = 512;
58
- const urlContentTypeCache = new Map();
59
- /**
60
- * Build the Map key for `urlContentTypeCache`. Delegates to the shared
61
- * {@link normalizeUrlForCache} — this is a module-level, process-lifetime
62
- * cache, so it must strip presigned-URL auth/signature query params (see
63
- * `SENSITIVE_URL_QUERY_PARAM_DENYLIST`) the same way `ImageCache.normalizeUrl`
64
- * does, folding a short hash of the stripped params into the key whenever any
65
- * were present so two different presigned URLs for the same path don't
66
- * collide and serve each other's cached content-type across auth contexts.
67
- * Also strips tracking/analytics params first, so two URLs differing only by
68
- * tracking noise (e.g. `utm_source`) still hit the same cache entry instead
69
- * of missing each other. Falls back to the raw URL if it isn't a parseable
70
- * absolute URL. Shared by both `getCachedUrlContentType` and
71
- * `setCachedUrlContentType` so lookups and writes always agree on the key.
72
- */
73
- function cacheKeyForUrl(url) {
74
- return normalizeUrlForCache(url);
75
- }
76
- function getCachedUrlContentType(url, now) {
77
- const key = cacheKeyForUrl(url);
78
- const hit = urlContentTypeCache.get(key);
79
- if (hit && hit.expiresAt > now) {
80
- // Bump recency: Map iteration order follows insertion order, and the
81
- // eviction below deletes the *first* key, so a plain `get` on a hot
82
- // entry would leave it first in line for eviction despite being the
83
- // most recently used. Re-inserting turns the size-bounded FIFO below
84
- // into an actual LRU.
85
- urlContentTypeCache.delete(key);
86
- urlContentTypeCache.set(key, hit);
87
- return hit.contentType;
88
- }
89
- if (hit) {
90
- // Entry exists but its TTL has passed — treat as a miss and evict it
91
- // immediately rather than serving (or retaining) stale data.
92
- urlContentTypeCache.delete(key);
93
- }
94
- return undefined;
95
- }
96
- /**
97
- * Opportunistically remove already-expired entries. Only called once the
98
- * cache is at its size cap (see `setCachedUrlContentType`) so it doesn't add
99
- * an O(n) scan to the common-case hot path.
100
- */
101
- function pruneExpiredUrlContentTypeEntries(now) {
102
- for (const [key, entry] of urlContentTypeCache) {
103
- if (entry.expiresAt <= now) {
104
- urlContentTypeCache.delete(key);
105
- }
106
- }
107
- }
108
- function setCachedUrlContentType(url, contentType, now) {
109
- if (!contentType) {
110
- return;
111
- }
112
- const key = cacheKeyForUrl(url);
113
- urlContentTypeCache.set(key, {
114
- contentType,
115
- expiresAt: now + URL_CONTENT_TYPE_TTL_MS,
116
- });
117
- // Bound the cache so a long-lived process can't grow it unbounded. Prefer
118
- // reclaiming already-expired entries first; only fall back to evicting the
119
- // oldest still-live entry (FIFO/LRU-ish, see getCachedUrlContentType) if
120
- // the cache is still over the cap after pruning.
121
- if (urlContentTypeCache.size > URL_CONTENT_TYPE_CACHE_MAX_SIZE) {
122
- pruneExpiredUrlContentTypeEntries(now);
123
- }
124
- if (urlContentTypeCache.size > URL_CONTENT_TYPE_CACHE_MAX_SIZE) {
125
- const oldest = urlContentTypeCache.keys().next().value;
126
- if (oldest !== undefined) {
127
- urlContentTypeCache.delete(oldest);
128
- }
129
- }
130
- }
131
- /**
132
- * Retryable network error codes (Node.js/undici network errors)
133
- */
134
- const RETRYABLE_ERROR_CODES = [
135
- "ETIMEDOUT",
136
- "ECONNRESET",
137
- "ECONNREFUSED",
138
- "ENOTFOUND",
139
- "ENETUNREACH",
140
- "EAI_AGAIN",
141
- "EPIPE",
142
- "ECONNABORTED",
143
- "UND_ERR_CONNECT_TIMEOUT",
144
- "UND_ERR_HEADERS_TIMEOUT",
145
- "UND_ERR_BODY_TIMEOUT",
146
- "UND_ERR_SOCKET",
147
- ];
148
- /**
149
- * Non-retryable HTTP status codes (client errors)
150
- */
151
- const NON_RETRYABLE_STATUS_CODES = [400, 401, 403, 404, 405];
152
- /**
153
- * Retryable HTTP status codes (server errors + rate limiting)
154
- */
155
- const RETRYABLE_STATUS_CODES = [429, 500, 502, 503, 504];
156
- /**
157
- * Check if an error is a recoverable network error that should be retried
158
- *
159
- * @param error - Error to check
160
- * @returns True if error is retryable (transient network issue)
161
- */
162
- function isRetryableNetworkError(error) {
163
- if (!(error instanceof Error)) {
164
- return false;
165
- }
166
- const errorMessage = error.message.toLowerCase();
167
- // Extract error code from various error shapes
168
- const errorWithCode = error;
169
- const errorCode = errorWithCode.code?.toUpperCase();
170
- // Check for retryable network error codes
171
- if (errorCode && RETRYABLE_ERROR_CODES.includes(errorCode)) {
172
- return true;
173
- }
174
- // Check HTTP status code if present in error message (e.g., "HTTP 503")
175
- const httpStatusMatch = errorMessage.match(/http\s*(\d{3})/);
176
- if (httpStatusMatch) {
177
- const statusCode = parseInt(httpStatusMatch[1], 10);
178
- if (NON_RETRYABLE_STATUS_CODES.includes(statusCode)) {
179
- return false;
180
- }
181
- if (RETRYABLE_STATUS_CODES.includes(statusCode)) {
182
- return true;
183
- }
184
- }
185
- // Check error message for transient issues
186
- const transientKeywords = [
187
- "timeout",
188
- "timed out",
189
- "connection reset",
190
- "econnreset",
191
- "etimedout",
192
- "network error",
193
- "socket hang up",
194
- "enotfound",
195
- "getaddrinfo",
196
- "unavailable",
197
- "service unavailable",
198
- ];
199
- return transientKeywords.some((keyword) => errorMessage.includes(keyword));
200
- }
201
- /**
202
- * Check if text has JSON markers (starts with { or [ and ends with corresponding closing bracket)
203
- */
204
- function hasJsonMarkers(text) {
205
- const trimmed = text.trim();
206
- if (!trimmed) {
207
- return false;
208
- }
209
- const firstChar = trimmed[0];
210
- const lastChar = trimmed[trimmed.length - 1];
211
- const hasMatchingBrackets = (firstChar === "{" && lastChar === "}") ||
212
- (firstChar === "[" && lastChar === "]");
213
- if (!hasMatchingBrackets) {
214
- return false;
215
- }
216
- try {
217
- JSON.parse(trimmed);
218
- return true;
219
- }
220
- catch {
221
- return false;
222
- }
223
- }
224
- /**
225
- * Format file size in human-readable units
226
- */
227
- function formatFileSize(bytes) {
228
- if (bytes < 1024) {
229
- return `${bytes} bytes`;
230
- }
231
- if (bytes < 1024 * 1024) {
232
- return `${(bytes / 1024).toFixed(2)} KB`;
233
- }
234
- if (bytes < 1024 * 1024 * 1024) {
235
- return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
236
- }
237
- return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
238
- }
239
- /**
240
- * Centralized file type detection and processing
241
- *
242
- * @example
243
- * ```typescript
244
- * // Auto-detect and process any file
245
- * const result = await FileDetector.detectAndProcess("data.csv");
246
- * logger.info(result.type); // 'csv'
247
- * ```
248
- */
249
- export class FileDetector {
250
- // FD-017: Replace hardcoded timeouts with constants.
251
- // These default ensure consistent timeout behavior across all file-detection logic.
252
- static DEFAULT_NETWORK_TIMEOUT = 30000; // 30 seconds
253
- static DEFAULT_HEAD_TIMEOUT = 5000; // 5 seconds
254
- /**
255
- * Ceiling on an in-process document parse (unzip + XML walk). Generous
256
- * relative to the work, because the cost of firing early on a large but
257
- * legitimate file is a lost extraction, while the cost of never firing is a
258
- * held request.
259
- */
260
- static DEFAULT_DOCUMENT_TIMEOUT = 30000; // 30 seconds
261
- /**
262
- * Auto-detect file type and process in one call
263
- *
264
- * Runs detection strategies in priority order:
265
- * 1. MagicBytesStrategy (95% confidence) - Binary file headers
266
- * 2. MimeTypeStrategy (85% confidence) - HTTP Content-Type for URLs
267
- * 3. ExtensionStrategy (70% confidence) - File extension
268
- * 4. ContentHeuristicStrategy (75% confidence) - Content analysis
269
- *
270
- * @param input - File path, URL, Buffer, or data URI
271
- * @param options - Detection and processing options
272
- * @returns Processed file result with type and content
273
- */
274
- static async detectAndProcess(input, options) {
275
- // Derive filename and size for tracing before detection runs
276
- const inputFilename = FileDetector.deriveInputFilename(input);
277
- const inputSizeBytes = FileDetector.deriveInputSize(input);
278
- return withSpan({
279
- name: "neurolink.file.detect_and_process",
280
- tracer: tracers.file,
281
- attributes: {
282
- [ATTR.FILE_NAME]: inputFilename,
283
- [ATTR.FILE_SIZE_BYTES]: inputSizeBytes,
284
- },
285
- }, async (span) => {
286
- const detection = await FileDetector.detect(input, options);
287
- span.setAttribute(ATTR.FILE_CATEGORY, detection.type);
288
- span.setAttribute(ATTR.FILE_MIMETYPE, detection.mimeType || "unknown");
289
- span.setAttribute(ATTR.FILE_CONFIDENCE, detection.metadata.confidence);
290
- logger.info(`[NEUROLINK] File detected: ${inputFilename} (${detection.mimeType || "unknown"}, ${formatFileSize(inputSizeBytes)}) → category: ${detection.type}`);
291
- // FD-018: Comprehensive fallback parsing for extension-less files
292
- if (options?.allowedTypes &&
293
- !options.allowedTypes.includes(detection.type)) {
294
- const content = await FileDetector.loadContent(input, detection, options);
295
- const errors = [];
296
- for (const allowedType of options.allowedTypes) {
297
- try {
298
- const result = await FileDetector.tryFallbackParsing(content, allowedType, options);
299
- if (result) {
300
- logger.info(`[FileDetector] ✅ ${allowedType.toUpperCase()} fallback successful`);
301
- const outputLength = typeof result.content === "string"
302
- ? result.content.length
303
- : result.content?.length || 0;
304
- span.setAttribute(ATTR.FILE_OUTPUT_LENGTH, outputLength);
305
- span.setAttribute(ATTR.FILE_SUCCESS, true);
306
- span.setAttribute(ATTR.FILE_PROCESSOR_USED, `fallback:${allowedType}`);
307
- logger.info(`[NEUROLINK] File processed: ${inputFilename} → ${outputLength} bytes output (fallback: ${allowedType})`);
308
- return result;
309
- }
310
- }
311
- catch (error) {
312
- const errorMsg = error instanceof Error ? error.message : String(error);
313
- errors.push(`${allowedType}: ${errorMsg}`);
314
- logger.debug(`[FileDetector] ${allowedType} fallback failed: ${errorMsg}`);
315
- }
316
- }
317
- logger.warn(`[FileDetector] All fallback parsing failed for type "${detection.type}". ` +
318
- `Attempted: ${options.allowedTypes.join(", ")}. Falling through to universal handler.`);
319
- const csvOptions = options?.csvOptions;
320
- const result = await FileDetector.processFile(content, detection, csvOptions, options?.provider, options?.videoOptions);
321
- FileDetector.setFileResultSpanAttributes(span, result, inputFilename, detection.type);
322
- return result;
323
- }
324
- const content = await FileDetector.loadContent(input, detection, options);
325
- const csvOptions = options?.csvOptions;
326
- const result = await FileDetector.processFile(content, detection, csvOptions, options?.provider, options?.videoOptions);
327
- FileDetector.setFileResultSpanAttributes(span, result, inputFilename, detection.type);
328
- return result;
329
- });
330
- }
331
- /**
332
- * Set span attributes and log after file processing completes.
333
- */
334
- static setFileResultSpanAttributes(span, result, filename, processorType) {
335
- const outputLength = typeof result.content === "string"
336
- ? result.content.length
337
- : result.content?.length || 0;
338
- const hasImages = Array.isArray(result.images)
339
- ? result.images.length > 0
340
- : false;
341
- const imageCount = Array.isArray(result.images)
342
- ? result.images.length
343
- : 0;
344
- span.setAttribute(ATTR.FILE_OUTPUT_LENGTH, outputLength);
345
- span.setAttribute(ATTR.FILE_SUCCESS, true);
346
- span.setAttribute(ATTR.FILE_PROCESSOR_USED, processorType);
347
- span.setAttribute(ATTR.FILE_HAS_IMAGES, hasImages);
348
- span.setAttribute(ATTR.FILE_IMAGE_COUNT, imageCount);
349
- logger.info(`[NEUROLINK] File processed: ${filename} → ${outputLength} bytes output` +
350
- (imageCount > 0 ? ` + ${imageCount} image(s)` : "") +
351
- ` (processor: ${processorType})`);
352
- }
353
- /**
354
- * Derive a human-readable filename from FileInput for tracing.
355
- */
356
- static deriveInputFilename(input) {
357
- if (typeof input === "string") {
358
- if (input.startsWith("data:")) {
359
- return "data-uri";
360
- }
361
- if (input.startsWith("http")) {
362
- try {
363
- return new URL(input).pathname.split("/").pop() || "url-file";
364
- }
365
- catch {
366
- return "url-file";
367
- }
368
- }
369
- // File path
370
- return input.split("/").pop() || input.split("\\").pop() || "file";
371
- }
372
- if (Buffer.isBuffer(input)) {
373
- return "buffer";
374
- }
375
- // Everything left is a `FileWithMetadata`, which states its own name, and
376
- // `withResolvedExtension` reads this to recover an extension when a
377
- // content-based strategy reported none. Falling straight through to
378
- // "unknown-input" threw that name away, so an `.odp`, `.rtf` or `.tar`
379
- // supplied as bytes-plus-name lost the extension its processor routes on.
380
- // Still defensive about the value: the type says required, callers are
381
- // untyped JavaScript often enough.
382
- return input?.filename || "unknown-input";
383
- }
384
- /**
385
- * Derive byte size from FileInput for tracing.
386
- */
387
- static deriveInputSize(input) {
388
- if (Buffer.isBuffer(input)) {
389
- return input.length;
390
- }
391
- if (typeof input === "string") {
392
- if (input.startsWith("data:")) {
393
- // Rough estimate: base64 is ~4/3 of raw
394
- const base64Part = input.split(",")[1];
395
- return base64Part ? Math.floor((base64Part.length * 3) / 4) : 0;
396
- }
397
- return input.length; // path or URL string length (not file size)
398
- }
399
- return 0;
400
- }
401
- /**
402
- * Classify a FileInput into the FileSource enum used by downstream
403
- * loaders. Keeps the mimetype-hint short-circuit in detect() able to
404
- * produce a valid FileDetectionResult without re-implementing the
405
- * source-inference rules scattered across loadContent().
406
- */
407
- static deriveInputSource(input) {
408
- if (Buffer.isBuffer(input)) {
409
- return "buffer";
410
- }
411
- if (typeof input === "string") {
412
- if (input.startsWith("data:")) {
413
- return "datauri";
414
- }
415
- if (input.startsWith("http://") || input.startsWith("https://")) {
416
- return "url";
417
- }
418
- return "path";
419
- }
420
- return "buffer";
421
- }
422
- /**
423
- * Try fallback parsing for a specific file type
424
- * Used when file detection returns "unknown" but we want to try parsing anyway
425
- */
426
- static async tryFallbackParsing(content, fileType, options) {
427
- logger.info(`[FileDetector] Attempting ${fileType.toUpperCase()} fallback parsing`);
428
- switch (fileType) {
429
- case "csv": {
430
- // Try CSV parsing
431
- const csvOptions = options?.csvOptions;
432
- const result = await CSVProcessor.process(content, csvOptions);
433
- logger.info(`[FileDetector] CSV fallback: ${result.metadata?.rowCount || 0} rows, ${result.metadata?.columnCount || 0} columns`);
434
- return result;
435
- }
436
- case "text": {
437
- // Try text parsing - check if content is valid UTF-8 text
438
- const textContent = content.toString("utf-8");
439
- // Validate it's actually text (no null bytes, mostly printable)
440
- if (FileDetector.isValidText(textContent)) {
441
- return {
442
- type: "text",
443
- content: textContent,
444
- mimeType: FileDetector.guessTextMimeType(textContent),
445
- metadata: {
446
- confidence: 70,
447
- size: content.length,
448
- },
449
- };
450
- }
451
- throw new Error("Content does not appear to be valid text");
452
- }
453
- case "image": {
454
- // Image requires magic bytes - can't fallback without detection
455
- throw new Error("Image type requires binary detection, cannot fallback parse");
456
- }
457
- case "pdf": {
458
- // PDF requires magic bytes - can't fallback without detection
459
- throw new Error("PDF type requires binary detection, cannot fallback parse");
460
- }
461
- case "audio": {
462
- // Audio requires magic bytes - can't fallback without detection
463
- throw new Error("Audio type requires binary detection, cannot fallback parse");
464
- }
465
- case "video": {
466
- // Video requires magic bytes - can't fallback without detection
467
- throw new Error("Video type requires binary detection, cannot fallback parse");
468
- }
469
- case "archive": {
470
- // Archive requires magic bytes - can't fallback without detection
471
- throw new Error("Archive type requires binary detection, cannot fallback parse");
472
- }
473
- case "xlsx": {
474
- // Document formats require binary detection
475
- throw new Error("Excel type requires binary detection, cannot fallback parse");
476
- }
477
- case "docx": {
478
- throw new Error("Word type requires binary detection, cannot fallback parse");
479
- }
480
- case "pptx": {
481
- throw new Error("PowerPoint type requires binary detection, cannot fallback parse");
482
- }
483
- case "svg": {
484
- // SVG can be detected from text content
485
- const svgContent = content.toString("utf-8");
486
- if (svgContent.includes("<svg") && svgContent.includes("</svg>")) {
487
- return {
488
- type: "svg",
489
- content: svgContent,
490
- mimeType: "image/svg+xml",
491
- metadata: {
492
- confidence: 70,
493
- size: content.length,
494
- },
495
- };
496
- }
497
- throw new Error("Content does not appear to be valid SVG");
498
- }
499
- default:
500
- return null;
501
- }
502
- }
503
- /**
504
- * Check if content is valid text (UTF-8, mostly printable)
505
- */
506
- static isValidText(content) {
507
- // Check for null bytes which indicate binary content
508
- if (content.includes("\0")) {
509
- return false;
510
- }
511
- // Check if content has reasonable amount of printable characters
512
- let printableCount = 0;
513
- for (let i = 0; i < content.length; i++) {
514
- const code = content.charCodeAt(i);
515
- if ((code >= 32 && code < 127) || // ASCII printable
516
- code === 9 || // Tab
517
- code === 10 || // Newline
518
- code === 13 || // Carriage return
519
- code > 127 // Unicode (non-ASCII)
520
- ) {
521
- printableCount++;
522
- }
523
- }
524
- // At least 90% should be printable
525
- return printableCount / content.length >= 0.9;
526
- }
527
- /**
528
- * Guess the MIME type for text content based on content patterns
529
- */
530
- static guessTextMimeType(content) {
531
- const trimmed = content.trim();
532
- // Check for JSON
533
- if ((trimmed.startsWith("{") && trimmed.endsWith("}")) ||
534
- (trimmed.startsWith("[") && trimmed.endsWith("]"))) {
535
- try {
536
- JSON.parse(trimmed);
537
- return "application/json";
538
- }
539
- catch {
540
- // Not valid JSON, continue checking
541
- }
542
- }
543
- // Check for XML/HTML using stricter detection
544
- if (FileDetector.looksLikeXMLStrict(trimmed)) {
545
- const isHTML = trimmed.includes("<!DOCTYPE html") ||
546
- trimmed.toLowerCase().includes("<html") ||
547
- trimmed.includes("<head") ||
548
- trimmed.includes("<body");
549
- return isHTML ? "text/html" : "application/xml";
550
- }
551
- // Check for YAML using robust multi-indicator detection
552
- if (FileDetector.looksLikeYAMLStrict(trimmed)) {
553
- return "application/yaml";
554
- }
555
- // Default to plain text
556
- return "text/plain";
557
- }
558
- /**
559
- * Strict YAML detection for guessTextMimeType
560
- * Similar to ContentHeuristicStrategy but requires at least 2 indicators
561
- * to avoid false positives from simple key: value patterns
562
- */
563
- static looksLikeYAMLStrict(text) {
564
- if (text.length === 0) {
565
- return false;
566
- }
567
- const lines = text.split("\n");
568
- // For single-line content, only --- or ... qualify as YAML
569
- if (lines.length === 1) {
570
- return text === "---" || text === "...";
571
- }
572
- // Collect YAML indicators (requires at least 2 for positive detection)
573
- const indicators = [];
574
- // Indicator 1: Document start marker (---)
575
- indicators.push(text.startsWith("---"));
576
- // Indicator 2: Document end marker (...)
577
- indicators.push(/^\.\.\.$|[\n]\.\.\.$/.test(text));
578
- // Indicator 3: YAML list items (- followed by space)
579
- indicators.push(/^[\s]*-\s+[^-]/m.test(text));
580
- // Indicator 4: Multiple key-value pairs (at least 2)
581
- const keyValuePattern = /^[\s]*[a-zA-Z_][a-zA-Z0-9_-]*:\s*(.+)$/;
582
- const keyValueMatches = lines.filter((line) => keyValuePattern.test(line)).length;
583
- indicators.push(keyValueMatches >= 2);
584
- // Require at least 2 indicators for confident YAML detection
585
- const matchCount = indicators.filter(Boolean).length;
586
- return matchCount >= 2;
587
- }
588
- /**
589
- * Strict XML detection for guessTextMimeType
590
- * Ensures content has proper XML declaration or valid tag structure with closing tags
591
- * Prevents false positives from arbitrary content starting with <
592
- */
593
- static looksLikeXMLStrict(content) {
594
- // XML declaration is a definitive marker
595
- if (content.startsWith("<?xml")) {
596
- return true;
597
- }
598
- // Must start with < for XML/HTML
599
- if (!content.startsWith("<")) {
600
- return false;
601
- }
602
- // Check for HTML DOCTYPE declaration
603
- if (content.includes("<!DOCTYPE html")) {
604
- return true;
605
- }
606
- // Must have valid opening tag structure: <tagname
607
- // Not just any < character like "< something"
608
- const hasValidOpeningTag = /<[a-zA-Z][a-zA-Z0-9-]*(?:\s[^>]*)?>/;
609
- if (!hasValidOpeningTag.test(content)) {
610
- return false;
611
- }
612
- // Must have at least one closing tag or self-closing tag to be valid XML/HTML
613
- const hasClosingTag = /<\/[a-zA-Z][a-zA-Z0-9-]*>/.test(content);
614
- const hasSelfClosingTag = /<[a-zA-Z][a-zA-Z0-9-]*(?:\s[^>]*)?\s*\/\s*>/.test(content);
615
- return hasClosingTag || hasSelfClosingTag;
616
- }
617
- /**
618
- * Detect file type using multi-strategy approach
619
- * Stops at first strategy with confidence >= threshold (default: 80%)
620
- */
621
- static async detect(input, options) {
622
- // Short-circuit on a trustworthy caller-provided mimetype hint. This is
623
- // the eager-path counterpart to FileReferenceRegistry.register()'s hint
624
- // handling — necessary for tiny files (<= TINY_MAX) that skip the lazy
625
- // registry path. normalizeMimeHint drops "application/octet-stream" so a
626
- // caller cannot hide real content behind the opaque sentinel.
627
- const hintMime = normalizeMimeHint(options?.mimetypeHint);
628
- if (hintMime) {
629
- const type = mimeHintToFileType(hintMime);
630
- if (type) {
631
- const ext = mimeHintToExtension(hintMime);
632
- const result = {
633
- type,
634
- mimeType: hintMime,
635
- extension: ext || null,
636
- source: FileDetector.deriveInputSource(input),
637
- metadata: {
638
- confidence: 95,
639
- filename: options?.filenameHint || FileDetector.deriveInputFilename(input),
640
- size: FileDetector.deriveInputSize(input),
641
- },
642
- };
643
- logger.info(`[FileDetector] Type: ${type} (95%, from mimetype hint: ${hintMime})`);
644
- return result;
645
- }
646
- }
647
- const confidenceThreshold = options?.confidenceThreshold ?? 80;
648
- const strategies = [
649
- new MagicBytesStrategy(),
650
- new MimeTypeStrategy(),
651
- new ExtensionStrategy(),
652
- new ContentHeuristicStrategy(),
653
- ];
654
- let best = null;
655
- for (const strategy of strategies) {
656
- const result = await strategy.detect(input);
657
- if (!best || result.metadata.confidence > best.metadata.confidence) {
658
- best = result;
659
- }
660
- if (result.metadata.confidence >= confidenceThreshold) {
661
- logger.info(`[FileDetector] Type: ${result.type} (${result.metadata.confidence}%)`);
662
- return FileDetector.withResolvedExtension(result, input, options);
663
- }
664
- }
665
- // Below-threshold detection is the common case for any file under the
666
- // ContentHeuristic ceiling — a debug detail, not a warning-worthy anomaly.
667
- logger.debug(`[FileDetector] Best-effort type below threshold: ${best?.type ?? "unknown"} (${best?.metadata.confidence ?? 0}%, threshold ${confidenceThreshold}%)`);
668
- return FileDetector.withResolvedExtension(best, input, options);
669
- }
670
- /**
671
- * Fill in `extension` from the input's name when detection did not set it.
672
- *
673
- * Content-based strategies identify a type from magic bytes and legitimately
674
- * have no extension to report, so they return null. That is fine for the type
675
- * itself but not for routing: several processors are chosen by extension
676
- * *after* detection has settled the type, because one routing type covers
677
- * several formats — `docx` covers .docx, .odt and .rtf.
678
- *
679
- * With a null extension those branches were unreachable. An .rtf scored high
680
- * on its `{\\rtf1` signature, arrived as type "docx" with no extension, and
681
- * fell through to the Word processor, which cannot read RTF — so a file whose
682
- * dedicated processor extracts it perfectly reported "Could not extract
683
- * content". The extension was known the whole time; it was simply dropped on
684
- * the way through.
685
- *
686
- * Only fills a gap — a strategy that did determine an extension keeps it, so
687
- * content still wins over a lying filename.
688
- */
689
- static withResolvedExtension(result, input, options) {
690
- if (!result) {
691
- return result;
692
- }
693
- // The caller's hint outranks a name derived from the input, because on the
694
- // unified path the input has already been unwrapped to a bare Buffer and
695
- // derives to the literal "buffer" — carrying no extension at all.
696
- const filename = options?.filenameHint ||
697
- result.metadata?.filename ||
698
- FileDetector.deriveInputFilename(input);
699
- if (!filename) {
700
- return result;
701
- }
702
- // Split on both separators so a Windows-style path on a POSIX host still
703
- // yields its basename, then take the final suffix.
704
- const base = filename.split(/[\\/]/).pop() ?? filename;
705
- const dot = base.lastIndexOf(".");
706
- const extension = result.extension ??
707
- (dot > 0 && dot < base.length - 1
708
- ? base.slice(dot + 1).toLowerCase()
709
- : null);
710
- // The name is carried alongside the extension for the same reason. A
711
- // content strategy reports no filename, so every processor keyed on one
712
- // received the literal fallback "archive" — and archive format detection
713
- // reads the name, because TAR has no magic bytes at offset 0 (its "ustar"
714
- // marker sits at byte 257). A .tar therefore arrived as an unidentifiable
715
- // archive and reported "Could not extract content", while the same bytes
716
- // handed to the processor WITH their name extract perfectly.
717
- const metadata = result.metadata && !result.metadata.filename
718
- ? { ...result.metadata, filename: base }
719
- : result.metadata;
720
- if (extension === result.extension && metadata === result.metadata) {
721
- return result;
722
- }
723
- return { ...result, extension, metadata };
724
- }
725
- /**
726
- * Load file content from various sources
727
- */
728
- static async loadContent(input, detection, options) {
729
- let source = detection.source;
730
- if (source === "buffer" && !Buffer.isBuffer(input)) {
731
- if (typeof input === "string") {
732
- if (input.startsWith("data:")) {
733
- source = "datauri";
734
- }
735
- else if (input.startsWith("http://") ||
736
- input.startsWith("https://")) {
737
- source = "url";
738
- }
739
- else {
740
- source = "path";
741
- }
742
- }
743
- }
744
- switch (source) {
745
- case "url":
746
- return await FileDetector.loadFromURL(input, options);
747
- case "path":
748
- return await FileDetector.loadFromPath(input, options);
749
- case "buffer":
750
- return input;
751
- case "datauri":
752
- return FileDetector.loadFromDataURI(input);
753
- default:
754
- throw new Error(`Unknown source: ${source}`);
755
- }
756
- }
757
- /**
758
- * SDK-8: Format an informative placeholder when a file processor fails.
759
- * Instead of bare "[Video file: name]" strings, include size, format, and
760
- * the reason for failure so the LLM can acknowledge the attachment.
761
- */
762
- static formatInformativePlaceholder(typeName, filename, content, detection, error) {
763
- const sizeStr = content.length < 1024
764
- ? `${content.length} bytes`
765
- : content.length < 1024 * 1024
766
- ? `${(content.length / 1024).toFixed(1)} KB`
767
- : `${(content.length / (1024 * 1024)).toFixed(1)} MB`;
768
- const errorMsg = error instanceof Error
769
- ? error.message
770
- : error
771
- ? String(error)
772
- : "Processing returned no usable content";
773
- return (`[${typeName} File: "${filename}"]\n` +
774
- `Size: ${sizeStr}\n` +
775
- `Format: ${detection.mimeType || "unknown"}\n` +
776
- `Error: Could not extract content (${errorMsg}).\n` +
777
- `The file was attached but could not be fully analyzed.`);
778
- }
779
- /**
780
- * Extract metadata and printable strings from an unrecognized binary file.
781
- * This is the "extract what you can" path for unknown file types.
782
- *
783
- * Extracts:
784
- * - File size (human-readable)
785
- * - MIME type / detected format
786
- * - First N bytes as hex dump (for identification)
787
- * - Printable ASCII/UTF-8 strings found in the binary (like `strings` command)
788
- * - Known file signatures that we don't have full processors for
789
- *
790
- * @param content Raw file buffer
791
- * @param detection Detection result (may be "unknown")
792
- * @param filename Original filename (if known)
793
- * @returns Formatted text summary suitable for LLM consumption
794
- */
795
- static extractBinaryMetadata(content, detection, filename) {
796
- const parts = [];
797
- // Header
798
- const ext = detection.extension
799
- ? `.${detection.extension}`
800
- : filename.includes(".")
801
- ? filename.slice(filename.lastIndexOf("."))
802
- : "";
803
- const typeLabel = ext
804
- ? `${ext.toUpperCase().slice(1)} file`
805
- : "Binary file";
806
- parts.push(`[${typeLabel}: "${filename}"]`);
807
- // Basic metadata
808
- const sizeStr = formatFileSize(content.length);
809
- parts.push(`Size: ${sizeStr}`);
810
- if (detection.mimeType &&
811
- detection.mimeType !== "application/octet-stream") {
812
- parts.push(`Format: ${detection.mimeType}`);
813
- }
814
- // Known binary signature identification (broader than our processing capabilities)
815
- const sigLabel = FileDetector.identifyBinarySignature(content);
816
- if (sigLabel) {
817
- parts.push(`Identified as: ${sigLabel}`);
818
- }
819
- // Hex dump of first 32 bytes for identification
820
- const hexPreview = content
821
- .subarray(0, Math.min(32, content.length))
822
- .toString("hex")
823
- .match(/.{1,2}/g)
824
- ?.join(" ");
825
- if (hexPreview) {
826
- parts.push(`Header bytes: ${hexPreview}`);
827
- }
828
- // Extract printable strings (similar to Unix `strings` command)
829
- const strings = FileDetector.extractPrintableStrings(content, 4, 50);
830
- if (strings.length > 0) {
831
- parts.push(`\nEmbedded text found (${strings.length} string${strings.length > 1 ? "s" : ""}):`);
832
- for (const s of strings) {
833
- parts.push(` "${s}"`);
834
- }
835
- }
836
- parts.push(`\nThis file was attached but its format is not fully supported for content extraction.`);
837
- parts.push(`The above metadata and any embedded text have been extracted for context.`);
838
- return parts.join("\n");
839
- }
840
- /**
841
- * Identify known binary file signatures beyond what we can process.
842
- * Returns a human-readable description, or null if unrecognized.
843
- */
844
- static identifyBinarySignature(buf) {
845
- if (buf.length < 4) {
846
- return null;
847
- }
848
- // SQLite: "SQLite format 3\0"
849
- if (buf.length >= 16 &&
850
- buf.subarray(0, 15).toString("ascii") === "SQLite format 3") {
851
- return "SQLite database";
852
- }
853
- // WOFF: "wOFF"
854
- if (buf[0] === 0x77 &&
855
- buf[1] === 0x4f &&
856
- buf[2] === 0x46 &&
857
- buf[3] === 0x46) {
858
- return "WOFF font";
859
- }
860
- // WOFF2: "wOF2"
861
- if (buf[0] === 0x77 &&
862
- buf[1] === 0x4f &&
863
- buf[2] === 0x46 &&
864
- buf[3] === 0x32) {
865
- return "WOFF2 font";
866
- }
867
- // TrueType/OpenType: starts with 0x00010000 or "OTTO"
868
- if ((buf[0] === 0x00 &&
869
- buf[1] === 0x01 &&
870
- buf[2] === 0x00 &&
871
- buf[3] === 0x00) ||
872
- (buf[0] === 0x4f && buf[1] === 0x54 && buf[2] === 0x54 && buf[3] === 0x4f)) {
873
- return "TrueType/OpenType font";
874
- }
875
- // ELF executable: \x7fELF
876
- if (buf[0] === 0x7f &&
877
- buf[1] === 0x45 &&
878
- buf[2] === 0x4c &&
879
- buf[3] === 0x46) {
880
- return "ELF executable/library";
881
- }
882
- // Mach-O: 0xFEEDFACE or 0xFEEDFACF (64-bit) or 0xCAFEBABE (universal)
883
- if ((buf[0] === 0xfe &&
884
- buf[1] === 0xed &&
885
- buf[2] === 0xfa &&
886
- buf[3] === 0xce) ||
887
- (buf[0] === 0xfe &&
888
- buf[1] === 0xed &&
889
- buf[2] === 0xfa &&
890
- buf[3] === 0xcf) ||
891
- (buf[0] === 0xca && buf[1] === 0xfe && buf[2] === 0xba && buf[3] === 0xbe)) {
892
- return "Mach-O executable/library";
893
- }
894
- // PE/Windows executable: "MZ"
895
- if (buf[0] === 0x4d && buf[1] === 0x5a) {
896
- return "Windows PE executable/DLL";
897
- }
898
- // WebAssembly: "\0asm"
899
- if (buf[0] === 0x00 &&
900
- buf[1] === 0x61 &&
901
- buf[2] === 0x73 &&
902
- buf[3] === 0x6d) {
903
- return "WebAssembly binary";
904
- }
905
- // DWG (AutoCAD): starts with "AC10"
906
- if (buf[0] === 0x41 &&
907
- buf[1] === 0x43 &&
908
- buf[2] === 0x31 &&
909
- buf[3] === 0x30) {
910
- return "AutoCAD DWG drawing";
911
- }
912
- // BZ2: "BZ" + 'h'
913
- if (buf[0] === 0x42 && buf[1] === 0x5a && buf[2] === 0x68) {
914
- return "BZip2 compressed archive";
915
- }
916
- // XZ: 0xFD + "7zXZ"
917
- if (buf.length >= 6 &&
918
- buf[0] === 0xfd &&
919
- buf[1] === 0x37 &&
920
- buf[2] === 0x7a &&
921
- buf[3] === 0x58 &&
922
- buf[4] === 0x5a &&
923
- buf[5] === 0x00) {
924
- return "XZ compressed archive";
925
- }
926
- // 7z: "7z" + BC AF 27 1C
927
- if (buf.length >= 6 &&
928
- buf[0] === 0x37 &&
929
- buf[1] === 0x7a &&
930
- buf[2] === 0xbc &&
931
- buf[3] === 0xaf &&
932
- buf[4] === 0x27 &&
933
- buf[5] === 0x1c) {
934
- return "7-Zip archive";
935
- }
936
- // ISO 9660: "CD001" at offset 32769
937
- if (buf.length > 32773 &&
938
- buf.subarray(32769, 32774).toString("ascii") === "CD001") {
939
- return "ISO 9660 disc image";
940
- }
941
- // Apache Parquet: "PAR1"
942
- if (buf[0] === 0x50 &&
943
- buf[1] === 0x41 &&
944
- buf[2] === 0x52 &&
945
- buf[3] === 0x31) {
946
- return "Apache Parquet data file";
947
- }
948
- // Protocol Buffers compiled: (no fixed magic, skip)
949
- // TIFF (already handled as image, but including for completeness)
950
- if ((buf[0] === 0x49 &&
951
- buf[1] === 0x49 &&
952
- buf[2] === 0x2a &&
953
- buf[3] === 0x00) ||
954
- (buf[0] === 0x4d && buf[1] === 0x4d && buf[2] === 0x00 && buf[3] === 0x2a)) {
955
- return "TIFF image";
956
- }
957
- // ICO: 00 00 01 00
958
- if (buf[0] === 0x00 &&
959
- buf[1] === 0x00 &&
960
- buf[2] === 0x01 &&
961
- buf[3] === 0x00) {
962
- return "ICO icon image";
963
- }
964
- return null;
965
- }
966
- /**
967
- * Extract printable ASCII strings from a binary buffer.
968
- * Similar to the Unix `strings` utility.
969
- *
970
- * @param buf Buffer to scan
971
- * @param minLength Minimum string length to include (default 4)
972
- * @param maxStrings Maximum number of strings to return (default 50)
973
- * @returns Array of printable strings found in the binary
974
- */
975
- static extractPrintableStrings(buf, minLength = 4, maxStrings = 50) {
976
- const strings = [];
977
- let current = "";
978
- // Only scan first 64KB to avoid huge processing time
979
- const scanLimit = Math.min(buf.length, 64 * 1024);
980
- for (let i = 0; i < scanLimit; i++) {
981
- const byte = buf[i];
982
- // Printable ASCII range (space through tilde) plus tab
983
- if ((byte >= 0x20 && byte <= 0x7e) || byte === 0x09) {
984
- current += String.fromCharCode(byte);
985
- }
986
- else {
987
- if (current.length >= minLength) {
988
- strings.push(current);
989
- if (strings.length >= maxStrings) {
990
- break;
991
- }
992
- }
993
- current = "";
994
- }
995
- }
996
- // Flush last string
997
- if (current.length >= minLength && strings.length < maxStrings) {
998
- strings.push(current);
999
- }
1000
- return strings;
1001
- }
1002
- /**
1003
- * Route to appropriate processor
1004
- */
1005
- static async processFile(content, detection, options, provider, videoOptions) {
1006
- switch (detection.type) {
1007
- case "csv":
1008
- // Pass original extension through to CSV processor; if detection has none,
1009
- // fall back to any extension provided in csvOptions.
1010
- return await CSVProcessor.process(content, {
1011
- ...options,
1012
- extension: detection.extension ?? options?.extension,
1013
- });
1014
- case "image":
1015
- return await ImageProcessor.process(content);
1016
- case "pdf":
1017
- return await PDFProcessor.process(content, { provider });
1018
- case "svg":
1019
- // SVG is processed as text content (sanitized XML markup)
1020
- // AI providers don't support SVG as image format, so we extract text content
1021
- return await FileDetector.processSvgAsText(content, detection);
1022
- case "video":
1023
- return await FileDetector.processVideoFile(content, detection, videoOptions);
1024
- case "audio":
1025
- return await FileDetector.processAudioFile(content, detection);
1026
- case "archive":
1027
- return await FileDetector.processArchiveFile(content, detection);
1028
- case "xlsx":
1029
- return await FileDetector.processXlsxFile(content, detection);
1030
- case "docx":
1031
- return await FileDetector.processDocxFile(content, detection);
1032
- case "pptx":
1033
- return await FileDetector.processPptxFile(content, detection);
1034
- case "text":
1035
- return {
1036
- type: "text",
1037
- content: content.toString("utf-8"),
1038
- mimeType: detection.mimeType || "text/plain",
1039
- metadata: detection.metadata,
1040
- };
1041
- default: {
1042
- // Graceful degradation: try to treat unknown types as text if content is valid UTF-8
1043
- const unknownContent = content.toString("utf-8");
1044
- if (FileDetector.isValidText(unknownContent)) {
1045
- logger.warn(`[FileDetector] Unknown type "${detection.type}", treating as text`);
1046
- return {
1047
- type: "text",
1048
- content: unknownContent,
1049
- mimeType: detection.mimeType || "text/plain",
1050
- metadata: detection.metadata,
1051
- };
1052
- }
1053
- // Binary file that we can't fully process — extract what we can
1054
- // (metadata, printable strings, signature identification)
1055
- const filename = detection.metadata.filename || "file";
1056
- logger.warn(`[FileDetector] Unknown binary type "${detection.type}", extracting metadata for "${filename}"`);
1057
- return {
1058
- type: "unknown",
1059
- content: FileDetector.extractBinaryMetadata(content, detection, filename),
1060
- mimeType: detection.mimeType || "application/octet-stream",
1061
- metadata: detection.metadata,
1062
- };
1063
- }
1064
- }
1065
- }
1066
- /**
1067
- * Process video file: extract metadata, keyframes, and subtitles via VideoProcessor
1068
- */
1069
- static async processVideoFile(content, detection, videoOptions) {
1070
- const videoFilename = detection.metadata.filename || "video";
1071
- try {
1072
- const videoResult = await (await getVideoProcessor()).processFile({
1073
- id: videoFilename,
1074
- name: videoFilename,
1075
- mimetype: detection.mimeType || "video/mp4",
1076
- size: content.length,
1077
- buffer: content,
1078
- },
1079
- // #478: carry the caller's keyframe budget/quality/format through to
1080
- // the processor; previously these stopped at the CLI layer.
1081
- videoOptions);
1082
- if (videoResult.success && videoResult.data) {
1083
- return {
1084
- type: "video",
1085
- content: videoResult.data.textContent ||
1086
- FileDetector.formatInformativePlaceholder("Video", videoFilename, content, detection),
1087
- mimeType: detection.mimeType,
1088
- images: videoResult.data.keyframes && videoResult.data.keyframes.length > 0
1089
- ? videoResult.data.keyframes
1090
- : undefined,
1091
- metadata: {
1092
- ...detection.metadata,
1093
- frameCount: videoResult.data.frameCount,
1094
- hasKeyframes: videoResult.data.hasKeyframes,
1095
- },
1096
- };
1097
- }
1098
- }
1099
- catch (videoError) {
1100
- logger.warn(`[FileDetector] VideoProcessor failed for ${videoFilename}, using fallback`, videoError instanceof Error ? videoError.message : String(videoError));
1101
- return {
1102
- type: "video",
1103
- content: FileDetector.formatInformativePlaceholder("Video", videoFilename, content, detection, videoError),
1104
- mimeType: detection.mimeType,
1105
- metadata: detection.metadata,
1106
- };
1107
- }
1108
- // Fallback if processor returned no data
1109
- return {
1110
- type: "video",
1111
- content: FileDetector.formatInformativePlaceholder("Video", videoFilename, content, detection),
1112
- mimeType: detection.mimeType,
1113
- metadata: detection.metadata,
1114
- };
1115
- }
1116
- /**
1117
- * Process audio file: extract metadata, tags, and cover art via AudioProcessor
1118
- */
1119
- static async processAudioFile(content, detection) {
1120
- const audioFilename = detection.metadata.filename || "audio";
1121
- try {
1122
- const audioResult = await (await getAudioProcessor()).processFile({
1123
- id: audioFilename,
1124
- name: audioFilename,
1125
- mimetype: detection.mimeType || "audio/mpeg",
1126
- size: content.length,
1127
- buffer: content,
1128
- });
1129
- if (audioResult.success && audioResult.data) {
1130
- return {
1131
- type: "audio",
1132
- content: audioResult.data.textContent ||
1133
- FileDetector.formatInformativePlaceholder("Audio", audioFilename, content, detection),
1134
- mimeType: detection.mimeType,
1135
- // Surface embedded cover art as an image content block
1136
- images: audioResult.data.coverArt
1137
- ? [audioResult.data.coverArt]
1138
- : undefined,
1139
- metadata: detection.metadata,
1140
- };
1141
- }
1142
- }
1143
- catch (audioError) {
1144
- logger.warn(`[FileDetector] AudioProcessor failed for ${audioFilename}, using fallback`, audioError instanceof Error ? audioError.message : String(audioError));
1145
- return {
1146
- type: "audio",
1147
- content: FileDetector.formatInformativePlaceholder("Audio", audioFilename, content, detection, audioError),
1148
- mimeType: detection.mimeType,
1149
- metadata: detection.metadata,
1150
- };
1151
- }
1152
- // Fallback if processor returned no data
1153
- return {
1154
- type: "audio",
1155
- content: FileDetector.formatInformativePlaceholder("Audio", audioFilename, content, detection),
1156
- mimeType: detection.mimeType,
1157
- metadata: detection.metadata,
1158
- };
1159
- }
1160
- /**
1161
- * Process archive file: list contents and extract metadata via ArchiveProcessor
1162
- */
1163
- static async processArchiveFile(content, detection) {
1164
- const archiveFilename = detection.metadata.filename || "archive";
1165
- try {
1166
- const archiveResult = await (await getArchiveProcessor()).processFile({
1167
- id: archiveFilename,
1168
- name: archiveFilename,
1169
- mimetype: detection.mimeType || "application/zip",
1170
- size: content.length,
1171
- buffer: content,
1172
- });
1173
- if (archiveResult.success && archiveResult.data) {
1174
- return {
1175
- type: "archive",
1176
- content: archiveResult.data.textContent ||
1177
- FileDetector.formatInformativePlaceholder("Archive", archiveFilename, content, detection),
1178
- mimeType: detection.mimeType,
1179
- metadata: detection.metadata,
1180
- };
1181
- }
1182
- }
1183
- catch (archiveError) {
1184
- logger.warn(`[FileDetector] ArchiveProcessor failed for ${archiveFilename}, using fallback`, archiveError instanceof Error
1185
- ? archiveError.message
1186
- : String(archiveError));
1187
- return {
1188
- type: "archive",
1189
- content: FileDetector.formatInformativePlaceholder("Archive", archiveFilename, content, detection, archiveError),
1190
- mimeType: detection.mimeType,
1191
- metadata: detection.metadata,
1192
- };
1193
- }
1194
- // Fallback if processor returned no data
1195
- return {
1196
- type: "archive",
1197
- content: FileDetector.formatInformativePlaceholder("Archive", archiveFilename, content, detection),
1198
- mimeType: detection.mimeType,
1199
- metadata: detection.metadata,
1200
- };
1201
- }
1202
- /**
1203
- * Process Excel/OpenDocument spreadsheet file via ExcelProcessor or OpenDocumentProcessor
1204
- */
1205
- static async processXlsxFile(content, detection) {
1206
- const xlsxFilename = detection.metadata.filename || "spreadsheet";
1207
- try {
1208
- const ext = detection.extension?.toLowerCase();
1209
- if (ext === "ods") {
1210
- const { openDocumentProcessor } = await import("../processors/document/OpenDocumentProcessor.js");
1211
- const odsResult = await openDocumentProcessor.processFile({
1212
- id: xlsxFilename,
1213
- name: xlsxFilename,
1214
- mimetype: detection.mimeType ||
1215
- "application/vnd.oasis.opendocument.spreadsheet",
1216
- size: content.length,
1217
- buffer: content,
1218
- });
1219
- if (odsResult.success && odsResult.data) {
1220
- return {
1221
- type: "xlsx",
1222
- content: odsResult.data.textContent ||
1223
- FileDetector.formatInformativePlaceholder("Spreadsheet", xlsxFilename, content, detection),
1224
- mimeType: detection.mimeType,
1225
- metadata: detection.metadata,
1226
- };
1227
- }
1228
- }
1229
- else {
1230
- const { excelProcessor } = await import("../processors/document/ExcelProcessor.js");
1231
- const xlsxResult = await excelProcessor.processFile({
1232
- id: xlsxFilename,
1233
- name: xlsxFilename,
1234
- mimetype: detection.mimeType ||
1235
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1236
- size: content.length,
1237
- buffer: content,
1238
- });
1239
- if (xlsxResult.success && xlsxResult.data) {
1240
- // Build text content from worksheets
1241
- const sheets = xlsxResult.data.worksheets || [];
1242
- let textContent = `Spreadsheet: ${sheets.length} sheet(s), ${xlsxResult.data.totalRows} total rows\n`;
1243
- for (const sheet of sheets) {
1244
- textContent += `\n### Sheet: ${sheet.name}\n`;
1245
- textContent += `Columns (${sheet.columnCount}): ${sheet.headers.join(", ")}\n`;
1246
- textContent += `Rows: ${sheet.rowCount}\n`;
1247
- // Include first rows as sample data
1248
- const sampleRows = sheet.rows.slice(0, 20);
1249
- const rowText = sampleRows
1250
- .map((row) => row.map((c) => String(c ?? "")).join("\t"))
1251
- .join("\n");
1252
- if (!rowText) {
1253
- continue;
1254
- }
1255
- textContent += `\nData:\n${sheet.headers.join("\t")}\n${rowText}\n`;
1256
- const remaining = sheet.rowCount - 20;
1257
- if (remaining > 0) {
1258
- textContent += `... (${remaining} more rows)\n`;
1259
- }
1260
- }
1261
- return {
1262
- type: "xlsx",
1263
- content: textContent,
1264
- mimeType: detection.mimeType,
1265
- metadata: detection.metadata,
1266
- };
1267
- }
1268
- }
1269
- }
1270
- catch (xlsxError) {
1271
- logger.warn(`[FileDetector] ExcelProcessor failed for ${xlsxFilename}, using fallback`, xlsxError instanceof Error ? xlsxError.message : String(xlsxError));
1272
- return {
1273
- type: "xlsx",
1274
- content: FileDetector.formatInformativePlaceholder("Spreadsheet", xlsxFilename, content, detection, xlsxError),
1275
- mimeType: detection.mimeType,
1276
- metadata: detection.metadata,
1277
- };
1278
- }
1279
- // Fallback if processor returned no data
1280
- return {
1281
- type: "xlsx",
1282
- content: FileDetector.formatInformativePlaceholder("Spreadsheet", xlsxFilename, content, detection),
1283
- mimeType: detection.mimeType,
1284
- metadata: detection.metadata,
1285
- };
1286
- }
1287
- /**
1288
- * Process Word/OpenDocument/RTF document via WordProcessor, OpenDocumentProcessor, or RtfProcessor
1289
- */
1290
- static async processDocxFile(content, detection) {
1291
- const docxFilename = detection.metadata.filename || "document";
1292
- const ext = detection.extension?.toLowerCase();
1293
- try {
1294
- if (ext === "odt") {
1295
- const { openDocumentProcessor } = await import("../processors/document/OpenDocumentProcessor.js");
1296
- const odtResult = await openDocumentProcessor.processFile({
1297
- id: docxFilename,
1298
- name: docxFilename,
1299
- mimetype: detection.mimeType || "application/vnd.oasis.opendocument.text",
1300
- size: content.length,
1301
- buffer: content,
1302
- });
1303
- if (odtResult.success && odtResult.data) {
1304
- return {
1305
- type: "docx",
1306
- content: odtResult.data.textContent ||
1307
- FileDetector.formatInformativePlaceholder("Document", docxFilename, content, detection),
1308
- mimeType: detection.mimeType,
1309
- metadata: detection.metadata,
1310
- };
1311
- }
1312
- }
1313
- else if (ext === "rtf") {
1314
- const { rtfProcessor } = await import("../processors/document/RtfProcessor.js");
1315
- const rtfResult = await rtfProcessor.processFile({
1316
- id: docxFilename,
1317
- name: docxFilename,
1318
- mimetype: detection.mimeType || "application/rtf",
1319
- size: content.length,
1320
- buffer: content,
1321
- });
1322
- if (rtfResult.success && rtfResult.data) {
1323
- return {
1324
- type: "docx",
1325
- content: rtfResult.data.textContent ||
1326
- FileDetector.formatInformativePlaceholder("Document", docxFilename, content, detection),
1327
- mimeType: detection.mimeType,
1328
- metadata: detection.metadata,
1329
- };
1330
- }
1331
- }
1332
- else {
1333
- const { wordProcessor } = await import("../processors/document/WordProcessor.js");
1334
- const docxResult = await wordProcessor.processFile({
1335
- id: docxFilename,
1336
- name: docxFilename,
1337
- mimetype: detection.mimeType ||
1338
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1339
- size: content.length,
1340
- buffer: content,
1341
- });
1342
- if (docxResult.success && docxResult.data) {
1343
- return {
1344
- type: "docx",
1345
- content: docxResult.data.textContent ||
1346
- FileDetector.formatInformativePlaceholder("Document", docxFilename, content, detection),
1347
- mimeType: detection.mimeType,
1348
- metadata: detection.metadata,
1349
- };
1350
- }
1351
- }
1352
- }
1353
- catch (docxError) {
1354
- logger.warn(`[FileDetector] Document processor failed for ${docxFilename}, using fallback`, docxError instanceof Error ? docxError.message : String(docxError));
1355
- return {
1356
- type: "docx",
1357
- content: FileDetector.formatInformativePlaceholder("Document", docxFilename, content, detection, docxError),
1358
- mimeType: detection.mimeType,
1359
- metadata: detection.metadata,
1360
- };
1361
- }
1362
- // Fallback if processor returned no data
1363
- return {
1364
- type: "docx",
1365
- content: FileDetector.formatInformativePlaceholder("Document", docxFilename, content, detection),
1366
- mimeType: detection.mimeType,
1367
- metadata: detection.metadata,
1368
- };
1369
- }
1370
- /**
1371
- * Process PowerPoint/OpenDocument presentation via PptxProcessor
1372
- */
1373
- static async processPptxFile(content, detection) {
1374
- const pptxFilename = detection.metadata.filename || "presentation";
1375
- try {
1376
- // ODP is an OpenDocument package, not OOXML — the PPTX reader finds no
1377
- // ppt/slides parts in it and returns nothing. It reaches this branch at
1378
- // all because one routing type ("pptx") covers every presentation
1379
- // format, the same way "docx" covers .odt.
1380
- if (detection.extension?.toLowerCase() === "odp") {
1381
- const { openDocumentProcessor } = await import("../processors/document/OpenDocumentProcessor.js");
1382
- // Bounded per the project's async-timeout guideline: this unzips and
1383
- // parses attacker-supplied bytes, and a stalled parse would otherwise
1384
- // hold the request open with no ceiling. On timeout the throw lands in
1385
- // this block's existing catch, which degrades to the placeholder.
1386
- const odpResult = await withTimeout(openDocumentProcessor.processFile({
1387
- id: pptxFilename,
1388
- name: pptxFilename,
1389
- mimetype: detection.mimeType ||
1390
- "application/vnd.oasis.opendocument.presentation",
1391
- size: content.length,
1392
- buffer: content,
1393
- }), FileDetector.DEFAULT_DOCUMENT_TIMEOUT);
1394
- // Gated on success rather than on text, because a presentation of
1395
- // nothing but images is a legitimate ODP that extracts to an empty
1396
- // string. Requiring text sent that file on to the PPTX reader, which
1397
- // cannot read OpenDocument at all — so a successful extraction was
1398
- // discarded in favour of a guaranteed failure. Matches how the ODT and
1399
- // ODS branches degrade.
1400
- if (odpResult.success && odpResult.data) {
1401
- return {
1402
- type: "pptx",
1403
- content: odpResult.data.textContent ||
1404
- FileDetector.formatInformativePlaceholder("Presentation", pptxFilename, content, detection),
1405
- mimeType: detection.mimeType,
1406
- metadata: detection.metadata,
1407
- };
1408
- }
1409
- }
1410
- const { PptxProcessor } = await import("../processors/document/PptxProcessor.js");
1411
- const pptxResult = await PptxProcessor.extractText(content);
1412
- if (pptxResult) {
1413
- return {
1414
- type: "pptx",
1415
- content: pptxResult,
1416
- mimeType: detection.mimeType,
1417
- metadata: detection.metadata,
1418
- };
1419
- }
1420
- }
1421
- catch (pptxError) {
1422
- logger.warn(`[FileDetector] PptxProcessor failed for ${pptxFilename}, using fallback`, pptxError instanceof Error ? pptxError.message : String(pptxError));
1423
- return {
1424
- type: "pptx",
1425
- content: FileDetector.formatInformativePlaceholder("Presentation", pptxFilename, content, detection, pptxError),
1426
- mimeType: detection.mimeType,
1427
- metadata: detection.metadata,
1428
- };
1429
- }
1430
- // Fallback if processor returned no content
1431
- return {
1432
- type: "pptx",
1433
- content: FileDetector.formatInformativePlaceholder("Presentation", pptxFilename, content, detection),
1434
- mimeType: detection.mimeType,
1435
- metadata: detection.metadata,
1436
- };
1437
- }
1438
- /**
1439
- * Process SVG file as text content
1440
- * Uses SvgProcessor for security sanitization (removes XSS vectors)
1441
- * Returns sanitized SVG markup as text for AI analysis
1442
- */
1443
- static async processSvgAsText(content, detection) {
1444
- try {
1445
- // Dynamic import to avoid circular dependencies
1446
- const { processSvg } = await import("../processors/markup/SvgProcessor.js");
1447
- const result = await processSvg({
1448
- id: "svg-file",
1449
- name: detection.metadata.filename || "image.svg",
1450
- mimetype: "image/svg+xml",
1451
- size: content.length,
1452
- buffer: content,
1453
- });
1454
- if (result.success && result.data) {
1455
- logger.info(`[FileDetector] SVG processed as text: ${detection.metadata.filename || "image.svg"}`);
1456
- return {
1457
- type: "svg",
1458
- content: result.data.textContent, // Sanitized SVG content
1459
- mimeType: "image/svg+xml",
1460
- metadata: {
1461
- confidence: detection.metadata.confidence,
1462
- size: content.length,
1463
- filename: detection.metadata.filename,
1464
- extension: detection.extension,
1465
- },
1466
- };
1467
- }
1468
- else {
1469
- // Fail closed: return safe empty SVG instead of raw unsanitized content
1470
- logger.warn(`[FileDetector] SVG processor failed, returning safe empty SVG: ${result.error?.userMessage}`);
1471
- return {
1472
- type: "svg",
1473
- content: '<svg xmlns="http://www.w3.org/2000/svg"></svg>',
1474
- mimeType: "image/svg+xml",
1475
- metadata: {
1476
- confidence: detection.metadata.confidence,
1477
- size: content.length,
1478
- filename: detection.metadata.filename,
1479
- extension: detection.extension,
1480
- },
1481
- };
1482
- }
1483
- }
1484
- catch (error) {
1485
- // Fail closed: return safe empty SVG instead of raw unsanitized content
1486
- logger.warn(`[FileDetector] SVG processor not available, returning safe empty SVG: ${error instanceof Error ? error.message : String(error)}`);
1487
- return {
1488
- type: "svg",
1489
- content: '<svg xmlns="http://www.w3.org/2000/svg"></svg>',
1490
- mimeType: "image/svg+xml",
1491
- metadata: {
1492
- confidence: detection.metadata.confidence,
1493
- size: content.length,
1494
- filename: detection.metadata.filename,
1495
- extension: detection.extension,
1496
- },
1497
- };
1498
- }
1499
- }
1500
- /**
1501
- * Load file from URL with automatic retry on transient network errors
1502
- */
1503
- static async loadFromURL(url, options) {
1504
- const maxSize = options?.maxSize || 200 * 1024 * 1024; // 200MB default (matches Curator memory-safety cap)
1505
- const timeout = options?.timeout || FileDetector.DEFAULT_NETWORK_TIMEOUT;
1506
- // #317: pre-flight HEAD to reject an oversized file BEFORE downloading any
1507
- // body. content-length is advisory (chunked responses omit it), so a
1508
- // missing/invalid header — or a server that refuses HEAD — falls through to
1509
- // the streaming byte guard below; only a genuine oversize rejection stops
1510
- // the GET from ever running.
1511
- //
1512
- // #323: skip the pre-flight entirely when this exact URL was recently seen
1513
- // (its Content-Type is still cached, whether from a prior loadFromURL GET
1514
- // or a MimeTypeStrategy HEAD) — issuing a fresh HEAD here would defeat the
1515
- // whole point of that cache. The streaming byte guard in the GET below
1516
- // still enforces maxSize even without a pre-flight, so this doesn't remove
1517
- // the oversize protection — it only skips the redundant round-trip for a
1518
- // URL we've already been talking to within the last 60s.
1519
- if (getCachedUrlContentType(url, Date.now()) === undefined) {
1520
- try {
1521
- const head = await request(url, {
1522
- dispatcher: getGlobalDispatcher().compose(interceptors.redirect({ maxRedirections: 5 })),
1523
- method: "HEAD",
1524
- headersTimeout: FileDetector.DEFAULT_HEAD_TIMEOUT,
1525
- bodyTimeout: FileDetector.DEFAULT_HEAD_TIMEOUT,
1526
- });
1527
- // Drain/close the (empty) HEAD body so the connection can be reused.
1528
- await head.body.dump();
1529
- // Only trust `content-length` on a genuine 2xx response. A non-2xx
1530
- // HEAD (redirect the dispatcher didn't follow, 403/404/405 "HEAD not
1531
- // allowed", 5xx, …) can still carry a stale/irrelevant
1532
- // `content-length` header — enforcing size off of that would reject
1533
- // (or silently pass) based on the wrong body. Treat any non-2xx HEAD
1534
- // as if the header were missing and fall through to the streaming
1535
- // GET guard below, which enforces maxSize independently either way.
1536
- if (head.statusCode >= 200 && head.statusCode < 300) {
1537
- const declaredLength = Number(head.headers["content-length"]);
1538
- if (Number.isFinite(declaredLength) && declaredLength > maxSize) {
1539
- throw new Error(`File too large: ${formatFileSize(declaredLength)} (max: ${formatFileSize(maxSize)})`);
1540
- }
1541
- }
1542
- }
1543
- catch (error) {
1544
- if (error instanceof Error && /File too large/.test(error.message)) {
1545
- throw error;
1546
- }
1547
- logger.debug(`[FileDetector] HEAD pre-flight skipped for ${redactUrlForError(url)}: ${sanitizeErrorCause(error).message}`);
1548
- }
1549
- }
1550
- return withRetry(async () => {
1551
- try {
1552
- const response = await request(url, {
1553
- dispatcher: getGlobalDispatcher().compose(interceptors.redirect({ maxRedirections: 5 })),
1554
- method: "GET",
1555
- headersTimeout: timeout,
1556
- bodyTimeout: timeout,
1557
- });
1558
- if (response.statusCode !== 200) {
1559
- // Query string / fragment stripped — a presigned URL's token must
1560
- // not be echoed into a thrown error.
1561
- throw new Error(`HTTP ${response.statusCode} fetching ${redactUrlForError(url)}`);
1562
- }
1563
- // #323: cache the Content-Type from this GET so a subsequent detection
1564
- // of the same URL needs no HEAD.
1565
- setCachedUrlContentType(url, response.headers["content-type"] || "", Date.now());
1566
- const chunks = [];
1567
- let totalSize = 0;
1568
- for await (const chunk of response.body) {
1569
- totalSize += chunk.length;
1570
- if (totalSize > maxSize) {
1571
- throw new Error(`File too large: ${formatFileSize(totalSize)} (max: ${formatFileSize(maxSize)})`);
1572
- }
1573
- chunks.push(chunk);
1574
- }
1575
- return Buffer.concat(chunks);
1576
- }
1577
- catch (error) {
1578
- // Node/undici DNS, TLS, and connect-timeout errors embed the full
1579
- // request URL (including a presigned query token) in
1580
- // `error.message`. Redact into a NEW error instead of mutating the
1581
- // original in place, so anything that still holds a reference to
1582
- // the original — debug logs, telemetry spans, upstream callers —
1583
- // keeps seeing the real message. `.code` is copied onto the new
1584
- // error so `isRetryableNetworkError`'s retry check in the outer
1585
- // `withRetry` catch still classifies it correctly. The raw
1586
- // original error is NEVER attached as `cause` — that would leave
1587
- // the unredacted URL reachable via `error.cause.message` for
1588
- // anything that walks the cause chain (cause-aware logging,
1589
- // telemetry). `cause` instead gets its own sanitized copy.
1590
- // `sanitizeErrorCause` handles non-`Error` thrown values too (a raw
1591
- // string/object can just as easily carry the full URL), so there is
1592
- // no unconditional `throw error` fallback that would bypass
1593
- // redaction for that case.
1594
- const cause = sanitizeErrorCause(error);
1595
- const redacted = new Error(cause.message, { cause });
1596
- redacted.name = cause.name;
1597
- const code = cause.code;
1598
- if (code !== undefined) {
1599
- redacted.code = code;
1600
- }
1601
- throw redacted;
1602
- }
1603
- }, {
1604
- maxRetries: options?.maxRetries ?? 3,
1605
- baseDelayMs: options?.retryDelay ?? 1000,
1606
- shouldRetry: isRetryableNetworkError,
1607
- });
1608
- }
1609
- /**
1610
- * Load file from filesystem path
1611
- */
1612
- static async loadFromPath(filePath, options) {
1613
- const maxSize = options?.maxSize || 200 * 1024 * 1024; // 200MB default (matches Curator memory-safety cap)
1614
- // Reject NUL-byte injection outright (a classic path-truncation vector).
1615
- if (filePath.includes("\0")) {
1616
- throw new Error("Invalid file path: contains a null byte");
1617
- }
1618
- // Optional sandbox: when a base dir is configured (servers accepting paths
1619
- // from untrusted callers), reject anything that resolves outside it. Real
1620
- // paths are resolved (symlinks followed) on BOTH sides so a symlink inside
1621
- // the base dir pointing outside cannot bypass containment. The
1622
- // path.relative check (not a string prefix) correctly handles the root dir
1623
- // ("/") and sibling-prefix ("/app" vs "/app-evil") edge cases.
1624
- //
1625
- // The actual open() below MUST target this validated `real` path, not the
1626
- // original `filePath` — otherwise a symlink swapped between the realpath()
1627
- // check and the open() call routes the read outside the sandbox even
1628
- // though validation passed (TOCTOU). With no sandbox configured there's no
1629
- // boundary to defend, so the original path is used as given.
1630
- let pathToOpen = filePath;
1631
- if (options?.allowedBaseDir) {
1632
- let base;
1633
- let real;
1634
- try {
1635
- base = await realpath(resolvePath(options.allowedBaseDir));
1636
- real = await realpath(filePath);
1637
- }
1638
- catch (error) {
1639
- // Full path stays in the debug log; the thrown (potentially
1640
- // client-facing) error only gets the basename to avoid leaking the
1641
- // host's directory layout to an untrusted caller. The cause is
1642
- // sanitized too — Node's realpath ENOENT/EACCES messages embed the
1643
- // full path verbatim, which would otherwise survive on the cause
1644
- // chain (cause-aware logging, telemetry) even though the outer
1645
- // message is already redacted.
1646
- logger.debug("loadFromPath: realpath resolution failed", {
1647
- filePath,
1648
- error,
1649
- });
1650
- // Assigned to a variable before the throw (rather than an inline
1651
- // `{ cause: sanitizeErrorCause(...) }`) so the sanitized, path-redacted
1652
- // copy is unambiguously the attached cause — the raw `error`, whose
1653
- // message still embeds the full path, is never reachable from the
1654
- // thrown result.
1655
- const cause = sanitizeErrorCause(error, { filePath });
1656
- const denied = new Error(`Access denied: "${basename(filePath)}" could not be resolved within the allowed base directory`, { cause });
1657
- throw denied;
1658
- }
1659
- const rel = relativePath(base, real);
1660
- if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolutePath(rel)) {
1661
- logger.debug("loadFromPath: path resolves outside allowed base dir", {
1662
- filePath,
1663
- real,
1664
- });
1665
- throw new Error(`Access denied: "${basename(filePath)}" resolves outside the allowed base directory`);
1666
- }
1667
- pathToOpen = real;
1668
- }
1669
- // Open a handle and stat/read through the SAME descriptor so a symlink
1670
- // swap between the size check and the read cannot occur (TOCTOU).
1671
- let handle;
1672
- try {
1673
- handle = await open(pathToOpen, "r");
1674
- }
1675
- catch (error) {
1676
- // A failed open (ENOENT/EACCES/…) embeds the opened path verbatim in
1677
- // its message. When a sandbox is configured `pathToOpen` is the
1678
- // realpath-resolved target (`real`), which differs from both `filePath`
1679
- // and its resolved form — so redact `pathToOpen` specifically, or the
1680
- // full host path would survive on both the thrown message and the cause
1681
- // chain despite this PR's path-redaction hardening.
1682
- const cause = sanitizeErrorCause(error, { filePath: pathToOpen });
1683
- const failed = new Error(cause.message, { cause });
1684
- failed.name = cause.name;
1685
- const code = cause.code;
1686
- if (code !== undefined) {
1687
- failed.code = code;
1688
- }
1689
- throw failed;
1690
- }
1691
- try {
1692
- const statInfo = await handle.stat();
1693
- if (!statInfo.isFile()) {
1694
- throw new Error(`Not a file: ${basename(filePath)}`);
1695
- }
1696
- if (statInfo.size > maxSize) {
1697
- throw new Error(`File too large: ${basename(filePath)} is ${formatFileSize(statInfo.size)} (max: ${formatFileSize(maxSize)})`);
1698
- }
1699
- return await handle.readFile();
1700
- }
1701
- finally {
1702
- await handle.close();
1703
- }
1704
- }
1705
- /**
1706
- * Load file from data URI
1707
- */
1708
- static loadFromDataURI(dataUri) {
1709
- const match = dataUri.match(/^data:([^;]+);base64,(.+)$/);
1710
- if (!match) {
1711
- throw new Error(`Invalid data URI format (expected "data:<mime>;base64,<data>"): "${dataUri.slice(0, 32)}…"`);
1712
- }
1713
- return Buffer.from(match[2], "base64");
1714
- }
1715
- }
1716
- /**
1717
- * Resolve an extension to a routing {@link FileType}.
1718
- *
1719
- * Consults, in order:
1720
- * 1. the canonical file-type registry — every image / audio / video /
1721
- * document / data / archive format;
1722
- * 2. the text, markup and config MIME map;
1723
- * 3. `LANGUAGE_MAP`, which already enumerates ~200 source-code extensions.
1724
- *
1725
- * (3) is why this is a function rather than a table: source code was
1726
- * previously a third hand-written list inside the detector covering roughly a
1727
- * quarter of the languages the code processor already knew about, so a `.zig`
1728
- * or `.erl` file was "unknown" and fell through to content heuristics.
1729
- *
1730
- * Returns undefined when the extension is not recognised at all.
1731
- */
1732
- function resolveFileTypeForExtension(ext) {
1733
- const registryType = fileTypeForExtension(ext);
1734
- if (registryType) {
1735
- return registryType;
1736
- }
1737
- const normalized = normalizeExtension(ext);
1738
- if (TEXT_EXTENSION_MIME_MAP[normalized] ||
1739
- LANGUAGE_MAP[normalized] ||
1740
- CONFIG_EXTENSIONS.includes(normalized)) {
1741
- return "text";
1742
- }
1743
- return undefined;
1744
- }
1745
- /**
1746
- * Bytes read from the head of a file when running magic-byte detection against
1747
- * a path.
1748
- *
1749
- * 4 KB rather than a few dozen: the largest consumers are the M2TS sync check
1750
- * (three 192-byte packets), the ASF stream-type GUID (which sits past the
1751
- * header object), and the OOXML sniff, which looks for `xl/`, `word/` or
1752
- * `ppt/` entry names inside a ZIP directory. Still a single small read, and
1753
- * far cheaper than the whole-file read the content heuristics would otherwise
1754
- * perform.
1755
- */
1756
- const MAGIC_BYTES_HEADER_SIZE = 4096;
1757
- /**
1758
- * ASF stream-type GUIDs, little-endian as stored in the file.
1759
- *
1760
- * `.wmv` and `.wma` share the same container signature, so the container alone
1761
- * cannot say which modality a file is. These GUIDs appear in the stream
1762
- * properties object and do.
1763
- */
1764
- const ASF_VIDEO_MEDIA_GUID = Buffer.from("c0ef19bc4d5bcf11a8fd00805f5c442b", "hex");
1765
- const ASF_AUDIO_MEDIA_GUID = Buffer.from("409e69f84d5bcf11a8fd00805f5c442b", "hex");
1766
- /**
1767
- * Identify an OOXML or OpenDocument package inside a ZIP.
1768
- *
1769
- * Every Office format is a ZIP, so the ZIP signature alone routes .xlsx, .docx,
1770
- * .pptx and .odt to the archive processor whenever no filename is available —
1771
- * which is exactly the shape of a Slack or API upload that arrives as a bare
1772
- * Buffer. Reading the entry names recovers the real type.
1773
- *
1774
- * ODF is exact: the spec requires a `mimetype` entry stored first and
1775
- * uncompressed, so the media type is literally in the bytes. OOXML has no such
1776
- * guarantee, so its part prefixes (`xl/`, `word/`, `ppt/`) are matched instead,
1777
- * gated on `[Content_Types].xml` being present so a plain ZIP that happens to
1778
- * contain a folder called `word/` is not misread.
1779
- *
1780
- * Returns null when the ZIP is inconclusive, leaving the archive fallback and
1781
- * the extension to decide.
1782
- */
1783
- function detectZipPackageType(input) {
1784
- const head = input.toString("latin1", 0, Math.min(input.length, 4096));
1785
- // ODF: the mimetype string follows the stored "mimetype" entry name directly.
1786
- const odfMatch = head.match(/mimetype(application\/vnd\.oasis\.opendocument\.[a-z-]+)/);
1787
- if (odfMatch) {
1788
- const mimeType = odfMatch[1];
1789
- const entry = lookupByMimeType(mimeType);
1790
- if (entry) {
1791
- return { type: entry.fileType, mimeType };
1792
- }
1793
- }
1794
- if (!head.includes("[Content_Types].xml")) {
1795
- return null;
1796
- }
1797
- for (const [prefix, mimeType] of [
1798
- [
1799
- "xl/",
1800
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1801
- ],
1802
- [
1803
- "word/",
1804
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1805
- ],
1806
- [
1807
- "ppt/",
1808
- "application/vnd.openxmlformats-officedocument.presentationml.presentation",
1809
- ],
1810
- ]) {
1811
- if (head.includes(prefix)) {
1812
- const entry = lookupByMimeType(mimeType);
1813
- if (entry) {
1814
- return { type: entry.fileType, mimeType };
1815
- }
1816
- }
1817
- }
1818
- return null;
1819
- }
1820
- /**
1821
- * Strategy 1: Magic Bytes Detection (95% confidence)
1822
- * Detects file type from binary file headers
1823
- */
1824
- class MagicBytesStrategy {
1825
- async detect(input) {
1826
- const buffer = await MagicBytesStrategy.resolveBuffer(input);
1827
- if (!buffer) {
1828
- return this.unknown();
1829
- }
1830
- return this.detectFromBuffer(buffer);
1831
- }
1832
- /**
1833
- * Obtain the header bytes to inspect.
1834
- *
1835
- * Buffers are used directly. For a filesystem path we read only the first
1836
- * {@link MAGIC_BYTES_HEADER_SIZE} bytes — this strategy previously bailed out
1837
- * for anything that was not already a Buffer, which meant a path was
1838
- * classified by its extension alone and any file whose extension was missing,
1839
- * wrong or ambiguous fell through to the content heuristics. Those heuristics
1840
- * `readFile()` the *entire* file, so detecting a 500 MB video used to read
1841
- * 500 MB into memory to conclude nothing; now it reads
1842
- * {@link MAGIC_BYTES_HEADER_SIZE} bytes and returns.
1843
- *
1844
- * URLs and data URIs are left alone: a URL would need a network round-trip
1845
- * (the MIME strategy handles it), and a data URI already carries its type.
1846
- */
1847
- static async resolveBuffer(input) {
1848
- if (Buffer.isBuffer(input)) {
1849
- return input;
1850
- }
1851
- if (typeof input !== "string" ||
1852
- input.startsWith("data:") ||
1853
- input.startsWith("http://") ||
1854
- input.startsWith("https://")) {
1855
- return undefined;
1856
- }
1857
- let handle;
1858
- try {
1859
- handle = await open(input, "r");
1860
- const header = Buffer.alloc(MAGIC_BYTES_HEADER_SIZE);
1861
- const { bytesRead } = await handle.read(header, 0, header.length, 0);
1862
- return bytesRead > 0 ? header.subarray(0, bytesRead) : undefined;
1863
- }
1864
- catch {
1865
- // Not a readable path (nonexistent, a directory, permission denied).
1866
- // Detection continues with the remaining strategies.
1867
- return undefined;
1868
- }
1869
- finally {
1870
- await handle?.close().catch(() => undefined);
1871
- }
1872
- }
1873
- detectFromBuffer(input) {
1874
- if (this.isPNG(input)) {
1875
- return this.result("image", "image/png", 95);
1876
- }
1877
- if (this.isJPEG(input)) {
1878
- return this.result("image", "image/jpeg", 95);
1879
- }
1880
- if (this.isGIF(input)) {
1881
- return this.result("image", "image/gif", 95);
1882
- }
1883
- if (this.isWebP(input)) {
1884
- return this.result("image", "image/webp", 95);
1885
- }
1886
- if (input.length >= 2 && input[0] === 0x42 && input[1] === 0x4d) {
1887
- return this.result("image", "image/bmp", 95);
1888
- }
1889
- if (input.length >= 4 &&
1890
- ((input[0] === 0x49 &&
1891
- input[1] === 0x49 &&
1892
- input[2] === 0x2a &&
1893
- input[3] === 0x00) ||
1894
- (input[0] === 0x4d &&
1895
- input[1] === 0x4d &&
1896
- input[2] === 0x00 &&
1897
- input[3] === 0x2a))) {
1898
- return this.result("image", "image/tiff", 95);
1899
- }
1900
- if (input.length >= 4 &&
1901
- input[0] === 0x00 &&
1902
- input[1] === 0x00 &&
1903
- input[2] === 0x01 &&
1904
- input[3] === 0x00 &&
1905
- !hasFtypBoxSignature(input)) {
1906
- return this.result("image", "image/x-icon", 95);
1907
- }
1908
- if (this.isPDF(input)) {
1909
- return this.result("pdf", "application/pdf", 95);
1910
- }
1911
- // ISO-BMFF ("ftyp" at offset 4): MP4 video, QuickTime MOV, or M4A/M4B/M4P
1912
- // audio all share this box — disambiguate by the major brand at offset 8-11,
1913
- // otherwise an .m4a audio file is misrouted to the video pipeline.
1914
- if (hasFtypBoxSignature(input)) {
1915
- const brand = input.length >= 12 ? input.toString("latin1", 8, 12) : "";
1916
- // AVIF images share the ISO-BMFF ftyp box with MP4/MOV; the major brand
1917
- // ('avif' still, 'avis' sequence, 'avio' intra-only AV1 image/sequence
1918
- // — spec-listed under compatible_brands but also emitted as
1919
- // major_brand by real encoders) distinguishes them. Detect before the
1920
- // audio/video branches so an AVIF buffer isn't misrouted to the video
1921
- // pipeline (#286).
1922
- const imageMimeType = detectIsoBmffImageMimeType(input);
1923
- if (imageMimeType) {
1924
- return this.result("image", imageMimeType, 95);
1925
- }
1926
- if (/^(M4A|M4B|M4P|F4A|F4B)/.test(brand)) {
1927
- return this.result("audio", "audio/mp4", 95);
1928
- }
1929
- if (brand.startsWith("qt")) {
1930
- return this.result("video", "video/quicktime", 95);
1931
- }
1932
- // 3GPP / 3GPP2 share the ftyp box. Brands are "3gp4".."3gp9", "3gr6",
1933
- // "3gs7", "3ge6" … for 3GPP and "3g2a".."3g2c" for 3GPP2. A 3GPP file can
1934
- // hold audio only (phone voice memos) or audio+video, and the brand does
1935
- // not say which — so this reports video at a confidence *below* the
1936
- // detection threshold, letting a `.3gp`/`.3g2` extension confirm it and
1937
- // an explicit audio mimetype hint override it.
1938
- if (brand.startsWith("3g2")) {
1939
- return this.result("video", "video/3gpp2", 75);
1940
- }
1941
- if (brand.startsWith("3g")) {
1942
- return this.result("video", "video/3gpp", 75);
1943
- }
1944
- return this.result("video", "video/mp4", 95);
1945
- }
1946
- // EBML container (MKV/WebM) — both share the 0x1A45DFA3 header; the DocType
1947
- // string in the header disambiguates WebM from generic Matroska.
1948
- if (input.length >= 4 &&
1949
- input[0] === 0x1a &&
1950
- input[1] === 0x45 &&
1951
- input[2] === 0xdf &&
1952
- input[3] === 0xa3) {
1953
- const head = input.toString("latin1", 0, Math.min(input.length, 64));
1954
- if (head.includes("webm")) {
1955
- return this.result("video", "video/webm", 92);
1956
- }
1957
- return this.result("video", "video/x-matroska", 90);
1958
- }
1959
- // AVI: "RIFF" + "AVI "
1960
- if (input.length >= 12 &&
1961
- input[0] === 0x52 &&
1962
- input[1] === 0x49 &&
1963
- input[2] === 0x46 &&
1964
- input[3] === 0x46 &&
1965
- input[8] === 0x41 &&
1966
- input[9] === 0x56 &&
1967
- input[10] === 0x49 &&
1968
- input[11] === 0x20) {
1969
- return this.result("video", "video/x-msvideo", 95);
1970
- }
1971
- // WAV: "RIFF" + "WAVE"
1972
- if (input.length >= 12 &&
1973
- input[0] === 0x52 &&
1974
- input[1] === 0x49 &&
1975
- input[2] === 0x46 &&
1976
- input[3] === 0x46 &&
1977
- input[8] === 0x57 &&
1978
- input[9] === 0x41 &&
1979
- input[10] === 0x56 &&
1980
- input[11] === 0x45) {
1981
- return this.result("audio", "audio/wav", 95);
1982
- }
1983
- // AIFF / AIFF-C: "FORM" + "AIFF" or "AIFC" at offset 8. Same IFF container
1984
- // shape as RIFF above, big-endian.
1985
- if (input.length >= 12 &&
1986
- input.toString("latin1", 0, 4) === "FORM" &&
1987
- (input.toString("latin1", 8, 12) === "AIFF" ||
1988
- input.toString("latin1", 8, 12) === "AIFC")) {
1989
- return this.result("audio", "audio/aiff", 95);
1990
- }
1991
- // ASF container — Windows Media. The header GUID is shared by .wmv (video)
1992
- // and .wma (audio), so the stream-type GUID inside decides. A .wma read
1993
- // from a bare Buffer was reported as video before this lookup existed.
1994
- if (input.length >= 4 &&
1995
- input[0] === 0x30 &&
1996
- input[1] === 0x26 &&
1997
- input[2] === 0xb2 &&
1998
- input[3] === 0x75) {
1999
- if (input.includes(ASF_VIDEO_MEDIA_GUID)) {
2000
- return this.result("video", "video/x-ms-wmv", 92);
2001
- }
2002
- if (input.includes(ASF_AUDIO_MEDIA_GUID)) {
2003
- return this.result("audio", "audio/x-ms-wma", 92);
2004
- }
2005
- // Neither GUID within the header slice — report below the detection
2006
- // threshold so an extension, if there is one, still wins.
2007
- return this.result("video", "video/x-ms-asf", 75);
2008
- }
2009
- // FLV: "FLV" + version byte.
2010
- if (input.length >= 4 &&
2011
- input.toString("latin1", 0, 3) === "FLV" &&
2012
- input[3] === 0x01) {
2013
- return this.result("video", "video/x-flv", 95);
2014
- }
2015
- // Rich Text Format: "{\rtf".
2016
- if (input.length >= 5 && input.toString("latin1", 0, 5) === "{\\rtf") {
2017
- return this.result("docx", "application/rtf", 92);
2018
- }
2019
- // Core Audio Format: "caff".
2020
- if (input.length >= 4 && input.toString("latin1", 0, 4) === "caff") {
2021
- return this.result("audio", "audio/x-caf", 95);
2022
- }
2023
- // Sun/NeXT audio: ".snd".
2024
- if (input.length >= 4 && input.toString("latin1", 0, 4) === ".snd") {
2025
- return this.result("audio", "audio/basic", 95);
2026
- }
2027
- // MPEG program stream (0x000001BA) and elementary video stream (0x000001B3)
2028
- // — .mpg/.mpeg/.vob. Without this, an MPEG-1 file reached the content
2029
- // heuristics, whose CSV check found consistent delimiter counts in the
2030
- // binary and classified real video as a spreadsheet.
2031
- if (input.length >= 4 &&
2032
- input[0] === 0x00 &&
2033
- input[1] === 0x00 &&
2034
- input[2] === 0x01 &&
2035
- (input[3] === 0xba || input[3] === 0xb3)) {
2036
- return this.result("video", "video/mpeg", 95);
2037
- }
2038
- // MPEG-2 transport stream — .ts/.mts/.m2ts. There is no magic number, only
2039
- // a 0x47 sync byte at a fixed stride; requiring three in a row keeps a
2040
- // stray 0x47 from claiming an unrelated file. This is also what rescues
2041
- // `.ts`, whose extension resolves to TypeScript source.
2042
- //
2043
- // Two strides, because BDAV/M2TS prefixes each packet with a 4-byte arrival
2044
- // timestamp: plain TS is 188 bytes from offset 0, M2TS is 192 from offset 4.
2045
- // Checking only the former left every .m2ts undetected from a Buffer.
2046
- if ((input.length >= 377 &&
2047
- input[0] === 0x47 &&
2048
- input[188] === 0x47 &&
2049
- input[376] === 0x47) ||
2050
- (input.length >= 389 &&
2051
- input[4] === 0x47 &&
2052
- input[196] === 0x47 &&
2053
- input[388] === 0x47)) {
2054
- return this.result("video", "video/mp2t", 92);
2055
- }
2056
- // MIDI: "MThd"
2057
- if (input.length >= 4 && input.toString("latin1", 0, 4) === "MThd") {
2058
- return this.result("audio", "audio/midi", 95);
2059
- }
2060
- // Monkey's Audio: "MAC " — the trailing space is part of the signature.
2061
- if (input.length >= 4 && input.toString("latin1", 0, 4) === "MAC ") {
2062
- return this.result("audio", "audio/x-ape", 95);
2063
- }
2064
- // WavPack: "wvpk"
2065
- if (input.length >= 4 && input.toString("latin1", 0, 4) === "wvpk") {
2066
- return this.result("audio", "audio/x-wavpack", 95);
2067
- }
2068
- // AMR narrowband ("#!AMR\n") and wideband ("#!AMR-WB\n").
2069
- if (input.length >= 6 && input.toString("latin1", 0, 5) === "#!AMR") {
2070
- return this.result("audio", "audio/amr", 95);
2071
- }
2072
- // JPEG 2000: the full 12-byte signature box, trailing 0D 0A 87 0A
2073
- // included. Those four bytes are a deliberate line-ending probe — CR LF, a
2074
- // high byte, LF — that any transfer which mangles newlines or strips the
2075
- // eighth bit will visibly corrupt, so checking only the length and brand
2076
- // accepts exactly the damaged files the signature exists to reject.
2077
- if (input.length >= 12 &&
2078
- input[0] === 0x00 &&
2079
- input[1] === 0x00 &&
2080
- input[2] === 0x00 &&
2081
- input[3] === 0x0c &&
2082
- input.toString("latin1", 4, 8) === "jP " &&
2083
- input[8] === 0x0d &&
2084
- input[9] === 0x0a &&
2085
- input[10] === 0x87 &&
2086
- input[11] === 0x0a) {
2087
- return this.result("image", "image/jp2", 95);
2088
- }
2089
- // The other shape JPEG 2000 ships in: a bare codestream (.j2k/.j2c) opening
2090
- // with the SOC + SIZ markers. `ImageProcessor.detectImageType` learned both
2091
- // shapes; this strategy knew only the container, so a codestream uploaded
2092
- // as bytes-plus-filename was typed "unknown" and delivered as a binary
2093
- // blob — the codestream branch over there was unreachable from this path.
2094
- if (input.length >= 4 &&
2095
- input[0] === 0xff &&
2096
- input[1] === 0x4f &&
2097
- input[2] === 0xff &&
2098
- input[3] === 0x51) {
2099
- return this.result("image", "image/jp2", 95);
2100
- }
2101
- // MP3: ID3 tag
2102
- if (input.length >= 3 &&
2103
- input[0] === 0x49 &&
2104
- input[1] === 0x44 &&
2105
- input[2] === 0x33) {
2106
- return this.result("audio", "audio/mpeg", 95);
2107
- }
2108
- // AAC (ADTS): 12-bit syncword 0xFFF with the 2 layer bits == 00. This must be
2109
- // checked before the MP3 sync word below, because an ADTS header also satisfies
2110
- // the looser 11-bit MPEG sync mask and would otherwise be mislabeled audio/mpeg.
2111
- if (input.length >= 2 && input[0] === 0xff && (input[1] & 0xf6) === 0xf0) {
2112
- return this.result("audio", "audio/aac", 85);
2113
- }
2114
- // MP3: sync word (MPEG audio — layer bits are non-zero, unlike ADTS AAC above)
2115
- if (input.length >= 2 && input[0] === 0xff && (input[1] & 0xe0) === 0xe0) {
2116
- return this.result("audio", "audio/mpeg", 80);
2117
- }
2118
- // FLAC: "fLaC"
2119
- if (input.length >= 4 &&
2120
- input[0] === 0x66 &&
2121
- input[1] === 0x4c &&
2122
- input[2] === 0x61 &&
2123
- input[3] === 0x43) {
2124
- return this.result("audio", "audio/flac", 95);
2125
- }
2126
- // OGG: "OggS"
2127
- if (input.length >= 4 &&
2128
- input[0] === 0x4f &&
2129
- input[1] === 0x67 &&
2130
- input[2] === 0x67 &&
2131
- input[3] === 0x53) {
2132
- // Ogg is a container, not a codec — .ogv (Theora/VP8 video) and .oga/.opus
2133
- // (Vorbis/Opus/FLAC audio) all start "OggS". The codec identifier lives in
2134
- // the first page's payload, so read it rather than assuming audio and
2135
- // routing every Ogg video to the audio processor.
2136
- const firstPage = input.toString("latin1", 0, Math.min(input.length, 128));
2137
- if (firstPage.includes("theora") || firstPage.includes("VP80")) {
2138
- return this.result("video", "video/ogg", 92);
2139
- }
2140
- if (firstPage.includes("OpusHead")) {
2141
- return this.result("audio", "audio/opus", 92);
2142
- }
2143
- return this.result("audio", "audio/ogg", 90);
2144
- }
2145
- // ZIP: "PK\x03\x04"
2146
- // Many document formats (OOXML: .xlsx, .docx, .pptx; ODF: .odt, .ods) are
2147
- // internally ZIP archives and share these magic bytes. Read the entry names
2148
- // first — that identifies the real format even for a bare Buffer with no
2149
- // filename, which previously routed every Office document to the archive
2150
- // processor. An inconclusive ZIP still reports archive at a lower
2151
- // confidence (70%) so the ExtensionStrategy (85%) can override it.
2152
- if (input.length >= 4 &&
2153
- input[0] === 0x50 &&
2154
- input[1] === 0x4b &&
2155
- input[2] === 0x03 &&
2156
- input[3] === 0x04) {
2157
- const packaged = detectZipPackageType(input);
2158
- if (packaged) {
2159
- return this.result(packaged.type, packaged.mimeType, 92);
2160
- }
2161
- return this.result("archive", "application/zip", 70);
2162
- }
2163
- // GZIP: 1F 8B
2164
- if (input.length >= 2 && input[0] === 0x1f && input[1] === 0x8b) {
2165
- return this.result("archive", "application/gzip", 90);
2166
- }
2167
- // BZIP2: "BZh" + a compression-level digit.
2168
- if (input.length >= 4 &&
2169
- input.toString("latin1", 0, 3) === "BZh" &&
2170
- input[3] >= 0x31 &&
2171
- input[3] <= 0x39) {
2172
- return this.result("archive", "application/x-bzip2", 95);
2173
- }
2174
- // XZ: FD "7zXZ" 00
2175
- if (input.length >= 6 &&
2176
- input[0] === 0xfd &&
2177
- input.toString("latin1", 1, 5) === "7zXZ" &&
2178
- input[5] === 0x00) {
2179
- return this.result("archive", "application/x-xz", 95);
2180
- }
2181
- // Zstandard frame magic: 28 B5 2F FD
2182
- if (input.length >= 4 &&
2183
- input[0] === 0x28 &&
2184
- input[1] === 0xb5 &&
2185
- input[2] === 0x2f &&
2186
- input[3] === 0xfd) {
2187
- return this.result("archive", "application/zstd", 95);
2188
- }
2189
- // TAR: "ustar" at offset 257, inside the first header block. Checked late
2190
- // because it is a weak, deep signature — anything with its own leading
2191
- // magic number should have matched already.
2192
- if (input.length >= 262 && input.toString("latin1", 257, 262) === "ustar") {
2193
- return this.result("archive", "application/x-tar", 90);
2194
- }
2195
- // 7z: 37 7A BC AF 27 1C
2196
- if (input.length >= 6 &&
2197
- input[0] === 0x37 &&
2198
- input[1] === 0x7a &&
2199
- input[2] === 0xbc &&
2200
- input[3] === 0xaf &&
2201
- input[4] === 0x27 &&
2202
- input[5] === 0x1c) {
2203
- return this.result("archive", "application/x-7z-compressed", 95);
2204
- }
2205
- // RAR: "Rar!"
2206
- if (input.length >= 4 &&
2207
- input[0] === 0x52 &&
2208
- input[1] === 0x61 &&
2209
- input[2] === 0x72 &&
2210
- input[3] === 0x21) {
2211
- return this.result("archive", "application/x-rar-compressed", 95);
2212
- }
2213
- // SVG is text, so it has no byte signature — but it does have an
2214
- // unambiguous root element. Without this an SVG supplied as a Buffer was
2215
- // classified as generic XML and inlined as raw markup instead of going
2216
- // through the SVG sanitizer, which is the whole reason SVG has its own
2217
- // FileType. Checked last so no binary format can be beaten to it.
2218
- if (looksLikeSvgMarkup(input)) {
2219
- return this.result("svg", "image/svg+xml", 90);
2220
- }
2221
- return this.unknown();
2222
- }
2223
- isPNG(buf) {
2224
- return (buf.length >= 4 &&
2225
- buf[0] === 0x89 &&
2226
- buf[1] === 0x50 &&
2227
- buf[2] === 0x4e &&
2228
- buf[3] === 0x47);
2229
- }
2230
- isJPEG(buf) {
2231
- return (buf.length >= 3 && buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff);
2232
- }
2233
- isGIF(buf) {
2234
- return (buf.length >= 4 &&
2235
- buf[0] === 0x47 &&
2236
- buf[1] === 0x49 &&
2237
- buf[2] === 0x46 &&
2238
- buf[3] === 0x38);
2239
- }
2240
- isWebP(buf) {
2241
- return (buf.length >= 12 &&
2242
- buf.slice(0, 4).toString() === "RIFF" &&
2243
- buf.slice(8, 12).toString() === "WEBP");
2244
- }
2245
- isPDF(buf) {
2246
- return buf.length >= 5 && buf.slice(0, 5).toString() === "%PDF-";
2247
- }
2248
- result(type, mime, confidence) {
2249
- return {
2250
- type,
2251
- mimeType: mime,
2252
- extension: null,
2253
- source: "buffer",
2254
- metadata: { confidence },
2255
- };
2256
- }
2257
- unknown() {
2258
- return {
2259
- type: "unknown",
2260
- mimeType: "application/octet-stream",
2261
- extension: null,
2262
- source: "buffer",
2263
- metadata: { confidence: 0 },
2264
- };
2265
- }
2266
- }
2267
- /**
2268
- * Strategy 2: MIME Type Detection (85% confidence)
2269
- * Detects file type from HTTP Content-Type headers
2270
- */
2271
- class MimeTypeStrategy {
2272
- async detect(input) {
2273
- if (typeof input !== "string" || !this.isURL(input)) {
2274
- return this.unknown();
2275
- }
2276
- try {
2277
- // #323: reuse a recently-seen Content-Type for this URL instead of
2278
- // re-issuing a HEAD (populated here and by loadFromURL's GET).
2279
- const now = Date.now();
2280
- let contentType = getCachedUrlContentType(input, now);
2281
- if (contentType === undefined) {
2282
- // Wrap the whole HEAD (request + body drain) in withTimeout so a stalled
2283
- // dump() can't hang detection, per the project's async-timeout guideline.
2284
- contentType = await withTimeout((async () => {
2285
- const response = await request(input, {
2286
- dispatcher: getGlobalDispatcher().compose(interceptors.redirect({ maxRedirections: 5 })),
2287
- method: "HEAD",
2288
- headersTimeout: FileDetector.DEFAULT_HEAD_TIMEOUT,
2289
- bodyTimeout: FileDetector.DEFAULT_HEAD_TIMEOUT,
2290
- });
2291
- await response.body.dump();
2292
- return response.headers["content-type"] || "";
2293
- })(), FileDetector.DEFAULT_HEAD_TIMEOUT);
2294
- setCachedUrlContentType(input, contentType, now);
2295
- }
2296
- const type = this.mimeToFileType(contentType);
2297
- return {
2298
- type,
2299
- mimeType: contentType.split(";")[0].trim(),
2300
- extension: null,
2301
- source: "url",
2302
- metadata: { confidence: type !== "unknown" ? 85 : 0 },
2303
- };
2304
- }
2305
- catch {
2306
- return this.unknown();
2307
- }
2308
- }
2309
- mimeToFileType(mime) {
2310
- const lower = mime.toLowerCase().split(";")[0].trim();
2311
- // CSV
2312
- if (lower === "text/csv" || lower === "text/tab-separated-values") {
2313
- return "csv";
2314
- }
2315
- // SVG is processed as text/markup, NOT as image
2316
- // Must check before generic image/ check
2317
- if (lower === "image/svg+xml") {
2318
- return "svg";
2319
- }
2320
- // Images
2321
- if (lower.startsWith("image/")) {
2322
- return "image";
2323
- }
2324
- // PDF
2325
- if (lower === "application/pdf") {
2326
- return "pdf";
2327
- }
2328
- // Video
2329
- if (lower.startsWith("video/")) {
2330
- return "video";
2331
- }
2332
- // Audio
2333
- if (lower.startsWith("audio/")) {
2334
- return "audio";
2335
- }
2336
- // Office documents — OOXML
2337
- if (lower ===
2338
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ||
2339
- lower === "application/msword") {
2340
- return "docx";
2341
- }
2342
- if (lower ===
2343
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ||
2344
- lower === "application/vnd.ms-excel") {
2345
- return "xlsx";
2346
- }
2347
- if (lower ===
2348
- "application/vnd.openxmlformats-officedocument.presentationml.presentation" ||
2349
- lower === "application/vnd.ms-powerpoint") {
2350
- return "pptx";
2351
- }
2352
- // OpenDocument formats
2353
- if (lower === "application/vnd.oasis.opendocument.text") {
2354
- return "docx";
2355
- }
2356
- if (lower === "application/vnd.oasis.opendocument.spreadsheet") {
2357
- return "xlsx";
2358
- }
2359
- if (lower === "application/vnd.oasis.opendocument.presentation") {
2360
- return "pptx";
2361
- }
2362
- // RTF
2363
- if (lower === "application/rtf" || lower === "text/rtf") {
2364
- return "docx";
2365
- }
2366
- // Archive formats
2367
- if (lower === "application/zip" ||
2368
- lower === "application/x-zip-compressed" ||
2369
- lower === "application/gzip" ||
2370
- lower === "application/x-gzip" ||
2371
- lower === "application/x-tar" ||
2372
- lower === "application/x-compressed-tar" ||
2373
- lower === "application/java-archive" ||
2374
- lower === "application/x-rar-compressed" ||
2375
- lower === "application/vnd.rar" ||
2376
- lower === "application/x-7z-compressed") {
2377
- return "archive";
2378
- }
2379
- // Text/markup/source code — broad matching
2380
- if (lower === "text/plain" ||
2381
- lower === "text/markdown" ||
2382
- lower === "text/html" ||
2383
- lower === "text/css" ||
2384
- lower === "text/javascript" ||
2385
- lower === "text/typescript" ||
2386
- lower === "application/json" ||
2387
- lower === "application/xml" ||
2388
- lower === "text/xml" ||
2389
- lower === "application/yaml" ||
2390
- lower === "application/x-yaml") {
2391
- return "text";
2392
- }
2393
- // Source code MIME types (text/x-*)
2394
- if (lower.startsWith("text/x-")) {
2395
- return "text";
2396
- }
2397
- // Generic text types we may not have listed explicitly
2398
- if (lower.startsWith("text/")) {
2399
- return "text";
2400
- }
2401
- return "unknown";
2402
- }
2403
- isURL(str) {
2404
- return str.startsWith("http://") || str.startsWith("https://");
2405
- }
2406
- unknown() {
2407
- return {
2408
- type: "unknown",
2409
- mimeType: "application/octet-stream",
2410
- extension: null,
2411
- source: "buffer",
2412
- metadata: { confidence: 0 },
2413
- };
2414
- }
2415
- }
2416
- /**
2417
- * Strategy 3: Extension Detection (70% confidence)
2418
- * Detects file type from file extension
2419
- */
2420
- class ExtensionStrategy {
2421
- async detect(input) {
2422
- if (typeof input !== "string") {
2423
- return this.unknown();
2424
- }
2425
- const ext = this.getExtension(input);
2426
- if (!ext) {
2427
- return this.unknown();
2428
- }
2429
- const type = resolveFileTypeForExtension(ext);
2430
- return {
2431
- type: type ?? "unknown",
2432
- mimeType: this.getMimeType(ext),
2433
- extension: ext,
2434
- source: this.detectSource(input),
2435
- metadata: { confidence: type ? 85 : 0 },
2436
- };
2437
- }
2438
- getExtension(input) {
2439
- const normalizedInput = input.trim();
2440
- let extensionSource = normalizedInput;
2441
- if (this.isURL(normalizedInput)) {
2442
- try {
2443
- const url = new URL(normalizedInput);
2444
- extensionSource = url.pathname;
2445
- try {
2446
- extensionSource = decodeURIComponent(extensionSource);
2447
- }
2448
- catch {
2449
- // Keep the original pathname if the URL contains malformed escapes.
2450
- }
2451
- }
2452
- catch {
2453
- extensionSource = normalizedInput;
2454
- }
2455
- }
2456
- const match = extensionSource.trim().match(/\.([^.]+)$/);
2457
- if (!match) {
2458
- return null;
2459
- }
2460
- const ext = match[1].split(/[?#]/)[0].toLowerCase();
2461
- return /^[a-z0-9]+$/.test(ext) ? ext : null;
2462
- }
2463
- isURL(str) {
2464
- const normalized = str.trim();
2465
- return (normalized.startsWith("http://") || normalized.startsWith("https://"));
2466
- }
2467
- detectSource(input) {
2468
- const normalized = input.trim();
2469
- if (normalized.startsWith("data:")) {
2470
- return "datauri";
2471
- }
2472
- if (this.isURL(normalized)) {
2473
- try {
2474
- new URL(normalized);
2475
- return "url";
2476
- }
2477
- catch {
2478
- return "path";
2479
- }
2480
- }
2481
- return "path";
2482
- }
2483
- getMimeType(ext) {
2484
- return getMimeTypeForExtension(ext);
2485
- }
2486
- unknown() {
2487
- return {
2488
- type: "unknown",
2489
- mimeType: "application/octet-stream",
2490
- extension: null,
2491
- source: "buffer",
2492
- metadata: { confidence: 0 },
2493
- };
2494
- }
2495
- }
2496
- /**
2497
- * Strategy 4: Content Heuristics (75% confidence)
2498
- * Detects file type by analyzing content patterns
2499
- */
2500
- class ContentHeuristicStrategy {
2501
- async detect(input) {
2502
- let buffer;
2503
- if (Buffer.isBuffer(input)) {
2504
- buffer = input;
2505
- }
2506
- else if (typeof input === "string") {
2507
- // Try to load from file path or data URI
2508
- if (input.startsWith("data:")) {
2509
- // Data URI
2510
- const match = input.match(/^data:([^;]+);base64,(.+)$/);
2511
- if (!match) {
2512
- return this.unknown();
2513
- }
2514
- buffer = Buffer.from(match[2], "base64");
2515
- }
2516
- else if (input.startsWith("http://") || input.startsWith("https://")) {
2517
- // URL - can't analyze without making HTTP request in ContentHeuristic
2518
- return this.unknown();
2519
- }
2520
- else {
2521
- // File path - try to load it
2522
- try {
2523
- buffer = await readFile(input);
2524
- }
2525
- catch {
2526
- return this.unknown();
2527
- }
2528
- }
2529
- }
2530
- else {
2531
- return this.unknown();
2532
- }
2533
- // Every check below runs on a UTF-8 *decoding* of the bytes, which succeeds
2534
- // for any input — decoding a video yields a string full of replacement
2535
- // characters, and that string can still satisfy a text heuristic. It did:
2536
- // MPEG-1 video decoded to "lines" with a consistent delimiter count and was
2537
- // classified `csv`, then handed to the CSV parser. Reject binary up front so
2538
- // no text heuristic can ever see it.
2539
- if (ContentHeuristicStrategy.looksBinary(buffer)) {
2540
- return this.unknown();
2541
- }
2542
- const sample = buffer.toString("utf-8", 0, Math.min(2000, buffer.length));
2543
- // Check for JSON first (more specific than CSV)
2544
- if (this.looksLikeJSON(sample)) {
2545
- return this.result("text", "application/json", 75);
2546
- }
2547
- // Check CSV after JSON (CSV is more generic)
2548
- if (this.looksLikeCSV(sample)) {
2549
- return this.result("csv", "text/csv", 75);
2550
- }
2551
- // Check for XML/HTML
2552
- if (this.looksLikeXML(sample)) {
2553
- const isHTML = sample.includes("<!DOCTYPE html") || sample.includes("<html");
2554
- return this.result("text", isHTML ? "text/html" : "application/xml", 70);
2555
- }
2556
- // Check for YAML
2557
- if (this.looksLikeYAML(sample)) {
2558
- return this.result("text", "application/yaml", 70);
2559
- }
2560
- // Check for plain text (if mostly printable characters)
2561
- if (this.looksLikeText(sample)) {
2562
- return this.result("text", "text/plain", 60);
2563
- }
2564
- return this.unknown();
2565
- }
2566
- /**
2567
- * Whether a buffer holds binary rather than text.
2568
- *
2569
- * Two independent signals, both computed on the same leading sample that the
2570
- * heuristics themselves inspect:
2571
- *
2572
- * - a NUL byte, which no text encoding this detector supports emits (UTF-16
2573
- * would, but it is not among the formats handled here and would already
2574
- * have been caught by its BOM);
2575
- * - more than 10% control/undecodable bytes, which catches binaries that
2576
- * happen not to contain a NUL in their first 2 KB.
2577
- *
2578
- * Tab, newline and carriage return are text and excluded from the control
2579
- * count.
2580
- */
2581
- static looksBinary(buffer) {
2582
- const sampleLength = Math.min(2000, buffer.length);
2583
- if (sampleLength === 0) {
2584
- return false;
2585
- }
2586
- let controlBytes = 0;
2587
- for (let i = 0; i < sampleLength; i++) {
2588
- const byte = buffer[i];
2589
- if (byte === 0x00) {
2590
- return true;
2591
- }
2592
- const isTextWhitespace = byte === 0x09 || byte === 0x0a || byte === 0x0d;
2593
- if (!isTextWhitespace && (byte < 0x20 || byte === 0x7f)) {
2594
- controlBytes++;
2595
- }
2596
- }
2597
- return controlBytes / sampleLength > 0.1;
2598
- }
2599
- looksLikeCSV(text) {
2600
- const lines = text.trim().split("\n");
2601
- if (lines.length < 2) {
2602
- return false;
2603
- }
2604
- // Detect delimiter from first line
2605
- const firstLine = lines[0];
2606
- const delimiters = [",", ";", "\t", "|"];
2607
- const delimiter = delimiters.find((d) => firstLine.includes(d));
2608
- // Single-column CSV check (no delimiter)
2609
- if (!delimiter) {
2610
- // Exclude content that looks like other structured formats
2611
- // YAML indicators
2612
- if (text.startsWith("---") ||
2613
- /^[\s]*-\s+/m.test(text) ||
2614
- /^[\s]*[a-zA-Z_][a-zA-Z0-9_-]*:\s*/m.test(text)) {
2615
- return false;
2616
- }
2617
- // XML/HTML indicators
2618
- if (text.startsWith("<") || text.includes("<?xml")) {
2619
- return false;
2620
- }
2621
- // JSON indicators
2622
- if ((text.startsWith("{") && text.includes("}")) ||
2623
- (text.startsWith("[") && text.includes("]"))) {
2624
- return false;
2625
- }
2626
- // Exclude prose/sentences (look for sentence patterns)
2627
- // Check for multiple words per line (prose indicator)
2628
- const hasProsePattern = lines.some((line) => {
2629
- const words = line.trim().split(/\s+/);
2630
- return words.length > 4; // More than 4 words suggests prose, not data
2631
- });
2632
- if (hasProsePattern) {
2633
- return false;
2634
- }
2635
- // Check for consistent line structure (not binary, reasonable lengths)
2636
- const hasReasonableLengths = lines.every((l) => l.length > 0 && l.length < 1000);
2637
- const noBinaryChars = !text.includes("\0");
2638
- // Single-column CSVs should have VERY uniform line lengths
2639
- // (data values like IDs, codes, numbers - not varied content)
2640
- const lengths = lines.map((l) => l.length);
2641
- const avgLength = lengths.reduce((a, b) => a + b, 0) / lengths.length;
2642
- const variance = lengths.reduce((sum, len) => sum + (len - avgLength) ** 2, 0) /
2643
- lengths.length;
2644
- const stdDev = Math.sqrt(variance);
2645
- // Single-column CSVs can contain varied data (names, cities, emails, etc.)
2646
- // but should still show some consistency compared to random text
2647
- const hasUniformLengths = stdDev / avgLength < 0.75;
2648
- return hasReasonableLengths && noBinaryChars && hasUniformLengths;
2649
- }
2650
- // Count delimiters per line and check consistency. Delimiters inside a
2651
- // double-quoted field are field content, not column separators (RFC 4180) —
2652
- // a naive count inflates rows with quoted delimiters (e.g. `"Smith, John"`),
2653
- // which used to make consistency collapse and reject a valid CSV.
2654
- const counts = lines.map((line) => ContentHeuristicStrategy.countDelimitersOutsideQuotes(line, delimiter));
2655
- const firstCount = counts[0];
2656
- const consistentLines = counts.filter((c) => c === firstCount).length;
2657
- return consistentLines / lines.length >= 0.8;
2658
- }
2659
- /**
2660
- * Count occurrences of `delimiter` in `line` that fall OUTSIDE double-quoted
2661
- * fields, honoring RFC-4180 escaped quotes (`""`). Used by CSV detection so a
2662
- * delimiter embedded in a quoted value is not mistaken for a column break.
2663
- */
2664
- static countDelimitersOutsideQuotes(line, delimiter) {
2665
- let count = 0;
2666
- let inQuotes = false;
2667
- for (let i = 0; i < line.length; i++) {
2668
- const ch = line[i];
2669
- if (ch === '"') {
2670
- if (inQuotes && line[i + 1] === '"') {
2671
- i++; // escaped quote inside a quoted field — skip the pair
2672
- continue;
2673
- }
2674
- inQuotes = !inQuotes;
2675
- }
2676
- else if (ch === delimiter && !inQuotes) {
2677
- count++;
2678
- }
2679
- }
2680
- return count;
2681
- }
2682
- looksLikeJSON(text) {
2683
- // hasJsonMarkers now does full validation including JSON.parse
2684
- return hasJsonMarkers(text);
2685
- }
2686
- looksLikeXML(text) {
2687
- const trimmed = text.trim();
2688
- // XML declaration is a definitive marker
2689
- if (trimmed.startsWith("<?xml")) {
2690
- return true;
2691
- }
2692
- // Check for HTML DOCTYPE or tags
2693
- if (trimmed.includes("<!DOCTYPE html") ||
2694
- trimmed.toLowerCase().includes("<html")) {
2695
- return true;
2696
- }
2697
- // Strict validation for arbitrary content starting with <:
2698
- // Must have proper tag structure with at least one closing tag
2699
- if (!trimmed.startsWith("<")) {
2700
- return false;
2701
- }
2702
- // Must have valid opening tag structure: <tagname followed by space or >
2703
- // Not just any < character
2704
- const hasValidOpeningTag = /<[a-zA-Z][a-zA-Z0-9-]*(?:\s[^>]*)?>/;
2705
- if (!hasValidOpeningTag.test(trimmed)) {
2706
- return false;
2707
- }
2708
- // Must have at least one closing tag or self-closing tag to be valid XML/HTML
2709
- const hasClosingTag = /<\/[a-zA-Z][a-zA-Z0-9-]*>/.test(trimmed);
2710
- const hasSelfClosingTag = /<[a-zA-Z][a-zA-Z0-9-]*(?:\s[^>]*)?\s*\/\s*>/.test(trimmed);
2711
- return hasClosingTag || hasSelfClosingTag;
2712
- }
2713
- looksLikeYAML(text) {
2714
- const trimmed = text.trim();
2715
- if (trimmed.length === 0) {
2716
- return false;
2717
- }
2718
- // For single-line content, be very conservative about YAML detection
2719
- const lines = trimmed.split("\n");
2720
- if (lines.length === 1) {
2721
- // Single line can only be YAML if it's a document marker
2722
- return trimmed === "---" || trimmed === "...";
2723
- }
2724
- // Collect YAML indicators (requires at least 2 for positive detection)
2725
- const indicators = [];
2726
- // Indicator 1: Document start marker (---)
2727
- indicators.push(trimmed.startsWith("---"));
2728
- // Indicator 2: Document end marker (...) or appears within content
2729
- indicators.push(/^\.\.\.$|[\n]\.\.\.$/.test(trimmed));
2730
- // Indicator 3: YAML list items (- followed by space at line start)
2731
- indicators.push(/^[\s]*-\s+[^-]/m.test(trimmed));
2732
- // Indicator 4: Multiple key-value pairs (at least 2)
2733
- // Allow hyphens and underscores in keys, support nested keys
2734
- const keyValuePattern = /^[\s]*[a-zA-Z_][a-zA-Z0-9_-]*:\s*(.+)$/;
2735
- const keyValueMatches = lines.filter((line) => keyValuePattern.test(line)).length;
2736
- indicators.push(keyValueMatches >= 2);
2737
- // Indicator 5: Nested indentation pattern (common in YAML objects/lists)
2738
- let hasNesting = false;
2739
- const sampleLines = lines.slice(0, 10);
2740
- for (let i = 0; i < sampleLines.length - 1; i++) {
2741
- const currentLine = sampleLines[i].trim();
2742
- const nextLine = sampleLines[i + 1];
2743
- if (currentLine.length > 0 &&
2744
- nextLine.length > 0 &&
2745
- /[:-]$/.test(currentLine)) {
2746
- const currentIndent = sampleLines[i].match(/^[\s]*/)?.[0].length ?? 0;
2747
- const nextIndent = nextLine.match(/^[\s]*/)?.[0].length ?? 0;
2748
- if (nextIndent > currentIndent) {
2749
- hasNesting = true;
2750
- break;
2751
- }
2752
- }
2753
- }
2754
- indicators.push(hasNesting);
2755
- // Indicator 6: YAML comments (# followed by space)
2756
- indicators.push(/^\s*#\s+/m.test(trimmed));
2757
- // Indicator 7: List continuation (multiple items with - )
2758
- const listItemCount = lines.filter((line) => /^[\s]*-[\s]/.test(line)).length;
2759
- indicators.push(listItemCount >= 2);
2760
- // Indicator 8: Inline maps or complex structures
2761
- indicators.push(/{\s*[a-zA-Z_]/.test(trimmed) || /\[.*\]/.test(trimmed));
2762
- // Require at least 2 indicators for confident YAML detection
2763
- const matchCount = indicators.filter(Boolean).length;
2764
- return matchCount >= 2;
2765
- }
2766
- looksLikeText(text) {
2767
- // Check if content has null bytes (binary indicator)
2768
- if (text.includes("\0")) {
2769
- return false;
2770
- }
2771
- // Count printable characters
2772
- let printable = 0;
2773
- for (let i = 0; i < text.length; i++) {
2774
- const code = text.charCodeAt(i);
2775
- if ((code >= 32 && code < 127) || // ASCII printable
2776
- code === 9 || // Tab
2777
- code === 10 || // Newline
2778
- code === 13 || // Carriage return
2779
- code > 127 // Unicode
2780
- ) {
2781
- printable++;
2782
- }
2783
- }
2784
- // At least 85% should be printable for text
2785
- return printable / text.length >= 0.85;
2786
- }
2787
- result(type, mime, confidence) {
2788
- return {
2789
- type,
2790
- mimeType: mime,
2791
- extension: null,
2792
- source: "buffer",
2793
- metadata: { confidence },
2794
- };
2795
- }
2796
- unknown() {
2797
- return {
2798
- type: "unknown",
2799
- mimeType: "application/octet-stream",
2800
- extension: null,
2801
- source: "buffer",
2802
- metadata: { confidence: 0 },
2803
- };
2804
- }
2805
- }
2806
- //# sourceMappingURL=fileDetector.js.map