@ai-sdk/xai 2.0.65 → 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/dist/index.mjs CHANGED
@@ -1204,6 +1204,24 @@ var xaiResponsesChunkSchema = z4.union([
1204
1204
  output_index: z4.number(),
1205
1205
  arguments: z4.string()
1206
1206
  }),
1207
+ z4.object({
1208
+ type: z4.literal("response.incomplete"),
1209
+ response: z4.object({
1210
+ incomplete_details: z4.object({ reason: z4.string() }).nullish(),
1211
+ usage: xaiResponsesUsageSchema.nullish()
1212
+ })
1213
+ }),
1214
+ z4.object({
1215
+ type: z4.literal("response.failed"),
1216
+ response: z4.object({
1217
+ error: z4.object({
1218
+ code: z4.string().nullish(),
1219
+ message: z4.string()
1220
+ }).nullish(),
1221
+ incomplete_details: z4.object({ reason: z4.string() }).nullish(),
1222
+ usage: xaiResponsesUsageSchema.nullish()
1223
+ })
1224
+ }),
1207
1225
  z4.object({
1208
1226
  type: z4.literal("response.done"),
1209
1227
  response: xaiResponsesResponseSchema
@@ -1221,6 +1239,7 @@ function mapXaiResponsesFinishReason(finishReason) {
1221
1239
  case "completed":
1222
1240
  return "stop";
1223
1241
  case "length":
1242
+ case "max_output_tokens":
1224
1243
  return "length";
1225
1244
  case "tool_calls":
1226
1245
  case "function_call":
@@ -1943,7 +1962,7 @@ var XaiResponsesLanguageModel = class {
1943
1962
  controller.enqueue({ type: "stream-start", warnings });
1944
1963
  },
1945
1964
  transform(chunk, controller) {
1946
- var _a2, _b, _c, _d, _e, _f, _g, _h;
1965
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1947
1966
  if (options.includeRawChunks) {
1948
1967
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1949
1968
  }
@@ -2065,7 +2084,7 @@ var XaiResponsesLanguageModel = class {
2065
2084
  }
2066
2085
  return;
2067
2086
  }
2068
- if (event.type === "response.done" || event.type === "response.completed") {
2087
+ if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
2069
2088
  const response2 = event.response;
2070
2089
  if (response2.usage) {
2071
2090
  const converted = convertXaiResponsesUsage(response2.usage);
@@ -2075,11 +2094,29 @@ var XaiResponsesLanguageModel = class {
2075
2094
  usage.reasoningTokens = converted.reasoningTokens;
2076
2095
  usage.cachedInputTokens = converted.cachedInputTokens;
2077
2096
  }
2078
- if (response2.status) {
2097
+ if (event.type === "response.incomplete") {
2098
+ const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
2099
+ finishReason = reason ? mapXaiResponsesFinishReason(reason) : "other";
2100
+ } else if ("status" in response2 && response2.status) {
2079
2101
  finishReason = hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status);
2080
2102
  }
2081
2103
  return;
2082
2104
  }
2105
+ if (event.type === "response.failed") {
2106
+ const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2107
+ finishReason = reason ? mapXaiResponsesFinishReason(reason) : "error";
2108
+ if (event.response.usage) {
2109
+ const converted = convertXaiResponsesUsage(
2110
+ event.response.usage
2111
+ );
2112
+ usage.inputTokens = converted.inputTokens;
2113
+ usage.outputTokens = converted.outputTokens;
2114
+ usage.totalTokens = converted.totalTokens;
2115
+ usage.reasoningTokens = converted.reasoningTokens;
2116
+ usage.cachedInputTokens = converted.cachedInputTokens;
2117
+ }
2118
+ return;
2119
+ }
2083
2120
  if (event.type === "response.function_call_arguments.delta") {
2084
2121
  const toolCall = ongoingToolCalls[event.output_index];
2085
2122
  if (toolCall != null) {
@@ -2137,15 +2174,15 @@ var XaiResponsesLanguageModel = class {
2137
2174
  "x_semantic_search",
2138
2175
  "x_thread_fetch"
2139
2176
  ];
2140
- let toolName = (_c = part.name) != null ? _c : "";
2141
- if (webSearchSubTools.includes((_d = part.name) != null ? _d : "") || part.type === "web_search_call") {
2177
+ let toolName = (_e = part.name) != null ? _e : "";
2178
+ if (webSearchSubTools.includes((_f = part.name) != null ? _f : "") || part.type === "web_search_call") {
2142
2179
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2143
- } else if (xSearchSubTools.includes((_e = part.name) != null ? _e : "") || part.type === "x_search_call") {
2180
+ } else if (xSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "x_search_call") {
2144
2181
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2145
2182
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2146
2183
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2147
2184
  }
2148
- const toolInput = part.type === "custom_tool_call" ? (_f = part.input) != null ? _f : "" : (_g = part.arguments) != null ? _g : "";
2185
+ const toolInput = part.type === "custom_tool_call" ? (_h = part.input) != null ? _h : "" : (_i = part.arguments) != null ? _i : "";
2149
2186
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2150
2187
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2151
2188
  seenToolCalls.add(part.id);
@@ -2198,7 +2235,7 @@ var XaiResponsesLanguageModel = class {
2198
2235
  sourceType: "url",
2199
2236
  id: self.config.generateId(),
2200
2237
  url: annotation.url,
2201
- title: (_h = annotation.title) != null ? _h : annotation.url
2238
+ title: (_j = annotation.title) != null ? _j : annotation.url
2202
2239
  });
2203
2240
  }
2204
2241
  }
@@ -2307,7 +2344,7 @@ var xaiTools = {
2307
2344
  };
2308
2345
 
2309
2346
  // src/version.ts
2310
- var VERSION = true ? "2.0.65" : "0.0.0-test";
2347
+ var VERSION = true ? "2.0.66" : "0.0.0-test";
2311
2348
 
2312
2349
  // src/xai-provider.ts
2313
2350
  var xaiErrorStructure = {