@ai-sdk/xai 2.0.56 → 2.0.58
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 +64 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -457,7 +457,7 @@ var XaiChatLanguageModel = class {
|
|
|
457
457
|
};
|
|
458
458
|
}
|
|
459
459
|
async doGenerate(options) {
|
|
460
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
460
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
461
461
|
const { args: body, warnings } = await this.getArgs(options);
|
|
462
462
|
const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
|
|
463
463
|
const {
|
|
@@ -539,10 +539,10 @@ var XaiChatLanguageModel = class {
|
|
|
539
539
|
finishReason: mapXaiFinishReason(choice.finish_reason),
|
|
540
540
|
usage: {
|
|
541
541
|
inputTokens: (_b = response.usage) == null ? void 0 : _b.prompt_tokens,
|
|
542
|
-
outputTokens: (_c = response.usage) == null ? void 0 : _c.completion_tokens,
|
|
543
|
-
totalTokens: (
|
|
544
|
-
reasoningTokens: (
|
|
545
|
-
cachedInputTokens: (
|
|
542
|
+
outputTokens: ((_d = (_c = response.usage) == null ? void 0 : _c.completion_tokens) != null ? _d : 0) + ((_g = (_f = (_e = response.usage) == null ? void 0 : _e.completion_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : 0),
|
|
543
|
+
totalTokens: (_h = response.usage) == null ? void 0 : _h.total_tokens,
|
|
544
|
+
reasoningTokens: (_k = (_j = (_i = response.usage) == null ? void 0 : _i.completion_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0,
|
|
545
|
+
cachedInputTokens: (_n = (_m = (_l = response.usage) == null ? void 0 : _l.prompt_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0
|
|
546
546
|
},
|
|
547
547
|
request: { body },
|
|
548
548
|
response: {
|
|
@@ -627,7 +627,7 @@ var XaiChatLanguageModel = class {
|
|
|
627
627
|
controller.enqueue({ type: "stream-start", warnings });
|
|
628
628
|
},
|
|
629
629
|
transform(chunk, controller) {
|
|
630
|
-
var _a2, _b, _c, _d;
|
|
630
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
631
631
|
if (options.includeRawChunks) {
|
|
632
632
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
633
633
|
}
|
|
@@ -655,10 +655,10 @@ var XaiChatLanguageModel = class {
|
|
|
655
655
|
}
|
|
656
656
|
if (value.usage != null) {
|
|
657
657
|
usage.inputTokens = value.usage.prompt_tokens;
|
|
658
|
-
usage.outputTokens = value.usage.completion_tokens;
|
|
658
|
+
usage.outputTokens = ((_a2 = value.usage.completion_tokens) != null ? _a2 : 0) + ((_c = (_b = value.usage.completion_tokens_details) == null ? void 0 : _b.reasoning_tokens) != null ? _c : 0);
|
|
659
659
|
usage.totalTokens = value.usage.total_tokens;
|
|
660
|
-
usage.reasoningTokens = (
|
|
661
|
-
usage.cachedInputTokens = (
|
|
660
|
+
usage.reasoningTokens = (_e = (_d = value.usage.completion_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
|
|
661
|
+
usage.cachedInputTokens = (_g = (_f = value.usage.prompt_tokens_details) == null ? void 0 : _f.cached_tokens) != null ? _g : void 0;
|
|
662
662
|
}
|
|
663
663
|
const choice = value.choices[0];
|
|
664
664
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
@@ -1049,6 +1049,20 @@ var xaiResponsesChunkSchema = z4.union([
|
|
|
1049
1049
|
summary_index: z4.number(),
|
|
1050
1050
|
text: z4.string()
|
|
1051
1051
|
}),
|
|
1052
|
+
z4.object({
|
|
1053
|
+
type: z4.literal("response.reasoning_text.delta"),
|
|
1054
|
+
item_id: z4.string(),
|
|
1055
|
+
output_index: z4.number(),
|
|
1056
|
+
content_index: z4.number(),
|
|
1057
|
+
delta: z4.string()
|
|
1058
|
+
}),
|
|
1059
|
+
z4.object({
|
|
1060
|
+
type: z4.literal("response.reasoning_text.done"),
|
|
1061
|
+
item_id: z4.string(),
|
|
1062
|
+
output_index: z4.number(),
|
|
1063
|
+
content_index: z4.number(),
|
|
1064
|
+
text: z4.string()
|
|
1065
|
+
}),
|
|
1052
1066
|
z4.object({
|
|
1053
1067
|
type: z4.literal("response.web_search_call.in_progress"),
|
|
1054
1068
|
item_id: z4.string(),
|
|
@@ -1930,6 +1944,35 @@ var XaiResponsesLanguageModel = class {
|
|
|
1930
1944
|
if (event.type === "response.reasoning_summary_text.done") {
|
|
1931
1945
|
return;
|
|
1932
1946
|
}
|
|
1947
|
+
if (event.type === "response.reasoning_text.delta") {
|
|
1948
|
+
const blockId = `reasoning-${event.item_id}`;
|
|
1949
|
+
if (activeReasoning[event.item_id] == null) {
|
|
1950
|
+
activeReasoning[event.item_id] = {};
|
|
1951
|
+
controller.enqueue({
|
|
1952
|
+
type: "reasoning-start",
|
|
1953
|
+
id: blockId,
|
|
1954
|
+
providerMetadata: {
|
|
1955
|
+
xai: {
|
|
1956
|
+
itemId: event.item_id
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
controller.enqueue({
|
|
1962
|
+
type: "reasoning-delta",
|
|
1963
|
+
id: blockId,
|
|
1964
|
+
delta: event.delta,
|
|
1965
|
+
providerMetadata: {
|
|
1966
|
+
xai: {
|
|
1967
|
+
itemId: event.item_id
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1971
|
+
return;
|
|
1972
|
+
}
|
|
1973
|
+
if (event.type === "response.reasoning_text.done") {
|
|
1974
|
+
return;
|
|
1975
|
+
}
|
|
1933
1976
|
if (event.type === "response.output_text.delta") {
|
|
1934
1977
|
const blockId = `text-${event.item_id}`;
|
|
1935
1978
|
if (contentBlocks[blockId] == null) {
|
|
@@ -1993,6 +2036,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
1993
2036
|
const part = event.item;
|
|
1994
2037
|
if (part.type === "reasoning") {
|
|
1995
2038
|
if (event.type === "response.output_item.done") {
|
|
2039
|
+
if (activeReasoning[part.id] == null) {
|
|
2040
|
+
controller.enqueue({
|
|
2041
|
+
type: "reasoning-start",
|
|
2042
|
+
id: `reasoning-${part.id}`,
|
|
2043
|
+
providerMetadata: {
|
|
2044
|
+
xai: {
|
|
2045
|
+
itemId: part.id
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
1996
2050
|
controller.enqueue({
|
|
1997
2051
|
type: "reasoning-end",
|
|
1998
2052
|
id: `reasoning-${part.id}`,
|
|
@@ -2190,7 +2244,7 @@ var xaiTools = {
|
|
|
2190
2244
|
};
|
|
2191
2245
|
|
|
2192
2246
|
// src/version.ts
|
|
2193
|
-
var VERSION = true ? "2.0.
|
|
2247
|
+
var VERSION = true ? "2.0.58" : "0.0.0-test";
|
|
2194
2248
|
|
|
2195
2249
|
// src/xai-provider.ts
|
|
2196
2250
|
var xaiErrorStructure = {
|