vibedgames 0.0.3 → 0.0.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/README.md +7 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/commands/completions.d.ts +7 -0
- package/dist/commands/completions.js +138 -0
- package/dist/commands/deploy.d.ts +9 -9
- package/dist/commands/deploy.js +6 -0
- package/dist/commands/init.d.ts +15 -15
- package/dist/commands/login.js +2 -2
- package/dist/commands/media.d.ts +1 -0
- package/dist/commands/media.js +401 -0
- package/dist/commands/new.d.ts +26 -0
- package/dist/commands/new.js +229 -0
- package/dist/index.js +6 -0
- package/dist/lib/api.js +14 -7
- package/dist/lib/config-file.js +18 -3
- package/dist/lib/config.js +5 -4
- package/dist/lib/media-args.d.ts +28 -0
- package/dist/lib/media-args.js +199 -0
- package/dist/lib/media-download.d.ts +31 -0
- package/dist/lib/media-download.js +190 -0
- package/dist/lib/media-poll.d.ts +17 -0
- package/dist/lib/media-poll.js +80 -0
- package/dist/lib/media-upload.d.ts +12 -0
- package/dist/lib/media-upload.js +51 -0
- package/dist/lib/types.d.ts +2 -0
- package/dist/lib/types.js +4 -0
- package/package.json +11 -9
- package/dist/commands/list.d.ts +0 -1
- package/dist/commands/list.js +0 -23
- package/dist/commands/rm.d.ts +0 -12
- package/dist/commands/rm.js +0 -35
- package/dist/commands/skills.d.ts +0 -8
- package/dist/commands/skills.js +0 -53
- package/dist/prompt-E6QYABXJ.js +0 -754
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
const SUPPORTED = new Set(["bash", "zsh", "fish"]);
|
|
3
|
+
const SUBCOMMANDS = [
|
|
4
|
+
"init",
|
|
5
|
+
"login",
|
|
6
|
+
"logout",
|
|
7
|
+
"deploy",
|
|
8
|
+
"media",
|
|
9
|
+
"completions",
|
|
10
|
+
"whoami",
|
|
11
|
+
];
|
|
12
|
+
const MEDIA_SUBCOMMANDS = ["run", "status", "models", "schema", "pricing", "docs", "upload"];
|
|
13
|
+
const COMMON_FLAGS = ["--help", "--version"];
|
|
14
|
+
// CLI-level flags across the media subcommands. Model parameters are
|
|
15
|
+
// arbitrary per fal endpoint and passed as `--<param>`, so they can't be
|
|
16
|
+
// enumerated here — these are just the stable, command-defined flags.
|
|
17
|
+
const MEDIA_FLAGS = [
|
|
18
|
+
"--async",
|
|
19
|
+
"--download",
|
|
20
|
+
"--result",
|
|
21
|
+
"--cancel",
|
|
22
|
+
"--logs",
|
|
23
|
+
"--category",
|
|
24
|
+
"--status",
|
|
25
|
+
"--limit",
|
|
26
|
+
"--cursor",
|
|
27
|
+
"--endpoint_id",
|
|
28
|
+
"--expand",
|
|
29
|
+
"--format",
|
|
30
|
+
"--json",
|
|
31
|
+
"--quiet",
|
|
32
|
+
];
|
|
33
|
+
function bashScript() {
|
|
34
|
+
return `# vg completions for bash. Source this file or write it to a file in your
|
|
35
|
+
# bash completion directory (e.g. /etc/bash_completion.d/vg).
|
|
36
|
+
_vg_completions() {
|
|
37
|
+
local cur prev cmd subcmd
|
|
38
|
+
COMPREPLY=()
|
|
39
|
+
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
40
|
+
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
41
|
+
cmd="\${COMP_WORDS[1]}"
|
|
42
|
+
subcmd="\${COMP_WORDS[2]}"
|
|
43
|
+
|
|
44
|
+
if [[ $COMP_CWORD -eq 1 ]]; then
|
|
45
|
+
COMPREPLY=( $(compgen -W "${SUBCOMMANDS.join(" ")} ${COMMON_FLAGS.join(" ")}" -- "$cur") )
|
|
46
|
+
return
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
case "$cmd" in
|
|
50
|
+
media)
|
|
51
|
+
if [[ $COMP_CWORD -eq 2 ]]; then
|
|
52
|
+
COMPREPLY=( $(compgen -W "${MEDIA_SUBCOMMANDS.join(" ")} ${MEDIA_FLAGS.join(" ")} ${COMMON_FLAGS.join(" ")}" -- "$cur") )
|
|
53
|
+
return
|
|
54
|
+
fi
|
|
55
|
+
COMPREPLY=( $(compgen -W "${MEDIA_FLAGS.join(" ")} ${COMMON_FLAGS.join(" ")}" -- "$cur") )
|
|
56
|
+
return
|
|
57
|
+
;;
|
|
58
|
+
*)
|
|
59
|
+
COMPREPLY=( $(compgen -W "${COMMON_FLAGS.join(" ")}" -- "$cur") )
|
|
60
|
+
return
|
|
61
|
+
;;
|
|
62
|
+
esac
|
|
63
|
+
}
|
|
64
|
+
complete -F _vg_completions vg
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
function zshScript() {
|
|
68
|
+
return `# vg completions for zsh. Source this file or place it on your fpath.
|
|
69
|
+
_vg() {
|
|
70
|
+
local -a subcmds media_subs media_flags common_flags
|
|
71
|
+
subcmds=(${SUBCOMMANDS.map((s) => `"${s}"`).join(" ")})
|
|
72
|
+
media_subs=(${MEDIA_SUBCOMMANDS.map((s) => `"${s}"`).join(" ")})
|
|
73
|
+
media_flags=(${MEDIA_FLAGS.map((s) => `"${s}"`).join(" ")})
|
|
74
|
+
common_flags=(${COMMON_FLAGS.map((s) => `"${s}"`).join(" ")})
|
|
75
|
+
|
|
76
|
+
if (( CURRENT == 2 )); then
|
|
77
|
+
_values "vg subcommand" "\${subcmds[@]}" "\${common_flags[@]}"
|
|
78
|
+
return
|
|
79
|
+
fi
|
|
80
|
+
case "\${words[2]}" in
|
|
81
|
+
media)
|
|
82
|
+
if (( CURRENT == 3 )); then
|
|
83
|
+
_values "vg media subcommand" "\${media_subs[@]}" "\${media_flags[@]}" "\${common_flags[@]}"
|
|
84
|
+
return
|
|
85
|
+
fi
|
|
86
|
+
_values "vg media flag" "\${media_flags[@]}" "\${common_flags[@]}"
|
|
87
|
+
;;
|
|
88
|
+
*)
|
|
89
|
+
_values "vg flag" "\${common_flags[@]}"
|
|
90
|
+
;;
|
|
91
|
+
esac
|
|
92
|
+
}
|
|
93
|
+
compdef _vg vg
|
|
94
|
+
`;
|
|
95
|
+
}
|
|
96
|
+
function fishFlag(flag, condition) {
|
|
97
|
+
const isShort = flag.startsWith("-") && !flag.startsWith("--");
|
|
98
|
+
const name = flag.replace(/^--?/, "");
|
|
99
|
+
const opt = isShort ? "-s" : "-l";
|
|
100
|
+
return `complete -c vg -n '${condition}' ${opt} '${name}'`;
|
|
101
|
+
}
|
|
102
|
+
function fishScript() {
|
|
103
|
+
const mediaFlagLines = [...MEDIA_FLAGS, ...COMMON_FLAGS].map((flag) => fishFlag(flag, "__fish_seen_subcommand_from media"));
|
|
104
|
+
// For all other subcommands, only the common flags are meaningful.
|
|
105
|
+
const otherSubcommands = SUBCOMMANDS.filter((s) => s !== "media");
|
|
106
|
+
const otherFlagLines = COMMON_FLAGS.flatMap((flag) => otherSubcommands.map((sub) => fishFlag(flag, `__fish_seen_subcommand_from ${sub}`)));
|
|
107
|
+
const topLevelFlagLines = COMMON_FLAGS.map((flag) => fishFlag(flag, "__fish_use_subcommand"));
|
|
108
|
+
return `# vg completions for fish.
|
|
109
|
+
complete -c vg -f
|
|
110
|
+
complete -c vg -n '__fish_use_subcommand' -a '${SUBCOMMANDS.join(" ")}'
|
|
111
|
+
${topLevelFlagLines.join("\n")}
|
|
112
|
+
${MEDIA_SUBCOMMANDS.map((sub) => `complete -c vg -n '__fish_seen_subcommand_from media' -a '${sub}'`).join("\n")}
|
|
113
|
+
${mediaFlagLines.join("\n")}
|
|
114
|
+
${otherFlagLines.join("\n")}
|
|
115
|
+
`;
|
|
116
|
+
}
|
|
117
|
+
export const completionsCommand = defineCommand({
|
|
118
|
+
meta: {
|
|
119
|
+
name: "completions",
|
|
120
|
+
description: "Print shell completions for vg. Pipe into your shell's completion dir.",
|
|
121
|
+
},
|
|
122
|
+
args: {
|
|
123
|
+
shell: {
|
|
124
|
+
type: "positional",
|
|
125
|
+
description: "Shell to generate completions for: bash | zsh | fish",
|
|
126
|
+
required: true,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
run: ({ args }) => {
|
|
130
|
+
const shell = String(args.shell ?? "");
|
|
131
|
+
if (!SUPPORTED.has(shell)) {
|
|
132
|
+
process.stderr.write(`Unsupported shell "${shell}". Expected: ${Array.from(SUPPORTED).join(", ")}\n`);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
const script = shell === "bash" ? bashScript() : shell === "zsh" ? zshScript() : fishScript();
|
|
136
|
+
process.stdout.write(script);
|
|
137
|
+
},
|
|
138
|
+
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export declare const deployCommand: import("citty").CommandDef<{
|
|
2
|
-
dir: {
|
|
3
|
-
type: "positional";
|
|
4
|
-
description:
|
|
5
|
-
required: false;
|
|
6
|
-
default:
|
|
2
|
+
readonly dir: {
|
|
3
|
+
readonly type: "positional";
|
|
4
|
+
readonly description: "Directory to deploy";
|
|
5
|
+
readonly required: false;
|
|
6
|
+
readonly default: ".";
|
|
7
7
|
};
|
|
8
|
-
slug: {
|
|
9
|
-
type: "string";
|
|
10
|
-
description:
|
|
11
|
-
required: false;
|
|
8
|
+
readonly slug: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
readonly description: "Override the slug (bypasses vibedgames.json)";
|
|
11
|
+
readonly required: false;
|
|
12
12
|
};
|
|
13
13
|
}>;
|
package/dist/commands/deploy.js
CHANGED
|
@@ -44,6 +44,12 @@ export const deployCommand = defineCommand({
|
|
|
44
44
|
config = { slug: args.slug, name: config?.name };
|
|
45
45
|
}
|
|
46
46
|
if (!config) {
|
|
47
|
+
if (!process.stdin.isTTY) {
|
|
48
|
+
consola.error("No slug specified and no vibedgames.json found.\n" +
|
|
49
|
+
" Pass --slug <name> when running without a TTY (e.g. in CI or from a coding agent).\n" +
|
|
50
|
+
" Example: vg deploy ./dist --slug my-game");
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
47
53
|
const slug = await consola.prompt("Slug (e.g. pong):", { type: "text" });
|
|
48
54
|
if (typeof slug !== "string" || !SLUG_RE.test(slug)) {
|
|
49
55
|
consola.error("Invalid slug. Use lowercase letters, digits, hyphens.");
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export declare const initCommand: import("citty").CommandDef<{
|
|
2
|
-
agent: {
|
|
3
|
-
type: "string";
|
|
4
|
-
description:
|
|
5
|
-
alias:
|
|
6
|
-
default:
|
|
2
|
+
readonly agent: {
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly description: "Comma-separated target agents. Default installs for Claude Code, Cursor, and Codex (symlinked from a shared .agents/skills/ dir). Pass '*' for every supported agent.";
|
|
5
|
+
readonly alias: "a";
|
|
6
|
+
readonly default: "claude-code,cursor,codex";
|
|
7
7
|
};
|
|
8
|
-
global: {
|
|
9
|
-
type: "boolean";
|
|
10
|
-
description:
|
|
11
|
-
default: false;
|
|
12
|
-
alias:
|
|
8
|
+
readonly global: {
|
|
9
|
+
readonly type: "boolean";
|
|
10
|
+
readonly description: "Install to user directory instead of project";
|
|
11
|
+
readonly default: false;
|
|
12
|
+
readonly alias: "g";
|
|
13
13
|
};
|
|
14
|
-
yes: {
|
|
15
|
-
type: "boolean";
|
|
16
|
-
description:
|
|
17
|
-
default: true;
|
|
18
|
-
alias:
|
|
14
|
+
readonly yes: {
|
|
15
|
+
readonly type: "boolean";
|
|
16
|
+
readonly description: "Skip confirmation prompts";
|
|
17
|
+
readonly default: true;
|
|
18
|
+
readonly alias: "y";
|
|
19
19
|
};
|
|
20
20
|
}>;
|
package/dist/commands/login.js
CHANGED
|
@@ -24,7 +24,7 @@ export const loginCommand = defineCommand({
|
|
|
24
24
|
run: async () => {
|
|
25
25
|
const baseUrl = getBaseUrl();
|
|
26
26
|
const client = createPublicClient(baseUrl);
|
|
27
|
-
const { code } = await client.
|
|
27
|
+
const { code } = await client.auth.cliInit.mutate();
|
|
28
28
|
consola.box(`Code: ${code}`);
|
|
29
29
|
consola.info("Opening browser to complete authentication...");
|
|
30
30
|
const authUrl = `${baseUrl}/auth/cli?code=${code}`;
|
|
@@ -32,7 +32,7 @@ export const loginCommand = defineCommand({
|
|
|
32
32
|
consola.start("Waiting for confirmation...");
|
|
33
33
|
for (let i = 0; i < MAX_POLLS; i++) {
|
|
34
34
|
await sleep(POLL_INTERVAL_MS);
|
|
35
|
-
const result = await client.
|
|
35
|
+
const result = await client.auth.cliPoll.query({ code });
|
|
36
36
|
if (result.status === "confirmed") {
|
|
37
37
|
saveConfig({ token: result.token, baseUrl });
|
|
38
38
|
consola.success("Logged in successfully");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mediaCommand: import("citty").CommandDef<import("citty").ArgsDef>;
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import consola from "consola";
|
|
3
|
+
import { createClient } from "../lib/api.js";
|
|
4
|
+
import { parseDownloadFlag, parseRunInput, readExplicitLocalFile, } from "../lib/media-args.js";
|
|
5
|
+
import { downloadMedia, extractMediaRefs } from "../lib/media-download.js";
|
|
6
|
+
import { endpointPath, queueAppId, waitForCompletion } from "../lib/media-poll.js";
|
|
7
|
+
import { uploadFile } from "../lib/media-upload.js";
|
|
8
|
+
import { isRecord } from "../lib/types.js";
|
|
9
|
+
// Action-specific fields for the status-command payload. `result` wraps
|
|
10
|
+
// the raw fal payload under `result:` so fal's own keys can't clobber
|
|
11
|
+
// our top-level (action / endpoint_id / request_id). `status` cherry-
|
|
12
|
+
// picks known fields for the same reason.
|
|
13
|
+
function buildActionFields(action, data) {
|
|
14
|
+
if (action === "result")
|
|
15
|
+
return { result: data };
|
|
16
|
+
if (action === "status" && isRecord(data)) {
|
|
17
|
+
return {
|
|
18
|
+
status: typeof data.status === "string" ? data.status : undefined,
|
|
19
|
+
queue_position: typeof data.queue_position === "number" ? data.queue_position : undefined,
|
|
20
|
+
logs: data.logs,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
function isJsonOutput(args) {
|
|
26
|
+
return Boolean(args.json) || process.env.VG_JSON_OUTPUT === "1";
|
|
27
|
+
}
|
|
28
|
+
function writeJson(value) {
|
|
29
|
+
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
30
|
+
}
|
|
31
|
+
function extractMediaUrls(result) {
|
|
32
|
+
return extractMediaRefs(result).map((r) => r.url);
|
|
33
|
+
}
|
|
34
|
+
// ---- run --------------------------------------------------------------------
|
|
35
|
+
const runCommand = defineCommand({
|
|
36
|
+
meta: { name: "run", description: "Run a fal model (waits for result by default)." },
|
|
37
|
+
args: {
|
|
38
|
+
endpoint_id: {
|
|
39
|
+
type: "positional",
|
|
40
|
+
required: true,
|
|
41
|
+
description: "Model endpoint ID, e.g. fal-ai/flux/dev.",
|
|
42
|
+
},
|
|
43
|
+
async: {
|
|
44
|
+
type: "boolean",
|
|
45
|
+
description: "Submit to queue and return request_id without waiting.",
|
|
46
|
+
},
|
|
47
|
+
download: {
|
|
48
|
+
type: "string",
|
|
49
|
+
description: "Download media from result. Optional value is a path or template with {index},{name},{ext},{request_id}.",
|
|
50
|
+
},
|
|
51
|
+
json: { type: "boolean", description: "Print structured JSON to stdout." },
|
|
52
|
+
quiet: { type: "boolean", description: "Suppress progress output during sync runs." },
|
|
53
|
+
},
|
|
54
|
+
run: async ({ args, rawArgs }) => {
|
|
55
|
+
const downloadFlag = parseDownloadFlag(rawArgs);
|
|
56
|
+
// parseRunInput already skips non-`--` tokens, so the positional
|
|
57
|
+
// endpoint_id and any subcommand name in argv are no-ops.
|
|
58
|
+
const finalInput = parseRunInput(rawArgs);
|
|
59
|
+
const client = createClient();
|
|
60
|
+
const submission = await client.media.forward.mutate({
|
|
61
|
+
target: "queue",
|
|
62
|
+
method: "POST",
|
|
63
|
+
path: `/${endpointPath(args.endpoint_id)}`,
|
|
64
|
+
body: finalInput,
|
|
65
|
+
});
|
|
66
|
+
const requestId = isRecord(submission) && typeof submission.request_id === "string"
|
|
67
|
+
? submission.request_id
|
|
68
|
+
: null;
|
|
69
|
+
if (!requestId) {
|
|
70
|
+
throw new Error("fal queue submit did not return a request_id.");
|
|
71
|
+
}
|
|
72
|
+
const endpoint_id = args.endpoint_id;
|
|
73
|
+
if (args.async) {
|
|
74
|
+
const payload = {
|
|
75
|
+
status: "submitted",
|
|
76
|
+
endpoint_id,
|
|
77
|
+
request_id: requestId,
|
|
78
|
+
hint: `Check status: vg media status ${endpoint_id} ${requestId}`,
|
|
79
|
+
};
|
|
80
|
+
if (isJsonOutput(args))
|
|
81
|
+
writeJson(payload);
|
|
82
|
+
else {
|
|
83
|
+
consola.success(`Submitted ${endpoint_id}`);
|
|
84
|
+
consola.log(` request_id: ${requestId}`);
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const completed = await waitForCompletion(client, endpoint_id, requestId, {
|
|
89
|
+
quiet: Boolean(args.quiet) || isJsonOutput(args),
|
|
90
|
+
});
|
|
91
|
+
let downloaded;
|
|
92
|
+
if (downloadFlag.mode === "on") {
|
|
93
|
+
const refs = extractMediaRefs(completed.result);
|
|
94
|
+
downloaded = await downloadMedia({
|
|
95
|
+
refs,
|
|
96
|
+
template: downloadFlag.template,
|
|
97
|
+
requestId: completed.request_id,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const payload = {
|
|
101
|
+
status: "completed",
|
|
102
|
+
endpoint_id,
|
|
103
|
+
request_id: completed.request_id,
|
|
104
|
+
result: completed.result,
|
|
105
|
+
...(downloaded ? { downloaded_files: downloaded.downloaded } : {}),
|
|
106
|
+
...(downloaded && downloaded.failed.length > 0
|
|
107
|
+
? { download_failures: downloaded.failed }
|
|
108
|
+
: {}),
|
|
109
|
+
};
|
|
110
|
+
if (isJsonOutput(args)) {
|
|
111
|
+
writeJson(payload);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
consola.success(`Run completed (${completed.request_id})`);
|
|
115
|
+
if (downloaded) {
|
|
116
|
+
for (const path of downloaded.downloaded)
|
|
117
|
+
consola.log(` ${path}`);
|
|
118
|
+
for (const f of downloaded.failed)
|
|
119
|
+
consola.warn(` failed: ${f.url} (${f.error})`);
|
|
120
|
+
}
|
|
121
|
+
if (!downloaded?.downloaded.length) {
|
|
122
|
+
for (const url of extractMediaUrls(completed.result))
|
|
123
|
+
consola.log(` ${url}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (downloaded && downloaded.failed.length > 0 && downloaded.downloaded.length === 0) {
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
// ---- status -----------------------------------------------------------------
|
|
132
|
+
const statusCommand = defineCommand({
|
|
133
|
+
meta: {
|
|
134
|
+
name: "status",
|
|
135
|
+
description: "Check job status, fetch result, or cancel.",
|
|
136
|
+
},
|
|
137
|
+
args: {
|
|
138
|
+
endpoint_id: { type: "positional", required: true },
|
|
139
|
+
request_id: { type: "positional", required: true },
|
|
140
|
+
result: { type: "boolean", description: "Fetch the completed result." },
|
|
141
|
+
cancel: { type: "boolean", description: "Cancel the job." },
|
|
142
|
+
logs: { type: "boolean", description: "Include logs." },
|
|
143
|
+
download: {
|
|
144
|
+
type: "string",
|
|
145
|
+
description: "Download media from the result (implies --result).",
|
|
146
|
+
},
|
|
147
|
+
json: { type: "boolean" },
|
|
148
|
+
},
|
|
149
|
+
run: async ({ args, rawArgs }) => {
|
|
150
|
+
if (args.result && args.cancel) {
|
|
151
|
+
consola.error("Pick one of --result or --cancel.");
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
const downloadFlag = parseDownloadFlag(rawArgs);
|
|
155
|
+
const wantResult = args.result || downloadFlag.mode === "on";
|
|
156
|
+
const action = args.cancel
|
|
157
|
+
? "cancel"
|
|
158
|
+
: wantResult
|
|
159
|
+
? "result"
|
|
160
|
+
: "status";
|
|
161
|
+
const ep = queueAppId(args.endpoint_id);
|
|
162
|
+
const client = createClient();
|
|
163
|
+
const path = action === "cancel"
|
|
164
|
+
? `/${ep}/requests/${args.request_id}/cancel`
|
|
165
|
+
: action === "result"
|
|
166
|
+
? `/${ep}/requests/${args.request_id}`
|
|
167
|
+
: `/${ep}/requests/${args.request_id}/status`;
|
|
168
|
+
const data = await client.media.forward.mutate({
|
|
169
|
+
target: "queue",
|
|
170
|
+
method: action === "cancel" ? "PUT" : "GET",
|
|
171
|
+
path,
|
|
172
|
+
query: action === "status" && args.logs ? { logs: "1" } : undefined,
|
|
173
|
+
});
|
|
174
|
+
let downloaded;
|
|
175
|
+
if (action === "result" && downloadFlag.mode === "on") {
|
|
176
|
+
const refs = extractMediaRefs(data);
|
|
177
|
+
downloaded = await downloadMedia({
|
|
178
|
+
refs,
|
|
179
|
+
template: downloadFlag.template,
|
|
180
|
+
requestId: args.request_id,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const actionFields = buildActionFields(action, data);
|
|
184
|
+
const payload = {
|
|
185
|
+
action,
|
|
186
|
+
endpoint_id: args.endpoint_id,
|
|
187
|
+
request_id: args.request_id,
|
|
188
|
+
...actionFields,
|
|
189
|
+
...(downloaded ? { downloaded_files: downloaded.downloaded } : {}),
|
|
190
|
+
...(downloaded && downloaded.failed.length > 0
|
|
191
|
+
? { download_failures: downloaded.failed }
|
|
192
|
+
: {}),
|
|
193
|
+
};
|
|
194
|
+
if (isJsonOutput(args)) {
|
|
195
|
+
writeJson(payload);
|
|
196
|
+
}
|
|
197
|
+
else if (action === "status") {
|
|
198
|
+
const status = isRecord(data) && typeof data.status === "string" ? data.status : "?";
|
|
199
|
+
consola.log(`status: ${status}`);
|
|
200
|
+
if (isRecord(data) && typeof data.queue_position === "number") {
|
|
201
|
+
consola.log(`queue_position: ${data.queue_position}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
consola.success(`${action} ${args.endpoint_id} ${args.request_id}`);
|
|
206
|
+
if (downloaded) {
|
|
207
|
+
for (const p of downloaded.downloaded)
|
|
208
|
+
consola.log(` ${p}`);
|
|
209
|
+
for (const f of downloaded.failed)
|
|
210
|
+
consola.warn(` failed: ${f.url} (${f.error})`);
|
|
211
|
+
}
|
|
212
|
+
if (action === "result" && !downloaded?.downloaded.length) {
|
|
213
|
+
for (const url of extractMediaUrls(data))
|
|
214
|
+
consola.log(` ${url}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (downloaded && downloaded.failed.length > 0 && downloaded.downloaded.length === 0) {
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
// ---- models -----------------------------------------------------------------
|
|
223
|
+
const modelsCommand = defineCommand({
|
|
224
|
+
meta: { name: "models", description: "Search/list fal models." },
|
|
225
|
+
args: {
|
|
226
|
+
query: { type: "positional", required: false, description: "Search query." },
|
|
227
|
+
category: { type: "string", description: "Filter by category." },
|
|
228
|
+
status: { type: "string", description: "active (default) | deprecated | all" },
|
|
229
|
+
limit: { type: "string", description: "Max results (default 20)." },
|
|
230
|
+
cursor: { type: "string", description: "Pagination cursor from a prior response." },
|
|
231
|
+
endpoint_id: {
|
|
232
|
+
type: "string",
|
|
233
|
+
description: "Specific endpoint id(s); repeat or comma-separate.",
|
|
234
|
+
},
|
|
235
|
+
expand: {
|
|
236
|
+
type: "string",
|
|
237
|
+
description: "Expand fields: openapi-3.0, enterprise_status. Repeat or comma-separate.",
|
|
238
|
+
},
|
|
239
|
+
json: { type: "boolean" },
|
|
240
|
+
},
|
|
241
|
+
run: async ({ args }) => {
|
|
242
|
+
const query = {};
|
|
243
|
+
if (args.query)
|
|
244
|
+
query.q = args.query;
|
|
245
|
+
if (args.category)
|
|
246
|
+
query.category = args.category;
|
|
247
|
+
if (args.status && args.status !== "all")
|
|
248
|
+
query.status = args.status;
|
|
249
|
+
query.limit = args.limit ?? "20";
|
|
250
|
+
if (args.cursor)
|
|
251
|
+
query.cursor = args.cursor;
|
|
252
|
+
const endpointIds = splitList(args.endpoint_id);
|
|
253
|
+
if (endpointIds.length > 0)
|
|
254
|
+
query.endpoint_id = endpointIds;
|
|
255
|
+
const expand = splitList(args.expand);
|
|
256
|
+
if (expand.length > 0)
|
|
257
|
+
query.expand = expand;
|
|
258
|
+
const client = createClient();
|
|
259
|
+
const data = await client.media.forward.mutate({
|
|
260
|
+
target: "platform",
|
|
261
|
+
method: "GET",
|
|
262
|
+
path: "/v1/models",
|
|
263
|
+
query,
|
|
264
|
+
});
|
|
265
|
+
if (isJsonOutput(args))
|
|
266
|
+
writeJson(data);
|
|
267
|
+
else
|
|
268
|
+
printModels(data);
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
function splitList(value) {
|
|
272
|
+
if (!value)
|
|
273
|
+
return [];
|
|
274
|
+
return value
|
|
275
|
+
.split(",")
|
|
276
|
+
.map((s) => s.trim())
|
|
277
|
+
.filter(Boolean);
|
|
278
|
+
}
|
|
279
|
+
function printModels(data) {
|
|
280
|
+
const models = isRecord(data) && Array.isArray(data.models) ? data.models : [];
|
|
281
|
+
for (const m of models) {
|
|
282
|
+
if (!isRecord(m))
|
|
283
|
+
continue;
|
|
284
|
+
const id = String(m.endpoint_id ?? "?");
|
|
285
|
+
const meta = isRecord(m.metadata) ? m.metadata : {};
|
|
286
|
+
const tags = [];
|
|
287
|
+
if (meta.category)
|
|
288
|
+
tags.push(String(meta.category));
|
|
289
|
+
if (meta.status)
|
|
290
|
+
tags.push(String(meta.status));
|
|
291
|
+
consola.log(`${id}${tags.length > 0 ? ` [${tags.join(", ")}]` : ""}`);
|
|
292
|
+
}
|
|
293
|
+
if (isRecord(data) && data.next_cursor) {
|
|
294
|
+
consola.log(`\nnext_cursor: ${String(data.next_cursor)}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// ---- schema -----------------------------------------------------------------
|
|
298
|
+
const schemaCommand = defineCommand({
|
|
299
|
+
meta: { name: "schema", description: "Fetch a model's input/output schema." },
|
|
300
|
+
args: {
|
|
301
|
+
endpoint_id: { type: "positional", required: true },
|
|
302
|
+
format: { type: "string", description: "compact (default) | openapi" },
|
|
303
|
+
json: { type: "boolean" },
|
|
304
|
+
},
|
|
305
|
+
run: async ({ args }) => {
|
|
306
|
+
const expand = args.format === "openapi" ? ["openapi-3.0"] : [];
|
|
307
|
+
const client = createClient();
|
|
308
|
+
const data = await client.media.forward.mutate({
|
|
309
|
+
target: "platform",
|
|
310
|
+
method: "GET",
|
|
311
|
+
path: "/v1/models",
|
|
312
|
+
query: {
|
|
313
|
+
endpoint_id: args.endpoint_id,
|
|
314
|
+
limit: "1",
|
|
315
|
+
...(expand.length > 0 ? { expand } : {}),
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
writeJson(data);
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
// ---- pricing ----------------------------------------------------------------
|
|
322
|
+
const pricingCommand = defineCommand({
|
|
323
|
+
meta: { name: "pricing", description: "Fetch pricing for a model." },
|
|
324
|
+
args: {
|
|
325
|
+
endpoint_id: { type: "positional", required: true },
|
|
326
|
+
json: { type: "boolean" },
|
|
327
|
+
},
|
|
328
|
+
run: async ({ args }) => {
|
|
329
|
+
const client = createClient();
|
|
330
|
+
const data = await client.media.forward.mutate({
|
|
331
|
+
target: "platform",
|
|
332
|
+
method: "GET",
|
|
333
|
+
path: "/v1/models/pricing",
|
|
334
|
+
query: { endpoint_id: args.endpoint_id },
|
|
335
|
+
});
|
|
336
|
+
writeJson(data);
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
// ---- docs -------------------------------------------------------------------
|
|
340
|
+
const docsCommand = defineCommand({
|
|
341
|
+
meta: { name: "docs", description: "Search fal documentation." },
|
|
342
|
+
args: {
|
|
343
|
+
query: { type: "positional", required: true },
|
|
344
|
+
json: { type: "boolean" },
|
|
345
|
+
},
|
|
346
|
+
run: async ({ args }) => {
|
|
347
|
+
const client = createClient();
|
|
348
|
+
const data = await client.media.forward.mutate({
|
|
349
|
+
target: "docs",
|
|
350
|
+
method: "POST",
|
|
351
|
+
path: "/docs/mcp",
|
|
352
|
+
body: {
|
|
353
|
+
jsonrpc: "2.0",
|
|
354
|
+
id: 1,
|
|
355
|
+
method: "tools/call",
|
|
356
|
+
params: { name: "search_fal", arguments: { query: args.query } },
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
writeJson(data);
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
// ---- upload -----------------------------------------------------------------
|
|
363
|
+
const uploadCommand = defineCommand({
|
|
364
|
+
meta: {
|
|
365
|
+
name: "upload",
|
|
366
|
+
description: "Upload a local file to fal CDN. Returns a stable URL.",
|
|
367
|
+
},
|
|
368
|
+
args: {
|
|
369
|
+
path: { type: "positional", required: true },
|
|
370
|
+
json: { type: "boolean" },
|
|
371
|
+
},
|
|
372
|
+
run: async ({ args }) => {
|
|
373
|
+
const stat = readExplicitLocalFile(args.path);
|
|
374
|
+
if (!stat) {
|
|
375
|
+
consola.error(`File not found: ${args.path}`);
|
|
376
|
+
process.exit(1);
|
|
377
|
+
}
|
|
378
|
+
const client = createClient();
|
|
379
|
+
const url = await uploadFile(client, stat);
|
|
380
|
+
if (isJsonOutput(args))
|
|
381
|
+
writeJson({ url });
|
|
382
|
+
else
|
|
383
|
+
process.stdout.write(url + "\n");
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
// ---- top-level --------------------------------------------------------------
|
|
387
|
+
export const mediaCommand = defineCommand({
|
|
388
|
+
meta: {
|
|
389
|
+
name: "media",
|
|
390
|
+
description: "Generate, edit, and inspect media via fal.ai (mirrors the genmedia CLI surface).",
|
|
391
|
+
},
|
|
392
|
+
subCommands: {
|
|
393
|
+
run: runCommand,
|
|
394
|
+
status: statusCommand,
|
|
395
|
+
models: modelsCommand,
|
|
396
|
+
schema: schemaCommand,
|
|
397
|
+
pricing: pricingCommand,
|
|
398
|
+
docs: docsCommand,
|
|
399
|
+
upload: uploadCommand,
|
|
400
|
+
},
|
|
401
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const newCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly slug: {
|
|
3
|
+
readonly type: "positional";
|
|
4
|
+
readonly description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.";
|
|
5
|
+
readonly required: true;
|
|
6
|
+
};
|
|
7
|
+
readonly engine: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "Engine preset: phaser (default), threejs, or none.";
|
|
10
|
+
readonly default: "phaser";
|
|
11
|
+
};
|
|
12
|
+
readonly template: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.";
|
|
15
|
+
};
|
|
16
|
+
readonly here: {
|
|
17
|
+
readonly type: "boolean";
|
|
18
|
+
readonly description: "Write into the current directory instead of creating <slug>/.";
|
|
19
|
+
readonly default: false;
|
|
20
|
+
};
|
|
21
|
+
readonly force: {
|
|
22
|
+
readonly type: "boolean";
|
|
23
|
+
readonly description: "Overwrite an existing target directory.";
|
|
24
|
+
readonly default: false;
|
|
25
|
+
};
|
|
26
|
+
}>;
|