@ai-sdk/xai 2.0.64 → 2.0.66

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
+ ## 2.0.66
4
+
5
+ ### Patch Changes
6
+
7
+ - 92e25ae: fix (provider/xai): add response.incomplete and response.failed streaming event handling
8
+
9
+ ## 2.0.65
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [a27a978]
14
+ - @ai-sdk/provider-utils@3.0.23
15
+ - @ai-sdk/openai-compatible@1.0.35
16
+
3
17
  ## 2.0.64
4
18
 
5
19
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1209,6 +1209,24 @@ var xaiResponsesChunkSchema = import_v44.z.union([
1209
1209
  output_index: import_v44.z.number(),
1210
1210
  arguments: import_v44.z.string()
1211
1211
  }),
1212
+ import_v44.z.object({
1213
+ type: import_v44.z.literal("response.incomplete"),
1214
+ response: import_v44.z.object({
1215
+ incomplete_details: import_v44.z.object({ reason: import_v44.z.string() }).nullish(),
1216
+ usage: xaiResponsesUsageSchema.nullish()
1217
+ })
1218
+ }),
1219
+ import_v44.z.object({
1220
+ type: import_v44.z.literal("response.failed"),
1221
+ response: import_v44.z.object({
1222
+ error: import_v44.z.object({
1223
+ code: import_v44.z.string().nullish(),
1224
+ message: import_v44.z.string()
1225
+ }).nullish(),
1226
+ incomplete_details: import_v44.z.object({ reason: import_v44.z.string() }).nullish(),
1227
+ usage: xaiResponsesUsageSchema.nullish()
1228
+ })
1229
+ }),
1212
1230
  import_v44.z.object({
1213
1231
  type: import_v44.z.literal("response.done"),
1214
1232
  response: xaiResponsesResponseSchema
@@ -1226,6 +1244,7 @@ function mapXaiResponsesFinishReason(finishReason) {
1226
1244
  case "completed":
1227
1245
  return "stop";
1228
1246
  case "length":
1247
+ case "max_output_tokens":
1229
1248
  return "length";
1230
1249
  case "tool_calls":
1231
1250
  case "function_call":
@@ -1936,7 +1955,7 @@ var XaiResponsesLanguageModel = class {
1936
1955
  controller.enqueue({ type: "stream-start", warnings });
1937
1956
  },
1938
1957
  transform(chunk, controller) {
1939
- var _a2, _b, _c, _d, _e, _f, _g, _h;
1958
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1940
1959
  if (options.includeRawChunks) {
1941
1960
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1942
1961
  }
@@ -2058,7 +2077,7 @@ var XaiResponsesLanguageModel = class {
2058
2077
  }
2059
2078
  return;
2060
2079
  }
2061
- if (event.type === "response.done" || event.type === "response.completed") {
2080
+ if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
2062
2081
  const response2 = event.response;
2063
2082
  if (response2.usage) {
2064
2083
  const converted = convertXaiResponsesUsage(response2.usage);
@@ -2068,11 +2087,29 @@ var XaiResponsesLanguageModel = class {
2068
2087
  usage.reasoningTokens = converted.reasoningTokens;
2069
2088
  usage.cachedInputTokens = converted.cachedInputTokens;
2070
2089
  }
2071
- if (response2.status) {
2090
+ if (event.type === "response.incomplete") {
2091
+ const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
2092
+ finishReason = reason ? mapXaiResponsesFinishReason(reason) : "other";
2093
+ } else if ("status" in response2 && response2.status) {
2072
2094
  finishReason = hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status);
2073
2095
  }
2074
2096
  return;
2075
2097
  }
2098
+ if (event.type === "response.failed") {
2099
+ const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2100
+ finishReason = reason ? mapXaiResponsesFinishReason(reason) : "error";
2101
+ if (event.response.usage) {
2102
+ const converted = convertXaiResponsesUsage(
2103
+ event.response.usage
2104
+ );
2105
+ usage.inputTokens = converted.inputTokens;
2106
+ usage.outputTokens = converted.outputTokens;
2107
+ usage.totalTokens = converted.totalTokens;
2108
+ usage.reasoningTokens = converted.reasoningTokens;
2109
+ usage.cachedInputTokens = converted.cachedInputTokens;
2110
+ }
2111
+ return;
2112
+ }
2076
2113
  if (event.type === "response.function_call_arguments.delta") {
2077
2114
  const toolCall = ongoingToolCalls[event.output_index];
2078
2115
  if (toolCall != null) {
@@ -2130,15 +2167,15 @@ var XaiResponsesLanguageModel = class {
2130
2167
  "x_semantic_search",
2131
2168
  "x_thread_fetch"
2132
2169
  ];
2133
- let toolName = (_c = part.name) != null ? _c : "";
2134
- if (webSearchSubTools.includes((_d = part.name) != null ? _d : "") || part.type === "web_search_call") {
2170
+ let toolName = (_e = part.name) != null ? _e : "";
2171
+ if (webSearchSubTools.includes((_f = part.name) != null ? _f : "") || part.type === "web_search_call") {
2135
2172
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2136
- } else if (xSearchSubTools.includes((_e = part.name) != null ? _e : "") || part.type === "x_search_call") {
2173
+ } else if (xSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "x_search_call") {
2137
2174
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2138
2175
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2139
2176
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2140
2177
  }
2141
- const toolInput = part.type === "custom_tool_call" ? (_f = part.input) != null ? _f : "" : (_g = part.arguments) != null ? _g : "";
2178
+ const toolInput = part.type === "custom_tool_call" ? (_h = part.input) != null ? _h : "" : (_i = part.arguments) != null ? _i : "";
2142
2179
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2143
2180
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2144
2181
  seenToolCalls.add(part.id);
@@ -2191,7 +2228,7 @@ var XaiResponsesLanguageModel = class {
2191
2228
  sourceType: "url",
2192
2229
  id: self.config.generateId(),
2193
2230
  url: annotation.url,
2194
- title: (_h = annotation.title) != null ? _h : annotation.url
2231
+ title: (_j = annotation.title) != null ? _j : annotation.url
2195
2232
  });
2196
2233
  }
2197
2234
  }
@@ -2300,7 +2337,7 @@ var xaiTools = {
2300
2337
  };
2301
2338
 
2302
2339
  // src/version.ts
2303
- var VERSION = true ? "2.0.64" : "0.0.0-test";
2340
+ var VERSION = true ? "2.0.66" : "0.0.0-test";
2304
2341
 
2305
2342
  // src/xai-provider.ts
2306
2343
  var xaiErrorStructure = {