Spaces:
Configuration error
Configuration error
Download src/adapters/cli/agentic-cli.ts from pirzm1/video-generator: direct link, hf CLI and curl.
- Browser
- Download file 8.09 kB
-
https://huggingface.co/spaces/pirzm1/video-generator/resolve/main/src/adapters/cli/agentic-cli.ts
- Command line
-
hf download hf://spaces/pirzm1/video-generator/src/adapters/cli/agentic-cli.ts
-
curl -L -o agentic-cli.ts https://huggingface.co/spaces/pirzm1/video-generator/resolve/main/src/adapters/cli/agentic-cli.ts
8.09 kB
| /** | |
| * agentic-cli.ts β SIMPLE JSON-INPUT CLI for the agentic pipeline. | |
| * | |
| * Reads `input/agentic-scripts.json`, processes each job through the | |
| * full agentic pipeline (plan β acquire β verify β decide β gate β render). | |
| * | |
| * Supports: | |
| * - Custom scripts with [Visual: filename] (local assets) tags | |
| * - Custom scripts with [Visual: search keywords] (online stock) tags | |
| * - localAssets/videoClips arrays for explicit asset binding | |
| * - All agentic pipeline benefits (gates, AI brain, plugins, operations) | |
| * | |
| * Usage: npx tsx src/adapters/cli/agentic-cli.ts | |
| * npm run generate:agentic | |
| */ | |
| import 'dotenv/config'; | |
| import * as fs from 'fs'; | |
| import * as path from 'path'; | |
| import { runAgenticPipeline } from '../../agentic/orchestrator/pipeline.js'; | |
| import { renderAgenticSlideshow } from '../../agentic/orchestrator/render.js'; | |
| import { AgenticCliJob, buildPipelineRequest } from './cli-job.js'; | |
| // βββ Config ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| const INPUT_DIR = path.join(process.cwd(), 'input', 'scripts'); | |
| const SCRIPTS_FILE = path.join(INPUT_DIR, 'agentic-scripts.json'); | |
| // βββ Config ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // βββ CLI Entry ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async function main() { | |
| console.log('βββββββββββββββββββββββββββββββββββββββββββββββββββββ'); | |
| console.log('β Agentic Video Pipeline CLI β'); | |
| console.log('βββββββββββββββββββββββββββββββββββββββββββββββββββββ'); | |
| console.log(); | |
| if (!fs.existsSync(SCRIPTS_FILE)) { | |
| console.error(`β Input file not found: ${SCRIPTS_FILE}`); | |
| console.error(' Create an agentic-scripts.json file in input/'); | |
| console.error(' See input/agentic-scripts.example.json for format.'); | |
| process.exit(1); | |
| } | |
| const raw = fs.readFileSync(SCRIPTS_FILE, 'utf-8'); | |
| let jobs: AgenticCliJob[]; | |
| try { | |
| jobs = JSON.parse(raw); | |
| if (!Array.isArray(jobs) || jobs.length === 0) { | |
| console.error('β agentic-scripts.json must be a non-empty array.'); | |
| process.exit(1); | |
| } | |
| } catch { | |
| console.error(`β JSON parse error in ${SCRIPTS_FILE}`); | |
| process.exit(1); | |
| } | |
| let completed = 0; | |
| let failed = 0; | |
| for (let i = 0; i < jobs.length; i++) { | |
| const job = jobs[i]; | |
| const jobLabel = job.title || `Job ${i + 1}`; | |
| console.log(`\n${'β'.repeat(55)}`); | |
| console.log(` Job ${i + 1}/${jobs.length}: "${jobLabel}"`); | |
| console.log(`${'β'.repeat(55)}`); | |
| const topic = job.topic ?? job.title ?? 'Untitled video'; | |
| const id = sanitizeId(job.id ?? job.title ?? `job_${Date.now()}`); | |
| const req = buildPipelineRequest(job, id, topic); | |
| try { | |
| const result = await runAgenticPipeline( | |
| req, | |
| (progress) => { | |
| const pct = progress.percent?.toFixed(0) ?? '??'; | |
| const stage = progress.stage ?? '?'; | |
| const msg = (progress.message ?? '').substring(0, 80); | |
| if (pct === '100') { | |
| process.stdout.write(`\r β [${stage}] ${msg}\n`); | |
| } else { | |
| process.stdout.write(`\r β³ [${pct}%] ${stage}: ${msg} `); | |
| } | |
| }, | |
| ); | |
| // dryRun produces no gate/manifest by design β treat successful | |
| // planning as a completed job (no render expected). | |
| if (req.dryRun) { | |
| completed++; | |
| console.log(`\n β DRY RUN OK β ${result.plan.scenes.length} scenes planned, ${result.plan.totalDurationSec}s`); | |
| console.log(` π§ͺ Control-surface validated (no assets fetched, no render)`); | |
| } else if (result.gate.pass && result.manifest) { | |
| completed++; | |
| console.log(`\n β Gate PASS β ${result.plan.scenes.length} scenes, ${result.plan.totalDurationSec}s`); | |
| console.log(` π Workspace: ${result.workspace.root}`); | |
| console.log(` π¬ Rendering video...`); | |
| // Render the final video using the agentic slideshow renderer | |
| const outPath = path.resolve(process.cwd(), 'output', id); | |
| fs.mkdirSync(outPath, { recursive: true }); | |
| // Orientation -> render dimensions. Without this the renderer | |
| // falls back to its hardcoded 720x1280 (portrait) default and | |
| // every orientation renders as portrait (verified visually). | |
| const ORIENT_DIMS: Record<string, { w: number; h: number }> = { | |
| portrait: { w: 720, h: 1280 }, | |
| landscape: { w: 1280, h: 720 }, | |
| square: { w: 1080, h: 1080 }, | |
| }; | |
| const orient = (job.orientation || 'portrait').toLowerCase(); | |
| const dims = ORIENT_DIMS[orient] ?? ORIENT_DIMS.portrait; | |
| const finalMp4 = await renderAgenticSlideshow(result, { | |
| outPath: path.join(outPath, `${job.title || 'output'}.mp4`), | |
| dimensions: dims, | |
| crossfadeSec: 0.3, | |
| burnCaptions: job.captions !== 'none', | |
| intro: job.intro, | |
| outro: job.outro, | |
| // Phase 1 β extended render opts | |
| sfx: job.sfx, | |
| captions: job.captions, | |
| captionTheme: job.captionTheme, | |
| kinetic: job.kineticText, | |
| kenBurns: job.kenBurns, | |
| preset: job.preset, | |
| jCutSec: job.jCutSec, | |
| brand: job.brand, | |
| }); | |
| if (fs.existsSync(finalMp4)) { | |
| const sizeKb = Math.round(fs.statSync(finalMp4).size / 1024); | |
| console.log(` π¬ Output: ${finalMp4} (${sizeKb} KB)`); | |
| } else { | |
| console.log(` β³ Output pending β check workspace: ${result.workspace.root}/render/`); | |
| } | |
| } else { | |
| failed++; | |
| const failReasons = result.gate.checks | |
| .filter((c) => !c.pass) | |
| .map((c) => ` β ${c.id}: ${c.label} β ${c.detail}`) | |
| .join('\n'); | |
| console.log(`\n β Gate FAIL β ${result.plan.scenes.length} scenes`); | |
| if (failReasons) console.log(failReasons); | |
| } | |
| } catch { | |
| failed++; | |
| console.error(`\n β Job failed with error`); | |
| } | |
| } | |
| // βββ Summary ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| console.log(`\n${'β'.repeat(55)}`); | |
| console.log(` Summary: ${completed} completed, ${failed} failed out of ${jobs.length} job(s)`); | |
| if (failed > 0) process.exitCode = 1; | |
| } | |
| function sanitizeId(name: string): string { | |
| return name | |
| .toLowerCase() | |
| .replace(/[^a-z0-9]+/g, '_') | |
| .replace(/^_|_$/g, '') | |
| .substring(0, 64) || `job_${Date.now()}`; | |
| } | |
| main().catch((e) => { | |
| console.error(`\nβ Fatal: ${e.message ?? e}`); | |
| process.exit(1); | |
| }); | |