@nodaro/shared 3.13.0 → 3.16.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 (142) hide show
  1. package/dist/index.cjs +1293 -55
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +1502 -30
  4. package/dist/index.d.ts +1502 -30
  5. package/dist/index.js +1134 -56
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/camera-switch-contract.test.ts +98 -0
  9. package/src/__tests__/competitors.test.ts +49 -0
  10. package/src/__tests__/content-recipe-ideas.test.ts +96 -0
  11. package/src/__tests__/edl-multicam.test.ts +192 -0
  12. package/src/__tests__/llm-models.test.ts +5 -2
  13. package/src/__tests__/music-provider.test.ts +17 -0
  14. package/src/__tests__/node-runtime-keys.test.ts +10 -0
  15. package/src/__tests__/parameter-node-value.test.ts +2 -1
  16. package/src/__tests__/per-unit-video-pricing.test.ts +97 -0
  17. package/src/__tests__/producer-types.test.ts +35 -0
  18. package/src/__tests__/saved-posts.test.ts +37 -0
  19. package/src/__tests__/script-settings.test.ts +61 -0
  20. package/src/__tests__/settings-input.test.ts +252 -0
  21. package/src/__tests__/social-search.test.ts +243 -0
  22. package/src/__tests__/studio-take-voice.test.ts +200 -0
  23. package/src/__tests__/studio-transient.test.ts +37 -0
  24. package/src/__tests__/sub-gates.test.ts +21 -0
  25. package/src/__tests__/telegram-account-trigger.test.ts +120 -0
  26. package/src/__tests__/video-analysis-pricing.test.ts +27 -13
  27. package/src/__tests__/video-link.test.ts +2 -2
  28. package/src/__tests__/video-utils.test.ts +89 -83
  29. package/src/__tests__/workflow-export-strip.test.ts +37 -0
  30. package/src/camera-switch-contract.ts +166 -0
  31. package/src/catalog-projection.ts +27 -0
  32. package/src/competitors.ts +430 -0
  33. package/src/content-recipe-ideas.ts +69 -0
  34. package/src/credit-estimators/index.ts +14 -0
  35. package/src/credit-estimators/ltx-extend.ts +33 -0
  36. package/src/credit-estimators/ltx-retake.ts +30 -0
  37. package/src/credit-estimators/video-sfx.ts +41 -0
  38. package/src/credit-estimators/video-utils.ts +38 -24
  39. package/src/credit-identifiers.ts +10 -0
  40. package/src/edl-multicam.ts +220 -0
  41. package/src/fan-out-rows.ts +7 -2
  42. package/src/i18n/action-fx.ko.ts +18 -18
  43. package/src/i18n/action-fx.pt-BR.ts +66 -66
  44. package/src/i18n/aesthetic.ko.ts +49 -49
  45. package/src/i18n/aesthetic.pt-BR.ts +14 -14
  46. package/src/i18n/animals.ko.ts +126 -126
  47. package/src/i18n/animals.pt-BR.ts +33 -33
  48. package/src/i18n/atmosphere.ko.ts +37 -37
  49. package/src/i18n/atmosphere.pt-BR.ts +29 -29
  50. package/src/i18n/backdrop.ko.ts +40 -40
  51. package/src/i18n/backdrop.pt-BR.ts +38 -38
  52. package/src/i18n/camera-format.ko.ts +31 -31
  53. package/src/i18n/camera-format.pt-BR.ts +12 -12
  54. package/src/i18n/camera-motions.ko.ts +66 -66
  55. package/src/i18n/camera-motions.pt-BR.ts +51 -51
  56. package/src/i18n/character-fx.ko.ts +19 -19
  57. package/src/i18n/character-fx.pt-BR.ts +64 -52
  58. package/src/i18n/character-motion.ko.ts +164 -164
  59. package/src/i18n/character-motion.pt-BR.ts +867 -858
  60. package/src/i18n/color-look.ko.ts +41 -41
  61. package/src/i18n/color-look.pt-BR.ts +23 -23
  62. package/src/i18n/composition-effects.ko.ts +18 -18
  63. package/src/i18n/composition-effects.pt-BR.ts +17 -17
  64. package/src/i18n/era.ko.ts +28 -28
  65. package/src/i18n/era.pt-BR.ts +20 -20
  66. package/src/i18n/exposure-settings.ko.ts +20 -20
  67. package/src/i18n/exposure-settings.pt-BR.ts +3 -3
  68. package/src/i18n/framing.ko.ts +66 -66
  69. package/src/i18n/framing.pt-BR.ts +50 -50
  70. package/src/i18n/furniture.ko.ts +78 -78
  71. package/src/i18n/furniture.pt-BR.ts +46 -46
  72. package/src/i18n/held-prop.ko.ts +60 -60
  73. package/src/i18n/held-prop.pt-BR.ts +30 -30
  74. package/src/i18n/instrumentation.ko.ts +62 -62
  75. package/src/i18n/instrumentation.pt-BR.ts +64 -64
  76. package/src/i18n/lens.ko.ts +16 -16
  77. package/src/i18n/lens.pt-BR.ts +5 -5
  78. package/src/i18n/lighting.ko.ts +68 -68
  79. package/src/i18n/lighting.pt-BR.ts +43 -43
  80. package/src/i18n/loop-subject.ko.ts +1 -1
  81. package/src/i18n/loop-subject.pt-BR.ts +31 -31
  82. package/src/i18n/materials.ko.ts +66 -66
  83. package/src/i18n/materials.pt-BR.ts +22 -22
  84. package/src/i18n/mood.ko.ts +50 -50
  85. package/src/i18n/mood.pt-BR.ts +12 -12
  86. package/src/i18n/music-genre.ko.ts +28 -28
  87. package/src/i18n/music-genre.pt-BR.ts +50 -50
  88. package/src/i18n/music-mood.ko.ts +27 -27
  89. package/src/i18n/music-mood.pt-BR.ts +20 -20
  90. package/src/i18n/person.ko.ts +396 -396
  91. package/src/i18n/person.pt-BR.ts +237 -237
  92. package/src/i18n/photo-genre.ko.ts +46 -46
  93. package/src/i18n/photo-genre.pt-BR.ts +32 -32
  94. package/src/i18n/photographer.ko.ts +63 -63
  95. package/src/i18n/photographer.pt-BR.ts +15 -15
  96. package/src/i18n/pose.ko.ts +81 -81
  97. package/src/i18n/pose.pt-BR.ts +65 -65
  98. package/src/i18n/post-process-effects.ko.ts +18 -18
  99. package/src/i18n/post-process-effects.pt-BR.ts +18 -18
  100. package/src/i18n/render-quality.ko.ts +24 -24
  101. package/src/i18n/render-quality.pt-BR.ts +12 -12
  102. package/src/i18n/setting.ko.ts +64 -64
  103. package/src/i18n/setting.pt-BR.ts +41 -41
  104. package/src/i18n/style.ko.ts +49 -49
  105. package/src/i18n/style.pt-BR.ts +19 -19
  106. package/src/i18n/styling.ko.ts +265 -265
  107. package/src/i18n/styling.pt-BR.ts +141 -141
  108. package/src/i18n/temporal.ko.ts +18 -18
  109. package/src/i18n/temporal.pt-BR.ts +12 -12
  110. package/src/i18n/transitions.ko.ts +14 -14
  111. package/src/i18n/transitions.pt-BR.ts +83 -71
  112. package/src/i18n/vehicles.ko.ts +107 -107
  113. package/src/i18n/vehicles.pt-BR.ts +55 -55
  114. package/src/i18n/voice-character.ko.ts +19 -19
  115. package/src/i18n/voice-character.pt-BR.ts +19 -19
  116. package/src/i18n/voice-delivery.ko.ts +22 -22
  117. package/src/i18n/voice-delivery.pt-BR.ts +22 -22
  118. package/src/i18n/weapons.ko.ts +85 -85
  119. package/src/i18n/weapons.pt-BR.ts +46 -46
  120. package/src/index.ts +202 -1
  121. package/src/llm-models.ts +11 -0
  122. package/src/model-catalog.ts +30 -14
  123. package/src/model-constants.ts +28 -0
  124. package/src/node-mappable-fields.ts +21 -5
  125. package/src/node-runtime-keys.ts +33 -0
  126. package/src/oauth-scopes.ts +28 -0
  127. package/src/parameter-node-value.ts +13 -5
  128. package/src/pipeline-defaults.ts +14 -0
  129. package/src/pipeline-state-types.ts +14 -0
  130. package/src/producer-types.ts +85 -0
  131. package/src/recast-segment-packs.ts +13 -0
  132. package/src/resolve-field-mappings.ts +15 -5
  133. package/src/saved-posts.ts +106 -0
  134. package/src/script-settings.ts +70 -0
  135. package/src/settings-input.ts +366 -0
  136. package/src/social-search.ts +467 -0
  137. package/src/studio-transient.ts +176 -5
  138. package/src/telegram-account-send.ts +32 -0
  139. package/src/telegram-account-trigger.ts +108 -0
  140. package/src/video-analysis-pricing.ts +17 -6
  141. package/src/video-link.ts +16 -4
  142. package/src/workflow-export.ts +7 -0
