@nodaro/shared 3.26.0 → 3.30.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 (43) hide show
  1. package/dist/index.cjs +726 -174
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +569 -34
  4. package/dist/index.d.ts +569 -34
  5. package/dist/index.js +667 -175
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/auto-aspect-source.test.ts +372 -0
  9. package/src/__tests__/camera-switch-contract.test.ts +10 -0
  10. package/src/__tests__/collections.test.ts +10 -0
  11. package/src/__tests__/edl.test.ts +319 -4
  12. package/src/__tests__/json-kinds.test.ts +11 -1
  13. package/src/__tests__/llm-models.test.ts +120 -8
  14. package/src/__tests__/pitch-tempo-pricing.test.ts +62 -0
  15. package/src/__tests__/render-nodes.test.ts +84 -5
  16. package/src/__tests__/transcribe-preflight.test.ts +5 -0
  17. package/src/__tests__/video-depth.test.ts +146 -0
  18. package/src/__tests__/video-mask.test.ts +77 -0
  19. package/src/camera-switch-contract.ts +9 -6
  20. package/src/collections.ts +72 -2
  21. package/src/credit-estimators/index.ts +10 -0
  22. package/src/credit-estimators/pitch-tempo.ts +68 -0
  23. package/src/credit-identifiers.ts +87 -19
  24. package/src/edl.ts +143 -23
  25. package/src/fan-out-rows.ts +3 -1
  26. package/src/i18n/camera-format.ko.ts +3 -3
  27. package/src/index.ts +35 -0
  28. package/src/json-kinds.ts +11 -6
  29. package/src/llm-models.ts +87 -2
  30. package/src/mask-composite.ts +108 -0
  31. package/src/model-catalog.ts +146 -4
  32. package/src/model-constants.ts +2 -1
  33. package/src/model-tree.ts +2 -0
  34. package/src/node-mappable-fields.ts +2 -0
  35. package/src/node-runtime-keys.ts +3 -0
  36. package/src/normalize-node-params.ts +47 -4
  37. package/src/pipeline-types.ts +16 -3
  38. package/src/presentation-utils.ts +3 -2
  39. package/src/producer-types.ts +13 -0
  40. package/src/render-nodes.ts +71 -6
  41. package/src/transcribe-preflight.ts +11 -10
  42. package/src/video-depth.ts +151 -0
  43. package/src/video-mask.ts +96 -0
@@ -25,6 +25,8 @@ import {
25
25
  parseEditPlanMode,
26
26
  } from "../edit-plan-contract.js"
27
27
  import { editPlanSourceDurationSec } from "../video-duration.js"
28
+ import * as edlModule from "../edl.js"
29
+ import * as sharedIndex from "../index.js"
28
30
 
29
31
  /** A minimal valid single-camera tighten EDL: two kept spans of the master. */
