@ai-sdk/xai 4.0.6 → 4.0.8

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 8e006de: fix: send reasoning effort `none` to the xAI API when the top-level `reasoning: 'none'` option is set
8
+ - 8e006de: fix: omit the reasoning effort parameter and emit an unsupported warning when the top-level `reasoning` option is used with xAI models that reject it (`grok-4.20-reasoning`, `grok-4.20-non-reasoning`, and dated variants)
9
+
10
+ ## 4.0.7
11
+
12
+ ### Patch Changes
13
+
14
+ - 5520b8a: Emit provider-executed tool results for completed xAI Responses API streaming tool calls.
15
+
3
16
  ## 4.0.6
4
17
 
5
18
  ### Patch Changes
package/dist/index.js CHANGED
@@ -222,6 +222,12 @@ function mapXaiFinishReason(finishReason) {
222
222
  }
223
223
  }
224
224
 
225
+ // src/supports-reasoning-effort.ts
226
+ var modelsWithoutReasoningEffort = /^grok-4\.20(-\d{4})?-(non-)?reasoning$/;
227
+ function supportsReasoningEffort(modelId) {
228
+ return !modelsWithoutReasoningEffort.test(modelId);
229
+ }
230
+
225
231
  // src/xai-chat-language-model-options.ts
226
232
  import { z } from "zod/v4";
227
233
  var webSourceSchema = z.object({
@@ -472,7 +478,7 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
472
478
  tools,
473
479
  toolChoice
474
480
  }) {
475
- var _a, _b, _c, _d;
481
+ var _a, _b, _c;
476
482
  const warnings = [];
477
483
  const options = (_a = await parseProviderOptions({
478
484
  provider: "xai",
@@ -502,6 +508,30 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
502
508
  toolChoice
503
509
  });
504
510
  warnings.push(...toolWarnings);
511
+ let reasoningEffort = options.reasoningEffort;
512
+ if (reasoningEffort == null && isCustomReasoning(reasoning)) {
513
+ if (!supportsReasoningEffort(this.modelId)) {
514
+ warnings.push({
515
+ type: "unsupported",
516
+ feature: "reasoning",
517
+ details: `reasoning "${reasoning}" is not supported by this model.`
518
+ });
519
+ } else if (reasoning === "none") {
520
+ reasoningEffort = "none";
521
+ } else {
522
+ reasoningEffort = mapReasoningToProviderEffort({
523
+ reasoning,
524
+ effortMap: {
525
+ minimal: "low",
526
+ low: "low",
527
+ medium: "medium",
528
+ high: "high",
529
+ xhigh: "high"
530
+ },
531
+ warnings
532
+ });
533
+ }
534
+ }
505
535
  const baseArgs = {
506
536
  // model id
507
537
  model: this.modelId,
@@ -512,24 +542,14 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
512
542
  temperature,
513
543
  top_p: topP,
514
544
  seed,
515
- reasoning_effort: (_b = options.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning === "none" ? void 0 : mapReasoningToProviderEffort({
516
- reasoning,
517
- effortMap: {
518
- minimal: "low",
519
- low: "low",
520
- medium: "medium",
521
- high: "high",
522
- xhigh: "high"
523
- },
524
- warnings
525
- }) : void 0,
545
+ reasoning_effort: reasoningEffort,
526
546
  // parallel function calling
527
547
  parallel_function_calling: options.parallel_function_calling,
528
548
  // response format
529
549
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
530
550
  type: "json_schema",
531
551
  json_schema: {
532
- name: (_c = responseFormat.name) != null ? _c : "response",
552
+ name: (_b = responseFormat.name) != null ? _b : "response",
533
553
  schema: responseFormat.schema,
534
554
  strict: true
535
555
  }
@@ -541,7 +561,7 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
541
561
  from_date: options.searchParameters.fromDate,
542
562
  to_date: options.searchParameters.toDate,
543
563
  max_search_results: options.searchParameters.maxSearchResults,
544
- sources: (_d = options.searchParameters.sources) == null ? void 0 : _d.map((source) => {
564
+ sources: (_c = options.searchParameters.sources) == null ? void 0 : _c.map((source) => {
545
565
  var _a2;
546
566
  return {
547
567
  type: source.type,
@@ -2234,7 +2254,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2234
2254
  toolChoice,
2235
2255
  reasoning
2236
2256
  }) {
2237
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2257
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2238
2258
  const warnings = [];
2239
2259
  const options = (_a = await parseProviderOptions3({
2240
2260
  provider: "xai",
@@ -2281,17 +2301,30 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2281
2301
  include = [...include, "reasoning.encrypted_content"];
2282
2302
  }
2283
2303
  }
2284
- const resolvedReasoningEffort = (_h = options.reasoningEffort) != null ? _h : isCustomReasoning2(reasoning) ? reasoning === "none" ? void 0 : mapReasoningToProviderEffort2({
2285
- reasoning,
2286
- effortMap: {
2287
- minimal: "low",
2288
- low: "low",
2289
- medium: "medium",
2290
- high: "high",
2291
- xhigh: "high"
2292
- },
2293
- warnings
2294
- }) : void 0;
2304
+ let resolvedReasoningEffort = options.reasoningEffort;
2305
+ if (resolvedReasoningEffort == null && isCustomReasoning2(reasoning)) {
2306
+ if (!supportsReasoningEffort(this.modelId)) {
2307
+ warnings.push({
2308
+ type: "unsupported",
2309
+ feature: "reasoning",
2310
+ details: `reasoning "${reasoning}" is not supported by this model.`
2311
+ });
2312
+ } else if (reasoning === "none") {
2313
+ resolvedReasoningEffort = "none";
2314
+ } else {
2315
+ resolvedReasoningEffort = mapReasoningToProviderEffort2({
2316
+ reasoning,
2317
+ effortMap: {
2318
+ minimal: "low",
2319
+ low: "low",
2320
+ medium: "medium",
2321
+ high: "high",
2322
+ xhigh: "high"
2323
+ },
2324
+ warnings
2325
+ });
2326
+ }
2327
+ }
2295
2328
  const baseArgs = {
2296
2329
  model: this.modelId,
2297
2330
  input,
@@ -2306,7 +2339,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2306
2339
  format: responseFormat.schema != null ? {
2307
2340
  type: "json_schema",
2308
2341
  strict: true,
2309
- name: (_i = responseFormat.name) != null ? _i : "response",
2342
+ name: (_h = responseFormat.name) != null ? _h : "response",
2310
2343
  description: responseFormat.description,
2311
2344
  schema: responseFormat.schema
2312
2345
  } : { type: "json_object" }
@@ -2870,6 +2903,14 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2870
2903
  providerExecuted: true
2871
2904
  });
2872
2905
  }
2906
+ if (event.type === "response.output_item.done") {
2907
+ controller.enqueue({
2908
+ type: "tool-result",
2909
+ toolCallId: part.id,
2910
+ toolName,
2911
+ result: {}
2912
+ });
2913
+ }
2873
2914
  return;
2874
2915
  }
2875
2916
  if (part.type === "message") {
@@ -3393,7 +3434,7 @@ var xaiTools = {
3393
3434
  };
3394
3435
 
3395
3436
  // src/version.ts
3396
- var VERSION = true ? "4.0.6" : "0.0.0-test";
3437
+ var VERSION = true ? "4.0.8" : "0.0.0-test";
3397
3438
 
3398
3439
  // src/files/xai-files.ts
3399
3440
  import {