@ai-sdk/xai 5.0.7 → 5.0.8
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 +7 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +214 -59
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +93 -34
- package/package.json +1 -1
- package/src/responses/xai-responses-api.ts +8 -1
- package/src/responses/xai-responses-language-model-options.ts +27 -1
- package/src/responses/xai-responses-language-model.ts +38 -14
- package/src/xai-video-model-options.ts +27 -0
- package/src/xai-video-model.ts +179 -53
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -46,14 +46,24 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
|
|
|
46
46
|
}>>;
|
|
47
47
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
48
48
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
minP: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
maxTurns: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
|
52
|
+
promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
53
|
+
safetyIdentifier: z.ZodOptional<z.ZodString>;
|
|
49
54
|
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
50
55
|
default: "default";
|
|
51
56
|
priority: "priority";
|
|
52
57
|
}>>;
|
|
53
58
|
store: z.ZodOptional<z.ZodBoolean>;
|
|
54
59
|
previousResponseId: z.ZodOptional<z.ZodString>;
|
|
60
|
+
user: z.ZodOptional<z.ZodString>;
|
|
55
61
|
include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
56
62
|
"file_search_call.results": "file_search_call.results";
|
|
63
|
+
"web_search_call.action.sources": "web_search_call.action.sources";
|
|
64
|
+
"code_interpreter_call.outputs": "code_interpreter_call.outputs";
|
|
65
|
+
"reasoning.encrypted_content": "reasoning.encrypted_content";
|
|
66
|
+
no_inline_citations: "no_inline_citations";
|
|
57
67
|
}>>>>;
|
|
58
68
|
}, z.core.$strip>;
|
|
59
69
|
type XaiLanguageModelResponsesOptions = z.infer<typeof xaiLanguageModelResponsesOptions>;
|
|
@@ -83,10 +93,25 @@ declare const resolutionSchema: z.ZodEnum<{
|
|
|
83
93
|
"1080p": "1080p";
|
|
84
94
|
}>;
|
|
85
95
|
type XaiVideoResolution = z.infer<typeof resolutionSchema>;
|
|
96
|
+
declare const keyframeSchema: z.ZodObject<{
|
|
97
|
+
imageUrl: z.ZodString;
|
|
98
|
+
timestampSeconds: z.ZodNumber;
|
|
99
|
+
}, z.core.$strip>;
|
|
100
|
+
declare const storageOptionsSchema: z.ZodObject<{
|
|
101
|
+
filename: z.ZodString;
|
|
102
|
+
expiresAfter: z.ZodOptional<z.ZodNumber>;
|
|
103
|
+
publicUrl: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
104
|
+
expiresAfter: z.ZodOptional<z.ZodNumber>;
|
|
105
|
+
}, z.core.$strip>]>>;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
type XaiVideoKeyframe = z.infer<typeof keyframeSchema>;
|
|
108
|
+
type XaiVideoStorageOptions = z.infer<typeof storageOptionsSchema>;
|
|
86
109
|
interface XaiVideoSharedOptions {
|
|
87
110
|
pollIntervalMs?: number | null;
|
|
88
111
|
pollTimeoutMs?: number | null;
|
|
89
112
|
resolution?: XaiVideoResolution | null;
|
|
113
|
+
/** Store the generated video in the xAI Files API. */
|
|
114
|
+
storageOptions?: XaiVideoStorageOptions;
|
|
90
115
|
}
|
|
91
116
|
interface XaiVideoUserOptions {
|
|
92
117
|
/**
|
|
@@ -126,6 +151,8 @@ interface XaiVideoGenerationOptions extends XaiVideoSharedOptions, XaiVideoUserO
|
|
|
126
151
|
mode?: undefined;
|
|
127
152
|
videoUrl?: undefined;
|
|
128
153
|
referenceImageUrls?: undefined;
|
|
154
|
+
/** Mid-video image anchors (up to 4). */
|
|
155
|
+
keyframes?: XaiVideoKeyframe[];
|
|
129
156
|
}
|
|
130
157
|
interface XaiLegacyEditVideoOptions extends XaiVideoSharedOptions, XaiVideoUserOptions {
|
|
131
158
|
/**
|
package/dist/index.js
CHANGED
|
@@ -806,7 +806,9 @@ var xaiResponsesResponseSchema = z6.object({
|
|
|
806
806
|
output: z6.array(outputItemSchema),
|
|
807
807
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
808
808
|
status: z6.string(),
|
|
809
|
-
service_tier: z6.string().nullish()
|
|
809
|
+
service_tier: z6.string().nullish(),
|
|
810
|
+
prompt_cache_key: z6.string().nullish(),
|
|
811
|
+
safety_identifier: z6.string().nullish()
|
|
810
812
|
});
|
|
811
813
|
var xaiResponsesChunkSchema = z6.union([
|
|
812
814
|
z6.object({
|
|
@@ -1090,7 +1092,9 @@ var xaiResponsesChunkSchema = z6.union([
|
|
|
1090
1092
|
response: z6.object({
|
|
1091
1093
|
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
1092
1094
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
1093
|
-
service_tier: z6.string().nullish()
|
|
1095
|
+
service_tier: z6.string().nullish(),
|
|
1096
|
+
prompt_cache_key: z6.string().nullish(),
|
|
1097
|
+
safety_identifier: z6.string().nullish()
|
|
1094
1098
|
})
|
|
1095
1099
|
}),
|
|
1096
1100
|
z6.object({
|
|
@@ -1133,9 +1137,23 @@ var xaiLanguageModelResponsesOptions = z7.object({
|
|
|
1133
1137
|
* @see https://docs.x.ai/docs/guides/reasoning
|
|
1134
1138
|
*/
|
|
1135
1139
|
reasoningEffort: z7.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
1140
|
+
/**
|
|
1141
|
+
* @deprecated xAI ignores the requested summary level and always returns a
|
|
1142
|
+
* detailed reasoning summary.
|
|
1143
|
+
*/
|
|
1136
1144
|
reasoningSummary: z7.enum(["auto", "concise", "detailed"]).optional(),
|
|
1137
1145
|
logprobs: z7.boolean().optional(),
|
|
1138
1146
|
topLogprobs: z7.number().int().min(0).max(8).optional(),
|
|
1147
|
+
/** Min-p sampling threshold between 0 and 1. */
|
|
1148
|
+
minP: z7.number().min(0).max(1).optional(),
|
|
1149
|
+
/** Maximum number of agentic tool-calling turns. */
|
|
1150
|
+
maxTurns: z7.number().int().optional(),
|
|
1151
|
+
/** Whether the model may call tools in parallel. @default true */
|
|
1152
|
+
parallelToolCalls: z7.boolean().optional(),
|
|
1153
|
+
/** Cache key used to route requests with shared prompt prefixes. */
|
|
1154
|
+
promptCacheKey: z7.string().optional(),
|
|
1155
|
+
/** Stable identifier used to attribute policy violations to an end user. */
|
|
1156
|
+
safetyIdentifier: z7.string().optional(),
|
|
1139
1157
|
serviceTier: z7.enum(["default", "priority"]).optional(),
|
|
1140
1158
|
/**
|
|
1141
1159
|
* Whether to store the input message(s) and model response for later retrieval.
|
|
@@ -1148,11 +1166,21 @@ var xaiLanguageModelResponsesOptions = z7.object({
|
|
|
1148
1166
|
* The ID of the previous response from the model.
|
|
1149
1167
|
*/
|
|
1150
1168
|
previousResponseId: z7.string().optional(),
|
|
1169
|
+
/** A unique identifier for the end user, used for abuse monitoring. */
|
|
1170
|
+
user: z7.string().optional(),
|
|
1151
1171
|
/**
|
|
1152
1172
|
* Specify additional output data to include in the model response.
|
|
1153
1173
|
* Example values: 'file_search_call.results'.
|
|
1154
1174
|
*/
|
|
1155
|
-
include: z7.array(
|
|
1175
|
+
include: z7.array(
|
|
1176
|
+
z7.enum([
|
|
1177
|
+
"file_search_call.results",
|
|
1178
|
+
"web_search_call.action.sources",
|
|
1179
|
+
"code_interpreter_call.outputs",
|
|
1180
|
+
"reasoning.encrypted_content",
|
|
1181
|
+
"no_inline_citations"
|
|
1182
|
+
])
|
|
1183
|
+
).nullish()
|
|
1156
1184
|
});
|
|
1157
1185
|
|
|
1158
1186
|
// src/responses/xai-responses-prepare-tools.ts
|
|
@@ -1625,9 +1653,6 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1625
1653
|
providerOptions,
|
|
1626
1654
|
schema: xaiLanguageModelResponsesOptions
|
|
1627
1655
|
})) != null ? _a : {};
|
|
1628
|
-
if (topK != null) {
|
|
1629
|
-
warnings.push({ type: "unsupported", feature: "topK" });
|
|
1630
|
-
}
|
|
1631
1656
|
if (frequencyPenalty != null) {
|
|
1632
1657
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
1633
1658
|
}
|
|
@@ -1709,6 +1734,8 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1709
1734
|
max_output_tokens: maxOutputTokens,
|
|
1710
1735
|
temperature,
|
|
1711
1736
|
top_p: topP,
|
|
1737
|
+
top_k: topK,
|
|
1738
|
+
min_p: options.minP,
|
|
1712
1739
|
seed,
|
|
1713
1740
|
...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
|
|
1714
1741
|
text: {
|
|
@@ -1721,14 +1748,9 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1721
1748
|
} : { type: "json_object" }
|
|
1722
1749
|
}
|
|
1723
1750
|
},
|
|
1724
|
-
...
|
|
1751
|
+
...resolvedReasoningEffort != null && {
|
|
1725
1752
|
reasoning: {
|
|
1726
|
-
|
|
1727
|
-
effort: resolvedReasoningEffort
|
|
1728
|
-
},
|
|
1729
|
-
...options.reasoningSummary != null && {
|
|
1730
|
-
summary: options.reasoningSummary
|
|
1731
|
-
}
|
|
1753
|
+
effort: resolvedReasoningEffort
|
|
1732
1754
|
}
|
|
1733
1755
|
},
|
|
1734
1756
|
...options.store === false && {
|
|
@@ -1740,8 +1762,23 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1740
1762
|
...options.previousResponseId != null && {
|
|
1741
1763
|
previous_response_id: options.previousResponseId
|
|
1742
1764
|
},
|
|
1765
|
+
...options.maxTurns != null && {
|
|
1766
|
+
max_turns: options.maxTurns
|
|
1767
|
+
},
|
|
1768
|
+
...options.parallelToolCalls != null && {
|
|
1769
|
+
parallel_tool_calls: options.parallelToolCalls
|
|
1770
|
+
},
|
|
1771
|
+
...options.promptCacheKey != null && {
|
|
1772
|
+
prompt_cache_key: options.promptCacheKey
|
|
1773
|
+
},
|
|
1774
|
+
...options.safetyIdentifier != null && {
|
|
1775
|
+
safety_identifier: options.safetyIdentifier
|
|
1776
|
+
},
|
|
1743
1777
|
...options.serviceTier != null && {
|
|
1744
1778
|
service_tier: options.serviceTier
|
|
1779
|
+
},
|
|
1780
|
+
...options.user != null && {
|
|
1781
|
+
user: options.user
|
|
1745
1782
|
}
|
|
1746
1783
|
};
|
|
1747
1784
|
if (xaiTools2 && xaiTools2.length > 0) {
|
|
@@ -1964,7 +2001,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1964
2001
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
1965
2002
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
1966
2003
|
},
|
|
1967
|
-
...(((_q = response.usage) == null ? void 0 : _q.cost_in_usd_ticks) != null || response.service_tier != null) && {
|
|
2004
|
+
...(((_q = response.usage) == null ? void 0 : _q.cost_in_usd_ticks) != null || response.service_tier != null || response.prompt_cache_key != null || response.safety_identifier != null) && {
|
|
1968
2005
|
providerMetadata: {
|
|
1969
2006
|
xai: {
|
|
1970
2007
|
...((_r = response.usage) == null ? void 0 : _r.cost_in_usd_ticks) != null && {
|
|
@@ -1972,6 +2009,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
1972
2009
|
},
|
|
1973
2010
|
...response.service_tier != null && {
|
|
1974
2011
|
serviceTier: response.service_tier
|
|
2012
|
+
},
|
|
2013
|
+
...response.prompt_cache_key != null && {
|
|
2014
|
+
promptCacheKey: response.prompt_cache_key
|
|
2015
|
+
},
|
|
2016
|
+
...response.safety_identifier != null && {
|
|
2017
|
+
safetyIdentifier: response.safety_identifier
|
|
1975
2018
|
}
|
|
1976
2019
|
}
|
|
1977
2020
|
}
|
|
@@ -2020,6 +2063,8 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2020
2063
|
let usage = void 0;
|
|
2021
2064
|
let costInUsdTicks = void 0;
|
|
2022
2065
|
let serviceTier = void 0;
|
|
2066
|
+
let promptCacheKey = void 0;
|
|
2067
|
+
let safetyIdentifier = void 0;
|
|
2023
2068
|
let isFirstChunk = true;
|
|
2024
2069
|
const contentBlocks = {};
|
|
2025
2070
|
const seenToolCalls = /* @__PURE__ */ new Set();
|
|
@@ -2033,7 +2078,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2033
2078
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2034
2079
|
},
|
|
2035
2080
|
transform(chunk, controller) {
|
|
2036
|
-
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2081
|
+
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
2037
2082
|
if (options.includeRawChunks) {
|
|
2038
2083
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2039
2084
|
}
|
|
@@ -2165,8 +2210,10 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2165
2210
|
costInUsdTicks = (_c2 = response2.usage.cost_in_usd_ticks) != null ? _c2 : void 0;
|
|
2166
2211
|
}
|
|
2167
2212
|
serviceTier = (_d = response2.service_tier) != null ? _d : void 0;
|
|
2213
|
+
promptCacheKey = (_e = response2.prompt_cache_key) != null ? _e : void 0;
|
|
2214
|
+
safetyIdentifier = (_f = response2.safety_identifier) != null ? _f : void 0;
|
|
2168
2215
|
if (event.type === "response.incomplete") {
|
|
2169
|
-
const reason = "incomplete_details" in response2 ? (
|
|
2216
|
+
const reason = "incomplete_details" in response2 ? (_g = response2.incomplete_details) == null ? void 0 : _g.reason : void 0;
|
|
2170
2217
|
finishReason = {
|
|
2171
2218
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2172
2219
|
raw: reason != null ? reason : "incomplete"
|
|
@@ -2180,7 +2227,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2180
2227
|
return;
|
|
2181
2228
|
}
|
|
2182
2229
|
if (event.type === "response.failed") {
|
|
2183
|
-
const reason = (
|
|
2230
|
+
const reason = (_h = event.response.incomplete_details) == null ? void 0 : _h.reason;
|
|
2184
2231
|
finishReason = {
|
|
2185
2232
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
|
|
2186
2233
|
raw: reason != null ? reason : "error"
|
|
@@ -2323,13 +2370,13 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2323
2370
|
toolCallId: part.id,
|
|
2324
2371
|
toolName,
|
|
2325
2372
|
result: {
|
|
2326
|
-
queries: (
|
|
2327
|
-
results: (
|
|
2373
|
+
queries: (_i = part.queries) != null ? _i : [],
|
|
2374
|
+
results: (_k = (_j = part.results) == null ? void 0 : _j.map((result) => ({
|
|
2328
2375
|
fileId: result.file_id,
|
|
2329
2376
|
filename: result.filename,
|
|
2330
2377
|
score: result.score,
|
|
2331
2378
|
text: result.text
|
|
2332
|
-
}))) != null ?
|
|
2379
|
+
}))) != null ? _k : null
|
|
2333
2380
|
}
|
|
2334
2381
|
});
|
|
2335
2382
|
}
|
|
@@ -2396,17 +2443,17 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2396
2443
|
"x_semantic_search",
|
|
2397
2444
|
"x_thread_fetch"
|
|
2398
2445
|
];
|
|
2399
|
-
let toolName = (
|
|
2400
|
-
if (webSearchSubTools.includes((
|
|
2446
|
+
let toolName = (_l = part.name) != null ? _l : "";
|
|
2447
|
+
if (webSearchSubTools.includes((_m = part.name) != null ? _m : "") || part.type === "web_search_call") {
|
|
2401
2448
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
2402
|
-
} else if (xSearchSubTools.includes((
|
|
2449
|
+
} else if (xSearchSubTools.includes((_n = part.name) != null ? _n : "") || part.type === "x_search_call") {
|
|
2403
2450
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2404
2451
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2405
2452
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2406
2453
|
} else if (part.type === "mcp_call") {
|
|
2407
|
-
toolName = (
|
|
2454
|
+
toolName = (_o = mcpToolName != null ? mcpToolName : part.name) != null ? _o : "mcp";
|
|
2408
2455
|
}
|
|
2409
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2456
|
+
const toolInput = part.type === "custom_tool_call" ? (_p = part.input) != null ? _p : "" : part.type === "mcp_call" ? (_q = part.arguments) != null ? _q : "" : (_r = part.arguments) != null ? _r : "";
|
|
2410
2457
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2411
2458
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2412
2459
|
seenToolCalls.add(part.id);
|
|
@@ -2467,7 +2514,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2467
2514
|
sourceType: "url",
|
|
2468
2515
|
id: self.config.generateId(),
|
|
2469
2516
|
url: annotation.url,
|
|
2470
|
-
title: (
|
|
2517
|
+
title: (_s = annotation.title) != null ? _s : annotation.url
|
|
2471
2518
|
});
|
|
2472
2519
|
}
|
|
2473
2520
|
}
|
|
@@ -2522,11 +2569,13 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2522
2569
|
},
|
|
2523
2570
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
2524
2571
|
},
|
|
2525
|
-
...(costInUsdTicks != null || serviceTier != null) && {
|
|
2572
|
+
...(costInUsdTicks != null || serviceTier != null || promptCacheKey != null || safetyIdentifier != null) && {
|
|
2526
2573
|
providerMetadata: {
|
|
2527
2574
|
xai: {
|
|
2528
2575
|
...costInUsdTicks != null && { costInUsdTicks },
|
|
2529
|
-
...serviceTier != null && { serviceTier }
|
|
2576
|
+
...serviceTier != null && { serviceTier },
|
|
2577
|
+
...promptCacheKey != null && { promptCacheKey },
|
|
2578
|
+
...safetyIdentifier != null && { safetyIdentifier }
|
|
2530
2579
|
}
|
|
2531
2580
|
}
|
|
2532
2581
|
}
|
|
@@ -3670,7 +3719,7 @@ var xaiTools = {
|
|
|
3670
3719
|
};
|
|
3671
3720
|
|
|
3672
3721
|
// src/version.ts
|
|
3673
|
-
var VERSION = true ? "5.0.
|
|
3722
|
+
var VERSION = true ? "5.0.8" : "0.0.0-test";
|
|
3674
3723
|
|
|
3675
3724
|
// src/files/xai-files.ts
|
|
3676
3725
|
import {
|
|
@@ -3947,6 +3996,20 @@ import { z as z18 } from "zod/v4";
|
|
|
3947
3996
|
var nonEmptyStringSchema = z18.string().min(1);
|
|
3948
3997
|
var resolutionSchema = z18.enum(["480p", "720p", "1080p"]);
|
|
3949
3998
|
var modeSchema = z18.enum(["edit-video", "extend-video", "reference-to-video"]);
|
|
3999
|
+
var keyframeSchema = z18.object({
|
|
4000
|
+
imageUrl: nonEmptyStringSchema,
|
|
4001
|
+
timestampSeconds: z18.number().positive()
|
|
4002
|
+
});
|
|
4003
|
+
var storageOptionsSchema = z18.object({
|
|
4004
|
+
filename: nonEmptyStringSchema,
|
|
4005
|
+
expiresAfter: z18.number().int().positive().max(2592e3).optional(),
|
|
4006
|
+
publicUrl: z18.union([
|
|
4007
|
+
z18.boolean(),
|
|
4008
|
+
z18.object({
|
|
4009
|
+
expiresAfter: z18.number().int().min(3600).max(2592e3).optional()
|
|
4010
|
+
})
|
|
4011
|
+
]).optional()
|
|
4012
|
+
});
|
|
3950
4013
|
var baseFields = {
|
|
3951
4014
|
pollIntervalMs: z18.number().positive().nullish(),
|
|
3952
4015
|
pollTimeoutMs: z18.number().positive().nullish(),
|
|
@@ -3957,6 +4020,8 @@ var runtimeSchema = z18.looseObject({
|
|
|
3957
4020
|
videoUrl: nonEmptyStringSchema.optional(),
|
|
3958
4021
|
referenceImageUrls: z18.array(nonEmptyStringSchema).min(1).max(7).optional(),
|
|
3959
4022
|
referenceVoiceIds: z18.array(nonEmptyStringSchema).max(3).optional(),
|
|
4023
|
+
keyframes: z18.array(keyframeSchema).max(4).optional(),
|
|
4024
|
+
storageOptions: storageOptionsSchema.optional(),
|
|
3960
4025
|
user: z18.string().optional(),
|
|
3961
4026
|
...baseFields
|
|
3962
4027
|
});
|
|
@@ -3989,6 +4054,7 @@ function resolveStartImage(options) {
|
|
|
3989
4054
|
}
|
|
3990
4055
|
var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType2(file.mediaType) === "video";
|
|
3991
4056
|
var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType2(file.mediaType) === "image";
|
|
4057
|
+
var isAudioReference = (file) => file.mediaType != null && getTopLevelMediaType2(file.mediaType) === "audio";
|
|
3992
4058
|
function fileToXaiUrl(file) {
|
|
3993
4059
|
if (file.type === "url") {
|
|
3994
4060
|
return file.url;
|
|
@@ -4000,11 +4066,14 @@ function resolveReferences(options, xaiOptions, warnings) {
|
|
|
4000
4066
|
if (options.inputReferences != null && options.inputReferences.length > 0) {
|
|
4001
4067
|
const imageFiles = [];
|
|
4002
4068
|
for (const reference of options.inputReferences) {
|
|
4069
|
+
if (isAudioReference(reference)) {
|
|
4070
|
+
continue;
|
|
4071
|
+
}
|
|
4003
4072
|
if (!isImageReference(reference)) {
|
|
4004
4073
|
warnings.push({
|
|
4005
4074
|
type: "unsupported",
|
|
4006
4075
|
feature: "inputReferences",
|
|
4007
|
-
details:
|
|
4076
|
+
details: 'xAI reference-to-video does not accept video references. The video reference was ignored. Use providerOptions.xai.mode "extend-video" to continue from a video.'
|
|
4008
4077
|
});
|
|
4009
4078
|
continue;
|
|
4010
4079
|
}
|
|
@@ -4016,10 +4085,19 @@ function resolveReferences(options, xaiOptions, warnings) {
|
|
|
4016
4085
|
return xaiOptions.referenceImageUrls.map((url) => ({ url }));
|
|
4017
4086
|
}
|
|
4018
4087
|
}
|
|
4088
|
+
function resolveReferenceAudios(options) {
|
|
4089
|
+
var _a;
|
|
4090
|
+
const audioReferences = (_a = options.inputReferences) == null ? void 0 : _a.filter(isAudioReference);
|
|
4091
|
+
return audioReferences != null && audioReferences.length > 0 ? audioReferences.map((reference) => ({ url: fileToXaiUrl(reference) })) : void 0;
|
|
4092
|
+
}
|
|
4019
4093
|
function hasImageInputReference(options) {
|
|
4020
4094
|
var _a, _b;
|
|
4021
4095
|
return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isImageReference)) != null ? _b : false;
|
|
4022
4096
|
}
|
|
4097
|
+
function hasAudioInputReference(options) {
|
|
4098
|
+
var _a, _b;
|
|
4099
|
+
return (_b = (_a = options.inputReferences) == null ? void 0 : _a.some(isAudioReference)) != null ? _b : false;
|
|
4100
|
+
}
|
|
4023
4101
|
function resolveVideoMode(options, xaiOptions) {
|
|
4024
4102
|
if ((xaiOptions == null ? void 0 : xaiOptions.mode) != null) {
|
|
4025
4103
|
return xaiOptions.mode;
|
|
@@ -4027,9 +4105,8 @@ function resolveVideoMode(options, xaiOptions) {
|
|
|
4027
4105
|
if ((xaiOptions == null ? void 0 : xaiOptions.videoUrl) != null) {
|
|
4028
4106
|
return "edit-video";
|
|
4029
4107
|
}
|
|
4030
|
-
const hasFrameImages = options.frameImages != null && options.frameImages.length > 0;
|
|
4031
4108
|
const hasLegacyReferenceUrls = (xaiOptions == null ? void 0 : xaiOptions.referenceImageUrls) != null && xaiOptions.referenceImageUrls.length > 0;
|
|
4032
|
-
if (
|
|
4109
|
+
if (hasImageInputReference(options) || hasAudioInputReference(options) || hasLegacyReferenceUrls) {
|
|
4033
4110
|
return "reference-to-video";
|
|
4034
4111
|
}
|
|
4035
4112
|
}
|
|
@@ -4137,6 +4214,41 @@ var XaiVideoModel = class {
|
|
|
4137
4214
|
});
|
|
4138
4215
|
}
|
|
4139
4216
|
}
|
|
4217
|
+
if (options.generateAudio != null && !isEdit && !isExtension) {
|
|
4218
|
+
body.generate_audio = options.generateAudio;
|
|
4219
|
+
} else if (options.generateAudio != null) {
|
|
4220
|
+
warnings.push({
|
|
4221
|
+
type: "unsupported",
|
|
4222
|
+
feature: "generateAudio",
|
|
4223
|
+
details: `xAI ${isEdit ? "video editing" : "video extension"} does not support generateAudio.`
|
|
4224
|
+
});
|
|
4225
|
+
}
|
|
4226
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.storageOptions) != null) {
|
|
4227
|
+
const { filename, expiresAfter, publicUrl } = xaiOptions.storageOptions;
|
|
4228
|
+
body.storage_options = {
|
|
4229
|
+
filename,
|
|
4230
|
+
...expiresAfter != null ? { expires_after: expiresAfter } : {},
|
|
4231
|
+
...publicUrl != null ? {
|
|
4232
|
+
public_url: typeof publicUrl === "boolean" ? publicUrl : {
|
|
4233
|
+
...publicUrl.expiresAfter != null ? { expires_after: publicUrl.expiresAfter } : {}
|
|
4234
|
+
}
|
|
4235
|
+
} : {}
|
|
4236
|
+
};
|
|
4237
|
+
}
|
|
4238
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.keyframes) != null && xaiOptions.keyframes.length > 0) {
|
|
4239
|
+
if (this.modelId !== "grok-imagine-video-1.5" || isEdit || isExtension) {
|
|
4240
|
+
warnings.push({
|
|
4241
|
+
type: "unsupported",
|
|
4242
|
+
feature: "keyframes",
|
|
4243
|
+
details: this.modelId !== "grok-imagine-video-1.5" ? 'xAI only supports keyframes with "grok-imagine-video-1.5".' : `xAI ${isEdit ? "video editing" : "video extension"} does not support keyframes.`
|
|
4244
|
+
});
|
|
4245
|
+
} else {
|
|
4246
|
+
body.keyframes = xaiOptions.keyframes.map((keyframe) => ({
|
|
4247
|
+
image: { url: keyframe.imageUrl },
|
|
4248
|
+
timestamp_s: keyframe.timestampSeconds
|
|
4249
|
+
}));
|
|
4250
|
+
}
|
|
4251
|
+
}
|
|
4140
4252
|
if (isEdit) {
|
|
4141
4253
|
body.video = { url: xaiOptions.videoUrl };
|
|
4142
4254
|
}
|
|
@@ -4158,17 +4270,22 @@ var XaiVideoModel = class {
|
|
|
4158
4270
|
}
|
|
4159
4271
|
const lastFrameImage = getLastFrameImage(options);
|
|
4160
4272
|
if (lastFrameImage != null) {
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4273
|
+
if (this.modelId !== "grok-imagine-video-1.5" || isEdit || isExtension || isVideoFile(lastFrameImage)) {
|
|
4274
|
+
warnings.push({
|
|
4275
|
+
type: "unsupported",
|
|
4276
|
+
feature: "frameImages",
|
|
4277
|
+
details: this.modelId !== "grok-imagine-video-1.5" ? 'xAI only supports last_frame with "grok-imagine-video-1.5". The last frame was ignored.' : "xAI only accepts an image last_frame for video generation. The last frame was ignored."
|
|
4278
|
+
});
|
|
4279
|
+
} else {
|
|
4280
|
+
body.last_frame = { url: fileToXaiUrl(lastFrameImage) };
|
|
4281
|
+
}
|
|
4166
4282
|
}
|
|
4167
4283
|
if (hasReferenceImages) {
|
|
4168
4284
|
const referenceImages = resolveReferences(options, xaiOptions, warnings);
|
|
4285
|
+
const referenceAudios = resolveReferenceAudios(options);
|
|
4169
4286
|
if (referenceImages != null) {
|
|
4170
4287
|
body.reference_images = referenceImages;
|
|
4171
|
-
} else {
|
|
4288
|
+
} else if (referenceAudios == null) {
|
|
4172
4289
|
warnings.push({
|
|
4173
4290
|
type: "unsupported",
|
|
4174
4291
|
feature: "referenceImages",
|
|
@@ -4176,10 +4293,22 @@ var XaiVideoModel = class {
|
|
|
4176
4293
|
});
|
|
4177
4294
|
}
|
|
4178
4295
|
const referenceVoiceIds = xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds;
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4296
|
+
const referenceVoices = referenceVoiceIds == null ? void 0 : referenceVoiceIds.map((voiceId) => ({
|
|
4297
|
+
voice_id: voiceId
|
|
4298
|
+
}));
|
|
4299
|
+
const referenceAudioInputs = [
|
|
4300
|
+
...referenceAudios != null ? referenceAudios : [],
|
|
4301
|
+
...referenceVoices != null ? referenceVoices : []
|
|
4302
|
+
];
|
|
4303
|
+
if (referenceAudioInputs.length > 0) {
|
|
4304
|
+
if (referenceAudioInputs.length > 3) {
|
|
4305
|
+
warnings.push({
|
|
4306
|
+
type: "unsupported",
|
|
4307
|
+
feature: "inputReferences",
|
|
4308
|
+
details: "xAI reference-to-video supports at most 3 audio references. Only the first 3 were used."
|
|
4309
|
+
});
|
|
4310
|
+
}
|
|
4311
|
+
body.reference_audios = referenceAudioInputs.slice(0, 3);
|
|
4183
4312
|
}
|
|
4184
4313
|
if (body.resolution === "1080p") {
|
|
4185
4314
|
warnings.push({
|
|
@@ -4201,7 +4330,7 @@ var XaiVideoModel = class {
|
|
|
4201
4330
|
warnings.push({
|
|
4202
4331
|
type: "unsupported",
|
|
4203
4332
|
feature: "inputReferences",
|
|
4204
|
-
details: hasImageInputReference(options) ? "xAI only supports inputReferences for reference-to-video generation. The
|
|
4333
|
+
details: hasImageInputReference(options) || hasAudioInputReference(options) ? "xAI only supports inputReferences for reference-to-video generation. The references were ignored." : "xAI reference-to-video requires at least one image or audio reference. The references were ignored."
|
|
4205
4334
|
});
|
|
4206
4335
|
}
|
|
4207
4336
|
if ((xaiOptions == null ? void 0 : xaiOptions.referenceVoiceIds) != null && xaiOptions.referenceVoiceIds.length > 0 && !hasReferenceImages) {
|
|
@@ -4224,6 +4353,8 @@ var XaiVideoModel = class {
|
|
|
4224
4353
|
"videoUrl",
|
|
4225
4354
|
"referenceImageUrls",
|
|
4226
4355
|
"referenceVoiceIds",
|
|
4356
|
+
"keyframes",
|
|
4357
|
+
"storageOptions",
|
|
4227
4358
|
"user"
|
|
4228
4359
|
].includes(key)) {
|
|
4229
4360
|
body[key] = value;
|
|
@@ -4282,7 +4413,7 @@ var XaiVideoModel = class {
|
|
|
4282
4413
|
};
|
|
4283
4414
|
}
|
|
4284
4415
|
async doStatus(options) {
|
|
4285
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4416
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
4286
4417
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
4287
4418
|
const { requestId } = options.operation;
|
|
4288
4419
|
const baseURL = (_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1";
|
|
@@ -4319,7 +4450,8 @@ var XaiVideoModel = class {
|
|
|
4319
4450
|
};
|
|
4320
4451
|
}
|
|
4321
4452
|
if (statusResponse.status === "done" || statusResponse.status == null && ((_h = statusResponse.video) == null ? void 0 : _h.url)) {
|
|
4322
|
-
|
|
4453
|
+
const video = statusResponse.video;
|
|
4454
|
+
if ((video == null ? void 0 : video.respect_moderation) === false) {
|
|
4323
4455
|
return {
|
|
4324
4456
|
status: "error",
|
|
4325
4457
|
error: "Video generation was blocked due to a content policy violation.",
|
|
@@ -4330,7 +4462,8 @@ var XaiVideoModel = class {
|
|
|
4330
4462
|
}
|
|
4331
4463
|
};
|
|
4332
4464
|
}
|
|
4333
|
-
|
|
4465
|
+
const videoUrl = (_k = (_j = video == null ? void 0 : video.url) != null ? _j : (_i = video == null ? void 0 : video.file_output) == null ? void 0 : _i.public_url) != null ? _k : void 0;
|
|
4466
|
+
if (!videoUrl) {
|
|
4334
4467
|
return {
|
|
4335
4468
|
status: "error",
|
|
4336
4469
|
error: "Video generation completed but no video URL was returned.",
|
|
@@ -4343,13 +4476,7 @@ var XaiVideoModel = class {
|
|
|
4343
4476
|
}
|
|
4344
4477
|
return {
|
|
4345
4478
|
status: "completed",
|
|
4346
|
-
videos: [
|
|
4347
|
-
{
|
|
4348
|
-
type: "url",
|
|
4349
|
-
url: statusResponse.video.url,
|
|
4350
|
-
mediaType: "video/mp4"
|
|
4351
|
-
}
|
|
4352
|
-
],
|
|
4479
|
+
videos: [{ type: "url", url: videoUrl, mediaType: "video/mp4" }],
|
|
4353
4480
|
warnings: [],
|
|
4354
4481
|
response: {
|
|
4355
4482
|
timestamp: currentDate,
|
|
@@ -4359,10 +4486,29 @@ var XaiVideoModel = class {
|
|
|
4359
4486
|
providerMetadata: {
|
|
4360
4487
|
xai: {
|
|
4361
4488
|
requestId,
|
|
4362
|
-
videoUrl
|
|
4363
|
-
...
|
|
4364
|
-
...((
|
|
4365
|
-
...statusResponse.progress != null ? { progress: statusResponse.progress } : {}
|
|
4489
|
+
videoUrl,
|
|
4490
|
+
...(video == null ? void 0 : video.duration) != null ? { duration: video.duration } : {},
|
|
4491
|
+
...((_l = statusResponse.usage) == null ? void 0 : _l.cost_in_usd_ticks) != null ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks } : {},
|
|
4492
|
+
...statusResponse.progress != null ? { progress: statusResponse.progress } : {},
|
|
4493
|
+
...(video == null ? void 0 : video.file_output) != null ? {
|
|
4494
|
+
fileOutput: {
|
|
4495
|
+
fileId: video.file_output.file_id,
|
|
4496
|
+
filename: video.file_output.filename,
|
|
4497
|
+
...video.file_output.expires_at != null ? {
|
|
4498
|
+
expiresAt: video.file_output.expires_at
|
|
4499
|
+
} : {},
|
|
4500
|
+
...video.file_output.public_url != null ? {
|
|
4501
|
+
publicUrl: video.file_output.public_url
|
|
4502
|
+
} : {},
|
|
4503
|
+
...video.file_output.public_url_error != null ? {
|
|
4504
|
+
publicUrlError: video.file_output.public_url_error
|
|
4505
|
+
} : {},
|
|
4506
|
+
...video.file_output.public_url_expires_at != null ? {
|
|
4507
|
+
publicUrlExpiresAt: video.file_output.public_url_expires_at
|
|
4508
|
+
} : {}
|
|
4509
|
+
}
|
|
4510
|
+
} : {},
|
|
4511
|
+
...(video == null ? void 0 : video.storage_error) != null ? { storageError: video.storage_error } : {}
|
|
4366
4512
|
}
|
|
4367
4513
|
}
|
|
4368
4514
|
};
|
|
@@ -4383,9 +4529,18 @@ var xaiCreateVideoResponseSchema = z19.object({
|
|
|
4383
4529
|
var xaiVideoStatusResponseSchema = z19.object({
|
|
4384
4530
|
status: z19.string().nullish(),
|
|
4385
4531
|
video: z19.object({
|
|
4386
|
-
url: z19.string(),
|
|
4532
|
+
url: z19.string().nullish(),
|
|
4387
4533
|
duration: z19.number().nullish(),
|
|
4388
|
-
respect_moderation: z19.boolean().nullish()
|
|
4534
|
+
respect_moderation: z19.boolean().nullish(),
|
|
4535
|
+
file_output: z19.object({
|
|
4536
|
+
file_id: z19.string(),
|
|
4537
|
+
filename: z19.string(),
|
|
4538
|
+
expires_at: z19.number().nullish(),
|
|
4539
|
+
public_url: z19.string().nullish(),
|
|
4540
|
+
public_url_error: z19.string().nullish(),
|
|
4541
|
+
public_url_expires_at: z19.number().nullish()
|
|
4542
|
+
}).nullish(),
|
|
4543
|
+
storage_error: z19.string().nullish()
|
|
4389
4544
|
}).nullish(),
|
|
4390
4545
|
model: z19.string().nullish(),
|
|
4391
4546
|
usage: z19.object({
|