@ai-sdk/xai 3.0.68 → 3.0.70

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
@@ -888,7 +888,9 @@ var xaiImageModelOptions = z4.object({
888
888
  aspect_ratio: z4.string().optional(),
889
889
  output_format: z4.string().optional(),
890
890
  sync_mode: z4.boolean().optional(),
891
- resolution: z4.enum(["1k", "2k"]).optional()
891
+ resolution: z4.enum(["1k", "2k"]).optional(),
892
+ quality: z4.enum(["low", "medium", "high"]).optional(),
893
+ user: z4.string().optional()
892
894
  });
893
895
 
894
896
  // src/xai-image-model.ts
@@ -897,7 +899,7 @@ var XaiImageModel = class {
897
899
  this.modelId = modelId;
898
900
  this.config = config;
899
901
  this.specificationVersion = "v3";
900
- this.maxImagesPerCall = 1;
902
+ this.maxImagesPerCall = 3;
901
903
  }
902
904
  get provider() {
903
905
  return this.config.provider;
@@ -914,7 +916,7 @@ var XaiImageModel = class {
914
916
  files,
915
917
  mask
916
918
  }) {
917
- var _a, _b, _c, _d;
919
+ var _a, _b, _c, _d, _e;
918
920
  const warnings = [];
919
921
  if (size != null) {
920
922
  warnings.push({
@@ -941,22 +943,13 @@ var XaiImageModel = class {
941
943
  schema: xaiImageModelOptions
942
944
  });
943
945
  const hasFiles = files != null && files.length > 0;
944
- let imageUrl;
945
- if (hasFiles) {
946
- imageUrl = convertImageModelFileToDataUri(files[0]);
947
- if (files.length > 1) {
948
- warnings.push({
949
- type: "other",
950
- message: "xAI only supports a single input image. Additional images are ignored."
951
- });
952
- }
953
- }
946
+ const imageUrls = hasFiles ? files.map((file) => convertImageModelFileToDataUri(file)) : [];
954
947
  const endpoint = hasFiles ? "/images/edits" : "/images/generations";
955
948
  const body = {
956
949
  model: this.modelId,
957
950
  prompt,
958
951
  n,
959
- response_format: "url"
952
+ response_format: "b64_json"
960
953
  };
961
954
  if (aspectRatio != null) {
962
955
  body.aspect_ratio = aspectRatio;
@@ -973,8 +966,16 @@ var XaiImageModel = class {
973
966
  if ((xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
974
967
  body.resolution = xaiOptions.resolution;
975
968
  }
976
- if (imageUrl != null) {
977
- body.image = { url: imageUrl, type: "image_url" };
969
+ if ((xaiOptions == null ? void 0 : xaiOptions.quality) != null) {
970
+ body.quality = xaiOptions.quality;
971
+ }
972
+ if ((xaiOptions == null ? void 0 : xaiOptions.user) != null) {
973
+ body.user = xaiOptions.user;
974
+ }
975
+ if (imageUrls.length === 1) {
976
+ body.image = { url: imageUrls[0], type: "image_url" };
977
+ } else if (imageUrls.length > 1) {
978
+ body.images = imageUrls.map((url) => ({ url, type: "image_url" }));
978
979
  }
979
980
  const baseURL = (_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1";
980
981
  const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
@@ -989,11 +990,14 @@ var XaiImageModel = class {
989
990
  abortSignal,
990
991
  fetch: this.config.fetch
991
992
  });
992
- const downloadedImages = await Promise.all(
993
- response.data.map((image) => this.downloadImage(image.url, abortSignal))
993
+ const hasAllBase64 = response.data.every((image) => image.b64_json != null);
994
+ const images = hasAllBase64 ? response.data.map((image) => image.b64_json) : await Promise.all(
995
+ response.data.map(
996
+ (image) => this.downloadImage(image.url, abortSignal)
997
+ )
994
998
  );
995
999
  return {
996
- images: downloadedImages,
1000
+ images,
997
1001
  warnings,
998
1002
  response: {
999
1003
  timestamp: currentDate,
@@ -1004,7 +1008,8 @@ var XaiImageModel = class {
1004
1008
  xai: {
1005
1009
  images: response.data.map((item) => ({
1006
1010
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {}
1007
- }))
1011
+ })),
1012
+ ...((_e = response.usage) == null ? void 0 : _e.cost_in_usd_ticks) != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
1008
1013
  }
1009
1014
  }
1010
1015
  };
@@ -1023,10 +1028,14 @@ var XaiImageModel = class {
1023
1028
  var xaiImageResponseSchema = z5.object({
1024
1029
  data: z5.array(
1025
1030
  z5.object({
1026
- url: z5.string(),
1031
+ url: z5.string().nullish(),
1032
+ b64_json: z5.string().nullish(),
1027
1033
  revised_prompt: z5.string().nullish()
1028
1034
  })
1029
- )
1035
+ ),
1036
+ usage: z5.object({
1037
+ cost_in_usd_ticks: z5.number().nullish()
1038
+ }).nullish()
1030
1039
  });
1031
1040
 
1032
1041
  // src/responses/xai-responses-language-model.ts
@@ -2727,7 +2736,7 @@ var xaiTools = {
2727
2736
  };
2728
2737
 
2729
2738
  // src/version.ts
2730
- var VERSION = true ? "3.0.68" : "0.0.0-test";
2739
+ var VERSION = true ? "3.0.70" : "0.0.0-test";
2731
2740
 
2732
2741
  // src/xai-video-model.ts
2733
2742
  import {