@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.
package/dist/index.d.cts CHANGED
@@ -799,6 +799,10 @@ interface ModelConstraints {
799
799
  } | number[];
800
800
  /** Curated UI choices when `durations` is a range; `resolveOptions` ignores it. */
801
801
  durationPresets?: number[];
802
+ /** Video rows: the longest output, in seconds, at a resolution that renders shorter than `durations`. */
803
+ maxSecondsByResolution?: Partial<Record<VideoResolution, number>>;
804
+ /** Pickers pre-select `defaults.durationSeconds` over their own product default. */
805
+ preferDefaultDuration?: boolean;
802
806
  /** Curated quality choices for rows whose `supports` includes "quality". */
803
807
  qualityOptions?: string[];
804
808
  /** Upscale rows: the `scaleFactor` values the row offers; absent means any. */
@@ -1401,6 +1405,16 @@ declare const CatalogModelSchemaBase: z.ZodObject<{
1401
1405
  max: z.ZodNumber;
1402
1406
  }, z.core.$loose>, z.ZodArray<z.ZodNumber>]>>;
1403
1407
  durationPresets: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
1408
+ maxSecondsByResolution: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
1409
+ "360p": "360p";
1410
+ "480p": "480p";
1411
+ "720p": "720p";
1412
+ "768p": "768p";
1413
+ "1080p": "1080p";
1414
+ "2k": "2k";
1415
+ "4k": "4k";
1416
+ }> & z.core.$partial, z.ZodNumber>>;
1417
+ preferDefaultDuration: z.ZodOptional<z.ZodBoolean>;
1404
1418
  qualityOptions: z.ZodOptional<z.ZodArray<z.ZodString>>;
1405
1419
  scaleFactors: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
1406
1420
  exactSizes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
package/dist/index.d.ts CHANGED
@@ -799,6 +799,10 @@ interface ModelConstraints {
799
799
  } | number[];
800
800
  /** Curated UI choices when `durations` is a range; `resolveOptions` ignores it. */
801
801
  durationPresets?: number[];
802
+ /** Video rows: the longest output, in seconds, at a resolution that renders shorter than `durations`. */
803
+ maxSecondsByResolution?: Partial<Record<VideoResolution, number>>;
804
+ /** Pickers pre-select `defaults.durationSeconds` over their own product default. */
805
+ preferDefaultDuration?: boolean;
802
806
  /** Curated quality choices for rows whose `supports` includes "quality". */
803
807
  qualityOptions?: string[];
804
808
  /** Upscale rows: the `scaleFactor` values the row offers; absent means any. */
@@ -1401,6 +1405,16 @@ declare const CatalogModelSchemaBase: z.ZodObject<{
1401
1405
  max: z.ZodNumber;
1402
1406
  }, z.core.$loose>, z.ZodArray<z.ZodNumber>]>>;
1403
1407
  durationPresets: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
1408
+ maxSecondsByResolution: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
1409
+ "360p": "360p";
1410
+ "480p": "480p";
1411
+ "720p": "720p";
1412
+ "768p": "768p";
1413
+ "1080p": "1080p";
1414
+ "2k": "2k";
1415
+ "4k": "4k";
1416
+ }> & z.core.$partial, z.ZodNumber>>;
1417
+ preferDefaultDuration: z.ZodOptional<z.ZodBoolean>;
1404
1418
  qualityOptions: z.ZodOptional<z.ZodArray<z.ZodString>>;
1405
1419
  scaleFactors: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
1406
1420
  exactSizes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
