@juspay/neurolink 9.54.6 → 9.54.8

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 (408) hide show
  1. package/CHANGELOG.md +8 -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 -0
  23. package/dist/auth/tokenStore.js +45 -4
  24. package/dist/autoresearch/tools.d.ts +1 -16
  25. package/dist/browser/neurolink.min.js +358 -358
  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 +1 -0
  54. package/dist/client/httpClient.js +13 -0
  55. package/dist/client/sseClient.d.ts +1 -0
  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 +6 -0
  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/evaluation/BatchEvaluator.d.ts +1 -97
  72. package/dist/evaluation/EvaluationAggregator.d.ts +1 -118
  73. package/dist/evaluation/EvaluatorFactory.d.ts +1 -13
  74. package/dist/evaluation/EvaluatorRegistry.d.ts +1 -50
  75. package/dist/evaluation/errors/EvaluationError.d.ts +2 -27
  76. package/dist/evaluation/hooks/langfuseAdapter.d.ts +1 -39
  77. package/dist/evaluation/hooks/observabilityHooks.d.ts +3 -55
  78. package/dist/evaluation/hooks/observabilityHooks.js +3 -0
  79. package/dist/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
  80. package/dist/evaluation/pipeline/strategies/batchStrategy.js +7 -7
  81. package/dist/evaluation/ragasEvaluator.js +54 -37
  82. package/dist/evaluation/reporting/metricsCollector.d.ts +1 -60
  83. package/dist/evaluation/reporting/reportGenerator.d.ts +1 -17
  84. package/dist/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
  85. package/dist/evaluation/scorers/rule/formatScorer.d.ts +1 -42
  86. package/dist/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
  87. package/dist/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
  88. package/dist/factories/providerFactory.d.ts +1 -16
  89. package/dist/factories/providerFactory.js +2 -0
  90. package/dist/image-gen/ImageGenService.d.ts +3 -0
  91. package/dist/image-gen/ImageGenService.js +3 -0
  92. package/dist/lib/action/actionInputs.d.ts +1 -1
  93. package/dist/lib/adapters/video/directorPipeline.js +6 -0
  94. package/dist/lib/adapters/video/vertexVideoHandler.js +6 -0
  95. package/dist/lib/agent/directTools.d.ts +3 -23
  96. package/dist/lib/auth/AuthProviderFactory.d.ts +1 -3
  97. package/dist/lib/auth/anthropicOAuth.d.ts +4 -7
  98. package/dist/lib/auth/anthropicOAuth.js +23 -0
  99. package/dist/lib/auth/errors.d.ts +1 -1
  100. package/dist/lib/auth/index.d.ts +11 -0
  101. package/dist/lib/auth/index.js +14 -0
  102. package/dist/lib/auth/middleware/AuthMiddleware.d.ts +5 -60
  103. package/dist/lib/auth/middleware/AuthMiddleware.js +3 -0
  104. package/dist/lib/auth/middleware/rateLimitByUser.d.ts +4 -93
  105. package/dist/lib/auth/middleware/rateLimitByUser.js +4 -0
  106. package/dist/lib/auth/providers/BaseAuthProvider.d.ts +1 -1
  107. package/dist/lib/auth/providers/CognitoProvider.js +3 -0
  108. package/dist/lib/auth/providers/KeycloakProvider.js +3 -0
  109. package/dist/lib/auth/providers/auth0.d.ts +1 -1
  110. package/dist/lib/auth/sessionManager.d.ts +2 -0
  111. package/dist/lib/auth/sessionManager.js +53 -11
  112. package/dist/lib/auth/tokenStore.d.ts +2 -0
  113. package/dist/lib/auth/tokenStore.js +45 -4
  114. package/dist/lib/autoresearch/tools.d.ts +1 -16
  115. package/dist/lib/client/aiSdkAdapter.d.ts +1 -1
  116. package/dist/lib/client/aiSdkAdapter.js +1 -0
  117. package/dist/lib/client/httpClient.d.ts +1 -0
  118. package/dist/lib/client/httpClient.js +13 -0
  119. package/dist/lib/client/sseClient.d.ts +1 -0
  120. package/dist/lib/client/sseClient.js +29 -0
  121. package/dist/lib/client/streamingClient.d.ts +2 -0
  122. package/dist/lib/client/streamingClient.js +19 -0
  123. package/dist/lib/client/wsClient.d.ts +6 -0
  124. package/dist/lib/client/wsClient.js +90 -10
  125. package/dist/lib/context/budgetChecker.js +3 -1
  126. package/dist/lib/context/contextCompactor.js +163 -143
  127. package/dist/lib/context/fileSummarizationService.d.ts +1 -9
  128. package/dist/lib/context/summarizationEngine.js +29 -16
  129. package/dist/lib/core/baseProvider.js +124 -153
  130. package/dist/lib/core/infrastructure/baseRegistry.d.ts +1 -7
  131. package/dist/lib/core/modules/GenerationHandler.d.ts +3 -2
  132. package/dist/lib/core/modules/GenerationHandler.js +9 -1
  133. package/dist/lib/core/modules/StreamHandler.js +9 -0
  134. package/dist/lib/core/modules/ToolsManager.js +18 -2
  135. package/dist/lib/evaluation/BatchEvaluator.d.ts +1 -97
  136. package/dist/lib/evaluation/EvaluationAggregator.d.ts +1 -118
  137. package/dist/lib/evaluation/EvaluatorFactory.d.ts +1 -13
  138. package/dist/lib/evaluation/EvaluatorRegistry.d.ts +1 -50
  139. package/dist/lib/evaluation/errors/EvaluationError.d.ts +2 -27
  140. package/dist/lib/evaluation/hooks/langfuseAdapter.d.ts +1 -39
  141. package/dist/lib/evaluation/hooks/observabilityHooks.d.ts +3 -55
  142. package/dist/lib/evaluation/hooks/observabilityHooks.js +3 -0
  143. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
  144. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.js +7 -7
  145. package/dist/lib/evaluation/ragasEvaluator.js +54 -37
  146. package/dist/lib/evaluation/reporting/metricsCollector.d.ts +1 -60
  147. package/dist/lib/evaluation/reporting/reportGenerator.d.ts +1 -17
  148. package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
  149. package/dist/lib/evaluation/scorers/rule/formatScorer.d.ts +1 -42
  150. package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
  151. package/dist/lib/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
  152. package/dist/lib/factories/providerFactory.d.ts +1 -16
  153. package/dist/lib/factories/providerFactory.js +2 -0
  154. package/dist/lib/image-gen/ImageGenService.d.ts +3 -0
  155. package/dist/lib/image-gen/ImageGenService.js +3 -0
  156. package/dist/lib/mcp/batching/requestBatcher.js +99 -73
  157. package/dist/lib/mcp/httpRateLimiter.js +3 -1
  158. package/dist/lib/mcp/httpRetryHandler.js +3 -1
  159. package/dist/lib/mcp/mcpClientFactory.js +3 -1
  160. package/dist/lib/mcp/multiServerManager.d.ts +1 -14
  161. package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
  162. package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
  163. package/dist/lib/mcp/toolDiscoveryService.js +70 -57
  164. package/dist/lib/mcp/toolRegistry.js +11 -1
  165. package/dist/lib/memory/memoryRetrievalTools.js +182 -141
  166. package/dist/lib/neurolink.js +236 -40
  167. package/dist/lib/observability/exporterRegistry.d.ts +3 -21
  168. package/dist/lib/observability/exporters/sentryExporter.js +1 -0
  169. package/dist/lib/observability/metricsAggregator.d.ts +1 -31
  170. package/dist/lib/observability/tokenTracker.d.ts +7 -16
  171. package/dist/lib/observability/tokenTracker.js +6 -4
  172. package/dist/lib/observability/utils/spanSerializer.d.ts +5 -1
  173. package/dist/lib/observability/utils/spanSerializer.js +24 -4
  174. package/dist/lib/processors/base/BaseFileProcessor.js +66 -53
  175. package/dist/lib/processors/document/ExcelProcessor.d.ts +1 -1
  176. package/dist/lib/processors/errors/errorHelpers.d.ts +1 -31
  177. package/dist/lib/processors/errors/errorSerializer.d.ts +1 -45
  178. package/dist/lib/processors/registry/ProcessorRegistry.js +17 -6
  179. package/dist/lib/providers/amazonBedrock.js +189 -15
  180. package/dist/lib/providers/amazonSagemaker.js +25 -11
  181. package/dist/lib/providers/anthropic.js +13 -0
  182. package/dist/lib/providers/azureOpenai.js +2 -0
  183. package/dist/lib/providers/googleAiStudio.js +96 -26
  184. package/dist/lib/providers/googleVertex.js +66 -27
  185. package/dist/lib/providers/huggingFace.js +2 -0
  186. package/dist/lib/providers/litellm.js +2 -0
  187. package/dist/lib/providers/mistral.js +2 -0
  188. package/dist/lib/providers/ollama.js +84 -5
  189. package/dist/lib/providers/openAI.d.ts +2 -0
  190. package/dist/lib/providers/openAI.js +17 -6
  191. package/dist/lib/providers/openRouter.js +2 -0
  192. package/dist/lib/providers/openaiCompatible.js +2 -0
  193. package/dist/lib/providers/sagemaker/detection.d.ts +1 -33
  194. package/dist/lib/providers/sagemaker/diagnostics.d.ts +1 -25
  195. package/dist/lib/providers/sagemaker/language-model.d.ts +1 -1
  196. package/dist/lib/proxy/proxyConfig.js +4 -0
  197. package/dist/lib/proxy/proxyEnv.d.ts +1 -17
  198. package/dist/lib/proxy/proxyTracer.d.ts +1 -36
  199. package/dist/lib/proxy/proxyTracer.js +9 -0
  200. package/dist/lib/proxy/quietDetector.d.ts +1 -7
  201. package/dist/lib/proxy/rawStreamCapture.d.ts +1 -10
  202. package/dist/lib/proxy/requestLogger.d.ts +1 -21
  203. package/dist/lib/proxy/sseInterceptor.d.ts +1 -66
  204. package/dist/lib/proxy/sseInterceptor.js +6 -0
  205. package/dist/lib/proxy/updateChecker.d.ts +1 -6
  206. package/dist/lib/proxy/updateState.d.ts +1 -12
  207. package/dist/lib/rag/chunkers/BaseChunker.js +36 -22
  208. package/dist/lib/rag/chunking/jsonChunker.d.ts +1 -1
  209. package/dist/lib/rag/errors/RAGError.d.ts +1 -2
  210. package/dist/lib/rag/ragIntegration.js +45 -32
  211. package/dist/lib/rag/reranker/reranker.js +151 -122
  212. package/dist/lib/rag/retrieval/vectorQueryTool.js +79 -65
  213. package/dist/lib/sdk/toolRegistration.d.ts +10 -44
  214. package/dist/lib/sdk/toolRegistration.js +1 -1
  215. package/dist/lib/server/middleware/abortSignal.d.ts +1 -11
  216. package/dist/lib/server/middleware/auth.d.ts +1 -21
  217. package/dist/lib/server/middleware/auth.js +12 -0
  218. package/dist/lib/server/middleware/common.js +48 -32
  219. package/dist/lib/server/middleware/deprecation.d.ts +1 -20
  220. package/dist/lib/server/middleware/rateLimit.d.ts +1 -75
  221. package/dist/lib/server/middleware/validation.d.ts +3 -81
  222. package/dist/lib/server/middleware/validation.js +3 -0
  223. package/dist/lib/server/openapi/generator.d.ts +1 -47
  224. package/dist/lib/server/routes/agentRoutes.js +112 -57
  225. package/dist/lib/server/routes/claudeProxyRoutes.d.ts +1 -6
  226. package/dist/lib/server/routes/claudeProxyRoutes.js +127 -13
  227. package/dist/lib/server/routes/healthRoutes.js +58 -12
  228. package/dist/lib/server/routes/index.d.ts +1 -26
  229. package/dist/lib/server/routes/mcpRoutes.js +40 -7
  230. package/dist/lib/server/routes/memoryRoutes.js +22 -7
  231. package/dist/lib/server/routes/openApiRoutes.js +30 -6
  232. package/dist/lib/server/routes/toolRoutes.js +140 -68
  233. package/dist/lib/server/streaming/dataStream.d.ts +1 -35
  234. package/dist/lib/server/streaming/dataStream.js +15 -0
  235. package/dist/lib/services/server/ai/observability/instrumentation.js +114 -14
  236. package/dist/lib/session/globalSessionState.d.ts +1 -10
  237. package/dist/lib/tasks/tools/taskTools.d.ts +2 -2
  238. package/dist/lib/telemetry/traceContext.d.ts +9 -0
  239. package/dist/lib/telemetry/traceContext.js +19 -0
  240. package/dist/lib/telemetry/tracers.d.ts +2 -0
  241. package/dist/lib/telemetry/tracers.js +2 -0
  242. package/dist/lib/types/action.d.ts +2 -0
  243. package/dist/lib/types/artifact.d.ts +7 -0
  244. package/dist/lib/types/auth.d.ts +125 -18
  245. package/dist/lib/types/autoresearch.d.ts +12 -0
  246. package/dist/lib/types/cli.d.ts +415 -0
  247. package/dist/lib/types/client.d.ts +34 -0
  248. package/dist/lib/types/common.d.ts +12 -41
  249. package/dist/lib/types/context.d.ts +5 -0
  250. package/dist/lib/types/evaluation.d.ts +332 -1
  251. package/dist/lib/types/file.d.ts +4 -0
  252. package/dist/lib/types/mcp.d.ts +102 -2
  253. package/dist/lib/types/middleware.d.ts +116 -0
  254. package/dist/lib/types/multimodal.d.ts +65 -0
  255. package/dist/lib/types/observability.d.ts +81 -0
  256. package/dist/lib/types/processor.d.ts +47 -0
  257. package/dist/lib/types/providers.d.ts +120 -16
  258. package/dist/lib/types/proxy.d.ts +321 -1
  259. package/dist/lib/types/rag.d.ts +22 -0
  260. package/dist/lib/types/scorer.d.ts +141 -0
  261. package/dist/lib/types/server.d.ts +99 -0
  262. package/dist/lib/types/span.d.ts +2 -1
  263. package/dist/lib/types/span.js +1 -0
  264. package/dist/lib/types/tools.d.ts +44 -0
  265. package/dist/lib/types/tts.d.ts +6 -0
  266. package/dist/lib/types/utilities.d.ts +22 -0
  267. package/dist/lib/types/workflow.d.ts +18 -0
  268. package/dist/lib/utils/async/retry.d.ts +2 -8
  269. package/dist/lib/utils/async/retry.js +9 -9
  270. package/dist/lib/utils/imageCompressor.d.ts +1 -21
  271. package/dist/lib/utils/imageCompressor.js +5 -1
  272. package/dist/lib/utils/messageBuilder.d.ts +1 -1
  273. package/dist/lib/utils/redis.d.ts +1 -4
  274. package/dist/lib/utils/toolEndEmitter.d.ts +25 -0
  275. package/dist/lib/utils/toolEndEmitter.js +65 -0
  276. package/dist/lib/workflow/config.d.ts +7 -32
  277. package/dist/lib/workflow/core/ensembleExecutor.js +28 -0
  278. package/dist/lib/workflow/core/judgeScorer.js +23 -0
  279. package/dist/lib/workflow/core/responseConditioner.js +17 -0
  280. package/dist/lib/workflow/core/workflowRunner.d.ts +1 -19
  281. package/dist/lib/workflow/core/workflowRunner.js +202 -147
  282. package/dist/mcp/batching/requestBatcher.js +99 -73
  283. package/dist/mcp/httpRateLimiter.js +3 -1
  284. package/dist/mcp/httpRetryHandler.js +3 -1
  285. package/dist/mcp/mcpClientFactory.js +3 -1
  286. package/dist/mcp/multiServerManager.d.ts +1 -14
  287. package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
  288. package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
  289. package/dist/mcp/toolDiscoveryService.js +70 -57
  290. package/dist/mcp/toolRegistry.js +11 -1
  291. package/dist/memory/memoryRetrievalTools.js +182 -141
  292. package/dist/neurolink.js +236 -40
  293. package/dist/observability/exporterRegistry.d.ts +3 -21
  294. package/dist/observability/exporters/sentryExporter.js +1 -0
  295. package/dist/observability/metricsAggregator.d.ts +1 -31
  296. package/dist/observability/tokenTracker.d.ts +7 -16
  297. package/dist/observability/tokenTracker.js +6 -4
  298. package/dist/observability/utils/spanSerializer.d.ts +5 -1
  299. package/dist/observability/utils/spanSerializer.js +24 -4
  300. package/dist/processors/base/BaseFileProcessor.js +66 -53
  301. package/dist/processors/document/ExcelProcessor.d.ts +1 -1
  302. package/dist/processors/errors/errorHelpers.d.ts +1 -31
  303. package/dist/processors/errors/errorSerializer.d.ts +1 -45
  304. package/dist/processors/registry/ProcessorRegistry.js +17 -6
  305. package/dist/providers/amazonBedrock.js +189 -15
  306. package/dist/providers/amazonSagemaker.js +25 -11
  307. package/dist/providers/anthropic.js +13 -0
  308. package/dist/providers/azureOpenai.js +2 -0
  309. package/dist/providers/googleAiStudio.js +96 -26
  310. package/dist/providers/googleVertex.js +66 -27
  311. package/dist/providers/huggingFace.js +2 -0
  312. package/dist/providers/litellm.js +2 -0
  313. package/dist/providers/mistral.js +2 -0
  314. package/dist/providers/ollama.js +84 -5
  315. package/dist/providers/openAI.d.ts +2 -0
  316. package/dist/providers/openAI.js +17 -6
  317. package/dist/providers/openRouter.js +2 -0
  318. package/dist/providers/openaiCompatible.js +2 -0
  319. package/dist/providers/sagemaker/detection.d.ts +1 -33
  320. package/dist/providers/sagemaker/diagnostics.d.ts +1 -25
  321. package/dist/providers/sagemaker/language-model.d.ts +1 -1
  322. package/dist/proxy/proxyConfig.js +4 -0
  323. package/dist/proxy/proxyEnv.d.ts +1 -17
  324. package/dist/proxy/proxyTracer.d.ts +1 -36
  325. package/dist/proxy/proxyTracer.js +9 -0
  326. package/dist/proxy/quietDetector.d.ts +1 -7
  327. package/dist/proxy/rawStreamCapture.d.ts +1 -10
  328. package/dist/proxy/requestLogger.d.ts +1 -21
  329. package/dist/proxy/sseInterceptor.d.ts +1 -66
  330. package/dist/proxy/sseInterceptor.js +6 -0
  331. package/dist/proxy/updateChecker.d.ts +1 -6
  332. package/dist/proxy/updateState.d.ts +1 -12
  333. package/dist/rag/chunkers/BaseChunker.js +36 -22
  334. package/dist/rag/chunking/jsonChunker.d.ts +1 -1
  335. package/dist/rag/errors/RAGError.d.ts +1 -2
  336. package/dist/rag/ragIntegration.js +45 -32
  337. package/dist/rag/reranker/reranker.js +151 -122
  338. package/dist/rag/retrieval/vectorQueryTool.js +79 -65
  339. package/dist/sdk/toolRegistration.d.ts +10 -44
  340. package/dist/sdk/toolRegistration.js +1 -1
  341. package/dist/server/middleware/abortSignal.d.ts +1 -11
  342. package/dist/server/middleware/auth.d.ts +1 -21
  343. package/dist/server/middleware/auth.js +12 -0
  344. package/dist/server/middleware/common.js +48 -32
  345. package/dist/server/middleware/deprecation.d.ts +1 -20
  346. package/dist/server/middleware/rateLimit.d.ts +1 -75
  347. package/dist/server/middleware/validation.d.ts +3 -81
  348. package/dist/server/middleware/validation.js +3 -0
  349. package/dist/server/openapi/generator.d.ts +1 -47
  350. package/dist/server/routes/agentRoutes.js +112 -57
  351. package/dist/server/routes/claudeProxyRoutes.d.ts +1 -6
  352. package/dist/server/routes/claudeProxyRoutes.js +127 -13
  353. package/dist/server/routes/healthRoutes.js +58 -12
  354. package/dist/server/routes/index.d.ts +1 -26
  355. package/dist/server/routes/mcpRoutes.js +40 -7
  356. package/dist/server/routes/memoryRoutes.js +22 -7
  357. package/dist/server/routes/openApiRoutes.js +30 -6
  358. package/dist/server/routes/toolRoutes.js +140 -68
  359. package/dist/server/streaming/dataStream.d.ts +1 -35
  360. package/dist/server/streaming/dataStream.js +15 -0
  361. package/dist/services/server/ai/observability/instrumentation.js +114 -14
  362. package/dist/session/globalSessionState.d.ts +1 -10
  363. package/dist/tasks/tools/taskTools.d.ts +2 -2
  364. package/dist/telemetry/traceContext.d.ts +9 -0
  365. package/dist/telemetry/traceContext.js +18 -0
  366. package/dist/telemetry/tracers.d.ts +2 -0
  367. package/dist/telemetry/tracers.js +2 -0
  368. package/dist/types/action.d.ts +2 -0
  369. package/dist/types/artifact.d.ts +7 -0
  370. package/dist/types/auth.d.ts +125 -18
  371. package/dist/types/autoresearch.d.ts +12 -0
  372. package/dist/types/cli.d.ts +415 -0
  373. package/dist/types/client.d.ts +34 -0
  374. package/dist/types/common.d.ts +12 -41
  375. package/dist/types/context.d.ts +5 -0
  376. package/dist/types/evaluation.d.ts +332 -1
  377. package/dist/types/file.d.ts +4 -0
  378. package/dist/types/mcp.d.ts +102 -2
  379. package/dist/types/middleware.d.ts +116 -0
  380. package/dist/types/multimodal.d.ts +65 -0
  381. package/dist/types/observability.d.ts +81 -0
  382. package/dist/types/processor.d.ts +47 -0
  383. package/dist/types/providers.d.ts +120 -16
  384. package/dist/types/proxy.d.ts +321 -1
  385. package/dist/types/rag.d.ts +22 -0
  386. package/dist/types/scorer.d.ts +141 -0
  387. package/dist/types/server.d.ts +99 -0
  388. package/dist/types/span.d.ts +2 -1
  389. package/dist/types/span.js +1 -0
  390. package/dist/types/tools.d.ts +44 -0
  391. package/dist/types/tts.d.ts +6 -0
  392. package/dist/types/utilities.d.ts +22 -0
  393. package/dist/types/workflow.d.ts +18 -0
  394. package/dist/utils/async/retry.d.ts +2 -8
  395. package/dist/utils/async/retry.js +9 -9
  396. package/dist/utils/imageCompressor.d.ts +1 -21
  397. package/dist/utils/imageCompressor.js +5 -1
  398. package/dist/utils/messageBuilder.d.ts +1 -1
  399. package/dist/utils/redis.d.ts +1 -4
  400. package/dist/utils/toolEndEmitter.d.ts +25 -0
  401. package/dist/utils/toolEndEmitter.js +64 -0
  402. package/dist/workflow/config.d.ts +4 -29
  403. package/dist/workflow/core/ensembleExecutor.js +28 -0
  404. package/dist/workflow/core/judgeScorer.js +23 -0
  405. package/dist/workflow/core/responseConditioner.js +17 -0
  406. package/dist/workflow/core/workflowRunner.d.ts +1 -19
  407. package/dist/workflow/core/workflowRunner.js +202 -147
  408. package/package.json +2 -8
