@ai-sdk/xai 3.0.0-beta.65 → 3.0.0-beta.67
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 +19 -0
- package/dist/index.js +50 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.67
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cbf52cd: feat: expose raw finish reason
|
|
8
|
+
- Updated dependencies [cbf52cd]
|
|
9
|
+
- @ai-sdk/openai-compatible@2.0.0-beta.58
|
|
10
|
+
- @ai-sdk/provider@3.0.0-beta.30
|
|
11
|
+
- @ai-sdk/provider-utils@4.0.0-beta.57
|
|
12
|
+
|
|
13
|
+
## 3.0.0-beta.66
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [9549c9e]
|
|
18
|
+
- @ai-sdk/provider@3.0.0-beta.29
|
|
19
|
+
- @ai-sdk/openai-compatible@2.0.0-beta.57
|
|
20
|
+
- @ai-sdk/provider-utils@4.0.0-beta.56
|
|
21
|
+
|
|
3
22
|
## 3.0.0-beta.65
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -150,6 +150,27 @@ function convertToXaiChatMessages(prompt) {
|
|
|
150
150
|
return { messages, warnings };
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
// src/convert-xai-chat-usage.ts
|
|
154
|
+
function convertXaiChatUsage(usage) {
|
|
155
|
+
var _a, _b, _c, _d;
|
|
156
|
+
const cacheReadTokens = (_b = (_a = usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
|
|
157
|
+
const reasoningTokens = (_d = (_c = usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
|
|
158
|
+
return {
|
|
159
|
+
inputTokens: {
|
|
160
|
+
total: usage.prompt_tokens,
|
|
161
|
+
noCache: usage.prompt_tokens - cacheReadTokens,
|
|
162
|
+
cacheRead: cacheReadTokens,
|
|
163
|
+
cacheWrite: void 0
|
|
164
|
+
},
|
|
165
|
+
outputTokens: {
|
|
166
|
+
total: usage.completion_tokens,
|
|
167
|
+
text: usage.completion_tokens - reasoningTokens,
|
|
168
|
+
reasoning: reasoningTokens
|
|
169
|
+
},
|
|
170
|
+
raw: usage
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
153
174
|
// src/get-response-metadata.ts
|
|
154
175
|
function getResponseMetadata({
|
|
155
176
|
id,
|
|
@@ -178,7 +199,7 @@ function mapXaiFinishReason(finishReason) {
|
|
|
178
199
|
case "content_filter":
|
|
179
200
|
return "content-filter";
|
|
180
201
|
default:
|
|
181
|
-
return "
|
|
202
|
+
return "other";
|
|
182
203
|
}
|
|
183
204
|
}
|
|
184
205
|
|
|
@@ -338,27 +359,6 @@ function prepareTools({
|
|
|
338
359
|
}
|
|
339
360
|
}
|
|
340
361
|
|
|
341
|
-
// src/convert-xai-chat-usage.ts
|
|
342
|
-
function convertXaiChatUsage(usage) {
|
|
343
|
-
var _a, _b, _c, _d;
|
|
344
|
-
const cacheReadTokens = (_b = (_a = usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
|
|
345
|
-
const reasoningTokens = (_d = (_c = usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
|
|
346
|
-
return {
|
|
347
|
-
inputTokens: {
|
|
348
|
-
total: usage.prompt_tokens,
|
|
349
|
-
noCache: usage.prompt_tokens - cacheReadTokens,
|
|
350
|
-
cacheRead: cacheReadTokens,
|
|
351
|
-
cacheWrite: void 0
|
|
352
|
-
},
|
|
353
|
-
outputTokens: {
|
|
354
|
-
total: usage.completion_tokens,
|
|
355
|
-
text: usage.completion_tokens - reasoningTokens,
|
|
356
|
-
reasoning: reasoningTokens
|
|
357
|
-
},
|
|
358
|
-
raw: usage
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
|
|
362
362
|
// src/xai-chat-language-model.ts
|
|
363
363
|
var XaiChatLanguageModel = class {
|
|
364
364
|
constructor(modelId, config) {
|
|
@@ -483,7 +483,7 @@ var XaiChatLanguageModel = class {
|
|
|
483
483
|
};
|
|
484
484
|
}
|
|
485
485
|
async doGenerate(options) {
|
|
486
|
-
var _a;
|
|
486
|
+
var _a, _b;
|
|
487
487
|
const { args: body, warnings } = await this.getArgs(options);
|
|
488
488
|
const {
|
|
489
489
|
responseHeaders,
|
|
@@ -540,7 +540,10 @@ var XaiChatLanguageModel = class {
|
|
|
540
540
|
}
|
|
541
541
|
return {
|
|
542
542
|
content,
|
|
543
|
-
finishReason:
|
|
543
|
+
finishReason: {
|
|
544
|
+
unified: mapXaiFinishReason(choice.finish_reason),
|
|
545
|
+
raw: (_b = choice.finish_reason) != null ? _b : void 0
|
|
546
|
+
},
|
|
544
547
|
usage: convertXaiChatUsage(response.usage),
|
|
545
548
|
request: { body },
|
|
546
549
|
response: {
|
|
@@ -570,7 +573,10 @@ var XaiChatLanguageModel = class {
|
|
|
570
573
|
abortSignal: options.abortSignal,
|
|
571
574
|
fetch: this.config.fetch
|
|
572
575
|
});
|
|
573
|
-
let finishReason =
|
|
576
|
+
let finishReason = {
|
|
577
|
+
unified: "other",
|
|
578
|
+
raw: void 0
|
|
579
|
+
};
|
|
574
580
|
let usage = void 0;
|
|
575
581
|
let isFirstChunk = true;
|
|
576
582
|
const contentBlocks = {};
|
|
@@ -613,7 +619,10 @@ var XaiChatLanguageModel = class {
|
|
|
613
619
|
}
|
|
614
620
|
const choice = value.choices[0];
|
|
615
621
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
616
|
-
finishReason =
|
|
622
|
+
finishReason = {
|
|
623
|
+
unified: mapXaiFinishReason(choice.finish_reason),
|
|
624
|
+
raw: choice.finish_reason
|
|
625
|
+
};
|
|
617
626
|
}
|
|
618
627
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
619
628
|
return;
|
|
@@ -958,7 +967,7 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
958
967
|
case "content_filter":
|
|
959
968
|
return "content-filter";
|
|
960
969
|
default:
|
|
961
|
-
return "
|
|
970
|
+
return "other";
|
|
962
971
|
}
|
|
963
972
|
}
|
|
964
973
|
|
|
@@ -1584,7 +1593,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1584
1593
|
};
|
|
1585
1594
|
}
|
|
1586
1595
|
async doGenerate(options) {
|
|
1587
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1596
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1588
1597
|
const {
|
|
1589
1598
|
args: body,
|
|
1590
1599
|
warnings,
|
|
@@ -1680,7 +1689,10 @@ var XaiResponsesLanguageModel = class {
|
|
|
1680
1689
|
}
|
|
1681
1690
|
return {
|
|
1682
1691
|
content,
|
|
1683
|
-
finishReason:
|
|
1692
|
+
finishReason: {
|
|
1693
|
+
unified: mapXaiResponsesFinishReason(response.status),
|
|
1694
|
+
raw: (_h = response.status) != null ? _h : void 0
|
|
1695
|
+
},
|
|
1684
1696
|
usage: convertXaiResponsesUsage(response.usage),
|
|
1685
1697
|
request: { body },
|
|
1686
1698
|
response: {
|
|
@@ -1715,7 +1727,10 @@ var XaiResponsesLanguageModel = class {
|
|
|
1715
1727
|
abortSignal: options.abortSignal,
|
|
1716
1728
|
fetch: this.config.fetch
|
|
1717
1729
|
});
|
|
1718
|
-
let finishReason =
|
|
1730
|
+
let finishReason = {
|
|
1731
|
+
unified: "other",
|
|
1732
|
+
raw: void 0
|
|
1733
|
+
};
|
|
1719
1734
|
let usage = void 0;
|
|
1720
1735
|
let isFirstChunk = true;
|
|
1721
1736
|
const contentBlocks = {};
|
|
@@ -1821,7 +1836,10 @@ var XaiResponsesLanguageModel = class {
|
|
|
1821
1836
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
1822
1837
|
}
|
|
1823
1838
|
if (response2.status) {
|
|
1824
|
-
finishReason =
|
|
1839
|
+
finishReason = {
|
|
1840
|
+
unified: mapXaiResponsesFinishReason(response2.status),
|
|
1841
|
+
raw: response2.status
|
|
1842
|
+
};
|
|
1825
1843
|
}
|
|
1826
1844
|
return;
|
|
1827
1845
|
}
|
|
@@ -2004,7 +2022,7 @@ var xaiTools = {
|
|
|
2004
2022
|
};
|
|
2005
2023
|
|
|
2006
2024
|
// src/version.ts
|
|
2007
|
-
var VERSION = true ? "3.0.0-beta.
|
|
2025
|
+
var VERSION = true ? "3.0.0-beta.67" : "0.0.0-test";
|
|
2008
2026
|
|
|
2009
2027
|
// src/xai-provider.ts
|
|
2010
2028
|
var xaiErrorStructure = {
|