@ai-sdk/xai 3.0.100 → 3.0.101
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 +10 -0
- package/dist/index.js +62 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -19
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +61 -1
- package/package.json +6 -6
- package/src/xai-video-model.ts +113 -25
package/dist/index.mjs
CHANGED
|
@@ -2864,7 +2864,7 @@ var xaiTools = {
|
|
|
2864
2864
|
};
|
|
2865
2865
|
|
|
2866
2866
|
// src/version.ts
|
|
2867
|
-
var VERSION = true ? "3.0.
|
|
2867
|
+
var VERSION = true ? "3.0.101" : "0.0.0-test";
|
|
2868
2868
|
|
|
2869
2869
|
// src/xai-video-model.ts
|
|
2870
2870
|
import {
|
|
@@ -2938,14 +2938,48 @@ var RESOLUTION_MAP = {
|
|
|
2938
2938
|
"854x480": "480p",
|
|
2939
2939
|
"640x480": "480p"
|
|
2940
2940
|
};
|
|
2941
|
-
function
|
|
2942
|
-
|
|
2943
|
-
|
|
2941
|
+
function getFirstFrameImage(options) {
|
|
2942
|
+
var _a, _b;
|
|
2943
|
+
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
2944
|
+
}
|
|
2945
|
+
function getLastFrameImage(options) {
|
|
2946
|
+
var _a, _b;
|
|
2947
|
+
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
2948
|
+
}
|
|
2949
|
+
function resolveStartImage(options) {
|
|
2950
|
+
var _a;
|
|
2951
|
+
return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
|
|
2952
|
+
}
|
|
2953
|
+
function fileToXaiImageUrl(file) {
|
|
2954
|
+
var _a;
|
|
2955
|
+
if (file.type === "url") {
|
|
2956
|
+
return file.url;
|
|
2957
|
+
}
|
|
2958
|
+
const base64Data = typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data);
|
|
2959
|
+
return `data:${(_a = file.mediaType) != null ? _a : "image/png"};base64,${base64Data}`;
|
|
2960
|
+
}
|
|
2961
|
+
function resolveReferenceImages(options, xaiOptions) {
|
|
2962
|
+
if (options.inputReferences != null && options.inputReferences.length > 0) {
|
|
2963
|
+
return options.inputReferences.map((reference) => ({
|
|
2964
|
+
url: fileToXaiImageUrl(reference)
|
|
2965
|
+
}));
|
|
2966
|
+
}
|
|
2967
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0) {
|
|
2968
|
+
return xaiOptions.referenceImageUrls.map((url) => ({ url }));
|
|
2969
|
+
}
|
|
2970
|
+
return void 0;
|
|
2971
|
+
}
|
|
2972
|
+
function resolveVideoMode(options, xaiOptions) {
|
|
2973
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.mode) != null) {
|
|
2974
|
+
return xaiOptions.mode;
|
|
2944
2975
|
}
|
|
2945
|
-
if ((
|
|
2976
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.videoUrl) != null) {
|
|
2946
2977
|
return "edit-video";
|
|
2947
2978
|
}
|
|
2948
|
-
|
|
2979
|
+
const hasFrameImages = options.frameImages != null && options.frameImages.length > 0;
|
|
2980
|
+
const hasInputReferences = options.inputReferences != null && options.inputReferences.length > 0;
|
|
2981
|
+
const hasLegacyReferenceUrls = (xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0;
|
|
2982
|
+
if (!hasFrameImages && (hasInputReferences || hasLegacyReferenceUrls)) {
|
|
2949
2983
|
return "reference-to-video";
|
|
2950
2984
|
}
|
|
2951
2985
|
return void 0;
|
|
@@ -2969,7 +3003,7 @@ var XaiVideoModel = class {
|
|
|
2969
3003
|
providerOptions: options.providerOptions,
|
|
2970
3004
|
schema: xaiVideoModelOptionsSchema
|
|
2971
3005
|
});
|
|
2972
|
-
const effectiveMode = resolveVideoMode(xaiOptions);
|
|
3006
|
+
const effectiveMode = resolveVideoMode(options, xaiOptions);
|
|
2973
3007
|
const isEdit = effectiveMode === "edit-video";
|
|
2974
3008
|
const isExtension = effectiveMode === "extend-video";
|
|
2975
3009
|
const hasReferenceImages = effectiveMode === "reference-to-video";
|
|
@@ -3062,20 +3096,29 @@ var XaiVideoModel = class {
|
|
|
3062
3096
|
if (isExtension) {
|
|
3063
3097
|
body.video = { url: xaiOptions.videoUrl };
|
|
3064
3098
|
}
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3099
|
+
const startImage = resolveStartImage(options);
|
|
3100
|
+
if (startImage != null) {
|
|
3101
|
+
body.image = { url: fileToXaiImageUrl(startImage) };
|
|
3102
|
+
}
|
|
3103
|
+
if (getLastFrameImage(options) != null) {
|
|
3104
|
+
warnings.push({
|
|
3105
|
+
type: "unsupported",
|
|
3106
|
+
feature: "frameImages",
|
|
3107
|
+
details: `xAI video models do not support last_frame. Use providerOptions.xai.mode "extend-video" to continue from a video's last frame. The last frame image was ignored.`
|
|
3108
|
+
});
|
|
3074
3109
|
}
|
|
3075
3110
|
if (hasReferenceImages) {
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3111
|
+
const referenceImages = resolveReferenceImages(options, xaiOptions);
|
|
3112
|
+
if (referenceImages != null) {
|
|
3113
|
+
body.reference_images = referenceImages;
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
if (options.inputReferences != null && options.inputReferences.length > 0 && !hasReferenceImages) {
|
|
3117
|
+
warnings.push({
|
|
3118
|
+
type: "unsupported",
|
|
3119
|
+
feature: "inputReferences",
|
|
3120
|
+
details: "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored."
|
|
3121
|
+
});
|
|
3079
3122
|
}
|
|
3080
3123
|
if (xaiOptions != null) {
|
|
3081
3124
|
for (const [key, value] of Object.entries(xaiOptions)) {
|