@ai-sdk/xai 3.0.118 → 3.0.120

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/dist/index.mjs CHANGED
@@ -258,9 +258,10 @@ var searchSourceSchema = z2.discriminatedUnion("type", [
258
258
  rssSourceSchema
259
259
  ]);
260
260
  var xaiLanguageModelChatOptions = z2.object({
261
- reasoningEffort: z2.enum(["none", "low", "medium", "high"]).optional(),
261
+ reasoningEffort: z2.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
262
262
  logprobs: z2.boolean().optional(),
263
263
  topLogprobs: z2.number().int().min(0).max(8).optional(),
264
+ serviceTier: z2.enum(["default", "priority"]).optional(),
264
265
  /**
265
266
  * Whether to enable parallel function calling during tool use.
266
267
  * When true, the model can call multiple functions in parallel.
@@ -487,6 +488,8 @@ var XaiChatLanguageModel = class {
487
488
  top_p: topP,
488
489
  seed,
489
490
  reasoning_effort: options.reasoningEffort,
491
+ // scheduling priority
492
+ service_tier: options.serviceTier,
490
493
  // parallel function calling
491
494
  parallel_function_calling: options.parallel_function_calling,
492
495
  // response format
@@ -621,6 +624,11 @@ var XaiChatLanguageModel = class {
621
624
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
622
625
  outputTokens: { total: 0, text: 0, reasoning: 0 }
623
626
  },
627
+ ...response.service_tier != null && {
628
+ providerMetadata: {
629
+ xai: { serviceTier: response.service_tier }
630
+ }
631
+ },
624
632
  request: { body },
625
633
  response: {
626
634
  ...getResponseMetadata(response),
@@ -689,6 +697,7 @@ var XaiChatLanguageModel = class {
689
697
  raw: void 0
690
698
  };
691
699
  let usage = void 0;
700
+ let serviceTier = void 0;
692
701
  let isFirstChunk = true;
693
702
  const contentBlocks = {};
694
703
  const lastReasoningDeltas = {};
@@ -729,6 +738,9 @@ var XaiChatLanguageModel = class {
729
738
  if (value.usage != null) {
730
739
  usage = convertXaiChatUsage(value.usage);
731
740
  }
741
+ if (value.service_tier != null) {
742
+ serviceTier = value.service_tier;
743
+ }
732
744
  const choice = value.choices[0];
733
745
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
734
746
  finishReason = {
@@ -843,6 +855,9 @@ var XaiChatLanguageModel = class {
843
855
  cacheWrite: 0
844
856
  },
845
857
  outputTokens: { total: 0, text: 0, reasoning: 0 }
858
+ },
859
+ ...serviceTier != null && {
860
+ providerMetadata: { xai: { serviceTier } }
846
861
  }
847
862
  });
848
863
  }
@@ -898,6 +913,7 @@ var xaiChatResponseSchema = z4.object({
898
913
  object: z4.literal("chat.completion").nullish(),
899
914
  usage: xaiUsageSchema.nullish(),
900
915
  citations: z4.array(z4.string().url()).nullish(),
916
+ service_tier: z4.string().nullish(),
901
917
  code: z4.string().nullish(),
902
918
  error: z4.string().nullish()
903
919
  });
@@ -927,7 +943,8 @@ var xaiChatChunkSchema = z4.object({
927
943
  })
928
944
  ),
929
945
  usage: xaiUsageSchema.nullish(),
930
- citations: z4.array(z4.string().url()).nullish()
946
+ citations: z4.array(z4.string().url()).nullish(),
947
+ service_tier: z4.string().nullish()
931
948
  });
932
949
  var xaiStreamErrorSchema = z4.object({
933
950
  code: z4.string(),
@@ -1512,7 +1529,8 @@ var xaiResponsesResponseSchema = z7.object({
1512
1529
  object: z7.literal("response"),
1513
1530
  output: z7.array(outputItemSchema),
1514
1531
  usage: xaiResponsesUsageSchema.nullish(),
1515
- status: z7.string()
1532
+ status: z7.string(),
1533
+ service_tier: z7.string().nullish()
1516
1534
  });
1517
1535
  var xaiResponsesChunkSchema = z7.union([
1518
1536
  z7.object({
@@ -1780,7 +1798,8 @@ var xaiResponsesChunkSchema = z7.union([
1780
1798
  type: z7.literal("response.incomplete"),
1781
1799
  response: z7.object({
1782
1800
  incomplete_details: z7.object({ reason: z7.string() }).nullish(),
1783
- usage: xaiResponsesUsageSchema.nullish()
1801
+ usage: xaiResponsesUsageSchema.nullish(),
1802
+ service_tier: z7.string().nullish()
1784
1803
  })
1785
1804
  }),
1786
1805
  z7.object({
@@ -1816,12 +1835,14 @@ var xaiLanguageModelResponsesOptions = z8.object({
1816
1835
  /**
1817
1836
  * Constrains how hard a reasoning model thinks before responding.
1818
1837
  * Possible values are `none` (disables reasoning), `low` (uses fewer reasoning
1819
- * tokens), `medium` and `high` (uses more reasoning tokens). Not all models
1820
- * support reasoning effort; see xAI's docs for the values each model accepts.
1838
+ * tokens), `medium`, `high`, and `xhigh` (uses more reasoning tokens). Not all
1839
+ * models support reasoning effort; see xAI's docs for the values each model
1840
+ * accepts. `xhigh` is currently only supported by `grok-4.6`.
1821
1841
  */
1822
- reasoningEffort: z8.enum(["none", "low", "medium", "high"]).optional(),
1842
+ reasoningEffort: z8.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
1823
1843
  logprobs: z8.boolean().optional(),
1824
1844
  topLogprobs: z8.number().int().min(0).max(8).optional(),
1845
+ serviceTier: z8.enum(["default", "priority"]).optional(),
1825
1846
  /**
1826
1847
  * Whether to store the input message(s) and model response for later retrieval.
1827
1848
  * Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
@@ -2268,6 +2289,9 @@ var XaiResponsesLanguageModel = class {
2268
2289
  },
2269
2290
  ...options.previousResponseId != null && {
2270
2291
  previous_response_id: options.previousResponseId
2292
+ },
2293
+ ...options.serviceTier != null && {
2294
+ service_tier: options.serviceTier
2271
2295
  }
2272
2296
  };
2273
2297
  if (xaiTools2 && xaiTools2.length > 0) {
@@ -2444,6 +2468,11 @@ var XaiResponsesLanguageModel = class {
2444
2468
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
2445
2469
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2446
2470
  },
2471
+ ...response.service_tier != null && {
2472
+ providerMetadata: {
2473
+ xai: { serviceTier: response.service_tier }
2474
+ }
2475
+ },
2447
2476
  request: { body },
2448
2477
  response: {
2449
2478
  ...getResponseMetadata(response),
@@ -2485,6 +2514,7 @@ var XaiResponsesLanguageModel = class {
2485
2514
  };
2486
2515
  let hasFunctionCall = false;
2487
2516
  let usage = void 0;
2517
+ let serviceTier = void 0;
2488
2518
  let isFirstChunk = true;
2489
2519
  const contentBlocks = {};
2490
2520
  const seenToolCalls = /* @__PURE__ */ new Set();
@@ -2498,7 +2528,7 @@ var XaiResponsesLanguageModel = class {
2498
2528
  controller.enqueue({ type: "stream-start", warnings });
2499
2529
  },
2500
2530
  transform(chunk, controller) {
2501
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2531
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2502
2532
  if (options.includeRawChunks) {
2503
2533
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2504
2534
  }
@@ -2628,8 +2658,9 @@ var XaiResponsesLanguageModel = class {
2628
2658
  if (response2.usage) {
2629
2659
  usage = convertXaiResponsesUsage(response2.usage);
2630
2660
  }
2661
+ serviceTier = (_c = response2.service_tier) != null ? _c : void 0;
2631
2662
  if (event.type === "response.incomplete") {
2632
- const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
2663
+ const reason = "incomplete_details" in response2 ? (_d = response2.incomplete_details) == null ? void 0 : _d.reason : void 0;
2633
2664
  finishReason = {
2634
2665
  unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2635
2666
  raw: reason != null ? reason : "incomplete"
@@ -2643,7 +2674,7 @@ var XaiResponsesLanguageModel = class {
2643
2674
  return;
2644
2675
  }
2645
2676
  if (event.type === "response.failed") {
2646
- const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2677
+ const reason = (_e = event.response.incomplete_details) == null ? void 0 : _e.reason;
2647
2678
  finishReason = {
2648
2679
  unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2649
2680
  raw: reason != null ? reason : "error"
@@ -2739,13 +2770,13 @@ var XaiResponsesLanguageModel = class {
2739
2770
  toolCallId: part.id,
2740
2771
  toolName,
2741
2772
  result: {
2742
- queries: (_e = part.queries) != null ? _e : [],
2743
- results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
2773
+ queries: (_f = part.queries) != null ? _f : [],
2774
+ results: (_h = (_g = part.results) == null ? void 0 : _g.map((result) => ({
2744
2775
  fileId: result.file_id,
2745
2776
  filename: result.filename,
2746
2777
  score: result.score,
2747
2778
  text: result.text
2748
- }))) != null ? _g : null
2779
+ }))) != null ? _h : null
2749
2780
  }
2750
2781
  });
2751
2782
  }
@@ -2763,17 +2794,17 @@ var XaiResponsesLanguageModel = class {
2763
2794
  "x_semantic_search",
2764
2795
  "x_thread_fetch"
2765
2796
  ];
2766
- let toolName = (_h = part.name) != null ? _h : "";
2767
- if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
2797
+ let toolName = (_i = part.name) != null ? _i : "";
2798
+ if (webSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "web_search_call") {
2768
2799
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2769
- } else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
2800
+ } else if (xSearchSubTools.includes((_k = part.name) != null ? _k : "") || part.type === "x_search_call") {
2770
2801
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2771
2802
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2772
2803
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2773
2804
  } else if (part.type === "mcp_call") {
2774
- toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
2805
+ toolName = (_l = mcpToolName != null ? mcpToolName : part.name) != null ? _l : "mcp";
2775
2806
  }
2776
- const toolInput = part.type === "custom_tool_call" ? (_l = part.input) != null ? _l : "" : part.type === "mcp_call" ? (_m = part.arguments) != null ? _m : "" : (_n = part.arguments) != null ? _n : "";
2807
+ const toolInput = part.type === "custom_tool_call" ? (_m = part.input) != null ? _m : "" : part.type === "mcp_call" ? (_n = part.arguments) != null ? _n : "" : (_o = part.arguments) != null ? _o : "";
2777
2808
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2778
2809
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2779
2810
  seenToolCalls.add(part.id);
@@ -2834,7 +2865,7 @@ var XaiResponsesLanguageModel = class {
2834
2865
  sourceType: "url",
2835
2866
  id: self.config.generateId(),
2836
2867
  url: annotation.url,
2837
- title: (_o = annotation.title) != null ? _o : annotation.url
2868
+ title: (_p = annotation.title) != null ? _p : annotation.url
2838
2869
  });
2839
2870
  }
2840
2871
  }
@@ -2888,6 +2919,9 @@ var XaiResponsesLanguageModel = class {
2888
2919
  cacheWrite: 0
2889
2920
  },
2890
2921
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2922
+ },
2923
+ ...serviceTier != null && {
2924
+ providerMetadata: { xai: { serviceTier } }
2891
2925
  }
2892
2926
  });
2893
2927
  }
@@ -2954,7 +2988,7 @@ var xaiTools = {
2954
2988
  };
2955
2989
 
2956
2990
  // src/version.ts
2957
- var VERSION = true ? "3.0.118" : "0.0.0-test";
2991
+ var VERSION = true ? "3.0.120" : "0.0.0-test";
2958
2992
 
2959
2993
  // src/xai-video-model.ts
2960
2994
  import {