@juspay/neurolink 9.65.1 → 9.66.0

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 (287) 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 +1 -5
  5. package/dist/autoresearch/tools.d.ts +2 -214
  6. package/dist/autoresearch/tools.js +1 -1
  7. package/dist/browser/neurolink.min.js +388 -386
  8. package/dist/cli/commands/proxy.js +154 -5
  9. package/dist/client/reactHooks.js +16 -8
  10. package/dist/client/reactHooks.tsx +24 -9
  11. package/dist/core/baseProvider.d.ts +1 -6
  12. package/dist/core/baseProvider.js +1 -1
  13. package/dist/core/modules/GenerationHandler.d.ts +2 -2
  14. package/dist/core/modules/GenerationHandler.js +3 -1
  15. package/dist/core/modules/MessageBuilder.d.ts +1 -15
  16. package/dist/core/modules/MessageBuilder.js +0 -14
  17. package/dist/core/modules/StreamHandler.js +1 -1
  18. package/dist/core/modules/ToolsManager.d.ts +1 -17
  19. package/dist/core/modules/ToolsManager.js +1 -17
  20. package/dist/core/streamAnalytics.js +1 -1
  21. package/dist/evaluation/contextBuilder.d.ts +1 -4
  22. package/dist/evaluation/contextBuilder.js +0 -3
  23. package/dist/evaluation/index.d.ts +1 -4
  24. package/dist/evaluation/index.js +0 -3
  25. package/dist/files/fileTools.d.ts +2 -18
  26. package/dist/files/fileTools.js +3 -19
  27. package/dist/lib/adapters/video/videoAnalyzer.d.ts +1 -1
  28. package/dist/lib/agent/directTools.d.ts +9 -17
  29. package/dist/lib/agent/directTools.js +1 -5
  30. package/dist/lib/autoresearch/tools.d.ts +2 -214
  31. package/dist/lib/autoresearch/tools.js +1 -1
  32. package/dist/lib/client/reactHooks.js +16 -8
  33. package/dist/lib/core/baseProvider.d.ts +1 -6
  34. package/dist/lib/core/baseProvider.js +1 -1
  35. package/dist/lib/core/modules/GenerationHandler.d.ts +2 -2
  36. package/dist/lib/core/modules/GenerationHandler.js +3 -1
  37. package/dist/lib/core/modules/MessageBuilder.d.ts +1 -15
  38. package/dist/lib/core/modules/MessageBuilder.js +0 -14
  39. package/dist/lib/core/modules/StreamHandler.js +1 -1
  40. package/dist/lib/core/modules/ToolsManager.d.ts +1 -17
  41. package/dist/lib/core/modules/ToolsManager.js +1 -17
  42. package/dist/lib/core/streamAnalytics.js +1 -1
  43. package/dist/lib/evaluation/contextBuilder.d.ts +1 -4
  44. package/dist/lib/evaluation/contextBuilder.js +0 -3
  45. package/dist/lib/evaluation/index.d.ts +1 -4
  46. package/dist/lib/evaluation/index.js +0 -3
  47. package/dist/lib/files/fileTools.d.ts +2 -18
  48. package/dist/lib/files/fileTools.js +3 -19
  49. package/dist/lib/memory/memoryRetrievalTools.d.ts +2 -126
  50. package/dist/lib/memory/memoryRetrievalTools.js +1 -9
  51. package/dist/lib/middleware/builtin/autoEvaluation.d.ts +0 -3
  52. package/dist/lib/middleware/builtin/autoEvaluation.js +0 -3
  53. package/dist/lib/middleware/builtin/guardrails.js +1 -1
  54. package/dist/lib/middleware/builtin/lifecycle.d.ts +0 -9
  55. package/dist/lib/middleware/builtin/lifecycle.js +0 -9
  56. package/dist/lib/middleware/factory.d.ts +1 -1
  57. package/dist/lib/middleware/factory.js +1 -1
  58. package/dist/lib/middleware/registry.d.ts +1 -1
  59. package/dist/lib/neurolink.d.ts +14 -2
  60. package/dist/lib/neurolink.js +46 -18
  61. package/dist/lib/processors/media/AudioProcessor.js +8 -3
  62. package/dist/lib/providers/amazonBedrock.js +1 -2
  63. package/dist/lib/providers/amazonSagemaker.d.ts +1 -7
  64. package/dist/lib/providers/amazonSagemaker.js +0 -6
  65. package/dist/lib/providers/anthropic.d.ts +1 -1
  66. package/dist/lib/providers/anthropic.js +2 -1
  67. package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
  68. package/dist/lib/providers/anthropicBaseProvider.js +2 -1
  69. package/dist/lib/providers/azureOpenai.d.ts +1 -1
  70. package/dist/lib/providers/azureOpenai.js +2 -1
  71. package/dist/lib/providers/cloudflare.d.ts +1 -1
  72. package/dist/lib/providers/cloudflare.js +2 -1
  73. package/dist/lib/providers/cohere.d.ts +1 -1
  74. package/dist/lib/providers/cohere.js +2 -1
  75. package/dist/lib/providers/deepseek.d.ts +1 -1
  76. package/dist/lib/providers/deepseek.js +2 -1
  77. package/dist/lib/providers/fireworks.d.ts +1 -1
  78. package/dist/lib/providers/fireworks.js +2 -1
  79. package/dist/lib/providers/googleAiStudio.d.ts +1 -1
  80. package/dist/lib/providers/googleAiStudio.js +0 -1
  81. package/dist/lib/providers/googleNativeGemini3.d.ts +1 -1
  82. package/dist/lib/providers/googleNativeGemini3.js +1 -1
  83. package/dist/lib/providers/googleVertex.d.ts +1 -1
  84. package/dist/lib/providers/googleVertex.js +0 -1
  85. package/dist/lib/providers/groq.d.ts +1 -1
  86. package/dist/lib/providers/groq.js +2 -1
  87. package/dist/lib/providers/huggingFace.d.ts +1 -1
  88. package/dist/lib/providers/huggingFace.js +3 -1
  89. package/dist/lib/providers/ideogram.d.ts +1 -1
  90. package/dist/lib/providers/jina.d.ts +1 -1
  91. package/dist/lib/providers/litellm.d.ts +1 -1
  92. package/dist/lib/providers/litellm.js +12 -6
  93. package/dist/lib/providers/llamaCpp.d.ts +1 -1
  94. package/dist/lib/providers/llamaCpp.js +2 -1
  95. package/dist/lib/providers/lmStudio.d.ts +1 -1
  96. package/dist/lib/providers/lmStudio.js +2 -1
  97. package/dist/lib/providers/mistral.d.ts +1 -1
  98. package/dist/lib/providers/mistral.js +2 -1
  99. package/dist/lib/providers/nvidiaNim.d.ts +1 -1
  100. package/dist/lib/providers/nvidiaNim.js +2 -1
  101. package/dist/lib/providers/ollama.d.ts +1 -1
  102. package/dist/lib/providers/ollama.js +1 -2
  103. package/dist/lib/providers/openAI.d.ts +1 -1
  104. package/dist/lib/providers/openAI.js +3 -1
  105. package/dist/lib/providers/openRouter.d.ts +1 -1
  106. package/dist/lib/providers/openRouter.js +3 -1
  107. package/dist/lib/providers/openaiCompatible.d.ts +1 -1
  108. package/dist/lib/providers/openaiCompatible.js +3 -1
  109. package/dist/lib/providers/perplexity.d.ts +1 -1
  110. package/dist/lib/providers/perplexity.js +2 -1
  111. package/dist/lib/providers/providerTypeUtils.d.ts +2 -7
  112. package/dist/lib/providers/providerTypeUtils.js +0 -6
  113. package/dist/lib/providers/recraft.d.ts +1 -1
  114. package/dist/lib/providers/replicate.d.ts +1 -1
  115. package/dist/lib/providers/stability.d.ts +1 -1
  116. package/dist/lib/providers/togetherAi.d.ts +1 -1
  117. package/dist/lib/providers/togetherAi.js +2 -1
  118. package/dist/lib/providers/voyage.d.ts +1 -1
  119. package/dist/lib/providers/xai.d.ts +1 -1
  120. package/dist/lib/providers/xai.js +2 -1
  121. package/dist/lib/proxy/claudeFormat.d.ts +0 -15
  122. package/dist/lib/proxy/claudeFormat.js +1 -11
  123. package/dist/lib/proxy/modelRouter.d.ts +5 -1
  124. package/dist/lib/proxy/modelRouter.js +8 -0
  125. package/dist/lib/proxy/openaiFormat.d.ts +137 -0
  126. package/dist/lib/proxy/openaiFormat.js +801 -0
  127. package/dist/lib/proxy/proxyTranslationEngine.d.ts +124 -0
  128. package/dist/lib/proxy/proxyTranslationEngine.js +679 -0
  129. package/dist/lib/rag/ragIntegration.d.ts +1 -12
  130. package/dist/lib/rag/ragIntegration.js +0 -8
  131. package/dist/lib/server/routes/claudeProxyRoutes.d.ts +6 -5
  132. package/dist/lib/server/routes/claudeProxyRoutes.js +22 -355
  133. package/dist/lib/server/routes/index.d.ts +1 -0
  134. package/dist/lib/server/routes/index.js +10 -2
  135. package/dist/lib/server/routes/openaiProxyRoutes.d.ts +30 -0
  136. package/dist/lib/server/routes/openaiProxyRoutes.js +337 -0
  137. package/dist/lib/tasks/tools/taskTools.d.ts +2 -117
  138. package/dist/lib/tasks/tools/taskTools.js +1 -10
  139. package/dist/lib/types/aliases.d.ts +1 -1
  140. package/dist/lib/types/conversation.d.ts +1 -0
  141. package/dist/lib/types/evaluation.d.ts +1 -5
  142. package/dist/lib/types/evaluation.js +0 -4
  143. package/dist/lib/types/generate.d.ts +2 -22
  144. package/dist/lib/types/guardrails.d.ts +1 -1
  145. package/dist/lib/types/middleware.d.ts +8 -3
  146. package/dist/lib/types/providers.d.ts +2 -1
  147. package/dist/lib/types/proxy.d.ts +179 -0
  148. package/dist/lib/types/rag.d.ts +1 -1
  149. package/dist/lib/types/rag.js +0 -6
  150. package/dist/lib/types/server.d.ts +3 -0
  151. package/dist/lib/types/stream.d.ts +2 -11
  152. package/dist/lib/types/tools.d.ts +2 -1
  153. package/dist/lib/utils/generation.d.ts +8 -0
  154. package/dist/lib/utils/generation.js +9 -0
  155. package/dist/lib/utils/generationErrors.d.ts +10 -0
  156. package/dist/lib/utils/generationErrors.js +11 -0
  157. package/dist/lib/utils/messageBuilder.d.ts +1 -6
  158. package/dist/lib/utils/messageBuilder.js +0 -5
  159. package/dist/lib/utils/noOutputSentinel.d.ts +0 -13
  160. package/dist/lib/utils/noOutputSentinel.js +1 -14
  161. package/dist/lib/utils/providerRetry.js +1 -1
  162. package/dist/lib/utils/tool.d.ts +8 -0
  163. package/dist/lib/utils/tool.js +9 -0
  164. package/dist/lib/utils/toolCallRepair.d.ts +1 -16
  165. package/dist/lib/utils/toolCallRepair.js +1 -16
  166. package/dist/lib/utils/toolChoice.d.ts +1 -1
  167. package/dist/lib/utils/videoAnalysisProcessor.d.ts +1 -8
  168. package/dist/lib/utils/videoAnalysisProcessor.js +0 -7
  169. package/dist/memory/memoryRetrievalTools.d.ts +2 -126
  170. package/dist/memory/memoryRetrievalTools.js +1 -9
  171. package/dist/middleware/builtin/autoEvaluation.d.ts +0 -3
  172. package/dist/middleware/builtin/autoEvaluation.js +0 -3
  173. package/dist/middleware/builtin/guardrails.js +1 -1
  174. package/dist/middleware/builtin/lifecycle.d.ts +0 -9
  175. package/dist/middleware/builtin/lifecycle.js +0 -9
  176. package/dist/middleware/factory.d.ts +1 -1
  177. package/dist/middleware/factory.js +1 -1
  178. package/dist/middleware/registry.d.ts +1 -1
  179. package/dist/neurolink.d.ts +14 -2
  180. package/dist/neurolink.js +46 -18
  181. package/dist/processors/media/AudioProcessor.js +8 -3
  182. package/dist/providers/amazonBedrock.js +1 -2
  183. package/dist/providers/amazonSagemaker.d.ts +1 -7
  184. package/dist/providers/amazonSagemaker.js +0 -6
  185. package/dist/providers/anthropic.d.ts +1 -1
  186. package/dist/providers/anthropic.js +2 -1
  187. package/dist/providers/anthropicBaseProvider.d.ts +1 -1
  188. package/dist/providers/anthropicBaseProvider.js +2 -1
  189. package/dist/providers/azureOpenai.d.ts +1 -1
  190. package/dist/providers/azureOpenai.js +2 -1
  191. package/dist/providers/cloudflare.d.ts +1 -1
  192. package/dist/providers/cloudflare.js +2 -1
  193. package/dist/providers/cohere.d.ts +1 -1
  194. package/dist/providers/cohere.js +2 -1
  195. package/dist/providers/deepseek.d.ts +1 -1
  196. package/dist/providers/deepseek.js +2 -1
  197. package/dist/providers/fireworks.d.ts +1 -1
  198. package/dist/providers/fireworks.js +2 -1
  199. package/dist/providers/googleAiStudio.d.ts +1 -1
  200. package/dist/providers/googleNativeGemini3.d.ts +1 -1
  201. package/dist/providers/googleNativeGemini3.js +1 -1
  202. package/dist/providers/googleVertex.d.ts +1 -1
  203. package/dist/providers/groq.d.ts +1 -1
  204. package/dist/providers/groq.js +2 -1
  205. package/dist/providers/huggingFace.d.ts +1 -1
  206. package/dist/providers/huggingFace.js +3 -1
  207. package/dist/providers/ideogram.d.ts +1 -1
  208. package/dist/providers/jina.d.ts +1 -1
  209. package/dist/providers/litellm.d.ts +1 -1
  210. package/dist/providers/litellm.js +12 -6
  211. package/dist/providers/llamaCpp.d.ts +1 -1
  212. package/dist/providers/llamaCpp.js +2 -1
  213. package/dist/providers/lmStudio.d.ts +1 -1
  214. package/dist/providers/lmStudio.js +2 -1
  215. package/dist/providers/mistral.d.ts +1 -1
  216. package/dist/providers/mistral.js +2 -1
  217. package/dist/providers/nvidiaNim.d.ts +1 -1
  218. package/dist/providers/nvidiaNim.js +2 -1
  219. package/dist/providers/ollama.d.ts +1 -1
  220. package/dist/providers/ollama.js +1 -2
  221. package/dist/providers/openAI.d.ts +1 -1
  222. package/dist/providers/openAI.js +3 -1
  223. package/dist/providers/openRouter.d.ts +1 -1
  224. package/dist/providers/openRouter.js +3 -1
  225. package/dist/providers/openaiCompatible.d.ts +1 -1
  226. package/dist/providers/openaiCompatible.js +3 -1
  227. package/dist/providers/perplexity.d.ts +1 -1
  228. package/dist/providers/perplexity.js +2 -1
  229. package/dist/providers/providerTypeUtils.d.ts +2 -7
  230. package/dist/providers/providerTypeUtils.js +0 -6
  231. package/dist/providers/recraft.d.ts +1 -1
  232. package/dist/providers/replicate.d.ts +1 -1
  233. package/dist/providers/stability.d.ts +1 -1
  234. package/dist/providers/togetherAi.d.ts +1 -1
  235. package/dist/providers/togetherAi.js +2 -1
  236. package/dist/providers/voyage.d.ts +1 -1
  237. package/dist/providers/xai.d.ts +1 -1
  238. package/dist/providers/xai.js +2 -1
  239. package/dist/proxy/claudeFormat.d.ts +0 -15
  240. package/dist/proxy/claudeFormat.js +1 -11
  241. package/dist/proxy/modelRouter.d.ts +5 -1
  242. package/dist/proxy/modelRouter.js +8 -0
  243. package/dist/proxy/openaiFormat.d.ts +137 -0
  244. package/dist/proxy/openaiFormat.js +800 -0
  245. package/dist/proxy/proxyTranslationEngine.d.ts +124 -0
  246. package/dist/proxy/proxyTranslationEngine.js +678 -0
  247. package/dist/rag/ragIntegration.d.ts +1 -12
  248. package/dist/rag/ragIntegration.js +0 -8
  249. package/dist/server/routes/claudeProxyRoutes.d.ts +6 -5
  250. package/dist/server/routes/claudeProxyRoutes.js +22 -355
  251. package/dist/server/routes/index.d.ts +1 -0
  252. package/dist/server/routes/index.js +10 -2
  253. package/dist/server/routes/openaiProxyRoutes.d.ts +30 -0
  254. package/dist/server/routes/openaiProxyRoutes.js +336 -0
  255. package/dist/tasks/tools/taskTools.d.ts +2 -117
  256. package/dist/tasks/tools/taskTools.js +1 -10
  257. package/dist/types/aliases.d.ts +1 -1
  258. package/dist/types/conversation.d.ts +1 -0
  259. package/dist/types/evaluation.d.ts +1 -5
  260. package/dist/types/evaluation.js +0 -4
  261. package/dist/types/generate.d.ts +2 -22
  262. package/dist/types/guardrails.d.ts +1 -1
  263. package/dist/types/middleware.d.ts +8 -3
  264. package/dist/types/providers.d.ts +2 -1
  265. package/dist/types/proxy.d.ts +179 -0
  266. package/dist/types/rag.d.ts +1 -1
  267. package/dist/types/rag.js +0 -6
  268. package/dist/types/server.d.ts +3 -0
  269. package/dist/types/stream.d.ts +2 -11
  270. package/dist/types/tools.d.ts +2 -1
  271. package/dist/utils/generation.d.ts +8 -0
  272. package/dist/utils/generation.js +8 -0
  273. package/dist/utils/generationErrors.d.ts +10 -0
  274. package/dist/utils/generationErrors.js +10 -0
  275. package/dist/utils/messageBuilder.d.ts +1 -6
  276. package/dist/utils/messageBuilder.js +0 -5
  277. package/dist/utils/noOutputSentinel.d.ts +0 -13
  278. package/dist/utils/noOutputSentinel.js +1 -14
  279. package/dist/utils/providerRetry.js +1 -1
  280. package/dist/utils/tool.d.ts +8 -0
  281. package/dist/utils/tool.js +8 -0
  282. package/dist/utils/toolCallRepair.d.ts +1 -16
  283. package/dist/utils/toolCallRepair.js +1 -16
  284. package/dist/utils/toolChoice.d.ts +1 -1
  285. package/dist/utils/videoAnalysisProcessor.d.ts +1 -8
  286. package/dist/utils/videoAnalysisProcessor.js +0 -7
  287. package/package.json +2 -3
