@makemidas/cli 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { Api } from "./api.js";
3
- import { generationInput, intOption, parse, usageError } from "./args.js";
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";
4
4
  import * as commands from "./commands.js";
5
+ import * as films from "./films.js";
5
6
  import { resolveBaseUrl, VERSION } from "./config.js";
6
- import { CliError, EXIT } from "./errors.js";
7
+ import { CliError, EXIT, formatError } from "./errors.js";
7
8
  import { setQuiet } from "./output.js";
8
- const HELP = `makemidas ${VERSION}: AI images and videos from the terminal, with your MakeMidas credits
9
+ const HELP = `makemidas ${VERSION}: AI images, videos, audio, transcripts and edits from the terminal, with your MakeMidas credits
9
10
 
10
11
  Usage:
11
12
  makemidas auth login [--no-browser] Sign in (opens the browser)
@@ -13,37 +14,130 @@ Usage:
13
14
  makemidas auth status Show the signed-in account
14
15
  makemidas image "<prompt>" Generate images and save them
15
16
  makemidas video "<prompt>" Generate a video and save it
17
+ makemidas music "<prompt>" Generate a song or track and save it
18
+ makemidas sfx "<prompt>" Generate a sound effect and save it
19
+ makemidas speech "<text>" Turn text into a voiceover (alias: voiceover)
20
+ makemidas transcribe <file|url> Transcribe audio or video, save the transcript
21
+ makemidas remove-bg <image> Remove the background (transparent WebP)
22
+ makemidas upscale <image> Upscale an image (--scale 1|2|4|8)
23
+ makemidas upscale-video <video> Upscale a clip (--resolution 1080P|2K|4K)
24
+ makemidas compare "<prompt>" --models a,b[,c,d]
25
+ One prompt on 2-4 image models
16
26
  makemidas get <id> Fetch a generation (and save its files)
17
27
  makemidas list Recent generations
28
+ makemidas delete <id> [--yes] Delete a generation and its files
29
+ makemidas brands [<id>|default] Saved brands, or one brand's guidelines
30
+ makemidas characters Saved characters
31
+ makemidas assets [--q words] [--kind image|video|audio]
32
+ Files in the asset library
18
33
  makemidas credits Credit balance and plan
19
- makemidas models [--kind image|video] Models, options and credit prices
34
+ makemidas credits buy Links and prices for plans and credit packs
35
+ makemidas estimate <command> "<prompt>|<file>"
36
+ Price a request without charging: image,
37
+ video, music, sfx, speech, transcribe,
38
+ remove-bg, upscale or upscale-video
39
+ makemidas models [<kind>] Models, options and credit prices; kind is
40
+ image, video, audio, transcription or edit
41
+ makemidas models <id> One model: options, defaults, prices
42
+ makemidas feedback "<message>" Send feedback (--kind bug|feature|praise|other,
43
+ --generation <id>)
20
44
 
