@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodaro/shared",
3
- "version": "3.21.0",
3
+ "version": "3.23.0",
4
4
  "description": "Shared types, model catalog, wire contracts, and structural vocabularies for the Nodaro platform and SDK.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -0,0 +1,33 @@
1
+ import { describe, expect, it, vi } from "vitest"
2
+ import { captionPlanBodyLevers, styleCaptionPlan } from "../add-captions-plan.js"
3
+
4
+ const plan = { v: 1, hookText: "Sample hook", hookEndMs: 1400, bodyEndMs: 5300, captions: [{ text: "one", startMs: 1500, endMs: 1800 }] }
5
+ const leverKeys = ["style", "look", "position", "positionY", "fontSize", "fontWeight", "maxWordsPerLine", "color", "backgroundColor", "highlightColor", "fontFamily", "uppercase", "strokeColor", "strokeWidth", "animate"]
6
+ const plate = { startMs: 0, endMs: 1400, text: "Sample hook", style: "subtitle", look: "clean", positionY: 20 }
7
+ const body = { startMs: 1400, endMs: 5300, captions: plan.captions, style: "word-highlight", look: "outline" }
8
+
9
+ describe("styleCaptionPlan — one composition for both engines (spec §6.2)", () => {
10
+ it("passes the node's set levers as bodyLevers, and none when the node sets none", () => {
11
+ expect(captionPlanBodyLevers({ label: "Captions", style: "karaoke", color: null, fontSize: undefined, autoTranscribe: true }, leverKeys)).toEqual({ style: "karaoke" })
12
+ expect(captionPlanBodyLevers({ label: "Captions", autoTranscribe: true }, leverKeys)).toBeUndefined()
13
+ const segmentsFor = vi.fn(() => ({ segments: [plate, body], dropped: [] }))
14
+ styleCaptionPlan(plan, { label: "Captions" }, { segmentsFor, leverKeys })
15
+ expect(segmentsFor).toHaveBeenCalledWith(plan, undefined)
16
+ styleCaptionPlan(plan, { style: "karaoke" }, { segmentsFor, leverKeys })
17
+ expect(segmentsFor).toHaveBeenLastCalledWith(plan, { bodyLevers: { style: "karaoke" } })
18
+ })
19
+ it("returns the helper's segments, or the parser's error", () => {
20
+ const styler = { segmentsFor: () => ({ segments: [plate, body], dropped: [] }), leverKeys }
21
+ expect(styleCaptionPlan(JSON.stringify(plan), {}, styler)).toEqual({ segments: [plate, body] })
22
+ expect(styleCaptionPlan({ ...plan, v: 3 }, {}, styler)).toEqual({ error: "Caption plan: v must be 1." })
23
+ })
24
+ it("refuses overlapping or schema-invalid segments before anything is reserved", () => {
25
+ const overlap = { segmentsFor: () => ({ segments: [plate, { ...body, startMs: 900 }], dropped: [] }), leverKeys }
26
+ expect(styleCaptionPlan(plan, {}, overlap)).toEqual({ error: "Caption plan: segments overlap: [0, 1400) and [900, 5300)." })
27
+ const inverted = { segmentsFor: () => ({ segments: [{ ...plate, endMs: 0 }], dropped: [] }), leverKeys }
28
+ expect(styleCaptionPlan(plan, {}, inverted)).toEqual({ error: "Caption plan: segment 1: segment endMs must be greater than startMs." })
29
+ })
30
+ it("an empty result is an empty list, never an error (the node passes the video through)", () => {
31
+ expect(styleCaptionPlan(plan, {}, { segmentsFor: () => ({ segments: [], dropped: ["hook", "body"] }), leverKeys })).toEqual({ segments: [] })
32
+ })
33
+ })
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import { parseCaptionPlan } from "../caption-plan.js"
3
+
4
+ const plan = { v: 1, hookText: "Sample hook", hookEndMs: 1400, bodyEndMs: 5300, captions: [{ text: "one", startMs: 1500, endMs: 1800 }] }
5
+
6
+ describe("parseCaptionPlan", () => {
7
+ it("accepts the object and its JSON string", () => {
8
+ expect(parseCaptionPlan(plan)).toEqual({ plan })
9
+ expect(parseCaptionPlan(JSON.stringify({ ...plan, videoDurationMs: 6000, language: "he" }))).toEqual({ plan: { ...plan, videoDurationMs: 6000, language: "he" } })
10
+ })
11
+ it("names the bad field", () => {
12
+ expect(parseCaptionPlan({ ...plan, v: 2 })).toEqual({ error: "Caption plan: v must be 1." })
13
+ expect(parseCaptionPlan({ ...plan, hookEndMs: -1 })).toEqual({ error: "Caption plan: hookEndMs must be a non-negative number." })
14
+ expect(parseCaptionPlan({ ...plan, bodyEndMs: Number.POSITIVE_INFINITY })).toEqual({ error: "Caption plan: bodyEndMs must be a non-negative number." })
15
+ expect(parseCaptionPlan({ ...plan, captions: [{ text: "x", startMs: 9, endMs: 3 }] })).toEqual({ error: "Caption plan: captions[0] ends before it starts." })
16
+ expect(parseCaptionPlan({ ...plan, captions: "nope" })).toEqual({ error: "Caption plan: captions must be a list." })
17
+ expect(parseCaptionPlan("{not json")).toEqual({ error: "Caption plan: not valid JSON." })
18
+ expect(parseCaptionPlan(null)).toEqual({ error: "Caption plan: not an object." })
19
+ })
20
+ it("never copies an unknown key onto the plan", () => {
21
+ expect(parseCaptionPlan({ ...plan, style: "karaoke" })).toEqual({ plan })
22
+ })
23
+ })
@@ -0,0 +1,30 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import {
3
+ CAPTION_SEGMENT_SCHEMA_KEYS,
4
+ captionFontWeightSchema,
5
+ captionSegmentInputSchema,
6
+ findSegmentOverlap,
7
+ } from "../caption-segment-schema.js"
8
+
9
+ describe("the add-captions segment schema, shared by the route and both engines", () => {
10
+ it("accepts a timed segment with its own text and levers", () => {
11
+ const r = captionSegmentInputSchema.safeParse({ startMs: 0, endMs: 1200, text: "Sample line", style: "subtitle", look: "clean", positionY: 20, fontWeight: 800 })
12
+ expect(r.success).toBe(true)
13
+ })
14
+ it("refuses an end at or before the start, blank text and a weight off the 100 grid", () => {
15
+ expect(captionSegmentInputSchema.safeParse({ startMs: 500, endMs: 500 }).success).toBe(false)
16
+ expect(captionSegmentInputSchema.safeParse({ startMs: 0, endMs: 10, text: " " }).success).toBe(false)
17
+ expect(captionFontWeightSchema.safeParse(850).success).toBe(false)
18
+ })
19
+ it("names exactly the route's segment fields", () => {
20
+ expect([...CAPTION_SEGMENT_SCHEMA_KEYS].sort()).toEqual([
21
+ "animate", "backgroundColor", "captions", "color", "endMs", "fontFamily", "fontSize", "fontWeight",
22
+ "highlightColor", "look", "maxWordsPerLine", "position", "positionY", "startMs", "strokeColor",
23
+ "strokeWidth", "style", "text", "uppercase",
24
+ ])
25
+ })
26
+ it("finds an overlap and lets abutting segments pass", () => {
27
+ expect(findSegmentOverlap([{ startMs: 0, endMs: 1000 }, { startMs: 1000, endMs: 2000 }])).toBeNull()
28
+ expect(findSegmentOverlap([{ startMs: 900, endMs: 2000 }, { startMs: 0, endMs: 1000 }])).toBe("segments overlap: [0, 1000) and [900, 2000)")
29
+ })
30
+ })
@@ -0,0 +1,253 @@
1
+ import { describe, it, expect } from "vitest"
2
+ import {
3
+ clampChars,
4
+ COLLECTION_RECORD_FIELDS_BYTES_MAX,
5
+ COLLECTION_RECORD_FIELDS_MAX,
6
+ COLLECTION_RECORD_MEDIA_MAX,
7
+ COLLECTION_TIER_CAPS,
8
+ collectionCapsForTier,
9
+ collectionRecordHeadline,
10
+ collectionRecordsDigest,
11
+ ingestRecordFromJson,
12
+ isCollectionMedia,
13
+ normalizeCollectionFields,
14
+ normalizeCollectionMedia,
15
+ normalizeDedupeKey,
16
+ type CollectionRecord,
17
+ } from "../collections.js"
18
+
19
+ function record(overrides: Partial<CollectionRecord> = {}): CollectionRecord {
20
+ return {
21
+ id: "r1",
22
+ collectionId: "c1",
23
+ title: "Telegram turns ten",
24
+ text: "The messenger marks a decade.\nSecond paragraph.",
25
+ url: "https://t.me/telegram/441",
26
+ media: [],
27
+ fields: {},
28
+ dedupeKey: "https://t.me/telegram/441",
29
+ source: {},
30
+ createdAt: "2026-10-06T08:00:00.000Z",
31
+ ...overrides,
32
+ }
33
+ }
34
+
35
+ describe("collection caps by tier", () => {
36
+ it("payg is a derived tier whose caps are basic's; enterprise reads as business", () => {
37
+ expect(COLLECTION_TIER_CAPS.payg).toEqual(COLLECTION_TIER_CAPS.basic)
38
+ expect(COLLECTION_TIER_CAPS.enterprise).toEqual(COLLECTION_TIER_CAPS.business)
39
+ })
40
+
41
+ it("the ladder Asaf decided (2026-10-05)", () => {
42
+ expect(COLLECTION_TIER_CAPS.free).toEqual({ collections: 3, records: 500 })
43
+ expect(COLLECTION_TIER_CAPS.basic).toEqual({ collections: 10, records: 5_000 })
44
+ expect(COLLECTION_TIER_CAPS.standard).toEqual({ collections: 30, records: 20_000 })
45
+ expect(COLLECTION_TIER_CAPS.pro).toEqual({ collections: 100, records: 100_000 })
46
+ expect(COLLECTION_TIER_CAPS.business).toEqual({ collections: 300, records: 250_000 })
47
+ })
48
+
49
+ it("every paid tier holds at least as much as the one below it", () => {
50
+ const ladder = ["free", "basic", "standard", "pro", "business"].map((t) => COLLECTION_TIER_CAPS[t]!)
51
+ for (let i = 1; i < ladder.length; i++) {
52
+ expect(ladder[i]!.collections).toBeGreaterThanOrEqual(ladder[i - 1]!.collections)
53
+ expect(ladder[i]!.records).toBeGreaterThanOrEqual(ladder[i - 1]!.records)
54
+ }
55
+ })
56
+
57
+ it("an unknown, empty or missing tier has NO caps here (the API then holds it to none, never to free's)", () => {
58
+ expect(collectionCapsForTier("gold")).toBeUndefined()
59
+ expect(collectionCapsForTier("")).toBeUndefined()
60
+ expect(collectionCapsForTier(null)).toBeUndefined()
61
+ expect(collectionCapsForTier(undefined)).toBeUndefined()
62
+ expect(collectionCapsForTier("pro")).toEqual(COLLECTION_TIER_CAPS.pro)
63
+ expect(collectionCapsForTier("free")).toEqual(COLLECTION_TIER_CAPS.free)
64
+ })
65
+ })
66
+
67
+ describe("clampChars", () => {
68
+ it("counts characters as Postgres does and never splits a surrogate pair", () => {
69
+ expect(clampChars("abc", 5)).toBe("abc")
70
+ expect(clampChars("abcdef", 3)).toBe("abc")
71
+ expect(clampChars("😀😀😀", 2)).toBe("😀😀")
72
+ expect(clampChars("😀😀😀", 3)).toBe("😀😀😀")
73
+ expect(Array.from(clampChars("a😀".repeat(10), 7))).toHaveLength(7)
74
+ })
75
+ })
76
+
77
+ describe("normalizeDedupeKey", () => {
78
+ it("trims, collapses spaces, lower-cases (a link: only its scheme and host) and caps the length", () => {
79
+ expect(normalizeDedupeKey(" Https://T.me/Telegram/441 ")).toBe("https://t.me/Telegram/441")
80
+ expect(normalizeDedupeKey("a b\n\tc")).toBe("a b c")
81
+ expect(normalizeDedupeKey("x".repeat(400))!.length).toBe(300)
82
+ })
83
+
84
+ it("reads a number as its text and nothing else as a key", () => {
85
+ expect(normalizeDedupeKey(441)).toBe("441")
86
+ expect(normalizeDedupeKey(" ")).toBeNull()
87
+ expect(normalizeDedupeKey(undefined)).toBeNull()
88
+ expect(normalizeDedupeKey({ id: 1 })).toBeNull()
89
+ expect(normalizeDedupeKey(Number.NaN)).toBeNull()
90
+ })
91
+ })
92
+
93
+ describe("media and fields as stored", () => {
94
+ it("keeps known kinds with http(s) links, drops repeats and anything else, at most 20", () => {
95
+ expect(isCollectionMedia({ type: "image", url: "https://cdn.example.com/a.jpg" })).toBe(true)
96
+ expect(isCollectionMedia({ type: "image", url: "javascript:alert(1)" })).toBe(false)
97
+ expect(isCollectionMedia({ type: "hologram", url: "https://cdn.example.com/a.jpg" })).toBe(false)
98
+ expect(isCollectionMedia({ type: "video", url: "https://cdn.example.com/v.mp4", posterUrl: "data:x" })).toBe(false)
99
+ expect(isCollectionMedia({ type: "image", url: "https://cdn.example.com/a.jpg", posterUrl: null })).toBe(true)
100
+ expect(normalizeCollectionMedia([{ type: "image", url: "https://cdn.example.com/a.jpg", posterUrl: null }])).toEqual([{ type: "image", url: "https://cdn.example.com/a.jpg" }])
101
+ const many = Array.from({ length: 25 }, (_, i) => ({ type: "image", url: `https://cdn.example.com/${i}.jpg` }))
102
+ expect(normalizeCollectionMedia([...many, many[0], { type: "nope" }, "x"]).length).toBe(COLLECTION_RECORD_MEDIA_MAX)
103
+ expect(normalizeCollectionMedia("not a list")).toEqual([])
104
+ })
105
+
106
+ it("keeps scalar fields only, bounded by count and bytes", () => {
107
+ const fields = normalizeCollectionFields({ a: "1", b: 2, c: true, d: null, e: { nested: 1 }, f: [1], "": "empty key" })
108
+ expect(fields).toEqual({ a: "1", b: 2, c: true })
109
+ const tooMany = Object.fromEntries(Array.from({ length: 80 }, (_, i) => [`k${i}`, i]))
110
+ expect(Object.keys(normalizeCollectionFields(tooMany)).length).toBe(COLLECTION_RECORD_FIELDS_MAX)
111
+ const big = normalizeCollectionFields({ one: "x".repeat(COLLECTION_RECORD_FIELDS_BYTES_MAX), two: "fits?" })
112
+ expect(big).toEqual({})
113
+ expect(normalizeCollectionFields("nope")).toEqual({})
114
+ })
115
+ })
116
+
117
+ describe("headline and digest", () => {
118
+ it("the headline is the title, else the first non-empty line of the text, else the link", () => {
119
+ expect(collectionRecordHeadline(record())).toBe("Telegram turns ten")
120
+ expect(collectionRecordHeadline(record({ title: " " }))).toBe("The messenger marks a decade.")
121
+ expect(collectionRecordHeadline(record({ title: "", text: "\n\n \n" }))).toBe("https://t.me/telegram/441")
122
+ expect(collectionRecordHeadline(record({ title: "", text: "", url: null }))).toBe("")
123
+ const long = collectionRecordHeadline(record({ title: "", text: "w".repeat(300) }))
124
+ expect(long.length).toBe(120)
125
+ expect(long.endsWith("…")).toBe(true)
126
+ })
127
+
128
+ it("headlines: one line per record with the date and the link", () => {
129
+ const digest = collectionRecordsDigest([record(), record({ id: "r2", title: "No link", url: null, createdAt: "2026-10-05T20:00:00Z" })])
130
+ expect(digest).toBe(["- Telegram turns ten · 2026-10-06 · https://t.me/telegram/441", "- No link · 2026-10-05"].join("\n"))
131
+ })
132
+
133
+ it("full: the text under its headline, records separated by a rule; a record with nothing adds nothing", () => {
134
+ const digest = collectionRecordsDigest(
135
+ [record(), record({ id: "r2", title: "", text: "Only a line", url: null }), record({ id: "r3", title: "", text: "", url: null })],
136
+ "full",
137
+ )
138
+ expect(digest).toBe(
139
+ [
140
+ "### Telegram turns ten\nThe messenger marks a decade.\nSecond paragraph.\nhttps://t.me/telegram/441",
141
+ "### Only a line",
142
+ ].join("\n\n---\n\n"),
143
+ )
144
+ })
145
+ })
146
+
147
+ describe("ingestRecordFromJson", () => {
148
+ const telegramPost = {
149
+ id: 441,
150
+ channel: "telegram",
151
+ postUrl: "https://t.me/telegram/441",
152
+ text: "Telegram turns ten.\nA decade of messaging.",
153
+ date: "2026-10-06T08:00:00.000Z",
154
+ forwardedFrom: { name: "Durov's Channel", url: "https://t.me/durov" },
155
+ media: [
156
+ { type: "photo", url: "https://cdn4.telesco.pe/file/a.jpg?token=1" },
157
+ { type: "video", posterUrl: "https://cdn4.telesco.pe/file/poster.jpg" },
158
+ { type: "video", url: "https://cdn4.telesco.pe/file/v.mp4", posterUrl: "https://cdn4.telesco.pe/file/p2.jpg" },
159
+ ],
160
+ imageUrl: "https://cdn4.telesco.pe/file/a.jpg?token=1",
161
+ views: "1.52M",
162
+ }
163
+
164
+ it("reads a Telegram post: link, text, every medium, the forwarded-from name and the scalars as fields", () => {
165
+ const r = ingestRecordFromJson(telegramPost)
166
+ expect(r.title).toBe("")
167
+ expect(r.text).toBe("Telegram turns ten.\nA decade of messaging.")
168
+ expect(r.url).toBe("https://t.me/telegram/441")
169
+ expect(r.dedupeKey).toBe("https://t.me/telegram/441")
170
+ expect(r.media).toEqual([
171
+ { type: "image", url: "https://cdn4.telesco.pe/file/a.jpg?token=1" },
172
+ { type: "image", url: "https://cdn4.telesco.pe/file/poster.jpg" },
173
+ { type: "video", url: "https://cdn4.telesco.pe/file/v.mp4", posterUrl: "https://cdn4.telesco.pe/file/p2.jpg" },
174
+ ])
175
+ expect(r.fields).toEqual({ id: 441, channel: "telegram", date: "2026-10-06T08:00:00.000Z", forwardedFrom: "Durov's Channel", views: "1.52M" })
176
+ expect(collectionRecordHeadline({ ...r, url: r.url })).toBe("Telegram turns ten.")
177
+ })
178
+
179
+ it("reads a Social Search post: title, the object-shaped media, the author's name", () => {
180
+ const r = ingestRecordFromJson({
181
+ id: "tiktok:7300000000000000001",
182
+ platform: "tiktok",
183
+ url: "https://www.tiktok.com/@maker/video/7300000000000000001",
184
+ title: "Three ways to fold a shirt",
185
+ text: "Long story",
186
+ author: { handle: "maker", name: "Maker" },
187
+ metrics: { views: 1200 },
188
+ media: { kind: "video", thumbnailUrl: "https://cdn.example.com/still.jpg", videoUrl: "https://cdn.example.com/v.mp4" },
189
+ hashtags: ["laundry"],
190
+ })
191
+ expect(r.title).toBe("Three ways to fold a shirt")
192
+ expect(r.text).toBe("Long story")
193
+ expect(r.url).toBe("https://www.tiktok.com/@maker/video/7300000000000000001")
194
+ expect(r.media).toEqual([{ type: "video", url: "https://cdn.example.com/v.mp4", posterUrl: "https://cdn.example.com/still.jpg" }])
195
+ expect(r.fields).toEqual({ id: "tiktok:7300000000000000001", platform: "tiktok", author: "Maker" })
196
+ expect(r.dedupeKey).toBe("https://www.tiktok.com/@maker/video/7300000000000000001")
197
+ })
198
+
199
+ it("reads an LLM's article object: headline / dek / body, the slug as the dedupe key when there is no link", () => {
200
+ const r = ingestRecordFromJson({ headline: "Markets rally", dek: "A short deck.", slug: "Markets-Rally", confidence: 0.9, topic: "business" })
201
+ expect(r.title).toBe("Markets rally")
202
+ expect(r.text).toBe("A short deck.")
203
+ expect(r.url).toBeNull()
204
+ expect(r.dedupeKey).toBe("markets-rally")
205
+ expect(r.fields).toEqual({ slug: "Markets-Rally", confidence: 0.9, topic: "business" })
206
+ })
207
+
208
+ it("a link that is not http(s) is not a link; a NUMERIC id is no key (each run numbers its items from 1), a named id is", () => {
209
+ const r = ingestRecordFromJson({ url: "javascript:alert(1)", id: 7, text: "x" })
210
+ expect(r.url).toBeNull()
211
+ expect(r.dedupeKey).toBeNull()
212
+ expect(r.fields).toEqual({ id: 7 })
213
+ expect(ingestRecordFromJson({ id: "12", text: "x" }).dedupeKey).toBeNull()
214
+ expect(ingestRecordFromJson({ id: "post-12", text: "x" }).dedupeKey).toBe("post-12")
215
+ // slug, then postId, then externalId, then a named id.
216
+ expect(ingestRecordFromJson({ id: "named", externalId: "ext", postId: 44, slug: "The-Slug", text: "x" }).dedupeKey).toBe("the-slug")
217
+ expect(ingestRecordFromJson({ id: "named", externalId: "ext", postId: 44, text: "x" }).dedupeKey).toBe("44")
218
+ })
219
+
220
+ it("a link keeps its path's case as a key — only the scheme and host fold", () => {
221
+ expect(normalizeDedupeKey("https://Bit.LY/AbC")).toBe("https://bit.ly/AbC")
222
+ expect(normalizeDedupeKey(" https://T.me/Telegram/441 ")).toBe("https://t.me/Telegram/441")
223
+ expect(normalizeDedupeKey("Story Seven")).toBe("story seven")
224
+ })
225
+
226
+ it("the first link key whose value IS a link wins over an earlier key that is not", () => {
227
+ const r = ingestRecordFromJson({ url: "t.me/x/1", postUrl: "https://t.me/x/1", text: "x" })
228
+ expect(r.url).toBe("https://t.me/x/1")
229
+ expect(r.dedupeKey).toBe("https://t.me/x/1")
230
+ })
231
+
232
+ it("reads a huge media list in one pass and keeps the first twenty distinct links", () => {
233
+ const media = Array.from({ length: 30_000 }, (_, i) => ({ type: "photo", url: `https://cdn.example.com/${i % 25}.jpg` }))
234
+ const started = Date.now()
235
+ const r = ingestRecordFromJson({ text: "x", media })
236
+ expect(Date.now() - started).toBeLessThan(500)
237
+ expect(r.media).toHaveLength(20)
238
+ expect(r.media[0]).toEqual({ type: "image", url: "https://cdn.example.com/0.jpg" })
239
+ })
240
+
241
+ it("a long text is cut to whole characters, never through a surrogate pair", () => {
242
+ const r = ingestRecordFromJson({ text: "😀".repeat(20_500) })
243
+ expect(Array.from(r.text)).toHaveLength(20_000)
244
+ })
245
+
246
+ it("a string or a scalar becomes the text; nothing becomes nothing", () => {
247
+ expect(ingestRecordFromJson("Just a line")).toEqual({ title: "", text: "Just a line", url: null, media: [], fields: {}, dedupeKey: null })
248
+ expect(ingestRecordFromJson(42).text).toBe("42")
249
+ expect(ingestRecordFromJson(null).text).toBe("")
250
+ expect(ingestRecordFromJson(undefined).text).toBe("")
251
+ expect(ingestRecordFromJson([1, 2]).text).toBe("[1,2]")
252
+ })
253
+ })
@@ -0,0 +1,157 @@
1
+ import { describe, it, expect } from "vitest"
2
+ import { MODEL_CATALOG, SPEECH_UNIT_PRICE_NOTE } from "../model-catalog.js"
3
+ import { DIALOGUE_PROVIDERS, DEFAULT_DIALOGUE_PROVIDER, TTS_PROVIDERS, getMaxTtsChars } from "../model-constants.js"
4
+ import {
5
+ findDialogueCapabilities,
6
+ getDialogueCapabilities,
7
+ dialogueProviderOf,
8
+ dialogueHasLever,
9
+ dialogueStabilityAccepted,
10
+ dialogueSupportsTimestamps,
11
+ } from "../dialogue-capabilities.js"
12
+ import { findTtsCapabilities } from "../tts-capabilities.js"
13
+
14
+ const V3_DIALOGUE_SHEET = MODEL_CATALOG["elevenlabs-dialogue"]!.tts!
15
+
16
+ describe("dialogue lane — totality", () => {
17
+ it("DIALOGUE_PROVIDERS is exactly the catalog's dialogue-mode models", () => {
18
+ const fromCatalog = Object.values(MODEL_CATALOG).filter((m) => m.modes.includes("dialogue")).map((m) => m.id).sort()
19
+ expect([...DIALOGUE_PROVIDERS].sort()).toEqual(fromCatalog)
20
+ })
21
+
22
+ it("every dialogue model has a sheet, a price row under its own id, and a Models-tab series", () => {
23
+ for (const id of DIALOGUE_PROVIDERS) {
24
+ const entry = MODEL_CATALOG[id]!
25
+ expect(entry.tts, `${id} sheet`).toBeDefined()
26
+ expect(entry.pricing[0]?.identifier, `${id} price identifier`).toBe(id)
27
+ expect(entry.series, `${id} series`).toBe("ElevenLabs")
28
+ }
29
+ })
30
+
31
+ it("the default is v3's dialogue model", () => {
32
+ expect(DEFAULT_DIALOGUE_PROVIDER).toBe("elevenlabs-dialogue")
33
+ expect(DIALOGUE_PROVIDERS).toContain(DEFAULT_DIALOGUE_PROVIDER)
34
+ })
35
+
36
+ it("no id is both a text-to-speech provider and a dialogue provider", () => {
37
+ for (const id of DIALOGUE_PROVIDERS) expect(TTS_PROVIDERS as readonly string[], id).not.toContain(id)
38
+ })
39
+
40
+ it("stabilitySteps, when declared, are unique, ascending values within 0..1 — and no text-to-speech model declares any", () => {
41
+ for (const m of Object.values(MODEL_CATALOG)) {
42
+ const steps = m.tts?.stabilitySteps
43
+ if (!steps) continue
44
+ expect(m.modes, `${m.id}: only a dialogue model may restrict stability to steps`).toContain("dialogue")
45
+ expect(steps.length, `${m.id} steps`).toBeGreaterThan(1)
46
+ expect([...steps].sort((a, b) => a - b), `${m.id} ascending`).toEqual([...steps])
47
+ expect(new Set(steps).size, `${m.id} unique`).toBe(steps.length)
48
+ for (const s of steps) expect(s >= 0 && s <= 1, `${m.id} step ${s}`).toBe(true)
49
+ }
50
+ })
51
+ })
52
+
53
+ describe("dialogue lane — what v3 dialogue does today", () => {
54
+ it("tags, stability only, in the steps 0 / 0.5 / 1, 5,000 characters in total, v3's languages", () => {
55
+ const c = getDialogueCapabilities("elevenlabs-dialogue")
56
+ expect(c.audioTags).toBe(true)
57
+ expect(c.levers).toEqual(["stability"])
58
+ expect(c.stabilitySteps).toEqual([0, 0.5, 1])
59
+ expect(c.languageCode).toBe(true)
60
+ expect(c.maxChars).toBe(5000)
61
+ expect(getMaxTtsChars("elevenlabs-dialogue")).toBe(5000) // the old reader still agrees
62
+ expect(c.languages).toHaveLength(46)
63
+ })
64
+ })
65
+
66
+ describe("dialogue lane — lookups", () => {
67
+ it("a missing, empty, unknown, non-string or inherited-member id runs as the default and has no sheet of its own", () => {
68
+ const odd = [undefined, null, "", "not-a-model", "constructor", "__proto__", "toString", "hasOwnProperty", ["elevenlabs-dialogue"], 3, {}, true] as unknown[]
69
+ for (const id of odd) {
70
+ expect(findDialogueCapabilities(id), JSON.stringify(id)).toBeUndefined()
71
+ expect(dialogueProviderOf(id), JSON.stringify(id)).toBe(DEFAULT_DIALOGUE_PROVIDER)
72
+ expect(getDialogueCapabilities(id), JSON.stringify(id)).toBe(V3_DIALOGUE_SHEET)
73
+ }
74
+ })
75
+
76
+ it("a text-to-speech id is not a dialogue model — and a dialogue id is not a text-to-speech model", () => {
77
+ for (const id of TTS_PROVIDERS) {
78
+ expect(findDialogueCapabilities(id), id).toBeUndefined()
79
+ expect(dialogueProviderOf(id), id).toBe(DEFAULT_DIALOGUE_PROVIDER)
80
+ }
81
+ for (const id of DIALOGUE_PROVIDERS) expect(findTtsCapabilities(id), id).toBeUndefined()
82
+ })
83
+
84
+ it("a real dialogue id runs as itself", () => {
85
+ for (const id of DIALOGUE_PROVIDERS) {
86
+ expect(dialogueProviderOf(id)).toBe(id)
87
+ expect(getDialogueCapabilities(id)).toBe(MODEL_CATALOG[id]!.tts)
88
+ }
89
+ })
90
+
91
+ it("levers come from the sheet", () => {
92
+ expect(dialogueHasLever("elevenlabs-dialogue", "stability")).toBe(true)
93
+ expect(dialogueHasLever("elevenlabs-dialogue", "similarity")).toBe(false)
94
+ expect(dialogueHasLever(undefined, "similarity")).toBe(false) // runs as v3 dialogue
95
+ })
96
+
97
+ it("stability: v3 dialogue accepts its three steps and nothing else", () => {
98
+ for (const v of [0, 0.5, 1]) expect(dialogueStabilityAccepted("elevenlabs-dialogue", v), String(v)).toBe(true)
99
+ for (const v of [0.3, 0.25, 0.75, -0.1, 1.1, Number.NaN, Number.POSITIVE_INFINITY]) {
100
+ expect(dialogueStabilityAccepted("elevenlabs-dialogue", v), String(v)).toBe(false)
101
+ }
102
+ // An unknown id is judged as the model it runs as.
103
+ expect(dialogueStabilityAccepted("constructor", 0.3)).toBe(false)
104
+ })
105
+ })
106
+
107
+ describe("elevenlabs-dialogue-v4 — added beside v3 dialogue", () => {
108
+ it("is a dialogue provider and a dialogue-mode catalog model, never a text-to-speech one", () => {
109
+ expect(DIALOGUE_PROVIDERS).toContain("elevenlabs-dialogue-v4")
110
+ expect(MODEL_CATALOG["elevenlabs-dialogue-v4"]?.modes).toEqual(["dialogue"])
111
+ expect(TTS_PROVIDERS as readonly string[]).not.toContain("elevenlabs-dialogue-v4")
112
+ expect(findTtsCapabilities("elevenlabs-dialogue-v4")).toBeUndefined()
113
+ })
114
+
115
+ it("tags, stability (any 0–1) and similarity, the probed total cap, v3's languages", () => {
116
+ const c = getDialogueCapabilities("elevenlabs-dialogue-v4")
117
+ expect(c.audioTags).toBe(true)
118
+ expect(c.ssmlBreaks).toBe(false)
119
+ expect(c.levers).toEqual(["stability", "similarity"])
120
+ expect(c.stabilitySteps).toBeUndefined()
121
+ expect(c.languageCode).toBe(true)
122
+ // The live-probe number (parity with v3 dialogue until the probe says otherwise); never above 5,000 here.
123
+ expect(c.maxChars).toBe(5000)
124
+ expect(c.languages).toEqual(getDialogueCapabilities("elevenlabs-dialogue").languages)
125
+ })
126
+
127
+ it("takes any stability from 0 to 1; v3 dialogue keeps its steps", () => {
128
+ for (const v of [0, 0.3, 0.55, 1]) expect(dialogueStabilityAccepted("elevenlabs-dialogue-v4", v), String(v)).toBe(true)
129
+ expect(dialogueStabilityAccepted("elevenlabs-dialogue-v4", 1.01)).toBe(false)
130
+ expect(dialogueStabilityAccepted("elevenlabs-dialogue", 0.3)).toBe(false)
131
+ })
132
+
133
+ it("its flat row is 25 credits with no note, beside its per-100-characters row, on either dialogue model; v3 dialogue stays the default", () => {
134
+ expect(MODEL_CATALOG["elevenlabs-dialogue-v4"]!.pricing).toEqual([
135
+ { identifier: "elevenlabs-dialogue-v4", credits: 25 },
136
+ { identifier: "elevenlabs-dialogue-v4:per-100-chars", credits: 4, note: SPEECH_UNIT_PRICE_NOTE },
137
+ ])
138
+ // Decided 2026-10-06: the flat row carries no note (the old "per 1K chars"
139
+ // described a scaling that never existed); the length rule is its own row.
140
+ expect(MODEL_CATALOG["elevenlabs-dialogue"]!.pricing).toEqual([
141
+ { identifier: "elevenlabs-dialogue", credits: 25 },
142
+ { identifier: "elevenlabs-dialogue:per-100-chars", credits: 4, note: SPEECH_UNIT_PRICE_NOTE },
143
+ ])
144
+ expect(DEFAULT_DIALOGUE_PROVIDER).toBe("elevenlabs-dialogue")
145
+ expect(dialogueProviderOf(undefined)).toBe("elevenlabs-dialogue")
146
+ })
147
+ })
148
+
149
+ describe("dialogueSupportsTimestamps", () => {
150
+ it("both dialogue models return timings (measured 2026-10-06); an unknown id runs as v3 dialogue, so it does too", () => {
151
+ expect(dialogueSupportsTimestamps("elevenlabs-dialogue-v4")).toBe(true)
152
+ expect(dialogueSupportsTimestamps("elevenlabs-dialogue")).toBe(true)
153
+ for (const id of [undefined, "", "nope", "constructor", ["elevenlabs-dialogue-v4"], "elevenlabs-v4"] as unknown[]) {
154
+ expect(dialogueSupportsTimestamps(id), JSON.stringify(id)).toBe(true)
155
+ }
156
+ })
157
+ })
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest"
2
2
  import {
3
3
  EDITED_EDL_VERSION,
4
4
  editPlanBasis,
5
+ editPlanResultPatch,
5
6
  editPlanSavedOutput,
6
7
  resolveEditPlanOutput,
7
8
  validateEditedEdl,
@@ -109,6 +110,26 @@ describe("editPlanBasis — FNV-1a-64 over key-sorted JSON (TA13)", () => {
109
110
  it("ignores undefined-valued keys, as the stored JSON does", () => {
110
111
  expect(editPlanBasis({ ...TIGHTEN, derivedFrom: undefined })).toBe(editPlanBasis(TIGHTEN))
111
112
  })
113
+
114
+ it("hashes a plan object once: a later edit of the same plan reuses its basis", () => {
115
+ // Each review keystroke makes a new `editedEdl` object over the SAME plan
116
+ // object, and both engines read a saved plan many times in one run; none of
117
+ // them may walk the whole plan again (about 20 ms on a large one). A
118
+ // counting getter sees every walk.
119
+ let reads = 0
120
+ const counted = Object.defineProperty({ ...CLIPS[0] }, "meta", {
121
+ get: () => (reads++, { title: "counted" }),
122
+ enumerable: true,
123
+ })
124
+ const plan = [counted, CLIPS[1]]
125
+ const first = editPlanBasis(plan)
126
+ expect(reads).toBe(1)
127
+ expect(editPlanBasis(plan)).toBe(first)
128
+ expect(validateEditedEdl({ v: EDITED_EDL_VERSION, kind: "clips", basis: first, clips: [{ keep: true }, { keep: false }] }, plan).ok).toBe(true)
129
+ expect(reads).toBe(1)
130
+ // A copy is another object: hashed on its own, to the same value.
131
+ expect(editPlanBasis(JSON.parse(JSON.stringify(plan)))).toBe(first)
132
+ })
112
133
  })
113
134
 
114
135
  // ── editPlanSavedOutput: unedited parity ────────────────────────────────────
@@ -366,6 +387,55 @@ describe("editedEdl is run-result data (TA14)", () => {
366
387
  })
367
388
  })
