@ai-sdk/xai 3.0.105 → 3.0.107

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
@@ -2912,7 +2912,7 @@ var xaiTools = {
2912
2912
  };
2913
2913
 
2914
2914
  // src/version.ts
2915
- var VERSION = true ? "3.0.105" : "0.0.0-test";
2915
+ var VERSION = true ? "3.0.107" : "0.0.0-test";
2916
2916
 
2917
2917
  // src/xai-video-model.ts
2918
2918
  import {
@@ -2998,17 +2998,32 @@ function resolveStartImage(options) {
2998
2998
  var _a;
2999
2999
  return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
3000
3000
  }
3001
+ function getTopLevelMediaType(mediaType) {
3002
+ const slashIndex = mediaType.indexOf("/");
3003
+ return slashIndex === -1 ? mediaType : mediaType.substring(0, slashIndex);
3004
+ }
3005
+ var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType(file.mediaType) === "video";
3001
3006
  function fileToXaiImageUrl(file) {
3002
- var _a;
3003
3007
  if (file.type === "url") {
3004
3008
  return file.url;
3005
3009
  }
3006
3010
  const base64Data = typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data);
3007
- return `data:${(_a = file.mediaType) != null ? _a : "image/png"};base64,${base64Data}`;
3011
+ return `data:${file.mediaType};base64,${base64Data}`;
3008
3012
  }
3009
- function resolveReferenceImages(options, xaiOptions) {
3013
+ function resolveReferenceImages(options, xaiOptions, warnings) {
3010
3014
  if (options.inputReferences != null && options.inputReferences.length > 0) {
3011
- return options.inputReferences.map((reference) => ({
3015
+ const imageReferences = options.inputReferences.filter((reference) => {
3016
+ if (isVideoFile(reference)) {
3017
+ warnings.push({
3018
+ type: "unsupported",
3019
+ feature: "inputReferences",
3020
+ 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.'
3021
+ });
3022
+ return false;
3023
+ }
3024
+ return true;
3025
+ });
3026
+ return imageReferences.map((reference) => ({
3012
3027
  url: fileToXaiImageUrl(reference)
3013
3028
  }));
3014
3029
  }
@@ -3146,17 +3161,31 @@ var XaiVideoModel = class {
3146
3161
  }
3147
3162
  const startImage = resolveStartImage(options);
3148
3163
  if (startImage != null) {
3149
- body.image = { url: fileToXaiImageUrl(startImage) };
3164
+ if (isVideoFile(startImage)) {
3165
+ const fromFrameImages = getFirstFrameImage(options) != null;
3166
+ warnings.push({
3167
+ type: "unsupported",
3168
+ feature: fromFrameImages ? "frameImages" : "image",
3169
+ 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.'
3170
+ });
3171
+ } else {
3172
+ body.image = { url: fileToXaiImageUrl(startImage) };
3173
+ }
3150
3174
  }
3151
- if (getLastFrameImage(options) != null) {
3175
+ const lastFrameImage = getLastFrameImage(options);
3176
+ if (lastFrameImage != null) {
3152
3177
  warnings.push({
3153
3178
  type: "unsupported",
3154
3179
  feature: "frameImages",
3155
- 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.`
3180
+ details: isVideoFile(lastFrameImage) ? 'xAI does not accept a video as a start/frame image. The video last frame was ignored. Use providerOptions.xai.mode "extend-video" to continue from a video instead.' : `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.`
3156
3181
  });
3157
3182
  }
3158
3183
  if (hasReferenceImages) {
3159
- const referenceImages = resolveReferenceImages(options, xaiOptions);
3184
+ const referenceImages = resolveReferenceImages(
3185
+ options,
3186
+ xaiOptions,
3187
+ warnings
3188
+ );
3160
3189
  if (referenceImages != null) {
3161
3190
  body.reference_images = referenceImages;
3162
3191
  }