@makemidas/cli 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,11 +1,11 @@
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, feedbackKind, generationInput, intOption, parse, sourceArg, transcriptionInput, usageError, } from "./args.js";
4
4
  import * as commands from "./commands.js";
5
5
  import { resolveBaseUrl, VERSION } from "./config.js";
6
- import { CliError, EXIT } from "./errors.js";
6
+ import { CliError, EXIT, formatError } from "./errors.js";
7
7
  import { setQuiet } from "./output.js";
8
- const HELP = `makemidas ${VERSION}: AI images and videos from the terminal, with your MakeMidas credits
8
+ const HELP = `makemidas ${VERSION}: AI images, videos, audio, transcripts and edits from the terminal, with your MakeMidas credits
9
9
 
10
10
  Usage:
11
11
  makemidas auth login [--no-browser] Sign in (opens the browser)
@@ -13,12 +13,31 @@ Usage:
13
13
  makemidas auth status Show the signed-in account
14
14
  makemidas image "<prompt>" Generate images and save them
15
15
  makemidas video "<prompt>" Generate a video and save it
16
+ makemidas music "<prompt>" Generate a song or track and save it
17
+ makemidas sfx "<prompt>" Generate a sound effect and save it
18
+ makemidas speech "<text>" Turn text into a voiceover (alias: voiceover)
19
+ makemidas transcribe <file|url> Transcribe audio or video, save the transcript
20
+ makemidas remove-bg <image> Remove the background (transparent WebP)
21
+ makemidas upscale <image> Upscale an image (--scale 1|2|4|8)
22
+ makemidas upscale-video <video> Upscale a clip (--resolution 1080P|2K|4K)
23
+ makemidas compare "<prompt>" --models a,b[,c,d]
24
+ One prompt on 2-4 image models
16
25
  makemidas get <id> Fetch a generation (and save its files)
17
26
  makemidas list Recent generations
27
+ makemidas delete <id> [--yes] Delete a generation and its files
18
28
  makemidas credits Credit balance and plan
19
- makemidas models [--kind image|video] Models, options and credit prices
29
+ makemidas credits buy Links and prices for plans and credit packs
30
+ makemidas estimate <command> "<prompt>|<file>"
31
+ Price a request without charging: image,
32
+ video, music, sfx, speech, transcribe,
33
+ remove-bg, upscale or upscale-video
34
+ makemidas models [<kind>] Models, options and credit prices; kind is
35
+ image, video, audio, transcription or edit
36
+ makemidas models <id> One model: options, defaults, prices
37
+ makemidas feedback "<message>" Send feedback (--kind bug|feature|praise|other,
38
+ --generation <id>)
20
39
 
