mmx-cli 1.0.18 → 1.0.19
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/README.md +12 -0
- package/dist/index.d.ts +73 -10
- package/dist/mmx.mjs +262 -261
- package/dist/sdk.mjs +252 -12
- package/package.json +1 -1
package/dist/sdk.mjs
CHANGED
|
@@ -496,7 +496,7 @@ function maybeShowStatusBar(config, token, model) {
|
|
|
496
496
|
// package.json
|
|
497
497
|
var package_default = {
|
|
498
498
|
name: "mmx-cli",
|
|
499
|
-
version: "1.0.
|
|
499
|
+
version: "1.0.19",
|
|
500
500
|
description: "CLI for the MiniMax AI Platform",
|
|
501
501
|
type: "module",
|
|
502
502
|
repository: {
|
|
@@ -737,9 +737,15 @@ function imageEndpoint(baseUrl) {
|
|
|
737
737
|
function videoGenerateEndpoint(baseUrl) {
|
|
738
738
|
return `${baseUrl}/v1/video_generation`;
|
|
739
739
|
}
|
|
740
|
+
function videoGenerateV2Endpoint(baseUrl) {
|
|
741
|
+
return `${baseUrl}/v2/video_generation`;
|
|
742
|
+
}
|
|
740
743
|
function videoTaskEndpoint(baseUrl, taskId) {
|
|
741
744
|
return `${baseUrl}/v1/query/video_generation?task_id=${taskId}`;
|
|
742
745
|
}
|
|
746
|
+
function videoTaskV2Endpoint(baseUrl, taskId) {
|
|
747
|
+
return `${baseUrl}/v2/query/video_generation/${taskId}`;
|
|
748
|
+
}
|
|
743
749
|
function fileRetrieveEndpoint(baseUrl, fileId) {
|
|
744
750
|
return `${baseUrl}/v1/files/retrieve?file_id=${fileId}`;
|
|
745
751
|
}
|
|
@@ -1186,7 +1192,7 @@ async function downloadFile(url, destPath, opts) {
|
|
|
1186
1192
|
if (!res.ok) {
|
|
1187
1193
|
throw new CLIError(`Download failed: HTTP ${res.status}`, ExitCode.GENERAL);
|
|
1188
1194
|
}
|
|
1189
|
-
const contentLength = Number(res.headers.get("content-length") || 0);
|
|
1195
|
+
const contentLength = res.headers.get("content-encoding") ? 0 : Number(res.headers.get("content-length") || 0);
|
|
1190
1196
|
const reader = res.body?.getReader();
|
|
1191
1197
|
if (!reader)
|
|
1192
1198
|
throw new CLIError("No response body", ExitCode.GENERAL);
|
|
@@ -1213,6 +1219,9 @@ async function downloadFile(url, destPath, opts) {
|
|
|
1213
1219
|
received += value.byteLength;
|
|
1214
1220
|
progress?.update(received);
|
|
1215
1221
|
}
|
|
1222
|
+
if (contentLength > 0 && received !== contentLength) {
|
|
1223
|
+
throw new CLIError(`Download truncated: expected ${contentLength} bytes, received ${received}.`, ExitCode.NETWORK);
|
|
1224
|
+
}
|
|
1216
1225
|
readComplete = true;
|
|
1217
1226
|
} finally {
|
|
1218
1227
|
reader.releaseLock();
|
|
@@ -1358,11 +1367,169 @@ async function poll(config, opts) {
|
|
|
1358
1367
|
throw new CLIError("Polling timed out.", ExitCode.TIMEOUT, "Try increasing --timeout or check task status manually.");
|
|
1359
1368
|
}
|
|
1360
1369
|
|
|
1370
|
+
// src/utils/media.ts
|
|
1371
|
+
var VIDEO_V2_MEDIA_SIZE_LIMITS = {
|
|
1372
|
+
image: 30 * 1024 * 1024,
|
|
1373
|
+
video: 50 * 1024 * 1024,
|
|
1374
|
+
audio: 15 * 1024 * 1024
|
|
1375
|
+
};
|
|
1376
|
+
var VIDEO_V2_MAX_REQUEST_BODY_BYTES = 64 * 1024 * 1024;
|
|
1377
|
+
function dataUriDecodedSize(input) {
|
|
1378
|
+
const match = /^data:[^;,]+;base64,([\s\S]*)$/.exec(input);
|
|
1379
|
+
if (!match)
|
|
1380
|
+
return;
|
|
1381
|
+
const base64 = match[1].replace(/\s/g, "");
|
|
1382
|
+
const padding = base64.endsWith("==") ? 2 : base64.endsWith("=") ? 1 : 0;
|
|
1383
|
+
return Math.max(0, Math.floor(base64.length * 3 / 4) - padding);
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
// src/video/v2.ts
|
|
1387
|
+
var VIDEO_V2_MODEL = "MiniMax-H3";
|
|
1388
|
+
var VIDEO_V2_RATIOS = new Set([
|
|
1389
|
+
"adaptive",
|
|
1390
|
+
"21:9",
|
|
1391
|
+
"16:9",
|
|
1392
|
+
"4:3",
|
|
1393
|
+
"1:1",
|
|
1394
|
+
"3:4",
|
|
1395
|
+
"9:16"
|
|
1396
|
+
]);
|
|
1397
|
+
var VIDEO_V2_IMAGE_ROLES = new Set([
|
|
1398
|
+
"first_frame",
|
|
1399
|
+
"last_frame",
|
|
1400
|
+
"reference_image"
|
|
1401
|
+
]);
|
|
1402
|
+
|
|
1403
|
+
class VideoV2InputError extends Error {
|
|
1404
|
+
constructor(message) {
|
|
1405
|
+
super(message);
|
|
1406
|
+
this.name = "VideoV2InputError";
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
function isVideoV2Model(model) {
|
|
1410
|
+
return model === VIDEO_V2_MODEL;
|
|
1411
|
+
}
|
|
1412
|
+
function isVideoV2Request(request2) {
|
|
1413
|
+
return isVideoV2Model(request2.model);
|
|
1414
|
+
}
|
|
1415
|
+
function buildVideoV2Request(options) {
|
|
1416
|
+
const images = options.images ?? [];
|
|
1417
|
+
if (images.length > 1 && images.some((image) => !image.role)) {
|
|
1418
|
+
throw new VideoV2InputError("Each image must specify a role when multiple images are provided.");
|
|
1419
|
+
}
|
|
1420
|
+
const content = [
|
|
1421
|
+
{ type: "text", text: options.prompt },
|
|
1422
|
+
...images.map((image) => ({
|
|
1423
|
+
type: "image_url",
|
|
1424
|
+
image_url: { url: image.url },
|
|
1425
|
+
role: image.role ?? "first_frame"
|
|
1426
|
+
})),
|
|
1427
|
+
...(options.referenceVideos ?? []).map((url) => ({
|
|
1428
|
+
type: "video_url",
|
|
1429
|
+
video_url: { url },
|
|
1430
|
+
role: "reference_video"
|
|
1431
|
+
})),
|
|
1432
|
+
...(options.referenceAudios ?? []).map((url) => ({
|
|
1433
|
+
type: "audio_url",
|
|
1434
|
+
audio_url: { url },
|
|
1435
|
+
role: "reference_audio"
|
|
1436
|
+
}))
|
|
1437
|
+
];
|
|
1438
|
+
const hasFrameInput = content.some((item) => item.type === "image_url" && (item.role === "first_frame" || item.role === "last_frame"));
|
|
1439
|
+
const hasReferenceInput = content.some((item) => item.type !== "text" && item.role?.startsWith("reference_"));
|
|
1440
|
+
const request2 = {
|
|
1441
|
+
model: VIDEO_V2_MODEL,
|
|
1442
|
+
content,
|
|
1443
|
+
resolution: options.resolution ?? "2K",
|
|
1444
|
+
duration: options.duration ?? 5,
|
|
1445
|
+
ratio: hasFrameInput ? "adaptive" : options.ratio ?? (hasReferenceInput ? "adaptive" : "16:9")
|
|
1446
|
+
};
|
|
1447
|
+
if (options.callbackUrl)
|
|
1448
|
+
request2.callback_url = options.callbackUrl;
|
|
1449
|
+
validateVideoV2Request(request2);
|
|
1450
|
+
return request2;
|
|
1451
|
+
}
|
|
1452
|
+
function validateVideoV2Request(request2) {
|
|
1453
|
+
if (!isVideoV2Model(request2.model)) {
|
|
1454
|
+
throw new VideoV2InputError(`Video Generation V2 only supports ${VIDEO_V2_MODEL}.`);
|
|
1455
|
+
}
|
|
1456
|
+
const textItems = request2.content.filter((item) => item.type === "text");
|
|
1457
|
+
if (!textItems.some((item) => item.text.trim().length > 0)) {
|
|
1458
|
+
throw new VideoV2InputError("MiniMax-H3 requires a non-empty text content item.");
|
|
1459
|
+
}
|
|
1460
|
+
if (textItems.some((item) => item.text.length > 7000)) {
|
|
1461
|
+
throw new VideoV2InputError("MiniMax-H3 text content must not exceed 7000 characters.");
|
|
1462
|
+
}
|
|
1463
|
+
if (request2.resolution !== "2K") {
|
|
1464
|
+
throw new VideoV2InputError("MiniMax-H3 currently only supports 2K resolution.");
|
|
1465
|
+
}
|
|
1466
|
+
if (!Number.isInteger(request2.duration) || request2.duration < 4 || request2.duration > 15) {
|
|
1467
|
+
throw new VideoV2InputError("MiniMax-H3 duration must be an integer from 4 to 15 seconds.");
|
|
1468
|
+
}
|
|
1469
|
+
if (request2.ratio && !VIDEO_V2_RATIOS.has(request2.ratio)) {
|
|
1470
|
+
throw new VideoV2InputError("MiniMax-H3 ratio must be one of: adaptive, 21:9, 16:9, 4:3, 1:1, 3:4, 9:16.");
|
|
1471
|
+
}
|
|
1472
|
+
const images = request2.content.filter((item) => item.type === "image_url");
|
|
1473
|
+
const videos = request2.content.filter((item) => item.type === "video_url");
|
|
1474
|
+
const audios = request2.content.filter((item) => item.type === "audio_url");
|
|
1475
|
+
if (images.some((item) => item.role && !VIDEO_V2_IMAGE_ROLES.has(item.role))) {
|
|
1476
|
+
throw new VideoV2InputError("MiniMax-H3 image role must be one of: first_frame, last_frame, reference_image.");
|
|
1477
|
+
}
|
|
1478
|
+
if (videos.some((item) => item.role !== "reference_video")) {
|
|
1479
|
+
throw new VideoV2InputError("MiniMax-H3 video role must be reference_video.");
|
|
1480
|
+
}
|
|
1481
|
+
if (audios.some((item) => item.role !== "reference_audio")) {
|
|
1482
|
+
throw new VideoV2InputError("MiniMax-H3 audio role must be reference_audio.");
|
|
1483
|
+
}
|
|
1484
|
+
for (const image of images) {
|
|
1485
|
+
validateDataUriSize(image.image_url.url, "image");
|
|
1486
|
+
}
|
|
1487
|
+
for (const video of videos) {
|
|
1488
|
+
validateDataUriSize(video.video_url.url, "video");
|
|
1489
|
+
}
|
|
1490
|
+
for (const audio of audios) {
|
|
1491
|
+
validateDataUriSize(audio.audio_url.url, "audio");
|
|
1492
|
+
}
|
|
1493
|
+
const requestBodyBytes = Buffer.byteLength(JSON.stringify(request2));
|
|
1494
|
+
if (requestBodyBytes > VIDEO_V2_MAX_REQUEST_BODY_BYTES) {
|
|
1495
|
+
throw new VideoV2InputError(`MiniMax-H3 request body is ${(requestBodyBytes / 1024 / 1024).toFixed(1)} MB; the maximum is 64 MB. Use public URLs or mm_file:// file IDs instead of Base64.`);
|
|
1496
|
+
}
|
|
1497
|
+
const firstFrames = images.filter((item) => !item.role || item.role === "first_frame");
|
|
1498
|
+
const lastFrames = images.filter((item) => item.role === "last_frame");
|
|
1499
|
+
const referenceImages = images.filter((item) => item.role === "reference_image");
|
|
1500
|
+
const hasFrameInput = firstFrames.length > 0 || lastFrames.length > 0;
|
|
1501
|
+
const hasReferenceInput = referenceImages.length > 0 || videos.length > 0 || audios.length > 0;
|
|
1502
|
+
if (firstFrames.length > 1 || lastFrames.length > 1) {
|
|
1503
|
+
throw new VideoV2InputError("MiniMax-H3 accepts at most one first frame and one last frame.");
|
|
1504
|
+
}
|
|
1505
|
+
if (referenceImages.length > 9 || videos.length > 3 || audios.length > 3) {
|
|
1506
|
+
throw new VideoV2InputError("MiniMax-H3 accepts up to 9 reference images, 3 reference videos, and 3 reference audios.");
|
|
1507
|
+
}
|
|
1508
|
+
if (hasFrameInput && hasReferenceInput) {
|
|
1509
|
+
throw new VideoV2InputError("MiniMax-H3 frame inputs and reference inputs cannot be used together.");
|
|
1510
|
+
}
|
|
1511
|
+
if (audios.length > 0 && referenceImages.length === 0 && videos.length === 0) {
|
|
1512
|
+
throw new VideoV2InputError("MiniMax-H3 reference audio requires at least one reference image or reference video.");
|
|
1513
|
+
}
|
|
1514
|
+
const isTextOnly = request2.content.every((item) => item.type === "text");
|
|
1515
|
+
if (isTextOnly && (!request2.ratio || request2.ratio === "adaptive")) {
|
|
1516
|
+
throw new VideoV2InputError("MiniMax-H3 text-to-video requires a concrete ratio; adaptive is not supported.");
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
function validateDataUriSize(url, kind) {
|
|
1520
|
+
const size = dataUriDecodedSize(url);
|
|
1521
|
+
const maxBytes = VIDEO_V2_MEDIA_SIZE_LIMITS[kind];
|
|
1522
|
+
if (size !== undefined && size > maxBytes) {
|
|
1523
|
+
throw new VideoV2InputError(`MiniMax-H3 ${kind} input is ${(size / 1024 / 1024).toFixed(1)} MB; the maximum is ${maxBytes / 1024 / 1024} MB.`);
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1361
1527
|
// src/sdk/video/index.ts
|
|
1362
1528
|
class VideoSDK extends Client {
|
|
1363
1529
|
async generate(request2) {
|
|
1364
1530
|
const body = this.validateParams(request2);
|
|
1365
|
-
const
|
|
1531
|
+
const usesV2 = isVideoV2Request(body);
|
|
1532
|
+
const url = usesV2 ? videoGenerateV2Endpoint(this.config.baseUrl) : videoGenerateEndpoint(this.config.baseUrl);
|
|
1366
1533
|
const res = await this.requestJson({
|
|
1367
1534
|
url,
|
|
1368
1535
|
method: "POST",
|
|
@@ -1372,8 +1539,20 @@ class VideoSDK extends Client {
|
|
|
1372
1539
|
if (request2.async) {
|
|
1373
1540
|
return { taskId };
|
|
1374
1541
|
}
|
|
1542
|
+
if (usesV2) {
|
|
1543
|
+
const taskUrl2 = videoTaskV2Endpoint(this.config.baseUrl, taskId);
|
|
1544
|
+
const result = await poll(this.config, {
|
|
1545
|
+
url: taskUrl2,
|
|
1546
|
+
intervalSec: request2.pollInterval ?? 5,
|
|
1547
|
+
timeoutSec: request2.timeout ?? this.config.timeout,
|
|
1548
|
+
isComplete: (d) => d.task.status === "succeeded",
|
|
1549
|
+
isFailed: (d) => ["failed", "cancelled", "expired"].includes(d.task.status),
|
|
1550
|
+
getStatus: (d) => d.task.status
|
|
1551
|
+
});
|
|
1552
|
+
return result.task;
|
|
1553
|
+
}
|
|
1375
1554
|
const taskUrl = videoTaskEndpoint(this.config.baseUrl, taskId);
|
|
1376
|
-
|
|
1555
|
+
return await poll(this.config, {
|
|
1377
1556
|
url: taskUrl,
|
|
1378
1557
|
intervalSec: request2.pollInterval ?? 5,
|
|
1379
1558
|
timeoutSec: request2.timeout ?? this.config.timeout,
|
|
@@ -1381,9 +1560,13 @@ class VideoSDK extends Client {
|
|
|
1381
1560
|
isFailed: (d) => d.status === "Failed",
|
|
1382
1561
|
getStatus: (d) => d.status
|
|
1383
1562
|
});
|
|
1384
|
-
return result;
|
|
1385
1563
|
}
|
|
1386
|
-
async getTask({ taskId }) {
|
|
1564
|
+
async getTask({ taskId, model }) {
|
|
1565
|
+
if (isVideoV2Model(model)) {
|
|
1566
|
+
const url2 = videoTaskV2Endpoint(this.config.baseUrl, taskId);
|
|
1567
|
+
const result = await this.requestJson({ url: url2 });
|
|
1568
|
+
return result.task;
|
|
1569
|
+
}
|
|
1387
1570
|
const url = videoTaskEndpoint(this.config.baseUrl, taskId);
|
|
1388
1571
|
return await this.requestJson({ url });
|
|
1389
1572
|
}
|
|
@@ -1402,7 +1585,55 @@ class VideoSDK extends Client {
|
|
|
1402
1585
|
};
|
|
1403
1586
|
}
|
|
1404
1587
|
validateParams(request2) {
|
|
1405
|
-
const
|
|
1588
|
+
const params = { ...request2 };
|
|
1589
|
+
delete params.async;
|
|
1590
|
+
delete params.pollInterval;
|
|
1591
|
+
delete params.timeout;
|
|
1592
|
+
if ("content" in params || isVideoV2Model(params.model)) {
|
|
1593
|
+
try {
|
|
1594
|
+
if ("content" in params) {
|
|
1595
|
+
if (params.model && !isVideoV2Model(params.model)) {
|
|
1596
|
+
throw new VideoV2InputError("content is only supported with model MiniMax-H3");
|
|
1597
|
+
}
|
|
1598
|
+
const content = params.content;
|
|
1599
|
+
const hasFrameInput = content.some((item) => item.type === "image_url" && (!item.role || item.role === "first_frame" || item.role === "last_frame"));
|
|
1600
|
+
const hasReferenceInput = content.some((item) => item.type !== "text" && item.role?.startsWith("reference_"));
|
|
1601
|
+
const body = {
|
|
1602
|
+
...params,
|
|
1603
|
+
model: VIDEO_V2_MODEL,
|
|
1604
|
+
resolution: params.resolution ?? "2K",
|
|
1605
|
+
duration: params.duration ?? 5,
|
|
1606
|
+
ratio: params.ratio ?? (hasFrameInput || hasReferenceInput ? "adaptive" : "16:9")
|
|
1607
|
+
};
|
|
1608
|
+
validateVideoV2Request(body);
|
|
1609
|
+
return body;
|
|
1610
|
+
}
|
|
1611
|
+
const prompt2 = params.prompt;
|
|
1612
|
+
if (!prompt2) {
|
|
1613
|
+
throw new VideoV2InputError("prompt or content is required");
|
|
1614
|
+
}
|
|
1615
|
+
return buildVideoV2Request({
|
|
1616
|
+
prompt: prompt2,
|
|
1617
|
+
images: [
|
|
1618
|
+
...params.first_frame_image ? [{ url: params.first_frame_image, role: "first_frame" }] : [],
|
|
1619
|
+
...params.last_frame_image ? [{ url: params.last_frame_image, role: "last_frame" }] : []
|
|
1620
|
+
],
|
|
1621
|
+
resolution: params.resolution,
|
|
1622
|
+
duration: params.duration,
|
|
1623
|
+
ratio: params.ratio,
|
|
1624
|
+
callbackUrl: params.callback_url
|
|
1625
|
+
});
|
|
1626
|
+
} catch (error) {
|
|
1627
|
+
if (error instanceof VideoV2InputError) {
|
|
1628
|
+
throw new SDKError(error.message, ExitCode.USAGE);
|
|
1629
|
+
}
|
|
1630
|
+
throw error;
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
if ("resolution" in params || "duration" in params || "ratio" in params) {
|
|
1634
|
+
throw new SDKError("resolution, duration, and ratio require model MiniMax-H3", ExitCode.USAGE);
|
|
1635
|
+
}
|
|
1636
|
+
const { prompt, model, first_frame_image, last_frame_image, subject_reference } = params;
|
|
1406
1637
|
if (!prompt) {
|
|
1407
1638
|
throw new SDKError("prompt is required", ExitCode.USAGE);
|
|
1408
1639
|
}
|
|
@@ -1425,9 +1656,10 @@ class VideoSDK extends Client {
|
|
|
1425
1656
|
if (last_frame_image && subject_reference) {
|
|
1426
1657
|
throw new SDKError("last_frame_image and subject_reference cannot be used together (SEF and S2V are different modes).", ExitCode.USAGE);
|
|
1427
1658
|
}
|
|
1428
|
-
return
|
|
1659
|
+
return {
|
|
1660
|
+
...params,
|
|
1429
1661
|
model: resolvedModel
|
|
1430
|
-
}
|
|
1662
|
+
};
|
|
1431
1663
|
}
|
|
1432
1664
|
}
|
|
1433
1665
|
|
|
@@ -1760,15 +1992,23 @@ class SearchSDK extends Client {
|
|
|
1760
1992
|
}
|
|
1761
1993
|
|
|
1762
1994
|
// src/utils/image.ts
|
|
1763
|
-
import { readFileSync as readFileSync2, existsSync as existsSync5 } from "fs";
|
|
1995
|
+
import { readFileSync as readFileSync2, existsSync as existsSync5, statSync } from "fs";
|
|
1764
1996
|
import { extname } from "path";
|
|
1765
1997
|
var IMAGE_MIME_TYPES = {
|
|
1766
1998
|
".jpg": "image/jpeg",
|
|
1767
1999
|
".jpeg": "image/jpeg",
|
|
1768
2000
|
".png": "image/png",
|
|
1769
|
-
".webp": "image/webp"
|
|
2001
|
+
".webp": "image/webp",
|
|
2002
|
+
".heic": "image/heic",
|
|
2003
|
+
".heif": "image/heif"
|
|
1770
2004
|
};
|
|
1771
|
-
function localFileToDataUri(filePath) {
|
|
2005
|
+
function localFileToDataUri(filePath, maxBytes) {
|
|
2006
|
+
if (maxBytes !== undefined) {
|
|
2007
|
+
const size = statSync(filePath).size;
|
|
2008
|
+
if (size > maxBytes) {
|
|
2009
|
+
throw new CLIError(`Image file is ${(size / 1024 / 1024).toFixed(1)} MB; MiniMax-H3 allows at most ${maxBytes / 1024 / 1024} MB.`, ExitCode.USAGE, "Use a public URL or mm_file:// file ID for large images.");
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
1772
2012
|
const ext = extname(filePath).toLowerCase();
|
|
1773
2013
|
const mime = IMAGE_MIME_TYPES[ext] || "image/jpeg";
|
|
1774
2014
|
const data = readFileSync2(filePath);
|