30
32
  function tightenEdl(): Edl {
@@ -296,10 +298,230 @@ describe("normalizeTranscript", () => {
296
298
  expect(t.words[0]).toEqual({ text: "hi", startMs: 2, endMs: 2 })
297
299
  })
298
300
 
299
- it("never produces an inverted word (endMs >= startMs)", () => {
300
- const t = normalizeTranscript({ words: [{ text: "x", startMs: 500, endMs: 100 }] })
301
- expect(t.words[0].endMs).toBeGreaterThanOrEqual(t.words[0].startMs)
302
- expect(t.words[0].endMs).toBe(500)
301
+ // The one transcript reader (decided 2026-10-08), the Cloud plugin's
302
+ // coerceTranscript reads by the same rule, so the app and the plugin read
303
+ // one transcript the same way. Round 2 (decided 2026-10-08): a zero-width
304
+ // word is a POINT and is kept, as before; only a broken word is dropped.
305
+ it("keeps a zero-width word as a point (also one that rounds to zero width)", () => {
306
+ const t = normalizeTranscript({
307
+ words: [
308
+ { text: "point", startMs: 700, endMs: 700, speaker: "A" },
309
+ { text: "rounds-to-point", startMs: 1.6, endMs: 2.4 },
310
+ { text: "alias-point", start: 900, end: "900" },
311
+ ],
312
+ })
313
+ expect(t.words).toEqual([
314
+ { text: "rounds-to-point", startMs: 2, endMs: 2 },
315
+ { text: "point", startMs: 700, endMs: 700, speaker: "A" },
316
+ { text: "alias-point", startMs: 900, endMs: 900 },
317
+ ])
318
+ })
319
+
320
+ it("drops only a broken word: no start or end, a non-finite or negative time, or an end before its start", () => {
321
+ const t = normalizeTranscript({
322
+ words: [
323
+ { text: "inverted", startMs: 500, endMs: 100 },
324
+ { text: "negative", startMs: -100, endMs: 200 },
325
+ { text: "nan", startMs: Number.NaN, endMs: 200 },
326
+ { text: "inf", startMs: 0, endMs: Number.POSITIVE_INFINITY },
327
+ { text: "not-a-number", startMs: "soon", endMs: 300 },
328
+ { text: "no-start", endMs: 300 },
329
+ { text: "no-end", startMs: 300 },
330
+ { text: "untimed" },
331
+ null,
332
+ "word",
333
+ { text: "point", startMs: 800, endMs: 800 },
334
+ { text: "kept", startMs: 900, endMs: 1_200 },
335
+ ],
336
+ })
337
+ expect(t.words).toEqual([
338
+ { text: "point", startMs: 800, endMs: 800 },
339
+ { text: "kept", startMs: 900, endMs: 1_200 },
340
+ ])
341
+ })
342
+
343
+ it("accepts start/end as aliases of startMs/endMs (and numeric strings), startMs/endMs winning when both are given", () => {
344
+ const t = normalizeTranscript({
345
+ words: [
346
+ { text: "a", start: 100, end: 400, speaker: "A" },
347
+ { text: "b", startMs: 500, start: 9_999, endMs: 800, end: 1 },
348
+ { text: "c", start: "900", end: "1100.4" },
349
+ ],
350
+ segments: [{ start: 100, end: 1_100, text: "a b c" }],
351
+ })
352
+ expect(t.words).toEqual([
353
+ { text: "a", startMs: 100, endMs: 400, speaker: "A" },
354
+ { text: "b", startMs: 500, endMs: 800 },
355
+ { text: "c", startMs: 900, endMs: 1_100 },
356
+ ])
357
+ expect(t.segments).toEqual([{ startMs: 100, endMs: 1_100, text: "a b c" }])
358
+ })
359
+
360
+ it("sorts words by start time (a stable sort: ties keep their order)", () => {
361
+ const t = normalizeTranscript({
362
+ words: [
363
+ { text: "late", startMs: 2_000, endMs: 2_300 },
364
+ { text: "early", startMs: 100, endMs: 300 },
365
+ { text: "tie-1", startMs: 1_000, endMs: 1_100 },
366
+ { text: "tie-2", startMs: 1_000, endMs: 1_200 },
367
+ ],
368
+ })
369
+ expect(t.words.map((w) => w.text)).toEqual(["early", "tie-1", "tie-2", "late"])
370
+ })
371
+
372
+ it("reads a segment by the same rule: a point is kept, a broken one dropped", () => {
373
+ const t = normalizeTranscript({
374
+ words: [],
375
+ segments: [
376
+ { startMs: 0, endMs: 0, text: "point" },
377
+ { startMs: 400, endMs: 100, text: "inverted" },
378
+ { startMs: -5, endMs: 100, text: "negative" },
379
+ { endMs: 100, text: "no-start" },
380
+ { startMs: 100, endMs: 900, text: "kept", speaker: "A" },
381
+ ],
382
+ })
383
+ expect(t.segments).toEqual([
384
+ { startMs: 0, endMs: 0, text: "point" },
385
+ { startMs: 100, endMs: 900, text: "kept", speaker: "A" },
386
+ ])
387
+ })
388
+
389
+ it("a point word the reader keeps survives the remap when its instant is kept", () => {
390
+ const edl: Edl = {
391
+ version: 1,
392
+ clock: "master",
393
+ sources: [{ id: "m", url: "https://x/m.mp4", kind: "video", role: "master-audio" }],
394
+ segments: [{ id: "s0", inMs: 0, outMs: 1_000, video: "m" }, { id: "s1", inMs: 2_000, outMs: 3_000, video: "m" }],
395
+ }
396
+ const t = normalizeTranscript({ words: [{ text: "[laugh]", start: 2_500, end: 2_500 }, { text: "[cut]", startMs: 1_500, endMs: 1_500 }] })
397
+ expect(remapTranscriptThroughEdl(edl, t).words).toEqual([{ text: "[laugh]", startMs: 1_500, endMs: 1_500 }])
398
+ })
399
+
400
+ // P3.5 round 2 (decided 2026-10-09): Camera Switch's renamed transcript
401
+ // carries its raw label → display name map, and the reader keeps it.
402
+ describe("speakerNames (the raw → display map a renamed transcript carries)", () => {
403
+ const words = [{ text: "hi", startMs: 0, endMs: 100, speaker: "Ana" }]
404
+
405
+ it("keeps the map", () => {
406
+ const t = normalizeTranscript({ words, speakerNames: { SPEAKER_00: "Ana", SPEAKER_01: "SPEAKER_01" } })
407
+ expect(t.speakerNames).toEqual({ SPEAKER_00: "Ana", SPEAKER_01: "SPEAKER_01" })
408
+ })
409
+
410
+ it("keeps only entries whose label and name are non-empty strings", () => {
411
+ const t = normalizeTranscript({ words, speakerNames: { SPEAKER_00: "Ana", "": "Nobody", SPEAKER_01: "", SPEAKER_02: 7, SPEAKER_03: null } })
412
+ expect(t.speakerNames).toEqual({ SPEAKER_00: "Ana" })
413
+ })
414
+
415
+ it("keeps a label spelled like an Object.prototype key as an own entry, as the plugin's reader does", () => {
416
+ const t = normalizeTranscript({ words, speakerNames: JSON.parse('{"__proto__":"Ana","S1":"Bo"}') })
417
+ expect(Object.keys(t.speakerNames ?? {})).toEqual(["__proto__", "S1"])
418
+ expect(Object.getOwnPropertyDescriptor(t.speakerNames, "__proto__")?.value).toBe("Ana")
419
+ expect(Object.getPrototypeOf(t.speakerNames)).toBe(Object.prototype)
420
+ })
421
+
422
+ it("leaves the field out when there is no map, an empty one, or not a map", () => {
423
+ for (const speakerNames of [undefined, null, {}, { SPEAKER_00: "" }, ["Ana"], "Ana", 3]) {
424
+ expect("speakerNames" in normalizeTranscript({ words, speakerNames })).toBe(false)
425
+ }
426
+ })
427
+
428
+ it("survives the remap onto the rendered output", () => {
429
+ const edl: Edl = {
430
+ version: 1,
431
+ clock: "master",
432
+ sources: [{ id: "m", url: "https://x/m.mp4", kind: "video", role: "master-audio" }],
433
+ segments: [{ id: "s0", inMs: 0, outMs: 1_000, video: "m" }],
434
+ }
435
+ const t = normalizeTranscript({ words, speakerNames: { SPEAKER_00: "Ana" } })
436
+ expect(remapTranscriptThroughEdl(edl, t).speakerNames).toEqual({ SPEAKER_00: "Ana" })
437
+ })
438
+ })
439
+ })
440
+
441
+ describe("remapTranscriptThroughEdl — a word across TOUCHING segments keeps its full length (decided 2026-10-08)", () => {
442
+ const master: Edl["sources"] = [{ id: "m", url: "https://x/m.mp4", kind: "video", role: "master-audio" }]
443
+ const at = (segments: Edl["segments"]): Edl => ({ version: 1, clock: "master", sources: master, segments })
444
+ const word = (startMs: number, endMs: number): Transcript => ({ version: 1, words: [{ text: "w", startMs, endMs }] })
445
+ const only = (edl: Edl, t: Transcript) => {
446
+ const out = remapTranscriptThroughEdl(edl, t).words
447
+ expect(out).toHaveLength(1)
448
+ return { startMs: out[0].startMs, endMs: out[0].endMs }
449
+ }
450
+
451
+ it("a split in continuous master time (seg[i].outMs === seg[i+1].inMs, contiguous on the output) does not clip the word", () => {
452
+ const edl = at([
453
+ { id: "s0", inMs: 0, outMs: 5_000, video: "m" },
454
+ { id: "s1", inMs: 5_000, outMs: 9_000, video: "m" },
455
+ ])
456
+ expect(only(edl, word(4_800, 5_300))).toEqual({ startMs: 4_800, endMs: 5_300 })
457
+ })
458
+
459
+ it("the time-free switches (cut, pan, zoom) keep the output contiguous, so the word stays whole", () => {
460
+ for (const layoutTransition of [{ type: "cut" }, { type: "pan", durationMs: 500 }, { type: "zoom", durationMs: 300 }]) {
461
+ const edl = at([
462
+ { id: "s0", inMs: 0, outMs: 5_000, video: "m", layout: { mode: "single" } },
463
+ { id: "s1", inMs: 5_000, outMs: 9_000, video: "m", layout: { mode: "single", transition: layoutTransition } },
464
+ ])
465
+ expect(only(edl, word(4_800, 5_300)), layoutTransition.type).toEqual({ startMs: 4_800, endMs: 5_300 })
466
+ }
467
+ const segCut = at([
468
+ { id: "s0", inMs: 0, outMs: 5_000, video: "m" },
469
+ { id: "s1", inMs: 5_000, outMs: 9_000, video: "m", transition: { type: "cut" } },
470
+ ])
471
+ expect(only(segCut, word(4_800, 5_300))).toEqual({ startMs: 4_800, endMs: 5_300 })
472
+ })
473
+
474
+ it("an overlap INTO the next segment (crossfade, xfade:*) breaks output contiguity: the word is clipped to its first kept part, as before", () => {
475
+ const crossfade = at([
476
+ { id: "s0", inMs: 0, outMs: 5_000, video: "m" },
477
+ { id: "s1", inMs: 5_000, outMs: 9_000, video: "m", transition: { type: "crossfade", durationMs: 400 } },
478
+ ])
479
+ expect(only(crossfade, word(4_800, 5_300))).toEqual({ startMs: 4_800, endMs: 5_000 })
480
+ const xfade = at([
481
+ { id: "s0", inMs: 0, outMs: 5_000, video: "m", layout: { mode: "single" } },
482
+ { id: "s1", inMs: 5_000, outMs: 9_000, video: "m", layout: { mode: "single", transition: { type: "xfade:wipe-left", durationMs: 400 } } },
483
+ ])
484
+ expect(only(xfade, word(4_800, 5_300))).toEqual({ startMs: 4_800, endMs: 5_000 })
485
+ })
486
+
487
+ it("runs across a chain of touching segments", () => {
488
+ const edl = at([
489
+ { id: "s0", inMs: 0, outMs: 1_000, video: "m" },
490
+ { id: "s1", inMs: 1_000, outMs: 2_000, video: "m" },
491
+ { id: "s2", inMs: 2_000, outMs: 3_000, video: "m" },
492
+ ])
493
+ expect(only(edl, word(500, 2_500))).toEqual({ startMs: 500, endMs: 2_500 })
494
+ })
495
+
496
+ it("stops at a real cut: across a touching boundary, then clipped where the master clock jumps", () => {
497
+ const edl = at([
498
+ { id: "s0", inMs: 0, outMs: 5_000, video: "m" },
499
+ { id: "s1", inMs: 5_000, outMs: 6_000, video: "m" },
500
+ { id: "s2", inMs: 8_000, outMs: 12_000, video: "m" },
501
+ ])
502
+ expect(only(edl, word(4_800, 8_300))).toEqual({ startMs: 4_800, endMs: 6_000 })
503
+ })
504
+
505
+ it("touching means the NEXT segment in the list: a later segment that happens to resume the master clock does not extend the word", () => {
506
+ const edl = at([
507
+ { id: "s0", inMs: 5_000, outMs: 8_000, video: "m" },
508
+ { id: "s1", inMs: 0, outMs: 5_000, video: "m" },
509
+ ])
510
+ // The first kept part is in s0 (output 0..3000): 5_000..5_200 → 0..200.
511
+ expect(only(edl, word(4_800, 5_200))).toEqual({ startMs: 0, endMs: 200 })
512
+ })
513
+
514
+ it("applies the source offset before testing the boundary", () => {
515
+ const edl: Edl = {
516
+ version: 1,
517
+ clock: "master",
518
+ sources: [...master, { id: "cam", url: "https://x/c.mp4", kind: "video", offsetMs: 1_000 }],
519
+ segments: [
520
+ { id: "s0", inMs: 0, outMs: 5_000, video: "m" },
521
+ { id: "s1", inMs: 5_000, outMs: 9_000, video: "m" },
522
+ ],
523
+ }
524
+ expect(only(edl, { ...word(3_800, 4_300), sourceId: "cam" })).toEqual({ startMs: 4_800, endMs: 5_300 })
303
525
  })
304
526
  })
305
527
 
@@ -854,3 +1076,96 @@ describe("validateEdl — warnings (registry class; ok stays true)", () => {
854
1076
  expect(r.warnings).toEqual([expect.stringMatching(/^clip\[1\]: segment\[1\] "s1": unknown layout mode "carousel"/)])
855
1077
  })
856
1078
  })
