@makemidas/cli 0.5.0 → 0.7.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
@@ -36,7 +36,7 @@ makemidas film new "a 15-second social video for our mugs" --style social --max-
36
36
  | `music "<prompt>"` | Generate a song or track (`--lyrics`, `--title`, `--instrumental`, `--duration`) |
37
37
  | `sfx "<prompt>"` | Generate a sound effect (`--loop`, `--bpm`; the model sets the length) |
38
38
  | `speech "<text>"` (alias `voiceover`) | Turn text into a voiceover (`--voice`; `--delivery` on Gemini TTS, `--speed`/`--stability` on ElevenLabs) |
39
- | `transcribe <file\|url\|fileId>` | Upload audio or video, transcribe it and save the transcript (`--format txt\|srt\|vtt\|json`, `--title`) |
39
+ | `transcribe <file\|url\|fileId>` | Upload audio or video, transcribe it and save the transcript (`--format txt\|srt\|vtt\|json`, `--title`); with Nemotron the JSON also times every word (`words: [{ word, start, end, speaker? }]`) |
40
40
  | `remove-bg <image>` | Remove the background; saves a transparent WebP |
41
41
  | `upscale <image> [--scale 1\|2\|4\|8]` | Upscale an image (1 sharpens at the same size; default 2) |
42
42
  | `upscale-video <video> [--resolution 1080P\|2K\|4K]` | Upscale an MP4 or MOV clip of up to 60 s (default 2K) |
@@ -53,11 +53,13 @@ makemidas film new "a 15-second social video for our mugs" --style social --max-
53
53
  | `list [--limit n] [--before t]` | Recent generations |
54
54
  | `delete <id> [--yes]` | Delete a finished or failed generation and its files (no refund) |
55
55
  | `credits` | Balance, plan, expiring credits |
56
+ | `credits activity [--generation <id>] [--limit n] [--before t]` | Grants, charges and refunds, newest first; with `--generation`, what one generation charged and refunded |
56
57
  | `credits buy` (or `credits link`) | Links to buy a plan or credit pack, with prices; opens nothing |
57
58
  | `models [image\|video\|audio\|transcription\|edit]` | Model ids, options and credit prices |
58
59
  | `models <id>` | One model: options, defaults, voices, prices and an example request |
