@shop-os/modelkit 0.7.3 → 0.7.4

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
@@ -6687,6 +6687,161 @@ var MODEL3D_IMAGE_SLOTS = {
6687
6687
  ordered: ["image", "left", "back", "right"],
6688
6688
  unordered: ["image", "back", "left", "right", "top"]
6689
6689
  };
6690
+ var MODEL3D_FAMILY_RULES = {
6691
+ trellis: {
6692
+ textPath: false,
6693
+ views: ["none"],
6694
+ multiImage: false,
6695
+ texture: null,
6696
+ pbr: false,
6697
+ seed: true,
6698
+ textureRef: false,
6699
+ resolutions: "integer"
6700
+ },
6701
+ hunyuan: {
6702
+ textPath: true,
6703
+ views: ["none", "named"],
6704
+ multiImage: false,
6705
+ // generate_type
6706
+ texture: { none: "Geometry", standard: "Normal" },
6707
+ pbr: true,
6708
+ seed: false,
6709
+ textureRef: false,
6710
+ resolutions: null
6711
+ },
6712
+ tripo: {
6713
+ textPath: true,
6714
+ views: ["none", "ordered"],
6715
+ multiImage: true,
6716
+ // texture_quality; null sends an untextured model.
6717
+ texture: { none: null, standard: "standard", detailed: "detailed" },
6718
+ pbr: true,
6719
+ seed: true,
6720
+ textureRef: false,
6721
+ resolutions: null
6722
+ },
6723
+ rodin: {
6724
+ textPath: true,
6725
+ views: ["none", "unordered"],
6726
+ multiImage: false,
6727
+ texture: null,
6728
+ pbr: false,
6729
+ seed: true,
6730
+ textureRef: false,
6731
+ resolutions: null
6732
+ },
6733
+ meshy: {
6734
+ textPath: true,
6735
+ views: ["none", "unordered"],
6736
+ multiImage: true,
6737
+ // The text endpoint's mode; the image endpoints take should_texture.
6738
+ texture: { none: "preview", standard: "full" },
6739
+ pbr: true,
6740
+ seed: true,
6741
+ textureRef: true,
6742
+ resolutions: null
6743
+ },
6744
+ hi3d: {
6745
+ textPath: false,
6746
+ views: ["none", "named"],
6747
+ multiImage: true,
6748
+ // enable_texture
6749
+ texture: { none: false, standard: true },
6750
+ pbr: true,
6751
+ seed: false,
6752
+ textureRef: false,
6753
+ resolutions: { quality: "2048quality", master: "2048master" }
6754
+ },
6755
+ sam: {
6756
+ textPath: false,
6757
+ views: ["none"],
6758
+ multiImage: false,
6759
+ texture: null,
6760
+ pbr: false,
6761
+ seed: true,
6762
+ textureRef: false,
6763
+ resolutions: null
6764
+ }
6765
+ };
6766
+ function model3dSpecIssues(spec) {
6767
+ const issues = [];
6768
+ const add = (path, message) => issues.push({ path, message });
6769
+ const rules = MODEL3D_FAMILY_RULES[spec.family];
6770
+ const promptOnly = spec.text && !spec.imageRequired;
6771
+ if (spec.endpoints.image === void 0)
6772
+ add(["endpoints", "image"], "every row needs an image endpoint");
6773
+ if (promptOnly && !rules.textPath) {
6774
+ add(
6775
+ ["imageRequired"],
6776
+ `${spec.family} has no text-to-3D endpoint; a text row needs an image`
6777
+ );
6778
+ }
6779
+ if (promptOnly && spec.endpoints.text === void 0) {
6780
+ add(["endpoints", "text"], "a text row needs a text endpoint");
6781
+ }
6782
+ if (!rules.views.includes(spec.views)) {
6783
+ add(["views"], `${spec.family} takes views ${rules.views.join(" or ")}`);
6784
+ }
6785
+ if (spec.views === "none" && spec.maxImages !== 1) {
6786
+ add(["maxImages"], "a row without views takes 1 image");
6787
+ }
6788
+ if (spec.views === "unordered" && spec.maxImages < 2) {
6789
+ add(["maxImages"], "a row with views takes at least 2 images");
6790
+ }
6791
+ const slots = MODEL3D_IMAGE_SLOTS[spec.views].length;
6792
+ if (spec.views !== "none" && spec.maxImages > slots) {
6793
+ add(["maxImages"], `a row with ${spec.views} views sends at most ${slots} images`);
6794
+ }
6795
+ if ((spec.views === "named" || spec.views === "ordered") && spec.maxImages < slots) {
6796
+ add(
6797
+ ["maxImages"],
6798
+ `a row with ${spec.views} views takes ${slots} images (front and three sides)`
6799
+ );
6800
+ }
6801
+ if (spec.views !== "none" && rules.multiImage && spec.endpoints.multiImage === void 0) {
6802
+ add(["endpoints", "multiImage"], `${spec.family} sends views to a multi-image endpoint`);
6803
+ }
6804
+ if (rules.texture === null) {
6805
+ if (spec.texture.length > 0) add(["texture"], `${spec.family} has no texture switch`);
6806
+ } else {
6807
+ const allowed = rules.texture;
6808
+ if (spec.texture.length === 0) add(["texture"], `${spec.family} needs its texture options`);
6809
+ if (new Set(spec.texture).size !== spec.texture.length)
6810
+ add(["texture"], "texture options repeat");
6811
+ for (const t of spec.texture) {
6812
+ if (!Object.hasOwn(allowed, t))
6813
+ add(["texture"], `${spec.family} has no "${t}" texture`);
6814
+ }
6815
+ }
6816
+ if (spec.pbr && !rules.pbr) add(["pbr"], `${spec.family} has no PBR switch`);
6817
+ if (spec.pbr && !spec.texture.some((t) => t !== "none")) {
6818
+ add(["pbr"], "PBR needs a textured option");
6819
+ }
6820
+ if (spec.seed && !rules.seed) add(["seed"], `${spec.family} takes no seed`);
6821
+ if (spec.seedMax !== void 0 && !spec.seed) add(["seedMax"], "seedMax needs seed");
6822
+ if (spec.textureRef && !rules.textureRef)
6823
+ add(["textureRef"], `${spec.family} takes no texture reference`);
6824
+ const res = spec.resolutions;
6825
+ if (rules.resolutions === null) {
6826
+ if (res !== void 0) add(["resolutions"], `${spec.family} has no resolution option`);
6827
+ } else if (res === void 0) {
6828
+ add(["resolutions"], `${spec.family} needs its resolution options`);
6829
+ } else {
6830
+ if (!res.options.includes(res.default)) {
6831
+ add(["resolutions", "default"], "default must be an option");
6832
+ }
6833
+ if (new Set(res.options).size !== res.options.length) {
6834
+ add(["resolutions", "options"], "resolution options repeat");
6835
+ }
6836
+ const allowed = rules.resolutions;
6837
+ for (const option of res.options) {
6838
+ const ok = allowed === "integer" ? /^[1-9][0-9]*$/.test(option) : Object.hasOwn(allowed, option);
6839
+ if (!ok)
6840
+ add(["resolutions", "options"], `${spec.family} has no "${option}" resolution`);
6841
+ }
6842
+ }
6843
+ return issues;
6844
+ }
6690
6845
  function model3dInputRefusal(spec, wired) {
6691
6846
  const top = spec.views === "unordered" && wired.top === true;
6692
6847
  const anyView = spec.views !== "none" && (wired.back || wired.left || wired.right || top);
@@ -7274,156 +7429,6 @@ var LanguageOptionSchema = import_zod3.z.looseObject({
7274
7429
  code: import_zod3.z.string().min(1),
7275
7430
  name: import_zod3.z.string().min(1)
7276
7431
  });
7277
- var MODEL3D_FAMILY_RULES = {
7278
- trellis: {
7279
- textPath: false,
7280
- views: ["none"],
7281
- multiImage: false,
7282
- texture: null,
7283
- pbr: false,
7284
- seed: true,
7285
- textureRef: false,
7286
- resolutions: "integer"
7287
- },
7288
- hunyuan: {
7289
- textPath: true,
7290
- views: ["none", "named"],
7291
- multiImage: false,
7292
- texture: ["none", "standard"],
7293
- pbr: true,
7294
- seed: false,
7295
- textureRef: false,
7296
- resolutions: null
7297
- },
7298
- tripo: {
7299
- textPath: true,
7300
- views: ["none", "ordered"],
7301
- multiImage: true,
7302
- texture: ["none", "standard", "detailed"],
7303
- pbr: true,
7304
- seed: true,
7305
- textureRef: false,
7306
- resolutions: null
7307
- },
7308
- rodin: {
7309
- textPath: true,
7310
- views: ["none", "unordered"],
7311
- multiImage: false,
7312
- texture: null,
7313
- pbr: false,
7314
- seed: true,
7315
- textureRef: false,
7316
- resolutions: null
7317
- },
7318
- meshy: {
7319
- textPath: true,
7320
- views: ["none", "unordered"],
7321
- multiImage: true,
7322
- texture: ["none", "standard"],
7323
- pbr: true,
7324
- seed: true,
7325
- textureRef: true,
7326
- resolutions: null
7327
- },
7328
- hi3d: {
7329
- textPath: false,
7330
- views: ["none", "named"],
7331
- multiImage: true,
7332
- texture: ["none", "standard"],
7333
- pbr: true,
7334
- seed: false,
7335
- textureRef: false,
7336
- resolutions: ["quality", "master"]
7337
- },
7338
- sam: {
7339
- textPath: false,
7340
- views: ["none"],
7341
- multiImage: false,
7342
- texture: null,
7343
- pbr: false,
7344
- seed: true,
7345
- textureRef: false,
7346
- resolutions: null
7347
- }
7348
- };
7349
- function model3dSpecIssues(spec) {
7350
- const issues = [];
7351
- const add = (path, message) => issues.push({ path, message });
7352
- const rules = MODEL3D_FAMILY_RULES[spec.family];
7353
- const promptOnly = spec.text && !spec.imageRequired;
7354
- if (spec.endpoints.image === void 0)
7355
- add(["endpoints", "image"], "every row needs an image endpoint");
7356
- if (promptOnly && !rules.textPath) {
7357
- add(
7358
- ["imageRequired"],
7359
- `${spec.family} has no text-to-3D endpoint; a text row needs an image`
7360
- );
7361
- }
7362
- if (promptOnly && spec.endpoints.text === void 0) {
7363
- add(["endpoints", "text"], "a text row needs a text endpoint");
7364
- }
7365
- if (!rules.views.includes(spec.views)) {
7366
- add(["views"], `${spec.family} takes views ${rules.views.join(" or ")}`);
7367
- }
7368
- if (spec.views === "none" && spec.maxImages !== 1) {
7369
- add(["maxImages"], "a row without views takes 1 image");
7370
- }
7371
- if (spec.views === "unordered" && spec.maxImages < 2) {
7372
- add(["maxImages"], "a row with views takes at least 2 images");
7373
- }
7374
- const slots = MODEL3D_IMAGE_SLOTS[spec.views].length;
7375
- if (spec.views !== "none" && spec.maxImages > slots) {
7376
- add(["maxImages"], `a row with ${spec.views} views sends at most ${slots} images`);
7377
- }
7378
- if ((spec.views === "named" || spec.views === "ordered") && spec.maxImages < slots) {
7379
- add(
7380
- ["maxImages"],
7381
- `a row with ${spec.views} views takes ${slots} images (front and three sides)`
7382
- );
7383
- }
7384
- if (spec.views !== "none" && rules.multiImage && spec.endpoints.multiImage === void 0) {
7385
- add(["endpoints", "multiImage"], `${spec.family} sends views to a multi-image endpoint`);
7386
- }
7387
- if (rules.texture === null) {
7388
- if (spec.texture.length > 0) add(["texture"], `${spec.family} has no texture switch`);
7389
- } else {
7390
- const allowed = rules.texture;
7391
- if (spec.texture.length === 0) add(["texture"], `${spec.family} needs its texture options`);
7392
- if (new Set(spec.texture).size !== spec.texture.length)
7393
- add(["texture"], "texture options repeat");
7394
- for (const t of spec.texture) {
7395
- if (!allowed.includes(t)) add(["texture"], `${spec.family} has no "${t}" texture`);
7396
- }
7397
- }
7398
- if (spec.pbr && !rules.pbr) add(["pbr"], `${spec.family} has no PBR switch`);
7399
- if (spec.pbr && !spec.texture.some((t) => t !== "none")) {
7400
- add(["pbr"], "PBR needs a textured option");
7401
- }
7402
- if (spec.seed && !rules.seed) add(["seed"], `${spec.family} takes no seed`);
7403
- if (spec.seedMax !== void 0 && !spec.seed) add(["seedMax"], "seedMax needs seed");
7404
- if (spec.textureRef && !rules.textureRef)
7405
- add(["textureRef"], `${spec.family} takes no texture reference`);
7406
- const res = spec.resolutions;
7407
- if (rules.resolutions === null) {
7408
- if (res !== void 0) add(["resolutions"], `${spec.family} has no resolution option`);
7409
- } else if (res === void 0) {
7410
- add(["resolutions"], `${spec.family} needs its resolution options`);
7411
- } else {
7412
- if (!res.options.includes(res.default)) {
7413
- add(["resolutions", "default"], "default must be an option");
7414
- }
7415
- if (new Set(res.options).size !== res.options.length) {
7416
- add(["resolutions", "options"], "resolution options repeat");
7417
- }
7418
- const allowed = rules.resolutions;
7419
- for (const option of res.options) {
7420
- const ok = allowed === "integer" ? /^[1-9][0-9]*$/.test(option) : allowed.includes(option);
7421
- if (!ok)
7422
- add(["resolutions", "options"], `${spec.family} has no "${option}" resolution`);
7423
- }
7424
- }
7425
- return issues;
7426
- }
7427
7432
  var VideoToolConstraintsSchema = import_zod3.z.looseObject({
7428
7433
  kind: import_zod3.z.enum(["upscale", "interpolate", "hdr", "bg-remove", "subtitles"]),
7429
7434
  upscaleFactor: RangeSchema.optional(),
@@ -10825,6 +10830,19 @@ function specOf(ctx) {
10825
10830
  return spec;
10826
10831
  }
10827
10832
  var present = (v) => v !== void 0 && v.length > 0;
10833
+ function wireValue(row2, values, option, what) {
10834
+ const value = option !== void 0 && Object.hasOwn(values, option) ? values[option] : void 0;
10835
+ if (value === void 0) {
10836
+ throw new ModelKitError({
10837
+ code: "unsupported_option",
10838
+ message: `${row2.id} has no ${what} "${option ?? ""}" to send`,
10839
+ provider: "fal",
10840
+ model: row2.id,
10841
+ retryable: false
10842
+ });
10843
+ }
10844
+ return value;
10845
+ }
10828
10846
  function model3dCall(row2, spec, req) {
10829
10847
  const prompt = req.prompt?.trim() || void 0;
10830
10848
  const texture = model3dTexture(spec, req.texture);
@@ -10868,7 +10886,15 @@ function model3dCall(row2, spec, req) {
10868
10886
  }
10869
10887
  };
10870
10888
  case "hunyuan": {
10871
- const opts = { generate_type: textured ? "Normal" : "Geometry", enable_pbr: pbr };
10889
+ const opts = {
10890
+ generate_type: wireValue(
10891
+ row2,
10892
+ MODEL3D_FAMILY_RULES.hunyuan.texture,
10893
+ texture,
10894
+ "texture"
10895
+ ),
10896
+ enable_pbr: pbr
10897
+ };
10872
10898
  if (!present(req.image)) {
10873
10899
  return {
10874
10900
  endpoint: endpoint(spec.endpoints.text),
@@ -10887,12 +10913,11 @@ function model3dCall(row2, spec, req) {
10887
10913
  };
10888
10914
  }
10889
10915
  case "tripo": {
10916
+ const quality = wireValue(row2, MODEL3D_FAMILY_RULES.tripo.texture, texture, "texture");
10890
10917
  const opts = {
10891
10918
  texture: textured,
10892
10919
  pbr,
10893
- ...textured && {
10894
- texture_quality: texture === "detailed" ? "detailed" : "standard"
10895
- },
10920
+ ...quality !== null && { texture_quality: quality },
10896
10921
  ...seed !== void 0 && { model_seed: seed }
10897
10922
  };
10898
10923
  if (!present(req.image)) {
@@ -10928,6 +10953,7 @@ function model3dCall(row2, spec, req) {
10928
10953
  };
10929
10954
  }
10930
10955
  case "meshy": {
10956
+ const mode = wireValue(row2, MODEL3D_FAMILY_RULES.meshy.texture, texture, "texture");
10931
10957
  const texturePrompt = req.texturePrompt?.trim() || void 0;
10932
10958
  const opts = {
10933
10959
  enable_pbr: pbr,
@@ -10939,7 +10965,7 @@ function model3dCall(row2, spec, req) {
10939
10965
  endpoint: endpoint(spec.endpoints.text),
10940
10966
  input: {
10941
10967
  prompt: prompt ?? "",
10942
- mode: textured ? "full" : "preview",
10968
+ mode,
10943
10969
  ...opts,
10944
10970
  ...seed !== void 0 && { seed }
10945
10971
  }
@@ -10955,8 +10981,18 @@ function model3dCall(row2, spec, req) {
10955
10981
  }
10956
10982
  case "hi3d": {
10957
10983
  const opts = {
10958
- resolution: resolution === "master" ? "2048master" : "2048quality",
10959
- enable_texture: textured,
10984
+ resolution: wireValue(
10985
+ row2,
10986
+ MODEL3D_FAMILY_RULES.hi3d.resolutions,
10987
+ resolution,
10988
+ "resolution"
10989
+ ),
10990
+ enable_texture: wireValue(
10991
+ row2,
10992
+ MODEL3D_FAMILY_RULES.hi3d.texture,
10993
+ texture,
10994
+ "texture"
10995
+ ),
10960
10996
  enable_pbr: pbr,
10961
10997
  export_format: "glb"
10962
10998
  };