@ai-sdk/xai 3.0.14 → 3.0.16

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.16
4
+
5
+ ### Patch Changes
6
+
7
+ - f446e23: fix(provider/xai): make streaming providerMetadata structure consistent with non-streaming
8
+
9
+ ## 3.0.15
10
+
11
+ ### Patch Changes
12
+
13
+ - ed1587d: feat (provider/xai): add support for encrypted reasoning content
14
+
3
15
  ## 3.0.14
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1130,7 +1130,8 @@ var outputItemSchema = import_v44.z.discriminatedUnion("type", [
1130
1130
  type: import_v44.z.literal("reasoning"),
1131
1131
  id: import_v44.z.string(),
1132
1132
  summary: import_v44.z.array(reasoningSummaryPartSchema),
1133
- status: import_v44.z.string()
1133
+ status: import_v44.z.string(),
1134
+ encrypted_content: import_v44.z.string().nullish()
1134
1135
  })
1135
1136
  ]);
1136
1137
  var xaiResponsesUsageSchema = import_v44.z.object({
@@ -1801,6 +1802,32 @@ var XaiResponsesLanguageModel = class {
1801
1802
  });
1802
1803
  break;
1803
1804
  }
1805
+ case "reasoning": {
1806
+ const summaryTexts = part.summary.map((s) => s.text).filter((text) => text && text.length > 0);
1807
+ if (summaryTexts.length > 0) {
1808
+ const reasoningText = summaryTexts.join("");
1809
+ if (part.encrypted_content || part.id) {
1810
+ content.push({
1811
+ type: "reasoning",
1812
+ text: reasoningText,
1813
+ providerMetadata: {
1814
+ xai: {
1815
+ ...part.encrypted_content && {
1816
+ reasoningEncryptedContent: part.encrypted_content
1817
+ },
1818
+ ...part.id && { itemId: part.id }
1819
+ }
1820
+ }
1821
+ });
1822
+ } else {
1823
+ content.push({
1824
+ type: "reasoning",
1825
+ text: reasoningText
1826
+ });
1827
+ }
1828
+ }
1829
+ break;
1830
+ }
1804
1831
  default: {
1805
1832
  break;
1806
1833
  }
@@ -1854,6 +1881,7 @@ var XaiResponsesLanguageModel = class {
1854
1881
  let isFirstChunk = true;
1855
1882
  const contentBlocks = {};
1856
1883
  const seenToolCalls = /* @__PURE__ */ new Set();
1884
+ const activeReasoning = {};
1857
1885
  const self = this;
1858
1886
  return {
1859
1887
  stream: response.pipeThrough(
@@ -1885,7 +1913,12 @@ var XaiResponsesLanguageModel = class {
1885
1913
  const blockId = `reasoning-${event.item_id}`;
1886
1914
  controller.enqueue({
1887
1915
  type: "reasoning-start",
1888
- id: blockId
1916
+ id: blockId,
1917
+ providerMetadata: {
1918
+ xai: {
1919
+ itemId: event.item_id
1920
+ }
1921
+ }
1889
1922
  });
1890
1923
  }
1891
1924
  if (event.type === "response.reasoning_summary_text.delta") {
@@ -1893,16 +1926,17 @@ var XaiResponsesLanguageModel = class {
1893
1926
  controller.enqueue({
1894
1927
  type: "reasoning-delta",
1895
1928
  id: blockId,
1896
- delta: event.delta
1929
+ delta: event.delta,
1930
+ providerMetadata: {
1931
+ xai: {
1932
+ itemId: event.item_id
1933
+ }
1934
+ }
1897
1935
  });
1898
1936
  return;
1899
1937
  }
1900
1938
  if (event.type === "response.reasoning_summary_text.done") {
1901
- const blockId = `reasoning-${event.item_id}`;
1902
- controller.enqueue({
1903
- type: "reasoning-end",
1904
- id: blockId
1905
- });
1939
+ return;
1906
1940
  }
1907
1941
  if (event.type === "response.output_text.delta") {
1908
1942
  const blockId = `text-${event.item_id}`;
@@ -1964,6 +1998,24 @@ var XaiResponsesLanguageModel = class {
1964
1998
  }
1965
1999
  if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
1966
2000
  const part = event.item;
2001
+ if (part.type === "reasoning") {
2002
+ if (event.type === "response.output_item.done") {
2003
+ controller.enqueue({
2004
+ type: "reasoning-end",
2005
+ id: `reasoning-${part.id}`,
2006
+ providerMetadata: {
2007
+ xai: {
2008
+ ...part.encrypted_content && {
2009
+ reasoningEncryptedContent: part.encrypted_content
2010
+ },
2011
+ ...part.id && { itemId: part.id }
2012
+ }
2013
+ }
2014
+ });
2015
+ delete activeReasoning[part.id];
2016
+ }
2017
+ return;
2018
+ }
1967
2019
  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") {
1968
2020
  const webSearchSubTools = [
1969
2021
  "web_search",
@@ -2142,7 +2194,7 @@ var xaiTools = {
2142
2194
  };
2143
2195
 
2144
2196
  // src/version.ts
2145
- var VERSION = true ? "3.0.14" : "0.0.0-test";
2197
+ var VERSION = true ? "3.0.16" : "0.0.0-test";
2146
2198
 
2147
2199
  // src/xai-provider.ts
2148
2200
  var xaiErrorStructure = {