@nodaro/shared 3.24.0 → 3.25.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 (37) hide show
  1. package/dist/index.cjs +595 -128
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +375 -48
  4. package/dist/index.d.ts +375 -48
  5. package/dist/index.js +553 -129
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/credit-identifiers.test.ts +19 -6
  9. package/src/__tests__/dialogue-capabilities.test.ts +3 -2
  10. package/src/__tests__/edit-plan-minute-ids.test.ts +82 -0
  11. package/src/__tests__/json-kinds.test.ts +179 -0
  12. package/src/__tests__/presentation-utils.test.ts +1 -0
  13. package/src/__tests__/preview-gate.test.ts +2 -2
  14. package/src/__tests__/pricing-default-duration.test.ts +56 -15
  15. package/src/__tests__/private-host.test.ts +24 -0
  16. package/src/__tests__/render-nodes.test.ts +22 -3
  17. package/src/__tests__/tts-capabilities.test.ts +61 -1
  18. package/src/__tests__/video-link-input.test.ts +148 -0
  19. package/src/__tests__/video-link-needs.test.ts +67 -0
  20. package/src/__tests__/video-request-normalize.test.ts +18 -3
  21. package/src/credit-identifiers.ts +48 -37
  22. package/src/edit-plan-contract.ts +67 -1
  23. package/src/fan-out-rows.ts +2 -2
  24. package/src/index.ts +45 -1
  25. package/src/json-kinds.ts +188 -0
  26. package/src/model-catalog.ts +121 -8
  27. package/src/model-constants.ts +68 -42
  28. package/src/node-default-mappings.ts +1 -0
  29. package/src/pipeline-types.ts +13 -2
  30. package/src/presentation-utils.ts +8 -1
  31. package/src/private-host.ts +91 -0
  32. package/src/producer-types.ts +3 -0
  33. package/src/render-nodes.ts +12 -1
  34. package/src/scene-node-types.ts +17 -5
  35. package/src/social-post-readers.ts +37 -0
  36. package/src/video-link.ts +238 -0
  37. package/src/voices.ts +16 -9
