@makemidas/cli 0.8.0 → 0.10.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
@@ -51,6 +51,7 @@ makemidas film new "a 15-second social video for our mugs" --style social --max-
51
51
  | `characters create "<name>" <image>` (or `--from <generationId> [--image n]`), `characters add <id> <image>` | Save a character from a JPG, PNG or WebP or one of your generated images (`--description` for its notes); up to 20 characters, 10 images each. Use it with `--character <id>` |
52
52
  | `examples [words] [--kind] [-m <model>] [--limit 1-20]` | Real results with the model and the exact prompt that made each; free |
53
53
  | `assets upload <file\|url>… [--name] [--tag t]`, `assets delete <id>` | Keep files in the asset library, or remove one |
54
+ | `assets keep <generationId>[/<n>]… [--name] [--tag t]` | Keep generated results in the asset library (every finished output without `/<n>`); copied on MakeMidas, no extra credits |
54
55
  | `get <id> [--wait]` | Fetch a generation and save its files |
55
56
  | `list [--limit n] [--before t]` | Recent generations |
56
57
  | `delete <id> [--yes]` | Delete a finished or failed generation and its files (no refund) |
@@ -65,7 +66,8 @@ makemidas film new "a 15-second social video for our mugs" --style social --max-
65
66
 
66
67
  Common options: `--model`, `--aspect`, `--resolution`, `--count`, `--ref`
67
68
  (file or URL, repeatable), `--style`, `--enhance`, `--duration`, `--audio`,
68
- `--frame-mode`, `--out <dir>`, `--no-download`, `--no-wait`, `--json`. Run
69
+ `--frame-mode`, `--out <dir>`, `--no-download`, `--no-wait`, `--keep` (with
70
+ `--tag`), `--json`. Run
69
71
  `makemidas --help` for all of them. An option that belongs to another
70
72
  command (say `--lyrics` on `sfx`) is a usage error.
71
73
 
@@ -110,12 +112,14 @@ stdin is not a terminal), 3 not signed in, 4 not enough credits, a plan
110
112
  limit or busy (also over `--max-credits`), 5 generation failed (credits
111
113
  refunded), 6 network or server error, 7 still rendering.
112
114
 
113
- Every generating request carries an `Idempotency-Key`. When its answer is
114
- lost (a dropped connection, a server error), the CLI asks again with the
115
- same key after 2, 5 and 10 seconds; MakeMidas answers the generation the
116
- first attempt started, so nothing is made or charged twice. Exit 6 after
117
- that means it still had no answer: look for the generation with
118
- `makemidas list` before running the command again.
115
+ Every request that spends credits carries an `Idempotency-Key`: generating,
116
+ `compare`, template videos (`render --video`, `html --video`) and film
117
+ `approve` and `redo`. When its answer is lost (a dropped connection, a
118
+ server error), the CLI asks again with the same key after 2, 5 and 10
119
+ seconds; MakeMidas answers what the first attempt made, so nothing is made
120
+ or charged twice. Exit 6 after that means it still had no answer: look for
121
+ it with `makemidas list` (or `makemidas film get <id>`) before running the
122
+ command again.
119
123
 
120
124
  ## Talking avatars
121
125
 
@@ -191,6 +195,8 @@ makemidas video "she waves at the camera" --character <id> -d 5
191
195
  makemidas assets --q "product shot" --kind image
192
196
  makemidas image "the same bottle on a beach" --ref asset:<id>
193
197
  makemidas assets upload logo.png bottle.jpg --tag brand
198
+ makemidas image "our bottle, studio shot" --keep --tag product
199
+ makemidas assets keep <generationId>/2 --name "hero shot"
194
200
  makemidas assets delete <id> --yes
