@nodaro/shared 3.21.0 → 3.23.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 (84) hide show
  1. package/dist/index.cjs +2284 -195
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +1915 -75
  4. package/dist/index.d.ts +1915 -75
  5. package/dist/index.js +2117 -196
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/add-captions-plan.test.ts +33 -0
  9. package/src/__tests__/caption-plan-parse.test.ts +23 -0
  10. package/src/__tests__/caption-segment-schema.test.ts +30 -0
  11. package/src/__tests__/collections.test.ts +253 -0
  12. package/src/__tests__/dialogue-capabilities.test.ts +157 -0
  13. package/src/__tests__/edit-plan-review.test.ts +70 -0
  14. package/src/__tests__/edl-clocks.test.ts +97 -0
  15. package/src/__tests__/edl.test.ts +34 -0
  16. package/src/__tests__/execution-outcome.test.ts +44 -0
  17. package/src/__tests__/fan-out-meta.test.ts +23 -0
  18. package/src/__tests__/fan-out-rows.test.ts +36 -0
  19. package/src/__tests__/fan-out-url-item.test.ts +44 -0
  20. package/src/__tests__/fixtures/speaker-tracks.fixtures.json +622 -0
  21. package/src/__tests__/input-field-extra-keys.test.ts +34 -0
  22. package/src/__tests__/list-consumers-fan-in.test.ts +40 -0
  23. package/src/__tests__/model-tree.test.ts +7 -0
  24. package/src/__tests__/node-pass-through.test.ts +23 -0
  25. package/src/__tests__/node-runtime-keys.test.ts +1 -0
  26. package/src/__tests__/picker-restrictions.test.ts +36 -0
  27. package/src/__tests__/preview-gate.test.ts +305 -0
  28. package/src/__tests__/render-basis.test.ts +176 -0
  29. package/src/__tests__/render-nodes.test.ts +73 -0
  30. package/src/__tests__/render-output.test.ts +392 -0
  31. package/src/__tests__/run-continuation.test.ts +32 -0
  32. package/src/__tests__/speaker-tracks.test.ts +474 -0
  33. package/src/__tests__/speech-pricing.test.ts +69 -0
  34. package/src/__tests__/telegram-channel.test.ts +91 -0
  35. package/src/__tests__/tts-capabilities.test.ts +81 -4
  36. package/src/__tests__/tts-neighbour-text.test.ts +19 -0
  37. package/src/__tests__/ugc-call-body.test.ts +38 -0
  38. package/src/__tests__/ugc-run-state.test.ts +68 -0
  39. package/src/__tests__/video-character-refs.test.ts +213 -0
  40. package/src/__tests__/video-overlay-layer-plan.test.ts +94 -0
  41. package/src/add-captions-plan.ts +50 -0
  42. package/src/caption-plan.ts +45 -0
  43. package/src/caption-segment-schema.ts +82 -0
  44. package/src/collections.ts +462 -0
  45. package/src/competitors.ts +77 -0
  46. package/src/credit-estimators/index.ts +9 -0
  47. package/src/credit-estimators/speech.ts +51 -0
  48. package/src/dialogue-capabilities.ts +48 -0
  49. package/src/edit-plan-contract.ts +20 -9
  50. package/src/edit-plan-review.ts +40 -1
  51. package/src/edl.ts +27 -1
  52. package/src/execution-outcome.ts +41 -0
  53. package/src/fan-out-meta.ts +23 -0
  54. package/src/fan-out-rows.ts +74 -5
  55. package/src/gemini-omni-voices.ts +59 -0
  56. package/src/handle-aliases.ts +295 -0
  57. package/src/i18n/camera-motions.pt-BR.ts +14 -14
  58. package/src/i18n/transitions.pt-BR.ts +13 -13
  59. package/src/index.ts +179 -1
  60. package/src/model-catalog.ts +122 -13
  61. package/src/model-constants.ts +24 -4
  62. package/src/model-tree.ts +5 -1
  63. package/src/node-execution-state.ts +13 -0
  64. package/src/node-mappable-fields.ts +7 -1
  65. package/src/node-pass-through.ts +37 -0
  66. package/src/node-runtime-keys.ts +14 -0
  67. package/src/picker-restrictions.ts +49 -0
  68. package/src/presentation-types.ts +26 -2
  69. package/src/presentation-utils.ts +25 -7
  70. package/src/preview-gate.ts +279 -0
  71. package/src/producer-types.ts +58 -0
  72. package/src/render-final.ts +20 -0
  73. package/src/render-nodes.ts +92 -0
  74. package/src/render-output.ts +565 -0
  75. package/src/run-continuation.ts +39 -0
  76. package/src/speaker-tracks.ts +638 -0
  77. package/src/telegram-channel.ts +140 -0
  78. package/src/transcribe-preflight.ts +8 -4
  79. package/src/tts-capabilities.ts +19 -5
  80. package/src/tts-neighbour-text.ts +46 -0
  81. package/src/ugc-call-body.ts +86 -0
  82. package/src/ugc-run-state.ts +64 -0
  83. package/src/video-character-refs.ts +233 -0
  84. package/src/video-overlay.ts +78 -21
