@juspay/neurolink 9.54.5 → 9.54.7

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 (432) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/action/actionInputs.d.ts +1 -1
  3. package/dist/adapters/video/directorPipeline.js +6 -0
  4. package/dist/adapters/video/vertexVideoHandler.js +6 -0
  5. package/dist/agent/directTools.d.ts +3 -23
  6. package/dist/auth/AuthProviderFactory.d.ts +1 -3
  7. package/dist/auth/anthropicOAuth.d.ts +4 -7
  8. package/dist/auth/anthropicOAuth.js +23 -0
  9. package/dist/auth/errors.d.ts +1 -1
  10. package/dist/auth/index.d.ts +11 -0
  11. package/dist/auth/index.js +14 -0
  12. package/dist/auth/middleware/AuthMiddleware.d.ts +5 -60
  13. package/dist/auth/middleware/AuthMiddleware.js +3 -0
  14. package/dist/auth/middleware/rateLimitByUser.d.ts +4 -93
  15. package/dist/auth/middleware/rateLimitByUser.js +4 -0
  16. package/dist/auth/providers/BaseAuthProvider.d.ts +1 -1
  17. package/dist/auth/providers/CognitoProvider.js +3 -0
  18. package/dist/auth/providers/KeycloakProvider.js +3 -0
  19. package/dist/auth/providers/auth0.d.ts +1 -1
  20. package/dist/auth/sessionManager.d.ts +2 -0
  21. package/dist/auth/sessionManager.js +53 -11
  22. package/dist/auth/tokenStore.d.ts +2 -1
  23. package/dist/auth/tokenStore.js +45 -4
  24. package/dist/autoresearch/tools.d.ts +1 -16
  25. package/dist/browser/neurolink.min.js +353 -353
  26. package/dist/cli/commands/config.d.ts +3 -123
  27. package/dist/cli/commands/config.js +4 -2
  28. package/dist/cli/commands/evaluate.d.ts +1 -19
  29. package/dist/cli/commands/proxy.d.ts +1 -1
  30. package/dist/cli/commands/proxy.js +3 -0
  31. package/dist/cli/commands/rag.js +3 -0
  32. package/dist/cli/commands/setup-anthropic.d.ts +2 -6
  33. package/dist/cli/commands/setup-anthropic.js +1 -1
  34. package/dist/cli/commands/setup-azure.d.ts +2 -6
  35. package/dist/cli/commands/setup-azure.js +1 -1
  36. package/dist/cli/commands/setup-bedrock.d.ts +2 -6
  37. package/dist/cli/commands/setup-bedrock.js +1 -1
  38. package/dist/cli/commands/setup-gcp.d.ts +2 -6
  39. package/dist/cli/commands/setup-google-ai.d.ts +2 -6
  40. package/dist/cli/commands/setup-google-ai.js +1 -1
  41. package/dist/cli/commands/setup-huggingface.d.ts +1 -5
  42. package/dist/cli/commands/setup-mistral.d.ts +1 -5
  43. package/dist/cli/commands/setup-openai.d.ts +2 -6
  44. package/dist/cli/commands/setup-openai.js +1 -1
  45. package/dist/cli/commands/setup.d.ts +1 -8
  46. package/dist/cli/commands/task.js +1 -0
  47. package/dist/cli/commands/voiceServer.d.ts +1 -4
  48. package/dist/cli/loop/session.js +31 -10
  49. package/dist/cli/utils/interactiveSetup.d.ts +2 -15
  50. package/dist/cli/utils/videoFileUtils.d.ts +1 -15
  51. package/dist/client/aiSdkAdapter.d.ts +1 -1
  52. package/dist/client/aiSdkAdapter.js +1 -0
  53. package/dist/client/httpClient.d.ts +2 -2
  54. package/dist/client/httpClient.js +13 -0
  55. package/dist/client/sseClient.d.ts +2 -2
  56. package/dist/client/sseClient.js +29 -0
  57. package/dist/client/streamingClient.d.ts +2 -0
  58. package/dist/client/streamingClient.js +19 -0
  59. package/dist/client/wsClient.d.ts +7 -2
  60. package/dist/client/wsClient.js +90 -10
  61. package/dist/context/budgetChecker.js +3 -1
  62. package/dist/context/contextCompactor.js +163 -143
  63. package/dist/context/fileSummarizationService.d.ts +1 -9
  64. package/dist/context/summarizationEngine.js +29 -16
  65. package/dist/core/baseProvider.js +124 -153
  66. package/dist/core/infrastructure/baseRegistry.d.ts +1 -7
  67. package/dist/core/modules/GenerationHandler.d.ts +3 -2
  68. package/dist/core/modules/GenerationHandler.js +9 -1
  69. package/dist/core/modules/StreamHandler.js +9 -0
  70. package/dist/core/modules/ToolsManager.js +18 -2
  71. package/dist/core/toolEvents.d.ts +0 -1
  72. package/dist/evaluation/BatchEvaluator.d.ts +1 -97
  73. package/dist/evaluation/EvaluationAggregator.d.ts +1 -118
  74. package/dist/evaluation/EvaluatorFactory.d.ts +1 -13
  75. package/dist/evaluation/EvaluatorRegistry.d.ts +1 -50
  76. package/dist/evaluation/errors/EvaluationError.d.ts +2 -27
  77. package/dist/evaluation/hooks/langfuseAdapter.d.ts +1 -39
  78. package/dist/evaluation/hooks/observabilityHooks.d.ts +3 -55
  79. package/dist/evaluation/hooks/observabilityHooks.js +3 -0
  80. package/dist/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
  81. package/dist/evaluation/pipeline/strategies/batchStrategy.js +7 -7
  82. package/dist/evaluation/ragasEvaluator.js +54 -37
  83. package/dist/evaluation/reporting/metricsCollector.d.ts +1 -60
  84. package/dist/evaluation/reporting/reportGenerator.d.ts +1 -17
  85. package/dist/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
  86. package/dist/evaluation/scorers/rule/formatScorer.d.ts +1 -42
  87. package/dist/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
  88. package/dist/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
  89. package/dist/factories/providerFactory.d.ts +1 -16
  90. package/dist/factories/providerFactory.js +2 -0
  91. package/dist/image-gen/ImageGenService.d.ts +3 -0
  92. package/dist/image-gen/ImageGenService.js +3 -0
  93. package/dist/lib/action/actionInputs.d.ts +1 -1
  94. package/dist/lib/adapters/video/directorPipeline.js +6 -0
  95. package/dist/lib/adapters/video/vertexVideoHandler.js +6 -0
  96. package/dist/lib/agent/directTools.d.ts +3 -23
  97. package/dist/lib/auth/AuthProviderFactory.d.ts +1 -3
  98. package/dist/lib/auth/anthropicOAuth.d.ts +4 -7
  99. package/dist/lib/auth/anthropicOAuth.js +23 -0
  100. package/dist/lib/auth/errors.d.ts +1 -1
  101. package/dist/lib/auth/index.d.ts +11 -0
  102. package/dist/lib/auth/index.js +14 -0
  103. package/dist/lib/auth/middleware/AuthMiddleware.d.ts +5 -60
  104. package/dist/lib/auth/middleware/AuthMiddleware.js +3 -0
  105. package/dist/lib/auth/middleware/rateLimitByUser.d.ts +4 -93
  106. package/dist/lib/auth/middleware/rateLimitByUser.js +4 -0
  107. package/dist/lib/auth/providers/BaseAuthProvider.d.ts +1 -1
  108. package/dist/lib/auth/providers/CognitoProvider.js +3 -0
  109. package/dist/lib/auth/providers/KeycloakProvider.js +3 -0
  110. package/dist/lib/auth/providers/auth0.d.ts +1 -1
  111. package/dist/lib/auth/sessionManager.d.ts +2 -0
  112. package/dist/lib/auth/sessionManager.js +53 -11
  113. package/dist/lib/auth/tokenStore.d.ts +2 -1
  114. package/dist/lib/auth/tokenStore.js +45 -4
  115. package/dist/lib/autoresearch/tools.d.ts +1 -16
  116. package/dist/lib/client/aiSdkAdapter.d.ts +1 -1
  117. package/dist/lib/client/aiSdkAdapter.js +1 -0
  118. package/dist/lib/client/httpClient.d.ts +2 -2
  119. package/dist/lib/client/httpClient.js +13 -0
  120. package/dist/lib/client/sseClient.d.ts +2 -2
  121. package/dist/lib/client/sseClient.js +29 -0
  122. package/dist/lib/client/streamingClient.d.ts +2 -0
  123. package/dist/lib/client/streamingClient.js +19 -0
  124. package/dist/lib/client/wsClient.d.ts +7 -2
  125. package/dist/lib/client/wsClient.js +90 -10
  126. package/dist/lib/context/budgetChecker.js +3 -1
  127. package/dist/lib/context/contextCompactor.js +163 -143
  128. package/dist/lib/context/fileSummarizationService.d.ts +1 -9
  129. package/dist/lib/context/summarizationEngine.js +29 -16
  130. package/dist/lib/core/baseProvider.js +124 -153
  131. package/dist/lib/core/infrastructure/baseRegistry.d.ts +1 -7
  132. package/dist/lib/core/modules/GenerationHandler.d.ts +3 -2
  133. package/dist/lib/core/modules/GenerationHandler.js +9 -1
  134. package/dist/lib/core/modules/StreamHandler.js +9 -0
  135. package/dist/lib/core/modules/ToolsManager.js +18 -2
  136. package/dist/lib/core/toolEvents.d.ts +0 -1
  137. package/dist/lib/evaluation/BatchEvaluator.d.ts +1 -97
  138. package/dist/lib/evaluation/EvaluationAggregator.d.ts +1 -118
  139. package/dist/lib/evaluation/EvaluatorFactory.d.ts +1 -13
  140. package/dist/lib/evaluation/EvaluatorRegistry.d.ts +1 -50
  141. package/dist/lib/evaluation/errors/EvaluationError.d.ts +2 -27
  142. package/dist/lib/evaluation/hooks/langfuseAdapter.d.ts +1 -39
  143. package/dist/lib/evaluation/hooks/observabilityHooks.d.ts +3 -55
  144. package/dist/lib/evaluation/hooks/observabilityHooks.js +3 -0
  145. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
  146. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.js +7 -7
  147. package/dist/lib/evaluation/ragasEvaluator.js +54 -37
  148. package/dist/lib/evaluation/reporting/metricsCollector.d.ts +1 -60
  149. package/dist/lib/evaluation/reporting/reportGenerator.d.ts +1 -17
  150. package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
  151. package/dist/lib/evaluation/scorers/rule/formatScorer.d.ts +1 -42
  152. package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
  153. package/dist/lib/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
  154. package/dist/lib/factories/providerFactory.d.ts +1 -16
  155. package/dist/lib/factories/providerFactory.js +2 -0
  156. package/dist/lib/image-gen/ImageGenService.d.ts +3 -0
  157. package/dist/lib/image-gen/ImageGenService.js +3 -0
  158. package/dist/lib/mcp/batching/requestBatcher.js +99 -73
  159. package/dist/lib/mcp/httpRateLimiter.js +3 -1
  160. package/dist/lib/mcp/httpRetryHandler.js +3 -1
  161. package/dist/lib/mcp/mcpClientFactory.js +3 -1
  162. package/dist/lib/mcp/multiServerManager.d.ts +1 -14
  163. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
  164. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
  165. package/dist/lib/mcp/toolDiscoveryService.js +70 -57
  166. package/dist/lib/mcp/toolRegistry.js +11 -1
  167. package/dist/lib/memory/hippocampusInitializer.d.ts +1 -2
  168. package/dist/lib/memory/hippocampusInitializer.js +1 -1
  169. package/dist/lib/memory/memoryRetrievalTools.js +182 -141
  170. package/dist/lib/models/anthropicModels.d.ts +0 -1
  171. package/dist/lib/models/anthropicModels.js +1 -0
  172. package/dist/lib/neurolink.js +237 -41
  173. package/dist/lib/observability/exporterRegistry.d.ts +3 -22
  174. package/dist/lib/observability/exporters/sentryExporter.js +1 -0
  175. package/dist/lib/observability/metricsAggregator.d.ts +1 -31
  176. package/dist/lib/observability/retryPolicy.d.ts +0 -1
  177. package/dist/lib/observability/sampling/samplers.d.ts +0 -1
  178. package/dist/lib/observability/spanProcessor.d.ts +0 -1
  179. package/dist/lib/observability/tokenTracker.d.ts +7 -16
  180. package/dist/lib/observability/tokenTracker.js +6 -4
  181. package/dist/lib/observability/utils/spanSerializer.d.ts +5 -1
  182. package/dist/lib/observability/utils/spanSerializer.js +24 -4
  183. package/dist/lib/processors/base/BaseFileProcessor.js +66 -53
  184. package/dist/lib/processors/document/ExcelProcessor.d.ts +1 -1
  185. package/dist/lib/processors/errors/errorHelpers.d.ts +1 -31
  186. package/dist/lib/processors/errors/errorSerializer.d.ts +1 -45
  187. package/dist/lib/processors/registry/ProcessorRegistry.js +17 -6
  188. package/dist/lib/providers/amazonBedrock.js +189 -15
  189. package/dist/lib/providers/amazonSagemaker.js +25 -11
  190. package/dist/lib/providers/anthropic.js +13 -0
  191. package/dist/lib/providers/azureOpenai.js +2 -0
  192. package/dist/lib/providers/googleAiStudio.js +82 -0
  193. package/dist/lib/providers/googleNativeGemini3.d.ts +1 -2
  194. package/dist/lib/providers/googleVertex.js +52 -0
  195. package/dist/lib/providers/huggingFace.js +2 -0
  196. package/dist/lib/providers/litellm.js +2 -0
  197. package/dist/lib/providers/mistral.js +2 -0
  198. package/dist/lib/providers/ollama.js +84 -5
  199. package/dist/lib/providers/openAI.d.ts +2 -0
  200. package/dist/lib/providers/openAI.js +17 -6
  201. package/dist/lib/providers/openRouter.js +2 -0
  202. package/dist/lib/providers/openaiCompatible.js +2 -0
  203. package/dist/lib/providers/sagemaker/detection.d.ts +1 -33
  204. package/dist/lib/providers/sagemaker/diagnostics.d.ts +1 -25
  205. package/dist/lib/providers/sagemaker/language-model.d.ts +1 -1
  206. package/dist/lib/proxy/proxyConfig.js +4 -0
  207. package/dist/lib/proxy/proxyEnv.d.ts +1 -17
  208. package/dist/lib/proxy/proxyHealth.d.ts +0 -1
  209. package/dist/lib/proxy/proxyTracer.d.ts +1 -36
  210. package/dist/lib/proxy/proxyTracer.js +9 -0
  211. package/dist/lib/proxy/quietDetector.d.ts +1 -7
  212. package/dist/lib/proxy/rawStreamCapture.d.ts +1 -10
  213. package/dist/lib/proxy/requestLogger.d.ts +1 -21
  214. package/dist/lib/proxy/routingPolicy.d.ts +1 -2
  215. package/dist/lib/proxy/sseInterceptor.d.ts +1 -66
  216. package/dist/lib/proxy/sseInterceptor.js +6 -0
  217. package/dist/lib/proxy/updateChecker.d.ts +1 -6
  218. package/dist/lib/proxy/updateState.d.ts +1 -12
  219. package/dist/lib/rag/chunkers/BaseChunker.js +36 -22
  220. package/dist/lib/rag/chunking/jsonChunker.d.ts +1 -1
  221. package/dist/lib/rag/errors/RAGError.d.ts +1 -2
  222. package/dist/lib/rag/ragIntegration.js +45 -32
  223. package/dist/lib/rag/reranker/reranker.js +151 -122
  224. package/dist/lib/rag/retrieval/vectorQueryTool.js +79 -65
  225. package/dist/lib/sdk/toolRegistration.d.ts +10 -44
  226. package/dist/lib/sdk/toolRegistration.js +1 -1
  227. package/dist/lib/server/middleware/abortSignal.d.ts +1 -11
  228. package/dist/lib/server/middleware/auth.d.ts +1 -21
  229. package/dist/lib/server/middleware/auth.js +12 -0
  230. package/dist/lib/server/middleware/common.js +48 -32
  231. package/dist/lib/server/middleware/deprecation.d.ts +1 -20
  232. package/dist/lib/server/middleware/rateLimit.d.ts +1 -75
  233. package/dist/lib/server/middleware/validation.d.ts +3 -81
  234. package/dist/lib/server/middleware/validation.js +3 -0
  235. package/dist/lib/server/openapi/generator.d.ts +1 -47
  236. package/dist/lib/server/routes/agentRoutes.js +112 -57
  237. package/dist/lib/server/routes/claudeProxyRoutes.d.ts +1 -6
  238. package/dist/lib/server/routes/claudeProxyRoutes.js +127 -13
  239. package/dist/lib/server/routes/healthRoutes.js +58 -12
  240. package/dist/lib/server/routes/index.d.ts +1 -26
  241. package/dist/lib/server/routes/mcpRoutes.js +40 -7
  242. package/dist/lib/server/routes/memoryRoutes.js +22 -7
  243. package/dist/lib/server/routes/openApiRoutes.js +30 -6
  244. package/dist/lib/server/routes/toolRoutes.js +140 -68
  245. package/dist/lib/server/streaming/dataStream.d.ts +1 -35
  246. package/dist/lib/server/streaming/dataStream.js +15 -0
  247. package/dist/lib/services/server/ai/observability/instrumentation.js +114 -14
  248. package/dist/lib/session/globalSessionState.d.ts +1 -10
  249. package/dist/lib/tasks/tools/taskTools.d.ts +2 -2
  250. package/dist/lib/telemetry/traceContext.d.ts +9 -0
  251. package/dist/lib/telemetry/traceContext.js +19 -0
  252. package/dist/lib/telemetry/tracers.d.ts +2 -0
  253. package/dist/lib/telemetry/tracers.js +2 -0
  254. package/dist/lib/types/action.d.ts +2 -0
  255. package/dist/lib/types/artifact.d.ts +7 -0
  256. package/dist/lib/types/auth.d.ts +125 -18
  257. package/dist/lib/types/autoresearch.d.ts +12 -0
  258. package/dist/lib/types/cli.d.ts +415 -0
  259. package/dist/lib/types/client.d.ts +34 -0
  260. package/dist/lib/types/common.d.ts +12 -41
  261. package/dist/lib/types/context.d.ts +5 -0
  262. package/dist/lib/types/evaluation.d.ts +332 -1
  263. package/dist/lib/types/file.d.ts +4 -0
  264. package/dist/lib/types/mcp.d.ts +102 -2
  265. package/dist/lib/types/middleware.d.ts +116 -0
  266. package/dist/lib/types/multimodal.d.ts +65 -0
  267. package/dist/lib/types/observability.d.ts +81 -0
  268. package/dist/lib/types/processor.d.ts +47 -0
  269. package/dist/lib/types/providers.d.ts +120 -16
  270. package/dist/lib/types/proxy.d.ts +321 -1
  271. package/dist/lib/types/rag.d.ts +22 -0
  272. package/dist/lib/types/scorer.d.ts +141 -0
  273. package/dist/lib/types/server.d.ts +99 -0
  274. package/dist/lib/types/span.d.ts +2 -1
  275. package/dist/lib/types/span.js +1 -0
  276. package/dist/lib/types/tools.d.ts +44 -0
  277. package/dist/lib/types/tts.d.ts +6 -0
  278. package/dist/lib/types/utilities.d.ts +22 -0
  279. package/dist/lib/types/workflow.d.ts +18 -0
  280. package/dist/lib/utils/async/retry.d.ts +2 -8
  281. package/dist/lib/utils/async/retry.js +9 -9
  282. package/dist/lib/utils/imageCompressor.d.ts +1 -21
  283. package/dist/lib/utils/imageCompressor.js +5 -1
  284. package/dist/lib/utils/messageBuilder.d.ts +1 -1
  285. package/dist/lib/utils/redis.d.ts +1 -4
  286. package/dist/lib/utils/sanitizers/filename.d.ts +0 -1
  287. package/dist/lib/utils/toolEndEmitter.d.ts +25 -0
  288. package/dist/lib/utils/toolEndEmitter.js +65 -0
  289. package/dist/lib/workflow/config.d.ts +7 -32
  290. package/dist/lib/workflow/core/ensembleExecutor.js +28 -0
  291. package/dist/lib/workflow/core/judgeScorer.js +23 -0
  292. package/dist/lib/workflow/core/responseConditioner.js +17 -0
  293. package/dist/lib/workflow/core/workflowRunner.d.ts +1 -19
  294. package/dist/lib/workflow/core/workflowRunner.js +202 -147
  295. package/dist/mcp/batching/requestBatcher.js +99 -73
  296. package/dist/mcp/httpRateLimiter.js +3 -1
  297. package/dist/mcp/httpRetryHandler.js +3 -1
  298. package/dist/mcp/mcpClientFactory.js +3 -1
  299. package/dist/mcp/multiServerManager.d.ts +1 -14
  300. package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
  301. package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
  302. package/dist/mcp/toolDiscoveryService.js +70 -57
  303. package/dist/mcp/toolRegistry.js +11 -1
  304. package/dist/memory/hippocampusInitializer.d.ts +1 -2
  305. package/dist/memory/hippocampusInitializer.js +1 -1
  306. package/dist/memory/memoryRetrievalTools.js +182 -141
  307. package/dist/models/anthropicModels.d.ts +0 -1
  308. package/dist/models/anthropicModels.js +1 -0
  309. package/dist/neurolink.js +237 -41
  310. package/dist/observability/exporterRegistry.d.ts +3 -22
  311. package/dist/observability/exporters/sentryExporter.js +1 -0
  312. package/dist/observability/metricsAggregator.d.ts +1 -31
  313. package/dist/observability/retryPolicy.d.ts +0 -1
  314. package/dist/observability/sampling/samplers.d.ts +0 -1
  315. package/dist/observability/spanProcessor.d.ts +0 -1
  316. package/dist/observability/tokenTracker.d.ts +7 -16
  317. package/dist/observability/tokenTracker.js +6 -4
  318. package/dist/observability/utils/spanSerializer.d.ts +5 -1
  319. package/dist/observability/utils/spanSerializer.js +24 -4
  320. package/dist/processors/base/BaseFileProcessor.js +66 -53
  321. package/dist/processors/document/ExcelProcessor.d.ts +1 -1
  322. package/dist/processors/errors/errorHelpers.d.ts +1 -31
  323. package/dist/processors/errors/errorSerializer.d.ts +1 -45
  324. package/dist/processors/registry/ProcessorRegistry.js +17 -6
  325. package/dist/providers/amazonBedrock.js +189 -15
  326. package/dist/providers/amazonSagemaker.js +25 -11
  327. package/dist/providers/anthropic.js +13 -0
  328. package/dist/providers/azureOpenai.js +2 -0
  329. package/dist/providers/googleAiStudio.js +82 -0
  330. package/dist/providers/googleNativeGemini3.d.ts +1 -2
  331. package/dist/providers/googleVertex.js +52 -0
  332. package/dist/providers/huggingFace.js +2 -0
  333. package/dist/providers/litellm.js +2 -0
  334. package/dist/providers/mistral.js +2 -0
  335. package/dist/providers/ollama.js +84 -5
  336. package/dist/providers/openAI.d.ts +2 -0
  337. package/dist/providers/openAI.js +17 -6
  338. package/dist/providers/openRouter.js +2 -0
  339. package/dist/providers/openaiCompatible.js +2 -0
  340. package/dist/providers/sagemaker/detection.d.ts +1 -33
  341. package/dist/providers/sagemaker/diagnostics.d.ts +1 -25
  342. package/dist/providers/sagemaker/language-model.d.ts +1 -1
  343. package/dist/proxy/proxyConfig.js +4 -0
  344. package/dist/proxy/proxyEnv.d.ts +1 -17
  345. package/dist/proxy/proxyHealth.d.ts +0 -1
  346. package/dist/proxy/proxyTracer.d.ts +1 -36
  347. package/dist/proxy/proxyTracer.js +9 -0
  348. package/dist/proxy/quietDetector.d.ts +1 -7
  349. package/dist/proxy/rawStreamCapture.d.ts +1 -10
  350. package/dist/proxy/requestLogger.d.ts +1 -21
  351. package/dist/proxy/routingPolicy.d.ts +1 -2
  352. package/dist/proxy/sseInterceptor.d.ts +1 -66
  353. package/dist/proxy/sseInterceptor.js +6 -0
  354. package/dist/proxy/updateChecker.d.ts +1 -6
  355. package/dist/proxy/updateState.d.ts +1 -12
  356. package/dist/rag/chunkers/BaseChunker.js +36 -22
  357. package/dist/rag/chunking/jsonChunker.d.ts +1 -1
  358. package/dist/rag/errors/RAGError.d.ts +1 -2
  359. package/dist/rag/ragIntegration.js +45 -32
  360. package/dist/rag/reranker/reranker.js +151 -122
  361. package/dist/rag/retrieval/vectorQueryTool.js +79 -65
  362. package/dist/sdk/toolRegistration.d.ts +10 -44
  363. package/dist/sdk/toolRegistration.js +1 -1
  364. package/dist/server/middleware/abortSignal.d.ts +1 -11
  365. package/dist/server/middleware/auth.d.ts +1 -21
  366. package/dist/server/middleware/auth.js +12 -0
  367. package/dist/server/middleware/common.js +48 -32
  368. package/dist/server/middleware/deprecation.d.ts +1 -20
  369. package/dist/server/middleware/rateLimit.d.ts +1 -75
  370. package/dist/server/middleware/validation.d.ts +3 -81
  371. package/dist/server/middleware/validation.js +3 -0
  372. package/dist/server/openapi/generator.d.ts +1 -47
  373. package/dist/server/routes/agentRoutes.js +112 -57
  374. package/dist/server/routes/claudeProxyRoutes.d.ts +1 -6
  375. package/dist/server/routes/claudeProxyRoutes.js +127 -13
  376. package/dist/server/routes/healthRoutes.js +58 -12
  377. package/dist/server/routes/index.d.ts +1 -26
  378. package/dist/server/routes/mcpRoutes.js +40 -7
  379. package/dist/server/routes/memoryRoutes.js +22 -7
  380. package/dist/server/routes/openApiRoutes.js +30 -6
  381. package/dist/server/routes/toolRoutes.js +140 -68
  382. package/dist/server/streaming/dataStream.d.ts +1 -35
  383. package/dist/server/streaming/dataStream.js +15 -0
  384. package/dist/services/server/ai/observability/instrumentation.js +114 -14
  385. package/dist/session/globalSessionState.d.ts +1 -10
  386. package/dist/tasks/tools/taskTools.d.ts +2 -2
  387. package/dist/telemetry/traceContext.d.ts +9 -0
  388. package/dist/telemetry/traceContext.js +18 -0
  389. package/dist/telemetry/tracers.d.ts +2 -0
  390. package/dist/telemetry/tracers.js +2 -0
  391. package/dist/types/action.d.ts +2 -0
  392. package/dist/types/artifact.d.ts +7 -0
  393. package/dist/types/auth.d.ts +125 -18
  394. package/dist/types/autoresearch.d.ts +12 -0
  395. package/dist/types/cli.d.ts +415 -0
  396. package/dist/types/client.d.ts +34 -0
  397. package/dist/types/common.d.ts +12 -41
  398. package/dist/types/context.d.ts +5 -0
  399. package/dist/types/evaluation.d.ts +332 -1
  400. package/dist/types/file.d.ts +4 -0
  401. package/dist/types/mcp.d.ts +102 -2
  402. package/dist/types/middleware.d.ts +116 -0
  403. package/dist/types/multimodal.d.ts +65 -0
  404. package/dist/types/observability.d.ts +81 -0
  405. package/dist/types/processor.d.ts +47 -0
  406. package/dist/types/providers.d.ts +120 -16
  407. package/dist/types/proxy.d.ts +321 -1
  408. package/dist/types/rag.d.ts +22 -0
  409. package/dist/types/scorer.d.ts +141 -0
  410. package/dist/types/server.d.ts +99 -0
  411. package/dist/types/span.d.ts +2 -1
  412. package/dist/types/span.js +1 -0
  413. package/dist/types/tools.d.ts +44 -0
  414. package/dist/types/tts.d.ts +6 -0
  415. package/dist/types/utilities.d.ts +22 -0
  416. package/dist/types/workflow.d.ts +18 -0
  417. package/dist/utils/async/retry.d.ts +2 -8
  418. package/dist/utils/async/retry.js +9 -9
  419. package/dist/utils/imageCompressor.d.ts +1 -21
  420. package/dist/utils/imageCompressor.js +5 -1
  421. package/dist/utils/messageBuilder.d.ts +1 -1
  422. package/dist/utils/redis.d.ts +1 -4
  423. package/dist/utils/sanitizers/filename.d.ts +0 -1
  424. package/dist/utils/toolEndEmitter.d.ts +25 -0
  425. package/dist/utils/toolEndEmitter.js +64 -0
  426. package/dist/workflow/config.d.ts +4 -29
  427. package/dist/workflow/core/ensembleExecutor.js +28 -0
  428. package/dist/workflow/core/judgeScorer.js +23 -0
  429. package/dist/workflow/core/responseConditioner.js +17 -0
  430. package/dist/workflow/core/workflowRunner.d.ts +1 -19
  431. package/dist/workflow/core/workflowRunner.js +202 -147
  432. package/package.json +2 -1