195
201
  ```
196
202
 
@@ -198,6 +204,9 @@ makemidas assets delete <id> --yes
198
204
  images, its style pictures as references; `--brand-logo` also sends its
199
205
  logo). `--character <id>` sends the character's pictures as references.
200
206
  `--ref asset:<id>` uses a file from the asset library like a local one.
207
+ `--keep` on any generating command (and `get`, `render`, `compare`) also
208
+ keeps each finished result in the library, labeled with `--tag`; a full
209
+ library is a warning, not a failed command, since the result is paid for.
201
210
 
202
211
  ## Film projects
203
212
 
package/dist/api.js CHANGED
@@ -319,12 +319,18 @@ export class Api {
319
319
  * again answers the generation the first attempt started instead of
320
320
  * starting, and charging for, another.
321
321
  */
322
- async generate(input, key = randomUUID()) {
322
+ /**
323
+ * POST a request that spends credits with an Idempotency-Key, and send it
324
+ * again with the same key when the answer is lost, so the server answers
325
+ * what the first one made instead of charging twice. `lookup` says where
326
+ * to look when every try failed.
327
+ */
328
+ async postOnce(path, json, key, lookup) {
323
329
  for (let attempt = 0;; attempt++) {
324
330
  try {
325
- return await this.json('/generations', {
331
+ return await this.json(path, {
326
332
  method: 'POST',
327
- json: input,
333
+ json,
328
334
  headers: { 'Idempotency-Key': key },
329
335
  });
330
336
  }
@@ -334,13 +340,16 @@ export class Api {
334
340
  const delay = GENERATE_RETRY_MS[attempt];
335
341
  if (delay === undefined) {
336
342
  const last = error;
337
- 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);
343
+ throw new CliError(`${last.message}. It may have started anyway: ${lookup} before running this again.`, last.exitCode, last.code, last.details);
338
344
  }
339
345
  log(`No answer yet (${error.message}); asking again in ${delay / 1000} s with the same request key, so nothing is charged twice…`);
340
346
  await this.sleep(delay);
341
347
  }
342
348
  }
343
349
  }
350
+ generate(input, key = randomUUID()) {
351
+ return this.postOnce('/generations', input, key, 'look for it with `makemidas list`');
352
+ }
344
353
  /** Price a request without charging or creating anything. */
345
354
  estimate(input) {
346
355
  return this.json('/generations/estimate', {
@@ -354,11 +363,8 @@ export class Api {
354
363
  });
355
364
  }
356
365
  /** Run one prompt on 2-4 image models at once. */
357
- compare(input) {
358
- return this.json('/generations/compare', {
359
- method: 'POST',
360
- json: input,
361
- });
366
+ compare(input, key = randomUUID()) {
367
+ return this.postOnce('/generations/compare', input, key, 'look for them with `makemidas list`');
362
368
  }
363
369
  /** Delete a finished or failed generation and its files. */
364
370
  deleteGeneration(id) {
@@ -415,6 +421,21 @@ export class Api {
415
421
  }
416
422
  return saved;
417
423
  }
424
+ /**
425
+ * Keep one finished output of your own generation in the asset library:
426
+ * copied on MakeMidas, nothing is uploaded or charged.
427
+ */
428
+ keepGeneration(generationId, index, opts = {}) {
429
+ return this.json('/assets', {
430
+ method: 'POST',
431
+ json: {
432
+ generationId,
433
+ index,
434
+ ...(opts.name ? { name: opts.name } : {}),
435
+ ...(opts.tags?.length ? { tags: opts.tags } : {}),
436
+ },
437
+ });
438
+ }
418
439
  async deleteAsset(id) {
419
440
  await this.request(`/assets/${encodeURIComponent(id)}`, { method: 'DELETE' });
420
441
  }
@@ -444,11 +465,8 @@ export class Api {
444
465
  return this.json('/renders', { method: 'POST', json: input });
445
466
  }
446
467
  /** A video; it answers while rendering, so read the generation until done. */
447
- videoRender(input) {
448
- return this.json('/video-renders', {
449
- method: 'POST',
450
- json: input,
451
- });
468
+ videoRender(input, key = randomUUID()) {
469
+ return this.postOnce('/video-renders', input, key, 'look for it with `makemidas list`');
452
470
  }
453
471
  // ---------------------------------------------------------------- films
454
472
  async films() {
@@ -484,14 +502,11 @@ export class Api {
484
502
  json: input,
485
503
  });
486
504
  }
487
- approveFilm(id, input) {
488
- return this.json(`/films/${encodeURIComponent(id)}/approve`, {
489
- method: 'POST',
490
- json: input,
491
- });
505
+ approveFilm(id, input, key = randomUUID()) {
506
+ return this.postOnce(`/films/${encodeURIComponent(id)}/approve`, input, key, `check it with \`makemidas film get ${id}\``);
492
507
  }