1079
+
1080
+ describe("slots[].follow — what a tracked slot followed (P3-8, decided 2026-10-06)", () => {
1081
+ /** Two cameras, one side-by-side segment whose first slot follows a track. */
1082
+ function followEdl(follow: unknown, slotSource = "camA"): Edl {
1083
+ return {
1084
+ version: 1,
1085
+ clock: "master",
1086
+ sources: [
1087
+ { id: "mic", url: "m", kind: "audio", role: "master-audio" },
1088
+ { id: "camA", url: "a", kind: "video" },
1089
+ { id: "camB", url: "b", kind: "video" },
1090
+ ],
1091
+ segments: [
1092
+ {
1093
+ id: "s0",
1094
+ inMs: 0,
1095
+ outMs: 1000,
1096
+ video: "camA",
1097
+ layout: {
1098
+ mode: "side-by-side",
1099
+ slots: [
1100
+ { source: slotSource, speaker: "Host", region: { x: 0.1, y: 0, w: 0.4, h: 1 }, follow } as never,
1101
+ { source: "camB", speaker: "Guest" },
1102
+ ],
1103
+ },
1104
+ },
1105
+ ],
1106
+ }
1107
+ }
1108
+
1109
+ it("accepts a follow on the slot's own video source", () => {
1110
+ const r = validateEdl(followEdl({ sourceId: "camA", trackId: "camA/t3", motion: "glide" }))
1111
+ expect(r.issues).toEqual([])
1112
+ expect(r.ok).toBe(true)
1113
+ })
1114
+
1115
+ it("accepts motion static", () => {
1116
+ expect(validateEdl(followEdl({ sourceId: "camA", trackId: "camA/t3", motion: "static" })).ok).toBe(true)
1117
+ })
1118
+
1119
+ it("refuses a follow naming a source other than the slot's — the crop is on the slot's frame", () => {
1120
+ const r = validateEdl(followEdl({ sourceId: "camB", trackId: "camB/t1", motion: "glide" }))
1121
+ expect(r.issues.join("\n")).toMatch(/follow\.sourceId "camB" is not the slot's source "camA"/)
1122
+ })
1123
+
1124
+ it("refuses an empty trackId and an unknown motion", () => {
1125
+ const r = validateEdl(followEdl({ sourceId: "camA", trackId: "", motion: "orbit" }))
1126
+ const text = r.issues.join("\n")
1127
+ expect(text).toMatch(/follow\.trackId is empty/)
1128
+ expect(text).toMatch(/follow\.motion "orbit" is not one of static, glide/)
1129
+ })
1130
+
1131
+ it("normalizeEdl carries a well-formed follow through, unchanged", () => {
1132
+ const follow = { sourceId: "camA", trackId: "camA/t3", motion: "glide" }
1133
+ const n = normalizeEdl(followEdl(follow))
1134
+ expect(n.segments[0].layout?.slots?.[0]).toEqual({ source: "camA", region: { x: 0.1, y: 0, w: 0.4, h: 1 }, speaker: "Host", follow })
1135
+ expect(n.segments[0].layout?.slots?.[1]).toEqual({ source: "camB", speaker: "Guest" })
1136
+ expect(validateEdl(n).ok).toBe(true)
1137
+ })
1138
+
1139
+ it("normalizeEdl drops only unknown keys inside follow", () => {
1140
+ const n = normalizeEdl(followEdl({ sourceId: "camA", trackId: "camA/t3", motion: "static", extra: 1 }))
1141
+ expect(n.segments[0].layout?.slots?.[0]?.follow).toEqual({ sourceId: "camA", trackId: "camA/t3", motion: "static" })
1142
+ })
1143
+
1144
+ it("normalizeEdl drops a malformed follow rather than guessing it — an unknown motion is never coerced", () => {
1145
+ for (const bad of [
1146
+ { sourceId: "camA", trackId: "camA/t3", motion: "orbit" },
1147
+ { sourceId: "camA", trackId: "camA/t3" },
1148
+ { sourceId: "camA", motion: "glide" },
1149
+ { trackId: "camA/t3", motion: "glide" },
1150
+ { sourceId: "camA", trackId: "", motion: "glide" },
1151
+ { sourceId: 3, trackId: "camA/t3", motion: "glide" },
1152
+ "camA/t3",
1153
+ null,
1154
+ ]) {
1155
+ const slot = normalizeEdl(followEdl(bad)).segments[0].layout?.slots?.[0]
1156
+ expect(slot, JSON.stringify(bad)).toBeDefined()
1157
+ expect(slot && "follow" in slot, JSON.stringify(bad)).toBe(false)
1158
+ }
1159
+ })
1160
+
1161
+ it("adds types only — no runtime export (keeps the Apache grant minimal, decided 2026-10-09)", () => {
1162
+ const followExports = (m: object) => Object.keys(m).filter((k) => /FOLLOW/i.test(k))
1163
+ expect(followExports(edlModule)).toEqual([])
1164
+ expect(followExports(sharedIndex)).toEqual([])
1165
+ })
1166
+
1167
+ it("a slot without follow normalizes exactly as before (the field is additive)", () => {
1168
+ const n = normalizeEdl(followEdl(undefined))
1169
+ expect(n.segments[0].layout?.slots?.[0]).toEqual({ source: "camA", region: { x: 0.1, y: 0, w: 0.4, h: 1 }, speaker: "Host" })
1170
+ })
1171
+ })
@@ -156,9 +156,19 @@ describe("declaredJsonOutput — every JSON pip is classified (decided 2026-10-0
156
156
  expect(jsonKindMismatch("silence-detect", "json", "apply-edl", "edl")).toBeNull()
157
157
  })
