@ai-sdk/xai 3.0.52 → 3.0.54

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,19 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 3.0.54
4
+
5
+ ### Patch Changes
6
+
7
+ - 902e93b: Add support for `response.function_call_arguments.delta` and `response.function_call_arguments.done` streaming events in the xAI Responses API provider. Previously, xAI Grok models using function tools would fail with `AI_TypeValidationError` because these standard Responses API events were missing from the Zod schema and stream handler.
8
+
9
+ ## 3.0.53
10
+
11
+ ### Patch Changes
12
+
13
+ - 99fbed8: feat: normalize provider specific model options type names and ensure they are exported
14
+ - Updated dependencies [99fbed8]
15
+ - @ai-sdk/openai-compatible@2.0.29
16
+
3
17
  ## 3.0.52
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -4,7 +4,7 @@ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
5
5
 
6
6
  type XaiChatModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | 'grok-code-fast-1' | 'grok-4' | 'grok-4-0709' | 'grok-4-latest' | 'grok-3' | 'grok-3-latest' | 'grok-3-fast' | 'grok-3-fast-latest' | 'grok-3-mini' | 'grok-3-mini-latest' | 'grok-3-mini-fast' | 'grok-3-mini-fast-latest' | 'grok-2-vision-1212' | 'grok-2-vision' | 'grok-2-vision-latest' | 'grok-2-image-1212' | 'grok-2-image' | 'grok-2-image-latest' | 'grok-2-1212' | 'grok-2' | 'grok-2-latest' | 'grok-vision-beta' | 'grok-beta' | (string & {});
7
- declare const xaiProviderOptions: z.ZodObject<{
7
+ declare const xaiLanguageModelChatOptions: z.ZodObject<{
8
8
  reasoningEffort: z.ZodOptional<z.ZodEnum<{
9
9
  low: "low";
10
10
  high: "high";
@@ -44,7 +44,7 @@ declare const xaiProviderOptions: z.ZodObject<{
44
44
  }, z.core.$strip>]>>>;
45
45
  }, z.core.$strip>>;
46
46
  }, z.core.$strip>;
47
- type XaiProviderOptions = z.infer<typeof xaiProviderOptions>;
47
+ type XaiLanguageModelChatOptions = z.infer<typeof xaiLanguageModelChatOptions>;
48
48
 
