@lingjingai/lj-awb-cli-pre 0.3.18 → 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.
@@ -680,6 +680,31 @@ function modelListMetadata(kind, paramKeys = [], rulesByKey = new Map()) {
680
680
  };
681
681
  }
682
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
+
683
708
  function normalizeModelRows(payload, kind, options = {}) {
684
709
  const includeRaw = Boolean(options.includeRaw);
685
710
  const includeInternal = Boolean(options.includeInternal);
@@ -702,6 +727,7 @@ function normalizeModelRows(payload, kind, options = {}) {
702
727
  enabled: item?.enabled ?? item?.available ?? item?.status ?? null,
703
728
  modelStatus: item?.modelStatus ?? null,
704
729
  taskQueueNum: item?.taskQueueNum ?? null,
730
+ successRate: modelSuccessRate(item),
705
731
  feeCalcType: item?.feeCalcType ?? item?.feeType ?? null,
706
732
  inputModes: metadata.inputModes,
707
733
  params: metadata.controls,
@@ -917,6 +943,68 @@ function normalizeModelConstraints(constraintSchema = [], taskKind = 'image') {
917
943
  }).filter((constraint) => constraint.target || constraint.targetConfigCode);
918
944
  }
919
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
+
920
1008
  function resourceUsageList(usage) {
921
1009
  return (Array.isArray(usage) ? usage : [usage])
922
1010
  .map((item) => trimToNull(item))
@@ -1161,6 +1249,58 @@ function assertResourceCountsAgainstModel(resourceDetails = [], resourceRules =
1161
1249
  }
1162
1250
  }
1163
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
+
1164
1304
  function promptParamValue(promptParams = {}, key) {
1165
1305
  if (key === 'duration') return promptParams.duration;
1166
1306
  if (key === 'generateNum') return promptParams.generate_num;
@@ -1239,9 +1379,10 @@ async function validateCreateRequestAgainstModel(kind, modelGroupCode, promptPar
1239
1379
  }
1240
1380
  const params = modelOptionParams(context.options, context.taskKind);
1241
1381
  const resources = modelOptionsResources(context.inputModes);
1382
+ const effectiveResources = applyResourceLimitProfileConstraints(resources, context.constraints, resourceDetails);
1242
1383
  assertParamsAgainstModel(promptParams, params, context.constraints);
1243
- assertResourceShapeAgainstModel(resourceDetails, resources);
1244
- assertResourceCountsAgainstModel(resourceDetails, resources);
1384
+ assertResourceShapeAgainstModel(resourceDetails, effectiveResources);
1385
+ assertResourceCountsAgainstModel(resourceDetails, effectiveResources);
1245
1386
  if (kind === 'video') {
1246
1387
  const supportedIntents = createSpecSupportedIntents(context.inputModes, context.taskKind);
1247
1388
  const inputRequirement = createSpecInputRequirement(context.taskKind, context.inputModes, supportedIntents);
@@ -1274,12 +1415,16 @@ async function loadModelOptionContext(modelGroupCode, options = {}) {
1274
1415
  const constraintSchema = options.includeConstraintSchema
1275
1416
  ? await fetchModelConstraintSchema(rawModel, modelGroupCode)
1276
1417
  : [];
1418
+ const constraints = [
1419
+ ...normalizeModelConstraints(constraintSchema, taskKind),
1420
+ ...normalizeResourceLimitProfileConstraints(mergedOptions),
1421
+ ];
1277
1422
  return {
1278
1423
  rawModel,
1279
1424
  model: modelSummaryFromRaw(rawModel, modelGroupCode, taskKind),
1280
1425
  options: mergedOptions,
1281
1426
  constraintSchema,
1282
- constraints: normalizeModelConstraints(constraintSchema, taskKind),
1427
+ constraints,
1283
1428
  optionKeys,
1284
1429
  rulesByKey,
1285
1430
  taskKind,
@@ -2073,6 +2218,7 @@ function modelOptionsResources(inputModes = []) {
2073
2218
  mediaType: 'IMAGE',
2074
2219
  usage: supportedFrameMode.optionResourceUsages,
2075
2220
  valueShapes: supportedFrameMode.sourceKinds,
2221
+ sources: supportedFrameMode.sourceKinds,
2076
2222
  ...supportedFrameMode.optionResourceLimits,
2077
2223
  formatPolicy: framePolicy.summary,
2078
2224
  webpSupported: framePolicy.webpSupported,
@@ -2090,6 +2236,7 @@ function modelOptionsResources(inputModes = []) {
2090
2236
  mediaType,
2091
2237
  usage: optionResourceUsage(sourceMode),
2092
2238
  valueShapes: item.valueShapes,
2239
+ sources: item.valueShapes,
2093
2240
  fileTypes: sourceMode === 'subject_reference' ? undefined : item.fileTypes,
2094
2241
  formatPolicy: imagePolicy?.summary,
2095
2242
  webpSupported: imagePolicy?.webpSupported,