blitzreels 0.1.30 → 0.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +285 -8
- package/dist/agent-context.d.ts.map +1 -1
- package/dist/agent-context.js +12 -3
- package/dist/agent-context.js.map +1 -1
- package/dist/cli-command-routing.d.ts.map +1 -1
- package/dist/cli-command-routing.js +5 -1
- package/dist/cli-command-routing.js.map +1 -1
- package/dist/command-registry.d.ts.map +1 -1
- package/dist/command-registry.js +28 -0
- package/dist/command-registry.js.map +1 -1
- package/dist/commands/analytics.d.ts +10 -0
- package/dist/commands/analytics.d.ts.map +1 -0
- package/dist/commands/analytics.js +214 -0
- package/dist/commands/analytics.js.map +1 -0
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +5 -0
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/carousels.d.ts.map +1 -1
- package/dist/commands/carousels.js +61 -8
- package/dist/commands/carousels.js.map +1 -1
- package/dist/commands/characters.d.ts.map +1 -1
- package/dist/commands/characters.js +137 -2
- package/dist/commands/characters.js.map +1 -1
- package/dist/commands/content-batches.d.ts +19 -0
- package/dist/commands/content-batches.d.ts.map +1 -0
- package/dist/commands/content-batches.js +128 -0
- package/dist/commands/content-batches.js.map +1 -0
- package/dist/commands/content-review.d.ts +18 -0
- package/dist/commands/content-review.d.ts.map +1 -0
- package/dist/commands/content-review.js +66 -0
- package/dist/commands/content-review.js.map +1 -0
- package/dist/commands/creative-learning.d.ts +8 -0
- package/dist/commands/creative-learning.d.ts.map +1 -0
- package/dist/commands/creative-learning.js +111 -0
- package/dist/commands/creative-learning.js.map +1 -0
- package/dist/commands/creative-map.d.ts +8 -0
- package/dist/commands/creative-map.d.ts.map +1 -0
- package/dist/commands/creative-map.js +121 -0
- package/dist/commands/creative-map.js.map +1 -0
- package/dist/commands/creative-source.d.ts +33 -0
- package/dist/commands/creative-source.d.ts.map +1 -0
- package/dist/commands/creative-source.js +267 -0
- package/dist/commands/creative-source.js.map +1 -0
- package/dist/commands/customer-outcomes.d.ts +8 -0
- package/dist/commands/customer-outcomes.d.ts.map +1 -0
- package/dist/commands/customer-outcomes.js +115 -0
- package/dist/commands/customer-outcomes.js.map +1 -0
- package/dist/commands/editor.d.ts +20 -0
- package/dist/commands/editor.d.ts.map +1 -0
- package/dist/commands/editor.js +116 -0
- package/dist/commands/editor.js.map +1 -0
- package/dist/commands/exports.d.ts.map +1 -1
- package/dist/commands/exports.js +57 -0
- package/dist/commands/exports.js.map +1 -1
- package/dist/commands/generation-review.d.ts +18 -0
- package/dist/commands/generation-review.d.ts.map +1 -0
- package/dist/commands/generation-review.js +60 -0
- package/dist/commands/generation-review.js.map +1 -0
- package/dist/commands/generation-wait.d.ts +15 -0
- package/dist/commands/generation-wait.d.ts.map +1 -0
- package/dist/commands/generation-wait.js +98 -0
- package/dist/commands/generation-wait.js.map +1 -0
- package/dist/commands/generation.d.ts +5 -0
- package/dist/commands/generation.d.ts.map +1 -1
- package/dist/commands/generation.js +693 -34
- package/dist/commands/generation.js.map +1 -1
- package/dist/commands/hosted-drafts.d.ts +8 -0
- package/dist/commands/hosted-drafts.d.ts.map +1 -0
- package/dist/commands/hosted-drafts.js +125 -0
- package/dist/commands/hosted-drafts.js.map +1 -0
- package/dist/commands/jobs.d.ts.map +1 -1
- package/dist/commands/jobs.js +156 -1
- package/dist/commands/jobs.js.map +1 -1
- package/dist/commands/knowledge-research.d.ts +10 -0
- package/dist/commands/knowledge-research.d.ts.map +1 -0
- package/dist/commands/knowledge-research.js +147 -0
- package/dist/commands/knowledge-research.js.map +1 -0
- package/dist/commands/knowledge.d.ts +37 -0
- package/dist/commands/knowledge.d.ts.map +1 -0
- package/dist/commands/knowledge.js +164 -0
- package/dist/commands/knowledge.js.map +1 -0
- package/dist/commands/media-assets.d.ts.map +1 -1
- package/dist/commands/media-assets.js +39 -0
- package/dist/commands/media-assets.js.map +1 -1
- package/dist/commands/project-read.d.ts.map +1 -1
- package/dist/commands/project-read.js +25 -4
- package/dist/commands/project-read.js.map +1 -1
- package/dist/commands/projects.d.ts.map +1 -1
- package/dist/commands/projects.js +51 -0
- package/dist/commands/projects.js.map +1 -1
- package/dist/commands/publishing-access-preflight.d.ts +16 -0
- package/dist/commands/publishing-access-preflight.d.ts.map +1 -0
- package/dist/commands/publishing-access-preflight.js +31 -0
- package/dist/commands/publishing-access-preflight.js.map +1 -0
- package/dist/commands/publishing-posts.d.ts.map +1 -1
- package/dist/commands/publishing-posts.js +140 -14
- package/dist/commands/publishing-posts.js.map +1 -1
- package/dist/commands/publishing-schedule-time.d.ts +11 -0
- package/dist/commands/publishing-schedule-time.d.ts.map +1 -0
- package/dist/commands/publishing-schedule-time.js +81 -0
- package/dist/commands/publishing-schedule-time.js.map +1 -0
- package/dist/commands/publishing.d.ts.map +1 -1
- package/dist/commands/publishing.js +285 -262
- package/dist/commands/publishing.js.map +1 -1
- package/dist/commands/recipes.d.ts +24 -0
- package/dist/commands/recipes.d.ts.map +1 -0
- package/dist/commands/recipes.js +177 -0
- package/dist/commands/recipes.js.map +1 -0
- package/dist/commands/series.d.ts +1 -2
- package/dist/commands/series.d.ts.map +1 -1
- package/dist/commands/series.js +132 -1
- package/dist/commands/series.js.map +1 -1
- package/dist/commands/system.d.ts.map +1 -1
- package/dist/commands/system.js +25 -1
- package/dist/commands/system.js.map +1 -1
- package/dist/commands/text-overlays.d.ts.map +1 -1
- package/dist/commands/text-overlays.js +1 -0
- package/dist/commands/text-overlays.js.map +1 -1
- package/dist/commands/voices.d.ts +16 -0
- package/dist/commands/voices.d.ts.map +1 -0
- package/dist/commands/voices.js +251 -0
- package/dist/commands/voices.js.map +1 -0
- package/dist/commands/web-capture.d.ts +10 -0
- package/dist/commands/web-capture.d.ts.map +1 -0
- package/dist/commands/web-capture.js +149 -0
- package/dist/commands/web-capture.js.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { readFile
|
|
2
|
-
import { extname, resolve } from "node:path";
|
|
3
|
-
import { IMAGE_RESOLUTIONS, VIDEO_RESOLUTIONS, videoTransformationSchema, } from "@blitzreels/contracts";
|
|
4
|
-
import {
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { extname, join, resolve } from "node:path";
|
|
3
|
+
import { audioSpendQuoteInputSchema, generationSpendQuoteInputSchema, IMAGE_RESOLUTIONS, VIDEO_RESOLUTIONS, videoTransformationSchema, } from "@blitzreels/contracts";
|
|
4
|
+
import { BlitzReelsError, } from "@blitzreels/sdk";
|
|
5
|
+
import { CliOperationError, CliUsageError } from "../cli-errors.js";
|
|
6
|
+
import { createFlagReader } from "../cli-flag-reader.js";
|
|
5
7
|
import { parseRequestTimeoutMs } from "../cli-runtime.js";
|
|
6
8
|
import { commandSpec } from "../command-metadata.js";
|
|
9
|
+
import { reviewGenerationOutput, } from "./generation-review.js";
|
|
10
|
+
import { DEFAULT_GENERATION_WAIT_TIMEOUT_MS, waitForGenerationJob, } from "./generation-wait.js";
|
|
7
11
|
import { uploadLocalMediaFile } from "./media-runtime.js";
|
|
8
12
|
import { clearUploadReceipts } from "./upload-receipt.js";
|
|
9
13
|
const GENERATION_COMMANDS = [
|
|
14
|
+
["generate", "models"],
|
|
15
|
+
["generate", "compare"],
|
|
16
|
+
["generate", "quote"],
|
|
17
|
+
["generate", "audio-quote"],
|
|
10
18
|
["generate", "plan-brief"],
|
|
11
19
|
["generate", "images"],
|
|
12
20
|
["generate", "videos"],
|
|
@@ -32,10 +40,112 @@ const SHARED_FLAGS = [
|
|
|
32
40
|
},
|
|
33
41
|
{
|
|
34
42
|
name: "output",
|
|
35
|
-
description: "Write the generated asset to this local path after waiting.",
|
|
43
|
+
description: "Write the generated asset to this local path after waiting. The extension follows the returned format.",
|
|
36
44
|
},
|
|
37
45
|
];
|
|
46
|
+
const BATCH_FLAG = {
|
|
47
|
+
name: "batch",
|
|
48
|
+
description: "JSON file with an array of entries keyed by this command's flag names. Command-line flags are shared defaults. Each entry needs idempotency-key, or --idempotency-key provides KEY-N.",
|
|
49
|
+
};
|
|
50
|
+
const GENERATION_KINDS = [
|
|
51
|
+
"image",
|
|
52
|
+
"video",
|
|
53
|
+
"voiceover",
|
|
54
|
+
"music",
|
|
55
|
+
"sound",
|
|
56
|
+
"faceless",
|
|
57
|
+
];
|
|
38
58
|
export const GENERATION_COMMAND_SPECS = [
|
|
59
|
+
commandSpec({
|
|
60
|
+
command: ["generate", "compare"],
|
|
61
|
+
discovery: "detail",
|
|
62
|
+
usage: "blitzreels generate compare --models ID,ID --prompt TEXT (--source-image FILE | --source-asset-id ID) [--duration 5] [--aspect-ratio 9:16] [--generate-audio] [--character-id ID] [--reference-audio-asset-id ID] [--output-dir DIR] [--review] --idempotency-key PREFIX [--no-wait] [--dry-run] [--json]",
|
|
63
|
+
description: "Run the same video request on several models in parallel. Each model gets its nearest supported duration; results list status, elapsed seconds, credits and, with --review, transcript and likeness.",
|
|
64
|
+
mutates: true,
|
|
65
|
+
dryRunSupported: true,
|
|
66
|
+
flags: [
|
|
67
|
+
{
|
|
68
|
+
name: "models",
|
|
69
|
+
required: true,
|
|
70
|
+
description: "Comma-separated video model IDs from generate models --kind video.",
|
|
71
|
+
},
|
|
72
|
+
"prompt",
|
|
73
|
+
"source-image",
|
|
74
|
+
"source-asset-id",
|
|
75
|
+
"end-frame",
|
|
76
|
+
"character-id",
|
|
77
|
+
"reference-asset-id",
|
|
78
|
+
"reference-audio-asset-id",
|
|
79
|
+
{
|
|
80
|
+
name: "duration",
|
|
81
|
+
type: "number",
|
|
82
|
+
description: "Target seconds; each model uses the nearest value from its durations_seconds.",
|
|
83
|
+
},
|
|
84
|
+
"aspect-ratio",
|
|
85
|
+
{
|
|
86
|
+
name: "generate-audio",
|
|
87
|
+
type: "boolean",
|
|
88
|
+
description: "Request audio on models where audio is optional.",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "output-dir",
|
|
92
|
+
description: "Write each video as <model>.mp4 (and review sheets) here.",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "review",
|
|
96
|
+
type: "boolean",
|
|
97
|
+
description: "After each video finishes, add frames, transcript and likeness (jobs review).",
|
|
98
|
+
},
|
|
99
|
+
{ name: "frame-count", type: "number", default: 4 },
|
|
100
|
+
{ name: "idempotency-key", required: true },
|
|
101
|
+
{ name: "no-wait", type: "boolean" },
|
|
102
|
+
],
|
|
103
|
+
}),
|
|
104
|
+
commandSpec({
|
|
105
|
+
command: ["generate", "models"],
|
|
106
|
+
usage: "blitzreels generate models --kind image|video|voiceover|music|sound|faceless [--json]",
|
|
107
|
+
discovery: "detail",
|
|
108
|
+
mutates: false,
|
|
109
|
+
description: "List current models, durations, aspect ratios, reference limits and credit pricing for one generation kind.",
|
|
110
|
+
flags: [{ name: "kind", enum: [...GENERATION_KINDS], required: true }],
|
|
111
|
+
}),
|
|
112
|
+
commandSpec({
|
|
113
|
+
command: ["generate", "quote"],
|
|
114
|
+
usage: "blitzreels generate quote --kind image|video|prompt [--model ID] [--seconds N] [--resolution VALUE] [--size WxH] [--source-image-model ID] [--enhance-prompt] [--json]",
|
|
115
|
+
discovery: "detail",
|
|
116
|
+
mutates: false,
|
|
117
|
+
description: "Read credits, eligibility and maximum workspace spending. Visual quotes need a model; videos need seconds. No generation or reservation.",
|
|
118
|
+
flags: [
|
|
119
|
+
{ name: "kind", enum: ["image", "video", "prompt"] },
|
|
120
|
+
"model",
|
|
121
|
+
"source-image-model",
|
|
122
|
+
{ name: "seconds", type: "number" },
|
|
123
|
+
{
|
|
124
|
+
name: "resolution",
|
|
125
|
+
enum: [...new Set([...IMAGE_RESOLUTIONS, ...VIDEO_RESOLUTIONS])],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "size",
|
|
129
|
+
description: "Image output size WIDTHxHEIGHT for models with parameters.size.supported.",
|
|
130
|
+
},
|
|
131
|
+
{ name: "enhance-prompt", type: "boolean" },
|
|
132
|
+
],
|
|
133
|
+
}),
|
|
134
|
+
commandSpec({
|
|
135
|
+
command: ["generate", "audio-quote"],
|
|
136
|
+
usage: "blitzreels generate audio-quote --kind music|sound|voiceover [--characters N] [--seconds N] [--preview] [--recovery] [--narration-take] [--json]",
|
|
137
|
+
discovery: "detail",
|
|
138
|
+
mutates: false,
|
|
139
|
+
description: "Read audio eligibility, credits and maximum workspace spending without starting work.",
|
|
140
|
+
flags: [
|
|
141
|
+
{ name: "kind", enum: ["voiceover", "music", "sound"] },
|
|
142
|
+
{ name: "characters", type: "number" },
|
|
143
|
+
{ name: "seconds", type: "number" },
|
|
144
|
+
{ name: "preview", type: "boolean" },
|
|
145
|
+
{ name: "recovery", type: "boolean" },
|
|
146
|
+
{ name: "narration-take", type: "boolean" },
|
|
147
|
+
],
|
|
148
|
+
}),
|
|
39
149
|
commandSpec({
|
|
40
150
|
command: ["generate", "plan-brief"],
|
|
41
151
|
usage: "blitzreels generate plan-brief --prompt TEXT [--model ID] [--duration 30] [--json]",
|
|
@@ -51,9 +161,9 @@ export const GENERATION_COMMAND_SPECS = [
|
|
|
51
161
|
commandSpec({
|
|
52
162
|
command: ["generate", "images"],
|
|
53
163
|
usage: "blitzreels generate images --prompt TEXT [--model ID] " +
|
|
54
|
-
"[--aspect-ratio 1:1] [--resolution 4k] [--reference FILE] " +
|
|
55
|
-
"[--reference-asset-id ID] [--output FILE] [--no-wait] [--json]",
|
|
56
|
-
description: "Generate one image as a durable workspace asset.",
|
|
164
|
+
"[--aspect-ratio 1:1 | --size 1920x2304] [--resolution 4k] [--character-id ID] [--reference FILE] " +
|
|
165
|
+
"[--reference-asset-id ID] [--output FILE] [--batch FILE] [--no-wait] [--json]",
|
|
166
|
+
description: "Generate one image as a durable workspace asset, or one per --batch entry.",
|
|
57
167
|
flags: [
|
|
58
168
|
"prompt",
|
|
59
169
|
{
|
|
@@ -68,9 +178,18 @@ export const GENERATION_COMMAND_SPECS = [
|
|
|
68
178
|
enum: [...IMAGE_RESOLUTIONS],
|
|
69
179
|
description: "Native output resolution; model support and pricing are listed by --options. Unsupported settings fail.",
|
|
70
180
|
},
|
|
181
|
+
{
|
|
182
|
+
name: "size",
|
|
183
|
+
description: "Exact output size WIDTHxHEIGHT, replacing --aspect-ratio. Only models with parameters.size.supported in --options; credits scale with pixel count. Invalid sizes fail with the nearest valid size.",
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: "character-id",
|
|
187
|
+
description: "Workspace character to keep consistent; adds its references and description. See parameters.character_id in --options.",
|
|
188
|
+
},
|
|
71
189
|
"reference",
|
|
72
190
|
"reference-asset-id",
|
|
73
191
|
"folder-id",
|
|
192
|
+
BATCH_FLAG,
|
|
74
193
|
...SHARED_FLAGS,
|
|
75
194
|
],
|
|
76
195
|
mutates: true,
|
|
@@ -80,10 +199,10 @@ export const GENERATION_COMMAND_SPECS = [
|
|
|
80
199
|
command: ["generate", "videos"],
|
|
81
200
|
usage: "blitzreels generate videos --prompt TEXT [--model ID] " +
|
|
82
201
|
"[--duration 5] [--aspect-ratio 9:16] [--resolution 720p] [--source-image FILE] " +
|
|
83
|
-
"[--source-asset-id ID] [--provider auto|byteplus-modelark|fal] " +
|
|
84
|
-
"[--reference FILE] [--output FILE] " +
|
|
202
|
+
"[--source-asset-id ID] [--character-id ID] [--provider auto|byteplus-modelark|fal] " +
|
|
203
|
+
"[--reference FILE] [--output FILE] [--batch FILE] " +
|
|
85
204
|
"[--no-wait] [--json]",
|
|
86
|
-
description: "Generate one video as a durable workspace asset.",
|
|
205
|
+
description: "Generate one video as a durable workspace asset, or one per --batch entry.",
|
|
87
206
|
flags: [
|
|
88
207
|
"prompt",
|
|
89
208
|
{
|
|
@@ -110,6 +229,16 @@ export const GENERATION_COMMAND_SPECS = [
|
|
|
110
229
|
},
|
|
111
230
|
"end-frame-asset-id",
|
|
112
231
|
"reference-video-asset-id",
|
|
232
|
+
{
|
|
233
|
+
name: "from",
|
|
234
|
+
type: "number",
|
|
235
|
+
description: "Start second of the reference video range to swap or edit; the server cuts it and bills its length.",
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: "to",
|
|
239
|
+
type: "number",
|
|
240
|
+
description: "End second of the reference video range (requires --from).",
|
|
241
|
+
},
|
|
113
242
|
{
|
|
114
243
|
name: "transformation",
|
|
115
244
|
description: "JSON object with characters (sourceRole, frontalAssetId, referenceAssetIds), sourcePersonCount, keepOriginalAudio and characterOrientation.",
|
|
@@ -120,8 +249,16 @@ export const GENERATION_COMMAND_SPECS = [
|
|
|
120
249
|
name: "provider",
|
|
121
250
|
description: "Provider override; auto routes to the cheapest compatible provider.",
|
|
122
251
|
},
|
|
252
|
+
{
|
|
253
|
+
name: "character-id",
|
|
254
|
+
description: "Workspace character to keep consistent. Its references come first (@Image1 is the primary), capped to the model limit. See parameters.character_id in --options.",
|
|
255
|
+
},
|
|
123
256
|
"reference",
|
|
124
257
|
"reference-asset-id",
|
|
258
|
+
{
|
|
259
|
+
name: "reference-asset-uri",
|
|
260
|
+
description: "BytePlus ModelArk real-human asset as asset://ID (repeatable). Requires --provider byteplus-modelark and a model whose parameters.reference_asset_uris.supported is true. Numbered after other references (@ImageN).",
|
|
261
|
+
},
|
|
125
262
|
{
|
|
126
263
|
name: "generate-audio",
|
|
127
264
|
type: "boolean",
|
|
@@ -135,6 +272,7 @@ export const GENERATION_COMMAND_SPECS = [
|
|
|
135
272
|
"negative-prompt",
|
|
136
273
|
{ name: "seed", type: "number" },
|
|
137
274
|
"folder-id",
|
|
275
|
+
BATCH_FLAG,
|
|
138
276
|
...SHARED_FLAGS,
|
|
139
277
|
],
|
|
140
278
|
mutates: true,
|
|
@@ -148,7 +286,10 @@ export const GENERATION_COMMAND_SPECS = [
|
|
|
148
286
|
description: "Generate one voiceover as a durable workspace asset.",
|
|
149
287
|
flags: [
|
|
150
288
|
"text",
|
|
151
|
-
|
|
289
|
+
{
|
|
290
|
+
name: "voice-id",
|
|
291
|
+
description: "Catalog voice ID (--options) or a workspace voice ID from voices list, such as a cloned voice.",
|
|
292
|
+
},
|
|
152
293
|
"voice-style",
|
|
153
294
|
{ name: "speed", type: "number" },
|
|
154
295
|
...SHARED_FLAGS,
|
|
@@ -178,7 +319,7 @@ export const GENERATION_COMMAND_SPECS = [
|
|
|
178
319
|
commandSpec({
|
|
179
320
|
command: ["generate", "sounds"],
|
|
180
321
|
usage: "blitzreels generate sounds --prompt TEXT [--duration 2] [--loop] " +
|
|
181
|
-
"[--prompt-influence 0.5] [--output FILE] [--no-wait] [--json]",
|
|
322
|
+
"[--prompt-influence 0.5] [--output FILE] [--batch FILE] [--no-wait] [--json]",
|
|
182
323
|
description: "Generate one sound as a durable workspace asset.",
|
|
183
324
|
flags: [
|
|
184
325
|
"prompt",
|
|
@@ -187,9 +328,14 @@ export const GENERATION_COMMAND_SPECS = [
|
|
|
187
328
|
type: "boolean",
|
|
188
329
|
description: "Enhance the prompt using model and input context.",
|
|
189
330
|
},
|
|
190
|
-
{
|
|
331
|
+
{
|
|
332
|
+
name: "duration",
|
|
333
|
+
type: "number",
|
|
334
|
+
description: "Requested length in seconds. Trailing silence is trimmed; result.durationSeconds reports the delivered length.",
|
|
335
|
+
},
|
|
191
336
|
{ name: "loop", type: "boolean" },
|
|
192
337
|
{ name: "prompt-influence", type: "number" },
|
|
338
|
+
BATCH_FLAG,
|
|
193
339
|
...SHARED_FLAGS,
|
|
194
340
|
],
|
|
195
341
|
mutates: true,
|
|
@@ -343,6 +489,8 @@ async function submitGeneration({ context, kind, }) {
|
|
|
343
489
|
model: flags.string({ name: "model" }),
|
|
344
490
|
aspectRatio: flags.string({ name: "aspect-ratio" }),
|
|
345
491
|
resolution: flags.string({ name: "resolution" }),
|
|
492
|
+
size: flags.string({ name: "size" }) ?? null,
|
|
493
|
+
characterId: flags.string({ name: "character-id" }) ?? null,
|
|
346
494
|
referenceAssetIds: await stageReferences({ context }),
|
|
347
495
|
folderId: flags.string({ name: "folder-id" }) ?? null,
|
|
348
496
|
enhancePrompt: flags.boolean({ name: "enhance-prompt" }),
|
|
@@ -363,6 +511,10 @@ async function submitGeneration({ context, kind, }) {
|
|
|
363
511
|
sourceAssetId,
|
|
364
512
|
transformation: readVideoTransformation({ context }),
|
|
365
513
|
referenceAssetIds: await stageReferences({ context }),
|
|
514
|
+
referenceAssetUris: splitRepeatedFlag({
|
|
515
|
+
value: flags.string({ name: "reference-asset-uri" }),
|
|
516
|
+
}),
|
|
517
|
+
characterId: flags.string({ name: "character-id" }) ?? null,
|
|
366
518
|
endFrameAssetId: flags.string({ name: "end-frame" })
|
|
367
519
|
? await stageLocalFile({
|
|
368
520
|
context,
|
|
@@ -372,6 +524,7 @@ async function submitGeneration({ context, kind, }) {
|
|
|
372
524
|
referenceVideoAssetIds: splitRepeatedFlag({
|
|
373
525
|
value: flags.string({ name: "reference-video-asset-id" }),
|
|
374
526
|
}),
|
|
527
|
+
referenceVideoRange: readVideoRange({ context }),
|
|
375
528
|
referenceAudioAssetIds: splitRepeatedFlag({
|
|
376
529
|
value: flags.string({ name: "reference-audio-asset-id" }),
|
|
377
530
|
}),
|
|
@@ -451,21 +604,7 @@ async function submitGeneration({ context, kind, }) {
|
|
|
451
604
|
idempotencyKey,
|
|
452
605
|
});
|
|
453
606
|
}
|
|
454
|
-
|
|
455
|
-
const job = await context.client.generation.wait({
|
|
456
|
-
jobId: receipt.job_id,
|
|
457
|
-
intervalMs: 3000,
|
|
458
|
-
timeoutMs: 30 * 60 * 1000,
|
|
459
|
-
});
|
|
460
|
-
const output = context.invocation.flags.string({ name: "output" });
|
|
461
|
-
if (!output) {
|
|
462
|
-
return job;
|
|
463
|
-
}
|
|
464
|
-
const outputPath = resolve(output);
|
|
465
|
-
await writeFile(outputPath, Buffer.from(await context.client.generation.download({ jobId: receipt.job_id })));
|
|
466
|
-
return { ...job, output_path: outputPath };
|
|
467
|
-
}
|
|
468
|
-
function humanResult({ result, }) {
|
|
607
|
+
export function humanGenerationResult({ result, }) {
|
|
469
608
|
return [
|
|
470
609
|
`Generation job: ${result.job_id}`,
|
|
471
610
|
`Status: ${result.status}`,
|
|
@@ -474,6 +613,12 @@ function humanResult({ result, }) {
|
|
|
474
613
|
...("download_url" in result && result.download_url
|
|
475
614
|
? [`Download: ${result.download_url}`]
|
|
476
615
|
: []),
|
|
616
|
+
...("result" in result && typeof result.result?.durationSeconds === "number"
|
|
617
|
+
? [`Duration: ${result.result.durationSeconds}s`]
|
|
618
|
+
: []),
|
|
619
|
+
...("output_path" in result && result.output_path
|
|
620
|
+
? [`Output: ${result.output_path}`]
|
|
621
|
+
: []),
|
|
477
622
|
];
|
|
478
623
|
}
|
|
479
624
|
function buildGenerationDryRunBody({ context, kind, }) {
|
|
@@ -491,6 +636,8 @@ function buildGenerationDryRunBody({ context, kind, }) {
|
|
|
491
636
|
model: flags.string({ name: "model" }),
|
|
492
637
|
aspect_ratio: flags.string({ name: "aspect-ratio" }),
|
|
493
638
|
resolution: flags.string({ name: "resolution" }),
|
|
639
|
+
size: flags.string({ name: "size" }),
|
|
640
|
+
character_id: flags.string({ name: "character-id" }),
|
|
494
641
|
reference_asset_ids: [...referenceAssetIds, ...stagedReferences],
|
|
495
642
|
folder_id: flags.string({ name: "folder-id" }),
|
|
496
643
|
};
|
|
@@ -508,6 +655,10 @@ function buildGenerationDryRunBody({ context, kind, }) {
|
|
|
508
655
|
? `<staged:${resolve(sourceImage)}>`
|
|
509
656
|
: flags.string({ name: "source-asset-id" }),
|
|
510
657
|
reference_asset_ids: [...referenceAssetIds, ...stagedReferences],
|
|
658
|
+
reference_asset_uris: splitRepeatedFlag({
|
|
659
|
+
value: flags.string({ name: "reference-asset-uri" }),
|
|
660
|
+
}),
|
|
661
|
+
character_id: flags.string({ name: "character-id" }),
|
|
511
662
|
end_frame_asset_id: flags.string({ name: "end-frame" })
|
|
512
663
|
? `<staged:${resolve(flags.string({ name: "end-frame" }))}>`
|
|
513
664
|
: flags.string({ name: "end-frame-asset-id" }),
|
|
@@ -515,6 +666,7 @@ function buildGenerationDryRunBody({ context, kind, }) {
|
|
|
515
666
|
reference_video_asset_ids: splitRepeatedFlag({
|
|
516
667
|
value: flags.string({ name: "reference-video-asset-id" }),
|
|
517
668
|
}),
|
|
669
|
+
reference_video_range: readVideoRange({ context }),
|
|
518
670
|
reference_audio_asset_ids: splitRepeatedFlag({
|
|
519
671
|
value: flags.string({ name: "reference-audio-asset-id" }),
|
|
520
672
|
}),
|
|
@@ -576,6 +728,45 @@ export function createGenerationCommandOperation({ helpers, }) {
|
|
|
576
728
|
name: "generation",
|
|
577
729
|
matches: ({ command }) => GENERATION_COMMANDS.some((candidate) => candidate[0] === command[0] && candidate[1] === command[1]),
|
|
578
730
|
handle: async ({ context }) => {
|
|
731
|
+
if (context.args.command[1] === "quote") {
|
|
732
|
+
const flags = context.invocation.flags;
|
|
733
|
+
const value = generationSpendQuoteInputSchema.parse({
|
|
734
|
+
kind: flags.string({ name: "kind" }),
|
|
735
|
+
model: flags.string({ name: "model" }) ?? null,
|
|
736
|
+
sourceImageModel: flags.string({ name: "source-image-model" }) ?? null,
|
|
737
|
+
seconds: flags.number({ name: "seconds" }) ?? null,
|
|
738
|
+
resolution: flags.string({ name: "resolution" }) ?? null,
|
|
739
|
+
size: flags.string({ name: "size" }) ?? null,
|
|
740
|
+
enhancePrompt: flags.boolean({ name: "enhance-prompt" }),
|
|
741
|
+
});
|
|
742
|
+
const quote = await context.client.generation.quote(value);
|
|
743
|
+
helpers.printResult({
|
|
744
|
+
json: context.json,
|
|
745
|
+
value: quote,
|
|
746
|
+
human: [JSON.stringify(quote, null, 2)],
|
|
747
|
+
fields: context.fields,
|
|
748
|
+
});
|
|
749
|
+
return true;
|
|
750
|
+
}
|
|
751
|
+
if (context.args.command[1] === "audio-quote") {
|
|
752
|
+
const flags = context.invocation.flags;
|
|
753
|
+
const value = audioSpendQuoteInputSchema.parse({
|
|
754
|
+
kind: flags.string({ name: "kind" }),
|
|
755
|
+
characters: flags.number({ name: "characters" }) ?? null,
|
|
756
|
+
seconds: flags.number({ name: "seconds" }) ?? null,
|
|
757
|
+
preview: flags.boolean({ name: "preview" }),
|
|
758
|
+
recovery: flags.boolean({ name: "recovery" }),
|
|
759
|
+
narrationTake: flags.boolean({ name: "narration-take" }),
|
|
760
|
+
});
|
|
761
|
+
const quote = await context.client.generation.quoteAudio(value);
|
|
762
|
+
helpers.printResult({
|
|
763
|
+
json: context.json,
|
|
764
|
+
value: quote,
|
|
765
|
+
human: [JSON.stringify(quote, null, 2)],
|
|
766
|
+
fields: context.fields,
|
|
767
|
+
});
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
579
770
|
if (context.args.command[1] === "plan-brief") {
|
|
580
771
|
const flags = context.invocation.flags;
|
|
581
772
|
const result = await context.client.generation.planBrief({
|
|
@@ -592,11 +783,18 @@ export function createGenerationCommandOperation({ helpers, }) {
|
|
|
592
783
|
});
|
|
593
784
|
return true;
|
|
594
785
|
}
|
|
595
|
-
|
|
786
|
+
if (context.args.command[1] === "compare") {
|
|
787
|
+
await runModelComparison({ context, helpers });
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
const kind = context.args.command[1] === "models"
|
|
791
|
+
? readModelsKind({ context })
|
|
792
|
+
: kindForCommand({ command: context.args.command });
|
|
596
793
|
if (kind === null) {
|
|
597
794
|
return false;
|
|
598
795
|
}
|
|
599
|
-
if (context.
|
|
796
|
+
if (context.args.command[1] === "models" ||
|
|
797
|
+
context.invocation.flags.boolean({ name: "options" })) {
|
|
600
798
|
const options = await context.client.generation.options({ kind });
|
|
601
799
|
helpers.printResult({
|
|
602
800
|
json: context.json,
|
|
@@ -606,20 +804,50 @@ export function createGenerationCommandOperation({ helpers, }) {
|
|
|
606
804
|
});
|
|
607
805
|
return true;
|
|
608
806
|
}
|
|
807
|
+
if (context.invocation.flags.string({ name: "batch" })) {
|
|
808
|
+
await runGenerationBatch({ context, kind, helpers });
|
|
809
|
+
return true;
|
|
810
|
+
}
|
|
609
811
|
const receipt = await submitGeneration({ context, kind });
|
|
610
812
|
await clearUploadReceipts({ context });
|
|
611
813
|
const result = context.invocation.flags.boolean({ name: "no-wait" })
|
|
612
814
|
? receipt
|
|
613
|
-
: await
|
|
815
|
+
: await waitForGenerationJob({
|
|
816
|
+
context,
|
|
817
|
+
jobId: receipt.job_id,
|
|
818
|
+
label: `Generation ${receipt.job_id}`,
|
|
819
|
+
output: context.invocation.flags.string({ name: "output" }),
|
|
820
|
+
timeoutMs: DEFAULT_GENERATION_WAIT_TIMEOUT_MS,
|
|
821
|
+
intervalMs: GENERATION_POLL_INTERVAL_MS,
|
|
822
|
+
});
|
|
614
823
|
helpers.printResult({
|
|
615
824
|
json: context.json,
|
|
616
825
|
value: result,
|
|
617
|
-
human:
|
|
826
|
+
human: humanGenerationResult({ result }),
|
|
618
827
|
fields: context.fields,
|
|
619
828
|
});
|
|
620
829
|
return true;
|
|
621
830
|
},
|
|
622
|
-
buildDryRun: ({ context, spec }) => {
|
|
831
|
+
buildDryRun: async ({ context, spec }) => {
|
|
832
|
+
if (context.args.command[1] === "compare") {
|
|
833
|
+
const entries = await buildComparisonEntries({ context, stage: false });
|
|
834
|
+
const [first, ...rest] = entries.map((entry) => buildGenerationDryRunBody({ context: entry.context, kind: "video" }));
|
|
835
|
+
return helpers.dryRunRequest({
|
|
836
|
+
spec,
|
|
837
|
+
method: "POST",
|
|
838
|
+
path: "/generate-video",
|
|
839
|
+
body: first,
|
|
840
|
+
followUpRequests: rest.map((body, index) => ({
|
|
841
|
+
method: "POST",
|
|
842
|
+
path: "/generate-video",
|
|
843
|
+
body,
|
|
844
|
+
reason: `Model ${index + 2} of ${entries.length}.`,
|
|
845
|
+
})),
|
|
846
|
+
notes: [
|
|
847
|
+
`Submits ${entries.length} generations in parallel, one per model.`,
|
|
848
|
+
],
|
|
849
|
+
});
|
|
850
|
+
}
|
|
623
851
|
const kind = kindForCommand({ command: context.args.command });
|
|
624
852
|
if (kind === null) {
|
|
625
853
|
return undefined;
|
|
@@ -634,6 +862,34 @@ export function createGenerationCommandOperation({ helpers, }) {
|
|
|
634
862
|
notes: ["No generation job or credit spend."],
|
|
635
863
|
});
|
|
636
864
|
}
|
|
865
|
+
if (context.invocation.flags.string({ name: "batch" })) {
|
|
866
|
+
const entries = await readBatchEntries({ context });
|
|
867
|
+
const [first, ...rest] = entries.map((entry) => buildGenerationDryRunBody({ context: entry.context, kind }));
|
|
868
|
+
return helpers.dryRunRequest({
|
|
869
|
+
spec,
|
|
870
|
+
method: "POST",
|
|
871
|
+
path: `/generate-${kind}`,
|
|
872
|
+
body: first,
|
|
873
|
+
followUpRequests: [
|
|
874
|
+
...rest.map((body, index) => ({
|
|
875
|
+
method: "POST",
|
|
876
|
+
path: `/generate-${kind}`,
|
|
877
|
+
body,
|
|
878
|
+
reason: `Submit batch entry ${index + 2} of ${entries.length}.`,
|
|
879
|
+
})),
|
|
880
|
+
{
|
|
881
|
+
method: "GET",
|
|
882
|
+
path: "/generation-jobs/{job_id}",
|
|
883
|
+
body: undefined,
|
|
884
|
+
reason: "Poll every submitted job until it is terminal.",
|
|
885
|
+
},
|
|
886
|
+
],
|
|
887
|
+
notes: [
|
|
888
|
+
`Submits ${entries.length} generations, one per batch entry, before waiting on all of them.`,
|
|
889
|
+
"Local reference files are staged before submission.",
|
|
890
|
+
],
|
|
891
|
+
});
|
|
892
|
+
}
|
|
637
893
|
return helpers.dryRunRequest({
|
|
638
894
|
spec,
|
|
639
895
|
method: "POST",
|
|
@@ -666,4 +922,407 @@ function readVideoTransformation({ context }) {
|
|
|
666
922
|
});
|
|
667
923
|
}
|
|
668
924
|
}
|
|
925
|
+
function readModelsKind({ context }) {
|
|
926
|
+
const kind = context.invocation.flags.requiredString({ name: "kind" });
|
|
927
|
+
const match = GENERATION_KINDS.find((candidate) => candidate === kind);
|
|
928
|
+
if (!match) {
|
|
929
|
+
throw new CliUsageError({
|
|
930
|
+
code: "invalid_flag_value",
|
|
931
|
+
message: `Invalid --kind. Expected ${GENERATION_KINDS.join(", ")}.`,
|
|
932
|
+
usage: specForCommand({ context }).usage,
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
return match;
|
|
936
|
+
}
|
|
937
|
+
function specForCommand({ context }) {
|
|
938
|
+
const spec = GENERATION_COMMAND_SPECS.find((candidate) => candidate.command[1] === context.args.command[1]);
|
|
939
|
+
if (!spec)
|
|
940
|
+
throw new Error(`No spec for generate ${context.args.command[1]}`);
|
|
941
|
+
return spec;
|
|
942
|
+
}
|
|
943
|
+
const GENERATION_POLL_INTERVAL_MS = 3000;
|
|
944
|
+
const MAX_BATCH_ENTRIES = 50;
|
|
945
|
+
const BATCH_ONLY_FLAGS = new Set(["batch", "options", "no-wait"]);
|
|
946
|
+
function usageError({ context, code, message, }) {
|
|
947
|
+
return new CliUsageError({
|
|
948
|
+
code,
|
|
949
|
+
message,
|
|
950
|
+
usage: specForCommand({ context }).usage,
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
async function readBatchEntries({ context, }) {
|
|
954
|
+
const file = context.invocation.flags.requiredString({ name: "batch" });
|
|
955
|
+
let parsed;
|
|
956
|
+
try {
|
|
957
|
+
parsed = JSON.parse(await readFile(resolve(file), "utf8"));
|
|
958
|
+
}
|
|
959
|
+
catch (error) {
|
|
960
|
+
throw usageError({
|
|
961
|
+
context,
|
|
962
|
+
code: "invalid_batch",
|
|
963
|
+
message: `Cannot read --batch ${file}: ${error instanceof Error ? error.message : "invalid JSON"}`,
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
if (!Array.isArray(parsed) ||
|
|
967
|
+
parsed.length === 0 ||
|
|
968
|
+
parsed.length > MAX_BATCH_ENTRIES) {
|
|
969
|
+
throw usageError({
|
|
970
|
+
context,
|
|
971
|
+
code: "invalid_batch",
|
|
972
|
+
message: `--batch must be a JSON array of 1 to ${MAX_BATCH_ENTRIES} entries.`,
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
const { batch: _batch, "idempotency-key": _keyPrefix, ...shared } = context.args.flags;
|
|
976
|
+
if (typeof shared.output === "string") {
|
|
977
|
+
throw usageError({
|
|
978
|
+
context,
|
|
979
|
+
code: "invalid_batch",
|
|
980
|
+
message: "Set output per batch entry, not with --output.",
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
const allowed = new Set(specForCommand({ context })
|
|
984
|
+
.flags.map((flag) => flag.name)
|
|
985
|
+
.filter((name) => !BATCH_ONLY_FLAGS.has(name)));
|
|
986
|
+
const rawEntries = parsed.map((raw, index) => {
|
|
987
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
988
|
+
throw usageError({
|
|
989
|
+
context,
|
|
990
|
+
code: "invalid_batch",
|
|
991
|
+
message: `Batch entry ${index + 1} must be a JSON object.`,
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
const flags = {};
|
|
995
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
996
|
+
if (!allowed.has(name)) {
|
|
997
|
+
throw usageError({
|
|
998
|
+
context,
|
|
999
|
+
code: "unknown_flag",
|
|
1000
|
+
message: `Batch entry ${index + 1}: unknown flag "${name}".`,
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
flags[name] = batchFlagValue({ context, index, name, value });
|
|
1004
|
+
}
|
|
1005
|
+
return flags;
|
|
1006
|
+
});
|
|
1007
|
+
return buildBatchEntries({
|
|
1008
|
+
context,
|
|
1009
|
+
shared,
|
|
1010
|
+
rawEntries,
|
|
1011
|
+
keyPrefix: context.invocation.flags.string({ name: "idempotency-key" }),
|
|
1012
|
+
labels: rawEntries.map(() => null),
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
function buildBatchEntries({ context, shared, rawEntries, keyPrefix, labels, }) {
|
|
1016
|
+
const entries = rawEntries.map((raw, index) => {
|
|
1017
|
+
const flags = { ...shared, ...raw };
|
|
1018
|
+
const idempotencyKey = typeof flags["idempotency-key"] === "string"
|
|
1019
|
+
? flags["idempotency-key"]
|
|
1020
|
+
: keyPrefix
|
|
1021
|
+
? `${keyPrefix}-${labels[index] ?? index + 1}`
|
|
1022
|
+
: null;
|
|
1023
|
+
if (!idempotencyKey) {
|
|
1024
|
+
throw usageError({
|
|
1025
|
+
context,
|
|
1026
|
+
code: "missing_required_flag",
|
|
1027
|
+
message: `Batch entry ${index + 1} needs "idempotency-key", or pass --idempotency-key as a prefix.`,
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
flags["idempotency-key"] = idempotencyKey;
|
|
1031
|
+
return {
|
|
1032
|
+
index,
|
|
1033
|
+
idempotencyKey,
|
|
1034
|
+
label: labels[index] ??
|
|
1035
|
+
`[${index + 1}/${rawEntries.length}] ${idempotencyKey}`,
|
|
1036
|
+
output: typeof flags.output === "string" ? flags.output : undefined,
|
|
1037
|
+
context: {
|
|
1038
|
+
...context,
|
|
1039
|
+
invocation: {
|
|
1040
|
+
...context.invocation,
|
|
1041
|
+
flags: createFlagReader({ flags }),
|
|
1042
|
+
},
|
|
1043
|
+
},
|
|
1044
|
+
};
|
|
1045
|
+
});
|
|
1046
|
+
for (const field of ["idempotencyKey", "output"]) {
|
|
1047
|
+
const values = entries
|
|
1048
|
+
.map((entry) => entry[field])
|
|
1049
|
+
.filter((value) => value !== undefined)
|
|
1050
|
+
.map((value) => (field === "output" ? resolve(value) : value));
|
|
1051
|
+
const duplicate = values.find((value, index) => values.indexOf(value) !== index);
|
|
1052
|
+
if (duplicate) {
|
|
1053
|
+
throw usageError({
|
|
1054
|
+
context,
|
|
1055
|
+
code: "invalid_batch",
|
|
1056
|
+
message: `Batch entries share ${field === "output" ? "output" : "idempotency-key"} ${duplicate}.`,
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return entries;
|
|
1061
|
+
}
|
|
1062
|
+
function batchFlagValue({ context, index, name, value, }) {
|
|
1063
|
+
if (typeof value === "string" || typeof value === "boolean")
|
|
1064
|
+
return value;
|
|
1065
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
1066
|
+
return String(value);
|
|
1067
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string"))
|
|
1068
|
+
return value.join(",");
|
|
1069
|
+
throw usageError({
|
|
1070
|
+
context,
|
|
1071
|
+
code: "invalid_flag_value",
|
|
1072
|
+
message: `Batch entry ${index + 1}: "${name}" must be a string, number, boolean or string array.`,
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
async function executeBatchEntries({ context, kind, entries, review, }) {
|
|
1076
|
+
const items = entries.map((entry) => ({
|
|
1077
|
+
index: entry.index,
|
|
1078
|
+
idempotency_key: entry.idempotencyKey,
|
|
1079
|
+
job_id: null,
|
|
1080
|
+
status: "not_submitted",
|
|
1081
|
+
media_id: null,
|
|
1082
|
+
estimated_credits: null,
|
|
1083
|
+
elapsed_seconds: null,
|
|
1084
|
+
output_path: null,
|
|
1085
|
+
error: null,
|
|
1086
|
+
request_id: null,
|
|
1087
|
+
resume_command: null,
|
|
1088
|
+
review: null,
|
|
1089
|
+
}));
|
|
1090
|
+
const submitted = [];
|
|
1091
|
+
for (const entry of entries) {
|
|
1092
|
+
const item = items[entry.index];
|
|
1093
|
+
try {
|
|
1094
|
+
const receipt = await submitGeneration({ context: entry.context, kind });
|
|
1095
|
+
await clearUploadReceipts({ context: entry.context });
|
|
1096
|
+
Object.assign(item, {
|
|
1097
|
+
job_id: receipt.job_id,
|
|
1098
|
+
status: receipt.status,
|
|
1099
|
+
estimated_credits: receipt.estimated_credits,
|
|
1100
|
+
});
|
|
1101
|
+
submitted.push({ entry, receipt, submittedAt: Date.now() });
|
|
1102
|
+
console.error(`${entry.label}: submitted job ${receipt.job_id}`);
|
|
1103
|
+
}
|
|
1104
|
+
catch (error) {
|
|
1105
|
+
Object.assign(item, {
|
|
1106
|
+
status: "submission_failed",
|
|
1107
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1108
|
+
request_id: error instanceof BlitzReelsError ? error.requestId : null,
|
|
1109
|
+
});
|
|
1110
|
+
console.error(`${entry.label}: submission failed: ${item.error}`);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (context.invocation.flags.boolean({ name: "no-wait" }))
|
|
1114
|
+
return { items, submittedCount: submitted.length };
|
|
1115
|
+
await Promise.all(submitted.map(async ({ entry, receipt, submittedAt }) => {
|
|
1116
|
+
const item = items[entry.index];
|
|
1117
|
+
try {
|
|
1118
|
+
const job = await waitForGenerationJob({
|
|
1119
|
+
context: entry.context,
|
|
1120
|
+
jobId: receipt.job_id,
|
|
1121
|
+
label: entry.label,
|
|
1122
|
+
output: entry.output,
|
|
1123
|
+
timeoutMs: DEFAULT_GENERATION_WAIT_TIMEOUT_MS,
|
|
1124
|
+
intervalMs: Math.max(GENERATION_POLL_INTERVAL_MS, submitted.length * 1000),
|
|
1125
|
+
});
|
|
1126
|
+
Object.assign(item, {
|
|
1127
|
+
status: job.status,
|
|
1128
|
+
media_id: job.media_id,
|
|
1129
|
+
elapsed_seconds: Math.round((Date.now() - submittedAt) / 1000),
|
|
1130
|
+
output_path: job.output_path ?? null,
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
catch (error) {
|
|
1134
|
+
const terminal = error instanceof BlitzReelsError && error.status === 422;
|
|
1135
|
+
Object.assign(item, {
|
|
1136
|
+
status: terminal ? "failed" : "wait_failed",
|
|
1137
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1138
|
+
resume_command: terminal
|
|
1139
|
+
? null
|
|
1140
|
+
: `blitzreels jobs wait --job-id ${receipt.job_id}${entry.output ? ` --output ${entry.output}` : ""}`,
|
|
1141
|
+
});
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
if (!review)
|
|
1145
|
+
return;
|
|
1146
|
+
item.review = await reviewGenerationOutput({
|
|
1147
|
+
context: entry.context,
|
|
1148
|
+
jobId: receipt.job_id,
|
|
1149
|
+
characterId: review.characterId,
|
|
1150
|
+
frameCount: review.frameCount,
|
|
1151
|
+
waitForTranscript: true,
|
|
1152
|
+
outputDir: review.outputDir,
|
|
1153
|
+
label: entry.label,
|
|
1154
|
+
}).catch((error) => {
|
|
1155
|
+
console.error(`${entry.label}: review failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1156
|
+
return null;
|
|
1157
|
+
});
|
|
1158
|
+
}));
|
|
1159
|
+
return { items, submittedCount: submitted.length };
|
|
1160
|
+
}
|
|
1161
|
+
function throwOnBatchFailures({ items, noun, }) {
|
|
1162
|
+
const failed = items.filter((item) => item.error !== null);
|
|
1163
|
+
if (failed.length === 0)
|
|
1164
|
+
return;
|
|
1165
|
+
throw new CliOperationError({
|
|
1166
|
+
code: "partial_failure",
|
|
1167
|
+
exitCode: 5,
|
|
1168
|
+
retryable: false,
|
|
1169
|
+
message: `${failed.length} of ${items.length} ${noun} failed.`,
|
|
1170
|
+
suggestions: failed.flatMap((item) => item.resume_command ? [item.resume_command] : []),
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
async function runGenerationBatch({ context, kind, helpers, }) {
|
|
1174
|
+
const entries = await readBatchEntries({ context });
|
|
1175
|
+
const { items, submittedCount } = await executeBatchEntries({
|
|
1176
|
+
context,
|
|
1177
|
+
kind,
|
|
1178
|
+
entries,
|
|
1179
|
+
review: null,
|
|
1180
|
+
});
|
|
1181
|
+
helpers.printResult({
|
|
1182
|
+
json: context.json,
|
|
1183
|
+
value: {
|
|
1184
|
+
count: items.length,
|
|
1185
|
+
submitted_count: submittedCount,
|
|
1186
|
+
failed_count: items.filter((item) => item.error !== null).length,
|
|
1187
|
+
items,
|
|
1188
|
+
},
|
|
1189
|
+
human: items.map((item) => [
|
|
1190
|
+
`[${item.index + 1}] ${item.idempotency_key}`,
|
|
1191
|
+
item.status,
|
|
1192
|
+
item.job_id ?? "-",
|
|
1193
|
+
item.output_path ?? item.media_id ?? "",
|
|
1194
|
+
item.error ?? "",
|
|
1195
|
+
]
|
|
1196
|
+
.filter(Boolean)
|
|
1197
|
+
.join(" ")),
|
|
1198
|
+
fields: context.fields,
|
|
1199
|
+
});
|
|
1200
|
+
throwOnBatchFailures({ items, noun: "batch generations" });
|
|
1201
|
+
}
|
|
1202
|
+
function nearestDuration({ durations, target, }) {
|
|
1203
|
+
const sorted = [...durations].sort((a, b) => a - b);
|
|
1204
|
+
return (sorted.find((duration) => duration >= target) ?? sorted.at(-1) ?? target);
|
|
1205
|
+
}
|
|
1206
|
+
async function buildComparisonEntries({ context, stage, }) {
|
|
1207
|
+
const flags = context.invocation.flags;
|
|
1208
|
+
const models = splitRepeatedFlag({ value: flags.string({ name: "models" }) });
|
|
1209
|
+
if (models.length < 2 || models.length > 8)
|
|
1210
|
+
throw usageError({
|
|
1211
|
+
context,
|
|
1212
|
+
code: "invalid_flag_value",
|
|
1213
|
+
message: "--models takes 2 to 8 video model IDs.",
|
|
1214
|
+
});
|
|
1215
|
+
const options = (await context.client.generation.options({
|
|
1216
|
+
kind: "video",
|
|
1217
|
+
}));
|
|
1218
|
+
const catalog = new Map((options.models ?? []).map((model) => [model.id, model]));
|
|
1219
|
+
const unknown = models.filter((model) => !catalog.has(model));
|
|
1220
|
+
if (unknown.length)
|
|
1221
|
+
throw usageError({
|
|
1222
|
+
context,
|
|
1223
|
+
code: "invalid_flag_value",
|
|
1224
|
+
message: `Unknown video models: ${unknown.join(", ")}. List them with generate models --kind video.`,
|
|
1225
|
+
});
|
|
1226
|
+
const outputDir = flags.string({ name: "output-dir" });
|
|
1227
|
+
const { models: _models, "output-dir": _outputDir, review: _review, "frame-count": _frameCount, "idempotency-key": _keyPrefix, "generate-audio": _generateAudio, duration: _duration, ...shared } = context.args.flags;
|
|
1228
|
+
const localSource = flags.string({ name: "source-image" });
|
|
1229
|
+
const { "source-image": _sourceImage, ...withoutLocalSource } = shared;
|
|
1230
|
+
const sharedFlags = localSource && stage
|
|
1231
|
+
? {
|
|
1232
|
+
...withoutLocalSource,
|
|
1233
|
+
"source-asset-id": await stageLocalFile({
|
|
1234
|
+
context,
|
|
1235
|
+
filePath: localSource,
|
|
1236
|
+
}),
|
|
1237
|
+
}
|
|
1238
|
+
: shared;
|
|
1239
|
+
const target = flags.number({ name: "duration" }) ?? 5;
|
|
1240
|
+
const wantsAudio = flags.boolean({ name: "generate-audio" });
|
|
1241
|
+
const rawEntries = models.map((model) => {
|
|
1242
|
+
const option = catalog.get(model);
|
|
1243
|
+
return {
|
|
1244
|
+
model,
|
|
1245
|
+
duration: String(nearestDuration({ durations: option.durations_seconds, target })),
|
|
1246
|
+
...(wantsAudio && option.audio_mode === "optional"
|
|
1247
|
+
? { "generate-audio": true }
|
|
1248
|
+
: {}),
|
|
1249
|
+
...(outputDir
|
|
1250
|
+
? { output: join(resolve(outputDir), `${model}.mp4`) }
|
|
1251
|
+
: {}),
|
|
1252
|
+
};
|
|
1253
|
+
});
|
|
1254
|
+
return buildBatchEntries({
|
|
1255
|
+
context,
|
|
1256
|
+
shared: sharedFlags,
|
|
1257
|
+
rawEntries,
|
|
1258
|
+
keyPrefix: flags.requiredString({ name: "idempotency-key" }),
|
|
1259
|
+
labels: models,
|
|
1260
|
+
}).map((entry, index) => ({
|
|
1261
|
+
...entry,
|
|
1262
|
+
model: models[index],
|
|
1263
|
+
durationSeconds: Number(rawEntries[index]?.duration),
|
|
1264
|
+
}));
|
|
1265
|
+
}
|
|
1266
|
+
async function runModelComparison({ context, helpers, }) {
|
|
1267
|
+
const flags = context.invocation.flags;
|
|
1268
|
+
const entries = await buildComparisonEntries({ context, stage: true });
|
|
1269
|
+
const { items } = await executeBatchEntries({
|
|
1270
|
+
context,
|
|
1271
|
+
kind: "video",
|
|
1272
|
+
entries,
|
|
1273
|
+
review: flags.boolean({ name: "review" })
|
|
1274
|
+
? {
|
|
1275
|
+
characterId: flags.string({ name: "character-id" }) ?? null,
|
|
1276
|
+
frameCount: flags.number({ name: "frame-count" }) ?? 4,
|
|
1277
|
+
outputDir: flags.string({ name: "output-dir" }),
|
|
1278
|
+
}
|
|
1279
|
+
: null,
|
|
1280
|
+
});
|
|
1281
|
+
const results = items
|
|
1282
|
+
.map((item) => {
|
|
1283
|
+
const entry = entries[item.index];
|
|
1284
|
+
return {
|
|
1285
|
+
model: entry?.model ?? "",
|
|
1286
|
+
duration_seconds: entry?.durationSeconds ?? null,
|
|
1287
|
+
...item,
|
|
1288
|
+
};
|
|
1289
|
+
})
|
|
1290
|
+
.sort((a, b) => (a.elapsed_seconds ?? Number.POSITIVE_INFINITY) -
|
|
1291
|
+
(b.elapsed_seconds ?? Number.POSITIVE_INFINITY));
|
|
1292
|
+
helpers.printResult({
|
|
1293
|
+
json: context.json,
|
|
1294
|
+
value: {
|
|
1295
|
+
count: results.length,
|
|
1296
|
+
failed_count: results.filter((item) => item.error !== null).length,
|
|
1297
|
+
results,
|
|
1298
|
+
},
|
|
1299
|
+
human: results.map((item) => [
|
|
1300
|
+
item.model.padEnd(24),
|
|
1301
|
+
item.status.padEnd(10),
|
|
1302
|
+
item.elapsed_seconds === null ? "-" : `${item.elapsed_seconds}s`,
|
|
1303
|
+
`${item.estimated_credits ?? "-"} cr`,
|
|
1304
|
+
item.review?.likeness ? `likeness ${item.review.likeness.score}` : "",
|
|
1305
|
+
item.review?.transcript.text ? `"${item.review.transcript.text}"` : "",
|
|
1306
|
+
item.output_path ?? item.error ?? "",
|
|
1307
|
+
]
|
|
1308
|
+
.filter(Boolean)
|
|
1309
|
+
.join(" ")),
|
|
1310
|
+
fields: context.fields,
|
|
1311
|
+
});
|
|
1312
|
+
throwOnBatchFailures({ items, noun: "model runs" });
|
|
1313
|
+
}
|
|
1314
|
+
function readVideoRange({ context, }) {
|
|
1315
|
+
const startSeconds = context.invocation.flags.number({ name: "from" });
|
|
1316
|
+
const endSeconds = context.invocation.flags.number({ name: "to" });
|
|
1317
|
+
if (startSeconds === undefined && endSeconds === undefined)
|
|
1318
|
+
return null;
|
|
1319
|
+
if (startSeconds === undefined ||
|
|
1320
|
+
endSeconds === undefined ||
|
|
1321
|
+
endSeconds <= startSeconds)
|
|
1322
|
+
throw new CliUsageError({
|
|
1323
|
+
code: "invalid_flag_value",
|
|
1324
|
+
message: "Pass both --from and --to, with --to after --from.",
|
|
1325
|
+
});
|
|
1326
|
+
return { startSeconds, endSeconds };
|
|
1327
|
+
}
|
|
669
1328
|
//# sourceMappingURL=generation.js.map
|