59
60
  | `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 |
60
- | `feedback "<message>" [--kind bug\|feature\|praise\|other] [--generation <id>]` | Send feedback to the MakeMidas team |
61
+ | `frames <video\|url> [--count 1-16] [--width 120-1920]` | Stills evenly spread over a clip and one contact sheet (`<name>-frames/sheet.jpg`), made on your computer with FFmpeg; free, nothing is sent |
62
+ | `feedback "<message>" [--kind bug\|quality\|feature\|praise\|other] [--generation <id>]` | Send feedback to the MakeMidas team (`quality`: a result clearly short of the request) |
61
63
 
62
64
  Common options: `--model`, `--aspect`, `--resolution`, `--count`, `--ref`
63
65
  (file or URL, repeatable), `--style`, `--enhance`, `--duration`, `--audio`,
@@ -106,6 +108,13 @@ stdin is not a terminal), 3 not signed in, 4 not enough credits, a plan
106
108
  limit or busy (also over `--max-credits`), 5 generation failed (credits
107
109
  refunded), 6 network or server error, 7 still rendering.
108
110
 
111
+ Every generating request carries an `Idempotency-Key`. When its answer is
112
+ lost (a dropped connection, a server error), the CLI asks again with the
113
+ same key after 2, 5 and 10 seconds; MakeMidas answers the generation the
114
+ first attempt started, so nothing is made or charged twice. Exit 6 after
115
+ that means it still had no answer: look for the generation with
116
+ `makemidas list` before running the command again.
117
+
109
118
  ## Talking avatars
110
119
 
111
120
  `avatar` turns one portrait photo and a voice track into a lip-synced video
package/dist/api.js CHANGED
@@ -1,8 +1,10 @@
1
+ import { randomUUID } from 'node:crypto';
1
2
  import { readFile } from 'node:fs/promises';
2
3
  import { basename, extname } from 'node:path';
3
4
  import { accessToken, envCredential } from "./auth.js";
4
5
  import { USER_AGENT } from "./config.js";
5
6
  import { CliError, EXIT, exitCodeFor } from "./errors.js";
7
+ import { log } from "./output.js";
6
8
  export const KINDS = [
7
9
  'image',
8
10
  'video',
@@ -61,10 +63,23 @@ const MEDIA_UPLOADS = {
61
63
  },
62
64
  };
63
65
  const isUrl = (source) => /^https?:\/\//i.test(source);
66
+ /** Waits before asking again for a generation whose answer was lost. */
67
+ export const GENERATE_RETRY_MS = [2000, 5000, 10000];
68
+ /**
69
+ * Errors after which the same request, with the same Idempotency-Key, can
70
+ * be sent again without a second charge: no answer, a server error, or the
71
+ * first attempt still starting.
72
+ */
73
+ function retriesSafely(error) {
74
+ return (error instanceof CliError &&
75
+ (error.exitCode === EXIT.NETWORK || error.code === 'idempotency_in_progress'));
76
+ }
64
77
  export class Api {
65
78
  baseUrl;
66
79
  /** Overridable in tests. */
67
80
  fetchImpl = (...args) => fetch(...args);
81
+ /** Overridable in tests. */
82
+ sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
68
83
  constructor(baseUrl) {
69
84
  this.baseUrl = baseUrl;
70
85
  }
@@ -241,11 +256,33 @@ export class Api {
241
256
  },
242
257
  });
243
258
  }
244
- generate(input) {
245
- return this.json('/generations', {
246
- method: 'POST',
247
- json: input,
248
- });
259
+ /**
260
+ * Start a generation. Every attempt sends the same Idempotency-Key, so
261
+ * when the answer is lost (a dropped connection, a server error) asking
262
+ * again answers the generation the first attempt started instead of
263
+ * starting, and charging for, another.
264
+ */
265
+ async generate(input, key = randomUUID()) {
266
+ for (let attempt = 0;; attempt++) {
267
+ try {
268
+ return await this.json('/generations', {
269
+ method: 'POST',
270
+ json: input,
271
+ headers: { 'Idempotency-Key': key },
272
+ });
273
+ }
274
+ catch (error) {
275
+ if (!retriesSafely(error))
276
+ throw error;
277
+ const delay = GENERATE_RETRY_MS[attempt];
278
+ if (delay === undefined) {
279
+ const last = error;
280
+ throw new CliError(`${last.message}. It may have started anyway: look for it with \`makemidas list\` before running this again.`, last.exitCode, last.code, last.details);
281
+ }
282
+ log(`No answer yet (${error.message}); asking again in ${delay / 1000} s with the same request key, so nothing is charged twice…`);
283
+ await this.sleep(delay);
284
+ }
285
+ }
249
286
  }
250
287
  /** Price a request without charging or creating anything. */
251
288
  estimate(input) {
@@ -276,6 +313,10 @@ export class Api {
276
313
  json: input,
277
314
  });
278
315
  }
316
+ /** Grants, charges and refunds, newest first. */
317
+ creditActivity(query) {
318
+ return this.json('/credits/activity', { query });
319
+ }
279
320
  purchaseLink() {
280
321
  return this.json('/credits/purchase-link');
281
322
  }
package/dist/args.js CHANGED
@@ -405,11 +405,11 @@ export function compareOptions(v) {
405
405
  'format',
406
406
  ], 'compare');
407
407
  }
408
- const FEEDBACK_KINDS = ['bug', 'feature', 'praise', 'other'];
408
+ const FEEDBACK_KINDS = ['bug', 'quality', 'feature', 'praise', 'other'];
409
409
  export function feedbackKind(value) {
410
410
  const kind = value ?? 'other';
411
411
  if (!FEEDBACK_KINDS.includes(kind)) {
412
- throw usageError('--kind must be bug, feature, praise or other.');
412
+ throw usageError('--kind must be bug, quality, feature, praise or other.');
413
413
  }
414
414
  return kind;
415
415
  }
package/dist/cli.js CHANGED
@@ -3,6 +3,7 @@ import { Api, KINDS } from "./api.js";
3
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 { filmEdit } from "./film-edit.js";
6
+ import { FRAME_DEFAULTS, frames } from "./frames.js";
6
7
  import * as films from "./films.js";
7
8
  import * as templates from "./templates.js";
8
9
  import { resolveBaseUrl, VERSION } from "./config.js";
@@ -37,6 +38,9 @@ Usage:
37
38
  makemidas assets upload <file|url>… Keep files in the asset library (--name, --tag)
38
39
  makemidas assets delete <id> [--yes] Remove a file from the library
39
40
  makemidas credits Credit balance and plan
