@ai-sdk/xai 3.0.48 → 3.0.50

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
@@ -549,8 +549,10 @@ var XaiChatLanguageModel = class {
549
549
  unified: mapXaiFinishReason(choice.finish_reason),
550
550
  raw: (_b = choice.finish_reason) != null ? _b : void 0
551
551
  },
552
- usage: convertXaiChatUsage(response.usage),
553
- // defined when there is no error
552
+ usage: response.usage ? convertXaiChatUsage(response.usage) : {
553
+ inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
554
+ outputTokens: { total: 0, text: 0, reasoning: 0 }
555
+ },
554
556
  request: { body },
555
557
  response: {
556
558
  ...getResponseMetadata(response),
@@ -762,7 +764,19 @@ var XaiChatLanguageModel = class {
762
764
  });
763
765
  }
764
766
  }
765
- controller.enqueue({ type: "finish", finishReason, usage });
767
+ controller.enqueue({
768
+ type: "finish",
769
+ finishReason,
770
+ usage: usage != null ? usage : {
771
+ inputTokens: {
772
+ total: 0,
773
+ noCache: 0,
774
+ cacheRead: 0,
775
+ cacheWrite: 0
776
+ },
777
+ outputTokens: { total: 0, text: 0, reasoning: 0 }
778
+ }
779
+ });
766
780
  }
767
781
  })
768
782
  ),
@@ -1273,6 +1287,20 @@ var xaiResponsesChunkSchema = z4.union([
1273
1287
  summary_index: z4.number(),
1274
1288
  text: z4.string()
1275
1289
  }),
1290
+ z4.object({
1291
+ type: z4.literal("response.reasoning_text.delta"),
1292
+ item_id: z4.string(),
1293
+ output_index: z4.number(),
1294
+ content_index: z4.number(),
1295
+ delta: z4.string()
1296
+ }),
1297
+ z4.object({
1298
+ type: z4.literal("response.reasoning_text.done"),
1299
+ item_id: z4.string(),
1300
+ output_index: z4.number(),
1301
+ content_index: z4.number(),
1302
+ text: z4.string()
1303
+ }),
1276
1304
  z4.object({
1277
1305
  type: z4.literal("response.web_search_call.in_progress"),
1278
1306
  item_id: z4.string(),
@@ -2141,6 +2169,35 @@ var XaiResponsesLanguageModel = class {
2141
2169
  if (event.type === "response.reasoning_summary_text.done") {
2142
2170
  return;
2143
2171
  }
2172
+ if (event.type === "response.reasoning_text.delta") {
2173
+ const blockId = `reasoning-${event.item_id}`;
2174
+ if (activeReasoning[event.item_id] == null) {
2175
+ activeReasoning[event.item_id] = {};
2176
+ controller.enqueue({
2177
+ type: "reasoning-start",
2178
+ id: blockId,
2179
+ providerMetadata: {
2180
+ xai: {
2181
+ itemId: event.item_id
2182
+ }
2183
+ }
2184
+ });
2185
+ }
2186
+ controller.enqueue({
2187
+ type: "reasoning-delta",
2188
+ id: blockId,
2189
+ delta: event.delta,
2190
+ providerMetadata: {
2191
+ xai: {
2192
+ itemId: event.item_id
2193
+ }
2194
+ }
2195
+ });
2196
+ return;
2197
+ }
2198
+ if (event.type === "response.reasoning_text.done") {
2199
+ return;
2200
+ }
2144
2201
  if (event.type === "response.output_text.delta") {
2145
2202
  const blockId = `text-${event.item_id}`;
2146
2203
  if (contentBlocks[blockId] == null) {
@@ -2396,7 +2453,19 @@ var XaiResponsesLanguageModel = class {
2396
2453
  });
2397
2454
  }
2398
2455
  }
2399
- controller.enqueue({ type: "finish", finishReason, usage });
2456
+ controller.enqueue({
2457
+ type: "finish",
2458
+ finishReason,
2459
+ usage: usage != null ? usage : {
2460
+ inputTokens: {
2461
+ total: 0,
2462
+ noCache: 0,
2463
+ cacheRead: 0,
2464
+ cacheWrite: 0
2465
+ },
2466
+ outputTokens: { total: 0, text: 0, reasoning: 0 }
2467
+ }
2468
+ });
2400
2469
  }
2401
2470
  })
2402
2471
  ),
@@ -2461,7 +2530,7 @@ var xaiTools = {
2461
2530
  };
2462
2531
 
2463
2532
  // src/version.ts
2464
- var VERSION = true ? "3.0.48" : "0.0.0-test";
2533
+ var VERSION = true ? "3.0.50" : "0.0.0-test";
2465
2534
 
2466
2535
  // src/xai-provider.ts
2467
2536
  var xaiErrorStructure = {