@ai-sdk/xai 3.0.80 → 3.0.82

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.80",
3
+ "version": "3.0.82",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -29,17 +29,17 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
+ "@ai-sdk/openai-compatible": "2.0.41",
32
33
  "@ai-sdk/provider": "3.0.8",
33
- "@ai-sdk/provider-utils": "4.0.23",
34
- "@ai-sdk/openai-compatible": "2.0.41"
34
+ "@ai-sdk/provider-utils": "4.0.23"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "20.17.24",
38
38
  "tsup": "^8",
39
39
  "typescript": "5.8.3",
40
40
  "zod": "3.25.76",
41
- "@vercel/ai-tsconfig": "0.0.0",
42
- "@ai-sdk/test-server": "1.0.3"
41
+ "@ai-sdk/test-server": "1.0.3",
42
+ "@vercel/ai-tsconfig": "0.0.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "zod": "^3.25.76 || ^4.1.8"
@@ -8,6 +8,7 @@ export function mapXaiResponsesFinishReason(
8
8
  case 'completed':
9
9
  return 'stop';
10
10
  case 'length':
11
+ case 'max_output_tokens':
11
12
  return 'length';
12
13
  case 'tool_calls':
13
14
  case 'function_call':
@@ -518,6 +518,32 @@ export const xaiResponsesChunkSchema = z.union([
518
518
  output_index: z.number(),
519
519
  output: z.string().optional(),
520
520
  }),
521
+ z.object({
522
+ type: z.literal('response.incomplete'),
523
+ response: z.object({
524
+ incomplete_details: z.object({ reason: z.string() }).nullish(),
525
+ usage: xaiResponsesUsageSchema.nullish(),
526
+ }),
527
+ }),
528
+ z.object({
529
+ type: z.literal('response.failed'),
530
+ response: z.object({
531
+ error: z
532
+ .object({
533
+ code: z.string().nullish(),
534
+ message: z.string(),
535
+ })
536
+ .nullish(),
537
+ incomplete_details: z.object({ reason: z.string() }).nullish(),
538
+ usage: xaiResponsesUsageSchema.nullish(),
539
+ }),
540
+ }),
541
+ z.object({
542
+ type: z.literal('error'),
543
+ code: z.string().nullish(),
544
+ message: z.string(),
545
+ param: z.string().nullish(),
546
+ }),
521
547
  z.object({
522
548
  type: z.literal('response.done'),
523
549
  response: xaiResponsesResponseSchema,
@@ -638,7 +638,8 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
638
638
 
639
639
  if (
640
640
  event.type === 'response.done' ||
641
- event.type === 'response.completed'
641
+ event.type === 'response.completed' ||
642
+ event.type === 'response.incomplete'
642
643
  ) {
643
644
  const response = event.response;
644
645
 
@@ -646,7 +647,18 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
646
647
  usage = convertXaiResponsesUsage(response.usage);
647
648
  }
648
649
 
649
- if (response.status) {
650
+ if (event.type === 'response.incomplete') {
651
+ const reason =
652
+ 'incomplete_details' in response
653
+ ? response.incomplete_details?.reason
654
+ : undefined;
655
+ finishReason = {
656
+ unified: reason
657
+ ? mapXaiResponsesFinishReason(reason)
658
+ : 'other',
659
+ raw: reason ?? 'incomplete',
660
+ };
661
+ } else if ('status' in response && response.status) {
650
662
  finishReason = {
651
663
  unified: hasFunctionCall
652
664
  ? 'tool-calls'
@@ -658,6 +670,25 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
658
670
  return;
659
671
  }
660
672
 
673
+ if (event.type === 'response.failed') {
674
+ const reason = event.response.incomplete_details?.reason;
675
+ finishReason = {
676
+ unified: reason ? mapXaiResponsesFinishReason(reason) : 'error',
677
+ raw: reason ?? 'error',
678
+ };
679
+
680
+ if (event.response.usage) {
681
+ usage = convertXaiResponsesUsage(event.response.usage);
682
+ }
683
+
684
+ return;
685
+ }
686
+
687
+ if (event.type === 'error') {
688
+ controller.enqueue({ type: 'error', error: event });
689
+ return;
690
+ }
691
+
661
692
  // Custom tool call input streaming - already handled by output_item events
662
693
  if (
663
694
  event.type === 'response.custom_tool_call_input.delta' ||