@shop-os/modelkit 0.30.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.cjs CHANGED
@@ -5905,7 +5905,9 @@ var VIDEO_FAMILY_MODELS = [
5905
5905
  aspectRatios: ["adaptive", "16:9", "9:16", "1:1", "21:9"],
5906
5906
  resolutions: ["720p", "1080p", "4k"],
5907
5907
  durations: { min: 3, max: 30 },
5908
- durationPresets: [5, 10, 15, 30],
5908
+ preferDefaultDuration: true,
5909
+ // A 3 s 4K clip took 138 s on fal; 30 s could outlast the 15-minute result wait.
5910
+ maxSecondsByResolution: { "4k": 15 },
5909
5911
  references: {
5910
5912
  ...NO_REFERENCES,
5911
5913
  images: 10,
@@ -5944,6 +5946,8 @@ var VIDEO_FAMILY_MODELS = [
5944
5946
  inputBilling: "kling-v4",
5945
5947
  resolutions: ["720p", "1080p", "4k"],
5946
5948
  durations: { min: 3, max: 30 },
5949
+ // A 3 s 4K clip took 138 s on fal; 30 s could outlast the 15-minute result wait.
5950
+ maxSecondsByResolution: { "4k": 15 },
5947
5951
  references: { ...NO_REFERENCES, images: 10 },
5948
5952
  requires: ["sourceVideo"],
5949
5953
  sourceVideoSeconds: { min: 3, max: 30.05 },
@@ -5981,7 +5985,7 @@ var VIDEO_FAMILY_MODELS = [
5981
5985
  aspectRatios: ["adaptive", "16:9", "9:16", "1:1", "21:9"],
5982
5986
  resolutions: ["720p"],
5983
5987
  durations: { min: 3, max: 20 },
5984
- durationPresets: [5, 10, 15, 20],
5988
+ preferDefaultDuration: true,
5985
5989
  references: {
5986
5990
  ...NO_REFERENCES,
5987
5991
  images: 10,
@@ -6428,6 +6432,76 @@ var VIDEO_FAMILY_MODELS = [
6428
6432
  description: "Speed-optimized Lightricks LTX 2.3 Fast text-to-video and start/end-frame image-to-video with native audio; 6-20 seconds at up to 4K, over 10 seconds at 1080p."
6429
6433
  },
6430
6434
  capabilities: { lastFrameRequiresFirstFrame: true }
6435
+ },
6436
+ {
6437
+ // https://fal.ai/models/lightricks/ltx-2.5/text-to-video/pro/api (+ /image-to-video/pro):
6438
+ // a Lightricks partner endpoint on fal. Pro renders 720p and 1080p only, 6/8/10 s;
6439
+ // no safety checker field. Routing and tiers as LTX 2.3 (adapters/fal-ltx.ts).
6440
+ id: "ltx-2.5",
6441
+ aliases: ["ltx-2-5", "ltx25", "ltx-2.5-pro"],
6442
+ label: "LTX 2.5",
6443
+ type: "video",
6444
+ adapter: "fal",
6445
+ providerModelId: "lightricks/ltx-2.5/text-to-video/pro",
6446
+ lifecycle: "active",
6447
+ exposure: ["cowork", "space_builder"],
6448
+ constraints: {
6449
+ aspectRatios: ["adaptive", "16:9", "9:16"],
6450
+ resolutions: ["720p", "1080p"],
6451
+ durations: [6, 8, 10],
6452
+ supports: ["generateAudio", "lastFrame"],
6453
+ prompt: { referenceSyntax: "numbered", maxChars: 5e3 },
6454
+ audio: "optional"
6455
+ },
6456
+ defaults: {
6457
+ durationSeconds: 6,
6458
+ resolution: "1080p",
6459
+ aspectRatio: "adaptive",
6460
+ generateAudio: true
6461
+ },
6462
+ usage: { ...VIDEO_USAGE },
6463
+ pricingKind: "video_per_second",
6464
+ display: {
6465
+ provider: "lightricks",
6466
+ logo: LIGHTRICKS_LOGO,
6467
+ description: "Lightricks LTX 2.5 Pro text-to-video and start/end-frame image-to-video with native audio; 6, 8 or 10 seconds at 720p or 1080p in landscape or portrait."
6468
+ },
6469
+ capabilities: { lastFrameRequiresFirstFrame: true }
6470
+ },
6471
+ {
6472
+ // https://fal.ai/models/lightricks/ltx-2.5/text-to-video/fast/api (+ /image-to-video/fast):
6473
+ // 720p to 2160p, even durations 6-20 s; over 10 s is 720p or 1080p at 24/25 fps only
6474
+ // (the kit never sends fps, so the rule checks the tier).
6475
+ id: "ltx-2.5-fast",
6476
+ aliases: ["ltx-2-5-fast", "ltx25-fast"],
6477
+ label: "LTX 2.5 Fast",
6478
+ type: "video",
6479
+ adapter: "fal",
6480
+ providerModelId: "lightricks/ltx-2.5/text-to-video/fast",
6481
+ lifecycle: "active",
6482
+ exposure: ["cowork", "space_builder"],
6483
+ constraints: {
6484
+ aspectRatios: ["adaptive", "16:9", "9:16"],
6485
+ resolutions: ["720p", "1080p", "2k", "4k"],
6486
+ durations: [6, 8, 10, 12, 14, 16, 18, 20],
6487
+ supports: ["generateAudio", "lastFrame"],
6488
+ prompt: { referenceSyntax: "numbered", maxChars: 5e3 },
6489
+ audio: "optional"
6490
+ },
6491
+ defaults: {
6492
+ durationSeconds: 6,
6493
+ resolution: "1080p",
6494
+ aspectRatio: "adaptive",
6495
+ generateAudio: true
6496
+ },
6497
+ usage: { ...VIDEO_USAGE },
6498
+ pricingKind: "video_per_second",
6499
+ display: {
6500
+ provider: "lightricks",
6501
+ logo: LIGHTRICKS_LOGO,
6502
+ description: "Speed-optimized Lightricks LTX 2.5 Fast text-to-video and start/end-frame image-to-video with native audio; 6-20 seconds at up to 4K, over 10 seconds at 720p or 1080p."
6503
+ },
6504
+ capabilities: { lastFrameRequiresFirstFrame: true }
6431
6505
  }
6432
6506
  ];
6433
6507
 
@@ -6766,7 +6840,6 @@ var VIDEO_MODELS = [
6766
6840
  aspectRatios: [...OMNI_RATIOS],
6767
6841
  resolutions: ["360p", "720p", "1080p", "4k"],
6768
6842
  durations: { min: 3, max: 15 },
6769
- durationPresets: [3, 5, 8, 10, 15],
6770
6843
  references: { images: 6, videos: 1, videoSeconds: { max: 10 } },
6771
6844
  sourceVideoSeconds: { max: 15 },
6772
6845
  supports: ["videoExtension", "lastFrame"],
@@ -7333,7 +7406,7 @@ var VIDEO_MODELS = [
7333
7406
  aspectRatios: [...WAN_RATIOS],
7334
7407
  resolutions: ["480p", "720p", "1080p"],
7335
7408
  durations: { min: 2, max: 30 },
7336
- durationPresets: [5, 10, 15, 30],
7409
+ preferDefaultDuration: true,
7337
7410
  references: {
7338
7411
  images: 10,
7339
7412
  videos: 5,
@@ -7375,7 +7448,7 @@ var VIDEO_MODELS = [
7375
7448
  aspectRatios: [...WAN_RATIOS],
7376
7449
  resolutions: ["480p", "720p", "1080p"],
7377
7450
  durations: { min: 2, max: 30 },
7378
- durationPresets: [5, 10, 15, 30],
7451
+ preferDefaultDuration: true,
7379
7452
  references: {
7380
7453
  images: 10,
7381
7454
  videos: 5,
@@ -8927,6 +9000,8 @@ var ModelConstraintsSchema = import_zod3.z.looseObject({
8927
9000
  resolutions: import_zod3.z.array(VideoResolutionSchema).optional(),
8928
9001
  durations: import_zod3.z.union([import_zod3.z.looseObject({ min: import_zod3.z.number(), max: import_zod3.z.number() }), import_zod3.z.array(import_zod3.z.number())]).optional(),
8929
9002
  durationPresets: import_zod3.z.array(import_zod3.z.number()).optional(),
9003
+ maxSecondsByResolution: import_zod3.z.partialRecord(VideoResolutionSchema, import_zod3.z.number().positive()).optional(),
9004
+ preferDefaultDuration: import_zod3.z.boolean().optional(),
8930
9005
  qualityOptions: import_zod3.z.array(import_zod3.z.string()).optional(),
8931
9006
  scaleFactors: import_zod3.z.array(import_zod3.z.number().positive()).min(1).optional(),
8932
9007
  exactSizes: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.string()).optional(),
@@ -9153,6 +9228,19 @@ var CatalogModelSchema = CatalogModelSchemaBase.superRefine(
9153
9228
  }
9154
9229
  }
9155
9230
  }
9231
+ const durations = row2.constraints.durations;
9232
+ for (const [resolution, max] of Object.entries(
9233
+ row2.constraints.maxSecondsByResolution ?? {}
9234
+ )) {
9235
+ const inRange = durations === void 0 || (Array.isArray(durations) ? durations.some((d) => d <= max) && max <= Math.max(...durations) : max >= durations.min && max <= durations.max);
9236
+ if (!Number.isInteger(max) || !inRange) {
9237
+ ctx.addIssue({
9238
+ code: "custom",
9239
+ path: ["constraints", "maxSecondsByResolution", resolution],
9240
+ message: "a resolution cap must be whole seconds within the row's durations"
9241
+ });
9242
+ }
9243
+ }
9156
9244
  const audio = row2.constraints.audio;
9157
9245
  if (audio !== void 0 && !AudioOutputSchema.safeParse(audio).success) {
9158
9246
  ctx.addIssue({
@@ -10523,6 +10611,8 @@ var VIDU_Q4 = "fal-ai/vidu/q4";
10523
10611
  var OMNIHUMAN_V2 = "bytedance/omnihuman/v2";
10524
10612
  var LTX_T2V = "fal-ai/ltx-2.3/text-to-video";
10525
10613
  var LTX_FAST_T2V = "fal-ai/ltx-2.3/text-to-video/fast";
10614
+ var LTX25_T2V = "lightricks/ltx-2.5/text-to-video/pro";
10615
+ var LTX25_FAST_T2V = "lightricks/ltx-2.5/text-to-video/fast";
10526
10616
  var KLING_O3_IMAGE_CAP = 7;
10527
10617
  var KLING_V4_IMAGE_CAP = 10;
10528
10618
  var TURBO_AUDIO_MIN_SECONDS = 2;
@@ -10593,15 +10683,16 @@ function hasReferences(req) {
10593
10683
  return count(req.referenceImages) + count(req.referenceVideos) > 0;
10594
10684
  }
10595
10685
  var KLING_V4_4K_MAX_SECONDS = 15;
10596
- function klingV4FourK(seconds3, req) {
10686
+ function klingV4FourK(seconds3, req, model) {
10597
10687
  if (req.resolution !== "4k") return void 0;
10688
+ const max = model.constraints.maxSecondsByResolution?.["4k"] ?? KLING_V4_4K_MAX_SECONDS;
10598
10689
  if (seconds3 === void 0) {
10599
- return missing(`needs a measured source video of up to ${KLING_V4_4K_MAX_SECONDS} s at 4K`);
10690
+ return missing(`needs a measured source video of up to ${max} s at 4K`);
10600
10691
  }
10601
- return seconds3 > KLING_V4_4K_MAX_SECONDS ? unsupported3(`renders at most ${KLING_V4_4K_MAX_SECONDS} s at 4K`) : void 0;
10692
+ return seconds3 > max ? unsupported3(`renders at most ${max} s at 4K`) : void 0;
10602
10693
  }
10603
- function klingV4(req) {
10604
- const fourK = klingV4FourK(req.durationSeconds ?? 5, req);
10694
+ function klingV4(req, model) {
10695
+ const fourK = klingV4FourK(req.durationSeconds ?? 5, req, model);
10605
10696
  if (fourK !== void 0) return fourK;
10606
10697
  if (hasReferences(req)) {
10607
10698
  if (req.lastFrame !== void 0) {
@@ -10616,10 +10707,10 @@ function klingV4(req) {
10616
10707
  }
10617
10708
  return needsPrompt(req);
10618
10709
  }
10619
- function klingV4Flash(req) {
10710
+ function klingV4Flash(req, model) {
10620
10711
  if (req.lastFrame !== void 0) return unsupported3("takes no end frame");
10621
10712
  if (!hasReferences(req) && req.firstFrame !== void 0) return void 0;
10622
- return klingV4(req);
10713
+ return klingV4(req, model);
10623
10714
  }
10624
10715
  function h3Turbo(req) {
10625
10716
  if (count(req.referenceImages) + count(req.referenceVideos) > 0) {
@@ -10699,7 +10790,7 @@ function imageAndAudio(req, audioSeconds) {
10699
10790
  }
10700
10791
  return inputSeconds("audio", audio, audioSeconds);
10701
10792
  }
10702
- function ltx(fast) {
10793
+ function ltx(longTiers) {
10703
10794
  return (req) => {
10704
10795
  if (req.lastFrame !== void 0 && req.firstFrame === void 0) {
10705
10796
  return missing("takes an end frame only together with a start frame");
@@ -10707,8 +10798,8 @@ function ltx(fast) {
10707
10798
  if (count(req.referenceImages) + count(req.referenceVideos) + count(req.referenceAudios) > 0) {
10708
10799
  return unsupported3("takes no reference images, videos or audio");
10709
10800
  }
10710
- if (fast && (req.durationSeconds ?? 6) > 10 && req.resolution !== void 0 && req.resolution !== "1080p") {
10711
- return unsupported3("renders over 10 s at 1080p only");
10801
+ if (longTiers !== null && (req.durationSeconds ?? 6) > 10 && req.resolution !== void 0 && !longTiers.includes(req.resolution)) {
10802
+ return unsupported3(`renders over 10 s at ${longTiers.join(" or ")} only`);
10712
10803
  }
10713
10804
  return needsPrompt(req);
10714
10805
  };
@@ -10722,7 +10813,7 @@ var RULES = new Map([
10722
10813
  [KLING_V4, klingV4],
10723
10814
  [
10724
10815
  KLING_V4_EDIT,
10725
- (req) => needsSource(req) ?? klingV4FourK(req.durationSeconds ?? req.sourceVideo?.durationSeconds, req) ?? needsPrompt(req)
10816
+ (req, model) => needsSource(req) ?? klingV4FourK(req.durationSeconds ?? req.sourceVideo?.durationSeconds, req, model) ?? needsPrompt(req)
10726
10817
  ],
10727
10818
  [KLING_V4_FLASH, klingV4Flash],
10728
10819
  [KLING_V4_FLASH_EDIT, (req) => needsSource(req) ?? needsPrompt(req)],
@@ -10737,11 +10828,13 @@ var RULES = new Map([
10737
10828
  ...AVATAR_AUDIO.map(
10738
10829
  ([id, limits]) => [id, (req) => imageAndAudio(req, limits)]
10739
10830
  ),
10740
- [LTX_T2V, ltx(false)],
10741
- [LTX_FAST_T2V, ltx(true)]
10831
+ [LTX_T2V, ltx(null)],
10832
+ [LTX_FAST_T2V, ltx(["1080p"])],
10833
+ [LTX25_T2V, ltx(null)],
10834
+ [LTX25_FAST_T2V, ltx(["720p", "1080p"])]
10742
10835
  ]);
10743
- function falVideoProblem(providerModelId, req) {
10744
- return RULES.get(providerModelId.toLowerCase())?.(req);
10836
+ function falVideoProblem(model, req) {
10837
+ return RULES.get(model.providerModelId.toLowerCase())?.(req, model);
10745
10838
  }
10746
10839
  function viduSilentWarning(model) {
10747
10840
  return {
@@ -10772,7 +10865,7 @@ function fillKlingModeResolution(model, req) {
10772
10865
  }
10773
10866
  function applyFalVideoRules(model, req, callerRatio, warnings) {
10774
10867
  if (model.adapter !== "fal" && model.adapter !== "alibaba") return;
10775
- const problem = falVideoProblem(model.providerModelId, withPromptForResolve(req));
10868
+ const problem = falVideoProblem(model, withPromptForResolve(req));
10776
10869
  if (problem !== void 0) throw ruleRefusal(model, problem.message, problem.code);
10777
10870
  const id = model.providerModelId.toLowerCase();
10778
10871
  const references = count(req.referenceImages) + count(req.referenceAudios);
@@ -10885,7 +10978,7 @@ function happyHorseBody(req, ctx) {
10885
10978
  }
10886
10979
  function planAlibabaVideo(req, ctx) {
10887
10980
  const id = ctx.model.providerModelId.toLowerCase();
10888
- const problem = falVideoProblem(id, req);
10981
+ const problem = falVideoProblem(ctx.model, req);
10889
10982
  if (problem !== void 0) throw ruleRefusal(ctx.model, problem.message, problem.code);
10890
10983
  if (WAN_VIDEO_IDS.has(id)) return wanBody(req, ctx);
10891
10984
  if (id === HAPPY_HORSE_FAMILY) return happyHorseBody(req, ctx);
@@ -13944,6 +14037,10 @@ var LTX_T2V2 = "fal-ai/ltx-2.3/text-to-video";
13944
14037
  var LTX_I2V = "fal-ai/ltx-2.3/image-to-video";
13945
14038
  var LTX_FAST_T2V2 = "fal-ai/ltx-2.3/text-to-video/fast";
13946
14039
  var LTX_FAST_I2V = "fal-ai/ltx-2.3/image-to-video/fast";
14040
+ var LTX25_T2V2 = "lightricks/ltx-2.5/text-to-video/pro";
14041
+ var LTX25_I2V = "lightricks/ltx-2.5/image-to-video/pro";
14042
+ var LTX25_FAST_T2V2 = "lightricks/ltx-2.5/text-to-video/fast";
14043
+ var LTX25_FAST_I2V = "lightricks/ltx-2.5/image-to-video/fast";
13947
14044
  var LTX_TIERS = {
13948
14045
  "360p": "360p",
13949
14046
  "480p": "480p",
@@ -13953,7 +14050,13 @@ var LTX_TIERS = {
13953
14050
  "2k": "1440p",
13954
14051
  "4k": "2160p"
13955
14052
  };
13956
- function ltxGenerate(fast, req, ctx) {
14053
+ var I2V_OF = /* @__PURE__ */ new Map([
14054
+ [LTX_T2V2, LTX_I2V],
14055
+ [LTX_FAST_T2V2, LTX_FAST_I2V],
14056
+ [LTX25_T2V2, LTX25_I2V],
14057
+ [LTX25_FAST_T2V2, LTX25_FAST_I2V]
14058
+ ]);
14059
+ function ltxGenerate(t2v, i2v, req, ctx) {
13957
14060
  const resolution = resolutionOf2(req, ctx);
13958
14061
  const duration = wholeSeconds(req, ctx);
13959
14062
  const input = {
@@ -13962,9 +14065,11 @@ function ltxGenerate(fast, req, ctx) {
13962
14065
  resolution: LTX_TIERS[resolution],
13963
14066
  generate_audio: req.generateAudio ?? true
13964
14067
  };
13965
- if (req.safetyChecker !== void 0) input["enable_safety_checker"] = req.safetyChecker;
14068
+ if (req.safetyChecker !== void 0 && t2v.startsWith("fal-ai/ltx-2.3/")) {
14069
+ input["enable_safety_checker"] = req.safetyChecker;
14070
+ }
13966
14071
  const firstFrame = req.firstFrame;
13967
- const endpoint = firstFrame === void 0 ? fast ? LTX_FAST_T2V2 : LTX_T2V2 : fast ? LTX_FAST_I2V : LTX_I2V;
14072
+ const endpoint = firstFrame === void 0 ? t2v : i2v;
13968
14073
  if (firstFrame === void 0) {
13969
14074
  const ratio = concreteRatio(req);
13970
14075
  if (ratio !== void 0) input["aspect_ratio"] = ratio;
@@ -13977,17 +14082,13 @@ function ltxGenerate(fast, req, ctx) {
13977
14082
  }
13978
14083
  return { endpoint, input, resolution, seconds: requestedSeconds(duration) };
13979
14084
  }
13980
- var LTX_MODEL_IDS = /* @__PURE__ */ new Set([
13981
- LTX_T2V2,
13982
- LTX_I2V,
13983
- LTX_FAST_T2V2,
13984
- LTX_FAST_I2V
13985
- ]);
14085
+ var LTX_MODEL_IDS = new Set([...I2V_OF.entries()].flat());
13986
14086
  var ltxFamily = {
13987
14087
  ids: LTX_MODEL_IDS,
13988
14088
  plan(req, ctx) {
13989
14089
  const id = ctx.model.providerModelId.toLowerCase();
13990
- return ltxGenerate(id === LTX_FAST_T2V2 || id === LTX_FAST_I2V, req, ctx);
14090
+ const t2v = I2V_OF.has(id) ? id : [...I2V_OF.entries()].find(([, i2v]) => i2v === id)?.[0] ?? LTX_T2V2;
14091
+ return ltxGenerate(t2v, I2V_OF.get(t2v) ?? LTX_I2V, req, ctx);
13991
14092
  }
13992
14093
  };
13993
14094
 
@@ -14174,7 +14275,7 @@ function planFalFamilyVideo(req, ctx) {
14174
14275
  const id = ctx.model.providerModelId.toLowerCase();
14175
14276
  const family = FAMILIES2.find((f) => f.ids.has(id));
14176
14277
  if (family === void 0) return void 0;
14177
- const problem = falVideoProblem(id, req);
14278
+ const problem = falVideoProblem(ctx.model, req);
14178
14279
  if (problem !== void 0) throw refusal2(ctx, problem.message, problem.code);
14179
14280
  return family.plan(req, ctx);
14180
14281
  }
@@ -19964,6 +20065,27 @@ function resolveDuration(requested, durations, model, onUnsupported, warnings) {
19964
20065
  });
19965
20066
  return to;
19966
20067
  }
20068
+ function capDurationAtResolution(seconds3, resolution, model, onUnsupported, warnings) {
20069
+ if (seconds3 === void 0 || resolution === void 0) return seconds3;
20070
+ const max = model.constraints.maxSecondsByResolution?.[resolution];
20071
+ if (max === void 0 || seconds3 <= max) return seconds3;
20072
+ const shown = resolution.endsWith("k") ? resolution.toUpperCase() : resolution;
20073
+ if (onUnsupported === "error") {
20074
+ throw new ModelKitError({
20075
+ code: "unsupported_option",
20076
+ message: `${model.id} renders at most ${max} s at ${shown}`,
20077
+ model: model.id
20078
+ });
20079
+ }
20080
+ warnings.push({
20081
+ code: "duration_coerced",
20082
+ field: "durationSeconds",
20083
+ from: seconds3,
20084
+ to: max,
20085
+ message: `duration ${seconds3}s coerced to ${max}s for ${model.id} at ${shown}`
20086
+ });
20087
+ return max;
20088
+ }
19967
20089
  function resolveAspectRatio(requested, supported, model, onUnsupported, warnings) {
19968
20090
  if (requested === void 0 || requested === "adaptive" || !supported) return requested;
19969
20091
  if (supported.includes(requested)) return requested;
@@ -20283,6 +20405,14 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
20283
20405
  warnings
20284
20406
  );
20285
20407
  if (duration !== void 0) merged.durationSeconds = duration;
20408
+ const capped = capDurationAtResolution(
20409
+ merged.durationSeconds,
20410
+ resolution,
20411
+ model,
20412
+ onUnsupported,
20413
+ warnings
20414
+ );
20415
+ if (capped !== void 0) merged.durationSeconds = capped;
20286
20416
  const limits = c.references ?? {};
20287
20417
  let images = trim(
20288
20418
  "referenceImages",