@juspay/neurolink 10.12.8 → 11.0.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 (179) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/browser/neurolink.min.js +399 -401
  3. package/dist/cli/commands/setup.d.ts +16 -1
  4. package/dist/cli/commands/setup.js +141 -3
  5. package/dist/core/baseProvider.js +3 -3
  6. package/dist/core/dynamicModels.d.ts +1 -1
  7. package/dist/core/dynamicModels.js +1 -23
  8. package/dist/core/modelConfiguration.d.ts +1 -70
  9. package/dist/core/modelConfiguration.js +0 -303
  10. package/dist/core/modules/GenerationHandler.js +38 -16
  11. package/dist/core/modules/structuredOutputPolicy.d.ts +2 -2
  12. package/dist/core/modules/structuredOutputPolicy.js +2 -2
  13. package/dist/factories/providerFactory.d.ts +15 -0
  14. package/dist/factories/providerFactory.js +27 -39
  15. package/dist/factories/providerRegistry.js +2 -2
  16. package/dist/lib/core/baseProvider.js +3 -3
  17. package/dist/lib/core/dynamicModels.d.ts +1 -1
  18. package/dist/lib/core/dynamicModels.js +1 -23
  19. package/dist/lib/core/modelConfiguration.d.ts +1 -70
  20. package/dist/lib/core/modelConfiguration.js +0 -303
  21. package/dist/lib/core/modules/GenerationHandler.js +38 -16
  22. package/dist/lib/core/modules/structuredOutputPolicy.d.ts +2 -2
  23. package/dist/lib/core/modules/structuredOutputPolicy.js +2 -2
  24. package/dist/lib/factories/providerFactory.d.ts +15 -0
  25. package/dist/lib/factories/providerFactory.js +27 -39
  26. package/dist/lib/factories/providerRegistry.js +2 -2
  27. package/dist/lib/models/anthropicModels.d.ts +0 -7
  28. package/dist/lib/models/anthropicModels.js +0 -9
  29. package/dist/lib/neurolink.d.ts +15 -0
  30. package/dist/lib/neurolink.js +77 -44
  31. package/dist/lib/providers/anthropic/client.js +17 -1
  32. package/dist/lib/providers/anthropic/constants.d.ts +0 -1
  33. package/dist/lib/providers/anthropic/constants.js +0 -2
  34. package/dist/lib/providers/anthropic/index.d.ts +0 -1
  35. package/dist/lib/providers/anthropic/index.js +0 -1
  36. package/dist/lib/providers/googleAiStudio/index.d.ts +0 -1
  37. package/dist/lib/providers/googleAiStudio/index.js +0 -1
  38. package/dist/lib/providers/googleNativeGemini3/index.d.ts +0 -1
  39. package/dist/lib/providers/googleNativeGemini3/index.js +0 -1
  40. package/dist/lib/providers/googleVertex/client.d.ts +0 -51
  41. package/dist/lib/providers/googleVertex/client.js +0 -678
  42. package/dist/lib/providers/huggingFace/client.d.ts +1 -1
  43. package/dist/lib/providers/huggingFace/client.js +1 -1
  44. package/dist/lib/providers/huggingFace/index.d.ts +0 -1
  45. package/dist/lib/providers/huggingFace/index.js +0 -1
  46. package/dist/lib/providers/jina.d.ts +0 -1
  47. package/dist/lib/providers/jina.js +0 -1
  48. package/dist/lib/providers/litellm/index.d.ts +0 -2
  49. package/dist/lib/providers/litellm/index.js +0 -2
  50. package/dist/lib/providers/llamaCpp.d.ts +1 -0
  51. package/dist/lib/providers/llamaCpp.js +3 -0
  52. package/dist/lib/providers/lmStudio.js +3 -23
  53. package/dist/lib/providers/nvidiaNim/index.d.ts +0 -1
  54. package/dist/lib/providers/nvidiaNim/index.js +0 -1
  55. package/dist/lib/providers/ollama/client.js +1 -23
  56. package/dist/lib/providers/ollama/index.d.ts +0 -1
  57. package/dist/lib/providers/ollama/index.js +0 -1
  58. package/dist/lib/providers/openAI/index.d.ts +0 -2
  59. package/dist/lib/providers/openAI/index.js +0 -2
  60. package/dist/lib/providers/openRouter/utils.d.ts +0 -2
  61. package/dist/lib/providers/openRouter/utils.js +0 -12
  62. package/dist/lib/providers/openaiChatCompletionsBase.d.ts +9 -0
  63. package/dist/lib/providers/openaiChatCompletionsBase.js +33 -0
  64. package/dist/lib/providers/perplexity.d.ts +2 -1
  65. package/dist/lib/providers/perplexity.js +2 -1
  66. package/dist/lib/providers/replicate.d.ts +0 -1
  67. package/dist/lib/providers/replicate.js +22 -9
  68. package/dist/lib/providers/voyage.d.ts +0 -1
  69. package/dist/lib/providers/voyage.js +0 -1
  70. package/dist/lib/types/index.d.ts +0 -1
  71. package/dist/lib/types/index.js +0 -1
  72. package/dist/lib/types/providers.d.ts +2 -11
  73. package/dist/lib/types/utilities.d.ts +29 -0
  74. package/dist/lib/utils/json/coerce.d.ts +21 -1
  75. package/dist/lib/utils/json/coerce.js +148 -11
  76. package/dist/lib/utils/providerConfig.d.ts +0 -8
  77. package/dist/lib/utils/providerConfig.js +0 -37
  78. package/dist/lib/utils/providerUtils.js +1 -25
  79. package/dist/models/anthropicModels.d.ts +0 -7
  80. package/dist/models/anthropicModels.js +0 -9
  81. package/dist/neurolink.d.ts +15 -0
  82. package/dist/neurolink.js +77 -44
  83. package/dist/providers/anthropic/client.js +17 -1
  84. package/dist/providers/anthropic/constants.d.ts +0 -1
  85. package/dist/providers/anthropic/constants.js +0 -2
  86. package/dist/providers/anthropic/index.d.ts +0 -1
  87. package/dist/providers/anthropic/index.js +0 -1
  88. package/dist/providers/googleAiStudio/index.d.ts +0 -1
  89. package/dist/providers/googleAiStudio/index.js +0 -1
  90. package/dist/providers/googleNativeGemini3/index.d.ts +0 -1
  91. package/dist/providers/googleNativeGemini3/index.js +0 -1
  92. package/dist/providers/googleVertex/client.d.ts +0 -51
  93. package/dist/providers/googleVertex/client.js +0 -678
  94. package/dist/providers/huggingFace/client.d.ts +1 -1
  95. package/dist/providers/huggingFace/client.js +1 -1
  96. package/dist/providers/huggingFace/index.d.ts +0 -1
  97. package/dist/providers/huggingFace/index.js +0 -1
  98. package/dist/providers/jina.d.ts +0 -1
  99. package/dist/providers/jina.js +0 -1
  100. package/dist/providers/litellm/index.d.ts +0 -2
  101. package/dist/providers/litellm/index.js +0 -2
  102. package/dist/providers/llamaCpp.d.ts +1 -0
  103. package/dist/providers/llamaCpp.js +3 -0
  104. package/dist/providers/lmStudio.js +3 -23
  105. package/dist/providers/nvidiaNim/index.d.ts +0 -1
  106. package/dist/providers/nvidiaNim/index.js +0 -1
  107. package/dist/providers/ollama/client.js +1 -23
  108. package/dist/providers/ollama/index.d.ts +0 -1
  109. package/dist/providers/ollama/index.js +0 -1
  110. package/dist/providers/openAI/index.d.ts +0 -2
  111. package/dist/providers/openAI/index.js +0 -2
  112. package/dist/providers/openRouter/utils.d.ts +0 -2
  113. package/dist/providers/openRouter/utils.js +0 -12
  114. package/dist/providers/openaiChatCompletionsBase.d.ts +9 -0
  115. package/dist/providers/openaiChatCompletionsBase.js +33 -0
  116. package/dist/providers/perplexity.d.ts +2 -1
  117. package/dist/providers/perplexity.js +2 -1
  118. package/dist/providers/replicate.d.ts +0 -1
  119. package/dist/providers/replicate.js +22 -9
  120. package/dist/providers/voyage.d.ts +0 -1
  121. package/dist/providers/voyage.js +0 -1
  122. package/dist/types/index.d.ts +0 -1
  123. package/dist/types/index.js +0 -1
  124. package/dist/types/providers.d.ts +2 -11
  125. package/dist/types/utilities.d.ts +29 -0
  126. package/dist/utils/json/coerce.d.ts +21 -1
  127. package/dist/utils/json/coerce.js +148 -11
  128. package/dist/utils/providerConfig.d.ts +0 -8
  129. package/dist/utils/providerConfig.js +0 -37
  130. package/dist/utils/providerUtils.js +1 -25
  131. package/package.json +8 -6
  132. package/dist/lib/providers/anthropic/utils.d.ts +0 -7
  133. package/dist/lib/providers/anthropic/utils.js +0 -150
  134. package/dist/lib/providers/googleAiStudio/utils.d.ts +0 -2
  135. package/dist/lib/providers/googleAiStudio/utils.js +0 -19
  136. package/dist/lib/providers/googleNativeGemini3/constants.d.ts +0 -1
  137. package/dist/lib/providers/googleNativeGemini3/constants.js +0 -2
  138. package/dist/lib/providers/huggingFace/utils.d.ts +0 -2
  139. package/dist/lib/providers/huggingFace/utils.js +0 -8
  140. package/dist/lib/providers/index.d.ts +0 -33
  141. package/dist/lib/providers/index.js +0 -34
  142. package/dist/lib/providers/litellm/constants.d.ts +0 -1
  143. package/dist/lib/providers/litellm/constants.js +0 -3
  144. package/dist/lib/providers/litellm/utils.d.ts +0 -5
  145. package/dist/lib/providers/litellm/utils.js +0 -11
  146. package/dist/lib/providers/nvidiaNim/utils.d.ts +0 -9
  147. package/dist/lib/providers/nvidiaNim/utils.js +0 -101
  148. package/dist/lib/providers/ollama/utils.d.ts +0 -8
  149. package/dist/lib/providers/ollama/utils.js +0 -43
  150. package/dist/lib/providers/openAI/constants.d.ts +0 -1
  151. package/dist/lib/providers/openAI/constants.js +0 -3
  152. package/dist/lib/providers/openAI/utils.d.ts +0 -2
  153. package/dist/lib/providers/openAI/utils.js +0 -8
  154. package/dist/lib/types/universalProviderOptions.d.ts +0 -89
  155. package/dist/lib/types/universalProviderOptions.js +0 -55
  156. package/dist/providers/anthropic/utils.d.ts +0 -7
  157. package/dist/providers/anthropic/utils.js +0 -149
  158. package/dist/providers/googleAiStudio/utils.d.ts +0 -2
  159. package/dist/providers/googleAiStudio/utils.js +0 -18
  160. package/dist/providers/googleNativeGemini3/constants.d.ts +0 -1
  161. package/dist/providers/googleNativeGemini3/constants.js +0 -1
  162. package/dist/providers/huggingFace/utils.d.ts +0 -2
  163. package/dist/providers/huggingFace/utils.js +0 -7
  164. package/dist/providers/index.d.ts +0 -33
  165. package/dist/providers/index.js +0 -33
  166. package/dist/providers/litellm/constants.d.ts +0 -1
  167. package/dist/providers/litellm/constants.js +0 -2
  168. package/dist/providers/litellm/utils.d.ts +0 -5
  169. package/dist/providers/litellm/utils.js +0 -10
  170. package/dist/providers/nvidiaNim/utils.d.ts +0 -9
  171. package/dist/providers/nvidiaNim/utils.js +0 -100
  172. package/dist/providers/ollama/utils.d.ts +0 -8
  173. package/dist/providers/ollama/utils.js +0 -42
  174. package/dist/providers/openAI/constants.d.ts +0 -1
  175. package/dist/providers/openAI/constants.js +0 -2
  176. package/dist/providers/openAI/utils.d.ts +0 -2
  177. package/dist/providers/openAI/utils.js +0 -7
  178. package/dist/types/universalProviderOptions.d.ts +0 -89
  179. package/dist/types/universalProviderOptions.js +0 -54