@@ -1,6 +1,5 @@
1
1
  import { createOpenAI } from "@ai-sdk/openai";
2
2
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
3
- import { NoOutputGeneratedError, Output, stepCountIs, streamText, } from "ai";
4
3
  import { BaseProvider } from "../core/baseProvider.js";
5
4
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
6
5
  import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
@@ -12,9 +11,12 @@ import { logger } from "../utils/logger.js";
12
11
  import { buildNoOutputSentinel, detectPostStreamNoOutput, stampNoOutputSpan, } from "../utils/noOutputSentinel.js";
13
12
  import { calculateCost } from "../utils/pricing.js";
14
13
  import { getProviderModel } from "../utils/providerConfig.js";
15
- import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
14
+ import { composeAbortSignals, createTimeoutController, TimeoutError, withTimeout, } from "../utils/timeout.js";
16
15
  import { resolveToolChoice } from "../utils/toolChoice.js";
17
16
  import { getModelId } from "./providerTypeUtils.js";
17
+ import { NoOutputGeneratedError } from "../utils/generationErrors.js";
18
+ import { Output, stepCountIs } from "../utils/tool.js";
19
+ import { streamText } from "../utils/generation.js";
18
20
  const streamTracer = trace.getTracer("neurolink.provider.litellm");
19
21
  // Configuration helpers
