@ai-sdk/xai 3.0.81 → 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,17 @@
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
+
9
+ ## 3.0.82
10
+
11
+ ### Patch Changes
12
+
13
+ - 72ebb54: fix (provider/xai): handle mid-stream error chunks
14
+
3
15
  ## 3.0.81
4
16
 
5
17
  ### 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":
@@ -1652,6 +1679,12 @@ var xaiResponsesChunkSchema = import_v46.z.union([
1652
1679
  usage: xaiResponsesUsageSchema.nullish()
1653
1680
  })
1654
1681
  }),
1682
+ import_v46.z.object({
1683
+ type: import_v46.z.literal("error"),
1684
+ code: import_v46.z.string().nullish(),
1685
+ message: import_v46.z.string(),
1686
+ param: import_v46.z.string().nullish()
1687
+ }),
1655
1688
  import_v46.z.object({
1656
1689
  type: import_v46.z.literal("response.done"),
1657
1690
  response: xaiResponsesResponseSchema
@@ -1674,6 +1707,8 @@ var xaiLanguageModelResponsesOptions = import_v47.z.object({
1674
1707
  topLogprobs: import_v47.z.number().int().min(0).max(8).optional(),
1675
1708
  /**
1676
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.
1677
1712
  * @default true
1678
1713
  */
1679
1714
  store: import_v47.z.boolean().optional(),
@@ -2001,7 +2036,7 @@ var XaiResponsesLanguageModel = class {
2001
2036
  tools,
2002
2037
  toolChoice
2003
2038
  }) {
2004
- var _a, _b, _c, _d, _e, _f, _g;
2039
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2005
2040
  const warnings = [];
2006
2041
  const options = (_a = await (0, import_provider_utils11.parseProviderOptions)({
2007
2042
  provider: "xai",
@@ -2028,7 +2063,7 @@ var XaiResponsesLanguageModel = class {
2028
2063
  )) == null ? void 0 : _f.name;
2029
2064
  const { input, inputWarnings } = await convertToXaiResponsesInput({
2030
2065
  prompt,
2031
- store: true
2066
+ store: (_g = options.store) != null ? _g : true
2032
2067
  });
2033
2068
  warnings.push(...inputWarnings);
2034
2069
  const {
@@ -2062,7 +2097,7 @@ var XaiResponsesLanguageModel = class {
2062
2097
  format: responseFormat.schema != null ? {
2063
2098
  type: "json_schema",
2064
2099
  strict: true,
2065
- name: (_g = responseFormat.name) != null ? _g : "response",
2100
+ name: (_h = responseFormat.name) != null ? _h : "response",
2066
2101
  description: responseFormat.description,
2067
2102
  schema: responseFormat.schema
2068
2103
  } : { type: "json_object" }
@@ -2220,12 +2255,13 @@ var XaiResponsesLanguageModel = class {
2220
2255
  }
2221
2256
  case "reasoning": {
2222
2257
  const summaryTexts = part.summary.map((s) => s.text).filter((text) => text && text.length > 0);
2223
- if (summaryTexts.length > 0) {
2224
- const reasoningText = summaryTexts.join("");
2225
- if (part.encrypted_content || part.id) {
2226
- content.push({
2227
- type: "reasoning",
2228
- 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 && {
2229
2265
  providerMetadata: {
2230
2266
  xai: {
2231
2267
  ...part.encrypted_content && {
@@ -2234,13 +2270,8 @@ var XaiResponsesLanguageModel = class {
2234
2270
  ...part.id && { itemId: part.id }
2235
2271
  }
2236
2272
  }
2237
- });
2238
- } else {
2239
- content.push({
2240
- type: "reasoning",
2241
- text: reasoningText
2242
- });
2243
- }
2273
+ }
2274
+ });
2244
2275
  }
2245
2276
  break;
2246
2277
  }
@@ -2466,6 +2497,10 @@ var XaiResponsesLanguageModel = class {
2466
2497
  }
2467
2498
  return;
2468
2499
  }
2500
+ if (event.type === "error") {
2501
+ controller.enqueue({ type: "error", error: event });
2502
+ return;
2503
+ }
2469
2504
  if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
2470
2505
  return;
2471
2506
  }
@@ -2755,7 +2790,7 @@ var xaiTools = {
2755
2790
  };
2756
2791
 
2757
2792
  // src/version.ts
2758
- var VERSION = true ? "3.0.81" : "0.0.0-test";
2793
+ var VERSION = true ? "3.0.83" : "0.0.0-test";
2759
2794
 
2760
2795
  // src/xai-video-model.ts
2761
2796
  var import_provider6 = require("@ai-sdk/provider");