@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
@@ -130,6 +130,11 @@ export const VIDEO_ANALYSIS_WINDOW = { LEN: WINDOW_LEN, STRIDE: WINDOW_STRIDE, O
130
130
  // regenerated, on the deployed 9_082 basis: the new gemini-3.8-flash family,
131
131
  // and `mixed` / `smart`, whose plans roll the fast model too. Every other row
132
132
  // is exactly as deployed.
133
+ //
134
+ // 2026-11-13 — the `ultra` tier (gemini-4-carbon) joined. Its four rows are new
135
+ // (migration 649); every other row is exactly as deployed. They are the decided
136
+ // schedule, set between `mixed` and `smart` in every bucket; the plugin's
137
+ // cost test holds its formula to them like every other row.
133
138
  export const VIDEO_ANALYSIS_BUCKET_CREDITS: Record<string, number> = {
134
139
  // Current fast tier (VIDEO_ANALYSIS_TIERS.fast, since 2026-11-13).
135
140
  "video-analysis:gemini-3.8-flash:60s": 186,
@@ -153,6 +158,12 @@ export const VIDEO_ANALYSIS_BUCKET_CREDITS: Record<string, number> = {
153
158
  "video-analysis:gemini-3.1-pro:180s": 232,
154
159
  "video-analysis:gemini-3.1-pro:360s": 640,
155
160
  "video-analysis:gemini-3.1-pro:600s": 1056,
161
+ // ULTRA (VIDEO_ANALYSIS_TIERS.ultra, since 2026-11-13) — the deepest-reasoning
162
+ // model reading every window. Above `mixed` and below `smart` per bucket.
163
+ "video-analysis:gemini-4-carbon:60s": 349,
164
+ "video-analysis:gemini-4-carbon:180s": 375,
165
+ "video-analysis:gemini-4-carbon:360s": 1054,
166
+ "video-analysis:gemini-4-carbon:600s": 1745,
156
167
  // Mixed tiers (`mixed` + `mixed-fast`) share ONE credit family — they are
157
168
  // variants of the same engine plan (plan internals live in the private
158
169
  // analysis plugin). Admin-tunable via model_pricing like every other row.
@@ -48,6 +48,16 @@ export interface VideoCharacterReference {
48
48
  * positive `voices` cap take it.
49
49
  */
50
50
  voice?: VideoCharacterVoice
51
+ /**
52
+ * A short single-shot clip of this character (public URL). On a model with a
53
+ * positive `videoCharacters` cap (Kling 4.0, Kling 4.0 Flash) the character
54
+ * becomes a VIDEO subject made from this clip instead of an image subject.
55
+ * The clip rides as one more reference video ({@link seatCharacterVideos}),
56
+ * so it is measured, capped and priced exactly as a reference video is; its
57
+ * own length must fit `VIDEO_CHARACTER_CLIP_DURATION_LIMITS`. Any other model
58
+ * refuses it.
59
+ */
60
+ videoUrl?: string
51
61
  }
52
62
 
53
63
  /** Zod `.max()` ceiling for the wire field — the widest cap any provider declares. */
@@ -73,6 +83,144 @@ export function videoCharacterRefCap(provider: string | undefined): number {
73
83
  return provider ? (VIDEO_REF_LIMITS_BY_PROVIDER[provider]?.characters ?? 0) : 0
74
84
  }
75
85
 
86
+ /** How many characters may be VIDEO subjects (a `videoUrl` clip) on the provider; 0 = none. */
87
+ export function videoCharacterVideoCap(provider: string | undefined): number {
88
+ return provider ? (VIDEO_REF_LIMITS_BY_PROVIDER[provider]?.videoCharacters ?? 0) : 0
89
+ }
90
+
91
+ /** Every provider that takes video subjects, in declaration order. */
92
+ export function videoCharacterVideoProviders(): string[] {
93
+ return Object.entries(VIDEO_REF_LIMITS_BY_PROVIDER)
94
+ .filter(([, l]) => (l?.videoCharacters ?? 0) > 0)
95
+ .map(([id]) => id)
96
+ }
97
+
98
+ /** The clips a set of character references carries (`videoUrl`, trimmed, non-empty), in order. */
99
+ export function characterVideoUrls(
100
+ characterReferences: readonly unknown[] | undefined,
101
+ ): string[] {
102
+ const out: string[] = []
103
+ for (const c of characterReferences ?? []) {
104
+ const url = (c as { videoUrl?: unknown } | null | undefined)?.videoUrl
105
+ if (typeof url === "string" && url.trim()) out.push(url.trim())
106
+ }
107
+ return out
108
+ }
109
+
110
+ /**
111
+ * Whether the provider bills a character's video subject as reference-video
112
+ * seconds (`videoCharactersBillAsReferenceVideo`: Kling 4.0). On any other
113
+ * model that takes video subjects (Kling 4.0 Flash, measured, decided
114
+ * 2026-11-14) the subject is priced like an image subject.
115
+ */
116
+ export function videoCharacterClipsBilledAsReferenceVideo(provider: string | undefined): boolean {
117
+ return provider ? VIDEO_REF_LIMITS_BY_PROVIDER[provider]?.videoCharactersBillAsReferenceVideo === true : false
118
+ }
119
+
120
+ /**
121
+ * The reference videos a run is PRICED on: `referenceVideoUrls` as sent, less
122
+ * — on a model that does not bill video subjects as reference video
123
+ * ({@link videoCharacterClipsBilledAsReferenceVideo}) — the seats that are a
124
+ * character's clip. Those seats still count toward the model's video cap and
125
+ * the reference videos' total length (`seatCharacterVideos`, the duration
126
+ * check); they only leave the price. The same value when nothing leaves it.
127
+ * Every price path reads it: the routes' credit guard and `POST /v1/quote`,
128
+ * the workflow reservation, the estimates and the completion settlement.
129
+ */
130
+ export function pricedReferenceVideoUrls(args: {
131
+ provider: string | undefined
132
+ referenceVideoUrls: readonly unknown[] | undefined
133
+ characterReferences: readonly unknown[] | undefined
134
+ }): readonly unknown[] | undefined {
135
+ if (videoCharacterClipsBilledAsReferenceVideo(args.provider)) return args.referenceVideoUrls
136
+ const clips = new Set(characterVideoUrls(args.characterReferences))
137
+ if (clips.size === 0 || !args.referenceVideoUrls?.some((u) => typeof u === "string" && clips.has(u))) return args.referenceVideoUrls
138
+ return args.referenceVideoUrls.filter((u) => !(typeof u === "string" && clips.has(u)))
139
+ }
140
+
141
+ /** A refusal from {@link seatCharacterVideos}: a finished, user-facing sentence. */
142
+ export interface CharacterVideoSeatProblem {
143
+ code: "character_video_unsupported" | "character_videos_over_limit" | "character_video_shared" | "reference_videos_over_limit"
144
+ message: string
145
+ }
146
+
147
+ /**
148
+ * The reference-video list a run sends once its characters' clips are seated
149
+ * in it — the ONE rule both video routes (a precheck, before the duration
150
+ * check, the quote and any reservation) and the workflow run (the payload
151
+ * builder) apply, so a video subject's clip is measured, capped, priced, held
152
+ * and settled exactly as a reference video is (KIE bills video subjects as
153
+ * reference-video seconds, summed). The provider runner then takes the seat
154
+ * back out of the reference videos and sends it as the character's subject.
155
+ *
156
+ * - No clip: the list as it came (the same value).
157
+ * - A clip already in the list (also wired as a plain reference video) keeps
158
+ * its seat, and becomes the subject only; any other is appended, in
159
+ * character order, after the reference videos.
160
+ * - Refused: a model that takes no video subjects; more clips than its
161
+ * `videoCharacters` cap; two characters with the same clip; reference
162
+ * videos plus clips over its `videos` cap (the provider counts both in one
163
+ * cap, and a clip past it would be neither measured nor sent).
164
+ * - On a model that takes video subjects (one shared cap), plain reference
165
+ * videos alone over that cap are refused too, instead of the extra ones
166
+ * being left out without a word (decided 2026-11-13). Any other model's
167
+ * list is not judged here.
168
+ */
169
+ export function seatCharacterVideos(args: {
170
+ provider: string | undefined
171
+ referenceVideoUrls: readonly unknown[] | undefined
172
+ characterReferences: readonly unknown[] | undefined
173
+ }):
174
+ | { ok: true; referenceVideoUrls: readonly unknown[] | undefined }
175
+ | ({ ok: false } & CharacterVideoSeatProblem) {
176
+ const clips = characterVideoUrls(args.characterReferences)
177
+ const provider = args.provider ?? "the selected model"
178
+ const cap = videoCharacterVideoCap(args.provider)
179
+ const videosCap = VIDEO_REF_LIMITS_BY_PROVIDER[args.provider as string]?.videos ?? 0
180
+ const overVideos = (count: number): { ok: false } & CharacterVideoSeatProblem => ({
181
+ ok: false,
182
+ code: "reference_videos_over_limit",
183
+ message:
184
+ `${provider} takes at most ${videosCap} videos in all — reference videos and characters made from a video together. ` +
185
+ `This run has ${count}. Remove a reference video${clips.length > 0 ? ", or the video from a character" : ""}.`,
186
+ })
187
+ if (clips.length === 0) {
188
+ const sent = (args.referenceVideoUrls ?? []).length
189
+ if (cap > 0 && sent > videosCap) return overVideos(sent)
190
+ return { ok: true, referenceVideoUrls: args.referenceVideoUrls }
191
+ }
192
+ if (cap === 0) {
193
+ const takers = videoCharacterVideoProviders()
194
+ return {
195
+ ok: false,
196
+ code: "character_video_unsupported",
197
+ message:
198
+ `A character video (characterReferences[].videoUrl) is not supported by ${provider}. ` +
199
+ `Models that take one: ${takers.join(", ")}. Otherwise drop the video and keep the character's images.`,
200
+ }
201
+ }
202
+ if (clips.length > cap) {
203
+ return {
204
+ ok: false,
205
+ code: "character_videos_over_limit",
206
+ message: `${provider} takes at most ${cap} characters made from a video; ${clips.length} characters carry one. Remove the video from some of them.`,
207
+ }
208
+ }
209
+ if (new Set(clips).size < clips.length) {
210
+ return {
211
+ ok: false,
212
+ code: "character_video_shared",
213
+ message: "Two characters carry the same video. Each character made from a video needs a clip of its own.",
214
+ }
215
+ }
216
+ // The list as sent stays as it is (an entry the route's schema would refuse
217
+ // is still there for it to refuse); the clips follow it.
218
+ const raw = args.referenceVideoUrls ?? []
219
+ const seated: unknown[] = [...raw, ...clips.filter((c) => !raw.includes(c))]
220
+ if (seated.length > videosCap) return overVideos(seated.length)
221
+ return { ok: true, referenceVideoUrls: seated }
222
+ }
223
+
76
224
  /** How many DISTINCT voice personas the provider takes per request; 0 = none. */
77
225
  export function videoCharacterVoiceCap(provider: string | undefined): number {
78
226
  return provider ? (VIDEO_REF_LIMITS_BY_PROVIDER[provider]?.voices ?? 0) : 0
@@ -278,13 +426,21 @@ export function videoCharacterRefProblem(args: {
278
426
  * image still yields a reference — the provider decides (Kling keeps it a
279
427
  * reference image).
280
428
  */
281
- export function characterReferencesFromWired(refs: readonly ConnectedReference[]): VideoCharacterReference[] {
282
- const bySlug = new Map<string, { name: string; description?: string; urls: string[] }>()
429
+ export function characterReferencesFromWired(
430
+ refs: readonly ConnectedReference[],
431
+ /**
432
+ * The clip each wired character carries, by its slug (`wiredCharacterVideoUrls`):
433
+ * pass it only for a model that takes video subjects. Absent = none.
434
+ */
435
+ videoBySlug?: ReadonlyMap<string, string>,
436
+ ): VideoCharacterReference[] {
437
+ const bySlug = new Map<string, { name: string; description?: string; urls: string[]; videoUrl?: string }>()
283
438
  for (const r of refs) {
284
439
  if (r.source !== "wired-character" || !r.characterSlug || !r.url) continue
285
440
  let entry = bySlug.get(r.characterSlug)
286
441
  if (!entry) {
287
- entry = { name: r.defaultName.split(" / ")[0]!.trim() || r.characterSlug, urls: [] }
442
+ const videoUrl = videoBySlug?.get(r.characterSlug)
443
+ entry = { name: r.defaultName.split(" / ")[0]!.trim() || r.characterSlug, urls: [], ...(videoUrl ? { videoUrl } : {}) }
288
444
  bySlug.set(r.characterSlug, entry)
289
445
  }
290
446
  const description = (r.characterCanonicalDescription ?? r.description)?.trim()
@@ -299,5 +455,6 @@ export function characterReferencesFromWired(refs: readonly ConnectedReference[]
299
455
  ...(c.urls.length > 1 ? { extraImageUrls: c.urls.slice(1, 1 + VIDEO_CHARACTER_EXTRA_IMAGES_MAX) } : {}),
300
456
  description: (c.description ?? c.name).slice(0, VIDEO_CHARACTER_DESCRIPTION_MAX),
301
457
  name: c.name.slice(0, VIDEO_CHARACTER_NAME_MAX),
458
+ ...(c.videoUrl ? { videoUrl: c.videoUrl } : {}),
302
459
  }))
303
460
  }
@@ -73,45 +73,109 @@ export interface WiredCharacterName {
73
73
  * unnamed ones: "Character 1", "Character 2", …, skipping a number whose
74
74
  * name (by slug) another wired character already has. Unnamed nodes are
75
75
  * never merged.
76
- * - A typed name the slug cannot spell ("マヤ", "מאיה", "마야" — no Latin
77
- * letter or digit) is a real name: the model reads it as typed, and the node
78
- * takes the next number of the same sequence as its key (`character-N`), so
79
- * it is included on every path and no two keys collide.
76
+ * - A typed name with a letter of another script ("マヤ", "מאיה", "마야",
77
+ * and a mixed one such as "マヤ1" or "マヤ A") is a real name: the model
78
+ * reads it as typed. Which character it is goes by the WHOLE name
79
+ * ({@link scriptNameKey}), never by the Latin part the slug can spell, so
80
+ * "マヤ1" and "レオ1" are two characters and "マヤ A" is not "A" (decided
81
+ * 2026-11-13). Two nodes with the same such name are ONE character, as two
82
+ * "Maya" nodes are (decided 2026-11-12).
83
+ * - Its mention key: the name's own slug when the name has one and no other
84
+ * wired character claims it ("マヤ A" alone stays `@a`); else — no slug
85
+ * ("マヤ"), or a slug another character also claims — the next number of
86
+ * the unnamed sequence (`character-N`), taken once per character, so it is
87
+ * included on every path and no two keys collide.
88
+ * - A name whose letters are all Latin is keyed by its slug, exactly as before
89
+ * ("Maya", "maya" and "MAYA" are one character).
80
90
  *
81
91
  * `sources` are the consuming node's incoming wires in edge-array order.
82
92
  */
83
93
  export function wiredCharacterNames(sources: readonly WiredCharacterSource[]): Map<string, WiredCharacterName> {
84
- const order: Array<{ key: string; own: string }> = []
94
+ const order: Array<{ key: string; own: string; identity: string; ownSlug: string }> = []
85
95
  const seen = new Set<string>()
86
96
  for (const s of sources) {
87
97
  if (seen.has(s.key) || resolveEffectiveSourceType(s.type, s.sourceHandle) !== "character") continue
88
98
  seen.add(s.key)
89
- order.push({ key: s.key, own: characterOwnName(s.data) })
99
+ const own = characterOwnName(s.data)
100
+ order.push({ key: s.key, own, identity: characterIdentity(own) ?? `node:${s.key}`, ownSlug: characterMentionSlug(own) })
90
101
  }
91
- const taken = new Set<string>()
92
- for (const { own } of order) {
93
- const slug = characterMentionSlug(own)
94
- if (slug) taken.add(slug)
102
+ // Every character that would go by each slug: a Latin name always keeps its
103
+ // own; another name keeps it only when it is the one character claiming it.
104
+ const claims = new Map<string, Set<string>>()
105
+ for (const { identity, ownSlug } of order) {
106
+ if (!ownSlug) continue
107
+ const set = claims.get(ownSlug) ?? new Set<string>()
108
+ set.add(identity)
109
+ claims.set(ownSlug, set)
95
110
  }
111
+ const keepsOwnSlug = (identity: string, ownSlug: string): boolean =>
112
+ !!ownSlug && (identity.startsWith(LATIN_IDENTITY) || claims.get(ownSlug)?.size === 1)
113
+ const taken = new Set<string>()
114
+ for (const { identity, ownSlug } of order) if (keepsOwnSlug(identity, ownSlug)) taken.add(ownSlug)
96
115
  const out = new Map<string, WiredCharacterName>()
116
+ /** A character (by identity) → the `character-N` its first node took. */
117
+ const numberedOf = new Map<string, string>()
97
118
  let next = 1
98
- for (const { key, own } of order) {
99
- const ownSlug = characterMentionSlug(own)
100
- if (ownSlug) {
119
+ for (const { key, own, identity, ownSlug } of order) {
120
+ if (keepsOwnSlug(identity, ownSlug)) {
101
121
  out.set(key, { name: own, slug: ownSlug, unnamed: false })
102
122
  continue
103
123
  }
124
+ const same = numberedOf.get(identity)
125
+ if (same) {
126
+ out.set(key, { name: own, slug: same, unnamed: false })
127
+ continue
128
+ }
104
129
  while (taken.has(numberedSlug(next))) next++
105
130
  const slug = numberedSlug(next)
106
131
  taken.add(slug)
132
+ numberedOf.set(identity, slug)
107
133
  out.set(key, own ? { name: own, slug, unnamed: false } : { name: `${UNNAMED_CHARACTER_NAME_PREFIX} ${next}`, slug, unnamed: true })
108
134
  next++
109
135
  }
110
136
  return out
111
137
  }
112
138
 
139
+ const LATIN_IDENTITY = "latin:"
140
+
141
+ /** A letter of a script other than Latin (accented Latin letters are Latin). */
142
+ const OTHER_SCRIPT_LETTER = /(?=\p{L})\P{Script=Latin}/u
143
+
144
+ /**
145
+ * Which character a typed name is — two names with the same identity are one
146
+ * character. A name whose letters are all Latin: its slug, exactly as before.
147
+ * Any other name with a letter or digit: the whole name ({@link scriptNameKey}).
148
+ * Undefined for no name, or one with no letter or digit at all ("!!!"): such a
149
+ * node is a character of its own.
150
+ */
151
+ function characterIdentity(name: string): string | undefined {
152
+ const slug = characterMentionSlug(name)
153
+ if (slug && !OTHER_SCRIPT_LETTER.test(name)) return `${LATIN_IDENTITY}${slug}`
154
+ const key = scriptNameKey(name)
155
+ return key ? `script:${key}` : undefined
156
+ }
157
+
113
158
  const numberedSlug = (n: number): string => characterMentionSlug(`${UNNAMED_CHARACTER_NAME_PREFIX} ${n}`)
114
159
 
160
+ /**
161
+ * When two typed names the slug cannot spell are the same name: the rule
162
+ * {@link characterMentionSlug} applies to a Latin name ("Maya", "maya" and
163
+ * "MAYA" are one; so are "Maya Lee" and "maya-lee"), over every script.
164
+ * Unicode NFKC (half-width "マヤ" is "マヤ", a decomposed Hangul syllable is the
165
+ * composed one), then case folded (Cyrillic "Мая" is "мая"), then every run of
166
+ * characters that are no letter, digit or combining mark is one separator.
167
+ * Marks stay: "ガ" is not "カ". "" for a name with no letter or digit at all
168
+ * ("!!!"), which never matches another.
169
+ */
170
+ function scriptNameKey(name: string): string {
171
+ return name
172
+ .normalize("NFKC")
173
+ .toUpperCase()
174
+ .toLowerCase()
175
+ .replace(/[^\p{L}\p{N}\p{M}]+/gu, "-")
176
+ .replace(/^-+|-+$/g, "")
177
+ }
178
+
115
179
  /**
116
180
  * The slugs an unnamed character's mentions were written with before it was
117
181
  * numbered: its default label's ("Character Asset") and the retired default's
@@ -175,20 +239,49 @@ export function wiredCharacterNamesOf(
175
239
  return wiredCharacterNames(sources)
176
240
  }
177
241
 
242
+ /**
243
+ * The slug a Character node goes by for the node it feeds: its slug in
244
+ * `names`; else — a node wired only by its plain `image` pip, which `names`
245
+ * leaves out — the slug of the wired character that is the same name (the
246
+ * same whole name is the same character, in any script); else a Latin name's
247
+ * own slug, when no wired character of another identity goes by it; else "".
248
+ */
249
+ export function wiredCharacterSlug(
250
+ names: ReadonlyMap<string, WiredCharacterName>,
251
+ nodeId: string,
252
+ data: unknown,
253
+ ): string {
254
+ const wired = names.get(nodeId)?.slug
255
+ if (wired) return wired
256
+ const own = characterOwnName(data)
257
+ const identity = characterIdentity(own)
258
+ if (!identity) return ""
259
+ // The wired character that IS this name (the same identity, in any script).
260
+ for (const n of names.values()) {
261
+ if (!n.unnamed && characterIdentity(n.name) === identity) return n.slug
262
+ }
263
+ // None: a Latin name still goes by its own slug — unless a wired character
264
+ // of ANOTHER identity goes by it ("A" beside a wired "マヤ A", decided
265
+ // 2026-11-13), which it must never be filed under.
266
+ if (!identity.startsWith(LATIN_IDENTITY)) return ""
267
+ const slug = characterMentionSlug(own)
268
+ for (const n of names.values()) if (n.slug === slug) return ""
269
+ return slug
270
+ }
271
+
178
272
  /**
179
273
  * The key a Character node's OWN elements (held prop, styling, …) are filed
180
274
  * under for the node it feeds, so they land on that character's identity
181
- * bullet: its slug in `names`; else — a node wired only by its plain `image`
182
- * pip, which `names` leaves out — its own name's slug (the same typed name is
183
- * the same character); else a key of its own that no character carries, so an
184
- * unnamed node's elements are never merged into another character's.
275
+ * bullet: the slug it goes by ({@link wiredCharacterSlug}); else a key of its
276
+ * own that no character carries, so an unnamed node's elements are never
277
+ * merged into another character's.
185
278
  */
186
279
  export function wiredCharacterKey(
187
280
  names: ReadonlyMap<string, WiredCharacterName>,
188
281
  nodeId: string,
189
282
  data: unknown,
190
283
  ): string {
191
- return names.get(nodeId)?.slug || characterMentionSlug(characterOwnName(data)) || `node:${nodeId}`
284
+ return wiredCharacterSlug(names, nodeId, data) || `node:${nodeId}`
192
285
  }
193
286
 
194
287
  /** The wired character whose slug is `slug`, if any (first in wire order). */
@@ -200,3 +293,26 @@ export function wiredCharacterBySlug(
200
293
  for (const [key, named] of names) if (named.slug === slug) return { key, named }
201
294
  return undefined
202
295
  }
296
+
297
+ /**
298
+ * The clip each Character node wired into `consumerId` carries as its VIDEO
299
+ * subject (its `subjectVideoUrl`, a short single-shot clip of the character),
300
+ * by the slug the node goes by ({@link wiredCharacterNamesOf}) — the key
301
+ * `characterReferencesFromWired` groups a character by. Two nodes that are one
302
+ * character (the same typed name) take the first node's clip, in wire order. A
303
+ * node wired only by its plain `image` pip is no character and gives none.
304
+ * Read it only for a model that takes video subjects.
305
+ */
306
+ export function wiredCharacterVideoUrls(
307
+ consumerId: string,
308
+ nodes: ReadonlyArray<{ readonly id: string; readonly type?: string | null; readonly data?: unknown }>,
309
+ edges: ReadonlyArray<{ readonly source: string; readonly target: string; readonly sourceHandle?: string | null }>,
310
+ ): Map<string, string> {
311
+ const byId = new Map(nodes.map((n) => [n.id, n] as const))
312
+ const out = new Map<string, string>()
313
+ for (const [id, named] of wiredCharacterNamesOf(consumerId, nodes, edges)) {
314
+ const clip = (byId.get(id)?.data as { subjectVideoUrl?: unknown } | undefined)?.subjectVideoUrl
315
+ if (typeof clip === "string" && clip.trim() && !out.has(named.slug)) out.set(named.slug, clip.trim())
316
+ }
317
+ return out
318
+ }
@@ -0,0 +1,63 @@
1
+ import { hasFeature } from "./model-catalog.js"
2
+ import { characterMentionSlug } from "./character-mention-slug.js"
3
+ import { characterMentionableAssetArrays } from "./character-variant-assets.js"
4
+ import { entityImageUrl } from "./entity-image-url.js"
5
+ import { videoCharacterRefCap, videoCharacterVideoCap } from "./video-character-refs.js"
6
+ import { wiredCharacterNamesOf, wiredCharacterVideoUrls } from "./wired-character-names.js"
7
+
8
+ type GraphNode = { readonly id: string; readonly type?: string | null; readonly data?: unknown }
9
+ type GraphEdge = { readonly source: string; readonly target: string; readonly sourceHandle?: string | null }
10
+
11
+ /**
12
+ * Whether a Character node gives its wired character a reference image: its
13
+ * portrait (`entityImageUrl`), or any named image of its mentionable asset
14
+ * buckets. The rule a run's character expansion follows (`expandWiredCharacterRefs`
15
+ * in the workflow payload builder, its editor twin): a node with none yields
16
+ * no reference, so `characterReferencesFromWired` makes no character of it.
17
+ */
18
+ function characterGivesAnImage(data: unknown): boolean {
19
+ if (entityImageUrl(data)) return true
20
+ const arrays = characterMentionableAssetArrays((data ?? {}) as Record<string, unknown>)
21
+ return Object.values(arrays).some((items) => items.some((item) => !!item?.url && !!characterMentionSlug(item.name ?? "")))
22
+ }
23
+
24
+ /**
25
+ * The clips a Generate Video run on `provider` sends as its characters' video
26
+ * subjects (decided 2026-11-13), in the order the run seats them — read off the
27
+ * graph without building the run, for an estimate that must price exactly what
28
+ * the run sends:
29
+ *
30
+ * - none on a model that takes no video subjects (or no named subjects at all);
31
+ * - the characters as the run groups them (`characterReferencesFromWired`): one
32
+ * per wired character by the slug it goes by, in wire order of its first node
33
+ * that gives an image — a node with no image at all makes no character, so
34
+ * its clip is not sent;
35
+ * - only the first `videoCharacterRefCap(provider)` characters (the run's slice);
36
+ * - each character's clip as `wiredCharacterVideoUrls` gives it (its first
37
+ * node's, in wire order).
38
+ *
39
+ * The workflow run itself builds the same list through
40
+ * `characterReferencesFromWired(expandWiredCharacterRefs(…), clips).slice(…)`;
41
+ * a parity test holds the two together. Only Generate Video carries video
42
+ * subjects — the older Image to Video / Text to Video nodes never do.
43
+ */
44
+ export function wiredCharacterSubjectClips(
45
+ consumerId: string,
46
+ nodes: ReadonlyArray<GraphNode>,
47
+ edges: ReadonlyArray<GraphEdge>,
48
+ provider: string,
49
+ ): string[] {
50
+ if (videoCharacterVideoCap(provider) === 0 || !hasFeature(provider, "character-subjects")) return []
51
+ const clips = wiredCharacterVideoUrls(consumerId, nodes, edges)
52
+ if (clips.size === 0) return []
53
+ const byId = new Map(nodes.map((n) => [n.id, n] as const))
54
+ const subjects: string[] = []
55
+ for (const [id, named] of wiredCharacterNamesOf(consumerId, nodes, edges)) {
56
+ if (subjects.includes(named.slug)) continue
57
+ if (characterGivesAnImage(byId.get(id)?.data)) subjects.push(named.slug)
58
+ }
59
+ return subjects.slice(0, videoCharacterRefCap(provider)).flatMap((slug) => {
60
+ const clip = clips.get(slug)
61
+ return clip ? [clip] : []
62
+ })
63
+ }