@ai-sdk/xai 2.0.50 → 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,17 @@
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
+
9
+ ## 2.0.51
10
+
11
+ ### Patch Changes
12
+
13
+ - c635580: fix (provider/xai): set response format to allow object generation
14
+
3
15
  ## 2.0.50
4
16
 
5
17
  ### 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({
@@ -1597,11 +1598,12 @@ var XaiResponsesLanguageModel = class {
1597
1598
  topP,
1598
1599
  stopSequences,
1599
1600
  seed,
1601
+ responseFormat,
1600
1602
  providerOptions,
1601
1603
  tools,
1602
1604
  toolChoice
1603
1605
  }) {
1604
- var _a, _b, _c, _d;
1606
+ var _a, _b, _c, _d, _e;
1605
1607
  const warnings = [];
1606
1608
  const options = (_a = await (0, import_provider_utils7.parseProviderOptions)({
1607
1609
  provider: "xai",
@@ -1644,6 +1646,17 @@ var XaiResponsesLanguageModel = class {
1644
1646
  temperature,
1645
1647
  top_p: topP,
1646
1648
  seed,
1649
+ ...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
1650
+ text: {
1651
+ format: responseFormat.schema != null ? {
1652
+ type: "json_schema",
1653
+ strict: true,
1654
+ name: (_e = responseFormat.name) != null ? _e : "response",
1655
+ description: responseFormat.description,
1656
+ schema: responseFormat.schema
1657
+ } : { type: "json_object" }
1658
+ }
1659
+ },
1647
1660
  ...options.reasoningEffort != null && {
1648
1661
  reasoning: { effort: options.reasoningEffort }
1649
1662
  },
@@ -1759,6 +1772,32 @@ var XaiResponsesLanguageModel = class {
1759
1772
  });
1760
1773
  break;
1761
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
+ }
1762
1801
  default: {
1763
1802
  break;
1764
1803
  }
@@ -1816,6 +1855,7 @@ var XaiResponsesLanguageModel = class {
1816
1855
  let isFirstChunk = true;
1817
1856
  const contentBlocks = {};
1818
1857
  const seenToolCalls = /* @__PURE__ */ new Set();
1858
+ const activeReasoning = {};
1819
1859
  const self = this;
1820
1860
  return {
1821
1861
  stream: response.pipeThrough(
@@ -1847,7 +1887,12 @@ var XaiResponsesLanguageModel = class {
1847
1887
  const blockId = `reasoning-${event.item_id}`;
1848
1888
  controller.enqueue({
1849
1889
  type: "reasoning-start",
1850
- id: blockId
1890
+ id: blockId,
1891
+ providerMetadata: {
1892
+ xai: {
1893
+ itemId: event.item_id
1894
+ }
1895
+ }
1851
1896
  });
1852
1897
  }
1853
1898
  if (event.type === "response.reasoning_summary_text.delta") {
@@ -1855,16 +1900,17 @@ var XaiResponsesLanguageModel = class {
1855
1900
  controller.enqueue({
1856
1901
  type: "reasoning-delta",
1857
1902
  id: blockId,
1858
- delta: event.delta
1903
+ delta: event.delta,
1904
+ providerMetadata: {
1905
+ xai: {
1906
+ itemId: event.item_id
1907
+ }
1908
+ }
1859
1909
  });
1860
1910
  return;
1861
1911
  }
1862
1912
  if (event.type === "response.reasoning_summary_text.done") {
1863
- const blockId = `reasoning-${event.item_id}`;
1864
- controller.enqueue({
1865
- type: "reasoning-end",
1866
- id: blockId
1867
- });
1913
+ return;
1868
1914
  }
1869
1915
  if (event.type === "response.output_text.delta") {
1870
1916
  const blockId = `text-${event.item_id}`;
@@ -1927,6 +1973,24 @@ var XaiResponsesLanguageModel = class {
1927
1973
  }
1928
1974
  if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
1929
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
+ }
1930
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") {
1931
1995
  const webSearchSubTools = [
1932
1996
  "web_search",
@@ -2108,7 +2172,7 @@ var xaiTools = {
2108
2172
  };
2109
2173
 
2110
2174
  // src/version.ts
2111
- var VERSION = true ? "2.0.50" : "0.0.0-test";
2175
+ var VERSION = true ? "2.0.52" : "0.0.0-test";
2112
2176
 
2113
2177
  // src/xai-provider.ts
2114
2178
  var xaiErrorStructure = {