@nodaro/shared 3.61.0 → 3.62.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 (254) hide show
  1. package/dist/{chunk-IVXSNW2B.cjs → chunk-2D5LQFV4.cjs} +18 -332
  2. package/dist/chunk-2D5LQFV4.cjs.map +1 -0
  3. package/dist/{chunk-XUJC6GHE.cjs → chunk-2HZGDZZN.cjs} +6 -6
  4. package/dist/{chunk-XUJC6GHE.cjs.map → chunk-2HZGDZZN.cjs.map} +1 -1
  5. package/dist/{chunk-43TGSZRJ.js → chunk-2QKF7M2Z.js} +3 -3
  6. package/dist/{chunk-43TGSZRJ.js.map → chunk-2QKF7M2Z.js.map} +1 -1
  7. package/dist/{chunk-7ARKVJTN.cjs → chunk-2W745U4A.cjs} +228 -355
  8. package/dist/chunk-2W745U4A.cjs.map +1 -0
  9. package/dist/{chunk-673E4KYC.js → chunk-3OYO3XCC.js} +70 -6
  10. package/dist/chunk-3OYO3XCC.js.map +1 -0
  11. package/dist/{chunk-FMXFHJWX.cjs → chunk-4ZEFP2FQ.cjs} +4 -4
  12. package/dist/{chunk-FMXFHJWX.cjs.map → chunk-4ZEFP2FQ.cjs.map} +1 -1
  13. package/dist/{chunk-A3FHTSLB.js → chunk-5YYN5X57.js} +302 -27
  14. package/dist/chunk-5YYN5X57.js.map +1 -0
  15. package/dist/{chunk-4KYLNTR7.cjs → chunk-6CSXMWL4.cjs} +4 -4
  16. package/dist/{chunk-4KYLNTR7.cjs.map → chunk-6CSXMWL4.cjs.map} +1 -1
  17. package/dist/{chunk-M3SXUUWC.cjs → chunk-6FQBKI2A.cjs} +4 -11
  18. package/dist/chunk-6FQBKI2A.cjs.map +1 -0
  19. package/dist/{chunk-G4XWVWRI.js → chunk-6G7NN4S4.js} +5 -4
  20. package/dist/chunk-6G7NN4S4.js.map +1 -0
  21. package/dist/{chunk-ZFJN23V4.cjs → chunk-A2PX5IRC.cjs} +4 -4
  22. package/dist/{chunk-ZFJN23V4.cjs.map → chunk-A2PX5IRC.cjs.map} +1 -1
  23. package/dist/{chunk-JHTT2V4A.cjs → chunk-AFYTX4AI.cjs} +52 -43
  24. package/dist/chunk-AFYTX4AI.cjs.map +1 -0
  25. package/dist/chunk-ALRXY4QH.cjs +13 -0
  26. package/dist/chunk-ALRXY4QH.cjs.map +1 -0
  27. package/dist/chunk-AOJ6B7K4.cjs +351 -0
  28. package/dist/chunk-AOJ6B7K4.cjs.map +1 -0
  29. package/dist/{chunk-ZDBPQBAA.js → chunk-C7POAYFE.js} +3 -3
  30. package/dist/{chunk-ZDBPQBAA.js.map → chunk-C7POAYFE.js.map} +1 -1
  31. package/dist/{chunk-B6BG3LV2.js → chunk-CC4V2B7S.js} +3 -3
  32. package/dist/{chunk-B6BG3LV2.js.map → chunk-CC4V2B7S.js.map} +1 -1
  33. package/dist/{chunk-XZKFZMRT.cjs → chunk-CIPPPT7E.cjs} +6 -6
  34. package/dist/{chunk-XZKFZMRT.cjs.map → chunk-CIPPPT7E.cjs.map} +1 -1
  35. package/dist/{chunk-6XVHYD5R.js → chunk-CLAKSLXF.js} +4 -9
  36. package/dist/chunk-CLAKSLXF.js.map +1 -0
  37. package/dist/chunk-CTANEPMY.js +61 -0
  38. package/dist/chunk-CTANEPMY.js.map +1 -0
  39. package/dist/{chunk-WGKAOUEQ.cjs → chunk-D34K455O.cjs} +3 -2
  40. package/dist/chunk-D34K455O.cjs.map +1 -0
  41. package/dist/chunk-E2HZTGYX.js +331 -0
  42. package/dist/chunk-E2HZTGYX.js.map +1 -0
  43. package/dist/{chunk-RQ4F3AJH.cjs → chunk-G3KVK7OU.cjs} +21 -21
  44. package/dist/{chunk-RQ4F3AJH.cjs.map → chunk-G3KVK7OU.cjs.map} +1 -1
  45. package/dist/chunk-G4U3HW6W.js +453 -0
  46. package/dist/chunk-G4U3HW6W.js.map +1 -0
  47. package/dist/{chunk-IRQ3SPX7.js → chunk-GSFB537T.js} +3 -3
  48. package/dist/{chunk-IRQ3SPX7.js.map → chunk-GSFB537T.js.map} +1 -1
  49. package/dist/chunk-HRY7KGAE.cjs +506 -0
  50. package/dist/chunk-HRY7KGAE.cjs.map +1 -0
  51. package/dist/{chunk-VOWJCUMR.js → chunk-I2RQB7VG.js} +3 -3
  52. package/dist/{chunk-VOWJCUMR.js.map → chunk-I2RQB7VG.js.map} +1 -1
  53. package/dist/chunk-IDTKF5EX.cjs +48 -0
  54. package/dist/chunk-IDTKF5EX.cjs.map +1 -0
  55. package/dist/{chunk-5XRRENHD.cjs → chunk-IWWVPR3W.cjs} +88 -11
  56. package/dist/chunk-IWWVPR3W.cjs.map +1 -0
  57. package/dist/{chunk-SCMTN57Y.js → chunk-JJNNM23P.js} +3 -3
  58. package/dist/{chunk-SCMTN57Y.js.map → chunk-JJNNM23P.js.map} +1 -1
  59. package/dist/{chunk-ZZGQRRN7.js → chunk-JZGZ26YB.js} +6 -306
  60. package/dist/chunk-JZGZ26YB.js.map +1 -0
  61. package/dist/{chunk-XROE3CAS.cjs → chunk-KHH54GRP.cjs} +120 -79
  62. package/dist/chunk-KHH54GRP.cjs.map +1 -0
  63. package/dist/{chunk-NJVOJXBS.cjs → chunk-KJSRPHJ2.cjs} +48 -47
  64. package/dist/chunk-KJSRPHJ2.cjs.map +1 -0
  65. package/dist/{chunk-FVVD6XY2.js → chunk-KL6GAYTT.js} +13 -4
  66. package/dist/chunk-KL6GAYTT.js.map +1 -0
  67. package/dist/{chunk-AFQFGZN7.cjs → chunk-KYMHFVAZ.cjs} +8 -6
  68. package/dist/chunk-KYMHFVAZ.cjs.map +1 -0
  69. package/dist/{chunk-F5YEMSNK.cjs → chunk-MYJQELFN.cjs} +320 -26
  70. package/dist/chunk-MYJQELFN.cjs.map +1 -0
  71. package/dist/chunk-N5HH46JF.cjs +68 -0
  72. package/dist/chunk-N5HH46JF.cjs.map +1 -0
  73. package/dist/{chunk-MQZRQ5LM.cjs → chunk-N7OUQK7E.cjs} +8 -8
  74. package/dist/{chunk-MQZRQ5LM.cjs.map → chunk-N7OUQK7E.cjs.map} +1 -1
  75. package/dist/{chunk-UARGJ5IZ.js → chunk-NGKKNSK6.js} +30 -7
  76. package/dist/chunk-NGKKNSK6.js.map +1 -0
  77. package/dist/{chunk-SWVGHAYO.js → chunk-O7RZRUMZ.js} +110 -74
  78. package/dist/chunk-O7RZRUMZ.js.map +1 -0
  79. package/dist/{chunk-C77F4ZTL.js → chunk-PTD6EDUU.js} +3 -3
  80. package/dist/{chunk-C77F4ZTL.js.map → chunk-PTD6EDUU.js.map} +1 -1
  81. package/dist/{chunk-ZNM2LW3D.cjs → chunk-QWYFHQYK.cjs} +78 -53
  82. package/dist/chunk-QWYFHQYK.cjs.map +1 -0
  83. package/dist/{chunk-VB2ARGQ6.js → chunk-RGNHHIMN.js} +3 -3
  84. package/dist/chunk-RGNHHIMN.js.map +1 -0
  85. package/dist/{chunk-MOMFX32D.js → chunk-S24ZBUB4.js} +194 -299
  86. package/dist/chunk-S24ZBUB4.js.map +1 -0
  87. package/dist/{chunk-EWS2VFO4.js → chunk-S5TMRJMX.js} +4 -4
  88. package/dist/{chunk-EWS2VFO4.js.map → chunk-S5TMRJMX.js.map} +1 -1
  89. package/dist/chunk-SMOO5FAH.js +10 -0
  90. package/dist/chunk-SMOO5FAH.js.map +1 -0
  91. package/dist/{chunk-RUHKBEFF.js → chunk-SYWR5G3T.js} +16 -7
  92. package/dist/chunk-SYWR5G3T.js.map +1 -0
  93. package/dist/{chunk-FQXRYPCX.cjs → chunk-TRVWMKNE.cjs} +337 -52
  94. package/dist/chunk-TRVWMKNE.cjs.map +1 -0
  95. package/dist/{chunk-LLOIAGFB.js → chunk-UDDVDQMF.js} +292 -35
  96. package/dist/chunk-UDDVDQMF.js.map +1 -0
  97. package/dist/{chunk-PONP5J5E.cjs → chunk-V24EPI5N.cjs} +13 -3
  98. package/dist/chunk-V24EPI5N.cjs.map +1 -0
  99. package/dist/{chunk-5I4T4QR5.cjs → chunk-VACPZPUA.cjs} +5 -5
  100. package/dist/{chunk-5I4T4QR5.cjs.map → chunk-VACPZPUA.cjs.map} +1 -1
  101. package/dist/{chunk-HGI2VKIV.js → chunk-Y6X7UJSD.js} +10 -9
  102. package/dist/chunk-Y6X7UJSD.js.map +1 -0
  103. package/dist/chunk-YCXRSWCQ.js +42 -0
  104. package/dist/chunk-YCXRSWCQ.js.map +1 -0
  105. package/dist/entries/apps.cjs +44 -44
  106. package/dist/entries/apps.js +9 -9
  107. package/dist/entries/credits.cjs +217 -152
  108. package/dist/entries/credits.d.cts +105 -3
  109. package/dist/entries/credits.d.ts +105 -3
  110. package/dist/entries/credits.js +13 -8
  111. package/dist/entries/entities.cjs +188 -143
  112. package/dist/entries/entities.d.cts +122 -1
  113. package/dist/entries/entities.d.ts +122 -1
  114. package/dist/entries/entities.js +2 -1
  115. package/dist/entries/llm-models.d.cts +2 -1
  116. package/dist/entries/llm-models.d.ts +2 -1
  117. package/dist/entries/media.cjs +92 -87
  118. package/dist/entries/media.d.cts +11 -1
  119. package/dist/entries/media.d.ts +11 -1
  120. package/dist/entries/media.js +3 -2
  121. package/dist/entries/model-catalog.cjs +195 -103
  122. package/dist/entries/model-catalog.d.cts +90 -4
  123. package/dist/entries/model-catalog.d.ts +90 -4
  124. package/dist/entries/model-catalog.js +5 -5
  125. package/dist/entries/models.cjs +407 -294
  126. package/dist/entries/models.d.cts +4 -3
  127. package/dist/entries/models.d.ts +4 -3
  128. package/dist/entries/models.js +6 -5
  129. package/dist/entries/nodes.cjs +241 -233
  130. package/dist/entries/nodes.d.cts +15 -2
  131. package/dist/entries/nodes.d.ts +15 -2
  132. package/dist/entries/nodes.js +10 -10
  133. package/dist/entries/pipeline.cjs +152 -152
  134. package/dist/entries/pipeline.d.cts +2 -1
  135. package/dist/entries/pipeline.d.ts +2 -1
  136. package/dist/entries/pipeline.js +3 -3
  137. package/dist/entries/ugc.cjs +71 -71
  138. package/dist/entries/ugc.js +4 -4
  139. package/dist/entries/video.cjs +308 -204
  140. package/dist/entries/video.d.cts +480 -98
  141. package/dist/entries/video.d.ts +480 -98
  142. package/dist/entries/video.js +8 -4
  143. package/dist/entries/workflow.cjs +102 -102
  144. package/dist/entries/workflow.d.cts +5 -4
  145. package/dist/entries/workflow.d.ts +5 -4
  146. package/dist/entries/workflow.js +2 -2
  147. package/dist/{gpt-image-2-6-BeZdT-pW.d.cts → gpt-image-2-6-jIRQBRag.d.cts} +6 -0
  148. package/dist/{gpt-image-2-6-BeZdT-pW.d.ts → gpt-image-2-6-jIRQBRag.d.ts} +6 -0
  149. package/dist/index.cjs +2309 -1886
  150. package/dist/index.d.cts +9 -9
  151. package/dist/index.d.ts +9 -9
  152. package/dist/index.js +26 -23
  153. package/dist/{model-catalog-BgSvskgY.d.cts → model-catalog-CCEcv08q.d.cts} +128 -14
  154. package/dist/{model-catalog-BgSvskgY.d.ts → model-catalog-CCEcv08q.d.ts} +128 -14
  155. package/dist/{model-constants-DHd9jwQ7.d.ts → model-constants-B88p6XR0.d.ts} +299 -19
  156. package/dist/{model-constants-DHd9jwQ7.d.cts → model-constants-Cf3zaITt.d.cts} +299 -19
  157. package/package.json +1 -1
  158. package/src/__tests__/extend-providers.test.ts +114 -0
  159. package/src/__tests__/fixtures/mask-composite-quote-parity.json +118 -0
  160. package/src/__tests__/fixtures/root-exports.baseline.json +68 -0
  161. package/src/__tests__/gpt-image-2-6-formats.test.ts +4 -1
  162. package/src/__tests__/grok-video-15-catalog.test.ts +189 -0
  163. package/src/__tests__/gvp-supported-providers.test.ts +5 -2
  164. package/src/__tests__/minimax-h3-image.test.ts +140 -0
  165. package/src/__tests__/model-makers.test.ts +49 -11
  166. package/src/__tests__/model-tree.test.ts +13 -0
  167. package/src/__tests__/retired-video-provider.test.ts +15 -5
  168. package/src/__tests__/seedance-25-catalog-modes.test.ts +1 -1
  169. package/src/__tests__/seedance-task-type.test.ts +178 -0
  170. package/src/__tests__/seedream-5-5.test.ts +117 -0
  171. package/src/__tests__/unit-contract-compose.test.ts +27 -1
  172. package/src/__tests__/unit-contracts.test.ts +20 -6
  173. package/src/__tests__/upscale-factors.test.ts +107 -0
  174. package/src/__tests__/video-character-refs.test.ts +20 -2
  175. package/src/__tests__/video-collapse-parity.test.ts +19 -0
  176. package/src/__tests__/video-overlay-geometry.test.ts +68 -0
  177. package/src/__tests__/video-overlay-layer-plan.test.ts +3 -4
  178. package/src/__tests__/video-overlay-layouts.test.ts +529 -0
  179. package/src/__tests__/video-overlay-pricing.test.ts +61 -0
  180. package/src/__tests__/video-overlay-validate.test.ts +128 -0
  181. package/src/__tests__/video-overlay-wired-kind.test.ts +207 -0
  182. package/src/__tests__/video-overlay.test.ts +280 -194
  183. package/src/__tests__/video-ref-limits.test.ts +2 -1
  184. package/src/__tests__/video-reference-only.test.ts +6 -2
  185. package/src/__tests__/video-start-frame-only.test.ts +98 -0
  186. package/src/__tests__/wired-character-names.test.ts +220 -0
  187. package/src/credit-estimators/index.ts +8 -0
  188. package/src/credit-estimators/video-overlay.ts +70 -0
  189. package/src/credit-identifiers.ts +94 -1
  190. package/src/entity-image-url.ts +21 -0
  191. package/src/entries/credits.ts +14 -0
  192. package/src/entries/entities.ts +14 -0
  193. package/src/entries/model-catalog.ts +35 -1
  194. package/src/entries/models.ts +34 -0
  195. package/src/entries/nodes.ts +2 -0
  196. package/src/entries/video.ts +6 -0
  197. package/src/generated/unit-contracts.ts +8 -1
  198. package/src/gpt-image-2-6.ts +6 -0
  199. package/src/input-image-pricing.ts +76 -0
  200. package/src/mask-composite.ts +11 -0
  201. package/src/minimax-h3-image.ts +61 -0
  202. package/src/model-catalog.ts +355 -37
  203. package/src/model-constants.ts +590 -32
  204. package/src/node-default-mappings.ts +12 -2
  205. package/src/node-execution-state.ts +4 -3
  206. package/src/producer-types.ts +23 -1
  207. package/src/seedance-task-type.ts +37 -0
  208. package/src/seedream-5-5.ts +45 -0
  209. package/src/unit-contract-compose.ts +4 -1
  210. package/src/upscale-factors.ts +111 -0
  211. package/src/video-character-refs.ts +7 -4
  212. package/src/video-overlay-geometry.ts +99 -0
  213. package/src/video-overlay-input.ts +25 -0
  214. package/src/video-overlay-layout-ids.ts +48 -0
  215. package/src/video-overlay-layouts.ts +315 -0
  216. package/src/video-overlay-validate.ts +223 -0
  217. package/src/video-overlay-video-layers.ts +304 -0
  218. package/src/video-overlay.ts +165 -297
  219. package/src/video-ui-defaults.ts +8 -6
  220. package/src/wired-character-names.ts +202 -0
  221. package/dist/chunk-5XRRENHD.cjs.map +0 -1
  222. package/dist/chunk-673E4KYC.js.map +0 -1
  223. package/dist/chunk-6XVHYD5R.js.map +0 -1
  224. package/dist/chunk-7ARKVJTN.cjs.map +0 -1
  225. package/dist/chunk-7WGKP3EU.js +0 -23
  226. package/dist/chunk-7WGKP3EU.js.map +0 -1
  227. package/dist/chunk-A3FHTSLB.js.map +0 -1
  228. package/dist/chunk-AFQFGZN7.cjs.map +0 -1
  229. package/dist/chunk-F5YEMSNK.cjs.map +0 -1
  230. package/dist/chunk-FQXRYPCX.cjs.map +0 -1
  231. package/dist/chunk-FVVD6XY2.js.map +0 -1
  232. package/dist/chunk-G4XWVWRI.js.map +0 -1
  233. package/dist/chunk-HGI2VKIV.js.map +0 -1
  234. package/dist/chunk-IVXSNW2B.cjs.map +0 -1
  235. package/dist/chunk-JHTT2V4A.cjs.map +0 -1
  236. package/dist/chunk-KHZAQGRP.js +0 -17
  237. package/dist/chunk-KHZAQGRP.js.map +0 -1
  238. package/dist/chunk-LLOIAGFB.js.map +0 -1
  239. package/dist/chunk-M3SXUUWC.cjs.map +0 -1
  240. package/dist/chunk-MOMFX32D.js.map +0 -1
  241. package/dist/chunk-NCOGGRRP.cjs +0 -27
  242. package/dist/chunk-NCOGGRRP.cjs.map +0 -1
  243. package/dist/chunk-NJVOJXBS.cjs.map +0 -1
  244. package/dist/chunk-PONP5J5E.cjs.map +0 -1
  245. package/dist/chunk-RUHKBEFF.js.map +0 -1
  246. package/dist/chunk-SWVGHAYO.js.map +0 -1
  247. package/dist/chunk-UARGJ5IZ.js.map +0 -1
  248. package/dist/chunk-VB2ARGQ6.js.map +0 -1
  249. package/dist/chunk-WGKAOUEQ.cjs.map +0 -1
  250. package/dist/chunk-XROE3CAS.cjs.map +0 -1
  251. package/dist/chunk-ZLDFPVVI.cjs +0 -19
  252. package/dist/chunk-ZLDFPVVI.cjs.map +0 -1
  253. package/dist/chunk-ZNM2LW3D.cjs.map +0 -1
  254. package/dist/chunk-ZZGQRRN7.js.map +0 -1
