videodraft 0.36.0 → 0.37.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 +760 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24,8 +24,8 @@ function readVersionFromDisk() {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
function resolveVersion() {
|
|
27
|
-
if ("0.
|
|
28
|
-
return "0.
|
|
27
|
+
if ("0.37.0") {
|
|
28
|
+
return "0.37.0";
|
|
29
29
|
}
|
|
30
30
|
return readVersionFromDisk();
|
|
31
31
|
}
|
|
@@ -1084,8 +1084,8 @@ var VideoDraftClient = class {
|
|
|
1084
1084
|
* MCP tool by design). Uses the same bearer token + 401 refresh as rpc().
|
|
1085
1085
|
* Returns the parsed JSON body; throws on non-2xx with the server's error.
|
|
1086
1086
|
*/
|
|
1087
|
-
async restRequest(method,
|
|
1088
|
-
const doFetch = (token2) => this.fetchImpl(`${this.baseUrl}${
|
|
1087
|
+
async restRequest(method, path15, body) {
|
|
1088
|
+
const doFetch = (token2) => this.fetchImpl(`${this.baseUrl}${path15}`, {
|
|
1089
1089
|
method,
|
|
1090
1090
|
headers: {
|
|
1091
1091
|
"content-type": "application/json",
|
|
@@ -2040,11 +2040,11 @@ function kindOf(url, typeHint) {
|
|
|
2040
2040
|
if (t.includes("audio") || t.includes("music") || t.includes("sound") || t.includes("voice") || t.includes("speech") || t.includes("tts")) {
|
|
2041
2041
|
return "audio";
|
|
2042
2042
|
}
|
|
2043
|
-
const
|
|
2044
|
-
if (
|
|
2045
|
-
if (
|
|
2046
|
-
if (
|
|
2047
|
-
const ext =
|
|
2043
|
+
const path15 = url.split(/[?#]/)[0]?.toLowerCase() ?? "";
|
|
2044
|
+
if (path15.includes("/img/")) return "image";
|
|
2045
|
+
if (path15.includes("/vid/")) return "video";
|
|
2046
|
+
if (path15.includes("/aud/")) return "audio";
|
|
2047
|
+
const ext = path15.match(/\.([a-z0-9]+)$/)?.[1];
|
|
2048
2048
|
if (ext) {
|
|
2049
2049
|
if (IMAGE_EXTS.has(ext)) return "image";
|
|
2050
2050
|
if (VIDEO_EXTS.has(ext)) return "video";
|
|
@@ -2402,13 +2402,13 @@ function isRetryableAudioError(error) {
|
|
|
2402
2402
|
if (error instanceof TypeError) return true;
|
|
2403
2403
|
return error instanceof DOMException && (error.name === "AbortError" || error.name === "TimeoutError");
|
|
2404
2404
|
}
|
|
2405
|
-
async function callAudioWithRetry(
|
|
2405
|
+
async function callAudioWithRetry(call2, options = {}) {
|
|
2406
2406
|
const attempts = options.attempts ?? 45;
|
|
2407
2407
|
const delayMs = options.delayMs ?? 1500;
|
|
2408
2408
|
const wait = options.wait ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
2409
2409
|
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
2410
2410
|
try {
|
|
2411
|
-
return await
|
|
2411
|
+
return await call2();
|
|
2412
2412
|
} catch (error) {
|
|
2413
2413
|
if (attempt >= attempts || !isRetryableAudioError(error)) throw error;
|
|
2414
2414
|
await wait(delayMs);
|
|
@@ -3759,14 +3759,14 @@ function parseKlingElements(values) {
|
|
|
3759
3759
|
for (const value of values) {
|
|
3760
3760
|
let raw = value;
|
|
3761
3761
|
if (value.startsWith("@")) {
|
|
3762
|
-
const
|
|
3763
|
-
if (!
|
|
3762
|
+
const path15 = value.slice(1);
|
|
3763
|
+
if (!path15 || !fs9.existsSync(path15)) {
|
|
3764
3764
|
throw new CliError(
|
|
3765
|
-
`--element file does not exist: ${
|
|
3765
|
+
`--element file does not exist: ${path15 || value}`,
|
|
3766
3766
|
EXIT.USAGE
|
|
3767
3767
|
);
|
|
3768
3768
|
}
|
|
3769
|
-
raw = fs9.readFileSync(
|
|
3769
|
+
raw = fs9.readFileSync(path15, "utf8");
|
|
3770
3770
|
}
|
|
3771
3771
|
let decoded;
|
|
3772
3772
|
try {
|
|
@@ -9390,7 +9390,7 @@ async function uploadResumable(uploadUrl, filePath, options = {}) {
|
|
|
9390
9390
|
}
|
|
9391
9391
|
const maxAttempts = options.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
|
|
9392
9392
|
const timeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
9393
|
-
const
|
|
9393
|
+
const sleep3 = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
9394
9394
|
const total = fs14.statSync(filePath).size;
|
|
9395
9395
|
if (total <= 0) throw new CliError("Cannot upload an empty file.");
|
|
9396
9396
|
const put = async (headers, body) => {
|
|
@@ -9448,7 +9448,7 @@ async function uploadResumable(uploadUrl, filePath, options = {}) {
|
|
|
9448
9448
|
failures++;
|
|
9449
9449
|
if (failures >= maxAttempts) break;
|
|
9450
9450
|
askSession = true;
|
|
9451
|
-
await
|
|
9451
|
+
await sleep3(backoffMs(failures));
|
|
9452
9452
|
continue;
|
|
9453
9453
|
}
|
|
9454
9454
|
askSession = false;
|
|
@@ -9467,7 +9467,7 @@ async function uploadResumable(uploadUrl, filePath, options = {}) {
|
|
|
9467
9467
|
lastError = `no bytes stored at offset ${offset}`;
|
|
9468
9468
|
failures++;
|
|
9469
9469
|
if (failures >= maxAttempts) break;
|
|
9470
|
-
await
|
|
9470
|
+
await sleep3(backoffMs(failures));
|
|
9471
9471
|
}
|
|
9472
9472
|
offset = outcome.next;
|
|
9473
9473
|
options.onProgress?.(offset, total);
|
|
@@ -9559,9 +9559,9 @@ function renderOutputPath(out, jobId, clipUrl) {
|
|
|
9559
9559
|
if (!out) return path13.join(DEFAULT_OUT_DIR, name);
|
|
9560
9560
|
return path13.extname(out) ? out : path13.join(out, name);
|
|
9561
9561
|
}
|
|
9562
|
-
async function renderCall(
|
|
9562
|
+
async function renderCall(call2) {
|
|
9563
9563
|
try {
|
|
9564
|
-
return await
|
|
9564
|
+
return await call2;
|
|
9565
9565
|
} catch (error) {
|
|
9566
9566
|
if (error instanceof ToolError && error.exitCode !== EXIT.CREDITS && error.data?.http_status === 402) {
|
|
9567
9567
|
throw new CliError(error.message, EXIT.CREDITS, TOP_UP_HINT, error.data);
|
|
@@ -10341,6 +10341,745 @@ function listCost(job) {
|
|
|
10341
10341
|
return job?.cost?.final === true ? `${credits}` : `${credits} so far`;
|
|
10342
10342
|
}
|
|
10343
10343
|
|
|
10344
|
+
// src/commands/session.ts
|
|
10345
|
+
import fs16 from "fs";
|
|
10346
|
+
import path14 from "path";
|
|
10347
|
+
var SKIP_NAMES = /* @__PURE__ */ new Set([".DS_Store", "Thumbs.db"]);
|
|
10348
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
10349
|
+
".git",
|
|
10350
|
+
"node_modules",
|
|
10351
|
+
"__pycache__",
|
|
10352
|
+
".venv",
|
|
10353
|
+
".cache"
|
|
10354
|
+
]);
|
|
10355
|
+
var SKIP_SUFFIXES = [".blend1", ".blend2", ".blend@", ".tmp", ".part"];
|
|
10356
|
+
var BATCH = 1e3;
|
|
10357
|
+
var URL_BATCH = 500;
|
|
10358
|
+
var UPLOAD_PARALLEL = 4;
|
|
10359
|
+
var DOWNLOAD_PARALLEL = 6;
|
|
10360
|
+
var TOP_UP_HINT2 = "Check your balance with `videodraft credits` or top up at https://app.videodraft.ai/pricing";
|
|
10361
|
+
var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
10362
|
+
async function uploadEmpty(uploadUrl) {
|
|
10363
|
+
let last = "";
|
|
10364
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
10365
|
+
try {
|
|
10366
|
+
const res = await fetch(uploadUrl, {
|
|
10367
|
+
method: "PUT",
|
|
10368
|
+
headers: { "content-length": "0" },
|
|
10369
|
+
redirect: "manual",
|
|
10370
|
+
signal: AbortSignal.timeout(6e4)
|
|
10371
|
+
});
|
|
10372
|
+
await res.arrayBuffer().catch(() => void 0);
|
|
10373
|
+
if (res.status === 200 || res.status === 201) return;
|
|
10374
|
+
last = `HTTP ${res.status}`;
|
|
10375
|
+
if (res.status < 500 && res.status !== 429) break;
|
|
10376
|
+
} catch (error) {
|
|
10377
|
+
last = error instanceof Error ? error.message : String(error);
|
|
10378
|
+
}
|
|
10379
|
+
await sleep2(1e3 * 2 ** attempt);
|
|
10380
|
+
}
|
|
10381
|
+
throw new CliError(`Could not upload an empty file: ${last}.`);
|
|
10382
|
+
}
|
|
10383
|
+
async function call(p) {
|
|
10384
|
+
try {
|
|
10385
|
+
return await p;
|
|
10386
|
+
} catch (error) {
|
|
10387
|
+
if (error instanceof ToolError && error.exitCode !== EXIT.CREDITS && error.data?.http_status === 402) {
|
|
10388
|
+
throw new CliError(error.message, EXIT.CREDITS, TOP_UP_HINT2, error.data);
|
|
10389
|
+
}
|
|
10390
|
+
throw error;
|
|
10391
|
+
}
|
|
10392
|
+
}
|
|
10393
|
+
function formatBytes2(bytes) {
|
|
10394
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
10395
|
+
const units = ["KiB", "MiB", "GiB", "TiB"];
|
|
10396
|
+
let value = bytes / 1024;
|
|
10397
|
+
let unit = 0;
|
|
10398
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
10399
|
+
value /= 1024;
|
|
10400
|
+
unit++;
|
|
10401
|
+
}
|
|
10402
|
+
return `${value.toFixed(1)} ${units[unit]}`;
|
|
10403
|
+
}
|
|
10404
|
+
async function mapLimit(items, limit, fn) {
|
|
10405
|
+
const out = new Array(items.length);
|
|
10406
|
+
let next = 0;
|
|
10407
|
+
await Promise.all(
|
|
10408
|
+
Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
10409
|
+
for (; ; ) {
|
|
10410
|
+
const i = next++;
|
|
10411
|
+
if (i >= items.length) return;
|
|
10412
|
+
out[i] = await fn(items[i]);
|
|
10413
|
+
}
|
|
10414
|
+
})
|
|
10415
|
+
);
|
|
10416
|
+
return out;
|
|
10417
|
+
}
|
|
10418
|
+
function positiveInt2(value, flag, max) {
|
|
10419
|
+
if (value === void 0) return void 0;
|
|
10420
|
+
const n = Number(value);
|
|
10421
|
+
if (!/^\d+$/.test(value.trim()) || n < 1 || max !== void 0 && n > max) {
|
|
10422
|
+
throw new UsageError(
|
|
10423
|
+
max === void 0 ? `${flag} must be a whole number of at least 1.` : `${flag} must be a whole number from 1 to ${max}.`
|
|
10424
|
+
);
|
|
10425
|
+
}
|
|
10426
|
+
return n;
|
|
10427
|
+
}
|
|
10428
|
+
function collectFiles(inputs, to) {
|
|
10429
|
+
const base = (to ?? "").replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
10430
|
+
const out = [];
|
|
10431
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10432
|
+
const add = (local, rel) => {
|
|
10433
|
+
const name = path14.basename(local);
|
|
10434
|
+
if (SKIP_NAMES.has(name) || SKIP_SUFFIXES.some((s) => name.endsWith(s)))
|
|
10435
|
+
return;
|
|
10436
|
+
const st = fs16.statSync(local);
|
|
10437
|
+
const remote = [base, rel.split(path14.sep).join("/")].filter(Boolean).join("/");
|
|
10438
|
+
if (seen.has(remote))
|
|
10439
|
+
throw new UsageError(`Two files would land on ${remote}.`);
|
|
10440
|
+
seen.add(remote);
|
|
10441
|
+
out.push({ local, remote, size: st.size, mode: st.mode & 511 });
|
|
10442
|
+
};
|
|
10443
|
+
for (const input of inputs) {
|
|
10444
|
+
const abs = path14.resolve(input);
|
|
10445
|
+
if (!fs16.existsSync(abs)) throw new UsageError(`${input} does not exist.`);
|
|
10446
|
+
const st = fs16.statSync(abs);
|
|
10447
|
+
if (st.isFile()) {
|
|
10448
|
+
add(abs, path14.basename(abs));
|
|
10449
|
+
continue;
|
|
10450
|
+
}
|
|
10451
|
+
if (!st.isDirectory())
|
|
10452
|
+
throw new UsageError(`${input} is not a file or folder.`);
|
|
10453
|
+
const top = path14.basename(abs);
|
|
10454
|
+
const walk = (dir) => {
|
|
10455
|
+
for (const entry of fs16.readdirSync(dir, { withFileTypes: true })) {
|
|
10456
|
+
const full = path14.join(dir, entry.name);
|
|
10457
|
+
if (entry.isDirectory()) {
|
|
10458
|
+
if (!SKIP_DIRS.has(entry.name)) walk(full);
|
|
10459
|
+
} else if (entry.isFile()) {
|
|
10460
|
+
add(full, path14.join(top, path14.relative(abs, full)));
|
|
10461
|
+
}
|
|
10462
|
+
}
|
|
10463
|
+
};
|
|
10464
|
+
walk(abs);
|
|
10465
|
+
}
|
|
10466
|
+
return out;
|
|
10467
|
+
}
|
|
10468
|
+
async function sessionCall(ctx, args) {
|
|
10469
|
+
return call(ctx.client.callTool("cloud_session", compact(args)));
|
|
10470
|
+
}
|
|
10471
|
+
function stateLine(s) {
|
|
10472
|
+
const machine = s?.machine?.phase ? ` (${s.machine.phase}${s.machine.zone ? `, ${s.machine.zone}` : ""})` : "";
|
|
10473
|
+
return `${s?.name ? `${s.name} ` : ""}${s?.session_id}: ${s?.state}${machine}`;
|
|
10474
|
+
}
|
|
10475
|
+
function showSession(ctx, s) {
|
|
10476
|
+
emit(ctx.out, s, (o) => {
|
|
10477
|
+
kv(o, [
|
|
10478
|
+
["session", s?.session_id],
|
|
10479
|
+
["name", s?.name ?? void 0],
|
|
10480
|
+
["state", s?.state],
|
|
10481
|
+
[
|
|
10482
|
+
"machine",
|
|
10483
|
+
s?.machine ? `${s.machine.phase ?? ""}${s.machine.zone ? ` in ${s.machine.zone}` : ""}` : void 0
|
|
10484
|
+
],
|
|
10485
|
+
[
|
|
10486
|
+
"files",
|
|
10487
|
+
s?.files ? `${s.files.count} (${formatBytes2(Number(s.files.bytes ?? 0))})` : void 0
|
|
10488
|
+
],
|
|
10489
|
+
[
|
|
10490
|
+
"commands",
|
|
10491
|
+
s?.commands ? `${s.commands.running} running, ${s.commands.queued} queued` : void 0
|
|
10492
|
+
],
|
|
10493
|
+
[
|
|
10494
|
+
"cost",
|
|
10495
|
+
s?.cost ? `${s.cost.credits} credits (${Math.round(Number(s.cost.gpu_seconds ?? 0) / 60)} GPU-min)` : void 0
|
|
10496
|
+
],
|
|
10497
|
+
[
|
|
10498
|
+
"billing now",
|
|
10499
|
+
typeof s?.billing_per_minute === "number" ? `${s.billing_per_minute} credits/min` : void 0
|
|
10500
|
+
],
|
|
10501
|
+
[
|
|
10502
|
+
"idle pause",
|
|
10503
|
+
s?.idle_minutes ? `after ${s.idle_minutes} idle minute${s.idle_minutes === 1 ? "" : "s"}` : void 0
|
|
10504
|
+
],
|
|
10505
|
+
["budget", s?.budget_credits ?? void 0]
|
|
10506
|
+
]);
|
|
10507
|
+
if (s?.message) note(o, fmt.dim(o, String(s.message)));
|
|
10508
|
+
});
|
|
10509
|
+
}
|
|
10510
|
+
async function waitReady(ctx, session, timeoutMs = 45 * 6e4) {
|
|
10511
|
+
const spin = spinner(ctx.out, "Waiting for the session's GPU machine");
|
|
10512
|
+
const started = Date.now();
|
|
10513
|
+
let last = "";
|
|
10514
|
+
try {
|
|
10515
|
+
for (; ; ) {
|
|
10516
|
+
const s = await sessionCall(ctx, { action: "status", session });
|
|
10517
|
+
const line = stateLine(s);
|
|
10518
|
+
spin.update(line);
|
|
10519
|
+
if (!process.stderr.isTTY && line !== last) note(ctx.out, line);
|
|
10520
|
+
last = line;
|
|
10521
|
+
if (s?.state === "ready") return s;
|
|
10522
|
+
if (s?.state !== "starting") {
|
|
10523
|
+
throw new CliError(
|
|
10524
|
+
`The session is ${s?.state}: ${s?.message ?? ""}`.trim()
|
|
10525
|
+
);
|
|
10526
|
+
}
|
|
10527
|
+
if (Date.now() - started > timeoutMs) {
|
|
10528
|
+
throw new CliError(
|
|
10529
|
+
"The session's machine is still not ready. It keeps its place; check `videodraft render session status`."
|
|
10530
|
+
);
|
|
10531
|
+
}
|
|
10532
|
+
await sleep2(5e3);
|
|
10533
|
+
}
|
|
10534
|
+
} finally {
|
|
10535
|
+
spin.stop();
|
|
10536
|
+
}
|
|
10537
|
+
}
|
|
10538
|
+
async function ensureReady(ctx, session, resume) {
|
|
10539
|
+
const s = await sessionCall(ctx, { action: "status", session });
|
|
10540
|
+
if (s?.state === "ready") return s;
|
|
10541
|
+
if (s?.state === "paused" && resume) {
|
|
10542
|
+
note(
|
|
10543
|
+
ctx.out,
|
|
10544
|
+
fmt.dim(
|
|
10545
|
+
ctx.out,
|
|
10546
|
+
"The session is paused; resuming it on a new machine (its files are saved)."
|
|
10547
|
+
)
|
|
10548
|
+
);
|
|
10549
|
+
await sessionCall(ctx, { action: "resume", session });
|
|
10550
|
+
return waitReady(ctx, session);
|
|
10551
|
+
}
|
|
10552
|
+
if (s?.state === "starting") return waitReady(ctx, session);
|
|
10553
|
+
throw new CliError(`The session is ${s?.state}. ${s?.message ?? ""}`.trim());
|
|
10554
|
+
}
|
|
10555
|
+
async function pushFiles(ctx, session, inputs, to) {
|
|
10556
|
+
const files = collectFiles(inputs, to);
|
|
10557
|
+
if (!files.length) throw new UsageError("Nothing to push.");
|
|
10558
|
+
const total = files.reduce((s, f) => s + f.size, 0);
|
|
10559
|
+
const hashing = spinner(
|
|
10560
|
+
ctx.out,
|
|
10561
|
+
`Hashing ${files.length} files (${formatBytes2(total)})`
|
|
10562
|
+
);
|
|
10563
|
+
let hashed = 0;
|
|
10564
|
+
const entries = await mapLimit(files, 4, async (f) => {
|
|
10565
|
+
const sha = await fileSha256(f.local);
|
|
10566
|
+
hashed++;
|
|
10567
|
+
hashing.update(`Hashing files: ${hashed} of ${files.length}`);
|
|
10568
|
+
return { ...f, sha256: sha };
|
|
10569
|
+
}).finally(() => hashing.stop());
|
|
10570
|
+
const bySha = new Map(entries.map((e) => [e.sha256, e]));
|
|
10571
|
+
const unique = [...bySha.values()];
|
|
10572
|
+
let uploaded = 0;
|
|
10573
|
+
let uploadedBytes = 0;
|
|
10574
|
+
for (let i = 0; i < unique.length; i += BATCH) {
|
|
10575
|
+
const part = unique.slice(i, i + BATCH);
|
|
10576
|
+
const plan = await call(
|
|
10577
|
+
ctx.client.callTool("cloud_session_files", {
|
|
10578
|
+
action: "plan",
|
|
10579
|
+
session,
|
|
10580
|
+
files: part.map((e) => ({ sha256: e.sha256, size: e.size }))
|
|
10581
|
+
})
|
|
10582
|
+
);
|
|
10583
|
+
const missing = Array.isArray(plan?.missing) ? plan.missing : [];
|
|
10584
|
+
const spin = spinner(ctx.out, `Uploading ${missing.length} new files`);
|
|
10585
|
+
try {
|
|
10586
|
+
await mapLimit(missing, UPLOAD_PARALLEL, async (m) => {
|
|
10587
|
+
const e = bySha.get(m.sha256);
|
|
10588
|
+
if (!e) return;
|
|
10589
|
+
if (e.size === 0) await uploadEmpty(String(m.upload_url));
|
|
10590
|
+
else await uploadResumable(String(m.upload_url), e.local);
|
|
10591
|
+
uploaded++;
|
|
10592
|
+
uploadedBytes += e.size;
|
|
10593
|
+
spin.update(
|
|
10594
|
+
`Uploaded ${uploaded} of ${missing.length} new files (${formatBytes2(uploadedBytes)})`
|
|
10595
|
+
);
|
|
10596
|
+
});
|
|
10597
|
+
} finally {
|
|
10598
|
+
spin.stop();
|
|
10599
|
+
}
|
|
10600
|
+
}
|
|
10601
|
+
let result = null;
|
|
10602
|
+
for (let i = 0; i < entries.length; i += BATCH) {
|
|
10603
|
+
result = await call(
|
|
10604
|
+
ctx.client.callTool("cloud_session_files", {
|
|
10605
|
+
action: "commit",
|
|
10606
|
+
session,
|
|
10607
|
+
files: entries.slice(i, i + BATCH).map((e) => ({
|
|
10608
|
+
path: e.remote,
|
|
10609
|
+
sha256: e.sha256,
|
|
10610
|
+
size: e.size,
|
|
10611
|
+
mode: e.mode
|
|
10612
|
+
}))
|
|
10613
|
+
})
|
|
10614
|
+
);
|
|
10615
|
+
}
|
|
10616
|
+
return {
|
|
10617
|
+
files: entries.length,
|
|
10618
|
+
uploaded,
|
|
10619
|
+
uploaded_bytes: uploadedBytes,
|
|
10620
|
+
total_bytes: total,
|
|
10621
|
+
session_files: result
|
|
10622
|
+
};
|
|
10623
|
+
}
|
|
10624
|
+
async function waitCommand(ctx, session, commandId, stream) {
|
|
10625
|
+
let printedBytes = 0;
|
|
10626
|
+
let delay = 1500;
|
|
10627
|
+
for (; ; ) {
|
|
10628
|
+
const c = await call(
|
|
10629
|
+
ctx.client.callTool("cloud_session_command", {
|
|
10630
|
+
action: "status",
|
|
10631
|
+
session,
|
|
10632
|
+
command_id: commandId
|
|
10633
|
+
})
|
|
10634
|
+
);
|
|
10635
|
+
if (stream && !ctx.out.json) {
|
|
10636
|
+
const tail = String(c?.log_tail ?? "");
|
|
10637
|
+
const bytes = Number(c?.log_bytes ?? 0);
|
|
10638
|
+
if (bytes > printedBytes && tail) {
|
|
10639
|
+
const fresh = bytes - printedBytes;
|
|
10640
|
+
process.stderr.write(
|
|
10641
|
+
fresh >= tail.length ? (printedBytes ? "\u2026\n" : "") + tail : tail.slice(tail.length - fresh)
|
|
10642
|
+
);
|
|
10643
|
+
printedBytes = bytes;
|
|
10644
|
+
}
|
|
10645
|
+
}
|
|
10646
|
+
if (!["queued", "running"].includes(String(c?.status))) return c;
|
|
10647
|
+
await sleep2(delay);
|
|
10648
|
+
delay = Math.min(5e3, delay + 500);
|
|
10649
|
+
}
|
|
10650
|
+
}
|
|
10651
|
+
async function pullFiles(ctx, session, prefix, outDir) {
|
|
10652
|
+
const all = [];
|
|
10653
|
+
let after;
|
|
10654
|
+
for (; ; ) {
|
|
10655
|
+
const page = await call(
|
|
10656
|
+
ctx.client.callTool(
|
|
10657
|
+
"cloud_session_files",
|
|
10658
|
+
compact({ action: "list", session, prefix, after, limit: 5e3 })
|
|
10659
|
+
)
|
|
10660
|
+
);
|
|
10661
|
+
all.push(...Array.isArray(page?.files) ? page.files : []);
|
|
10662
|
+
after = page?.next_after ?? void 0;
|
|
10663
|
+
if (!after) break;
|
|
10664
|
+
}
|
|
10665
|
+
if (!all.length)
|
|
10666
|
+
throw new CliError(
|
|
10667
|
+
`No saved files${prefix ? ` under ${prefix}` : ""}. Run \`videodraft render session sync\` if a command just made them.`
|
|
10668
|
+
);
|
|
10669
|
+
const need = [];
|
|
10670
|
+
for (const f of all) {
|
|
10671
|
+
const dest = path14.join(outDir, ...String(f.path).split("/"));
|
|
10672
|
+
if (fs16.existsSync(dest) && fs16.statSync(dest).size === Number(f.size) && await fileSha256(dest) === f.sha256)
|
|
10673
|
+
continue;
|
|
10674
|
+
need.push({ ...f, dest });
|
|
10675
|
+
}
|
|
10676
|
+
const spin = spinner(ctx.out, `Downloading ${need.length} files`);
|
|
10677
|
+
let done = 0;
|
|
10678
|
+
try {
|
|
10679
|
+
for (let i = 0; i < need.length; i += URL_BATCH) {
|
|
10680
|
+
const part = need.slice(i, i + URL_BATCH);
|
|
10681
|
+
const r = await call(
|
|
10682
|
+
ctx.client.callTool("cloud_session_files", {
|
|
10683
|
+
action: "urls",
|
|
10684
|
+
session,
|
|
10685
|
+
paths: part.map((f) => f.path)
|
|
10686
|
+
})
|
|
10687
|
+
);
|
|
10688
|
+
const urls = new Map(
|
|
10689
|
+
(r?.files ?? []).filter((f) => f?.url).map((f) => [f.path, f.url])
|
|
10690
|
+
);
|
|
10691
|
+
await mapLimit(part, DOWNLOAD_PARALLEL, async (f) => {
|
|
10692
|
+
const url = urls.get(f.path);
|
|
10693
|
+
if (!url) return;
|
|
10694
|
+
await downloadUrl(url, f.dest);
|
|
10695
|
+
try {
|
|
10696
|
+
fs16.chmodSync(f.dest, Number(f.mode ?? 420) & 511);
|
|
10697
|
+
} catch {
|
|
10698
|
+
}
|
|
10699
|
+
done++;
|
|
10700
|
+
spin.update(`Downloaded ${done} of ${need.length} files`);
|
|
10701
|
+
});
|
|
10702
|
+
}
|
|
10703
|
+
} finally {
|
|
10704
|
+
spin.stop();
|
|
10705
|
+
}
|
|
10706
|
+
return {
|
|
10707
|
+
files: all.length,
|
|
10708
|
+
downloaded: done,
|
|
10709
|
+
skipped: all.length - need.length,
|
|
10710
|
+
out: outDir
|
|
10711
|
+
};
|
|
10712
|
+
}
|
|
10713
|
+
function registerSessionCommands(program) {
|
|
10714
|
+
const render = program.commands.find((c) => c.name() === "render");
|
|
10715
|
+
if (!render)
|
|
10716
|
+
throw new Error(
|
|
10717
|
+
"registerRenderCommands must run before registerSessionCommands"
|
|
10718
|
+
);
|
|
10719
|
+
const s = render.command("session", { hidden: true }).description(
|
|
10720
|
+
"Cloud sessions: a GPU machine you work on (files, commands, Blender scripts), paused when idle"
|
|
10721
|
+
);
|
|
10722
|
+
s.command("start").description(
|
|
10723
|
+
"Start a session on a cloud GPU machine (billed per second while on; waiting for a GPU is not billed)"
|
|
10724
|
+
).option("--name <name>", "a name to use instead of the session id").option("--from-snapshot <name>", "begin with the files of this snapshot").option(
|
|
10725
|
+
"--idle-minutes <n>",
|
|
10726
|
+
"minutes without work before it pauses itself (default 15)"
|
|
10727
|
+
).option(
|
|
10728
|
+
"--budget <credits>",
|
|
10729
|
+
"pause once the session has cost this many credits"
|
|
10730
|
+
).option("--no-spot", "wait for a regular GPU only").option("--no-wait", "return at once instead of waiting for the machine").action(async function() {
|
|
10731
|
+
const o = this.opts();
|
|
10732
|
+
const ctx = buildContext(this);
|
|
10733
|
+
const budget = o.budget === void 0 ? void 0 : Number(o.budget);
|
|
10734
|
+
if (budget !== void 0 && !(budget > 0))
|
|
10735
|
+
throw new UsageError("--budget must be a positive number of credits.");
|
|
10736
|
+
let st = await sessionCall(ctx, {
|
|
10737
|
+
action: "start",
|
|
10738
|
+
name: o.name,
|
|
10739
|
+
from_snapshot: o.fromSnapshot,
|
|
10740
|
+
idle_minutes: positiveInt2(o.idleMinutes, "--idle-minutes", 1440),
|
|
10741
|
+
budget_credits: budget,
|
|
10742
|
+
spot: o.spot === false ? "never" : void 0
|
|
10743
|
+
});
|
|
10744
|
+
if (o.wait !== false) st = await waitReady(ctx, String(st.session_id));
|
|
10745
|
+
showSession(ctx, st);
|
|
10746
|
+
});
|
|
10747
|
+
s.command("status <session>").description("Show a session (id or name)").action(async function(session) {
|
|
10748
|
+
const ctx = buildContext(this);
|
|
10749
|
+
showSession(ctx, await sessionCall(ctx, { action: "status", session }));
|
|
10750
|
+
});
|
|
10751
|
+
s.command("list").description("List your sessions, running and paused first").option("--name <name>", "only sessions of this name").option("--limit <n>", "how many (default 20)").action(async function() {
|
|
10752
|
+
const o = this.opts();
|
|
10753
|
+
const ctx = buildContext(this);
|
|
10754
|
+
const r = await sessionCall(ctx, {
|
|
10755
|
+
action: "list",
|
|
10756
|
+
name: o.name,
|
|
10757
|
+
limit: positiveInt2(o.limit, "--limit", 100)
|
|
10758
|
+
});
|
|
10759
|
+
emit(ctx.out, r, (out) => {
|
|
10760
|
+
const rows = Array.isArray(r?.sessions) ? r.sessions : [];
|
|
10761
|
+
if (!rows.length)
|
|
10762
|
+
return note(
|
|
10763
|
+
out,
|
|
10764
|
+
"No sessions yet. Start one with `videodraft render session start`."
|
|
10765
|
+
);
|
|
10766
|
+
table(
|
|
10767
|
+
out,
|
|
10768
|
+
["session", "name", "state", "files", "cost", "created"],
|
|
10769
|
+
rows.map((x) => [
|
|
10770
|
+
String(x.session_id),
|
|
10771
|
+
String(x.name ?? ""),
|
|
10772
|
+
String(x.state),
|
|
10773
|
+
`${x.files?.count ?? 0}`,
|
|
10774
|
+
`${x.cost?.credits ?? 0}`,
|
|
10775
|
+
String(x.created_at ?? "").slice(0, 16).replace("T", " ")
|
|
10776
|
+
])
|
|
10777
|
+
);
|
|
10778
|
+
});
|
|
10779
|
+
});
|
|
10780
|
+
for (const [name, verb, help] of [
|
|
10781
|
+
[
|
|
10782
|
+
"pause",
|
|
10783
|
+
"pause",
|
|
10784
|
+
"Save the session's files and switch its machine off (resume later)"
|
|
10785
|
+
],
|
|
10786
|
+
[
|
|
10787
|
+
"resume",
|
|
10788
|
+
"resume",
|
|
10789
|
+
"Resume a paused session on a new machine with its saved files"
|
|
10790
|
+
],
|
|
10791
|
+
[
|
|
10792
|
+
"release",
|
|
10793
|
+
"release",
|
|
10794
|
+
"Save and release the session (its files stay 30 days; snapshot to keep a copy)"
|
|
10795
|
+
]
|
|
10796
|
+
]) {
|
|
10797
|
+
s.command(`${name} <session>`).description(help).option("--no-wait", "return at once").action(async function(session) {
|
|
10798
|
+
const o = this.opts();
|
|
10799
|
+
const ctx = buildContext(this);
|
|
10800
|
+
let st = await sessionCall(ctx, { action: verb, session });
|
|
10801
|
+
if (o.wait !== false && verb === "resume")
|
|
10802
|
+
st = await waitReady(ctx, session);
|
|
10803
|
+
if (o.wait !== false && verb !== "resume") {
|
|
10804
|
+
for (let i = 0; i < 120 && ["pausing", "releasing", "ready"].includes(String(st?.state)); i++) {
|
|
10805
|
+
await sleep2(3e3);
|
|
10806
|
+
st = await sessionCall(ctx, { action: "status", session });
|
|
10807
|
+
}
|
|
10808
|
+
}
|
|
10809
|
+
showSession(ctx, st);
|
|
10810
|
+
});
|
|
10811
|
+
}
|
|
10812
|
+
s.command("push <session> <paths...>").description(
|
|
10813
|
+
"Send files or folders to the session (unchanged contents are not uploaded again)"
|
|
10814
|
+
).option("--to <dir>", "folder inside the session (default: the top folder)").action(async function(session, paths) {
|
|
10815
|
+
const o = this.opts();
|
|
10816
|
+
const ctx = buildContext(this);
|
|
10817
|
+
const r = await pushFiles(ctx, session, paths, o.to);
|
|
10818
|
+
emit(
|
|
10819
|
+
ctx.out,
|
|
10820
|
+
r,
|
|
10821
|
+
(out) => note(
|
|
10822
|
+
out,
|
|
10823
|
+
`Pushed ${r.files} files (${formatBytes2(r.total_bytes)}); uploaded ${r.uploaded} new (${formatBytes2(r.uploaded_bytes)}).`
|
|
10824
|
+
)
|
|
10825
|
+
);
|
|
10826
|
+
});
|
|
10827
|
+
s.command("run <session> <command...>").description(
|
|
10828
|
+
"Run a shell command on the session's machine and stream its output (Blender: `blender -b ...`)"
|
|
10829
|
+
).option("--cwd <dir>", "folder inside the session to run in").option("--timeout <seconds>", "stop the command after this long").option("--detach", "start it and print the command id without waiting").option("--no-resume", "fail instead of resuming a paused session").action(async function(session, command) {
|
|
10830
|
+
const o = this.opts();
|
|
10831
|
+
const ctx = buildContext(this);
|
|
10832
|
+
await ensureReady(ctx, session, o.resume !== false);
|
|
10833
|
+
const c = await call(
|
|
10834
|
+
ctx.client.callTool(
|
|
10835
|
+
"cloud_session_command",
|
|
10836
|
+
compact({
|
|
10837
|
+
action: "run",
|
|
10838
|
+
session,
|
|
10839
|
+
command: command.join(" "),
|
|
10840
|
+
cwd: o.cwd,
|
|
10841
|
+
timeout_s: positiveInt2(o.timeout, "--timeout")
|
|
10842
|
+
})
|
|
10843
|
+
)
|
|
10844
|
+
);
|
|
10845
|
+
if (o.detach)
|
|
10846
|
+
return emit(
|
|
10847
|
+
ctx.out,
|
|
10848
|
+
c,
|
|
10849
|
+
(out) => note(
|
|
10850
|
+
out,
|
|
10851
|
+
`Started ${c.command_id}. Follow it with \`videodraft render session logs ${session} ${c.command_id}\`.`
|
|
10852
|
+
)
|
|
10853
|
+
);
|
|
10854
|
+
const done = await waitCommand(ctx, session, String(c.command_id), true);
|
|
10855
|
+
emit(ctx.out, done, (out) => {
|
|
10856
|
+
if (!String(done?.log_tail ?? "").endsWith("\n"))
|
|
10857
|
+
process.stderr.write("\n");
|
|
10858
|
+
note(
|
|
10859
|
+
out,
|
|
10860
|
+
fmt.dim(
|
|
10861
|
+
out,
|
|
10862
|
+
`${done.command_id}: ${done.status}${done.exit_code !== null && done.exit_code !== void 0 ? ` (exit ${done.exit_code})` : ""}${done.error ? `: ${done.error}` : ""}`
|
|
10863
|
+
)
|
|
10864
|
+
);
|
|
10865
|
+
});
|
|
10866
|
+
if (done?.status !== "done") {
|
|
10867
|
+
process.exitCode = EXIT.ERROR;
|
|
10868
|
+
}
|
|
10869
|
+
});
|
|
10870
|
+
s.command("logs <session> <command_id>").description(
|
|
10871
|
+
"Show a command's status and output (the whole log once it has finished)"
|
|
10872
|
+
).option("--follow", "keep printing until it finishes").action(async function(session, commandId) {
|
|
10873
|
+
const o = this.opts();
|
|
10874
|
+
const ctx = buildContext(this);
|
|
10875
|
+
const c = o.follow ? await waitCommand(ctx, session, commandId, true) : await call(
|
|
10876
|
+
ctx.client.callTool("cloud_session_command", {
|
|
10877
|
+
action: "status",
|
|
10878
|
+
session,
|
|
10879
|
+
command_id: commandId
|
|
10880
|
+
})
|
|
10881
|
+
);
|
|
10882
|
+
if (ctx.out.json) return emit(ctx.out, c);
|
|
10883
|
+
if (!o.follow) {
|
|
10884
|
+
if (c?.log_url) {
|
|
10885
|
+
const res = await fetch(String(c.log_url));
|
|
10886
|
+
process.stdout.write(
|
|
10887
|
+
res.ok ? await res.text() : String(c.log_tail ?? "")
|
|
10888
|
+
);
|
|
10889
|
+
} else process.stdout.write(String(c?.log_tail ?? ""));
|
|
10890
|
+
}
|
|
10891
|
+
note(
|
|
10892
|
+
ctx.out,
|
|
10893
|
+
fmt.dim(
|
|
10894
|
+
ctx.out,
|
|
10895
|
+
`${c.command_id}: ${c.status}${c.exit_code !== null && c.exit_code !== void 0 ? ` (exit ${c.exit_code})` : ""}`
|
|
10896
|
+
)
|
|
10897
|
+
);
|
|
10898
|
+
});
|
|
10899
|
+
s.command("sync <session>").description(
|
|
10900
|
+
"Save what commands changed on the machine (it also saves after every command)"
|
|
10901
|
+
).action(async function(session) {
|
|
10902
|
+
const ctx = buildContext(this);
|
|
10903
|
+
const r = await sessionCall(ctx, { action: "sync", session });
|
|
10904
|
+
const done = await waitCommand(ctx, session, String(r.command_id), false);
|
|
10905
|
+
emit(
|
|
10906
|
+
ctx.out,
|
|
10907
|
+
done,
|
|
10908
|
+
(out) => note(out, String(done?.log_tail ?? done?.status).trim())
|
|
10909
|
+
);
|
|
10910
|
+
if (done?.status !== "done") process.exitCode = 1;
|
|
10911
|
+
});
|
|
10912
|
+
s.command("pull <session> [prefix]").description("Download the session's saved files (or one folder)").option("--out <dir>", "where to put them (default: the current folder)").action(async function(session, prefix) {
|
|
10913
|
+
const o = this.opts();
|
|
10914
|
+
const ctx = buildContext(this);
|
|
10915
|
+
const r = await pullFiles(
|
|
10916
|
+
ctx,
|
|
10917
|
+
session,
|
|
10918
|
+
prefix,
|
|
10919
|
+
path14.resolve(o.out ?? ".")
|
|
10920
|
+
);
|
|
10921
|
+
emit(
|
|
10922
|
+
ctx.out,
|
|
10923
|
+
r,
|
|
10924
|
+
(out) => note(
|
|
10925
|
+
out,
|
|
10926
|
+
`Downloaded ${r.downloaded} files to ${r.out} (${r.skipped} already here).`
|
|
10927
|
+
)
|
|
10928
|
+
);
|
|
10929
|
+
});
|
|
10930
|
+
s.command("scene <session> <path>").description(
|
|
10931
|
+
"Make a .blend in the session a Cloud render scene; prints its scene_sha"
|
|
10932
|
+
).action(async function(session, file) {
|
|
10933
|
+
const ctx = buildContext(this);
|
|
10934
|
+
const r = await sessionCall(ctx, {
|
|
10935
|
+
action: "scene",
|
|
10936
|
+
session,
|
|
10937
|
+
path: file
|
|
10938
|
+
});
|
|
10939
|
+
emit(
|
|
10940
|
+
ctx.out,
|
|
10941
|
+
r,
|
|
10942
|
+
(out) => kv(out, [
|
|
10943
|
+
["scene_sha", r.scene_sha],
|
|
10944
|
+
["path", r.path],
|
|
10945
|
+
["size", formatBytes2(Number(r.size ?? 0))]
|
|
10946
|
+
])
|
|
10947
|
+
);
|
|
10948
|
+
});
|
|
10949
|
+
s.command("blender <session> <path>").description(
|
|
10950
|
+
"Render a .blend from the session on Cloud render (no upload from this computer) and download the MP4"
|
|
10951
|
+
).requiredOption(
|
|
10952
|
+
"--frames <range>",
|
|
10953
|
+
"frames to render, e.g. 1-240 (inclusive)"
|
|
10954
|
+
).option("--name <name>", "a label for the job").option("--gpu <size>", "GPU size from `render prices` (default full)").option("--procs <n>", "Blender processes in parallel on the GPU, 1-4").option("--blender <version>", "Blender version: 5.2 (default) or 4.5").option("--no-spot", "wait for a regular GPU only").option(
|
|
10955
|
+
"--out <path>",
|
|
10956
|
+
"file or folder for the clip (default media/renders/<job>.mp4)"
|
|
10957
|
+
).option("--no-wait", "submit and print the job id without waiting").action(async function(session, file) {
|
|
10958
|
+
const o = this.opts();
|
|
10959
|
+
const ctx = buildContext(this);
|
|
10960
|
+
const m = /^\s*(\d+)\s*(?:-\s*(\d+)\s*)?$/.exec(o.frames);
|
|
10961
|
+
if (!m)
|
|
10962
|
+
throw new UsageError(
|
|
10963
|
+
"--frames must be a range like 1-240 or one frame like 42."
|
|
10964
|
+
);
|
|
10965
|
+
const start = Number(m[1]);
|
|
10966
|
+
const end = m[2] === void 0 ? start : Number(m[2]);
|
|
10967
|
+
if (end < start)
|
|
10968
|
+
throw new UsageError("--frames: the last frame is before the first.");
|
|
10969
|
+
const scene = await sessionCall(ctx, {
|
|
10970
|
+
action: "scene",
|
|
10971
|
+
session,
|
|
10972
|
+
path: file
|
|
10973
|
+
});
|
|
10974
|
+
const job = await call(
|
|
10975
|
+
ctx.client.callTool(
|
|
10976
|
+
"cloud_render_submit",
|
|
10977
|
+
compact({
|
|
10978
|
+
scene_sha: scene.scene_sha,
|
|
10979
|
+
start,
|
|
10980
|
+
end,
|
|
10981
|
+
name: o.name,
|
|
10982
|
+
gpu: o.gpu,
|
|
10983
|
+
procs: positiveInt2(o.procs, "--procs", 4),
|
|
10984
|
+
blender_version: o.blender,
|
|
10985
|
+
spot: o.spot === false ? "never" : void 0
|
|
10986
|
+
})
|
|
10987
|
+
)
|
|
10988
|
+
);
|
|
10989
|
+
const jobId = String(job?.job_id ?? "");
|
|
10990
|
+
if (!jobId)
|
|
10991
|
+
throw new CliError("cloud_render_submit did not return a job_id.");
|
|
10992
|
+
if (o.wait === false)
|
|
10993
|
+
return emit(
|
|
10994
|
+
ctx.out,
|
|
10995
|
+
job,
|
|
10996
|
+
(out) => note(
|
|
10997
|
+
out,
|
|
10998
|
+
`Submitted ${jobId}. Wait for it with \`videodraft render wait ${jobId}\`.`
|
|
10999
|
+
)
|
|
11000
|
+
);
|
|
11001
|
+
const spin = spinner(ctx.out, `Rendering ${jobId}`);
|
|
11002
|
+
let final;
|
|
11003
|
+
try {
|
|
11004
|
+
final = await pollRenderJob(ctx.client, jobId, {
|
|
11005
|
+
onTick: (p) => spin.update(
|
|
11006
|
+
`${jobId}: ${p?.status ?? ""} ${p?.message ?? ""}`.trim()
|
|
11007
|
+
)
|
|
11008
|
+
});
|
|
11009
|
+
} finally {
|
|
11010
|
+
spin.stop();
|
|
11011
|
+
}
|
|
11012
|
+
if (final?.status !== "done" || !final?.clip_url) {
|
|
11013
|
+
throw new CliError(
|
|
11014
|
+
`${jobId} ended ${final?.status}: ${final?.error ?? final?.message ?? ""}`.trim()
|
|
11015
|
+
);
|
|
11016
|
+
}
|
|
11017
|
+
const dest = o.out ? fs16.existsSync(o.out) && fs16.statSync(o.out).isDirectory() ? path14.join(o.out, `${jobId}.mp4`) : o.out : path14.join("media", "renders", `${jobId}.mp4`);
|
|
11018
|
+
const saved = await downloadUrl(String(final.clip_url), dest);
|
|
11019
|
+
emit(
|
|
11020
|
+
ctx.out,
|
|
11021
|
+
{ ...final, saved: saved.path },
|
|
11022
|
+
(out) => note(out, `Saved ${saved.path} (${formatBytes2(saved.bytes)}).`)
|
|
11023
|
+
);
|
|
11024
|
+
});
|
|
11025
|
+
s.command("snapshot <session> <name>").description(
|
|
11026
|
+
"Save a named copy of the session's files (kept 30 days) to start sessions from"
|
|
11027
|
+
).option("--replace", "overwrite a snapshot of the same name").action(async function(session, name) {
|
|
11028
|
+
const o = this.opts();
|
|
11029
|
+
const ctx = buildContext(this);
|
|
11030
|
+
const r = await call(
|
|
11031
|
+
ctx.client.callTool(
|
|
11032
|
+
"cloud_session_snapshot",
|
|
11033
|
+
compact({
|
|
11034
|
+
action: "create",
|
|
11035
|
+
session,
|
|
11036
|
+
name,
|
|
11037
|
+
replace: o.replace ? true : void 0
|
|
11038
|
+
})
|
|
11039
|
+
)
|
|
11040
|
+
);
|
|
11041
|
+
emit(
|
|
11042
|
+
ctx.out,
|
|
11043
|
+
r,
|
|
11044
|
+
(out) => note(
|
|
11045
|
+
out,
|
|
11046
|
+
`Snapshot ${r.name}: ${r.files} files (${formatBytes2(Number(r.bytes ?? 0))}), kept until ${String(r.expires_at).slice(0, 10)}.`
|
|
11047
|
+
)
|
|
11048
|
+
);
|
|
11049
|
+
});
|
|
11050
|
+
s.command("snapshots").description("List your snapshots").action(async function() {
|
|
11051
|
+
const ctx = buildContext(this);
|
|
11052
|
+
const r = await call(
|
|
11053
|
+
ctx.client.callTool("cloud_session_snapshot", { action: "list" })
|
|
11054
|
+
);
|
|
11055
|
+
emit(ctx.out, r, (out) => {
|
|
11056
|
+
const rows = Array.isArray(r?.snapshots) ? r.snapshots : [];
|
|
11057
|
+
if (!rows.length) return note(out, "No snapshots yet.");
|
|
11058
|
+
table(
|
|
11059
|
+
out,
|
|
11060
|
+
["name", "files", "size", "created", "kept until"],
|
|
11061
|
+
rows.map((x) => [
|
|
11062
|
+
String(x.name),
|
|
11063
|
+
`${x.files}`,
|
|
11064
|
+
formatBytes2(Number(x.bytes ?? 0)),
|
|
11065
|
+
String(x.created_at).slice(0, 16).replace("T", " "),
|
|
11066
|
+
String(x.expires_at).slice(0, 10)
|
|
11067
|
+
])
|
|
11068
|
+
);
|
|
11069
|
+
});
|
|
11070
|
+
});
|
|
11071
|
+
s.command("snapshot-delete <name>").description("Delete a snapshot").action(async function(name) {
|
|
11072
|
+
const ctx = buildContext(this);
|
|
11073
|
+
const r = await call(
|
|
11074
|
+
ctx.client.callTool("cloud_session_snapshot", {
|
|
11075
|
+
action: "delete",
|
|
11076
|
+
name
|
|
11077
|
+
})
|
|
11078
|
+
);
|
|
11079
|
+
emit(ctx.out, r, (out) => note(out, `Deleted snapshot ${name}.`));
|
|
11080
|
+
});
|
|
11081
|
+
}
|
|
11082
|
+
|
|
10344
11083
|
// src/index.ts
|
|
10345
11084
|
async function configureProxy() {
|
|
10346
11085
|
if (!process.env.HTTPS_PROXY && !process.env.HTTP_PROXY && !process.env.https_proxy && !process.env.http_proxy) {
|
|
@@ -10377,6 +11116,7 @@ function buildProgram() {
|
|
|
10377
11116
|
registerBackgroundRemovalCommands(program);
|
|
10378
11117
|
register3DAssetCommands(program);
|
|
10379
11118
|
registerRenderCommands(program);
|
|
11119
|
+
registerSessionCommands(program);
|
|
10380
11120
|
registerJobCommands(program);
|
|
10381
11121
|
registerMediaCommands(program);
|
|
10382
11122
|
registerStockCommands(program);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "videodraft",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Official VideoDraft CLI for AI videos, images, audio and 3D assets. Agent-friendly: --json everywhere, stable exit codes, async job polling.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|