@nodaro/shared 3.32.0 → 3.35.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 (274) hide show
  1. package/dist/{chunk-VWGNPMJZ.cjs → chunk-24ZKPE33.cjs} +5 -5
  2. package/dist/{chunk-VWGNPMJZ.cjs.map → chunk-24ZKPE33.cjs.map} +1 -1
  3. package/dist/{chunk-CK3GK34R.js → chunk-2HIDE3QV.js} +9 -3
  4. package/dist/chunk-2HIDE3QV.js.map +1 -0
  5. package/dist/{chunk-WDIBOWAA.js → chunk-2HVFF5SS.js} +6 -6
  6. package/dist/chunk-2HVFF5SS.js.map +1 -0
  7. package/dist/{chunk-KHCBJ7KD.js → chunk-2QWNPYDG.js} +3 -3
  8. package/dist/{chunk-KHCBJ7KD.js.map → chunk-2QWNPYDG.js.map} +1 -1
  9. package/dist/{chunk-J6KHW2E5.cjs → chunk-3YG3MYDE.cjs} +153 -24
  10. package/dist/chunk-3YG3MYDE.cjs.map +1 -0
  11. package/dist/{chunk-ULXI7A6Q.cjs → chunk-5VNBQ4QK.cjs} +16 -16
  12. package/dist/{chunk-ULXI7A6Q.cjs.map → chunk-5VNBQ4QK.cjs.map} +1 -1
  13. package/dist/{chunk-5AUSSJIM.cjs → chunk-5ZCXWA7J.cjs} +232 -15
  14. package/dist/chunk-5ZCXWA7J.cjs.map +1 -0
  15. package/dist/{chunk-Z2OL5AJD.cjs → chunk-6F6GGX2W.cjs} +4 -3
  16. package/dist/chunk-6F6GGX2W.cjs.map +1 -0
  17. package/dist/{chunk-E2TGXG6X.cjs → chunk-72IFMNJE.cjs} +80 -52
  18. package/dist/chunk-72IFMNJE.cjs.map +1 -0
  19. package/dist/{chunk-NB72XWXQ.cjs → chunk-A5Z3IMSJ.cjs} +6 -6
  20. package/dist/{chunk-NB72XWXQ.cjs.map → chunk-A5Z3IMSJ.cjs.map} +1 -1
  21. package/dist/{chunk-NT6IJH4L.cjs → chunk-AGEZY4LL.cjs} +66 -47
  22. package/dist/chunk-AGEZY4LL.cjs.map +1 -0
  23. package/dist/{chunk-3CUFITU7.js → chunk-ANOQWAMU.js} +88 -54
  24. package/dist/chunk-ANOQWAMU.js.map +1 -0
  25. package/dist/{chunk-PRYE7AZQ.cjs → chunk-AWWOQH46.cjs} +7 -7
  26. package/dist/chunk-AWWOQH46.cjs.map +1 -0
  27. package/dist/{chunk-QELDJGDK.cjs → chunk-B7WJJHJS.cjs} +7 -4
  28. package/dist/chunk-B7WJJHJS.cjs.map +1 -0
  29. package/dist/{chunk-AVQK77G6.cjs → chunk-BBLE4UTG.cjs} +88 -54
  30. package/dist/chunk-BBLE4UTG.cjs.map +1 -0
  31. package/dist/{chunk-HGC5JNVA.cjs → chunk-BVVKMQKR.cjs} +9 -2
  32. package/dist/chunk-BVVKMQKR.cjs.map +1 -0
  33. package/dist/{chunk-YYV35XOS.js → chunk-C4R7BTBQ.js} +4 -3
  34. package/dist/chunk-C4R7BTBQ.js.map +1 -0
  35. package/dist/{chunk-AROWPFO2.js → chunk-ETXUOETU.js} +29 -36
  36. package/dist/chunk-ETXUOETU.js.map +1 -0
  37. package/dist/{chunk-S5DMKUWK.cjs → chunk-F4ZT5X2S.cjs} +11 -11
  38. package/dist/{chunk-S5DMKUWK.cjs.map → chunk-F4ZT5X2S.cjs.map} +1 -1
  39. package/dist/{chunk-YBPBK5KI.js → chunk-FKQJYMCO.js} +97 -23
  40. package/dist/chunk-FKQJYMCO.js.map +1 -0
  41. package/dist/{chunk-ZDFHA2EC.js → chunk-FVKCNAEQ.js} +51 -7
  42. package/dist/chunk-FVKCNAEQ.js.map +1 -0
  43. package/dist/{chunk-JSNV5O2F.cjs → chunk-GHBXS5RT.cjs} +4 -4
  44. package/dist/{chunk-JSNV5O2F.cjs.map → chunk-GHBXS5RT.cjs.map} +1 -1
  45. package/dist/{chunk-C57NEO3X.js → chunk-GKJRNIP4.js} +230 -16
  46. package/dist/chunk-GKJRNIP4.js.map +1 -0
  47. package/dist/{chunk-QNGNOU4Z.js → chunk-GRIMIJJ3.js} +3 -3
  48. package/dist/{chunk-QNGNOU4Z.js.map → chunk-GRIMIJJ3.js.map} +1 -1
  49. package/dist/{chunk-IEBZHTPE.js → chunk-GVHBHUFV.js} +34 -16
  50. package/dist/chunk-GVHBHUFV.js.map +1 -0
  51. package/dist/chunk-GZH2SIOF.cjs +99 -0
  52. package/dist/chunk-GZH2SIOF.cjs.map +1 -0
  53. package/dist/{chunk-YHRG7UOC.js → chunk-IJNQYMN7.js} +4 -4
  54. package/dist/{chunk-YHRG7UOC.js.map → chunk-IJNQYMN7.js.map} +1 -1
  55. package/dist/{chunk-JX5YZ4DH.cjs → chunk-IRUPCNW2.cjs} +49 -46
  56. package/dist/chunk-IRUPCNW2.cjs.map +1 -0
  57. package/dist/{chunk-JL4C5VJ7.cjs → chunk-J65CAOUV.cjs} +14 -2
  58. package/dist/chunk-J65CAOUV.cjs.map +1 -0
  59. package/dist/{chunk-ISJDAFKS.js → chunk-LJMNCSDG.js} +38 -15
  60. package/dist/chunk-LJMNCSDG.js.map +1 -0
  61. package/dist/{chunk-ZT77RY6R.js → chunk-MEN7VLQ5.js} +8 -5
  62. package/dist/chunk-MEN7VLQ5.js.map +1 -0
  63. package/dist/{chunk-VIWSWVAW.js → chunk-MUA5L25B.js} +125 -12
  64. package/dist/chunk-MUA5L25B.js.map +1 -0
  65. package/dist/{chunk-6IJOPRZP.cjs → chunk-NWXB4F6D.cjs} +21 -21
  66. package/dist/{chunk-6IJOPRZP.cjs.map → chunk-NWXB4F6D.cjs.map} +1 -1
  67. package/dist/{chunk-PQHS255G.js → chunk-OHSIVNJO.js} +3 -3
  68. package/dist/chunk-OHSIVNJO.js.map +1 -0
  69. package/dist/{chunk-LKAIXWK3.js → chunk-PVVO23LZ.js} +3 -3
  70. package/dist/{chunk-LKAIXWK3.js.map → chunk-PVVO23LZ.js.map} +1 -1
  71. package/dist/{chunk-XAMC4S53.js → chunk-Q4ZXDDWA.js} +3 -3
  72. package/dist/{chunk-XAMC4S53.js.map → chunk-Q4ZXDDWA.js.map} +1 -1
  73. package/dist/{chunk-EK362Q45.cjs → chunk-QIIG2QDP.cjs} +8 -8
  74. package/dist/{chunk-EK362Q45.cjs.map → chunk-QIIG2QDP.cjs.map} +1 -1
  75. package/dist/{chunk-Q4CDQ2KO.js → chunk-QXW6O56Z.js} +6 -6
  76. package/dist/chunk-QXW6O56Z.js.map +1 -0
  77. package/dist/{chunk-5PC6JBGJ.cjs → chunk-R2VF5NQG.cjs} +3 -3
  78. package/dist/chunk-R2VF5NQG.cjs.map +1 -0
  79. package/dist/{chunk-6DKDOWBL.js → chunk-RRI5YBUK.js} +6 -3
  80. package/dist/{chunk-QELDJGDK.cjs.map → chunk-RRI5YBUK.js.map} +1 -1
  81. package/dist/{chunk-RJL7RCEM.cjs → chunk-RUKFN3LJ.cjs} +6 -6
  82. package/dist/chunk-RUKFN3LJ.cjs.map +1 -0
  83. package/dist/chunk-TCBHVIMD.js +89 -0
  84. package/dist/chunk-TCBHVIMD.js.map +1 -0
  85. package/dist/{chunk-SES6GDBQ.cjs → chunk-UJJUX6NW.cjs} +59 -8
  86. package/dist/chunk-UJJUX6NW.cjs.map +1 -0
  87. package/dist/{chunk-ZRL2UFTH.cjs → chunk-V3N56Z2S.cjs} +101 -22
  88. package/dist/chunk-V3N56Z2S.cjs.map +1 -0
  89. package/dist/{chunk-Z4AZW6FY.js → chunk-W36WCZS2.js} +6 -6
  90. package/dist/{chunk-Z4AZW6FY.js.map → chunk-W36WCZS2.js.map} +1 -1
  91. package/dist/{chunk-M36G6SRP.js → chunk-WXNQMJ67.js} +14 -3
  92. package/dist/chunk-WXNQMJ67.js.map +1 -0
  93. package/dist/{chunk-O7PUQLJ3.cjs → chunk-XE5PE54B.cjs} +33 -40
  94. package/dist/chunk-XE5PE54B.cjs.map +1 -0
  95. package/dist/{chunk-LPW3XNC2.js → chunk-XJOBMAWW.js} +3 -3
  96. package/dist/{chunk-LPW3XNC2.js.map → chunk-XJOBMAWW.js.map} +1 -1
  97. package/dist/{chunk-5U7VLG43.js → chunk-XS7FI4JA.js} +3 -3
  98. package/dist/chunk-XS7FI4JA.js.map +1 -0
  99. package/dist/{chunk-O5MP52U2.cjs → chunk-YD3JA36S.cjs} +4 -4
  100. package/dist/{chunk-O5MP52U2.cjs.map → chunk-YD3JA36S.cjs.map} +1 -1
  101. package/dist/chunk-YYODFQEU.cjs +25 -0
  102. package/dist/chunk-YYODFQEU.cjs.map +1 -0
  103. package/dist/{chunk-RN3RMBJZ.js → chunk-ZXBSARZX.js} +4 -4
  104. package/dist/{chunk-RN3RMBJZ.js.map → chunk-ZXBSARZX.js.map} +1 -1
  105. package/dist/entries/apps.cjs +43 -42
  106. package/dist/entries/apps.d.cts +11 -2
  107. package/dist/entries/apps.d.ts +11 -2
  108. package/dist/entries/apps.js +8 -7
  109. package/dist/entries/catalogs.d.cts +1 -1
  110. package/dist/entries/catalogs.d.ts +1 -1
  111. package/dist/entries/credits.cjs +156 -152
  112. package/dist/entries/credits.d.cts +41 -10
  113. package/dist/entries/credits.d.ts +41 -10
  114. package/dist/entries/credits.js +8 -8
  115. package/dist/entries/edl.cjs +130 -102
  116. package/dist/entries/edl.d.cts +74 -3
  117. package/dist/entries/edl.d.ts +74 -3
  118. package/dist/entries/edl.js +2 -2
  119. package/dist/entries/entities.cjs +126 -122
  120. package/dist/entries/entities.d.cts +2 -2
  121. package/dist/entries/entities.d.ts +2 -2
  122. package/dist/entries/entities.js +1 -1
  123. package/dist/entries/i18n.cjs +11 -11
  124. package/dist/entries/i18n.d.cts +2 -2
  125. package/dist/entries/i18n.d.ts +2 -2
  126. package/dist/entries/i18n.js +1 -1
  127. package/dist/entries/llm-models.cjs +63 -43
  128. package/dist/entries/llm-models.d.cts +71 -4
  129. package/dist/entries/llm-models.d.ts +71 -4
  130. package/dist/entries/llm-models.js +1 -1
  131. package/dist/entries/media.cjs +45 -41
  132. package/dist/entries/media.d.cts +39 -1
  133. package/dist/entries/media.d.ts +39 -1
  134. package/dist/entries/media.js +1 -1
  135. package/dist/entries/model-catalog.cjs +75 -63
  136. package/dist/entries/model-catalog.d.cts +2 -2
  137. package/dist/entries/model-catalog.d.ts +2 -2
  138. package/dist/entries/model-catalog.js +4 -4
  139. package/dist/entries/models.cjs +274 -210
  140. package/dist/entries/models.d.cts +3 -3
  141. package/dist/entries/models.d.ts +3 -3
  142. package/dist/entries/models.js +5 -5
  143. package/dist/entries/nodes.cjs +222 -201
  144. package/dist/entries/nodes.d.cts +48 -8
  145. package/dist/entries/nodes.d.ts +48 -8
  146. package/dist/entries/nodes.js +10 -9
  147. package/dist/entries/pipeline.cjs +149 -149
  148. package/dist/entries/pipeline.d.cts +12 -8
  149. package/dist/entries/pipeline.d.ts +12 -8
  150. package/dist/entries/pipeline.js +3 -3
  151. package/dist/entries/social.cjs +174 -174
  152. package/dist/entries/social.d.cts +13 -5
  153. package/dist/entries/social.d.ts +13 -5
  154. package/dist/entries/social.js +2 -2
  155. package/dist/entries/types.d.cts +1 -1
  156. package/dist/entries/types.d.ts +1 -1
  157. package/dist/entries/ugc.cjs +71 -71
  158. package/dist/entries/ugc.js +4 -4
  159. package/dist/entries/video.cjs +115 -115
  160. package/dist/entries/video.d.cts +4 -3
  161. package/dist/entries/video.d.ts +4 -3
  162. package/dist/entries/video.js +4 -4
  163. package/dist/entries/workflow.cjs +96 -95
  164. package/dist/entries/workflow.d.cts +19 -20
  165. package/dist/entries/workflow.d.ts +19 -20
  166. package/dist/entries/workflow.js +2 -1
  167. package/dist/index.cjs +1720 -1563
  168. package/dist/index.d.cts +10 -10
  169. package/dist/index.d.ts +10 -10
  170. package/dist/index.js +26 -25
  171. package/dist/{model-catalog-flJYaa-g.d.ts → model-catalog-VIHGmQL2.d.cts} +113 -1
  172. package/dist/{model-catalog-flJYaa-g.d.cts → model-catalog-VIHGmQL2.d.ts} +113 -1
  173. package/dist/{presentation-utils-BIqiCzSA.d.cts → presentation-utils-A4i92SYo.d.cts} +3 -1
  174. package/dist/{presentation-utils-BdiObtwq.d.ts → presentation-utils-DjdPtM9k.d.ts} +3 -1
  175. package/dist/{scene-node-types-DjenYFLO.d.ts → scene-node-types-Cvbtf-0a.d.cts} +147 -6
  176. package/dist/{scene-node-types-DjenYFLO.d.cts → scene-node-types-Cvbtf-0a.d.ts} +147 -6
  177. package/dist/{types-DffyGSy5.d.ts → types-CU6SQnMS.d.cts} +0 -5
  178. package/dist/{types-DffyGSy5.d.cts → types-CU6SQnMS.d.ts} +0 -5
  179. package/dist/{types-BRlFPEru.d.cts → types-DzUBR7yr.d.cts} +8 -1
  180. package/dist/{types-BRlFPEru.d.ts → types-DzUBR7yr.d.ts} +8 -1
  181. package/package.json +1 -1
  182. package/src/__tests__/camera-switch-contract.test.ts +33 -1
  183. package/src/__tests__/character-mention-slug.test.ts +0 -8
  184. package/src/__tests__/effective-tier.test.ts +3 -14
  185. package/src/__tests__/fixtures/camera-switch-speaker-map-parity.json +178 -0
  186. package/src/__tests__/fixtures/root-exports.baseline.json +21 -0
  187. package/src/__tests__/fixtures/speaker-map-camera-ids.json +26 -0
  188. package/src/__tests__/gvp-supported-providers.test.ts +1 -0
  189. package/src/__tests__/i18n-locale-completeness.test.ts +38 -3
  190. package/src/__tests__/llm-models.test.ts +200 -20
  191. package/src/__tests__/model-makers.test.ts +76 -0
  192. package/src/__tests__/node-preset-extract.test.ts +10 -0
  193. package/src/__tests__/presentation-utils.test.ts +15 -0
  194. package/src/__tests__/preview-gate-use-case.test.ts +16 -1
  195. package/src/__tests__/private-host.test.ts +53 -0
  196. package/src/__tests__/producer-types.test.ts +19 -0
  197. package/src/__tests__/run-continuation.test.ts +4 -1
  198. package/src/__tests__/speaker-map-contract.test.ts +48 -0
  199. package/src/__tests__/unit-contract-compose.test.ts +129 -0
  200. package/src/__tests__/unit-contracts.test.ts +134 -0
  201. package/src/__tests__/use-case-types.test.ts +33 -0
  202. package/src/__tests__/video-collapse-parity.test.ts +10 -0
  203. package/src/__tests__/video-frame-slot.test.ts +85 -0
  204. package/src/__tests__/video-mode-aliases.test.ts +1 -0
  205. package/src/__tests__/video-reference-only.test.ts +117 -0
  206. package/src/__tests__/vidu-q4-catalog.test.ts +230 -0
  207. package/src/camera-switch-contract.ts +36 -2
  208. package/src/component-types.ts +9 -0
  209. package/src/credit-identifiers.ts +81 -23
  210. package/src/entity-asset-types.ts +13 -0
  211. package/src/entries/credits.ts +1 -0
  212. package/src/entries/edl.ts +2 -0
  213. package/src/entries/llm-models.ts +5 -0
  214. package/src/entries/media.ts +1 -0
  215. package/src/entries/model-catalog.ts +6 -0
  216. package/src/entries/models.ts +25 -0
  217. package/src/entries/nodes.ts +5 -1
  218. package/src/fan-out-rows.ts +36 -3
  219. package/src/generate-mask.ts +40 -0
  220. package/src/generated/unit-contracts.ts +58 -0
  221. package/src/i18n/types.ts +13 -2
  222. package/src/json-kinds.ts +24 -4
  223. package/src/llm-models.ts +184 -31
  224. package/src/meta-ads-scrape.ts +16 -8
  225. package/src/model-catalog.ts +285 -13
  226. package/src/model-constants.ts +260 -5
  227. package/src/node-default-mappings.ts +3 -0
  228. package/src/node-preset-extract.ts +8 -0
  229. package/src/pipeline-types.ts +3 -0
  230. package/src/presentation-utils.ts +19 -12
  231. package/src/preview-gate.ts +4 -2
  232. package/src/private-host.ts +89 -59
  233. package/src/producer-types.ts +19 -19
  234. package/src/run-continuation.ts +26 -4
  235. package/src/speaker-layouts.ts +8 -3
  236. package/src/speaker-map-contract.ts +77 -0
  237. package/src/unit-contract-compose.ts +55 -0
  238. package/src/use-case-types.ts +19 -0
  239. package/src/video-ui-defaults.ts +7 -5
  240. package/dist/chunk-3CUFITU7.js.map +0 -1
  241. package/dist/chunk-5AUSSJIM.cjs.map +0 -1
  242. package/dist/chunk-5PC6JBGJ.cjs.map +0 -1
  243. package/dist/chunk-5U7VLG43.js.map +0 -1
  244. package/dist/chunk-6DKDOWBL.js.map +0 -1
  245. package/dist/chunk-AROWPFO2.js.map +0 -1
  246. package/dist/chunk-AVQK77G6.cjs.map +0 -1
  247. package/dist/chunk-C57NEO3X.js.map +0 -1
  248. package/dist/chunk-CK3GK34R.js.map +0 -1
  249. package/dist/chunk-E2TGXG6X.cjs.map +0 -1
  250. package/dist/chunk-HGC5JNVA.cjs.map +0 -1
  251. package/dist/chunk-IEBZHTPE.js.map +0 -1
  252. package/dist/chunk-ISJDAFKS.js.map +0 -1
  253. package/dist/chunk-J6KHW2E5.cjs.map +0 -1
  254. package/dist/chunk-JL4C5VJ7.cjs.map +0 -1
  255. package/dist/chunk-JX5YZ4DH.cjs.map +0 -1
  256. package/dist/chunk-M36G6SRP.js.map +0 -1
  257. package/dist/chunk-NT6IJH4L.cjs.map +0 -1
  258. package/dist/chunk-O7PUQLJ3.cjs.map +0 -1
  259. package/dist/chunk-PQHS255G.js.map +0 -1
  260. package/dist/chunk-PRYE7AZQ.cjs.map +0 -1
  261. package/dist/chunk-Q4CDQ2KO.js.map +0 -1
  262. package/dist/chunk-RJL7RCEM.cjs.map +0 -1
  263. package/dist/chunk-SES6GDBQ.cjs.map +0 -1
  264. package/dist/chunk-VIWSWVAW.js.map +0 -1
  265. package/dist/chunk-WDIBOWAA.js.map +0 -1
  266. package/dist/chunk-WNG7HRVA.cjs +0 -25
  267. package/dist/chunk-WNG7HRVA.cjs.map +0 -1
  268. package/dist/chunk-YBPBK5KI.js.map +0 -1
  269. package/dist/chunk-YYV35XOS.js.map +0 -1
  270. package/dist/chunk-Z2OL5AJD.cjs.map +0 -1
  271. package/dist/chunk-ZDFHA2EC.js.map +0 -1
  272. package/dist/chunk-ZRL2UFTH.cjs.map +0 -1
  273. package/dist/chunk-ZT77RY6R.js.map +0 -1
  274. package/src/__tests__/__snapshots__/prompt-builder-segments.test.ts.snap +0 -65
