@ai-sdk/xai 3.0.89 → 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.89",
3
+ "version": "3.0.91",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Recursively removes `additionalProperties: false` entries from a JSON
3
+ * schema.
4
+ * Used to sanitize tool input schemas before sending them to the xAI API.
5
+ * https://docs.x.ai/developers/model-capabilities/text/structured-outputs#supported-types
6
+ */
7
+ export function removeAdditionalPropertiesFalse(value: unknown): unknown {
8
+ if (Array.isArray(value)) {
9
+ return value.map(removeAdditionalPropertiesFalse);
10
+ }
11
+
12
+ if (value == null || typeof value !== 'object') {
13
+ return value;
14
+ }
15
+
16
+ const result: Record<string, unknown> = {};
17
+ for (const [key, propertyValue] of Object.entries(value)) {
18
+ if (key === 'additionalProperties' && propertyValue === false) {
19
+ continue;
20
+ }
21
+ result[key] = removeAdditionalPropertiesFalse(propertyValue);
22
+ }
23
+ return result;
24
+ }
@@ -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') {
@@ -4,6 +4,7 @@ import {
4
4
  type SharedV3Warning,
5
5
  } from '@ai-sdk/provider';
6
6
  import { validateTypes } from '@ai-sdk/provider-utils';
7
+ import { removeAdditionalPropertiesFalse } from '../remove-additional-properties';
7
8
  import { fileSearchArgsSchema } from '../tool/file-search';
8
9
  import { mcpServerArgsSchema } from '../tool/mcp-server';
9
10
  import { webSearchArgsSchema } from '../tool/web-search';
@@ -142,7 +143,7 @@ export async function prepareResponsesTools({
142
143
  type: 'function',
143
144
  name: tool.name,
144
145
  description: tool.description,
145
- parameters: tool.inputSchema,
146
+ parameters: removeAdditionalPropertiesFalse(tool.inputSchema),
146
147
  ...(tool.strict != null ? { strict: tool.strict } : {}),
147
148
  });
148
149
  }
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
  });
@@ -3,6 +3,7 @@ import {
3
3
  type LanguageModelV3CallOptions,
4
4
  type SharedV3Warning,
5
5
  } from '@ai-sdk/provider';
6
+ import { removeAdditionalPropertiesFalse } from './remove-additional-properties';
6
7
  import type { XaiToolChoice } from './xai-chat-prompt';
7
8
 
8
9
  export function prepareTools({
@@ -58,7 +59,7 @@ export function prepareTools({
58
59
  function: {
59
60
  name: tool.name,
60
61
  description: tool.description,
61
- parameters: tool.inputSchema,
62
+ parameters: removeAdditionalPropertiesFalse(tool.inputSchema),
62
63
  ...(tool.strict != null ? { strict: tool.strict } : {}),
63
64
  },
64
65
  });