@@ -0,0 +1,97 @@
1
+ import { describe, it, expect } from "vitest"
2
+ // Through the package index: the review inspector's player reads a take's
3
+ // clock through these.
4
+ import { edlDurationMs, edlSegmentOutputStarts, normalizeEdl, outputMsToMasterMs, remapMsThroughEdl, type Edl } from "../index.js"
5
+
6
+ const SRC = { id: "A", url: "https://media.test/a.mp4", kind: "video" as const }
7
+
8
+ function edlOf(spans: ReadonlyArray<readonly [number, number, number?]>): Edl {
9
+ return normalizeEdl({
10
+ version: 1,
11
+ clock: "master",
12
+ sources: [SRC],
13
+ segments: spans.map(([inMs, outMs, crossfade], i) => ({
14
+ id: `s${i}`,
15
+ inMs,
16
+ outMs,
17
+ video: "A",
18
+ ...(crossfade ? { transition: { type: "crossfade", durationMs: crossfade } } : {}),
19
+ })),
20
+ })
21
+ }
22
+
23
+ describe("edlSegmentOutputStarts — each segment's start on the output clock", () => {
24
+ it("is the running sum of the kept durations", () => {
25
+ expect(edlSegmentOutputStarts(edlOf([[0, 1000], [3000, 4500], [9000, 9500]]))).toEqual([0, 1000, 2500])
26
+ })
27
+
28
+ it("pulls a segment back by the crossfade into it", () => {
29
+ const edl = edlOf([[0, 1000], [3000, 4500, 200]])
30
+ expect(edlSegmentOutputStarts(edl)).toEqual([0, 800])
31
+ expect(edlDurationMs(edl)).toBe(2300)
32
+ })
33
+
34
+ it("is empty for an EDL with no segments", () => {
35
+ expect(edlSegmentOutputStarts(edlOf([]))).toEqual([])
36
+ })
37
+ })
38
+
39
+ describe("outputMsToMasterMs — the inverse of remapMsThroughEdl", () => {
40
+ it("maps an output instant back to the master time it plays", () => {
41
+ const edl = edlOf([[0, 1000], [3000, 4500], [9000, 9500]])
42
+ expect(outputMsToMasterMs(edl, 0)).toBe(0)
43
+ expect(outputMsToMasterMs(edl, 999)).toBe(999)
44
+ expect(outputMsToMasterMs(edl, 1000)).toBe(3000)
45
+ expect(outputMsToMasterMs(edl, 2499)).toBe(4499)
46
+ expect(outputMsToMasterMs(edl, 2500)).toBe(9000)
47
+ })
48
+
49
+ it("inside a crossfade, is the incoming segment's time", () => {
50
+ const edl = edlOf([[0, 1000], [3000, 4500, 200]])
51
+ // Output 800..1000 plays the tail of s0 under the head of s1.
52
+ expect(outputMsToMasterMs(edl, 799)).toBe(799)
53
+ expect(outputMsToMasterMs(edl, 800)).toBe(3000)
54
+ expect(outputMsToMasterMs(edl, 950)).toBe(3150)
55
+ })
56
+
57
+ it("is null past the end, before the start, and for a non-finite time", () => {
58
+ const edl = edlOf([[0, 1000], [3000, 4500]])
59
+ expect(outputMsToMasterMs(edl, 2500)).toBeNull()
60
+ expect(outputMsToMasterMs(edl, 99_000)).toBeNull()
61
+ expect(outputMsToMasterMs(edl, -1)).toBeNull()
62
+ expect(outputMsToMasterMs(edl, Number.NaN)).toBeNull()
63
+ expect(outputMsToMasterMs(edlOf([]), 0)).toBeNull()
64
+ })
65
+
66
+ // A Tighten base never revisits master time, so every output instant has
67
+ // exactly one master instant that remaps onto it. (A multicam or clip EDL
68
+ // that re-reads a span has two, and remapMsThroughEdl names the first.)
69
+ it("round-trips every output instant of a monotonic EDL, crossfades included", () => {
70
+ let seed = 7
71
+ const rand = (n: number) => {
72
+ seed = (seed * 1103515245 + 12345) % 2147483648
73
+ return seed % n
74
+ }
75
+ for (let trial = 0; trial < 60; trial++) {
76
+ const spans: Array<[number, number, number?]> = []
77
+ let cursor = rand(500)
78
+ const count = 1 + rand(8)
79
+ for (let i = 0; i < count; i++) {
80
+ const len = 50 + rand(2000)
81
+ const prev = spans.at(-1)
82
+ const prevLen = prev ? prev[1] - prev[0] : 0
83
+ const fade = i > 0 && rand(2) === 0 ? Math.floor(0.9 * Math.min(len, prevLen) * (rand(100) / 100)) : 0
84
+ spans.push([cursor, cursor + len, fade > 0 ? fade : undefined])
85
+ cursor += len + rand(3000)
86
+ }
87
+ const edl = edlOf(spans)
88
+ const total = edlDurationMs(edl)
89
+ for (let t = 0; t < total; t += 1 + rand(37)) {
90
+ const master = outputMsToMasterMs(edl, t)
91
+ expect(master, `trial ${trial} t=${t}`).not.toBeNull()
92
+ expect(remapMsThroughEdl(edl, master as number), `trial ${trial} t=${t}`).toBe(t)
93
+ }
94
+ expect(outputMsToMasterMs(edl, total)).toBeNull()
95
+ }
96
+ })
97
+ })
@@ -20,6 +20,9 @@ import {
20
20
  clampEditPlanClipCount,
21
21
  EDIT_PLAN_DEFAULT_CLIP_COUNT,
22
22
  EDIT_PLAN_MAX_CLIP_COUNT,
23
+ EDIT_PLAN_MODES,
24
+ asEditPlanMode,
25
+ parseEditPlanMode,
23
26
  } from "../edit-plan-contract.js"