@@ -8,74 +8,104 @@
8
8
  * Literal hosts only. A name that RESOLVES to a private address is caught where
9
9
  * the connection is made (`safeFetch` re-validates the resolved IP); nothing
10
10
  * here does DNS.
11
+ *
12
+ * The documentation blocks (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24,
13
+ * 2001:db8::/32) are deliberately NOT refused: no network routes them, so they
14
+ * are no SSRF target, and this same rule decides which client addresses the
15
+ * server trusts and keys rate limits on (client-address.ts, hosting-ranges.ts),
16
+ * where they stand in for public addresses.
11
17
  */
12
18
 
19
+ function isPrivateOrReservedIPv4(a: number, b: number, c: number): boolean {
20
+ if (a === 0) return true // 0.0.0.0/8 "this network"
21
+ if (a === 127) return true // 127.0.0.0/8 loopback
22
+ if (a === 10) return true // 10.0.0.0/8 private
23
+ if (a === 172 && b >= 16 && b <= 31) return true // 172.16.0.0/12 private
24
+ if (a === 192 && b === 168) return true // 192.168.0.0/16 private
25
+ if (a === 169 && b === 254) return true // 169.254.0.0/16 link-local + AWS/GCP metadata
26
+ if (a === 100 && b >= 64 && b <= 127) return true // 100.64.0.0/10 CGN
27
+ if (a === 198 && (b === 18 || b === 19)) return true // 198.18.0.0/15 benchmarking
28
+ if (a === 192 && b === 0 && c === 0) return true // 192.0.0.0/24 IETF protocol assignments (DS-Lite, NAT64 discovery)
29
+ if (a >= 224) return true // 224.0.0.0/4 multicast + 240.0.0.0/4 reserved + 255.255.255.255
30
+ return false
31
+ }
32
+
33
+ /** The IPv4 address carried in two 16-bit groups. */
34
+ function embeddedIPv4IsPrivate(hi: number, lo: number): boolean {
35
+ return isPrivateOrReservedIPv4(hi >> 8, hi & 0xff, lo >> 8)
36
+ }
37
+
38
+ /**
39
+ * The eight 16-bit groups of an IPv6 address, or null when `ip` is not one.
40
+ * Reads `::` compression, a dotted IPv4 tail (`::ffff:127.0.0.1`) and a zone
41
+ * suffix (`fe80::1%eth0`).
42
+ */
43
+ function ipv6Groups(ip: string): number[] | null {
44
+ let text = ip.toLowerCase()
45
+ const zone = text.indexOf("%")
46
+ if (zone >= 0) text = text.slice(0, zone)
47
+ if (!text.includes(":") || !/^[0-9a-f:.]+$/.test(text)) return null
48
+
49
+ const lastColon = text.lastIndexOf(":")
50
+ const last = text.slice(lastColon + 1)
51
+ if (last.includes(".")) {
52
+ const parts = last.split(".")
53
+ if (parts.length !== 4 || parts.some((p) => !/^\d{1,3}$/.test(p) || Number(p) > 255)) return null
54
+ const [a, b, c, d] = parts.map(Number) as [number, number, number, number]
55
+ text = `${text.slice(0, lastColon + 1)}${((a << 8) | b).toString(16)}:${((c << 8) | d).toString(16)}`
56
+ }
57
+
58
+ const halves = text.split("::")
59
+ if (halves.length > 2) return null
60
+ const groupsOf = (part: string) => (part === "" ? [] : part.split(":"))
61
+ const head = groupsOf(halves[0] ?? "")
62
+ const tail = halves.length === 2 ? groupsOf(halves[1] ?? "") : []
63
+ if ([...head, ...tail].some((g) => !/^[0-9a-f]{1,4}$/.test(g))) return null
64
+ if (halves.length === 1) {
65
+ return head.length === 8 ? head.map((g) => parseInt(g, 16)) : null
66
+ }
67
+ const missing = 8 - head.length - tail.length
68
+ if (missing < 1) return null
69
+ return [...head, ...Array<string>(missing).fill("0"), ...tail].map((g) => parseInt(g, 16))
70
+ }
71
+
72
+ function isPrivateOrReservedIPv6(g: number[]): boolean {
73
+ const zeroThrough = (n: number) => g.slice(0, n).every((x) => x === 0)
74
+ const [g0 = 0, g1 = 0, g2 = 0, g3 = 0, , g5 = 0, g6 = 0, g7 = 0] = g
75
+ if (zeroThrough(8)) return true // :: unspecified
76
+ if (zeroThrough(7) && g7 === 1) return true // ::1 loopback
77
+ if (zeroThrough(5) && g5 === 0xffff) return embeddedIPv4IsPrivate(g6, g7) // ::ffff:0:0/96 IPv4-mapped
78
+ if (zeroThrough(6)) return embeddedIPv4IsPrivate(g6, g7) // ::/96 IPv4-compatible (deprecated)
79
+ if (g0 === 0x64 && g1 === 0xff9b && g.slice(2, 6).every((x) => x === 0)) {
80
+ return embeddedIPv4IsPrivate(g6, g7) // 64:ff9b::/96 NAT64: the IPv4 it reaches
81
+ }
82
+ if (g0 === 0x64 && g1 === 0xff9b && g2 === 1) return true // 64:ff9b:1::/48 local-use NAT64
83
+ if (g0 === 0x2002) return embeddedIPv4IsPrivate(g1, g2) // 2002::/16 6to4: the IPv4 it reaches
84
+ if (g0 === 0x2001 && g1 === 0) return true // 2001::/32 Teredo
85
+ if ((g0 & 0xfe00) === 0xfc00) return true // fc00::/7 unique-local
86
+ if ((g0 & 0xffc0) === 0xfe80) return true // fe80::/10 link-local (fe80:: to febf::)
87
+ if ((g0 & 0xffc0) === 0xfec0) return true // fec0::/10 site-local (deprecated)
88
+ if ((g0 & 0xff00) === 0xff00) return true // ff00::/8 multicast
89
+ return false
90
+ }
91
+
13
92
  /**
14
93
  * True if the IP belongs to a range we refuse to connect to from server-side
15
- * fetches. Covers IPv4 loopback/private/link-local/cloud-metadata/multicast
16
- * and the equivalent IPv6 classes (including IPv4-mapped IPv6 embeddings).
94
+ * fetches. Covers IPv4 loopback/private/link-local/cloud-metadata/CGN/
95
+ * multicast/reserved, the equivalent IPv6 classes, and every
96
+ * IPv6 form that carries an IPv4 address (mapped, compatible, NAT64, 6to4 —
97
+ * judged by the IPv4 they reach). Something with a colon that is not a valid
98
+ * IPv6 address is refused (fail closed); anything else that is not an IP (a
99
+ * host name) is not refused here.
17
100
  */
