@gepetto/cli 0.2.3 → 0.3.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 +6 -3
- package/bin/gepetto.mjs +28 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,9 @@ npx @gepetto/cli init # writes GEPETTO_API_KEY (test key, 200 free ren
|
|
|
12
12
|
npx @gepetto/cli run declutter --image ./room.jpg --out empty.png
|
|
13
13
|
npx @gepetto/cli run furnish --image ./room.jpg --roomId bedroom --styleId modern
|
|
14
14
|
npx @gepetto/cli run enhance --image ./room.jpg --straighten
|
|
15
|
-
npx @gepetto/cli
|
|
15
|
+
npx @gepetto/cli run camera-move --image ./room.jpg --camera zoom_in # video, live key only
|
|
16
|
+
npx @gepetto/cli run transition --jobId <id> --transition <id> # video from a finished render
|
|
17
|
+
npx @gepetto/cli list rooms # valid ids (also: styles, furnitures, skies, surfaces, transitions)
|
|
16
18
|
npx @gepetto/cli job <id> # one job; jobs --failed lists the latest failures with their reason
|
|
17
19
|
npx @gepetto/cli usage # renders and consumption of the period
|
|
18
20
|
npx @gepetto/cli webhook test http://localhost:3000/api/gepetto # sends a signed success and failure to your endpoint
|
|
@@ -23,8 +25,9 @@ npx @gepetto/cli billing # invoices, payment method and cancellation (Str
|
|
|
23
25
|
npx @gepetto/cli whoami # or logout
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
`run` passes any API parameter as is: `--keepFireplace`, `--straighten`, `--skyId sunny`, `--resolution 4k`... A local `--image
|
|
27
|
-
`--mask` file is uploaded first.
|
|
28
|
+
`run` passes any API parameter as is: `--keepFireplace`, `--straighten`, `--skyId sunny`, `--resolution 4k`... A local `--image`,
|
|
29
|
+
`--mask` or `--end` file is uploaded first. The videos (`camera-move`, `transition`) need a live key; `run` waits for
|
|
30
|
+
the MP4 (2 to 10 minutes) and saves it.
|
|
28
31
|
|
|
29
32
|
Every command accepts `--json`. The API key is read from `--key`, then `GEPETTO_API_KEY`, then `.env.local` /
|
|
30
33
|
`.env`, then the test key of the signed-in account.
|
package/bin/gepetto.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import path from 'node:path';
|
|
|
7
7
|
import crypto from 'node:crypto';
|
|
8
8
|
import { spawn } from 'node:child_process';
|
|
9
9
|
|
|
10
|
-
const VERSION = '0.
|
|
10
|
+
const VERSION = '0.3.0';
|
|
11
11
|
const API = (process.env.GEPETTO_API_URL || 'https://europe-west1-gepettoai.cloudfunctions.net/v2').replace(/\/$/, '');
|
|
12
12
|
// The keys go wherever GEPETTO_API_URL points: https only (http allowed for a local server)
|
|
13
13
|
{
|
|
@@ -19,8 +19,10 @@ const API = (process.env.GEPETTO_API_URL || 'https://europe-west1-gepettoai.clou
|
|
|
19
19
|
const BROWSER_HOSTS = ['app.gepettoapp.com', 'pay.gepettoapp.com', 'checkout.stripe.com'];
|
|
20
20
|
const CONFIG_DIR = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'gepetto');
|
|
21
21
|
const CREDENTIALS = path.join(CONFIG_DIR, 'credentials.json');
|
|
22
|
-
const TOOLS = ['declutter', 'furnish', 'sunshine', 'creative-redesign', 'surfaces', 'enhance', 'upscale'];
|
|
23
|
-
|
|
22
|
+
const TOOLS = ['declutter', 'furnish', 'sunshine', 'creative-redesign', 'surfaces', 'enhance', 'upscale', 'camera-move', 'transition'];
|
|
23
|
+
/** Under /v2/video: always asynchronous, followed here until the MP4 is ready (live key only). */
|
|
24
|
+
const VIDEOS = ['camera-move', 'transition'];
|
|
25
|
+
const LISTS = ['rooms', 'styles', 'furnitures', 'skies', 'surfaces', 'transitions'];
|
|
24
26
|
|
|
25
27
|
// --- arguments ---
|
|
26
28
|
|
|
@@ -241,17 +243,29 @@ const commands = {
|
|
|
241
243
|
const tool = positional[1];
|
|
242
244
|
if (!TOOLS.includes(tool)) fail('unknown_tool', `Tool: ${TOOLS.join(', ')}. Example: npx @gepetto/cli run declutter --image ./room.jpg`);
|
|
243
245
|
const key = await apiKey();
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
const body = { ...rest
|
|
246
|
+
const video = VIDEOS.includes(tool);
|
|
247
|
+
const { image, mask, end, transition, out: outFile, key: _k, noBrowser: _n, ...rest } = flags;
|
|
248
|
+
const body = { ...rest };
|
|
249
|
+
if (typeof image === 'string') body.url = await imageUrl(image, key, '--image');
|
|
250
|
+
else if (!(tool === 'transition' && body.jobId)) fail('missing_parameter', '--image is required (a local file or a URL).');
|
|
247
251
|
if (typeof mask === 'string') body.mask = await imageUrl(mask, key, '--mask');
|
|
248
|
-
if (
|
|
249
|
-
|
|
252
|
+
if (typeof end === 'string') body.endUrl = await imageUrl(end, key, '--end');
|
|
253
|
+
if (typeof transition === 'string') body.transitionId = transition;
|
|
254
|
+
if (!JSON_OUT) console.log(body.webhook ? 'Sending the job…' : video ? 'Making the video (2 to 10 minutes)…' : 'Rendering (about 15 to 60 s)…');
|
|
255
|
+
let job = await api('POST', video ? `/video/${tool}` : `/${tool}`, { token: key, body });
|
|
256
|
+
// A video answers 202 at once: follow it until it is done (30 minutes at most, as the API)
|
|
257
|
+
const deadline = Date.now() + 30 * 60 * 1000;
|
|
258
|
+
while (video && !body.webhook && (job.status === 'pending' || job.status === 'processing') && Date.now() < deadline) {
|
|
259
|
+
await sleep(5000);
|
|
260
|
+
job = await api('GET', `/job/${encodeURIComponent(job.id)}`, { token: key });
|
|
261
|
+
}
|
|
262
|
+
if (job.status === 'error') fail(job.error?.code ?? 'render_failed', `${job.error?.message ?? 'The render failed.'} (job ${job.id})`);
|
|
250
263
|
if (job.status !== 'success') return out(`Job ${job.id}: ${job.status}. Follow it with: npx @gepetto/cli job ${job.id}`, job);
|
|
251
|
-
// Default name built from what the server sent: only letters, digits, - and _, and
|
|
264
|
+
// Default name built from what the server sent: only letters, digits, - and _, and a known extension
|
|
252
265
|
const ext = path.extname(new URL(job.output).pathname).toLowerCase();
|
|
253
266
|
const safeId = String(job.id).replace(/[^A-Za-z0-9_-]/g, '').slice(0, 64) || 'output';
|
|
254
|
-
const
|
|
267
|
+
const known = video ? ['.mp4'] : ['.jpg', '.jpeg', '.png', '.webp'];
|
|
268
|
+
const target = typeof outFile === 'string' ? outFile : `${tool}-${safeId}${known.includes(ext) ? ext : known[0]}`;
|
|
255
269
|
fs.writeFileSync(target, Buffer.from(await (await fetch(job.output)).arrayBuffer()));
|
|
256
270
|
out(`Done in ${job.createdAt && job.finishedAt ? Math.round((Date.parse(job.finishedAt) - Date.parse(job.createdAt)) / 1000) + ' s' : '—'}: ${target} (${job.test ? 'test key' : `${job.priceCents} cents`})`, { ...job, file: target });
|
|
257
271
|
},
|
|
@@ -281,7 +295,7 @@ const commands = {
|
|
|
281
295
|
async list() {
|
|
282
296
|
const what = positional[1];
|
|
283
297
|
if (!LISTS.includes(what)) fail('unknown_list', `List: ${LISTS.join(', ')}`);
|
|
284
|
-
const data = await api('GET', `/${what}`, { token: await apiKey() });
|
|
298
|
+
const data = await api('GET', what === 'transitions' ? '/video/transitions' : `/${what}`, { token: await apiKey() });
|
|
285
299
|
if (JSON_OUT) return console.log(JSON.stringify(data));
|
|
286
300
|
const show = (items) => items.map((x) => ` ${x.id}${x.name_en || x.name ? ` (${x.name_en || x.name})` : ''}${x.modes ? ` modes: ${x.modes.join(', ')}` : ''}`).join('\n');
|
|
287
301
|
if (Array.isArray(data)) console.log(show(data));
|
|
@@ -327,6 +341,9 @@ const commands = {
|
|
|
327
341
|
run <tool> --image <file|url> [--mask <file|url>] [--out file] [--<param> value]
|
|
328
342
|
Tools: ${TOOLS.join(', ')}
|
|
329
343
|
e.g. run furnish --image room.jpg --roomId bedroom --styleId modern
|
|
344
|
+
Videos (live key): run camera-move --image room.jpg --camera zoom_in
|
|
345
|
+
run transition --image before.jpg --end after.jpg --transition <id>
|
|
346
|
+
(or --jobId <id of a finished render>, or --prompt "...")
|
|
330
347
|
list <${LISTS.join('|')}> Valid ids for the parameters
|
|
331
348
|
job <id> | jobs [--failed] A job, or the latest ones (with the reason of a failure)
|
|
332
349
|
usage Renders and consumption of the period
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gepetto/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Gepetto API v2 from the terminal: sign in, get an API key, render real estate photos (enhance, declutter, furnish, sky, restyle, walls and floors, upscale), subscribe.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|