41
+ makemidas credits activity Grants, charges and refunds, newest first
42
+ (--generation <id> for one generation's,
43
+ --limit, --before)
40
44
  makemidas credits buy Links and prices for plans and credit packs
41
45
  makemidas estimate <command> "<prompt>|<file>"
42
46
  Price a request without charging: image,
@@ -45,7 +49,10 @@ Usage:
45
49
  makemidas models [<kind>] Models, options and credit prices; kind is
46
50
  image, video, audio, transcription or edit
47
51
  makemidas models <id> One model: options, defaults, prices
48
- makemidas feedback "<message>" Send feedback (--kind bug|feature|praise|other,
52
+ makemidas frames <video|url> Stills and a contact sheet of a clip, made
53
+ here with FFmpeg; free (--count 1-16,
54
+ default 6; --width 120-1920, default 480)
55
+ makemidas feedback "<message>" Send feedback (--kind bug|quality|feature|praise|other,
49
56
  --generation <id>)
50
57
 
51
58
  HTML templates (exact text: OG images, quote cards, lower thirds, title cards;
@@ -124,7 +131,8 @@ Audio options:
124
131
 
125
132
  Transcribe and edit options:
126
133
  -m, --model <id> transcribe: default openai/whisper-large-v2
127
- --format <f> transcribe: txt (default), srt, vtt or json
134
+ --format <f> transcribe: txt (default), srt, vtt or json (json
135
+ times every word with Nemotron)
128
136
  --scale <n> upscale: 1 (sharpen), 2 (default), 4 or 8
129
137
  -r, --resolution <r> upscale-video: 1080P, 2K (default) or 4K
130
138
 
@@ -215,6 +223,7 @@ Examples:
215
223
  makemidas video "the waves roll in" -d 5 --audio --max-credits 60
216
224
  makemidas speech "Welcome back." --voice Kore --delivery "warm and unhurried"
217
225
  makemidas transcribe interview.m4a --format srt
226
+ makemidas frames clip.mp4 --count 9
218
227
  makemidas compare "a red fox in snow" --models a/one,b/two --max-credits 40
219
228
  makemidas models google/gemini-omni-flash
220
229
  makemidas film new "A 20-second ad for our cold brew" --max-credits 40
@@ -317,6 +326,13 @@ async function main(argv) {
317
326
  const { input, format } = transcriptionInput(v);
318
327
  return commands.transcribe(api, g, input, source, format, save, wait, maxCredits(v));
319
328
  }
329
+ case 'frames':
330
+ return frames(g, sourceArg(rest, 'frames', 'video file or link'), {
331
+ count: intOption(v.count, 'count', 1, 16) ?? FRAME_DEFAULTS.count,
332
+ width: intOption(v.width, 'width', 120, 1920) ?? FRAME_DEFAULTS.width,
333
+ out: v.out,
334
+ force: v.force,
335
+ });
320
336
  case 'avatar':
321
337
  case 'talking-avatar': {
322
338
  const input = editInput('talking-avatar', v);
@@ -446,7 +462,15 @@ async function main(argv) {
446
462
  return commands.credits(api, g);
447
463
  if (sub === 'buy' || sub === 'link')
448
464
  return commands.creditsLink(api, g);
449
- throw usageError('Use `credits` or `credits buy`.');
465
+ if (sub === 'activity' || sub === 'history') {
466
+ return commands.creditActivity(api, g, {
467
+ limit: intOption(v.limit === '20' ? undefined : v.limit, 'limit', 1, 100) ??
468
+ 20,
469
+ ...(v.before ? { before: v.before } : {}),
470
+ ...(v.generation ? { generationId: v.generation } : {}),
471
+ });
472
+ }
473
+ throw usageError('Use `credits`, `credits activity` or `credits buy`.');
450
474
  }
451
475
  case 'estimate': {
452
476
  const [kind, ...args] = rest;
package/dist/commands.js CHANGED
@@ -353,6 +353,54 @@ export async function credits(api, g) {
353
353
  print(` ${item.amount} expire ${item.expiresAt.slice(0, 10)}`);
354
354
  }
355
355
  }
356
+ /** How many pages `credits activity --generation` looks through. */
357
+ const ACTIVITY_SCAN_PAGES = 5;
358
+ /**
359
+ * The credit history, newest first: grants, charges and refunds. With
360
+ * `generationId`, only what that generation charged and refunded.
361
+ */
362
+ export async function creditActivity(api, g, opts) {
363
+ let entries;
364
+ let nextBefore;
365
+ if (opts.generationId) {
366
+ entries = [];
367
+ nextBefore = opts.before ?? null;
368
+ for (let page = 0; page < ACTIVITY_SCAN_PAGES; page++) {
369
+ const result = await api.creditActivity({
370
+ limit: 100,
371
+ ...(nextBefore ? { before: nextBefore } : {}),
372
+ });
373
+ entries.push(...result.entries.filter((e) => e.generationId === opts.generationId));
374
+ nextBefore = result.nextBefore;
375
+ if (!nextBefore)
376
+ break;
377
+ }
378
+ }
379
+ else {
380
+ ({ entries, nextBefore } = await api.creditActivity({
381
+ limit: opts.limit,
382
+ ...(opts.before ? { before: opts.before } : {}),
383
+ }));
384
+ }
385
+ if (g.json) {
386
+ printJson({ entries, nextBefore });
387
+ return;
388
+ }
389
+ if (!entries.length) {
390
+ print(opts.generationId
391
+ ? `No charges or refunds found for ${opts.generationId}.`
392
+ : 'No credit activity yet.');
393
+ return;
394
+ }
395
+ for (const e of entries) {
396
+ const credits = e.credits > 0 ? `+${e.credits}` : String(e.credits);
397
+ const what = [e.source, e.model, e.generationId].filter(Boolean).join(' ');
398
+ print(`${e.at.slice(0, 16).replace('T', ' ')} ${e.type.padEnd(6)} ${credits.padStart(6)} ${what}`);
399
+ }
400
+ if (nextBefore && !opts.generationId) {
401
+ print(`Older: makemidas credits activity --before ${nextBefore}`);
402
+ }
403
+ }
356
404
  export async function models(api, g, kind) {
357
405
  const result = await api.models(kind);
358
406
  if (g.json) {
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.5.0';
4
+ export const VERSION = '0.7.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/frames.js ADDED
@@ -0,0 +1,160 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { existsSync } from 'node:fs';
3
+ import { mkdir } from 'node:fs/promises';
4
+ import { basename, extname, join, resolve } from 'node:path';
5
+ import { CliError, EXIT } from "./errors.js";
6
+ import { log, print, printJson } from "./output.js";
7
+ /*
8
+ * `makemidas frames <video>`: stills from a clip, evenly spread, and one
9
+ * contact sheet of them, made on this computer with FFmpeg. An agent opens
10
+ * the sheet to check a clip it cannot watch. Nothing is sent to MakeMidas
11
+ * and nothing is charged.
12
+ */
13
+ export const FRAME_DEFAULTS = { count: 6, width: 480 };
14
+ export const runTool = (command, args) => new Promise((done, fail) => {
15
+ execFile(command, args, { maxBuffer: 4 * 1024 * 1024 }, (error, stdout, stderr) => {
16
+ if (error) {
17
+ Object.assign(error, { stderr: String(stderr) });
18
+ fail(error);
19
+ }
20
+ else {
21
+ done(String(stdout));
22
+ }
23
+ });
24
+ });
25
+ /** Where `count` stills fall: the middle of each equal part of the clip. */
26
+ export function frameTimes(seconds, count) {
27
+ return Array.from({ length: count }, (_, i) => Math.round(((i + 0.5) * seconds * 1000) / count) / 1000);
28
+ }
29
+ /** Columns and rows of the contact sheet: close to square, wider than tall. */
30
+ export function sheetGrid(count) {
31
+ const cols = Math.ceil(Math.sqrt(count));
32
+ return { cols, rows: Math.ceil(count / cols) };
33
+ }
34
+ function missingTool(error) {
35
+ return error?.code === 'ENOENT';
36
+ }
37
+ /** A tool error as one readable line, FFmpeg's own last line included. */
38
+ function toolError(what, error) {
39
+ if (missingTool(error)) {
40
+ return new CliError('`makemidas frames` needs FFmpeg (ffmpeg and ffprobe on the PATH): https://ffmpeg.org/download.html', EXIT.USAGE, 'ffmpeg_missing');
41
+ }
42
+ const detail = String(error?.stderr ?? '')
43
+ .trim()
44
+ .split('\n')
45
+ .at(-1);
46
+ return new CliError(`${what}${detail ? `: ${detail}` : ''}`, EXIT.USAGE, 'bad_file');
47
+ }
48
+ /** The clip's length in seconds, from ffprobe. */
49
+ export async function probeSeconds(source, run = runTool) {
50
+ let out;
51
+ try {
52
+ out = await run('ffprobe', [
53
+ '-v',
54
+ 'error',
55
+ '-show_entries',
56
+ 'format=duration',
57
+ '-of',
58
+ 'default=noprint_wrappers=1:nokey=1',
59
+ source,
60
+ ]);
61
+ }
62
+ catch (error) {
63
+ throw toolError(`Can't read ${source} as a video`, error);
64
+ }
65
+ const seconds = Number.parseFloat(out.trim());
66
+ if (!Number.isFinite(seconds) || seconds <= 0) {
67
+ throw new CliError(`${source} has no length; give a video file or link.`, EXIT.USAGE, 'bad_file');
68
+ }
69
+ return seconds;
70
+ }
71
+ /** `clip.mp4` and `https://…/clip.mp4?x` both name the folder `clip-frames`. */
72
+ function folderName(source) {
73
+ let name = source;
74
+ if (/^https?:\/\//i.test(source)) {
75
+ try {
76
+ name = decodeURIComponent(new URL(source).pathname);
77
+ }
78
+ catch {
79
+ name = 'video';
80
+ }
81
+ }
82
+ const base = basename(name, extname(name)).replace(/[^\w.-]+/g, '-');
83
+ return `${base || 'video'}-frames`;
84
+ }
85
+ /**
86
+ * Save `count` stills of the clip and a contact sheet of them under
87
+ * `<out>/<name>-frames/`. Refuses to overwrite without `force`.
88
+ */
89
+ export async function makeFrames(source, opts, run = runTool) {
90
+ // A name starting with "-" would read as an FFmpeg option.
91
+ const input = source.startsWith('-') ? `./${source}` : source;
92
+ const seconds = await probeSeconds(input, run);
93
+ const dir = join(resolve(opts.out), folderName(source));
94
+ const sheet = join(dir, 'sheet.jpg');
95
+ if (existsSync(sheet) && !opts.force) {
96
+ throw new CliError(`${dir} exists; use --force to overwrite or -o for another folder.`, EXIT.USAGE, 'exists');
97
+ }
98
+ await mkdir(dir, { recursive: true });
99
+ const frames = [];
100
+ for (const [i, at] of frameTimes(seconds, opts.count).entries()) {
101
+ const file = join(dir, `${String(i + 1).padStart(2, '0')}.jpg`);
102
+ try {
103
+ await run('ffmpeg', [
104
+ '-v',
105
+ 'error',
106
+ '-ss',
107
+ String(at),
108
+ '-i',
109
+ input,
110
+ '-frames:v',
111
+ '1',
112
+ '-vf',
113
+ `scale=${opts.width}:-2`,
114
+ '-q:v',
115
+ '3',
116
+ '-y',
117
+ file,
118
+ ]);
119
+ }
120
+ catch (error) {
121
+ throw toolError(`Can't take a frame at ${at}s`, error);
122
+ }
123
+ if (!existsSync(file)) {
124
+ throw new CliError(`FFmpeg made no frame at ${at}s of ${source}.`, EXIT.USAGE, 'bad_file');
125
+ }
126
+ frames.push({ file, seconds: at });
127
+ }
128
+ const { cols, rows } = sheetGrid(frames.length);
129
+ try {
130
+ await run('ffmpeg', [
131
+ '-v',
132
+ 'error',
133
+ '-i',
134
+ join(dir, '%02d.jpg'),
135
+ '-vf',
136
+ // Only this run's stills, not ones left from a run with more.
137
+ `trim=end_frame=${frames.length},tile=${cols}x${rows}:padding=6:margin=6:color=black`,
138
+ '-frames:v',
139
+ '1',
140
+ '-q:v',
141
+ '3',
142
+ '-y',
143
+ sheet,
144
+ ]);
145
+ }
146
+ catch (error) {
147
+ throw toolError("Can't make the contact sheet", error);
148
+ }
149
+ return { seconds, sheet, frames };
150
+ }
151
+ /** The command: saves the stills and the sheet, prints the sheet's path. */
152
+ export async function frames(g, source, opts, run = runTool) {
153
+ const result = await makeFrames(source, opts, run);
154
+ if (g.json) {
155
+ printJson(result);
156
+ return;
157
+ }
158
+ log(`${result.frames.length} frames of ${result.seconds.toFixed(1)}s at ${result.frames.map((f) => `${f.seconds}s`).join(', ')}`);
159
+ print(result.sheet);
160
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makemidas/cli",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
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",