@@ -1,19 +1,32 @@
1
1
  /**
2
2
  * Pure credit estimators for video-utility nodes (loop-video, trim-video,
3
- * combine-videos). Used by frontend (Run-button display + API call) AND
4
- * backend (creditGuard reservation) so the displayed cost equals what gets
5
- * debited.
3
+ * combine-videos, assemble-narrated-video). Used by frontend (Run-button
4
+ * display + API call) AND backend (creditGuard reservation, the workflow
5
+ * run's reservation, the workflow estimate) so the displayed cost equals
6
+ * what gets debited.
7
+ *
8
+ * Every estimate counts pricing UNITS and returns units × CREDIT_UNIT base
9
+ * credits: a unit is 5 seconds of output, ~24 frames a smart loop cut
10
+ * searches, each combine input beyond two, and each step of Assemble Narrated
11
+ * Video (3 + 1 per 6 blocks).
6
12
  */
7
13
 
8
14
  export const VIDEO_UTIL_PRICING = {
9
- /** 1 credit per 5 seconds of output, ceiling. */
10
- CREDITS_PER_5_SEC: 1,
11
- /** Smart-loop-cut work scales at 1 credit per ~24 frames searched. */
15
+ /** Base credits per pricing unit. The node's own `model_pricing` row is one unit. */
16
+ CREDIT_UNIT: 10,
17
+ /** Base credits per 5 seconds of output (one unit), ceiling. */
18
+ CREDITS_PER_5_SEC: 10,
19
+ /** Smart-loop-cut work scales at one unit per ~24 frames searched. */
12
20
  FRAMES_PER_CREDIT: 24,
13
21
  /** Used when an upstream node hasn't produced a measurable duration yet. */
14
22
  FALLBACK_DURATION_SECONDS: 8,
15
23
  } as const
16
24
 