493
- redoShot(id, shotId, input) {
494
- return this.json(`/films/${encodeURIComponent(id)}/shots/${encodeURIComponent(shotId)}/redo`, { method: 'POST', json: input });
508
+ redoShot(id, shotId, input, key = randomUUID()) {
509
+ return this.postOnce(`/films/${encodeURIComponent(id)}/shots/${encodeURIComponent(shotId)}/redo`, input, key, `check it with \`makemidas film get ${id}\``);
495
510
  }
496
511
  resumeFilm(id) {
497
512
  return this.json(`/films/${encodeURIComponent(id)}/resume`, {
package/dist/args.js CHANGED
@@ -80,6 +80,7 @@ export function parse(argv) {
80
80
  description: { type: 'string' },
81
81
  fields: { type: 'string' },
82
82
  tag: { type: 'string', multiple: true, default: [] },
83
+ keep: { type: 'boolean', default: false },
83
84
  subtitles: { type: 'string' },
84
85
  'title-card': { type: 'string' },
85
86
  'end-card': { type: 'string' },
package/dist/cli.js CHANGED
@@ -43,6 +43,8 @@ Usage:
43
43
  makemidas assets [--q words] [--kind image|video|audio]
44
44
  Search the asset library
45
45
  makemidas assets upload <file|url>… Keep files in the asset library (--name, --tag)
46
+ makemidas assets keep <id>[/<n>]… Keep generated results in the library
47
+ (all finished outputs without /n; --name, --tag)
46
48
  makemidas assets delete <id> [--yes] Remove a file from the library
47
49
  makemidas credits Credit balance and plan
48
50
  makemidas credits activity Grants, charges and refunds, newest first
@@ -184,6 +186,9 @@ Output options (generating commands, get):
184
186
  prints the transcript itself
185
187
  --no-download Print signed links (valid 1 hour) instead
186
188
  --force Overwrite existing files
189
+ --keep Also keep each finished result in the asset library
190
+ (copied there, no extra credits); --tag <t>, repeat
191
+ for more, labels them
187
192
  --wait get: wait until it is done
188
193
  --timeout <min> How long to wait (default 15)
189
194
 
@@ -322,7 +327,14 @@ async function main(argv) {
322
327
  }
323
328
  const api = new Api(resolveBaseUrl(v['base-url']));
324
329
  const g = { json: v.json };
325
- const save = { out: v['no-download'] ? null : v.out, force: v.force };
330
+ const save = {
331
+ out: v['no-download'] ? null : v.out,
332
+ force: v.force,
333
+ keep: v.keep ? v.tag : null,
334
+ };
335
+ if (v.tag.length && !v.keep && command !== 'assets') {
336
+ throw usageError('--tag goes with --keep, or with `assets upload` and `assets keep`.');
337
+ }
326
338
  const timeoutMin = intOption(v.timeout, 'timeout', 1, 120) ?? 15;
327
339
  const wait = { wait: !v['no-wait'], timeoutMin };
328
340
  switch (command) {
@@ -346,6 +358,9 @@ async function main(argv) {
346
358
  case 'voiceover':
347
359
  return commands.generate(api, g, audioInput(audioTask(command), rest.join(' '), v), [], save, wait, maxCredits(v));
348
360
  case 'transcribe': {
361
+ if (v.keep) {
362
+ throw usageError('--keep keeps images, clips and tracks; transcripts stay in `makemidas list`.');
363
+ }
349
364
  const source = sourceArg(rest, command, 'audio or video file');
350
365
  const { input, format } = transcriptionInput(v);
351
366
  return commands.transcribe(api, g, input, source, format, save, wait, maxCredits(v));
@@ -494,6 +509,12 @@ async function main(argv) {
494
509
  tags: v.tag,
495
510
  });
496
511
  }
512
+ if (rest[0] === 'keep') {
513
+ return templates.assetKeep(api, g, rest.slice(1), {
514
+ ...(v.name ? { name: v.name } : {}),
515
+ tags: v.tag,
516
+ });
517
+ }
497
518
  if (rest[0] === 'delete' || rest[0] === 'rm') {
498
519
  if (rest.length > 2)
499
520
  throw usageError('Delete one asset at a time.');
package/dist/commands.js CHANGED
@@ -83,6 +83,40 @@ export async function authLogout(api, g) {
83
83
  else
84
84
  print(removed ? 'Signed out.' : 'Not signed in.');
85
85
  }
86
+ /**
87
+ * With `--keep`, keep every finished output in the asset library. The
88
+ * generation is already paid for, so a refusal (a full library, a file
89
+ * over the library's size limit) is a warning, not a failed command.
90
+ */
91
+ export async function keepOutputs(api, generation, save) {
92
+ if (!save.keep)
93
+ return [];
94
+ const kept = [];
95
+ for (const [index, output] of generation.outputs.entries()) {
96
+ if (output.status !== 'done' || !output.url)
97
+ continue;
98
+ try {
99
+ const saved = await api.keepGeneration(generation.id, index, {
100
+ tags: save.keep,
101
+ });
102
+ kept.push({
103
+ index,
104
+ id: saved.asset.id,
105
+ name: saved.asset.name,
106
+ deduped: saved.deduped,
107
+ });
108
+ log(`Kept in the library: ${saved.asset.id} ${saved.asset.name}${saved.deduped ? ' (already kept)' : ''}`);
109
+ }
110
+ catch (error) {
111
+ if (!(error instanceof CliError))
112
+ throw error;
113
+ warn(`Not kept in the library: ${error.message}`);
114
+ if (error.code === 'storage_full')
115
+ break;
116
+ }
117
+ }
118
+ return kept;
119
+ }
86
120
  /** Save every finished output into `dir`; returns the file paths. */
87
121
  export async function saveOutputs(api, generation, save) {
88
122
  if (!save.out)
@@ -111,9 +145,9 @@ export async function waitFor(api, generation, timeoutMin) {
111
145
  }
112
146
  return current;
113
147
  }
114
- export function report(g, generation, files, links = generation.outputs.flatMap((o) => (o.url ? [o.url] : []))) {
148
+ export function report(g, generation, files, links = generation.outputs.flatMap((o) => (o.url ? [o.url] : [])), kept) {
115
149
  if (g.json) {
116
- printJson({ ...generation, files });
150
+ printJson({ ...generation, files, ...(kept ? { assets: kept } : {}) });
117
151
  }
118
152
  else {
119
153
  if (files.length)
@@ -206,7 +240,8 @@ async function start(api, input, refs, wait, maxCredits, media) {
206
240
  export async function generate(api, g, input, refs, save, wait, maxCredits, media) {
207
241
  const generation = await start(api, input, refs, wait, maxCredits, media);
208
242
  const files = await saveOutputs(api, generation, save);
209
- report(g, generation, files);
243
+ const kept = save.keep ? await keepOutputs(api, generation, save) : undefined;
244
+ report(g, generation, files, undefined, kept);
210
245
  }
211
246
  // ---------------------------------------------------------------------------
212
247
  // transcribe
@@ -265,7 +300,8 @@ export async function get(api, g, id, save, wait) {
265
300
  generation = await waitFor(api, generation, wait.timeoutMin);
266
301
  }
267
302
  const files = await saveOutputs(api, generation, save);
268
- report(g, generation, files);
303
+ const kept = save.keep ? await keepOutputs(api, generation, save) : undefined;
304
+ report(g, generation, files, undefined, kept);
269
305
  }
270
306
  // ---------------------------------------------------------------------------
271
307
  // estimate
@@ -579,11 +615,15 @@ export async function compare(api, g, request, refs, save, maxCredits) {
579
615
  log(`Comparing ${request.models.join(', ')}…`);
580
616
  const result = await api.compare(body);
581
617
  const files = [];
618
+ const kept = [];
582
619
  for (const generation of result.generations) {
583
620
  files.push(...(await saveOutputs(api, generation, save)));
621
+ for (const asset of await keepOutputs(api, generation, save)) {
622
+ kept.push({ generationId: generation.id, ...asset });
623
+ }
584
624
  }
585
625
  if (g.json) {
586
- printJson({ ...result, files });
626
+ printJson({ ...result, files, ...(save.keep ? { assets: kept } : {}) });
587
627
  }
588
628
  else {
589
629
  for (const generation of result.generations) {
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.8.0';
4
+ export const VERSION = '0.10.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/templates.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFile } from 'node:fs/promises';
2
- import { askYesNo, report, saveOutputs, waitFor, } from "./commands.js";
2
+ import { askYesNo, report, keepOutputs, saveOutputs, waitFor, } from "./commands.js";
3
3
  import { CliError, EXIT } from "./errors.js";
4
4
  import { formatBytes, log, print, printJson } from "./output.js";
5
5
  /*
@@ -102,12 +102,13 @@ export async function render(api, g, request, save, wait) {
102
102
  generation = await waitFor(api, generation, wait.timeoutMin);
103
103
  }
104
104
  const files = await saveOutputs(api, generation, save);
105
+ const kept = save.keep ? await keepOutputs(api, generation, save) : undefined;
105
106
  if (!g.json && result.quota) {
106
107
  log(result.credits
107
108
  ? `${result.credits} credit (no free renders left today).`
108
109
  : `Free: ${result.quota.freeLeft} of ${result.quota.freePerDay} free renders left today.`);
109
110
  }
110
- report(g, generation, files);
111
+ report(g, generation, files, undefined, kept);
111
112
  }
112
113
  /** `makemidas render <templateId> --set …`. */
113
114
  export function templateRender(templateId, values, options, brandId) {
@@ -221,6 +222,61 @@ export async function assetUpload(api, g, sources, opts) {
221
222
  else
222
223
  log('Use one with --ref asset:<id>, or in a template with --set <field>=asset:<id>.');
223
224
  }
225
+ /**
226
+ * `assets keep <id>[/<n>]…`: keep finished outputs of your generations in
227
+ * the library (every finished output of a generation without `/<n>`; `n`
228
+ * counts from 1 like the saved file names).
229
+ */
230
+ export async function assetKeep(api, g, refs, opts) {
231
+ if (!refs.length) {
232
+ throw new CliError('Give one or more generation ids: `makemidas assets keep <id>[/<n>]`.', EXIT.USAGE, 'usage');
233
+ }
234
+ const picks = [];
235
+ for (const ref of refs) {
236
+ const match = /^(?:generation:)?([^/\s]+?)(?:[/.](\d+))?$/.exec(ref);
237
+ if (!match) {
238
+ throw new CliError(`Not a generation id: ${ref}`, EXIT.USAGE, 'usage');
239
+ }
240
+ const [, id, n] = match;
241
+ if (n !== undefined) {
242
+ if (Number(n) < 1) {
243
+ throw new CliError(`Outputs count from 1: ${ref}`, EXIT.USAGE, 'usage');
244
+ }
245
+ picks.push({ id, index: Number(n) - 1 });
246
+ continue;
247
+ }
248
+ const generation = await api.generation(id);
249
+ const done = generation.outputs.flatMap((output, index) => output.status === 'done' ? [{ id, index }] : []);
250
+ if (!done.length) {
251
+ throw new CliError(`${id} has no finished output to keep (${generation.status}).`, EXIT.NOT_READY, 'not_ready');
252
+ }
253
+ picks.push(...done);
254
+ }
255
+ if (opts.name && picks.length > 1) {
256
+ throw new CliError('--name goes with one output.', EXIT.USAGE, 'usage');
257
+ }
258
+ const saved = [];
259
+ for (const pick of picks) {
260
+ const result = await api.keepGeneration(pick.id, pick.index, opts);
261
+ saved.push({ ...pick, ...result });
262
+ if (!g.json) {
263
+ print(`${result.asset.id} ${result.asset.kind.padEnd(5)} ${formatBytes(result.asset.size).padStart(8)} ${result.asset.name}${result.deduped ? ' (already kept)' : ''}`);
264
+ }
265
+ }
266
+ if (g.json) {
267
+ printJson({
268
+ assets: saved.map((s) => ({
269
+ ...s.asset,
270
+ deduped: s.deduped,
271
+ generationId: s.id,
272
+ index: s.index,
273
+ })),
274
+ });
275
+ }
276
+ else {
277
+ log('Use one with --ref asset:<id>, or in a template with --set <field>=asset:<id>.');
278
+ }
279
+ }
224
280
  export async function assetDelete(api, g, id, opts) {
225
281
  const assetId = need(id, 'an asset id: `makemidas assets delete <id>`');
226
282
  await confirmDelete(opts, `the asset ${assetId}`, 'Generations made with it stay.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makemidas/cli",
3
- "version": "0.8.0",
3
+ "version": "0.10.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",