@juspay/neurolink 11.2.1 → 11.2.3

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 (43) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/browser/neurolink.min.js +392 -392
  3. package/dist/factories/providerRegistry.d.ts +16 -4
  4. package/dist/factories/providerRegistry.js +70 -48
  5. package/dist/lib/factories/providerRegistry.d.ts +16 -4
  6. package/dist/lib/factories/providerRegistry.js +70 -48
  7. package/dist/lib/providers/configuredOpenAICompat.js +10 -3
  8. package/dist/lib/providers/openaiChatCompletionsBase.js +26 -14
  9. package/dist/lib/providers/openaiCompatCatalog.js +9 -11
  10. package/dist/lib/types/providers.d.ts +15 -1
  11. package/dist/providers/configuredOpenAICompat.js +10 -3
  12. package/dist/providers/openaiChatCompletionsBase.js +26 -14
  13. package/dist/providers/openaiCompatCatalog.js +9 -11
  14. package/dist/types/providers.d.ts +15 -1
  15. package/package.json +3 -2
  16. package/dist/lib/providers/cloudflare.d.ts +0 -26
  17. package/dist/lib/providers/cloudflare.js +0 -83
  18. package/dist/lib/providers/fireworks.d.ts +0 -22
  19. package/dist/lib/providers/fireworks.js +0 -73
  20. package/dist/lib/providers/groq.d.ts +0 -24
  21. package/dist/lib/providers/groq.js +0 -83
  22. package/dist/lib/providers/mistral.d.ts +0 -25
  23. package/dist/lib/providers/mistral.js +0 -87
  24. package/dist/lib/providers/perplexity.d.ts +0 -24
  25. package/dist/lib/providers/perplexity.js +0 -69
  26. package/dist/lib/providers/togetherAi.d.ts +0 -23
  27. package/dist/lib/providers/togetherAi.js +0 -73
  28. package/dist/lib/providers/xai.d.ts +0 -22
  29. package/dist/lib/providers/xai.js +0 -77
  30. package/dist/providers/cloudflare.d.ts +0 -26
  31. package/dist/providers/cloudflare.js +0 -82
  32. package/dist/providers/fireworks.d.ts +0 -22
  33. package/dist/providers/fireworks.js +0 -72
  34. package/dist/providers/groq.d.ts +0 -24
  35. package/dist/providers/groq.js +0 -82
  36. package/dist/providers/mistral.d.ts +0 -25
  37. package/dist/providers/mistral.js +0 -86
  38. package/dist/providers/perplexity.d.ts +0 -24
  39. package/dist/providers/perplexity.js +0 -68
  40. package/dist/providers/togetherAi.d.ts +0 -23
  41. package/dist/providers/togetherAi.js +0 -72
  42. package/dist/providers/xai.d.ts +0 -22
  43. package/dist/providers/xai.js +0 -76
