@nodaro/shared 3.24.0 → 3.25.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 (37) hide show
  1. package/dist/index.cjs +595 -128
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +375 -48
  4. package/dist/index.d.ts +375 -48
  5. package/dist/index.js +553 -129
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/credit-identifiers.test.ts +19 -6
  9. package/src/__tests__/dialogue-capabilities.test.ts +3 -2
  10. package/src/__tests__/edit-plan-minute-ids.test.ts +82 -0
  11. package/src/__tests__/json-kinds.test.ts +179 -0
  12. package/src/__tests__/presentation-utils.test.ts +1 -0
  13. package/src/__tests__/preview-gate.test.ts +2 -2
  14. package/src/__tests__/pricing-default-duration.test.ts +56 -15
  15. package/src/__tests__/private-host.test.ts +24 -0
  16. package/src/__tests__/render-nodes.test.ts +22 -3
  17. package/src/__tests__/tts-capabilities.test.ts +61 -1
  18. package/src/__tests__/video-link-input.test.ts +148 -0
  19. package/src/__tests__/video-link-needs.test.ts +67 -0
  20. package/src/__tests__/video-request-normalize.test.ts +18 -3
  21. package/src/credit-identifiers.ts +48 -37
  22. package/src/edit-plan-contract.ts +67 -1
  23. package/src/fan-out-rows.ts +2 -2
  24. package/src/index.ts +45 -1
  25. package/src/json-kinds.ts +188 -0
  26. package/src/model-catalog.ts +121 -8
  27. package/src/model-constants.ts +68 -42
  28. package/src/node-default-mappings.ts +1 -0
  29. package/src/pipeline-types.ts +13 -2
  30. package/src/presentation-utils.ts +8 -1
  31. package/src/private-host.ts +91 -0
  32. package/src/producer-types.ts +3 -0
  33. package/src/render-nodes.ts +12 -1
  34. package/src/scene-node-types.ts +17 -5
  35. package/src/social-post-readers.ts +37 -0
  36. package/src/video-link.ts +238 -0
  37. package/src/voices.ts +16 -9
