@nodaro/shared 3.24.0 → 3.26.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 (50) hide show
  1. package/dist/index.cjs +1086 -257
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +531 -97
  4. package/dist/index.d.ts +531 -97
  5. package/dist/index.js +1034 -258
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/condition-variables.test.ts +12 -0
  9. package/src/__tests__/content-recipe-ideas.test.ts +9 -4
  10. package/src/__tests__/credit-identifiers.test.ts +31 -6
  11. package/src/__tests__/dialogue-capabilities.test.ts +3 -2
  12. package/src/__tests__/edit-plan-minute-ids.test.ts +82 -0
  13. package/src/__tests__/image-model-roles.test.ts +57 -0
  14. package/src/__tests__/image-ref-limit.test.ts +1 -0
  15. package/src/__tests__/json-kinds.test.ts +179 -0
  16. package/src/__tests__/llm-models.test.ts +136 -37
  17. package/src/__tests__/lone-media-url.test.ts +78 -0
  18. package/src/__tests__/presentation-utils.test.ts +1 -0
  19. package/src/__tests__/preview-gate.test.ts +2 -2
  20. package/src/__tests__/pricing-default-duration.test.ts +56 -15
  21. package/src/__tests__/private-host.test.ts +24 -0
  22. package/src/__tests__/prompt-length-limits.test.ts +2 -0
  23. package/src/__tests__/render-nodes.test.ts +22 -3
  24. package/src/__tests__/tts-capabilities.test.ts +61 -1
  25. package/src/__tests__/video-link-input.test.ts +148 -0
  26. package/src/__tests__/video-link-needs.test.ts +67 -0
  27. package/src/__tests__/video-request-normalize.test.ts +18 -3
  28. package/src/condition-variables.ts +3 -1
  29. package/src/content-recipe-ideas.ts +5 -2
  30. package/src/credit-identifiers.ts +48 -37
  31. package/src/edit-plan-contract.ts +67 -1
  32. package/src/fan-out-rows.ts +2 -2
  33. package/src/image-model-roles.ts +62 -0
  34. package/src/index.ts +59 -1
  35. package/src/json-kinds.ts +188 -0
  36. package/src/llm-models.ts +348 -23
  37. package/src/lone-media-url.ts +57 -0
  38. package/src/model-catalog.ts +160 -13
  39. package/src/model-constants.ts +79 -43
  40. package/src/node-default-mappings.ts +4 -0
  41. package/src/pipeline-types.ts +13 -2
  42. package/src/presentation-utils.ts +8 -1
  43. package/src/private-host.ts +91 -0
  44. package/src/producer-types.ts +3 -0
  45. package/src/render-nodes.ts +12 -1
  46. package/src/scene-node-types.ts +17 -5
  47. package/src/settings-input.ts +2 -1
  48. package/src/social-post-readers.ts +37 -0
  49. package/src/video-link.ts +238 -0
  50. 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
 
@@ -42,7 +42,9 @@ export function buildConditionVariables<
42
42
  if (edge.targetHandle !== VARIABLES_HANDLE_ID) continue
43
43
  const src = nodes.find((n) => n.id === edge.source)
44
44
  if (!src) continue
45
- const output = extractOutput(src)
45
+ // Surrounding whitespace is never part of a variable: a model's answer
46
+ // ("<id>\n") must still equal the field it is compared with.
47
+ const output = extractOutput(src)?.trim()
46
48
  if (output === undefined || output === "") continue
47
49
  const label = (src.data.label as string) || src.type || src.id
48
50
  pairs.push({ label, output })
@@ -8,8 +8,8 @@ import { buildLlmCreditIdentifier, getLlmModel, LLM_FEATURE_DEFAULTS } from "./l
8
8
  * the cloud plugin that runs the nodes computes the same ids.
9
9
  *
10
10
  * Content Ideas is charged per batch of up to five ideas: a run of 1–5 ideas
11
- * bills `content-ideas[:economy|:premium]`, a run of 6–10 bills
12
- * `content-ideas:10[:economy|:premium]`, priced at two batches.
11
+ * bills `content-ideas[:economy|:premium|:premium-direct]`, a run of 6–10 bills
12
+ * `content-ideas:10[:economy|:premium|:premium-direct]`, priced at two batches.
13
13
  */
14
14
 
15
15
  export const CONTENT_IDEAS_MAX_COUNT = 10
