@juspay/neurolink 9.65.0 → 9.65.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/adapters/video/videoAnalyzer.d.ts +1 -1
  3. package/dist/agent/directTools.d.ts +9 -17
  4. package/dist/agent/directTools.js +12 -8
  5. package/dist/autoresearch/tools.d.ts +2 -214
  6. package/dist/autoresearch/tools.js +1 -1
  7. package/dist/browser/neurolink.min.js +362 -368
  8. package/dist/client/reactHooks.js +16 -8
  9. package/dist/client/reactHooks.tsx +24 -9
  10. package/dist/core/baseProvider.d.ts +1 -6
  11. package/dist/core/baseProvider.js +1 -1
  12. package/dist/core/constants.d.ts +1 -0
  13. package/dist/core/constants.js +3 -0
  14. package/dist/core/modules/GenerationHandler.d.ts +2 -2
  15. package/dist/core/modules/GenerationHandler.js +3 -1
  16. package/dist/core/modules/MessageBuilder.d.ts +1 -15
  17. package/dist/core/modules/MessageBuilder.js +0 -14
  18. package/dist/core/modules/StreamHandler.js +1 -1
  19. package/dist/core/modules/ToolsManager.d.ts +1 -17
  20. package/dist/core/modules/ToolsManager.js +1 -17
  21. package/dist/core/redisConversationMemoryManager.js +0 -6
  22. package/dist/core/streamAnalytics.js +1 -1
  23. package/dist/evaluation/contextBuilder.d.ts +1 -4
  24. package/dist/evaluation/contextBuilder.js +0 -3
  25. package/dist/evaluation/index.d.ts +1 -4
  26. package/dist/evaluation/index.js +0 -3
  27. package/dist/files/fileTools.d.ts +2 -18
  28. package/dist/files/fileTools.js +3 -19
  29. package/dist/lib/adapters/video/videoAnalyzer.d.ts +1 -1
  30. package/dist/lib/agent/directTools.d.ts +9 -17
  31. package/dist/lib/agent/directTools.js +12 -8
  32. package/dist/lib/autoresearch/tools.d.ts +2 -214
  33. package/dist/lib/autoresearch/tools.js +1 -1
  34. package/dist/lib/client/reactHooks.js +16 -8
  35. package/dist/lib/core/baseProvider.d.ts +1 -6
  36. package/dist/lib/core/baseProvider.js +1 -1
  37. package/dist/lib/core/constants.d.ts +1 -0
  38. package/dist/lib/core/constants.js +3 -0
  39. package/dist/lib/core/modules/GenerationHandler.d.ts +2 -2
  40. package/dist/lib/core/modules/GenerationHandler.js +3 -1
  41. package/dist/lib/core/modules/MessageBuilder.d.ts +1 -15
  42. package/dist/lib/core/modules/MessageBuilder.js +0 -14
  43. package/dist/lib/core/modules/StreamHandler.js +1 -1
  44. package/dist/lib/core/modules/ToolsManager.d.ts +1 -17
  45. package/dist/lib/core/modules/ToolsManager.js +1 -17
  46. package/dist/lib/core/redisConversationMemoryManager.js +0 -6
  47. package/dist/lib/core/streamAnalytics.js +1 -1
  48. package/dist/lib/evaluation/contextBuilder.d.ts +1 -4
  49. package/dist/lib/evaluation/contextBuilder.js +0 -3
  50. package/dist/lib/evaluation/index.d.ts +1 -4
  51. package/dist/lib/evaluation/index.js +0 -3
  52. package/dist/lib/files/fileTools.d.ts +2 -18
  53. package/dist/lib/files/fileTools.js +3 -19
  54. package/dist/lib/memory/memoryRetrievalTools.d.ts +2 -126
  55. package/dist/lib/memory/memoryRetrievalTools.js +1 -9
  56. package/dist/lib/middleware/builtin/autoEvaluation.d.ts +0 -3
  57. package/dist/lib/middleware/builtin/autoEvaluation.js +0 -3
  58. package/dist/lib/middleware/builtin/guardrails.js +1 -1
  59. package/dist/lib/middleware/builtin/lifecycle.d.ts +0 -9
  60. package/dist/lib/middleware/builtin/lifecycle.js +0 -9
  61. package/dist/lib/middleware/factory.d.ts +1 -1
  62. package/dist/lib/middleware/factory.js +1 -1
  63. package/dist/lib/middleware/registry.d.ts +1 -1
  64. package/dist/lib/neurolink.d.ts +14 -2
  65. package/dist/lib/neurolink.js +46 -18
  66. package/dist/lib/processors/media/AudioProcessor.js +8 -3
  67. package/dist/lib/providers/amazonBedrock.js +1 -2
  68. package/dist/lib/providers/amazonSagemaker.d.ts +1 -7
  69. package/dist/lib/providers/amazonSagemaker.js +0 -6
  70. package/dist/lib/providers/anthropic.d.ts +1 -1
  71. package/dist/lib/providers/anthropic.js +2 -1
  72. package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
  73. package/dist/lib/providers/anthropicBaseProvider.js +2 -1
  74. package/dist/lib/providers/azureOpenai.d.ts +1 -1
  75. package/dist/lib/providers/azureOpenai.js +2 -1
  76. package/dist/lib/providers/cloudflare.d.ts +1 -1
  77. package/dist/lib/providers/cloudflare.js +2 -1
  78. package/dist/lib/providers/cohere.d.ts +1 -1
  79. package/dist/lib/providers/cohere.js +2 -1
  80. package/dist/lib/providers/deepseek.d.ts +1 -1
  81. package/dist/lib/providers/deepseek.js +2 -1
  82. package/dist/lib/providers/fireworks.d.ts +1 -1
  83. package/dist/lib/providers/fireworks.js +2 -1
  84. package/dist/lib/providers/googleAiStudio.d.ts +1 -1
  85. package/dist/lib/providers/googleAiStudio.js +82 -6
  86. package/dist/lib/providers/googleNativeGemini3.d.ts +3 -6
  87. package/dist/lib/providers/googleNativeGemini3.js +104 -9
  88. package/dist/lib/providers/googleVertex.d.ts +1 -1
  89. package/dist/lib/providers/googleVertex.js +466 -165
  90. package/dist/lib/providers/groq.d.ts +1 -1
  91. package/dist/lib/providers/groq.js +2 -1
  92. package/dist/lib/providers/huggingFace.d.ts +1 -1
  93. package/dist/lib/providers/huggingFace.js +3 -1
  94. package/dist/lib/providers/ideogram.d.ts +1 -1
  95. package/dist/lib/providers/jina.d.ts +1 -1
  96. package/dist/lib/providers/litellm.d.ts +1 -1
  97. package/dist/lib/providers/litellm.js +12 -6
  98. package/dist/lib/providers/llamaCpp.d.ts +1 -1
  99. package/dist/lib/providers/llamaCpp.js +2 -1
  100. package/dist/lib/providers/lmStudio.d.ts +1 -1
  101. package/dist/lib/providers/lmStudio.js +2 -1
  102. package/dist/lib/providers/mistral.d.ts +1 -1
  103. package/dist/lib/providers/mistral.js +2 -1
  104. package/dist/lib/providers/nvidiaNim.d.ts +1 -1
  105. package/dist/lib/providers/nvidiaNim.js +2 -1
  106. package/dist/lib/providers/ollama.d.ts +1 -1
  107. package/dist/lib/providers/ollama.js +1 -2
  108. package/dist/lib/providers/openAI.d.ts +1 -1
  109. package/dist/lib/providers/openAI.js +3 -1
  110. package/dist/lib/providers/openRouter.d.ts +1 -1
  111. package/dist/lib/providers/openRouter.js +3 -1
  112. package/dist/lib/providers/openaiCompatible.d.ts +1 -1
  113. package/dist/lib/providers/openaiCompatible.js +3 -1
  114. package/dist/lib/providers/perplexity.d.ts +1 -1
  115. package/dist/lib/providers/perplexity.js +2 -1
  116. package/dist/lib/providers/providerTypeUtils.d.ts +2 -7
  117. package/dist/lib/providers/providerTypeUtils.js +0 -6
  118. package/dist/lib/providers/recraft.d.ts +1 -1
  119. package/dist/lib/providers/replicate.d.ts +1 -1
  120. package/dist/lib/providers/stability.d.ts +1 -1
  121. package/dist/lib/providers/togetherAi.d.ts +1 -1
  122. package/dist/lib/providers/togetherAi.js +2 -1
  123. package/dist/lib/providers/voyage.d.ts +1 -1
  124. package/dist/lib/providers/xai.d.ts +1 -1
  125. package/dist/lib/providers/xai.js +2 -1
  126. package/dist/lib/proxy/claudeFormat.d.ts +0 -15
  127. package/dist/lib/proxy/claudeFormat.js +1 -11
  128. package/dist/lib/rag/ragIntegration.d.ts +1 -12
  129. package/dist/lib/rag/ragIntegration.js +0 -8
  130. package/dist/lib/tasks/tools/taskTools.d.ts +2 -117
  131. package/dist/lib/tasks/tools/taskTools.js +1 -10
  132. package/dist/lib/types/aliases.d.ts +1 -1
  133. package/dist/lib/types/conversation.d.ts +17 -0
  134. package/dist/lib/types/evaluation.d.ts +1 -5
  135. package/dist/lib/types/evaluation.js +0 -4
  136. package/dist/lib/types/generate.d.ts +2 -22
  137. package/dist/lib/types/guardrails.d.ts +1 -1
  138. package/dist/lib/types/middleware.d.ts +8 -3
  139. package/dist/lib/types/providers.d.ts +2 -1
  140. package/dist/lib/types/rag.d.ts +1 -1
  141. package/dist/lib/types/rag.js +0 -6
  142. package/dist/lib/types/stream.d.ts +2 -11
  143. package/dist/lib/types/tools.d.ts +2 -1
  144. package/dist/lib/utils/generation.d.ts +8 -0
  145. package/dist/lib/utils/generation.js +9 -0
  146. package/dist/lib/utils/generationErrors.d.ts +10 -0
  147. package/dist/lib/utils/generationErrors.js +11 -0
  148. package/dist/lib/utils/messageBuilder.d.ts +1 -6
  149. package/dist/lib/utils/messageBuilder.js +0 -5
  150. package/dist/lib/utils/noOutputSentinel.d.ts +0 -13
  151. package/dist/lib/utils/noOutputSentinel.js +1 -14
  152. package/dist/lib/utils/providerRetry.js +1 -1
  153. package/dist/lib/utils/tool.d.ts +8 -0
  154. package/dist/lib/utils/tool.js +9 -0
  155. package/dist/lib/utils/toolCallRepair.d.ts +1 -16
  156. package/dist/lib/utils/toolCallRepair.js +1 -16
  157. package/dist/lib/utils/toolChoice.d.ts +1 -1
  158. package/dist/lib/utils/videoAnalysisProcessor.d.ts +1 -8
  159. package/dist/lib/utils/videoAnalysisProcessor.js +0 -7
  160. package/dist/memory/memoryRetrievalTools.d.ts +2 -126
  161. package/dist/memory/memoryRetrievalTools.js +1 -9
  162. package/dist/middleware/builtin/autoEvaluation.d.ts +0 -3
  163. package/dist/middleware/builtin/autoEvaluation.js +0 -3
  164. package/dist/middleware/builtin/guardrails.js +1 -1
  165. package/dist/middleware/builtin/lifecycle.d.ts +0 -9
  166. package/dist/middleware/builtin/lifecycle.js +0 -9
  167. package/dist/middleware/factory.d.ts +1 -1
  168. package/dist/middleware/factory.js +1 -1
  169. package/dist/middleware/registry.d.ts +1 -1
  170. package/dist/neurolink.d.ts +14 -2
  171. package/dist/neurolink.js +46 -18
  172. package/dist/processors/media/AudioProcessor.js +8 -3
  173. package/dist/providers/amazonBedrock.js +1 -2
  174. package/dist/providers/amazonSagemaker.d.ts +1 -7
  175. package/dist/providers/amazonSagemaker.js +0 -6
  176. package/dist/providers/anthropic.d.ts +1 -1
  177. package/dist/providers/anthropic.js +2 -1
  178. package/dist/providers/anthropicBaseProvider.d.ts +1 -1
  179. package/dist/providers/anthropicBaseProvider.js +2 -1
  180. package/dist/providers/azureOpenai.d.ts +1 -1
  181. package/dist/providers/azureOpenai.js +2 -1
  182. package/dist/providers/cloudflare.d.ts +1 -1
  183. package/dist/providers/cloudflare.js +2 -1
  184. package/dist/providers/cohere.d.ts +1 -1
  185. package/dist/providers/cohere.js +2 -1
  186. package/dist/providers/deepseek.d.ts +1 -1
  187. package/dist/providers/deepseek.js +2 -1
  188. package/dist/providers/fireworks.d.ts +1 -1
  189. package/dist/providers/fireworks.js +2 -1
  190. package/dist/providers/googleAiStudio.d.ts +1 -1
  191. package/dist/providers/googleAiStudio.js +82 -5
  192. package/dist/providers/googleNativeGemini3.d.ts +3 -6
  193. package/dist/providers/googleNativeGemini3.js +104 -9
  194. package/dist/providers/googleVertex.d.ts +1 -1
  195. package/dist/providers/googleVertex.js +466 -164
  196. package/dist/providers/groq.d.ts +1 -1
  197. package/dist/providers/groq.js +2 -1
  198. package/dist/providers/huggingFace.d.ts +1 -1
  199. package/dist/providers/huggingFace.js +3 -1
  200. package/dist/providers/ideogram.d.ts +1 -1
  201. package/dist/providers/jina.d.ts +1 -1
  202. package/dist/providers/litellm.d.ts +1 -1
  203. package/dist/providers/litellm.js +12 -6
  204. package/dist/providers/llamaCpp.d.ts +1 -1
  205. package/dist/providers/llamaCpp.js +2 -1
  206. package/dist/providers/lmStudio.d.ts +1 -1
  207. package/dist/providers/lmStudio.js +2 -1
  208. package/dist/providers/mistral.d.ts +1 -1
  209. package/dist/providers/mistral.js +2 -1
  210. package/dist/providers/nvidiaNim.d.ts +1 -1
  211. package/dist/providers/nvidiaNim.js +2 -1
  212. package/dist/providers/ollama.d.ts +1 -1
  213. package/dist/providers/ollama.js +1 -2
  214. package/dist/providers/openAI.d.ts +1 -1
  215. package/dist/providers/openAI.js +3 -1
  216. package/dist/providers/openRouter.d.ts +1 -1
  217. package/dist/providers/openRouter.js +3 -1
  218. package/dist/providers/openaiCompatible.d.ts +1 -1
  219. package/dist/providers/openaiCompatible.js +3 -1
  220. package/dist/providers/perplexity.d.ts +1 -1
  221. package/dist/providers/perplexity.js +2 -1
  222. package/dist/providers/providerTypeUtils.d.ts +2 -7
  223. package/dist/providers/providerTypeUtils.js +0 -6
  224. package/dist/providers/recraft.d.ts +1 -1
  225. package/dist/providers/replicate.d.ts +1 -1
  226. package/dist/providers/stability.d.ts +1 -1
  227. package/dist/providers/togetherAi.d.ts +1 -1
  228. package/dist/providers/togetherAi.js +2 -1
  229. package/dist/providers/voyage.d.ts +1 -1
  230. package/dist/providers/xai.d.ts +1 -1
  231. package/dist/providers/xai.js +2 -1
  232. package/dist/proxy/claudeFormat.d.ts +0 -15
  233. package/dist/proxy/claudeFormat.js +1 -11
  234. package/dist/rag/ragIntegration.d.ts +1 -12
  235. package/dist/rag/ragIntegration.js +0 -8
  236. package/dist/tasks/tools/taskTools.d.ts +2 -117
  237. package/dist/tasks/tools/taskTools.js +1 -10
  238. package/dist/types/aliases.d.ts +1 -1
  239. package/dist/types/conversation.d.ts +17 -0
  240. package/dist/types/evaluation.d.ts +1 -5
  241. package/dist/types/evaluation.js +0 -4
  242. package/dist/types/generate.d.ts +2 -22
  243. package/dist/types/guardrails.d.ts +1 -1
  244. package/dist/types/middleware.d.ts +8 -3
  245. package/dist/types/providers.d.ts +2 -1
  246. package/dist/types/rag.d.ts +1 -1
  247. package/dist/types/rag.js +0 -6
  248. package/dist/types/stream.d.ts +2 -11
  249. package/dist/types/tools.d.ts +2 -1
  250. package/dist/utils/generation.d.ts +8 -0
  251. package/dist/utils/generation.js +8 -0
  252. package/dist/utils/generationErrors.d.ts +10 -0
  253. package/dist/utils/generationErrors.js +10 -0
  254. package/dist/utils/messageBuilder.d.ts +1 -6
  255. package/dist/utils/messageBuilder.js +0 -5
  256. package/dist/utils/noOutputSentinel.d.ts +0 -13
  257. package/dist/utils/noOutputSentinel.js +1 -14
  258. package/dist/utils/providerRetry.js +1 -1
  259. package/dist/utils/tool.d.ts +8 -0
  260. package/dist/utils/tool.js +8 -0
  261. package/dist/utils/toolCallRepair.d.ts +1 -16
  262. package/dist/utils/toolCallRepair.js +1 -16
  263. package/dist/utils/toolChoice.d.ts +1 -1
  264. package/dist/utils/videoAnalysisProcessor.d.ts +1 -8
  265. package/dist/utils/videoAnalysisProcessor.js +0 -7
  266. package/package.json +2 -3
