@nodaro/shared 3.25.0 → 3.27.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 (45) hide show
  1. package/dist/index.cjs +778 -169
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +427 -75
  4. package/dist/index.d.ts +427 -75
  5. package/dist/index.js +749 -170
  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__/condition-variables.test.ts +12 -0
  12. package/src/__tests__/content-recipe-ideas.test.ts +9 -4
  13. package/src/__tests__/credit-identifiers.test.ts +12 -0
  14. package/src/__tests__/edl.test.ts +319 -4
  15. package/src/__tests__/image-model-roles.test.ts +57 -0
  16. package/src/__tests__/image-ref-limit.test.ts +1 -0
  17. package/src/__tests__/json-kinds.test.ts +11 -1
  18. package/src/__tests__/llm-models.test.ts +253 -42
  19. package/src/__tests__/lone-media-url.test.ts +78 -0
  20. package/src/__tests__/prompt-length-limits.test.ts +2 -0
  21. package/src/__tests__/render-nodes.test.ts +46 -1
  22. package/src/__tests__/transcribe-preflight.test.ts +5 -0
  23. package/src/camera-switch-contract.ts +9 -6
  24. package/src/collections.ts +72 -2
  25. package/src/condition-variables.ts +3 -1
  26. package/src/content-recipe-ideas.ts +5 -2
  27. package/src/credit-identifiers.ts +56 -13
  28. package/src/edl.ts +143 -23
  29. package/src/fan-out-rows.ts +1 -1
  30. package/src/i18n/camera-format.ko.ts +3 -3
  31. package/src/image-model-roles.ts +62 -0
  32. package/src/index.ts +42 -0
  33. package/src/json-kinds.ts +11 -6
  34. package/src/llm-models.ts +434 -24
  35. package/src/lone-media-url.ts +57 -0
  36. package/src/model-catalog.ts +145 -9
  37. package/src/model-constants.ts +13 -2
  38. package/src/node-default-mappings.ts +3 -0
  39. package/src/node-runtime-keys.ts +3 -0
  40. package/src/normalize-node-params.ts +47 -4
  41. package/src/pipeline-types.ts +16 -3
  42. package/src/producer-types.ts +4 -0
  43. package/src/render-nodes.ts +58 -2
  44. package/src/settings-input.ts +2 -1
  45. package/src/transcribe-preflight.ts +11 -10
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The ONE rule both engines use when a text-shaped wire reaches a social post:
3
+ * a value that is exactly one media LINK — and nothing else — carries the
4
+ * medium, not the caption. An Extract Field over a saved record's cover posts
5
+ * the picture; a page link, a sentence with a link in it, a JSON value or a
6
+ * format no platform posts stays the caption (decided 2026-10-08).
7
+ *
8
+ * The file name is read from the parsed URL's PATH, anchored at its end: a host
9
+ * that merely contains a file ending (`movistar.es`, `webmd.com`, `gifs.com`)
10
+ * or a file name in the query (`?img=a.png`) is a page link. Only the formats
11
+ * the platforms accept count — avif / heic / svg / bmp are not pictures to
12
+ * Telegram, X or Instagram and would fail the post.
13
+ */
14
+ import { AUDIO_PRODUCER_TYPES, DYNAMIC_PRODUCER_TYPES, IMAGE_PRODUCER_TYPES, VIDEO_PRODUCER_TYPES } from "./producer-types.js"
15
+ import { ENTITY_NODE_KINDS } from "./entity-node-fields.js"
16
+
17
+ export type LoneMediaUrlKind = "image" | "video"
18
+
19
+ const IMAGE_FILE_RE = /\.(png|jpe?g|gif|webp)$/i
20
+ const VIDEO_FILE_RE = /\.(mp4|mov|webm|m4v)$/i
21
+
22
+ /** Which medium a text value is when its WHOLE value is one media link; `null`
23
+ * for anything else (empty, several words, a comma-joined pair of links, a
24
+ * page link, a file ending in the host or the query, an unsupported format). */
25
+ export function loneMediaUrlKind(value: string): LoneMediaUrlKind | null {
26
+ const s = value.trim()
27
+ if (s.length === 0 || /[\s,]/.test(s) || !/^https?:\/\//i.test(s)) return null
28
+ let pathname: string
29
+ try {
30
+ pathname = new URL(s).pathname
31
+ } catch {
32
+ return null
33
+ }
34
+ if (IMAGE_FILE_RE.test(pathname)) return "image"
35
+ if (VIDEO_FILE_RE.test(pathname)) return "video"
36
+ return null
37
+ }
38
+
39
+ /** A trigger whose ONE wire carries a message's text AND its medium (the
40
+ * caption and the photo of an incoming Telegram message): both engines route
41
+ * the two together from the message itself, so the wire's single value is
42
+ * never read as "one media link". */
43
+ const MESSAGE_TRIGGER_TYPES: ReadonlySet<string> = new Set(["telegram-trigger", "telegram-account-trigger"])
44
+
45
+ /** A source whose wire a social post reads as TEXT: not a declared image, video
46
+ * or audio producer, not a dynamic (multi-typed) one such as List — whose typed
47
+ * columns route by column type — not a message trigger, and not an entity
48
+ * whose picture is a reference. Derived from the producer sets, so a new text
49
+ * node is covered and a new media node (which must join its producer set to
50
+ * connect at all) is excluded, with nothing to remember. */
51
+ export function isLoneMediaLinkSource(nodeType: string | null | undefined): boolean {
52
+ if (!nodeType) return false
53
+ if (IMAGE_PRODUCER_TYPES.has(nodeType) || VIDEO_PRODUCER_TYPES.has(nodeType) || AUDIO_PRODUCER_TYPES.has(nodeType)) return false
54
+ if (DYNAMIC_PRODUCER_TYPES.has(nodeType) || MESSAGE_TRIGGER_TYPES.has(nodeType)) return false
55
+ if ((ENTITY_NODE_KINDS as readonly string[]).includes(nodeType) || nodeType === "face") return false
56
+ return true
57
+ }
@@ -282,14 +282,14 @@ export interface ModelRecommendation {
282
282
 
283
283
  export const MODEL_RECOMMENDATIONS: readonly ModelRecommendation[] = [
284
284
  // image
285
- { intent: "best for typography / logos / text-heavy", modelIds: ["nano-banana-pro", "gpt-image-2"], note: "Nano Banana Pro for diagrams / complex text; GPT Image 2 for logos and short copy." },
285
+ { intent: "best for typography / logos / text-heavy", modelIds: ["gpt-image-2", "gpt-image-2-5-flare"], note: "GPT Image 2 for exact copy, labels and non-Latin text; GPT Image 2.5 Flare is close and faster." },
286
286
  // Notes name the RANKING, not the price — the price sits in the generated
287
287
  // table directly below them and in `pricing`, so restating it here just
288
288
  // creates a copy that rots (this one said "1 credit" long after it was 2).
289
289
  { intent: "cheapest realistic image", modelIds: ["z-image", "qwen", "imagen4-fast"], note: "Z-Image is the cheapest. Qwen / Imagen4 Fast for slightly higher quality." },
290
- { intent: "highest fidelity image", modelIds: ["nano-banana-pro", "imagen4-ultra", "flux-flex"], note: "Pick by family preference; all three are premium tiers." },
291
- { intent: "image edit / restyle", modelIds: ["flux-kontext", "ideogram-remix", "seedream-5-pro-i2i"], note: "Flux Kontext preserves identity; Ideogram Remix is character-aware; Seedream 5 Pro for instruction-based edits (5 Lite is the budget option)." },
292
- { intent: "highest-resolution image", modelIds: ["topaz-image-upscale", "nano-banana-pro", "gpt-image-2"], note: "Generate at the model's top tier, then Topaz upscale 4x (Topaz's only lever is the 1x/2x/4x factor)." },
290
+ { intent: "highest fidelity image", modelIds: ["gpt-image-2", "gpt-image-2-5-sunburst", "imagen4-ultra"], note: "GPT Image 2 for characters and identity; GPT Image 2.5 Sunburst for wide or in-between ratios GPT Image 2 can't draw." },
291
+ { intent: "image edit / restyle", modelIds: ["gpt-image-2-5-flare-i2i", "gpt-image-2-i2i", "seedream-5-pro-i2i"], note: "GPT Image 2.5 Flare keeps pose, framing and product detail; GPT Image 2 i2i for identity-critical edits; Seedream 5 Pro for instruction-based edits." },
292
+ { intent: "highest-resolution image", modelIds: ["topaz-image-upscale", "gpt-image-2", "gpt-image-2-5-sunburst"], note: "Generate at the model's top tier, then Topaz upscale 4x (Topaz's only lever is the 1x/2x/4x factor)." },
293
293
  { intent: "background removal / cutout", modelIds: ["recraft-remove-bg"], note: "Cheap, no prompt needed." },
294
294
  // video
295
295
  { intent: "best cinematic video", modelIds: ["veo3", "kling-3.0", "seedance-2"], note: "VEO 3.1 Quality for premium narrative; Kling 3.0 for music-synced motion; Seedance 2 for reference-driven consistency." },
@@ -344,7 +344,7 @@ const VIDEO_RATIOS_HVS = ["16:9", "9:16", "1:1"] as const
344
344
  const WAN_27_IMAGE_RATIOS = ["1:1", "16:9", "9:16", "4:3", "3:4", "21:9", "8:1", "1:8"] as const
345
345
  const VIDEO_RATIOS_HVS345 = ["16:9", "9:16", "1:1", "4:3", "3:4"] as const
346
346
  // Seedance 2.x only — KIE accepts the full fixed-ratio set incl. 21:9
347
- // (docs.kie.ai/market/bytedance/seedance-2); MiniMax Hailuo 3 shares the same
347
+ // (docs.kie.ai/market/bytedance/seedance-2); MiniMax H3 shares the same
348
348
  // seven-ratio set (t2v enum + r2v adaptive default per docs.kie.ai/market/minimax-h3).
349
349
  // Kept separate from HVS so the
350
350
  // wider set can't leak to models that don't support it.
@@ -453,7 +453,6 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
453
453
  { identifier: "nano-banana-pro", credits: 45, note: "1K / 2K" },
454
454
  { identifier: "nano-banana-pro:4K", credits: 60, note: "4K" },
455
455
  ],
456
- featured: true,
457
456
  },
458
457
  "nano-banana-edit": {
459
458
  id: "nano-banana-edit",
@@ -691,6 +690,7 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
691
690
  { identifier: "gpt-image-2:4K", credits: 60, note: "4K" },
692
691
  ],
693
692
  safetyFilter: { stochastic: true, fallback: "nano-banana-pro" },
693
+ featured: true,
694
694
  },