24
27
  import { editPlanSourceDurationSec } from "../video-duration.js"
25
28
 
@@ -605,6 +608,37 @@ describe("edit-plan credit-id scheme", () => {
605
608
  it("builds `edit-plan:<mode>:<tier>:<bucket>m`", () => {
606
609
  expect(buildEditPlanCreditId("tighten", "standard", 45 * 60)).toBe("edit-plan:tighten:standard:60m")
607
610
  expect(buildEditPlanCreditId("clips", "premium", undefined)).toBe("edit-plan:clips:premium:180m")
611
+ expect(buildEditPlanCreditId("trailer", "standard", 45 * 60)).toBe("edit-plan:trailer:standard:60m")
612
+ })
613
+ })
614
+
615
+ describe("edit-plan modes — trailer (Track D1)", () => {
616
+ it("trailer is a known mode, after the three Phase-1 modes", () => {
617
+ expect(EDIT_PLAN_MODES).toEqual(["tighten", "clips", "chapters", "trailer"])
618
+ })
619
+
620
+ it("asEditPlanMode keeps every known mode and defaults anything else to tighten", () => {
621
+ for (const m of EDIT_PLAN_MODES) expect(asEditPlanMode(m)).toBe(m)
622
+ expect(asEditPlanMode("teaser")).toBe("tighten")
623
+ expect(asEditPlanMode(undefined)).toBe("tighten")
624
+ })
625
+
626
+ // Round 4 (decided 2026-10-06): the app refuses a mode it does not know
627
+ // instead of planning (and charging) it as tighten. asEditPlanMode is a
628
+ // published function, so its coercion stays; the strict sibling never
629
+ // substitutes a mode.
630
+ it("parseEditPlanMode returns every known mode and undefined for anything else", () => {
631
+ for (const m of EDIT_PLAN_MODES) expect(parseEditPlanMode(m)).toBe(m)
632
+ for (const v of ["teaser", "Tighten", "", " clips", undefined, null, 1, {}, ["clips"]]) {
633
+ expect(parseEditPlanMode(v), JSON.stringify(v)).toBeUndefined()
634
+ }
635
+ })
636
+
637
+ it("a trailer plan is one Edl at top level, unwrapped like tighten", () => {
638
+ const edl = tightenEdl()
639
+ const out = unwrapEditPlanOutput({ ...edl, viaNodaroCloud: true })
640
+ expect(out).toEqual(edl)
641
+ expect(Array.isArray(out)).toBe(false)
608
642
  })
609
643
  })