@@ -3,8 +3,9 @@
3
3
  * Single source of truth for model capability sets and variable pricing rules.
4
4
  */
5
5
  import { z } from "zod"
6
- import { MODEL_CATALOG } from "./model-catalog.js"
6
+ import { MODEL_CATALOG, isVideoAutoAspectToken, videoAutoAspectRunsAt, type ModelInputAdjustment } from "./model-catalog.js"
7
7
  import { isAutoVideoDuration, VIDEO_DURATION_AUTO } from "./video-duration-auto.js"
8
+ import { SEEDANCE_EDIT_REF_VIDEO_SEC, type DeclaredSeedanceTaskType } from "./seedance-task-type.js"
8
9
 
9
10
  /** Base USD value of 1 Nodaro credit. Used for cost→credit conversion. */
10
11
  export const CREDIT_BASE_USD = 0.002
@@ -56,14 +57,22 @@ export const IMAGE_ASPECT_RATIO_VALUES = [
56
57
  /** A ratio string the image routes accept (pre-snap vocabulary, not a per-model guarantee). */
57
58
  export type ImageAspectRatio = typeof IMAGE_ASPECT_RATIO_VALUES[number]
58
59
 
60
+ /**
61
+ * The K tiers of {@link IMAGE_RESOLUTION_VALUES}, smallest first. `1.5K` is
62
+ * Seedream 5.5's middle size; no other model lists it, and the catalog snap
63
+ * moves it to a size the chosen model does list.
64
+ */
65
+ export const IMAGE_K_RESOLUTION_VALUES = ["1K", "1.5K", "2K", "4K"] as const
66
+
59
67
  /**
60
68
  * The `resolution` vocabulary `/v1/generate-image` and `/v1/image-to-image`
61
- * accept: the K tiers (`1K`/`2K`/`4K`) and the Flux 2 megapixel tiers. Like
62
- * {@link IMAGE_ASPECT_RATIO_VALUES} it is a vocabulary bound, not a per-model
63
- * gate — the catalog snap corrects a value the chosen model does not declare.
64
- * One tuple for the route Zod enums and the SDK's `ImageResolution`.
69
+ * accept: the K tiers ({@link IMAGE_K_RESOLUTION_VALUES}) and the Flux 2
70
+ * megapixel tiers. Like {@link IMAGE_ASPECT_RATIO_VALUES} it is a vocabulary
71
+ * bound, not a per-model gate — the catalog snap corrects a value the chosen
72
+ * model does not declare. One tuple for the route Zod enums (the entity routes'
73
+ * too) and the SDK's `ImageResolution`.
65
74
  */
66
- export const IMAGE_RESOLUTION_VALUES = ["1K", "2K", "4K", "0.5 MP", "1 MP", "2 MP", "4 MP"] as const
75
+ export const IMAGE_RESOLUTION_VALUES = [...IMAGE_K_RESOLUTION_VALUES, "0.5 MP", "1 MP", "2 MP", "4 MP"] as const
67
76
  export type ImageResolution = typeof IMAGE_RESOLUTION_VALUES[number]
68
77
 
69
78
  /** The `quality` vocabulary of the same two routes (vocabulary bound; the catalog snap gates per model). */
@@ -174,7 +183,12 @@ export const MAX_IMAGE_PROMPT_CHARS_BY_PROVIDER: Record<string, number> = {
174
183
  // grok, qwen-i2i, seedream-5-pro, seedream-5-pro-i2i
175
184
  // (docs.kie.ai/market/seedream/5-pro-text-to-image + 5-pro-image-to-image),
176
185
  // seedream-5-flash, seedream-5-flash-i2i (both "4–5000 characters";
177
- // docs.kie.ai/market/seedream/5-flash-text-to-image + 5-flash-image-to-image).
186
+ // docs.kie.ai/market/seedream/5-flash-text-to-image + 5-flash-image-to-image),
187
+ // minimax-h3-image, minimax-h3-image-i2i (both "1–5000 characters";
188
+ // docs.kie.ai/market/minimax-h3/text-to-image + image-edit),
189
+ // seedream-5-5, seedream-5-5-i2i (both "5–5000 characters"; the minimum is
190
+ // MIN_IMAGE_PROMPT_CHARS_BY_PROVIDER below;
191
+ // docs.kie.ai/market/seedream/5-5-text-to-image + 5-5-image-to-image).
178
192
  // grok-i2i: doc states 390000 (78× its t2i sibling) — treated as a KIE schema
179
193
  // typo and left at the 5000 default per the sanity-cap decision.
180
194
  // UNVERIFIED (no limit stated in schema) → 5000 default: flux-kontext(-max)
@@ -189,6 +203,24 @@ export function getMaxImagePromptChars(provider: string | undefined): number {
189
203
  return (provider && MAX_IMAGE_PROMPT_CHARS_BY_PROVIDER[provider]) || IMAGE_PROMPT_MAX
190
204
  }
191
205
 
206
+ /**
207
+ * The fewest characters (after trimming) the prompt a provider is SENT may have,
208
+ * where its schema states a minimum it refuses below. Unlike the maximum, a
209
+ * short prompt cannot be fixed by the platform without writing words for the
210
+ * person, so a run whose final prompt is shorter is refused before anything is
211
+ * reserved (the image routes and the workflow run). Only a value quoted from
212
+ * the provider's schema is listed; a provider absent here has no minimum.
213
+ */
214
+ export const MIN_IMAGE_PROMPT_CHARS_BY_PROVIDER: Record<string, number> = {
215
+ "seedream-5-5": 5, // docs.kie.ai/market/seedream/5-5-text-to-image ("5–5000 characters")
216
+ "seedream-5-5-i2i": 5, // docs.kie.ai/market/seedream/5-5-image-to-image
217
+ }
218
+
219
+ /** The minimum prompt length for a provider ({@link MIN_IMAGE_PROMPT_CHARS_BY_PROVIDER}), 0 when it states none. */
220
+ export function getMinImagePromptChars(provider: string | undefined): number {
221
+ return (provider && MIN_IMAGE_PROMPT_CHARS_BY_PROVIDER[provider]) || 0
222
+ }
223
+
192
224
  /**
193
225
  * Video prompt/negative cap shared by routes + editor (MCP verbs already use
194
226
  * 8000). Providers allow far more (KIE seedance-2: 20k chars) — the old
@@ -293,7 +325,8 @@ export const MAX_VIDEO_PROMPT_CHARS_BY_PROVIDER: Record<string, number> = {
293
325
  "seedance-2": 20000,
294
326
  "seedance-2-fast": 20000,
295
327
  "seedance-2-mini": 20000,
296
- "seedance-2-extend": 20000,
328
+ "seedance-2-5-extend": 20000,
329
+ "seedance-2-0-extend": 20000,
297
330
  // Seedance 2.5 raises the prompt ceiling to 30000
298
331
  // (docs.kie.ai/market/bytedance/seedance-2-5).
299
332
  "seedance-2-5": 30000,
@@ -314,6 +347,9 @@ export const MAX_VIDEO_PROMPT_CHARS_BY_PROVIDER: Record<string, number> = {
314
347
  // (docs.kie.ai/market/kling/v4-reference-to-video and /v4-keyframe-to-video).
315
348
  "kling-4": 8000,
316
349
  "kling-4-keyframes": 8000,
350
+ // Kling 4.0 Flash — 8000 chars on both endpoints
351
+ // (docs.kie.ai/market/kling/v4-flash-reference-to-video and /v4-flash-keyframe-to-video).
352
+ "kling-4-flash": 8000,
317
353
  "bytedance-lite": 10000,
318
354
  "bytedance-pro": 10000,
319
355
  "bytedance-pro-fast": 10000,
@@ -600,6 +636,8 @@ export const MODELS_WITH_REFERENCE_IMAGE_SUPPORT = new Set([
600
636
  "seedream-5-lite",
601
637
  "seedream-5-pro",
602
638
  "seedream-5-flash",
639
+ "minimax-h3-image",
640
+ "seedream-5-5",
603
641
  "flux",
604
642
  "flux-flex",
605
643
  // Image editing / image-to-image (reference = source image)
@@ -624,11 +662,14 @@ export const MODELS_WITH_REFERENCE_IMAGE_SUPPORT = new Set([
624
662
  "seedream-5-lite-i2i",
625
663
  "seedream-5-pro-i2i",
626
664
  "seedream-5-flash-i2i",
665
+ "minimax-h3-image-i2i",
666
+ "seedream-5-5-i2i",
627
667
  "grok-i2i",
628
668
  // Upscale / background ops (source acts as the reference)
629
669
  "recraft-remove-bg",
630
670
  "recraft-upscale",
631
671
  "topaz-image-upscale",
672
+ "nodaro-image-upscale",
632
673
  // Wan 2.7 — accepts up to 9 optional ref images via input_urls (pure T2I when omitted)
633
674
  "wan-2.7",
634
675
  // Replicate "Open" (uncensored) image models
@@ -663,6 +704,11 @@ export const T2I_TO_I2I_VARIANT: Record<string, string> = {
663
704
  "seedream-5-lite": "seedream-5-lite-i2i",
664
705
  "seedream-5-pro": "seedream-5-pro-i2i",
665
706
  "seedream-5-flash": "seedream-5-flash-i2i",
707
+ // MiniMax H3 Image: its text-to-image endpoint takes no image at all.
708
+ "minimax-h3-image": "minimax-h3-image-i2i",
709
+ // Seedream 5.5's text-to-image endpoint takes no image at all: its edit
710
+ // endpoint is the only one that reads them (the provider swaps too).
711
+ "seedream-5-5": "seedream-5-5-i2i",
666
712
  "flux": "flux-pro-i2i",
667
713
  "flux-flex": "flux-i2i",
668
714
  }
@@ -703,6 +749,10 @@ export const REF_IMAGE_MAX_LIMITS: Record<string, number> = {
703
749
  "seedream-5-pro-i2i": 16,
704
750
  // Flash takes at most 10 `image_urls` (docs.kie.ai/market/seedream/5-flash-image-to-image) — not the family's 16.
705
751
  "seedream-5-flash-i2i": 10,
752
+ // 1 to 16 `image_urls` (docs.kie.ai/market/minimax-h3/image-edit).
753
+ "minimax-h3-image-i2i": 16,
754
+ // Seedream 5.5 takes 1–10 `image_urls` (docs.kie.ai/market/seedream/5-5-image-to-image).
755
+ "seedream-5-5-i2i": 10,
706
756
  // Single-source i2i (one input image)
707
757
  "flux-kontext": 1,
708
758
  "flux-kontext-max": 1,
@@ -714,6 +764,7 @@ export const REF_IMAGE_MAX_LIMITS: Record<string, number> = {
714
764
  "recraft-remove-bg": 1,
715
765
  "recraft-upscale": 1,
716
766
  "topaz-image-upscale": 1,
767
+ "nodaro-image-upscale": 1,
717
768
  // Replicate Open models — Klein takes an optional single ref; Kontext Multi
718
769
  // (multi-image-kontext-pro) is a two-image combiner (input_image_1/2 only);
719
770
  // Flux 2 Pro up to 4; Max up to 8.
@@ -761,14 +812,19 @@ export function imageReferenceLimit(provider: string | undefined): number {
761
812
  export const DEFAULT_REQUEST_IMAGE_LIMIT = 14
762
813
 
763
814
  /**
764
- * Models a request may give more input images than
815
+ * Models whose request may carry a different number of input images than
765
816
  * {@link DEFAULT_REQUEST_IMAGE_LIMIT}. Separate from
766
817
  * {@link REF_IMAGE_MAX_LIMITS}, the cap the canvas and the assembler honour: the
767
- * routes have their own, lower ceiling, and it rises per model only here.
818
+ * routes have their own ceiling, and it moves per model only here. GPT Image
819
+ * 2.6 takes more; a model priced per input image whose provider takes fewer
820
+ * (Seedream 5.5: 10) is held to its own, so a request is refused before it is
821
+ * reserved instead of failing at the provider.
768
822
  */
769
823
  const REQUEST_IMAGE_LIMITS: Record<string, number> = {
770
824
  "gpt-image-2-6-flare-i2i": 16,
771
825
  "gpt-image-2-6-sunburst-i2i": 16,
826
+ "minimax-h3-image-i2i": 16,
827
+ "seedream-5-5-i2i": 10,
772
828
  }
773
829
 
774
830
  /** The largest per-model limit: the outer bound of the routes' array schemas. */
@@ -806,12 +862,17 @@ export const VARIABLE_PRICING_MODELS: Record<string, "quality" | "resolution" |
806
862
  "seedream-5-lite-i2i": "quality",
807
863
  "seedream-5-pro": "quality",
808
864
  "seedream-5-pro-i2i": "quality",
865
+ "seedream-5-5": "resolution",
866
+ "seedream-5-5-i2i": "resolution",
809
867
  "topaz-image-upscale": "resolution",
810
868
  "ideogram-edit": "rendering-speed",
811
869
  "ideogram-remix": "rendering-speed",
812
870
  "ideogram-v3": "rendering-speed",
813
871
  "wan-2.7": "resolution",
814
872
  "wan-2.7-pro": "resolution",
873
+ // Also priced per reference image on an edit (`minimaxH3ImageCreditId`).
874
+ "minimax-h3-image": "resolution",
875
+ "minimax-h3-image-i2i": "resolution",
815
876
  }
816
877
 
817
878
 
@@ -873,6 +934,8 @@ export const IMAGE_GEN_PROVIDERS = [
873
934
  "seedream-5-lite",
874
935
  "seedream-5-pro",
875
936
  "seedream-5-flash",
937
+ "minimax-h3-image",
938
+ "seedream-5-5",
876
939
  "flux-flex",
877
940
  "flux-kontext",
878
941
  "flux-kontext-max",
@@ -911,6 +974,8 @@ export const IMAGE_I2I_PROVIDERS = [
911
974
  "seedream-5-lite-i2i",
912
975
  "seedream-5-pro-i2i",
913
976
  "seedream-5-flash-i2i",
977
+ "minimax-h3-image-i2i",
978
+ "seedream-5-5-i2i",
914
979
  "flux-kontext",
915
980
  "flux-kontext-max",
916
981
  // Replicate Open (uncensored) — multi-image Kontext via Replicate
@@ -942,6 +1007,8 @@ export const IMAGE_EDIT_PROVIDERS = [
942
1007
  "recraft-remove-bg",
943
1008
  "nano-banana-edit",
944
1009
  "topaz-image-upscale",
1010
+ // Nodaro Image Upscale: 1x to 8x, priced by the output's size.
1011
+ "nodaro-image-upscale",
945
1012
  // Grok Imagine 2 task-chained ops — a prior grok-2 generation's task_id (NOT
946
1013
  // an image URL); see the edit-image route for the taskId-vs-imageUrl
947
1014
  // branching. grok-2-edit: prompt edit of a prior grok-2 generation,
@@ -981,6 +1048,7 @@ export type ModifyImageProvider = typeof MODIFY_IMAGE_PROVIDERS[number]
981
1048
  export const UPSCALE_IMAGE_PROVIDERS = [
982
1049
  "recraft-upscale",
983
1050
  "topaz-image-upscale",
1051
+ "nodaro-image-upscale",
984
1052
  ] as const
985
1053
  export type UpscaleImageProvider = typeof UPSCALE_IMAGE_PROVIDERS[number]
986
1054
 
@@ -1034,9 +1102,12 @@ export const IMAGE_TO_VIDEO_PROVIDERS = [
1034
1102
  // listed here AND in TEXT_TO_VIDEO_PROVIDERS's main section (like wan-3).
1035
1103
  "kling-4",
1036
1104
  "kling-4-keyframes",
1105
+ // Kling 4.0 Flash — one id over KIE's two Flash endpoints (picked by what is
1106
+ // wired); both run with no image, so it is listed in both arrays too.
1107
+ "kling-4-flash",
1037
1108
  "ltx-2.3-pro",
1038
1109
  "ltx-2.3-fast",
1039
- // xAI Grok Imagine Video 1.5 — KIE i2v (image_urls required). Also listed in
1110
+ // xAI Grok Imagine Video 1.5 — KIE i2v (a start image required). Also listed in
1040
1111
  // TEXT_TO_VIDEO_PROVIDERS so it's offered everywhere in the unified node; the
1041
1112
  // t2v route guards no-image runs via VIDEO_PROVIDERS_REQUIRING_IMAGE.
1042
1113
  "grok-imagine-video-1.5",
@@ -1082,6 +1153,7 @@ export const TEXT_TO_VIDEO_PROVIDERS = [
1082
1153
  // no materials, keyframe-to-video with no frame).
1083
1154
  "kling-4",
1084
1155
  "kling-4-keyframes",
1156
+ "kling-4-flash",
1085
1157
  "ltx-2.3-pro",
1086
1158
  "ltx-2.3-fast",
1087
1159
  // ── i2v-only providers (image required) ──────────────────────────────────
@@ -1165,9 +1237,14 @@ export const VIDEO_MODE_ALIASES: readonly VideoModeAlias[] = [
1165
1237
  * - `seedance` (Seedance 1.5 Pro, KIE `bytedance/seedance-1.5-pro`): retired
1166
1238
  * upstream 2026-10-25 (KIE answers 410). Runs as Seedance 2 Mini, the
1167
1239
  * cheapest Seedance left (owner's decision 2026-10-25).
1240
+ * - `seedance-2-extend` (the one Seedance Extend Video provider, its model
1241
+ * chosen by the deployment): split 2026-11-11 into one provider per model.
1242
+ * Runs as `seedance-2-5-extend`, the Seedance 2.5 extend, and is priced on
1243
+ * its rows; `seedance-2-0-extend` is the Seedance 2.0 one.
1168
1244
  */
1169
1245
  export const RETIRED_VIDEO_PROVIDERS: Readonly<Record<string, string>> = {
1170
1246
  seedance: "seedance-2-mini",
1247
+ "seedance-2-extend": "seedance-2-5-extend",
1171
1248
  }
1172
1249
 
1173
1250
  /** A retired video model id becomes the id it runs as; any other value passes through unchanged. Own properties only. */
@@ -1256,12 +1333,15 @@ export function videoProviderReferenceSyntax(provider: string | undefined): Vide
1256
1333
  * Reference-capable video models whose start/end frames ride a channel of
1257
1334
  * their OWN (separate frame parameters next to the reference list), so a frame
1258
1335
  * never occupies a reference seat: `kling-3-omni` (Replicate `start_image` /
1259
- * `end_image`, no dispatch path today) and Kling 4.0 Keyframes (KIE
1260
- * `first_frame_url` / `last_frame_url` beside its in-between `keyframe_urls`).
1336
+ * `end_image`, no dispatch path today), Kling 4.0 Keyframes (KIE
1337
+ * `first_frame_url` / `last_frame_url` beside its in-between `keyframe_urls`)
1338
+ * and Grok Imagine Video 1.5 (KIE `first_frame_url` / `last_frame_url` /
1339
+ * `loop_url` beside its in-between `keyframes`).
1261
1340
  */
1262
1341
  export const VIDEO_PROVIDERS_WITH_SEPARATE_FRAME_CHANNEL: ReadonlySet<string> = new Set([
1263
1342
  "kling-3-omni",
1264
1343
  "kling-4-keyframes",
1344
+ "grok-imagine-video-1.5",
1265
1345
  ])
1266
1346
 
1267
1347
  /**
@@ -1374,6 +1454,17 @@ export const DEFAULT_VIDEO_TO_VIDEO_PROVIDER: VideoToVideoNodeProvider = "wan"
1374
1454
  */
1375
1455
  export const SEEDANCE_VIDEO_EDIT_SHAPE = { aspectRatio: "adaptive", duration: VIDEO_DURATION_AUTO } as const
1376
1456
 
1457
+ /**
1458
+ * The reference task type a purpose-built Seedance video edit requests (the
1459
+ * Video to Video route and node, MCP `modify_video`): the reference video is
1460
+ * the clip to edit, said outright instead of left to the prompt. A request, not
1461
+ * a promise: `resolveSeedanceTaskType` declares it only when the edit's
1462
+ * reference videos qualify, and otherwise the edit goes out undeclared, as
1463
+ * before. Kept apart from `SEEDANCE_VIDEO_EDIT_SHAPE`, whose exact value other
1464
+ * callers spread and pin.
1465
+ */
1466
+ export const SEEDANCE_VIDEO_EDIT_TASK_TYPE = "edit" as const satisfies DeclaredSeedanceTaskType
1467
+
1377
1468
  /** Face swap providers */
1378
1469
  export const FACE_SWAP_PROVIDERS = [
1379
1470
  "roop",
@@ -1396,10 +1487,27 @@ export const EXTEND_VIDEO_PROVIDERS = [
1396
1487
  "veo-extend",
1397
1488
  "runway-extend",
1398
1489
  "ltx-2.3-pro",
1399
- "seedance-2-extend",
1490
+ // Seedance extends ANY video, one provider per model: Seedance 2.5 (4–30 s
1491
+ // added) and Seedance 2.0 (4–15 s), each priced on its own rows
1492
+ // (`seedanceExtendCreditId`). The earlier single id `seedance-2-extend` is
1493
+ // retired (RETIRED_VIDEO_PROVIDERS) and runs as Seedance 2.5.
1494
+ "seedance-2-5-extend",
1495
+ "seedance-2-0-extend",
1400
1496
  ] as const
1401
1497
  export type ExtendVideoProvider = typeof EXTEND_VIDEO_PROVIDERS[number]
1402
1498
 
1499
+ /** The Extend Video providers that run on Seedance, one per model. */
1500
+ export type SeedanceExtendProvider = Extract<ExtendVideoProvider, "seedance-2-5-extend" | "seedance-2-0-extend">
1501
+ const SEEDANCE_EXTEND_PROVIDERS: readonly SeedanceExtendProvider[] = ["seedance-2-5-extend", "seedance-2-0-extend"]
1502
+
1503
+ /**
1504
+ * Whether a value is one of the Seedance Extend Video providers. A retired id
1505
+ * answers false: pass it through {@link canonicalVideoProvider} first.
1506
+ */
1507
+ export function isSeedanceExtendProvider(p: unknown): p is SeedanceExtendProvider {
1508
+ return typeof p === "string" && (SEEDANCE_EXTEND_PROVIDERS as readonly string[]).includes(p)
1509
+ }
1510
+
1403
1511
  /** Lip sync providers */
1404
1512
  export const LIP_SYNC_PROVIDERS = [
1405
1513
  "kling-avatar",
@@ -1859,6 +1967,8 @@ export const IMAGE_MASK_MODE: Record<ImageGenProvider, ImageMaskMode> = {
1859
1967
  "seedream-5-lite": "prompt",
1860
1968
  "seedream-5-pro": "prompt",
1861
1969
  "seedream-5-flash": "prompt",
1970
+ "minimax-h3-image": "prompt",
1971
+ "seedream-5-5": "prompt",
1862
1972
  "qwen": "prompt",
1863
1973
  "flux-kontext": "prompt",
1864
1974
  "flux-kontext-max": "prompt",
@@ -1890,6 +2000,7 @@ export const SEED_SUPPORT = new Set([
1890
2000
  "qwen", "qwen-i2i", "qwen-edit",
1891
2001
  "flux", "flux-flex", "flux-i2i", "flux-pro-i2i", "flux-kontext", "flux-kontext-max",
1892
2002
  "flux-2-klein", "kontext-multi",
2003
+ "minimax-h3-image", "minimax-h3-image-i2i",
1893
2004
  ])
1894
2005
 
1895
2006
  /** Ideogram models that support rendering_speed selection (TURBO/BALANCED/QUALITY) */
@@ -1914,7 +2025,6 @@ export const GUIDANCE_SCALE_SUPPORT: Record<string, { min: number; max: number;
1914
2025
  * TODO: Run verification script and update costs after confirming actual KIE pricing.
1915
2026
  */
1916
2027
  export const DURATION_PRICED_PROVIDERS = new Set([
1917
- "seedance-2-extend",
1918
2028
  "kling-3.0",
1919
2029
  "kling-3-omni",
1920
2030
  "kling",
@@ -1947,6 +2057,9 @@ export const DURATION_PRICED_PROVIDERS = new Set([
1947
2057
  // video rate on `kling-4`, see VIDEO_REF_RATE_PROVIDERS).
1948
2058
  "kling-4",
1949
2059
  "kling-4-keyframes",
2060
+ // Kling 4.0 Flash — per-second billing at 720p, the same rate on both
2061
+ // endpoints, plus a reference-video rate (VIDEO_REF_RATE_PROVIDERS).
2062
+ "kling-4-flash",
1950
2063
  // Gemini Omni Flash 1.2 — per-second billing at four resolution rates. The
1951
2064
  // only Omni SKU here: the per-clip SKUs price in their own branch of
1952
2065
  // buildVideoCreditModelIdentifier.
@@ -2141,6 +2254,110 @@ export function kling4KeyframeFrameCap(durationSec: number | string | undefined)
2141
2254
  return Math.min(10, d + 1)
2142
2255
  }
2143
2256
 
2257
+ /**
2258
+ * Kling 4.0 Flash — ONE Nodaro id over KIE's two Flash endpoints
2259
+ * (`kling-4.0/flash-reference-to-video` and `kling-4.0/flash-keyframe-to-video`),
2260
+ * picked by what is wired: a start frame alone runs on the keyframe endpoint,
2261
+ * everything else on the reference endpoint (backend `kling4.ts`).
2262
+ *
2263
+ * Deliberately NOT a member of {@link KLING_4_PROVIDERS}: that set's branches
2264
+ * carry Kling 4.0's 1080p tier, its `voices` array, its Keyframes frame table
2265
+ * and its materials rule, none of which Flash has. Every place Flash shares
2266
+ * with Kling 4.0 opts in explicitly ({@link isKling4RunnerProvider}).
2267
+ */
2268
+ export const KLING_4_FLASH_PROVIDER = "kling-4-flash"
2269
+
2270
+ export function isKling4FlashProvider(provider: string | undefined): provider is "kling-4-flash" {
2271
+ return provider === KLING_4_FLASH_PROVIDER
2272
+ }
2273
+
2274
+ /** The one resolution Kling 4.0 Flash renders (both schemas: `720p` only). */
2275
+ export const KLING_4_FLASH_RESOLUTION = "720p"
2276
+
2277
+ /**
2278
+ * Every id the bespoke Kling 4.0 runner serves — Kling 4.0, its Keyframes twin
2279
+ * and Flash. Read only where the three behave the same: the provider dispatch,
2280
+ * the image normalization, the editor's UI defaults (aspect `auto`, 720p, 5s).
2281
+ * Anything about resolutions, frames, voices or the materials budget asks
2282
+ * {@link isKling4Provider} or {@link isKling4FlashProvider} instead.
2283
+ */
2284
+ export function isKling4RunnerProvider(provider: string | undefined): provider is "kling-4" | "kling-4-keyframes" | "kling-4-flash" {
2285
+ return isKling4Provider(provider) || isKling4FlashProvider(provider)
2286
+ }
2287
+
2288
+ /**
2289
+ * Grok Imagine Video 1.5 — KIE `grok-imagine-video-1-5-preview`
2290
+ * (docs.kie.ai/market/grok-imagine/1-5-preview), built by the backend's bespoke
2291
+ * runner (`kie/grok-video-15.ts`). Image to video: the start frame is the exact
2292
+ * first frame, an end frame the exact last frame (one picture wired as both is
2293
+ * a seamless loop), and the Image References are up to
2294
+ * {@link GROK_VIDEO_15_MAX_MIDDLE_FRAMES} in-between frames, each placed at a
2295
+ * whole second inside the clip.
2296
+ */
2297
+ export const GROK_VIDEO_15_PROVIDER = "grok-imagine-video-1.5"
2298
+
2299
+ export function isGrokVideo15Provider(provider: string | undefined): provider is "grok-imagine-video-1.5" {
2300
+ return provider === GROK_VIDEO_15_PROVIDER
2301
+ }
2302
+
2303
+ /** Grok Imagine Video 1.5 resolution rendered when the param is omitted or
2304
+ * unknown — KIE's own default and the tier the bare credit identifier prices. */
2305
+ export const GROK_VIDEO_15_DEFAULT_RESOLUTION = "480p"
2306
+
2307
+ /**
2308
+ * SINGLE normalization for the Grok Imagine Video 1.5 resolution lever. The KIE
2309
+ * wire enum is lowercase (`480p` | `720p` | `1080p`), the same spelling as the
2310
+ * catalog and the credit identifiers; this folds case and collapses anything
2311
+ * else to {@link GROK_VIDEO_15_DEFAULT_RESOLUTION}. The runner sends what this
2312
+ * returns and the credit identifier bills what this returns.
2313
+ */
2314
+ export function normalizeGrokVideo15Resolution(resolution: string | undefined): "480p" | "720p" | "1080p" {
2315
+ const r = resolution?.trim().toLowerCase()
2316
+ return r === "720p" || r === "1080p" ? r : GROK_VIDEO_15_DEFAULT_RESOLUTION
2317
+ }
2318
+
2319
+ /** Most in-between frames Grok Imagine Video 1.5 takes (KIE `keyframes`). */
2320
+ export const GROK_VIDEO_15_MAX_MIDDLE_FRAMES = 4
2321
+
2322
+ /**
2323
+ * How many in-between frames a Grok Imagine Video 1.5 clip of `durationSec`
2324
+ * seconds carries. The node has no per-frame time, so the frames sit at whole
2325
+ * seconds strictly inside the clip, no two on the same second (decided
2326
+ * 2026-11-11): a D-second clip has D − 1 such seconds, and KIE takes at most
2327
+ * {@link GROK_VIDEO_15_MAX_MIDDLE_FRAMES}. Frames past this count are left out
2328
+ * (the runner logs it), never refused.
2329
+ */
2330
+ export function grokVideo15MiddleFrameSlots(durationSec: number | string | undefined): number {
2331
+ // The length the run renders: the catalog's default when unset, else the
2332
+ // nearest legal second — the same funnel the price reads.
2333
+ const d = pricedOutputDurationSec(GROK_VIDEO_15_PROVIDER, Number.isFinite(Number(durationSec)) ? durationSec : undefined)
2334
+ return Math.max(0, Math.min(GROK_VIDEO_15_MAX_MIDDLE_FRAMES, d - 1))
2335
+ }
2336
+
2337
+ /**
2338
+ * How many in-between frames (the Image References of a catalog `keyframes`
2339
+ * model) a run takes, given its length and which end frames are wired —
2340
+ * undefined for a model whose references are not frames. The editor's handle
2341
+ * cap and panel count read this, so the two cannot disagree.
2342
+ *
2343
+ * - Kling 4.0 Keyframes: the start and end frames share the clip's frame cap
2344
+ * ({@link kling4KeyframeFrameCap}), at most {@link KLING_4_MAX_MIDDLE_FRAMES}.
2345
+ * - Grok Imagine Video 1.5: {@link grokVideo15MiddleFrameSlots}; the start and
2346
+ * end frames ride their own fields and take no slot.
2347
+ */
2348
+ export function videoKeyframesMiddleCap(
2349
+ provider: string | undefined,
2350
+ durationSec: number | string | undefined,
2351
+ frames: { readonly hasStartFrame: boolean; readonly hasEndFrame: boolean },
2352
+ ): number | undefined {
2353
+ if (isGrokVideo15Provider(provider)) return grokVideo15MiddleFrameSlots(durationSec)
2354
+ if (provider === "kling-4-keyframes") {
2355
+ const ends = (frames.hasStartFrame ? 1 : 0) + (frames.hasEndFrame ? 1 : 0)
2356
+ return Math.max(0, Math.min(KLING_4_MAX_MIDDLE_FRAMES, kling4KeyframeFrameCap(durationSec) - ends))
2357
+ }
2358
+ return undefined
2359
+ }
2360
+
2144
2361
  /**
2145
2362
  * Google Gemini Omni family — the KIE "gemini-omni-video" market model and its
2146
2363
  * faster/cheaper "google/gemini-omni-flash-1-1" sibling. Both take the SAME
@@ -2509,8 +2726,8 @@ export const SEEDANCE_2_R2V_MIN_REF_VIDEO_SEC = 1.8
2509
2726
  export const SEEDANCE_2_CONTINUATION_REF_SEC = 2
2510
2727
 
2511
2728
  /**
2512
- * Trim-stitch parameters for the seedance-2-extend provider (spike-validated
2513
- * 2026-06-11):
2729
+ * Trim-stitch parameters for the Seedance Extend Video providers
2730
+ * (`seedance-2-5-extend`, `seedance-2-0-extend`; spike-validated 2026-06-11):
2514
2731
  * the model's extension output wobbles for its first ~3 frames and the source
2515
2732
  * tail's last ~4 frames lead into it; dropping both and butt-joining yields a
2516
2733
  * seam SMOOTHER than ordinary in-clip motion (PSNR 34.4dB vs 30.6dB
@@ -2675,6 +2892,15 @@ export const VIDEO_REF_LIMITS_BY_PROVIDER: Record<
2675
2892
  * (`videoCharacterRefProblem`).
2676
2893
  */
2677
2894
  materials?: number
2895
+ /**
2896
+ * Reference audio rides ON a character subject (its voice), not as a
2897
+ * material of its own: clip N belongs to wired character N, in the order
2898
+ * the characters arrive, and takes no seat in `materials`. A character with
2899
+ * fewer than 2 images is no subject and cannot carry a voice, so its clip
2900
+ * is dropped, as is a clip past the last character (Kling 4.0 Flash: KIE
2901
+ * `elements[].voice_url`, no standalone `voices`).
2902
+ */
2903
+ audioBindsToCharacters?: true
2678
2904
  } | undefined
2679
2905
  > = {
2680
2906
  // Seedance 2 — full multimodal caps.
@@ -2724,6 +2950,13 @@ export const VIDEO_REF_LIMITS_BY_PROVIDER: Record<
2724
2950
  // (`keyframe_urls`, max 8; the clip's duration lowers the cap, see
2725
2951
  // kling4KeyframeFrameCap). No reference videos or audio.
2726
2952
  "kling-4-keyframes": { images: KLING_4_MAX_MIDDLE_FRAMES },
2953
+ // Kling 4.0 Flash (reference endpoint) — 10 images, 5 videos, 7 subjects,
2954
+ // 15 in all (docs.kie.ai/market/kling/v4-flash-reference-to-video). No
2955
+ // standalone voices: reference audio clip N becomes wired character N's voice
2956
+ // (`voice_url`) when that character is a subject (2-4 images), so at most one
2957
+ // per character (7) and none takes a material seat. A wired start frame takes one of the 10 image slots when it
2958
+ // runs on this endpoint.
2959
+ "kling-4-flash": { images: 10, videos: 5, audio: 7, characters: 7, materials: 15, audioBindsToCharacters: true },
2727
2960
  "grok-i2v": { images: 7 }, // backend kie/models.ts maxRefImages: 7
2728
2961
  "happyhorse-ref2v": { images: 9 }, // backend kie/models.ts maxRefImages: 9
2729
2962
  // VEO 3.x — REFERENCE_2_VIDEO path caps refs at 3 (kie/video.ts slices to
@@ -2735,12 +2968,18 @@ export const VIDEO_REF_LIMITS_BY_PROVIDER: Record<
2735
2968
  // flips a Quality call to REFERENCE_2_VIDEO.
2736
2969
  "veo3.1": { images: 3 },
2737
2970
  "veo3_lite": { images: 3 },
2738
- // NOTE: wan-i2v / hailuo-2.3[-pro] / bytedance-pro[-fast] / grok-imagine-video-1.5
2739
- // are deliberately ABSENT. The 2026-06-28 audit (video-reference-features.test.ts)
2740
- // verified backend reference-forwarding paths and these i2v models have none —
2741
- // a single image_url start frame only. Advertising a ref cap would silently drop
2742
- // the user's references (the grok-imagine-video-1.5 bug). Add only with a
2743
- // verified provider path + the catalog `reference-image` feature.
2971
+ // Grok Imagine Video 1.5 — the Image References are its in-between frames
2972
+ // (KIE `keyframes`, max 4; the clip's length lowers the count, see
2973
+ // grokVideo15MiddleFrameSlots). They are frames only, never `image_urls`
2974
+ // references, and need the start frame. No reference videos or audio.
2975
+ "grok-imagine-video-1.5": { images: GROK_VIDEO_15_MAX_MIDDLE_FRAMES },
2976
+ // NOTE: wan-i2v / hailuo-2.3[-pro] / bytedance-pro[-fast] are deliberately
2977
+ // ABSENT. The 2026-06-28 audit (video-reference-features.test.ts) verified
2978
+ // backend reference-forwarding paths and these i2v models have none — a
2979
+ // single image_url start frame only. Advertising a ref cap would silently
2980
+ // drop the user's references (grok-imagine-video-1.5 had that bug before its
2981
+ // in-between frames were wired). Add only with a verified provider path + the
2982
+ // catalog `reference-image` feature.
2744
2983
  }
2745
2984
 
2746
2985
  /** Per-reference-video duration bounds, in seconds. */
@@ -2791,6 +3030,11 @@ export const VIDEO_REF_VIDEO_DURATION_LIMITS: Record<string, RefVideoDurationLim
2791
3030
  // while two 14 s ones were accepted (a production run with two 20 s
2792
3031
  // references had reached users as the generic "rejected these settings").
2793
3032
  "kling-4": { minSec: 2, maxSec: 30, maxTotalSec: 30 },
3033
+ // Kling 4.0 Flash — the reference videos' COMBINED length must be 2-20 s,
3034
+ // and KIE fails the task at completion otherwise ("video_1 duration must be
3035
+ // between 2 and 20 seconds, got 45", docs.kie.ai/market/kling/v4-flash-reference-to-video).
3036
+ // A 2 s floor per clip makes the combined floor hold too.
3037
+ "kling-4-flash": { minSec: 2, maxSec: 20, maxTotalSec: 20 },
2794
3038
  }
2795
3039
 
2796
3040
  /**
@@ -2857,11 +3101,9 @@ export const RESOLUTION_VIDEO_REF_PRICING = SEEDANCE_2_PROVIDERS
2857
3101
  * RESOLUTION_VIDEO_REF_PRICING (Seedance gen), which also adds `-ref` variants.
2858
3102
  */
2859
3103
  export const RESOLUTION_DURATION_PRICING: Record<string, readonly string[]> = {
2860
- // KIE supports only 480p/720p here; 480p is the default.
2861
- "grok-imagine-video-1.5": ["480p", "720p"],
2862
- // seedance-2-extend always uses a video ref, so pricing has no -ref
2863
- // dimension — duration tier + ":res" only (rates = seedance-2 -ref + stitch).
2864
- "seedance-2-extend": ["480p", "720p", "1080p"],
3104
+ // 480p is KIE's default and the bare id's tier; the runner and the credit
3105
+ // identifier both read normalizeGrokVideo15Resolution.
3106
+ "grok-imagine-video-1.5": ["480p", "720p", "1080p"],
2865
3107
  // HappyHorse 1.1 — per-second billing at two published resolution rates
2866
3108
  // (kie.ai/happyhorse-1-1: 22.5 cr/s @720p, 29 cr/s @1080p, uniform across
2867
3109
  // t2v/i2v/ref2v). 720p first = billing default; the KIE-side default is
@@ -2885,6 +3127,9 @@ export const RESOLUTION_DURATION_PRICING: Record<string, readonly string[]> = {
2885
3127
  // (VIDEO_REF_RATE_PROVIDERS).
2886
3128
  "kling-4": ["720p", "1080p"],
2887
3129
  "kling-4-keyframes": ["720p", "1080p"],
3130
+ // Kling 4.0 Flash — 720p only (both schemas), one rate on both endpoints,
3131
+ // plus a `-ref` rate for a run with a reference video (VIDEO_REF_RATE_PROVIDERS).
3132
+ "kling-4-flash": ["720p"],
2888
3133
  // Gemini Omni Flash 1.2 — per-second billing at four resolution rates.
2889
3134
  // Ascending; the billed default (720p) is declared in PRICING_DEFAULT_RESOLUTION.
2890
3135
  "gemini-omni-flash-1-2": ["360p", "720p", "1080p", "4k"],
@@ -2899,6 +3144,8 @@ export const RESOLUTION_DURATION_PRICING: Record<string, readonly string[]> = {
2899
3144
  */
2900
3145
  export const VIDEO_REF_RATE_PROVIDERS = new Set<string>([
2901
3146
  "kling-4",
3147
+ // Kling 4.0 Flash — the same rule at its own with-video rate.
3148
+ "kling-4-flash",
2902
3149
  ])
2903
3150
 
2904
3151
  /**
@@ -3020,6 +3267,142 @@ export function videoProviderFoldsLoneEndFrame(provider: string): boolean {
3020
3267
  return isSeedance2Provider(provider) || isMinimaxH3Provider(provider) || isWan3Provider(provider) || isGeminiOmniPerSecondProvider(provider)
3021
3268
  }
3022
3269
 
3270
+ /**
3271
+ * True when the provider takes an end frame ALONE, with no start frame, as the
3272
+ * clip's closing frame: Kling 4.0 Keyframes (KIE `last_frame_url` without
3273
+ * `first_frame_url`) and Gemini Omni Flash 1.2. Every other model meets the
3274
+ * platform's general rule for a lone end frame: the workflow run moves it into
3275
+ * the start slot, while the editor's Run and the image-to-video route refuse
3276
+ * the run for having no start frame.
3277
+ *
3278
+ * Read by the three places that apply that rule (the route's image gate, the
3279
+ * workflow payload builder's swap, the editor's start-frame guard) so they
3280
+ * cannot disagree. A `keyframes` model qualifies only when its endpoint runs
3281
+ * with no start frame at all (it has a text-to-video mode): Grok Imagine Video
3282
+ * 1.5 declares `keyframes` but needs its start image, so a lone end frame
3283
+ * keeps the general rule there.
3284
+ */
3285
+ export function videoProviderTakesLoneEndFrame(provider: string | undefined): boolean {
3286
+ if (!provider) return false
3287
+ if (isGeminiOmniPerSecondProvider(provider)) return true
3288
+ return MODEL_CATALOG[provider]?.features?.includes("keyframes") === true && !videoProviderRequiresImage(provider)
3289
+ }
3290
+
3291
+ /**
3292
+ * True when wired reference images can stand in for a missing start frame on
3293
+ * the image-to-video lane: the provider carries image references
3294
+ * ({@link VIDEO_REF_LIMITS_BY_PROVIDER}), unless they are a `keyframes`
3295
+ * model's in-between FRAMES and its endpoint cannot run from them alone (no
3296
+ * `reference-to-video`, {@link videoProviderRunsFromReferences}) — Grok Imagine
3297
+ * Video 1.5's in-between frames need its start frame. Read by the
3298
+ * image-to-video route's gate and the editor's start-frame guard; the workflow
3299
+ * run reaches the same answer through {@link resolveVideoModeForInputs}.
3300
+ */
3301
+ export function videoProviderRefsReplaceStartFrame(provider: string | undefined): boolean {
3302
+ if (!provider || (VIDEO_REF_LIMITS_BY_PROVIDER[provider]?.images ?? 0) <= 0) return false
3303
+ const keyframes = MODEL_CATALOG[provider]?.features?.includes("keyframes") === true
3304
+ return !keyframes || videoProviderRunsFromReferences(provider)
3305
+ }
3306
+
3307
+ /** The error code of a {@link videoStartFrameOnlyProblem} refusal. */
3308
+ export const VIDEO_START_FRAME_ONLY_CODE = "start_frame_only_resolution" as const
3309
+
3310
+ /**
3311
+ * The resolution tier a run of `provider` renders for `resolution` when that
3312
+ * tier takes a start frame only (the catalog's `startFrameOnlyResolutions`),
3313
+ * else undefined. Case-folded, as the runners send it (`"1080P"` is 1080p).
3314
+ */
3315
+ export function videoStartFrameOnlyResolution(provider: string | undefined, resolution: string | undefined): string | undefined {
3316
+ const tiers = provider ? MODEL_CATALOG[provider]?.startFrameOnlyResolutions : undefined
3317
+ const r = resolution?.trim().toLowerCase()
3318
+ if (!tiers?.length || !r) return undefined
3319
+ return tiers.find((t) => t.toLowerCase() === r)
3320
+ }
3321
+
3322
+ /** The highest listed resolution of `provider` that takes every frame — the one to offer instead. */
3323
+ function videoFramesResolutionFallback(provider: string): string | undefined {
3324
+ const entry = MODEL_CATALOG[provider]
3325
+ const restricted = new Set((entry?.startFrameOnlyResolutions ?? []).map((t) => t.toLowerCase()))
3326
+ const open = (entry?.resolutions ?? []).filter((r) => !restricted.has(r.toLowerCase()))
3327
+ const height = (r: string): number => Number.parseInt(r, 10) || 0
3328
+ return [...open].sort((a, b) => height(b) - height(a))[0]
3329
+ }
3330
+
3331
+ /**
3332
+ * The sentence for a start-frame-only refusal: which tier takes a start frame
3333
+ * only, and the two ways out (the highest tier that takes every frame, or
3334
+ * removing the extra frames). `nothingCharged` adds that nothing was charged —
3335
+ * for a refusal of a run (the API, the workflow run, the editor's Run), never
3336
+ * for the editor's note beside the setting.
3337
+ */
3338
+ export function videoStartFrameOnlyMessage(
3339
+ provider: string,
3340
+ resolution: string,
3341
+ opts: { readonly nothingCharged?: boolean } = {},
3342
+ ): string {
3343
+ const label = MODEL_CATALOG[provider]?.label ?? provider
3344
+ const fallback = videoFramesResolutionFallback(provider)
3345
+ const choose = fallback ? `Choose ${fallback}, or remove` : "Remove"
3346
+ const sentence =
3347
+ `${label} takes a start frame only at ${resolution}: no end frame, loop or in-between frames. ` +
3348
+ `${choose} the end frame and the in-between frames.`
3349
+ return opts.nothingCharged ? `${sentence} Nothing was charged.` : sentence
3350
+ }
3351
+
3352
+ /** A {@link videoStartFrameOnlyProblem} refusal. */
3353
+ export interface VideoStartFrameOnlyProblem {
3354
+ readonly code: typeof VIDEO_START_FRAME_ONLY_CODE
3355
+ /** The sentence, in English — the API's `error.message`. */
3356
+ readonly message: string
3357
+ /** The tier that takes a start frame only (catalog spelling). */
3358
+ readonly resolution: string
3359
+ /** The highest tier that takes every frame, when the model has one. */
3360
+ readonly fallbackResolution?: string
3361
+ }
3362
+
3363
+ /**
3364
+ * THE rule for a resolution that takes a start frame only (decided 2026-11-12:
3365
+ * refuse up front). Given the resolution a run renders and the frames it would
3366
+ * send BESIDE its start frame, is the combination refused, and with what
3367
+ * sentence? Undefined when it runs.
3368
+ *
3369
+ * - `hasEndFrame`: an end frame is wired. The same picture as the start frame
3370
+ * (a loop) counts too — the provider refuses a loop at such a tier as well.
3371
+ * - `inBetweenFrameCount`: the in-between frames wired (a `keyframes` model's
3372
+ * image references), BEFORE the clip's cap. The cap is applied here through
3373
+ * {@link videoKeyframesMiddleCap} — the same function the provider runner
3374
+ * truncates with — so a request whose extra frames are all dropped (a
3375
+ * 1-second Grok Imagine Video 1.5 clip has no in-between second) is a
3376
+ * start-only request and runs.
3377
+ *
3378
+ * Judged only on a run that has a start frame: a run without one is refused by
3379
+ * the image-required rule first, so every caller runs this after that gate.
3380
+ * Read by `/v1/generate-video`, the workflow payload builder and the editor's
3381
+ * Run; the editor's note and resolution menus read it too.
3382
+ */
3383
+ export function videoStartFrameOnlyProblem(
3384
+ provider: string | undefined,
3385
+ args: {
3386
+ readonly resolution: string | undefined
3387
+ readonly durationSec?: number | string
3388
+ readonly hasEndFrame: boolean
3389
+ readonly inBetweenFrameCount: number
3390
+ readonly nothingCharged?: boolean
3391
+ },
3392
+ ): VideoStartFrameOnlyProblem | undefined {
3393
+ const tier = videoStartFrameOnlyResolution(provider, args.resolution)
3394
+ if (!provider || !tier) return undefined
3395
+ const cap = videoKeyframesMiddleCap(provider, args.durationSec, { hasStartFrame: true, hasEndFrame: args.hasEndFrame })
3396
+ const inBetween = Math.max(0, cap === undefined ? args.inBetweenFrameCount : Math.min(cap, args.inBetweenFrameCount))
3397
+ if (!args.hasEndFrame && inBetween === 0) return undefined
3398
+ return {
3399
+ code: VIDEO_START_FRAME_ONLY_CODE,
3400
+ message: videoStartFrameOnlyMessage(provider, tier, { nothingCharged: args.nothingCharged }),
3401
+ resolution: tier,
3402
+ fallbackResolution: videoFramesResolutionFallback(provider),
3403
+ }
3404
+ }
3405
+
3023
3406
  /**
3024
3407
  * Video models where enabling audio/sound incurs an additional cost.
3025
3408
  * The audio addon is expressed as a separate composite identifier suffix.
@@ -3148,6 +3531,8 @@ export const VIDEO_AUDIO_CAPABILITY: Record<string, VideoAudioCapability> = {
3148
3531
  // dialogue; priced into the per-second rate.
3149
3532
  "kling-4": { mode: "ambient", alwaysOn: true, defaultOn: true },
3150
3533
  "kling-4-keyframes": { mode: "ambient", alwaysOn: true, defaultOn: true },
3534
+ // Kling 4.0 Flash — the same: native audio on both endpoints, no lever.
3535
+ "kling-4-flash": { mode: "ambient", alwaysOn: true, defaultOn: true },
3151
3536
  // Gemini Omni Flash 1.2 — native audio with no on/off input in its schema.
3152
3537
  "gemini-omni-flash-1-2": { mode: "ambient", alwaysOn: true },
3153
3538
  // Gemini Omni (both SKUs — the pro `gemini-omni-video` and the faster
@@ -3307,7 +3692,8 @@ export const VIDEO_VARIABLE_PRICING: Record<string, "duration" | "duration+audio
3307
3692
  // appended for the cheaper tier); ref-video input seconds + extra input
3308
3693
  // images are billed via the dedicated compute hook, not the identifier.
3309
3694
  "minimax-h3": "duration+resolution",
3310
- // Grok Imagine Video 1.5 — per-second billing split 480p/720p (no video-ref dimension).
3695
+ // Grok Imagine Video 1.5 — per-second billing at 480p / 720p / 1080p (no
3696
+ // video-ref dimension, no per-image or per-frame part).
3311
3697
  "grok-imagine-video-1.5": "duration+resolution",
3312
3698
  // Wan 3.0 family — per-second billing at three resolution rates (no video-ref
3313
3699
  // dimension: reference runs bill output seconds only). No gemini-omni-flash
@@ -3321,6 +3707,8 @@ export const VIDEO_VARIABLE_PRICING: Record<string, "duration" | "duration+audio
3321
3707
  // reference-video rate.
3322
3708
  "kling-4": "duration+resolution+ref",
3323
3709
  "kling-4-keyframes": "duration+resolution",
3710
+ // Kling 4.0 Flash — per-second at 720p, plus the reference-video rate.
3711
+ "kling-4-flash": "duration+resolution+ref",
3324
3712
  // Gemini Omni Flash 1.2 — per-second at four resolution rates; a video edit
3325
3713
  // bills the same rates over the source clip.
3326
3714
  "gemini-omni-flash-1-2": "duration+resolution",
@@ -3403,6 +3791,156 @@ export function supportsAutoVideoDuration(provider: string | undefined): boolean
3403
3791
  return !!provider && MODEL_CATALOG[provider]?.autoDuration === true
3404
3792
  }
3405
3793
 
3794
+ /** Models that accept a reference task type declaration — a catalog capability
3795
+ * (`MODEL_CATALOG[id].referenceTaskTypes`, see `SEEDANCE_REFERENCE_TASK_TYPES`). */
3796
+ export function supportsReferenceTaskType(provider: string | undefined): boolean {
3797
+ return !!provider && (MODEL_CATALOG[provider]?.referenceTaskTypes?.length ?? 0) > 0
3798
+ }
3799
+
3800
+ /** What a request knows that decides its reference task type. */
3801
+ export interface SeedanceTaskTypeFacts {
3802
+ provider: string | undefined
3803
+ /** The value the request carries, unvalidated: anything but a declared value is Auto. */
3804
+ requested: unknown
3805
+ draft: boolean
3806
+ /** Reference images only: a start or end frame is not counted. */
3807
+ referenceImageCount: number
3808
+ referenceAudioCount: number
3809
+ /** One entry per reference video; `undefined` = its length could not be measured. */
3810
+ referenceVideoSec: ReadonlyArray<number | undefined>
3811
+ aspectRatio: string | undefined
3812
+ duration: number | undefined
3813
+ }
3814
+
3815
+ /** The declaration a request sends (if any), and the ratio and length it runs at. */
3816
+ export interface SeedanceTaskTypeResolution {
3817
+ /** `undefined`: nothing is declared and the provider guesses from the prompt. */
3818
+ taskType: DeclaredSeedanceTaskType | undefined
3819
+ aspectRatio: string | undefined
3820
+ duration: number | undefined
3821
+ /** Each change made to the ratio or length, for disclosure. Empty when nothing changed. */
3822
+ adjustments: ModelInputAdjustment[]
3823
+ }
3824
+
3825
+ /** The aspect ratio an `extend` runs at: the reference video's own (an `edit`
3826
+ * takes its whole shape from `SEEDANCE_VIDEO_EDIT_SHAPE`). */
3827
+ const SEEDANCE_EXTEND_ASPECT = "adaptive"
3828
+
3829
+ /**
3830
+ * `requested` when the model's catalog `referenceTaskTypes` lists it (strict
3831
+ * match), else `undefined`. The one membership test: the resolver below and the
3832
+ * provider adapter that writes the value both ask it.
3833
+ */
3834
+ export function listedSeedanceTaskType(provider: string | undefined, requested: unknown): DeclaredSeedanceTaskType | undefined {
3835
+ return provider ? MODEL_CATALOG[provider]?.referenceTaskTypes?.find((t) => t === requested) : undefined
3836
+ }
3837
+
3838
+ /** How many of each kind of reference media a request carries. A start or end frame is not reference media. */
3839
+ export interface SeedanceReferenceMediaCount {
3840
+ imageCount: number
3841
+ videoCount: number
3842
+ audioCount: number
3843
+ }
3844
+
3845
+ /**
3846
+ * Whether a request's reference media is what the declared type needs:
3847
+ * `reference` takes any reference media; `edit` and `extend` need a reference
3848
+ * video, since both act on one. The one media rule: the resolver below asks it
3849
+ * of the request, and the provider adapter of the body as it will be sent.
3850
+ */
3851
+ export function seedanceTaskTypeFitsMedia(type: DeclaredSeedanceTaskType, media: SeedanceReferenceMediaCount): boolean {
3852
+ return type === "reference" ? media.imageCount + media.videoCount + media.audioCount > 0 : media.videoCount > 0
3853
+ }
3854
+
3855
+ function editReferenceVideosFit(referenceVideoSec: ReadonlyArray<number | undefined>): boolean {
3856
+ const { min, max } = SEEDANCE_EDIT_REF_VIDEO_SEC
3857
+ return referenceVideoSec.every((sec) => typeof sec === "number" && sec >= min && sec <= max)
3858
+ }
3859
+
3860
+ /**
3861
+ * The ONE place that decides whether a request declares a reference task type,
3862
+ * and the aspect ratio and length that declaration forces.
3863
+ *
3864
+ * Declared only when every condition holds; otherwise the result is the input
3865
+ * unchanged (no declaration, ratio and length as given, nothing reported):
3866
+ * - the request asks for a value the model's catalog `referenceTaskTypes`
3867
+ * LISTS, matched exactly. The list is what is honoured: a model that lists
3868
+ * nothing, a value it does not list (`auto`, a wrong case, a number) and a
3869
+ * model that lists only some values are all Auto;
3870
+ * - the run is not a draft;
3871
+ * - it has the reference media the type needs
3872
+ * ({@link seedanceTaskTypeFitsMedia}): `edit` and `extend` need a
3873
+ * reference video;
3874
+ * - for `edit`, every reference video is measured and between
3875
+ * `SEEDANCE_EDIT_REF_VIDEO_SEC.min` and `.max` seconds inclusive.
3876
+ *
3877
+ * What a declaration forces:
3878
+ * - `reference` — nothing;
3879
+ * - `edit` — the edit shape, `SEEDANCE_VIDEO_EDIT_SHAPE` (`"adaptive"`
3880
+ * and Auto length): the output takes the video's own shape
3881
+ * and length;
3882
+ * - `extend` — `"adaptive"`; a fixed length is kept, and Auto or no length
3883
+ * becomes the model's catalog `defaultDuration`.
3884
+ *
3885
+ * Each value it changes is reported as one adjustment; a value it fills where
3886
+ * the request had none is not a correction and reports nothing, and neither is
3887
+ * a ratio that already runs at the forced one (`"Auto"` with a reference video
3888
+ * runs at `"adaptive"`). Pure.
3889
+ */
3890
+ export function resolveSeedanceTaskType(facts: SeedanceTaskTypeFacts): SeedanceTaskTypeResolution {
3891
+ const { provider, aspectRatio, duration, referenceVideoSec } = facts
3892
+ const unchanged: SeedanceTaskTypeResolution = { taskType: undefined, aspectRatio, duration, adjustments: [] }
3893
+ const taskType = listedSeedanceTaskType(provider, facts.requested)
3894
+ if (!taskType || !provider || facts.draft) return unchanged
3895
+ const media = {
3896
+ imageCount: facts.referenceImageCount,
3897
+ videoCount: referenceVideoSec.length,
3898
+ audioCount: facts.referenceAudioCount,
3899
+ }
3900
+ if (!seedanceTaskTypeFitsMedia(taskType, media)) return unchanged
3901
+ if (taskType === "edit" && !editReferenceVideosFit(referenceVideoSec)) return unchanged
3902
+ if (taskType === "reference") return { ...unchanged, taskType }
3903
+
3904
+ const verb = taskType === "edit" ? "Edit" : "Extend"
3905
+ const nextAspect = taskType === "edit" ? SEEDANCE_VIDEO_EDIT_SHAPE.aspectRatio : SEEDANCE_EXTEND_ASPECT
3906
+ const adjustments: ModelInputAdjustment[] = []
3907
+ const askedAspect = typeof aspectRatio === "string" ? aspectRatio.trim() : ""
3908
+ // A ratio that already runs at the forced one is not replaced: the forced
3909
+ // value itself, or the "Auto" token, which a request with a reference video
3910
+ // runs at "adaptive" (`videoAutoAspectRunsAt`, the adapter's own rule).
3911
+ const runsAtForced = askedAspect.toLowerCase() === nextAspect
3912
+ || (isVideoAutoAspectToken(askedAspect) && videoAutoAspectRunsAt(provider, media.videoCount > 0) === nextAspect)
3913
+ if (askedAspect !== "" && !runsAtForced) {
3914
+ adjustments.push({
3915
+ field: "aspectRatio", from: askedAspect, to: nextAspect,
3916
+ reason: `${verb} keeps the video's own shape — using "${nextAspect}" instead of "${askedAspect}".`,
3917
+ })
3918
+ }
3919
+
3920
+ let nextDuration: number
3921
+ if (taskType === "edit") {
3922
+ nextDuration = SEEDANCE_VIDEO_EDIT_SHAPE.duration
3923
+ if (duration !== undefined && !isAutoVideoDuration(duration)) {
3924
+ adjustments.push({
3925
+ field: "duration", from: duration, to: nextDuration,
3926
+ reason: `Edit keeps the video's own length — using Auto instead of ${duration}s.`,
3927
+ })
3928
+ }
3929
+ } else if (duration === undefined || isAutoVideoDuration(duration)) {
3930
+ nextDuration = videoDefaultDurationSec(provider)
3931
+ if (duration !== undefined) {
3932
+ adjustments.push({
3933
+ field: "duration", from: duration, to: nextDuration,
3934
+ reason: `Extend needs a set length — using ${nextDuration}s, the model's default, instead of Auto.`,
3935
+ })
3936
+ }
3937
+ } else {
3938
+ nextDuration = duration
3939
+ }
3940
+
3941
+ return { taskType, aspectRatio: nextAspect, duration: nextDuration, adjustments }
3942
+ }
3943
+
3406
3944
  /** The longest clip a duration-tiered provider can render (its top priced tier). */
3407
3945
  export function maxVideoDurationSec(provider: string): number | undefined {
3408
3946
  const tiers = VIDEO_DURATION_TIERS[provider]
@@ -3443,9 +3981,17 @@ export const PRICING_DEFAULT_RESOLUTION: Record<string, string> = {
3443
3981
  // normalizeKling4Resolution pins the same tier for anything unknown.
3444
3982
  "kling-4": "720p",
3445
3983
  "kling-4-keyframes": "720p",
3984
+ // Kling 4.0 Flash — 720p is its only tier.
3985
+ "kling-4-flash": "720p",
3446
3986
  // Gemini Omni Flash 1.2 — KIE renders 720p when `resolution` is omitted, and
3447
3987
  // the runner sends 720p for anything off its list.
3448
3988
  "gemini-omni-flash-1-2": "720p",
3989
+ // Grok Imagine Video 1.5 — KIE renders 480p when `resolution` is omitted, and
3990
+ // normalizeGrokVideo15Resolution pins the same tier for anything unknown. It
3991
+ // is also the cheapest tier, so the bill does not move; declared so a run
3992
+ // that names no resolution is judged at 480p by the free-tier check (decided
3993
+ // 2026-11-11) and is sent 480p by pricedVideoSelection.
3994
+ "grok-imagine-video-1.5": "480p",
3449
3995
  }
3450
3996
 
3451
3997
  /** Gemini Omni Flash 1.2 per-second tiers — one per allowed duration (3–15s). */
@@ -3507,6 +4053,12 @@ const KLING_4_DURATION_TIERS: Array<{ maxSeconds: number; suffix: string }> = Ar
3507
4053
  (_, i) => ({ maxSeconds: i + 3, suffix: `${i + 3}s` }),
3508
4054
  )
3509
4055
 
4056
+ /** Kling 4.0 Flash per-second tiers — one per allowed duration (3-20s). */
4057
+ const KLING_4_FLASH_DURATION_TIERS: Array<{ maxSeconds: number; suffix: string }> = Array.from(
4058
+ { length: 18 },
4059
+ (_, i) => ({ maxSeconds: i + 3, suffix: `${i + 3}s` }),
4060
+ )
4061
+
3510
4062
  /**
3511
4063
  * Duration tier breakpoints for variable-priced video models.
3512
4064
  * Maps provider → array of { maxSeconds, suffix } in ascending order.
@@ -3569,6 +4121,10 @@ export const VIDEO_DURATION_TIERS: Record<string, Array<{ maxSeconds: number; su
3569
4121
  { maxSeconds: 12, suffix: "12s" },
3570
4122
  { maxSeconds: 15, suffix: "15s" },
3571
4123
  ],
4124
+ // The length tiers of the earlier Seedance Extend rows
4125
+ // (`seedance-2-extend:<tier>:<res>`). No extend is priced on them any more —
4126
+ // each Seedance extend provider has a row per second (`seedanceExtendCreditId`)
4127
+ // — but the rows stay, and so do their tiers.
3572
4128
  "seedance-2-extend": [
3573
4129
  { maxSeconds: 4, suffix: "4s" },
3574
4130
  { maxSeconds: 8, suffix: "8s" },
@@ -3587,6 +4143,7 @@ export const VIDEO_DURATION_TIERS: Record<string, Array<{ maxSeconds: number; su
3587
4143
  "vidu-q4": VIDU_Q4_DURATION_TIERS,
3588
4144
  "kling-4": KLING_4_DURATION_TIERS,
3589
4145
  "kling-4-keyframes": KLING_4_DURATION_TIERS,
4146
+ "kling-4-flash": KLING_4_FLASH_DURATION_TIERS,
3590
4147
  "gemini-omni-flash-1-2": GEMINI_OMNI_12_DURATION_TIERS,
3591
4148
  // MiniMax Hailuo 3 — true per-second billing (KIE 36.5 cr/s @2K, 22.5 cr/s
3592
4149
  // @768P). One tier per allowed second (4-15s) so the composite identifier
@@ -3606,9 +4163,10 @@ export const VIDEO_DURATION_TIERS: Record<string, Array<{ maxSeconds: number; su
3606
4163
  { maxSeconds: 14, suffix: "14s" },
3607
4164
  { maxSeconds: 15, suffix: "15s" },
3608
4165
  ],
3609
- // Grok Imagine Video 1.5 — true per-second billing (KIE 14.5 cr/s @480p, 25 cr/s
3610
- // @720p, +2 cr/image). One tier per allowed second (1–15s) so the composite
3611
- // identifier maps 1:1 to the seeded price — no rounding/overcharge for any on-menu value.
4166
+ // Grok Imagine Video 1.5 — true per-second billing by resolution, with no
4167
+ // per-image or per-frame part. One tier per allowed second (1–15s) so the
4168
+ // composite identifier maps 1:1 to the seeded price — no rounding/overcharge
4169
+ // for any on-menu value.
3612
4170
  "grok-imagine-video-1.5": [
3613
4171
  { maxSeconds: 1, suffix: "1s" },
3614
4172
  { maxSeconds: 2, suffix: "2s" },