@@ -4,6 +4,8 @@
4
4
  */
5
5
  import { logger } from "../../utils/logger.js";
6
6
  import { OpenAPIGenerator } from "../openapi/generator.js";
7
+ import { withSpan } from "../../telemetry/withSpan.js";
8
+ import { tracers } from "../../telemetry/tracers.js";
7
9
  /**
8
10
  * Create OpenAPI documentation routes
9
11
  *
@@ -44,7 +46,14 @@ export function createOpenApiRoutes(basePath = "/api", getRoutes) {
44
46
  {
45
47
  method: "GET",
46
48
  path: `${basePath}/openapi.json`,
47
- handler: async () => {
49
+ handler: async () => withSpan({
50
+ name: "neurolink.http.openapi.json",
51
+ tracer: tracers.http,
52
+ attributes: {
53
+ "http.route": `${basePath}/openapi.json`,
54
+ "openapi.format": "json",
55
+ },
56
+ }, async (span) => {
48
57
  const routes = getRoutes?.() ?? [];
49
58
  if (!getRoutes) {
50
59
  logger.warn("[OpenAPI] No getRoutes callback provided. OpenAPI spec will use default endpoint definitions. " +
@@ -53,19 +62,27 @@ export function createOpenApiRoutes(basePath = "/api", getRoutes) {
53
62
  else if (routes.length === 0) {
54
63
  logger.debug("[OpenAPI] getRoutes returned empty array. No custom routes will be documented.");
55
64
  }
65
+ span.setAttribute("openapi.route_count", routes.length);
56
66
  const generator = new OpenAPIGenerator({
57
67
  basePath,
58
68
  routes,
59
69
  });
60
70
  return generator.generate();
61
- },
71
+ }),
62
72
  description: "Get OpenAPI specification as JSON",
63
73
  tags: ["openapi", "documentation"],
64
74
  },
65
75
  {
66
76
  method: "GET",
67
77
  path: `${basePath}/openapi.yaml`,
68
- handler: async () => {
78
+ handler: async () => withSpan({
79
+ name: "neurolink.http.openapi.yaml",
80
+ tracer: tracers.http,
81
+ attributes: {
82
+ "http.route": `${basePath}/openapi.yaml`,
83
+ "openapi.format": "yaml",
84
+ },
85
+ }, async (span) => {
69
86
  const routes = getRoutes?.() ?? [];
70
87
  if (!getRoutes) {
71
88
  logger.warn("[OpenAPI] No getRoutes callback provided. OpenAPI spec will use default endpoint definitions. " +
@@ -74,6 +91,7 @@ export function createOpenApiRoutes(basePath = "/api", getRoutes) {
74
91
  else if (routes.length === 0) {
75
92
  logger.debug("[OpenAPI] getRoutes returned empty array. No custom routes will be documented.");
76
93
  }
94
+ span.setAttribute("openapi.route_count", routes.length);
77
95
  const generator = new OpenAPIGenerator({
78
96
  basePath,
79
97
  routes,
@@ -83,14 +101,20 @@ export function createOpenApiRoutes(basePath = "/api", getRoutes) {
83
101
  contentType: "text/yaml",
84
102
  body: generator.toYAML(),
85
103
  };
86
- },
104
+ }),
87
105
  description: "Get OpenAPI specification as YAML",
88
106
  tags: ["openapi", "documentation"],
89
107
  },
90
108
  {
91
109
  method: "GET",
92
110
  path: `${basePath}/docs`,
93
- handler: async () => {
111
+ handler: async () => withSpan({
112
+ name: "neurolink.http.openapi.docs",
113
+ tracer: tracers.http,
114
+ attributes: {
115
+ "http.route": `${basePath}/docs`,
116
+ },
117
+ }, async () => {
94
118
  const html = `<!DOCTYPE html>
95
119
  <html>
96
120
  <head>
@@ -117,7 +141,7 @@ export function createOpenApiRoutes(basePath = "/api", getRoutes) {
117
141
  contentType: "text/html",
118
142
  body: html,
119
143
  };
120
- },
144
+ }),
121
145
  description: "Swagger UI documentation page",
122
146
  tags: ["openapi", "documentation"],
123
147
  },
@@ -2,6 +2,9 @@
2
2
  * Tool Routes
3
3
  * Endpoints for tool listing, discovery, and execution
4
4
  */