49
49
  declare const xaiErrorDataSchema: z.ZodObject<{
50
50
  error: z.ZodObject<{
@@ -56,18 +56,11 @@ declare const xaiErrorDataSchema: z.ZodObject<{
56
56
  }, z.core.$strip>;
57
57
  type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
58
58
 
59
- declare const xaiImageProviderOptions: z.ZodObject<{
60
- aspect_ratio: z.ZodOptional<z.ZodString>;
61
- output_format: z.ZodOptional<z.ZodString>;
62
- sync_mode: z.ZodOptional<z.ZodBoolean>;
63
- }, z.core.$strip>;
64
- type XaiImageProviderOptions = z.infer<typeof xaiImageProviderOptions>;
65
-
66
59
  type XaiResponsesModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4' | 'grok-4-fast' | 'grok-4-fast-non-reasoning' | (string & {});
67
60
  /**
68
61
  * @see https://docs.x.ai/docs/api-reference#create-new-response
69
62
  */
70
- declare const xaiResponsesProviderOptions: z.ZodObject<{
63
+ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
71
64
  reasoningEffort: z.ZodOptional<z.ZodEnum<{
72
65
  low: "low";
73
66
  high: "high";
@@ -79,7 +72,14 @@ declare const xaiResponsesProviderOptions: z.ZodObject<{
79
72
  "file_search_call.results": "file_search_call.results";
80
73
  }>>>>;
81
74
  }, z.core.$strip>;
82
- type XaiResponsesProviderOptions = z.infer<typeof xaiResponsesProviderOptions>;
75
+ type XaiLanguageModelResponsesOptions = z.infer<typeof xaiLanguageModelResponsesOptions>;
76
+
77
+ declare const xaiImageModelOptions: z.ZodObject<{
78
+ aspect_ratio: z.ZodOptional<z.ZodString>;
79
+ output_format: z.ZodOptional<z.ZodString>;
80
+ sync_mode: z.ZodOptional<z.ZodBoolean>;
81
+ }, z.core.$strip>;
82
+ type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
83
83
 
84
84
  type XaiImageModelId = 'grok-2-image' | 'grok-imagine-image' | (string & {});
85
85
 
@@ -340,4 +340,4 @@ declare const xai: XaiProvider;
340
340
 
341
341
  declare const VERSION: string;
342
342
 
343
- export { VERSION, type XaiErrorData, type XaiImageProviderOptions, type XaiProvider, type XaiProviderOptions, type XaiProviderSettings, type XaiResponsesProviderOptions, codeExecution, createXai, mcpServer, viewImage, viewXVideo, webSearch, xSearch, xai, xaiTools };
343
+ export { VERSION, type XaiErrorData, type XaiImageModelOptions, type XaiImageModelOptions as XaiImageProviderOptions, type XaiLanguageModelChatOptions, type XaiLanguageModelResponsesOptions, type XaiProvider, type XaiLanguageModelChatOptions as XaiProviderOptions, type XaiProviderSettings, type XaiLanguageModelResponsesOptions as XaiResponsesProviderOptions, codeExecution, createXai, mcpServer, viewImage, viewXVideo, webSearch, xSearch, xai, xaiTools };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
5
5
 
6
6
  type XaiChatModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | 'grok-code-fast-1' | 'grok-4' | 'grok-4-0709' | 'grok-4-latest' | 'grok-3' | 'grok-3-latest' | 'grok-3-fast' | 'grok-3-fast-latest' | 'grok-3-mini' | 'grok-3-mini-latest' | 'grok-3-mini-fast' | 'grok-3-mini-fast-latest' | 'grok-2-vision-1212' | 'grok-2-vision' | 'grok-2-vision-latest' | 'grok-2-image-1212' | 'grok-2-image' | 'grok-2-image-latest' | 'grok-2-1212' | 'grok-2' | 'grok-2-latest' | 'grok-vision-beta' | 'grok-beta' | (string & {});
7
- declare const xaiProviderOptions: z.ZodObject<{
7
+ declare const xaiLanguageModelChatOptions: z.ZodObject<{
8
8
  reasoningEffort: z.ZodOptional<z.ZodEnum<{
9
9
  low: "low";
10
10
  high: "high";
@@ -44,7 +44,7 @@ declare const xaiProviderOptions: z.ZodObject<{
44
44
  }, z.core.$strip>]>>>;
45
45
  }, z.core.$strip>>;
46
46
  }, z.core.$strip>;
47
- type XaiProviderOptions = z.infer<typeof xaiProviderOptions>;
47
+ type XaiLanguageModelChatOptions = z.infer<typeof xaiLanguageModelChatOptions>;
48
48
 
49
49
  declare const xaiErrorDataSchema: z.ZodObject<{
50
50
  error: z.ZodObject<{
@@ -56,18 +56,11 @@ declare const xaiErrorDataSchema: z.ZodObject<{
56
56
  }, z.core.$strip>;
57
57
  type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
58
58
 
59
- declare const xaiImageProviderOptions: z.ZodObject<{
60
- aspect_ratio: z.ZodOptional<z.ZodString>;
61
- output_format: z.ZodOptional<z.ZodString>;
62
- sync_mode: z.ZodOptional<z.ZodBoolean>;
63
- }, z.core.$strip>;
64
- type XaiImageProviderOptions = z.infer<typeof xaiImageProviderOptions>;
65
-
66
59
  type XaiResponsesModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4' | 'grok-4-fast' | 'grok-4-fast-non-reasoning' | (string & {});
67
60
  /**
68
61
  * @see https://docs.x.ai/docs/api-reference#create-new-response
69
62
  */
70
- declare const xaiResponsesProviderOptions: z.ZodObject<{
63
+ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
71
64
  reasoningEffort: z.ZodOptional<z.ZodEnum<{
72
65
  low: "low";
73
66
  high: "high";
@@ -79,7 +72,14 @@ declare const xaiResponsesProviderOptions: z.ZodObject<{
79
72
  "file_search_call.results": "file_search_call.results";
80
73
  }>>>>;
81
74
  }, z.core.$strip>;
82
- type XaiResponsesProviderOptions = z.infer<typeof xaiResponsesProviderOptions>;
75
+ type XaiLanguageModelResponsesOptions = z.infer<typeof xaiLanguageModelResponsesOptions>;
76
+
77
+ declare const xaiImageModelOptions: z.ZodObject<{
78
+ aspect_ratio: z.ZodOptional<z.ZodString>;
79
+ output_format: z.ZodOptional<z.ZodString>;
80
+ sync_mode: z.ZodOptional<z.ZodBoolean>;
81
+ }, z.core.$strip>;
82
+ type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
83
83
 
84
84
  type XaiImageModelId = 'grok-2-image' | 'grok-imagine-image' | (string & {});
85
85
 
@@ -340,4 +340,4 @@ declare const xai: XaiProvider;
340
340
 
341
341
  declare const VERSION: string;
342
342
 
343
- export { VERSION, type XaiErrorData, type XaiImageProviderOptions, type XaiProvider, type XaiProviderOptions, type XaiProviderSettings, type XaiResponsesProviderOptions, codeExecution, createXai, mcpServer, viewImage, viewXVideo, webSearch, xSearch, xai, xaiTools };
343
+ export { VERSION, type XaiErrorData, type XaiImageModelOptions, type XaiImageModelOptions as XaiImageProviderOptions, type XaiLanguageModelChatOptions, type XaiLanguageModelResponsesOptions, type XaiProvider, type XaiLanguageModelChatOptions as XaiProviderOptions, type XaiProviderSettings, type XaiLanguageModelResponsesOptions as XaiResponsesProviderOptions, codeExecution, createXai, mcpServer, viewImage, viewXVideo, webSearch, xSearch, xai, xaiTools };
package/dist/index.js CHANGED
@@ -244,7 +244,7 @@ var searchSourceSchema = import_v4.z.discriminatedUnion("type", [
244
244
  newsSourceSchema,
245
245
  rssSourceSchema
246
246
  ]);
247
- var xaiProviderOptions = import_v4.z.object({
247
+ var xaiLanguageModelChatOptions = import_v4.z.object({
248
248
  reasoningEffort: import_v4.z.enum(["low", "high"]).optional(),
249
249
  /**
250
250
  * Whether to enable parallel function calling during tool use.
@@ -396,7 +396,7 @@ var XaiChatLanguageModel = class {
396
396
  const options = (_a = await (0, import_provider_utils3.parseProviderOptions)({
397
397
  provider: "xai",
398
398
  providerOptions,
399
- schema: xaiProviderOptions
399
+ schema: xaiLanguageModelChatOptions
400
400
  })) != null ? _a : {};
401
401
  if (topK != null) {
402
402
  warnings.push({ type: "unsupported", feature: "topK" });
@@ -883,7 +883,7 @@ var import_v45 = require("zod/v4");
883
883
 
884
884
  // src/xai-image-options.ts
885
885
  var import_v44 = require("zod/v4");
886
- var xaiImageProviderOptions = import_v44.z.object({
886
+ var xaiImageModelOptions = import_v44.z.object({
887
887
  aspect_ratio: import_v44.z.string().optional(),
888
888
  output_format: import_v44.z.string().optional(),
889
889
  sync_mode: import_v44.z.boolean().optional()
@@ -936,7 +936,7 @@ var XaiImageModel = class {
936
936
  const xaiOptions = await (0, import_provider_utils4.parseProviderOptions)({
937
937
  provider: "xai",
938
938
  providerOptions,
939
- schema: xaiImageProviderOptions
939
+ schema: xaiImageModelOptions
940
940
  });
941
941
  const hasFiles = files != null && files.length > 0;
942
942
  let imageUrl;
@@ -1556,6 +1556,19 @@ var xaiResponsesChunkSchema = import_v46.z.union([
1556
1556
  output_index: import_v46.z.number(),
1557
1557
  input: import_v46.z.string()
1558
1558
  }),
1559
+ // Function call arguments streaming events (standard function tools)
1560
+ import_v46.z.object({
1561
+ type: import_v46.z.literal("response.function_call_arguments.delta"),
1562
+ item_id: import_v46.z.string(),
1563
+ output_index: import_v46.z.number(),
1564
+ delta: import_v46.z.string()
1565
+ }),
1566
+ import_v46.z.object({
1567
+ type: import_v46.z.literal("response.function_call_arguments.done"),
1568
+ item_id: import_v46.z.string(),
1569
+ output_index: import_v46.z.number(),
1570
+ arguments: import_v46.z.string()
1571
+ }),
1559
1572
  import_v46.z.object({
1560
1573
  type: import_v46.z.literal("response.mcp_call.in_progress"),
1561
1574
  item_id: import_v46.z.string(),
@@ -1612,7 +1625,7 @@ var xaiResponsesChunkSchema = import_v46.z.union([
1612
1625
 
1613
1626
  // src/responses/xai-responses-options.ts
1614
1627
  var import_v47 = require("zod/v4");
1615
- var xaiResponsesProviderOptions = import_v47.z.object({
1628
+ var xaiLanguageModelResponsesOptions = import_v47.z.object({
1616
1629
  /**
1617
1630
  * Constrains how hard a reasoning model thinks before responding.
1618
1631
  * Possible values are `low` (uses fewer reasoning tokens), `medium` and `high` (uses more reasoning tokens).
@@ -1951,7 +1964,7 @@ var XaiResponsesLanguageModel = class {
1951
1964
  const options = (_a = await (0, import_provider_utils11.parseProviderOptions)({
1952
1965
  provider: "xai",
1953
1966
  providerOptions,
1954
- schema: xaiResponsesProviderOptions
1967
+ schema: xaiLanguageModelResponsesOptions
1955
1968
  })) != null ? _a : {};
1956
1969
  if (stopSequences != null) {
1957
1970
  warnings.push({ type: "unsupported", feature: "stopSequences" });
@@ -2243,6 +2256,7 @@ var XaiResponsesLanguageModel = class {
2243
2256
  let isFirstChunk = true;
2244
2257
  const contentBlocks = {};
2245
2258
  const seenToolCalls = /* @__PURE__ */ new Set();
2259
+ const ongoingToolCalls = {};
2246
2260
  const activeReasoning = {};
2247
2261
  const self = this;
2248
2262
  return {
@@ -2391,6 +2405,20 @@ var XaiResponsesLanguageModel = class {
2391
2405
  if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
2392
2406
  return;
2393
2407
  }
2408
+ if (event.type === "response.function_call_arguments.delta") {
2409
+ const toolCall = ongoingToolCalls[event.output_index];
2410
+ if (toolCall != null) {
2411
+ controller.enqueue({
2412
+ type: "tool-input-delta",
2413
+ id: toolCall.toolCallId,
2414
+ delta: event.delta
2415
+ });
2416
+ }
2417
+ return;
2418
+ }
2419
+ if (event.type === "response.function_call_arguments.done") {
2420
+ return;
2421
+ }
2394
2422
  if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
2395
2423
  const part = event.item;
2396
2424
  if (part.type === "reasoning") {
@@ -2550,18 +2578,18 @@ var XaiResponsesLanguageModel = class {
2550
2578
  }
2551
2579
  }
2552
2580
  } else if (part.type === "function_call") {
2553
- if (!seenToolCalls.has(part.call_id)) {
2554
- seenToolCalls.add(part.call_id);
2581
+ if (event.type === "response.output_item.added") {
2582
+ ongoingToolCalls[event.output_index] = {
2583
+ toolName: part.name,
2584
+ toolCallId: part.call_id
2585
+ };
2555
2586
  controller.enqueue({
2556
2587
  type: "tool-input-start",
2557
2588
  id: part.call_id,
2558
2589
  toolName: part.name
2559
2590
  });
2560
- controller.enqueue({
2561
- type: "tool-input-delta",
2562
- id: part.call_id,
2563
- delta: part.arguments
2564
- });
2591
+ } else if (event.type === "response.output_item.done") {
2592
+ ongoingToolCalls[event.output_index] = void 0;
2565
2593
  controller.enqueue({
2566
2594
  type: "tool-input-end",
2567
2595
  id: part.call_id
@@ -2662,7 +2690,7 @@ var xaiTools = {
2662
2690
  };
2663
2691
 
2664
2692
  // src/version.ts
2665
- var VERSION = true ? "3.0.52" : "0.0.0-test";
2693
+ var VERSION = true ? "3.0.54" : "0.0.0-test";
2666
2694
 
2667
2695
  // src/xai-provider.ts
2668
2696
  function createXai(options = {}) {