@@ -0,0 +1,148 @@
1
+ import { describe, it, expect } from "vitest"
2
+ import { INPUT_FIELD_MAP as COMPONENT_FIELD_MAP, getInputFieldSchema } from "../index.js"
3
+ import { INPUT_FIELD_MAP, INPUT_NODE_TYPES, mergeNodeInputOverrides, getInputNodes } from "../presentation-utils.js"
4
+ import {
5
+ VIDEO_LINK_DERIVED_FIELDS,
6
+ DIRECT_VIDEO_EXTENSIONS,
7
+ isDirectVideoFileUrl,
8
+ videoLinkInputProblem,
9
+ } from "../video-link.js"
10
+
11
+ describe("the Video URL node as an app input", () => {
12
+ it("is an input node type, written through its `youtubeUrl` field", () => {
13
+ expect(INPUT_NODE_TYPES.has("youtube-video")).toBe(true)
14
+ expect(INPUT_FIELD_MAP["youtube-video"]).toEqual({ key: "youtubeUrl", type: "video-url" })
15
+ expect(getInputFieldSchema("youtube-video")).toEqual({ key: "youtubeUrl", type: "video-url" })
16
+ // …and a component can take one as an input handle on the same field.
17
+ expect(COMPONENT_FIELD_MAP["youtube-video"]).toBe("youtubeUrl")
18
+ })
19
+
20
+ it("a curated Video URL node is listed as an input (not only by the legacy flag)", () => {
21
+ const node = { id: "n1", type: "youtube-video", data: { presentationInput: true } }
22
+ expect(getInputNodes([node])).toHaveLength(1)
23
+ const legacy = { id: "n2", type: "youtube-video", data: { presentationVisible: true } }
24
+ expect(getInputNodes([legacy])).toHaveLength(1)
25
+ })
26
+ })
27
+
28
+ describe("videoLinkInputProblem — the one URL rule the card, the route and the lock share", () => {
29
+ it("accepts a supported social link and any other http(s) link — the canvas node's own rule (decided 2026-10-08)", () => {
30
+ for (const ok of [
31
+ "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
32
+ "https://youtu.be/dQw4w9WgXcQ",
33
+ "https://www.tiktok.com/@a/video/7234567890123456789",
34
+ "https://www.instagram.com/reel/Cabc123/",
35
+ "https://x.com/a/status/123456",
36
+ "https://cdn.example.com/episodes/ep-12.mp4",
37
+ "https://cdn.example.com/episodes/EP.MOV?sig=abc",
38
+ // No video extension: the canvas node passes any non-post link through, so the input does too.
39
+ "https://cdn.example.com/stream/ep-12",
40
+ "https://example.com/page",
41
+ "https://www.netflix.com/watch/1", // not a supported post host: passed through as it is, like the canvas
42
+ "http://cdn.example.com/a.mp4.exe",
43
+ ]) {
44
+ expect(videoLinkInputProblem(ok), ok).toBeNull()
45
+ }
46
+ })
47
+
48
+ it("surrounding spaces are not a problem (the card trims before it sends)", () => {
49
+ expect(videoLinkInputProblem(" https://youtu.be/dQw4w9WgXcQ ")).toBeNull()
50
+ })
51
+
52
+ it("names an empty value", () => {
53
+ expect(videoLinkInputProblem("")).toBe("empty")
54
+ expect(videoLinkInputProblem(" ")).toBe("empty")
55
+ expect(videoLinkInputProblem(undefined)).toBe("empty")
56
+ expect(videoLinkInputProblem(null)).toBe("empty")
57
+ })
58
+
59
+ it("refuses everything else as `invalid`", () => {
60
+ for (const bad of [
61
+ "hello",
62
+ "ftp://cdn.example.com/a.mp4",
63
+ "javascript:alert(1)",
64
+ "//cdn.example.com/a.mp4", // no scheme
65
+ "mailto:a@example.com",
66
+ "https://tiktok.com\\@10.0.0.1/x", // parser differential
67
+ "https://example.com/a\n.mp4",
68
+ ]) {
69
+ expect(videoLinkInputProblem(bad), bad).toBe("invalid")
70
+ }
71
+ expect(videoLinkInputProblem(42 as unknown)).toBe("invalid")
72
+ expect(videoLinkInputProblem({ href: "https://youtu.be/x" } as unknown)).toBe("invalid")
73
+ })
74
+
75
+ it("an over-long value is invalid, not parsed", () => {
76
+ expect(videoLinkInputProblem(`https://cdn.example.com/${"a".repeat(3000)}.mp4`)).toBe("invalid")
77
+ })
78
+ })
79
+
80
+ describe("isDirectVideoFileUrl (lifted to shared so the card and the route cannot drift)", () => {
81
+ it("reads the path's extension only", () => {
82
+ expect(DIRECT_VIDEO_EXTENSIONS).toEqual([".mp4", ".webm", ".mov", ".avi"])
83
+ expect(isDirectVideoFileUrl("https://cdn.example/CLIP.MP4")).toBe(true)
84
+ expect(isDirectVideoFileUrl("https://cdn.example/page?file=a.mp4")).toBe(false)
85
+ })
86
+ })
87
+
88
+ describe("merging a new link over a saved Video URL node", () => {
89
+ const saved = {
90
+ label: "Episode",
91
+ youtubeUrl: "https://youtu.be/AAAAAAAAAAA",
92
+ videoId: "AAAAAAAAAAA",
93
+ title: "Creator's sample",
94
+ thumbnailUrl: "https://img/creator.jpg",
95
+ downloadedVideoUrl: "https://cdn/creator-sample.mp4",
96
+ downloadedFromUrl: "https://youtu.be/AAAAAAAAAAA",
97
+ downloadedAudioUrl: "https://cdn/creator-sample.mp3",
98
+ downloadedSection: { startSec: 0, endSec: 60 },
99
+ videoDurationSec: 60,
100
+ needsRangeChoice: false,
101
+ metadata: { durationSeconds: 60 },
102
+ }
103
+
104
+ it("drops everything that belonged to the previous link", () => {
105
+ const merged = mergeNodeInputOverrides("youtube-video", saved, { youtubeUrl: "https://youtu.be/BBBBBBBBBBB" })
106
+ expect(merged.youtubeUrl).toBe("https://youtu.be/BBBBBBBBBBB")
107
+ for (const key of VIDEO_LINK_DERIVED_FIELDS) expect(key in merged, `${key} outlived its link`).toBe(false)
108
+ // …and nothing the creator authored.
109
+ expect(merged.label).toBe("Episode")
110
+ })
111
+
112
+ it("a stale audio track can never reach Transcribe / Suno Cover under the caller's link", () => {
113
+ const merged = mergeNodeInputOverrides("youtube-video", saved, { youtubeUrl: "https://cdn.example.com/ep.mp4" })
114
+ expect(merged.downloadedAudioUrl).toBeUndefined()
115
+ expect(merged.videoDurationSec).toBeUndefined()
116
+ })
117
+
118
+ it("keeps what the SAME override brings for the new link (the runner's own download)", () => {
119
+ const merged = mergeNodeInputOverrides("youtube-video", saved, {
120
+ youtubeUrl: "https://youtu.be/BBBBBBBBBBB",
121
+ downloadedVideoUrl: "https://cdn/runner-episode.mp4",
122
+ downloadedFromUrl: "https://youtu.be/BBBBBBBBBBB",
123
+ })
124
+ expect(merged.downloadedVideoUrl).toBe("https://cdn/runner-episode.mp4")
125
+ expect(merged.downloadedFromUrl).toBe("https://youtu.be/BBBBBBBBBBB")
126
+ expect(merged.downloadedAudioUrl).toBeUndefined()
127
+ })
128
+
129
+ it("keeps the saved state when the link is re-sent unchanged or not sent at all", () => {
130
+ const same = mergeNodeInputOverrides("youtube-video", saved, { youtubeUrl: saved.youtubeUrl })
131
+ expect(same.downloadedAudioUrl).toBe("https://cdn/creator-sample.mp3")
132
+ expect(same.metadata).toEqual({ durationSeconds: 60 })
133
+ const none = mergeNodeInputOverrides("youtube-video", saved, { label: "Renamed" })
134
+ expect(none.downloadedVideoUrl).toBe("https://cdn/creator-sample.mp4")
135
+ })
136
+
137
+ it("does not touch the saved data (a new object each time)", () => {
138
+ const copy = { ...saved }
139
+ mergeNodeInputOverrides("youtube-video", copy, { youtubeUrl: "https://youtu.be/BBBBBBBBBBB" })
140
+ expect(copy).toEqual(saved)
141
+ })
142
+
143
+ it("only the Video URL node drops link-bound state", () => {
144
+ const merged = mergeNodeInputOverrides("upload-video", { url: "a", title: "keep", downloadedAudioUrl: "keep" }, { url: "b" })
145
+ expect(merged.title).toBe("keep")
146
+ expect(merged.downloadedAudioUrl).toBe("keep")
147
+ })
148
+ })
@@ -0,0 +1,67 @@
1
+ import { describe, it, expect } from "vitest"
2
+ import {
3
+ AUTO_DOWNLOAD_MAX_SEC,
4
+ VIDEO_LINK_AUDIO_CONSUMER_TYPES,
5
+ VIDEO_LINK_TOLERANT_CONSUMER_TYPES,
6
+ YOUTUBE_MAX_HEIGHT,
7
+ videoLinkNeedOf,
8
+ videoLinkRunNeeds,
9
+ } from "../video-link.js"
10
+
11
+ const YT = "https://www.youtube.com/watch?v=aqz-KE-bpKQ"
12
+ const link = (id: string, data: Record<string, unknown> = { youtubeUrl: YT }) => ({ id, type: "youtube-video", data })
13
+ const node = (id: string, type: string, data: Record<string, unknown> = {}) => ({ id, type, data })
14
+ const edge = (source: string, target: string) => ({ source, target })
15
+
16
+ describe("what a Video URL node must fetch for the nodes that read it", () => {
17
+ it("the audio readers are a subset of the consumers that never read the video file", () => {
18
+ for (const type of VIDEO_LINK_AUDIO_CONSUMER_TYPES) expect(VIDEO_LINK_TOLERANT_CONSUMER_TYPES.has(type)).toBe(true)
19
+ expect([...VIDEO_LINK_AUDIO_CONSUMER_TYPES].sort()).toEqual(["suno-cover", "transcribe"])
20
+ })
21
+
22
+ it("a node that watches the video needs the file; audio readers alone need the track; link readers alone need nothing", () => {
23
+ expect(videoLinkNeedOf(["video-to-video"])).toBe("file")
24
+ expect(videoLinkNeedOf(["transcribe", "video-to-video"])).toBe("file")
25
+ expect(videoLinkNeedOf(["transcribe"])).toBe("audio")
26
+ expect(videoLinkNeedOf(["suno-cover", "content-recipe"])).toBe("audio")
27
+ expect(videoLinkNeedOf(["dubbing", "content-recipe"])).toBe("none")
28
+ expect(videoLinkNeedOf([])).toBe("none")
29
+ })
30
+
31
+ it("the card's and the server's constants are the same numbers the editor used", () => {
32
+ expect(AUTO_DOWNLOAD_MAX_SEC).toBe(240)
33
+ expect(YOUTUBE_MAX_HEIGHT).toBe(1080)
34
+ })
35
+ })
36
+
37
+ describe("videoLinkRunNeeds — one reading of the graph for the editor's gate, the card and the server", () => {
38
+ it("reads each Video URL node's consumers inside the run, at any depth upstream of the scope", () => {
39
+ const nodes = [link("src"), node("pass", "trim-video"), node("run", "video-to-video")]
40
+ const edges = [edge("src", "pass"), edge("pass", "run")]
41
+ expect(videoLinkRunNeeds(["run"], nodes, edges).get("src")).toBe("file")
42
+ })
43
+
44
+ it("Transcribe alone is audio-only; add a node that watches the video and it is the file", () => {
45
+ const nodes = [link("src"), node("tx", "transcribe"), node("va", "video-analysis")]
46
+ expect(videoLinkRunNeeds(["tx"], nodes, [edge("src", "tx")]).get("src")).toBe("audio")
47
+ expect(videoLinkRunNeeds(["tx", "va"], nodes, [edge("src", "tx"), edge("src", "va")]).get("src")).toBe("file")
48
+ })
49
+
50
+ it("a link that feeds nothing in the run is absent from the answer", () => {
51
+ const nodes = [link("unused"), link("other"), node("run", "video-to-video"), node("elsewhere", "video-to-video")]
52
+ const needs = videoLinkRunNeeds(["run"], nodes, [edge("other", "elsewhere")])
53
+ expect(needs.has("unused")).toBe(false)
54
+ expect(needs.has("other")).toBe(false)
55
+ })
56
+
57
+ it("skipped nodes are not part of the run and pull nothing in", () => {
58
+ const nodes = [link("src"), node("run", "video-to-video", { skipped: true })]
59
+ expect(videoLinkRunNeeds(["run"], nodes, [edge("src", "run")]).size).toBe(0)
60
+ })
61
+
62
+ it("a null scope is the whole graph (the app runner's view)", () => {
63
+ const nodes = [link("src"), node("tx", "transcribe"), node("dub", "dubbing")]
64
+ expect(videoLinkRunNeeds(null, nodes, [edge("src", "tx"), edge("src", "dub")]).get("src")).toBe("audio")
65
+ expect(videoLinkRunNeeds(null, [link("src"), node("dub", "dubbing")], [edge("src", "dub")]).get("src")).toBe("none")
66
+ })
67
+ })
@@ -175,9 +175,24 @@ describe("pricedVideoSelection", () => {
175
175
  expect(pricedVideoSelection({ provider: "ltx-2.3-pro" }).adjustments).toEqual([])
176
176
  })
