@ai-sdk/xai 3.0.113 → 3.0.115
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 +14 -0
- package/dist/index.js +50 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/xai-video-model.ts +68 -3
package/dist/index.mjs
CHANGED
|
@@ -2954,14 +2954,14 @@ var xaiTools = {
|
|
|
2954
2954
|
};
|
|
2955
2955
|
|
|
2956
2956
|
// src/version.ts
|
|
2957
|
-
var VERSION = true ? "3.0.
|
|
2957
|
+
var VERSION = true ? "3.0.115" : "0.0.0-test";
|
|
2958
2958
|
|
|
2959
2959
|
// src/xai-video-model.ts
|
|
2960
2960
|
import {
|
|
2961
|
-
AISDKError
|
|
2961
|
+
AISDKError,
|
|
2962
|
+
APICallError as APICallError2
|
|
2962
2963
|
} from "@ai-sdk/provider";
|
|
2963
2964
|
import {
|
|
2964
|
-
cancelResponseBody,
|
|
2965
2965
|
combineHeaders as combineHeaders4,
|
|
2966
2966
|
convertUint8ArrayToBase64,
|
|
2967
2967
|
createJsonResponseHandler as createJsonResponseHandler4,
|
|
@@ -2969,7 +2969,8 @@ import {
|
|
|
2969
2969
|
extractResponseHeaders as extractResponseHeaders2,
|
|
2970
2970
|
getFromApi as getFromApi2,
|
|
2971
2971
|
parseProviderOptions as parseProviderOptions6,
|
|
2972
|
-
postJsonToApi as postJsonToApi4
|
|
2972
|
+
postJsonToApi as postJsonToApi4,
|
|
2973
|
+
safeParseJSON as safeParseJSON2
|
|
2973
2974
|
} from "@ai-sdk/provider-utils";
|
|
2974
2975
|
import { z as z17 } from "zod/v4";
|
|
2975
2976
|
|
|
@@ -3390,13 +3391,60 @@ var xaiVideoStatusResponseSchema = z17.object({
|
|
|
3390
3391
|
var xaiVideoStatusJsonResponseHandler = createJsonResponseHandler4(
|
|
3391
3392
|
xaiVideoStatusResponseSchema
|
|
3392
3393
|
);
|
|
3394
|
+
var MAX_PENDING_BODY_BYTES = 1024 * 1024;
|
|
3395
|
+
var textDecoder = new TextDecoder();
|
|
3396
|
+
async function readPendingBody({
|
|
3397
|
+
response,
|
|
3398
|
+
url,
|
|
3399
|
+
requestBodyValues
|
|
3400
|
+
}) {
|
|
3401
|
+
if (response.body == null) {
|
|
3402
|
+
return "";
|
|
3403
|
+
}
|
|
3404
|
+
const reader = response.body.getReader();
|
|
3405
|
+
const chunks = [];
|
|
3406
|
+
let totalBytes = 0;
|
|
3407
|
+
try {
|
|
3408
|
+
while (true) {
|
|
3409
|
+
const { done, value } = await reader.read();
|
|
3410
|
+
if (done) break;
|
|
3411
|
+
totalBytes += value.length;
|
|
3412
|
+
if (totalBytes > MAX_PENDING_BODY_BYTES) {
|
|
3413
|
+
throw new APICallError2({
|
|
3414
|
+
message: `xAI video status response exceeded ${MAX_PENDING_BODY_BYTES} bytes`,
|
|
3415
|
+
url,
|
|
3416
|
+
requestBodyValues,
|
|
3417
|
+
statusCode: response.status,
|
|
3418
|
+
responseHeaders: extractResponseHeaders2(response)
|
|
3419
|
+
});
|
|
3420
|
+
}
|
|
3421
|
+
chunks.push(value);
|
|
3422
|
+
}
|
|
3423
|
+
} finally {
|
|
3424
|
+
reader.releaseLock();
|
|
3425
|
+
}
|
|
3426
|
+
const merged = new Uint8Array(totalBytes);
|
|
3427
|
+
let offset = 0;
|
|
3428
|
+
for (const chunk of chunks) {
|
|
3429
|
+
merged.set(chunk, offset);
|
|
3430
|
+
offset += chunk.length;
|
|
3431
|
+
}
|
|
3432
|
+
return textDecoder.decode(merged);
|
|
3433
|
+
}
|
|
3393
3434
|
var xaiVideoStatusResponseHandler = async (options) => {
|
|
3394
3435
|
if (options.response.status === 202) {
|
|
3395
3436
|
const responseHeaders = extractResponseHeaders2(options.response);
|
|
3396
|
-
await
|
|
3437
|
+
const text = await readPendingBody(options);
|
|
3438
|
+
if (text.trim().length === 0) {
|
|
3439
|
+
return { responseHeaders, value: { status: "pending" } };
|
|
3440
|
+
}
|
|
3441
|
+
const parsed = await safeParseJSON2({
|
|
3442
|
+
text,
|
|
3443
|
+
schema: xaiVideoStatusResponseSchema
|
|
3444
|
+
});
|
|
3397
3445
|
return {
|
|
3398
3446
|
responseHeaders,
|
|
3399
|
-
value: { status: "pending" }
|
|
3447
|
+
value: parsed.success ? parsed.value : { status: "pending" }
|
|
3400
3448
|
};
|
|
3401
3449
|
}
|
|
3402
3450
|
return xaiVideoStatusJsonResponseHandler(options);
|