@nodaro/cli 1.18.1 → 1.19.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/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import { createClient, StaticTokenAuth, UnauthorizedError, NodaroError, LOCATION
13
13
  import select from '@inquirer/select';
14
14
  import checkbox from '@inquirer/checkbox';
15
15
  import input from '@inquirer/input';
16
- import { CHARACTER_STYLES } from '@nodaro/shared';
16
+ import { CHARACTER_STYLES, OVERLAY_ANCHORS, OVERLAY_PLATFORM_IDS } from '@nodaro/shared';
17
17
 
18
18
  var __getOwnPropNames = Object.getOwnPropertyNames;
19
19
  var __commonJS = (cb, mod) => function __require() {
@@ -29,7 +29,7 @@ var require_package = __commonJS({
29
29
  "package.json"(exports$1, module) {
30
30
  module.exports = {
31
31
  name: "@nodaro/cli",
32
- version: "1.18.1",
32
+ version: "1.19.0",
33
33
  description: "Command-line interface for Nodaro \u2014 list and run workflows, inspect jobs and executions, manage projects from the terminal.",
34
34
  type: "module",
35
35
  license: "Apache-2.0",
@@ -70,11 +70,11 @@ var require_package = __commonJS({
70
70
  "@inquirer/confirm": "^6.0.12",
71
71
  "@inquirer/input": "^5.0.12",
72
72
  "@inquirer/select": "^5.1.4",
73
- "@nodaro/sdk": "^1.28.0",
74
- "@nodaro/shared": "^2.21.1",
73
+ "@nodaro/sdk": "^2.7.0",
74
+ "@nodaro/shared": "^3.7.0",
75
75
  commander: "^12.1.0",
76
76
  picocolors: "^1.1.1",
77
- "@nodaro/prompts": "^1.15.0"
77
+ "@nodaro/prompts": "^1.17.2"
78
78
  },
79
79
  devDependencies: {
80
80
  tsup: "^8.5.0",
@@ -398,7 +398,7 @@ function saveWorkspace(profileName, workspaceId) {
398
398
  }
399
399
 
400
400
  // src/client.ts
401
- var CLI_VERSION = "1.18.1" ;
401
+ var CLI_VERSION = "1.19.0" ;
402
402
  function buildClient(profileName) {
403
403
  const { name, profile } = getProfile(profileName);
404
404
  if (!profile) {
@@ -2323,9 +2323,26 @@ function parseSection(raw) {
2323
2323
  }
2324
2324
  return { sectionStartSec: start, sectionEndSec: end };
2325
2325
  }
2326
+ function parseCanvas(raw) {
2327
+ const m = raw.match(/^([0-9]{2,4})x([0-9]{2,4})$/i);
2328
+ if (!m) {
2329
+ warn(`--canvas must be "<width>x<height>" in px, e.g. 1920x1080 (got "${raw}")`);
2330
+ process.exit(1);
2331
+ }
2332
+ return { width: parseInt(m[1], 10), height: parseInt(m[2], 10) };
2333
+ }
2334
+ function parseSafeArea(raw) {
2335
+ const parts = raw.split(",").map((n) => parseFloat(n.trim()));
2336
+ if (parts.length !== 4 || parts.some((n) => !Number.isFinite(n) || n < 0 || n > 1)) {
2337
+ warn(`--safe-area must be "x,y,w,h" as fractions 0..1, e.g. 0.05,0.05,0.9,0.9 (got "${raw}")`);
2338
+ process.exit(1);
2339
+ }
2340
+ const [x, y, w, h] = parts;
2341
+ return { x, y, w, h };
2342
+ }
2326
2343
  function mediaCommand() {
2327
2344
  const cmd = new Command("media").description(
2328
- "media ingestion + compositing \u2014 pull a social video into storage, trim video/audio, still-to-video, slideshow, collage images, save a URL to storage, probe metadata"
2345
+ "media ingestion + compositing \u2014 pull a social video into storage, trim video/audio, still-to-video, slideshow, collage images, overlay layers on an image, save a URL to storage, probe metadata"
2329
2346
  );
2330
2347
  cmd.command("download <url>").description("download a social video (YouTube / TikTok / Instagram / X / Facebook) into your storage").option("--max-height <px>", "cap the resolution (e.g. 720); omit for best available", (v) => parseInt(v, 10)).option("--section <a-b>", 'fetch ONLY this time range in seconds (e.g. "30-90"); the cut lands on keyframes, so pad and trim after').option("--watch", "stream the download's live progress until it completes").option("--profile <name>").option("--json").addHelpText("after", `
2331
2348
  Examples:
@@ -2590,6 +2607,124 @@ after the number ("3 \xB7 Close-up"); pass "" to skip a label for one image.`).a
2590
2607
  }
2591
2608
  }
2592
2609
  );
2610
+ cmd.command("overlay <imageUrl> [layerUrls...]").description("place layers on a base image, pixel-exactly (local compositor, no AI) \u2014 positional URLs are image layers; --layers-file for text/QR/shape layers").option("--layers-file <path>", "JSON file with the full layers array (every kind and per-layer option; mutually exclusive with positional layer URLs)").option("--anchor <anchor>", `the point each positional layer attaches to: ${OVERLAY_ANCHORS.join(" | ")} (default center)`).option("--x <percent>", "offset from the anchor in % of the base width (negative on a right anchor moves inward)", parseFloat).option("--y <percent>", "offset from the anchor in % of the base height (negative on a bottom anchor moves inward)", parseFloat).option("--width <percent>", "layer width in % of the base width (default 25; height follows the layer's aspect)", parseFloat).option("--opacity <0-1>", "layer opacity (default 1)", parseFloat).option("--platform <id>", `also render the composite at a platform's size; repeat for more (${OVERLAY_PLATFORM_IDS.length} available, e.g. youtube-thumbnail)`, collectVariadic).option("--qr-text <text>", "fills every QR layer that reads its link from the workflow (qr.fromInput)").option("--mask-mode <mode>", "mask the job also emits (white = may change): none | layers | around (default \u2014 the ring an AI finish repaints) | outside").option("--mask-spread <px>", "ring width in px for --mask-mode around (default 48)", (v) => parseInt(v, 10)).option("--canvas <WxH>", "output canvas in px (the base is placed into it); omit to keep the base's pixel size").option("--base-fit <fit>", "how the base fills --canvas: contain or cover").option("--background-color <hex>", "canvas background behind the base, #RRGGBB (with --canvas)").option("--output-format <fmt>", "png (default, keeps transparency), jpg or webp").option("--watch", "poll until the job completes").option("--poll-interval <ms>", "watch poll interval in ms", (v) => parseInt(v, 10), 2e3).option("--profile <name>").option("--json").addHelpText("after", `
2611
+ Examples:
2612
+ $ nodaro media overlay https://x/base.png https://x/logo.svg --anchor bottom-right --x -4 --y -6 --width 12 --watch
2613
+ $ nodaro media overlay https://x/base.png https://x/logo.png --platform youtube-thumbnail --platform x-header --watch
2614
+ $ cat > layers.json <<'JSON'
2615
+ [{"kind":"text","text":{"content":"50% OFF","fontId":"anton","fontSize":9,"color":"#ffffff"},"anchor":"top-left","x":5,"y":5},
2616
+ {"kind":"qr","qr":{"text":"https://nodaro.ai"},"anchor":"bottom-right","x":-4,"y":-4,"width":14}]
2617
+ JSON
2618
+ $ nodaro media overlay https://x/base.png --layers-file layers.json --watch
2619
+
2620
+ Placement is in PERCENT of the base image, so the same call works on a 1K
2621
+ preview and a 4K render. --anchor/--x/--y/--width/--opacity apply to EVERY
2622
+ positional layer (the watermark case); per-layer control \u2014 and the text, QR and
2623
+ shape kinds \u2014 goes through --layers-file.
2624
+
2625
+ Not sure where a layer should sit? \`nodaro media overlay-placement\` asks a
2626
+ vision model and answers in these same units.`).action(
2627
+ async (imageUrl, layerUrls, opts) => {
2628
+ try {
2629
+ if (opts.layersFile && layerUrls.length > 0) {
2630
+ warn("Pass layers EITHER as positional URLs OR with --layers-file, not both");
2631
+ process.exit(1);
2632
+ }
2633
+ if (!opts.layersFile && layerUrls.length === 0) {
2634
+ warn("Give at least one layer: a positional image URL, or --layers-file with the layers array");
2635
+ process.exit(1);
2636
+ }
2637
+ if (opts.anchor && !OVERLAY_ANCHORS.includes(opts.anchor)) {
2638
+ warn(`--anchor must be one of ${OVERLAY_ANCHORS.join(", ")} (got "${opts.anchor}")`);
2639
+ process.exit(1);
2640
+ }
2641
+ if (opts.maskMode && !["none", "layers", "around", "outside"].includes(opts.maskMode)) {
2642
+ warn(`--mask-mode must be none, layers, around or outside (got "${opts.maskMode}")`);
2643
+ process.exit(1);
2644
+ }
2645
+ if (opts.baseFit && !["contain", "cover"].includes(opts.baseFit)) {
2646
+ warn(`--base-fit must be contain or cover (got "${opts.baseFit}")`);
2647
+ process.exit(1);
2648
+ }
2649
+ if (opts.outputFormat && !["png", "jpg", "webp"].includes(opts.outputFormat)) {
2650
+ warn(`--output-format must be png, jpg or webp (got "${opts.outputFormat}")`);
2651
+ process.exit(1);
2652
+ }
2653
+ const unknownPlatforms = (opts.platform ?? []).filter(
2654
+ (p) => !OVERLAY_PLATFORM_IDS.includes(p)
2655
+ );
2656
+ if (unknownPlatforms.length > 0) {
2657
+ warn(`Unknown --platform: ${unknownPlatforms.join(", ")}. Available: ${OVERLAY_PLATFORM_IDS.join(", ")}`);
2658
+ process.exit(1);
2659
+ }
2660
+ let layers;
2661
+ if (opts.layersFile) {
2662
+ const parsed = JSON.parse(readFileSync(opts.layersFile, "utf8"));
2663
+ if (!Array.isArray(parsed) || parsed.length === 0) {
2664
+ warn(`--layers-file must contain a non-empty JSON array of layers (${opts.layersFile})`);
2665
+ process.exit(1);
2666
+ }
2667
+ layers = parsed;
2668
+ } else {
2669
+ const placement = {
2670
+ ...opts.anchor ? { anchor: opts.anchor } : {},
2671
+ ...opts.x !== void 0 ? { x: opts.x } : {},
2672
+ ...opts.y !== void 0 ? { y: opts.y } : {},
2673
+ ...opts.width !== void 0 ? { width: opts.width } : {},
2674
+ ...opts.opacity !== void 0 ? { opacity: opts.opacity } : {}
2675
+ };
2676
+ layers = layerUrls.map((url) => ({ imageUrl: url, ...placement }));
2677
+ }
2678
+ const canvas = opts.canvas ? parseCanvas(opts.canvas) : void 0;
2679
+ const client = buildClient(opts.profile);
2680
+ const result = await client.media.imageOverlay({
2681
+ imageUrl,
2682
+ layers,
2683
+ ...canvas ? { canvas: { ...canvas, ...opts.backgroundColor ? { backgroundColor: opts.backgroundColor } : {} } } : {},
2684
+ ...opts.baseFit ? { baseFit: opts.baseFit } : {},
2685
+ ...opts.outputFormat ? { outputFormat: opts.outputFormat } : {},
2686
+ ...opts.platform?.length ? { variants: opts.platform } : {},
2687
+ ...opts.qrText ? { qrText: opts.qrText } : {},
2688
+ ...opts.maskMode ? { maskMode: opts.maskMode } : {},
2689
+ ...opts.maskSpread !== void 0 ? { maskSpread: opts.maskSpread } : {}
2690
+ });
2691
+ await reportQueuedJob(result, () => client.jobs.get(result.jobId), { ...opts, note: "image overlay" });
2692
+ } catch (err) {
2693
+ handleError(err);
2694
+ }
2695
+ }
2696
+ );
2697
+ cmd.command("overlay-placement <imageUrl>").description("ask a vision model WHERE one overlay layer should sit \u2014 answers in `media overlay`'s own percent units").option("--intent <text>", 'what the layer is, in words \u2014 "a logo", "a price badge" (default a logo)').option("--aspect <ratio>", "the layer's width / height (1 = square, the default)", parseFloat).option("--safe-area <x,y,w,h>", "always-visible region as fractions 0..1; the placement is kept inside it").option("--profile <name>").option("--json").addHelpText("after", `
2698
+ Example:
2699
+ $ nodaro media overlay-placement https://x/base.png --intent "a logo" --aspect 2.5
2700
+
2701
+ Answers synchronously (no job to poll) with anchor, x, y and width \u2014 feed them
2702
+ straight to \`nodaro media overlay --anchor \u2026 --x \u2026 --y \u2026 --width \u2026\`. Billed as
2703
+ one image-to-text call.`).action(
2704
+ async (imageUrl, opts) => {
2705
+ try {
2706
+ const safeArea = opts.safeArea ? parseSafeArea(opts.safeArea) : void 0;
2707
+ const client = buildClient(opts.profile);
2708
+ const { placement } = await client.media.suggestOverlayPlacement({
2709
+ imageUrl,
2710
+ ...opts.intent ? { intent: opts.intent } : {},
2711
+ ...opts.aspect !== void 0 ? { layerAspect: opts.aspect } : {},
2712
+ ...safeArea ? { safeArea } : {}
2713
+ });
2714
+ if (opts.json) {
2715
+ emit(placement, opts);
2716
+ return;
2717
+ }
2718
+ success(`anchor ${placement.anchor}, x ${placement.x}%, y ${placement.y}%, width ${placement.width}%`);
2719
+ dim(placement.reason);
2720
+ info(
2721
+ `apply: nodaro media overlay ${imageUrl} <layerUrl> --anchor ${placement.anchor} --x ${placement.x} --y ${placement.y} --width ${placement.width} --watch`
2722
+ );
2723
+ } catch (err) {
2724
+ handleError(err);
2725
+ }
2726
+ }
2727
+ );
2593
2728
  cmd.command("save <url>").description("copy an external media URL into your Nodaro storage (server-side fetch)").option("--filename <name>", "filename to store it under").option("--type <type>", "media type hint: image, video, or audio").option("--watch", "poll until the job completes").option("--poll-interval <ms>", "watch poll interval in ms", (v) => parseInt(v, 10), 2e3).option("--profile <name>").option("--json").action(
2594
2729
  async (url, opts) => {
2595
2730
  try {