@makemidas/cli 0.3.1 → 0.4.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/README.md CHANGED
@@ -1,11 +1,13 @@
1
- # MakeMidas CLI: AI image and video generation for AI agents
1
+ # MakeMidas CLI: AI image, video and audio generation for AI agents
2
2
 
3
3
  An AI image, video and audio generation CLI for Claude Code, Cursor, Codex,
4
4
  Gemini CLI, OpenClaw and people at a terminal. One command reaches Nano
5
5
  Banana, GPT Image, Seedream, Flux, Seedance, Kling, Veo, Wan, Suno, Lyria,
6
6
  Gemini TTS, Whisper and more through [MakeMidas](https://makemidas.com), paid
7
7
  with your MakeMidas credits. It also transcribes audio, removes backgrounds,
8
- upscales images and videos, and compares image models side by side. Coding
8
+ upscales images and videos, lip-syncs talking avatars, renders HTML
9
+ templates and your own HTML to images and videos, makes short films from a
10
+ brief, and compares image models side by side. Coding
9
11
  agents run it like any other command; the
10
12
  [agent skill](https://github.com/makemidas-ai/skills) teaches them the
11
13
  options, and the same account works in ChatGPT and Claude through the
@@ -18,6 +20,8 @@ makemidas image "a lighthouse at dawn, film photo" --aspect 16:9
18
20
  makemidas video "the waves roll in" --ref lighthouse.png --duration 5
19
21
  makemidas speech "Welcome back." --delivery "warm and unhurried"
20
22
  makemidas transcribe interview.m4a --format srt
23
+ makemidas render quote-card --set quote="Make it simple." --set author=Ada
24
+ makemidas film new "a 15-second social video for our mugs" --style social --max-credits 30
21
25
  ```
22
26
 
23
27
  ## Commands
@@ -36,9 +40,15 @@ makemidas transcribe interview.m4a --format srt
36
40
  | `remove-bg <image>` | Remove the background; saves a transparent WebP |
37
41
  | `upscale <image> [--scale 1\|2\|4\|8]` | Upscale an image (1 sharpens at the same size; default 2) |
38
42
  | `upscale-video <video> [--resolution 1080P\|2K\|4K]` | Upscale an MP4 or MOV clip of up to 60 s (default 2K) |
43
+ | `avatar <photo> <voice>` | Lip-sync a portrait to a voice track (a talking avatar video); `--character <id>` in place of the photo ([below](#talking-avatars)) |
39
44
  | `compare "<prompt>" --models a,b[,c,d]` | One prompt on 2–4 image models, one image each |
45
+ | `templates [<category>]`, `template <id>` | HTML templates (built-in and saved), their fields and today's free renders |
46
+ | `render <id> --set f=v…` | Fill a template and save the image, or `--video` for an animated one ([below](#templates-and-your-own-html)) |
47
+ | `html <page.html\|->` | Render your own HTML and CSS to an image, or `--video` to play its CSS animations |
48
+ | `template save\|update\|delete …` | Keep your own page as a template with fill-in fields |
40
49
  | `film new "<brief>"`, `film get/approve/redo/download …` | Film projects: script and storyboard, approved frames and clips, an assembled film ([below](#film-projects)) |
41
50
  | `brands [<id>\|default]`, `characters`, `assets [--q] [--kind]` | Saved brands (with their guidelines), characters and asset-library files to build on |
51
+ | `assets upload <file\|url>… [--name] [--tag t]`, `assets delete <id>` | Keep files in the asset library, or remove one |
42
52
  | `get <id> [--wait]` | Fetch a generation and save its files |
43
53
  | `list [--limit n] [--before t]` | Recent generations |
44
54
  | `delete <id> [--yes]` | Delete a finished or failed generation and its files (no refund) |
@@ -46,7 +56,7 @@ makemidas transcribe interview.m4a --format srt
46
56
  | `credits buy` (or `credits link`) | Links to buy a plan or credit pack, with prices; opens nothing |
47
57
  | `models [image\|video\|audio\|transcription\|edit]` | Model ids, options and credit prices |
48
58
  | `models <id>` | One model: options, defaults, voices, prices and an example request |
49
- | `estimate <command> "<prompt>"\|<file>` | Price a request without charging; `<command>` is `image`, `video`, `music`, `sfx`, `speech`, `transcribe`, `remove-bg`, `upscale` or `upscale-video`, with that command's options |
59
+ | `estimate <command> "<prompt>"\|<file>` | Price a request without charging; `<command>` is `image`, `video`, `music`, `sfx`, `speech`, `transcribe`, `remove-bg`, `upscale`, `upscale-video` or `avatar`, with that command's options |
50
60
  | `feedback "<message>" [--kind bug\|feature\|praise\|other] [--generation <id>]` | Send feedback to the MakeMidas team |
51
61
 
52
62
  Common options: `--model`, `--aspect`, `--resolution`, `--count`, `--ref`
@@ -96,6 +106,68 @@ stdin is not a terminal), 3 not signed in, 4 not enough credits, a plan
96
106
  limit or busy (also over `--max-credits`), 5 generation failed (credits
97
107
  refunded), 6 network or server error, 7 still rendering.
98
108
 
109
+ ## Talking avatars
110
+
111
+ `avatar` turns one portrait photo and a voice track into a lip-synced video
112
+ as long as the track, billed per second of it:
113
+
114
+ ```bash
115
+ makemidas speech "Hi, I'm Ada. Let me show you around." --voice Kore -o .
116
+ makemidas avatar ada.png makemidas-<id>-1.wav -r 720p --direction "smiles, nods once"
117
+ makemidas avatar line.mp3 --character <id> --max-credits 60
118
+ ```
119
+
120
+ The voice track (MP3, WAV, M4A, AAC or OGG, up to 50 MB and 5 minutes, a
121
+ file or a link) is spoken exactly as given; make it with `makemidas speech`
122
+ when you have only a script. `-m kie/infinitetalk` takes up to 15 seconds at
123
+ 480p or 720p, `-m kwaivgi/kling-ai-avatar` up to 5 minutes at 720p; left
124
+ out, the first model on sale is used (`makemidas models edit`).
125
+ `--direction` describes expression and movement. `makemidas estimate avatar
126
+ <photo> <voice>` prices it first.
127
+
128
+ ## Templates and your own HTML
129
+
130
+ Image models get text wrong; templates don't. Built-in templates make quote
131
+ cards, announcement posts, link preview (OG) images, product promos, title
132
+ cards, transparent lower thirds and stat cards, filled with your default
133
+ brand's colors, fonts and logo:
134
+
135
+ ```bash
136
+ makemidas templates # ids, sizes, free renders left today
137
+ makemidas template quote-card # its fields, as --set lines
138
+ makemidas render quote-card --set quote="Make it simple." --set author=Ada --size portrait
139
+ makemidas render og-image --set title="Launch week" --brand none --format webp
140
+ makemidas render lower-third --set name=Ada --video --format mov # keeps transparency
141
+ ```
142
+
143
+ `--set field=value` takes text as written; image fields take
144
+ `asset:<id>`, `generation:<id>[/<n>]`, `background:<id>` (built-in photos a
145
+ field lists), `brand-image:<id>`, or a local JPG, PNG or WebP, which is
146
+ kept in your asset library first. An empty value clears a field.
147
+
148
+ Your own page renders the same way: no JavaScript runs, images are data
149
+ URLs or your files as `asset:<id>` / `generation:<id>`, fonts come from
150
+ Google Fonts, and every other URL is removed.
151
+
152
+ ```bash
153
+ makemidas html card.html --css card.css --size og
154
+ makemidas html intro.html --video --seconds 6 --size landscape # CSS animations
155
+ makemidas template save card.html --name "Launch card" --fields fields.json --width 1200 --height 630
156
+ makemidas render <saved-id> --set title="Spring sale"
157
+ ```
158
+
159
+ A saved template's fields fill its placeholders: a text field the element
160
+ with `data-var-text="<id>"`, an image field `<img data-var-src="<id>">`, a
161
+ color field the CSS variable `--<id>`, a choice `data-<id>` on `<html>`.
162
+ `fields.json` is a list (or `{ "fields": [...] }`) of `{ "id", "type":
163
+ "text"|"color"|"image"|"choice", "label", "default", … }`; text fields
164
+ need `maxLength`, choices `options`.
165
+
166
+ The first image renders each UTC day are free (10, or 100 on a paid plan),
167
+ templates and HTML together, then 1 credit each. Videos (2–15 seconds, MP4,
168
+ or MOV for transparent templates; `--matte #rrggbb` sets what sits behind a
169
+ transparent page in an MP4) cost 1 credit per started 5 seconds.
170
+
99
171
  ## Brands, characters and the asset library
100
172
 
101
173
  Images and videos can follow a saved brand and reuse saved characters and
@@ -107,6 +179,8 @@ makemidas image "our cold brew on a desk" --brand default --brand-logo
107
179
  makemidas video "she waves at the camera" --character <id> -d 5
108
180
  makemidas assets --q "product shot" --kind image
109
181
  makemidas image "the same bottle on a beach" --ref asset:<id>
182
+ makemidas assets upload logo.png bottle.jpg --tag brand
183
+ makemidas assets delete <id> --yes
110
184
  ```
111
185
 
112
186
  `--brand <id|default>` adds the brand's guidelines to the prompt (and, for
@@ -149,22 +223,39 @@ makemidas film download <id> --pieces -o ./cut # clips, audio, timeline.jso
149
223
  `--speech-model`, `--voice`, `--music-model <id|none>`, `--music-prompt`,
150
224
  `--transition cut|fade|crossfade`, `--clip-audio`, `--brand <id|none>`. After
151
225
  the film is approved only the voiceover model and voice can change.
226
+ - `--style social` writes a short vertical video to stop the scroll on
227
+ TikTok, Reels or Shorts (9:16, about 15 seconds and subtitles on by
228
+ default). `--subtitles on|off` burns the voiceover in as subtitles;
229
+ `--title-card` and `--end-card` take `on`, `off` or a title for an
230
+ animated card (1 credit per started 5 seconds, approved with the film);
231
+ `--lower-thirds on` shows each speaker's name the first time they speak.
232
+ - Cast: `--characters <id,…>` (up to 4 saved characters). A shot with
233
+ `"type": "talking"` and a `characterId` in the storyboard file has that
234
+ character say its voiceover to camera, lip-synced by `--avatar-model`
235
+ (priced per second of the line).
236
+ - With each storyboard the script model adds a self-check (the question the
237
+ opening raises, the shot that pays it off, the one surprise); read it with
238
+ `film get <id> --json` under `settings.storyboardCheck`.
152
239
  - `--wait` follows the frames, the film and the assembly (`--timeout`,
153
240
  default 15 minutes); it polls the assembly every 8 seconds, which keeps the
154
241
  render moving. A paused project (out of credits) exits 4: top up, then
155
242
  `makemidas film resume <id>`.
156
- - `film download --pieces` saves every clip, voiceover and the music with a
157
- `timeline.json` (start, duration and local file of each piece) for your own
158
- ffmpeg cut or an agent's.
243
+ - `film download` saves the film and, when it has subtitles, its `.srt`.
244
+ `--pieces` saves every clip (`title-card`, `clip-<n>`, `end-card`),
245
+ voiceover and the music with a `timeline.json` (start, duration and local
246
+ file of each piece) for your own ffmpeg cut or an agent's. A talking clip
247
+ already carries its line: use its sound or the voiceover, not both.
159
248
  - The storyboard file for `film update --file` is a JSON list of shots (or
160
249
  `{ "shots": [...] }`), each with `prompt` and `duration`, and optionally
161
- `id` (keep a shot and its frame), `description`, `camera` and `voiceover`.
250
+ `id` (keep a shot and its frame), `type` (`normal` or `talking`),
251
+ `description`, `camera`, `voiceover`, `characterId` and `assetIds`.
162
252
 
163
253
  ## Credits
164
254
 
165
- Every generation spends credits at the same prices as the website. There
166
- are no free credits: credits come from a monthly plan or a one-time credit
167
- pack (`makemidas credits buy` prints the links and prices). `makemidas
255
+ Every generation spends credits at the same prices as the website. A new
256
+ account gets free credits once its email is verified; after that, credits
257
+ come from a monthly plan or a one-time credit pack (`makemidas credits buy`
258
+ prints the links and prices). `makemidas
168
259
  models` shows the prices;
169
260
  `--quoted-credits <n>` refuses to charge anything else.
170
261
 
@@ -184,7 +275,7 @@ makemidas estimate upscale-video clip.mp4 --resolution 4K
184
275
 
185
276
  Or price and run in one step: `--max-credits <n>` on any generating command
186
277
  (`image`, `video`, `music`, `sfx`, `speech`, `transcribe`, `remove-bg`,
187
- `upscale`, `upscale-video`, `compare`) estimates first and stops (exit 4, nothing charged) when the request costs
278
+ `upscale`, `upscale-video`, `avatar`, `compare`) estimates first and stops (exit 4, nothing charged) when the request costs
188
279
  more than `n` or more than your balance. Otherwise it sends the estimated
