@shop-os/modelkit 0.31.0 → 0.33.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
@@ -5147,6 +5147,22 @@ var TEXT_MODELS = [
5147
5147
  contextWindow: 1e6
5148
5148
  }
5149
5149
  }),
5150
+ text("claude-sonnet-5-5", "Claude Sonnet 5.5", "claude-sonnet-5-5", {
5151
+ exposure: [],
5152
+ // Sonnet 5.5 rejects a forced tool_choice, which is how Bedrock's SDK asks for JSON on Sonnet 5.
5153
+ providerOptions: { modelkit: { structuredOutputMode: "outputFormat" } },
5154
+ display: {
5155
+ chat: { providerOptions: ANTHROPIC_ADAPTIVE },
5156
+ provider: "anthropic",
5157
+ costTier: 3,
5158
+ description: "Anthropic Claude Sonnet 5.5 balanced model; text and image input, 1M-token context."
5159
+ },
5160
+ capabilities: {
5161
+ reasoning: true,
5162
+ vision: true,
5163
+ contextWindow: 1e6
5164
+ }
5165
+ }),
5150
5166
  text("claude-opus-4-8", "Claude Opus 4.8", "claude-opus-4-8", {
5151
5167
  exposure: ["cowork", "space_builder"],
5152
5168
  aliases: ["claude-opus-4.8", "claude-opus-4", "claude-opus-4.0", "claude-opus-4-20250514"],
@@ -5737,7 +5753,9 @@ var VIDEO_FAMILY_MODELS = [
5737
5753
  aspectRatios: ["adaptive", "16:9", "9:16", "1:1", "21:9"],
5738
5754
  resolutions: ["720p", "1080p", "4k"],
5739
5755
  durations: { min: 3, max: 30 },
5740
- durationPresets: [5, 10, 15, 30],
5756
+ preferDefaultDuration: true,
5757
+ // A 3 s 4K clip took 138 s on fal; 30 s could outlast the 15-minute result wait.
5758
+ maxSecondsByResolution: { "4k": 15 },
5741
5759
  references: {
5742
5760
  ...NO_REFERENCES,
5743
5761
  images: 10,
@@ -5776,6 +5794,8 @@ var VIDEO_FAMILY_MODELS = [
5776
5794
  inputBilling: "kling-v4",
5777
5795
  resolutions: ["720p", "1080p", "4k"],
5778
5796
  durations: { min: 3, max: 30 },
5797
+ // A 3 s 4K clip took 138 s on fal; 30 s could outlast the 15-minute result wait.
5798
+ maxSecondsByResolution: { "4k": 15 },
5779
5799
  references: { ...NO_REFERENCES, images: 10 },
5780
5800
  requires: ["sourceVideo"],
5781
5801
  sourceVideoSeconds: { min: 3, max: 30.05 },
@@ -5813,7 +5833,7 @@ var VIDEO_FAMILY_MODELS = [
5813
5833
  aspectRatios: ["adaptive", "16:9", "9:16", "1:1", "21:9"],
5814
5834
  resolutions: ["720p"],
5815
5835
  durations: { min: 3, max: 20 },
5816
- durationPresets: [5, 10, 15, 20],
5836
+ preferDefaultDuration: true,
5817
5837
  references: {
5818
5838
  ...NO_REFERENCES,
5819
5839
  images: 10,
@@ -6668,7 +6688,6 @@ var VIDEO_MODELS = [
6668
6688
  aspectRatios: [...OMNI_RATIOS],
6669
6689
  resolutions: ["360p", "720p", "1080p", "4k"],
6670
6690
  durations: { min: 3, max: 15 },
6671
- durationPresets: [3, 5, 8, 10, 15],
6672
6691
  references: { images: 6, videos: 1, videoSeconds: { max: 10 } },
6673
6692
  sourceVideoSeconds: { max: 15 },
6674
6693
  supports: ["videoExtension", "lastFrame"],
@@ -7235,7 +7254,7 @@ var VIDEO_MODELS = [
7235
7254
  aspectRatios: [...WAN_RATIOS],
7236
7255
  resolutions: ["480p", "720p", "1080p"],
7237
7256
  durations: { min: 2, max: 30 },
7238
- durationPresets: [5, 10, 15, 30],
7257
+ preferDefaultDuration: true,
7239
7258
  references: {
7240
7259
  images: 10,
7241
7260
  videos: 5,
@@ -7277,7 +7296,7 @@ var VIDEO_MODELS = [
7277
7296
  aspectRatios: [...WAN_RATIOS],
7278
7297
  resolutions: ["480p", "720p", "1080p"],
7279
7298
  durations: { min: 2, max: 30 },
7280
- durationPresets: [5, 10, 15, 30],
7299
+ preferDefaultDuration: true,
7281
7300
  references: {
7282
7301
  images: 10,
7283
7302
  videos: 5,
@@ -8835,6 +8854,8 @@ var ModelConstraintsSchema = z3.looseObject({
8835
8854
  resolutions: z3.array(VideoResolutionSchema).optional(),
8836
8855
  durations: z3.union([z3.looseObject({ min: z3.number(), max: z3.number() }), z3.array(z3.number())]).optional(),
8837
8856
  durationPresets: z3.array(z3.number()).optional(),
8857
+ maxSecondsByResolution: z3.partialRecord(VideoResolutionSchema, z3.number().positive()).optional(),
8858
+ preferDefaultDuration: z3.boolean().optional(),
8838
8859
  qualityOptions: z3.array(z3.string()).optional(),
8839
8860
  scaleFactors: z3.array(z3.number().positive()).min(1).optional(),
8840
8861
  exactSizes: z3.record(z3.string(), z3.string()).optional(),
@@ -9061,6 +9082,19 @@ var CatalogModelSchema = CatalogModelSchemaBase.superRefine(
9061
9082
  }
9062
9083
  }
9063
9084
  }
9085
+ const durations = row2.constraints.durations;
9086
+ for (const [resolution, max] of Object.entries(
9087
+ row2.constraints.maxSecondsByResolution ?? {}
9088
+ )) {
9089
+ const inRange = durations === void 0 || (Array.isArray(durations) ? durations.some((d) => d <= max) && max <= Math.max(...durations) : max >= durations.min && max <= durations.max);
9090
+ if (!Number.isInteger(max) || !inRange) {
9091
+ ctx.addIssue({
9092
+ code: "custom",
9093
+ path: ["constraints", "maxSecondsByResolution", resolution],
9094
+ message: "a resolution cap must be whole seconds within the row's durations"
9095
+ });
9096
+ }
9097
+ }
9064
9098
  const audio = row2.constraints.audio;
9065
9099
  if (audio !== void 0 && !AudioOutputSchema.safeParse(audio).success) {
9066
9100
  ctx.addIssue({
@@ -10299,15 +10333,16 @@ function hasReferences(req) {
10299
10333
  return count(req.referenceImages) + count(req.referenceVideos) > 0;
10300
10334
  }
10301
10335
  var KLING_V4_4K_MAX_SECONDS = 15;
10302
- function klingV4FourK(seconds3, req) {
10336
+ function klingV4FourK(seconds3, req, model) {
10303
10337
  if (req.resolution !== "4k") return void 0;
10338
+ const max = model.constraints.maxSecondsByResolution?.["4k"] ?? KLING_V4_4K_MAX_SECONDS;
10304
10339
  if (seconds3 === void 0) {
10305
- return missing(`needs a measured source video of up to ${KLING_V4_4K_MAX_SECONDS} s at 4K`);
10340
+ return missing(`needs a measured source video of up to ${max} s at 4K`);
10306
10341
  }
10307
- return seconds3 > KLING_V4_4K_MAX_SECONDS ? unsupported2(`renders at most ${KLING_V4_4K_MAX_SECONDS} s at 4K`) : void 0;
10342
+ return seconds3 > max ? unsupported2(`renders at most ${max} s at 4K`) : void 0;
10308
10343
  }
10309
- function klingV4(req) {
10310
- const fourK = klingV4FourK(req.durationSeconds ?? 5, req);
10344
+ function klingV4(req, model) {
10345
+ const fourK = klingV4FourK(req.durationSeconds ?? 5, req, model);
10311
10346
  if (fourK !== void 0) return fourK;
10312
10347
  if (hasReferences(req)) {
10313
10348
  if (req.lastFrame !== void 0) {
@@ -10322,10 +10357,10 @@ function klingV4(req) {
10322
10357
  }
10323
10358
  return needsPrompt(req);
10324
10359
  }
10325
- function klingV4Flash(req) {
10360
+ function klingV4Flash(req, model) {
10326
10361
  if (req.lastFrame !== void 0) return unsupported2("takes no end frame");
10327
10362
  if (!hasReferences(req) && req.firstFrame !== void 0) return void 0;
10328
- return klingV4(req);
10363
+ return klingV4(req, model);
10329
10364
  }
10330
10365
  function h3Turbo(req) {
10331
10366
  if (count(req.referenceImages) + count(req.referenceVideos) > 0) {
@@ -10428,7 +10463,7 @@ var RULES = new Map([
10428
10463
  [KLING_V4, klingV4],
10429
10464
  [
10430
10465
  KLING_V4_EDIT,
10431
- (req) => needsSource(req) ?? klingV4FourK(req.durationSeconds ?? req.sourceVideo?.durationSeconds, req) ?? needsPrompt(req)
10466
+ (req, model) => needsSource(req) ?? klingV4FourK(req.durationSeconds ?? req.sourceVideo?.durationSeconds, req, model) ?? needsPrompt(req)
10432
10467
  ],
10433
10468
  [KLING_V4_FLASH, klingV4Flash],
10434
10469
  [KLING_V4_FLASH_EDIT, (req) => needsSource(req) ?? needsPrompt(req)],
@@ -10448,8 +10483,8 @@ var RULES = new Map([
10448
10483
  [LTX25_T2V, ltx(null)],
10449
10484
  [LTX25_FAST_T2V, ltx(["720p", "1080p"])]
10450
10485
  ]);
10451
- function falVideoProblem(providerModelId, req) {
10452
- return RULES.get(providerModelId.toLowerCase())?.(req);
10486
+ function falVideoProblem(model, req) {
10487
+ return RULES.get(model.providerModelId.toLowerCase())?.(req, model);
10453
10488
  }
10454
10489
  function viduSilentWarning(model) {
10455
10490
  return {
@@ -10480,7 +10515,7 @@ function fillKlingModeResolution(model, req) {
10480
10515
  }
10481
10516
  function applyFalVideoRules(model, req, callerRatio, warnings) {
10482
10517
  if (model.adapter !== "fal" && model.adapter !== "alibaba") return;
10483
- const problem = falVideoProblem(model.providerModelId, withPromptForResolve(req));
10518
+ const problem = falVideoProblem(model, withPromptForResolve(req));
10484
10519
  if (problem !== void 0) throw ruleRefusal(model, problem.message, problem.code);
10485
10520
  const id = model.providerModelId.toLowerCase();
10486
10521
  const references = count(req.referenceImages) + count(req.referenceAudios);
@@ -10621,6 +10656,27 @@ function resolveDuration(requested, durations, model, onUnsupported, warnings) {
10621
10656
  });
10622
10657
  return to;
10623
10658
  }
10659
+ function capDurationAtResolution(seconds3, resolution, model, onUnsupported, warnings) {
10660
+ if (seconds3 === void 0 || resolution === void 0) return seconds3;
10661
+ const max = model.constraints.maxSecondsByResolution?.[resolution];
10662
+ if (max === void 0 || seconds3 <= max) return seconds3;
10663
+ const shown = resolution.endsWith("k") ? resolution.toUpperCase() : resolution;
10664
+ if (onUnsupported === "error") {
10665
+ throw new ModelKitError({
10666
+ code: "unsupported_option",
10667
+ message: `${model.id} renders at most ${max} s at ${shown}`,
10668
+ model: model.id
10669
+ });
10670
+ }
10671
+ warnings.push({
10672
+ code: "duration_coerced",
10673
+ field: "durationSeconds",
10674
+ from: seconds3,
10675
+ to: max,
10676
+ message: `duration ${seconds3}s coerced to ${max}s for ${model.id} at ${shown}`
10677
+ });
10678
+ return max;
10679
+ }
10624
10680
  function resolveAspectRatio(requested, supported, model, onUnsupported, warnings) {
10625
10681
  if (requested === void 0 || requested === "adaptive" || !supported) return requested;
10626
10682
  if (supported.includes(requested)) return requested;
@@ -10940,6 +10996,14 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
10940
10996
  warnings
10941
10997
  );
10942
10998
  if (duration !== void 0) merged.durationSeconds = duration;
10999
+ const capped = capDurationAtResolution(
11000
+ merged.durationSeconds,
11001
+ resolution,
11002
+ model,
11003
+ onUnsupported,
11004
+ warnings
11005
+ );
11006
+ if (capped !== void 0) merged.durationSeconds = capped;
10943
11007
  const limits = c.references ?? {};
10944
11008
  let images = trim(
10945
11009
  "referenceImages",