5
+ import { SpanStatusCode } from "@opentelemetry/api";
6
+ import { withSpan } from "../../telemetry/withSpan.js";
7
+ import { tracers } from "../../telemetry/tracers.js";
5
8
  import { createErrorResponse, ToolArgumentsSchema, ToolExecuteRequestSchema, ToolNameParamSchema, validateParams, validateRequest, } from "../utils/validation.js";
6
9
  /**
7
10
  * Create tool routes
@@ -19,8 +22,13 @@ export function createToolRoutes(basePath = "/api") {
19
22
  {
20
23
  method: "GET",
21
24
  path: `${basePath}/tools`,
22
- handler: async (ctx) => {
25
+ handler: async (ctx) => withSpan({
26
+ name: "neurolink.http.tools.list",
27
+ tracer: tracers.http,
28
+ attributes: { "http.route": `${basePath}/tools` },
29
+ }, async (span) => {
23
30
  const tools = await ctx.toolRegistry.listTools();
31
+ span.setAttribute("tools.count", tools.length);
24
32
  return {
25
33
  tools: tools.map((tool) => ({
26
34
  name: tool.name,
@@ -30,7 +38,7 @@ export function createToolRoutes(basePath = "/api") {
30
38
  })),
31
39
  total: tools.length,
32
40
  };
33
- },
41
+ }),
34
42
  description: "List all available tools",
35
43
  tags: ["tools"],
36
44
  },
@@ -38,7 +46,14 @@ export function createToolRoutes(basePath = "/api") {
38
46
  {
39
47
  method: "GET",
40
48
  path: `${basePath}/tools/search`,
41
- handler: async (ctx) => {
49
+ handler: async (ctx) => withSpan({
50
+ name: "neurolink.http.tools.search",
51
+ tracer: tracers.http,
52
+ attributes: {
53
+ "http.route": `${basePath}/tools/search`,
54
+ "tools.search.query": ctx.query.q ?? "",
55
+ },
56
+ }, async () => {
42
57
  const { q, source, limit } = ctx.query;
43
58
  const tools = await ctx.toolRegistry.listTools();
44
59
  let filtered = tools;
@@ -65,7 +80,7 @@ export function createToolRoutes(basePath = "/api") {
65
80
  total: filtered.length,
66
81
  query: q || null,
67
82
  };
68
- },
83
+ }),
69
84
  description: "Search tools by name or description",
70
85
  tags: ["tools"],
71
86
  },
@@ -80,38 +95,59 @@ export function createToolRoutes(basePath = "/api") {
80
95
  return validation.error;
81
96
  }
82
97
  const request = validation.data;
83
- const startTime = Date.now();
84
- try {
85
- // Get tool from registry
86
- const tools = await ctx.toolRegistry.listTools();
87
- const tool = tools.find((t) => t.name === request.name);
88
- if (!tool) {
98
+ return withSpan({
99
+ name: "neurolink.http.tools.execute",
100
+ tracer: tracers.http,
101
+ attributes: {
102
+ "http.route": `${basePath}/tools/execute`,
103
+ "tool.name": request.name,
104
+ },
105
+ }, async (span) => {
106
+ const startTime = Date.now();
107
+ try {
108
+ // Get tool from registry
109
+ const tools = await ctx.toolRegistry.listTools();
110
+ const tool = tools.find((t) => t.name === request.name);
111
+ if (!tool) {
112
+ span.setAttribute("tool.found", false);
113
+ span.setStatus({
114
+ code: SpanStatusCode.ERROR,
115
+ message: `Tool '${request.name}' not found`,
116
+ });
117
+ return {
118
+ success: false,
119
+ error: `Tool '${request.name}' not found`,
120
+ duration: Date.now() - startTime,
121
+ };
122
+ }
123
+ // Execute the tool
124
+ const result = await ctx.toolRegistry.executeTool(request.name, request.arguments);
125
+ span.setAttribute("tool.success", true);
126
+ return {
127
+ success: true,
128
+ data: result,
129
+ duration: Date.now() - startTime,
130
+ metadata: {
131
+ toolName: request.name,
132
+ sessionId: request.sessionId || null,
133
+ },
134
+ };
135
+ }
136
+ catch (error) {
137
+ const errorMessage = error instanceof Error ? error.message : String(error);
138
+ span.setAttribute("tool.success", false);
139
+ span.setStatus({
140
+ code: SpanStatusCode.ERROR,
141
+ message: errorMessage,
142
+ });
143
+ span.recordException(error instanceof Error ? error : new Error(errorMessage));
89
144
  return {
90
145
  success: false,
91
- error: `Tool '${request.name}' not found`,
146
+ error: errorMessage,
92
147
  duration: Date.now() - startTime,
93
148
  };
94
149
  }
95
- // Execute the tool
96
- const result = await ctx.toolRegistry.executeTool(request.name, request.arguments);
97
- return {
98
- success: true,
99
- data: result,
100
- duration: Date.now() - startTime,
101
- metadata: {
102
- toolName: request.name,
103
- sessionId: request.sessionId || null,
104
- },
105
- };
106
- }
107
- catch (error) {
108
- const errorMessage = error instanceof Error ? error.message : String(error);
109
- return {
110
- success: false,
111
- error: errorMessage,
112
- duration: Date.now() - startTime,
113
- };
114
- }
150
+ });
115
151
  },
116
152
  description: "Execute a tool with arguments",
117
153
  tags: ["tools"],
@@ -133,37 +169,58 @@ export function createToolRoutes(basePath = "/api") {
133
169
  return bodyValidation.error;
134
170
  }
135
171
  const args = bodyValidation.data;
136
- const startTime = Date.now();
137
- try {
138
- // Get tool from registry
139
- const tools = await ctx.toolRegistry.listTools();
140
- const tool = tools.find((t) => t.name === name);
141
- if (!tool) {
172
+ return withSpan({
173
+ name: "neurolink.http.tools.executeByName",
174
+ tracer: tracers.http,
175
+ attributes: {
176
+ "http.route": `${basePath}/tools/:name/execute`,
177
+ "tool.name": name,
178
+ },
179
+ }, async (span) => {
180
+ const startTime = Date.now();
181
+ try {
182
+ // Get tool from registry
183
+ const tools = await ctx.toolRegistry.listTools();
184
+ const tool = tools.find((t) => t.name === name);
185
+ if (!tool) {
186
+ span.setAttribute("tool.found", false);
187
+ span.setStatus({
188
+ code: SpanStatusCode.ERROR,
189
+ message: `Tool '${name}' not found`,
190
+ });
191
+ return {
192
+ success: false,
193
+ error: `Tool '${name}' not found`,
194
+ duration: Date.now() - startTime,
195
+ };
196
+ }
197
+ // Execute the tool
198
+ const result = await ctx.toolRegistry.executeTool(name, args);
199
+ span.setAttribute("tool.success", true);
200
+ return {
201
+ success: true,
202
+ data: result,
203
+ duration: Date.now() - startTime,
204
+ metadata: {
205
+ toolName: name,
206
+ },
207
+ };
208
+ }
209
+ catch (error) {
210
+ const errorMessage = error instanceof Error ? error.message : String(error);
211
+ span.setAttribute("tool.success", false);
212
+ span.setStatus({
213
+ code: SpanStatusCode.ERROR,
214
+ message: errorMessage,
215
+ });
216
+ span.recordException(error instanceof Error ? error : new Error(errorMessage));
142
217
  return {
143
218
  success: false,
144
- error: `Tool '${name}' not found`,
219
+ error: errorMessage,
145
220
  duration: Date.now() - startTime,
146
221
  };
147
222
  }
148
- // Execute the tool
149
- const result = await ctx.toolRegistry.executeTool(name, args);
150
- return {
151
- success: true,
152
- data: result,
153
- duration: Date.now() - startTime,
154
- metadata: {
155
- toolName: name,
156
- },
157
- };
158
- }
159
- catch (error) {
160
- const errorMessage = error instanceof Error ? error.message : String(error);
161
- return {
162
- success: false,
163
- error: errorMessage,
164
- duration: Date.now() - startTime,
165
- };
166
- }
223
+ });
167
224
  },
168
225
  description: "Execute a specific tool by name",
169
226
  tags: ["tools"],
@@ -179,17 +236,32 @@ export function createToolRoutes(basePath = "/api") {
179
236
  return paramValidation.error;
180
237
  }
181
238
  const { name } = paramValidation.data;
182
- const tools = await ctx.toolRegistry.listTools();
183
- const tool = tools.find((t) => t.name === name);
184
- if (!tool) {
185
- return createErrorResponse("TOOL_NOT_FOUND", `Tool '${name}' not found`, undefined, ctx.requestId);
186
- }
187
- return {
188
- name: tool.name,
189
- description: tool.description,
190
- inputSchema: tool.inputSchema,
191
- source: tool.source || "built-in",
192
- };
239
+ return withSpan({
240
+ name: "neurolink.http.tools.get",
241
+ tracer: tracers.http,
242
+ attributes: {
243
+ "http.route": `${basePath}/tools/:name`,
244
+ "tool.name": name,
245
+ },
246
+ }, async (span) => {
247
+ const tools = await ctx.toolRegistry.listTools();
248
+ const tool = tools.find((t) => t.name === name);
249
+ if (!tool) {
250
+ span.setAttribute("tool.found", false);
251
+ span.setStatus({
252
+ code: SpanStatusCode.ERROR,
253
+ message: `Tool '${name}' not found`,
254
+ });
255
+ return createErrorResponse("TOOL_NOT_FOUND", `Tool '${name}' not found`, undefined, ctx.requestId);
256
+ }
257
+ span.setAttribute("tool.found", true);
258
+ return {
259
+ name: tool.name,
260
+ description: tool.description,
261
+ inputSchema: tool.inputSchema,
262
+ source: tool.source || "built-in",
263
+ };
264
+ });
193
265
  },
194
266
  description: "Get tool details by name",
195
267
  tags: ["tools"],
@@ -3,20 +3,7 @@
3
3
  * Implements a protocol for streaming structured data between server and client
4
4
  * Compatible with AI SDK's data stream format
5
5
  */
