blitzreels 0.1.32 → 0.1.34

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.
@@ -31,6 +31,9 @@ export type FacelessCommandHelpers = {
31
31
  flags: Flags;
32
32
  name: string;
33
33
  }) => string;
34
+ sleep: (params: {
35
+ ms: number;
36
+ }) => Promise<void>;
34
37
  printResult: (params: {
35
38
  json: boolean;
36
39
  value: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"faceless.d.ts","sourceRoot":"","sources":["../../src/commands/faceless.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAc,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,KAAK,WAAW,EAAe,MAAM,wBAAwB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAiH/C,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,aAAa,EAAE,CAAC,MAAM,EAAE;QACtB,IAAI,EAAE,WAAW,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;KAClB,KAAK,aAAa,CAAC;IACpB,aAAa,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,GAAG,SAAS,CAAC;IAC9E,sBAAsB,EAAE,CAAC,MAAM,EAAE;QAC/B,KAAK,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,OAAO,GAAG,SAAS,CAAC;IAC1B,aAAa,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,KAAK,CA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import { createHash, randomUUID } from "node:crypto";
2
+ import { readFileSync, writeFileSync } from "node:fs";
2
3
  import { resolve } from "node:path";
3
- import { CliUsageError } from "../cli-errors.js";
4
+ import { CliOperationError, CliUsageError } from "../cli-errors.js";
4
5
  import { commandSpec } from "../command-metadata.js";
6
+ const CREATIVE_MODE_USAGE = "[--genre ID] [--storyboard] [--multi-shot] [--clip-seconds 15]";
7
+ const CREATIVE_MODE_FLAGS = [
8
+ {
9
+ name: "genre",
10
+ description: "Genre pack id, such as dark-wild-documentary. `generate models --kind faceless` lists them.",
11
+ },
12
+ {
13
+ name: "storyboard",
14
+ type: "boolean",
15
+ description: "Generate one storyboard sheet for approval instead of per-scene keyframes, and use it as the video reference.",
16
+ },
17
+ {
18
+ name: "multi-shot",
19
+ type: "boolean",
20
+ description: "Let each video generation cover several timed shots. Implied by --storyboard.",
21
+ },
22
+ {
23
+ name: "clip-seconds",
24
+ description: "Target length of each multi-shot generation. Must be supported by the video model.",
25
+ },
26
+ ];
5
27
  export const FACELESS_COMMAND_SPECS = [
28
+ commandSpec({
29
+ command: ["faceless", "runs", "start"],
30
+ usage: `blitzreels faceless runs start (--script TEXT | --script-file FILE) [--project-name NAME] [--duration 45] [--story-kit-id ID] [--series-id ID] ${CREATIVE_MODE_USAGE} [--visual-style TEXT] [--planner-model MODEL] [--image-model MODEL] [--video-model MODEL] [--voice-id ID] [--no-voiceover] [--no-captions] [--caption-style-id ID] [--background-music] [--sound-effects] [--character-ids ID,ID] [--style-reference-ids ID,ID] [--max-credits 400] [--auto-approve] [--no-export] [--resolution 1080p] [--no-watermark] [--output FILE] [--no-wait] [--timeout-seconds 3600] [--idempotency-key KEY] [--dry-run] [--json]`,
31
+ description: "Start a film run from script to MP4, stopping at each approval gate.",
32
+ mutates: true,
33
+ dryRunSupported: true,
34
+ flags: [
35
+ "script",
36
+ "script-file",
37
+ "project-name",
38
+ "duration",
39
+ "story-kit-id",
40
+ "series-id",
41
+ ...CREATIVE_MODE_FLAGS,
42
+ "visual-style",
43
+ "planner-model",
44
+ "image-model",
45
+ "video-model",
46
+ "voice-id",
47
+ { name: "no-voiceover", type: "boolean" },
48
+ { name: "no-captions", type: "boolean" },
49
+ "caption-style-id",
50
+ { name: "background-music", type: "boolean" },
51
+ { name: "sound-effects", type: "boolean" },
52
+ "character-ids",
53
+ "style-reference-ids",
54
+ {
55
+ name: "max-credits",
56
+ description: "Budget checked against the quote and before each paid stage. The run pauses rather than exceed it.",
57
+ },
58
+ {
59
+ name: "auto-approve",
60
+ type: "boolean",
61
+ description: "Skip both approval gates and run unattended.",
62
+ },
63
+ {
64
+ name: "no-export",
65
+ type: "boolean",
66
+ description: "Stop at the finished timeline without rendering an MP4.",
67
+ },
68
+ "resolution",
69
+ { name: "no-watermark", type: "boolean" },
70
+ { name: "output", description: "Save the finished MP4 to this path." },
71
+ { name: "no-wait", type: "boolean" },
72
+ "timeout-seconds",
73
+ {
74
+ name: "idempotency-key",
75
+ description: "Defaults to a hash of the request, so rerunning the same command resumes the same run.",
76
+ },
77
+ ],
78
+ }),
79
+ commandSpec({
80
+ command: ["faceless", "runs", "get"],
81
+ usage: "blitzreels faceless runs get --run-id ID [--output FILE] [--wait] [--timeout-seconds 3600] [--json]",
82
+ description: "Show a run's stage, review images, spend and next action.",
83
+ flags: [
84
+ "run-id",
85
+ { name: "output", description: "Save the finished MP4 to this path." },
86
+ { name: "wait", type: "boolean" },
87
+ "timeout-seconds",
88
+ ],
89
+ }),
90
+ commandSpec({
91
+ command: ["faceless", "runs", "approve"],
92
+ usage: "blitzreels faceless runs approve --run-id ID --gate plan|keyframes --revision-id ID [--output FILE] [--no-wait] [--timeout-seconds 3600] [--idempotency-key KEY] [--dry-run] [--json]",
93
+ description: "Approve a run gate and start the next paid stage.",
94
+ mutates: true,
95
+ dryRunSupported: true,
96
+ flags: [
97
+ "run-id",
98
+ "gate",
99
+ "revision-id",
100
+ { name: "output", description: "Save the finished MP4 to this path." },
101
+ { name: "no-wait", type: "boolean" },
102
+ "timeout-seconds",
103
+ "idempotency-key",
104
+ ],
105
+ }),
106
+ commandSpec({
107
+ command: ["faceless", "runs", "retry"],
108
+ usage: "blitzreels faceless runs retry --run-id ID [--scene-indexes 2,7] [--output FILE] [--no-wait] [--timeout-seconds 3600] [--idempotency-key KEY] [--dry-run] [--json]",
109
+ description: "Resume a failed run, reusing finished clips.",
110
+ mutates: true,
111
+ dryRunSupported: true,
112
+ flags: [
113
+ "run-id",
114
+ {
115
+ name: "scene-indexes",
116
+ description: "Scenes to generate again even though a clip exists.",
117
+ },
118
+ { name: "output", description: "Save the finished MP4 to this path." },
119
+ { name: "no-wait", type: "boolean" },
120
+ "timeout-seconds",
121
+ "idempotency-key",
122
+ ],
123
+ }),
124
+ commandSpec({
125
+ command: ["faceless", "runs", "budget"],
126
+ usage: "blitzreels faceless runs budget --run-id ID (--max-credits 600 | --no-limit) [--idempotency-key KEY] [--dry-run] [--json]",
127
+ description: "Change a run's credit limit.",
128
+ mutates: true,
129
+ dryRunSupported: true,
130
+ flags: [
131
+ "run-id",
132
+ "max-credits",
133
+ { name: "no-limit", type: "boolean" },
134
+ "idempotency-key",
135
+ ],
136
+ }),
6
137
  commandSpec({
7
138
  command: ["faceless", "plans", "create"],
8
- usage: "blitzreels faceless plans create --project-id ID (--script TEXT | --script-file ./script.txt) [--story-kit-id ID] [--character-ids ID,ID] [--style-reference-ids ID,ID] [--target-duration-seconds 45] [--planner-model-id MODEL] [--image-model-id MODEL] [--video-model MODEL] [--idempotency-key KEY] [--json]",
139
+ usage: "blitzreels faceless plans create --project-id ID (--script TEXT | --script-file ./script.txt) [--story-kit-id ID] [--character-ids ID,ID] [--style-reference-ids ID,ID] [--target-duration-seconds 45] [--planner-model-id MODEL] [--image-model-id MODEL] [--video-model MODEL] [--voice-id ID] [--include-captions] [--caption-style-id ID] [--generate-background-music] [--generate-sound-effects] [--genre ID] [--storyboard] [--multi-shot] [--clip-seconds 15] [--idempotency-key KEY] [--json]",
9
140
  description: "Create an immutable generated-only 9:16 faceless production plan revision.",
10
141
  dryRunSupported: true,
11
142
  flags: [
@@ -26,6 +157,7 @@ export const FACELESS_COMMAND_SPECS = [
26
157
  "caption-style-id",
27
158
  { name: "generate-background-music", type: "boolean" },
28
159
  { name: "generate-sound-effects", type: "boolean" },
160
+ ...CREATIVE_MODE_FLAGS,
29
161
  {
30
162
  name: "idempotency-key",
31
163
  description: "Stable retry key; reuse only with identical inputs.",
@@ -72,13 +204,18 @@ export const FACELESS_COMMAND_SPECS = [
72
204
  }),
73
205
  commandSpec({
74
206
  command: ["faceless", "assets", "regenerate"],
75
- usage: "blitzreels faceless assets regenerate --project-id ID --revision-id ID (--style-anchor | --character-id ID | --scene-index N) --idempotency-key KEY [--dry-run] [--json]",
76
- description: "Regenerate the style anchor, one character anchor, or one scene keyframe.",
207
+ usage: "blitzreels faceless assets regenerate --project-id ID --revision-id ID (--storyboard | --style-anchor | --character-id ID | --scene-index N) --idempotency-key KEY [--dry-run] [--json]",
208
+ description: "Regenerate the storyboard sheet, the style anchor, one character anchor, or one scene keyframe.",
77
209
  mutates: true,
78
210
  dryRunSupported: true,
79
211
  flags: [
80
212
  "project-id",
81
213
  "revision-id",
214
+ {
215
+ name: "storyboard",
216
+ type: "boolean",
217
+ description: "Regenerate the storyboard sheet on storyboard plans.",
218
+ },
82
219
  {
83
220
  name: "style-anchor",
84
221
  type: "boolean",
@@ -148,6 +285,12 @@ function resolvePlanChanges({ flags, helpers, }) {
148
285
  }
149
286
  const update = item;
150
287
  const sceneIndex = Number(update.scene_index);
288
+ if (update.shots !== undefined && !Array.isArray(update.shots)) {
289
+ throw new CliUsageError({
290
+ code: "invalid_flag_value",
291
+ message: `scene_updates[${index}].shots must be an array.`,
292
+ });
293
+ }
151
294
  if (!Number.isInteger(sceneIndex) || sceneIndex < 0) {
152
295
  throw new CliUsageError({
153
296
  code: "invalid_flag_value",
@@ -177,6 +320,25 @@ function resolvePlanChanges({ flags, helpers, }) {
177
320
  value: update.motion_prompt,
178
321
  field: `scene_updates[${index}].motion_prompt`,
179
322
  }),
323
+ ...(Array.isArray(update.shots)
324
+ ? {
325
+ shots: update.shots.map((rawShot, shotIndex) => {
326
+ const shot = (rawShot ?? {});
327
+ const durationSeconds = Number(shot.duration_seconds);
328
+ if (!Number.isFinite(durationSeconds) || durationSeconds <= 0) {
329
+ throw new CliUsageError({
330
+ code: "invalid_flag_value",
331
+ message: `scene_updates[${index}].shots[${shotIndex}].duration_seconds must be a positive number.`,
332
+ });
333
+ }
334
+ return {
335
+ camera: String(shot.camera ?? ""),
336
+ action: String(shot.action ?? ""),
337
+ durationSeconds,
338
+ };
339
+ }),
340
+ }
341
+ : {}),
180
342
  };
181
343
  });
182
344
  const characterUpdates = rawCharacterUpdates?.map((item, index) => {
@@ -242,10 +404,12 @@ function resolvePlanChanges({ flags, helpers, }) {
242
404
  return result;
243
405
  }
244
406
  function resolveRegenerationTarget({ flags, helpers, }) {
407
+ const storyboard = helpers.getOptionalBooleanFlag({ flags, name: "storyboard" }) ?? false;
245
408
  const styleAnchor = helpers.getOptionalBooleanFlag({ flags, name: "style-anchor" }) ?? false;
246
409
  const characterId = helpers.getStringFlag({ flags, name: "character-id" });
247
410
  const sceneIndex = helpers.getNumberFlag({ flags, name: "scene-index" });
248
411
  const selectedTargets = [
412
+ storyboard,
249
413
  styleAnchor,
250
414
  Boolean(characterId),
251
415
  sceneIndex !== undefined,
@@ -253,9 +417,12 @@ function resolveRegenerationTarget({ flags, helpers, }) {
253
417
  if (selectedTargets !== 1) {
254
418
  throw new CliUsageError({
255
419
  code: "invalid_flag_value",
256
- message: "Provide exactly one of --style-anchor, --character-id, or --scene-index.",
420
+ message: "Provide exactly one of --storyboard, --style-anchor, --character-id, or --scene-index.",
257
421
  });
258
422
  }
423
+ if (storyboard) {
424
+ return { assetType: "storyboard" };
425
+ }
259
426
  if (styleAnchor) {
260
427
  return { assetType: "style_anchor" };
261
428
  }
@@ -334,8 +501,343 @@ function buildCreateBody({ context, helpers, }) {
334
501
  style_reference_asset_ids: csvIdList({
335
502
  value: helpers.getStringFlag({ flags, name: "style-reference-ids" }),
336
503
  }),
504
+ genre: helpers.getStringFlag({ flags, name: "genre" }),
505
+ storyboard: helpers.getOptionalBooleanFlag({ flags, name: "storyboard" }),
506
+ multi_shot: helpers.getOptionalBooleanFlag({ flags, name: "multi-shot" }),
507
+ clip_seconds: helpers.getNumberFlag({ flags, name: "clip-seconds" }),
508
+ };
509
+ }
510
+ function creativeModeOptions({ flags, helpers, }) {
511
+ return {
512
+ genre: helpers.getStringFlag({ flags, name: "genre" }),
513
+ storyboard: helpers.getOptionalBooleanFlag({ flags, name: "storyboard" }),
514
+ multiShot: helpers.getOptionalBooleanFlag({ flags, name: "multi-shot" }),
515
+ clipSeconds: helpers.getNumberFlag({ flags, name: "clip-seconds" }),
516
+ };
517
+ }
518
+ function humanFacelessRun({ run }) {
519
+ const nextAction = run.next_action;
520
+ return [
521
+ `Run: ${run.run_id}`,
522
+ `Project: ${run.project_id}`,
523
+ `Status: ${run.status} (${run.stage}${run.gate ? `, gate ${run.gate}` : ""})`,
524
+ `Credits: ${run.spent_credits} spent${run.quote ? `, ${run.quote.total} quoted` : ""}${run.max_credits !== null ? `, ${run.max_credits} max` : ""}`,
525
+ ...(run.plan
526
+ ? [
527
+ `Plan: ${run.plan.scene_count} video generations, ${run.plan.shot_count} shots, ${run.plan.video_model}${run.plan.genre ? `, ${run.plan.genre}` : ""}`,
528
+ ]
529
+ : []),
530
+ ...(run.review?.storyboard?.url
531
+ ? [`Storyboard: ${run.review.storyboard.url}`]
532
+ : []),
533
+ ...(run.review?.keyframes ?? []).flatMap((keyframe) => keyframe.url ? [`Keyframe ${keyframe.scene_index}: ${keyframe.url}`] : []),
534
+ ...run.checks.map((check) => `Check scene ${check.scene_index}: ${check.summary}`),
535
+ ...run.warnings.map((warning) => `Warning: ${warning}`),
536
+ ...(run.error?.message ? [`Error: ${run.error.message}`] : []),
537
+ ...(run.export?.download_url ? [`Export: ${run.export.download_url}`] : []),
538
+ ...("cli" in nextAction ? [`Next: ${nextAction.cli}`] : []),
539
+ ...(nextAction.kind === "approve" && nextAction.revise_cli
540
+ ? [`Or change it: ${nextAction.revise_cli}`]
541
+ : []),
542
+ ];
543
+ }
544
+ function isStopped({ run }) {
545
+ return run.status !== "processing";
546
+ }
547
+ async function waitForFacelessRun({ context, helpers, run, timeoutSeconds, }) {
548
+ const deadline = Date.now() + timeoutSeconds * 1000;
549
+ let current = run;
550
+ let lastLine = "";
551
+ while (!isStopped({ run: current })) {
552
+ const line = `${current.status}: ${current.stage}`;
553
+ if (line !== lastLine) {
554
+ process.stderr.write(`${line}\n`);
555
+ lastLine = line;
556
+ }
557
+ if (Date.now() >= deadline) {
558
+ throw new CliOperationError({
559
+ code: "wait_timeout",
560
+ exitCode: 6,
561
+ retryable: true,
562
+ message: `Run ${current.run_id} is still in ${current.stage}. The run keeps going.`,
563
+ suggestions: [
564
+ `blitzreels faceless runs get --run-id ${current.run_id} --wait`,
565
+ ],
566
+ });
567
+ }
568
+ await helpers.sleep({
569
+ ms: current.next_action.kind === "wait"
570
+ ? current.next_action.poll_after_seconds * 1000
571
+ : 10_000,
572
+ });
573
+ current = await context.client.faceless.runs.get({
574
+ runId: current.run_id,
575
+ });
576
+ }
577
+ return current;
578
+ }
579
+ async function finishFacelessRun({ context, helpers, run, wait, }) {
580
+ const flags = context.args.flags;
581
+ const finalRun = wait
582
+ ? await waitForFacelessRun({
583
+ context,
584
+ helpers,
585
+ run,
586
+ timeoutSeconds: helpers.getNumberFlag({ flags, name: "timeout-seconds" }) ?? 3600,
587
+ })
588
+ : run;
589
+ const output = helpers.getStringFlag({ flags, name: "output" });
590
+ const saved = await saveFinishedFilm({ context, run: finalRun, output });
591
+ helpers.printResult({
592
+ json: context.json,
593
+ value: saved ? { ...finalRun, saved_to: saved } : finalRun,
594
+ human: [
595
+ ...humanFacelessRun({ run: finalRun }),
596
+ ...(saved ? [`Saved: ${saved}`] : []),
597
+ ],
598
+ });
599
+ }
600
+ async function saveFinishedFilm({ context, run, output, }) {
601
+ if (!output || run.status !== "complete" || !run.export?.export_id) {
602
+ return null;
603
+ }
604
+ const bytes = await context.client.exports.download({
605
+ exportId: run.export.export_id,
606
+ });
607
+ const path = resolve(output);
608
+ writeFileSync(path, Buffer.from(bytes));
609
+ return path;
610
+ }
611
+ function resolveRunResolution({ flags, helpers, }) {
612
+ const resolution = helpers.getStringFlag({ flags, name: "resolution" }) ?? "1080p";
613
+ if (resolution !== "720p" && resolution !== "1080p" && resolution !== "4k") {
614
+ throw new CliUsageError({
615
+ code: "invalid_flag_value",
616
+ message: "--resolution must be 720p, 1080p, or 4k.",
617
+ });
618
+ }
619
+ return resolution;
620
+ }
621
+ function buildRunCreateOptions({ flags, helpers, }) {
622
+ const noVoiceover = helpers.getOptionalBooleanFlag({ flags, name: "no-voiceover" }) ?? false;
623
+ const noCaptions = helpers.getOptionalBooleanFlag({ flags, name: "no-captions" }) ?? false;
624
+ const autoApprove = helpers.getOptionalBooleanFlag({ flags, name: "auto-approve" }) ?? false;
625
+ const noExport = helpers.getOptionalBooleanFlag({ flags, name: "no-export" }) ?? false;
626
+ const noWatermark = helpers.getOptionalBooleanFlag({ flags, name: "no-watermark" }) ?? false;
627
+ return {
628
+ script: resolveScript({ flags, helpers }),
629
+ projectName: helpers.getStringFlag({ flags, name: "project-name" }),
630
+ targetDurationSeconds: helpers.getNumberFlag({ flags, name: "duration" }),
631
+ visualStyle: helpers.getStringFlag({ flags, name: "visual-style" }),
632
+ storyKitId: helpers.getStringFlag({ flags, name: "story-kit-id" }),
633
+ seriesId: helpers.getStringFlag({ flags, name: "series-id" }),
634
+ ...creativeModeOptions({ flags, helpers }),
635
+ plannerModelId: helpers.getStringFlag({ flags, name: "planner-model" }),
636
+ imageModelId: helpers.getStringFlag({ flags, name: "image-model" }),
637
+ videoModel: helpers.getStringFlag({ flags, name: "video-model" }),
638
+ generateVoiceover: noVoiceover ? false : undefined,
639
+ voiceId: helpers.getStringFlag({ flags, name: "voice-id" }),
640
+ includeCaptions: noCaptions ? false : undefined,
641
+ captionStyleId: helpers.getStringFlag({
642
+ flags,
643
+ name: "caption-style-id",
644
+ }),
645
+ generateBackgroundMusic: helpers.getOptionalBooleanFlag({
646
+ flags,
647
+ name: "background-music",
648
+ }),
649
+ generateSoundEffects: helpers.getOptionalBooleanFlag({
650
+ flags,
651
+ name: "sound-effects",
652
+ }),
653
+ characterIds: csvIdList({
654
+ value: helpers.getStringFlag({ flags, name: "character-ids" }),
655
+ }),
656
+ styleReferenceAssetIds: csvIdList({
657
+ value: helpers.getStringFlag({ flags, name: "style-reference-ids" }),
658
+ }),
659
+ approvalGates: autoApprove ? [] : undefined,
660
+ maxCredits: helpers.getNumberFlag({ flags, name: "max-credits" }),
661
+ export: noExport
662
+ ? null
663
+ : {
664
+ resolution: resolveRunResolution({ flags, helpers }),
665
+ showWatermark: noWatermark ? false : null,
666
+ },
337
667
  };
338
668
  }
669
+ function hashedIdempotencyKey({ prefix, value, }) {
670
+ return `${prefix}-${createHash("sha256").update(JSON.stringify(value)).digest("hex").slice(0, 32)}`;
671
+ }
672
+ function resolveRunGate({ flags, helpers, }) {
673
+ const gate = helpers.requireStringFlag({ flags, name: "gate" });
674
+ if (gate !== "plan" && gate !== "keyframes") {
675
+ throw new CliUsageError({
676
+ code: "invalid_flag_value",
677
+ message: "--gate must be plan or keyframes.",
678
+ });
679
+ }
680
+ return gate;
681
+ }
682
+ function resolveSceneIndexes({ flags, helpers, }) {
683
+ const value = helpers.getStringFlag({ flags, name: "scene-indexes" });
684
+ if (!value)
685
+ return undefined;
686
+ return value.split(",").map((item) => {
687
+ const sceneIndex = Number(item.trim());
688
+ if (!Number.isInteger(sceneIndex) || sceneIndex < 0) {
689
+ throw new CliUsageError({
690
+ code: "invalid_flag_value",
691
+ message: "--scene-indexes must be comma-separated scene numbers.",
692
+ });
693
+ }
694
+ return sceneIndex;
695
+ });
696
+ }
697
+ function resolveBudget({ flags, helpers, }) {
698
+ const noLimit = helpers.getOptionalBooleanFlag({ flags, name: "no-limit" }) ?? false;
699
+ const maxCredits = helpers.getNumberFlag({ flags, name: "max-credits" });
700
+ if (noLimit === (maxCredits !== undefined)) {
701
+ throw new CliUsageError({
702
+ code: "invalid_flag_value",
703
+ message: "Provide exactly one of --max-credits or --no-limit.",
704
+ });
705
+ }
706
+ return maxCredits ?? null;
707
+ }
708
+ async function handleFacelessRunCommand({ action, context, helpers, }) {
709
+ const flags = context.args.flags;
710
+ const noWait = helpers.getOptionalBooleanFlag({ flags, name: "no-wait" }) ?? false;
711
+ const explicitKey = helpers.getStringFlag({ flags, name: "idempotency-key" });
712
+ if (action === "start") {
713
+ const options = buildRunCreateOptions({ flags, helpers });
714
+ const run = await context.client.faceless.runs.create({
715
+ ...options,
716
+ idempotencyKey: explicitKey ?? hashedIdempotencyKey({ prefix: "run", value: options }),
717
+ });
718
+ await finishFacelessRun({ context, helpers, run, wait: !noWait });
719
+ return true;
720
+ }
721
+ const runId = helpers.requireStringFlag({ flags, name: "run-id" });
722
+ if (action === "get") {
723
+ const run = await context.client.faceless.runs.get({ runId });
724
+ const wait = helpers.getOptionalBooleanFlag({ flags, name: "wait" }) ?? false;
725
+ await finishFacelessRun({ context, helpers, run, wait });
726
+ return true;
727
+ }
728
+ if (action === "approve") {
729
+ const gate = resolveRunGate({ flags, helpers });
730
+ const revisionId = helpers.requireStringFlag({
731
+ flags,
732
+ name: "revision-id",
733
+ });
734
+ const run = await context.client.faceless.runs.approve({
735
+ runId,
736
+ gate,
737
+ revisionId,
738
+ idempotencyKey: explicitKey ??
739
+ hashedIdempotencyKey({
740
+ prefix: "run-approve",
741
+ value: { runId, gate, revisionId },
742
+ }),
743
+ });
744
+ await finishFacelessRun({ context, helpers, run, wait: !noWait });
745
+ return true;
746
+ }
747
+ if (action === "retry") {
748
+ const run = await context.client.faceless.runs.retry({
749
+ runId,
750
+ sceneIndexes: resolveSceneIndexes({ flags, helpers }),
751
+ idempotencyKey: explicitKey ?? `run-retry-${randomUUID()}`,
752
+ });
753
+ await finishFacelessRun({ context, helpers, run, wait: !noWait });
754
+ return true;
755
+ }
756
+ if (action === "budget") {
757
+ const run = await context.client.faceless.runs.setBudget({
758
+ runId,
759
+ maxCredits: resolveBudget({ flags, helpers }),
760
+ idempotencyKey: explicitKey ?? `run-budget-${randomUUID()}`,
761
+ });
762
+ await finishFacelessRun({ context, helpers, run, wait: false });
763
+ return true;
764
+ }
765
+ return false;
766
+ }
767
+ function buildFacelessRunDryRun({ action, context, spec, helpers, }) {
768
+ const flags = context.args.flags;
769
+ if (action === "start") {
770
+ const options = buildRunCreateOptions({ flags, helpers });
771
+ return helpers.dryRunRequest({
772
+ spec,
773
+ method: "POST",
774
+ path: "/faceless/runs",
775
+ body: {
776
+ script: `${options.script.length} characters`,
777
+ project_name: options.projectName,
778
+ target_duration_seconds: options.targetDurationSeconds,
779
+ visual_style: options.visualStyle,
780
+ story_kit_id: options.storyKitId,
781
+ series_id: options.seriesId,
782
+ genre: options.genre,
783
+ storyboard: options.storyboard,
784
+ multi_shot: options.multiShot,
785
+ clip_seconds: options.clipSeconds,
786
+ planner_model_id: options.plannerModelId,
787
+ image_model_id: options.imageModelId,
788
+ video_model: options.videoModel,
789
+ generate_voiceover: options.generateVoiceover,
790
+ voice_id: options.voiceId,
791
+ include_captions: options.includeCaptions,
792
+ caption_style_id: options.captionStyleId,
793
+ generate_background_music: options.generateBackgroundMusic,
794
+ generate_sound_effects: options.generateSoundEffects,
795
+ character_ids: options.characterIds,
796
+ style_reference_asset_ids: options.styleReferenceAssetIds,
797
+ approval_gates: options.approvalGates,
798
+ max_credits: options.maxCredits,
799
+ export: options.export
800
+ ? {
801
+ resolution: options.export.resolution,
802
+ show_watermark: options.export.showWatermark,
803
+ }
804
+ : options.export,
805
+ },
806
+ notes: ["Quotes the film, creates a project and starts paid planning."],
807
+ });
808
+ }
809
+ const runId = helpers.requireStringFlag({ flags, name: "run-id" });
810
+ const path = `/faceless/runs/${encodeURIComponent(runId)}`;
811
+ if (action === "approve") {
812
+ return helpers.dryRunRequest({
813
+ spec,
814
+ method: "POST",
815
+ path: `${path}/approve`,
816
+ body: {
817
+ gate: resolveRunGate({ flags, helpers }),
818
+ revision_id: helpers.requireStringFlag({ flags, name: "revision-id" }),
819
+ },
820
+ notes: ["Starts the next paid stage."],
821
+ });
822
+ }
823
+ if (action === "retry") {
824
+ return helpers.dryRunRequest({
825
+ spec,
826
+ method: "POST",
827
+ path: `${path}/retry`,
828
+ body: { scene_indexes: resolveSceneIndexes({ flags, helpers }) },
829
+ });
830
+ }
831
+ if (action === "budget") {
832
+ return helpers.dryRunRequest({
833
+ spec,
834
+ method: "POST",
835
+ path: `${path}/budget`,
836
+ body: { max_credits: resolveBudget({ flags, helpers }) },
837
+ });
838
+ }
839
+ return undefined;
840
+ }
339
841
  export function createFacelessCommandOperation({ helpers, }) {
340
842
  return {
341
843
  name: "faceless",
@@ -343,6 +845,9 @@ export function createFacelessCommandOperation({ helpers, }) {
343
845
  handle: async ({ context }) => {
344
846
  const [domain, action] = context.args.command.slice(1);
345
847
  const flags = context.args.flags;
848
+ if (domain === "runs") {
849
+ return handleFacelessRunCommand({ action, context, helpers });
850
+ }
346
851
  const projectId = helpers.requireStringFlag({
347
852
  flags,
348
853
  name: "project-id",
@@ -366,6 +871,7 @@ export function createFacelessCommandOperation({ helpers, }) {
366
871
  flags,
367
872
  name: "image-model-id",
368
873
  }),
874
+ ...creativeModeOptions({ flags, helpers }),
369
875
  videoModel: helpers.getStringFlag({ flags, name: "video-model" }),
370
876
  voiceId: helpers.getStringFlag({ flags, name: "voice-id" }),
371
877
  includeCaptions: helpers.getOptionalBooleanFlag({
@@ -540,6 +1046,9 @@ export function createFacelessCommandOperation({ helpers, }) {
540
1046
  buildDryRun: ({ context, spec }) => {
541
1047
  const [domain, action] = context.args.command.slice(1);
542
1048
  const flags = context.args.flags;
1049
+ if (domain === "runs") {
1050
+ return buildFacelessRunDryRun({ action, context, spec, helpers });
1051
+ }
543
1052
  const projectId = helpers.requireStringFlag({
544
1053
  flags,
545
1054
  name: "project-id",
@@ -572,6 +1081,11 @@ export function createFacelessCommandOperation({ helpers, }) {
572
1081
  character_ids: update.characterIds,
573
1082
  image_prompt: update.imagePrompt,
574
1083
  motion_prompt: update.motionPrompt,
1084
+ shots: update.shots?.map((shot) => ({
1085
+ camera: shot.camera,
1086
+ action: shot.action,
1087
+ duration_seconds: shot.durationSeconds,
1088
+ })),
575
1089
  })),
576
1090
  character_updates: changes.characterUpdates?.map((update) => ({
577
1091
  character_id: update.characterId,
@@ -592,7 +1106,8 @@ export function createFacelessCommandOperation({ helpers, }) {
592
1106
  spec,
593
1107
  method: "POST",
594
1108
  path: `/projects/${encodeURIComponent(projectId)}/faceless/plans/${encodeURIComponent(revisionId)}/regenerate-assets`,
595
- body: target.assetType === "style_anchor"
1109
+ body: target.assetType === "style_anchor" ||
1110
+ target.assetType === "storyboard"
596
1111
  ? { asset_type: target.assetType }
597
1112
  : target.assetType === "character_anchor"
598
1113
  ? {