The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Studios: Shorts prices and starts from a header already read, Faceless takes a written script, Ads takes fixed copy
Claude34c412ef8245
diff --git a/src/server/ads.ts b/src/server/ads.tsindex 59852154..0c833bc9 100644--- a/src/server/ads.ts+++ b/src/server/ads.ts@@ -259,13 +259,16 @@ export interface BatchEstimate {copyBy: "llm" | "rules";}-/** "Create N ads" with its price, before anything runs (the stepper shows it first). */-export function estimateBatch(input: BatchInput): BatchEstimate {- const brand = getBrand(input.brandId);+/**+ * "Create N ads" with its price, before anything runs (the stepper shows it first). `draft` prices a+ * brand and product that don't exist yet (Assist, before its brand kit and product are saved).+ */+export function estimateBatch(input: BatchInput, draft?: { brand: BrandKit; product: Product | null }): BatchEstimate {+ const brand = draft?.brand ?? getBrand(input.brandId);if (!brand) throw new AdsError("That brand no longer exists");const route = batchRoute(input);const total = input.items.reduce((n, i) => n + i.count, 0);- const product = getProduct(input.items[0].productId);+ const product = draft ? draft.product : getProduct(input.items[0].productId);const req = route === "higgsfield" ? higgsfieldRequest(product, brand, input.ratio ?? "4:5") : visualRequest({ visual: "the product", headline: "Ad" }, product, brand, input.engine);const p = previewGeneration(req);let copy = 0;@@ -290,8 +293,14 @@ export function estimateBatch(input: BatchInput): BatchEstimate {};}+/** Words every ad of a batch uses as given (Assist: "Headline exactly …"), instead of the copywriter's. */+export interface FixedCopy {+ headline?: string;+ cta?: string;+}+/** Start a batch: creatives appear at once ("writing"), copy and visuals follow in the background. */-export function createBatch(input: BatchInput): { batchId: string; creatives: AdCreative[]; run: Promise<void> } {+export function createBatch(input: BatchInput, fixed: FixedCopy = {}): { batchId: string; creatives: AdCreative[]; run: Promise<void> } {const mode = engineMode();if (mode !== "both" && mode !== input.engine) throw new AdsError(mode === "open" ? "This install is set to open source only (Settings → Engine mode)" : "This install is set to paid cloud APIs only (Settings → Engine mode)");const brand = getBrand(input.brandId);@@ -323,11 +332,11 @@ export function createBatch(input: BatchInput): { batchId: string; creatives: Ad}})();running().add(batchId);- const run = fillBatch(batchId, brand, ids, input, route).finally(() => running().delete(batchId));+ const run = fillBatch(batchId, brand, ids, input, route, fixed).finally(() => running().delete(batchId));return { batchId, creatives: listCreatives({ brandId: brand.id, batchId }), run };}-async function fillBatch(batchId: string, brand: BrandKit, ids: { id: string; product: Product; index: number }[], input: BatchInput, route: "fuobe" | "higgsfield"): Promise<void> {+async function fillBatch(batchId: string, brand: BrandKit, ids: { id: string; product: Product; index: number }[], input: BatchInput, route: "fuobe" | "higgsfield", fixed: FixedCopy = {}): Promise<void> {const setGen = (id: string, g: Generation) => db().prepare("UPDATE ad_creatives SET generation_id = ?, status = 'queued', updated_at = ? WHERE id = ?").run(g.id, Date.now(), id);const fail = (id: string, error: string) => db().prepare("UPDATE ad_creatives SET status = 'failed', error = ?, updated_at = ? WHERE id = ?").run(error, Date.now(), id);if (route === "higgsfield") {@@ -351,8 +360,10 @@ async function fillBatch(batchId: string, brand: BrandKit, ids: { id: string; pr} catch {concepts = heuristicConcepts(brand, product, list.length, input.direction);}+ const headline = fixed.headline?.trim().slice(0, 90);+ const cta = fixed.cta?.trim().slice(0, 30);list.forEach((c, i) => {- const k = concepts[i];+ const k = { ...concepts[i], ...(headline && { headline }), ...(cta && { cta }) };// A creative deleted meanwhile gets no visual.const ok = db().prepare("UPDATE ad_creatives SET angle = ?, headline = ?, body = ?, cta = ?, visual = ?, status = 'queued', updated_at = ? WHERE id = ? AND status = 'writing'")diff --git a/src/server/faceless.ts b/src/server/faceless.tsindex 39559e17..85e01864 100644--- a/src/server/faceless.ts+++ b/src/server/faceless.ts@@ -315,7 +315,7 @@ const NAME_SYSTEM = "You name YouTube channels. Reply with the name only: 2–4* A new channel is there straight away with a name taken from the idea; the LLM's name replaces it when* it answers (within 15 s, and only while the channel still has the first name), then the avatar is drawn.*/-export async function createChannel(input: { idea: string; genre: FacelessGenre; engine: Engine; reference?: string; name?: string }): Promise<FacelessChannel> {+export async function createChannel(input: { idea: string; genre: FacelessGenre; engine: Engine; reference?: string; name?: string; avatar?: boolean }): Promise<FacelessChannel> {const idea = input.idea.trim();if (!idea) throw new FacelessError("Describe the channel first");const reference = input.reference?.trim() ? await readReference(input.reference) : null;@@ -343,7 +343,8 @@ export async function createChannel(input: { idea: string; genre: FacelessGenre;if (name) db().prepare("UPDATE faceless_channels SET name = ? WHERE id = ? AND name = ?").run(name, row.id, row.name);}try {- if (channelRow(row.id)) makeAvatar(row.id);+ // avatar: false (Assist's channel) leaves the initials and the "Draw an avatar" button.+ if (input.avatar !== false && channelRow(row.id)) makeAvatar(row.id);} catch {// No picture model can run right now: the channel shows its initials, and "Draw an avatar" is there.}@@ -444,6 +445,8 @@ export interface EpisodeInput {autoRender?: boolean;/** Save this episode's look and sound as the channel's (default: only for a channel's first episode). */saveLook?: boolean;+ /** A script that's written already, with its pictures (Assist): no writer runs; it's ready to review, or renders at once with autoRender. */+ blocks?: Partial<ScriptBlock>[];}function cleanSettings(s: EpisodeSettings): EpisodeSettings {@@ -462,25 +465,27 @@ function cleanSettings(s: EpisodeSettings): EpisodeSettings {export function createEpisode(input: EpisodeInput): FacelessEpisode {const topic = input.topic.trim();const pasted = input.script?.trim() ?? "";- if (!topic && !pasted && !input.sources?.length) throw new FacelessError(input.kind === "explainer" ? "Add a prompt, or attach a file or link" : "Add a topic, or bring your own script");- if (pasted.length > MAX_SCRIPT) throw new FacelessError("That script is too long to narrate. Shorten it and try again.");+ const written = input.blocks ? normalizeBlocks(input.blocks) : null;+ if (!topic && !pasted && !input.sources?.length && !written?.length) throw new FacelessError(input.kind === "explainer" ? "Add a prompt, or attach a file or link" : "Add a topic, or bring your own script");+ if (pasted.length > MAX_SCRIPT || (written && narrationText(written).length > MAX_SCRIPT)) throw new FacelessError("That script is too long to narrate. Shorten it and try again.");+ if (written && !written.length) throw new FacelessError("The script has no scenes yet");const channel = input.channelId ? getChannel(input.channelId) : null;if (input.channelId && !channel) throw new FacelessError("Channel not found", 404);const settings = cleanSettings(input.settings);const sources = (input.sources ?? []).slice(0, MAX_SOURCES);settings.sourceImages = sources.filter((s): s is Extract<ExplainerSource, { kind: "image" }> => s.kind === "image").map((s) => s.url);const now = Date.now();- const title = (topic || pasted).replace(/\s+/g, " ").slice(0, 80) || "Untitled episode";+ const title = (topic || pasted || written?.[0]?.narration || "").replace(/\s+/g, " ").slice(0, 80) || "Untitled episode";const row: EpisodeRow = {id: nanoid(10),channel_id: channel?.id ?? null,kind: input.kind,title,topic: topic.slice(0, 5000),- status: "writing",+ status: written ? "review" : "writing",error: null,settings_json: JSON.stringify(settings),- script_json: JSON.stringify({ blocks: [], source: pasted ? "pasted" : "ai" } satisfies EpisodeScript),+ script_json: JSON.stringify((written ? { blocks: written, source: "ai" } : { blocks: [], source: pasted ? "pasted" : "ai" }) satisfies EpisodeScript),plan_json: null,sources_json: JSON.stringify(sources),favorite: 0,@@ -496,6 +501,16 @@ export function createEpisode(input: EpisodeInput): FacelessEpisode {settings: { engine: settings.engine, styleId: settings.styleId, styleRefs: settings.styleRefs, voice: settings.voice, aspect: settings.aspect, subtitles: settings.subtitles, music: settings.music, animation: settings.animation, length: settings.length },});}+ if (written) {+ if (!input.autoRender) return toEpisode(row);+ try {+ return renderEpisode(row.id);+ } catch (e) {+ // The script is there: show it with what's in the way, as a written script that can't render does.+ updateEpisodeRow(row.id, { status: "review", error: (e as Error).message });+ return mustEpisode(row.id);+ }+ }startWriting(row.id, pasted, !!input.autoRender);return toEpisode(row);}diff --git a/src/server/shorts.ts b/src/server/shorts.tsindex 8a5b586a..dc10d075 100644--- a/src/server/shorts.ts+++ b/src/server/shorts.ts@@ -76,13 +76,18 @@ export interface SourceInfo {*/export async function probeSource(url: string): Promise<SourceInfo> {if (!url.startsWith("/api/files/")) throw new ShortsError("Upload the clip first");- let info: MediaInfo | null = null;let data: Buffer;try {data = (await readRef(url)).data;} catch {throw new ShortsError("That clip is gone — upload it again", 404);}+ return sourceInfo(data);+}++/** What a clip's bytes say (the header readers behind probeSource). */+export function sourceInfo(data: Buffer): SourceInfo {+ let info: MediaInfo | null = null;try {info = probeMedia(data);} catch {@@ -219,6 +224,8 @@ export interface ShortsBody {aspectRatio: ShortsRatio;language: string;modelId?: string;+ /** A look of its own instead of a preset (Assist's words), kept on the session like a preset's. Server-side only. */+ look?: ShortsLook;}function lookFor(presetId: string): ShortsLook {@@ -245,10 +252,14 @@ const fileTitle = (name?: string) =>/** The plan input for a request: model, look, clip facts (from its header when it has one). */async function planInput(body: ShortsBody, opts: { probe: boolean }): Promise<{ input: ShortsPlanInput; info: SourceInfo }> {+ return planWith(body, opts.probe ? await probeSource(body.source.url) : {});+}++/** planInput with the clip's header already read (`{}`: the browser's numbers only). */+function planWith(body: ShortsBody, info: SourceInfo): { input: ShortsPlanInput; info: SourceInfo } {checkEngine(body.engine);const modelId = body.modelId && SHORTS_MODELS[body.engine].includes(body.modelId) ? body.modelId : SHORTS_MODELS[body.engine][0];- const look = lookFor(body.presetId);- const info = opts.probe ? await probeSource(body.source.url) : {};+ const look = body.look ?? lookFor(body.presetId);const duration = info.duration ?? body.source.duration;const problem = rangeProblem(body.range, duration) ?? clipShapeProblem(info.width ?? body.source.width, info.height ?? body.source.height);if (problem) throw new ShortsError(problem);@@ -329,7 +340,12 @@ function notesFor(input: ShortsPlanInput): string[] {/** What a session would cost and how it would run, without creating anything. */export async function estimateShorts(body: ShortsBody): Promise<ShortsEstimate> {- const { input } = await planInput(body, { probe: false });+ return estimateWith(body, {});+}++/** estimateShorts for a clip whose header was read already (Assist prices with its sound and length). */+export function estimateWith(body: ShortsBody, info: SourceInfo): ShortsEstimate {+ const { input } = planWith(body, info);const plan = planShorts(input);const all = priceSteps(plan.steps);const one = priceSteps(planTake(input, plan.segments[0], plan.segments.length).steps);@@ -346,8 +362,9 @@ export async function estimateShorts(body: ShortsBody): Promise<ShortsEstimate>// ---------------------------------------------------------------------------// Sessions-export async function createSession(body: ShortsBody): Promise<ShortsSession> {- const { input, info } = await planInput(body, { probe: true });+/** Start a session; `known` is the clip's header when the caller read it already (else it's read here). */+export async function createSession(body: ShortsBody, known?: SourceInfo): Promise<ShortsSession> {+ const { input, info } = known ? planWith(body, known) : await planInput(body, { probe: true });const plan = planShorts(input);const pipeline = (() => {try {