@ai-sdk/xai 4.0.2 → 4.0.4

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [8c616f0]
8
+ - @ai-sdk/provider-utils@5.0.3
9
+ - @ai-sdk/openai-compatible@3.0.3
10
+
11
+ ## 4.0.3
12
+
13
+ ### Patch Changes
14
+
15
+ - 0274f34: feat (video): add first-class `frameImages` and `inputReferences` call options for video generation
16
+ - Updated dependencies [0274f34]
17
+ - @ai-sdk/provider@4.0.1
18
+ - @ai-sdk/openai-compatible@3.0.2
19
+ - @ai-sdk/provider-utils@5.0.2
20
+
3
21
  ## 4.0.2
4
22
 
5
23
  ### Patch Changes
package/dist/index.js CHANGED
@@ -3393,7 +3393,7 @@ var xaiTools = {
3393
3393
  };
3394
3394
 
3395
3395
  // src/version.ts
3396
- var VERSION = true ? "4.0.2" : "0.0.0-test";
3396
+ var VERSION = true ? "4.0.4" : "0.0.0-test";
3397
3397
 
3398
3398
  // src/files/xai-files.ts
3399
3399
  import {
@@ -3568,14 +3568,48 @@ var RESOLUTION_MAP = {
3568
3568
  "854x480": "480p",
3569
3569
  "640x480": "480p"
3570
3570
  };
3571
- function resolveVideoMode(options) {
3572
- if ((options == null ? void 0 : options.mode) != null) {
3573
- return options.mode;
3571
+ function getFirstFrameImage(options) {
3572
+ var _a, _b;
3573
+ return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
3574
+ }
3575
+ function getLastFrameImage(options) {
3576
+ var _a, _b;
3577
+ return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
3578
+ }
3579
+ function resolveStartImage(options) {
3580
+ var _a;
3581
+ return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
3582
+ }
3583
+ function fileToXaiImageUrl(file) {
3584
+ var _a;
3585
+ if (file.type === "url") {
3586
+ return file.url;
3587
+ }
3588
+ const base64Data = typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data);
3589
+ return `data:${(_a = file.mediaType) != null ? _a : "image/png"};base64,${base64Data}`;
3590
+ }
3591
+ function resolveReferenceImages(options, xaiOptions) {
3592
+ if (options.inputReferences != null && options.inputReferences.length > 0) {
3593
+ return options.inputReferences.map((reference) => ({
3594
+ url: fileToXaiImageUrl(reference)
3595
+ }));
3596
+ }
3597
+ if ((xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0) {
3598
+ return xaiOptions.referenceImageUrls.map((url) => ({ url }));
3599
+ }
3600
+ return void 0;
3601
+ }
3602
+ function resolveVideoMode(options, xaiOptions) {
3603
+ if ((xaiOptions == null ? void 0 : xaiOptions.mode) != null) {
3604
+ return xaiOptions.mode;
3574
3605
  }
3575
- if ((options == null ? void 0 : options.videoUrl) != null) {
3606
+ if ((xaiOptions == null ? void 0 : xaiOptions.videoUrl) != null) {
3576
3607
  return "edit-video";
3577
3608
  }
3578
- if ((options == null ? void 0 : options.referenceImageUrls) != null && options.referenceImageUrls.length > 0) {
3609
+ const hasFrameImages = options.frameImages != null && options.frameImages.length > 0;
3610
+ const hasInputReferences = options.inputReferences != null && options.inputReferences.length > 0;
3611
+ const hasLegacyReferenceUrls = (xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0;
3612
+ if (!hasFrameImages && (hasInputReferences || hasLegacyReferenceUrls)) {
3579
3613
  return "reference-to-video";
3580
3614
  }
3581
3615
  return void 0;
@@ -3599,7 +3633,7 @@ var XaiVideoModel = class {
3599
3633
  providerOptions: options.providerOptions,
3600
3634
  schema: xaiVideoModelOptionsSchema
3601
3635
  });
3602
- const effectiveMode = resolveVideoMode(xaiOptions);
3636
+ const effectiveMode = resolveVideoMode(options, xaiOptions);
3603
3637
  const isEdit = effectiveMode === "edit-video";
3604
3638
  const isExtension = effectiveMode === "extend-video";
3605
3639
  const hasReferenceImages = effectiveMode === "reference-to-video";
@@ -3692,20 +3726,29 @@ var XaiVideoModel = class {
3692
3726
  if (isExtension) {
3693
3727
  body.video = { url: xaiOptions.videoUrl };
3694
3728
  }
3695
- if (options.image != null) {
3696
- if (options.image.type === "url") {
3697
- body.image = { url: options.image.url };
3698
- } else {
3699
- const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
3700
- body.image = {
3701
- url: `data:${options.image.mediaType};base64,${base64Data}`
3702
- };
3703
- }
3729
+ const startImage = resolveStartImage(options);
3730
+ if (startImage != null) {
3731
+ body.image = { url: fileToXaiImageUrl(startImage) };
3732
+ }
3733
+ if (getLastFrameImage(options) != null) {
3734
+ warnings.push({
3735
+ type: "unsupported",
3736
+ feature: "frameImages",
3737
+ 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.`
3738
+ });
3704
3739
  }
3705
3740
  if (hasReferenceImages) {
3706
- body.reference_images = xaiOptions.referenceImageUrls.map((url) => ({
3707
- url
3708
- }));
3741
+ const referenceImages = resolveReferenceImages(options, xaiOptions);
3742
+ if (referenceImages != null) {
3743
+ body.reference_images = referenceImages;
3744
+ }
3745
+ }
3746
+ if (options.inputReferences != null && options.inputReferences.length > 0 && !hasReferenceImages) {
3747
+ warnings.push({
3748
+ type: "unsupported",
3749
+ feature: "inputReferences",
3750
+ details: "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored."
3751
+ });
3709
3752
  }
3710
3753
  if (xaiOptions != null) {
3711
3754
  for (const [key, value] of Object.entries(xaiOptions)) {