@nodaro/cli 1.32.0 → 1.34.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
@@ -9,19 +9,23 @@ import { join } from 'path';
9
9
  import { createServer } from 'http';
10
10
  import { randomBytes } from 'crypto';
11
11
  import { spawn } from 'child_process';
12
- import { ContinuationRefusedError, createClient, StaticTokenAuth, UnauthorizedError, NodaroError, CallbackAuth, LOCATION_ASSET_TYPES, LOCATION_ATTACH_COLUMNS, OBJECT_ASSET_TYPES, OBJECT_ATTACH_COLUMNS } from '@nodaro/sdk';
12
+ import { createClient, StaticTokenAuth, CallbackAuth } from '@nodaro/sdk/client';
13
+ import { ContinuationPreviewPendingError, UnauthorizedError, NodaroError, AppRunVersionChangedError, AlreadyRunningError, ContinuationRefusedError } from '@nodaro/sdk/errors';
14
+ import { collectionRecordHeadline, PREVIEW_RENDER_NODE_TYPES, isPreviewRefusalCode, parseNodePresetExport } from '@nodaro/shared/nodes';
13
15
  import select from '@inquirer/select';
14
16
  import checkbox from '@inquirer/checkbox';
15
17
  import input from '@inquirer/input';
16
18
  import { CHARACTER_STYLES } from '@nodaro/shared/entities';
17
19
  import { TRANSCRIBE_PROVIDERS, transcribeLaneSupportsWordTimestamps, DIALOGUE_PROVIDERS, dialogueStabilityAccepted, dialogueProviderOf, getDialogueCapabilities, TRANSCRIBE_LANES, DEFAULT_TRANSCRIBE_PROVIDER } from '@nodaro/shared/models';
18
- import { OVERLAY_ANCHORS, OVERLAY_PLATFORM_IDS, DEFAULT_VIDEO_MASK_PROVIDER, VIDEO_MASK_PROVIDERS, VIDEO_MASK_LIMITS, MASK_COMPOSITE_BOUNDS, MASK_COMPOSITE_DEFAULTS, MASK_COMPOSITE_BACKGROUND_FITS, MASK_COMPOSITE_AUDIO_SOURCES } from '@nodaro/shared/media';
20
+ import { OVERLAY_ANCHORS, OVERLAY_PLATFORM_IDS, GENERATE_MASK_LIMITS, DEFAULT_VIDEO_MASK_PROVIDER, VIDEO_MASK_PROVIDERS, VIDEO_MASK_LIMITS, MASK_COMPOSITE_BOUNDS, MASK_COMPOSITE_DEFAULTS, MASK_COMPOSITE_BACKGROUND_FITS, MASK_COMPOSITE_AUDIO_SOURCES } from '@nodaro/shared/media';
19
21
  import { ALL_CAPTION_STYLES, DEFAULT_CAPTION_LOOK, CAPTION_LOOK_IDS, CAPTION_MAX_WORDS_PER_LINE_MIN, CAPTION_MAX_WORDS_PER_LINE_MAX, SUPPORTED_FONT_NAMES } from '@nodaro/shared/captions';
20
22
  import { VIDEO_OVERLAY_PRESET_IDS, VIDEO_OVERLAY_CORNERS, VIDEO_OVERLAY_OUTPUT_ASPECTS, isVideoOverlayPresetId, isVideoOverlayCorner, isVideoOverlayOutputAspect, VIDEO_OVERLAY_FITS } from '@nodaro/shared/video';
21
- import { collectionRecordHeadline, parseNodePresetExport } from '@nodaro/shared/nodes';
22
23
  import { SOCIAL_PLATFORMS, COMPETITOR_ACCOUNT_KEYS, isMeasurableCard, isSocialPost, COMPETITOR_ABOUT_PLATFORMS, COMPETITOR_SCHEDULES } from '@nodaro/shared/social';
23
24
  import { RECAST_SEGMENT_PACKS } from '@nodaro/shared/apps';
24
- import { SPEAKER_LAYOUT_IDS, EDL_TARGET_ASPECTS, EDIT_PLAN_TIERS, EDIT_PLAN_MODES } from '@nodaro/shared/edl';
25
+ import { LOCATION_ASSET_TYPES, LOCATION_ATTACH_COLUMNS } from '@nodaro/sdk/locations';
26
+ import { OBJECT_ASSET_TYPES, OBJECT_ATTACH_COLUMNS } from '@nodaro/sdk/objects';
27
+ import { SPEAKER_EMPHASIS_STYLES, EDIT_PLAN_MODES, SPEAKER_LAYOUT_IDS, EDL_TARGET_ASPECTS, EDIT_PLAN_TIERS, EDIT_PLAN_MAX_CLIP_COUNT, SPEAKER_SWITCH_IDS, isKnownSpeakerEmphasisStyle } from '@nodaro/shared/edl';
28
+ import { TRAILER_FORMATS, CLIP_PACK_MIN_TARGET_SEC, CLIP_PACK_MAX_TARGET_SEC, USE_CASE_NODE_TYPES } from '@nodaro/sdk/edit';
25
29
 
26
30
  var __getOwnPropNames = Object.getOwnPropertyNames;
