@ai-sdk/xai 4.0.34 → 4.0.36

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,19 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.36
4
+
5
+ ### Patch Changes
6
+
7
+ - 8edc775: feat (provider/xai): support Grok Imagine Video 1.5. Adds the `grok-imagine-video-1.5` model id and native `1080p` for text-to-video and image-to-video (the standard `resolution: '1920x1080'` now maps to `1080p`). Reference-to-video remains capped at `720p`, so a `1080p` request in that mode is downgraded with a warning. Also fixes reference routing: previously any non-empty `inputReferences` array selected reference-to-video, so an array holding only a non-image reference sent `reference_images: []` with no usable references.
8
+ - 3d05053: feat (provider/xai): add `referenceVoiceIds` for reference-to-video reference audio. Pass up to 3 xAI preset voice ids (e.g. `['eve']`) and reference them from the prompt with `<AUDIO_0>`–`<AUDIO_2>`; they are sent as `reference_audios: [{ voice_id }]` on `POST /v1/videos/generations`.
9
+
10
+ ## 4.0.35
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [7fbfc6d]
15
+ - @ai-sdk/provider-utils@5.0.27
16
+
3
17
  ## 4.0.34
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -115,11 +115,12 @@ declare const xaiImageModelOptions: z.ZodObject<{
115
115
  }, z.core.$strip>;
116
116
  type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
117
117
 
118
- type XaiVideoModelId = 'grok-imagine-video' | (string & {});
118
+ type XaiVideoModelId = 'grok-imagine-video' | 'grok-imagine-video-1.5' | (string & {});
119
119
 
120
120
  declare const resolutionSchema: z.ZodEnum<{
121
121
  "480p": "480p";
122
122
  "720p": "720p";
123
+ "1080p": "1080p";
123
124
  }>;
124
125
  type XaiVideoResolution = z.infer<typeof resolutionSchema>;
125
126
  interface XaiVideoSharedOptions {
@@ -156,6 +157,10 @@ interface XaiVideoReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVide
156
157
  mode: 'reference-to-video';
157
158
  /** Reference image URLs (1-7) for R2V generation. */
158
159
  referenceImageUrls: string[];
160
+ /**
161
+ * Preset voice ids (up to 3) that give the subject a voice.
162
+ */
163
+ referenceVoiceIds?: string[];
159
164
  }
160
165
  interface XaiVideoGenerationOptions extends XaiVideoSharedOptions, XaiVideoUserOptions {
161
166
  mode?: undefined;
@@ -177,6 +182,10 @@ interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVid
177
182
  */
178
183
  mode?: undefined;
179
184
  referenceImageUrls: string[];
185
+ /**
186
+ * Preset voice ids (up to 3) that give the subject a voice.
187
+ */
188
+ referenceVoiceIds?: string[];
180
189
  }
