@ai-sdk/xai 4.0.0-beta.21 → 4.0.0-beta.23
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 +16 -0
- package/dist/index.d.mts +82 -8
- package/dist/index.d.ts +82 -8
- package/dist/index.js +264 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +275 -44
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +166 -47
- package/package.json +4 -4
- package/src/convert-to-xai-chat-messages.ts +17 -1
- package/src/files/xai-files-api.ts +16 -0
- package/src/files/xai-files-options.ts +15 -0
- package/src/files/xai-files.ts +93 -0
- package/src/index.ts +1 -0
- package/src/responses/convert-to-xai-responses-input.ts +14 -2
- package/src/responses/xai-responses-api.ts +2 -1
- package/src/xai-chat-prompt.ts +2 -1
- package/src/xai-provider.ts +16 -0
- package/src/xai-video-model.ts +104 -13
- package/src/xai-video-options.ts +136 -14
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
35
35
|
|
|
36
36
|
// src/xai-provider.ts
|
|
37
37
|
var import_provider7 = require("@ai-sdk/provider");
|
|
38
|
-
var
|
|
38
|
+
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
39
39
|
|
|
40
40
|
// src/xai-chat-language-model.ts
|
|
41
41
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -68,6 +68,17 @@ function convertToXaiChatMessages(prompt) {
|
|
|
68
68
|
return { type: "text", text: part.text };
|
|
69
69
|
}
|
|
70
70
|
case "file": {
|
|
71
|
+
if ((0, import_provider_utils.isProviderReference)(part.data)) {
|
|
72
|
+
return {
|
|
73
|
+
type: "file",
|
|
74
|
+
file: {
|
|
75
|
+
file_id: (0, import_provider_utils.resolveProviderReference)({
|
|
76
|
+
reference: part.data,
|
|
77
|
+
provider: "xai"
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
71
82
|
if (part.mediaType.startsWith("image/")) {
|
|
72
83
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
73
84
|
return {
|
|
@@ -1084,7 +1095,15 @@ async function convertToXaiResponsesInput({
|
|
|
1084
1095
|
break;
|
|
1085
1096
|
}
|
|
1086
1097
|
case "file": {
|
|
1087
|
-
if (block.
|
|
1098
|
+
if ((0, import_provider_utils5.isProviderReference)(block.data)) {
|
|
1099
|
+
contentParts.push({
|
|
1100
|
+
type: "input_file",
|
|
1101
|
+
file_id: (0, import_provider_utils5.resolveProviderReference)({
|
|
1102
|
+
reference: block.data,
|
|
1103
|
+
provider: "xai"
|
|
1104
|
+
})
|
|
1105
|
+
});
|
|
1106
|
+
} else if (block.mediaType.startsWith("image/")) {
|
|
1088
1107
|
const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
|
|
1089
1108
|
const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils5.convertToBase64)(block.data)}`;
|
|
1090
1109
|
contentParts.push({ type: "input_image", image_url: imageUrl });
|
|
@@ -2753,33 +2772,174 @@ var xaiTools = {
|
|
|
2753
2772
|
};
|
|
2754
2773
|
|
|
2755
2774
|
// src/version.ts
|
|
2756
|
-
var VERSION = true ? "4.0.0-beta.
|
|
2775
|
+
var VERSION = true ? "4.0.0-beta.23" : "0.0.0-test";
|
|
2757
2776
|
|
|
2758
|
-
// src/xai-
|
|
2759
|
-
var
|
|
2760
|
-
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
2761
|
-
var import_v416 = require("zod/v4");
|
|
2777
|
+
// src/files/xai-files.ts
|
|
2778
|
+
var import_provider_utils17 = require("@ai-sdk/provider-utils");
|
|
2762
2779
|
|
|
2763
|
-
// src/xai-
|
|
2780
|
+
// src/files/xai-files-api.ts
|
|
2764
2781
|
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
2765
2782
|
var import_v415 = require("zod/v4");
|
|
2766
|
-
var
|
|
2783
|
+
var xaiFilesResponseSchema = (0, import_provider_utils15.lazySchema)(
|
|
2767
2784
|
() => (0, import_provider_utils15.zodSchema)(
|
|
2768
2785
|
import_v415.z.object({
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2786
|
+
id: import_v415.z.string(),
|
|
2787
|
+
object: import_v415.z.string().nullish(),
|
|
2788
|
+
bytes: import_v415.z.number().nullish(),
|
|
2789
|
+
created_at: import_v415.z.number().nullish(),
|
|
2790
|
+
filename: import_v415.z.string().nullish(),
|
|
2791
|
+
purpose: import_v415.z.string().nullish(),
|
|
2792
|
+
status: import_v415.z.string().nullish()
|
|
2793
|
+
})
|
|
2794
|
+
)
|
|
2795
|
+
);
|
|
2796
|
+
|
|
2797
|
+
// src/files/xai-files-options.ts
|
|
2798
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
2799
|
+
var import_v416 = require("zod/v4");
|
|
2800
|
+
var xaiFilesOptionsSchema = (0, import_provider_utils16.lazySchema)(
|
|
2801
|
+
() => (0, import_provider_utils16.zodSchema)(
|
|
2802
|
+
import_v416.z.object({
|
|
2803
|
+
teamId: import_v416.z.string().optional(),
|
|
2804
|
+
filePath: import_v416.z.string().optional()
|
|
2773
2805
|
}).passthrough()
|
|
2774
2806
|
)
|
|
2775
2807
|
);
|
|
2776
2808
|
|
|
2809
|
+
// src/files/xai-files.ts
|
|
2810
|
+
var XaiFiles = class {
|
|
2811
|
+
constructor(config) {
|
|
2812
|
+
this.config = config;
|
|
2813
|
+
this.specificationVersion = "v4";
|
|
2814
|
+
}
|
|
2815
|
+
get provider() {
|
|
2816
|
+
return this.config.provider;
|
|
2817
|
+
}
|
|
2818
|
+
async uploadFile({
|
|
2819
|
+
data,
|
|
2820
|
+
mediaType,
|
|
2821
|
+
filename,
|
|
2822
|
+
providerOptions
|
|
2823
|
+
}) {
|
|
2824
|
+
var _a, _b;
|
|
2825
|
+
const xaiOptions = await (0, import_provider_utils17.parseProviderOptions)({
|
|
2826
|
+
provider: "xai",
|
|
2827
|
+
providerOptions,
|
|
2828
|
+
schema: xaiFilesOptionsSchema
|
|
2829
|
+
});
|
|
2830
|
+
const fileBytes = data instanceof Uint8Array ? data : (0, import_provider_utils17.convertBase64ToUint8Array)(data);
|
|
2831
|
+
const blob = new Blob([fileBytes], {
|
|
2832
|
+
type: mediaType
|
|
2833
|
+
});
|
|
2834
|
+
const formData = new FormData();
|
|
2835
|
+
if (filename != null) {
|
|
2836
|
+
formData.append("file", blob, filename);
|
|
2837
|
+
} else {
|
|
2838
|
+
formData.append("file", blob);
|
|
2839
|
+
}
|
|
2840
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.teamId) != null) {
|
|
2841
|
+
formData.append("team_id", xaiOptions.teamId);
|
|
2842
|
+
}
|
|
2843
|
+
const { value: response } = await (0, import_provider_utils17.postFormDataToApi)({
|
|
2844
|
+
url: `${this.config.baseURL}/files`,
|
|
2845
|
+
headers: (0, import_provider_utils17.combineHeaders)(this.config.headers()),
|
|
2846
|
+
formData,
|
|
2847
|
+
failedResponseHandler: xaiFailedResponseHandler,
|
|
2848
|
+
successfulResponseHandler: (0, import_provider_utils17.createJsonResponseHandler)(
|
|
2849
|
+
xaiFilesResponseSchema
|
|
2850
|
+
),
|
|
2851
|
+
fetch: this.config.fetch
|
|
2852
|
+
});
|
|
2853
|
+
return {
|
|
2854
|
+
warnings: [],
|
|
2855
|
+
providerReference: { xai: response.id },
|
|
2856
|
+
...((_a = response.filename) != null ? _a : filename) ? { filename: (_b = response.filename) != null ? _b : filename } : {},
|
|
2857
|
+
...mediaType != null ? { mediaType } : {},
|
|
2858
|
+
providerMetadata: {
|
|
2859
|
+
xai: {
|
|
2860
|
+
...response.filename != null ? { filename: response.filename } : {},
|
|
2861
|
+
...response.bytes != null ? { bytes: response.bytes } : {},
|
|
2862
|
+
...response.created_at != null ? { createdAt: response.created_at } : {}
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2867
|
+
};
|
|
2868
|
+
|
|
2869
|
+
// src/xai-video-model.ts
|
|
2870
|
+
var import_provider6 = require("@ai-sdk/provider");
|
|
2871
|
+
var import_provider_utils19 = require("@ai-sdk/provider-utils");
|
|
2872
|
+
var import_v418 = require("zod/v4");
|
|
2873
|
+
|
|
2874
|
+
// src/xai-video-options.ts
|
|
2875
|
+
var import_provider_utils18 = require("@ai-sdk/provider-utils");
|
|
2876
|
+
var import_v417 = require("zod/v4");
|
|
2877
|
+
var nonEmptyStringSchema = import_v417.z.string().min(1);
|
|
2878
|
+
var resolutionSchema = import_v417.z.enum(["480p", "720p"]);
|
|
2879
|
+
var modeSchema = import_v417.z.enum(["edit-video", "extend-video", "reference-to-video"]);
|
|
2880
|
+
var baseFields = {
|
|
2881
|
+
pollIntervalMs: import_v417.z.number().positive().nullish(),
|
|
2882
|
+
pollTimeoutMs: import_v417.z.number().positive().nullish(),
|
|
2883
|
+
resolution: resolutionSchema.nullish()
|
|
2884
|
+
};
|
|
2885
|
+
var editVideoSchema = import_v417.z.object({
|
|
2886
|
+
...baseFields,
|
|
2887
|
+
mode: import_v417.z.literal("edit-video"),
|
|
2888
|
+
videoUrl: nonEmptyStringSchema,
|
|
2889
|
+
referenceImageUrls: import_v417.z.undefined().optional()
|
|
2890
|
+
});
|
|
2891
|
+
var extendVideoSchema = import_v417.z.object({
|
|
2892
|
+
...baseFields,
|
|
2893
|
+
mode: import_v417.z.literal("extend-video"),
|
|
2894
|
+
videoUrl: nonEmptyStringSchema,
|
|
2895
|
+
referenceImageUrls: import_v417.z.undefined().optional()
|
|
2896
|
+
});
|
|
2897
|
+
var referenceToVideoSchema = import_v417.z.object({
|
|
2898
|
+
...baseFields,
|
|
2899
|
+
mode: import_v417.z.literal("reference-to-video"),
|
|
2900
|
+
referenceImageUrls: import_v417.z.array(nonEmptyStringSchema).min(1).max(7),
|
|
2901
|
+
videoUrl: import_v417.z.undefined().optional()
|
|
2902
|
+
});
|
|
2903
|
+
var autoDetectSchema = import_v417.z.object({
|
|
2904
|
+
...baseFields,
|
|
2905
|
+
mode: import_v417.z.undefined().optional(),
|
|
2906
|
+
videoUrl: nonEmptyStringSchema.optional(),
|
|
2907
|
+
referenceImageUrls: import_v417.z.array(nonEmptyStringSchema).min(1).max(7).optional()
|
|
2908
|
+
});
|
|
2909
|
+
var xaiVideoModelOptions = import_v417.z.union([
|
|
2910
|
+
editVideoSchema,
|
|
2911
|
+
extendVideoSchema,
|
|
2912
|
+
referenceToVideoSchema,
|
|
2913
|
+
autoDetectSchema
|
|
2914
|
+
]);
|
|
2915
|
+
var runtimeSchema = import_v417.z.object({
|
|
2916
|
+
mode: modeSchema.optional(),
|
|
2917
|
+
videoUrl: nonEmptyStringSchema.optional(),
|
|
2918
|
+
referenceImageUrls: import_v417.z.array(nonEmptyStringSchema).min(1).max(7).optional(),
|
|
2919
|
+
...baseFields
|
|
2920
|
+
}).passthrough();
|
|
2921
|
+
var xaiVideoModelOptionsSchema = (0, import_provider_utils18.lazySchema)(
|
|
2922
|
+
() => (0, import_provider_utils18.zodSchema)(runtimeSchema)
|
|
2923
|
+
);
|
|
2924
|
+
|
|
2777
2925
|
// src/xai-video-model.ts
|
|
2778
2926
|
var RESOLUTION_MAP = {
|
|
2779
2927
|
"1280x720": "720p",
|
|
2780
2928
|
"854x480": "480p",
|
|
2781
2929
|
"640x480": "480p"
|
|
2782
2930
|
};
|
|
2931
|
+
function resolveVideoMode(options) {
|
|
2932
|
+
if ((options == null ? void 0 : options.mode) != null) {
|
|
2933
|
+
return options.mode;
|
|
2934
|
+
}
|
|
2935
|
+
if ((options == null ? void 0 : options.videoUrl) != null) {
|
|
2936
|
+
return "edit-video";
|
|
2937
|
+
}
|
|
2938
|
+
if ((options == null ? void 0 : options.referenceImageUrls) != null && options.referenceImageUrls.length > 0) {
|
|
2939
|
+
return "reference-to-video";
|
|
2940
|
+
}
|
|
2941
|
+
return void 0;
|
|
2942
|
+
}
|
|
2783
2943
|
var XaiVideoModel = class {
|
|
2784
2944
|
constructor(modelId, config) {
|
|
2785
2945
|
this.modelId = modelId;
|
|
@@ -2794,12 +2954,15 @@ var XaiVideoModel = class {
|
|
|
2794
2954
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2795
2955
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2796
2956
|
const warnings = [];
|
|
2797
|
-
const xaiOptions = await (0,
|
|
2957
|
+
const xaiOptions = await (0, import_provider_utils19.parseProviderOptions)({
|
|
2798
2958
|
provider: "xai",
|
|
2799
2959
|
providerOptions: options.providerOptions,
|
|
2800
2960
|
schema: xaiVideoModelOptionsSchema
|
|
2801
2961
|
});
|
|
2802
|
-
const
|
|
2962
|
+
const effectiveMode = resolveVideoMode(xaiOptions);
|
|
2963
|
+
const isEdit = effectiveMode === "edit-video";
|
|
2964
|
+
const isExtension = effectiveMode === "extend-video";
|
|
2965
|
+
const hasReferenceImages = effectiveMode === "reference-to-video";
|
|
2803
2966
|
if (options.fps != null) {
|
|
2804
2967
|
warnings.push({
|
|
2805
2968
|
type: "unsupported",
|
|
@@ -2842,19 +3005,36 @@ var XaiVideoModel = class {
|
|
|
2842
3005
|
details: "xAI video editing does not support custom resolution."
|
|
2843
3006
|
});
|
|
2844
3007
|
}
|
|
3008
|
+
if (isExtension && options.aspectRatio != null) {
|
|
3009
|
+
warnings.push({
|
|
3010
|
+
type: "unsupported",
|
|
3011
|
+
feature: "aspectRatio",
|
|
3012
|
+
details: "xAI video extension does not support custom aspect ratio."
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
3015
|
+
if (isExtension && ((xaiOptions == null ? void 0 : xaiOptions.resolution) != null || options.resolution != null)) {
|
|
3016
|
+
warnings.push({
|
|
3017
|
+
type: "unsupported",
|
|
3018
|
+
feature: "resolution",
|
|
3019
|
+
details: "xAI video extension does not support custom resolution."
|
|
3020
|
+
});
|
|
3021
|
+
}
|
|
2845
3022
|
const body = {
|
|
2846
3023
|
model: this.modelId,
|
|
2847
3024
|
prompt: options.prompt
|
|
2848
3025
|
};
|
|
2849
|
-
|
|
3026
|
+
const allowDuration = !isEdit;
|
|
3027
|
+
const allowAspectRatio = !isEdit && !isExtension;
|
|
3028
|
+
const allowResolution = !isEdit && !isExtension;
|
|
3029
|
+
if (allowDuration && options.duration != null) {
|
|
2850
3030
|
body.duration = options.duration;
|
|
2851
3031
|
}
|
|
2852
|
-
if (
|
|
3032
|
+
if (allowAspectRatio && options.aspectRatio != null) {
|
|
2853
3033
|
body.aspect_ratio = options.aspectRatio;
|
|
2854
3034
|
}
|
|
2855
|
-
if (
|
|
3035
|
+
if (allowResolution && (xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
|
|
2856
3036
|
body.resolution = xaiOptions.resolution;
|
|
2857
|
-
} else if (
|
|
3037
|
+
} else if (allowResolution && options.resolution != null) {
|
|
2858
3038
|
const mapped = RESOLUTION_MAP[options.resolution];
|
|
2859
3039
|
if (mapped != null) {
|
|
2860
3040
|
body.resolution = mapped;
|
|
@@ -2866,38 +3046,56 @@ var XaiVideoModel = class {
|
|
|
2866
3046
|
});
|
|
2867
3047
|
}
|
|
2868
3048
|
}
|
|
2869
|
-
if (
|
|
3049
|
+
if (isEdit) {
|
|
3050
|
+
body.video = { url: xaiOptions.videoUrl };
|
|
3051
|
+
}
|
|
3052
|
+
if (isExtension) {
|
|
2870
3053
|
body.video = { url: xaiOptions.videoUrl };
|
|
2871
3054
|
}
|
|
2872
3055
|
if (options.image != null) {
|
|
2873
3056
|
if (options.image.type === "url") {
|
|
2874
3057
|
body.image = { url: options.image.url };
|
|
2875
3058
|
} else {
|
|
2876
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (0,
|
|
3059
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils19.convertUint8ArrayToBase64)(options.image.data);
|
|
2877
3060
|
body.image = {
|
|
2878
3061
|
url: `data:${options.image.mediaType};base64,${base64Data}`
|
|
2879
3062
|
};
|
|
2880
3063
|
}
|
|
2881
3064
|
}
|
|
3065
|
+
if (hasReferenceImages) {
|
|
3066
|
+
body.reference_images = xaiOptions.referenceImageUrls.map((url) => ({
|
|
3067
|
+
url
|
|
3068
|
+
}));
|
|
3069
|
+
}
|
|
2882
3070
|
if (xaiOptions != null) {
|
|
2883
3071
|
for (const [key, value] of Object.entries(xaiOptions)) {
|
|
2884
3072
|
if (![
|
|
3073
|
+
"mode",
|
|
2885
3074
|
"pollIntervalMs",
|
|
2886
3075
|
"pollTimeoutMs",
|
|
2887
3076
|
"resolution",
|
|
2888
|
-
"videoUrl"
|
|
3077
|
+
"videoUrl",
|
|
3078
|
+
"referenceImageUrls"
|
|
2889
3079
|
].includes(key)) {
|
|
2890
3080
|
body[key] = value;
|
|
2891
3081
|
}
|
|
2892
3082
|
}
|
|
2893
3083
|
}
|
|
2894
3084
|
const baseURL = (_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1";
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
3085
|
+
let endpoint;
|
|
3086
|
+
if (isEdit) {
|
|
3087
|
+
endpoint = `${baseURL}/videos/edits`;
|
|
3088
|
+
} else if (isExtension) {
|
|
3089
|
+
endpoint = `${baseURL}/videos/extensions`;
|
|
3090
|
+
} else {
|
|
3091
|
+
endpoint = `${baseURL}/videos/generations`;
|
|
3092
|
+
}
|
|
3093
|
+
const { value: createResponse } = await (0, import_provider_utils19.postJsonToApi)({
|
|
3094
|
+
url: endpoint,
|
|
3095
|
+
headers: (0, import_provider_utils19.combineHeaders)(this.config.headers(), options.headers),
|
|
2898
3096
|
body,
|
|
2899
3097
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2900
|
-
successfulResponseHandler: (0,
|
|
3098
|
+
successfulResponseHandler: (0, import_provider_utils19.createJsonResponseHandler)(
|
|
2901
3099
|
xaiCreateVideoResponseSchema
|
|
2902
3100
|
),
|
|
2903
3101
|
abortSignal: options.abortSignal,
|
|
@@ -2915,17 +3113,17 @@ var XaiVideoModel = class {
|
|
|
2915
3113
|
const startTime = Date.now();
|
|
2916
3114
|
let responseHeaders;
|
|
2917
3115
|
while (true) {
|
|
2918
|
-
await (0,
|
|
3116
|
+
await (0, import_provider_utils19.delay)(pollIntervalMs, { abortSignal: options.abortSignal });
|
|
2919
3117
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2920
3118
|
throw new import_provider6.AISDKError({
|
|
2921
3119
|
name: "XAI_VIDEO_GENERATION_TIMEOUT",
|
|
2922
3120
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
2923
3121
|
});
|
|
2924
3122
|
}
|
|
2925
|
-
const { value: statusResponse, responseHeaders: pollHeaders } = await (0,
|
|
3123
|
+
const { value: statusResponse, responseHeaders: pollHeaders } = await (0, import_provider_utils19.getFromApi)({
|
|
2926
3124
|
url: `${baseURL}/videos/${requestId}`,
|
|
2927
|
-
headers: (0,
|
|
2928
|
-
successfulResponseHandler: (0,
|
|
3125
|
+
headers: (0, import_provider_utils19.combineHeaders)(this.config.headers(), options.headers),
|
|
3126
|
+
successfulResponseHandler: (0, import_provider_utils19.createJsonResponseHandler)(
|
|
2929
3127
|
xaiVideoStatusResponseSchema
|
|
2930
3128
|
),
|
|
2931
3129
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
@@ -2965,7 +3163,8 @@ var XaiVideoModel = class {
|
|
|
2965
3163
|
requestId,
|
|
2966
3164
|
videoUrl: statusResponse.video.url,
|
|
2967
3165
|
...statusResponse.video.duration != null ? { duration: statusResponse.video.duration } : {},
|
|
2968
|
-
...((_j = statusResponse.usage) == null ? void 0 : _j.cost_in_usd_ticks) != null ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks } : {}
|
|
3166
|
+
...((_j = statusResponse.usage) == null ? void 0 : _j.cost_in_usd_ticks) != null ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks } : {},
|
|
3167
|
+
...statusResponse.progress != null ? { progress: statusResponse.progress } : {}
|
|
2969
3168
|
}
|
|
2970
3169
|
}
|
|
2971
3170
|
};
|
|
@@ -2976,34 +3175,45 @@ var XaiVideoModel = class {
|
|
|
2976
3175
|
message: "Video generation request expired."
|
|
2977
3176
|
});
|
|
2978
3177
|
}
|
|
3178
|
+
if (statusResponse.status === "failed") {
|
|
3179
|
+
throw new import_provider6.AISDKError({
|
|
3180
|
+
name: "XAI_VIDEO_GENERATION_FAILED",
|
|
3181
|
+
message: "Video generation failed."
|
|
3182
|
+
});
|
|
3183
|
+
}
|
|
2979
3184
|
}
|
|
2980
3185
|
}
|
|
2981
3186
|
};
|
|
2982
|
-
var xaiCreateVideoResponseSchema =
|
|
2983
|
-
request_id:
|
|
3187
|
+
var xaiCreateVideoResponseSchema = import_v418.z.object({
|
|
3188
|
+
request_id: import_v418.z.string().nullish()
|
|
2984
3189
|
});
|
|
2985
|
-
var xaiVideoStatusResponseSchema =
|
|
2986
|
-
status:
|
|
2987
|
-
video:
|
|
2988
|
-
url:
|
|
2989
|
-
duration:
|
|
2990
|
-
respect_moderation:
|
|
3190
|
+
var xaiVideoStatusResponseSchema = import_v418.z.object({
|
|
3191
|
+
status: import_v418.z.string().nullish(),
|
|
3192
|
+
video: import_v418.z.object({
|
|
3193
|
+
url: import_v418.z.string(),
|
|
3194
|
+
duration: import_v418.z.number().nullish(),
|
|
3195
|
+
respect_moderation: import_v418.z.boolean().nullish()
|
|
3196
|
+
}).nullish(),
|
|
3197
|
+
model: import_v418.z.string().nullish(),
|
|
3198
|
+
usage: import_v418.z.object({
|
|
3199
|
+
cost_in_usd_ticks: import_v418.z.number().nullish()
|
|
2991
3200
|
}).nullish(),
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
3201
|
+
progress: import_v418.z.number().nullish(),
|
|
3202
|
+
error: import_v418.z.object({
|
|
3203
|
+
code: import_v418.z.string().nullish(),
|
|
3204
|
+
message: import_v418.z.string().nullish()
|
|
2995
3205
|
}).nullish()
|
|
2996
3206
|
});
|
|
2997
3207
|
|
|
2998
3208
|
// src/xai-provider.ts
|
|
2999
3209
|
function createXai(options = {}) {
|
|
3000
3210
|
var _a;
|
|
3001
|
-
const baseURL = (0,
|
|
3211
|
+
const baseURL = (0, import_provider_utils20.withoutTrailingSlash)(
|
|
3002
3212
|
(_a = options.baseURL) != null ? _a : "https://api.x.ai/v1"
|
|
3003
3213
|
);
|
|
3004
|
-
const getHeaders = () => (0,
|
|
3214
|
+
const getHeaders = () => (0, import_provider_utils20.withUserAgentSuffix)(
|
|
3005
3215
|
{
|
|
3006
|
-
Authorization: `Bearer ${(0,
|
|
3216
|
+
Authorization: `Bearer ${(0, import_provider_utils20.loadApiKey)({
|
|
3007
3217
|
apiKey: options.apiKey,
|
|
3008
3218
|
environmentVariableName: "XAI_API_KEY",
|
|
3009
3219
|
description: "xAI API key"
|
|
@@ -3017,7 +3227,7 @@ function createXai(options = {}) {
|
|
|
3017
3227
|
provider: "xai.chat",
|
|
3018
3228
|
baseURL,
|
|
3019
3229
|
headers: getHeaders,
|
|
3020
|
-
generateId:
|
|
3230
|
+
generateId: import_provider_utils20.generateId,
|
|
3021
3231
|
fetch: options.fetch
|
|
3022
3232
|
});
|
|
3023
3233
|
};
|
|
@@ -3026,7 +3236,7 @@ function createXai(options = {}) {
|
|
|
3026
3236
|
provider: "xai.responses",
|
|
3027
3237
|
baseURL,
|
|
3028
3238
|
headers: getHeaders,
|
|
3029
|
-
generateId:
|
|
3239
|
+
generateId: import_provider_utils20.generateId,
|
|
3030
3240
|
fetch: options.fetch
|
|
3031
3241
|
});
|
|
3032
3242
|
};
|
|
@@ -3046,6 +3256,12 @@ function createXai(options = {}) {
|
|
|
3046
3256
|
fetch: options.fetch
|
|
3047
3257
|
});
|
|
3048
3258
|
};
|
|
3259
|
+
const createFiles = () => new XaiFiles({
|
|
3260
|
+
provider: "xai.files",
|
|
3261
|
+
baseURL,
|
|
3262
|
+
headers: getHeaders,
|
|
3263
|
+
fetch: options.fetch
|
|
3264
|
+
});
|
|
3049
3265
|
const provider = (modelId) => createResponsesLanguageModel(modelId);
|
|
3050
3266
|
provider.specificationVersion = "v4";
|
|
3051
3267
|
provider.languageModel = createResponsesLanguageModel;
|
|
@@ -3059,6 +3275,7 @@ function createXai(options = {}) {
|
|
|
3059
3275
|
provider.image = createImageModel;
|
|
3060
3276
|
provider.videoModel = createVideoModel;
|
|
3061
3277
|
provider.video = createVideoModel;
|
|
3278
|
+
provider.files = createFiles;
|
|
3062
3279
|
provider.tools = xaiTools;
|
|
3063
3280
|
return provider;
|
|
3064
3281
|
}
|