@ai-sdk/minimax 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +14 -0
- package/dist/index.d.ts +40 -2
- package/dist/index.js +572 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +2 -0
- package/src/minimax-provider.ts +46 -0
- package/src/minimax-video-model-options.ts +63 -0
- package/src/minimax-video-model.ts +675 -0
- package/src/minimax-video-settings.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -10,14 +10,565 @@ import {
|
|
|
10
10
|
} from "@ai-sdk/provider-utils";
|
|
11
11
|
import { AnthropicLanguageModel } from "@ai-sdk/anthropic/internal";
|
|
12
12
|
|
|
13
|
+
// src/minimax-video-model.ts
|
|
14
|
+
import {
|
|
15
|
+
AISDKError
|
|
16
|
+
} from "@ai-sdk/provider";
|
|
17
|
+
import {
|
|
18
|
+
combineHeaders,
|
|
19
|
+
convertImageModelFileToDataUri,
|
|
20
|
+
createJsonErrorResponseHandler,
|
|
21
|
+
createJsonResponseHandler,
|
|
22
|
+
delay,
|
|
23
|
+
getFromApi,
|
|
24
|
+
getTopLevelMediaType,
|
|
25
|
+
parseProviderOptions,
|
|
26
|
+
postJsonToApi,
|
|
27
|
+
resolve
|
|
28
|
+
} from "@ai-sdk/provider-utils";
|
|
29
|
+
import { z as z2 } from "zod/v4";
|
|
30
|
+
|
|
31
|
+
// src/minimax-video-model-options.ts
|
|
32
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
33
|
+
import { z } from "zod/v4";
|
|
34
|
+
var minimaxVideoRatios = [
|
|
35
|
+
"adaptive",
|
|
36
|
+
"21:9",
|
|
37
|
+
"16:9",
|
|
38
|
+
"4:3",
|
|
39
|
+
"1:1",
|
|
40
|
+
"3:4",
|
|
41
|
+
"9:16"
|
|
42
|
+
];
|
|
43
|
+
var minimaxVideoResolutions = ["2K"];
|
|
44
|
+
var minimaxVideoProviderOptions = z.object({
|
|
45
|
+
/**
|
|
46
|
+
* Output resolution.
|
|
47
|
+
*/
|
|
48
|
+
resolution: z.enum(minimaxVideoResolutions).optional(),
|
|
49
|
+
/**
|
|
50
|
+
* Aspect ratio of the generated video. Overrides the top-level `aspectRatio`.
|
|
51
|
+
*/
|
|
52
|
+
ratio: z.enum(minimaxVideoRatios).optional(),
|
|
53
|
+
/**
|
|
54
|
+
* Reference audio URLs for reference-to-video generation.
|
|
55
|
+
*/
|
|
56
|
+
referenceAudioUrls: z.array(z.string()).optional(),
|
|
57
|
+
/**
|
|
58
|
+
* Whether to embed an AIGC watermark in the output. Defaults to `false`.
|
|
59
|
+
*/
|
|
60
|
+
aigcWatermark: z.boolean().optional(),
|
|
61
|
+
/**
|
|
62
|
+
* Interval in milliseconds between task status polls. Default: 10000.
|
|
63
|
+
*/
|
|
64
|
+
pollIntervalMs: z.number().int().positive().optional(),
|
|
65
|
+
/**
|
|
66
|
+
* Maximum time in milliseconds to poll before timing out. Default: 600000.
|
|
67
|
+
*/
|
|
68
|
+
pollTimeoutMs: z.number().int().positive().optional()
|
|
69
|
+
});
|
|
70
|
+
var minimaxVideoModelOptionsSchema = lazySchema(
|
|
71
|
+
() => zodSchema(minimaxVideoProviderOptions)
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// src/minimax-video-model.ts
|
|
75
|
+
var DEFAULT_RESOLUTION = "2K";
|
|
76
|
+
var DEFAULT_ASPECT_RATIO = "16:9";
|
|
77
|
+
var DEFAULT_POLL_INTERVAL_MS = 1e4;
|
|
78
|
+
var DEFAULT_POLL_TIMEOUT_MS = 6e5;
|
|
79
|
+
var MIN_DURATION_SECONDS = 5;
|
|
80
|
+
var MAX_DURATION_SECONDS = 15;
|
|
81
|
+
var MAX_REFERENCE_IMAGES = 9;
|
|
82
|
+
var MAX_REFERENCE_VIDEOS = 3;
|
|
83
|
+
var MAX_REFERENCE_AUDIOS = 3;
|
|
84
|
+
var allowedRatios = new Set(minimaxVideoRatios);
|
|
85
|
+
var allowedResolutions = new Set(minimaxVideoResolutions);
|
|
86
|
+
var RESOLUTION_MAP = {
|
|
87
|
+
// Square
|
|
88
|
+
"2048x2048": "2K",
|
|
89
|
+
// Landscape
|
|
90
|
+
"2560x1080": "2K",
|
|
91
|
+
"2560x1440": "2K",
|
|
92
|
+
"2048x1536": "2K",
|
|
93
|
+
// Portrait
|
|
94
|
+
"1440x2560": "2K",
|
|
95
|
+
"1536x2048": "2K"
|
|
96
|
+
};
|
|
97
|
+
function resolveTopLevelResolution(resolution) {
|
|
98
|
+
const named = resolution.toUpperCase();
|
|
99
|
+
return allowedResolutions.has(named) ? named : RESOLUTION_MAP[resolution];
|
|
100
|
+
}
|
|
101
|
+
function nonImageFrameMediaType(file) {
|
|
102
|
+
if (file.mediaType == null) {
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
const topLevelMediaType = getTopLevelMediaType(file.mediaType);
|
|
106
|
+
return topLevelMediaType === "image" ? void 0 : topLevelMediaType;
|
|
107
|
+
}
|
|
108
|
+
var MiniMaxVideoModel = class {
|
|
109
|
+
constructor(modelId, config) {
|
|
110
|
+
this.modelId = modelId;
|
|
111
|
+
this.config = config;
|
|
112
|
+
this.specificationVersion = "v4";
|
|
113
|
+
this.maxVideosPerCall = 1;
|
|
114
|
+
}
|
|
115
|
+
get provider() {
|
|
116
|
+
return this.config.provider;
|
|
117
|
+
}
|
|
118
|
+
async doGenerate(options) {
|
|
119
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
120
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
121
|
+
const warnings = [];
|
|
122
|
+
const minimaxOptions = await parseProviderOptions({
|
|
123
|
+
provider: "minimax",
|
|
124
|
+
providerOptions: options.providerOptions,
|
|
125
|
+
schema: minimaxVideoModelOptionsSchema
|
|
126
|
+
});
|
|
127
|
+
if (options.fps != null) {
|
|
128
|
+
warnings.push({
|
|
129
|
+
type: "unsupported",
|
|
130
|
+
feature: "fps",
|
|
131
|
+
details: "MiniMax-H3 does not support a custom frame rate."
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (options.seed != null) {
|
|
135
|
+
warnings.push({
|
|
136
|
+
type: "unsupported",
|
|
137
|
+
feature: "seed",
|
|
138
|
+
details: "MiniMax-H3 does not support a seed."
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (options.n != null && options.n > 1) {
|
|
142
|
+
warnings.push({
|
|
143
|
+
type: "unsupported",
|
|
144
|
+
feature: "n",
|
|
145
|
+
details: "MiniMax-H3 generates a single video per call. Only 1 video will be generated."
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (options.generateAudio != null) {
|
|
149
|
+
warnings.push({
|
|
150
|
+
type: "unsupported",
|
|
151
|
+
feature: "generateAudio",
|
|
152
|
+
details: "The MiniMax-H3 API does not expose an audio parameter. The generateAudio option was ignored."
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
let resolution = minimaxOptions == null ? void 0 : minimaxOptions.resolution;
|
|
156
|
+
if (options.resolution != null) {
|
|
157
|
+
const mapped = resolveTopLevelResolution(options.resolution);
|
|
158
|
+
if (resolution != null) {
|
|
159
|
+
if (mapped == null) {
|
|
160
|
+
warnings.push({
|
|
161
|
+
type: "unsupported",
|
|
162
|
+
feature: "resolution",
|
|
163
|
+
details: `Unrecognized resolution "${options.resolution}". MiniMax-H3 only supports "2K", so providerOptions.minimax.resolution ("${resolution}") was used instead.`
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
} else if (mapped != null) {
|
|
167
|
+
resolution = mapped;
|
|
168
|
+
} else {
|
|
169
|
+
warnings.push({
|
|
170
|
+
type: "unsupported",
|
|
171
|
+
feature: "resolution",
|
|
172
|
+
details: `Unrecognized resolution "${options.resolution}". MiniMax-H3 only supports "2K".`
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
resolution != null ? resolution : resolution = DEFAULT_RESOLUTION;
|
|
177
|
+
const content = [
|
|
178
|
+
{ type: "text", text: (_d = options.prompt) != null ? _d : "" }
|
|
179
|
+
];
|
|
180
|
+
let sentImageCount = 0;
|
|
181
|
+
const sentReferenceVideoUrls = [];
|
|
182
|
+
const firstFrameImage = (_f = (_e = options.frameImages) == null ? void 0 : _e.find(
|
|
183
|
+
(frame) => frame.frameType === "first_frame"
|
|
184
|
+
)) == null ? void 0 : _f.image;
|
|
185
|
+
let firstFrame = firstFrameImage != null ? firstFrameImage : options.image;
|
|
186
|
+
let lastFrame = (_h = (_g = options.frameImages) == null ? void 0 : _g.find(
|
|
187
|
+
(frame) => frame.frameType === "last_frame"
|
|
188
|
+
)) == null ? void 0 : _h.image;
|
|
189
|
+
const firstFrameMediaType = firstFrame != null ? nonImageFrameMediaType(firstFrame) : void 0;
|
|
190
|
+
if (firstFrame != null && firstFrameMediaType != null) {
|
|
191
|
+
warnings.push({
|
|
192
|
+
type: "unsupported",
|
|
193
|
+
feature: firstFrameImage != null ? "frameImages" : "image",
|
|
194
|
+
details: firstFrameMediaType === "video" ? "MiniMax-H3 does not accept a video as a frame image. The video was ignored." : `MiniMax-H3 only accepts an image as a frame image; the "${firstFrame.mediaType}" file was ignored.`
|
|
195
|
+
});
|
|
196
|
+
firstFrame = void 0;
|
|
197
|
+
}
|
|
198
|
+
if (lastFrame != null) {
|
|
199
|
+
if (firstFrame == null) {
|
|
200
|
+
warnings.push({
|
|
201
|
+
type: "unsupported",
|
|
202
|
+
feature: "frameImages",
|
|
203
|
+
details: "MiniMax-H3 requires a first_frame when a last_frame is provided. The last_frame was ignored."
|
|
204
|
+
});
|
|
205
|
+
lastFrame = void 0;
|
|
206
|
+
} else {
|
|
207
|
+
const lastFrameMediaType = nonImageFrameMediaType(lastFrame);
|
|
208
|
+
if (lastFrameMediaType != null) {
|
|
209
|
+
warnings.push({
|
|
210
|
+
type: "unsupported",
|
|
211
|
+
feature: "frameImages",
|
|
212
|
+
details: lastFrameMediaType === "video" ? "MiniMax-H3 does not accept a video as a frame image. The last_frame video was ignored." : `MiniMax-H3 only accepts an image as a frame image; the "${lastFrame.mediaType}" last_frame was ignored.`
|
|
213
|
+
});
|
|
214
|
+
lastFrame = void 0;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const usesFrameImages = firstFrame != null || lastFrame != null;
|
|
219
|
+
const referenceFiles = (_i = options.inputReferences) != null ? _i : [];
|
|
220
|
+
const referenceAudioUrls = (_j = minimaxOptions == null ? void 0 : minimaxOptions.referenceAudioUrls) != null ? _j : [];
|
|
221
|
+
const usesReferences = referenceFiles.length > 0 || referenceAudioUrls.length > 0;
|
|
222
|
+
if (usesFrameImages) {
|
|
223
|
+
if (firstFrame != null) {
|
|
224
|
+
content.push({
|
|
225
|
+
type: "image_url",
|
|
226
|
+
image_url: { url: convertImageModelFileToDataUri(firstFrame) },
|
|
227
|
+
role: "first_frame"
|
|
228
|
+
});
|
|
229
|
+
sentImageCount++;
|
|
230
|
+
}
|
|
231
|
+
if (lastFrame != null) {
|
|
232
|
+
content.push({
|
|
233
|
+
type: "image_url",
|
|
234
|
+
image_url: { url: convertImageModelFileToDataUri(lastFrame) },
|
|
235
|
+
role: "last_frame"
|
|
236
|
+
});
|
|
237
|
+
sentImageCount++;
|
|
238
|
+
}
|
|
239
|
+
if (usesReferences) {
|
|
240
|
+
warnings.push({
|
|
241
|
+
type: "unsupported",
|
|
242
|
+
feature: "inputReferences",
|
|
243
|
+
details: "MiniMax-H3 cannot combine frame images with reference inputs. The references were ignored."
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
} else if (usesReferences) {
|
|
247
|
+
const referenceImages = [];
|
|
248
|
+
const referenceVideos = [];
|
|
249
|
+
for (const file of referenceFiles) {
|
|
250
|
+
const topLevelMediaType = file.mediaType != null ? getTopLevelMediaType(file.mediaType) : void 0;
|
|
251
|
+
if (topLevelMediaType === "video") {
|
|
252
|
+
referenceVideos.push(file);
|
|
253
|
+
} else if (topLevelMediaType === "image") {
|
|
254
|
+
referenceImages.push(file);
|
|
255
|
+
} else if (topLevelMediaType == null) {
|
|
256
|
+
warnings.push({
|
|
257
|
+
type: "unsupported",
|
|
258
|
+
feature: "inputReferences",
|
|
259
|
+
details: 'MiniMax-H3 requires an explicit mediaType to route URL references as video or image. Pass { data: url, mediaType: "video/mp4" } for video references. The reference was treated as an image.'
|
|
260
|
+
});
|
|
261
|
+
referenceImages.push(file);
|
|
262
|
+
} else {
|
|
263
|
+
warnings.push({
|
|
264
|
+
type: "unsupported",
|
|
265
|
+
feature: "inputReferences",
|
|
266
|
+
details: `MiniMax-H3 only accepts image and video references; the "${file.mediaType}" reference was ignored. Pass reference audio via providerOptions.minimax.referenceAudioUrls.`
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
for (const image of referenceImages.slice(0, MAX_REFERENCE_IMAGES)) {
|
|
271
|
+
content.push({
|
|
272
|
+
type: "image_url",
|
|
273
|
+
image_url: { url: convertImageModelFileToDataUri(image) },
|
|
274
|
+
role: "reference_image"
|
|
275
|
+
});
|
|
276
|
+
sentImageCount++;
|
|
277
|
+
}
|
|
278
|
+
if (referenceImages.length > MAX_REFERENCE_IMAGES) {
|
|
279
|
+
warnings.push({
|
|
280
|
+
type: "unsupported",
|
|
281
|
+
feature: "inputReferences",
|
|
282
|
+
details: `MiniMax-H3 accepts at most ${MAX_REFERENCE_IMAGES} reference images. Extra images were ignored.`
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
for (const video of referenceVideos.slice(0, MAX_REFERENCE_VIDEOS)) {
|
|
286
|
+
const url = convertImageModelFileToDataUri(video);
|
|
287
|
+
content.push({
|
|
288
|
+
type: "video_url",
|
|
289
|
+
video_url: { url },
|
|
290
|
+
role: "reference_video"
|
|
291
|
+
});
|
|
292
|
+
if (video.type === "url") {
|
|
293
|
+
sentReferenceVideoUrls.push(url);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (referenceVideos.length > MAX_REFERENCE_VIDEOS) {
|
|
297
|
+
warnings.push({
|
|
298
|
+
type: "unsupported",
|
|
299
|
+
feature: "inputReferences",
|
|
300
|
+
details: `MiniMax-H3 accepts at most ${MAX_REFERENCE_VIDEOS} reference videos. Extra videos were ignored.`
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
if (referenceAudioUrls.length > 0) {
|
|
304
|
+
if (referenceImages.length === 0 && referenceVideos.length === 0) {
|
|
305
|
+
warnings.push({
|
|
306
|
+
type: "unsupported",
|
|
307
|
+
feature: "referenceAudioUrls",
|
|
308
|
+
details: "MiniMax-H3 reference audio must be paired with at least one reference image or video. The audio was ignored."
|
|
309
|
+
});
|
|
310
|
+
} else {
|
|
311
|
+
for (const url of referenceAudioUrls.slice(0, MAX_REFERENCE_AUDIOS)) {
|
|
312
|
+
content.push({
|
|
313
|
+
type: "audio_url",
|
|
314
|
+
audio_url: { url },
|
|
315
|
+
role: "reference_audio"
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (referenceAudioUrls.length > MAX_REFERENCE_AUDIOS) {
|
|
319
|
+
warnings.push({
|
|
320
|
+
type: "unsupported",
|
|
321
|
+
feature: "referenceAudioUrls",
|
|
322
|
+
details: `MiniMax-H3 accepts at most ${MAX_REFERENCE_AUDIOS} reference audios. Extra audios were ignored.`
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const isTextToVideo = content.length === 1;
|
|
329
|
+
let ratio = minimaxOptions == null ? void 0 : minimaxOptions.ratio;
|
|
330
|
+
if (ratio == null && options.aspectRatio != null) {
|
|
331
|
+
if (allowedRatios.has(options.aspectRatio)) {
|
|
332
|
+
ratio = options.aspectRatio;
|
|
333
|
+
} else {
|
|
334
|
+
warnings.push({
|
|
335
|
+
type: "unsupported",
|
|
336
|
+
feature: "aspectRatio",
|
|
337
|
+
details: isTextToVideo ? `MiniMax-H3 does not support the aspect ratio "${options.aspectRatio}". Using the default (${DEFAULT_ASPECT_RATIO}).` : `MiniMax-H3 does not support the aspect ratio "${options.aspectRatio}". Using the provider default (adaptive).`
|
|
338
|
+
});
|
|
339
|
+
if (isTextToVideo) {
|
|
340
|
+
ratio = DEFAULT_ASPECT_RATIO;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (ratio === "adaptive" && isTextToVideo) {
|
|
345
|
+
warnings.push({
|
|
346
|
+
type: "unsupported",
|
|
347
|
+
feature: "aspectRatio",
|
|
348
|
+
details: `MiniMax-H3 text-to-video does not support the adaptive aspect ratio. Using the default (${DEFAULT_ASPECT_RATIO}).`
|
|
349
|
+
});
|
|
350
|
+
ratio = DEFAULT_ASPECT_RATIO;
|
|
351
|
+
}
|
|
352
|
+
if (usesFrameImages && ratio != null) {
|
|
353
|
+
warnings.push({
|
|
354
|
+
type: "unsupported",
|
|
355
|
+
feature: "aspectRatio",
|
|
356
|
+
details: "MiniMax-H3 derives the aspect ratio from the frame image; the requested ratio was ignored."
|
|
357
|
+
});
|
|
358
|
+
ratio = void 0;
|
|
359
|
+
}
|
|
360
|
+
if (ratio == null && isTextToVideo) {
|
|
361
|
+
ratio = DEFAULT_ASPECT_RATIO;
|
|
362
|
+
}
|
|
363
|
+
let duration = (_k = options.duration) != null ? _k : MIN_DURATION_SECONDS;
|
|
364
|
+
if (options.duration != null) {
|
|
365
|
+
if (!Number.isInteger(duration)) {
|
|
366
|
+
duration = Math.round(duration);
|
|
367
|
+
warnings.push({
|
|
368
|
+
type: "unsupported",
|
|
369
|
+
feature: "duration",
|
|
370
|
+
details: `MiniMax-H3 requires a whole number of seconds. The requested duration of ${options.duration} was rounded to ${duration}.`
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (duration > MAX_DURATION_SECONDS) {
|
|
374
|
+
warnings.push({
|
|
375
|
+
type: "unsupported",
|
|
376
|
+
feature: "duration",
|
|
377
|
+
details: `MiniMax-H3 supports at most ${MAX_DURATION_SECONDS} seconds. The requested duration of ${options.duration} was clamped to ${MAX_DURATION_SECONDS}.`
|
|
378
|
+
});
|
|
379
|
+
duration = MAX_DURATION_SECONDS;
|
|
380
|
+
} else if (duration < MIN_DURATION_SECONDS) {
|
|
381
|
+
warnings.push({
|
|
382
|
+
type: "unsupported",
|
|
383
|
+
feature: "duration",
|
|
384
|
+
details: `MiniMax-H3 requires at least ${MIN_DURATION_SECONDS} seconds. The requested duration of ${options.duration} was clamped to ${MIN_DURATION_SECONDS}.`
|
|
385
|
+
});
|
|
386
|
+
duration = MIN_DURATION_SECONDS;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const body = {
|
|
390
|
+
model: this.modelId,
|
|
391
|
+
content,
|
|
392
|
+
resolution,
|
|
393
|
+
duration
|
|
394
|
+
};
|
|
395
|
+
if (ratio != null) {
|
|
396
|
+
body.ratio = ratio;
|
|
397
|
+
}
|
|
398
|
+
if ((minimaxOptions == null ? void 0 : minimaxOptions.aigcWatermark) != null) {
|
|
399
|
+
body.aigc_watermark = minimaxOptions.aigcWatermark;
|
|
400
|
+
}
|
|
401
|
+
const baseURL = this.config.baseURL;
|
|
402
|
+
const { value: createResponse } = await postJsonToApi({
|
|
403
|
+
url: `${baseURL}/v2/video_generation`,
|
|
404
|
+
headers: combineHeaders(
|
|
405
|
+
await resolve(this.config.headers),
|
|
406
|
+
options.headers
|
|
407
|
+
),
|
|
408
|
+
body,
|
|
409
|
+
failedResponseHandler: minimaxVideoFailedResponseHandler,
|
|
410
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
411
|
+
minimaxCreateVideoResponseSchema
|
|
412
|
+
),
|
|
413
|
+
abortSignal: options.abortSignal,
|
|
414
|
+
fetch: this.config.fetch
|
|
415
|
+
});
|
|
416
|
+
const taskId = createResponse.task_id;
|
|
417
|
+
if (!taskId) {
|
|
418
|
+
throw new AISDKError({
|
|
419
|
+
name: "MINIMAX_VIDEO_GENERATION_ERROR",
|
|
420
|
+
message: `No task_id returned from the MiniMax API. Response: ${JSON.stringify(createResponse)}`
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
const pollIntervalMs = (_l = minimaxOptions == null ? void 0 : minimaxOptions.pollIntervalMs) != null ? _l : DEFAULT_POLL_INTERVAL_MS;
|
|
424
|
+
const pollTimeoutMs = (_m = minimaxOptions == null ? void 0 : minimaxOptions.pollTimeoutMs) != null ? _m : DEFAULT_POLL_TIMEOUT_MS;
|
|
425
|
+
const startTime = Date.now();
|
|
426
|
+
let responseHeaders;
|
|
427
|
+
while (true) {
|
|
428
|
+
await delay(pollIntervalMs, { abortSignal: options.abortSignal });
|
|
429
|
+
if (Date.now() - startTime > pollTimeoutMs) {
|
|
430
|
+
throw new AISDKError({
|
|
431
|
+
name: "MINIMAX_VIDEO_GENERATION_TIMEOUT",
|
|
432
|
+
message: `MiniMax video generation timed out after ${pollTimeoutMs}ms. Task ID: ${taskId}`
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi({
|
|
436
|
+
url: `${baseURL}/v2/query/video_generation/${taskId}`,
|
|
437
|
+
validateUrl: false,
|
|
438
|
+
headers: combineHeaders(
|
|
439
|
+
await resolve(this.config.headers),
|
|
440
|
+
options.headers
|
|
441
|
+
),
|
|
442
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
443
|
+
minimaxVideoStatusResponseSchema
|
|
444
|
+
),
|
|
445
|
+
failedResponseHandler: minimaxVideoFailedResponseHandler,
|
|
446
|
+
abortSignal: options.abortSignal,
|
|
447
|
+
fetch: this.config.fetch
|
|
448
|
+
});
|
|
449
|
+
responseHeaders = pollHeaders;
|
|
450
|
+
const task = statusResponse.task;
|
|
451
|
+
switch (task.status) {
|
|
452
|
+
case "succeeded": {
|
|
453
|
+
const url = (_n = task.content) == null ? void 0 : _n.url;
|
|
454
|
+
if (!url) {
|
|
455
|
+
throw new AISDKError({
|
|
456
|
+
name: "MINIMAX_VIDEO_GENERATION_ERROR",
|
|
457
|
+
message: `MiniMax video generation completed but no video URL was returned. Task ID: ${taskId}`
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
videos: [
|
|
462
|
+
{
|
|
463
|
+
type: "url",
|
|
464
|
+
url,
|
|
465
|
+
mediaType: "video/mp4"
|
|
466
|
+
}
|
|
467
|
+
],
|
|
468
|
+
warnings,
|
|
469
|
+
response: {
|
|
470
|
+
timestamp: currentDate,
|
|
471
|
+
modelId: this.modelId,
|
|
472
|
+
headers: responseHeaders
|
|
473
|
+
},
|
|
474
|
+
providerMetadata: {
|
|
475
|
+
minimax: {
|
|
476
|
+
taskId,
|
|
477
|
+
videoUrl: url,
|
|
478
|
+
resolvedInputs: {
|
|
479
|
+
imageCount: sentImageCount,
|
|
480
|
+
referenceVideoUrls: sentReferenceVideoUrls
|
|
481
|
+
},
|
|
482
|
+
...task.duration != null ? { duration: task.duration } : {},
|
|
483
|
+
...task.ratio != null ? { ratio: task.ratio } : {},
|
|
484
|
+
...task.resolution != null ? { resolution: task.resolution } : {},
|
|
485
|
+
...task.usage != null ? {
|
|
486
|
+
usage: {
|
|
487
|
+
totalSeconds: task.usage.total_seconds,
|
|
488
|
+
inputSeconds: task.usage.input_seconds,
|
|
489
|
+
outputSeconds: task.usage.output_seconds
|
|
490
|
+
}
|
|
491
|
+
} : {}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
case "failed": {
|
|
497
|
+
throw new AISDKError({
|
|
498
|
+
name: "MINIMAX_VIDEO_GENERATION_FAILED",
|
|
499
|
+
message: `MiniMax video generation failed${((_o = task.error) == null ? void 0 : _o.message) ? `: ${task.error.message}` : ""}${((_p = task.error) == null ? void 0 : _p.code) != null ? ` (${task.error.code})` : ""}. Task ID: ${taskId}`
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
case "cancelled": {
|
|
503
|
+
throw new AISDKError({
|
|
504
|
+
name: "MINIMAX_VIDEO_GENERATION_CANCELLED",
|
|
505
|
+
message: `MiniMax video generation was cancelled. Task ID: ${taskId}`
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
case "expired": {
|
|
509
|
+
throw new AISDKError({
|
|
510
|
+
name: "MINIMAX_VIDEO_GENERATION_EXPIRED",
|
|
511
|
+
message: `MiniMax video generation request expired. Task ID: ${taskId}`
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
// 'queued' | 'running' | unknown → keep polling.
|
|
515
|
+
default:
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
var minimaxCreateVideoResponseSchema = z2.object({
|
|
522
|
+
task_id: z2.string().nullish()
|
|
523
|
+
});
|
|
524
|
+
var minimaxVideoStatusResponseSchema = z2.object({
|
|
525
|
+
task: z2.object({
|
|
526
|
+
id: z2.string().nullish(),
|
|
527
|
+
status: z2.string().nullish(),
|
|
528
|
+
content: z2.object({
|
|
529
|
+
url: z2.string().nullish()
|
|
530
|
+
}).nullish(),
|
|
531
|
+
resolution: z2.string().nullish(),
|
|
532
|
+
duration: z2.number().nullish(),
|
|
533
|
+
ratio: z2.string().nullish(),
|
|
534
|
+
usage: z2.object({
|
|
535
|
+
total_seconds: z2.number().nullish(),
|
|
536
|
+
input_seconds: z2.number().nullish(),
|
|
537
|
+
output_seconds: z2.number().nullish()
|
|
538
|
+
}).nullish(),
|
|
539
|
+
error: z2.object({
|
|
540
|
+
code: z2.union([z2.string(), z2.number()]).nullish(),
|
|
541
|
+
message: z2.string().nullish()
|
|
542
|
+
}).nullish()
|
|
543
|
+
})
|
|
544
|
+
});
|
|
545
|
+
var minimaxVideoErrorSchema = z2.object({
|
|
546
|
+
type: z2.string().nullish(),
|
|
547
|
+
error: z2.object({
|
|
548
|
+
type: z2.string().nullish(),
|
|
549
|
+
message: z2.string().nullish(),
|
|
550
|
+
http_code: z2.union([z2.string(), z2.number()]).nullish()
|
|
551
|
+
}).nullish(),
|
|
552
|
+
request_id: z2.string().nullish()
|
|
553
|
+
});
|
|
554
|
+
var minimaxVideoFailedResponseHandler = createJsonErrorResponseHandler({
|
|
555
|
+
errorSchema: minimaxVideoErrorSchema,
|
|
556
|
+
errorToMessage: (data) => {
|
|
557
|
+
var _a, _b;
|
|
558
|
+
return (_b = (_a = data.error) == null ? void 0 : _a.message) != null ? _b : "MiniMax video generation error";
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
|
|
13
562
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "3.0.
|
|
563
|
+
var VERSION = true ? "3.0.3" : "0.0.0-test";
|
|
15
564
|
|
|
16
565
|
// src/minimax-provider.ts
|
|
17
566
|
var defaultBaseURL = "https://api.minimax.io/anthropic/v1";
|
|
567
|
+
var defaultVideoBaseURL = "https://api.minimax.io";
|
|
18
568
|
function createMiniMax(options = {}) {
|
|
19
|
-
var _a, _b;
|
|
569
|
+
var _a, _b, _c, _d;
|
|
20
570
|
const baseURL = (_b = withoutTrailingSlash((_a = options.baseURL) != null ? _a : defaultBaseURL)) != null ? _b : defaultBaseURL;
|
|
571
|
+
const videoBaseURL = (_d = withoutTrailingSlash((_c = options.videoBaseURL) != null ? _c : defaultVideoBaseURL)) != null ? _d : defaultVideoBaseURL;
|
|
21
572
|
const getHeaders = () => withUserAgentSuffix(
|
|
22
573
|
{
|
|
23
574
|
"anthropic-version": "2023-06-01",
|
|
@@ -38,10 +589,29 @@ function createMiniMax(options = {}) {
|
|
|
38
589
|
generateId,
|
|
39
590
|
supportedUrls: () => ({})
|
|
40
591
|
});
|
|
592
|
+
const getVideoHeaders = () => withUserAgentSuffix(
|
|
593
|
+
{
|
|
594
|
+
Authorization: `Bearer ${loadApiKey({
|
|
595
|
+
apiKey: options.apiKey,
|
|
596
|
+
environmentVariableName: "MINIMAX_API_KEY",
|
|
597
|
+
description: "MiniMax API key"
|
|
598
|
+
})}`,
|
|
599
|
+
...options.headers
|
|
600
|
+
},
|
|
601
|
+
`ai-sdk/minimax/${VERSION}`
|
|
602
|
+
);
|
|
603
|
+
const createVideoModel = (modelId) => new MiniMaxVideoModel(modelId, {
|
|
604
|
+
provider: "minimax.video",
|
|
605
|
+
baseURL: videoBaseURL,
|
|
606
|
+
headers: getVideoHeaders,
|
|
607
|
+
fetch: options.fetch
|
|
608
|
+
});
|
|
41
609
|
const provider = (modelId) => createChatModel(modelId);
|
|
42
610
|
provider.specificationVersion = "v4";
|
|
43
611
|
provider.languageModel = createChatModel;
|
|
44
612
|
provider.chat = createChatModel;
|
|
613
|
+
provider.video = createVideoModel;
|
|
614
|
+
provider.videoModel = createVideoModel;
|
|
45
615
|
provider.embeddingModel = (modelId) => {
|
|
46
616
|
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
47
617
|
};
|