vibedgames 0.6.2 → 0.7.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 +14 -9
- package/dist/THIRD_PARTY_NOTICES.txt +383 -0
- package/dist/chunk-2GL2WJZX.js +172 -0
- package/dist/chunk-2QBYTIMH.js +511 -0
- package/dist/chunk-34AHIMX7.js +466 -0
- package/dist/chunk-6FZPPUQH.js +107 -0
- package/dist/chunk-BVVYDSFJ.js +99 -0
- package/dist/chunk-CAKBGDCY.js +47 -0
- package/dist/chunk-CBKOPVU6.js +1780 -0
- package/dist/chunk-CU7UY5YJ.js +1108 -0
- package/dist/chunk-CZPKN32Z.js +257 -0
- package/dist/chunk-DHEXGWJY.js +111 -0
- package/dist/chunk-FL6IFBUF.js +22 -0
- package/dist/chunk-FLUXEHMU.js +1360 -0
- package/dist/chunk-FNYBZNW2.js +165 -0
- package/dist/chunk-G5FRIFA3.js +22 -0
- package/dist/chunk-HCMTSR7E.js +69 -0
- package/dist/chunk-HKA5LBYW.js +159 -0
- package/dist/chunk-I6O4HIDY.js +1063 -0
- package/dist/chunk-J6PKNPI2.js +26 -0
- package/dist/chunk-JT2AU24K.js +759 -0
- package/dist/chunk-MBXCVCC4.js +478 -0
- package/dist/chunk-MJQSHP3Y.js +415 -0
- package/dist/chunk-MYFLYNPO.js +68 -0
- package/dist/chunk-PEUP4MZR.js +59 -0
- package/dist/chunk-PHEDW6C7.js +32 -0
- package/dist/chunk-PQDBCZRT.js +2017 -0
- package/dist/chunk-QGEITHUP.js +395 -0
- package/dist/chunk-QIVCBUYD.js +273 -0
- package/dist/chunk-RYFO3ZPO.js +71 -0
- package/dist/chunk-RZ4DIJQW.js +68 -0
- package/dist/chunk-SAANBZ25.js +118 -0
- package/dist/chunk-VFFOT7KD.js +2980 -0
- package/dist/chunk-Y552BNFZ.js +41 -0
- package/dist/chunk-Z4Z24FWO.js +39 -0
- package/dist/chunk-ZI6PKVXG.js +64 -0
- package/dist/chunk-ZYCSYJWX.js +87 -0
- package/dist/index.js +67 -60
- package/package.json +13 -16
- package/templates/none/_gitignore +3 -0
- package/templates/none/index.html +29 -0
- package/templates/none/package.json +16 -0
- package/templates/none/src/main.ts +16 -0
- package/templates/none/tsconfig.json +18 -0
- package/templates/none/vite.config.ts +8 -0
- package/templates/phaser/_gitignore +3 -0
- package/templates/phaser/index.html +24 -0
- package/templates/phaser/package.json +19 -0
- package/templates/phaser/src/main.ts +16 -0
- package/templates/phaser/src/scenes/game-scene.ts +65 -0
- package/templates/phaser/tsconfig.json +18 -0
- package/templates/phaser/vite.config.ts +8 -0
- package/templates/react-r3f/_gitignore +3 -0
- package/templates/react-r3f/index.html +24 -0
- package/templates/react-r3f/package.json +27 -0
- package/templates/react-r3f/src/app.tsx +33 -0
- package/templates/react-r3f/src/main.tsx +15 -0
- package/templates/react-r3f/tsconfig.json +19 -0
- package/templates/react-r3f/vite.config.ts +10 -0
- package/templates/threejs/_gitignore +3 -0
- package/templates/threejs/index.html +36 -0
- package/templates/threejs/package.json +20 -0
- package/templates/threejs/src/main.ts +44 -0
- package/templates/threejs/tsconfig.json +18 -0
- package/templates/threejs/vite.config.ts +8 -0
- package/dist/commands/completions.d.ts +0 -7
- package/dist/commands/completions.js +0 -145
- package/dist/commands/credits.d.ts +0 -10
- package/dist/commands/credits.js +0 -136
- package/dist/commands/deploy.d.ts +0 -26
- package/dist/commands/deploy.js +0 -257
- package/dist/commands/factory.d.ts +0 -3
- package/dist/commands/factory.js +0 -73
- package/dist/commands/fork.d.ts +0 -29
- package/dist/commands/fork.js +0 -124
- package/dist/commands/generate.d.ts +0 -1
- package/dist/commands/generate.js +0 -565
- package/dist/commands/init.d.ts +0 -20
- package/dist/commands/init.js +0 -105
- package/dist/commands/login.d.ts +0 -1
- package/dist/commands/login.js +0 -45
- package/dist/commands/logout.d.ts +0 -1
- package/dist/commands/logout.js +0 -13
- package/dist/commands/new.d.ts +0 -26
- package/dist/commands/new.js +0 -318
- package/dist/commands/playtest-run.d.ts +0 -66
- package/dist/commands/playtest-run.js +0 -268
- package/dist/commands/playtest.d.ts +0 -76
- package/dist/commands/playtest.js +0 -372
- package/dist/commands/update.d.ts +0 -13
- package/dist/commands/update.js +0 -82
- package/dist/commands/whoami.d.ts +0 -10
- package/dist/commands/whoami.js +0 -44
- package/dist/index.d.ts +0 -2
- package/dist/lib/api.d.ts +0 -18
- package/dist/lib/api.js +0 -27
- package/dist/lib/archive.d.ts +0 -17
- package/dist/lib/archive.js +0 -228
- package/dist/lib/codex.d.ts +0 -117
- package/dist/lib/codex.js +0 -426
- package/dist/lib/config-file.d.ts +0 -16
- package/dist/lib/config-file.js +0 -54
- package/dist/lib/config.d.ts +0 -11
- package/dist/lib/config.js +0 -54
- package/dist/lib/manifest.d.ts +0 -10
- package/dist/lib/manifest.js +0 -91
- package/dist/lib/media-args.d.ts +0 -30
- package/dist/lib/media-args.js +0 -219
- package/dist/lib/media-download.d.ts +0 -37
- package/dist/lib/media-download.js +0 -268
- package/dist/lib/media-poll.d.ts +0 -18
- package/dist/lib/media-poll.js +0 -86
- package/dist/lib/media-upload.d.ts +0 -12
- package/dist/lib/media-upload.js +0 -52
- package/dist/lib/output.d.ts +0 -68
- package/dist/lib/output.js +0 -102
- package/dist/lib/package-manager.d.ts +0 -25
- package/dist/lib/package-manager.js +0 -77
- package/dist/lib/playtest/agent.d.ts +0 -192
- package/dist/lib/playtest/agent.js +0 -652
- package/dist/lib/playtest/browser.d.ts +0 -109
- package/dist/lib/playtest/browser.js +0 -219
- package/dist/lib/playtest/controls.d.ts +0 -47
- package/dist/lib/playtest/controls.js +0 -218
- package/dist/lib/playtest/errors.d.ts +0 -9
- package/dist/lib/playtest/errors.js +0 -12
- package/dist/lib/playtest/keys.d.ts +0 -41
- package/dist/lib/playtest/keys.js +0 -157
- package/dist/lib/playtest/run.d.ts +0 -195
- package/dist/lib/playtest/run.js +0 -409
- package/dist/lib/run.d.ts +0 -19
- package/dist/lib/run.js +0 -23
- package/dist/lib/strict-args.d.ts +0 -27
- package/dist/lib/strict-args.js +0 -78
- package/dist/lib/types.d.ts +0 -16
- package/dist/lib/types.js +0 -10
- package/dist/lib/update.d.ts +0 -10
- package/dist/lib/update.js +0 -110
- package/dist/lib/upload.d.ts +0 -16
- package/dist/lib/upload.js +0 -41
package/dist/lib/media-args.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { JsonObject } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Parse `--<key> value` pairs from argv into a JS object, JSON-decoding
|
|
4
|
-
* values that look like JSON (true/false/null/numbers/objects/arrays) and
|
|
5
|
-
* leaving everything else as a string. The parse-value behavior is stable
|
|
6
|
-
* so skills targeting this surface produce the same input shapes.
|
|
7
|
-
*
|
|
8
|
-
* Handles both `--key value` and the GNU-style `--key=value`. Without
|
|
9
|
-
* `=` support, `--prompt=hello` would silently send the malformed key
|
|
10
|
-
* `"prompt=hello"` upstream, and `--async=true` would slip past the
|
|
11
|
-
* RUN_RESERVED_FLAGS guard as a bogus model param.
|
|
12
|
-
*/
|
|
13
|
-
export declare const parseRunInput: (argv: string[]) => JsonObject;
|
|
14
|
-
export interface LocalFile {
|
|
15
|
-
path: string;
|
|
16
|
-
filename: string;
|
|
17
|
-
contentType: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Probe a path the user explicitly asked us to read (e.g.
|
|
21
|
-
* `vg generate upload <path>`). Skips the path-shape heuristic so a bare
|
|
22
|
-
* filename with a non-media extension — `model.glb`, `scene.fbx`,
|
|
23
|
-
* `data.ply`, even `LICENSE` — still works.
|
|
24
|
-
*/
|
|
25
|
-
export declare const readExplicitLocalFile: (value: string) => LocalFile | null;
|
|
26
|
-
export interface DownloadFlag {
|
|
27
|
-
mode: "off" | "on";
|
|
28
|
-
template?: string;
|
|
29
|
-
}
|
|
30
|
-
export declare const parseDownloadFlag: (argv: string[]) => DownloadFlag;
|
package/dist/lib/media-args.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { statSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
// `--json`/`--help`/`--quiet` are global; `--async` switches the run path
|
|
5
|
-
// in citty; `--download` takes an optional template. None of them should
|
|
6
|
-
// leak through to fal as model parameters. `--logs` is intentionally NOT
|
|
7
|
-
// here: it's a `vg generate status` flag, not a `run` flag, so swallowing it
|
|
8
|
-
// would block users from passing a legitimate `logs` parameter to a
|
|
9
|
-
// model endpoint.
|
|
10
|
-
const RUN_RESERVED_FLAGS = new Set([
|
|
11
|
-
"--json",
|
|
12
|
-
"--help",
|
|
13
|
-
"--quiet",
|
|
14
|
-
"--async",
|
|
15
|
-
"--download",
|
|
16
|
-
"--provider",
|
|
17
|
-
]);
|
|
18
|
-
const assign = (out, key, value) => {
|
|
19
|
-
const existing = out[key];
|
|
20
|
-
if (existing !== undefined) {
|
|
21
|
-
if (Array.isArray(existing)) {
|
|
22
|
-
existing.push(value);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
out[key] = [existing, value];
|
|
26
|
-
}
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
out[key] = value;
|
|
30
|
-
};
|
|
31
|
-
const parseValue = (raw) => {
|
|
32
|
-
if (raw === "true") {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
if (raw === "false") {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
if (raw === "null") {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
if (raw.length > 0 && (raw[0] === "{" || raw[0] === "[")) {
|
|
42
|
-
try {
|
|
43
|
-
// SAFETY: JSON.parse output is structurally JsonValue.
|
|
44
|
-
return JSON.parse(raw);
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return raw;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (/^-?\d+(?:\.\d+)?$/u.test(raw)) {
|
|
51
|
-
const n = Number(raw);
|
|
52
|
-
if (Number.isFinite(n)) {
|
|
53
|
-
return n;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return raw;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Parse `--<key> value` pairs from argv into a JS object, JSON-decoding
|
|
60
|
-
* values that look like JSON (true/false/null/numbers/objects/arrays) and
|
|
61
|
-
* leaving everything else as a string. The parse-value behavior is stable
|
|
62
|
-
* so skills targeting this surface produce the same input shapes.
|
|
63
|
-
*
|
|
64
|
-
* Handles both `--key value` and the GNU-style `--key=value`. Without
|
|
65
|
-
* `=` support, `--prompt=hello` would silently send the malformed key
|
|
66
|
-
* `"prompt=hello"` upstream, and `--async=true` would slip past the
|
|
67
|
-
* RUN_RESERVED_FLAGS guard as a bogus model param.
|
|
68
|
-
*/
|
|
69
|
-
export const parseRunInput = (argv) => {
|
|
70
|
-
const out = {};
|
|
71
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
72
|
-
const arg = argv[i];
|
|
73
|
-
if (!arg || !arg.startsWith("--")) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
// POSIX `--` argument terminator: stop interpreting subsequent
|
|
77
|
-
// tokens as flags. Without this guard, `--` itself parses as
|
|
78
|
-
// `{ "": <next token> }` and pollutes the request body.
|
|
79
|
-
if (arg === "--") {
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
const eqIdx = arg.indexOf("=");
|
|
83
|
-
const name = eqIdx === -1 ? arg : arg.slice(0, eqIdx);
|
|
84
|
-
const inlineValue = eqIdx === -1 ? undefined : arg.slice(eqIdx + 1);
|
|
85
|
-
if (RUN_RESERVED_FLAGS.has(name)) {
|
|
86
|
-
// --download (without inline value) optionally consumes the next
|
|
87
|
-
// token as its template. With `--download=foo` the value is
|
|
88
|
-
// already attached and we move on without skipping anything.
|
|
89
|
-
if (name === "--download" && inlineValue === undefined) {
|
|
90
|
-
const next = argv[i + 1];
|
|
91
|
-
if (next && !next.startsWith("--")) {
|
|
92
|
-
i += 1;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
const key = name.slice(2);
|
|
98
|
-
if (inlineValue !== undefined) {
|
|
99
|
-
assign(out, key, parseValue(inlineValue));
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
const next = argv[i + 1];
|
|
103
|
-
if (next === undefined || next.startsWith("--")) {
|
|
104
|
-
assign(out, key, true);
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
assign(out, key, parseValue(next));
|
|
108
|
-
i += 1;
|
|
109
|
-
}
|
|
110
|
-
return out;
|
|
111
|
-
};
|
|
112
|
-
const expandHome = (value) => {
|
|
113
|
-
// node:path's resolve() doesn't expand `~` — that's a shell feature.
|
|
114
|
-
// We expand it ourselves so quoted paths like `"~/photo.png"` work.
|
|
115
|
-
if (value === "~") {
|
|
116
|
-
return homedir();
|
|
117
|
-
}
|
|
118
|
-
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
119
|
-
return path.join(homedir(), value.slice(2));
|
|
120
|
-
}
|
|
121
|
-
return value;
|
|
122
|
-
};
|
|
123
|
-
const contentTypeForPath = (file) => {
|
|
124
|
-
// extname splits on basename, so a dotted directory like
|
|
125
|
-
// "/home/user/my.project/texture" correctly yields "" instead of
|
|
126
|
-
// mistaking "project/texture" for the extension.
|
|
127
|
-
const ext = path.extname(file).slice(1).toLowerCase();
|
|
128
|
-
const map = new Map(Object.entries({
|
|
129
|
-
avif: "image/avif",
|
|
130
|
-
bmp: "image/bmp",
|
|
131
|
-
flac: "audio/flac",
|
|
132
|
-
gif: "image/gif",
|
|
133
|
-
jpeg: "image/jpeg",
|
|
134
|
-
jpg: "image/jpeg",
|
|
135
|
-
json: "application/json",
|
|
136
|
-
m4a: "audio/mp4",
|
|
137
|
-
mov: "video/quicktime",
|
|
138
|
-
mp3: "audio/mpeg",
|
|
139
|
-
mp4: "video/mp4",
|
|
140
|
-
ogg: "audio/ogg",
|
|
141
|
-
png: "image/png",
|
|
142
|
-
tif: "image/tiff",
|
|
143
|
-
tiff: "image/tiff",
|
|
144
|
-
txt: "text/plain",
|
|
145
|
-
wav: "audio/wav",
|
|
146
|
-
webm: "video/webm",
|
|
147
|
-
webp: "image/webp",
|
|
148
|
-
}));
|
|
149
|
-
return map.get(ext) ?? "application/octet-stream";
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Probe a path the user explicitly asked us to read (e.g.
|
|
153
|
-
* `vg generate upload <path>`). Skips the path-shape heuristic so a bare
|
|
154
|
-
* filename with a non-media extension — `model.glb`, `scene.fbx`,
|
|
155
|
-
* `data.ply`, even `LICENSE` — still works.
|
|
156
|
-
*/
|
|
157
|
-
export const readExplicitLocalFile = (value) => {
|
|
158
|
-
if (value.startsWith("http://") || value.startsWith("https://")) {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
if (value.startsWith("data:")) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
if (value.length === 0) {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
const expanded = expandHome(value);
|
|
168
|
-
const abs = path.isAbsolute(expanded) ? expanded : path.resolve(expanded);
|
|
169
|
-
let stat;
|
|
170
|
-
try {
|
|
171
|
-
stat = statSync(abs);
|
|
172
|
-
}
|
|
173
|
-
catch {
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
if (!stat.isFile()) {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
contentType: contentTypeForPath(abs),
|
|
181
|
-
filename: path.basename(abs),
|
|
182
|
-
path: abs,
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
export const parseDownloadFlag = (argv) => {
|
|
186
|
-
let lastIdx = -1;
|
|
187
|
-
let inlineValue;
|
|
188
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
189
|
-
const arg = argv[i];
|
|
190
|
-
if (!arg) {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
if (arg === "--") {
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
if (arg === "--download") {
|
|
197
|
-
lastIdx = i;
|
|
198
|
-
inlineValue = undefined;
|
|
199
|
-
}
|
|
200
|
-
else if (arg.startsWith("--download=")) {
|
|
201
|
-
lastIdx = i;
|
|
202
|
-
inlineValue = arg.slice("--download=".length);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (lastIdx === -1) {
|
|
206
|
-
return { mode: "off" };
|
|
207
|
-
}
|
|
208
|
-
const candidate = inlineValue ?? argv[lastIdx + 1];
|
|
209
|
-
if (candidate === "false") {
|
|
210
|
-
return { mode: "off" };
|
|
211
|
-
}
|
|
212
|
-
if (candidate === undefined ||
|
|
213
|
-
candidate === "" ||
|
|
214
|
-
candidate.startsWith("--") ||
|
|
215
|
-
candidate === "true") {
|
|
216
|
-
return { mode: "on" };
|
|
217
|
-
}
|
|
218
|
-
return { mode: "on", template: candidate };
|
|
219
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { JsonValue } from "./types.js";
|
|
2
|
-
interface MediaRef {
|
|
3
|
-
url: string;
|
|
4
|
-
filename: string;
|
|
5
|
-
contentType: string | null;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Walk a fal result payload and pull out anything that looks like a media
|
|
9
|
-
* output. fal endpoints embed outputs in objects shaped like
|
|
10
|
-
* `{ url, content_type, file_name, ... }`; we accept image/video/audio
|
|
11
|
-
* content types and also fall back to URL extension when content_type is
|
|
12
|
-
* absent (some endpoints omit it).
|
|
13
|
-
*/
|
|
14
|
-
export declare const extractMediaRefs: (result: JsonValue) => MediaRef[];
|
|
15
|
-
interface DownloadResult {
|
|
16
|
-
downloaded: string[];
|
|
17
|
-
failed: {
|
|
18
|
-
url: string;
|
|
19
|
-
error: string;
|
|
20
|
-
}[];
|
|
21
|
-
mislabeled: {
|
|
22
|
-
path: string;
|
|
23
|
-
actual: string;
|
|
24
|
-
}[];
|
|
25
|
-
}
|
|
26
|
-
export declare const disambiguateTargets: (paths: string[]) => string[];
|
|
27
|
-
/**
|
|
28
|
-
* Download all extracted media refs to disk, materializing the path from
|
|
29
|
-
* a template. Supported placeholders: {index}, {name}, {ext}, {request_id}.
|
|
30
|
-
* Falls back to the source filename in the cwd when no template is given.
|
|
31
|
-
*/
|
|
32
|
-
export declare const downloadMedia: (opts: {
|
|
33
|
-
refs: MediaRef[];
|
|
34
|
-
template?: string;
|
|
35
|
-
requestId: string;
|
|
36
|
-
}) => Promise<DownloadResult>;
|
|
37
|
-
export {};
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { isJsonObject, isJsonString } from "./types.js";
|
|
4
|
-
// Lowercase file extensions we recognize as media when sniffing fal
|
|
5
|
-
// response payloads where `content_type` is missing (some endpoints
|
|
6
|
-
// omit it).
|
|
7
|
-
const MEDIA_EXT = new Set([
|
|
8
|
-
"png",
|
|
9
|
-
"jpg",
|
|
10
|
-
"jpeg",
|
|
11
|
-
"webp",
|
|
12
|
-
"gif",
|
|
13
|
-
"bmp",
|
|
14
|
-
"tif",
|
|
15
|
-
"tiff",
|
|
16
|
-
"avif",
|
|
17
|
-
"mp4",
|
|
18
|
-
"mov",
|
|
19
|
-
"webm",
|
|
20
|
-
"mp3",
|
|
21
|
-
"wav",
|
|
22
|
-
"ogg",
|
|
23
|
-
"flac",
|
|
24
|
-
"m4a",
|
|
25
|
-
]);
|
|
26
|
-
const TRUSTED_HOST_SUFFIXES = [".fal.media", ".fal.run", ".fal.ai"];
|
|
27
|
-
const TRUSTED_HOSTS = new Set(["fal.media", "fal.run", "fal.ai"]);
|
|
28
|
-
const isTrustedFalContentHost = (url) => {
|
|
29
|
-
let parsed;
|
|
30
|
-
try {
|
|
31
|
-
parsed = new URL(url);
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
if (parsed.protocol !== "https:") {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
const host = parsed.hostname.toLowerCase();
|
|
40
|
-
if (TRUSTED_HOSTS.has(host)) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
return TRUSTED_HOST_SUFFIXES.some((suffix) => host.endsWith(suffix));
|
|
44
|
-
};
|
|
45
|
-
const extFromUrl = (url) => {
|
|
46
|
-
try {
|
|
47
|
-
const { pathname } = new URL(url);
|
|
48
|
-
const dot = pathname.lastIndexOf(".");
|
|
49
|
-
return dot === -1 ? "" : pathname.slice(dot + 1).toLowerCase();
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
return "";
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
// Strip any directory components from a fal-provided file_name so a
|
|
56
|
-
// malicious response can't traverse out of the download target dir.
|
|
57
|
-
// Handle both POSIX and Windows separators regardless of host OS so a
|
|
58
|
-
// `..\\..\\evil` payload sent to a Linux client is still flattened.
|
|
59
|
-
const sanitizeFilename = (name) => {
|
|
60
|
-
const base = name
|
|
61
|
-
.replaceAll(/[\\/]+/gu, "/")
|
|
62
|
-
.split("/")
|
|
63
|
-
.pop() ?? "";
|
|
64
|
-
if (!base || base === "." || base === "..") {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
return base;
|
|
68
|
-
};
|
|
69
|
-
const visit = (value, refs, seen) => {
|
|
70
|
-
if (Array.isArray(value)) {
|
|
71
|
-
for (const v of value) {
|
|
72
|
-
visit(v, refs, seen);
|
|
73
|
-
}
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (!isJsonObject(value)) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const { url } = value;
|
|
80
|
-
if (isJsonString(url) && isTrustedFalContentHost(url) && !seen.has(url)) {
|
|
81
|
-
const contentType = isJsonString(value.content_type) ? value.content_type.toLowerCase() : null;
|
|
82
|
-
const filenameField = isJsonString(value.file_name) ? sanitizeFilename(value.file_name) : null;
|
|
83
|
-
const ext = filenameField
|
|
84
|
-
? path.extname(filenameField).slice(1).toLowerCase()
|
|
85
|
-
: extFromUrl(url);
|
|
86
|
-
const looksMedia = contentType === null ? MEDIA_EXT.has(ext) : /^(?:image|video|audio)\//u.test(contentType);
|
|
87
|
-
if (looksMedia) {
|
|
88
|
-
seen.add(url);
|
|
89
|
-
refs.push({
|
|
90
|
-
contentType,
|
|
91
|
-
filename: filenameField ?? `output${ext ? `.${ext}` : ""}`,
|
|
92
|
-
url,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
for (const child of Object.values(value)) {
|
|
97
|
-
visit(child, refs, seen);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* Walk a fal result payload and pull out anything that looks like a media
|
|
102
|
-
* output. fal endpoints embed outputs in objects shaped like
|
|
103
|
-
* `{ url, content_type, file_name, ... }`; we accept image/video/audio
|
|
104
|
-
* content types and also fall back to URL extension when content_type is
|
|
105
|
-
* absent (some endpoints omit it).
|
|
106
|
-
*/
|
|
107
|
-
export const extractMediaRefs = (result) => {
|
|
108
|
-
const seen = new Set();
|
|
109
|
-
const refs = [];
|
|
110
|
-
visit(result, refs, seen);
|
|
111
|
-
return refs;
|
|
112
|
-
};
|
|
113
|
-
// The extension each content type genuinely is. Only formats an agent is
|
|
114
|
-
// likely to hand to a decoder afterwards need an entry; anything absent is
|
|
115
|
-
// left alone rather than guessed at.
|
|
116
|
-
const EXT_FOR_CONTENT_TYPE = new Map(Object.entries({
|
|
117
|
-
"audio/mpeg": "mp3",
|
|
118
|
-
"audio/ogg": "ogg",
|
|
119
|
-
"audio/wav": "wav",
|
|
120
|
-
"image/avif": "avif",
|
|
121
|
-
"image/gif": "gif",
|
|
122
|
-
"image/jpeg": "jpg",
|
|
123
|
-
"image/png": "png",
|
|
124
|
-
"image/webp": "webp",
|
|
125
|
-
"video/mp4": "mp4",
|
|
126
|
-
"video/quicktime": "mov",
|
|
127
|
-
"video/webm": "webm",
|
|
128
|
-
}));
|
|
129
|
-
// Extensions that name the same format, so `.jpg` for `image/jpeg` is not a lie.
|
|
130
|
-
const EXT_ALIASES = new Map(Object.entries({
|
|
131
|
-
htm: "html",
|
|
132
|
-
jpeg: "jpg",
|
|
133
|
-
tif: "tiff",
|
|
134
|
-
}));
|
|
135
|
-
const canonicalExt = (ext) => EXT_ALIASES.get(ext) ?? ext;
|
|
136
|
-
/**
|
|
137
|
-
* The extension the caller asked for versus the bytes actually served.
|
|
138
|
-
*
|
|
139
|
-
* `--download board.png` is honoured literally — renaming the path the caller
|
|
140
|
-
* chose would break whatever they wired it into — so when a model returns JPEG
|
|
141
|
-
* the file is a `.png` holding JPEG bytes. Downstream decoders reject it with
|
|
142
|
-
* "bad signature" and nothing points back here, hence the explicit report.
|
|
143
|
-
*/
|
|
144
|
-
const mislabelOf = (target, ref) => {
|
|
145
|
-
const asked = canonicalExt(path.extname(target).slice(1).toLowerCase());
|
|
146
|
-
if (!asked) {
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
const actual = ref.contentType ? EXT_FOR_CONTENT_TYPE.get(ref.contentType) : undefined;
|
|
150
|
-
if (!actual || canonicalExt(actual) === asked) {
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
return { actual, path: target };
|
|
154
|
-
};
|
|
155
|
-
// Exported so the codex provider (lib/codex.ts) reuses identical
|
|
156
|
-
// `_1`/`_2` collision-suffix behavior when placing its local outputs.
|
|
157
|
-
export const disambiguateTargets = (paths) => {
|
|
158
|
-
const counts = new Map();
|
|
159
|
-
for (const p of paths) {
|
|
160
|
-
counts.set(p, (counts.get(p) ?? 0) + 1);
|
|
161
|
-
}
|
|
162
|
-
const seen = new Map();
|
|
163
|
-
return paths.map((p) => {
|
|
164
|
-
if ((counts.get(p) ?? 0) <= 1) {
|
|
165
|
-
return p;
|
|
166
|
-
}
|
|
167
|
-
const n = seen.get(p) ?? 0;
|
|
168
|
-
seen.set(p, n + 1);
|
|
169
|
-
if (n === 0) {
|
|
170
|
-
return p;
|
|
171
|
-
}
|
|
172
|
-
const ext = path.extname(p);
|
|
173
|
-
return `${p.slice(0, p.length - ext.length)}_${n}${ext}`;
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
const renderTemplate = (ref, template, index, requestId) => {
|
|
177
|
-
const ext = (() => {
|
|
178
|
-
const fromName = path.extname(ref.filename).slice(1);
|
|
179
|
-
if (fromName) {
|
|
180
|
-
return fromName;
|
|
181
|
-
}
|
|
182
|
-
return extFromUrl(ref.url) || "bin";
|
|
183
|
-
})();
|
|
184
|
-
// String-based stem extraction: a dynamic RegExp built from `ext`
|
|
185
|
-
// would treat any regex metachars in an unusual fal `file_name`
|
|
186
|
-
// (`.`, `+`, `*`) as patterns, potentially stripping the wrong
|
|
187
|
-
// suffix. Plain endsWith is exact and case-insensitive via toLowerCase.
|
|
188
|
-
const lowerName = ref.filename.toLowerCase();
|
|
189
|
-
const dotExt = `.${ext.toLowerCase()}`;
|
|
190
|
-
const stem = lowerName.endsWith(dotExt)
|
|
191
|
-
? ref.filename.slice(0, -dotExt.length) || "output"
|
|
192
|
-
: ref.filename || "output";
|
|
193
|
-
// No template or no placeholder → caller meant either a destination
|
|
194
|
-
// directory (omitted, ".", "./", "../out", "out/") or an explicit
|
|
195
|
-
// output filename (`./out.png`, `frame.mp4`). We disambiguate by
|
|
196
|
-
// looking for an extension on the basename — anything with one is
|
|
197
|
-
// treated as the literal output path; otherwise we resolve into the
|
|
198
|
-
// directory using the ref's filename. The previous all-as-dir
|
|
199
|
-
// behavior wrote `./walk.png/output.png` for `--download ./walk.png`.
|
|
200
|
-
if (!template || !template.includes("{")) {
|
|
201
|
-
if (template && path.extname(template)) {
|
|
202
|
-
return path.resolve(template);
|
|
203
|
-
}
|
|
204
|
-
const dir = template ?? process.cwd();
|
|
205
|
-
return path.resolve(dir, ref.filename || `output-${index}.${ext}`);
|
|
206
|
-
}
|
|
207
|
-
const rendered = template
|
|
208
|
-
.replaceAll("{index}", String(index))
|
|
209
|
-
.replaceAll("{name}", stem)
|
|
210
|
-
.replaceAll("{ext}", ext)
|
|
211
|
-
.replaceAll("{request_id}", requestId);
|
|
212
|
-
return path.resolve(rendered);
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* Download all extracted media refs to disk, materializing the path from
|
|
216
|
-
* a template. Supported placeholders: {index}, {name}, {ext}, {request_id}.
|
|
217
|
-
* Falls back to the source filename in the cwd when no template is given.
|
|
218
|
-
*/
|
|
219
|
-
export const downloadMedia = async (opts) => {
|
|
220
|
-
const initial = opts.refs.map((ref, i) => renderTemplate(ref, opts.template, i, opts.requestId));
|
|
221
|
-
// Disambiguate any colliding resolved paths so multi-output runs (e.g.
|
|
222
|
-
// `--num_images 3` where fal returns the same default `file_name` for
|
|
223
|
-
// every output) don't silently overwrite each other on disk. The first
|
|
224
|
-
// occurrence keeps the original name; subsequent collisions get a
|
|
225
|
-
// `_1`, `_2`, … suffix inserted before the extension.
|
|
226
|
-
const targets = disambiguateTargets(initial);
|
|
227
|
-
// Create each unique parent directory once instead of redoing it per ref.
|
|
228
|
-
const dirs = new Set(targets.map((t) => path.dirname(t)));
|
|
229
|
-
for (const d of dirs) {
|
|
230
|
-
mkdirSync(d, { recursive: true });
|
|
231
|
-
}
|
|
232
|
-
const outcomes = await Promise.all(opts.refs.map(async (ref, i) => {
|
|
233
|
-
const target = targets[i];
|
|
234
|
-
if (target === undefined) {
|
|
235
|
-
return { error: "no download target", ok: false, url: ref.url };
|
|
236
|
-
}
|
|
237
|
-
try {
|
|
238
|
-
const res = await fetch(ref.url);
|
|
239
|
-
if (!res.ok) {
|
|
240
|
-
return { error: `${res.status} ${res.statusText}`, ok: false, url: ref.url };
|
|
241
|
-
}
|
|
242
|
-
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
243
|
-
writeFileSync(target, bytes);
|
|
244
|
-
return { mislabel: mislabelOf(target, ref), ok: true, target };
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
return {
|
|
248
|
-
error: error instanceof Error ? error.message : String(error),
|
|
249
|
-
ok: false,
|
|
250
|
-
url: ref.url,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
}));
|
|
254
|
-
const downloaded = [];
|
|
255
|
-
const failed = [];
|
|
256
|
-
const mislabeled = [];
|
|
257
|
-
for (const o of outcomes) {
|
|
258
|
-
if (!o.ok) {
|
|
259
|
-
failed.push({ error: o.error, url: o.url });
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
downloaded.push(o.target);
|
|
263
|
-
if (o.mislabel) {
|
|
264
|
-
mislabeled.push(o.mislabel);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return { downloaded, failed, mislabeled };
|
|
268
|
-
};
|
package/dist/lib/media-poll.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { createClient } from "./api.js";
|
|
2
|
-
import type { JsonValue } from "./types.js";
|
|
3
|
-
type Client = ReturnType<typeof createClient>;
|
|
4
|
-
export declare const endpointPath: (endpointId: string) => string;
|
|
5
|
-
export declare const queueAppId: (endpointId: string) => string;
|
|
6
|
-
interface CompletedResult {
|
|
7
|
-
request_id: string;
|
|
8
|
-
result: JsonValue;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Poll fal's queue from the client side until the job reaches a
|
|
12
|
-
* terminal status, then fetch the result. The Worker isn't in the
|
|
13
|
-
* loop — it's only along for each individual `generate.forward` hop.
|
|
14
|
-
*/
|
|
15
|
-
export declare const waitForCompletion: (client: Client, endpoint_id: string, request_id: string, opts: {
|
|
16
|
-
quiet: boolean;
|
|
17
|
-
}) => Promise<CompletedResult>;
|
|
18
|
-
export {};
|
package/dist/lib/media-poll.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
|
-
import { consola } from "consola";
|
|
3
|
-
import { forwardJson } from "./api.js";
|
|
4
|
-
import { isJsonNumber, isJsonObject, isJsonString } from "./types.js";
|
|
5
|
-
// Strip leading/trailing slashes from a fal endpoint id so it can be
|
|
6
|
-
// spliced into a URL path without doubling separators.
|
|
7
|
-
export const endpointPath = (endpointId) => endpointId.replaceAll(/^\/+|\/+$/gu, "");
|
|
8
|
-
// fal's queue accepts the full endpoint id (including any model subpath,
|
|
9
|
-
// e.g. `fal-ai/flux/schnell`) on submit, but the status/result/cancel
|
|
10
|
-
// routes are keyed by the owning *application* id only (`fal-ai/flux`).
|
|
11
|
-
// Passing the subpath to those routes returns 405. `workflows`/`comfy`
|
|
12
|
-
// ids carry the namespace as a leading segment, so their app id is three
|
|
13
|
-
// segments deep.
|
|
14
|
-
const QUEUE_APP_NAMESPACES = new Set(["workflows", "comfy"]);
|
|
15
|
-
export const queueAppId = (endpointId) => {
|
|
16
|
-
const parts = endpointPath(endpointId).split("/").filter(Boolean);
|
|
17
|
-
const take = QUEUE_APP_NAMESPACES.has(parts[0] ?? "") ? 3 : 2;
|
|
18
|
-
return parts.slice(0, take).join("/");
|
|
19
|
-
};
|
|
20
|
-
const POLL_INTERVAL_MS = 2000;
|
|
21
|
-
// 30-minute ceiling on a sync run. Generous (this is the user's local
|
|
22
|
-
// CLI process, not a billed Worker) but bounded so a stuck IN_QUEUE
|
|
23
|
-
// job can't hang the CLI indefinitely. Long jobs should use --async.
|
|
24
|
-
const POLL_TIMEOUT_MS = 30 * 60 * 1000;
|
|
25
|
-
const pickErrorReason = (value) => {
|
|
26
|
-
if (!isJsonObject(value)) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
if (isJsonString(value.error) && value.error.length > 0) {
|
|
30
|
-
return value.error;
|
|
31
|
-
}
|
|
32
|
-
if (isJsonString(value.detail) && value.detail.length > 0) {
|
|
33
|
-
return value.detail;
|
|
34
|
-
}
|
|
35
|
-
if (isJsonObject(value.error) && isJsonString(value.error.message)) {
|
|
36
|
-
return value.error.message;
|
|
37
|
-
}
|
|
38
|
-
if (isJsonObject(value.response)) {
|
|
39
|
-
return pickErrorReason(value.response);
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Poll fal's queue from the client side until the job reaches a
|
|
45
|
-
* terminal status, then fetch the result. The Worker isn't in the
|
|
46
|
-
* loop — it's only along for each individual `generate.forward` hop.
|
|
47
|
-
*/
|
|
48
|
-
export const waitForCompletion = async (client, endpoint_id, request_id, opts) => {
|
|
49
|
-
const ep = queueAppId(endpoint_id);
|
|
50
|
-
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
51
|
-
let lastStatus;
|
|
52
|
-
while (true) {
|
|
53
|
-
if (Date.now() > deadline) {
|
|
54
|
-
throw new Error(`Job did not complete within ${POLL_TIMEOUT_MS}ms ` +
|
|
55
|
-
`(endpoint=${endpoint_id} request_id=${request_id}). ` +
|
|
56
|
-
`Use \`vg generate status ${endpoint_id} ${request_id} --result\` to check later.`);
|
|
57
|
-
}
|
|
58
|
-
const raw = await forwardJson(client, {
|
|
59
|
-
method: "GET",
|
|
60
|
-
path: `/${ep}/requests/${request_id}/status`,
|
|
61
|
-
target: "queue",
|
|
62
|
-
});
|
|
63
|
-
const status = isJsonObject(raw) && isJsonString(raw.status) ? raw.status : "UNKNOWN";
|
|
64
|
-
const upper = status.toUpperCase();
|
|
65
|
-
if (!opts.quiet && upper !== lastStatus) {
|
|
66
|
-
lastStatus = upper;
|
|
67
|
-
const queuePos = isJsonObject(raw) && isJsonNumber(raw.queue_position) ? raw.queue_position : null;
|
|
68
|
-
const tag = queuePos === null ? upper.toLowerCase() : `${upper.toLowerCase()} (queue ${queuePos})`;
|
|
69
|
-
consola.log(` ${tag}`);
|
|
70
|
-
}
|
|
71
|
-
if (upper === "COMPLETED") {
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
if (upper === "FAILED" || upper === "CANCELLED") {
|
|
75
|
-
const reason = pickErrorReason(raw);
|
|
76
|
-
throw new Error(reason ? `Job ${upper.toLowerCase()}: ${reason}` : `Job ${upper.toLowerCase()}`);
|
|
77
|
-
}
|
|
78
|
-
await sleep(POLL_INTERVAL_MS);
|
|
79
|
-
}
|
|
80
|
-
const result = await forwardJson(client, {
|
|
81
|
-
method: "GET",
|
|
82
|
-
path: `/${ep}/requests/${request_id}`,
|
|
83
|
-
target: "queue",
|
|
84
|
-
});
|
|
85
|
-
return { request_id, result };
|
|
86
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { createClient } from "./api.js";
|
|
2
|
-
import type { LocalFile } from "./media-args.js";
|
|
3
|
-
type Client = ReturnType<typeof createClient>;
|
|
4
|
-
/**
|
|
5
|
-
* Upload one local file directly to fal's CDN. The proxy hands us a
|
|
6
|
-
* presigned upload slot (upload_url + file_url) via the `generate.forward`
|
|
7
|
-
* storage target; bytes go straight from the client to fal, never
|
|
8
|
-
* through the worker. The returned file_url is a stable fal CDN URL
|
|
9
|
-
* that can be reused across runs without re-uploading.
|
|
10
|
-
*/
|
|
11
|
-
export declare const uploadFile: (client: Client, file: LocalFile) => Promise<string>;
|
|
12
|
-
export {};
|