695
695
  "gpt-image-2-i2i": {
696
696
  id: "gpt-image-2-i2i",
@@ -1013,6 +1013,40 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
1013
1013
  { identifier: "seedream-5-pro-i2i:high", credits: 60, note: "high / 2K" },
1014
1014
  ],
1015
1015
  },
1016
+ // Seedream 5 Flash — fast, low-cost Seedream 5. Its lever is KIE's `size`
1017
+ // (1K / 1.5K / 2K), NOT the siblings' `quality`: declared as `resolutions`
1018
+ // (the KIE config renames it to `size` on the wire). Flat price at every
1019
+ // offered size. 1.5K is not offered yet: no other image model or route enum
1020
+ // carries it, and its price has not been confirmed.
1021
+ // See: docs.kie.ai/market/seedream/5-flash-text-to-image.md
1022
+ "seedream-5-flash": {
1023
+ id: "seedream-5-flash",
1024
+ kind: "image",
1025
+ modes: ["t2i"] as const,
1026
+ family: "Bytedance",
1027
+ label: "Seedream 5 Flash",
1028
+ series: "Seedream",
1029
+ description: "Fast, low-cost Seedream 5 — quick generations at 1K or 2K, same price at either size.",
1030
+ useCases: ["realistic", "drafts", "iteration"],
1031
+ features: ["reference-image"],
1032
+ aspectRatios: SEEDREAM_RATIOS,
1033
+ resolutions: ["1K", "2K"],
1034
+ pricing: [{ identifier: "seedream-5-flash", credits: 10, note: "1K / 2K flat" }],
1035
+ },
1036
+ "seedream-5-flash-i2i": {
1037
+ id: "seedream-5-flash-i2i",
1038
+ kind: "image",
1039
+ modes: ["i2i"] as const,
1040
+ family: "Bytedance",
1041
+ label: "Seedream 5 Flash (I2I)",
1042
+ series: "Seedream",
1043
+ description: "Image-to-image with Seedream 5 Flash — fast edits from up to 10 input images at 1K or 2K, same price at either size.",
1044
+ useCases: ["edit", "iteration"],
1045
+ features: ["reference-image"],
1046
+ aspectRatios: SEEDREAM_RATIOS,
1047
+ resolutions: ["1K", "2K"],
1048
+ pricing: [{ identifier: "seedream-5-flash-i2i", credits: 10, note: "1K / 2K flat" }],
1049
+ },
1016
1050
 