@@ -14,7 +14,7 @@ import { OpenAIChatCompletionsProvider } from "../openaiChatCompletionsBase.js";
14
14
  * @see https://huggingface.co/docs/api-inference/index
15
15
  */
16
16
  export declare class HuggingFaceProvider extends OpenAIChatCompletionsProvider {
17
- constructor(modelName?: string, sdk?: unknown, credentials?: NeurolinkCredentials["huggingFace"]);
17
+ constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["huggingFace"]);
18
18
  protected getProviderName(): AIProviderName;
19
19
  protected getDefaultModel(): string;
20
20
  protected getFallbackModelName(): string;
@@ -20,7 +20,7 @@ const getDefaultHuggingFaceModel = () => getProviderModel("HUGGINGFACE_MODEL", "
20
20
  * @see https://huggingface.co/docs/api-inference/index
21
21
  */
22
22
  export class HuggingFaceProvider extends OpenAIChatCompletionsProvider {
23
- constructor(modelName, sdk, credentials) {
23
+ constructor(modelName, sdk, _region, credentials) {
24
24
  const apiKey = credentials?.apiKey?.trim()
25
25
  ? credentials.apiKey.trim()
26
26
  : getHuggingFaceApiKey();
@@ -1,2 +1 @@
1
1
  export * from "./client.js";
2
- export * from "./utils.js";
@@ -1,3 +1,2 @@
1
1
  export * from "./client.js";
2
- export * from "./utils.js";
3
2
  //# sourceMappingURL=index.js.map
@@ -56,4 +56,3 @@ export declare class JinaProvider extends BaseProvider {
56
56
  baseURL: string;
57
57
  };
58
58
  }
59
- export default JinaProvider;
@@ -214,5 +214,4 @@ export class JinaProvider extends BaseProvider {
214
214
  };
215
215
  }
216
216
  }
217
- export default JinaProvider;
218
217
  //# sourceMappingURL=jina.js.map
@@ -1,3 +1 @@
1
1
  export * from "./client.js";
2
- export * from "./constants.js";
3
- export * from "./utils.js";
@@ -1,4 +1,2 @@
1
1
  export * from "./client.js";
2
- export * from "./constants.js";
3
- export * from "./utils.js";
4
2
  //# sourceMappingURL=index.js.map
@@ -15,6 +15,7 @@ import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
15
15
  */
16
16
  export declare class LlamaCppProvider extends OpenAIChatCompletionsProvider {
17
17
  constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["llamacpp"]);
18
+ validateConfiguration(): Promise<boolean>;
18
19
  protected getProviderName(): AIProviderName;
19
20
  protected getDefaultModel(): string;
20
21
  protected getFallbackModelName(): string;
@@ -36,6 +36,9 @@ export class LlamaCppProvider extends OpenAIChatCompletionsProvider {
36
36
  baseURL: redactUrlCredentials(this.config.baseURL),
37
37
  });
