jimeng-cli 0.3.1 → 0.3.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/README.md +1 -1
- package/dist/{chunk-2IIK4X7C.js → chunk-ZMTQQZFH.js} +394 -321
- package/dist/{chunk-2IIK4X7C.js.map → chunk-ZMTQQZFH.js.map} +1 -1
- package/dist/cli/index.cjs +831 -706
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +324 -268
- package/dist/cli/index.js.map +1 -1
- package/dist/mcp/index.cjs +236 -166
- 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
|
@@ -5621,6 +5621,17 @@ import mime from "mime";
|
|
|
5621
5621
|
import axios from "axios";
|
|
5622
5622
|
import { v4 as uuidv4 } from "uuid";
|
|
5623
5623
|
import { format as dateFormat } from "date-fns";
|
|
5624
|
+
var CRC32_TABLE = (() => {
|
|
5625
|
+
const table = [];
|
|
5626
|
+
for (let i = 0; i < 256; i++) {
|
|
5627
|
+
let crc = i;
|
|
5628
|
+
for (let j = 0; j < 8; j++) {
|
|
5629
|
+
crc = crc & 1 ? 3988292384 ^ crc >>> 1 : crc >>> 1;
|
|
5630
|
+
}
|
|
5631
|
+
table[i] = crc;
|
|
5632
|
+
}
|
|
5633
|
+
return table;
|
|
5634
|
+
})();
|
|
5624
5635
|
var util = {
|
|
5625
5636
|
uuid: (separator = true) => separator ? uuidv4() : uuidv4().replace(/-/g, ""),
|
|
5626
5637
|
getDateString(format = "yyyy-MM-dd", date = /* @__PURE__ */ new Date()) {
|
|
@@ -5666,22 +5677,18 @@ var util = {
|
|
|
5666
5677
|
* @returns CRC32 十六进制字符串
|
|
5667
5678
|
*/
|
|
5668
5679
|
calculateCRC32(buffer) {
|
|
5669
|
-
const crcTable = [];
|
|
5670
|
-
for (let i = 0; i < 256; i++) {
|
|
5671
|
-
let crc2 = i;
|
|
5672
|
-
for (let j = 0; j < 8; j++) {
|
|
5673
|
-
crc2 = crc2 & 1 ? 3988292384 ^ crc2 >>> 1 : crc2 >>> 1;
|
|
5674
|
-
}
|
|
5675
|
-
crcTable[i] = crc2;
|
|
5676
|
-
}
|
|
5677
5680
|
let crc = 0 ^ -1;
|
|
5678
5681
|
const bytes = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5679
5682
|
for (let i = 0; i < bytes.length; i++) {
|
|
5680
|
-
crc = crc >>> 8 ^
|
|
5683
|
+
crc = crc >>> 8 ^ CRC32_TABLE[(crc ^ bytes[i]) & 255];
|
|
5681
5684
|
}
|
|
5682
5685
|
return ((crc ^ -1) >>> 0).toString(16).padStart(8, "0");
|
|
5683
5686
|
}
|
|
5684
5687
|
};
|
|
5688
|
+
function maskToken(token) {
|
|
5689
|
+
if (token.length <= 10) return "***";
|
|
5690
|
+
return `${token.slice(0, 4)}...${token.slice(-4)}`;
|
|
5691
|
+
}
|
|
5685
5692
|
var util_default = util;
|
|
5686
5693
|
|
|
5687
5694
|
// src/lib/logger.ts
|
|
@@ -5957,6 +5964,8 @@ var JimengErrorHandler = class {
|
|
|
5957
5964
|
throw new APIException(exceptions_default.API_IMAGE_GENERATION_FAILED, `[\u751F\u6210\u5931\u8D25]: ${errmsg}`);
|
|
5958
5965
|
case "5002":
|
|
5959
5966
|
throw new APIException(exceptions_default.API_VIDEO_GENERATION_FAILED, `[\u89C6\u9891\u751F\u6210\u5931\u8D25]: ${errmsg}`);
|
|
5967
|
+
case "34010105":
|
|
5968
|
+
throw new APIException(exceptions_default.API_REQUEST_FAILED, `[\u767B\u5F55\u9A8C\u8BC1\u5931\u8D25]: ${errmsg} (\u9519\u8BEF\u7801: ${ret})`);
|
|
5960
5969
|
default:
|
|
5961
5970
|
throw new APIException(exceptions_default.API_REQUEST_FAILED, `[${operation}\u5931\u8D25]: ${errmsg} (\u9519\u8BEF\u7801: ${ret})`);
|
|
5962
5971
|
}
|
|
@@ -5986,16 +5995,18 @@ var JimengErrorHandler = class {
|
|
|
5986
5995
|
* 处理轮询超时错误
|
|
5987
5996
|
* @returns 如果有部分结果,返回 void 而不抛出异常
|
|
5988
5997
|
*/
|
|
5989
|
-
static handlePollingTimeout(pollCount, maxPollCount, elapsedTime, status, itemCount, historyId) {
|
|
5990
|
-
const
|
|
5998
|
+
static handlePollingTimeout(pollCount, maxPollCount, elapsedTime, status, itemCount, historyId, type = "image") {
|
|
5999
|
+
const typeText = type === "image" ? "\u56FE\u7247" : "\u89C6\u9891";
|
|
6000
|
+
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}`;
|
|
5991
6001
|
logger_default.warn(message + (historyId ? `\uFF0C\u5386\u53F2ID: ${historyId}` : ""));
|
|
5992
6002
|
if (itemCount === 0) {
|
|
6003
|
+
const exception = type === "image" ? exceptions_default.API_IMAGE_GENERATION_FAILED : exceptions_default.API_VIDEO_GENERATION_FAILED;
|
|
5993
6004
|
throw new APIException(
|
|
5994
|
-
|
|
5995
|
-
|
|
6005
|
+
exception,
|
|
6006
|
+
`${typeText}\u751F\u6210\u8D85\u65F6\u4E14\u65E0\u7ED3\u679C\uFF0C\u72B6\u6001\u7801: ${status}${historyId ? `\uFF0C\u5386\u53F2ID: ${historyId}` : ""}`
|
|
5996
6007
|
);
|
|
5997
6008
|
}
|
|
5998
|
-
logger_default.info(`\u8F6E\u8BE2\u8D85\u65F6\u4F46\u5DF2\u83B7\u5F97 ${itemCount} \
|
|
6009
|
+
logger_default.info(`\u8F6E\u8BE2\u8D85\u65F6\u4F46\u5DF2\u83B7\u5F97 ${itemCount} \u4E2A${typeText}\uFF0C\u5C06\u8FD4\u56DE\u73B0\u6709\u7ED3\u679C`);
|
|
5999
6010
|
}
|
|
6000
6011
|
/**
|
|
6001
6012
|
* 处理生成失败错误
|
|
@@ -6060,12 +6071,11 @@ var BASE_URL_IMAGEX_US = "https://imagex16-normal-us-ttp.capcutapi.us";
|
|
|
6060
6071
|
var BASE_URL_DREAMINA_HK = "https://mweb-api-sg.capcut.com";
|
|
6061
6072
|
var BASE_URL_IMAGEX_HK = "https://imagex-normal-sg.capcutapi.com";
|
|
6062
6073
|
var WEB_VERSION = "7.5.0";
|
|
6063
|
-
var DA_VERSION = "3.3.
|
|
6074
|
+
var DA_VERSION = "3.3.12";
|
|
6064
6075
|
|
|
6065
6076
|
// src/api/consts/common.ts
|
|
6066
6077
|
var BASE_URL_CN = "https://jimeng.jianying.com";
|
|
6067
6078
|
var BASE_URL_US_COMMERCE = "https://commerce.us.capcut.com";
|
|
6068
|
-
var BASE_URL_HK_COMMERCE = "https://commerce-api-sg.capcut.com";
|
|
6069
6079
|
var DEFAULT_ASSISTANT_ID_CN = 513695;
|
|
6070
6080
|
var DEFAULT_ASSISTANT_ID_US = 513641;
|
|
6071
6081
|
var DEFAULT_ASSISTANT_ID_HK = 513641;
|
|
@@ -6081,9 +6091,9 @@ var VERSION_CODE = "8.4.0";
|
|
|
6081
6091
|
var DEFAULT_IMAGE_MODEL = "jimeng-4.5";
|
|
6082
6092
|
var DEFAULT_IMAGE_MODEL_US = "jimeng-4.5";
|
|
6083
6093
|
var DEFAULT_VIDEO_MODEL = "jimeng-video-3.5-pro";
|
|
6084
|
-
var DRAFT_VERSION = "3.3.
|
|
6094
|
+
var DRAFT_VERSION = "3.3.12";
|
|
6085
6095
|
var DRAFT_MIN_VERSION = "3.0.2";
|
|
6086
|
-
var DRAFT_VERSION_OMNI = "3.3.
|
|
6096
|
+
var DRAFT_VERSION_OMNI = "3.3.12";
|
|
6087
6097
|
var OMNI_BENEFIT_TYPE = "dreamina_video_seedance_20_video_add";
|
|
6088
6098
|
var OMNI_BENEFIT_TYPE_FAST = "dreamina_seedance_20_fast_with_video";
|
|
6089
6099
|
var IMAGE_MODEL_MAP = {
|
|
@@ -6099,6 +6109,8 @@ var IMAGE_MODEL_MAP = {
|
|
|
6099
6109
|
"jimeng-lab": "high_aes_general_v50_lab"
|
|
6100
6110
|
};
|
|
6101
6111
|
var IMAGE_MODEL_MAP_US = {
|
|
6112
|
+
"jimeng-5.0": "high_aes_general_v50",
|
|
6113
|
+
"jimeng-4.6": "high_aes_general_v42",
|
|
6102
6114
|
"jimeng-4.5": "high_aes_general_v40l",
|
|
6103
6115
|
"jimeng-4.1": "high_aes_general_v41",
|
|
6104
6116
|
"jimeng-4.0": "high_aes_general_v40",
|
|
@@ -6112,6 +6124,7 @@ var IMAGE_MODEL_MAP_ASIA = {
|
|
|
6112
6124
|
"jimeng-4.5": "high_aes_general_v40l",
|
|
6113
6125
|
"jimeng-4.1": "high_aes_general_v41",
|
|
6114
6126
|
"jimeng-4.0": "high_aes_general_v40",
|
|
6127
|
+
"jimeng-3.1": "high_aes_general_v30l_art:general_v3.0_18b",
|
|
6115
6128
|
"jimeng-3.0": "high_aes_general_v30l:general_v3.0_18b",
|
|
6116
6129
|
"nanobanana": "external_model_gemini_flash_image_v25",
|
|
6117
6130
|
"nanobananapro": "dreamina_image_lib_1"
|
|
@@ -6129,10 +6142,14 @@ var VIDEO_MODEL_MAP = {
|
|
|
6129
6142
|
"jimeng-video-2.0-pro": "dreamina_ic_generate_video_model_vgfm1.0"
|
|
6130
6143
|
};
|
|
6131
6144
|
var VIDEO_MODEL_MAP_US = {
|
|
6145
|
+
"jimeng-video-seedance-2.0": "dreamina_seedance_40_pro",
|
|
6146
|
+
"jimeng-video-seedance-2.0-fast": "dreamina_seedance_40",
|
|
6132
6147
|
"jimeng-video-3.5-pro": "dreamina_ic_generate_video_model_vgfm_3.5_pro",
|
|
6133
6148
|
"jimeng-video-3.0": "dreamina_ic_generate_video_model_vgfm_3.0"
|
|
6134
6149
|
};
|
|
6135
6150
|
var VIDEO_MODEL_MAP_ASIA = {
|
|
6151
|
+
"jimeng-video-seedance-2.0": "dreamina_seedance_40_pro",
|
|
6152
|
+
"jimeng-video-seedance-2.0-fast": "dreamina_seedance_40",
|
|
6136
6153
|
"jimeng-video-veo3": "dreamina_veo3_generate_video",
|
|
6137
6154
|
"jimeng-video-veo3.1": "dreamina_veo3.1_generate_video",
|
|
6138
6155
|
"jimeng-video-sora2": "dreamina_sora2_generate_video",
|
|
@@ -6212,6 +6229,7 @@ var RESOLUTION_OPTIONS_NANOBANANAPRO_4K = {
|
|
|
6212
6229
|
var DEVICE_ID = Math.random() * 1e18 + 7e18;
|
|
6213
6230
|
var WEB_ID = Math.random() * 1e18 + 7e18;
|
|
6214
6231
|
var USER_ID = util_default.uuid(false);
|
|
6232
|
+
var INTERNATIONAL_FRONTEND_ORIGIN = "https://dreamina.capcut.com";
|
|
6215
6233
|
var FAKE_HEADERS = {
|
|
6216
6234
|
Accept: "application/json, text/plain, */*",
|
|
6217
6235
|
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
@@ -6335,8 +6353,7 @@ function parseProxyFromToken(rawToken) {
|
|
|
6335
6353
|
return { token, proxyUrl };
|
|
6336
6354
|
}
|
|
6337
6355
|
function getRefererByRegion(regionInfo, cnPath) {
|
|
6338
|
-
|
|
6339
|
-
return isInternational ? "https://dreamina.capcut.com/" : `https://jimeng.jianying.com${cnPath}`;
|
|
6356
|
+
return regionInfo.isInternational ? `${INTERNATIONAL_FRONTEND_ORIGIN}/` : `${BASE_URL_CN}${cnPath}`;
|
|
6340
6357
|
}
|
|
6341
6358
|
function getAssistantId(regionInfo) {
|
|
6342
6359
|
if (regionInfo.isUS) return DEFAULT_ASSISTANT_ID_US;
|
|
@@ -6367,12 +6384,14 @@ function generateCookie(refreshToken) {
|
|
|
6367
6384
|
}
|
|
6368
6385
|
async function getCredit(refreshToken, regionInfo) {
|
|
6369
6386
|
const referer = getRefererByRegion(regionInfo, "/ai-tool/image/generate");
|
|
6387
|
+
const origin = regionInfo.isInternational ? INTERNATIONAL_FRONTEND_ORIGIN : void 0;
|
|
6370
6388
|
const {
|
|
6371
6389
|
credit: { gift_credit, purchase_credit, vip_credit }
|
|
6372
6390
|
} = await request("POST", "/commerce/v1/benefits/user_credit", refreshToken, regionInfo, {
|
|
6373
6391
|
data: {},
|
|
6374
6392
|
headers: {
|
|
6375
|
-
Referer: referer
|
|
6393
|
+
Referer: referer,
|
|
6394
|
+
...origin ? { Origin: origin } : {}
|
|
6376
6395
|
},
|
|
6377
6396
|
noDefaultParams: true
|
|
6378
6397
|
});
|
|
@@ -6389,13 +6408,15 @@ async function getCredit(refreshToken, regionInfo) {
|
|
|
6389
6408
|
async function receiveCredit(refreshToken, regionInfo) {
|
|
6390
6409
|
logger_default.info("\u6B63\u5728\u5C1D\u8BD5\u6536\u53D6\u4ECA\u65E5\u79EF\u5206...");
|
|
6391
6410
|
const referer = getRefererByRegion(regionInfo, "/ai-tool/home");
|
|
6411
|
+
const origin = regionInfo.isInternational ? INTERNATIONAL_FRONTEND_ORIGIN : void 0;
|
|
6392
6412
|
const timeZone = regionInfo.isUS ? "America/New_York" : regionInfo.isHK ? "Asia/Hong_Kong" : regionInfo.isJP ? "Asia/Tokyo" : regionInfo.isSG ? "Asia/Singapore" : "Asia/Shanghai";
|
|
6393
6413
|
const { receive_quota } = await request("POST", "/commerce/v1/benefits/credit_receive", refreshToken, regionInfo, {
|
|
6394
6414
|
data: {
|
|
6395
6415
|
time_zone: timeZone
|
|
6396
6416
|
},
|
|
6397
6417
|
headers: {
|
|
6398
|
-
Referer: referer
|
|
6418
|
+
Referer: referer,
|
|
6419
|
+
...origin ? { Origin: origin } : {}
|
|
6399
6420
|
}
|
|
6400
6421
|
});
|
|
6401
6422
|
logger_default.info(`\u4ECA\u65E5${receive_quota}\u79EF\u5206\u6536\u53D6\u6210\u529F`);
|
|
@@ -6423,7 +6444,7 @@ async function request(method, uri, refreshToken, regionInfo, options = {}) {
|
|
|
6423
6444
|
region = REGION_US;
|
|
6424
6445
|
} else if (isHK || isJP || isSG) {
|
|
6425
6446
|
if (uri.startsWith("/commerce/")) {
|
|
6426
|
-
baseUrl =
|
|
6447
|
+
baseUrl = BASE_URL_US_COMMERCE;
|
|
6427
6448
|
} else {
|
|
6428
6449
|
baseUrl = BASE_URL_DREAMINA_HK;
|
|
6429
6450
|
}
|
|
@@ -6503,7 +6524,8 @@ async function request(method, uri, refreshToken, regionInfo, options = {}) {
|
|
|
6503
6524
|
});
|
|
6504
6525
|
logger_default.info(`\u54CD\u5E94\u72B6\u6001: ${response.status} ${response.statusText}`);
|
|
6505
6526
|
if (options.responseType == "stream") return response;
|
|
6506
|
-
const
|
|
6527
|
+
const responseJson = JSON.stringify(response.data);
|
|
6528
|
+
const responseDataSummary = responseJson.substring(0, 500) + (responseJson.length > 500 ? "..." : "");
|
|
6507
6529
|
logger_default.info(`\u54CD\u5E94\u6570\u636E\u6458\u8981: ${responseDataSummary}`);
|
|
6508
6530
|
if (response.status >= 400) {
|
|
6509
6531
|
logger_default.warn(`HTTP\u9519\u8BEF: ${response.status} ${response.statusText}`);
|
|
@@ -6594,6 +6616,9 @@ function checkResult(result) {
|
|
|
6594
6616
|
}
|
|
6595
6617
|
async function getTokenLiveStatus(refreshToken, regionInfo) {
|
|
6596
6618
|
try {
|
|
6619
|
+
if (regionInfo.isInternational) {
|
|
6620
|
+
return await checkInternationalTokenLive(refreshToken, regionInfo);
|
|
6621
|
+
}
|
|
6597
6622
|
const result = await request(
|
|
6598
6623
|
"POST",
|
|
6599
6624
|
"/passport/account/info/v2",
|
|
@@ -6612,10 +6637,264 @@ async function getTokenLiveStatus(refreshToken, regionInfo) {
|
|
|
6612
6637
|
return false;
|
|
6613
6638
|
}
|
|
6614
6639
|
}
|
|
6640
|
+
async function checkInternationalTokenLive(refreshToken, regionInfo) {
|
|
6641
|
+
const aid = getAssistantId(regionInfo);
|
|
6642
|
+
const countryCode = regionInfo.isUS ? "us" : regionInfo.isJP ? "jp" : regionInfo.isHK ? "hk" : "sg";
|
|
6643
|
+
const cookie = generateCookie(refreshToken);
|
|
6644
|
+
try {
|
|
6645
|
+
const response = await axios2.get(
|
|
6646
|
+
`${INTERNATIONAL_FRONTEND_ORIGIN}/passport/web/account/info/`,
|
|
6647
|
+
{
|
|
6648
|
+
params: {
|
|
6649
|
+
aid,
|
|
6650
|
+
account_sdk_source: "web",
|
|
6651
|
+
sdk_version: "2.1.10-tiktok",
|
|
6652
|
+
language: countryCode === "jp" ? "ja" : "en"
|
|
6653
|
+
},
|
|
6654
|
+
headers: {
|
|
6655
|
+
...FAKE_HEADERS,
|
|
6656
|
+
Cookie: cookie,
|
|
6657
|
+
Referer: `${INTERNATIONAL_FRONTEND_ORIGIN}/ai-tool/home/`,
|
|
6658
|
+
Origin: INTERNATIONAL_FRONTEND_ORIGIN,
|
|
6659
|
+
Appid: String(aid),
|
|
6660
|
+
"store-country-code": countryCode,
|
|
6661
|
+
"store-country-code-src": "uid"
|
|
6662
|
+
},
|
|
6663
|
+
timeout: 15e3
|
|
6664
|
+
}
|
|
6665
|
+
);
|
|
6666
|
+
const data = response.data;
|
|
6667
|
+
if (data && typeof data === "object") {
|
|
6668
|
+
const obj = data;
|
|
6669
|
+
if (obj.user_id || obj.email || obj.data) {
|
|
6670
|
+
return true;
|
|
6671
|
+
}
|
|
6672
|
+
}
|
|
6673
|
+
return false;
|
|
6674
|
+
} catch {
|
|
6675
|
+
return false;
|
|
6676
|
+
}
|
|
6677
|
+
}
|
|
6615
6678
|
|
|
6616
6679
|
// src/lib/session-pool.ts
|
|
6617
6680
|
import path4 from "path";
|
|
6618
6681
|
import fs4 from "fs-extra";
|
|
6682
|
+
|
|
6683
|
+
// src/api/controllers/models.ts
|
|
6684
|
+
var CACHE_TTL_MS = 10 * 60 * 1e3;
|
|
6685
|
+
var FALLBACK_TOKEN = "test_token";
|
|
6686
|
+
var modelCache = /* @__PURE__ */ new Map();
|
|
6687
|
+
function mapVideoDescription(id) {
|
|
6688
|
+
if (id.includes("veo3.1")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B veo3.1";
|
|
6689
|
+
if (id.includes("veo3")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B veo3";
|
|
6690
|
+
if (id.includes("sora2")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B sora2";
|
|
6691
|
+
if (id.includes("seedance-2.0-fast")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B seedance 2.0-fast";
|
|
6692
|
+
if (id.includes("seedance-2.0")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B seedance 2.0";
|
|
6693
|
+
if (id.includes("3.5-pro")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 3.5 \u4E13\u4E1A\u7248";
|
|
6694
|
+
if (id.includes("3.0-fast")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 3.0 \u6781\u901F\u7248";
|
|
6695
|
+
if (id.includes("3.0-pro")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 3.0 \u4E13\u4E1A\u7248";
|
|
6696
|
+
if (id.includes("3.0")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 3.0";
|
|
6697
|
+
if (id.includes("2.0-pro")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 2.0 \u4E13\u4E1A\u7248";
|
|
6698
|
+
if (id.includes("2.0")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 2.0";
|
|
6699
|
+
return void 0;
|
|
6700
|
+
}
|
|
6701
|
+
function mapImageDescription(id) {
|
|
6702
|
+
if (id.includes("5.0")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 5.0";
|
|
6703
|
+
if (id.includes("4.6")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 4.6";
|
|
6704
|
+
if (id.includes("4.5")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 4.5";
|
|
6705
|
+
if (id.includes("4.1")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 4.1";
|
|
6706
|
+
if (id.includes("4.0")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 4.0";
|
|
6707
|
+
if (id.includes("3.1")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 3.1";
|
|
6708
|
+
if (id.includes("3.0")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 3.0";
|
|
6709
|
+
return `\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B ${id}`;
|
|
6710
|
+
}
|
|
6711
|
+
function buildModelItem(modelId, meta) {
|
|
6712
|
+
var _a;
|
|
6713
|
+
const modelType = modelId.startsWith("jimeng-video-") ? "video" : "image";
|
|
6714
|
+
const item = {
|
|
6715
|
+
id: modelId,
|
|
6716
|
+
object: "model",
|
|
6717
|
+
owned_by: "jimeng-cli",
|
|
6718
|
+
model_type: modelType
|
|
6719
|
+
};
|
|
6720
|
+
if (meta == null ? void 0 : meta.reqKey) item.model_req_key = meta.reqKey;
|
|
6721
|
+
if (meta == null ? void 0 : meta.modelName) item.model_name = meta.modelName;
|
|
6722
|
+
if ((_a = meta == null ? void 0 : meta.capabilities) == null ? void 0 : _a.length) item.capabilities = Array.from(new Set(meta.capabilities)).sort();
|
|
6723
|
+
if ((meta == null ? void 0 : meta.params) && Object.keys(meta.params).length > 0) item.params = meta.params;
|
|
6724
|
+
if (meta == null ? void 0 : meta.modelTip) {
|
|
6725
|
+
item.description = meta.modelTip;
|
|
6726
|
+
} else if (modelType === "video") {
|
|
6727
|
+
item.description = mapVideoDescription(modelId);
|
|
6728
|
+
} else {
|
|
6729
|
+
item.description = mapImageDescription(modelId);
|
|
6730
|
+
}
|
|
6731
|
+
return item;
|
|
6732
|
+
}
|
|
6733
|
+
function parseFirstToken(authorization) {
|
|
6734
|
+
var _a;
|
|
6735
|
+
if (!authorization || !/^Bearer\s+/i.test(authorization)) return void 0;
|
|
6736
|
+
const raw = authorization.replace(/^Bearer\s+/i, "").trim();
|
|
6737
|
+
if (!raw) return void 0;
|
|
6738
|
+
const first = (_a = raw.split(",")[0]) == null ? void 0 : _a.trim();
|
|
6739
|
+
return first || void 0;
|
|
6740
|
+
}
|
|
6741
|
+
function resolveToken(authorization) {
|
|
6742
|
+
const fromAuth = parseFirstToken(authorization);
|
|
6743
|
+
if (fromAuth) return fromAuth;
|
|
6744
|
+
const fromPool = session_pool_default.getAllTokens({ onlyEnabled: true, preferLive: true })[0];
|
|
6745
|
+
return fromPool || void 0;
|
|
6746
|
+
}
|
|
6747
|
+
function getRegionalMaps(region) {
|
|
6748
|
+
if (region === "us") return [IMAGE_MODEL_MAP_US, VIDEO_MODEL_MAP_US];
|
|
6749
|
+
if (region === "hk" || region === "jp" || region === "sg") return [IMAGE_MODEL_MAP_ASIA, VIDEO_MODEL_MAP_ASIA];
|
|
6750
|
+
if (region === "cn") return [IMAGE_MODEL_MAP, VIDEO_MODEL_MAP];
|
|
6751
|
+
return [IMAGE_MODEL_MAP, IMAGE_MODEL_MAP_US, IMAGE_MODEL_MAP_ASIA, VIDEO_MODEL_MAP, VIDEO_MODEL_MAP_US, VIDEO_MODEL_MAP_ASIA];
|
|
6752
|
+
}
|
|
6753
|
+
function resolveRegion(authorization, xRegion) {
|
|
6754
|
+
var _a;
|
|
6755
|
+
const token = resolveToken(authorization);
|
|
6756
|
+
const parsedXRegion = parseRegionCode(xRegion);
|
|
6757
|
+
if (parsedXRegion) return parsedXRegion;
|
|
6758
|
+
if (token) {
|
|
6759
|
+
assertTokenWithoutRegionPrefix(token);
|
|
6760
|
+
const normalizedToken = parseProxyFromToken(token).token;
|
|
6761
|
+
const poolRegion = (_a = session_pool_default.getTokenEntry(normalizedToken)) == null ? void 0 : _a.region;
|
|
6762
|
+
if (poolRegion) return poolRegion;
|
|
6763
|
+
throw new Error("\u7F3A\u5C11 region\u3002token \u672A\u5728 pool \u4E2D\u6CE8\u518C\u65F6\uFF0C/v1/models \u9700\u8981\u63D0\u4F9B\u8BF7\u6C42\u5934 X-Region");
|
|
6764
|
+
}
|
|
6765
|
+
return "cn";
|
|
6766
|
+
}
|
|
6767
|
+
var reverseMapCache = /* @__PURE__ */ new Map();
|
|
6768
|
+
function buildReverseMap(region) {
|
|
6769
|
+
const cached = reverseMapCache.get(region);
|
|
6770
|
+
if (cached) return cached;
|
|
6771
|
+
const reverse = {};
|
|
6772
|
+
for (const map of getRegionalMaps(region)) {
|
|
6773
|
+
for (const [modelId, upstreamKey] of Object.entries(map)) {
|
|
6774
|
+
reverse[upstreamKey] = modelId;
|
|
6775
|
+
}
|
|
6776
|
+
}
|
|
6777
|
+
reverseMapCache.set(region, reverse);
|
|
6778
|
+
return reverse;
|
|
6779
|
+
}
|
|
6780
|
+
function buildFallbackModels(region) {
|
|
6781
|
+
const maps = getRegionalMaps(region);
|
|
6782
|
+
const modelIds = Array.from(new Set(maps.flatMap((item) => Object.keys(item)))).sort();
|
|
6783
|
+
return modelIds.map((id) => buildModelItem(id));
|
|
6784
|
+
}
|
|
6785
|
+
function makeCacheKey(region) {
|
|
6786
|
+
return `models|${region}`;
|
|
6787
|
+
}
|
|
6788
|
+
function resolveFetchToken(token) {
|
|
6789
|
+
if (!token) return FALLBACK_TOKEN;
|
|
6790
|
+
const normalizedToken = parseProxyFromToken(token).token;
|
|
6791
|
+
assertTokenWithoutRegionPrefix(normalizedToken);
|
|
6792
|
+
return normalizedToken;
|
|
6793
|
+
}
|
|
6794
|
+
function extractValidOptions(item) {
|
|
6795
|
+
return (Array.isArray(item.options) ? item.options : []).filter(
|
|
6796
|
+
(opt) => !!opt && typeof opt === "object" && typeof opt.key === "string" && opt.key.length > 0
|
|
6797
|
+
);
|
|
6798
|
+
}
|
|
6799
|
+
function extractCapabilities(item) {
|
|
6800
|
+
const features = Array.isArray(item.feats) ? item.feats.filter((f) => typeof f === "string" && f.length > 0) : [];
|
|
6801
|
+
const optionKeys = extractValidOptions(item).map((o) => o.key);
|
|
6802
|
+
return Array.from(/* @__PURE__ */ new Set([...features, ...optionKeys]));
|
|
6803
|
+
}
|
|
6804
|
+
function extractEnumParams(item) {
|
|
6805
|
+
const params = {};
|
|
6806
|
+
for (const o of extractValidOptions(item)) {
|
|
6807
|
+
const ev = o.enum_val;
|
|
6808
|
+
if (!ev) continue;
|
|
6809
|
+
const sv = ev.string_value;
|
|
6810
|
+
const iv = ev.int_value;
|
|
6811
|
+
const vals = sv || iv;
|
|
6812
|
+
if (vals && vals.length > 0) {
|
|
6813
|
+
params[o.key] = vals;
|
|
6814
|
+
}
|
|
6815
|
+
}
|
|
6816
|
+
const rm = item.resolution_map;
|
|
6817
|
+
if (rm && typeof rm === "object") {
|
|
6818
|
+
params["resolution"] = Object.keys(rm).map(String);
|
|
6819
|
+
}
|
|
6820
|
+
const steps = item.sample_steps;
|
|
6821
|
+
if (steps && typeof steps === "object") {
|
|
6822
|
+
params["steps"] = [steps.min_steps, steps.max_steps];
|
|
6823
|
+
}
|
|
6824
|
+
return params;
|
|
6825
|
+
}
|
|
6826
|
+
function toUpstreamMeta(item) {
|
|
6827
|
+
const reqKey = item == null ? void 0 : item.model_req_key;
|
|
6828
|
+
if (typeof reqKey !== "string" || reqKey.length === 0) return void 0;
|
|
6829
|
+
return {
|
|
6830
|
+
reqKey,
|
|
6831
|
+
modelName: typeof (item == null ? void 0 : item.model_name) === "string" ? item.model_name : void 0,
|
|
6832
|
+
modelTip: typeof (item == null ? void 0 : item.model_tip) === "string" ? item.model_tip : void 0,
|
|
6833
|
+
capabilities: extractCapabilities(item),
|
|
6834
|
+
params: extractEnumParams(item)
|
|
6835
|
+
};
|
|
6836
|
+
}
|
|
6837
|
+
async function fetchConfigModelReqKeys(token, region) {
|
|
6838
|
+
const regionInfo = buildRegionInfo(region);
|
|
6839
|
+
const [imageConfig, videoConfig] = await Promise.all([
|
|
6840
|
+
request("post", "/mweb/v1/get_common_config", token, regionInfo, {
|
|
6841
|
+
data: {},
|
|
6842
|
+
params: { needCache: true, needRefresh: false }
|
|
6843
|
+
}),
|
|
6844
|
+
request("post", "/mweb/v1/video_generate/get_common_config", token, regionInfo, {
|
|
6845
|
+
data: { scene: "generate_video", params: {} }
|
|
6846
|
+
})
|
|
6847
|
+
]);
|
|
6848
|
+
const toList = (config) => Array.isArray(config == null ? void 0 : config.model_list) ? config.model_list.map(toUpstreamMeta).filter((m) => Boolean(m)) : [];
|
|
6849
|
+
return { imageModels: toList(imageConfig), videoModels: toList(videoConfig) };
|
|
6850
|
+
}
|
|
6851
|
+
async function getLiveModels(authorization, xRegion) {
|
|
6852
|
+
const region = resolveRegion(authorization, xRegion);
|
|
6853
|
+
const token = resolveToken(authorization);
|
|
6854
|
+
const effectiveToken = resolveFetchToken(token);
|
|
6855
|
+
const cacheKey = makeCacheKey(region);
|
|
6856
|
+
const cached = modelCache.get(cacheKey);
|
|
6857
|
+
if (cached && cached.expiresAt > Date.now()) {
|
|
6858
|
+
return { source: cached.source, data: cached.data };
|
|
6859
|
+
}
|
|
6860
|
+
try {
|
|
6861
|
+
const reverseMap = buildReverseMap(region);
|
|
6862
|
+
const { imageModels, videoModels } = await fetchConfigModelReqKeys(effectiveToken, region);
|
|
6863
|
+
const upstreamModels = [...imageModels, ...videoModels];
|
|
6864
|
+
const metaByModelId = /* @__PURE__ */ new Map();
|
|
6865
|
+
const mapped = upstreamModels.map((model) => {
|
|
6866
|
+
const modelId = reverseMap[model.reqKey];
|
|
6867
|
+
if (modelId && !metaByModelId.has(modelId)) {
|
|
6868
|
+
metaByModelId.set(modelId, model);
|
|
6869
|
+
}
|
|
6870
|
+
return modelId;
|
|
6871
|
+
}).filter((item) => typeof item === "string" && item.length > 0);
|
|
6872
|
+
const modelIds = Array.from(new Set(mapped)).sort();
|
|
6873
|
+
if (modelIds.length === 0) {
|
|
6874
|
+
throw new Error("model_req_key resolved but none matched local reverse map");
|
|
6875
|
+
}
|
|
6876
|
+
const data = modelIds.map((id) => buildModelItem(id, metaByModelId.get(id)));
|
|
6877
|
+
modelCache.set(cacheKey, {
|
|
6878
|
+
expiresAt: Date.now() + CACHE_TTL_MS,
|
|
6879
|
+
source: "upstream",
|
|
6880
|
+
data
|
|
6881
|
+
});
|
|
6882
|
+
return { source: "upstream", data };
|
|
6883
|
+
} catch {
|
|
6884
|
+
const data = buildFallbackModels(region);
|
|
6885
|
+
modelCache.set(cacheKey, {
|
|
6886
|
+
expiresAt: Date.now() + CACHE_TTL_MS,
|
|
6887
|
+
source: "fallback",
|
|
6888
|
+
data
|
|
6889
|
+
});
|
|
6890
|
+
return { source: "fallback", data };
|
|
6891
|
+
}
|
|
6892
|
+
}
|
|
6893
|
+
async function refreshAllTokenModels() {
|
|
6894
|
+
return session_pool_default.refreshAllDynamicCapabilities();
|
|
6895
|
+
}
|
|
6896
|
+
|
|
6897
|
+
// src/lib/session-pool.ts
|
|
6619
6898
|
function sample(arr) {
|
|
6620
6899
|
return arr.length > 0 ? arr[Math.floor(Math.random() * arr.length)] : void 0;
|
|
6621
6900
|
}
|
|
@@ -6664,10 +6943,14 @@ var TokenPool = class {
|
|
|
6664
6943
|
);
|
|
6665
6944
|
}
|
|
6666
6945
|
getSummary() {
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
const
|
|
6946
|
+
let enabledCount = 0;
|
|
6947
|
+
let liveCount = 0;
|
|
6948
|
+
let missingRegionCount = 0;
|
|
6949
|
+
for (const item of this.entryMap.values()) {
|
|
6950
|
+
if (item.enabled) enabledCount++;
|
|
6951
|
+
if (item.enabled && item.live === true) liveCount++;
|
|
6952
|
+
if (!item.region) missingRegionCount++;
|
|
6953
|
+
}
|
|
6671
6954
|
return {
|
|
6672
6955
|
enabled: this.enabled,
|
|
6673
6956
|
filePath: this.filePath,
|
|
@@ -6676,19 +6959,19 @@ var TokenPool = class {
|
|
|
6676
6959
|
fetchCreditOnCheck: this.fetchCreditOnCheck,
|
|
6677
6960
|
autoDisableEnabled: this.autoDisableEnabled,
|
|
6678
6961
|
autoDisableFailures: this.autoDisableFailures,
|
|
6679
|
-
total:
|
|
6962
|
+
total: this.entryMap.size,
|
|
6680
6963
|
enabledCount,
|
|
6681
6964
|
liveCount,
|
|
6682
6965
|
missingRegionCount,
|
|
6683
6966
|
lastHealthCheckAt: this.lastHealthCheckAt || null
|
|
6684
6967
|
};
|
|
6685
6968
|
}
|
|
6686
|
-
getEntries(
|
|
6969
|
+
getEntries(shouldMask = true) {
|
|
6687
6970
|
const items = Array.from(this.entryMap.values()).map((item) => ({ ...item }));
|
|
6688
|
-
if (!
|
|
6971
|
+
if (!shouldMask) return items;
|
|
6689
6972
|
return items.map((item) => ({
|
|
6690
6973
|
...item,
|
|
6691
|
-
token:
|
|
6974
|
+
token: maskToken(item.token)
|
|
6692
6975
|
}));
|
|
6693
6976
|
}
|
|
6694
6977
|
getAllTokens(options = {}) {
|
|
@@ -6759,7 +7042,7 @@ var TokenPool = class {
|
|
|
6759
7042
|
token: null,
|
|
6760
7043
|
region: null,
|
|
6761
7044
|
error: "prefixed_token_not_supported",
|
|
6762
|
-
reason: `token ${
|
|
7045
|
+
reason: `token ${maskToken(prefixedCandidate.token)} \u4F7F\u7528\u4E86\u5DF2\u5E9F\u5F03\u7684 region \u524D\u7F00`
|
|
6763
7046
|
};
|
|
6764
7047
|
}
|
|
6765
7048
|
const regionLockedCandidates = validCandidates.filter(
|
|
@@ -6865,8 +7148,8 @@ var TokenPool = class {
|
|
|
6865
7148
|
async refreshDynamicCapabilitiesForToken(token) {
|
|
6866
7149
|
if (!this.enabled) throw new Error("Token pool disabled");
|
|
6867
7150
|
const item = this.entryMap.get(token);
|
|
6868
|
-
if (!item) throw new Error(`Token not found in pool: ${
|
|
6869
|
-
if (!item.region) throw new Error(`Token ${
|
|
7151
|
+
if (!item) throw new Error(`Token not found in pool: ${maskToken(token)}`);
|
|
7152
|
+
if (!item.region) throw new Error(`Token ${maskToken(token)} has no region`);
|
|
6870
7153
|
const regionInfo = buildRegionInfo(item.region);
|
|
6871
7154
|
const capabilities = await this.fetchDynamicCapabilities(token, regionInfo);
|
|
6872
7155
|
item.dynamicCapabilities = { ...capabilities, updatedAt: Date.now() };
|
|
@@ -6878,39 +7161,41 @@ var TokenPool = class {
|
|
|
6878
7161
|
* Returns a per-token result summary.
|
|
6879
7162
|
*/
|
|
6880
7163
|
async refreshAllDynamicCapabilities() {
|
|
6881
|
-
var _a, _b;
|
|
6882
7164
|
if (!this.enabled) return [];
|
|
6883
7165
|
const entries = this.getEntries(false).filter(
|
|
6884
7166
|
(item) => item.enabled && item.live !== false && Boolean(item.region)
|
|
6885
7167
|
);
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
current
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
|
|
6902
|
-
|
|
6903
|
-
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
|
|
6913
|
-
|
|
7168
|
+
if (entries.length === 0) return [];
|
|
7169
|
+
const results = await Promise.all(
|
|
7170
|
+
entries.map(async (entry) => {
|
|
7171
|
+
var _a, _b;
|
|
7172
|
+
try {
|
|
7173
|
+
const regionInfo = buildRegionInfo(entry.region);
|
|
7174
|
+
const capabilities = await this.fetchDynamicCapabilities(entry.token, regionInfo);
|
|
7175
|
+
const current = this.entryMap.get(entry.token);
|
|
7176
|
+
if (current) {
|
|
7177
|
+
current.dynamicCapabilities = { ...capabilities, updatedAt: Date.now() };
|
|
7178
|
+
}
|
|
7179
|
+
return {
|
|
7180
|
+
token: maskToken(entry.token),
|
|
7181
|
+
region: entry.region,
|
|
7182
|
+
imageModels: ((_a = capabilities.imageModels) == null ? void 0 : _a.length) ?? 0,
|
|
7183
|
+
videoModels: ((_b = capabilities.videoModels) == null ? void 0 : _b.length) ?? 0,
|
|
7184
|
+
capabilityTags: capabilities.capabilityTags ?? []
|
|
7185
|
+
};
|
|
7186
|
+
} catch (err) {
|
|
7187
|
+
return {
|
|
7188
|
+
token: maskToken(entry.token),
|
|
7189
|
+
region: entry.region,
|
|
7190
|
+
imageModels: 0,
|
|
7191
|
+
videoModels: 0,
|
|
7192
|
+
capabilityTags: [],
|
|
7193
|
+
error: err instanceof Error ? err.message : String(err)
|
|
7194
|
+
};
|
|
7195
|
+
}
|
|
7196
|
+
})
|
|
7197
|
+
);
|
|
7198
|
+
await this.persistToDisk();
|
|
6914
7199
|
return results;
|
|
6915
7200
|
}
|
|
6916
7201
|
async runHealthCheck() {
|
|
@@ -7031,14 +7316,10 @@ var TokenPool = class {
|
|
|
7031
7316
|
await fs4.ensureDir(path4.dirname(this.filePath));
|
|
7032
7317
|
const payload = {
|
|
7033
7318
|
updatedAt: Date.now(),
|
|
7034
|
-
tokens: this.
|
|
7319
|
+
tokens: Array.from(this.entryMap.values())
|
|
7035
7320
|
};
|
|
7036
7321
|
await fs4.writeJson(this.filePath, payload, { spaces: 2 });
|
|
7037
7322
|
}
|
|
7038
|
-
maskToken(token) {
|
|
7039
|
-
if (token.length <= 10) return "***";
|
|
7040
|
-
return `${token.slice(0, 4)}...${token.slice(-4)}`;
|
|
7041
|
-
}
|
|
7042
7323
|
parseAuthorizationTokens(authorization) {
|
|
7043
7324
|
if (typeof authorization !== "string" || authorization.trim().length === 0) {
|
|
7044
7325
|
return { tokens: [], error: null };
|
|
@@ -7067,7 +7348,7 @@ var TokenPool = class {
|
|
|
7067
7348
|
if (!token) continue;
|
|
7068
7349
|
const parsedRegion = parseRegionCode(item.region || defaultRegion);
|
|
7069
7350
|
if (!parsedRegion) {
|
|
7070
|
-
throw new Error(`token ${
|
|
7351
|
+
throw new Error(`token ${maskToken(token)} \u7F3A\u5C11\u6709\u6548 region\uFF08\u4EC5\u652F\u6301 cn/us/hk/jp/sg\uFF09`);
|
|
7071
7352
|
}
|
|
7072
7353
|
normalized.push({
|
|
7073
7354
|
token,
|
|
@@ -7175,233 +7456,25 @@ var TokenPool = class {
|
|
|
7175
7456
|
}
|
|
7176
7457
|
async fetchDynamicCapabilities(token, regionInfo) {
|
|
7177
7458
|
const regionCode = regionInfo.isUS ? "us" : regionInfo.isHK ? "hk" : regionInfo.isJP ? "jp" : regionInfo.isSG ? "sg" : "cn";
|
|
7178
|
-
const reverseMap =
|
|
7179
|
-
const
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
});
|
|
7183
|
-
const videoConfig = await request("post", "/mweb/v1/video_generate/get_common_config", token, regionInfo, {
|
|
7184
|
-
data: { scene: "generate_video", params: {} }
|
|
7185
|
-
});
|
|
7186
|
-
const imageReqKeys = Array.isArray(imageConfig == null ? void 0 : imageConfig.model_list) ? imageConfig.model_list.map((item) => typeof (item == null ? void 0 : item.model_req_key) === "string" ? item.model_req_key : "").filter(Boolean) : [];
|
|
7187
|
-
const videoReqKeys = Array.isArray(videoConfig == null ? void 0 : videoConfig.model_list) ? videoConfig.model_list.map((item) => typeof (item == null ? void 0 : item.model_req_key) === "string" ? item.model_req_key : "").filter(Boolean) : [];
|
|
7188
|
-
const imageModels = imageReqKeys.map((key) => reverseMap[key]).filter(Boolean);
|
|
7189
|
-
const videoModels = videoReqKeys.map((key) => reverseMap[key]).filter(Boolean);
|
|
7459
|
+
const reverseMap = buildReverseMap(regionCode);
|
|
7460
|
+
const { imageModels, videoModels } = await fetchConfigModelReqKeys(token, regionCode);
|
|
7461
|
+
const imageIds = imageModels.map((m) => reverseMap[m.reqKey]).filter(Boolean);
|
|
7462
|
+
const videoIds = videoModels.map((m) => reverseMap[m.reqKey]).filter(Boolean);
|
|
7190
7463
|
const capabilityTags = /* @__PURE__ */ new Set();
|
|
7191
|
-
for (const model of
|
|
7464
|
+
for (const model of videoIds) {
|
|
7192
7465
|
if (model.includes("seedance_40")) capabilityTags.add("omni_reference");
|
|
7193
7466
|
if (model.includes("veo3")) capabilityTags.add("veo3");
|
|
7194
7467
|
if (model.includes("sora2")) capabilityTags.add("sora2");
|
|
7195
7468
|
}
|
|
7196
7469
|
return {
|
|
7197
|
-
imageModels:
|
|
7198
|
-
videoModels:
|
|
7470
|
+
imageModels: imageIds.length ? Array.from(new Set(imageIds)) : void 0,
|
|
7471
|
+
videoModels: videoIds.length ? Array.from(new Set(videoIds)) : void 0,
|
|
7199
7472
|
capabilityTags: capabilityTags.size ? Array.from(capabilityTags) : void 0
|
|
7200
7473
|
};
|
|
7201
7474
|
}
|
|
7202
|
-
getReverseModelMapByRegion(region) {
|
|
7203
|
-
const maps = region === "us" ? [IMAGE_MODEL_MAP_US, VIDEO_MODEL_MAP_US] : region === "hk" || region === "jp" || region === "sg" ? [IMAGE_MODEL_MAP_ASIA, VIDEO_MODEL_MAP_ASIA] : [IMAGE_MODEL_MAP, VIDEO_MODEL_MAP];
|
|
7204
|
-
const reverse = {};
|
|
7205
|
-
for (const map of maps) {
|
|
7206
|
-
for (const [modelId, reqKey] of Object.entries(map)) {
|
|
7207
|
-
reverse[reqKey] = modelId;
|
|
7208
|
-
}
|
|
7209
|
-
}
|
|
7210
|
-
return reverse;
|
|
7211
|
-
}
|
|
7212
7475
|
};
|
|
7213
7476
|
var session_pool_default = new TokenPool();
|
|
7214
7477
|
|
|
7215
|
-
// src/api/controllers/models.ts
|
|
7216
|
-
var CACHE_TTL_MS = 10 * 60 * 1e3;
|
|
7217
|
-
var FALLBACK_TOKEN = "test_token";
|
|
7218
|
-
var modelCache = /* @__PURE__ */ new Map();
|
|
7219
|
-
function mapVideoDescription(id) {
|
|
7220
|
-
if (id.includes("veo3.1")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B veo3.1";
|
|
7221
|
-
if (id.includes("veo3")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B veo3";
|
|
7222
|
-
if (id.includes("sora2")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B sora2";
|
|
7223
|
-
if (id.includes("seedance-2.0-fast")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B seedance 2.0-fast";
|
|
7224
|
-
if (id.includes("seedance-2.0")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B seedance 2.0";
|
|
7225
|
-
if (id.includes("3.5-pro")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 3.5 \u4E13\u4E1A\u7248";
|
|
7226
|
-
if (id.includes("3.0-fast")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 3.0 \u6781\u901F\u7248";
|
|
7227
|
-
if (id.includes("3.0-pro")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 3.0 \u4E13\u4E1A\u7248";
|
|
7228
|
-
if (id.includes("3.0")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 3.0";
|
|
7229
|
-
if (id.includes("2.0-pro")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 2.0 \u4E13\u4E1A\u7248";
|
|
7230
|
-
if (id.includes("2.0")) return "\u5373\u68A6AI\u89C6\u9891\u751F\u6210\u6A21\u578B 2.0";
|
|
7231
|
-
return void 0;
|
|
7232
|
-
}
|
|
7233
|
-
function mapImageDescription(id) {
|
|
7234
|
-
if (id.includes("5.0")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 5.0";
|
|
7235
|
-
if (id.includes("4.6")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 4.6";
|
|
7236
|
-
if (id.includes("4.5")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 4.5";
|
|
7237
|
-
if (id.includes("4.1")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 4.1";
|
|
7238
|
-
if (id.includes("4.0")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 4.0";
|
|
7239
|
-
if (id.includes("3.1")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 3.1";
|
|
7240
|
-
if (id.includes("3.0")) return "\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B 3.0";
|
|
7241
|
-
return `\u5373\u68A6AI\u56FE\u50CF\u6A21\u578B ${id}`;
|
|
7242
|
-
}
|
|
7243
|
-
function buildModelItem(modelId, meta) {
|
|
7244
|
-
var _a;
|
|
7245
|
-
const modelType = modelId.startsWith("jimeng-video-") ? "video" : "image";
|
|
7246
|
-
const item = {
|
|
7247
|
-
id: modelId,
|
|
7248
|
-
object: "model",
|
|
7249
|
-
owned_by: "jimeng-cli",
|
|
7250
|
-
model_type: modelType
|
|
7251
|
-
};
|
|
7252
|
-
if (meta == null ? void 0 : meta.reqKey) item.model_req_key = meta.reqKey;
|
|
7253
|
-
if (meta == null ? void 0 : meta.modelName) item.model_name = meta.modelName;
|
|
7254
|
-
if ((_a = meta == null ? void 0 : meta.capabilities) == null ? void 0 : _a.length) item.capabilities = Array.from(new Set(meta.capabilities)).sort();
|
|
7255
|
-
if (meta == null ? void 0 : meta.modelTip) {
|
|
7256
|
-
item.description = meta.modelTip;
|
|
7257
|
-
} else if (modelType === "video") {
|
|
7258
|
-
item.description = mapVideoDescription(modelId);
|
|
7259
|
-
} else {
|
|
7260
|
-
item.description = mapImageDescription(modelId);
|
|
7261
|
-
}
|
|
7262
|
-
return item;
|
|
7263
|
-
}
|
|
7264
|
-
function parseFirstToken(authorization) {
|
|
7265
|
-
var _a;
|
|
7266
|
-
if (!authorization || !/^Bearer\s+/i.test(authorization)) return void 0;
|
|
7267
|
-
const raw = authorization.replace(/^Bearer\s+/i, "").trim();
|
|
7268
|
-
if (!raw) return void 0;
|
|
7269
|
-
const first = (_a = raw.split(",")[0]) == null ? void 0 : _a.trim();
|
|
7270
|
-
return first || void 0;
|
|
7271
|
-
}
|
|
7272
|
-
function resolveToken(authorization) {
|
|
7273
|
-
const fromAuth = parseFirstToken(authorization);
|
|
7274
|
-
if (fromAuth) return fromAuth;
|
|
7275
|
-
const fromPool = session_pool_default.getAllTokens({ onlyEnabled: true, preferLive: true })[0];
|
|
7276
|
-
return fromPool || void 0;
|
|
7277
|
-
}
|
|
7278
|
-
function getRegionalMaps(region) {
|
|
7279
|
-
if (region === "us") return [IMAGE_MODEL_MAP_US, VIDEO_MODEL_MAP_US];
|
|
7280
|
-
if (region === "hk" || region === "jp" || region === "sg") return [IMAGE_MODEL_MAP_ASIA, VIDEO_MODEL_MAP_ASIA];
|
|
7281
|
-
if (region === "cn") return [IMAGE_MODEL_MAP, VIDEO_MODEL_MAP];
|
|
7282
|
-
return [IMAGE_MODEL_MAP, IMAGE_MODEL_MAP_US, IMAGE_MODEL_MAP_ASIA, VIDEO_MODEL_MAP, VIDEO_MODEL_MAP_US, VIDEO_MODEL_MAP_ASIA];
|
|
7283
|
-
}
|
|
7284
|
-
function resolveRegion(authorization, xRegion) {
|
|
7285
|
-
var _a;
|
|
7286
|
-
const token = resolveToken(authorization);
|
|
7287
|
-
const parsedXRegion = parseRegionCode(xRegion);
|
|
7288
|
-
if (parsedXRegion) return parsedXRegion;
|
|
7289
|
-
if (token) {
|
|
7290
|
-
assertTokenWithoutRegionPrefix(token);
|
|
7291
|
-
const normalizedToken = parseProxyFromToken(token).token;
|
|
7292
|
-
const poolRegion = (_a = session_pool_default.getTokenEntry(normalizedToken)) == null ? void 0 : _a.region;
|
|
7293
|
-
if (poolRegion) return poolRegion;
|
|
7294
|
-
throw new Error("\u7F3A\u5C11 region\u3002token \u672A\u5728 pool \u4E2D\u6CE8\u518C\u65F6\uFF0C/v1/models \u9700\u8981\u63D0\u4F9B\u8BF7\u6C42\u5934 X-Region");
|
|
7295
|
-
}
|
|
7296
|
-
return "cn";
|
|
7297
|
-
}
|
|
7298
|
-
function buildReverseMap(region) {
|
|
7299
|
-
const reverse = {};
|
|
7300
|
-
for (const map of getRegionalMaps(region)) {
|
|
7301
|
-
for (const [modelId, upstreamKey] of Object.entries(map)) {
|
|
7302
|
-
reverse[upstreamKey] = modelId;
|
|
7303
|
-
}
|
|
7304
|
-
}
|
|
7305
|
-
return reverse;
|
|
7306
|
-
}
|
|
7307
|
-
function buildFallbackModels(region) {
|
|
7308
|
-
const maps = getRegionalMaps(region);
|
|
7309
|
-
const modelIds = Array.from(new Set(maps.flatMap((item) => Object.keys(item)))).sort();
|
|
7310
|
-
return modelIds.map((id) => buildModelItem(id));
|
|
7311
|
-
}
|
|
7312
|
-
function makeCacheKey(region) {
|
|
7313
|
-
return `models|${region}`;
|
|
7314
|
-
}
|
|
7315
|
-
function resolveFetchToken(token) {
|
|
7316
|
-
if (!token) return FALLBACK_TOKEN;
|
|
7317
|
-
const normalizedToken = parseProxyFromToken(token).token;
|
|
7318
|
-
assertTokenWithoutRegionPrefix(normalizedToken);
|
|
7319
|
-
return normalizedToken;
|
|
7320
|
-
}
|
|
7321
|
-
function extractCapabilities(item) {
|
|
7322
|
-
const features = Array.isArray(item.feats) ? item.feats.filter((feature) => typeof feature === "string" && feature.length > 0) : [];
|
|
7323
|
-
const options = Array.isArray(item.options) ? item.options.map(
|
|
7324
|
-
(option) => option && typeof option === "object" && typeof option.key === "string" ? option.key : void 0
|
|
7325
|
-
).filter((key) => typeof key === "string" && key.length > 0) : [];
|
|
7326
|
-
return Array.from(/* @__PURE__ */ new Set([...features, ...options]));
|
|
7327
|
-
}
|
|
7328
|
-
async function fetchConfigModelReqKeys(token, region) {
|
|
7329
|
-
const regionInfo = buildRegionInfo(region);
|
|
7330
|
-
const imageConfig = await request("post", "/mweb/v1/get_common_config", token, regionInfo, {
|
|
7331
|
-
data: {},
|
|
7332
|
-
params: { needCache: true, needRefresh: false }
|
|
7333
|
-
});
|
|
7334
|
-
const videoConfig = await request("post", "/mweb/v1/video_generate/get_common_config", token, regionInfo, {
|
|
7335
|
-
data: { scene: "generate_video", params: {} }
|
|
7336
|
-
});
|
|
7337
|
-
const imageModels = Array.isArray(imageConfig == null ? void 0 : imageConfig.model_list) ? imageConfig.model_list.map((item) => {
|
|
7338
|
-
const reqKey = item == null ? void 0 : item.model_req_key;
|
|
7339
|
-
if (typeof reqKey !== "string" || reqKey.length === 0) return void 0;
|
|
7340
|
-
return {
|
|
7341
|
-
reqKey,
|
|
7342
|
-
modelName: typeof (item == null ? void 0 : item.model_name) === "string" ? item.model_name : void 0,
|
|
7343
|
-
modelTip: typeof (item == null ? void 0 : item.model_tip) === "string" ? item.model_tip : void 0,
|
|
7344
|
-
capabilities: extractCapabilities(item)
|
|
7345
|
-
};
|
|
7346
|
-
}).filter((item) => Boolean(item)) : [];
|
|
7347
|
-
const videoModels = Array.isArray(videoConfig == null ? void 0 : videoConfig.model_list) ? videoConfig.model_list.map((item) => {
|
|
7348
|
-
const reqKey = item == null ? void 0 : item.model_req_key;
|
|
7349
|
-
if (typeof reqKey !== "string" || reqKey.length === 0) return void 0;
|
|
7350
|
-
return {
|
|
7351
|
-
reqKey,
|
|
7352
|
-
modelName: typeof (item == null ? void 0 : item.model_name) === "string" ? item.model_name : void 0,
|
|
7353
|
-
modelTip: typeof (item == null ? void 0 : item.model_tip) === "string" ? item.model_tip : void 0,
|
|
7354
|
-
capabilities: extractCapabilities(item)
|
|
7355
|
-
};
|
|
7356
|
-
}).filter((item) => Boolean(item)) : [];
|
|
7357
|
-
return { imageModels, videoModels };
|
|
7358
|
-
}
|
|
7359
|
-
async function getLiveModels(authorization, xRegion) {
|
|
7360
|
-
const region = resolveRegion(authorization, xRegion);
|
|
7361
|
-
const token = resolveToken(authorization);
|
|
7362
|
-
const effectiveToken = resolveFetchToken(token);
|
|
7363
|
-
const cacheKey = makeCacheKey(region);
|
|
7364
|
-
const cached = modelCache.get(cacheKey);
|
|
7365
|
-
if (cached && cached.expiresAt > Date.now()) {
|
|
7366
|
-
return { source: cached.source, data: cached.data };
|
|
7367
|
-
}
|
|
7368
|
-
try {
|
|
7369
|
-
const reverseMap = buildReverseMap(region);
|
|
7370
|
-
const { imageModels, videoModels } = await fetchConfigModelReqKeys(effectiveToken, region);
|
|
7371
|
-
const upstreamModels = [...imageModels, ...videoModels];
|
|
7372
|
-
const metaByModelId = /* @__PURE__ */ new Map();
|
|
7373
|
-
const mapped = upstreamModels.map((model) => {
|
|
7374
|
-
const modelId = reverseMap[model.reqKey];
|
|
7375
|
-
if (modelId && !metaByModelId.has(modelId)) {
|
|
7376
|
-
metaByModelId.set(modelId, model);
|
|
7377
|
-
}
|
|
7378
|
-
return modelId;
|
|
7379
|
-
}).filter((item) => typeof item === "string" && item.length > 0);
|
|
7380
|
-
const modelIds = Array.from(new Set(mapped)).sort();
|
|
7381
|
-
if (modelIds.length === 0) {
|
|
7382
|
-
throw new Error("model_req_key resolved but none matched local reverse map");
|
|
7383
|
-
}
|
|
7384
|
-
const data = modelIds.map((id) => buildModelItem(id, metaByModelId.get(id)));
|
|
7385
|
-
modelCache.set(cacheKey, {
|
|
7386
|
-
expiresAt: Date.now() + CACHE_TTL_MS,
|
|
7387
|
-
source: "upstream",
|
|
7388
|
-
data
|
|
7389
|
-
});
|
|
7390
|
-
return { source: "upstream", data };
|
|
7391
|
-
} catch {
|
|
7392
|
-
const data = buildFallbackModels(region);
|
|
7393
|
-
modelCache.set(cacheKey, {
|
|
7394
|
-
expiresAt: Date.now() + CACHE_TTL_MS,
|
|
7395
|
-
source: "fallback",
|
|
7396
|
-
data
|
|
7397
|
-
});
|
|
7398
|
-
return { source: "fallback", data };
|
|
7399
|
-
}
|
|
7400
|
-
}
|
|
7401
|
-
async function refreshAllTokenModels() {
|
|
7402
|
-
return session_pool_default.refreshAllDynamicCapabilities();
|
|
7403
|
-
}
|
|
7404
|
-
|
|
7405
7478
|
// src/lib/smart-poller.ts
|
|
7406
7479
|
var SmartPoller = class {
|
|
7407
7480
|
pollCount = 0;
|
|
@@ -7428,7 +7501,7 @@ var SmartPoller = class {
|
|
|
7428
7501
|
/**
|
|
7429
7502
|
* 根据状态码计算智能轮询间隔
|
|
7430
7503
|
*/
|
|
7431
|
-
getSmartInterval(status,
|
|
7504
|
+
getSmartInterval(status, _itemCount) {
|
|
7432
7505
|
const baseInterval = this.options.pollInterval;
|
|
7433
7506
|
switch (status) {
|
|
7434
7507
|
case 20:
|
|
@@ -7465,9 +7538,6 @@ var SmartPoller = class {
|
|
|
7465
7538
|
if (status === 30) {
|
|
7466
7539
|
return { shouldExit: true, reason: "\u4EFB\u52A1\u5931\u8D25" };
|
|
7467
7540
|
}
|
|
7468
|
-
if (itemCount >= this.options.expectedItemCount && (status === 10 || status === 50)) {
|
|
7469
|
-
return { shouldExit: true, reason: `\u5DF2\u83B7\u5F97\u5B8C\u6574\u7ED3\u679C\u96C6(${itemCount}/${this.options.expectedItemCount})` };
|
|
7470
|
-
}
|
|
7471
7541
|
if (this.pollCount >= this.options.maxPollCount) {
|
|
7472
7542
|
return { shouldExit: true, reason: "\u8F6E\u8BE2\u6B21\u6570\u8D85\u9650" };
|
|
7473
7543
|
}
|
|
@@ -7484,6 +7554,7 @@ var SmartPoller = class {
|
|
|
7484
7554
|
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}`);
|
|
7485
7555
|
let lastData;
|
|
7486
7556
|
let lastStatus = { status: 20, itemCount: 0 };
|
|
7557
|
+
let exitReason = "";
|
|
7487
7558
|
while (true) {
|
|
7488
7559
|
this.pollCount++;
|
|
7489
7560
|
const elapsedTime = Math.round((Date.now() - this.startTime) / 1e3);
|
|
@@ -7497,6 +7568,7 @@ var SmartPoller = class {
|
|
|
7497
7568
|
}
|
|
7498
7569
|
const { shouldExit, reason } = this.shouldExitPolling(status);
|
|
7499
7570
|
if (shouldExit) {
|
|
7571
|
+
exitReason = reason;
|
|
7500
7572
|
logger_default.info(`\u9000\u51FA\u8F6E\u8BE2: ${reason}, \u6700\u7EC8${this.options.type === "image" ? "\u56FE\u7247" : "\u89C6\u9891"}\u6570\u91CF=${status.itemCount}`);
|
|
7501
7573
|
if (status.status === 30) {
|
|
7502
7574
|
handleGenerationFailure(status.status, status.failCode, historyId, this.options.type, status.itemCount);
|
|
@@ -7508,7 +7580,8 @@ var SmartPoller = class {
|
|
|
7508
7580
|
elapsedTime,
|
|
7509
7581
|
status.status,
|
|
7510
7582
|
status.itemCount,
|
|
7511
|
-
historyId
|
|
7583
|
+
historyId,
|
|
7584
|
+
this.options.type
|
|
7512
7585
|
);
|
|
7513
7586
|
}
|
|
7514
7587
|
break;
|
|
@@ -7552,7 +7625,7 @@ var SmartPoller = class {
|
|
|
7552
7625
|
itemCount: lastStatus.itemCount,
|
|
7553
7626
|
elapsedTime: finalElapsedTime,
|
|
7554
7627
|
pollCount: this.pollCount,
|
|
7555
|
-
exitReason
|
|
7628
|
+
exitReason
|
|
7556
7629
|
};
|
|
7557
7630
|
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)}`);
|
|
7558
7631
|
return { result, data: lastData };
|
|
@@ -7598,17 +7671,20 @@ function extractImageUrls(itemList) {
|
|
|
7598
7671
|
return itemList.map((item, index) => extractImageUrl(item, index)).filter((url) => url !== null);
|
|
7599
7672
|
}
|
|
7600
7673
|
function extractVideoUrl(item) {
|
|
7601
|
-
var _a, _b, _c, _d, _e, _f;
|
|
7602
|
-
if ((_c = (_b = (_a = item == null ? void 0 : item.
|
|
7674
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
7675
|
+
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) {
|
|
7676
|
+
return item.common_attr.transcoded_video.origin.video_url;
|
|
7677
|
+
}
|
|
7678
|
+
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) {
|
|
7603
7679
|
return item.video.transcoded_video.origin.video_url;
|
|
7604
7680
|
}
|
|
7605
|
-
if ((
|
|
7681
|
+
if ((_g = item == null ? void 0 : item.video) == null ? void 0 : _g.play_url) {
|
|
7606
7682
|
return item.video.play_url;
|
|
7607
7683
|
}
|
|
7608
|
-
if ((
|
|
7684
|
+
if ((_h = item == null ? void 0 : item.video) == null ? void 0 : _h.download_url) {
|
|
7609
7685
|
return item.video.download_url;
|
|
7610
7686
|
}
|
|
7611
|
-
if ((
|
|
7687
|
+
if ((_i = item == null ? void 0 : item.video) == null ? void 0 : _i.url) {
|
|
7612
7688
|
return item.video.url;
|
|
7613
7689
|
}
|
|
7614
7690
|
return null;
|
|
@@ -7638,20 +7714,15 @@ async function fetchHighQualityVideoUrl(itemId, refreshToken, regionInfo) {
|
|
|
7638
7714
|
return videoUrl;
|
|
7639
7715
|
}
|
|
7640
7716
|
}
|
|
7641
|
-
const
|
|
7642
|
-
if (
|
|
7643
|
-
logger_default.info(`\u6B63\u5219\u63D0\u53D6\u5230\
|
|
7644
|
-
return
|
|
7645
|
-
}
|
|
7646
|
-
const jimengUrlMatch = responseStr.match(/https:\/\/v[0-9]+-[^"\\]*\.jimeng\.com\/[^"\s\\]+/);
|
|
7647
|
-
if (jimengUrlMatch && jimengUrlMatch[0]) {
|
|
7648
|
-
logger_default.info(`\u6B63\u5219\u63D0\u53D6\u5230jimeng\u89C6\u9891URL: ${jimengUrlMatch[0]}`);
|
|
7649
|
-
return jimengUrlMatch[0];
|
|
7717
|
+
const cdnUrlMatch = responseStr.match(/https:\/\/v[0-9]+-[^"\\]*\.(jimeng|capcut|dreamina)\.com\/[^"\s\\]+/);
|
|
7718
|
+
if (cdnUrlMatch && cdnUrlMatch[0]) {
|
|
7719
|
+
logger_default.info(`\u6B63\u5219\u63D0\u53D6\u5230\u89C6\u9891URL: ${cdnUrlMatch[0]}`);
|
|
7720
|
+
return cdnUrlMatch[0];
|
|
7650
7721
|
}
|
|
7651
|
-
const
|
|
7652
|
-
if (
|
|
7653
|
-
logger_default.info(`\
|
|
7654
|
-
return
|
|
7722
|
+
const vlabUrlMatch = responseStr.match(/https:\/\/v[0-9]+-[^"\\]*\.vlabvod\.com\/[^"\s\\]+/);
|
|
7723
|
+
if (vlabUrlMatch && vlabUrlMatch[0]) {
|
|
7724
|
+
logger_default.info(`\u6B63\u5219\u63D0\u53D6\u5230\u89C6\u9891URL: ${vlabUrlMatch[0]}`);
|
|
7725
|
+
return vlabUrlMatch[0];
|
|
7655
7726
|
}
|
|
7656
7727
|
logger_default.warn(`\u672A\u80FD\u4ECEget_local_item_list\u54CD\u5E94\u4E2D\u63D0\u53D6\u5230\u89C6\u9891URL`);
|
|
7657
7728
|
return null;
|
|
@@ -8052,7 +8123,7 @@ async function uploadImageBuffer(imageBuffer, refreshToken, regionInfo) {
|
|
|
8052
8123
|
"Authorization": auth,
|
|
8053
8124
|
"Connection": "keep-alive",
|
|
8054
8125
|
"Content-CRC32": crc32,
|
|
8055
|
-
"Content-Disposition": 'attachment; filename="
|
|
8126
|
+
"Content-Disposition": 'attachment; filename="upload.bin"',
|
|
8056
8127
|
"Content-Type": "application/octet-stream",
|
|
8057
8128
|
"Origin": origin,
|
|
8058
8129
|
"Referer": RegionUtils.getRefererPath(regionInfo),
|
|
@@ -8552,7 +8623,7 @@ async function generateImageComposition(_model, prompt, images, {
|
|
|
8552
8623
|
abilityName: "byte_edit",
|
|
8553
8624
|
strength: sampleStrength,
|
|
8554
8625
|
source: {
|
|
8555
|
-
imageUrl: `blob
|
|
8626
|
+
imageUrl: `blob:${INTERNATIONAL_FRONTEND_ORIGIN}/${util_default.uuid()}`
|
|
8556
8627
|
}
|
|
8557
8628
|
}));
|
|
8558
8629
|
const metricsExtra = buildMetricsExtra({
|
|
@@ -8587,7 +8658,7 @@ async function generateImageComposition(_model, prompt, images, {
|
|
|
8587
8658
|
draftContent,
|
|
8588
8659
|
metricsExtra
|
|
8589
8660
|
});
|
|
8590
|
-
const imageReferer = regionInfo.isCN ?
|
|
8661
|
+
const imageReferer = regionInfo.isCN ? `${BASE_URL_CN}/ai-tool/generate?type=image` : `${INTERNATIONAL_FRONTEND_ORIGIN}/ai-tool/generate?type=image`;
|
|
8591
8662
|
const { aigc_data } = await request(
|
|
8592
8663
|
"post",
|
|
8593
8664
|
"/mweb/v1/aigc_draft/generate",
|
|
@@ -8751,7 +8822,7 @@ async function generateImagesInternal(_model, prompt, {
|
|
|
8751
8822
|
draftContent,
|
|
8752
8823
|
metricsExtra
|
|
8753
8824
|
});
|
|
8754
|
-
const imageReferer = regionInfo.isCN ?
|
|
8825
|
+
const imageReferer = regionInfo.isCN ? `${BASE_URL_CN}/ai-tool/generate?type=image` : `${INTERNATIONAL_FRONTEND_ORIGIN}/ai-tool/generate?type=image`;
|
|
8755
8826
|
const { aigc_data } = await request(
|
|
8756
8827
|
"post",
|
|
8757
8828
|
"/mweb/v1/aigc_draft/generate",
|
|
@@ -8873,7 +8944,7 @@ async function generateJimeng4xMultiImages(_model, prompt, {
|
|
|
8873
8944
|
draftContent,
|
|
8874
8945
|
metricsExtra
|
|
8875
8946
|
});
|
|
8876
|
-
const imageReferer = regionInfo.isCN ?
|
|
8947
|
+
const imageReferer = regionInfo.isCN ? `${BASE_URL_CN}/ai-tool/generate?type=image` : `${INTERNATIONAL_FRONTEND_ORIGIN}/ai-tool/generate?type=image`;
|
|
8877
8948
|
const { aigc_data } = await request(
|
|
8878
8949
|
"post",
|
|
8879
8950
|
"/mweb/v1/aigc_draft/generate",
|
|
@@ -9045,7 +9116,7 @@ async function upscaleImage(_model, image, {
|
|
|
9045
9116
|
draftContent,
|
|
9046
9117
|
metricsExtra
|
|
9047
9118
|
});
|
|
9048
|
-
const imageReferer = regionInfo.isCN ?
|
|
9119
|
+
const imageReferer = regionInfo.isCN ? `${BASE_URL_CN}/ai-tool/generate?type=image` : `${INTERNATIONAL_FRONTEND_ORIGIN}/ai-tool/generate?type=image`;
|
|
9049
9120
|
const { aigc_data } = await request(
|
|
9050
9121
|
"post",
|
|
9051
9122
|
"/mweb/v1/aigc_draft/generate",
|
|
@@ -10000,7 +10071,8 @@ async function generateVideo(_model, prompt, {
|
|
|
10000
10071
|
isDefaultSeed: 1,
|
|
10001
10072
|
originSubmitId,
|
|
10002
10073
|
isRegenerate: false,
|
|
10003
|
-
enterFrom: "
|
|
10074
|
+
enterFrom: "use_bgimage_prompt",
|
|
10075
|
+
position: "page_bottom_box",
|
|
10004
10076
|
functionMode: flFunctionMode,
|
|
10005
10077
|
sceneOptions: JSON.stringify([sceneOption])
|
|
10006
10078
|
});
|
|
@@ -10094,7 +10166,7 @@ async function generateVideo(_model, prompt, {
|
|
|
10094
10166
|
}
|
|
10095
10167
|
};
|
|
10096
10168
|
}
|
|
10097
|
-
const videoReferer = regionInfo.isCN ?
|
|
10169
|
+
const videoReferer = regionInfo.isCN ? `${BASE_URL_CN}/ai-tool/generate?type=video` : `${INTERNATIONAL_FRONTEND_ORIGIN}/ai-tool/generate?type=video`;
|
|
10098
10170
|
const { aigc_data } = await request(
|
|
10099
10171
|
"post",
|
|
10100
10172
|
"/mweb/v1/aigc_draft/generate",
|
|
@@ -10125,7 +10197,7 @@ async function generateVideo(_model, prompt, {
|
|
|
10125
10197
|
timeoutSeconds: pollerOptions.timeoutSeconds
|
|
10126
10198
|
});
|
|
10127
10199
|
const { result: pollingResult, data: finalHistoryData } = await poller.poll(async () => {
|
|
10128
|
-
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2;
|
|
10200
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l, _m, _n, _o;
|
|
10129
10201
|
pollAttempts++;
|
|
10130
10202
|
const result = await request("post", "/mweb/v1/get_history_by_ids", refreshToken, regionInfo, {
|
|
10131
10203
|
data: {
|
|
@@ -10150,7 +10222,7 @@ async function generateVideo(_model, prompt, {
|
|
|
10150
10222
|
const currentItemList = historyData.item_list || [];
|
|
10151
10223
|
const finishTime = ((_a2 = historyData.task) == null ? void 0 : _a2.finish_time) || 0;
|
|
10152
10224
|
if (currentItemList.length > 0) {
|
|
10153
|
-
const tempVideoUrl = ((_e2 = (_d2 = (_c2 = (_b2 = currentItemList[0]) == null ? void 0 : _b2.
|
|
10225
|
+
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);
|
|
10154
10226
|
if (tempVideoUrl) {
|
|
10155
10227
|
logger_default.info(`\u68C0\u6D4B\u5230\u89C6\u9891URL: ${tempVideoUrl}`);
|
|
10156
10228
|
}
|
|
@@ -10193,6 +10265,7 @@ async function generateVideo(_model, prompt, {
|
|
|
10193
10265
|
export {
|
|
10194
10266
|
environment_default,
|
|
10195
10267
|
config_default,
|
|
10268
|
+
maskToken,
|
|
10196
10269
|
util_default,
|
|
10197
10270
|
logger_default,
|
|
10198
10271
|
DEFAULT_IMAGE_MODEL,
|
|
@@ -10201,9 +10274,9 @@ export {
|
|
|
10201
10274
|
getCredit,
|
|
10202
10275
|
receiveCredit,
|
|
10203
10276
|
getTokenLiveStatus,
|
|
10204
|
-
session_pool_default,
|
|
10205
10277
|
getLiveModels,
|
|
10206
10278
|
refreshAllTokenModels,
|
|
10279
|
+
session_pool_default,
|
|
10207
10280
|
getTaskResponse,
|
|
10208
10281
|
waitForTaskResponse,
|
|
10209
10282
|
getAssetList,
|
|
@@ -10225,4 +10298,4 @@ lodash/lodash.js:
|
|
|
10225
10298
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
10226
10299
|
*)
|
|
10227
10300
|
*/
|
|
10228
|
-
//# sourceMappingURL=chunk-
|
|
10301
|
+
//# sourceMappingURL=chunk-ZMTQQZFH.js.map
|