@nodaro/shared 3.63.0 → 3.65.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 (265) hide show
  1. package/dist/{chunk-3K24DWOH.js → chunk-222QM7CO.js} +3 -3
  2. package/dist/{chunk-3K24DWOH.js.map → chunk-222QM7CO.js.map} +1 -1
  3. package/dist/chunk-27HA6YOL.cjs +377 -0
  4. package/dist/chunk-27HA6YOL.cjs.map +1 -0
  5. package/dist/{chunk-4DVWXEB6.js → chunk-2NKF476Z.js} +3 -3
  6. package/dist/{chunk-4DVWXEB6.js.map → chunk-2NKF476Z.js.map} +1 -1
  7. package/dist/chunk-3AU52TSW.js +143 -0
  8. package/dist/chunk-3AU52TSW.js.map +1 -0
  9. package/dist/{chunk-F6WGGYQW.cjs → chunk-5NVGKXJV.cjs} +68 -29
  10. package/dist/chunk-5NVGKXJV.cjs.map +1 -0
  11. package/dist/{chunk-HWQ2SYNA.js → chunk-5SSMPYE5.js} +99 -9
  12. package/dist/chunk-5SSMPYE5.js.map +1 -0
  13. package/dist/{chunk-WRSWH7US.cjs → chunk-6BRWPJPP.cjs} +17 -2
  14. package/dist/chunk-6BRWPJPP.cjs.map +1 -0
  15. package/dist/{chunk-KHH54GRP.cjs → chunk-6ET3KDO4.cjs} +15 -338
  16. package/dist/chunk-6ET3KDO4.cjs.map +1 -0
  17. package/dist/{chunk-TM5JYSJF.cjs → chunk-6OSIOVF7.cjs} +98 -37
  18. package/dist/chunk-6OSIOVF7.cjs.map +1 -0
  19. package/dist/{chunk-YUER7TJG.js → chunk-6X5PBAC4.js} +13 -4
  20. package/dist/chunk-6X5PBAC4.js.map +1 -0
  21. package/dist/chunk-7BN4EDIC.cjs +185 -0
  22. package/dist/chunk-7BN4EDIC.cjs.map +1 -0
  23. package/dist/{chunk-6M563QE6.js → chunk-7OWXHW7Z.js} +78 -28
  24. package/dist/chunk-7OWXHW7Z.js.map +1 -0
  25. package/dist/{chunk-FXGNRYQQ.js → chunk-AT53ZQUC.js} +3 -3
  26. package/dist/{chunk-FXGNRYQQ.js.map → chunk-AT53ZQUC.js.map} +1 -1
  27. package/dist/{chunk-HSHCCBIV.js → chunk-BQYCZLMF.js} +16 -3
  28. package/dist/chunk-BQYCZLMF.js.map +1 -0
  29. package/dist/{chunk-34QLPTSA.js → chunk-BSTAAGLY.js} +3 -3
  30. package/dist/{chunk-34QLPTSA.js.map → chunk-BSTAAGLY.js.map} +1 -1
  31. package/dist/{chunk-PSKZKLDG.js → chunk-CW6MMQNO.js} +562 -26
  32. package/dist/chunk-CW6MMQNO.js.map +1 -0
  33. package/dist/{chunk-EPXGG27L.js → chunk-D5Y3EYRM.js} +5 -5
  34. package/dist/{chunk-EPXGG27L.js.map → chunk-D5Y3EYRM.js.map} +1 -1
  35. package/dist/{chunk-XGVJGNZW.cjs → chunk-DQ2PARNH.cjs} +15 -5
  36. package/dist/chunk-DQ2PARNH.cjs.map +1 -0
  37. package/dist/{chunk-6BZC2ZHC.cjs → chunk-E66HSC2E.cjs} +9 -9
  38. package/dist/{chunk-6BZC2ZHC.cjs.map → chunk-E66HSC2E.cjs.map} +1 -1
  39. package/dist/{chunk-NIAFR5EE.js → chunk-FGBGKBML.js} +32 -3
  40. package/dist/chunk-FGBGKBML.js.map +1 -0
  41. package/dist/{chunk-M5OCFGHF.cjs → chunk-FI3HJZWM.cjs} +588 -25
  42. package/dist/chunk-FI3HJZWM.cjs.map +1 -0
  43. package/dist/{chunk-L2TVY6XN.cjs → chunk-FJZTQTF4.cjs} +4 -4
  44. package/dist/{chunk-L2TVY6XN.cjs.map → chunk-FJZTQTF4.cjs.map} +1 -1
  45. package/dist/{chunk-XGGZWA4A.cjs → chunk-GJ3D5X4X.cjs} +52 -49
  46. package/dist/chunk-GJ3D5X4X.cjs.map +1 -0
  47. package/dist/{chunk-Q6IES3U2.js → chunk-H5KHWTAE.js} +5 -2
  48. package/dist/chunk-H5KHWTAE.js.map +1 -0
  49. package/dist/{chunk-MD4XHED4.js → chunk-H745DQ6V.js} +3 -3
  50. package/dist/{chunk-MD4XHED4.js.map → chunk-H745DQ6V.js.map} +1 -1
  51. package/dist/{chunk-KCZHQH2O.js → chunk-HAH2F7LT.js} +4 -4
  52. package/dist/{chunk-KCZHQH2O.js.map → chunk-HAH2F7LT.js.map} +1 -1
  53. package/dist/{chunk-V5EEQR2U.cjs → chunk-JQMFJAYU.cjs} +21 -21
  54. package/dist/{chunk-V5EEQR2U.cjs.map → chunk-JQMFJAYU.cjs.map} +1 -1
  55. package/dist/{chunk-WZVIBAKN.cjs → chunk-JYU5EIRM.cjs} +12 -12
  56. package/dist/{chunk-WZVIBAKN.cjs.map → chunk-JYU5EIRM.cjs.map} +1 -1
  57. package/dist/{chunk-Y35JQPT6.cjs → chunk-K6RIN3LW.cjs} +142 -45
  58. package/dist/chunk-K6RIN3LW.cjs.map +1 -0
  59. package/dist/{chunk-BLJUCPMV.cjs → chunk-KSHAAPQF.cjs} +5 -2
  60. package/dist/chunk-KSHAAPQF.cjs.map +1 -0
  61. package/dist/{chunk-2PU3AGGS.cjs → chunk-KTCEKGBJ.cjs} +7 -7
  62. package/dist/{chunk-2PU3AGGS.cjs.map → chunk-KTCEKGBJ.cjs.map} +1 -1
  63. package/dist/{chunk-LH72PQO2.cjs → chunk-KWYS4IIM.cjs} +165 -50
  64. package/dist/chunk-KWYS4IIM.cjs.map +1 -0
  65. package/dist/{chunk-GSKLPI3J.cjs → chunk-MIT2USTS.cjs} +118 -61
  66. package/dist/chunk-MIT2USTS.cjs.map +1 -0
  67. package/dist/{chunk-Y4GCJJPF.cjs → chunk-NYZQOIXJ.cjs} +35 -2
  68. package/dist/chunk-NYZQOIXJ.cjs.map +1 -0
  69. package/dist/{chunk-A2PX5IRC.cjs → chunk-PERUFUVH.cjs} +13 -13
  70. package/dist/{chunk-A2PX5IRC.cjs.map → chunk-PERUFUVH.cjs.map} +1 -1
  71. package/dist/{chunk-X5BAFW3Q.cjs → chunk-PGDR7CO3.cjs} +8 -8
  72. package/dist/{chunk-X5BAFW3Q.cjs.map → chunk-PGDR7CO3.cjs.map} +1 -1
  73. package/dist/{chunk-OV3JTKBY.js → chunk-PL7AQQV7.js} +123 -22
  74. package/dist/chunk-PL7AQQV7.js.map +1 -0
  75. package/dist/chunk-Q4YOLT4M.js +164 -0
  76. package/dist/chunk-Q4YOLT4M.js.map +1 -0
  77. package/dist/{chunk-GMBDLNLD.cjs → chunk-R5ILCNCC.cjs} +197 -60
  78. package/dist/chunk-R5ILCNCC.cjs.map +1 -0
  79. package/dist/chunk-RP4KQUNU.cjs +168 -0
  80. package/dist/chunk-RP4KQUNU.cjs.map +1 -0
  81. package/dist/{chunk-77WU3V3J.cjs → chunk-SPU7MUWE.cjs} +6 -6
  82. package/dist/{chunk-77WU3V3J.cjs.map → chunk-SPU7MUWE.cjs.map} +1 -1
  83. package/dist/{chunk-XBTYGQ6Z.js → chunk-ST7OBB5J.js} +8 -5
  84. package/dist/chunk-ST7OBB5J.js.map +1 -0
  85. package/dist/{chunk-2QKF7M2Z.js → chunk-TAPBDT47.js} +3 -3
  86. package/dist/{chunk-2QKF7M2Z.js.map → chunk-TAPBDT47.js.map} +1 -1
  87. package/dist/{chunk-BMJVKYVB.js → chunk-V5NLQ4L5.js} +123 -7
  88. package/dist/chunk-V5NLQ4L5.js.map +1 -0
  89. package/dist/{chunk-KMGCHV6O.js → chunk-V6OXSXIX.js} +63 -30
  90. package/dist/chunk-V6OXSXIX.js.map +1 -0
  91. package/dist/{chunk-LMAQUR55.cjs → chunk-WQMPIURW.cjs} +6 -6
  92. package/dist/{chunk-LMAQUR55.cjs.map → chunk-WQMPIURW.cjs.map} +1 -1
  93. package/dist/{chunk-ZPE2ZTJ4.cjs → chunk-WZG6GZIL.cjs} +4 -4
  94. package/dist/{chunk-ZPE2ZTJ4.cjs.map → chunk-WZG6GZIL.cjs.map} +1 -1
  95. package/dist/{chunk-AE3AAJ4O.js → chunk-XJANKTIL.js} +3 -3
  96. package/dist/{chunk-AE3AAJ4O.js.map → chunk-XJANKTIL.js.map} +1 -1
  97. package/dist/{chunk-O7RZRUMZ.js → chunk-XJWED257.js} +14 -309
  98. package/dist/chunk-XJWED257.js.map +1 -0
  99. package/dist/chunk-XSSLNINL.js +346 -0
  100. package/dist/chunk-XSSLNINL.js.map +1 -0
  101. package/dist/{chunk-6TGB7ECA.cjs → chunk-YD4XY74W.cjs} +12 -8
  102. package/dist/chunk-YD4XY74W.cjs.map +1 -0
  103. package/dist/{chunk-YX6TFX7H.js → chunk-YMZUE2IX.js} +66 -11
  104. package/dist/chunk-YMZUE2IX.js.map +1 -0
  105. package/dist/{chunk-4MMZD63H.js → chunk-Z77M7Q2R.js} +3 -3
  106. package/dist/{chunk-4MMZD63H.js.map → chunk-Z77M7Q2R.js.map} +1 -1
  107. package/dist/{chunk-CZ5IQB3L.js → chunk-ZSRXY5YT.js} +8 -5
  108. package/dist/chunk-ZSRXY5YT.js.map +1 -0
  109. package/dist/entries/apps.cjs +43 -42
  110. package/dist/entries/apps.js +8 -7
  111. package/dist/entries/captions.cjs +38 -30
  112. package/dist/entries/captions.d.cts +48 -2
  113. package/dist/entries/captions.d.ts +48 -2
  114. package/dist/entries/captions.js +1 -1
  115. package/dist/entries/credits.cjs +319 -191
  116. package/dist/entries/credits.d.cts +260 -19
  117. package/dist/entries/credits.d.ts +260 -19
  118. package/dist/entries/credits.js +11 -11
  119. package/dist/entries/entities.cjs +202 -193
  120. package/dist/entries/entities.d.cts +44 -9
  121. package/dist/entries/entities.d.ts +44 -9
  122. package/dist/entries/entities.js +2 -1
  123. package/dist/entries/llm-models.cjs +86 -62
  124. package/dist/entries/llm-models.d.cts +73 -20
  125. package/dist/entries/llm-models.d.ts +73 -20
  126. package/dist/entries/llm-models.js +2 -2
  127. package/dist/entries/media.cjs +79 -63
  128. package/dist/entries/media.d.cts +154 -1
  129. package/dist/entries/media.d.ts +154 -1
  130. package/dist/entries/media.js +1 -1
  131. package/dist/entries/model-catalog.cjs +205 -109
  132. package/dist/entries/model-catalog.d.cts +65 -58
  133. package/dist/entries/model-catalog.d.ts +65 -58
  134. package/dist/entries/model-catalog.js +4 -4
  135. package/dist/entries/models.cjs +527 -346
  136. package/dist/entries/models.d.cts +86 -7
  137. package/dist/entries/models.d.ts +86 -7
  138. package/dist/entries/models.js +6 -5
  139. package/dist/entries/nodes.cjs +220 -211
  140. package/dist/entries/nodes.d.cts +46 -3
  141. package/dist/entries/nodes.d.ts +46 -3
  142. package/dist/entries/nodes.js +10 -9
  143. package/dist/entries/pipeline.cjs +156 -152
  144. package/dist/entries/pipeline.d.cts +14 -4
  145. package/dist/entries/pipeline.d.ts +14 -4
  146. package/dist/entries/pipeline.js +3 -3
  147. package/dist/entries/social.cjs +177 -177
  148. package/dist/entries/social.js +2 -2
  149. package/dist/entries/ugc.cjs +71 -71
  150. package/dist/entries/ugc.js +4 -4
  151. package/dist/entries/video.cjs +174 -145
  152. package/dist/entries/video.d.cts +114 -2
  153. package/dist/entries/video.d.ts +114 -2
  154. package/dist/entries/video.js +7 -6
  155. package/dist/entries/workflow.cjs +150 -150
  156. package/dist/entries/workflow.d.cts +1 -1
  157. package/dist/entries/workflow.d.ts +1 -1
  158. package/dist/entries/workflow.js +2 -2
  159. package/dist/index.cjs +2430 -1929
  160. package/dist/index.d.cts +13 -12
  161. package/dist/index.d.ts +13 -12
  162. package/dist/index.js +28 -27
  163. package/dist/{model-catalog-C_Eo35tL.d.cts → model-catalog-BoUKGFNl.d.cts} +182 -3
  164. package/dist/{model-catalog-C_Eo35tL.d.ts → model-catalog-BoUKGFNl.d.ts} +182 -3
  165. package/dist/{model-constants-DWcxOmaY.d.cts → model-constants-BElS3AeE.d.ts} +142 -23
  166. package/dist/{model-constants-Bg4ccSQb.d.ts → model-constants-CpQz1bGa.d.cts} +142 -23
  167. package/dist/tts-capabilities-BtnDWK9K.d.ts +133 -0
  168. package/dist/tts-capabilities-C52UccTI.d.cts +133 -0
  169. package/package.json +1 -1
  170. package/src/__tests__/add-captions-nemotron-pricing.test.ts +111 -0
  171. package/src/__tests__/dialogue-capabilities.test.ts +167 -6
  172. package/src/__tests__/extend-providers.test.ts +353 -26
  173. package/src/__tests__/fixtures/mask-composite-quote-parity.json +1 -1
  174. package/src/__tests__/fixtures/measured-input-quote-parity.json +1435 -0
  175. package/src/__tests__/fixtures/planned-length-quote-parity.json +1866 -0
  176. package/src/__tests__/fixtures/video-utility-quote-parity.json +2343 -0
  177. package/src/__tests__/flux-3-klein.test.ts +203 -0
  178. package/src/__tests__/gpt-image-2-6-formats.test.ts +3 -1
  179. package/src/__tests__/kling4-catalog.test.ts +1 -1
  180. package/src/__tests__/llm-models.test.ts +48 -13
  181. package/src/__tests__/llm-price-key.test.ts +12 -0
  182. package/src/__tests__/model-makers.test.ts +3 -0
  183. package/src/__tests__/node-runtime-keys.test.ts +7 -0
  184. package/src/__tests__/normalize-node-params.test.ts +147 -1
  185. package/src/__tests__/retired-lip-sync-providers.test.ts +43 -0
  186. package/src/__tests__/seedance-extend-source-credit-id.test.ts +89 -0
  187. package/src/__tests__/sequence-execution.test.ts +22 -1
  188. package/src/__tests__/speech-pricing.test.ts +62 -1
  189. package/src/__tests__/suno-credit-type.test.ts +21 -2
  190. package/src/__tests__/transcribe-capabilities.test.ts +4 -2
  191. package/src/__tests__/tts-capabilities.test.ts +160 -4
  192. package/src/__tests__/video-analysis-catalog-sync.test.ts +4 -2
  193. package/src/__tests__/video-analysis-pricing.test.ts +22 -9
  194. package/src/__tests__/video-subjects.test.ts +192 -0
  195. package/src/__tests__/wired-character-names.test.ts +142 -0
  196. package/src/caption-styles.ts +62 -0
  197. package/src/credit-estimators/add-captions-nemotron.ts +73 -0
  198. package/src/credit-estimators/index.ts +14 -0
  199. package/src/credit-estimators/speech.ts +57 -9
  200. package/src/credit-identifiers.ts +284 -13
  201. package/src/dialogue-capabilities.ts +220 -3
  202. package/src/dubbing-structure.ts +186 -0
  203. package/src/entries/captions.ts +2 -0
  204. package/src/entries/credits.ts +25 -1
  205. package/src/entries/entities.ts +2 -0
  206. package/src/entries/llm-models.ts +7 -0
  207. package/src/entries/media.ts +3 -1
  208. package/src/entries/model-catalog.ts +30 -0
  209. package/src/entries/models.ts +54 -0
  210. package/src/entries/nodes.ts +2 -0
  211. package/src/entries/pipeline.ts +1 -1
  212. package/src/entries/video.ts +8 -1
  213. package/src/flux-3-klein.ts +69 -0
  214. package/src/gemini-tts.ts +144 -0
  215. package/src/input-image-pricing.ts +23 -6
  216. package/src/llm-models.ts +130 -36
  217. package/src/model-catalog.ts +539 -25
  218. package/src/model-constants.ts +247 -25
  219. package/src/node-default-mappings.ts +3 -0
  220. package/src/node-runtime-keys.ts +3 -0
  221. package/src/normalize-node-params.ts +123 -2
  222. package/src/seedance-extend-rate.ts +116 -0
  223. package/src/sequence-execution.ts +24 -0
  224. package/src/transcribe-preflight.ts +23 -0
  225. package/src/tts-capabilities.ts +193 -1
  226. package/src/video-analysis-pricing.ts +39 -15
  227. package/src/video-character-refs.ts +160 -3
  228. package/src/wired-character-names.ts +134 -18
  229. package/src/wired-character-video-subjects.ts +63 -0
  230. package/dist/chunk-63H4C56Q.cjs +0 -38
  231. package/dist/chunk-63H4C56Q.cjs.map +0 -1
  232. package/dist/chunk-6M563QE6.js.map +0 -1
  233. package/dist/chunk-6TGB7ECA.cjs.map +0 -1
  234. package/dist/chunk-6XUG4L7X.cjs +0 -54
  235. package/dist/chunk-6XUG4L7X.cjs.map +0 -1
  236. package/dist/chunk-BLJUCPMV.cjs.map +0 -1
  237. package/dist/chunk-BMJVKYVB.js.map +0 -1
  238. package/dist/chunk-CZ5IQB3L.js.map +0 -1
  239. package/dist/chunk-F6WGGYQW.cjs.map +0 -1
  240. package/dist/chunk-GMBDLNLD.cjs.map +0 -1
  241. package/dist/chunk-GSKLPI3J.cjs.map +0 -1
  242. package/dist/chunk-HBXF6RUU.js +0 -31
  243. package/dist/chunk-HBXF6RUU.js.map +0 -1
  244. package/dist/chunk-HSHCCBIV.js.map +0 -1
  245. package/dist/chunk-HWQ2SYNA.js.map +0 -1
  246. package/dist/chunk-IY3Y462W.js +0 -42
  247. package/dist/chunk-IY3Y462W.js.map +0 -1
  248. package/dist/chunk-KHH54GRP.cjs.map +0 -1
  249. package/dist/chunk-KMGCHV6O.js.map +0 -1
  250. package/dist/chunk-LH72PQO2.cjs.map +0 -1
  251. package/dist/chunk-M5OCFGHF.cjs.map +0 -1
  252. package/dist/chunk-NIAFR5EE.js.map +0 -1
  253. package/dist/chunk-O7RZRUMZ.js.map +0 -1
  254. package/dist/chunk-OV3JTKBY.js.map +0 -1
  255. package/dist/chunk-PSKZKLDG.js.map +0 -1
  256. package/dist/chunk-Q6IES3U2.js.map +0 -1
  257. package/dist/chunk-TM5JYSJF.cjs.map +0 -1
  258. package/dist/chunk-WRSWH7US.cjs.map +0 -1
  259. package/dist/chunk-XBTYGQ6Z.js.map +0 -1
  260. package/dist/chunk-XGGZWA4A.cjs.map +0 -1
  261. package/dist/chunk-XGVJGNZW.cjs.map +0 -1
  262. package/dist/chunk-Y35JQPT6.cjs.map +0 -1
  263. package/dist/chunk-Y4GCJJPF.cjs.map +0 -1
  264. package/dist/chunk-YUER7TJG.js.map +0 -1
  265. package/dist/chunk-YX6TFX7H.js.map +0 -1
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Seedance 2.5 Extend's price rows — part of the public credit-id contract:
3
+ * the rows a run is charged a multiple of, and so the ids a client names to
4
+ * ask what a run costs (`tailExtendCreditId`, `credit-identifiers.ts`).
5
+ *
6
+ * A Seedance 2.5 Extend run sends the source's last
7
+ * {@link SEEDANCE_EXTEND_CONTEXT_MAX_SEC} seconds (all of a shorter source)
8
+ * and is charged per second sent and added. A per-second price is not a
9
+ * whole credit, so each resolution's row is the price of
10
+ * {@link SEEDANCE_EXTEND_RATE_SECONDS} seconds, and a run is that row × (seconds
11
+ * sent + seconds added) ÷ 2, rounded up once.
12
+ *
13
+ * The seconds rule lives here too (decided 2026-11-13), so a client prices a
14
+ * run on a known source by the same rule the server charges it by
15
+ * (`seedanceExtendSourceCreditId`, credit-identifiers.ts): how many seconds of
16
+ * the source are sent ({@link seedanceExtendSentSec}, a picture's length read
17
+ * by the container-overhang rule), how many are added
18
+ * ({@link seedanceExtendAddedSec}) and the units of a rate row they make
19
+ * ({@link seedanceExtendUnits}). `@nodaro/render-rules`
20
+ * (`seedance-extend-pricing.ts`) and the backend read them from here.
21
+ */
22
+ import { MODEL_CATALOG } from "./model-catalog.js"
23
+ import { pricedOutputDurationSec, SEEDANCE_2_R2V_MIN_REF_VIDEO_SEC, type SeedanceExtendProvider, type TailExtendProvider } from "./model-constants.js"
24
+ import { CONTAINER_OVERHANG_SEC } from "./video-duration.js"
25
+
26
+ /** The Extend Video provider priced by the seconds it sends. */
27
+ export const SEEDANCE_EXTEND_SENT_PRICED_PROVIDER = "seedance-2-5-extend" satisfies SeedanceExtendProvider
28
+
29
+ /** The Extend Video provider priced by the seconds it sends. */
30
+ export type SentPricedSeedanceExtendProvider = typeof SEEDANCE_EXTEND_SENT_PRICED_PROVIDER
31
+
32
+ /** The most of the source's end a run sends as `@video_1`, in seconds. */
33
+ export const SEEDANCE_EXTEND_CONTEXT_MAX_SEC = 10
34
+
35
+ /** The seconds one rate row prices. */
36
+ export const SEEDANCE_EXTEND_RATE_SECONDS = 2
37
+
38
+ /** The rate row of each resolution: the price of {@link SEEDANCE_EXTEND_RATE_SECONDS} seconds. */
39
+ export const SEEDANCE_EXTEND_RATE_CREDIT_IDS: Readonly<Record<"480p" | "720p" | "1080p", string>> = {
40
+ "480p": "seedance-2-5-extend:480p:per-2s",
41
+ "720p": "seedance-2-5-extend:720p:per-2s",
42
+ "1080p": "seedance-2-5-extend:1080p:per-2s",
43
+ }
44
+
45
+ /** Is `provider` the Extend Video provider priced by the seconds it sends? A retired id answers false: pass it through `canonicalVideoProvider` first. */
46
+ export function isSeedanceExtendPricedBySecondsSent(provider: unknown): provider is SentPricedSeedanceExtendProvider {
47
+ return provider === SEEDANCE_EXTEND_SENT_PRICED_PROVIDER
48
+ }
49
+
50
+ /** Is `id` one of the rate rows? */
51
+ export function isSeedanceExtendRateCreditId(id: unknown): boolean {
52
+ return typeof id === "string" && (Object.values(SEEDANCE_EXTEND_RATE_CREDIT_IDS) as string[]).includes(id)
53
+ }
54
+
55
+ /**
56
+ * The seconds a tail-recipe extend run (Seedance 2.5 / 2.0, Kling 4) adds for a requested `duration`: the
57
+ * seconds its price counts (`pricedOutputDurationSec`, the provider's catalog
58
+ * default when unset or unreadable), held in the provider's catalog window.
59
+ * The one reading of the length: the route queues it, the worker generates
60
+ * it, and every price and quote counts it.
61
+ */
62
+ export function seedanceExtendAddedSec(provider: TailExtendProvider, duration: unknown): number {
63
+ const requested = typeof duration === "number" || typeof duration === "string" ? duration : undefined
64
+ const offered = MODEL_CATALOG[provider]?.durations ?? []
65
+ const min = offered.length > 0 ? Math.min(...offered) : 1
66
+ const max = offered.length > 0 ? Math.max(...offered) : Number.POSITIVE_INFINITY
67
+ return Math.min(max, Math.max(min, Math.round(pricedOutputDurationSec(provider, requested))))
68
+ }
69
+
70
+ /** A length the source gives, when it is one: finite and above 0. */
71
+ function knownSec(sec: number | null | undefined): number | undefined {
72
+ return typeof sec === "number" && Number.isFinite(sec) && sec > 0 ? sec : undefined
73
+ }
74
+
75
+ /**
76
+ * A picture's measured length as the seconds it is charged as — the
77
+ * platform's container-overhang rule: at most `CONTAINER_OVERHANG_SEC` (a
78
+ * quarter second) past a whole second is that whole second (8.04 s is 8 s,
79
+ * 8.25 s is 8 s); anything else is exactly as measured (8.3 s is 8.3 s).
80
+ * Under a second there is no whole second to read it as.
81
+ */
82
+ export function seedanceExtendSourceSec(pictureSec: number): number {
83
+ const whole = Math.floor(pictureSec)
84
+ return whole >= 1 && pictureSec - whole <= CONTAINER_OVERHANG_SEC ? whole : pictureSec
85
+ }
86
+
87
+ /**
88
+ * The seconds of the source a run is charged for sending: its last
89
+ * {@link SEEDANCE_EXTEND_CONTEXT_MAX_SEC}, or all of a shorter source, its
90
+ * picture's length read by the container-overhang rule
91
+ * ({@link seedanceExtendSourceSec}). A source whose length is not known (a
92
+ * quote before the upstream video exists, or a length that is not a positive
93
+ * finite number) counts the whole window: the most a run sends.
94
+ */
95
+ export function seedanceExtendSentSec(sourcePictureSec: number | null | undefined): number {
96
+ const known = knownSec(sourcePictureSec)
97
+ return known === undefined ? SEEDANCE_EXTEND_CONTEXT_MAX_SEC : Math.min(SEEDANCE_EXTEND_CONTEXT_MAX_SEC, seedanceExtendSourceSec(known))
98
+ }
99
+
100
+ /**
101
+ * Whether a Seedance Extend run refuses a source of this measured picture
102
+ * length: a known length (positive, finite) under the shortest source the
103
+ * extend takes, `SEEDANCE_2_R2V_MIN_REF_VIDEO_SEC`, compared as measured, as
104
+ * the route refuses it before anything is reserved and the worker before it
105
+ * generates. A length that is not known is never refused here (the run
106
+ * measures the source itself).
107
+ */
108
+ export function seedanceExtendRefusesSource(sourcePictureSec: number | null | undefined): boolean {
109
+ const known = knownSec(sourcePictureSec)
110
+ return known !== undefined && known < SEEDANCE_2_R2V_MIN_REF_VIDEO_SEC
111
+ }
112
+
113
+ /** The units of a rate row a run that sends `sentSec` and adds `addedSec` is charged. */
114
+ export function seedanceExtendUnits(sentSec: number, addedSec: number): number {
115
+ return (sentSec + addedSec) / SEEDANCE_EXTEND_RATE_SECONDS
116
+ }
@@ -1,6 +1,30 @@
1
1
  /** Public workflow capability marker; creative planning stays in the Studio codec. */