@@ -421,3 +421,144 @@ export type ReportConfig = {
421
421
  /** Include timing information */
422
422
  includeTiming?: boolean;
423
423
  };
424
+ /** Similarity metric types. */
425
+ export type SimilarityMetric = "jaccard" | "cosine" | "levenshtein" | "dice" | "overlap";
426
+ /** Configuration specific to content similarity scoring. */
427
+ export type ContentSimilarityConfig = RuleScorerConfig & {
428
+ metric?: SimilarityMetric;
429
+ metrics?: SimilarityMetric[];
430
+ metricCombination?: "average" | "min" | "max" | "weighted";
431
+ metricWeights?: Record<SimilarityMetric, number>;
432
+ normalizeText?: boolean;
433
+ tokenLevel?: "word" | "character" | "ngram";
434
+ ngramSize?: number;
435
+ compareWith?: "groundTruth" | "context" | "custom";
436
+ referenceText?: string;
437
+ };
438
+ /** Similarity calculation detail row. */
439
+ export type SimilarityDetails = {
440
+ metric: SimilarityMetric;
441
+ score: number;
442
+ responseTokens: number;
443
+ referenceTokens: number;
444
+ commonTokens?: number;
445
+ };
446
+ /** Expected format types evaluated by the format scorer. */
447
+ export type FormatType = "json" | "markdown" | "code" | "list" | "numbered-list" | "bullet-list" | "table" | "yaml" | "xml" | "plain" | "html" | "custom";
448
+ /** Code language types for the code-format validator. */
449
+ export type CodeLanguage = "javascript" | "typescript" | "python" | "java" | "c" | "cpp" | "csharp" | "go" | "rust" | "sql" | "bash" | "any";
450
+ /** Configuration specific to format scoring. */
451
+ export type FormatScorerConfig = RuleScorerConfig & {
452
+ expectedFormat?: FormatType;
453
+ allowedFormats?: FormatType[];
454
+ codeLanguage?: CodeLanguage;
455
+ jsonSchema?: object;
456
+ markdownRequirements?: {
457
+ hasHeadings?: boolean;
458
+ hasCodeBlocks?: boolean;
459
+ hasLinks?: boolean;
460
+ hasLists?: boolean;
461
+ minHeadingLevel?: number;
462
+ maxHeadingLevel?: number;
463
+ };
464
+ listRequirements?: {
465
+ minItems?: number;
466
+ maxItems?: number;
467
+ itemPattern?: string;
468
+ };
469
+ customPattern?: string;
470
+ strictFormat?: boolean;
471
+ };
472
+ /** Format validation result. */
473
+ export type FormatValidationResult = {
474
+ isValid: boolean;
475
+ detectedFormat: FormatType | null;
476
+ issues: string[];
477
+ structureAnalysis?: object;
478
+ };
479
+ /** Configuration specific to keyword coverage scoring. */
480
+ export type KeywordCoverageConfig = RuleScorerConfig & {
481
+ keywords?: string[];
482
+ minCoverage?: number;
483
+ caseInsensitive?: boolean;
484
+ wordBoundary?: boolean;
485
+ synonyms?: Record<string, string[]>;
486
+ keywordWeights?: Record<string, number>;
487
+ };
488
+ /** Keyword coverage result details. */
489
+ export type KeywordCoverageDetails = {
490
+ totalKeywords: number;
491
+ foundKeywords: string[];
492
+ missingKeywords: string[];
493
+ coverageRatio: number;
494
+ weightedCoverage: number;
495
+ };
496
+ /** Length measurement unit. */
497
+ export type LengthUnit = "words" | "characters" | "sentences" | "paragraphs" | "tokens";
498
+ /** Length constraint type. */
499
+ export type LengthConstraintType = "exact" | "range" | "minimum" | "maximum" | "ratio";
500
+ /** Configuration specific to length scoring. */
501
+ export type LengthScorerConfig = RuleScorerConfig & {
502
+ unit?: LengthUnit;
503
+ constraintType?: LengthConstraintType;
504
+ minLength?: number;
505
+ maxLength?: number;
506
+ exactLength?: number;
507
+ tolerance?: number;
508
+ ratioTarget?: number;
509
+ ratioReference?: "query" | "context";
510
+ scoringMode?: "binary" | "proportional";
511
+ };
512
+ /** Length measurement result. */
513
+ export type LengthMeasurement = {
514
+ words: number;
515
+ characters: number;
516
+ sentences: number;
517
+ paragraphs: number;
518
+ estimatedTokens: number;
519
+ };
520
+ /** Row describing a built-in scorer in the scorer registry seed list. */
521
+ export type BuiltInScorerDefinition = {
522
+ metadata: ScorerMetadata;
523
+ factory: ScorerFactory;
524
+ aliases?: string[];
525
+ };
526
+ /** Bias instance reported by the bias-detection scorer. */
527
+ export type BiasInstance = {
528
+ type?: string;
529
+ text?: string;
530
+ explanation?: string;
531
+ severity?: string;
532
+ };
533
+ /** Context score row reported by the context-relevancy scorer. */
534
+ export type ContextScoreItem = {
535
+ index?: number;
536
+ score?: number;
537
+ reasoning?: string;
538
+ keyInfo?: string[];
539
+ };
540
+ /** Claim row reported by the faithfulness scorer. */
541
+ export type ClaimItem = {
542
+ claim?: string;
543
+ supported?: boolean;
544
+ evidence?: string;
545
+ };
546
+ /** Hallucination row reported by the hallucination scorer. */
547
+ export type HallucinationItem = {
548
+ text?: string;
549
+ reason?: string;
550
+ severity?: string;
551
+ };
552
+ /** Tone-shift location reported by the tone-consistency scorer. */
553
+ export type ToneShift = {
554
+ location?: string;
555
+ from?: string;
556
+ to?: string;
557
+ severity?: string;
558
+ };
559
+ /** Flagged content row reported by the toxicity scorer. */
560
+ export type FlaggedItem = {
561
+ text?: string;
562
+ category?: string;
563
+ severity?: string;
564
+ };
@@ -1010,3 +1010,102 @@ export type CacheEntry = {
1010
1010
  ttlMs: number;
1011
1011
  headers?: Record<string, string>;
1012
1012
  };
