@nodaro/shared 3.56.0 → 3.58.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.
Files changed (127) hide show
  1. package/dist/{chunk-PFXPAWPQ.cjs → chunk-4UUX62S3.cjs} +12 -12
  2. package/dist/{chunk-PFXPAWPQ.cjs.map → chunk-4UUX62S3.cjs.map} +1 -1
  3. package/dist/{chunk-CGZLENU4.cjs → chunk-4ZZ6SVIQ.cjs} +90 -6
  4. package/dist/chunk-4ZZ6SVIQ.cjs.map +1 -0
  5. package/dist/{chunk-33P5FI2U.cjs → chunk-5PJC4ZWO.cjs} +6 -6
  6. package/dist/{chunk-33P5FI2U.cjs.map → chunk-5PJC4ZWO.cjs.map} +1 -1
  7. package/dist/{chunk-TSKYEREJ.cjs → chunk-5UVBFY2G.cjs} +11 -11
  8. package/dist/{chunk-TSKYEREJ.cjs.map → chunk-5UVBFY2G.cjs.map} +1 -1
  9. package/dist/{chunk-2AR3OXAA.js → chunk-6CYS7VRH.js} +89 -7
  10. package/dist/chunk-6CYS7VRH.js.map +1 -0
  11. package/dist/{chunk-4O5STV7N.js → chunk-6TFWFYYI.js} +3 -3
  12. package/dist/{chunk-4O5STV7N.js.map → chunk-6TFWFYYI.js.map} +1 -1
  13. package/dist/{chunk-DURFRWAW.js → chunk-A5ESI2NY.js} +8 -8
  14. package/dist/{chunk-DURFRWAW.js.map → chunk-A5ESI2NY.js.map} +1 -1
  15. package/dist/{chunk-62ZQQA7L.js → chunk-BSENM6HM.js} +3 -3
  16. package/dist/{chunk-62ZQQA7L.js.map → chunk-BSENM6HM.js.map} +1 -1
  17. package/dist/{chunk-RX7WII6I.js → chunk-CNSRCZYY.js} +5 -5
  18. package/dist/{chunk-RX7WII6I.js.map → chunk-CNSRCZYY.js.map} +1 -1
  19. package/dist/{chunk-2J6NTA5I.js → chunk-DC2QPACA.js} +5 -5
  20. package/dist/chunk-DC2QPACA.js.map +1 -0
  21. package/dist/{chunk-HWJE4FNS.cjs → chunk-DCP7JFSE.cjs} +5 -5
  22. package/dist/{chunk-HWJE4FNS.cjs.map → chunk-DCP7JFSE.cjs.map} +1 -1
  23. package/dist/{chunk-AZDVL7IM.js → chunk-HEUWAIXG.js} +6 -6
  24. package/dist/chunk-HEUWAIXG.js.map +1 -0
  25. package/dist/{chunk-JO3XSUO2.cjs → chunk-I7NG2D6X.cjs} +21 -21
  26. package/dist/{chunk-JO3XSUO2.cjs.map → chunk-I7NG2D6X.cjs.map} +1 -1
  27. package/dist/{chunk-FCQYMPUQ.cjs → chunk-IKOKRJDI.cjs} +4 -4
  28. package/dist/{chunk-FCQYMPUQ.cjs.map → chunk-IKOKRJDI.cjs.map} +1 -1
  29. package/dist/{chunk-ZYITB47P.js → chunk-IQBIH3AE.js} +3 -3
  30. package/dist/{chunk-ZYITB47P.js.map → chunk-IQBIH3AE.js.map} +1 -1
  31. package/dist/{chunk-55FQBILM.js → chunk-JUEFRVHZ.js} +4 -4
  32. package/dist/{chunk-55FQBILM.js.map → chunk-JUEFRVHZ.js.map} +1 -1
  33. package/dist/{chunk-4ONS6QRT.js → chunk-K6UMB37V.js} +3 -3
  34. package/dist/{chunk-4ONS6QRT.js.map → chunk-K6UMB37V.js.map} +1 -1
  35. package/dist/{chunk-IKP4GOWZ.cjs → chunk-KYHDKKUJ.cjs} +8 -8
  36. package/dist/{chunk-IKP4GOWZ.cjs.map → chunk-KYHDKKUJ.cjs.map} +1 -1
  37. package/dist/{chunk-7DGJDISO.js → chunk-L26G7B27.js} +3 -3
  38. package/dist/{chunk-7DGJDISO.js.map → chunk-L26G7B27.js.map} +1 -1
  39. package/dist/{chunk-JHTYULY2.js → chunk-M7SMSAOU.js} +4 -4
  40. package/dist/{chunk-JHTYULY2.js.map → chunk-M7SMSAOU.js.map} +1 -1
  41. package/dist/{chunk-6GGHM33Z.js → chunk-ODTZV3BW.js} +4 -4
  42. package/dist/{chunk-6GGHM33Z.js.map → chunk-ODTZV3BW.js.map} +1 -1
  43. package/dist/{chunk-MROKQP4U.js → chunk-OMUYZKRB.js} +3 -3
  44. package/dist/{chunk-MROKQP4U.js.map → chunk-OMUYZKRB.js.map} +1 -1
  45. package/dist/{chunk-AKDJKMAL.cjs → chunk-PK4ZR2SK.cjs} +4 -4
  46. package/dist/{chunk-AKDJKMAL.cjs.map → chunk-PK4ZR2SK.cjs.map} +1 -1
  47. package/dist/chunk-QCW6J6BQ.cjs +27 -0
  48. package/dist/chunk-QCW6J6BQ.cjs.map +1 -0
  49. package/dist/{chunk-ZXDH3L3P.cjs → chunk-QPBBIRLF.cjs} +40 -39
  50. package/dist/{chunk-ZXDH3L3P.cjs.map → chunk-QPBBIRLF.cjs.map} +1 -1
  51. package/dist/{chunk-ILMHITHK.cjs → chunk-QVPIO2NU.cjs} +5 -5
  52. package/dist/{chunk-ILMHITHK.cjs.map → chunk-QVPIO2NU.cjs.map} +1 -1
  53. package/dist/{chunk-EWARI452.cjs → chunk-S5VBJJUT.cjs} +46 -46
  54. package/dist/chunk-S5VBJJUT.cjs.map +1 -0
  55. package/dist/{chunk-ST4WQ6ND.js → chunk-SEQ5L72K.js} +52 -11
  56. package/dist/chunk-SEQ5L72K.js.map +1 -0
  57. package/dist/{chunk-EAKO7PGC.js → chunk-VVGSIWNL.js} +5 -4
  58. package/dist/{chunk-EAKO7PGC.js.map → chunk-VVGSIWNL.js.map} +1 -1
  59. package/dist/{chunk-O7DXNX5J.cjs → chunk-VZXRDSWA.cjs} +74 -28
  60. package/dist/chunk-VZXRDSWA.cjs.map +1 -0
  61. package/dist/{chunk-WKCFTWLO.cjs → chunk-WBERPAXE.cjs} +6 -6
  62. package/dist/{chunk-WKCFTWLO.cjs.map → chunk-WBERPAXE.cjs.map} +1 -1
  63. package/dist/{chunk-H7VMJBNZ.cjs → chunk-WLFT5UVV.cjs} +8 -8
  64. package/dist/{chunk-H7VMJBNZ.cjs.map → chunk-WLFT5UVV.cjs.map} +1 -1
  65. package/dist/{chunk-4JODLC2N.js → chunk-ZMH56CLL.js} +3 -3
  66. package/dist/{chunk-4JODLC2N.js.map → chunk-ZMH56CLL.js.map} +1 -1
  67. package/dist/{chunk-CLKU3ZIU.cjs → chunk-ZX6RRM6R.cjs} +43 -43
  68. package/dist/{chunk-CLKU3ZIU.cjs.map → chunk-ZX6RRM6R.cjs.map} +1 -1
  69. package/dist/entries/apps.cjs +42 -42
  70. package/dist/entries/apps.js +7 -7
  71. package/dist/entries/credits.cjs +150 -150
  72. package/dist/entries/credits.d.cts +1 -1
  73. package/dist/entries/credits.d.ts +1 -1
  74. package/dist/entries/credits.js +7 -7
  75. package/dist/entries/llm-models.d.cts +1 -1
  76. package/dist/entries/llm-models.d.ts +1 -1
  77. package/dist/entries/model-catalog.cjs +76 -68
  78. package/dist/entries/model-catalog.d.cts +2 -2
  79. package/dist/entries/model-catalog.d.ts +2 -2
  80. package/dist/entries/model-catalog.js +4 -4
  81. package/dist/entries/models.cjs +303 -283
  82. package/dist/entries/models.d.cts +3 -3
  83. package/dist/entries/models.d.ts +3 -3
  84. package/dist/entries/models.js +4 -4
  85. package/dist/entries/nodes.cjs +206 -206
  86. package/dist/entries/nodes.d.cts +1 -1
  87. package/dist/entries/nodes.d.ts +1 -1
  88. package/dist/entries/nodes.js +8 -8
  89. package/dist/entries/pipeline.cjs +152 -152
  90. package/dist/entries/pipeline.d.cts +1 -1
  91. package/dist/entries/pipeline.d.ts +1 -1
  92. package/dist/entries/pipeline.js +3 -3
  93. package/dist/entries/ugc.cjs +71 -71
  94. package/dist/entries/ugc.js +4 -4
  95. package/dist/entries/video.cjs +117 -117
  96. package/dist/entries/video.js +4 -4
  97. package/dist/index.cjs +1093 -1065
  98. package/dist/index.d.cts +2 -2
  99. package/dist/index.d.ts +2 -2
  100. package/dist/index.js +17 -17
  101. package/dist/{model-catalog-vQ3NWn24.d.cts → model-catalog-CCsA1isC.d.cts} +58 -13
  102. package/dist/{model-catalog-vQ3NWn24.d.ts → model-catalog-CCsA1isC.d.ts} +58 -13
  103. package/dist/{model-constants-QZVHZX25.d.ts → model-constants-BtXkUsX3.d.cts} +36 -9
  104. package/dist/{model-constants-QZVHZX25.d.cts → model-constants-BtXkUsX3.d.ts} +36 -9
  105. package/package.json +1 -1
  106. package/src/__tests__/auto-aspect-source.test.ts +93 -0
  107. package/src/__tests__/gvp-supported-providers.test.ts +2 -0
  108. package/src/__tests__/normalize-model-input.test.ts +62 -8
  109. package/src/__tests__/resolutions-by-aspect-ratio.test.ts +134 -0
  110. package/src/__tests__/seedance-25-catalog-modes.test.ts +35 -0
  111. package/src/__tests__/video-frame-slot.test.ts +5 -0
  112. package/src/credit-identifiers.ts +3 -1
  113. package/src/entries/model-catalog.ts +2 -0
  114. package/src/entries/models.ts +5 -0
  115. package/src/model-catalog.ts +161 -20
  116. package/src/model-constants.ts +79 -7
  117. package/src/node-default-mappings.ts +1 -0
  118. package/src/video-ui-defaults.ts +2 -1
  119. package/dist/chunk-2AR3OXAA.js.map +0 -1
  120. package/dist/chunk-2J6NTA5I.js.map +0 -1
  121. package/dist/chunk-AZDVL7IM.js.map +0 -1
  122. package/dist/chunk-CGZLENU4.cjs.map +0 -1
  123. package/dist/chunk-EWARI452.cjs.map +0 -1
  124. package/dist/chunk-O7DXNX5J.cjs.map +0 -1
  125. package/dist/chunk-ST4WQ6ND.js.map +0 -1
  126. package/dist/chunk-XPUGMYAJ.cjs +0 -27
  127. package/dist/chunk-XPUGMYAJ.cjs.map +0 -1