189
280
  request back at exactly the quoted price, with reference images and files
190
281
  uploaded once. `compare` prices each model and quotes the total:
package/dist/api.js CHANGED
@@ -33,6 +33,20 @@ const AUDIO_TYPES = {
33
33
  '.webm': 'audio/webm',
34
34
  ...VIDEO_TYPES,
35
35
  };
36
+ /** Talking avatar voice tracks. */
37
+ const VOICE_TYPES = {
38
+ '.mp3': 'audio/mpeg',
39
+ '.wav': 'audio/wav',
40
+ '.m4a': 'audio/mp4',
41
+ '.aac': 'audio/aac',
42
+ '.ogg': 'audio/ogg',
43
+ '.oga': 'audio/ogg',
44
+ };
45
+ /** What the asset library keeps, by file extension. */
46
+ const ASSET_TYPES = {
47
+ ...CONTENT_TYPES,
48
+ ...AUDIO_TYPES,
49
+ };
36
50
  const MEDIA_UPLOADS = {
37
51
  audio: {
38
52
  path: '/audio-uploads',
@@ -40,6 +54,11 @@ const MEDIA_UPLOADS = {
40
54
  what: 'MP3, WAV, M4A, AAC, FLAC, OGG, Opus, WEBM, MP4 or MOV',
41
55
  },
42
56
  video: { path: '/video-uploads', types: VIDEO_TYPES, what: 'MP4 or MOV' },
57
+ voice: {
58
+ path: '/voice-uploads',
59
+ types: VOICE_TYPES,
60
+ what: 'MP3, WAV, M4A, AAC or OGG',
61
+ },
43
62
  };
44
63
  const isUrl = (source) => /^https?:\/\//i.test(source);
45
64
  export class Api {
@@ -189,9 +208,9 @@ export class Api {
189
208
  return id;
190
209
  }
191
210
  /**
192
- * Upload audio or video to transcribe (`audio`), or a video to upscale
193
- * (`video`): a local file goes as the raw body, a link as `{ url }` for
194
- * the server to download.
211
+ * Upload audio or video to transcribe (`audio`), a video to upscale
212
+ * (`video`) or a talking avatar's voice track (`voice`): a local file goes
213
+ * as the raw body, a link as `{ url }` for the server to download.
195
214
  */
196
215
  async mediaUpload(kind, source) {
197
216
  const { path, types, what } = MEDIA_UPLOADS[kind];
@@ -263,6 +282,76 @@ export class Api {
263
282
  async list(query) {
264
283
  return (await this.json('/generations', { query })).generations;
265
284
  }
285
+ // ---------------------------------------------------------------- assets
286
+ /**
287
+ * Keep a local file or a public link in the asset library; answers the
288
+ * asset (`deduped` when the same file was already kept).
289
+ */
290
+ async uploadAsset(source, opts = {}) {
291
+ if (isUrl(source)) {
292
+ return this.json('/assets', {
293
+ method: 'POST',
294
+ json: {
295
+ url: source,
296
+ ...(opts.name ? { name: opts.name } : {}),
297
+ ...(opts.tags?.length ? { tags: opts.tags } : {}),
298
+ },
299
+ });
300
+ }
301
+ const type = ASSET_TYPES[extname(source).toLowerCase()];
302
+ if (!type) {
303
+ throw new CliError(`${source}: the asset library keeps JPG, PNG or WebP images, audio, and MP4 or MOV video.`, EXIT.USAGE, 'invalid_file');
304
+ }
305
+ let bytes;
306
+ try {
307
+ bytes = new Uint8Array(await readFile(source));
308
+ }
309
+ catch {
310
+ throw new CliError(`Can't read ${source}`, EXIT.USAGE, 'invalid_file');
311
+ }
312
+ const form = new FormData();
313
+ form.append('file', new Blob([bytes], { type }), opts.name ?? basename(source));
314
+ const saved = await this.json('/assets', { method: 'POST', form });
315
+ if (opts.tags?.length) {
316
+ saved.asset = await this.json(`/assets/${encodeURIComponent(saved.asset.id)}`, { method: 'PATCH', json: { tags: opts.tags } });
317
+ }
318
+ return saved;
319
+ }
320
+ async deleteAsset(id) {
321
+ await this.request(`/assets/${encodeURIComponent(id)}`, { method: 'DELETE' });
322
+ }
323
+ // ---------------------------------------------------------------- templates
324
+ templates(category) {
325
+ return this.json('/templates', { query: { category } });
326
+ }
327
+ template(id) {
328
+ return this.json(`/templates/${encodeURIComponent(id)}`);
329
+ }
330
+ saveTemplate(input) {
331
+ return this.json('/templates', { method: 'POST', json: input });
332
+ }
333
+ updateTemplate(id, input) {
334
+ return this.json(`/templates/${encodeURIComponent(id)}`, {
335
+ method: 'PATCH',
336
+ json: input,
337
+ });
338
+ }
339
+ async deleteTemplate(id) {
340
+ await this.request(`/templates/${encodeURIComponent(id)}`, {
341
+ method: 'DELETE',
342
+ });
343
+ }
344
+ /** An image, done within the request. */
345
+ render(input) {
346
+ return this.json('/renders', { method: 'POST', json: input });
347
+ }
348
+ /** A video; it answers while rendering, so read the generation until done. */
349
+ videoRender(input) {
350
+ return this.json('/video-renders', {
351
+ method: 'POST',
352
+ json: input,
353
+ });
354
+ }
266
355
  // ---------------------------------------------------------------- films
267
356
  async films() {
268
357
  return (await this.json('/films')).films;
package/dist/args.js CHANGED
@@ -67,6 +67,25 @@ export function parse(argv) {
67
67
  character: { type: 'string' },
68
68
  'brand-logo': { type: 'boolean', default: false },
69
69
  q: { type: 'string' },
70
+ direction: { type: 'string' },
71
+ set: { type: 'string', multiple: true, default: [] },
72
+ size: { type: 'string' },
73
+ width: { type: 'string' },
74
+ height: { type: 'string' },
75
+ css: { type: 'string' },
76
+ transparent: { type: 'boolean', default: false },
77
+ video: { type: 'boolean', default: false },
78
+ matte: { type: 'string' },
79
+ name: { type: 'string' },
80
+ description: { type: 'string' },
81
+ fields: { type: 'string' },
82
+ tag: { type: 'string', multiple: true, default: [] },
83
+ subtitles: { type: 'string' },
84
+ 'title-card': { type: 'string' },
85
+ 'end-card': { type: 'string' },
86
+ 'lower-thirds': { type: 'string' },
87
+ characters: { type: 'string' },
88
+ 'avatar-model': { type: 'string' },
70
89
  },
71
90
  });
72
91
  }
@@ -287,8 +306,10 @@ export const EDIT_COMMANDS = {
287
306
  'remove-background': 'remove-bg',
288
307
  'upscale-image': 'upscale',
289
308
  'upscale-video': 'upscale-video',
309
+ 'talking-avatar': 'avatar',
290
310
  };
291
311
  const VIDEO_UPSCALE_RESOLUTIONS = ['1080P', '2K', '4K'];
312
+ const AVATAR_RESOLUTIONS = ['480p', '720p'];
292
313
  /** A `makemidas remove-bg|upscale|upscale-video` request (kind edit). */
293
314
  export function editInput(task, v) {
294
315
  const command = EDIT_COMMANDS[task];
@@ -302,14 +323,38 @@ export function editInput(task, v) {
302
323
  ];
303
324
  if (task !== 'upscale-image')
304
325
  others.push('scale');
305
- if (task !== 'upscale-video')
326
+ if (task !== 'upscale-video' && task !== 'talking-avatar') {
306
327
  others.push('resolution');
307
- refuse(v, others, command);
328
+ }
329
+ if (task !== 'talking-avatar')
330
+ others.push('direction');
331
+ refuse(v, task === 'talking-avatar'
332
+ ? others.filter((name) => name !== 'character')
333
+ : others, command);
308
334
  const input = {
309
335
  kind: 'edit',
310
336
  task,
311
337
  ...(v.model ? { model: v.model } : {}),
312
338
  };
339
+ if (task === 'talking-avatar') {
340
+ if (v.resolution !== undefined) {
341
+ const resolution = v.resolution.toLowerCase();
342
+ if (!AVATAR_RESOLUTIONS.includes(resolution)) {
343
+ throw usageError('--resolution must be 480p or 720p.');
344
+ }
345
+ input.resolution = resolution;
346
+ }
347
+ if (v.direction !== undefined) {
348
+ const direction = v.direction.trim();
349
+ if (direction.length > 1000) {
350
+ throw usageError('--direction is at most 1,000 characters.');
351
+ }
352
+ if (direction)
353
+ input.prompt = direction;
354
+ }
355
+ if (v.character)
356
+ input.characterId = v.character;
357
+ }
313
358
  if (task === 'upscale-image' && v.scale !== undefined) {
314
359
  const scale = Number(v.scale.replace(/x$/i, ''));
315
360
  if (![1, 2, 4, 8].includes(scale)) {
@@ -405,9 +450,178 @@ export function filmSettings(v) {
405
450
  }
406
451
  settings.transition = v.transition;
407
452
  }
453
+ if (v.style) {
454
+ if (v.style !== 'film' && v.style !== 'social') {
455
+ throw usageError('--style must be film or social (a short vertical video for TikTok, Reels or Shorts).');
456
+ }
457
+ settings.style = v.style;
458
+ }
459
+ if (v.subtitles !== undefined)
460
+ settings.subtitles = onOff(v.subtitles, 'subtitles');
461
+ if (v['lower-thirds'] !== undefined) {
462
+ settings.lowerThirds = onOff(v['lower-thirds'], 'lower-thirds');
463
+ }
464
+ if (v['title-card'] !== undefined) {
465
+ settings.titleCard = filmCard(v['title-card']);
466
+ }
467
+ if (v['end-card'] !== undefined)
468
+ settings.endCard = filmCard(v['end-card']);
469
+ if (v.characters !== undefined) {
470
+ settings.characterIds =
471
+ v.characters === 'none'
472
+ ? []
473
+ : v.characters
474
+ .split(',')
475
+ .map((id) => id.trim())
476
+ .filter(Boolean);
477
+ if (settings.characterIds.length > 4) {
478
+ throw usageError('--characters takes up to 4 character ids.');
479
+ }
480
+ }
481
+ if (v['avatar-model'])
482
+ settings.avatarModel = v['avatar-model'];
408
483
  return settings;
409
484
  }
485
+ function onOff(value, name) {
486
+ const lower = value.toLowerCase();
487
+ if (lower === 'on' || lower === 'true' || lower === 'yes')
488
+ return true;
489
+ if (lower === 'off' || lower === 'false' || lower === 'no')
490
+ return false;
491
+ throw usageError(`--${name} must be on or off.`);
492
+ }
493
+ /** `--title-card on|off|"<title>"`: the default card, none, or one with that title. */
494
+ function filmCard(value) {
495
+ const lower = value.trim().toLowerCase();
496
+ if (lower === 'off' || lower === 'none')
497
+ return null;
498
+ if (lower === 'on' || lower === 'yes')
499
+ return {};
500
+ if (value.trim().length > 80) {
501
+ throw usageError('A card title is at most 80 characters.');
502
+ }
503
+ return { title: value.trim() };
504
+ }
410
505
  /** About how long the film should be, in seconds. */
411
506
  export function filmSeconds(v) {
412
507
  return intOption(v.seconds, 'seconds', 10, 120);
413
508
  }
509
+ // ---------------------------------------------------------------- templates
510
+ const TEMPLATE_SIZES = ['square', 'portrait', 'story', 'landscape', 'og'];
511
+ const IMAGE_FILE = /\.(jpe?g|png|webp)$/i;
512
+ /**
513
+ * One `--set field=value`: text as given; `asset:<id>`,
514
+ * `generation:<id>[/<n>]`, `background:<id>` and `brand-image:<id>` are
515
+ * images; an empty value clears the field. A local image is uploaded to
516
+ * the asset library first (the caller swaps `file:<path>` for its asset).
517
+ */
518
+ export function templateValue(raw) {
519
+ if (raw === '')
520
+ return null;
521
+ const [prefix, ...rest] = raw.split(':');
522
+ const id = rest.join(':');
523
+ if (id) {
524
+ switch (prefix) {
525
+ case 'asset':
526
+ return { assetId: id };
527
+ case 'generation': {
528
+ const [generationId, n] = id.split('/');
529
+ const index = n === undefined ? 0 : Number(n) - 1;
530
+ if (!Number.isInteger(index) || index < 0 || index > 7) {
531
+ throw usageError('Write generation:<id>/<n> with n from 1 to 8.');
532
+ }
533
+ return { generationId, index };
534
+ }
535
+ case 'background':
536
+ return { backgroundId: id };
537
+ case 'brand-image':
538
+ return { brandImageId: id };
539
+ }
540
+ }
541
+ return raw;
542
+ }
543
+ /** `--set a=b` pairs; values of local image files are returned apart. */
544
+ export function templateValues(sets) {
545
+ const values = {};
546
+ const files = {};
547
+ for (const set of sets) {
548
+ const eq = set.indexOf('=');
549
+ if (eq < 1) {
550
+ throw usageError(`Write --set field=value (got "${set}").`);
551
+ }
552
+ const field = set.slice(0, eq).trim();
553
+ const raw = set.slice(eq + 1);
554
+ if (IMAGE_FILE.test(raw) && !raw.includes(':'))
555
+ files[field] = raw;
556
+ else
557
+ values[field] = templateValue(raw);
558
+ }
559
+ return { values, files };
560
+ }
561
+ /** Size, format and video options shared by `render` and `html`. */
562
+ export function renderOptions(v) {
563
+ const out = {};
564
+ if (v.size) {
565
+ if (!TEMPLATE_SIZES.includes(v.size)) {
566
+ throw usageError(`--size must be ${TEMPLATE_SIZES.join(', ')}.`);
567
+ }
568
+ out.size = v.size;
569
+ }
570
+ const width = intOption(v.width, 'width', 200, 2048);
571
+ const height = intOption(v.height, 'height', 200, 2048);
572
+ if ((width === undefined) !== (height === undefined)) {
573
+ throw usageError('Give --width and --height together.');
574
+ }
575
+ if (width !== undefined && v.size) {
576
+ throw usageError('Use --size or --width and --height, not both.');
577
+ }
578
+ if (width !== undefined)
579
+ out.width = width;
580
+ if (height !== undefined)
581
+ out.height = height;
582
+ if (v.video) {
583
+ if (v.scale !== undefined)
584
+ throw usageError('--scale is for images.');
585
+ const seconds = intOption(v.seconds, 'seconds', 2, 15);
586
+ if (seconds !== undefined)
587
+ out.seconds = seconds;
588
+ if (v.format !== undefined) {
589
+ const format = v.format.toLowerCase();
590
+ if (format !== 'mp4' && format !== 'mov') {
591
+ throw usageError('--format must be mp4 or mov (mov keeps transparency).');
592
+ }
593
+ out.format = format;
594
+ }
595
+ if (v.matte !== undefined) {
596
+ if (!/^#[0-9a-f]{6}$/i.test(v.matte)) {
597
+ throw usageError('--matte takes a color like #00b140.');
598
+ }
599
+ out.matte = v.matte;
600
+ }
601
+ }
602
+ else {
603
+ if (v.seconds !== undefined || v.matte !== undefined) {
604
+ throw usageError('--seconds and --matte go with --video.');
605
+ }
606
+ if (v.scale !== undefined) {
607
+ if (v.scale !== '1' && v.scale !== '2') {
608
+ throw usageError('--scale must be 1 or 2.');
609
+ }
610
+ out.scale = Number(v.scale);
611
+ }
612
+ if (v.format !== undefined) {
613
+ const format = v.format.toLowerCase();
614
+ if (format !== 'png' && format !== 'webp') {
615
+ throw usageError('--format must be png or webp (mp4 or mov with --video).');
616
+ }
617
+ out.format = format;
618
+ }
619
+ }
620
+ return out;
621
+ }
622
+ /** `--brand <id|default|none>` on a render: left out uses the default brand. */
623
+ export function renderBrand(value) {
624
+ if (value === undefined || value === 'default')
625
+ return undefined;
626
+ return value === 'none' ? null : value;
627
+ }
package/dist/cli.js CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { Api, KINDS } from "./api.js";
3
- import { audioInput, compareModels, compareOptions, editInput, filmSeconds, filmSettings, feedbackKind, generationInput, intOption, parse, sourceArg, transcriptionInput, usageError, } from "./args.js";
3
+ import { audioInput, compareModels, compareOptions, editInput, filmSeconds, filmSettings, feedbackKind, generationInput, intOption, parse, renderBrand, renderOptions, sourceArg, templateValues, transcriptionInput, usageError, } from "./args.js";
4
4
  import * as commands from "./commands.js";
5
5
  import * as films from "./films.js";
6
+ import * as templates from "./templates.js";
6
7
  import { resolveBaseUrl, VERSION } from "./config.js";
7
8
  import { CliError, EXIT, formatError } from "./errors.js";
8
9
  import { setQuiet } from "./output.js";
9
- const HELP = `makemidas ${VERSION}: AI images, videos, audio, transcripts and edits from the terminal, with your MakeMidas credits
10
+ const HELP = `makemidas ${VERSION}: AI images, videos, audio, transcripts, edits, templates and short films from the terminal, with your MakeMidas credits
10
11
 
11
12
  Usage:
12
13
  makemidas auth login [--no-browser] Sign in (opens the browser)
@@ -21,6 +22,8 @@ Usage:
21
22
  makemidas remove-bg <image> Remove the background (transparent WebP)
22
23
  makemidas upscale <image> Upscale an image (--scale 1|2|4|8)
23
24
  makemidas upscale-video <video> Upscale a clip (--resolution 1080P|2K|4K)
25
+ makemidas avatar <photo> <voice> Lip-sync a portrait to a voice track (a talking
26
+ avatar); --character <id> in place of the photo
24
27
  makemidas compare "<prompt>" --models a,b[,c,d]
25
28
  One prompt on 2-4 image models
26
29
  makemidas get <id> Fetch a generation (and save its files)
@@ -29,19 +32,37 @@ Usage:
29
32
  makemidas brands [<id>|default] Saved brands, or one brand's guidelines
30
33
  makemidas characters Saved characters
31
34
  makemidas assets [--q words] [--kind image|video|audio]
32
- Files in the asset library
35
+ Search the asset library
36
+ makemidas assets upload <file|url>… Keep files in the asset library (--name, --tag)
37
+ makemidas assets delete <id> [--yes] Remove a file from the library
33
38
  makemidas credits Credit balance and plan
34
39
  makemidas credits buy Links and prices for plans and credit packs
35
40
  makemidas estimate <command> "<prompt>|<file>"
36
41
  Price a request without charging: image,
37
42
  video, music, sfx, speech, transcribe,
38
- remove-bg, upscale or upscale-video
43
+ remove-bg, upscale, upscale-video or avatar
39
44
  makemidas models [<kind>] Models, options and credit prices; kind is
40
45
  image, video, audio, transcription or edit
41
46
  makemidas models <id> One model: options, defaults, prices
42
47
  makemidas feedback "<message>" Send feedback (--kind bug|feature|praise|other,
43
48
  --generation <id>)
44
49
 
50
+ HTML templates (exact text: OG images, quote cards, lower thirds, title cards;
51
+ the first renders each day are free, then 1 credit an image; videos cost
52
+ 1 credit per started 5 seconds):
53
+ makemidas templates [<category>] Built-in and saved templates (social, web,
54
+ promo, video, custom) and free renders left
55
+ makemidas template <id> One template: sizes, video, its --set fields
56
+ makemidas render <id> --set f=v… Fill a template and save the image (--video
57
+ for an animated one)
58
+ makemidas html <page.html|-> Render your own HTML and CSS to an image, or
59
+ with --video its CSS animations to a video
60
+ makemidas template save <page.html> --name <name> [--fields fields.json]
61
+ Keep a page as a template with fill-in fields
62
+ makemidas template update <id> [<page.html>]
63
+ Change a saved template
64
+ makemidas template delete <id> [--yes]
65
+
45
66
  Film projects (a brief → script and storyboard → frames → clips, voiceover
46
67
  and music → one film; each paid stage is approved at the credits shown):
47
68
  makemidas film new "<brief>" Create a project and write its storyboard
@@ -103,6 +124,35 @@ Transcribe and edit options:
103
124
  --scale <n> upscale: 1 (sharpen), 2 (default), 4 or 8
104
125
  -r, --resolution <r> upscale-video: 1080P, 2K (default) or 4K
105
126
 
127
+ Avatar options:
128
+ -m, --model <id> kie/infinitetalk or kwaivgi/kling-ai-avatar (default:
129
+ the first on sale; see \`makemidas models edit\`)
130
+ -r, --resolution <r> 480p or 720p (default: the model's smallest)
131
+ --direction <words> Expression and movement, e.g. "smiles, nods once"
132
+ --character <id> A saved character's portrait instead of a photo
133
+ The voice track (MP3, WAV, M4A, AAC or OGG, up to 5 minutes) is spoken as
134
+ given; make one first with \`makemidas speech\`. Billed per second of it.
135
+
136
+ Template and HTML options (render, html):
137
+ --set <field>=<value> Repeat per field. Text as written; images as
138
+ asset:<id>, generation:<id>[/<n>], background:<id>,
139
+ brand-image:<id>, or a local JPG/PNG/WebP (kept in
140
+ the asset library); empty clears the field
141
+ --size <id> square, portrait, story, landscape or og
142
+ --width, --height <px> A custom size, 200-2048 (videos: even, up to 1920)
143
+ --scale 1|2 Image pixel density
144
+ --format <f> png or webp; with --video, mp4 or mov (mov keeps
145
+ a transparent template's alpha)
146
+ --brand <id|none> render: the brand's colors, fonts and logo
147
+ (default: your default brand)
148
+ --css <file> html: a stylesheet; --transparent keeps unpainted
149
+ areas transparent
150
+ --video Render a video; --seconds 2-15, --matte #rrggbb
151
+ behind a transparent page in an MP4
152
+ Saved templates: --name, --description, --fields fields.json (text, color,
153
+ image or choice fields that fill data-var-text, data-var-src, --<id> CSS
154
+ variables and data-<id> attributes), --width and --height (the canvas)
155
+
106
156
  Compare options:
107
157
  --models <a,b,…> 2-4 different image model ids
108
158
  -a, --aspect, --ref, --max-credits, --quoted-credits as for image
@@ -131,6 +181,17 @@ Film options:
131
181
  --speech-model <id>, --voice <id|default>
132
182
  --music-model <id|none>, --music-prompt <words>
133
183
  --transition cut|fade|crossfade, --clip-audio, --brand <id|none>
184
+ --style film|social social: a short vertical video written to stop the
185
+ scroll (9:16, about 15 s, subtitles on by default)
186
+ --subtitles on|off Burn the voiceover in as subtitles
187
+ --title-card, --end-card on|off|"<title>"
188
+ Open or close with an animated template card
189
+ --lower-thirds on|off Each speaker's name the first time they speak
190
+ --characters <id,…|none>
191
+ Cast (up to 4 saved characters); a shot with
192
+ "type": "talking" in --file has its character say
193
+ the line to camera, lip-synced
194
+ --avatar-model <id> The talking avatar model for talking shots
134
195
  --no-write film new: create it without writing the storyboard
135
196
  --file <shots.json> film update: the whole storyboard, in order
136
197
  --max-credits <n> Charge the step's price only if it is at most n
@@ -153,6 +214,11 @@ Examples:
153
214
  makemidas compare "a red fox in snow" --models a/one,b/two --max-credits 40
154
215
  makemidas models google/gemini-omni-flash
155
216
  makemidas film new "A 20-second ad for our cold brew" --max-credits 40
217
+ makemidas film new "Why our mugs never chip" --style social --max-credits 30
218
+ makemidas avatar host.png line.mp3 -r 720p --max-credits 40
219
+ makemidas render quote-card --set quote="Make it simple." --set author=Ada
220
+ makemidas html card.html --css card.css --size og
221
+ makemidas html intro.html --video --seconds 6
156
222
  makemidas film approve <id> frames --quoted-credits 10 --wait
157
223
 
158
224
  Credentials: \`auth login\`, or MAKEMIDAS_API_KEY (Settings → API keys).
@@ -178,6 +244,33 @@ function editTask(command) {
178
244
  return 'upscale-image';
179
245
  return 'upscale-video';
180
246
  }
247
+ /** `avatar <photo> <voice>`, or `avatar <voice> --character <id>`. */
248
+ function avatarSources(rest, character, command) {
249
+ if (character) {
250
+ if (rest.length !== 1) {
251
+ throw usageError(`With --character, give only the voice track: \`makemidas ${command} line.mp3 --character <id>\`.`);
252
+ }
253
+ return [undefined, rest[0]];
254
+ }
255
+ if (rest.length !== 2) {
256
+ throw usageError(`Give a portrait and a voice track: \`makemidas ${command} face.png line.mp3\` (make the track with \`makemidas speech\`).`);
257
+ }
258
+ return [rest[0], rest[1]];
259
+ }
260
+ /** Name, description and canvas of a saved template, from the options. */
261
+ function savedTemplateRest(v) {
262
+ const width = intOption(v.width, 'width', 200, 2048);
263
+ const height = intOption(v.height, 'height', 200, 2048);
264
+ if ((width === undefined) !== (height === undefined)) {
265
+ throw usageError('Give --width and --height together.');
266
+ }
267
+ return {
268
+ ...(v.name ? { name: v.name } : {}),
269
+ ...(v.description !== undefined ? { description: v.description } : {}),
270
+ ...(width !== undefined ? { width, height } : {}),
271
+ ...(v.transparent ? { transparent: true } : {}),
272
+ };
273
+ }
181
274
  async function main(argv) {
182
275
  const { values: v, positionals } = parse(argv);
183
276
  setQuiet(v.quiet);
@@ -220,6 +313,57 @@ async function main(argv) {
220
313
  const { input, format } = transcriptionInput(v);
221
314
  return commands.transcribe(api, g, input, source, format, save, wait, maxCredits(v));
222
315
  }
316
+ case 'avatar':
317
+ case 'talking-avatar': {
318
+ const input = editInput('talking-avatar', v);
319
+ const [photo, voice] = avatarSources(rest, Boolean(v.character), command);
320
+ return commands.generate(api, g, input, photo ? [photo] : [], save, wait, maxCredits(v), { kind: 'voice', source: voice });
321
+ }
322
+ case 'templates':
323
+ if (rest.length > 1)
324
+ throw usageError('Use `templates [<category>]`.');
325
+ return templates.templatesList(api, g, rest[0] ?? v.kind);
326
+ case 'template': {
327
+ const [sub, ...args] = rest;
328
+ const deleteOpts = { yes: v.yes, interactive: Boolean(process.stdin.isTTY) };
329
+ switch (sub) {
330
+ case 'save':
331
+ case 'new':
332
+ return templates.templateSave(api, g, await templates.savedTemplateInput({ html: args[0], css: v.css, fields: v.fields }, savedTemplateRest(v)));
333
+ case 'update':
334
+ return templates.templateUpdate(api, g, args[0], await templates.savedTemplateInput({ html: args[1], css: v.css, fields: v.fields }, savedTemplateRest(v)));
335
+ case 'delete':
336
+ return templates.templateDelete(api, g, args[0], deleteOpts);
337
+ case 'list':
338
+ case undefined:
339
+ return templates.templatesList(api, g, args[0]);
340
+ default:
341
+ return templates.templateShow(api, g, sub);
342
+ }
343
+ }
344
+ case 'render': {
345
+ if (rest.length !== 1) {
346
+ throw usageError('Give one template id: `makemidas render quote-card --set quote="…"`.');
347
+ }
348
+ const { values, files } = templateValues(v.set);
349
+ return templates.render(api, g, {
350
+ input: templates.templateRender(rest[0], values, renderOptions(v), renderBrand(v.brand)),
351
+ files,
352
+ video: v.video,
353
+ }, save, wait);
354
+ }
355
+ case 'html': {
356
+ if (rest.length !== 1) {
357
+ throw usageError('Give one HTML file (or - for stdin): `makemidas html page.html`.');
358
+ }
359
+ if (v.set.length || v.brand) {
360
+ throw usageError('--set and --brand are for templates; your own page renders as written.');
361
+ }
362
+ return templates.render(api, g, {
363
+ input: await templates.htmlRender(rest[0], v.css, v.transparent, renderOptions(v)),
364
+ video: v.video,
365
+ }, save, wait);
366
+ }
223
367
  case 'remove-bg':
224
368
  case 'upscale':
225
369
  case 'upscale-video': {
@@ -273,6 +417,20 @@ async function main(argv) {
273
417
  case 'characters':
274
418
  return commands.characters(api, g);
275
419
  case 'assets':
420
+ if (rest[0] === 'upload' || rest[0] === 'add') {
421
+ return templates.assetUpload(api, g, rest.slice(1), {
422
+ ...(v.name ? { name: v.name } : {}),
423
+ tags: v.tag,
424
+ });
425
+ }
426
+ if (rest[0] === 'delete' || rest[0] === 'rm') {
427
+ if (rest.length > 2)
428
+ throw usageError('Delete one asset at a time.');
429
+ return templates.assetDelete(api, g, rest[1], {
430
+ yes: v.yes,
431
+ interactive: Boolean(process.stdin.isTTY),
432
+ });
433
+ }
276
434
  return commands.assets(api, g, {
277
435
  q: v.q ?? (rest.join(' ') || undefined),
278
436
  kind: v.kind,
@@ -305,6 +463,11 @@ async function main(argv) {
305
463
  source,
306
464
  });
307
465
  }
466
+ case 'avatar':
467
+ case 'talking-avatar': {
468
+ const [photo, voice] = avatarSources(args, Boolean(v.character), `estimate ${kind}`);
469
+ return commands.estimate(api, g, editInput('talking-avatar', v), photo ? [photo] : [], 'avatar', { kind: 'voice', source: voice });
470
+ }
308
471
  case 'remove-bg':
309
472
  case 'upscale':
310
473
  case 'upscale-video': {
@@ -316,7 +479,7 @@ async function main(argv) {
316
479
  : commands.estimate(api, g, input, [source], kind);
317
480
  }
318
481
  default:
319
- throw usageError('Use `estimate <command> …` with image, video, music, sfx, speech, transcribe, remove-bg, upscale or upscale-video.');
482
+ throw usageError('Use `estimate <command> …` with image, video, music, sfx, speech, transcribe, remove-bg, upscale, upscale-video or avatar.');
320
483
  }
321
484
  }
322
485
  case 'models': {
package/dist/commands.js CHANGED
@@ -84,7 +84,7 @@ export async function authLogout(api, g) {
84
84
  print(removed ? 'Signed out.' : 'Not signed in.');
85
85
  }
86
86
  /** Save every finished output into `dir`; returns the file paths. */
87
- async function saveOutputs(api, generation, save) {
87
+ export async function saveOutputs(api, generation, save) {
88
88
  if (!save.out)
89
89
  return [];
90
90
  const dir = resolve(save.out);
@@ -102,7 +102,7 @@ async function saveOutputs(api, generation, save) {
102
102
  return files;
103
103
  }
104
104
  /** Keep asking for a running generation until it finishes or time runs out. */
105
- async function waitFor(api, generation, timeoutMin) {
105
+ export async function waitFor(api, generation, timeoutMin) {
106
106
  const deadline = Date.now() + timeoutMin * 60_000;
107
107
  let current = generation;
108
108
  while (current.status === 'running' && Date.now() < deadline) {
@@ -111,7 +111,7 @@ async function waitFor(api, generation, timeoutMin) {
111
111
  }
112
112
  return current;
113
113
  }
114
- function report(g, generation, files, links = generation.outputs.flatMap((o) => (o.url ? [o.url] : []))) {
114
+ export function report(g, generation, files, links = generation.outputs.flatMap((o) => (o.url ? [o.url] : []))) {
115
115
  if (g.json) {
116
116
  printJson({ ...generation, files });
117
117
  }
package/dist/config.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
2
2
  import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
- export const VERSION = '0.3.1';
4
+ export const VERSION = '0.4.0';
5
5
  export const USER_AGENT = `makemidas-cli/${VERSION}`;
6
6
  export const DEFAULT_BASE_URL = 'https://makemidas.com';
7
7
  export function resolveBaseUrl(flag) {
package/dist/films.js CHANGED
@@ -64,24 +64,35 @@ export function nextHint(film) {
64
64
  }
65
65
  /** A project as a few lines of text. */
66
66
  export function describeFilm(film) {
67
+ const style = film.settings?.style === 'social' ? ' · social video' : '';
67
68
  const lines = [
68
- `${film.title} (${film.id}) · ${film.stage} · ${film.shots.length} shot${film.shots.length === 1 ? '' : 's'} · ${film.seconds} s`,
69
+ `${film.title} (${film.id}) · ${film.stage} · ${film.shots.length} shot${film.shots.length === 1 ? '' : 's'} · ${film.seconds} s${style}`,
69
70
  ];
71
+ if (film.titleCard)
72
+ lines.push(` ${pieceMark('title card', film.titleCard)}`);
70
73
  for (const shot of film.shots) {
74
+ const talking = shot.type === 'talking';
71
75
  const parts = [
72
76
  pieceMark('frame', shot.frame),
73
- pieceMark('clip', shot.clip),
74
77
  ...(shot.voiceover ? [pieceMark('voice', shot.voice)] : []),
78
+ pieceMark(talking ? 'avatar' : 'clip', shot.clip),
75
79
  ].join(' ');
76
- lines.push(` ${shot.position + 1}. ${shot.duration}s [${parts}] ${shot.description || shot.prompt.slice(0, 80)}`);
80
+ lines.push(` ${shot.position + 1}. ${shot.seconds ?? shot.duration}s [${parts}] ${talking ? '(talking) ' : ''}${shot.description || shot.prompt.slice(0, 80)}`);
77
81
  if (shot.error)
78
82
  lines.push(` error: ${shot.error}`);
79
83
  }
84
+ if (film.endCard)
85
+ lines.push(` ${pieceMark('end card', film.endCard)}`);
80
86
  if (film.assembly?.status === 'failed') {
81
87
  lines.push(` assembly failed: ${film.assembly.error ?? 'unknown error'}`);
82
88
  }
83
89
  if (film.filmUrl)
84
90
  lines.push(` film: ${film.filmUrl}`);
91
+ if (film.subtitlesUrl)
92
+ lines.push(` subtitles: ${film.subtitlesUrl}`);
93
+ if (film.share) {
94
+ lines.push(` share link: ${film.share.status === 'live' && film.share.url ? film.share.url : film.share.status === 'pending' ? 'waiting for review' : 'refused for this render'}`);
95
+ }
85
96
  lines.push(`Next: ${nextHint(film)}`);
86
97
  lines.push(`Web: ${film.webUrl}`);
87
98
  return lines;
@@ -143,15 +154,24 @@ function settle(film, waited) {
143
154
  throw new CliError(`Still working (${film.next}). Run \`makemidas film get ${film.id} --wait\` later.`, EXIT.NOT_READY, 'not_ready');
144
155
  }
145
156
  }
146
- /** Save the assembled film as `<dir>/film-<id>.mp4`. */
157
+ /** Save the assembled film as `<dir>/film-<id>.mp4`, and its subtitles as `.srt`. */
147
158
  async function saveFilm(api, film, save) {
148
159
  if (!save.out || !film.filmUrl)
149
160
  return [];
150
161
  const dir = resolve(save.out);
151
162
  await mkdir(dir, { recursive: true });
163
+ const files = [];
152
164
  const { bytes } = await api.download(film.filmUrl);
153
165
  const file = join(dir, `film-${short(film.id)}.mp4`);
154
- return (await writeOutput(file, bytes, save.force)) ? [file] : [];
166
+ if (await writeOutput(file, bytes, save.force))
167
+ files.push(file);
168
+ if (film.subtitlesUrl) {
169
+ const srt = await api.download(film.subtitlesUrl);
170
+ const subtitles = join(dir, `film-${short(film.id)}.srt`);
171
+ if (await writeOutput(subtitles, srt.bytes, save.force))
172
+ files.push(subtitles);
173
+ }
174
+ return files;
155
175
  }
156
176
  const EXT = {
157
177
  'video/mp4': 'mp4',
@@ -184,8 +204,13 @@ async function savePieces(api, film, save) {
184
204
  };
185
205
  const timeline = film.timeline;
186
206
  const clips = [];
187
- for (const [i, clip] of timeline.clips.entries()) {
188
- clips.push({ ...clip, file: await fetchTo(clip.url, `clip-${i + 1}`) });
207
+ for (const clip of timeline.clips) {
208
+ const name = clip.kind === 'title_card'
209
+ ? 'title-card'
210
+ : clip.kind === 'end_card'
211
+ ? 'end-card'
212
+ : `clip-${film.shots.findIndex((shot) => shot.id === clip.shotId) + 1}`;
213
+ clips.push({ ...clip, file: await fetchTo(clip.url, name) });
189
214
  }
190
215
  const voiceover = [];
191
216
  for (const line of timeline.voiceover) {
@@ -0,0 +1,232 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { askYesNo, report, saveOutputs, waitFor, } from "./commands.js";
3
+ import { CliError, EXIT } from "./errors.js";
4
+ import { formatBytes, log, print, printJson } from "./output.js";
5
+ /*
6
+ * HTML templates (quote cards, OG images, lower thirds, title cards…), your
7
+ * own HTML and CSS rendered to an image or a CSS-animated video, templates
8
+ * you save with fill-in fields, and the asset library's uploads.
9
+ */
10
+ const CATEGORIES = ['social', 'web', 'promo', 'video', 'custom'];
11
+ function need(value, usage) {
12
+ if (!value?.trim()) {
13
+ throw new CliError(`Give ${usage}.`, EXIT.USAGE, 'usage');
14
+ }
15
+ return value.trim();
16
+ }
17
+ /** A file's text; `-` reads stdin. */
18
+ export async function readText(path, what) {
19
+ if (path === '-') {
20
+ const chunks = [];
21
+ for await (const chunk of process.stdin)
22
+ chunks.push(chunk);
23
+ return Buffer.concat(chunks).toString('utf8');
24
+ }
25
+ try {
26
+ return await readFile(path, 'utf8');
27
+ }
28
+ catch {
29
+ throw new CliError(`Can't read ${what} ${path}`, EXIT.USAGE, 'invalid_file');
30
+ }
31
+ }
32
+ function fieldLine(field) {
33
+ const extra = [
34
+ field.type,
35
+ field.options?.length ? `one of ${field.options.join('|')}` : '',
36
+ field.maxLength ? `max ${field.maxLength}` : '',
37
+ field.backgrounds?.length ? `or background:${field.backgrounds.join('|')}` : '',
38
+ field.brand ? `brand: ${field.brand}` : '',
39
+ ]
40
+ .filter(Boolean)
41
+ .join(', ');
42
+ const fallback = field.default ? ` default: ${JSON.stringify(field.default)}` : '';
43
+ return ` --set ${field.id}=… ${field.label} (${extra})${fallback}`;
44
+ }
45
+ // ---------------------------------------------------------------- listing
46
+ export async function templatesList(api, g, category) {
47
+ if (category && !CATEGORIES.includes(category)) {
48
+ throw new CliError(`The category must be ${CATEGORIES.join(', ')}.`, EXIT.USAGE, 'usage');
49
+ }
50
+ const { templates, quota } = await api.templates(category);
51
+ if (g.json)
52
+ return printJson({ templates, quota });
53
+ for (const t of templates) {
54
+ const sizes = t.saved && t.canvas
55
+ ? `${t.canvas.width}x${t.canvas.height}`
56
+ : t.sizes.map((s) => s.id).join(',');
57
+ const video = t.video ? ` · video ${t.video.formats.join('/')}` : '';
58
+ print(`${t.id.padEnd(24)} ${t.category.padEnd(7)} ${sizes}${video} ${t.name}`);
59
+ }
60
+ log(`${quota.freeLeft} of ${quota.freePerDay} free images left today (UTC), then ${quota.creditsPerImage} credit each. Fields: makemidas template <id>`);
61
+ }
62
+ export async function templateShow(api, g, id) {
63
+ const template = await api.template(need(id, 'a template id: `makemidas template <id>`'));
64
+ if (g.json)
65
+ return printJson(template);
66
+ print(`${template.name} (${template.id}) · ${template.category}`);
67
+ if (template.description)
68
+ print(template.description);
69
+ const sizes = template.saved && template.canvas
70
+ ? `${template.canvas.width}x${template.canvas.height} (any --width/--height)`
71
+ : template.sizes.map((s) => `${s.id} ${s.width}x${s.height}`).join(', ');
72
+ print(`Sizes: ${sizes}${template.transparent ? ' · transparent' : ''}`);
73
+ if (template.video) {
74
+ print(`Video: ${template.video.minSeconds}-${template.video.maxSeconds} s (default ${template.video.defaultSeconds}), ${template.video.formats.join(' or ')}, 1 credit per started ${template.video.creditsPerSeconds} s`);
75
+ }
76
+ print('Fields:');
77
+ for (const field of template.fields)
78
+ print(fieldLine(field));
79
+ print(`Render: makemidas render ${template.id} --set <field>=<value>${template.video ? ' [--video]' : ''}`);
80
+ }
81
+ // ---------------------------------------------------------------- render
82
+ /** Upload local images named in `--set` to the asset library. */
83
+ async function uploadFieldFiles(api, files) {
84
+ const values = {};
85
+ for (const [field, path] of Object.entries(files)) {
86
+ log(`Uploading ${path} to your asset library…`);
87
+ const { asset } = await api.uploadAsset(path);
88
+ values[field] = { assetId: asset.id };
89
+ }
90
+ return values;
91
+ }
92
+ /** Render a template or a page; save the image or video and report it. */
93
+ export async function render(api, g, request, save, wait) {
94
+ const uploaded = request.files ? await uploadFieldFiles(api, request.files) : {};
95
+ const input = Object.keys(uploaded).length
96
+ ? { ...request.input, values: { ...request.input.values, ...uploaded } }
97
+ : request.input;
98
+ log(request.video ? 'Rendering the video…' : 'Rendering…');
99
+ const result = request.video ? await api.videoRender(input) : await api.render(input);
100
+ let generation = result.generation;
101
+ if (generation.status === 'running' && wait.wait) {
102
+ generation = await waitFor(api, generation, wait.timeoutMin);
103
+ }
104
+ const files = await saveOutputs(api, generation, save);
105
+ if (!g.json && result.quota) {
106
+ log(result.credits
107
+ ? `${result.credits} credit (no free renders left today).`
108
+ : `Free: ${result.quota.freeLeft} of ${result.quota.freePerDay} free renders left today.`);
109
+ }
110
+ report(g, generation, files);
111
+ }
112
+ /** `makemidas render <templateId> --set …`. */
113
+ export function templateRender(templateId, values, options, brandId) {
114
+ return {
115
+ templateId: need(templateId, 'a template id: `makemidas render quote-card --set quote="…"`'),
116
+ ...(Object.keys(values).length ? { values } : {}),
117
+ ...(brandId !== undefined ? { brandId } : {}),
118
+ ...options,
119
+ };
120
+ }
121
+ /** `makemidas html <page.html>`: your own page, no template. */
122
+ export async function htmlRender(file, css, transparent, options) {
123
+ const html = await readText(need(file, 'an HTML file (or - for stdin): `makemidas html page.html`'), 'the page');
124
+ if (!html.trim())
125
+ throw new CliError('The page is empty.', EXIT.USAGE, 'usage');
126
+ return {
127
+ html,
128
+ ...(css ? { css: await readText(css, 'the stylesheet') } : {}),
129
+ ...(transparent ? { transparent: true } : {}),
130
+ ...options,
131
+ };
132
+ }
133
+ // ---------------------------------------------------------------- saved templates
134
+ /** Ask before deleting, as `makemidas delete` does. */
135
+ async function confirmDelete(opts, what, note) {
136
+ if (opts.yes)
137
+ return;
138
+ if (!opts.interactive) {
139
+ throw new CliError(`Deleting ${what} can't be undone. Run again with --yes to confirm.`, EXIT.USAGE, 'confirmation_required');
140
+ }
141
+ const confirm = opts.confirm ?? askYesNo;
142
+ if (!(await confirm(`Delete ${what} for good? ${note}`))) {
143
+ throw new CliError('Not deleted.', EXIT.USAGE, 'cancelled');
144
+ }
145
+ }
146
+ /** The body of `template save|update`, read from the files given. */
147
+ export async function savedTemplateInput(files, rest) {
148
+ const input = { ...rest };
149
+ if (files.html)
150
+ input.html = await readText(files.html, 'the page');
151
+ if (files.css)
152
+ input.css = await readText(files.css, 'the stylesheet');
153
+ if (files.fields) {
154
+ let fields;
155
+ try {
156
+ fields = JSON.parse(await readText(files.fields, 'the fields file'));
157
+ }
158
+ catch (error) {
159
+ if (error instanceof CliError)
160
+ throw error;
161
+ throw new CliError(`${files.fields} is not valid JSON.`, EXIT.USAGE, 'invalid_file');
162
+ }
163
+ const list = Array.isArray(fields) ? fields : fields?.fields;
164
+ if (!Array.isArray(list)) {
165
+ throw new CliError(`${files.fields} must hold a list of fields (or { "fields": [...] }).`, EXIT.USAGE, 'invalid_file');
166
+ }
167
+ input.fields = list;
168
+ }
169
+ return input;
170
+ }
171
+ function showSaved(g, template, verb) {
172
+ if (g.json)
173
+ return printJson(template);
174
+ print(`${verb} ${template.name} (${template.id}), ${template.fields.length} field${template.fields.length === 1 ? '' : 's'}.`);
175
+ print(`Render: makemidas render ${template.id}${template.fields.map((f) => ` --set ${f.id}=…`).join('')}`);
176
+ }
177
+ export async function templateSave(api, g, input) {
178
+ if (!input.html) {
179
+ throw new CliError('Give the page: `makemidas template save page.html --name "Launch card"`.', EXIT.USAGE, 'usage');
180
+ }
181
+ if (!input.name) {
182
+ throw new CliError('Name it with --name.', EXIT.USAGE, 'usage');
183
+ }
184
+ showSaved(g, await api.saveTemplate(input), 'Saved');
185
+ }
186
+ export async function templateUpdate(api, g, id, input) {
187
+ const templateId = need(id, 'a saved template id: `makemidas template update <id> page.html`');
188
+ if (!Object.keys(input).length) {
189
+ throw new CliError('Say what to change: a page file, --css, --fields, --name, --description, --width and --height.', EXIT.USAGE, 'usage');
190
+ }
191
+ showSaved(g, await api.updateTemplate(templateId, input), 'Updated');
192
+ }
193
+ export async function templateDelete(api, g, id, opts) {
194
+ const templateId = need(id, 'a saved template id: `makemidas template delete <id>`');
195
+ await confirmDelete(opts, `the template ${templateId}`, 'Images made from it stay.');
196
+ await api.deleteTemplate(templateId);
197
+ if (g.json)
198
+ printJson({ id: templateId, deleted: true });
199
+ else
200
+ print(`Deleted template ${templateId}.`);
201
+ }
202
+ // ---------------------------------------------------------------- assets
203
+ export async function assetUpload(api, g, sources, opts) {
204
+ if (!sources.length) {
205
+ throw new CliError('Give one or more files or links: `makemidas assets upload logo.png`.', EXIT.USAGE, 'usage');
206
+ }
207
+ if (opts.name && sources.length > 1) {
208
+ throw new CliError('--name goes with one file.', EXIT.USAGE, 'usage');
209
+ }
210
+ const saved = [];
211
+ for (const source of sources) {
212
+ log(`Uploading ${source}…`);
213
+ const result = await api.uploadAsset(source, opts);
214
+ saved.push(result);
215
+ if (!g.json) {
216
+ print(`${result.asset.id} ${result.asset.kind.padEnd(5)} ${formatBytes(result.asset.size).padStart(8)} ${result.asset.name}${result.deduped ? ' (already kept)' : ''}`);
217
+ }
218
+ }
219
+ if (g.json)
220
+ printJson({ assets: saved.map((s) => ({ ...s.asset, deduped: s.deduped })) });
221
+ else
222
+ log('Use one with --ref asset:<id>, or in a template with --set <field>=asset:<id>.');
223
+ }
224
+ export async function assetDelete(api, g, id, opts) {
225
+ const assetId = need(id, 'an asset id: `makemidas assets delete <id>`');
226
+ await confirmDelete(opts, `the asset ${assetId}`, 'Generations made with it stay.');
227
+ await api.deleteAsset(assetId);
228
+ if (g.json)
229
+ printJson({ id: assetId, deleted: true });
230
+ else
231
+ print(`Deleted asset ${assetId}.`);
232
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@makemidas/cli",
3
- "version": "0.3.1",
4
- "description": "AI image and video generation CLI for AI agents (Claude Code, Cursor, Codex) and people: Nano Banana, GPT Image, Seedream, Seedance, Kling, Veo and more through MakeMidas.",
3
+ "version": "0.4.0",
4
+ "description": "AI image, video and audio generation CLI for AI agents (Claude Code, Cursor, Codex) and people: Nano Banana, GPT Image, Seedream, Seedance, Kling, Veo, Suno and more, plus talking avatars, HTML templates and short films, through MakeMidas.",
5
5
  "keywords": [
6
6
  "ai-image-generator",
7
7
  "ai-video-generator",
@@ -21,7 +21,10 @@
21
21
  "veo",
22
22
  "kling",
23
23
  "gemini-cli",
24
- "openclaw"
24
+ "openclaw",
25
+ "talking-avatar",
26
+ "html-to-image",
27
+ "ai-video-ads"
25
28
  ],
26
29
  "homepage": "https://makemidas.com/developers",
27
30
  "repository": {