vibedgames 0.6.3 → 0.8.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-2QBYTIMH.js +511 -0
- package/dist/chunk-6FZPPUQH.js +107 -0
- package/dist/chunk-AZGENOOR.js +22 -0
- package/dist/chunk-CAKBGDCY.js +47 -0
- package/dist/chunk-CU7UY5YJ.js +1108 -0
- package/dist/chunk-CZPKN32Z.js +257 -0
- package/dist/chunk-FL6IFBUF.js +22 -0
- package/dist/chunk-FNYBZNW2.js +165 -0
- package/dist/chunk-GUF6ADBF.js +273 -0
- package/dist/chunk-H4NBRFBY.js +79 -0
- package/dist/chunk-HASKWB6B.js +111 -0
- package/dist/chunk-I6O4HIDY.js +1063 -0
- package/dist/chunk-IO6OM6WM.js +466 -0
- package/dist/chunk-J6PKNPI2.js +26 -0
- package/dist/chunk-JT2AU24K.js +759 -0
- package/dist/chunk-K5SC6SXO.js +172 -0
- package/dist/chunk-MBXCVCC4.js +478 -0
- package/dist/chunk-PEUP4MZR.js +59 -0
- package/dist/chunk-PQDBCZRT.js +2017 -0
- package/dist/chunk-RIGKOLNN.js +1360 -0
- package/dist/chunk-RNBUX5VF.js +68 -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-TMK6V5FV.js +395 -0
- package/dist/chunk-TYVYWBY6.js +69 -0
- package/dist/chunk-VFFOT7KD.js +2980 -0
- package/dist/chunk-W5XP4ZVU.js +159 -0
- package/dist/chunk-X4ZABSCN.js +415 -0
- package/dist/chunk-XDC7QGOF.js +32 -0
- package/dist/chunk-XK5RZQMX.js +1780 -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/codex.js
DELETED
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
import { randomBytes } from "node:crypto";
|
|
2
|
-
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, statSync } from "node:fs";
|
|
3
|
-
import { homedir, tmpdir } from "node:os";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import spawn from "cross-spawn";
|
|
6
|
-
import { readExplicitLocalFile } from "./media-args.js";
|
|
7
|
-
import { disambiguateTargets } from "./media-download.js";
|
|
8
|
-
import { isJsonNumber, isJsonString } from "./types.js";
|
|
9
|
-
/**
|
|
10
|
-
* Expected, user-facing failure of the codex provider. Carries a clean
|
|
11
|
-
* message plus any output Codex itself emitted, so the caller can present
|
|
12
|
-
* it directly instead of dumping a stack trace. `notInstalled` flags the
|
|
13
|
-
* "`codex` binary missing" case so callers can suggest a fallback.
|
|
14
|
-
*/
|
|
15
|
-
export class CodexError extends Error {
|
|
16
|
-
notInstalled;
|
|
17
|
-
output;
|
|
18
|
-
constructor(message, opts = {}) {
|
|
19
|
-
super(message);
|
|
20
|
-
this.name = "CodexError";
|
|
21
|
-
this.notInstalled = opts.notInstalled ?? false;
|
|
22
|
-
this.output = opts.output ?? "";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Resolve an explicitly named provider from the `--provider` flag, falling
|
|
27
|
-
* back to the `VG_GENERATE_PROVIDER` env var and finally the vibedgames
|
|
28
|
-
* default. Unknown values throw so a typo (`--provider coddex`) fails
|
|
29
|
-
* loudly instead of silently hitting the paid backend. `chooseProvider`
|
|
30
|
-
* layers the automatic Codex routing on top of this.
|
|
31
|
-
*/
|
|
32
|
-
export const resolveProvider = (flag) => {
|
|
33
|
-
const raw = (flag ?? process.env.VG_GENERATE_PROVIDER ?? "").trim().toLowerCase();
|
|
34
|
-
if (raw === "codex") {
|
|
35
|
-
return "codex";
|
|
36
|
-
}
|
|
37
|
-
if (raw === "" || raw === "vibedgames" || raw === "fal" || raw === "default") {
|
|
38
|
-
return "vibedgames";
|
|
39
|
-
}
|
|
40
|
-
throw new Error(`Unknown --provider "${raw}". Supported: vibedgames (default), codex.`);
|
|
41
|
-
};
|
|
42
|
-
/** The OpenAI image family — the models a signed-in Codex plan serves itself. */
|
|
43
|
-
export const isOpenAiImageEndpoint = (endpointId) => endpointId === "codex" || /^openai\/gpt-image/iu.test(endpointId);
|
|
44
|
-
/**
|
|
45
|
-
* The `codex` binary this machine would run: `VG_CODEX_BIN` when set (and
|
|
46
|
-
* present), else the first `codex` on PATH. Null when there is none — the
|
|
47
|
-
* signal that keeps automatic routing on the vibedgames runner.
|
|
48
|
-
*/
|
|
49
|
-
export const findCodexBinary = (env = process.env) => {
|
|
50
|
-
const pinned = env.VG_CODEX_BIN;
|
|
51
|
-
if (pinned) {
|
|
52
|
-
return existsSync(pinned) ? pinned : null;
|
|
53
|
-
}
|
|
54
|
-
for (const dir of (env.PATH ?? "").split(path.delimiter)) {
|
|
55
|
-
if (!dir) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
for (const name of ["codex", "codex.cmd"]) {
|
|
59
|
-
const candidate = path.join(dir, name);
|
|
60
|
-
try {
|
|
61
|
-
if (statSync(candidate).isFile()) {
|
|
62
|
-
return candidate;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
// not here; keep walking PATH
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
};
|
|
72
|
-
// Input keys we map onto Codex's natural-language image request. Codex
|
|
73
|
-
// only exposes a single built-in image model, so most fal-style params
|
|
74
|
-
// don't apply — we fold the few that have a meaning (prompt, count,
|
|
75
|
-
// size, reference images) into the prompt / CLI flags and ignore the
|
|
76
|
-
// rest rather than erroring.
|
|
77
|
-
const PROMPT_KEYS = ["prompt", "text"];
|
|
78
|
-
const COUNT_KEYS = ["num_images", "num_outputs", "n", "count"];
|
|
79
|
-
const REF_KEYS = [
|
|
80
|
-
"image_url",
|
|
81
|
-
"image_urls",
|
|
82
|
-
"image",
|
|
83
|
-
"images",
|
|
84
|
-
"input_image",
|
|
85
|
-
"reference_image_url",
|
|
86
|
-
"reference_image_urls",
|
|
87
|
-
];
|
|
88
|
-
const MAX_IMAGES = 8;
|
|
89
|
-
const IMAGE_EXT = new Set(["png", "jpg", "jpeg", "webp", "gif"]);
|
|
90
|
-
const buildSizeHint = (input) => {
|
|
91
|
-
const parts = [];
|
|
92
|
-
const size = input.image_size ?? input.size;
|
|
93
|
-
if (isJsonString(size) && size.trim().length > 0) {
|
|
94
|
-
parts.push(size.trim());
|
|
95
|
-
}
|
|
96
|
-
const aspect = input.aspect_ratio;
|
|
97
|
-
if (isJsonString(aspect) && aspect.trim().length > 0) {
|
|
98
|
-
parts.push(`aspect ratio ${aspect.trim()}`);
|
|
99
|
-
}
|
|
100
|
-
const w = input.width;
|
|
101
|
-
const h = input.height;
|
|
102
|
-
if (isJsonNumber(w) && isJsonNumber(h)) {
|
|
103
|
-
parts.push(`${w}x${h}px`);
|
|
104
|
-
}
|
|
105
|
-
return parts.length > 0 ? parts.join(", ") : undefined;
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Pull the fields Codex can act on out of the parsed `run` input. Pure:
|
|
109
|
-
* no filesystem access, so the reference values are returned verbatim and
|
|
110
|
-
* resolved to local files later.
|
|
111
|
-
*/
|
|
112
|
-
export const parseCodexInput = (input) => {
|
|
113
|
-
let prompt = "";
|
|
114
|
-
for (const key of PROMPT_KEYS) {
|
|
115
|
-
const v = input[key];
|
|
116
|
-
if (isJsonString(v) && v.trim().length > 0) {
|
|
117
|
-
prompt = v.trim();
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
let count = 1;
|
|
122
|
-
for (const key of COUNT_KEYS) {
|
|
123
|
-
const v = input[key];
|
|
124
|
-
if (isJsonNumber(v)) {
|
|
125
|
-
count = Math.max(1, Math.min(MAX_IMAGES, Math.floor(v)));
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const referenceCandidates = [];
|
|
130
|
-
for (const key of REF_KEYS) {
|
|
131
|
-
const v = input[key];
|
|
132
|
-
if (isJsonString(v)) {
|
|
133
|
-
referenceCandidates.push(v);
|
|
134
|
-
}
|
|
135
|
-
else if (Array.isArray(v)) {
|
|
136
|
-
for (const item of v) {
|
|
137
|
-
if (isJsonString(item)) {
|
|
138
|
-
referenceCandidates.push(item);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return { count, prompt, referenceCandidates, sizeHint: buildSizeHint(input) };
|
|
144
|
-
};
|
|
145
|
-
const isLocalReference = (ref) => !/^(?:https?:|data:)/iu.test(ref);
|
|
146
|
-
/**
|
|
147
|
-
* Pick the backend for one `run`. An explicit `--provider` or
|
|
148
|
-
* `VG_GENERATE_PROVIDER` always wins. Left unset, an OpenAI image endpoint
|
|
149
|
-
* goes to a locally installed Codex CLI — the same model family on the
|
|
150
|
-
* user's own plan, nothing billed to vibedgames — whenever Codex can honour
|
|
151
|
-
* the request (synchronous, local references only). Everything else stays
|
|
152
|
-
* on the vibedgames runner, so video/audio and non-OpenAI image models are
|
|
153
|
-
* unaffected by having Codex installed.
|
|
154
|
-
*/
|
|
155
|
-
export const chooseProvider = (flag, ctx) => {
|
|
156
|
-
const named = (flag ?? process.env.VG_GENERATE_PROVIDER ?? "").trim();
|
|
157
|
-
if (named !== "") {
|
|
158
|
-
return { auto: false, provider: resolveProvider(named) };
|
|
159
|
-
}
|
|
160
|
-
const refs = parseCodexInput(ctx.input).referenceCandidates;
|
|
161
|
-
const eligible = ctx.codexInstalled &&
|
|
162
|
-
!ctx.async &&
|
|
163
|
-
isOpenAiImageEndpoint(ctx.endpointId) &&
|
|
164
|
-
refs.every((ref) => isLocalReference(ref));
|
|
165
|
-
return { auto: eligible, provider: eligible ? "codex" : "vibedgames" };
|
|
166
|
-
};
|
|
167
|
-
/**
|
|
168
|
-
* Build the natural-language instruction handed to `codex exec`. We pin
|
|
169
|
-
* exact output filenames and the working directory so the generated
|
|
170
|
-
* files land somewhere we can deterministically collect them.
|
|
171
|
-
*/
|
|
172
|
-
export const buildCodexPrompt = (input, filenames, hasReferences) => {
|
|
173
|
-
const n = filenames.length;
|
|
174
|
-
const noun = n === 1 ? "image" : `${n} images`;
|
|
175
|
-
const lines = [
|
|
176
|
-
hasReferences
|
|
177
|
-
? `Edit the attached reference image to produce ${noun} using your built-in image generation.`
|
|
178
|
-
: `Generate ${noun} using your built-in image generation.`,
|
|
179
|
-
`Prompt: ${input.prompt}`,
|
|
180
|
-
];
|
|
181
|
-
if (input.sizeHint) {
|
|
182
|
-
// A target, not a contract: the generator picks from a few fixed sizes, and
|
|
183
|
-
// asked for an exact one Codex stops to request permission to resize —
|
|
184
|
-
// which the no-code rule below forbids, so the run ends with no file.
|
|
185
|
-
lines.push(`Size: aim for ${input.sizeHint}. Use the closest size the generator offers and save that as-is — never resize, crop or ask about it.`);
|
|
186
|
-
}
|
|
187
|
-
lines.push(`Save the output as PNG into the current working directory using exactly ` +
|
|
188
|
-
`these filenames: ${filenames.join(", ")}.`, `Do not read, create, or modify any other files, and do not write or run code. $imagegen`);
|
|
189
|
-
return lines.join("\n");
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Choose the on-disk destination for a collected Codex output, mirroring
|
|
193
|
-
* the `--download` template semantics used for the vibedgames path
|
|
194
|
-
* ({index}, {ext}, {request_id} placeholders; bare path treated as a
|
|
195
|
-
* directory or a literal file by extension).
|
|
196
|
-
*/
|
|
197
|
-
export const renderLocalTarget = (template, index, ext, requestId, count) => {
|
|
198
|
-
if (!template) {
|
|
199
|
-
return path.resolve(process.cwd(), `codex-image-${requestId}-${index}.${ext}`);
|
|
200
|
-
}
|
|
201
|
-
if (template.includes("{")) {
|
|
202
|
-
const rendered = template
|
|
203
|
-
.replaceAll("{index}", String(index))
|
|
204
|
-
.replaceAll("{ext}", ext)
|
|
205
|
-
.replaceAll("{request_id}", requestId)
|
|
206
|
-
.replaceAll("{name}", "output");
|
|
207
|
-
return path.resolve(rendered);
|
|
208
|
-
}
|
|
209
|
-
if (path.extname(template)) {
|
|
210
|
-
if (count <= 1) {
|
|
211
|
-
return path.resolve(template);
|
|
212
|
-
}
|
|
213
|
-
const e = path.extname(template);
|
|
214
|
-
const stem = template.slice(0, template.length - e.length);
|
|
215
|
-
return path.resolve(index === 0 ? template : `${stem}_${index}${e}`);
|
|
216
|
-
}
|
|
217
|
-
return path.resolve(template, `codex-image-${index}.${ext}`);
|
|
218
|
-
};
|
|
219
|
-
const codexHome = () => process.env.CODEX_HOME ?? path.join(homedir(), ".codex");
|
|
220
|
-
/**
|
|
221
|
-
* Image files under `dir`, one level of subdirectories included: Codex files
|
|
222
|
-
* its generated images per session (`generated_images/<session>/<id>.png`),
|
|
223
|
-
* so a flat listing of the store never sees them.
|
|
224
|
-
*/
|
|
225
|
-
const listImages = (dir, depth = 1) => {
|
|
226
|
-
let entries;
|
|
227
|
-
try {
|
|
228
|
-
entries = readdirSync(dir, { withFileTypes: true });
|
|
229
|
-
}
|
|
230
|
-
catch {
|
|
231
|
-
return [];
|
|
232
|
-
}
|
|
233
|
-
const out = [];
|
|
234
|
-
for (const entry of entries) {
|
|
235
|
-
const full = path.join(dir, entry.name);
|
|
236
|
-
if (entry.isDirectory()) {
|
|
237
|
-
if (depth > 0) {
|
|
238
|
-
out.push(...listImages(full, depth - 1));
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else if (entry.isFile() && IMAGE_EXT.has(path.extname(entry.name).slice(1).toLowerCase())) {
|
|
242
|
-
out.push(full);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return out.toSorted();
|
|
246
|
-
};
|
|
247
|
-
// Keep the `limit` most-recently-modified paths (by mtime), returned in
|
|
248
|
-
// stable name order. Used to bound the shared-store fallback.
|
|
249
|
-
const pickNewest = (paths, limit) => {
|
|
250
|
-
if (paths.length <= limit) {
|
|
251
|
-
return paths;
|
|
252
|
-
}
|
|
253
|
-
const withTime = paths.map((p) => {
|
|
254
|
-
let mtimeMs = 0;
|
|
255
|
-
try {
|
|
256
|
-
({ mtimeMs } = statSync(p));
|
|
257
|
-
}
|
|
258
|
-
catch {
|
|
259
|
-
// Gone between listing and stat; sort it oldest.
|
|
260
|
-
}
|
|
261
|
-
return { mtimeMs, p };
|
|
262
|
-
});
|
|
263
|
-
return withTime
|
|
264
|
-
.toSorted((a, b) => b.mtimeMs - a.mtimeMs)
|
|
265
|
-
.slice(0, limit)
|
|
266
|
-
.map((x) => x.p)
|
|
267
|
-
.toSorted();
|
|
268
|
-
};
|
|
269
|
-
const spawnCodex = (bin, args, cwd) =>
|
|
270
|
-
// oxlint-disable-next-line promise/avoid-new -- child_process.spawn is event-based
|
|
271
|
-
new Promise((resolve) => {
|
|
272
|
-
const child = spawn(bin, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
273
|
-
let output = "";
|
|
274
|
-
// Forward Codex's own stdout/stderr straight to our stderr so the user
|
|
275
|
-
// sees its progress and messages directly. It goes to stderr (never
|
|
276
|
-
// stdout) so it can't corrupt our `--json` payload. We also buffer it
|
|
277
|
-
// so a failure can surface the tail even for a caller that isn't
|
|
278
|
-
// watching the live stream.
|
|
279
|
-
child.stdout?.on("data", (c) => {
|
|
280
|
-
output += c.toString("utf-8");
|
|
281
|
-
process.stderr.write(c);
|
|
282
|
-
});
|
|
283
|
-
child.stderr?.on("data", (c) => {
|
|
284
|
-
output += c.toString("utf-8");
|
|
285
|
-
process.stderr.write(c);
|
|
286
|
-
});
|
|
287
|
-
child.on("error", (err) => {
|
|
288
|
-
resolve({
|
|
289
|
-
code: 1,
|
|
290
|
-
notFound: err.code === "ENOENT",
|
|
291
|
-
output: output + err.message,
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
child.on("close", (code) => {
|
|
295
|
-
resolve({ code: code ?? 1, notFound: false, output });
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
/**
|
|
299
|
-
* Delegate image generation to the local `codex` CLI. Runs
|
|
300
|
-
* `codex exec` in an isolated temp workspace, then collects the produced
|
|
301
|
-
* images from that workspace (and, as a fallback, from Codex's default
|
|
302
|
-
* `generated_images` store). Throws with actionable guidance when Codex
|
|
303
|
-
* is missing, fails, or produces nothing.
|
|
304
|
-
*/
|
|
305
|
-
/** The `codex exec` argv for one image run. */
|
|
306
|
-
export const codexExecArgs = (workDir, references, prompt) => [
|
|
307
|
-
"exec",
|
|
308
|
-
"--skip-git-repo-check",
|
|
309
|
-
"-s",
|
|
310
|
-
"workspace-write",
|
|
311
|
-
"-C",
|
|
312
|
-
workDir,
|
|
313
|
-
...references.flatMap((r) => ["-i", r]),
|
|
314
|
-
// `-i` is variadic (`--image <FILE>...`): without the separator it
|
|
315
|
-
// swallows the prompt as one more image and codex waits on stdin for one.
|
|
316
|
-
"--",
|
|
317
|
-
prompt,
|
|
318
|
-
];
|
|
319
|
-
export const generateImagesWithCodex = async (opts) => {
|
|
320
|
-
const parsed = parseCodexInput(opts.input);
|
|
321
|
-
if (!parsed.prompt) {
|
|
322
|
-
throw new CodexError("codex image generation requires a prompt (--prompt).");
|
|
323
|
-
}
|
|
324
|
-
// Codex can only attach on-disk references. Record any non-local ones
|
|
325
|
-
// (e.g. uploaded URLs) so the caller can surface them even under --json,
|
|
326
|
-
// rather than silently generating plain text-to-image.
|
|
327
|
-
const references = [];
|
|
328
|
-
const ignoredReferences = [];
|
|
329
|
-
for (const candidate of parsed.referenceCandidates) {
|
|
330
|
-
const local = readExplicitLocalFile(candidate);
|
|
331
|
-
if (local) {
|
|
332
|
-
references.push(local.path);
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
ignoredReferences.push(candidate);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
const requestId = randomBytes(4).toString("hex");
|
|
339
|
-
const workDir = mkdtempSync(path.join(tmpdir(), "vg-codex-"));
|
|
340
|
-
const filenames = Array.from({ length: parsed.count }, (_, i) => `output-${i}.png`);
|
|
341
|
-
const prompt = buildCodexPrompt(parsed, filenames, references.length > 0);
|
|
342
|
-
const bin = process.env.VG_CODEX_BIN ?? "codex";
|
|
343
|
-
const args = codexExecArgs(workDir, references, prompt);
|
|
344
|
-
// Snapshot Codex's default image store so we can tell which files this
|
|
345
|
-
// run produced if the model saves there instead of the workspace.
|
|
346
|
-
const storeDir = path.join(codexHome(), "generated_images");
|
|
347
|
-
const before = new Set(listImages(storeDir));
|
|
348
|
-
const outcome = await spawnCodex(bin, args, workDir);
|
|
349
|
-
if (outcome.notFound) {
|
|
350
|
-
throw new CodexError(`The \`codex\` CLI was not found on PATH. Install it (npm install -g @openai/codex) ` +
|
|
351
|
-
`and sign in with \`codex login\`, or drop --provider codex to use vibedgames. ` +
|
|
352
|
-
`Set VG_CODEX_BIN to point at a specific binary.`, { notInstalled: true });
|
|
353
|
-
}
|
|
354
|
-
if (outcome.code !== 0) {
|
|
355
|
-
throw new CodexError(`codex exec exited with code ${outcome.code}.`, {
|
|
356
|
-
output: outcome.output,
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
// Prefer the exact filenames we pinned in the prompt — those are the
|
|
360
|
-
// images Codex produced for this run. A stray/incidental PNG in the
|
|
361
|
-
// workspace must NOT count as output nor suppress the store fallback.
|
|
362
|
-
const pinned = new Set(filenames);
|
|
363
|
-
const fromWork = listImages(workDir);
|
|
364
|
-
const pinnedWork = fromWork.filter((p) => pinned.has(path.basename(p)));
|
|
365
|
-
// Fallback for when Codex ignored the workspace and wrote to its shared
|
|
366
|
-
// store instead. That store is not scoped to this invocation, so cap to
|
|
367
|
-
// the newest `count` new files to limit picking up a concurrent run's
|
|
368
|
-
// outputs (best-effort — Codex names store files itself, so there's no
|
|
369
|
-
// requestId to match on).
|
|
370
|
-
const fromStore = pickNewest(listImages(storeDir).filter((p) => !before.has(p)), parsed.count);
|
|
371
|
-
// Pinned workspace files win; then the store; then, as a last resort,
|
|
372
|
-
// any workspace PNG (Codex saved images but chose different names) —
|
|
373
|
-
// capped to `count` like the store branch so an unexpected extra file
|
|
374
|
-
// can't inflate the output set.
|
|
375
|
-
let rawFiles = pickNewest(fromWork, parsed.count);
|
|
376
|
-
if (pinnedWork.length > 0) {
|
|
377
|
-
rawFiles = pinnedWork;
|
|
378
|
-
}
|
|
379
|
-
else if (fromStore.length > 0) {
|
|
380
|
-
rawFiles = fromStore;
|
|
381
|
-
}
|
|
382
|
-
if (rawFiles.length === 0) {
|
|
383
|
-
throw new CodexError(`codex produced no image files. It may have declined the request or lack ` +
|
|
384
|
-
`image-generation access on the signed-in plan.`, { output: outcome.output });
|
|
385
|
-
}
|
|
386
|
-
return { ignoredReferences, prompt, rawFiles, requestId };
|
|
387
|
-
};
|
|
388
|
-
/**
|
|
389
|
-
* Copy Codex's raw outputs to their final destinations per the
|
|
390
|
-
* `--download` template (or default cwd naming). Returns the written
|
|
391
|
-
* paths and any per-file failures.
|
|
392
|
-
*/
|
|
393
|
-
export const placeCodexOutputs = (rawFiles, template, requestId) => {
|
|
394
|
-
const downloaded = [];
|
|
395
|
-
// Keyed `url` (holding the source path) to match the shape the
|
|
396
|
-
// vibedgames run/status paths use for `download_failures`, so agents
|
|
397
|
-
// reading `download_failures[].url` on the shared --json surface work
|
|
398
|
-
// uniformly across providers.
|
|
399
|
-
const failed = [];
|
|
400
|
-
// Render every target first, then disambiguate colliding paths the same
|
|
401
|
-
// way downloadMedia does — a multi-image run with a template that lacks
|
|
402
|
-
// {index} (e.g. `{request_id}.{ext}` or a fixed filename) would
|
|
403
|
-
// otherwise overwrite earlier outputs while still reporting each path.
|
|
404
|
-
const rendered = rawFiles.map((source, index) => {
|
|
405
|
-
const ext = path.extname(source).slice(1).toLowerCase() || "png";
|
|
406
|
-
return renderLocalTarget(template, index, ext, requestId, rawFiles.length);
|
|
407
|
-
});
|
|
408
|
-
const targets = disambiguateTargets(rendered);
|
|
409
|
-
for (const [index, source] of rawFiles.entries()) {
|
|
410
|
-
const target = targets[index];
|
|
411
|
-
if (target === undefined) {
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
try {
|
|
415
|
-
if (path.resolve(source) !== target) {
|
|
416
|
-
mkdirSync(path.dirname(target), { recursive: true });
|
|
417
|
-
copyFileSync(source, target);
|
|
418
|
-
}
|
|
419
|
-
downloaded.push(target);
|
|
420
|
-
}
|
|
421
|
-
catch (error) {
|
|
422
|
-
failed.push({ error: error instanceof Error ? error.message : String(error), url: source });
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
return { downloaded, failed };
|
|
426
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface ProjectConfig {
|
|
2
|
-
slug: string;
|
|
3
|
-
name?: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* The slug grammar every surface must agree on — it is the deploy target, the
|
|
7
|
-
* fork target, and the label in `{slug}.vibedgames.com`. Kept here rather than
|
|
8
|
-
* per-command so a validator can't drift and reject a slug that deploy accepts.
|
|
9
|
-
*/
|
|
10
|
-
export declare const SLUG_RE: RegExp;
|
|
11
|
-
/** The directory containing the nearest vibedgames.json at or above `dir`,
|
|
12
|
-
* or null if none — i.e. the project root to archive as forkable source. */
|
|
13
|
-
export declare const findProjectRoot: (dir: string) => string | null;
|
|
14
|
-
export declare const readProjectConfig: (dir: string) => ProjectConfig | null;
|
|
15
|
-
export declare const writeProjectConfig: (dir: string, config: ProjectConfig) => void;
|
|
16
|
-
export declare const projectConfigPath: (dir: string) => string;
|
package/dist/lib/config-file.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { isJsonObject, isJsonString } from "./types.js";
|
|
4
|
-
const FILENAME = "vibedgames.json";
|
|
5
|
-
/**
|
|
6
|
-
* The slug grammar every surface must agree on — it is the deploy target, the
|
|
7
|
-
* fork target, and the label in `{slug}.vibedgames.com`. Kept here rather than
|
|
8
|
-
* per-command so a validator can't drift and reject a slug that deploy accepts.
|
|
9
|
-
*/
|
|
10
|
-
export const SLUG_RE = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/u;
|
|
11
|
-
// Walk from `dir` up toward the filesystem root, stopping at the first
|
|
12
|
-
// vibedgames.json. Lets `vg deploy ./dist` pick up the config from the
|
|
13
|
-
// project root even when the build step doesn't copy it into the output.
|
|
14
|
-
const findConfigPath = (dir) => {
|
|
15
|
-
let current = path.resolve(dir);
|
|
16
|
-
while (true) {
|
|
17
|
-
const candidate = path.join(current, FILENAME);
|
|
18
|
-
if (existsSync(candidate)) {
|
|
19
|
-
return candidate;
|
|
20
|
-
}
|
|
21
|
-
const parent = path.dirname(current);
|
|
22
|
-
if (parent === current) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
current = parent;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
/** The directory containing the nearest vibedgames.json at or above `dir`,
|
|
29
|
-
* or null if none — i.e. the project root to archive as forkable source. */
|
|
30
|
-
export const findProjectRoot = (dir) => {
|
|
31
|
-
const found = findConfigPath(dir);
|
|
32
|
-
return found ? path.dirname(found) : null;
|
|
33
|
-
};
|
|
34
|
-
export const readProjectConfig = (dir) => {
|
|
35
|
-
const file = findConfigPath(dir);
|
|
36
|
-
if (!file) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
const raw = readFileSync(file, "utf-8");
|
|
40
|
-
const parsed = JSON.parse(raw);
|
|
41
|
-
if (!isJsonObject(parsed) || !isJsonString(parsed.slug)) {
|
|
42
|
-
throw new Error(`${FILENAME} is malformed — missing "slug".`);
|
|
43
|
-
}
|
|
44
|
-
const config = { slug: parsed.slug };
|
|
45
|
-
if (isJsonString(parsed.name)) {
|
|
46
|
-
config.name = parsed.name;
|
|
47
|
-
}
|
|
48
|
-
return config;
|
|
49
|
-
};
|
|
50
|
-
export const writeProjectConfig = (dir, config) => {
|
|
51
|
-
const file = path.join(dir, FILENAME);
|
|
52
|
-
writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`);
|
|
53
|
-
};
|
|
54
|
-
export const projectConfigPath = (dir) => path.join(dir, FILENAME);
|
package/dist/lib/config.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
interface Config {
|
|
2
|
-
token: string;
|
|
3
|
-
baseUrl: string;
|
|
4
|
-
}
|
|
5
|
-
export declare const getConfigDir: () => string;
|
|
6
|
-
export declare const getConfig: () => Config | null;
|
|
7
|
-
export declare const saveConfig: (config: Config) => void;
|
|
8
|
-
export declare const clearConfig: () => void;
|
|
9
|
-
export declare const getBaseUrl: () => string;
|
|
10
|
-
export declare const getToken: () => string | null;
|
|
11
|
-
export {};
|
package/dist/lib/config.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { isJsonObject, isJsonString } from "./types.js";
|
|
5
|
-
export const getConfigDir = () => {
|
|
6
|
-
const xdg = process.env.XDG_CONFIG_HOME;
|
|
7
|
-
const base = xdg ?? path.join(homedir(), ".config");
|
|
8
|
-
return path.join(base, "vg");
|
|
9
|
-
};
|
|
10
|
-
const getConfigPath = () => path.join(getConfigDir(), "auth.json");
|
|
11
|
-
export const getConfig = () => {
|
|
12
|
-
const file = getConfigPath();
|
|
13
|
-
if (!existsSync(file)) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
let raw;
|
|
17
|
-
try {
|
|
18
|
-
raw = JSON.parse(readFileSync(file, "utf-8"));
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
// auth.json is only ever written by saveConfig, so both fields are present
|
|
24
|
-
// in practice; a hand-corrupted file reads as "not logged in".
|
|
25
|
-
if (!isJsonObject(raw)) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
const { token, baseUrl } = raw;
|
|
29
|
-
if (!isJsonString(token) || !isJsonString(baseUrl)) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
return { baseUrl, token };
|
|
33
|
-
};
|
|
34
|
-
export const saveConfig = (config) => {
|
|
35
|
-
const dir = getConfigDir();
|
|
36
|
-
if (!existsSync(dir)) {
|
|
37
|
-
mkdirSync(dir, { mode: 0o700, recursive: true });
|
|
38
|
-
}
|
|
39
|
-
writeFileSync(getConfigPath(), JSON.stringify(config, null, 2), {
|
|
40
|
-
mode: 0o600,
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
export const clearConfig = () => {
|
|
44
|
-
const file = getConfigPath();
|
|
45
|
-
if (existsSync(file)) {
|
|
46
|
-
unlinkSync(file);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
export const getBaseUrl = () => process.env.VG_API_URL ?? getConfig()?.baseUrl ?? "https://vibedgames.com";
|
|
50
|
-
export const getToken = () =>
|
|
51
|
-
// VG_TOKEN lets local/CI runs authenticate without touching the saved
|
|
52
|
-
// login (e.g. a seeded dev session), so headless testing never clobbers
|
|
53
|
-
// the user's real `vg login` credentials.
|
|
54
|
-
process.env.VG_TOKEN ?? getConfig()?.token ?? null;
|
package/dist/lib/manifest.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface ManifestFile {
|
|
2
|
-
/** forward-slash relative path, e.g. "assets/sprite.png" */
|
|
3
|
-
path: string;
|
|
4
|
-
/** absolute filesystem path */
|
|
5
|
-
absolutePath: string;
|
|
6
|
-
size: number;
|
|
7
|
-
sha256: string;
|
|
8
|
-
contentType: string;
|
|
9
|
-
}
|
|
10
|
-
export declare const buildManifest: (rootDir: string) => ManifestFile[];
|
package/dist/lib/manifest.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
const IGNORED_TOP_LEVEL = new Set([
|
|
5
|
-
"node_modules",
|
|
6
|
-
".git",
|
|
7
|
-
".turbo",
|
|
8
|
-
".cache",
|
|
9
|
-
".DS_Store",
|
|
10
|
-
"vibedgames.json",
|
|
11
|
-
]);
|
|
12
|
-
const CONTENT_TYPES = new Map(Object.entries({
|
|
13
|
-
avif: "image/avif",
|
|
14
|
-
cjs: "application/javascript; charset=utf-8",
|
|
15
|
-
css: "text/css; charset=utf-8",
|
|
16
|
-
gif: "image/gif",
|
|
17
|
-
glb: "model/gltf-binary",
|
|
18
|
-
gltf: "model/gltf+json",
|
|
19
|
-
htm: "text/html; charset=utf-8",
|
|
20
|
-
html: "text/html; charset=utf-8",
|
|
21
|
-
ico: "image/x-icon",
|
|
22
|
-
jpeg: "image/jpeg",
|
|
23
|
-
jpg: "image/jpeg",
|
|
24
|
-
js: "application/javascript; charset=utf-8",
|
|
25
|
-
json: "application/json; charset=utf-8",
|
|
26
|
-
m4a: "audio/mp4",
|
|
27
|
-
map: "application/json; charset=utf-8",
|
|
28
|
-
mjs: "application/javascript; charset=utf-8",
|
|
29
|
-
mp3: "audio/mpeg",
|
|
30
|
-
mp4: "video/mp4",
|
|
31
|
-
ogg: "audio/ogg",
|
|
32
|
-
otf: "font/otf",
|
|
33
|
-
png: "image/png",
|
|
34
|
-
svg: "image/svg+xml",
|
|
35
|
-
ttf: "font/ttf",
|
|
36
|
-
txt: "text/plain; charset=utf-8",
|
|
37
|
-
wasm: "application/wasm",
|
|
38
|
-
wav: "audio/wav",
|
|
39
|
-
webm: "video/webm",
|
|
40
|
-
webp: "image/webp",
|
|
41
|
-
woff: "font/woff",
|
|
42
|
-
woff2: "font/woff2",
|
|
43
|
-
xml: "application/xml",
|
|
44
|
-
}));
|
|
45
|
-
const contentTypeForPath = (file) => {
|
|
46
|
-
const ext = file.split(".").pop()?.toLowerCase() ?? "";
|
|
47
|
-
return CONTENT_TYPES.get(ext) ?? "application/octet-stream";
|
|
48
|
-
};
|
|
49
|
-
const shouldIgnore = (relPath) => {
|
|
50
|
-
const top = relPath.split(path.sep)[0] ?? "";
|
|
51
|
-
if (IGNORED_TOP_LEVEL.has(top)) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
// skip hidden files anywhere in the tree
|
|
55
|
-
if (relPath.split(path.sep).some((seg) => seg.startsWith("."))) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
};
|
|
60
|
-
export const buildManifest = (rootDir) => {
|
|
61
|
-
const files = [];
|
|
62
|
-
const walk = (dir) => {
|
|
63
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
64
|
-
const abs = path.join(dir, entry.name);
|
|
65
|
-
const rel = path.relative(rootDir, abs);
|
|
66
|
-
if (shouldIgnore(rel)) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (entry.isDirectory()) {
|
|
70
|
-
walk(abs);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (!entry.isFile()) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const stat = statSync(abs);
|
|
77
|
-
const buf = readFileSync(abs);
|
|
78
|
-
const sha256 = createHash("sha256").update(buf).digest("hex");
|
|
79
|
-
const posixPath = rel.split(path.sep).join("/");
|
|
80
|
-
files.push({
|
|
81
|
-
absolutePath: abs,
|
|
82
|
-
contentType: contentTypeForPath(posixPath),
|
|
83
|
-
path: posixPath,
|
|
84
|
-
sha256,
|
|
85
|
-
size: stat.size,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
walk(rootDir);
|
|
90
|
-
return files;
|
|
91
|
-
};
|