@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.
- package/CHANGELOG.md +32 -0
- package/dist/browser/neurolink.min.js +399 -401
- package/dist/cli/commands/setup.d.ts +16 -1
- package/dist/cli/commands/setup.js +141 -3
- package/dist/core/baseProvider.js +3 -3
- package/dist/core/dynamicModels.d.ts +1 -1
- package/dist/core/dynamicModels.js +1 -23
- package/dist/core/modelConfiguration.d.ts +1 -70
- package/dist/core/modelConfiguration.js +0 -303
- package/dist/core/modules/GenerationHandler.js +38 -16
- package/dist/core/modules/structuredOutputPolicy.d.ts +2 -2
- package/dist/core/modules/structuredOutputPolicy.js +2 -2
- package/dist/factories/providerFactory.d.ts +15 -0
- package/dist/factories/providerFactory.js +27 -39
- package/dist/factories/providerRegistry.js +2 -2
- package/dist/lib/core/baseProvider.js +3 -3
- package/dist/lib/core/dynamicModels.d.ts +1 -1
- package/dist/lib/core/dynamicModels.js +1 -23
- package/dist/lib/core/modelConfiguration.d.ts +1 -70
- package/dist/lib/core/modelConfiguration.js +0 -303
- package/dist/lib/core/modules/GenerationHandler.js +38 -16
- package/dist/lib/core/modules/structuredOutputPolicy.d.ts +2 -2
- package/dist/lib/core/modules/structuredOutputPolicy.js +2 -2
- package/dist/lib/factories/providerFactory.d.ts +15 -0
- package/dist/lib/factories/providerFactory.js +27 -39
- package/dist/lib/factories/providerRegistry.js +2 -2
- package/dist/lib/models/anthropicModels.d.ts +0 -7
- package/dist/lib/models/anthropicModels.js +0 -9
- package/dist/lib/neurolink.d.ts +15 -0
- package/dist/lib/neurolink.js +77 -44
- package/dist/lib/providers/anthropic/client.js +17 -1
- package/dist/lib/providers/anthropic/constants.d.ts +0 -1
- package/dist/lib/providers/anthropic/constants.js +0 -2
- package/dist/lib/providers/anthropic/index.d.ts +0 -1
- package/dist/lib/providers/anthropic/index.js +0 -1
- package/dist/lib/providers/googleAiStudio/index.d.ts +0 -1
- package/dist/lib/providers/googleAiStudio/index.js +0 -1
- package/dist/lib/providers/googleNativeGemini3/index.d.ts +0 -1
- package/dist/lib/providers/googleNativeGemini3/index.js +0 -1
- package/dist/lib/providers/googleVertex/client.d.ts +0 -51
- package/dist/lib/providers/googleVertex/client.js +0 -678
- package/dist/lib/providers/huggingFace/client.d.ts +1 -1
- package/dist/lib/providers/huggingFace/client.js +1 -1
- package/dist/lib/providers/huggingFace/index.d.ts +0 -1
- package/dist/lib/providers/huggingFace/index.js +0 -1
- package/dist/lib/providers/jina.d.ts +0 -1
- package/dist/lib/providers/jina.js +0 -1
- package/dist/lib/providers/litellm/index.d.ts +0 -2
- package/dist/lib/providers/litellm/index.js +0 -2
- package/dist/lib/providers/llamaCpp.d.ts +1 -0
- package/dist/lib/providers/llamaCpp.js +3 -0
- package/dist/lib/providers/lmStudio.js +3 -23
- package/dist/lib/providers/nvidiaNim/index.d.ts +0 -1
- package/dist/lib/providers/nvidiaNim/index.js +0 -1
- package/dist/lib/providers/ollama/client.js +1 -23
- package/dist/lib/providers/ollama/index.d.ts +0 -1
- package/dist/lib/providers/ollama/index.js +0 -1
- package/dist/lib/providers/openAI/index.d.ts +0 -2
- package/dist/lib/providers/openAI/index.js +0 -2
- package/dist/lib/providers/openRouter/utils.d.ts +0 -2
- package/dist/lib/providers/openRouter/utils.js +0 -12
- package/dist/lib/providers/openaiChatCompletionsBase.d.ts +9 -0
- package/dist/lib/providers/openaiChatCompletionsBase.js +33 -0
- package/dist/lib/providers/perplexity.d.ts +2 -1
- package/dist/lib/providers/perplexity.js +2 -1
- package/dist/lib/providers/replicate.d.ts +0 -1
- package/dist/lib/providers/replicate.js +22 -9
- package/dist/lib/providers/voyage.d.ts +0 -1
- package/dist/lib/providers/voyage.js +0 -1
- package/dist/lib/types/index.d.ts +0 -1
- package/dist/lib/types/index.js +0 -1
- package/dist/lib/types/providers.d.ts +2 -11
- package/dist/lib/types/utilities.d.ts +29 -0
- package/dist/lib/utils/json/coerce.d.ts +21 -1
- package/dist/lib/utils/json/coerce.js +148 -11
- package/dist/lib/utils/providerConfig.d.ts +0 -8
- package/dist/lib/utils/providerConfig.js +0 -37
- package/dist/lib/utils/providerUtils.js +1 -25
- package/dist/models/anthropicModels.d.ts +0 -7
- package/dist/models/anthropicModels.js +0 -9
- package/dist/neurolink.d.ts +15 -0
- package/dist/neurolink.js +77 -44
- package/dist/providers/anthropic/client.js +17 -1
- package/dist/providers/anthropic/constants.d.ts +0 -1
- package/dist/providers/anthropic/constants.js +0 -2
- package/dist/providers/anthropic/index.d.ts +0 -1
- package/dist/providers/anthropic/index.js +0 -1
- package/dist/providers/googleAiStudio/index.d.ts +0 -1
- package/dist/providers/googleAiStudio/index.js +0 -1
- package/dist/providers/googleNativeGemini3/index.d.ts +0 -1
- package/dist/providers/googleNativeGemini3/index.js +0 -1
- package/dist/providers/googleVertex/client.d.ts +0 -51
- package/dist/providers/googleVertex/client.js +0 -678
- package/dist/providers/huggingFace/client.d.ts +1 -1
- package/dist/providers/huggingFace/client.js +1 -1
- package/dist/providers/huggingFace/index.d.ts +0 -1
- package/dist/providers/huggingFace/index.js +0 -1
- package/dist/providers/jina.d.ts +0 -1
- package/dist/providers/jina.js +0 -1
- package/dist/providers/litellm/index.d.ts +0 -2
- package/dist/providers/litellm/index.js +0 -2
- package/dist/providers/llamaCpp.d.ts +1 -0
- package/dist/providers/llamaCpp.js +3 -0
- package/dist/providers/lmStudio.js +3 -23
- package/dist/providers/nvidiaNim/index.d.ts +0 -1
- package/dist/providers/nvidiaNim/index.js +0 -1
- package/dist/providers/ollama/client.js +1 -23
- package/dist/providers/ollama/index.d.ts +0 -1
- package/dist/providers/ollama/index.js +0 -1
- package/dist/providers/openAI/index.d.ts +0 -2
- package/dist/providers/openAI/index.js +0 -2
- package/dist/providers/openRouter/utils.d.ts +0 -2
- package/dist/providers/openRouter/utils.js +0 -12
- package/dist/providers/openaiChatCompletionsBase.d.ts +9 -0
- package/dist/providers/openaiChatCompletionsBase.js +33 -0
- package/dist/providers/perplexity.d.ts +2 -1
- package/dist/providers/perplexity.js +2 -1
- package/dist/providers/replicate.d.ts +0 -1
- package/dist/providers/replicate.js +22 -9
- package/dist/providers/voyage.d.ts +0 -1
- package/dist/providers/voyage.js +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/providers.d.ts +2 -11
- package/dist/types/utilities.d.ts +29 -0
- package/dist/utils/json/coerce.d.ts +21 -1
- package/dist/utils/json/coerce.js +148 -11
- package/dist/utils/providerConfig.d.ts +0 -8
- package/dist/utils/providerConfig.js +0 -37
- package/dist/utils/providerUtils.js +1 -25
- package/package.json +8 -6
- package/dist/lib/providers/anthropic/utils.d.ts +0 -7
- package/dist/lib/providers/anthropic/utils.js +0 -150
- package/dist/lib/providers/googleAiStudio/utils.d.ts +0 -2
- package/dist/lib/providers/googleAiStudio/utils.js +0 -19
- package/dist/lib/providers/googleNativeGemini3/constants.d.ts +0 -1
- package/dist/lib/providers/googleNativeGemini3/constants.js +0 -2
- package/dist/lib/providers/huggingFace/utils.d.ts +0 -2
- package/dist/lib/providers/huggingFace/utils.js +0 -8
- package/dist/lib/providers/index.d.ts +0 -33
- package/dist/lib/providers/index.js +0 -34
- package/dist/lib/providers/litellm/constants.d.ts +0 -1
- package/dist/lib/providers/litellm/constants.js +0 -3
- package/dist/lib/providers/litellm/utils.d.ts +0 -5
- package/dist/lib/providers/litellm/utils.js +0 -11
- package/dist/lib/providers/nvidiaNim/utils.d.ts +0 -9
- package/dist/lib/providers/nvidiaNim/utils.js +0 -101
- package/dist/lib/providers/ollama/utils.d.ts +0 -8
- package/dist/lib/providers/ollama/utils.js +0 -43
- package/dist/lib/providers/openAI/constants.d.ts +0 -1
- package/dist/lib/providers/openAI/constants.js +0 -3
- package/dist/lib/providers/openAI/utils.d.ts +0 -2
- package/dist/lib/providers/openAI/utils.js +0 -8
- package/dist/lib/types/universalProviderOptions.d.ts +0 -89
- package/dist/lib/types/universalProviderOptions.js +0 -55
- package/dist/providers/anthropic/utils.d.ts +0 -7
- package/dist/providers/anthropic/utils.js +0 -149
- package/dist/providers/googleAiStudio/utils.d.ts +0 -2
- package/dist/providers/googleAiStudio/utils.js +0 -18
- package/dist/providers/googleNativeGemini3/constants.d.ts +0 -1
- package/dist/providers/googleNativeGemini3/constants.js +0 -1
- package/dist/providers/huggingFace/utils.d.ts +0 -2
- package/dist/providers/huggingFace/utils.js +0 -7
- package/dist/providers/index.d.ts +0 -33
- package/dist/providers/index.js +0 -33
- package/dist/providers/litellm/constants.d.ts +0 -1
- package/dist/providers/litellm/constants.js +0 -2
- package/dist/providers/litellm/utils.d.ts +0 -5
- package/dist/providers/litellm/utils.js +0 -10
- package/dist/providers/nvidiaNim/utils.d.ts +0 -9
- package/dist/providers/nvidiaNim/utils.js +0 -100
- package/dist/providers/ollama/utils.d.ts +0 -8
- package/dist/providers/ollama/utils.js +0 -42
- package/dist/providers/openAI/constants.d.ts +0 -1
- package/dist/providers/openAI/constants.js +0 -2
- package/dist/providers/openAI/utils.d.ts +0 -2
- package/dist/providers/openAI/utils.js +0 -7
- package/dist/types/universalProviderOptions.d.ts +0 -89
- 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();
|
|
@@ -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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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 {
|
|
@@ -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
|
-
|
|
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,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
|
|
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
|
|
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
|
|
@@ -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
|
|
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 =
|
|
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 {
|
|
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 =
|
|
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
|
|
179
|
-
const
|
|
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
|
|
259
|
-
const
|
|
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
|
|
@@ -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";
|
package/dist/lib/types/index.js
CHANGED
|
@@ -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).
|