@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
@@ -42,9 +42,26 @@ import {
42
42
  type VideoAudioRequest,
43
43
  canonicalVideoProvider,
44
44
  isTailExtendProvider,
45
+ isPixverseExtendProvider,
46
+ PIXVERSE_V6_EXTEND_PROVIDER,
47
+ isGrokExtendProvider,
48
+ isGrokExtendSourceModel,
49
+ GROK_EXTEND_PROVIDER,
50
+ type CatalogExtendProvider,
45
51
  type SeedanceExtendProvider,
46
52
  type TailExtendProvider,
47
53
  } from "./model-constants.js"
54
+ import {
55
+ SEEDANCE_EXTEND_CONTEXT_MAX_SEC,
56
+ SEEDANCE_EXTEND_RATE_CREDIT_IDS,
57
+ SEEDANCE_EXTEND_SENT_PRICED_PROVIDER,
58
+ isSeedanceExtendPricedBySecondsSent,
59
+ seedanceExtendAddedSec,
60
+ seedanceExtendRefusesSource,
61
+ seedanceExtendSentSec,
62
+ seedanceExtendUnits,
63
+ } from "./seedance-extend-rate.js"
64
+ import { unitQuoteCreditId } from "./credit-estimators/unit-quote.js"
48
65
  import { isFlux2Model, FLUX2_RES_MP, type Flux2Model } from "./flux2-pricing.js"