18
101
  export function isPrivateOrReservedIP(ip: string): boolean {
19
102
  const v4 = ip.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
20
103
  if (v4) {
21
- const a = Number(v4[1])
22
- const b = Number(v4[2])
23
- if (a === 0) return true // 0.0.0.0/8 "this network"
24
- if (a === 127) return true // 127.0.0.0/8 loopback
25
- if (a === 10) return true // 10.0.0.0/8 private
26
- if (a === 172 && b >= 16 && b <= 31) return true // 172.16.0.0/12 private
27
- if (a === 192 && b === 168) return true // 192.168.0.0/16 private
28
- if (a === 169 && b === 254) return true // 169.254.0.0/16 link-local + AWS/GCP metadata
29
- if (a === 100 && b >= 64 && b <= 127) return true // 100.64.0.0/10 CGN
30
- if (a === 198 && (b === 18 || b === 19)) return true // 198.18.0.0/15 benchmarking
31
- if (a >= 224) return true // 224.0.0.0/4 multicast + 240.0.0.0/4 reserved + 255.255.255.255
32
- return false
33
- }
34
- // IPv6. Hostnames from URL parsing come without brackets.
35
- const lower = ip.toLowerCase()
36
- if (lower === "::" || lower === "::1") return true // unspecified / loopback
37
- if (lower.startsWith("fe80:") || lower.startsWith("fe80::")) return true // link-local fe80::/10
38
- if (/^f[cd]/.test(lower)) return true // unique-local fc00::/7
39
- if (lower.startsWith("ff")) return true // multicast ff00::/8
40
- if (lower.startsWith("::ffff:")) {
41
- // IPv4-mapped IPv6. WHATWG URL parsing normalises the dotted-quad tail
42
- // into two hex quads (`::ffff:127.0.0.1` → `::ffff:7f00:1`), so handle
43
- // both forms.
44
- const tail = lower.slice(7)
45
- if (tail.includes(".")) {
46
- return isPrivateOrReservedIP(tail)
47
- }
48
- const parts = tail.split(":")
49
- if (parts.length === 2) {
50
- const hi = parseInt(parts[0] || "0", 16)
51
- const lo = parseInt(parts[1] || "0", 16)
52
- if (Number.isFinite(hi) && Number.isFinite(lo)) {
53
- const ipv4 = `${(hi >> 8) & 0xff}.${hi & 0xff}.${(lo >> 8) & 0xff}.${lo & 0xff}`
54
- return isPrivateOrReservedIP(ipv4)
55
- }
56
- }
57
- // Unrecognisable mapped form — fail closed, treat as reserved.
58
- return true
104
+ return isPrivateOrReservedIPv4(Number(v4[1]), Number(v4[2]), Number(v4[3]))
59
105
  }
60
- if (lower.startsWith("::") && lower !== "::" && lower !== "::1") {
61
- // IPv4-compatible IPv6 (deprecated ::/96): the low 32 bits are an IPv4.
62
- // WHATWG URL parsing presents `::127.0.0.1` as EITHER a dotted tail or two
63
- // hex quads (`::7f00:1`), exactly like the ::ffff: case above — handle both,
64
- // or the canonical hex form silently fails open.
65
- const tail = lower.slice(2)
66
- if (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(tail)) {
67
- return isPrivateOrReservedIP(tail)
68
- }
69
- const parts = tail.split(":")
70
- if (parts.length === 2 && /^[0-9a-f]{1,4}$/.test(parts[0]) && /^[0-9a-f]{1,4}$/.test(parts[1])) {
71
- const hi = parseInt(parts[0], 16)
72
- const lo = parseInt(parts[1], 16)
73
- if (Number.isFinite(hi) && Number.isFinite(lo)) {
74
- return isPrivateOrReservedIP(`${(hi >> 8) & 0xff}.${hi & 0xff}.${(lo >> 8) & 0xff}.${lo & 0xff}`)
75
- }
76
- }
77
- }
78
- return false
106
+ if (!ip.includes(":")) return false
107
+ const groups = ipv6Groups(ip)
108
+ return groups === null ? true : isPrivateOrReservedIPv6(groups)
79
109
  }
