@flatkey-ai/cli 0.1.12 → 0.1.14
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/package.json +1 -1
- package/src/api.js +6 -2
- package/src/cli.js +103 -1
- package/src/config.js +1 -1
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -295,11 +295,15 @@ function extractErrorMessage(body, status) {
|
|
|
295
295
|
: typeof body?.message === "string"
|
|
296
296
|
? body.message
|
|
297
297
|
: undefined;
|
|
298
|
-
if (message
|
|
298
|
+
if (isAuthTokenError(message)) return missingApiKeyMessage();
|
|
299
299
|
if (message) return message;
|
|
300
300
|
return `Flatkey API request failed with HTTP ${status}`;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
function isAuthTokenError(message) {
|
|
304
|
+
return message === "Token not provided" || /^Invalid token\b/i.test(message ?? "");
|
|
305
|
+
}
|
|
306
|
+
|
|
303
307
|
function missingApiKeyMessage() {
|
|
304
|
-
return "Missing Flatkey API key.
|
|
308
|
+
return "Missing or invalid Flatkey API key. Run `flatkey login`, or create a key at https://console.flatkey.ai/keys and run `flatkey onboard --api-key <key>`.";
|
|
305
309
|
}
|
package/src/cli.js
CHANGED
|
@@ -576,7 +576,109 @@ async function handleModels(command, deps) {
|
|
|
576
576
|
|
|
577
577
|
function formatHuman(result) {
|
|
578
578
|
if (typeof result === "string") return result;
|
|
579
|
-
|
|
579
|
+
if (!result || typeof result !== "object") return String(result);
|
|
580
|
+
if (result.dryRun && result.request) return formatDryRun(result);
|
|
581
|
+
if (result.kind) return formatGenerationResult(result);
|
|
582
|
+
if (Array.isArray(result.models)) return formatModels(result.models);
|
|
583
|
+
if (Array.isArray(result.voices)) return formatVoices(result.voices);
|
|
584
|
+
if (typeof result.authenticated === "boolean") return formatAuthStatus(result);
|
|
585
|
+
return formatKeyValues(result);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function formatDryRun(result) {
|
|
589
|
+
const lines = [
|
|
590
|
+
`Dry run: ${result.kind}`,
|
|
591
|
+
`${result.request.method ?? "GET"} ${result.request.url}`,
|
|
592
|
+
];
|
|
593
|
+
if (result.request.body !== undefined) {
|
|
594
|
+
lines.push("Body:");
|
|
595
|
+
lines.push(JSON.stringify(result.request.body, null, 2));
|
|
596
|
+
}
|
|
597
|
+
return lines.join("\n");
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function formatGenerationResult(result) {
|
|
601
|
+
if (result.kind === "text") {
|
|
602
|
+
const lines = [result.text || "(empty text)"];
|
|
603
|
+
if (result.output) lines.push(`Saved: ${result.output}`);
|
|
604
|
+
return lines.join("\n");
|
|
605
|
+
}
|
|
606
|
+
const artifacts = Array.isArray(result.artifacts) ? result.artifacts : [];
|
|
607
|
+
if (artifacts.length === 0) return `${titleCase(result.kind)} generated. No artifacts returned.`;
|
|
608
|
+
const lines = [`${titleCase(result.kind)} generated:`];
|
|
609
|
+
for (const artifact of artifacts) {
|
|
610
|
+
if (artifact.path) lines.push(`- Saved: ${artifact.path}`);
|
|
611
|
+
else if (artifact.url) lines.push(`- URL: ${artifact.url}`);
|
|
612
|
+
else lines.push(`- ${JSON.stringify(artifact)}`);
|
|
613
|
+
}
|
|
614
|
+
return lines.join("\n");
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function formatModels(models) {
|
|
618
|
+
if (models.length === 0) return "No models available.";
|
|
619
|
+
return [
|
|
620
|
+
`Available models (${models.length}):`,
|
|
621
|
+
formatTable(
|
|
622
|
+
["Model", "Type", "Source"],
|
|
623
|
+
models.map((model) => [
|
|
624
|
+
model.id,
|
|
625
|
+
model.type ?? "",
|
|
626
|
+
model.source ?? "",
|
|
627
|
+
]),
|
|
628
|
+
),
|
|
629
|
+
].join("\n");
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function formatVoices(voices) {
|
|
633
|
+
if (voices.length === 0) return "No voices available.";
|
|
634
|
+
const lines = [`Available voices (${voices.length}):`];
|
|
635
|
+
for (const voice of voices) {
|
|
636
|
+
const id = voice.voice_id ?? voice.id;
|
|
637
|
+
const name = voice.name ? `${voice.name} ` : "";
|
|
638
|
+
lines.push(`- ${name}${id ? `(${id})` : ""}`.trim());
|
|
639
|
+
}
|
|
640
|
+
return lines.join("\n");
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function formatKeyValues(result) {
|
|
644
|
+
const entries = Object.entries(result);
|
|
645
|
+
if (entries.length === 0) return "OK";
|
|
646
|
+
return entries
|
|
647
|
+
.map(([key, value]) => `${humanLabel(key)}: ${formatScalar(value)}`)
|
|
648
|
+
.join("\n");
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function formatScalar(value) {
|
|
652
|
+
if (value === null || value === undefined) return "";
|
|
653
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
654
|
+
return String(value);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function humanLabel(key) {
|
|
658
|
+
return key
|
|
659
|
+
.replaceAll("_", " ")
|
|
660
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
661
|
+
.replace(/^./, (char) => char.toUpperCase());
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
function titleCase(value) {
|
|
665
|
+
return String(value).replace(/^./, (char) => char.toUpperCase());
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function formatTable(headers, rows) {
|
|
669
|
+
const widths = headers.map((header, index) => Math.max(
|
|
670
|
+
header.length,
|
|
671
|
+
...rows.map((row) => String(row[index] ?? "").length),
|
|
672
|
+
));
|
|
673
|
+
const line = (cells) => cells
|
|
674
|
+
.map((cell, index) => String(cell ?? "").padEnd(widths[index]))
|
|
675
|
+
.join(" ")
|
|
676
|
+
.trimEnd();
|
|
677
|
+
return [
|
|
678
|
+
line(headers),
|
|
679
|
+
line(widths.map((width) => "-".repeat(width))),
|
|
680
|
+
...rows.map(line),
|
|
681
|
+
].join("\n");
|
|
580
682
|
}
|
|
581
683
|
|
|
582
684
|
async function readPackageVersion() {
|
package/src/config.js
CHANGED
|
@@ -26,7 +26,7 @@ export async function resolveApiKey({
|
|
|
26
26
|
if (env.FLATKEY_API_KEY) return env.FLATKEY_API_KEY;
|
|
27
27
|
|
|
28
28
|
throw new Error(
|
|
29
|
-
"Missing Flatkey API key.
|
|
29
|
+
"Missing or invalid Flatkey API key. Run `flatkey login`, or create a key at https://console.flatkey.ai/keys and run `flatkey onboard --api-key <key>`.",
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
|