20
22
  const getLiteLLMConfig = () => {
@@ -425,7 +427,7 @@ export class LiteLLMProvider extends BaseProvider {
425
427
  * Uses the LiteLLM proxy with OpenAI-compatible embedding API
426
428
  */
427
429
  async embed(text, modelName) {
428
- const { embed: aiEmbed } = await import("ai");
430
+ const { embed: aiEmbed } = await import("../utils/generation.js");
429
431
  const { createOpenAI } = await import("@ai-sdk/openai");
430
432
  const config = getLiteLLMConfig();
431
433
  const embeddingModelName = modelName ||
@@ -437,7 +439,10 @@ export class LiteLLMProvider extends BaseProvider {
437
439
  fetch: createProxyFetch(),
438
440
  });
439
441
  const embeddingModel = customOpenAI.textEmbeddingModel(embeddingModelName);
440
- const result = await aiEmbed({ model: embeddingModel, value: text });
442
+ // Wrap in withTimeout so stalled upstream embedding requests abort instead
443
+ // of hanging forever. 30s matches the default for embedding endpoints
444
+ // across the OpenAI-compatible cluster.
445
+ const result = await withTimeout(aiEmbed({ model: embeddingModel, value: text }), 30_000, "litellm", "generate");
441
446
  return result.embedding;
442
447
  }
443
448
  /**
@@ -445,7 +450,7 @@ export class LiteLLMProvider extends BaseProvider {
445
450
  * Uses the LiteLLM proxy with OpenAI-compatible embedding API
446
451
  */
447
452
  async embedMany(texts, modelName) {
448
- const { embedMany: aiEmbedMany } = await import("ai");
453
+ const { embedMany: aiEmbedMany } = await import("../utils/generation.js");
449
454
  const { createOpenAI } = await import("@ai-sdk/openai");
450
455
  const config = getLiteLLMConfig();
451
456
  const embeddingModelName = modelName ||
@@ -457,7 +462,8 @@ export class LiteLLMProvider extends BaseProvider {
457
462
  fetch: createProxyFetch(),
458
463
  });
459
464
  const embeddingModel = customOpenAI.textEmbeddingModel(embeddingModelName);
460
- const result = await aiEmbedMany({ model: embeddingModel, values: texts });
465
+ // Wrap in withTimeout so a single slow batch doesn't hang indefinitely.
466
+ const result = await withTimeout(aiEmbedMany({ model: embeddingModel, values: texts }), 30_000, "litellm", "generate");
461
467
  return result.embeddings;
462
468
  }
463
469
  /**
@@ -1,7 +1,7 @@
1
- import { type LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { NeurolinkCredentials, StreamOptions, StreamResult, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * llama.cpp Provider
7
7
  * Wraps a llama-server process (https://github.com/ggerganov/llama.cpp) that
@@ -1,5 +1,4 @@
1
1
  import { createOpenAI } from "@ai-sdk/openai";
2
- import { stepCountIs, streamText } from "ai";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
5
4
  import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
@@ -13,6 +12,8 @@ import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../
13
12
  import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
14
13
  import { resolveToolChoice } from "../utils/toolChoice.js";
15
14
  import { toAnalyticsStreamResult } from "./providerTypeUtils.js";
15
+ import { stepCountIs } from "../utils/tool.js";
16
+ import { streamText } from "../utils/generation.js";
16
17
  const LLAMACPP_DEFAULT_BASE_URL = "http://localhost:8080/v1";
17
18
  const LLAMACPP_PLACEHOLDER_KEY = "llamacpp";
18
19
  const FALLBACK_MODEL = "loaded-model";
@@ -1,7 +1,7 @@
1
- import { type LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { NeurolinkCredentials, StreamOptions, StreamResult, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * LM Studio Provider
7
7
  * Wraps the LM Studio local server (https://lmstudio.ai/) which exposes an
@@ -1,5 +1,4 @@
1
1
  import { createOpenAI } from "@ai-sdk/openai";
2
- import { stepCountIs, streamText } from "ai";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
5
4
  import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
@@ -13,6 +12,8 @@ import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../
13
12
  import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
14
13
  import { resolveToolChoice } from "../utils/toolChoice.js";
15
14
  import { toAnalyticsStreamResult } from "./providerTypeUtils.js";
15
+ import { stepCountIs } from "../utils/tool.js";
16
+ import { streamText } from "../utils/generation.js";
16
17
  const LM_STUDIO_DEFAULT_BASE_URL = "http://localhost:1234/v1";
17
18
  const LM_STUDIO_PLACEHOLDER_KEY = "lm-studio";
18
19
  const FALLBACK_MODEL = "local-model";
@@ -1,7 +1,7 @@
1
- import { type LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { NeurolinkCredentials, StreamOptions, StreamResult, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * Mistral AI Provider v2 - BaseProvider Implementation
7
7
  * Supports official AI-SDK integration with all Mistral models
@@ -1,5 +1,4 @@
1
1
  import { createMistral } from "@ai-sdk/mistral";
2
- import { stepCountIs, streamText } from "ai";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
5
4
  import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
@@ -12,6 +11,8 @@ import { createMistralConfig, getProviderModel, validateApiKey, } from "../utils
12
11
  import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
13
12
  import { resolveToolChoice } from "../utils/toolChoice.js";
14
13
  import { toAnalyticsStreamResult } from "./providerTypeUtils.js";
14
+ import { stepCountIs } from "../utils/tool.js";
15
+ import { streamText } from "../utils/generation.js";
15
16
  // Configuration helpers - now using consolidated utility
16
17
  const getMistralApiKey = () => {
17
18
  return validateApiKey(createMistralConfig());
@@ -1,7 +1,7 @@
1
- import { type LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { NeurolinkCredentials, StreamOptions, StreamResult, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * NVIDIA NIM Provider
7
7
  * Wraps NVIDIA's hosted (or self-hosted) inference endpoints via OpenAI-compat.
@@ -1,5 +1,4 @@
1
1
  import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
2
- import { stepCountIs, streamText } from "ai";
3
2
  import { NvidiaNimModels } from "../constants/enums.js";
4
3
  import { BaseProvider } from "../core/baseProvider.js";
5
4
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
@@ -14,6 +13,8 @@ import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../
14
13
  import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
15
14
  import { resolveToolChoice } from "../utils/toolChoice.js";
16
15
  import { toAnalyticsStreamResult } from "./providerTypeUtils.js";
16
+ import { stepCountIs } from "../utils/tool.js";
17
+ import { streamText } from "../utils/generation.js";
17
18
  /**
18
19
  * Decide whether a NIM 400 response body is a rejection of the named
19
20
  * field (as opposed to an unrelated 400 that happens to mention the
@@ -1,7 +1,7 @@
1
- import type { LanguageModel, Schema } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { StreamOptions, StreamResult, ZodUnknownSchema } from "../types/index.js";
4
+ import type { LanguageModel, Schema } from "../types/index.js";
5
5
  /**
6
6
  * Ollama Provider v2 - BaseProvider Implementation
7
7
  *
@@ -706,8 +706,7 @@ export class OllamaProvider extends BaseProvider {
706
706
  let iteration = 0;
707
707
  // Get all available tools (direct + MCP + external)
708
708
  // BaseProvider.stream() pre-merges base tools + external tools into options.tools
709
- const allTools = options.tools ||
710
- (await this.getAllTools());
709
+ const allTools = options.tools || (await this.getAllTools());
711
710
  // Convert tools to Ollama format
712
711
  const ollamaTools = this.convertToolsToOllamaFormat(allTools);
713
712
  span.setAttribute(ATTR.NL_TOOL_COUNT, ollamaTools.length);
@@ -1,8 +1,8 @@
1
- import { type LanguageModel } from "ai";
2
1
  import { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { NeuroLink } from "../neurolink.js";
5
4
  import type { EnhancedGenerateResult, TextGenerationOptions, ValidationSchema, StreamOptions, StreamResult } from "../types/index.js";
5
+ import type { LanguageModel } from "../types/index.js";
6
6
  /**
7
7
  * OpenAI Provider v2 - BaseProvider Implementation
8
8
  * Migrated to use factory pattern with exact Google AI provider pattern
@@ -1,6 +1,5 @@
1
1
  import { createOpenAI } from "@ai-sdk/openai";
2
2
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
3
- import { embed, embedMany, NoOutputGeneratedError, stepCountIs, streamText, } from "ai";
4
3
  import { AIProviderName } from "../constants/enums.js";
5
4
  import { BaseProvider } from "../core/baseProvider.js";
6
5
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
@@ -18,6 +17,9 @@ import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
18
17
  import { MAX_IMAGE_BYTES, readBoundedBuffer } from "../utils/sizeGuard.js";
19
18
  import { assertSafeUrl } from "../utils/ssrfGuard.js";
20
19
  import { getModelId } from "./providerTypeUtils.js";
20
+ import { NoOutputGeneratedError } from "../utils/generationErrors.js";
21
+ import { stepCountIs } from "../utils/tool.js";
22
+ import { embed, embedMany, streamText } from "../utils/generation.js";
21
23
  /**
22
24
  * Retrieve a tool's schema, handling both AI SDK v6 (`inputSchema`) and
23
25
  * legacy v4 (`parameters`) field names.
@@ -1,8 +1,8 @@
1
- import { type LanguageModel, type Schema } from "ai";
2
1
  import type { ZodType } from "zod";
3
2
  import { AIProviderName } from "../constants/enums.js";
4
3
  import { BaseProvider } from "../core/baseProvider.js";
5
4
  import type { StreamOptions, StreamResult } from "../types/index.js";
5
+ import type { LanguageModel, Schema } from "../types/index.js";
6
6
  /**
7
7
  * OpenRouter Provider - BaseProvider Implementation
8
8
  * Provides access to 300+ models from 60+ providers via OpenRouter unified gateway
@@ -1,5 +1,4 @@
1
1
  import { createOpenRouter } from "@openrouter/ai-sdk-provider";
2
- import { NoOutputGeneratedError, Output, stepCountIs, streamText, } from "ai";
3
2
  import { AIProviderName } from "../constants/enums.js";
4
3
  import { BaseProvider } from "../core/baseProvider.js";
5
4
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
@@ -13,6 +12,9 @@ import { buildNoOutputSentinel, detectPostStreamNoOutput, stampNoOutputSpan, } f
13
12
  import { getProviderModel } from "../utils/providerConfig.js";
14
13
  import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
15
14
  import { resolveToolChoice } from "../utils/toolChoice.js";
15
+ import { NoOutputGeneratedError } from "../utils/generationErrors.js";
16
+ import { Output, stepCountIs } from "../utils/tool.js";
17
+ import { streamText } from "../utils/generation.js";
16
18
  // Constants
17
19
  const MODELS_DISCOVERY_TIMEOUT_MS = 5000; // 5 seconds for model discovery
18
20
  // Configuration helpers
@@ -1,7 +1,7 @@
1
- import { type LanguageModel, type Schema } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { StreamOptions, StreamResult, ZodUnknownSchema } from "../types/index.js";
4
+ import type { LanguageModel, Schema } from "../types/index.js";
5
5
  /**
6
6
  * OpenAI Compatible Provider - BaseProvider Implementation
7
7
  * Provides access to one of the OpenAI-compatible endpoint (OpenRouter, vLLM, LiteLLM, etc.)
@@ -1,5 +1,4 @@
1
1
  import { createOpenAI } from "@ai-sdk/openai";
2
- import { NoOutputGeneratedError, stepCountIs, streamText, } from "ai";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
5
4
  import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
@@ -11,6 +10,9 @@ import { buildNoOutputSentinel, detectPostStreamNoOutput, stampNoOutputSpan, } f
11
10
  import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../utils/timeout.js";
12
11
  import { resolveToolChoice } from "../utils/toolChoice.js";
13
12
  import { toAnalyticsStreamResult } from "./providerTypeUtils.js";
13
+ import { NoOutputGeneratedError } from "../utils/generationErrors.js";
14
+ import { stepCountIs } from "../utils/tool.js";
15
+ import { streamText } from "../utils/generation.js";
14
16
  // Constants
15
17
  const FALLBACK_OPENAI_COMPATIBLE_MODEL = "gpt-3.5-turbo";
16
18
  // Configuration helpers
@@ -1,7 +1,7 @@
1
- import { type LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { NeurolinkCredentials, StreamOptions, StreamResult, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * Perplexity Provider
7
7
  *
@@ -1,5 +1,4 @@
1
1
  import { createOpenAI } from "@ai-sdk/openai";
2
- import { stepCountIs, streamText } from "ai";
3
2
  import { PerplexityModels } from "../constants/enums.js";
4
3
  import { BaseProvider } from "../core/baseProvider.js";
5
4
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
@@ -14,6 +13,8 @@ import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../
14
13
  import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
15
14
  import { resolveToolChoice } from "../utils/toolChoice.js";
16
15
  import { toAnalyticsStreamResult } from "./providerTypeUtils.js";
16
+ import { stepCountIs } from "../utils/tool.js";
17
+ import { streamText } from "../utils/generation.js";
17
18
  const PERPLEXITY_DEFAULT_BASE_URL = "https://api.perplexity.ai";
18
19
  const getPerplexityApiKey = () => validateApiKey(createPerplexityConfig());
19
20
  const getDefaultPerplexityModel = () => getProviderModel("PERPLEXITY_MODEL", PerplexityModels.SONAR);
@@ -1,11 +1,6 @@
1
- /**
2
- * Shared type utilities for AI SDK provider integration.
3
- *
4
- * Provides type-safe helpers to bridge between the AI SDK's generic types
5
- * and NeuroLink's internal type system without resorting to `as any` casts.
6
- */
7
- import type { LanguageModel, streamText } from "ai";
8
1
  import type { StreamTextResult } from "../types/index.js";