80
110
 
81
111
  /**
@@ -15,12 +15,17 @@
15
15
  * execution time (the prior drift bug, see issue 1 of the Task 4.1 review).
16
16
  */
17
17
  import { UGC_PRIMARY_HANDLE } from "./ugc-node-wires.js"
18
+ import { composeUnitRecord, composeUnitSet, unitFanOutEach, unitProducers } from "./unit-contract-compose.js"
19
+
20
+ // Each producer set below is its hand-written members ∪ the node units
21
+ // (tools/units/README.md) of that producer kind, from their generated contract
22
+ // rows, in that order — a type in both throws at load (composeUnitSet).
18
23
 
19
24
  /**
20
25
  * Source node types whose primary output is a video URL.
21
26
  * Mirrors the backend execution-graph VIDEO_SOURCE_TYPES verbatim.
22
27
  */
23
- export const VIDEO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
28
+ export const VIDEO_PRODUCER_TYPES: ReadonlySet<string> = composeUnitSet("VIDEO_PRODUCER_TYPES", [
24
29
  "image-to-video",
25
30
  "video-to-video",
26
31
  "switchx", // Beeble SwitchX relight/composite
@@ -79,8 +84,6 @@ export const VIDEO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
79
84
  "mask-composite",
80
85
  "transcode-video",
81
86
  "manual-edit",
82
- // Remove Audio: strips the audio track, emits a silent video.
83
- "remove-audio",
84
87
  // AI Avatar (HeyGen): avatar + voice/audio → video.
85
88
  "ai-avatar",
86
89
  // Cinematic Avatar (HeyGen cinematic_avatar): prompt + 1–3 avatar looks → video.
@@ -93,10 +96,6 @@ export const VIDEO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
93
96
  // Slideshow: 2-100 stills + one optional audio track → MP4 (local FFmpeg,
94
97
  // no provider). Same contract; images arrive via the image-collage lane.
95
98
  "slideshow",
96
- // GIF to Video: animated GIF → H.264 MP4 (local FFmpeg, no provider).
97
- // Emits generatedVideoUrl so it connects to any downstream video consumer
98
- // (e.g. a Seedance video-reference input) by an ordinary edge.
99
- "gif-to-video",
100
99
  // 3D Render Pro: authors a scene AND exports it in one operation, settling
101
100
  // with the standard `videoUrl` field. It is a video producer as much as it
102
101
  // is a composition producer — omitting it here is the "cannot connect the
@@ -111,7 +110,7 @@ export const VIDEO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
111
110
  // UGC Finish: the video's clips, finished, as one ordered list — a registered producer, so a
112
111
  // Bundle edge into Combine Videos routes each one as a video, in order.
113
112
  "ugc-finish-clips",
114
- ])
113
+ ], unitProducers("video"))
115
114
 
