@gepetto/cli 0.2.2 → 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 CHANGED
@@ -12,18 +12,22 @@ 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 list rooms # valid ids (also: styles, furnitures, skies, surfaces)
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
19
21
  npx @gepetto/cli secret # your webhook signing secret
20
22
  npx @gepetto/cli keys # your test and live keys, masked (--show to print them in full)
21
23
  npx @gepetto/cli subscribe # payment link; the live key is written to .env.production.local once paid
24
+ npx @gepetto/cli billing # invoices, payment method and cancellation (Stripe portal)
22
25
  npx @gepetto/cli whoami # or logout
23
26
  ```
24
27
 
25
- `run` passes any API parameter as is: `--keepFireplace`, `--straighten`, `--skyId sunny`, `--resolution 4k`... A local `--image` or
26
- `--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.
27
31
 
28
32
  Every command accepts `--json`. The API key is read from `--key`, then `GEPETTO_API_KEY`, then `.env.local` /
29
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.2.2';
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
- const LISTS = ['rooms', 'styles', 'furnitures', 'skies', 'surfaces'];
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
 
@@ -230,21 +232,40 @@ const commands = {
230
232
  fail('payment_timeout', 'No payment after 30 minutes. Run the command again once paid: the key will be written.');
231
233
  },
232
234
 
235
+ /** The Stripe customer portal of the account: invoices, payment method, cancellation. */
236
+ async billing() {
237
+ const { url } = await api('POST', '/cli/billing', { token: session() });
238
+ out(`Billing (invoices, payment method, cancellation): ${url}`, { event: 'billing', url });
239
+ openBrowser(url);
240
+ },
241
+
233
242
  async run() {
234
243
  const tool = positional[1];
235
244
  if (!TOOLS.includes(tool)) fail('unknown_tool', `Tool: ${TOOLS.join(', ')}. Example: npx @gepetto/cli run declutter --image ./room.jpg`);
236
245
  const key = await apiKey();
237
- const { image, mask, out: outFile, key: _k, noBrowser: _n, ...rest } = flags;
238
- if (typeof image !== 'string') fail('missing_parameter', '--image is required (a local file or a URL).');
239
- const body = { ...rest, url: await imageUrl(image, key, '--image') };
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).');
240
251
  if (typeof mask === 'string') body.mask = await imageUrl(mask, key, '--mask');
241
- if (!JSON_OUT) console.log(body.webhook ? 'Sending the job…' : 'Rendering (about 15 to 60 s)…');
242
- const job = await api('POST', `/${tool}`, { token: key, body });
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})`);
243
263
  if (job.status !== 'success') return out(`Job ${job.id}: ${job.status}. Follow it with: npx @gepetto/cli job ${job.id}`, job);
244
- // Default name built from what the server sent: only letters, digits, - and _, and an image extension
264
+ // Default name built from what the server sent: only letters, digits, - and _, and a known extension
245
265
  const ext = path.extname(new URL(job.output).pathname).toLowerCase();
246
266
  const safeId = String(job.id).replace(/[^A-Za-z0-9_-]/g, '').slice(0, 64) || 'output';
247
- const target = typeof outFile === 'string' ? outFile : `${tool}-${safeId}${['.jpg', '.jpeg', '.png', '.webp'].includes(ext) ? ext : '.jpg'}`;
267
+ const known = video ? ['.mp4'] : ['.jpg', '.jpeg', '.png', '.webp'];
268
+ const target = typeof outFile === 'string' ? outFile : `${tool}-${safeId}${known.includes(ext) ? ext : known[0]}`;
248
269
  fs.writeFileSync(target, Buffer.from(await (await fetch(job.output)).arrayBuffer()));
249
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 });
250
271
  },
@@ -274,7 +295,7 @@ const commands = {
274
295
  async list() {
275
296
  const what = positional[1];
276
297
  if (!LISTS.includes(what)) fail('unknown_list', `List: ${LISTS.join(', ')}`);
277
- const data = await api('GET', `/${what}`, { token: await apiKey() });
298
+ const data = await api('GET', what === 'transitions' ? '/video/transitions' : `/${what}`, { token: await apiKey() });
278
299
  if (JSON_OUT) return console.log(JSON.stringify(data));
279
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');
280
301
  if (Array.isArray(data)) console.log(show(data));
@@ -320,12 +341,16 @@ const commands = {
320
341
  run <tool> --image <file|url> [--mask <file|url>] [--out file] [--<param> value]
321
342
  Tools: ${TOOLS.join(', ')}
322
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 "...")
323
347
  list <${LISTS.join('|')}> Valid ids for the parameters
324
348
  job <id> | jobs [--failed] A job, or the latest ones (with the reason of a failure)
325
349
  usage Renders and consumption of the period
326
350
  webhook test <url> Send a signed success and failure to your webhook endpoint
327
351
  secret Your webhook signing secret
328
352
  subscribe Payment link of the subscription; writes the live key once paid
353
+ billing Invoices, payment method and cancellation (Stripe portal)
329
354
  logout | whoami
330
355
 
331
356
  Every command accepts --json. Docs: https://docs.gepettoapp.com`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gepetto/cli",
3
- "version": "0.2.2",
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": {