@nodaro/shared 3.64.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 (205) hide show
  1. package/dist/{chunk-PJJAZQVZ.js → chunk-222QM7CO.js} +3 -3
  2. package/dist/{chunk-PJJAZQVZ.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-TTGZ2L3O.js → chunk-2NKF476Z.js} +3 -3
  6. package/dist/{chunk-TTGZ2L3O.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-7AJGUI7L.cjs → chunk-5NVGKXJV.cjs} +34 -17
  10. package/dist/chunk-5NVGKXJV.cjs.map +1 -0
  11. package/dist/{chunk-3AYM47GW.js → chunk-5SSMPYE5.js} +99 -9
  12. package/dist/chunk-5SSMPYE5.js.map +1 -0
  13. package/dist/{chunk-KHH54GRP.cjs → chunk-6ET3KDO4.cjs} +15 -338
  14. package/dist/chunk-6ET3KDO4.cjs.map +1 -0
  15. package/dist/{chunk-ACZZHHFZ.cjs → chunk-6OSIOVF7.cjs} +44 -22
  16. package/dist/chunk-6OSIOVF7.cjs.map +1 -0
  17. package/dist/{chunk-OBOOHG3N.js → chunk-6X5PBAC4.js} +3 -3
  18. package/dist/{chunk-OBOOHG3N.js.map → chunk-6X5PBAC4.js.map} +1 -1
  19. package/dist/chunk-7BN4EDIC.cjs +185 -0
  20. package/dist/chunk-7BN4EDIC.cjs.map +1 -0
  21. package/dist/{chunk-IYSOVS7O.js → chunk-7OWXHW7Z.js} +31 -13
  22. package/dist/chunk-7OWXHW7Z.js.map +1 -0
  23. package/dist/{chunk-ZI3QDUHO.js → chunk-AT53ZQUC.js} +3 -3
  24. package/dist/{chunk-ZI3QDUHO.js.map → chunk-AT53ZQUC.js.map} +1 -1
  25. package/dist/{chunk-SHH2T4CR.js → chunk-BSTAAGLY.js} +3 -3
  26. package/dist/{chunk-SHH2T4CR.js.map → chunk-BSTAAGLY.js.map} +1 -1
  27. package/dist/{chunk-DZ4IOP3Q.js → chunk-CW6MMQNO.js} +277 -3
  28. package/dist/chunk-CW6MMQNO.js.map +1 -0
  29. package/dist/{chunk-Q2Y4JHF7.js → chunk-D5Y3EYRM.js} +5 -5
  30. package/dist/{chunk-Q2Y4JHF7.js.map → chunk-D5Y3EYRM.js.map} +1 -1
  31. package/dist/{chunk-EXEVT6D2.cjs → chunk-DQ2PARNH.cjs} +5 -5
  32. package/dist/{chunk-EXEVT6D2.cjs.map → chunk-DQ2PARNH.cjs.map} +1 -1
  33. package/dist/{chunk-OOZW2MM6.cjs → chunk-E66HSC2E.cjs} +9 -9
  34. package/dist/{chunk-OOZW2MM6.cjs.map → chunk-E66HSC2E.cjs.map} +1 -1
  35. package/dist/{chunk-NIAFR5EE.js → chunk-FGBGKBML.js} +32 -3
  36. package/dist/chunk-FGBGKBML.js.map +1 -0
  37. package/dist/{chunk-5OBTGNUQ.cjs → chunk-FI3HJZWM.cjs} +294 -2
  38. package/dist/chunk-FI3HJZWM.cjs.map +1 -0
  39. package/dist/{chunk-SPAHI7DY.cjs → chunk-FJZTQTF4.cjs} +4 -4
  40. package/dist/{chunk-SPAHI7DY.cjs.map → chunk-FJZTQTF4.cjs.map} +1 -1
  41. package/dist/{chunk-J6B7J73J.cjs → chunk-GJ3D5X4X.cjs} +49 -49
  42. package/dist/{chunk-J6B7J73J.cjs.map → chunk-GJ3D5X4X.cjs.map} +1 -1
  43. package/dist/{chunk-KB2SQAR3.js → chunk-H745DQ6V.js} +3 -3
  44. package/dist/{chunk-KB2SQAR3.js.map → chunk-H745DQ6V.js.map} +1 -1
  45. package/dist/{chunk-7KQ6W5DS.js → chunk-HAH2F7LT.js} +4 -4
  46. package/dist/{chunk-7KQ6W5DS.js.map → chunk-HAH2F7LT.js.map} +1 -1
  47. package/dist/{chunk-HDPJNNMF.cjs → chunk-JQMFJAYU.cjs} +21 -21
  48. package/dist/{chunk-HDPJNNMF.cjs.map → chunk-JQMFJAYU.cjs.map} +1 -1
  49. package/dist/{chunk-D4KWNDPH.cjs → chunk-JYU5EIRM.cjs} +12 -12
  50. package/dist/{chunk-D4KWNDPH.cjs.map → chunk-JYU5EIRM.cjs.map} +1 -1
  51. package/dist/{chunk-AZNZ5WNZ.cjs → chunk-K6RIN3LW.cjs} +142 -45
  52. package/dist/chunk-K6RIN3LW.cjs.map +1 -0
  53. package/dist/{chunk-YQV53HRR.cjs → chunk-KTCEKGBJ.cjs} +7 -7
  54. package/dist/{chunk-YQV53HRR.cjs.map → chunk-KTCEKGBJ.cjs.map} +1 -1
  55. package/dist/{chunk-W6VJAUGM.cjs → chunk-KWYS4IIM.cjs} +83 -37
  56. package/dist/chunk-KWYS4IIM.cjs.map +1 -0
  57. package/dist/{chunk-GTWUS6MQ.cjs → chunk-MIT2USTS.cjs} +61 -61
  58. package/dist/{chunk-GTWUS6MQ.cjs.map → chunk-MIT2USTS.cjs.map} +1 -1
  59. package/dist/{chunk-Y4GCJJPF.cjs → chunk-NYZQOIXJ.cjs} +35 -2
  60. package/dist/chunk-NYZQOIXJ.cjs.map +1 -0
  61. package/dist/{chunk-FHGRKQVZ.cjs → chunk-PGDR7CO3.cjs} +8 -8
  62. package/dist/{chunk-FHGRKQVZ.cjs.map → chunk-PGDR7CO3.cjs.map} +1 -1
  63. package/dist/{chunk-W7KHHNZR.js → chunk-PL7AQQV7.js} +53 -9
  64. package/dist/chunk-PL7AQQV7.js.map +1 -0
  65. package/dist/chunk-Q4YOLT4M.js +164 -0
  66. package/dist/chunk-Q4YOLT4M.js.map +1 -0
  67. package/dist/{chunk-CHS2SIP6.cjs → chunk-R5ILCNCC.cjs} +90 -76
  68. package/dist/chunk-R5ILCNCC.cjs.map +1 -0
  69. package/dist/chunk-RP4KQUNU.cjs +168 -0
  70. package/dist/chunk-RP4KQUNU.cjs.map +1 -0
  71. package/dist/{chunk-CHTZZRAL.cjs → chunk-SPU7MUWE.cjs} +6 -6
  72. package/dist/{chunk-CHTZZRAL.cjs.map → chunk-SPU7MUWE.cjs.map} +1 -1
  73. package/dist/{chunk-VPTA4Z7G.js → chunk-ST7OBB5J.js} +5 -5
  74. package/dist/{chunk-VPTA4Z7G.js.map → chunk-ST7OBB5J.js.map} +1 -1
  75. package/dist/{chunk-TPQJKS7D.js → chunk-V5NLQ4L5.js} +21 -7
  76. package/dist/{chunk-CHS2SIP6.cjs.map → chunk-V5NLQ4L5.js.map} +1 -1
  77. package/dist/{chunk-QYU7J5EQ.js → chunk-V6OXSXIX.js} +29 -18
  78. package/dist/chunk-V6OXSXIX.js.map +1 -0
  79. package/dist/{chunk-T2OVDF2M.cjs → chunk-WQMPIURW.cjs} +6 -6
  80. package/dist/{chunk-T2OVDF2M.cjs.map → chunk-WQMPIURW.cjs.map} +1 -1
  81. package/dist/{chunk-67CMMTLN.cjs → chunk-WZG6GZIL.cjs} +4 -4
  82. package/dist/{chunk-67CMMTLN.cjs.map → chunk-WZG6GZIL.cjs.map} +1 -1
  83. package/dist/{chunk-36VWLB4J.js → chunk-XJANKTIL.js} +3 -3
  84. package/dist/{chunk-36VWLB4J.js.map → chunk-XJANKTIL.js.map} +1 -1
  85. package/dist/{chunk-O7RZRUMZ.js → chunk-XJWED257.js} +14 -309
  86. package/dist/chunk-XJWED257.js.map +1 -0
  87. package/dist/chunk-XSSLNINL.js +346 -0
  88. package/dist/chunk-XSSLNINL.js.map +1 -0
  89. package/dist/{chunk-O4RPXBDZ.cjs → chunk-YD4XY74W.cjs} +8 -8
  90. package/dist/{chunk-O4RPXBDZ.cjs.map → chunk-YD4XY74W.cjs.map} +1 -1
  91. package/dist/{chunk-SXHHLZ22.js → chunk-YMZUE2IX.js} +9 -9
  92. package/dist/{chunk-SXHHLZ22.js.map → chunk-YMZUE2IX.js.map} +1 -1
  93. package/dist/{chunk-4IUE2JB7.js → chunk-Z77M7Q2R.js} +3 -3
  94. package/dist/{chunk-4IUE2JB7.js.map → chunk-Z77M7Q2R.js.map} +1 -1
  95. package/dist/{chunk-3KTWYYCN.js → chunk-ZSRXY5YT.js} +3 -3
  96. package/dist/{chunk-3KTWYYCN.js.map → chunk-ZSRXY5YT.js.map} +1 -1
  97. package/dist/entries/apps.cjs +42 -42
  98. package/dist/entries/apps.js +7 -7
  99. package/dist/entries/captions.d.cts +1 -1
  100. package/dist/entries/captions.d.ts +1 -1
  101. package/dist/entries/credits.cjs +230 -214
  102. package/dist/entries/credits.d.cts +51 -14
  103. package/dist/entries/credits.d.ts +51 -14
  104. package/dist/entries/credits.js +10 -10
  105. package/dist/entries/entities.cjs +202 -193
  106. package/dist/entries/entities.d.cts +44 -9
  107. package/dist/entries/entities.d.ts +44 -9
  108. package/dist/entries/entities.js +2 -1
  109. package/dist/entries/llm-models.cjs +86 -62
  110. package/dist/entries/llm-models.d.cts +46 -15
  111. package/dist/entries/llm-models.d.ts +46 -15
  112. package/dist/entries/llm-models.js +2 -2
  113. package/dist/entries/media.cjs +79 -63
  114. package/dist/entries/media.d.cts +154 -1
  115. package/dist/entries/media.d.ts +154 -1
  116. package/dist/entries/media.js +1 -1
  117. package/dist/entries/model-catalog.cjs +175 -119
  118. package/dist/entries/model-catalog.d.cts +4 -54
  119. package/dist/entries/model-catalog.d.ts +4 -54
  120. package/dist/entries/model-catalog.js +4 -4
  121. package/dist/entries/models.cjs +491 -358
  122. package/dist/entries/models.d.cts +86 -7
  123. package/dist/entries/models.d.ts +86 -7
  124. package/dist/entries/models.js +6 -5
  125. package/dist/entries/nodes.cjs +212 -212
  126. package/dist/entries/nodes.d.cts +1 -1
  127. package/dist/entries/nodes.d.ts +1 -1
  128. package/dist/entries/nodes.js +8 -8
  129. package/dist/entries/pipeline.cjs +153 -153
  130. package/dist/entries/pipeline.d.cts +3 -3
  131. package/dist/entries/pipeline.d.ts +3 -3
  132. package/dist/entries/pipeline.js +3 -3
  133. package/dist/entries/social.cjs +177 -177
  134. package/dist/entries/social.js +2 -2
  135. package/dist/entries/ugc.cjs +71 -71
  136. package/dist/entries/ugc.js +4 -4
  137. package/dist/entries/video.cjs +174 -145
  138. package/dist/entries/video.d.cts +114 -2
  139. package/dist/entries/video.d.ts +114 -2
  140. package/dist/entries/video.js +7 -6
  141. package/dist/entries/workflow.d.cts +1 -1
  142. package/dist/entries/workflow.d.ts +1 -1
  143. package/dist/index.cjs +2074 -1793
  144. package/dist/index.d.cts +10 -9
  145. package/dist/index.d.ts +10 -9
  146. package/dist/index.js +24 -23
  147. package/dist/{model-catalog-Cf9fkEUp.d.ts → model-catalog-BoUKGFNl.d.cts} +167 -1
  148. package/dist/{model-catalog-Cf9fkEUp.d.cts → model-catalog-BoUKGFNl.d.ts} +167 -1
  149. package/dist/{model-constants-BxjiWVQ9.d.ts → model-constants-BElS3AeE.d.ts} +55 -6
  150. package/dist/{model-constants-C_Nyft_i.d.cts → model-constants-CpQz1bGa.d.cts} +55 -6
  151. package/dist/tts-capabilities-BtnDWK9K.d.ts +133 -0
  152. package/dist/tts-capabilities-C52UccTI.d.cts +133 -0
  153. package/package.json +1 -1
  154. package/src/__tests__/dialogue-capabilities.test.ts +167 -6
  155. package/src/__tests__/extend-providers.test.ts +87 -0
  156. package/src/__tests__/kling4-catalog.test.ts +1 -1
  157. package/src/__tests__/llm-models.test.ts +41 -4
  158. package/src/__tests__/speech-pricing.test.ts +62 -1
  159. package/src/__tests__/tts-capabilities.test.ts +160 -4
  160. package/src/__tests__/video-analysis-pricing.test.ts +13 -1
  161. package/src/__tests__/video-subjects.test.ts +192 -0
  162. package/src/__tests__/wired-character-names.test.ts +142 -0
  163. package/src/credit-estimators/index.ts +4 -0
  164. package/src/credit-estimators/speech.ts +57 -9
  165. package/src/credit-identifiers.ts +48 -13
  166. package/src/dialogue-capabilities.ts +220 -3
  167. package/src/dubbing-structure.ts +186 -0
  168. package/src/entries/entities.ts +2 -0
  169. package/src/entries/llm-models.ts +7 -0
  170. package/src/entries/media.ts +3 -1
  171. package/src/entries/model-catalog.ts +17 -0
  172. package/src/entries/models.ts +39 -0
  173. package/src/entries/video.ts +8 -1
  174. package/src/gemini-tts.ts +144 -0
  175. package/src/llm-models.ts +71 -21
  176. package/src/model-catalog.ts +259 -0
  177. package/src/model-constants.ts +101 -8
  178. package/src/tts-capabilities.ts +193 -1
  179. package/src/video-analysis-pricing.ts +11 -0
  180. package/src/video-character-refs.ts +160 -3
  181. package/src/wired-character-names.ts +134 -18
  182. package/src/wired-character-video-subjects.ts +63 -0
  183. package/dist/chunk-3AYM47GW.js.map +0 -1
  184. package/dist/chunk-5OBTGNUQ.cjs.map +0 -1
  185. package/dist/chunk-6YIV37V7.js +0 -31
  186. package/dist/chunk-6YIV37V7.js.map +0 -1
  187. package/dist/chunk-7AJGUI7L.cjs.map +0 -1
  188. package/dist/chunk-ACZZHHFZ.cjs.map +0 -1
  189. package/dist/chunk-AZNZ5WNZ.cjs.map +0 -1
  190. package/dist/chunk-DZ4IOP3Q.js.map +0 -1
  191. package/dist/chunk-IYSOVS7O.js.map +0 -1
  192. package/dist/chunk-KHH54GRP.cjs.map +0 -1
  193. package/dist/chunk-NIAFR5EE.js.map +0 -1
  194. package/dist/chunk-O7RZRUMZ.js.map +0 -1
  195. package/dist/chunk-QYU7J5EQ.js.map +0 -1
  196. package/dist/chunk-S3UGLZSF.js +0 -42
  197. package/dist/chunk-S3UGLZSF.js.map +0 -1
  198. package/dist/chunk-TPQJKS7D.js.map +0 -1
  199. package/dist/chunk-TQW3R44P.cjs +0 -38
  200. package/dist/chunk-TQW3R44P.cjs.map +0 -1
  201. package/dist/chunk-VZ6TE23U.cjs +0 -54
  202. package/dist/chunk-VZ6TE23U.cjs.map +0 -1
  203. package/dist/chunk-W6VJAUGM.cjs.map +0 -1
  204. package/dist/chunk-W7KHHNZR.js.map +0 -1
  205. package/dist/chunk-Y4GCJJPF.cjs.map +0 -1