21
- Generation options (image, video):
40
+ Generation options (image, video, estimate):
22
41
  -m, --model <id> Model id from \`makemidas models\` (default: cheapest)
23
42
  -a, --aspect <ratio> e.g. 1:1, 16:9, 9:16
24
43
  -r, --resolution <r> image: 1K | 2K | 4K; video: 480p | 720p | 1080p
@@ -28,17 +47,46 @@ Generation options (image, video):
28
47
  --style <id> photo, cinematic, film, anime, …
29
48
  --enhance Let MakeMidas expand a short prompt
30
49
  --quoted-credits <n> Refuse to charge anything else
31
- -d, --duration <s> video: seconds
50
+ --max-credits <n> Price it first, stop if it costs more, else run it
51
+ at exactly the quoted price (every generating command)
52
+ -d, --duration <s> video: seconds; music: track length (models that
53
+ list durations)
32
54
  --audio video: with sound (models that support it)
33
55
  --frame-mode <mode> video: none | first | first_last | reference
34
- --no-wait video: print the id and exit; fetch later with get
56
+ --no-wait Print the id and exit instead of waiting (everything
57
+ but image and compare); fetch later with get
35
58
 
36
- Output options (image, video, get):
37
- -o, --out <dir> Where to save files (default .)
59
+ Audio options:
60
+ --lyrics <text> music: lyrics to sing; the prompt gives the style
61
+ --title <title> music: track title; transcribe: transcript name
62
+ --instrumental music: no vocals (models that offer it)
63
+ --loop, --bpm <n> sfx: a seamless loop, its tempo (40-240)
64
+ --voice <id> speech: a voice of the model (\`makemidas models <id>\`)
65
+ --delivery <words> speech, Gemini TTS: how to read it, e.g. "warm, unhurried"
66
+ --speed <0.7-1.2> speech, ElevenLabs: speaking speed
67
+ --stability <0-1> speech, ElevenLabs: varied (0) to even (1)
68
+ --language <code> speech, models with a language choice: auto, en, …
69
+
70
+ Transcribe and edit options:
71
+ -m, --model <id> transcribe: default openai/whisper-large-v2
72
+ --format <f> transcribe: txt (default), srt, vtt or json
73
+ --scale <n> upscale: 1 (sharpen), 2 (default), 4 or 8
74
+ -r, --resolution <r> upscale-video: 1080P, 2K (default) or 4K
75
+
76
+ Compare options:
77
+ --models <a,b,…> 2-4 different image model ids
78
+ -a, --aspect, --ref, --max-credits, --quoted-credits as for image
79
+
80
+ Output options (generating commands, get):
81
+ -o, --out <dir> Where to save files (default .); transcribe: \`-\`
82
+ prints the transcript itself
38
83
  --no-download Print signed links (valid 1 hour) instead
39
84
  --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)
85
+ --wait get: wait until it is done
86
+ --timeout <min> How long to wait (default 15)
87
+
88
+ Delete options:
89
+ -y, --yes Don't ask; required when stdin is not a terminal
42
90
 
43
91
  List options:
44
92
  --limit <n> How many (default 20, max 50)
@@ -51,11 +99,37 @@ Global:
51
99
  -v, --version Print the version
52
100
  -h, --help This help
53
101
 
102
+ Examples:
103
+ makemidas estimate video "the waves roll in" -d 5 --audio
104
+ makemidas video "the waves roll in" -d 5 --audio --max-credits 60
105
+ makemidas speech "Welcome back." --voice Kore --delivery "warm and unhurried"
106
+ makemidas transcribe interview.m4a --format srt
107
+ makemidas compare "a red fox in snow" --models a/one,b/two --max-credits 40
108
+ makemidas models google/gemini-omni-flash
109
+
54
110
  Credentials: \`auth login\`, or MAKEMIDAS_API_KEY (Settings → API keys).
55
111
 
56
112
  Exit codes: 0 ok, 2 bad input, 3 not signed in, 4 not enough credits or plan
57
113
  limit, 5 generation failed, 6 network or server error, 7 not ready yet.
58
114
  `;
