@ai-sdk/xai 2.0.51 → 2.0.52

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,11 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 2.0.52
4
+
5
+ ### Patch Changes
6
+
7
+ - a2b5824: feat (provider/xai): add support for encrypted reasoning content
8
+
3
9
  ## 2.0.51
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -942,7 +942,8 @@ var outputItemSchema = import_v44.z.discriminatedUnion("type", [
942
942
  type: import_v44.z.literal("reasoning"),
943
943
  id: import_v44.z.string(),
944
944
  summary: import_v44.z.array(reasoningSummaryPartSchema),
945
- status: import_v44.z.string()
945
+ status: import_v44.z.string(),
946
+ encrypted_content: import_v44.z.string().nullish()
946
947
  })
947
948
  ]);
948
949
  var xaiResponsesUsageSchema = import_v44.z.object({
@@ -1771,6 +1772,32 @@ var XaiResponsesLanguageModel = class {
1771
1772
  });
1772
1773
  break;
1773
1774
  }
1775
+ case "reasoning": {
1776
+ const summaryTexts = part.summary.map((s) => s.text).filter((text) => text && text.length > 0);
1777
+ if (summaryTexts.length > 0) {
1778
+ const reasoningText = summaryTexts.join("");
1779
+ if (part.encrypted_content || part.id) {
1780
+ content.push({
1781
+ type: "reasoning",
1782
+ text: reasoningText,
1783
+ providerMetadata: {
1784
+ xai: {
1785
+ ...part.encrypted_content && {
1786
+ reasoningEncryptedContent: part.encrypted_content
1787
+ },
1788
+ ...part.id && { itemId: part.id }
1789
+ }
1790
+ }
1791
+ });
1792
+ } else {
1793
+ content.push({
1794
+ type: "reasoning",
1795
+ text: reasoningText
1796
+ });
1797
+ }
1798
+ }
1799
+ break;
1800
+ }
1774
1801
  default: {
1775
1802
  break;
1776
1803
  }
@@ -1828,6 +1855,7 @@ var XaiResponsesLanguageModel = class {
1828
1855
  let isFirstChunk = true;
1829
1856
  const contentBlocks = {};
1830
1857
  const seenToolCalls = /* @__PURE__ */ new Set();
1858
+ const activeReasoning = {};
1831
1859
  const self = this;
1832
1860
  return {
1833
1861
  stream: response.pipeThrough(
@@ -1859,7 +1887,12 @@ var XaiResponsesLanguageModel = class {
1859
1887
  const blockId = `reasoning-${event.item_id}`;
1860
1888
  controller.enqueue({
1861
1889
  type: "reasoning-start",
1862
- id: blockId
1890
+ id: blockId,
1891
+ providerMetadata: {
1892
+ xai: {
1893
+ itemId: event.item_id
1894
+ }
1895
+ }
1863
1896
  });
1864
1897
  }
1865
1898
  if (event.type === "response.reasoning_summary_text.delta") {
@@ -1867,16 +1900,17 @@ var XaiResponsesLanguageModel = class {
1867
1900
  controller.enqueue({
1868
1901
  type: "reasoning-delta",
1869
1902
  id: blockId,
1870
- delta: event.delta
1903
+ delta: event.delta,
1904
+ providerMetadata: {
1905
+ xai: {
1906
+ itemId: event.item_id
1907
+ }
1908
+ }
1871
1909
  });
1872
1910
  return;
1873
1911
  }
1874
1912
  if (event.type === "response.reasoning_summary_text.done") {
1875
- const blockId = `reasoning-${event.item_id}`;
1876
- controller.enqueue({
1877
- type: "reasoning-end",
1878
- id: blockId
1879
- });
1913
+ return;
1880
1914
  }
1881
1915
  if (event.type === "response.output_text.delta") {
1882
1916
  const blockId = `text-${event.item_id}`;
@@ -1939,6 +1973,24 @@ var XaiResponsesLanguageModel = class {
1939
1973
  }
1940
1974
  if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
1941
1975
  const part = event.item;
1976
+ if (part.type === "reasoning") {
1977
+ if (event.type === "response.output_item.done") {
1978
+ controller.enqueue({
1979
+ type: "reasoning-end",
1980
+ id: `reasoning-${part.id}`,
1981
+ providerMetadata: {
1982
+ xai: {
1983
+ ...part.encrypted_content && {
1984
+ reasoningEncryptedContent: part.encrypted_content
1985
+ },
1986
+ ...part.id && { itemId: part.id }
1987
+ }
1988
+ }
1989
+ });
1990
+ delete activeReasoning[part.id];
1991
+ }
1992
+ return;
1993
+ }
1942
1994
  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") {
1943
1995
  const webSearchSubTools = [
1944
1996
  "web_search",
@@ -2120,7 +2172,7 @@ var xaiTools = {
2120
2172
  };
2121
2173
 
2122
2174
  // src/version.ts
2123
- var VERSION = true ? "2.0.51" : "0.0.0-test";
2175
+ var VERSION = true ? "2.0.52" : "0.0.0-test";
2124
2176
 
2125
2177
  // src/xai-provider.ts
2126
2178
  var xaiErrorStructure = {