@@ -60,10 +60,13 @@ export const CONTENT_RECIPE_IDEAS_CREDIT_IDS = [
60
60
  "content-recipe:economy",
61
61
  "content-recipe",
62
62
  "content-recipe:premium",
63
+ "content-recipe:premium-direct",
63
64
  "content-ideas:economy",
64
65
  "content-ideas",
65
66
  "content-ideas:premium",
67
+ "content-ideas:premium-direct",
66
68
  "content-ideas:10:economy",
67
69
  "content-ideas:10",
68
70
  "content-ideas:10:premium",
71
+ "content-ideas:10:premium-direct",
69
72
  ] as const
@@ -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"],
@@ -0,0 +1,62 @@
1
+ import { MODEL_CATALOG } from "./model-catalog.js"
2
+
3
+ /**
4
+ * The platform's answer to "which image model, when the caller names none".
5
+ *
6
+ * One table by ROLE, so every surface that picks for the user (node defaults,
7
+ * route and workflow fallbacks, MCP tools, studios, pipelines) reads the same
8
+ * model instead of keeping its own literal. Before this table those literals
9
+ * had drifted apart: the Generate Image node started on Nano Banana Pro, the
10
+ * routes fell back to the original Nano Banana, and MCP used Nano Banana 2.1.
11
+ *
12
+ * Decided on 2026-10-08 from a blind five-model comparison, quality
13
+ * first and price second:
14
+ * - characters, general text-to-image and video anchors on GPT Image 2;
15
+ * - edits on GPT Image 2.5 Flare.
16
+ * With reference images attached, GPT Image 2 runs as its i2i sibling (the
17
+ * provider swaps it), so `character` covers identity-from-reference too.
18
+ *
19
+ * Nano Banana Pro is no longer a default. It remains a FALLBACK only: last in
20
+ * the ratio chain below (it is the one model here that draws 4:5 and 5:4), the
21
+ * GPT-family safety-block retry, and the swimwear dressing model.
22
+ */
23
+ export const IMAGE_MODEL_ROLE_DEFAULTS = {
24
+ character: "gpt-image-2",
25
+ general: "gpt-image-2",
26
+ anchor: "gpt-image-2",
27
+ edit: "gpt-image-2-5-flare-i2i",
28
+ } as const
29
+
30
+ export type ImageModelRole = keyof typeof IMAGE_MODEL_ROLE_DEFAULTS
31
+
32
+ /**
33
+ * Where a role's model goes when it cannot draw the requested aspect ratio.
34
+ * GPT Image 2 draws only auto / 1:1 / 16:9 / 9:16 / 4:3 / 3:4, so 21:9, 3:2,
35
+ * 2:3 and the other wide or in-between ratios move to GPT Image 2.5 Sunburst,
36
+ * and 4:5 / 5:4 (which neither GPT generation draws) to Nano Banana Pro.
37
+ */
38
+ export const IMAGE_MODEL_RATIO_FALLBACKS: Readonly<Record<ImageModelRole, readonly string[]>> = {
39
+ character: ["gpt-image-2-5-sunburst", "nano-banana-pro"],
40
+ general: ["gpt-image-2-5-sunburst", "nano-banana-pro"],
41
+ anchor: ["gpt-image-2-5-sunburst", "nano-banana-pro"],
42
+ edit: ["gpt-image-2-5-sunburst-i2i", "nano-banana-pro"],
43
+ }
44
+
45
+ /** True when the model's catalog entry lists the ratio (or no ratio was asked for). */
46
+ export function imageModelDrawsRatio(modelId: string, aspectRatio?: string | null): boolean {
47
+ if (!aspectRatio) return true
48
+ const ratios = MODEL_CATALOG[modelId]?.aspectRatios
49
+ return ratios === undefined || ratios.includes(aspectRatio)
50
+ }
51
+
52
+ /**
53
+ * The default image model for a role at the requested aspect ratio: the role's
54
+ * model when it draws the ratio, else the first fallback that does, else the
55
+ * role's model (whose own ratio normalization then snaps the ratio). Read from
56
+ * the catalog, so widening a model's documented ratios moves this with it.
57
+ */
58
+ export function defaultImageModel(role: ImageModelRole, aspectRatio?: string | null): string {
59
+ const primary = IMAGE_MODEL_ROLE_DEFAULTS[role]
60
+ if (imageModelDrawsRatio(primary, aspectRatio)) return primary
61
+ return IMAGE_MODEL_RATIO_FALLBACKS[role].find((id) => imageModelDrawsRatio(id, aspectRatio)) ?? primary
62
+ }