368
389
 
390
+ // ── A landing plan keeps an edit made on the same plan (decided 2026-10-05) ──
391
+
392
+ describe("editPlanResultPatch — what a result writer writes when a plan lands", () => {
393
+ it("lands the plan", () => {
394
+ expect(editPlanResultPatch(TIGHTEN, undefined).generatedJson).toBe(TIGHTEN)
395
+ })
396
+
397
+ it("keeps an edit made on the same plan: the patch never names editedEdl", () => {
398
+ const edit = cutEdit(TIGHTEN, { segments: [], dropped: [] })
399
+ const patch = editPlanResultPatch(TIGHTEN, edit)
400
+ expect(patch).toEqual({ generatedJson: TIGHTEN })
401
+ expect(Object.prototype.hasOwnProperty.call(patch, "editedEdl")).toBe(false)
402
+ })
403
+
404
+ it("keeps it when the same plan comes back as another object (a reload, a JSONB round trip)", () => {
405
+ const edit = clipsEdit(CLIPS, [{ keep: true }, { keep: false }, { keep: true }])
406
+ const again = reverseKeysDeep(JSON.parse(JSON.stringify(CLIPS)))
407
+ expect(Object.prototype.hasOwnProperty.call(editPlanResultPatch(again, edit), "editedEdl")).toBe(false)
408
+ })
409
+
410
+ it("clears an edit made on a different plan", () => {
411
+ const edit = cutEdit(TIGHTEN, { segments: [], dropped: [] })
412
+ const replanned = { ...TIGHTEN, dropped: [] }
413
+ const patch = editPlanResultPatch(replanned, edit)
414
+ expect(patch).toEqual({ generatedJson: replanned, editedEdl: undefined })
415
+ expect(Object.prototype.hasOwnProperty.call(patch, "editedEdl")).toBe(true)
416
+ })
417
+
418
+ it("clears a clip review when the re-plan changes the clip set", () => {
419
+ const edit = clipsEdit(CLIPS, [{ keep: true }, { keep: false }, { keep: true }])
420
+ expect(editPlanResultPatch(CLIPS.slice(0, 2), edit)).toHaveProperty("editedEdl", undefined)
421
+ })
422
+
423
+ it.each([
424
+ ["no basis", { v: 1, kind: "edl", edl: { segments: [], dropped: [] } }],
425
+ ["an empty basis", { v: 1, kind: "edl", basis: "", edl: { segments: [], dropped: [] } }],
426
+ ["junk", "nope"],
427
+ ["null", null],
428
+ ])("clears an edit with %s (it names no plan)", (_name, edited) => {
429
+ expect(Object.prototype.hasOwnProperty.call(editPlanResultPatch(TIGHTEN, edited), "editedEdl")).toBe(true)
430
+ })
431
+
432
+ it("an edit kept by the patch still applies to the plan that landed", () => {
433
+ const edit = clipsEdit(CLIPS, [{ keep: false }, { keep: true }, { keep: false }])
434
+ const landed = { editedEdl: edit, ...editPlanResultPatch(CLIPS, edit) }
435
+ expect(editPlanSavedOutput(landed)?.json).toEqual([CLIPS[1]])
436
+ })
437
+ })
438
+
369
439
  // ── reference FNV-1a-64 (BigInt; the test's own oracle) ─────────────────────
370
440
 
371
441
  function fnv1a64Reference(text: string): string {