@ai-sdk/xai 2.0.36 → 2.0.38
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 +12 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +89 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 2.0.38
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c6eb78c: add grok-4-1 model IDs
|
|
8
|
+
|
|
9
|
+
## 2.0.37
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 864881c: Fix Responses API validation errors for server-side tools (web_search, x_search, code_execution). Add missing custom_tool_call type and streaming event schemas.
|
|
14
|
+
|
|
3
15
|
## 2.0.36
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { ProviderV2, LanguageModelV2, ImageModelV2 } from '@ai-sdk/provider';
|
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
5
5
|
|
|
6
|
-
type XaiChatModelId = '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 & {});
|
|
6
|
+
type XaiChatModelId = 'grok-4-1' | '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
7
|
declare const xaiProviderOptions: z.ZodObject<{
|
|
8
8
|
reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
|
9
9
|
low: "low";
|
|
@@ -56,7 +56,7 @@ declare const xaiErrorDataSchema: z.ZodObject<{
|
|
|
56
56
|
}, z.core.$strip>;
|
|
57
57
|
type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
|
|
58
58
|
|
|
59
|
-
type XaiResponsesModelId = 'grok-4' | 'grok-4-fast' | 'grok-4-fast-non-reasoning' | (string & {});
|
|
59
|
+
type XaiResponsesModelId = 'grok-4-1' | 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4' | 'grok-4-fast' | 'grok-4-fast-non-reasoning' | (string & {});
|
|
60
60
|
/**
|
|
61
61
|
* @see https://docs.x.ai/docs/api-reference#create-new-response
|
|
62
62
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ProviderV2, LanguageModelV2, ImageModelV2 } from '@ai-sdk/provider';
|
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
5
5
|
|
|
6
|
-
type XaiChatModelId = '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 & {});
|
|
6
|
+
type XaiChatModelId = 'grok-4-1' | '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
7
|
declare const xaiProviderOptions: z.ZodObject<{
|
|
8
8
|
reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
|
9
9
|
low: "low";
|
|
@@ -56,7 +56,7 @@ declare const xaiErrorDataSchema: z.ZodObject<{
|
|
|
56
56
|
}, z.core.$strip>;
|
|
57
57
|
type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
|
|
58
58
|
|
|
59
|
-
type XaiResponsesModelId = 'grok-4' | 'grok-4-fast' | 'grok-4-fast-non-reasoning' | (string & {});
|
|
59
|
+
type XaiResponsesModelId = 'grok-4-1' | 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4' | 'grok-4-fast' | 'grok-4-fast-non-reasoning' | (string & {});
|
|
60
60
|
/**
|
|
61
61
|
* @see https://docs.x.ai/docs/api-reference#create-new-response
|
|
62
62
|
*/
|
package/dist/index.js
CHANGED
|
@@ -800,11 +800,13 @@ var reasoningSummaryPartSchema = import_v44.z.object({
|
|
|
800
800
|
text: import_v44.z.string()
|
|
801
801
|
});
|
|
802
802
|
var toolCallSchema = import_v44.z.object({
|
|
803
|
-
name: import_v44.z.string(),
|
|
804
|
-
arguments: import_v44.z.string(),
|
|
805
|
-
|
|
803
|
+
name: import_v44.z.string().optional(),
|
|
804
|
+
arguments: import_v44.z.string().optional(),
|
|
805
|
+
input: import_v44.z.string().optional(),
|
|
806
|
+
call_id: import_v44.z.string().optional(),
|
|
806
807
|
id: import_v44.z.string(),
|
|
807
|
-
status: import_v44.z.string()
|
|
808
|
+
status: import_v44.z.string(),
|
|
809
|
+
action: import_v44.z.any().optional()
|
|
808
810
|
});
|
|
809
811
|
var outputItemSchema = import_v44.z.discriminatedUnion("type", [
|
|
810
812
|
import_v44.z.object({
|
|
@@ -831,6 +833,10 @@ var outputItemSchema = import_v44.z.discriminatedUnion("type", [
|
|
|
831
833
|
type: import_v44.z.literal("view_x_video_call"),
|
|
832
834
|
...toolCallSchema.shape
|
|
833
835
|
}),
|
|
836
|
+
import_v44.z.object({
|
|
837
|
+
type: import_v44.z.literal("custom_tool_call"),
|
|
838
|
+
...toolCallSchema.shape
|
|
839
|
+
}),
|
|
834
840
|
import_v44.z.object({
|
|
835
841
|
type: import_v44.z.literal("message"),
|
|
836
842
|
role: import_v44.z.string(),
|
|
@@ -960,6 +966,66 @@ var xaiResponsesChunkSchema = import_v44.z.union([
|
|
|
960
966
|
summary_index: import_v44.z.number(),
|
|
961
967
|
text: import_v44.z.string()
|
|
962
968
|
}),
|
|
969
|
+
import_v44.z.object({
|
|
970
|
+
type: import_v44.z.literal("response.web_search_call.in_progress"),
|
|
971
|
+
item_id: import_v44.z.string(),
|
|
972
|
+
output_index: import_v44.z.number()
|
|
973
|
+
}),
|
|
974
|
+
import_v44.z.object({
|
|
975
|
+
type: import_v44.z.literal("response.web_search_call.searching"),
|
|
976
|
+
item_id: import_v44.z.string(),
|
|
977
|
+
output_index: import_v44.z.number()
|
|
978
|
+
}),
|
|
979
|
+
import_v44.z.object({
|
|
980
|
+
type: import_v44.z.literal("response.web_search_call.completed"),
|
|
981
|
+
item_id: import_v44.z.string(),
|
|
982
|
+
output_index: import_v44.z.number()
|
|
983
|
+
}),
|
|
984
|
+
import_v44.z.object({
|
|
985
|
+
type: import_v44.z.literal("response.x_search_call.in_progress"),
|
|
986
|
+
item_id: import_v44.z.string(),
|
|
987
|
+
output_index: import_v44.z.number()
|
|
988
|
+
}),
|
|
989
|
+
import_v44.z.object({
|
|
990
|
+
type: import_v44.z.literal("response.x_search_call.searching"),
|
|
991
|
+
item_id: import_v44.z.string(),
|
|
992
|
+
output_index: import_v44.z.number()
|
|
993
|
+
}),
|
|
994
|
+
import_v44.z.object({
|
|
995
|
+
type: import_v44.z.literal("response.x_search_call.completed"),
|
|
996
|
+
item_id: import_v44.z.string(),
|
|
997
|
+
output_index: import_v44.z.number()
|
|
998
|
+
}),
|
|
999
|
+
import_v44.z.object({
|
|
1000
|
+
type: import_v44.z.literal("response.code_execution_call.in_progress"),
|
|
1001
|
+
item_id: import_v44.z.string(),
|
|
1002
|
+
output_index: import_v44.z.number()
|
|
1003
|
+
}),
|
|
1004
|
+
import_v44.z.object({
|
|
1005
|
+
type: import_v44.z.literal("response.code_execution_call.executing"),
|
|
1006
|
+
item_id: import_v44.z.string(),
|
|
1007
|
+
output_index: import_v44.z.number()
|
|
1008
|
+
}),
|
|
1009
|
+
import_v44.z.object({
|
|
1010
|
+
type: import_v44.z.literal("response.code_execution_call.completed"),
|
|
1011
|
+
item_id: import_v44.z.string(),
|
|
1012
|
+
output_index: import_v44.z.number()
|
|
1013
|
+
}),
|
|
1014
|
+
import_v44.z.object({
|
|
1015
|
+
type: import_v44.z.literal("response.code_interpreter_call.in_progress"),
|
|
1016
|
+
item_id: import_v44.z.string(),
|
|
1017
|
+
output_index: import_v44.z.number()
|
|
1018
|
+
}),
|
|
1019
|
+
import_v44.z.object({
|
|
1020
|
+
type: import_v44.z.literal("response.code_interpreter_call.executing"),
|
|
1021
|
+
item_id: import_v44.z.string(),
|
|
1022
|
+
output_index: import_v44.z.number()
|
|
1023
|
+
}),
|
|
1024
|
+
import_v44.z.object({
|
|
1025
|
+
type: import_v44.z.literal("response.code_interpreter_call.completed"),
|
|
1026
|
+
item_id: import_v44.z.string(),
|
|
1027
|
+
output_index: import_v44.z.number()
|
|
1028
|
+
}),
|
|
963
1029
|
import_v44.z.object({
|
|
964
1030
|
type: import_v44.z.literal("response.done"),
|
|
965
1031
|
response: xaiResponsesResponseSchema
|
|
@@ -1491,7 +1557,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1491
1557
|
};
|
|
1492
1558
|
}
|
|
1493
1559
|
async doGenerate(options) {
|
|
1494
|
-
var _a, _b, _c;
|
|
1560
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1495
1561
|
const {
|
|
1496
1562
|
args: body,
|
|
1497
1563
|
warnings,
|
|
@@ -1527,20 +1593,21 @@ var XaiResponsesLanguageModel = class {
|
|
|
1527
1593
|
"x_thread_fetch"
|
|
1528
1594
|
];
|
|
1529
1595
|
for (const part of response.output) {
|
|
1530
|
-
if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call") {
|
|
1531
|
-
let toolName = part.name;
|
|
1532
|
-
if (webSearchSubTools.includes(part.name)) {
|
|
1596
|
+
if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call" || part.type === "custom_tool_call") {
|
|
1597
|
+
let toolName = (_b = part.name) != null ? _b : "";
|
|
1598
|
+
if (webSearchSubTools.includes((_c = part.name) != null ? _c : "")) {
|
|
1533
1599
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
1534
|
-
} else if (xSearchSubTools.includes(part.name)) {
|
|
1600
|
+
} else if (xSearchSubTools.includes((_d = part.name) != null ? _d : "")) {
|
|
1535
1601
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
1536
1602
|
} else if (part.name === "code_execution") {
|
|
1537
1603
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
1538
1604
|
}
|
|
1605
|
+
const toolInput = part.type === "custom_tool_call" ? (_e = part.input) != null ? _e : "" : (_f = part.arguments) != null ? _f : "";
|
|
1539
1606
|
content.push({
|
|
1540
1607
|
type: "tool-call",
|
|
1541
1608
|
toolCallId: part.id,
|
|
1542
1609
|
toolName,
|
|
1543
|
-
input:
|
|
1610
|
+
input: toolInput,
|
|
1544
1611
|
providerExecuted: true
|
|
1545
1612
|
});
|
|
1546
1613
|
continue;
|
|
@@ -1562,7 +1629,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1562
1629
|
sourceType: "url",
|
|
1563
1630
|
id: this.config.generateId(),
|
|
1564
1631
|
url: annotation.url,
|
|
1565
|
-
title: (
|
|
1632
|
+
title: (_g = annotation.title) != null ? _g : annotation.url
|
|
1566
1633
|
});
|
|
1567
1634
|
}
|
|
1568
1635
|
}
|
|
@@ -1591,7 +1658,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1591
1658
|
inputTokens: response.usage.input_tokens,
|
|
1592
1659
|
outputTokens: response.usage.output_tokens,
|
|
1593
1660
|
totalTokens: response.usage.total_tokens,
|
|
1594
|
-
reasoningTokens: (
|
|
1661
|
+
reasoningTokens: (_h = response.usage.output_tokens_details) == null ? void 0 : _h.reasoning_tokens
|
|
1595
1662
|
},
|
|
1596
1663
|
request: { body },
|
|
1597
1664
|
response: {
|
|
@@ -1643,7 +1710,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1643
1710
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1644
1711
|
},
|
|
1645
1712
|
transform(chunk, controller) {
|
|
1646
|
-
var _a2, _b, _c, _d;
|
|
1713
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1647
1714
|
if (options.includeRawChunks) {
|
|
1648
1715
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1649
1716
|
}
|
|
@@ -1745,7 +1812,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1745
1812
|
}
|
|
1746
1813
|
if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
|
|
1747
1814
|
const part = event.item;
|
|
1748
|
-
if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call") {
|
|
1815
|
+
if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call" || part.type === "custom_tool_call") {
|
|
1749
1816
|
if (!seenToolCalls.has(part.id)) {
|
|
1750
1817
|
seenToolCalls.add(part.id);
|
|
1751
1818
|
const webSearchSubTools = [
|
|
@@ -1759,14 +1826,15 @@ var XaiResponsesLanguageModel = class {
|
|
|
1759
1826
|
"x_semantic_search",
|
|
1760
1827
|
"x_thread_fetch"
|
|
1761
1828
|
];
|
|
1762
|
-
let toolName = part.name;
|
|
1763
|
-
if (webSearchSubTools.includes(part.name)) {
|
|
1829
|
+
let toolName = (_d = part.name) != null ? _d : "";
|
|
1830
|
+
if (webSearchSubTools.includes((_e = part.name) != null ? _e : "")) {
|
|
1764
1831
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
1765
|
-
} else if (xSearchSubTools.includes(part.name)) {
|
|
1832
|
+
} else if (xSearchSubTools.includes((_f = part.name) != null ? _f : "")) {
|
|
1766
1833
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
1767
1834
|
} else if (part.name === "code_execution") {
|
|
1768
1835
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
1769
1836
|
}
|
|
1837
|
+
const toolInput = part.type === "custom_tool_call" ? (_g = part.input) != null ? _g : "" : (_h = part.arguments) != null ? _h : "";
|
|
1770
1838
|
controller.enqueue({
|
|
1771
1839
|
type: "tool-input-start",
|
|
1772
1840
|
id: part.id,
|
|
@@ -1775,7 +1843,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1775
1843
|
controller.enqueue({
|
|
1776
1844
|
type: "tool-input-delta",
|
|
1777
1845
|
id: part.id,
|
|
1778
|
-
delta:
|
|
1846
|
+
delta: toolInput
|
|
1779
1847
|
});
|
|
1780
1848
|
controller.enqueue({
|
|
1781
1849
|
type: "tool-input-end",
|
|
@@ -1785,7 +1853,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1785
1853
|
type: "tool-call",
|
|
1786
1854
|
toolCallId: part.id,
|
|
1787
1855
|
toolName,
|
|
1788
|
-
input:
|
|
1856
|
+
input: toolInput,
|
|
1789
1857
|
providerExecuted: true
|
|
1790
1858
|
});
|
|
1791
1859
|
}
|
|
@@ -1816,7 +1884,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1816
1884
|
sourceType: "url",
|
|
1817
1885
|
id: self.config.generateId(),
|
|
1818
1886
|
url: annotation.url,
|
|
1819
|
-
title: (
|
|
1887
|
+
title: (_i = annotation.title) != null ? _i : annotation.url
|
|
1820
1888
|
});
|
|
1821
1889
|
}
|
|
1822
1890
|
}
|
|
@@ -1924,7 +1992,7 @@ var xaiTools = {
|
|
|
1924
1992
|
};
|
|
1925
1993
|
|
|
1926
1994
|
// src/version.ts
|
|
1927
|
-
var VERSION = true ? "2.0.
|
|
1995
|
+
var VERSION = true ? "2.0.38" : "0.0.0-test";
|
|
1928
1996
|
|
|
1929
1997
|
// src/xai-provider.ts
|
|
1930
1998
|
var xaiErrorStructure = {
|