@ai-sdk/xai 3.0.0-beta.40 → 3.0.0-beta.42
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 +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +178 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +178 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -137,12 +137,14 @@ function convertToXaiChatMessages(prompt) {
|
|
|
137
137
|
function getResponseMetadata({
|
|
138
138
|
id,
|
|
139
139
|
model,
|
|
140
|
-
created
|
|
140
|
+
created,
|
|
141
|
+
created_at
|
|
141
142
|
}) {
|
|
143
|
+
const unixTime = created != null ? created : created_at;
|
|
142
144
|
return {
|
|
143
145
|
id: id != null ? id : void 0,
|
|
144
146
|
modelId: model != null ? model : void 0,
|
|
145
|
-
timestamp:
|
|
147
|
+
timestamp: unixTime != null ? new Date(unixTime * 1e3) : void 0
|
|
146
148
|
};
|
|
147
149
|
}
|
|
148
150
|
|
|
@@ -788,12 +790,18 @@ var messageContentPartSchema = z4.object({
|
|
|
788
790
|
logprobs: z4.array(z4.any()).optional(),
|
|
789
791
|
annotations: z4.array(annotationSchema).optional()
|
|
790
792
|
});
|
|
793
|
+
var reasoningSummaryPartSchema = z4.object({
|
|
794
|
+
type: z4.string(),
|
|
795
|
+
text: z4.string()
|
|
796
|
+
});
|
|
791
797
|
var toolCallSchema = z4.object({
|
|
792
|
-
name: z4.string(),
|
|
793
|
-
arguments: z4.string(),
|
|
794
|
-
|
|
798
|
+
name: z4.string().optional(),
|
|
799
|
+
arguments: z4.string().optional(),
|
|
800
|
+
input: z4.string().optional(),
|
|
801
|
+
call_id: z4.string().optional(),
|
|
795
802
|
id: z4.string(),
|
|
796
|
-
status: z4.string()
|
|
803
|
+
status: z4.string(),
|
|
804
|
+
action: z4.any().optional()
|
|
797
805
|
});
|
|
798
806
|
var outputItemSchema = z4.discriminatedUnion("type", [
|
|
799
807
|
z4.object({
|
|
@@ -820,6 +828,10 @@ var outputItemSchema = z4.discriminatedUnion("type", [
|
|
|
820
828
|
type: z4.literal("view_x_video_call"),
|
|
821
829
|
...toolCallSchema.shape
|
|
822
830
|
}),
|
|
831
|
+
z4.object({
|
|
832
|
+
type: z4.literal("custom_tool_call"),
|
|
833
|
+
...toolCallSchema.shape
|
|
834
|
+
}),
|
|
823
835
|
z4.object({
|
|
824
836
|
type: z4.literal("message"),
|
|
825
837
|
role: z4.string(),
|
|
@@ -833,6 +845,12 @@ var outputItemSchema = z4.discriminatedUnion("type", [
|
|
|
833
845
|
arguments: z4.string(),
|
|
834
846
|
call_id: z4.string(),
|
|
835
847
|
id: z4.string()
|
|
848
|
+
}),
|
|
849
|
+
z4.object({
|
|
850
|
+
type: z4.literal("reasoning"),
|
|
851
|
+
id: z4.string(),
|
|
852
|
+
summary: z4.array(reasoningSummaryPartSchema),
|
|
853
|
+
status: z4.string()
|
|
836
854
|
})
|
|
837
855
|
]);
|
|
838
856
|
var xaiResponsesUsageSchema = z4.object({
|
|
@@ -915,6 +933,94 @@ var xaiResponsesChunkSchema = z4.union([
|
|
|
915
933
|
annotation_index: z4.number(),
|
|
916
934
|
annotation: annotationSchema
|
|
917
935
|
}),
|
|
936
|
+
z4.object({
|
|
937
|
+
type: z4.literal("response.reasoning_summary_part.added"),
|
|
938
|
+
item_id: z4.string(),
|
|
939
|
+
output_index: z4.number(),
|
|
940
|
+
summary_index: z4.number(),
|
|
941
|
+
part: reasoningSummaryPartSchema
|
|
942
|
+
}),
|
|
943
|
+
z4.object({
|
|
944
|
+
type: z4.literal("response.reasoning_summary_part.done"),
|
|
945
|
+
item_id: z4.string(),
|
|
946
|
+
output_index: z4.number(),
|
|
947
|
+
summary_index: z4.number(),
|
|
948
|
+
part: reasoningSummaryPartSchema
|
|
949
|
+
}),
|
|
950
|
+
z4.object({
|
|
951
|
+
type: z4.literal("response.reasoning_summary_text.delta"),
|
|
952
|
+
item_id: z4.string(),
|
|
953
|
+
output_index: z4.number(),
|
|
954
|
+
summary_index: z4.number(),
|
|
955
|
+
delta: z4.string()
|
|
956
|
+
}),
|
|
957
|
+
z4.object({
|
|
958
|
+
type: z4.literal("response.reasoning_summary_text.done"),
|
|
959
|
+
item_id: z4.string(),
|
|
960
|
+
output_index: z4.number(),
|
|
961
|
+
summary_index: z4.number(),
|
|
962
|
+
text: z4.string()
|
|
963
|
+
}),
|
|
964
|
+
z4.object({
|
|
965
|
+
type: z4.literal("response.web_search_call.in_progress"),
|
|
966
|
+
item_id: z4.string(),
|
|
967
|
+
output_index: z4.number()
|
|
968
|
+
}),
|
|
969
|
+
z4.object({
|
|
970
|
+
type: z4.literal("response.web_search_call.searching"),
|
|
971
|
+
item_id: z4.string(),
|
|
972
|
+
output_index: z4.number()
|
|
973
|
+
}),
|
|
974
|
+
z4.object({
|
|
975
|
+
type: z4.literal("response.web_search_call.completed"),
|
|
976
|
+
item_id: z4.string(),
|
|
977
|
+
output_index: z4.number()
|
|
978
|
+
}),
|
|
979
|
+
z4.object({
|
|
980
|
+
type: z4.literal("response.x_search_call.in_progress"),
|
|
981
|
+
item_id: z4.string(),
|
|
982
|
+
output_index: z4.number()
|
|
983
|
+
}),
|
|
984
|
+
z4.object({
|
|
985
|
+
type: z4.literal("response.x_search_call.searching"),
|
|
986
|
+
item_id: z4.string(),
|
|
987
|
+
output_index: z4.number()
|
|
988
|
+
}),
|
|
989
|
+
z4.object({
|
|
990
|
+
type: z4.literal("response.x_search_call.completed"),
|
|
991
|
+
item_id: z4.string(),
|
|
992
|
+
output_index: z4.number()
|
|
993
|
+
}),
|
|
994
|
+
z4.object({
|
|
995
|
+
type: z4.literal("response.code_execution_call.in_progress"),
|
|
996
|
+
item_id: z4.string(),
|
|
997
|
+
output_index: z4.number()
|
|
998
|
+
}),
|
|
999
|
+
z4.object({
|
|
1000
|
+
type: z4.literal("response.code_execution_call.executing"),
|
|
1001
|
+
item_id: z4.string(),
|
|
1002
|
+
output_index: z4.number()
|
|
1003
|
+
}),
|
|
1004
|
+
z4.object({
|
|
1005
|
+
type: z4.literal("response.code_execution_call.completed"),
|
|
1006
|
+
item_id: z4.string(),
|
|
1007
|
+
output_index: z4.number()
|
|
1008
|
+
}),
|
|
1009
|
+
z4.object({
|
|
1010
|
+
type: z4.literal("response.code_interpreter_call.in_progress"),
|
|
1011
|
+
item_id: z4.string(),
|
|
1012
|
+
output_index: z4.number()
|
|
1013
|
+
}),
|
|
1014
|
+
z4.object({
|
|
1015
|
+
type: z4.literal("response.code_interpreter_call.executing"),
|
|
1016
|
+
item_id: z4.string(),
|
|
1017
|
+
output_index: z4.number()
|
|
1018
|
+
}),
|
|
1019
|
+
z4.object({
|
|
1020
|
+
type: z4.literal("response.code_interpreter_call.completed"),
|
|
1021
|
+
item_id: z4.string(),
|
|
1022
|
+
output_index: z4.number()
|
|
1023
|
+
}),
|
|
918
1024
|
z4.object({
|
|
919
1025
|
type: z4.literal("response.done"),
|
|
920
1026
|
response: xaiResponsesResponseSchema
|
|
@@ -946,7 +1052,20 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
946
1052
|
// src/responses/xai-responses-options.ts
|
|
947
1053
|
import { z as z5 } from "zod/v4";
|
|
948
1054
|
var xaiResponsesProviderOptions = z5.object({
|
|
949
|
-
|
|
1055
|
+
/**
|
|
1056
|
+
* Constrains how hard a reasoning model thinks before responding.
|
|
1057
|
+
* Possible values are `low` (uses fewer reasoning tokens), `medium` and `high` (uses more reasoning tokens).
|
|
1058
|
+
*/
|
|
1059
|
+
reasoningEffort: z5.enum(["low", "medium", "high"]).optional(),
|
|
1060
|
+
/**
|
|
1061
|
+
* Whether to store the input message(s) and model response for later retrieval.
|
|
1062
|
+
* @default true
|
|
1063
|
+
*/
|
|
1064
|
+
store: z5.boolean().optional(),
|
|
1065
|
+
/**
|
|
1066
|
+
* The ID of the previous response from the model.
|
|
1067
|
+
*/
|
|
1068
|
+
previousResponseId: z5.string().optional()
|
|
950
1069
|
});
|
|
951
1070
|
|
|
952
1071
|
// src/responses/convert-to-xai-responses-input.ts
|
|
@@ -1420,7 +1539,16 @@ var XaiResponsesLanguageModel = class {
|
|
|
1420
1539
|
temperature,
|
|
1421
1540
|
top_p: topP,
|
|
1422
1541
|
seed,
|
|
1423
|
-
|
|
1542
|
+
...options.reasoningEffort != null && {
|
|
1543
|
+
reasoning: { effort: options.reasoningEffort }
|
|
1544
|
+
},
|
|
1545
|
+
...options.store === false && {
|
|
1546
|
+
store: options.store,
|
|
1547
|
+
include: ["reasoning.encrypted_content"]
|
|
1548
|
+
},
|
|
1549
|
+
...options.previousResponseId != null && {
|
|
1550
|
+
previous_response_id: options.previousResponseId
|
|
1551
|
+
}
|
|
1424
1552
|
};
|
|
1425
1553
|
if (xaiTools2 && xaiTools2.length > 0) {
|
|
1426
1554
|
baseArgs.tools = xaiTools2;
|
|
@@ -1437,7 +1565,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1437
1565
|
};
|
|
1438
1566
|
}
|
|
1439
1567
|
async doGenerate(options) {
|
|
1440
|
-
var _a, _b, _c;
|
|
1568
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1441
1569
|
const {
|
|
1442
1570
|
args: body,
|
|
1443
1571
|
warnings,
|
|
@@ -1473,20 +1601,21 @@ var XaiResponsesLanguageModel = class {
|
|
|
1473
1601
|
"x_thread_fetch"
|
|
1474
1602
|
];
|
|
1475
1603
|
for (const part of response.output) {
|
|
1476
|
-
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") {
|
|
1477
|
-
let toolName = part.name;
|
|
1478
|
-
if (webSearchSubTools.includes(part.name)) {
|
|
1604
|
+
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") {
|
|
1605
|
+
let toolName = (_b = part.name) != null ? _b : "";
|
|
1606
|
+
if (webSearchSubTools.includes((_c = part.name) != null ? _c : "")) {
|
|
1479
1607
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
1480
|
-
} else if (xSearchSubTools.includes(part.name)) {
|
|
1608
|
+
} else if (xSearchSubTools.includes((_d = part.name) != null ? _d : "")) {
|
|
1481
1609
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
1482
1610
|
} else if (part.name === "code_execution") {
|
|
1483
1611
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
1484
1612
|
}
|
|
1613
|
+
const toolInput = part.type === "custom_tool_call" ? (_e = part.input) != null ? _e : "" : (_f = part.arguments) != null ? _f : "";
|
|
1485
1614
|
content.push({
|
|
1486
1615
|
type: "tool-call",
|
|
1487
1616
|
toolCallId: part.id,
|
|
1488
1617
|
toolName,
|
|
1489
|
-
input:
|
|
1618
|
+
input: toolInput,
|
|
1490
1619
|
providerExecuted: true
|
|
1491
1620
|
});
|
|
1492
1621
|
continue;
|
|
@@ -1508,7 +1637,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1508
1637
|
sourceType: "url",
|
|
1509
1638
|
id: this.config.generateId(),
|
|
1510
1639
|
url: annotation.url,
|
|
1511
|
-
title: (
|
|
1640
|
+
title: (_g = annotation.title) != null ? _g : annotation.url
|
|
1512
1641
|
});
|
|
1513
1642
|
}
|
|
1514
1643
|
}
|
|
@@ -1537,7 +1666,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1537
1666
|
inputTokens: response.usage.input_tokens,
|
|
1538
1667
|
outputTokens: response.usage.output_tokens,
|
|
1539
1668
|
totalTokens: response.usage.total_tokens,
|
|
1540
|
-
reasoningTokens: (
|
|
1669
|
+
reasoningTokens: (_h = response.usage.output_tokens_details) == null ? void 0 : _h.reasoning_tokens
|
|
1541
1670
|
},
|
|
1542
1671
|
request: { body },
|
|
1543
1672
|
response: {
|
|
@@ -1589,7 +1718,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1589
1718
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1590
1719
|
},
|
|
1591
1720
|
transform(chunk, controller) {
|
|
1592
|
-
var _a2, _b, _c, _d;
|
|
1721
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1593
1722
|
if (options.includeRawChunks) {
|
|
1594
1723
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1595
1724
|
}
|
|
@@ -1608,6 +1737,29 @@ var XaiResponsesLanguageModel = class {
|
|
|
1608
1737
|
}
|
|
1609
1738
|
return;
|
|
1610
1739
|
}
|
|
1740
|
+
if (event.type === "response.reasoning_summary_part.added") {
|
|
1741
|
+
const blockId = `reasoning-${event.item_id}`;
|
|
1742
|
+
controller.enqueue({
|
|
1743
|
+
type: "reasoning-start",
|
|
1744
|
+
id: blockId
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
if (event.type === "response.reasoning_summary_text.delta") {
|
|
1748
|
+
const blockId = `reasoning-${event.item_id}`;
|
|
1749
|
+
controller.enqueue({
|
|
1750
|
+
type: "reasoning-delta",
|
|
1751
|
+
id: blockId,
|
|
1752
|
+
delta: event.delta
|
|
1753
|
+
});
|
|
1754
|
+
return;
|
|
1755
|
+
}
|
|
1756
|
+
if (event.type === "response.reasoning_summary_text.done") {
|
|
1757
|
+
const blockId = `reasoning-${event.item_id}`;
|
|
1758
|
+
controller.enqueue({
|
|
1759
|
+
type: "reasoning-end",
|
|
1760
|
+
id: blockId
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1611
1763
|
if (event.type === "response.output_text.delta") {
|
|
1612
1764
|
const blockId = `text-${event.item_id}`;
|
|
1613
1765
|
if (contentBlocks[blockId] == null) {
|
|
@@ -1668,7 +1820,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1668
1820
|
}
|
|
1669
1821
|
if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
|
|
1670
1822
|
const part = event.item;
|
|
1671
|
-
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") {
|
|
1823
|
+
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") {
|
|
1672
1824
|
if (!seenToolCalls.has(part.id)) {
|
|
1673
1825
|
seenToolCalls.add(part.id);
|
|
1674
1826
|
const webSearchSubTools = [
|
|
@@ -1682,14 +1834,15 @@ var XaiResponsesLanguageModel = class {
|
|
|
1682
1834
|
"x_semantic_search",
|
|
1683
1835
|
"x_thread_fetch"
|
|
1684
1836
|
];
|
|
1685
|
-
let toolName = part.name;
|
|
1686
|
-
if (webSearchSubTools.includes(part.name)) {
|
|
1837
|
+
let toolName = (_d = part.name) != null ? _d : "";
|
|
1838
|
+
if (webSearchSubTools.includes((_e = part.name) != null ? _e : "")) {
|
|
1687
1839
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
1688
|
-
} else if (xSearchSubTools.includes(part.name)) {
|
|
1840
|
+
} else if (xSearchSubTools.includes((_f = part.name) != null ? _f : "")) {
|
|
1689
1841
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
1690
1842
|
} else if (part.name === "code_execution") {
|
|
1691
1843
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
1692
1844
|
}
|
|
1845
|
+
const toolInput = part.type === "custom_tool_call" ? (_g = part.input) != null ? _g : "" : (_h = part.arguments) != null ? _h : "";
|
|
1693
1846
|
controller.enqueue({
|
|
1694
1847
|
type: "tool-input-start",
|
|
1695
1848
|
id: part.id,
|
|
@@ -1698,7 +1851,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1698
1851
|
controller.enqueue({
|
|
1699
1852
|
type: "tool-input-delta",
|
|
1700
1853
|
id: part.id,
|
|
1701
|
-
delta:
|
|
1854
|
+
delta: toolInput
|
|
1702
1855
|
});
|
|
1703
1856
|
controller.enqueue({
|
|
1704
1857
|
type: "tool-input-end",
|
|
@@ -1708,7 +1861,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1708
1861
|
type: "tool-call",
|
|
1709
1862
|
toolCallId: part.id,
|
|
1710
1863
|
toolName,
|
|
1711
|
-
input:
|
|
1864
|
+
input: toolInput,
|
|
1712
1865
|
providerExecuted: true
|
|
1713
1866
|
});
|
|
1714
1867
|
}
|
|
@@ -1739,7 +1892,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1739
1892
|
sourceType: "url",
|
|
1740
1893
|
id: self.config.generateId(),
|
|
1741
1894
|
url: annotation.url,
|
|
1742
|
-
title: (
|
|
1895
|
+
title: (_i = annotation.title) != null ? _i : annotation.url
|
|
1743
1896
|
});
|
|
1744
1897
|
}
|
|
1745
1898
|
}
|
|
@@ -1847,7 +2000,7 @@ var xaiTools = {
|
|
|
1847
2000
|
};
|
|
1848
2001
|
|
|
1849
2002
|
// src/version.ts
|
|
1850
|
-
var VERSION = true ? "3.0.0-beta.
|
|
2003
|
+
var VERSION = true ? "3.0.0-beta.42" : "0.0.0-test";
|
|
1851
2004
|
|
|
1852
2005
|
// src/xai-provider.ts
|
|
1853
2006
|
var xaiErrorStructure = {
|