@ai-sdk/xai 3.0.12 → 3.0.13
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 +5 -5
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -633,6 +633,7 @@ var XaiChatLanguageModel = class {
|
|
|
633
633
|
let isFirstChunk = true;
|
|
634
634
|
const contentBlocks = {};
|
|
635
635
|
const lastReasoningDeltas = {};
|
|
636
|
+
let activeReasoningBlockId = void 0;
|
|
636
637
|
const self = this;
|
|
637
638
|
return {
|
|
638
639
|
stream: response.pipeThrough(
|
|
@@ -683,13 +684,21 @@ var XaiChatLanguageModel = class {
|
|
|
683
684
|
const choiceIndex = choice.index;
|
|
684
685
|
if (delta.content != null && delta.content.length > 0) {
|
|
685
686
|
const textContent = delta.content;
|
|
687
|
+
if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
|
|
688
|
+
controller.enqueue({
|
|
689
|
+
type: "reasoning-end",
|
|
690
|
+
id: activeReasoningBlockId
|
|
691
|
+
});
|
|
692
|
+
contentBlocks[activeReasoningBlockId].ended = true;
|
|
693
|
+
activeReasoningBlockId = void 0;
|
|
694
|
+
}
|
|
686
695
|
const lastMessage = body.messages[body.messages.length - 1];
|
|
687
696
|
if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && textContent === lastMessage.content) {
|
|
688
697
|
return;
|
|
689
698
|
}
|
|
690
699
|
const blockId = `text-${value.id || choiceIndex}`;
|
|
691
700
|
if (contentBlocks[blockId] == null) {
|
|
692
|
-
contentBlocks[blockId] = { type: "text" };
|
|
701
|
+
contentBlocks[blockId] = { type: "text", ended: false };
|
|
693
702
|
controller.enqueue({
|
|
694
703
|
type: "text-start",
|
|
695
704
|
id: blockId
|
|
@@ -708,7 +717,8 @@ var XaiChatLanguageModel = class {
|
|
|
708
717
|
}
|
|
709
718
|
lastReasoningDeltas[blockId] = delta.reasoning_content;
|
|
710
719
|
if (contentBlocks[blockId] == null) {
|
|
711
|
-
contentBlocks[blockId] = { type: "reasoning" };
|
|
720
|
+
contentBlocks[blockId] = { type: "reasoning", ended: false };
|
|
721
|
+
activeReasoningBlockId = blockId;
|
|
712
722
|
controller.enqueue({
|
|
713
723
|
type: "reasoning-start",
|
|
714
724
|
id: blockId
|
|
@@ -721,6 +731,14 @@ var XaiChatLanguageModel = class {
|
|
|
721
731
|
});
|
|
722
732
|
}
|
|
723
733
|
if (delta.tool_calls != null) {
|
|
734
|
+
if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
|
|
735
|
+
controller.enqueue({
|
|
736
|
+
type: "reasoning-end",
|
|
737
|
+
id: activeReasoningBlockId
|
|
738
|
+
});
|
|
739
|
+
contentBlocks[activeReasoningBlockId].ended = true;
|
|
740
|
+
activeReasoningBlockId = void 0;
|
|
741
|
+
}
|
|
724
742
|
for (const toolCall of delta.tool_calls) {
|
|
725
743
|
const toolCallId = toolCall.id;
|
|
726
744
|
controller.enqueue({
|
|
@@ -748,10 +766,12 @@ var XaiChatLanguageModel = class {
|
|
|
748
766
|
},
|
|
749
767
|
flush(controller) {
|
|
750
768
|
for (const [blockId, block] of Object.entries(contentBlocks)) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
769
|
+
if (!block.ended) {
|
|
770
|
+
controller.enqueue({
|
|
771
|
+
type: block.type === "text" ? "text-end" : "reasoning-end",
|
|
772
|
+
id: blockId
|
|
773
|
+
});
|
|
774
|
+
}
|
|
755
775
|
}
|
|
756
776
|
controller.enqueue({ type: "finish", finishReason, usage });
|
|
757
777
|
}
|
|
@@ -2110,7 +2130,7 @@ var xaiTools = {
|
|
|
2110
2130
|
};
|
|
2111
2131
|
|
|
2112
2132
|
// src/version.ts
|
|
2113
|
-
var VERSION = true ? "3.0.
|
|
2133
|
+
var VERSION = true ? "3.0.13" : "0.0.0-test";
|
|
2114
2134
|
|
|
2115
2135
|
// src/xai-provider.ts
|
|
2116
2136
|
var xaiErrorStructure = {
|