@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 3.0.101
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fa850e6: feat (video): add first-class `frameImages` and `inputReferences` call options for video generation
|
|
8
|
+
- Updated dependencies [fa850e6]
|
|
9
|
+
- @ai-sdk/provider@3.0.13
|
|
10
|
+
- @ai-sdk/openai-compatible@2.0.55
|
|
11
|
+
- @ai-sdk/provider-utils@4.0.34
|
|
12
|
+
|
|
3
13
|
## 3.0.100
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -2843,7 +2843,7 @@ var xaiTools = {
|
|
|
2843
2843
|
};
|
|
2844
2844
|
|
|
2845
2845
|
// src/version.ts
|
|
2846
|
-
var VERSION = true ? "3.0.
|
|
2846
|
+
var VERSION = true ? "3.0.101" : "0.0.0-test";
|
|
2847
2847
|
|
|
2848
2848
|
// src/xai-video-model.ts
|
|
2849
2849
|
var import_provider6 = require("@ai-sdk/provider");
|
|
@@ -2907,14 +2907,48 @@ var RESOLUTION_MAP = {
|
|
|
2907
2907
|
"854x480": "480p",
|
|
2908
2908
|
"640x480": "480p"
|
|
2909
2909
|
};
|
|
2910
|
-
function
|
|
2911
|
-
|
|
2912
|
-
|
|
2910
|
+
function getFirstFrameImage(options) {
|
|
2911
|
+
var _a, _b;
|
|
2912
|
+
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
2913
|
+
}
|
|
2914
|
+
function getLastFrameImage(options) {
|
|
2915
|
+
var _a, _b;
|
|
2916
|
+
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
2917
|
+
}
|
|
2918
|
+
function resolveStartImage(options) {
|
|
2919
|
+
var _a;
|
|
2920
|
+
return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
|
|
2921
|
+
}
|
|
2922
|
+
function fileToXaiImageUrl(file) {
|
|
2923
|
+
var _a;
|
|
2924
|
+
if (file.type === "url") {
|
|
2925
|
+
return file.url;
|
|
2926
|
+
}
|
|
2927
|
+
const base64Data = typeof file.data === "string" ? file.data : (0, import_provider_utils16.convertUint8ArrayToBase64)(file.data);
|
|
2928
|
+
return `data:${(_a = file.mediaType) != null ? _a : "image/png"};base64,${base64Data}`;
|
|
2929
|
+
}
|
|
2930
|
+
function resolveReferenceImages(options, xaiOptions) {
|
|
2931
|
+
if (options.inputReferences != null && options.inputReferences.length > 0) {
|
|
2932
|
+
return options.inputReferences.map((reference) => ({
|
|
2933
|
+
url: fileToXaiImageUrl(reference)
|
|
2934
|
+
}));
|
|
2935
|
+
}
|
|
2936
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0) {
|
|
2937
|
+
return xaiOptions.referenceImageUrls.map((url) => ({ url }));
|
|
2938
|
+
}
|
|
2939
|
+
return void 0;
|
|
2940
|
+
}
|
|
2941
|
+
function resolveVideoMode(options, xaiOptions) {
|
|
2942
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.mode) != null) {
|
|
2943
|
+
return xaiOptions.mode;
|
|
2913
2944
|
}
|
|
2914
|
-
if ((
|
|
2945
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.videoUrl) != null) {
|
|
2915
2946
|
return "edit-video";
|
|
2916
2947
|
}
|
|
2917
|
-
|
|
2948
|
+
const hasFrameImages = options.frameImages != null && options.frameImages.length > 0;
|
|
2949
|
+
const hasInputReferences = options.inputReferences != null && options.inputReferences.length > 0;
|
|
2950
|
+
const hasLegacyReferenceUrls = (xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0;
|
|
2951
|
+
if (!hasFrameImages && (hasInputReferences || hasLegacyReferenceUrls)) {
|
|
2918
2952
|
return "reference-to-video";
|
|
2919
2953
|
}
|
|
2920
2954
|
return void 0;
|
|
@@ -2938,7 +2972,7 @@ var XaiVideoModel = class {
|
|
|
2938
2972
|
providerOptions: options.providerOptions,
|
|
2939
2973
|
schema: xaiVideoModelOptionsSchema
|
|
2940
2974
|
});
|
|
2941
|
-
const effectiveMode = resolveVideoMode(xaiOptions);
|
|
2975
|
+
const effectiveMode = resolveVideoMode(options, xaiOptions);
|
|
2942
2976
|
const isEdit = effectiveMode === "edit-video";
|
|
2943
2977
|
const isExtension = effectiveMode === "extend-video";
|
|
2944
2978
|
const hasReferenceImages = effectiveMode === "reference-to-video";
|
|
@@ -3031,20 +3065,29 @@ var XaiVideoModel = class {
|
|
|
3031
3065
|
if (isExtension) {
|
|
3032
3066
|
body.video = { url: xaiOptions.videoUrl };
|
|
3033
3067
|
}
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3068
|
+
const startImage = resolveStartImage(options);
|
|
3069
|
+
if (startImage != null) {
|
|
3070
|
+
body.image = { url: fileToXaiImageUrl(startImage) };
|
|
3071
|
+
}
|
|
3072
|
+
if (getLastFrameImage(options) != null) {
|
|
3073
|
+
warnings.push({
|
|
3074
|
+
type: "unsupported",
|
|
3075
|
+
feature: "frameImages",
|
|
3076
|
+
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.`
|
|
3077
|
+
});
|
|
3043
3078
|
}
|
|
3044
3079
|
if (hasReferenceImages) {
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3080
|
+
const referenceImages = resolveReferenceImages(options, xaiOptions);
|
|
3081
|
+
if (referenceImages != null) {
|
|
3082
|
+
body.reference_images = referenceImages;
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
if (options.inputReferences != null && options.inputReferences.length > 0 && !hasReferenceImages) {
|
|
3086
|
+
warnings.push({
|
|
3087
|
+
type: "unsupported",
|
|
3088
|
+
feature: "inputReferences",
|
|
3089
|
+
details: "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored."
|
|
3090
|
+
});
|
|
3048
3091
|
}
|
|
3049
3092
|
if (xaiOptions != null) {
|
|
3050
3093
|
for (const [key, value] of Object.entries(xaiOptions)) {
|