@ai-sdk/xai 4.0.0-beta.2 → 4.0.0-beta.21
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 +156 -8
- package/README.md +2 -0
- package/dist/index.d.mts +51 -43
- package/dist/index.d.ts +51 -43
- package/dist/index.js +110 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -50
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +30 -336
- package/package.json +4 -6
- package/src/convert-to-xai-chat-messages.ts +5 -5
- package/src/convert-xai-chat-usage.ts +2 -2
- package/src/map-xai-finish-reason.ts +2 -2
- package/src/responses/convert-to-xai-responses-input.ts +7 -5
- package/src/responses/convert-xai-responses-usage.ts +2 -2
- package/src/responses/map-xai-responses-finish-reason.ts +2 -2
- package/src/responses/xai-responses-api.ts +3 -0
- package/src/responses/xai-responses-language-model.ts +71 -30
- package/src/responses/xai-responses-options.ts +4 -0
- package/src/responses/xai-responses-prepare-tools.ts +6 -6
- package/src/xai-chat-language-model.ts +41 -22
- package/src/xai-chat-options.ts +3 -6
- package/src/xai-image-model.ts +43 -28
- package/src/xai-image-options.ts +2 -0
- package/src/xai-image-settings.ts +0 -2
- package/src/xai-prepare-tools.ts +6 -6
- package/src/xai-provider.ts +18 -21
- package/src/xai-video-model.ts +23 -7
package/dist/index.js
CHANGED
|
@@ -18,8 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
VERSION: () => VERSION,
|
|
24
24
|
codeExecution: () => codeExecution,
|
|
25
25
|
createXai: () => createXai,
|
|
@@ -31,7 +31,7 @@ __export(src_exports, {
|
|
|
31
31
|
xai: () => xai,
|
|
32
32
|
xaiTools: () => xaiTools
|
|
33
33
|
});
|
|
34
|
-
module.exports = __toCommonJS(
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
35
|
|
|
36
36
|
// src/xai-provider.ts
|
|
37
37
|
var import_provider7 = require("@ai-sdk/provider");
|
|
@@ -370,7 +370,7 @@ function prepareTools({
|
|
|
370
370
|
// src/xai-chat-language-model.ts
|
|
371
371
|
var XaiChatLanguageModel = class {
|
|
372
372
|
constructor(modelId, config) {
|
|
373
|
-
this.specificationVersion = "
|
|
373
|
+
this.specificationVersion = "v4";
|
|
374
374
|
this.supportedUrls = {
|
|
375
375
|
"image/*": [/^https?:\/\/.*$/]
|
|
376
376
|
};
|
|
@@ -390,12 +390,13 @@ var XaiChatLanguageModel = class {
|
|
|
390
390
|
presencePenalty,
|
|
391
391
|
stopSequences,
|
|
392
392
|
seed,
|
|
393
|
+
reasoning,
|
|
393
394
|
responseFormat,
|
|
394
395
|
providerOptions,
|
|
395
396
|
tools,
|
|
396
397
|
toolChoice
|
|
397
398
|
}) {
|
|
398
|
-
var _a, _b, _c;
|
|
399
|
+
var _a, _b, _c, _d;
|
|
399
400
|
const warnings = [];
|
|
400
401
|
const options = (_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
401
402
|
provider: "xai",
|
|
@@ -435,14 +436,24 @@ var XaiChatLanguageModel = class {
|
|
|
435
436
|
temperature,
|
|
436
437
|
top_p: topP,
|
|
437
438
|
seed,
|
|
438
|
-
reasoning_effort: options.reasoningEffort,
|
|
439
|
+
reasoning_effort: (_b = options.reasoningEffort) != null ? _b : (0, import_provider_utils3.isCustomReasoning)(reasoning) ? reasoning === "none" ? void 0 : (0, import_provider_utils3.mapReasoningToProviderEffort)({
|
|
440
|
+
reasoning,
|
|
441
|
+
effortMap: {
|
|
442
|
+
minimal: "low",
|
|
443
|
+
low: "low",
|
|
444
|
+
medium: "low",
|
|
445
|
+
high: "high",
|
|
446
|
+
xhigh: "high"
|
|
447
|
+
},
|
|
448
|
+
warnings
|
|
449
|
+
}) : void 0,
|
|
439
450
|
// parallel function calling
|
|
440
451
|
parallel_function_calling: options.parallel_function_calling,
|
|
441
452
|
// response format
|
|
442
453
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
443
454
|
type: "json_schema",
|
|
444
455
|
json_schema: {
|
|
445
|
-
name: (
|
|
456
|
+
name: (_c = responseFormat.name) != null ? _c : "response",
|
|
446
457
|
schema: responseFormat.schema,
|
|
447
458
|
strict: true
|
|
448
459
|
}
|
|
@@ -454,7 +465,7 @@ var XaiChatLanguageModel = class {
|
|
|
454
465
|
from_date: options.searchParameters.fromDate,
|
|
455
466
|
to_date: options.searchParameters.toDate,
|
|
456
467
|
max_search_results: options.searchParameters.maxSearchResults,
|
|
457
|
-
sources: (
|
|
468
|
+
sources: (_d = options.searchParameters.sources) == null ? void 0 : _d.map((source) => {
|
|
458
469
|
var _a2;
|
|
459
470
|
return {
|
|
460
471
|
type: source.type,
|
|
@@ -893,7 +904,9 @@ var xaiImageModelOptions = import_v44.z.object({
|
|
|
893
904
|
aspect_ratio: import_v44.z.string().optional(),
|
|
894
905
|
output_format: import_v44.z.string().optional(),
|
|
895
906
|
sync_mode: import_v44.z.boolean().optional(),
|
|
896
|
-
resolution: import_v44.z.enum(["1k", "2k"]).optional()
|
|
907
|
+
resolution: import_v44.z.enum(["1k", "2k"]).optional(),
|
|
908
|
+
quality: import_v44.z.enum(["low", "medium", "high"]).optional(),
|
|
909
|
+
user: import_v44.z.string().optional()
|
|
897
910
|
});
|
|
898
911
|
|
|
899
912
|
// src/xai-image-model.ts
|
|
@@ -901,8 +914,8 @@ var XaiImageModel = class {
|
|
|
901
914
|
constructor(modelId, config) {
|
|
902
915
|
this.modelId = modelId;
|
|
903
916
|
this.config = config;
|
|
904
|
-
this.specificationVersion = "
|
|
905
|
-
this.maxImagesPerCall =
|
|
917
|
+
this.specificationVersion = "v4";
|
|
918
|
+
this.maxImagesPerCall = 3;
|
|
906
919
|
}
|
|
907
920
|
get provider() {
|
|
908
921
|
return this.config.provider;
|
|
@@ -919,7 +932,7 @@ var XaiImageModel = class {
|
|
|
919
932
|
files,
|
|
920
933
|
mask
|
|
921
934
|
}) {
|
|
922
|
-
var _a, _b, _c, _d;
|
|
935
|
+
var _a, _b, _c, _d, _e;
|
|
923
936
|
const warnings = [];
|
|
924
937
|
if (size != null) {
|
|
925
938
|
warnings.push({
|
|
@@ -946,22 +959,13 @@ var XaiImageModel = class {
|
|
|
946
959
|
schema: xaiImageModelOptions
|
|
947
960
|
});
|
|
948
961
|
const hasFiles = files != null && files.length > 0;
|
|
949
|
-
|
|
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
|
-
}
|
|
962
|
+
const imageUrls = hasFiles ? files.map((file) => (0, import_provider_utils4.convertImageModelFileToDataUri)(file)) : [];
|
|
959
963
|
const endpoint = hasFiles ? "/images/edits" : "/images/generations";
|
|
960
964
|
const body = {
|
|
961
965
|
model: this.modelId,
|
|
962
966
|
prompt,
|
|
963
967
|
n,
|
|
964
|
-
response_format: "
|
|
968
|
+
response_format: "b64_json"
|
|
965
969
|
};
|
|
966
970
|
if (aspectRatio != null) {
|
|
967
971
|
body.aspect_ratio = aspectRatio;
|
|
@@ -978,8 +982,16 @@ var XaiImageModel = class {
|
|
|
978
982
|
if ((xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
|
|
979
983
|
body.resolution = xaiOptions.resolution;
|
|
980
984
|
}
|
|
981
|
-
if (
|
|
982
|
-
body.
|
|
985
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.quality) != null) {
|
|
986
|
+
body.quality = xaiOptions.quality;
|
|
987
|
+
}
|
|
988
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.user) != null) {
|
|
989
|
+
body.user = xaiOptions.user;
|
|
990
|
+
}
|
|
991
|
+
if (imageUrls.length === 1) {
|
|
992
|
+
body.image = { url: imageUrls[0], type: "image_url" };
|
|
993
|
+
} else if (imageUrls.length > 1) {
|
|
994
|
+
body.images = imageUrls.map((url) => ({ url, type: "image_url" }));
|
|
983
995
|
}
|
|
984
996
|
const baseURL = (_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1";
|
|
985
997
|
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 +1006,14 @@ var XaiImageModel = class {
|
|
|
994
1006
|
abortSignal,
|
|
995
1007
|
fetch: this.config.fetch
|
|
996
1008
|
});
|
|
997
|
-
const
|
|
998
|
-
|
|
1009
|
+
const hasAllBase64 = response.data.every((image) => image.b64_json != null);
|
|
1010
|
+
const images = hasAllBase64 ? response.data.map((image) => image.b64_json) : await Promise.all(
|
|
1011
|
+
response.data.map(
|
|
1012
|
+
(image) => this.downloadImage(image.url, abortSignal)
|
|
1013
|
+
)
|
|
999
1014
|
);
|
|
1000
1015
|
return {
|
|
1001
|
-
images
|
|
1016
|
+
images,
|
|
1002
1017
|
warnings,
|
|
1003
1018
|
response: {
|
|
1004
1019
|
timestamp: currentDate,
|
|
@@ -1009,7 +1024,8 @@ var XaiImageModel = class {
|
|
|
1009
1024
|
xai: {
|
|
1010
1025
|
images: response.data.map((item) => ({
|
|
1011
1026
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {}
|
|
1012
|
-
}))
|
|
1027
|
+
})),
|
|
1028
|
+
...((_e = response.usage) == null ? void 0 : _e.cost_in_usd_ticks) != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
|
|
1013
1029
|
}
|
|
1014
1030
|
}
|
|
1015
1031
|
};
|
|
@@ -1028,10 +1044,14 @@ var XaiImageModel = class {
|
|
|
1028
1044
|
var xaiImageResponseSchema = import_v45.z.object({
|
|
1029
1045
|
data: import_v45.z.array(
|
|
1030
1046
|
import_v45.z.object({
|
|
1031
|
-
url: import_v45.z.string(),
|
|
1047
|
+
url: import_v45.z.string().nullish(),
|
|
1048
|
+
b64_json: import_v45.z.string().nullish(),
|
|
1032
1049
|
revised_prompt: import_v45.z.string().nullish()
|
|
1033
1050
|
})
|
|
1034
|
-
)
|
|
1051
|
+
),
|
|
1052
|
+
usage: import_v45.z.object({
|
|
1053
|
+
cost_in_usd_ticks: import_v45.z.number().nullish()
|
|
1054
|
+
}).nullish()
|
|
1035
1055
|
});
|
|
1036
1056
|
|
|
1037
1057
|
// src/responses/xai-responses-language-model.ts
|
|
@@ -1121,6 +1141,8 @@ async function convertToXaiResponsesInput({
|
|
|
1121
1141
|
break;
|
|
1122
1142
|
}
|
|
1123
1143
|
case "reasoning":
|
|
1144
|
+
case "reasoning-file":
|
|
1145
|
+
case "custom":
|
|
1124
1146
|
case "file": {
|
|
1125
1147
|
inputWarnings.push({
|
|
1126
1148
|
type: "other",
|
|
@@ -1336,6 +1358,7 @@ var outputItemSchema = import_v46.z.discriminatedUnion("type", [
|
|
|
1336
1358
|
type: import_v46.z.literal("reasoning"),
|
|
1337
1359
|
id: import_v46.z.string(),
|
|
1338
1360
|
summary: import_v46.z.array(reasoningSummaryPartSchema),
|
|
1361
|
+
content: import_v46.z.array(import_v46.z.object({ type: import_v46.z.string(), text: import_v46.z.string() })).nullish(),
|
|
1339
1362
|
status: import_v46.z.string(),
|
|
1340
1363
|
encrypted_content: import_v46.z.string().nullish()
|
|
1341
1364
|
})
|
|
@@ -1642,6 +1665,7 @@ var xaiLanguageModelResponsesOptions = import_v47.z.object({
|
|
|
1642
1665
|
* Possible values are `low` (uses fewer reasoning tokens), `medium` and `high` (uses more reasoning tokens).
|
|
1643
1666
|
*/
|
|
1644
1667
|
reasoningEffort: import_v47.z.enum(["low", "medium", "high"]).optional(),
|
|
1668
|
+
reasoningSummary: import_v47.z.enum(["auto", "concise", "detailed"]).optional(),
|
|
1645
1669
|
logprobs: import_v47.z.boolean().optional(),
|
|
1646
1670
|
topLogprobs: import_v47.z.number().int().min(0).max(8).optional(),
|
|
1647
1671
|
/**
|
|
@@ -1951,7 +1975,7 @@ async function prepareResponsesTools({
|
|
|
1951
1975
|
// src/responses/xai-responses-language-model.ts
|
|
1952
1976
|
var XaiResponsesLanguageModel = class {
|
|
1953
1977
|
constructor(modelId, config) {
|
|
1954
|
-
this.specificationVersion = "
|
|
1978
|
+
this.specificationVersion = "v4";
|
|
1955
1979
|
this.supportedUrls = {
|
|
1956
1980
|
"image/*": [/^https?:\/\/.*$/]
|
|
1957
1981
|
};
|
|
@@ -1971,9 +1995,10 @@ var XaiResponsesLanguageModel = class {
|
|
|
1971
1995
|
responseFormat,
|
|
1972
1996
|
providerOptions,
|
|
1973
1997
|
tools,
|
|
1974
|
-
toolChoice
|
|
1998
|
+
toolChoice,
|
|
1999
|
+
reasoning
|
|
1975
2000
|
}) {
|
|
1976
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2001
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1977
2002
|
const warnings = [];
|
|
1978
2003
|
const options = (_a = await (0, import_provider_utils11.parseProviderOptions)({
|
|
1979
2004
|
provider: "xai",
|
|
@@ -2020,6 +2045,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2020
2045
|
include = [...include, "reasoning.encrypted_content"];
|
|
2021
2046
|
}
|
|
2022
2047
|
}
|
|
2048
|
+
const resolvedReasoningEffort = (_g = options.reasoningEffort) != null ? _g : (0, import_provider_utils11.isCustomReasoning)(reasoning) ? reasoning === "none" ? void 0 : (0, import_provider_utils11.mapReasoningToProviderEffort)({
|
|
2049
|
+
reasoning,
|
|
2050
|
+
effortMap: {
|
|
2051
|
+
minimal: "low",
|
|
2052
|
+
low: "low",
|
|
2053
|
+
medium: "medium",
|
|
2054
|
+
high: "high",
|
|
2055
|
+
xhigh: "high"
|
|
2056
|
+
},
|
|
2057
|
+
warnings
|
|
2058
|
+
}) : void 0;
|
|
2023
2059
|
const baseArgs = {
|
|
2024
2060
|
model: this.modelId,
|
|
2025
2061
|
input,
|
|
@@ -2034,14 +2070,21 @@ var XaiResponsesLanguageModel = class {
|
|
|
2034
2070
|
format: responseFormat.schema != null ? {
|
|
2035
2071
|
type: "json_schema",
|
|
2036
2072
|
strict: true,
|
|
2037
|
-
name: (
|
|
2073
|
+
name: (_h = responseFormat.name) != null ? _h : "response",
|
|
2038
2074
|
description: responseFormat.description,
|
|
2039
2075
|
schema: responseFormat.schema
|
|
2040
2076
|
} : { type: "json_object" }
|
|
2041
2077
|
}
|
|
2042
2078
|
},
|
|
2043
|
-
...options.
|
|
2044
|
-
reasoning: {
|
|
2079
|
+
...(resolvedReasoningEffort != null || options.reasoningSummary != null) && {
|
|
2080
|
+
reasoning: {
|
|
2081
|
+
...resolvedReasoningEffort != null && {
|
|
2082
|
+
effort: resolvedReasoningEffort
|
|
2083
|
+
},
|
|
2084
|
+
...options.reasoningSummary != null && {
|
|
2085
|
+
summary: options.reasoningSummary
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2045
2088
|
},
|
|
2046
2089
|
...options.store === false && {
|
|
2047
2090
|
store: options.store
|
|
@@ -2070,7 +2113,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2070
2113
|
};
|
|
2071
2114
|
}
|
|
2072
2115
|
async doGenerate(options) {
|
|
2073
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2116
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2074
2117
|
const {
|
|
2075
2118
|
args: body,
|
|
2076
2119
|
warnings,
|
|
@@ -2096,6 +2139,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2096
2139
|
fetch: this.config.fetch
|
|
2097
2140
|
});
|
|
2098
2141
|
const content = [];
|
|
2142
|
+
let hasFunctionCall = false;
|
|
2099
2143
|
const webSearchSubTools = [
|
|
2100
2144
|
"web_search",
|
|
2101
2145
|
"web_search_with_snippets",
|
|
@@ -2180,6 +2224,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2180
2224
|
break;
|
|
2181
2225
|
}
|
|
2182
2226
|
case "function_call": {
|
|
2227
|
+
hasFunctionCall = true;
|
|
2183
2228
|
content.push({
|
|
2184
2229
|
type: "tool-call",
|
|
2185
2230
|
toolCallId: part.call_id,
|
|
@@ -2189,9 +2234,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
2189
2234
|
break;
|
|
2190
2235
|
}
|
|
2191
2236
|
case "reasoning": {
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
|
|
2237
|
+
const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : ((_m = part.content) != null ? _m : []).map((c) => c.text);
|
|
2238
|
+
const reasoningText = texts.filter((text) => text && text.length > 0).join("");
|
|
2239
|
+
if (reasoningText) {
|
|
2195
2240
|
if (part.encrypted_content || part.id) {
|
|
2196
2241
|
content.push({
|
|
2197
2242
|
type: "reasoning",
|
|
@@ -2222,8 +2267,8 @@ var XaiResponsesLanguageModel = class {
|
|
|
2222
2267
|
return {
|
|
2223
2268
|
content,
|
|
2224
2269
|
finishReason: {
|
|
2225
|
-
unified: mapXaiResponsesFinishReason(response.status),
|
|
2226
|
-
raw: (
|
|
2270
|
+
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response.status),
|
|
2271
|
+
raw: (_n = response.status) != null ? _n : void 0
|
|
2227
2272
|
},
|
|
2228
2273
|
usage: response.usage ? convertXaiResponsesUsage(response.usage) : {
|
|
2229
2274
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
@@ -2268,6 +2313,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2268
2313
|
unified: "other",
|
|
2269
2314
|
raw: void 0
|
|
2270
2315
|
};
|
|
2316
|
+
let hasFunctionCall = false;
|
|
2271
2317
|
let usage = void 0;
|
|
2272
2318
|
let isFirstChunk = true;
|
|
2273
2319
|
const contentBlocks = {};
|
|
@@ -2412,7 +2458,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2412
2458
|
}
|
|
2413
2459
|
if (response2.status) {
|
|
2414
2460
|
finishReason = {
|
|
2415
|
-
unified: mapXaiResponsesFinishReason(response2.status),
|
|
2461
|
+
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
|
|
2416
2462
|
raw: response2.status
|
|
2417
2463
|
};
|
|
2418
2464
|
}
|
|
@@ -2605,6 +2651,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2605
2651
|
toolName: part.name
|
|
2606
2652
|
});
|
|
2607
2653
|
} else if (event.type === "response.output_item.done") {
|
|
2654
|
+
hasFunctionCall = true;
|
|
2608
2655
|
ongoingToolCalls[event.output_index] = void 0;
|
|
2609
2656
|
controller.enqueue({
|
|
2610
2657
|
type: "tool-input-end",
|
|
@@ -2706,7 +2753,7 @@ var xaiTools = {
|
|
|
2706
2753
|
};
|
|
2707
2754
|
|
|
2708
2755
|
// src/version.ts
|
|
2709
|
-
var VERSION = true ? "4.0.0-beta.
|
|
2756
|
+
var VERSION = true ? "4.0.0-beta.21" : "0.0.0-test";
|
|
2710
2757
|
|
|
2711
2758
|
// src/xai-video-model.ts
|
|
2712
2759
|
var import_provider6 = require("@ai-sdk/provider");
|
|
@@ -2737,14 +2784,14 @@ var XaiVideoModel = class {
|
|
|
2737
2784
|
constructor(modelId, config) {
|
|
2738
2785
|
this.modelId = modelId;
|
|
2739
2786
|
this.config = config;
|
|
2740
|
-
this.specificationVersion = "
|
|
2787
|
+
this.specificationVersion = "v4";
|
|
2741
2788
|
this.maxVideosPerCall = 1;
|
|
2742
2789
|
}
|
|
2743
2790
|
get provider() {
|
|
2744
2791
|
return this.config.provider;
|
|
2745
2792
|
}
|
|
2746
2793
|
async doGenerate(options) {
|
|
2747
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2794
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2748
2795
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2749
2796
|
const warnings = [];
|
|
2750
2797
|
const xaiOptions = await (0, import_provider_utils16.parseProviderOptions)({
|
|
@@ -2887,7 +2934,13 @@ var XaiVideoModel = class {
|
|
|
2887
2934
|
});
|
|
2888
2935
|
responseHeaders = pollHeaders;
|
|
2889
2936
|
if (statusResponse.status === "done" || statusResponse.status == null && ((_g = statusResponse.video) == null ? void 0 : _g.url)) {
|
|
2890
|
-
if (
|
|
2937
|
+
if (((_h = statusResponse.video) == null ? void 0 : _h.respect_moderation) === false) {
|
|
2938
|
+
throw new import_provider6.AISDKError({
|
|
2939
|
+
name: "XAI_VIDEO_MODERATION_ERROR",
|
|
2940
|
+
message: "Video generation was blocked due to a content policy violation."
|
|
2941
|
+
});
|
|
2942
|
+
}
|
|
2943
|
+
if (!((_i = statusResponse.video) == null ? void 0 : _i.url)) {
|
|
2891
2944
|
throw new import_provider6.AISDKError({
|
|
2892
2945
|
name: "XAI_VIDEO_GENERATION_ERROR",
|
|
2893
2946
|
message: "Video generation completed but no video URL was returned."
|
|
@@ -2911,7 +2964,8 @@ var XaiVideoModel = class {
|
|
|
2911
2964
|
xai: {
|
|
2912
2965
|
requestId,
|
|
2913
2966
|
videoUrl: statusResponse.video.url,
|
|
2914
|
-
...statusResponse.video.duration != null ? { duration: statusResponse.video.duration } : {}
|
|
2967
|
+
...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 } : {}
|
|
2915
2969
|
}
|
|
2916
2970
|
}
|
|
2917
2971
|
};
|
|
@@ -2935,7 +2989,10 @@ var xaiVideoStatusResponseSchema = import_v416.z.object({
|
|
|
2935
2989
|
duration: import_v416.z.number().nullish(),
|
|
2936
2990
|
respect_moderation: import_v416.z.boolean().nullish()
|
|
2937
2991
|
}).nullish(),
|
|
2938
|
-
model: import_v416.z.string().nullish()
|
|
2992
|
+
model: import_v416.z.string().nullish(),
|
|
2993
|
+
usage: import_v416.z.object({
|
|
2994
|
+
cost_in_usd_ticks: import_v416.z.number().nullish()
|
|
2995
|
+
}).nullish()
|
|
2939
2996
|
});
|
|
2940
2997
|
|
|
2941
2998
|
// src/xai-provider.ts
|
|
@@ -2989,9 +3046,9 @@ function createXai(options = {}) {
|
|
|
2989
3046
|
fetch: options.fetch
|
|
2990
3047
|
});
|
|
2991
3048
|
};
|
|
2992
|
-
const provider = (modelId) =>
|
|
2993
|
-
provider.specificationVersion = "
|
|
2994
|
-
provider.languageModel =
|
|
3049
|
+
const provider = (modelId) => createResponsesLanguageModel(modelId);
|
|
3050
|
+
provider.specificationVersion = "v4";
|
|
3051
|
+
provider.languageModel = createResponsesLanguageModel;
|
|
2995
3052
|
provider.chat = createChatLanguageModel;
|
|
2996
3053
|
provider.responses = createResponsesLanguageModel;
|
|
2997
3054
|
provider.embeddingModel = (modelId) => {
|