@ai-sdk/xai 2.0.51 → 2.0.53
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.js +116 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -937,7 +937,8 @@ var outputItemSchema = z4.discriminatedUnion("type", [
|
|
|
937
937
|
type: z4.literal("reasoning"),
|
|
938
938
|
id: z4.string(),
|
|
939
939
|
summary: z4.array(reasoningSummaryPartSchema),
|
|
940
|
-
status: z4.string()
|
|
940
|
+
status: z4.string(),
|
|
941
|
+
encrypted_content: z4.string().nullish()
|
|
941
942
|
})
|
|
942
943
|
]);
|
|
943
944
|
var xaiResponsesUsageSchema = z4.object({
|
|
@@ -1184,6 +1185,10 @@ var xaiResponsesProviderOptions = z5.object({
|
|
|
1184
1185
|
});
|
|
1185
1186
|
|
|
1186
1187
|
// src/responses/convert-to-xai-responses-input.ts
|
|
1188
|
+
import {
|
|
1189
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
1190
|
+
} from "@ai-sdk/provider";
|
|
1191
|
+
import { convertToBase64 as convertToBase642 } from "@ai-sdk/provider-utils";
|
|
1187
1192
|
async function convertToXaiResponsesInput({
|
|
1188
1193
|
prompt
|
|
1189
1194
|
}) {
|
|
@@ -1200,18 +1205,23 @@ async function convertToXaiResponsesInput({
|
|
|
1200
1205
|
break;
|
|
1201
1206
|
}
|
|
1202
1207
|
case "user": {
|
|
1203
|
-
|
|
1208
|
+
const contentParts = [];
|
|
1204
1209
|
for (const block of message.content) {
|
|
1205
1210
|
switch (block.type) {
|
|
1206
1211
|
case "text": {
|
|
1207
|
-
|
|
1212
|
+
contentParts.push({ type: "input_text", text: block.text });
|
|
1208
1213
|
break;
|
|
1209
1214
|
}
|
|
1210
1215
|
case "file": {
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1216
|
+
if (block.mediaType.startsWith("image/")) {
|
|
1217
|
+
const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
|
|
1218
|
+
const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${convertToBase642(block.data)}`;
|
|
1219
|
+
contentParts.push({ type: "input_image", image_url: imageUrl });
|
|
1220
|
+
} else {
|
|
1221
|
+
throw new UnsupportedFunctionalityError3({
|
|
1222
|
+
functionality: `file part media type ${block.mediaType}`
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1215
1225
|
break;
|
|
1216
1226
|
}
|
|
1217
1227
|
default: {
|
|
@@ -1225,7 +1235,7 @@ async function convertToXaiResponsesInput({
|
|
|
1225
1235
|
}
|
|
1226
1236
|
input.push({
|
|
1227
1237
|
role: "user",
|
|
1228
|
-
content:
|
|
1238
|
+
content: contentParts
|
|
1229
1239
|
});
|
|
1230
1240
|
break;
|
|
1231
1241
|
}
|
|
@@ -1326,7 +1336,7 @@ async function convertToXaiResponsesInput({
|
|
|
1326
1336
|
|
|
1327
1337
|
// src/responses/xai-responses-prepare-tools.ts
|
|
1328
1338
|
import {
|
|
1329
|
-
UnsupportedFunctionalityError as
|
|
1339
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError4
|
|
1330
1340
|
} from "@ai-sdk/provider";
|
|
1331
1341
|
import { validateTypes } from "@ai-sdk/provider-utils";
|
|
1332
1342
|
|
|
@@ -1575,7 +1585,7 @@ async function prepareResponsesTools({
|
|
|
1575
1585
|
}
|
|
1576
1586
|
default: {
|
|
1577
1587
|
const _exhaustiveCheck = type;
|
|
1578
|
-
throw new
|
|
1588
|
+
throw new UnsupportedFunctionalityError4({
|
|
1579
1589
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1580
1590
|
});
|
|
1581
1591
|
}
|
|
@@ -1776,6 +1786,32 @@ var XaiResponsesLanguageModel = class {
|
|
|
1776
1786
|
});
|
|
1777
1787
|
break;
|
|
1778
1788
|
}
|
|
1789
|
+
case "reasoning": {
|
|
1790
|
+
const summaryTexts = part.summary.map((s) => s.text).filter((text) => text && text.length > 0);
|
|
1791
|
+
if (summaryTexts.length > 0) {
|
|
1792
|
+
const reasoningText = summaryTexts.join("");
|
|
1793
|
+
if (part.encrypted_content || part.id) {
|
|
1794
|
+
content.push({
|
|
1795
|
+
type: "reasoning",
|
|
1796
|
+
text: reasoningText,
|
|
1797
|
+
providerMetadata: {
|
|
1798
|
+
xai: {
|
|
1799
|
+
...part.encrypted_content && {
|
|
1800
|
+
reasoningEncryptedContent: part.encrypted_content
|
|
1801
|
+
},
|
|
1802
|
+
...part.id && { itemId: part.id }
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
});
|
|
1806
|
+
} else {
|
|
1807
|
+
content.push({
|
|
1808
|
+
type: "reasoning",
|
|
1809
|
+
text: reasoningText
|
|
1810
|
+
});
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
break;
|
|
1814
|
+
}
|
|
1779
1815
|
default: {
|
|
1780
1816
|
break;
|
|
1781
1817
|
}
|
|
@@ -1833,6 +1869,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1833
1869
|
let isFirstChunk = true;
|
|
1834
1870
|
const contentBlocks = {};
|
|
1835
1871
|
const seenToolCalls = /* @__PURE__ */ new Set();
|
|
1872
|
+
const activeReasoning = {};
|
|
1836
1873
|
const self = this;
|
|
1837
1874
|
return {
|
|
1838
1875
|
stream: response.pipeThrough(
|
|
@@ -1864,7 +1901,12 @@ var XaiResponsesLanguageModel = class {
|
|
|
1864
1901
|
const blockId = `reasoning-${event.item_id}`;
|
|
1865
1902
|
controller.enqueue({
|
|
1866
1903
|
type: "reasoning-start",
|
|
1867
|
-
id: blockId
|
|
1904
|
+
id: blockId,
|
|
1905
|
+
providerMetadata: {
|
|
1906
|
+
xai: {
|
|
1907
|
+
itemId: event.item_id
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1868
1910
|
});
|
|
1869
1911
|
}
|
|
1870
1912
|
if (event.type === "response.reasoning_summary_text.delta") {
|
|
@@ -1872,16 +1914,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
1872
1914
|
controller.enqueue({
|
|
1873
1915
|
type: "reasoning-delta",
|
|
1874
1916
|
id: blockId,
|
|
1875
|
-
delta: event.delta
|
|
1917
|
+
delta: event.delta,
|
|
1918
|
+
providerMetadata: {
|
|
1919
|
+
xai: {
|
|
1920
|
+
itemId: event.item_id
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1876
1923
|
});
|
|
1877
1924
|
return;
|
|
1878
1925
|
}
|
|
1879
1926
|
if (event.type === "response.reasoning_summary_text.done") {
|
|
1880
|
-
|
|
1881
|
-
controller.enqueue({
|
|
1882
|
-
type: "reasoning-end",
|
|
1883
|
-
id: blockId
|
|
1884
|
-
});
|
|
1927
|
+
return;
|
|
1885
1928
|
}
|
|
1886
1929
|
if (event.type === "response.output_text.delta") {
|
|
1887
1930
|
const blockId = `text-${event.item_id}`;
|
|
@@ -1944,6 +1987,24 @@ var XaiResponsesLanguageModel = class {
|
|
|
1944
1987
|
}
|
|
1945
1988
|
if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
|
|
1946
1989
|
const part = event.item;
|
|
1990
|
+
if (part.type === "reasoning") {
|
|
1991
|
+
if (event.type === "response.output_item.done") {
|
|
1992
|
+
controller.enqueue({
|
|
1993
|
+
type: "reasoning-end",
|
|
1994
|
+
id: `reasoning-${part.id}`,
|
|
1995
|
+
providerMetadata: {
|
|
1996
|
+
xai: {
|
|
1997
|
+
...part.encrypted_content && {
|
|
1998
|
+
reasoningEncryptedContent: part.encrypted_content
|
|
1999
|
+
},
|
|
2000
|
+
...part.id && { itemId: part.id }
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
});
|
|
2004
|
+
delete activeReasoning[part.id];
|
|
2005
|
+
}
|
|
2006
|
+
return;
|
|
2007
|
+
}
|
|
1947
2008
|
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") {
|
|
1948
2009
|
const webSearchSubTools = [
|
|
1949
2010
|
"web_search",
|
|
@@ -2125,7 +2186,7 @@ var xaiTools = {
|
|
|
2125
2186
|
};
|
|
2126
2187
|
|
|
2127
2188
|
// src/version.ts
|
|
2128
|
-
var VERSION = true ? "2.0.
|
|
2189
|
+
var VERSION = true ? "2.0.53" : "0.0.0-test";
|
|
2129
2190
|
|
|
2130
2191
|
// src/xai-provider.ts
|
|
2131
2192
|
var xaiErrorStructure = {
|