Open source CapCut alternative.
TypeScript
refactor(site): veo reference-image cap reads from the model registries
David Lead12e8bbb46e
diff --git a/site/src/cut/lib/generate.ts b/site/src/cut/lib/generate.tsindex 3560075b..6128ede2 100644--- a/site/src/cut/lib/generate.ts+++ b/site/src/cut/lib/generate.ts@@ -13,6 +13,7 @@ import { useGenNotify } from "./genNotify";import { useImageGen } from "./imageGen";import { useEditor } from "./store";import { mediaUrl, type MediaAsset } from "./types";+import { videoModel } from "./videoGen";// AI generation jobs, held outside the panels so a tab switch (which unmounts// them) doesn't orphan a running generation — Veo renders take minutes.@@ -413,8 +414,11 @@ export const useGenerate = create<GenerateState>((set, get) => {// Identity anchors travel separately: with referenceImages set, the// prompt stands as written and no seed image rides (Veo takes one// or the other).+ const tier = opts?.tier === "high" ? "high" : "fast";const anchors = opts?.referenceImages?.length- ? await refsToInlineImages(visualRefs(opts.referenceImages).slice(0, 3))+ ? await refsToInlineImages(+ visualRefs(opts.referenceImages).slice(0, videoModel(tier).maxReferenceImages)+ ): [];const { prompt: sent, images } = anchors.length? { prompt, images: [] }@@ -428,7 +432,7 @@ export const useGenerate = create<GenerateState>((set, get) => {? { inputs: { images } }: {}),parameters: {- tier: opts?.tier === "high" ? "high" : "fast",+ tier,aspectRatio: opts?.aspect ?? useEditor.getState().aspect,...(opts?.resolution ? { resolution: opts.resolution } : {}),...(opts?.durationSeconds ? { durationSeconds: opts.durationSeconds } : {}),diff --git a/site/src/cut/lib/genvideo/adapters/media.ts b/site/src/cut/lib/genvideo/adapters/media.tsindex 1193e8be..5a3497f8 100644--- a/site/src/cut/lib/genvideo/adapters/media.ts+++ b/site/src/cut/lib/genvideo/adapters/media.ts@@ -32,7 +32,7 @@ import { NO_CREDITS_MESSAGE, useGenerate, type VideoGenOptions } from "../../genimport { enrichAsset } from "../../media";import { useEditor } from "../../store";import { DEFAULT_VOICE, synthesizeSpeech } from "../../tts";-import { supportedVideoDuration } from "../../videoGen";+import { supportedVideoDuration, videoModel } from "../../videoGen";import type { ImageRole, VideoRole, VoiceRole } from "../capabilities";import type { RefAsset } from "../types";@@ -71,8 +71,6 @@ export function makeImageRole(projectId: string, chatId?: string): ImageRole {}const VIDEO_TIER = "fast" as const;-/** Veo takes at most three asset reference images per render. */-const MAX_VIDEO_ANCHORS = 3;export function makeVideoRole(projectId: string, chatId?: string): VideoRole {return {@@ -101,7 +99,7 @@ export function makeVideoRole(projectId: string, chatId?: string): VideoRole {// not a cast member, and must never ride as an asset to keep consistent.const anchors = refsToAssetRefs(input.refs.filter((r) => r.purpose === "character" || r.purpose === "location")- ).slice(0, MAX_VIDEO_ANCHORS);+ ).slice(0, videoModel(VIDEO_TIER).maxReferenceImages);const attempts: VideoGenOptions[] = [// 1. The keyframe as the literal first frame. It was rendered from the// cast's reference images, so it carries identity, wardrobe, setting,diff --git a/site/src/cut/lib/videoGen.ts b/site/src/cut/lib/videoGen.tsindex 44f16f3f..7f48de17 100644--- a/site/src/cut/lib/videoGen.ts+++ b/site/src/cut/lib/videoGen.ts@@ -34,6 +34,8 @@ export interface VideoModelOption {/** Clip lengths the model renders when identity reference images ride* along — Veo 3.1 reference-to-video renders 8s only. */referenceDurations: number[];+ /** Identity reference images a render accepts alongside the prompt. */+ maxReferenceImages: number;aspects: VideoAspect[];resolutions: VideoResolution[];}@@ -45,6 +47,7 @@ export const VIDEO_MODELS: VideoModelOption[] = [model: "Veo 3.1 Fast",durations: [4, 6, 8],referenceDurations: [8],+ maxReferenceImages: 3,aspects: ["16:9", "9:16"],resolutions: ["720p", "1080p"],},@@ -54,6 +57,7 @@ export const VIDEO_MODELS: VideoModelOption[] = [model: "Veo 3.1",durations: [4, 6, 8],referenceDurations: [8],+ maxReferenceImages: 3,aspects: ["16:9", "9:16"],resolutions: ["720p", "1080p"],},diff --git a/site/src/lib/inference/adapters/gemini-video.ts b/site/src/lib/inference/adapters/gemini-video.tsindex 6ee1637d..956ca2b1 100644--- a/site/src/lib/inference/adapters/gemini-video.ts+++ b/site/src/lib/inference/adapters/gemini-video.ts@@ -16,7 +16,7 @@ import {type AdapterEnvironment,} from "@/lib/inference/adapters/gemini-client";import { providerCreditPricing } from "@/lib/credits/provider-pricing";-import { veoModels, veoTierModels } from "@/lib/inference/gemini-models";+import { veoMaxReferenceImages, veoModels, veoTierModels } from "@/lib/inference/gemini-models";import { ensureConfigured } from "@/lib/inference/http";import { isJsonObject, toJsonObject, toJsonValue } from "@/lib/inference/json";import {@@ -266,11 +266,10 @@ function inputImage(inputs: JsonObject | undefined): InlineImage | undefined {return undefined;}-// Veo 3.1 asset references ("ingredients"): up to three identity anchors — characters, objects,-// scenes — the render keeps consistent, sent as inputs.referenceImages = [{ data, mimeType }].-// Distinct from inputs.images: a reference conditions the whole clip, a seed becomes frame one.-const MAX_REFERENCE_IMAGES = 3;-+// Veo 3.1 asset references ("ingredients"): identity anchors — characters, objects, scenes —+// the render keeps consistent, sent as inputs.referenceImages = [{ data, mimeType }], capped at+// the registry's veoMaxReferenceImages. Distinct from inputs.images: a reference conditions the+// whole clip, a seed becomes frame one.function referenceImages(inputs: JsonObject | undefined): InlineImage[] {const list = inputs?.referenceImages;if (!Array.isArray(list)) {@@ -286,7 +285,7 @@ function referenceImages(inputs: JsonObject | undefined): InlineImage[] {continue;}out.push({ data, mimeType: stringValue(item.mimeType) ?? "image/png" });- if (out.length === MAX_REFERENCE_IMAGES) {+ if (out.length === veoMaxReferenceImages) {break;}}diff --git a/site/src/lib/inference/gemini-models.ts b/site/src/lib/inference/gemini-models.tsindex cb33abc4..2c30c7c7 100644--- a/site/src/lib/inference/gemini-models.ts+++ b/site/src/lib/inference/gemini-models.ts@@ -36,6 +36,10 @@ export const veoModels = {export type VeoModel = (typeof veoModels)[keyof typeof veoModels];+// Veo 3.1 asset references ("ingredients"): a render keeps at most this many+// identity anchors consistent. Bump here when a newer Veo raises it.+export const veoMaxReferenceImages = 3;+// Generative speech (Gemini TTS): text in, spoken audio out, with prompt-driven// style direction and inline audio tags. Bump here when adopting a newer TTS model.export const geminiTtsModels = {