6
- import type { DataStreamWriter, CloseHandler } from "../../types/index.js";
7
- /**
8
- * Configuration for DataStreamWriter
9
- */
10
- type DataStreamWriterConfig = {
11
- /** Writer function to send data */
12
- write: (chunk: string) => void | Promise<void>;
13
- /** Function to close the stream */
14
- close?: () => void | Promise<void>;
15
- /** Format: sse (Server-Sent Events) or ndjson (Newline-delimited JSON) */
16
- format?: "sse" | "ndjson";
17
- /** Include timestamps in events */
18
- includeTimestamps?: boolean;
19
- };
6
+ import type { CloseHandler, DataStreamResponseConfig, DataStreamWriter, DataStreamWriterConfig, SSEEventOptions } from "../../types/index.js";
20
7
  /**
21
8
  * Creates a data stream writer
22
9
  */
@@ -24,16 +11,6 @@ export declare function createDataStreamWriter(config: DataStreamWriterConfig):
24
11
  /**
25
12
  * Configuration for DataStreamResponse
26
13
  */
27
- type DataStreamResponseConfig = {
28
- /** Content type header */
29
- contentType?: "text/event-stream" | "application/x-ndjson";
30
- /** Initial headers */
31
- headers?: Record<string, string>;
32
- /** Keep-alive interval in milliseconds */
33
- keepAliveInterval?: number;
34
- /** Include timestamps in events */
35
- includeTimestamps?: boolean;
36
- };
37
14
  /**
38
15
  * Data stream response class
39
16
  * Creates a streaming response with writer interface
@@ -136,16 +113,6 @@ export declare function createNDJSONHeaders(additionalHeaders?: Record<string, s
136
113
  /**
137
114
  * SSE Event options for formatSSEEvent
138
115
  */
