@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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 3.0.50
4
+
5
+ ### Patch Changes
6
+
7
+ - de16a00: fix(xai): add dummy usage data when response.usage is missing
8
+
9
+ ## 3.0.49
10
+
11
+ ### Patch Changes
12
+
13
+ - 8b3e72d: fix (provider/xai): handle new reasoning text chunk parts
14
+
3
15
  ## 3.0.48
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -561,8 +561,10 @@ var XaiChatLanguageModel = class {
561
561
  unified: mapXaiFinishReason(choice.finish_reason),
562
562
  raw: (_b = choice.finish_reason) != null ? _b : void 0
563
563
  },
564
- usage: convertXaiChatUsage(response.usage),
565
- // defined when there is no error
564
+ usage: response.usage ? convertXaiChatUsage(response.usage) : {
565
+ inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
566
+ outputTokens: { total: 0, text: 0, reasoning: 0 }
567
+ },
566
568
  request: { body },
567
569
  response: {
568
570
  ...getResponseMetadata(response),
@@ -774,7 +776,19 @@ var XaiChatLanguageModel = class {
774
776
  });
775
777
  }
776
778
  }
777
- controller.enqueue({ type: "finish", finishReason, usage });
779
+ controller.enqueue({
780
+ type: "finish",
781
+ finishReason,
782
+ usage: usage != null ? usage : {
783
+ inputTokens: {
784
+ total: 0,
785
+ noCache: 0,
786
+ cacheRead: 0,
787
+ cacheWrite: 0
788
+ },
789
+ outputTokens: { total: 0, text: 0, reasoning: 0 }
790
+ }
791
+ });
778
792
  }
779
793
  })
780
794
  ),
@@ -1277,6 +1291,20 @@ var xaiResponsesChunkSchema = import_v44.z.union([
1277
1291
  summary_index: import_v44.z.number(),
1278
1292
  text: import_v44.z.string()
1279
1293
  }),
1294
+ import_v44.z.object({
1295
+ type: import_v44.z.literal("response.reasoning_text.delta"),
1296
+ item_id: import_v44.z.string(),
1297
+ output_index: import_v44.z.number(),
1298
+ content_index: import_v44.z.number(),
1299
+ delta: import_v44.z.string()
1300
+ }),
1301
+ import_v44.z.object({
1302
+ type: import_v44.z.literal("response.reasoning_text.done"),
1303
+ item_id: import_v44.z.string(),
1304
+ output_index: import_v44.z.number(),
1305
+ content_index: import_v44.z.number(),
1306
+ text: import_v44.z.string()
1307
+ }),
1280
1308
  import_v44.z.object({
1281
1309
  type: import_v44.z.literal("response.web_search_call.in_progress"),
1282
1310
  item_id: import_v44.z.string(),
@@ -2127,6 +2155,35 @@ var XaiResponsesLanguageModel = class {
2127
2155
  if (event.type === "response.reasoning_summary_text.done") {
2128
2156
  return;
2129
2157
  }
2158
+ if (event.type === "response.reasoning_text.delta") {
2159
+ const blockId = `reasoning-${event.item_id}`;
2160
+ if (activeReasoning[event.item_id] == null) {
2161
+ activeReasoning[event.item_id] = {};
2162
+ controller.enqueue({
2163
+ type: "reasoning-start",
2164
+ id: blockId,
2165
+ providerMetadata: {
2166
+ xai: {
2167
+ itemId: event.item_id
2168
+ }
2169
+ }
2170
+ });
2171
+ }
2172
+ controller.enqueue({
2173
+ type: "reasoning-delta",
2174
+ id: blockId,
2175
+ delta: event.delta,
2176
+ providerMetadata: {
2177
+ xai: {
2178
+ itemId: event.item_id
2179
+ }
2180
+ }
2181
+ });
2182
+ return;
2183
+ }
2184
+ if (event.type === "response.reasoning_text.done") {
2185
+ return;
2186
+ }
2130
2187
  if (event.type === "response.output_text.delta") {
2131
2188
  const blockId = `text-${event.item_id}`;
2132
2189
  if (contentBlocks[blockId] == null) {
@@ -2382,7 +2439,19 @@ var XaiResponsesLanguageModel = class {
2382
2439
  });
2383
2440
  }
2384
2441
  }
2385
- controller.enqueue({ type: "finish", finishReason, usage });
2442
+ controller.enqueue({
2443
+ type: "finish",
2444
+ finishReason,
2445
+ usage: usage != null ? usage : {
2446
+ inputTokens: {
2447
+ total: 0,
2448
+ noCache: 0,
2449
+ cacheRead: 0,
2450
+ cacheWrite: 0
2451
+ },
2452
+ outputTokens: { total: 0, text: 0, reasoning: 0 }
2453
+ }
2454
+ });
2386
2455
  }
2387
2456
  })
2388
2457
  ),
@@ -2447,7 +2516,7 @@ var xaiTools = {
2447
2516
  };
2448
2517
 
2449
2518
  // src/version.ts
2450
- var VERSION = true ? "3.0.48" : "0.0.0-test";
2519
+ var VERSION = true ? "3.0.50" : "0.0.0-test";
2451
2520
 
2452
2521
  // src/xai-provider.ts
2453
2522
  var xaiErrorStructure = {