@shop-os/modelkit 0.31.0 → 0.32.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.
@@ -796,6 +796,10 @@ interface ModelConstraints {
796
796
  } | number[];
797
797
  /** Curated UI choices when `durations` is a range; `resolveOptions` ignores it. */
798
798
  durationPresets?: number[];
799
+ /** Video rows: the longest output, in seconds, at a resolution that renders shorter than `durations`. */
800
+ maxSecondsByResolution?: Partial<Record<VideoResolution, number>>;
801
+ /** Pickers pre-select `defaults.durationSeconds` over their own product default. */
802
+ preferDefaultDuration?: boolean;
799
803
  /** Curated quality choices for rows whose `supports` includes "quality". */
800
804
  qualityOptions?: string[];
801
805
  /** Upscale rows: the `scaleFactor` values the row offers; absent means any. */
@@ -1361,6 +1365,16 @@ declare const CatalogModelSchemaBase: z.ZodObject<{
1361
1365
  max: z.ZodNumber;
1362
1366
  }, z.core.$loose>, z.ZodArray<z.ZodNumber>]>>;
1363
1367
  durationPresets: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
1368
+ maxSecondsByResolution: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
1369
+ "360p": "360p";
1370
+ "480p": "480p";
1371
+ "720p": "720p";
1372
+ "768p": "768p";
1373
+ "1080p": "1080p";
1374
+ "2k": "2k";
1375
+ "4k": "4k";
1376
+ }> & z.core.$partial, z.ZodNumber>>;
1377
+ preferDefaultDuration: z.ZodOptional<z.ZodBoolean>;
1364
1378
  qualityOptions: z.ZodOptional<z.ZodArray<z.ZodString>>;
1365
1379
  scaleFactors: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
1366
1380
  exactSizes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
package/dist/catalog.d.ts CHANGED
@@ -796,6 +796,10 @@ interface ModelConstraints {
796
796
  } | number[];
797
797
  /** Curated UI choices when `durations` is a range; `resolveOptions` ignores it. */
798
798
  durationPresets?: number[];
799
+ /** Video rows: the longest output, in seconds, at a resolution that renders shorter than `durations`. */
800
+ maxSecondsByResolution?: Partial<Record<VideoResolution, number>>;
801
+ /** Pickers pre-select `defaults.durationSeconds` over their own product default. */
802
+ preferDefaultDuration?: boolean;
799
803
  /** Curated quality choices for rows whose `supports` includes "quality". */
800
804
  qualityOptions?: string[];
801
805
  /** Upscale rows: the `scaleFactor` values the row offers; absent means any. */
@@ -1361,6 +1365,16 @@ declare const CatalogModelSchemaBase: z.ZodObject<{
1361
1365
  max: z.ZodNumber;
1362
1366
  }, z.core.$loose>, z.ZodArray<z.ZodNumber>]>>;
1363
1367
  durationPresets: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
1368
+ maxSecondsByResolution: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
1369
+ "360p": "360p";
1370
+ "480p": "480p";
1371
+ "720p": "720p";
1372
+ "768p": "768p";
1373
+ "1080p": "1080p";
1374
+ "2k": "2k";
1375
+ "4k": "4k";
1376
+ }> & z.core.$partial, z.ZodNumber>>;
1377
+ preferDefaultDuration: z.ZodOptional<z.ZodBoolean>;
1364
1378
  qualityOptions: z.ZodOptional<z.ZodArray<z.ZodString>>;
1365
1379
  scaleFactors: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
1366
1380
  exactSizes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