package/dist/index.js CHANGED
@@ -5748,7 +5748,9 @@ var VIDEO_FAMILY_MODELS = [
5748
5748
  aspectRatios: ["adaptive", "16:9", "9:16", "1:1", "21:9"],
5749
5749
  resolutions: ["720p", "1080p", "4k"],
5750
5750
  durations: { min: 3, max: 30 },
5751
- durationPresets: [5, 10, 15, 30],
5751
+ preferDefaultDuration: true,
5752
+ // A 3 s 4K clip took 138 s on fal; 30 s could outlast the 15-minute result wait.
5753
+ maxSecondsByResolution: { "4k": 15 },
5752
5754
  references: {
5753
5755
  ...NO_REFERENCES,
5754
5756
  images: 10,
@@ -5787,6 +5789,8 @@ var VIDEO_FAMILY_MODELS = [
5787
5789
  inputBilling: "kling-v4",
5788
5790
  resolutions: ["720p", "1080p", "4k"],
5789
5791
  durations: { min: 3, max: 30 },
5792
+ // A 3 s 4K clip took 138 s on fal; 30 s could outlast the 15-minute result wait.
5793
+ maxSecondsByResolution: { "4k": 15 },
5790
5794
  references: { ...NO_REFERENCES, images: 10 },
5791
5795
  requires: ["sourceVideo"],
5792
5796
  sourceVideoSeconds: { min: 3, max: 30.05 },
@@ -5824,7 +5828,7 @@ var VIDEO_FAMILY_MODELS = [
5824
5828
  aspectRatios: ["adaptive", "16:9", "9:16", "1:1", "21:9"],
5825
5829
  resolutions: ["720p"],
5826
5830
  durations: { min: 3, max: 20 },
5827
- durationPresets: [5, 10, 15, 20],
5831
+ preferDefaultDuration: true,
5828
5832
  references: {
5829
5833
  ...NO_REFERENCES,
5830
5834
  images: 10,
@@ -6679,7 +6683,6 @@ var VIDEO_MODELS = [
6679
6683
  aspectRatios: [...OMNI_RATIOS],
6680
6684
  resolutions: ["360p", "720p", "1080p", "4k"],
6681
6685
  durations: { min: 3, max: 15 },
6682
- durationPresets: [3, 5, 8, 10, 15],
6683
6686
  references: { images: 6, videos: 1, videoSeconds: { max: 10 } },
6684
6687
  sourceVideoSeconds: { max: 15 },
6685
6688
  supports: ["videoExtension", "lastFrame"],
@@ -7246,7 +7249,7 @@ var VIDEO_MODELS = [
7246
7249
  aspectRatios: [...WAN_RATIOS],
7247
7250
  resolutions: ["480p", "720p", "1080p"],
7248
7251
  durations: { min: 2, max: 30 },
7249
- durationPresets: [5, 10, 15, 30],
7252
+ preferDefaultDuration: true,
7250
7253
  references: {
7251
7254
  images: 10,
7252
7255
  videos: 5,
@@ -7288,7 +7291,7 @@ var VIDEO_MODELS = [
7288
7291
  aspectRatios: [...WAN_RATIOS],
7289
7292
  resolutions: ["480p", "720p", "1080p"],
7290
7293
  durations: { min: 2, max: 30 },
7291
- durationPresets: [5, 10, 15, 30],
7294
+ preferDefaultDuration: true,
7292
7295
  references: {
7293
7296
  images: 10,
7294
7297
  videos: 5,
@@ -8840,6 +8843,8 @@ var ModelConstraintsSchema = z3.looseObject({
8840
8843
  resolutions: z3.array(VideoResolutionSchema).optional(),
8841
8844
  durations: z3.union([z3.looseObject({ min: z3.number(), max: z3.number() }), z3.array(z3.number())]).optional(),
8842
8845
  durationPresets: z3.array(z3.number()).optional(),
8846
+ maxSecondsByResolution: z3.partialRecord(VideoResolutionSchema, z3.number().positive()).optional(),
8847
+ preferDefaultDuration: z3.boolean().optional(),
8843
8848
  qualityOptions: z3.array(z3.string()).optional(),
8844
8849
  scaleFactors: z3.array(z3.number().positive()).min(1).optional(),
8845
8850
  exactSizes: z3.record(z3.string(), z3.string()).optional(),
@@ -9066,6 +9071,19 @@ var CatalogModelSchema = CatalogModelSchemaBase.superRefine(
9066
9071
  }
9067
9072
  }
9068
9073
  }
9074
+ const durations = row2.constraints.durations;
9075
+ for (const [resolution, max] of Object.entries(
9076
+ row2.constraints.maxSecondsByResolution ?? {}
9077
+ )) {
9078
+ const inRange = durations === void 0 || (Array.isArray(durations) ? durations.some((d) => d <= max) && max <= Math.max(...durations) : max >= durations.min && max <= durations.max);
9079
+ if (!Number.isInteger(max) || !inRange) {
9080
+ ctx.addIssue({
9081
+ code: "custom",
9082
+ path: ["constraints", "maxSecondsByResolution", resolution],
9083
+ message: "a resolution cap must be whole seconds within the row's durations"
9084
+ });
9085
+ }
9086
+ }
9069
9087
  const audio = row2.constraints.audio;
9070
9088
  if (audio !== void 0 && !AudioOutputSchema.safeParse(audio).success) {
9071
9089
  ctx.addIssue({
@@ -10508,15 +10526,16 @@ function hasReferences(req) {
10508
10526
  return count(req.referenceImages) + count(req.referenceVideos) > 0;
10509
10527
  }
10510
10528
  var KLING_V4_4K_MAX_SECONDS = 15;
10511
- function klingV4FourK(seconds3, req) {
10529
+ function klingV4FourK(seconds3, req, model) {
10512
10530
  if (req.resolution !== "4k") return void 0;
10531
+ const max = model.constraints.maxSecondsByResolution?.["4k"] ?? KLING_V4_4K_MAX_SECONDS;
10513
10532
  if (seconds3 === void 0) {
10514
- return missing(`needs a measured source video of up to ${KLING_V4_4K_MAX_SECONDS} s at 4K`);
10533
+ return missing(`needs a measured source video of up to ${max} s at 4K`);
10515
10534
  }
10516
- return seconds3 > KLING_V4_4K_MAX_SECONDS ? unsupported3(`renders at most ${KLING_V4_4K_MAX_SECONDS} s at 4K`) : void 0;
10535
+ return seconds3 > max ? unsupported3(`renders at most ${max} s at 4K`) : void 0;
10517
10536
  }
10518
- function klingV4(req) {
10519
- const fourK = klingV4FourK(req.durationSeconds ?? 5, req);
10537
+ function klingV4(req, model) {
10538
+ const fourK = klingV4FourK(req.durationSeconds ?? 5, req, model);
10520
10539
  if (fourK !== void 0) return fourK;
10521
10540
  if (hasReferences(req)) {
10522
10541
  if (req.lastFrame !== void 0) {
@@ -10531,10 +10550,10 @@ function klingV4(req) {
10531
10550
  }
10532
10551
  return needsPrompt(req);
10533
10552
  }
10534
- function klingV4Flash(req) {
10553
+ function klingV4Flash(req, model) {
10535
10554
  if (req.lastFrame !== void 0) return unsupported3("takes no end frame");
10536
10555
  if (!hasReferences(req) && req.firstFrame !== void 0) return void 0;
10537
- return klingV4(req);
10556
+ return klingV4(req, model);
10538
10557
  }
10539
10558
  function h3Turbo(req) {
10540
10559
  if (count(req.referenceImages) + count(req.referenceVideos) > 0) {
@@ -10637,7 +10656,7 @@ var RULES = new Map([
10637
10656
  [KLING_V4, klingV4],
10638
10657
  [
10639
10658
  KLING_V4_EDIT,
10640
- (req) => needsSource(req) ?? klingV4FourK(req.durationSeconds ?? req.sourceVideo?.durationSeconds, req) ?? needsPrompt(req)
10659
+ (req, model) => needsSource(req) ?? klingV4FourK(req.durationSeconds ?? req.sourceVideo?.durationSeconds, req, model) ?? needsPrompt(req)
10641
10660
  ],
10642
10661
  [KLING_V4_FLASH, klingV4Flash],
10643
10662
  [KLING_V4_FLASH_EDIT, (req) => needsSource(req) ?? needsPrompt(req)],
@@ -10657,8 +10676,8 @@ var RULES = new Map([
10657
10676
  [LTX25_T2V, ltx(null)],
10658
10677
  [LTX25_FAST_T2V, ltx(["720p", "1080p"])]
10659
10678
  ]);
10660
- function falVideoProblem(providerModelId, req) {
10661
- return RULES.get(providerModelId.toLowerCase())?.(req);
10679
+ function falVideoProblem(model, req) {
10680
+ return RULES.get(model.providerModelId.toLowerCase())?.(req, model);
10662
10681
  }
10663
10682
  function viduSilentWarning(model) {
10664
10683
  return {
@@ -10689,7 +10708,7 @@ function fillKlingModeResolution(model, req) {
10689
10708
  }
10690
10709
  function applyFalVideoRules(model, req, callerRatio, warnings) {
10691
10710
  if (model.adapter !== "fal" && model.adapter !== "alibaba") return;
10692
- const problem = falVideoProblem(model.providerModelId, withPromptForResolve(req));
10711
+ const problem = falVideoProblem(model, withPromptForResolve(req));
10693
10712
  if (problem !== void 0) throw ruleRefusal(model, problem.message, problem.code);
10694
10713
  const id = model.providerModelId.toLowerCase();
10695
10714
  const references = count(req.referenceImages) + count(req.referenceAudios);
@@ -10802,7 +10821,7 @@ function happyHorseBody(req, ctx) {
10802
10821
  }
10803
10822
  function planAlibabaVideo(req, ctx) {
10804
10823
  const id = ctx.model.providerModelId.toLowerCase();
10805
- const problem = falVideoProblem(id, req);
10824
+ const problem = falVideoProblem(ctx.model, req);
10806
10825
  if (problem !== void 0) throw ruleRefusal(ctx.model, problem.message, problem.code);
10807
10826
  if (WAN_VIDEO_IDS.has(id)) return wanBody(req, ctx);
10808
10827
  if (id === HAPPY_HORSE_FAMILY) return happyHorseBody(req, ctx);
@@ -14099,7 +14118,7 @@ function planFalFamilyVideo(req, ctx) {
14099
14118
  const id = ctx.model.providerModelId.toLowerCase();
14100
14119
  const family = FAMILIES2.find((f) => f.ids.has(id));
14101
14120
  if (family === void 0) return void 0;
14102
- const problem = falVideoProblem(id, req);
14121
+ const problem = falVideoProblem(ctx.model, req);
14103
14122
  if (problem !== void 0) throw refusal2(ctx, problem.message, problem.code);
14104
14123
  return family.plan(req, ctx);
14105
14124
  }
@@ -19891,6 +19910,27 @@ function resolveDuration(requested, durations, model, onUnsupported, warnings) {
19891
19910
  });
19892
19911
  return to;
19893
19912
  }
19913
+ function capDurationAtResolution(seconds3, resolution, model, onUnsupported, warnings) {
19914
+ if (seconds3 === void 0 || resolution === void 0) return seconds3;
19915
+ const max = model.constraints.maxSecondsByResolution?.[resolution];
19916
+ if (max === void 0 || seconds3 <= max) return seconds3;
19917
+ const shown = resolution.endsWith("k") ? resolution.toUpperCase() : resolution;
19918
+ if (onUnsupported === "error") {
19919
+ throw new ModelKitError({
19920
+ code: "unsupported_option",
19921
+ message: `${model.id} renders at most ${max} s at ${shown}`,
19922
+ model: model.id
19923
+ });
19924
+ }
19925
+ warnings.push({
19926
+ code: "duration_coerced",
19927
+ field: "durationSeconds",
19928
+ from: seconds3,
19929
+ to: max,
19930
+ message: `duration ${seconds3}s coerced to ${max}s for ${model.id} at ${shown}`
19931
+ });
19932
+ return max;
19933
+ }
19894
19934
  function resolveAspectRatio(requested, supported, model, onUnsupported, warnings) {
19895
19935
  if (requested === void 0 || requested === "adaptive" || !supported) return requested;
19896
19936
  if (supported.includes(requested)) return requested;
@@ -20210,6 +20250,14 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
20210
20250
  warnings
20211
20251
  );
20212
20252
  if (duration !== void 0) merged.durationSeconds = duration;
20253
+ const capped = capDurationAtResolution(
20254
+ merged.durationSeconds,
20255
+ resolution,
20256
+ model,
20257
+ onUnsupported,
20258
+ warnings
20259
+ );
20260
+ if (capped !== void 0) merged.durationSeconds = capped;
20213
20261
  const limits = c.references ?? {};
20214
20262
  let images = trim(
20215
20263
  "referenceImages",