@@ -76,18 +76,19 @@ describe("normalizeModelInput", () => {
76
76
  expect(normalizeModelInput("gpt-image-2", { aspectRatio: "1:1", resolution: "4K" }).resolution).toBe("2K")
77
77
  })
78
78
 
79
- // GPT Image 2.5 is NOT GPT Image 2. Its KIE docs
80
- // (docs.kie.ai/market/gpt/gpt-image-2-5-*) state no aspect_ratio x resolution
81
- // restriction, so the cross-field block above must NOT be widened to these
82
- // ids "for consistency" — doing so would silently downgrade a paid 4K render
83
- // to 1K. If GPT Image 2.5 ever documents such a limit, add it deliberately
84
- // and change this test in the same commit.
85
- it.each([
79
+ // GPT Image 2.5 is NOT GPT Image 2. Its docs
80
+ // (docs.kie.ai/market/gpt/gpt-image-2-5-*) limit four ratios to 1K and
81
+ // nothing else, so GPT Image 2's own rules (auto → 1K, 1:1 not at 4K) must
82
+ // NOT be widened to these ids "for consistency" — that would downgrade a paid
83
+ // 4K render to 1K. The four ratios are the catalog's
84
+ // `resolutionsByAspectRatio`, tested below.
85
+ const GPT_IMAGE_2_5_IDS = [
86
86
  "gpt-image-2-5-flare",
87
87
  "gpt-image-2-5-flare-i2i",
88
88
  "gpt-image-2-5-sunburst",
89
89
  "gpt-image-2-5-sunburst-i2i",
90
- ])("%s has NO cross-field aspect-ratio x resolution rule", (modelId) => {
90
+ ]
91
+ it.each(GPT_IMAGE_2_5_IDS)("%s keeps 4K at auto and at 1:1 (GPT Image 2's rules are not its own)", (modelId) => {
91
92
  const auto4k = normalizeModelInput(modelId, { aspectRatio: "auto", resolution: "4K" })
92
93
  expect(auto4k.resolution).toBe("4K")
93
94
  expect(auto4k.adjustments).toEqual([])
@@ -97,6 +98,59 @@ describe("normalizeModelInput", () => {
97
98
  expect(square4k.adjustments).toEqual([])
98
99
  })
99
100
 
101
+ const ONE_K_ONLY_RATIOS = ["27:16", "16:27", "9:8", "8:9"]
102
+ describe.each(GPT_IMAGE_2_5_IDS)("%s renders 27:16, 16:27, 9:8 and 8:9 at 1K only", (modelId) => {
103
+ it.each(ONE_K_ONLY_RATIOS.flatMap((ratio) => ["2K", "4K"].map((size) => [ratio, size] as const)))(
104
+ "%s at %s moves to 1K and says so",
105
+ (ratio, size) => {
106
+ const out = normalizeModelInput(modelId, { aspectRatio: ratio, resolution: size })
107
+ expect(out.aspectRatio).toBe(ratio)
108
+ expect(out.resolution).toBe("1K")
109
+ expect(out.adjustments).toEqual([{
110
+ field: "resolution",
111
+ from: size,
112
+ to: "1K",
113
+ reason: `${MODEL_CATALOG[modelId].label} only renders 1K at the "${ratio}" aspect ratio.`,
114
+ }])
115
+ },
116
+ )
117
+
118
+ it.each(ONE_K_ONLY_RATIOS)("%s at 1K, or with no size, is left as it is", (ratio) => {
119
+ expect(normalizeModelInput(modelId, { aspectRatio: ratio, resolution: "1K" }).adjustments).toEqual([])
120
+ const unset = normalizeModelInput(modelId, { aspectRatio: ratio })
121
+ expect(unset.resolution).toBeUndefined()
122
+ expect(unset.adjustments).toEqual([])
123
+ })
124
+
125
+ it.each(["auto", "1:1", "3:2", "2:3", "4:3", "3:4", "16:9", "9:16", "21:9"])("%s keeps 2K and 4K", (ratio) => {
126
+ for (const size of ["2K", "4K"]) {
127
+ const out = normalizeModelInput(modelId, { aspectRatio: ratio, resolution: size })
128
+ expect(out.resolution).toBe(size)
129
+ expect(out.adjustments).toEqual([])
130
+ }
131
+ })
132
+
133
+ it("an opaque background at 27:16 and 2K keeps its setting, as the size it renders is 1K", () => {
134
+ const out = normalizeModelInput(modelId, { aspectRatio: "27:16", resolution: "2K", background: "opaque" })
135
+ expect(out.resolution).toBe("1K")
136
+ expect(out.background).toBe("opaque")
137
+ expect(out.adjustments.map((a) => a.field)).toEqual(["resolution"])
138
+ })
139
+
140
+ it("a transparent background at 9:8 and 4K is one move to 1K", () => {
141
+ const out = normalizeModelInput(modelId, { aspectRatio: "9:8", resolution: "4K", background: "transparent" })
142
+ expect(out.resolution).toBe("1K")
143
+ expect(out.background).toBe("transparent")
144
+ expect(out.adjustments).toHaveLength(1)
145
+ })
146
+ })
147
+
148
+ it("GPT Image 2.6 offers none of the four ratios, so the rule never reaches it", () => {
149
+ for (const id of Object.keys(MODEL_CATALOG).filter((m) => m.startsWith("gpt-image-2-6"))) {
150
+ expect(MODEL_CATALOG[id].resolutionsByAspectRatio, id).toBeUndefined()
151
+ }
152
+ })
153
+
100
154
  // The four ratios 2.5 introduced are new to the platform vocabulary; the snap
101
155
  // must accept them rather than rewrite them to a neighbour.
102
156
  it.each(["27:16", "16:27", "9:8", "8:9", "21:9", "3:2"])(
@@ -0,0 +1,134 @@
1
+ import { describe, it, expect } from "vitest"
2
+ import {
3
+ MODEL_CATALOG,
4
+ defaultResolutionFor,
5
+ resolutionAtAspectRatio,
6
+ resolutionsAtAspectRatio,
7
+ } from "../model-catalog.js"
8
+ import { buildCreditModelIdentifier, resolveNormalizedImageGen } from "../credit-identifiers.js"
9
+ import { normalizeNodeModelParams } from "../normalize-node-params.js"
10
+
11
+ /**
12
+ * `resolutionsByAspectRatio`: the ratios at which a model renders fewer sizes
13
+ * than it lists. GPT Image 2.5 renders 27:16, 16:27, 9:8 and 8:9 at 1K only, so
14
+ * a 2K or 4K request there is sent, and priced, as 1K.
15
+ */
16
+
17
+ const GPT_IMAGE_2_5 = [
18
+ "gpt-image-2-5-flare",
19
+ "gpt-image-2-5-flare-i2i",
20
+ "gpt-image-2-5-sunburst",
21
+ "gpt-image-2-5-sunburst-i2i",
22
+ ] as const
23
+ const ONE_K_ONLY = ["27:16", "16:27", "9:8", "8:9"] as const
24
+
25
+ describe("the catalog's resolutionsByAspectRatio", () => {
26
+ it("is declared on the four GPT Image 2.5 ids, 1K at each of the four ratios", () => {
27
+ for (const id of GPT_IMAGE_2_5) {
28
+ expect(MODEL_CATALOG[id].resolutionsByAspectRatio, id).toEqual({
29
+ "27:16": ["1K"], "16:27": ["1K"], "9:8": ["1K"], "8:9": ["1K"],
30
+ })
31
+ }
32
+ })
33
+
34
+ it("INVARIANT: every declaration names the model's own ratios and sizes, and its default size renders everywhere", () => {
35
+ const failures: string[] = []
36
+ for (const [id, m] of Object.entries(MODEL_CATALOG)) {
37
+ if (!m.resolutionsByAspectRatio) continue
38
+ // The size an unset request is priced at must render at every listed
39
+ // ratio, or a request naming no size would be priced above what it renders.
40
+ const unsetSize = defaultResolutionFor(id) ?? m.resolutions?.[0]
41
+ for (const [ratio, sizes] of Object.entries(m.resolutionsByAspectRatio)) {
42
+ if (!m.aspectRatios?.includes(ratio)) failures.push(`${id}: ${ratio} is not one of its ratios`)
43
+ if (sizes.length === 0) failures.push(`${id}: ${ratio} renders no size`)
44
+ for (const size of sizes) {
45
+ if (!m.resolutions?.includes(size)) failures.push(`${id}: ${ratio} names ${size}, not one of its sizes`)
46
+ }
47
+ if (unsetSize !== undefined && !sizes.includes(unsetSize)) {
48
+ failures.push(`${id}: its default size ${unsetSize} does not render at ${ratio}`)
49
+ }
50
+ }
51
+ }
52
+ expect(failures).toEqual([])
53
+ })
54
+ })
55
+
56
+ describe("resolutionsAtAspectRatio", () => {
57
+ it("narrows the sizes at a limited ratio, in the catalog's order", () => {
58
+ for (const id of GPT_IMAGE_2_5) {
59
+ for (const ratio of ONE_K_ONLY) expect(resolutionsAtAspectRatio(id, ratio)).toEqual(["1K"])
60
+ expect(resolutionsAtAspectRatio(id, "16:9")).toEqual(["1K", "2K", "4K"])
61
+ expect(resolutionsAtAspectRatio(id, "auto")).toEqual(["1K", "2K", "4K"])
62
+ expect(resolutionsAtAspectRatio(id, undefined)).toEqual(["1K", "2K", "4K"])
63
+ }
64
+ })
65
+
66
+ it("reads a padded ratio, and never the object's prototype", () => {
67
+ expect(resolutionsAtAspectRatio("gpt-image-2-5-flare", " 9:8 ")).toEqual(["1K"])
68
+ expect(resolutionsAtAspectRatio("gpt-image-2-5-flare", "constructor")).toEqual(["1K", "2K", "4K"])
69
+ expect(resolutionsAtAspectRatio("gpt-image-2-5-flare", "__proto__")).toEqual(["1K", "2K", "4K"])
70
+ })
71
+
72
+ it("is the model's own list where nothing is limited, and undefined with no size setting", () => {
73
+ expect(resolutionsAtAspectRatio("gpt-image-2-6-flare", "16:9")).toEqual(MODEL_CATALOG["gpt-image-2-6-flare"].resolutions)
74
+ expect(resolutionsAtAspectRatio("nano-banana", "16:9")).toBeUndefined()
75
+ expect(resolutionsAtAspectRatio("not-a-model", "27:16")).toBeUndefined()
76
+ })
77
+ })
78
+
79
+ describe("resolutionAtAspectRatio", () => {
80
+ it("moves a size the ratio does not render to the largest it does at or below it", () => {
81
+ for (const ratio of ONE_K_ONLY) {
82
+ expect(resolutionAtAspectRatio("gpt-image-2-5-sunburst", ratio, "4K")).toBe("1K")
83
+ expect(resolutionAtAspectRatio("gpt-image-2-5-sunburst", ratio, "2K")).toBe("1K")
84
+ expect(resolutionAtAspectRatio("gpt-image-2-5-sunburst", ratio, "1K")).toBe("1K")
85
+ }
86
+ })
87
+
88
+ it("leaves everything else as it is", () => {
89
+ expect(resolutionAtAspectRatio("gpt-image-2-5-flare", "16:9", "4K")).toBe("4K")
90
+ expect(resolutionAtAspectRatio("gpt-image-2-5-flare", "27:16", undefined)).toBeUndefined()
91
+ // A size the model does not list is the lever snap's to correct, not this one's.
92
+ expect(resolutionAtAspectRatio("gpt-image-2-5-flare", "27:16", "8K")).toBe("8K")
93
+ expect(resolutionAtAspectRatio("gpt-image-2-6-flare", "21:9", "4K")).toBe("4K")
94
+ expect(resolutionAtAspectRatio("not-a-model", "27:16", "4K")).toBe("4K")
95
+ })
96
+ })
97
+
98
+ describe("the price follows the size that renders (quote = charge)", () => {
99
+ it.each(GPT_IMAGE_2_5.flatMap((id) => ONE_K_ONLY.map((ratio) => [id, ratio] as const)))(
100
+ "%s at %s: a 2K or 4K request is priced as 1K",
101
+ (id, ratio) => {
102
+ for (const resolution of ["2K", "4K"]) {
103
+ // Image-to-image / edit pricing (no swap) and Generate Image pricing.
104
+ const direct = resolveNormalizedImageGen({ provider: id, aspectRatio: ratio, resolution, refCount: 1, swapToI2i: false })
105
+ expect(direct.resolution).toBe("1K")
106
+ expect(direct.identifier).toBe(buildCreditModelIdentifier(id, undefined, "1K"))
107
+ expect(direct.identifier).toBe(id)
108
+ expect(direct.adjustments.some((a) => a.field === "resolution" && a.to === "1K")).toBe(true)
109
+ }
110
+ },
111
+ )
112
+
113
+ it("a text-to-image id swapped onto its edit sibling by references is priced as that sibling's 1K", () => {
114
+ const out = resolveNormalizedImageGen({ provider: "gpt-image-2-5-flare", aspectRatio: "16:27", resolution: "4K", refCount: 2, swapToI2i: true })
115
+ expect(out.modelId).toBe("gpt-image-2-5-flare-i2i")
116
+ expect(out.resolution).toBe("1K")
117
+ expect(out.identifier).toBe("gpt-image-2-5-flare-i2i")
118
+ })
119
+
120
+ it("other ratios keep their 2K and 4K prices", () => {
121
+ expect(resolveNormalizedImageGen({ provider: "gpt-image-2-5-flare", aspectRatio: "21:9", resolution: "2K", refCount: 0 }).identifier)
122
+ .toBe("gpt-image-2-5-flare:2K")
123
+ expect(resolveNormalizedImageGen({ provider: "gpt-image-2-5-sunburst-i2i", aspectRatio: "auto", resolution: "4K", refCount: 1 }).identifier)
124
+ .toBe("gpt-image-2-5-sunburst-i2i:4K")
125
+ })
126
+
127
+ it("a workflow written by an agent stores the size that renders (normalizeNodeModelParams)", () => {
128
+ const { nodes, adjustments } = normalizeNodeModelParams([
129
+ { id: "n1", type: "generate-image", data: { provider: "gpt-image-2-5-sunburst", aspectRatio: "9:8", resolution: "4K" } },
130
+ ])
131
+ expect((nodes[0]!.data as Record<string, unknown>).resolution).toBe("1K")
132
+ expect(adjustments).toMatchObject([{ nodeId: "n1", field: "resolution", from: "4K", to: "1K" }])
133
+ })
134
+ })
@@ -0,0 +1,35 @@
1
+ import { describe, expect, it } from "vitest"
2
+
3
+ import { MODEL_CATALOG } from "../model-catalog"
4
+ import { VIDEO_TO_VIDEO_NODE_PROVIDERS, isSeedanceVideoEditProvider, videoProviderRequiresImage } from "../model-constants"
5
+ import { modelToNodeTarget } from "../model-tree"
6
+
7
+ /**
8
+ * The catalog's `modes` are what a model can be run for: `/v1/models`, MCP
9
+ * `list_models`, the header's menu categories. Seedance 2.5 edits a clip on the
10
+ * same route as the other edit models (`/v1/video-to-video`, through the
11
+ * reference lane), so the catalog says `v2v` for it, and everything that makes
12
+ * a clip from words or a picture is unchanged by that.
13
+ */
14
+ describe("Seedance 2.5 in the catalog", () => {
15
+ const entry = MODEL_CATALOG["seedance-2-5"]!
16
+
17
+ it("lists the video-to-video mode the edit route runs it in", () => {
18
+ expect(entry.modes).toContain("v2v")
19
+ expect(VIDEO_TO_VIDEO_NODE_PROVIDERS).toContain("seedance-2-5")
20
+ expect(isSeedanceVideoEditProvider("seedance-2-5")).toBe(true)
21
+ })
22
+
23
+ it("is still a model that makes a clip from words or a picture: a generation does not start needing a clip", () => {
24
+ expect(entry.modes).toEqual(expect.arrayContaining(["i2v", "t2v"]))
25
+ // The first mode stays the same for anything that reads the modes in order.
26
+ expect(entry.modes[0]).toBe("i2v")
27
+ expect(videoProviderRequiresImage("seedance-2-5")).toBe(false)
28
+ expect(modelToNodeTarget("seedance-2-5")).toEqual({ nodeType: "generate-video", field: "provider", value: "seedance-2-5" })
29
+ })
30
+
31
+ it("is not listed as an extend model: extending is a model of its own", () => {
32
+ expect(entry.modes).not.toContain("extend")
33
+ expect(MODEL_CATALOG["seedance-2-extend"]?.modes).toContain("extend")
34
+ })
35
+ })
@@ -75,6 +75,11 @@ describe("videoProviderReferenceSyntax", () => {
75
75
  expect(videoProviderReferenceSyntax("happyhorse-ref2v")).toBe("[Image N]")
76
76
  })
77
77
 
78
+ it("names Gemini Omni Flash 1.2's images in plain words", () => {
79
+ expect(videoProviderReferenceSyntax("gemini-omni-flash-1-2")).toBe("image N")
80
+ expect(videoProviderReferenceSyntax("gemini-omni-flash")).toBe("@image_N")
81
+ })
82
+
78
83
  it("is declared only on reference-capable video models", () => {
79
84
  for (const m of Object.values(MODEL_CATALOG)) {
80
85
  if (!m.referenceSyntax) continue
@@ -23,6 +23,7 @@ import {
23
23
  isVeoProvider,
24
24
  isMinimaxH3Provider,
25
25
  isGeminiOmniProvider,
26
+ isGeminiOmniPerSecondProvider,
26
27
  isWan3Provider,
27
28
  isViduQ4Provider,
28
29
  isKling4Provider,
@@ -439,7 +440,8 @@ export function buildVideoCreditModelIdentifier(
439
440
  // provider id, so a further Omni SKU needs no edit here — it only has to join
440
441
  // GEMINI_OMNI_PROVIDERS and seed its rows. These models are deliberately NOT
441
442
  // in DURATION_PRICED_PROVIDERS; this branch early-returns before that gate.
442
- if (isGeminiOmniProvider(effectiveProvider)) {
443
+ // A per-second SKU (Omni Flash 1.2) prices on the `:<N>s:<res>` ladder below.
444
+ if (isGeminiOmniProvider(effectiveProvider) && !isGeminiOmniPerSecondProvider(effectiveProvider)) {
443
445
  if (hasVideoRef) {
444
446
  return resolution === "4k" ? `${effectiveProvider}:4k:vref` : `${effectiveProvider}:vref`
445
447
  }
@@ -63,6 +63,8 @@ export {
63
63
  nearestCatalogAspectRatio,
64
64
  autoAspectNeedsSourceImage,
65
65
  isAutoAspectToken,
66
+ resolutionsAtAspectRatio,
67
+ resolutionAtAspectRatio,
66
68
  } from "../model-catalog.js"
67
69
  export type {
68
70
  NormalizedVideoRequest,
@@ -18,6 +18,7 @@ export {
18
18
  getMaxImagePromptChars,
19
19
  PROMPT_HARD_CEILING,
20
20
  LLM_TEXT_INPUT_MAX,
21
+ LLM_STRUCTURED_SYSTEM_MAX,
21
22
  MAX_VIDEO_PROMPT_CHARS_BY_PROVIDER,
22
23
  getMaxVideoPromptChars,
23
24
  NEGATIVE_PROMPT_MAX,
@@ -173,6 +174,10 @@ export {
173
174
  billsReferenceVideoSeconds,
174
175
  GEMINI_OMNI_PROVIDERS,
175
176
  isGeminiOmniProvider,
177
+ GEMINI_OMNI_PER_SECOND_PROVIDERS,
178
+ isGeminiOmniPerSecondProvider,
179
+ GEMINI_OMNI_12_MAX_SOURCE_SEC,
180
+ videoSourceTrimMaxSec,
176
181
  VIDEO_PROVIDERS_WITHOUT_DISPATCH,
177
182
  GVP_DEFAULT_PROVIDER,
178
183
  GVP_SUPPORTED_PROVIDERS,
@@ -312,10 +312,34 @@ export interface ModelCatalogEntry {
312
312
  * Declared only where the provider documents its own form: Grok Imagine's
313
313
  * `@image(n)` (docs.kie.ai/market/grok-imagine/image-to-video) and
314
314
  * HappyHorse's `[Image N]` (docs.kie.ai/market/happyhorse-1-1/reference-to-video).
315
+ * Gemini Omni Flash 1.2 documents none and is written plain `image N`, the
316
+ * form of KIE's own example; beside references its frames only guide the
317
+ * clip, in either wording.
315
318
  */
316
- referenceSyntax?: "@image(n)" | "[Image N]"
319
+ referenceSyntax?: "@image(n)" | "[Image N]" | "image N"
317
320
  aspectRatios?: readonly string[]
321
+ /**
322
+ * The model lists "auto", but its own auto does not keep the photo's shape
323
+ * (GPT Image 2.6 renders a portrait square). "auto" with a photo is then
324
+ * resolved as on a model without a native auto: to the listed ratio nearest
325
+ * the photo (`autoAspectNeedsSourceImage`, `normalizeModelInput`). With no
326
+ * photo, or one whose size cannot be read, the model's own "auto" is sent,
327
+ * as before. "auto" stays in `aspectRatios`, so every menu still offers it.
328
+ */
329
+ autoAspectFromSourceImage?: true
318
330
  resolutions?: readonly string[]
331
+ /**
332
+ * The aspect ratios at which this model renders fewer sizes than
333
+ * `resolutions`: each one names the sizes it renders, in the catalog's own
334
+ * spelling. A ratio not listed renders every entry of `resolutions`.
335
+ * `normalizeModelInput` moves a size such a ratio does not render to the
336
+ * largest one it does at or below it, and says so, before the run is priced;
337
+ * a menu reads the sizes on offer with `resolutionsAtAspectRatio`.
338
+ */
339
+ resolutionsByAspectRatio?: Readonly<Record<string, readonly string[]>>
340
+ /** The resolution a caller who names none lands on when it is not the
341
+ * cheapest entry (see `defaultResolutionFor`). */
342
+ defaultResolution?: string
319
343
  /**
320
344
  * What this model actually RENDERS for a resolution outside `resolutions`.
321
345
  *
@@ -479,15 +503,23 @@ const GPT_IMAGE_RATIOS = ["1:1", "3:2", "2:3"] as const
479
503
  const GPT_IMAGE_2_RATIOS = ["auto", "1:1", "16:9", "9:16", "4:3", "3:4"] as const
480
504
  // GPT Image 2.5 (Flare + Sunburst) widen the set to thirteen — the GPT Image 2
481
505
  // six plus 3:2/2:3, ultra-wide 21:9/27:16, ultra-tall 16:27 and near-square
482
- // 9:8/8:9 (docs.kie.ai/market/gpt/gpt-image-2-5-*). Unlike GPT Image 2, the 2.5
483
- // docs state NO aspect-ratio x resolution restriction, so no cross-field
484
- // constraint is registered for these ids in normalizeModelInput below.
506
+ // 9:8/8:9 (docs.kie.ai/market/gpt/gpt-image-2-5-*).
485
507
  const GPT_IMAGE_2_5_RATIOS = [
486
508
  "auto", "1:1", "3:2", "2:3", "4:3", "3:4", "16:9", "9:16",
487
509
  "21:9", "27:16", "16:27", "9:8", "8:9",
488
510
  ] as const
511
+ // GPT Image 2.5 renders 27:16, 16:27, 9:8 and 8:9 at 1K only; 2K and 4K are for
512
+ // its other ratios (the aspect_ratio field of every 2.5 page: Flare and
513
+ // Sunburst, text-to-image and image-to-image). `normalizeModelInput` moves a
514
+ // larger size there to 1K before the run is priced.
515
+ const GPT_IMAGE_2_5_RESOLUTIONS_BY_RATIO = {
516
+ "27:16": ["1K"], "16:27": ["1K"], "9:8": ["1K"], "8:9": ["1K"],
517
+ } as const
489
518
  // GPT Image 2.6 Flare and Sunburst: auto plus fifteen ratios, Economy a shorter
490
- // list of its own (docs.kie.ai/market/gpt/gpt-image-2-6-*).
519
+ // list of its own (docs.kie.ai/market/gpt/gpt-image-2-6-*). Every 2.6 entry
520
+ // carries `autoAspectFromSourceImage`: 2.6's own auto renders a portrait photo
521
+ // square (measured 2026-11-10: 768x1024 in, 1024x1024 out; 2.5's auto kept
522
+ // it at 3:4), so "auto" with a photo is sent as the ratio nearest the photo.
491
523
  const GPT_IMAGE_2_6_RATIOS = [
492
524
  "auto", "1:1", "3:2", "2:3", "4:3", "3:4", "5:4", "4:5", "16:9", "9:16",
493
525
  "2:1", "1:2", "21:9", "9:21", "3:1", "1:3",
@@ -923,6 +955,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
923
955
  features: ["reference-image"],
924
956
  aspectRatios: GPT_IMAGE_2_5_RATIOS,
925
957
  resolutions: ["1K", "2K", "4K"],
958
+ resolutionsByAspectRatio: GPT_IMAGE_2_5_RESOLUTIONS_BY_RATIO,
926
959
  backgrounds: GPT_IMAGE_BACKGROUNDS,
927
960
  transparentResolution: "1K",
928
961
  backgroundOnlyAtTransparentResolution: true,
@@ -951,6 +984,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
951
984
  features: ["reference-image"],
952
985
  aspectRatios: GPT_IMAGE_2_5_RATIOS,
953
986
  resolutions: ["1K", "2K", "4K"],
987
+ resolutionsByAspectRatio: GPT_IMAGE_2_5_RESOLUTIONS_BY_RATIO,
954
988
  backgrounds: GPT_IMAGE_BACKGROUNDS,
955
989
  transparentResolution: "1K",
956
990
  backgroundOnlyAtTransparentResolution: true,
@@ -979,6 +1013,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
979
1013
  features: ["reference-image"],
980
1014
  aspectRatios: GPT_IMAGE_2_5_RATIOS,
981
1015
  resolutions: ["1K", "2K", "4K"],
1016
+ resolutionsByAspectRatio: GPT_IMAGE_2_5_RESOLUTIONS_BY_RATIO,
982
1017
  backgrounds: GPT_IMAGE_BACKGROUNDS,
983
1018
  transparentResolution: "1K",
984
1019
  backgroundOnlyAtTransparentResolution: true,
@@ -1007,6 +1042,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
1007
1042
  features: ["reference-image"],
1008
1043
  aspectRatios: GPT_IMAGE_2_5_RATIOS,
1009
1044
  resolutions: ["1K", "2K", "4K"],
1045
+ resolutionsByAspectRatio: GPT_IMAGE_2_5_RESOLUTIONS_BY_RATIO,
1010
1046
  backgrounds: GPT_IMAGE_BACKGROUNDS,
1011
1047
  transparentResolution: "1K",
1012
1048
  backgroundOnlyAtTransparentResolution: true,
@@ -1034,6 +1070,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
1034
1070
  useCases: ["typography", "high-res", "general", "draft"],
1035
1071
  features: ["reference-image"],
1036
1072
  aspectRatios: GPT_IMAGE_2_6_RATIOS,
1073
+ autoAspectFromSourceImage: true,
1037
1074
  resolutions: ["1K", "2K", "4K"],
1038
1075
  qualities: ["auto", "low", "medium", "high", "xhigh", "max"],
1039
1076
  defaultQuality: "medium",
@@ -1075,6 +1112,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
1075
1112
  useCases: ["edit", "high-res"],
1076
1113
  features: ["reference-image"],
1077
1114
  aspectRatios: GPT_IMAGE_2_6_RATIOS,
1115
+ autoAspectFromSourceImage: true,
1078
1116
  resolutions: ["1K", "2K", "4K"],
1079
1117
  qualities: ["auto", "low", "medium", "high", "xhigh", "max"],
1080
1118
  defaultQuality: "medium",
@@ -1103,6 +1141,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
1103
1141
  useCases: ["typography", "high-res", "general"],
1104
1142
  features: ["reference-image"],
1105
1143
  aspectRatios: GPT_IMAGE_2_6_RATIOS,
1144
+ autoAspectFromSourceImage: true,
1106
1145
  resolutions: ["1K", "2K", "4K"],
1107
1146
  qualities: ["auto", "low", "medium", "high", "xhigh", "max"],
1108
1147
  defaultQuality: "medium",
@@ -1144,6 +1183,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
1144
1183
  useCases: ["edit", "high-res"],
1145
1184
  features: ["reference-image"],
1146
1185
  aspectRatios: GPT_IMAGE_2_6_RATIOS,
1186
+ autoAspectFromSourceImage: true,
1147
1187
  resolutions: ["1K", "2K", "4K"],
1148
1188
  qualities: ["auto", "low", "medium", "high", "xhigh", "max"],
1149
1189
  defaultQuality: "medium",
@@ -1178,6 +1218,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
1178
1218
  useCases: ["general", "draft"],
1179
1219
  features: ["reference-image"],
1180
1220
  aspectRatios: GPT_IMAGE_2_6_ECONOMY_RATIOS,
1221
+ autoAspectFromSourceImage: true,
1181
1222
  backgrounds: GPT_IMAGE_BACKGROUNDS,
1182
1223
  pricing: [{ identifier: "gpt-image-2-6-economy", credits: 13, note: "1K flat" }],
1183
1224
  valueLabels: GPT_IMAGE_2_6_VALUE_LABELS,
@@ -1196,6 +1237,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
1196
1237
  useCases: ["edit", "draft"],
1197
1238
  features: ["reference-image"],
1198
1239
  aspectRatios: GPT_IMAGE_2_6_ECONOMY_RATIOS,
1240
+ autoAspectFromSourceImage: true,
1199
1241
  backgrounds: GPT_IMAGE_BACKGROUNDS,
1200
1242
  pricing: [{ identifier: "gpt-image-2-6-economy-i2i", credits: 13, note: "1K flat" }],
1201
1243
  valueLabels: GPT_IMAGE_2_6_VALUE_LABELS,
@@ -1926,6 +1968,33 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1926
1968
  { identifier: "gemini-omni-flash:4k:vref", credits: 630, note: "video-edit 4K" },
1927
1969
  ],
1928
1970
  },
1971
+ "gemini-omni-flash-1-2": {
1972
+ id: "gemini-omni-flash-1-2",
1973
+ kind: "video",
1974
+ modes: ["i2v", "t2v"] as const, // V2V is served via the i2v handle, not a catalog mode
1975
+ family: "Google",
1976
+ maker: "google",
1977
+ label: "Gemini Omni Flash 1.2",
1978
+ series: "Gemini",
1979
+ description: "Google Gemini Omni Flash 1.2 — 3–15s video with native sound, from 360p to 4K: from text, up to 6 reference images, exact first and last frames, or a video edit. Priced per second.",
1980
+ useCases: ["cinematic", "fast"],
1981
+ features: ["audio", "reference-image", "reference-to-video", "end-frame"],
1982
+ referenceSyntax: "image N",
1983
+ aspectRatios: ["16:9", "9:16", "auto"],
1984
+ resolutions: ["360p", "720p", "1080p", "4k"],
1985
+ defaultResolution: "720p",
1986
+ unlistedResolutionRendersAs: "720p",
1987
+ durations: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1988
+ defaultDuration: 8,
1989
+ pricing: [
1990
+ { identifier: "gemini-omni-flash-1-2", credits: 180, note: "default 8s 720p — see :Ns:res variants" },
1991
+ { identifier: "gemini-omni-flash-1-2:3s:360p", credits: 30, note: "3s 360p (min)" },
1992
+ { identifier: "gemini-omni-flash-1-2:8s:720p", credits: 180, note: "8s 720p (the default tier)" },
1993
+ { identifier: "gemini-omni-flash-1-2:8s:1080p", credits: 200, note: "8s 1080p" },
1994
+ { identifier: "gemini-omni-flash-1-2:8s:4k", credits: 440, note: "8s 4K" },
1995
+ { identifier: "gemini-omni-flash-1-2:15s:4k", credits: 830, note: "15s 4K (max)" },
1996
+ ],
1997
+ },
1929
1998
 
1930
1999
  // ── Kling ──
1931
2000
  "kling": {
@@ -2246,7 +2315,10 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
2246
2315
  "seedance-2-5": {
2247
2316
  id: "seedance-2-5",
2248
2317
  kind: "video",
2249
- modes: ["i2v", "t2v"] as const,
2318
+ // `v2v`: it edits a clip by instruction on the same route as the other edit
2319
+ // models (/v1/video-to-video, through its reference lane, in the clip's own
2320
+ // ratio and length). It still makes a clip from words or a picture.
2321
+ modes: ["i2v", "t2v", "v2v"] as const,
2250
2322
  family: "Bytedance",
2251
2323
  maker: "bytedance",
2252
2324
  label: "Seedance 2.5",
@@ -3912,10 +3984,14 @@ export function validateModelInput(
3912
3984
  * The resolution a Flux 2 model should land on when its stored value is absent
3913
3985
  * or invalid. Flux 2 exposes ascending megapixel options ("0.5 MP"…"4 MP"), so
3914
3986
  * snapping to `options[0]` would silently downgrade every node to the cheapest
3915
- * tier; each variant has a sensible mid default instead. Returns undefined for
3916
- * every non-Flux-2 model (they snap to `options[0]` normally).
3987
+ * tier; each variant has a sensible mid default instead. A model can also
3988
+ * declare one (`defaultResolution`, Gemini Omni Flash 1.2: its cheapest tier is
3989
+ * a 360p preview). Returns undefined for every other model (they snap to
3990
+ * `options[0]` normally).
3917
3991
  */
3918
3992
  export function defaultResolutionFor(modelId: string): string | undefined {
3993
+ const declared = MODEL_CATALOG[modelId]?.defaultResolution
3994
+ if (declared) return declared
3919
3995
  if (!isFlux2Model(modelId)) return undefined
3920
3996
  return modelId === "flux-2-klein" ? "1 MP" : "2 MP"
3921
3997
  }
@@ -3968,8 +4044,9 @@ export interface SourceImageSize {
3968
4044
  export interface ModelInputContext {
3969
4045
  /**
3970
4046
  * The image an image-to-image or edit request transforms. Only read to
3971
- * resolve "auto" on a model without a native auto; absent or unusable means
3972
- * the size is unknown and "auto" snaps the way it always has.
4047
+ * resolve "auto" on a model without a native auto, or whose own auto does
4048
+ * not keep the photo's shape (`autoAspectFromSourceImage`); absent or
4049
+ * unusable means the size is unknown and "auto" snaps the way it always has.
3973
4050
  */
3974
4051
  sourceImage?: SourceImageSize
3975
4052
  }
@@ -4030,14 +4107,59 @@ export function nearestCatalogAspectRatio(
4030
4107
 
4031
4108
  /**
4032
4109
  * True when `aspectRatio` is "auto" and `modelId`'s catalog ratio list does not
4033
- * carry "auto" — the one case where the source image's size decides the ratio.
4034
- * A caller that has to fetch the size asks this first, so a request that will
4035
- * not use it never pays for the read.
4110
+ * carry "auto", or carries it but the model's own auto does not keep the
4111
+ * photo's shape (`autoAspectFromSourceImage`) — the cases where the source
4112
+ * image's size decides the ratio. A caller that has to fetch the size asks
4113
+ * this first, so a request that will not use it never pays for the read.
4036
4114
  */
4037
4115
  export function autoAspectNeedsSourceImage(modelId: string | undefined, aspectRatio: unknown): boolean {
4038
4116
  if (!modelId || !isAutoAspectToken(aspectRatio)) return false
4039
- const ratios = MODEL_CATALOG[modelId]?.aspectRatios
4040
- return ratios !== undefined && ratios.length > 0 && !ratios.some(isAutoAspectToken)
4117
+ const entry = MODEL_CATALOG[modelId]
4118
+ const ratios = entry?.aspectRatios
4119
+ if (ratios === undefined || ratios.length === 0) return false
4120
+ return entry?.autoAspectFromSourceImage === true || !ratios.some(isAutoAspectToken)
4121
+ }
4122
+
4123
+ /**
4124
+ * The sizes `modelId` renders at `aspectRatio`, in the catalog's order: its
4125
+ * `resolutions`, narrowed where `resolutionsByAspectRatio` lists that ratio.
4126
+ * `undefined` for an unknown model or one with no size setting. What a menu
4127
+ * offers once a ratio is chosen.
4128
+ */
4129
+ export function resolutionsAtAspectRatio(modelId: string, aspectRatio: unknown): readonly string[] | undefined {
4130
+ const m = MODEL_CATALOG[modelId]
4131
+ const all = m?.resolutions
4132
+ if (!all || all.length === 0) return undefined
4133
+ const byRatio = m.resolutionsByAspectRatio
4134
+ const ratio = typeof aspectRatio === "string" ? aspectRatio.trim() : undefined
4135
+ // Own keys only: a ratio such as "constructor" must not read the prototype.
4136
+ const only = byRatio && ratio !== undefined && Object.prototype.hasOwnProperty.call(byRatio, ratio)
4137
+ ? byRatio[ratio]
4138
+ : undefined
4139
+ return only ? all.filter((r) => only.includes(r)) : all
4140
+ }
4141
+
4142
+ /**
4143
+ * The size `modelId` renders `resolution` at, at `aspectRatio`: the same size
4144
+ * where that ratio renders it (or the model limits no ratio), else the largest
4145
+ * size the ratio renders at or below it, else its smallest. A size the model
4146
+ * does not list comes back as it is: snapping the lever itself is
4147
+ * `normalizeModelInput`'s. A route that prices a run without that function
4148
+ * prices and sends the size this returns, so the two agree.
4149
+ */
4150
+ export function resolutionAtAspectRatio(
4151
+ modelId: string,
4152
+ aspectRatio: unknown,
4153
+ resolution: string | undefined,
4154
+ ): string | undefined {
4155
+ if (resolution === undefined) return undefined
4156
+ const all = MODEL_CATALOG[modelId]?.resolutions
4157
+ const offered = resolutionsAtAspectRatio(modelId, aspectRatio)
4158
+ if (!all || !offered || offered.length === 0 || offered.includes(resolution)) return resolution
4159
+ const at = all.indexOf(resolution)
4160
+ if (at < 0) return resolution
4161
+ const atOrBelow = offered.filter((r) => all.indexOf(r) <= at)
4162
+ return atOrBelow.length > 0 ? atOrBelow[atOrBelow.length - 1]! : offered[0]!
4041
4163
  }
4042
4164
 
4043
4165
  /**
@@ -4054,10 +4176,11 @@ export function autoAspectNeedsSourceImage(modelId: string | undefined, aspectRa
4054
4176
  *
4055
4177
  * Rules, mirroring the config panels' provider-change snap:
4056
4178
  * - Model has no such lever → drop the value (sending it 400s upstream).
4057
- * - "auto" on a model whose list lacks it, with a known `context.sourceImage`
4058
- * → the listed ratio nearest the source's shape (`nearestCatalogAspectRatio`).
4059
- * "auto" asks to keep the source photo's shape; the first listed ratio
4060
- * would reframe every source of another shape.
4179
+ * - "auto" on a model whose list lacks it, or whose own auto does not keep
4180
+ * the photo's shape (`autoAspectFromSourceImage`), with a known
4181
+ * `context.sourceImage` → the listed ratio nearest the source's shape
4182
+ * (`nearestCatalogAspectRatio`). "auto" asks to keep the source photo's
4183
+ * shape; the first listed ratio would reframe every source of another shape.
4061
4184
  * - Value outside the model's allow-list → snap to the model's default
4062
4185
  * (`defaultResolutionFor`) or the first valid option.
4063
4186
  * - Then apply cross-field constraints that only hold for certain models.
@@ -4126,11 +4249,14 @@ export function normalizeModelInput(
4126
4249
  : undefined
4127
4250
  if (sourceRatio !== undefined && input.aspectRatio !== undefined) {
4128
4251
  const { width, height } = context.sourceImage!
4252
+ const why = m.autoAspectFromSourceImage === true
4253
+ ? `${m.label}'s own "auto" does not keep the photo's shape`
4254
+ : `${m.label} has no "auto" aspect ratio`
4129
4255
  adjustments.push({
4130
4256
  field: "aspectRatio",
4131
4257
  from: input.aspectRatio,
4132
4258
  to: sourceRatio,
4133
- reason: `${m.label} has no "auto" aspect ratio — using "${sourceRatio}", the supported ratio closest to the source image's shape (${width}x${height}).`,
4259
+ reason: `${why} — using "${sourceRatio}", the supported ratio closest to the source image's shape (${width}x${height}).`,
4134
4260
  })
4135
4261
  out.aspectRatio = sourceRatio
4136
4262
  } else {
@@ -4149,6 +4275,21 @@ export function normalizeModelInput(
4149
4275
  ? input.duration
4150
4276
  : snap("duration", input.duration, m.durations)
4151
4277
 
4278
+ // A size the chosen ratio does not render (`resolutionsByAspectRatio`) moves
4279
+ // to the largest one it does at or below it. Before the background rules
4280
+ // below, which read the size this leaves, and before any price is built.
4281
+ const sized = resolutionAtAspectRatio(modelId, out.aspectRatio, out.resolution)
4282
+ if (out.resolution !== undefined && sized !== undefined && sized !== out.resolution) {
4283
+ const offered = resolutionsAtAspectRatio(modelId, out.aspectRatio) ?? [sized]
4284
+ adjustments.push({
4285
+ field: "resolution",
4286
+ from: out.resolution,
4287
+ to: sized,
4288
+ reason: `${m.label} only renders ${offered.join(" or ")} at the "${out.aspectRatio}" aspect ratio.`,
4289
+ })
4290
+ out.resolution = sized
4291
+ }
4292
+
4152
4293
  // Cross-field constraints — a pair that is individually valid but jointly
4153
4294
  // rejected upstream. GPT Image 2 (per docs.kie.ai): `auto` requires 1K, and
4154
4295
  // 1:1 cannot go to 4K. Applied last so it sees the already-snapped values.