1017
1051
  // ── Alibaba Qwen ──
1018
1052
  "qwen": {
@@ -1236,7 +1270,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1236
1270
  defaultDuration: 5,
1237
1271
  pricing: [{ identifier: "minimax", credits: 143, note: "5s, 1080p" }],
1238
1272
  },
1239
- // MiniMax Hailuo 3 (KIE "minimax-h3") — t2v / i2v (first and/or last frame) /
1273
+ // MiniMax H3 (KIE "minimax-h3") — t2v / i2v (first and/or last frame) /
1240
1274
  // reference-to-video (9 images / 3 videos ≤15s total / 3 audios ≤15s total;
1241
1275
  // audio refs require an image or video ref alongside). Two-rate resolution
1242
1276
  // lever (768P added 2026-08-03): 2K (KIE default) at 36.5 KIE cr/s, 768P at
@@ -1254,7 +1288,7 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
1254
1288
  family: "MiniMax",
1255
1289
  label: "minimax-h3",
1256
1290
  series: "Hailuo",
1257
- description: "MiniMax Hailuo 3 — premium multimodal tier: first/last frame + image/video/audio references, native audio, 2K (default) or 768P output, 4-15s per-second pricing.",
1291
+ description: "MiniMax H3 — premium multimodal tier: first/last frame + image/video/audio references, native audio, 2K (default) or 768P output, 4-15s per-second pricing.",
1258
1292
  useCases: ["premium", "narrative"],
1259
1293
  features: ["end-frame", "audio", "reference-image", "video-reference"],
1260
1294
  aspectRatios: VIDEO_RATIOS_SEEDANCE_2,
@@ -3247,6 +3281,88 @@ export interface NormalizedModelInput {
3247
3281
  adjustments: ModelInputAdjustment[]
3248
3282
  }
3249
3283
 
