@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
package/src/video-link.ts CHANGED
@@ -113,6 +113,98 @@ export const VIDEO_LINK_TOLERANT_CONSUMER_TYPES: ReadonlySet<string> = new Set([
113
113
  "content-recipe",
114
114
  ])
115
115
 
116
+ /**
117
+ * The tolerant consumers that DO read something fetched from the link — the
118
+ * separately-fetched audio track (`downloadedAudioUrl`): Transcribe and Suno
119
+ * Cover. The rest of the tolerant set (Dubbing, Content Recipe) read only the
120
+ * page link and need nothing fetched. A subset of the tolerant set by
121
+ * construction (guard test).
122
+ */
123
+ export const VIDEO_LINK_AUDIO_CONSUMER_TYPES: ReadonlySet<string> = new Set(["suno-cover", "transcribe"])
124
+
125
+ /**
126
+ * What a run must FETCH for a Video URL node holding a post link:
127
+ * - `file`: some node in the run watches the video — download the video;
128
+ * - `audio`: every reader is tolerant and at least one takes the audio track —
129
+ * fetch the track only, never the video (and never ask for a part of it);
130
+ * - `none`: every reader takes the page link alone — fetch nothing.
131
+ */
132
+ export type VideoLinkNeed = "file" | "audio" | "none"
133
+
134
+ /** The need of a node read by consumers of these types. No consumer reads nothing. */
135
+ export function videoLinkNeedOf(consumerTypes: Iterable<string>): VideoLinkNeed {
136
+ let audio = false
137
+ for (const type of consumerTypes) {
138
+ if (!VIDEO_LINK_TOLERANT_CONSUMER_TYPES.has(type)) return "file"
139
+ if (VIDEO_LINK_AUDIO_CONSUMER_TYPES.has(type)) audio = true
140
+ }
141
+ return audio ? "audio" : "none"
142
+ }
143
+
144
+ /** The node shape the graph readers need — open on purpose, both engines' nodes fit. */
145
+ export interface VideoLinkGraphNode {
146
+ readonly id: string
147
+ readonly type?: string
148
+ readonly data?: unknown
149
+ }
150
+
151
+ export interface VideoLinkGraphEdge {
152
+ readonly source: string
153
+ readonly target: string
154
+ }
155
+
156
+ /**
157
+ * The need of every Video URL node that feeds the run, by node id — ONE reading
158
+ * of the graph for the editor's pre-run gate, the app runner's card and the
159
+ * server's pre-run fetch, so the three cannot disagree on what a run needs.
160
+ *
161
+ * `scopeIds` are the nodes about to run (`null` = every node: an app runs its
162
+ * whole graph). The run is those nodes plus everything they read from, at any
163
+ * depth; a link that feeds nothing in it is absent (a long video parked on the
164
+ * canvas must never block an unrelated run). Skipped nodes are not part of the
165
+ * run and pull nothing in.
166
+ */
167
+ export function videoLinkRunNeeds(
168
+ scopeIds: readonly string[] | null,
169
+ nodes: readonly VideoLinkGraphNode[],
170
+ edges: readonly VideoLinkGraphEdge[],
171
+ ): Map<string, VideoLinkNeed> {
172
+ const byId = new Map(nodes.map((n) => [n.id, n] as const))
173
+ const isSkipped = (id: string) => (byId.get(id)?.data as { skipped?: unknown } | undefined)?.skipped === true
174
+
175
+ const sourcesOf = new Map<string, string[]>()
176
+ for (const edge of edges) {
177
+ const list = sourcesOf.get(edge.target)
178
+ if (list) list.push(edge.source)
179
+ else sourcesOf.set(edge.target, [edge.source])
180
+ }
181
+
182
+ // Everything the run touches: the nodes about to run plus all they read from.
183
+ const inRun = new Set<string>()
184
+ const queue = (scopeIds ?? nodes.map((n) => n.id)).filter((id) => !isSkipped(id))
185
+ for (const id of queue) inRun.add(id)
186
+ while (queue.length > 0) {
187
+ const current = queue.pop()!
188
+ for (const source of sourcesOf.get(current) ?? []) {
189
+ if (inRun.has(source)) continue
190
+ inRun.add(source)
191
+ queue.push(source)
192
+ }
193
+ }
194
+
195
+ const consumers = new Map<string, string[]>()
196
+ for (const edge of edges) {
197
+ if (byId.get(edge.source)?.type !== "youtube-video" || !inRun.has(edge.target)) continue
198
+ const list = consumers.get(edge.source)
199
+ const type = byId.get(edge.target)?.type ?? ""
200
+ if (list) list.push(type)
201
+ else consumers.set(edge.source, [type])
202
+ }
203
+ const needs = new Map<string, VideoLinkNeed>()
204
+ for (const [id, types] of consumers) needs.set(id, videoLinkNeedOf(types))
205
+ return needs
206
+ }
207
+
116
208
  /**
117
209
  * The fields of a Video URL node's data that decide what it emits. Open-ended
118
210
  * on purpose: both engines hand over the node's whole `data` bag, and a closed
@@ -177,3 +269,149 @@ export function videoLinkNeedsDownload(data: VideoLinkNodeFields): boolean {
177
269
  if (!url || !isSocialVideoUrl(url)) return false
178
270
  return videoLinkDownloadedFile(data) === undefined
179
271
  }
272
+
273
+ // ---------------------------------------------------------------------------
274
+ // The link as an APP INPUT (a published app, MCP `run_app`, the SDK)
275
+ // ---------------------------------------------------------------------------
276
+
277
+ /**
278
+ * File extensions accepted as DIRECT video-file links (pathname suffix match).
279
+ * Mirrors save-to-storage's video auto-detect set.
280
+ */
281
+ export const DIRECT_VIDEO_EXTENSIONS = [".mp4", ".webm", ".mov", ".avi"] as const
282
+
283
+ /**
284
+ * True for a DIRECT video-file link: http(s) whose PATHNAME ends in a video
285
+ * extension — `https://cdn.nodaro.ai/uploads/videos/<id>.mp4` and any other
286
+ * cdn-style link. Query and fragment are ignored (signed CDN links keep the
287
+ * extension in the path); an extension that appears only in the query does
288
+ * not qualify. Host-agnostic BY DESIGN, which is exactly why admission is not
289
+ * sufficient on its own: the download route pre-resolves these hosts before it
290
+ * fetches (`resolvesOnlyToPublicAddresses`), and every other reader goes
291
+ * through the SSRF-guarded fetch.
292
+ *
293
+ * A link carrying a backslash or a control character is refused first
294
+ * (`hasUrlParserHazard`): the route pre-resolves the WHATWG host, and the
295
+ * download tool would fetch whatever host ITS parser reads.
296
+ */
297
+ export function isDirectVideoFileUrl(url: string): boolean {
298
+ if (hasUrlParserHazard(url)) return false
299
+ try {
300
+ const parsed = new URL(url)
301
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return false
302
+ const path = parsed.pathname.toLowerCase()
303
+ return DIRECT_VIDEO_EXTENSIONS.some((ext) => path.endsWith(ext))
304
+ } catch {
305
+ return false
306
+ }
307
+ }
308
+
309
+ /**
310
+ * A YouTube video shorter than this downloads whole the moment the link lands;
311
+ * a longer one (or one whose length could not be read) waits for a part to be
312
+ * chosen. The same 4 minutes Recast and Studio use — a two-hour talk nobody
313
+ * asked for never gets fetched by accident. One number for the canvas node, the
314
+ * app runner's card and the server's pre-run fetch.
315
+ */
316
+ export const AUTO_DOWNLOAD_MAX_SEC = 240
317
+
318
+ /** YouTube's quality cap ("up to N rows"). Other hosts have no ladder worth capping. */
319
+ export const YOUTUBE_MAX_HEIGHT = 1080
320
+
321
+ /** The longest link an app input accepts. A real video link is a few hundred characters. */
322
+ export const MAX_VIDEO_LINK_INPUT_CHARS = 2048
323
+
324
+ export type VideoLinkInputProblem = "empty" | "invalid"
325
+
326
+ /**
327
+ * The ONE rule for what a Video URL app input may hold — the canvas node's own
328
+ * (decided 2026-10-08): a link to a supported social host (downloaded before
329
+ * the nodes that need the file run), or any other http(s) link (passed through
330
+ * as it is, never downloaded; the nodes that read it fetch it through the
331
+ * SSRF-guarded fetch). The app runner's card, the run-request lock and MCP
332
+ * `get_app_inputs` all read it, so a link the card accepts is a link the
333
+ * server accepts, and the reverse.
334
+ *
335
+ * Structural only: the server layers its SSRF guard on top (`safeUrlSchema`),
336
+ * and the card refuses a literal local / private host. A link carrying a
337
+ * backslash or a control character is refused (`hasUrlParserHazard`).
338
+ * `null` = fine; leading and trailing spaces are not a problem (the card trims
339
+ * before it sends).
340
+ */
341
+ export function videoLinkInputProblem(value: unknown): VideoLinkInputProblem | null {
342
+ if (value === undefined || value === null) return "empty"
343
+ if (typeof value !== "string") return "invalid"
344
+ const link = value.trim()
345
+ if (link === "") return "empty"
346
+ if (link.length > MAX_VIDEO_LINK_INPUT_CHARS) return "invalid"
347
+ return isSocialVideoUrl(link) || isHttpLink(link) ? null : "invalid"
348
+ }
349
+
350
+ function isHttpLink(link: string): boolean {
351
+ if (hasUrlParserHazard(link)) return false
352
+ try {
353
+ const parsed = new URL(link)
354
+ return (parsed.protocol === "http:" || parsed.protocol === "https:") && parsed.hostname !== ""
355
+ } catch {
356
+ return false
357
+ }
358
+ }
359
+
360
+ /**
361
+ * The fields of a Video URL node's data that belong to ONE link: the file and
362
+ * audio track fetched from it, the progress of that fetch, and what was read
363
+ * from the link (its id, title, picture, length). Every one of them describes
364
+ * the link it was made for.
365
+ *
366
+ * A run-time override that swaps the link (`dropStaleVideoLinkFields`) drops
367
+ * these first, because the creator's published node carries all of them and a
368
+ * shallow merge would leave them standing under the caller's link — the audio
369
+ * track in particular has no binding to its link (`downloadedAudioUrl` is read
370
+ * straight off the node by Transcribe and Suno Cover), so a caller's episode
371
+ * would be transcribed from the creator's sample. The editor's own
372
+ * link-change reset (`CLEARED_DOWNLOAD` in `lib/video-link-ingest.ts`) is
373
+ * guarded to be inside this list.
374
+ */
375
+ export const VIDEO_LINK_DERIVED_FIELDS = [
376
+ "videoId",
377
+ "title",
378
+ "thumbnailUrl",
379
+ "downloadedVideoUrl",
380
+ "downloadedThumbnailUrl",
381
+ "downloadedFromUrl",
382
+ "downloadedSection",
383
+ "downloadStatus",
384
+ "downloadError",
385
+ "downloadErrorCode",
386
+ "downloadId",
387
+ "downloadIdUrl",
388
+ "downloadMode",
389
+ "downloadAllowSilent",
390
+ "downloadPercent",
391
+ "downloadPhase",
392
+ "sectionStartSec",
393
+ "sectionEndSec",
394
+ "needsRangeChoice",
395
+ "videoDurationSec",
396
+ "downloadedAudioUrl",
397
+ "audioDownloadStatus",
398
+ "audioDownloadError",
399
+ ] as const
400
+
401
+ /**
402
+ * The saved Video URL node data without what belonged to its previous link,
403
+ * when `incoming` (the run's override for the node) points it at a different
404
+ * one. A field the override brings itself is kept (the merge applies it after
405
+ * this). Returns the SAME object when the link is not being changed; never
406
+ * mutates.
407
+ */
408
+ export function dropStaleVideoLinkFields(
409
+ data: Record<string, unknown>,
410
+ incoming: Record<string, unknown>,
411
+ ): Record<string, unknown> {
412
+ if (!("youtubeUrl" in incoming)) return data
413
+ if (trimmed(incoming.youtubeUrl) === trimmed(data.youtubeUrl)) return data
414
+ const out: Record<string, unknown> = { ...data }
415
+ for (const key of VIDEO_LINK_DERIVED_FIELDS) delete out[key]
416
+ return out
417
+ }
package/src/voices.ts CHANGED
@@ -24,10 +24,13 @@ export interface Voice {
24
24
  export interface SharedVoice extends Voice {
25
25
  /**
26
26
  * The best of our TTS providers whose underlying ElevenLabs model the
27
- * voice lists in `verified_languages` (v4 preferred when verified, then v3,
28
- * which renders any voice unmodified, then the cheapest v2 model: turbo
29
- * preferred, else multilingual). Only the base model id `eleven_v4` counts
30
- * toward v4; its `eleven_v4_…` variants do not. Models the deployment does
27
+ * voice lists in `verified_languages`, in the order `elevenlabs-v4` (when
28
+ * verified for the base model `eleven_v4`), then `elevenlabs-v3`, which
29
+ * renders any voice unmodified, then `elevenlabs-v4-turbo` (verified for the
30
+ * exact id `eleven_v4_turbo`), then the cheapest v2 model: `elevenlabs-turbo`
31
+ * preferred, else `elevenlabs-multilingual`. Only those two exact ids count
32
+ * in the v4 family; the other `eleven_v4_…` variants (`_hq`, `_exp`, …) are
33
+ * not models of ours and count toward nothing. Models the deployment does
31
34
  * not offer are never recommended.
32
35
  * Clients without a provider picker should send it as the `provider` on
33
36
  * text-to-speech so generation uses a model the voice is actually verified
@@ -38,11 +41,15 @@ export interface SharedVoice extends Voice {
38
41
  recommendedProvider?: TtsProvider
39
42
  /**
40
43
  * Every TTS provider the voice is verified on and the deployment offers
41
- * (subset of `elevenlabs-v4` / `elevenlabs-v3` / `elevenlabs-turbo` /
42
- * `elevenlabs-multilingual`, v4 first when present, then v3, turbo,
43
- * multilingual); absent whenever `recommendedProvider` is. Clients WITH a provider picker should only snap the
44
- * provider when the current choice is NOT in this set — most voices verify
45
- * more than one, and an explicit user choice within the set must win.
44
+ * (a subset of {@link TtsProvider}, in the order `elevenlabs-v4`,
45
+ * `elevenlabs-v3`, `elevenlabs-v4-turbo`, `elevenlabs-turbo`,
46
+ * `elevenlabs-multilingual` — the same order `recommendedProvider` is picked
47
+ * from, so it is always the first entry); absent whenever
48
+ * `recommendedProvider` is. Clients WITH a provider picker should only snap
49
+ * the provider when the current choice is NOT in this set — most voices
50
+ * verify more than one, and an explicit user choice within the set must win.
51
+ * Do not switch over a closed list of members: a speech model added later
52
+ * joins this set the release it ships.
46
53
  */
47
54
  verifiedProviders?: TtsProvider[]
48
55
  }