27
31
  var __commonJS = (cb, mod) => function __require() {
@@ -37,7 +41,7 @@ var require_package = __commonJS({
37
41
  "package.json"(exports$1, module) {
38
42
  module.exports = {
39
43
  name: "@nodaro/cli",
40
- version: "1.32.0",
44
+ version: "1.34.0",
41
45
  description: "Command-line interface for Nodaro \u2014 list and run workflows, inspect jobs and executions, manage projects from the terminal.",
42
46
  type: "module",
43
47
  license: "Apache-2.0",
@@ -78,11 +82,11 @@ var require_package = __commonJS({
78
82
  "@inquirer/confirm": "^6.0.12",
79
83
  "@inquirer/input": "^5.0.12",
80
84
  "@inquirer/select": "^5.1.4",
81
- "@nodaro/sdk": "^2.29.0",
82
- "@nodaro/shared": "^3.33.0",
85
+ "@nodaro/sdk": "^2.31.0",
86
+ "@nodaro/shared": "^3.35.0",
83
87
  commander: "^12.1.0",
84
88
  picocolors: "^1.1.1",
85
- "@nodaro/prompts": "^1.39.0"
89
+ "@nodaro/prompts": "^1.40.0"
86
90
  },
87
91
  devDependencies: {
88
92
  tsup: "^8.5.0",
@@ -409,7 +413,7 @@ function saveWorkspace(profileName, workspaceId) {
409
413
  }
410
414
 
411
415
  // src/client.ts
412
- var CLI_VERSION = "1.32.0" ;
416
+ var CLI_VERSION = "1.34.0" ;
413
417
  function buildPublicClient(opts = {}) {
414
418
  const { profile } = getProfile(opts.profile);
415
419
  return createClient({
@@ -626,14 +630,15 @@ function sessionsCommand() {
626
630
  handleError(err);
627
631
  }
628
632
  });
629
- cmd.command("update <id>").description("rename or archive a session").option("--title <title>", "new title").option("--untitled", "clear the title").option("--archive", "archive it").option("--unarchive", "bring it back").option("--profile <name>").option("--json").action(async (id, opts) => {
633
+ cmd.command("update <id>").description("rename or archive a session, or pick its cover").option("--title <title>", "new title").option("--untitled", "clear the title").option("--archive", "archive it").option("--unarchive", "bring it back").option("--cover <jobId>", "one of the session's items to lead its previews").option("--auto-cover", "go back to the automatic cover").option("--profile <name>").option("--json").action(async (id, opts) => {
630
634
  try {
631
635
  const title = opts.untitled ? null : opts.title;
632
636
  const archived = opts.archive ? true : opts.unarchive ? false : void 0;
633
- if (title === void 0 && archived === void 0) {
634
- throw new Error("nothing to update \u2014 provide --title, --untitled, --archive or --unarchive");
637
+ const coverJobId = opts.autoCover ? null : opts.cover;
638
+ if (title === void 0 && archived === void 0 && coverJobId === void 0) {
639
+ throw new Error("nothing to update \u2014 provide --title, --untitled, --archive, --unarchive, --cover or --auto-cover");
635
640
  }
636
- const result = await buildClient(opts.profile).sessions.update(id, { title, archived });
641
+ const result = await buildClient(opts.profile).sessions.update(id, { title, archived, coverJobId });
637
642
  if (opts.json) {
638
643
  emit(result.data, opts);
639
644
  return;
@@ -849,6 +854,25 @@ function elapsed(startMs) {
849
854
  function sleep(ms) {
850
855
  return new Promise((resolve) => setTimeout(resolve, ms));
851
856
  }
857
+ function parseOverridePairs(pairs) {
858
+ if (!pairs?.length) return void 0;
859
+ const out = {};
860
+ for (const pair of pairs) {
861
+ const eq = pair.indexOf("=");
862
+ const dot = pair.indexOf(".");
863
+ if (eq === -1 || dot === -1 || dot > eq) throw new Error(`--override expects nodeId.field=value, got "${pair}"`);
864
+ const nodeId = pair.slice(0, dot);
865
+ const field = pair.slice(dot + 1, eq);
866
+ const raw = pair.slice(eq + 1);
867
+ let value = raw;
868
+ try {
869
+ value = JSON.parse(raw);
870
+ } catch {
871
+ }
872
+ out[nodeId] = { ...out[nodeId] ?? {}, [field]: value };
873
+ }
874
+ return out;
875
+ }
852
876
 
853
877
  // src/commands/workflows.ts
854
878
  function readJsonObject(path, flag) {
@@ -869,6 +893,52 @@ function readJsonObject(path, flag) {
869
893
  }
870
894
  return parsed;
871
895
  }
896
+ function shellQuote(word) {
897
+ if (!word.startsWith("=") && /^[A-Za-z0-9_.:/=@%+-]+$/.test(word)) return word;
898
+ return `'${word.replace(/'/g, `'\\''`)}'`;
899
+ }
900
+ function readNextBody(value) {
901
+ const raw = value === "-" ? readFileSync(0, "utf8") : value.trim().startsWith("{") ? value : null;
902
+ let parsed;
903
+ if (raw === null) {
904
+ parsed = readJsonObject(value, "--next");
905
+ } else {
906
+ try {
907
+ parsed = JSON.parse(raw);
908
+ } catch (err) {
909
+ throw new Error(`--next is not valid JSON: ${err.message}`);
910
+ }
911
+ }
912
+ const next = parsed;
913
+ const shape = "--next takes the `next` of a continuation_preview_pending answer: { continueFromExecutionId, nodeIds, inputOverrides }";
914
+ if (typeof next !== "object" || next === null || Array.isArray(next)) throw new Error(shape);
915
+ if (typeof next.continueFromExecutionId !== "string" || next.continueFromExecutionId.length === 0) throw new Error(shape);
916
+ if (!Array.isArray(next.nodeIds) || next.nodeIds.length === 0 || !next.nodeIds.every((id) => typeof id === "string")) {
917
+ throw new Error(shape);
918
+ }
919
+ if (next.inputOverrides !== void 0 && (typeof next.inputOverrides !== "object" || next.inputOverrides === null || Array.isArray(next.inputOverrides))) {
920
+ throw new Error(shape);
921
+ }
922
+ for (const key2 of ["continueMode", "renderFinal"]) {
923
+ if (next[key2] !== void 0 && next[key2] !== null) {
924
+ throw new Error(`--next is the run a held continuation names, which never carries ${key2}: use --from-failed or workflows render-final for that run`);
925
+ }
926
+ }
927
+ return next;
928
+ }
929
+ function previewPendingCommand(workflowId, err) {
930
+ if (err.renderNodeIds.length === 1 && err.reviewNodeIds.length === 0) {
931
+ return `nodaro workflows render-final ${shellQuote(workflowId)} --from ${shellQuote(err.executionId)} --render ${shellQuote(err.renderNodeIds[0])}`;
932
+ }
933
+ if (!err.next) return null;
934
+ return `nodaro workflows run ${shellQuote(workflowId)} --next ${shellQuote(JSON.stringify(err.next))}`;
935
+ }
936
+ function soleRenderOf(nodes) {
937
+ const renders = (nodes ?? []).filter((n) => PREVIEW_RENDER_NODE_TYPES.has(n.type ?? ""));
938
+ if (renders.length === 1) return renders[0].id;
939
+ if (renders.length === 0) throw new Error("this workflow has no render node to finalize");
940
+ throw new Error(`this workflow has ${renders.length} renders \u2014 name one with --render: ${renders.map((n) => n.id).join(", ")}`);
941
+ }
872
942
  function workflowsCommand() {
873
943
  const cmd = new Command("workflows").description("list, run, and manage workflows");
874
944
  cmd.command("list").description("list workflows in a project").requiredOption("--project <projectId>", "project id (run `nodaro projects list` to find it)").option("--profile <name>").option("--json").action(async (opts) => {
@@ -986,16 +1056,94 @@ function workflowsCommand() {
986
1056
  handleError(err);
987
1057
  }
988
1058
  });
989
- cmd.command("run <id>").description("trigger a workflow run; prints execution id (use --watch to follow)").option("--profile <name>").option("--json").option("--watch", "poll execution status until completion").option("--node <ids...>", "execute only these node ids (space-separated)").action(async (id, opts) => {
1059
+ cmd.command("run <id>").description("trigger a workflow run; prints execution id (use --watch to follow)").option("--profile <name>").option("--json").option("--watch", "poll execution status until completion").option("--node <ids...>", "execute only these node ids (space-separated)").option(
1060
+ "--continue-from <executionId>",
1061
+ "continue an earlier execution of this workflow: nodes not run hand on its outputs (needs --node, unless --from-failed)"
1062
+ ).option(
1063
+ "--from-failed",
1064
+ "with --continue-from: resume that FAILED run from where it stopped \u2014 runs only what it did not complete (of --node; default: the nodes its chain was first started on, every node for a full run, plus what it left failed), and each --node no run of its chain ever ran (charged; never a source, trigger or skipped node)"
1065
+ ).option(
1066
+ "--override <pairs...>",
1067
+ "per-node override for this run only, nodeId.field=value (repeat); values that parse as JSON are sent as JSON, e.g. --override cut.quality=final",
1068
+ collectVariadic
1069
+ ).option(
1070
+ "--next <json|file|->",
1071
+ "send the `next` a continuation_preview_pending answer names, exactly as given (inline JSON, a file, or - for stdin); not combinable with --node, --continue-from, --from-failed or --override"
1072
+ ).option(
1073
+ "--idempotency-key <key>",
1074
+ "sent as Idempotency-Key (8+ characters): a retry with the same key answers the run already started"
1075
+ ).action(
1076
+ async (id, opts) => {
1077
+ try {
1078
+ if (opts.fromFailed && !opts.continueFrom) {
1079
+ throw new Error("--from-failed needs --continue-from <executionId> (the run that failed)");
1080
+ }
1081
+ if (opts.next !== void 0 && (opts.node || opts.continueFrom || opts.fromFailed || opts.override)) {
1082
+ throw new Error("--next is the whole run: do not combine it with --node, --continue-from, --from-failed or --override");
1083
+ }
1084
+ if (opts.idempotencyKey !== void 0 && opts.idempotencyKey.trim().length < 8) {
1085
+ throw new Error("--idempotency-key must be at least 8 characters (the server ignores a shorter one)");
1086
+ }
1087
+ const params = opts.next !== void 0 ? readNextBody(opts.next) : {
1088
+ ...opts.node ? { nodeIds: opts.node } : {},
1089
+ ...opts.override ? { inputOverrides: parseOverridePairs(opts.override) } : {},
1090
+ ...opts.continueFrom ? { continueFromExecutionId: opts.continueFrom } : {},
1091
+ ...opts.fromFailed ? { continueMode: "from-failed" } : {}
1092
+ };
1093
+ const client = buildClient(opts.profile);
1094
+ const result = opts.idempotencyKey ? await client.workflows.run(id, params, { idempotencyKey: opts.idempotencyKey }) : await client.workflows.run(id, params);
1095
+ if (opts.json && !opts.watch) {
1096
+ emit(result, opts);
1097
+ return;
1098
+ }
1099
+ success(`execution ${result.executionId} (${result.status})${result.deduped ? " \u2014 already started by an earlier request with this key" : ""}`);
1100
+ if (result.continuedFrom && result.continuedFrom !== opts.continueFrom) {
1101
+ dim(`continued from ${result.continuedFrom}, a later continuation of ${opts.continueFrom} \u2014 only what it left runs`);
1102
+ }
1103
+ if (!opts.watch) {
1104
+ dim(`follow: nodaro executions get ${result.executionId} --watch`);
1105
+ return;
1106
+ }
1107
+ await watchExecution(client, result.executionId, opts);
1108
+ } catch (err) {
1109
+ if (err instanceof ContinuationPreviewPendingError) {
1110
+ const next = previewPendingCommand(id, err);
1111
+ if (next) {
1112
+ warn("once the preview is reviewed, finish it first, then continue again:");
1113
+ warn(` ${next}`);
1114
+ }
1115
+ }
1116
+ handleError(err);
1117
+ }
1118
+ }
1119
+ );
1120
+ cmd.command("render-final <workflowId>").description(
1121
+ "render the final of a run that stopped at a Preview render: the render at Final and every node after it, continuing that run (the server works out which nodes run)"
1122
+ ).requiredOption("--from <executionId>", "the run that stopped at the preview (your own completed run of this workflow)").option("--render <nodeId>", "the render node to finalize (default: the workflow's only render)").option("--estimate", "quote it only: the nodes it runs and its estimated credits; nothing is created or charged").option("--watch", "poll execution status until completion").option("--profile <name>").option("--json").action(async (workflowId, opts) => {
990
1123
  try {
991
1124
  const client = buildClient(opts.profile);
992
- const params = opts.node ? { nodeIds: opts.node } : {};
993
- const result = await client.workflows.run(id, params);
1125
+ const renderNodeId = opts.render ?? soleRenderOf((await client.workflows.get(workflowId)).data.nodes);
1126
+ const params = { renderNodeId, continueFromExecutionId: opts.from };
1127
+ if (opts.estimate) {
1128
+ const { data: quote } = await client.workflows.estimateRenderFinal(workflowId, params);
1129
+ if (opts.json) {
1130
+ emit(quote, opts);
1131
+ return;
1132
+ }
1133
+ success(`Render final of ${renderNodeId} runs ${quote.nodeIds.join(", ")}`);
1134
+ if (quote.estimatedCredits !== null) {
1135
+ dim(
1136
+ `estimated ${quote.estimatedCredits} credits` + (quote.sufficient === false ? ` \u2014 not covered${quote.available !== null ? ` (${quote.available} available)` : ""}` : "")
1137
+ );
1138
+ }
1139
+ return;
1140
+ }
1141
+ const result = await client.workflows.renderFinal(workflowId, params);
994
1142
  if (opts.json && !opts.watch) {
995
1143
  emit(result, opts);
996
1144
  return;
997
1145
  }
998
- success(`execution ${result.executionId} (${result.status})`);
1146
+ success(`execution ${result.executionId} (${result.status}) \u2014 Render final of ${renderNodeId}`);
999
1147
  if (!opts.watch) {
1000
1148
  dim(`follow: nodaro executions get ${result.executionId} --watch`);
1001
1149
  return;
@@ -1476,24 +1624,31 @@ function rejectPositionalInputs(extras, slug) {
1476
1624
  }
1477
1625
  process.exit(1);
1478
1626
  }
1479
- function parseOverridePairs(pairs) {
1480
- if (!pairs?.length) return void 0;
1481
- const out = {};
1482
- for (const pair of pairs) {
1483
- const eq = pair.indexOf("=");
1484
- const dot = pair.indexOf(".");
1485
- if (eq === -1 || dot === -1 || dot > eq) throw new Error(`--override expects nodeId.field=value, got "${pair}"`);
1486
- const nodeId = pair.slice(0, dot);
1487
- const field = pair.slice(dot + 1, eq);
1488
- const raw = pair.slice(eq + 1);
1489
- let value = raw;
1490
- try {
1491
- value = JSON.parse(raw);
1492
- } catch {
1627
+ function parseAppVersion(value) {
1628
+ const n = Number(value);
1629
+ if (!Number.isInteger(n) || n < 1) throw new Error(`--app-version must be a whole number of 1 or more, got ${JSON.stringify(value)}`);
1630
+ return n;
1631
+ }
1632
+ function retryRefusalAdvice(slug, runId, err) {
1633
+ const startOver = ` start it over (every step runs, and is charged, again): nodaro apps run ${shellQuote(slug)} --input \u2026`;
1634
+ if (err instanceof AppRunVersionChangedError) {
1635
+ const lines = ["the app changed since this run, so it is not continued:", startOver];
1636
+ if (err.runVersion !== void 0) {
1637
+ lines.push(` or continue on the run's own version ${err.runVersion}: nodaro apps run-retry ${shellQuote(slug)} ${shellQuote(runId)} --app-version ${err.runVersion}`);
1493
1638
  }
1494
- out[nodeId] = { ...out[nodeId] ?? {}, [field]: value };
1639
+ return lines;
1495
1640
  }
1496
- return out;
1641
+ if (err instanceof NodaroError && (err.code === "app_run_version_unavailable" || err.code === "continuation_not_failed")) {
1642
+ return [startOver];
1643
+ }
1644
+ if (err instanceof NodaroError && err.code === "already_running") {
1645
+ const live = err instanceof AlreadyRunningError ? `nodaro executions get ${shellQuote(err.executionId)} --watch` : `nodaro apps run-get ${shellQuote(slug)} ${shellQuote(runId)}`;
1646
+ return [` follow it: ${live}`];
1647
+ }
1648
+ if (err instanceof NodaroError && isPreviewRefusalCode(err.code)) {
1649
+ return [" retry it from the app page instead, where a person can review the Preview it stops at"];
1650
+ }
1651
+ return [];
1497
1652
  }
1498
1653
  function appsCommand() {
1499
1654
  const cmd = new Command("apps").description("browse and run published apps (workflows wrapped in a curated UI)");
@@ -1596,6 +1751,52 @@ Tip: \`nodaro apps get <slug>\` shows the input schema for that app.`).action(as
1596
1751
  handleError(err);
1597
1752
  }
1598
1753
  });
1754
+ cmd.command("run-retry <slug> <runId>").description("retry a failed app run from where it stopped: only the steps it did not complete run, and only those are charged").option("--dry-run", "show the steps the Retry would run and what it would charge; start nothing").option("--app-version <n>", "the app version you expect it to run (default: the app's latest); the run's own version continues it after the app changed", parseAppVersion).option("--watch", "follow the Retry's execution until completion").option("--profile <name>").option("--json").addHelpText("after", `
1755
+ The Retry runs the version the run ran, with the inputs the run applied (it takes none).
1756
+ To run with other inputs or on the app's current version, start over with \`nodaro apps run\`.
1757
+
1758
+ Examples:
1759
+ $ nodaro apps run-retry hair-styler-dd3erw 3f0c\u2026 --dry-run
1760
+ $ nodaro apps run-retry hair-styler-dd3erw 3f0c\u2026 --watch`).action(async (slug, runId, opts) => {
1761
+ try {
1762
+ const client = buildClient(opts.profile);
1763
+ if (opts.dryRun) {
1764
+ const { data: plan } = await client.apps.resume(slug, runId, { dryRun: true, version: opts.appVersion });
1765
+ if (opts.json) {
1766
+ emit(plan, opts);
1767
+ return;
1768
+ }
1769
+ table(
1770
+ plan.steps.map((s) => ({ node: s.nodeId, type: s.type, label: s.label ?? "" })),
1771
+ ["node", "type", "label"]
1772
+ );
1773
+ const price = plan.estimatedCredits === null ? "not billed in credits on this edition" : `about ${plan.estimatedCredits} credits`;
1774
+ const reused = plan.reusedClips > 0 ? `, ${plan.reusedClips} finished clip(s) handed back at no cost` : "";
1775
+ success(`Retry of run ${plan.runId} (app version ${plan.appVersion ?? "?"}): ${plan.steps.length} step(s), ${price}${reused}`);
1776
+ if (plan.sufficient === false) {
1777
+ warn(
1778
+ plan.appCreditsAllowance !== void 0 ? "you have no app credits left to run apps: the Retry would be refused" : `your balance cannot cover it${plan.available !== null ? ` (${plan.available} available)` : ""}: the Retry would be refused`
1779
+ );
1780
+ }
1781
+ dim(`start it: nodaro apps run-retry ${shellQuote(slug)} ${shellQuote(runId)}${opts.appVersion !== void 0 ? ` --app-version ${opts.appVersion}` : ""}`);
1782
+ return;
1783
+ }
1784
+ const result = await client.apps.resume(slug, runId, { version: opts.appVersion });
1785
+ if (opts.json && !opts.watch) {
1786
+ emit(result, opts);
1787
+ return;
1788
+ }
1789
+ success(`execution ${result.executionId} (${result.status})${result.deduped ? " \u2014 this Retry was already started" : ""}`);
1790
+ if (!opts.watch) {
1791
+ dim(`follow: nodaro executions get ${result.executionId} --watch`);
1792
+ return;
1793
+ }
1794
+ await watchExecution(client, result.executionId, opts);
1795
+ } catch (err) {
1796
+ for (const line of retryRefusalAdvice(slug, runId, err)) warn(line);
1797
+ handleError(err);
1798
+ }
1799
+ });
1599
1800
  return cmd;
1600
1801
  }
1601
1802
  var BATCH_NODE_TYPE = "generate-image";
@@ -3428,6 +3629,29 @@ names).`).action(
3428
3629
  }
3429
3630
  }
3430
3631
  );
3632
+ cmd.command("generate-mask <imageUrl> <prompt>").description("select a subject described in text in an image (Grounded SAM) and get a black-and-white mask image back (white = the subject)").option("--threshold <n>", `segmentation confidence ${GENERATE_MASK_LIMITS.THRESHOLD_MIN}\u2013${GENERATE_MASK_LIMITS.THRESHOLD_MAX} (default ${GENERATE_MASK_LIMITS.THRESHOLD_DEFAULT}; lower selects more)`, parseFloat).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", `
3633
+ Examples:
3634
+ $ nodaro media generate-mask https://x/portrait.png "the person" --watch
3635
+ $ nodaro media generate-mask https://x/landscape.jpg "sky and clouds" --threshold 0.2 --watch --json
3636
+
3637
+ The finished job's output carries \`maskUrl\` (the mask) and \`imageUrl\` (the source
3638
+ image, passed through unchanged): \`nodaro jobs get <jobId>\`. Use the mask for inpainting.`).action(async (imageUrl, prompt, opts) => {
3639
+ try {
3640
+ if (opts.threshold !== void 0 && !(opts.threshold >= GENERATE_MASK_LIMITS.THRESHOLD_MIN && opts.threshold <= GENERATE_MASK_LIMITS.THRESHOLD_MAX)) {
3641
+ warn(`--threshold must be between ${GENERATE_MASK_LIMITS.THRESHOLD_MIN} and ${GENERATE_MASK_LIMITS.THRESHOLD_MAX}`);
3642
+ process.exit(1);
3643
+ }
3644
+ const client = buildClient(opts.profile);
3645
+ const result = await client.nodes.run("generate-mask", {
3646
+ imageUrl,
3647
+ prompt,
3648
+ ...opts.threshold !== void 0 ? { threshold: opts.threshold } : {}
3649
+ });
3650
+ await reportQueuedJob(result, () => client.jobs.get(result.jobId), { ...opts, note: "mask" });
3651
+ } catch (err) {
3652
+ handleError(err);
3653
+ }
3654
+ });
3431
3655
  cmd.command("video-mask <videoUrl> <prompt>").description("track a subject described in text through a video (SAM 3.1, or --model sam-3 at half the price) and get a black-and-white mask video back (white = the subject)").option("--model <model>", `${VIDEO_MASK_PROVIDERS.join(" | ")} (default ${DEFAULT_VIDEO_MASK_PROVIDER})`).option("--threshold <n>", `detection confidence ${VIDEO_MASK_LIMITS.THRESHOLD_MIN}\u2013${VIDEO_MASK_LIMITS.THRESHOLD_MAX} (default ${VIDEO_MASK_LIMITS.THRESHOLD_DEFAULT}; lower finds more)`, parseFloat).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", `
3432
3656
  Examples:
3433
3657
  $ nodaro media video-mask https://x/dance.mp4 "the dancer" --watch
@@ -3826,15 +4050,15 @@ function presetsCommand() {
3826
4050
  const cmd = new Command("presets").description(
3827
4051
  "node presets \u2014 your own (create, update, delete, import, favorites, folders) plus the built-in factory catalog"
3828
4052
  );
3829
- cmd.command("list").description("list your custom presets (or the built-in factory catalog with --factory)").option("--node-type <type>", "filter to one node type, e.g. generate-image").option("--factory", "list the built-in factory catalog instead of your custom presets").option("--profile <name>").option("--json").action(async (opts) => {
4053
+ cmd.command("list").description("list your custom presets (or the built-in factory catalog with --factory, which needs no sign-in)").option("--node-type <type>", "filter to one node type, e.g. generate-image").option("--factory", "list the built-in factory catalog instead of your custom presets (no sign-in needed)").option("--base-url <url>", "with --factory: ask this instance instead (default: the profile's, else https://app.nodaro.ai)").option("--profile <name>").option("--json").action(async (opts) => {
3830
4054
  try {
3831
- const client = buildClient(opts.profile);
3832
4055
  if (opts.factory) {
3833
4056
  if (!opts.nodeType) {
3834
4057
  handleError(new Error("--node-type is required with --factory (e.g. --node-type generate-image)"));
3835
4058
  return;
3836
4059
  }
3837
- const result = await client.presets.listFactory(opts.nodeType);
4060
+ const client2 = buildPublicClient({ profile: opts.profile, baseUrl: opts.baseUrl });
4061
+ const result = await client2.presets.listFactory(opts.nodeType);
3838
4062
  if (opts.json) {
3839
4063
  emit(result, opts);
3840
4064
  return;
@@ -3851,6 +4075,10 @@ function presetsCommand() {
3851
4075
  );
3852
4076
  return;
3853
4077
  }
4078
+ if (opts.baseUrl !== void 0) {
4079
+ throw new Error("--base-url only applies with --factory; your own presets come from the profile's instance");
4080
+ }
4081
+ const client = buildClient(opts.profile);
3854
4082
  const presets = await client.presets.list(opts.nodeType);
3855
4083
  if (opts.json) {
3856
4084
  emit(presets, opts);
@@ -6712,14 +6940,6 @@ var SOURCE_LABELS = {
6712
6940
  profile: "the profile's saved workspace",
6713
6941
  none: "nothing \u2014 the personal space"
6714
6942
  };
6715
- function isEditPlanMode(v) {
6716
- return EDIT_PLAN_MODES.includes(v);
6717
- }
6718
- var CONTINUATION_NEXT_STEP = {
6719
- already_running: (id) => ` \u2014 follow it: nodaro jobs get ${id}`,
6720
- continuation_superseded: (id) => ` \u2014 continue that one: nodaro edit continue-use-case ${id} --mode from-failed`,
6721
- render_final_already_rendered: (id) => ` \u2014 its result is the one to use: nodaro jobs get ${id}`
6722
- };
6723
6943
  function readJsonFile2(path) {
6724
6944
  let raw;
6725
6945
  try {
@@ -6733,6 +6953,293 @@ function readJsonFile2(path) {
6733
6953
  throw new Error(`${path} is not valid JSON: ${err.message}`);
6734
6954
  }
6735
6955
  }
6956
+ function refuseUnknownPlanTier(planTier) {
6957
+ if (planTier !== void 0 && !EDIT_PLAN_TIERS.includes(planTier)) {
6958
+ warn(`--plan-tier must be ${EDIT_PLAN_TIERS.join(", ")} (got "${planTier}")`);
6959
+ process.exit(1);
6960
+ }
6961
+ }
6962
+ var EMPHASIS_HELP = `none, or ${SPEAKER_EMPHASIS_STYLES.filter((s) => s !== "none").join(", ")} joined with "+" (each once)`;
6963
+ var CONTINUATION_NEXT_STEP = {
6964
+ already_running: (id) => ` \u2014 follow it: nodaro jobs get ${id}`,
6965
+ continuation_superseded: (id) => ` \u2014 continue that one: nodaro edit continue-use-case ${id} --mode from-failed`,
6966
+ render_final_already_rendered: (id) => ` \u2014 its result is the one to use: nodaro jobs get ${id}`
6967
+ };
6968
+ function registerUseCaseCommands(cmd) {
6969
+ const framingLayouts = ["auto", ...SPEAKER_LAYOUT_IDS];
6970
+ cmd.command("tighten-episode").description("tighten a podcast recording in one step (transcribe, cut silences, render; optional captions, music and framing)").requiredOption("--media <url>", "the recording (video or audio URL, up to 3 hours)").option("--music <url>", "optional music bed, ducked under the voice").option("--output <kind>", "video | audio (an audio recording always makes an audio episode)").option("--framing <aspect>", `frame a video episode on its speakers: ${EDL_TARGET_ASPECTS.join(" | ")}`).option("--layout <layout>", `layout with --framing (default auto): ${framingLayouts.join(" | ")}`).option("--no-captions", "no captions on a video episode").option("--review", "stop at a preview to review (render the final with `nodaro edit continue-use-case <jobId> --mode render-final`)").option("--plan-tier <tier>", EDIT_PLAN_TIERS.join(" | ")).option("--instructions <text>", "editing instructions for the planner").option("--watch", "poll the job until it finishes").option("--poll-interval <ms>", "poll interval with --watch", (v) => parseInt(v, 10)).option("--profile <name>").option("--json").action(
6971
+ async (opts, command) => {
6972
+ if (opts.output !== void 0 && opts.output !== "video" && opts.output !== "audio") {
6973
+ warn(`--output must be "video" or "audio" (got "${opts.output}")`);
6974
+ process.exit(1);
6975
+ }
6976
+ refuseUnknownPlanTier(opts.planTier);
6977
+ if (opts.framing !== void 0 && !EDL_TARGET_ASPECTS.includes(opts.framing)) {
6978
+ warn(`--framing must be ${EDL_TARGET_ASPECTS.join(", ")} (got "${opts.framing}")`);
6979
+ process.exit(1);
6980
+ }
6981
+ if (opts.layout !== void 0 && opts.framing === void 0) {
6982
+ warn("--layout applies with --framing only (it picks the framed layout)");
6983
+ process.exit(1);
6984
+ }
6985
+ if (opts.layout !== void 0 && !framingLayouts.includes(opts.layout)) {
6986
+ warn(`--layout must be ${framingLayouts.join(", ")} (got "${opts.layout}")`);
6987
+ process.exit(1);
6988
+ }
6989
+ try {
6990
+ const client = buildClient(opts.profile);
6991
+ const result = await client.edit.tightenEpisode({
6992
+ mediaUrl: opts.media,
6993
+ ...opts.music ? { musicUrl: opts.music } : {},
6994
+ ...opts.output ? { output: opts.output } : {},
6995
+ ...opts.framing ? { framing: { aspect: opts.framing, layout: opts.layout ?? "auto" } } : {},
6996
+ // commander's --no-captions defaults `captions` to true: send it only when turned off.
6997
+ ...opts.captions === false ? { captions: false } : {},
6998
+ ...opts.review ? { reviewBeforeRender: true } : {},
6999
+ ...opts.planTier ? { planTier: opts.planTier } : {},
7000
+ ...opts.instructions ? { instructions: opts.instructions } : {}
7001
+ });
7002
+ await reportQueuedJob(result, () => client.jobs.getStatus(result.jobId), {
7003
+ json: opts.json,
7004
+ watch: opts.watch,
7005
+ pollInterval: opts.pollInterval,
7006
+ note: command.name()
7007
+ });
7008
+ } catch (err) {
7009
+ handleError(err);
7010
+ }
7011
+ }
7012
+ );
7013
+ cmd.command("episode-chapters").description("list a podcast recording's chapters in one step (transcribe, then plan the chapters); with --watch, prints the show notes").requiredOption("--media <url>", "the recording (video or audio URL, up to 3 hours)").option("--plan-tier <tier>", EDIT_PLAN_TIERS.join(" | ")).option("--instructions <text>", 'instructions for the chapters ("5 to 8 chapters")').option("--style-guide <text>", "a style guide for the chapter titles").option("--idempotency-key <key>", "sent as Idempotency-Key: a retry with the same key answers the run already started").option("--watch", "poll the job until it finishes, then print the chapter list").option("--poll-interval <ms>", "poll interval with --watch", (v) => parseInt(v, 10)).option("--profile <name>").option("--json").action(
7014
+ async (opts, command) => {
7015
+ refuseUnknownPlanTier(opts.planTier);
7016
+ try {
7017
+ const client = buildClient(opts.profile);
7018
+ const result = await client.edit.episodeChapters(
7019
+ {
7020
+ mediaUrl: opts.media,
7021
+ ...opts.planTier ? { planTier: opts.planTier } : {},
7022
+ ...opts.instructions ? { instructions: opts.instructions } : {},
7023
+ ...opts.styleGuide ? { styleGuide: opts.styleGuide } : {}
7024
+ },
7025
+ opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : void 0
7026
+ );
7027
+ const done = await reportQueuedJob(result, () => client.jobs.getStatus(result.jobId), {
7028
+ json: opts.json,
7029
+ watch: opts.watch,
7030
+ pollInterval: opts.pollInterval,
7031
+ note: command.name()
7032
+ });
7033
+ const text = done?.data.output_data?.text;
7034
+ if (!opts.json && done?.data.status === "completed" && typeof text === "string" && text.length > 0) console.log(text);
7035
+ } catch (err) {
7036
+ handleError(err);
7037
+ }
7038
+ }
7039
+ );
7040
+ cmd.command("episode-trailer").description("cut a 20\u201340 second trailer of a recording and deliver it in each chosen social format, in one step").requiredOption("--media <url>", "the recording (a video URL, up to 3 hours)").option("--intro-card <url>", "an optional short video (15 s at most) played before the trailer").option("--formats <list>", `comma-separated, at least one: ${TRAILER_FORMATS.join(",")} (default 9:16,1:1,4:5)`).option("--review", "stop at a preview to review (render every format with `nodaro edit continue-use-case <jobId> --mode render-final`)").option("--plan-tier <tier>", EDIT_PLAN_TIERS.join(" | ")).option("--instructions <text>", "instructions for the trailer").option("--style-guide <text>", "a style guide for the plan").option("--idempotency-key <key>", "sent as Idempotency-Key: a retry with the same key answers the run already started").option("--watch", "poll the job until it finishes, then print each format's URL").option("--poll-interval <ms>", "poll interval with --watch", (v) => parseInt(v, 10)).option("--profile <name>").option("--json").action(
7041
+ async (opts) => {
7042
+ const formats = opts.formats?.split(",").map((f) => f.trim()).filter((f) => f.length > 0);
7043
+ if (formats !== void 0 && (formats.length === 0 || formats.some((f) => !TRAILER_FORMATS.includes(f)))) {
7044
+ warn(`--formats must be one or more of ${TRAILER_FORMATS.join(", ")}, comma-separated (got "${opts.formats}")`);
7045
+ process.exit(1);
7046
+ }
7047
+ refuseUnknownPlanTier(opts.planTier);
7048
+ try {
7049
+ const client = buildClient(opts.profile);
7050
+ const result = await client.edit.episodeTrailer(
7051
+ {
7052
+ mediaUrl: opts.media,
7053
+ ...opts.introCard ? { introCardUrl: opts.introCard } : {},
7054
+ ...formats ? { formats } : {},
7055
+ ...opts.review ? { reviewBeforeRender: true } : {},
7056
+ ...opts.planTier ? { planTier: opts.planTier } : {},
7057
+ ...opts.instructions ? { instructions: opts.instructions } : {},
7058
+ ...opts.styleGuide ? { styleGuide: opts.styleGuide } : {}
7059
+ },
7060
+ opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : void 0
7061
+ );
7062
+ const done = await reportQueuedJob(result, () => client.jobs.getStatus(result.jobId), {
7063
+ json: opts.json,
7064
+ watch: opts.watch,
7065
+ pollInterval: opts.pollInterval,
7066
+ note: "episode-trailer"
7067
+ });
7068
+ if (opts.json) return;
7069
+ const out = done?.data.output_data;
7070
+ if (done?.data.status === "completed" && Array.isArray(out?.formats)) {
7071
+ for (const f of out.formats) {
7072
+ if (typeof f?.format === "string" && typeof f.url === "string") console.log(`${f.format} ${f.url}`);
7073
+ }
7074
+ const failed = Array.isArray(out.failedFormats) ? out.failedFormats.filter((f) => typeof f === "string") : [];
7075
+ if (failed.length > 0) console.log(`Could not render: ${failed.join(", ")}`);
7076
+ }
7077
+ if (opts.review) console.log(pc3.dim(` render every format after your review: nodaro edit continue-use-case ${result.jobId} --mode render-final`));
7078
+ } catch (err) {
7079
+ handleError(err);
7080
+ }
7081
+ }
7082
+ );
7083
+ const isWhole = (v, min, max) => v !== void 0 && /^\d+$/.test(v.trim()) && Number(v) >= min && Number(v) <= max;
7084
+ cmd.command("clip-pack").description("cut a recording into a pack of short clips in one step (find the best moments, render each \u2014 framed and captioned by default)").requiredOption("--media <url>", "the recording (video or audio URL, up to 3 hours; an audio recording makes audio clips)").option("--count <n>", `how many clips, 1\u2013${EDIT_PLAN_MAX_CLIP_COUNT} (default 8; the plan may find fewer)`).option("--length <sec>", `each clip's target length in seconds, ${CLIP_PACK_MIN_TARGET_SEC}\u2013${CLIP_PACK_MAX_TARGET_SEC} (default 60)`).option("--framing <aspect>", `frame each clip on its speakers: ${EDL_TARGET_ASPECTS.join(" | ")}, or none for the recording's shape (default 9:16)`).option("--layout <layout>", `layout with --framing <aspect> (default stacked): ${framingLayouts.join(" | ")}`).option("--switch <id>", `the switch at each speaker change, with --framing <aspect> (default pan): cut | pan | zoom | xfade:<transition>, e.g. xfade:fade`).option("--emphasis <style>", `how the speaker talking is emphasised, with --framing <aspect> (default scale): ${EMPHASIS_HELP}`).option("--no-captions", "no captions on the clips").option("--caption-style <style>", `the captions' look (default karaoke): ${ALL_CAPTION_STYLES.join(" | ")}`).option("--review", "stop at previews to review (render the kept clips with `nodaro edit continue-use-case <jobId> --mode render-final`)").option("--plan-tier <tier>", EDIT_PLAN_TIERS.join(" | ")).option("--instructions <text>", "instructions for picking the clips").option("--style-guide <text>", "a style guide for the plan").option("--idempotency-key <key>", "sent as Idempotency-Key: a retry with the same key answers the run already started").option("--watch", "poll the job until it finishes, then print each clip's URL").option("--poll-interval <ms>", "poll interval with --watch", (v) => parseInt(v, 10)).option("--profile <name>").option("--json").action(
7085
+ async (opts) => {
7086
+ if (opts.count !== void 0 && !isWhole(opts.count, 1, EDIT_PLAN_MAX_CLIP_COUNT)) {
7087
+ warn(`--count must be 1\u2013${EDIT_PLAN_MAX_CLIP_COUNT} (got "${opts.count}")`);
7088
+ process.exit(1);
7089
+ }
7090
+ if (opts.length !== void 0 && !isWhole(opts.length, CLIP_PACK_MIN_TARGET_SEC, CLIP_PACK_MAX_TARGET_SEC)) {
7091
+ warn(`--length must be ${CLIP_PACK_MIN_TARGET_SEC}\u2013${CLIP_PACK_MAX_TARGET_SEC} seconds (got "${opts.length}")`);
7092
+ process.exit(1);
7093
+ }
7094
+ if (opts.framing !== void 0 && opts.framing !== "none" && !EDL_TARGET_ASPECTS.includes(opts.framing)) {
7095
+ warn(`--framing must be ${EDL_TARGET_ASPECTS.join(", ")} or none (got "${opts.framing}")`);
7096
+ process.exit(1);
7097
+ }
7098
+ if (opts.layout !== void 0 && (opts.framing === void 0 || opts.framing === "none")) {
7099
+ warn("--layout applies with --framing <aspect> only (it picks the framed layout)");
7100
+ process.exit(1);
7101
+ }
7102
+ if (opts.layout !== void 0 && !framingLayouts.includes(opts.layout)) {
7103
+ warn(`--layout must be ${framingLayouts.join(", ")} (got "${opts.layout}")`);
7104
+ process.exit(1);
7105
+ }
7106
+ for (const [flag, value] of [["--switch", opts.switch], ["--emphasis", opts.emphasis]]) {
7107
+ if (value !== void 0 && (opts.framing === void 0 || opts.framing === "none")) {
7108
+ warn(`${flag} applies with --framing <aspect> only (it is part of the framing)`);
7109
+ process.exit(1);
7110
+ }
7111
+ }
7112
+ if (opts.switch !== void 0 && !SPEAKER_SWITCH_IDS.includes(opts.switch)) {
7113
+ warn(`--switch must be one of ${SPEAKER_SWITCH_IDS.join(", ")} (got "${opts.switch}")`);
7114
+ process.exit(1);
7115
+ }
7116
+ if (opts.emphasis !== void 0 && !isKnownSpeakerEmphasisStyle(opts.emphasis)) {
7117
+ warn(`--emphasis must be ${EMPHASIS_HELP} (got "${opts.emphasis}")`);
7118
+ process.exit(1);
7119
+ }
7120
+ if (opts.captionStyle !== void 0 && opts.captions === false) {
7121
+ warn("--caption-style applies with captions on (drop --no-captions)");
7122
+ process.exit(1);
7123
+ }
7124
+ if (opts.captionStyle !== void 0 && !ALL_CAPTION_STYLES.includes(opts.captionStyle)) {
7125
+ warn(`--caption-style must be ${ALL_CAPTION_STYLES.join(", ")} (got "${opts.captionStyle}")`);
7126
+ process.exit(1);
7127
+ }
7128
+ refuseUnknownPlanTier(opts.planTier);
7129
+ try {
7130
+ const client = buildClient(opts.profile);
7131
+ const result = await client.edit.clipPack(
7132
+ {
7133
+ mediaUrl: opts.media,
7134
+ ...opts.count !== void 0 ? { count: Number(opts.count) } : {},
7135
+ ...opts.length !== void 0 ? { targetDurationSec: Number(opts.length) } : {},
7136
+ // none = the recording's shape; an aspect alone leaves the layout to the route (stacked).
7137
+ ...opts.framing === "none" ? { framing: null } : opts.framing ? {
7138
+ framing: {
7139
+ aspect: opts.framing,
7140
+ ...opts.layout ? { layout: opts.layout } : {},
7141
+ ...opts.switch ? { switchType: opts.switch } : {},
7142
+ ...opts.emphasis ? { emphasisStyle: opts.emphasis } : {}
7143
+ }
7144
+ } : {},
7145
+ // commander's --no-captions defaults `captions` to true: send it only when turned off.
7146
+ ...opts.captions === false ? { captions: false } : {},
7147
+ ...opts.captionStyle ? { captionStyle: opts.captionStyle } : {},
7148
+ ...opts.review ? { reviewBeforeRender: true } : {},
7149
+ ...opts.planTier ? { planTier: opts.planTier } : {},
7150
+ ...opts.instructions ? { instructions: opts.instructions } : {},
7151
+ ...opts.styleGuide ? { styleGuide: opts.styleGuide } : {}
7152
+ },
7153
+ opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : void 0
7154
+ );
7155
+ const done = await reportQueuedJob(result, () => client.jobs.getStatus(result.jobId), {
7156
+ json: opts.json,
7157
+ watch: opts.watch,
7158
+ pollInterval: opts.pollInterval,
7159
+ note: "clip-pack"
7160
+ });
7161
+ if (opts.json) return;
7162
+ const out = done?.data.output_data;
7163
+ if (done?.data.status === "completed" && Array.isArray(out?.clips)) {
7164
+ ;
7165
+ out.clips.forEach((c, i) => {
7166
+ if (typeof c?.url !== "string") return;
7167
+ const note = [typeof c.title === "string" ? c.title : "", c.captionsFailed === true ? "(no captions)" : ""].filter(Boolean).join(" ");
7168
+ console.log(`${i + 1} ${c.url}${note ? ` ${note}` : ""}`);
7169
+ });
7170
+ const failed = typeof out.failedClips === "number" && out.failedClips > 0 ? out.failedClips : 0;
7171
+ if (failed > 0) console.log(failed === 1 ? "1 clip could not be rendered." : `${failed} clips could not be rendered.`);
7172
+ }
7173
+ if (opts.review) console.log(pc3.dim(` render the kept clips after your review: nodaro edit continue-use-case ${result.jobId} --mode render-final [--edit <file>]`));
7174
+ } catch (err) {
7175
+ handleError(err);
7176
+ }
7177
+ }
7178
+ );
7179
+ cmd.command("continue-use-case <jobId>").description("continue a Tighten Episode, Chapters, Trailer or Clip Pack run as a new job: from where it failed, or its Render final after a review").requiredOption("--mode <mode>", "from-failed | render-final").option("--edit <file>", "render-final only: a JSON file holding the reviewer's edit of the plan (an EDL)").option(
7180
+ "--type <type>",
7181
+ `the run's node type (${USE_CASE_NODE_TYPES.join(" | ")}); without it the job is read for its type, which needs the jobs:read scope`
7182
+ ).option("--idempotency-key <key>", "sent as Idempotency-Key: a retry with the same key answers the run already started").option("--watch", "poll the job until it finishes").option("--poll-interval <ms>", "poll interval with --watch", (v) => parseInt(v, 10)).option("--profile <name>").option("--json").action(async (jobId, opts) => {
7183
+ if (opts.mode !== "from-failed" && opts.mode !== "render-final") {
7184
+ warn(`--mode must be "from-failed" or "render-final" (got "${opts.mode}")`);
7185
+ process.exit(1);
7186
+ }
7187
+ if (opts.type !== void 0 && !USE_CASE_NODE_TYPES.includes(opts.type)) {
7188
+ warn(`--type must be ${USE_CASE_NODE_TYPES.join(", ")} (got "${opts.type}")`);
7189
+ process.exit(1);
7190
+ }
7191
+ if (opts.edit !== void 0 && opts.mode !== "render-final") {
7192
+ warn("--edit applies to --mode render-final only");
7193
+ process.exit(1);
7194
+ }
7195
+ try {
7196
+ const client = buildClient(opts.profile);
7197
+ const result = await client.edit.continueUseCase(
7198
+ {
7199
+ jobId,
7200
+ mode: opts.mode,
7201
+ ...opts.edit !== void 0 ? { editedEdl: readJsonFile2(opts.edit) } : {},
7202
+ ...opts.type !== void 0 ? { nodeType: opts.type } : {}
7203
+ },
7204
+ opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : void 0
7205
+ );
7206
+ await reportQueuedJob(result, () => client.jobs.getStatus(result.jobId), {
7207
+ json: opts.json,
7208
+ watch: opts.watch,
7209
+ pollInterval: opts.pollInterval,
7210
+ note: `continue-use-case (${opts.mode})`
7211
+ });
7212
+ } catch (err) {
7213
+ if (err instanceof ContinuationRefusedError) {
7214
+ if (opts.json) {
7215
+ emit({ error: { code: err.code, message: err.message }, jobId: err.jobId }, opts);
7216
+ } else {
7217
+ console.error(pc3.red(`\u2717 ${err.message}`));
7218
+ console.error(pc3.dim(` code: ${err.code}`));
7219
+ console.error(pc3.dim(` job: ${err.jobId}${CONTINUATION_NEXT_STEP[err.code]?.(err.jobId) ?? ""}`));
7220
+ }
7221
+ process.exit(1);
7222
+ }
7223
+ if (err instanceof NodaroError && err.code === "use_case_type_unknown") {
7224
+ const message = "pass --type <node type> (this key can't read the job's type)";
7225
+ if (opts.json) {
7226
+ emit({ error: { code: err.code, message } }, opts);
7227
+ } else {
7228
+ console.error(pc3.red(`\u2717 ${message}`));
7229
+ console.error(pc3.dim(` code: ${err.code}`));
7230
+ console.error(pc3.dim(` --type: ${USE_CASE_NODE_TYPES.join(" | ")}`));
7231
+ }
7232
+ process.exit(1);
7233
+ }
7234
+ handleError(err);
7235
+ }
7236
+ });
7237
+ }
7238
+
7239
+ // src/commands/edit.ts
7240
+ function isEditPlanMode(v) {
7241
+ return EDIT_PLAN_MODES.includes(v);
7242
+ }
6736
7243
  function parseSourceSpec(spec, index2) {
6737
7244
  const named = /^([^=\s]{1,200})=(https?:\/\/.+)$/.exec(spec);
6738
7245
  const id = named ? named[1] : `source-${index2 + 1}`;
@@ -6813,6 +7320,39 @@ function editCommand() {
6813
7320
  }
6814
7321
  }
6815
7322
  );
7323
+ cmd.command("speaker-map").description("work out which camera each speaker is on, from the cameras' own microphones (keyless)").option(
7324
+ "--source <[id=]url>",
7325
+ "a camera (or the master / wide) as url or id=url (repeatable, 2-6); ids are minted as source-N when omitted",
7326
+ collectVariadic
7327
+ ).option("--sources-file <file>", "JSON array of { id, url } rows (overrides --source)").requiredOption("--transcript <file>", "path to the transcript JSON WITH speaker labels (transcribe with speaker detection)").option("--offsets <file>", "an audio-sync result JSON (the job's output_data.json); omit when the recordings share a clock").option("--master <id>", "the master audio's id: hears everyone, so it is no one's camera").option("--wide <id>", "the wide shot's id: no one's camera; a speaker with no clear camera is shown on it").option("--margin-db <db>", "how much louder the loudest camera must be than the next (default 3)", (v) => Number(v)).option("--watch", "poll the job until it finishes").option("--poll-interval <ms>", "poll interval with --watch", (v) => parseInt(v, 10)).option("--profile <name>").option("--json").action(
7328
+ async (opts) => {
7329
+ const sources = opts.sourcesFile ? readJsonFile2(opts.sourcesFile) : (opts.source ?? []).map(parseAudioSyncSource);
7330
+ if (!Array.isArray(sources) || sources.length < 2 || sources.length > 6) {
7331
+ warn("speaker-map takes 2-6 recordings \u2014 pass --source <url> (repeatable) or --sources-file <file> (a JSON array of { id, url } rows)");
7332
+ process.exit(1);
7333
+ }
7334
+ try {
7335
+ const client = buildClient(opts.profile);
7336
+ const input2 = {
7337
+ sources,
7338
+ transcript: readJsonFile2(opts.transcript),
7339
+ ...opts.offsets ? { offsets: readJsonFile2(opts.offsets) } : {},
7340
+ ...opts.master !== void 0 ? { masterSourceId: opts.master } : {},
7341
+ ...opts.wide !== void 0 ? { wideSourceId: opts.wide } : {},
7342
+ ...opts.marginDb !== void 0 ? { marginDb: opts.marginDb } : {}
7343
+ };
7344
+ const result = await client.edit.speakerMap(input2);
7345
+ await reportQueuedJob(result, () => client.jobs.getStatus(result.jobId), {
7346
+ json: opts.json,
7347
+ watch: opts.watch,
7348
+ pollInterval: opts.pollInterval,
7349
+ note: `speaker-map (${sources.length} sources)`
7350
+ });
7351
+ } catch (err) {
7352
+ handleError(err);
7353
+ }
7354
+ }
7355
+ );
6816
7356
  cmd.command("apply-edl").description("render an edit decision list into a video or audio cut").requiredOption("--edl <file>", "path to a JSON file holding the EDL").option("--transcript <file>", "optional transcript JSON to remap through the cut").option("--source <url>", "positional media-URL override for edl.sources[i] (repeatable)", collectVariadic).option("--output <kind>", "video | audio", "video").option("--quality <q>", "proxy | final", "final").option("--crossfade-ms <ms>", "default crossfade on boundaries with no transition", (v) => parseInt(v, 10)).option(
6817
7357
  "--clip-key <key>",
6818
7358
  'the plan clip this render cuts, "<first inMs>-<last outMs>" of a clips-mode plan clip; stamped back on the result as clipKey'
@@ -6848,92 +7388,7 @@ function editCommand() {
6848
7388
  }
6849
7389
  }
6850
7390
  );
6851
- const framingLayouts = ["auto", ...SPEAKER_LAYOUT_IDS];
6852
- cmd.command("tighten-episode").description("tighten a podcast recording in one step (transcribe, cut silences, render; optional captions, music and framing)").requiredOption("--media <url>", "the recording (video or audio URL, up to 3 hours)").option("--music <url>", "optional music bed, ducked under the voice").option("--output <kind>", "video | audio (an audio recording always makes an audio episode)").option("--framing <aspect>", `frame a video episode on its speakers: ${EDL_TARGET_ASPECTS.join(" | ")}`).option("--layout <layout>", `layout with --framing (default auto): ${framingLayouts.join(" | ")}`).option("--no-captions", "no captions on a video episode").option("--review", "stop at a preview to review (render the final with `nodaro edit continue-use-case <jobId> --mode render-final`)").option("--plan-tier <tier>", EDIT_PLAN_TIERS.join(" | ")).option("--instructions <text>", "editing instructions for the planner").option("--watch", "poll the job until it finishes").option("--poll-interval <ms>", "poll interval with --watch", (v) => parseInt(v, 10)).option("--profile <name>").option("--json").action(
6853
- async (opts) => {
6854
- if (opts.output !== void 0 && opts.output !== "video" && opts.output !== "audio") {
6855
- warn(`--output must be "video" or "audio" (got "${opts.output}")`);
6856
- process.exit(1);
6857
- }
6858
- if (opts.planTier !== void 0 && !EDIT_PLAN_TIERS.includes(opts.planTier)) {
6859
- warn(`--plan-tier must be ${EDIT_PLAN_TIERS.join(", ")} (got "${opts.planTier}")`);
6860
- process.exit(1);
6861
- }
6862
- if (opts.framing !== void 0 && !EDL_TARGET_ASPECTS.includes(opts.framing)) {
6863
- warn(`--framing must be ${EDL_TARGET_ASPECTS.join(", ")} (got "${opts.framing}")`);
6864
- process.exit(1);
6865
- }
6866
- if (opts.layout !== void 0 && opts.framing === void 0) {
6867
- warn("--layout applies with --framing only (it picks the framed layout)");
6868
- process.exit(1);
6869
- }
6870
- if (opts.layout !== void 0 && !framingLayouts.includes(opts.layout)) {
6871
- warn(`--layout must be ${framingLayouts.join(", ")} (got "${opts.layout}")`);
6872
- process.exit(1);
6873
- }
6874
- try {
6875
- const client = buildClient(opts.profile);
6876
- const result = await client.edit.tightenEpisode({
6877
- mediaUrl: opts.media,
6878
- ...opts.music ? { musicUrl: opts.music } : {},
6879
- ...opts.output ? { output: opts.output } : {},
6880
- ...opts.framing ? { framing: { aspect: opts.framing, layout: opts.layout ?? "auto" } } : {},
6881
- // commander's --no-captions defaults `captions` to true: send it only when turned off.
6882
- ...opts.captions === false ? { captions: false } : {},
6883
- ...opts.review ? { reviewBeforeRender: true } : {},
6884
- ...opts.planTier ? { planTier: opts.planTier } : {},
6885
- ...opts.instructions ? { instructions: opts.instructions } : {}
6886
- });
6887
- await reportQueuedJob(result, () => client.jobs.getStatus(result.jobId), {
6888
- json: opts.json,
6889
- watch: opts.watch,
6890
- pollInterval: opts.pollInterval,
6891
- note: "tighten-episode"
6892
- });
6893
- } catch (err) {
6894
- handleError(err);
6895
- }
6896
- }
6897
- );
6898
- cmd.command("continue-use-case <jobId>").description("continue a Tighten Episode run as a new job: from where it failed, or its Render final after a review").requiredOption("--mode <mode>", "from-failed | render-final").option("--edit <file>", "render-final only: a JSON file holding the reviewer's edit of the plan (an EDL)").option("--idempotency-key <key>", "sent as Idempotency-Key: a retry with the same key answers the run already started").option("--watch", "poll the job until it finishes").option("--poll-interval <ms>", "poll interval with --watch", (v) => parseInt(v, 10)).option("--profile <name>").option("--json").action(async (jobId, opts) => {
6899
- if (opts.mode !== "from-failed" && opts.mode !== "render-final") {
6900
- warn(`--mode must be "from-failed" or "render-final" (got "${opts.mode}")`);
6901
- process.exit(1);
6902
- }
6903
- if (opts.edit !== void 0 && opts.mode !== "render-final") {
6904
- warn("--edit applies to --mode render-final only");
6905
- process.exit(1);
6906
- }
6907
- try {
6908
- const client = buildClient(opts.profile);
6909
- const result = await client.edit.continueUseCase(
6910
- {
6911
- jobId,
6912
- mode: opts.mode,
6913
- ...opts.edit !== void 0 ? { editedEdl: readJsonFile2(opts.edit) } : {}
6914
- },
6915
- opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : void 0
6916
- );
6917
- await reportQueuedJob(result, () => client.jobs.getStatus(result.jobId), {
6918
- json: opts.json,
6919
- watch: opts.watch,
6920
- pollInterval: opts.pollInterval,
6921
- note: `continue-use-case (${opts.mode})`
6922
- });
6923
- } catch (err) {
6924
- if (err instanceof ContinuationRefusedError) {
6925
- if (opts.json) {
6926
- emit({ error: { code: err.code, message: err.message }, jobId: err.jobId }, opts);
6927
- } else {
6928
- console.error(pc3.red(`\u2717 ${err.message}`));
6929
- console.error(pc3.dim(` code: ${err.code}`));
6930
- console.error(pc3.dim(` job: ${err.jobId}${CONTINUATION_NEXT_STEP[err.code]?.(err.jobId) ?? ""}`));
6931
- }
6932
- process.exit(1);
6933
- }
6934
- handleError(err);
6935
- }
6936
- });
7391
+ registerUseCaseCommands(cmd);
6937
7392
  cmd.command("plan").description("plan a transcript-driven cut / clips / chapters / trailer (Cloud edition)").requiredOption("--mode <mode>", EDIT_PLAN_MODES.join(" | ")).requiredOption("--plan-tier <tier>", "economy | standard | premium").requiredOption("--transcript <file>", "path to a timed transcript JSON file").option("--silence <file>", "optional silence JSON \u2014 the silence-detect job's output_data.json ({ version, ranges, durationMs })").option(
6938
7393
  "--source <url>",
6939
7394
  "a media source as [id=]url[@audio|@video] (repeatable); id defaults to source-N, kind to video",
@@ -6999,7 +7454,7 @@ function editCommand() {
6999
7454
  }
7000
7455
  }
7001
7456
  );
7002
- cmd.command("switch-cameras").description("choose which camera shows each cut of an edit by who is speaking (Cloud edition; flat price)").requiredOption("--edl <file>", "path to ONE EDL JSON (an `edit plan` result)").requiredOption("--transcript <file>", "path to the transcript JSON WITH speaker labels (transcribe with speaker detection)").option("--speaker-map <file>", "JSON object: speaker label \u2192 EDL source id of their camera").option("--speaker-names <file>", "JSON object: speaker label \u2192 display name").option("--min-shot-ms <ms>", "shortest shot (default 2500)", (v) => parseInt(v, 10)).option("--lead-ms <ms>", "cut this long before the new speaker (default 200)", (v) => parseInt(v, 10)).option("--max-shot-ms <ms>", "with a wide source: break to it after this long (default 20000)", (v) => parseInt(v, 10)).option("--wide-every <n>", "with a wide source: every N-th cut to the wide (default 0 = off)", (v) => parseInt(v, 10)).option("--layout-hints", "suggest side-by-side / stacked layouts for crosstalk (Apply EDL renders cut-only edits)").option("--watch", "poll the job until it finishes").option("--poll-interval <ms>", "poll interval with --watch", (v) => parseInt(v, 10)).option("--profile <name>").option("--json").action(
7457
+ cmd.command("switch-cameras").description("choose which camera shows each cut of an edit by who is speaking (Cloud edition; flat price)").requiredOption("--edl <file>", "path to ONE EDL JSON (an `edit plan` result)").requiredOption("--transcript <file>", "path to the transcript JSON WITH speaker labels (transcribe with speaker detection)").option("--speaker-map <file>", "JSON object: speaker label \u2192 EDL source id of their camera").option("--speaker-map-result <file>", "a speaker-map result JSON (the job's output_data.json); a label in --speaker-map wins over it").option("--speaker-names <file>", "JSON object: speaker label \u2192 display name").option("--min-shot-ms <ms>", "shortest shot (default 2500)", (v) => parseInt(v, 10)).option("--lead-ms <ms>", "cut this long before the new speaker (default 200)", (v) => parseInt(v, 10)).option("--max-shot-ms <ms>", "with a wide source: break to it after this long (default 20000)", (v) => parseInt(v, 10)).option("--wide-every <n>", "with a wide source: every N-th cut to the wide (default 0 = off)", (v) => parseInt(v, 10)).option("--layout-hints", "suggest side-by-side / stacked layouts for crosstalk (Apply EDL renders cut-only edits)").option("--watch", "poll the job until it finishes").option("--poll-interval <ms>", "poll interval with --watch", (v) => parseInt(v, 10)).option("--profile <name>").option("--json").action(
7003
7458
  async (opts) => {
7004
7459
  try {
7005
7460
  const client = buildClient(opts.profile);
@@ -7007,6 +7462,7 @@ function editCommand() {
7007
7462
  edl: readJsonFile2(opts.edl),
7008
7463
  transcript: readJsonFile2(opts.transcript),
7009
7464
  ...opts.speakerMap ? { speakerMap: readJsonFile2(opts.speakerMap) } : {},
7465
+ ...opts.speakerMapResult ? { speakerMapResult: readJsonFile2(opts.speakerMapResult) } : {},
7010
7466
  ...opts.speakerNames ? { speakerNames: readJsonFile2(opts.speakerNames) } : {},
7011
7467
  ...opts.minShotMs !== void 0 ? { minShotMs: opts.minShotMs } : {},
7012
7468
  ...opts.leadMs !== void 0 ? { leadMs: opts.leadMs } : {},