@ai-sdk/xai 3.0.0-beta.40 → 3.0.0-beta.42

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,17 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 3.0.0-beta.42
4
+
5
+ ### Patch Changes
6
+
7
+ - b39ec2c: Fix Responses API validation errors for server-side tools (web_search, x_search, code_execution). Add missing custom_tool_call type and streaming event schemas.
8
+
9
+ ## 3.0.0-beta.41
10
+
11
+ ### Patch Changes
12
+
13
+ - 248b540: fix(xai): responses model fixes
14
+
3
15
  ## 3.0.0-beta.40
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -57,11 +57,17 @@ declare const xaiErrorDataSchema: z.ZodObject<{
57
57
  type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
58
58
 
59
59
  type XaiResponsesModelId = 'grok-4' | 'grok-4-fast' | 'grok-4-fast-non-reasoning' | (string & {});
60
+ /**
61
+ * @see https://docs.x.ai/docs/api-reference#create-new-response
62
+ */
60
63
  declare const xaiResponsesProviderOptions: z.ZodObject<{
61
64
  reasoningEffort: z.ZodOptional<z.ZodEnum<{
62
65
  low: "low";
63
66
  high: "high";
67
+ medium: "medium";
64
68
  }>>;
69
+ store: z.ZodOptional<z.ZodBoolean>;
70
+ previousResponseId: z.ZodOptional<z.ZodString>;
65
71
  }, z.core.$strip>;
66
72
  type XaiResponsesProviderOptions = z.infer<typeof xaiResponsesProviderOptions>;
67
73
 
package/dist/index.d.ts CHANGED
@@ -57,11 +57,17 @@ declare const xaiErrorDataSchema: z.ZodObject<{
57
57
  type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
58
58
 
59
59
  type XaiResponsesModelId = 'grok-4' | 'grok-4-fast' | 'grok-4-fast-non-reasoning' | (string & {});
60
+ /**
61
+ * @see https://docs.x.ai/docs/api-reference#create-new-response
62
+ */
60
63
  declare const xaiResponsesProviderOptions: z.ZodObject<{
61
64
  reasoningEffort: z.ZodOptional<z.ZodEnum<{
62
65
  low: "low";
63
66
  high: "high";
67
+ medium: "medium";
64
68
  }>>;
69
+ store: z.ZodOptional<z.ZodBoolean>;
70
+ previousResponseId: z.ZodOptional<z.ZodString>;
65
71
  }, z.core.$strip>;
66
72
  type XaiResponsesProviderOptions = z.infer<typeof xaiResponsesProviderOptions>;
67
73
 
package/dist/index.js CHANGED
@@ -154,12 +154,14 @@ function convertToXaiChatMessages(prompt) {
154
154
  function getResponseMetadata({
155
155
  id,
156
156
  model,
157
- created
157
+ created,
158
+ created_at
158
159
  }) {
160
+ const unixTime = created != null ? created : created_at;
159
161
  return {
160
162
  id: id != null ? id : void 0,
161
163
  modelId: model != null ? model : void 0,
162
- timestamp: created != null ? new Date(created * 1e3) : void 0
164
+ timestamp: unixTime != null ? new Date(unixTime * 1e3) : void 0
163
165
  };
164
166
  }
165
167
 
@@ -797,12 +799,18 @@ var messageContentPartSchema = import_v44.z.object({
797
799
  logprobs: import_v44.z.array(import_v44.z.any()).optional(),
798
800
  annotations: import_v44.z.array(annotationSchema).optional()
799
801
  });
802
+ var reasoningSummaryPartSchema = import_v44.z.object({
803
+ type: import_v44.z.string(),
804
+ text: import_v44.z.string()
805
+ });
800
806
  var toolCallSchema = import_v44.z.object({
801
- name: import_v44.z.string(),
802
- arguments: import_v44.z.string(),
803
- call_id: import_v44.z.string(),
807
+ name: import_v44.z.string().optional(),
808
+ arguments: import_v44.z.string().optional(),
809
+ input: import_v44.z.string().optional(),
810
+ call_id: import_v44.z.string().optional(),
804
811
  id: import_v44.z.string(),
805
- status: import_v44.z.string()
812
+ status: import_v44.z.string(),
813
+ action: import_v44.z.any().optional()
806
814
  });
807
815
  var outputItemSchema = import_v44.z.discriminatedUnion("type", [
808
816
  import_v44.z.object({
@@ -829,6 +837,10 @@ var outputItemSchema = import_v44.z.discriminatedUnion("type", [
829
837
  type: import_v44.z.literal("view_x_video_call"),
830
838
  ...toolCallSchema.shape
831
839
  }),
840
+ import_v44.z.object({
841
+ type: import_v44.z.literal("custom_tool_call"),
842
+ ...toolCallSchema.shape
843
+ }),
832
844
  import_v44.z.object({
833
845
  type: import_v44.z.literal("message"),
834
846
  role: import_v44.z.string(),
@@ -842,6 +854,12 @@ var outputItemSchema = import_v44.z.discriminatedUnion("type", [
842
854
  arguments: import_v44.z.string(),
843
855
  call_id: import_v44.z.string(),
844
856
  id: import_v44.z.string()
857
+ }),
858
+ import_v44.z.object({
859
+ type: import_v44.z.literal("reasoning"),
860
+ id: import_v44.z.string(),
861
+ summary: import_v44.z.array(reasoningSummaryPartSchema),
862
+ status: import_v44.z.string()
845
863
  })
846
864
  ]);
847
865
  var xaiResponsesUsageSchema = import_v44.z.object({
@@ -924,6 +942,94 @@ var xaiResponsesChunkSchema = import_v44.z.union([
924
942
  annotation_index: import_v44.z.number(),
925
943
  annotation: annotationSchema
926
944
  }),
945
+ import_v44.z.object({
946
+ type: import_v44.z.literal("response.reasoning_summary_part.added"),
947
+ item_id: import_v44.z.string(),
948
+ output_index: import_v44.z.number(),
949
+ summary_index: import_v44.z.number(),
950
+ part: reasoningSummaryPartSchema
951
+ }),
952
+ import_v44.z.object({
953
+ type: import_v44.z.literal("response.reasoning_summary_part.done"),
954
+ item_id: import_v44.z.string(),
955
+ output_index: import_v44.z.number(),
956
+ summary_index: import_v44.z.number(),
957
+ part: reasoningSummaryPartSchema
958
+ }),
959
+ import_v44.z.object({
960
+ type: import_v44.z.literal("response.reasoning_summary_text.delta"),
961
+ item_id: import_v44.z.string(),
962
+ output_index: import_v44.z.number(),
963
+ summary_index: import_v44.z.number(),
964
+ delta: import_v44.z.string()
965
+ }),
966
+ import_v44.z.object({
967
+ type: import_v44.z.literal("response.reasoning_summary_text.done"),
968
+ item_id: import_v44.z.string(),
969
+ output_index: import_v44.z.number(),
970
+ summary_index: import_v44.z.number(),
971
+ text: import_v44.z.string()
972
+ }),
973
+ import_v44.z.object({
974
+ type: import_v44.z.literal("response.web_search_call.in_progress"),
975
+ item_id: import_v44.z.string(),
976
+ output_index: import_v44.z.number()
977
+ }),
978
+ import_v44.z.object({
979
+ type: import_v44.z.literal("response.web_search_call.searching"),
980
+ item_id: import_v44.z.string(),
981
+ output_index: import_v44.z.number()
982
+ }),
983
+ import_v44.z.object({
984
+ type: import_v44.z.literal("response.web_search_call.completed"),
985
+ item_id: import_v44.z.string(),
986
+ output_index: import_v44.z.number()
987
+ }),
988
+ import_v44.z.object({
989
+ type: import_v44.z.literal("response.x_search_call.in_progress"),
990
+ item_id: import_v44.z.string(),
991
+ output_index: import_v44.z.number()
992
+ }),
993
+ import_v44.z.object({
994
+ type: import_v44.z.literal("response.x_search_call.searching"),
995
+ item_id: import_v44.z.string(),
996
+ output_index: import_v44.z.number()
997
+ }),
998
+ import_v44.z.object({
999
+ type: import_v44.z.literal("response.x_search_call.completed"),
1000
+ item_id: import_v44.z.string(),
1001
+ output_index: import_v44.z.number()
1002
+ }),
1003
+ import_v44.z.object({
1004
+ type: import_v44.z.literal("response.code_execution_call.in_progress"),
1005
+ item_id: import_v44.z.string(),
1006
+ output_index: import_v44.z.number()
1007
+ }),
1008
+ import_v44.z.object({
1009
+ type: import_v44.z.literal("response.code_execution_call.executing"),
1010
+ item_id: import_v44.z.string(),
1011
+ output_index: import_v44.z.number()
1012
+ }),
1013
+ import_v44.z.object({
1014
+ type: import_v44.z.literal("response.code_execution_call.completed"),
1015
+ item_id: import_v44.z.string(),
1016
+ output_index: import_v44.z.number()
1017
+ }),
1018
+ import_v44.z.object({
1019
+ type: import_v44.z.literal("response.code_interpreter_call.in_progress"),
1020
+ item_id: import_v44.z.string(),
1021
+ output_index: import_v44.z.number()
1022
+ }),
1023
+ import_v44.z.object({
1024
+ type: import_v44.z.literal("response.code_interpreter_call.executing"),
1025
+ item_id: import_v44.z.string(),
1026
+ output_index: import_v44.z.number()
1027
+ }),
1028
+ import_v44.z.object({
1029
+ type: import_v44.z.literal("response.code_interpreter_call.completed"),
1030
+ item_id: import_v44.z.string(),
1031
+ output_index: import_v44.z.number()
1032
+ }),
927
1033
  import_v44.z.object({
928
1034
  type: import_v44.z.literal("response.done"),
929
1035
  response: xaiResponsesResponseSchema
@@ -955,7 +1061,20 @@ function mapXaiResponsesFinishReason(finishReason) {
955
1061
  // src/responses/xai-responses-options.ts
956
1062
  var import_v45 = require("zod/v4");
957
1063
  var xaiResponsesProviderOptions = import_v45.z.object({
958
- reasoningEffort: import_v45.z.enum(["low", "high"]).optional()
1064
+ /**
1065
+ * Constrains how hard a reasoning model thinks before responding.
1066
+ * Possible values are `low` (uses fewer reasoning tokens), `medium` and `high` (uses more reasoning tokens).
1067
+ */
1068
+ reasoningEffort: import_v45.z.enum(["low", "medium", "high"]).optional(),
1069
+ /**
1070
+ * Whether to store the input message(s) and model response for later retrieval.
1071
+ * @default true
1072
+ */
1073
+ store: import_v45.z.boolean().optional(),
1074
+ /**
1075
+ * The ID of the previous response from the model.
1076
+ */
1077
+ previousResponseId: import_v45.z.string().optional()
959
1078
  });
960
1079
 
961
1080
  // src/responses/convert-to-xai-responses-input.ts
@@ -1419,7 +1538,16 @@ var XaiResponsesLanguageModel = class {
1419
1538
  temperature,
1420
1539
  top_p: topP,
1421
1540
  seed,
1422
- reasoning_effort: options.reasoningEffort
1541
+ ...options.reasoningEffort != null && {
1542
+ reasoning: { effort: options.reasoningEffort }
1543
+ },
1544
+ ...options.store === false && {
1545
+ store: options.store,
1546
+ include: ["reasoning.encrypted_content"]
1547
+ },
1548
+ ...options.previousResponseId != null && {
1549
+ previous_response_id: options.previousResponseId
1550
+ }
1423
1551
  };
1424
1552
  if (xaiTools2 && xaiTools2.length > 0) {
1425
1553
  baseArgs.tools = xaiTools2;
@@ -1436,7 +1564,7 @@ var XaiResponsesLanguageModel = class {
1436
1564
  };
1437
1565
  }
1438
1566
  async doGenerate(options) {
1439
- var _a, _b, _c;
1567
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1440
1568
  const {
1441
1569
  args: body,
1442
1570
  warnings,
@@ -1472,20 +1600,21 @@ var XaiResponsesLanguageModel = class {
1472
1600
  "x_thread_fetch"
1473
1601
  ];
1474
1602
  for (const part of response.output) {
1475
- if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call") {
1476
- let toolName = part.name;
1477
- if (webSearchSubTools.includes(part.name)) {
1603
+ if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call" || part.type === "custom_tool_call") {
1604
+ let toolName = (_b = part.name) != null ? _b : "";
1605
+ if (webSearchSubTools.includes((_c = part.name) != null ? _c : "")) {
1478
1606
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
1479
- } else if (xSearchSubTools.includes(part.name)) {
1607
+ } else if (xSearchSubTools.includes((_d = part.name) != null ? _d : "")) {
1480
1608
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
1481
1609
  } else if (part.name === "code_execution") {
1482
1610
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
1483
1611
  }
1612
+ const toolInput = part.type === "custom_tool_call" ? (_e = part.input) != null ? _e : "" : (_f = part.arguments) != null ? _f : "";
1484
1613
  content.push({
1485
1614
  type: "tool-call",
1486
1615
  toolCallId: part.id,
1487
1616
  toolName,
1488
- input: part.arguments,
1617
+ input: toolInput,
1489
1618
  providerExecuted: true
1490
1619
  });
1491
1620
  continue;
@@ -1507,7 +1636,7 @@ var XaiResponsesLanguageModel = class {
1507
1636
  sourceType: "url",
1508
1637
  id: this.config.generateId(),
1509
1638
  url: annotation.url,
1510
- title: (_b = annotation.title) != null ? _b : annotation.url
1639
+ title: (_g = annotation.title) != null ? _g : annotation.url
1511
1640
  });
1512
1641
  }
1513
1642
  }
@@ -1536,7 +1665,7 @@ var XaiResponsesLanguageModel = class {
1536
1665
  inputTokens: response.usage.input_tokens,
1537
1666
  outputTokens: response.usage.output_tokens,
1538
1667
  totalTokens: response.usage.total_tokens,
1539
- reasoningTokens: (_c = response.usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens
1668
+ reasoningTokens: (_h = response.usage.output_tokens_details) == null ? void 0 : _h.reasoning_tokens
1540
1669
  },
1541
1670
  request: { body },
1542
1671
  response: {
@@ -1588,7 +1717,7 @@ var XaiResponsesLanguageModel = class {
1588
1717
  controller.enqueue({ type: "stream-start", warnings });
1589
1718
  },
1590
1719
  transform(chunk, controller) {
1591
- var _a2, _b, _c, _d;
1720
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
1592
1721
  if (options.includeRawChunks) {
1593
1722
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1594
1723
  }
@@ -1607,6 +1736,29 @@ var XaiResponsesLanguageModel = class {
1607
1736
  }
1608
1737
  return;
1609
1738
  }
1739
+ if (event.type === "response.reasoning_summary_part.added") {
1740
+ const blockId = `reasoning-${event.item_id}`;
1741
+ controller.enqueue({
1742
+ type: "reasoning-start",
1743
+ id: blockId
1744
+ });
1745
+ }
1746
+ if (event.type === "response.reasoning_summary_text.delta") {
1747
+ const blockId = `reasoning-${event.item_id}`;
1748
+ controller.enqueue({
1749
+ type: "reasoning-delta",
1750
+ id: blockId,
1751
+ delta: event.delta
1752
+ });
1753
+ return;
1754
+ }
1755
+ if (event.type === "response.reasoning_summary_text.done") {
1756
+ const blockId = `reasoning-${event.item_id}`;
1757
+ controller.enqueue({
1758
+ type: "reasoning-end",
1759
+ id: blockId
1760
+ });
1761
+ }
1610
1762
  if (event.type === "response.output_text.delta") {
1611
1763
  const blockId = `text-${event.item_id}`;
1612
1764
  if (contentBlocks[blockId] == null) {
@@ -1667,7 +1819,7 @@ var XaiResponsesLanguageModel = class {
1667
1819
  }
1668
1820
  if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
1669
1821
  const part = event.item;
1670
- if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call") {
1822
+ if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call" || part.type === "custom_tool_call") {
1671
1823
  if (!seenToolCalls.has(part.id)) {
1672
1824
  seenToolCalls.add(part.id);
1673
1825
  const webSearchSubTools = [
@@ -1681,14 +1833,15 @@ var XaiResponsesLanguageModel = class {
1681
1833
  "x_semantic_search",
1682
1834
  "x_thread_fetch"
1683
1835
  ];
1684
- let toolName = part.name;
1685
- if (webSearchSubTools.includes(part.name)) {
1836
+ let toolName = (_d = part.name) != null ? _d : "";
1837
+ if (webSearchSubTools.includes((_e = part.name) != null ? _e : "")) {
1686
1838
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
1687
- } else if (xSearchSubTools.includes(part.name)) {
1839
+ } else if (xSearchSubTools.includes((_f = part.name) != null ? _f : "")) {
1688
1840
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
1689
1841
  } else if (part.name === "code_execution") {
1690
1842
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
1691
1843
  }
1844
+ const toolInput = part.type === "custom_tool_call" ? (_g = part.input) != null ? _g : "" : (_h = part.arguments) != null ? _h : "";
1692
1845
  controller.enqueue({
1693
1846
  type: "tool-input-start",
1694
1847
  id: part.id,
@@ -1697,7 +1850,7 @@ var XaiResponsesLanguageModel = class {
1697
1850
  controller.enqueue({
1698
1851
  type: "tool-input-delta",
1699
1852
  id: part.id,
1700
- delta: part.arguments
1853
+ delta: toolInput
1701
1854
  });
1702
1855
  controller.enqueue({
1703
1856
  type: "tool-input-end",
@@ -1707,7 +1860,7 @@ var XaiResponsesLanguageModel = class {
1707
1860
  type: "tool-call",
1708
1861
  toolCallId: part.id,
1709
1862
  toolName,
1710
- input: part.arguments,
1863
+ input: toolInput,
1711
1864
  providerExecuted: true
1712
1865
  });
1713
1866
  }
@@ -1738,7 +1891,7 @@ var XaiResponsesLanguageModel = class {
1738
1891
  sourceType: "url",
1739
1892
  id: self.config.generateId(),
1740
1893
  url: annotation.url,
1741
- title: (_d = annotation.title) != null ? _d : annotation.url
1894
+ title: (_i = annotation.title) != null ? _i : annotation.url
1742
1895
  });
1743
1896
  }
1744
1897
  }
@@ -1846,7 +1999,7 @@ var xaiTools = {
1846
1999
  };
1847
2000
 
1848
2001
  // src/version.ts
1849
- var VERSION = true ? "3.0.0-beta.40" : "0.0.0-test";
2002
+ var VERSION = true ? "3.0.0-beta.42" : "0.0.0-test";
1850
2003
 
1851
2004
  // src/xai-provider.ts
1852
2005
  var xaiErrorStructure = {