@ai-sdk/xai 4.0.0-beta.36 → 4.0.0-beta.38

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,19 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.0-beta.38
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [add1126]
8
+ - @ai-sdk/provider-utils@5.0.0-beta.21
9
+ - @ai-sdk/openai-compatible@3.0.0-beta.26
10
+
11
+ ## 4.0.0-beta.37
12
+
13
+ ### Patch Changes
14
+
15
+ - 8d87577: fix(xai): support encrypted reasoning round-trip for ZDR
16
+
3
17
  ## 4.0.0-beta.36
4
18
 
5
19
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1116,7 +1116,7 @@ import {
1116
1116
  async function convertToXaiResponsesInput({
1117
1117
  prompt
1118
1118
  }) {
1119
- var _a, _b, _c, _d, _e;
1119
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1120
1120
  const input = [];
1121
1121
  const inputWarnings = [];
1122
1122
  for (const message of prompt) {
@@ -1201,7 +1201,34 @@ async function convertToXaiResponsesInput({
1201
1201
  case "tool-result": {
1202
1202
  break;
1203
1203
  }
1204
- case "reasoning":
1204
+ case "reasoning": {
1205
+ const itemId = typeof ((_f = (_e = part.providerOptions) == null ? void 0 : _e.xai) == null ? void 0 : _f.itemId) === "string" ? part.providerOptions.xai.itemId : void 0;
1206
+ const encryptedContent = typeof ((_h = (_g = part.providerOptions) == null ? void 0 : _g.xai) == null ? void 0 : _h.reasoningEncryptedContent) === "string" ? part.providerOptions.xai.reasoningEncryptedContent : void 0;
1207
+ if (itemId != null || encryptedContent != null) {
1208
+ const summaryParts = [];
1209
+ if (part.text.length > 0) {
1210
+ summaryParts.push({
1211
+ type: "summary_text",
1212
+ text: part.text
1213
+ });
1214
+ }
1215
+ input.push({
1216
+ type: "reasoning",
1217
+ id: itemId != null ? itemId : "",
1218
+ summary: summaryParts,
1219
+ status: "completed",
1220
+ ...encryptedContent != null && {
1221
+ encrypted_content: encryptedContent
1222
+ }
1223
+ });
1224
+ } else {
1225
+ inputWarnings.push({
1226
+ type: "other",
1227
+ message: "Reasoning parts without itemId or encrypted content cannot be sent back to xAI. Skipping."
1228
+ });
1229
+ }
1230
+ break;
1231
+ }
1205
1232
  case "reasoning-file":
1206
1233
  case "custom":
1207
1234
  case "file": {
@@ -1235,7 +1262,7 @@ async function convertToXaiResponsesInput({
1235
1262
  outputValue = output.value;
1236
1263
  break;
1237
1264
  case "execution-denied":
1238
- outputValue = (_e = output.reason) != null ? _e : "tool execution denied";
1265
+ outputValue = (_i = output.reason) != null ? _i : "tool execution denied";
1239
1266
  break;
1240
1267
  case "json":
1241
1268
  case "error-json":
@@ -1756,6 +1783,8 @@ var xaiLanguageModelResponsesOptions = z7.object({
1756
1783
  topLogprobs: z7.number().int().min(0).max(8).optional(),
1757
1784
  /**
1758
1785
  * Whether to store the input message(s) and model response for later retrieval.
1786
+ * Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
1787
+ * otherwise the API will return an error.
1759
1788
  * @default true
1760
1789
  */
1761
1790
  store: z7.boolean().optional(),
@@ -2111,7 +2140,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2111
2140
  toolChoice,
2112
2141
  reasoning
2113
2142
  }) {
2114
- var _a, _b, _c, _d, _e, _f, _g, _h;
2143
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2115
2144
  const warnings = [];
2116
2145
  const options = (_a = await parseProviderOptions3({
2117
2146
  provider: "xai",
@@ -2138,7 +2167,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2138
2167
  )) == null ? void 0 : _f.name;
2139
2168
  const { input, inputWarnings } = await convertToXaiResponsesInput({
2140
2169
  prompt,
2141
- store: true
2170
+ store: (_g = options.store) != null ? _g : true
2142
2171
  });
2143
2172
  warnings.push(...inputWarnings);
2144
2173
  const {
@@ -2158,7 +2187,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2158
2187
  include = [...include, "reasoning.encrypted_content"];
2159
2188
  }
2160
2189
  }
2161
- const resolvedReasoningEffort = (_g = options.reasoningEffort) != null ? _g : isCustomReasoning2(reasoning) ? reasoning === "none" ? void 0 : mapReasoningToProviderEffort2({
2190
+ const resolvedReasoningEffort = (_h = options.reasoningEffort) != null ? _h : isCustomReasoning2(reasoning) ? reasoning === "none" ? void 0 : mapReasoningToProviderEffort2({
2162
2191
  reasoning,
2163
2192
  effortMap: {
2164
2193
  minimal: "low",
@@ -2183,7 +2212,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2183
2212
  format: responseFormat.schema != null ? {
2184
2213
  type: "json_schema",
2185
2214
  strict: true,
2186
- name: (_h = responseFormat.name) != null ? _h : "response",
2215
+ name: (_i = responseFormat.name) != null ? _i : "response",
2187
2216
  description: responseFormat.description,
2188
2217
  schema: responseFormat.schema
2189
2218
  } : { type: "json_object" }
@@ -2349,11 +2378,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2349
2378
  case "reasoning": {
2350
2379
  const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : ((_o = part.content) != null ? _o : []).map((c) => c.text);
2351
2380
  const reasoningText = texts.filter((text) => text && text.length > 0).join("");
2352
- if (reasoningText) {
2353
- if (part.encrypted_content || part.id) {
2354
- content.push({
2355
- type: "reasoning",
2356
- text: reasoningText,
2381
+ if (reasoningText || part.encrypted_content) {
2382
+ const hasMetadata = part.encrypted_content || part.id;
2383
+ content.push({
2384
+ type: "reasoning",
2385
+ text: reasoningText,
2386
+ ...hasMetadata && {
2357
2387
  providerMetadata: {
2358
2388
  xai: {
2359
2389
  ...part.encrypted_content && {
@@ -2362,13 +2392,8 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2362
2392
  ...part.id && { itemId: part.id }
2363
2393
  }
2364
2394
  }
2365
- });
2366
- } else {
2367
- content.push({
2368
- type: "reasoning",
2369
- text: reasoningText
2370
- });
2371
- }
2395
+ }
2396
+ });
2372
2397
  }
2373
2398
  break;
2374
2399
  }
@@ -2887,7 +2912,7 @@ var xaiTools = {
2887
2912
  };
2888
2913
 
2889
2914
  // src/version.ts
2890
- var VERSION = true ? "4.0.0-beta.36" : "0.0.0-test";
2915
+ var VERSION = true ? "4.0.0-beta.38" : "0.0.0-test";
2891
2916
 
2892
2917
  // src/files/xai-files.ts
2893
2918
  import {