@ai-sdk/xai 3.0.12 → 3.0.14
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 +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 3.0.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0a081cb: fix (provider/xai): set response format to allow object generation
|
|
8
|
+
|
|
9
|
+
## 3.0.13
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 7ac2437: fix(provider/xai): send reasoning-end before text-start in streaming
|
|
14
|
+
|
|
3
15
|
## 3.0.12
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
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
|
}
|
|
@@ -1610,11 +1630,12 @@ var XaiResponsesLanguageModel = class {
|
|
|
1610
1630
|
topP,
|
|
1611
1631
|
stopSequences,
|
|
1612
1632
|
seed,
|
|
1633
|
+
responseFormat,
|
|
1613
1634
|
providerOptions,
|
|
1614
1635
|
tools,
|
|
1615
1636
|
toolChoice
|
|
1616
1637
|
}) {
|
|
1617
|
-
var _a, _b, _c, _d;
|
|
1638
|
+
var _a, _b, _c, _d, _e;
|
|
1618
1639
|
const warnings = [];
|
|
1619
1640
|
const options = (_a = await (0, import_provider_utils7.parseProviderOptions)({
|
|
1620
1641
|
provider: "xai",
|
|
@@ -1654,6 +1675,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
1654
1675
|
temperature,
|
|
1655
1676
|
top_p: topP,
|
|
1656
1677
|
seed,
|
|
1678
|
+
...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
|
|
1679
|
+
text: {
|
|
1680
|
+
format: responseFormat.schema != null ? {
|
|
1681
|
+
type: "json_schema",
|
|
1682
|
+
strict: true,
|
|
1683
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
1684
|
+
description: responseFormat.description,
|
|
1685
|
+
schema: responseFormat.schema
|
|
1686
|
+
} : { type: "json_object" }
|
|
1687
|
+
}
|
|
1688
|
+
},
|
|
1657
1689
|
...options.reasoningEffort != null && {
|
|
1658
1690
|
reasoning: { effort: options.reasoningEffort }
|
|
1659
1691
|
},
|
|
@@ -2110,7 +2142,7 @@ var xaiTools = {
|
|
|
2110
2142
|
};
|
|
2111
2143
|
|
|
2112
2144
|
// src/version.ts
|
|
2113
|
-
var VERSION = true ? "3.0.
|
|
2145
|
+
var VERSION = true ? "3.0.14" : "0.0.0-test";
|
|
2114
2146
|
|
|
2115
2147
|
// src/xai-provider.ts
|
|
2116
2148
|
var xaiErrorStructure = {
|