@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/dist/index.mjs CHANGED
@@ -1055,7 +1055,7 @@ import { convertToBase64 as convertToBase642 } from "@ai-sdk/provider-utils";
1055
1055
  async function convertToXaiResponsesInput({
1056
1056
  prompt
1057
1057
  }) {
1058
- var _a, _b, _c, _d, _e;
1058
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1059
1059
  const input = [];
1060
1060
  const inputWarnings = [];
1061
1061
  for (const message of prompt) {
@@ -1132,7 +1132,34 @@ async function convertToXaiResponsesInput({
1132
1132
  case "tool-result": {
1133
1133
  break;
1134
1134
  }
1135
- case "reasoning":
1135
+ case "reasoning": {
1136
+ const itemId = typeof ((_f = (_e = part.providerOptions) == null ? void 0 : _e.xai) == null ? void 0 : _f.itemId) === "string" ? part.providerOptions.xai.itemId : void 0;
1137
+ const encryptedContent = typeof ((_h = (_g = part.providerOptions) == null ? void 0 : _g.xai) == null ? void 0 : _h.reasoningEncryptedContent) === "string" ? part.providerOptions.xai.reasoningEncryptedContent : void 0;
1138
+ if (itemId != null || encryptedContent != null) {
1139
+ const summaryParts = [];
1140
+ if (part.text.length > 0) {
1141
+ summaryParts.push({
1142
+ type: "summary_text",
1143
+ text: part.text
1144
+ });
1145
+ }
1146
+ input.push({
1147
+ type: "reasoning",
1148
+ id: itemId != null ? itemId : "",
1149
+ summary: summaryParts,
1150
+ status: "completed",
1151
+ ...encryptedContent != null && {
1152
+ encrypted_content: encryptedContent
1153
+ }
1154
+ });
1155
+ } else {
1156
+ inputWarnings.push({
1157
+ type: "other",
1158
+ message: "Reasoning parts without itemId or encrypted content cannot be sent back to xAI. Skipping."
1159
+ });
1160
+ }
1161
+ break;
1162
+ }
1136
1163
  case "file": {
1137
1164
  inputWarnings.push({
1138
1165
  type: "other",
@@ -1164,7 +1191,7 @@ async function convertToXaiResponsesInput({
1164
1191
  outputValue = output.value;
1165
1192
  break;
1166
1193
  case "execution-denied":
1167
- outputValue = (_e = output.reason) != null ? _e : "tool execution denied";
1194
+ outputValue = (_i = output.reason) != null ? _i : "tool execution denied";
1168
1195
  break;
1169
1196
  case "json":
1170
1197
  case "error-json":
@@ -1655,6 +1682,12 @@ var xaiResponsesChunkSchema = z6.union([
1655
1682
  usage: xaiResponsesUsageSchema.nullish()
1656
1683
  })
1657
1684
  }),
1685
+ z6.object({
1686
+ type: z6.literal("error"),
1687
+ code: z6.string().nullish(),
1688
+ message: z6.string(),
1689
+ param: z6.string().nullish()
1690
+ }),
1658
1691
  z6.object({
1659
1692
  type: z6.literal("response.done"),
1660
1693
  response: xaiResponsesResponseSchema
@@ -1677,6 +1710,8 @@ var xaiLanguageModelResponsesOptions = z7.object({
1677
1710
  topLogprobs: z7.number().int().min(0).max(8).optional(),
1678
1711
  /**
1679
1712
  * Whether to store the input message(s) and model response for later retrieval.
1713
+ * Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
1714
+ * otherwise the API will return an error.
1680
1715
  * @default true
1681
1716
  */
1682
1717
  store: z7.boolean().optional(),
@@ -2022,7 +2057,7 @@ var XaiResponsesLanguageModel = class {
2022
2057
  tools,
2023
2058
  toolChoice
2024
2059
  }) {
2025
- var _a, _b, _c, _d, _e, _f, _g;
2060
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2026
2061
  const warnings = [];
2027
2062
  const options = (_a = await parseProviderOptions3({
2028
2063
  provider: "xai",
@@ -2049,7 +2084,7 @@ var XaiResponsesLanguageModel = class {
2049
2084
  )) == null ? void 0 : _f.name;
2050
2085
  const { input, inputWarnings } = await convertToXaiResponsesInput({
2051
2086
  prompt,
2052
- store: true
2087
+ store: (_g = options.store) != null ? _g : true
2053
2088
  });
2054
2089
  warnings.push(...inputWarnings);
2055
2090
  const {
@@ -2083,7 +2118,7 @@ var XaiResponsesLanguageModel = class {
2083
2118
  format: responseFormat.schema != null ? {
2084
2119
  type: "json_schema",
2085
2120
  strict: true,
2086
- name: (_g = responseFormat.name) != null ? _g : "response",
2121
+ name: (_h = responseFormat.name) != null ? _h : "response",
2087
2122
  description: responseFormat.description,
2088
2123
  schema: responseFormat.schema
2089
2124
  } : { type: "json_object" }
@@ -2241,12 +2276,13 @@ var XaiResponsesLanguageModel = class {
2241
2276
  }
2242
2277
  case "reasoning": {
2243
2278
  const summaryTexts = part.summary.map((s) => s.text).filter((text) => text && text.length > 0);
2244
- if (summaryTexts.length > 0) {
2245
- const reasoningText = summaryTexts.join("");
2246
- if (part.encrypted_content || part.id) {
2247
- content.push({
2248
- type: "reasoning",
2249
- text: reasoningText,
2279
+ const reasoningText = summaryTexts.join("");
2280
+ if (reasoningText || part.encrypted_content) {
2281
+ const hasMetadata = part.encrypted_content || part.id;
2282
+ content.push({
2283
+ type: "reasoning",
2284
+ text: reasoningText,
2285
+ ...hasMetadata && {
2250
2286
  providerMetadata: {
2251
2287
  xai: {
2252
2288
  ...part.encrypted_content && {
@@ -2255,13 +2291,8 @@ var XaiResponsesLanguageModel = class {
2255
2291
  ...part.id && { itemId: part.id }
2256
2292
  }
2257
2293
  }
2258
- });
2259
- } else {
2260
- content.push({
2261
- type: "reasoning",
2262
- text: reasoningText
2263
- });
2264
- }
2294
+ }
2295
+ });
2265
2296
  }
2266
2297
  break;
2267
2298
  }
@@ -2487,6 +2518,10 @@ var XaiResponsesLanguageModel = class {
2487
2518
  }
2488
2519
  return;
2489
2520
  }
2521
+ if (event.type === "error") {
2522
+ controller.enqueue({ type: "error", error: event });
2523
+ return;
2524
+ }
2490
2525
  if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
2491
2526
  return;
2492
2527
  }
@@ -2776,7 +2811,7 @@ var xaiTools = {
2776
2811
  };
2777
2812
 
2778
2813
  // src/version.ts
2779
- var VERSION = true ? "3.0.81" : "0.0.0-test";
2814
+ var VERSION = true ? "3.0.83" : "0.0.0-test";
2780
2815
 
2781
2816
  // src/xai-video-model.ts
2782
2817
  import {