@nodaro/shared 3.70.0 → 3.71.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 (136) hide show
  1. package/dist/{chunk-FMQ43SJP.cjs → chunk-4A3ITJJB.cjs} +6 -6
  2. package/dist/{chunk-FMQ43SJP.cjs.map → chunk-4A3ITJJB.cjs.map} +1 -1
  3. package/dist/{chunk-XBHDXURR.cjs → chunk-4HV3LY4A.cjs} +78 -78
  4. package/dist/chunk-4HV3LY4A.cjs.map +1 -0
  5. package/dist/{chunk-52JNQG4K.js → chunk-6FUVGATF.js} +3 -3
  6. package/dist/{chunk-52JNQG4K.js.map → chunk-6FUVGATF.js.map} +1 -1
  7. package/dist/{chunk-GC77W57T.cjs → chunk-6PEWM2B3.cjs} +9 -9
  8. package/dist/{chunk-GC77W57T.cjs.map → chunk-6PEWM2B3.cjs.map} +1 -1
  9. package/dist/{chunk-BIQ7COJP.js → chunk-BO6IKV24.js} +5 -5
  10. package/dist/{chunk-BIQ7COJP.js.map → chunk-BO6IKV24.js.map} +1 -1
  11. package/dist/{chunk-IKN54UGB.js → chunk-BQV6NV7E.js} +3 -3
  12. package/dist/{chunk-IKN54UGB.js.map → chunk-BQV6NV7E.js.map} +1 -1
  13. package/dist/{chunk-LTBM2KMY.js → chunk-BVP4M5AK.js} +235 -9
  14. package/dist/chunk-BVP4M5AK.js.map +1 -0
  15. package/dist/{chunk-OW5AXH2Y.js → chunk-CL7ECTK2.js} +5 -4
  16. package/dist/chunk-CL7ECTK2.js.map +1 -0
  17. package/dist/{chunk-R22UHRR6.js → chunk-COA2OJIH.js} +39 -23
  18. package/dist/chunk-COA2OJIH.js.map +1 -0
  19. package/dist/{chunk-HW6TLOK4.cjs → chunk-DRPHRE4J.cjs} +2 -2
  20. package/dist/{chunk-HW6TLOK4.cjs.map → chunk-DRPHRE4J.cjs.map} +1 -1
  21. package/dist/{chunk-EWNDK4FV.js → chunk-F3XG5J5V.js} +3 -3
  22. package/dist/{chunk-EWNDK4FV.js.map → chunk-F3XG5J5V.js.map} +1 -1
  23. package/dist/{chunk-4U7QAUV3.cjs → chunk-H52P7DD2.cjs} +61 -61
  24. package/dist/{chunk-4U7QAUV3.cjs.map → chunk-H52P7DD2.cjs.map} +1 -1
  25. package/dist/{chunk-MZ772ZXA.cjs → chunk-HUCGHMOI.cjs} +17 -17
  26. package/dist/{chunk-MZ772ZXA.cjs.map → chunk-HUCGHMOI.cjs.map} +1 -1
  27. package/dist/{chunk-PYYYBINP.cjs → chunk-I4C6ZYU4.cjs} +6 -6
  28. package/dist/{chunk-PYYYBINP.cjs.map → chunk-I4C6ZYU4.cjs.map} +1 -1
  29. package/dist/{chunk-QCVQVKCI.js → chunk-JPSKVBYB.js} +3 -3
  30. package/dist/{chunk-QCVQVKCI.js.map → chunk-JPSKVBYB.js.map} +1 -1
  31. package/dist/{chunk-QVAUBB2T.js → chunk-K2P7KOIT.js} +9 -9
  32. package/dist/{chunk-QVAUBB2T.js.map → chunk-K2P7KOIT.js.map} +1 -1
  33. package/dist/{chunk-QV32JI4L.cjs → chunk-K5WRF2F3.cjs} +4 -4
  34. package/dist/{chunk-QV32JI4L.cjs.map → chunk-K5WRF2F3.cjs.map} +1 -1
  35. package/dist/{chunk-YLDY23N2.js → chunk-KD4UUCMW.js} +5 -5
  36. package/dist/{chunk-YLDY23N2.js.map → chunk-KD4UUCMW.js.map} +1 -1
  37. package/dist/{chunk-OZHE77T3.cjs → chunk-LBKMQAXD.cjs} +9 -9
  38. package/dist/{chunk-OZHE77T3.cjs.map → chunk-LBKMQAXD.cjs.map} +1 -1
  39. package/dist/{chunk-HBRDKHIW.cjs → chunk-MI4WEFJ4.cjs} +21 -21
  40. package/dist/{chunk-HBRDKHIW.cjs.map → chunk-MI4WEFJ4.cjs.map} +1 -1
  41. package/dist/{chunk-DOY47F7S.cjs → chunk-MN7BUGXF.cjs} +7 -7
  42. package/dist/{chunk-DOY47F7S.cjs.map → chunk-MN7BUGXF.cjs.map} +1 -1
  43. package/dist/{chunk-BLGZW3UF.cjs → chunk-NNCHSLFD.cjs} +291 -20
  44. package/dist/chunk-NNCHSLFD.cjs.map +1 -0
  45. package/dist/{chunk-NS34PZ2S.js → chunk-PPXUSZJU.js} +3 -3
  46. package/dist/{chunk-NS34PZ2S.js.map → chunk-PPXUSZJU.js.map} +1 -1
  47. package/dist/{chunk-PKWRAMVB.js → chunk-QME5O4NG.js} +7 -5
  48. package/dist/chunk-QME5O4NG.js.map +1 -0
  49. package/dist/{chunk-42ICEVUN.js → chunk-SAOIGWA2.js} +3 -3
  50. package/dist/{chunk-42ICEVUN.js.map → chunk-SAOIGWA2.js.map} +1 -1
  51. package/dist/{chunk-V6TC2NDG.js → chunk-SHSDGAI4.js} +4 -4
  52. package/dist/{chunk-V6TC2NDG.js.map → chunk-SHSDGAI4.js.map} +1 -1
  53. package/dist/{chunk-JEUZNHLL.cjs → chunk-SR7WH4FX.cjs} +33 -33
  54. package/dist/{chunk-JEUZNHLL.cjs.map → chunk-SR7WH4FX.cjs.map} +1 -1
  55. package/dist/{chunk-2VOXSVIE.js → chunk-SZ7ALYPK.js} +3 -3
  56. package/dist/{chunk-2VOXSVIE.js.map → chunk-SZ7ALYPK.js.map} +1 -1
  57. package/dist/{chunk-O53P2D4V.js → chunk-T4YYUI5Q.js} +3 -3
  58. package/dist/{chunk-O53P2D4V.js.map → chunk-T4YYUI5Q.js.map} +1 -1
  59. package/dist/{chunk-HWBLZSM3.cjs → chunk-TOYWEF6E.cjs} +39 -23
  60. package/dist/chunk-TOYWEF6E.cjs.map +1 -0
  61. package/dist/{chunk-FWPGRC4X.cjs → chunk-U6APV2PO.cjs} +5 -5
  62. package/dist/{chunk-FWPGRC4X.cjs.map → chunk-U6APV2PO.cjs.map} +1 -1
  63. package/dist/{chunk-QCZYYAPZ.cjs → chunk-UJIPIVTB.cjs} +48 -48
  64. package/dist/{chunk-QCZYYAPZ.cjs.map → chunk-UJIPIVTB.cjs.map} +1 -1
  65. package/dist/{chunk-KKFFQUMM.js → chunk-VZIMLPDC.js} +5 -5
  66. package/dist/chunk-VZIMLPDC.js.map +1 -0
  67. package/dist/{chunk-PWIKUOLB.cjs → chunk-W4CJ2P3F.cjs} +8 -8
  68. package/dist/{chunk-PWIKUOLB.cjs.map → chunk-W4CJ2P3F.cjs.map} +1 -1
  69. package/dist/{chunk-HP3YIWNJ.js → chunk-WARGPM7P.js} +2 -2
  70. package/dist/{chunk-HP3YIWNJ.js.map → chunk-WARGPM7P.js.map} +1 -1
  71. package/dist/{chunk-POZBRZUM.cjs → chunk-WHK3HTFY.cjs} +41 -41
  72. package/dist/{chunk-POZBRZUM.cjs.map → chunk-WHK3HTFY.cjs.map} +1 -1
  73. package/dist/{chunk-H2E4QXEZ.js → chunk-X3YRSRHP.js} +3 -3
  74. package/dist/{chunk-H2E4QXEZ.js.map → chunk-X3YRSRHP.js.map} +1 -1
  75. package/dist/{chunk-HA2PVTER.js → chunk-XK75VOEH.js} +4 -4
  76. package/dist/{chunk-HA2PVTER.js.map → chunk-XK75VOEH.js.map} +1 -1
  77. package/dist/{chunk-5DRSENY3.cjs → chunk-YHZUTPZL.cjs} +14 -12
  78. package/dist/{chunk-PKWRAMVB.js.map → chunk-YHZUTPZL.cjs.map} +1 -1
  79. package/dist/{chunk-WHV7MDNC.cjs → chunk-ZJQ2L3MI.cjs} +5 -3
  80. package/dist/chunk-ZJQ2L3MI.cjs.map +1 -0
  81. package/dist/entries/apps.cjs +42 -42
  82. package/dist/entries/apps.js +7 -7
  83. package/dist/entries/credits.cjs +418 -238
  84. package/dist/entries/credits.d.cts +262 -1
  85. package/dist/entries/credits.d.ts +262 -1
  86. package/dist/entries/credits.js +9 -9
  87. package/dist/entries/edl.cjs +60 -60
  88. package/dist/entries/edl.d.cts +96 -1
  89. package/dist/entries/edl.d.ts +96 -1
  90. package/dist/entries/edl.js +1 -1
  91. package/dist/entries/model-catalog.cjs +133 -133
  92. package/dist/entries/model-catalog.js +4 -4
  93. package/dist/entries/models.cjs +404 -404
  94. package/dist/entries/models.js +5 -5
  95. package/dist/entries/nodes.cjs +212 -212
  96. package/dist/entries/nodes.js +8 -8
  97. package/dist/entries/pipeline.cjs +153 -153
  98. package/dist/entries/pipeline.js +3 -3
  99. package/dist/entries/social.cjs +195 -191
  100. package/dist/entries/social.d.cts +9 -3
  101. package/dist/entries/social.d.ts +9 -3
  102. package/dist/entries/social.js +1 -1
  103. package/dist/entries/ugc.cjs +71 -71
  104. package/dist/entries/ugc.js +4 -4
  105. package/dist/entries/video.cjs +152 -152
  106. package/dist/entries/video.js +6 -6
  107. package/dist/index.cjs +1812 -1628
  108. package/dist/index.d.cts +3 -3
  109. package/dist/index.d.ts +3 -3
  110. package/dist/index.js +20 -20
  111. package/package.json +1 -1
  112. package/src/__tests__/audio-isolation-pricing.test.ts +49 -0
  113. package/src/__tests__/competitors.test.ts +6 -1
  114. package/src/__tests__/credit-identifiers.test.ts +9 -10
  115. package/src/__tests__/motion-transfer-pricing.test.ts +252 -0
  116. package/src/__tests__/video-to-video-pricing.test.ts +151 -0
  117. package/src/audio-isolation-pricing.ts +80 -0
  118. package/src/competitors.ts +8 -2
  119. package/src/credit-identifiers.ts +6 -0
  120. package/src/entries/credits.ts +54 -0
  121. package/src/entries/edl.ts +2 -0
  122. package/src/entries/social.ts +1 -0
  123. package/src/model-catalog.ts +34 -18
  124. package/src/motion-transfer-pricing.ts +239 -0
  125. package/src/producer-types.ts +2 -0
  126. package/src/use-case-output.ts +102 -0
  127. package/src/video-to-video-pricing.ts +248 -0
  128. package/dist/chunk-5DRSENY3.cjs.map +0 -1
  129. package/dist/chunk-BLGZW3UF.cjs.map +0 -1
  130. package/dist/chunk-HWBLZSM3.cjs.map +0 -1
  131. package/dist/chunk-KKFFQUMM.js.map +0 -1
  132. package/dist/chunk-LTBM2KMY.js.map +0 -1
  133. package/dist/chunk-OW5AXH2Y.js.map +0 -1
  134. package/dist/chunk-R22UHRR6.js.map +0 -1
  135. package/dist/chunk-WHV7MDNC.cjs.map +0 -1
  136. package/dist/chunk-XBHDXURR.cjs.map +0 -1