49
66
  import {
50
67
  GPT_IMAGE_2_6_DEFAULT_QUALITY,
@@ -59,6 +76,7 @@ import {
59
76
  type ImageFormatLevers,
60
77
  } from "./gpt-image-2-6.js"
61
78
  import { isMinimaxH3Image, minimaxH3ImageCreditId } from "./minimax-h3-image.js"
79
+ import { flux3KleinCreditId, isFlux3Klein } from "./flux-3-klein.js"
62
80
  import {
63
81
  SEEDREAM_5_5_I2I,
64
82
  SEEDREAM_5_5_MAX_INPUT_IMAGES,
@@ -210,6 +228,11 @@ export function buildCreditModelIdentifier(
210
228
  if (isSeedream55(provider)) {
211
229
  return seedream55CreditId(provider, resolution, referenceImageCount)
212
230
  }
231
+ // FLUX 3 Klein: by size alone, the same on both ids (`flux-3-klein:2K`,
232
+ // `flux-3-klein-i2i:4K`); images move a text-to-image id onto the edit id.
233
+ if (isFlux3Klein(provider)) {
234
+ return flux3KleinCreditId(provider, resolution, referenceImageCount)
235
+ }
213
236
  if (HIGH_QUALITY_PROVIDERS.has(provider) && quality === "high") {
214
237
  return `${provider}:high`
215
238
  }
@@ -532,9 +555,16 @@ export function buildVideoCreditModelIdentifier(
532
555
  // A retired model (RETIRED_VIDEO_PROVIDERS) is priced as the model it runs as.
533
556
  const provider = canonicalVideoProvider(rawProvider) as string
534
557
  // A tail-recipe Extend Video provider (Seedance 2.5 / 2.0, Kling 4) is
535
- // priced on its own rows — the one builder every surface that prices an
536
- // extend reads.
558
+ // priced through the one builder every surface that prices an extend reads
559
+ // (Seedance 2.5: the most a run of that length costs, the whole 10-second
560
+ // window sent — see tailExtendCreditId).
537
561
  if (isTailExtendProvider(provider)) return tailExtendCreditId(provider, duration, resolution)
562
+ // PixVerse V6 Extend on its own rows too, its sound read from the extend's
563
+ // own switch (`generateAudio`), else the request's `sound`.
564
+ if (isPixverseExtendProvider(provider)) return pixverseExtendCreditId(duration, resolution, audio.generateAudio ?? audio.sound)
565
+ // Grok Extend is priced at its SOURCE's resolution, which only its source
566
+ // check knows: a resolution handed here is never read, so the dearer row.
567
+ if (isGrokExtendProvider(provider)) return grokExtendCreditId(duration)
538
568
  // T2V overrides: some providers have different base costs for text-to-video
539
569
  let effectiveProvider = provider
540
570
  if (nodeType === "text-to-video") {
@@ -787,29 +817,265 @@ export function tailExtendResolution(provider: TailExtendProvider, resolution?:
787
817
  }
788
818
 
789
819
  /**
790
- * The credit identifier one tail-recipe Extend Video run is priced at — the
791
- * one builder every surface that prices it reads (the route's guard and
792
- * reservation, the workflow reservation and estimate, the editor), so none of
793
- * them can name a different row.
820
+ * The rate row a Seedance 2.5 Extend run at `resolution` is charged a multiple
821
+ * of: the row of the resolution the run is priced and rendered at
822
+ * ({@link tailExtendResolution}: one the model offers, else 720p).
823
+ */
824
+ export function seedanceExtendRateCreditId(resolution: unknown): string {
825
+ const res = tailExtendResolution(SEEDANCE_EXTEND_SENT_PRICED_PROVIDER, resolution) as keyof typeof SEEDANCE_EXTEND_RATE_CREDIT_IDS
826
+ return SEEDANCE_EXTEND_RATE_CREDIT_IDS[res] ?? SEEDANCE_EXTEND_RATE_CREDIT_IDS["720p"]
827
+ }
828
+
829
+ /**
830
+ * The ONE id a Seedance 2.5 Extend run on a known source is charged: the
831
+ * whole-run quote (`<rate row>:<units>u`, {@link unitQuoteCreditId}) of that
832
+ * run, which the price lookups (`GET /v1/credits/model-cost`,
833
+ * `POST /v1/credits/model-costs`) answer with exactly what the run is charged.
834
+ *
835
+ * The units are (seconds sent + seconds added) ÷ 2, by the rule the server
836
+ * charges a run by (seedance-extend-rate.ts): the seconds sent are the
837
+ * source's last {@link SEEDANCE_EXTEND_CONTEXT_MAX_SEC} seconds, or all of a
838
+ * shorter source, its picture's length read by the container-overhang rule
839
+ * (`CONTAINER_OVERHANG_SEC`: 8.04 s counts as 8 s, 8.3 s as 8.3 s); the seconds
840
+ * added snap into the catalog window as {@link tailExtendCreditId} reads them.
841
+ *
842
+ * @param sourcePictureSec the source's measured picture length, in seconds.
843
+ * Not known or unreadable (undefined, null, not a positive finite number):
844
+ * the whole window is counted — {@link seedanceExtendFullWindowCreditId},
845
+ * the most a run of that length costs.
846
+ * @param duration the seconds added (the request's `duration`).
847
+ * @param resolution the request's resolution (one the model does not offer is 720p).
848
+ * @returns the id, or `undefined` for a source the extend refuses: a measured
849
+ * picture shorter than the shortest source it takes
850
+ * (`SEEDANCE_2_R2V_MIN_REF_VIDEO_SEC`, 1.8 s, compared as measured, as the
851
+ * route and the worker compare it), whatever the seconds added. No run on
852
+ * such a source is made or charged, so there is no price to name.
853
+ */
854
+ export function seedanceExtendSourceCreditId(
855
+ sourcePictureSec: number | null | undefined,
856
+ duration?: number | string,
857
+ resolution?: unknown,
858
+ ): string | undefined {
859
+ if (seedanceExtendRefusesSource(sourcePictureSec)) return undefined
860
+ return seedanceExtendWholeRunCreditId(seedanceExtendSentSec(sourcePictureSec), duration, resolution)
861
+ }
862
+
863
+ /** The whole-run quote of a Seedance 2.5 Extend run that sends `sentSec` and adds `duration` at `resolution`. */
864
+ function seedanceExtendWholeRunCreditId(sentSec: number, duration: number | string | undefined, resolution: unknown): string {
865
+ const units = seedanceExtendUnits(sentSec, seedanceExtendAddedSec(SEEDANCE_EXTEND_SENT_PRICED_PROVIDER, duration))
866
+ return unitQuoteCreditId(seedanceExtendRateCreditId(resolution), units)
867
+ }
868
+
869
+ /**
870
+ * The most a Seedance 2.5 Extend run that adds `duration` seconds at
871
+ * `resolution` can cost, as ONE id: the whole-run quote
872
+ * (`<rate row>:<units>u`, {@link unitQuoteCreditId}) of a run that sends the
873
+ * whole {@link SEEDANCE_EXTEND_CONTEXT_MAX_SEC}-second window — the units are
874
+ * (10 + the seconds added) ÷ 2. A run sends at most that window, so this is
875
+ * never below what a run of that length is charged; the price lookups answer
876
+ * it at the rate row's current price. A client that knows the source names
877
+ * its run exactly with {@link seedanceExtendSourceCreditId}; this is that id
878
+ * for a source not known.
879
+ *
880
+ * The seconds added snap into the catalog window exactly as
881
+ * {@link tailExtendCreditId} reads them for every tail-recipe provider.
882
+ */
883
+ export function seedanceExtendFullWindowCreditId(duration?: number | string, resolution?: unknown): string {
884
+ return seedanceExtendWholeRunCreditId(seedanceExtendSentSec(undefined), duration, resolution)
885
+ }
886
+
887
+ /**
888
+ * The credit identifier a client prices one tail-recipe Extend Video run at —
889
+ * the one builder every surface that prices it reads (the route's guard and
890
+ * reservation, the workflow reservation and estimate, the editor, and every
891
+ * client of this package), so none of them can name a different row.
794
892
  *
795
893
  * The seconds added snap into the provider's catalog `durations` (its catalog
796
894
  * `defaultDuration` when unset, through {@link pricedOutputDurationSec}); the
797
- * resolution is {@link tailExtendResolution}'s. Each provider has its own
798
- * rows, one per second of its window and resolution: `<provider>:<N>s:<res>`
799
- * (`seedance-2-5-extend` 4–30 s, `seedance-2-0-extend` 4–15 s, both at
800
- * 480p / 720p / 1080p; `kling-4-extend` 3–30 s at 720p / 1080p).
895
+ * resolution is {@link tailExtendResolution}'s.
896
+ * - Seedance 2.0 Extend (4–15 s) and Kling 4 Extend (3–30 s): their own rows,
897
+ * one per second of the window and resolution, `<provider>:<N>s:<res>`
898
+ * (480p / 720p / 1080p; Kling 4 720p / 1080p) — the price a run is charged.
899
+ * - Seedance 2.5 Extend (4–30 s) is charged per second it sends and adds, and
900
+ * how much it sends depends on the source: this names the most a run of
901
+ * that length costs, the whole 10-second window sent
902
+ * ({@link seedanceExtendFullWindowCreditId},
903
+ * `seedance-2-5-extend:<res>:per-2s:<units>u`). A client that knows the
904
+ * source names the run's own id with {@link seedanceExtendSourceCreditId}.
801
905
  *
802
906
  * A retired id (`seedance-2-extend`) is not a {@link TailExtendProvider}:
803
- * pass a stored or sent provider through `canonicalVideoProvider` first.
907
+ * pass a stored or sent provider through `canonicalVideoProvider` first
908
+ * ({@link buildVideoCreditModelIdentifier} does).
804
909
  */
805
910
  export function tailExtendCreditId(
806
911
  provider: TailExtendProvider,
807
912
  duration?: number | string,
808
913
  resolution?: string,
809
914
  ): string {
915
+ if (isSeedanceExtendPricedBySecondsSent(provider)) return seedanceExtendFullWindowCreditId(duration, resolution)
810
916
  return `${provider}:${pricedOutputDurationSec(provider, duration)}s:${tailExtendResolution(provider, resolution)}`
811
917
  }
812
918
 
919
+ /** PixVerse V6 Extend's qualities, ascending: its catalog `resolutions`. */
920
+ type PixverseExtendQuality = "360p" | "540p" | "720p" | "1080p"
921
+
922
+ /** The quality a PixVerse V6 Extend that names none, or one it cannot map, is priced and run at. */
923
+ const PIXVERSE_EXTEND_DEFAULT_QUALITY: PixverseExtendQuality = "720p"
924
+
925
+ /**
926
+ * The quality a PixVerse V6 Extend run is priced at, and so the one it must
927
+ * render at: a quality it offers (360p / 540p / 720p / 1080p) as asked; 480p —
928
+ * the lowest the other extends render, which PixVerse does not — at the
929
+ * nearest it offers, 540p; anything else, or none, at 720p. The route refuses
930
+ * 480p and every other value it does not offer; a saved node, a quick-strip
931
+ * switch or a workflow written elsewhere carrying one runs, and is priced, at
932
+ * this quality instead.
933
+ */
934
+ export function pixverseExtendQuality(resolution?: unknown): PixverseExtendQuality {
935
+ if (resolution === "480p") return "540p"
936
+ return typeof resolution === "string" && MODEL_CATALOG[PIXVERSE_V6_EXTEND_PROVIDER]?.resolutions?.includes(resolution)
937
+ ? (resolution as PixverseExtendQuality)
938
+ : PIXVERSE_EXTEND_DEFAULT_QUALITY
939
+ }
940
+
941
+ /**
942
+ * The credit identifier one PixVerse V6 Extend run is priced at:
943
+ * `pixverse-v6-extend:<N>s:<quality>`, `:audio` appended with sound. The
944
+ * seconds added snap into its catalog `durations` (1–15, its default 5 when
945
+ * unset, {@link pricedOutputDurationSec}); the quality is
946
+ * {@link pixverseExtendQuality}'s; the sound is on unless `generateAudio` is
947
+ * `false` (the editor's sound switch shows it on until it is turned off).
948
+ */
949
+ export function pixverseExtendCreditId(duration?: number | string, resolution?: unknown, generateAudio?: boolean): string {
950
+ const seconds = pricedOutputDurationSec(PIXVERSE_V6_EXTEND_PROVIDER, duration)
951
+ return `${PIXVERSE_V6_EXTEND_PROVIDER}:${seconds}s:${pixverseExtendQuality(resolution)}${generateAudio === false ? "" : ":audio"}`
952
+ }
953
+
954
+ /**
955
+ * The resolution a catalog Extend Video run ({@link CatalogExtendProvider}) is
956
+ * priced at, and so renders at: a tail recipe's {@link tailExtendResolution},
957
+ * PixVerse V6's {@link pixverseExtendQuality}.
958
+ */
959
+ export function catalogExtendResolution(provider: CatalogExtendProvider, resolution?: unknown): string {
960
+ return isPixverseExtendProvider(provider) ? pixverseExtendQuality(resolution) : tailExtendResolution(provider, resolution)
961
+ }
962
+
963
+ /**
964
+ * The credit identifier one catalog Extend Video run is priced at — the one
965
+ * builder every surface that prices one reads (the route's guard and
966
+ * reservation, the workflow reservation and estimate, the editor): a tail
967
+ * recipe's {@link tailExtendCreditId} (no sound switch is priced there), and
968
+ * PixVerse V6's {@link pixverseExtendCreditId}.
969
+ */
970
+ export function catalogExtendCreditId(
971
+ provider: CatalogExtendProvider,
972
+ duration?: number | string,
973
+ resolution?: string,
974
+ generateAudio?: boolean,
975
+ ): string {
976
+ return isPixverseExtendProvider(provider)
977
+ ? pixverseExtendCreditId(duration, resolution, generateAudio)
978
+ : tailExtendCreditId(provider, duration, resolution)
979
+ }
980
+
981
+ /** The source resolutions Grok Extend is priced at (one row each per length added). */
982
+ export type GrokExtendSourceResolution = "480p" | "720p"
983
+
984
+ /**
985
+ * The seconds a Grok Extend run adds for a requested `duration`: 6 or 10 as
986
+ * asked, its default 6 when unset or unreadable, any other length snapped to
987
+ * the nearer of the two ({@link pricedOutputDurationSec} on its catalog
988
+ * `durations`). The route refuses any other length; a saved node, a quick-strip
989
+ * switch or a workflow written elsewhere runs, and is priced, at this one.
990
+ */
991
+ export function grokExtendSeconds(duration: unknown): number {
992
+ const requested = typeof duration === "number" || typeof duration === "string" ? duration : undefined
993
+ return pricedOutputDurationSec(GROK_EXTEND_PROVIDER, requested)
994
+ }
995
+
996
+ /**
997
+ * The credit identifier one Grok Extend run is priced at:
998
+ * `grok-extend:<6|10>s:<480p|720p>`. The resolution is the SOURCE's — what
999
+ * Grok bills an extension at — as the source check answers it (the route's
1000
+ * hold, the workflow hold); never a resolution the request names. Anything but
1001
+ * `480p` (a source not known yet, an estimate) is priced at the dearer 720p
1002
+ * row, so a quote never falls below the charge.
1003
+ */
1004
+ export function grokExtendCreditId(duration?: unknown, sourceResolution?: unknown): string {
1005
+ const resolution: GrokExtendSourceResolution = sourceResolution === "480p" ? "480p" : "720p"
1006
+ return `${GROK_EXTEND_PROVIDER}:${grokExtendSeconds(duration)}s:${resolution}`
1007
+ }
1008
+
1009
+ /** The video node types whose run Grok Extend can extend, set to a Grok Imagine model. */
1010
+ const GROK_EXTEND_SOURCE_NODE_TYPES: ReadonlySet<string> = new Set(["generate-video", "text-to-video", "image-to-video"])
1011
+
1012
+ /**
1013
+ * The resolution a Grok Extend is quoted at from the clip a Grok Imagine node
1014
+ * already made — the clip the run extends: the take its task (`kieTaskId`, the
1015
+ * task the node hands on) names. The charge reads the resolution the source's
1016
+ * JOB recorded (`input_data.resolution`; with none, the KIE config's pin, else
1017
+ * Grok's own 480p default — `sourceResolution` in grok-extend-source.ts), and
1018
+ * every lane that lands a take records that value on the result row beside
1019
+ * the task (`recordedResolution`), so the quote reads the same fact: `480p`
1020
+ * (any case) → `480p`; anything else, or none → `720p`, never below the charge
1021
+ * — a take with no recorded value may have been charged at a pinned 720p. Also
1022
+ * `720p` when no result names the node's task (a result landed before results
1023
+ * recorded it, or the take was deleted while the node kept its task).
1024
+ * Undefined when the node holds neither a task nor a result (it has not run).
1025
+ */
1026
+ function grokMadeClipResolution(data: Record<string, unknown>): GrokExtendSourceResolution | undefined {
1027
+ const rows = (Array.isArray(data.generatedResults) ? (data.generatedResults as ReadonlyArray<unknown>) : []).filter(
1028
+ (r): r is Record<string, unknown> =>
1029
+ typeof r === "object" && r !== null && typeof (r as { url?: unknown }).url === "string" && (r as { url: string }).url.trim() !== "",
1030
+ )
1031
+ const task = typeof data.kieTaskId === "string" && data.kieTaskId.trim() !== "" ? data.kieTaskId.trim() : undefined
1032
+ if (task === undefined && rows.length === 0) return undefined
1033
+ const named = task !== undefined ? rows.find((r) => typeof r.kieTaskId === "string" && r.kieTaskId.trim() === task) : undefined
1034
+ const recorded = typeof named?.recordedResolution === "string" ? named.recordedResolution.trim().toLowerCase() : undefined
1035
+ return recorded === "480p" ? "480p" : "720p"
1036
+ }
1037
+
1038
+ /**
1039
+ * The source resolution a Grok Extend node is QUOTED at (its estimate, its
1040
+ * editor price), read off the node wired into its `video` input — `480p` only
1041
+ * when the clip the extension continues is surely 480p; `720p`, the dearer
1042
+ * row, for anything else (nothing wired, another model, a clip whose
1043
+ * resolution is not known):
1044
+ *
1045
+ * - a Grok Imagine video node (text- or image-to-video) that already made a
1046
+ * clip and does not make a new one in the quoted run: THAT clip's
1047
+ * resolution ({@link grokMadeClipResolution}) — the run extends it, whatever
1048
+ * the node is set to now;
1049
+ * - one that has not run yet, or runs again in the quoted run (it is in
1050
+ * `rerunIds` and not frozen): its setting — `480p` when set so, which every
1051
+ * mode sends as set; unset, Grok may render it at either.
1052
+ *
1053
+ * `rerunIds`: the nodes the quoted run executes — empty for one node's own
1054
+ * price (its pill, its Run button), where nothing upstream runs again. The
1055
+ * run is held and charged at the source's own row, read off its job.
1056
+ */
1057
+ export function grokExtendWiredSourceResolution(
1058
+ nodeId: string | undefined,
1059
+ nodes: ReadonlyArray<{ readonly id?: string; readonly type?: string; readonly data?: unknown }>,
1060
+ edges: ReadonlyArray<{ readonly source?: string; readonly target?: string; readonly targetHandle?: string | null }> | undefined,
1061
+ rerunIds: ReadonlySet<string> = new Set(),
1062
+ ): GrokExtendSourceResolution {
1063
+ if (nodeId === undefined || !edges) return "720p"
1064
+ const sources = edges
1065
+ .filter((e) => e.target === nodeId && (e.targetHandle == null || e.targetHandle === "video"))
1066
+ .map((e) => nodes.find((n) => n.id !== undefined && n.id === e.source))
1067
+ if (sources.length === 0) return "720p"
1068
+ const surely480p = sources.every((n) => {
1069
+ const data = (n?.data ?? {}) as Record<string, unknown>
1070
+ if (n?.type === undefined || !GROK_EXTEND_SOURCE_NODE_TYPES.has(n.type) || !isGrokExtendSourceModel(data.provider)) return false
1071
+ const runsAgain = n.id !== undefined && rerunIds.has(n.id) && data.skipped !== true
1072
+ const made = runsAgain ? undefined : grokMadeClipResolution(data)
1073
+ if (made !== undefined) return made === "480p"
1074
+ return typeof data.resolution === "string" && data.resolution.trim().toLowerCase() === "480p"
1075
+ })
1076
+ return surely480p ? "480p" : "720p"
1077
+ }
1078
+
813
1079
  /** @deprecated Use {@link tailExtendResolution}, which also answers for Kling 4 Extend. */
814
1080
  export function seedanceExtendResolution(provider: SeedanceExtendProvider, resolution?: unknown): string {
815
1081
  return tailExtendResolution(provider, resolution)
@@ -1108,8 +1374,8 @@ export function speakerViewCreditId(quality: unknown, tier?: unknown): SpeakerVi
1108
1374
  * satisfies the B3 egress invariant.
1109
1375
  *
1110
1376
  * The version → key map is {@link SUNO_VERSION_CREDIT_KEYS}; a version with no
1111
- * entry (V4 / V4_5 / V4_5ALL / V4_5PLUS) falls back to the operation key, and a
1112
- * non-version-priced operation is returned unchanged.
1377
+ * entry (V4) falls back to the operation key, and a non-version-priced
1378
+ * operation is returned unchanged.
1113
1379
  */
1114
1380
  export function sunoCreditType(model: string | undefined, operation: string): string {
1115
1381
  if (!(SUNO_VERSION_PRICED_OPERATIONS as readonly string[]).includes(operation)) {
@@ -1132,4 +1398,9 @@ export const SUNO_VERSION_CREDIT_KEYS: Readonly<Record<string, string>> = {
1132
1398
  V6_MINI: "suno-v6_mini",
1133
1399
  V5_5: "suno-v5_5",
1134
1400
  V5: "suno-v5",
1401
+ // Their own rows since 2026-11-12, at the price their runs were charged
1402
+ // under the operation's row before.
1403
+ V4_5PLUS: "suno-v4_5plus",
1404
+ V4_5ALL: "suno-v4_5all",
1405
+ V4_5: "suno-v4_5",
1135
1406
  }
@@ -4,13 +4,15 @@
4
4
  *
5
5
  * The dialogue models carry a `tts` sheet in `MODEL_CATALOG` like the
6
6
  * text-to-speech models, but each lane answers only for its own models: the
7
- * text-to-speech lookups (`tts-capabilities.ts`) treat a dialogue id as unknown,
8
- * and these treat a text-to-speech id as unknown. An unknown id here runs as
7
+ * text-to-speech lookups (`tts-capabilities.ts`) treat a dialogue-only id as
8
+ * unknown, and these treat a text-to-speech-only id as unknown (a model in both
9
+ * lanes — Gemini — has one sheet, read by either). An unknown id here runs as
9
10
  * {@link DEFAULT_DIALOGUE_PROVIDER} (v3 dialogue) — not as the text-to-speech
10
11
  * fallback (turbo), which has no dialogue form.
11
12
  */
12
13
  import { MODEL_CATALOG, type TtsCapabilities, type TtsSettingLever } from "./model-catalog.js"
13
- import { DEFAULT_DIALOGUE_PROVIDER, type DialogueProvider } from "./model-constants.js"
14
+ import { DEFAULT_DIALOGUE_PROVIDER, DEFAULT_TTS_OUTPUT_FORMAT, TTS_OUTPUT_FORMATS, type DialogueProvider, type TtsOutputFormat } from "./model-constants.js"
15
+ import { replicaOf, ttsDirectionFor, ttsDirectionProblem, ttsReplicaProblem, ttsTakesReplica, ttsVoiceForModel, type TtsDirectionValues } from "./tts-capabilities.js"
14
16
 
15
17
  /** The sheet of a dialogue model, or `undefined` when the id is not one. Own properties only; a non-string is unknown. */
16
18
  export function findDialogueCapabilities(provider: unknown): TtsCapabilities | undefined {
@@ -46,3 +48,218 @@ export function dialogueStabilityAccepted(provider: unknown, value: number): boo
46
48
  const steps = getDialogueCapabilities(provider).stabilitySteps
47
49
  return steps ? steps.includes(value) : true
48
50
  }
51
+
52
+ /** The ElevenLabs dialogue lane's own limit on distinct voices in one script (probed 2026-08-30: an 11th → 400). */
53
+ export const ELEVENLABS_DIALOGUE_MAX_VOICES = 10
54
+
55
+ /** The most speakers (distinct voices) one script on the dialogue model may have: its sheet's, else the ElevenLabs limit. */
56
+ export function dialogueMaxSpeakers(provider: unknown): number {
57
+ return getDialogueCapabilities(provider).dialogueSpeakers ?? ELEVENLABS_DIALOGUE_MAX_VOICES
58
+ }
59
+
60
+ /** The dialogue model adds filler words between two speakers on request (`TtsCapabilities.fillerWords`). */
61
+ export function dialogueTakesFillerWords(provider: unknown): boolean {
62
+ return getDialogueCapabilities(provider).fillerWords === true
63
+ }
64
+
65
+ /**
66
+ * Each line's voice on the dialogue model, when the model and the voices may
67
+ * have been chosen apart (a published app's Model card, a field mapping, the
68
+ * editor's model switch): the text-to-speech lane's `ttsVoiceForModel` rule,
69
+ * per speaker. A voice the model speaks stays. On a model with named voices
70
+ * (Gemini) every other voice moves onto one of its voices that the script does
71
+ * not use yet, its default first — so two speakers are never merged into one
72
+ * voice by the move. On an ElevenLabs model a voice only a named-voice model
73
+ * speaks becomes "" (the deployment's default voice). Returns the voices in
74
+ * line order.
75
+ */
76
+ export function dialogueVoicesForModel(provider: unknown, voices: readonly unknown[], speakers?: unknown): string[] {
77
+ const sheet = getDialogueCapabilities(provider)
78
+ const id = dialogueProviderOf(provider)
79
+ const named = sheet.voices
80
+ if (!named) return voices.map((v) => ttsVoiceForModel(id, v) ?? "")
81
+ // A speaker cloned for this request (`replica`) is the model's own voice too, on a model that clones;
82
+ // on any other model it is a foreign voice and moves (decided 2026-11-13: one rule, `dialogueReplicaVoices`).
83
+ const clones = dialogueReplicaVoices(id, speakers)
84
+ const own = (v: unknown): v is string => typeof v === "string" && (named.some((n) => n.id === v) || clones.has(v))
85
+ const used = new Set(voices.filter(own))
86
+ const pool = [sheet.defaultVoice, ...named.map((n) => n.id)].filter((v): v is string => typeof v === "string")
87
+ const moved = new Map<string, string>()
88
+ return voices.map((v) => {
89
+ if (own(v)) return v
90
+ const key = typeof v === "string" ? v : ""
91
+ const kept = moved.get(key)
92
+ if (kept !== undefined) return kept
93
+ const next = pool.find((p) => !used.has(p)) ?? sheet.defaultVoice ?? named[0]!.id
94
+ used.add(next)
95
+ moved.set(key, next)
96
+ return next
97
+ })
98
+ }
99
+
100
+ /**
101
+ * The most characters of the free-text style ONE LINE takes on the dialogue
102
+ * model (Gemini 3.8: `direction.styleMaxChars`, a style per turn), or
103
+ * undefined on a model whose style is a speaker's choice (3.1 / 2.5) or that
104
+ * takes none (ElevenLabs).
105
+ */
106
+ export function dialogueLineStyleMaxChars(provider: unknown): number | undefined {
107
+ const d = getDialogueCapabilities(provider).direction
108
+ return d && d.styles === undefined ? d.styleMaxChars : undefined
109
+ }
110
+
111
+ /** A line's style as the dialogue model is sent it: trimmed, when the model takes one per line and it fits; else undefined. */
112
+ export function dialogueLineStyleFor(provider: unknown, value: unknown): string | undefined {
113
+ const max = dialogueLineStyleMaxChars(provider)
114
+ if (max === undefined || typeof value !== "string") return undefined
115
+ const trimmed = value.trim()
116
+ return trimmed && trimmed.length <= max ? trimmed : undefined
117
+ }
118
+
119
+ /** Whether the dialogue model takes direction per SPEAKER (Gemini 3.1 / 2.5: a style, pace, accent and audio profile per voice). */
120
+ export function dialogueTakesSpeakerDirection(provider: unknown): boolean {
121
+ const d = getDialogueCapabilities(provider).direction
122
+ return d !== undefined && (d.styles !== undefined || d.paces !== undefined || d.accents !== undefined || d.audioProfileMaxChars !== undefined)
123
+ }
124
+
125
+ /** One speaker's direction as the dialogue model is sent it (`ttsDirectionFor`), or {} on a model that takes none per speaker. */
126
+ export function dialogueSpeakerDirectionFor(provider: unknown, values: Readonly<Record<string, unknown>>): TtsDirectionValues {
127
+ return dialogueTakesSpeakerDirection(provider) ? ttsDirectionFor(dialogueProviderOf(provider), values) : {}
128
+ }
129
+
130
+ /**
131
+ * The files the dialogue model delivers: every speech file format on a model
132
+ * that renders a WAV the platform keeps or encodes (Gemini,
133
+ * `dialogueAnyOutputFormat`); the default MP3 only on the ElevenLabs dialogue
134
+ * models, as the platform calls them.
135
+ */
136
+ export function dialogueOutputFormats(provider: unknown): readonly TtsOutputFormat[] {
137
+ return getDialogueCapabilities(provider).dialogueAnyOutputFormat ? TTS_OUTPUT_FORMATS : [DEFAULT_TTS_OUTPUT_FORMAT]
138
+ }
139
+
140
+ /** The file a dialogue request on `provider` asks for, when it is one the model delivers; else undefined (the default MP3). */
141
+ export function dialogueOutputFormatFor(provider: unknown, value: unknown): TtsOutputFormat | undefined {
142
+ return typeof value === "string" && (dialogueOutputFormats(provider) as readonly string[]).includes(value) ? (value as TtsOutputFormat) : undefined
143
+ }
144
+
145
+ /** A dialogue request as every lane reads it (the route's body, a node's data, the MCP verb's args mapped). */
146
+ export interface DialogueRequestShape {
147
+ readonly dialogue?: unknown
148
+ readonly speakers?: unknown
149
+ /** The file asked for; judged against `dialogueOutputFormats` when given. */
150
+ readonly outputFormat?: unknown
151
+ }
152
+
153
+ /** Why a dialogue request cannot run on its model: where, and the sentence a caller is answered with. */
154
+ export interface DialogueProblem {
155
+ readonly path: ReadonlyArray<string | number>
156
+ readonly message: string
157
+ }
158
+
159
+ /**
160
+ * The speakers a dialogue clones for this request: the voice labels whose
161
+ * `speakers` entry carries a `replica` (two https links), on a model that
162
+ * clones (`TtsCapabilities.replica`); none on any other. The ONE predicate
163
+ * every dialogue seam reads — the voice move, the check, the worker — so a
164
+ * cloned speaker is kept on a model that clones and never silently voiced by
165
+ * a stock voice in its place.
166
+ */
167
+ export function dialogueReplicaVoices(provider: unknown, speakers: unknown): Set<string> {
168
+ const id = dialogueProviderOf(provider)
169
+ if (!ttsTakesReplica(id) || !Array.isArray(speakers)) return new Set()
170
+ const out = new Set<string>()
171
+ for (const entry of speakers) {
172
+ const s = entry as { voice?: unknown; replica?: unknown } | null
173
+ if (s && typeof s.voice === "string" && s.voice && replicaOf(s.replica)) out.add(s.voice)
174
+ }
175
+ return out
176
+ }
177
+
178
+ /** A cloned speaker's recordings in a dialogue request, by voice label (`dialogueReplicaVoices`' speakers). */
179
+ export function dialogueReplicaOf(provider: unknown, speakers: unknown, voice: string): ReturnType<typeof replicaOf> {
180
+ if (!dialogueReplicaVoices(provider, speakers).has(voice) || !Array.isArray(speakers)) return undefined
181
+ const entry = speakers.find((s) => (s as { voice?: unknown } | null)?.voice === voice) as { replica?: unknown } | undefined
182
+ return replicaOf(entry?.replica)
183
+ }
184
+
185
+ /** The distinct voices of a script, in the order they first speak. */
186
+ export function dialogueVoicesOf(lines: unknown): string[] {
187
+ if (!Array.isArray(lines)) return []
188
+ const out: string[] = []
189
+ for (const line of lines) {
190
+ const voice = (line as { voice?: unknown } | null)?.voice
191
+ if (typeof voice === "string" && !out.includes(voice)) out.push(voice)
192
+ }
193
+ return out
194
+ }
195
+
196
+ /**
197
+ * The first reason a dialogue request cannot run on `provider`, or undefined.
198
+ * The ONE rule the route's schema, the workflow engine and the MCP verb read,
199
+ * so a script is refused the same way at every door and before any hold:
200
+ * at most `dialogueMaxSpeakers` distinct voices; on a model with named voices
201
+ * (Gemini) every voice one of them; a line's style within what the model takes
202
+ * per line; each speaker's direction within what the model takes per speaker.
203
+ * A field the model does not take is never sent, so it is no problem (as on
204
+ * one speaker: `ttsDirectionProblem`). The script's length is the caller's to
205
+ * judge (`dialogueTextBeforeCap`, @nodaro/prompts).
206
+ */
207
+ export function dialogueProblem(provider: unknown, request: DialogueRequestShape): DialogueProblem | undefined {
208
+ const id = dialogueProviderOf(provider)
209
+ const sheet = getDialogueCapabilities(id)
210
+ const lines = Array.isArray(request.dialogue) ? request.dialogue : []
211
+ // One entry per speaker: two entries for one voice would leave which one applies to chance.
212
+ if (Array.isArray(request.speakers)) {
213
+ const seen = new Set<string>()
214
+ for (let i = 0; i < request.speakers.length; i++) {
215
+ const voice = (request.speakers[i] as { voice?: unknown } | null)?.voice
216
+ if (typeof voice !== "string") continue
217
+ if (seen.has(voice)) return { path: ["speakers", i, "voice"], message: `speakers lists the voice "${voice}" more than once; give each speaker one entry` }
218
+ seen.add(voice)
219
+ }
220
+ }
221
+ const voices = dialogueVoicesOf(lines)
222
+ const max = dialogueMaxSpeakers(id)
223
+ if (voices.length > max) {
224
+ return { path: ["dialogue"], message: `A dialogue can use at most ${max} unique voices — reuse voices across lines or split the script into two nodes` }
225
+ }
226
+ // A one-off clone (`replica`) on a speaker: refused on a model that does not clone, never dropped.
227
+ if (Array.isArray(request.speakers)) {
228
+ for (let i = 0; i < request.speakers.length; i++) {
229
+ const replica = (request.speakers[i] as { replica?: unknown } | null)?.replica
230
+ const problem = ttsReplicaProblem(id, replica)
231
+ if (problem) return { path: ["speakers", i, "replica"], message: problem }
232
+ }
233
+ }
234
+ const clones = dialogueReplicaVoices(id, request.speakers)
235
+ const named = sheet.voices
236
+ if (named) {
237
+ for (let i = 0; i < lines.length; i++) {
238
+ const voice = (lines[i] as { voice?: unknown } | null)?.voice
239
+ if (typeof voice === "string" && !clones.has(voice) && !named.some((v) => v.id === voice)) {
240
+ return { path: ["dialogue", i, "voice"], message: `${voice} is not a voice of ${id}. Its voices: ${named.map((v) => v.id).join(", ")}` }
241
+ }
242
+ }
243
+ }
244
+ const styleMax = dialogueLineStyleMaxChars(id)
245
+ if (styleMax !== undefined) {
246
+ for (let i = 0; i < lines.length; i++) {
247
+ const style = (lines[i] as { styleDirection?: unknown } | null)?.styleDirection
248
+ if (style === undefined) continue
249
+ if (typeof style !== "string") return { path: ["dialogue", i, "styleDirection"], message: "styleDirection must be a string" }
250
+ if (style.trim().length > styleMax) return { path: ["dialogue", i, "styleDirection"], message: `styleDirection must be at most ${styleMax} characters` }
251
+ }
252
+ }
253
+ if (request.outputFormat !== undefined && dialogueOutputFormatFor(id, request.outputFormat) === undefined) {
254
+ return { path: ["outputFormat"], message: `outputFormat on ${id} must be one of: ${dialogueOutputFormats(id).join(", ")}` }
255
+ }
256
+ if (dialogueTakesSpeakerDirection(id) && Array.isArray(request.speakers)) {
257
+ for (let i = 0; i < request.speakers.length; i++) {
258
+ const speaker = request.speakers[i]
259
+ if (!speaker || typeof speaker !== "object") continue
260
+ const problem = ttsDirectionProblem(id, speaker as Record<string, unknown>)
261
+ if (problem) return { path: ["speakers", i, problem.field], message: problem.message }
262
+ }
263
+ }
264
+ return undefined
265
+ }