@lingjingai/lj-awb-cli 0.3.14 → 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 +36 -28
- package/build/_shared.mjs +130 -0
- package/build/build.mjs +3 -0
- package/build/pre-publish.mjs +57 -0
- package/build/pre.mjs +15 -51
- package/build/prod.mjs +25 -68
- package/install.mjs +1 -0
- package/package.json +10 -3
- package/packages/awb-cli/README.md +0 -3
- package/packages/awb-cli/package.json +2 -2
- package/packages/awb-core/package.json +7 -2
- package/packages/awb-core/src/api.js +33 -64
- package/packages/awb-core/src/artifact.js +936 -0
- package/packages/awb-core/src/auth.js +1 -1
- package/packages/awb-core/src/commands.js +668 -97
- package/packages/awb-core/src/common.js +3 -2
- package/packages/awb-core/src/output.js +2380 -106
- package/packages/awb-core/src/services.js +868 -114
- package/packages/awb-core/src/standalone.js +985 -235
- package/skills/lj-awb/SKILL.md +84 -73
- 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 +65 -0
- package/skills/lj-awb/modules/asset.md +50 -11
- package/skills/lj-awb/modules/auth.md +12 -5
- package/skills/lj-awb/modules/create-contract.md +23 -14
- 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 -10
- 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 +40 -28
- package/skills/lj-awb/modules/task.md +70 -8
- package/skills/lj-awb/modules/upload.md +18 -2
- package/skills/lj-awb/modules/video.md +30 -26
- package/skills/lj-awb/modules/workflows.md +274 -145
- 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) {
|
|
@@ -2494,6 +2835,18 @@ function isRemoteOrBackendPath(value) {
|
|
|
2494
2835
|
|| text.startsWith('/material/');
|
|
2495
2836
|
}
|
|
2496
2837
|
|
|
2838
|
+
function normalizeMaterialUrlValue(value) {
|
|
2839
|
+
const text = trimToNull(value);
|
|
2840
|
+
if (!text) return text;
|
|
2841
|
+
if (/^https?:\/\//i.test(text)) {
|
|
2842
|
+
try {
|
|
2843
|
+
const pathname = decodeURIComponent(new URL(text).pathname);
|
|
2844
|
+
if (pathname.startsWith('/material/')) return pathname;
|
|
2845
|
+
} catch {}
|
|
2846
|
+
}
|
|
2847
|
+
return text;
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2497
2850
|
function conversionOutputExtension(format) {
|
|
2498
2851
|
const normalized = normalizeFileFormat(format);
|
|
2499
2852
|
if (normalized === 'jpg') return 'jpg';
|
|
@@ -2558,7 +2911,7 @@ async function resolveResourceFileValue(resource, options = {}) {
|
|
|
2558
2911
|
}
|
|
2559
2912
|
const value = resource._source.value;
|
|
2560
2913
|
if (isRemoteOrBackendPath(value)) {
|
|
2561
|
-
return { resource: { ...base, source: { kind: 'url', value } }, upload: null, localFile: null };
|
|
2914
|
+
return { resource: { ...base, source: { kind: 'url', value: normalizeMaterialUrlValue(value) } }, upload: null, localFile: null };
|
|
2562
2915
|
}
|
|
2563
2916
|
const inspected = await inspectLocalFile(value);
|
|
2564
2917
|
if (!inspected.exists) {
|
|
@@ -2753,7 +3106,7 @@ export async function imageFee(kwargs = {}) {
|
|
|
2753
3106
|
const built = await buildImageRequest(kwargs, { dryRun: true, includeCustomBizId: false });
|
|
2754
3107
|
return compactRecord({
|
|
2755
3108
|
dryRun: true,
|
|
2756
|
-
action: 'image
|
|
3109
|
+
action: 'create image-fee',
|
|
2757
3110
|
request: built.request,
|
|
2758
3111
|
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2759
3112
|
});
|
|
@@ -2808,13 +3161,13 @@ export async function imageCreate(kwargs = {}) {
|
|
|
2808
3161
|
const built = await buildImageRequest(kwargs, { dryRun: true });
|
|
2809
3162
|
return compactRecord({
|
|
2810
3163
|
dryRun: true,
|
|
2811
|
-
action: 'image
|
|
3164
|
+
action: 'create image',
|
|
2812
3165
|
request: built.request,
|
|
2813
3166
|
...(built.localFiles.length ? { localFiles: built.localFiles } : {}),
|
|
2814
3167
|
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2815
3168
|
});
|
|
2816
3169
|
}
|
|
2817
|
-
ensureConfirmed(kwargs, '正式生图会消耗积分,需要确认', { action: 'image
|
|
3170
|
+
ensureConfirmed(kwargs, '正式生图会消耗积分,需要确认', { action: 'create image' });
|
|
2818
3171
|
const built = await buildImageRequest(kwargs);
|
|
2819
3172
|
const feePayload = await awbApi.fetchImageFee(built.request).catch(() => null);
|
|
2820
3173
|
const estimate = await pointEstimate(feePayload, built.projectGroupNo).catch(() => ({}));
|
|
@@ -2907,7 +3260,7 @@ export async function videoFee(kwargs = {}) {
|
|
|
2907
3260
|
const built = await buildVideoRequest(kwargs, { dryRun: true, includeCustomBizId: false });
|
|
2908
3261
|
return compactRecord({
|
|
2909
3262
|
dryRun: true,
|
|
2910
|
-
action: 'video
|
|
3263
|
+
action: 'create video-fee',
|
|
2911
3264
|
request: built.request,
|
|
2912
3265
|
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2913
3266
|
});
|
|
@@ -2925,13 +3278,13 @@ export async function videoCreate(kwargs = {}) {
|
|
|
2925
3278
|
const built = await buildVideoRequest(kwargs, { dryRun: true });
|
|
2926
3279
|
return compactRecord({
|
|
2927
3280
|
dryRun: true,
|
|
2928
|
-
action: 'video
|
|
3281
|
+
action: 'create video',
|
|
2929
3282
|
request: built.request,
|
|
2930
3283
|
...(built.localFiles.length ? { localFiles: built.localFiles } : {}),
|
|
2931
3284
|
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2932
3285
|
});
|
|
2933
3286
|
}
|
|
2934
|
-
ensureConfirmed(kwargs, '正式生视频会消耗积分,需要确认', { action: 'video
|
|
3287
|
+
ensureConfirmed(kwargs, '正式生视频会消耗积分,需要确认', { action: 'create video' });
|
|
2935
3288
|
const built = await buildVideoRequest(kwargs);
|
|
2936
3289
|
const feePayload = await awbApi.fetchVideoFee(built.request).catch(() => null);
|
|
2937
3290
|
const estimate = await pointEstimate(feePayload, built.projectGroupNo).catch(() => ({}));
|
|
@@ -3067,7 +3420,7 @@ export async function imageCreateBatch(kwargs = {}) {
|
|
|
3067
3420
|
}
|
|
3068
3421
|
return { dryRun: true, count: items.length, results };
|
|
3069
3422
|
}
|
|
3070
|
-
ensureConfirmed(kwargs, '批量生图会多次消耗积分,需要确认', { action: 'image
|
|
3423
|
+
ensureConfirmed(kwargs, '批量生图会多次消耗积分,需要确认', { action: 'create image-batch', count: items.length });
|
|
3071
3424
|
const results = await runConcurrent(items, kwargs.concurrency ?? 1, async (item, index) => ({
|
|
3072
3425
|
inputIndex: index,
|
|
3073
3426
|
status: 'success',
|
|
@@ -3086,7 +3439,7 @@ export async function videoCreateBatch(kwargs = {}) {
|
|
|
3086
3439
|
}
|
|
3087
3440
|
return { dryRun: true, count: items.length, results };
|
|
3088
3441
|
}
|
|
3089
|
-
ensureConfirmed(kwargs, '批量生视频会多次消耗积分,需要确认', { action: 'video
|
|
3442
|
+
ensureConfirmed(kwargs, '批量生视频会多次消耗积分,需要确认', { action: 'create video-batch', count: items.length });
|
|
3090
3443
|
const results = await runConcurrent(items, kwargs.concurrency ?? 1, async (item, index) => ({
|
|
3091
3444
|
inputIndex: index,
|
|
3092
3445
|
status: 'success',
|
|
@@ -3299,6 +3652,7 @@ function normalizeAssetGroup(item = {}) {
|
|
|
3299
3652
|
groupId: item?.id ?? item?.groupId ?? item?.assetGroupsId ?? null,
|
|
3300
3653
|
name: item?.name ?? item?.groupName ?? null,
|
|
3301
3654
|
description: item?.description ?? null,
|
|
3655
|
+
platform: item?.platform ?? null,
|
|
3302
3656
|
projectName: item?.projectName ?? null,
|
|
3303
3657
|
};
|
|
3304
3658
|
}
|
|
@@ -3372,12 +3726,64 @@ function normalizeSubjectTagIds(tagList) {
|
|
|
3372
3726
|
return uniqueNonEmpty(tagList.map((item) => (typeof item === 'string' ? item : item?.tagId ?? item?.id ?? item?.tagCode)));
|
|
3373
3727
|
}
|
|
3374
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
|
+
|
|
3375
3780
|
function normalizeSubjectRecord(item = {}) {
|
|
3376
3781
|
const referList = Array.isArray(item?.elementReferList) ? item.elementReferList : [];
|
|
3377
3782
|
const videoList = Array.isArray(item?.elementVideoList) ? item.elementVideoList : [];
|
|
3378
3783
|
const elementId = item?.id ?? item?.subjectId ?? item?.elementId ?? null;
|
|
3379
3784
|
const externalId = item?.externalId ?? item?.external_id ?? null;
|
|
3380
3785
|
const name = item?.elementName ?? item?.name ?? item?.subjectName ?? null;
|
|
3786
|
+
const taskMeta = normalizeSubjectTaskMeta(item);
|
|
3381
3787
|
return {
|
|
3382
3788
|
subjectId: externalId ?? elementId,
|
|
3383
3789
|
elementId,
|
|
@@ -3400,6 +3806,33 @@ function normalizeSubjectRecord(item = {}) {
|
|
|
3400
3806
|
tagIds: normalizeSubjectTagIds(item?.tagList),
|
|
3401
3807
|
...(trimToNull(item?.elementVoiceId) ? { voiceId: trimToNull(item.elementVoiceId) } : {}),
|
|
3402
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}` } : {}),
|
|
3403
3836
|
createdAt: item?.gmtCreate ?? item?.createdAt ?? null,
|
|
3404
3837
|
};
|
|
3405
3838
|
}
|
|
@@ -3427,45 +3860,55 @@ export async function assetMatchActor(kwargs = {}) {
|
|
|
3427
3860
|
}
|
|
3428
3861
|
|
|
3429
3862
|
export async function assetGroupList(kwargs = {}) {
|
|
3863
|
+
const platform = requireAssetPlatform(kwargs.platform);
|
|
3430
3864
|
const payload = await awbApi.listAssetGroups({
|
|
3431
3865
|
name: kwargs.name ?? '',
|
|
3866
|
+
platform,
|
|
3432
3867
|
pageNumber: toInt(kwargs.pageNumber, 1),
|
|
3433
3868
|
pageSize: toInt(kwargs.pageSize, 20),
|
|
3434
3869
|
...(parseListArg(kwargs.groupIds).length ? { groupIds: parseListArg(kwargs.groupIds) } : {}),
|
|
3435
3870
|
});
|
|
3436
|
-
return { groups: extractAssetGroupRows(payload), raw: toBool(kwargs.includeRaw) ? payload : undefined };
|
|
3871
|
+
return { platform, groups: extractAssetGroupRows(payload), raw: toBool(kwargs.includeRaw) ? payload : undefined };
|
|
3437
3872
|
}
|
|
3438
3873
|
|
|
3439
3874
|
export async function assetGroupGet(kwargs = {}) {
|
|
3440
3875
|
const groupId = requireValue(kwargs, 'groupId', 'group-id');
|
|
3441
|
-
const
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
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 };
|
|
3445
3883
|
}
|
|
3446
3884
|
|
|
3447
3885
|
export async function assetGroupCreate(kwargs = {}) {
|
|
3448
3886
|
const name = requireValue(kwargs, 'name');
|
|
3887
|
+
const platform = requireAssetPlatform(kwargs.platform);
|
|
3449
3888
|
const body = {
|
|
3450
3889
|
name,
|
|
3451
3890
|
description: kwargs.description ?? '',
|
|
3891
|
+
platform,
|
|
3452
3892
|
projectName: kwargs.projectName ?? 'default',
|
|
3453
3893
|
};
|
|
3454
|
-
if (toBool(kwargs.dryRun)) return { dryRun: true, action: 'asset
|
|
3455
|
-
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 });
|
|
3456
3896
|
const payload = await awbApi.createAssetGroup(body);
|
|
3457
|
-
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 };
|
|
3458
3898
|
}
|
|
3459
3899
|
|
|
3460
3900
|
export async function assetGroupUpdate(kwargs = {}) {
|
|
3461
3901
|
const groupId = requireValue(kwargs, 'groupId', 'group-id');
|
|
3462
|
-
const
|
|
3902
|
+
const platform = requireAssetPlatform(kwargs.platform);
|
|
3903
|
+
const body = { platform };
|
|
3463
3904
|
if (kwargs.name != null) body.name = kwargs.name;
|
|
3464
3905
|
if (kwargs.description != null) body.description = kwargs.description;
|
|
3465
3906
|
if (kwargs.projectName != null) body.projectName = kwargs.projectName;
|
|
3466
|
-
if (!
|
|
3467
|
-
|
|
3468
|
-
|
|
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 });
|
|
3469
3912
|
await awbApi.updateAssetGroup(groupId, body);
|
|
3470
3913
|
return { updated: true, groupId, ...body };
|
|
3471
3914
|
}
|
|
@@ -3479,29 +3922,30 @@ function extractAssetId(payload) {
|
|
|
3479
3922
|
export async function assetRegister(kwargs = {}) {
|
|
3480
3923
|
const groupId = requireValue(kwargs, 'groupId', 'group-id');
|
|
3481
3924
|
const name = requireValue(kwargs, 'name');
|
|
3925
|
+
const platform = requireAssetPlatform(kwargs.platform);
|
|
3482
3926
|
const localFile = trimToNull(kwargs.file);
|
|
3483
3927
|
const assetPath = trimToNull(kwargs.backendPath) ?? normalizeCosAssetPath(kwargs.url);
|
|
3484
3928
|
if (!localFile && !assetPath) throw argumentError('缺少素材路径', '传 --file、--backend-path 或 --url。');
|
|
3485
3929
|
if (toBool(kwargs.dryRun)) {
|
|
3486
3930
|
return {
|
|
3487
3931
|
dryRun: true,
|
|
3488
|
-
action: 'asset
|
|
3932
|
+
action: 'create asset',
|
|
3489
3933
|
request: {
|
|
3490
3934
|
assetGroupsId: groupId,
|
|
3491
|
-
url: localFile ? normalizeCosAssetPath(dryRunBackendPath(localFile, TASK_UPLOAD_SCENE.
|
|
3935
|
+
url: localFile ? normalizeCosAssetPath(dryRunBackendPath(localFile, TASK_UPLOAD_SCENE.ASSET_REVIEW)) : assetPath,
|
|
3492
3936
|
name,
|
|
3493
|
-
|
|
3937
|
+
platform,
|
|
3494
3938
|
},
|
|
3495
3939
|
localFile: localFile ? await inspectLocalFile(localFile) : null,
|
|
3496
3940
|
};
|
|
3497
3941
|
}
|
|
3498
|
-
ensureConfirmed(kwargs, '注册素材是云端写入动作,需要确认', { action: 'asset
|
|
3499
|
-
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;
|
|
3500
3944
|
const body = {
|
|
3501
3945
|
assetGroupsId: groupId,
|
|
3502
3946
|
url: normalizeCosAssetPath(uploaded?.backendPath ?? assetPath),
|
|
3503
3947
|
name,
|
|
3504
|
-
|
|
3948
|
+
platform,
|
|
3505
3949
|
};
|
|
3506
3950
|
const payload = await awbApi.registerAsset(body);
|
|
3507
3951
|
return {
|
|
@@ -3509,6 +3953,7 @@ export async function assetRegister(kwargs = {}) {
|
|
|
3509
3953
|
assetId: extractAssetId(payload),
|
|
3510
3954
|
groupId,
|
|
3511
3955
|
name,
|
|
3956
|
+
platform,
|
|
3512
3957
|
assetPath: body.url,
|
|
3513
3958
|
...(uploaded ? { upload: uploaded } : {}),
|
|
3514
3959
|
};
|
|
@@ -3530,13 +3975,255 @@ export async function subjectList(kwargs = {}) {
|
|
|
3530
3975
|
};
|
|
3531
3976
|
}
|
|
3532
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
|
+
|
|
3533
4208
|
function subjectAssetSpecs(kwargs = {}) {
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
{
|
|
3538
|
-
|
|
3539
|
-
|
|
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;
|
|
3540
4227
|
}
|
|
3541
4228
|
|
|
3542
4229
|
function subjectAssetPathForDryRun(item) {
|
|
@@ -3553,15 +4240,37 @@ function tagListFromArg(value) {
|
|
|
3553
4240
|
.filter((item) => item.tagId);
|
|
3554
4241
|
}
|
|
3555
4242
|
|
|
3556
|
-
|
|
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)) {
|
|
3557
4264
|
const name = requireValue(kwargs, 'name');
|
|
4265
|
+
const description = trimToNull(kwargs.description ?? kwargs.elementDescription) ?? name;
|
|
3558
4266
|
const primary = assets.find((item) => item.isPrimary);
|
|
3559
4267
|
const referAssets = assets.filter((item) => item.assetPath);
|
|
4268
|
+
const { modelCode } = modelCodeResolution;
|
|
3560
4269
|
return compactRecord({
|
|
3561
4270
|
reqTaskId: trimToNull(kwargs.reqTaskId),
|
|
3562
|
-
modelCode
|
|
4271
|
+
modelCode,
|
|
3563
4272
|
elementName: name,
|
|
3564
|
-
elementDescription:
|
|
4273
|
+
elementDescription: description,
|
|
3565
4274
|
elementFrontalImage: primary?.assetPath ?? null,
|
|
3566
4275
|
elementReferList: referAssets.map((item) => ({
|
|
3567
4276
|
imageUrl: item.assetPath,
|
|
@@ -3579,9 +4288,12 @@ function extractCreatedElementId(payload) {
|
|
|
3579
4288
|
return payload.id ?? payload.elementId ?? payload.subjectId ?? payload.reqTaskId ?? payload.data?.id ?? payload.data?.elementId ?? null;
|
|
3580
4289
|
}
|
|
3581
4290
|
|
|
3582
|
-
async function fetchSubjectByReqTaskId(reqTaskId) {
|
|
4291
|
+
async function fetchSubjectByReqTaskId(reqTaskId, options = {}) {
|
|
3583
4292
|
if (!reqTaskId) return null;
|
|
3584
|
-
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
|
+
});
|
|
3585
4297
|
return payload && typeof payload === 'object' ? normalizeSubjectRecord(payload) : null;
|
|
3586
4298
|
}
|
|
3587
4299
|
|
|
@@ -3590,7 +4302,7 @@ async function waitForSubjectExternalId(reqTaskId, options = {}) {
|
|
|
3590
4302
|
const pollIntervalMs = Math.max(500, toInt(options.pollIntervalMs, 2000));
|
|
3591
4303
|
const deadline = Date.now() + waitSeconds * 1000;
|
|
3592
4304
|
let latest = await fetchSubjectByReqTaskId(reqTaskId);
|
|
3593
|
-
while (waitSeconds > 0 && !latest?.externalId && Date.now() < deadline) {
|
|
4305
|
+
while (waitSeconds > 0 && !latest?.externalId && !subjectFailureDetails(latest, 'subject') && Date.now() < deadline) {
|
|
3594
4306
|
await sleep(pollIntervalMs);
|
|
3595
4307
|
latest = await fetchSubjectByReqTaskId(reqTaskId);
|
|
3596
4308
|
}
|
|
@@ -3604,7 +4316,10 @@ function subjectWaitPayload(elementId, subject) {
|
|
|
3604
4316
|
subjectId: externalId ?? elementId,
|
|
3605
4317
|
externalId,
|
|
3606
4318
|
nextRefSubject: externalId && subject?.name ? `${subject.name}=${externalId}` : null,
|
|
3607
|
-
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),
|
|
3608
4323
|
subject,
|
|
3609
4324
|
};
|
|
3610
4325
|
}
|
|
@@ -3613,8 +4328,9 @@ export async function subjectPublish(kwargs = {}) {
|
|
|
3613
4328
|
const name = requireValue(kwargs, 'name');
|
|
3614
4329
|
const specs = subjectAssetSpecs(kwargs);
|
|
3615
4330
|
if (!specs.some((item) => item.isPrimary)) {
|
|
3616
|
-
throw argumentError('缺少主体主参考图', '传 --primary
|
|
4331
|
+
throw argumentError('缺少主体主参考图', '传 --resource primary:<path|url>(或 --resource three-view:<path|url> 自动升为主图)。');
|
|
3617
4332
|
}
|
|
4333
|
+
const modelCodeResolution = resolveSubjectCreateModelCode(kwargs);
|
|
3618
4334
|
if (toBool(kwargs.dryRun)) {
|
|
3619
4335
|
const assets = specs.map((item) => ({
|
|
3620
4336
|
label: item.label,
|
|
@@ -3626,15 +4342,15 @@ export async function subjectPublish(kwargs = {}) {
|
|
|
3626
4342
|
}));
|
|
3627
4343
|
return {
|
|
3628
4344
|
dryRun: true,
|
|
3629
|
-
action: 'subject
|
|
4345
|
+
action: 'create subject',
|
|
3630
4346
|
name,
|
|
3631
|
-
request: buildSubjectCreateBody(kwargs, specs, assets),
|
|
4347
|
+
request: buildSubjectCreateBody(kwargs, specs, assets, modelCodeResolution),
|
|
3632
4348
|
assets,
|
|
3633
4349
|
localFiles: await inspectLocalFiles(specs.map((item) => item.file).filter(Boolean)),
|
|
3634
4350
|
nextRefSubject: `${name}=<externalId>`,
|
|
3635
4351
|
};
|
|
3636
4352
|
}
|
|
3637
|
-
ensureConfirmed(kwargs, '创建平台主体 element 是云端写入动作,需要确认', { action: 'subject
|
|
4353
|
+
ensureConfirmed(kwargs, '创建平台主体 element 是云端写入动作,需要确认', { action: 'create subject', name });
|
|
3638
4354
|
const assets = [];
|
|
3639
4355
|
for (const spec of specs) {
|
|
3640
4356
|
const uploaded = spec.file ? await uploadLocalFile(spec.file, { sceneType: TASK_UPLOAD_SCENE.SUBJECT }) : null;
|
|
@@ -3648,11 +4364,11 @@ export async function subjectPublish(kwargs = {}) {
|
|
|
3648
4364
|
...(uploaded ? { upload: uploaded } : {}),
|
|
3649
4365
|
});
|
|
3650
4366
|
}
|
|
3651
|
-
const body = buildSubjectCreateBody(kwargs, specs, assets);
|
|
4367
|
+
const body = buildSubjectCreateBody(kwargs, specs, assets, modelCodeResolution);
|
|
3652
4368
|
const payload = await awbApi.createElement(body);
|
|
3653
4369
|
const elementId = extractCreatedElementId(payload);
|
|
3654
4370
|
if (!elementId) throw new LingjingAwbCliError('主体创建完成但未拿到 elementId', { type: 'api_error', exitCode: 1, details: payload });
|
|
3655
|
-
const subject = await fetchSubjectByReqTaskId(elementId);
|
|
4371
|
+
const subject = await fetchSubjectByReqTaskId(elementId, { optional: true });
|
|
3656
4372
|
const waitPayload = subjectWaitPayload(elementId, subject);
|
|
3657
4373
|
return {
|
|
3658
4374
|
created: true,
|
|
@@ -3672,11 +4388,20 @@ export async function subjectWait(kwargs = {}) {
|
|
|
3672
4388
|
const elementId = requireValue(kwargs, 'elementId', 'element-id');
|
|
3673
4389
|
const subject = await waitForSubjectExternalId(elementId, kwargs);
|
|
3674
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
|
+
}
|
|
3675
4400
|
if (!payload.externalId) {
|
|
3676
4401
|
throw new LingjingAwbCliError('主体 externalId 尚未回填', {
|
|
3677
4402
|
type: 'subject_still_pending',
|
|
3678
4403
|
exitCode: 20,
|
|
3679
|
-
hint: '稍后重试 subject
|
|
4404
|
+
hint: '稍后重试 create subject-wait,或用 create subject-list --name 查询。',
|
|
3680
4405
|
details: payload,
|
|
3681
4406
|
});
|
|
3682
4407
|
}
|
|
@@ -3692,7 +4417,7 @@ export async function subjectPublishBatch(kwargs = {}) {
|
|
|
3692
4417
|
}
|
|
3693
4418
|
return { dryRun: true, count: items.length, results };
|
|
3694
4419
|
}
|
|
3695
|
-
ensureConfirmed(kwargs, '批量发布主体资产是云端写入动作,需要确认', { action: 'subject
|
|
4420
|
+
ensureConfirmed(kwargs, '批量发布主体资产是云端写入动作,需要确认', { action: 'create subject-batch', count: items.length });
|
|
3696
4421
|
const results = await runConcurrent(items, kwargs.concurrency ?? 1, async (item, index) => ({
|
|
3697
4422
|
inputIndex: index,
|
|
3698
4423
|
status: 'success',
|
|
@@ -3702,44 +4427,73 @@ export async function subjectPublishBatch(kwargs = {}) {
|
|
|
3702
4427
|
}
|
|
3703
4428
|
|
|
3704
4429
|
export async function subtitleRemove(kwargs = {}) {
|
|
3705
|
-
const
|
|
4430
|
+
const built = await buildSubtitleRemovalRequest(kwargs, { dryRun: toBool(kwargs.dryRun) });
|
|
3706
4431
|
if (toBool(kwargs.dryRun)) {
|
|
3707
|
-
return {
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
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,
|
|
3716
4443
|
});
|
|
3717
|
-
|
|
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,
|
|
3718
4449
|
submitted: true,
|
|
3719
|
-
|
|
3720
|
-
|
|
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
|
+
}),
|
|
3721
4489
|
};
|
|
3722
4490
|
}
|
|
3723
4491
|
|
|
3724
4492
|
export async function subtitleStatus(kwargs = {}) {
|
|
3725
|
-
const
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
: await awbApi.fetchSubtitleTaskByRemoteId(remoteTaskId);
|
|
3731
|
-
const resultUrls = uniqueNonEmpty([
|
|
3732
|
-
...parseListArg(payload?.result_url ?? payload?.resultUrl),
|
|
3733
|
-
...parseListArg(payload?.output_url ?? payload?.outputUrl),
|
|
3734
|
-
...parseListArg(payload?.url),
|
|
3735
|
-
]);
|
|
3736
|
-
return compactRecord({
|
|
3737
|
-
publicId: publicId ?? payload?.public_id ?? payload?.publicId ?? payload?.id ?? null,
|
|
3738
|
-
remoteTaskId: remoteTaskId ?? payload?.remote_task_id ?? payload?.remoteTaskId ?? null,
|
|
3739
|
-
taskStatus: payload?.status ?? payload?.taskStatus ?? payload?.state ?? null,
|
|
3740
|
-
isTerminal: isTerminalTaskStatus(payload?.status ?? payload?.taskStatus ?? payload?.state),
|
|
3741
|
-
resultCount: resultUrls.length,
|
|
3742
|
-
...(resultUrls.length ? { resultUrls } : {}),
|
|
3743
|
-
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',
|
|
3744
4498
|
});
|
|
3745
4499
|
}
|