@@ -35,6 +35,19 @@ import { isAutoVideoDuration } from "./video-duration-auto.js"
35
35
  import type { DeclaredSeedanceTaskType } from "./seedance-task-type.js"
36
36
  import { SEEDREAM_5_5_DEFAULT_RESOLUTION, SEEDREAM_5_5_RESOLUTIONS } from "./seedream-5-5.js"
37
37
  import { FLUX_3_KLEIN_RESOLUTIONS } from "./flux-3-klein.js"
38
+ import {
39
+ GEMINI_3_1_DEFAULT_VOICE,
40
+ GEMINI_3_1_TTS_ACCENTS,
41
+ GEMINI_3_1_TTS_PACES,
42
+ GEMINI_3_1_TTS_STYLES,
43
+ GEMINI_3_1_TTS_VOICES,
44
+ GEMINI_3_8_DEFAULT_VOICE,
45
+ GEMINI_3_8_TONE_TAGS,
46
+ GEMINI_3_8_TTS_VOICES,
47
+ GEMINI_TTS_MAX_CHARS,
48
+ TTS_DIRECTION_MAX_CHARS,
49
+ type TtsNamedVoice,
50
+ } from "./gemini-tts.js"
38
51
 
39
52
  export type ModelKind = "image" | "video" | "audio"