@@ -254,8 +254,9 @@ export function useChat(options = {}) {
254
254
  */
255
255
  const handleSubmit = useCallback((e, submitOptions) => {
256
256
  e?.preventDefault?.();
257
- if (!input.trim())
257
+ if (!input.trim()) {
258
258
  return;
259
+ }
259
260
  const message = {
260
261
  role: "user",
261
262
  content: input,
@@ -271,8 +272,9 @@ export function useChat(options = {}) {
271
272
  // Read from the ref so we always have the latest messages
272
273
  const currentMessages = messagesRef.current;
273
274
  const lastUserMessageIndex = currentMessages.findLastIndex((m) => m.role === "user");
274
- if (lastUserMessageIndex === -1)
275
+ if (lastUserMessageIndex === -1) {
275
276
  return null;
277
+ }
276
278
  const lastUserMessage = currentMessages[lastUserMessageIndex];
277
279
  // Remove messages after the last user message
278
280
  setMessages((prev) => prev.slice(0, lastUserMessageIndex));
@@ -742,8 +744,9 @@ export function useVoice(options = {}) {
742
744
  const synthesisRef = useRef(null);
743
745
  // Check browser support
744
746
  const isSupported = useMemo(() => {
745
- if (typeof window === "undefined")
747
+ if (typeof window === "undefined") {
746
748
  return false;
749
+ }
747
750
  const hasSpeechRecognition = "SpeechRecognition" in window || "webkitSpeechRecognition" in window;
748
751
  const hasSpeechSynthesis = "speechSynthesis" in window;
749
752
  return hasSpeechRecognition || hasSpeechSynthesis;
@@ -752,12 +755,14 @@ export function useVoice(options = {}) {
752
755
  * Initialize speech recognition
753
756
  */
754
757
  const initRecognition = useCallback(() => {
755
- if (typeof window === "undefined")
758
+ if (typeof window === "undefined") {
756
759
  return null;
760
+ }
757
761
  const SpeechRecognitionCtor = window.SpeechRecognition ||
758
762
  window.webkitSpeechRecognition;
759
- if (!SpeechRecognitionCtor)
763
+ if (!SpeechRecognitionCtor) {
760
764
  return null;
765
+ }
761
766
  const recognition = new SpeechRecognitionCtor();
762
767
  recognition.continuous = true;
763
768
  recognition.interimResults = true;
@@ -795,8 +800,9 @@ export function useVoice(options = {}) {
795
800
  * Start listening for voice input
796
801
  */
797
802
  const startListening = useCallback(() => {
798
- if (!enableSpeechRecognition)
803
+ if (!enableSpeechRecognition) {
799
804
  return;
805
+ }
800
806
  if (!recognitionRef.current) {
801
807
  recognitionRef.current = initRecognition();
802
808
  }
@@ -820,8 +826,9 @@ export function useVoice(options = {}) {
820
826
  * Speak text using TTS
821
827
  */
822
828
  const speak = useCallback(async (text) => {
823
- if (typeof window === "undefined")
829
+ if (typeof window === "undefined") {
824
830
  return;
831
+ }
825
832
  setIsSpeaking(true);
826
833
  onSpeechStart?.();
827
834
  try {
@@ -1002,8 +1009,9 @@ export function useStream(options = {}) {
1002
1009
  let fullText = "";
1003
1010
  while (true) {
1004
1011
  const { done, value } = await reader.read();
1005
- if (done)
1012
+ if (done) {
1006
1013
  break;
1014
+ }
1007
1015
  buffer += decoder.decode(value, { stream: true });
1008
1016
  const lines = buffer.split("\n");
1009
1017
  buffer = lines.pop() ?? "";
@@ -27,7 +27,6 @@ import {
27
27
  import type { ReactNode } from "react";
28
28
 
29
29
  import type {
30
- ClientConfig,
31
30
  ClientApiError,
32
31
  NeuroLinkProviderProps,
33
32
  UseChatOptions,
@@ -361,7 +360,9 @@ export function useChat(options: UseChatOptions = {}): UseChatReturn {
361
360
  ) => {
362
361
  e?.preventDefault?.();
363
362
 
364
- if (!input.trim()) return;
363
+ if (!input.trim()) {
364
+ return;
365
+ }
365
366
 
366
367
  const message: Omit<ChatMessage, "id" | "createdAt"> = {
367
368
  role: "user",
@@ -384,7 +385,9 @@ export function useChat(options: UseChatOptions = {}): UseChatReturn {
384
385
  const lastUserMessageIndex = currentMessages.findLastIndex(
385
386
  (m: ChatMessage) => m.role === "user",
386
387
  );
387
- if (lastUserMessageIndex === -1) return null;
388
+ if (lastUserMessageIndex === -1) {
389
+ return null;
390
+ }
388
391
 
389
392
  const lastUserMessage = currentMessages[lastUserMessageIndex];
390
393
 
@@ -977,7 +980,9 @@ export function useVoice(options: UseVoiceOptions = {}): UseVoiceReturn {
977
980
 
978
981
  // Check browser support
979
982
  const isSupported = useMemo(() => {
980
- if (typeof window === "undefined") return false;
983
+ if (typeof window === "undefined") {
984
+ return false;
985
+ }
981
986
  const hasSpeechRecognition =
982
987
  "SpeechRecognition" in window || "webkitSpeechRecognition" in window;
983
988
  const hasSpeechSynthesis = "speechSynthesis" in window;
@@ -988,7 +993,9 @@ export function useVoice(options: UseVoiceOptions = {}): UseVoiceReturn {
988
993
  * Initialize speech recognition
989
994
  */
990
995
  const initRecognition = useCallback(() => {
991
- if (typeof window === "undefined") return null;
996
+ if (typeof window === "undefined") {
997
+ return null;
998
+ }
992
999
 
993
1000
  const SpeechRecognitionCtor =
994
1001
  (
@@ -1002,7 +1009,9 @@ export function useVoice(options: UseVoiceOptions = {}): UseVoiceReturn {
1002
1009
  }
1003
1010
  ).webkitSpeechRecognition;
1004
1011
 
1005
- if (!SpeechRecognitionCtor) return null;
1012
+ if (!SpeechRecognitionCtor) {
1013
+ return null;
1014
+ }
1006
1015
 
1007
1016
  const recognition = new SpeechRecognitionCtor();
1008
1017
  recognition.continuous = true;
@@ -1047,7 +1056,9 @@ export function useVoice(options: UseVoiceOptions = {}): UseVoiceReturn {
1047
1056
  * Start listening for voice input
1048
1057
  */
1049
1058
  const startListening = useCallback(() => {
1050
- if (!enableSpeechRecognition) return;
1059
+ if (!enableSpeechRecognition) {
1060
+ return;
1061
+ }
1051
1062
 
1052
1063
  if (!recognitionRef.current) {
1053
1064
  recognitionRef.current = initRecognition();
@@ -1076,7 +1087,9 @@ export function useVoice(options: UseVoiceOptions = {}): UseVoiceReturn {
1076
1087
  */
1077
1088
  const speak = useCallback(
1078
1089
  async (text: string): Promise<void> => {
1079
- if (typeof window === "undefined") return;
1090
+ if (typeof window === "undefined") {
1091
+ return;
1092
+ }
1080
1093
 
1081
1094
  setIsSpeaking(true);
1082
1095
  onSpeechStart?.();
@@ -1286,7 +1299,9 @@ export function useStream(options: UseStreamOptions = {}): UseStreamReturn {
1286
1299
 
1287
1300
  while (true) {
1288
1301
  const { done, value } = await reader.read();
1289
- if (done) break;
1302
+ if (done) {
1303
+ break;
1304
+ }
1290
1305
 
1291
1306
  buffer += decoder.decode(value, { stream: true });
1292
1307
  const lines = buffer.split("\n");
@@ -1,9 +1,9 @@
1
- import type { LanguageModel, ModelMessage, Tool, ToolCallRepairFunction, ToolSet } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import type { EvaluationData } from "../index.js";
4
3
  import type { NeuroLink } from "../neurolink.js";
5
4
  import type { UnknownRecord, MiddlewareFactoryOptions, StreamOptions, StreamResult, AIProvider, AnalyticsData, EnhancedGenerateResult, TextGenerationOptions, TextGenerationResult, ValidationSchema } from "../types/index.js";
6
5
  import { TelemetryHandler } from "./modules/TelemetryHandler.js";
6
+ import type { LanguageModel, ModelMessage, Tool, ToolCallRepairFunction, ToolSet } from "../types/index.js";
7
7
  /**
8
8
  * Abstract base class for all AI providers
9
9
  * Tools are integrated as first-class citizens - always available by default
@@ -20,11 +20,6 @@ export declare abstract class BaseProvider implements AIProvider {
20
20
  protected sessionId?: string;
21
21
  protected userId?: string;
22
22
  protected neurolink?: NeuroLink;
23
- /** @internal Trace context propagated from NeuroLink SDK for span hierarchy */
24
- protected _traceContext: {
25
- traceId: string;
26
- parentSpanId: string;
27
- } | null;
28
23
  setTraceContext(ctx: {
29
24
  traceId: string;
30
25
  parentSpanId: string;
@@ -1,5 +1,4 @@
1
1
  import { context, SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
2
- import { generateText } from "ai";
3
2
  import { directAgentTools } from "../agent/directTools.js";
4
3
  import { IMAGE_GENERATION_MODELS } from "../core/constants.js";
5
4
  import { MiddlewareFactory } from "../middleware/factory.js";
@@ -21,6 +20,7 @@ import { StreamHandler } from "./modules/StreamHandler.js";
21
20
  import { TelemetryHandler } from "./modules/TelemetryHandler.js";
22
21
  import { ToolsManager } from "./modules/ToolsManager.js";
23
22
  import { Utilities } from "./modules/Utilities.js";
23
+ import { generateText } from "../utils/generation.js";
24
24
  /**
25
25
  * Abstract base class for all AI providers
26
26
  * Tools are integrated as first-class citizens - always available by default
@@ -21,6 +21,7 @@ export declare const DEFAULT_TEMPERATURE = 0.7;
21
21
  export declare const DEFAULT_TIMEOUT = 60000;
22
22
  export declare const DEFAULT_MAX_STEPS = 200;
23
23
  export declare const DEFAULT_TOOL_MAX_RETRIES = 2;
24
+ export declare const TOOL_STORAGE_TIMEOUT_MS = 5000;
24
25
  export declare const STEP_LIMITS: {
25
26
  min: number;
26
27
  max: number;
@@ -107,6 +107,9 @@ export const DEFAULT_TEMPERATURE = 0.7;
107
107
  export const DEFAULT_TIMEOUT = 60000;
108
108
  export const DEFAULT_MAX_STEPS = 200;
109
109
  export const DEFAULT_TOOL_MAX_RETRIES = 2; // Maximum retries per tool before permanently failing
110
+ // Fire-and-forget tool storage writes (Redis). 5s is generous for a single
111
+ // Redis write; if breached, the .catch logs a warning.
112
+ export const TOOL_STORAGE_TIMEOUT_MS = 5000;
110
113
  // Step execution limits
111
114
  export const STEP_LIMITS = {
112
115
  min: 1,
@@ -12,9 +12,9 @@
12
12
  *
13
13
  * @module core/modules/GenerationHandler
14
14
  */
15
- import type { LanguageModel, ModelMessage, Tool } from "ai";
16
- import { generateText } from "ai";
17
15
  import type { AIProviderName, EnhancedGenerateResult, NeuroLinkEvents, StandardRecord, TextGenerationOptions, TypedEventEmitter } from "../../types/index.js";
16
+ import type { LanguageModel, ModelMessage, Tool } from "../../types/index.js";
17
+ import { generateText } from "../../utils/generation.js";
18
18
  /**
19
19
  * GenerationHandler class - Handles text generation operations for AI providers
20
20
  */
@@ -13,7 +13,6 @@
13
13
  * @module core/modules/GenerationHandler
14
14
  */
15
15
  import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
16
- import { generateText, NoObjectGeneratedError, Output, stepCountIs } from "ai";
17
16
  import { getModelId } from "../../providers/providerTypeUtils.js";
18
17
  import { tracers } from "../../telemetry/tracers.js";
19
18
  import { logger } from "../../utils/logger.js";
@@ -22,6 +21,9 @@ import { calculateCost } from "../../utils/pricing.js";
22
21
  import { withProviderRetry } from "../../utils/providerRetry.js";
23
22
  import { calculateCacheSavingsPercent, extractCacheCreationTokens, extractCacheReadTokens, extractTokenUsage, } from "../../utils/tokenUtils.js";
24
23
  import { DEFAULT_MAX_STEPS } from "../constants.js";
24
+ import { NoObjectGeneratedError } from "../../utils/generationErrors.js";
25
+ import { Output, stepCountIs } from "../../utils/tool.js";
26
+ import { generateText } from "../../utils/generation.js";
25
27
  const genTracer = tracers.generation;
26
28
  /**
27
29
  * Safely preview-serialize a value for debug logging.
@@ -1,19 +1,5 @@
1
- /**
2
- * Message Builder Module
3
- *
4
- * Handles all message construction logic for AI providers.
5
- * Extracted from BaseProvider to follow Single Responsibility Principle.
6
- *
7
- * Responsibilities:
8
- * - Building messages from text generation options
9
- * - Building messages from stream options
10
- * - Multimodal input detection
11
- * - Message format conversion (to ModelMessage[])
12
- *
13
- * @module core/modules/MessageBuilder
14
- */
15
- import type { ModelMessage } from "ai";
16
1
  import type { AIProviderName, TextGenerationOptions, StreamOptions } from "../../types/index.js";
2
+ import type { ModelMessage } from "../../types/index.js";
17
3
  /**
18
4
  * MessageBuilder class - Handles message construction for AI providers
19
5
  */
@@ -1,17 +1,3 @@
1
- /**
2
- * Message Builder Module
3
- *
4
- * Handles all message construction logic for AI providers.
5
- * Extracted from BaseProvider to follow Single Responsibility Principle.
6
- *
7
- * Responsibilities:
8
- * - Building messages from text generation options
9
- * - Building messages from stream options
10
- * - Multimodal input detection
11
- * - Message format conversion (to ModelMessage[])
12
- *
13
- * @module core/modules/MessageBuilder
14
- */
15
1
  import { tracers, ATTR, withSpan } from "../../telemetry/index.js";
16
2
  import { logger } from "../../utils/logger.js";
17
3
  import { buildMessagesArray, buildMultimodalMessagesArray, } from "../../utils/messageBuilder.js";
@@ -20,7 +20,7 @@ import { buildNoOutputSentinel, detectPostStreamNoOutput, stampNoOutputSpan, } f
20
20
  import { STEP_LIMITS } from "../constants.js";
21
21
  import { createAnalytics } from "../analytics.js";
22
22
  import { nanoid } from "nanoid";
23
- import { NoOutputGeneratedError } from "ai";
23
+ import { NoOutputGeneratedError } from "../../utils/generationErrors.js";
24
24
  /**
25
25
  * StreamHandler class - Handles streaming operations for AI providers
26
26
  */
@@ -1,22 +1,6 @@
1
- /**
2
- * Tools Manager Module
3
- *
4
- * Handles all tool registration, discovery, and execution for AI providers.
5
- * Extracted from BaseProvider to follow Single Responsibility Principle.
6
- *
7
- * Responsibilities:
8
- * - Tool registration (direct, custom, MCP, external MCP)
9
- * - Tool discovery and aggregation
10
- * - Tool creation from definitions and schemas
11
- * - Tool executor setup
12
- * - Session context management for MCP tools
13
- * - Event emission wrapping for tool execution
14
- *
15
- * @module core/modules/ToolsManager
16
- */
17
- import type { Tool } from "ai";
18
1
  import type { AIProviderName, ToolUtilities } from "../../types/index.js";
19
2
  import type { NeuroLink } from "../../neurolink.js";
3
+ import type { Tool } from "../../types/index.js";
20
4
  /**
21
5
  * ToolsManager class - Handles all tool management operations
22
6
  */
@@ -1,20 +1,3 @@
1
- /**
2
- * Tools Manager Module
3
- *
4
- * Handles all tool registration, discovery, and execution for AI providers.
5
- * Extracted from BaseProvider to follow Single Responsibility Principle.
6
- *
7
- * Responsibilities:
8
- * - Tool registration (direct, custom, MCP, external MCP)
9
- * - Tool discovery and aggregation
10
- * - Tool creation from definitions and schemas
11
- * - Tool executor setup
12
- * - Session context management for MCP tools
13
- * - Event emission wrapping for tool execution
14
- *
15
- * @module core/modules/ToolsManager
16
- */
17
- import { tool as createAISDKTool, jsonSchema } from "ai";
18
1
  import { z } from "zod";
19
2
  import { createToolEventPayload } from "../toolEvents.js";
20
3
  import { tracers, ATTR, withSpan } from "../../telemetry/index.js";
@@ -23,6 +6,7 @@ import { logger } from "../../utils/logger.js";
23
6
  import { getKeyCount } from "../../utils/transformationUtils.js";
24
7
  import { convertJsonSchemaToZod } from "../../utils/schemaConversion.js";
25
8
  import { generateToolOutputPreview } from "../../context/toolOutputLimits.js";
9
+ import { tool as createAISDKTool, jsonSchema } from "../../utils/tool.js";
26
10
  /**
27
11
  * ToolsManager class - Handles all tool management operations
28
12
  */
@@ -951,12 +951,6 @@ User message: "${userMessage}"`;
951
951
  provider: this.config.summarizationProvider || "vertex",
952
952
  model: this.config.summarizationModel || "gemini-2.5-flash",
953
953
  disableTools: true, // Title generation doesn't need tools — saves ~600 tokens of tool descriptions
954
- // A 20-25 letter title is well under 64 tokens; capping prevents
955
- // Vertex 400 INVALID_ARGUMENT — Gemini 2.5 Flash on the native
956
- // @google/genai SDK rejects requests with no maxOutputTokens cap
957
- // when the prompt is short, which silently broke every
958
- // `conversationMemory.enabled + context` test path.
959
- maxTokens: 64,
960
954
  });
961
955
  // Clean up the generated title
962
956
  let title = result.content?.trim() || "New Conversation";
@@ -1,7 +1,7 @@
1
1
  import { createAnalytics } from "./analytics.js";
2
2
  import { logger } from "../utils/logger.js";
3
3
  import { extractTokenUsage, createEmptyTokenUsage, } from "../utils/tokenUtils.js";
4
- import { NoOutputGeneratedError } from "ai";
4
+ import { NoOutputGeneratedError } from "../utils/generationErrors.js";
5
5
  /**
6
6
  * Base implementation for collecting analytics from Vercel AI SDK stream results
7
7
  */
@@ -1,8 +1,5 @@
1
- /**
2
- * @file Implements the ContextBuilder class for creating rich evaluation context.
3
- */
4
- import type { LanguageModelV3CallOptions } from "@ai-sdk/provider";
5
1
  import type { EnhancedEvaluationContext, EvaluationResult, GenerateResult } from "../types/index.js";
2
+ import type { LanguageModelV3CallOptions } from "../types/index.js";
6
3
  /**
7
4
  * Builds the enhanced context required for a RAGAS-style evaluation.
8
5
  * This class gathers data from the generation options and results to create a
@@ -1,6 +1,3 @@
1
- /**
2
- * @file Implements the ContextBuilder class for creating rich evaluation context.
3
- */
4
1
  import { logger } from "../utils/logger.js";
5
2
  /**
6
3
  * Builds the enhanced context required for a RAGAS-style evaluation.
@@ -1,8 +1,5 @@
1
- /**
2
- * @file This file exports the main Evaluator class, which serves as the central entry point for the evaluation system.
3
- */
4
- import type { LanguageModelV3CallOptions } from "@ai-sdk/provider";
5
1
  import type { EvaluationData, GenerateResult, AutoEvaluationConfig, EvaluationConfig } from "../types/index.js";
2
+ import type { LanguageModelV3CallOptions } from "../types/index.js";
6
3
  export * from "./errors/index.js";
7
4
  export * from "./hooks/index.js";
8
5
  export * from "./pipeline/index.js";
@@ -1,6 +1,3 @@
1
- /**
2
- * @file This file exports the main Evaluator class, which serves as the central entry point for the evaluation system.
3
- */
4
1
  import { ContextBuilder } from "./contextBuilder.js";
5
2
  import { RAGASEvaluator } from "./ragasEvaluator.js";
6
3
  import { mapToEvaluationData } from "./scoring.js";
@@ -1,27 +1,11 @@
1
- /**
2
- * On-Demand File Access Tools
3
- *
4
- * Exposes file operations as LLM tools via the Vercel AI SDK `tool()` pattern.
5
- * These tools allow the LLM to access file content lazily — only reading
6
- * the specific sections, lines, or search results it needs.
7
- *
8
- * Tools:
9
- * - list_attached_files: List all registered files with metadata
10
- * - read_file_section: Read specific line range with token budget
11
- * - search_in_file: Search for patterns within a file
12
- * - get_file_preview: Get the preview/summary of a file
13
- * - extract_file_content: Targeted extraction for any file type (video frames,
14
- * PDF pages, spreadsheet ranges, archive entries, PPTX slides)
15
- *
16
- * @module files/fileTools
17
- */
18
1
  import type { FileReferenceRegistry } from "./fileReferenceRegistry.js";
19
2
  /**
20
3
  * Create file access tools bound to a FileReferenceRegistry instance.
21
4
  *
22
5
  * These tools follow the same pattern as the existing directAgentTools
23
6
  * (getCurrentTime, readFile, etc.) in src/lib/agent/directTools.ts.
24
- * They use `tool()` from the Vercel AI SDK with zod parameter schemas.
7
+ * They use NeuroLink's `tool()` helper from `../utils/tool.js` with Zod
8
+ * parameter schemas.
25
9
  *
26
10
  * @param registry - The FileReferenceRegistry instance to bind to
27
11
  * @returns Record of tool name to tool definition
@@ -1,28 +1,12 @@
1
- /**
2
- * On-Demand File Access Tools
3
- *
4
- * Exposes file operations as LLM tools via the Vercel AI SDK `tool()` pattern.
5
- * These tools allow the LLM to access file content lazily — only reading
6
- * the specific sections, lines, or search results it needs.
7
- *
8
- * Tools:
9
- * - list_attached_files: List all registered files with metadata
10
- * - read_file_section: Read specific line range with token budget
11
- * - search_in_file: Search for patterns within a file
12
- * - get_file_preview: Get the preview/summary of a file
13
- * - extract_file_content: Targeted extraction for any file type (video frames,
14
- * PDF pages, spreadsheet ranges, archive entries, PPTX slides)
15
- *
16
- * @module files/fileTools
17
- */
18
- import { tool } from "ai";
19
1
  import { z } from "zod";
2
+ import { tool } from "../utils/tool.js";
20
3
  /**
21
4
  * Create file access tools bound to a FileReferenceRegistry instance.
22
5
  *
23
6
  * These tools follow the same pattern as the existing directAgentTools
24
7
  * (getCurrentTime, readFile, etc.) in src/lib/agent/directTools.ts.
25
- * They use `tool()` from the Vercel AI SDK with zod parameter schemas.
8
+ * They use NeuroLink's `tool()` helper from `../utils/tool.js` with Zod
9
+ * parameter schemas.
26
10
  *
27
11
  * @param registry - The FileReferenceRegistry instance to bind to
28
12
  * @returns Record of tool name to tool definition
@@ -7,7 +7,7 @@
7
7
  * @module adapters/video/geminiVideoAnalyzer
8
8
  */
9
9
  import { AIProviderName } from "../../constants/enums.js";
10
- import type { ModelMessage } from "ai";
10
+ import type { ModelMessage } from "../../types/index.js";
11
11
  export declare function analyzeVideoWithVertexAI(messages: ModelMessage[], options?: {
12
12
  project?: string;
13
13
  location?: string;
@@ -1,14 +1,10 @@
1
- /**
2
- * Direct Tool Definitions for NeuroLink CLI Agent
3
- * Simple, reliable tools that work immediately with Vercel AI SDK
4
- */
5
- import type { AllToolsMap, BasicToolsMap, FilesystemToolsMap, UtilityToolsMap } from "../types/index.js";
1
+ import type { AllToolsMap, BasicToolsMap, FilesystemToolsMap, Tool, UtilityToolsMap } from "../types/index.js";
6
2
  /**
7
3
  * Direct tool definitions that work immediately with Gemini/AI SDK
8
4
  * These bypass MCP complexity and provide reliable agent functionality
9
5
  */
10
6
  export declare const directAgentTools: {
11
- getCurrentTime: import("ai").Tool<{
7
+ getCurrentTime: Tool<{
12
8
  timezone?: string | undefined;
13
9
  }, {
14
10
  success: boolean;
@@ -32,7 +28,7 @@ export declare const directAgentTools: {
32
28
  iso?: undefined;
33
29
  timestamp?: undefined;
34
30
  }>;
35
- readFile: import("ai").Tool<{
31
+ readFile: Tool<{
36
32
  path: string;
37
33
  }, {
38
34
  success: boolean;
@@ -56,7 +52,7 @@ export declare const directAgentTools: {
56
52
  size?: undefined;
57
53
  lastModified?: undefined;
58
54
  }>;
59
- listDirectory: import("ai").Tool<{
55
+ listDirectory: Tool<{
60
56
  path: string;
61
57
  includeHidden: boolean;
62
58
  }, {
@@ -77,7 +73,7 @@ export declare const directAgentTools: {
77
73
  items?: undefined;
78
74
  count?: undefined;
79
75
  }>;
80
- calculateMath: import("ai").Tool<{
76
+ calculateMath: Tool<{
81
77
  expression: string;
82
78
  precision: number;
83
79
  }, {
@@ -99,7 +95,7 @@ export declare const directAgentTools: {
99
95
  result?: undefined;
100
96
  type?: undefined;
101
97
  }>;
102
- writeFile: import("ai").Tool<{
98
+ writeFile: Tool<{
103
99
  path: string;
104
100
  content: string;
105
101
  mode: "append" | "create" | "overwrite";
@@ -125,7 +121,7 @@ export declare const directAgentTools: {
125
121
  size?: undefined;
126
122
  written?: undefined;
127
123
  }>;
128
- analyzeCSV: import("ai").Tool<{
124
+ analyzeCSV: Tool<{
129
125
  filePath: string;
130
126
  operation: "count_by_column" | "sum_by_column" | "average_by_column" | "min_max_by_column" | "describe";
131
127
  column: string;
@@ -147,7 +143,7 @@ export declare const directAgentTools: {
147
143
  operation: "count_by_column" | "sum_by_column" | "average_by_column" | "min_max_by_column" | "describe";
148
144
  column: string;
149
145
  }>;
150
- websearchGrounding: import("ai").Tool<{
146
+ websearchGrounding: Tool<{
151
147
  query: string;
152
148
  maxResults: number;
153
149
  maxWords: number;
@@ -221,11 +217,7 @@ export declare const directAgentTools: {
221
217
  * Import this directly when you need bash execution capabilities:
222
218
  * import { bashTool } from '../agent/directTools.js';
223
219
  */
224
- export declare const bashTool: import("ai").Tool<{
225
- command: string;
226
- timeout: number;
227
- cwd?: string | undefined;
228
- }, unknown>;
220
+ export declare const bashTool: Tool;
229
221
  /**
230
222
  * Get a subset of tools for specific use cases with improved type safety
231
223
  */
@@ -1,8 +1,3 @@
1
- /**
2
- * Direct Tool Definitions for NeuroLink CLI Agent
3
- * Simple, reliable tools that work immediately with Vercel AI SDK
4
- */
5
- import { tool } from "ai";
6
1
  import { z } from "zod";
7
2
  import * as fs from "fs";
8
3
  import * as path from "path";
@@ -11,6 +6,7 @@ import { logger } from "../utils/logger.js";
11
6
  import { VertexAI } from "@google-cloud/vertexai";
12
7
  import { CSVProcessor } from "../utils/csvProcessor.js";
13
8
  import { shouldEnableBashTool } from "../utils/toolUtils.js";
9
+ import { tool } from "../utils/tool.js";
14
10
  const MAX_OUTPUT_BYTES = 102400; // 100KB
15
11
  function truncateOutput(output) {
16
12
  if (output.length > MAX_OUTPUT_BYTES) {
@@ -547,9 +543,16 @@ export const directAgentTools = {
547
543
  // It is only included in directAgentTools when NEUROLINK_ENABLE_BASH_TOOL=true or
548
544
  // toolConfig.enableBashTool is explicitly set to true. See shouldEnableBashTool() in toolUtils.ts.
549
545
  websearchGrounding: tool({
550
- description: "Search the web for current information using Google Search grounding. Returns raw search data for AI processing.",
546
+ description: "Performs a Google Search and returns a summarized answer with source citations. Always check the current date before constructing the query. Use whenever the answer depends on time-sensitive facts or requires verification against real-world sources.",
551
547
  inputSchema: z.object({
552
- query: z.string().describe("Search query to find information about"),
548
+ query: z
549
+ .string()
550
+ .trim()
551
+ .min(1, { message: "must be a non-empty search string" })
552
+ .refine((v) => v.toLowerCase() !== "undefined", {
553
+ message: 'must not be the literal string "undefined" — pass a real search query',
554
+ })
555
+ .describe("The search query string to look up on the web."),
553
556
  maxResults: z
554
557
  .number()
555
558
  .optional()
@@ -581,7 +584,8 @@ export const directAgentTools = {
581
584
  project: hasProjectId,
582
585
  location: projectLocation,
583
586
  });
584
- const websearchModel = "gemini-2.5-flash-lite";
587
+ const websearchModel = process.env.NEUROLINK_WEBSEARCH_MODEL?.trim() ||
588
+ "gemini-2.5-flash-lite";
585
589
  const model = vertex_ai.getGenerativeModel({
586
590
  model: websearchModel,
587
591
  tools: createGoogleSearchTools(),