2
+ import type { LanguageModel } from "../types/index.js";
3
+ import type { streamText } from "../utils/generation.js";
9
4
  /**
10
5
  * Extract the model identifier from a LanguageModel value.
11
6
  *
@@ -1,9 +1,3 @@
1
- /**
2
- * Shared type utilities for AI SDK provider integration.
3
- *
4
- * Provides type-safe helpers to bridge between the AI SDK's generic types
5
- * and NeuroLink's internal type system without resorting to `as any` casts.
6
- */
7
1
  /**
8
2
  * Type guard: checks whether a LanguageModel value is an object with `modelId`
9
3
  * (i.e. LanguageModelV2 or LanguageModelV3) rather than a bare string ID.
@@ -1,7 +1,7 @@
1
- import type { LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { EnhancedGenerateResult, NeurolinkCredentials, StreamOptions, StreamResult, TextGenerationOptions, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * Recraft Provider — image generation with vector / illustration focus.
7
7
  *
@@ -1,7 +1,7 @@
1
- import type { LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { EnhancedGenerateResult, NeurolinkCredentials, StreamOptions, StreamResult, TextGenerationOptions, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * Replicate LLM Provider — predict-then-stream pattern.
7
7
  *
@@ -1,7 +1,7 @@
1
- import type { LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { EnhancedGenerateResult, NeurolinkCredentials, StreamOptions, StreamResult, TextGenerationOptions, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * Stability AI Provider — direct image generation.
7
7
  *
@@ -1,7 +1,7 @@
1
- import { type LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { NeurolinkCredentials, StreamOptions, StreamResult, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * Together AI Provider
7
7
  *
@@ -1,5 +1,4 @@
1
1
  import { createOpenAI } from "@ai-sdk/openai";
2
- import { stepCountIs, streamText } from "ai";
3
2
  import { TogetherAIModels } from "../constants/enums.js";
4
3
  import { BaseProvider } from "../core/baseProvider.js";
5
4
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
@@ -14,6 +13,8 @@ import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../
14
13
  import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
15
14
  import { resolveToolChoice } from "../utils/toolChoice.js";
16
15
  import { toAnalyticsStreamResult } from "./providerTypeUtils.js";
16
+ import { stepCountIs } from "../utils/tool.js";
17
+ import { streamText } from "../utils/generation.js";
17
18
  const TOGETHER_DEFAULT_BASE_URL = "https://api.together.xyz/v1";
18
19
  const getTogetherApiKey = () => validateApiKey(createTogetherAIConfig());
19
20
  const getDefaultTogetherModel = () => getProviderModel("TOGETHER_MODEL", TogetherAIModels.LLAMA_3_3_70B_INSTRUCT_TURBO);
@@ -1,7 +1,7 @@
1
- import type { LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { NeurolinkCredentials, StreamOptions, StreamResult, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * Voyage AI Provider — embedding-only.
7
7
  *
@@ -1,7 +1,7 @@
1
- import { type LanguageModel } from "ai";
2
1
  import type { AIProviderName } from "../constants/enums.js";
3
2
  import { BaseProvider } from "../core/baseProvider.js";
4
3
  import type { NeurolinkCredentials, StreamOptions, StreamResult, ValidationSchema } from "../types/index.js";
4
+ import type { LanguageModel } from "../types/index.js";
5
5
  /**
6
6
  * xAI Grok Provider
7
7
  *
@@ -1,5 +1,4 @@
1
1
  import { createOpenAI } from "@ai-sdk/openai";
2
- import { stepCountIs, streamText } from "ai";
3
2
  import { XaiModels } from "../constants/enums.js";
4
3
  import { BaseProvider } from "../core/baseProvider.js";
5
4
  import { DEFAULT_MAX_STEPS } from "../core/constants.js";
@@ -14,6 +13,8 @@ import { composeAbortSignals, createTimeoutController, TimeoutError, } from "../
14
13
  import { emitToolEndFromStepFinish } from "../utils/toolEndEmitter.js";
15
14
  import { resolveToolChoice } from "../utils/toolChoice.js";
16
15
  import { toAnalyticsStreamResult } from "./providerTypeUtils.js";
16
+ import { stepCountIs } from "../utils/tool.js";
17
+ import { streamText } from "../utils/generation.js";
17
18
  /**
18
19
  * Logging fetch wrapper — masks the proxy URL on non-2xx responses so
19
20
  * stack traces and log lines don't leak the upstream's internal token /
@@ -1,23 +1,8 @@
1
- /**
2
- * Claude Messages API format conversion layer.
3
- *
4
- * Provides a request parser (Claude -> NeuroLink), a response serializer
5
- * (NeuroLink -> Claude), a streaming SSE state machine, and an error
6
- * envelope helper. Together they allow NeuroLink to act as a
7
- * drop-in Claude API proxy.
8
- *
9
- * Reference: https://docs.anthropic.com/en/api/messages
10
- */
11
1
  import type { ClaudeErrorResponse, ClaudeRequest, ClaudeResponse, ContentBlockType, InternalResult, ParsedClaudeRequest, StreamLifecycleState } from "../types/index.js";