21
- Generation options (image, video):
45
+ Film projects (a brief → script and storyboard → frames → clips, voiceover
46
+ and music → one film; each paid stage is approved at the credits shown):
47
+ makemidas film new "<brief>" Create a project and write its storyboard
48
+ makemidas film list Your film projects
49
+ makemidas film get <id> [--wait] Storyboard, progress, prices, what's next;
50
+ saves the film once assembled
51
+ makemidas film write <id> Write (or rewrite) the storyboard
52
+ makemidas film update <id> Change --title, --brief, settings, or the
53
+ storyboard from --file shots.json
54
+ makemidas film approve <id> frames|film
55
+ Approve the next stage at its price
56
+ makemidas film redo <id> <shot> frame|clip|voice
57
+ Make one piece of a shot again
58
+ makemidas film resume <id> Carry on after a top-up
59
+ makemidas film assemble <id> Assemble the film (free; it starts on its
60
+ own once every piece is made)
61
+ makemidas film download <id> [--pieces]
62
+ The film, or every clip, voiceover and the
63
+ music with timeline.json to cut it yourself
64
+ makemidas film delete <id> [--yes] Delete the project (its generations stay)
65
+
66
+ Generation options (image, video, estimate):
22
67
  -m, --model <id> Model id from \`makemidas models\` (default: cheapest)
23
68
  -a, --aspect <ratio> e.g. 1:1, 16:9, 9:16
24
69
  -r, --resolution <r> image: 1K | 2K | 4K; video: 480p | 720p | 1080p
25
70
  -n, --count <n> Outputs, 1-4 (default 1)
26
- --ref <file|url> Reference image; repeat for more. For videos: one is
71
+ --ref <file|url|asset:<id>>
72
+ Reference image; repeat for more. For videos: one is
27
73
  the first frame, two are first and last frame
28
74
  --style <id> photo, cinematic, film, anime, …
29
75
  --enhance Let MakeMidas expand a short prompt
76
+ --brand <id> A saved brand: its look and tone join the prompt
77
+ (\`makemidas brands\`); --brand-logo also sends its logo
78
+ --character <id> A saved character as the reference (\`makemidas characters\`)
30
79
  --quoted-credits <n> Refuse to charge anything else
31
- -d, --duration <s> video: seconds
80
+ --max-credits <n> Price it first, stop if it costs more, else run it
81
+ at exactly the quoted price (every generating command)
82
+ -d, --duration <s> video: seconds; music: track length (models that
83
+ list durations)
32
84
  --audio video: with sound (models that support it)
33
85
  --frame-mode <mode> video: none | first | first_last | reference
34
- --no-wait video: print the id and exit; fetch later with get
86
+ --no-wait Print the id and exit instead of waiting (everything
87
+ but image and compare); fetch later with get
88
+
89
+ Audio options:
90
+ --lyrics <text> music: lyrics to sing; the prompt gives the style
91
+ --title <title> music: track title; transcribe: transcript name
92
+ --instrumental music: no vocals (models that offer it)
93
+ --loop, --bpm <n> sfx: a seamless loop, its tempo (40-240)
94
+ --voice <id> speech: a voice of the model (\`makemidas models <id>\`)
95
+ --delivery <words> speech, Gemini TTS: how to read it, e.g. "warm, unhurried"
96
+ --speed <0.7-1.2> speech, ElevenLabs: speaking speed
97
+ --stability <0-1> speech, ElevenLabs: varied (0) to even (1)
98
+ --language <code> speech, models with a language choice: auto, en, …
99
+
100
+ Transcribe and edit options:
101
+ -m, --model <id> transcribe: default openai/whisper-large-v2
102
+ --format <f> transcribe: txt (default), srt, vtt or json
103
+ --scale <n> upscale: 1 (sharpen), 2 (default), 4 or 8
104
+ -r, --resolution <r> upscale-video: 1080P, 2K (default) or 4K
105
+
106
+ Compare options:
107
+ --models <a,b,…> 2-4 different image model ids
108
+ -a, --aspect, --ref, --max-credits, --quoted-credits as for image
35
109
 
36
- Output options (image, video, get):
37
- -o, --out <dir> Where to save files (default .)
110
+ Output options (generating commands, get):
111
+ -o, --out <dir> Where to save files (default .); transcribe: \`-\`
112
+ prints the transcript itself
38
113
  --no-download Print signed links (valid 1 hour) instead
39
114
  --force Overwrite existing files
40
- --wait get: wait until a video is done
41
- --timeout <min> How long to wait for a video (default 15)
115
+ --wait get: wait until it is done
116
+ --timeout <min> How long to wait (default 15)
117
+
118
+ Delete options:
119
+ -y, --yes Don't ask; required when stdin is not a terminal
42
120
 
43
121
  List options:
44
122
  --limit <n> How many (default 20, max 50)
45
123
  --before <ISO time> Older than this
46
124
 
125
+ Film options:
126
+ --seconds <n> About how long, 10-120 (default 30)
127
+ --title, --brief Name it; a new brief for \`write\` or \`update\`
128
+ -a, --aspect <ratio> 16:9, 9:16 or 1:1
129
+ --text-model <id> Writes the script (see \`makemidas models\`)
130
+ --video-model <id>, -r <res>, --frame-model <id>
131
+ --speech-model <id>, --voice <id|default>
132
+ --music-model <id|none>, --music-prompt <words>
133
+ --transition cut|fade|crossfade, --clip-audio, --brand <id|none>
134
+ --no-write film new: create it without writing the storyboard
135
+ --file <shots.json> film update: the whole storyboard, in order
136
+ --max-credits <n> Charge the step's price only if it is at most n
137
+ --quoted-credits <n> Charge exactly n (the price shown), or nothing
138
+ --wait, --timeout <min> Wait for the frames, the film or the assembly
139
+ -o, --out <dir> Where the film (or pieces) go (default .)
140
+
47
141
  Global:
48
142
  --json Machine-readable output on stdout
49
143
  --quiet No progress on stderr
@@ -51,11 +145,39 @@ Global:
51
145
  -v, --version Print the version
52
146
  -h, --help This help
53
147
 
148
+ Examples:
149
+ makemidas estimate video "the waves roll in" -d 5 --audio
150
+ makemidas video "the waves roll in" -d 5 --audio --max-credits 60
151
+ makemidas speech "Welcome back." --voice Kore --delivery "warm and unhurried"
152
+ makemidas transcribe interview.m4a --format srt
153
+ makemidas compare "a red fox in snow" --models a/one,b/two --max-credits 40
154
+ makemidas models google/gemini-omni-flash
155
+ makemidas film new "A 20-second ad for our cold brew" --max-credits 40
156
+ makemidas film approve <id> frames --quoted-credits 10 --wait
157
+
54
158
  Credentials: \`auth login\`, or MAKEMIDAS_API_KEY (Settings → API keys).
55
159
 
56
160
  Exit codes: 0 ok, 2 bad input, 3 not signed in, 4 not enough credits or plan
57
161
  limit, 5 generation failed, 6 network or server error, 7 not ready yet.
58
162
  `;
