@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/xai",
3
- "version": "3.0.48",
3
+ "version": "3.0.50",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -341,6 +341,20 @@ export const xaiResponsesChunkSchema = z.union([
341
341
  summary_index: z.number(),
342
342
  text: z.string(),
343
343
  }),
344
+ z.object({
345
+ type: z.literal('response.reasoning_text.delta'),
346
+ item_id: z.string(),
347
+ output_index: z.number(),
348
+ content_index: z.number(),
349
+ delta: z.string(),
350
+ }),
351
+ z.object({
352
+ type: z.literal('response.reasoning_text.done'),
353
+ item_id: z.string(),
354
+ output_index: z.number(),
355
+ content_index: z.number(),
356
+ text: z.string(),
357
+ }),
344
358
  z.object({
345
359
  type: z.literal('response.web_search_call.in_progress'),
346
360
  item_id: z.string(),
@@ -529,6 +529,40 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
529
529
  return;
530
530
  }
531
531
 
532
+ if (event.type === 'response.reasoning_text.delta') {
533
+ const blockId = `reasoning-${event.item_id}`;
534
+
535
+ if (activeReasoning[event.item_id] == null) {
536
+ activeReasoning[event.item_id] = {};
537
+ controller.enqueue({
538
+ type: 'reasoning-start',
539
+ id: blockId,
540
+ providerMetadata: {
541
+ xai: {
542
+ itemId: event.item_id,
543
+ },
544
+ },
545
+ });
546
+ }
547
+
548
+ controller.enqueue({
549
+ type: 'reasoning-delta',
550
+ id: blockId,
551
+ delta: event.delta,
552
+ providerMetadata: {
553
+ xai: {
554
+ itemId: event.item_id,
555
+ },
556
+ },
557
+ });
558
+
559
+ return;
560
+ }
561
+
562
+ if (event.type === 'response.reasoning_text.done') {
563
+ return;
564
+ }
565
+
532
566
  if (event.type === 'response.output_text.delta') {
533
567
  const blockId = `text-${event.item_id}`;
534
568
 
@@ -874,7 +908,19 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
874
908
  }
875
909
  }
876
910
 
877
- controller.enqueue({ type: 'finish', finishReason, usage: usage! });
911
+ controller.enqueue({
912
+ type: 'finish',
913
+ finishReason,
914
+ usage: usage ?? {
915
+ inputTokens: {
916
+ total: 0,
917
+ noCache: 0,
918
+ cacheRead: 0,
919
+ cacheWrite: 0,
920
+ },
921
+ outputTokens: { total: 0, text: 0, reasoning: 0 },
922
+ },
923
+ });
878
924
  },
879
925
  }),
880
926
  ),
@@ -287,7 +287,12 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
287
287
  unified: mapXaiFinishReason(choice.finish_reason),
288
288
  raw: choice.finish_reason ?? undefined,
289
289
  },
290
- usage: convertXaiChatUsage(response.usage!), // defined when there is no error
290
+ usage: response.usage
291
+ ? convertXaiChatUsage(response.usage)
292
+ : {
293
+ inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
294
+ outputTokens: { total: 0, text: 0, reasoning: 0 },
295
+ },
291
296
  request: { body },
292
297
  response: {
293
298
  ...getResponseMetadata(response),
@@ -573,7 +578,19 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
573
578
  }
574
579
  }
575
580
 
576
- controller.enqueue({ type: 'finish', finishReason, usage: usage! });
581
+ controller.enqueue({
582
+ type: 'finish',
583
+ finishReason,
584
+ usage: usage ?? {
585
+ inputTokens: {
586
+ total: 0,
587
+ noCache: 0,
588
+ cacheRead: 0,
589
+ cacheWrite: 0,
590
+ },
591
+ outputTokens: { total: 0, text: 0, reasoning: 0 },
592
+ },
593
+ });
577
594
  },
578
595
  }),
579
596
  ),