38
38
  }
39
+ async validateConfiguration() {
40
+ return this.probeModelsEndpoint(this.getAuthHeaders());
41
+ }
39
42
  getProviderName() {
40
43
  return "llamacpp";
41
44
  }
@@ -1,4 +1,3 @@
1
- import { createProxyFetch } from "../proxy/proxyFetch.js";
2
1
  import { InvalidModelError, NetworkError, ProviderError, } from "../types/index.js";
3
2
  import { logger } from "../utils/logger.js";
4
3
  import { redactUrlCredentials } from "../utils/logSanitize.js";
@@ -70,28 +69,9 @@ export class LMStudioProvider extends OpenAIChatCompletionsProvider {
70
69
  return new ProviderError(`LM Studio error: ${message}`, "lm-studio");
71
70
  }
72
71
  async validateConfiguration() {
73
- try {
74
- const url = `${this.config.baseURL.replace(/\/$/, "")}/models`;
75
- const proxyFetch = createProxyFetch();
76
- const r = await proxyFetch(url, {
77
- headers: this.config.apiKey && this.config.apiKey !== LM_STUDIO_PLACEHOLDER_KEY
78
- ? { Authorization: `Bearer ${this.config.apiKey}` }
79
- : undefined,
80
- signal: AbortSignal.timeout(5000),
81
- });
82
- if (!r.ok) {
83
- return false;
84
- }
85
- // A 200 with an empty data array means LM Studio is up but no model is
86
- // loaded — `resolveModelName()` will fall back to FALLBACK_MODEL and the
87
- // first real request will fail. Require at least one loaded model so
88
- // health checks honestly reflect whether the provider is usable.
89
- const data = (await r.json().catch(() => null));
90
- return Boolean(data?.data?.some((m) => typeof m?.id === "string" && m.id.trim().length > 0));
91
- }
92
- catch {
93
- return false;
94
- }
72
+ return this.probeModelsEndpoint(this.config.apiKey && this.config.apiKey !== LM_STUDIO_PLACEHOLDER_KEY
73
+ ? { Authorization: `Bearer ${this.config.apiKey}` }
74
+ : {});
95
75
  }
