@ai-sdk/xai 4.0.0-beta.2 → 4.0.0-beta.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,17 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 25f1837: feat(xai): add b64_json response format, usage cost tracking, and quality/user parameters for image models
8
+
9
+ ## 4.0.0-beta.3
10
+
11
+ ### Patch Changes
12
+
13
+ - f5181ad: feat(provider/xai): support multiple input images for image editing
14
+
3
15
  ## 4.0.0-beta.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -86,6 +86,12 @@ declare const xaiImageModelOptions: z.ZodObject<{
86
86
  "1k": "1k";
87
87
  "2k": "2k";
88
88
  }>>;
89
+ quality: z.ZodOptional<z.ZodEnum<{
90
+ low: "low";
91
+ high: "high";
92
+ medium: "medium";
93
+ }>>;
94
+ user: z.ZodOptional<z.ZodString>;
89
95
  }, z.core.$strip>;
90
96
  type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
91
97
 
package/dist/index.d.ts CHANGED
@@ -86,6 +86,12 @@ declare const xaiImageModelOptions: z.ZodObject<{
86
86
  "1k": "1k";
87
87
  "2k": "2k";
88
88
  }>>;
89
+ quality: z.ZodOptional<z.ZodEnum<{
90
+ low: "low";
91
+ high: "high";
92
+ medium: "medium";
93
+ }>>;
94
+ user: z.ZodOptional<z.ZodString>;
89
95
  }, z.core.$strip>;
90
96
  type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
91
97
 
package/dist/index.js CHANGED
@@ -893,7 +893,9 @@ var xaiImageModelOptions = import_v44.z.object({
893
893
  aspect_ratio: import_v44.z.string().optional(),
894
894
  output_format: import_v44.z.string().optional(),
895
895
  sync_mode: import_v44.z.boolean().optional(),
896
- resolution: import_v44.z.enum(["1k", "2k"]).optional()
896
+ resolution: import_v44.z.enum(["1k", "2k"]).optional(),
897
+ quality: import_v44.z.enum(["low", "medium", "high"]).optional(),
898
+ user: import_v44.z.string().optional()
897
899
  });
898
900
 
899
901
  // src/xai-image-model.ts
@@ -902,7 +904,7 @@ var XaiImageModel = class {
902
904
  this.modelId = modelId;
903
905
  this.config = config;
904
906
  this.specificationVersion = "v3";
905
- this.maxImagesPerCall = 1;
907
+ this.maxImagesPerCall = 3;
906
908
  }
907
909
  get provider() {
908
910
  return this.config.provider;
@@ -919,7 +921,7 @@ var XaiImageModel = class {
919
921
  files,
920
922
  mask
921
923
  }) {
922
- var _a, _b, _c, _d;
924
+ var _a, _b, _c, _d, _e;
923
925
  const warnings = [];
924
926
  if (size != null) {
925
927
  warnings.push({
@@ -946,22 +948,13 @@ var XaiImageModel = class {
946
948
  schema: xaiImageModelOptions
947
949
  });
948
950
  const hasFiles = files != null && files.length > 0;
949
- let imageUrl;
950
- if (hasFiles) {
951
- imageUrl = (0, import_provider_utils4.convertImageModelFileToDataUri)(files[0]);
952
- if (files.length > 1) {
953
- warnings.push({
954
- type: "other",
955
- message: "xAI only supports a single input image. Additional images are ignored."
956
- });
957
- }
958
- }
951
+ const imageUrls = hasFiles ? files.map((file) => (0, import_provider_utils4.convertImageModelFileToDataUri)(file)) : [];
959
952
  const endpoint = hasFiles ? "/images/edits" : "/images/generations";
960
953
  const body = {
961
954
  model: this.modelId,
962
955
  prompt,
963
956
  n,
964
- response_format: "url"
957
+ response_format: "b64_json"
965
958
  };
966
959
  if (aspectRatio != null) {
967
960
  body.aspect_ratio = aspectRatio;
@@ -978,8 +971,16 @@ var XaiImageModel = class {
978
971
  if ((xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
979
972
  body.resolution = xaiOptions.resolution;
980
973
  }
981
- if (imageUrl != null) {
982
- body.image = { url: imageUrl, type: "image_url" };
974
+ if ((xaiOptions == null ? void 0 : xaiOptions.quality) != null) {
975
+ body.quality = xaiOptions.quality;
976
+ }
977
+ if ((xaiOptions == null ? void 0 : xaiOptions.user) != null) {
978
+ body.user = xaiOptions.user;
979
+ }
980
+ if (imageUrls.length === 1) {
981
+ body.image = { url: imageUrls[0], type: "image_url" };
982
+ } else if (imageUrls.length > 1) {
983
+ body.images = imageUrls.map((url) => ({ url, type: "image_url" }));
983
984
  }
984
985
  const baseURL = (_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1";
985
986
  const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
@@ -994,11 +995,14 @@ var XaiImageModel = class {
994
995
  abortSignal,
995
996
  fetch: this.config.fetch
996
997
  });
997
- const downloadedImages = await Promise.all(
998
- response.data.map((image) => this.downloadImage(image.url, abortSignal))
998
+ const hasAllBase64 = response.data.every((image) => image.b64_json != null);
999
+ const images = hasAllBase64 ? response.data.map((image) => image.b64_json) : await Promise.all(
1000
+ response.data.map(
1001
+ (image) => this.downloadImage(image.url, abortSignal)
1002
+ )
999
1003
  );
1000
1004
  return {
1001
- images: downloadedImages,
1005
+ images,
1002
1006
  warnings,
1003
1007
  response: {
1004
1008
  timestamp: currentDate,
@@ -1009,7 +1013,8 @@ var XaiImageModel = class {
1009
1013
  xai: {
1010
1014
  images: response.data.map((item) => ({
1011
1015
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {}
1012
- }))
1016
+ })),
1017
+ ...((_e = response.usage) == null ? void 0 : _e.cost_in_usd_ticks) != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
1013
1018
  }
1014
1019
  }
1015
1020
  };
@@ -1028,10 +1033,14 @@ var XaiImageModel = class {
1028
1033
  var xaiImageResponseSchema = import_v45.z.object({
1029
1034
  data: import_v45.z.array(
1030
1035
  import_v45.z.object({
1031
- url: import_v45.z.string(),
1036
+ url: import_v45.z.string().nullish(),
1037
+ b64_json: import_v45.z.string().nullish(),
1032
1038
  revised_prompt: import_v45.z.string().nullish()
1033
1039
  })
1034
- )
1040
+ ),
1041
+ usage: import_v45.z.object({
1042
+ cost_in_usd_ticks: import_v45.z.number().nullish()
1043
+ }).nullish()
1035
1044
  });
1036
1045
 
1037
1046
  // src/responses/xai-responses-language-model.ts
@@ -2706,7 +2715,7 @@ var xaiTools = {
2706
2715
  };
2707
2716
 
2708
2717
  // src/version.ts
2709
- var VERSION = true ? "4.0.0-beta.2" : "0.0.0-test";
2718
+ var VERSION = true ? "4.0.0-beta.4" : "0.0.0-test";
2710
2719
 
2711
2720
  // src/xai-video-model.ts
2712
2721
  var import_provider6 = require("@ai-sdk/provider");