12
2
  /** Generate a unique message id in the Claude format. */
13
3
  export declare function generateMessageId(): string;
14
4
  /** Generate a Claude-format tool use ID (`toolu_` + 24 random chars). */
15
5
  export declare function generateToolUseId(): string;
16
- /**
17
- * Reset the internal id counter (useful in tests).
18
- * @internal
19
- */
20
- export declare function _resetIdCounter(): void;
21
6
  /**
22
7
  * Parse an incoming Claude Messages API request into an intermediate
23
8
  * representation consumable by NeuroLink's generate/stream pipeline.
@@ -1,16 +1,6 @@
1
- /**
2
- * Claude Messages API format conversion layer.
3
- *
4
- * Provides a request parser (Claude -> NeuroLink), a response serializer
5
- * (NeuroLink -> Claude), a streaming SSE state machine, and an error
6
- * envelope helper. Together they allow NeuroLink to act as a
7
- * drop-in Claude API proxy.
8
- *
9
- * Reference: https://docs.anthropic.com/en/api/messages
10
- */
11
- import { jsonSchema, tool } from "ai";
12
1
  import { randomBytes } from "crypto";
13
2
  import { normalizeJsonSchemaObject } from "../utils/schemaConversion.js";
3
+ import { jsonSchema, tool } from "../utils/tool.js";
14
4
  // ---------------------------------------------------------------------------