96
76
  getConfiguration() {
97
77
  return {
@@ -1,3 +1,2 @@
1
1
  export * from "./client.js";
2
2
  export * from "./constants.js";
3
- export * from "./utils.js";
@@ -1,4 +1,3 @@
1
1
  export * from "./client.js";
2
2
  export * from "./constants.js";
3
- export * from "./utils.js";
4
3
  //# sourceMappingURL=index.js.map
@@ -181,29 +181,7 @@ export class OllamaProvider extends OpenAIChatCompletionsProvider {
181
181
  * back to a model that the first real request can't serve, so report unusable.
182
182
  */
183
183
  async validateConfiguration() {
184
- try {
185
- const url = `${stripTrailingSlash(this.config.baseURL)}/models`;
186
- const proxyFetch = createProxyFetch();
187
- const r = await proxyFetch(url, {
188
- headers: {
189
- ...this.getAuthHeaders(),
190
- "Content-Type": "application/json",
191
- },
192
- signal: AbortSignal.timeout(5000),
193
- });
194
- if (!r.ok) {
195
- return false;
196
- }
197
- const data = (await r.json().catch(() => null));
198
- return Boolean(data?.data?.some((m) => typeof m?.id === "string" && m.id.trim().length > 0));
199
- }
200
- catch (error) {
201
- logger.debug("Ollama validateConfiguration probe failed", {
202
- baseURL: redactUrlCredentials(this.config.baseURL),
203
- error: error instanceof Error ? error.message : String(error),
204
- });
205
- return false;
206
- }
184
+ return this.probeModelsEndpoint(this.getAuthHeaders());
207
185
  }
208
186
  getConfiguration() {
209
187
  return {
@@ -1,3 +1,2 @@
1
1
  export * from "./client.js";
2
2
  export * from "./constants.js";
3
- export * from "./utils.js";
@@ -1,4 +1,3 @@
1
1
  export * from "./client.js";
2
2
  export * from "./constants.js";
3
- export * from "./utils.js";
4
3
  //# sourceMappingURL=index.js.map
@@ -1,3 +1 @@
1
1
  export * from "./client.js";
2
- export * from "./constants.js";
3
- export * from "./utils.js";
@@ -1,4 +1,2 @@
1
1
  export * from "./client.js";
2
- export * from "./constants.js";
3
- export * from "./utils.js";
4
2
  //# sourceMappingURL=index.js.map
@@ -1,3 +1 @@
1
- import type { OpenRouterConfig } from "../../types/index.js";
2
- export declare const getOpenRouterConfig: () => OpenRouterConfig;
3
1
  export declare const getDefaultOpenRouterModel: () => string;
@@ -1,17 +1,5 @@
1
1
  import { OpenRouterModels } from "../../constants/enums.js";
2
2
  import { getProviderModel } from "../../utils/providerConfig.js";
3
- export const getOpenRouterConfig = () => {
4
- const apiKey = process.env.OPENROUTER_API_KEY;
5
- if (!apiKey) {
6
- throw new Error("OPENROUTER_API_KEY environment variable is required. " +
7
- "Get your API key at https://openrouter.ai/keys");
8
- }
9
- return {
10
- apiKey,
11
- referer: process.env.OPENROUTER_REFERER,
12
- appName: process.env.OPENROUTER_APP_NAME,
13
- };
14
- };
15
3
  export const getDefaultOpenRouterModel = () => {
16
4
  return getProviderModel("OPENROUTER_MODEL", OpenRouterModels.CLAUDE_SONNET_4_5);
17
5
  };
@@ -166,6 +166,15 @@ export declare abstract class OpenAIChatCompletionsProvider extends BaseProvider
166
166
  * override this to probe the server's `/models` endpoint.
167
167
  */
168
168
  validateConfiguration(): Promise<boolean>;
169
+ /**
170
+ * Shared local-runtime reachability probe: GET `${baseURL}/models` with a
171
+ * short timeout, requiring at least one model entry with a non-empty id.
172
+ * Local providers (Ollama, LM Studio, llama.cpp) call this from their own
173
+ * validateConfiguration() override instead of relying on the base class's
174
+ * "apiKey is a non-empty string" default, which can't detect an
175
+ * unreachable local server.
176
+ */
177
+ protected probeModelsEndpoint(headers?: Record<string, string>): Promise<boolean>;
169
178
  /**
170
179
  * Snapshot of the provider's resolved configuration — part of the documented
171
180
  * public provider contract (`docs/provider-integration/00-architecture.md`).
@@ -26,6 +26,7 @@ import { DEFAULT_MAX_STEPS } from "../core/constants.js";
26
26
  import { streamAnalyticsCollector } from "../core/streamAnalytics.js";
27
27
  import { createProxyFetch } from "../proxy/proxyFetch.js";
28
28
  import { logger } from "../utils/logger.js";
29
+ import { redactUrlCredentials } from "../utils/logSanitize.js";
29
30
  import { NoOutputGeneratedError } from "../utils/generationErrors.js";
30
31
  import { buildNoOutputSentinel, stampNoOutputSpan, } from "../utils/noOutputSentinel.js";
31
32
  import { composeAbortSignalsScoped, createTimeoutController, mergeAbortSignals, } from "../utils/timeout.js";
@@ -272,6 +273,38 @@ export class OpenAIChatCompletionsProvider extends BaseProvider {
272
273
  return (typeof this.config.apiKey === "string" &&
273
274
  this.config.apiKey.trim().length > 0);
274
275
  }
276
+ /**
277
+ * Shared local-runtime reachability probe: GET `${baseURL}/models` with a
278
+ * short timeout, requiring at least one model entry with a non-empty id.
279
+ * Local providers (Ollama, LM Studio, llama.cpp) call this from their own
280
+ * validateConfiguration() override instead of relying on the base class's
281
+ * "apiKey is a non-empty string" default, which can't detect an
282
+ * unreachable local server.
283
+ */
284
+ async probeModelsEndpoint(headers = {}) {
285
+ try {
286
+ const url = `${stripTrailingSlash(this.config.baseURL)}/models`;
287
+ const proxyFetch = createProxyFetch();
288
+ const response = await proxyFetch(url, {
289
+ headers: { ...headers, "Content-Type": "application/json" },
290
+ signal: AbortSignal.timeout(5000),
291
+ });
292
+ if (!response.ok) {
293
+ return false;
294
+ }
295
+ const data = (await response
296
+ .json()
297
+ .catch(() => null));
298
+ return Boolean(data?.data?.some((m) => typeof m?.id === "string" && m.id.trim().length > 0));
299
+ }
300
+ catch (error) {
301
+ logger.debug(`[${this.constructor.name}] probeModelsEndpoint failed`, {
302
+ baseURL: redactUrlCredentials(this.config.baseURL),
303
+ error: error instanceof Error ? error.message : String(error),
304
+ });
305
+ return false;
306
+ }
307
+ }
275
308
  /**
276
309
  * Snapshot of the provider's resolved configuration — part of the documented
277
310
  * public provider contract (`docs/provider-integration/00-architecture.md`).
@@ -6,7 +6,8 @@ import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
6
6
  *
7
7
  * Sonar models with built-in web grounding. OpenAI-compatible chat
8
8
  * completions at api.perplexity.ai. Best for queries that need fresh
9
- * web context (search-augmented answers + citations).
9
+ * web context (search-augmented answers). Citation data, if the API returns
10
+ * any, is not extracted or exposed by this provider.
10
11
  *
11
12
  * All request/stream/tool-loop orchestration lives in
12
13
  * `OpenAIChatCompletionsProvider`; this class only declares configuration
@@ -13,7 +13,8 @@ const getDefaultPerplexityModel = () => getProviderModel("PERPLEXITY_MODEL", Per
13
13
  *
14
14
  * Sonar models with built-in web grounding. OpenAI-compatible chat
15
15
  * completions at api.perplexity.ai. Best for queries that need fresh
16
- * web context (search-augmented answers + citations).
16
+ * web context (search-augmented answers). Citation data, if the API returns
17
+ * any, is not extracted or exposed by this provider.
17
18
  *
18
19
  * All request/stream/tool-loop orchestration lives in
19
20
  * `OpenAIChatCompletionsProvider`; this class only declares configuration
@@ -72,4 +72,3 @@ export declare class ReplicateProvider extends BaseProvider {
72
72
  baseURL: string | undefined;
73
73
  };
74
74
  }
75
- export default ReplicateProvider;
@@ -34,6 +34,18 @@ function flattenReplicateOutput(output) {
34
34
  }
35
35
  return "";
36
36
  }
37
+ /**
38
+ * Resolve Replicate credentials, aliasing the standard `apiKey`/`baseURL`
39
+ * field names (shared with every other provider in `NeurolinkCredentials`)
40
+ * against the legacy `apiToken`/`baseUrl` names. The standard name wins
41
+ * when both are present; used identically for instance-level and per-call
42
+ * credentials so aliasing never drifts between the two.
43
+ */
44
+ function resolveReplicateCredentials(credentials) {
45
+ const apiToken = credentials?.apiKey?.trim() || credentials?.apiToken?.trim();
46
+ const baseUrl = credentials?.baseURL || credentials?.baseUrl;
47
+ return { apiToken, baseUrl };
48
+ }
37
49
  /**
38
50
  * Replicate LLM Provider — predict-then-stream pattern.
39
51
  *
@@ -63,12 +75,12 @@ export class ReplicateProvider extends BaseProvider {
63
75
  constructor(modelName, sdk, _region, credentials) {
64
76
  const validatedNeurolink = isNeuroLink(sdk) ? sdk : undefined;
65
77
  super(modelName, "replicate", validatedNeurolink);
66
- const overrideToken = credentials?.apiToken?.trim();
78
+ const { apiToken: overrideToken, baseUrl: overrideBaseUrl } = resolveReplicateCredentials(credentials);
67
79
  this.apiToken =
68
80
  overrideToken && overrideToken.length > 0
69
81
  ? overrideToken
70
82
  : validateApiKey(createReplicateConfig());
71
- this.baseURL = credentials?.baseUrl;
83
+ this.baseURL = overrideBaseUrl;
72
84
  logger.debug("Replicate Provider initialized", {
73
85
  modelName: this.modelName,
74
86
  baseURL: this.baseURL,
@@ -109,7 +121,7 @@ export class ReplicateProvider extends BaseProvider {
109
121
  const options = typeof optionsOrPrompt === "string"
110
122
  ? { prompt: optionsOrPrompt }
111
123
  : optionsOrPrompt;
112
- const { IMAGE_GENERATION_MODELS } = await import("../core/constants.js");
124
+ const { isImageGenerationModel } = await import("../core/constants.js");
113
125
  // Delegate special output modes to base class (which never calls getAISDKModel for these)
114
126
  if (options.output?.mode === "video" ||
115
127
  options.output?.mode === "avatar" ||
@@ -117,7 +129,7 @@ export class ReplicateProvider extends BaseProvider {
117
129
  return super.generate(options, _analysisSchema);
118
130
  }
119
131
  // Image-gen models: delegate to base which calls executeImageGeneration()
120
- const isImageModel = IMAGE_GENERATION_MODELS.some((m) => this.modelName.includes(m));
132
+ const isImageModel = isImageGenerationModel(this.modelName);
121
133
  const requestsNonImageOutput = options.output?.format === "json" ||
122
134
  options.output?.format === "structured" ||
123
135
  options.output?.format === "text";
@@ -175,8 +187,9 @@ export class ReplicateProvider extends BaseProvider {
175
187
  const startTime = Date.now();
176
188
  // Resolve per-call credentials first, then fall back to instance-level.
177
189
  const perCallCreds = options.credentials?.replicate;
178
- const effectiveToken = perCallCreds?.apiToken?.trim() || this.apiToken;
179
- const effectiveBaseUrl = perCallCreds?.baseUrl || this.baseURL;
190
+ const resolvedPerCall = resolveReplicateCredentials(perCallCreds);
191
+ const effectiveToken = resolvedPerCall.apiToken || this.apiToken;
192
+ const effectiveBaseUrl = resolvedPerCall.baseUrl || this.baseURL;
180
193
  const auth = getReplicateAuth({
181
194
  apiToken: effectiveToken,
182
195
  baseUrl: effectiveBaseUrl,
@@ -255,8 +268,9 @@ export class ReplicateProvider extends BaseProvider {
255
268
  const startTime = Date.now();
256
269
  // Resolve per-call credentials first, then fall back to instance-level.
257
270
  const perCallCreds = options.credentials?.replicate;
258
- const effectiveToken = perCallCreds?.apiToken?.trim() || this.apiToken;
259
- const effectiveBaseUrl = perCallCreds?.baseUrl || this.baseURL;
271
+ const resolvedPerCall = resolveReplicateCredentials(perCallCreds);
272
+ const effectiveToken = resolvedPerCall.apiToken || this.apiToken;
273
+ const effectiveBaseUrl = resolvedPerCall.baseUrl || this.baseURL;
260
274
  const auth = getReplicateAuth({
261
275
  apiToken: effectiveToken,
262
276
  baseUrl: effectiveBaseUrl,
@@ -399,5 +413,4 @@ export class ReplicateProvider extends BaseProvider {
399
413
  };
400
414
  }
401
415
  }
402
- export default ReplicateProvider;
403
416
  //# sourceMappingURL=replicate.js.map
@@ -44,4 +44,3 @@ export declare class VoyageProvider extends BaseProvider {
44
44
  baseURL: string;
45
45
  };
46
46
  }
47
- export default VoyageProvider;
@@ -173,5 +173,4 @@ export class VoyageProvider extends BaseProvider {
173
173
  };
174
174
  }
175
175
  }
176
- export default VoyageProvider;
177
176
  //# sourceMappingURL=voyage.js.map
@@ -60,7 +60,6 @@ export * from "./tools.js";
60
60
  export * from "./vectorStoreChroma.js";
61
61
  export * from "./vectorStorePinecone.js";
62
62
  export * from "./voice.js";
63
- export * from "./universalProviderOptions.js";
64
63
  export * from "./utilities.js";
65
64
  export * from "./workflow.js";
66
65
  export * from "./ioProcessor.js";
@@ -61,7 +61,6 @@ export * from "./tools.js";
61
61
  export * from "./vectorStoreChroma.js";
62
62
  export * from "./vectorStorePinecone.js";
63
63
  export * from "./voice.js";
64
- export * from "./universalProviderOptions.js";
65
64
  export * from "./utilities.js";
66
65
  export * from "./workflow.js";
67
66
  // Processor base types are re-exported via ./processor.js
@@ -200,6 +200,8 @@ export type NeurolinkCredentials = {
200
200
  replicate?: {
201
201
  apiToken?: string;
202
202
  baseUrl?: string;
203
+ apiKey?: string;
204
+ baseURL?: string;
203
205
  };
204
206
  voyage?: {
205
207
  apiKey?: string;
@@ -1531,17 +1533,6 @@ export declare namespace TelemetryTypes {
1531
1533
  recordException(exception: unknown): void;
1532
1534
  };
1533
1535
  }
1534
- /**
1535
- * OpenRouter provider configuration
1536
- */
1537
- export type OpenRouterConfig = {
1538
- /** OpenRouter API key */
1539
- apiKey: string;
1540
- /** HTTP Referer header for attribution on openrouter.ai/activity */
1541
- referer?: string;
1542
- /** App name for X-Title header attribution */
1543
- appName?: string;
1544
- };
1545
1536
  /**
1546
1537
  * OpenRouter model information from /api/v1/models endpoint
1547
1538
  */
@@ -279,3 +279,32 @@ export type JsonCoercionResult = {
279
279
  */
280
280
  truncated: boolean;
281
281
  };
282
+ /**
283
+ * Decision returned by `recoverScalarRoot`. Each caller applies it to its own
284
+ * result shape and logger prefix, preserving its existing warning behaviour:
285
+ *
286
+ * - `empty` — the text is a JSON-encoded empty string (an EMPTY
287
+ * completion, not a recovered scalar). Callers normalize to a
288
+ * true empty.
289
+ * - `accepted` — a scalar root the caller's schema accepts; safe to publish
290
+ * as `structuredData`.
291
+ * - `rejected` — a scalar root the caller's schema rejects (e.g. a raw
292
+ * string under an object schema — the shape a truncated
293
+ * response degrades to). Do NOT publish it.
294
+ * - `nullish` — the text is the JSON literals `null`/`undefined`; there is
295
+ * no structured value to publish.
296
+ * - `not-json` — the text is not JSON at all.
297
+ */
298
+ export type ScalarRecoveryDecision = {
299
+ kind: "empty";
300
+ } | {
301
+ kind: "accepted";
302
+ value: unknown;
303
+ } | {
304
+ kind: "rejected";
305
+ value: unknown;
306
+ } | {
307
+ kind: "nullish";
308
+ } | {
309
+ kind: "not-json";
310
+ };
@@ -1,4 +1,24 @@
1
- import type { JsonCoercionResult, ValidationSchema } from "../../types/index.js";
1
+ import type { JsonCoercionResult, ScalarRecoveryDecision, ValidationSchema } from "../../types/index.js";
2
+ /**
3
+ * Does `value` satisfy `schema`? A schema we cannot validate with (absent, or
4
+ * without a Zod-style `safeParse`) accepts everything — callers use this as a
5
+ * gate, not as proof, so an unknown schema must never block a value.
6
+ *
7
+ * Exists so the consumers of coerceJsonToSchema can refuse to publish a
8
+ * recovered value as `structuredData` when the caller's schema rejects it —
9
+ * e.g. a raw *string* under an object schema, which is the shape a truncated
10
+ * response degrades to.
11
+ */
12
+ export declare function schemaAccepts(schema: ValidationSchema | undefined, value: unknown): boolean;
13
+ /**
14
+ * Recover a JSON *scalar* root (string/number/boolean) from model text. The
15
+ * object/array case is handled by `coerceJsonToSchema`; this covers the
16
+ * residual scalar root after that path returns null. Encapsulates the JSON
17
+ * parsing, the empty-string normalization, and the `schemaAccepts` gate so the
18
+ * same policy cannot drift between consumers (`neurolink.recoverStructuredData`
19
+ * and `GenerationHandler.coerceTextMode`).
20
+ */
21
+ export declare function recoverScalarRoot(text: string, schema: ValidationSchema | undefined): ScalarRecoveryDecision;
2
22
  /**
3
23
  * Try to produce canonical JSON from `text`. Returns null when no JSON object
4
24
  * could be recovered (caller should then keep the raw text).