vibedgames 0.3.0 → 0.4.0
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 +45 -12
- package/dist/commands/completions.js +3 -0
- package/dist/commands/credits.d.ts +10 -0
- package/dist/commands/credits.js +137 -0
- package/dist/commands/deploy.d.ts +2 -2
- package/dist/commands/deploy.js +4 -5
- package/dist/commands/fork.d.ts +8 -5
- package/dist/commands/fork.js +5 -10
- package/dist/commands/generate.js +69 -53
- package/dist/commands/init.js +18 -6
- package/dist/commands/new.js +1 -1
- package/dist/commands/playtest.d.ts +29 -0
- package/dist/commands/playtest.js +325 -0
- package/dist/commands/update.d.ts +1 -1
- package/dist/commands/update.js +14 -8
- package/dist/index.js +11 -3
- package/dist/lib/config-file.d.ts +6 -0
- package/dist/lib/config-file.js +6 -0
- package/dist/lib/manifest.js +2 -0
- package/dist/lib/output.d.ts +45 -0
- package/dist/lib/output.js +94 -0
- package/dist/lib/package-manager.d.ts +25 -0
- package/dist/lib/package-manager.js +72 -0
- package/dist/lib/run.d.ts +6 -0
- package/dist/lib/run.js +6 -0
- package/package.json +8 -8
- package/dist/.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -22,39 +22,72 @@ vg new <slug> --engine react-r3f # scaffold a React + R3F + drei + Vite + TS sta
|
|
|
22
22
|
vg new <slug> --engine none # minimal Vite + TS + canvas (offline; inline)
|
|
23
23
|
vg new <slug> --template owner/repo # any github degit spec
|
|
24
24
|
vg new <slug> --here # scaffold into the current directory
|
|
25
|
-
vg init [
|
|
25
|
+
vg init [--global] [--agents …] # install/update the vibedgames skills + CLI
|
|
26
|
+
vg update # update the CLI and installed skills to latest
|
|
26
27
|
vg login # authenticate via browser
|
|
27
28
|
vg logout # clear credentials
|
|
28
29
|
vg whoami # show current user
|
|
29
30
|
vg deploy [dir] # deploy a game directory (reads vibedgames.json or --slug)
|
|
31
|
+
vg fork <slug> [target] # fork a project's shipped source under a new slug
|
|
32
|
+
vg credits # credit balance + recent usage
|
|
33
|
+
vg factory [args…] # autonomous game agent (optional plugin, installs on first use)
|
|
34
|
+
vg completions <bash|zsh|fish> # print shell completions
|
|
30
35
|
|
|
31
36
|
vg generate run <model> [params] # run a generative model (waits for result)
|
|
32
37
|
vg generate models [query] # search/list available models
|
|
33
38
|
vg generate schema <model> # fetch a model's input/output schema
|
|
34
39
|
vg generate pricing <model> # fetch pricing for a model
|
|
35
|
-
vg generate status <model> <id> # check an async request
|
|
40
|
+
vg generate status <model> <id> # check an async request (--result, --cancel)
|
|
36
41
|
vg generate upload <file> # upload an asset, get a URL
|
|
37
42
|
vg generate docs <query> # search generative-model documentation
|
|
38
43
|
```
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
Most commands support `--json` for machine-readable output, and `--field <path>`
|
|
46
|
+
to print one value out of it — `vg generate upload x.png --field url` prints the
|
|
47
|
+
bare URL, ready for `$(...)` capture, so no JSON processor is needed. The path is
|
|
48
|
+
dotted, takes `images[0]` or `images.0`, and counts negative indices from the
|
|
49
|
+
end; a path that doesn't resolve is an error rather than an empty line.
|
|
50
|
+
|
|
51
|
+
`vg init` shells out to `npx skills add kyh/vibedgames` and installs for Claude
|
|
52
|
+
Code, Cursor and Codex by default (symlinked from a shared `.agents/skills/`);
|
|
53
|
+
`--agents` narrows or widens that, `--global` targets the user directory instead
|
|
54
|
+
of the project. `vg update` runs automatically once a day — disable with
|
|
55
|
+
`VG_NO_AUTO_UPDATE=1`.
|
|
56
|
+
|
|
57
|
+
Both self-update with whichever package manager installed the CLI, detected
|
|
58
|
+
from its install path (npm, pnpm, yarn or bun) — installing with a different
|
|
59
|
+
one would write a second copy into a prefix your shell may not be looking at.
|
|
60
|
+
If that manager isn't on PATH, the CLI prints the exact command to run instead
|
|
61
|
+
of failing with a bare exit code.
|
|
62
|
+
|
|
63
|
+
`vg factory` is a pure passthrough to the [factory](../factory) binary, which is
|
|
64
|
+
installed as a platform-specific optional package on first use — the CLI itself
|
|
65
|
+
carries none of it.
|
|
41
66
|
|
|
42
67
|
`vg generate` calls the `generate.forward` tRPC proc — the server holds the
|
|
43
68
|
provider API key, so generation works for any logged-in user with no local keys.
|
|
44
69
|
|
|
45
|
-
## Using with
|
|
70
|
+
## Using with a coding agent
|
|
46
71
|
|
|
47
|
-
Run `vg init` in your project to
|
|
48
|
-
(Phaser, Three.js,
|
|
49
|
-
|
|
72
|
+
Run `vg init` in your project to install the full set of game-building skills
|
|
73
|
+
(design, Phaser, Three.js, asset generation, multiplayer, deploy — see
|
|
74
|
+
[`plugins/`](../../plugins)). The agent picks them up on its next session.
|
|
50
75
|
|
|
51
76
|
## How deploy works
|
|
52
77
|
|
|
53
|
-
1.
|
|
54
|
-
2.
|
|
55
|
-
3.
|
|
56
|
-
4.
|
|
78
|
+
1. Picks the build output (`dist`/`build`/`out`) when the directory is a project root
|
|
79
|
+
2. Walks the directory, hashes files, validates `index.html` exists
|
|
80
|
+
3. Calls `deploy.create` API — gets presigned R2 upload URLs
|
|
81
|
+
4. Uploads files to R2 with bounded concurrency
|
|
82
|
+
5. Calls `deploy.finalize` — game goes live at `{slug}.vibedgames.com`
|
|
83
|
+
|
|
84
|
+
Passing `--source` also uploads a forkable source archive, which is what
|
|
85
|
+
`vg fork <slug>` downloads. It is off by default: the archive is readable by
|
|
86
|
+
any logged-in user, so shipping it is a publish and should be a deliberate act.
|
|
57
87
|
|
|
58
88
|
## Auth
|
|
59
89
|
|
|
60
|
-
Uses a polling flow: CLI generates a code, opens the browser,
|
|
90
|
+
Uses a device-code polling flow: CLI generates a 6-char code, opens the browser,
|
|
91
|
+
polls until the user confirms. Token stored at `~/.config/vg/auth.json`.
|
|
92
|
+
`VG_TOKEN` overrides it (for CI and headless agents) and `VG_API_URL` points the
|
|
93
|
+
CLI at a non-production API.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const creditsCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly json: {
|
|
3
|
+
readonly type: "boolean";
|
|
4
|
+
readonly description: "Print structured JSON to stdout.";
|
|
5
|
+
};
|
|
6
|
+
readonly field: {
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
readonly description: "Print a single value from the JSON result, e.g. --field request_id or --field images[0].url. Prints scalars bare for shell capture.";
|
|
9
|
+
};
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import consola from "consola";
|
|
3
|
+
import { createClient } from "../lib/api.js";
|
|
4
|
+
import { getToken } from "../lib/config.js";
|
|
5
|
+
import { outputArgs, writeStructured } from "../lib/output.js";
|
|
6
|
+
const MICRO_PER_USD = 1_000_000;
|
|
7
|
+
const SUB_CENT_MICRO = MICRO_PER_USD / 100;
|
|
8
|
+
const MAX_ENTRIES_SHOWN = 15;
|
|
9
|
+
// Dollars from integer micro-USD. Two decimals normally; four when the
|
|
10
|
+
// magnitude is sub-cent so small generation charges don't render as $0.00.
|
|
11
|
+
function formatUsd(micro) {
|
|
12
|
+
const abs = Math.abs(micro);
|
|
13
|
+
const decimals = abs > 0 && abs < SUB_CENT_MICRO ? 4 : 2;
|
|
14
|
+
const base = `$${(abs / MICRO_PER_USD).toFixed(decimals)}`;
|
|
15
|
+
return micro < 0 ? `-${base}` : base;
|
|
16
|
+
}
|
|
17
|
+
function formatSignedUsd(micro) {
|
|
18
|
+
return micro < 0 ? formatUsd(micro) : `+${formatUsd(micro)}`;
|
|
19
|
+
}
|
|
20
|
+
function kindLabel(kind, deltaMicro) {
|
|
21
|
+
switch (kind) {
|
|
22
|
+
case "signup_grant":
|
|
23
|
+
return "Welcome credits";
|
|
24
|
+
case "admin_grant":
|
|
25
|
+
return deltaMicro < 0 ? "Adjustment" : "Credit grant";
|
|
26
|
+
case "generation_hold":
|
|
27
|
+
return "Generation";
|
|
28
|
+
case "generation_settle":
|
|
29
|
+
return "Usage adjustment";
|
|
30
|
+
case "generation_release":
|
|
31
|
+
return "Refund — failed generation";
|
|
32
|
+
default:
|
|
33
|
+
return kind;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Relative for the last week, short date beyond that.
|
|
37
|
+
function formatWhen(date, now) {
|
|
38
|
+
const minutes = Math.floor((now.getTime() - date.getTime()) / 60_000);
|
|
39
|
+
if (minutes < 1)
|
|
40
|
+
return "just now";
|
|
41
|
+
if (minutes < 60)
|
|
42
|
+
return `${minutes}m ago`;
|
|
43
|
+
const hours = Math.floor(minutes / 60);
|
|
44
|
+
if (hours < 24)
|
|
45
|
+
return `${hours}h ago`;
|
|
46
|
+
const days = Math.floor(hours / 24);
|
|
47
|
+
if (days < 7)
|
|
48
|
+
return `${days}d ago`;
|
|
49
|
+
const opts = { month: "short", day: "numeric" };
|
|
50
|
+
if (date.getFullYear() !== now.getFullYear())
|
|
51
|
+
opts.year = "numeric";
|
|
52
|
+
return date.toLocaleDateString("en-US", opts);
|
|
53
|
+
}
|
|
54
|
+
function authErrorCode(err) {
|
|
55
|
+
if (typeof err === "object" && err !== null && "data" in err) {
|
|
56
|
+
const data = err.data;
|
|
57
|
+
if (typeof data === "object" &&
|
|
58
|
+
data !== null &&
|
|
59
|
+
"code" in data &&
|
|
60
|
+
typeof data.code === "string") {
|
|
61
|
+
return data.code;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
export const creditsCommand = defineCommand({
|
|
67
|
+
meta: {
|
|
68
|
+
name: "credits",
|
|
69
|
+
description: "Show your credit balance and recent usage.",
|
|
70
|
+
},
|
|
71
|
+
args: {
|
|
72
|
+
...outputArgs,
|
|
73
|
+
},
|
|
74
|
+
run: async ({ args }) => {
|
|
75
|
+
const token = getToken();
|
|
76
|
+
if (!token) {
|
|
77
|
+
consola.warn("Not logged in. Run `vg login` to authenticate.");
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
const client = createClient();
|
|
81
|
+
try {
|
|
82
|
+
const { balanceMicro, entries } = await client.credits.me.query();
|
|
83
|
+
const payload = {
|
|
84
|
+
balance_micro: balanceMicro,
|
|
85
|
+
balance_usd: balanceMicro / MICRO_PER_USD,
|
|
86
|
+
entries: entries.map((e) => ({
|
|
87
|
+
id: e.id,
|
|
88
|
+
delta_micro: e.deltaMicro,
|
|
89
|
+
kind: e.kind,
|
|
90
|
+
request_id: e.requestId,
|
|
91
|
+
endpoint_id: e.endpointId,
|
|
92
|
+
note: e.note,
|
|
93
|
+
created_at: e.createdAt.toISOString(),
|
|
94
|
+
})),
|
|
95
|
+
};
|
|
96
|
+
if (writeStructured(payload, args))
|
|
97
|
+
return;
|
|
98
|
+
consola.log(`Balance: ${formatUsd(balanceMicro)}`);
|
|
99
|
+
if (entries.length === 0) {
|
|
100
|
+
consola.log("No activity yet.");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const now = new Date();
|
|
104
|
+
const rows = entries.slice(0, MAX_ENTRIES_SHOWN).map((e) => ({
|
|
105
|
+
amount: formatSignedUsd(e.deltaMicro),
|
|
106
|
+
label: kindLabel(e.kind, e.deltaMicro),
|
|
107
|
+
endpoint: e.endpointId ?? "",
|
|
108
|
+
when: formatWhen(e.createdAt, now),
|
|
109
|
+
}));
|
|
110
|
+
const amountWidth = Math.max(...rows.map((r) => r.amount.length));
|
|
111
|
+
const labelWidth = Math.max(...rows.map((r) => r.label.length));
|
|
112
|
+
const endpointWidth = Math.max(...rows.map((r) => r.endpoint.length));
|
|
113
|
+
consola.log("");
|
|
114
|
+
for (const r of rows) {
|
|
115
|
+
const line = [
|
|
116
|
+
` ${r.amount.padStart(amountWidth)}`,
|
|
117
|
+
r.label.padEnd(labelWidth),
|
|
118
|
+
r.endpoint.padEnd(endpointWidth),
|
|
119
|
+
r.when,
|
|
120
|
+
].join(" ");
|
|
121
|
+
consola.log(line.trimEnd());
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
// Only an auth error means "log in"; surface network/server failures as
|
|
126
|
+
// themselves so they aren't mistaken for a bad credential.
|
|
127
|
+
const code = authErrorCode(err);
|
|
128
|
+
if (code === "UNAUTHORIZED" || code === "FORBIDDEN") {
|
|
129
|
+
consola.warn("Not authenticated. Run `vg login`, or check your VG_TOKEN / API key.");
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
consola.error(`Failed to fetch credits: ${err instanceof Error ? err.message : String(err)}`);
|
|
133
|
+
}
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
});
|
|
@@ -12,7 +12,7 @@ export declare const deployCommand: import("citty").CommandDef<{
|
|
|
12
12
|
};
|
|
13
13
|
readonly source: {
|
|
14
14
|
readonly type: "boolean";
|
|
15
|
-
readonly description: "
|
|
16
|
-
readonly default:
|
|
15
|
+
readonly description: "Also upload a forkable source archive, letting anyone logged in fork the project.";
|
|
16
|
+
readonly default: false;
|
|
17
17
|
};
|
|
18
18
|
}>;
|
package/dist/commands/deploy.js
CHANGED
|
@@ -5,10 +5,9 @@ import { defineCommand } from "citty";
|
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
import { createClient } from "../lib/api.js";
|
|
7
7
|
import { packSource } from "../lib/archive.js";
|
|
8
|
-
import { findProjectRoot, projectConfigPath, readProjectConfig, writeProjectConfig, } from "../lib/config-file.js";
|
|
8
|
+
import { findProjectRoot, projectConfigPath, readProjectConfig, writeProjectConfig, SLUG_RE, } from "../lib/config-file.js";
|
|
9
9
|
import { buildManifest } from "../lib/manifest.js";
|
|
10
10
|
import { uploadAll } from "../lib/upload.js";
|
|
11
|
-
const SLUG_RE = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
|
|
12
11
|
export const deployCommand = defineCommand({
|
|
13
12
|
meta: {
|
|
14
13
|
name: "deploy",
|
|
@@ -28,8 +27,8 @@ export const deployCommand = defineCommand({
|
|
|
28
27
|
},
|
|
29
28
|
source: {
|
|
30
29
|
type: "boolean",
|
|
31
|
-
description: "
|
|
32
|
-
default:
|
|
30
|
+
description: "Also upload a forkable source archive, letting anyone logged in fork the project.",
|
|
31
|
+
default: false,
|
|
33
32
|
},
|
|
34
33
|
},
|
|
35
34
|
run: async ({ args }) => {
|
|
@@ -106,7 +105,7 @@ export const deployCommand = defineCommand({
|
|
|
106
105
|
}
|
|
107
106
|
const totalBytes = manifest.reduce((acc, f) => acc + f.size, 0);
|
|
108
107
|
consola.info(`Deploying ${config.slug}: ${manifest.length} files, ${formatBytes(totalBytes)}`);
|
|
109
|
-
// ---- Pack forkable source (
|
|
108
|
+
// ---- Pack forkable source (opt-in: source is a publish, --source) -------
|
|
110
109
|
let sourceArchive = null;
|
|
111
110
|
if (args.source) {
|
|
112
111
|
const root = findProjectRoot(dir);
|
package/dist/commands/fork.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export declare const forkCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly json: {
|
|
3
|
+
readonly type: "boolean";
|
|
4
|
+
readonly description: "Print structured JSON to stdout.";
|
|
5
|
+
};
|
|
6
|
+
readonly field: {
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
readonly description: "Print a single value from the JSON result, e.g. --field request_id or --field images[0].url. Prints scalars bare for shell capture.";
|
|
9
|
+
};
|
|
2
10
|
readonly slug: {
|
|
3
11
|
readonly type: "positional";
|
|
4
12
|
readonly description: "Slug of the project to fork (e.g. bomberman).";
|
|
@@ -18,9 +26,4 @@ export declare const forkCommand: import("citty").CommandDef<{
|
|
|
18
26
|
readonly description: "Overwrite the target directory if it exists.";
|
|
19
27
|
readonly default: false;
|
|
20
28
|
};
|
|
21
|
-
readonly json: {
|
|
22
|
-
readonly type: "boolean";
|
|
23
|
-
readonly description: "Emit machine-readable JSON (for agents).";
|
|
24
|
-
readonly default: false;
|
|
25
|
-
};
|
|
26
29
|
}>;
|
package/dist/commands/fork.js
CHANGED
|
@@ -5,7 +5,8 @@ import { defineCommand } from "citty";
|
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
import { createClient } from "../lib/api.js";
|
|
7
7
|
import { extractSource } from "../lib/archive.js";
|
|
8
|
-
|
|
8
|
+
import { SLUG_RE } from "../lib/config-file.js";
|
|
9
|
+
import { isJsonOutput, outputArgs, writeStructured } from "../lib/output.js";
|
|
9
10
|
export const forkCommand = defineCommand({
|
|
10
11
|
meta: {
|
|
11
12
|
name: "fork",
|
|
@@ -31,11 +32,7 @@ export const forkCommand = defineCommand({
|
|
|
31
32
|
description: "Overwrite the target directory if it exists.",
|
|
32
33
|
default: false,
|
|
33
34
|
},
|
|
34
|
-
|
|
35
|
-
type: "boolean",
|
|
36
|
-
description: "Emit machine-readable JSON (for agents).",
|
|
37
|
-
default: false,
|
|
38
|
-
},
|
|
35
|
+
...outputArgs,
|
|
39
36
|
},
|
|
40
37
|
run: async ({ args }) => {
|
|
41
38
|
const source = args.slug.trim().toLowerCase();
|
|
@@ -56,7 +53,7 @@ export const forkCommand = defineCommand({
|
|
|
56
53
|
}
|
|
57
54
|
const client = createClient();
|
|
58
55
|
// ---- Resolve + download source -----------------------------------------
|
|
59
|
-
if (!args.
|
|
56
|
+
if (!isJsonOutput(args) && !args.field)
|
|
60
57
|
consola.start(`Forking ${source}`);
|
|
61
58
|
let src;
|
|
62
59
|
try {
|
|
@@ -86,10 +83,8 @@ export const forkCommand = defineCommand({
|
|
|
86
83
|
const name = args.name ?? target.replace(/-/g, " ");
|
|
87
84
|
writeFileSync(resolve(dir, "vibedgames.json"), `${JSON.stringify({ slug: target, name }, null, 2)}\n`);
|
|
88
85
|
rewritePackageName(dir, target);
|
|
89
|
-
if (args
|
|
90
|
-
consola.log(JSON.stringify({ slug: target, dir, forkedFrom: source }));
|
|
86
|
+
if (writeStructured({ slug: target, dir, forkedFrom: source }, args))
|
|
91
87
|
return;
|
|
92
|
-
}
|
|
93
88
|
consola.success(`Forked ${source} → ${target}`);
|
|
94
89
|
consola.log(` ${dir}`);
|
|
95
90
|
consola.log("");
|
|
@@ -6,6 +6,7 @@ import { parseDownloadFlag, parseRunInput, readExplicitLocalFile } from "../lib/
|
|
|
6
6
|
import { downloadMedia, extractMediaRefs } from "../lib/media-download.js";
|
|
7
7
|
import { endpointPath, queueAppId, waitForCompletion } from "../lib/media-poll.js";
|
|
8
8
|
import { uploadFile } from "../lib/media-upload.js";
|
|
9
|
+
import { isJsonOutput, outputArgs, writeJson, writeStructured } from "../lib/output.js";
|
|
9
10
|
import { isRecord } from "../lib/types.js";
|
|
10
11
|
// Action-specific fields for the status-command payload. `result` wraps
|
|
11
12
|
// the raw fal payload under `result:` so fal's own keys can't clobber
|
|
@@ -23,11 +24,13 @@ function buildActionFields(action, data) {
|
|
|
23
24
|
}
|
|
24
25
|
return {};
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
/**
|
|
28
|
+
* True when stdout is carrying data rather than a progress narrative, so
|
|
29
|
+
* spinners and status lines must stay off it. `--field` counts: its whole
|
|
30
|
+
* point is that the output can be captured by a shell verbatim.
|
|
31
|
+
*/
|
|
32
|
+
function isStructuredOutput(args) {
|
|
33
|
+
return isJsonOutput(args) || Boolean(args.field);
|
|
31
34
|
}
|
|
32
35
|
function extractMediaUrls(result) {
|
|
33
36
|
return extractMediaRefs(result).map((r) => r.url);
|
|
@@ -53,7 +56,7 @@ const runCommand = defineCommand({
|
|
|
53
56
|
type: "string",
|
|
54
57
|
description: "Download media from result. Optional value is a path or template with {index},{name},{ext},{request_id}.",
|
|
55
58
|
},
|
|
56
|
-
|
|
59
|
+
...outputArgs,
|
|
57
60
|
quiet: { type: "boolean", description: "Suppress progress output during sync runs." },
|
|
58
61
|
},
|
|
59
62
|
run: async ({ args, rawArgs }) => {
|
|
@@ -87,16 +90,14 @@ const runCommand = defineCommand({
|
|
|
87
90
|
request_id: requestId,
|
|
88
91
|
hint: `Check status: vg generate status ${endpoint_id} ${requestId}`,
|
|
89
92
|
};
|
|
90
|
-
if (
|
|
91
|
-
writeJson(payload);
|
|
92
|
-
else {
|
|
93
|
+
if (!writeStructured(payload, args)) {
|
|
93
94
|
consola.success(`Submitted ${endpoint_id}`);
|
|
94
95
|
consola.log(` request_id: ${requestId}`);
|
|
95
96
|
}
|
|
96
97
|
return;
|
|
97
98
|
}
|
|
98
99
|
const completed = await waitForCompletion(client, endpoint_id, requestId, {
|
|
99
|
-
quiet: Boolean(args.quiet) ||
|
|
100
|
+
quiet: Boolean(args.quiet) || isStructuredOutput(args),
|
|
100
101
|
});
|
|
101
102
|
let downloaded;
|
|
102
103
|
if (downloadFlag.mode === "on") {
|
|
@@ -117,10 +118,7 @@ const runCommand = defineCommand({
|
|
|
117
118
|
? { download_failures: downloaded.failed }
|
|
118
119
|
: {}),
|
|
119
120
|
};
|
|
120
|
-
if (
|
|
121
|
-
writeJson(payload);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
121
|
+
if (!writeStructured(payload, args)) {
|
|
124
122
|
consola.success(`Run completed (${completed.request_id})`);
|
|
125
123
|
if (downloaded) {
|
|
126
124
|
for (const path of downloaded.downloaded)
|
|
@@ -185,10 +183,7 @@ async function runViaCodex(opts) {
|
|
|
185
183
|
...(failed.length > 0 ? { download_failures: failed } : {}),
|
|
186
184
|
...(ignoredReferences.length > 0 ? { ignored_references: ignoredReferences } : {}),
|
|
187
185
|
};
|
|
188
|
-
if (
|
|
189
|
-
writeJson(payload);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
186
|
+
if (!writeStructured(payload, args)) {
|
|
192
187
|
consola.success(`Codex generated ${downloaded.length} image(s) (${requestId})`);
|
|
193
188
|
for (const path of downloaded)
|
|
194
189
|
consola.log(` ${path}`);
|
|
@@ -214,7 +209,7 @@ const statusCommand = defineCommand({
|
|
|
214
209
|
type: "string",
|
|
215
210
|
description: "Download media from the result (implies --result).",
|
|
216
211
|
},
|
|
217
|
-
|
|
212
|
+
...outputArgs,
|
|
218
213
|
},
|
|
219
214
|
run: async ({ args, rawArgs }) => {
|
|
220
215
|
if (args.result && args.cancel) {
|
|
@@ -241,6 +236,29 @@ const statusCommand = defineCommand({
|
|
|
241
236
|
path,
|
|
242
237
|
query: action === "status" && args.logs ? { logs: "1" } : undefined,
|
|
243
238
|
});
|
|
239
|
+
// Cancellation is confirmed asynchronously, and the platform refunds a
|
|
240
|
+
// cancelled job's credit hold when a status poll reports the terminal
|
|
241
|
+
// state — so confirm with a few polls instead of leaving the refund to
|
|
242
|
+
// whenever the user next checks. Best-effort: a miss just defers it.
|
|
243
|
+
if (action === "cancel") {
|
|
244
|
+
const statusPath = `/${ep}/requests/${args.request_id}/status`;
|
|
245
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
246
|
+
await new Promise((resolve) => setTimeout(resolve, 1_000));
|
|
247
|
+
try {
|
|
248
|
+
const poll = await client.generate.forward.mutate({
|
|
249
|
+
target: "queue",
|
|
250
|
+
method: "GET",
|
|
251
|
+
path: statusPath,
|
|
252
|
+
});
|
|
253
|
+
const status = isRecord(poll) && typeof poll.status === "string" ? poll.status.toUpperCase() : "";
|
|
254
|
+
if (["CANCELLED", "FAILED", "COMPLETED"].includes(status))
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
244
262
|
let downloaded;
|
|
245
263
|
if (action === "result" && downloadFlag.mode === "on") {
|
|
246
264
|
const refs = extractMediaRefs(data);
|
|
@@ -261,27 +279,26 @@ const statusCommand = defineCommand({
|
|
|
261
279
|
? { download_failures: downloaded.failed }
|
|
262
280
|
: {}),
|
|
263
281
|
};
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
consola.log(`queue_position: ${data.queue_position}`);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
consola.success(`${action} ${args.endpoint_id} ${args.request_id}`);
|
|
276
|
-
if (downloaded) {
|
|
277
|
-
for (const p of downloaded.downloaded)
|
|
278
|
-
consola.log(` ${p}`);
|
|
279
|
-
for (const f of downloaded.failed)
|
|
280
|
-
consola.warn(` failed: ${f.url} (${f.error})`);
|
|
282
|
+
if (!writeStructured(payload, args)) {
|
|
283
|
+
if (action === "status") {
|
|
284
|
+
const status = isRecord(data) && typeof data.status === "string" ? data.status : "?";
|
|
285
|
+
consola.log(`status: ${status}`);
|
|
286
|
+
if (isRecord(data) && typeof data.queue_position === "number") {
|
|
287
|
+
consola.log(`queue_position: ${data.queue_position}`);
|
|
288
|
+
}
|
|
281
289
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
290
|
+
else {
|
|
291
|
+
consola.success(`${action} ${args.endpoint_id} ${args.request_id}`);
|
|
292
|
+
if (downloaded) {
|
|
293
|
+
for (const p of downloaded.downloaded)
|
|
294
|
+
consola.log(` ${p}`);
|
|
295
|
+
for (const f of downloaded.failed)
|
|
296
|
+
consola.warn(` failed: ${f.url} (${f.error})`);
|
|
297
|
+
}
|
|
298
|
+
if (action === "result" && !downloaded?.downloaded.length) {
|
|
299
|
+
for (const url of extractMediaUrls(data))
|
|
300
|
+
consola.log(` ${url}`);
|
|
301
|
+
}
|
|
285
302
|
}
|
|
286
303
|
}
|
|
287
304
|
if (downloaded && downloaded.failed.length > 0 && downloaded.downloaded.length === 0) {
|
|
@@ -306,7 +323,7 @@ const modelsCommand = defineCommand({
|
|
|
306
323
|
type: "string",
|
|
307
324
|
description: "Expand fields: openapi-3.0, enterprise_status. Repeat or comma-separate.",
|
|
308
325
|
},
|
|
309
|
-
|
|
326
|
+
...outputArgs,
|
|
310
327
|
},
|
|
311
328
|
run: async ({ args }) => {
|
|
312
329
|
const query = {};
|
|
@@ -332,9 +349,7 @@ const modelsCommand = defineCommand({
|
|
|
332
349
|
path: "/v1/models",
|
|
333
350
|
query,
|
|
334
351
|
});
|
|
335
|
-
if (
|
|
336
|
-
writeJson(data);
|
|
337
|
-
else
|
|
352
|
+
if (!writeStructured(data, args))
|
|
338
353
|
printModels(data);
|
|
339
354
|
},
|
|
340
355
|
});
|
|
@@ -370,7 +385,7 @@ const schemaCommand = defineCommand({
|
|
|
370
385
|
args: {
|
|
371
386
|
endpoint_id: { type: "positional", required: true },
|
|
372
387
|
format: { type: "string", description: "compact (default) | openapi" },
|
|
373
|
-
|
|
388
|
+
...outputArgs,
|
|
374
389
|
},
|
|
375
390
|
run: async ({ args }) => {
|
|
376
391
|
const expand = args.format === "openapi" ? ["openapi-3.0"] : [];
|
|
@@ -385,7 +400,8 @@ const schemaCommand = defineCommand({
|
|
|
385
400
|
...(expand.length > 0 ? { expand } : {}),
|
|
386
401
|
},
|
|
387
402
|
});
|
|
388
|
-
|
|
403
|
+
if (!writeStructured(data, args))
|
|
404
|
+
writeJson(data);
|
|
389
405
|
},
|
|
390
406
|
});
|
|
391
407
|
// ---- pricing ----------------------------------------------------------------
|
|
@@ -393,7 +409,7 @@ const pricingCommand = defineCommand({
|
|
|
393
409
|
meta: { name: "pricing", description: "Fetch pricing for a model." },
|
|
394
410
|
args: {
|
|
395
411
|
endpoint_id: { type: "positional", required: true },
|
|
396
|
-
|
|
412
|
+
...outputArgs,
|
|
397
413
|
},
|
|
398
414
|
run: async ({ args }) => {
|
|
399
415
|
const client = createClient();
|
|
@@ -403,7 +419,8 @@ const pricingCommand = defineCommand({
|
|
|
403
419
|
path: "/v1/models/pricing",
|
|
404
420
|
query: { endpoint_id: args.endpoint_id },
|
|
405
421
|
});
|
|
406
|
-
|
|
422
|
+
if (!writeStructured(data, args))
|
|
423
|
+
writeJson(data);
|
|
407
424
|
},
|
|
408
425
|
});
|
|
409
426
|
// ---- docs -------------------------------------------------------------------
|
|
@@ -411,7 +428,7 @@ const docsCommand = defineCommand({
|
|
|
411
428
|
meta: { name: "docs", description: "Search generative-model documentation." },
|
|
412
429
|
args: {
|
|
413
430
|
query: { type: "positional", required: true },
|
|
414
|
-
|
|
431
|
+
...outputArgs,
|
|
415
432
|
},
|
|
416
433
|
run: async ({ args }) => {
|
|
417
434
|
const client = createClient();
|
|
@@ -426,7 +443,8 @@ const docsCommand = defineCommand({
|
|
|
426
443
|
params: { name: "search_fal", arguments: { query: args.query } },
|
|
427
444
|
},
|
|
428
445
|
});
|
|
429
|
-
|
|
446
|
+
if (!writeStructured(data, args))
|
|
447
|
+
writeJson(data);
|
|
430
448
|
},
|
|
431
449
|
});
|
|
432
450
|
// ---- upload -----------------------------------------------------------------
|
|
@@ -437,7 +455,7 @@ const uploadCommand = defineCommand({
|
|
|
437
455
|
},
|
|
438
456
|
args: {
|
|
439
457
|
path: { type: "positional", required: true },
|
|
440
|
-
|
|
458
|
+
...outputArgs,
|
|
441
459
|
},
|
|
442
460
|
run: async ({ args }) => {
|
|
443
461
|
const stat = readExplicitLocalFile(args.path);
|
|
@@ -447,9 +465,7 @@ const uploadCommand = defineCommand({
|
|
|
447
465
|
}
|
|
448
466
|
const client = createClient();
|
|
449
467
|
const url = await uploadFile(client, stat);
|
|
450
|
-
if (
|
|
451
|
-
writeJson({ url });
|
|
452
|
-
else
|
|
468
|
+
if (!writeStructured({ url }, args))
|
|
453
469
|
process.stdout.write(url + "\n");
|
|
454
470
|
},
|
|
455
471
|
});
|
package/dist/commands/init.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
1
2
|
import { defineCommand } from "citty";
|
|
2
3
|
import consola from "consola";
|
|
3
|
-
import {
|
|
4
|
+
import { detectPackageManager, globalInstallArgs, globalInstallCommand, PKG_NAME, } from "../lib/package-manager.js";
|
|
5
|
+
import { isMissingCommand, run } from "../lib/run.js";
|
|
4
6
|
const REPO = "kyh/vibedgames";
|
|
5
|
-
const PKG = "vibedgames";
|
|
6
7
|
const DEFAULT_AGENTS = "claude-code,cursor,codex";
|
|
7
8
|
const description = "Install/update vibedgames skills and the vg CLI";
|
|
8
9
|
const skillsAddArgs = (agents, global, yes) => {
|
|
@@ -50,12 +51,21 @@ export const initCommand = defineCommand({
|
|
|
50
51
|
.split(",")
|
|
51
52
|
.map((s) => s.trim())
|
|
52
53
|
.filter(Boolean);
|
|
54
|
+
// Whatever installed this CLI is what should upgrade it. Installing with a
|
|
55
|
+
// different manager writes a second copy into a prefix the shell may not
|
|
56
|
+
// even be looking at, so `vg --version` would not move.
|
|
57
|
+
const manager = detectPackageManager(fileURLToPath(import.meta.url));
|
|
53
58
|
consola.start("Installing/updating vibedgames skills and the vg CLI...");
|
|
54
59
|
const [add, cli] = await Promise.all([
|
|
55
60
|
run("npx", skillsAddArgs(agents, args.global, args.yes)),
|
|
56
|
-
run(
|
|
61
|
+
run(manager, globalInstallArgs(manager)),
|
|
57
62
|
]);
|
|
58
63
|
if (add.code !== 0) {
|
|
64
|
+
if (isMissingCommand(add)) {
|
|
65
|
+
throw new Error("`npx` was not found on PATH. It ships with Node, so this usually means " +
|
|
66
|
+
"the vg CLI is running from a standalone build — install Node, or add " +
|
|
67
|
+
`the skills yourself with: npx skills add ${REPO}`);
|
|
68
|
+
}
|
|
59
69
|
if (add.output.trim())
|
|
60
70
|
consola.error(add.output.trim());
|
|
61
71
|
throw new Error(`skills add exited with code ${add.code}`);
|
|
@@ -71,11 +81,13 @@ export const initCommand = defineCommand({
|
|
|
71
81
|
consola.success("Refreshed installed skills to latest");
|
|
72
82
|
}
|
|
73
83
|
if (cli.code !== 0) {
|
|
74
|
-
if (cli.output.trim())
|
|
84
|
+
if (cli.output.trim() && !isMissingCommand(cli))
|
|
75
85
|
consola.warn(cli.output.trim());
|
|
76
|
-
consola.warn(
|
|
86
|
+
consola.warn(isMissingCommand(cli)
|
|
87
|
+
? `Couldn't find ${manager} to update the vg CLI. Update manually: ${globalInstallCommand(manager)}`
|
|
88
|
+
: `Couldn't install the vg CLI globally (${manager} exit ${cli.code}). Install manually: ${globalInstallCommand(manager)}`);
|
|
77
89
|
return;
|
|
78
90
|
}
|
|
79
|
-
consola.success(
|
|
91
|
+
consola.success(`Installed/updated ${PKG_NAME} globally with ${manager}`);
|
|
80
92
|
},
|
|
81
93
|
});
|