@nodaro/shared 3.20.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.
- package/dist/index.cjs +2287 -195
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1938 -82
- package/dist/index.d.ts +1938 -82
- package/dist/index.js +2119 -196
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/add-captions-plan.test.ts +33 -0
- package/src/__tests__/caption-plan-parse.test.ts +23 -0
- package/src/__tests__/caption-segment-schema.test.ts +30 -0
- package/src/__tests__/collections.test.ts +253 -0
- package/src/__tests__/default-tts-provider.test.ts +46 -0
- package/src/__tests__/dialogue-capabilities.test.ts +157 -0
- package/src/__tests__/edit-plan-review.test.ts +70 -0
- package/src/__tests__/edl-clocks.test.ts +97 -0
- package/src/__tests__/edl.test.ts +34 -0
- package/src/__tests__/execution-outcome.test.ts +44 -0
- package/src/__tests__/fan-out-meta.test.ts +23 -0
- package/src/__tests__/fan-out-rows.test.ts +36 -0
- package/src/__tests__/fan-out-url-item.test.ts +44 -0
- package/src/__tests__/fixtures/speaker-tracks.fixtures.json +622 -0
- package/src/__tests__/input-field-extra-keys.test.ts +34 -0
- package/src/__tests__/list-consumers-fan-in.test.ts +40 -0
- package/src/__tests__/model-tree.test.ts +7 -0
- package/src/__tests__/node-pass-through.test.ts +23 -0
- package/src/__tests__/node-runtime-keys.test.ts +1 -0
- package/src/__tests__/picker-restrictions.test.ts +36 -0
- package/src/__tests__/preview-gate.test.ts +305 -0
- package/src/__tests__/render-basis.test.ts +176 -0
- package/src/__tests__/render-nodes.test.ts +73 -0
- package/src/__tests__/render-output.test.ts +392 -0
- package/src/__tests__/run-continuation.test.ts +32 -0
- package/src/__tests__/speaker-tracks.test.ts +474 -0
- package/src/__tests__/speech-pricing.test.ts +69 -0
- package/src/__tests__/telegram-channel.test.ts +91 -0
- package/src/__tests__/tts-capabilities.test.ts +83 -5
- package/src/__tests__/tts-neighbour-text.test.ts +19 -0
- package/src/__tests__/ugc-call-body.test.ts +38 -0
- package/src/__tests__/ugc-run-state.test.ts +68 -0
- package/src/__tests__/video-character-refs.test.ts +213 -0
- package/src/__tests__/video-overlay-layer-plan.test.ts +94 -0
- package/src/add-captions-plan.ts +50 -0
- package/src/caption-plan.ts +45 -0
- package/src/caption-segment-schema.ts +82 -0
- package/src/collections.ts +462 -0
- package/src/competitors.ts +77 -0
- package/src/credit-estimators/index.ts +9 -0
- package/src/credit-estimators/speech.ts +51 -0
- package/src/dialogue-capabilities.ts +48 -0
- package/src/edit-plan-contract.ts +20 -9
- package/src/edit-plan-review.ts +40 -1
- package/src/edl.ts +27 -1
- package/src/execution-outcome.ts +41 -0
- package/src/fan-out-meta.ts +23 -0
- package/src/fan-out-rows.ts +74 -5
- package/src/gemini-omni-voices.ts +59 -0
- package/src/handle-aliases.ts +295 -0
- package/src/i18n/camera-motions.pt-BR.ts +14 -14
- package/src/i18n/transitions.pt-BR.ts +13 -13
- package/src/index.ts +180 -1
- package/src/model-catalog.ts +125 -15
- package/src/model-constants.ts +37 -4
- package/src/model-tree.ts +5 -1
- package/src/node-execution-state.ts +13 -0
- package/src/node-mappable-fields.ts +7 -1
- package/src/node-pass-through.ts +37 -0
- package/src/node-runtime-keys.ts +14 -0
- package/src/picker-restrictions.ts +49 -0
- package/src/presentation-types.ts +26 -2
- package/src/presentation-utils.ts +25 -7
- package/src/preview-gate.ts +279 -0
- package/src/producer-types.ts +58 -0
- package/src/render-final.ts +20 -0
- package/src/render-nodes.ts +92 -0
- package/src/render-output.ts +565 -0
- package/src/run-continuation.ts +39 -0
- package/src/speaker-tracks.ts +638 -0
- package/src/telegram-channel.ts +140 -0
- package/src/transcribe-preflight.ts +8 -4
- package/src/tts-capabilities.ts +19 -5
- package/src/tts-neighbour-text.ts +46 -0
- package/src/ugc-call-body.ts +86 -0
- package/src/ugc-run-state.ts +64 -0
- package/src/video-character-refs.ts +233 -0
- package/src/video-overlay.ts +78 -21
- package/src/voices.ts +11 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest"
|
|
2
|
-
import { MODEL_CATALOG } from "../model-catalog.js"
|
|
2
|
+
import { MODEL_CATALOG, SPEECH_UNIT_PRICE_NOTE } from "../model-catalog.js"
|
|
3
3
|
import { TTS_PROVIDERS, MAX_TTS_CHARS_BY_PROVIDER, getMaxTtsChars, TTS_TEXT_MAX } from "../model-constants.js"
|
|
4
4
|
import {
|
|
5
5
|
TTS_PROVIDER_ALIASES,
|
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
getTtsCapabilities,
|
|
10
10
|
ttsSupportsAudioTags,
|
|
11
11
|
ttsSupportsSsmlBreaks,
|
|
12
|
+
ttsSupportsStitching,
|
|
12
13
|
ttsHasLever,
|
|
13
14
|
ttsLanguageCodes,
|
|
15
|
+
ttsSupportsTimestamps,
|
|
14
16
|
} from "../tts-capabilities.js"
|
|
15
17
|
|
|
16
18
|
describe("speech-model capability sheets — totality", () => {
|
|
@@ -54,6 +56,24 @@ describe("speech-model capability sheets — totality", () => {
|
|
|
54
56
|
expect(m.features?.includes("audio-tags") ?? false, `${m.id} audio-tags feature`).toBe(m.tts.audioTags)
|
|
55
57
|
}
|
|
56
58
|
})
|
|
59
|
+
|
|
60
|
+
it("every sheet says whether the model returns timings, and all six speech models do", () => {
|
|
61
|
+
const yes = Object.values(MODEL_CATALOG).filter((m) => m.tts?.timestamps === true).map((m) => m.id).sort()
|
|
62
|
+
for (const m of Object.values(MODEL_CATALOG)) {
|
|
63
|
+
if (!m.tts) continue
|
|
64
|
+
expect(typeof m.tts.timestamps, `${m.id} timestamps`).toBe("boolean")
|
|
65
|
+
}
|
|
66
|
+
// Measured 2026-10-04 (v4) and 2026-10-06 (the rest): /with-timestamps answers 200 on every
|
|
67
|
+
// speech model at the same character cost. A new model joins this list only once it is measured.
|
|
68
|
+
expect(yes).toEqual([
|
|
69
|
+
"elevenlabs-dialogue",
|
|
70
|
+
"elevenlabs-dialogue-v4",
|
|
71
|
+
"elevenlabs-multilingual",
|
|
72
|
+
"elevenlabs-turbo",
|
|
73
|
+
"elevenlabs-v3",
|
|
74
|
+
"elevenlabs-v4",
|
|
75
|
+
])
|
|
76
|
+
})
|
|
57
77
|
})
|
|
58
78
|
|
|
59
79
|
describe("speech-model capability sheets — what each model does today", () => {
|
|
@@ -224,14 +244,72 @@ describe("elevenlabs-v4 — added beside v3", () => {
|
|
|
224
244
|
expect(getMaxTtsChars("elevenlabs-v3")).toBe(5000)
|
|
225
245
|
})
|
|
226
246
|
|
|
227
|
-
it("
|
|
247
|
+
it("its flat row is 30 credits with no note — the same as v3 — beside its per-100-characters row; as the default, it is the featured model", () => {
|
|
228
248
|
const v4 = MODEL_CATALOG["elevenlabs-v4"]!
|
|
229
|
-
expect(v4.pricing).toEqual([
|
|
230
|
-
|
|
231
|
-
|
|
249
|
+
expect(v4.pricing).toEqual([
|
|
250
|
+
{ identifier: "elevenlabs-v4", credits: 30 },
|
|
251
|
+
{ identifier: "elevenlabs-v4:per-100-chars", credits: 4, note: SPEECH_UNIT_PRICE_NOTE },
|
|
252
|
+
])
|
|
253
|
+
expect(MODEL_CATALOG["elevenlabs-v3"]!.pricing).toEqual([
|
|
254
|
+
{ identifier: "elevenlabs-v3", credits: 30 },
|
|
255
|
+
{ identifier: "elevenlabs-v3:per-100-chars", credits: 4, note: SPEECH_UNIT_PRICE_NOTE },
|
|
256
|
+
])
|
|
257
|
+
expect(v4.featured).toBe(true)
|
|
258
|
+
expect(MODEL_CATALOG["elevenlabs-v3"]!.featured).toBeUndefined()
|
|
232
259
|
})
|
|
233
260
|
|
|
234
261
|
it("does not call v3 the latest model any more", () => {
|
|
235
262
|
expect(MODEL_CATALOG["elevenlabs-v3"]!.description).not.toMatch(/latest/i)
|
|
236
263
|
})
|
|
237
264
|
})
|
|
265
|
+
|
|
266
|
+
describe("ttsSupportsTimestamps", () => {
|
|
267
|
+
it("answers for the model the request runs as", () => {
|
|
268
|
+
expect(ttsSupportsTimestamps("elevenlabs-v4")).toBe(true)
|
|
269
|
+
expect(ttsSupportsTimestamps("elevenlabs-v3")).toBe(true)
|
|
270
|
+
expect(ttsSupportsTimestamps("elevenlabs-turbo")).toBe(true)
|
|
271
|
+
expect(ttsSupportsTimestamps("elevenlabs-multilingual")).toBe(true)
|
|
272
|
+
// Unknown / missing / legacy alias run as turbo, which answers timings too.
|
|
273
|
+
expect(ttsSupportsTimestamps(undefined)).toBe(true)
|
|
274
|
+
expect(ttsSupportsTimestamps("elevenlabs")).toBe(true)
|
|
275
|
+
expect(ttsSupportsTimestamps("not-a-model")).toBe(true)
|
|
276
|
+
// A dialogue id is not a text-to-speech model: it runs as the fallback here (turbo).
|
|
277
|
+
expect(ttsSupportsTimestamps("elevenlabs-dialogue-v4")).toBe(true)
|
|
278
|
+
})
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
describe("stitching — conditioning on neighbouring text (previous_text / next_text)", () => {
|
|
282
|
+
it("every speech sheet declares it (a boolean, never undefined)", () => {
|
|
283
|
+
for (const m of Object.values(MODEL_CATALOG)) {
|
|
284
|
+
if (!m.tts) continue
|
|
285
|
+
expect(typeof m.tts.stitching, `${m.id} stitching`).toBe("boolean")
|
|
286
|
+
}
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
it("v4, Turbo and Multilingual condition on neighbouring text (probed 200 each); v3 rejects the fields (probed 400); the dialogue sheet says no (its lane does not read it)", () => {
|
|
290
|
+
expect(getTtsCapabilities("elevenlabs-v4").stitching).toBe(true)
|
|
291
|
+
expect(getTtsCapabilities("elevenlabs-turbo").stitching).toBe(true)
|
|
292
|
+
expect(getTtsCapabilities("elevenlabs-multilingual").stitching).toBe(true)
|
|
293
|
+
expect(getTtsCapabilities("elevenlabs-v3").stitching).toBe(false)
|
|
294
|
+
expect(MODEL_CATALOG["elevenlabs-dialogue"]!.tts!.stitching).toBe(false)
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
it("the reader answers from the sheet of the model the request runs as", () => {
|
|
298
|
+
expect(ttsSupportsStitching("elevenlabs-v4")).toBe(true)
|
|
299
|
+
expect(ttsSupportsStitching("elevenlabs-v3")).toBe(false)
|
|
300
|
+
expect(ttsSupportsStitching("elevenlabs-multilingual")).toBe(true)
|
|
301
|
+
const turbo = ttsSupportsStitching("elevenlabs-turbo")
|
|
302
|
+
expect(turbo).toBe(getTtsCapabilities("elevenlabs-turbo").stitching)
|
|
303
|
+
// The alias, a missing id, an unknown id, an inherited-member name and a non-string all run as turbo.
|
|
304
|
+
for (const id of ["elevenlabs", undefined, "not-a-model", "constructor", "elevenlabs-dialogue", ["elevenlabs-v4"] as unknown as string]) {
|
|
305
|
+
expect(ttsSupportsStitching(id), JSON.stringify(id)).toBe(turbo)
|
|
306
|
+
}
|
|
307
|
+
})
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
describe("field mappings — the neighbour text fields are mappable", () => {
|
|
311
|
+
it("text-to-speech maps directText and both neighbour fields, in that order", async () => {
|
|
312
|
+
const { NODE_MAPPABLE_FIELDS } = await import("../node-mappable-fields.js")
|
|
313
|
+
expect(NODE_MAPPABLE_FIELDS["text-to-speech"]).toEqual(["directText", "previousText", "nextText"])
|
|
314
|
+
})
|
|
315
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest"
|
|
2
|
+
import { TTS_NEIGHBOUR_TEXT_MAX_CHARS, normalizeTtsNeighbourText } from "../tts-neighbour-text.js"
|
|
3
|
+
|
|
4
|
+
describe("the neighbour-text rule (shared by the editor and the provider exits)", () => {
|
|
5
|
+
it("the cap is 1,000 characters", () => {
|
|
6
|
+
expect(TTS_NEIGHBOUR_TEXT_MAX_CHARS).toBe(1000)
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it("trims; blank and non-string values are absent", () => {
|
|
10
|
+
expect(normalizeTtsNeighbourText({ previousText: " Before. ", nextText: null })).toEqual({ previousText: "Before." })
|
|
11
|
+
expect(normalizeTtsNeighbourText(undefined)).toEqual({})
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it("over the cap: previous keeps its end, next its start", () => {
|
|
15
|
+
const out = normalizeTtsNeighbourText({ previousText: `${"a".repeat(5)}${"b".repeat(1000)}`, nextText: `${"c".repeat(1000)}${"d".repeat(5)}` })
|
|
16
|
+
expect(out.previousText).toBe("b".repeat(1000))
|
|
17
|
+
expect(out.nextText).toBe("c".repeat(1000))
|
|
18
|
+
})
|
|
19
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { ugcCallToRouteBody } from "../ugc-call-body.js"
|
|
3
|
+
|
|
4
|
+
describe("ugcCallToRouteBody", () => {
|
|
5
|
+
it("maps generate_image, every lever as given", () => {
|
|
6
|
+
expect(ugcCallToRouteBody({ tool: "generate_image", args: { prompt: "p", model: "m-1", aspect_ratio: "3:4", resolution: "1K" } })).toEqual({
|
|
7
|
+
path: "/v1/generate-image",
|
|
8
|
+
body: { prompt: "p", provider: "m-1", aspectRatio: "3:4", resolution: "1K" },
|
|
9
|
+
})
|
|
10
|
+
expect(ugcCallToRouteBody({ tool: "generate_image", args: { prompt: "p", model: "m-2", aspect_ratio: "3:4", quality: "basic" } })!).toEqual({
|
|
11
|
+
path: "/v1/generate-image",
|
|
12
|
+
body: { prompt: "p", provider: "m-2", aspectRatio: "3:4", quality: "basic" },
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
it("maps a lever-less generate_image (a model with no resolution or quality) without adding either", () => {
|
|
16
|
+
expect(ugcCallToRouteBody({ tool: "generate_image", args: { prompt: "p", model: "m-4", aspect_ratio: "3:4" } })).toEqual({
|
|
17
|
+
path: "/v1/generate-image",
|
|
18
|
+
body: { prompt: "p", provider: "m-4", aspectRatio: "3:4" },
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
it("fills the image of an ImageArgCall and nothing else", () => {
|
|
22
|
+
const call = { tool: "image_to_image", args: { prompt: "edit", model: "m-3", resolution: "2K" }, imageArg: "image_url" }
|
|
23
|
+
expect(ugcCallToRouteBody(call, { image: "https://cdn.example/c.png" })).toEqual({
|
|
24
|
+
path: "/v1/image-to-image",
|
|
25
|
+
body: { imageUrl: "https://cdn.example/c.png", prompt: "edit", provider: "m-3", resolution: "2K" },
|
|
26
|
+
})
|
|
27
|
+
expect(ugcCallToRouteBody(call)).toEqual({ error: "image_to_image needs the previous step's image" })
|
|
28
|
+
})
|
|
29
|
+
it("maps image_to_text with the photo as its image", () => {
|
|
30
|
+
expect(ugcCallToRouteBody({ tool: "image_to_text", args: { custom_prompt: "q" } }, { image: "https://cdn.example/p.png" })).toEqual({
|
|
31
|
+
path: "/v1/image-to-text/describe",
|
|
32
|
+
body: { imageUrl: "https://cdn.example/p.png", customPrompt: "q" },
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
it("returns undefined for a tool it does not know", () => {
|
|
36
|
+
expect(ugcCallToRouteBody({ tool: "generate_video", args: {} })).toBeUndefined()
|
|
37
|
+
})
|
|
38
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { LEGACY_EXPOSED_FIELD_KEYS } from "../exposed-field-keys.js"
|
|
3
|
+
import { UGC_NODE_RUN_STATE_KEYS, UGC_NODE_TYPES, UGC_OVERRIDABLE_FIELDS, findUgcLockedFields, stripUgcRunState } from "../ugc-run-state.js"
|
|
4
|
+
|
|
5
|
+
describe("UGC run state", () => {
|
|
6
|
+
it("covers exactly the five UGC types", () => {
|
|
7
|
+
const five = ["ugc-cards", "ugc-clip", "ugc-clips", "ugc-creator", "ugc-script"]
|
|
8
|
+
expect([...UGC_NODE_TYPES].sort()).toEqual(five)
|
|
9
|
+
expect(Object.keys(UGC_NODE_RUN_STATE_KEYS).sort()).toEqual(five)
|
|
10
|
+
expect(Object.keys(UGC_OVERRIDABLE_FIELDS).sort()).toEqual(five)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it("never lists a run-state key as overridable", () => {
|
|
14
|
+
for (const [type, fields] of Object.entries(UGC_OVERRIDABLE_FIELDS)) {
|
|
15
|
+
for (const field of fields) expect(UGC_NODE_RUN_STATE_KEYS[type]).not.toContain(field)
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it("no UGC type has a legacy exposed-field rename (the lock reads the stored key)", () => {
|
|
20
|
+
for (const type of UGC_NODE_TYPES) expect(Object.hasOwn(LEGACY_EXPOSED_FIELD_KEYS, type)).toBe(false)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it("strips every run-state key and turns keepResult off, leaving choices and other nodes alone", () => {
|
|
24
|
+
const nodes = [
|
|
25
|
+
{ id: "c", type: "ugc-creator", data: { source: "photo", gender: "man", keepResult: true, result: { v: 1 } } },
|
|
26
|
+
{ id: "s", type: "ugc-script", data: { targetDurationSec: 20, keepResult: true, result: { v: 1 } } },
|
|
27
|
+
{ id: "l", type: "ugc-clips", data: { voiceId: "v", quote: { lines: [] }, result: {}, __listResults: ["{}"], ugcOutputs: { "plan-out": "{}" } } },
|
|
28
|
+
{ id: "k", type: "ugc-clip", data: { rerender: { "2": 1 }, warnings: ["x"], __listResults: ["u"], __listResultMeta: [], clipWarnings: [], durationSec: 9 } },
|
|
29
|
+
{ id: "d", type: "ugc-cards", data: { result: { report: "No issues." } } },
|
|
30
|
+
{ id: "t", type: "text-prompt", data: { text: "keep", result: "keep" } },
|
|
31
|
+
]
|
|
32
|
+
const out = stripUgcRunState(nodes)
|
|
33
|
+
expect(out.map((n) => n.data)).toEqual([
|
|
34
|
+
{ source: "photo", gender: "man", keepResult: false },
|
|
35
|
+
{ targetDurationSec: 20, keepResult: false },
|
|
36
|
+
{ voiceId: "v" },
|
|
37
|
+
{},
|
|
38
|
+
{},
|
|
39
|
+
{ text: "keep", result: "keep" },
|
|
40
|
+
])
|
|
41
|
+
expect(nodes[0]!.data.keepResult).toBe(true) // input untouched
|
|
42
|
+
expect(out[5]).toBe(nodes[5]) // other nodes are returned as they are
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it("leaves a UGC node with no data object alone", () => {
|
|
46
|
+
const node = { id: "x", type: "ugc-clip" }
|
|
47
|
+
expect(stripUgcRunState([node])).toEqual([node])
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it("refuses every UGC key outside the allow-list", () => {
|
|
51
|
+
const nodes = [{ id: "creator", type: "ugc-creator" }, { id: "script", type: "ugc-script" }, { id: "clip", type: "ugc-clip" }]
|
|
52
|
+
expect(findUgcLockedFields(nodes, { creator: { source: "photo", gender: "woman", photoUrl: "https://cdn.example/p.png" }, script: { targetDurationSec: 20 } })).toEqual([])
|
|
53
|
+
expect(findUgcLockedFields(nodes, { creator: { keepResult: true, result: {} }, script: { keepResult: true }, clip: { rerender: {} } })).toEqual([
|
|
54
|
+
{ nodeId: "creator", nodeType: "ugc-creator", field: "keepResult" },
|
|
55
|
+
{ nodeId: "creator", nodeType: "ugc-creator", field: "result" },
|
|
56
|
+
{ nodeId: "script", nodeType: "ugc-script", field: "keepResult" },
|
|
57
|
+
{ nodeId: "clip", nodeType: "ugc-clip", field: "rerender" },
|
|
58
|
+
])
|
|
59
|
+
// A future field is refused without anyone listing it.
|
|
60
|
+
expect(findUgcLockedFields(nodes, { script: { language: "he" } })).toEqual([{ nodeId: "script", nodeType: "ugc-script", field: "language" }])
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it("ignores non-UGC nodes and missing inputs", () => {
|
|
64
|
+
expect(findUgcLockedFields([{ id: "t", type: "text-prompt" }], { t: { text: "x" } })).toEqual([])
|
|
65
|
+
expect(findUgcLockedFields(null, { t: { text: "x" } })).toEqual([])
|
|
66
|
+
expect(findUgcLockedFields([{ id: "c", type: "ugc-creator" }], undefined)).toEqual([])
|
|
67
|
+
})
|
|
68
|
+
})
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import {
|
|
3
|
+
VIDEO_CHARACTER_REFS_WIRE_MAX,
|
|
4
|
+
VIDEO_REF_LIMITS_BY_PROVIDER,
|
|
5
|
+
videoCharacterRefCap,
|
|
6
|
+
videoCharacterRefUnits,
|
|
7
|
+
videoCharacterRefProblem,
|
|
8
|
+
videoCharacterVoiceCap,
|
|
9
|
+
videoCharacterVoiceProblem,
|
|
10
|
+
videoCharacterDistinctVoices,
|
|
11
|
+
GEMINI_OMNI_VOICE_PRESETS,
|
|
12
|
+
GEMINI_OMNI_VOICE_PRESET_IDS,
|
|
13
|
+
VIDEO_CHARACTER_VOICE_DESCRIPTION_MAX,
|
|
14
|
+
VIDEO_CHARACTER_VOICE_EXAMPLE_MAX,
|
|
15
|
+
type VideoCharacterReference,
|
|
16
|
+
} from "../index.js"
|
|
17
|
+
|
|
18
|
+
const portrait = (over: Partial<VideoCharacterReference> = {}): VideoCharacterReference => ({
|
|
19
|
+
imageUrl: "https://cdn.example/p.png",
|
|
20
|
+
description: "A woman with short silver hair",
|
|
21
|
+
...over,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe("character reference capability (data-driven)", () => {
|
|
25
|
+
it("both Gemini Omni SKUs declare a 3-character cap; nothing else does", () => {
|
|
26
|
+
expect(VIDEO_REF_LIMITS_BY_PROVIDER["gemini-omni-video"]?.characters).toBe(3)
|
|
27
|
+
expect(VIDEO_REF_LIMITS_BY_PROVIDER["gemini-omni-flash"]?.characters).toBe(3)
|
|
28
|
+
const others = Object.entries(VIDEO_REF_LIMITS_BY_PROVIDER)
|
|
29
|
+
.filter(([id, l]) => !id.startsWith("gemini-omni") && (l?.characters ?? 0) > 0)
|
|
30
|
+
expect(others).toEqual([])
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it("the wire ceiling is the widest declared cap", () => {
|
|
34
|
+
const widest = Math.max(...Object.values(VIDEO_REF_LIMITS_BY_PROVIDER).map((l) => l?.characters ?? 0))
|
|
35
|
+
expect(VIDEO_CHARACTER_REFS_WIRE_MAX).toBe(widest)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it("videoCharacterRefCap reads the map; unknown / undefined provider = 0", () => {
|
|
39
|
+
expect(videoCharacterRefCap("gemini-omni-video")).toBe(3)
|
|
40
|
+
expect(videoCharacterRefCap("seedance-2")).toBe(0)
|
|
41
|
+
expect(videoCharacterRefCap(undefined)).toBe(0)
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe("videoCharacterRefUnits", () => {
|
|
46
|
+
it("a portrait-only character is 1 unit, a portrait+body set is 2 (KIE: dual-image sets occupy two slots)", () => {
|
|
47
|
+
expect(videoCharacterRefUnits([portrait()])).toBe(1)
|
|
48
|
+
expect(videoCharacterRefUnits([portrait({ bodyImageUrl: "https://cdn.example/b.png" })])).toBe(2)
|
|
49
|
+
expect(videoCharacterRefUnits([portrait(), portrait({ bodyImageUrl: "https://cdn.example/b.png" })])).toBe(3)
|
|
50
|
+
expect(videoCharacterRefUnits(undefined)).toBe(0)
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe("videoCharacterRefProblem", () => {
|
|
55
|
+
const base = { provider: "gemini-omni-video", imageCount: 0, videoCount: 0, hasStartFrame: false }
|
|
56
|
+
|
|
57
|
+
it("nothing supplied is never a problem, on any provider", () => {
|
|
58
|
+
expect(videoCharacterRefProblem({ ...base, provider: "seedance-2", characterReferences: undefined })).toBeNull()
|
|
59
|
+
expect(videoCharacterRefProblem({ ...base, provider: "seedance-2", characterReferences: [] })).toBeNull()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it("a supported provider with an in-budget request passes", () => {
|
|
63
|
+
expect(videoCharacterRefProblem({ ...base, characterReferences: [portrait()] })).toBeNull()
|
|
64
|
+
expect(videoCharacterRefProblem({ ...base, provider: "gemini-omni-flash", characterReferences: [portrait()] })).toBeNull()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it("an unsupported provider is rejected, naming the provider", () => {
|
|
68
|
+
const p = videoCharacterRefProblem({ ...base, provider: "seedance-2", characterReferences: [portrait()] })
|
|
69
|
+
expect(p?.code).toBe("character_references_unsupported")
|
|
70
|
+
expect(p?.message).toContain("seedance-2")
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it("more than the provider cap is rejected", () => {
|
|
74
|
+
const p = videoCharacterRefProblem({ ...base, characterReferences: [portrait(), portrait(), portrait(), portrait()] })
|
|
75
|
+
expect(p?.code).toBe("character_references_over_limit")
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it("a start frame is rejected with an explanation (no silent drop)", () => {
|
|
79
|
+
const p = videoCharacterRefProblem({ ...base, hasStartFrame: true, characterReferences: [portrait()] })
|
|
80
|
+
expect(p?.code).toBe("character_references_with_start_frame")
|
|
81
|
+
expect(p?.message.toLowerCase()).toContain("start frame")
|
|
82
|
+
// It is OUR limit (the frame rides image_urls), never a claim about the upstream.
|
|
83
|
+
expect(p?.message.toLowerCase()).not.toContain("mutually exclusive")
|
|
84
|
+
expect(p?.message.toLowerCase()).not.toContain("provider treats")
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it("an end frame is rejected too (Gemini has no end-frame input; never dropped silently)", () => {
|
|
88
|
+
const p = videoCharacterRefProblem({ ...base, hasEndFrame: true, characterReferences: [portrait()] })
|
|
89
|
+
expect(p?.code).toBe("character_references_with_end_frame")
|
|
90
|
+
expect(p?.message).toContain("endFrameUrl")
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it("an end frame without characters is none of this rule's business", () => {
|
|
94
|
+
expect(videoCharacterRefProblem({ ...base, hasEndFrame: true, characterReferences: undefined })).toBeNull()
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it("enforces images + 2×videos + character units ≤ 7", () => {
|
|
98
|
+
// 3 characters (3) + 1 video (2) + 2 images = 7 → ok
|
|
99
|
+
expect(videoCharacterRefProblem({
|
|
100
|
+
...base, imageCount: 2, videoCount: 1, characterReferences: [portrait(), portrait(), portrait()],
|
|
101
|
+
})).toBeNull()
|
|
102
|
+
// one more image → 8 → rejected
|
|
103
|
+
const over = videoCharacterRefProblem({
|
|
104
|
+
...base, imageCount: 3, videoCount: 1, characterReferences: [portrait(), portrait(), portrait()],
|
|
105
|
+
})
|
|
106
|
+
expect(over?.code).toBe("character_references_quota")
|
|
107
|
+
expect(over?.message).toContain("7")
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it("a body image costs a second unit in the quota", () => {
|
|
111
|
+
const withBody = portrait({ bodyImageUrl: "https://cdn.example/b.png" })
|
|
112
|
+
// 2 body-sets (4) + 3 images = 7 → ok; + 1 more image = 8 → rejected
|
|
113
|
+
expect(videoCharacterRefProblem({ ...base, imageCount: 3, characterReferences: [withBody, withBody] })).toBeNull()
|
|
114
|
+
expect(videoCharacterRefProblem({ ...base, imageCount: 4, characterReferences: [withBody, withBody] })?.code)
|
|
115
|
+
.toBe("character_references_quota")
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
describe("Gemini Omni voice presets (data)", () => {
|
|
120
|
+
it("lists the 30 documented preset ids, each with a gender and style label", () => {
|
|
121
|
+
expect(GEMINI_OMNI_VOICE_PRESETS).toHaveLength(30)
|
|
122
|
+
expect(GEMINI_OMNI_VOICE_PRESET_IDS).toHaveLength(30)
|
|
123
|
+
expect(new Set(GEMINI_OMNI_VOICE_PRESET_IDS).size).toBe(30)
|
|
124
|
+
expect(GEMINI_OMNI_VOICE_PRESET_IDS).toContain("achernar")
|
|
125
|
+
expect(GEMINI_OMNI_VOICE_PRESET_IDS).toContain("zubenelgenubi")
|
|
126
|
+
for (const v of GEMINI_OMNI_VOICE_PRESETS) {
|
|
127
|
+
expect(["female", "male", "genderless"]).toContain(v.gender)
|
|
128
|
+
expect(v.style.length).toBeGreaterThan(0)
|
|
129
|
+
expect(v.pitch.length).toBeGreaterThan(0)
|
|
130
|
+
}
|
|
131
|
+
expect(GEMINI_OMNI_VOICE_PRESETS.find((v) => v.id === "achernar")).toMatchObject({ gender: "female", style: "soft", pitch: "high" })
|
|
132
|
+
expect(GEMINI_OMNI_VOICE_PRESETS.find((v) => v.id === "pulcherrima")?.gender).toBe("genderless")
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it("exposes the free-text limits the upstream documents", () => {
|
|
136
|
+
expect(VIDEO_CHARACTER_VOICE_DESCRIPTION_MAX).toBe(2000)
|
|
137
|
+
expect(VIDEO_CHARACTER_VOICE_EXAMPLE_MAX).toBe(120)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it("a model that declares voices also declares characters (voices ride the character create)", () => {
|
|
141
|
+
for (const [id, l] of Object.entries(VIDEO_REF_LIMITS_BY_PROVIDER)) {
|
|
142
|
+
if ((l?.voices ?? 0) > 0) expect(l?.characters ?? 0, `${id} declares voices but no characters`).toBeGreaterThan(0)
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it("the voice cap is data on the same map: Gemini Omni 3, others 0", () => {
|
|
147
|
+
expect(videoCharacterVoiceCap("gemini-omni-video")).toBe(3)
|
|
148
|
+
expect(videoCharacterVoiceCap("gemini-omni-flash")).toBe(3)
|
|
149
|
+
expect(videoCharacterVoiceCap("seedance-2")).toBe(0)
|
|
150
|
+
expect(videoCharacterVoiceCap(undefined)).toBe(0)
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
describe("character voices", () => {
|
|
155
|
+
const base = { provider: "gemini-omni-video", imageCount: 0, videoCount: 0, hasStartFrame: false }
|
|
156
|
+
const voiced = (preset: string, over: Partial<NonNullable<VideoCharacterReference["voice"]>> = {}) =>
|
|
157
|
+
portrait({ voice: { preset: preset as never, ...over } })
|
|
158
|
+
|
|
159
|
+
it("counts distinct voice PERSONAS: (preset, description, exampleLine, name); the portrait does not matter", () => {
|
|
160
|
+
expect(videoCharacterDistinctVoices([voiced("kore"), voiced("kore", { description: "warm" }), portrait()])).toBe(2)
|
|
161
|
+
expect(videoCharacterDistinctVoices([voiced("kore"), { ...voiced("kore"), imageUrl: "https://cdn.example/other.png" }])).toBe(1)
|
|
162
|
+
// The persona is created under the character's name, so a different name is a different persona.
|
|
163
|
+
expect(videoCharacterDistinctVoices([voiced("kore"), { ...voiced("kore"), name: "Ann" }])).toBe(2)
|
|
164
|
+
expect(videoCharacterDistinctVoices(undefined)).toBe(0)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
it("a voiced character on a supporting provider passes", () => {
|
|
168
|
+
expect(videoCharacterRefProblem({ ...base, characterReferences: [voiced("kore"), voiced("puck")] })).toBeNull()
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
it("an unsupported provider rejects a voice by name (never silently drops it)", () => {
|
|
172
|
+
const p = videoCharacterVoiceProblem({ provider: "seedance-2", characterReferences: [voiced("kore")] })
|
|
173
|
+
expect(p?.code).toBe("character_voice_unsupported")
|
|
174
|
+
expect(p?.message).toContain("seedance-2")
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it("more than the voice cap in DISTINCT voices has its own code", () => {
|
|
178
|
+
const four = [voiced("kore"), voiced("puck"), voiced("leda"), voiced("orus")]
|
|
179
|
+
const p = videoCharacterVoiceProblem({ provider: "gemini-omni-video", characterReferences: four })
|
|
180
|
+
expect(p?.code).toBe("character_voices_over_limit")
|
|
181
|
+
expect(p?.message).toContain("3")
|
|
182
|
+
expect(p?.message).toContain("4")
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it("exactly the cap passes; two characters sharing one voice count once", () => {
|
|
186
|
+
expect(videoCharacterVoiceProblem({ provider: "gemini-omni-video", characterReferences: [voiced("kore"), voiced("puck"), voiced("leda")] })).toBeNull()
|
|
187
|
+
expect(videoCharacterVoiceProblem({ provider: "gemini-omni-video", characterReferences: [voiced("kore"), voiced("kore")], cap: 1 })).toBeNull()
|
|
188
|
+
expect(videoCharacterVoiceProblem({ provider: "gemini-omni-video", characterReferences: [voiced("kore"), { ...voiced("kore"), name: "Bo" }], cap: 1 })?.code).toBe("character_voices_over_limit")
|
|
189
|
+
expect(videoCharacterVoiceProblem({ provider: "gemini-omni-video", characterReferences: [voiced("kore"), voiced("puck")], cap: 1 })?.code).toBe("character_voices_over_limit")
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
it("no voices is none of this rule's business", () => {
|
|
193
|
+
expect(videoCharacterVoiceProblem({ provider: "seedance-2", characterReferences: [portrait()] })).toBeNull()
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it("videoCharacterRefProblem runs the voice rule after the character rules", () => {
|
|
197
|
+
expect(videoCharacterRefProblem({ ...base, provider: "seedance-2", characterReferences: [voiced("kore")] })?.code)
|
|
198
|
+
.toBe("character_references_unsupported")
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
describe("voice presets documentation", () => {
|
|
203
|
+
it("the public node page lists every preset with its gender, style and pitch (the table cannot drift from the data)", async () => {
|
|
204
|
+
const { readFileSync } = await import("node:fs")
|
|
205
|
+
const { resolve, dirname } = await import("node:path")
|
|
206
|
+
const { fileURLToPath } = await import("node:url")
|
|
207
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
208
|
+
const doc = readFileSync(resolve(here, "../../../../docs/nodes/ai-video/generate-video.md"), "utf8")
|
|
209
|
+
for (const v of GEMINI_OMNI_VOICE_PRESETS) {
|
|
210
|
+
expect(doc, `${v.id} row`).toContain(`| \`${v.id}\` | ${v.gender} | ${v.style} | ${v.pitch} |`)
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import {
|
|
3
|
+
VIDEO_OVERLAY_MAX_LAYERS,
|
|
4
|
+
assembleVideoOverlayRequest,
|
|
5
|
+
formatVideoOverlayError,
|
|
6
|
+
parseVideoOverlayLayerPlan,
|
|
7
|
+
validateVideoOverlayRequest,
|
|
8
|
+
videoOverlayCompositionKey,
|
|
9
|
+
videoOverlayRenderOrder,
|
|
10
|
+
videoOverlaySlotSources,
|
|
11
|
+
} from "../video-overlay.js"
|
|
12
|
+
|
|
13
|
+
const box = { anchor: "top", x: 0, y: 12, width: 78, height: 52, fit: "contain" } as const
|
|
14
|
+
const plan = [
|
|
15
|
+
{ imageUrl: "https://cdn.example/s1.png", start: 1.4, end: 2.8, ...box },
|
|
16
|
+
{ imageUrl: "https://cdn.example/s2.png", start: 3.2, end: 4.6, ...box },
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
describe("the layerPlan input (SP2 D6, spec §6.1)", () => {
|
|
20
|
+
it("parses a JSON string or an array of objects; anything else is invalid_layer_plan", () => {
|
|
21
|
+
expect(parseVideoOverlayLayerPlan(JSON.stringify(plan))).toEqual({ layers: plan })
|
|
22
|
+
expect(parseVideoOverlayLayerPlan(plan)).toEqual({ layers: plan })
|
|
23
|
+
expect(parseVideoOverlayLayerPlan("{")).toEqual({ error: "invalid_layer_plan" })
|
|
24
|
+
expect(parseVideoOverlayLayerPlan({ layers: plan })).toEqual({ error: "invalid_layer_plan" })
|
|
25
|
+
expect(parseVideoOverlayLayerPlan([1, 2])).toEqual({ error: "invalid_layer_plan" })
|
|
26
|
+
})
|
|
27
|
+
it("puts plan layers first, then the slot layers, and stamps planLayer", () => {
|
|
28
|
+
const req = assembleVideoOverlayRequest({
|
|
29
|
+
videoUrl: "https://cdn.example/v.mp4",
|
|
30
|
+
data: { layers: [{ preset: "corner-badge", start: 0 }] },
|
|
31
|
+
wiredImageUrls: ["https://cdn.example/logo.png"],
|
|
32
|
+
planLayers: JSON.stringify(plan),
|
|
33
|
+
})
|
|
34
|
+
expect(req.layers.map((l) => l.imageUrl)).toEqual(["https://cdn.example/s1.png", "https://cdn.example/s2.png", "https://cdn.example/logo.png"])
|
|
35
|
+
expect(req.layers[0]!.planLayer).toBe(1)
|
|
36
|
+
expect(req.layers[0]!.slot).toBeUndefined()
|
|
37
|
+
expect(req.layers[2]!.slot).toBe(1)
|
|
38
|
+
})
|
|
39
|
+
it("never fills a plan layer's image from the index-aligned handle (R18)", () => {
|
|
40
|
+
const req = assembleVideoOverlayRequest({
|
|
41
|
+
videoUrl: "https://cdn.example/v.mp4",
|
|
42
|
+
data: { layers: [] },
|
|
43
|
+
wiredImageUrls: ["https://cdn.example/handle.png"],
|
|
44
|
+
planLayers: [{ start: 1, ...box }],
|
|
45
|
+
})
|
|
46
|
+
const verdict = validateVideoOverlayRequest(req)
|
|
47
|
+
expect(verdict.ok).toBe(false)
|
|
48
|
+
if (!verdict.ok) {
|
|
49
|
+
expect(verdict.code).toBe("layer_without_image")
|
|
50
|
+
expect(formatVideoOverlayError(verdict)).toBe("Plan layer 1: no image — set imageUrl on this layer in the plan.")
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
it("a handle layer without an image keeps the handle wording", () => {
|
|
54
|
+
const verdict = validateVideoOverlayRequest({ layers: [{ start: 0, slot: 2 }] })
|
|
55
|
+
expect(verdict.ok).toBe(false)
|
|
56
|
+
if (!verdict.ok) expect(formatVideoOverlayError(verdict)).toBe("Layer 2: no image — connect one to the layer's handle or set imageUrl")
|
|
57
|
+
})
|
|
58
|
+
it("reports an unparseable plan as invalid_layer_plan", () => {
|
|
59
|
+
const req = assembleVideoOverlayRequest({ videoUrl: "https://cdn.example/v.mp4", data: { layers: [] }, wiredImageUrls: [], planLayers: "not json" })
|
|
60
|
+
const verdict = validateVideoOverlayRequest(req)
|
|
61
|
+
expect(verdict.ok ? null : verdict.code).toBe("invalid_layer_plan")
|
|
62
|
+
})
|
|
63
|
+
it("counts plan and slot layers together against the 20-layer cap", () => {
|
|
64
|
+
const many = Array.from({ length: VIDEO_OVERLAY_MAX_LAYERS }, (_, i) => ({ ...plan[0], start: i }))
|
|
65
|
+
const req = assembleVideoOverlayRequest({ videoUrl: "https://cdn.example/v.mp4", data: { layers: [{ preset: "corner-badge", start: 0 }] }, wiredImageUrls: ["https://cdn.example/logo.png"], planLayers: many })
|
|
66
|
+
const verdict = validateVideoOverlayRequest(req)
|
|
67
|
+
expect(verdict.ok ? null : verdict.code).toBe("too_many_layers")
|
|
68
|
+
})
|
|
69
|
+
it("makes a new plan read as stale", () => {
|
|
70
|
+
const base = { baseUrl: "https://cdn.example/v.mp4", sources: videoOverlaySlotSources([], []), data: { layers: [] } }
|
|
71
|
+
expect(videoOverlayCompositionKey({ ...base, planLayers: plan })).not.toBe(videoOverlayCompositionKey({ ...base, planLayers: [plan[0]] }))
|
|
72
|
+
expect(videoOverlayCompositionKey({ ...base, planLayers: plan })).toBe(videoOverlayCompositionKey({ ...base, planLayers: JSON.stringify(plan) }))
|
|
73
|
+
})
|
|
74
|
+
it("renders every plan layer under every slot layer — handle layers draw above the cards", () => {
|
|
75
|
+
const req = assembleVideoOverlayRequest({
|
|
76
|
+
videoUrl: "https://cdn.example/v.mp4",
|
|
77
|
+
data: { layers: [{ preset: "corner-badge", start: 0 }] },
|
|
78
|
+
wiredImageUrls: ["https://cdn.example/logo.png"],
|
|
79
|
+
planLayers: plan,
|
|
80
|
+
})
|
|
81
|
+
// [plan 1, plan 2, slot 1] — slot 1 (position 0) would sit under plan 2 by position alone.
|
|
82
|
+
expect(videoOverlayRenderOrder(req.layers)).toEqual([0, 1, 2])
|
|
83
|
+
expect(videoOverlayRenderOrder(req.layers.map((l, i) => ({ ...l, index: i })).reverse())).toEqual([2, 1, 0])
|
|
84
|
+
expect(videoOverlayRenderOrder([{ slot: 1 }, { planLayer: 2 }, { planLayer: 1 }])).toEqual([2, 1, 0])
|
|
85
|
+
// An explicit zIndex on a plan layer is respected.
|
|
86
|
+
expect(videoOverlayRenderOrder([{ slot: 1 }, { planLayer: 1, zIndex: 50 }])).toEqual([0, 1])
|
|
87
|
+
})
|
|
88
|
+
it("an absent plan changes nothing: the request and the key are today's", () => {
|
|
89
|
+
const base = { baseUrl: "https://cdn.example/v.mp4", sources: videoOverlaySlotSources([], []), data: { layers: [] } }
|
|
90
|
+
expect(videoOverlayCompositionKey(base)).toBe(videoOverlayCompositionKey({ ...base, planLayers: undefined }))
|
|
91
|
+
expect(JSON.parse(videoOverlayCompositionKey(base))).toHaveLength(6)
|
|
92
|
+
expect(assembleVideoOverlayRequest({ videoUrl: "v", data: { layers: [] }, wiredImageUrls: [] }).planError).toBeUndefined()
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { parseCaptionPlan, type CaptionPlan } from "./caption-plan.js"
|
|
2
|
+
import { captionSegmentInputSchema, findSegmentOverlap } from "./caption-segment-schema.js"
|
|
3
|
+
|
|
4
|
+
/** The styling half, injected so this package never imports @nodaro/prompts (each engine passes hookPlateCaptionSegments). */
|
|
5
|
+
export interface CaptionPlanStyler {
|
|
6
|
+
readonly segmentsFor: (
|
|
7
|
+
plan: CaptionPlan,
|
|
8
|
+
opts?: { bodyLevers?: Readonly<Record<string, unknown>> },
|
|
9
|
+
) => { segments: Record<string, unknown>[]; dropped: readonly string[] }
|
|
10
|
+
readonly leverKeys: readonly string[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The node's own caption levers (set, non-null) — the body's style. Undefined when it sets none (the helper then applies Body Captions). */
|
|
14
|
+
export function captionPlanBodyLevers(
|
|
15
|
+
nodeData: Readonly<Record<string, unknown>>,
|
|
16
|
+
leverKeys: readonly string[],
|
|
17
|
+
): Record<string, unknown> | undefined {
|
|
18
|
+
const levers: Record<string, unknown> = {}
|
|
19
|
+
for (const k of leverKeys) {
|
|
20
|
+
const v = nodeData[k]
|
|
21
|
+
if (v !== undefined && v !== null) levers[k] = v
|
|
22
|
+
}
|
|
23
|
+
return Object.keys(levers).length > 0 ? levers : undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A wired caption plan → the timed segments of ONE add-captions request, checked
|
|
28
|
+
* with the route's own segment schema and overlap rule (a DAG payload never
|
|
29
|
+
* passes the route, so both engines check here, before any reservation). The
|
|
30
|
+
* plate is always Hook Plate plus the plan's language levers; the body is the
|
|
31
|
+
* node's own style (the helper's rules, SP7 §4.6.3). `segments: []` = no
|
|
32
|
+
* captions — the caller passes the video through.
|
|
33
|
+
*/
|
|
34
|
+
export function styleCaptionPlan(
|
|
35
|
+
raw: unknown,
|
|
36
|
+
nodeData: Readonly<Record<string, unknown>>,
|
|
37
|
+
styler: CaptionPlanStyler,
|
|
38
|
+
): { segments: Record<string, unknown>[] } | { error: string } {
|
|
39
|
+
const parsed = parseCaptionPlan(raw)
|
|
40
|
+
if ("error" in parsed) return { error: parsed.error }
|
|
41
|
+
const bodyLevers = captionPlanBodyLevers(nodeData, styler.leverKeys)
|
|
42
|
+
const { segments } = styler.segmentsFor(parsed.plan, bodyLevers ? { bodyLevers } : undefined)
|
|
43
|
+
for (let i = 0; i < segments.length; i++) {
|
|
44
|
+
const r = captionSegmentInputSchema.safeParse(segments[i])
|
|
45
|
+
if (!r.success) return { error: `Caption plan: segment ${i + 1}: ${r.error.issues[0]?.message ?? "invalid"}.` }
|
|
46
|
+
}
|
|
47
|
+
const overlap = findSegmentOverlap(segments as { startMs: number; endMs: number }[])
|
|
48
|
+
if (overlap) return { error: `Caption plan: ${overlap}.` }
|
|
49
|
+
return { segments }
|
|
50
|
+
}
|
package/src/caption-plan.ts
CHANGED
|
@@ -25,3 +25,48 @@ export interface CaptionPlan {
|
|
|
25
25
|
/** Primary language tag: "en", "he", … */
|
|
26
26
|
readonly language?: string
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
const nonNegative = (v: unknown): v is number => typeof v === "number" && Number.isFinite(v) && v >= 0
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A wired caption plan (object or JSON string) → the plan, or the first problem
|
|
33
|
+
* named as "Caption plan: <issue>." Only the CaptionPlan fields are kept.
|
|
34
|
+
*/
|
|
35
|
+
export function parseCaptionPlan(raw: unknown): { plan: CaptionPlan } | { error: string } {
|
|
36
|
+
let value: unknown = raw
|
|
37
|
+
if (typeof raw === "string") {
|
|
38
|
+
try { value = JSON.parse(raw) } catch { return { error: "Caption plan: not valid JSON." } }
|
|
39
|
+
}
|
|
40
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return { error: "Caption plan: not an object." }
|
|
41
|
+
const o = value as Record<string, unknown>
|
|
42
|
+
if (o.v !== 1) return { error: "Caption plan: v must be 1." }
|
|
43
|
+
if (typeof o.hookText !== "string") return { error: "Caption plan: hookText must be text." }
|
|
44
|
+
for (const f of ["hookEndMs", "bodyEndMs"] as const) {
|
|
45
|
+
if (!nonNegative(o[f])) return { error: `Caption plan: ${f} must be a non-negative number.` }
|
|
46
|
+
}
|
|
47
|
+
if (o.videoDurationMs !== undefined && !nonNegative(o.videoDurationMs)) {
|
|
48
|
+
return { error: "Caption plan: videoDurationMs must be a non-negative number." }
|
|
49
|
+
}
|
|
50
|
+
if (o.language !== undefined && typeof o.language !== "string") return { error: "Caption plan: language must be text." }
|
|
51
|
+
if (!Array.isArray(o.captions)) return { error: "Caption plan: captions must be a list." }
|
|
52
|
+
const captions: CaptionWordTiming[] = []
|
|
53
|
+
for (let i = 0; i < o.captions.length; i++) {
|
|
54
|
+
const c = o.captions[i] as Record<string, unknown> | null
|
|
55
|
+
if (!c || typeof c !== "object" || typeof c.text !== "string" || !nonNegative(c.startMs) || !nonNegative(c.endMs)) {
|
|
56
|
+
return { error: `Caption plan: captions[${i}] needs text, startMs and endMs.` }
|
|
57
|
+
}
|
|
58
|
+
if (c.endMs < c.startMs) return { error: `Caption plan: captions[${i}] ends before it starts.` }
|
|
59
|
+
captions.push({ text: c.text, startMs: c.startMs, endMs: c.endMs })
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
plan: {
|
|
63
|
+
v: 1,
|
|
64
|
+
hookText: o.hookText,
|
|
65
|
+
hookEndMs: o.hookEndMs as number,
|
|
66
|
+
bodyEndMs: o.bodyEndMs as number,
|
|
67
|
+
captions,
|
|
68
|
+
...(o.videoDurationMs !== undefined ? { videoDurationMs: o.videoDurationMs as number } : {}),
|
|
69
|
+
...(o.language !== undefined ? { language: o.language as string } : {}),
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
}
|