@flatkey-ai/cli 0.2.1 → 0.2.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatkey-ai/cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Flatkey media generation CLI for image, video, audio, credits, status, and models.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { withCliRequestHeaders } from "./requestHeaders.js";
2
+
1
3
  export const DEFAULT_BASE_URL = "https://router.flatkey.ai";
2
4
  export const DEFAULT_MODELS_BASE_URL = "https://console.flatkey.ai";
3
5
  export const DEFAULT_CONSOLE_URL = "https://console.flatkey.ai";
@@ -231,7 +233,7 @@ function planRequest(options, path, init = {}) {
231
233
  return {
232
234
  url: buildUrl(options.baseUrl, path),
233
235
  method: init.method ?? "GET",
234
- headers: init.headers ?? authHeaders(options.apiKey),
236
+ headers: withCliRequestHeaders(init.headers ?? authHeaders(options.apiKey)),
235
237
  body: init.body,
236
238
  };
237
239
  }
package/src/artifacts.js CHANGED
@@ -2,6 +2,8 @@ import { mkdir, writeFile } from "node:fs/promises";
2
2
  import { homedir } from "node:os";
3
3
  import { dirname, extname, join } from "node:path";
4
4
 
5
+ import { CLI_REQUEST_HEADERS } from "./requestHeaders.js";
6
+
5
7
  const DEFAULT_EXTENSIONS = {
6
8
  audio: "mp3",
7
9
  image: "png",
@@ -80,7 +82,7 @@ async function persistItem({ kind, item, outDir, output, index, fetchImpl }) {
80
82
  }
81
83
 
82
84
  async function downloadArtifact({ url, path, fetchImpl }) {
83
- const response = await fetchImpl(url);
85
+ const response = await fetchImpl(url, { headers: CLI_REQUEST_HEADERS });
84
86
  if (!response.ok) {
85
87
  throw new Error(`Failed to download artifact ${url}: HTTP ${response.status}`);
86
88
  }
@@ -99,6 +101,8 @@ function extractItems(response) {
99
101
  if (typeof response?.metadata?.url === "string") return [{ url: response.metadata.url }];
100
102
  if (typeof response?.url === "string") return [response];
101
103
  if (typeof response?.video_url?.url === "string") return [{ url: response.video_url.url }];
104
+ if (typeof response?.video?.url === "string") return [{ url: response.video.url }];
105
+ if (typeof response?.video?.temp_url === "string") return [{ url: response.video.temp_url }];
102
106
  return [];
103
107
  }
104
108
 
package/src/cli.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { join } from "node:path";
2
+
1
3
  const COMMANDS = new Set([
2
4
  "audio",
3
5
  "credits",
@@ -548,11 +550,14 @@ async function handleGenerate(command, deps) {
548
550
  const output = await writeTextOutput(text, command.options.output);
549
551
  return { kind: command.group, text, output, response };
550
552
  }
553
+ const outDir = command.options.out ?? "flatkey-output";
554
+ const output = command.options.output
555
+ ?? (command.group === "video" ? join(outDir, "video-01.mp4") : undefined);
551
556
  const artifacts = await persistArtifacts({
552
557
  kind: command.group,
553
558
  response: artifactResponse,
554
- outDir: command.options.out ?? "flatkey-output",
555
- output: command.options.output,
559
+ outDir,
560
+ output,
556
561
  fetch: deps.fetch,
557
562
  });
558
563
  return { kind: command.group, artifacts, response: scrubArtifactResponse(artifactResponse) };
@@ -649,6 +654,8 @@ function hasArtifact(response) {
649
654
  || response?.url
650
655
  || response?.temp_url
651
656
  || response?.video_url?.url
657
+ || response?.video?.url
658
+ || response?.video?.temp_url
652
659
  || response?.data?.some?.((item) => item?.url || item?.temp_url || item?.b64_json || item?.base64 || item?.data)
653
660
  || response?.artifacts?.some?.((item) => item?.url || item?.temp_url || item?.path)
654
661
  || response?.content?.some?.((item) => item?.url || item?.video_url?.url || item?.data_url || item?.b64_json || item?.base64 || item?.data),
@@ -660,7 +667,7 @@ function videoTaskId(response) {
660
667
  }
661
668
 
662
669
  function isVideoDone(response) {
663
- return ["completed", "succeeded", "success"].includes(String(response?.status ?? "").toLowerCase());
670
+ return ["completed", "done", "succeeded", "success"].includes(String(response?.status ?? "").toLowerCase());
664
671
  }
665
672
 
666
673
  function isVideoFailed(response) {
@@ -1051,9 +1058,11 @@ async function maybeWriteUpdateNotice(command, deps = {}) {
1051
1058
  }
1052
1059
 
1053
1060
  async function fetchLatestPackageVersion(deps = {}) {
1061
+ const { CLI_REQUEST_HEADERS } = await import("./requestHeaders.js");
1054
1062
  const fetchImpl = deps.fetch ?? globalThis.fetch;
1055
1063
  if (typeof fetchImpl !== "function") return undefined;
1056
1064
  const response = await fetchImpl("https://registry.npmjs.org/@flatkey-ai%2fcli/latest", {
1065
+ headers: CLI_REQUEST_HEADERS,
1057
1066
  signal: typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function"
1058
1067
  ? AbortSignal.timeout(750)
1059
1068
  : undefined,
@@ -0,0 +1,10 @@
1
+ export const CLI_REQUEST_HEADERS = {
2
+ "x-flatkey-client": "cli",
3
+ };
4
+
5
+ export function withCliRequestHeaders(headers = {}) {
6
+ return {
7
+ ...headers,
8
+ ...CLI_REQUEST_HEADERS,
9
+ };
10
+ }