@@ -0,0 +1,188 @@
1
+ /**
2
+ * What a JSON pip CARRIES — the handle typing behind "an EDL is not a
3
+ * transcript" (decided 2026-10-07) and its reverse, "a transcript is not an
4
+ * EDL" (decided 2026-10-08).
5
+ *
6
+ * Every JSON output colours the same "look" data pip, so a validator that sees
7
+ * only the source NODE type cannot tell Edit Plan's edit list from a
8
+ * Transcribe's transcript. Wired into Add Captions' Transcript input, the edit
9
+ * list is accepted at connect time and only fails (or captions nothing) at run
10
+ * time. This module is the one place that knows the difference, read by the
11
+ * canvas validators and the server's edge normalization alike (MCP workflow
12
+ * writes, the REST delta lane, the Copilot).
13
+ *
14
+ * Output kinds are DATA, never a list of node names:
15
+ * - a render node's `json` pip answers its registry `jsonKind`
16
+ * (`RENDER_NODE_TYPES`), so a render registered later — Speaker View, whose
17
+ * json is an EDL — is covered by its own registry entry;
18
+ * - the other JSON producers declare a kind per output pip in
19
+ * `JSON_OUTPUT_KINDS` below. EVERY node with a JSON output declares one
20
+ * (decided 2026-10-08): `transcript`, `edl`, or `other` for JSON that is
21
+ * neither (a scrape, an analysis, a collection). `other` is a positive
22
+ * statement, not a gap — it connects exactly as an undeclared pip always
23
+ * has. A guard test enumerates the node definitions' JSON pips and fails
24
+ * on one with no declaration, so a new JSON node cannot ship unclassified
25
+ * and a Transcript producer cannot slip past the EDL/Transcript block.
26
+ * Input kinds follow the platform's handle vocabulary: a `transcript` pip
27
+ * expects a Transcript, an `edl` pip an EDL.
28
+ */
29
+ import { RENDER_NODE_TYPES, type RenderNodeDescriptor } from "./render-nodes.js"
30
+
31
+ /** The two JSON shapes the platform's handle vocabulary tells apart. */
32
+ export type JsonKind = "transcript" | "edl"
33
+
34
+ /**
35
+ * What a JSON output pip DECLARES: one of the two kinds, or `other` — JSON that
36
+ * is neither a Transcript nor an EDL. Only `JsonKind` ever takes part in a
37
+ * connection check; `other` records that the pip was classified.
38
+ */
39
+ export type JsonOutputDeclaration = JsonKind | "other"
40
+
41
+ interface JsonOutputs {
42
+ /** The pip an edge with no `sourceHandle` reads — absent when that read is not JSON (Text to Dialogue's is its audio). */
43
+ readonly primary?: string
44
+ readonly pips: Readonly<Record<string, JsonOutputDeclaration>>
45
+ }
46
+
47
+ /** JSON outputs of the nodes that are not renders: pip id → what it carries. */
48
+ const JSON_OUTPUT_KINDS: Readonly<Record<string, JsonOutputs>> = Object.freeze({
49
+ // Edit Plan: the plan on `edl` — a Tighten EDL, a clip set (`Edl[]`) or a chapter list.
50
+ "edit-plan": { primary: "edl", pips: { edl: "edl" } },
51
+ // Transcribe: its json is the normalized Transcript (its `text` pip is plain text, no kind).
52
+ transcribe: { primary: "json", pips: { json: "transcript" } },
53
+ // Camera Switch: the switched edit and the renamed (still a Transcript) transcript.
54
+ "camera-switch": { primary: "edl", pips: { edl: "edl", transcript: "transcript" } },
55
+ // Text to Dialogue: the Transcript built from the model's own word timings (its default read is the audio).
56
+ "text-to-dialogue": { pips: { json: "transcript" } },
57
+
58
+ // ── JSON that is neither a Transcript nor an EDL (decided 2026-10-08) ──
59
+ // Forced Alignment: `{ alignment: [{ word, start, end }] }` in seconds — a word list, not a Transcript.
60
+ "forced-alignment": { primary: "data", pips: { data: "other" } },
61
+ // Video Analysis / Video Audit: the canonical analysis result (an audit IS an analysis).
62
+ "video-analysis": { primary: "json", pips: { json: "other" } },
63
+ "video-audit": { primary: "json", pips: { json: "other" } },
64
+ // Silence Detect: `{ version, ranges, durationMs }`. Audio Sync: `{ version, reference, offsets, notes }`.
65
+ "silence-detect": { primary: "json", pips: { json: "other" } },
66
+ "audio-sync": { primary: "json", pips: { json: "other" } },
67
+ // Scrapers and searches: the scraped page / ad array / post list.
68
+ "web-scrape": { primary: "json", pips: { json: "other" } },
69
+ "meta-ads-scrape": { primary: "json", pips: { json: "other" } },
70
+ "instagram-scrape": { primary: "json", pips: { json: "other" } },
71
+ "social-search": { primary: "json", pips: { json: "other" } },
72
+ "telegram-channel-feed": { primary: "json", pips: { json: "other" } },
73
+ // Content Recipe: the recipe's structured result.
74
+ "content-recipe": { primary: "json", pips: { json: "other" } },
75
+ // Collections and libraries: the stored rows, whatever the user keeps in them.
76
+ "collection-read": { primary: "json", pips: { json: "other" } },
77
+ "collection-write": { primary: "json", pips: { json: "other" } },
78
+ "inspiration-read": { primary: "json", pips: { json: "other" } },
79
+ "competitor-read": { primary: "json", pips: { json: "other" } },
80
+ // Describe to Picker: the picker values read off an image.
81
+ "describe-to-picker": { primary: "picker-json", pips: { "picker-json": "other" } },
82
+ })
83
+
84
+ /** The pip a render's order reads/writes its json on. */
85
+ const RENDER_JSON_PIP = "json"
86
+
87
+ /** The input pips whose kind is fixed by the handle vocabulary. */
88
+ const JSON_INPUT_KINDS: Readonly<Record<string, JsonKind>> = Object.freeze({
89
+ transcript: "transcript",
90
+ edl: "edl",
91
+ })
92
+
93
+ const own = <T>(table: Readonly<Record<string, T>>, key: string): T | undefined =>
94
+ Object.hasOwn(table, key) ? table[key] : undefined
95
+
96
+ /**
97
+ * What the JSON output `sourceHandle` of a node of `nodeType` DECLARES —
98
+ * `transcript`, `edl`, `other` — or `undefined` when the pip is not declared at
99
+ * all (a non-JSON pip, an unknown handle, an unregistered node). `renders` is
100
+ * the render-node registry (injectable for tests). The guard test reads this to
101
+ * prove every JSON pip is classified.
102
+ */
103
+ export function declaredJsonOutput(
104
+ nodeType: string | null | undefined,
105
+ sourceHandle: string | null | undefined,
106
+ renders: Readonly<Record<string, RenderNodeDescriptor>> = RENDER_NODE_TYPES,
107
+ ): JsonOutputDeclaration | undefined {
108
+ if (typeof nodeType !== "string") return undefined
109
+ const render = own(renders, nodeType)
110
+ if (render) return (sourceHandle ?? RENDER_JSON_PIP) === RENDER_JSON_PIP ? render.jsonKind : undefined
111
+ const outputs = own(JSON_OUTPUT_KINDS, nodeType)
112
+ if (!outputs) return undefined
113
+ const pip = sourceHandle ?? outputs.primary
114
+ return typeof pip === "string" ? own(outputs.pips, pip) : undefined
115
+ }
116
+
117
+ /** The declared JSON output pips of the non-render nodes, as `[nodeType, pipId, declaration]` rows. */
118
+ export function declaredJsonOutputRows(): ReadonlyArray<readonly [string, string, JsonOutputDeclaration]> {
119
+ return Object.entries(JSON_OUTPUT_KINDS).flatMap(([type, o]) =>
120
+ Object.entries(o.pips).map(([pip, kind]) => [type, pip, kind] as const),
121
+ )
122
+ }
123
+
124
+ /**
125
+ * What the JSON output `sourceHandle` of a node of `nodeType` carries, or
126
+ * `undefined` when it is not known to carry one of the two kinds (anything
127
+ * declared `other`, a non-JSON pip, anything unregistered).
128
+ */
129
+ export function jsonOutputKind(
130
+ nodeType: string | null | undefined,
131
+ sourceHandle: string | null | undefined,
132
+ renders: Readonly<Record<string, RenderNodeDescriptor>> = RENDER_NODE_TYPES,
133
+ ): JsonKind | undefined {
134
+ const declared = declaredJsonOutput(nodeType, sourceHandle, renders)
135
+ return declared === "other" ? undefined : declared
136
+ }
137
+
138
+ /** What the JSON input `targetHandle` of a node expects, or `undefined`. */
139
+ export function jsonInputKind(
140
+ _nodeType: string | null | undefined,
141
+ targetHandle: string | null | undefined,
142
+ ): JsonKind | undefined {
143
+ return typeof targetHandle === "string" ? own(JSON_INPUT_KINDS, targetHandle) : undefined
144
+ }
145
+
146
+ export interface JsonKindMismatch {
147
+ readonly output: JsonKind
148
+ readonly input: JsonKind
149
+ }
150
+
151
+ /**
152
+ * The connections this blocks: a JSON output of one kind wired into an input of
153
+ * the other (decided 2026-10-07 / 2026-10-08) — an EDL into a Transcript input
154
+ * and a Transcript into an EDL input. Both directions read the same two
155
+ * tables. `null` for every other pair — including pairs it cannot classify,
156
+ * which keep today's behaviour.
157
+ */
158
+ export function jsonKindMismatch(
159
+ sourceType: string | null | undefined,
160
+ sourceHandle: string | null | undefined,
161
+ targetType: string | null | undefined,
162
+ targetHandle: string | null | undefined,
163
+ renders: Readonly<Record<string, RenderNodeDescriptor>> = RENDER_NODE_TYPES,
164
+ ): JsonKindMismatch | null {
165
+ const input = jsonInputKind(targetType, targetHandle)
166
+ if (!input) return null
167
+ const output = jsonOutputKind(sourceType, sourceHandle, renders)
168
+ return output && output !== input ? { output, input } : null
169
+ }
170
+
171
+ /** The sentence a rejected connection is explained with. */
172
+ export function jsonKindMismatchMessage(
173
+ mismatch: JsonKindMismatch,
174
+ labels: { readonly sourceLabel?: string; readonly targetLabel?: string } = {},
175
+ ): string {
176
+ const source = labels.sourceLabel ?? "This output"
177
+ const target = labels.targetLabel ?? "this node"
178
+ if (mismatch.output === "transcript") {
179
+ return (
180
+ `${source} outputs a transcript, not an edit list (EDL), so it cannot feed the EDL input of ${target}. ` +
181
+ `Wire an Edit Plan's or Camera Switch's edl there instead.`
182
+ )
183
+ }
184
+ return (
185
+ `${source} outputs an edit list (EDL), not a transcript, so it cannot feed the Transcript input of ${target}. ` +
186
+ `Wire a Transcribe node's json (or Apply EDL's or Camera Switch's transcript) there instead.`
187
+ )
188
+ }
@@ -220,6 +220,14 @@ export interface ModelCatalogEntry {
220
220
  unlistedResolutionRendersAs?: string
221
221
  qualities?: readonly string[]
222
222
  durations?: readonly number[]
223
+ /**
224
+ * The length (seconds) this model renders when the request names no duration
225
+ * — a capability fact, and the length an unset duration is CHARGED at
226
+ * (`pricedOutputDurationSec`). A member of `durations`. REQUIRED on every
227
+ * video model priced by length (`pricing-default-duration-sync.test.ts`), and
228
+ * where the KIE config pins `extraParams.duration` it must equal that pin.
229
+ */
230
+ defaultDuration?: number
223
231
  /**
224
232
  * The model accepts an AUTO duration (`duration: -1`, see
225
233
  * `VIDEO_DURATION_AUTO`): it picks the clip length itself — the source clip's
@@ -288,7 +296,7 @@ export const MODEL_RECOMMENDATIONS: readonly ModelRecommendation[] = [
288
296
  { intent: "cheap batch video clips", modelIds: ["veo3.1", "wan-turbo", "bytedance-lite"], note: "VEO 3.1 Fast is the best price/quality balance with native audio." },
289
297
  { intent: "video with start + end frame", modelIds: ["veo3", "veo3.1", "kling-turbo", "minimax", "hailuo-standard", "seedance-2"], note: "All listed support an end frame; VEO uses imageUrls[start, end]." },
290
298
  { intent: "music / song generation", modelIds: ["suno-v6", "suno-v6_wild", "suno-v6_mini", "suno-v5_5"], note: "V6 is the default flagship; V6 Wild for bolder, less predictable results; V6 Mini when speed matters; v5.5 / v5 / v4 keep their own character. Same price." },
291
- { intent: "voice over / narration", modelIds: ["elevenlabs-v4", "elevenlabs-v3", "elevenlabs-turbo"], note: "v4 is the default: [audio tags] for emotion and up to 10,000 characters per request. v3 is the previous expressive model, still selectable. Turbo is cheaper for plain narration." },
299
+ { intent: "voice over / narration", modelIds: ["elevenlabs-v4", "elevenlabs-v3", "elevenlabs-v4-turbo", "elevenlabs-turbo"], note: "v4 is the default: [audio tags] for emotion and up to 10,000 characters per request. v3 is the previous expressive model, still selectable. v4 Turbo keeps v4's tags at Turbo's credit price; Turbo v2.5 is the cheapest for plain narration without tags." },
292
300
  { intent: "lip-sync a portrait to audio", modelIds: ["kling-avatar-pro", "kling-avatar", "infinitalk"], note: "Pro for best mouth shape; InfiniTalk for resolution control." },
293
301
  { intent: "transcription / captions", modelIds: ["elevenlabs-stt", "incredibly-fast-whisper", "whisper"], note: "Captions need WORD timestamps: ElevenLabs STT (always) or Incredibly Fast Whisper. Plain Whisper returns phrase segments only." },
294
302
  { intent: "motion transfer (drive a subject by another video)", modelIds: ["motion-transfer", "kling-3.0-motion"], note: "Kling 2.6 base is cheap; Kling 3.0 is premium." },
@@ -304,6 +312,10 @@ const NANO_BANANA_RATIOS = ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "
304
312
  // nano-banana-2-lite). Kept separate so the wider set can't leak to the
305
313
  // rest of the family.
306
314
  const NANO_BANANA_2_LITE_RATIOS = ["auto", "1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "4:5", "5:4", "21:9", "4:1", "1:4", "8:1", "1:8"] as const
315
+ // Nano Banana 2.1 — its own documented enum, the same fifteen ratios as Lite
316
+ // (docs.kie.ai/market/google/nanobanana-2-1). Declared separately so a change to
317
+ // either model's set cannot silently move the other.
318
+ const NANO_BANANA_2_1_RATIOS = ["auto", "1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "4:5", "5:4", "21:9", "4:1", "1:4", "8:1", "1:8"] as const
307
319
  // Note: these arrays are synchronized with the frontend's
308
320
  // `model-options.ts` constants of the same names. The frontend now imports
309
321
  // them via the `getAspectRatioOptions(modelId)` helper; if you update one
@@ -389,6 +401,26 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
389
401
  { identifier: "nano-banana-2:4K", credits: 50, note: "4K" },
390
402
  ],
391
403
  },
404
+ "nano-banana-2-1": {
405
+ id: "nano-banana-2-1",
406
+ kind: "image",
407
+ // Single id for both modes, like nano-banana-2: optional input images via
408
+ // image_input (up to 10) on the one endpoint.
409
+ modes: ["t2i", "i2i"] as const,
410
+ family: "Google",
411
+ label: "Nano Banana 2.1",
412
+ series: "Nano Banana",
413
+ description: "Google's high-efficiency image model for generation and editing — sharper quality, prompt adherence, character consistency and text rendering, up to 10 references and 4K output.",
414
+ useCases: ["realistic", "character", "typography", "high-res"],
415
+ features: ["reference-image"],
416
+ aspectRatios: NANO_BANANA_2_1_RATIOS,
417
+ resolutions: ["1K", "2K", "4K"],
418
+ pricing: [
419
+ { identifier: "nano-banana-2-1", credits: 10, note: "1K default" },
420
+ { identifier: "nano-banana-2-1:2K", credits: 20, note: "2K" },
421
+ { identifier: "nano-banana-2-1:4K", credits: 30, note: "4K" },
422
+ ],
423
+ },
392
424
  "nano-banana-2-lite": {
393
425
  id: "nano-banana-2-lite",
394
426
  kind: "image",
@@ -1201,6 +1233,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1201
1233
  useCases: ["realistic", "motion", "narrative"],
1202
1234
  features: ["end-frame"],
1203
1235
  durations: [5],
1236
+ defaultDuration: 5,
1204
1237
  pricing: [{ identifier: "minimax", credits: 143, note: "5s, 1080p" }],
1205
1238
  },
1206
1239
  // MiniMax Hailuo 3 (KIE "minimax-h3") — t2v / i2v (first and/or last frame) /
@@ -1226,6 +1259,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1226
1259
  features: ["end-frame", "audio", "reference-image", "video-reference"],
1227
1260
  aspectRatios: VIDEO_RATIOS_SEEDANCE_2,
1228
1261
  durations: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1262
+ defaultDuration: 6,
1229
1263
  // First entry = default (the UI dropdown + fail-safe snap use opts[0], and
1230
1264
  // 2K is the KIE-side default). Uppercase values are the exact KIE wire enum.
1231
1265
  resolutions: ["2K", "768P"],
@@ -1251,6 +1285,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1251
1285
  description: "Hailuo 2.3 Pro — newer Hailuo with 768P / 1080P resolutions.",
1252
1286
  useCases: ["realistic", "motion"],
1253
1287
  durations: [6, 10],
1288
+ defaultDuration: 6,
1254
1289
  resolutions: ["768P", "1080P"],
1255
1290
  pricing: [
1256
1291
  { identifier: "hailuo-2.3-pro", credits: 200, note: "10s default" },
@@ -1270,6 +1305,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1270
1305
  description: "Cheaper Hailuo 2.3 tier — good baseline quality.",
1271
1306
  useCases: ["realistic", "cheap"],
1272
1307
  durations: [6, 10],
1308
+ defaultDuration: 6,
1273
1309
  pricing: [
1274
1310
  { identifier: "hailuo-2.3", credits: 75, note: "6s default" },
1275
1311
  { identifier: "hailuo-2.3:6s", credits: 80, note: "6s" },
@@ -1287,6 +1323,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1287
1323
  useCases: ["cheap", "motion"],
1288
1324
  features: ["end-frame"],
1289
1325
  durations: [6, 10],
1326
+ defaultDuration: 6,
1290
1327
  resolutions: ["512P", "768P"],
1291
1328
  pricing: [
1292
1329
  { identifier: "hailuo-standard", credits: 75, note: "6s default" },
@@ -1315,6 +1352,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1315
1352
  // `veo3_lite` DO serve it and keep the flag.
1316
1353
  features: ["end-frame", "audio"],
1317
1354
  durations: [4, 6, 8],
1355
+ defaultDuration: 8,
1318
1356
  aspectRatios: VIDEO_RATIOS_HV,
1319
1357
  // 720p (default) + 1080p inline. 4K generates the base at 1080p then chains
1320
1358
  // KIE's /api/v1/veo/get-4k-video endpoint (worker handleImageToVideo / handleTextToVideo).
@@ -1336,6 +1374,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1336
1374
  useCases: ["cinematic", "fast", "general"],
1337
1375
  features: ["end-frame", "audio", "reference-image"],
1338
1376
  durations: [4, 6, 8],
1377
+ defaultDuration: 8,
1339
1378
  aspectRatios: VIDEO_RATIOS_HV,
1340
1379
  resolutions: ["720p", "1080p", "4k"],
1341
1380
  pricing: [
@@ -1356,6 +1395,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1356
1395
  useCases: ["cinematic", "cheap", "high-volume"],
1357
1396
  features: ["end-frame", "audio", "reference-image"],
1358
1397
  durations: [4, 6, 8],
1398
+ defaultDuration: 8,
1359
1399
  aspectRatios: VIDEO_RATIOS_HV,
1360
1400
  resolutions: ["720p", "1080p", "4k"],
1361
1401
  pricing: [
@@ -1378,6 +1418,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1378
1418
  aspectRatios: VIDEO_RATIOS_HV,
1379
1419
  resolutions: ["720p", "1080p", "4k"],
1380
1420
  durations: [4, 6, 8, 10],
1421
+ defaultDuration: 8,
1381
1422
  pricing: [
1382
1423
  { identifier: "gemini-omni-video", credits: 315, note: "default — 720p/1080p 4s" },
1383
1424
  { identifier: "gemini-omni-video:4", credits: 230, note: "720p/1080p 4s" },
@@ -1413,6 +1454,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1413
1454
  aspectRatios: VIDEO_RATIOS_HV,
1414
1455
  resolutions: ["720p", "1080p", "4k"],
1415
1456
  durations: [4, 6, 8, 10],
1457
+ defaultDuration: 8,
1416
1458
  pricing: [
1417
1459
  { identifier: "gemini-omni-flash", credits: 270, note: "default — 8s 720p/1080p (the credit builder's duration fallback)" },
1418
1460
  { identifier: "gemini-omni-flash:4", credits: 160, note: "720p/1080p 4s" },
@@ -1441,6 +1483,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1441
1483
  features: ["audio"],
1442
1484
  aspectRatios: VIDEO_RATIOS_HVS,
1443
1485
  durations: [5, 10],
1486
+ defaultDuration: 5,
1444
1487
  pricing: [
1445
1488
  { identifier: "kling", credits: 280, note: "10s no audio default" },
1446
1489
  { identifier: "kling:5s", credits: 138, note: "5s no audio" },
@@ -1460,6 +1503,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1460
1503
  useCases: ["fast", "motion", "cheap"],
1461
1504
  features: ["end-frame"],
1462
1505
  durations: [5, 10],
1506
+ defaultDuration: 5,
1463
1507
  pricing: [
1464
1508
  { identifier: "kling-turbo", credits: 125, note: "5s default" },
1465
1509
  { identifier: "kling-turbo:5s", credits: 110 },
@@ -1477,6 +1521,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1477
1521
  useCases: ["premium", "narrative", "cinematic"],
1478
1522
  features: ["end-frame", "audio"],
1479
1523
  durations: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1524
+ defaultDuration: 5,
1480
1525
  resolutions: ["720P", "1080P"],
1481
1526
  pricing: [
1482
1527
  { identifier: "kling-3.0", credits: 500, note: "5s 1080p with audio" },
@@ -1499,6 +1544,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1499
1544
  description: "Master tier I2V — strong cinematic quality.",
1500
1545
  useCases: ["cinematic", "premium"],
1501
1546
  durations: [5, 10],
1547
+ defaultDuration: 5,
1502
1548
  pricing: [
1503
1549
  { identifier: "kling-master", credits: 400, note: "5s default" },
1504
1550
  { identifier: "kling-master:5s", credits: 400 },
@@ -1516,6 +1562,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1516
1562
  useCases: ["motion", "cinematic", "reference"],
1517
1563
  features: ["end-frame", "reference-image"],
1518
1564
  durations: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1565
+ defaultDuration: 5,
1519
1566
  resolutions: ["720p", "1080p"],
1520
1567
  aspectRatios: VIDEO_RATIOS_HVS,
1521
1568
  pricing: [
@@ -1538,6 +1585,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1538
1585
  description: "Grok image-to-video — stylized motion. Up to 15s.",
1539
1586
  useCases: ["stylized", "motion"],
1540
1587
  durations: [6, 10],
1588
+ defaultDuration: 6,
1541
1589
  resolutions: ["480p", "720p"],
1542
1590
  pricing: [
1543
1591
  { identifier: "grok-i2v", credits: 150, note: "6s default" },
@@ -1566,6 +1614,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1566
1614
  useCases: ["stylized", "motion"],
1567
1615
  aspectRatios: ["16:9", "9:16", "1:1", "4:3", "3:4"],
1568
1616
  durations: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1617
+ defaultDuration: 8,
1569
1618
  resolutions: ["480p", "720p"],
1570
1619
  pricing: [
1571
1620
  { identifier: "grok-imagine-video-1.5", credits: 295, note: "default 8s 480p — see :Ns:res variants" },
@@ -1588,6 +1637,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1588
1637
  useCases: ["motion", "narrative"],
1589
1638
  features: ["end-frame"],
1590
1639
  durations: [4, 8, 12],
1640
+ defaultDuration: 8,
1591
1641
  resolutions: ["480p", "720p", "1080p"],
1592
1642
  pricing: [
1593
1643
  { identifier: "seedance", credits: 250, note: "8s default" },
@@ -1609,6 +1659,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1609
1659
  features: ["end-frame", "audio", "reference-image", "video-reference"],
1610
1660
  aspectRatios: VIDEO_RATIOS_SEEDANCE_2,
1611
1661
  durations: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1662
+ defaultDuration: 8,
1612
1663
  autoDuration: true,
1613
1664
  resolutions: ["480p", "720p", "1080p", "4k"],
1614
1665
  pricing: [
@@ -1635,6 +1686,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1635
1686
  features: ["end-frame", "audio", "reference-image", "video-reference"],
1636
1687
  aspectRatios: VIDEO_RATIOS_SEEDANCE_2,
1637
1688
  durations: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1689
+ defaultDuration: 8,
1638
1690
  autoDuration: true,
1639
1691
  resolutions: ["480p", "720p"],
1640
1692
  pricing: [
@@ -1657,6 +1709,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1657
1709
  features: ["end-frame", "audio", "reference-image", "video-reference"],
1658
1710
  aspectRatios: VIDEO_RATIOS_SEEDANCE_2,
1659
1711
  durations: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1712
+ defaultDuration: 8,
1660
1713
  autoDuration: true,
1661
1714
  resolutions: ["480p", "720p"],
1662
1715
  pricing: [
@@ -1685,6 +1738,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1685
1738
  features: ["end-frame", "audio", "reference-image", "video-reference"],
1686
1739
  aspectRatios: VIDEO_RATIOS_SEEDANCE_2,
1687
1740
  durations: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],
1741
+ defaultDuration: 8,
1688
1742
  autoDuration: true,
1689
1743
  resolutions: ["480p", "720p", "1080p"],
1690
1744
  pricing: [
@@ -1727,6 +1781,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1727
1781
  features: ["end-frame", "audio", "reference-image"],
1728
1782
  aspectRatios: VIDEO_RATIOS_WAN_3,
1729
1783
  durations: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],
1784
+ defaultDuration: 5,
1730
1785
  resolutions: ["480p", "720p", "1080p"],
1731
1786
  pricing: [
1732
1787
  { identifier: "wan-3", credits: 200, note: "default 5s 720p — see :Ns:res variants for exact" },
@@ -1752,6 +1807,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1752
1807
  features: ["end-frame", "audio", "reference-image"],
1753
1808
  aspectRatios: VIDEO_RATIOS_WAN_3,
1754
1809
  durations: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],
1810
+ defaultDuration: 5,
1755
1811
  resolutions: ["480p", "720p", "1080p"],
1756
1812
  pricing: [
1757
1813
  { identifier: "wan-3-prime", credits: 320, note: "default 5s 720p — see :Ns:res variants for exact" },
@@ -1774,6 +1830,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1774
1830
  description: "Wan 2.6 image-to-video — 5/10/15s at 720p/1080p.",
1775
1831
  useCases: ["motion", "narrative"],
1776
1832
  durations: [5, 10, 15],
1833
+ defaultDuration: 5,
1777
1834
  resolutions: ["720p", "1080p"],
1778
1835
  pricing: [
1779
1836
  { identifier: "wan-i2v", credits: 175, note: "5s 720p default" },
@@ -1793,6 +1850,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1793
1850
  useCases: ["cheap", "fast"],
1794
1851
  aspectRatios: VIDEO_RATIOS_HVS,
1795
1852
  durations: [5],
1853
+ defaultDuration: 5,
1796
1854
  resolutions: ["480p", "720p"],
1797
1855
  // Different KIE endpoints (i2v vs t2v) → different costs under
1798
1856
  // composite ids. Route picks endpoint based on whether image was supplied.
@@ -1813,6 +1871,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1813
1871
  description: "Wan 2.6 — text-to-video and video-to-video under a single id.",
1814
1872
  useCases: ["v2v", "t2v", "restyle"],
1815
1873
  durations: [5],
1874
+ defaultDuration: 5,
1816
1875
  resolutions: ["720p", "1080p"],
1817
1876
  pricing: [
1818
1877
  { identifier: "wan", credits: 175, note: "v2v 5s 720p" },
@@ -1888,6 +1947,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1888
1947
  description: "Wan 2.7 image-to-video — 2–15s at 720p/1080p, supports start+end frame.",
1889
1948
  useCases: ["motion", "narrative"],
1890
1949
  durations: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1950
+ defaultDuration: 5,
1891
1951
  resolutions: ["720p", "1080p"],
1892
1952
  features: ["end-frame"],
1893
1953
  pricing: [
@@ -1905,6 +1965,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1905
1965
  useCases: ["motion", "narrative"],
1906
1966
  aspectRatios: VIDEO_RATIOS_HVS345,
1907
1967
  durations: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
1968
+ defaultDuration: 5,
1908
1969
  resolutions: ["720p", "1080p"],
1909
1970
  pricing: [
1910
1971
  { identifier: "wan-2.7-t2v", credits: 188, note: "5s 720p default" },
@@ -1931,6 +1992,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1931
1992
  aspectRatios: ["16:9", "9:16"] as const,
1932
1993
  resolutions: ["1080p", "2k", "4k"] as const,
1933
1994
  durations: [6, 8, 10],
1995
+ defaultDuration: 6,
1934
1996
  pricing: [
1935
1997
  { identifier: "ltx-2.3-pro", credits: 240, note: "default 1080p 6s" },
1936
1998
  { identifier: "ltx-2.3-pro:1080p:6s", credits: 240 },
@@ -1962,6 +2024,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1962
2024
  // in credit-identifiers.ts is the per-band authority and snaps a 2k/4k
1963
2025
  // request back onto 6/8/10s, so the reservation is always a real tier).
1964
2026
  durations: [6, 8, 10, 12, 14, 16, 18, 20],
2027
+ defaultDuration: 6,
1965
2028
  pricing: [
1966
2029
  { identifier: "ltx-2.3-fast", credits: 180, note: "default 1080p 6s" },
1967
2030
  { identifier: "ltx-2.3-fast:1080p:6s", credits: 180 },
@@ -1993,6 +2056,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1993
2056
  useCases: ["motion", "creative"],
1994
2057
  aspectRatios: VIDEO_RATIOS_HAPPYHORSE_11,
1995
2058
  durations: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
2059
+ defaultDuration: 5,
1996
2060
  resolutions: ["720p", "1080p"],
1997
2061
  pricing: [
1998
2062
  { identifier: "happyhorse", credits: 282, note: "5s 720p default — per-second: ~5.7 cr/s @720p, ~7.3 cr/s @1080p" },
@@ -2008,6 +2072,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
2008
2072
  description: "HappyHorse 1.1 image-to-video — 3–15s at 720p/1080p, aspect ratio inferred from input image, per-second pricing.",
2009
2073
  useCases: ["motion", "creative"],
2010
2074
  durations: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
2075
+ defaultDuration: 5,
2011
2076
  resolutions: ["720p", "1080p"],
2012
2077
  pricing: [
2013
2078
  { identifier: "happyhorse-i2v", credits: 282, note: "5s 720p default — per-second: ~5.7 cr/s @720p, ~7.3 cr/s @1080p" },
@@ -2024,6 +2089,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
2024
2089
  useCases: ["motion", "reference"],
2025
2090
  aspectRatios: VIDEO_RATIOS_HAPPYHORSE_11,
2026
2091
  durations: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
2092
+ defaultDuration: 5,
2027
2093
  resolutions: ["720p", "1080p"],
2028
2094
  features: ["reference-image"],
2029
2095
  pricing: [
@@ -2057,6 +2123,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
2057
2123
  features: ["end-frame"],
2058
2124
  aspectRatios: VIDEO_RATIOS_HVS,
2059
2125
  durations: [5, 10],
2126
+ defaultDuration: 5,
2060
2127
  resolutions: ["480p", "720p", "1080p"],
2061
2128
  pricing: [{ identifier: "bytedance-lite", credits: 57 }],
2062
2129
  },
@@ -2071,6 +2138,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
2071
2138
  useCases: ["motion", "narrative"],
2072
2139
  aspectRatios: VIDEO_RATIOS_HVS,
2073
2140
  durations: [5, 10],
2141
+ defaultDuration: 5,
2074
2142
  resolutions: ["480p", "720p", "1080p"],
2075
2143
  pricing: [{ identifier: "bytedance-pro", credits: 175 }],
2076
2144
  },
@@ -2084,6 +2152,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
2084
2152
  description: "Faster Bytedance Pro variant.",
2085
2153
  useCases: ["fast", "motion"],
2086
2154
  durations: [5, 10],
2155
+ defaultDuration: 5,
2087
2156
  resolutions: ["720p", "1080p"],
2088
2157
  pricing: [{ identifier: "bytedance-pro-fast", credits: 90 }],
2089
2158
  },
@@ -2105,6 +2174,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
2105
2174
  description: "Runway Gen-3 routed through KIE. 5/10s at 720p/1080p.",
2106
2175
  useCases: ["motion", "narrative"],
2107
2176
  durations: [5, 10],
2177
+ defaultDuration: 5,
2108
2178
  resolutions: ["720p", "1080p"],
2109
2179
  pricing: [{ identifier: "runway-kie", credits: 30, note: "5s 720p" }],
2110
2180
  },
@@ -2156,6 +2226,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
2156
2226
  description: "Extend ANY video: generates the continuation (audio included) and trim-stitches it into one seamless clip.",
2157
2227
  useCases: ["extend"],
2158
2228
  durations: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
2229
+ defaultDuration: 8,
2159
2230
  resolutions: ["480p", "720p", "1080p"],
2160
2231
  pricing: [
2161
2232
  { identifier: "seedance-2-extend", credits: 530, note: "default 8s 720p (ref-mode 50 + 3 stitch) — see :NsR variants" },
@@ -2506,14 +2577,26 @@ const TTS_LANGS_V3 = [
2506
2577
  const TTS_LEVERS_V2 = ["stability", "similarity", "style", "speed", "speakerBoost"] as const
2507
2578
  /**
2508
2579
  * ElevenLabs Dialogue v4's total-character cap across lines — ONE constant, so
2509
- * the live probe's answer lands in one place. Rule (decided 2026-10-06): the
2510
- * largest of 2,500 / 5,000 that returned 200, voiced its last line and finished
2511
- * well inside the funnel's timeout in a live check of v4 dialogue above 2,000
2512
- * characters; never above 5,000 (parity with v3 dialogue) without a separate
2513
- * decision. Written at parity until that check reports; ElevenLabs recommends
2514
- * ≤ 2,000 for quality on either model.
2580
+ * the live probe's answer lands in one place. Measured 2026-10-06: a
2581
+ * 10,000-character v4 dialogue returned 200, voiced its last line and finished
2582
+ * whole in 130 s, well inside the funnel's 300 s timeout
2583
+ * (`DIALOGUE_GENERATION_TIMEOUT_MS`); decided 2026-10-07 to raise the cap to
2584
+ * that number, twice v3 dialogue's 5,000. Length pricing charges
2585
+ * `min(total, cap)`, so the same unit rows reach 10,000 characters without a
2586
+ * new row. ElevenLabs recommends ≤ 2,000 for quality on either model.
2587
+ */
2588
+ const DIALOGUE_V4_MAX_CHARS = 10000
2589
+ /**
2590
+ * ElevenLabs v4 Turbo's per-request character cap — ONE constant, so a change
2591
+ * of the owner's rule lands in one place. The vendor declares 10,000, the same
2592
+ * as v4 (`maximum_text_length_per_request`, measured 2026-10-07); live, both a
2593
+ * 10,000- and a 10,001-character request returned 200 (the vendor accepts over
2594
+ * its declared figure), so the platform clamps at the declared figure — the
2595
+ * smaller of the two. Decided 2026-10-07: the model takes that whole cap because
2596
+ * it ships priced per started 100 characters. An instance that still prices
2597
+ * speech flat charges the flat row for any length (the Text to Speech docs say so).
2515
2598
  */
2516
- const DIALOGUE_V4_MAX_CHARS = 5000
2599
+ const V4_TURBO_MAX_CHARS = 10000
2517
2600
 
2518
2601
  const AUDIO_MODELS: Record<string, ModelCatalogEntry> = {
2519
2602
  // ── ElevenLabs TTS ──
@@ -2574,6 +2657,36 @@ const AUDIO_MODELS: Record<string, ModelCatalogEntry> = {
2574
2657
  languages: TTS_LANGS_V3,
2575
2658
  },
2576
2659
  },
2660
+ "elevenlabs-v4-turbo": {
2661
+ id: "elevenlabs-v4-turbo",
2662
+ kind: "audio",
2663
+ modes: ["tts"] as const,
2664
+ family: "ElevenLabs",
2665
+ label: "ElevenLabs v4 Turbo",
2666
+ series: "ElevenLabs",
2667
+ description: "Faster, cheaper ElevenLabs v4 at lower fidelity — [audio tags], stability and similarity control, at Turbo's credit price. Prefer v4 when quality matters. Direct API.",
2668
+ useCases: ["tts", "voice-over", "narration", "expressive", "fast"],
2669
+ features: ["audio-tags", "voice-cloning"],
2670
+ // Flat per request at parity with Turbo v2.5 (what a run costs where length
2671
+ // pricing is off); per started 100 characters at Turbo's rate where it is on
2672
+ // (decided 2026-10-06).
2673
+ pricing: [
2674
+ { identifier: "elevenlabs-v4-turbo", credits: 15 },
2675
+ { identifier: "elevenlabs-v4-turbo:per-100-chars", credits: 2, note: SPEECH_UNIT_PRICE_NOTE },
2676
+ ],
2677
+ tts: {
2678
+ // Every value below was measured 2026-10-07 from live calls to eleven_v4_turbo.
2679
+ audioTags: true, // measured 2026-10-07: a tagged line → 200; Scribe hears no tag word spoken and lists [chuckles] as an audio event
2680
+ ssmlBreaks: false,
2681
+ levers: ["stability", "similarity"], // measured 2026-10-07: /v1/models can_use_style / can_use_speaker_boost both false, as v4; stability + similarity_boost → 200
2682
+ languageCode: true, // measured 2026-10-07: language_code "he" with Hebrew text → 200
2683
+ timestamps: true, // measured 2026-10-07: /with-timestamps answers 200 at the same character cost as the plain call
2684
+ stitching: true, // measured 2026-10-07: previous_text / next_text → 200, at the same character cost (context not billed)
2685
+ maxChars: V4_TURBO_MAX_CHARS,
2686
+ // The curated picker, the same 46 as v4 and v3 (the model lists 85; widening is its own change).
2687
+ languages: TTS_LANGS_V3, // measured 2026-10-07: all 46 present in the model's 85-language list
2688
+ },
2689
+ },
2577
2690
  "elevenlabs-turbo": {
2578
2691
  id: "elevenlabs-turbo",
2579
2692
  kind: "audio",