@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/dist/index.mjs
CHANGED
|
@@ -618,6 +618,7 @@ var XaiChatLanguageModel = class {
|
|
|
618
618
|
let isFirstChunk = true;
|
|
619
619
|
const contentBlocks = {};
|
|
620
620
|
const lastReasoningDeltas = {};
|
|
621
|
+
let activeReasoningBlockId = void 0;
|
|
621
622
|
const self = this;
|
|
622
623
|
return {
|
|
623
624
|
stream: response.pipeThrough(
|
|
@@ -670,13 +671,21 @@ var XaiChatLanguageModel = class {
|
|
|
670
671
|
const choiceIndex = choice.index;
|
|
671
672
|
if (delta.content != null && delta.content.length > 0) {
|
|
672
673
|
const textContent = delta.content;
|
|
674
|
+
if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
|
|
675
|
+
controller.enqueue({
|
|
676
|
+
type: "reasoning-end",
|
|
677
|
+
id: activeReasoningBlockId
|
|
678
|
+
});
|
|
679
|
+
contentBlocks[activeReasoningBlockId].ended = true;
|
|
680
|
+
activeReasoningBlockId = void 0;
|
|
681
|
+
}
|
|
673
682
|
const lastMessage = body.messages[body.messages.length - 1];
|
|
674
683
|
if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && textContent === lastMessage.content) {
|
|
675
684
|
return;
|
|
676
685
|
}
|
|
677
686
|
const blockId = `text-${value.id || choiceIndex}`;
|
|
678
687
|
if (contentBlocks[blockId] == null) {
|
|
679
|
-
contentBlocks[blockId] = { type: "text" };
|
|
688
|
+
contentBlocks[blockId] = { type: "text", ended: false };
|
|
680
689
|
controller.enqueue({
|
|
681
690
|
type: "text-start",
|
|
682
691
|
id: blockId
|
|
@@ -695,7 +704,8 @@ var XaiChatLanguageModel = class {
|
|
|
695
704
|
}
|
|
696
705
|
lastReasoningDeltas[blockId] = delta.reasoning_content;
|
|
697
706
|
if (contentBlocks[blockId] == null) {
|
|
698
|
-
contentBlocks[blockId] = { type: "reasoning" };
|
|
707
|
+
contentBlocks[blockId] = { type: "reasoning", ended: false };
|
|
708
|
+
activeReasoningBlockId = blockId;
|
|
699
709
|
controller.enqueue({
|
|
700
710
|
type: "reasoning-start",
|
|
701
711
|
id: blockId
|
|
@@ -708,6 +718,14 @@ var XaiChatLanguageModel = class {
|
|
|
708
718
|
});
|
|
709
719
|
}
|
|
710
720
|
if (delta.tool_calls != null) {
|
|
721
|
+
if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
|
|
722
|
+
controller.enqueue({
|
|
723
|
+
type: "reasoning-end",
|
|
724
|
+
id: activeReasoningBlockId
|
|
725
|
+
});
|
|
726
|
+
contentBlocks[activeReasoningBlockId].ended = true;
|
|
727
|
+
activeReasoningBlockId = void 0;
|
|
728
|
+
}
|
|
711
729
|
for (const toolCall of delta.tool_calls) {
|
|
712
730
|
const toolCallId = toolCall.id;
|
|
713
731
|
controller.enqueue({
|
|
@@ -735,10 +753,12 @@ var XaiChatLanguageModel = class {
|
|
|
735
753
|
},
|
|
736
754
|
flush(controller) {
|
|
737
755
|
for (const [blockId, block] of Object.entries(contentBlocks)) {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
756
|
+
if (!block.ended) {
|
|
757
|
+
controller.enqueue({
|
|
758
|
+
type: block.type === "text" ? "text-end" : "reasoning-end",
|
|
759
|
+
id: blockId
|
|
760
|
+
});
|
|
761
|
+
}
|
|
742
762
|
}
|
|
743
763
|
controller.enqueue({ type: "finish", finishReason, usage });
|
|
744
764
|
}
|
|
@@ -1582,11 +1602,12 @@ var XaiResponsesLanguageModel = class {
|
|
|
1582
1602
|
topP,
|
|
1583
1603
|
stopSequences,
|
|
1584
1604
|
seed,
|
|
1605
|
+
responseFormat,
|
|
1585
1606
|
providerOptions,
|
|
1586
1607
|
tools,
|
|
1587
1608
|
toolChoice
|
|
1588
1609
|
}) {
|
|
1589
|
-
var _a, _b, _c, _d;
|
|
1610
|
+
var _a, _b, _c, _d, _e;
|
|
1590
1611
|
const warnings = [];
|
|
1591
1612
|
const options = (_a = await parseProviderOptions2({
|
|
1592
1613
|
provider: "xai",
|
|
@@ -1629,6 +1650,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
1629
1650
|
temperature,
|
|
1630
1651
|
top_p: topP,
|
|
1631
1652
|
seed,
|
|
1653
|
+
...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
|
|
1654
|
+
text: {
|
|
1655
|
+
format: responseFormat.schema != null ? {
|
|
1656
|
+
type: "json_schema",
|
|
1657
|
+
strict: true,
|
|
1658
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
1659
|
+
description: responseFormat.description,
|
|
1660
|
+
schema: responseFormat.schema
|
|
1661
|
+
} : { type: "json_object" }
|
|
1662
|
+
}
|
|
1663
|
+
},
|
|
1632
1664
|
...options.reasoningEffort != null && {
|
|
1633
1665
|
reasoning: { effort: options.reasoningEffort }
|
|
1634
1666
|
},
|
|
@@ -2093,7 +2125,7 @@ var xaiTools = {
|
|
|
2093
2125
|
};
|
|
2094
2126
|
|
|
2095
2127
|
// src/version.ts
|
|
2096
|
-
var VERSION = true ? "2.0.
|
|
2128
|
+
var VERSION = true ? "2.0.51" : "0.0.0-test";
|
|
2097
2129
|
|
|
2098
2130
|
// src/xai-provider.ts
|
|
2099
2131
|
var xaiErrorStructure = {
|