@ai-sdk/xai 4.0.50 → 4.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 +6 -0
- package/dist/index.js +49 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/responses/xai-responses-batch.ts +51 -28
- package/src/xai-chat-language-model.ts +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -990,7 +990,7 @@ var xaiChatResponseSchema = z4.object({
|
|
|
990
990
|
choices: z4.array(
|
|
991
991
|
z4.object({
|
|
992
992
|
message: z4.object({
|
|
993
|
-
role: z4.
|
|
993
|
+
role: z4.enum(["assistant", "tool"]),
|
|
994
994
|
content: z4.string().nullish(),
|
|
995
995
|
reasoning_content: z4.string().nullish(),
|
|
996
996
|
tool_calls: z4.array(
|
|
@@ -3808,8 +3808,8 @@ function convertXaiChatBatchResponse(response) {
|
|
|
3808
3808
|
}
|
|
3809
3809
|
};
|
|
3810
3810
|
}
|
|
3811
|
-
const
|
|
3812
|
-
if (
|
|
3811
|
+
const choices = response.choices;
|
|
3812
|
+
if (choices == null || choices.length === 0) {
|
|
3813
3813
|
return {
|
|
3814
3814
|
success: false,
|
|
3815
3815
|
error: {
|
|
@@ -3818,18 +3818,50 @@ function convertXaiChatBatchResponse(response) {
|
|
|
3818
3818
|
}
|
|
3819
3819
|
};
|
|
3820
3820
|
}
|
|
3821
|
-
if ((_b = choice.message.tool_calls) == null ? void 0 : _b.length) {
|
|
3822
|
-
return unsupportedXaiBatchContent("tool_calls");
|
|
3823
|
-
}
|
|
3824
3821
|
const content = [];
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3822
|
+
const providerExecutedToolCallIds = new Set(
|
|
3823
|
+
choices.filter((choice) => choice.message.role === "tool").flatMap(
|
|
3824
|
+
(choice) => {
|
|
3825
|
+
var _a2;
|
|
3826
|
+
return ((_a2 = choice.message.tool_calls) != null ? _a2 : []).map((toolCall) => toolCall.id);
|
|
3827
|
+
}
|
|
3828
|
+
)
|
|
3829
|
+
);
|
|
3830
|
+
let lastAssistantChoice;
|
|
3831
|
+
for (const choice of choices) {
|
|
3832
|
+
if (choice.message.role === "tool") {
|
|
3833
|
+
if (choice.message.content != null) {
|
|
3834
|
+
for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
|
|
3835
|
+
content.push({
|
|
3836
|
+
type: "tool-result",
|
|
3837
|
+
toolCallId: toolCall.id,
|
|
3838
|
+
toolName: toolCall.function.name,
|
|
3839
|
+
result: choice.message.content,
|
|
3840
|
+
dynamic: true
|
|
3841
|
+
});
|
|
3842
|
+
}
|
|
3843
|
+
}
|
|
3844
|
+
continue;
|
|
3845
|
+
}
|
|
3846
|
+
lastAssistantChoice = choice;
|
|
3847
|
+
if (choice.message.content) {
|
|
3848
|
+
content.push({ type: "text", text: choice.message.content });
|
|
3849
|
+
}
|
|
3850
|
+
if (choice.message.reasoning_content) {
|
|
3851
|
+
content.push({
|
|
3852
|
+
type: "reasoning",
|
|
3853
|
+
text: choice.message.reasoning_content
|
|
3854
|
+
});
|
|
3855
|
+
}
|
|
3856
|
+
for (const toolCall of (_b = choice.message.tool_calls) != null ? _b : []) {
|
|
3857
|
+
content.push({
|
|
3858
|
+
type: "tool-call",
|
|
3859
|
+
toolCallId: toolCall.id,
|
|
3860
|
+
toolName: toolCall.function.name,
|
|
3861
|
+
input: toolCall.function.arguments,
|
|
3862
|
+
...providerExecutedToolCallIds.has(toolCall.id) ? { providerExecuted: true, dynamic: true } : {}
|
|
3863
|
+
});
|
|
3864
|
+
}
|
|
3833
3865
|
}
|
|
3834
3866
|
for (const url of (_c = response.citations) != null ? _c : []) {
|
|
3835
3867
|
content.push({
|
|
@@ -3844,8 +3876,8 @@ function convertXaiChatBatchResponse(response) {
|
|
|
3844
3876
|
result: {
|
|
3845
3877
|
content,
|
|
3846
3878
|
finishReason: {
|
|
3847
|
-
unified: mapXaiFinishReason(
|
|
3848
|
-
raw: (_d =
|
|
3879
|
+
unified: mapXaiFinishReason(lastAssistantChoice == null ? void 0 : lastAssistantChoice.finish_reason),
|
|
3880
|
+
raw: (_d = lastAssistantChoice == null ? void 0 : lastAssistantChoice.finish_reason) != null ? _d : void 0
|
|
3849
3881
|
},
|
|
3850
3882
|
usage: response.usage ? convertXaiChatUsage(response.usage) : createNullLanguageModelUsage(),
|
|
3851
3883
|
response: getResponseMetadata(response),
|
|
@@ -3861,15 +3893,6 @@ function convertXaiChatBatchResponse(response) {
|
|
|
3861
3893
|
}
|
|
3862
3894
|
};
|
|
3863
3895
|
}
|
|
3864
|
-
function unsupportedXaiBatchContent(type) {
|
|
3865
|
-
return {
|
|
3866
|
-
success: false,
|
|
3867
|
-
error: {
|
|
3868
|
-
message: `xAI returned "${type}" content, but tool content is not supported in AI SDK text batches.`,
|
|
3869
|
-
code: "unsupported_content"
|
|
3870
|
-
}
|
|
3871
|
-
};
|
|
3872
|
-
}
|
|
3873
3896
|
|
|
3874
3897
|
// src/realtime/xai-realtime-event-mapper.ts
|
|
3875
3898
|
function parseXaiRealtimeServerEvent(raw) {
|
|
@@ -4296,7 +4319,7 @@ var xaiTools = {
|
|
|
4296
4319
|
};
|
|
4297
4320
|
|
|
4298
4321
|
// src/version.ts
|
|
4299
|
-
var VERSION = true ? "4.0.
|
|
4322
|
+
var VERSION = true ? "4.0.51" : "0.0.0-test";
|
|
4300
4323
|
|
|
4301
4324
|
// src/files/xai-files.ts
|
|
4302
4325
|
import {
|