@ai-sdk/xai 3.0.90 → 3.0.91

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.90",
3
+ "version": "3.0.91",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -516,16 +516,18 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
516
516
  if (event.type === 'response.reasoning_summary_part.added') {
517
517
  const blockId = `reasoning-${event.item_id}`;
518
518
 
519
- activeReasoning[event.item_id] = {};
520
- controller.enqueue({
521
- type: 'reasoning-start',
522
- id: blockId,
523
- providerMetadata: {
524
- xai: {
525
- itemId: event.item_id,
519
+ if (activeReasoning[event.item_id] == null) {
520
+ activeReasoning[event.item_id] = {};
521
+ controller.enqueue({
522
+ type: 'reasoning-start',
523
+ id: blockId,
524
+ providerMetadata: {
525
+ xai: {
526
+ itemId: event.item_id,
527
+ },
526
528
  },
527
- },
528
- });
529
+ });
530
+ }
529
531
  }
530
532
 
531
533
  if (event.type === 'response.reasoning_summary_text.delta') {
package/src/xai-error.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
2
2
  import { z } from 'zod/v4';
3
3
 
4
- // Add error schema and structure
5
- export const xaiErrorDataSchema = z.object({
4
+ const chatCompletionsErrorSchema = z.object({
6
5
  error: z.object({
7
6
  message: z.string(),
8
7
  type: z.string().nullish(),
@@ -11,9 +10,20 @@ export const xaiErrorDataSchema = z.object({
11
10
  }),
12
11
  });
13
12
 
13
+ const responsesErrorSchema = z.object({
14
+ code: z.string(),
15
+ error: z.string(),
16
+ });
17
+
18
+ export const xaiErrorDataSchema = z.union([
19
+ chatCompletionsErrorSchema,
20
+ responsesErrorSchema,
21
+ ]);
22
+
14
23
  export type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
15
24
 
16
25
  export const xaiFailedResponseHandler = createJsonErrorResponseHandler({
17
26
  errorSchema: xaiErrorDataSchema,
18
- errorToMessage: data => data.error.message,
27
+ errorToMessage: data =>
28
+ 'code' in data ? `${data.code}: ${data.error}` : data.error.message,
19
29
  });