3284
+ /** A source image's pixel size as it is DISPLAYED (EXIF orientation applied). */
3285
+ export interface SourceImageSize {
3286
+ width: number
3287
+ height: number
3288
+ }
3289
+
3290
+ /** What a request knows beyond its own levers. */
3291
+ export interface ModelInputContext {
3292
+ /**
3293
+ * The image an image-to-image or edit request transforms. Only read to
3294
+ * resolve "auto" on a model without a native auto; absent or unusable means
3295
+ * the size is unknown and "auto" snaps the way it always has.
3296
+ */
3297
+ sourceImage?: SourceImageSize
3298
+ }
3299
+
3300
+ /** True for the "auto" aspect token in any case or padding. */
3301
+ export function isAutoAspectToken(value: unknown): boolean {
3302
+ return typeof value === "string" && value.trim().toLowerCase() === "auto"
3303
+ }
3304
+
3305
+ function usableSize(size: SourceImageSize | undefined): size is SourceImageSize {
3306
+ return (
3307
+ size !== undefined &&
3308
+ Number.isFinite(size.width) && size.width > 0 &&
3309
+ Number.isFinite(size.height) && size.height > 0
3310
+ )
3311
+ }
3312
+
3313
+ /**
3314
+ * Log-space distances closer than this are a tie. Mirror pairs that are
3315
+ * mathematically equidistant (4:3 and 3:4 from a square) differ in the last
3316
+ * bit once `Math.log` rounds them, so an exact comparison would let rounding,
3317
+ * not the catalog's order, pick between them. Real catalog ratios sit at least
3318
+ * ~1e-2 apart, far above this.
3319
+ *
3320
+ * Source-size path ONLY. The ratio-TOKEN fit (`nearestAspectRatio` behind
3321
+ * `fitAspectRatioToModel`) keeps its strict comparison on purpose: it mirrors
3322
+ * the video adapters' `snapAspectRatioToken` exactly (pinned by
3323
+ * `video-normalizer-totality.test.ts`), and a request must snap to one ratio
3324
+ * whichever door it came through.
3325
+ */
3326
+ const ASPECT_TIE_EPSILON = 1e-9
3327
+
3328
+ /**
3329
+ * The ratio in `ratios` nearest a `sourceWidth` x `sourceHeight` image:
3330
+ * minimises |ln(w/h) - ln(rw/rh)|, so a portrait and its landscape mirror are
3331
+ * equally far from a square. Entries that are not ratios ("auto", "adaptive",
3332
+ * "match_input_image") are skipped, and a tie goes to the ratio listed first
3333
+ * (`ASPECT_TIE_EPSILON`). `undefined` for unusable dimensions or a list
3334
+ * without a single ratio.
3335
+ */
3336
+ export function nearestCatalogAspectRatio(
3337
+ sourceWidth: number,
3338
+ sourceHeight: number,
3339
+ ratios: readonly string[],
3340
+ ): string | undefined {
3341
+ if (!usableSize({ width: sourceWidth, height: sourceHeight })) return undefined
3342
+ const target = Math.log(sourceWidth / sourceHeight)
3343
+ let best: string | undefined
3344
+ let bestDist = Infinity
3345
+ for (const ratio of ratios) {
3346
+ const [rw, rh] = ratio.split(":").map(Number)
3347
+ if (!rw || !rh || rw < 0 || rh < 0) continue
3348
+ const dist = Math.abs(Math.log(rw / rh) - target)
3349
+ if (dist < bestDist - ASPECT_TIE_EPSILON) { bestDist = dist; best = ratio }
3350
+ }
3351
+ return best
3352
+ }
3353
+
3354
+ /**
3355
+ * True when `aspectRatio` is "auto" and `modelId`'s catalog ratio list does not
3356
+ * carry "auto" — the one case where the source image's size decides the ratio.
3357
+ * A caller that has to fetch the size asks this first, so a request that will
3358
+ * not use it never pays for the read.
3359
+ */
3360
+ export function autoAspectNeedsSourceImage(modelId: string | undefined, aspectRatio: unknown): boolean {
3361
+ if (!modelId || !isAutoAspectToken(aspectRatio)) return false
3362
+ const ratios = MODEL_CATALOG[modelId]?.aspectRatios
3363
+ return ratios !== undefined && ratios.length > 0 && !ratios.some(isAutoAspectToken)
3364
+ }
3365
+
3250
3366
  /**
3251
3367
  * Coerce a model's parameters into a combination the model actually accepts.
3252
3368
  *
@@ -3261,6 +3377,10 @@ export interface NormalizedModelInput {
3261
3377
  *
3262
3378
  * Rules, mirroring the config panels' provider-change snap:
3263
3379
  * - Model has no such lever → drop the value (sending it 400s upstream).
3380
+ * - "auto" on a model whose list lacks it, with a known `context.sourceImage`
3381
+ * → the listed ratio nearest the source's shape (`nearestCatalogAspectRatio`).
3382
+ * "auto" asks to keep the source photo's shape; the first listed ratio
3383
+ * would reframe every source of another shape.
3264
3384
  * - Value outside the model's allow-list → snap to the model's default
3265
3385
  * (`defaultResolutionFor`) or the first valid option.
3266
3386
  * - Then apply cross-field constraints that only hold for certain models.
@@ -3279,6 +3399,7 @@ export function normalizeModelInput(
3279
3399
  quality?: string
3280
3400
  duration?: number
3281
3401
  },
3402
+ context: ModelInputContext = {},
3282
3403
  ): NormalizedModelInput {
3283
3404
  const m = MODEL_CATALOG[modelId]
3284
3405
  const adjustments: ModelInputAdjustment[] = []
@@ -3321,7 +3442,22 @@ export function normalizeModelInput(
3321
3442
  return next
3322
3443
  }
3323
3444
 
3324
- out.aspectRatio = snap("aspectRatio", input.aspectRatio, m.aspectRatios)
3445
+ const sourceRatio =
3446
+ autoAspectNeedsSourceImage(modelId, input.aspectRatio) && usableSize(context.sourceImage)
3447
+ ? nearestCatalogAspectRatio(context.sourceImage.width, context.sourceImage.height, m.aspectRatios ?? [])
3448
+ : undefined
3449
+ if (sourceRatio !== undefined && input.aspectRatio !== undefined) {
3450
+ const { width, height } = context.sourceImage!
3451
+ adjustments.push({
3452
+ field: "aspectRatio",
3453
+ from: input.aspectRatio,
3454
+ to: sourceRatio,
3455
+ reason: `${m.label} has no "auto" aspect ratio — using "${sourceRatio}", the supported ratio closest to the source image's shape (${width}x${height}).`,
3456
+ })
3457
+ out.aspectRatio = sourceRatio
3458
+ } else {
3459
+ out.aspectRatio = snap("aspectRatio", input.aspectRatio, m.aspectRatios)
3460
+ }
3325
3461
  out.resolution = snap(
3326
3462
  "resolution",
3327
3463
  input.resolution,
@@ -102,7 +102,9 @@ export const MAX_IMAGE_PROMPT_CHARS_BY_PROVIDER: Record<string, number> = {
102
102
  // verified == 5000 default (no entry needed): imagen4(-fast/-ultra), nano-banana,
103
103
  // nano-banana-edit, flux, flux-flex, gpt-image-2, ideogram-v3/-edit/-remix,
104
104
  // grok, qwen-i2i, seedream-5-pro, seedream-5-pro-i2i
105
- // (docs.kie.ai/market/seedream/5-pro-text-to-image + 5-pro-image-to-image).
105
+ // (docs.kie.ai/market/seedream/5-pro-text-to-image + 5-pro-image-to-image),
106
+ // seedream-5-flash, seedream-5-flash-i2i (both "4–5000 characters";
107
+ // docs.kie.ai/market/seedream/5-flash-text-to-image + 5-flash-image-to-image).
106
108
  // grok-i2i: doc states 390000 (78× its t2i sibling) — treated as a KIE schema
107
109
  // typo and left at the 5000 default per the sanity-cap decision.
108
110
  // UNVERIFIED (no limit stated in schema) → 5000 default: flux-kontext(-max)
@@ -503,6 +505,7 @@ export const MODELS_WITH_REFERENCE_IMAGE_SUPPORT = new Set([
503
505
  "seedream",
504
506
  "seedream-5-lite",
505
507
  "seedream-5-pro",
508
+ "seedream-5-flash",
506
509
  "flux",
507
510
  "flux-flex",
508
511
  // Image editing / image-to-image (reference = source image)
@@ -523,6 +526,7 @@ export const MODELS_WITH_REFERENCE_IMAGE_SUPPORT = new Set([
523
526
  "seedream-edit",
524
527
  "seedream-5-lite-i2i",
525
528
  "seedream-5-pro-i2i",
529
+ "seedream-5-flash-i2i",
526
530
  "grok-i2i",
527
531
  // Upscale / background ops (source acts as the reference)
528
532
  "recraft-remove-bg",
@@ -558,6 +562,7 @@ export const T2I_TO_I2I_VARIANT: Record<string, string> = {
558
562
  "seedream": "seedream-edit",
559
563
  "seedream-5-lite": "seedream-5-lite-i2i",
560
564
  "seedream-5-pro": "seedream-5-pro-i2i",
565
+ "seedream-5-flash": "seedream-5-flash-i2i",
561
566
  "flux": "flux-pro-i2i",
562
567
  "flux-flex": "flux-i2i",
563
568
  }
@@ -593,6 +598,8 @@ export const REF_IMAGE_MAX_LIMITS: Record<string, number> = {
593
598
  "seedream-edit": 16,
594
599
  "seedream-5-lite-i2i": 16,
595
600
  "seedream-5-pro-i2i": 16,
601
+ // Flash takes at most 10 `image_urls` (docs.kie.ai/market/seedream/5-flash-image-to-image) — not the family's 16.
602
+ "seedream-5-flash-i2i": 10,
596
603
  // Single-source i2i (one input image)
597
604
  "flux-kontext": 1,
598
605
  "flux-kontext-max": 1,
@@ -633,7 +640,8 @@ export const DEFAULT_REF_IMAGE_MAX = 4
633
640
  * route silently routes to the i2i sibling ({@link T2I_TO_I2I_VARIANT}) —
634
641
  * the endpoint that actually consumes refs — so the advertised cap is the
635
642
  * SIBLING's (grok→grok-i2i = 1, gpt-image-2→gpt-image-2-i2i = 16), never the
636
- * t2i id's absent default. Mirrors the route's `resolveEffectiveProvider`.
643
+ * t2i id's absent default. Mirrors the swap `resolveNormalizedImageGen`
644
+ * makes for the route and the workflow run alike.
637
645
  * 2. {@link REF_IMAGE_MAX_LIMITS} is the PRODUCT/UI cap, which may be
638
646
  * intentionally TIGHTER than the raw provider schema (e.g. flux-2-pro = 4
639
647
  * here though the BFL schema accepts 8; flux-2-klein = 1 though the array
@@ -732,6 +740,7 @@ export const IMAGE_GEN_PROVIDERS = [
732
740
  "seedream",
733
741
  "seedream-5-lite",
734
742
  "seedream-5-pro",
743
+ "seedream-5-flash",
735
744
  "flux-flex",
736
745
  "flux-kontext",
737
746
  "flux-kontext-max",
@@ -766,6 +775,7 @@ export const IMAGE_I2I_PROVIDERS = [
766
775
  "seedream-edit",
767
776
  "seedream-5-lite-i2i",
768
777
  "seedream-5-pro-i2i",
778
+ "seedream-5-flash-i2i",
769
779
  "flux-kontext",
770
780
  "flux-kontext-max",
771
781
  // Replicate Open (uncensored) — multi-image Kontext via Replicate
@@ -1535,6 +1545,7 @@ export const IMAGE_MASK_MODE: Record<ImageGenProvider, ImageMaskMode> = {
1535
1545
  "seedream": "prompt",
1536
1546
  "seedream-5-lite": "prompt",
1537
1547
  "seedream-5-pro": "prompt",
1548
+ "seedream-5-flash": "prompt",
1538
1549
  "qwen": "prompt",
1539
1550
  "flux-kontext": "prompt",
1540
1551
  "flux-kontext-max": "prompt",
@@ -181,6 +181,9 @@ const QUALITY_MAP: Record<string, QualityMapping> = {
181
181
  "seedream-5-lite-i2i": { field: "quality", values: { low: "basic", mid: "basic", high: "high" } },
182
182
  "seedream-5-pro": { field: "quality", values: { low: "basic", mid: "basic", high: "high" } },
183
183
  "seedream-5-pro-i2i": { field: "quality", values: { low: "basic", mid: "basic", high: "high" } },
184
+ // Seedream 5 Flash's lever is size (sent as KIE `size`), flat-priced — resolution-style.
185
+ "seedream-5-flash": { field: "resolution", values: { low: "1K", mid: "2K", high: "2K" } },
186
+ "seedream-5-flash-i2i": { field: "resolution", values: { low: "1K", mid: "2K", high: "2K" } },
184
187
  // Video gen — resolution-style (720p/1080p)
185
188
  "veo3": { field: "resolution", values: { low: "720p", mid: "1080p", high: "1080p" } },
186
189
  "veo3.1": { field: "resolution", values: { low: "720p", mid: "1080p", high: "1080p" } },
@@ -72,6 +72,9 @@ export const EXECUTION_DATA_KEYS: ReadonlySet<string> = new Set([
72
72
  "__pickedTotal",
73
73
  "__restTotal",
74
74
  "generatedJson",
75
+ // A render's remapped transcript on its own pip (Speaker View's
76
+ // `transcript`, RENDER_NODE_TYPES transcriptOutput) — run-result data.
77
+ "generatedTranscript",
75
78
  // Edit Plan: a person's review of the plan (`EditedEdl`, edit-plan-review.ts),
76
79
  // kept beside `generatedJson` and fingerprinted against it. Run-result data
77
80
  // (TA14, decided 2026-10-04): out of undo, presets, templates and exports,
@@ -20,7 +20,8 @@
20
20
  * is covered without touching this file.
21
21
  */