2
2
  export const STUDIO_DEPENDENT_FRAMES_CAPABILITY = "studio-dependent-frames-v1"
3
3
 
4
+ const record = (value: unknown): Record<string, unknown> =>
5
+ value && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>) : {}
6
+ const declaresDependentFrames = (data: Record<string, unknown>): boolean =>
7
+ Array.isArray(data.requiredCapabilities) && data.requiredCapabilities.includes(STUDIO_DEPENDENT_FRAMES_CAPABILITY)
8
+
9
+ /**
10
+ * Whether a workflow document is one a server codec owns (Studio): the TS
11
+ * mirror of the database's `workflow_requires_compatible_writer`, whose write
12
+ * guard refuses any change to such a document by any writer but the codec's.
13
+ * Recognized even when a writer omitted the declaration: a Studio settings
14
+ * block holding keyframes, sequences or settled jobs, or declaring dependent
15
+ * frames, or any node carrying `keyframeId`, `sequenceBinding` or that
16
+ * declaration. The one predicate the server's routes and the editor ask.
17
+ */
18
+ export function isCodecOwnedDocument(nodes: unknown, settings: unknown): boolean {
19
+ const studio = record(record(settings).studio)
20
+ return ["keyframes", "sequences", "settledJobIds"].some((key) => Object.hasOwn(studio, key))
21
+ || declaresDependentFrames(studio)
22
+ || (Array.isArray(nodes) && nodes.some((node) => {
23
+ const data = record(record(node).data)
24
+ return Object.hasOwn(data, "keyframeId") || Object.hasOwn(data, "sequenceBinding") || declaresDependentFrames(data)
25
+ }))
26
+ }
27
+
4
28
  export class SequenceExecutionRequiredError extends Error {
5
29
  readonly code = "sequence_execution_required"
6
30
  readonly statusCode = 400
@@ -92,6 +92,29 @@ export interface WordlessTranscriptFeed {
92
92
  readonly message: string
93
93
  }
94
94
 
95
+ /** Lanes that return word timings whatever the flag (ElevenLabs Scribe is word-level). */
96
+ const ALWAYS_WORD_LEVEL_LANES: ReadonlySet<string> = new Set(["elevenlabs-stt"])
97
+
98
+ /**
99
+ * Whether a Transcribe node's run returns WORD timings, as its data and the
100
+ * graph say — what a caption render downstream can take as its words (the run's
101
+ * resolver hands an Add Captions node a Transcribe node's words only when there
102
+ * are some). Never while it translates, never on a lane that cannot give them;
103
+ * a word-level lane always; any other capable lane only when they are asked
104
+ * for: `wordTimestamps: true`, or its `json` output wired (`jsonWired`: the
105
+ * workflow run turns the flag on then). A price that reads this errs high when
106
+ * it is wrong: an unknown lane answers false.
107
+ */
108
+ export function transcribeNodeReturnsWords(
109
+ data: { readonly provider?: unknown; readonly wordTimestamps?: unknown; readonly targetLanguage?: unknown } | null | undefined,
110
+ jsonWired: boolean,
111
+ ): boolean {
112
+ const provider = (typeof data?.provider === "string" && data.provider) || DEFAULT_TRANSCRIBE_NODE_PROVIDER
113
+ if (transcribeTargetLanguageOf(data?.targetLanguage) !== undefined) return false
114
+ if (!transcribeLaneSupportsWordTimestamps(provider)) return false
115
+ return ALWAYS_WORD_LEVEL_LANES.has(provider) || data?.wordTimestamps === true || jsonWired
116
+ }
117
+
95
118
  // Handle ids (generated map: backend/src/lib/mcp/generated/node-handles.ts).
96
119
  const TRANSCRIBE_JSON_OUT = "json"
97
120
  const TRANSCRIPT_IN = "transcript"
@@ -13,7 +13,8 @@
13
13
  * text-to-speech request that names one runs as the fallback model, so these
14
14
  * helpers answer for the fallback there.
15
15
  */
16
- import { MODEL_CATALOG, type TtsCapabilities, type TtsSettingLever } from "./model-catalog.js"
16
+ import { MODEL_CATALOG, type TtsCapabilities, type TtsDirectionSheet, type TtsSettingLever } from "./model-catalog.js"
17
+ import { REPLICA_CONSENT_ATTESTATION, type TtsNamedVoice, type TtsReplica } from "./gemini-tts.js"
17
18
 
18
19
  /** Legacy provider ids that are another model under an old name. They have no catalog entry of their own. */
19
20
  export const TTS_PROVIDER_ALIASES: Readonly<Record<string, string>> = {
@@ -87,3 +88,194 @@ export function ttsSupportsTimestamps(provider: string | undefined): boolean {
87
88
  export function ttsLanguageCodes(provider: string | undefined): readonly string[] {
88
89
  return getTtsCapabilities(provider).languages
89
90
  }
91
+
92
+ /**
93
+ * The named voices the model speaks, or `undefined` when it speaks the
94
+ * ElevenLabs voices (premade, library, clones). See `TtsCapabilities.voices`.
95
+ */
96
+ export function ttsNamedVoices(provider: string | undefined): readonly TtsNamedVoice[] | undefined {
97
+ return getTtsCapabilities(provider).voices
98
+ }
99
+
100
+ /**
101
+ * Whether `voice` is one the model can speak: on a model with named voices,
102
+ * one of them by its exact wire name; on any other model, any id (the
103
+ * ElevenLabs voice checks apply there, as before).
104
+ */
105
+ export function ttsAcceptsVoice(provider: string | undefined, voice: string): boolean {
106
+ const named = ttsNamedVoices(provider)
107
+ return !named || named.some((v) => v.id === voice)
108
+ }
109
+
110
+ /**
111
+ * The voice a request on a named-voice model runs with: the one it names when
112
+ * the model speaks it, else the model's default. `undefined` on an ElevenLabs
113
+ * model (its own default applies downstream).
114
+ */
115
+ export function ttsNamedVoiceFor(provider: string | undefined, voice: unknown): string | undefined {
116
+ const caps = getTtsCapabilities(provider)
117
+ if (!caps.voices) return undefined
118
+ return typeof voice === "string" && caps.voices.some((v) => v.id === voice) ? voice : caps.defaultVoice
119
+ }
120
+
121
+ /** The style direction the model takes (`TtsCapabilities.direction`), or `undefined` when it takes none. */
122
+ export function ttsDirection(provider: string | undefined): TtsDirectionSheet | undefined {
123
+ return getTtsCapabilities(provider).direction
124
+ }
125
+
126
+ /** The model writes its tone tags `<in angle brackets>` from a closed list (`TtsCapabilities.tagSyntax`). */
127
+ export function ttsAngleTags(provider: string | undefined): readonly string[] | undefined {
128
+ const caps = getTtsCapabilities(provider)
129
+ return caps.audioTags && caps.tagSyntax === "angle" ? (caps.tags ?? []) : undefined
130
+ }
131
+
132
+ /**
133
+ * The style direction of a request, as the model takes it: each field kept
134
+ * only when the model's sheet names it and the value is one it accepts (a
135
+ * listed choice, or free text within its cap — trimmed, an empty one
136
+ * dropped). What the provider funnel sends and the workflow engine passes on;
137
+ * the REST route rejects instead of dropping (`ttsDirectionProblem`).
138
+ */
139
+ export interface TtsDirectionValues {
140
+ styleDirection?: string
141
+ pace?: string
142
+ accent?: string
143
+ audioProfile?: string
144
+ }
145
+
146
+ export function ttsDirectionFor(provider: string | undefined, values: Readonly<Record<string, unknown>>): TtsDirectionValues {
147
+ const sheet = ttsDirection(provider)
148
+ if (!sheet) return {}
149
+ const text = (value: unknown, max: number | undefined): string | undefined => {
150
+ if (max === undefined || typeof value !== "string") return undefined
151
+ const trimmed = value.trim()
152
+ return trimmed && trimmed.length <= max ? trimmed : undefined
153
+ }
154
+ const choice = (value: unknown, choices: readonly string[] | undefined): string | undefined =>
155
+ choices && typeof value === "string" && choices.includes(value) ? value : undefined
156
+ const out: TtsDirectionValues = {}
157
+ const style = sheet.styles ? choice(values.styleDirection, sheet.styles) : text(values.styleDirection, sheet.styleMaxChars)
158
+ if (style !== undefined) out.styleDirection = style
159
+ const pace = choice(values.pace, sheet.paces)
160
+ if (pace !== undefined) out.pace = pace
161
+ const accent = choice(values.accent, sheet.accents)
162
+ if (accent !== undefined) out.accent = accent
163
+ const profile = text(values.audioProfile, sheet.audioProfileMaxChars)
164
+ if (profile !== undefined) out.audioProfile = profile
165
+ return out
166
+ }
167
+
168
+ /**
169
+ * Why a request's style direction cannot run on the model, or `undefined`
170
+ * when it can. Only the fields the model takes are judged; on a model that
171
+ * takes none, or a field it does not take, the value is never sent (as the
172
+ * neighbour text on a model that does not stitch), so it is no problem.
173
+ */
174
+ export function ttsDirectionProblem(provider: string | undefined, values: Readonly<Record<string, unknown>>): { field: keyof TtsDirectionValues; message: string } | undefined {
175
+ const sheet = ttsDirection(provider)
176
+ if (!sheet) return undefined
177
+ const textProblem = (field: keyof TtsDirectionValues, max: number | undefined) => {
178
+ const value = values[field]
179
+ if (max === undefined || value === undefined) return undefined
180
+ if (typeof value !== "string") return { field, message: `${field} must be a string` }
181
+ return value.trim().length > max ? { field, message: `${field} must be at most ${max} characters` } : undefined
182
+ }
183
+ const choiceProblem = (field: keyof TtsDirectionValues, choices: readonly string[] | undefined) => {
184
+ const value = values[field]
185
+ if (!choices || value === undefined || value === "") return undefined
186
+ return typeof value === "string" && choices.includes(value) ? undefined : { field, message: `${field} must be one of: ${choices.join(", ")}` }
187
+ }
188
+ return (
189
+ (sheet.styles ? choiceProblem("styleDirection", sheet.styles) : textProblem("styleDirection", sheet.styleMaxChars)) ??
190
+ choiceProblem("pace", sheet.paces) ??
191
+ choiceProblem("accent", sheet.accents) ??
192
+ textProblem("audioProfile", sheet.audioProfileMaxChars)
193
+ )
194
+ }
195
+
196
+ /** Every voice name a named-voice model speaks (all of them, across models). Built once from the catalog. */
197
+ let namedVoiceIds: ReadonlySet<string> | undefined
198
+ function anyModelsNamedVoice(voice: string): boolean {
199
+ namedVoiceIds ??= new Set(
200
+ Object.values(MODEL_CATALOG).flatMap((m) => (m.modes.includes("tts") ? (m.tts?.voices ?? []).map((v) => v.id) : [])),
201
+ )
202
+ return namedVoiceIds.has(voice)
203
+ }
204
+
205
+ /**
206
+ * The voice a text-to-speech run on `provider` speaks, when the model and the
207
+ * voice may have been chosen apart — a published app's Model card, a field
208
+ * mapping onto the model, an upstream Character's voice, a preset's voice with
209
+ * a model the caller named (decided 2026-11-13: the editor's model-switch rule,
210
+ * applied wherever the editor is not there to apply it):
211
+ * - a model with named voices (Gemini): the voice when it is one of them, its
212
+ * default voice for any other voice, and none (its default) for none;
213
+ * - an ElevenLabs model: none (the deployment's default) for a voice that only
214
+ * a named-voice model speaks (`Fola`, `Kore`…), else the voice as given.
215
+ * Returns `undefined` for "no voice named"; never a voice the model refuses.
216
+ */
217
+ export function ttsVoiceForModel(provider: string | undefined, voice: unknown): string | undefined {
218
+ const named = typeof voice === "string" && voice.length > 0 ? voice : undefined
219
+ const caps = getTtsCapabilities(provider)
220
+ if (caps.voices) {
221
+ if (named === undefined) return undefined
222
+ return caps.voices.some((v) => v.id === named) ? named : caps.defaultVoice
223
+ }
224
+ return named !== undefined && anyModelsNamedVoice(named) ? undefined : named
225
+ }
226
+
227
+ /** The model clones a speaker's voice for one request (`TtsCapabilities.replica`: Gemini 3.8 Flash). */
228
+ export function ttsTakesReplica(provider: string | undefined): boolean {
229
+ return getTtsCapabilities(provider).replica === true
230
+ }
231
+
232
+ /** Every model that takes a one-off clone, in catalog order (for a refusal's sentence). */
233
+ export function replicaModels(): string[] {
234
+ return Object.values(MODEL_CATALOG).filter((m) => m.modes.includes("tts") && m.tts?.replica === true).map((m) => m.id)
235
+ }
236
+
237
+ /** Whether `value` is an https link (the only scheme a recording is fetched from). */
238
+ function isHttpsLink(value: unknown): value is string {
239
+ if (typeof value !== "string") return false
240
+ try {
241
+ return new URL(value).protocol === "https:"
242
+ } catch {
243
+ return false
244
+ }
245
+ }
246
+
247
+ /** A request's one-off clone as the platform reads it: two https links, or undefined when absent or not that shape. */
248
+ export function replicaOf(value: unknown): TtsReplica | undefined {
249
+ if (!value || typeof value !== "object") return undefined
250
+ const { sourceAudioUrl, consentAudioUrl } = value as Record<string, unknown>
251
+ return isHttpsLink(sourceAudioUrl) && isHttpsLink(consentAudioUrl) ? { sourceAudioUrl, consentAudioUrl } : undefined
252
+ }
253
+
254
+ /**
255
+ * Why a request's one-off clone (`replica`) cannot run on the model, or
256
+ * undefined (none asked, or one it takes). Refused, never dropped: a clone
257
+ * that is not sent is someone else's voice. The recordings themselves (WAV,
258
+ * size, length) are judged where they are fetched (backend
259
+ * `lib/voice-replica.ts`).
260
+ */
261
+ export function ttsReplicaProblem(provider: string | undefined, value: unknown): string | undefined {
262
+ if (value === undefined || value === null) return undefined
263
+ if (!ttsTakesReplica(provider)) {
264
+ return `${provider ?? "This model"} does not clone a voice; a one-off clone runs on ${replicaModels().join(", ")}`
265
+ }
266
+ return replicaOf(value) ? undefined : "replica needs sourceAudioUrl and consentAudioUrl, each an https link to a WAV recording"
267
+ }
268
+
269
+ /**
270
+ * Why an API or MCP clone lacks its consent, or undefined: a `replica` asked
271
+ * must say `consent: true` — the caller's confirmation of
272
+ * `REPLICA_CONSENT_ATTESTATION`, what the editor's checkbox says (decided
273
+ * 2026-11-13). Refused before anything is read or held.
274
+ */
275
+ export function replicaConsentProblem(value: unknown): string | undefined {
276
+ if (value === undefined || value === null) return undefined
277
+ return (value as { consent?: unknown }).consent === true
278
+ ? undefined
279
+ : `replica.consent must be true: it confirms "${REPLICA_CONSENT_ATTESTATION}"`
280
+ }
281
+
@@ -124,9 +124,26 @@ export const VIDEO_ANALYSIS_WINDOW = { LEN: WINDOW_LEN, STRIDE: WINDOW_STRIDE, O
124
124
  // lands TOGETHER with the migration that seeds it —
125
125
  // `backend/src/ee/billing/__tests__/static-costs-match-migrations.test.ts`
126
126
  // fails the build on any row that differs from its latest migration.
127
+ //
128
+ // 2026-11-13 — the fast tier moved to gemini-3.8-flash (KIE dropped
129
+ // gemini-3-flash's channel). Only the rows the model swap touches were
130
+ // regenerated, on the deployed 9_082 basis: the new gemini-3.8-flash family,
131
+ // and `mixed` / `smart`, whose plans roll the fast model too. Every other row
132
+ // is exactly as deployed.
133
+ //
134
+ // 2026-11-13 — the `ultra` tier (gemini-4-carbon) joined. Its four rows are new
135
+ // (migration 649); every other row is exactly as deployed. They are the decided
136
+ // schedule, set between `mixed` and `smart` in every bucket; the plugin's
137
+ // cost test holds its formula to them like every other row.
127
138
  export const VIDEO_ANALYSIS_BUCKET_CREDITS: Record<string, number> = {
128
- // Current fast tier (VIDEO_ANALYSIS_TIERS.fast; it was also the fast model
129
- // before 2026-07).
139
+ // Current fast tier (VIDEO_ANALYSIS_TIERS.fast, since 2026-11-13).
140
+ "video-analysis:gemini-3.8-flash:60s": 186,
141
+ "video-analysis:gemini-3.8-flash:180s": 193,
142
+ "video-analysis:gemini-3.8-flash:360s": 534,
143
+ "video-analysis:gemini-3.8-flash:600s": 880,
144
+ // Legacy fast-tier model (backed the fast tier 2026-07-29 → 2026-11-13, and
145
+ // before 2026-07) — kept for stored raw-id configs, which the analysis engine
146
+ // now serves with the current fast model; still ≤ pro per bucket.
130
147
  "video-analysis:gemini-3-flash:60s": 181,
131
148
  "video-analysis:gemini-3-flash:180s": 185,
132
149
  "video-analysis:gemini-3-flash:360s": 515,
@@ -141,23 +158,29 @@ export const VIDEO_ANALYSIS_BUCKET_CREDITS: Record<string, number> = {
141
158
  "video-analysis:gemini-3.1-pro:180s": 232,
142
159
  "video-analysis:gemini-3.1-pro:360s": 640,
143
160
  "video-analysis:gemini-3.1-pro:600s": 1056,
161
+ // ULTRA (VIDEO_ANALYSIS_TIERS.ultra, since 2026-11-13) — the deepest-reasoning
162
+ // model reading every window. Above `mixed` and below `smart` per bucket.
163
+ "video-analysis:gemini-4-carbon:60s": 349,
164
+ "video-analysis:gemini-4-carbon:180s": 375,
165
+ "video-analysis:gemini-4-carbon:360s": 1054,
166
+ "video-analysis:gemini-4-carbon:600s": 1745,
144
167
  // Mixed tiers (`mixed` + `mixed-fast`) share ONE credit family — they are
145
168
  // variants of the same engine plan (plan internals live in the private
146
169
  // analysis plugin). Admin-tunable via model_pricing like every other row.
147
- "video-analysis:mixed:60s": 270,
148
- "video-analysis:mixed:180s": 291,
149
- "video-analysis:mixed:360s": 729,
150
- "video-analysis:mixed:600s": 1177,
170
+ "video-analysis:mixed:60s": 275,
171
+ "video-analysis:mixed:180s": 298,
172
+ "video-analysis:mixed:360s": 748,
173
+ "video-analysis:mixed:600s": 1209,
151
174
  // SMART — the accuracy tier, and since the 2026-08-03 re-plan a multi-roll
152
175
  // plan like the others, always refined (`selectionMode` does not apply
153
176
  // here — smart always refines; it never offers a cheaper "choose" path).
154
177
  // Priced above the economy tiers because it genuinely costs more to run;
155
178
  // the only tier whose accuracy is validated against a hand-counted edit
156
179
  // list, re-validated at the current plan before this schedule shipped.
157
- "video-analysis:smart:60s": 413,
158
- "video-analysis:smart:180s": 503,
159
- "video-analysis:smart:360s": 1267,
160
- "video-analysis:smart:600s": 2076,
180
+ "video-analysis:smart:60s": 416,
181
+ "video-analysis:smart:180s": 508,
182
+ "video-analysis:smart:360s": 1280,
183
+ "video-analysis:smart:600s": 2097,
161
184
  }
162
185
 
163
186
  /**
@@ -209,7 +232,7 @@ export function videoAnalysisNumWindows(bucketSec: number): number {
209
232
  * safety margin — internals stay private in the plugin).
210
233
  * - `video-audit:auto:<bucket>s` — no analysis wired; the node auto-runs a
211
234
  * fast-tier analysis first. Exactly the base family's price PLUS the
212
- * `gemini-3-flash` (legacy fast tier) row from `VIDEO_ANALYSIS_BUCKET_CREDITS`
235
+ * fast tier's row (`gemini-3.8-flash` since 2026-11-13) from `VIDEO_ANALYSIS_BUCKET_CREDITS`
213
236
  * at the SAME bucket — summed in the plugin's generator/formula, never
214
237
  * hand-added here (see the single-source assertion in
215
238
  * video-analysis-pricing.test.ts).
@@ -231,10 +254,11 @@ export const VIDEO_AUDIT_BUCKET_CREDITS: Record<string, number> = {
231
254
  "video-audit:180s": 290,
232
255
  "video-audit:360s": 663,
233
256
  "video-audit:600s": 1073,
234
- "video-audit:auto:60s": 396,
235
- "video-audit:auto:180s": 475,
236
- "video-audit:auto:360s": 1178,
237
- "video-audit:auto:600s": 1921,
257
+ // The auto family follows the fast row (2026-11-13: gemini-3.8-flash).
258
+ "video-audit:auto:60s": 401,
259
+ "video-audit:auto:180s": 483,
260
+ "video-audit:auto:360s": 1197,
261
+ "video-audit:auto:600s": 1953,
238
262
  }
239
263
 
240
264
  /**
@@ -48,6 +48,16 @@ export interface VideoCharacterReference {
48
48
  * positive `voices` cap take it.
49
49
  */
50
50
  voice?: VideoCharacterVoice
51
+ /**
52
+ * A short single-shot clip of this character (public URL). On a model with a
53
+ * positive `videoCharacters` cap (Kling 4.0, Kling 4.0 Flash) the character
54
+ * becomes a VIDEO subject made from this clip instead of an image subject.
55
+ * The clip rides as one more reference video ({@link seatCharacterVideos}),
56
+ * so it is measured, capped and priced exactly as a reference video is; its
57
+ * own length must fit `VIDEO_CHARACTER_CLIP_DURATION_LIMITS`. Any other model
58
+ * refuses it.
59
+ */
60
+ videoUrl?: string
51
61
  }
52
62
 
53
63
  /** Zod `.max()` ceiling for the wire field — the widest cap any provider declares. */
@@ -73,6 +83,144 @@ export function videoCharacterRefCap(provider: string | undefined): number {
73
83
  return provider ? (VIDEO_REF_LIMITS_BY_PROVIDER[provider]?.characters ?? 0) : 0
74
84
  }
75
85
 
86
+ /** How many characters may be VIDEO subjects (a `videoUrl` clip) on the provider; 0 = none. */
87
+ export function videoCharacterVideoCap(provider: string | undefined): number {
88
+ return provider ? (VIDEO_REF_LIMITS_BY_PROVIDER[provider]?.videoCharacters ?? 0) : 0
89
+ }
90
+
91
+ /** Every provider that takes video subjects, in declaration order. */
92
+ export function videoCharacterVideoProviders(): string[] {
93
+ return Object.entries(VIDEO_REF_LIMITS_BY_PROVIDER)
94
+ .filter(([, l]) => (l?.videoCharacters ?? 0) > 0)
95
+ .map(([id]) => id)
96
+ }
97
+
98
+ /** The clips a set of character references carries (`videoUrl`, trimmed, non-empty), in order. */
99
+ export function characterVideoUrls(
100
+ characterReferences: readonly unknown[] | undefined,
101
+ ): string[] {
102
+ const out: string[] = []
103
+ for (const c of characterReferences ?? []) {
104
+ const url = (c as { videoUrl?: unknown } | null | undefined)?.videoUrl
105
+ if (typeof url === "string" && url.trim()) out.push(url.trim())
106
+ }
107
+ return out
108
+ }
109
+
110
+ /**
111
+ * Whether the provider bills a character's video subject as reference-video
112
+ * seconds (`videoCharactersBillAsReferenceVideo`: Kling 4.0). On any other
113
+ * model that takes video subjects (Kling 4.0 Flash, measured, decided
114
+ * 2026-11-14) the subject is priced like an image subject.
115
+ */
116
+ export function videoCharacterClipsBilledAsReferenceVideo(provider: string | undefined): boolean {
117
+ return provider ? VIDEO_REF_LIMITS_BY_PROVIDER[provider]?.videoCharactersBillAsReferenceVideo === true : false
118
+ }
119
+
120
+ /**
121
+ * The reference videos a run is PRICED on: `referenceVideoUrls` as sent, less
122
+ * — on a model that does not bill video subjects as reference video
123
+ * ({@link videoCharacterClipsBilledAsReferenceVideo}) — the seats that are a
124
+ * character's clip. Those seats still count toward the model's video cap and
125
+ * the reference videos' total length (`seatCharacterVideos`, the duration
126
+ * check); they only leave the price. The same value when nothing leaves it.
127
+ * Every price path reads it: the routes' credit guard and `POST /v1/quote`,
128
+ * the workflow reservation, the estimates and the completion settlement.
129
+ */
130
+ export function pricedReferenceVideoUrls(args: {
131
+ provider: string | undefined
132
+ referenceVideoUrls: readonly unknown[] | undefined
133
+ characterReferences: readonly unknown[] | undefined
134
+ }): readonly unknown[] | undefined {
135
+ if (videoCharacterClipsBilledAsReferenceVideo(args.provider)) return args.referenceVideoUrls
136
+ const clips = new Set(characterVideoUrls(args.characterReferences))
137
+ if (clips.size === 0 || !args.referenceVideoUrls?.some((u) => typeof u === "string" && clips.has(u))) return args.referenceVideoUrls
138
+ return args.referenceVideoUrls.filter((u) => !(typeof u === "string" && clips.has(u)))
139
+ }
140
+
141
+ /** A refusal from {@link seatCharacterVideos}: a finished, user-facing sentence. */
142
+ export interface CharacterVideoSeatProblem {
143
+ code: "character_video_unsupported" | "character_videos_over_limit" | "character_video_shared" | "reference_videos_over_limit"
144
+ message: string
145
+ }
146
+
147
+ /**
148
+ * The reference-video list a run sends once its characters' clips are seated
149
+ * in it — the ONE rule both video routes (a precheck, before the duration
150
+ * check, the quote and any reservation) and the workflow run (the payload
151
+ * builder) apply, so a video subject's clip is measured, capped, priced, held
152
+ * and settled exactly as a reference video is (KIE bills video subjects as
153
+ * reference-video seconds, summed). The provider runner then takes the seat
154
+ * back out of the reference videos and sends it as the character's subject.
155
+ *
156
+ * - No clip: the list as it came (the same value).
157
+ * - A clip already in the list (also wired as a plain reference video) keeps
158
+ * its seat, and becomes the subject only; any other is appended, in
159
+ * character order, after the reference videos.
160
+ * - Refused: a model that takes no video subjects; more clips than its
161
+ * `videoCharacters` cap; two characters with the same clip; reference
162
+ * videos plus clips over its `videos` cap (the provider counts both in one
163
+ * cap, and a clip past it would be neither measured nor sent).
164
+ * - On a model that takes video subjects (one shared cap), plain reference
165
+ * videos alone over that cap are refused too, instead of the extra ones
166
+ * being left out without a word (decided 2026-11-13). Any other model's
167
+ * list is not judged here.
168
+ */
169
+ export function seatCharacterVideos(args: {
170
+ provider: string | undefined
171
+ referenceVideoUrls: readonly unknown[] | undefined
172
+ characterReferences: readonly unknown[] | undefined
173
+ }):
174
+ | { ok: true; referenceVideoUrls: readonly unknown[] | undefined }
175
+ | ({ ok: false } & CharacterVideoSeatProblem) {
176
+ const clips = characterVideoUrls(args.characterReferences)
177
+ const provider = args.provider ?? "the selected model"
178
+ const cap = videoCharacterVideoCap(args.provider)
179
+ const videosCap = VIDEO_REF_LIMITS_BY_PROVIDER[args.provider as string]?.videos ?? 0
180
+ const overVideos = (count: number): { ok: false } & CharacterVideoSeatProblem => ({
181
+ ok: false,
182
+ code: "reference_videos_over_limit",
183
+ message:
184
+ `${provider} takes at most ${videosCap} videos in all — reference videos and characters made from a video together. ` +
185
+ `This run has ${count}. Remove a reference video${clips.length > 0 ? ", or the video from a character" : ""}.`,
186
+ })
187
+ if (clips.length === 0) {
188
+ const sent = (args.referenceVideoUrls ?? []).length
189
+ if (cap > 0 && sent > videosCap) return overVideos(sent)
190
+ return { ok: true, referenceVideoUrls: args.referenceVideoUrls }
191
+ }
192
+ if (cap === 0) {
193
+ const takers = videoCharacterVideoProviders()
194
+ return {
195
+ ok: false,
196
+ code: "character_video_unsupported",
197
+ message:
198
+ `A character video (characterReferences[].videoUrl) is not supported by ${provider}. ` +
199
+ `Models that take one: ${takers.join(", ")}. Otherwise drop the video and keep the character's images.`,
200
+ }
201
+ }
202
+ if (clips.length > cap) {
203
+ return {
204
+ ok: false,
205
+ code: "character_videos_over_limit",
206
+ message: `${provider} takes at most ${cap} characters made from a video; ${clips.length} characters carry one. Remove the video from some of them.`,
207
+ }
208
+ }
209
+ if (new Set(clips).size < clips.length) {
210
+ return {
211
+ ok: false,
212
+ code: "character_video_shared",
213
+ message: "Two characters carry the same video. Each character made from a video needs a clip of its own.",
214
+ }
215
+ }
216
+ // The list as sent stays as it is (an entry the route's schema would refuse
217
+ // is still there for it to refuse); the clips follow it.
218
+ const raw = args.referenceVideoUrls ?? []
219
+ const seated: unknown[] = [...raw, ...clips.filter((c) => !raw.includes(c))]
220
+ if (seated.length > videosCap) return overVideos(seated.length)
221
+ return { ok: true, referenceVideoUrls: seated }
222
+ }
223
+
76
224
  /** How many DISTINCT voice personas the provider takes per request; 0 = none. */
77
225
  export function videoCharacterVoiceCap(provider: string | undefined): number {
78
226
  return provider ? (VIDEO_REF_LIMITS_BY_PROVIDER[provider]?.voices ?? 0) : 0
@@ -278,13 +426,21 @@ export function videoCharacterRefProblem(args: {
278
426
  * image still yields a reference — the provider decides (Kling keeps it a
279
427
  * reference image).
280
428
  */
281
- export function characterReferencesFromWired(refs: readonly ConnectedReference[]): VideoCharacterReference[] {
282
- const bySlug = new Map<string, { name: string; description?: string; urls: string[] }>()
429
+ export function characterReferencesFromWired(
430
+ refs: readonly ConnectedReference[],
431
+ /**
432
+ * The clip each wired character carries, by its slug (`wiredCharacterVideoUrls`):
433
+ * pass it only for a model that takes video subjects. Absent = none.
434
+ */
435
+ videoBySlug?: ReadonlyMap<string, string>,
436
+ ): VideoCharacterReference[] {
437
+ const bySlug = new Map<string, { name: string; description?: string; urls: string[]; videoUrl?: string }>()
283
438
  for (const r of refs) {
284
439
  if (r.source !== "wired-character" || !r.characterSlug || !r.url) continue
285
440
  let entry = bySlug.get(r.characterSlug)
286
441
  if (!entry) {
287
- entry = { name: r.defaultName.split(" / ")[0]!.trim() || r.characterSlug, urls: [] }
442
+ const videoUrl = videoBySlug?.get(r.characterSlug)
443
+ entry = { name: r.defaultName.split(" / ")[0]!.trim() || r.characterSlug, urls: [], ...(videoUrl ? { videoUrl } : {}) }
288
444
  bySlug.set(r.characterSlug, entry)
289
445
  }
290
446
  const description = (r.characterCanonicalDescription ?? r.description)?.trim()
@@ -299,5 +455,6 @@ export function characterReferencesFromWired(refs: readonly ConnectedReference[]
299
455
  ...(c.urls.length > 1 ? { extraImageUrls: c.urls.slice(1, 1 + VIDEO_CHARACTER_EXTRA_IMAGES_MAX) } : {}),
300
456
  description: (c.description ?? c.name).slice(0, VIDEO_CHARACTER_DESCRIPTION_MAX),
301
457
  name: c.name.slice(0, VIDEO_CHARACTER_NAME_MAX),
458
+ ...(c.videoUrl ? { videoUrl: c.videoUrl } : {}),
302
459
  }))
303
460
  }