@ai-sdk/xai 4.0.20 → 4.0.22
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 +16 -0
- package/dist/index.js +68 -8
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +19 -14
- package/package.json +3 -3
- package/src/responses/xai-responses-language-model.ts +15 -0
- package/src/xai-video-model.ts +68 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 4.0.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2b872b0: fix(xai): video generation no longer hangs while polling status
|
|
8
|
+
- Updated dependencies [1659cd5]
|
|
9
|
+
- Updated dependencies [6a5bdff]
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.15
|
|
11
|
+
- @ai-sdk/openai-compatible@3.0.17
|
|
12
|
+
|
|
13
|
+
## 4.0.21
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- dc2f851: Warn when xAI Responses models ignore unsupported sampling settings.
|
|
18
|
+
|
|
3
19
|
## 4.0.20
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -2310,6 +2310,9 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2310
2310
|
maxOutputTokens,
|
|
2311
2311
|
temperature,
|
|
2312
2312
|
topP,
|
|
2313
|
+
topK,
|
|
2314
|
+
frequencyPenalty,
|
|
2315
|
+
presencePenalty,
|
|
2313
2316
|
stopSequences,
|
|
2314
2317
|
seed,
|
|
2315
2318
|
responseFormat,
|
|
@@ -2325,6 +2328,15 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2325
2328
|
providerOptions,
|
|
2326
2329
|
schema: xaiLanguageModelResponsesOptions
|
|
2327
2330
|
})) != null ? _a : {};
|
|
2331
|
+
if (topK != null) {
|
|
2332
|
+
warnings.push({ type: "unsupported", feature: "topK" });
|
|
2333
|
+
}
|
|
2334
|
+
if (frequencyPenalty != null) {
|
|
2335
|
+
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
2336
|
+
}
|
|
2337
|
+
if (presencePenalty != null) {
|
|
2338
|
+
warnings.push({ type: "unsupported", feature: "presencePenalty" });
|
|
2339
|
+
}
|
|
2328
2340
|
if (stopSequences != null) {
|
|
2329
2341
|
warnings.push({ type: "unsupported", feature: "stopSequences" });
|
|
2330
2342
|
}
|
|
@@ -3498,7 +3510,7 @@ var xaiTools = {
|
|
|
3498
3510
|
};
|
|
3499
3511
|
|
|
3500
3512
|
// src/version.ts
|
|
3501
|
-
var VERSION = true ? "4.0.
|
|
3513
|
+
var VERSION = true ? "4.0.22" : "0.0.0-test";
|
|
3502
3514
|
|
|
3503
3515
|
// src/files/xai-files.ts
|
|
3504
3516
|
import {
|
|
@@ -3603,10 +3615,10 @@ var XaiFiles = class {
|
|
|
3603
3615
|
|
|
3604
3616
|
// src/xai-video-model.ts
|
|
3605
3617
|
import {
|
|
3606
|
-
AISDKError
|
|
3618
|
+
AISDKError,
|
|
3619
|
+
APICallError as APICallError2
|
|
3607
3620
|
} from "@ai-sdk/provider";
|
|
3608
3621
|
import {
|
|
3609
|
-
cancelResponseBody,
|
|
3610
3622
|
combineHeaders as combineHeaders5,
|
|
3611
3623
|
convertUint8ArrayToBase64,
|
|
3612
3624
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
@@ -3615,7 +3627,8 @@ import {
|
|
|
3615
3627
|
getFromApi as getFromApi2,
|
|
3616
3628
|
getTopLevelMediaType as getTopLevelMediaType3,
|
|
3617
3629
|
parseProviderOptions as parseProviderOptions7,
|
|
3618
|
-
postJsonToApi as postJsonToApi4
|
|
3630
|
+
postJsonToApi as postJsonToApi4,
|
|
3631
|
+
safeParseJSON as safeParseJSON2
|
|
3619
3632
|
} from "@ai-sdk/provider-utils";
|
|
3620
3633
|
import { z as z19 } from "zod/v4";
|
|
3621
3634
|
|
|
@@ -4033,13 +4046,60 @@ var xaiVideoStatusResponseSchema = z19.object({
|
|
|
4033
4046
|
var xaiVideoStatusJsonResponseHandler = createJsonResponseHandler5(
|
|
4034
4047
|
xaiVideoStatusResponseSchema
|
|
4035
4048
|
);
|
|
4049
|
+
var MAX_PENDING_BODY_BYTES = 1024 * 1024;
|
|
4050
|
+
var textDecoder = new TextDecoder();
|
|
4051
|
+
async function readPendingBody({
|
|
4052
|
+
response,
|
|
4053
|
+
url,
|
|
4054
|
+
requestBodyValues
|
|
4055
|
+
}) {
|
|
4056
|
+
if (response.body == null) {
|
|
4057
|
+
return "";
|
|
4058
|
+
}
|
|
4059
|
+
const reader = response.body.getReader();
|
|
4060
|
+
const chunks = [];
|
|
4061
|
+
let totalBytes = 0;
|
|
4062
|
+
try {
|
|
4063
|
+
while (true) {
|
|
4064
|
+
const { done, value } = await reader.read();
|
|
4065
|
+
if (done) break;
|
|
4066
|
+
totalBytes += value.length;
|
|
4067
|
+
if (totalBytes > MAX_PENDING_BODY_BYTES) {
|
|
4068
|
+
throw new APICallError2({
|
|
4069
|
+
message: `xAI video status response exceeded ${MAX_PENDING_BODY_BYTES} bytes`,
|
|
4070
|
+
url,
|
|
4071
|
+
requestBodyValues,
|
|
4072
|
+
statusCode: response.status,
|
|
4073
|
+
responseHeaders: extractResponseHeaders2(response)
|
|
4074
|
+
});
|
|
4075
|
+
}
|
|
4076
|
+
chunks.push(value);
|
|
4077
|
+
}
|
|
4078
|
+
} finally {
|
|
4079
|
+
reader.releaseLock();
|
|
4080
|
+
}
|
|
4081
|
+
const merged = new Uint8Array(totalBytes);
|
|
4082
|
+
let offset = 0;
|
|
4083
|
+
for (const chunk of chunks) {
|
|
4084
|
+
merged.set(chunk, offset);
|
|
4085
|
+
offset += chunk.length;
|
|
4086
|
+
}
|
|
4087
|
+
return textDecoder.decode(merged);
|
|
4088
|
+
}
|
|
4036
4089
|
var xaiVideoStatusResponseHandler = async (options) => {
|
|
4037
4090
|
if (options.response.status === 202) {
|
|
4038
4091
|
const responseHeaders = extractResponseHeaders2(options.response);
|
|
4039
|
-
await
|
|
4092
|
+
const text = await readPendingBody(options);
|
|
4093
|
+
if (text.trim().length === 0) {
|
|
4094
|
+
return { responseHeaders, value: { status: "pending" } };
|
|
4095
|
+
}
|
|
4096
|
+
const parsed = await safeParseJSON2({
|
|
4097
|
+
text,
|
|
4098
|
+
schema: xaiVideoStatusResponseSchema
|
|
4099
|
+
});
|
|
4040
4100
|
return {
|
|
4041
4101
|
responseHeaders,
|
|
4042
|
-
value: { status: "pending" }
|
|
4102
|
+
value: parsed.success ? parsed.value : { status: "pending" }
|
|
4043
4103
|
};
|
|
4044
4104
|
}
|
|
4045
4105
|
return xaiVideoStatusJsonResponseHandler(options);
|
|
@@ -4226,7 +4286,7 @@ import {
|
|
|
4226
4286
|
mediaTypeToExtension,
|
|
4227
4287
|
parseProviderOptions as parseProviderOptions9,
|
|
4228
4288
|
postFormDataToApi as postFormDataToApi2,
|
|
4229
|
-
safeParseJSON as
|
|
4289
|
+
safeParseJSON as safeParseJSON3,
|
|
4230
4290
|
serializeModelOptions as serializeModelOptions5,
|
|
4231
4291
|
toWebSocketUrl,
|
|
4232
4292
|
waitForWebSocketBufferDrain,
|
|
@@ -4544,7 +4604,7 @@ function createXaiStreamingTranscriptionStream({
|
|
|
4544
4604
|
onProcessingError: finishWithError,
|
|
4545
4605
|
onMessageText: async (text) => {
|
|
4546
4606
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4547
|
-
const parsed = await
|
|
4607
|
+
const parsed = await safeParseJSON3({ text });
|
|
4548
4608
|
if (!parsed.success) return;
|
|
4549
4609
|
const raw = parsed.value;
|
|
4550
4610
|
if (includeRawChunks) {
|