22
22
 
23
- import { normalizeModelInput, type ModelInputAdjustment } from "./model-catalog.js"
23
+ import { autoAspectNeedsSourceImage, normalizeModelInput, type ModelInputAdjustment } from "./model-catalog.js"
24
+ import { imageGenAutoAspectNeedsSourceImage } from "./credit-identifiers.js"
24
25
 
25
26
  /**
26
27
  * Node types whose `data` carries catalog-governed model parameters under the
@@ -44,6 +45,35 @@ export const MODEL_PARAM_NODE_TYPES: ReadonlySet<string> = new Set([
44
45
  "edit-image",
45
46
  ])
46
47
 
48
+ /**
49
+ * The image node types that transform a SOURCE image (their required `image`
50
+ * input). On these "auto" means "keep the source photo's shape", and the run
51
+ * resolves it against that image — natively on a model that lists "auto", else
52
+ * to the model's nearest listed ratio (`normalizeModelInput`'s `sourceImage`).
53
+ *
54
+ * `generate-image` is absent: its photo is optional, and it is the first image
55
+ * its references ASSEMBLE to, not a node input — see
56
+ * `AUTO_ASPECT_AT_RUN_NODE_TYPES`.
57
+ */
58
+ export const SOURCE_IMAGE_NODE_TYPES: ReadonlySet<string> = new Set([
59
+ "image-to-image",
60
+ "modify-image",
61
+ "edit-image",
62
+ ])
63
+
64
+ /**
65
+ * The node types whose "auto" aspect ratio the RUN resolves against a photo,
66
+ * so a write boundary (which has no photo) keeps it: the source-image types,
67
+ * plus `generate-image`, whose photo is the first reference the run assembles
68
+ * (or its inpaint / refine base). A Generate Image run with no photo snaps
69
+ * "auto" exactly as this boundary used to — the value that reaches a provider
70
+ * never changes there.
71
+ */
72
+ export const AUTO_ASPECT_AT_RUN_NODE_TYPES: ReadonlySet<string> = new Set([
73
+ ...SOURCE_IMAGE_NODE_TYPES,
74
+ "generate-image",
75
+ ])
76
+
47
77
  export interface NodeParamAdjustment extends ModelInputAdjustment {
48
78
  nodeId: string
49
79
  provider: string
@@ -97,12 +127,25 @@ export function normalizeNodeModelParams<T extends NodeLike>(
97
127
  : undefined
98
128
  if (!provider) return node
99
129
 
130
+ // A write boundary has no photo, so "auto" on a node the run resolves it for
131
+ // is left for the run to resolve against the photo — snapping it here would
132
+ // discard the very request ("keep my photo's shape") the run can honour. It
133
+ // is stored in its canonical spelling, the one the image routes' ratio enum
134
+ // accepts. A Generate Image run snaps against its model's i2i sibling once
135
+ // references attach, and this boundary cannot count them (wired ones come
136
+ // from edges), so it asks about both.
137
+ const deferAuto = AUTO_ASPECT_AT_RUN_NODE_TYPES.has(type) && (
138
+ type === "generate-image"
139
+ ? imageGenAutoAspectNeedsSourceImage({ provider, aspectRatio: d.aspectRatio })
140
+ : autoAspectNeedsSourceImage(provider, d.aspectRatio)
141
+ )
100
142
  const normalized = normalizeModelInput(provider, {
101
- aspectRatio: typeof d.aspectRatio === "string" ? d.aspectRatio : undefined,
143
+ aspectRatio: !deferAuto && typeof d.aspectRatio === "string" ? d.aspectRatio : undefined,
102
144
  resolution: typeof d.resolution === "string" ? d.resolution : undefined,
103
145
  quality: typeof d.quality === "string" ? d.quality : undefined,
104
146
  })
105
- if (normalized.adjustments.length === 0) return node
147
+ const respell = deferAuto && d.aspectRatio !== "auto"
148
+ if (normalized.adjustments.length === 0 && !respell) return node
106
149
 
107
150
  const nodeId = typeof node.id === "string" ? node.id : "(unknown node)"
108
151
  for (const adj of normalized.adjustments) {
@@ -116,7 +159,7 @@ export function normalizeNodeModelParams<T extends NodeLike>(
116
159
  ...node,
117
160
  data: {
118
161
  ...d,
119
- aspectRatio: normalized.aspectRatio,
162
+ aspectRatio: deferAuto ? "auto" : normalized.aspectRatio,
120
163
  resolution: normalized.resolution,
121
164
  quality: normalized.quality,
122
165
  },
@@ -95,16 +95,29 @@ export type PipelinePinnableVideoModel = (typeof PIPELINE_PINNABLE_VIDEO_MODELS)
95
95
  // the upfront credit reservation. Adding GPT/Gemini support requires routing
96
96
  // through `lib/llm-client.ts` first; until then, keep this list tight.
97
97
  export const PIPELINE_PINNABLE_SCRIPT_LLMS = [
98
- "claude-haiku-4-5",
98
+ "claude-haiku-5-5",
99
99
  "claude-sonnet-4-6",
100
100
  "claude-opus-4-7",
101
101
  "claude-opus-5",
102
102
  ] as const
103
- export type PipelinePinnableScriptLlm = (typeof PIPELINE_PINNABLE_SCRIPT_LLMS)[number]
103
+
104
+ // Script LLMs no longer OFFERED as a pin but still honoured when a saved
105
+ // pipeline names one: Claude Haiku 5.5 replaced Claude Haiku 4.5 in the picker
106
+ // (decided 2026-10-10), and a pipeline pinned to Haiku 4.5 before that keeps
107
+ // its pin.
108
+ export const PIPELINE_LEGACY_PINNED_SCRIPT_LLMS = ["claude-haiku-4-5"] as const
109
+
110
+ /** Every script LLM a pipeline's config may name: the offered pins plus the legacy ones. */
111
+ export const PIPELINE_ACCEPTED_SCRIPT_LLMS = [
112
+ ...PIPELINE_PINNABLE_SCRIPT_LLMS,
113
+ ...PIPELINE_LEGACY_PINNED_SCRIPT_LLMS,
114
+ ] as const
115
+ /** A script LLM a pipeline config may carry — an offered pin or a legacy one a saved pipeline still names. */
116
+ export type PipelinePinnableScriptLlm = (typeof PIPELINE_ACCEPTED_SCRIPT_LLMS)[number]
104
117
 
105
118
  const ImageModelEnum = z.enum(PIPELINE_ACCEPTED_IMAGE_MODELS)
106
119
  const VideoModelEnum = z.enum(PIPELINE_PINNABLE_VIDEO_MODELS)
107
- const ScriptLlmEnum = z.enum(PIPELINE_PINNABLE_SCRIPT_LLMS)
120
+ const ScriptLlmEnum = z.enum(PIPELINE_ACCEPTED_SCRIPT_LLMS)
108
121
 
109
122
  // Per-stage override map. Each stage key maps to a model id valid for its
110
123
  // kind. Defined as a discriminated shape (instead of `Record<stage, string>`)
@@ -386,6 +386,10 @@ export const FAN_IN_TARGETS: Readonly<Record<string, "*" | readonly string[]>> =
386
386
  "merge-lists": "*",
387
387
  "sort-list": "*",
388
388
  selector: "*",
389
+ // Speaker Frames on a clip pack (P3-24 (a), decided 2026-10-06): ONE run over
390
+ // the union of the clips' spans — the pack's EDLs fold onto its `edl` wire
391
+ // instead of running one detection job (and one minimum charge) per clip.
392
+ "speaker-frames": ["edl"],
389
393
  }
390
394
 
391
395
  export function isFanInNodeType(nodeType: string | undefined | null): boolean {
@@ -27,6 +27,21 @@ export type RenderClockSource = "input" | "output-json"
27
27
  * on as one (Add Captions, the word-timing preflight). */
28
28
  export type RenderJsonKind = "transcript" | "edl"
29
29
 
30
+ /** Where a render's wired transcript, remapped through its cut, comes out
31
+ * (Apply EDL's on its `json`; Speaker View's on its own `transcript` pip,
32
+ * decided 2026-10-08). */
33
+ export interface RenderTranscriptOutput {
34
+ /** The output pip — also the key it rides on the job's `output_data` and on
35
+ * a run's node output. */
36
+ readonly handle: string
37
+ /** The saved node-data field that holds it (the landed take's). */
38
+ readonly dataField: string
39
+ }
40
+
41
+ /** The pip a render's `json` output (its `jsonKind`) comes out on, and its key
42
+ * on the job's `output_data`. */
43
+ export const RENDER_JSON_HANDLE = "json"
44
+
30
45
  export interface RenderNodeDescriptor {
31
46
  /** The medium the render's order asks for (its node data, or its job's
32
47
  * `input_data`) — before any output exists to say. */
@@ -42,6 +57,9 @@ export interface RenderNodeDescriptor {
42
57
  * (TA6, decided 2026-10-04). */
43
58
  readonly latestBatch: boolean
44
59
  readonly jsonKind: RenderJsonKind
60
+ /** Where its remapped transcript comes out. On the `json` pip exactly when
61
+ * `jsonKind` is `transcript` (a guard test holds the two together). */
62
+ readonly transcriptOutput: RenderTranscriptOutput
45
63
  }
46
64
 
47
65
  type Data = Readonly<Record<string, unknown>>
@@ -49,7 +67,8 @@ type Data = Readonly<Record<string, unknown>>
49
67
  /** Its `output` setting, video when absent. */
50
68
  const outputSettingMedium = (data: Data): RenderMedium => (data.output === "audio" ? "audio" : "video")
51
69
 
52
- const descriptor = (d: RenderNodeDescriptor): RenderNodeDescriptor => Object.freeze({ ...d })
70
+ const descriptor = (d: RenderNodeDescriptor): RenderNodeDescriptor =>
71
+ Object.freeze({ ...d, transcriptOutput: Object.freeze({ ...d.transcriptOutput }) })
53
72
 
54
73
  export const RENDER_NODE_TYPES: Readonly<Record<string, RenderNodeDescriptor>> = Object.freeze({
55
74
  "apply-edl": descriptor({
@@ -59,10 +78,13 @@ export const RENDER_NODE_TYPES: Readonly<Record<string, RenderNodeDescriptor>> =
59
78
  ownerOnlyListing: true,
60
79
  latestBatch: true,
61
80
  jsonKind: "transcript",
81
+ transcriptOutput: { handle: RENDER_JSON_HANDLE, dataField: "generatedJson" },
62
82
  }),
63
83
  // Speaker View (C3.2): video only; its `json` is the EDL as it drew it (the
64
84
  // turns split, the layouts written), so a player maps the output clock
65
- // through THAT, and Add Captions never takes it for a Transcript.
85
+ // through THAT, and Add Captions never takes it for a Transcript. The wired
86
+ // transcript, remapped through that same drawn edit, comes out on its own
87
+ // `transcript` pip (decided 2026-10-08) — what a caption step reads.
66
88
  "speaker-view": descriptor({
67
89
  mediumOf: () => "video",
68
90
  creditId: (quality) => speakerViewCreditId(quality),
@@ -70,6 +92,7 @@ export const RENDER_NODE_TYPES: Readonly<Record<string, RenderNodeDescriptor>> =
70
92
  ownerOnlyListing: true,
71
93
  latestBatch: true,
72
94
  jsonKind: "edl",
95
+ transcriptOutput: { handle: "transcript", dataField: "generatedTranscript" },
73
96
  }),
74
97
  })
75
98
 
@@ -97,6 +120,39 @@ export function rendersTranscriptJson(type: unknown): boolean {
97
120
  return renderNodeOf(type)?.jsonKind === "transcript"
98
121
  }
99
122
 
123
+ /** Where a render's remapped transcript comes out; `undefined` for any other
124
+ * node type. */
125
+ export function renderTranscriptOutputOf(type: unknown): RenderTranscriptOutput | undefined {
126
+ return renderNodeOf(type)?.transcriptOutput
127
+ }
128
+
129
+ /** Is `handle` one of a render's data pips — its `json` or its transcript —
130
+ * rather than its media? Every other pip of a render (the default included)
131
+ * is the rendered media. `false` for any other node type. */
132
+ export function isRenderDataHandle(type: unknown, handle: unknown): boolean {
133
+ const d = renderNodeOf(type)
134
+ if (!d || typeof handle !== "string") return false
135
+ return handle === RENDER_JSON_HANDLE || handle === d.transcriptOutput.handle
136
+ }
137
+
138
+ /** One json output a render lands on its node: its key on the job's
139
+ * `output_data` (and on a run's node output) and its saved node-data field. */
140
+ export interface RenderSavedJsonOutput {
141
+ readonly outputKey: string
142
+ readonly dataField: string
143
+ }
144
+
145
+ /** The json outputs a render lands on its node, `json` first, each once — what
146
+ * every lane that lands a take (or picks one) writes or restores. Empty for
147
+ * any other node type. */
148
+ export function renderSavedJsonOutputs(type: unknown): readonly RenderSavedJsonOutput[] {
149
+ const d = renderNodeOf(type)
150
+ if (!d) return []
151
+ const json: RenderSavedJsonOutput = { outputKey: RENDER_JSON_HANDLE, dataField: "generatedJson" }
152
+ const t = d.transcriptOutput
153
+ return t.handle === RENDER_JSON_HANDLE ? [json] : [json, { outputKey: t.handle, dataField: t.dataField }]
154
+ }
155
+
100
156
  /** The render job types that list in their owner's own views only. */
101
157
  export const OWNER_ONLY_LISTING_RENDER_TYPES: readonly string[] = Object.freeze(
102
158
  RENDER_NODE_TYPE_IDS.filter((t) => RENDER_NODE_TYPES[t]!.ownerOnlyListing),
@@ -1,3 +1,4 @@
1
+ import { IMAGE_MODEL_ROLE_DEFAULTS } from "./image-model-roles.js"
1
2
  /**
2
3
  * The "Settings" input: ONE input handle on a generation node that takes the
3
4
  * Generation Settings nodes. Aspect Ratio, Duration and Provider set the
@@ -107,7 +108,7 @@ const SETTINGS_CONSUMERS: Readonly<Record<string, SettingsConsumer>> = {
107
108
  models: IMAGE_GEN_PROVIDERS,
108
109
  // The node's own default (NODE_DEFINITIONS) — only used to fit a wired
109
110
  // ratio when the node names no model.
110
- defaultModel: "nano-banana-pro",
111
+ defaultModel: IMAGE_MODEL_ROLE_DEFAULTS.general,
111
112
  modelList: "providers",
112
113
  },
113
114
  }