@lingjingai/lj-awb-cli 0.3.12 → 0.3.14
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 +13 -8
- package/build/build.mjs +47 -0
- package/build/pre.mjs +78 -0
- package/build/prod.mjs +95 -0
- package/install.mjs +9 -3
- package/package.json +2 -1
- package/packages/awb-cli/package.json +2 -2
- package/packages/awb-core/package.json +1 -1
- package/packages/awb-core/src/commands.js +21 -8
- package/packages/awb-core/src/common.js +1 -1
- package/packages/awb-core/src/output.js +160 -23
- package/packages/awb-core/src/services.js +907 -128
- package/packages/awb-core/src/standalone.js +46 -12
- package/skills/lj-awb/SKILL.md +15 -10
- package/skills/lj-awb/VERSION +1 -1
- package/skills/lj-awb/compat.json +3 -3
- package/skills/lj-awb/modules/create-contract.md +23 -17
- package/skills/lj-awb/modules/credits.md +6 -4
- package/skills/lj-awb/modules/evals.md +42 -8
- package/skills/lj-awb/modules/image.md +10 -2
- package/skills/lj-awb/modules/model.md +16 -9
- package/skills/lj-awb/modules/project.md +1 -1
- package/skills/lj-awb/modules/task-manual.md +48 -13
- package/skills/lj-awb/modules/video.md +24 -14
- package/skills/lj-awb/modules/workflows.md +26 -14
- package/skills/lj-awb/references/model-options-read.md +15 -9
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
1
2
|
import crypto from 'node:crypto';
|
|
2
3
|
import fs from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
3
5
|
import path from 'node:path';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
4
7
|
import {
|
|
5
8
|
API_ORIGIN,
|
|
6
9
|
APP_HOME_DIR,
|
|
@@ -41,6 +44,8 @@ import * as awbApi from './api.js';
|
|
|
41
44
|
const SITE = 'lj-awb';
|
|
42
45
|
const REQUEST_SOURCE_CLI = 'LINGJING_AWB_CLI';
|
|
43
46
|
const DEFAULT_TASK_RECORD_FILE_ENV = process.env.LINGJING_AWB_TASK_RECORD_FILE || process.env.AWB_TASK_RECORD_FILE;
|
|
47
|
+
const execFileAsync = promisify(execFile);
|
|
48
|
+
const COMMON_IMAGE_FORMATS = new Set(['jpg', 'jpeg', 'jfif', 'png', 'webp']);
|
|
44
49
|
|
|
45
50
|
export function normalizeUserInfo(payload) {
|
|
46
51
|
const data = payload && typeof payload === 'object' ? payload : {};
|
|
@@ -204,12 +209,8 @@ export async function fetchProjectGroupSummary(projectGroupNo) {
|
|
|
204
209
|
projectGroupNo: actualProjectGroupNo,
|
|
205
210
|
projectGroupName: row?.projectGroupName ?? row?.name ?? null,
|
|
206
211
|
isSelected: actualProjectGroupNo === currentNo,
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
projectPointMax: integralPayload?.projectGroupIntegralMax ?? null,
|
|
210
|
-
personPointBalance: integralPayload?.personIntegralCurrent ?? null,
|
|
211
|
-
personPointMax: integralPayload?.personIntegralMax ?? null,
|
|
212
|
-
teamPointBalance: integralPayload?.teamIntegral ?? null,
|
|
212
|
+
projectBudgetBalance: integralPayload?.projectGroupIntegralCurrent ?? extractPointBalance(integralPayload),
|
|
213
|
+
projectBudgetMax: integralPayload?.projectGroupIntegralMax ?? null,
|
|
213
214
|
};
|
|
214
215
|
await saveState({
|
|
215
216
|
currentProjectGroupNo: summary.projectGroupNo,
|
|
@@ -235,9 +236,12 @@ export async function accountInfo() {
|
|
|
235
236
|
}).catch(() => {});
|
|
236
237
|
return {
|
|
237
238
|
...user,
|
|
239
|
+
billingPointBalance: extractPointBalance(pointPayload),
|
|
238
240
|
teamPointBalance: extractPointBalance(pointPayload),
|
|
239
241
|
currentProjectGroupNo: currentProjectGroup?.projectGroupNo ?? null,
|
|
240
242
|
currentProjectGroupName: currentProjectGroup?.projectGroupName ?? null,
|
|
243
|
+
projectBudgetBalance: currentProjectGroup?.projectBudgetBalance ?? currentProjectGroup?.projectPointBalance ?? null,
|
|
244
|
+
projectBudgetMax: currentProjectGroup?.projectBudgetMax ?? currentProjectGroup?.projectPointMax ?? null,
|
|
241
245
|
projectPointBalance: currentProjectGroup?.projectPointBalance ?? null,
|
|
242
246
|
projectPointMax: currentProjectGroup?.projectPointMax ?? null,
|
|
243
247
|
};
|
|
@@ -557,10 +561,14 @@ export async function creditsBalance(kwargs = {}) {
|
|
|
557
561
|
awbApi.fetchPoints(),
|
|
558
562
|
projectGroupNo ? fetchProjectGroupSummary(projectGroupNo).catch(() => null) : Promise.resolve(null),
|
|
559
563
|
]);
|
|
564
|
+
const billingPointBalance = extractPointBalance(teamPayload);
|
|
560
565
|
return {
|
|
561
|
-
|
|
566
|
+
billingPointBalance,
|
|
567
|
+
teamPointBalance: billingPointBalance,
|
|
562
568
|
currentProjectGroupNo: projectGroup?.projectGroupNo ?? projectGroupNo,
|
|
563
569
|
currentProjectGroupName: projectGroup?.projectGroupName ?? null,
|
|
570
|
+
projectBudgetBalance: projectGroup?.projectBudgetBalance ?? projectGroup?.projectPointBalance ?? null,
|
|
571
|
+
projectBudgetMax: projectGroup?.projectBudgetMax ?? projectGroup?.projectPointMax ?? null,
|
|
564
572
|
projectPointBalance: projectGroup?.projectPointBalance ?? null,
|
|
565
573
|
projectPointMax: projectGroup?.projectPointMax ?? null,
|
|
566
574
|
};
|
|
@@ -643,8 +651,7 @@ function modelListMetadata(kind, paramKeys = [], rulesByKey = new Map()) {
|
|
|
643
651
|
const keys = new Set(paramKeys);
|
|
644
652
|
const imageReferenceParams = ['cref', 'sref', 'iref', 'resources'].filter((key) => keys.has(key));
|
|
645
653
|
const videoResourceParams = ['frames', 'multi_param', 'multi_prompt'].filter((key) => keys.has(key));
|
|
646
|
-
const inputModes = createSpecInputModes(kind, keys, rulesByKey)
|
|
647
|
-
.filter((item) => item.supported)
|
|
654
|
+
const inputModes = createSpecSupportedIntents(createSpecInputModes(kind, keys, rulesByKey), kind)
|
|
648
655
|
.map((item) => item.mode);
|
|
649
656
|
const controls = [];
|
|
650
657
|
if (keys.has('ratio')) controls.push('ratio');
|
|
@@ -790,6 +797,408 @@ function modelSummaryFromRaw(rawModel = {}, modelGroupCode, taskKind) {
|
|
|
790
797
|
});
|
|
791
798
|
}
|
|
792
799
|
|
|
800
|
+
async function fetchModelConstraintSchema(rawModel = {}, modelGroupCode) {
|
|
801
|
+
const usage = trimToNull(rawModel?.usage);
|
|
802
|
+
if (!usage) return [];
|
|
803
|
+
const payload = await awbApi.fetchModelsByUsage(usage, { includeConstraintSchema: true }).catch(() => null);
|
|
804
|
+
const rows = normalizeRows(payload);
|
|
805
|
+
const found = rows.find((item) => (
|
|
806
|
+
item?.modelGroupCode === modelGroupCode
|
|
807
|
+
|| (rawModel?.modelCode && item?.modelCode === rawModel.modelCode)
|
|
808
|
+
));
|
|
809
|
+
return Array.isArray(found?.constraintSchema) ? found.constraintSchema : [];
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
function configCodeDecisionKey(code, taskKind = 'image') {
|
|
813
|
+
const normalized = String(code || '');
|
|
814
|
+
const mappings = {
|
|
815
|
+
generated_time: 'duration',
|
|
816
|
+
generate_num: 'generateNum',
|
|
817
|
+
need_audio: 'needAudio',
|
|
818
|
+
audio: 'needAudio',
|
|
819
|
+
frames: 'resource.image.frame',
|
|
820
|
+
multi_param: 'resource.reference',
|
|
821
|
+
multi_prompt: 'resource.keyframe',
|
|
822
|
+
iref: 'resource.image.reference',
|
|
823
|
+
cref: 'resource.image.reference',
|
|
824
|
+
sref: 'resource.image.reference',
|
|
825
|
+
resources: 'resource.image.reference',
|
|
826
|
+
generated_mode: 'generatedMode',
|
|
827
|
+
generate_mode: 'generatedMode',
|
|
828
|
+
};
|
|
829
|
+
if (normalized === 'prompt') return 'prompt';
|
|
830
|
+
if (normalized === 'ratio') return 'ratio';
|
|
831
|
+
if (normalized === 'quality') return 'quality';
|
|
832
|
+
if (taskKind === 'video' && normalized === 'duration') return 'duration';
|
|
833
|
+
return mappings[normalized] ?? normalized;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
function constraintTriggerMeaning(value) {
|
|
837
|
+
if (value === '__NOT_EMPTY__') return 'present';
|
|
838
|
+
if (value === '__EMPTY__') return 'empty';
|
|
839
|
+
return 'equals';
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function normalizeConstraintConditions(conditions = [], taskKind = 'image') {
|
|
843
|
+
return (Array.isArray(conditions) ? conditions : []).map((condition) => compactRecord({
|
|
844
|
+
key: configCodeDecisionKey(condition?.triggerConfigCode, taskKind),
|
|
845
|
+
configCode: condition?.triggerConfigCode,
|
|
846
|
+
value: condition?.triggerConfigValue,
|
|
847
|
+
meaning: constraintTriggerMeaning(condition?.triggerConfigValue),
|
|
848
|
+
}));
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
function normalizeModelConstraints(constraintSchema = [], taskKind = 'image') {
|
|
852
|
+
return (Array.isArray(constraintSchema) ? constraintSchema : []).map((constraint) => {
|
|
853
|
+
const allowValues = Array.isArray(constraint?.allowValues) ? constraint.allowValues : [];
|
|
854
|
+
return compactRecord({
|
|
855
|
+
id: constraint?.constraintId,
|
|
856
|
+
name: constraint?.constraintName,
|
|
857
|
+
target: configCodeDecisionKey(constraint?.targetConfigCode, taskKind),
|
|
858
|
+
targetConfigCode: constraint?.targetConfigCode,
|
|
859
|
+
allowValues,
|
|
860
|
+
effect: allowValues.length ? 'allow_only_values' : 'no_selectable_values',
|
|
861
|
+
priority: constraint?.priority,
|
|
862
|
+
conditions: normalizeConstraintConditions(constraint?.conditions, taskKind),
|
|
863
|
+
});
|
|
864
|
+
}).filter((constraint) => constraint.target || constraint.targetConfigCode);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
function resourceUsageList(usage) {
|
|
868
|
+
return (Array.isArray(usage) ? usage : [usage])
|
|
869
|
+
.map((item) => trimToNull(item))
|
|
870
|
+
.filter(Boolean);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function resourceMediaType(resource = {}) {
|
|
874
|
+
const type = String(resource.type || '').toLowerCase();
|
|
875
|
+
if (type === 'image') return 'IMAGE';
|
|
876
|
+
if (type === 'video') return 'VIDEO';
|
|
877
|
+
if (type === 'audio') return 'AUDIO';
|
|
878
|
+
if (type === 'subject') return 'SUBJECT';
|
|
879
|
+
return type.toUpperCase();
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
function resourceRuleMatches(rule = {}, resource = {}) {
|
|
883
|
+
return String(rule.mediaType || '').toUpperCase() === resourceMediaType(resource)
|
|
884
|
+
&& resourceUsageList(rule.usage).includes(resource.usage);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
function resourceText(resource = {}) {
|
|
888
|
+
return `${resource.type}:${resource.usage}${resource.reference_key ? `:${resource.reference_key}` : ''}`;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
function resourceSourceKindForValidation(detail = {}) {
|
|
892
|
+
if (detail.localFile) return 'local_file';
|
|
893
|
+
const source = detail.resource?.source || {};
|
|
894
|
+
if (source.kind === 'asset_id') return 'asset_id';
|
|
895
|
+
const value = trimToNull(source.value);
|
|
896
|
+
if (/^https?:\/\//i.test(value || '')) return 'http_url';
|
|
897
|
+
return 'backendPath';
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
function sourceAllowedByRule(rule = {}, sourceKind) {
|
|
901
|
+
const sources = Array.isArray(rule.sources) ? rule.sources : [];
|
|
902
|
+
if (!sources.length) return true;
|
|
903
|
+
return sources.includes(sourceKind);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
function resourceFormatForValidation(detail = {}) {
|
|
907
|
+
if (detail.localFile?.format) return String(detail.localFile.format).toLowerCase();
|
|
908
|
+
const value = detail.resource?.source?.value;
|
|
909
|
+
const pathname = (() => {
|
|
910
|
+
try {
|
|
911
|
+
return new URL(String(value)).pathname;
|
|
912
|
+
} catch {
|
|
913
|
+
return String(value || '').split('?')[0].split('#')[0];
|
|
914
|
+
}
|
|
915
|
+
})();
|
|
916
|
+
const ext = path.extname(pathname).replace(/^\./, '').toLowerCase();
|
|
917
|
+
return ext || null;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function normalizeFileFormat(value) {
|
|
921
|
+
const format = trimToNull(value)?.toLowerCase();
|
|
922
|
+
if (!format) return null;
|
|
923
|
+
if (format === 'jpeg' || format === 'jfif') return 'jpg';
|
|
924
|
+
return format;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
function normalizedFileTypes(fileTypes = []) {
|
|
928
|
+
return Array.isArray(fileTypes)
|
|
929
|
+
? uniqueNonEmpty(fileTypes.map((item) => normalizeFileFormat(item)))
|
|
930
|
+
: [];
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
function fileTypeIncludes(fileTypes = [], format) {
|
|
934
|
+
const normalized = normalizeFileFormat(format);
|
|
935
|
+
if (!normalized) return true;
|
|
936
|
+
return normalizedFileTypes(fileTypes).includes(normalized);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
function isImageRule(rule = {}) {
|
|
940
|
+
return String(rule.mediaType || '').toUpperCase() === 'IMAGE';
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function imageFormatPolicy(fileTypes = []) {
|
|
944
|
+
const types = normalizedFileTypes(fileTypes);
|
|
945
|
+
if (!types.length) {
|
|
946
|
+
return {
|
|
947
|
+
kind: 'normal_without_webp',
|
|
948
|
+
webpSupported: false,
|
|
949
|
+
autoConvertTo: 'jpg',
|
|
950
|
+
strict: false,
|
|
951
|
+
summary: 'normal_without_webp',
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
if (types.length === 1 && types[0] === 'webp') {
|
|
955
|
+
return {
|
|
956
|
+
kind: 'normal_plus_webp',
|
|
957
|
+
webpSupported: true,
|
|
958
|
+
strict: false,
|
|
959
|
+
summary: 'normal_plus_webp',
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
return {
|
|
963
|
+
kind: 'strict',
|
|
964
|
+
webpSupported: types.includes('webp'),
|
|
965
|
+
allowed: types,
|
|
966
|
+
autoConvertTo: preferredImageConversionTarget(types),
|
|
967
|
+
strict: true,
|
|
968
|
+
summary: `strict:${types.join('|')}`,
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
function preferredImageConversionTarget(fileTypes = []) {
|
|
973
|
+
const types = normalizedFileTypes(fileTypes);
|
|
974
|
+
if (types.includes('jpg')) return 'jpg';
|
|
975
|
+
if (types.includes('png')) return 'png';
|
|
976
|
+
if (types.includes('webp')) return 'webp';
|
|
977
|
+
return types[0] || 'jpg';
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
function isConvertibleLocalImage(detail = {}) {
|
|
981
|
+
return Boolean(detail.localFile?.exists && String(detail.localFile?.mimeType || '').startsWith('image/'));
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
function resourceFormatConversion(rule = {}, detail = {}) {
|
|
985
|
+
if (!isImageRule(rule)) return null;
|
|
986
|
+
const format = normalizeFileFormat(resourceFormatForValidation(detail));
|
|
987
|
+
if (!format) return null;
|
|
988
|
+
const policy = imageFormatPolicy(rule.fileTypes);
|
|
989
|
+
if (policy.kind === 'normal_without_webp') {
|
|
990
|
+
if (format !== 'webp') return null;
|
|
991
|
+
return {
|
|
992
|
+
fromFormat: format,
|
|
993
|
+
toFormat: policy.autoConvertTo,
|
|
994
|
+
reason: 'image_webp_not_supported',
|
|
995
|
+
possible: isConvertibleLocalImage(detail),
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
if (policy.kind === 'normal_plus_webp') return null;
|
|
999
|
+
if (!policy.strict || fileTypeIncludes(policy.allowed, format)) return null;
|
|
1000
|
+
return {
|
|
1001
|
+
fromFormat: format,
|
|
1002
|
+
toFormat: policy.autoConvertTo,
|
|
1003
|
+
reason: 'image_strict_format_mismatch',
|
|
1004
|
+
possible: isConvertibleLocalImage(detail),
|
|
1005
|
+
allowed: policy.allowed,
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function fileTypeAllowedByRule(rule = {}, format) {
|
|
1010
|
+
const fileTypes = normalizedFileTypes(rule.fileTypes);
|
|
1011
|
+
if (!format) return true;
|
|
1012
|
+
if (isImageRule(rule)) {
|
|
1013
|
+
const policy = imageFormatPolicy(fileTypes);
|
|
1014
|
+
if (policy.kind === 'normal_without_webp') return normalizeFileFormat(format) !== 'webp';
|
|
1015
|
+
if (policy.kind === 'normal_plus_webp') return COMMON_IMAGE_FORMATS.has(normalizeFileFormat(format));
|
|
1016
|
+
return fileTypeIncludes(policy.allowed, format);
|
|
1017
|
+
}
|
|
1018
|
+
if (!fileTypes.length) return true;
|
|
1019
|
+
return fileTypeIncludes(fileTypes, format);
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
function assertResourceShapeAgainstModel(resourceDetails = [], resourceRules = []) {
|
|
1023
|
+
for (const [index, detail] of resourceDetails.entries()) {
|
|
1024
|
+
const resource = detail.resource;
|
|
1025
|
+
const rule = resourceRules.find((item) => resourceRuleMatches(item, resource));
|
|
1026
|
+
if (!rule) {
|
|
1027
|
+
throw argumentError(
|
|
1028
|
+
`模型不支持素材输入:${resourceText(resource)}`,
|
|
1029
|
+
'请先运行 model options --model-group-code <code>,只使用 resources[] 中列出的 media/usage;上传音频参考必须存在 media=AUDIO usage=reference。',
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
const sourceKind = resourceSourceKindForValidation(detail);
|
|
1033
|
+
if (!sourceAllowedByRule(rule, sourceKind)) {
|
|
1034
|
+
throw argumentError(
|
|
1035
|
+
`模型不支持 ${resourceText(resource)} 的来源:${sourceKind}`,
|
|
1036
|
+
`该资源允许来源:${(rule.sources || []).join(', ') || '未限制'}。`,
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
const format = resourceFormatForValidation(detail);
|
|
1040
|
+
const conversion = resourceFormatConversion(rule, detail);
|
|
1041
|
+
if (conversion && !conversion.possible) {
|
|
1042
|
+
throw argumentError(
|
|
1043
|
+
`素材格式需要转换但无法自动处理:${resourceText(resource)}`,
|
|
1044
|
+
`当前格式 ${conversion.fromFormat},目标格式 ${conversion.toFormat};请使用本地文件,或先转换后再传远程 URL / asset。`,
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
if (!conversion && !fileTypeAllowedByRule(rule, format)) {
|
|
1048
|
+
throw argumentError(
|
|
1049
|
+
`模型不支持 ${resourceText(resource)} 的文件格式:${format}`,
|
|
1050
|
+
`该资源允许格式:${(rule.fileTypes || []).join(', ')}。`,
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
if (detail.localFile?.size != null && rule.maxSizeKB != null && detail.localFile.size > rule.maxSizeKB * 1024) {
|
|
1054
|
+
throw argumentError(
|
|
1055
|
+
`素材超过模型大小限制:${resourceText(resource)}`,
|
|
1056
|
+
`文件大小 ${(detail.localFile.size / 1024).toFixed(0)}KB,模型限制 <=${rule.maxSizeKB}KB。`,
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
if (resource.usage === 'keyframe') {
|
|
1060
|
+
if (rule.maxPromptLength != null && resource.prompt && resource.prompt.length > rule.maxPromptLength) {
|
|
1061
|
+
throw argumentError(`keyframe prompt 超过模型长度限制:${resource.prompt.length}/${rule.maxPromptLength}`);
|
|
1062
|
+
}
|
|
1063
|
+
if (rule.minDurationMs != null && resource.duration != null && resource.duration * 1000 < rule.minDurationMs) {
|
|
1064
|
+
throw argumentError(`keyframe duration 小于模型限制:${resource.duration}s`, `最小 ${(rule.minDurationMs / 1000).toFixed(3).replace(/\.?0+$/, '')}s。`);
|
|
1065
|
+
}
|
|
1066
|
+
if (rule.maxDurationMs != null && resource.duration != null && resource.duration * 1000 > rule.maxDurationMs) {
|
|
1067
|
+
throw argumentError(`keyframe duration 超过模型限制:${resource.duration}s`, `最大 ${(rule.maxDurationMs / 1000).toFixed(3).replace(/\.?0+$/, '')}s。`);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
function assertResourceCountsAgainstModel(resourceDetails = [], resourceRules = []) {
|
|
1074
|
+
for (const rule of resourceRules) {
|
|
1075
|
+
const matches = resourceDetails.filter((detail) => resourceRuleMatches(rule, detail.resource));
|
|
1076
|
+
if (!matches.length) continue;
|
|
1077
|
+
const count = matches.length;
|
|
1078
|
+
const minCount = rule.minFiles ?? rule.minItems;
|
|
1079
|
+
const maxCount = rule.maxFiles ?? rule.maxItems;
|
|
1080
|
+
if (minCount != null && count < minCount) {
|
|
1081
|
+
throw argumentError(`模型素材数量不足:${rule.mediaType}:${resourceUsageList(rule.usage).join('|')}`, `当前 ${count} 个,至少 ${minCount} 个。`);
|
|
1082
|
+
}
|
|
1083
|
+
if (maxCount != null && count > maxCount) {
|
|
1084
|
+
throw argumentError(`模型素材数量超限:${rule.mediaType}:${resourceUsageList(rule.usage).join('|')}`, `当前 ${count} 个,最多 ${maxCount} 个。`);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
const firstFrames = resourceDetails.filter((detail) => detail.resource.type === 'image' && detail.resource.usage === 'first_frame');
|
|
1089
|
+
const lastFrames = resourceDetails.filter((detail) => detail.resource.type === 'image' && detail.resource.usage === 'last_frame');
|
|
1090
|
+
if (firstFrames.length > 1) throw argumentError('同一请求最多只能有 1 个 first_frame');
|
|
1091
|
+
if (lastFrames.length > 1) throw argumentError('同一请求最多只能有 1 个 last_frame');
|
|
1092
|
+
if (lastFrames.length && !firstFrames.length) {
|
|
1093
|
+
const frameRule = resourceRules.find((rule) => (
|
|
1094
|
+
String(rule.mediaType || '').toUpperCase() === 'IMAGE'
|
|
1095
|
+
&& resourceUsageList(rule.usage).includes('last_frame')
|
|
1096
|
+
));
|
|
1097
|
+
if (frameRule?.supportLastFrameOnly !== true) {
|
|
1098
|
+
throw argumentError('当前模型不支持仅尾帧输入', '请同时提供 image:first_frame,或换用 supportLastFrameOnly=true 的模型。');
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
const keyframes = resourceDetails.filter((detail) => detail.resource.usage === 'keyframe');
|
|
1103
|
+
const orders = new Set();
|
|
1104
|
+
for (const detail of keyframes) {
|
|
1105
|
+
const order = detail.resource.order;
|
|
1106
|
+
if (orders.has(order)) throw argumentError(`keyframe order 重复:${order}`);
|
|
1107
|
+
orders.add(order);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
function promptParamValue(promptParams = {}, key) {
|
|
1112
|
+
if (key === 'duration') return promptParams.duration;
|
|
1113
|
+
if (key === 'generateNum') return promptParams.generate_num;
|
|
1114
|
+
if (key === 'needAudio') return promptParams.need_audio;
|
|
1115
|
+
return promptParams[key];
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
function providedPromptParamKeys(promptParams = {}) {
|
|
1119
|
+
const keys = [];
|
|
1120
|
+
for (const key of ['prompt', 'ratio', 'quality', 'duration', 'generateNum', 'needAudio']) {
|
|
1121
|
+
const value = promptParamValue(promptParams, key);
|
|
1122
|
+
if (value !== undefined && value !== null && value !== '') keys.push(key);
|
|
1123
|
+
}
|
|
1124
|
+
return keys;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
function inferGeneratedMode(resources = []) {
|
|
1128
|
+
if (resources.some((resource) => resource.usage === 'keyframe')) return 'multi_prompt';
|
|
1129
|
+
if (resources.some((resource) => ['first_frame', 'last_frame'].includes(resource.usage))) return 'frames';
|
|
1130
|
+
if (resources.some((resource) => resource.usage === 'reference')) return 'multi_param';
|
|
1131
|
+
return null;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
function conditionValue(condition = {}, promptParams = {}) {
|
|
1135
|
+
const resources = Array.isArray(promptParams.resources) ? promptParams.resources : [];
|
|
1136
|
+
if (condition.key === 'resource.image.frame') return resources.some((resource) => resource.type === 'image' && ['first_frame', 'last_frame'].includes(resource.usage));
|
|
1137
|
+
if (condition.key === 'resource.reference') return resources.some((resource) => resource.usage === 'reference');
|
|
1138
|
+
if (condition.key === 'resource.keyframe') return resources.some((resource) => resource.usage === 'keyframe');
|
|
1139
|
+
if (condition.key === 'generatedMode') return inferGeneratedMode(resources);
|
|
1140
|
+
return promptParamValue(promptParams, condition.key);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
function constraintConditionMatches(condition = {}, promptParams = {}) {
|
|
1144
|
+
const actual = conditionValue(condition, promptParams);
|
|
1145
|
+
if (condition.meaning === 'present') return actual !== undefined && actual !== null && actual !== '' && actual !== false;
|
|
1146
|
+
if (condition.meaning === 'empty') return actual === undefined || actual === null || actual === '' || actual === false;
|
|
1147
|
+
return String(actual ?? '') === String(condition.value ?? '');
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
function assertParamsAgainstModel(promptParams = {}, params = [], constraints = []) {
|
|
1151
|
+
const paramByKey = new Map(params.map((item) => [item.key, item]));
|
|
1152
|
+
for (const key of providedPromptParamKeys(promptParams)) {
|
|
1153
|
+
const param = paramByKey.get(key);
|
|
1154
|
+
if (!param) {
|
|
1155
|
+
throw argumentError(`模型不支持参数:${key}`, '请先运行 model options,只传 params[] 中暴露的参数。');
|
|
1156
|
+
}
|
|
1157
|
+
const value = promptParamValue(promptParams, key);
|
|
1158
|
+
if (Array.isArray(param.values) && param.values.length && !param.values.map(String).includes(String(value))) {
|
|
1159
|
+
throw argumentError(`参数 ${key} 不在模型允许值中:${value}`, `允许值:${param.values.join(', ')}。`);
|
|
1160
|
+
}
|
|
1161
|
+
if (param.maxLength != null && typeof value === 'string' && value.length > param.maxLength) {
|
|
1162
|
+
throw argumentError(`参数 ${key} 超过模型长度限制:${value.length}/${param.maxLength}`);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
for (const constraint of constraints) {
|
|
1167
|
+
const conditions = Array.isArray(constraint.conditions) ? constraint.conditions : [];
|
|
1168
|
+
if (!conditions.length || !conditions.every((condition) => constraintConditionMatches(condition, promptParams))) continue;
|
|
1169
|
+
const target = constraint.target;
|
|
1170
|
+
const value = promptParamValue(promptParams, target);
|
|
1171
|
+
if (value === undefined || value === null || value === '') continue;
|
|
1172
|
+
const allowedValues = Array.isArray(constraint.allowValues) ? constraint.allowValues : [];
|
|
1173
|
+
if (!allowedValues.length) {
|
|
1174
|
+
throw argumentError(`当前输入触发模型约束,不能传参数:${target}`, `约束:${constraint.name || constraint.targetConfigCode || target}。`);
|
|
1175
|
+
}
|
|
1176
|
+
if (!allowedValues.map(String).includes(String(value))) {
|
|
1177
|
+
throw argumentError(`参数 ${target} 不满足当前输入触发的模型约束:${value}`, `允许值:${allowedValues.join(', ')}。`);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
async function validateCreateRequestAgainstModel(kind, modelGroupCode, promptParams = {}, resourceDetails = []) {
|
|
1183
|
+
const context = await loadModelOptionContext(modelGroupCode, { includeConstraintSchema: true });
|
|
1184
|
+
if (context.taskKind !== kind) {
|
|
1185
|
+
throw argumentError(`模型任务类型不匹配:${context.taskKind}`, `当前命令是 ${kind} create,请换用对应任务类型的模型。`);
|
|
1186
|
+
}
|
|
1187
|
+
const params = modelOptionParams(context.options, context.taskKind);
|
|
1188
|
+
const resources = modelOptionsResources(context.inputModes);
|
|
1189
|
+
assertParamsAgainstModel(promptParams, params, context.constraints);
|
|
1190
|
+
assertResourceShapeAgainstModel(resourceDetails, resources);
|
|
1191
|
+
assertResourceCountsAgainstModel(resourceDetails, resources);
|
|
1192
|
+
if (kind === 'video') {
|
|
1193
|
+
const supportedIntents = createSpecSupportedIntents(context.inputModes, context.taskKind);
|
|
1194
|
+
const inputRequirement = createSpecInputRequirement(context.taskKind, context.inputModes, supportedIntents);
|
|
1195
|
+
if (inputRequirement.visualInputRequired && !resourceDetails.length) {
|
|
1196
|
+
throw argumentError('当前视频模型不能只传 prompt 创建', `必须选择一种受支持的素材输入:${inputRequirement.acceptedModes?.join(', ') || 'reference/frames/storyboard'}。`);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
return { context, params, resourceRules: resources };
|
|
1200
|
+
}
|
|
1201
|
+
|
|
793
1202
|
async function loadModelOptionContext(modelGroupCode, options = {}) {
|
|
794
1203
|
const rawModel = await awbApi.fetchModelGroupInfoAll(modelGroupCode);
|
|
795
1204
|
const rawOptions = normalizeRawModelOptions(rawModel, { includeRaw: options.includeRaw });
|
|
@@ -809,10 +1218,15 @@ async function loadModelOptionContext(modelGroupCode, options = {}) {
|
|
|
809
1218
|
const rulesByKey = new Map(mergedOptions.map((item) => [item.paramKey, item.rules]).filter(([key, rules]) => key && rules));
|
|
810
1219
|
const inputModes = createSpecInputModes(taskKind, optionKeys, rulesByKey);
|
|
811
1220
|
const createParams = mergedOptions.map((option) => createParamForModelOption(option, taskKind));
|
|
1221
|
+
const constraintSchema = options.includeConstraintSchema
|
|
1222
|
+
? await fetchModelConstraintSchema(rawModel, modelGroupCode)
|
|
1223
|
+
: [];
|
|
812
1224
|
return {
|
|
813
1225
|
rawModel,
|
|
814
1226
|
model: modelSummaryFromRaw(rawModel, modelGroupCode, taskKind),
|
|
815
1227
|
options: mergedOptions,
|
|
1228
|
+
constraintSchema,
|
|
1229
|
+
constraints: normalizeModelConstraints(constraintSchema, taskKind),
|
|
816
1230
|
optionKeys,
|
|
817
1231
|
rulesByKey,
|
|
818
1232
|
taskKind,
|
|
@@ -864,11 +1278,29 @@ function normalizeMediaRule(rule = {}) {
|
|
|
864
1278
|
minItems: ruleNumber(rule.minPromptNum),
|
|
865
1279
|
maxItems: ruleNumber(rule.maxPromptNum),
|
|
866
1280
|
maxPromptLength: ruleNumber(rule.maxPromptLength),
|
|
867
|
-
|
|
1281
|
+
supportLastFrameOnly: rule.supportLastFrame,
|
|
868
1282
|
required: rule.required,
|
|
869
1283
|
});
|
|
870
1284
|
}
|
|
871
1285
|
|
|
1286
|
+
function frameRuleCapabilities(rule = {}) {
|
|
1287
|
+
const maxFrameNum = ruleNumber(rule.maxFrameNum ?? rule.fileListMaxNum);
|
|
1288
|
+
const minFrameNum = ruleNumber(rule.minFrameNum ?? rule.fileListMinNum);
|
|
1289
|
+
const supportLastFrameOnly = rule.supportLastFrame === true;
|
|
1290
|
+
const supportsFirstFrame = maxFrameNum == null || maxFrameNum >= 1;
|
|
1291
|
+
const supportsFirstLastFrame = maxFrameNum != null && maxFrameNum >= 2;
|
|
1292
|
+
const usages = ['first_frame'];
|
|
1293
|
+
if (supportsFirstLastFrame || supportLastFrameOnly) usages.push('last_frame');
|
|
1294
|
+
return compactRecord({
|
|
1295
|
+
minFrameNum,
|
|
1296
|
+
maxFrameNum,
|
|
1297
|
+
supportsFirstFrame,
|
|
1298
|
+
supportsFirstLastFrame,
|
|
1299
|
+
supportLastFrameOnly,
|
|
1300
|
+
usages,
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
|
|
872
1304
|
function mediaRuleFromMultiParam(rules = {}, mediaType) {
|
|
873
1305
|
const resources = Array.isArray(rules?.resources) ? rules.resources : [];
|
|
874
1306
|
const found = resources.find((item) => String(item?.mediaType || '').toUpperCase() === mediaType);
|
|
@@ -947,8 +1379,8 @@ function createParamForModelOption(option = {}, taskKind = 'image') {
|
|
|
947
1379
|
cliArg: '--need-audio',
|
|
948
1380
|
requestPath: 'promptParams.need_audio',
|
|
949
1381
|
materialLegacyKey: 'need_audio',
|
|
950
|
-
meaning: '
|
|
951
|
-
valueSource: '布尔值 true / false
|
|
1382
|
+
meaning: '是否需要输出音效 / 模型生成音频。',
|
|
1383
|
+
valueSource: '布尔值 true / false;仅模型配置存在该项且用户明确要求输出音效时使用。它不是上传音频文件的入口。',
|
|
952
1384
|
controlKind: 'output_audio_toggle',
|
|
953
1385
|
},
|
|
954
1386
|
audio: {
|
|
@@ -956,8 +1388,8 @@ function createParamForModelOption(option = {}, taskKind = 'image') {
|
|
|
956
1388
|
cliArg: '--need-audio',
|
|
957
1389
|
requestPath: 'promptParams.need_audio',
|
|
958
1390
|
materialLegacyKey: 'audio',
|
|
959
|
-
meaning: '
|
|
960
|
-
valueSource: '布尔值 true / false
|
|
1391
|
+
meaning: '是否需要输出音效 / 模型生成音频。',
|
|
1392
|
+
valueSource: '布尔值 true / false;仅模型配置存在该项且用户明确要求输出音效时使用。它不是上传音频文件的入口。',
|
|
961
1393
|
controlKind: 'output_audio_toggle',
|
|
962
1394
|
},
|
|
963
1395
|
iref: {
|
|
@@ -992,11 +1424,13 @@ function createParamForModelOption(option = {}, taskKind = 'image') {
|
|
|
992
1424
|
cliArg: '--resource / --resources-json',
|
|
993
1425
|
requestPath: 'promptParams.resources[]',
|
|
994
1426
|
materialLegacyKey: 'multi_param',
|
|
995
|
-
meaning: '
|
|
996
|
-
valueSource: '
|
|
1427
|
+
meaning: '参考模式输入;图片、视频、音频和主体都用 type=...、usage=reference 表达。',
|
|
1428
|
+
valueSource: 'reference_key 是可选绑定。prompt 可以不写占位符;如果写了 <<<key>>>,必须能匹配同名 reference 资源。',
|
|
997
1429
|
resourceSyntax: [
|
|
1430
|
+
'image:reference=./hero.png',
|
|
998
1431
|
'image:reference:hero=./hero.png',
|
|
999
1432
|
'image:reference:hero=asset:<assetId>',
|
|
1433
|
+
'video:reference=./motion.mp4',
|
|
1000
1434
|
'video:reference:motion=./motion.mp4',
|
|
1001
1435
|
'audio:reference=./music.mp3',
|
|
1002
1436
|
'audio:reference:voice=./voice.wav',
|
|
@@ -1063,16 +1497,22 @@ function createSpecInputModes(taskKind, optionKeys, rulesByKey = new Map()) {
|
|
|
1063
1497
|
const supportsMultiImage = supportsMultiMedia('IMAGE');
|
|
1064
1498
|
const supportsMultiVideo = supportsMultiMedia('VIDEO');
|
|
1065
1499
|
const supportsMultiAudio = supportsMultiMedia('AUDIO');
|
|
1066
|
-
const
|
|
1067
|
-
const
|
|
1500
|
+
const frameCapabilities = frameRuleCapabilities(framesRules);
|
|
1501
|
+
const frameOptionResourceLimits = normalizeMediaRule(framesRules);
|
|
1502
|
+
const supportsFirstFrame = hasFrames && frameCapabilities.supportsFirstFrame !== false;
|
|
1503
|
+
const supportsFirstLastFrame = hasFrames && frameCapabilities.supportsFirstLastFrame === true;
|
|
1504
|
+
const supportLastFrameOnly = hasFrames && frameCapabilities.supportLastFrameOnly === true;
|
|
1505
|
+
const frameMinFiles = frameOptionResourceLimits.minFiles ?? 0;
|
|
1506
|
+
const framesRequired = hasFrames && (framesRules.required === true || frameMinFiles > 0);
|
|
1507
|
+
const videoPromptOnlyBlocked = taskKind === 'video' && hasPrompt && (framesRequired || hasMultiParam || hasMultiPrompt);
|
|
1068
1508
|
const modes = [];
|
|
1069
1509
|
modes.push({
|
|
1070
1510
|
mode: 'prompt_only',
|
|
1071
|
-
supported: taskKind === 'image' ? hasPrompt : hasPrompt && !
|
|
1511
|
+
supported: taskKind === 'image' ? hasPrompt : hasPrompt && !videoPromptOnlyBlocked,
|
|
1072
1512
|
intent: taskKind === 'image' ? '文生图' : '文生视频',
|
|
1073
1513
|
requiredArgs: ['--model-group-code', '--prompt'],
|
|
1074
1514
|
userInput: '只提供 prompt,不提供参考素材。',
|
|
1075
|
-
...(videoPromptOnlyBlocked ? { unsupportedReason: '该视频模型配置要求在 frames 或
|
|
1515
|
+
...(videoPromptOnlyBlocked ? { unsupportedReason: '该视频模型配置要求在 reference、frames 或 storyboard 模式中选择一种素材输入,不能只传 prompt。' } : {}),
|
|
1076
1516
|
});
|
|
1077
1517
|
modes.push({
|
|
1078
1518
|
mode: 'reference_image',
|
|
@@ -1080,17 +1520,17 @@ function createSpecInputModes(taskKind, optionKeys, rulesByKey = new Map()) {
|
|
|
1080
1520
|
intent: taskKind === 'image' ? '参考图生图 / 图像编辑式生成' : '参考图生视频',
|
|
1081
1521
|
requiredArgs: taskKind === 'image'
|
|
1082
1522
|
? ['--model-group-code', '--prompt', '--resource image:reference=...']
|
|
1083
|
-
: ['--model-group-code', '--prompt', '--resource image:reference
|
|
1523
|
+
: ['--model-group-code', '--prompt', '--resource image:reference[:key]=...'],
|
|
1084
1524
|
userInput: taskKind === 'image' ? '用户提供参考图,希望生成或编辑图片。' : '用户提供参考图,希望参考图中主体、风格或构图生成视频。',
|
|
1085
1525
|
resourceSyntax: taskKind === 'image'
|
|
1086
1526
|
? ['image:reference=./ref.png']
|
|
1087
1527
|
: ['image:reference:hero=./hero.png', 'image:reference:hero=asset:<assetId>'],
|
|
1088
|
-
requiredResources: taskKind === 'image' ? ['image:reference'] : ['image:reference
|
|
1528
|
+
requiredResources: taskKind === 'image' ? ['image:reference'] : ['image:reference[:key]'],
|
|
1089
1529
|
sourceKinds: taskKind === 'image' ? ['local_file', 'http_url', 'backendPath'] : ['local_file', 'http_url', 'backendPath', 'asset_id'],
|
|
1090
1530
|
resourceLimits: taskKind === 'image' ? normalizeMediaRule(imageReferenceRules) : mediaRuleFromMultiParam(multiParamRules, 'IMAGE'),
|
|
1091
|
-
promptBinding: taskKind === 'video' ? '
|
|
1092
|
-
promptPlaceholder: taskKind === 'video' ? '
|
|
1093
|
-
resourceConstraints: taskKind === 'video' ? ['
|
|
1531
|
+
promptBinding: taskKind === 'video' ? 'optional_key' : 'none',
|
|
1532
|
+
promptPlaceholder: taskKind === 'video' ? 'reference_key 可选;prompt 中写了 <<<key>>> 时必须有同名 image reference。' : null,
|
|
1533
|
+
resourceConstraints: taskKind === 'video' ? ['reference_key_optional', 'if_prompt_has_key_then_resource_must_exist'] : [],
|
|
1094
1534
|
...((taskKind === 'image' ? !hasImageReference : !supportsMultiImage) ? { unsupportedReason: '模型配置没有对应参考图片资源参数。' } : {}),
|
|
1095
1535
|
});
|
|
1096
1536
|
if (taskKind === 'video') {
|
|
@@ -1106,27 +1546,27 @@ function createSpecInputModes(taskKind, optionKeys, rulesByKey = new Map()) {
|
|
|
1106
1546
|
resourceLimits: mediaRuleFromMultiParam(multiParamRules, 'AUDIO'),
|
|
1107
1547
|
promptBinding: 'optional_key',
|
|
1108
1548
|
promptPlaceholder: '普通音频参考可不写 key;当用户强调音频也要参考 / 显式绑定音频时,可用 audio:reference:<key> 并在 prompt 中包含同名 <<<key>>>。',
|
|
1109
|
-
resourceConstraints: ['use_resource_not_need_audio', '
|
|
1549
|
+
resourceConstraints: ['use_resource_not_need_audio', 'if_prompt_has_key_then_resource_must_exist'],
|
|
1110
1550
|
...(!supportsMultiAudio ? { unsupportedReason: '模型配置没有音频参考资源规则。' } : {}),
|
|
1111
1551
|
});
|
|
1112
1552
|
modes.push({
|
|
1113
1553
|
mode: 'reference_video',
|
|
1114
1554
|
supported: supportsMultiVideo,
|
|
1115
1555
|
intent: '参考视频生视频',
|
|
1116
|
-
requiredArgs: ['--model-group-code', '--prompt', '--resource video:reference
|
|
1556
|
+
requiredArgs: ['--model-group-code', '--prompt', '--resource video:reference[:key]=...'],
|
|
1117
1557
|
userInput: '用户提供参考视频,希望参考运动、节奏或镜头生成视频。',
|
|
1118
1558
|
resourceSyntax: ['video:reference:motion=./motion.mp4', 'video:reference:motion=asset:<assetId>'],
|
|
1119
|
-
requiredResources: ['video:reference
|
|
1559
|
+
requiredResources: ['video:reference[:key]'],
|
|
1120
1560
|
sourceKinds: ['local_file', 'http_url', 'backendPath', 'asset_id'],
|
|
1121
1561
|
resourceLimits: mediaRuleFromMultiParam(multiParamRules, 'VIDEO'),
|
|
1122
|
-
promptBinding: '
|
|
1123
|
-
promptPlaceholder: '
|
|
1124
|
-
resourceConstraints: ['
|
|
1562
|
+
promptBinding: 'optional_key',
|
|
1563
|
+
promptPlaceholder: 'reference_key 可选;prompt 中写了 <<<key>>> 时必须有同名 video reference。',
|
|
1564
|
+
resourceConstraints: ['reference_key_optional', 'if_prompt_has_key_then_resource_must_exist'],
|
|
1125
1565
|
...(!supportsMultiVideo ? { unsupportedReason: '模型配置没有视频参考资源规则。' } : {}),
|
|
1126
1566
|
});
|
|
1127
1567
|
modes.push({
|
|
1128
1568
|
mode: 'first_frame',
|
|
1129
|
-
supported:
|
|
1569
|
+
supported: supportsFirstFrame,
|
|
1130
1570
|
intent: '首帧生视频',
|
|
1131
1571
|
requiredArgs: ['--model-group-code', '--resource image:first_frame=...'],
|
|
1132
1572
|
userInput: '用户提供起始画面,希望从这张图延展成视频。',
|
|
@@ -1134,14 +1574,17 @@ function createSpecInputModes(taskKind, optionKeys, rulesByKey = new Map()) {
|
|
|
1134
1574
|
requiredResources: ['image:first_frame'],
|
|
1135
1575
|
sourceKinds: ['local_file', 'http_url', 'backendPath', 'asset_id'],
|
|
1136
1576
|
resourceLimits: mergeResourceLimits(normalizeMediaRule(framesRules), { minFiles: 1, maxFiles: 1 }),
|
|
1577
|
+
optionResourceLimits: frameOptionResourceLimits,
|
|
1578
|
+
optionResourceUsages: frameCapabilities.usages,
|
|
1137
1579
|
promptBinding: 'none',
|
|
1138
1580
|
promptPlaceholder: '不需要 <<<key>>> 占位符。',
|
|
1139
1581
|
resourceConstraints: ['last_frame_not_required', 'key_not_used'],
|
|
1140
|
-
|
|
1582
|
+
supportLastFrameOnly,
|
|
1583
|
+
...(!hasFrames ? { unsupportedReason: '模型配置没有 frames 参数。' } : (!supportsFirstFrame ? { unsupportedReason: '模型配置 frames.maxFrameNum 小于 1。' } : {})),
|
|
1141
1584
|
});
|
|
1142
1585
|
modes.push({
|
|
1143
1586
|
mode: 'first_last_frame',
|
|
1144
|
-
supported:
|
|
1587
|
+
supported: supportsFirstLastFrame,
|
|
1145
1588
|
intent: '首尾帧过渡生视频',
|
|
1146
1589
|
requiredArgs: ['--model-group-code', '--resource image:first_frame=...', '--resource image:last_frame=...'],
|
|
1147
1590
|
userInput: '用户提供起始画面和结束画面,希望生成中间过渡视频。',
|
|
@@ -1149,10 +1592,31 @@ function createSpecInputModes(taskKind, optionKeys, rulesByKey = new Map()) {
|
|
|
1149
1592
|
requiredResources: ['image:first_frame', 'image:last_frame'],
|
|
1150
1593
|
sourceKinds: ['local_file', 'http_url', 'backendPath', 'asset_id'],
|
|
1151
1594
|
resourceLimits: mergeResourceLimits(normalizeMediaRule(framesRules), { minFiles: 2, maxFiles: 2 }),
|
|
1595
|
+
optionResourceLimits: frameOptionResourceLimits,
|
|
1596
|
+
optionResourceUsages: frameCapabilities.usages,
|
|
1152
1597
|
promptBinding: 'none',
|
|
1153
1598
|
promptPlaceholder: '不需要 <<<key>>> 占位符。',
|
|
1154
1599
|
resourceConstraints: ['both_first_and_last_required', 'key_not_used'],
|
|
1155
|
-
|
|
1600
|
+
supportLastFrameOnly,
|
|
1601
|
+
...(!hasFrames ? { unsupportedReason: '模型配置没有 frames 参数。' } : (!supportsFirstLastFrame ? { unsupportedReason: '模型配置 frames.maxFrameNum 小于 2。' } : {})),
|
|
1602
|
+
});
|
|
1603
|
+
modes.push({
|
|
1604
|
+
mode: 'last_frame_only',
|
|
1605
|
+
supported: supportLastFrameOnly,
|
|
1606
|
+
intent: '仅尾帧生视频',
|
|
1607
|
+
requiredArgs: ['--model-group-code', '--resource image:last_frame=...'],
|
|
1608
|
+
userInput: '用户只提供结束画面,希望反向约束视频收束到该画面;这是少数模型才支持的特殊能力。',
|
|
1609
|
+
resourceSyntax: ['image:last_frame=./last.png', 'image:last_frame=asset:<assetId>'],
|
|
1610
|
+
requiredResources: ['image:last_frame'],
|
|
1611
|
+
sourceKinds: ['local_file', 'http_url', 'backendPath', 'asset_id'],
|
|
1612
|
+
resourceLimits: mergeResourceLimits(normalizeMediaRule(framesRules), { minFiles: 1, maxFiles: 1 }),
|
|
1613
|
+
optionResourceLimits: frameOptionResourceLimits,
|
|
1614
|
+
optionResourceUsages: frameCapabilities.usages,
|
|
1615
|
+
promptBinding: 'none',
|
|
1616
|
+
promptPlaceholder: 'last_frame 不使用 reference_key;prompt 可选,用于补充动作、镜头或画面要求。',
|
|
1617
|
+
resourceConstraints: ['last_frame_only_requires_supportLastFrameOnly', 'key_not_used'],
|
|
1618
|
+
supportLastFrameOnly,
|
|
1619
|
+
...(!hasFrames ? { unsupportedReason: '模型配置没有 frames 参数。' } : (!supportLastFrameOnly ? { unsupportedReason: '模型配置未声明支持仅尾帧。' } : {})),
|
|
1156
1620
|
});
|
|
1157
1621
|
modes.push({
|
|
1158
1622
|
mode: 'subject_reference',
|
|
@@ -1164,9 +1628,9 @@ function createSpecInputModes(taskKind, optionKeys, rulesByKey = new Map()) {
|
|
|
1164
1628
|
requiredResources: ['subject:reference:<key>=asset:<externalId>'],
|
|
1165
1629
|
sourceKinds: ['asset_id'],
|
|
1166
1630
|
resourceLimits: mediaRuleFromMultiParam(multiParamRules, 'IMAGE'),
|
|
1167
|
-
promptBinding: '
|
|
1168
|
-
promptPlaceholder: '
|
|
1169
|
-
resourceConstraints: ['external_id_from_subject_wait', '
|
|
1631
|
+
promptBinding: 'optional_key',
|
|
1632
|
+
promptPlaceholder: 'subject reference 必须带 reference_key;是否在 prompt 中写 <<<key>>> 由用户表达决定。',
|
|
1633
|
+
resourceConstraints: ['external_id_from_subject_wait', 'reference_key_required_for_subject'],
|
|
1170
1634
|
...(!supportsMultiImage ? { unsupportedReason: '模型配置没有图片 / 主体参考资源规则。' } : {}),
|
|
1171
1635
|
});
|
|
1172
1636
|
modes.push({
|
|
@@ -1188,18 +1652,103 @@ function createSpecInputModes(taskKind, optionKeys, rulesByKey = new Map()) {
|
|
|
1188
1652
|
return modes;
|
|
1189
1653
|
}
|
|
1190
1654
|
|
|
1191
|
-
function createSpecSupportedIntents(inputModes) {
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
.map((
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1655
|
+
function createSpecSupportedIntents(inputModes, taskKind = null) {
|
|
1656
|
+
const supported = (mode) => inputModes.find((item) => item.mode === mode && item.supported);
|
|
1657
|
+
const referenceModes = ['reference_image', 'reference_audio', 'reference_video', 'subject_reference']
|
|
1658
|
+
.map((mode) => supported(mode))
|
|
1659
|
+
.filter(Boolean);
|
|
1660
|
+
const firstFrame = supported('first_frame');
|
|
1661
|
+
const firstLastFrame = supported('first_last_frame');
|
|
1662
|
+
const lastFrameOnly = supported('last_frame_only');
|
|
1663
|
+
const intents = [];
|
|
1664
|
+
const promptOnly = supported('prompt_only');
|
|
1665
|
+
if (promptOnly) {
|
|
1666
|
+
intents.push(compactRecord({
|
|
1667
|
+
mode: 'prompt_only',
|
|
1668
|
+
intent: promptOnly.intent,
|
|
1669
|
+
userInput: promptOnly.userInput,
|
|
1670
|
+
requiredArgs: promptOnly.requiredArgs,
|
|
1671
|
+
promptBinding: 'none',
|
|
1672
|
+
}));
|
|
1673
|
+
}
|
|
1674
|
+
if (referenceModes.length) {
|
|
1675
|
+
const referenceLabels = uniqueNonEmpty(referenceModes.map((item) => ({
|
|
1676
|
+
reference_image: '图片',
|
|
1677
|
+
reference_audio: '音频',
|
|
1678
|
+
reference_video: '视频',
|
|
1679
|
+
subject_reference: '主体',
|
|
1680
|
+
}[item.mode])));
|
|
1681
|
+
if (taskKind === 'image') {
|
|
1682
|
+
intents.push(compactRecord({
|
|
1683
|
+
mode: 'reference',
|
|
1684
|
+
intent: '参考图生图',
|
|
1685
|
+
userInput: '用户提供图片作为参考素材;图片任务不使用 reference_key 或 <<<key>>>,prompt 用图一、图二、参考图、主体等自然描述指代素材。',
|
|
1686
|
+
requiredArgs: ['--model-group-code', '--prompt', '--resource image:reference=...'],
|
|
1687
|
+
resourceUsages: ['reference'],
|
|
1688
|
+
resourceSyntax: uniqueNonEmpty(referenceModes.flatMap((item) => item.resourceSyntax || [])),
|
|
1689
|
+
promptBinding: 'none',
|
|
1690
|
+
promptPlaceholder: '图片任务不使用 reference_key 或 <<<key>>>;在 prompt 中用自然语言指代参考图。',
|
|
1691
|
+
}));
|
|
1692
|
+
} else {
|
|
1693
|
+
intents.push(compactRecord({
|
|
1694
|
+
mode: 'reference',
|
|
1695
|
+
intent: '参考模式',
|
|
1696
|
+
userInput: `用户提供${referenceLabels.join('、')}作为参考素材;同一 reference_key 可聚合多条参考资源。`,
|
|
1697
|
+
requiredArgs: ['--model-group-code', '--prompt', '--resource <type>:reference[:key]=...'],
|
|
1698
|
+
resourceUsages: ['reference'],
|
|
1699
|
+
resourceSyntax: uniqueNonEmpty(referenceModes.flatMap((item) => item.resourceSyntax || []).flatMap((syntax) => {
|
|
1700
|
+
const text = String(syntax);
|
|
1701
|
+
if (text.startsWith('image:reference:hero=')) return [text.replace('image:reference:hero=', 'image:reference='), text];
|
|
1702
|
+
if (text.startsWith('video:reference:motion=')) return [text.replace('video:reference:motion=', 'video:reference='), text];
|
|
1703
|
+
return [text];
|
|
1704
|
+
})),
|
|
1705
|
+
promptBinding: 'optional_key',
|
|
1706
|
+
promptPlaceholder: 'reference_key 可选;prompt 可以不写占位符。如果 prompt 写了 <<<key>>>,必须能匹配同名 reference 资源。',
|
|
1707
|
+
}));
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
if (firstFrame || firstLastFrame || lastFrameOnly) {
|
|
1711
|
+
const resourceSyntax = uniqueNonEmpty([
|
|
1712
|
+
...(firstFrame?.resourceSyntax || []),
|
|
1713
|
+
...(firstLastFrame?.resourceSyntax || []),
|
|
1714
|
+
...(lastFrameOnly?.resourceSyntax || []),
|
|
1715
|
+
]);
|
|
1716
|
+
const resourceUsages = uniqueNonEmpty([
|
|
1717
|
+
...(firstFrame ? ['first_frame'] : []),
|
|
1718
|
+
...(firstLastFrame || lastFrameOnly ? ['last_frame'] : []),
|
|
1719
|
+
]);
|
|
1720
|
+
const userInputParts = uniqueNonEmpty([
|
|
1721
|
+
firstFrame ? '可提供 first_frame 作为起始画面' : null,
|
|
1722
|
+
firstLastFrame ? '可同时提供 first_frame + last_frame 表达起止画面' : null,
|
|
1723
|
+
lastFrameOnly ? '也支持只提供 last_frame 作为结束画面约束' : null,
|
|
1724
|
+
]);
|
|
1725
|
+
intents.push(compactRecord({
|
|
1726
|
+
mode: 'frames',
|
|
1727
|
+
intent: 'frames 模式',
|
|
1728
|
+
userInput: `${userInputParts.join(';')}。`,
|
|
1729
|
+
requiredArgs: firstFrame
|
|
1730
|
+
? ['--model-group-code', '--resource image:first_frame=...', ...(firstLastFrame ? ['[--resource image:last_frame=...]'] : [])]
|
|
1731
|
+
: ['--model-group-code', '--resource image:last_frame=...'],
|
|
1732
|
+
resourceUsages,
|
|
1733
|
+
resourceSyntax,
|
|
1734
|
+
promptBinding: 'none',
|
|
1735
|
+
promptPlaceholder: 'first_frame / last_frame 不使用 reference_key;prompt 可选,用于补充动作、镜头或画面要求。',
|
|
1736
|
+
}));
|
|
1737
|
+
}
|
|
1738
|
+
const storyboard = supported('storyboard');
|
|
1739
|
+
if (storyboard) {
|
|
1740
|
+
intents.push(compactRecord({
|
|
1741
|
+
mode: 'storyboard',
|
|
1742
|
+
intent: '多帧 / 故事板模式',
|
|
1743
|
+
userInput: storyboard.userInput,
|
|
1744
|
+
requiredArgs: storyboard.requiredArgs,
|
|
1745
|
+
resourceUsages: ['keyframe'],
|
|
1746
|
+
resourceSyntax: storyboard.resourceSyntax,
|
|
1747
|
+
promptBinding: 'none',
|
|
1748
|
+
promptPlaceholder: 'keyframe 不使用 reference_key;每帧可在 resources-json 中携带 prompt / duration。',
|
|
1202
1749
|
}));
|
|
1750
|
+
}
|
|
1751
|
+
return intents;
|
|
1203
1752
|
}
|
|
1204
1753
|
|
|
1205
1754
|
function createSpecResourceRequirements(inputModes) {
|
|
@@ -1228,13 +1777,12 @@ function createSpecUnsupportedIntents(inputModes) {
|
|
|
1228
1777
|
}));
|
|
1229
1778
|
}
|
|
1230
1779
|
|
|
1231
|
-
function createSpecInputRequirement(taskKind, inputModes) {
|
|
1232
|
-
const
|
|
1233
|
-
const
|
|
1234
|
-
const promptRequiredModes = supportedModeItems
|
|
1780
|
+
function createSpecInputRequirement(taskKind, inputModes, supportedIntents = createSpecSupportedIntents(inputModes, taskKind)) {
|
|
1781
|
+
const supportedModes = supportedIntents.map((item) => item.mode);
|
|
1782
|
+
const promptRequiredModes = supportedIntents
|
|
1235
1783
|
.filter((item) => (item.requiredArgs || []).some((arg) => String(arg).includes('--prompt')))
|
|
1236
1784
|
.map((item) => item.mode);
|
|
1237
|
-
const promptOptionalModes =
|
|
1785
|
+
const promptOptionalModes = supportedIntents
|
|
1238
1786
|
.filter((item) => !(item.requiredArgs || []).some((arg) => String(arg).includes('--prompt')))
|
|
1239
1787
|
.map((item) => item.mode);
|
|
1240
1788
|
const promptOnly = inputModes.find((item) => item.mode === 'prompt_only');
|
|
@@ -1249,7 +1797,7 @@ function createSpecInputRequirement(taskKind, inputModes) {
|
|
|
1249
1797
|
promptOptionalModes: arrayOrUndefined(promptOptionalModes),
|
|
1250
1798
|
visualInputRequired,
|
|
1251
1799
|
summary: visualInputRequired
|
|
1252
|
-
? '
|
|
1800
|
+
? '必须选择 reference、frames 或 storyboard 中的一种视觉输入;不能只传 prompt 创建视频。'
|
|
1253
1801
|
: (taskKind === 'image' ? '至少需要 prompt;参考图按用户意图选择。' : '至少需要 prompt;是否需要素材取决于 selected input mode。'),
|
|
1254
1802
|
acceptedModes: supportedModes,
|
|
1255
1803
|
blockedModes: inputModes.filter((item) => !item.supported).map((item) => item.mode),
|
|
@@ -1306,23 +1854,34 @@ function createSpecParameterControls(createParams, inputModes = []) {
|
|
|
1306
1854
|
? '用户上传音频、音乐、配音、节奏参考时,使用 --resource audio:reference=... 或 resources-json 中 type=audio;不要用 --need-audio。'
|
|
1307
1855
|
: '当前模型规格没有 multi_param 资源通道,create-spec 未声明可上传音频参考资源。',
|
|
1308
1856
|
generatedAudioToggle: hasGeneratedAudioToggle
|
|
1309
|
-
? '--need-audio
|
|
1310
|
-
: '
|
|
1857
|
+
? '该模型支持“是否需要输出音效”控制;命令层用 --need-audio true/false,不接收音频文件或 URL。'
|
|
1858
|
+
: '当前模型没有暴露“是否需要输出音效”控制项;这不等价于不能使用音频参考资源。',
|
|
1311
1859
|
},
|
|
1312
1860
|
note: '这里只列当前模型明确暴露的 CLI 可控参数。不要主动把未列出的参数总结成“不支持”;只有用户明确要求对应控制时,才说明 create-spec 没有该参数。',
|
|
1313
1861
|
});
|
|
1314
1862
|
}
|
|
1315
1863
|
|
|
1316
1864
|
function createSpecAgentGuidance(taskKind, inputRequirement) {
|
|
1865
|
+
const keyParamGuidance = taskKind === 'video'
|
|
1866
|
+
? 'fee 或 create --dry-run 前,必须先确认用户未提供的价格 / 效果关键参数:quality、duration、约束后仍可选的 ratio;needAudio 只在用户明确要输出音效时确认。不要静默使用 defaultValue 先估价。'
|
|
1867
|
+
: 'fee 或 create --dry-run 前,必须先确认用户未提供的价格 / 效果关键参数:quality、ratio、generateNum。不要静默使用 defaultValue 先估价。';
|
|
1317
1868
|
const guidance = [
|
|
1318
|
-
'先用 model options
|
|
1319
|
-
'用 inputRequirement 和 supportedIntents
|
|
1320
|
-
'资源带 reference_key 时,prompt 必须包含同名 <<<key>>>;first_frame、last_frame、keyframe 不需要 key。',
|
|
1321
|
-
'音频文件 / URL / asset 走 --resource audio:reference=...;--need-audio 只控制输出视频是否带模型生成音效。',
|
|
1322
|
-
'prompt 以用户明确文本为基底,只补必要的 <<<key>>> 占位符和 shell/JSON 转义。',
|
|
1869
|
+
'先用 model options 获取枚举值、文件类型、数量、大小、时长和条件约束;create-spec 只负责创建方式。',
|
|
1870
|
+
'用 inputRequirement 和 supportedIntents 在 prompt_only、reference、frames、storyboard 中选择一种输入模式;不要按媒体类型拆成多个任务。',
|
|
1323
1871
|
];
|
|
1872
|
+
if (taskKind === 'image') {
|
|
1873
|
+
guidance.push('图片任务不使用 reference_key 或 <<<key>>>。参考图只用 --resource image:reference=... 传入,prompt 用“图一 / 图二 / 参考图 / 白发女 / 背景图”等自然语言指代。');
|
|
1874
|
+
} else {
|
|
1875
|
+
guidance.push('reference_key 是视频参考资源的可选绑定;prompt 可以不写占位符。如果 prompt 写了 <<<key>>>,必须能匹配同名 reference 资源。');
|
|
1876
|
+
guidance.push('只有 model options.resources[] 存在 media=AUDIO usage=reference 时,音频文件 / URL / asset 才能走 --resource audio:reference=...;是否需要输出音效才使用 --need-audio true/false。');
|
|
1877
|
+
}
|
|
1878
|
+
guidance.push(
|
|
1879
|
+
keyParamGuidance,
|
|
1880
|
+
'费用确认优先使用 billingPointBalance / billingPointRemainingAfter,它来自 queryGroupPoint,表示实际可扣积分;projectBudgetBalance 只是项目组预算信息。',
|
|
1881
|
+
'prompt 以用户明确文本为基底;不要为了引用素材而强行补 <<<key>>>。',
|
|
1882
|
+
);
|
|
1324
1883
|
if (taskKind === 'video' && inputRequirement.visualInputRequired) {
|
|
1325
|
-
guidance.push('该视频模型必须带视觉输入;创建前必须从 supportedIntents 中选择
|
|
1884
|
+
guidance.push('该视频模型必须带视觉输入;创建前必须从 supportedIntents 中选择 reference、frames 或 storyboard。');
|
|
1326
1885
|
}
|
|
1327
1886
|
return guidance;
|
|
1328
1887
|
}
|
|
@@ -1331,14 +1890,17 @@ function createSpecValidationRules(taskKind) {
|
|
|
1331
1890
|
const rules = [
|
|
1332
1891
|
'ratio、quality、duration、generateNum 等参数值以 model options.params[].values 为准。',
|
|
1333
1892
|
'素材类型、文件格式、数量、大小和时长以 model options.resources[] 为准。',
|
|
1893
|
+
'参数 / 资源联动限制以 model options.constraints[] 为准;触发 no_selectable_values 后不要传该目标参数。',
|
|
1334
1894
|
'prompt 以用户明确创作描述为基底;没有明确需求时先追问或使用最小中性表达,不主动编内容补空白。',
|
|
1335
|
-
'
|
|
1336
|
-
'
|
|
1895
|
+
'fee 和 create --dry-run 前,先让用户选择或确认缺失的关键价格 / 效果参数;defaultValue 只能作为候选默认展示。',
|
|
1896
|
+
'fee 输出中的 billingPointBalance 是实际可扣积分余额;projectBudgetBalance 是项目组预算余额,不要混用。',
|
|
1897
|
+
'用户确认关键参数后先运行 fee,再运行 create --dry-run,给用户确认后才追加 --yes。',
|
|
1337
1898
|
];
|
|
1338
1899
|
if (taskKind === 'video') {
|
|
1900
|
+
rules.splice(4, 0, 'reference_key 仅用于视频 reference 资源的可选 prompt 占位符绑定;prompt 中出现 <<<key>>> 时,必须有同名 reference 资源。');
|
|
1339
1901
|
rules.push('subject reference 必须使用 asset:<externalId>,externalId 应来自 subject publish + subject wait。');
|
|
1340
1902
|
} else {
|
|
1341
|
-
rules.push('图片任务 resources 只接受 image reference
|
|
1903
|
+
rules.push('图片任务 resources 只接受 image reference,且不接受 reference_key 或 <<<key>>>;请用自然 prompt 描述图一、图二、参考图、主体等映射。');
|
|
1342
1904
|
}
|
|
1343
1905
|
return rules;
|
|
1344
1906
|
}
|
|
@@ -1353,30 +1915,38 @@ function createSpecPreflight(taskKind) {
|
|
|
1353
1915
|
'model options --model-group-code <code>',
|
|
1354
1916
|
'model create-spec --model-group-code <code>',
|
|
1355
1917
|
'按 options 的约束和 create-spec 的 supportedIntents 组装参数',
|
|
1918
|
+
'向用户确认缺失的关键参数候选值',
|
|
1356
1919
|
feeCommand,
|
|
1357
1920
|
`${createCommand} --dry-run`,
|
|
1358
|
-
'向用户确认模型、项目组、最终 prompt
|
|
1921
|
+
'向用户确认模型、项目组、最终 prompt 文本、素材、关键参数、预估积分、可扣积分余额和项目组预算',
|
|
1359
1922
|
`${createCommand} --yes`,
|
|
1360
1923
|
];
|
|
1361
1924
|
}
|
|
1362
1925
|
|
|
1363
|
-
function createSpecExamples(taskKind,
|
|
1926
|
+
function createSpecExamples(taskKind, supportedIntents) {
|
|
1364
1927
|
const examples = [];
|
|
1365
|
-
const
|
|
1366
|
-
const referenceImage = inputModes.find((item) => item.mode === 'reference_image' && item.supported);
|
|
1928
|
+
const hasIntent = (mode) => supportedIntents.some((item) => item.mode === mode);
|
|
1367
1929
|
if (taskKind === 'image') {
|
|
1368
|
-
if (
|
|
1369
|
-
if (
|
|
1930
|
+
if (hasIntent('prompt_only')) examples.push('lj-awb image create --model-group-code <code> --prompt "品牌吉祥物表情包四宫格" --ratio 1:1 --quality 1K --dry-run');
|
|
1931
|
+
if (hasIntent('reference')) examples.push('lj-awb image create --model-group-code <code> --prompt "保持参考图主体,生成海报" --resource image:reference=./ref.png --dry-run');
|
|
1370
1932
|
} else {
|
|
1371
|
-
if (
|
|
1372
|
-
if (
|
|
1373
|
-
|
|
1933
|
+
if (hasIntent('prompt_only')) examples.push('lj-awb video create --model-group-code <code> --prompt "机器人站在白色展台中央,缓慢转身" --duration 6 --dry-run');
|
|
1934
|
+
if (hasIntent('reference')) {
|
|
1935
|
+
const referenceIntent = supportedIntents.find((item) => item.mode === 'reference');
|
|
1936
|
+
examples.push('lj-awb video create --model-group-code <code> --prompt "人物转身看向镜头" --resource image:reference=./hero.png --duration 5 --dry-run');
|
|
1937
|
+
if (referenceIntent?.resourceSyntax?.some((item) => String(item).startsWith('audio:reference'))) {
|
|
1938
|
+
examples.push('lj-awb video create --model-group-code <code> --prompt "让 <<<hero>>> 跟随音乐节奏转身" --resource image:reference:hero=./hero.png --resource audio:reference=./music.mp3 --duration 5 --dry-run');
|
|
1939
|
+
}
|
|
1374
1940
|
}
|
|
1375
|
-
if (
|
|
1941
|
+
if (hasIntent('frames')) {
|
|
1942
|
+
const framesIntent = supportedIntents.find((item) => item.mode === 'frames');
|
|
1376
1943
|
examples.push('lj-awb video create --model-group-code <code> --prompt "镜头缓慢推进" --resource image:first_frame=./first.png --duration 5 --dry-run');
|
|
1377
1944
|
examples.push('lj-awb video create --model-group-code <code> --prompt "镜头缓慢推进" --resource image:first_frame=asset:<assetId> --duration 5 --dry-run');
|
|
1945
|
+
if (framesIntent?.resourceUsages?.includes('last_frame')) {
|
|
1946
|
+
examples.push('lj-awb video create --model-group-code <code> --prompt "从第一张过渡到第二张" --resource image:first_frame=./first.png --resource image:last_frame=./last.png --duration 5 --dry-run');
|
|
1947
|
+
}
|
|
1378
1948
|
}
|
|
1379
|
-
if (
|
|
1949
|
+
if (hasIntent('storyboard')) examples.push('lj-awb video create --model-group-code <code> --resources-json ./storyboard.json --duration 5 --dry-run');
|
|
1380
1950
|
}
|
|
1381
1951
|
return examples;
|
|
1382
1952
|
}
|
|
@@ -1422,29 +1992,111 @@ function optionResourceMedia(mode) {
|
|
|
1422
1992
|
|
|
1423
1993
|
function optionResourceUsage(mode) {
|
|
1424
1994
|
if (mode === 'first_frame') return 'first_frame';
|
|
1425
|
-
if (mode === 'first_last_frame') return '
|
|
1995
|
+
if (mode === 'first_last_frame') return ['first_frame', 'last_frame'];
|
|
1996
|
+
if (mode === 'last_frame_only') return 'last_frame';
|
|
1426
1997
|
if (mode === 'storyboard') return 'keyframe';
|
|
1427
1998
|
return 'reference';
|
|
1428
1999
|
}
|
|
1429
2000
|
|
|
2001
|
+
function optionResourceMode(mode) {
|
|
2002
|
+
if (['reference_image', 'reference_audio', 'reference_video', 'subject_reference'].includes(mode)) return 'reference';
|
|
2003
|
+
if (['first_frame', 'first_last_frame', 'last_frame_only'].includes(mode)) return 'frames';
|
|
2004
|
+
if (mode === 'storyboard') return 'storyboard';
|
|
2005
|
+
return mode;
|
|
2006
|
+
}
|
|
2007
|
+
|
|
1430
2008
|
function modelOptionsResources(inputModes = []) {
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
2009
|
+
const resources = [];
|
|
2010
|
+
const frameModes = inputModes.filter((item) => ['first_frame', 'first_last_frame', 'last_frame_only'].includes(item.mode));
|
|
2011
|
+
const supportedFrameMode = frameModes.find((item) => item.supported);
|
|
2012
|
+
let frameResourcePushed = false;
|
|
2013
|
+
for (const item of createSpecResourceRequirements(inputModes)) {
|
|
2014
|
+
const sourceMode = item.mode;
|
|
2015
|
+
if (['first_frame', 'first_last_frame', 'last_frame_only'].includes(sourceMode)) {
|
|
2016
|
+
if (!frameResourcePushed && supportedFrameMode) {
|
|
2017
|
+
const framePolicy = imageFormatPolicy(supportedFrameMode.optionResourceLimits?.fileTypes);
|
|
2018
|
+
resources.push(compactRecord({
|
|
2019
|
+
mode: 'frames',
|
|
2020
|
+
mediaType: 'IMAGE',
|
|
2021
|
+
usage: supportedFrameMode.optionResourceUsages,
|
|
2022
|
+
sources: supportedFrameMode.sourceKinds,
|
|
2023
|
+
...supportedFrameMode.optionResourceLimits,
|
|
2024
|
+
formatPolicy: framePolicy.summary,
|
|
2025
|
+
webpSupported: framePolicy.webpSupported,
|
|
2026
|
+
autoConvertTo: framePolicy.autoConvertTo,
|
|
2027
|
+
supportLastFrameOnly: supportedFrameMode.supportLastFrameOnly,
|
|
2028
|
+
}));
|
|
2029
|
+
frameResourcePushed = true;
|
|
2030
|
+
}
|
|
2031
|
+
continue;
|
|
2032
|
+
}
|
|
2033
|
+
const mediaType = optionResourceMedia(sourceMode);
|
|
2034
|
+
const imagePolicy = mediaType === 'IMAGE' ? imageFormatPolicy(item.fileTypes) : null;
|
|
2035
|
+
resources.push(compactRecord({
|
|
2036
|
+
mode: optionResourceMode(sourceMode),
|
|
2037
|
+
mediaType,
|
|
2038
|
+
usage: optionResourceUsage(sourceMode),
|
|
2039
|
+
sources: item.sources,
|
|
2040
|
+
fileTypes: sourceMode === 'subject_reference' ? undefined : item.fileTypes,
|
|
2041
|
+
formatPolicy: imagePolicy?.summary,
|
|
2042
|
+
webpSupported: imagePolicy?.webpSupported,
|
|
2043
|
+
autoConvertTo: imagePolicy?.autoConvertTo,
|
|
2044
|
+
minFiles: sourceMode === 'subject_reference' ? undefined : item.minFiles,
|
|
2045
|
+
maxFiles: sourceMode === 'subject_reference' ? undefined : item.maxFiles,
|
|
2046
|
+
maxSizeKB: sourceMode === 'subject_reference' ? undefined : item.maxSizeKB,
|
|
2047
|
+
minDurationMs: sourceMode === 'subject_reference' ? undefined : item.minDurationMs,
|
|
2048
|
+
maxDurationMs: sourceMode === 'subject_reference' ? undefined : item.maxDurationMs,
|
|
2049
|
+
maxTotalDurationMs: sourceMode === 'subject_reference' ? undefined : item.maxTotalDurationMs,
|
|
2050
|
+
minItems: item.minItems,
|
|
2051
|
+
maxItems: item.maxItems,
|
|
2052
|
+
maxPromptLength: item.maxPromptLength,
|
|
2053
|
+
supportLastFrameOnly: item.supportLastFrameOnly,
|
|
2054
|
+
}));
|
|
2055
|
+
}
|
|
2056
|
+
return resources;
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
export function modelInputGuide() {
|
|
2060
|
+
return {
|
|
2061
|
+
schemaVersion: 1,
|
|
2062
|
+
commonFields: [
|
|
2063
|
+
{ field: 'prompt', description: '提示词,描述希望生成什么。' },
|
|
2064
|
+
{ field: 'quality', description: '清晰度 / 尺寸档位。' },
|
|
2065
|
+
{ field: 'ratio', description: '宽高比,例如 16:9、9:16、1:1。' },
|
|
2066
|
+
{ field: 'duration', description: '视频时长,单位秒。' },
|
|
2067
|
+
{ field: 'generate_num', description: '一次生成几张图。' },
|
|
2068
|
+
{ field: 'need_audio', description: '是否生成音频 / 音效;仅部分视频模型支持。' },
|
|
2069
|
+
{ field: 'prompt_optimizer', description: '是否开启提示词增强;不传等同 false。' },
|
|
2070
|
+
{ field: 'resources', description: '输入素材列表,例如首帧、尾帧、参考图、关键帧、参考视频、参考音频。' },
|
|
2071
|
+
{ field: 'subject', description: '主体创建输入,仅主体创建专用接口使用。' },
|
|
2072
|
+
],
|
|
2073
|
+
resourceFields: [
|
|
2074
|
+
{ field: 'resources[].type', values: ['image', 'video', 'audio', 'subject'], description: '资源本体类型;subject 表示已创建的主体对象。' },
|
|
2075
|
+
{ field: 'resources[].usage', values: ['first_frame', 'last_frame', 'reference', 'keyframe'], description: '素材用途。' },
|
|
2076
|
+
{ 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: '默认建议使用 url;asset_id 表示平台资产或主体对象 ID。' },
|
|
2078
|
+
{ field: 'resources[].source.value', description: '资源值,必填。url 传素材地址;asset_id 传资源 ID。' },
|
|
2079
|
+
{ field: 'resources[].order', description: '仅 usage=keyframe 时需要,且同一请求内不能重复。' },
|
|
2080
|
+
{ field: 'resources[].duration', description: '仅 keyframe 场景下用于表达该帧持续时长,可传小数秒。' },
|
|
2081
|
+
{ field: 'resources[].prompt', description: '仅 keyframe 场景下可为该帧补充说明。' },
|
|
2082
|
+
],
|
|
2083
|
+
resourceRules: [
|
|
2084
|
+
'同一请求里最多只能有 1 个 first_frame。',
|
|
2085
|
+
'同一请求里最多只能有 1 个 last_frame;默认必须和 first_frame 成对使用,只有模型声明 supportLastFrameOnly=true 时才可仅传 last_frame。',
|
|
2086
|
+
'图片生图的 image:reference 不使用 reference_key 或 <<<key>>>;在 prompt 中用图一、图二、参考图、主体等自然语言描述资源映射。',
|
|
2087
|
+
'视频 reference prompt 中可以不写 <<<reference_key>>>;如果写了,必须能匹配某个 reference 素材的 reference_key。',
|
|
2088
|
+
'视频 reference 同一个 reference_key 可以对应多条 image / video / audio / subject 参考资源,系统会按 provider 规则聚合后提交。',
|
|
2089
|
+
'type=subject 只支持 usage=reference,且必须传 reference_key。',
|
|
2090
|
+
'first_frame / last_frame / keyframe 不需要、也不使用 reference_key。',
|
|
2091
|
+
],
|
|
2092
|
+
referenceKeyGuide: [
|
|
2093
|
+
'图片生图没有 reference_key 概念;多张参考图按资源顺序和 prompt 中“图一 / 图二 / 参考图 / 背景图”等自然描述理解。',
|
|
2094
|
+
'视频普通参考图 / 参考视频 / 参考音频可以不传 reference_key。',
|
|
2095
|
+
'视频里需要在 prompt 中用 <<<hero>>> 明确指代素材时,再传 reference_key=hero。',
|
|
2096
|
+
'视频同一个主体可以由多条资源组成,例如形象图、动作视频、音频都使用 reference_key=hero。',
|
|
2097
|
+
'视频里不需要被 prompt 占位符引用的普通场景参考,继续使用 type=image / video / audio + usage=reference。',
|
|
2098
|
+
],
|
|
2099
|
+
};
|
|
1448
2100
|
}
|
|
1449
2101
|
|
|
1450
2102
|
export async function modelOptions(kwargs = {}) {
|
|
@@ -1454,7 +2106,7 @@ export async function modelOptions(kwargs = {}) {
|
|
|
1454
2106
|
}
|
|
1455
2107
|
const selectedConfigs = parseJsonArg(kwargs.selectedConfigsJson, {}) ?? {};
|
|
1456
2108
|
const includeRaw = toBool(kwargs.includeRaw);
|
|
1457
|
-
const context = await loadModelOptionContext(modelGroupCode, { selectedConfigs, includeRaw });
|
|
2109
|
+
const context = await loadModelOptionContext(modelGroupCode, { selectedConfigs, includeRaw, includeConstraintSchema: true });
|
|
1458
2110
|
return compactRecord({
|
|
1459
2111
|
schemaVersion: 1,
|
|
1460
2112
|
modelGroupCode,
|
|
@@ -1463,7 +2115,8 @@ export async function modelOptions(kwargs = {}) {
|
|
|
1463
2115
|
model: context.model,
|
|
1464
2116
|
params: modelOptionParams(context.options, context.taskKind),
|
|
1465
2117
|
resources: modelOptionsResources(context.inputModes),
|
|
1466
|
-
|
|
2118
|
+
constraints: context.constraints,
|
|
2119
|
+
...(includeRaw ? { options: context.options, constraintSchema: context.constraintSchema, rawModel: context.rawModel } : {}),
|
|
1467
2120
|
});
|
|
1468
2121
|
}
|
|
1469
2122
|
|
|
@@ -1474,7 +2127,8 @@ export async function modelCreateSpec(kwargs = {}) {
|
|
|
1474
2127
|
}
|
|
1475
2128
|
const includeRaw = toBool(kwargs.includeRaw);
|
|
1476
2129
|
const context = await loadModelOptionContext(modelGroupCode, { includeRaw });
|
|
1477
|
-
const
|
|
2130
|
+
const supportedIntents = createSpecSupportedIntents(context.inputModes, context.taskKind);
|
|
2131
|
+
const inputRequirement = createSpecInputRequirement(context.taskKind, context.inputModes, supportedIntents);
|
|
1478
2132
|
return compactRecord({
|
|
1479
2133
|
schemaVersion: 1,
|
|
1480
2134
|
modelGroupCode,
|
|
@@ -1485,11 +2139,11 @@ export async function modelCreateSpec(kwargs = {}) {
|
|
|
1485
2139
|
optionsCommand: `model options --model-group-code ${modelGroupCode}`,
|
|
1486
2140
|
model: context.model,
|
|
1487
2141
|
inputRequirement,
|
|
1488
|
-
supportedIntents
|
|
2142
|
+
supportedIntents,
|
|
1489
2143
|
validationRules: createSpecValidationRules(context.taskKind),
|
|
1490
2144
|
agentGuidance: createSpecAgentGuidance(context.taskKind, inputRequirement),
|
|
1491
2145
|
preflight: createSpecPreflight(context.taskKind),
|
|
1492
|
-
examples: createSpecExamples(context.taskKind,
|
|
2146
|
+
examples: createSpecExamples(context.taskKind, supportedIntents),
|
|
1493
2147
|
...(includeRaw ? { options: context.options, rawModel: context.rawModel } : {}),
|
|
1494
2148
|
});
|
|
1495
2149
|
}
|
|
@@ -1818,6 +2472,12 @@ async function collectResourceSpecs(kwargs = {}, options = {}) {
|
|
|
1818
2472
|
if (item.usage !== 'reference') {
|
|
1819
2473
|
throw argumentError('图片任务 resource 只支持 usage=reference');
|
|
1820
2474
|
}
|
|
2475
|
+
if (item.reference_key) {
|
|
2476
|
+
throw argumentError(
|
|
2477
|
+
'图片任务 reference 不支持 reference_key',
|
|
2478
|
+
'生图参考图不会按 <<<key>>> 绑定;请使用 image:reference=...,并在 prompt 中用“图一 / 图二 / 参考图 / 主体”等自然语言指代。',
|
|
2479
|
+
);
|
|
2480
|
+
}
|
|
1821
2481
|
if (item._source.kind !== 'url') {
|
|
1822
2482
|
throw argumentError('图片任务 resource 暂只支持 url,本地文件会自动上传为 url');
|
|
1823
2483
|
}
|
|
@@ -1834,6 +2494,43 @@ function isRemoteOrBackendPath(value) {
|
|
|
1834
2494
|
|| text.startsWith('/material/');
|
|
1835
2495
|
}
|
|
1836
2496
|
|
|
2497
|
+
function conversionOutputExtension(format) {
|
|
2498
|
+
const normalized = normalizeFileFormat(format);
|
|
2499
|
+
if (normalized === 'jpg') return 'jpg';
|
|
2500
|
+
return normalized || 'jpg';
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
async function convertLocalImageFile(filePath, targetFormat) {
|
|
2504
|
+
const target = normalizeFileFormat(targetFormat) || 'jpg';
|
|
2505
|
+
const outputPath = path.join(tmpdir(), `lj-awb-${crypto.randomUUID()}.${conversionOutputExtension(target)}`);
|
|
2506
|
+
const codecArgs = target === 'jpg' ? ['-q:v', '2'] : [];
|
|
2507
|
+
try {
|
|
2508
|
+
await execFileAsync('ffmpeg', [
|
|
2509
|
+
'-y',
|
|
2510
|
+
'-hide_banner',
|
|
2511
|
+
'-loglevel',
|
|
2512
|
+
'error',
|
|
2513
|
+
'-i',
|
|
2514
|
+
filePath,
|
|
2515
|
+
'-frames:v',
|
|
2516
|
+
'1',
|
|
2517
|
+
...codecArgs,
|
|
2518
|
+
outputPath,
|
|
2519
|
+
]);
|
|
2520
|
+
} catch (error) {
|
|
2521
|
+
await fs.rm(outputPath, { force: true }).catch(() => {});
|
|
2522
|
+
throw argumentError(
|
|
2523
|
+
`图片格式转换失败:${path.basename(filePath)}`,
|
|
2524
|
+
`需要把该帧图片转换为 ${target} 后提交。请确认本机可用 ffmpeg,或手动转换后重试。${error?.message ? ` 原因:${error.message}` : ''}`,
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
2527
|
+
const inspected = await inspectLocalFile(outputPath);
|
|
2528
|
+
if (!inspected.exists) {
|
|
2529
|
+
throw argumentError(`图片格式转换失败:${path.basename(filePath)}`, `未生成 ${target} 文件。`);
|
|
2530
|
+
}
|
|
2531
|
+
return inspected;
|
|
2532
|
+
}
|
|
2533
|
+
|
|
1837
2534
|
async function resolveResourceFileValue(resource, options = {}) {
|
|
1838
2535
|
if (resource.type === 'subject') {
|
|
1839
2536
|
if (resource._source.kind !== 'asset_id') throw argumentError('subject resource 必须使用 asset_id,例如 subject:reference:hero=asset:element_123');
|
|
@@ -1870,6 +2567,47 @@ async function resolveResourceFileValue(resource, options = {}) {
|
|
|
1870
2567
|
'source.kind=url 只接受完整 http(s) URL、material backendPath,或当前工作目录下存在的本地文件路径。',
|
|
1871
2568
|
);
|
|
1872
2569
|
}
|
|
2570
|
+
const conversion = options.resourceRules
|
|
2571
|
+
? resourceFormatConversion(
|
|
2572
|
+
options.resourceRules.find((item) => resourceRuleMatches(item, { ...base, source: { kind: 'url', value } })),
|
|
2573
|
+
{ resource: { ...base, source: { kind: 'url', value } }, localFile: inspected },
|
|
2574
|
+
)
|
|
2575
|
+
: null;
|
|
2576
|
+
if (conversion) {
|
|
2577
|
+
const conversionRecord = compactRecord({
|
|
2578
|
+
resource: resourceText(base),
|
|
2579
|
+
fromFormat: conversion.fromFormat,
|
|
2580
|
+
toFormat: conversion.toFormat,
|
|
2581
|
+
reason: conversion.reason,
|
|
2582
|
+
sourceFile: inspected.filePath,
|
|
2583
|
+
dryRun: options.dryRun || undefined,
|
|
2584
|
+
});
|
|
2585
|
+
if (options.dryRun) {
|
|
2586
|
+
const convertedName = `${path.basename(inspected.filePath, path.extname(inspected.filePath))}.${conversionOutputExtension(conversion.toFormat)}`;
|
|
2587
|
+
return {
|
|
2588
|
+
resource: { ...base, source: { kind: 'url', value: dryRunBackendPath(convertedName, options.sceneType) } },
|
|
2589
|
+
upload: null,
|
|
2590
|
+
localFile: inspected,
|
|
2591
|
+
conversion: conversionRecord,
|
|
2592
|
+
};
|
|
2593
|
+
}
|
|
2594
|
+
const converted = await convertLocalImageFile(inspected.filePath, conversion.toFormat);
|
|
2595
|
+
try {
|
|
2596
|
+
const upload = await uploadLocalFile(converted.filePath, { sceneType: options.sceneType });
|
|
2597
|
+
return {
|
|
2598
|
+
resource: { ...base, source: { kind: 'url', value: upload.backendPath } },
|
|
2599
|
+
upload,
|
|
2600
|
+
localFile: inspected,
|
|
2601
|
+
conversion: {
|
|
2602
|
+
...conversionRecord,
|
|
2603
|
+
convertedFile: converted.filePath,
|
|
2604
|
+
convertedSize: converted.size,
|
|
2605
|
+
},
|
|
2606
|
+
};
|
|
2607
|
+
} finally {
|
|
2608
|
+
await fs.rm(converted.filePath, { force: true }).catch(() => {});
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
1873
2611
|
if (options.dryRun) {
|
|
1874
2612
|
return {
|
|
1875
2613
|
resource: { ...base, source: { kind: 'url', value: dryRunBackendPath(inspected.filePath, options.sceneType) } },
|
|
@@ -1890,13 +2628,21 @@ async function resolveResources(kwargs = {}, options = {}) {
|
|
|
1890
2628
|
const resources = [];
|
|
1891
2629
|
const uploads = [];
|
|
1892
2630
|
const localFiles = [];
|
|
2631
|
+
const resourceDetails = [];
|
|
2632
|
+
const resourceConversions = [];
|
|
1893
2633
|
for (const spec of specs) {
|
|
1894
2634
|
const resolved = await resolveResourceFileValue(spec, options);
|
|
1895
2635
|
resources.push(resolved.resource);
|
|
1896
2636
|
if (resolved.upload) uploads.push(resolved.upload);
|
|
1897
2637
|
if (resolved.localFile) localFiles.push(resolved.localFile);
|
|
2638
|
+
if (resolved.conversion) resourceConversions.push(resolved.conversion);
|
|
2639
|
+
resourceDetails.push({
|
|
2640
|
+
resource: resolved.resource,
|
|
2641
|
+
upload: resolved.upload,
|
|
2642
|
+
localFile: resolved.localFile,
|
|
2643
|
+
});
|
|
1898
2644
|
}
|
|
1899
|
-
return { resources, uploads, localFiles };
|
|
2645
|
+
return { resources, uploads, localFiles, resourceDetails, resourceConversions };
|
|
1900
2646
|
}
|
|
1901
2647
|
|
|
1902
2648
|
function extractPromptReferenceKeys(prompt) {
|
|
@@ -1914,16 +2660,7 @@ function assertVideoReferenceKeysUsed(prompt, resources = []) {
|
|
|
1914
2660
|
const declaredKeys = new Set(resources
|
|
1915
2661
|
.filter((resource) => resource?.usage === 'reference' && trimToNull(resource.reference_key))
|
|
1916
2662
|
.map((resource) => trimToNull(resource.reference_key)));
|
|
1917
|
-
if (!declaredKeys.size) return;
|
|
1918
2663
|
const promptKeys = extractPromptReferenceKeys(prompt);
|
|
1919
|
-
for (const key of declaredKeys) {
|
|
1920
|
-
if (!promptKeys.has(key)) {
|
|
1921
|
-
throw argumentError(
|
|
1922
|
-
`reference_key 未在 prompt 中引用:${key}`,
|
|
1923
|
-
`带 key 的参考资源必须在 prompt 中出现 <<<${key}>>>;如果只是普通参考素材,请去掉 :${key}。`,
|
|
1924
|
-
);
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
2664
|
for (const key of promptKeys) {
|
|
1928
2665
|
if (!declaredKeys.has(key)) {
|
|
1929
2666
|
throw argumentError(`prompt 引用了未声明的资源占位符:<<<${key}>>>`);
|
|
@@ -1938,14 +2675,21 @@ async function buildImageRequest(kwargs = {}, options = {}) {
|
|
|
1938
2675
|
if (!prompt) {
|
|
1939
2676
|
throw argumentError('缺少生图 prompt', '传 --prompt "..."。');
|
|
1940
2677
|
}
|
|
1941
|
-
const
|
|
1942
|
-
|
|
2678
|
+
const promptReferenceKeys = extractPromptReferenceKeys(prompt);
|
|
2679
|
+
if (promptReferenceKeys.size) {
|
|
2680
|
+
throw argumentError(
|
|
2681
|
+
'图片任务 prompt 不支持 <<<key>>> 资源占位符',
|
|
2682
|
+
'生图参考图没有 reference_key 绑定概念;请改用自然描述,例如“图一中的白发女在图二背景里坐秋千”。',
|
|
2683
|
+
);
|
|
2684
|
+
}
|
|
2685
|
+
const validationResources = await resolveResources(kwargs, {
|
|
2686
|
+
dryRun: true,
|
|
1943
2687
|
kind: 'image',
|
|
1944
2688
|
sceneType: TASK_UPLOAD_SCENE.IMAGE_CREATE,
|
|
1945
2689
|
});
|
|
1946
2690
|
const defaultParams = {
|
|
1947
2691
|
prompt,
|
|
1948
|
-
resources:
|
|
2692
|
+
resources: validationResources.resources,
|
|
1949
2693
|
};
|
|
1950
2694
|
if (kwargs.ratio != null && kwargs.ratio !== '') defaultParams.ratio = kwargs.ratio;
|
|
1951
2695
|
if (kwargs.quality != null && kwargs.quality !== '') defaultParams.quality = kwargs.quality;
|
|
@@ -1953,6 +2697,14 @@ async function buildImageRequest(kwargs = {}, options = {}) {
|
|
|
1953
2697
|
defaultParams.generate_num = parseIntegerParam(kwargs.generateNum, '--generate-num', 1);
|
|
1954
2698
|
}
|
|
1955
2699
|
const promptParams = normalizeUnifiedPromptParams(defaultParams);
|
|
2700
|
+
const validation = await validateCreateRequestAgainstModel('image', model.modelGroupCode, promptParams, validationResources.resourceDetails);
|
|
2701
|
+
const resolvedResources = await resolveResources(kwargs, {
|
|
2702
|
+
dryRun,
|
|
2703
|
+
kind: 'image',
|
|
2704
|
+
sceneType: TASK_UPLOAD_SCENE.IMAGE_CREATE,
|
|
2705
|
+
resourceRules: validation.resourceRules,
|
|
2706
|
+
});
|
|
2707
|
+
const requestPromptParams = normalizeUnifiedPromptParams({ ...defaultParams, resources: resolvedResources.resources });
|
|
1956
2708
|
const projectGroupNo = await resolveProjectGroupNo(kwargs.projectGroupNo, { allowNull: dryRun, noNetwork: dryRun, noSave: dryRun });
|
|
1957
2709
|
const customBizId = options.includeCustomBizId === false ? null : resolveCustomBizId(kwargs.customBizId);
|
|
1958
2710
|
return {
|
|
@@ -1960,11 +2712,12 @@ async function buildImageRequest(kwargs = {}, options = {}) {
|
|
|
1960
2712
|
projectGroupNo,
|
|
1961
2713
|
uploads: resolvedResources.uploads,
|
|
1962
2714
|
localFiles: resolvedResources.localFiles,
|
|
2715
|
+
resourceConversions: resolvedResources.resourceConversions,
|
|
1963
2716
|
request: {
|
|
1964
2717
|
requestSource: REQUEST_SOURCE_CLI,
|
|
1965
2718
|
modelGroupCode: model.modelGroupCode,
|
|
1966
2719
|
...(customBizId ? { customBizId } : {}),
|
|
1967
|
-
promptParams,
|
|
2720
|
+
promptParams: requestPromptParams,
|
|
1968
2721
|
...(projectGroupNo ? { projectGroupNo } : {}),
|
|
1969
2722
|
},
|
|
1970
2723
|
};
|
|
@@ -1978,22 +2731,32 @@ function extractPointCost(payload) {
|
|
|
1978
2731
|
async function pointEstimate(pointCost, projectGroupNo) {
|
|
1979
2732
|
const snapshot = projectGroupNo ? await creditsBalance({ projectGroupNo }).catch(() => null) : null;
|
|
1980
2733
|
const normalizedPointCost = extractPointCost(pointCost);
|
|
1981
|
-
const
|
|
1982
|
-
const
|
|
2734
|
+
const billingPointBalance = toNumberOrNull(snapshot?.billingPointBalance ?? snapshot?.teamPointBalance);
|
|
2735
|
+
const projectBudgetBalance = toNumberOrNull(snapshot?.projectBudgetBalance ?? snapshot?.projectPointBalance);
|
|
1983
2736
|
return {
|
|
1984
2737
|
pointCost: normalizedPointCost,
|
|
1985
|
-
|
|
1986
|
-
|
|
2738
|
+
billingPointBalance,
|
|
2739
|
+
billingPointRemainingAfter: normalizedPointCost != null && billingPointBalance != null ? billingPointBalance - normalizedPointCost : null,
|
|
2740
|
+
projectBudgetBalance,
|
|
2741
|
+
projectBudgetMax: snapshot?.projectBudgetMax ?? snapshot?.projectPointMax ?? null,
|
|
2742
|
+
projectBudgetRemainingAfter: normalizedPointCost != null && projectBudgetBalance != null ? projectBudgetBalance - normalizedPointCost : null,
|
|
2743
|
+
teamPointBalance: billingPointBalance,
|
|
2744
|
+
projectPointBalance: projectBudgetBalance,
|
|
1987
2745
|
projectPointMax: snapshot?.projectPointMax ?? null,
|
|
1988
|
-
teamPointRemainingAfter: normalizedPointCost != null &&
|
|
1989
|
-
projectPointRemainingAfter: normalizedPointCost != null &&
|
|
2746
|
+
teamPointRemainingAfter: normalizedPointCost != null && billingPointBalance != null ? billingPointBalance - normalizedPointCost : null,
|
|
2747
|
+
projectPointRemainingAfter: normalizedPointCost != null && projectBudgetBalance != null ? projectBudgetBalance - normalizedPointCost : null,
|
|
1990
2748
|
};
|
|
1991
2749
|
}
|
|
1992
2750
|
|
|
1993
2751
|
export async function imageFee(kwargs = {}) {
|
|
1994
2752
|
if (toBool(kwargs.dryRun)) {
|
|
1995
2753
|
const built = await buildImageRequest(kwargs, { dryRun: true, includeCustomBizId: false });
|
|
1996
|
-
return {
|
|
2754
|
+
return compactRecord({
|
|
2755
|
+
dryRun: true,
|
|
2756
|
+
action: 'image fee',
|
|
2757
|
+
request: built.request,
|
|
2758
|
+
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2759
|
+
});
|
|
1997
2760
|
}
|
|
1998
2761
|
const built = await buildImageRequest(kwargs, { includeCustomBizId: false });
|
|
1999
2762
|
const payload = await awbApi.fetchImageFee(built.request);
|
|
@@ -2048,6 +2811,7 @@ export async function imageCreate(kwargs = {}) {
|
|
|
2048
2811
|
action: 'image create',
|
|
2049
2812
|
request: built.request,
|
|
2050
2813
|
...(built.localFiles.length ? { localFiles: built.localFiles } : {}),
|
|
2814
|
+
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2051
2815
|
});
|
|
2052
2816
|
}
|
|
2053
2817
|
ensureConfirmed(kwargs, '正式生图会消耗积分,需要确认', { action: 'image create' });
|
|
@@ -2091,19 +2855,19 @@ export async function imageCreate(kwargs = {}) {
|
|
|
2091
2855
|
async function buildVideoRequest(kwargs = {}, options = {}) {
|
|
2092
2856
|
const dryRun = Boolean(options.dryRun);
|
|
2093
2857
|
const model = resolveTaskModel('video', kwargs);
|
|
2094
|
-
const
|
|
2095
|
-
dryRun,
|
|
2858
|
+
const validationResources = await resolveResources(kwargs, {
|
|
2859
|
+
dryRun: true,
|
|
2096
2860
|
kind: 'video',
|
|
2097
2861
|
sceneType: TASK_UPLOAD_SCENE.VIDEO_CREATE,
|
|
2098
2862
|
});
|
|
2099
2863
|
const prompt = trimToNull(kwargs.prompt) ?? '';
|
|
2100
|
-
if (!prompt && !
|
|
2864
|
+
if (!prompt && !validationResources.resources.length) {
|
|
2101
2865
|
throw argumentError('缺少视频生成输入', '至少传 --prompt 或 --resource。');
|
|
2102
2866
|
}
|
|
2103
|
-
assertVideoReferenceKeysUsed(prompt,
|
|
2867
|
+
assertVideoReferenceKeysUsed(prompt, validationResources.resources);
|
|
2104
2868
|
const defaultParams = {
|
|
2105
2869
|
prompt,
|
|
2106
|
-
resources:
|
|
2870
|
+
resources: validationResources.resources,
|
|
2107
2871
|
};
|
|
2108
2872
|
if (kwargs.duration != null && kwargs.duration !== '') {
|
|
2109
2873
|
defaultParams.duration = parseIntegerParam(kwargs.duration, '--duration', 0);
|
|
@@ -2112,6 +2876,14 @@ async function buildVideoRequest(kwargs = {}, options = {}) {
|
|
|
2112
2876
|
if (kwargs.quality != null && kwargs.quality !== '') defaultParams.quality = kwargs.quality;
|
|
2113
2877
|
if (kwargs.needAudio != null && kwargs.needAudio !== '') defaultParams.need_audio = toBool(kwargs.needAudio);
|
|
2114
2878
|
const promptParams = normalizeUnifiedPromptParams(defaultParams);
|
|
2879
|
+
const validation = await validateCreateRequestAgainstModel('video', model.modelGroupCode, promptParams, validationResources.resourceDetails);
|
|
2880
|
+
const resolvedResources = await resolveResources(kwargs, {
|
|
2881
|
+
dryRun,
|
|
2882
|
+
kind: 'video',
|
|
2883
|
+
sceneType: TASK_UPLOAD_SCENE.VIDEO_CREATE,
|
|
2884
|
+
resourceRules: validation.resourceRules,
|
|
2885
|
+
});
|
|
2886
|
+
const requestPromptParams = normalizeUnifiedPromptParams({ ...defaultParams, resources: resolvedResources.resources });
|
|
2115
2887
|
const projectGroupNo = await resolveProjectGroupNo(kwargs.projectGroupNo, { allowNull: dryRun, noNetwork: dryRun, noSave: dryRun });
|
|
2116
2888
|
const customBizId = options.includeCustomBizId === false ? null : resolveCustomBizId(kwargs.customBizId);
|
|
2117
2889
|
return {
|
|
@@ -2119,11 +2891,12 @@ async function buildVideoRequest(kwargs = {}, options = {}) {
|
|
|
2119
2891
|
projectGroupNo,
|
|
2120
2892
|
uploads: resolvedResources.uploads,
|
|
2121
2893
|
localFiles: resolvedResources.localFiles,
|
|
2894
|
+
resourceConversions: resolvedResources.resourceConversions,
|
|
2122
2895
|
request: {
|
|
2123
2896
|
requestSource: REQUEST_SOURCE_CLI,
|
|
2124
2897
|
modelGroupCode: model.modelGroupCode,
|
|
2125
2898
|
...(customBizId ? { customBizId } : {}),
|
|
2126
|
-
promptParams,
|
|
2899
|
+
promptParams: requestPromptParams,
|
|
2127
2900
|
...(projectGroupNo ? { projectGroupNo } : {}),
|
|
2128
2901
|
},
|
|
2129
2902
|
};
|
|
@@ -2132,7 +2905,12 @@ async function buildVideoRequest(kwargs = {}, options = {}) {
|
|
|
2132
2905
|
export async function videoFee(kwargs = {}) {
|
|
2133
2906
|
if (toBool(kwargs.dryRun)) {
|
|
2134
2907
|
const built = await buildVideoRequest(kwargs, { dryRun: true, includeCustomBizId: false });
|
|
2135
|
-
return {
|
|
2908
|
+
return compactRecord({
|
|
2909
|
+
dryRun: true,
|
|
2910
|
+
action: 'video fee',
|
|
2911
|
+
request: built.request,
|
|
2912
|
+
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2913
|
+
});
|
|
2136
2914
|
}
|
|
2137
2915
|
const built = await buildVideoRequest(kwargs, { includeCustomBizId: false });
|
|
2138
2916
|
const payload = await awbApi.fetchVideoFee(built.request);
|
|
@@ -2150,6 +2928,7 @@ export async function videoCreate(kwargs = {}) {
|
|
|
2150
2928
|
action: 'video create',
|
|
2151
2929
|
request: built.request,
|
|
2152
2930
|
...(built.localFiles.length ? { localFiles: built.localFiles } : {}),
|
|
2931
|
+
...(built.resourceConversions.length ? { resourceConversions: built.resourceConversions } : {}),
|
|
2153
2932
|
});
|
|
2154
2933
|
}
|
|
2155
2934
|
ensureConfirmed(kwargs, '正式生视频会消耗积分,需要确认', { action: 'video create' });
|