@shop-os/modelkit 0.4.4 → 0.4.5

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
@@ -4251,6 +4251,20 @@ var import_zod11 = require("zod");
4251
4251
 
4252
4252
  // src/catalog/video-tools-spec.ts
4253
4253
  var import_zod10 = require("zod");
4254
+
4255
+ // src/video-length.ts
4256
+ function tenths(seconds2) {
4257
+ return Math.round(seconds2 * 10) / 10;
4258
+ }
4259
+ function overMax(seconds2, max) {
4260
+ return seconds2 > max && tenths(seconds2) > max;
4261
+ }
4262
+ function overTotal(lengths, total) {
4263
+ const sum = (values) => values.reduce((acc, len) => acc + len, 0);
4264
+ return sum(lengths) > total && tenths(sum(lengths.map(tenths))) > total;
4265
+ }
4266
+
4267
+ // src/catalog/video-tools-spec.ts
4254
4268
  var RangeSchema2 = import_zod10.z.object({ min: import_zod10.z.number(), max: import_zod10.z.number() });
4255
4269
  var ToolSchema = import_zod10.z.object({
4256
4270
  kind: import_zod10.z.enum(["upscale", "interpolate", "hdr"]),
@@ -4294,7 +4308,7 @@ function planVideoTool(row, req) {
4294
4308
  return fail("The source video's width, height and duration are required");
4295
4309
  }
4296
4310
  const maxSeconds = row.constraints.sourceVideoSeconds?.max;
4297
- if (maxSeconds !== void 0 && durationSeconds > maxSeconds) {
4311
+ if (maxSeconds !== void 0 && overMax(durationSeconds, maxSeconds)) {
4298
4312
  return fail(`${row.label} takes source videos up to ${maxSeconds} seconds.`);
4299
4313
  }
4300
4314
  const base = {
@@ -8696,7 +8710,7 @@ function videoLengthViolation(model, input) {
8696
8710
  const lengths = (input.referenceVideos ?? []).map(knownLength);
8697
8711
  if (limits?.max !== void 0) {
8698
8712
  const max = limits.max;
8699
- const i = lengths.findIndex((len) => len !== void 0 && len > max);
8713
+ const i = lengths.findIndex((len) => len !== void 0 && overMax(len, max));
8700
8714
  if (i >= 0)
8701
8715
  return `${model.label} takes reference videos up to ${String(max)} s each; video ${i + 1} is ${seconds(lengths[i], max)} s.`;
8702
8716
  }
@@ -8708,14 +8722,17 @@ function videoLengthViolation(model, input) {
8708
8722
  const source = knownLength(input.sourceVideo);
8709
8723
  const sourceLimits = model.constraints.sourceVideoSeconds;
8710
8724
  if (limits?.total !== void 0) {
8711
- const refSum = lengths.reduce((acc, len) => acc + (len ?? 0), 0);
8712
- const sum = refSum + (sourceLimits?.inReferenceTotal ? source ?? 0 : 0);
8713
- if (sum > limits.total)
8725
+ const counted = [
8726
+ ...lengths.filter((len) => len !== void 0),
8727
+ ...sourceLimits?.inReferenceTotal && source !== void 0 ? [source] : []
8728
+ ];
8729
+ const sum = counted.reduce((acc, len) => acc + len, 0);
8730
+ if (overTotal(counted, limits.total))
8714
8731
  return `${model.label} takes reference videos up to ${String(limits.total)} s combined; these add up to ${seconds(sum, limits.total)} s.`;
8715
8732
  }
8716
8733
  if (source === void 0) return void 0;
8717
8734
  const sourceMin = effectiveMin(sourceLimits, input.taskType);
8718
- if (sourceLimits?.max !== void 0 && source > sourceLimits.max)
8735
+ if (sourceLimits?.max !== void 0 && overMax(source, sourceLimits.max))
8719
8736
  return `${model.label} takes a source video up to ${String(sourceLimits.max)} s; this one is ${seconds(source, sourceLimits.max)} s.`;
8720
8737
  if (sourceMin !== void 0 && source < sourceMin)
8721
8738
  return `${model.label} takes a source video of at least ${String(sourceMin)} s; this one is ${seconds(source, sourceMin)} s.`;