139
- type SSEEventOptions = {
140
- /** Event type (optional) */
141
- event?: string;
142
- /** Event data (required) */
143
- data: string;
144
- /** Event ID (optional) */
145
- id?: string;
146
- /** Retry interval in milliseconds (optional) */
147
- retry?: number;
148
- };
149
116
  /**
150
117
  * Format a Server-Sent Events (SSE) message
151
118
  *
@@ -243,4 +210,3 @@ export declare class WebStreamWriter extends BaseDataStreamWriter {
243
210
  writeEvent(eventType: string, data: unknown): void;
244
211
  protected doClose(): void;
245
212
  }
246
- export {};
@@ -3,6 +3,9 @@
3
3
  * Implements a protocol for streaming structured data between server and client
4
4
  * Compatible with AI SDK's data stream format
5
5
  */
6
+ // ============================================
7
+ // Data Stream Writer Implementation
8
+ // ============================================
6
9
  /**
7
10
  * Creates a data stream writer
8
11
  */
@@ -64,6 +67,12 @@ export function createDataStreamWriter(config) {
64
67
  },
65
68
  };
66
69
  }
70
+ // ============================================
71
+ // Data Stream Response
72
+ // ============================================
73
+ /**
74
+ * Configuration for DataStreamResponse
75
+ */
67
76
  /**
68
77
  * Data stream response class
69
78
  * Creates a streaming response with writer interface
@@ -305,6 +314,12 @@ export function createNDJSONHeaders(additionalHeaders) {
305
314
  ...additionalHeaders,
306
315
  };
307
316
  }
317
+ // ============================================
318
+ // SSE Event Formatting (Legacy Compatibility)
319
+ // ============================================
320
+ /**
321
+ * SSE Event options for formatSSEEvent
322
+ */
308
323
  /**
309
324
  * Format a Server-Sent Events (SSE) message
310
325
  *
@@ -7,7 +7,7 @@
7
7
  * Flow: Vercel AI SDK → OpenTelemetry Spans → LangfuseSpanProcessor → Langfuse Platform
8
8
  */