181
190
  /**
182
191
  * Provider options for xAI video generation.
package/dist/index.js CHANGED
@@ -3687,7 +3687,7 @@ var xaiTools = {
3687
3687
  };
3688
3688
 
3689
3689
  // src/version.ts
3690
- var VERSION = true ? "4.0.34" : "0.0.0-test";
3690
+ var VERSION = true ? "4.0.36" : "0.0.0-test";
3691
3691
 
3692
3692
  // src/files/xai-files.ts
3693
3693
  import {
@@ -3812,53 +3812,18 @@ import { z as z20 } from "zod/v4";
3812
3812
  import { lazySchema as lazySchema8, zodSchema as zodSchema8 } from "@ai-sdk/provider-utils";
3813
3813
  import { z as z19 } from "zod/v4";
3814
3814
  var nonEmptyStringSchema = z19.string().min(1);
3815
- var resolutionSchema = z19.enum(["480p", "720p"]);
3815
+ var resolutionSchema = z19.enum(["480p", "720p", "1080p"]);
3816
3816
  var modeSchema = z19.enum(["edit-video", "extend-video", "reference-to-video"]);
3817
3817
  var baseFields = {
3818
3818
  pollIntervalMs: z19.number().positive().nullish(),
3819
3819
  pollTimeoutMs: z19.number().positive().nullish(),
3820
3820
  resolution: resolutionSchema.nullish()
3821
3821
  };
3822
- var userField = {
3823
- user: z19.string().optional()
3824
- };
3825
- var editVideoSchema = z19.object({
3826
- ...baseFields,
3827
- ...userField,
3828
- mode: z19.literal("edit-video"),
3829
- videoUrl: nonEmptyStringSchema,
3830
- referenceImageUrls: z19.undefined().optional()
3831
- });
3832
- var extendVideoSchema = z19.object({
3833
- ...baseFields,
3834
- mode: z19.literal("extend-video"),
3835
- videoUrl: nonEmptyStringSchema,
3836
- referenceImageUrls: z19.undefined().optional()
3837
- });
3838
- var referenceToVideoSchema = z19.object({
3839
- ...baseFields,
3840
- ...userField,
3841
- mode: z19.literal("reference-to-video"),
3842
- referenceImageUrls: z19.array(nonEmptyStringSchema).min(1).max(7),
3843
- videoUrl: z19.undefined().optional()
3844
- });
3845
- var autoDetectSchema = z19.object({
3846
- ...baseFields,
3847
- ...userField,
3848
- mode: z19.undefined().optional(),
3849
- videoUrl: nonEmptyStringSchema.optional(),
3850
- referenceImageUrls: z19.array(nonEmptyStringSchema).min(1).max(7).optional()
3851
- });
3852
- var xaiVideoModelOptions = z19.union([
3853
- editVideoSchema,
3854
- extendVideoSchema,
3855
- referenceToVideoSchema,
3856
- autoDetectSchema
3857
- ]);
3858
3822
  var runtimeSchema = z19.looseObject({
3859
3823
  mode: modeSchema.optional(),
3860
3824
  videoUrl: nonEmptyStringSchema.optional(),
3861
3825
  referenceImageUrls: z19.array(nonEmptyStringSchema).min(1).max(7).optional(),
3826
+ referenceVoiceIds: z19.array(nonEmptyStringSchema).max(3).optional(),
3862
3827
  user: z19.string().optional(),
3863
3828
  ...baseFields
3864
3829
  });
@@ -3868,6 +3833,7 @@ var xaiVideoModelOptionsSchema = lazySchema8(
3868
3833
 
3869
3834
  // src/xai-video-model.ts
3870
3835
  var RESOLUTION_MAP = {
3836
+ "1920x1080": "1080p",
3871
3837
  "1280x720": "720p",
3872
3838
  "854x480": "480p",
3873
3839
  "640x480": "480p"
@@ -3885,35 +3851,39 @@ function resolveStartImage(options) {
3885
3851
  return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
3886
3852
  }
3887
3853
  var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType3(file.mediaType) === "video";
3888
- function fileToXaiImageUrl(file) {
3854
+ var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType3(file.mediaType) === "image";
3855
+ function fileToXaiUrl(file) {
3889
3856
  if (file.type === "url") {
3890
3857
  return file.url;
3891
3858
  }
3892
3859
  const base64Data = typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data);
3893
3860
  return `data:${file.mediaType};base64,${base64Data}`;
3894
3861
  }
3895
- function resolveReferenceImages(options, xaiOptions, warnings) {
3862
+ function resolveReferences(options, xaiOptions, warnings) {
3896
3863
  if (options.inputReferences != null && options.inputReferences.length > 0) {
3897
- const imageReferences = options.inputReferences.filter((reference) => {
3898
- if (isVideoFile(reference)) {
3864
+ const imageFiles = [];
3865
+ for (const reference of options.inputReferences) {
3866
+ if (!isImageReference(reference)) {
3899
3867
  warnings.push({
3900
3868
  type: "unsupported",
3901
3869
  feature: "inputReferences",
3902
- details: 'xAI reference-to-video accepts image references only. The video reference was ignored. Use providerOptions.xai.mode "extend-video" to continue from a video.'
3870
+ details: isVideoFile(reference) ? 'xAI reference-to-video accepts image references only. The video reference was ignored. Use providerOptions.xai.mode "extend-video" to continue from a video.' : "xAI reference-to-video accepts image references only. The non-image reference was ignored."
3903
3871
  });
3904
- return false;
3872
+ continue;
3905
3873
  }
3906
- return true;
3907
- });
3908
- return imageReferences.map((reference) => ({
3909
- url: fileToXaiImageUrl(reference)
3910
- }));
3874
+ imageFiles.push(reference);
3875
+ }
3876
+ return imageFiles.length > 0 ? imageFiles.map((reference) => ({ url: fileToXaiUrl(reference) })) : void 0;
3911
3877
  }
3912
3878
  if ((xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0) {
3913
3879
  return xaiOptions.referenceImageUrls.map((url) => ({ url }));
3914
3880
  }
3915
3881
  return void 0;
3916
3882
  }
3883
+ function hasImageInputReference(options) {
3884
+ var _a, _b;
3885
+ return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isImageReference)) != null ? _b : false;
3886
+ }
3917
3887
  function resolveVideoMode(options, xaiOptions) {
3918
3888
  if ((xaiOptions == null ? void 0 : xaiOptions.mode) != null) {
3919
3889
  return xaiOptions.mode;
@@ -3922,9 +3892,8 @@ function resolveVideoMode(options, xaiOptions) {
3922
3892
  return "edit-video";
3923
3893
  }
3924
3894
  const hasFrameImages = options.frameImages != null && options.frameImages.length > 0;
3925
- const hasInputReferences = options.inputReferences != null && options.inputReferences.length > 0;
3926
3895
  const hasLegacyReferenceUrls = (xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0;
3927
- if (!hasFrameImages && (hasInputReferences || hasLegacyReferenceUrls)) {
3896
+ if (!hasFrameImages && (hasImageInputReference(options) || hasLegacyReferenceUrls)) {
3928
3897
  return "reference-to-video";
3929
3898
  }
3930
3899
  return void 0;
@@ -4029,7 +3998,7 @@ var XaiVideoModel = class {
4029
3998
  warnings.push({
4030
3999
  type: "unsupported",
4031
4000
  feature: "resolution",
4032
- details: `Unrecognized resolution "${options.resolution}". Use providerOptions.xai.resolution with "480p" or "720p" instead.`
4001
+ details: `Unrecognized resolution "${options.resolution}". Use providerOptions.xai.resolution with "480p", "720p", or "1080p" instead.`
4033
4002
  });
4034
4003
  }
4035
4004
  }
@@ -4049,7 +4018,7 @@ var XaiVideoModel = class {
4049
4018
  details: 'xAI does not accept a video as a start/frame image. The video was ignored. Use providerOptions.xai.mode "extend-video" to continue from a video instead.'
4050
4019
  });
4051
4020
  } else {
4052
- body.image = { url: fileToXaiImageUrl(startImage) };
4021
+ body.image = { url: fileToXaiUrl(startImage) };
4053
4022
  }
4054
4023
  }
4055
4024
  const lastFrameImage = getLastFrameImage(options);
@@ -4061,20 +4030,50 @@ var XaiVideoModel = class {
4061
4030
  });
4062
4031
  }
4063
4032
  if (hasReferenceImages) {
4064
- const referenceImages = resolveReferenceImages(
4065
- options,
4066
- xaiOptions,
4067
- warnings
4068
- );
4033
+ const referenceImages = resolveReferences(options, xaiOptions, warnings);
4069
4034
  if (referenceImages != null) {
4070
4035
  body.reference_images = referenceImages;
4036
+ } else {
4037
+ warnings.push({
4038
+ type: "unsupported",
4039
+ feature: "referenceImages",
4040
+ details: "xAI reference-to-video requires at least one image reference. The video will be generated without reference images."
4041
+ });
4042
+ }
4043
+ const referenceVoiceIds = xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds;
4044
+ if (referenceVoiceIds != null && referenceVoiceIds.length > 0) {
4045
+ body.reference_audios = referenceVoiceIds.map((voiceId) => ({
4046
+ voice_id: voiceId
4047
+ }));
4048
+ }
4049
+ if (body.resolution === "1080p") {
4050
+ warnings.push({
4051
+ type: "unsupported",
4052
+ feature: "resolution",
4053
+ details: "xAI reference-to-video is limited to 720p. The request was downgraded from 1080p to 720p."
4054
+ });
4055
+ body.resolution = "720p";
4071
4056
  }
4072
4057
  }
4058
+ if (body.resolution === "1080p" && this.modelId === "grok-imagine-video") {
4059
+ warnings.push({
4060
+ type: "unsupported",
4061
+ feature: "resolution",
4062
+ details: 'xAI model "grok-imagine-video" does not support 1080p. Use "grok-imagine-video-1.5" for 1080p, or a lower resolution. The request was sent with 1080p.'
4063
+ });
4064
+ }
4073
4065
  if (options.inputReferences != null && options.inputReferences.length > 0 && !hasReferenceImages) {
4074
4066
  warnings.push({
4075
4067
  type: "unsupported",
4076
4068
  feature: "inputReferences",
4077
- details: "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored."
4069
+ details: hasImageInputReference(options) ? "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored." : "xAI reference-to-video requires at least one image reference. The references were ignored."
4070
+ });
4071
+ }
4072
+ if ((xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds) != null && xaiOptions.referenceVoiceIds.length > 0 && !hasReferenceImages) {
4073
+ warnings.push({
4074
+ type: "unsupported",
4075
+ feature: "referenceVoiceIds",
4076
+ details: "xAI only supports reference voices for reference-to-video generation. The reference voices were ignored."
4078
4077
  });
4079
4078
  }
4080
4079
  if (!isExtension && (xaiOptions == null ? void 0 : xaiOptions.user) !== void 0) {
@@ -4089,6 +4088,7 @@ var XaiVideoModel = class {
4089
4088
  "resolution",
4090
4089
  "videoUrl",
4091
4090
  "referenceImageUrls",
4091
+ "referenceVoiceIds",
4092
4092
  "user"
4093
4093
  ].includes(key)) {
4094
4094
  body[key] = value;