115
+ function maxCredits(v) {
116
+ const max = intOption(v['max-credits'], 'max-credits', 0, 1_000_000);
117
+ if (max !== undefined && v['quoted-credits'] !== undefined) {
118
+ throw usageError('Use --max-credits or --quoted-credits, not both.');
119
+ }
120
+ return max;
121
+ }
122
+ const isKind = (value) => KINDS.includes(value);
123
+ function audioTask(command) {
124
+ return command === 'voiceover' ? 'speech' : command;
125
+ }
126
+ function editTask(command) {
127
+ if (command === 'remove-bg')
128
+ return 'remove-background';
129
+ if (command === 'upscale')
130
+ return 'upscale-image';
131
+ return 'upscale-video';
132
+ }
59
133
  async function main(argv) {
60
134
  const { values: v, positionals } = parse(argv);
61
135
  setQuiet(v.quiet);
@@ -72,6 +146,7 @@ async function main(argv) {
72
146
  const g = { json: v.json };
73
147
  const save = { out: v['no-download'] ? null : v.out, force: v.force };
74
148
  const timeoutMin = intOption(v.timeout, 'timeout', 1, 120) ?? 15;
149
+ const wait = { wait: !v['no-wait'], timeoutMin };
75
150
  switch (command) {
76
151
  case 'auth': {
77
152
  const [sub] = rest;
@@ -86,7 +161,57 @@ async function main(argv) {
86
161
  }
87
162
  case 'image':
88
163
  case 'video':
89
- return commands.generate(api, g, generationInput(command, rest.join(' '), v), v.ref, save, { wait: !v['no-wait'], timeoutMin });
164
+ return commands.generate(api, g, generationInput(command, rest.join(' '), v), v.ref, save, wait, maxCredits(v));
165
+ case 'music':
166
+ case 'sfx':
167
+ case 'speech':
168
+ case 'voiceover':
169
+ return commands.generate(api, g, audioInput(audioTask(command), rest.join(' '), v), [], save, wait, maxCredits(v));
170
+ case 'transcribe': {
171
+ const source = sourceArg(rest, command, 'audio or video file');
172
+ const { input, format } = transcriptionInput(v);
173
+ return commands.transcribe(api, g, input, source, format, save, wait, maxCredits(v));
174
+ }
175
+ case 'remove-bg':
176
+ case 'upscale':
177
+ case 'upscale-video': {
178
+ const task = editTask(command);
179
+ const source = sourceArg(rest, command, task === 'upscale-video' ? 'video' : 'image');
180
+ const input = editInput(task, v);
181
+ return task === 'upscale-video'
182
+ ? commands.generate(api, g, input, [], save, wait, maxCredits(v), {
183
+ kind: 'video',
184
+ source,
185
+ })
186
+ : commands.generate(api, g, input, [source], save, wait, maxCredits(v));
187
+ }
188
+ case 'compare': {
189
+ compareOptions(v);
190
+ const prompt = rest.join(' ').trim();
191
+ if (!prompt) {
192
+ throw usageError('Give a prompt: `makemidas compare "a fox" --models a,b`.');
193
+ }
194
+ const quoted = intOption(v['quoted-credits'], 'quoted-credits', 0, 1_000_000);
195
+ return commands.compare(api, g, {
196
+ prompt,
197
+ models: compareModels(v.models),
198
+ ...(v.aspect ? { aspectRatio: v.aspect } : {}),
199
+ ...(quoted !== undefined ? { quotedCredits: quoted } : {}),
200
+ }, v.ref, save, maxCredits(v));
201
+ }
202
+ case 'delete':
203
+ if (rest.length > 1)
204
+ throw usageError('Delete one generation at a time.');
205
+ return commands.deleteGeneration(api, g, rest[0], {
206
+ yes: v.yes,
207
+ interactive: Boolean(process.stdin.isTTY),
208
+ });
209
+ case 'feedback':
210
+ return commands.feedback(api, g, {
211
+ kind: feedbackKind(v.kind),
212
+ message: rest.join(' '),
213
+ ...(v.generation ? { generationId: v.generation } : {}),
214
+ });
90
215
  case 'get':
91
216
  return commands.get(api, g, rest[0], save, { wait: v.wait, timeoutMin });
92
217
  case 'list':
@@ -94,12 +219,55 @@ async function main(argv) {
94
219
  limit: intOption(v.limit, 'limit', 1, 50) ?? 20,
95
220
  before: v.before,
96
221
  });
97
- case 'credits':
98
- return commands.credits(api, g);
222
+ case 'credits': {
223
+ const [sub] = rest;
224
+ if (!sub)
225
+ return commands.credits(api, g);
226
+ if (sub === 'buy' || sub === 'link')
227
+ return commands.creditsLink(api, g);
228
+ throw usageError('Use `credits` or `credits buy`.');
229
+ }
230
+ case 'estimate': {
231
+ const [kind, ...args] = rest;
232
+ switch (kind) {
233
+ case 'image':
234
+ case 'video':
235
+ return commands.estimate(api, g, generationInput(kind, args.join(' '), v), v.ref);
236
+ case 'music':
237
+ case 'sfx':
238
+ case 'speech':
239
+ case 'voiceover':
240
+ return commands.estimate(api, g, audioInput(audioTask(kind), args.join(' '), v), [], kind);
241
+ case 'transcribe':
242
+ case 'transcription': {
243
+ const source = sourceArg(args, 'estimate transcribe', 'audio or video file');
244
+ return commands.estimate(api, g, transcriptionInput(v).input, [], 'transcribe', {
245
+ kind: 'audio',
246
+ source,
247
+ });
248
+ }
249
+ case 'remove-bg':
250
+ case 'upscale':
251
+ case 'upscale-video': {
252
+ const task = editTask(kind);
253
+ const source = sourceArg(args, `estimate ${kind}`, task === 'upscale-video' ? 'video' : 'image');
254
+ const input = editInput(task, v);
255
+ return task === 'upscale-video'
256
+ ? commands.estimate(api, g, input, [], kind, { kind: 'video', source })
257
+ : commands.estimate(api, g, input, [source], kind);
258
+ }
259
+ default:
260
+ throw usageError('Use `estimate <command> …` with image, video, music, sfx, speech, transcribe, remove-bg, upscale or upscale-video.');
261
+ }
262
+ }
99
263
  case 'models': {
100
- const kind = v.kind;
101
- if (kind && kind !== 'image' && kind !== 'video') {
102
- throw usageError('--kind must be image or video.');
264
+ const [arg] = rest;
265
+ if (arg && !isKind(arg)) {
266
+ return commands.modelDetails(api, g, arg);
267
+ }
268
+ const kind = v.kind ?? arg;
269
+ if (kind && !isKind(kind)) {
270
+ throw usageError(`--kind must be ${KINDS.join(', ')}.`);
103
271
  }
104
272
  return commands.models(api, g, kind);
105
273
  }
@@ -111,11 +279,6 @@ main(process.argv.slice(2)).then(() => process.exit(EXIT.OK), (error) => {
111
279
  const cli = error instanceof CliError
112
280
  ? error
113
281
  : 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
- }
282
+ process.stderr.write(`${formatError(cli, process.argv.includes('--json'))}\n`);
120
283
  process.exit(cli.exitCode);
121
284
  });