40
53
 
@@ -108,6 +121,14 @@ export interface PriceVariant {
108
121
  */
109
122
  export const SPEECH_UNIT_PRICE_NOTE = "per started 100 characters, at least 8 units — where length pricing is on; a request costs at most its units × this"
110
123
 
124
+ /**
125
+ * The note on a speech model's `<model>:per-1k-chars` row (`TtsCapabilities.ratePer1kChars`):
126
+ * the same count as {@link SPEECH_UNIT_PRICE_NOTE} — started 100 characters, at
127
+ * least 8 units — quoted per 1,000, so a request costs its hundreds × this ÷ 10,
128
+ * rounded up once (the exact price of N hundreds is the `<model>:per-100-chars:<N>u` id).
129
+ */
130
+ export const SPEECH_PER_1K_PRICE_NOTE = "per 1,000 characters, counted in started 100s, at least 800 — where length pricing is on; a request costs its hundreds × this ÷ 10, rounded up"
131
+
111
132
  /** A voice-setting lever a speech model honours. */
112
133
  export type TtsSettingLever = "stability" | "similarity" | "style" | "speed" | "speakerBoost"
113
134
 
@@ -160,6 +181,81 @@ export interface TtsCapabilities {
160
181
  maxChars: number
161
182
  /** Languages offered in pickers (ISO 639-1; `fil` has no two-letter code). A curated list, not the vendor's full one. */
162
183
  languages: readonly string[]
184
+ /**
185
+ * The model speaks only these named voices, by wire name: a request's
186
+ * `voice` must be one of them (else a 400 before any hold), and none means
187
+ * `defaultVoice`. Absent ⇒ the ElevenLabs voices (premade, library, clones).
188
+ * A client offers this list in place of the ElevenLabs voice browser.
189
+ */
190
+ voices?: readonly TtsNamedVoice[]
191
+ /** With `voices`: the voice a request that names none runs with. */
192
+ defaultVoice?: string
193
+ /**
194
+ * With `audioTags`: the tags are written `<in angle brackets>`, from the
195
+ * closed list `tags`. The platform's `[square]` tags are rewritten to them
196
+ * where they match and the rest are taken out before sending
197
+ * (`@nodaro/prompts` `toAngleTags`). Absent ⇒ `[square]` tags, sent as written.
198
+ */
199
+ tagSyntax?: "angle"
200
+ /** With `tagSyntax: "angle"`: the tags the model performs, by their own names (`laugh`, `short pause`). */
201
+ tags?: readonly string[]
202
+ /**
203
+ * Style direction the model takes beside the text — never spoken, never
204
+ * billed. Absent ⇒ none (the request's direction fields are not sent).
205
+ */
206
+ direction?: TtsDirectionSheet
207
+ /**
208
+ * Dialogue lane only: at most this many speakers (distinct voices) in one
209
+ * script. Absent ⇒ the lane's own limit (ElevenLabs dialogue: 10).
210
+ */
211
+ dialogueSpeakers?: number
212
+ /**
213
+ * Dialogue lane only: the model can add natural filler words ("um", "you
214
+ * know") between two speakers when asked (`fillerWords` on a request).
215
+ */
216
+ fillerWords?: true
217
+ /**
218
+ * Dialogue lane only: the model delivers every speech file format
219
+ * (`TTS_OUTPUT_FORMATS`) — it renders a WAV the platform keeps as it is or
220
+ * encodes to MP3. Absent ⇒ the default MP3 only (the ElevenLabs dialogue
221
+ * endpoint, as the platform calls it).
222
+ */
223
+ dialogueAnyOutputFormat?: true
224
+ /**
225
+ * The model clones a speaker's voice for one request from two recordings
226
+ * (`replica`: a reference and a consent recording, `TtsReplica`), in place of
227
+ * a named voice; nothing is saved as a voice. Gemini 3.8 Flash only: KIE's
228
+ * 3.8 Flash-Lite refuses it ("Inline voice sample replication is not
229
+ * supported", probed 2026-11-13).
230
+ */
231
+ replica?: true
232
+ /**
233
+ * The model's length-price row is quoted per 1,000 characters
234
+ * (`<id>:per-1k-chars`) instead of per started 100 (`<id>:per-100-chars`).
235
+ * The count is the same — started 100 characters, at least 8 — and a
236
+ * request costs its hundreds × the row ÷ 10, rounded up once
237
+ * (`speechRowCredits`). For a rate below one credit per 100 characters,
238
+ * which a whole-credit row cannot hold.
239
+ */
240
+ ratePer1kChars?: true
241
+ }
242
+
243
+ /**
244
+ * The style direction a speech model takes (`styleDirection`, `pace`,
245
+ * `accent`, `audioProfile` on a request). A field the sheet does not name is
246
+ * never sent.
247
+ */
248
+ export interface TtsDirectionSheet {
249
+ /** `styleDirection` is free text — tone, emotion, pace in the person's own words — up to this many characters. */
250
+ styleMaxChars?: number
251
+ /** `styleDirection` is one of these (the model's own names). */
252
+ styles?: readonly string[]
253
+ /** `pace` is one of these. */
254
+ paces?: readonly string[]
255
+ /** `accent` is one of these. */
256
+ accents?: readonly string[]
257
+ /** `audioProfile` (who is speaking, in words) is free text up to this many characters. */
258
+ audioProfileMaxChars?: number
163
259
  }
164
260
 
165
261
  /**
@@ -605,6 +701,7 @@ export const MODEL_RECOMMENDATIONS: readonly ModelRecommendation[] = [
605
701
  { intent: "video with start + end frame", modelIds: ["veo3", "veo3.1", "kling-turbo", "minimax", "hailuo-standard", "seedance-2"], note: "All listed support an end frame; VEO uses imageUrls[start, end]." },
606
702
  { intent: "music / song generation", modelIds: ["suno-v6", "suno-v6_wild", "suno-v6_mini", "suno-v5_5"], note: "V6 is the default flagship; V6 Wild for bolder, less predictable results; V6 Mini when speed matters; v5.5 / v5 / v4 keep their own character. Same price." },
607
703
  { intent: "voice over / narration", modelIds: ["elevenlabs-v4", "elevenlabs-v3", "elevenlabs-v4-turbo", "elevenlabs-turbo"], note: "v4 is the default: [audio tags] for emotion and up to 10,000 characters per request. v3 is the previous expressive model, still selectable. v4 Turbo keeps v4's tags at Turbo's credit price; Turbo v2.5 is the cheapest for plain narration without tags." },
704
+ { intent: "low-cost narration with a named voice", modelIds: ["gemini-3-8-flash-lite-tts", "gemini-3-8-flash-tts", "gemini-3-1-flash-tts", "gemini-2-5-pro-tts"], note: "Google's Gemini voices cost far less per character than ElevenLabs. Each speaks only its own named voices (no clones or library voices) and no language is set: the text decides. 3.8 Flash-Lite is the cheapest; 3.8 Flash is the larger 3.8 model; both take their own tone tags (laugh, sigh, short pause…) and a free-text style. 3.1 Flash and 2.5 Pro take [audio tags] and a style, pace, accent and audio profile." },
608
705
  { intent: "lip-sync a portrait to audio", modelIds: ["kling-avatar-pro", "kling-avatar", "infinitalk"], note: "Pro for best mouth shape; InfiniTalk for resolution control." },
609
706
  { intent: "transcription / captions", modelIds: ["elevenlabs-stt", "incredibly-fast-whisper", "whisper", "nemotron-3-5-transcribe"], note: "Captions need WORD timestamps: ElevenLabs STT (always), Incredibly Fast Whisper or Nemotron 3.5 Transcribe (on request, with a speaker per word). Plain Whisper returns phrase segments only. To translate the speech (to or from English) instead of transcribing it, use Nemotron 3.5 Transcribe with a target language; a translation carries no word timings." },
610
707
  { intent: "motion transfer (drive a subject by another video)", modelIds: ["motion-transfer", "kling-3.0-motion"], note: "Kling 2.6 base is cheap; Kling 3.0 is premium." },
@@ -4110,6 +4207,29 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
4110
4207
  { identifier: "video-analysis:gemini-3.1-pro:600s", credits: 1056, note: "10-min ceiling" },
4111
4208
  ],
4112
4209
  },
4210
+ // ULTRA (since 2026-11-13) — the deepest-reasoning analysis model reading
4211
+ // every window, at the same frame sampling as the other single-model tiers.
4212
+ // Priced between the mixed tiers and smart.
4213
+ "gemini-4-carbon-video-analysis": {
4214
+ id: "gemini-4-carbon-video-analysis",
4215
+ kind: "video",
4216
+ modes: ["video-analysis"] as const,
4217
+ family: "Nodaro",
4218
+ maker: "nodaro",
4219
+ label: "Video Analysis (Ultra)",
4220
+ series: "Video Analysis",
4221
+ description: "Deep-reasoning analysis — the most thorough model reads every window of the video. Better on fast cuts and on scenes with many people, and it does not invent cuts. Billed per duration bucket.",
4222
+ // Not `most-accurate`: that tag is Smart's (hand-counted edit list, always
4223
+ // refined). Ultra's strengths are the footage that trips the other tiers.
4224
+ useCases: ["video-analysis", "shot-list", "premium", "fast-cuts", "many-people", "no-invented-cuts"],
4225
+ pricing: [
4226
+ { identifier: "video-analysis:gemini-4-carbon", credits: 1745, note: "10-min ceiling (no duration given)" },
4227
+ { identifier: "video-analysis:gemini-4-carbon:60s", credits: 349 },
4228
+ { identifier: "video-analysis:gemini-4-carbon:180s", credits: 375 },
4229
+ { identifier: "video-analysis:gemini-4-carbon:360s", credits: 1054 },
4230
+ { identifier: "video-analysis:gemini-4-carbon:600s", credits: 1745, note: "10-min ceiling" },
4231
+ ],
4232
+ },
4113
4233
  // Both mixed tiers are variants of the same advanced multi-engine analysis
4114
4234
  // and share this ONE credit family (videoAnalysisCreditSegment maps both;
4115
4235
  // plan internals live in the private analysis plugin).
@@ -4244,6 +4364,65 @@ const DIALOGUE_V4_MAX_CHARS = 10000
4244
4364
  */
4245
4365
  const V4_TURBO_MAX_CHARS = 10000
4246
4366
 
4367
+ /**
4368
+ * Gemini 3.8 (Flash-Lite, Flash) speech, one speaker: its own 70 voices, its
4369
+ * closed list of `<angle>` tone tags, a free-text style per line. No language
4370
+ * field, no timings, no neighbour text, no ElevenLabs levers. From the
4371
+ * provider's schema (2026-11-12); whether each tag is performed rather than
4372
+ * read aloud is to be checked on staging.
4373
+ */
4374
+ const GEMINI_3_8_TTS_SHEET: TtsCapabilities = {
4375
+ audioTags: true,
4376
+ tagSyntax: "angle",
4377
+ tags: GEMINI_3_8_TONE_TAGS,
4378
+ ssmlBreaks: false,
4379
+ levers: [],
4380
+ languageCode: false,
4381
+ timestamps: false,
4382
+ stitching: false,
4383
+ maxChars: GEMINI_TTS_MAX_CHARS,
4384
+ // No picker: the language follows the text.
4385
+ languages: [],
4386
+ voices: GEMINI_3_8_TTS_VOICES,
4387
+ defaultVoice: GEMINI_3_8_DEFAULT_VOICE,
4388
+ direction: { styleMaxChars: TTS_DIRECTION_MAX_CHARS },
4389
+ ratePer1kChars: true,
4390
+ // Two-speaker dialogue (decided 2026-11-12): one or two voices, a style per line, filler words on request.
4391
+ dialogueSpeakers: 2,
4392
+ fillerWords: true,
4393
+ // A dialogue's file is chosen as one speaker's is: MP3 or the WAV as rendered (decided 2026-11-13).
4394
+ dialogueAnyOutputFormat: true,
4395
+ }
4396
+
4397
+ /**
4398
+ * Gemini 3.1 Flash and 2.5 Pro speech, one speaker: 30 voices, `[square]`
4399
+ * tone tags written freely (sent as written), and the speaker's style, pace,
4400
+ * accent and audio profile. Otherwise as the 3.8 sheet.
4401
+ */
4402
+ const GEMINI_3_1_TTS_SHEET: TtsCapabilities = {
4403
+ audioTags: true,
4404
+ ssmlBreaks: false,
4405
+ levers: [],
4406
+ languageCode: false,
4407
+ timestamps: false,
4408
+ stitching: false,
4409
+ maxChars: GEMINI_TTS_MAX_CHARS,
4410
+ languages: [],
4411
+ voices: GEMINI_3_1_TTS_VOICES,
4412
+ defaultVoice: GEMINI_3_1_DEFAULT_VOICE,
4413
+ direction: {
4414
+ styles: GEMINI_3_1_TTS_STYLES,
4415
+ paces: GEMINI_3_1_TTS_PACES,
4416
+ accents: GEMINI_3_1_TTS_ACCENTS,
4417
+ audioProfileMaxChars: TTS_DIRECTION_MAX_CHARS,
4418
+ },
4419
+ ratePer1kChars: true,
4420
+ // Two-speaker dialogue (decided 2026-11-12): one or two voices, the style, pace, accent and profile per speaker.
4421
+ dialogueSpeakers: 2,
4422
+ // A dialogue's file is chosen as one speaker's is: MP3 or the WAV as rendered (decided 2026-11-13).
4423
+ dialogueAnyOutputFormat: true,
4424
+ }
4425
+
4247
4426
  const AUDIO_MODELS: Record<string, ModelCatalogEntry> = {
4248
4427
  // ── ElevenLabs TTS ──
4249
4428
  "elevenlabs-v3": {
@@ -4392,6 +4571,86 @@ const AUDIO_MODELS: Record<string, ModelCatalogEntry> = {
4392
4571
  languages: TTS_LANGS_MULTILINGUAL_V2,
4393
4572
  },
4394
4573
  },
4574
+
4575
+ // ── Google Gemini TTS (through KIE) ──
4576
+ // One id per model for both lanes: the same KIE model takes one speaker
4577
+ // (Text to Speech) and two (Text to Dialogue), and dialogue costs the same per
4578
+ // character as one speaker (decided 2026-11-12) — so `tts` AND `dialogue`,
4579
+ // one sheet and one price row, the same rate by construction.
4580
+ // Named voices of their own (never ElevenLabs'), no language field (the
4581
+ // language follows the text), no timings, no neighbour text. Priced per
4582
+ // 1,000 characters on the same count as every speech model (decided
4583
+ // 2026-11-12, provisional until measured on staging); the flat row is the
4584
+ // price of 1,000 characters.
4585
+ "gemini-3-8-flash-lite-tts": {
4586
+ id: "gemini-3-8-flash-lite-tts",
4587
+ kind: "audio",
4588
+ modes: ["tts", "dialogue"] as const,
4589
+ family: "Google",
4590
+ maker: "google",
4591
+ label: "Gemini 3.8 Flash-Lite TTS",
4592
+ series: "Gemini",
4593
+ description: "Google's lightest Gemini speech model and the cheapest speech on the platform — 70 named voices grouped by use, its own tone tags (laugh, sigh, short pause and more) and a free-text style direction. The language follows the text; up to 10,000 characters per request. Also voices a dialogue of two speakers.",
4594
+ useCases: ["tts", "voice-over", "narration", "fast", "budget"],
4595
+ features: ["audio-tags"],
4596
+ pricing: [
4597
+ { identifier: "gemini-3-8-flash-lite-tts", credits: 4 },
4598
+ { identifier: "gemini-3-8-flash-lite-tts:per-1k-chars", credits: 4, note: SPEECH_PER_1K_PRICE_NOTE },
4599
+ ],
4600
+ tts: GEMINI_3_8_TTS_SHEET,
4601
+ },
4602
+ "gemini-3-8-flash-tts": {
4603
+ id: "gemini-3-8-flash-tts",
4604
+ kind: "audio",
4605
+ modes: ["tts", "dialogue"] as const,
4606
+ family: "Google",
4607
+ maker: "google",
4608
+ label: "Gemini 3.8 Flash TTS",
4609
+ series: "Gemini",
4610
+ description: "Google's Gemini 3.8 speech model — the same 70 voices, tone tags and free-text style direction as Flash-Lite, from the larger model of the generation. The language follows the text; up to 10,000 characters per request. Also voices a dialogue of two speakers.",
4611
+ useCases: ["tts", "voice-over", "narration", "expressive"],
4612
+ features: ["audio-tags"],
4613
+ pricing: [
4614
+ { identifier: "gemini-3-8-flash-tts", credits: 6 },
4615
+ { identifier: "gemini-3-8-flash-tts:per-1k-chars", credits: 6, note: SPEECH_PER_1K_PRICE_NOTE },
4616
+ ],
4617
+ // A one-off clone (`replica`, decided 2026-11-13) on 3.8 Flash alone: its Flash-Lite sibling refuses it.
4618
+ tts: { ...GEMINI_3_8_TTS_SHEET, replica: true },
4619
+ },
4620
+ "gemini-3-1-flash-tts": {
4621
+ id: "gemini-3-1-flash-tts",
4622
+ kind: "audio",
4623
+ modes: ["tts", "dialogue"] as const,
4624
+ family: "Google",
4625
+ maker: "google",
4626
+ label: "Gemini 3.1 Flash TTS",
4627
+ series: "Gemini",
4628
+ description: "Google's Gemini 3.1 speech model — 30 named voices, [audio tags] written freely, and a speaking style, pace, accent and audio profile for the speaker. The language follows the text; up to 10,000 characters per request. Also voices a dialogue of two speakers.",
4629
+ useCases: ["tts", "voice-over", "narration", "expressive"],
4630
+ features: ["audio-tags"],
4631
+ pricing: [
4632
+ { identifier: "gemini-3-1-flash-tts", credits: 13 },
4633
+ { identifier: "gemini-3-1-flash-tts:per-1k-chars", credits: 13, note: SPEECH_PER_1K_PRICE_NOTE },
4634
+ ],
4635
+ tts: GEMINI_3_1_TTS_SHEET,
4636
+ },
4637
+ "gemini-2-5-pro-tts": {
4638
+ id: "gemini-2-5-pro-tts",
4639
+ kind: "audio",
4640
+ modes: ["tts", "dialogue"] as const,
4641
+ family: "Google",
4642
+ maker: "google",
4643
+ label: "Gemini 2.5 Pro TTS",
4644
+ series: "Gemini",
4645
+ description: "Google's Gemini 2.5 Pro speech model — the same 30 voices, [audio tags] and speaker controls (style, pace, accent, audio profile) as Gemini 3.1 Flash TTS, from the Pro model. The language follows the text; up to 10,000 characters per request. Also voices a dialogue of two speakers.",
4646
+ useCases: ["tts", "voice-over", "narration", "expressive", "long-form"],
4647
+ features: ["audio-tags"],
4648
+ pricing: [
4649
+ { identifier: "gemini-2-5-pro-tts", credits: 16 },
4650
+ { identifier: "gemini-2-5-pro-tts:per-1k-chars", credits: 16, note: SPEECH_PER_1K_PRICE_NOTE },
4651
+ ],
4652
+ tts: GEMINI_3_1_TTS_SHEET,
4653
+ },
4395
4654
  "elevenlabs-dialogue": {
4396
4655
  id: "elevenlabs-dialogue",
4397
4656
  kind: "audio",
@@ -1805,6 +1805,12 @@ export const TTS_PROVIDERS = [
1805
1805
  "elevenlabs-v4-turbo",
1806
1806
  "elevenlabs-turbo",
1807
1807
  "elevenlabs-multilingual",
1808
+ // Google's Gemini speech through KIE (decided 2026-11-12): named voices of
1809
+ // their own (`TtsCapabilities.voices`), never ElevenLabs'.
1810
+ "gemini-3-8-flash-lite-tts",
1811
+ "gemini-3-8-flash-tts",
1812
+ "gemini-3-1-flash-tts",
1813
+ "gemini-2-5-pro-tts",
1808
1814
  "elevenlabs",
1809
1815
  ] as const
1810
1816
  export type TtsProvider = typeof TTS_PROVIDERS[number]
@@ -1831,10 +1837,20 @@ export const TTS_OUTPUT_FORMAT_FILES: Readonly<Record<TtsOutputFormat, { readonl
1831
1837
  /**
1832
1838
  * Text-to-dialogue models (the `provider` of `/v1/text-to-dialogue` and of the
1833
1839
  * Text to Dialogue node). Each IS its catalog id and its credit identifier.
1834
- * Never members of TTS_PROVIDERS: a dialogue model takes a script of lines, not
1835
- * one text (`dialogue-capabilities.test.ts` pins both directions).
1836
- */
1837
- export const DIALOGUE_PROVIDERS = ["elevenlabs-dialogue", "elevenlabs-dialogue-v4"] as const
1840
+ * The ElevenLabs dialogue models are dialogue-only ids, never members of
1841
+ * TTS_PROVIDERS: their dialogue endpoint is its own model. Google's Gemini
1842
+ * models take one speaker and two under ONE id, so each is in both lists,
1843
+ * priced on its one row (dialogue costs what one speaker costs per character,
1844
+ * decided 2026-11-12); `dialogue-capabilities.test.ts` pins exactly that.
1845
+ */
1846
+ export const DIALOGUE_PROVIDERS = [
1847
+ "elevenlabs-dialogue",
1848
+ "elevenlabs-dialogue-v4",
1849
+ "gemini-3-8-flash-lite-tts",
1850
+ "gemini-3-8-flash-tts",
1851
+ "gemini-3-1-flash-tts",
1852
+ "gemini-2-5-pro-tts",
1853
+ ] as const
1838
1854
  export type DialogueProvider = typeof DIALOGUE_PROVIDERS[number]
1839
1855
 
1840
1856
  /** The model a dialogue request runs on when its provider is missing or unknown: v3 dialogue (decided 2026-10-04 — v3 stays the default). */
@@ -3184,6 +3200,25 @@ export const VIDEO_REF_LIMITS_BY_PROVIDER: Record<
3184
3200
  * `elements[].voice_url`, no standalone `voices`).
3185
3201
  */
3186
3202
  audioBindsToCharacters?: true
3203
+ /**
3204
+ * How many of the `characters` may be VIDEO subjects — a character made
3205
+ * from a short clip of itself (`characterReferences[].videoUrl`) instead of
3206
+ * images. The clip counts as one of the `videos` too: the provider caps
3207
+ * reference videos and video subjects together. Absent ⇒ none (any other
3208
+ * model refuses a character video). Each clip's own length is
3209
+ * `VIDEO_CHARACTER_CLIP_DURATION_LIMITS`.
3210
+ */
3211
+ videoCharacters?: number
3212
+ /**
3213
+ * The provider bills a video subject's clip as reference-video seconds
3214
+ * (its with-video rate on output + input), so the run is priced as a
3215
+ * reference-video run with the clip among its input seconds. Absent ⇒ a
3216
+ * video subject is priced like an image subject: it adds no input seconds
3217
+ * and does not move the run onto the reference-video rate (its clip still
3218
+ * counts toward the `videos` cap and the reference videos' total length).
3219
+ * Read through `videoCharacterClipsBilledAsReferenceVideo`.
3220
+ */
3221
+ videoCharactersBillAsReferenceVideo?: true
3187
3222
  } | undefined
3188
3223
  > = {
3189
3224
  // Seedance 2 — full multimodal caps.
@@ -3228,7 +3263,12 @@ export const VIDEO_REF_LIMITS_BY_PROVIDER: Record<
3228
3263
  // (docs.kie.ai/market/kling/v4-reference-to-video). A wired start frame takes
3229
3264
  // one of the 10 image slots. No `voices` key: that names Gemini Omni's
3230
3265
  // preset personas, which Kling does not take.
3231
- "kling-4": { images: 10, videos: 5, audio: 3, characters: 7, materials: 15 },
3266
+ // Of the 7 subjects, at most 3 may be video subjects (a 3-8 s clip each), and
3267
+ // reference videos plus video subjects are at most 5. A video subject is
3268
+ // priced as a reference video here until a measured run confirms how Kling
3269
+ // 4.0 bills one (decided 2026-11-14): Flash, measured, bills it as an image
3270
+ // subject (no flag below).
3271
+ "kling-4": { images: 10, videos: 5, audio: 3, characters: 7, materials: 15, videoCharacters: 3, videoCharactersBillAsReferenceVideo: true },
3232
3272
  // Kling 4.0 Keyframes — the Image References are the in-between frames
3233
3273
  // (`keyframe_urls`, max 8; the clip's duration lowers the cap, see
3234
3274
  // kling4KeyframeFrameCap). No reference videos or audio.
@@ -3238,8 +3278,10 @@ export const VIDEO_REF_LIMITS_BY_PROVIDER: Record<
3238
3278
  // standalone voices: reference audio clip N becomes wired character N's voice
3239
3279
  // (`voice_url`) when that character is a subject (2-4 images), so at most one
3240
3280
  // per character (7) and none takes a material seat. A wired start frame takes one of the 10 image slots when it
3241
- // runs on this endpoint.
3242
- "kling-4-flash": { images: 10, videos: 5, audio: 7, characters: 7, materials: 15, audioBindsToCharacters: true },
3281
+ // runs on this endpoint. A video subject is billed like an image subject
3282
+ // (measured on a staging run, decided 2026-11-14): no
3283
+ // `videoCharactersBillAsReferenceVideo`.
3284
+ "kling-4-flash": { images: 10, videos: 5, audio: 7, characters: 7, materials: 15, audioBindsToCharacters: true, videoCharacters: 3 },
3243
3285
  "grok-i2v": { images: 7 }, // backend kie/models.ts maxRefImages: 7
3244
3286
  "happyhorse-ref2v": { images: 9 }, // backend kie/models.ts maxRefImages: 9
3245
3287
  // VEO 3.x — REFERENCE_2_VIDEO path caps refs at 3 (kie/video.ts slices to
@@ -3320,6 +3362,56 @@ export const VIDEO_REF_VIDEO_DURATION_LIMITS: Record<string, RefVideoDurationLim
3320
3362
  "kling-4-flash": { minSec: 2, maxSec: 20, maxTotalSec: 20 },
3321
3363
  }
3322
3364
 
3365
+ /**
3366
+ * The length a character's own clip (`characterReferences[].videoUrl`, a video
3367
+ * subject) must have, per provider. Kling 4.0 and Kling 4.0 Flash: "one 3-8
3368
+ * second single-shot character video" (docs.kie.ai/market/kling/v4-reference-to-video,
3369
+ * v4-flash-reference-to-video, read 2026-11-13). The clip is also one of the
3370
+ * run's reference videos, so `VIDEO_REF_VIDEO_DURATION_LIMITS` (its per-clip
3371
+ * bound and the combined `maxTotalSec`) applies to it as well.
3372
+ */
3373
+ export const VIDEO_CHARACTER_CLIP_DURATION_LIMITS: Record<string, { minSec: number; maxSec: number } | undefined> = {
3374
+ "kling-4": { minSec: 3, maxSec: 8 },
3375
+ "kling-4-flash": { minSec: 3, maxSec: 8 },
3376
+ }
3377
+
3378
+ /**
3379
+ * Validate probed character-clip durations against
3380
+ * {@link VIDEO_CHARACTER_CLIP_DURATION_LIMITS}. Unlike a reference video
3381
+ * ({@link checkRefVideoDurations}, which ignores a clip the probe could not
3382
+ * read and charges its worst case), a character's clip must be measured within
3383
+ * its bounds to be accepted (decided 2026-11-13): one the probe could not read
3384
+ * (NaN, ≤0) is refused too, as `character_video_unreadable`.
3385
+ */
3386
+ export function checkCharacterClipDurations(
3387
+ provider: string,
3388
+ durationsSec: readonly number[],
3389
+ ): { ok: true } | { ok: false; code: "video_too_long" | "character_video_unreadable"; message: string } {
3390
+ const limit = VIDEO_CHARACTER_CLIP_DURATION_LIMITS[provider]
3391
+ if (!limit) return { ok: true }
3392
+ if (durationsSec.some((d) => !Number.isFinite(d) || d <= 0)) {
3393
+ return {
3394
+ ok: false,
3395
+ code: "character_video_unreadable",
3396
+ message:
3397
+ `A character's video could not be measured, and it must be ${limit.minSec}–${limit.maxSec} seconds long. ` +
3398
+ "Check that the link is a playable video file anyone can open, and run again. Nothing was charged.",
3399
+ }
3400
+ }
3401
+ const offender = durationsSec.find((d) => d < limit.minSec || d > limit.maxSec)
3402
+ if (offender === undefined) return { ok: true }
3403
+ // The measured length, rounded UP to hundredths, so a clip just past the
3404
+ // bound never reads as inside it (8.03 s, never "8.0 s").
3405
+ const shown = (Math.ceil(offender * 100 - 1e-9) / 100).toFixed(2)
3406
+ return {
3407
+ ok: false,
3408
+ code: "video_too_long",
3409
+ message:
3410
+ `A character's video must be between ${limit.minSec} and ${limit.maxSec} seconds — one is ${shown} s. ` +
3411
+ `Use a single-shot clip of that length (a Trim Video node upstream works) and run again.`,
3412
+ }
3413
+ }
3414
+
3323
3415
  /**
3324
3416
  * Validate probed reference-video durations against the provider's limits.
3325
3417
  *
@@ -4492,7 +4584,8 @@ export const VIDEO_DURATION_TIERS: Record<string, Array<{ maxSeconds: number; su
4492
4584
  // The length tiers of the earlier Seedance Extend rows
4493
4585
  // (`seedance-2-extend:<tier>:<res>`). No extend is priced on them any more —
4494
4586
  // each Seedance extend provider has a row per second (`tailExtendCreditId`)
4495
- // — but the rows stay, and so do their tiers.
4587
+ // — and the rows themselves were removed (migration 648); the tiers stay,
4588
+ // unread, as part of this published table.
4496
4589
  "seedance-2-extend": [
4497
4590
  { maxSeconds: 4, suffix: "4s" },
4498
4591
  { maxSeconds: 8, suffix: "8s" },
@@ -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
+