Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.
TypeScript agentic-aiaiai-agentsai-videocompilerdslffmpeggenerative-aillmmarkup-languagemonorepoplugin-systemprogramming-languagetext-to-videotypescriptvideovideo-automationvideo-clonevideo-editingvideo-generation
import { resolve } from "node:path";
import {
createRuntimeEndpointAdapterFacet,
runtimeConfigExact,
runtimeConfigObject,
runtimeConfigPositiveInteger,
runtimeConfigString,
} from "@hypit/runtime-local/extension";
import {
diagnoseRuntimeExecutable,
resolveRuntimeExecutable,
} from "@hypit/runtime-local/node";
import { createLocalHtmlProvider } from "./provider.js";
import { configuredBrowserPath, browserExecutablePath, selectedBrowserVersion } from "./browser.js";
import type { HtmlBrowserGpu, HtmlQuality, HtmlWorkers } from "./provider.js";
import { localHtmlBrowserProgram } from "./program.js";
const localHTMLRuntimeAdapter = createRuntimeEndpointAdapterFacet({
use: "@hypit/provider-html-local",
activate(context) {
if (context.pool === undefined) throw new Error("local HTML renderer Provider Pool is required");
const config = runtimeConfigObject(context.config, "local HTML renderer");
runtimeConfigExact(config, [
"nodePath", "chromePath", "browserVersion", "browserCacheDirectory", "browserDownloadBaseUrl", "ffprobePath", "ffmpegPath", "workers", "maxWorkers", "quality", "browserGpu",
"defaultConcurrency", "browserCapacity", "initializationTimeoutMs", "frameTimeoutMs", "processTimeoutMs", "maxProcessOutputBytes", "artifactStagingConcurrency", "maxPendingFrameBytes", "maxDecodedSourceBytes", "maxRenderedBytes",
], "local HTML renderer");
runtimeConfigString(config.nodePath, "HTML renderer nodePath");
runtimeConfigString(config.ffprobePath, "HTML renderer ffprobePath");
const workers = config.workers;
if (workers !== undefined && workers !== "auto") {
runtimeConfigPositiveInteger(workers, "HTML renderer workers");
}
const quality = runtimeConfigString(config.quality, "HTML renderer quality");
if (quality !== undefined && quality !== "draft" && quality !== "standard" && quality !== "high") {
throw new Error("HTML renderer quality is invalid");
}
const browserGpu = runtimeConfigString(config.browserGpu, "HTML renderer browserGpu");
if (browserGpu !== undefined && browserGpu !== "auto" && browserGpu !== "software" && browserGpu !== "hardware") {
throw new Error("HTML renderer browserGpu is invalid");
}
const configuredNode = runtimeConfigString(config.nodePath, "HTML renderer nodePath");
const configuredChrome = runtimeConfigString(config.chromePath, "HTML renderer chromePath");
const browserVersion = runtimeConfigString(config.browserVersion, "HTML renderer browserVersion");
const browserDownloadBaseUrl = runtimeConfigString(config.browserDownloadBaseUrl, "HTML renderer browserDownloadBaseUrl");
const configuredCache = runtimeConfigString(config.browserCacheDirectory, "HTML renderer browserCacheDirectory");
const chromePath = configuredBrowserPath({ ...(configuredChrome === undefined ? {} : {
chromePath: resolve(context.dataRoot, configuredChrome),
}) });
const browser = {
...(browserVersion === undefined ? {} : { browserVersion }),
...(browserDownloadBaseUrl === undefined ? {} : { browserDownloadBaseUrl }),
...(chromePath === undefined ? {} : { chromePath }),
...(configuredCache === undefined ? {} : { browserCacheDirectory: resolve(context.dataRoot, configuredCache) }),
};
const configuredFfprobe = runtimeConfigString(config.ffprobePath, "HTML renderer ffprobePath");
const nodePath = resolveRuntimeExecutable(context.dataRoot, configuredNode ?? process.execPath);
const configuredFfmpeg = runtimeConfigString(config.ffmpegPath, "HTML renderer ffmpegPath");
const ffmpegPath = resolveRuntimeExecutable(context.dataRoot, configuredFfmpeg ?? "ffmpeg");
const ffprobePath = resolveRuntimeExecutable(context.dataRoot, configuredFfprobe ?? "ffprobe");
const defaultConcurrency = runtimeConfigPositiveInteger(config.defaultConcurrency, "HTML renderer defaultConcurrency");
const maxWorkers = runtimeConfigPositiveInteger(config.maxWorkers, "HTML renderer maxWorkers");
const browserCapacity = runtimeConfigPositiveInteger(config.browserCapacity, "HTML renderer browserCapacity");
const initializationTimeoutMs = runtimeConfigPositiveInteger(config.initializationTimeoutMs, "HTML renderer initializationTimeoutMs");
const frameTimeoutMs = runtimeConfigPositiveInteger(config.frameTimeoutMs, "HTML renderer frameTimeoutMs");
const processTimeoutMs = runtimeConfigPositiveInteger(config.processTimeoutMs, "HTML renderer processTimeoutMs");
const maxProcessOutputBytes = runtimeConfigPositiveInteger(config.maxProcessOutputBytes, "HTML renderer maxProcessOutputBytes");
const artifactStagingConcurrency = runtimeConfigPositiveInteger(config.artifactStagingConcurrency, "HTML renderer artifactStagingConcurrency");
const maxPendingFrameBytes = runtimeConfigPositiveInteger(config.maxPendingFrameBytes, "HTML renderer maxPendingFrameBytes");
const maxDecodedSourceBytes = runtimeConfigPositiveInteger(config.maxDecodedSourceBytes, "HTML renderer maxDecodedSourceBytes");
const maxRenderedBytes = runtimeConfigPositiveInteger(config.maxRenderedBytes, "HTML renderer maxRenderedBytes");
return {
endpoint: createLocalHtmlProvider({
instance: context.instance,
pool: context.pool,
nodePath,
...browser,
ffprobePath,
ffmpegPath,
...(workers === undefined ? {} : { workers: workers as HtmlWorkers }),
...(maxWorkers === undefined ? {} : { maxWorkers }),
...(quality === undefined ? {} : { quality: quality as HtmlQuality }),
...(browserGpu === undefined ? {} : { browserGpu: browserGpu as HtmlBrowserGpu }),
...(defaultConcurrency === undefined ? {} : { defaultConcurrency }),
...(browserCapacity === undefined ? {} : { browserCapacity }),
...(initializationTimeoutMs === undefined ? {} : { initializationTimeoutMs }),
...(frameTimeoutMs === undefined ? {} : { frameTimeoutMs }),
...(processTimeoutMs === undefined ? {} : { processTimeoutMs }),
...(maxProcessOutputBytes === undefined ? {} : { maxProcessOutputBytes }),
...(artifactStagingConcurrency === undefined ? {} : { artifactStagingConcurrency }),
...(maxPendingFrameBytes === undefined ? {} : { maxPendingFrameBytes }),
...(maxDecodedSourceBytes === undefined ? {} : { maxDecodedSourceBytes }),
...(maxRenderedBytes === undefined ? {} : { maxRenderedBytes }),
}),
program: localHtmlBrowserProgram({
id: context.instance,
nodePath,
...browser,
ffprobePath,
ffmpegPath,
}),
diagnose: async () => [
{ severity: "info", code: "HTML_BROWSER_SELECTION", subject: context.instance,
message: `${chromePath === undefined ? `Managed Chrome Headless Shell ${selectedBrowserVersion(browser)} (${browserVersion === undefined ? "Provider recommendation" : "Profile version"})` : "Profile browser"}: ${browserExecutablePath(browser)}` },
...await diagnoseRuntimeExecutable({ root: context.dataRoot, configured: configuredFfmpeg, fallback: "ffmpeg", subject: "FFmpeg" }),
...await diagnoseRuntimeExecutable({
root: context.dataRoot,
configured: configuredNode,
fallback: process.execPath,
subject: "Node.js",
}),
...await diagnoseRuntimeExecutable({
root: context.dataRoot,
configured: configuredFfprobe,
fallback: "ffprobe",
subject: "FFprobe",
}),
],
};
},
});
export const hypitPackage = {
format: "hypit.package@1" as const,
facets: [localHTMLRuntimeAdapter],
};
export default hypitPackage;