@juspay/neurolink 12.14.8 → 12.14.10

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 (35) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/dist/adapters/providerImageAdapter.js +1 -0
  3. package/dist/browser/neurolink.min.js +364 -364
  4. package/dist/cli/commands/config.js +2 -2
  5. package/dist/cli/commands/setup-huggingface.js +19 -11
  6. package/dist/core/modelConfiguration.d.ts +3 -3
  7. package/dist/core/modelConfiguration.js +6 -4
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.js +11 -0
  10. package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +43 -30
  11. package/dist/models/manifests/huggingface.d.ts +6 -3
  12. package/dist/models/manifests/huggingface.js +7 -4
  13. package/dist/neurolink.d.ts +4 -1
  14. package/dist/neurolink.js +41 -6
  15. package/dist/providers/azureOpenai.js +1 -1
  16. package/dist/providers/catalog/loader.d.ts +1 -1
  17. package/dist/providers/catalog/loader.js +30 -1
  18. package/dist/providers/cohere.js +1 -1
  19. package/dist/providers/deepseek.js +1 -1
  20. package/dist/providers/googleAiStudio/client.js +6 -5
  21. package/dist/providers/googleVertex/client.d.ts +11 -30
  22. package/dist/providers/googleVertex/client.js +49 -131
  23. package/dist/providers/huggingFace/client.d.ts +30 -7
  24. package/dist/providers/huggingFace/client.js +45 -27
  25. package/dist/providers/llamaCpp.js +1 -1
  26. package/dist/providers/lmStudio.js +1 -1
  27. package/dist/providers/nvidiaNim/client.js +1 -1
  28. package/dist/providers/ollama/client.js +1 -1
  29. package/dist/providers/openRouter/client.js +1 -1
  30. package/dist/providers/openaiCompatible/client.js +1 -1
  31. package/dist/utils/providerSetupMessages.js +2 -2
  32. package/dist/utils/timeout.d.ts +13 -2
  33. package/dist/utils/timeout.js +14 -3
  34. package/docs-site/static/search-index.json +1 -1
  35. package/package.json +1 -1
@@ -87,7 +87,7 @@ const ConfigSchema = z.object({
87
87
  huggingface: z
88
88
  .object({
89
89
  apiKey: z.string().optional(),
90
- model: z.string().default("microsoft/DialoGPT-large"),
90
+ model: z.string().default("Qwen/Qwen2.5-72B-Instruct"),
91
91
  })
92
92
  .optional(),
93
93
  ollama: z
@@ -783,7 +783,7 @@ export class ConfigManager {
783
783
  type: "input",
784
784
  name: "model",
785
785
  message: "Model name:",
786
- default: "microsoft/DialoGPT-large",
786
+ default: "Qwen/Qwen2.5-72B-Instruct",
787
787
  },
788
788
  ]);
789
789
  this.config.providers.huggingface = answers;