25
+ /** Base credits for a count of pricing units, never below one unit. */
26
+ function unitsToCredits(units: number): number {
27
+ return VIDEO_UTIL_PRICING.CREDIT_UNIT * Math.max(1, units)
28
+ }
29
+
17
30
  export interface LoopVideoEstimatorInput {
18
31
  mode?: "repeat" | "duration"
19
32
  repeatCount?: number
@@ -64,7 +77,7 @@ export function estimateLoopVideoCredits(
64
77
  ? Math.ceil((data.smartLoopCutLookback ?? 16) / VIDEO_UTIL_PRICING.FRAMES_PER_CREDIT)
65
78
  : 0
66
79
 
67
- return Math.max(1, base + cut)
80
+ return unitsToCredits(base + cut)
68
81
  }
69
82
 
70
83
  export function estimateTrimVideoCredits(
@@ -77,7 +90,7 @@ export function estimateTrimVideoCredits(
77
90
  if (data.trimMode === "smart-loop-cut") {
78
91
  const base = Math.ceil(inputDuration / 5)
79
92
  const cut = Math.ceil((data.smartLoopCutLookback ?? 16) / VIDEO_UTIL_PRICING.FRAMES_PER_CREDIT)
80
- return Math.max(1, base + cut)
93
+ return unitsToCredits(base + cut)
81
94
  }
82
95
 
83
96
  if (data.trimMode === "frames") {
@@ -85,34 +98,34 @@ export function estimateTrimVideoCredits(
85
98
  const startSec = (data.trimStartFrames ?? 0) / VIDEO_UTIL_PRICING.FRAMES_PER_CREDIT
86
99
  const endSec = (data.trimEndFrames ?? 0) / VIDEO_UTIL_PRICING.FRAMES_PER_CREDIT
87
100
  const output = Math.max(0, inputDuration - startSec - endSec)
88
- return Math.max(1, Math.ceil(output / 5))
101
+ return unitsToCredits(Math.ceil(output / 5))
89
102
  }
90
103
 
91
104
  if (data.trimMode === "seconds") {
92
105
  const output = Math.max(0, inputDuration - (data.trimStartSeconds ?? 0) - (data.trimEndSeconds ?? 0))
93
- return Math.max(1, Math.ceil(output / 5))
106
+ return unitsToCredits(Math.ceil(output / 5))
94
107
  }
95
108
 
96
109
  if (data.trimMode === "keep-first-seconds") {
97
110
  const output = Math.min(inputDuration, Math.max(0, data.keepFirstSeconds ?? 0))
98
- return Math.max(1, Math.ceil(output / 5))
111
+ return unitsToCredits(Math.ceil(output / 5))
99
112
  }
100
113
 
101
114
  if (data.trimMode === "keep-last-seconds") {
102
115
  const output = Math.min(inputDuration, Math.max(0, data.keepLastSeconds ?? 0))
103
- return Math.max(1, Math.ceil(output / 5))
116
+ return unitsToCredits(Math.ceil(output / 5))
104
117
  }
105
118
 
106
119
  // "time" mode (default)
107
120
  const output = (data.endTime ?? 0) - (data.startTime ?? 0)
108
- return Math.max(1, Math.ceil(output / 5))
121
+ return unitsToCredits(Math.ceil(output / 5))
109
122
  }
110
123
 
111
124
  export function estimateCombineVideosCredits(
112
125
  data: CombineVideosEstimatorInput,
113
126
  upstreamDurations: ReadonlyArray<number | undefined>,
114
127
  ): number {
115
- if (upstreamDurations.length === 0) return 1
128
+ if (upstreamDurations.length === 0) return unitsToCredits(1)
116
129
 
117
130
  const fallback = VIDEO_UTIL_PRICING.FALLBACK_DURATION_SECONDS
118
131
  const n = upstreamDurations.length
@@ -133,7 +146,7 @@ export function estimateCombineVideosCredits(
133
146
 
134
147
  const base = Math.ceil(Math.max(0, total) / 5)
135
148
  const inputAdder = Math.max(0, n - 2)
136
- return Math.max(1, base + inputAdder)
149
+ return unitsToCredits(base + inputAdder)
137
150
  }
138
151
 
139
152
  export interface LoopTrimEstimatorInput {
@@ -143,23 +156,24 @@ export interface LoopTrimEstimatorInput {
143
156
 
144
157
  /** Add-on credits charged for the smart-loop-cut post-process applied to an
145
158
  * image-to-video output. Returns 0 when loopTrim is undefined or disabled.
146
- * Formula: ceil(duration / 5) + ceil(framesToTest / 24) — matches the
147
- * trim-video smart-loop-cut formula for consistency. */
159
+ * Formula: CREDIT_UNIT × (ceil(duration / 5) + ceil(framesToTest / 24)) —
160
+ * the same units as Trim Video's smart loop cut, so 8 s at 16 frames → 30. */
148
161
  export function estimateLoopTrimAddonCredits(
149
162
  loopTrim: LoopTrimEstimatorInput | undefined,
150
163
  outputDurationSeconds: number,
151
164
  ): number {
152
165
  if (!loopTrim?.enabled) return 0
153
166
  const frames = Math.max(1, Math.min(loopTrim.framesToTest ?? 16, 64))
154
- return Math.ceil(outputDurationSeconds / 5) +
155
- Math.ceil(frames / VIDEO_UTIL_PRICING.FRAMES_PER_CREDIT)
167
+ return unitsToCredits(
168
+ Math.ceil(outputDurationSeconds / 5) + Math.ceil(frames / VIDEO_UTIL_PRICING.FRAMES_PER_CREDIT),
169
+ )
156
170
  }
157
171
 
158
- /** BASE credits for assemble-narrated-video: 3 flat + 1 per 6
159
- * blocks. 6→4, 24→7, 60→13. Single source of truth shared by the backend
172
+ /** BASE credits for assemble-narrated-video: 3 units flat + 1 per 6
173
+ * blocks. 6→40, 24→70, 60→130. Single source of truth shared by the backend
160
174
  * route/creditGuard (`backend/src/providers/video/narrated-block-fit.ts`
161
- * re-exports this) and the frontend pre-run estimate
162
- * (`frontend/src/hooks/use-estimated-credits.ts`). */
175
+ * re-exports this), the workflow run's reservation and the frontend pre-run
176
+ * estimate (`frontend/src/hooks/use-estimated-credits.ts`). */
163
177
  export function assembleNarratedVideoCredits(blockCount: number): number {
164
- return 3 + Math.ceil(blockCount / 6)
178
+ return unitsToCredits(3 + Math.ceil(blockCount / 6))
165
179
  }
@@ -652,6 +652,16 @@ export const SUNO_SELECT_OPERATIONS = [
652
652
  "suno-upload-extend",
653
653
  ] as const
654
654
 
655
+ /**
656
+ * Adjust Speed's price id: motion-compensated ("smooth") interpolation is its
657
+ * own, dearer tier. The route, the workflow run, and the editor's badge and
658
+ * run estimate all price through this, so none of them can quote the fast tier
659
+ * for a smooth run.
660
+ */
661
+ export function speedRampCreditId(quality: unknown): "speed-ramp" | "speed-ramp:smooth" {
662
+ return quality === "smooth" ? "speed-ramp:smooth" : "speed-ramp"
663
+ }
664
+
655
665
  /**
656
666
  * OUR Nodaro credit key for a Suno operation, given the model version and the
657
667
  * operation (which is also the node type and the BullMQ job name).
@@ -91,6 +91,226 @@ export function mergeEdlSourceOffsets(
91
91
  return { edl: merged, ...(anchor !== undefined ? { anchor } : {}), applied, ignored }
92
92
  }
93
93
 
94
+ // ─────────────────────────────────────────────────────────────────────────
95
+ // B4 — audio-sync offsets onto a planner's sources
96
+ // ─────────────────────────────────────────────────────────────────────────
97
+
98
+ /** Below this, a measured offset is not trusted (audio-sync's own
99
+ * "check it by ear" line). */
100
+ export const AUDIO_SYNC_MIN_CONFIDENCE = 0.5
101
+
102
+ /** One source row as a planner (edit-plan) sends it. */
103
+ export interface AudioSyncOffsetSource {
104
+ readonly id: string
105
+ readonly role?: string
106
+ /** Set = a hand-set offset, which always wins over a measured one. */
107
+ readonly offsetMs?: number
108
+ }
109
+
110
+ /** Why measured offsets could not be applied. Every code names the source to
111
+ * fix, so a caller can phrase it with its own label (`describeAudioSyncOffsetIssue`). */
112
+ export type AudioSyncOffsetIssue =
113
+ | { readonly code: "not-audio-sync" }
114
+ | { readonly code: "invalid-offset"; readonly sourceId: string }
115
+ | { readonly code: "anchor-offset"; readonly sourceId: string; readonly offsetMs: number }
116
+ | { readonly code: "anchor-unmeasured"; readonly sourceId: string }
117
+ | { readonly code: "weak-match"; readonly sourceId: string; readonly confidence: number; readonly anchor: boolean }
118
+ | { readonly code: "unmeasured"; readonly sourceId: string }
119
+
120
+ export type AudioSyncOffsetsResult<S> =
121
+ | {
122
+ readonly ok: true
123
+ /** The sources, with the measured offsets written onto `offsetMs`. */
124
+ readonly sources: S[]
125
+ /** The source whose clock the offsets are anchored to. */
126
+ readonly anchor?: string
127
+ /** Source ids that took a measured offset. */
128
+ readonly applied: readonly string[]
129
+ }
130
+ | { readonly ok: false; readonly issues: readonly AudioSyncOffsetIssue[] }
131
+
132
+ interface SyncRow { readonly offsetMs: number; readonly confidence: number }
133
+
134
+ /** audio-sync's result (an object, or the JSON string a canvas handle carries)
135
+ * → its rows by source id, the reference included; null when it is not one. */
136
+ function readAudioSyncRows(sync: unknown): Map<string, SyncRow> | null {
137
+ let value = sync
138
+ if (typeof value === "string") {
139
+ try { value = JSON.parse(value) } catch { return null }
140
+ }
141
+ if (!value || typeof value !== "object") return null
142
+ const { reference, offsets } = value as { reference?: unknown; offsets?: unknown }
143
+ if (!Array.isArray(offsets)) return null
144
+ const rows = new Map<string, SyncRow>()
145
+ for (const row of offsets) {
146
+ if (!row || typeof row !== "object") return null
147
+ const { sourceId, offsetMs, confidence } = row as Record<string, unknown>
148
+ if (typeof sourceId !== "string" || !isFiniteNumber(offsetMs)) return null
149
+ if (!rows.has(sourceId)) rows.set(sourceId, { offsetMs, confidence: isFiniteNumber(confidence) ? confidence : 0 })
150
+ }
151
+ // The reference is measured by definition (its own offset is 0).
152
+ if (typeof reference === "string" && reference && !rows.has(reference)) rows.set(reference, { offsetMs: 0, confidence: 1 })
153
+ return rows
154
+ }
155
+
156
+ const handSet = (s: AudioSyncOffsetSource): boolean => isFiniteNumber(s.offsetMs)
157
+
158
+ /** The source whose clock a planner's plan is on: the `master-audio` source,
159
+ * else the first (edit-plan's `masterProbeSource`). */
160
+ function plannerClockSource<S extends AudioSyncOffsetSource>(sources: readonly S[]): S | undefined {
161
+ return sources.find((s) => s.role === "master-audio") ?? sources[0]
162
+ }
163
+
164
+ /** B4 — audio-sync's measured offsets → a planner's `sources[].offsetMs`
165
+ * (decided 2026-09-25). The planner makes its plan on its MASTER's clock:
166
+ * the `master-audio` source, else its first source (edit-plan's own rule) —
167
+ * the ANCHOR. Every other source gets `offsetMs = measured(s) − measured(anchor)`
168
+ * (D19 via `mergeEdlSourceOffsets`), so audio-sync's reference need not be the
169
+ * master. Never out of sync silently — each of these is an issue instead:
170
+ * - a source with a hand-set `offsetMs` keeps it (it always wins);
171
+ * - a source audio-sync did not measure → "unmeasured";
172
+ * - a measured source under `AUDIO_SYNC_MIN_CONFIDENCE` → "weak-match";
173
+ * - the anchor unmeasured / weak, when any source needs it → "anchor-…";
174
+ * - a hand-set non-zero offset on the anchor → "anchor-offset" (its clock is the plan's).
175
+ * Rows for sources the planner does not have are ignored. Pure; never throws. */
176
+ export function applyAudioSyncOffsets<S extends AudioSyncOffsetSource>(
177
+ sources: readonly S[],
178
+ sync: unknown,
179
+ ): AudioSyncOffsetsResult<S> {
180
+ const rows = readAudioSyncRows(sync)
181
+ if (!rows) return { ok: false, issues: [{ code: "not-audio-sync" }] }
182
+ const list = Array.isArray(sources) ? sources.filter((s): s is S => !!s && typeof s === "object") : []
183
+ const anchor = plannerClockSource(list)
184
+ if (!anchor) return { ok: true, sources: [...list], applied: [] }
185
+
186
+ const issues: AudioSyncOffsetIssue[] = []
187
+ // A hand-set offset that is not a number (a "500" from a JSON file) would
188
+ // otherwise be read as absent, or summed as a string.
189
+ for (const s of list) if (s.offsetMs !== undefined && !handSet(s)) issues.push({ code: "invalid-offset", sourceId: s.id })
190
+ if (handSet(anchor) && anchor.offsetMs !== 0) {
191
+ issues.push({ code: "anchor-offset", sourceId: anchor.id, offsetMs: anchor.offsetMs! })
192
+ }
193
+ const measured: Record<string, number> = {}
194
+ for (const s of list) {
195
+ if (s.id === anchor.id || handSet(s)) continue
196
+ const row = rows.get(s.id)
197
+ if (!row) issues.push({ code: "unmeasured", sourceId: s.id })
198
+ else if (!(row.confidence >= AUDIO_SYNC_MIN_CONFIDENCE)) issues.push({ code: "weak-match", sourceId: s.id, confidence: row.confidence, anchor: false })
199
+ else measured[s.id] = row.offsetMs
200
+ }
201
+ // The anchor's own measurement is the rebase point — needed only when some
202
+ // source takes a measured offset.
203
+ if (Object.keys(measured).length > 0) {
204
+ const row = rows.get(anchor.id)
205
+ if (!row) issues.push({ code: "anchor-unmeasured", sourceId: anchor.id })
206
+ else if (!(row.confidence >= AUDIO_SYNC_MIN_CONFIDENCE)) issues.push({ code: "weak-match", sourceId: anchor.id, confidence: row.confidence, anchor: true })
207
+ else measured[anchor.id] = row.offsetMs
208
+ }
209
+ if (issues.length > 0) return { ok: false, issues }
210
+ if (Object.keys(measured).length === 0) return { ok: true, sources: [...list], anchor: anchor.id, applied: [] }
211
+
212
+ // One arithmetic implementation: the D19 anchored SET.
213
+ const pseudo = { version: 1, clock: "master", sources: list, segments: [] } as unknown as Edl
214
+ const merged = mergeEdlSourceOffsets(pseudo, measured, { anchor: anchor.id })
215
+ const byId = new Map(merged.edl.sources.map((s) => [s.id, s.offsetMs]))
216
+ const applied = new Set(merged.applied)
217
+ return {
218
+ ok: true,
219
+ sources: list.map((s) => (applied.has(s.id) ? { ...s, offsetMs: byId.get(s.id)! } : s)),
220
+ anchor: anchor.id,
221
+ applied: merged.applied,
222
+ }
223
+ }
224
+
225
+ /** Why edit-plan's sources cannot be planned as given: an audio-sync issue,
226
+ * or a transcript made from a recording that is off the plan's clock. */
227
+ export type EditPlanSourceIssue =
228
+ | AudioSyncOffsetIssue
229
+ | { readonly code: "transcript-off-clock"; readonly sourceId: string; readonly masterId: string; readonly offsetMs: number }
230
+
231
+ /** B4 — the ONE check every edit-plan caller runs before dispatch (the
232
+ * orchestrator, the editor, MCP, the SDK), so a plan that would render out of
233
+ * sync fails before charging (decided 2026-09-25):
234
+ * - `offsets` given (audio-sync's result; null/"" when wired but empty) →
235
+ * `applyAudioSyncOffsets`;
236
+ * - the master's own offset must be 0 (the plan follows its clock);
237
+ * - `transcriptSourceId` (the recording the transcript was made from, when
238
+ * known) must be on the master's clock: the master itself, or a source
239
+ * whose offset is 0. Unknown → assumed the master's.
240
+ * `transcriptSourceId` is echoed back only when it names one of the sources,
241
+ * for the caller to stamp on the transcript. Pure; never throws. */
242
+ export function resolveEditPlanSources<S extends AudioSyncOffsetSource>(
243
+ sources: readonly S[],
244
+ opts: { readonly offsets?: unknown; readonly transcriptSourceId?: string } = {},
245
+ ):
246
+ | { readonly ok: true; readonly sources: S[]; readonly transcriptSourceId?: string }
247
+ | { readonly ok: false; readonly issues: readonly EditPlanSourceIssue[] } {
248
+ const list = Array.isArray(sources) ? sources.filter((s): s is S => !!s && typeof s === "object") : []
249
+ const anchor = plannerClockSource(list)
250
+ const issues: EditPlanSourceIssue[] = []
251
+ let planned: S[] = [...list]
252
+ if (opts.offsets !== undefined) {
253
+ const synced = applyAudioSyncOffsets(list, opts.offsets)
254
+ if (synced.ok) planned = synced.sources
255
+ else issues.push(...synced.issues)
256
+ } else {
257
+ for (const s of list) if (s.offsetMs !== undefined && !handSet(s)) issues.push({ code: "invalid-offset", sourceId: s.id })
258
+ if (anchor && handSet(anchor) && anchor.offsetMs !== 0) {
259
+ issues.push({ code: "anchor-offset", sourceId: anchor.id, offsetMs: anchor.offsetMs! })
260
+ }
261
+ }
262
+ const spoken = opts.transcriptSourceId ? planned.find((s) => s.id === opts.transcriptSourceId) : undefined
263
+ if (spoken && anchor && spoken.id !== anchor.id && handSet(spoken) && spoken.offsetMs !== 0) {
264
+ issues.push({ code: "transcript-off-clock", sourceId: spoken.id, masterId: anchor.id, offsetMs: spoken.offsetMs! })
265
+ }
266
+ if (issues.length > 0) return { ok: false, issues }
267
+ return { ok: true, sources: planned, ...(spoken ? { transcriptSourceId: spoken.id } : {}) }
268
+ }
269
+
270
+ /** The recording a transcript was made from, traced on a canvas: the node
271
+ * feeding the transcribing node, through clock-preserving hops (extract-audio).
272
+ * Undefined when the producer is not a transcriber or the trace is ambiguous
273
+ * (more than one upstream) — the caller then assumes the master's clock. */
274
+ export function editPlanTranscriptOrigin(
275
+ producerId: string,
276
+ typeOf: (nodeId: string) => string | undefined,
277
+ edges: ReadonlyArray<{ readonly source: string; readonly target: string }>,
278
+ ): string | undefined {
279
+ if (typeOf(producerId) !== "transcribe") return undefined
280
+ let current = producerId
281
+ for (let hop = 0; hop < 4; hop++) {
282
+ const upstream = [...new Set(edges.filter((e) => e.target === current).map((e) => e.source))]
283
+ if (upstream.length !== 1) return undefined
284
+ const up = upstream[0]!
285
+ if (typeOf(up) !== "extract-audio") return up
286
+ current = up
287
+ }
288
+ return undefined
289
+ }
290
+
291
+ /** A plain-language line for one issue; `labelOf` turns a source id into the
292
+ * name the user sees (a canvas node's label, say). */
293
+ export function describeAudioSyncOffsetIssue(issue: EditPlanSourceIssue, labelOf: (sourceId: string) => string = (id) => id): string {
294
+ switch (issue.code) {
295
+ case "transcript-off-clock":
296
+ return `the transcript was made from "${labelOf(issue.sourceId)}", which is ${issue.offsetMs} ms off the master "${labelOf(issue.masterId)}" — the plan follows the master's clock, so transcribe "${labelOf(issue.masterId)}", or mark "${labelOf(issue.sourceId)}" as master audio`
297
+ case "not-audio-sync":
298
+ return "the offsets carry no Audio Sync result — pass its job's output_data.json (on the canvas: connect Audio Sync's Offsets output and run it)"
299
+ case "invalid-offset":
300
+ return `the offset set on "${labelOf(issue.sourceId)}" is not a number of milliseconds`
301
+ case "anchor-offset":
302
+ return `"${labelOf(issue.sourceId)}" is the master (the plan follows its clock), so its offset must be 0, not ${issue.offsetMs} ms`
303
+ case "anchor-unmeasured":
304
+ return `audio-sync did not measure "${labelOf(issue.sourceId)}", the master the other sources are timed against — add it to audio-sync's sources`
305
+ case "weak-match":
306
+ return issue.anchor
307
+ ? `audio-sync's match for "${labelOf(issue.sourceId)}", the master the other sources are timed against, is too weak to trust (confidence ${issue.confidence}; ${AUDIO_SYNC_MIN_CONFIDENCE} needed) — set the other sources' offsets by hand, or mark a better-recorded source as master audio`
308
+ : `audio-sync's match for "${labelOf(issue.sourceId)}" is too weak to trust (confidence ${issue.confidence}; ${AUDIO_SYNC_MIN_CONFIDENCE} needed) — set its offset by hand`
309
+ case "unmeasured":
310
+ return `"${labelOf(issue.sourceId)}" was not measured by audio-sync — wire it into audio-sync, or set its offset by hand (0 if it started with the master)`
311
+ }
312
+ }
313
+
94
314
  // ─────────────────────────────────────────────────────────────────────────
95
315
  // D20 — slot resolution
96
316
  // ─────────────────────────────────────────────────────────────────────────
@@ -40,11 +40,16 @@ export const NON_PROMPT_TEXT_LANES: Readonly<Record<string, "*" | readonly strin
40
40
  negative: "*",
41
41
  "system-prompt": "*",
42
42
  script: ["ai-avatar"],
43
- transcript: ["add-captions", "apply-edl", "edit-plan"],
44
- edl: ["apply-edl"],
43
+ transcript: ["add-captions", "apply-edl", "edit-plan", "camera-switch"],
44
+ edl: ["apply-edl", "camera-switch"],
45
45
  silence: ["edit-plan"],
46
+ offsets: ["edit-plan"],
46
47
  qrText: ["image-overlay"],
47
48
  transition: ["slideshow"],
49
+ // Content Recipe's `link` carries the post's address (inputs.sourceLink), not
50
+ // the material it analyzes — a list of links fanned through it must not be
51
+ // written into the material too.
52
+ link: ["content-recipe"],
48
53
  }
49
54
 
50
55
  /** Does a TEXT list wired to `targetHandle` of a `nodeType` node feed its prompt slot? */
@@ -10,31 +10,31 @@ const map: LocaleCatalogMap = {
10
10
  "hurricane": { label: "허리케인", description: "나무를 휘게 하는 광풍, 몰아치는 빗줄기" },
11
11
  "blizzard-whiteout": { label: "눈보라 화이트아웃", description: "시야를 지우는 폭설" },
12
12
  "sandstorm": { label: "모래폭풍", description: "장면을 삼키는 오렌지색 먼지의 벽" },
13
- "dust-storm-haboob": { label: "먼지폭풍 (하부브)", description: "거대한 사막 먼지 전선" },
13
+ "dust-storm-haboob": { label: "먼지폭풍(하부브)", description: "거대한 사막 먼지 전선" },
14
14
  "wildfire-distant": { label: "원거리 산불", description: "지평선의 오렌지빛과 연기" },
15
15
  "wildfire-engulfing": { label: "삼키는 산불", description: "다가오는 화염, 강렬한 열기 일렁임" },
16
16
  "volcanic-eruption": { label: "화산 폭발", description: "치솟는 용암, 화산재 기둥" },
17
- "lava-flow": { label: "용암류", description: "지면을 기어가는 빛나는 용융 강" },
17
+ "lava-flow": { label: "용암류", description: "지면을 따라 서서히 흘러가는 이글거리는 용암의 강" },
18
18
  "ash-rain": { label: "화산재 비", description: "눈처럼 내리는 종말적 회색 화산재" },
19
19
  "avalanche": { label: "눈사태", description: "산비탈을 굴러내려오는 눈의 벽" },
20
20
  "hailstorm": { label: "우박 폭풍", description: "표면에서 튀는 큰 우박" },
21
21
 
22
22
  // ── Fire & Blasts ──
23
- "explosion-small": { label: "소형 폭발", description: "초점 섬광이 있는 소형 폭발" },
23
+ "explosion-small": { label: "소형 폭발", description: "중심부 섬광을 동반한 소형 폭발" },
24
24
  "explosion-large": { label: "대형 폭발", description: "잔해를 동반한 차량 규모의 화염구" },
25
25
  "explosion-massive": { label: "초대형 폭발", description: "건물을 무너뜨리는 화염구와 충격파" },
26
26
  "nuclear-detonation": { label: "핵폭발", description: "버섯구름과 지평선을 비추는 섬광" },
27
27
  "fireball-airborne": { label: "공중 화염구", description: "공중에서 굴러가는 불꽃의 구체" },
28
- "gas-explosion": { label: "가스 폭발", description: "밝은 프로판식 폭발" },
29
- "oil-fire": { label: "석유 화재", description: "높이 솟는 기름진 화염과 짙은 검은 연기" },
28
+ "gas-explosion": { label: "가스 폭발", description: "프로판 가스가 터지는 듯한 밝은 폭발" },
29
+ "oil-fire": { label: "석유 화재", description: "높이 치솟는 그을음 섞인 화염과 짙은 검은 연기" },
30
30
  "blazing-inferno": { label: "맹렬한 화염지옥", description: "모든 것을 삼키는 불의 벽" },
31
31
  "flame-burst": { label: "화염 분출", description: "빠른 방향성 불꽃 분사" },
32
- "ember-shower": { label: "잉걸불 소나기", description: "빛나는 오렌지 잉걸불의 폭포" },
32
+ "ember-shower": { label: "쏟아지는 불씨", description: "폭포처럼 쏟아지는 오렌지빛 불씨" },
33
33
  "smoke-pillar": { label: "연기 기둥", description: "검은 연기의 높은 수직 기둥" },
34
34
  "mushroom-cloud": { label: "버섯구름", description: "고전적인 돔과 줄기 형태의 폭발 구름" },
35
35
 
36
36
  // ── Electric ──
37
- "lightning-bolt": { label: "번개", description: "폭풍우 하늘을 가로지르는 분기 방전" },
37
+ "lightning-bolt": { label: "번개", description: "폭풍우 치는 하늘을 가로지르며 갈라지는 번개 줄기" },
38
38
  "lightning-strike-impact": { label: "낙뢰 충격", description: "빛의 폭발을 동반한 지면 낙뢰" },
39
39
  "lightning-storm": { label: "낙뢰 폭풍", description: "동시 다발적인 낙뢰" },
40
40
  "ball-lightning": { label: "구상 번개", description: "공중에 떠 있는 빛나는 전기 플라즈마 구체" },
@@ -49,16 +49,16 @@ const map: LocaleCatalogMap = {
49
49
  "muzzle-flash": { label: "총구 화염", description: "총구에서 터지는 밝은 오렌지 섬광" },
50
50
  "gunshot-impact": { label: "탄착 충격", description: "표면을 때리는 탄환과 흩날리는 파편" },
51
51
  "bullet-trail": { label: "탄환 궤적", description: "공기를 가르는 가시적인 탄환 궤적" },
52
- "sword-spark": { label: "검 불꽃", description: "금속 마찰 불꽃의 매크로 샤워" },
53
- "blade-clash": { label: "검 격돌", description: "충격파를 동반한 두 칼날의 만남" },
52
+ "sword-spark": { label: "검 불꽃", description: "매크로로 담은, 금속끼리 부딪혀 쏟아지는 마찰 불꽃" },
53
+ "blade-clash": { label: "검 격돌", description: "충격파를 일으키며 맞부딪히는 두 칼날" },
54
54
  "ricochet-spark": { label: "도탄 불꽃", description: "금속에 튕기는 탄환과 불꽃" },
55
55
  "debris-field": { label: "잔해 지대", description: "공중에 멈춰 흩어지는 파편" },
56
- "glass-shatter-airborne": { label: "공중 유리 파열", description: "공중에 떠 있는 조각으로 산산조각 나는 유리" },
57
- "shockwave-ground": { label: "지면 충격파", description: "지면 높이에서 퍼지는 가시적인 환형파" },
56
+ "glass-shatter-airborne": { label: "공중 유리 파열", description: "공중에서 바깥으로 산산조각 나 흩어지는 유리 파편" },
57
+ "shockwave-ground": { label: "지면 충격파", description: "지면을 따라 퍼져 나가는, 눈에 보이는 고리 모양 파동" },
58
58
  "sonic-boom": { label: "음속 폭음", description: "초음속에서의 압축 공기 원뿔" },
59
- "smoke-grenade": { label: "연막탄", description: "외부로 퍼지는 짙은 색 연기" },
59
+ "smoke-grenade": { label: "연막탄", description: "바깥으로 피어오르는 짙은 컬러 연기" },
60
60
  "flashbang": { label: "섬광탄", description: "시야를 가리는 백색 섬광 폭발" },
61
- "blood-spray": { label: "혈액 분사", description: "영화적인 혈액 방울의 호" },
61
+ "blood-spray": { label: "피 튀김", description: "영화적인 호를 그리며 튀는 핏방울" },
62
62
  "arrow-hit-spark": { label: "화살 명중 불꽃", description: "충돌 지점의 작은 불꽃과 함께 박히는 화살" },
63
63
 
64
64
  // ── Sci-Fi ──
@@ -66,24 +66,24 @@ const map: LocaleCatalogMap = {
66
66
  "energy-beam": { label: "에너지 빔", description: "넓고 맥동하는 플라즈마 에너지 빔" },
67
67
  "plasma-bolt": { label: "플라즈마 볼트", description: "증기 흔적을 남기는 빛나는 발사체" },
68
68
  "force-field-shimmer": { label: "역장의 어른거림", description: "육각 패턴의 반투명 에너지 장벽" },
69
- "force-field-impact": { label: "역장 충돌", description: "발사체가 방패에 닿는 가시적인 파동" },
69
+ "force-field-impact": { label: "역장 충돌", description: "발사체가 보호막에 부딪힌 자리에 번지는 파문" },
70
70
  "portal-opening": { label: "포털 개방", description: "공간을 찢는 에너지 소용돌이" },
71
71
  "warp-distortion": { label: "워프 왜곡", description: "물체 주위로 휘어지는 시공간" },
72
72
  "hologram-flicker": { label: "홀로그램 깜빡임", description: "글리치가 발생하는 반투명 투영" },
73
- "ion-storm": { label: "이온 폭풍", description: "우주적 배경에 펼쳐진 대전 입자의 작렬" },
73
+ "ion-storm": { label: "이온 폭풍", description: "우주를 배경으로 지지직 튀는 대전 입자의 장" },
74
74
  "antimatter-flash": { label: "반물질 섬광", description: "현실을 찢는 순백 에너지의 폭발" },
75
75
 
76
76
  // ── Magic ──
77
77
  "fireball-spell": { label: "파이어볼 주문", description: "손으로 시전한 휘몰아치는 불의 구체" },
78
78
  "magic-aura": { label: "마법의 오라", description: "인물을 둘러싼 빛나는 에너지 후광" },
79
- "summoning-glyph": { label: "소환 문양", description: "지면에 빛나는 마법 원" },
79
+ "summoning-glyph": { label: "소환 문양", description: "지면에 빛나는 마법진" },
80
80
  "lightning-magic": { label: "번개 마법", description: "시전자의 손에서 호를 그리는 전기 마법" },
81
81
  "ice-shard-burst": { label: "얼음 파편 폭발", description: "바깥으로 흩날리는 결정 파편" },
82
82
  "energy-rune": { label: "에너지 룬", description: "공중에 떠 있는 빛나는 비전 상징" },
83
83
  "portal-magic": { label: "마법 포털", description: "공간에 휘몰아치는 신비한 출입구" },
84
84
  "healing-glow": { label: "치유의 광채", description: "시전자에게서 발산되는 따뜻한 황금빛" },
85
- "dark-vortex": { label: "암흑 소용돌이", description: "불길한 검보라색 소용돌이 공허" },
86
- "light-explosion": { label: "빛의 폭발", description: "순수한 백금색 광채의 폭발" },
85
+ "dark-vortex": { label: "암흑 소용돌이", description: "불길하게 소용돌이치는 검보라색 공허" },
86
+ "light-explosion": { label: "빛의 폭발", description: "순백과 금빛이 어우러진 광채의 폭발" },
87
87
  }
88
88
 
89
89
  export default map