@ai-sdk/xai 4.0.0-beta.3 → 4.0.0-beta.31
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 +230 -8
- package/README.md +2 -0
- package/dist/index.d.mts +132 -50
- package/dist/index.d.ts +132 -50
- package/dist/index.js +421 -94
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +433 -88
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +173 -381
- package/package.json +4 -6
- package/src/convert-to-xai-chat-messages.ts +22 -6
- package/src/convert-xai-chat-usage.ts +2 -2
- 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/map-xai-finish-reason.ts +2 -2
- package/src/responses/convert-to-xai-responses-input.ts +21 -7
- package/src/responses/convert-xai-responses-usage.ts +2 -2
- package/src/responses/map-xai-responses-finish-reason.ts +3 -2
- package/src/responses/xai-responses-api.ts +31 -1
- package/src/responses/xai-responses-language-model.ts +104 -32
- 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-chat-prompt.ts +2 -1
- package/src/xai-image-model.ts +35 -12
- 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 +34 -21
- package/src/xai-video-model.ts +127 -20
- package/src/xai-video-options.ts +136 -14
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,11 +31,11 @@ __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");
|
|
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 {
|
|
@@ -370,7 +381,7 @@ function prepareTools({
|
|
|
370
381
|
// src/xai-chat-language-model.ts
|
|
371
382
|
var XaiChatLanguageModel = class {
|
|
372
383
|
constructor(modelId, config) {
|
|
373
|
-
this.specificationVersion = "
|
|
384
|
+
this.specificationVersion = "v4";
|
|
374
385
|
this.supportedUrls = {
|
|
375
386
|
"image/*": [/^https?:\/\/.*$/]
|
|
376
387
|
};
|
|
@@ -390,12 +401,13 @@ var XaiChatLanguageModel = class {
|
|
|
390
401
|
presencePenalty,
|
|
391
402
|
stopSequences,
|
|
392
403
|
seed,
|
|
404
|
+
reasoning,
|
|
393
405
|
responseFormat,
|
|
394
406
|
providerOptions,
|
|
395
407
|
tools,
|
|
396
408
|
toolChoice
|
|
397
409
|
}) {
|
|
398
|
-
var _a, _b, _c;
|
|
410
|
+
var _a, _b, _c, _d;
|
|
399
411
|
const warnings = [];
|
|
400
412
|
const options = (_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
401
413
|
provider: "xai",
|
|
@@ -435,14 +447,24 @@ var XaiChatLanguageModel = class {
|
|
|
435
447
|
temperature,
|
|
436
448
|
top_p: topP,
|
|
437
449
|
seed,
|
|
438
|
-
reasoning_effort: options.reasoningEffort,
|
|
450
|
+
reasoning_effort: (_b = options.reasoningEffort) != null ? _b : (0, import_provider_utils3.isCustomReasoning)(reasoning) ? reasoning === "none" ? void 0 : (0, import_provider_utils3.mapReasoningToProviderEffort)({
|
|
451
|
+
reasoning,
|
|
452
|
+
effortMap: {
|
|
453
|
+
minimal: "low",
|
|
454
|
+
low: "low",
|
|
455
|
+
medium: "low",
|
|
456
|
+
high: "high",
|
|
457
|
+
xhigh: "high"
|
|
458
|
+
},
|
|
459
|
+
warnings
|
|
460
|
+
}) : void 0,
|
|
439
461
|
// parallel function calling
|
|
440
462
|
parallel_function_calling: options.parallel_function_calling,
|
|
441
463
|
// response format
|
|
442
464
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
443
465
|
type: "json_schema",
|
|
444
466
|
json_schema: {
|
|
445
|
-
name: (
|
|
467
|
+
name: (_c = responseFormat.name) != null ? _c : "response",
|
|
446
468
|
schema: responseFormat.schema,
|
|
447
469
|
strict: true
|
|
448
470
|
}
|
|
@@ -454,7 +476,7 @@ var XaiChatLanguageModel = class {
|
|
|
454
476
|
from_date: options.searchParameters.fromDate,
|
|
455
477
|
to_date: options.searchParameters.toDate,
|
|
456
478
|
max_search_results: options.searchParameters.maxSearchResults,
|
|
457
|
-
sources: (
|
|
479
|
+
sources: (_d = options.searchParameters.sources) == null ? void 0 : _d.map((source) => {
|
|
458
480
|
var _a2;
|
|
459
481
|
return {
|
|
460
482
|
type: source.type,
|
|
@@ -893,7 +915,9 @@ var xaiImageModelOptions = import_v44.z.object({
|
|
|
893
915
|
aspect_ratio: import_v44.z.string().optional(),
|
|
894
916
|
output_format: import_v44.z.string().optional(),
|
|
895
917
|
sync_mode: import_v44.z.boolean().optional(),
|
|
896
|
-
resolution: import_v44.z.enum(["1k", "2k"]).optional()
|
|
918
|
+
resolution: import_v44.z.enum(["1k", "2k"]).optional(),
|
|
919
|
+
quality: import_v44.z.enum(["low", "medium", "high"]).optional(),
|
|
920
|
+
user: import_v44.z.string().optional()
|
|
897
921
|
});
|
|
898
922
|
|
|
899
923
|
// src/xai-image-model.ts
|
|
@@ -901,7 +925,7 @@ var XaiImageModel = class {
|
|
|
901
925
|
constructor(modelId, config) {
|
|
902
926
|
this.modelId = modelId;
|
|
903
927
|
this.config = config;
|
|
904
|
-
this.specificationVersion = "
|
|
928
|
+
this.specificationVersion = "v4";
|
|
905
929
|
this.maxImagesPerCall = 3;
|
|
906
930
|
}
|
|
907
931
|
get provider() {
|
|
@@ -919,7 +943,7 @@ var XaiImageModel = class {
|
|
|
919
943
|
files,
|
|
920
944
|
mask
|
|
921
945
|
}) {
|
|
922
|
-
var _a, _b, _c, _d;
|
|
946
|
+
var _a, _b, _c, _d, _e;
|
|
923
947
|
const warnings = [];
|
|
924
948
|
if (size != null) {
|
|
925
949
|
warnings.push({
|
|
@@ -952,7 +976,7 @@ var XaiImageModel = class {
|
|
|
952
976
|
model: this.modelId,
|
|
953
977
|
prompt,
|
|
954
978
|
n,
|
|
955
|
-
response_format: "
|
|
979
|
+
response_format: "b64_json"
|
|
956
980
|
};
|
|
957
981
|
if (aspectRatio != null) {
|
|
958
982
|
body.aspect_ratio = aspectRatio;
|
|
@@ -969,6 +993,12 @@ var XaiImageModel = class {
|
|
|
969
993
|
if ((xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
|
|
970
994
|
body.resolution = xaiOptions.resolution;
|
|
971
995
|
}
|
|
996
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.quality) != null) {
|
|
997
|
+
body.quality = xaiOptions.quality;
|
|
998
|
+
}
|
|
999
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.user) != null) {
|
|
1000
|
+
body.user = xaiOptions.user;
|
|
1001
|
+
}
|
|
972
1002
|
if (imageUrls.length === 1) {
|
|
973
1003
|
body.image = { url: imageUrls[0], type: "image_url" };
|
|
974
1004
|
} else if (imageUrls.length > 1) {
|
|
@@ -987,11 +1017,14 @@ var XaiImageModel = class {
|
|
|
987
1017
|
abortSignal,
|
|
988
1018
|
fetch: this.config.fetch
|
|
989
1019
|
});
|
|
990
|
-
const
|
|
991
|
-
|
|
1020
|
+
const hasAllBase64 = response.data.every((image) => image.b64_json != null);
|
|
1021
|
+
const images = hasAllBase64 ? response.data.map((image) => image.b64_json) : await Promise.all(
|
|
1022
|
+
response.data.map(
|
|
1023
|
+
(image) => this.downloadImage(image.url, abortSignal)
|
|
1024
|
+
)
|
|
992
1025
|
);
|
|
993
1026
|
return {
|
|
994
|
-
images
|
|
1027
|
+
images,
|
|
995
1028
|
warnings,
|
|
996
1029
|
response: {
|
|
997
1030
|
timestamp: currentDate,
|
|
@@ -1002,7 +1035,8 @@ var XaiImageModel = class {
|
|
|
1002
1035
|
xai: {
|
|
1003
1036
|
images: response.data.map((item) => ({
|
|
1004
1037
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {}
|
|
1005
|
-
}))
|
|
1038
|
+
})),
|
|
1039
|
+
...((_e = response.usage) == null ? void 0 : _e.cost_in_usd_ticks) != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
|
|
1006
1040
|
}
|
|
1007
1041
|
}
|
|
1008
1042
|
};
|
|
@@ -1021,10 +1055,14 @@ var XaiImageModel = class {
|
|
|
1021
1055
|
var xaiImageResponseSchema = import_v45.z.object({
|
|
1022
1056
|
data: import_v45.z.array(
|
|
1023
1057
|
import_v45.z.object({
|
|
1024
|
-
url: import_v45.z.string(),
|
|
1058
|
+
url: import_v45.z.string().nullish(),
|
|
1059
|
+
b64_json: import_v45.z.string().nullish(),
|
|
1025
1060
|
revised_prompt: import_v45.z.string().nullish()
|
|
1026
1061
|
})
|
|
1027
|
-
)
|
|
1062
|
+
),
|
|
1063
|
+
usage: import_v45.z.object({
|
|
1064
|
+
cost_in_usd_ticks: import_v45.z.number().nullish()
|
|
1065
|
+
}).nullish()
|
|
1028
1066
|
});
|
|
1029
1067
|
|
|
1030
1068
|
// src/responses/xai-responses-language-model.ts
|
|
@@ -1057,7 +1095,15 @@ async function convertToXaiResponsesInput({
|
|
|
1057
1095
|
break;
|
|
1058
1096
|
}
|
|
1059
1097
|
case "file": {
|
|
1060
|
-
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/")) {
|
|
1061
1107
|
const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
|
|
1062
1108
|
const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils5.convertToBase64)(block.data)}`;
|
|
1063
1109
|
contentParts.push({ type: "input_image", image_url: imageUrl });
|
|
@@ -1114,6 +1160,8 @@ async function convertToXaiResponsesInput({
|
|
|
1114
1160
|
break;
|
|
1115
1161
|
}
|
|
1116
1162
|
case "reasoning":
|
|
1163
|
+
case "reasoning-file":
|
|
1164
|
+
case "custom":
|
|
1117
1165
|
case "file": {
|
|
1118
1166
|
inputWarnings.push({
|
|
1119
1167
|
type: "other",
|
|
@@ -1213,6 +1261,7 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
1213
1261
|
case "completed":
|
|
1214
1262
|
return "stop";
|
|
1215
1263
|
case "length":
|
|
1264
|
+
case "max_output_tokens":
|
|
1216
1265
|
return "length";
|
|
1217
1266
|
case "tool_calls":
|
|
1218
1267
|
case "function_call":
|
|
@@ -1329,6 +1378,7 @@ var outputItemSchema = import_v46.z.discriminatedUnion("type", [
|
|
|
1329
1378
|
type: import_v46.z.literal("reasoning"),
|
|
1330
1379
|
id: import_v46.z.string(),
|
|
1331
1380
|
summary: import_v46.z.array(reasoningSummaryPartSchema),
|
|
1381
|
+
content: import_v46.z.array(import_v46.z.object({ type: import_v46.z.string(), text: import_v46.z.string() })).nullish(),
|
|
1332
1382
|
status: import_v46.z.string(),
|
|
1333
1383
|
encrypted_content: import_v46.z.string().nullish()
|
|
1334
1384
|
})
|
|
@@ -1617,6 +1667,30 @@ var xaiResponsesChunkSchema = import_v46.z.union([
|
|
|
1617
1667
|
output_index: import_v46.z.number(),
|
|
1618
1668
|
output: import_v46.z.string().optional()
|
|
1619
1669
|
}),
|
|
1670
|
+
import_v46.z.object({
|
|
1671
|
+
type: import_v46.z.literal("response.incomplete"),
|
|
1672
|
+
response: import_v46.z.object({
|
|
1673
|
+
incomplete_details: import_v46.z.object({ reason: import_v46.z.string() }).nullish(),
|
|
1674
|
+
usage: xaiResponsesUsageSchema.nullish()
|
|
1675
|
+
})
|
|
1676
|
+
}),
|
|
1677
|
+
import_v46.z.object({
|
|
1678
|
+
type: import_v46.z.literal("response.failed"),
|
|
1679
|
+
response: import_v46.z.object({
|
|
1680
|
+
error: import_v46.z.object({
|
|
1681
|
+
code: import_v46.z.string().nullish(),
|
|
1682
|
+
message: import_v46.z.string()
|
|
1683
|
+
}).nullish(),
|
|
1684
|
+
incomplete_details: import_v46.z.object({ reason: import_v46.z.string() }).nullish(),
|
|
1685
|
+
usage: xaiResponsesUsageSchema.nullish()
|
|
1686
|
+
})
|
|
1687
|
+
}),
|
|
1688
|
+
import_v46.z.object({
|
|
1689
|
+
type: import_v46.z.literal("error"),
|
|
1690
|
+
code: import_v46.z.string().nullish(),
|
|
1691
|
+
message: import_v46.z.string(),
|
|
1692
|
+
param: import_v46.z.string().nullish()
|
|
1693
|
+
}),
|
|
1620
1694
|
import_v46.z.object({
|
|
1621
1695
|
type: import_v46.z.literal("response.done"),
|
|
1622
1696
|
response: xaiResponsesResponseSchema
|
|
@@ -1635,6 +1709,7 @@ var xaiLanguageModelResponsesOptions = import_v47.z.object({
|
|
|
1635
1709
|
* Possible values are `low` (uses fewer reasoning tokens), `medium` and `high` (uses more reasoning tokens).
|
|
1636
1710
|
*/
|
|
1637
1711
|
reasoningEffort: import_v47.z.enum(["low", "medium", "high"]).optional(),
|
|
1712
|
+
reasoningSummary: import_v47.z.enum(["auto", "concise", "detailed"]).optional(),
|
|
1638
1713
|
logprobs: import_v47.z.boolean().optional(),
|
|
1639
1714
|
topLogprobs: import_v47.z.number().int().min(0).max(8).optional(),
|
|
1640
1715
|
/**
|
|
@@ -1944,7 +2019,7 @@ async function prepareResponsesTools({
|
|
|
1944
2019
|
// src/responses/xai-responses-language-model.ts
|
|
1945
2020
|
var XaiResponsesLanguageModel = class {
|
|
1946
2021
|
constructor(modelId, config) {
|
|
1947
|
-
this.specificationVersion = "
|
|
2022
|
+
this.specificationVersion = "v4";
|
|
1948
2023
|
this.supportedUrls = {
|
|
1949
2024
|
"image/*": [/^https?:\/\/.*$/]
|
|
1950
2025
|
};
|
|
@@ -1964,9 +2039,10 @@ var XaiResponsesLanguageModel = class {
|
|
|
1964
2039
|
responseFormat,
|
|
1965
2040
|
providerOptions,
|
|
1966
2041
|
tools,
|
|
1967
|
-
toolChoice
|
|
2042
|
+
toolChoice,
|
|
2043
|
+
reasoning
|
|
1968
2044
|
}) {
|
|
1969
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2045
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1970
2046
|
const warnings = [];
|
|
1971
2047
|
const options = (_a = await (0, import_provider_utils11.parseProviderOptions)({
|
|
1972
2048
|
provider: "xai",
|
|
@@ -2013,6 +2089,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2013
2089
|
include = [...include, "reasoning.encrypted_content"];
|
|
2014
2090
|
}
|
|
2015
2091
|
}
|
|
2092
|
+
const resolvedReasoningEffort = (_g = options.reasoningEffort) != null ? _g : (0, import_provider_utils11.isCustomReasoning)(reasoning) ? reasoning === "none" ? void 0 : (0, import_provider_utils11.mapReasoningToProviderEffort)({
|
|
2093
|
+
reasoning,
|
|
2094
|
+
effortMap: {
|
|
2095
|
+
minimal: "low",
|
|
2096
|
+
low: "low",
|
|
2097
|
+
medium: "medium",
|
|
2098
|
+
high: "high",
|
|
2099
|
+
xhigh: "high"
|
|
2100
|
+
},
|
|
2101
|
+
warnings
|
|
2102
|
+
}) : void 0;
|
|
2016
2103
|
const baseArgs = {
|
|
2017
2104
|
model: this.modelId,
|
|
2018
2105
|
input,
|
|
@@ -2027,14 +2114,21 @@ var XaiResponsesLanguageModel = class {
|
|
|
2027
2114
|
format: responseFormat.schema != null ? {
|
|
2028
2115
|
type: "json_schema",
|
|
2029
2116
|
strict: true,
|
|
2030
|
-
name: (
|
|
2117
|
+
name: (_h = responseFormat.name) != null ? _h : "response",
|
|
2031
2118
|
description: responseFormat.description,
|
|
2032
2119
|
schema: responseFormat.schema
|
|
2033
2120
|
} : { type: "json_object" }
|
|
2034
2121
|
}
|
|
2035
2122
|
},
|
|
2036
|
-
...options.
|
|
2037
|
-
reasoning: {
|
|
2123
|
+
...(resolvedReasoningEffort != null || options.reasoningSummary != null) && {
|
|
2124
|
+
reasoning: {
|
|
2125
|
+
...resolvedReasoningEffort != null && {
|
|
2126
|
+
effort: resolvedReasoningEffort
|
|
2127
|
+
},
|
|
2128
|
+
...options.reasoningSummary != null && {
|
|
2129
|
+
summary: options.reasoningSummary
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2038
2132
|
},
|
|
2039
2133
|
...options.store === false && {
|
|
2040
2134
|
store: options.store
|
|
@@ -2063,7 +2157,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2063
2157
|
};
|
|
2064
2158
|
}
|
|
2065
2159
|
async doGenerate(options) {
|
|
2066
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2160
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2067
2161
|
const {
|
|
2068
2162
|
args: body,
|
|
2069
2163
|
warnings,
|
|
@@ -2089,6 +2183,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2089
2183
|
fetch: this.config.fetch
|
|
2090
2184
|
});
|
|
2091
2185
|
const content = [];
|
|
2186
|
+
let hasFunctionCall = false;
|
|
2092
2187
|
const webSearchSubTools = [
|
|
2093
2188
|
"web_search",
|
|
2094
2189
|
"web_search_with_snippets",
|
|
@@ -2173,6 +2268,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2173
2268
|
break;
|
|
2174
2269
|
}
|
|
2175
2270
|
case "function_call": {
|
|
2271
|
+
hasFunctionCall = true;
|
|
2176
2272
|
content.push({
|
|
2177
2273
|
type: "tool-call",
|
|
2178
2274
|
toolCallId: part.call_id,
|
|
@@ -2182,9 +2278,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
2182
2278
|
break;
|
|
2183
2279
|
}
|
|
2184
2280
|
case "reasoning": {
|
|
2185
|
-
const
|
|
2186
|
-
|
|
2187
|
-
|
|
2281
|
+
const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : ((_m = part.content) != null ? _m : []).map((c) => c.text);
|
|
2282
|
+
const reasoningText = texts.filter((text) => text && text.length > 0).join("");
|
|
2283
|
+
if (reasoningText) {
|
|
2188
2284
|
if (part.encrypted_content || part.id) {
|
|
2189
2285
|
content.push({
|
|
2190
2286
|
type: "reasoning",
|
|
@@ -2215,8 +2311,8 @@ var XaiResponsesLanguageModel = class {
|
|
|
2215
2311
|
return {
|
|
2216
2312
|
content,
|
|
2217
2313
|
finishReason: {
|
|
2218
|
-
unified: mapXaiResponsesFinishReason(response.status),
|
|
2219
|
-
raw: (
|
|
2314
|
+
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response.status),
|
|
2315
|
+
raw: (_n = response.status) != null ? _n : void 0
|
|
2220
2316
|
},
|
|
2221
2317
|
usage: response.usage ? convertXaiResponsesUsage(response.usage) : {
|
|
2222
2318
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
@@ -2261,6 +2357,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2261
2357
|
unified: "other",
|
|
2262
2358
|
raw: void 0
|
|
2263
2359
|
};
|
|
2360
|
+
let hasFunctionCall = false;
|
|
2264
2361
|
let usage = void 0;
|
|
2265
2362
|
let isFirstChunk = true;
|
|
2266
2363
|
const contentBlocks = {};
|
|
@@ -2275,7 +2372,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2275
2372
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2276
2373
|
},
|
|
2277
2374
|
transform(chunk, controller) {
|
|
2278
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2375
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2279
2376
|
if (options.includeRawChunks) {
|
|
2280
2377
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2281
2378
|
}
|
|
@@ -2398,19 +2495,40 @@ var XaiResponsesLanguageModel = class {
|
|
|
2398
2495
|
}
|
|
2399
2496
|
return;
|
|
2400
2497
|
}
|
|
2401
|
-
if (event.type === "response.done" || event.type === "response.completed") {
|
|
2498
|
+
if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
|
|
2402
2499
|
const response2 = event.response;
|
|
2403
2500
|
if (response2.usage) {
|
|
2404
2501
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
2405
2502
|
}
|
|
2406
|
-
if (
|
|
2503
|
+
if (event.type === "response.incomplete") {
|
|
2504
|
+
const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
|
|
2407
2505
|
finishReason = {
|
|
2408
|
-
unified: mapXaiResponsesFinishReason(
|
|
2506
|
+
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2507
|
+
raw: reason != null ? reason : "incomplete"
|
|
2508
|
+
};
|
|
2509
|
+
} else if ("status" in response2 && response2.status) {
|
|
2510
|
+
finishReason = {
|
|
2511
|
+
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
|
|
2409
2512
|
raw: response2.status
|
|
2410
2513
|
};
|
|
2411
2514
|
}
|
|
2412
2515
|
return;
|
|
2413
2516
|
}
|
|
2517
|
+
if (event.type === "response.failed") {
|
|
2518
|
+
const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
|
|
2519
|
+
finishReason = {
|
|
2520
|
+
unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
|
|
2521
|
+
raw: reason != null ? reason : "error"
|
|
2522
|
+
};
|
|
2523
|
+
if (event.response.usage) {
|
|
2524
|
+
usage = convertXaiResponsesUsage(event.response.usage);
|
|
2525
|
+
}
|
|
2526
|
+
return;
|
|
2527
|
+
}
|
|
2528
|
+
if (event.type === "error") {
|
|
2529
|
+
controller.enqueue({ type: "error", error: event });
|
|
2530
|
+
return;
|
|
2531
|
+
}
|
|
2414
2532
|
if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
|
|
2415
2533
|
return;
|
|
2416
2534
|
}
|
|
@@ -2493,13 +2611,13 @@ var XaiResponsesLanguageModel = class {
|
|
|
2493
2611
|
toolCallId: part.id,
|
|
2494
2612
|
toolName,
|
|
2495
2613
|
result: {
|
|
2496
|
-
queries: (
|
|
2497
|
-
results: (
|
|
2614
|
+
queries: (_e = part.queries) != null ? _e : [],
|
|
2615
|
+
results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
|
|
2498
2616
|
fileId: result.file_id,
|
|
2499
2617
|
filename: result.filename,
|
|
2500
2618
|
score: result.score,
|
|
2501
2619
|
text: result.text
|
|
2502
|
-
}))) != null ?
|
|
2620
|
+
}))) != null ? _g : null
|
|
2503
2621
|
}
|
|
2504
2622
|
});
|
|
2505
2623
|
}
|
|
@@ -2517,17 +2635,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2517
2635
|
"x_semantic_search",
|
|
2518
2636
|
"x_thread_fetch"
|
|
2519
2637
|
];
|
|
2520
|
-
let toolName = (
|
|
2521
|
-
if (webSearchSubTools.includes((
|
|
2638
|
+
let toolName = (_h = part.name) != null ? _h : "";
|
|
2639
|
+
if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
|
|
2522
2640
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
2523
|
-
} else if (xSearchSubTools.includes((
|
|
2641
|
+
} else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
|
|
2524
2642
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2525
2643
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2526
2644
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2527
2645
|
} else if (part.type === "mcp_call") {
|
|
2528
|
-
toolName = (
|
|
2646
|
+
toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
|
|
2529
2647
|
}
|
|
2530
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2648
|
+
const toolInput = part.type === "custom_tool_call" ? (_l = part.input) != null ? _l : "" : part.type === "mcp_call" ? (_m = part.arguments) != null ? _m : "" : (_n = part.arguments) != null ? _n : "";
|
|
2531
2649
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2532
2650
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2533
2651
|
seenToolCalls.add(part.id);
|
|
@@ -2580,7 +2698,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2580
2698
|
sourceType: "url",
|
|
2581
2699
|
id: self.config.generateId(),
|
|
2582
2700
|
url: annotation.url,
|
|
2583
|
-
title: (
|
|
2701
|
+
title: (_o = annotation.title) != null ? _o : annotation.url
|
|
2584
2702
|
});
|
|
2585
2703
|
}
|
|
2586
2704
|
}
|
|
@@ -2598,6 +2716,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2598
2716
|
toolName: part.name
|
|
2599
2717
|
});
|
|
2600
2718
|
} else if (event.type === "response.output_item.done") {
|
|
2719
|
+
hasFunctionCall = true;
|
|
2601
2720
|
ongoingToolCalls[event.output_index] = void 0;
|
|
2602
2721
|
controller.enqueue({
|
|
2603
2722
|
type: "tool-input-end",
|
|
@@ -2699,53 +2818,197 @@ var xaiTools = {
|
|
|
2699
2818
|
};
|
|
2700
2819
|
|
|
2701
2820
|
// src/version.ts
|
|
2702
|
-
var VERSION = true ? "4.0.0-beta.
|
|
2821
|
+
var VERSION = true ? "4.0.0-beta.31" : "0.0.0-test";
|
|
2703
2822
|
|
|
2704
|
-
// src/xai-
|
|
2705
|
-
var
|
|
2706
|
-
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
2707
|
-
var import_v416 = require("zod/v4");
|
|
2823
|
+
// src/files/xai-files.ts
|
|
2824
|
+
var import_provider_utils17 = require("@ai-sdk/provider-utils");
|
|
2708
2825
|
|
|
2709
|
-
// src/xai-
|
|
2826
|
+
// src/files/xai-files-api.ts
|
|
2710
2827
|
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
2711
2828
|
var import_v415 = require("zod/v4");
|
|
2712
|
-
var
|
|
2829
|
+
var xaiFilesResponseSchema = (0, import_provider_utils15.lazySchema)(
|
|
2713
2830
|
() => (0, import_provider_utils15.zodSchema)(
|
|
2714
2831
|
import_v415.z.object({
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2832
|
+
id: import_v415.z.string(),
|
|
2833
|
+
object: import_v415.z.string().nullish(),
|
|
2834
|
+
bytes: import_v415.z.number().nullish(),
|
|
2835
|
+
created_at: import_v415.z.number().nullish(),
|
|
2836
|
+
filename: import_v415.z.string().nullish(),
|
|
2837
|
+
purpose: import_v415.z.string().nullish(),
|
|
2838
|
+
status: import_v415.z.string().nullish()
|
|
2839
|
+
})
|
|
2840
|
+
)
|
|
2841
|
+
);
|
|
2842
|
+
|
|
2843
|
+
// src/files/xai-files-options.ts
|
|
2844
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
2845
|
+
var import_v416 = require("zod/v4");
|
|
2846
|
+
var xaiFilesOptionsSchema = (0, import_provider_utils16.lazySchema)(
|
|
2847
|
+
() => (0, import_provider_utils16.zodSchema)(
|
|
2848
|
+
import_v416.z.object({
|
|
2849
|
+
teamId: import_v416.z.string().optional(),
|
|
2850
|
+
filePath: import_v416.z.string().optional()
|
|
2719
2851
|
}).passthrough()
|
|
2720
2852
|
)
|
|
2721
2853
|
);
|
|
2722
2854
|
|
|
2855
|
+
// src/files/xai-files.ts
|
|
2856
|
+
var XaiFiles = class {
|
|
2857
|
+
constructor(config) {
|
|
2858
|
+
this.config = config;
|
|
2859
|
+
this.specificationVersion = "v4";
|
|
2860
|
+
}
|
|
2861
|
+
get provider() {
|
|
2862
|
+
return this.config.provider;
|
|
2863
|
+
}
|
|
2864
|
+
async uploadFile({
|
|
2865
|
+
data,
|
|
2866
|
+
mediaType,
|
|
2867
|
+
filename,
|
|
2868
|
+
providerOptions
|
|
2869
|
+
}) {
|
|
2870
|
+
var _a, _b;
|
|
2871
|
+
const xaiOptions = await (0, import_provider_utils17.parseProviderOptions)({
|
|
2872
|
+
provider: "xai",
|
|
2873
|
+
providerOptions,
|
|
2874
|
+
schema: xaiFilesOptionsSchema
|
|
2875
|
+
});
|
|
2876
|
+
const fileBytes = data instanceof Uint8Array ? data : (0, import_provider_utils17.convertBase64ToUint8Array)(data);
|
|
2877
|
+
const blob = new Blob([fileBytes], {
|
|
2878
|
+
type: mediaType
|
|
2879
|
+
});
|
|
2880
|
+
const formData = new FormData();
|
|
2881
|
+
if (filename != null) {
|
|
2882
|
+
formData.append("file", blob, filename);
|
|
2883
|
+
} else {
|
|
2884
|
+
formData.append("file", blob);
|
|
2885
|
+
}
|
|
2886
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.teamId) != null) {
|
|
2887
|
+
formData.append("team_id", xaiOptions.teamId);
|
|
2888
|
+
}
|
|
2889
|
+
const { value: response } = await (0, import_provider_utils17.postFormDataToApi)({
|
|
2890
|
+
url: `${this.config.baseURL}/files`,
|
|
2891
|
+
headers: (0, import_provider_utils17.combineHeaders)(this.config.headers()),
|
|
2892
|
+
formData,
|
|
2893
|
+
failedResponseHandler: xaiFailedResponseHandler,
|
|
2894
|
+
successfulResponseHandler: (0, import_provider_utils17.createJsonResponseHandler)(
|
|
2895
|
+
xaiFilesResponseSchema
|
|
2896
|
+
),
|
|
2897
|
+
fetch: this.config.fetch
|
|
2898
|
+
});
|
|
2899
|
+
return {
|
|
2900
|
+
warnings: [],
|
|
2901
|
+
providerReference: { xai: response.id },
|
|
2902
|
+
...((_a = response.filename) != null ? _a : filename) ? { filename: (_b = response.filename) != null ? _b : filename } : {},
|
|
2903
|
+
...mediaType != null ? { mediaType } : {},
|
|
2904
|
+
providerMetadata: {
|
|
2905
|
+
xai: {
|
|
2906
|
+
...response.filename != null ? { filename: response.filename } : {},
|
|
2907
|
+
...response.bytes != null ? { bytes: response.bytes } : {},
|
|
2908
|
+
...response.created_at != null ? { createdAt: response.created_at } : {}
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
};
|
|
2912
|
+
}
|
|
2913
|
+
};
|
|
2914
|
+
|
|
2915
|
+
// src/xai-video-model.ts
|
|
2916
|
+
var import_provider6 = require("@ai-sdk/provider");
|
|
2917
|
+
var import_provider_utils19 = require("@ai-sdk/provider-utils");
|
|
2918
|
+
var import_v418 = require("zod/v4");
|
|
2919
|
+
|
|
2920
|
+
// src/xai-video-options.ts
|
|
2921
|
+
var import_provider_utils18 = require("@ai-sdk/provider-utils");
|
|
2922
|
+
var import_v417 = require("zod/v4");
|
|
2923
|
+
var nonEmptyStringSchema = import_v417.z.string().min(1);
|
|
2924
|
+
var resolutionSchema = import_v417.z.enum(["480p", "720p"]);
|
|
2925
|
+
var modeSchema = import_v417.z.enum(["edit-video", "extend-video", "reference-to-video"]);
|
|
2926
|
+
var baseFields = {
|
|
2927
|
+
pollIntervalMs: import_v417.z.number().positive().nullish(),
|
|
2928
|
+
pollTimeoutMs: import_v417.z.number().positive().nullish(),
|
|
2929
|
+
resolution: resolutionSchema.nullish()
|
|
2930
|
+
};
|
|
2931
|
+
var editVideoSchema = import_v417.z.object({
|
|
2932
|
+
...baseFields,
|
|
2933
|
+
mode: import_v417.z.literal("edit-video"),
|
|
2934
|
+
videoUrl: nonEmptyStringSchema,
|
|
2935
|
+
referenceImageUrls: import_v417.z.undefined().optional()
|
|
2936
|
+
});
|
|
2937
|
+
var extendVideoSchema = import_v417.z.object({
|
|
2938
|
+
...baseFields,
|
|
2939
|
+
mode: import_v417.z.literal("extend-video"),
|
|
2940
|
+
videoUrl: nonEmptyStringSchema,
|
|
2941
|
+
referenceImageUrls: import_v417.z.undefined().optional()
|
|
2942
|
+
});
|
|
2943
|
+
var referenceToVideoSchema = import_v417.z.object({
|
|
2944
|
+
...baseFields,
|
|
2945
|
+
mode: import_v417.z.literal("reference-to-video"),
|
|
2946
|
+
referenceImageUrls: import_v417.z.array(nonEmptyStringSchema).min(1).max(7),
|
|
2947
|
+
videoUrl: import_v417.z.undefined().optional()
|
|
2948
|
+
});
|
|
2949
|
+
var autoDetectSchema = import_v417.z.object({
|
|
2950
|
+
...baseFields,
|
|
2951
|
+
mode: import_v417.z.undefined().optional(),
|
|
2952
|
+
videoUrl: nonEmptyStringSchema.optional(),
|
|
2953
|
+
referenceImageUrls: import_v417.z.array(nonEmptyStringSchema).min(1).max(7).optional()
|
|
2954
|
+
});
|
|
2955
|
+
var xaiVideoModelOptions = import_v417.z.union([
|
|
2956
|
+
editVideoSchema,
|
|
2957
|
+
extendVideoSchema,
|
|
2958
|
+
referenceToVideoSchema,
|
|
2959
|
+
autoDetectSchema
|
|
2960
|
+
]);
|
|
2961
|
+
var runtimeSchema = import_v417.z.object({
|
|
2962
|
+
mode: modeSchema.optional(),
|
|
2963
|
+
videoUrl: nonEmptyStringSchema.optional(),
|
|
2964
|
+
referenceImageUrls: import_v417.z.array(nonEmptyStringSchema).min(1).max(7).optional(),
|
|
2965
|
+
...baseFields
|
|
2966
|
+
}).passthrough();
|
|
2967
|
+
var xaiVideoModelOptionsSchema = (0, import_provider_utils18.lazySchema)(
|
|
2968
|
+
() => (0, import_provider_utils18.zodSchema)(runtimeSchema)
|
|
2969
|
+
);
|
|
2970
|
+
|
|
2723
2971
|
// src/xai-video-model.ts
|
|
2724
2972
|
var RESOLUTION_MAP = {
|
|
2725
2973
|
"1280x720": "720p",
|
|
2726
2974
|
"854x480": "480p",
|
|
2727
2975
|
"640x480": "480p"
|
|
2728
2976
|
};
|
|
2977
|
+
function resolveVideoMode(options) {
|
|
2978
|
+
if ((options == null ? void 0 : options.mode) != null) {
|
|
2979
|
+
return options.mode;
|
|
2980
|
+
}
|
|
2981
|
+
if ((options == null ? void 0 : options.videoUrl) != null) {
|
|
2982
|
+
return "edit-video";
|
|
2983
|
+
}
|
|
2984
|
+
if ((options == null ? void 0 : options.referenceImageUrls) != null && options.referenceImageUrls.length > 0) {
|
|
2985
|
+
return "reference-to-video";
|
|
2986
|
+
}
|
|
2987
|
+
return void 0;
|
|
2988
|
+
}
|
|
2729
2989
|
var XaiVideoModel = class {
|
|
2730
2990
|
constructor(modelId, config) {
|
|
2731
2991
|
this.modelId = modelId;
|
|
2732
2992
|
this.config = config;
|
|
2733
|
-
this.specificationVersion = "
|
|
2993
|
+
this.specificationVersion = "v4";
|
|
2734
2994
|
this.maxVideosPerCall = 1;
|
|
2735
2995
|
}
|
|
2736
2996
|
get provider() {
|
|
2737
2997
|
return this.config.provider;
|
|
2738
2998
|
}
|
|
2739
2999
|
async doGenerate(options) {
|
|
2740
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3000
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2741
3001
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2742
3002
|
const warnings = [];
|
|
2743
|
-
const xaiOptions = await (0,
|
|
3003
|
+
const xaiOptions = await (0, import_provider_utils19.parseProviderOptions)({
|
|
2744
3004
|
provider: "xai",
|
|
2745
3005
|
providerOptions: options.providerOptions,
|
|
2746
3006
|
schema: xaiVideoModelOptionsSchema
|
|
2747
3007
|
});
|
|
2748
|
-
const
|
|
3008
|
+
const effectiveMode = resolveVideoMode(xaiOptions);
|
|
3009
|
+
const isEdit = effectiveMode === "edit-video";
|
|
3010
|
+
const isExtension = effectiveMode === "extend-video";
|
|
3011
|
+
const hasReferenceImages = effectiveMode === "reference-to-video";
|
|
2749
3012
|
if (options.fps != null) {
|
|
2750
3013
|
warnings.push({
|
|
2751
3014
|
type: "unsupported",
|
|
@@ -2788,19 +3051,36 @@ var XaiVideoModel = class {
|
|
|
2788
3051
|
details: "xAI video editing does not support custom resolution."
|
|
2789
3052
|
});
|
|
2790
3053
|
}
|
|
3054
|
+
if (isExtension && options.aspectRatio != null) {
|
|
3055
|
+
warnings.push({
|
|
3056
|
+
type: "unsupported",
|
|
3057
|
+
feature: "aspectRatio",
|
|
3058
|
+
details: "xAI video extension does not support custom aspect ratio."
|
|
3059
|
+
});
|
|
3060
|
+
}
|
|
3061
|
+
if (isExtension && ((xaiOptions == null ? void 0 : xaiOptions.resolution) != null || options.resolution != null)) {
|
|
3062
|
+
warnings.push({
|
|
3063
|
+
type: "unsupported",
|
|
3064
|
+
feature: "resolution",
|
|
3065
|
+
details: "xAI video extension does not support custom resolution."
|
|
3066
|
+
});
|
|
3067
|
+
}
|
|
2791
3068
|
const body = {
|
|
2792
3069
|
model: this.modelId,
|
|
2793
3070
|
prompt: options.prompt
|
|
2794
3071
|
};
|
|
2795
|
-
|
|
3072
|
+
const allowDuration = !isEdit;
|
|
3073
|
+
const allowAspectRatio = !isEdit && !isExtension;
|
|
3074
|
+
const allowResolution = !isEdit && !isExtension;
|
|
3075
|
+
if (allowDuration && options.duration != null) {
|
|
2796
3076
|
body.duration = options.duration;
|
|
2797
3077
|
}
|
|
2798
|
-
if (
|
|
3078
|
+
if (allowAspectRatio && options.aspectRatio != null) {
|
|
2799
3079
|
body.aspect_ratio = options.aspectRatio;
|
|
2800
3080
|
}
|
|
2801
|
-
if (
|
|
3081
|
+
if (allowResolution && (xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
|
|
2802
3082
|
body.resolution = xaiOptions.resolution;
|
|
2803
|
-
} else if (
|
|
3083
|
+
} else if (allowResolution && options.resolution != null) {
|
|
2804
3084
|
const mapped = RESOLUTION_MAP[options.resolution];
|
|
2805
3085
|
if (mapped != null) {
|
|
2806
3086
|
body.resolution = mapped;
|
|
@@ -2812,38 +3092,56 @@ var XaiVideoModel = class {
|
|
|
2812
3092
|
});
|
|
2813
3093
|
}
|
|
2814
3094
|
}
|
|
2815
|
-
if (
|
|
3095
|
+
if (isEdit) {
|
|
3096
|
+
body.video = { url: xaiOptions.videoUrl };
|
|
3097
|
+
}
|
|
3098
|
+
if (isExtension) {
|
|
2816
3099
|
body.video = { url: xaiOptions.videoUrl };
|
|
2817
3100
|
}
|
|
2818
3101
|
if (options.image != null) {
|
|
2819
3102
|
if (options.image.type === "url") {
|
|
2820
3103
|
body.image = { url: options.image.url };
|
|
2821
3104
|
} else {
|
|
2822
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (0,
|
|
3105
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils19.convertUint8ArrayToBase64)(options.image.data);
|
|
2823
3106
|
body.image = {
|
|
2824
3107
|
url: `data:${options.image.mediaType};base64,${base64Data}`
|
|
2825
3108
|
};
|
|
2826
3109
|
}
|
|
2827
3110
|
}
|
|
3111
|
+
if (hasReferenceImages) {
|
|
3112
|
+
body.reference_images = xaiOptions.referenceImageUrls.map((url) => ({
|
|
3113
|
+
url
|
|
3114
|
+
}));
|
|
3115
|
+
}
|
|
2828
3116
|
if (xaiOptions != null) {
|
|
2829
3117
|
for (const [key, value] of Object.entries(xaiOptions)) {
|
|
2830
3118
|
if (![
|
|
3119
|
+
"mode",
|
|
2831
3120
|
"pollIntervalMs",
|
|
2832
3121
|
"pollTimeoutMs",
|
|
2833
3122
|
"resolution",
|
|
2834
|
-
"videoUrl"
|
|
3123
|
+
"videoUrl",
|
|
3124
|
+
"referenceImageUrls"
|
|
2835
3125
|
].includes(key)) {
|
|
2836
3126
|
body[key] = value;
|
|
2837
3127
|
}
|
|
2838
3128
|
}
|
|
2839
3129
|
}
|
|
2840
3130
|
const baseURL = (_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1";
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
3131
|
+
let endpoint;
|
|
3132
|
+
if (isEdit) {
|
|
3133
|
+
endpoint = `${baseURL}/videos/edits`;
|
|
3134
|
+
} else if (isExtension) {
|
|
3135
|
+
endpoint = `${baseURL}/videos/extensions`;
|
|
3136
|
+
} else {
|
|
3137
|
+
endpoint = `${baseURL}/videos/generations`;
|
|
3138
|
+
}
|
|
3139
|
+
const { value: createResponse } = await (0, import_provider_utils19.postJsonToApi)({
|
|
3140
|
+
url: endpoint,
|
|
3141
|
+
headers: (0, import_provider_utils19.combineHeaders)(this.config.headers(), options.headers),
|
|
2844
3142
|
body,
|
|
2845
3143
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2846
|
-
successfulResponseHandler: (0,
|
|
3144
|
+
successfulResponseHandler: (0, import_provider_utils19.createJsonResponseHandler)(
|
|
2847
3145
|
xaiCreateVideoResponseSchema
|
|
2848
3146
|
),
|
|
2849
3147
|
abortSignal: options.abortSignal,
|
|
@@ -2861,17 +3159,17 @@ var XaiVideoModel = class {
|
|
|
2861
3159
|
const startTime = Date.now();
|
|
2862
3160
|
let responseHeaders;
|
|
2863
3161
|
while (true) {
|
|
2864
|
-
await (0,
|
|
3162
|
+
await (0, import_provider_utils19.delay)(pollIntervalMs, { abortSignal: options.abortSignal });
|
|
2865
3163
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2866
3164
|
throw new import_provider6.AISDKError({
|
|
2867
3165
|
name: "XAI_VIDEO_GENERATION_TIMEOUT",
|
|
2868
3166
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
2869
3167
|
});
|
|
2870
3168
|
}
|
|
2871
|
-
const { value: statusResponse, responseHeaders: pollHeaders } = await (0,
|
|
3169
|
+
const { value: statusResponse, responseHeaders: pollHeaders } = await (0, import_provider_utils19.getFromApi)({
|
|
2872
3170
|
url: `${baseURL}/videos/${requestId}`,
|
|
2873
|
-
headers: (0,
|
|
2874
|
-
successfulResponseHandler: (0,
|
|
3171
|
+
headers: (0, import_provider_utils19.combineHeaders)(this.config.headers(), options.headers),
|
|
3172
|
+
successfulResponseHandler: (0, import_provider_utils19.createJsonResponseHandler)(
|
|
2875
3173
|
xaiVideoStatusResponseSchema
|
|
2876
3174
|
),
|
|
2877
3175
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
@@ -2880,7 +3178,13 @@ var XaiVideoModel = class {
|
|
|
2880
3178
|
});
|
|
2881
3179
|
responseHeaders = pollHeaders;
|
|
2882
3180
|
if (statusResponse.status === "done" || statusResponse.status == null && ((_g = statusResponse.video) == null ? void 0 : _g.url)) {
|
|
2883
|
-
if (
|
|
3181
|
+
if (((_h = statusResponse.video) == null ? void 0 : _h.respect_moderation) === false) {
|
|
3182
|
+
throw new import_provider6.AISDKError({
|
|
3183
|
+
name: "XAI_VIDEO_MODERATION_ERROR",
|
|
3184
|
+
message: "Video generation was blocked due to a content policy violation."
|
|
3185
|
+
});
|
|
3186
|
+
}
|
|
3187
|
+
if (!((_i = statusResponse.video) == null ? void 0 : _i.url)) {
|
|
2884
3188
|
throw new import_provider6.AISDKError({
|
|
2885
3189
|
name: "XAI_VIDEO_GENERATION_ERROR",
|
|
2886
3190
|
message: "Video generation completed but no video URL was returned."
|
|
@@ -2904,7 +3208,9 @@ var XaiVideoModel = class {
|
|
|
2904
3208
|
xai: {
|
|
2905
3209
|
requestId,
|
|
2906
3210
|
videoUrl: statusResponse.video.url,
|
|
2907
|
-
...statusResponse.video.duration != null ? { duration: statusResponse.video.duration } : {}
|
|
3211
|
+
...statusResponse.video.duration != null ? { duration: statusResponse.video.duration } : {},
|
|
3212
|
+
...((_j = statusResponse.usage) == null ? void 0 : _j.cost_in_usd_ticks) != null ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks } : {},
|
|
3213
|
+
...statusResponse.progress != null ? { progress: statusResponse.progress } : {}
|
|
2908
3214
|
}
|
|
2909
3215
|
}
|
|
2910
3216
|
};
|
|
@@ -2915,31 +3221,45 @@ var XaiVideoModel = class {
|
|
|
2915
3221
|
message: "Video generation request expired."
|
|
2916
3222
|
});
|
|
2917
3223
|
}
|
|
3224
|
+
if (statusResponse.status === "failed") {
|
|
3225
|
+
throw new import_provider6.AISDKError({
|
|
3226
|
+
name: "XAI_VIDEO_GENERATION_FAILED",
|
|
3227
|
+
message: "Video generation failed."
|
|
3228
|
+
});
|
|
3229
|
+
}
|
|
2918
3230
|
}
|
|
2919
3231
|
}
|
|
2920
3232
|
};
|
|
2921
|
-
var xaiCreateVideoResponseSchema =
|
|
2922
|
-
request_id:
|
|
3233
|
+
var xaiCreateVideoResponseSchema = import_v418.z.object({
|
|
3234
|
+
request_id: import_v418.z.string().nullish()
|
|
2923
3235
|
});
|
|
2924
|
-
var xaiVideoStatusResponseSchema =
|
|
2925
|
-
status:
|
|
2926
|
-
video:
|
|
2927
|
-
url:
|
|
2928
|
-
duration:
|
|
2929
|
-
respect_moderation:
|
|
3236
|
+
var xaiVideoStatusResponseSchema = import_v418.z.object({
|
|
3237
|
+
status: import_v418.z.string().nullish(),
|
|
3238
|
+
video: import_v418.z.object({
|
|
3239
|
+
url: import_v418.z.string(),
|
|
3240
|
+
duration: import_v418.z.number().nullish(),
|
|
3241
|
+
respect_moderation: import_v418.z.boolean().nullish()
|
|
3242
|
+
}).nullish(),
|
|
3243
|
+
model: import_v418.z.string().nullish(),
|
|
3244
|
+
usage: import_v418.z.object({
|
|
3245
|
+
cost_in_usd_ticks: import_v418.z.number().nullish()
|
|
2930
3246
|
}).nullish(),
|
|
2931
|
-
|
|
3247
|
+
progress: import_v418.z.number().nullish(),
|
|
3248
|
+
error: import_v418.z.object({
|
|
3249
|
+
code: import_v418.z.string().nullish(),
|
|
3250
|
+
message: import_v418.z.string().nullish()
|
|
3251
|
+
}).nullish()
|
|
2932
3252
|
});
|
|
2933
3253
|
|
|
2934
3254
|
// src/xai-provider.ts
|
|
2935
3255
|
function createXai(options = {}) {
|
|
2936
3256
|
var _a;
|
|
2937
|
-
const baseURL = (0,
|
|
3257
|
+
const baseURL = (0, import_provider_utils20.withoutTrailingSlash)(
|
|
2938
3258
|
(_a = options.baseURL) != null ? _a : "https://api.x.ai/v1"
|
|
2939
3259
|
);
|
|
2940
|
-
const getHeaders = () => (0,
|
|
3260
|
+
const getHeaders = () => (0, import_provider_utils20.withUserAgentSuffix)(
|
|
2941
3261
|
{
|
|
2942
|
-
Authorization: `Bearer ${(0,
|
|
3262
|
+
Authorization: `Bearer ${(0, import_provider_utils20.loadApiKey)({
|
|
2943
3263
|
apiKey: options.apiKey,
|
|
2944
3264
|
environmentVariableName: "XAI_API_KEY",
|
|
2945
3265
|
description: "xAI API key"
|
|
@@ -2953,7 +3273,7 @@ function createXai(options = {}) {
|
|
|
2953
3273
|
provider: "xai.chat",
|
|
2954
3274
|
baseURL,
|
|
2955
3275
|
headers: getHeaders,
|
|
2956
|
-
generateId:
|
|
3276
|
+
generateId: import_provider_utils20.generateId,
|
|
2957
3277
|
fetch: options.fetch
|
|
2958
3278
|
});
|
|
2959
3279
|
};
|
|
@@ -2962,7 +3282,7 @@ function createXai(options = {}) {
|
|
|
2962
3282
|
provider: "xai.responses",
|
|
2963
3283
|
baseURL,
|
|
2964
3284
|
headers: getHeaders,
|
|
2965
|
-
generateId:
|
|
3285
|
+
generateId: import_provider_utils20.generateId,
|
|
2966
3286
|
fetch: options.fetch
|
|
2967
3287
|
});
|
|
2968
3288
|
};
|
|
@@ -2982,9 +3302,15 @@ function createXai(options = {}) {
|
|
|
2982
3302
|
fetch: options.fetch
|
|
2983
3303
|
});
|
|
2984
3304
|
};
|
|
2985
|
-
const
|
|
2986
|
-
|
|
2987
|
-
|
|
3305
|
+
const createFiles = () => new XaiFiles({
|
|
3306
|
+
provider: "xai.files",
|
|
3307
|
+
baseURL,
|
|
3308
|
+
headers: getHeaders,
|
|
3309
|
+
fetch: options.fetch
|
|
3310
|
+
});
|
|
3311
|
+
const provider = (modelId) => createResponsesLanguageModel(modelId);
|
|
3312
|
+
provider.specificationVersion = "v4";
|
|
3313
|
+
provider.languageModel = createResponsesLanguageModel;
|
|
2988
3314
|
provider.chat = createChatLanguageModel;
|
|
2989
3315
|
provider.responses = createResponsesLanguageModel;
|
|
2990
3316
|
provider.embeddingModel = (modelId) => {
|
|
@@ -2995,6 +3321,7 @@ function createXai(options = {}) {
|
|
|
2995
3321
|
provider.image = createImageModel;
|
|
2996
3322
|
provider.videoModel = createVideoModel;
|
|
2997
3323
|
provider.video = createVideoModel;
|
|
3324
|
+
provider.files = createFiles;
|
|
2998
3325
|
provider.tools = xaiTools;
|
|
2999
3326
|
return provider;
|
|
3000
3327
|
}
|