@ai-sdk/xai 3.0.120 → 3.0.122

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/dist/index.mjs CHANGED
@@ -2988,7 +2988,7 @@ var xaiTools = {
2988
2988
  };
2989
2989
 
2990
2990
  // src/version.ts
2991
- var VERSION = true ? "3.0.120" : "0.0.0-test";
2991
+ var VERSION = true ? "3.0.122" : "0.0.0-test";
2992
2992
 
2993
2993
  // src/xai-video-model.ts
2994
2994
  import {
@@ -3012,7 +3012,7 @@ import { z as z17 } from "zod/v4";
3012
3012
  import { lazySchema as lazySchema5, zodSchema as zodSchema5 } from "@ai-sdk/provider-utils";
3013
3013
  import { z as z16 } from "zod/v4";
3014
3014
  var nonEmptyStringSchema = z16.string().min(1);
3015
- var resolutionSchema = z16.enum(["480p", "720p"]);
3015
+ var resolutionSchema = z16.enum(["480p", "720p", "1080p"]);
3016
3016
  var modeSchema = z16.enum(["edit-video", "extend-video", "reference-to-video"]);
3017
3017
  var baseFields = {
3018
3018
  pollIntervalMs: z16.number().positive().nullish(),
@@ -3022,22 +3022,28 @@ var baseFields = {
3022
3022
  var userField = {
3023
3023
  user: z16.string().optional()
3024
3024
  };
3025
+ var referenceVoiceIdsField = {
3026
+ referenceVoiceIds: z16.array(nonEmptyStringSchema).max(3).optional()
3027
+ };
3025
3028
  var editVideoSchema = z16.object({
3026
3029
  ...baseFields,
3027
3030
  ...userField,
3028
3031
  mode: z16.literal("edit-video"),
3029
3032
  videoUrl: nonEmptyStringSchema,
3030
- referenceImageUrls: z16.undefined().optional()
3033
+ referenceImageUrls: z16.undefined().optional(),
3034
+ referenceVoiceIds: z16.undefined().optional()
3031
3035
  });
3032
3036
  var extendVideoSchema = z16.object({
3033
3037
  ...baseFields,
3034
3038
  mode: z16.literal("extend-video"),
3035
3039
  videoUrl: nonEmptyStringSchema,
3036
- referenceImageUrls: z16.undefined().optional()
3040
+ referenceImageUrls: z16.undefined().optional(),
3041
+ referenceVoiceIds: z16.undefined().optional()
3037
3042
  });
3038
3043
  var referenceToVideoSchema = z16.object({
3039
3044
  ...baseFields,
3040
3045
  ...userField,
3046
+ ...referenceVoiceIdsField,
3041
3047
  mode: z16.literal("reference-to-video"),
3042
3048
  referenceImageUrls: z16.array(nonEmptyStringSchema).min(1).max(7),
3043
3049
  videoUrl: z16.undefined().optional()
@@ -3045,6 +3051,7 @@ var referenceToVideoSchema = z16.object({
3045
3051
  var autoDetectSchema = z16.object({
3046
3052
  ...baseFields,
3047
3053
  ...userField,
3054
+ ...referenceVoiceIdsField,
3048
3055
  mode: z16.undefined().optional(),
3049
3056
  videoUrl: nonEmptyStringSchema.optional(),
3050
3057
  referenceImageUrls: z16.array(nonEmptyStringSchema).min(1).max(7).optional()
@@ -3059,6 +3066,7 @@ var runtimeSchema = z16.object({
3059
3066
  mode: modeSchema.optional(),
3060
3067
  videoUrl: nonEmptyStringSchema.optional(),
3061
3068
  referenceImageUrls: z16.array(nonEmptyStringSchema).min(1).max(7).optional(),
3069
+ referenceVoiceIds: z16.array(nonEmptyStringSchema).max(3).optional(),
3062
3070
  user: z16.string().optional(),
3063
3071
  ...baseFields
3064
3072
  }).passthrough();
@@ -3068,6 +3076,7 @@ var xaiVideoModelOptionsSchema = lazySchema5(
3068
3076
 
3069
3077
  // src/xai-video-model.ts
3070
3078
  var RESOLUTION_MAP = {
3079
+ "1920x1080": "1080p",
3071
3080
  "1280x720": "720p",
3072
3081
  "854x480": "480p",
3073
3082
  "640x480": "480p"
@@ -3089,6 +3098,7 @@ function getTopLevelMediaType(mediaType) {
3089
3098
  return slashIndex === -1 ? mediaType : mediaType.substring(0, slashIndex);
3090
3099
  }
3091
3100
  var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType(file.mediaType) === "video";
3101
+ var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType(file.mediaType) === "image";
3092
3102
  function fileToXaiImageUrl(file) {
3093
3103
  if (file.type === "url") {
3094
3104
  return file.url;
@@ -3098,26 +3108,29 @@ function fileToXaiImageUrl(file) {
3098
3108
  }
3099
3109
  function resolveReferenceImages(options, xaiOptions, warnings) {
3100
3110
  if (options.inputReferences != null && options.inputReferences.length > 0) {
3101
- const imageReferences = options.inputReferences.filter((reference) => {
3102
- if (isVideoFile(reference)) {
3111
+ const imageFiles = [];
3112
+ for (const reference of options.inputReferences) {
3113
+ if (!isImageReference(reference)) {
3103
3114
  warnings.push({
3104
3115
  type: "unsupported",
3105
3116
  feature: "inputReferences",
3106
- 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.'
3117
+ 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."
3107
3118
  });
3108
- return false;
3119
+ continue;
3109
3120
  }
3110
- return true;
3111
- });
3112
- return imageReferences.map((reference) => ({
3113
- url: fileToXaiImageUrl(reference)
3114
- }));
3121
+ imageFiles.push(reference);
3122
+ }
3123
+ return imageFiles.length > 0 ? imageFiles.map((reference) => ({ url: fileToXaiImageUrl(reference) })) : void 0;
3115
3124
  }
3116
3125
  if ((xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0) {
3117
3126
  return xaiOptions.referenceImageUrls.map((url) => ({ url }));
3118
3127
  }
3119
3128
  return void 0;
3120
3129
  }
3130
+ function hasImageInputReference(options) {
3131
+ var _a, _b;
3132
+ return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isImageReference)) != null ? _b : false;
3133
+ }
3121
3134
  function resolveVideoMode(options, xaiOptions) {
3122
3135
  if ((xaiOptions == null ? void 0 : xaiOptions.mode) != null) {
3123
3136
  return xaiOptions.mode;
@@ -3126,9 +3139,8 @@ function resolveVideoMode(options, xaiOptions) {
3126
3139
  return "edit-video";
3127
3140
  }
3128
3141
  const hasFrameImages = options.frameImages != null && options.frameImages.length > 0;
3129
- const hasInputReferences = options.inputReferences != null && options.inputReferences.length > 0;
3130
3142
  const hasLegacyReferenceUrls = (xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0;
3131
- if (!hasFrameImages && (hasInputReferences || hasLegacyReferenceUrls)) {
3143
+ if (!hasFrameImages && (hasImageInputReference(options) || hasLegacyReferenceUrls)) {
3132
3144
  return "reference-to-video";
3133
3145
  }
3134
3146
  return void 0;
@@ -3235,7 +3247,7 @@ var XaiVideoModel = class {
3235
3247
  warnings.push({
3236
3248
  type: "unsupported",
3237
3249
  feature: "resolution",
3238
- details: `Unrecognized resolution "${options.resolution}". Use providerOptions.xai.resolution with "480p" or "720p" instead.`
3250
+ details: `Unrecognized resolution "${options.resolution}". Use providerOptions.xai.resolution with "480p", "720p", or "1080p" instead.`
3239
3251
  });
3240
3252
  }
3241
3253
  }
@@ -3274,13 +3286,47 @@ var XaiVideoModel = class {
3274
3286
  );
3275
3287
  if (referenceImages != null) {
3276
3288
  body.reference_images = referenceImages;
3289
+ } else {
3290
+ warnings.push({
3291
+ type: "unsupported",
3292
+ feature: "referenceImages",
3293
+ details: "xAI reference-to-video requires at least one image reference. The video will be generated without reference images."
3294
+ });
3277
3295
  }
3296
+ const referenceVoiceIds = xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds;
3297
+ if (referenceVoiceIds != null && referenceVoiceIds.length > 0) {
3298
+ body.reference_audios = referenceVoiceIds.map((voiceId) => ({
3299
+ voice_id: voiceId
3300
+ }));
3301
+ }
3302
+ if (body.resolution === "1080p") {
3303
+ warnings.push({
3304
+ type: "unsupported",
3305
+ feature: "resolution",
3306
+ details: "xAI reference-to-video is limited to 720p. The request was downgraded from 1080p to 720p."
3307
+ });
3308
+ body.resolution = "720p";
3309
+ }
3310
+ }
3311
+ if (body.resolution === "1080p" && this.modelId === "grok-imagine-video") {
3312
+ warnings.push({
3313
+ type: "unsupported",
3314
+ feature: "resolution",
3315
+ 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.'
3316
+ });
3278
3317
  }
3279
3318
  if (options.inputReferences != null && options.inputReferences.length > 0 && !hasReferenceImages) {
3280
3319
  warnings.push({
3281
3320
  type: "unsupported",
3282
3321
  feature: "inputReferences",
3283
- details: "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored."
3322
+ 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."
3323
+ });
3324
+ }
3325
+ if ((xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds) != null && xaiOptions.referenceVoiceIds.length > 0 && !hasReferenceImages) {
3326
+ warnings.push({
3327
+ type: "unsupported",
3328
+ feature: "referenceVoiceIds",
3329
+ details: "xAI only supports reference voices for reference-to-video generation. The reference voices were ignored."
3284
3330
  });
3285
3331
  }
3286
3332
  if (!isExtension && (xaiOptions == null ? void 0 : xaiOptions.user) !== void 0) {
@@ -3295,6 +3341,7 @@ var XaiVideoModel = class {
3295
3341
  "resolution",
3296
3342
  "videoUrl",
3297
3343
  "referenceImageUrls",
3344
+ "referenceVoiceIds",
3298
3345
  "user"
3299
3346
  ].includes(key)) {
3300
3347
  body[key] = value;