@ai-sdk/xai 2.0.49 → 2.0.50
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 +6 -0
- package/dist/index.js +27 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
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
|
}
|
|
@@ -2088,7 +2108,7 @@ var xaiTools = {
|
|
|
2088
2108
|
};
|
|
2089
2109
|
|
|
2090
2110
|
// src/version.ts
|
|
2091
|
-
var VERSION = true ? "2.0.
|
|
2111
|
+
var VERSION = true ? "2.0.50" : "0.0.0-test";
|
|
2092
2112
|
|
|
2093
2113
|
// src/xai-provider.ts
|
|
2094
2114
|
var xaiErrorStructure = {
|