9
9
  import { LangfuseSpanProcessor } from "@langfuse/otel";
10
- import { metrics, trace } from "@opentelemetry/api";
10
+ import { metrics, SpanStatusCode, trace } from "@opentelemetry/api";
11
11
  import { W3CTraceContextPropagator } from "@opentelemetry/core";
12
12
  import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
13
13
  import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
@@ -368,24 +368,124 @@ class ContextEnricher {
368
368
  attributes["ai.model.id"] ||
369
369
  attributes["gen_ai.request.model"];
370
370
  if (isGenAISpan) {
371
+ const model = attributes["gen_ai.request.model"] ||
372
+ attributes["ai.model.id"];
373
+ const provider = attributes["gen_ai.system"] ||
374
+ attributes["ai.model.provider"];
371
375
  logger.debug(`${LOG_PREFIX} GenAI span detected`, {
372
376
  spanName: readableSpan.name,
373
- model: attributes["gen_ai.request.model"] || attributes["ai.model.id"],
374
- provider: attributes["gen_ai.system"] || attributes["ai.model.provider"],
377
+ model,
378
+ provider,
375
379
  });
376
- // Log token usage for observability
377
- const inputTokens = attributes["gen_ai.usage.input_tokens"] ||
378
- attributes["ai.usage.promptTokens"];
379
- const outputTokens = attributes["gen_ai.usage.output_tokens"] ||
380
- attributes["ai.usage.completionTokens"];
381
- if (inputTokens !== undefined || outputTokens !== undefined) {
382
- logger.debug(`${LOG_PREFIX} Token usage captured`, {
383
- inputTokens,
384
- outputTokens,
385
- totalTokens: attributes["gen_ai.usage.total_tokens"],
386
- });
380
+ // L4/L6 fix: Set explicit Langfuse observation attributes so
381
+ // cost dashboards and model analytics work correctly.
382
+ try {
383
+ const mAttrs = span.attributes;
384
+ // L6: Model identity
385
+ if (model) {
386
+ mAttrs["gen_ai.response.model"] = model;
387
+ }
388
+ // L4: Usage details — aggregate from AI SDK attributes into a
389
+ // structured JSON object that Langfuse can parse for cost analysis.
390
+ const inputTokens = attributes["gen_ai.usage.input_tokens"] ??
391
+ attributes["ai.usage.promptTokens"];
392
+ const outputTokens = attributes["gen_ai.usage.output_tokens"] ??
393
+ attributes["ai.usage.completionTokens"];
394
+ const totalTokens = attributes["gen_ai.usage.total_tokens"] ??
395
+ (inputTokens !== undefined && outputTokens !== undefined
396
+ ? inputTokens + outputTokens
397
+ : undefined);
398
+ const reasoningTokens = attributes["gen_ai.usage.reasoning_tokens"] ??
399
+ attributes["ai.usage.reasoningTokens"];
400
+ const cachedTokens = attributes["gen_ai.usage.input_cached_tokens"];
401
+ if (inputTokens !== undefined || outputTokens !== undefined) {
402
+ const usageDetails = {};
403
+ if (inputTokens !== undefined) {
404
+ usageDetails.input = inputTokens;
405
+ }
406
+ if (outputTokens !== undefined) {
407
+ usageDetails.output = outputTokens;
408
+ }
409
+ if (totalTokens !== undefined) {
410
+ usageDetails.total = totalTokens;
411
+ }
412
+ if (reasoningTokens !== undefined) {
413
+ usageDetails.reasoning_tokens = reasoningTokens;
414
+ }
415
+ if (cachedTokens !== undefined) {
416
+ usageDetails.input_cached_tokens = cachedTokens;
417
+ }
418
+ mAttrs["langfuse.usage_details"] = JSON.stringify(usageDetails);
419
+ logger.debug(`${LOG_PREFIX} Token usage captured`, {
420
+ inputTokens,
421
+ outputTokens,
422
+ totalTokens,
423
+ });
424
+ }
425
+ // L7: Model parameters — surface temperature and max_tokens for
426
+ // generation tuning visibility.
427
+ const temperature = attributes["gen_ai.request.temperature"] ??
428
+ attributes["ai.settings.temperature"];
429
+ const maxTokens = attributes["gen_ai.request.max_tokens"] ??
430
+ attributes["ai.settings.maxTokens"];
431
+ const topP = attributes["gen_ai.request.top_p"] ??
432
+ attributes["ai.settings.topP"];
433
+ if (temperature !== undefined ||
434
+ maxTokens !== undefined ||
435
+ topP !== undefined) {
436
+ const params = {};
437
+ if (temperature !== undefined) {
438
+ params.temperature = temperature;
439
+ }
440
+ if (maxTokens !== undefined) {
441
+ params.max_tokens = maxTokens;
442
+ }
443
+ if (topP !== undefined) {
444
+ params.top_p = topP;
445
+ }
446
+ mAttrs["gen_ai.request.model_parameters"] = JSON.stringify(params);
447
+ }
448
+ }
449
+ catch {
450
+ // Read-only attributes — cannot enrich; Pipeline A will still
451
+ // export the raw GenAI attributes that Langfuse can parse.
452
+ }
453
+ }
454
+ // P8 fix: Propagate error status to Langfuse-consumable attributes.
455
+ // OTel ReadableSpan attributes may be readonly at onEnd() time; the type
456
+ // cast attempts late mutation. LangfuseSpanProcessor runs after
457
+ // ContextEnricher in the spanProcessors array and reads these attributes,
458
+ // so setting them here allows Langfuse to surface the correct level and
459
+ // status message on the trace/generation.
460
+ const readableStatus = span.status;
461
+ try {
462
+ const mutableAttrs = span.attributes;
463
+ if (readableStatus?.code === SpanStatusCode.ERROR) {
464
+ mutableAttrs["langfuse.level"] = "ERROR";
465
+ if (readableStatus.message) {
466
+ mutableAttrs["langfuse.status_message"] = readableStatus.message;
467
+ }
468
+ }
469
+ else {
470
+ // P8 extended: Detect WARNING-level conditions on non-ERROR spans.
471
+ // The AI SDK sets ai.finishReason on its spans; content-filter and
472
+ // length finish reasons indicate partial failures that deserve WARNING.
473
+ const finishReason = mutableAttrs["ai.finishReason"] ??
474
+ mutableAttrs["gen_ai.response.finish_reasons"];
475
+ const reasonStr = Array.isArray(finishReason)
476
+ ? finishReason.join(",")
477
+ : String(finishReason ?? "");
478
+ if (reasonStr.includes("content-filter") || reasonStr === "length") {
479
+ mutableAttrs["langfuse.level"] = "WARNING";
480
+ mutableAttrs["langfuse.status_message"] =
481
+ `Generation stopped: finishReason=${reasonStr}`;
482
+ }
387
483
  }
388
484
  }
485
+ catch {
486
+ // Readonly enforcement by OTel SDK — mutation not possible; log at debug.
487
+ logger.debug(`${LOG_PREFIX} Could not set langfuse.level on span (read-only attributes)`);
488
+ }
389
489
  }
390
490
  catch (error) {
391
491
  // Don't fail span processing on errors
@@ -1,13 +1,5 @@
1
1
  import { NeuroLink } from "../neurolink.js";
2
- import type { ConversationMemoryConfig } from "../types/index.js";
3
- type SessionVariableValue = string | number | boolean;
4
- type LoopSessionState = {
5
- neurolinkInstance: NeuroLink;
6
- sessionId: string;
7
- isActive: boolean;
8
- conversationMemoryConfig?: ConversationMemoryConfig;
9
- sessionVariables: Record<string, SessionVariableValue>;
10
- };
2
+ import type { ConversationMemoryConfig, LoopSessionState, SessionVariableValue } from "../types/index.js";
11
3
  export declare class GlobalSessionManager {
12
4
  private static instance;
13
5
  private loopSession;
@@ -50,4 +42,3 @@ export declare class GlobalSessionManager {
50
42
  clearSessionVariables(): void;
51
43
  }
52
44
  export declare const globalSession: GlobalSessionManager;
53
- export {};
@@ -31,7 +31,7 @@ export declare function createTaskTools(manager: TaskManager): {
31
31
  name: string;
32
32
  prompt: string;
33
33
  schedule: {
34
- type: "cron" | "interval" | "once";
34
+ type: "once" | "cron" | "interval";
35
35
  expression?: string | undefined;
36
36
  timezone?: string | undefined;
37
37
  every?: number | undefined;
@@ -58,7 +58,7 @@ export declare function createTaskTools(manager: TaskManager): {
58
58
  schedule?: undefined;
59
59
  }>;
60
60
  listTasks: import("ai").Tool<{
61
- status?: "failed" | "pending" | "active" | "paused" | "completed" | "cancelled" | undefined;
61
+ status?: "failed" | "pending" | "completed" | "cancelled" | "active" | "paused" | undefined;
62
62
  }, {
63
63
  success: boolean;
64
64
  count: number;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Extract the current OTel trace context for use by Pipeline B spans.
3
+ * Returns undefined values when no OTel context is active, allowing
4
+ * Pipeline B spans to share the same trace as Pipeline A spans.
5
+ */
6
+ export declare function getActiveTraceContext(): {
7
+ traceId?: string;
8
+ parentSpanId?: string;
9
+ };