jimeng-cli 0.3.1 → 0.3.2
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 +1 -1
- package/dist/{chunk-2IIK4X7C.js → chunk-FAXTAAQO.js} +90 -45
- package/dist/{chunk-2IIK4X7C.js.map → chunk-FAXTAAQO.js.map} +1 -1
- package/dist/cli/index.cjs +365 -286
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +277 -243
- package/dist/cli/index.js.map +1 -1
- package/dist/mcp/index.cjs +93 -48
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.js +6 -5
- package/dist/mcp/index.js.map +1 -1
- package/package.json +4 -4
package/dist/cli/index.cjs
CHANGED
|
@@ -5627,6 +5627,17 @@ var import_mime = __toESM(require("mime"), 1);
|
|
|
5627
5627
|
var import_axios = __toESM(require("axios"), 1);
|
|
5628
5628
|
var import_uuid = require("uuid");
|
|
5629
5629
|
var import_date_fns = require("date-fns");
|
|
5630
|
+
var CRC32_TABLE = (() => {
|
|
5631
|
+
const table = [];
|
|
5632
|
+
for (let i = 0; i < 256; i++) {
|
|
5633
|
+
let crc = i;
|
|
5634
|
+
for (let j = 0; j < 8; j++) {
|
|
5635
|
+
crc = crc & 1 ? 3988292384 ^ crc >>> 1 : crc >>> 1;
|
|
5636
|
+
}
|
|
5637
|
+
table[i] = crc;
|
|
5638
|
+
}
|
|
5639
|
+
return table;
|
|
5640
|
+
})();
|
|
5630
5641
|
var util = {
|
|
5631
5642
|
uuid: (separator = true) => separator ? (0, import_uuid.v4)() : (0, import_uuid.v4)().replace(/-/g, ""),
|
|
5632
5643
|
getDateString(format = "yyyy-MM-dd", date = /* @__PURE__ */ new Date()) {
|
|
@@ -5672,18 +5683,10 @@ var util = {
|
|
|
5672
5683
|
* @returns CRC32 十六进制字符串
|
|
5673
5684
|
*/
|
|
5674
5685
|
calculateCRC32(buffer) {
|
|
5675
|
-
const crcTable = [];
|
|
5676
|
-
for (let i = 0; i < 256; i++) {
|
|
5677
|
-
let crc2 = i;
|
|
5678
|
-
for (let j = 0; j < 8; j++) {
|
|
5679
|
-
crc2 = crc2 & 1 ? 3988292384 ^ crc2 >>> 1 : crc2 >>> 1;
|
|
5680
|
-
}
|
|
5681
|
-
crcTable[i] = crc2;
|
|
5682
|
-
}
|
|
5683
5686
|
let crc = 0 ^ -1;
|
|
5684
5687
|
const bytes = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5685
5688
|
for (let i = 0; i < bytes.length; i++) {
|
|
5686
|
-
crc = crc >>> 8 ^
|
|
5689
|
+
crc = crc >>> 8 ^ CRC32_TABLE[(crc ^ bytes[i]) & 255];
|
|
5687
5690
|
}
|
|
5688
5691
|
return ((crc ^ -1) >>> 0).toString(16).padStart(8, "0");
|
|
5689
5692
|
}
|
|
@@ -5996,16 +5999,18 @@ var JimengErrorHandler = class {
|
|
|
5996
5999
|
* 处理轮询超时错误
|
|
5997
6000
|
* @returns 如果有部分结果,返回 void 而不抛出异常
|
|
5998
6001
|
*/
|
|
5999
|
-
static handlePollingTimeout(pollCount, maxPollCount, elapsedTime, status, itemCount, historyId) {
|
|
6000
|
-
const
|
|
6002
|
+
static handlePollingTimeout(pollCount, maxPollCount, elapsedTime, status, itemCount, historyId, type = "image") {
|
|
6003
|
+
const typeText = type === "image" ? "\u56FE\u7247" : "\u89C6\u9891";
|
|
6004
|
+
const message = `\u8F6E\u8BE2\u8D85\u65F6: \u5DF2\u8F6E\u8BE2 ${pollCount} \u6B21\uFF0C\u8017\u65F6 ${elapsedTime} \u79D2\uFF0C\u6700\u7EC8\u72B6\u6001: ${status}\uFF0C${typeText}\u6570\u91CF: ${itemCount}`;
|
|
6001
6005
|
logger_default.warn(message + (historyId ? `\uFF0C\u5386\u53F2ID: ${historyId}` : ""));
|
|
6002
6006
|
if (itemCount === 0) {
|
|
6007
|
+
const exception = type === "image" ? exceptions_default.API_IMAGE_GENERATION_FAILED : exceptions_default.API_VIDEO_GENERATION_FAILED;
|
|
6003
6008
|
throw new APIException(
|
|
6004
|
-
|
|
6005
|
-
|
|
6009
|
+
exception,
|
|
6010
|
+
`${typeText}\u751F\u6210\u8D85\u65F6\u4E14\u65E0\u7ED3\u679C\uFF0C\u72B6\u6001\u7801: ${status}${historyId ? `\uFF0C\u5386\u53F2ID: ${historyId}` : ""}`
|
|
6006
6011
|
);
|
|
6007
6012
|
}
|
|
6008
|
-
logger_default.info(`\u8F6E\u8BE2\u8D85\u65F6\u4F46\u5DF2\u83B7\u5F97 ${itemCount} \
|
|
6013
|
+
logger_default.info(`\u8F6E\u8BE2\u8D85\u65F6\u4F46\u5DF2\u83B7\u5F97 ${itemCount} \u4E2A${typeText}\uFF0C\u5C06\u8FD4\u56DE\u73B0\u6709\u7ED3\u679C`);
|
|
6009
6014
|
}
|
|
6010
6015
|
/**
|
|
6011
6016
|
* 处理生成失败错误
|
|
@@ -6070,7 +6075,7 @@ var BASE_URL_IMAGEX_US = "https://imagex16-normal-us-ttp.capcutapi.us";
|
|
|
6070
6075
|
var BASE_URL_DREAMINA_HK = "https://mweb-api-sg.capcut.com";
|
|
6071
6076
|
var BASE_URL_IMAGEX_HK = "https://imagex-normal-sg.capcutapi.com";
|
|
6072
6077
|
var WEB_VERSION = "7.5.0";
|
|
6073
|
-
var DA_VERSION = "3.3.
|
|
6078
|
+
var DA_VERSION = "3.3.12";
|
|
6074
6079
|
|
|
6075
6080
|
// src/api/consts/common.ts
|
|
6076
6081
|
var BASE_URL_CN = "https://jimeng.jianying.com";
|
|
@@ -6091,7 +6096,7 @@ var VERSION_CODE = "8.4.0";
|
|
|
6091
6096
|
var DEFAULT_IMAGE_MODEL = "jimeng-4.5";
|
|
6092
6097
|
var DEFAULT_IMAGE_MODEL_US = "jimeng-4.5";
|
|
6093
6098
|
var DEFAULT_VIDEO_MODEL = "jimeng-video-3.5-pro";
|
|
6094
|
-
var DRAFT_VERSION = "3.3.
|
|
6099
|
+
var DRAFT_VERSION = "3.3.9";
|
|
6095
6100
|
var DRAFT_MIN_VERSION = "3.0.2";
|
|
6096
6101
|
var DRAFT_VERSION_OMNI = "3.3.9";
|
|
6097
6102
|
var OMNI_BENEFIT_TYPE = "dreamina_video_seedance_20_video_add";
|
|
@@ -6604,6 +6609,9 @@ function checkResult(result) {
|
|
|
6604
6609
|
}
|
|
6605
6610
|
async function getTokenLiveStatus(refreshToken, regionInfo) {
|
|
6606
6611
|
try {
|
|
6612
|
+
if (regionInfo.isInternational) {
|
|
6613
|
+
return await checkInternationalTokenLive(refreshToken, regionInfo);
|
|
6614
|
+
}
|
|
6607
6615
|
const result = await request(
|
|
6608
6616
|
"POST",
|
|
6609
6617
|
"/passport/account/info/v2",
|
|
@@ -6622,6 +6630,44 @@ async function getTokenLiveStatus(refreshToken, regionInfo) {
|
|
|
6622
6630
|
return false;
|
|
6623
6631
|
}
|
|
6624
6632
|
}
|
|
6633
|
+
async function checkInternationalTokenLive(refreshToken, regionInfo) {
|
|
6634
|
+
const aid = getAssistantId(regionInfo);
|
|
6635
|
+
const countryCode = regionInfo.isUS ? "us" : regionInfo.isJP ? "jp" : regionInfo.isHK ? "hk" : "sg";
|
|
6636
|
+
const cookie = generateCookie(refreshToken);
|
|
6637
|
+
try {
|
|
6638
|
+
const response = await import_axios2.default.get(
|
|
6639
|
+
"https://dreamina.capcut.com/passport/web/account/info/",
|
|
6640
|
+
{
|
|
6641
|
+
params: {
|
|
6642
|
+
aid,
|
|
6643
|
+
account_sdk_source: "web",
|
|
6644
|
+
sdk_version: "2.1.10-tiktok",
|
|
6645
|
+
language: countryCode === "jp" ? "ja" : "en"
|
|
6646
|
+
},
|
|
6647
|
+
headers: {
|
|
6648
|
+
...FAKE_HEADERS,
|
|
6649
|
+
Cookie: cookie,
|
|
6650
|
+
Referer: "https://dreamina.capcut.com/ai-tool/home/",
|
|
6651
|
+
Origin: "https://dreamina.capcut.com",
|
|
6652
|
+
Appid: String(aid),
|
|
6653
|
+
"store-country-code": countryCode,
|
|
6654
|
+
"store-country-code-src": "uid"
|
|
6655
|
+
},
|
|
6656
|
+
timeout: 15e3
|
|
6657
|
+
}
|
|
6658
|
+
);
|
|
6659
|
+
const data = response.data;
|
|
6660
|
+
if (data && typeof data === "object") {
|
|
6661
|
+
const obj = data;
|
|
6662
|
+
if (obj.user_id || obj.email || obj.data) {
|
|
6663
|
+
return true;
|
|
6664
|
+
}
|
|
6665
|
+
}
|
|
6666
|
+
return false;
|
|
6667
|
+
} catch {
|
|
6668
|
+
return false;
|
|
6669
|
+
}
|
|
6670
|
+
}
|
|
6625
6671
|
|
|
6626
6672
|
// src/lib/session-pool.ts
|
|
6627
6673
|
function sample(arr) {
|
|
@@ -7226,8 +7272,7 @@ var import_node_path = __toESM(require("path"), 1);
|
|
|
7226
7272
|
var import_promises2 = require("fs/promises");
|
|
7227
7273
|
var import_minimist2 = __toESM(require("minimist"), 1);
|
|
7228
7274
|
function maskToken(token) {
|
|
7229
|
-
|
|
7230
|
-
if (n <= 10) return "***";
|
|
7275
|
+
if (token.length <= 10) return "***";
|
|
7231
7276
|
return `${token.slice(0, 4)}...${token.slice(-4)}`;
|
|
7232
7277
|
}
|
|
7233
7278
|
function formatUnixMs(value) {
|
|
@@ -7242,14 +7287,14 @@ function printTokenEntriesTable(items) {
|
|
|
7242
7287
|
console.log("token region enabled live lastCredit lastCheckedAt failures");
|
|
7243
7288
|
for (const item of items) {
|
|
7244
7289
|
if (!item || typeof item !== "object") continue;
|
|
7245
|
-
const
|
|
7246
|
-
const token = typeof
|
|
7247
|
-
const region = typeof
|
|
7248
|
-
const enabled = typeof
|
|
7249
|
-
const live = typeof
|
|
7250
|
-
const lastCredit = typeof
|
|
7251
|
-
const lastCheckedAt = formatUnixMs(
|
|
7252
|
-
const failures = typeof
|
|
7290
|
+
const e = item;
|
|
7291
|
+
const token = typeof e.token === "string" ? e.token : "-";
|
|
7292
|
+
const region = typeof e.region === "string" ? e.region : "-";
|
|
7293
|
+
const enabled = typeof e.enabled === "boolean" ? String(e.enabled) : "-";
|
|
7294
|
+
const live = typeof e.live === "boolean" ? String(e.live) : "-";
|
|
7295
|
+
const lastCredit = typeof e.lastCredit === "number" ? String(e.lastCredit) : "-";
|
|
7296
|
+
const lastCheckedAt = formatUnixMs(e.lastCheckedAt);
|
|
7297
|
+
const failures = typeof e.consecutiveFailures === "number" ? String(e.consecutiveFailures) : "-";
|
|
7253
7298
|
console.log(`${token} ${region} ${enabled} ${live} ${lastCredit} ${lastCheckedAt} ${failures}`);
|
|
7254
7299
|
}
|
|
7255
7300
|
}
|
|
@@ -7288,6 +7333,30 @@ ${usage}`);
|
|
|
7288
7333
|
}
|
|
7289
7334
|
return deduped;
|
|
7290
7335
|
}
|
|
7336
|
+
function resolveTokenRegionPairs(explicitTokens, regionCode, deps, opts) {
|
|
7337
|
+
if (explicitTokens.length > 0) {
|
|
7338
|
+
return explicitTokens.map((token) => {
|
|
7339
|
+
var _a;
|
|
7340
|
+
const entryRegion = (_a = session_pool_default.getTokenEntry(token)) == null ? void 0 : _a.region;
|
|
7341
|
+
const finalRegion = regionCode || entryRegion;
|
|
7342
|
+
if (!finalRegion) {
|
|
7343
|
+
deps.fail(`Missing region for token ${maskToken(token)}. Provide --region or register token in token-pool.`);
|
|
7344
|
+
}
|
|
7345
|
+
return { token, region: finalRegion };
|
|
7346
|
+
});
|
|
7347
|
+
}
|
|
7348
|
+
const requireLive = (opts == null ? void 0 : opts.requireLive) ?? true;
|
|
7349
|
+
const entries = session_pool_default.getEntries(false).filter((item) => {
|
|
7350
|
+
if (!item.enabled || !item.region) return false;
|
|
7351
|
+
if (requireLive && item.live === false) return false;
|
|
7352
|
+
if (regionCode && item.region !== regionCode) return false;
|
|
7353
|
+
return true;
|
|
7354
|
+
});
|
|
7355
|
+
if (entries.length === 0) {
|
|
7356
|
+
deps.fail("No token available. Provide --token or configure token-pool.");
|
|
7357
|
+
}
|
|
7358
|
+
return entries.map((item) => ({ token: item.token, region: item.region }));
|
|
7359
|
+
}
|
|
7291
7360
|
function createTokenSubcommands(deps) {
|
|
7292
7361
|
const handleTokenCheck = async (argv) => {
|
|
7293
7362
|
const args = (0, import_minimist2.default)(argv, {
|
|
@@ -7299,74 +7368,68 @@ function createTokenSubcommands(deps) {
|
|
|
7299
7368
|
console.log(usage);
|
|
7300
7369
|
return;
|
|
7301
7370
|
}
|
|
7302
|
-
const
|
|
7303
|
-
const regionCode = deps.parseRegionOrFail(
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
}
|
|
7307
|
-
const tokens = await collectTokensFromArgs(args, usage, deps, true);
|
|
7371
|
+
const explicitRegion = deps.getSingleString(args, "region");
|
|
7372
|
+
const regionCode = explicitRegion ? deps.parseRegionOrFail(explicitRegion) : void 0;
|
|
7373
|
+
await deps.ensureTokenPoolReady();
|
|
7374
|
+
const explicitTokens = await collectTokensFromArgs(args, usage, deps, false);
|
|
7375
|
+
const pairs = resolveTokenRegionPairs(explicitTokens, regionCode, deps, { requireLive: false });
|
|
7308
7376
|
if (!args.json) {
|
|
7309
|
-
console.log(`Checking ${
|
|
7377
|
+
console.log(`Checking ${pairs.length} token(s)`);
|
|
7310
7378
|
}
|
|
7311
|
-
await deps.ensureTokenPoolReady();
|
|
7312
7379
|
let invalid = 0;
|
|
7313
7380
|
let requestErrors = 0;
|
|
7314
7381
|
const results = [];
|
|
7315
|
-
for (const token of
|
|
7382
|
+
for (const { token, region } of pairs) {
|
|
7316
7383
|
const masked = maskToken(token);
|
|
7317
7384
|
try {
|
|
7318
|
-
const live = await getTokenLiveStatus(token, buildRegionInfo(
|
|
7385
|
+
const live = await getTokenLiveStatus(token, buildRegionInfo(region));
|
|
7319
7386
|
await session_pool_default.syncTokenCheckResult(token, live);
|
|
7320
|
-
if (live
|
|
7321
|
-
if (!args.json) console.log(`[OK] ${masked} live=true`);
|
|
7387
|
+
if (live) {
|
|
7388
|
+
if (!args.json) console.log(`[OK] ${masked} (${region}) live=true`);
|
|
7389
|
+
results.push({ token_masked: masked, region, live: true });
|
|
7322
7390
|
} else {
|
|
7323
7391
|
invalid += 1;
|
|
7324
|
-
if (!args.json) console.log(`[FAIL] ${masked} live=false`);
|
|
7392
|
+
if (!args.json) console.log(`[FAIL] ${masked} (${region}) live=false`);
|
|
7393
|
+
results.push({ token_masked: masked, region, live: false });
|
|
7325
7394
|
}
|
|
7326
|
-
results.push({ token_masked: masked, live: live === true });
|
|
7327
7395
|
} catch (error) {
|
|
7328
7396
|
requestErrors += 1;
|
|
7329
7397
|
const message = error instanceof Error ? error.message : String(error);
|
|
7330
|
-
if (!args.json) console.log(`[ERROR] ${masked} ${message}`);
|
|
7331
|
-
results.push({ token_masked: masked, error: message });
|
|
7398
|
+
if (!args.json) console.log(`[ERROR] ${masked} (${region}) ${message}`);
|
|
7399
|
+
results.push({ token_masked: masked, region, error: message });
|
|
7332
7400
|
}
|
|
7333
7401
|
}
|
|
7334
7402
|
if (args.json) {
|
|
7335
7403
|
deps.printCommandJson("token.check", results, {
|
|
7336
|
-
total:
|
|
7404
|
+
total: pairs.length,
|
|
7337
7405
|
invalid,
|
|
7338
7406
|
request_errors: requestErrors
|
|
7339
7407
|
});
|
|
7340
7408
|
} else {
|
|
7341
|
-
console.log(`Summary: total=${
|
|
7409
|
+
console.log(`Summary: total=${pairs.length} invalid=${invalid} request_errors=${requestErrors}`);
|
|
7342
7410
|
}
|
|
7343
7411
|
if (requestErrors > 0) process.exit(3);
|
|
7344
7412
|
if (invalid > 0) process.exit(2);
|
|
7345
7413
|
};
|
|
7346
7414
|
const handleTokenList = async (argv) => {
|
|
7347
|
-
const args = (0, import_minimist2.default)(argv, {
|
|
7348
|
-
boolean: ["help", "json"]
|
|
7349
|
-
});
|
|
7350
|
-
const usage = deps.getUsage("list");
|
|
7415
|
+
const args = (0, import_minimist2.default)(argv, { boolean: ["help", "json"] });
|
|
7351
7416
|
if (args.help) {
|
|
7352
|
-
console.log(
|
|
7417
|
+
console.log(deps.getUsage("list"));
|
|
7353
7418
|
return;
|
|
7354
7419
|
}
|
|
7355
7420
|
await deps.ensureTokenPoolReady();
|
|
7356
|
-
const
|
|
7421
|
+
const snapshot = buildTokenPoolSnapshot();
|
|
7357
7422
|
if (args.json) {
|
|
7358
|
-
deps.printCommandJson("token.list",
|
|
7423
|
+
deps.printCommandJson("token.list", snapshot);
|
|
7359
7424
|
return;
|
|
7360
7425
|
}
|
|
7361
|
-
const body =
|
|
7362
|
-
|
|
7363
|
-
if (summary && typeof summary === "object") {
|
|
7426
|
+
const body = snapshot && typeof snapshot === "object" ? snapshot : {};
|
|
7427
|
+
if (body.summary && typeof body.summary === "object") {
|
|
7364
7428
|
console.log("Summary:");
|
|
7365
|
-
deps.printJson(summary);
|
|
7429
|
+
deps.printJson(body.summary);
|
|
7366
7430
|
}
|
|
7367
|
-
const items = Array.isArray(body.items) ? body.items : [];
|
|
7368
7431
|
console.log("Entries:");
|
|
7369
|
-
printTokenEntriesTable(items);
|
|
7432
|
+
printTokenEntriesTable(Array.isArray(body.items) ? body.items : []);
|
|
7370
7433
|
};
|
|
7371
7434
|
const handleTokenPointsOrReceive = async (argv, action) => {
|
|
7372
7435
|
const args = (0, import_minimist2.default)(argv, {
|
|
@@ -7378,45 +7441,30 @@ function createTokenSubcommands(deps) {
|
|
|
7378
7441
|
console.log(usage);
|
|
7379
7442
|
return;
|
|
7380
7443
|
}
|
|
7381
|
-
const
|
|
7382
|
-
const regionCode = deps.parseRegionOrFail(
|
|
7444
|
+
const regionArg = deps.getSingleString(args, "region");
|
|
7445
|
+
const regionCode = regionArg ? deps.parseRegionOrFail(regionArg) : void 0;
|
|
7383
7446
|
await deps.ensureTokenPoolReady();
|
|
7384
|
-
const
|
|
7385
|
-
const
|
|
7386
|
-
var _a;
|
|
7387
|
-
const entryRegion = (_a = session_pool_default.getTokenEntry(token)) == null ? void 0 : _a.region;
|
|
7388
|
-
const finalRegion = regionCode || entryRegion;
|
|
7389
|
-
if (!finalRegion) {
|
|
7390
|
-
deps.fail(`Missing region for token ${maskToken(token)}. Provide --region or register token region in token-pool.`);
|
|
7391
|
-
}
|
|
7392
|
-
return { token, region: finalRegion };
|
|
7393
|
-
}) : session_pool_default.getEntries(false).filter((item) => item.enabled && item.live !== false && item.region).filter((item) => regionCode ? item.region === regionCode : true).map((item) => ({ token: item.token, region: item.region }));
|
|
7394
|
-
if (resolvedTokens.length === 0) {
|
|
7395
|
-
deps.fail("No token available. Provide --token or configure token-pool.");
|
|
7396
|
-
}
|
|
7447
|
+
const explicitTokens = await collectTokensFromArgs(args, usage, deps, false);
|
|
7448
|
+
const pairs = resolveTokenRegionPairs(explicitTokens, regionCode, deps);
|
|
7397
7449
|
const payload = action === "points" ? await Promise.all(
|
|
7398
|
-
|
|
7399
|
-
token
|
|
7400
|
-
points: await getCredit(
|
|
7450
|
+
pairs.map(async ({ token, region }) => ({
|
|
7451
|
+
token,
|
|
7452
|
+
points: await getCredit(token, buildRegionInfo(region))
|
|
7401
7453
|
}))
|
|
7402
7454
|
) : await Promise.all(
|
|
7403
|
-
|
|
7404
|
-
const
|
|
7455
|
+
pairs.map(async ({ token, region }) => {
|
|
7456
|
+
const regionInfo = buildRegionInfo(region);
|
|
7457
|
+
const currentCredit = await getCredit(token, regionInfo);
|
|
7405
7458
|
if (currentCredit.totalCredit <= 0) {
|
|
7406
7459
|
try {
|
|
7407
|
-
await receiveCredit(
|
|
7408
|
-
const updatedCredit = await getCredit(
|
|
7409
|
-
return { token
|
|
7460
|
+
await receiveCredit(token, regionInfo);
|
|
7461
|
+
const updatedCredit = await getCredit(token, regionInfo);
|
|
7462
|
+
return { token, credits: updatedCredit, received: true };
|
|
7410
7463
|
} catch (error) {
|
|
7411
|
-
return {
|
|
7412
|
-
token: item.token,
|
|
7413
|
-
credits: currentCredit,
|
|
7414
|
-
received: false,
|
|
7415
|
-
error: (error == null ? void 0 : error.message) || String(error)
|
|
7416
|
-
};
|
|
7464
|
+
return { token, credits: currentCredit, received: false, error: (error == null ? void 0 : error.message) || String(error) };
|
|
7417
7465
|
}
|
|
7418
7466
|
}
|
|
7419
|
-
return { token
|
|
7467
|
+
return { token, credits: currentCredit, received: false };
|
|
7420
7468
|
})
|
|
7421
7469
|
);
|
|
7422
7470
|
if (args.json) {
|
|
@@ -7435,28 +7483,32 @@ function createTokenSubcommands(deps) {
|
|
|
7435
7483
|
console.log(usage);
|
|
7436
7484
|
return;
|
|
7437
7485
|
}
|
|
7438
|
-
const region = deps.getRegionWithDefault(args);
|
|
7439
7486
|
await deps.ensureTokenPoolReady();
|
|
7440
7487
|
const tokens = await collectTokensFromArgs(args, usage, deps, true);
|
|
7441
|
-
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7488
|
+
let payload;
|
|
7489
|
+
let jsonMeta;
|
|
7490
|
+
if (action === "add") {
|
|
7491
|
+
const region = deps.getRegionWithDefault(args);
|
|
7492
|
+
const regionCode = deps.parseRegionOrFail(region);
|
|
7493
|
+
payload = {
|
|
7494
|
+
...await session_pool_default.addTokens(tokens, { defaultRegion: regionCode || void 0 }),
|
|
7495
|
+
summary: session_pool_default.getSummary()
|
|
7496
|
+
};
|
|
7497
|
+
jsonMeta = { region };
|
|
7498
|
+
} else {
|
|
7499
|
+
payload = {
|
|
7500
|
+
...await session_pool_default.removeTokens(tokens),
|
|
7501
|
+
summary: session_pool_default.getSummary()
|
|
7502
|
+
};
|
|
7503
|
+
}
|
|
7449
7504
|
if (args.json) {
|
|
7450
|
-
deps.printCommandJson(`token.${action}`, deps.unwrapBody(payload),
|
|
7505
|
+
deps.printCommandJson(`token.${action}`, deps.unwrapBody(payload), jsonMeta);
|
|
7451
7506
|
return;
|
|
7452
7507
|
}
|
|
7453
7508
|
deps.printJson(deps.unwrapBody(payload));
|
|
7454
7509
|
};
|
|
7455
7510
|
const handleTokenEnableOrDisable = async (argv, action) => {
|
|
7456
|
-
const args = (0, import_minimist2.default)(argv, {
|
|
7457
|
-
string: ["token"],
|
|
7458
|
-
boolean: ["help", "json"]
|
|
7459
|
-
});
|
|
7511
|
+
const args = (0, import_minimist2.default)(argv, { string: ["token"], boolean: ["help", "json"] });
|
|
7460
7512
|
const usage = deps.getUsage(action);
|
|
7461
7513
|
if (args.help) {
|
|
7462
7514
|
console.log(usage);
|
|
@@ -7478,44 +7530,34 @@ function createTokenSubcommands(deps) {
|
|
|
7478
7530
|
deps.printJson(deps.unwrapBody(payload));
|
|
7479
7531
|
};
|
|
7480
7532
|
const handleTokenPool = async (argv) => {
|
|
7481
|
-
const args = (0, import_minimist2.default)(argv, {
|
|
7482
|
-
boolean: ["help", "json"]
|
|
7483
|
-
});
|
|
7484
|
-
const usage = deps.getUsage("pool");
|
|
7533
|
+
const args = (0, import_minimist2.default)(argv, { boolean: ["help", "json"] });
|
|
7485
7534
|
if (args.help) {
|
|
7486
|
-
console.log(
|
|
7535
|
+
console.log(deps.getUsage("pool"));
|
|
7487
7536
|
return;
|
|
7488
7537
|
}
|
|
7489
7538
|
await deps.ensureTokenPoolReady();
|
|
7490
|
-
const
|
|
7539
|
+
const snapshot = buildTokenPoolSnapshot();
|
|
7491
7540
|
if (args.json) {
|
|
7492
|
-
deps.printCommandJson("token.pool",
|
|
7541
|
+
deps.printCommandJson("token.pool", snapshot);
|
|
7493
7542
|
return;
|
|
7494
7543
|
}
|
|
7495
|
-
const body =
|
|
7544
|
+
const body = snapshot && typeof snapshot === "object" ? snapshot : {};
|
|
7496
7545
|
console.log("Summary:");
|
|
7497
7546
|
deps.printJson(body.summary ?? {});
|
|
7498
7547
|
console.log("Entries:");
|
|
7499
7548
|
printTokenEntriesTable(Array.isArray(body.items) ? body.items : []);
|
|
7500
7549
|
};
|
|
7501
7550
|
const handleTokenPoolCheckOrReload = async (argv, action) => {
|
|
7502
|
-
const args = (0, import_minimist2.default)(argv, {
|
|
7503
|
-
boolean: ["help", "json"]
|
|
7504
|
-
});
|
|
7505
|
-
const usage = deps.getUsage(action);
|
|
7551
|
+
const args = (0, import_minimist2.default)(argv, { boolean: ["help", "json"] });
|
|
7506
7552
|
if (args.help) {
|
|
7507
|
-
console.log(
|
|
7553
|
+
console.log(deps.getUsage(action));
|
|
7508
7554
|
return;
|
|
7509
7555
|
}
|
|
7510
7556
|
await deps.ensureTokenPoolReady();
|
|
7511
|
-
const payload = action === "pool-check" ? {
|
|
7512
|
-
|
|
7513
|
-
summary: session_pool_default.getSummary()
|
|
7514
|
-
}
|
|
7515
|
-
reloaded: true,
|
|
7516
|
-
summary: session_pool_default.getSummary(),
|
|
7517
|
-
items: buildTokenPoolSnapshot().items
|
|
7518
|
-
});
|
|
7557
|
+
const payload = action === "pool-check" ? { ...await session_pool_default.runHealthCheck(), summary: session_pool_default.getSummary() } : (() => {
|
|
7558
|
+
session_pool_default.reloadFromDisk();
|
|
7559
|
+
return { reloaded: true, summary: session_pool_default.getSummary(), items: buildTokenPoolSnapshot().items };
|
|
7560
|
+
})();
|
|
7519
7561
|
if (args.json) {
|
|
7520
7562
|
deps.printCommandJson(`token.${action}`, deps.unwrapBody(payload));
|
|
7521
7563
|
return;
|
|
@@ -7532,12 +7574,12 @@ function createTokenSubcommands(deps) {
|
|
|
7532
7574
|
},
|
|
7533
7575
|
{
|
|
7534
7576
|
name: "check",
|
|
7535
|
-
description: "Validate tokens
|
|
7536
|
-
usageLine: " jimeng token check
|
|
7577
|
+
description: "Validate tokens",
|
|
7578
|
+
usageLine: " jimeng token check [options]",
|
|
7537
7579
|
options: [
|
|
7538
|
-
" --token <token> Token, can be repeated",
|
|
7580
|
+
" --token <token> Token, can be repeated (default: all enabled tokens)",
|
|
7539
7581
|
" --token-file <path> Read tokens from file (one per line, # for comments)",
|
|
7540
|
-
" --region <region>
|
|
7582
|
+
" --region <region> Override region (default: token's registered region)",
|
|
7541
7583
|
deps.jsonOption,
|
|
7542
7584
|
deps.helpOption
|
|
7543
7585
|
],
|
|
@@ -7545,12 +7587,12 @@ function createTokenSubcommands(deps) {
|
|
|
7545
7587
|
},
|
|
7546
7588
|
{
|
|
7547
7589
|
name: "points",
|
|
7548
|
-
description: "Query token points
|
|
7590
|
+
description: "Query token points",
|
|
7549
7591
|
usageLine: " jimeng token points [options]",
|
|
7550
7592
|
options: [
|
|
7551
7593
|
" --token <token> Token, can be repeated",
|
|
7552
7594
|
" --token-file <path> Read tokens from file (one per line, # for comments)",
|
|
7553
|
-
" --region <region> Filter tokens by
|
|
7595
|
+
" --region <region> Filter tokens by region (cn/us/hk/jp/sg)",
|
|
7554
7596
|
deps.jsonOption,
|
|
7555
7597
|
deps.helpOption
|
|
7556
7598
|
],
|
|
@@ -7558,12 +7600,12 @@ function createTokenSubcommands(deps) {
|
|
|
7558
7600
|
},
|
|
7559
7601
|
{
|
|
7560
7602
|
name: "receive",
|
|
7561
|
-
description: "Receive token credits
|
|
7603
|
+
description: "Receive token credits",
|
|
7562
7604
|
usageLine: " jimeng token receive [options]",
|
|
7563
7605
|
options: [
|
|
7564
7606
|
" --token <token> Token, can be repeated",
|
|
7565
7607
|
" --token-file <path> Read tokens from file (one per line, # for comments)",
|
|
7566
|
-
" --region <region> Filter tokens by
|
|
7608
|
+
" --region <region> Filter tokens by region (cn/us/hk/jp/sg)",
|
|
7567
7609
|
deps.jsonOption,
|
|
7568
7610
|
deps.helpOption
|
|
7569
7611
|
],
|
|
@@ -7851,7 +7893,7 @@ var SmartPoller = class {
|
|
|
7851
7893
|
/**
|
|
7852
7894
|
* 根据状态码计算智能轮询间隔
|
|
7853
7895
|
*/
|
|
7854
|
-
getSmartInterval(status,
|
|
7896
|
+
getSmartInterval(status, _itemCount) {
|
|
7855
7897
|
const baseInterval = this.options.pollInterval;
|
|
7856
7898
|
switch (status) {
|
|
7857
7899
|
case 20:
|
|
@@ -7888,9 +7930,6 @@ var SmartPoller = class {
|
|
|
7888
7930
|
if (status === 30) {
|
|
7889
7931
|
return { shouldExit: true, reason: "\u4EFB\u52A1\u5931\u8D25" };
|
|
7890
7932
|
}
|
|
7891
|
-
if (itemCount >= this.options.expectedItemCount && (status === 10 || status === 50)) {
|
|
7892
|
-
return { shouldExit: true, reason: `\u5DF2\u83B7\u5F97\u5B8C\u6574\u7ED3\u679C\u96C6(${itemCount}/${this.options.expectedItemCount})` };
|
|
7893
|
-
}
|
|
7894
7933
|
if (this.pollCount >= this.options.maxPollCount) {
|
|
7895
7934
|
return { shouldExit: true, reason: "\u8F6E\u8BE2\u6B21\u6570\u8D85\u9650" };
|
|
7896
7935
|
}
|
|
@@ -7907,6 +7946,7 @@ var SmartPoller = class {
|
|
|
7907
7946
|
logger_default.info(`\u5F00\u59CB\u667A\u80FD\u8F6E\u8BE2: historyId=${historyId || "N/A"}, \u6700\u5927\u8F6E\u8BE2\u6B21\u6570=${this.options.maxPollCount}, \u671F\u671B\u7ED3\u679C\u6570=${this.options.expectedItemCount}`);
|
|
7908
7947
|
let lastData;
|
|
7909
7948
|
let lastStatus = { status: 20, itemCount: 0 };
|
|
7949
|
+
let exitReason = "";
|
|
7910
7950
|
while (true) {
|
|
7911
7951
|
this.pollCount++;
|
|
7912
7952
|
const elapsedTime = Math.round((Date.now() - this.startTime) / 1e3);
|
|
@@ -7920,6 +7960,7 @@ var SmartPoller = class {
|
|
|
7920
7960
|
}
|
|
7921
7961
|
const { shouldExit, reason } = this.shouldExitPolling(status);
|
|
7922
7962
|
if (shouldExit) {
|
|
7963
|
+
exitReason = reason;
|
|
7923
7964
|
logger_default.info(`\u9000\u51FA\u8F6E\u8BE2: ${reason}, \u6700\u7EC8${this.options.type === "image" ? "\u56FE\u7247" : "\u89C6\u9891"}\u6570\u91CF=${status.itemCount}`);
|
|
7924
7965
|
if (status.status === 30) {
|
|
7925
7966
|
handleGenerationFailure(status.status, status.failCode, historyId, this.options.type, status.itemCount);
|
|
@@ -7931,7 +7972,8 @@ var SmartPoller = class {
|
|
|
7931
7972
|
elapsedTime,
|
|
7932
7973
|
status.status,
|
|
7933
7974
|
status.itemCount,
|
|
7934
|
-
historyId
|
|
7975
|
+
historyId,
|
|
7976
|
+
this.options.type
|
|
7935
7977
|
);
|
|
7936
7978
|
}
|
|
7937
7979
|
break;
|
|
@@ -7975,7 +8017,7 @@ var SmartPoller = class {
|
|
|
7975
8017
|
itemCount: lastStatus.itemCount,
|
|
7976
8018
|
elapsedTime: finalElapsedTime,
|
|
7977
8019
|
pollCount: this.pollCount,
|
|
7978
|
-
exitReason
|
|
8020
|
+
exitReason
|
|
7979
8021
|
};
|
|
7980
8022
|
logger_default.info(`${this.options.type === "image" ? "\u56FE\u50CF" : "\u89C6\u9891"}\u751F\u6210\u5B8C\u6210: \u6210\u529F\u751F\u6210 ${lastStatus.itemCount} \u4E2A\u7ED3\u679C\uFF0C\u603B\u8017\u65F6 ${finalElapsedTime} \u79D2\uFF0C\u6700\u7EC8\u72B6\u6001: ${this.getStatusName(lastStatus.status)}`);
|
|
7981
8023
|
return { result, data: lastData };
|
|
@@ -8021,17 +8063,20 @@ function extractImageUrls(itemList) {
|
|
|
8021
8063
|
return itemList.map((item, index) => extractImageUrl(item, index)).filter((url) => url !== null);
|
|
8022
8064
|
}
|
|
8023
8065
|
function extractVideoUrl(item) {
|
|
8024
|
-
var _a, _b, _c, _d, _e, _f;
|
|
8025
|
-
if ((_c = (_b = (_a = item == null ? void 0 : item.
|
|
8066
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
8067
|
+
if ((_c = (_b = (_a = item == null ? void 0 : item.common_attr) == null ? void 0 : _a.transcoded_video) == null ? void 0 : _b.origin) == null ? void 0 : _c.video_url) {
|
|
8068
|
+
return item.common_attr.transcoded_video.origin.video_url;
|
|
8069
|
+
}
|
|
8070
|
+
if ((_f = (_e = (_d = item == null ? void 0 : item.video) == null ? void 0 : _d.transcoded_video) == null ? void 0 : _e.origin) == null ? void 0 : _f.video_url) {
|
|
8026
8071
|
return item.video.transcoded_video.origin.video_url;
|
|
8027
8072
|
}
|
|
8028
|
-
if ((
|
|
8073
|
+
if ((_g = item == null ? void 0 : item.video) == null ? void 0 : _g.play_url) {
|
|
8029
8074
|
return item.video.play_url;
|
|
8030
8075
|
}
|
|
8031
|
-
if ((
|
|
8076
|
+
if ((_h = item == null ? void 0 : item.video) == null ? void 0 : _h.download_url) {
|
|
8032
8077
|
return item.video.download_url;
|
|
8033
8078
|
}
|
|
8034
|
-
if ((
|
|
8079
|
+
if ((_i = item == null ? void 0 : item.video) == null ? void 0 : _i.url) {
|
|
8035
8080
|
return item.video.url;
|
|
8036
8081
|
}
|
|
8037
8082
|
return null;
|
|
@@ -8061,20 +8106,15 @@ async function fetchHighQualityVideoUrl(itemId, refreshToken, regionInfo) {
|
|
|
8061
8106
|
return videoUrl;
|
|
8062
8107
|
}
|
|
8063
8108
|
}
|
|
8064
|
-
const
|
|
8065
|
-
if (
|
|
8066
|
-
logger_default.info(`\u6B63\u5219\u63D0\u53D6\u5230\
|
|
8067
|
-
return
|
|
8068
|
-
}
|
|
8069
|
-
const jimengUrlMatch = responseStr.match(/https:\/\/v[0-9]+-[^"\\]*\.jimeng\.com\/[^"\s\\]+/);
|
|
8070
|
-
if (jimengUrlMatch && jimengUrlMatch[0]) {
|
|
8071
|
-
logger_default.info(`\u6B63\u5219\u63D0\u53D6\u5230jimeng\u89C6\u9891URL: ${jimengUrlMatch[0]}`);
|
|
8072
|
-
return jimengUrlMatch[0];
|
|
8109
|
+
const cdnUrlMatch = responseStr.match(/https:\/\/v[0-9]+-[^"\\]*\.(jimeng|capcut|dreamina)\.com\/[^"\s\\]+/);
|
|
8110
|
+
if (cdnUrlMatch && cdnUrlMatch[0]) {
|
|
8111
|
+
logger_default.info(`\u6B63\u5219\u63D0\u53D6\u5230\u89C6\u9891URL: ${cdnUrlMatch[0]}`);
|
|
8112
|
+
return cdnUrlMatch[0];
|
|
8073
8113
|
}
|
|
8074
|
-
const
|
|
8075
|
-
if (
|
|
8076
|
-
logger_default.info(`\
|
|
8077
|
-
return
|
|
8114
|
+
const vlabUrlMatch = responseStr.match(/https:\/\/v[0-9]+-[^"\\]*\.vlabvod\.com\/[^"\s\\]+/);
|
|
8115
|
+
if (vlabUrlMatch && vlabUrlMatch[0]) {
|
|
8116
|
+
logger_default.info(`\u6B63\u5219\u63D0\u53D6\u5230\u89C6\u9891URL: ${vlabUrlMatch[0]}`);
|
|
8117
|
+
return vlabUrlMatch[0];
|
|
8078
8118
|
}
|
|
8079
8119
|
logger_default.warn(`\u672A\u80FD\u4ECEget_local_item_list\u54CD\u5E94\u4E2D\u63D0\u53D6\u5230\u89C6\u9891URL`);
|
|
8080
8120
|
return null;
|
|
@@ -8327,11 +8367,62 @@ function printTaskInfo(task, deps) {
|
|
|
8327
8367
|
deps.printJson(task.data);
|
|
8328
8368
|
}
|
|
8329
8369
|
}
|
|
8370
|
+
function outputTaskResult(command, normalized, isJson, deps) {
|
|
8371
|
+
const taskInfo = collectTaskInfo(normalized, deps);
|
|
8372
|
+
if (!taskInfo) {
|
|
8373
|
+
const body = deps.unwrapBody(normalized);
|
|
8374
|
+
if (isJson) deps.printCommandJson(command, body);
|
|
8375
|
+
else deps.printJson(body);
|
|
8376
|
+
return;
|
|
8377
|
+
}
|
|
8378
|
+
if (isJson) deps.printCommandJson(command, taskInfo);
|
|
8379
|
+
else printTaskInfo(taskInfo, deps);
|
|
8380
|
+
}
|
|
8381
|
+
function resolveSingleQueryToken(explicitToken, explicitRegion, deps) {
|
|
8382
|
+
var _a;
|
|
8383
|
+
const regionCode = explicitRegion ? deps.parseRegionOrFail(explicitRegion) : void 0;
|
|
8384
|
+
if (explicitToken) {
|
|
8385
|
+
const poolRegion = (_a = session_pool_default.getTokenEntry(explicitToken)) == null ? void 0 : _a.region;
|
|
8386
|
+
const region = regionCode || poolRegion;
|
|
8387
|
+
if (!region) {
|
|
8388
|
+
deps.fail("Missing region for token. Provide --region or register token in token-pool.");
|
|
8389
|
+
}
|
|
8390
|
+
return { token: explicitToken, region };
|
|
8391
|
+
}
|
|
8392
|
+
if (!regionCode) {
|
|
8393
|
+
const entry = session_pool_default.getEntries(false).find(
|
|
8394
|
+
(item) => item.enabled && item.live !== false && item.region
|
|
8395
|
+
);
|
|
8396
|
+
if (!entry) {
|
|
8397
|
+
deps.fail("No token available. Provide --token, --region, or --all.");
|
|
8398
|
+
}
|
|
8399
|
+
return { token: entry.token, region: entry.region };
|
|
8400
|
+
}
|
|
8401
|
+
return { token: void 0, region: regionCode };
|
|
8402
|
+
}
|
|
8403
|
+
function printModelIds(models) {
|
|
8404
|
+
for (const item of models) {
|
|
8405
|
+
if (!item || typeof item !== "object") continue;
|
|
8406
|
+
const id = item.id;
|
|
8407
|
+
if (typeof id === "string" && id.length > 0) console.log(id);
|
|
8408
|
+
}
|
|
8409
|
+
}
|
|
8410
|
+
function printModelVerbose(models) {
|
|
8411
|
+
console.log("id type desc capabilities");
|
|
8412
|
+
for (const item of models) {
|
|
8413
|
+
if (!item || typeof item !== "object") continue;
|
|
8414
|
+
const m = item;
|
|
8415
|
+
const id = typeof m.id === "string" ? m.id : "";
|
|
8416
|
+
if (!id) continue;
|
|
8417
|
+
const type = typeof m.model_type === "string" ? m.model_type : "-";
|
|
8418
|
+
const desc = typeof m.description === "string" ? m.description : "-";
|
|
8419
|
+
const caps = Array.isArray(m.capabilities) ? m.capabilities.filter((c) => typeof c === "string").join(",") : "-";
|
|
8420
|
+
console.log(`${id} type=${type} desc=${desc} capabilities=${caps}`);
|
|
8421
|
+
}
|
|
8422
|
+
}
|
|
8330
8423
|
function createQueryCommandHandlers(deps) {
|
|
8331
8424
|
const handleModelsRefresh = async (argv) => {
|
|
8332
|
-
const args = (0, import_minimist3.default)(argv, {
|
|
8333
|
-
boolean: ["help", "json"]
|
|
8334
|
-
});
|
|
8425
|
+
const args = (0, import_minimist3.default)(argv, { boolean: ["help", "json"] });
|
|
8335
8426
|
if (args.help) {
|
|
8336
8427
|
console.log(deps.usageModelsRefresh());
|
|
8337
8428
|
return;
|
|
@@ -8359,48 +8450,68 @@ function createQueryCommandHandlers(deps) {
|
|
|
8359
8450
|
const handleModelsList = async (argv) => {
|
|
8360
8451
|
const args = (0, import_minimist3.default)(argv, {
|
|
8361
8452
|
string: ["region", "token"],
|
|
8362
|
-
boolean: ["help", "json", "verbose"]
|
|
8453
|
+
boolean: ["help", "json", "verbose", "all"]
|
|
8363
8454
|
});
|
|
8364
8455
|
if (args.help) {
|
|
8365
8456
|
console.log(deps.usageModelsList());
|
|
8366
8457
|
return;
|
|
8367
8458
|
}
|
|
8368
|
-
const
|
|
8369
|
-
const
|
|
8370
|
-
const
|
|
8459
|
+
const isJson = Boolean(args.json);
|
|
8460
|
+
const isVerbose = Boolean(args.verbose);
|
|
8461
|
+
const explicitRegion = deps.getSingleString(args, "region");
|
|
8462
|
+
const explicitToken = deps.getSingleString(args, "token");
|
|
8371
8463
|
await deps.ensureTokenPoolReady();
|
|
8372
|
-
|
|
8373
|
-
|
|
8374
|
-
|
|
8375
|
-
|
|
8376
|
-
|
|
8464
|
+
if (args.all) {
|
|
8465
|
+
const entries = session_pool_default.getEntries(false).filter(
|
|
8466
|
+
(item) => item.enabled && item.live !== false && item.region
|
|
8467
|
+
);
|
|
8468
|
+
if (entries.length === 0) {
|
|
8469
|
+
deps.fail("No enabled+live tokens with region found in pool.");
|
|
8470
|
+
}
|
|
8471
|
+
const results = [];
|
|
8472
|
+
for (const entry of entries) {
|
|
8473
|
+
const masked = entry.token.length <= 10 ? "***" : `${entry.token.slice(0, 4)}...${entry.token.slice(-4)}`;
|
|
8474
|
+
try {
|
|
8475
|
+
const direct2 = await getLiveModels(`Bearer ${entry.token}`, entry.region);
|
|
8476
|
+
results.push({
|
|
8477
|
+
token: masked,
|
|
8478
|
+
region: entry.region,
|
|
8479
|
+
models: direct2.data.map((m) => m.id)
|
|
8480
|
+
});
|
|
8481
|
+
} catch (error) {
|
|
8482
|
+
results.push({ token: masked, region: entry.region, error: error.message });
|
|
8483
|
+
}
|
|
8484
|
+
}
|
|
8485
|
+
if (isJson) {
|
|
8486
|
+
deps.printCommandJson("models.list", results);
|
|
8487
|
+
return;
|
|
8488
|
+
}
|
|
8489
|
+
for (const r of results) {
|
|
8490
|
+
console.log(`[${r.region}] ${r.token}`);
|
|
8491
|
+
if (r.error) {
|
|
8492
|
+
console.log(` error: ${r.error}`);
|
|
8493
|
+
} else {
|
|
8494
|
+
for (const id of r.models) console.log(` ${id}`);
|
|
8495
|
+
}
|
|
8496
|
+
console.log("");
|
|
8497
|
+
}
|
|
8377
8498
|
return;
|
|
8378
8499
|
}
|
|
8379
|
-
const
|
|
8380
|
-
|
|
8381
|
-
|
|
8382
|
-
|
|
8383
|
-
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
const model = item;
|
|
8388
|
-
const id = typeof model.id === "string" ? model.id : "";
|
|
8389
|
-
if (!id) continue;
|
|
8390
|
-
const modelType = typeof model.model_type === "string" ? model.model_type : "-";
|
|
8391
|
-
const description = typeof model.description === "string" ? model.description : "-";
|
|
8392
|
-
const capabilities = Array.isArray(model.capabilities) ? model.capabilities.filter((cap) => typeof cap === "string").join(",") : "-";
|
|
8393
|
-
console.log(`${id} type=${modelType} desc=${description} capabilities=${capabilities}`);
|
|
8394
|
-
}
|
|
8500
|
+
const { token, region } = resolveSingleQueryToken(explicitToken, explicitRegion, deps);
|
|
8501
|
+
const direct = await getLiveModels(token ? `Bearer ${token}` : void 0, region);
|
|
8502
|
+
const models = direct.data;
|
|
8503
|
+
if (isJson) {
|
|
8504
|
+
deps.printCommandJson("models.list", { object: "list", data: models }, {
|
|
8505
|
+
region: region || null,
|
|
8506
|
+
token: token ? `${token.slice(0, 4)}...` : null
|
|
8507
|
+
});
|
|
8395
8508
|
return;
|
|
8396
8509
|
}
|
|
8397
|
-
|
|
8398
|
-
|
|
8399
|
-
const id = item.id;
|
|
8400
|
-
if (typeof id === "string" && id.length > 0) {
|
|
8401
|
-
console.log(id);
|
|
8402
|
-
}
|
|
8510
|
+
if (models.length === 0) {
|
|
8511
|
+
deps.fail("No models found.");
|
|
8403
8512
|
}
|
|
8513
|
+
if (isVerbose) printModelVerbose(models);
|
|
8514
|
+
else printModelIds(models);
|
|
8404
8515
|
};
|
|
8405
8516
|
const handleTaskGet = async (argv) => {
|
|
8406
8517
|
const args = (0, import_minimist3.default)(argv, {
|
|
@@ -8417,42 +8528,13 @@ function createQueryCommandHandlers(deps) {
|
|
|
8417
8528
|
${deps.usageTaskGet()}`);
|
|
8418
8529
|
const type = parseTaskTypeOrFail(deps.getSingleString(args, "type"), deps);
|
|
8419
8530
|
const responseFormat = parseResponseFormatOrFail(deps.getSingleString(args, "response-format"), deps);
|
|
8420
|
-
const
|
|
8421
|
-
const
|
|
8422
|
-
|
|
8423
|
-
const pick = await deps.pickDirectTokenForTask(token, region);
|
|
8424
|
-
const normalized = await getTaskResponse(
|
|
8425
|
-
taskId,
|
|
8426
|
-
pick.token,
|
|
8427
|
-
buildRegionInfo(pick.region),
|
|
8428
|
-
{
|
|
8429
|
-
type,
|
|
8430
|
-
responseFormat
|
|
8431
|
-
}
|
|
8432
|
-
);
|
|
8433
|
-
const taskInfo = collectTaskInfo(normalized, deps);
|
|
8434
|
-
if (!taskInfo) {
|
|
8435
|
-
if (isJson) {
|
|
8436
|
-
deps.printCommandJson("task.get", deps.unwrapBody(normalized));
|
|
8437
|
-
} else {
|
|
8438
|
-
deps.printJson(deps.unwrapBody(normalized));
|
|
8439
|
-
}
|
|
8440
|
-
return;
|
|
8441
|
-
}
|
|
8442
|
-
if (isJson) deps.printCommandJson("task.get", taskInfo);
|
|
8443
|
-
else printTaskInfo(taskInfo, deps);
|
|
8531
|
+
const pick = await deps.pickDirectTokenForTask(deps.getSingleString(args, "token"), deps.getSingleString(args, "region"));
|
|
8532
|
+
const normalized = await getTaskResponse(taskId, pick.token, buildRegionInfo(pick.region), { type, responseFormat });
|
|
8533
|
+
outputTaskResult("task.get", normalized, Boolean(args.json), deps);
|
|
8444
8534
|
};
|
|
8445
8535
|
const handleTaskWait = async (argv) => {
|
|
8446
8536
|
const args = (0, import_minimist3.default)(argv, {
|
|
8447
|
-
string: [
|
|
8448
|
-
"token",
|
|
8449
|
-
"region",
|
|
8450
|
-
"task-id",
|
|
8451
|
-
"type",
|
|
8452
|
-
"response-format",
|
|
8453
|
-
"wait-timeout-seconds",
|
|
8454
|
-
"poll-interval-ms"
|
|
8455
|
-
],
|
|
8537
|
+
string: ["token", "region", "task-id", "type", "response-format", "wait-timeout-seconds", "poll-interval-ms"],
|
|
8456
8538
|
boolean: ["help", "json"]
|
|
8457
8539
|
});
|
|
8458
8540
|
if (args.help) {
|
|
@@ -8463,41 +8545,18 @@ ${deps.usageTaskGet()}`);
|
|
|
8463
8545
|
if (!taskId) deps.fail(`Missing required --task-id.
|
|
8464
8546
|
|
|
8465
8547
|
${deps.usageTaskWait()}`);
|
|
8466
|
-
const token = deps.getSingleString(args, "token");
|
|
8467
|
-
const region = deps.getRegionWithDefault(args);
|
|
8468
|
-
const isJson = Boolean(args.json);
|
|
8469
|
-
const body = {};
|
|
8470
8548
|
const type = parseTaskTypeOrFail(deps.getSingleString(args, "type"), deps);
|
|
8471
8549
|
const responseFormat = parseResponseFormatOrFail(deps.getSingleString(args, "response-format"), deps);
|
|
8472
|
-
if (type) body.type = type;
|
|
8473
|
-
body.response_format = responseFormat;
|
|
8474
8550
|
const waitTimeoutSeconds = parsePositiveNumberOption(args, "wait-timeout-seconds", deps);
|
|
8475
|
-
if (waitTimeoutSeconds !== void 0) body.wait_timeout_seconds = waitTimeoutSeconds;
|
|
8476
8551
|
const pollIntervalMs = parsePositiveNumberOption(args, "poll-interval-ms", deps);
|
|
8477
|
-
|
|
8478
|
-
const
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
|
|
8482
|
-
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
responseFormat,
|
|
8486
|
-
waitTimeoutSeconds: typeof body.wait_timeout_seconds === "number" ? body.wait_timeout_seconds : void 0,
|
|
8487
|
-
pollIntervalMs: typeof body.poll_interval_ms === "number" ? body.poll_interval_ms : void 0
|
|
8488
|
-
}
|
|
8489
|
-
);
|
|
8490
|
-
const taskInfo = collectTaskInfo(normalized, deps);
|
|
8491
|
-
if (!taskInfo) {
|
|
8492
|
-
if (isJson) {
|
|
8493
|
-
deps.printCommandJson("task.wait", deps.unwrapBody(normalized));
|
|
8494
|
-
} else {
|
|
8495
|
-
deps.printJson(deps.unwrapBody(normalized));
|
|
8496
|
-
}
|
|
8497
|
-
return;
|
|
8498
|
-
}
|
|
8499
|
-
if (isJson) deps.printCommandJson("task.wait", taskInfo);
|
|
8500
|
-
else printTaskInfo(taskInfo, deps);
|
|
8552
|
+
const pick = await deps.pickDirectTokenForTask(deps.getSingleString(args, "token"), deps.getSingleString(args, "region"));
|
|
8553
|
+
const normalized = await waitForTaskResponse(taskId, pick.token, buildRegionInfo(pick.region), {
|
|
8554
|
+
type,
|
|
8555
|
+
responseFormat,
|
|
8556
|
+
waitTimeoutSeconds,
|
|
8557
|
+
pollIntervalMs
|
|
8558
|
+
});
|
|
8559
|
+
outputTaskResult("task.wait", normalized, Boolean(args.json), deps);
|
|
8501
8560
|
};
|
|
8502
8561
|
const handleTaskList = async (argv) => {
|
|
8503
8562
|
const args = (0, import_minimist3.default)(argv, {
|
|
@@ -8508,24 +8567,18 @@ ${deps.usageTaskWait()}`);
|
|
|
8508
8567
|
console.log(deps.usageTaskList());
|
|
8509
8568
|
return;
|
|
8510
8569
|
}
|
|
8511
|
-
const token = deps.getSingleString(args, "token");
|
|
8512
|
-
const region = deps.getRegionWithDefault(args);
|
|
8513
8570
|
const type = deps.getSingleString(args, "type");
|
|
8514
|
-
const countRaw = deps.getSingleString(args, "count");
|
|
8515
|
-
const count = countRaw ? Number(countRaw) : 20;
|
|
8516
|
-
const isJson = Boolean(args.json);
|
|
8517
8571
|
if (type && type !== "image" && type !== "video" && type !== "all") {
|
|
8518
8572
|
deps.fail(`Invalid --type: ${type}. Use image, video, or all.`);
|
|
8519
8573
|
}
|
|
8520
|
-
const
|
|
8521
|
-
const
|
|
8522
|
-
|
|
8523
|
-
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
);
|
|
8574
|
+
const countRaw = deps.getSingleString(args, "count");
|
|
8575
|
+
const count = countRaw ? Number(countRaw) : 20;
|
|
8576
|
+
const isJson = Boolean(args.json);
|
|
8577
|
+
const pick = await deps.pickDirectTokenForTask(deps.getSingleString(args, "token"), deps.getSingleString(args, "region"));
|
|
8578
|
+
const result = await getAssetList(pick.token, buildRegionInfo(pick.region), {
|
|
8579
|
+
count: Number.isFinite(count) && count > 0 ? count : 20,
|
|
8580
|
+
type
|
|
8581
|
+
});
|
|
8529
8582
|
if (isJson) {
|
|
8530
8583
|
deps.printCommandJson("task.list", {
|
|
8531
8584
|
has_more: result.hasMore,
|
|
@@ -8544,9 +8597,7 @@ ${deps.usageTaskWait()}`);
|
|
|
8544
8597
|
const modelShort = item.modelName || item.modelReqKey || "-";
|
|
8545
8598
|
const promptShort = item.prompt.length > 50 ? item.prompt.slice(0, 50) + "..." : item.prompt;
|
|
8546
8599
|
console.log(`${item.id} ${typeLabel} ${statusLabel.padEnd(4)} ${time} ${modelShort.padEnd(20)} ${promptShort}`);
|
|
8547
|
-
if (item.imageUrl) {
|
|
8548
|
-
console.log(` ${item.imageUrl}`);
|
|
8549
|
-
}
|
|
8600
|
+
if (item.imageUrl) console.log(` ${item.imageUrl}`);
|
|
8550
8601
|
}
|
|
8551
8602
|
};
|
|
8552
8603
|
return {
|
|
@@ -8556,12 +8607,12 @@ ${deps.usageTaskWait()}`);
|
|
|
8556
8607
|
handleTaskWait,
|
|
8557
8608
|
handleTaskList,
|
|
8558
8609
|
printTaskInfo: (task) => {
|
|
8559
|
-
const
|
|
8560
|
-
if (!
|
|
8610
|
+
const info = collectTaskInfo(task, deps);
|
|
8611
|
+
if (!info) {
|
|
8561
8612
|
deps.printJson(task);
|
|
8562
8613
|
return;
|
|
8563
8614
|
}
|
|
8564
|
-
printTaskInfo(
|
|
8615
|
+
printTaskInfo(info, deps);
|
|
8565
8616
|
}
|
|
8566
8617
|
};
|
|
8567
8618
|
}
|
|
@@ -8782,7 +8833,7 @@ async function uploadImageBuffer(imageBuffer, refreshToken, regionInfo) {
|
|
|
8782
8833
|
"Authorization": auth,
|
|
8783
8834
|
"Connection": "keep-alive",
|
|
8784
8835
|
"Content-CRC32": crc32,
|
|
8785
|
-
"Content-Disposition": 'attachment; filename="
|
|
8836
|
+
"Content-Disposition": 'attachment; filename="upload.bin"',
|
|
8786
8837
|
"Content-Type": "application/octet-stream",
|
|
8787
8838
|
"Origin": origin,
|
|
8788
8839
|
"Referer": RegionUtils.getRefererPath(regionInfo),
|
|
@@ -10730,7 +10781,8 @@ async function generateVideo(_model, prompt, {
|
|
|
10730
10781
|
isDefaultSeed: 1,
|
|
10731
10782
|
originSubmitId,
|
|
10732
10783
|
isRegenerate: false,
|
|
10733
|
-
enterFrom: "
|
|
10784
|
+
enterFrom: "use_bgimage_prompt",
|
|
10785
|
+
position: "page_bottom_box",
|
|
10734
10786
|
functionMode: flFunctionMode,
|
|
10735
10787
|
sceneOptions: JSON.stringify([sceneOption])
|
|
10736
10788
|
});
|
|
@@ -10855,7 +10907,7 @@ async function generateVideo(_model, prompt, {
|
|
|
10855
10907
|
timeoutSeconds: pollerOptions.timeoutSeconds
|
|
10856
10908
|
});
|
|
10857
10909
|
const { result: pollingResult, data: finalHistoryData } = await poller.poll(async () => {
|
|
10858
|
-
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2;
|
|
10910
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l, _m, _n, _o;
|
|
10859
10911
|
pollAttempts++;
|
|
10860
10912
|
const result = await request("post", "/mweb/v1/get_history_by_ids", refreshToken, regionInfo, {
|
|
10861
10913
|
data: {
|
|
@@ -10880,7 +10932,7 @@ async function generateVideo(_model, prompt, {
|
|
|
10880
10932
|
const currentItemList = historyData.item_list || [];
|
|
10881
10933
|
const finishTime = ((_a2 = historyData.task) == null ? void 0 : _a2.finish_time) || 0;
|
|
10882
10934
|
if (currentItemList.length > 0) {
|
|
10883
|
-
const tempVideoUrl = ((_e2 = (_d2 = (_c2 = (_b2 = currentItemList[0]) == null ? void 0 : _b2.
|
|
10935
|
+
const tempVideoUrl = ((_e2 = (_d2 = (_c2 = (_b2 = currentItemList[0]) == null ? void 0 : _b2.common_attr) == null ? void 0 : _c2.transcoded_video) == null ? void 0 : _d2.origin) == null ? void 0 : _e2.video_url) || ((_i2 = (_h2 = (_g2 = (_f2 = currentItemList[0]) == null ? void 0 : _f2.video) == null ? void 0 : _g2.transcoded_video) == null ? void 0 : _h2.origin) == null ? void 0 : _i2.video_url) || ((_k2 = (_j2 = currentItemList[0]) == null ? void 0 : _j2.video) == null ? void 0 : _k2.play_url) || ((_m = (_l = currentItemList[0]) == null ? void 0 : _l.video) == null ? void 0 : _m.download_url) || ((_o = (_n = currentItemList[0]) == null ? void 0 : _n.video) == null ? void 0 : _o.url);
|
|
10884
10936
|
if (tempVideoUrl) {
|
|
10885
10937
|
logger_default.info(`\u68C0\u6D4B\u5230\u89C6\u9891URL: ${tempVideoUrl}`);
|
|
10886
10938
|
}
|
|
@@ -11143,7 +11195,19 @@ function applyWaitOptionsToBody(body, args, deps, includeWaitFlag = true) {
|
|
|
11143
11195
|
return wait;
|
|
11144
11196
|
}
|
|
11145
11197
|
async function downloadBinary(url, deps) {
|
|
11146
|
-
const
|
|
11198
|
+
const controller = new AbortController();
|
|
11199
|
+
const timeout = setTimeout(() => controller.abort(), 12e4);
|
|
11200
|
+
let response;
|
|
11201
|
+
try {
|
|
11202
|
+
response = await fetch(url, { signal: controller.signal });
|
|
11203
|
+
} catch (err) {
|
|
11204
|
+
clearTimeout(timeout);
|
|
11205
|
+
if (err.name === "AbortError") {
|
|
11206
|
+
deps.fail(`Download timed out after 120s: ${url}`);
|
|
11207
|
+
}
|
|
11208
|
+
throw err;
|
|
11209
|
+
}
|
|
11210
|
+
clearTimeout(timeout);
|
|
11147
11211
|
if (!response.ok) {
|
|
11148
11212
|
deps.fail(`Download failed (${response.status}): ${url}`);
|
|
11149
11213
|
}
|
|
@@ -11212,6 +11276,9 @@ function createMediaCommandHandlers(deps) {
|
|
|
11212
11276
|
if (!Number.isFinite(parsed)) {
|
|
11213
11277
|
deps.fail(`Invalid --sample-strength: ${sampleStrengthRaw}`);
|
|
11214
11278
|
}
|
|
11279
|
+
if (parsed < 0 || parsed > 1) {
|
|
11280
|
+
deps.fail(`Invalid --sample-strength: ${sampleStrengthRaw} (must be between 0 and 1)`);
|
|
11281
|
+
}
|
|
11215
11282
|
body.sample_strength = parsed;
|
|
11216
11283
|
}
|
|
11217
11284
|
const pick = await deps.pickDirectTokenForGeneration(
|
|
@@ -11528,12 +11595,15 @@ var import_node_child_process = require("child_process");
|
|
|
11528
11595
|
var import_node_fs3 = require("fs");
|
|
11529
11596
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
11530
11597
|
var import_node_os = __toESM(require("os"), 1);
|
|
11531
|
-
var import_node_url = require("url");
|
|
11532
11598
|
var import_minimist5 = __toESM(require("minimist"), 1);
|
|
11533
11599
|
var import_meta = {};
|
|
11534
|
-
var
|
|
11535
|
-
|
|
11536
|
-
|
|
11600
|
+
var LOGIN_SCRIPT = import_node_path4.default.join(
|
|
11601
|
+
import_node_path4.default.dirname(new URL(import_meta.url).pathname),
|
|
11602
|
+
"..",
|
|
11603
|
+
"..",
|
|
11604
|
+
"scripts",
|
|
11605
|
+
"jimeng_login_helper.py"
|
|
11606
|
+
);
|
|
11537
11607
|
function createLoginCommandHandler(deps) {
|
|
11538
11608
|
return async (argv) => {
|
|
11539
11609
|
const args = (0, import_minimist5.default)(argv, {
|
|
@@ -11737,10 +11807,20 @@ function usageRoot() {
|
|
|
11737
11807
|
}
|
|
11738
11808
|
function usageModelsList() {
|
|
11739
11809
|
return buildUsageText(" jimeng models list [options]", [
|
|
11740
|
-
" --
|
|
11810
|
+
" --token <token> Query with specific token",
|
|
11811
|
+
" --region <region> Query with specific region (cn/us/hk/jp/sg)",
|
|
11812
|
+
" --all Query all tokens in pool, grouped by token/region",
|
|
11741
11813
|
" --verbose Print rich model fields",
|
|
11742
11814
|
" --json Print full JSON response",
|
|
11743
11815
|
HELP_OPTION
|
|
11816
|
+
], [
|
|
11817
|
+
{
|
|
11818
|
+
title: "Notes:",
|
|
11819
|
+
lines: [
|
|
11820
|
+
" Without --token, --region, or --all, uses the first available token in pool.",
|
|
11821
|
+
" With --all, queries every enabled+live token and groups results by token/region."
|
|
11822
|
+
]
|
|
11823
|
+
}
|
|
11744
11824
|
]);
|
|
11745
11825
|
}
|
|
11746
11826
|
function usageModelsRefresh() {
|
|
@@ -11900,7 +11980,7 @@ function usageVideoGenerate() {
|
|
|
11900
11980
|
function usageTaskGet() {
|
|
11901
11981
|
return buildUsageText(" jimeng task get --task-id <id> [options]", [
|
|
11902
11982
|
" --token <token> Optional, override token-pool selection",
|
|
11903
|
-
" --region <region>
|
|
11983
|
+
" --region <region> Filter token by region (cn/us/hk/jp/sg)",
|
|
11904
11984
|
" --task-id <id> Required history/task id",
|
|
11905
11985
|
" --type <type> Optional image or video",
|
|
11906
11986
|
" --response-format <fmt> Optional url or b64_json",
|
|
@@ -11911,7 +11991,7 @@ function usageTaskGet() {
|
|
|
11911
11991
|
function usageTaskWait() {
|
|
11912
11992
|
return buildUsageText(" jimeng task wait --task-id <id> [options]", [
|
|
11913
11993
|
" --token <token> Optional, override token-pool selection",
|
|
11914
|
-
" --region <region>
|
|
11994
|
+
" --region <region> Filter token by region (cn/us/hk/jp/sg)",
|
|
11915
11995
|
" --task-id <id> Required history/task id",
|
|
11916
11996
|
" --type <type> Optional image or video",
|
|
11917
11997
|
" --response-format <fmt> Optional url or b64_json",
|
|
@@ -11924,7 +12004,7 @@ function usageTaskWait() {
|
|
|
11924
12004
|
function usageTaskList() {
|
|
11925
12005
|
return buildUsageText(" jimeng task list [options]", [
|
|
11926
12006
|
" --token <token> Optional, override token-pool selection",
|
|
11927
|
-
" --region <region>
|
|
12007
|
+
" --region <region> Filter token by region (cn/us/hk/jp/sg)",
|
|
11928
12008
|
" --type <type> Filter by type: image, video, or all (default all)",
|
|
11929
12009
|
" --count <num> Number of items per page (default 20)",
|
|
11930
12010
|
JSON_OPTION,
|
|
@@ -12069,7 +12149,6 @@ var queryHandlers = createQueryCommandHandlers({
|
|
|
12069
12149
|
usageTaskWait,
|
|
12070
12150
|
usageTaskList,
|
|
12071
12151
|
getSingleString,
|
|
12072
|
-
getRegionWithDefault,
|
|
12073
12152
|
parseRegionOrFail,
|
|
12074
12153
|
ensureTokenPoolReady,
|
|
12075
12154
|
pickDirectTokenForTask,
|