15
5
  // Helpers
16
6
  // ---------------------------------------------------------------------------
@@ -1,4 +1,4 @@
1
- import type { FallbackEntry, ProxyRoutingConfig, RouteResult } from "../types/index.js";
1
+ import type { FallbackEntry, ModelMapping, ProxyRoutingConfig, RouteResult } from "../types/index.js";
2
2
  export declare class ModelRouter {
3
3
  private readonly mappings;
4
4
  private readonly passthrough;
@@ -7,4 +7,8 @@ export declare class ModelRouter {
7
7
  resolve(requestedModel: string): RouteResult;
8
8
  isClaudeTarget(requestedModel: string): boolean;
9
9
  getFallbackChain(): FallbackEntry[];
10
+ /** Return the raw model mapping entries (used by /v1/models). */
11
+ getModelMappings(): ModelMapping[];
12
+ /** Return models configured for passthrough (used by /v1/models). */
13
+ getPassthroughModels(): string[];
10
14
  }
@@ -29,4 +29,12 @@ export class ModelRouter {
29
29
  getFallbackChain() {
30
30
  return this.fallback;
31
31
  }
32
+ /** Return the raw model mapping entries (used by /v1/models). */
33
+ getModelMappings() {
34
+ return Array.from(this.mappings.values());
35
+ }
36
+ /** Return models configured for passthrough (used by /v1/models). */
37
+ getPassthroughModels() {
38
+ return Array.from(this.passthrough);
39
+ }
32
40
  }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * OpenAI Chat Completions API format conversion layer.
3
+ *
4
+ * Provides a request parser (OpenAI -> NeuroLink), a response serializer
5
+ * (NeuroLink -> OpenAI), a streaming SSE state machine, and an error
6
+ * envelope helper. Together they allow NeuroLink to act as a
7
+ * drop-in OpenAI API proxy.
8
+ *
9
+ * Reference: https://platform.openai.com/docs/api-reference/chat/create
10
+ */
11
+ import type { ClaudeRequest, ClaudeResponse, InternalResult, OpenAICompletionRequest, OpenAICompletionResponse, OpenAIErrorResponse, ParsedOpenAIRequest, StreamLifecycleState } from "../types/index.js";
12
+ /** Generate a unique chat completion ID in the OpenAI format. */
13
+ export declare function generateChatCompletionId(): string;
14
+ /** Generate an OpenAI-format tool call ID (`call_` + random chars). */
15
+ export declare function generateOpenAIToolCallId(): string;
16
+ /**
17
+ * Parse an incoming OpenAI Chat Completions request into an intermediate
18
+ * representation consumable by NeuroLink's generate/stream pipeline.
19
+ *
20
+ * Handles:
21
+ * - System prompt extraction from system messages
22
+ * - Message flattening (text + image parts)
23
+ * - Tool definition conversion
24
+ * - tool_choice mapping
25
+ * - top_p, temperature, max_tokens pass-through
26
+ */
27
+ export declare function parseOpenAIRequest(body: OpenAICompletionRequest): ParsedOpenAIRequest;
28
+ /**
29
+ * Serialize a NeuroLink GenerateResult into an OpenAI Chat Completions response.
30
+ */
31
+ export declare function serializeOpenAIResponse(result: InternalResult, requestModel: string): OpenAICompletionResponse;
32
+ /**
33
+ * Build an OpenAI-compatible error envelope.
34
+ */
35
+ export declare function buildOpenAIError(status: number, message: string): OpenAIErrorResponse;
36
+ /**
37
+ * Format a single OpenAI SSE frame.
38
+ * OpenAI uses only `data:` lines (no `event:` prefix unlike Claude).
39
+ */
40
+ export declare function formatOpenAISSE(data: unknown): string;
41
+ /**
42
+ * Stateful SSE serializer that emits a well-formed OpenAI streaming response.
43
+ *
44
+ * Tracks lifecycle state (`idle` -> `streaming` -> `done`) and the current
45
+ * tool call index for multi-tool streaming.
46
+ *
47
+ * Usage:
48
+ * ```ts
49
+ * const sse = new OpenAIStreamSerializer(requestModel);
50
+ *
51
+ * // Start the stream
52
+ * yield* sse.start();
53
+ *
54
+ * // Text deltas
55
+ * for await (const chunk of textStream) {
56
+ * yield* sse.pushDelta(chunk);
57
+ * }
58
+ *
59
+ * // Tool use
60
+ * yield* sse.pushToolUse(toolId, toolName, toolInput);
61
+ *
62
+ * // Finalize
63
+ * yield* sse.finish("stop", usage);
64
+ * ```
65
+ */
66
+ export declare class OpenAIStreamSerializer {
67
+ private state;
68
+ private readonly id;
69
+ private readonly model;
70
+ private started;
71
+ private toolCallIndex;
72
+ constructor(model: string);
73
+ /** Current lifecycle state (exposed for testing). */
74
+ getState(): StreamLifecycleState;
75
+ private makeChunk;
76
+ /**
77
+ * Emit the opening frame with `role: "assistant"`.
78
+ */
79
+ start(): Generator<string>;
80
+ /**
81
+ * Push a text content delta.
82
+ */
83
+ pushDelta(text: string): Generator<string>;
84
+ /**
85
+ * Push the start of a tool call (id, name, empty arguments).
86
+ */
87
+ pushToolCallStart(id: string, name: string): Generator<string>;
88
+ /**
89
+ * Push an arguments delta for the current tool call.
90
+ */
91
+ pushToolCallArgDelta(index: number, argsChunk: string): Generator<string>;
92
+ /**
93
+ * Push a complete tool use: emits tool call start followed by chunked
94
+ * argument deltas (~100 chars per chunk).
95
+ */
96
+ pushToolUse(id: string, name: string, input: unknown): Generator<string>;
97
+ /**
98
+ * Finalize the stream: emit finish_reason chunk, then `data: [DONE]`.
99
+ */
100
+ finish(finishReason?: string, usage?: {
101
+ input: number;
102
+ output: number;
103
+ total: number;
104
+ }): Generator<string>;
105
+ /**
106
+ * Emit an error event. Transitions to terminal ERROR state.
107
+ */
108
+ emitError(message: string): Generator<string>;
109
+ }
110
+ /**
111
+ * Convert an OpenAI Chat Completions request to a Claude Messages API request.
112
+ *
113
+ * Used by the OpenAI proxy endpoint to internally loopback requests targeting
114
+ * Claude models through the proxy's native /v1/messages passthrough path,
115
+ * so they benefit from OAuth account rotation, retry, SSE interception, etc.
116
+ */
117
+ export declare function convertOpenAIToClaudeRequest(openai: OpenAICompletionRequest): ClaudeRequest;
118
+ /**
119
+ * Convert a non-streaming Claude Messages response to an OpenAI Chat
120
+ * Completions response by bridging through {@link InternalResult}.
121
+ */
122
+ export declare function convertClaudeToOpenAIResponse(claude: ClaudeResponse, requestModel: string): OpenAICompletionResponse;
123
+ /**
124
+ * Create a TransformStream that parses Claude Messages API SSE events from
125
+ * the upstream response and re-emits them as OpenAI Chat Completions SSE
126
+ * frames.
127
+ *
128
+ * Handles the canonical Claude SSE event types:
129
+ * - message_start -> emits the opening `role: "assistant"` chunk
130
+ * - content_block_start -> text block: no-op; tool_use block: emit tool call start
131
+ * - content_block_delta -> text_delta: emit content delta;
132
+ * input_json_delta: emit tool call argument delta
133
+ * - content_block_stop -> no-op
134
+ * - message_delta -> captures stop_reason and output token usage
135
+ * - message_stop -> emits the final `finish_reason` chunk + `[DONE]`
136
+ */
137
+ export declare function createClaudeToOpenAIStreamTransform(requestModel: string): TransformStream<Uint8Array, Uint8Array>;