@flatkey-ai/cli 0.2.2 → 0.2.4
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/artifacts.js +2 -0
- package/src/cli.js +24 -4
package/package.json
CHANGED
package/src/artifacts.js
CHANGED
|
@@ -101,6 +101,8 @@ function extractItems(response) {
|
|
|
101
101
|
if (typeof response?.metadata?.url === "string") return [{ url: response.metadata.url }];
|
|
102
102
|
if (typeof response?.url === "string") return [response];
|
|
103
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 }];
|
|
104
106
|
return [];
|
|
105
107
|
}
|
|
106
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
|
|
555
|
-
output
|
|
559
|
+
outDir,
|
|
560
|
+
output,
|
|
556
561
|
fetch: deps.fetch,
|
|
557
562
|
});
|
|
558
563
|
return { kind: command.group, artifacts, response: scrubArtifactResponse(artifactResponse) };
|
|
@@ -631,7 +636,8 @@ async function waitForVideoResult(response, options) {
|
|
|
631
636
|
|
|
632
637
|
while (Date.now() <= deadline) {
|
|
633
638
|
last = await options.getVideo(options, taskId);
|
|
634
|
-
if (hasArtifact(last)
|
|
639
|
+
if (hasArtifact(last)) return last;
|
|
640
|
+
if (isVideoDone(last)) return withVideoContentFallback(last, options, taskId);
|
|
635
641
|
if (isVideoFailed(last)) {
|
|
636
642
|
const message = last?.error?.message ?? last?.message ?? `Video generation failed: ${taskId}`;
|
|
637
643
|
throw new Error(message);
|
|
@@ -642,6 +648,18 @@ async function waitForVideoResult(response, options) {
|
|
|
642
648
|
throw new Error(`Video task still processing after ${Math.round(timeoutMs / 1000)}s: ${taskId}`);
|
|
643
649
|
}
|
|
644
650
|
|
|
651
|
+
function withVideoContentFallback(response, options, taskId) {
|
|
652
|
+
const baseUrl = String(options.baseUrl ?? "").replace(/\/$/, "");
|
|
653
|
+
if (!baseUrl || !taskId) return response;
|
|
654
|
+
return {
|
|
655
|
+
...response,
|
|
656
|
+
metadata: {
|
|
657
|
+
...(response.metadata ?? {}),
|
|
658
|
+
url: `${baseUrl}/v1/videos/${encodeURIComponent(taskId)}/content`,
|
|
659
|
+
},
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
|
|
645
663
|
function hasArtifact(response) {
|
|
646
664
|
return Boolean(
|
|
647
665
|
response?.metadata?.url
|
|
@@ -649,6 +667,8 @@ function hasArtifact(response) {
|
|
|
649
667
|
|| response?.url
|
|
650
668
|
|| response?.temp_url
|
|
651
669
|
|| response?.video_url?.url
|
|
670
|
+
|| response?.video?.url
|
|
671
|
+
|| response?.video?.temp_url
|
|
652
672
|
|| response?.data?.some?.((item) => item?.url || item?.temp_url || item?.b64_json || item?.base64 || item?.data)
|
|
653
673
|
|| response?.artifacts?.some?.((item) => item?.url || item?.temp_url || item?.path)
|
|
654
674
|
|| response?.content?.some?.((item) => item?.url || item?.video_url?.url || item?.data_url || item?.b64_json || item?.base64 || item?.data),
|
|
@@ -660,7 +680,7 @@ function videoTaskId(response) {
|
|
|
660
680
|
}
|
|
661
681
|
|
|
662
682
|
function isVideoDone(response) {
|
|
663
|
-
return ["completed", "succeeded", "success"].includes(String(response?.status ?? "").toLowerCase());
|
|
683
|
+
return ["completed", "done", "succeeded", "success"].includes(String(response?.status ?? "").toLowerCase());
|
|
664
684
|
}
|
|
665
685
|
|
|
666
686
|
function isVideoFailed(response) {
|