1013
+ /** Voice-server conversation turn — superset role set. */
1014
+ export type Message = {
1015
+ role: "system" | "user" | "assistant";
1016
+ content: string;
1017
+ };
1018
+ /** Subset of Message that excludes the system role (assistant+user only). */
1019
+ export type ConversationMessage = {
1020
+ role: "user" | "assistant";
1021
+ content: string;
1022
+ };
1023
+ /** Configuration passed to the OpenAPI spec generator. */
1024
+ export type OpenAPIGeneratorConfig = {
1025
+ info?: {
1026
+ title?: string;
1027
+ version?: string;
1028
+ description?: string;
1029
+ };
1030
+ servers?: Array<{
1031
+ url: string;
1032
+ description?: string;
1033
+ }>;
1034
+ includeSecurity?: boolean;
1035
+ basePath?: string;
1036
+ additionalTags?: Array<{
1037
+ name: string;
1038
+ description: string;
1039
+ }>;
1040
+ customSchemas?: Record<string, JsonObject>;
1041
+ routes?: RouteDefinition[];
1042
+ };
1043
+ /** Structured OpenAPI 3.1 specification object. */
1044
+ export type OpenAPISpec = {
1045
+ openapi: "3.1.0";
1046
+ info: JsonObject;
1047
+ servers: JsonObject[];
1048
+ tags: JsonObject[];
1049
+ paths: Record<string, JsonObject>;
1050
+ components: {
1051
+ schemas: Record<string, JsonObject>;
1052
+ securitySchemes?: Record<string, JsonObject>;
1053
+ parameters?: Record<string, JsonObject>;
1054
+ };
1055
+ security?: JsonObject[];
1056
+ };
1057
+ /** Options for createAllRoutes / createRoutes. */
1058
+ export type CreateRoutesOptions = {
1059
+ enableSwagger?: boolean;
1060
+ getRoutes?: () => RouteDefinition[];
1061
+ claudeProxy?: boolean;
1062
+ };
1063
+ /** Data stream finish event. */
1064
+ export type FinishEvent = DataStreamEvent & {
1065
+ type: "finish";
1066
+ data: {
1067
+ reason?: string;
1068
+ usage?: {
1069
+ input: number;
1070
+ output: number;
1071
+ total: number;
1072
+ };
1073
+ };
1074
+ };
1075
+ /** Configuration for DataStreamWriter. */
1076
+ export type DataStreamWriterConfig = {
1077
+ write: (chunk: string) => void | Promise<void>;
1078
+ close?: () => void | Promise<void>;
1079
+ format?: "sse" | "ndjson";
1080
+ includeTimestamps?: boolean;
1081
+ };
1082
+ /** Configuration for the DataStreamResponse wrapper. */
1083
+ export type DataStreamResponseConfig = {
1084
+ contentType?: "text/event-stream" | "application/x-ndjson";
1085
+ headers?: Record<string, string>;
1086
+ keepAliveInterval?: number;
1087
+ includeTimestamps?: boolean;
1088
+ };
1089
+ /** Options for a single SSE message. */
1090
+ export type SSEEventOptions = {
1091
+ event?: string;
1092
+ data: string;
1093
+ id?: string;
1094
+ retry?: number;
1095
+ };
1096
+ /** Single token emitted by the Soniox STT stream. */
1097
+ export type SonioxToken = {
1098
+ is_final?: boolean;
1099
+ text?: string;
1100
+ };
1101
+ /** Envelope received from the Soniox STT WebSocket. */
1102
+ export type SonioxMessage = {
1103
+ error?: string;
1104
+ status?: string;
1105
+ type?: string;
1106
+ tokens?: SonioxToken[];
1107
+ };
1108
+ /** Control message received from the voice client over WebSocket. */
1109
+ export type ClientControlMessage = {
1110
+ type?: string;
1111
+ };
@@ -48,7 +48,8 @@ export declare enum SpanType {
48
48
  export declare enum SpanStatus {
49
49
  UNSET = 0,
50
50
  OK = 1,
51
- ERROR = 2
51
+ ERROR = 2,
52
+ WARNING = 3
52
53
  }
53
54
  /**
54
55
  * OpenTelemetry GenAI semantic conventions
@@ -51,6 +51,7 @@ export var SpanStatus;
51
51
  SpanStatus[SpanStatus["UNSET"] = 0] = "UNSET";
52
52
  SpanStatus[SpanStatus["OK"] = 1] = "OK";
53
53
  SpanStatus[SpanStatus["ERROR"] = 2] = "ERROR";
54
+ SpanStatus[SpanStatus["WARNING"] = 3] = "WARNING";
54
55
  })(SpanStatus || (SpanStatus = {}));
55
56
  /**
56
57
  * OpenTelemetry GenAI semantic conventions
@@ -3,6 +3,7 @@
3
3
  * argument patterns, execution metadata, context, and result types.
4
4
  */
5
5
  import { z } from "zod";
6
+ import type { Tool } from "ai";
6
7
  import type { ErrorInfo, JsonObject, JsonValue, Result, UnknownRecord } from "./common.js";
7
8
  import type { StandardRecord, StringArray, ZodUnknownSchema } from "./aliases.js";
8
9
  import type { ValidationError } from "../utils/parameterValidation.js";
@@ -357,6 +358,49 @@ export type SimpleTool<TArgs = ToolArgs, TResult = JsonValue> = {
357
358
  metadata?: ToolMetadata;
358
359
  execute: (params: TArgs, context?: ToolContext) => Promise<TResult>;
359
360
  };
361
+ /**
362
+ * Simple tool type accepted by the SDK registerTool() helper. Uses
363
+ * SDKToolContext (richer tool context with request metadata).
364
+ */
365
+ export type SdkSimpleTool<TArgs = ToolArgs, TResult = JsonValue> = Omit<SimpleTool<TArgs, TResult>, "execute"> & {
366
+ description: string;
367
+ parameters?: ZodUnknownSchema;
368
+ execute: (params: TArgs, context?: SDKToolContext) => Promise<TResult>;
369
+ metadata?: {
370
+ category?: string;
371
+ version?: string;
372
+ author?: string;
373
+ tags?: string[];
374
+ documentation?: string;
375
+ [key: string]: JsonValue | undefined;
376
+ };
377
+ };
378
+ /** Subset of directAgentTools exposing only the "basic" category. */
379
+ export type BasicToolsMap = {
380
+ getCurrentTime: Tool;
381
+ calculateMath: Tool;
382
+ };
383
+ /** Subset of directAgentTools exposing only the "filesystem" category. */
384
+ export type FilesystemToolsMap = {
385
+ readFile: Tool;
386
+ listDirectory: Tool;
387
+ writeFile: Tool;
388
+ };
389
+ /** Subset of directAgentTools exposing the "utility" category. */
390
+ export type UtilityToolsMap = {
391
+ getCurrentTime: Tool;
392
+ calculateMath: Tool;
393
+ listDirectory: Tool;
394
+ };
395
+ /** Full directAgentTools map, with the opt-in bashTool appended. */
396
+ export type AllToolsMap = {
397
+ getCurrentTime: Tool;
398
+ calculateMath: Tool;
399
+ readFile: Tool;
400
+ listDirectory: Tool;
401
+ writeFile: Tool;
402
+ executeBashCommand?: Tool;
403
+ };
360
404
  /**
361
405
  * Tool registry entry
362
406
  */
@@ -167,3 +167,9 @@ export type TTSChunk = {
167
167
  /** Sample rate in Hz */
168
168
  sampleRate?: number;
169
169
  };
170
+ /** Message envelope received from the Cartesia TTS WebSocket. */
171
+ export type CartesiaMessage = {
172
+ data?: string;
173
+ done?: boolean;
174
+ error?: string;
175
+ };
@@ -241,3 +241,25 @@ export type ImageCacheStats = {
241
241
  /** Cache hit rate as percentage */
242
242
  hitRate: number;
243
243
  };
244
+ /**
245
+ * Pending request held by TokenBucketRateLimiter's queue.
246
+ * Named RateLimiterPendingRequest to disambiguate from the MCP
247
+ * PendingRequest in mcp.ts (Rule 9).
248
+ */
249
+ export type RateLimiterPendingRequest = {
250
+ resolve: () => void;
251
+ reject: (error: Error) => void;
252
+ timestamp: number;
253
+ timeoutTimer?: ReturnType<typeof setTimeout>;
254
+ };
255
+ /**
256
+ * Shape of a completed tool result as returned by the AI SDK in
257
+ * `onStepFinish`. Both `output` (AI SDK v4) and `result` (older shape)
258
+ * are supported so the helper works across SDK versions.
259
+ */
260
+ export type StepToolResult = {
261
+ toolName: string;
262
+ output?: unknown;
263
+ result?: unknown;
264
+ error?: string;
265
+ };
@@ -4,6 +4,7 @@
4
4
  *
5
5
  * Testing Phase: Focuses on original output + evaluation metrics for AB testing
6
6
  */
7
+ import type { z } from "zod";
7
8
  import type { AnalyticsData } from "./analytics.js";
8
9
  import { AIProviderName } from "../constants/enums.js";
9
10
  import type { JsonValue } from "./common.js";
@@ -578,3 +579,20 @@ export type RunWorkflowOptions = {
578
579
  /** Enable progressive streaming (yield preliminary response) */
579
580
  streaming?: boolean;
580
581
  };
582
+ /**
583
+ * Generic workflow validation result — replaces three near-identical types
584
+ * (WorkflowConfigValidationResult, ModelConfigValidationResult,
585
+ * JudgeConfigValidationResult). Named with `Workflow*` prefix to avoid
586
+ * collision with `tools.ts#ValidationResult` (Rule 9).
587
+ */
588
+ export type WorkflowValidation<T> = {
589
+ success: boolean;
590
+ data?: T;
591
+ error?: z.ZodError;
592
+ };
593
+ /** Progressive workflow response chunk streamed by runWorkflow(). */
594
+ export type WorkflowStreamChunk = {
595
+ type: "preliminary" | "final";
596
+ content: string;
597
+ partialResult?: Partial<WorkflowResult>;
598
+ };
@@ -3,16 +3,11 @@
3
3
  *
4
4
  * Provides retry logic with exponential backoff for resilient async operations.
5
5
  */
6
- import type { AsyncRetryOptions } from "../../types/index.js";
7
- /**
8
- * Local alias: the canonical type was renamed to AsyncRetryOptions to avoid
9
- * collision with other RetryOptions types in the codebase.
10
- */
11
- type RetryOptions = AsyncRetryOptions;
6
+ import type { RetryOptions } from "../../types/index.js";
12
7
  /**
13
8
  * Default retry configuration.
14
9
  */
15
- export declare const DEFAULT_RETRY_OPTIONS: RetryOptions;
10
+ export declare const DEFAULT_RETRY_OPTIONS: Required<Pick<RetryOptions, "maxAttempts" | "initialDelay" | "maxDelay" | "backoffMultiplier">>;
16
11
  /**
17
12
  * Calculate exponential backoff delay with optional jitter.
18
13
  *
@@ -110,4 +105,3 @@ export declare function retry<T>(fn: () => Promise<T>, options?: Partial<RetryOp
110
105
  * ```
111
106
  */
112
107
  export declare function createRetry(defaultOptions: Partial<RetryOptions>): <T>(fn: () => Promise<T>, overrideOptions?: Partial<RetryOptions>) => Promise<T>;
113
- export {};
@@ -8,9 +8,9 @@ import { delay } from "./delay.js";
8
8
  * Default retry configuration.
9
9
  */
10
10
  export const DEFAULT_RETRY_OPTIONS = {
11
- maxRetries: 3,
12
- baseDelayMs: 1000,
13
- maxDelayMs: 30000,
11
+ maxAttempts: 3,
12
+ initialDelay: 1000,
13
+ maxDelay: 30000,
14
14
  backoffMultiplier: 2,
15
15
  };
16
16
  /**
@@ -109,11 +109,11 @@ export async function retry(fn, options = {}) {
109
109
  ...DEFAULT_RETRY_OPTIONS,
110
110
  ...options,
111
111
  };
112
- const { maxRetries, baseDelayMs, maxDelayMs, backoffMultiplier = 2, shouldRetry = () => true, onRetry, } = config;
112
+ const { maxAttempts, initialDelay, maxDelay, backoffMultiplier, retryCondition = () => true, onRetry, } = config;
113
113
  let lastError = new Error("Retry failed");
114
- let currentDelay = baseDelayMs;
114
+ let currentDelay = initialDelay;
115
115
  // Total attempts = initial attempt + retries
116
- const totalAttempts = maxRetries + 1;
116
+ const totalAttempts = maxAttempts + 1;
117
117
  for (let attempt = 1; attempt <= totalAttempts; attempt++) {
118
118
  try {
119
119
  return await fn();
@@ -126,14 +126,14 @@ export async function retry(fn, options = {}) {
126
126
  throw new RetryExhaustedError(`All ${totalAttempts} retry attempts exhausted`, totalAttempts, err);
127
127
  }
128
128
  // Check if we should retry this error
129
- if (!shouldRetry(err, attempt)) {
129
+ if (!retryCondition(err)) {
130
130
  throw err;
131
131
  }
132
132
  // Calculate delay with exponential backoff (capped at maxDelay)
133
- const delayMs = Math.min(currentDelay, maxDelayMs);
133
+ const delayMs = Math.min(currentDelay, maxDelay);
134
134
  // Notify about retry
135
135
  if (onRetry) {
136
- onRetry(err, attempt, delayMs);
136
+ onRetry(attempt, err);
137
137
  }
138
138
  // Wait before next attempt
139
139
  await delay(delayMs);
@@ -1,27 +1,8 @@
1
- import type { ProviderName } from "../types/index.js";
2
- declare const SUPPORTED_FORMATS: readonly ["jpeg", "png", "webp"];
3
- type SupportedFormat = (typeof SUPPORTED_FORMATS)[number];
1
+ import type { CompressionOptions, CompressionResult, ProviderName } from "../types/index.js";
4
2
  /**
5
3
  * Provider-specific image size limits in bytes
6
4
  */
7
5
  export declare const PROVIDER_IMAGE_LIMITS: Record<ProviderName, number>;
8
- type CompressionOptions = {
9
- provider: ProviderName;
10
- quality?: number;
11
- maxDimension?: number;
12
- format?: SupportedFormat;
13
- };
14
- type CompressionResult = {
15
- buffer: Buffer;
16
- originalSize: number;
17
- compressedSize: number;
18
- compressionRatio: number;
19
- metadata: {
20
- width: number;
21
- height: number;
22
- format: string;
23
- };
24
- };
25
6
  /**
26
7
  * Compress an image to meet provider-specific size limits
27
8
  * @param imageBuffer - Input image buffer
@@ -42,4 +23,3 @@ export declare function needsCompression(imageBuffer: Buffer, provider: Provider
42
23
  * @returns Size limit in bytes
43
24
  */
44
25
  export declare function getProviderSizeLimit(provider: ProviderName): number;
45
- export {};
@@ -1,6 +1,10 @@
1
1
  import sharp from "sharp";
2
2
  import { withTimeout } from "./async/index.js";
3
- const SUPPORTED_FORMATS = ["jpeg", "png", "webp"];
3
+ const SUPPORTED_FORMATS = [
4
+ "jpeg",
5
+ "png",
6
+ "webp",
7
+ ];
4
8
  const IMAGE_COMPRESSION_TIMEOUT_MS = 30_000;
5
9
  /**
6
10
  * Provider-specific image size limits in bytes
@@ -4,7 +4,7 @@
4
4
  * Enhanced with multimodal support for images
5
5
  */
6
6
  import type { ModelMessage } from "ai";
7
- import type { MultimodalChatMessage, GenerateOptions, TextGenerationOptions, StreamOptions } from "../types/index.js";
7
+ import type { GenerateOptions, MultimodalChatMessage, StreamOptions, TextGenerationOptions } from "../types/index.js";
8
8
  /**
9
9
  * Type-safe conversion from MultimodalChatMessage[] to ModelMessage[]
10
10
  * Filters out invalid content and ensures strict ModelMessage contract compliance
@@ -2,9 +2,7 @@
2
2
  * Redis Utilities for NeuroLink
3
3
  * Helper functions for Redis storage operations
4
4
  */
5
- import { createClient } from "redis";
6
- import type { RedisConversationObject, RedisStorageConfig } from "../types/index.js";
7
- type RedisClient = ReturnType<typeof createClient>;
5
+ import type { RedisClient, RedisConversationObject, RedisStorageConfig } from "../types/index.js";
8
6
  /**
9
7
  * Get a pooled Redis connection. Multiple callers with the same host:port:db
10
8
  * share a single connection, reducing connection count.
@@ -60,4 +58,3 @@ export declare function scanKeys(client: RedisClient, pattern: string, batchSize
60
58
  * Get normalized Redis configuration with defaults
61
59
  */
62
60
  export declare function getNormalizedConfig(config: RedisStorageConfig): Required<RedisStorageConfig>;
63
- export {};
@@ -10,7 +10,6 @@
10
10
  * @see https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html
11
11
  */
12
12
  import type { SanitizeFileNameOptions, SanitizeDisplayNameOptions } from "../../types/index.js";
13
- export type { SanitizeFileNameOptions, SanitizeDisplayNameOptions };
14
13
  /**
15
14
  * Sanitize a filename for safe filesystem storage.
16
15
  * Removes characters that are invalid on various operating systems.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * toolEndEmitter — shared helper for emitting `tool:end` events from
3
+ * AI-SDK `onStepFinish` callbacks.
4
+ *
5
+ * Pipeline B (metrics aggregator) listens for `tool:end` on the NeuroLink
6
+ * EventEmitter. When tools are executed by the AI SDK internally (via
7
+ * `generateText` / `streamText`) the SDK calls `onStepFinish` with the
8
+ * completed tool results. Without this helper those results are silently
9
+ * stored but never surfaced as `tool:end` events, leaving Pipeline B with
10
+ * zero tool spans for AI-SDK-driven tool calls (gaps G5 and S2).
11
+ *
12
+ * @module utils/toolEndEmitter
13
+ */
14
+ import type { NeuroLinkEvents, StepToolResult, TypedEventEmitter } from "../types/index.js";
15
+ /**
16
+ * Emit a `tool:end` event for every completed tool result in an
17
+ * `onStepFinish` callback.
18
+ *
19
+ * @param emitter - The NeuroLink event emitter (obtained via
20
+ * `neurolink.getEventEmitter()`). When `undefined` the function is a
21
+ * no-op so callers need not guard every call site.
22
+ * @param toolResults - The `toolResults` array from `onStepFinish`. When
23
+ * `undefined` or empty the function is a no-op.
24
+ */
25
+ export declare function emitToolEndFromStepFinish(emitter: TypedEventEmitter<NeuroLinkEvents> | undefined, toolResults: StepToolResult[] | undefined): void;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * toolEndEmitter — shared helper for emitting `tool:end` events from
3
+ * AI-SDK `onStepFinish` callbacks.
4
+ *
5
+ * Pipeline B (metrics aggregator) listens for `tool:end` on the NeuroLink
6
+ * EventEmitter. When tools are executed by the AI SDK internally (via
7
+ * `generateText` / `streamText`) the SDK calls `onStepFinish` with the
8
+ * completed tool results. Without this helper those results are silently
9
+ * stored but never surfaced as `tool:end` events, leaving Pipeline B with
10
+ * zero tool spans for AI-SDK-driven tool calls (gaps G5 and S2).
11
+ *
12
+ * @module utils/toolEndEmitter
13
+ */
14
+ import { createToolEventPayload } from "../core/toolEvents.js";
15
+ /**
16
+ * Emit a `tool:end` event for every completed tool result in an
17
+ * `onStepFinish` callback.
18
+ *
19
+ * @param emitter - The NeuroLink event emitter (obtained via
20
+ * `neurolink.getEventEmitter()`). When `undefined` the function is a
21
+ * no-op so callers need not guard every call site.
22
+ * @param toolResults - The `toolResults` array from `onStepFinish`. When
23
+ * `undefined` or empty the function is a no-op.
24
+ */
25
+ export function emitToolEndFromStepFinish(emitter, toolResults) {
26
+ if (!emitter || !toolResults || toolResults.length === 0) {
27
+ return;
28
+ }
29
+ for (const tr of toolResults) {
30
+ const output = tr.output ?? tr.result;
31
+ const isError = !!tr.error ||
32
+ (output !== null &&
33
+ output !== undefined &&
34
+ typeof output === "object" &&
35
+ "isError" in output &&
36
+ output.isError === true);
37
+ let errorMessage;
38
+ if (isError) {
39
+ if (tr.error) {
40
+ errorMessage = tr.error;
41
+ }
42
+ else if (output && typeof output === "object") {
43
+ const content = output.content;
44
+ if (Array.isArray(content)) {
45
+ const texts = content
46
+ .filter((c) => c.type === "text" && c.text)
47
+ .map((c) => c.text);
48
+ errorMessage =
49
+ texts.length > 0 ? texts.join(" ") : "Tool returned isError: true";
50
+ }
51
+ else {
52
+ errorMessage = "Tool returned isError: true";
53
+ }
54
+ }
55
+ }
56
+ emitter.emit("tool:end", createToolEventPayload(tr.toolName, {
57
+ responseTime: 0,
58
+ success: !isError,
59
+ timestamp: Date.now(),
60
+ result: output,
61
+ error: errorMessage,
62
+ }));
63
+ }
64
+ }