@ai-sdk/xai 2.0.35 → 2.0.37

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
@@ -133,12 +133,14 @@ function convertToXaiChatMessages(prompt) {
133
133
  function getResponseMetadata({
134
134
  id,
135
135
  model,
136
- created
136
+ created,
137
+ created_at
137
138
  }) {
139
+ const unixTime = created != null ? created : created_at;
138
140
  return {
139
141
  id: id != null ? id : void 0,
140
142
  modelId: model != null ? model : void 0,
141
- timestamp: created != null ? new Date(created * 1e3) : void 0
143
+ timestamp: unixTime != null ? new Date(unixTime * 1e3) : void 0
142
144
  };
143
145
  }
144
146
 
@@ -784,12 +786,18 @@ var messageContentPartSchema = z4.object({
784
786
  logprobs: z4.array(z4.any()).optional(),
785
787
  annotations: z4.array(annotationSchema).optional()
786
788
  });
789
+ var reasoningSummaryPartSchema = z4.object({
790
+ type: z4.string(),
791
+ text: z4.string()
792
+ });
787
793
  var toolCallSchema = z4.object({
788
- name: z4.string(),
789
- arguments: z4.string(),
790
- call_id: z4.string(),
794
+ name: z4.string().optional(),
795
+ arguments: z4.string().optional(),
796
+ input: z4.string().optional(),
797
+ call_id: z4.string().optional(),
791
798
  id: z4.string(),
792
- status: z4.string()
799
+ status: z4.string(),
800
+ action: z4.any().optional()
793
801
  });
794
802
  var outputItemSchema = z4.discriminatedUnion("type", [
795
803
  z4.object({
@@ -816,6 +824,10 @@ var outputItemSchema = z4.discriminatedUnion("type", [
816
824
  type: z4.literal("view_x_video_call"),
817
825
  ...toolCallSchema.shape
818
826
  }),
827
+ z4.object({
828
+ type: z4.literal("custom_tool_call"),
829
+ ...toolCallSchema.shape
830
+ }),
819
831
  z4.object({
820
832
  type: z4.literal("message"),
821
833
  role: z4.string(),
@@ -829,6 +841,12 @@ var outputItemSchema = z4.discriminatedUnion("type", [
829
841
  arguments: z4.string(),
830
842
  call_id: z4.string(),
831
843
  id: z4.string()
844
+ }),
845
+ z4.object({
846
+ type: z4.literal("reasoning"),
847
+ id: z4.string(),
848
+ summary: z4.array(reasoningSummaryPartSchema),
849
+ status: z4.string()
832
850
  })
833
851
  ]);
834
852
  var xaiResponsesUsageSchema = z4.object({
@@ -911,6 +929,94 @@ var xaiResponsesChunkSchema = z4.union([
911
929
  annotation_index: z4.number(),
912
930
  annotation: annotationSchema
913
931
  }),
932
+ z4.object({
933
+ type: z4.literal("response.reasoning_summary_part.added"),
934
+ item_id: z4.string(),
935
+ output_index: z4.number(),
936
+ summary_index: z4.number(),
937
+ part: reasoningSummaryPartSchema
938
+ }),
939
+ z4.object({
940
+ type: z4.literal("response.reasoning_summary_part.done"),
941
+ item_id: z4.string(),
942
+ output_index: z4.number(),
943
+ summary_index: z4.number(),
944
+ part: reasoningSummaryPartSchema
945
+ }),
946
+ z4.object({
947
+ type: z4.literal("response.reasoning_summary_text.delta"),
948
+ item_id: z4.string(),
949
+ output_index: z4.number(),
950
+ summary_index: z4.number(),
951
+ delta: z4.string()
952
+ }),
953
+ z4.object({
954
+ type: z4.literal("response.reasoning_summary_text.done"),
955
+ item_id: z4.string(),
956
+ output_index: z4.number(),
957
+ summary_index: z4.number(),
958
+ text: z4.string()
959
+ }),
960
+ z4.object({
961
+ type: z4.literal("response.web_search_call.in_progress"),
962
+ item_id: z4.string(),
963
+ output_index: z4.number()
964
+ }),
965
+ z4.object({
966
+ type: z4.literal("response.web_search_call.searching"),
967
+ item_id: z4.string(),
968
+ output_index: z4.number()
969
+ }),
970
+ z4.object({
971
+ type: z4.literal("response.web_search_call.completed"),
972
+ item_id: z4.string(),
973
+ output_index: z4.number()
974
+ }),
975
+ z4.object({
976
+ type: z4.literal("response.x_search_call.in_progress"),
977
+ item_id: z4.string(),
978
+ output_index: z4.number()
979
+ }),
980
+ z4.object({
981
+ type: z4.literal("response.x_search_call.searching"),
982
+ item_id: z4.string(),
983
+ output_index: z4.number()
984
+ }),
985
+ z4.object({
986
+ type: z4.literal("response.x_search_call.completed"),
987
+ item_id: z4.string(),
988
+ output_index: z4.number()
989
+ }),
990
+ z4.object({
991
+ type: z4.literal("response.code_execution_call.in_progress"),
992
+ item_id: z4.string(),
993
+ output_index: z4.number()
994
+ }),
995
+ z4.object({
996
+ type: z4.literal("response.code_execution_call.executing"),
997
+ item_id: z4.string(),
998
+ output_index: z4.number()
999
+ }),
1000
+ z4.object({
1001
+ type: z4.literal("response.code_execution_call.completed"),
1002
+ item_id: z4.string(),
1003
+ output_index: z4.number()
1004
+ }),
1005
+ z4.object({
1006
+ type: z4.literal("response.code_interpreter_call.in_progress"),
1007
+ item_id: z4.string(),
1008
+ output_index: z4.number()
1009
+ }),
1010
+ z4.object({
1011
+ type: z4.literal("response.code_interpreter_call.executing"),
1012
+ item_id: z4.string(),
1013
+ output_index: z4.number()
1014
+ }),
1015
+ z4.object({
1016
+ type: z4.literal("response.code_interpreter_call.completed"),
1017
+ item_id: z4.string(),
1018
+ output_index: z4.number()
1019
+ }),
914
1020
  z4.object({
915
1021
  type: z4.literal("response.done"),
916
1022
  response: xaiResponsesResponseSchema
@@ -942,7 +1048,20 @@ function mapXaiResponsesFinishReason(finishReason) {
942
1048
  // src/responses/xai-responses-options.ts
943
1049
  import { z as z5 } from "zod/v4";
944
1050
  var xaiResponsesProviderOptions = z5.object({
945
- reasoningEffort: z5.enum(["low", "high"]).optional()
1051
+ /**
1052
+ * Constrains how hard a reasoning model thinks before responding.
1053
+ * Possible values are `low` (uses fewer reasoning tokens), `medium` and `high` (uses more reasoning tokens).
1054
+ */
1055
+ reasoningEffort: z5.enum(["low", "medium", "high"]).optional(),
1056
+ /**
1057
+ * Whether to store the input message(s) and model response for later retrieval.
1058
+ * @default true
1059
+ */
1060
+ store: z5.boolean().optional(),
1061
+ /**
1062
+ * The ID of the previous response from the model.
1063
+ */
1064
+ previousResponseId: z5.string().optional()
946
1065
  });
947
1066
 
948
1067
  // src/responses/convert-to-xai-responses-input.ts
@@ -1413,7 +1532,16 @@ var XaiResponsesLanguageModel = class {
1413
1532
  temperature,
1414
1533
  top_p: topP,
1415
1534
  seed,
1416
- reasoning_effort: options.reasoningEffort
1535
+ ...options.reasoningEffort != null && {
1536
+ reasoning: { effort: options.reasoningEffort }
1537
+ },
1538
+ ...options.store === false && {
1539
+ store: options.store,
1540
+ include: ["reasoning.encrypted_content"]
1541
+ },
1542
+ ...options.previousResponseId != null && {
1543
+ previous_response_id: options.previousResponseId
1544
+ }
1417
1545
  };
1418
1546
  if (xaiTools2 && xaiTools2.length > 0) {
1419
1547
  baseArgs.tools = xaiTools2;
@@ -1430,7 +1558,7 @@ var XaiResponsesLanguageModel = class {
1430
1558
  };
1431
1559
  }
1432
1560
  async doGenerate(options) {
1433
- var _a, _b, _c;
1561
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1434
1562
  const {
1435
1563
  args: body,
1436
1564
  warnings,
@@ -1466,20 +1594,21 @@ var XaiResponsesLanguageModel = class {
1466
1594
  "x_thread_fetch"
1467
1595
  ];
1468
1596
  for (const part of response.output) {
1469
- 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") {
1470
- let toolName = part.name;
1471
- if (webSearchSubTools.includes(part.name)) {
1597
+ 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") {
1598
+ let toolName = (_b = part.name) != null ? _b : "";
1599
+ if (webSearchSubTools.includes((_c = part.name) != null ? _c : "")) {
1472
1600
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
1473
- } else if (xSearchSubTools.includes(part.name)) {
1601
+ } else if (xSearchSubTools.includes((_d = part.name) != null ? _d : "")) {
1474
1602
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
1475
1603
  } else if (part.name === "code_execution") {
1476
1604
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
1477
1605
  }
1606
+ const toolInput = part.type === "custom_tool_call" ? (_e = part.input) != null ? _e : "" : (_f = part.arguments) != null ? _f : "";
1478
1607
  content.push({
1479
1608
  type: "tool-call",
1480
1609
  toolCallId: part.id,
1481
1610
  toolName,
1482
- input: part.arguments,
1611
+ input: toolInput,
1483
1612
  providerExecuted: true
1484
1613
  });
1485
1614
  continue;
@@ -1501,7 +1630,7 @@ var XaiResponsesLanguageModel = class {
1501
1630
  sourceType: "url",
1502
1631
  id: this.config.generateId(),
1503
1632
  url: annotation.url,
1504
- title: (_b = annotation.title) != null ? _b : annotation.url
1633
+ title: (_g = annotation.title) != null ? _g : annotation.url
1505
1634
  });
1506
1635
  }
1507
1636
  }
@@ -1530,7 +1659,7 @@ var XaiResponsesLanguageModel = class {
1530
1659
  inputTokens: response.usage.input_tokens,
1531
1660
  outputTokens: response.usage.output_tokens,
1532
1661
  totalTokens: response.usage.total_tokens,
1533
- reasoningTokens: (_c = response.usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens
1662
+ reasoningTokens: (_h = response.usage.output_tokens_details) == null ? void 0 : _h.reasoning_tokens
1534
1663
  },
1535
1664
  request: { body },
1536
1665
  response: {
@@ -1582,7 +1711,7 @@ var XaiResponsesLanguageModel = class {
1582
1711
  controller.enqueue({ type: "stream-start", warnings });
1583
1712
  },
1584
1713
  transform(chunk, controller) {
1585
- var _a2, _b, _c, _d;
1714
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
1586
1715
  if (options.includeRawChunks) {
1587
1716
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1588
1717
  }
@@ -1601,6 +1730,29 @@ var XaiResponsesLanguageModel = class {
1601
1730
  }
1602
1731
  return;
1603
1732
  }
1733
+ if (event.type === "response.reasoning_summary_part.added") {
1734
+ const blockId = `reasoning-${event.item_id}`;
1735
+ controller.enqueue({
1736
+ type: "reasoning-start",
1737
+ id: blockId
1738
+ });
1739
+ }
1740
+ if (event.type === "response.reasoning_summary_text.delta") {
1741
+ const blockId = `reasoning-${event.item_id}`;
1742
+ controller.enqueue({
1743
+ type: "reasoning-delta",
1744
+ id: blockId,
1745
+ delta: event.delta
1746
+ });
1747
+ return;
1748
+ }
1749
+ if (event.type === "response.reasoning_summary_text.done") {
1750
+ const blockId = `reasoning-${event.item_id}`;
1751
+ controller.enqueue({
1752
+ type: "reasoning-end",
1753
+ id: blockId
1754
+ });
1755
+ }
1604
1756
  if (event.type === "response.output_text.delta") {
1605
1757
  const blockId = `text-${event.item_id}`;
1606
1758
  if (contentBlocks[blockId] == null) {
@@ -1661,7 +1813,7 @@ var XaiResponsesLanguageModel = class {
1661
1813
  }
1662
1814
  if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
1663
1815
  const part = event.item;
1664
- 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") {
1816
+ 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") {
1665
1817
  if (!seenToolCalls.has(part.id)) {
1666
1818
  seenToolCalls.add(part.id);
1667
1819
  const webSearchSubTools = [
@@ -1675,14 +1827,15 @@ var XaiResponsesLanguageModel = class {
1675
1827
  "x_semantic_search",
1676
1828
  "x_thread_fetch"
1677
1829
  ];
1678
- let toolName = part.name;
1679
- if (webSearchSubTools.includes(part.name)) {
1830
+ let toolName = (_d = part.name) != null ? _d : "";
1831
+ if (webSearchSubTools.includes((_e = part.name) != null ? _e : "")) {
1680
1832
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
1681
- } else if (xSearchSubTools.includes(part.name)) {
1833
+ } else if (xSearchSubTools.includes((_f = part.name) != null ? _f : "")) {
1682
1834
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
1683
1835
  } else if (part.name === "code_execution") {
1684
1836
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
1685
1837
  }
1838
+ const toolInput = part.type === "custom_tool_call" ? (_g = part.input) != null ? _g : "" : (_h = part.arguments) != null ? _h : "";
1686
1839
  controller.enqueue({
1687
1840
  type: "tool-input-start",
1688
1841
  id: part.id,
@@ -1691,7 +1844,7 @@ var XaiResponsesLanguageModel = class {
1691
1844
  controller.enqueue({
1692
1845
  type: "tool-input-delta",
1693
1846
  id: part.id,
1694
- delta: part.arguments
1847
+ delta: toolInput
1695
1848
  });
1696
1849
  controller.enqueue({
1697
1850
  type: "tool-input-end",
@@ -1701,7 +1854,7 @@ var XaiResponsesLanguageModel = class {
1701
1854
  type: "tool-call",
1702
1855
  toolCallId: part.id,
1703
1856
  toolName,
1704
- input: part.arguments,
1857
+ input: toolInput,
1705
1858
  providerExecuted: true
1706
1859
  });
1707
1860
  }
@@ -1732,7 +1885,7 @@ var XaiResponsesLanguageModel = class {
1732
1885
  sourceType: "url",
1733
1886
  id: self.config.generateId(),
1734
1887
  url: annotation.url,
1735
- title: (_d = annotation.title) != null ? _d : annotation.url
1888
+ title: (_i = annotation.title) != null ? _i : annotation.url
1736
1889
  });
1737
1890
  }
1738
1891
  }
@@ -1840,7 +1993,7 @@ var xaiTools = {
1840
1993
  };
1841
1994
 
1842
1995
  // src/version.ts
1843
- var VERSION = true ? "2.0.35" : "0.0.0-test";
1996
+ var VERSION = true ? "2.0.37" : "0.0.0-test";
1844
1997
 
1845
1998
  // src/xai-provider.ts
1846
1999
  var xaiErrorStructure = {