163
+ function maxCredits(v) {
164
+ const max = intOption(v['max-credits'], 'max-credits', 0, 1_000_000);
165
+ if (max !== undefined && v['quoted-credits'] !== undefined) {
166
+ throw usageError('Use --max-credits or --quoted-credits, not both.');
167
+ }
168
+ return max;
169
+ }
170
+ const isKind = (value) => KINDS.includes(value);
171
+ function audioTask(command) {
172
+ return command === 'voiceover' ? 'speech' : command;
173
+ }
174
+ function editTask(command) {
175
+ if (command === 'remove-bg')
176
+ return 'remove-background';
177
+ if (command === 'upscale')
178
+ return 'upscale-image';
179
+ return 'upscale-video';
180
+ }
59
181
  async function main(argv) {
60
182
  const { values: v, positionals } = parse(argv);
61
183
  setQuiet(v.quiet);
@@ -72,6 +194,7 @@ async function main(argv) {
72
194
  const g = { json: v.json };
73
195
  const save = { out: v['no-download'] ? null : v.out, force: v.force };
74
196
  const timeoutMin = intOption(v.timeout, 'timeout', 1, 120) ?? 15;
197
+ const wait = { wait: !v['no-wait'], timeoutMin };
75
198
  switch (command) {
76
199
  case 'auth': {
77
200
  const [sub] = rest;
@@ -86,7 +209,57 @@ async function main(argv) {
86
209
  }
87
210
  case 'image':
88
211
  case 'video':
89
- return commands.generate(api, g, generationInput(command, rest.join(' '), v), v.ref, save, { wait: !v['no-wait'], timeoutMin });
212
+ return commands.generate(api, g, generationInput(command, rest.join(' '), v), v.ref, save, wait, maxCredits(v));
213
+ case 'music':
214
+ case 'sfx':
215
+ case 'speech':
216
+ case 'voiceover':
217
+ return commands.generate(api, g, audioInput(audioTask(command), rest.join(' '), v), [], save, wait, maxCredits(v));
218
+ case 'transcribe': {
219
+ const source = sourceArg(rest, command, 'audio or video file');
220
+ const { input, format } = transcriptionInput(v);
221
+ return commands.transcribe(api, g, input, source, format, save, wait, maxCredits(v));
222
+ }
223
+ case 'remove-bg':
224
+ case 'upscale':
225
+ case 'upscale-video': {
226
+ const task = editTask(command);
227
+ const source = sourceArg(rest, command, task === 'upscale-video' ? 'video' : 'image');
228
+ const input = editInput(task, v);
229
+ return task === 'upscale-video'
230
+ ? commands.generate(api, g, input, [], save, wait, maxCredits(v), {
231
+ kind: 'video',
232
+ source,
233
+ })
234
+ : commands.generate(api, g, input, [source], save, wait, maxCredits(v));
235
+ }
236
+ case 'compare': {
237
+ compareOptions(v);
238
+ const prompt = rest.join(' ').trim();
239
+ if (!prompt) {
240
+ throw usageError('Give a prompt: `makemidas compare "a fox" --models a,b`.');
241
+ }
242
+ const quoted = intOption(v['quoted-credits'], 'quoted-credits', 0, 1_000_000);
243
+ return commands.compare(api, g, {
244
+ prompt,
245
+ models: compareModels(v.models),
246
+ ...(v.aspect ? { aspectRatio: v.aspect } : {}),
247
+ ...(quoted !== undefined ? { quotedCredits: quoted } : {}),
248
+ }, v.ref, save, maxCredits(v));
249
+ }
250
+ case 'delete':
251
+ if (rest.length > 1)
252
+ throw usageError('Delete one generation at a time.');
253
+ return commands.deleteGeneration(api, g, rest[0], {
254
+ yes: v.yes,
255
+ interactive: Boolean(process.stdin.isTTY),
256
+ });
257
+ case 'feedback':
258
+ return commands.feedback(api, g, {
259
+ kind: feedbackKind(v.kind),
260
+ message: rest.join(' '),
261
+ ...(v.generation ? { generationId: v.generation } : {}),
262
+ });
90
263
  case 'get':
91
264
  return commands.get(api, g, rest[0], save, { wait: v.wait, timeoutMin });
92
265
  case 'list':
@@ -94,15 +267,126 @@ async function main(argv) {
94
267
  limit: intOption(v.limit, 'limit', 1, 50) ?? 20,
95
268
  before: v.before,
96
269
  });
97
- case 'credits':
98
- return commands.credits(api, g);
270
+ case 'brands':
271
+ case 'brand':
272
+ return commands.brands(api, g, rest[0]);
273
+ case 'characters':
274
+ return commands.characters(api, g);
275
+ case 'assets':
276
+ return commands.assets(api, g, {
277
+ q: v.q ?? (rest.join(' ') || undefined),
278
+ kind: v.kind,
279
+ limit: intOption(v.limit, 'limit', 1, 60) ?? 20,
280
+ });
281
+ case 'credits': {
282
+ const [sub] = rest;
283
+ if (!sub)
284
+ return commands.credits(api, g);
285
+ if (sub === 'buy' || sub === 'link')
286
+ return commands.creditsLink(api, g);
287
+ throw usageError('Use `credits` or `credits buy`.');
288
+ }
289
+ case 'estimate': {
290
+ const [kind, ...args] = rest;
291
+ switch (kind) {
292
+ case 'image':
293
+ case 'video':
294
+ return commands.estimate(api, g, generationInput(kind, args.join(' '), v), v.ref);
295
+ case 'music':
296
+ case 'sfx':
297
+ case 'speech':
298
+ case 'voiceover':
299
+ return commands.estimate(api, g, audioInput(audioTask(kind), args.join(' '), v), [], kind);
300
+ case 'transcribe':
301
+ case 'transcription': {
302
+ const source = sourceArg(args, 'estimate transcribe', 'audio or video file');
303
+ return commands.estimate(api, g, transcriptionInput(v).input, [], 'transcribe', {
304
+ kind: 'audio',
305
+ source,
306
+ });
307
+ }
308
+ case 'remove-bg':
309
+ case 'upscale':
310
+ case 'upscale-video': {
311
+ const task = editTask(kind);
312
+ const source = sourceArg(args, `estimate ${kind}`, task === 'upscale-video' ? 'video' : 'image');
313
+ const input = editInput(task, v);
314
+ return task === 'upscale-video'
315
+ ? commands.estimate(api, g, input, [], kind, { kind: 'video', source })
316
+ : commands.estimate(api, g, input, [source], kind);
317
+ }
318
+ default:
319
+ throw usageError('Use `estimate <command> …` with image, video, music, sfx, speech, transcribe, remove-bg, upscale or upscale-video.');
320
+ }
321
+ }
99
322
  case 'models': {
100
- const kind = v.kind;
101
- if (kind && kind !== 'image' && kind !== 'video') {
102
- throw usageError('--kind must be image or video.');
323
+ const [arg] = rest;
324
+ if (arg && !isKind(arg)) {
325
+ return commands.modelDetails(api, g, arg);
326
+ }
327
+ const kind = v.kind ?? arg;
328
+ if (kind && !isKind(kind)) {
329
+ throw usageError(`--kind must be ${KINDS.join(', ')}.`);
103
330
  }
104
331
  return commands.models(api, g, kind);
105
332
  }
333
+ case 'film':
334
+ case 'films': {
335
+ const [sub, id, ...args] = rest;
336
+ const price = {
337
+ maxCredits: maxCredits(v),
338
+ quotedCredits: intOption(v['quoted-credits'], 'quoted-credits', 0, 1_000_000),
339
+ };
340
+ const filmWait = { wait: v.wait, timeoutMin };
341
+ switch (sub) {
342
+ case 'list':
343
+ case undefined:
344
+ return films.filmList(api, g);
345
+ case 'new':
346
+ case 'create':
347
+ return films.filmNew(api, g, {
348
+ brief: [id, ...args].filter(Boolean).join(' '),
349
+ ...(v.title ? { title: v.title } : {}),
350
+ settings: filmSettings(v),
351
+ write: !v['no-write'],
352
+ targetSeconds: filmSeconds(v),
353
+ }, price);
354
+ case 'get':
355
+ case 'show':
356
+ return films.filmGet(api, g, id, save, filmWait);
357
+ case 'write':
358
+ return films.filmWrite(api, g, id, {
359
+ ...(filmSeconds(v) !== undefined ? { targetSeconds: filmSeconds(v) } : {}),
360
+ ...(v.brief ? { brief: v.brief } : {}),
361
+ }, price);
362
+ case 'update': {
363
+ const settings = filmSettings(v);
364
+ return films.filmUpdate(api, g, id, {
365
+ ...(v.title ? { title: v.title } : {}),
366
+ ...(v.brief ? { brief: v.brief } : {}),
367
+ ...(Object.keys(settings).length ? { settings } : {}),
368
+ ...(v.file ? { shots: await films.readStoryboard(v.file) } : {}),
369
+ });
370
+ }
371
+ case 'approve':
372
+ return films.filmApprove(api, g, id, args[0], price, save, filmWait);
373
+ case 'redo':
374
+ return films.filmRedo(api, g, id, args[0], args[1], price, filmWait);
375
+ case 'resume':
376
+ return films.filmResume(api, g, id, filmWait);
377
+ case 'assemble':
378
+ return films.filmAssemble(api, g, id, save, filmWait);
379
+ case 'download':
380
+ return films.filmDownload(api, g, id, save, { pieces: v.pieces });
381
+ case 'delete':
382
+ return films.filmDelete(api, g, id, {
383
+ yes: v.yes,
384
+ interactive: Boolean(process.stdin.isTTY),
385
+ });
386
+ default:
387
+ throw usageError('Use `film new`, `list`, `get`, `write`, `update`, `approve`, `redo`, `resume`, `assemble`, `download` or `delete`.');
388
+ }
389
+ }
106
390
  default:
107
391
  throw usageError(`Unknown command "${command}".`);
108
392
  }
@@ -111,11 +395,6 @@ main(process.argv.slice(2)).then(() => process.exit(EXIT.OK), (error) => {
111
395
  const cli = error instanceof CliError
112
396
  ? error
113
397
  : new CliError(error?.message ?? String(error), EXIT.NETWORK, 'internal');
114
- if (process.argv.includes('--json')) {
115
- process.stderr.write(`${JSON.stringify({ error: { code: cli.code, message: cli.message } })}\n`);
116
- }
117
- else {
118
- process.stderr.write(`Error: ${cli.message}\n`);
119
- }
398
+ process.stderr.write(`${formatError(cli, process.argv.includes('--json'))}\n`);
120
399
  process.exit(cli.exitCode);
121
400
  });