116
115
  /**
117
116
  * Source node types whose output media-type cannot be classified
@@ -139,7 +138,7 @@ export const VIDEO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
139
138
  * that fail at execution. Users wanting trigger → media flows
140
139
  * should wire through an upload node.
141
140
  */
142
- export const DYNAMIC_PRODUCER_TYPES: ReadonlySet<string> = new Set([
141
+ export const DYNAMIC_PRODUCER_TYPES: ReadonlySet<string> = composeUnitSet("DYNAMIC_PRODUCER_TYPES", [
143
142
  "list",
144
143
  "sub-workflow",
145
144
  "adjust-volume",
@@ -184,16 +183,13 @@ export const DYNAMIC_PRODUCER_TYPES: ReadonlySet<string> = new Set([
184
183
  // voice-changer/dubbing precedent. Asserted in producer-types.test.ts (the
185
184
  // suite does not fail on omission).
186
185
  "apply-edl",
187
- // Tighten Episode (podcast use-case node): the episode is video OR audio by
188
- // its `output` setting (an audio recording forces audio) — runtime-decided.
189
- "tighten-episode",
190
- ])
186
+ ], unitProducers("dynamic"))
191
187
 
192
188
  /**
193
189
  * Source node types whose primary output is an audio URL.
194
190
  * Mirrors the backend execution-graph AUDIO_SOURCE_TYPES verbatim.
195
191
  */
196
- export const AUDIO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
192
+ export const AUDIO_PRODUCER_TYPES: ReadonlySet<string> = composeUnitSet("AUDIO_PRODUCER_TYPES", [
197
193
  "text-to-speech",
198
194
  "text-to-audio",
199
195
  "generate-music",
@@ -227,7 +223,7 @@ export const AUDIO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
227
223
  "voice-design",
228
224
  // Extract Audio: demuxes a video's audio track to a standalone MP3.
229
225
  "extract-audio",
230
- ])
226
+ ], unitProducers("audio"))
231
227
 