177
177
 
178
- it("leaves duration alone for every non-LTX provider (legality is not a flat catalog list)", () => {
179
- expect(pricedVideoSelection({ provider: "seedance-2-5", duration: 7 }).duration).toBeUndefined()
180
- expect(pricedVideoSelection({ provider: "kling-3.0", duration: 7 }).duration).toBeUndefined()
178
+ it("a length-priced provider carries the length it is charged at: its own default when unset, an offered length as sent", () => {
179
+ expect(pricedVideoSelection({ provider: "seedance-2-5", duration: 7 })).toMatchObject({ duration: 7, adjustments: [] })
180
+ expect(pricedVideoSelection({ provider: "kling-3.0", duration: 7 })).toMatchObject({ duration: 7, adjustments: [] })
181
+ expect(pricedVideoSelection({ provider: "seedance-2" }).duration).toBe(8)
182
+ expect(pricedVideoSelection({ provider: "hailuo-2.3-pro" }).duration).toBe(6)
183
+ expect(pricedVideoSelection({ provider: "kling" }).duration).toBe(5)
184
+ })
185
+
186
+ it("a length the model does not offer is carried (and disclosed) as the nearest one it renders", () => {
187
+ const sel = pricedVideoSelection({ provider: "kling", duration: 7 })
188
+ expect(sel.duration).toBe(5)
189
+ expect(sel.adjustments).toEqual([expect.objectContaining({ field: "duration", from: 7, to: 5 })])
190
+ })
191
+
192
+ it("leaves Auto and a flat-priced provider's duration alone", () => {
193
+ expect(pricedVideoSelection({ provider: "seedance-2", duration: -1 }).duration).toBeUndefined()
194
+ expect(pricedVideoSelection({ provider: "veo3", duration: 7 }).duration).toBeUndefined()
195
+ expect(pricedVideoSelection({ provider: "veo3" }).duration).toBeUndefined()
181
196
  })
182
197
  })
