@ai-sdk/xai 3.0.82 → 3.0.83

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
+ ## 3.0.83
4
+
5
+ ### Patch Changes
6
+
7
+ - b937f3e: fix(xai): support encrypted reasoning round-trip for ZDR
8
+
3
9
  ## 3.0.82
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1052,7 +1052,7 @@ var import_provider_utils5 = require("@ai-sdk/provider-utils");
1052
1052
  async function convertToXaiResponsesInput({
1053
1053
  prompt
1054
1054
  }) {
1055
- var _a, _b, _c, _d, _e;
1055
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1056
1056
  const input = [];
1057
1057
  const inputWarnings = [];
1058
1058
  for (const message of prompt) {
@@ -1129,7 +1129,34 @@ async function convertToXaiResponsesInput({
1129
1129
  case "tool-result": {
1130
1130
  break;
1131
1131
  }
1132
- case "reasoning":
1132
+ case "reasoning": {
1133
+ const itemId = typeof ((_f = (_e = part.providerOptions) == null ? void 0 : _e.xai) == null ? void 0 : _f.itemId) === "string" ? part.providerOptions.xai.itemId : void 0;
1134
+ const encryptedContent = typeof ((_h = (_g = part.providerOptions) == null ? void 0 : _g.xai) == null ? void 0 : _h.reasoningEncryptedContent) === "string" ? part.providerOptions.xai.reasoningEncryptedContent : void 0;
1135
+ if (itemId != null || encryptedContent != null) {
1136
+ const summaryParts = [];
1137
+ if (part.text.length > 0) {
1138
+ summaryParts.push({
1139
+ type: "summary_text",
1140
+ text: part.text
1141
+ });
1142
+ }
1143
+ input.push({
1144
+ type: "reasoning",
1145
+ id: itemId != null ? itemId : "",
1146
+ summary: summaryParts,
1147
+ status: "completed",
1148
+ ...encryptedContent != null && {
1149
+ encrypted_content: encryptedContent
1150
+ }
1151
+ });
1152
+ } else {
1153
+ inputWarnings.push({
1154
+ type: "other",
1155
+ message: "Reasoning parts without itemId or encrypted content cannot be sent back to xAI. Skipping."
1156
+ });
1157
+ }
1158
+ break;
1159
+ }
1133
1160
  case "file": {
1134
1161
  inputWarnings.push({
1135
1162
  type: "other",
@@ -1161,7 +1188,7 @@ async function convertToXaiResponsesInput({
1161
1188
  outputValue = output.value;
1162
1189
  break;
1163
1190
  case "execution-denied":
1164
- outputValue = (_e = output.reason) != null ? _e : "tool execution denied";
1191
+ outputValue = (_i = output.reason) != null ? _i : "tool execution denied";
1165
1192
  break;
1166
1193
  case "json":
1167
1194
  case "error-json":
@@ -1680,6 +1707,8 @@ var xaiLanguageModelResponsesOptions = import_v47.z.object({
1680
1707
  topLogprobs: import_v47.z.number().int().min(0).max(8).optional(),
1681
1708
  /**
1682
1709
  * Whether to store the input message(s) and model response for later retrieval.
1710
+ * Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
1711
+ * otherwise the API will return an error.
1683
1712
  * @default true
1684
1713
  */
1685
1714
  store: import_v47.z.boolean().optional(),
@@ -2007,7 +2036,7 @@ var XaiResponsesLanguageModel = class {
2007
2036
  tools,
2008
2037
  toolChoice
2009
2038
  }) {
2010
- var _a, _b, _c, _d, _e, _f, _g;
2039
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2011
2040
  const warnings = [];
2012
2041
  const options = (_a = await (0, import_provider_utils11.parseProviderOptions)({
2013
2042
  provider: "xai",
@@ -2034,7 +2063,7 @@ var XaiResponsesLanguageModel = class {
2034
2063
  )) == null ? void 0 : _f.name;
2035
2064
  const { input, inputWarnings } = await convertToXaiResponsesInput({
2036
2065
  prompt,
2037
- store: true
2066
+ store: (_g = options.store) != null ? _g : true
2038
2067
  });
2039
2068
  warnings.push(...inputWarnings);
2040
2069
  const {
@@ -2068,7 +2097,7 @@ var XaiResponsesLanguageModel = class {
2068
2097
  format: responseFormat.schema != null ? {
2069
2098
  type: "json_schema",
2070
2099
  strict: true,
2071
- name: (_g = responseFormat.name) != null ? _g : "response",
2100
+ name: (_h = responseFormat.name) != null ? _h : "response",
2072
2101
  description: responseFormat.description,
2073
2102
  schema: responseFormat.schema
2074
2103
  } : { type: "json_object" }
@@ -2226,12 +2255,13 @@ var XaiResponsesLanguageModel = class {
2226
2255
  }
2227
2256
  case "reasoning": {
2228
2257
  const summaryTexts = part.summary.map((s) => s.text).filter((text) => text && text.length > 0);
2229
- if (summaryTexts.length > 0) {
2230
- const reasoningText = summaryTexts.join("");
2231
- if (part.encrypted_content || part.id) {
2232
- content.push({
2233
- type: "reasoning",
2234
- text: reasoningText,
2258
+ const reasoningText = summaryTexts.join("");
2259
+ if (reasoningText || part.encrypted_content) {
2260
+ const hasMetadata = part.encrypted_content || part.id;
2261
+ content.push({
2262
+ type: "reasoning",
2263
+ text: reasoningText,
2264
+ ...hasMetadata && {
2235
2265
  providerMetadata: {
2236
2266
  xai: {
2237
2267
  ...part.encrypted_content && {
@@ -2240,13 +2270,8 @@ var XaiResponsesLanguageModel = class {
2240
2270
  ...part.id && { itemId: part.id }
2241
2271
  }
2242
2272
  }
2243
- });
2244
- } else {
2245
- content.push({
2246
- type: "reasoning",
2247
- text: reasoningText
2248
- });
2249
- }
2273
+ }
2274
+ });
2250
2275
  }
2251
2276
  break;
2252
2277
  }
@@ -2765,7 +2790,7 @@ var xaiTools = {
2765
2790
  };
2766
2791
 
2767
2792
  // src/version.ts
2768
- var VERSION = true ? "3.0.82" : "0.0.0-test";
2793
+ var VERSION = true ? "3.0.83" : "0.0.0-test";
2769
2794
 
2770
2795
  // src/xai-video-model.ts
2771
2796
  var import_provider6 = require("@ai-sdk/provider");