610
644
 
@@ -0,0 +1,44 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import { countEmptyInputSkips, executionOutcome } from "../execution-outcome.js"
3
+
4
+ /**
5
+ * How a completed run ended, derived on read from its node states — never a
6
+ * column. The rule every surface asks (the editor, the Executions tab, apps,
7
+ * Present, REST / SDK, MCP get_app_run / diagnose_run).
8
+ */
9
+ describe("executionOutcome", () => {
10
+ it("a completed run with a node skipped for want of input is nothing_new", () => {
11
+ const states = {
12
+ feed: { status: "completed", output: { text: "" } },
13
+ llm: { status: "skipped", skipReason: "empty_input" },
14
+ tts: { status: "skipped", skipReason: "empty_input" },
15
+ }
16
+ expect(executionOutcome("completed", states)).toBe("nothing_new")
17
+ expect(countEmptyInputSkips(states)).toBe(2)
18
+ })
19
+
20
+ it("a completed run whose skips are router gates (no reason) succeeded", () => {
21
+ const states = {
22
+ router: { status: "completed", output: { routeOutputs: { a: "x" } } },
23
+ b: { status: "skipped" },
24
+ a: { status: "completed", output: { text: "x" } },
25
+ }
26
+ expect(executionOutcome("completed", states)).toBe("succeeded")
27
+ expect(countEmptyInputSkips(states)).toBe(0)
28
+ })
29
+
30
+ it("a run that has not completed has no outcome — a failed run has a status, not an outcome", () => {
31
+ const states = { llm: { status: "skipped", skipReason: "empty_input" } }
32
+ expect(executionOutcome("running", states)).toBeUndefined()
33
+ expect(executionOutcome("failed", states)).toBeUndefined()
34
+ expect(executionOutcome("cancelled", states)).toBeUndefined()
35
+ expect(executionOutcome(undefined, states)).toBeUndefined()
36
+ })
37
+
38
+ it("tolerates empty, null and malformed states", () => {
39
+ expect(executionOutcome("completed", {})).toBe("succeeded")
40
+ expect(executionOutcome("completed", null)).toBe("succeeded")
41
+ expect(executionOutcome("completed", undefined)).toBe("succeeded")
42
+ expect(countEmptyInputSkips({ odd: null as unknown as { status?: unknown }, other: { skipReason: "empty_input" } })).toBe(0)
43
+ })
44
+ })
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import { FAN_OUT_ALL_OR_NOTHING_TYPES, clipNotesFrom, fanOutItemMeta } from "../index.js"
3
+
4
+ describe("the per-item notes channel (spec §6.4.3)", () => {
5
+ it("reads an iteration's warnings and length, tolerating junk", () => {
6
+ expect(fanOutItemMeta({ clipWarnings: ["clip_lengthened:16"], durationSec: 16 })).toEqual({ warnings: ["clip_lengthened:16"], durationSec: 16 })
7
+ expect(fanOutItemMeta({ clipWarnings: "x", durationSec: "9" })).toEqual({ warnings: [], durationSec: null })
8
+ expect(fanOutItemMeta(undefined)).toEqual({ warnings: [], durationSec: null })
9
+ })
10
+ it("numbers clips from 1 in list order and drops a missing length", () => {
11
+ expect(clipNotesFrom([{ warnings: [], durationSec: 12 }, { warnings: ["frame_check_failed"], durationSec: null }])).toEqual([
12
+ { clip: 1, warnings: [], durationSec: 12 },
13
+ { clip: 2, warnings: ["frame_check_failed"] },
14
+ ])
15
+ })
16
+ it("a single (non-fan-out) output yields one notes row", () => {
17
+ expect(clipNotesFrom(undefined, { warnings: ["clip_lengthened:16"], durationSec: 16 })).toEqual([{ clip: 1, warnings: ["clip_lengthened:16"], durationSec: 16 }])
18
+ expect(clipNotesFrom(undefined)).toEqual([])
19
+ })
20
+ it("only UGC Clip is all-or-nothing", () => {
21
+ expect([...FAN_OUT_ALL_OR_NOTHING_TYPES]).toEqual(["ugc-clip"])
22
+ })
23
+ })
@@ -7,6 +7,7 @@ import {
7
7
  planFanOut,
8
8
  alignedFieldList,
9
9
  liveRowColumn,
10
+ pickHeldRow,
10
11
  type FanOutCandidate,
11
12
  } from "../fan-out-rows.js"