@@ -0,0 +1,248 @@
1
+ /**
2
+ * How a Video to Video run on HappyHorse Edit or Wan 2.7 VideoEdit is priced
3
+ * (decided 2026-11-18): from the length of the clip it edits, as the server
4
+ * reads it from the file before anything is held. Every other Video to Video
5
+ * model keeps its flat row and is never read.
6
+ *
7
+ * - HappyHorse Edit is charged per started half-second of the clip, at its
8
+ * size's row (the price of four clip seconds): row × half-seconds ÷ 8,
9
+ * rounded up once, marked up once. The size priced is the size sent
10
+ * ({@link videoToVideoSentResolution}): 1080p only when the request says
11
+ * so, else 720p. A clip shorter than 3 s or longer than 60 s is refused.
12
+ * - Wan 2.7 VideoEdit is charged per second of the clip it delivers (the
13
+ * clip's length, or the shorter `videoEditDuration` it is asked for),
14
+ * rounded up to a whole second after the house grace — at its row (the price
15
+ * of four seconds) × seconds ÷ 4, rounded up once — but never below its flat
16
+ * row (`wan-videoedit`): a run is charged the LARGER of the two. A clip
17
+ * shorter than 2 s or longer than 10 s (past `CLIP_PRICE_GRACE_SEC`) is
18
+ * refused; a clip within the grace is priced at 10 s.
19
+ *
20
+ * The route, the workflow run, the MCP verb (which calls the route), `POST
21
+ * /v1/quote` and both estimates read this one module.
22
+ */
23
+ import { CLIP_PRICE_GRACE_SEC, gracedMeasuredSec } from "./priced-clip-seconds.js"
24
+ import { MODEL_CATALOG } from "./model-catalog.js"
25
+
26
+ /** Float noise: a length that is arithmetic can land a hair past an edge, and must not be refused or rounded up for it. */
27
+ const FLOAT_NOISE_SEC = 1e-9
28
+
29
+ /** The Video to Video models priced by the length of their clip. */
30
+ export const CLIP_PRICED_V2V_PROVIDERS = ["happyhorse-edit", "wan-videoedit"] as const
31
+ export type ClipPricedV2vProvider = (typeof CLIP_PRICED_V2V_PROVIDERS)[number]
32
+
33
+ /** Whether a Video to Video run on `provider` is priced by its clip's length (and so reads the clip before it holds anything). */
34
+ export function isClipPricedV2vProvider(provider: unknown): provider is ClipPricedV2vProvider {
35
+ return typeof provider === "string" && (CLIP_PRICED_V2V_PROVIDERS as readonly string[]).includes(provider)
36
+ }
37
+
38
+ /** The shortest and longest clip HappyHorse Edit takes, in seconds. */
39
+ export const HAPPYHORSE_EDIT_MIN_SEC = 3
40
+ export const HAPPYHORSE_EDIT_MAX_SEC = 60
41
+ /** The shortest and longest clip Wan 2.7 VideoEdit takes, in seconds. */
42
+ export const WAN_VIDEOEDIT_MIN_SEC = 2
43
+ export const WAN_VIDEOEDIT_MAX_SEC = 10
44
+
45
+ /** Wan 2.7 VideoEdit's flat row: what a run cost before it was priced by length, and the least it costs now. */
46
+ export const WAN_VIDEOEDIT_FLOOR_CREDIT_ID = "wan-videoedit"
47
+
48
+ /** A rate: the row that prices `rateSeconds` seconds of clip. */
49
+ export interface V2vClipRate {
50
+ readonly rateId: string
51
+ readonly rateSeconds: number
52
+ }
53
+
54
+ const WAN_VIDEOEDIT_1080P_RATE: V2vClipRate = { rateId: "wan-videoedit:1080p:per-4s", rateSeconds: 4 }
55
+
56
+ /**
57
+ * The rates, keyed `<provider>:<size priced>`. A row prices four seconds so
58
+ * its value stays a whole credit, and dividing by 4 (or 8 half-seconds) is
59
+ * exact in floating point. Wan 2.7 VideoEdit at 720p is charged at its 1080p
60
+ * rate for now: giving it its own is this one entry (plus its row).
61
+ */
62
+ export const V2V_CLIP_RATES: Readonly<Record<string, V2vClipRate>> = {
63
+ "happyhorse-edit:720p": { rateId: "happyhorse-edit:720p:per-4s", rateSeconds: 4 },
64
+ "happyhorse-edit:1080p": { rateId: "happyhorse-edit:1080p:per-4s", rateSeconds: 4 },
65
+ "wan-videoedit:1080p": WAN_VIDEOEDIT_1080P_RATE,
66
+ "wan-videoedit:720p": WAN_VIDEOEDIT_1080P_RATE,
67
+ }
68
+
69
+ /** Every rate row, once. */
70
+ export const V2V_CLIP_RATE_IDS: readonly string[] = [...new Set(Object.values(V2V_CLIP_RATES).map((r) => r.rateId))]
71
+
72
+ /**
73
+ * The seeded credits of one of these models' rows, from their catalog entries'
74
+ * pricing (held to `STATIC_CREDIT_COSTS` by the catalog parity test): the rows
75
+ * an estimate with no live price table of its own compares.
76
+ */
77
+ export function v2vSeededRowCredits(id: string): number | undefined {
78
+ for (const provider of CLIP_PRICED_V2V_PROVIDERS) {
79
+ const row = MODEL_CATALOG[provider]?.pricing.find((p) => p.identifier === id)
80
+ if (row) return row.credits
81
+ }
82
+ return undefined
83
+ }
84
+
85
+ /** The shortest clip `provider` takes. */
86
+ export function videoToVideoClipMinSec(provider: ClipPricedV2vProvider): number {
87
+ return provider === "happyhorse-edit" ? HAPPYHORSE_EDIT_MIN_SEC : WAN_VIDEOEDIT_MIN_SEC
88
+ }
89
+
90
+ /** The longest clip `provider` takes. */
91
+ export function videoToVideoClipMaxSec(provider: ClipPricedV2vProvider): number {
92
+ return provider === "happyhorse-edit" ? HAPPYHORSE_EDIT_MAX_SEC : WAN_VIDEOEDIT_MAX_SEC
93
+ }
94
+
95
+ /**
96
+ * The resolution a Video to Video run SENDS. HappyHorse Edit: "1080p" only
97
+ * when the request names it, else "720p" — what it is priced at too, so a
98
+ * size left on the node by another model never reaches the model unpriced.
99
+ * Every other model: the value as given (absent stays absent).
100
+ */
101
+ export function videoToVideoSentResolution(provider: unknown, resolution: unknown): string | undefined {
102
+ if (provider === "happyhorse-edit") return resolution === "1080p" ? "1080p" : "720p"
103
+ return typeof resolution === "string" && resolution !== "" ? resolution : undefined
104
+ }
105
+
106
+ /** The size a clip-priced run is CHARGED at: HappyHorse Edit's sent size; Wan 2.7 VideoEdit 720p only when named (it renders 1080p otherwise). */
107
+ function chargedSize(provider: ClipPricedV2vProvider, resolution: unknown): "720p" | "1080p" {
108
+ if (provider === "happyhorse-edit") return videoToVideoSentResolution(provider, resolution) as "720p" | "1080p"
109
+ return resolution === "720p" ? "720p" : "1080p"
110
+ }
111
+
112
+ /** The rate a run of `provider` at `resolution` is charged at, or undefined for a model not priced by its clip. */
113
+ export function videoToVideoClipRateOf(provider: unknown, resolution: unknown): V2vClipRate | undefined {
114
+ if (!isClipPricedV2vProvider(provider)) return undefined
115
+ return V2V_CLIP_RATES[`${provider}:${chargedSize(provider, resolution)}`]
116
+ }
117
+
118
+ /** The output length Wan 2.7 VideoEdit is asked for: `videoEditDuration` "5" / "10", else 0 (as long as the clip). */
119
+ function wanAskedSeconds(videoEditDuration: unknown): number {
120
+ const n = typeof videoEditDuration === "number" ? videoEditDuration : typeof videoEditDuration === "string" ? Number(videoEditDuration) : 0
121
+ return Number.isFinite(n) && n > 0 ? n : 0
122
+ }
123
+
124
+ /**
125
+ * The seconds a clip of `clipSec` is billed for. HappyHorse Edit: every
126
+ * started half-second of the clip (float noise forgiven, nothing more): 3.00 s
127
+ * is 3, 10.04 s is 10.5. Wan 2.7 VideoEdit: the clip it delivers — the clip's
128
+ * length, or `videoEditDuration` when that is shorter — rounded up to a whole
129
+ * second after `CLIP_PRICE_GRACE_SEC`, at least 1 and at most its limit. THE
130
+ * one rounding every lane reads.
131
+ */
132
+ export function videoToVideoBilledSeconds(provider: ClipPricedV2vProvider, clipSec: number, videoEditDuration?: unknown): number {
133
+ if (provider === "happyhorse-edit") return Math.max(1, Math.ceil(2 * clipSec - FLOAT_NOISE_SEC)) / 2
134
+ const asked = wanAskedSeconds(videoEditDuration)
135
+ const output = asked > 0 ? Math.min(asked, clipSec) : clipSec
136
+ return Math.min(WAN_VIDEOEDIT_MAX_SEC, Math.max(1, Math.ceil(gracedMeasuredSec(output))))
137
+ }
138
+
139
+ /** What the length check answers for a clip. */
140
+ export type V2vClipLengthCheck =
141
+ | { readonly ok: true; readonly billedSeconds: number }
142
+ | { readonly ok: false; readonly code: "video_too_short" | "video_too_long"; readonly message: string }
143
+
144
+ const LABEL: Readonly<Record<ClipPricedV2vProvider, string>> = {
145
+ "happyhorse-edit": "HappyHorse Edit",
146
+ "wan-videoedit": "Wan 2.7 VideoEdit",
147
+ }
148
+
149
+ /**
150
+ * Whether a clip of `clipSec` can run on `provider`, and the seconds it is
151
+ * billed for. Shorter than the model's minimum is refused; longer than its
152
+ * maximum is refused — past float noise on HappyHorse Edit, past
153
+ * `CLIP_PRICE_GRACE_SEC` on Wan 2.7 VideoEdit (a clip within it is billed at
154
+ * the limit).
155
+ */
156
+ export function checkVideoToVideoClipLength(provider: ClipPricedV2vProvider, clipSec: number, videoEditDuration?: unknown): V2vClipLengthCheck {
157
+ const min = videoToVideoClipMinSec(provider)
158
+ const max = videoToVideoClipMaxSec(provider)
159
+ if (clipSec < min - FLOAT_NOISE_SEC) {
160
+ return {
161
+ ok: false,
162
+ code: "video_too_short",
163
+ message: `The video is ${clipSec.toFixed(1)} seconds. ${LABEL[provider]} needs a video of at least ${min} seconds.`,
164
+ }
165
+ }
166
+ const grace = provider === "wan-videoedit" ? CLIP_PRICE_GRACE_SEC : 0
167
+ if (clipSec > max + grace + FLOAT_NOISE_SEC) {
168
+ return {
169
+ ok: false,
170
+ code: "video_too_long",
171
+ message: `The video is ${clipSec.toFixed(1)} seconds. ${LABEL[provider]} takes at most ${max} seconds. Trim the video first.`,
172
+ }
173
+ }
174
+ return { ok: true, billedSeconds: videoToVideoBilledSeconds(provider, Math.min(clipSec, max), videoEditDuration) }
175
+ }
176
+
177
+ /** A clip-priced run's price: the row it reserves and, for a rate, the units of that row. */
178
+ export interface V2vClipPrice {
179
+ /** The row the run reserves: a rate row, or Wan 2.7 VideoEdit's flat row while it is the larger. */
180
+ readonly creditId: string
181
+ /** Units of the row the run is charged (billed seconds ÷ the rate's seconds); undefined for a row charged once. */
182
+ readonly units?: number
183
+ }
184
+
185
+ /**
186
+ * The price of a run of `provider` at `resolution` billed for `billedSeconds`.
187
+ *
188
+ * Wan 2.7 VideoEdit is charged the LARGER of its flat row and its rate for the
189
+ * billed seconds (its rate row × seconds ÷ 4, rounded up), so a run never
190
+ * costs less than the flat row and costs more once its length passes what
191
+ * that row covers; a tie keeps the flat row. `rowOf` gives a row's credits —
192
+ * the caller's own table (the server's live rows, an estimate's price table),
193
+ * the same kind for both rows; a row it does not know never wins.
194
+ */
195
+ export function videoToVideoClipPrice(
196
+ provider: ClipPricedV2vProvider,
197
+ resolution: unknown,
198
+ billedSeconds: number,
199
+ rowOf: (id: string) => number | undefined,
200
+ ): V2vClipPrice {
201
+ const rate = videoToVideoClipRateOf(provider, resolution)!
202
+ const units = billedSeconds / rate.rateSeconds
203
+ if (provider === "happyhorse-edit") return { creditId: rate.rateId, units }
204
+ const rateRow = rowOf(rate.rateId)
205
+ const floorRow = rowOf(WAN_VIDEOEDIT_FLOOR_CREDIT_ID)
206
+ const rateWins = rateRow !== undefined && (floorRow === undefined || Math.ceil(rateRow * units) > floorRow)
207
+ return rateWins ? { creditId: rate.rateId, units } : { creditId: WAN_VIDEOEDIT_FLOOR_CREDIT_ID }
208
+ }
209
+
210
+ /**
211
+ * The fewest billed seconds at which Wan 2.7 VideoEdit at `resolution` is
212
+ * charged by its rate rather than its flat row, given `rowOf`; undefined when
213
+ * the rate never passes the flat row inside the model's limit.
214
+ */
215
+ export function wanVideoEditRateFromSeconds(resolution: unknown, rowOf: (id: string) => number | undefined): number | undefined {
216
+ for (let s = 1; s <= WAN_VIDEOEDIT_MAX_SEC; s++) {
217
+ if (videoToVideoClipPrice("wan-videoedit", resolution, s, rowOf).units !== undefined) return s
218
+ }
219
+ return undefined
220
+ }
221
+
222
+ /**
223
+ * The billed seconds an ESTIMATE quotes before the clip is read: the length
224
+ * the graph gives, held to the model's limits, billed as a run bills it; a
225
+ * length it does not know quotes the longest clip the model takes — the most
226
+ * the run can be charged — marked as an estimate by the caller.
227
+ */
228
+ export function videoToVideoEstimateSeconds(provider: ClipPricedV2vProvider, videoEditDuration: unknown, knownSec?: number | null): number {
229
+ const min = videoToVideoClipMinSec(provider)
230
+ const max = videoToVideoClipMaxSec(provider)
231
+ const sec = knownSec == null || !Number.isFinite(knownSec) || knownSec <= 0 ? max : Math.min(max, Math.max(min, knownSec))
232
+ return videoToVideoBilledSeconds(provider, sec, videoEditDuration)
233
+ }
234
+
235
+ /** The price an estimate quotes ({@link videoToVideoEstimateSeconds}), and whether it stood in for an unknown length. */
236
+ export function videoToVideoEstimatePrice(
237
+ provider: ClipPricedV2vProvider,
238
+ resolution: unknown,
239
+ videoEditDuration: unknown,
240
+ knownSec: number | null | undefined,
241
+ rowOf: (id: string) => number | undefined,
242
+ ): V2vClipPrice & { readonly lengthKnown: boolean } {
243
+ const lengthKnown = knownSec != null && Number.isFinite(knownSec) && knownSec > 0
244
+ return {
245
+ ...videoToVideoClipPrice(provider, resolution, videoToVideoEstimateSeconds(provider, videoEditDuration, knownSec), rowOf),
246
+ lengthKnown,
247
+ }
248
+ }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/producer-types.ts","../src/video-ui-defaults.ts"],"names":["composeUnitSet","unitProducers","composeUnitRecord","UGC_PRIMARY_HANDLE","unitFanOutEach","unitListPips","isSeedance2Provider","isMinimaxH3Provider","isWan3Provider","isKling4RunnerProvider","isViduQ4Provider","isGeminiOmniPerSecondProvider","isPixverseV6MaxProvider","PRICING_DEFAULT_RESOLUTION","MODEL_CATALOG","isGeminiOmniProvider"],"mappings":";;;;;;;;AA2BO,IAAM,oBAAA,GAA4CA,iCAAe,sBAAA,EAAwB;AAAA,EAC9F,gBAAA;AAAA,EACA,gBAAA;AAAA,EACA,SAAA;AAAA;AAAA,EACA,eAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,oBAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,gBAAA;AAAA,EACA,UAAA;AAAA,EACA,iBAAA;AAAA,EACA,iBAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAA;AAAA;AAAA;AAAA,EAGA,cAAA;AAAA,EACA,cAAA;AA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O,IAAA;AACzB,EAAA,OAAO,gBAAgB,IAAA,IAAQ,YAAA,KAAiB,EAAA,IAAM,IAAA,CAAK,SAAS,YAAY,CAAA;AAClF;;;ACjaO,SAAS,kBAAkB,QAAA,EAAsC;AACtE,EAAA,IAAIC,qCAAA,CAAoB,QAAQ,CAAA,IAAKC,qCAAA,CAAoB,QAAQ,CAAA,IAAKC,gCAAA,CAAe,QAAQ,CAAA,EAAG,OAAO,UAAA;AAKvG,EAAA,IAAIC,wCAAA,CAAuB,QAAQ,CAAA,EAAG,OAAO,MAAA;AAC7C,EAAA,OAAO,MAAA;AACT;AAIO,SAAS,iBAAiB,QAAA,EAAsC;AACrE,EAAA,IAAID,iCAAe,QAAQ,CAAA,IAAKE,kCAAA,CAAiB,QAAQ,KAAKD,wCAAA,CAAuB,QAAQ,CAAA,IAAKE,+CAAA,CAA8B,QAAQ,CAAA,IAAKC,yCAAA,CAAwB,QAAQ,CAAA,EAAG,OAAOC,6CAA2B,QAAQ,CAAA;AAC1N,EAAA,IAAIP,qCAAA,CAAoB,QAAQ,CAAA,EAAG,OAAOQ,gCAAc,QAAQ,CAAA,EAAG,cAAc,CAAC,CAAA;AAClF,EAAA,OAAO,MAAA;AACT;AAWO,SAAS,eAAe,QAAA,EAAsC;AACnE,EAAA,IAAIN,gCAAA,CAAe,QAAQ,CAAA,IAAKE,kCAAA,CAAiB,QAAQ,CAAA,IAAKD,wCAAA,CAAuB,QAAQ,CAAA,IAAKG,yCAAA,CAAwB,QAAQ,CAAA,EAAG,OAAO,CAAA;AAC5I,EAAA,IAAIG,sCAAA,CAAqB,QAAQ,CAAA,EAAG,OAAO,CAAA;AAC3C,EAAA,OAAO,MAAA;AACT","file":"chunk-5DRSENY3.cjs","sourcesContent":["/**\n * Producer-type sets — single source of truth for the node types whose\n * primary output is a video URL, audio URL, etc.\n *\n * Consumed by:\n * - backend/src/services/workflow-engine/execution-graph.ts (orchestrator\n * dispatch + asset-type tagging in payload-builder, output-extractor,\n * inline-executor — re-exported there as VIDEO_SOURCE_TYPES /\n * AUDIO_SOURCE_TYPES for backwards compatibility).\n * - frontend/src/lib/generate-video-handles.ts (handle connection\n * validation on the Generate Video node).\n *\n * Lifting these here ensures the frontend handle validator can never reject\n * a connection from a node type that the backend would happily route at\n * execution time (the prior drift bug, see issue 1 of the Task 4.1 review).\n */\nimport { UGC_PRIMARY_HANDLE } from \"./ugc-node-wires.js\"\nimport { composeUnitRecord, composeUnitSet, unitFanOutEach, unitListPips, unitProducers } from \"./unit-contract-compose.js\"\n\n// Each producer set below is its hand-written members ∪ the node units\n// (tools/units/README.md) of that producer kind, from their generated contract\n// rows, in that order — a type in both throws at load (composeUnitSet).\n\n/**\n * Source node types whose primary output is a video URL.\n * Mirrors the backend execution-graph VIDEO_SOURCE_TYPES verbatim.\n */\nexport const VIDEO_PRODUCER_TYPES: ReadonlySet<string> = composeUnitSet(\"VIDEO_PRODUCER_TYPES\", [\n \"image-to-video\",\n \"video-to-video\",\n \"switchx\", // Beeble SwitchX relight/composite\n \"text-to-video\",\n // Unified video node — emits videoUrl identically to i2v/t2v (its payload-builder\n // case dispatches dynamically to \"image-to-video\" or \"text-to-video\" jobName based\n // on whether a start frame is wired). Without this, getPrimaryOutput would fall\n // through to the imageUrl/videoUrl/audioUrl/text default and downstream consumers\n // could silently misroute the output.\n \"generate-video\",\n // Generate Video Pro — Seedance-2-family multi-segment stitch variant of\n // generate-video (same \"emits videoUrl\" contract; a trimmed provider +\n // handle set). Must mirror generate-video here or its output can't connect\n // downstream (the recurring \"cannot connect the outputs\" bug class).\n \"generate-video-pro\",\n // Edit Video Pro — Seedance-2-family span-replace sibling of generate-\n // video-pro (same \"emits videoUrl\" contract; source video + prompt in,\n // ONE video out). Must mirror generate-video-pro here or its output can't\n // connect downstream (the recurring \"cannot connect the outputs\" bug class).\n \"edit-video-pro\",\n \"upload-video\",\n \"youtube-video\",\n \"combine-videos\",\n \"lip-sync\",\n \"speech-to-video\",\n \"motion-transfer\",\n \"video-upscale\",\n \"video-depth\",\n \"extend-video\",\n // face-swap output is video (writes generatedVideoUrl, per-result `url`).\n // Frontend execution-graph already includes it in VIDEO_SOURCE_TYPES; this\n // entry brings the shared set in line so canvas typed-handle validation\n // doesn't reject face-swap → video-consumer edges that the orchestrator\n // would happily route at runtime.\n \"face-swap\",\n // Speaker View (C3.2): an EDL rendered with its speakers framed — one VIDEO\n // out (no audio-only render). Registered in RENDER_NODE_TYPES as well.\n \"speaker-view\",\n \"video-retake\",\n // video-sfx: adds an SFX track to a video → emits a video URL. Belongs here so\n // canvas handle validation accepts video-sfx → video-consumer edges and the\n // backend routes its output as video (it was previously relying on a fallback).\n \"video-sfx\",\n \"suno-music-video\",\n \"merge-video-audio\",\n \"add-captions\",\n \"resize-video\",\n \"social-media-format\",\n \"trim-video\",\n \"render-video\",\n \"speed-ramp\",\n \"loop-video\",\n \"fade-video\",\n // Video Mask emits its mask as a video; Mask Composite its composite.\n \"video-mask\",\n \"mask-composite\",\n \"transcode-video\",\n \"manual-edit\",\n // AI Avatar (HeyGen): avatar + voice/audio → video.\n \"ai-avatar\",\n // Cinematic Avatar (HeyGen cinematic_avatar): prompt + 1–3 avatar looks → video.\n \"cinematic-avatar\",\n // Assemble Narrated Video: fits N (clip, voice) blocks into one MP4 → video.\n \"assemble-narrated-video\",\n // Still to Video: one still image + one audio track → MP4 (local FFmpeg,\n // no provider). Emits generatedVideoUrl like every other ffmpeg video node.\n \"still-to-video\",\n // Slideshow: 2-100 stills + one optional audio track → MP4 (local FFmpeg,\n // no provider). Same contract; images arrive via the image-collage lane.\n \"slideshow\",\n // 3D Render Pro: authors a scene AND exports it in one operation, settling\n // with the standard `videoUrl` field. It is a video producer as much as it\n // is a composition producer — omitting it here is the \"cannot connect the\n // outputs\" bug, and its `composition` handle is typed separately.\n \"pro-3d-render\",\n // Video Overlay: timed image layers over a video in one local FFmpeg pass\n // (the base audio copied) — emits a video URL on `video-out`.\n \"video-overlay\",\n // UGC Clip: renders one clip of a UGC video from its ticket — emits a video\n // URL on `video-out` (one per fan-out iteration).\n \"ugc-clip\",\n // UGC Finish: the video's clips, finished, as one ordered list — a registered producer, so a\n // Bundle edge into Combine Videos routes each one as a video, in order.\n \"ugc-finish-clips\",\n], unitProducers(\"video\"))\n\n/**\n * Source node types whose output media-type cannot be classified\n * statically — iterators, dynamic dispatchers, sub-workflow wrappers.\n * The orchestrator decides their actual output type at execution time\n * based on what's wired upstream (loop iterates upstream column type;\n * sub-workflow emits its leaf node's type; adjust-volume passes through\n * video or audio based on its `lastInputType` runtime field;\n * voice-changer emits audio in audio mode, video+audio in video mode).\n *\n * Typed-handle validators (frontend/src/lib/{generate-image,generate-\n * video,ffmpeg}-handles.ts) must include these as acceptors on EVERY\n * media-typed input handle — otherwise the canvas validator hard-\n * rejects edges that the orchestrator would happily route at runtime.\n *\n * Lifted here from `frontend/src/lib/ffmpeg-handles.ts` (where the\n * escape hatch was first added) so the same set drives ALL handle\n * validators uniformly. Adding a new dynamic-output node type means\n * one edit here instead of N across sibling validator files.\n *\n * Intentionally OMITTED:\n * - `webhook-trigger` / `schedule-trigger` — their outputs are\n * user-defined JSON shapes, not media URLs. Accepting them as\n * media producers creates false-positive drops at the canvas\n * that fail at execution. Users wanting trigger → media flows\n * should wire through an upload node.\n */\nexport const DYNAMIC_PRODUCER_TYPES: ReadonlySet<string> = composeUnitSet(\"DYNAMIC_PRODUCER_TYPES\", [\n \"list\",\n \"sub-workflow\",\n \"adjust-volume\",\n // Pitch & Tempo: audio in → audio out, video in → video out (picture\n // copied). Dual-mode like adjust-volume; stays in AUDIO_PRODUCER_TYPES as\n // its default.\n \"pitch-tempo\",\n // Dual-mode: audio in → audio out; video in → video out (+ revoiced audio).\n // Listed here so canvas validators accept its output on BOTH audio and video\n // input handles (it also stays in AUDIO_PRODUCER_TYPES as its default).\n \"voice-changer\",\n // voice-changer-pro (renamed from voice-recast in #3581) is a behavioral\n // twin of voice-changer — identical dual-mode output. Must mirror it in\n // EVERY producer set or its outputs can't connect (was the \"cannot connect\n // the outputs of voice-changer-pro\" bug). Guarded by producer-types.test.ts.\n \"voice-changer-pro\",\n // Dubbing joined the dual-mode family with the full-surface upgrade:\n // audio in → dubbed audio; video in (or a video sourceUrl) → dubbed VIDEO\n // (+ audio sidecar). Same wiring contract as voice-changer; stays in\n // AUDIO_PRODUCER_TYPES as its default. Explicitly asserted in\n // producer-types.test.ts (the suite does not fail on omission).\n \"dubbing\",\n \"reduce\",\n // Dual-output time chunker (UI label \"Split into Chunks\"; type id stays\n // \"split-media\"): video in → video chunks, audio in → audio chunks — two\n // independent lanes on two output handles. Like voice-changer, the canvas\n // validator only sees the source NODE type, not which handle a wire leaves,\n // so it lives here to be accepted on BOTH audio and video input handles. The\n // backend routes the correct lane by sourceHandle in getPrimaryOutput\n // (output-extractor.ts); the frontend does so in extractNodeOutput.\n \"split-media\",\n // apply-edl renders an EDL into ONE media output whose type is decided at\n // run time by the node's `output` setting (video OR audio) — so its static\n // medium is genuinely unknown and it belongs here, letting canvas validators\n // accept its default media handle on BOTH audio and video input handles. It\n // ALSO emits a fixed `json` handle (the remapped Transcript); that half lives\n // in JSON_PRODUCER_TYPES (frontend/src/lib/data-handles.ts). The FIRST node\n // with both a dynamic media handle and a fixed json handle. Because\n // getOutputType (presentation-utils.ts) deliberately returns \"data\" for\n // DYNAMIC members, apply-edl is ALSO added to the literal VIDEO_OUTPUT_TYPES\n // there so a published app renders the cut as video, mirroring the\n // voice-changer/dubbing precedent. Asserted in producer-types.test.ts (the\n // suite does not fail on omission).\n \"apply-edl\",\n], unitProducers(\"dynamic\"))\n\n/**\n * Source node types whose primary output is an audio URL.\n * Mirrors the backend execution-graph AUDIO_SOURCE_TYPES verbatim.\n */\nexport const AUDIO_PRODUCER_TYPES: ReadonlySet<string> = composeUnitSet(\"AUDIO_PRODUCER_TYPES\", [\n \"text-to-speech\",\n \"text-to-audio\",\n \"generate-music\",\n \"upload-audio\",\n \"suno-generate\",\n \"suno-cover\",\n \"suno-extend\",\n \"suno-separate\",\n \"audio-separation\",\n \"suno-mashup\",\n \"suno-replace-section\",\n \"suno-add-instrumental\",\n \"suno-add-vocals\",\n \"suno-convert-wav\",\n \"suno-upload-extend\",\n \"trim-audio\",\n \"mix-audio\",\n \"combine-audio\",\n \"adjust-volume\",\n \"audio-fx\",\n \"pitch-tempo\",\n \"reference-audio\",\n \"audio-isolation\",\n \"text-to-dialogue\",\n \"voice-changer\",\n // Twin of voice-changer (see DYNAMIC_PRODUCER_TYPES note). Audio is its\n // default output mode; video mode is handled via DYNAMIC membership.\n \"voice-changer-pro\",\n \"dubbing\",\n \"voice-remix\",\n \"voice-design\",\n // Extract Audio: demuxes a video's audio track to a standalone MP3.\n \"extract-audio\",\n], unitProducers(\"audio\"))\n\n/**\n * Source node types whose output is an IMAGE URL — what feeds a References\n * input. ONE set for the canvas validators (`frontend/src/lib/\n * generate-image-handles.ts` re-exports it), the backend's Generate Image\n * handle migration and the MCP edge normalizer (`llm-chat`'s legacy `in`):\n * they used to keep separate copies, and the backend's lagged by eight types.\n */\nexport const IMAGE_PRODUCER_TYPES: ReadonlySet<string> = composeUnitSet(\"IMAGE_PRODUCER_TYPES\", [\n \"upload-image\", \"generate-image\", \"edit-image\", \"image-to-image\", \"modify-image\", \"upscale-image\", \"remove-background\",\n // extract-frame produces a single still image extracted from a video source.\n \"extract-frame\",\n // generate-mask emits the source image AND a mask PNG; its `image` source\n // pip is the passthrough (the same image as the input).\n \"generate-mask\",\n // paint-mask emits the hand-painted mask PNG (a plain image at runtime).\n // Membership is what makes mask targets accept it — mask is an advisory\n // color, not a gated type.\n \"paint-mask\",\n // reference-sheet's `sheet` is one composited image and `panels` carries\n // clean reference images; both resolve to image URLs at runtime.\n \"reference-sheet\",\n // reference-board's `image` pip emits a real generated board image.\n \"reference-board\",\n // image-collage composites N images → ONE image.\n \"image-collage\",\n // image-overlay places layers on a base → ONE image.\n \"image-overlay\",\n // 3D Render Pro's `stills` handle carries one PNG per shot of the exported\n // composition (spread into referenceImageUrls like reference-sheet\n // `panels`). A validator sees only the source NODE type, so this also makes\n // its `video` pip droppable on an image input — the handle-blind trade\n // reference-sheet and split-media already make; the input resolvers route\n // by handle, so only `stills` becomes an image at runtime. Deliberately NOT\n // in IMAGE_SOURCE_TYPES on either engine: that set types the node's PRIMARY\n // asset, and 3D Render Pro's is the MP4.\n \"pro-3d-render\",\n], unitProducers(\"image\"))\n\n/**\n * Source node types whose primary output is a LIST that, by default, fans out\n * one downstream execution per element when an edge leaves them WITHOUT an\n * explicit `outputMode` (all other edges default to \"last\"). `selector` is\n * included because its picked/rest channels are lists too.\n *\n * Single source of truth for the fan-out \"each\" default, consumed by:\n * - backend/src/services/workflow-engine/input-resolver.ts (DEFAULT_EACH_TYPES)\n * - frontend/src/components/editor/workflow-editor/types.ts (FAN_OUT_EACH_TYPES)\n * - frontend/src/components/editor/workflow-editor/node-input-resolver.ts\n *\n * These three previously kept independent copies; the backend copy drifted\n * (missing the four list-transform types), so server-side workflow runs\n * silently dropped all-but-the-first item for filter-list / deduplicate /\n * merge-lists / sort-list sources while the canvas fanned out N ways. Lifting\n * the set here makes that drift impossible.\n */\nexport const FAN_OUT_EACH_TYPES: ReadonlySet<string> = new Set([\n \"list\",\n \"split-text\",\n \"filter-list\",\n \"deduplicate\",\n \"merge-lists\",\n \"sort-list\",\n \"selector\",\n // edit-plan `clips` mode emits a bare `Edl[]` on `data.generatedJson`, so an\n // edge leaving it defaults to \"each\" — one downstream execution (typically an\n // apply-edl render) per clip. The `tighten`/`chapters` modes emit an OBJECT,\n // for which the list extractors return undefined, so an \"each\" edge falls back\n // to the scalar `edl` value (no fan-out) — the same graceful degradation\n // web-scrape relies on. See `unwrapEditPlanOutput` in `edit-plan-contract.ts`.\n \"edit-plan\",\n // Content Ideas emits one creative brief per idea on `listResults`, so an\n // edge leaving it defaults to \"each\" — the node after it (typically\n // Generate Script) runs once per idea, on the server too.\n \"content-ideas\",\n])\n\n/**\n * Per-HANDLE \"each\" defaults, for a node whose outputs differ in kind: on the\n * `each` handles an edge without an explicit `outputMode` defaults to \"each\",\n * on its other handles to \"last\". `primary` is the handle an edge with no\n * `sourceHandle` reads (agent-written workflow JSON often omits it).\n *\n * The list an \"each\" edge reads is the node's per-iteration results\n * (`listResults`) — it exists only when the node itself ran once per item, so\n * after a single run the edge degrades to the single value, exactly like a\n * `FAN_OUT_EACH_TYPES` member with one item.\n *\n * Its hand-written rows ∪ the node units' rows (`contract.fanOutEach`,\n * generated/unit-contracts.ts); a type in both refuses to load.\n */\nexport const FAN_OUT_EACH_HANDLES: Readonly<Record<string, { readonly each: readonly string[]; readonly primary: string }>> = composeUnitRecord(\"FAN_OUT_EACH_HANDLES\", {\n // Camera Switch run once per clip (Edit Plan in clips mode): each clip's\n // switched EDL is its own Apply EDL render. Its transcript is the same for\n // every clip (the master clock, renamed), so that handle stays one value\n // (decided 2026-10-04).\n \"camera-switch\": { each: [\"edl\"], primary: \"edl\" },\n // UGC Clips: one ticket per clip on `clips` (each); `plan-out` and\n // `transcript` carry one value. Not a FAN_OUT_EACH_TYPES member — every\n // handle of such a member would fan out. Its one run writes the tickets as\n // its list (`listResults`, the editor's `__listResults`). The pip an edge\n // with no handle reads is the UGC wires' own (UGC_PRIMARY_HANDLE).\n \"ugc-clips\": { each: [\"clips\"], primary: UGC_PRIMARY_HANDLE[\"ugc-clips\"]! },\n // A node unit declares its row in unit.json (contract.fanOutEach); it is added after these.\n}, unitFanOutEach())\n\n/**\n * Fan-out nodes whose iterations must ALL succeed: one failed item fails the\n * node (today's rule tolerates a partial list). UGC Clip — a missing clip\n * silently drops a beat from the script (spec R17). Already-started items\n * finish and settle; their jobs are reused on the next run.\n */\nexport const FAN_OUT_ALL_OR_NOTHING_TYPES: ReadonlySet<string> = new Set([\"ugc-clip\"])\n\n/**\n * Nodes whose saved list is the list their last run PRODUCED — `__listResults`\n * (Extract Field's JSON value on `generatedJson`) — and never a history in\n * `generatedResults`: Extract Field, JSON Process and Site Capture. No run of the first two writes\n * one; earlier builds' server runs did (the run's text, the links of a list of\n * links), and both engines' list readers leave it out for these two (decided\n * 2026-10-05). Single source of truth for the backend engine and the editor.\n */\nexport const OWN_LIST_NODE_TYPES: ReadonlySet<string> = new Set([\n \"extract-field\",\n \"json-process\",\n // Site Capture: its stills, in page order — the last capture's, never every capture's (site-capture-node.ts).\n \"site-capture\",\n])\n\n/** Whether a node's saved list is its own `__listResults`, never a history. */\nexport function ownsItsList(nodeType: string | null | undefined): boolean {\n return typeof nodeType === \"string\" && OWN_LIST_NODE_TYPES.has(nodeType)\n}\n\n/**\n * The output pips that carry the LIST one run produced — several files on one\n * pip (a node unit's `handles.outputs[].list`: each layer of a split image). An\n * edge leaving one runs the next node once per item by default (\"each\"); a\n * Bundle hands the whole list to a node that takes several. Unlike\n * FAN_OUT_EACH_HANDLES, the list is what ONE run made on that pip, never the\n * node's per-iteration results. An edge naming no pip reads the node's primary\n * output, which is never a list pip (tools/units/json-output-rules.mjs).\n * Node units only (generated/unit-contracts.ts UNIT_LIST_PIPS).\n */\nexport const LIST_OUTPUT_HANDLES: Readonly<Record<string, readonly string[]>> = composeUnitRecord(\"LIST_OUTPUT_HANDLES\", {}, unitListPips())\n\n/** Whether an edge leaving `sourceHandle` of a `sourceType` node carries a list one run produced (LIST_OUTPUT_HANDLES). */\nexport function isListOutputHandle(\n sourceType: string | null | undefined,\n sourceHandle: string | null | undefined,\n): boolean {\n if (typeof sourceType !== \"string\" || typeof sourceHandle !== \"string\" || !Object.hasOwn(LIST_OUTPUT_HANDLES, sourceType)) return false\n return LIST_OUTPUT_HANDLES[sourceType]!.includes(sourceHandle)\n}\n\n/** The `outputMode` an edge has when none is set on it — the ONE rule both\n * engines, the credit estimate and the editor read. */\nexport function defaultEdgeOutputMode(\n sourceType: string | null | undefined,\n sourceHandle: string | null | undefined,\n): \"each\" | \"last\" {\n if (typeof sourceType !== \"string\") return \"last\"\n if (FAN_OUT_EACH_TYPES.has(sourceType)) return \"each\"\n if (isListOutputHandle(sourceType, sourceHandle)) return \"each\"\n const entry = FAN_OUT_EACH_HANDLES[sourceType]\n if (!entry) return \"last\"\n return entry.each.includes(sourceHandle || entry.primary) ? \"each\" : \"last\"\n}\n\n/** Whether an edge from `sourceHandle` reads the node's per-iteration results\n * (`listResults` — each iteration's PRIMARY output). False on the other\n * handles of a `FAN_OUT_EACH_HANDLES` node: Camera Switch's transcript is one\n * value, never the list of switched EDLs, whatever mode its edge is set to. */\nexport function listResultsServeHandle(\n sourceType: string | null | undefined,\n sourceHandle: string | null | undefined,\n): boolean {\n const entry = typeof sourceType === \"string\" ? FAN_OUT_EACH_HANDLES[sourceType] : undefined\n return !entry || entry.each.includes(sourceHandle || entry.primary)\n}\n\n/**\n * FAN-IN targets: nodes that FOLD everything wired into them into ONE run,\n * instead of running once per upstream item. Keyed by node type; the value\n * names the target handles that fold (`\"*\"` = every handle). An edge into any\n * other handle of such a node is routed normally — Content Ideas folds its\n * recipes but reads its brand from a `field-brand` wire like any field.\n *\n * Single source of truth for both engines' input resolvers (the backend and\n * the editor each used to keep a private `new Set([\"reduce\"])`). A fan-in\n * node is never itself fanned out by an upstream list.\n */\nexport const FAN_IN_TARGETS: Readonly<Record<string, \"*\" | readonly string[]>> = {\n // Choose Best — every wire is a candidate.\n reduce: \"*\",\n // Content Ideas — one or more recipes, from several Content Recipe nodes\n // and/or one that ran once per post.\n \"content-ideas\": [\"recipes\"],\n // Telegram Reply — one message per run, whatever is wired into its text\n // input: a list (or a writer that ran once per item) arrives as one\n // message, never as a burst of sends to the owner's chat.\n \"telegram-account-send\": [\"in\"],\n // The list operators — they READ the whole list wired into them (their\n // executors collect every upstream item themselves) and emit a list. Run\n // once per item by an \"each\" wire (a Split Text, a List, a node that ran per\n // item), every iteration saw the same whole list and answered with its\n // first match: a Filter List fed 11 stories handed 11 copies of story one\n // downstream, and every paid stage after it ran 11 times on it\n // (2026-10-06). A list operator is never fanned out, on any wire.\n \"filter-list\": \"*\",\n deduplicate: \"*\",\n \"merge-lists\": \"*\",\n \"sort-list\": \"*\",\n selector: \"*\",\n // Speaker Frames on a clip pack (P3-24 (a), decided 2026-10-06): ONE run over\n // the union of the clips' spans — the pack's EDLs fold onto its `edl` wire\n // instead of running one detection job (and one minimum charge) per clip.\n \"speaker-frames\": [\"edl\"],\n // UGC Finish: ONE run over every clip of the video, in clip order — the finish plans its\n // cut and its sound over all of them at once, so it is never run once per clip.\n \"ugc-finish-clips\": [\"clips\"],\n}\n\nexport function isFanInNodeType(nodeType: string | undefined | null): boolean {\n return typeof nodeType === \"string\" && Object.prototype.hasOwnProperty.call(FAN_IN_TARGETS, nodeType)\n}\n\n/** True when an edge into `targetHandle` of a `targetType` node is folded.\n * An edge with NO target handle (workflow JSON written by an agent often\n * omits it) lands on the node's primary input, which is the folding one. */\nexport function isFanInEdge(targetType: string | undefined | null, targetHandle: string | null | undefined): boolean {\n if (!isFanInNodeType(targetType)) return false\n const spec = FAN_IN_TARGETS[targetType as string]!\n if (spec === \"*\") return true\n return targetHandle == null || targetHandle === \"\" || spec.includes(targetHandle)\n}\n","/**\n * UI-default fills for the unified video nodes — the ONE source of truth shared\n * by the backend DAG payload builder, the config-panel fail-safe snaps and the\n * node's hover/run strip.\n *\n * Several config panels RENDER a default without persisting it to node data, so\n * an untouched node submits `aspectRatio` / `resolution` undefined and the\n * enqueued job row (and the /v1/jobs echo) then disagrees with what actually\n * renders. Worse, the panels' generic snap writes `resolutions[0]` for a stale\n * value, which is the CHEAPEST tier under the repo's ascending-resolution\n * convention — not necessarily the tier the model renders and bills.\n *\n * These helpers were local to `backend/src/services/workflow-engine/payload-builder.ts`\n * until the Wan 3.0 launch gave the platform its first provider whose declared\n * billing default differs from `resolutions[0]`; three surfaces then had to\n * agree, so they live here.\n *\n * The resolution fill is per-family ON PURPOSE. Wan 3.0 (and Vidu Q4, whose\n * ascending list starts at 540p) reads its DECLARED\n * billing default (PRICING_DEFAULT_RESOLUTION = 720p) because its catalog list\n * is ascending, so an index-0 fill would write 480p — a tier both `runWan3`\n * (which renders 720P) and the credit identifier (which bills the 720p row)\n * disagree with. The Seedance family keeps its historical first-catalog-tier\n * fill, deliberately: switching it to PRICING_DEFAULT_RESOLUTION would reprice\n * live seedance-2-5 runs, whose declared default (720p) differs from the 480p\n * this has always filled. That 480p-fill vs 720p-billing-default divergence on\n * seedance-2-5 is a KNOWN pre-existing gap, out of scope here — do not \"align\"\n * the branches without repricing it deliberately.\n */\n\nimport {\n PRICING_DEFAULT_RESOLUTION,\n isSeedance2Provider,\n isMinimaxH3Provider,\n isWan3Provider,\n isViduQ4Provider,\n isKling4RunnerProvider,\n isGeminiOmniProvider,\n isGeminiOmniPerSecondProvider,\n isPixverseV6MaxProvider,\n} from \"./model-constants.js\"\nimport { MODEL_CATALOG } from \"./model-catalog.js\"\n\n/** `adaptive` is the aspect default for Seedance 2, MiniMax H3 and Wan 3.0. */\nexport function uiAspectRatioFill(provider: string): string | undefined {\n if (isSeedance2Provider(provider) || isMinimaxH3Provider(provider) || isWan3Provider(provider)) return \"adaptive\"\n // Kling 4.0 (and Flash): `auto` follows the materials (frames / references)\n // and renders 16:9 with none — KIE's own default when the field is omitted.\n // Flash's keyframe endpoint has no `auto`, but it runs only with a start\n // frame, where the ratio is never sent (the clip follows the frame).\n if (isKling4RunnerProvider(provider)) return \"auto\"\n return undefined\n}\n\n/** See the file docstring — per-family on purpose; never a generic\n * PRICING_DEFAULT_RESOLUTION read (that would reprice seedance-2-5). */\nexport function uiResolutionFill(provider: string): string | undefined {\n if (isWan3Provider(provider) || isViduQ4Provider(provider) || isKling4RunnerProvider(provider) || isGeminiOmniPerSecondProvider(provider) || isPixverseV6MaxProvider(provider)) return PRICING_DEFAULT_RESOLUTION[provider]\n if (isSeedance2Provider(provider)) return MODEL_CATALOG[provider]?.resolutions?.[0]\n return undefined\n}\n\n/**\n * Duration the node RENDERS and BILLS when `data.duration` is unset, for the\n * families whose credit identifier declares a duration fallback that is NOT\n * `durations[0]`. Wan 3.0's bare identifier is the 5s tier while its ladder\n * starts at 2s; Vidu Q4's is the 5s tier while its ladder starts at 3s;\n * PixVerse V6 Max's is the 5s tier while its ladder starts at 1s; the\n * 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\n * undefined and the caller keeps `durations[0]`.\n */\nexport function uiDurationFill(provider: string): number | undefined {\n if (isWan3Provider(provider) || isViduQ4Provider(provider) || isKling4RunnerProvider(provider) || isPixverseV6MaxProvider(provider)) return 5\n if (isGeminiOmniProvider(provider)) return 8\n return undefined\n}\n"]}