@ai-sdk/xai 3.0.120 → 3.0.121
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 +7 -0
- package/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +64 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -17
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +82 -9
- package/package.json +3 -3
- package/src/xai-video-model.ts +108 -22
- package/src/xai-video-options.ts +21 -1
- package/src/xai-video-settings.ts +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 3.0.121
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 70a6c3b: 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
|
+
- 70a6c3b: 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
|
+
|
|
3
10
|
## 3.0.120
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -120,11 +120,12 @@ declare const xaiImageModelOptions: z.ZodObject<{
|
|
|
120
120
|
}, z.core.$strip>;
|
|
121
121
|
type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
|
|
122
122
|
|
|
123
|
-
type XaiVideoModelId = 'grok-imagine-video' | (string & {});
|
|
123
|
+
type XaiVideoModelId = 'grok-imagine-video' | 'grok-imagine-video-1.5' | (string & {});
|
|
124
124
|
|
|
125
125
|
declare const resolutionSchema: z.ZodEnum<{
|
|
126
126
|
"480p": "480p";
|
|
127
127
|
"720p": "720p";
|
|
128
|
+
"1080p": "1080p";
|
|
128
129
|
}>;
|
|
129
130
|
type XaiVideoResolution = z.infer<typeof resolutionSchema>;
|
|
130
131
|
interface XaiVideoSharedOptions {
|
|
@@ -161,6 +162,10 @@ interface XaiVideoReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVide
|
|
|
161
162
|
mode: 'reference-to-video';
|
|
162
163
|
/** Reference image URLs (1-7) for R2V generation. */
|
|
163
164
|
referenceImageUrls: string[];
|
|
165
|
+
/**
|
|
166
|
+
* Preset voice ids (up to 3) that give the subject a voice.
|
|
167
|
+
*/
|
|
168
|
+
referenceVoiceIds?: string[];
|
|
164
169
|
}
|
|
165
170
|
interface XaiVideoGenerationOptions extends XaiVideoSharedOptions, XaiVideoUserOptions {
|
|
166
171
|
mode?: undefined;
|
|
@@ -182,6 +187,10 @@ interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVid
|
|
|
182
187
|
*/
|
|
183
188
|
mode?: undefined;
|
|
184
189
|
referenceImageUrls: string[];
|
|
190
|
+
/**
|
|
191
|
+
* Preset voice ids (up to 3) that give the subject a voice.
|
|
192
|
+
*/
|
|
193
|
+
referenceVoiceIds?: string[];
|
|
185
194
|
}
|
|
186
195
|
/**
|
|
187
196
|
* Provider options for xAI video generation.
|
|
@@ -193,6 +202,9 @@ interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVid
|
|
|
193
202
|
* - `'reference-to-video'` + `referenceImageUrls` -- R2V generation (`POST /v1/videos/generations`)
|
|
194
203
|
* - no `mode` -- standard generation from text prompts or image input
|
|
195
204
|
*
|
|
205
|
+
* Reference images may also come from the top-level `inputReferences` option
|
|
206
|
+
* instead of `referenceImageUrls`.
|
|
207
|
+
*
|
|
196
208
|
* Runtime remains backward compatible with legacy auto-detected provider
|
|
197
209
|
* options, but the public TypeScript type is intentionally explicit so editors
|
|
198
210
|
* can suggest valid modes and flag invalid field combinations.
|
package/dist/index.d.ts
CHANGED
|
@@ -120,11 +120,12 @@ declare const xaiImageModelOptions: z.ZodObject<{
|
|
|
120
120
|
}, z.core.$strip>;
|
|
121
121
|
type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
|
|
122
122
|
|
|
123
|
-
type XaiVideoModelId = 'grok-imagine-video' | (string & {});
|
|
123
|
+
type XaiVideoModelId = 'grok-imagine-video' | 'grok-imagine-video-1.5' | (string & {});
|
|
124
124
|
|
|
125
125
|
declare const resolutionSchema: z.ZodEnum<{
|
|
126
126
|
"480p": "480p";
|
|
127
127
|
"720p": "720p";
|
|
128
|
+
"1080p": "1080p";
|
|
128
129
|
}>;
|
|
129
130
|
type XaiVideoResolution = z.infer<typeof resolutionSchema>;
|
|
130
131
|
interface XaiVideoSharedOptions {
|
|
@@ -161,6 +162,10 @@ interface XaiVideoReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVide
|
|
|
161
162
|
mode: 'reference-to-video';
|
|
162
163
|
/** Reference image URLs (1-7) for R2V generation. */
|
|
163
164
|
referenceImageUrls: string[];
|
|
165
|
+
/**
|
|
166
|
+
* Preset voice ids (up to 3) that give the subject a voice.
|
|
167
|
+
*/
|
|
168
|
+
referenceVoiceIds?: string[];
|
|
164
169
|
}
|
|
165
170
|
interface XaiVideoGenerationOptions extends XaiVideoSharedOptions, XaiVideoUserOptions {
|
|
166
171
|
mode?: undefined;
|
|
@@ -182,6 +187,10 @@ interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVid
|
|
|
182
187
|
*/
|
|
183
188
|
mode?: undefined;
|
|
184
189
|
referenceImageUrls: string[];
|
|
190
|
+
/**
|
|
191
|
+
* Preset voice ids (up to 3) that give the subject a voice.
|
|
192
|
+
*/
|
|
193
|
+
referenceVoiceIds?: string[];
|
|
185
194
|
}
|
|
186
195
|
/**
|
|
187
196
|
* Provider options for xAI video generation.
|
|
@@ -193,6 +202,9 @@ interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVid
|
|
|
193
202
|
* - `'reference-to-video'` + `referenceImageUrls` -- R2V generation (`POST /v1/videos/generations`)
|
|
194
203
|
* - no `mode` -- standard generation from text prompts or image input
|
|
195
204
|
*
|
|
205
|
+
* Reference images may also come from the top-level `inputReferences` option
|
|
206
|
+
* instead of `referenceImageUrls`.
|
|
207
|
+
*
|
|
196
208
|
* Runtime remains backward compatible with legacy auto-detected provider
|
|
197
209
|
* options, but the public TypeScript type is intentionally explicit so editors
|
|
198
210
|
* can suggest valid modes and flag invalid field combinations.
|
package/dist/index.js
CHANGED
|
@@ -2967,7 +2967,7 @@ var xaiTools = {
|
|
|
2967
2967
|
};
|
|
2968
2968
|
|
|
2969
2969
|
// src/version.ts
|
|
2970
|
-
var VERSION = true ? "3.0.
|
|
2970
|
+
var VERSION = true ? "3.0.121" : "0.0.0-test";
|
|
2971
2971
|
|
|
2972
2972
|
// src/xai-video-model.ts
|
|
2973
2973
|
var import_provider6 = require("@ai-sdk/provider");
|
|
@@ -2978,7 +2978,7 @@ var import_v417 = require("zod/v4");
|
|
|
2978
2978
|
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
2979
2979
|
var import_v416 = require("zod/v4");
|
|
2980
2980
|
var nonEmptyStringSchema = import_v416.z.string().min(1);
|
|
2981
|
-
var resolutionSchema = import_v416.z.enum(["480p", "720p"]);
|
|
2981
|
+
var resolutionSchema = import_v416.z.enum(["480p", "720p", "1080p"]);
|
|
2982
2982
|
var modeSchema = import_v416.z.enum(["edit-video", "extend-video", "reference-to-video"]);
|
|
2983
2983
|
var baseFields = {
|
|
2984
2984
|
pollIntervalMs: import_v416.z.number().positive().nullish(),
|
|
@@ -2988,22 +2988,28 @@ var baseFields = {
|
|
|
2988
2988
|
var userField = {
|
|
2989
2989
|
user: import_v416.z.string().optional()
|
|
2990
2990
|
};
|
|
2991
|
+
var referenceVoiceIdsField = {
|
|
2992
|
+
referenceVoiceIds: import_v416.z.array(nonEmptyStringSchema).max(3).optional()
|
|
2993
|
+
};
|
|
2991
2994
|
var editVideoSchema = import_v416.z.object({
|
|
2992
2995
|
...baseFields,
|
|
2993
2996
|
...userField,
|
|
2994
2997
|
mode: import_v416.z.literal("edit-video"),
|
|
2995
2998
|
videoUrl: nonEmptyStringSchema,
|
|
2996
|
-
referenceImageUrls: import_v416.z.undefined().optional()
|
|
2999
|
+
referenceImageUrls: import_v416.z.undefined().optional(),
|
|
3000
|
+
referenceVoiceIds: import_v416.z.undefined().optional()
|
|
2997
3001
|
});
|
|
2998
3002
|
var extendVideoSchema = import_v416.z.object({
|
|
2999
3003
|
...baseFields,
|
|
3000
3004
|
mode: import_v416.z.literal("extend-video"),
|
|
3001
3005
|
videoUrl: nonEmptyStringSchema,
|
|
3002
|
-
referenceImageUrls: import_v416.z.undefined().optional()
|
|
3006
|
+
referenceImageUrls: import_v416.z.undefined().optional(),
|
|
3007
|
+
referenceVoiceIds: import_v416.z.undefined().optional()
|
|
3003
3008
|
});
|
|
3004
3009
|
var referenceToVideoSchema = import_v416.z.object({
|
|
3005
3010
|
...baseFields,
|
|
3006
3011
|
...userField,
|
|
3012
|
+
...referenceVoiceIdsField,
|
|
3007
3013
|
mode: import_v416.z.literal("reference-to-video"),
|
|
3008
3014
|
referenceImageUrls: import_v416.z.array(nonEmptyStringSchema).min(1).max(7),
|
|
3009
3015
|
videoUrl: import_v416.z.undefined().optional()
|
|
@@ -3011,6 +3017,7 @@ var referenceToVideoSchema = import_v416.z.object({
|
|
|
3011
3017
|
var autoDetectSchema = import_v416.z.object({
|
|
3012
3018
|
...baseFields,
|
|
3013
3019
|
...userField,
|
|
3020
|
+
...referenceVoiceIdsField,
|
|
3014
3021
|
mode: import_v416.z.undefined().optional(),
|
|
3015
3022
|
videoUrl: nonEmptyStringSchema.optional(),
|
|
3016
3023
|
referenceImageUrls: import_v416.z.array(nonEmptyStringSchema).min(1).max(7).optional()
|
|
@@ -3025,6 +3032,7 @@ var runtimeSchema = import_v416.z.object({
|
|
|
3025
3032
|
mode: modeSchema.optional(),
|
|
3026
3033
|
videoUrl: nonEmptyStringSchema.optional(),
|
|
3027
3034
|
referenceImageUrls: import_v416.z.array(nonEmptyStringSchema).min(1).max(7).optional(),
|
|
3035
|
+
referenceVoiceIds: import_v416.z.array(nonEmptyStringSchema).max(3).optional(),
|
|
3028
3036
|
user: import_v416.z.string().optional(),
|
|
3029
3037
|
...baseFields
|
|
3030
3038
|
}).passthrough();
|
|
@@ -3034,6 +3042,7 @@ var xaiVideoModelOptionsSchema = (0, import_provider_utils15.lazySchema)(
|
|
|
3034
3042
|
|
|
3035
3043
|
// src/xai-video-model.ts
|
|
3036
3044
|
var RESOLUTION_MAP = {
|
|
3045
|
+
"1920x1080": "1080p",
|
|
3037
3046
|
"1280x720": "720p",
|
|
3038
3047
|
"854x480": "480p",
|
|
3039
3048
|
"640x480": "480p"
|
|
@@ -3055,6 +3064,7 @@ function getTopLevelMediaType(mediaType) {
|
|
|
3055
3064
|
return slashIndex === -1 ? mediaType : mediaType.substring(0, slashIndex);
|
|
3056
3065
|
}
|
|
3057
3066
|
var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType(file.mediaType) === "video";
|
|
3067
|
+
var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType(file.mediaType) === "image";
|
|
3058
3068
|
function fileToXaiImageUrl(file) {
|
|
3059
3069
|
if (file.type === "url") {
|
|
3060
3070
|
return file.url;
|
|
@@ -3064,26 +3074,29 @@ function fileToXaiImageUrl(file) {
|
|
|
3064
3074
|
}
|
|
3065
3075
|
function resolveReferenceImages(options, xaiOptions, warnings) {
|
|
3066
3076
|
if (options.inputReferences != null && options.inputReferences.length > 0) {
|
|
3067
|
-
const
|
|
3068
|
-
|
|
3077
|
+
const imageFiles = [];
|
|
3078
|
+
for (const reference of options.inputReferences) {
|
|
3079
|
+
if (!isImageReference(reference)) {
|
|
3069
3080
|
warnings.push({
|
|
3070
3081
|
type: "unsupported",
|
|
3071
3082
|
feature: "inputReferences",
|
|
3072
|
-
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.'
|
|
3083
|
+
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."
|
|
3073
3084
|
});
|
|
3074
|
-
|
|
3085
|
+
continue;
|
|
3075
3086
|
}
|
|
3076
|
-
|
|
3077
|
-
}
|
|
3078
|
-
return
|
|
3079
|
-
url: fileToXaiImageUrl(reference)
|
|
3080
|
-
}));
|
|
3087
|
+
imageFiles.push(reference);
|
|
3088
|
+
}
|
|
3089
|
+
return imageFiles.length > 0 ? imageFiles.map((reference) => ({ url: fileToXaiImageUrl(reference) })) : void 0;
|
|
3081
3090
|
}
|
|
3082
3091
|
if ((xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0) {
|
|
3083
3092
|
return xaiOptions.referenceImageUrls.map((url) => ({ url }));
|
|
3084
3093
|
}
|
|
3085
3094
|
return void 0;
|
|
3086
3095
|
}
|
|
3096
|
+
function hasImageInputReference(options) {
|
|
3097
|
+
var _a, _b;
|
|
3098
|
+
return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isImageReference)) != null ? _b : false;
|
|
3099
|
+
}
|
|
3087
3100
|
function resolveVideoMode(options, xaiOptions) {
|
|
3088
3101
|
if ((xaiOptions == null ? void 0 : xaiOptions.mode) != null) {
|
|
3089
3102
|
return xaiOptions.mode;
|
|
@@ -3092,9 +3105,8 @@ function resolveVideoMode(options, xaiOptions) {
|
|
|
3092
3105
|
return "edit-video";
|
|
3093
3106
|
}
|
|
3094
3107
|
const hasFrameImages = options.frameImages != null && options.frameImages.length > 0;
|
|
3095
|
-
const hasInputReferences = options.inputReferences != null && options.inputReferences.length > 0;
|
|
3096
3108
|
const hasLegacyReferenceUrls = (xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0;
|
|
3097
|
-
if (!hasFrameImages && (
|
|
3109
|
+
if (!hasFrameImages && (hasImageInputReference(options) || hasLegacyReferenceUrls)) {
|
|
3098
3110
|
return "reference-to-video";
|
|
3099
3111
|
}
|
|
3100
3112
|
return void 0;
|
|
@@ -3201,7 +3213,7 @@ var XaiVideoModel = class {
|
|
|
3201
3213
|
warnings.push({
|
|
3202
3214
|
type: "unsupported",
|
|
3203
3215
|
feature: "resolution",
|
|
3204
|
-
details: `Unrecognized resolution "${options.resolution}". Use providerOptions.xai.resolution with "480p" or "
|
|
3216
|
+
details: `Unrecognized resolution "${options.resolution}". Use providerOptions.xai.resolution with "480p", "720p", or "1080p" instead.`
|
|
3205
3217
|
});
|
|
3206
3218
|
}
|
|
3207
3219
|
}
|
|
@@ -3240,13 +3252,47 @@ var XaiVideoModel = class {
|
|
|
3240
3252
|
);
|
|
3241
3253
|
if (referenceImages != null) {
|
|
3242
3254
|
body.reference_images = referenceImages;
|
|
3255
|
+
} else {
|
|
3256
|
+
warnings.push({
|
|
3257
|
+
type: "unsupported",
|
|
3258
|
+
feature: "referenceImages",
|
|
3259
|
+
details: "xAI reference-to-video requires at least one image reference. The video will be generated without reference images."
|
|
3260
|
+
});
|
|
3243
3261
|
}
|
|
3262
|
+
const referenceVoiceIds = xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds;
|
|
3263
|
+
if (referenceVoiceIds != null && referenceVoiceIds.length > 0) {
|
|
3264
|
+
body.reference_audios = referenceVoiceIds.map((voiceId) => ({
|
|
3265
|
+
voice_id: voiceId
|
|
3266
|
+
}));
|
|
3267
|
+
}
|
|
3268
|
+
if (body.resolution === "1080p") {
|
|
3269
|
+
warnings.push({
|
|
3270
|
+
type: "unsupported",
|
|
3271
|
+
feature: "resolution",
|
|
3272
|
+
details: "xAI reference-to-video is limited to 720p. The request was downgraded from 1080p to 720p."
|
|
3273
|
+
});
|
|
3274
|
+
body.resolution = "720p";
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
if (body.resolution === "1080p" && this.modelId === "grok-imagine-video") {
|
|
3278
|
+
warnings.push({
|
|
3279
|
+
type: "unsupported",
|
|
3280
|
+
feature: "resolution",
|
|
3281
|
+
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.'
|
|
3282
|
+
});
|
|
3244
3283
|
}
|
|
3245
3284
|
if (options.inputReferences != null && options.inputReferences.length > 0 && !hasReferenceImages) {
|
|
3246
3285
|
warnings.push({
|
|
3247
3286
|
type: "unsupported",
|
|
3248
3287
|
feature: "inputReferences",
|
|
3249
|
-
details: "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored."
|
|
3288
|
+
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."
|
|
3289
|
+
});
|
|
3290
|
+
}
|
|
3291
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds) != null && xaiOptions.referenceVoiceIds.length > 0 && !hasReferenceImages) {
|
|
3292
|
+
warnings.push({
|
|
3293
|
+
type: "unsupported",
|
|
3294
|
+
feature: "referenceVoiceIds",
|
|
3295
|
+
details: "xAI only supports reference voices for reference-to-video generation. The reference voices were ignored."
|
|
3250
3296
|
});
|
|
3251
3297
|
}
|
|
3252
3298
|
if (!isExtension && (xaiOptions == null ? void 0 : xaiOptions.user) !== void 0) {
|
|
@@ -3261,6 +3307,7 @@ var XaiVideoModel = class {
|
|
|
3261
3307
|
"resolution",
|
|
3262
3308
|
"videoUrl",
|
|
3263
3309
|
"referenceImageUrls",
|
|
3310
|
+
"referenceVoiceIds",
|
|
3264
3311
|
"user"
|
|
3265
3312
|
].includes(key)) {
|
|
3266
3313
|
body[key] = value;
|