158
158
 
159
- it("answers a render's json from the registry and nothing else on a render", () => {
159
+ it("answers a render's json and transcript pips from the registry and nothing else on a render", () => {
160
160
  expect(declaredJsonOutput("speaker-view", "json")).toBe("edl")
161
161
  expect(declaredJsonOutput("speaker-view", "video")).toBeUndefined()
162
+ // Speaker View's second output (decided 2026-10-08): the remapped transcript
163
+ expect(declaredJsonOutput("speaker-view", "transcript")).toBe("transcript")
164
+ expect(declaredJsonOutput("apply-edl", "transcript")).toBeUndefined()
165
+ expect(declaredJsonOutput("apply-edl", "media")).toBeUndefined()
166
+ })
167
+
168
+ it("Speaker View's transcript feeds a Transcript input and is blocked from an EDL input; its json the reverse", () => {
169
+ expect(jsonKindMismatch("speaker-view", "transcript", "add-captions", "transcript")).toBeNull()
170
+ expect(jsonKindMismatch("speaker-view", "transcript", "apply-edl", "edl")).toEqual({ output: "transcript", input: "edl" })
171
+ expect(jsonKindMismatch("speaker-view", "json", "add-captions", "transcript")).toEqual({ output: "edl", input: "transcript" })
162
172
  })
163
173
 
164
174
  it("is undefined for anything undeclared, and never reads inherited keys", () => {
@@ -2,6 +2,8 @@ import {
2
2
  LLM_MODELS,
3
3
  LLM_MODEL_IDS,
4
4
  LLM_FEATURE_DEFAULTS,
5
+ LLM_FEATURE_DEFAULT_EFFORTS,
6
+ defaultReasoningEffort,
5
7
  STRUCTURED_VISION_MODELS,
6
8
  LLM_REASONING_EFFORTS,
7
9
  getLlmModel,
@@ -25,7 +27,7 @@ import {
25
27
  LLM_CREDIT_RUNGS,
26
28
  } from "../llm-models.js"
27
29
  import type { LlmModelDef, LlmTier, LlmFeature } from "../llm-models.js"
28
- import { PIPELINE_PINNABLE_SCRIPT_LLMS } from "../pipeline-types.js"
30
+ import { PIPELINE_ACCEPTED_SCRIPT_LLMS, PIPELINE_LEGACY_PINNED_SCRIPT_LLMS, PIPELINE_PINNABLE_SCRIPT_LLMS, PipelineConfigSchema } from "../pipeline-types.js"
29
31
 
30
32
  // The provider-$ per-token rate table and `calculateLlmCost` moved to
31
33
  // backend/src/lib/pricing/llm-cost.ts (S5) — its tests live in
@@ -42,6 +44,7 @@ const EXPECTED_MODEL_IDS = [
42
44
  "gemini-3.7-flash",
43
45
  "gemini-3.8-flash",
44
46
  "claude-haiku-4.5",
47
+ "claude-haiku-5.5",
45
48
  "claude-sonnet-4.6",
46
49
  "gpt-5.2",
47
50
  "gemini-3.1-pro",
@@ -114,7 +117,7 @@ describe("LLM_MODELS data integrity", () => {
114
117
  for (const model of LLM_MODELS) {
115
118
  tierCounts[model.tier]++
116
119
  }
117
- expect(tierCounts.economy).toBe(8)
120
+ expect(tierCounts.economy).toBe(9)
118
121
  expect(tierCounts.standard).toBe(7)
119
122
  expect(tierCounts.premium).toBe(13)
120
123
  })
@@ -175,12 +178,24 @@ describe("getLlmModel", () => {
175
178
  expect(getLlmModel("claude-haiku-4-5")?.id).toBe("claude-haiku-4.5")
176
179
  })
177
180
 
178
- it("resolves every PIPELINE_PINNABLE_SCRIPT_LLMS member (the film pipeline's pin surface)", () => {
179
- for (const id of PIPELINE_PINNABLE_SCRIPT_LLMS) {
181
+ it("resolves every script LLM a pipeline config may name (the film pipeline's pin surface)", () => {
182
+ for (const id of PIPELINE_ACCEPTED_SCRIPT_LLMS) {
180
183
  expect(getLlmModel(id), `pinnable script llm ${id} must resolve`).toBeDefined()
181
184
  }
182
185
  })
183
186
 
187
+ it("Claude Haiku 5.5 is the offered Haiku pin; a saved Haiku 4.5 pin is still accepted", () => {
188
+ expect(PIPELINE_PINNABLE_SCRIPT_LLMS).toContain("claude-haiku-5-5")
189
+ expect(PIPELINE_PINNABLE_SCRIPT_LLMS).not.toContain("claude-haiku-4-5")
190
+ expect(PIPELINE_LEGACY_PINNED_SCRIPT_LLMS).toEqual(["claude-haiku-4-5"])
191
+ expect(getLlmModel("claude-haiku-5-5")?.id).toBe("claude-haiku-5.5")
192
+ for (const id of ["claude-haiku-5-5", "claude-haiku-4-5"] as const) {
193
+ expect(PipelineConfigSchema.safeParse({ script_llm: id }).success, id).toBe(true)
194
+ expect(PipelineConfigSchema.safeParse({ stage_models: { script_llm: id } }).success, `stage ${id}`).toBe(true)
195
+ }
196
+ expect(PipelineConfigSchema.safeParse({ script_llm: "claude-haiku-3" }).success).toBe(false)
197
+ })
198
+
184
199
  it("resolves provider slugs as historical aliases", () => {
185
200
  const dated = LLM_MODELS.find((m) => m.directFallbackModel && m.directFallbackModel !== m.id)
186
201
  if (dated) expect(getLlmModel(dated.directFallbackModel!)?.id).toBe(dated.id)
@@ -239,6 +254,7 @@ describe("getLlmTier", () => {
239
254
  it.each([
240
255
  ["gemini-3-flash", "economy"],
241
256
  ["claude-haiku-4.5", "economy"],
257
+ ["claude-haiku-5.5", "economy"],
242
258
  ] as const)("%s -> %s", (id, expected) => {
243
259
  expect(getLlmTier(id)).toBe(expected)
244
260
  })
@@ -476,6 +492,52 @@ describe("LLM_FEATURE_DEFAULTS", () => {
476
492
  })
477
493
  })
478
494
 
495
+ // ---------------------------------------------------------------------------
496
+ // defaultReasoningEffort — a feature's default effort rides its default model
497
+ // ---------------------------------------------------------------------------
498
+ describe("defaultReasoningEffort", () => {
499
+ it('"describe-to-picker" runs at "high" on its default model, named or omitted (decided 2026-10-09)', () => {
500
+ expect(defaultReasoningEffort("describe-to-picker", undefined)).toBe("high")
501
+ expect(defaultReasoningEffort("describe-to-picker", "claude-opus-5.5")).toBe("high")
502
+ // An unset model in node data can be "" — the same "use the default" the
503
+ // `llmModel || LLM_FEATURE_DEFAULTS[…]` reads give it.
504
+ expect(defaultReasoningEffort("describe-to-picker", "")).toBe("high")
505
+ })
506
+
507
+ it("names the default model by any of its accepted ids", () => {
508
+ // The dash alias getLlmModel resolves to the canonical claude-opus-5.5.
509
+ expect(defaultReasoningEffort("describe-to-picker", "claude-opus-5-5")).toBe("high")
510
+ })
511
+
512
+ it("a caller who picked another model and no effort keeps that model's Auto", () => {
513
+ expect(defaultReasoningEffort("describe-to-picker", "gemini-3.8-flash")).toBeUndefined()
514
+ expect(defaultReasoningEffort("describe-to-picker", "claude-opus-5")).toBeUndefined()
515
+ })
516
+
517
+ it("a feature with no default effort, or an unknown feature, has none", () => {
518
+ expect(defaultReasoningEffort("llm-chat", undefined)).toBeUndefined()
519
+ expect(defaultReasoningEffort("llm-chat", LLM_FEATURE_DEFAULTS["llm-chat"])).toBeUndefined()
520
+ expect(defaultReasoningEffort("no-such-feature", undefined)).toBeUndefined()
521
+ })
522
+
523
+ it("every declared default effort is a level its default model offers, on the aggregator lane and direct", () => {
524
+ // The effort pickers show this level as selected — one the model does not
525
+ // offer would leave them blank (and the quick strip's fail-safe snapping).
526
+ for (const [feature, effort] of Object.entries(LLM_FEATURE_DEFAULT_EFFORTS)) {
527
+ const model = LLM_FEATURE_DEFAULTS[feature as LlmFeature]
528
+ expect(availableReasoningEfforts(model), feature).toContain(effort)
529
+ expect(availableReasoningEfforts(model, true), feature).toContain(effort)
530
+ }
531
+ })
532
+
533
+ it("the describe-to-picker default runs and bills direct: Opus 5.5's effort only works on Anthropic's API", () => {
534
+ const model = LLM_FEATURE_DEFAULTS["describe-to-picker"]
535
+ const effort = defaultReasoningEffort("describe-to-picker", model)
536
+ expect(llmServesDirect(model, effort)).toBe(true)
537
+ expect(buildLlmCreditIdentifier("describe-to-picker", model, effort)).toBe("describe-to-picker:premium-direct")
538
+ })
539
+ })
540
+
479
541
  // ---------------------------------------------------------------------------
480
542
  // motionGraphicsFeature
481
543
  // ---------------------------------------------------------------------------
@@ -500,6 +562,8 @@ describe("STRUCTURED_VISION_MODELS", () => {
500
562
  expect(ids).toEqual(
501
563
  [
502
564
  "claude-haiku-4.5",
565
+ // Vision + a forced tool both live-probed 2026-10-10 (KIE and direct).
566
+ "claude-haiku-5.5",
503
567
  "claude-opus-4.7",
504
568
  "claude-sonnet-4.6",
505
569
  "gemini-3-flash",
@@ -597,6 +661,41 @@ describe("reasoning effort registry", () => {
597
661
  expect(m?.thinkingDefaultOn).toBe(true)
598
662
  })
599
663
 
664
+ it("claude-haiku-5.5 is the economy Claude with an effort ladder that reasons by default", () => {
665
+ const m = getLlmModel("claude-haiku-5.5")!
666
+ expect(m.tier).toBe("economy")
667
+ expect(m.kieFormat).toBe("messages")
668
+ expect(m.kieSlugOrModel).toBe("claude-haiku-5-5")
669
+ expect(m.directFallbackModel).toBe("claude-haiku-5-5")
670
+ expect(m.reasoningEfforts).toEqual(["low", "medium", "high", "xhigh", "max"])
671
+ expect(m.effortRequiresDirect).toBe(true)
672
+ expect(m.preferKie).toBe(true)
673
+ // Anthropic 400s `temperature` on this model (probed 2026-10-10).
674
+ expect(m.supportsTemperature).toBe(false)
675
+ // Load-bearing: measured 2026-10-10, a no-effort call spent ~2,000 output
676
+ // tokens on a ~350-token answer on BOTH lanes. Unflagged, a node's small
677
+ // cap (qa-check's 1,024) is eaten by reasoning and the answer is cut.
678
+ expect(m.thinkingDefaultOn).toBe(true)
679
+ expect(reasoningOutputFloor(m)).toBe(REASONING_OUTPUT_FLOOR)
680
+ expect(getLlmModalityCaps(m.id)).toEqual({ image: true, video: false, audio: false })
681
+ // Haiku 4.5 stays as it was: no ladder, no default reasoning, its own cap.
682
+ const old = getLlmModel("claude-haiku-4.5")!
683
+ expect(old.reasoningEfforts).toBeUndefined()
684
+ expect(old.thinkingDefaultOn).toBeUndefined()
685
+ expect(old.maxOutputTokens).toBe(8192)
686
+ })
687
+
688
+ it("every model whose thinking cannot be turned off carries thinkingDefaultOn", () => {
689
+ // Vendor docs: Claude Fable 5 always has thinking enabled, and Claude Opus
690
+ // 5.5 rejects `disabled` at every effort. Nothing in the registry says
691
+ // "cannot be turned off", so the list is pinned here. Consumers floor
692
+ // max_tokens off this flag; unflagged, such a model's reasoning shares the
693
+ // plain 16384 cap with its answer on every call.
694
+ for (const id of ["claude-fable-5", "claude-opus-5.5"]) {
695
+ expect(getLlmModel(id)?.thinkingDefaultOn, id).toBe(true)
696
+ }
697
+ })
698
+
600
699
  it("thinkingDefaultOn is set only where the vendor default actually reasons", () => {
601
700
  // Opus 4.8 / 4.7 and Sonnet 5 do NOT reason when `thinking` is omitted —
602
701
  // flagging them would inflate every call's cap for no reason.
@@ -946,6 +1045,14 @@ describe("advanced mode", () => {
946
1045
  expect(buildLlmCreditIdentifier("llm-chat", "claude-sonnet-5.5", "low")).toBe("llm-chat:premium")
947
1046
  expect(buildLlmCreditIdentifier("llm-chat", "claude-sonnet-5.5", "xhigh")).toBe("llm-chat:premium-direct")
948
1047
  expect(buildLlmCreditIdentifier("llm-chat", "claude-haiku-4.5", "xhigh")).toBe("llm-chat:economy") // no ladder
1048
+ // Haiku 5.5 is the economy Claude WITH a ladder: no effort stays economy on
1049
+ // KIE, any effort runs direct (one rung), and xhigh/max stack the effort bump.
1050
+ expect(buildLlmCreditIdentifier("llm-chat", "claude-haiku-5.5")).toBe("llm-chat:economy")
1051
+ expect(buildLlmCreditIdentifier("llm-chat", "claude-haiku-5.5", "low")).toBe("llm-chat")
1052
+ expect(buildLlmCreditIdentifier("llm-chat", "claude-haiku-5.5", "high")).toBe("llm-chat")
1053
+ expect(buildLlmCreditIdentifier("llm-chat", "claude-haiku-5.5", "xhigh")).toBe("llm-chat:premium")
1054
+ expect(buildLlmCreditIdentifier("llm-chat", "claude-haiku-5.5", "max")).toBe("llm-chat:premium")
1055
+ expect(buildLlmCreditIdentifier("llm-chat", "claude-haiku-5.5", undefined, true)).toBe("llm-chat")
949
1056
  })
950
1057
 
951
1058
  it("a premium model served direct lands on premium-direct, and nothing goes past it", () => {
@@ -1087,11 +1194,13 @@ describe("groupLlmModelsByVendor / orderedLlmModels", () => {
1087
1194
  // Forced tool choice + conversation-bound thinking (Claude 5.5 generation)
1088
1195
  // ---------------------------------------------------------------------------
1089
1196
  describe("supportsForcedToolChoice / conversationBoundThinking", () => {
1090
- it("are declared exactly on the Claude 5.5 models", () => {
1197
+ it("are declared exactly on the Claude 5.5 models — Haiku 5.5 binds its thinking but still takes a forced tool", () => {
1091
1198
  const noForce = LLM_MODELS.filter((m) => m.supportsForcedToolChoice === false).map((m) => m.id)
1092
1199
  const bound = LLM_MODELS.filter((m) => m.conversationBoundThinking).map((m) => m.id)
1200
+ // Haiku 5.5 is NOT here: Anthropic's API served it a forced tool_choice
1201
+ // (probed 2026-10-10), where Sonnet 5.5 and Opus 5.5 answer 400.
1093
1202
  expect(noForce.sort()).toEqual(["claude-opus-5.5", "claude-sonnet-5.5"])
1094
- expect(bound.sort()).toEqual(["claude-opus-5.5", "claude-sonnet-5.5"])
1203
+ expect(bound.sort()).toEqual(["claude-haiku-5.5", "claude-opus-5.5", "claude-sonnet-5.5"])
1095
1204
  })
1096
1205
 
1097
1206
  it("only an anthropic-tool model can decline a forced tool choice (the flag has no reader elsewhere)", () => {
@@ -1110,7 +1219,7 @@ describe("supportsForcedToolChoice / conversationBoundThinking", () => {
1110
1219
  // through PIPELINE_PINNABLE_SCRIPT_LLMS. A model that 400s on forcing must not
1111
1220
  // join that list until callLLM reads `supportsForcedToolChoice`.
1112
1221
  it("no pipeline-pinnable script LLM rejects a forced tool choice", () => {
1113
- for (const id of PIPELINE_PINNABLE_SCRIPT_LLMS) {
1222
+ for (const id of PIPELINE_ACCEPTED_SCRIPT_LLMS) {
1114
1223
  expect(getLlmModel(id)?.supportsForcedToolChoice, id).not.toBe(false)
1115
1224
  }
1116
1225
  })
@@ -1118,6 +1227,7 @@ describe("supportsForcedToolChoice / conversationBoundThinking", () => {
1118
1227
  it("resolves the KIE / Anthropic dash-form ids of the new models", () => {
1119
1228
  expect(getLlmModel("claude-opus-5-5")?.id).toBe("claude-opus-5.5")
1120
1229
  expect(getLlmModel("claude-sonnet-5-5")?.id).toBe("claude-sonnet-5.5")
1230
+ expect(getLlmModel("claude-haiku-5-5")?.id).toBe("claude-haiku-5.5")
1121
1231
  expect(getLlmModel("gpt-6-1-sol")?.id).toBe("gpt-6.1-sol")
1122
1232
  expect(getLlmModel("deepseek-v4-1-flash")?.id).toBe("deepseek-v4.1-flash")
1123
1233
  expect(getLlmModel("grok-4-7")?.id).toBe("grok-4.7")
@@ -1134,8 +1244,10 @@ describe("llmServesDirect (decided 2026-10-08: priced on the lane it runs on)",
1134
1244
  expect(llmServesDirect("claude-opus-5.5", "low")).toBe(true)
1135
1245
  expect(llmServesDirect("gemini-3.6-flash", "high")).toBe(false)
1136
1246
  expect(llmServesDirect("gpt-6-sol", "max")).toBe(false)
1137
- // Haiku has no effort ladder: an effort clamps to nothing, so it stays on KIE.
1247
+ // Haiku 4.5 has no effort ladder: an effort clamps to nothing, so it stays on KIE.
1138
1248
  expect(llmServesDirect("claude-haiku-4.5", "high")).toBe(false)
1249
+ // Haiku 5.5 has one, and KIE ignores it like every other Claude effort.
1250
+ expect(llmServesDirect("claude-haiku-5.5", "low")).toBe(true)
1139
1251
  })
1140
1252
  it("no effort and no Advanced: every model runs on the aggregator", () => {
1141
1253
  for (const m of LLM_MODELS) expect(llmServesDirect(m.id), m.id).toBe(false)
@@ -0,0 +1,62 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import {
3
+ PITCH_TEMPO_PRICING,
4
+ parsePitchTempoCreditId,
5
+ pitchTempoBaseCredits,
6
+ pitchTempoCreditId,
7
+ pitchTempoStartedMinutes,
8
+ semitonesToPitchRatio,
9
+ } from "../credit-estimators/pitch-tempo.js"
10
+
11
+ const RATE = PITCH_TEMPO_PRICING.CREDITS_PER_MINUTE_DEFAULT
12
+
13
+ describe("pitch-tempo pricing", () => {
14
+ // The worked examples in docs/nodes/processing-audio/pitch-tempo.md.
15
+ it.each([
16
+ [45, 20],
17
+ [60, 20],
18
+ [61, 40],
19
+ [190, 80],
20
+ [1800, 600],
21
+ ])("%ss of input costs %s credits at the default rate", (sec, credits) => {
22
+ expect(pitchTempoBaseCredits(RATE, pitchTempoStartedMinutes(sec))).toBe(credits)
23
+ })
24
+
25
+ it("prices an unknown or non-positive length as one minute", () => {
26
+ expect(pitchTempoStartedMinutes(undefined)).toBe(1)
27
+ expect(pitchTempoStartedMinutes(null)).toBe(1)
28
+ expect(pitchTempoStartedMinutes(0)).toBe(1)
29
+ expect(pitchTempoStartedMinutes(Number.NaN)).toBe(1)
30
+ })
31
+
32
+ it("clamps the minutes at the 30-minute cap (the route refuses longer input)", () => {
33
+ expect(pitchTempoStartedMinutes(1800.4)).toBe(30)
34
+ expect(pitchTempoStartedMinutes(5000)).toBe(30)
35
+ })
36
+
37
+ it("builds and parses the per-minute id", () => {
38
+ expect(pitchTempoCreditId(190)).toBe("pitch-tempo:4m")
39
+ expect(pitchTempoCreditId(undefined)).toBe("pitch-tempo:1m")
40
+ expect(parsePitchTempoCreditId("pitch-tempo:4m")).toEqual({ minutes: 4 })
41
+ expect(parsePitchTempoCreditId(pitchTempoCreditId(1800))).toEqual({ minutes: 30 })
42
+ })
43
+
44
+ it.each(["pitch-tempo", "pitch-tempo:0m", "pitch-tempo:31m", "pitch-tempo:2.5m", "edit-plan:tighten:economy:3m"])(
45
+ "does not read %s as a per-minute id",
46
+ (id) => {
47
+ expect(parsePitchTempoCreditId(id)).toBeUndefined()
48
+ },
49
+ )
50
+
51
+ it("never charges less than one credit and rounds up", () => {
52
+ expect(pitchTempoBaseCredits(0, 3)).toBe(1)
53
+ expect(pitchTempoBaseCredits(2.5, 3)).toBe(8)
54
+ })
55
+
56
+ it("converts semitones to a frequency ratio", () => {
57
+ expect(semitonesToPitchRatio(0)).toBe(1)
58
+ expect(semitonesToPitchRatio(12)).toBeCloseTo(2, 10)
59
+ expect(semitonesToPitchRatio(-12)).toBeCloseTo(0.5, 10)
60
+ expect(semitonesToPitchRatio(3)).toBeCloseTo(1.189207, 6)
61
+ })
62
+ })