cheapgen 0.1.2 → 0.2.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/src/request.js CHANGED
@@ -5,16 +5,25 @@ import fs from 'node:fs';
5
5
  import path from 'node:path';
6
6
  import { usageError } from './errors.js';
7
7
  import { frameSize } from './pricing/formulas.js';
8
+ import { probeImage, probeAudio, nearestRatio } from './media.js';
9
+ import { variantFor } from './catalog.js';
8
10
 
9
11
  /**
10
12
  * @typedef {object} CanonicalRequest
11
13
  * @property {string} model
12
14
  * @property {'video'|'image'} kind
13
15
  * @property {string} [frameSeries]
14
- * @property {'text-to-video'|'image-to-video'|'text-to-image'} mode
16
+ * @property {'text-to-video'|'image-to-video'|'reference-to-video'|'text-to-image'|'image-edit'} mode
15
17
  * @property {string} [prompt]
16
18
  * @property {string} [image] URL, or absolute local path when imageIsLocal
17
19
  * @property {boolean} [imageIsLocal]
20
+ * @property {InputImage} [lastImage] image-to-video: the last frame
21
+ * @property {InputImage[]} [refImages] reference-to-video: the reference images, in the order given
22
+ * @property {InputAudio[]} [refAudio] reference-to-video: the reference audio files, in the order given
23
+ * @property {InputImage[]} [images] image-edit: the input images, in the order given
24
+ * @property {number|null} [inputPixels] image-edit: total pixels of the inputs; null when any is a URL
25
+ * @property {string|null} [effectiveAspect] image-edit with aspect "auto": the model's ratio closest to
26
+ * the first input; null when that input is a URL
18
27
  * @property {string} [resolution] video
19
28
  * @property {string} [size] image
20
29
  * @property {string} aspectRatio
@@ -25,6 +34,37 @@ import { frameSize } from './pricing/formulas.js';
25
34
  * @property {number} count
26
35
  */
27
36
 
37
+ /**
38
+ * @typedef {object} InputImage
39
+ * @property {string} source URL, or absolute local path when isLocal
40
+ * @property {boolean} isLocal
41
+ * @property {'png'|'jpeg'|'webp'} [type] local files only, read from the file's bytes
42
+ * @property {number} [bytes]
43
+ * @property {number} [width]
44
+ * @property {number} [height]
45
+ */
46
+
47
+ /**
48
+ * @typedef {object} InputAudio
49
+ * @property {string} source URL, or absolute local path when isLocal
50
+ * @property {boolean} isLocal
51
+ * @property {'wav'|'mp3'} [type] local files only, read from the file's bytes
52
+ * @property {number} [bytes]
53
+ * @property {number|null} [seconds] null when the file doesn't state its length
54
+ */
55
+
56
+ /** No provider takes a larger input image. */
57
+ export const MAX_INPUT_IMAGE_BYTES = 30_000_000;
58
+ /** What the video models accept as a first frame, last frame or reference image. */
59
+ const FRAME_SIDE = Object.freeze({ min: 300, max: 6000 });
60
+ const FRAME_RATIO = Object.freeze({ min: 0.4, max: 2.5 });
61
+ const MAX_AUDIO_BYTES = 15_000_000;
62
+ const MIN_AUDIO_SECONDS = 2;
63
+ /** Encoders pad a clip by a few hundredths of a second; providers allow about this much. */
64
+ const AUDIO_SLACK_SECONDS = 0.2;
65
+ const REFERENCE_MODE = 'reference-to-video';
66
+ export const AUTO_ASPECT = 'auto';
67
+
28
68
  export const DEFAULTS = Object.freeze({ resolution: '720p', duration: 5, aspectRatio: '16:9', audio: true, size: '1K' });
29
69
 
30
70
  const isUrl = (s) => /^https?:\/\//i.test(s);
@@ -33,10 +73,11 @@ const isUrl = (s) => /^https?:\/\//i.test(s);
33
73
  * @param {string} modelId
34
74
  * @param {object} flags parsed command-line values
35
75
  * @param {object} catalog
36
- * @param {{ cwd: string, requirePrompt: boolean }} opts
76
+ * @param {{ cwd: string, requirePrompt: boolean, allowVariants?: boolean }} opts `allowVariants`
77
+ * accepts a resolution that only a provider's variant of the model sells
37
78
  * @returns {CanonicalRequest}