12
13
  import { REPEAT_PLACEHOLDER, encodeProviderItem } from "../repeat-types.js"
@@ -206,3 +207,38 @@ describe("alignedFieldList", () => {
206
207
  expect(alignedFieldList([{ a: 1 }, { b: 2 }], "missing")).toBeUndefined()
207
208
  })
208
209
  })
210
+
211
+ describe("pickHeldRow — one value off a list with holes, outside its fan-out", () => {
212
+ // An Edit Plan's clips as a person's review leaves them: the PLAN's rows,
213
+ // "" at every dropped clip. Clips 1 and 4 are kept.
214
+ const rows = ["c1", "", "", "c4"]
215
+
216
+ it("a selector that leaves one kept clip reads that clip, never the plan's first kept one", () => {
217
+ expect(pickHeldRow(rows, { selectorMode: "list", listExpression: "2,4" }, false)).toEqual({ kind: "value", value: "c4" })
218
+ expect(pickHeldRow(rows, { outputMode: "each", rangeFrom: "3", rangeTo: "last" }, false)).toEqual({ kind: "value", value: "c4" })
219
+ })
220
+
221
+ it("a selector that leaves no kept clip reads nothing", () => {
222
+ expect(pickHeldRow(rows, { selectorMode: "list", listExpression: "2,3" }, false)).toEqual({ kind: "none" })
223
+ })
224
+
225
+ it("a selector that leaves several reads the first kept clip OF THE SELECTION", () => {
226
+ expect(pickHeldRow(["", "c2", "c3", "c4"], { selectorMode: "list", listExpression: "4,3" }, false)).toEqual({ kind: "value", value: "c4" })
227
+ })
228
+
229
+ it("an item pick on a dropped clip reads nothing; on a kept clip, that clip", () => {
230
+ expect(pickHeldRow(rows, { outputMode: "item", itemIndex: "2" }, false)).toEqual({ kind: "none" })
231
+ expect(pickHeldRow(rows, { outputMode: "item", itemIndex: "last" }, false)).toEqual({ kind: "value", value: "c4" })
232
+ expect(pickHeldRow(rows, { outputMode: "item:1" }, false)).toEqual({ kind: "none" })
233
+ expect(pickHeldRow(rows, { outputMode: "item:0" }, true)).toEqual({ kind: "value", value: "c1" })
234
+ })
235
+
236
+ it("leaves every other read alone: a default each edge, Selected, Bundle, and an each edge inside its fan-out", () => {
237
+ expect(pickHeldRow(rows, undefined, false)).toEqual({ kind: "unaffected" })
238
+ expect(pickHeldRow(rows, { outputMode: "each" }, false)).toEqual({ kind: "unaffected" })
239
+ expect(pickHeldRow(rows, { outputMode: "last", selectorMode: "list", listExpression: "2" }, false)).toEqual({ kind: "unaffected" })
240
+ expect(pickHeldRow(rows, { outputMode: "all", selectorMode: "list", listExpression: "2" }, false)).toEqual({ kind: "unaffected" })
241
+ expect(pickHeldRow(rows, { selectorMode: "list", listExpression: "2,4" }, true)).toEqual({ kind: "unaffected" })
242
+ expect(pickHeldRow([], { outputMode: "item", itemIndex: "2" }, false)).toEqual({ kind: "unaffected" })
243
+ })
244
+ })
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The one guess both engines make about a fan-out item — media link or text —
3
+ * and the lanes where a link stays the item.
4
+ */
5
+ import { describe, expect, it } from "vitest"
6
+ import { fanOutUrlItemIsText, isFanOutUrlItem, resolveListFanOut, type FanOutCandidate } from "../fan-out-rows.js"
7
+
8
+ describe("isFanOutUrlItem", () => {
9
+ it("one address is a media link, with or without a query string", () => {
10
+ expect(isFanOutUrlItem("https://cdn.example.test/a.jpg")).toBe(true)
11
+ expect(isFanOutUrlItem("https://cdn.example.test/a.jpg?token=1")).toBe(true)
12
+ expect(isFanOutUrlItem(" https://news.example.test/story-7 ")).toBe(true)
13
+ expect(isFanOutUrlItem("clip.mp4")).toBe(true)
14
+ })
15
+
16
+ it("JSON and sentences are text, however many addresses they carry — a scraped post is not a picture", () => {
17
+ expect(isFanOutUrlItem('{"title":"a post","imageUrl":"https://cdn.example.test/a.jpg?token=1"}')).toBe(false)
18
+ expect(isFanOutUrlItem('[{"url":"https://cdn.example.test/a.jpg?x"}]')).toBe(false)
19
+ expect(isFanOutUrlItem("Read https://news.example.test/story-7 today")).toBe(false)
20
+ expect(isFanOutUrlItem("https://cdn.example.test/a.jpg the caption")).toBe(false)
21
+ expect(isFanOutUrlItem("")).toBe(false)
22
+ expect(isFanOutUrlItem("plain text")).toBe(false)
23
+ })
24
+ })
25
+
26
+ describe("fanOutUrlItemIsText — lanes where a link IS the item", () => {
27
+ it("Save to Collection's `in` keeps a link as the record's link; every other lane keeps the media guess", () => {
28
+ expect(fanOutUrlItemIsText("collection-write", "in")).toBe(true)
29
+ expect(fanOutUrlItemIsText("collection-write", "image")).toBe(false)
30
+ expect(fanOutUrlItemIsText("generate-image", "prompt")).toBe(false)
31
+ expect(fanOutUrlItemIsText(undefined, "in")).toBe(false)
32
+ })
33
+
34
+ it("a list of links wired into Save to Collection's `in` DRIVES the fan-out as items (it is a text list there)", () => {
35
+ const links: FanOutCandidate = { targetHandle: "in", aligned: ["https://news.example.test/1", "https://news.example.test/2"] }
36
+ const plan = resolveListFanOut([links], "collection-write")
37
+ expect(plan?.items).toEqual(["https://news.example.test/1", "https://news.example.test/2"])
38
+ expect(plan?.targetHandle).toBe("in")
39
+ // The same list into a prompt lane is a media list: it never supplies the items as prompts.
40
+ const intoPrompt: FanOutCandidate = { targetHandle: "prompt", aligned: links.aligned }
41
+ const text: FanOutCandidate = { targetHandle: "negative", aligned: ["a", "b"] }
42
+ expect(resolveListFanOut([intoPrompt, text], "generate-image")?.targetHandle).toBe("prompt")
43
+ })
44
+ })