@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.
- package/dist/index.cjs +726 -174
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +569 -34
- package/dist/index.d.ts +569 -34
- package/dist/index.js +667 -175
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/auto-aspect-source.test.ts +372 -0
- package/src/__tests__/camera-switch-contract.test.ts +10 -0
- package/src/__tests__/collections.test.ts +10 -0
- package/src/__tests__/edl.test.ts +319 -4
- package/src/__tests__/json-kinds.test.ts +11 -1
- package/src/__tests__/llm-models.test.ts +120 -8
- package/src/__tests__/pitch-tempo-pricing.test.ts +62 -0
- package/src/__tests__/render-nodes.test.ts +84 -5
- package/src/__tests__/transcribe-preflight.test.ts +5 -0
- package/src/__tests__/video-depth.test.ts +146 -0
- package/src/__tests__/video-mask.test.ts +77 -0
- package/src/camera-switch-contract.ts +9 -6
- package/src/collections.ts +72 -2
- package/src/credit-estimators/index.ts +10 -0
- package/src/credit-estimators/pitch-tempo.ts +68 -0
- package/src/credit-identifiers.ts +87 -19
- package/src/edl.ts +143 -23
- package/src/fan-out-rows.ts +3 -1
- package/src/i18n/camera-format.ko.ts +3 -3
- package/src/index.ts +35 -0
- package/src/json-kinds.ts +11 -6
- package/src/llm-models.ts +87 -2
- package/src/mask-composite.ts +108 -0
- package/src/model-catalog.ts +146 -4
- package/src/model-constants.ts +2 -1
- package/src/model-tree.ts +2 -0
- package/src/node-mappable-fields.ts +2 -0
- package/src/node-runtime-keys.ts +3 -0
- package/src/normalize-node-params.ts +47 -4
- package/src/pipeline-types.ts +16 -3
- package/src/presentation-utils.ts +3 -2
- package/src/producer-types.ts +13 -0
- package/src/render-nodes.ts +71 -6
- package/src/transcribe-preflight.ts +11 -10
- package/src/video-depth.ts +151 -0
- package/src/video-mask.ts +96 -0
package/package.json
CHANGED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest"
|
|
2
|
+
import {
|
|
3
|
+
MODEL_CATALOG,
|
|
4
|
+
autoAspectNeedsSourceImage,
|
|
5
|
+
fitAspectRatioToModel,
|
|
6
|
+
nearestCatalogAspectRatio,
|
|
7
|
+
normalizeModelInput,
|
|
8
|
+
validateModelInput,
|
|
9
|
+
} from "../model-catalog.js"
|
|
10
|
+
import { imageGenAutoAspectNeedsSourceImage, normalizedImageGenModelId, resolveNormalizedImageGen } from "../credit-identifiers.js"
|
|
11
|
+
import { IMAGE_ASPECT_RATIO_VALUES, T2I_TO_I2I_VARIANT } from "../model-constants.js"
|
|
12
|
+
import { normalizeNodeModelParams, AUTO_ASPECT_AT_RUN_NODE_TYPES, SOURCE_IMAGE_NODE_TYPES } from "../normalize-node-params.js"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* "auto" means "keep the source photo's shape". A model that lists "auto"
|
|
16
|
+
* receives it as is. A model that does not would otherwise have "auto" snapped
|
|
17
|
+
* to its FIRST listed ratio, which reframes every source of another shape — so
|
|
18
|
+
* when the request carries a source image, "auto" becomes the model's supported
|
|
19
|
+
* ratio nearest the source's aspect instead.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** The fixed eight-ratio list a model with no "match the input" option takes. */
|
|
23
|
+
const SEEDREAM_LIST = MODEL_CATALOG["seedream-5-pro-i2i"]!.aspectRatios!
|
|
24
|
+
/** A list without 21:9, for the wide-cinema case. */
|
|
25
|
+
const NO_WIDE_LIST = ["1:1", "16:9", "9:16", "4:3", "3:4"] as const
|
|
26
|
+
|
|
27
|
+
/** Runs `fn` with a made-up text-to-image model and its image-to-image sibling
|
|
28
|
+
* registered (their ratio lists as given), then removes both — for the pairs
|
|
29
|
+
* today's catalog does not have. */
|
|
30
|
+
function withModelPair(textToImageRatios: string[] | undefined, siblingRatios: string[] | undefined, fn: (provider: string) => void) {
|
|
31
|
+
const provider = "pair-probe"
|
|
32
|
+
const sibling = "pair-probe-i2i"
|
|
33
|
+
const base = MODEL_CATALOG["seedream-5-pro"]!
|
|
34
|
+
MODEL_CATALOG[provider] = { ...base, label: "Pair probe", aspectRatios: textToImageRatios }
|
|
35
|
+
MODEL_CATALOG[sibling] = { ...base, label: "Pair probe edit", aspectRatios: siblingRatios }
|
|
36
|
+
T2I_TO_I2I_VARIANT[provider] = sibling
|
|
37
|
+
try {
|
|
38
|
+
fn(provider)
|
|
39
|
+
} finally {
|
|
40
|
+
delete MODEL_CATALOG[provider]
|
|
41
|
+
delete MODEL_CATALOG[sibling]
|
|
42
|
+
delete T2I_TO_I2I_VARIANT[provider]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe("nearestCatalogAspectRatio", () => {
|
|
47
|
+
it("returns the listed ratio a source already has", () => {
|
|
48
|
+
expect(nearestCatalogAspectRatio(1600, 1200, SEEDREAM_LIST)).toBe("4:3")
|
|
49
|
+
expect(nearestCatalogAspectRatio(1080, 1920, SEEDREAM_LIST)).toBe("9:16")
|
|
50
|
+
expect(nearestCatalogAspectRatio(1024, 1024, SEEDREAM_LIST)).toBe("1:1")
|
|
51
|
+
expect(nearestCatalogAspectRatio(1500, 1000, SEEDREAM_LIST)).toBe("3:2")
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it("reads a phone portrait as 3:4", () => {
|
|
55
|
+
expect(nearestCatalogAspectRatio(1104, 1472, SEEDREAM_LIST)).toBe("3:4")
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it("maps a 2.39:1 frame to the nearest listed ratio — 21:9 when listed, else 16:9", () => {
|
|
59
|
+
expect(nearestCatalogAspectRatio(2390, 1000, SEEDREAM_LIST)).toBe("21:9")
|
|
60
|
+
expect(nearestCatalogAspectRatio(2390, 1000, NO_WIDE_LIST)).toBe("16:9")
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it("compares in log space, so a portrait and its landscape mirror are symmetric", () => {
|
|
64
|
+
expect(nearestCatalogAspectRatio(1000, 2390, NO_WIDE_LIST)).toBe("9:16")
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it("ignores entries that are not ratios", () => {
|
|
68
|
+
expect(nearestCatalogAspectRatio(1600, 1200, ["auto", "match_input_image", "adaptive", "4:3"])).toBe("4:3")
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it("breaks a tie by the order the catalog lists the ratios", () => {
|
|
72
|
+
// A square source is exactly as far from 4:3 as from 3:4.
|
|
73
|
+
expect(nearestCatalogAspectRatio(1000, 1000, ["4:3", "3:4"])).toBe("4:3")
|
|
74
|
+
expect(nearestCatalogAspectRatio(1000, 1000, ["3:4", "4:3"])).toBe("3:4")
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The tie rule belongs to the source-size path alone. The ratio-TOKEN fit
|
|
79
|
+
* keeps the strict comparison every video lane shares (the provider
|
|
80
|
+
* adapters' snap and the MCP normalizer): 4:3 sits exactly between 16:9 and
|
|
81
|
+
* 1:1 in log space, and those lanes answer 1:1.
|
|
82
|
+
*/
|
|
83
|
+
it("leaves the ratio-token fit as it was", () => {
|
|
84
|
+
for (const id of ["kling", "kling-3-omni", "wan-turbo", "bytedance-lite", "bytedance-pro"]) {
|
|
85
|
+
expect(fitAspectRatioToModel(id, "4:3"), id).toBe("1:1")
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it("answers undefined for unusable dimensions or a list with no ratios", () => {
|
|
90
|
+
expect(nearestCatalogAspectRatio(0, 1000, SEEDREAM_LIST)).toBeUndefined()
|
|
91
|
+
expect(nearestCatalogAspectRatio(1000, -5, SEEDREAM_LIST)).toBeUndefined()
|
|
92
|
+
expect(nearestCatalogAspectRatio(Number.NaN, 1000, SEEDREAM_LIST)).toBeUndefined()
|
|
93
|
+
expect(nearestCatalogAspectRatio(Number.POSITIVE_INFINITY, 1000, SEEDREAM_LIST)).toBeUndefined()
|
|
94
|
+
expect(nearestCatalogAspectRatio(1000, 1000, ["auto"])).toBeUndefined()
|
|
95
|
+
expect(nearestCatalogAspectRatio(1000, 1000, [])).toBeUndefined()
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe("autoAspectNeedsSourceImage", () => {
|
|
100
|
+
it("is true only for 'auto' on a model whose ratio list lacks it", () => {
|
|
101
|
+
expect(autoAspectNeedsSourceImage("seedream-5-pro-i2i", "auto")).toBe(true)
|
|
102
|
+
expect(autoAspectNeedsSourceImage("seedream-5-pro-i2i", " Auto ")).toBe(true)
|
|
103
|
+
// A native auto goes to the provider untouched.
|
|
104
|
+
expect(autoAspectNeedsSourceImage("gpt-image-2-i2i", "auto")).toBe(false)
|
|
105
|
+
// A concrete ratio is not asking for the source's shape.
|
|
106
|
+
expect(autoAspectNeedsSourceImage("seedream-5-pro-i2i", "16:9")).toBe(false)
|
|
107
|
+
expect(autoAspectNeedsSourceImage("seedream-5-pro-i2i", undefined)).toBe(false)
|
|
108
|
+
// No ratio lever at all, or a model the catalog does not know.
|
|
109
|
+
expect(autoAspectNeedsSourceImage("grok-i2i", "auto")).toBe(false)
|
|
110
|
+
expect(autoAspectNeedsSourceImage("not-a-model", "auto")).toBe(false)
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
describe("normalizeModelInput — 'auto' with a source image", () => {
|
|
115
|
+
const portrait = { width: 1104, height: 1472 }
|
|
116
|
+
|
|
117
|
+
it("picks the supported ratio nearest the source and says so", () => {
|
|
118
|
+
const out = normalizeModelInput("seedream-5-pro-i2i", { aspectRatio: "auto" }, { sourceImage: portrait })
|
|
119
|
+
expect(out.aspectRatio).toBe("3:4")
|
|
120
|
+
expect(out.adjustments).toHaveLength(1)
|
|
121
|
+
expect(out.adjustments[0]).toMatchObject({ field: "aspectRatio", from: "auto", to: "3:4" })
|
|
122
|
+
expect(out.adjustments[0].reason).toContain("source image")
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it("keeps today's answer when no source size is known", () => {
|
|
126
|
+
const today = normalizeModelInput("seedream-5-pro-i2i", { aspectRatio: "auto" })
|
|
127
|
+
expect(today.aspectRatio).toBe(SEEDREAM_LIST[0])
|
|
128
|
+
expect(normalizeModelInput("seedream-5-pro-i2i", { aspectRatio: "auto" }, {})).toEqual(today)
|
|
129
|
+
expect(normalizeModelInput("seedream-5-pro-i2i", { aspectRatio: "auto" }, { sourceImage: undefined })).toEqual(today)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it("keeps today's answer when the source size is unusable", () => {
|
|
133
|
+
const today = normalizeModelInput("seedream-5-pro-i2i", { aspectRatio: "auto" })
|
|
134
|
+
const out = normalizeModelInput("seedream-5-pro-i2i", { aspectRatio: "auto" }, { sourceImage: { width: 0, height: 900 } })
|
|
135
|
+
expect(out).toEqual(today)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it("leaves a native 'auto' alone even when the source size is known", () => {
|
|
139
|
+
const out = normalizeModelInput("gpt-image-2-i2i", { aspectRatio: "auto" }, { sourceImage: portrait })
|
|
140
|
+
expect(out.aspectRatio).toBe("auto")
|
|
141
|
+
expect(out.adjustments).toEqual([])
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it("never second-guesses a concrete ratio", () => {
|
|
145
|
+
expect(normalizeModelInput("seedream-5-pro-i2i", { aspectRatio: "16:9" }, { sourceImage: portrait }).aspectRatio).toBe("16:9")
|
|
146
|
+
// An off-list ratio still snaps exactly as it does without a source image.
|
|
147
|
+
const off = normalizeModelInput("seedream-5-pro-i2i", { aspectRatio: "4:5" }, { sourceImage: portrait })
|
|
148
|
+
expect(off).toEqual(normalizeModelInput("seedream-5-pro-i2i", { aspectRatio: "4:5" }))
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it("still drops the value for a model with no ratio lever", () => {
|
|
152
|
+
const out = normalizeModelInput("grok-i2i", { aspectRatio: "auto" }, { sourceImage: portrait })
|
|
153
|
+
expect(out.aspectRatio).toBeUndefined()
|
|
154
|
+
expect(out.adjustments[0]?.to).toBeUndefined()
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it("reads 'auto' in any case", () => {
|
|
158
|
+
const out = normalizeModelInput("seedream-5-pro-i2i", { aspectRatio: "AUTO" }, { sourceImage: { width: 1920, height: 1080 } })
|
|
159
|
+
expect(out.aspectRatio).toBe("16:9")
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it("INVARIANT: every image model without a native auto resolves to one of its own ratios", () => {
|
|
163
|
+
const sources = [
|
|
164
|
+
{ width: 1104, height: 1472 },
|
|
165
|
+
{ width: 1920, height: 1080 },
|
|
166
|
+
{ width: 2390, height: 1000 },
|
|
167
|
+
{ width: 1000, height: 1000 },
|
|
168
|
+
{ width: 400, height: 3200 },
|
|
169
|
+
]
|
|
170
|
+
const failures: string[] = []
|
|
171
|
+
for (const [id, m] of Object.entries(MODEL_CATALOG)) {
|
|
172
|
+
if (m.kind !== "image" || !autoAspectNeedsSourceImage(id, "auto")) continue
|
|
173
|
+
for (const sourceImage of sources) {
|
|
174
|
+
const out = normalizeModelInput(id, { aspectRatio: "auto" }, { sourceImage })
|
|
175
|
+
const issue = validateModelInput(id, { aspectRatio: out.aspectRatio })
|
|
176
|
+
if (issue || out.aspectRatio === "auto") failures.push(`${id} ${sourceImage.width}x${sourceImage.height} → ${out.aspectRatio}`)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
expect(failures).toEqual([])
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
describe("resolveNormalizedImageGen — source image", () => {
|
|
184
|
+
it("threads the source size into the snap", () => {
|
|
185
|
+
const out = resolveNormalizedImageGen({
|
|
186
|
+
provider: "seedream-5-pro-i2i",
|
|
187
|
+
aspectRatio: "auto",
|
|
188
|
+
quality: "high",
|
|
189
|
+
refCount: 1,
|
|
190
|
+
sourceImage: { width: 1920, height: 1080 },
|
|
191
|
+
})
|
|
192
|
+
expect(out.aspectRatio).toBe("16:9")
|
|
193
|
+
expect(out.quality).toBe("high")
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The credit CHECK (route preHandler) runs before the source image is read,
|
|
198
|
+
* so it prices "auto" with no size; the DEBIT prices the resolved ratio. They
|
|
199
|
+
* agree only because, on every model this rule touches, the ratio is not a
|
|
200
|
+
* pricing dimension. This pins that across the whole catalog: a model added
|
|
201
|
+
* later that prices by ratio fails here instead of under-billing in silence.
|
|
202
|
+
*/
|
|
203
|
+
it("INVARIANT: on a model without a native auto, the ratio never changes the credit id", () => {
|
|
204
|
+
const failures: string[] = []
|
|
205
|
+
for (const [id, m] of Object.entries(MODEL_CATALOG)) {
|
|
206
|
+
if (m.kind !== "image" || !autoAspectNeedsSourceImage(id, "auto")) continue
|
|
207
|
+
const qualities: Array<string | undefined> = [undefined, ...(m.qualities ?? [])]
|
|
208
|
+
const resolutions: Array<string | undefined> = [undefined, ...(m.resolutions ?? [])]
|
|
209
|
+
for (const quality of qualities) {
|
|
210
|
+
for (const resolution of resolutions) {
|
|
211
|
+
for (const refCount of [0, 1, 3]) {
|
|
212
|
+
// Generate Image prices with the T2I→I2I swap (references attached);
|
|
213
|
+
// the image-to-image / edit routes price without it.
|
|
214
|
+
for (const swapToI2i of [false, true]) {
|
|
215
|
+
const base = { provider: id, quality, resolution, refCount, swapToI2i }
|
|
216
|
+
const at = `${id} q=${quality} r=${resolution} refs=${refCount} swap=${swapToI2i}`
|
|
217
|
+
const priced = resolveNormalizedImageGen({ ...base, aspectRatio: "auto" }).identifier
|
|
218
|
+
const sizes = [{ width: 1104, height: 1472 }, { width: 2390, height: 1000 }]
|
|
219
|
+
for (const sourceImage of sizes) {
|
|
220
|
+
const withSource = resolveNormalizedImageGen({ ...base, aspectRatio: "auto", sourceImage }).identifier
|
|
221
|
+
if (withSource !== priced) failures.push(`${at}: ${priced} vs ${withSource}`)
|
|
222
|
+
}
|
|
223
|
+
for (const ratio of m.aspectRatios ?? []) {
|
|
224
|
+
const listed = resolveNormalizedImageGen({ ...base, aspectRatio: ratio }).identifier
|
|
225
|
+
if (listed !== priced) failures.push(`${at} ${ratio}: ${priced} vs ${listed}`)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
expect(failures).toEqual([])
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
it("names the model the snap runs against — the i2i variant once references attach", () => {
|
|
236
|
+
expect(normalizedImageGenModelId({ provider: "seedream-5-pro", refCount: 1, swapToI2i: true })).toBe("seedream-5-pro-i2i")
|
|
237
|
+
expect(normalizedImageGenModelId({ provider: "seedream-5-pro", refCount: 0, swapToI2i: true })).toBe("seedream-5-pro")
|
|
238
|
+
expect(normalizedImageGenModelId({ provider: "seedream-5-pro", refCount: 2, swapToI2i: false })).toBe("seedream-5-pro")
|
|
239
|
+
expect(normalizedImageGenModelId({ provider: "nano-banana-2", refCount: 1, swapToI2i: true })).toBe("nano-banana-2")
|
|
240
|
+
expect(normalizedImageGenModelId({ provider: undefined, refCount: 0 })).toBe("nano-banana")
|
|
241
|
+
// The same id the snap itself reports, for every swap pair.
|
|
242
|
+
for (const t2i of Object.keys(T2I_TO_I2I_VARIANT)) {
|
|
243
|
+
const opts = { provider: t2i, refCount: 1, swapToI2i: true }
|
|
244
|
+
expect(normalizedImageGenModelId(opts), t2i).toBe(resolveNormalizedImageGen(opts).modelId)
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it("asks whether 'auto' needs the photo about the model the snap runs against", () => {
|
|
249
|
+
const needs = (provider: string, refCount?: number, aspectRatio: string = "auto") =>
|
|
250
|
+
imageGenAutoAspectNeedsSourceImage({ provider, aspectRatio, refCount })
|
|
251
|
+
// With the assembled reference count: exactly that model. grok's sibling
|
|
252
|
+
// takes no ratio, so once a reference attaches there is nothing to resolve.
|
|
253
|
+
expect(needs("grok", 0)).toBe(true)
|
|
254
|
+
expect(needs("grok", 1)).toBe(false)
|
|
255
|
+
expect(needs("seedream-5-pro", 1)).toBe(true)
|
|
256
|
+
expect(needs("gpt-image-2", 1)).toBe(false)
|
|
257
|
+
expect(needs("nano-banana-2", 2)).toBe(autoAspectNeedsSourceImage("nano-banana-2", "auto"))
|
|
258
|
+
expect(needs("seedream-5-pro", 1, "16:9")).toBe(false)
|
|
259
|
+
// Before assembly (no count): either model, since references may yet attach.
|
|
260
|
+
expect(needs("grok")).toBe(true)
|
|
261
|
+
withModelPair(["auto", "1:1"], ["1:1", "16:9"], (p) => {
|
|
262
|
+
expect(needs(p, 0)).toBe(false)
|
|
263
|
+
expect(needs(p, 1)).toBe(true)
|
|
264
|
+
expect(needs(p)).toBe(true)
|
|
265
|
+
})
|
|
266
|
+
withModelPair(["auto", "1:1"], ["auto", "1:1"], (p) => expect(needs(p)).toBe(false))
|
|
267
|
+
withModelPair(undefined, undefined, (p) => expect(needs(p)).toBe(false))
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* The routes write the resolved ratio back through their own Zod enum
|
|
272
|
+
* (`applySnappedLevers`), which leaves a value the enum does not carry
|
|
273
|
+
* untouched — so a ratio a model lists but the shared vocabulary lacks would
|
|
274
|
+
* send the caller's "auto" on to a model that cannot take it.
|
|
275
|
+
*/
|
|
276
|
+
it("INVARIANT: every ratio an image model lists is in the routes' ratio vocabulary", () => {
|
|
277
|
+
const vocabulary = new Set<string>(IMAGE_ASPECT_RATIO_VALUES)
|
|
278
|
+
const missing: string[] = []
|
|
279
|
+
for (const [id, m] of Object.entries(MODEL_CATALOG)) {
|
|
280
|
+
if (m.kind !== "image") continue
|
|
281
|
+
for (const ratio of m.aspectRatios ?? []) if (!vocabulary.has(ratio)) missing.push(`${id}:${ratio}`)
|
|
282
|
+
}
|
|
283
|
+
expect(missing).toEqual([])
|
|
284
|
+
})
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
describe("normalizeNodeModelParams — 'auto' on a node that transforms a source image", () => {
|
|
288
|
+
const node = (id: string, type: string, data: Record<string, unknown>) => ({ id, type, data })
|
|
289
|
+
|
|
290
|
+
it("names the node types that carry a source image", () => {
|
|
291
|
+
expect([...SOURCE_IMAGE_NODE_TYPES].sort()).toEqual(["edit-image", "image-to-image", "modify-image"])
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
it("names the node types whose 'auto' the run resolves — the source-image ones plus Generate Image", () => {
|
|
295
|
+
expect([...AUTO_ASPECT_AT_RUN_NODE_TYPES].sort()).toEqual(["edit-image", "generate-image", "image-to-image", "modify-image"])
|
|
296
|
+
for (const type of SOURCE_IMAGE_NODE_TYPES) expect(AUTO_ASPECT_AT_RUN_NODE_TYPES.has(type), type).toBe(true)
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
it("keeps 'auto' for the run to resolve against the photo", () => {
|
|
300
|
+
for (const type of AUTO_ASPECT_AT_RUN_NODE_TYPES) {
|
|
301
|
+
const provider = type === "edit-image" ? "nano-banana-edit" : type === "generate-image" ? "seedream-5-pro" : "seedream-5-pro-i2i"
|
|
302
|
+
const input = [node("n", type, { provider, aspectRatio: "auto" })]
|
|
303
|
+
const { nodes, adjustments } = normalizeNodeModelParams(input)
|
|
304
|
+
expect(adjustments, type).toEqual([])
|
|
305
|
+
expect(nodes[0], type).toBe(input[0])
|
|
306
|
+
}
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
it("writes the canonical spelling so the route's enum accepts it", () => {
|
|
310
|
+
const { nodes, adjustments } = normalizeNodeModelParams([
|
|
311
|
+
node("n", "modify-image", { provider: "seedream-5-pro-i2i", aspectRatio: " Auto " }),
|
|
312
|
+
])
|
|
313
|
+
expect((nodes[0].data as Record<string, unknown>).aspectRatio).toBe("auto")
|
|
314
|
+
expect(adjustments).toEqual([])
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
it("still corrects the other levers on the same node", () => {
|
|
318
|
+
const { nodes, adjustments } = normalizeNodeModelParams([
|
|
319
|
+
node("n", "image-to-image", { provider: "seedream-5-pro-i2i", aspectRatio: "auto", quality: "medium" }),
|
|
320
|
+
])
|
|
321
|
+
const d = nodes[0].data as Record<string, unknown>
|
|
322
|
+
expect(d.aspectRatio).toBe("auto")
|
|
323
|
+
expect(d.quality).toBe("basic")
|
|
324
|
+
expect(adjustments.map((a) => a.field)).toEqual(["quality"])
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
it("keeps 'auto' on a Generate Image node too, so a wired photo can decide it at run time", () => {
|
|
328
|
+
const input = [node("g", "generate-image", { provider: "seedream-5-pro", aspectRatio: "auto" })]
|
|
329
|
+
const { nodes, adjustments } = normalizeNodeModelParams(input)
|
|
330
|
+
expect(adjustments).toEqual([])
|
|
331
|
+
expect(nodes[0]).toBe(input[0])
|
|
332
|
+
// With no photo the run snaps it to exactly what this boundary used to store.
|
|
333
|
+
expect(normalizeModelInput("seedream-5-pro", { aspectRatio: "auto" }).aspectRatio).toBe(SEEDREAM_LIST[0])
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
it("keeps 'auto' on a Generate Image node whose image-to-image sibling resolves it from the photo", () => {
|
|
337
|
+
// The node's own model has no ratio lever; references would swap the run to
|
|
338
|
+
// a sibling that lists ratios but no auto, so the run can still use the photo.
|
|
339
|
+
withModelPair(undefined, ["1:1", "16:9"], (provider) => {
|
|
340
|
+
const input = [node("g", "generate-image", { provider, aspectRatio: "auto" })]
|
|
341
|
+
const { nodes, adjustments } = normalizeNodeModelParams(input)
|
|
342
|
+
expect(adjustments).toEqual([])
|
|
343
|
+
expect(nodes[0]).toBe(input[0])
|
|
344
|
+
// Only Generate Image swaps on references: another node type asks about its own model.
|
|
345
|
+
const other = normalizeNodeModelParams([node("m", "modify-image", { provider, aspectRatio: "auto" })])
|
|
346
|
+
expect((other.nodes[0].data as Record<string, unknown>).aspectRatio).toBeUndefined()
|
|
347
|
+
})
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
it("still drops 'auto' on a model with no ratio lever", () => {
|
|
351
|
+
const { nodes } = normalizeNodeModelParams([
|
|
352
|
+
node("e", "edit-image", { provider: "recraft-upscale", aspectRatio: "auto" }),
|
|
353
|
+
])
|
|
354
|
+
expect((nodes[0].data as Record<string, unknown>).aspectRatio).toBeUndefined()
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
it("leaves a native 'auto' alone, as before", () => {
|
|
358
|
+
const input = [node("m", "modify-image", { provider: "gpt-image-2-i2i", aspectRatio: "auto" })]
|
|
359
|
+
const { nodes, adjustments } = normalizeNodeModelParams(input)
|
|
360
|
+
expect(adjustments).toEqual([])
|
|
361
|
+
expect(nodes[0]).toBe(input[0])
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
it("is idempotent", () => {
|
|
365
|
+
const once = normalizeNodeModelParams([
|
|
366
|
+
node("n", "modify-image", { provider: "seedream-5-pro-i2i", aspectRatio: "Auto", quality: "medium" }),
|
|
367
|
+
])
|
|
368
|
+
const twice = normalizeNodeModelParams(once.nodes)
|
|
369
|
+
expect(twice.adjustments).toEqual([])
|
|
370
|
+
expect(twice.nodes[0]).toBe(once.nodes[0])
|
|
371
|
+
})
|
|
372
|
+
})
|
|
@@ -16,6 +16,16 @@ describe("transcriptSpeakerLabels", () => {
|
|
|
16
16
|
expect(transcriptSpeakerLabels({ words: [{ text: "a", startMs: 0, endMs: 1 }] })).toEqual([])
|
|
17
17
|
for (const bad of [undefined, null, "nope", 4, { words: "x" }]) expect(transcriptSpeakerLabels(bad)).toEqual([])
|
|
18
18
|
})
|
|
19
|
+
it("reads through normalizeTranscript (decided 2026-10-08), as the Cloud plugin reads it: an untimed word names no speaker, a point word does, and first appearance is in time order", () => {
|
|
20
|
+
const raw = { words: [
|
|
21
|
+
{ text: "late", start: 5_000, end: 5_400, speaker: "speaker_2" },
|
|
22
|
+
{ text: "point", startMs: 100, endMs: 100, speaker: "speaker_3" },
|
|
23
|
+
{ text: "untimed", speaker: "ghost" },
|
|
24
|
+
{ text: "inverted", startMs: 700, endMs: 300, speaker: "ghost_2" },
|
|
25
|
+
{ text: "early", startMs: 200, endMs: 600, speaker: "speaker_0" },
|
|
26
|
+
] }
|
|
27
|
+
expect(transcriptSpeakerLabels(raw)).toEqual(["speaker_3", "speaker_0", "speaker_2"])
|
|
28
|
+
})
|
|
19
29
|
})
|
|
20
30
|
|
|
21
31
|
describe("cameraSwitchCameras", () => {
|
|
@@ -205,6 +205,16 @@ describe("ingestRecordFromJson", () => {
|
|
|
205
205
|
expect(r.fields).toEqual({ slug: "Markets-Rally", confidence: 0.9, topic: "business" })
|
|
206
206
|
})
|
|
207
207
|
|
|
208
|
+
it("reads a `mediaUrl` as a medium — its kind from `mediaKind`, else from the file's ending — and keeps both as fields too", () => {
|
|
209
|
+
const video = ingestRecordFromJson({ headline: "H", body: "B", mediaUrl: "https://cdn4.telesco.pe/file/a.mp4?token=1", mediaKind: "video" })
|
|
210
|
+
expect(video.media).toEqual([{ type: "video", url: "https://cdn4.telesco.pe/file/a.mp4?token=1" }])
|
|
211
|
+
expect(video.fields).toMatchObject({ mediaUrl: "https://cdn4.telesco.pe/file/a.mp4?token=1", mediaKind: "video" })
|
|
212
|
+
expect(ingestRecordFromJson({ text: "t", mediaUrl: "https://cdn.example.com/p.jpg", mediaKind: "photo" }).media).toEqual([{ type: "image", url: "https://cdn.example.com/p.jpg" }])
|
|
213
|
+
expect(ingestRecordFromJson({ text: "t", mediaUrl: "https://cdn.example.com/clip.webm" }).media).toEqual([{ type: "video", url: "https://cdn.example.com/clip.webm" }])
|
|
214
|
+
expect(ingestRecordFromJson({ text: "t", mediaUrl: "https://example.com/watch?v=1" }).media).toEqual([{ type: "link", url: "https://example.com/watch?v=1" }])
|
|
215
|
+
expect(ingestRecordFromJson({ text: "t", mediaUrl: "", mediaKind: "" }).media).toEqual([])
|
|
216
|
+
})
|
|
217
|
+
|
|
208
218
|
it("a link that is not http(s) is not a link; a NUMERIC id is no key (each run numbers its items from 1), a named id is", () => {
|
|
209
219
|
const r = ingestRecordFromJson({ url: "javascript:alert(1)", id: 7, text: "x" })
|
|
210
220
|
expect(r.url).toBeNull()
|