38
79
  */
39
- export function buildCanonicalRequest(modelId, flags, catalog, { cwd, requirePrompt }) {
80
+ export function buildCanonicalRequest(modelId, flags, catalog, { cwd, requirePrompt, allowVariants = false }) {
40
81
  if (!modelId) throw usageError('name a model, for example: cheapgen quote seedance-2.0-mini');
41
82
  const model = catalog.models[modelId];
42
83
  if (!model) {
@@ -48,24 +89,45 @@ export function buildCanonicalRequest(modelId, flags, catalog, { cwd, requirePro
48
89
  throw usageError('--prompt is required');
49
90
  }
50
91
 
92
+ // --image is repeatable on the command line; other callers may pass one value.
93
+ const given = flags.image === undefined ? [] : [flags.image].flat();
94
+ const editing = model.kind === 'image' && given.length > 0;
95
+ if (model.kind !== 'image' && given.length > 1) {
96
+ throw usageError(`${modelId} takes one --image (the first frame), got ${given.length}`);
97
+ }
98
+
99
+ const lastGiven = [flags['last-image'] ?? []].flat();
100
+ const refImagesGiven = [flags['ref-image'] ?? []].flat();
101
+ const refAudioGiven = [flags['ref-audio'] ?? []].flat();
102
+ if (model.kind === 'image') {
103
+ const flag = lastGiven.length ? '--last-image' : refImagesGiven.length ? '--ref-image' : refAudioGiven.length ? '--ref-audio' : null;
104
+ if (flag) throw usageError(`${flag} applies to video models; ${modelId} is an image model`);
105
+ }
106
+
51
107
  let image;
52
108
  let imageIsLocal = false;
53
- if (flags.image !== undefined) {
54
- if (isUrl(flags.image)) image = flags.image;
109
+ if (model.kind !== 'image' && given.length === 1) {
110
+ if (isUrl(given[0])) image = given[0];
55
111
  else {
56
- image = path.resolve(cwd, flags.image);
57
- if (!fs.existsSync(image)) throw usageError(`--image file not found: ${flags.image}`);
112
+ image = path.resolve(cwd, given[0]);
113
+ if (!fs.existsSync(image)) throw usageError(`--image file not found: ${given[0]}`);
58
114
  imageIsLocal = true;
115
+ // A first frame cheapgen can read is checked against the model's limits; other files pass as they are.
116
+ const info = readImage(image);
117
+ if (info) checkFrame(info, given[0], '--image');
59
118
  }
60
119
  }
61
120
 
62
- const aspectRatio = flags.aspect ?? DEFAULTS.aspectRatio;
63
- if (!model.aspectRatios.includes(aspectRatio)) {
121
+ const aspectRatio = flags.aspect ?? (editing ? AUTO_ASPECT : DEFAULTS.aspectRatio);
122
+ if (aspectRatio === AUTO_ASPECT && !editing) {
123
+ throw usageError('--aspect auto follows an input image, so it needs --image on an image model. '
124
+ + `Choose one of: ${model.aspectRatios.join(', ')}`);
125
+ }
126
+ if (aspectRatio !== AUTO_ASPECT && !model.aspectRatios.includes(aspectRatio)) {
64
127
  throw usageError(`${modelId} doesn't support aspect ratio ${aspectRatio}. Choose one of: ${model.aspectRatios.join(', ')}`);
65
128
  }
66
129
 
67
130
  if (model.kind === 'image') {
68
- if (image) throw usageError(`${modelId} is a text-to-image model; --image isn't supported yet`);
69
131
  for (const f of ['res', 'duration', 'audio', 'no-audio']) {
70
132
  if (flags[f] !== undefined) throw usageError(`--${f} doesn't apply to image models`);
71
133
  }
@@ -74,16 +136,37 @@ export function buildCanonicalRequest(modelId, flags, catalog, { cwd, requirePro
74
136
  throw usageError(`${modelId} doesn't support size ${size}. Choose one of: ${model.sizes.join(', ')}`);
75
137
  }
76
138
  const frameSeries = model.frameSeries ?? modelId;
77
- // Pixels for providers that take explicit sizes; null when the model has no table.
78
- const pixels = frameSize({ frameSeries, size, aspectRatio }, catalog.frameSizes);
79
- return withMode(model, { model: modelId, kind: 'image', frameSeries,
80
- mode: 'text-to-image', prompt, size, aspectRatio, pixels, count: 1 });
139
+ if (!editing) {
140
+ // Pixels for providers that take explicit sizes; null when the model has no table.
141
+ const pixels = frameSize({ frameSeries, size, aspectRatio }, catalog.frameSizes);
142
+ return withMode(model, { model: modelId, kind: 'image', frameSeries,
143
+ mode: 'text-to-image', prompt, size, aspectRatio, pixels, count: 1 });
144
+ }
145
+
146
+ if (!model.modes.includes('image-edit')) {
147
+ throw usageError(`${modelId} is a text-to-image model; it doesn't take input images`);
148
+ }
149
+ const max = model.edit?.maxImages;
150
+ if (max && given.length > max) {
151
+ throw usageError(`${modelId} takes at most ${max} input images, got ${given.length}`);
152
+ }
153
+ const images = given.map((src) => inputImage(src, cwd));
154
+ const first = images[0];
155
+ const effectiveAspect = aspectRatio !== AUTO_ASPECT ? null
156
+ : first.isLocal ? nearestRatio(first.width, first.height, model.aspectRatios) : null;
157
+ const sizedBy = aspectRatio === AUTO_ASPECT ? effectiveAspect : aspectRatio;
158
+ const pixels = sizedBy ? frameSize({ frameSeries, size, aspectRatio: sizedBy }, catalog.frameSizes) : null;
159
+ const inputPixels = images.every((i) => i.isLocal) ? images.reduce((sum, i) => sum + i.width * i.height, 0) : null;
160
+ return withMode(model, { model: modelId, kind: 'image', frameSeries, mode: 'image-edit', prompt, size, aspectRatio,
161
+ effectiveAspect, pixels, images: Object.freeze(images), inputPixels, count: 1 });
81
162
  }
82
163
 
83
164
  if (flags.size !== undefined) throw usageError('--size applies to image models; use --res for video');
84
165
  const resolution = flags.res ?? DEFAULTS.resolution;
85
- if (!model.resolutions.includes(resolution)) {
86
- throw usageError(`${modelId} doesn't support ${resolution}. Choose one of: ${model.resolutions.join(', ')}`);
166
+ const variant = variantFor(model, resolution);
167
+ if (!model.resolutions.includes(resolution) && !(variant && allowVariants)) {
168
+ throw usageError(`${modelId} doesn't support ${resolution}. Choose one of: ${model.resolutions.join(', ')}`
169
+ + (variant ? `. ${variant.note} To allow that, run: cheapgen config set allowVariants true` : ''));
87
170
  }
88
171
 
89
172
  let duration = DEFAULTS.duration;
@@ -110,13 +193,159 @@ export function buildCanonicalRequest(modelId, flags, catalog, { cwd, requirePro
110
193
  if (flags.audio && flags['no-audio']) throw usageError('pass either --audio or --no-audio, not both');
111
194
  const audio = flags['no-audio'] ? false : DEFAULTS.audio;
112
195
 
196
+ // The model takes a first frame, a first and last frame, or references: never a mix.
197
+ const referencing = refImagesGiven.length + refAudioGiven.length > 0;
198
+ if (lastGiven.length > 1) throw usageError(`${modelId} takes one --last-image, got ${lastGiven.length}`);
199
+ if (referencing && (given.length || lastGiven.length)) {
200
+ throw usageError('--ref-image and --ref-audio can\'t be combined with --image or --last-image: the model takes a first '
201
+ + 'frame, a first and last frame, or references, not a mix');
202
+ }
203
+ if (lastGiven.length && !given.length) throw usageError('--last-image needs --image (the first frame)');
204
+ const lastImage = lastGiven.length ? frameImage(lastGiven[0], cwd, '--last-image') : undefined;
205
+ const references = referencing ? referenceInputs(modelId, model, refImagesGiven, refAudioGiven, prompt, cwd) : {};
206
+
113
207
  return withMode(model, {
114
208
  model: modelId, kind: 'video', frameSeries: model.frameSeries ?? modelId,
115
- mode: image ? 'image-to-video' : 'text-to-video',
209
+ mode: referencing ? REFERENCE_MODE : image ? 'image-to-video' : 'text-to-video',
116
210
  prompt, image, imageIsLocal, resolution, aspectRatio, duration, autoDuration, maxDuration: max, audio, count: 1,
211
+ ...(lastImage ? { lastImage } : {}),
212
+ ...references,
213
+ ...(variant ? { variant: Object.freeze({ id: variant.id, provider: variant.provider, label: variant.label, note: variant.note }) } : {}),
117
214
  });
118
215
  }
119
216
 
217
+ /** The reference images and audio of a reference-to-video request, checked against the model's limits. */
218
+ function referenceInputs(modelId, model, imagesGiven, audioGiven, prompt, cwd) {
219
+ const limits = model.references;
220
+ if (!limits || !model.modes.includes(REFERENCE_MODE)) throw usageError(`${modelId} doesn't take reference images or audio`);
221
+ if (imagesGiven.length > limits.maxImages) {
222
+ throw usageError(`${modelId} takes at most ${limits.maxImages} reference images, got ${imagesGiven.length}`);
223
+ }
224
+ if (audioGiven.length > limits.maxAudio) {
225
+ throw usageError(`${modelId} takes at most ${limits.maxAudio} reference audio files, got ${audioGiven.length}`);
226
+ }
227
+ if (!imagesGiven.length && !limits.audioAlone) {
228
+ throw usageError(`${modelId} can't use reference audio alone: add at least one reference image (--ref-image)`);
229
+ }
230
+ const refImages = imagesGiven.map((src) => frameImage(src, cwd, '--ref-image'));
231
+ const maxSeconds = limits.maxAudioSeconds;
232
+ const refAudio = audioGiven.map((src) => inputAudio(src, cwd, modelId, maxSeconds));
233
+ const total = refAudio.reduce((sum, a) => sum + (a.seconds ?? 0), 0);
234
+ if (maxSeconds && total > maxSeconds + AUDIO_SLACK_SECONDS) {
235
+ throw usageError(`the --ref-audio files add up to ${total.toFixed(1)} seconds. ${modelId} takes at most ${maxSeconds} `
236
+ + 'seconds of reference audio in total.');
237
+ }
238
+ for (const name of promptNames(prompt)) {
239
+ const have = name.kind === 'image' ? refImages.length : refAudio.length;
240
+ if (name.number < 1 || name.number > have) {
241
+ const what = name.kind === 'image' ? 'reference image' : 'reference audio file';
242
+ throw usageError(`the prompt names @${name.kind}${name.number}, but ${have === 0 ? `no ${what} was` : `only ${have} ${what}${have === 1 ? ' was' : 's were'}`} given`);
243
+ }
244
+ }
245
+ return { refImages: Object.freeze(refImages), refAudio: Object.freeze(refAudio) };
246
+ }
247
+
248
+ // An input named in the prompt: "@image1", "@Image 1" or "[Image1]" (the spellings fal,
249
+ // WaveSpeed and Replicate document), and the same for audio.
250
+ const PROMPT_NAME = /(?<![\w@])@(image|audio) ?(\d+)(?!\w)|\[(image|audio) ?(\d+)\]/gi;
251
+ const PROMPT_NAME_STYLES = Object.freeze({
252
+ plain: (kind, n) => `@${kind}${n}`,
253
+ spaced: (kind, n) => `@${kind} ${n}`,
254
+ bracket: (kind, n) => `[${kind}${n}]`,
255
+ });
256
+ const capitalized = (kind) => kind[0].toUpperCase() + kind.slice(1).toLowerCase();
257
+
258
+ /** The inputs a prompt names, as `{ kind: 'image'|'audio', number }`. */
259
+ export function promptNames(prompt) {
260
+ if (typeof prompt !== 'string') return [];
261
+ return [...prompt.matchAll(PROMPT_NAME)].map((m) => ({ kind: (m[1] ?? m[3]).toLowerCase(), number: Number(m[2] ?? m[4]) }));
262
+ }
263
+
264
+ /**
265
+ * The prompt with each named input written the way one provider documents it: `plain`
266
+ * ("@Image1"), `spaced` ("@Image 1") or `bracket` ("[Image1]"). Only a reference-to-video
267
+ * request has names; any other prompt is returned as it is.
268
+ */
269
+ export function promptFor(request, style) {
270
+ if (request.mode !== REFERENCE_MODE || typeof request.prompt !== 'string') return request.prompt;
271
+ const write = PROMPT_NAME_STYLES[style];
272
+ return request.prompt.replace(PROMPT_NAME, (_, k1, n1, k2, n2) => write(capitalized(k1 ?? k2), Number(n1 ?? n2)));
273
+ }
274
+
275
+ /** What a local image file is, or null when it isn't a PNG, JPEG or WebP that can be read. */
276
+ function readImage(file) {
277
+ try { return probeImage(file); } catch { return null; }
278
+ }
279
+
280
+ /** Refuses an image the video models don't accept as a frame or a reference. */
281
+ function checkFrame(info, src, flag) {
282
+ if (info.bytes > MAX_INPUT_IMAGE_BYTES) {
283
+ throw usageError(`${flag} ${src} is ${(info.bytes / 1e6).toFixed(1)} MB. Input images can be at most `
284
+ + `${MAX_INPUT_IMAGE_BYTES / 1e6} MB.`);
285
+ }
286
+ const size = `${info.width}×${info.height}`;
287
+ if (Math.min(info.width, info.height) < FRAME_SIDE.min || Math.max(info.width, info.height) > FRAME_SIDE.max) {
288
+ throw usageError(`${flag} ${src} is ${size} pixels. Each side must be between ${FRAME_SIDE.min} and ${FRAME_SIDE.max} pixels.`);
289
+ }
290
+ const ratio = info.width / info.height;
291
+ if (ratio < FRAME_RATIO.min || ratio > FRAME_RATIO.max) {
292
+ throw usageError(`${flag} ${src} is ${size} pixels. Its width divided by its height must be between `
293
+ + `${FRAME_RATIO.min} and ${FRAME_RATIO.max}.`);
294
+ }
295
+ }
296
+
297
+ /** A last frame or reference image: a URL is passed through unread; a local file is measured and checked. */
298
+ function frameImage(src, cwd, flag) {
299
+ if (isUrl(src)) return Object.freeze({ source: src, isLocal: false });
300
+ const file = path.resolve(cwd, src);
301
+ if (!fs.existsSync(file)) throw usageError(`${flag} file not found: ${src}`);
302
+ const info = readImage(file);
303
+ if (!info) throw usageError(`${flag} ${src} isn't a PNG, JPEG or WebP image. It must be one of those three.`);
304
+ checkFrame(info, src, flag);
305
+ return Object.freeze({ source: file, isLocal: true, ...info });
306
+ }
307
+
308
+ /** A reference audio file: a URL is passed through unread; a local file is measured and checked. */
309
+ function inputAudio(src, cwd, modelId, maxSeconds) {
310
+ if (isUrl(src)) return Object.freeze({ source: src, isLocal: false });
311
+ const file = path.resolve(cwd, src);
312
+ if (!fs.existsSync(file)) throw usageError(`--ref-audio file not found: ${src}`);
313
+ let info = null;
314
+ try { info = probeAudio(file); } catch { info = null; }
315
+ if (!info) throw usageError(`--ref-audio ${src} isn't a WAV or MP3 file. Reference audio must be one of those two.`);
316
+ if (info.bytes > MAX_AUDIO_BYTES) {
317
+ throw usageError(`--ref-audio ${src} is ${(info.bytes / 1e6).toFixed(1)} MB. Reference audio can be at most `
318
+ + `${MAX_AUDIO_BYTES / 1e6} MB.`);
319
+ }
320
+ // An MP3 that doesn't state its length is passed on unchecked.
321
+ if (info.seconds !== null && maxSeconds
322
+ && (info.seconds < MIN_AUDIO_SECONDS - AUDIO_SLACK_SECONDS || info.seconds > maxSeconds + AUDIO_SLACK_SECONDS)) {
323
+ throw usageError(`--ref-audio ${src} is ${info.seconds.toFixed(1)} seconds long. ${modelId} takes reference audio of `
324
+ + `${MIN_AUDIO_SECONDS} to ${maxSeconds} seconds.`);
325
+ }
326
+ return Object.freeze({ source: file, isLocal: true, ...info });
327
+ }
328
+
329
+ /** The warning shown when a request is for a provider's variant of the model. */
330
+ export function variantWarning(request) {
331
+ return `${request.resolution} on ${request.model} is a variant: ${request.variant.note}`;
332
+ }
333
+
334
+ /** One input image: a URL is passed through unread; a local file is measured and checked. */
335
+ function inputImage(src, cwd) {
336
+ if (isUrl(src)) return Object.freeze({ source: src, isLocal: false });
337
+ const file = path.resolve(cwd, src);
338
+ if (!fs.existsSync(file)) throw usageError(`--image file not found: ${src}`);
339
+ let info = null;
340
+ try { info = probeImage(file); } catch { info = null; }
341
+ if (!info) throw usageError(`--image ${src} isn't a PNG, JPEG or WebP image. Input images must be one of those three.`);
342
+ if (info.bytes > MAX_INPUT_IMAGE_BYTES) {
343
+ throw usageError(`--image ${src} is ${(info.bytes / 1e6).toFixed(1)} MB. Input images can be at most `
344
+ + `${MAX_INPUT_IMAGE_BYTES / 1e6} MB.`);
345
+ }
346
+ return Object.freeze({ source: file, isLocal: true, ...info });
347
+ }
348
+
120
349
  function withMode(model, request) {
121
350
  if (!model.modes.includes(request.mode)) {
122
351
  throw usageError(`${request.model} doesn't support ${request.mode}. It supports: ${model.modes.join(', ')}`);
@@ -124,25 +353,49 @@ function withMode(model, request) {
124
353
  return Object.freeze(request);
125
354
  }
126
355
 
127
- /** The request as priced: an auto duration is priced at the model's maximum. */
128
- export const pricedRequest = (request) =>
129
- (request.autoDuration ? { ...request, duration: request.maxDuration } : request);
356
+ /**
357
+ * The request as priced: an auto duration is priced at the model's maximum, and an edit that
358
+ * follows its input image at the ratio worked out from that image.
359
+ */
360
+ export function pricedRequest(request) {
361
+ if (request.autoDuration) return { ...request, duration: request.maxDuration };
362
+ if (request.aspectRatio === AUTO_ASPECT && request.effectiveAspect) return { ...request, aspectRatio: request.effectiveAspect };
363
+ return request;
364
+ }
130
365
 
131
366
  /** Parameters written to the spend log. Never the prompt. */
132
367
  export function logParams(request) {
133
- if (request.kind === 'image') return { size: request.size, aspectRatio: request.aspectRatio, count: request.count };
368
+ if (request.kind === 'image') {
369
+ return { size: request.size, aspectRatio: request.aspectRatio, count: request.count,
370
+ ...(request.images ? { inputImages: request.images.length } : {}) };
371
+ }
134
372
  return {
135
373
  resolution: request.resolution,
136
374
  duration: request.autoDuration ? 'auto' : request.duration,
137
375
  aspectRatio: request.aspectRatio,
138
376
  audio: request.audio,
139
377
  ...(request.image ? { image: true } : {}),
378
+ ...(request.lastImage ? { lastImage: true } : {}),
379
+ ...(request.mode === REFERENCE_MODE ? { refImages: request.refImages.length, refAudio: request.refAudio.length } : {}),
140
380
  };
141
381
  }
142
382
 
383
+ /** What a video request was given besides the prompt, e.g. "first + last frame" or "2 images, 1 audio". */
384
+ function describeInputs(r) {
385
+ if (r.lastImage) return ['first + last frame'];
386
+ if (r.mode !== REFERENCE_MODE) return [];
387
+ const images = r.refImages.length;
388
+ const counts = [...(images ? [`${images} image${images === 1 ? '' : 's'}`] : []),
389
+ ...(r.refAudio.length ? [`${r.refAudio.length} audio`] : [])];
390
+ return [counts.join(', ')];
391
+ }
392
+
143
393
  /** A one-line description, e.g. "seedance-2.0-mini · text-to-video · 480p · 5s · 16:9 · audio on". */
144
394
  export function describeRequest(r) {
145
- if (r.kind === 'image') return [r.model, r.mode, r.size, r.aspectRatio].join(' · ');
146
- return [r.model, r.mode, r.resolution, r.autoDuration ? `auto (up to ${r.maxDuration}s)` : `${r.duration}s`,
395
+ if (r.kind === 'image') {
396
+ const inputs = r.images ? [`${r.images.length} image${r.images.length === 1 ? '' : 's'}`] : [];
397
+ return [r.model, r.mode, ...inputs, r.size, r.aspectRatio].join(' · ');
398
+ }
399
+ return [r.model, r.mode, ...describeInputs(r), r.resolution, r.autoDuration ? `auto (up to ${r.maxDuration}s)` : `${r.duration}s`,
147
400
  r.aspectRatio, r.audio ? 'audio on' : 'audio off'].join(' · ');
148
401
  }