232
228
  /**
233
229
  * Source node types whose output is an IMAGE URL — what feeds a References
@@ -236,7 +232,7 @@ export const AUDIO_PRODUCER_TYPES: ReadonlySet<string> = new Set([
236
232
  * handle migration and the MCP edge normalizer (`llm-chat`'s legacy `in`):
237
233
  * they used to keep separate copies, and the backend's lagged by eight types.
238
234
  */
239
- export const IMAGE_PRODUCER_TYPES: ReadonlySet<string> = new Set([
235
+ export const IMAGE_PRODUCER_TYPES: ReadonlySet<string> = composeUnitSet("IMAGE_PRODUCER_TYPES", [
240
236
  "upload-image", "generate-image", "edit-image", "image-to-image", "modify-image", "upscale-image", "remove-background",
241
237
  // extract-frame produces a single still image extracted from a video source.
242
238
  "extract-frame",
@@ -265,7 +261,7 @@ export const IMAGE_PRODUCER_TYPES: ReadonlySet<string> = new Set([
265
261
  // in IMAGE_SOURCE_TYPES on either engine: that set types the node's PRIMARY
266
262
  // asset, and 3D Render Pro's is the MP4.
267
263
  "pro-3d-render",
268
- ])
264
+ ], unitProducers("image"))
269
265
 
270
266
  /**
271
267
  * Source node types whose primary output is a LIST that, by default, fans out
@@ -315,8 +311,11 @@ export const FAN_OUT_EACH_TYPES: ReadonlySet<string> = new Set([
315
311
  * (`listResults`) — it exists only when the node itself ran once per item, so
316
312
  * after a single run the edge degrades to the single value, exactly like a
317
313
  * `FAN_OUT_EACH_TYPES` member with one item.
314
+ *
315
+ * Its hand-written rows ∪ the node units' rows (`contract.fanOutEach`,
316
+ * generated/unit-contracts.ts); a type in both refuses to load.
318
317
  */
319
- export const FAN_OUT_EACH_HANDLES: Readonly<Record<string, { readonly each: readonly string[]; readonly primary: string }>> = {
318
+ export const FAN_OUT_EACH_HANDLES: Readonly<Record<string, { readonly each: readonly string[]; readonly primary: string }>> = composeUnitRecord("FAN_OUT_EACH_HANDLES", {
320
319
  // Camera Switch run once per clip (Edit Plan in clips mode): each clip's
321
320
  // switched EDL is its own Apply EDL render. Its transcript is the same for
322
321
  // every clip (the master clock, renamed), so that handle stays one value
@@ -328,7 +327,8 @@ export const FAN_OUT_EACH_HANDLES: Readonly<Record<string, { readonly each: read
328
327
  // its list (`listResults`, the editor's `__listResults`). The pip an edge
329
328
  // with no handle reads is the UGC wires' own (UGC_PRIMARY_HANDLE).
330
329
  "ugc-clips": { each: ["clips"], primary: UGC_PRIMARY_HANDLE["ugc-clips"]! },
331
- }
330
+ // A node unit declares its row in unit.json (contract.fanOutEach); it is added after these.
331
+ }, unitFanOutEach())
332
332
 
333
333
  /**
334
334
  * Fan-out nodes whose iterations must ALL succeed: one failed item fails the
@@ -27,14 +27,29 @@ export const CONTINUATION_NOT_COMPLETED = "continuation_not_completed"
27
27
  * on the execution's output. */
28
28
  export const CONTINUATION_SUBSET_REQUIRED = "continuation_subset_required"
29
29
 
30
- /** A continue-from-failed run (use-case nodes) needs an execution that ended
31
- * `failed`: a completed run has nothing to resume, a running one is not over. */
30
+ /** A continue-from-failed run (a use-case node's, or a saved workflow's) needs
31
+ * an execution that ended `failed`: a completed run has nothing to resume, a
32
+ * running one is not over. */
32
33
  export const CONTINUATION_NOT_FAILED = "continuation_not_failed"
33
34
 
34
- /** A continue-from-failed (use-case nodes) of a run a later continuation of
35
- * it has superseded — that later one failed too: continue it instead. */
35
+ /** A continue-from-failed of a run a later continuation of it has superseded
36
+ * — that later one failed too: continue it instead. A saved workflow's run
37
+ * also answers it when a later continuation completed everything the run left
38
+ * (the work is done; its results are on that run). */
36
39
  export const CONTINUATION_SUPERSEDED = "continuation_superseded"
37
40
 
41
+ /** A continue-from-failed of a saved workflow's run whose lineage's newest
42
+ * continuation COMPLETED by stopping at a Preview review — of an Apply EDL
43
+ * render, or of a use-case node with review on (Tighten Episode): continuing
44
+ * again would only stop at the same Preview. The answer names that execution
45
+ * (`executionId`), its renders (`renderNodeIds`) and its use-case nodes
46
+ * (`reviewNodeIds`), and the run that finishes them (`next`:
47
+ * `continueFromExecutionId`, `nodeIds`, `inputOverrides`, to send to `/run`):
48
+ * for one render, its Render final (`renderFinal` with
49
+ * `continueFromExecutionId` set to that execution) is the same run. A
50
+ * continue-from-failed after it builds on that run. */
51
+ export const CONTINUATION_PREVIEW_PENDING = "continuation_preview_pending"
52
+
38
53
  /** A continue-from-failed (use-case nodes) of a failed run whose wrapper is not
39
54
  * settled yet (its fee not yet refunded): ask again in a moment. A retry
40
55
  * answer, not a refusal — outside `RUN_CONTINUATION_CODES`. */
@@ -46,6 +61,12 @@ export const CONTINUATION_SETTLING = "continuation_settling"
46
61
  export const RENDER_FINAL_ALREADY_RENDERED = "render_final_already_rendered"
47
62
  export const RENDER_FINAL_ALREADY_RENDERED_MESSAGE = "Already rendered with this edit."
48
63
 
64
+ /** A Render final (use-case nodes) of a clip pack whose review dropped every
65
+ * clip: there is nothing to render, so nothing runs and nothing is charged.
66
+ * A refusal of the request, outside `RUN_CONTINUATION_CODES`. */
67
+ export const USE_CASE_NOTHING_KEPT = "use_case_nothing_kept"
68
+ export const USE_CASE_NOTHING_KEPT_MESSAGE = "Every clip was dropped in the review: keep at least one clip to render the final."
69
+
49
70
  /** Every continuation refusal code. */
50
71
  export const RUN_CONTINUATION_CODES = [
51
72
  CONTINUATION_NOT_FOUND,
@@ -55,6 +76,7 @@ export const RUN_CONTINUATION_CODES = [
55
76
  CONTINUATION_SUBSET_REQUIRED,
56
77
  CONTINUATION_NOT_FAILED,
57
78
  CONTINUATION_SUPERSEDED,
79
+ CONTINUATION_PREVIEW_PENDING,
58
80
  ] as const
59
81
 
60
82
  export type RunContinuationCode = (typeof RUN_CONTINUATION_CODES)[number]
@@ -78,8 +78,13 @@ export function speakerSwitchOverlaps(type: string): boolean {
78
78
  return typeof type === "string" && type.startsWith(XFADE_SWITCH_PREFIX)
79
79
  }
80
80
 
81
+ /** A Speaker View switch id: `cut`, `pan`, `zoom`, or `xfade:<combine transition id>`
82
+ * (one per real ffmpeg xfade transition — `SPEAKER_SWITCH_IDS` lists them). Every
83
+ * sheet below is built from one, so a new switch outside this shape fails to compile. */
84
+ export type SpeakerSwitchId = "cut" | "pan" | "zoom" | `${typeof XFADE_SWITCH_PREFIX}${string}`
85
+
81
86
  export interface SpeakerSwitchSheet {
82
- /** "cut" | "pan" | "zoom" | `xfade:${combine id}` */
87
+ /** "cut" | "pan" | "zoom" | `xfade:${combine id}` (a `SpeakerSwitchId`) */
83
88
  readonly id: string
84
89
  /** = `speakerSwitchOverlaps(id)`, derived, never hand-set. */
85
90
  readonly overlaps: boolean
@@ -87,7 +92,7 @@ export interface SpeakerSwitchSheet {
87
92
  readonly requiresSameSource: boolean
88
93
  }
89
94
 
90
- const switchSheet = (id: string, requiresSameSource: boolean): SpeakerSwitchSheet => ({
95
+ const switchSheet = (id: SpeakerSwitchId, requiresSameSource: boolean): SpeakerSwitchSheet => ({
91
96
  id,
92
97
  overlaps: speakerSwitchOverlaps(id),
93
98
  requiresSameSource,
@@ -101,7 +106,7 @@ export const SPEAKER_SWITCHES: readonly SpeakerSwitchSheet[] = [
101
106
  switchSheet("cut", false),
102
107
  switchSheet("pan", true),
103
108
  switchSheet("zoom", false),
104
- ...COMBINE_TRANSITIONS.filter((t) => t.xfade !== null).map((t) => switchSheet(XFADE_SWITCH_PREFIX + t.id, false)),
109
+ ...COMBINE_TRANSITIONS.filter((t) => t.xfade !== null).map((t) => switchSheet(`${XFADE_SWITCH_PREFIX}${t.id}`, false)),
105
110
  ]
106
111
 
107
112
  export const SPEAKER_SWITCH_IDS: readonly string[] = SPEAKER_SWITCHES.map((s) => s.id)
@@ -0,0 +1,77 @@
1
+ /**
2
+ * speaker-map (podcast use-case nodes, decided 2026-10-12/17) — which camera
3
+ * each speaker is on, worked out from the cameras' own microphones: the
4
+ * structural pieces every caller shares (the canvas engines, MCP, the SDK).
5
+ * HOW the levels are compared is the server's. Pure, no I/O.
6
+ */
7
+ import type { Edl } from "./edl.js"
8
+
9
+ export const SPEAKER_MAP_VERSION = 1 as const
10
+ /** Recordings one run reads (cameras, plus the master when it also emits the edit). */
11
+ export const SPEAKER_MAP_MAX_SOURCES = 6
12
+ /** Candidate cameras a comparison needs. */
13
+ export const SPEAKER_MAP_MIN_CAMERAS = 2
14
+ /** How far the loudest camera must beat the next for the speaker to get it. */
15
+ export const SPEAKER_MAP_DEFAULT_MARGIN_DB = 3
16
+
17
+ export interface SpeakerMapConfidence {
18
+ /** The camera the speaker got; "" = none clear (shown on the wide shot). */
19
+ readonly camera: string
20
+ /** The loudest camera's lead over the next, in dB; null when there was nothing to compare. */
21
+ readonly marginDb: number | null
22
+ }
23
+
24
+ export interface SpeakerMapResult {
25
+ readonly version: typeof SPEAKER_MAP_VERSION
26
+ /** Transcript speaker label → camera source id; "" = no camera of their own. Feeds Camera Switch's `speakerMap`. */
27
+ readonly speakerMap: Readonly<Record<string, string>>
28
+ readonly confidence: Readonly<Record<string, SpeakerMapConfidence>>
29
+ readonly notes: readonly string[]
30
+ /** The recordings as one edit on the master clock (offsets applied, roles and speakers set, one segment). */
31
+ readonly edl?: Edl
32
+ }
33
+
34
+ const parse = (raw: unknown): unknown => {
35
+ if (typeof raw !== "string") return raw
36
+ try { return JSON.parse(raw) } catch { return undefined }
37
+ }
38
+ const isRecord = (v: unknown): v is Record<string, unknown> => !!v && typeof v === "object" && !Array.isArray(v)
39
+
40
+ const isConfidence = (v: unknown): boolean =>
41
+ isRecord(v) && typeof v.camera === "string" && (v.marginDb === null || (typeof v.marginDb === "number" && Number.isFinite(v.marginDb)))
42
+
43
+ /** A Speaker Map result (an object or its JSON string), or null when it is not
44
+ * one: every map value and confidence camera a string, every margin a finite
45
+ * number or null, every note a string — so a reader can trust each field. */
46
+ export function speakerMapResultOf(raw: unknown): SpeakerMapResult | null {
47
+ const v = parse(raw)
48
+ if (!isRecord(v) || v.version !== SPEAKER_MAP_VERSION || !isRecord(v.speakerMap) || !isRecord(v.confidence) || !Array.isArray(v.notes)) return null
49
+ if (!Object.values(v.speakerMap).every((c) => typeof c === "string")) return null
50
+ if (!Object.values(v.confidence).every(isConfidence)) return null
51
+ if (!v.notes.every((n) => typeof n === "string")) return null
52
+ return v as unknown as SpeakerMapResult
53
+ }
54
+
55
+ /** An ordinal key: a whole number from 1, written plainly ("1", "12" — never " 1", "01", "1.0", "1e0"). */
56
+ const ORDINAL = /^[1-9]\d*$/
57
+
58
+ /**
59
+ * The override keyed by ordinal ("1" = the first voice heard) as a map keyed
60
+ * by the transcript's own labels. `labels` is the transcript's speakers in
61
+ * first-heard order — the caller passes `transcriptSpeakerLabels(transcript)`,
62
+ * so this module imports nothing from camera-switch-contract (one import
63
+ * direction: camera-switch-contract → speaker-map-contract, no cycle for the
64
+ * structure ratchet). An ordinal past the transcript's speakers maps nobody,
65
+ * and so do a key that is not a plain ordinal and an override that is not an
66
+ * object (a hand-written workflow).
67
+ */
68
+ export function speakerMapByOrdinal(labels: readonly string[], byOrder: Readonly<Record<string, string>> | undefined): Record<string, string> {
69
+ if (!isRecord(byOrder)) return {}
70
+ const out: Record<string, string> = {}
71
+ for (const [ordinal, camera] of Object.entries(byOrder)) {
72
+ if (!ORDINAL.test(ordinal)) continue
73
+ const label = labels[Number(ordinal) - 1]
74
+ if (label !== undefined && typeof camera === "string") out[label] = camera
75
+ }
76
+ return out
77
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The node units' rows in @nodaro/shared (tools/units/README.md): the readers
3
+ * of `generated/unit-contracts.ts` and the one rule every table that composes
4
+ * them keeps — a type is hand-written or a node unit, never both. Internal:
5
+ * no entry exports this module, so it adds nothing to the published surface;
6
+ * the tables that compose its rows (producer-types, presentation-utils,
7
+ * json-kinds, fan-out-rows, preview-gate) are what consumers read.
8
+ */
9
+ import { UNIT_CONTRACTS, UNIT_FAN_OUT_EACH, UNIT_JSON_PIPS, UNIT_NON_PROMPT_INPUTS, UNIT_PRESENTS, UNIT_REVIEW_HOLDS } from "./generated/unit-contracts.js"
10
+
11
+ /**
12
+ * `legacy ∪ units` as a set, `legacy` first, refusing a type that is in both —
13
+ * a type lives in one place (G1; the editor's and the server's composeSet keep
14
+ * the same rule). Throws at module load, so any import of the set fails.
15
+ */
16
+ export function composeUnitSet(what: string, legacy: readonly string[], units: readonly string[]): ReadonlySet<string> {
17
+ const clash = units.filter((t) => legacy.includes(t))
18
+ if (clash.length > 0) throw new Error(`${what}: ${clash.join(", ")} is both hand-written and a node unit — a type lives in one place (tools/units/README.md)`)
19
+ return new Set([...legacy, ...units])
20
+ }
21
+
22
+ /**
23
+ * `legacy` with each unit row added after it, refusing a type that is in both
24
+ * or a unit row given twice — the record twin of `composeUnitSet`. Throws at
25
+ * module load, so any import of the record fails.
26
+ */
27
+ export function composeUnitRecord<V>(what: string, legacy: Readonly<Record<string, V>>, units: ReadonlyArray<readonly [string, V]>): Readonly<Record<string, V>> {
28
+ const out: Record<string, V> = { ...legacy }
29
+ for (const [type, value] of units) {
30
+ if (Object.hasOwn(legacy, type)) throw new Error(`${what}: ${type} is both hand-written and a node unit — a type lives in one place (tools/units/README.md)`)
31
+ if (Object.hasOwn(out, type)) throw new Error(`${what}: node unit ${type} has more than one row`)
32
+ out[type] = value
33
+ }
34
+ return out
35
+ }
36
+
37
+ /** The node units of one producer kind (`contract.producer`), in generated order. */
38
+ export const unitProducers = (kind: "audio" | "video" | "image" | "dynamic"): string[] =>
39
+ UNIT_CONTRACTS.filter(([, producer]) => producer === kind).map(([type]) => type)
40
+
41
+ /** The node units a published app shows as `kind` (`contract.presents`). */
42
+ export const unitsPresenting = (kind: "image" | "video" | "audio" | "text"): string[] =>
43
+ UNIT_PRESENTS.filter(([, presents]) => presents === kind).map(([type]) => type)
44
+
45
+ /** What each node unit's JSON (look) output pips carry (`contract.jsonPips`). */
46
+ export const unitJsonPips = (): ReadonlyArray<readonly [string, Readonly<Record<string, "transcript" | "edl" | "other">>]> => UNIT_JSON_PIPS
47
+
48
+ /** Each node unit's input pips that are never a prompt lane (`contract.nonPromptInputs`). */
49
+ export const unitNonPromptInputs = (): ReadonlyArray<readonly [string, ReadonlyArray<string>]> => UNIT_NON_PROMPT_INPUTS
50
+
51
+ /** The use-case units whose review-on run ends at a Preview that holds what follows (`contract.reviewHold`). */
52
+ export const unitReviewHolds = (): readonly string[] => UNIT_REVIEW_HOLDS
53
+
54
+ /** Each node unit's fan-out "each" outputs and primary pip (`contract.fanOutEach`), in generated order. */
55
+ export const unitFanOutEach = (): ReadonlyArray<readonly [string, { readonly each: ReadonlyArray<string>; readonly primary: string }]> => UNIT_FAN_OUT_EACH
@@ -0,0 +1,19 @@
1
+ import { UNIT_USE_CASE_TYPES } from "./generated/unit-contracts.js"
2
+
3
+ /**
4
+ * The use-case node types — each a route (`POST /v1/<type>`, `/estimate`,
5
+ * and `POST /v1/<type>/continue` to continue one of its runs): the node units
6
+ * whose execution.kind is "use-case" (generated/unit-contracts.ts), in their
7
+ * position order, the order every list of the types shows.
8
+ */
9
+ export const USE_CASE_NODE_TYPES = UNIT_USE_CASE_TYPES
10
+ export type UseCaseNodeType = (typeof USE_CASE_NODE_TYPES)[number]
11
+
12
+ /** Is `type` a use-case node type? Anything that is not one of the strings above is not (an object key like "constructor" included). */
13
+ export function isUseCaseNodeType(type: unknown): type is UseCaseNodeType {
14
+ return typeof type === "string" && (USE_CASE_NODE_TYPES as readonly string[]).includes(type)
15
+ }
16
+
17
+ if (new Set(USE_CASE_NODE_TYPES).size !== USE_CASE_NODE_TYPES.length) {
18
+ throw new Error(`USE_CASE_NODE_TYPES: ${USE_CASE_NODE_TYPES.join(", ")} lists a type twice — a type is one node unit`)
19
+ }
@@ -15,7 +15,8 @@
15
15
  * billing default differs from `resolutions[0]`; three surfaces then had to
16
16
  * agree, so they live here.
17
17
  *
18
- * The resolution fill is per-family ON PURPOSE. Wan 3.0 reads its DECLARED
18
+ * The resolution fill is per-family ON PURPOSE. Wan 3.0 (and Vidu Q4, whose
19
+ * ascending list starts at 540p) reads its DECLARED
19
20
  * billing default (PRICING_DEFAULT_RESOLUTION = 720p) because its catalog list
20
21
  * is ascending, so an index-0 fill would write 480p — a tier both `runWan3`
21
22
  * (which renders 720P) and the credit identifier (which bills the 720p row)
@@ -32,6 +33,7 @@ import {
32
33
  isSeedance2Provider,
33
34
  isMinimaxH3Provider,
34
35
  isWan3Provider,
36
+ isViduQ4Provider,
35
37
  isGeminiOmniProvider,
36
38
  } from "./model-constants.js"
37
39
  import { MODEL_CATALOG } from "./model-catalog.js"
@@ -46,7 +48,7 @@ export function uiAspectRatioFill(provider: string): string | undefined {
46
48
  /** See the file docstring — per-family on purpose; never a generic
47
49
  * PRICING_DEFAULT_RESOLUTION read (that would reprice seedance-2-5). */
48
50
  export function uiResolutionFill(provider: string): string | undefined {
49
- if (isWan3Provider(provider)) return PRICING_DEFAULT_RESOLUTION[provider]
51
+ if (isWan3Provider(provider) || isViduQ4Provider(provider)) return PRICING_DEFAULT_RESOLUTION[provider]
50
52
  if (isSeedance2Provider(provider)) return MODEL_CATALOG[provider]?.resolutions?.[0]
51
53
  return undefined
52
54
  }
@@ -55,12 +57,12 @@ export function uiResolutionFill(provider: string): string | undefined {
55
57
  * Duration the node RENDERS and BILLS when `data.duration` is unset, for the
56
58
  * families whose credit identifier declares a duration fallback that is NOT
57
59
  * `durations[0]`. Wan 3.0's bare identifier is the 5s tier while its ladder
58
- * starts at 2s; the Gemini Omni family's is the 8s tier while its ladder starts
59
- * at 4s. Everyone else falls back to the first listed duration, so this returns
60
+ * starts at 2s; Vidu Q4's is the 5s tier while its ladder starts at 3s; the
61
+ * Gemini Omni family's is the 8s tier while its ladder starts at 4s. Everyone else falls back to the first listed duration, so this returns
60
62
  * undefined and the caller keeps `durations[0]`.
61
63
  */
62
64
  export function uiDurationFill(provider: string): number | undefined {
63
- if (isWan3Provider(provider)) return 5
65
+ if (isWan3Provider(provider) || isViduQ4Provider(provider)) return 5
64
66
  if (isGeminiOmniProvider(provider)) return 8
65
67
  return undefined
66
68
  }