@ai-sdk/xai 4.0.21 → 4.0.23

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 CHANGED
@@ -1,5 +1,24 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.23
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d8210b6]
8
+ - Updated dependencies [b192878]
9
+ - @ai-sdk/provider-utils@5.0.16
10
+ - @ai-sdk/openai-compatible@3.0.18
11
+
12
+ ## 4.0.22
13
+
14
+ ### Patch Changes
15
+
16
+ - 2b872b0: fix(xai): video generation no longer hangs while polling status
17
+ - Updated dependencies [1659cd5]
18
+ - Updated dependencies [6a5bdff]
19
+ - @ai-sdk/provider-utils@5.0.15
20
+ - @ai-sdk/openai-compatible@3.0.17
21
+
3
22
  ## 4.0.21
4
23
 
5
24
  ### Patch Changes
package/dist/index.js CHANGED
@@ -3510,7 +3510,7 @@ var xaiTools = {
3510
3510
  };
3511
3511
 
3512
3512
  // src/version.ts
3513
- var VERSION = true ? "4.0.21" : "0.0.0-test";
3513
+ var VERSION = true ? "4.0.23" : "0.0.0-test";
3514
3514
 
3515
3515
  // src/files/xai-files.ts
3516
3516
  import {
@@ -3615,10 +3615,10 @@ var XaiFiles = class {
3615
3615
 
3616
3616
  // src/xai-video-model.ts
3617
3617
  import {
3618
- AISDKError
3618
+ AISDKError,
3619
+ APICallError as APICallError2
3619
3620
  } from "@ai-sdk/provider";
3620
3621
  import {
3621
- cancelResponseBody,
3622
3622
  combineHeaders as combineHeaders5,
3623
3623
  convertUint8ArrayToBase64,
3624
3624
  createJsonResponseHandler as createJsonResponseHandler5,
@@ -3627,7 +3627,8 @@ import {
3627
3627
  getFromApi as getFromApi2,
3628
3628
  getTopLevelMediaType as getTopLevelMediaType3,
3629
3629
  parseProviderOptions as parseProviderOptions7,
3630
- postJsonToApi as postJsonToApi4
3630
+ postJsonToApi as postJsonToApi4,
3631
+ safeParseJSON as safeParseJSON2
3631
3632
  } from "@ai-sdk/provider-utils";
3632
3633
  import { z as z19 } from "zod/v4";
3633
3634
 
@@ -4045,13 +4046,60 @@ var xaiVideoStatusResponseSchema = z19.object({
4045
4046
  var xaiVideoStatusJsonResponseHandler = createJsonResponseHandler5(
4046
4047
  xaiVideoStatusResponseSchema
4047
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
+ }
4048
4089
  var xaiVideoStatusResponseHandler = async (options) => {
4049
4090
  if (options.response.status === 202) {
4050
4091
  const responseHeaders = extractResponseHeaders2(options.response);
4051
- await cancelResponseBody(options.response);
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
+ });
4052
4100
  return {
4053
4101
  responseHeaders,
4054
- value: { status: "pending" }
4102
+ value: parsed.success ? parsed.value : { status: "pending" }
4055
4103
  };
4056
4104
  }
4057
4105
  return xaiVideoStatusJsonResponseHandler(options);
@@ -4238,7 +4286,7 @@ import {
4238
4286
  mediaTypeToExtension,
4239
4287
  parseProviderOptions as parseProviderOptions9,
4240
4288
  postFormDataToApi as postFormDataToApi2,
4241
- safeParseJSON as safeParseJSON2,
4289
+ safeParseJSON as safeParseJSON3,
4242
4290
  serializeModelOptions as serializeModelOptions5,
4243
4291
  toWebSocketUrl,
4244
4292
  waitForWebSocketBufferDrain,
@@ -4556,7 +4604,7 @@ function createXaiStreamingTranscriptionStream({
4556
4604
  onProcessingError: finishWithError,
4557
4605
  onMessageText: async (text) => {
4558
4606
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4559
- const parsed = await safeParseJSON2({ text });
4607
+ const parsed = await safeParseJSON3({ text });
4560
4608
  if (!parsed.success) return;
4561
4609
  const raw = parsed.value;
4562
4610
  if (includeRawChunks) {