package/dist/catalog.js CHANGED
@@ -5737,7 +5737,9 @@ var VIDEO_FAMILY_MODELS = [
5737
5737
  aspectRatios: ["adaptive", "16:9", "9:16", "1:1", "21:9"],
5738
5738
  resolutions: ["720p", "1080p", "4k"],
5739
5739
  durations: { min: 3, max: 30 },
5740
- durationPresets: [5, 10, 15, 30],
5740
+ preferDefaultDuration: true,
5741
+ // A 3 s 4K clip took 138 s on fal; 30 s could outlast the 15-minute result wait.
5742
+ maxSecondsByResolution: { "4k": 15 },
5741
5743
  references: {
5742
5744
  ...NO_REFERENCES,
5743
5745
  images: 10,
@@ -5776,6 +5778,8 @@ var VIDEO_FAMILY_MODELS = [
5776
5778
  inputBilling: "kling-v4",
5777
5779
  resolutions: ["720p", "1080p", "4k"],
5778
5780
  durations: { min: 3, max: 30 },
5781
+ // A 3 s 4K clip took 138 s on fal; 30 s could outlast the 15-minute result wait.
5782
+ maxSecondsByResolution: { "4k": 15 },
5779
5783
  references: { ...NO_REFERENCES, images: 10 },
5780
5784
  requires: ["sourceVideo"],
5781
5785
  sourceVideoSeconds: { min: 3, max: 30.05 },
@@ -5813,7 +5817,7 @@ var VIDEO_FAMILY_MODELS = [
5813
5817
  aspectRatios: ["adaptive", "16:9", "9:16", "1:1", "21:9"],
5814
5818
  resolutions: ["720p"],
5815
5819
  durations: { min: 3, max: 20 },
5816
- durationPresets: [5, 10, 15, 20],
5820
+ preferDefaultDuration: true,
5817
5821
  references: {
5818
5822
  ...NO_REFERENCES,
5819
5823
  images: 10,
@@ -6668,7 +6672,6 @@ var VIDEO_MODELS = [
6668
6672
  aspectRatios: [...OMNI_RATIOS],
6669
6673
  resolutions: ["360p", "720p", "1080p", "4k"],
6670
6674
  durations: { min: 3, max: 15 },
6671
- durationPresets: [3, 5, 8, 10, 15],
6672
6675
  references: { images: 6, videos: 1, videoSeconds: { max: 10 } },
6673
6676
  sourceVideoSeconds: { max: 15 },
6674
6677
  supports: ["videoExtension", "lastFrame"],
@@ -7235,7 +7238,7 @@ var VIDEO_MODELS = [
7235
7238
  aspectRatios: [...WAN_RATIOS],
7236
7239
  resolutions: ["480p", "720p", "1080p"],
7237
7240
  durations: { min: 2, max: 30 },
7238
- durationPresets: [5, 10, 15, 30],
7241
+ preferDefaultDuration: true,
7239
7242
  references: {
7240
7243
  images: 10,
7241
7244
  videos: 5,
@@ -7277,7 +7280,7 @@ var VIDEO_MODELS = [
7277
7280
  aspectRatios: [...WAN_RATIOS],
7278
7281
  resolutions: ["480p", "720p", "1080p"],
7279
7282
  durations: { min: 2, max: 30 },
7280
- durationPresets: [5, 10, 15, 30],
7283
+ preferDefaultDuration: true,
7281
7284
  references: {
7282
7285
  images: 10,
7283
7286
  videos: 5,
@@ -8835,6 +8838,8 @@ var ModelConstraintsSchema = z3.looseObject({
8835
8838
  resolutions: z3.array(VideoResolutionSchema).optional(),
8836
8839
  durations: z3.union([z3.looseObject({ min: z3.number(), max: z3.number() }), z3.array(z3.number())]).optional(),
8837
8840
  durationPresets: z3.array(z3.number()).optional(),
8841
+ maxSecondsByResolution: z3.partialRecord(VideoResolutionSchema, z3.number().positive()).optional(),
8842
+ preferDefaultDuration: z3.boolean().optional(),
8838
8843
  qualityOptions: z3.array(z3.string()).optional(),
8839
8844
  scaleFactors: z3.array(z3.number().positive()).min(1).optional(),
8840
8845
  exactSizes: z3.record(z3.string(), z3.string()).optional(),
@@ -9061,6 +9066,19 @@ var CatalogModelSchema = CatalogModelSchemaBase.superRefine(
9061
9066
  }
9062
9067
  }
9063
9068
  }
9069
+ const durations = row2.constraints.durations;
9070
+ for (const [resolution, max] of Object.entries(
9071
+ row2.constraints.maxSecondsByResolution ?? {}
9072
+ )) {
9073
+ const inRange = durations === void 0 || (Array.isArray(durations) ? durations.some((d) => d <= max) && max <= Math.max(...durations) : max >= durations.min && max <= durations.max);
9074
+ if (!Number.isInteger(max) || !inRange) {
9075
+ ctx.addIssue({
9076
+ code: "custom",
9077
+ path: ["constraints", "maxSecondsByResolution", resolution],
9078
+ message: "a resolution cap must be whole seconds within the row's durations"
9079
+ });
9080
+ }
9081
+ }
9064
9082
  const audio = row2.constraints.audio;
9065
9083
  if (audio !== void 0 && !AudioOutputSchema.safeParse(audio).success) {
9066
9084
  ctx.addIssue({
@@ -10299,15 +10317,16 @@ function hasReferences(req) {
10299
10317
  return count(req.referenceImages) + count(req.referenceVideos) > 0;
10300
10318
  }
10301
10319
  var KLING_V4_4K_MAX_SECONDS = 15;
10302
- function klingV4FourK(seconds3, req) {
10320
+ function klingV4FourK(seconds3, req, model) {
10303
10321
  if (req.resolution !== "4k") return void 0;
10322
+ const max = model.constraints.maxSecondsByResolution?.["4k"] ?? KLING_V4_4K_MAX_SECONDS;
10304
10323
  if (seconds3 === void 0) {
10305
- return missing(`needs a measured source video of up to ${KLING_V4_4K_MAX_SECONDS} s at 4K`);
10324
+ return missing(`needs a measured source video of up to ${max} s at 4K`);
10306
10325
  }
10307
- return seconds3 > KLING_V4_4K_MAX_SECONDS ? unsupported2(`renders at most ${KLING_V4_4K_MAX_SECONDS} s at 4K`) : void 0;
10326
+ return seconds3 > max ? unsupported2(`renders at most ${max} s at 4K`) : void 0;
10308
10327
  }
10309
- function klingV4(req) {
10310
- const fourK = klingV4FourK(req.durationSeconds ?? 5, req);
10328
+ function klingV4(req, model) {
10329
+ const fourK = klingV4FourK(req.durationSeconds ?? 5, req, model);
10311
10330
  if (fourK !== void 0) return fourK;
10312
10331
  if (hasReferences(req)) {
10313
10332
  if (req.lastFrame !== void 0) {
@@ -10322,10 +10341,10 @@ function klingV4(req) {
10322
10341
  }
10323
10342
  return needsPrompt(req);
10324
10343
  }
10325
- function klingV4Flash(req) {
10344
+ function klingV4Flash(req, model) {
10326
10345
  if (req.lastFrame !== void 0) return unsupported2("takes no end frame");
10327
10346
  if (!hasReferences(req) && req.firstFrame !== void 0) return void 0;
10328
- return klingV4(req);
10347
+ return klingV4(req, model);
10329
10348
  }
10330
10349
  function h3Turbo(req) {
10331
10350
  if (count(req.referenceImages) + count(req.referenceVideos) > 0) {
@@ -10428,7 +10447,7 @@ var RULES = new Map([
10428
10447
  [KLING_V4, klingV4],
10429
10448
  [
10430
10449
  KLING_V4_EDIT,
10431
- (req) => needsSource(req) ?? klingV4FourK(req.durationSeconds ?? req.sourceVideo?.durationSeconds, req) ?? needsPrompt(req)
10450
+ (req, model) => needsSource(req) ?? klingV4FourK(req.durationSeconds ?? req.sourceVideo?.durationSeconds, req, model) ?? needsPrompt(req)
10432
10451
  ],
10433
10452
  [KLING_V4_FLASH, klingV4Flash],
10434
10453
  [KLING_V4_FLASH_EDIT, (req) => needsSource(req) ?? needsPrompt(req)],
@@ -10448,8 +10467,8 @@ var RULES = new Map([
10448
10467
  [LTX25_T2V, ltx(null)],
10449
10468
  [LTX25_FAST_T2V, ltx(["720p", "1080p"])]
10450
10469
  ]);
10451
- function falVideoProblem(providerModelId, req) {
10452
- return RULES.get(providerModelId.toLowerCase())?.(req);
10470
+ function falVideoProblem(model, req) {
10471
+ return RULES.get(model.providerModelId.toLowerCase())?.(req, model);
10453
10472
  }
10454
10473
  function viduSilentWarning(model) {
10455
10474
  return {
@@ -10480,7 +10499,7 @@ function fillKlingModeResolution(model, req) {
10480
10499
  }
10481
10500
  function applyFalVideoRules(model, req, callerRatio, warnings) {
10482
10501
  if (model.adapter !== "fal" && model.adapter !== "alibaba") return;
10483
- const problem = falVideoProblem(model.providerModelId, withPromptForResolve(req));
10502
+ const problem = falVideoProblem(model, withPromptForResolve(req));
10484
10503
  if (problem !== void 0) throw ruleRefusal(model, problem.message, problem.code);
10485
10504
  const id = model.providerModelId.toLowerCase();
10486
10505
  const references = count(req.referenceImages) + count(req.referenceAudios);
@@ -10621,6 +10640,27 @@ function resolveDuration(requested, durations, model, onUnsupported, warnings) {
10621
10640
  });
10622
10641
  return to;
10623
10642
  }
10643
+ function capDurationAtResolution(seconds3, resolution, model, onUnsupported, warnings) {
10644
+ if (seconds3 === void 0 || resolution === void 0) return seconds3;
10645
+ const max = model.constraints.maxSecondsByResolution?.[resolution];
10646
+ if (max === void 0 || seconds3 <= max) return seconds3;
10647
+ const shown = resolution.endsWith("k") ? resolution.toUpperCase() : resolution;
10648
+ if (onUnsupported === "error") {
10649
+ throw new ModelKitError({
10650
+ code: "unsupported_option",
10651
+ message: `${model.id} renders at most ${max} s at ${shown}`,
10652
+ model: model.id
10653
+ });
10654
+ }
10655
+ warnings.push({
10656
+ code: "duration_coerced",
10657
+ field: "durationSeconds",
10658
+ from: seconds3,
10659
+ to: max,
10660
+ message: `duration ${seconds3}s coerced to ${max}s for ${model.id} at ${shown}`
10661
+ });
10662
+ return max;
10663
+ }
10624
10664
  function resolveAspectRatio(requested, supported, model, onUnsupported, warnings) {
10625
10665
  if (requested === void 0 || requested === "adaptive" || !supported) return requested;
10626
10666
  if (supported.includes(requested)) return requested;
@@ -10940,6 +10980,14 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
10940
10980
  warnings
10941
10981
  );
10942
10982
  if (duration !== void 0) merged.durationSeconds = duration;
10983
+ const capped = capDurationAtResolution(
10984
+ merged.durationSeconds,
10985
+ resolution,
10986
+ model,
10987
+ onUnsupported,
10988
+ warnings
10989
+ );
10990
+ if (capped !== void 0) merged.durationSeconds = capped;
10943
10991
  const limits = c.references ?? {};
10944
10992
  let images = trim(
10945
10993
  "referenceImages",