@lingjingai/lj-awb-cli 0.3.15 → 0.4.0
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 +28 -27
- package/build/_shared.mjs +130 -0
- package/build/build.mjs +3 -0
- package/build/pre-publish.mjs +57 -0
- package/build/pre.mjs +8 -107
- package/build/prod.mjs +9 -78
- package/install.mjs +1 -0
- package/package.json +8 -3
- package/packages/awb-cli/README.md +0 -3
- package/packages/awb-cli/package.json +2 -2
- package/packages/awb-core/package.json +6 -2
- package/packages/awb-core/src/api.js +33 -64
- package/packages/awb-core/src/artifact.js +75 -6
- package/packages/awb-core/src/auth.js +1 -1
- package/packages/awb-core/src/commands.js +279 -118
- package/packages/awb-core/src/common.js +3 -2
- package/packages/awb-core/src/output.js +2310 -106
- package/packages/awb-core/src/services.js +855 -113
- package/packages/awb-core/src/standalone.js +841 -242
- package/skills/lj-awb/SKILL.md +84 -74
- package/skills/lj-awb/VERSION +1 -1
- package/skills/lj-awb/compat.json +3 -3
- package/skills/lj-awb/modules/account.md +20 -7
- package/skills/lj-awb/modules/artifact/asset.md +64 -0
- package/skills/lj-awb/modules/artifact/clip.md +65 -0
- package/skills/lj-awb/modules/artifact/script.md +37 -0
- package/skills/lj-awb/modules/artifact/video.md +65 -0
- package/skills/lj-awb/modules/artifact.md +31 -52
- package/skills/lj-awb/modules/asset.md +50 -11
- package/skills/lj-awb/modules/auth.md +10 -4
- package/skills/lj-awb/modules/create-contract.md +21 -12
- package/skills/lj-awb/modules/create.md +37 -0
- package/skills/lj-awb/modules/credits.md +6 -0
- package/skills/lj-awb/modules/driver.md +125 -0
- package/skills/lj-awb/modules/evals.md +84 -36
- package/skills/lj-awb/modules/image.md +19 -12
- package/skills/lj-awb/modules/model.md +31 -31
- package/skills/lj-awb/modules/project.md +7 -0
- package/skills/lj-awb/modules/subject.md +28 -7
- package/skills/lj-awb/modules/task-manual.md +32 -28
- package/skills/lj-awb/modules/task.md +70 -8
- package/skills/lj-awb/modules/upload.md +16 -2
- package/skills/lj-awb/modules/video.md +30 -28
- package/skills/lj-awb/modules/workflows.md +232 -169
- package/skills/lj-awb/references/error-codes.md +109 -0
- package/skills/lj-awb/references/model-options-read.md +19 -12
- package/skills/lj-awb/references/output-fields.md +118 -0
|
@@ -46,6 +46,21 @@ const REQUEST_SOURCE_CLI = 'LINGJING_AWB_CLI';
|
|
|
46
46
|
const DEFAULT_TASK_RECORD_FILE_ENV = process.env.LINGJING_AWB_TASK_RECORD_FILE || process.env.AWB_TASK_RECORD_FILE;
|
|
47
47
|
const execFileAsync = promisify(execFile);
|
|
48
48
|
const COMMON_IMAGE_FORMATS = new Set(['jpg', 'jpeg', 'jfif', 'png', 'webp']);
|
|
49
|
+
const REMOTE_VOICE_DOWNLOAD_TIMEOUT_MS = 30_000;
|
|
50
|
+
const REMOTE_VOICE_DOWNLOAD_MAX_BYTES = 100 * 1024 * 1024;
|
|
51
|
+
const REMOTE_VOICE_MIME_TYPES = new Set([
|
|
52
|
+
'audio/mpeg',
|
|
53
|
+
'audio/wav',
|
|
54
|
+
'audio/x-wav',
|
|
55
|
+
'audio/mp4',
|
|
56
|
+
'audio/aac',
|
|
57
|
+
'audio/ogg',
|
|
58
|
+
'video/mp4',
|
|
59
|
+
]);
|
|
60
|
+
const REMOTE_VOICE_EXTENSIONS = new Set(['.mp3', '.wav', '.m4a', '.aac', '.ogg', '.mp4']);
|
|
61
|
+
const ASSET_PLATFORM_CODES = ['JIMENG', 'BYTEPLUS'];
|
|
62
|
+
const ASSET_PLATFORM_CODE_SET = new Set(ASSET_PLATFORM_CODES);
|
|
63
|
+
const ASSET_PLATFORM_HINT = ASSET_PLATFORM_CODES.join('|');
|
|
49
64
|
|
|
50
65
|
export function normalizeUserInfo(payload) {
|
|
51
66
|
const data = payload && typeof payload === 'object' ? payload : {};
|
|
@@ -371,7 +386,6 @@ export async function doctor(kwargs = {}) {
|
|
|
371
386
|
},
|
|
372
387
|
origins: {
|
|
373
388
|
apiOrigin: API_ORIGIN,
|
|
374
|
-
assetEditOrigin: awbApi.ASSET_EDIT_ORIGIN,
|
|
375
389
|
},
|
|
376
390
|
auth: summarizeAuth(auth, authContext.accessKeyInfo),
|
|
377
391
|
paths: {
|
|
@@ -666,6 +680,31 @@ function modelListMetadata(kind, paramKeys = [], rulesByKey = new Map()) {
|
|
|
666
680
|
};
|
|
667
681
|
}
|
|
668
682
|
|
|
683
|
+
function normalizeRateValue(value) {
|
|
684
|
+
if (value === undefined || value === null || value === '') return null;
|
|
685
|
+
const text = String(value).trim();
|
|
686
|
+
const isPercent = text.endsWith('%');
|
|
687
|
+
const parsed = Number(isPercent ? text.slice(0, -1) : text);
|
|
688
|
+
if (!Number.isFinite(parsed)) return null;
|
|
689
|
+
const rate = isPercent || parsed > 1 ? parsed / 100 : parsed;
|
|
690
|
+
if (rate < 0 || rate > 1) return null;
|
|
691
|
+
return rate;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function modelSuccessRate(item = {}) {
|
|
695
|
+
const ext = item?.modelExtInfo || {};
|
|
696
|
+
return normalizeRateValue(
|
|
697
|
+
item?.successRate
|
|
698
|
+
?? item?.success_rate
|
|
699
|
+
?? item?.successRatio
|
|
700
|
+
?? item?.success_ratio
|
|
701
|
+
?? ext?.successRate
|
|
702
|
+
?? ext?.success_rate
|
|
703
|
+
?? ext?.successRatio
|
|
704
|
+
?? ext?.success_ratio,
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
|
|
669
708
|
function normalizeModelRows(payload, kind, options = {}) {
|
|
670
709
|
const includeRaw = Boolean(options.includeRaw);
|
|
671
710
|
const includeInternal = Boolean(options.includeInternal);
|
|
@@ -683,10 +722,12 @@ function normalizeModelRows(payload, kind, options = {}) {
|
|
|
683
722
|
const row = compactRecord({
|
|
684
723
|
modelGroupCode,
|
|
685
724
|
displayName: item?.modelName ?? item?.name ?? item?.label ?? null,
|
|
725
|
+
modelDesc: item?.modelDesc ?? null,
|
|
686
726
|
provider: item?.provider ?? item?.vendor ?? item?.supplier ?? item?.componyName ?? null,
|
|
687
727
|
enabled: item?.enabled ?? item?.available ?? item?.status ?? null,
|
|
688
728
|
modelStatus: item?.modelStatus ?? null,
|
|
689
729
|
taskQueueNum: item?.taskQueueNum ?? null,
|
|
730
|
+
successRate: modelSuccessRate(item),
|
|
690
731
|
feeCalcType: item?.feeCalcType ?? item?.feeType ?? null,
|
|
691
732
|
inputModes: metadata.inputModes,
|
|
692
733
|
params: metadata.controls,
|
|
@@ -720,6 +761,44 @@ export async function listModels(kind, kwargs = {}) {
|
|
|
720
761
|
return { usage, models };
|
|
721
762
|
}
|
|
722
763
|
|
|
764
|
+
function requireAssetPlatform(value, options = {}) {
|
|
765
|
+
const flag = options.flag || '--platform';
|
|
766
|
+
const platform = trimToNull(value);
|
|
767
|
+
if (!platform) {
|
|
768
|
+
throw argumentError(`缺少参数:${flag}`, `素材加白平台必须显式传入 ${ASSET_PLATFORM_HINT},不要依赖默认平台。`);
|
|
769
|
+
}
|
|
770
|
+
if (!ASSET_PLATFORM_CODE_SET.has(platform)) {
|
|
771
|
+
throw argumentError(`不支持的平台:${platform}`, `只接受 ${ASSET_PLATFORM_HINT};请使用 model asset-review-models 查看模型支持的平台。`);
|
|
772
|
+
}
|
|
773
|
+
return platform;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function optionalAssetPlatform(value) {
|
|
777
|
+
if (value == null || value === '') return null;
|
|
778
|
+
return requireAssetPlatform(value);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function normalizeAssetReviewModelRecord(item = {}) {
|
|
782
|
+
return compactRecord({
|
|
783
|
+
modelGroupCode: item?.modelGroupCode ?? item?.groupCode ?? null,
|
|
784
|
+
platform: item?.platform ?? null,
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
export async function assetReviewModels(kwargs = {}) {
|
|
789
|
+
const modelGroupCode = trimToNull(kwargs.modelGroupCode);
|
|
790
|
+
const platform = optionalAssetPlatform(kwargs.platform);
|
|
791
|
+
const payload = await awbApi.fetchAssetReviewModels();
|
|
792
|
+
const models = normalizeRows(payload)
|
|
793
|
+
.map((item) => normalizeAssetReviewModelRecord(item))
|
|
794
|
+
.filter((item) => !modelGroupCode || item.modelGroupCode === modelGroupCode)
|
|
795
|
+
.filter((item) => !platform || item.platform === platform);
|
|
796
|
+
return {
|
|
797
|
+
models,
|
|
798
|
+
...(toBool(kwargs.includeRaw) ? { raw: payload } : {}),
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
|
|
723
802
|
async function findModelGroup(modelGroupCode, options = {}) {
|
|
724
803
|
const includeRaw = Boolean(options.includeRaw);
|
|
725
804
|
const [imageResult, videoResult] = await Promise.allSettled([
|
|
@@ -864,6 +943,68 @@ function normalizeModelConstraints(constraintSchema = [], taskKind = 'image') {
|
|
|
864
943
|
}).filter((constraint) => constraint.target || constraint.targetConfigCode);
|
|
865
944
|
}
|
|
866
945
|
|
|
946
|
+
function resourceConstraintTarget(mediaType, usage = 'reference') {
|
|
947
|
+
const media = String(mediaType || '').toLowerCase();
|
|
948
|
+
const normalizedUsage = String(usage || 'reference');
|
|
949
|
+
return media ? `resource.${media}.${normalizedUsage}` : '';
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function countRangeValue(minCount, maxCount) {
|
|
953
|
+
if (minCount != null && maxCount != null && minCount === maxCount) return String(minCount);
|
|
954
|
+
if (minCount != null && maxCount != null) return `${minCount}..${maxCount}`;
|
|
955
|
+
if (minCount != null) return `>=${minCount}`;
|
|
956
|
+
if (maxCount != null) return `<=${maxCount}`;
|
|
957
|
+
return undefined;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
function normalizeLimitProfileCondition(condition = {}) {
|
|
961
|
+
const mediaType = String(condition?.mediaType || '').toUpperCase();
|
|
962
|
+
const usage = condition?.usage || 'reference';
|
|
963
|
+
const minCount = ruleNumber(condition?.minCount);
|
|
964
|
+
const maxCount = ruleNumber(condition?.maxCount);
|
|
965
|
+
const target = resourceConstraintTarget(mediaType, usage);
|
|
966
|
+
return compactRecord({
|
|
967
|
+
key: target ? `${target}.count` : undefined,
|
|
968
|
+
mediaType,
|
|
969
|
+
usage,
|
|
970
|
+
minCount,
|
|
971
|
+
maxCount,
|
|
972
|
+
value: countRangeValue(minCount, maxCount),
|
|
973
|
+
meaning: 'count',
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
function normalizeResourceLimitProfileConstraints(options = []) {
|
|
978
|
+
const constraints = [];
|
|
979
|
+
for (const option of Array.isArray(options) ? options : []) {
|
|
980
|
+
const profiles = Array.isArray(option?.rules?.limitProfiles) ? option.rules.limitProfiles : [];
|
|
981
|
+
for (const [profileIndex, profile] of profiles.entries()) {
|
|
982
|
+
const condition = normalizeLimitProfileCondition(profile?.condition);
|
|
983
|
+
const overrides = Array.isArray(profile?.overrides) ? profile.overrides : [];
|
|
984
|
+
for (const [overrideIndex, override] of overrides.entries()) {
|
|
985
|
+
const mediaType = String(override?.mediaType || '').toUpperCase();
|
|
986
|
+
if (!mediaType) continue;
|
|
987
|
+
const usage = override?.usage || condition.usage || 'reference';
|
|
988
|
+
const limits = compactRecord({
|
|
989
|
+
usage,
|
|
990
|
+
...normalizeMediaRule({ ...override, mediaType }),
|
|
991
|
+
});
|
|
992
|
+
constraints.push(compactRecord({
|
|
993
|
+
id: `${option.paramKey || 'resource'}.limitProfiles[${profileIndex}].overrides[${overrideIndex}]`,
|
|
994
|
+
name: '素材联动限制',
|
|
995
|
+
target: resourceConstraintTarget(mediaType, usage),
|
|
996
|
+
targetConfigCode: option.paramKey,
|
|
997
|
+
effect: 'resource_limit_overrides',
|
|
998
|
+
priority: option.rank,
|
|
999
|
+
conditions: condition.key ? [condition] : [],
|
|
1000
|
+
limits,
|
|
1001
|
+
}));
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return constraints;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
867
1008
|
function resourceUsageList(usage) {
|
|
868
1009
|
return (Array.isArray(usage) ? usage : [usage])
|
|
869
1010
|
.map((item) => trimToNull(item))
|
|
@@ -898,9 +1039,9 @@ function resourceSourceKindForValidation(detail = {}) {
|
|
|
898
1039
|
}
|
|
899
1040
|
|
|
900
1041
|
function sourceAllowedByRule(rule = {}, sourceKind) {
|
|
901
|
-
const
|
|
902
|
-
if (!
|
|
903
|
-
return
|
|
1042
|
+
const shapes = Array.isArray(rule.valueShapes) ? rule.valueShapes : [];
|
|
1043
|
+
if (!shapes.length) return true;
|
|
1044
|
+
return shapes.includes(sourceKind);
|
|
904
1045
|
}
|
|
905
1046
|
|
|
906
1047
|
function resourceFormatForValidation(detail = {}) {
|
|
@@ -1033,7 +1174,7 @@ function assertResourceShapeAgainstModel(resourceDetails = [], resourceRules = [
|
|
|
1033
1174
|
if (!sourceAllowedByRule(rule, sourceKind)) {
|
|
1034
1175
|
throw argumentError(
|
|
1035
1176
|
`模型不支持 ${resourceText(resource)} 的来源:${sourceKind}`,
|
|
1036
|
-
|
|
1177
|
+
`该资源允许的 value 形状:${(rule.valueShapes || []).join(', ') || '未限制'}。`,
|
|
1037
1178
|
);
|
|
1038
1179
|
}
|
|
1039
1180
|
const format = resourceFormatForValidation(detail);
|
|
@@ -1108,6 +1249,58 @@ function assertResourceCountsAgainstModel(resourceDetails = [], resourceRules =
|
|
|
1108
1249
|
}
|
|
1109
1250
|
}
|
|
1110
1251
|
|
|
1252
|
+
function resourceCountForCondition(resourceDetails = [], condition = {}) {
|
|
1253
|
+
return resourceDetails.filter((detail) => {
|
|
1254
|
+
const resource = detail.resource || {};
|
|
1255
|
+
if (condition.mediaType && resourceMediaType(resource) !== String(condition.mediaType).toUpperCase()) return false;
|
|
1256
|
+
if (condition.usage && resource.usage !== condition.usage) return false;
|
|
1257
|
+
return true;
|
|
1258
|
+
}).length;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
function resourceLimitConditionMatches(resourceDetails = [], condition = {}) {
|
|
1262
|
+
if (condition.meaning !== 'count') return false;
|
|
1263
|
+
const count = resourceCountForCondition(resourceDetails, condition);
|
|
1264
|
+
if (condition.minCount != null && count < condition.minCount) return false;
|
|
1265
|
+
if (condition.maxCount != null && count > condition.maxCount) return false;
|
|
1266
|
+
return true;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
function validationResourceLimitOverrides(limits = {}) {
|
|
1270
|
+
const validatesResourceDuration = resourceUsageList(limits.usage).includes('keyframe');
|
|
1271
|
+
return compactRecord({
|
|
1272
|
+
mediaType: limits.mediaType,
|
|
1273
|
+
usage: limits.usage,
|
|
1274
|
+
fileTypes: limits.fileTypes,
|
|
1275
|
+
minFiles: limits.minFiles,
|
|
1276
|
+
maxFiles: limits.maxFiles,
|
|
1277
|
+
maxSizeKB: limits.maxSizeKB,
|
|
1278
|
+
minItems: limits.minItems,
|
|
1279
|
+
maxItems: limits.maxItems,
|
|
1280
|
+
supportLastFrameOnly: limits.supportLastFrameOnly,
|
|
1281
|
+
minDurationMs: validatesResourceDuration ? limits.minDurationMs : undefined,
|
|
1282
|
+
maxDurationMs: validatesResourceDuration ? limits.maxDurationMs : undefined,
|
|
1283
|
+
maxPromptLength: validatesResourceDuration ? limits.maxPromptLength : undefined,
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
function applyResourceLimitProfileConstraints(resourceRules = [], constraints = [], resourceDetails = []) {
|
|
1288
|
+
const effective = resourceRules.map((rule) => ({ ...rule }));
|
|
1289
|
+
const profiles = constraints.filter((constraint) => constraint.effect === 'resource_limit_overrides' && constraint.limits);
|
|
1290
|
+
for (const profile of profiles) {
|
|
1291
|
+
const conditions = Array.isArray(profile.conditions) ? profile.conditions : [];
|
|
1292
|
+
if (conditions.length && !conditions.every((condition) => resourceLimitConditionMatches(resourceDetails, condition))) continue;
|
|
1293
|
+
const validationLimits = validationResourceLimitOverrides(profile.limits);
|
|
1294
|
+
if (!Object.keys(validationLimits).some((key) => !['mediaType', 'usage'].includes(key))) continue;
|
|
1295
|
+
const index = effective.findIndex((rule) => (
|
|
1296
|
+
String(rule.mediaType || '').toUpperCase() === String(validationLimits.mediaType || '').toUpperCase()
|
|
1297
|
+
&& resourceUsageList(rule.usage).includes(validationLimits.usage || 'reference')
|
|
1298
|
+
));
|
|
1299
|
+
if (index >= 0) effective[index] = compactRecord({ ...effective[index], ...validationLimits });
|
|
1300
|
+
}
|
|
1301
|
+
return effective;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1111
1304
|
function promptParamValue(promptParams = {}, key) {
|
|
1112
1305
|
if (key === 'duration') return promptParams.duration;
|
|
1113
1306
|
if (key === 'generateNum') return promptParams.generate_num;
|
|
@@ -1186,9 +1379,10 @@ async function validateCreateRequestAgainstModel(kind, modelGroupCode, promptPar
|
|
|
1186
1379
|
}
|
|
1187
1380
|
const params = modelOptionParams(context.options, context.taskKind);
|
|
1188
1381
|
const resources = modelOptionsResources(context.inputModes);
|
|
1382
|
+
const effectiveResources = applyResourceLimitProfileConstraints(resources, context.constraints, resourceDetails);
|
|
1189
1383
|
assertParamsAgainstModel(promptParams, params, context.constraints);
|
|
1190
|
-
assertResourceShapeAgainstModel(resourceDetails,
|
|
1191
|
-
assertResourceCountsAgainstModel(resourceDetails,
|
|
1384
|
+
assertResourceShapeAgainstModel(resourceDetails, effectiveResources);
|
|
1385
|
+
assertResourceCountsAgainstModel(resourceDetails, effectiveResources);
|
|
1192
1386
|
if (kind === 'video') {
|
|
1193
1387
|
const supportedIntents = createSpecSupportedIntents(context.inputModes, context.taskKind);
|
|
1194
1388
|
const inputRequirement = createSpecInputRequirement(context.taskKind, context.inputModes, supportedIntents);
|
|
@@ -1221,12 +1415,16 @@ async function loadModelOptionContext(modelGroupCode, options = {}) {
|
|
|
1221
1415
|
const constraintSchema = options.includeConstraintSchema
|
|
1222
1416
|
? await fetchModelConstraintSchema(rawModel, modelGroupCode)
|
|
1223
1417
|
: [];
|
|
1418
|
+
const constraints = [
|
|
1419
|
+
...normalizeModelConstraints(constraintSchema, taskKind),
|
|
1420
|
+
...normalizeResourceLimitProfileConstraints(mergedOptions),
|
|
1421
|
+
];
|
|
1224
1422
|
return {
|
|
1225
1423
|
rawModel,
|
|
1226
1424
|
model: modelSummaryFromRaw(rawModel, modelGroupCode, taskKind),
|
|
1227
1425
|
options: mergedOptions,
|
|
1228
1426
|
constraintSchema,
|
|
1229
|
-
constraints
|
|
1427
|
+
constraints,
|
|
1230
1428
|
optionKeys,
|
|
1231
1429
|
rulesByKey,
|
|
1232
1430
|
taskKind,
|
|
@@ -1759,7 +1957,7 @@ function createSpecResourceRequirements(inputModes) {
|
|
|
1759
1957
|
intent: item.intent,
|
|
1760
1958
|
resource: item.requiredResources,
|
|
1761
1959
|
syntax: item.resourceSyntax,
|
|
1762
|
-
|
|
1960
|
+
valueShapes: item.sourceKinds,
|
|
1763
1961
|
...item.resourceLimits,
|
|
1764
1962
|
promptBinding: item.promptBinding,
|
|
1765
1963
|
constraints: item.resourceConstraints,
|
|
@@ -1898,7 +2096,7 @@ function createSpecValidationRules(taskKind) {
|
|
|
1898
2096
|
];
|
|
1899
2097
|
if (taskKind === 'video') {
|
|
1900
2098
|
rules.splice(4, 0, 'reference_key 仅用于视频 reference 资源的可选 prompt 占位符绑定;prompt 中出现 <<<key>>> 时,必须有同名 reference 资源。');
|
|
1901
|
-
rules.push('subject reference 必须使用 asset:<externalId>,externalId 应来自 subject
|
|
2099
|
+
rules.push('subject reference 必须使用 asset:<externalId>,externalId 应来自 create subject + create subject-wait。');
|
|
1902
2100
|
} else {
|
|
1903
2101
|
rules.push('图片任务 resources 只接受 image reference,且不接受 reference_key 或 <<<key>>>;请用自然 prompt 描述图一、图二、参考图、主体等映射。');
|
|
1904
2102
|
}
|
|
@@ -1907,8 +2105,8 @@ function createSpecValidationRules(taskKind) {
|
|
|
1907
2105
|
|
|
1908
2106
|
function createSpecPreflight(taskKind) {
|
|
1909
2107
|
const modelListCommand = taskKind === 'image' ? 'model image-models' : 'model video-models';
|
|
1910
|
-
const feeCommand = taskKind === 'image' ? 'image
|
|
1911
|
-
const createCommand = taskKind === 'image' ? 'image
|
|
2108
|
+
const feeCommand = taskKind === 'image' ? 'create image-fee' : 'create video-fee';
|
|
2109
|
+
const createCommand = taskKind === 'image' ? 'create image' : 'create video';
|
|
1912
2110
|
return [
|
|
1913
2111
|
'doctor --verify',
|
|
1914
2112
|
`${modelListCommand} --model <keyword>`,
|
|
@@ -1927,26 +2125,26 @@ function createSpecExamples(taskKind, supportedIntents) {
|
|
|
1927
2125
|
const examples = [];
|
|
1928
2126
|
const hasIntent = (mode) => supportedIntents.some((item) => item.mode === mode);
|
|
1929
2127
|
if (taskKind === 'image') {
|
|
1930
|
-
if (hasIntent('prompt_only')) examples.push('lj-awb image
|
|
1931
|
-
if (hasIntent('reference')) examples.push('lj-awb image
|
|
2128
|
+
if (hasIntent('prompt_only')) examples.push('lj-awb create image --model-group-code <code> --prompt "品牌吉祥物表情包四宫格" --ratio 1:1 --quality 1K --dry-run');
|
|
2129
|
+
if (hasIntent('reference')) examples.push('lj-awb create image --model-group-code <code> --prompt "保持参考图主体,生成海报" --resource image:reference=./ref.png --dry-run');
|
|
1932
2130
|
} else {
|
|
1933
|
-
if (hasIntent('prompt_only')) examples.push('lj-awb video
|
|
2131
|
+
if (hasIntent('prompt_only')) examples.push('lj-awb create video --model-group-code <code> --prompt "机器人站在白色展台中央,缓慢转身" --duration 6 --dry-run');
|
|
1934
2132
|
if (hasIntent('reference')) {
|
|
1935
2133
|
const referenceIntent = supportedIntents.find((item) => item.mode === 'reference');
|
|
1936
|
-
examples.push('lj-awb video
|
|
2134
|
+
examples.push('lj-awb create video --model-group-code <code> --prompt "人物转身看向镜头" --resource image:reference=./hero.png --duration 5 --dry-run');
|
|
1937
2135
|
if (referenceIntent?.resourceSyntax?.some((item) => String(item).startsWith('audio:reference'))) {
|
|
1938
|
-
examples.push('lj-awb video
|
|
2136
|
+
examples.push('lj-awb create video --model-group-code <code> --prompt "让 <<<hero>>> 跟随音乐节奏转身" --resource image:reference:hero=./hero.png --resource audio:reference=./music.mp3 --duration 5 --dry-run');
|
|
1939
2137
|
}
|
|
1940
2138
|
}
|
|
1941
2139
|
if (hasIntent('frames')) {
|
|
1942
2140
|
const framesIntent = supportedIntents.find((item) => item.mode === 'frames');
|
|
1943
|
-
examples.push('lj-awb video
|
|
1944
|
-
examples.push('lj-awb video
|
|
2141
|
+
examples.push('lj-awb create video --model-group-code <code> --prompt "镜头缓慢推进" --resource image:first_frame=./first.png --duration 5 --dry-run');
|
|
2142
|
+
examples.push('lj-awb create video --model-group-code <code> --prompt "镜头缓慢推进" --resource image:first_frame=asset:<assetId> --duration 5 --dry-run');
|
|
1945
2143
|
if (framesIntent?.resourceUsages?.includes('last_frame')) {
|
|
1946
|
-
examples.push('lj-awb video
|
|
2144
|
+
examples.push('lj-awb create video --model-group-code <code> --prompt "从第一张过渡到第二张" --resource image:first_frame=./first.png --resource image:last_frame=./last.png --duration 5 --dry-run');
|
|
1947
2145
|
}
|
|
1948
2146
|
}
|
|
1949
|
-
if (hasIntent('storyboard')) examples.push('lj-awb video
|
|
2147
|
+
if (hasIntent('storyboard')) examples.push('lj-awb create video --model-group-code <code> --resources-json ./storyboard.json --duration 5 --dry-run');
|
|
1950
2148
|
}
|
|
1951
2149
|
return examples;
|
|
1952
2150
|
}
|
|
@@ -2019,6 +2217,7 @@ function modelOptionsResources(inputModes = []) {
|
|
|
2019
2217
|
mode: 'frames',
|
|
2020
2218
|
mediaType: 'IMAGE',
|
|
2021
2219
|
usage: supportedFrameMode.optionResourceUsages,
|
|
2220
|
+
valueShapes: supportedFrameMode.sourceKinds,
|
|
2022
2221
|
sources: supportedFrameMode.sourceKinds,
|
|
2023
2222
|
...supportedFrameMode.optionResourceLimits,
|
|
2024
2223
|
formatPolicy: framePolicy.summary,
|
|
@@ -2036,7 +2235,8 @@ function modelOptionsResources(inputModes = []) {
|
|
|
2036
2235
|
mode: optionResourceMode(sourceMode),
|
|
2037
2236
|
mediaType,
|
|
2038
2237
|
usage: optionResourceUsage(sourceMode),
|
|
2039
|
-
|
|
2238
|
+
valueShapes: item.valueShapes,
|
|
2239
|
+
sources: item.valueShapes,
|
|
2040
2240
|
fileTypes: sourceMode === 'subject_reference' ? undefined : item.fileTypes,
|
|
2041
2241
|
formatPolicy: imagePolicy?.summary,
|
|
2042
2242
|
webpSupported: imagePolicy?.webpSupported,
|
|
@@ -2074,7 +2274,7 @@ export function modelInputGuide() {
|
|
|
2074
2274
|
{ field: 'resources[].type', values: ['image', 'video', 'audio', 'subject'], description: '资源本体类型;subject 表示已创建的主体对象。' },
|
|
2075
2275
|
{ field: 'resources[].usage', values: ['first_frame', 'last_frame', 'reference', 'keyframe'], description: '素材用途。' },
|
|
2076
2276
|
{ field: 'resources[].reference_key', values: ['custom string'], description: '仅视频 reference 资源需要占位绑定时使用;图片生图 image:reference 不使用 reference_key。subject reference 必须传。' },
|
|
2077
|
-
{ field: 'resources[].source.kind', values: ['url', 'asset_id'], description: '
|
|
2277
|
+
{ field: 'resources[].source.kind', values: ['url', 'asset_id'], description: '只接受 url、asset_id 两个枚举值。本地文件、http(s) URL、material backendPath 一律传 kind=url,CLI 按 value 自动识别;asset_id 表示平台资产或主体对象 ID。注意:模型 resources[].valueShapes 列出的 local_file / http_url / backendPath 是 value 形状分类,不是 kind 枚举。' },
|
|
2078
2278
|
{ field: 'resources[].source.value', description: '资源值,必填。url 传素材地址;asset_id 传资源 ID。' },
|
|
2079
2279
|
{ field: 'resources[].order', description: '仅 usage=keyframe 时需要,且同一请求内不能重复。' },
|
|
2080
2280
|
{ field: 'resources[].duration', description: '仅 keyframe 场景下用于表达该帧持续时长,可传小数秒。' },
|
|
@@ -2133,8 +2333,8 @@ export async function modelCreateSpec(kwargs = {}) {
|
|
|
2133
2333
|
schemaVersion: 1,
|
|
2134
2334
|
modelGroupCode,
|
|
2135
2335
|
taskKind: context.taskKind,
|
|
2136
|
-
createCommand: context.taskKind === 'image' ? 'image
|
|
2137
|
-
feeCommand: context.taskKind === 'image' ? 'image
|
|
2336
|
+
createCommand: context.taskKind === 'image' ? 'create image' : 'create video',
|
|
2337
|
+
feeCommand: context.taskKind === 'image' ? 'create image-fee' : 'create video-fee',
|
|
2138
2338
|
statusCommandTaskType: context.taskKind === 'image' ? 'IMAGE_CREATE' : 'VIDEO_GROUP',
|
|
2139
2339
|
optionsCommand: `model options --model-group-code ${modelGroupCode}`,
|
|
2140
2340
|
model: context.model,
|
|
@@ -2156,7 +2356,35 @@ async function readJsonMaybeFile(value, fallback) {
|
|
|
2156
2356
|
return JSON.parse(fileText);
|
|
2157
2357
|
}
|
|
2158
2358
|
|
|
2159
|
-
|
|
2359
|
+
const AUDIO_VIDEO_EXTENSIONS = new Set([
|
|
2360
|
+
'.aac',
|
|
2361
|
+
'.aiff',
|
|
2362
|
+
'.avi',
|
|
2363
|
+
'.flac',
|
|
2364
|
+
'.m4a',
|
|
2365
|
+
'.m4v',
|
|
2366
|
+
'.mkv',
|
|
2367
|
+
'.mov',
|
|
2368
|
+
'.mp3',
|
|
2369
|
+
'.mp4',
|
|
2370
|
+
'.mpeg',
|
|
2371
|
+
'.mpg',
|
|
2372
|
+
'.oga',
|
|
2373
|
+
'.ogg',
|
|
2374
|
+
'.ogv',
|
|
2375
|
+
'.wav',
|
|
2376
|
+
'.webm',
|
|
2377
|
+
]);
|
|
2378
|
+
|
|
2379
|
+
function defaultUploadSceneForFile(filePath, mimeType = '') {
|
|
2380
|
+
const normalizedMime = String(mimeType || '').toLowerCase();
|
|
2381
|
+
if (normalizedMime.startsWith('audio/') || normalizedMime.startsWith('video/')) return TASK_UPLOAD_SCENE.VIDEO_CREATE;
|
|
2382
|
+
const ext = path.extname(String(filePath || '')).toLowerCase();
|
|
2383
|
+
if (AUDIO_VIDEO_EXTENSIONS.has(ext)) return TASK_UPLOAD_SCENE.VIDEO_CREATE;
|
|
2384
|
+
return TASK_UPLOAD_SCENE.DEFAULT;
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
async function collectFileSpecs(kwargs = {}, defaultSceneType = null) {
|
|
2160
2388
|
const specs = [];
|
|
2161
2389
|
for (const file of parseListArg(kwargs.file)) specs.push({ file });
|
|
2162
2390
|
for (const file of parseListArg(kwargs.files)) specs.push({ file });
|
|
@@ -2169,11 +2397,14 @@ async function collectFileSpecs(kwargs = {}, defaultSceneType = TASK_UPLOAD_SCEN
|
|
|
2169
2397
|
}
|
|
2170
2398
|
}
|
|
2171
2399
|
return specs
|
|
2172
|
-
.map((item) =>
|
|
2173
|
-
file
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2400
|
+
.map((item) => {
|
|
2401
|
+
const file = trimToNull(item.file ?? item.path ?? item.filePath);
|
|
2402
|
+
return {
|
|
2403
|
+
file,
|
|
2404
|
+
sceneType: trimToNull(item.sceneType ?? kwargs.sceneType) ?? defaultSceneType ?? defaultUploadSceneForFile(file),
|
|
2405
|
+
projectNo: trimToNull(item.projectNo ?? kwargs.projectNo) ?? '',
|
|
2406
|
+
};
|
|
2407
|
+
})
|
|
2177
2408
|
.filter((item) => item.file);
|
|
2178
2409
|
}
|
|
2179
2410
|
|
|
@@ -2182,7 +2413,7 @@ function dryRunBackendPath(filePath, sceneType) {
|
|
|
2182
2413
|
}
|
|
2183
2414
|
|
|
2184
2415
|
export async function uploadFilesCommand(kwargs = {}) {
|
|
2185
|
-
const specs = await collectFileSpecs(kwargs, trimToNull(kwargs.sceneType)
|
|
2416
|
+
const specs = await collectFileSpecs(kwargs, trimToNull(kwargs.sceneType));
|
|
2186
2417
|
if (!specs.length) throw argumentError('缺少上传文件', '传 --file <path> 或 --files a.png,b.mp4。');
|
|
2187
2418
|
if (toBool(kwargs.dryRun)) {
|
|
2188
2419
|
const files = [];
|
|
@@ -2212,7 +2443,7 @@ export async function uploadLocalFile(filePath, options = {}) {
|
|
|
2212
2443
|
throw argumentError(`文件不存在:${filePath}`);
|
|
2213
2444
|
}
|
|
2214
2445
|
const buffer = await fs.readFile(inspected.filePath);
|
|
2215
|
-
const sceneType = options.sceneType ??
|
|
2446
|
+
const sceneType = options.sceneType ?? defaultUploadSceneForFile(inspected.filePath, inspected.mimeType);
|
|
2216
2447
|
const groupId = crypto.randomUUID().replaceAll('-', '');
|
|
2217
2448
|
const secret = await awbApi.fetchUploadSecret({
|
|
2218
2449
|
sceneType,
|
|
@@ -2259,6 +2490,113 @@ export async function uploadLocalFile(filePath, options = {}) {
|
|
|
2259
2490
|
});
|
|
2260
2491
|
}
|
|
2261
2492
|
|
|
2493
|
+
function isHttpUrl(value) {
|
|
2494
|
+
return /^https?:\/\//i.test(String(value || '').trim());
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
function isUploadedMaterialReference(value) {
|
|
2498
|
+
const text = trimToNull(value);
|
|
2499
|
+
if (!text) return false;
|
|
2500
|
+
if (text.startsWith('material/') || text.startsWith('/material/')) return true;
|
|
2501
|
+
if (!isHttpUrl(text)) return false;
|
|
2502
|
+
try {
|
|
2503
|
+
const url = new URL(text);
|
|
2504
|
+
return url.hostname.endsWith('.myqcloud.com');
|
|
2505
|
+
} catch {
|
|
2506
|
+
return false;
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
function remoteFileNameFromUrl(remoteUrl, fallback = 'voice-audio') {
|
|
2511
|
+
try {
|
|
2512
|
+
const pathname = decodeURIComponent(new URL(remoteUrl).pathname);
|
|
2513
|
+
const baseName = safeFileName(path.basename(pathname));
|
|
2514
|
+
if (baseName && baseName !== '.' && baseName !== '/') return baseName;
|
|
2515
|
+
} catch {}
|
|
2516
|
+
return `${fallback}.mp3`;
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2519
|
+
function extensionFromContentType(contentType = '') {
|
|
2520
|
+
const normalized = String(contentType || '').split(';')[0].trim().toLowerCase();
|
|
2521
|
+
if (normalized === 'audio/mpeg') return '.mp3';
|
|
2522
|
+
if (normalized === 'audio/wav' || normalized === 'audio/x-wav') return '.wav';
|
|
2523
|
+
if (normalized === 'audio/mp4') return '.m4a';
|
|
2524
|
+
if (normalized === 'audio/aac') return '.aac';
|
|
2525
|
+
if (normalized === 'audio/ogg') return '.ogg';
|
|
2526
|
+
if (normalized === 'video/mp4') return '.mp4';
|
|
2527
|
+
return '';
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
function isSupportedRemoteVoiceDownload(contentType = '', fileName = '') {
|
|
2531
|
+
const normalized = String(contentType || '').split(';')[0].trim().toLowerCase();
|
|
2532
|
+
const extension = path.extname(fileName).toLowerCase();
|
|
2533
|
+
if (REMOTE_VOICE_MIME_TYPES.has(normalized)) return true;
|
|
2534
|
+
if ((!normalized || normalized === 'application/octet-stream') && REMOTE_VOICE_EXTENSIONS.has(extension)) return true;
|
|
2535
|
+
return false;
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
async function downloadRemoteFileToTemp(remoteUrl, options = {}) {
|
|
2539
|
+
const timeoutMs = Math.max(1_000, toInt(options.timeoutMs, REMOTE_VOICE_DOWNLOAD_TIMEOUT_MS));
|
|
2540
|
+
const maxBytes = Math.max(1, toInt(options.maxBytes, REMOTE_VOICE_DOWNLOAD_MAX_BYTES));
|
|
2541
|
+
const controller = new AbortController();
|
|
2542
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
2543
|
+
let dir = null;
|
|
2544
|
+
let response;
|
|
2545
|
+
try {
|
|
2546
|
+
response = await fetch(remoteUrl, { signal: controller.signal });
|
|
2547
|
+
if (!response.ok) {
|
|
2548
|
+
throw new LingjingAwbCliError(`下载远程音频失败:${response.status} ${response.statusText}`, {
|
|
2549
|
+
type: 'http_error',
|
|
2550
|
+
exitCode: 30,
|
|
2551
|
+
details: { url: remoteUrl, status: response.status },
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2554
|
+
const contentType = response.headers.get('content-type') || '';
|
|
2555
|
+
let fileName = remoteFileNameFromUrl(remoteUrl, options.fallbackName || 'voice-audio');
|
|
2556
|
+
if (!path.extname(fileName)) fileName = `${fileName}${extensionFromContentType(contentType) || '.mp3'}`;
|
|
2557
|
+
if (!isSupportedRemoteVoiceDownload(contentType, fileName)) {
|
|
2558
|
+
throw argumentError(
|
|
2559
|
+
`远程音频类型不支持:${contentType || path.extname(fileName) || 'unknown'}`,
|
|
2560
|
+
'create subject-voice 只支持 mp3、wav、m4a、aac、ogg 音频或 mp4 视频来源。',
|
|
2561
|
+
);
|
|
2562
|
+
}
|
|
2563
|
+
const contentLength = toInt(response.headers.get('content-length'), 0);
|
|
2564
|
+
if (contentLength > maxBytes) {
|
|
2565
|
+
throw argumentError(`远程音频过大:${contentLength} bytes`, `最大支持 ${maxBytes} bytes。`);
|
|
2566
|
+
}
|
|
2567
|
+
dir = await fs.mkdtemp(path.join(tmpdir(), 'lj-awb-voice-'));
|
|
2568
|
+
const filePath = path.join(dir, fileName);
|
|
2569
|
+
const file = await fs.open(filePath, 'w');
|
|
2570
|
+
let size = 0;
|
|
2571
|
+
try {
|
|
2572
|
+
if (!response.body) throw new Error('empty response body');
|
|
2573
|
+
for await (const chunk of response.body) {
|
|
2574
|
+
const buffer = Buffer.from(chunk);
|
|
2575
|
+
size += buffer.length;
|
|
2576
|
+
if (size > maxBytes) {
|
|
2577
|
+
throw argumentError(`远程音频过大:超过 ${maxBytes} bytes`);
|
|
2578
|
+
}
|
|
2579
|
+
await file.write(buffer);
|
|
2580
|
+
}
|
|
2581
|
+
} finally {
|
|
2582
|
+
await file.close();
|
|
2583
|
+
}
|
|
2584
|
+
return { filePath, dir, contentType, size };
|
|
2585
|
+
} catch (error) {
|
|
2586
|
+
if (dir) await fs.rm(dir, { recursive: true, force: true }).catch(() => {});
|
|
2587
|
+
if (error instanceof LingjingAwbCliError) throw error;
|
|
2588
|
+
const isAbort = error?.name === 'AbortError';
|
|
2589
|
+
throw new LingjingAwbCliError(`下载远程音频失败:${error.message}`, {
|
|
2590
|
+
type: 'network_error',
|
|
2591
|
+
exitCode: 30,
|
|
2592
|
+
hint: isAbort ? `远程下载超过 ${timeoutMs}ms,请改用本地 --file 或已上传 material 路径。` : '',
|
|
2593
|
+
details: { url: remoteUrl, causeCode: error?.cause?.code },
|
|
2594
|
+
});
|
|
2595
|
+
} finally {
|
|
2596
|
+
clearTimeout(timeout);
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2262
2600
|
function resolveCustomBizId(explicit) {
|
|
2263
2601
|
return trimToNull(explicit);
|
|
2264
2602
|
}
|
|
@@ -2330,7 +2668,10 @@ function normalizeResourceSource(source, type, index, options = {}) {
|
|
|
2330
2668
|
? explicitKind.toLowerCase()
|
|
2331
2669
|
: (rawValue?.startsWith('asset:') || type === 'subject' ? 'asset_id' : 'url');
|
|
2332
2670
|
if (!['url', 'asset_id'].includes(kind)) {
|
|
2333
|
-
throw argumentError(
|
|
2671
|
+
throw argumentError(
|
|
2672
|
+
`resource[${index}] source.kind 不支持:${explicitKind}`,
|
|
2673
|
+
'只支持 url、asset_id 两个值。本地文件 / http(s) URL / material backendPath 都统一传 kind=url(CLI 按 value 自动识别);平台资产或主体对象传 kind=asset_id。',
|
|
2674
|
+
);
|
|
2334
2675
|
}
|
|
2335
2676
|
const value = kind === 'asset_id' ? assetValue : rawValue;
|
|
2336
2677
|
if (!value) {
|
|
@@ -2765,7 +3106,7 @@ export async function imageFee(kwargs = {}) {
|
|
|
2765
3106
|
const built = await buildImageRequest(kwargs, { dryRun: true, includeCustomBizId: false });
|
|
2766
3107
|
return compactRecord({
|
|
2767
3108
|
dryRun: true,
|
|
2768
|
-
action: 'image
|
|
3109
|
+
action: 'create image-fee',
|
|
2769
3110
|
request: built.request,
|
|
2770
3111
|
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2771
3112
|
});
|
|
@@ -2820,13 +3161,13 @@ export async function imageCreate(kwargs = {}) {
|
|
|
2820
3161
|
const built = await buildImageRequest(kwargs, { dryRun: true });
|
|
2821
3162
|
return compactRecord({
|
|
2822
3163
|
dryRun: true,
|
|
2823
|
-
action: 'image
|
|
3164
|
+
action: 'create image',
|
|
2824
3165
|
request: built.request,
|
|
2825
3166
|
...(built.localFiles.length ? { localFiles: built.localFiles } : {}),
|
|
2826
3167
|
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2827
3168
|
});
|
|
2828
3169
|
}
|
|
2829
|
-
ensureConfirmed(kwargs, '正式生图会消耗积分,需要确认', { action: 'image
|
|
3170
|
+
ensureConfirmed(kwargs, '正式生图会消耗积分,需要确认', { action: 'create image' });
|
|
2830
3171
|
const built = await buildImageRequest(kwargs);
|
|
2831
3172
|
const feePayload = await awbApi.fetchImageFee(built.request).catch(() => null);
|
|
2832
3173
|
const estimate = await pointEstimate(feePayload, built.projectGroupNo).catch(() => ({}));
|
|
@@ -2919,7 +3260,7 @@ export async function videoFee(kwargs = {}) {
|
|
|
2919
3260
|
const built = await buildVideoRequest(kwargs, { dryRun: true, includeCustomBizId: false });
|
|
2920
3261
|
return compactRecord({
|
|
2921
3262
|
dryRun: true,
|
|
2922
|
-
action: 'video
|
|
3263
|
+
action: 'create video-fee',
|
|
2923
3264
|
request: built.request,
|
|
2924
3265
|
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2925
3266
|
});
|
|
@@ -2937,13 +3278,13 @@ export async function videoCreate(kwargs = {}) {
|
|
|
2937
3278
|
const built = await buildVideoRequest(kwargs, { dryRun: true });
|
|
2938
3279
|
return compactRecord({
|
|
2939
3280
|
dryRun: true,
|
|
2940
|
-
action: 'video
|
|
3281
|
+
action: 'create video',
|
|
2941
3282
|
request: built.request,
|
|
2942
3283
|
...(built.localFiles.length ? { localFiles: built.localFiles } : {}),
|
|
2943
3284
|
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2944
3285
|
});
|
|
2945
3286
|
}
|
|
2946
|
-
ensureConfirmed(kwargs, '正式生视频会消耗积分,需要确认', { action: 'video
|
|
3287
|
+
ensureConfirmed(kwargs, '正式生视频会消耗积分,需要确认', { action: 'create video' });
|
|
2947
3288
|
const built = await buildVideoRequest(kwargs);
|
|
2948
3289
|
const feePayload = await awbApi.fetchVideoFee(built.request).catch(() => null);
|
|
2949
3290
|
const estimate = await pointEstimate(feePayload, built.projectGroupNo).catch(() => ({}));
|
|
@@ -3079,7 +3420,7 @@ export async function imageCreateBatch(kwargs = {}) {
|
|
|
3079
3420
|
}
|
|
3080
3421
|
return { dryRun: true, count: items.length, results };
|
|
3081
3422
|
}
|
|
3082
|
-
ensureConfirmed(kwargs, '批量生图会多次消耗积分,需要确认', { action: 'image
|
|
3423
|
+
ensureConfirmed(kwargs, '批量生图会多次消耗积分,需要确认', { action: 'create image-batch', count: items.length });
|
|
3083
3424
|
const results = await runConcurrent(items, kwargs.concurrency ?? 1, async (item, index) => ({
|
|
3084
3425
|
inputIndex: index,
|
|
3085
3426
|
status: 'success',
|
|
@@ -3098,7 +3439,7 @@ export async function videoCreateBatch(kwargs = {}) {
|
|
|
3098
3439
|
}
|
|
3099
3440
|
return { dryRun: true, count: items.length, results };
|
|
3100
3441
|
}
|
|
3101
|
-
ensureConfirmed(kwargs, '批量生视频会多次消耗积分,需要确认', { action: 'video
|
|
3442
|
+
ensureConfirmed(kwargs, '批量生视频会多次消耗积分,需要确认', { action: 'create video-batch', count: items.length });
|
|
3102
3443
|
const results = await runConcurrent(items, kwargs.concurrency ?? 1, async (item, index) => ({
|
|
3103
3444
|
inputIndex: index,
|
|
3104
3445
|
status: 'success',
|
|
@@ -3311,6 +3652,7 @@ function normalizeAssetGroup(item = {}) {
|
|
|
3311
3652
|
groupId: item?.id ?? item?.groupId ?? item?.assetGroupsId ?? null,
|
|
3312
3653
|
name: item?.name ?? item?.groupName ?? null,
|
|
3313
3654
|
description: item?.description ?? null,
|
|
3655
|
+
platform: item?.platform ?? null,
|
|
3314
3656
|
projectName: item?.projectName ?? null,
|
|
3315
3657
|
};
|
|
3316
3658
|
}
|
|
@@ -3384,12 +3726,64 @@ function normalizeSubjectTagIds(tagList) {
|
|
|
3384
3726
|
return uniqueNonEmpty(tagList.map((item) => (typeof item === 'string' ? item : item?.tagId ?? item?.id ?? item?.tagCode)));
|
|
3385
3727
|
}
|
|
3386
3728
|
|
|
3729
|
+
function normalizeSubjectTaskMeta(item = {}) {
|
|
3730
|
+
const rawTaskStatus = item?.taskStatus ?? item?.task_status ?? null;
|
|
3731
|
+
const taskStatus = rawTaskStatus ? taskStatusText(rawTaskStatus) : null;
|
|
3732
|
+
const errorMessage = trimToNull(
|
|
3733
|
+
item?.errorMessage
|
|
3734
|
+
?? item?.error_msg
|
|
3735
|
+
?? item?.errorMsg
|
|
3736
|
+
?? item?.resultMessage
|
|
3737
|
+
?? item?.result_msg
|
|
3738
|
+
?? item?.resultMsg
|
|
3739
|
+
?? item?.message
|
|
3740
|
+
?? item?.msg,
|
|
3741
|
+
);
|
|
3742
|
+
return {
|
|
3743
|
+
taskStatus,
|
|
3744
|
+
errorMessage,
|
|
3745
|
+
isTerminal: taskStatus ? isTerminalTaskStatus(taskStatus) : false,
|
|
3746
|
+
isSuccess: taskStatus ? isSuccessTaskStatus(taskStatus) : false,
|
|
3747
|
+
};
|
|
3748
|
+
}
|
|
3749
|
+
|
|
3750
|
+
function subjectResourceStatus(externalId, taskMeta) {
|
|
3751
|
+
if (externalId) return 'ready';
|
|
3752
|
+
if (taskMeta?.taskStatus && taskMeta.isTerminal) {
|
|
3753
|
+
return taskMeta.isSuccess ? 'missing_external_id' : 'failed';
|
|
3754
|
+
}
|
|
3755
|
+
return 'pending_external_id';
|
|
3756
|
+
}
|
|
3757
|
+
|
|
3758
|
+
function subjectFailureDetails(record, kind = 'subject') {
|
|
3759
|
+
if (!record) return null;
|
|
3760
|
+
const taskStatus = taskStatusText(record.taskStatus);
|
|
3761
|
+
if (!taskStatus || !isTerminalTaskStatus(taskStatus)) return null;
|
|
3762
|
+
const fallback = kind === 'voice'
|
|
3763
|
+
? '主体音色创建失败'
|
|
3764
|
+
: '主体创建失败';
|
|
3765
|
+
if (!isSuccessTaskStatus(taskStatus)) {
|
|
3766
|
+
return {
|
|
3767
|
+
taskStatus,
|
|
3768
|
+
errorMessage: record.errorMessage || fallback,
|
|
3769
|
+
};
|
|
3770
|
+
}
|
|
3771
|
+
if (!record.externalId) {
|
|
3772
|
+
return {
|
|
3773
|
+
taskStatus,
|
|
3774
|
+
errorMessage: record.errorMessage || `${fallback}:任务已终态但未返回externalId`,
|
|
3775
|
+
};
|
|
3776
|
+
}
|
|
3777
|
+
return null;
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3387
3780
|
function normalizeSubjectRecord(item = {}) {
|
|
3388
3781
|
const referList = Array.isArray(item?.elementReferList) ? item.elementReferList : [];
|
|
3389
3782
|
const videoList = Array.isArray(item?.elementVideoList) ? item.elementVideoList : [];
|
|
3390
3783
|
const elementId = item?.id ?? item?.subjectId ?? item?.elementId ?? null;
|
|
3391
3784
|
const externalId = item?.externalId ?? item?.external_id ?? null;
|
|
3392
3785
|
const name = item?.elementName ?? item?.name ?? item?.subjectName ?? null;
|
|
3786
|
+
const taskMeta = normalizeSubjectTaskMeta(item);
|
|
3393
3787
|
return {
|
|
3394
3788
|
subjectId: externalId ?? elementId,
|
|
3395
3789
|
elementId,
|
|
@@ -3412,6 +3806,33 @@ function normalizeSubjectRecord(item = {}) {
|
|
|
3412
3806
|
tagIds: normalizeSubjectTagIds(item?.tagList),
|
|
3413
3807
|
...(trimToNull(item?.elementVoiceId) ? { voiceId: trimToNull(item.elementVoiceId) } : {}),
|
|
3414
3808
|
...(externalId && name ? { nextRefSubject: `${name}=${externalId}` } : {}),
|
|
3809
|
+
taskStatus: taskMeta.taskStatus,
|
|
3810
|
+
errorMessage: taskMeta.errorMessage,
|
|
3811
|
+
isTerminal: externalId ? true : taskMeta.isTerminal,
|
|
3812
|
+
status: subjectResourceStatus(externalId, taskMeta),
|
|
3813
|
+
createdAt: item?.gmtCreate ?? item?.createdAt ?? null,
|
|
3814
|
+
};
|
|
3815
|
+
}
|
|
3816
|
+
|
|
3817
|
+
function normalizeSubjectVoiceRecord(item = {}) {
|
|
3818
|
+
const voiceRecordId = item?.voiceRecordId ?? item?.id ?? item?.reqTaskId ?? item?.voiceTaskId ?? null;
|
|
3819
|
+
const reqTaskId = item?.reqTaskId ?? voiceRecordId;
|
|
3820
|
+
const externalId = item?.externalId ?? item?.external_id ?? item?.voice_id ?? item?.voiceId ?? null;
|
|
3821
|
+
const name = item?.voiceName ?? item?.name ?? null;
|
|
3822
|
+
const taskMeta = normalizeSubjectTaskMeta(item);
|
|
3823
|
+
return {
|
|
3824
|
+
voiceRecordId,
|
|
3825
|
+
reqTaskId,
|
|
3826
|
+
voiceId: externalId,
|
|
3827
|
+
externalId,
|
|
3828
|
+
name,
|
|
3829
|
+
voiceUrl: item?.voiceUrl ?? item?.voice_url ?? item?.audioUrl ?? item?.audio_url ?? null,
|
|
3830
|
+
videoId: item?.videoId ?? item?.video_id ?? null,
|
|
3831
|
+
status: subjectResourceStatus(externalId, taskMeta),
|
|
3832
|
+
taskStatus: taskMeta.taskStatus,
|
|
3833
|
+
errorMessage: taskMeta.errorMessage,
|
|
3834
|
+
isTerminal: externalId ? true : taskMeta.isTerminal,
|
|
3835
|
+
...(externalId ? { nextVoiceArg: `--voice-id ${externalId}` } : {}),
|
|
3415
3836
|
createdAt: item?.gmtCreate ?? item?.createdAt ?? null,
|
|
3416
3837
|
};
|
|
3417
3838
|
}
|
|
@@ -3439,45 +3860,55 @@ export async function assetMatchActor(kwargs = {}) {
|
|
|
3439
3860
|
}
|
|
3440
3861
|
|
|
3441
3862
|
export async function assetGroupList(kwargs = {}) {
|
|
3863
|
+
const platform = requireAssetPlatform(kwargs.platform);
|
|
3442
3864
|
const payload = await awbApi.listAssetGroups({
|
|
3443
3865
|
name: kwargs.name ?? '',
|
|
3866
|
+
platform,
|
|
3444
3867
|
pageNumber: toInt(kwargs.pageNumber, 1),
|
|
3445
3868
|
pageSize: toInt(kwargs.pageSize, 20),
|
|
3446
3869
|
...(parseListArg(kwargs.groupIds).length ? { groupIds: parseListArg(kwargs.groupIds) } : {}),
|
|
3447
3870
|
});
|
|
3448
|
-
return { groups: extractAssetGroupRows(payload), raw: toBool(kwargs.includeRaw) ? payload : undefined };
|
|
3871
|
+
return { platform, groups: extractAssetGroupRows(payload), raw: toBool(kwargs.includeRaw) ? payload : undefined };
|
|
3449
3872
|
}
|
|
3450
3873
|
|
|
3451
3874
|
export async function assetGroupGet(kwargs = {}) {
|
|
3452
3875
|
const groupId = requireValue(kwargs, 'groupId', 'group-id');
|
|
3453
|
-
const
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3876
|
+
const platform = requireAssetPlatform(kwargs.platform);
|
|
3877
|
+
const payload = await awbApi.getAssetGroup(groupId, { platform });
|
|
3878
|
+
if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
|
|
3879
|
+
const group = normalizeAssetGroup(payload);
|
|
3880
|
+
return { ...group, platform: group.platform ?? platform };
|
|
3881
|
+
}
|
|
3882
|
+
return extractAssetGroupRows(payload)[0] ?? { groupId, platform };
|
|
3457
3883
|
}
|
|
3458
3884
|
|
|
3459
3885
|
export async function assetGroupCreate(kwargs = {}) {
|
|
3460
3886
|
const name = requireValue(kwargs, 'name');
|
|
3887
|
+
const platform = requireAssetPlatform(kwargs.platform);
|
|
3461
3888
|
const body = {
|
|
3462
3889
|
name,
|
|
3463
3890
|
description: kwargs.description ?? '',
|
|
3891
|
+
platform,
|
|
3464
3892
|
projectName: kwargs.projectName ?? 'default',
|
|
3465
3893
|
};
|
|
3466
|
-
if (toBool(kwargs.dryRun)) return { dryRun: true, action: 'asset
|
|
3467
|
-
ensureConfirmed(kwargs, '创建素材组是云端写入动作,需要确认', { action: 'asset
|
|
3894
|
+
if (toBool(kwargs.dryRun)) return { dryRun: true, action: 'create asset-group', request: body };
|
|
3895
|
+
ensureConfirmed(kwargs, '创建素材组是云端写入动作,需要确认', { action: 'create asset-group', body });
|
|
3468
3896
|
const payload = await awbApi.createAssetGroup(body);
|
|
3469
|
-
return { created: true, groupId: payload?.id ?? payload?.groupId ?? payload ?? null, name, projectName: body.projectName };
|
|
3897
|
+
return { created: true, groupId: payload?.id ?? payload?.groupId ?? payload ?? null, name, platform, projectName: body.projectName };
|
|
3470
3898
|
}
|
|
3471
3899
|
|
|
3472
3900
|
export async function assetGroupUpdate(kwargs = {}) {
|
|
3473
3901
|
const groupId = requireValue(kwargs, 'groupId', 'group-id');
|
|
3474
|
-
const
|
|
3902
|
+
const platform = requireAssetPlatform(kwargs.platform);
|
|
3903
|
+
const body = { platform };
|
|
3475
3904
|
if (kwargs.name != null) body.name = kwargs.name;
|
|
3476
3905
|
if (kwargs.description != null) body.description = kwargs.description;
|
|
3477
3906
|
if (kwargs.projectName != null) body.projectName = kwargs.projectName;
|
|
3478
|
-
if (!
|
|
3479
|
-
|
|
3480
|
-
|
|
3907
|
+
if (!['name', 'description', 'projectName'].some((key) => Object.prototype.hasOwnProperty.call(body, key))) {
|
|
3908
|
+
throw argumentError('缺少素材组更新字段', '至少传 --name、--description 或 --project-name;--platform 只用于定位平台资产组。');
|
|
3909
|
+
}
|
|
3910
|
+
if (toBool(kwargs.dryRun)) return { dryRun: true, action: 'create asset-group-update', groupId, request: body };
|
|
3911
|
+
ensureConfirmed(kwargs, '更新素材组是云端写入动作,需要确认', { action: 'create asset-group-update', groupId, body });
|
|
3481
3912
|
await awbApi.updateAssetGroup(groupId, body);
|
|
3482
3913
|
return { updated: true, groupId, ...body };
|
|
3483
3914
|
}
|
|
@@ -3491,29 +3922,30 @@ function extractAssetId(payload) {
|
|
|
3491
3922
|
export async function assetRegister(kwargs = {}) {
|
|
3492
3923
|
const groupId = requireValue(kwargs, 'groupId', 'group-id');
|
|
3493
3924
|
const name = requireValue(kwargs, 'name');
|
|
3925
|
+
const platform = requireAssetPlatform(kwargs.platform);
|
|
3494
3926
|
const localFile = trimToNull(kwargs.file);
|
|
3495
3927
|
const assetPath = trimToNull(kwargs.backendPath) ?? normalizeCosAssetPath(kwargs.url);
|
|
3496
3928
|
if (!localFile && !assetPath) throw argumentError('缺少素材路径', '传 --file、--backend-path 或 --url。');
|
|
3497
3929
|
if (toBool(kwargs.dryRun)) {
|
|
3498
3930
|
return {
|
|
3499
3931
|
dryRun: true,
|
|
3500
|
-
action: 'asset
|
|
3932
|
+
action: 'create asset',
|
|
3501
3933
|
request: {
|
|
3502
3934
|
assetGroupsId: groupId,
|
|
3503
|
-
url: localFile ? normalizeCosAssetPath(dryRunBackendPath(localFile, TASK_UPLOAD_SCENE.
|
|
3935
|
+
url: localFile ? normalizeCosAssetPath(dryRunBackendPath(localFile, TASK_UPLOAD_SCENE.ASSET_REVIEW)) : assetPath,
|
|
3504
3936
|
name,
|
|
3505
|
-
|
|
3937
|
+
platform,
|
|
3506
3938
|
},
|
|
3507
3939
|
localFile: localFile ? await inspectLocalFile(localFile) : null,
|
|
3508
3940
|
};
|
|
3509
3941
|
}
|
|
3510
|
-
ensureConfirmed(kwargs, '注册素材是云端写入动作,需要确认', { action: 'asset
|
|
3511
|
-
const uploaded = localFile ? await uploadLocalFile(localFile, { sceneType: TASK_UPLOAD_SCENE.
|
|
3942
|
+
ensureConfirmed(kwargs, '注册素材是云端写入动作,需要确认', { action: 'create asset', groupId, name });
|
|
3943
|
+
const uploaded = localFile ? await uploadLocalFile(localFile, { sceneType: TASK_UPLOAD_SCENE.ASSET_REVIEW }) : null;
|
|
3512
3944
|
const body = {
|
|
3513
3945
|
assetGroupsId: groupId,
|
|
3514
3946
|
url: normalizeCosAssetPath(uploaded?.backendPath ?? assetPath),
|
|
3515
3947
|
name,
|
|
3516
|
-
|
|
3948
|
+
platform,
|
|
3517
3949
|
};
|
|
3518
3950
|
const payload = await awbApi.registerAsset(body);
|
|
3519
3951
|
return {
|
|
@@ -3521,6 +3953,7 @@ export async function assetRegister(kwargs = {}) {
|
|
|
3521
3953
|
assetId: extractAssetId(payload),
|
|
3522
3954
|
groupId,
|
|
3523
3955
|
name,
|
|
3956
|
+
platform,
|
|
3524
3957
|
assetPath: body.url,
|
|
3525
3958
|
...(uploaded ? { upload: uploaded } : {}),
|
|
3526
3959
|
};
|
|
@@ -3542,13 +3975,255 @@ export async function subjectList(kwargs = {}) {
|
|
|
3542
3975
|
};
|
|
3543
3976
|
}
|
|
3544
3977
|
|
|
3978
|
+
export async function subjectVoiceList(kwargs = {}) {
|
|
3979
|
+
const keyword = trimToNull(kwargs.keyword ?? kwargs.name);
|
|
3980
|
+
const payload = keyword
|
|
3981
|
+
? await awbApi.listVoicesByName(keyword)
|
|
3982
|
+
: await awbApi.listVoices();
|
|
3983
|
+
const voices = paginateRows(
|
|
3984
|
+
normalizeRows(payload).map((item) => normalizeSubjectVoiceRecord(item)),
|
|
3985
|
+
kwargs.pageNumber,
|
|
3986
|
+
kwargs.pageSize,
|
|
3987
|
+
);
|
|
3988
|
+
return {
|
|
3989
|
+
voices,
|
|
3990
|
+
...(toBool(kwargs.includeRaw) ? { raw: payload } : {}),
|
|
3991
|
+
};
|
|
3992
|
+
}
|
|
3993
|
+
|
|
3994
|
+
function subjectVoiceSource(kwargs = {}) {
|
|
3995
|
+
const file = trimToNull(kwargs.file);
|
|
3996
|
+
const voiceUrlArg = trimToNull(kwargs.voiceUrl);
|
|
3997
|
+
const audioUrlArg = trimToNull(kwargs.audioUrl);
|
|
3998
|
+
if (voiceUrlArg && audioUrlArg) {
|
|
3999
|
+
throw argumentError('音色来源只能选择一种', '--voice-url 和 --audio-url 是同一含义的别名,只能传一个。');
|
|
4000
|
+
}
|
|
4001
|
+
const voiceUrl = voiceUrlArg ?? audioUrlArg ?? trimToNull(kwargs.url);
|
|
4002
|
+
const videoId = trimToNull(kwargs.videoId);
|
|
4003
|
+
const sourceCount = [file, voiceUrl, videoId].filter(Boolean).length;
|
|
4004
|
+
if (sourceCount === 0) {
|
|
4005
|
+
throw argumentError('缺少音色来源', '传 --file <audio>、--voice-url/--audio-url <material path> 或 --video-id <id>。');
|
|
4006
|
+
}
|
|
4007
|
+
if (sourceCount > 1) {
|
|
4008
|
+
throw argumentError('音色来源只能选择一种', '--file、--voice-url/--audio-url、--video-id 三者只能传一个。');
|
|
4009
|
+
}
|
|
4010
|
+
const shouldUploadRemoteUrl = Boolean(voiceUrl && isHttpUrl(voiceUrl) && !isUploadedMaterialReference(voiceUrl));
|
|
4011
|
+
return { file, voiceUrl, videoId, shouldUploadRemoteUrl };
|
|
4012
|
+
}
|
|
4013
|
+
|
|
4014
|
+
function buildSubjectVoiceCreateBody(kwargs, source, uploaded = null) {
|
|
4015
|
+
const name = requireValue(kwargs, 'name');
|
|
4016
|
+
const voiceUrl = uploaded
|
|
4017
|
+
? normalizeCosAssetPath(uploaded.backendPath)
|
|
4018
|
+
: normalizeCosAssetPath(source.voiceUrl);
|
|
4019
|
+
return compactRecord({
|
|
4020
|
+
reqTaskId: trimToNull(kwargs.reqTaskId),
|
|
4021
|
+
voiceName: name,
|
|
4022
|
+
voiceUrl,
|
|
4023
|
+
videoId: source.videoId,
|
|
4024
|
+
});
|
|
4025
|
+
}
|
|
4026
|
+
|
|
4027
|
+
function extractCreatedVoiceRecordId(payload) {
|
|
4028
|
+
if (typeof payload === 'string') return payload;
|
|
4029
|
+
if (!payload || typeof payload !== 'object') return null;
|
|
4030
|
+
return payload.id
|
|
4031
|
+
?? payload.voiceRecordId
|
|
4032
|
+
?? payload.reqTaskId
|
|
4033
|
+
?? payload.voiceTaskId
|
|
4034
|
+
?? payload.data?.id
|
|
4035
|
+
?? payload.data?.voiceRecordId
|
|
4036
|
+
?? payload.data?.reqTaskId
|
|
4037
|
+
?? null;
|
|
4038
|
+
}
|
|
4039
|
+
|
|
4040
|
+
async function fetchSubjectVoiceByReqTaskId(reqTaskId, options = {}) {
|
|
4041
|
+
if (!reqTaskId) return null;
|
|
4042
|
+
const payload = await awbApi.getVoiceByReqTaskId(reqTaskId).catch((error) => {
|
|
4043
|
+
if (options.optional) return null;
|
|
4044
|
+
throw error;
|
|
4045
|
+
});
|
|
4046
|
+
return payload && typeof payload === 'object' ? normalizeSubjectVoiceRecord(payload) : null;
|
|
4047
|
+
}
|
|
4048
|
+
|
|
4049
|
+
async function waitForSubjectVoiceExternalId(reqTaskId, options = {}) {
|
|
4050
|
+
const waitSeconds = Math.max(0, toInt(options.waitSeconds, 0));
|
|
4051
|
+
const pollIntervalMs = Math.max(500, toInt(options.pollIntervalMs, 2000));
|
|
4052
|
+
const deadline = Date.now() + waitSeconds * 1000;
|
|
4053
|
+
let latest = await fetchSubjectVoiceByReqTaskId(reqTaskId);
|
|
4054
|
+
while (waitSeconds > 0 && !latest?.externalId && !subjectFailureDetails(latest, 'voice') && Date.now() < deadline) {
|
|
4055
|
+
await sleep(pollIntervalMs);
|
|
4056
|
+
latest = await fetchSubjectVoiceByReqTaskId(reqTaskId);
|
|
4057
|
+
}
|
|
4058
|
+
return latest;
|
|
4059
|
+
}
|
|
4060
|
+
|
|
4061
|
+
function subjectVoiceWaitPayload(voiceRecordId, voice) {
|
|
4062
|
+
const externalId = voice?.externalId ?? null;
|
|
4063
|
+
return {
|
|
4064
|
+
voiceRecordId,
|
|
4065
|
+
reqTaskId: voice?.reqTaskId ?? voiceRecordId,
|
|
4066
|
+
voiceId: externalId,
|
|
4067
|
+
externalId,
|
|
4068
|
+
nextVoiceArg: externalId ? `--voice-id ${externalId}` : null,
|
|
4069
|
+
status: voice?.status ?? (externalId ? 'ready' : 'pending_external_id'),
|
|
4070
|
+
taskStatus: voice?.taskStatus ?? null,
|
|
4071
|
+
errorMessage: voice?.errorMessage ?? null,
|
|
4072
|
+
isTerminal: externalId ? true : Boolean(voice?.isTerminal),
|
|
4073
|
+
voice,
|
|
4074
|
+
};
|
|
4075
|
+
}
|
|
4076
|
+
|
|
4077
|
+
export async function subjectVoiceCreate(kwargs = {}) {
|
|
4078
|
+
const name = requireValue(kwargs, 'name');
|
|
4079
|
+
const source = subjectVoiceSource(kwargs);
|
|
4080
|
+
if (toBool(kwargs.dryRun)) {
|
|
4081
|
+
const localFiles = source.file ? [await inspectLocalFile(source.file)] : [];
|
|
4082
|
+
let dryRunSource = source;
|
|
4083
|
+
if (source.file) {
|
|
4084
|
+
dryRunSource = { ...source, voiceUrl: dryRunBackendPath(source.file, TASK_UPLOAD_SCENE.SUBJECT) };
|
|
4085
|
+
} else if (source.shouldUploadRemoteUrl) {
|
|
4086
|
+
dryRunSource = {
|
|
4087
|
+
...source,
|
|
4088
|
+
voiceUrl: dryRunBackendPath(remoteFileNameFromUrl(source.voiceUrl), TASK_UPLOAD_SCENE.SUBJECT),
|
|
4089
|
+
};
|
|
4090
|
+
}
|
|
4091
|
+
return {
|
|
4092
|
+
dryRun: true,
|
|
4093
|
+
action: 'create subject-voice',
|
|
4094
|
+
name,
|
|
4095
|
+
request: buildSubjectVoiceCreateBody(kwargs, dryRunSource),
|
|
4096
|
+
localFiles,
|
|
4097
|
+
remoteUpload: source.shouldUploadRemoteUrl || undefined,
|
|
4098
|
+
remoteUrl: source.shouldUploadRemoteUrl ? source.voiceUrl : undefined,
|
|
4099
|
+
nextVoiceArg: '--voice-id <externalId>',
|
|
4100
|
+
};
|
|
4101
|
+
}
|
|
4102
|
+
ensureConfirmed(kwargs, '创建主体音色是云端写入动作,需要确认', { action: 'create subject-voice', name });
|
|
4103
|
+
let uploaded = null;
|
|
4104
|
+
let tempDownload = null;
|
|
4105
|
+
try {
|
|
4106
|
+
if (source.file) {
|
|
4107
|
+
uploaded = await uploadLocalFile(source.file, { sceneType: TASK_UPLOAD_SCENE.SUBJECT });
|
|
4108
|
+
} else if (source.shouldUploadRemoteUrl) {
|
|
4109
|
+
tempDownload = await downloadRemoteFileToTemp(source.voiceUrl, { fallbackName: safeFileName(name) || 'voice-audio' });
|
|
4110
|
+
uploaded = await uploadLocalFile(tempDownload.filePath, { sceneType: TASK_UPLOAD_SCENE.SUBJECT });
|
|
4111
|
+
}
|
|
4112
|
+
} finally {
|
|
4113
|
+
if (tempDownload?.dir) await fs.rm(tempDownload.dir, { recursive: true, force: true }).catch(() => {});
|
|
4114
|
+
}
|
|
4115
|
+
const body = buildSubjectVoiceCreateBody(kwargs, source, uploaded);
|
|
4116
|
+
const payload = await awbApi.createVoice(body);
|
|
4117
|
+
const voiceRecordId = extractCreatedVoiceRecordId(payload);
|
|
4118
|
+
if (!voiceRecordId) throw new LingjingAwbCliError('音色创建完成但未拿到 voiceRecordId', { type: 'api_error', exitCode: 1, details: payload });
|
|
4119
|
+
const voice = await fetchSubjectVoiceByReqTaskId(voiceRecordId, { optional: true });
|
|
4120
|
+
const waitPayload = subjectVoiceWaitPayload(voiceRecordId, voice);
|
|
4121
|
+
return {
|
|
4122
|
+
created: true,
|
|
4123
|
+
name,
|
|
4124
|
+
voiceRecordId,
|
|
4125
|
+
reqTaskId: waitPayload.reqTaskId,
|
|
4126
|
+
voiceId: waitPayload.voiceId,
|
|
4127
|
+
externalId: waitPayload.externalId,
|
|
4128
|
+
nextVoiceArg: waitPayload.nextVoiceArg,
|
|
4129
|
+
status: waitPayload.status,
|
|
4130
|
+
request: body,
|
|
4131
|
+
...(uploaded ? { upload: uploaded } : {}),
|
|
4132
|
+
voice,
|
|
4133
|
+
};
|
|
4134
|
+
}
|
|
4135
|
+
|
|
4136
|
+
function requireSubjectVoiceRecordId(kwargs = {}) {
|
|
4137
|
+
const value = trimToNull(kwargs.voiceRecordId ?? kwargs.reqTaskId);
|
|
4138
|
+
if (!value) throw argumentError('缺少参数:--voice-record-id', '传 create subject-voice 返回的 voiceRecordId;也可用 --req-task-id。');
|
|
4139
|
+
return value;
|
|
4140
|
+
}
|
|
4141
|
+
|
|
4142
|
+
export async function subjectVoiceWait(kwargs = {}) {
|
|
4143
|
+
const voiceRecordId = requireSubjectVoiceRecordId(kwargs);
|
|
4144
|
+
const voice = await waitForSubjectVoiceExternalId(voiceRecordId, kwargs);
|
|
4145
|
+
const payload = subjectVoiceWaitPayload(voiceRecordId, voice);
|
|
4146
|
+
const failure = subjectFailureDetails(voice, 'voice');
|
|
4147
|
+
if (failure) {
|
|
4148
|
+
throw new LingjingAwbCliError(failure.errorMessage, {
|
|
4149
|
+
type: 'subject_voice_failed',
|
|
4150
|
+
exitCode: 1,
|
|
4151
|
+
hint: '主体音色创建任务已失败,请根据 error.details.errorMessage 调整音频/视频来源后重新创建。',
|
|
4152
|
+
details: payload,
|
|
4153
|
+
});
|
|
4154
|
+
}
|
|
4155
|
+
if (!payload.externalId) {
|
|
4156
|
+
throw new LingjingAwbCliError('主体音色 externalId 尚未回填', {
|
|
4157
|
+
type: 'subject_voice_still_pending',
|
|
4158
|
+
exitCode: 20,
|
|
4159
|
+
hint: '稍后重试 create subject-voice-wait,或用 create subject-voice-list --name 查询。',
|
|
4160
|
+
details: payload,
|
|
4161
|
+
});
|
|
4162
|
+
}
|
|
4163
|
+
return payload;
|
|
4164
|
+
}
|
|
4165
|
+
|
|
4166
|
+
const SUBJECT_SLOT_ALIASES = {
|
|
4167
|
+
primary: 'primary',
|
|
4168
|
+
'three-view': 'three-view',
|
|
4169
|
+
three_view: 'three-view',
|
|
4170
|
+
threeview: 'three-view',
|
|
4171
|
+
face: 'face',
|
|
4172
|
+
side: 'side',
|
|
4173
|
+
back: 'back',
|
|
4174
|
+
};
|
|
4175
|
+
|
|
4176
|
+
const SUBJECT_SLOT_META = {
|
|
4177
|
+
primary: { idField: 'subjectId' },
|
|
4178
|
+
'three-view': { idField: 'subjectId' },
|
|
4179
|
+
face: { idField: 'faceViewId' },
|
|
4180
|
+
side: { idField: 'sideViewId' },
|
|
4181
|
+
back: { idField: 'backViewId' },
|
|
4182
|
+
};
|
|
4183
|
+
|
|
4184
|
+
function parseSubjectResourceItem(raw, index) {
|
|
4185
|
+
const text = String(raw ?? '').trim();
|
|
4186
|
+
if (!text) {
|
|
4187
|
+
throw argumentError(`resource[${index}] 为空`, '格式:--resource <slot>:<file|url>,slot ∈ primary | three-view | face | side | back。');
|
|
4188
|
+
}
|
|
4189
|
+
const colonIndex = text.indexOf(':');
|
|
4190
|
+
if (colonIndex <= 0) {
|
|
4191
|
+
throw argumentError(
|
|
4192
|
+
`resource[${index}] 缺少 slot`,
|
|
4193
|
+
'格式:--resource <slot>:<file|url>,例如 --resource primary:./three-view.png。',
|
|
4194
|
+
);
|
|
4195
|
+
}
|
|
4196
|
+
const slotRaw = text.slice(0, colonIndex).trim().toLowerCase();
|
|
4197
|
+
const slot = SUBJECT_SLOT_ALIASES[slotRaw];
|
|
4198
|
+
if (!slot) {
|
|
4199
|
+
throw argumentError(`resource[${index}] slot 不支持:${slotRaw}`, 'slot ∈ primary | three-view | face | side | back。');
|
|
4200
|
+
}
|
|
4201
|
+
const value = text.slice(colonIndex + 1).trim();
|
|
4202
|
+
if (!value) {
|
|
4203
|
+
throw argumentError(`resource[${index}] value 不能为空`);
|
|
4204
|
+
}
|
|
4205
|
+
return { slot, value };
|
|
4206
|
+
}
|
|
4207
|
+
|
|
3545
4208
|
function subjectAssetSpecs(kwargs = {}) {
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
{
|
|
3550
|
-
|
|
3551
|
-
|
|
4209
|
+
const bySlot = new Map();
|
|
4210
|
+
const items = parseListArg(kwargs.resource);
|
|
4211
|
+
for (const [index, raw] of items.entries()) {
|
|
4212
|
+
const { slot, value } = parseSubjectResourceItem(raw, index);
|
|
4213
|
+
if (bySlot.has(slot)) {
|
|
4214
|
+
throw argumentError(`resource[${index}] slot 重复:${slot}`, '每个 slot 只能传一次。');
|
|
4215
|
+
}
|
|
4216
|
+
const isUrl = isRemoteOrBackendPath(value);
|
|
4217
|
+
bySlot.set(slot, { label: slot, idField: SUBJECT_SLOT_META[slot].idField, file: isUrl ? null : value, url: isUrl ? value : null });
|
|
4218
|
+
}
|
|
4219
|
+
const primary = bySlot.get('primary') ?? bySlot.get('three-view');
|
|
4220
|
+
if (!primary) return [];
|
|
4221
|
+
const ordered = [{ ...primary, label: 'primary', isPrimary: true }];
|
|
4222
|
+
for (const slot of ['face', 'side', 'back']) {
|
|
4223
|
+
const item = bySlot.get(slot);
|
|
4224
|
+
if (item) ordered.push(item);
|
|
4225
|
+
}
|
|
4226
|
+
return ordered;
|
|
3552
4227
|
}
|
|
3553
4228
|
|
|
3554
4229
|
function subjectAssetPathForDryRun(item) {
|
|
@@ -3565,15 +4240,37 @@ function tagListFromArg(value) {
|
|
|
3565
4240
|
.filter((item) => item.tagId);
|
|
3566
4241
|
}
|
|
3567
4242
|
|
|
3568
|
-
|
|
4243
|
+
const SUBJECT_MODEL_CODE_HINT = '传 --model-code tx|vidu;KeLing / 可灵主体明确传 tx,Vidu 主体明确传 vidu。';
|
|
4244
|
+
|
|
4245
|
+
function resolveSubjectCreateModelCode(kwargs = {}) {
|
|
4246
|
+
const explicitModelCode = trimToNull(kwargs.modelCode ?? kwargs.model_code);
|
|
4247
|
+
if (explicitModelCode === 'tx' || explicitModelCode === 'vidu') {
|
|
4248
|
+
return { modelCode: explicitModelCode };
|
|
4249
|
+
}
|
|
4250
|
+
if (explicitModelCode) {
|
|
4251
|
+
throw argumentError(
|
|
4252
|
+
`主体 modelCode 不支持:${explicitModelCode}`,
|
|
4253
|
+
SUBJECT_MODEL_CODE_HINT,
|
|
4254
|
+
);
|
|
4255
|
+
}
|
|
4256
|
+
|
|
4257
|
+
throw argumentError(
|
|
4258
|
+
'缺少主体 modelCode',
|
|
4259
|
+
SUBJECT_MODEL_CODE_HINT,
|
|
4260
|
+
);
|
|
4261
|
+
}
|
|
4262
|
+
|
|
4263
|
+
function buildSubjectCreateBody(kwargs, specs, assets, modelCodeResolution = resolveSubjectCreateModelCode(kwargs)) {
|
|
3569
4264
|
const name = requireValue(kwargs, 'name');
|
|
4265
|
+
const description = trimToNull(kwargs.description ?? kwargs.elementDescription) ?? name;
|
|
3570
4266
|
const primary = assets.find((item) => item.isPrimary);
|
|
3571
4267
|
const referAssets = assets.filter((item) => item.assetPath);
|
|
4268
|
+
const { modelCode } = modelCodeResolution;
|
|
3572
4269
|
return compactRecord({
|
|
3573
4270
|
reqTaskId: trimToNull(kwargs.reqTaskId),
|
|
3574
|
-
modelCode
|
|
4271
|
+
modelCode,
|
|
3575
4272
|
elementName: name,
|
|
3576
|
-
elementDescription:
|
|
4273
|
+
elementDescription: description,
|
|
3577
4274
|
elementFrontalImage: primary?.assetPath ?? null,
|
|
3578
4275
|
elementReferList: referAssets.map((item) => ({
|
|
3579
4276
|
imageUrl: item.assetPath,
|
|
@@ -3591,9 +4288,12 @@ function extractCreatedElementId(payload) {
|
|
|
3591
4288
|
return payload.id ?? payload.elementId ?? payload.subjectId ?? payload.reqTaskId ?? payload.data?.id ?? payload.data?.elementId ?? null;
|
|
3592
4289
|
}
|
|
3593
4290
|
|
|
3594
|
-
async function fetchSubjectByReqTaskId(reqTaskId) {
|
|
4291
|
+
async function fetchSubjectByReqTaskId(reqTaskId, options = {}) {
|
|
3595
4292
|
if (!reqTaskId) return null;
|
|
3596
|
-
const payload = await awbApi.getElementByReqTaskId(reqTaskId).catch(() =>
|
|
4293
|
+
const payload = await awbApi.getElementByReqTaskId(reqTaskId).catch((error) => {
|
|
4294
|
+
if (options.optional) return null;
|
|
4295
|
+
throw error;
|
|
4296
|
+
});
|
|
3597
4297
|
return payload && typeof payload === 'object' ? normalizeSubjectRecord(payload) : null;
|
|
3598
4298
|
}
|
|
3599
4299
|
|
|
@@ -3602,7 +4302,7 @@ async function waitForSubjectExternalId(reqTaskId, options = {}) {
|
|
|
3602
4302
|
const pollIntervalMs = Math.max(500, toInt(options.pollIntervalMs, 2000));
|
|
3603
4303
|
const deadline = Date.now() + waitSeconds * 1000;
|
|
3604
4304
|
let latest = await fetchSubjectByReqTaskId(reqTaskId);
|
|
3605
|
-
while (waitSeconds > 0 && !latest?.externalId && Date.now() < deadline) {
|
|
4305
|
+
while (waitSeconds > 0 && !latest?.externalId && !subjectFailureDetails(latest, 'subject') && Date.now() < deadline) {
|
|
3606
4306
|
await sleep(pollIntervalMs);
|
|
3607
4307
|
latest = await fetchSubjectByReqTaskId(reqTaskId);
|
|
3608
4308
|
}
|
|
@@ -3616,7 +4316,10 @@ function subjectWaitPayload(elementId, subject) {
|
|
|
3616
4316
|
subjectId: externalId ?? elementId,
|
|
3617
4317
|
externalId,
|
|
3618
4318
|
nextRefSubject: externalId && subject?.name ? `${subject.name}=${externalId}` : null,
|
|
3619
|
-
status: externalId ? 'ready' : 'pending_external_id',
|
|
4319
|
+
status: subject?.status ?? (externalId ? 'ready' : 'pending_external_id'),
|
|
4320
|
+
taskStatus: subject?.taskStatus ?? null,
|
|
4321
|
+
errorMessage: subject?.errorMessage ?? null,
|
|
4322
|
+
isTerminal: externalId ? true : Boolean(subject?.isTerminal),
|
|
3620
4323
|
subject,
|
|
3621
4324
|
};
|
|
3622
4325
|
}
|
|
@@ -3625,8 +4328,9 @@ export async function subjectPublish(kwargs = {}) {
|
|
|
3625
4328
|
const name = requireValue(kwargs, 'name');
|
|
3626
4329
|
const specs = subjectAssetSpecs(kwargs);
|
|
3627
4330
|
if (!specs.some((item) => item.isPrimary)) {
|
|
3628
|
-
throw argumentError('缺少主体主参考图', '传 --primary
|
|
4331
|
+
throw argumentError('缺少主体主参考图', '传 --resource primary:<path|url>(或 --resource three-view:<path|url> 自动升为主图)。');
|
|
3629
4332
|
}
|
|
4333
|
+
const modelCodeResolution = resolveSubjectCreateModelCode(kwargs);
|
|
3630
4334
|
if (toBool(kwargs.dryRun)) {
|
|
3631
4335
|
const assets = specs.map((item) => ({
|
|
3632
4336
|
label: item.label,
|
|
@@ -3638,15 +4342,15 @@ export async function subjectPublish(kwargs = {}) {
|
|
|
3638
4342
|
}));
|
|
3639
4343
|
return {
|
|
3640
4344
|
dryRun: true,
|
|
3641
|
-
action: 'subject
|
|
4345
|
+
action: 'create subject',
|
|
3642
4346
|
name,
|
|
3643
|
-
request: buildSubjectCreateBody(kwargs, specs, assets),
|
|
4347
|
+
request: buildSubjectCreateBody(kwargs, specs, assets, modelCodeResolution),
|
|
3644
4348
|
assets,
|
|
3645
4349
|
localFiles: await inspectLocalFiles(specs.map((item) => item.file).filter(Boolean)),
|
|
3646
4350
|
nextRefSubject: `${name}=<externalId>`,
|
|
3647
4351
|
};
|
|
3648
4352
|
}
|
|
3649
|
-
ensureConfirmed(kwargs, '创建平台主体 element 是云端写入动作,需要确认', { action: 'subject
|
|
4353
|
+
ensureConfirmed(kwargs, '创建平台主体 element 是云端写入动作,需要确认', { action: 'create subject', name });
|
|
3650
4354
|
const assets = [];
|
|
3651
4355
|
for (const spec of specs) {
|
|
3652
4356
|
const uploaded = spec.file ? await uploadLocalFile(spec.file, { sceneType: TASK_UPLOAD_SCENE.SUBJECT }) : null;
|
|
@@ -3660,11 +4364,11 @@ export async function subjectPublish(kwargs = {}) {
|
|
|
3660
4364
|
...(uploaded ? { upload: uploaded } : {}),
|
|
3661
4365
|
});
|
|
3662
4366
|
}
|
|
3663
|
-
const body = buildSubjectCreateBody(kwargs, specs, assets);
|
|
4367
|
+
const body = buildSubjectCreateBody(kwargs, specs, assets, modelCodeResolution);
|
|
3664
4368
|
const payload = await awbApi.createElement(body);
|
|
3665
4369
|
const elementId = extractCreatedElementId(payload);
|
|
3666
4370
|
if (!elementId) throw new LingjingAwbCliError('主体创建完成但未拿到 elementId', { type: 'api_error', exitCode: 1, details: payload });
|
|
3667
|
-
const subject = await fetchSubjectByReqTaskId(elementId);
|
|
4371
|
+
const subject = await fetchSubjectByReqTaskId(elementId, { optional: true });
|
|
3668
4372
|
const waitPayload = subjectWaitPayload(elementId, subject);
|
|
3669
4373
|
return {
|
|
3670
4374
|
created: true,
|
|
@@ -3684,11 +4388,20 @@ export async function subjectWait(kwargs = {}) {
|
|
|
3684
4388
|
const elementId = requireValue(kwargs, 'elementId', 'element-id');
|
|
3685
4389
|
const subject = await waitForSubjectExternalId(elementId, kwargs);
|
|
3686
4390
|
const payload = subjectWaitPayload(elementId, subject);
|
|
4391
|
+
const failure = subjectFailureDetails(subject, 'subject');
|
|
4392
|
+
if (failure) {
|
|
4393
|
+
throw new LingjingAwbCliError(failure.errorMessage, {
|
|
4394
|
+
type: 'subject_failed',
|
|
4395
|
+
exitCode: 1,
|
|
4396
|
+
hint: '主体创建任务已失败,请根据 error.details.errorMessage 调整参考资源/模型后重新创建。',
|
|
4397
|
+
details: payload,
|
|
4398
|
+
});
|
|
4399
|
+
}
|
|
3687
4400
|
if (!payload.externalId) {
|
|
3688
4401
|
throw new LingjingAwbCliError('主体 externalId 尚未回填', {
|
|
3689
4402
|
type: 'subject_still_pending',
|
|
3690
4403
|
exitCode: 20,
|
|
3691
|
-
hint: '稍后重试 subject
|
|
4404
|
+
hint: '稍后重试 create subject-wait,或用 create subject-list --name 查询。',
|
|
3692
4405
|
details: payload,
|
|
3693
4406
|
});
|
|
3694
4407
|
}
|
|
@@ -3704,7 +4417,7 @@ export async function subjectPublishBatch(kwargs = {}) {
|
|
|
3704
4417
|
}
|
|
3705
4418
|
return { dryRun: true, count: items.length, results };
|
|
3706
4419
|
}
|
|
3707
|
-
ensureConfirmed(kwargs, '批量发布主体资产是云端写入动作,需要确认', { action: 'subject
|
|
4420
|
+
ensureConfirmed(kwargs, '批量发布主体资产是云端写入动作,需要确认', { action: 'create subject-batch', count: items.length });
|
|
3708
4421
|
const results = await runConcurrent(items, kwargs.concurrency ?? 1, async (item, index) => ({
|
|
3709
4422
|
inputIndex: index,
|
|
3710
4423
|
status: 'success',
|
|
@@ -3714,44 +4427,73 @@ export async function subjectPublishBatch(kwargs = {}) {
|
|
|
3714
4427
|
}
|
|
3715
4428
|
|
|
3716
4429
|
export async function subtitleRemove(kwargs = {}) {
|
|
3717
|
-
const
|
|
4430
|
+
const built = await buildSubtitleRemovalRequest(kwargs, { dryRun: toBool(kwargs.dryRun) });
|
|
3718
4431
|
if (toBool(kwargs.dryRun)) {
|
|
3719
|
-
return {
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
4432
|
+
return {
|
|
4433
|
+
dryRun: true,
|
|
4434
|
+
action: 'create video-subtitle-removal',
|
|
4435
|
+
request: built.request,
|
|
4436
|
+
materialEndpoint: '/api/material/creation/videoSubtitleRemoval',
|
|
4437
|
+
taskType: 'VIDEO_SUBTITLE_REMOVAL',
|
|
4438
|
+
};
|
|
4439
|
+
}
|
|
4440
|
+
ensureConfirmed(kwargs, '提交视频去字幕任务会通过 material 创建任务并消耗积分,需要确认', {
|
|
4441
|
+
action: 'create video-subtitle-removal',
|
|
4442
|
+
sourceTaskId: built.sourceTaskId,
|
|
3728
4443
|
});
|
|
3729
|
-
|
|
4444
|
+
const feePayload = await awbApi.fetchVideoSubtitleRemovalFee(built.request).catch(() => null);
|
|
4445
|
+
const estimate = await pointEstimate(feePayload, built.projectGroupNo).catch(() => ({}));
|
|
4446
|
+
const payload = await awbApi.createVideoSubtitleRemovalTask(built.request);
|
|
4447
|
+
const result = normalizeCreatedTask(payload, {
|
|
4448
|
+
...estimate,
|
|
3730
4449
|
submitted: true,
|
|
3731
|
-
|
|
3732
|
-
|
|
4450
|
+
taskType: 'VIDEO_SUBTITLE_REMOVAL',
|
|
4451
|
+
sourceTaskId: built.sourceTaskId,
|
|
4452
|
+
projectGroupNo: built.projectGroupNo,
|
|
4453
|
+
});
|
|
4454
|
+
await appendTaskRecord(kwargs, {
|
|
4455
|
+
taskId: result.taskId,
|
|
4456
|
+
taskType: 'VIDEO_SUBTITLE_REMOVAL',
|
|
4457
|
+
projectGroupNo: built.projectGroupNo,
|
|
4458
|
+
promptSummary: `去字幕 sourceTaskId=${built.sourceTaskId}`,
|
|
4459
|
+
});
|
|
4460
|
+
return {
|
|
4461
|
+
...result,
|
|
4462
|
+
nextCommand: result.taskId
|
|
4463
|
+
? `lj-awb task video-subtitle-status --task-id ${result.taskId}${built.projectGroupNo ? ` --project-group-no ${built.projectGroupNo}` : ''} -f json`
|
|
4464
|
+
: null,
|
|
4465
|
+
};
|
|
4466
|
+
}
|
|
4467
|
+
|
|
4468
|
+
async function buildSubtitleRemovalRequest(kwargs = {}, options = {}) {
|
|
4469
|
+
const sourceTaskId = trimToNull(kwargs.sourceTaskId);
|
|
4470
|
+
if (!sourceTaskId) {
|
|
4471
|
+
throw argumentError('缺少来源视频任务 ID', '传 --source-task-id <taskId>;必须是 material 中已成功的视频任务。');
|
|
4472
|
+
}
|
|
4473
|
+
const dryRun = Boolean(options.dryRun);
|
|
4474
|
+
const projectGroupNo = await resolveProjectGroupNo(kwargs.projectGroupNo, {
|
|
4475
|
+
allowNull: true,
|
|
4476
|
+
noNetwork: dryRun,
|
|
4477
|
+
noSave: dryRun,
|
|
4478
|
+
}).catch((error) => {
|
|
4479
|
+
if (dryRun) return null;
|
|
4480
|
+
throw error;
|
|
4481
|
+
});
|
|
4482
|
+
return {
|
|
4483
|
+
sourceTaskId,
|
|
4484
|
+
projectGroupNo,
|
|
4485
|
+
request: compactRecord({
|
|
4486
|
+
sourceTaskId,
|
|
4487
|
+
projectGroupNo,
|
|
4488
|
+
}),
|
|
3733
4489
|
};
|
|
3734
4490
|
}
|
|
3735
4491
|
|
|
3736
4492
|
export async function subtitleStatus(kwargs = {}) {
|
|
3737
|
-
const
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
: await awbApi.fetchSubtitleTaskByRemoteId(remoteTaskId);
|
|
3743
|
-
const resultUrls = uniqueNonEmpty([
|
|
3744
|
-
...parseListArg(payload?.result_url ?? payload?.resultUrl),
|
|
3745
|
-
...parseListArg(payload?.output_url ?? payload?.outputUrl),
|
|
3746
|
-
...parseListArg(payload?.url),
|
|
3747
|
-
]);
|
|
3748
|
-
return compactRecord({
|
|
3749
|
-
publicId: publicId ?? payload?.public_id ?? payload?.publicId ?? payload?.id ?? null,
|
|
3750
|
-
remoteTaskId: remoteTaskId ?? payload?.remote_task_id ?? payload?.remoteTaskId ?? null,
|
|
3751
|
-
taskStatus: payload?.status ?? payload?.taskStatus ?? payload?.state ?? null,
|
|
3752
|
-
isTerminal: isTerminalTaskStatus(payload?.status ?? payload?.taskStatus ?? payload?.state),
|
|
3753
|
-
resultCount: resultUrls.length,
|
|
3754
|
-
...(resultUrls.length ? { resultUrls } : {}),
|
|
3755
|
-
errorMessage: payload?.error_message ?? payload?.errorMessage ?? payload?.message ?? null,
|
|
4493
|
+
const taskId = requireValue(kwargs, 'taskId', 'task-id');
|
|
4494
|
+
return taskStatus({
|
|
4495
|
+
...kwargs,
|
|
4496
|
+
taskId,
|
|
4497
|
+
taskType: 'VIDEO_SUBTITLE_REMOVAL',
|
|
3756
4498
|
});
|
|
3757
4499
|
}
|