183
198
 
@@ -16,6 +16,7 @@ import {
16
16
  VEO_RESOLUTION_TIERED_PROVIDERS,
17
17
  VIDEO_DURATION_TIERS,
18
18
  pricedOutputDurationSec,
19
+ snapToNearestDuration,
19
20
  PRICING_DEFAULT_RESOLUTION,
20
21
  MOTION_DURATION_TIERS,
21
22
  T2I_TO_I2I_VARIANT,
@@ -251,13 +252,6 @@ const T2V_CREDIT_OVERRIDES: Record<string, string> = {
251
252
  * @param resolution - Output resolution (used by Seedance 2 for 480p/720p pricing)
252
253
  * @param hasVideoRef - Whether a reference video is connected (Seedance 2 uses a lower per-second rate when true)
253
254
  */
254
- /** Gemini Omni duration tiers (seconds). Mirrors the `durations` of BOTH
255
- * `MODEL_CATALOG["gemini-omni-video"]` and `MODEL_CATALOG["gemini-omni-flash"]`
256
- * (and their `KIE_VIDEO_MODELS[*].allowedDurations`) — the family shares one
257
- * ladder. Hoisted to module scope so the nearest-tier snap below doesn't
258
- * reallocate on every (hot-path) call. */
259
- const GEMINI_OMNI_DURATIONS = [4, 6, 8, 10]
260
-
261
255
  /**
262
256
  * LTX 2.3 (Lightricks via Replicate) credit tiers: priced by
263
257
  * (resolution-band × duration-seconds). Keys mirror STATIC_CREDIT_COSTS /
@@ -292,9 +286,9 @@ function ltxPricedTier(
292
286
  if (!bands) return undefined
293
287
  const band = bands[String(resolution)] ? String(resolution) : "1080p"
294
288
  const allowed = bands[band]!
295
- const raw = typeof duration === "string" ? parseInt(duration, 10) : (duration ?? allowed[0]!)
296
- const want = Number.isNaN(raw) ? allowed[0]! : raw
297
- const dur = allowed.reduce((b, a) => (Math.abs(a - want) < Math.abs(b - want) ? a : b))
289
+ // The model's own default (catalog `defaultDuration`) when unset, then the
290
+ // nearest rung of THIS band's ladder — the length LTX renders.
291
+ const dur = snapToNearestDuration(pricedOutputDurationSec(provider, duration), allowed)
298
292
  return { band, duration: dur }
299
293
  }
300
294
 
@@ -343,10 +337,9 @@ export function buildVideoCreditModelIdentifier(
343
337
  if (hasVideoRef) {
344
338
  return resolution === "4k" ? `${effectiveProvider}:4k:vref` : `${effectiveProvider}:vref`
345
339
  }
346
- // Snap to nearest allowed tier (NOT a min/max clamp) so off-tier durations
347
- // map to a SEEDED composite; default 8 when unset.
348
- const raw = parseInt(String(duration ?? 8), 10)
349
- const d = Number.isNaN(raw) ? 8 : GEMINI_OMNI_DURATIONS.reduce((b, a) => (Math.abs(a - raw) < Math.abs(b - raw) ? a : b))
340
+ // The rendered length through the catalog funnel (nearest legal tier, the
341
+ // model's own default when unset) so the composite is always a SEEDED one.
342
+ const d = pricedOutputDurationSec(effectiveProvider, duration)
350
343
  return resolution === "4k" ? `${effectiveProvider}:4k:${d}` : `${effectiveProvider}:${d}`
351
344
  }
352
345
 
@@ -501,12 +494,13 @@ export interface PricedVideoSelection {
501
494
  * it": either the caller supplied one, or the provider's real default is not
502
495
  * known to be the band the identifier assumes. */
503
496
  resolution?: string
504
- /** The seeded duration tier the reservation is priced at (LTX only — the one
505
- * family whose duration ladder is per-band and case-sensitively seeded).
506
- * `undefined` for every other provider: their duration passes through. */
497
+ /** The length the reservation is priced at and the wire carries, for a
498
+ * provider whose price follows the clip length (LTX's seeded tier, the KIE
499
+ * ladders, Gemini Omni). `undefined` for every other provider, and for Auto:
500
+ * their duration passes through. */
507
501
  duration?: number
508
- /** Non-empty only for a lever the caller ASKED for and did not get (an LTX
509
- * 7s snapped to the 6s tier). Filling an omitted lever is a disclosure of
502
+ /** Non-empty only for a lever the caller ASKED for and did not get (a 7s
503
+ * request snapped to the 6s tier). Filling an omitted lever is a disclosure of
510
504
  * the price already being charged, not a correction, so it reports nothing. */
511
505
  adjustments: ModelInputAdjustment[]
512
506
  }
@@ -535,17 +529,14 @@ export interface PricedVideoSelection {
535
529
  * the render to match a price we already know is wrong. That mismatch is a
536
530
  * pre-existing identifier bug and is fixed by seeding the row, not here.
537
531
  *
538
- * 2. **LTX duration.** The LTX ladder is seeded per (band × seconds), so the
539
- * identifier snaps 7s onto the 6s tier. Sending 7s bills six and renders
540
- * seven. Most other providers' durations pass through untouched: their
541
- * legality is a flat catalog list the caller already sees, and their tiers
542
- * are ranges (`durationSec <= maxSeconds`), not seeded points. Gemini Omni
543
- * is the one other seeded ladder — `GEMINI_OMNI_DURATIONS` ([4, 6, 8, 10])
544
- * is nearest-snapped by `buildVideoCreditModelIdentifier`, the same shape
545
- * as LTX — but this function does not carry it yet: a 7s request prices
546
- * `:6` while 7s is still what gets sent. Pre-existing, out of scope here,
547
- * and ticketed as a follow-up (`geminiOmniPricedTier`, mirroring
548
- * `ltxPricedTier`).
532
+ * 2. **Duration.** Every provider whose price follows the clip length is
533
+ * charged at the length it RENDERS: its own default when the request named
534
+ * none (catalog `defaultDuration`), the nearest length it offers otherwise
535
+ * (`pricedOutputDurationSec` — the runners' own snap rule). The LTX ladder is
536
+ * seeded per (band × seconds), so a 7s request snaps onto the 6s tier;
537
+ * sending 7s would bill six and render seven. The same value is returned for
538
+ * the other length-priced providers (the KIE ladders, Gemini Omni), so what
539
+ * is priced is what is sent. Auto (-1) is the model's call and is untouched.
549
540
  *
550
541
  * Pure, and IDEMPOTENT against the identifier: feeding its output back in
551
542
  * cannot move the reserved tier. `video-request-normalize.test.ts` proves that
@@ -564,18 +555,27 @@ export function pricedVideoSelection(opts: {
564
555
  const resolution = opts.resolution
565
556
  ?? (ltx ? ltx.band : PRICING_DEFAULT_RESOLUTION[opts.provider])
566
557
 
567
- if (!ltx) return { resolution, adjustments }
568
-
569
558
  const requested = typeof opts.duration === "string" ? parseInt(opts.duration, 10) : opts.duration
570
- if (requested !== undefined && !Number.isNaN(requested) && requested !== ltx.duration) {
559
+ const asked = requested !== undefined && !Number.isNaN(requested)
560
+
561
+ // Every provider whose price follows the clip length sends the length it is
562
+ // CHARGED at (the catalog funnel: its own default when unset, the nearest
563
+ // legal length otherwise). Auto (-1) is the model's call and is left alone.
564
+ const lengthPriced = !!ltx || DURATION_PRICED_PROVIDERS.has(opts.provider) || isGeminiOmniProvider(opts.provider)
565
+ if (!lengthPriced || (!ltx && asked && requested! <= 0)) return { resolution, adjustments }
566
+
567
+ const duration = ltx ? ltx.duration : pricedOutputDurationSec(opts.provider, opts.duration)
568
+ if (asked && requested !== duration) {
571
569
  adjustments.push({
572
570
  field: "duration",
573
- from: requested,
574
- to: ltx.duration,
575
- reason: `LTX renders ${ltx.band} in ${ltx.duration}s steps — using ${ltx.duration}s instead of ${requested}s.`,
571
+ from: requested!,
572
+ to: duration,
573
+ reason: ltx
574
+ ? `LTX renders ${ltx.band} in ${ltx.duration}s steps — using ${ltx.duration}s instead of ${requested}s.`
575
+ : `${opts.provider} renders ${duration}s clips at the nearest length it offers — using ${duration}s instead of ${requested}s.`,
576
576
  })
577
577
  }
578
- return { resolution, duration: ltx.duration, adjustments }
578
+ return { resolution, duration, adjustments }
579
579
  }
580
580
 
581
581
  /**
@@ -674,6 +674,17 @@ export function applyEdlCreditId(quality: unknown): "apply-edl" | "apply-edl:pro
674
674
  return quality === "proxy" ? "apply-edl:proxy" : "apply-edl"
675
675
  }
676
676
 
677
+ /**
678
+ * The credit id of a Speaker View render (decided 2026-09-23, F4): a Preview
679
+ * (`quality` "proxy") reserves on `speaker-view:proxy`, anything else on
680
+ * `speaker-view`. The job is always named `speaker-view`; only its credit id
681
+ * follows the quality, as Apply EDL's does. Ids only — no price is published
682
+ * here, and none is set yet.
683
+ */
684
+ export function speakerViewCreditId(quality: unknown): "speaker-view" | "speaker-view:proxy" {
685
+ return quality === "proxy" ? "speaker-view:proxy" : "speaker-view"
686
+ }
687
+
677
688
  /**
678
689
  * OUR Nodaro credit key for a Suno operation, given the model version and the
679
690
  * operation (which is also the node type and the BullMQ job name).
@@ -56,7 +56,73 @@ export function editPlanBucketMinutes(durationSec: number | undefined): number {
56
56
  /** `edit-plan:<mode>:<tier>:<bucket>m`. `durationSec` undefined → the ceiling
57
57
  * bucket. Single source of truth for the composite id shape. */
58
58
  export function buildEditPlanCreditId(mode: EditPlanMode, tier: EditPlanTier, durationSec?: number): string {
59
- return `edit-plan:${mode}:${tier}:${editPlanBucketMinutes(durationSec)}m`
59
+ return editPlanMinutesCreditId(mode, tier, editPlanBucketMinutes(durationSec))
60
+ }
61
+
62
+ // ─────────────────────────────────────────────────────────────────────────
63
+ // Per started minute (decided 2026-10-07). A plugin that declares
64
+ // `supports().editPlanPerMinute` reserves `edit-plan:<mode>:<tier>:<N>m` with
65
+ // N = the started minutes of the source (1..180), priced flat + rate × N from
66
+ // ONE rate row and ONE flat row per mode × tier. The step ids above have the
67
+ // same shape (N = a step), so one parser reads both, and the plugin's money
68
+ // gate (`:(\d+)m$`) accepts both.
69
+ // ─────────────────────────────────────────────────────────────────────────
70
+
71
+ /** Started minutes of a source (seconds): ceil(sec / 60), at least 1, capped at
72
+ * the maximum. `undefined` / non-finite → the maximum (over-reserve direction). */
73
+ export function editPlanStartedMinutes(durationSec: number | undefined): number {
74
+ const secs = typeof durationSec === "number" && Number.isFinite(durationSec) ? durationSec : EDIT_PLAN_MAX_MINUTES * 60
75
+ return Math.min(EDIT_PLAN_MAX_MINUTES, Math.max(1, Math.ceil(secs / 60)))
76
+ }
77
+
78
+ /** `edit-plan:<mode>:<tier>:<N>m` for N minutes (a started-minute count or a step). */
79
+ export function editPlanMinutesCreditId(mode: EditPlanMode, tier: EditPlanTier, minutes: number): string {
80
+ return `edit-plan:${mode}:${tier}:${minutes}m`
81
+ }
82
+
83
+ /** The id a run of this mode/tier on a source of `durationSec` reserves: per
84
+ * started minute when the plugin charges that way (`perMinute`), else the step
85
+ * the length rounds up to. An unknown length → the 180-minute maximum either way. */
86
+ export function editPlanReserveCreditId(
87
+ mode: EditPlanMode,
88
+ tier: EditPlanTier,
89
+ durationSec: number | undefined,
90
+ perMinute: boolean,
91
+ ): string {
92
+ return perMinute
93
+ ? editPlanMinutesCreditId(mode, tier, editPlanStartedMinutes(durationSec))
94
+ : buildEditPlanCreditId(mode, tier, durationSec)
95
+ }
96
+
97
+ /** The rate row: credits per started source minute for a mode/tier. Never reserved. */
98
+ export function editPlanRateCreditId(mode: EditPlanMode, tier: EditPlanTier): string {
99
+ return `edit-plan:${mode}:${tier}:per-minute`
100
+ }
101
+
102
+ /** The flat row: credits once per plan for a mode/tier (0 for tighten and chapters). Never reserved. */
103
+ export function editPlanFlatCreditId(mode: EditPlanMode, tier: EditPlanTier): string {
104
+ return `edit-plan:${mode}:${tier}:flat`
105
+ }
106
+
107
+ /** The mode, tier and minutes of an `edit-plan:<mode>:<tier>:<N>m` id (1 ≤ N ≤
108
+ * the maximum), or `undefined` for anything else (the bare id, a rate or flat
109
+ * row, an unknown mode or tier). */
110
+ export function parseEditPlanMinutesCreditId(
111
+ id: string,
112
+ ): { mode: EditPlanMode; tier: EditPlanTier; minutes: number } | undefined {
113
+ const m = /^edit-plan:([a-z]+):([a-z]+):(\d+)m$/.exec(id)
114
+ if (!m) return undefined
115
+ const mode = parseEditPlanMode(m[1])
116
+ const tier = (EDIT_PLAN_TIERS as readonly string[]).includes(m[2]!) ? (m[2] as EditPlanTier) : undefined
117
+ const minutes = Number(m[3])
118
+ if (!mode || !tier || !Number.isInteger(minutes) || minutes < 1 || minutes > EDIT_PLAN_MAX_MINUTES) return undefined
119
+ return { mode, tier, minutes }
120
+ }
121
+
122
+ /** flat + rate × N, rounded up, at least 1 credit — what an
123
+ * `edit-plan:<mode>:<tier>:<N>m` id costs from its two rows (the plugin's formula). */
124
+ export function editPlanMinutesBaseCredits(flat: number, rate: number, minutes: number): number {
125
+ return Math.max(1, Math.ceil(flat + rate * minutes))
60
126
  }
61
127
 
62
128
  /** Narrow an arbitrary value to a known edit-plan mode, defaulting to "tighten".
@@ -41,8 +41,8 @@ export const NON_PROMPT_TEXT_LANES: Readonly<Record<string, "*" | readonly strin
41
41
  negative: "*",
42
42
  "system-prompt": "*",
43
43
  script: ["ai-avatar"],
44
- transcript: ["add-captions", "apply-edl", "edit-plan", "camera-switch"],
45
- edl: ["apply-edl", "camera-switch"],
44
+ transcript: ["add-captions", "apply-edl", "edit-plan", "camera-switch", "speaker-view"],
45
+ edl: ["apply-edl", "camera-switch", "speaker-view"],
46
46
  silence: ["edit-plan"],
47
47
  offsets: ["edit-plan"],
48
48
  qrText: ["image-overlay"],
package/src/index.ts CHANGED
@@ -186,6 +186,8 @@ export {
186
186
  applyDefaultVideoSelection,
187
187
  PRICING_DEFAULT_DURATION_SEC,
188
188
  pricedOutputDurationSec,
189
+ snapToNearestDuration,
190
+ videoDefaultDurationSec,
189
191
  supportsAutoVideoDuration,
190
192
  maxVideoDurationSec,
191
193
  PRICING_DEFAULT_RESOLUTION,
@@ -299,6 +301,7 @@ export {
299
301
  buildMotionCreditModelIdentifier,
300
302
  speedRampCreditId,
301
303
  applyEdlCreditId,
304
+ speakerViewCreditId,
302
305
  sunoCreditType,
303
306
  SUNO_VERSION_CREDIT_KEYS,
304
307
  SUNO_VERSION_PRICED_OPERATIONS,
@@ -763,6 +766,17 @@ export {
763
766
  type RenderClockSource,
764
767
  type RenderJsonKind,
765
768
  } from "./render-nodes.js"
769
+ export {
770
+ declaredJsonOutput,
771
+ declaredJsonOutputRows,
772
+ jsonOutputKind,
773
+ jsonInputKind,
774
+ jsonKindMismatch,
775
+ jsonKindMismatchMessage,
776
+ type JsonKind,
777
+ type JsonKindMismatch,
778
+ type JsonOutputDeclaration,
779
+ } from "./json-kinds.js"
766
780
  export {
767
781
  PREVIEW_RENDER_NODE_TYPES,
768
782
  PREVIEW_REVIEW_REQUIRED,
@@ -997,6 +1011,23 @@ export {
997
1011
  type SavedPostsLookupResult,
998
1012
  } from "./saved-posts.js"
999
1013
 
1014
+ // Read Inspiration / Read Competitor: the post readers (emit posts the way Social Search does).
1015
+ export {
1016
+ INSPIRATION_READ_NODE_TYPE,
1017
+ COMPETITOR_READ_NODE_TYPE,
1018
+ SOCIAL_POST_READER_NODE_TYPES,
1019
+ isSocialPostReaderNodeType,
1020
+ SOCIAL_READ_LIMIT_MAX,
1021
+ SOCIAL_READ_DEFAULT_LIMIT,
1022
+ SOCIAL_READ_WINDOW_HOURS_MAX,
1023
+ SOCIAL_READ_WINDOW_DAYS_MAX,
1024
+ SOCIAL_READ_PERIODS,
1025
+ COMPETITOR_READ_ROLES,
1026
+ SOCIAL_READ_DAY_PATTERN,
1027
+ type SocialReadPeriod,
1028
+ type CompetitorReadRole,
1029
+ } from "./social-post-readers.js"
1030
+
1000
1031
  export {
1001
1032
  COLLECTION_NAME_MAX,
1002
1033
  COLLECTION_DESCRIPTION_MAX,
@@ -1538,12 +1569,19 @@ export * from "./fan-out-meta.js"
1538
1569
 
1539
1570
  export { SUNO_TRACK_SOURCE_TYPES } from "./suno-track-sources.js"
1540
1571
 
1572
+ export { isPrivateOrReservedIP, isLocalOrPrivateHostname } from "./private-host.js"
1573
+
1541
1574
  // --- Video URL node + social-video import (host allowlist, node output rule) ---
1542
1575
  export {
1543
1576
  SOCIAL_VIDEO_HOSTS,
1544
1577
  YOUTUBE_HOSTS,
1545
1578
  INSTAGRAM_HOSTS,
1546
1579
  VIDEO_LINK_TOLERANT_CONSUMER_TYPES,
1580
+ VIDEO_LINK_AUDIO_CONSUMER_TYPES,
1581
+ videoLinkNeedOf,
1582
+ videoLinkRunNeeds,
1583
+ AUTO_DOWNLOAD_MAX_SEC,
1584
+ YOUTUBE_MAX_HEIGHT,
1547
1585
  hostnameMatchesAllowlist,
1548
1586
  hasUrlParserHazard,
1549
1587
  isSocialVideoUrl,
@@ -1552,8 +1590,14 @@ export {
1552
1590
  resolveVideoLinkOutput,
1553
1591
  videoLinkPageUrl,
1554
1592
  videoLinkNeedsDownload,
1593
+ DIRECT_VIDEO_EXTENSIONS,
1594
+ MAX_VIDEO_LINK_INPUT_CHARS,
1595
+ VIDEO_LINK_DERIVED_FIELDS,
1596
+ isDirectVideoFileUrl,
1597
+ videoLinkInputProblem,
1598
+ dropStaleVideoLinkFields,
1555
1599
  } from "./video-link.js"
1556
- export type { VideoLinkPlatform, VideoLinkNodeFields } from "./video-link.js"
1600
+ export type { VideoLinkPlatform, VideoLinkNodeFields, VideoLinkInputProblem, VideoLinkNeed, VideoLinkGraphNode, VideoLinkGraphEdge } from "./video-link.js"
1557
1601
 
1558
1602
  export {
1559
1603
  VOICE_CHANGER_MODELS,