@@ -1,73 +0,0 @@
1
- import { TogetherAIModels } from "../constants/enums.js";
2
- import { AuthenticationError } from "../types/index.js";
3
- import { logger } from "../utils/logger.js";
4
- import { redactUrlCredentials } from "../utils/logSanitize.js";
5
- import { classifyProviderError, DEFAULT_ERROR_RULES, } from "../utils/errorClassifier.js";
6
- import { createTogetherAIConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
7
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
8
- const TOGETHER_DEFAULT_BASE_URL = "https://api.together.xyz/v1";
9
- const getTogetherApiKey = () => validateApiKey(createTogetherAIConfig());
10
- const getDefaultTogetherModel = () => getProviderModel("TOGETHER_MODEL", TogetherAIModels.LLAMA_3_3_70B_INSTRUCT_TURBO);
11
- /**
12
- * Together AI Provider — direct HTTP, no AI SDK.
13
- *
14
- * Hosted open-model gateway at api.together.xyz/v1 (OpenAI-compatible).
15
- * Llama / Mistral / Qwen / DeepSeek / Gemma / WizardLM available
16
- * server-less; pass any catalog id via `--model`.
17
- * All request/stream/tool-loop orchestration lives in
18
- * `OpenAIChatCompletionsProvider`; this class only declares configuration
19
- * and provider-specific error mapping.
20
- *
21
- * @see https://docs.together.ai/docs/openai-api-compatibility
22
- */
23
- export class TogetherAIProvider extends OpenAIChatCompletionsProvider {
24
- constructor(modelName, sdk, _region, credentials) {
25
- const overrideApiKey = credentials?.apiKey?.trim();
26
- const apiKey = overrideApiKey && overrideApiKey.length > 0
27
- ? overrideApiKey
28
- : getTogetherApiKey();
29
- const baseURL = credentials?.baseURL?.trim() ||
30
- process.env.TOGETHER_BASE_URL?.trim() ||
31
- TOGETHER_DEFAULT_BASE_URL;
32
- super("together-ai", modelName, sdk, { baseURL, apiKey });
33
- logger.debug("Together AI Provider initialized", {
34
- modelName: this.modelName,
35
- providerName: this.providerName,
36
- baseURL: redactUrlCredentials(this.config.baseURL),
37
- });
38
- }
39
- getProviderName() {
40
- return "together-ai";
41
- }
42
- getDefaultModel() {
43
- return getDefaultTogetherModel();
44
- }
45
- getFallbackModelName() {
46
- return TogetherAIModels.LLAMA_3_1_8B_INSTRUCT_TURBO;
47
- }
48
- getFallbackModels() {
49
- return [
50
- TogetherAIModels.LLAMA_3_3_70B_INSTRUCT_TURBO,
51
- TogetherAIModels.LLAMA_3_1_405B_INSTRUCT_TURBO,
52
- TogetherAIModels.LLAMA_3_1_70B_INSTRUCT_TURBO,
53
- TogetherAIModels.LLAMA_3_1_8B_INSTRUCT_TURBO,
54
- TogetherAIModels.MIXTRAL_8X22B_INSTRUCT,
55
- TogetherAIModels.QWEN_2_5_72B_INSTRUCT_TURBO,
56
- TogetherAIModels.DEEPSEEK_R1,
57
- TogetherAIModels.DEEPSEEK_V3,
58
- ];
59
- }
60
- formatProviderError(error) {
61
- const rules = [
62
- {
63
- match: (ctx) => ctx.statusCode === 401 ||
64
- /Invalid API key|Authentication/i.test(ctx.message),
65
- errorClass: AuthenticationError,
66
- message: "Invalid Together AI API key. Get one at https://api.together.xyz/settings/api-keys",
67
- },
68
- ...DEFAULT_ERROR_RULES,
69
- ];
70
- return classifyProviderError(error, rules, "together-ai", this.modelName);
71
- }
72
- }
73
- //# sourceMappingURL=togetherAi.js.map
@@ -1,22 +0,0 @@
1
- import type { AIProviderName } from "../constants/enums.js";
2
- import type { NeurolinkCredentials } from "../types/index.js";
3
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
4
- /**
5
- * xAI Grok Provider — direct HTTP, no AI SDK.
6
- *
7
- * OpenAI-compatible chat completions at api.x.ai/v1 (Grok family:
8
- * grok-3, grok-3-mini, grok-2-latest, grok-2-vision-latest, grok-beta).
9
- * All request/stream/tool-loop orchestration lives in
10
- * `OpenAIChatCompletionsProvider`; this class only declares configuration
11
- * and provider-specific error mapping.
12
- *
13
- * @see https://docs.x.ai/api
14
- */
15
- export declare class XaiProvider extends OpenAIChatCompletionsProvider {
16
- constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["xai"]);
17
- protected getProviderName(): AIProviderName;
18
- protected getDefaultModel(): string;
19
- protected getFallbackModelName(): string;
20
- protected getFallbackModels(): string[];
21
- protected formatProviderError(error: unknown): Error;
22
- }
@@ -1,77 +0,0 @@
1
- import { XaiModels } from "../constants/enums.js";
2
- import { AuthenticationError, ProviderError } from "../types/index.js";
3
- import { logger } from "../utils/logger.js";
4
- import { redactUrlCredentials } from "../utils/logSanitize.js";
5
- import { classifyProviderError, DEFAULT_ERROR_RULES, } from "../utils/errorClassifier.js";
6
- import { createXaiConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
7
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
8
- const XAI_DEFAULT_BASE_URL = "https://api.x.ai/v1";
9
- const getXaiApiKey = () => validateApiKey(createXaiConfig());
10
- const getDefaultXaiModel = () => getProviderModel("XAI_MODEL", XaiModels.GROK_3);
11
- /**
12
- * xAI Grok Provider — direct HTTP, no AI SDK.
13
- *
14
- * OpenAI-compatible chat completions at api.x.ai/v1 (Grok family:
15
- * grok-3, grok-3-mini, grok-2-latest, grok-2-vision-latest, grok-beta).
16
- * All request/stream/tool-loop orchestration lives in
17
- * `OpenAIChatCompletionsProvider`; this class only declares configuration
18
- * and provider-specific error mapping.
19
- *
20
- * @see https://docs.x.ai/api
21
- */
22
- export class XaiProvider extends OpenAIChatCompletionsProvider {
23
- constructor(modelName, sdk, _region, credentials) {
24
- // Trim the override before applying precedence. A blank/whitespace
25
- // `credentials.apiKey` must NOT bypass the env key — that would build a
26
- // client with an unusable bearer token and fail at request time.
27
- const overrideApiKey = credentials?.apiKey?.trim();
28
- const apiKey = overrideApiKey && overrideApiKey.length > 0
29
- ? overrideApiKey
30
- : getXaiApiKey();
31
- const baseURL = credentials?.baseURL?.trim() ||
32
- process.env.XAI_BASE_URL?.trim() ||
33
- XAI_DEFAULT_BASE_URL;
34
- super("xai", modelName, sdk, { baseURL, apiKey });
35
- logger.debug("xAI Provider initialized", {
36
- modelName: this.modelName,
37
- providerName: this.providerName,
38
- baseURL: redactUrlCredentials(this.config.baseURL),
39
- });
40
- }
41
- getProviderName() {
42
- return "xai";
43
- }
44
- getDefaultModel() {
45
- return getDefaultXaiModel();
46
- }
47
- getFallbackModelName() {
48
- return XaiModels.GROK_3_MINI;
49
- }
50
- getFallbackModels() {
51
- return [
52
- XaiModels.GROK_3,
53
- XaiModels.GROK_3_MINI,
54
- XaiModels.GROK_2_LATEST,
55
- XaiModels.GROK_2_VISION_LATEST,
56
- XaiModels.GROK_BETA,
57
- ];
58
- }
59
- formatProviderError(error) {
60
- const rules = [
61
- {
62
- match: (ctx) => ctx.statusCode === 401 ||
63
- /Invalid API key|Authentication|invalid_api_key/i.test(ctx.message),
64
- errorClass: AuthenticationError,
65
- message: "Invalid xAI API key. Please check your XAI_API_KEY environment variable. Get one at https://console.x.ai/",
66
- },
67
- {
68
- match: (ctx) => /insufficient_quota|quota exceeded/i.test(ctx.message),
69
- errorClass: ProviderError,
70
- message: "xAI account has insufficient quota. Top up at https://console.x.ai/",
71
- },
72
- ...DEFAULT_ERROR_RULES,
73
- ];
74
- return classifyProviderError(error, rules, "xai", this.modelName);
75
- }
76
- }
77
- //# sourceMappingURL=xai.js.map
@@ -1,26 +0,0 @@
1
- import type { AIProviderName } from "../constants/enums.js";
2
- import type { NeurolinkCredentials } from "../types/index.js";
3
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
4
- /**
5
- * Cloudflare Workers AI Provider — direct HTTP, no AI SDK.
6
- *
7
- * Edge-served open models (Llama / Mistral / Qwen / Gemma) at
8
- * `https://api.cloudflare.com/client/v4/accounts/{accountId}/ai/v1`
9
- * (OpenAI-compatible). Cheapest tier for high-volume usage.
10
- *
11
- * Required env: `CLOUDFLARE_API_KEY` + `CLOUDFLARE_ACCOUNT_ID`.
12
- *
13
- * All request/stream/tool-loop orchestration lives in
14
- * `OpenAIChatCompletionsProvider`; this class only declares configuration
15
- * and provider-specific error mapping.
16
- *
17
- * @see https://developers.cloudflare.com/workers-ai/configuration/open-ai-compatibility/
18
- */
19
- export declare class CloudflareProvider extends OpenAIChatCompletionsProvider {
20
- constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["cloudflare"]);
21
- protected getProviderName(): AIProviderName;
22
- protected getDefaultModel(): string;
23
- protected getFallbackModelName(): string;
24
- protected getFallbackModels(): string[];
25
- protected formatProviderError(error: unknown): Error;
26
- }
@@ -1,82 +0,0 @@
1
- import { CloudflareModels } from "../constants/enums.js";
2
- import { AuthenticationError } from "../types/index.js";
3
- import { logger } from "../utils/logger.js";
4
- import { redactUrlCredentials } from "../utils/logSanitize.js";
5
- import { classifyProviderError, DEFAULT_ERROR_RULES, } from "../utils/errorClassifier.js";
6
- import { createCloudflareConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
7
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
8
- /**
9
- * Cloudflare Workers AI exposes an OpenAI-compatible endpoint scoped per
10
- * account: `https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/v1`.
11
- * The account id is required — without it the URL would 404.
12
- */
13
- const buildCloudflareBaseURL = (accountId) => `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai/v1`;
14
- const getCloudflareApiKey = () => validateApiKey(createCloudflareConfig());
15
- const getDefaultCloudflareModel = () => getProviderModel("CLOUDFLARE_MODEL", CloudflareModels.LLAMA_3_3_70B_FAST);
16
- /**
17
- * Cloudflare Workers AI Provider — direct HTTP, no AI SDK.
18
- *
19
- * Edge-served open models (Llama / Mistral / Qwen / Gemma) at
20
- * `https://api.cloudflare.com/client/v4/accounts/{accountId}/ai/v1`
21
- * (OpenAI-compatible). Cheapest tier for high-volume usage.
22
- *
23
- * Required env: `CLOUDFLARE_API_KEY` + `CLOUDFLARE_ACCOUNT_ID`.
24
- *
25
- * All request/stream/tool-loop orchestration lives in
26
- * `OpenAIChatCompletionsProvider`; this class only declares configuration
27
- * and provider-specific error mapping.
28
- *
29
- * @see https://developers.cloudflare.com/workers-ai/configuration/open-ai-compatibility/
30
- */
31
- export class CloudflareProvider extends OpenAIChatCompletionsProvider {
32
- constructor(modelName, sdk, _region, credentials) {
33
- const overrideApiKey = credentials?.apiKey?.trim();
34
- const apiKey = overrideApiKey && overrideApiKey.length > 0
35
- ? overrideApiKey
36
- : getCloudflareApiKey();
37
- const accountId = (credentials?.accountId ??
38
- process.env.CLOUDFLARE_ACCOUNT_ID ??
39
- "").trim();
40
- if (!accountId) {
41
- throw new Error("CLOUDFLARE_ACCOUNT_ID is required (or pass credentials.cloudflare.accountId). Get the account id from https://dash.cloudflare.com/");
42
- }
43
- const baseURL = credentials?.baseURL ?? buildCloudflareBaseURL(accountId);
44
- super("cloudflare", modelName, sdk, { baseURL, apiKey });
45
- logger.debug("Cloudflare Workers AI Provider initialized", {
46
- modelName: this.modelName,
47
- providerName: this.providerName,
48
- baseURL: redactUrlCredentials(this.config.baseURL),
49
- });
50
- }
51
- getProviderName() {
52
- return "cloudflare";
53
- }
54
- getDefaultModel() {
55
- return getDefaultCloudflareModel();
56
- }
57
- getFallbackModelName() {
58
- return CloudflareModels.LLAMA_3_1_8B_FAST;
59
- }
60
- getFallbackModels() {
61
- return [
62
- CloudflareModels.LLAMA_3_3_70B_FAST,
63
- CloudflareModels.LLAMA_3_1_70B_INSTRUCT,
64
- CloudflareModels.LLAMA_3_1_8B_FAST,
65
- CloudflareModels.LLAMA_3_2_11B_VISION,
66
- CloudflareModels.MISTRAL_7B_INSTRUCT_V0_2,
67
- CloudflareModels.QWEN_1P5_14B_CHAT_AWQ,
68
- ];
69
- }
70
- formatProviderError(error) {
71
- const rules = [
72
- {
73
- match: (ctx) => ctx.statusCode === 401 ||
74
- /Invalid API key|Authentication/i.test(ctx.message),
75
- errorClass: AuthenticationError,
76
- message: "Invalid Cloudflare API key. Use a token with Workers AI Read+Write scope. Get one at https://dash.cloudflare.com/profile/api-tokens",
77
- },
78
- ...DEFAULT_ERROR_RULES,
79
- ];
80
- return classifyProviderError(error, rules, "cloudflare", this.modelName);
81
- }
82
- }
@@ -1,22 +0,0 @@
1
- import type { AIProviderName } from "../constants/enums.js";
2
- import type { NeurolinkCredentials } from "../types/index.js";
3
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
4
- /**
5
- * Fireworks AI Provider — direct HTTP, no AI SDK.
6
- *
7
- * Hosted open-model serving at api.fireworks.ai/inference/v1
8
- * (OpenAI-compatible). Best for low-latency at scale on Llama / Mixtral /
9
- * Qwen / DeepSeek. All request/stream/tool-loop orchestration lives in
10
- * `OpenAIChatCompletionsProvider`; this class only declares configuration
11
- * and provider-specific error mapping.
12
- *
13
- * @see https://docs.fireworks.ai/api-reference/introduction
14
- */
15
- export declare class FireworksProvider extends OpenAIChatCompletionsProvider {
16
- constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["fireworks"]);
17
- protected getProviderName(): AIProviderName;
18
- protected getDefaultModel(): string;
19
- protected getFallbackModelName(): string;
20
- protected getFallbackModels(): string[];
21
- protected formatProviderError(error: unknown): Error;
22
- }
@@ -1,72 +0,0 @@
1
- import { FireworksModels } from "../constants/enums.js";
2
- import { AuthenticationError } from "../types/index.js";
3
- import { logger } from "../utils/logger.js";
4
- import { redactUrlCredentials } from "../utils/logSanitize.js";
5
- import { classifyProviderError, DEFAULT_ERROR_RULES, } from "../utils/errorClassifier.js";
6
- import { createFireworksConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
7
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
8
- const FIREWORKS_DEFAULT_BASE_URL = "https://api.fireworks.ai/inference/v1";
9
- const getFireworksApiKey = () => validateApiKey(createFireworksConfig());
10
- const getDefaultFireworksModel = () => getProviderModel("FIREWORKS_MODEL", FireworksModels.DEEPSEEK_V4_PRO);
11
- /**
12
- * Fireworks AI Provider — direct HTTP, no AI SDK.
13
- *
14
- * Hosted open-model serving at api.fireworks.ai/inference/v1
15
- * (OpenAI-compatible). Best for low-latency at scale on Llama / Mixtral /
16
- * Qwen / DeepSeek. All request/stream/tool-loop orchestration lives in
17
- * `OpenAIChatCompletionsProvider`; this class only declares configuration
18
- * and provider-specific error mapping.
19
- *
20
- * @see https://docs.fireworks.ai/api-reference/introduction
21
- */
22
- export class FireworksProvider extends OpenAIChatCompletionsProvider {
23
- constructor(modelName, sdk, _region, credentials) {
24
- // Trim the override before applying precedence. A blank/whitespace
25
- // `credentials.apiKey` must NOT bypass the env key — that would build a
26
- // client with an unusable bearer token and fail at request time.
27
- const overrideApiKey = credentials?.apiKey?.trim();
28
- const apiKey = overrideApiKey && overrideApiKey.length > 0
29
- ? overrideApiKey
30
- : getFireworksApiKey();
31
- const baseURL = credentials?.baseURL?.trim() ||
32
- process.env.FIREWORKS_BASE_URL?.trim() ||
33
- FIREWORKS_DEFAULT_BASE_URL;
34
- super("fireworks", modelName, sdk, { baseURL, apiKey });
35
- logger.debug("Fireworks Provider initialized", {
36
- modelName: this.modelName,
37
- providerName: this.providerName,
38
- baseURL: redactUrlCredentials(this.config.baseURL),
39
- });
40
- }
41
- getProviderName() {
42
- return "fireworks";
43
- }
44
- getDefaultModel() {
45
- return getDefaultFireworksModel();
46
- }
47
- getFallbackModelName() {
48
- return FireworksModels.DEEPSEEK_V4_PRO;
49
- }
50
- getFallbackModels() {
51
- return [
52
- FireworksModels.DEEPSEEK_V4_PRO,
53
- FireworksModels.GLM_5P1,
54
- FireworksModels.GLM_5,
55
- FireworksModels.KIMI_K2P6,
56
- FireworksModels.KIMI_K2P5,
57
- FireworksModels.GPT_OSS_120B,
58
- ];
59
- }
60
- formatProviderError(error) {
61
- const rules = [
62
- {
63
- match: (ctx) => ctx.statusCode === 401 ||
64
- /Invalid API key|Authentication/i.test(ctx.message),
65
- errorClass: AuthenticationError,
66
- message: "Invalid Fireworks API key. Get one at https://fireworks.ai/account/api-keys",
67
- },
68
- ...DEFAULT_ERROR_RULES,
69
- ];
70
- return classifyProviderError(error, rules, "fireworks", this.modelName);
71
- }
72
- }
@@ -1,24 +0,0 @@
1
- import type { AIProviderName } from "../constants/enums.js";
2
- import type { NeurolinkCredentials } from "../types/index.js";
3
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
4
- /**
5
- * Groq Provider — direct HTTP, no AI SDK.
6
- *
7
- * Sub-100ms inference of Llama / Mistral / Gemma at api.groq.com/openai/v1
8
- * (OpenAI-compatible). Best for low-latency tier; trade-off vs other open
9
- * model hosts is throughput latency, not quality.
10
- *
11
- * All request/stream/tool-loop orchestration lives in
12
- * `OpenAIChatCompletionsProvider`; this class only declares configuration
13
- * and provider-specific error mapping.
14
- *
15
- * @see https://console.groq.com/docs/quickstart
16
- */
17
- export declare class GroqProvider extends OpenAIChatCompletionsProvider {
18
- constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["groq"]);
19
- protected getProviderName(): AIProviderName;
20
- protected getDefaultModel(): string;
21
- protected getFallbackModelName(): string;
22
- protected getFallbackModels(): string[];
23
- protected formatProviderError(error: unknown): Error;
24
- }
@@ -1,82 +0,0 @@
1
- import { GroqModels } from "../constants/enums.js";
2
- import { AuthenticationError, InvalidModelError, ProviderError, } from "../types/index.js";
3
- import { logger } from "../utils/logger.js";
4
- import { redactUrlCredentials } from "../utils/logSanitize.js";
5
- import { classifyProviderError, DEFAULT_ERROR_RULES, } from "../utils/errorClassifier.js";
6
- import { createGroqConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
7
- import { TimeoutError } from "../utils/timeout.js";
8
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
9
- const GROQ_DEFAULT_BASE_URL = "https://api.groq.com/openai/v1";
10
- const getGroqApiKey = () => validateApiKey(createGroqConfig());
11
- const getDefaultGroqModel = () => getProviderModel("GROQ_MODEL", GroqModels.LLAMA_3_3_70B_VERSATILE);
12
- /**
13
- * Groq Provider — direct HTTP, no AI SDK.
14
- *
15
- * Sub-100ms inference of Llama / Mistral / Gemma at api.groq.com/openai/v1
16
- * (OpenAI-compatible). Best for low-latency tier; trade-off vs other open
17
- * model hosts is throughput latency, not quality.
18
- *
19
- * All request/stream/tool-loop orchestration lives in
20
- * `OpenAIChatCompletionsProvider`; this class only declares configuration
21
- * and provider-specific error mapping.
22
- *
23
- * @see https://console.groq.com/docs/quickstart
24
- */
25
- export class GroqProvider extends OpenAIChatCompletionsProvider {
26
- constructor(modelName, sdk, _region, credentials) {
27
- const overrideApiKey = credentials?.apiKey?.trim();
28
- const apiKey = overrideApiKey && overrideApiKey.length > 0
29
- ? overrideApiKey
30
- : getGroqApiKey();
31
- const baseURL = credentials?.baseURL?.trim() ||
32
- process.env.GROQ_BASE_URL?.trim() ||
33
- GROQ_DEFAULT_BASE_URL;
34
- super("groq", modelName, sdk, { baseURL, apiKey });
35
- logger.debug("Groq Provider initialized", {
36
- modelName: this.modelName,
37
- providerName: this.providerName,
38
- baseURL: redactUrlCredentials(this.config.baseURL),
39
- });
40
- }
41
- getProviderName() {
42
- return "groq";
43
- }
44
- getDefaultModel() {
45
- return getDefaultGroqModel();
46
- }
47
- getFallbackModelName() {
48
- return GroqModels.LLAMA_3_1_8B_INSTANT;
49
- }
50
- getFallbackModels() {
51
- return [
52
- GroqModels.LLAMA_3_3_70B_VERSATILE,
53
- GroqModels.LLAMA_3_1_8B_INSTANT,
54
- GroqModels.GEMMA_2_9B_IT,
55
- GroqModels.MIXTRAL_8X7B_32768,
56
- GroqModels.LLAMA_3_2_90B_VISION_PREVIEW,
57
- GroqModels.LLAMA_3_2_11B_VISION_PREVIEW,
58
- ];
59
- }
60
- formatProviderError(error) {
61
- // Groq's TimeoutError maps to plain ProviderError (not NetworkError, the
62
- // classifier's built-in default) — intercept before delegating.
63
- if (error instanceof TimeoutError) {
64
- return new ProviderError(`Groq request timed out: ${error.message}`, "groq");
65
- }
66
- const rules = [
67
- {
68
- match: (ctx) => ctx.statusCode === 401 ||
69
- /Invalid API key|Authentication|invalid_api_key/i.test(ctx.message),
70
- errorClass: AuthenticationError,
71
- message: "Invalid Groq API key. Check GROQ_API_KEY. Get one at https://console.groq.com/keys",
72
- },
73
- {
74
- match: (ctx) => /model_decommissioned/i.test(ctx.message),
75
- errorClass: InvalidModelError,
76
- message: (ctx) => `Groq model '${ctx.modelName}' was decommissioned. Pick a current model from https://console.groq.com/docs/models.`,
77
- },
78
- ...DEFAULT_ERROR_RULES,
79
- ];
80
- return classifyProviderError(error, rules, "groq", this.modelName);
81
- }
82
- }
@@ -1,25 +0,0 @@
1
- import type { AIProviderName } from "../constants/enums.js";
2
- import type { NeurolinkCredentials } from "../types/index.js";
3
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
4
- /**
5
- * Mistral AI Provider — direct HTTP, no AI SDK.
6
- *
7
- * OpenAI-compatible chat completions at api.mistral.ai/v1. All request/stream/
8
- * tool-loop orchestration lives in `OpenAIChatCompletionsProvider`; this class
9
- * only declares configuration and the provider-specific error mapping.
10
- *
11
- * Mistral's `/chat/completions` accepts `response_format: { type:
12
- * "json_schema" }` on current models (mistral-small-2506 and newer), so no
13
- * structured-output downgrade is needed — the base client's default
14
- * pass-through is correct.
15
- *
16
- * @see https://docs.mistral.ai/api/
17
- */
18
- export declare class MistralProvider extends OpenAIChatCompletionsProvider {
19
- constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["mistral"]);
20
- protected getProviderName(): AIProviderName;
21
- protected getDefaultModel(): string;
22
- protected formatProviderError(error: unknown): Error;
23
- protected getFallbackModelName(): string;
24
- protected getFallbackModels(): string[];
25
- }
@@ -1,86 +0,0 @@
1
- import { MistralModels } from "../constants/enums.js";
2
- import { AuthenticationError } from "../types/index.js";
3
- import { logger } from "../utils/logger.js";
4
- import { redactUrlCredentials } from "../utils/logSanitize.js";
5
- import { classifyProviderError, DEFAULT_ERROR_RULES, } from "../utils/errorClassifier.js";
6
- import { createMistralConfig, getProviderModel, validateApiKey, } from "../utils/providerConfig.js";
7
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
8
- const MISTRAL_DEFAULT_BASE_URL = "https://api.mistral.ai/v1";
9
- const getMistralApiKey = () => {
10
- return validateApiKey(createMistralConfig());
11
- };
12
- const getDefaultMistralModel = () => {
13
- // Vision-capable Mistral Small (June 2025) with multimodal support.
14
- return getProviderModel("MISTRAL_MODEL", MistralModels.MISTRAL_SMALL_2506);
15
- };
16
- /**
17
- * Mistral AI Provider — direct HTTP, no AI SDK.
18
- *
19
- * OpenAI-compatible chat completions at api.mistral.ai/v1. All request/stream/
20
- * tool-loop orchestration lives in `OpenAIChatCompletionsProvider`; this class
21
- * only declares configuration and the provider-specific error mapping.
22
- *
23
- * Mistral's `/chat/completions` accepts `response_format: { type:
24
- * "json_schema" }` on current models (mistral-small-2506 and newer), so no
25
- * structured-output downgrade is needed — the base client's default
26
- * pass-through is correct.
27
- *
28
- * @see https://docs.mistral.ai/api/
29
- */
30
- export class MistralProvider extends OpenAIChatCompletionsProvider {
31
- constructor(modelName, sdk, _region, credentials) {
32
- // Trim the override before applying precedence. A blank/whitespace
33
- // `credentials.apiKey` must NOT bypass `getMistralApiKey()` — that would
34
- // build a client with an unusable bearer token and fail at request time
35
- // with a confusing 401 instead of at construction time.
36
- const overrideApiKey = credentials?.apiKey?.trim();
37
- const apiKey = overrideApiKey && overrideApiKey.length > 0
38
- ? overrideApiKey
39
- : getMistralApiKey();
40
- // Treat blank/whitespace overrides as unset so an empty
41
- // `credentials.baseURL` or `MISTRAL_BASE_URL=` cannot silently override
42
- // the default with "" (mirrors the apiKey precedence above).
43
- const baseURL = credentials?.baseURL?.trim() ||
44
- process.env.MISTRAL_BASE_URL?.trim() ||
45
- MISTRAL_DEFAULT_BASE_URL;
46
- super("mistral", modelName, sdk, { baseURL, apiKey });
47
- logger.debug("Mistral Provider initialized", {
48
- modelName: this.modelName,
49
- providerName: this.providerName,
50
- baseURL: redactUrlCredentials(this.config.baseURL),
51
- });
52
- }
53
- // ===========================================================================
54
- // Abstract hooks (required)
55
- // ===========================================================================
56
- getProviderName() {
57
- return "mistral";
58
- }
59
- getDefaultModel() {
60
- return getDefaultMistralModel();
61
- }
62
- formatProviderError(error) {
63
- const rules = [
64
- {
65
- match: (ctx) => ctx.statusCode === 401 ||
66
- /API_KEY_INVALID|Invalid API key|Unauthorized/i.test(ctx.message),
67
- errorClass: AuthenticationError,
68
- message: "Invalid Mistral API key. Please check your MISTRAL_API_KEY environment variable.",
69
- },
70
- ...DEFAULT_ERROR_RULES,
71
- ];
72
- return classifyProviderError(error, rules, "mistral", this.modelName);
73
- }
74
- // ===========================================================================
75
- // Optional hooks
76
- // ===========================================================================
77
- getFallbackModelName() {
78
- return MistralModels.MISTRAL_SMALL_2506;
79
- }
80
- getFallbackModels() {
81
- return [
82
- MistralModels.MISTRAL_SMALL_2506,
83
- MistralModels.MISTRAL_LARGE_LATEST,
84
- ];
85
- }
86
- }
@@ -1,24 +0,0 @@
1
- import type { AIProviderName } from "../constants/enums.js";
2
- import type { NeurolinkCredentials } from "../types/index.js";
3
- import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
4
- /**
5
- * Perplexity Provider — direct HTTP, no AI SDK.
6
- *
7
- * Sonar models with built-in web grounding. OpenAI-compatible chat
8
- * completions at api.perplexity.ai. Best for queries that need fresh
9
- * web context (search-augmented answers). Citation data, if the API returns
10
- * any, is not extracted or exposed by this provider.
11
- *
12
- * All request/stream/tool-loop orchestration lives in
13
- * `OpenAIChatCompletionsProvider`; this class only declares configuration
14
- * and provider-specific error mapping.
15
- *
16
- * @see https://docs.perplexity.ai/api-reference/chat-completions
17
- */
18
- export declare class PerplexityProvider extends OpenAIChatCompletionsProvider {
19
- constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["perplexity"]);
20
- protected getProviderName(): AIProviderName;
21
- protected getDefaultModel(): string;
22
- protected getFallbackModels(): string[];
23
- protected formatProviderError(error: unknown): Error;
24
- }