@@ -92,26 +92,34 @@ export const handleHuggingFaceSetup = async (argv) => {
92
92
  type: "select",
93
93
  name: "modelChoice",
94
94
  message: "Select a Hugging Face model:",
95
+ // Router-served ids only. The previous five options
96
+ // (DialoGPT-large/medium/small, blenderbot-400M-distill) are all
97
+ // absent from the router catalogue and answer 400 on every request,
98
+ // so this wizard wrote a dead model into the user's .env.
95
99
  choices: [
96
100
  {
97
- name: "Skip - use default (microsoft/DialoGPT-large)",
101
+ name: "Skip - use default (Qwen/Qwen2.5-72B-Instruct)",
98
102
  value: "default",
99
103
  },
100
104
  {
101
- name: "microsoft/DialoGPT-large (Conversational AI - Recommended)",
102
- value: "microsoft/DialoGPT-large",
105
+ name: "Qwen/Qwen2.5-72B-Instruct (Recommended - tool-capable)",
106
+ value: "Qwen/Qwen2.5-72B-Instruct",
103
107
  },
104
108
  {
105
- name: "microsoft/DialoGPT-medium (Faster, smaller)",
106
- value: "microsoft/DialoGPT-medium",
109
+ name: "meta-llama/Llama-3.1-8B-Instruct (Fastest)",
110
+ value: "meta-llama/Llama-3.1-8B-Instruct",
107
111
  },
108
112
  {
109
- name: "facebook/blenderbot-400M-distill (General purpose)",
110
- value: "facebook/blenderbot-400M-distill",
113
+ name: "meta-llama/Llama-3.3-70B-Instruct (Stronger reasoning)",
114
+ value: "meta-llama/Llama-3.3-70B-Instruct",
111
115
  },
112
116
  {
113
- name: "microsoft/DialoGPT-small (Fastest)",
114
- value: "microsoft/DialoGPT-small",
117
+ name: "deepseek-ai/DeepSeek-V3 (Highest quality)",
118
+ value: "deepseek-ai/DeepSeek-V3",
119
+ },
120
+ {
121
+ name: "Qwen/Qwen2.5-Coder-32B-Instruct (Code-focused)",
122
+ value: "Qwen/Qwen2.5-Coder-32B-Instruct",
115
123
  },
116
124
  {
117
125
  name: "Custom model name",
@@ -134,7 +142,7 @@ export const handleHuggingFaceSetup = async (argv) => {
134
142
  return "Model name is required";
135
143
  }
136
144
  if (!trimmed.includes("/")) {
137
- return "Model name should include organization (e.g., 'microsoft/DialoGPT-large')";
145
+ return "Model name should include organization (e.g., 'Qwen/Qwen2.5-72B-Instruct')";
138
146
  }
139
147
  return true;
140
148
  },
@@ -173,7 +181,7 @@ export const handleHuggingFaceSetup = async (argv) => {
173
181
  }
174
182
  else {
175
183
  logger.always(chalk.gray(' neurolink generate "Tell me a story" --provider huggingface'));
176
- logger.always(chalk.gray(' neurolink generate "Explain AI" --provider huggingface --model microsoft/DialoGPT-medium'));
184
+ logger.always(chalk.gray(' neurolink generate "Explain AI" --provider huggingface --model Qwen/Qwen2.5-72B-Instruct'));
177
185
  }
178
186
  logger.always(chalk.blue("\n🔗 Resources:"));
179
187
  logger.always(chalk.gray(" • Hugging Face Models: https://huggingface.co/models"));
@@ -51,9 +51,9 @@ export declare const MODEL_NAMES: {
51
51
  readonly QUALITY: "llama3.1:70b";
52
52
  };
53
53
  readonly HUGGINGFACE: {
54
- readonly FAST: "microsoft/DialoGPT-medium";
55
- readonly BALANCED: "microsoft/DialoGPT-large";
56
- readonly QUALITY: "meta-llama/Llama-2-7b-chat-hf";
54
+ readonly FAST: "meta-llama/Llama-3.1-8B-Instruct";
55
+ readonly BALANCED: "Qwen/Qwen2.5-72B-Instruct";
56
+ readonly QUALITY: "deepseek-ai/DeepSeek-V3";
57
57
  };
58
58
  readonly MISTRAL: {
59
59
  readonly FAST: "mistral-small-latest";
@@ -58,11 +58,13 @@ export const MODEL_NAMES = {
58
58
  BALANCED: "llama3.1:8b",
59
59
  QUALITY: "llama3.1:70b",
60
60
  },
61
- // HuggingFace Models
61
+ // HuggingFace Models — router-served ids. The previous three
62
+ // (DialoGPT-medium / -large, Llama-2-7b-chat-hf) are absent from the
63
+ // router catalogue and answer 400 on every request.
62
64
  HUGGINGFACE: {
63
- FAST: "microsoft/DialoGPT-medium",
64
- BALANCED: "microsoft/DialoGPT-large",
65
- QUALITY: "meta-llama/Llama-2-7b-chat-hf",
65
+ FAST: "meta-llama/Llama-3.1-8B-Instruct",
66
+ BALANCED: "Qwen/Qwen2.5-72B-Instruct",
67
+ QUALITY: "deepseek-ai/DeepSeek-V3",
66
68
  },
67
69
  // Mistral Models
68
70
  MISTRAL: {
package/dist/index.d.ts CHANGED
@@ -46,6 +46,7 @@ export { createApiKeyAuthInterceptor, createBearerAuthInterceptor, createDynamic
46
46
  export { SSEClient, WebSocketStreamingClient, createStreamingClient, createAsyncStream, collectStream, } from "./client/streamingClient.js";
47
47
  export { OAuth2TokenManager, JWTTokenManager, createApiKeyMiddleware, createBearerTokenMiddleware, createTokenManagerMiddleware, createAuthWithRetryMiddleware, createMultiAuthMiddleware, OAuth2Error, OAuth2AuthenticationError as OAuth2AuthError, TokenRefreshError, decodeJWTPayload, isJWTExpired, getJWTExpiry, getApiKeyFromEnv, } from "./client/auth.js";
48
48
  export { ErrorCode as ClientErrorCode, NeuroLinkError as ClientNeuroLinkError, HttpError, ClientRateLimitError, ClientValidationError, ClientAuthenticationError, ClientAuthorizationError, NotFoundError, ClientNetworkError, ClientTimeoutError, ClientConnectionError, AbortError, ClientConfigurationError, StreamError, ClientProviderError, ContextLengthError, ContentFilterError, createErrorFromResponse, createErrorFromNative, mapStatusToErrorCode, isRetryableStatus, isRetryableError, isNeuroLinkError, isApiError, } from "./client/errors.js";
49
+ export { BaseError, ProviderError, AuthenticationError, AuthorizationError, NetworkError, RateLimitError, InvalidModelError, } from "./types/index.js";
49
50
  export { AIProviderName, BedrockModels, OpenAIModels, VertexModels, } from "./constants/enums.js";
50
51
  export { dynamicModelProvider } from "./core/dynamicModels.js";
51
52
  export { validateTool } from "./sdk/toolRegistration.js";
package/dist/index.js CHANGED
@@ -73,6 +73,17 @@ OAuth2TokenManager, JWTTokenManager, createApiKeyMiddleware, createBearerTokenMi
73
73
  export {
74
74
  // Errors
75
75
  ErrorCode as ClientErrorCode, NeuroLinkError as ClientNeuroLinkError, HttpError, ClientRateLimitError, ClientValidationError, ClientAuthenticationError, ClientAuthorizationError, NotFoundError, ClientNetworkError, ClientTimeoutError, ClientConnectionError, AbortError, ClientConfigurationError, StreamError, ClientProviderError, ContextLengthError, ContentFilterError, createErrorFromResponse, createErrorFromNative, mapStatusToErrorCode, isRetryableStatus, isRetryableError, isNeuroLinkError, isApiError, } from "./client/errors.js";
76
+ // The SDK-side error hierarchy `classifyProviderError()` actually throws
77
+ // (as opposed to the unrelated `Client*` REST-client errors above). These
78
+ // already reach consumers transitively through `export * from
79
+ // "./types/index.js"` below, but that makes them public by accident of the
80
+ // types barrel's shape — a future reshuffle of that barrel could drop them
81
+ // silently. Exporting them here, explicitly, by name, makes the guarantee
82
+ // intentional: `catch (e) { if (e instanceof RateLimitError) ... }` against
83
+ // `@juspay/neurolink` is a supported, stable pattern, not an implementation
84
+ // detail a caller happened to be able to reach. Imported from the barrel
85
+ // (never the specific `types/errors.js` file) per Critical Rule 13.
86
+ export { BaseError, ProviderError, AuthenticationError, AuthorizationError, NetworkError, RateLimitError, InvalidModelError, } from "./types/index.js";
76
87
  export { AIProviderName, BedrockModels, OpenAIModels, VertexModels, } from "./constants/enums.js";
77
88
  // Dynamic Models exports
78
89
  export { dynamicModelProvider } from "./core/dynamicModels.js";
@@ -185,41 +185,54 @@ const _benchmarkProviderPerformanceTool = {
185
185
  ];
186
186
  const benchmarkResults = [];
187
187
  for (const providerName of providersToTest) {
188
- const provider = await AIProviderFactory.createProvider(providerName);
189
- if (!provider) {
188
+ try {
189
+ const provider = await AIProviderFactory.createProvider(providerName);
190
+ if (!provider) {
191
+ benchmarkResults.push({
192
+ provider: providerName,
193
+ error: "Failed to create provider.",
194
+ });
195
+ continue;
196
+ }
197
+ let totalLatency = 0, totalTokens = 0, successfulTests = 0;
198
+ for (const prompt of testPrompts) {
199
+ for (let i = 0; i < typedParams.iterations; i++) {
200
+ const testStartTime = Date.now();
201
+ const result = await provider.generate({
202
+ prompt: prompt,
203
+ maxTokens: typedParams.maxTokens,
204
+ });
205
+ if (result && result.usage) {
206
+ totalLatency += Date.now() - testStartTime;
207
+ totalTokens += result.usage.total || 0;
208
+ successfulTests++;
209
+ }
210
+ }
211
+ }
190
212
  benchmarkResults.push({
191
213
  provider: providerName,
192
- error: "Failed to create provider.",
214
+ metrics: {
215
+ avgLatency: successfulTests > 0
216
+ ? Math.round(totalLatency / successfulTests)
217
+ : 0,
218
+ total: totalTokens,
219
+ successRate: (successfulTests /
220
+ (testPrompts.length * typedParams.iterations)) *
221
+ 100,
222
+ },
193
223
  });
194
- continue;
195
224
  }
196
- let totalLatency = 0, totalTokens = 0, successfulTests = 0;
197
- for (const prompt of testPrompts) {
198
- for (let i = 0; i < typedParams.iterations; i++) {
199
- const testStartTime = Date.now();
200
- const result = await provider.generate({
201
- prompt: prompt,
202
- maxTokens: typedParams.maxTokens,
203
- });
204
- if (result && result.usage) {
205
- totalLatency += Date.now() - testStartTime;
206
- totalTokens += result.usage.total || 0;
207
- successfulTests++;
208
- }
209
- }
225
+ catch (providerError) {
226
+ // A single provider's failure (network, auth, rate-limit, etc.)
227
+ // must not abort the whole benchmark — record it and keep testing
228
+ // the remaining providers, mirroring the null-provider branch above.
229
+ benchmarkResults.push({
230
+ provider: providerName,
231
+ error: providerError instanceof Error
232
+ ? providerError.message
233
+ : String(providerError),
234
+ });
210
235
  }
211
- benchmarkResults.push({
212
- provider: providerName,
213
- metrics: {
214
- avgLatency: successfulTests > 0
215
- ? Math.round(totalLatency / successfulTests)
216
- : 0,
217
- total: totalTokens,
218
- successRate: (successfulTests /
219
- (testPrompts.length * typedParams.iterations)) *
220
- 100,
221
- },
222
- });
223
236
  }
224
237
  const executionTime = Date.now() - startTime;
225
238
  return {
@@ -1,8 +1,11 @@
1
1
  import type { ProviderModelManifest } from "../../types/index.js";
2
2
  /**
3
3
  * Minimal manifest: huggingface has no MODEL_REGISTRY entries today, so
4
- * only the provider-wide fallback is known. Named models can be added here
5
- * incrementally without touching any consumer — see Task 5 of the model
6
- * metadata consolidation plan.
4
+ * only the provider-wide fallback is known. `functionCalling` is true
5
+ * because the router serves tool-calling models and returns `tool_calls` for
6
+ * them; it previously claimed false, contradicting the wire.
7
+ *
8
+ * Named models can be added here incrementally without touching any
9
+ * consumer — see Task 5 of the model metadata consolidation plan.
7
10
  */
8
11
  export declare const huggingfaceManifest: ProviderModelManifest;
@@ -1,8 +1,11 @@
1
1
  /**
2
2
  * Minimal manifest: huggingface has no MODEL_REGISTRY entries today, so
3
- * only the provider-wide fallback is known. Named models can be added here
4
- * incrementally without touching any consumer — see Task 5 of the model
5
- * metadata consolidation plan.
3
+ * only the provider-wide fallback is known. `functionCalling` is true
4
+ * because the router serves tool-calling models and returns `tool_calls` for
5
+ * them; it previously claimed false, contradicting the wire.
6
+ *
7
+ * Named models can be added here incrementally without touching any
8
+ * consumer — see Task 5 of the model metadata consolidation plan.
6
9
  */
7
10
  export const huggingfaceManifest = {
8
11
  defaultContextWindow: 32000,
@@ -12,7 +15,7 @@ export const huggingfaceManifest = {
12
15
  contextWindow: 32000,
13
16
  maxOutputTokens: 32000,
14
17
  vision: false,
15
- functionCalling: false,
18
+ functionCalling: true,
16
19
  },
17
20
  },
18
21
  };
@@ -1648,7 +1648,10 @@ export declare class NeuroLink {
1648
1648
  */
1649
1649
  testProvider(providerName: string): Promise<boolean>;
1650
1650
  /**
1651
- * Internal method to test provider connection with minimal generation call
1651
+ * Internal method to test provider connection with minimal generation call.
1652
+ * `signal` lets a caller (getProviderStatus's per-provider race) cancel the
1653
+ * underlying request once it has already lost the race against its
1654
+ * timeout, instead of leaving it running unobserved.
1652
1655
  */
1653
1656
  private testProviderConnection;
1654
1657
  /**
package/dist/neurolink.js CHANGED
@@ -6490,6 +6490,14 @@ Current user's request: ${currentInput}`;
6490
6490
  if (lastError instanceof ContextBudgetExceededError) {
6491
6491
  throw lastError;
6492
6492
  }
6493
+ // A single-candidate list (an explicit provider, or
6494
+ // disableInternalFallback) never actually tried "all providers" —
6495
+ // naming the one provider that failed is clearer than the generic
6496
+ // multi-provider wording. The multi-provider prefix is left untouched
6497
+ // so existing message-matching suites keep passing.
6498
+ if (providersToTry.length === 1) {
6499
+ throw new Error(`Provider ${providersToTry[0]} failed: ${lastError?.message || "Unknown error"}`);
6500
+ }
6493
6501
  throw new Error(`Failed to generate text with all providers. Last error: ${lastError?.message || "Unknown error"}`);
6494
6502
  }
6495
6503
  /**
@@ -10863,13 +10871,36 @@ Current user's request: ${currentInput}`;
10863
10871
  };
10864
10872
  }
10865
10873
  }
10866
- // Test other providers with actual generation call
10874
+ // Test other providers with actual generation call. The losing
10875
+ // side of the race is aborted in `finally` below — previously the
10876
+ // timeout promise alone rejected while the still-running
10877
+ // testProviderConnection() call (and the provider request inside
10878
+ // it) kept executing to completion unobserved, wasting quota and
10879
+ // holding the connection open past the 5s status check.
10867
10880
  const testTimeout = 5000;
10868
- const testPromise = this.testProviderConnection(providerName);
10881
+ const abortController = new AbortController();
10882
+ const testPromise = this.testProviderConnection(providerName, abortController.signal);
10883
+ let timeoutHandle;
10869
10884
  const timeoutPromise = new Promise((_, reject) => {
10870
- setTimeout(() => reject(new Error("Provider test timeout (5s)")), testTimeout);
10885
+ timeoutHandle = setTimeout(() => {
10886
+ reject(new Error("Provider test timeout (5s)"));
10887
+ }, testTimeout);
10871
10888
  });
10872
- await Promise.race([testPromise, timeoutPromise]);
10889
+ try {
10890
+ await Promise.race([testPromise, timeoutPromise]);
10891
+ }
10892
+ finally {
10893
+ // Runs on both outcomes: clears the timer so it can't fire after
10894
+ // a fast success, and aborts the signal so a timed-out
10895
+ // generate() call stops instead of finishing unobserved.
10896
+ clearTimeout(timeoutHandle);
10897
+ // The aborted generate() resolves/rejects after the race is
10898
+ // decided; swallow that settlement so it can't surface as an
10899
+ // unhandledRejection, mirroring raceWithAbort's handling of the
10900
+ // losing side.
10901
+ testPromise.catch(() => undefined);
10902
+ abortController.abort();
10903
+ }
10873
10904
  return {
10874
10905
  provider: providerName,
10875
10906
  status: "working",
@@ -10919,15 +10950,19 @@ Current user's request: ${currentInput}`;
10919
10950
  }
10920
10951
  }
10921
10952
  /**
10922
- * Internal method to test provider connection with minimal generation call
10953
+ * Internal method to test provider connection with minimal generation call.
10954
+ * `signal` lets a caller (getProviderStatus's per-provider race) cancel the
10955
+ * underlying request once it has already lost the race against its
10956
+ * timeout, instead of leaving it running unobserved.
10923
10957
  */
10924
- async testProviderConnection(providerName) {
10958
+ async testProviderConnection(providerName, signal) {
10925
10959
  const { AIProviderFactory } = await import("./core/factory.js");
10926
10960
  const provider = await AIProviderFactory.createProvider(providerName, null);
10927
10961
  await provider.generate({
10928
10962
  prompt: "test",
10929
10963
  maxTokens: 1,
10930
10964
  disableTools: true,
10965
+ abortSignal: signal,
10931
10966
  });
10932
10967
  }
10933
10968
  /**
@@ -172,7 +172,7 @@ export class AzureOpenAIProvider extends OpenAIChatCompletionsProvider {
172
172
  },
173
173
  ...DEFAULT_ERROR_RULES,
174
174
  ];
175
- return classifyProviderError(error, rules, "azure", this.modelName);
175
+ return classifyProviderError(error, rules, this.providerName, this.modelName);
176
176
  }
177
177
  // ===========================================================================
178
178
  // New overridable hooks (provided by the base-enhancement branch)
@@ -2,5 +2,5 @@ import type { OpenAICompatCatalogEntry, ProviderCatalogJson, ProviderConfigOptio
2
2
  export declare function catalogCredentialsKey(entry: ProviderCatalogJson): string;
3
3
  export declare function catalogEnvVar(entry: ProviderCatalogJson, kind: "apiKey" | "baseURL" | "model"): string;
4
4
  export declare function buildCatalogConfigOptions(entry: ProviderCatalogJson): ProviderConfigOptions;
5
- export declare function getCatalogJsonEntries(): ProviderCatalogJson[];
5
+ export declare function getCatalogJsonEntries(): readonly ProviderCatalogJson[];
6
6
  export declare function buildCatalogEntries(): OpenAICompatCatalogEntry[];
@@ -70,8 +70,37 @@ function buildErrorRules(entry) {
70
70
  });
71
71
  return [...bespoke, ...DEFAULT_ERROR_RULES];
72
72
  }
73
+ // Recursively freezes a value in place and returns it. Used only on a
74
+ // structuredClone()d graph below — never on CATALOG_JSON_ENTRIES itself —
75
+ // so this never touches the module-level singleton.
76
+ function deepFreeze(value) {
77
+ if (Array.isArray(value)) {
78
+ for (const item of value) {
79
+ deepFreeze(item);
80
+ }
81
+ return Object.freeze(value);
82
+ }
83
+ if (value !== null && typeof value === "object") {
84
+ for (const key of Object.keys(value)) {
85
+ deepFreeze(value[key]);
86
+ }
87
+ return Object.freeze(value);
88
+ }
89
+ return value;
90
+ }
91
+ // Returns a deep clone of the catalog graph, frozen at every level, never
92
+ // the module-level singleton by reference or anything sharing its nested
93
+ // objects/arrays — CATALOG_JSON_ENTRIES is reused on every call, so handing
94
+ // out (a shallow copy of) the live array would let any one caller's
95
+ // mutation corrupt catalog state for the rest of the process, and freezing
96
+ // only the outer array left `entry.aliases`, `entry.models.fallbacks`,
97
+ // `entry.models.catalog` etc. shared and mutable despite the `readonly`
98
+ // return type. structuredClone() first (so the frozen graph never aliases
99
+ // CATALOG_JSON_ENTRIES's own objects), then deepFreeze() the clone. All
100
+ // current callers only .find/.map/.flatMap/.filter/iterate, so this is
101
+ // behavior-preserving for them.
73
102
  export function getCatalogJsonEntries() {
74
- return CATALOG_JSON_ENTRIES;
103
+ return deepFreeze(structuredClone(CATALOG_JSON_ENTRIES));
75
104
  }
76
105
  export function buildCatalogEntries() {
77
106
  return CATALOG_JSON_ENTRIES.map((entry) => {
@@ -87,7 +87,7 @@ export class CohereProvider extends OpenAIChatCompletionsProvider {
87
87
  },
88
88
  ...DEFAULT_ERROR_RULES,
89
89
  ];
90
- return classifyProviderError(error, rules, "cohere", this.modelName);
90
+ return classifyProviderError(error, rules, this.providerName, this.modelName);
91
91
  }
92
92
  async validateConfiguration() {
93
93
  return (typeof this.config.apiKey === "string" &&
@@ -89,7 +89,7 @@ export class DeepSeekProvider extends OpenAIChatCompletionsProvider {
89
89
  },
90
90
  ...DEFAULT_ERROR_RULES,
91
91
  ];
92
- return classifyProviderError(error, rules, "deepseek", this.modelName);
92
+ return classifyProviderError(error, rules, this.providerName, this.modelName);
93
93
  }
94
94
  // ===========================================================================
95
95
  // Optional hooks — provider-specific quirks
@@ -1289,12 +1289,13 @@ export class GoogleAIStudioProvider extends BaseProvider {
1289
1289
  ...options,
1290
1290
  tools: baseTools,
1291
1291
  };
1292
- // Check for tools + JSON schema conflict (Gemini limitation)
1292
+ // Check for tools + JSON schema conflict, via the shared predicate (same
1293
+ // gate executeStream() and executeNativeGemini3Generate() use) so this
1294
+ // path also honors isGeminiProvider/isNativeAnthropicProvider instead of
1295
+ // hand-rolling its own tools+schema condition.
1293
1296
  const wantsJsonOutput = options.output?.format === "json" || options.schema;
1294
- if (wantsJsonOutput &&
1295
- mergedOptions.tools &&
1296
- Object.keys(mergedOptions.tools).length > 0 &&
1297
- !mergedOptions.disableTools) {
1297
+ const exclusionInForce = isToolsSchemaExclusionInForce(this.providerName, modelName, !mergedOptions.disableTools, Object.keys(mergedOptions.tools ?? {}).length);
1298
+ if (wantsJsonOutput && exclusionInForce) {
1298
1299
  logger.warn("[GoogleAIStudio] Gemini does not support tools and JSON schema output simultaneously. Disabling tools for this request.");
1299
1300
  mergedOptions = { ...mergedOptions, disableTools: true, tools: {} };
1300
1301
  }
@@ -138,32 +138,6 @@ export declare class GoogleVertexProvider extends BaseProvider {
138
138
  * this purpose.
139
139
  */
140
140
  private resolveExpressApiKey;
141
- /**
142
- * Convert one AI-SDK tool into a Vertex Gemini function declaration.
143
- * Single source for the pre-loop snapshot AND the mid-turn discovery
144
- * refresh, so tools hydrated by search_tools get the exact same schema
145
- * treatment (inline, typed, additionalProperties stripped).
146
- */
147
- private buildGeminiFunctionDeclaration;
148
- /**
149
- * Mid-turn tool sync for the native Gemini loops. `search_tools` hydrates
150
- * discovered tools into the live `options.tools` record between steps, but
151
- * the loop's declarations + executeMap are a pre-loop snapshot — without
152
- * this refresh, a tool discovered this turn stays invisible to the rest of
153
- * the turn and every call to it dies as TOOL_NOT_FOUND. Mutates the
154
- * declaration array in place (the request config holds it by reference)
155
- * and clears breaker strikes accrued while the tool was still deferred.
156
- */
157
- private refreshGeminiToolDeclarations;
158
- /**
159
- * Dispatch-miss recovery for the native Gemini loops: the model called a
160
- * name missing from the executeMap snapshot. Re-read the live record (a
161
- * tool hydrated by search_tools in this very step batch) or auto-hydrate a
162
- * deferred catalog tool the model called directly by its advertised name.
163
- * Returns the dedup-wrapped executor, or undefined when the name is
164
- * genuinely unknown — callers keep TOOL_NOT_FOUND for that case.
165
- */
166
- private resolveGeminiToolOnMiss;
167
141
  /**
168
142
  * Convert one AI-SDK tool into an Anthropic (Claude-on-Vertex) tool
169
143
  * declaration. Single source for the pre-loop snapshot AND the mid-turn
@@ -174,18 +148,25 @@ export declare class GoogleVertexProvider extends BaseProvider {
174
148
  */
175
149
  private buildAnthropicToolDeclaration;
176
150
  /**
177
- * Mid-turn tool sync for the Claude-on-Vertex loops — the Anthropic
178
- * counterpart of refreshGeminiToolDeclarations. Claude only calls tools
151
+ * Mid-turn tool sync for the Claude-on-Vertex loops. Claude only calls tools
179
152
  * present in the request's `tools` array, so without this per-step refresh
180
153
  * a tool discovered via search_tools is unreachable for the rest of the
181
154
  * turn. Mutates the array in place (requestParams holds it by reference).
182
155
  */
183
156
  private refreshAnthropicToolDeclarations;
184
157
  /**
185
- * Dispatch-miss recovery for the Claude-on-Vertex loops — the Anthropic
186
- * counterpart of resolveGeminiToolOnMiss.
158
+ * Dispatch-miss recovery for the Claude-on-Vertex loops.
187
159
  */
188
160
  private resolveAnthropicToolOnMiss;
161
+ /**
162
+ * Build the synthetic `final_result` tool used to force structured output
163
+ * on Claude-on-Vertex. Anthropic has no native responseSchema, so a schema
164
+ * is instead enforced by requiring the model to call this tool with
165
+ * matching arguments. Single source for the non-streaming and streaming
166
+ * paths — both previously built this object independently from their own
167
+ * schema variable, byte-identical apart from that variable's name.
168
+ */
169
+ private buildFinalResultTool;
189
170
  /**
190
171
  * Execute stream using native @google/genai SDK for Gemini 3 models on Vertex AI
191
172
  * This bypasses @ai-sdk/google-vertex to properly handle thought_signature