@ai-sdk/xai 3.0.76 → 3.0.78

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
@@ -2740,7 +2740,7 @@ var xaiTools = {
2740
2740
  };
2741
2741
 
2742
2742
  // src/version.ts
2743
- var VERSION = true ? "3.0.76" : "0.0.0-test";
2743
+ var VERSION = true ? "3.0.78" : "0.0.0-test";
2744
2744
 
2745
2745
  // src/xai-video-model.ts
2746
2746
  import {
@@ -2760,15 +2760,52 @@ import { z as z16 } from "zod/v4";
2760
2760
  // src/xai-video-options.ts
2761
2761
  import { lazySchema as lazySchema5, zodSchema as zodSchema5 } from "@ai-sdk/provider-utils";
2762
2762
  import { z as z15 } from "zod/v4";
2763
+ var nonEmptyStringSchema = z15.string().min(1);
2764
+ var resolutionSchema = z15.enum(["480p", "720p"]);
2765
+ var modeSchema = z15.enum(["edit-video", "extend-video", "reference-to-video"]);
2766
+ var baseFields = {
2767
+ pollIntervalMs: z15.number().positive().nullish(),
2768
+ pollTimeoutMs: z15.number().positive().nullish(),
2769
+ resolution: resolutionSchema.nullish()
2770
+ };
2771
+ var editVideoSchema = z15.object({
2772
+ ...baseFields,
2773
+ mode: z15.literal("edit-video"),
2774
+ videoUrl: nonEmptyStringSchema,
2775
+ referenceImageUrls: z15.undefined().optional()
2776
+ });
2777
+ var extendVideoSchema = z15.object({
2778
+ ...baseFields,
2779
+ mode: z15.literal("extend-video"),
2780
+ videoUrl: nonEmptyStringSchema,
2781
+ referenceImageUrls: z15.undefined().optional()
2782
+ });
2783
+ var referenceToVideoSchema = z15.object({
2784
+ ...baseFields,
2785
+ mode: z15.literal("reference-to-video"),
2786
+ referenceImageUrls: z15.array(nonEmptyStringSchema).min(1).max(7),
2787
+ videoUrl: z15.undefined().optional()
2788
+ });
2789
+ var autoDetectSchema = z15.object({
2790
+ ...baseFields,
2791
+ mode: z15.undefined().optional(),
2792
+ videoUrl: nonEmptyStringSchema.optional(),
2793
+ referenceImageUrls: z15.array(nonEmptyStringSchema).min(1).max(7).optional()
2794
+ });
2795
+ var xaiVideoModelOptions = z15.union([
2796
+ editVideoSchema,
2797
+ extendVideoSchema,
2798
+ referenceToVideoSchema,
2799
+ autoDetectSchema
2800
+ ]);
2801
+ var runtimeSchema = z15.object({
2802
+ mode: modeSchema.optional(),
2803
+ videoUrl: nonEmptyStringSchema.optional(),
2804
+ referenceImageUrls: z15.array(nonEmptyStringSchema).min(1).max(7).optional(),
2805
+ ...baseFields
2806
+ }).passthrough();
2763
2807
  var xaiVideoModelOptionsSchema = lazySchema5(
2764
- () => zodSchema5(
2765
- z15.object({
2766
- pollIntervalMs: z15.number().positive().nullish(),
2767
- pollTimeoutMs: z15.number().positive().nullish(),
2768
- resolution: z15.enum(["480p", "720p"]).nullish(),
2769
- videoUrl: z15.string().nullish()
2770
- }).passthrough()
2771
- )
2808
+ () => zodSchema5(runtimeSchema)
2772
2809
  );
2773
2810
 
2774
2811
  // src/xai-video-model.ts
@@ -2777,6 +2814,18 @@ var RESOLUTION_MAP = {
2777
2814
  "854x480": "480p",
2778
2815
  "640x480": "480p"
2779
2816
  };
2817
+ function resolveVideoMode(options) {
2818
+ if ((options == null ? void 0 : options.mode) != null) {
2819
+ return options.mode;
2820
+ }
2821
+ if ((options == null ? void 0 : options.videoUrl) != null) {
2822
+ return "edit-video";
2823
+ }
2824
+ if ((options == null ? void 0 : options.referenceImageUrls) != null && options.referenceImageUrls.length > 0) {
2825
+ return "reference-to-video";
2826
+ }
2827
+ return void 0;
2828
+ }
2780
2829
  var XaiVideoModel = class {
2781
2830
  constructor(modelId, config) {
2782
2831
  this.modelId = modelId;
@@ -2796,7 +2845,10 @@ var XaiVideoModel = class {
2796
2845
  providerOptions: options.providerOptions,
2797
2846
  schema: xaiVideoModelOptionsSchema
2798
2847
  });
2799
- const isEdit = (xaiOptions == null ? void 0 : xaiOptions.videoUrl) != null;
2848
+ const effectiveMode = resolveVideoMode(xaiOptions);
2849
+ const isEdit = effectiveMode === "edit-video";
2850
+ const isExtension = effectiveMode === "extend-video";
2851
+ const hasReferenceImages = effectiveMode === "reference-to-video";
2800
2852
  if (options.fps != null) {
2801
2853
  warnings.push({
2802
2854
  type: "unsupported",
@@ -2839,19 +2891,36 @@ var XaiVideoModel = class {
2839
2891
  details: "xAI video editing does not support custom resolution."
2840
2892
  });
2841
2893
  }
2894
+ if (isExtension && options.aspectRatio != null) {
2895
+ warnings.push({
2896
+ type: "unsupported",
2897
+ feature: "aspectRatio",
2898
+ details: "xAI video extension does not support custom aspect ratio."
2899
+ });
2900
+ }
2901
+ if (isExtension && ((xaiOptions == null ? void 0 : xaiOptions.resolution) != null || options.resolution != null)) {
2902
+ warnings.push({
2903
+ type: "unsupported",
2904
+ feature: "resolution",
2905
+ details: "xAI video extension does not support custom resolution."
2906
+ });
2907
+ }
2842
2908
  const body = {
2843
2909
  model: this.modelId,
2844
2910
  prompt: options.prompt
2845
2911
  };
2846
- if (!isEdit && options.duration != null) {
2912
+ const allowDuration = !isEdit;
2913
+ const allowAspectRatio = !isEdit && !isExtension;
2914
+ const allowResolution = !isEdit && !isExtension;
2915
+ if (allowDuration && options.duration != null) {
2847
2916
  body.duration = options.duration;
2848
2917
  }
2849
- if (!isEdit && options.aspectRatio != null) {
2918
+ if (allowAspectRatio && options.aspectRatio != null) {
2850
2919
  body.aspect_ratio = options.aspectRatio;
2851
2920
  }
2852
- if (!isEdit && (xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
2921
+ if (allowResolution && (xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
2853
2922
  body.resolution = xaiOptions.resolution;
2854
- } else if (!isEdit && options.resolution != null) {
2923
+ } else if (allowResolution && options.resolution != null) {
2855
2924
  const mapped = RESOLUTION_MAP[options.resolution];
2856
2925
  if (mapped != null) {
2857
2926
  body.resolution = mapped;
@@ -2863,7 +2932,10 @@ var XaiVideoModel = class {
2863
2932
  });
2864
2933
  }
2865
2934
  }
2866
- if ((xaiOptions == null ? void 0 : xaiOptions.videoUrl) != null) {
2935
+ if (isEdit) {
2936
+ body.video = { url: xaiOptions.videoUrl };
2937
+ }
2938
+ if (isExtension) {
2867
2939
  body.video = { url: xaiOptions.videoUrl };
2868
2940
  }
2869
2941
  if (options.image != null) {
@@ -2876,21 +2948,36 @@ var XaiVideoModel = class {
2876
2948
  };
2877
2949
  }
2878
2950
  }
2951
+ if (hasReferenceImages) {
2952
+ body.reference_images = xaiOptions.referenceImageUrls.map((url) => ({
2953
+ url
2954
+ }));
2955
+ }
2879
2956
  if (xaiOptions != null) {
2880
2957
  for (const [key, value] of Object.entries(xaiOptions)) {
2881
2958
  if (![
2959
+ "mode",
2882
2960
  "pollIntervalMs",
2883
2961
  "pollTimeoutMs",
2884
2962
  "resolution",
2885
- "videoUrl"
2963
+ "videoUrl",
2964
+ "referenceImageUrls"
2886
2965
  ].includes(key)) {
2887
2966
  body[key] = value;
2888
2967
  }
2889
2968
  }
2890
2969
  }
2891
2970
  const baseURL = (_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1";
2971
+ let endpoint;
2972
+ if (isEdit) {
2973
+ endpoint = `${baseURL}/videos/edits`;
2974
+ } else if (isExtension) {
2975
+ endpoint = `${baseURL}/videos/extensions`;
2976
+ } else {
2977
+ endpoint = `${baseURL}/videos/generations`;
2978
+ }
2892
2979
  const { value: createResponse } = await postJsonToApi4({
2893
- url: `${baseURL}/videos/${isEdit ? "edits" : "generations"}`,
2980
+ url: endpoint,
2894
2981
  headers: combineHeaders4(this.config.headers(), options.headers),
2895
2982
  body,
2896
2983
  failedResponseHandler: xaiFailedResponseHandler,
@@ -2962,7 +3049,8 @@ var XaiVideoModel = class {
2962
3049
  requestId,
2963
3050
  videoUrl: statusResponse.video.url,
2964
3051
  ...statusResponse.video.duration != null ? { duration: statusResponse.video.duration } : {},
2965
- ...((_j = statusResponse.usage) == null ? void 0 : _j.cost_in_usd_ticks) != null ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks } : {}
3052
+ ...((_j = statusResponse.usage) == null ? void 0 : _j.cost_in_usd_ticks) != null ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks } : {},
3053
+ ...statusResponse.progress != null ? { progress: statusResponse.progress } : {}
2966
3054
  }
2967
3055
  }
2968
3056
  };
@@ -2973,6 +3061,12 @@ var XaiVideoModel = class {
2973
3061
  message: "Video generation request expired."
2974
3062
  });
2975
3063
  }
3064
+ if (statusResponse.status === "failed") {
3065
+ throw new AISDKError({
3066
+ name: "XAI_VIDEO_GENERATION_FAILED",
3067
+ message: "Video generation failed."
3068
+ });
3069
+ }
2976
3070
  }
2977
3071
  }
2978
3072
  };
@@ -2989,6 +3083,11 @@ var xaiVideoStatusResponseSchema = z16.object({
2989
3083
  model: z16.string().nullish(),
2990
3084
  usage: z16.object({
2991
3085
  cost_in_usd_ticks: z16.number().nullish()
3086
+ }).nullish(),
3087
+ progress: z16.number().nullish(),
3088
+ error: z16.object({
3089
+ code: z16.string().nullish(),
3090
+ message: z16.string().nullish()
2992
3091
  }).nullish()
2993
3092
  });
2994
3093