@ai-sdk/xai 3.0.13 → 3.0.15
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 +78 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 3.0.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ed1587d: feat (provider/xai): add support for encrypted reasoning content
|
|
8
|
+
|
|
9
|
+
## 3.0.14
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 0a081cb: fix (provider/xai): set response format to allow object generation
|
|
14
|
+
|
|
3
15
|
## 3.0.13
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1130,7 +1130,8 @@ var outputItemSchema = import_v44.z.discriminatedUnion("type", [
|
|
|
1130
1130
|
type: import_v44.z.literal("reasoning"),
|
|
1131
1131
|
id: import_v44.z.string(),
|
|
1132
1132
|
summary: import_v44.z.array(reasoningSummaryPartSchema),
|
|
1133
|
-
status: import_v44.z.string()
|
|
1133
|
+
status: import_v44.z.string(),
|
|
1134
|
+
encrypted_content: import_v44.z.string().nullish()
|
|
1134
1135
|
})
|
|
1135
1136
|
]);
|
|
1136
1137
|
var xaiResponsesUsageSchema = import_v44.z.object({
|
|
@@ -1630,11 +1631,12 @@ var XaiResponsesLanguageModel = class {
|
|
|
1630
1631
|
topP,
|
|
1631
1632
|
stopSequences,
|
|
1632
1633
|
seed,
|
|
1634
|
+
responseFormat,
|
|
1633
1635
|
providerOptions,
|
|
1634
1636
|
tools,
|
|
1635
1637
|
toolChoice
|
|
1636
1638
|
}) {
|
|
1637
|
-
var _a, _b, _c, _d;
|
|
1639
|
+
var _a, _b, _c, _d, _e;
|
|
1638
1640
|
const warnings = [];
|
|
1639
1641
|
const options = (_a = await (0, import_provider_utils7.parseProviderOptions)({
|
|
1640
1642
|
provider: "xai",
|
|
@@ -1674,6 +1676,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
1674
1676
|
temperature,
|
|
1675
1677
|
top_p: topP,
|
|
1676
1678
|
seed,
|
|
1679
|
+
...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
|
|
1680
|
+
text: {
|
|
1681
|
+
format: responseFormat.schema != null ? {
|
|
1682
|
+
type: "json_schema",
|
|
1683
|
+
strict: true,
|
|
1684
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
1685
|
+
description: responseFormat.description,
|
|
1686
|
+
schema: responseFormat.schema
|
|
1687
|
+
} : { type: "json_object" }
|
|
1688
|
+
}
|
|
1689
|
+
},
|
|
1677
1690
|
...options.reasoningEffort != null && {
|
|
1678
1691
|
reasoning: { effort: options.reasoningEffort }
|
|
1679
1692
|
},
|
|
@@ -1789,6 +1802,32 @@ var XaiResponsesLanguageModel = class {
|
|
|
1789
1802
|
});
|
|
1790
1803
|
break;
|
|
1791
1804
|
}
|
|
1805
|
+
case "reasoning": {
|
|
1806
|
+
const summaryTexts = part.summary.map((s) => s.text).filter((text) => text && text.length > 0);
|
|
1807
|
+
if (summaryTexts.length > 0) {
|
|
1808
|
+
const reasoningText = summaryTexts.join("");
|
|
1809
|
+
if (part.encrypted_content || part.id) {
|
|
1810
|
+
content.push({
|
|
1811
|
+
type: "reasoning",
|
|
1812
|
+
text: reasoningText,
|
|
1813
|
+
providerMetadata: {
|
|
1814
|
+
xai: {
|
|
1815
|
+
...part.encrypted_content && {
|
|
1816
|
+
reasoningEncryptedContent: part.encrypted_content
|
|
1817
|
+
},
|
|
1818
|
+
...part.id && { itemId: part.id }
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
});
|
|
1822
|
+
} else {
|
|
1823
|
+
content.push({
|
|
1824
|
+
type: "reasoning",
|
|
1825
|
+
text: reasoningText
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
break;
|
|
1830
|
+
}
|
|
1792
1831
|
default: {
|
|
1793
1832
|
break;
|
|
1794
1833
|
}
|
|
@@ -1842,6 +1881,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1842
1881
|
let isFirstChunk = true;
|
|
1843
1882
|
const contentBlocks = {};
|
|
1844
1883
|
const seenToolCalls = /* @__PURE__ */ new Set();
|
|
1884
|
+
const activeReasoning = {};
|
|
1845
1885
|
const self = this;
|
|
1846
1886
|
return {
|
|
1847
1887
|
stream: response.pipeThrough(
|
|
@@ -1850,7 +1890,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1850
1890
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1851
1891
|
},
|
|
1852
1892
|
transform(chunk, controller) {
|
|
1853
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
1893
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1854
1894
|
if (options.includeRawChunks) {
|
|
1855
1895
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1856
1896
|
}
|
|
@@ -1873,7 +1913,12 @@ var XaiResponsesLanguageModel = class {
|
|
|
1873
1913
|
const blockId = `reasoning-${event.item_id}`;
|
|
1874
1914
|
controller.enqueue({
|
|
1875
1915
|
type: "reasoning-start",
|
|
1876
|
-
id: blockId
|
|
1916
|
+
id: blockId,
|
|
1917
|
+
providerMetadata: {
|
|
1918
|
+
xai: {
|
|
1919
|
+
itemId: event.item_id
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1877
1922
|
});
|
|
1878
1923
|
}
|
|
1879
1924
|
if (event.type === "response.reasoning_summary_text.delta") {
|
|
@@ -1881,16 +1926,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
1881
1926
|
controller.enqueue({
|
|
1882
1927
|
type: "reasoning-delta",
|
|
1883
1928
|
id: blockId,
|
|
1884
|
-
delta: event.delta
|
|
1929
|
+
delta: event.delta,
|
|
1930
|
+
providerMetadata: {
|
|
1931
|
+
xai: {
|
|
1932
|
+
itemId: event.item_id
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1885
1935
|
});
|
|
1886
1936
|
return;
|
|
1887
1937
|
}
|
|
1888
1938
|
if (event.type === "response.reasoning_summary_text.done") {
|
|
1889
|
-
|
|
1890
|
-
controller.enqueue({
|
|
1891
|
-
type: "reasoning-end",
|
|
1892
|
-
id: blockId
|
|
1893
|
-
});
|
|
1939
|
+
return;
|
|
1894
1940
|
}
|
|
1895
1941
|
if (event.type === "response.output_text.delta") {
|
|
1896
1942
|
const blockId = `text-${event.item_id}`;
|
|
@@ -1952,6 +1998,22 @@ var XaiResponsesLanguageModel = class {
|
|
|
1952
1998
|
}
|
|
1953
1999
|
if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
|
|
1954
2000
|
const part = event.item;
|
|
2001
|
+
if (part.type === "reasoning") {
|
|
2002
|
+
if (event.type === "response.output_item.done") {
|
|
2003
|
+
controller.enqueue({
|
|
2004
|
+
type: "reasoning-end",
|
|
2005
|
+
id: `reasoning-${part.id}`,
|
|
2006
|
+
providerMetadata: {
|
|
2007
|
+
xai: {
|
|
2008
|
+
itemId: part.id,
|
|
2009
|
+
reasoningEncryptedContent: (_c = part.encrypted_content) != null ? _c : null
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
});
|
|
2013
|
+
delete activeReasoning[part.id];
|
|
2014
|
+
}
|
|
2015
|
+
return;
|
|
2016
|
+
}
|
|
1955
2017
|
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") {
|
|
1956
2018
|
const webSearchSubTools = [
|
|
1957
2019
|
"web_search",
|
|
@@ -1964,15 +2026,15 @@ var XaiResponsesLanguageModel = class {
|
|
|
1964
2026
|
"x_semantic_search",
|
|
1965
2027
|
"x_thread_fetch"
|
|
1966
2028
|
];
|
|
1967
|
-
let toolName = (
|
|
1968
|
-
if (webSearchSubTools.includes((
|
|
2029
|
+
let toolName = (_d = part.name) != null ? _d : "";
|
|
2030
|
+
if (webSearchSubTools.includes((_e = part.name) != null ? _e : "") || part.type === "web_search_call") {
|
|
1969
2031
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
1970
|
-
} else if (xSearchSubTools.includes((
|
|
2032
|
+
} else if (xSearchSubTools.includes((_f = part.name) != null ? _f : "") || part.type === "x_search_call") {
|
|
1971
2033
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
1972
2034
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
1973
2035
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
1974
2036
|
}
|
|
1975
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2037
|
+
const toolInput = part.type === "custom_tool_call" ? (_g = part.input) != null ? _g : "" : (_h = part.arguments) != null ? _h : "";
|
|
1976
2038
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
1977
2039
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
1978
2040
|
seenToolCalls.add(part.id);
|
|
@@ -2025,7 +2087,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2025
2087
|
sourceType: "url",
|
|
2026
2088
|
id: self.config.generateId(),
|
|
2027
2089
|
url: annotation.url,
|
|
2028
|
-
title: (
|
|
2090
|
+
title: (_i = annotation.title) != null ? _i : annotation.url
|
|
2029
2091
|
});
|
|
2030
2092
|
}
|
|
2031
2093
|
}
|
|
@@ -2130,7 +2192,7 @@ var xaiTools = {
|
|
|
2130
2192
|
};
|
|
2131
2193
|
|
|
2132
2194
|
// src/version.ts
|
|
2133
|
-
var VERSION = true ? "3.0.
|
|
2195
|
+
var VERSION = true ? "3.0.15" : "0.0.0-test";
|
|
2134
2196
|
|
|
2135
2197
|
// src/xai-provider.ts
|
|
2136
2198
|
var xaiErrorStructure = {
|