@flatkey-ai/cli 0.1.7 → 0.1.9

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +48 -11
  3. package/src/help.js +6 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatkey-ai/cli",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Flatkey media generation CLI for image, video, audio, credits, status, and models.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -15,6 +15,28 @@ const COMMANDS = new Set([
15
15
  ]);
16
16
 
17
17
  const GROUP_ACTIONS = new Set(["audio", "auth", "image", "text", "video"]);
18
+ const GLOBAL_OPTIONS = new Set(["api_key", "base_url", "dry_run", "help", "json", "output", "out"]);
19
+ const COMMAND_OPTIONS = {
20
+ "audio generate": new Set(["model", "prompt", "similarity_boost", "stability", "style", "voice_id"]),
21
+ "audio music": new Set(["music_length_ms", "prompt"]),
22
+ "audio sfx": new Set(["duration", "prompt"]),
23
+ "audio voices": new Set([]),
24
+ "auth status": new Set([]),
25
+ credits: new Set([]),
26
+ help: new Set(["ai", "command"]),
27
+ image: new Set([]),
28
+ "image generate": new Set(["model", "n", "prompt", "quality", "size"]),
29
+ login: new Set(["console_url", "no_open", "open"]),
30
+ logout: new Set([]),
31
+ models: new Set(["type"]),
32
+ onboard: new Set(["api_key"]),
33
+ status: new Set([]),
34
+ text: new Set([]),
35
+ "text generate": new Set(["model", "prompt"]),
36
+ version: new Set([]),
37
+ video: new Set([]),
38
+ "video generate": new Set(["aspect", "duration", "fps", "model", "prompt", "ratio", "resolution"]),
39
+ };
18
40
 
19
41
  export function parseArgv(argv) {
20
42
  const [group, maybeAction, ...rest] = argv;
@@ -31,11 +53,11 @@ export function parseArgv(argv) {
31
53
  throw new Error(`Unknown command: ${group}`);
32
54
  }
33
55
  if (group === "help" && maybeAction && !maybeAction.startsWith("--")) {
34
- return {
56
+ return validateCommandOptions({
35
57
  group: "help",
36
58
  action: undefined,
37
59
  options: { command: maybeAction, ...parseOptions(rest) },
38
- };
60
+ });
39
61
  }
40
62
 
41
63
  const hasAction = GROUP_ACTIONS.has(group);
@@ -50,21 +72,21 @@ export function parseArgv(argv) {
50
72
  const hasHelpOption = optionTokens.some((token) => token === "--help" || token === "-h")
51
73
  || (optionTokens.length === 1 && optionTokens[0] === "help");
52
74
  if (hasHelpOption) {
53
- return {
75
+ return validateCommandOptions({
54
76
  group,
55
77
  action,
56
78
  options: {
57
79
  ...parseOptions(optionTokens.filter((token) => token !== "help" && token !== "--help" && token !== "-h")),
58
80
  help: true,
59
81
  },
60
- };
82
+ });
61
83
  }
62
84
 
63
- return {
85
+ return validateCommandOptions({
64
86
  group,
65
87
  action,
66
88
  options: parseOptions(optionTokens),
67
- };
89
+ });
68
90
  }
69
91
 
70
92
  function isHelpToken(token) {
@@ -99,6 +121,20 @@ function parseOptions(tokens) {
99
121
  return options;
100
122
  }
101
123
 
124
+ function validateCommandOptions(command) {
125
+ const key = command.action ? `${command.group} ${command.action}` : command.group;
126
+ const allowed = COMMAND_OPTIONS[key] ?? new Set();
127
+ for (const option of Object.keys(command.options)) {
128
+ if (GLOBAL_OPTIONS.has(option) || allowed.has(option)) continue;
129
+ const flag = `--${option.replaceAll("_", "-")}`;
130
+ const helpCommand = command.action
131
+ ? `flatkey ${command.group} ${command.action} --help`
132
+ : `flatkey ${command.group} --help`;
133
+ throw new Error(`Unknown option ${flag} for flatkey ${key}. Run \`${helpCommand}\` to see supported options.`);
134
+ }
135
+ return command;
136
+ }
137
+
102
138
  export async function main(argv) {
103
139
  const command = parseArgv(argv);
104
140
  if (command.options.help) {
@@ -183,7 +219,8 @@ async function handleLogin(command, deps) {
183
219
  const { createDeviceAuthorization, pollDeviceAuthorization } = await import("./api.js");
184
220
  const deviceId = await ensureDeviceId({ configDir: deps.configDir });
185
221
  const version = await readPackageVersion();
186
- const consoleUrl = command.options.console_url;
222
+ const env = deps.env ?? process.env;
223
+ const consoleUrl = command.options.console_url ?? env.CONSOLE_ORIGIN;
187
224
  const authorization = await createDeviceAuthorization({
188
225
  consoleUrl,
189
226
  deviceId,
@@ -349,7 +386,7 @@ async function handleGenerate(command, deps) {
349
386
  const options = {
350
387
  ...command.options,
351
388
  apiKey,
352
- baseUrl: command.options.base_url,
389
+ baseUrl: command.options.base_url ?? (deps.env ?? process.env).ROUTER_ORIGIN,
353
390
  fetch: deps.fetch,
354
391
  };
355
392
  if (command.options.dry_run) {
@@ -431,7 +468,7 @@ async function handleVoices(command, deps) {
431
468
  });
432
469
  return getVoices({
433
470
  apiKey,
434
- baseUrl: command.options.base_url,
471
+ baseUrl: command.options.base_url ?? (deps.env ?? process.env).ROUTER_ORIGIN,
435
472
  fetch: deps.fetch,
436
473
  });
437
474
  }
@@ -483,7 +520,7 @@ async function handleUtility(command, deps) {
483
520
  });
484
521
  const options = {
485
522
  apiKey,
486
- baseUrl: command.options.base_url,
523
+ baseUrl: command.options.base_url ?? (deps.env ?? process.env).CONSOLE_ORIGIN,
487
524
  fetch: deps.fetch,
488
525
  };
489
526
  return command.group === "credits" ? getCredits(options) : getStatus(options);
@@ -501,7 +538,7 @@ async function handleModels(command, deps) {
501
538
  });
502
539
  const response = await getModels({
503
540
  apiKey,
504
- baseUrl: command.options.base_url,
541
+ baseUrl: command.options.base_url ?? (deps.env ?? process.env).CONSOLE_ORIGIN,
505
542
  fetch: deps.fetch,
506
543
  });
507
544
  const models = normalizeModels(response, command.options.type);
package/src/help.js CHANGED
@@ -31,6 +31,8 @@ Commands:
31
31
 
32
32
  Environment:
33
33
  - FLATKEY_API_KEY: Flatkey API key.
34
+ - ROUTER_ORIGIN: Override generation router origin, e.g. staging router.
35
+ - CONSOLE_ORIGIN: Override console API origin, e.g. staging console.
34
36
  - Default router: https://router.flatkey.ai
35
37
 
36
38
  Recovery:
@@ -65,6 +67,10 @@ Global options:
65
67
  --json Print machine-readable JSON
66
68
  --output, -o <file> Write generated output to a local file
67
69
  --base-url <url> Override Flatkey router URL
70
+
71
+ Environment:
72
+ ROUTER_ORIGIN Override generation router origin
73
+ CONSOLE_ORIGIN Override console API origin
68
74
  --console-url <url> Override Flatkey console URL for login
69
75
 
70
76
  Video options: