@ai-sdk/xai 2.0.49 → 2.0.51
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 +40 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 2.0.51
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c635580: fix (provider/xai): set response format to allow object generation
|
|
8
|
+
|
|
9
|
+
## 2.0.50
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 13a913c: fix(provider/xai): send reasoning-end before text-start in streaming
|
|
14
|
+
|
|
3
15
|
## 2.0.49
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -629,6 +629,7 @@ var XaiChatLanguageModel = class {
|
|
|
629
629
|
let isFirstChunk = true;
|
|
630
630
|
const contentBlocks = {};
|
|
631
631
|
const lastReasoningDeltas = {};
|
|
632
|
+
let activeReasoningBlockId = void 0;
|
|
632
633
|
const self = this;
|
|
633
634
|
return {
|
|
634
635
|
stream: response.pipeThrough(
|
|
@@ -681,13 +682,21 @@ var XaiChatLanguageModel = class {
|
|
|
681
682
|
const choiceIndex = choice.index;
|
|
682
683
|
if (delta.content != null && delta.content.length > 0) {
|
|
683
684
|
const textContent = delta.content;
|
|
685
|
+
if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
|
|
686
|
+
controller.enqueue({
|
|
687
|
+
type: "reasoning-end",
|
|
688
|
+
id: activeReasoningBlockId
|
|
689
|
+
});
|
|
690
|
+
contentBlocks[activeReasoningBlockId].ended = true;
|
|
691
|
+
activeReasoningBlockId = void 0;
|
|
692
|
+
}
|
|
684
693
|
const lastMessage = body.messages[body.messages.length - 1];
|
|
685
694
|
if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && textContent === lastMessage.content) {
|
|
686
695
|
return;
|
|
687
696
|
}
|
|
688
697
|
const blockId = `text-${value.id || choiceIndex}`;
|
|
689
698
|
if (contentBlocks[blockId] == null) {
|
|
690
|
-
contentBlocks[blockId] = { type: "text" };
|
|
699
|
+
contentBlocks[blockId] = { type: "text", ended: false };
|
|
691
700
|
controller.enqueue({
|
|
692
701
|
type: "text-start",
|
|
693
702
|
id: blockId
|
|
@@ -706,7 +715,8 @@ var XaiChatLanguageModel = class {
|
|
|
706
715
|
}
|
|
707
716
|
lastReasoningDeltas[blockId] = delta.reasoning_content;
|
|
708
717
|
if (contentBlocks[blockId] == null) {
|
|
709
|
-
contentBlocks[blockId] = { type: "reasoning" };
|
|
718
|
+
contentBlocks[blockId] = { type: "reasoning", ended: false };
|
|
719
|
+
activeReasoningBlockId = blockId;
|
|
710
720
|
controller.enqueue({
|
|
711
721
|
type: "reasoning-start",
|
|
712
722
|
id: blockId
|
|
@@ -719,6 +729,14 @@ var XaiChatLanguageModel = class {
|
|
|
719
729
|
});
|
|
720
730
|
}
|
|
721
731
|
if (delta.tool_calls != null) {
|
|
732
|
+
if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
|
|
733
|
+
controller.enqueue({
|
|
734
|
+
type: "reasoning-end",
|
|
735
|
+
id: activeReasoningBlockId
|
|
736
|
+
});
|
|
737
|
+
contentBlocks[activeReasoningBlockId].ended = true;
|
|
738
|
+
activeReasoningBlockId = void 0;
|
|
739
|
+
}
|
|
722
740
|
for (const toolCall of delta.tool_calls) {
|
|
723
741
|
const toolCallId = toolCall.id;
|
|
724
742
|
controller.enqueue({
|
|
@@ -746,10 +764,12 @@ var XaiChatLanguageModel = class {
|
|
|
746
764
|
},
|
|
747
765
|
flush(controller) {
|
|
748
766
|
for (const [blockId, block] of Object.entries(contentBlocks)) {
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
767
|
+
if (!block.ended) {
|
|
768
|
+
controller.enqueue({
|
|
769
|
+
type: block.type === "text" ? "text-end" : "reasoning-end",
|
|
770
|
+
id: blockId
|
|
771
|
+
});
|
|
772
|
+
}
|
|
753
773
|
}
|
|
754
774
|
controller.enqueue({ type: "finish", finishReason, usage });
|
|
755
775
|
}
|
|
@@ -1577,11 +1597,12 @@ var XaiResponsesLanguageModel = class {
|
|
|
1577
1597
|
topP,
|
|
1578
1598
|
stopSequences,
|
|
1579
1599
|
seed,
|
|
1600
|
+
responseFormat,
|
|
1580
1601
|
providerOptions,
|
|
1581
1602
|
tools,
|
|
1582
1603
|
toolChoice
|
|
1583
1604
|
}) {
|
|
1584
|
-
var _a, _b, _c, _d;
|
|
1605
|
+
var _a, _b, _c, _d, _e;
|
|
1585
1606
|
const warnings = [];
|
|
1586
1607
|
const options = (_a = await (0, import_provider_utils7.parseProviderOptions)({
|
|
1587
1608
|
provider: "xai",
|
|
@@ -1624,6 +1645,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
1624
1645
|
temperature,
|
|
1625
1646
|
top_p: topP,
|
|
1626
1647
|
seed,
|
|
1648
|
+
...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
|
|
1649
|
+
text: {
|
|
1650
|
+
format: responseFormat.schema != null ? {
|
|
1651
|
+
type: "json_schema",
|
|
1652
|
+
strict: true,
|
|
1653
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
1654
|
+
description: responseFormat.description,
|
|
1655
|
+
schema: responseFormat.schema
|
|
1656
|
+
} : { type: "json_object" }
|
|
1657
|
+
}
|
|
1658
|
+
},
|
|
1627
1659
|
...options.reasoningEffort != null && {
|
|
1628
1660
|
reasoning: { effort: options.reasoningEffort }
|
|
1629
1661
|
},
|
|
@@ -2088,7 +2120,7 @@ var xaiTools = {
|
|
|
2088
2120
|
};
|
|
2089
2121
|
|
|
2090
2122
|
// src/version.ts
|
|
2091
|
-
var VERSION = true ? "2.0.
|
|
2123
|
+
var VERSION = true ? "2.0.51" : "0.0.0-test";
|
|
2092
2124
|
|
|
2093
2125
|
// src/xai-provider.ts
|
|
2094
2126
|
var xaiErrorStructure = {
|