Skip to content

Open source CapCut alternative.

TypeScript

feat(site): pick the video model from a capability-driven dropdown

David Lec035fff4273f
diff --git a/site/src/cut/components/GeneratePanel.tsx b/site/src/cut/components/GeneratePanel.tsx
index 42758267..a4747737 100644
--- a/site/src/cut/components/GeneratePanel.tsx
+++ b/site/src/cut/components/GeneratePanel.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useRef } from "react";
+import { useEffect, useRef } from "react";
import { Copy, Film, Loader2, Maximize2, Plus, Sparkles, Trash2, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
@@ -14,13 +14,22 @@ import {
} from "@/cut/lib/assetRef";
import { signInUrl, useGenerate, useSignedIn, type GenerateJob } from "@/cut/lib/generate";
import { useLightbox } from "@/cut/lib/lightbox";
+import { refsFromDroppedFiles } from "@/cut/lib/refMedia";
import { characterPrompt, stockTitle } from "@/cut/lib/stock";
import { useEditor } from "@/cut/lib/store";
import { useLocalPref } from "@/cut/lib/uiState";
-import { useVideoGen } from "@/cut/lib/videoGen";
+import {
+ useVideoGen,
+ VIDEO_ASPECT_LABEL,
+ VIDEO_MODELS,
+ type VideoAspect,
+ type VideoModelOption,
+} from "@/cut/lib/videoGen";
import { cn } from "@/lib/utils";
import { MentionTextarea, RefChips, RefHandlePill } from "./AssetRefs";
import { GeneratedAssetMenu } from "./GeneratedAssetMenu";
+import { cardIconButton } from "./iconButton";
+import { PillSelect } from "./PillSelect";
// The generate-video panel: an always-on column in the Video tab, sitting left
// of the stock-clip browser. Clicking a stock tile loads its saved prompt here.
@@ -29,6 +38,11 @@ import { GeneratedAssetMenu } from "./GeneratedAssetMenu";
// takes one input image, so the first reference's picture becomes the start
// frame.
+const ASPECT_WORD: Record<VideoAspect, string> = {
+ "16:9": "Landscape",
+ "9:16": "Portrait",
+};
+
// Segmented pill group, same language as the platform switcher in PlatformPreview.
const segGroup = "flex gap-0.5 rounded-full border border-border bg-card p-0.5 shadow-xs";
const segButton = (active: boolean) =>
@@ -41,22 +55,47 @@ export function GenerateVideoPanel({ projectId }: { projectId: string }) {
const signedIn = useSignedIn();
const allJobs = useGenerate((s) => s.jobs);
const jobs = allJobs.filter((j) => j.projectId === projectId && j.kind === "video");
- const { prompt, refs, character } = useVideoGen();
+ const { prompt, refs, character, aspect, resolution } = useVideoGen();
const candidates = useRefCandidates();
- const { active: dropActive, attachTarget, targetProps } = useAssetDrop((ref) => {
- if (ref.kind !== "audio") useVideoGen.getState().addRef(ref);
- });
- const [tier, setTier] = useLocalPref<"fast" | "high">(
+ const { active: dropActive, attachTarget, targetProps } = useAssetDrop(
+ (ref) => {
+ if (ref.kind !== "audio") useVideoGen.getState().addRef(ref);
+ },
+ // OS files dropped on the panel attach as references (media files import
+ // into the project on the way; text files ride as-is).
+ (files) =>
+ void refsFromDroppedFiles(projectId, files).then((refs) => {
+ for (const r of refs) if (r.kind !== "audio") useVideoGen.getState().addRef(r);
+ })
+ );
+ const [tier, setTier] = useLocalPref<VideoModelOption["tier"]>(
"cut-gen-tier",
"fast",
- (v) => v === "fast" || v === "high"
+ (v) => VIDEO_MODELS.some((m) => m.tier === v)
);
const [seconds, setSeconds] = useLocalPref<number>(
"cut-gen-seconds",
8,
- (v) => v === 4 || v === 6 || v === 8
+ (v) => typeof v === "number" && VIDEO_MODELS.some((m) => m.durations.includes(v))
);
+ // Every knob renders from — and is clamped to — what the selected model
+ // supports, so a stored pick from another model can never reach the API.
+ const model = VIDEO_MODELS.find((m) => m.tier === tier) ?? VIDEO_MODELS[0];
+ const effSeconds = model.durations.includes(seconds)
+ ? seconds
+ : model.durations[model.durations.length - 1];
+ const effAspect = model.aspects.includes(aspect) ? aspect : model.aspects[0];
+ const effResolution = model.resolutions.includes(resolution)
+ ? resolution
+ : model.resolutions[0];
+
+ // Default the shape to the project's own orientation when the panel opens,
+ // same as the image panel (the user can still pick the other one).
+ useEffect(() => {
+ useVideoGen.getState().setAspect(useEditor.getState().aspect);
+ }, []);
+
const go = () => {
const { text, refs: all } = collectRefs(prompt.trim(), refs, candidates, { dropAudio: true });
if (!text) return;
@@ -65,9 +104,16 @@ export function GenerateVideoPanel({ projectId }: { projectId: string }) {
// same person delivers it.
const composed = character?.persona ? characterPrompt(character.persona, text) : text;
const seedRefs = character ? [refFromStockVideo(character)] : all;
- void useGenerate
- .getState()
- .generateVideo(projectId, composed, { tier, durationSeconds: seconds, refs: seedRefs });
+ void useGenerate.getState().generateVideo(projectId, composed, {
+ tier,
+ durationSeconds: effSeconds,
+ aspect: effAspect,
+ resolution: effResolution,
+ refs: seedRefs,
+ // The character's poster seed is the point — the same person must
+ // deliver the line — so free-form prompts alone get the ref rewrite.
+ composeRefs: !character,
+ });
useVideoGen.getState().openWith("");
};
@@ -133,33 +179,55 @@ export function GenerateVideoPanel({ projectId }: { projectId: string }) {
/>
</div>
+ {/* Which model renders the clip — a dropdown, since the catalog grows. */}
+ <PillSelect
+ className="shrink-0"
+ title="Model"
+ value={tier}
+ display={model.model}
+ options={VIDEO_MODELS.map((m) => ({
+ value: m.tier,
+ label: `${m.word} · ${m.model}`,
+ }))}
+ onChange={setTier}
+ />
+
+ {/* The remaining knobs follow the selected model's capabilities. */}
<div className="flex shrink-0 items-center justify-between gap-2">
<div className={segGroup}>
- {[4, 6, 8].map((s) => (
+ {model.durations.map((s) => (
<button
key={s}
- className={segButton(seconds === s)}
- aria-pressed={seconds === s}
+ className={segButton(effSeconds === s)}
+ aria-pressed={effSeconds === s}
onClick={() => setSeconds(s)}
>
{s}s
</button>
))}
</div>
- <div className={segGroup}>
- {(["fast", "high"] as const).map((t) => (
- <button
- key={t}
- className={segButton(tier === t)}
- aria-pressed={tier === t}
- onClick={() => setTier(t)}
- >
- {t === "fast" ? "Fast" : "Best"}
- </button>
- ))}
- </div>
+ <PillSelect
+ title="Resolution"
+ value={effResolution}
+ display={effResolution}
+ options={model.resolutions.map((r) => ({ value: r, label: r }))}
+ onChange={(v) => useVideoGen.getState().setResolution(v)}
+ />
</div>
+ {/* Shape, the same pill family as the image panel. */}
+ <PillSelect
+ className="shrink-0"
+ title="Aspect ratio"
+ value={effAspect}
+ display={ASPECT_WORD[effAspect]}
+ options={model.aspects.map((a) => ({
+ value: a,
+ label: VIDEO_ASPECT_LABEL[a],
+ }))}
+ onChange={(v) => useVideoGen.getState().setAspect(v)}
+ />
+
<Button
className="gen-go w-full shrink-0"
disabled={!prompt.trim() || signedIn === false}
@@ -234,7 +302,7 @@ function JobRow({ job, handle }: { job: GenerateJob; handle?: string }) {
{job.status !== "running" && (
<button
title="Dismiss"
- className="grid size-6 shrink-0 place-items-center rounded-full text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 hover:text-foreground"
+ className={cn(cardIconButton, "opacity-0 group-hover:opacity-100")}
onClick={() => useGenerate.getState().dismiss(job.id)}
>
<Trash2 className="size-3.5" />
diff --git a/site/src/cut/components/ImageGenPanel.tsx b/site/src/cut/components/ImageGenPanel.tsx
index 2922a16e..724598a9 100644
--- a/site/src/cut/components/ImageGenPanel.tsx
+++ b/site/src/cut/components/ImageGenPanel.tsx
@@ -1,7 +1,7 @@
"use client";
import { useEffect, useMemo, useRef } from "react";
-import { ChevronDown, Copy, Loader2, Maximize2, Sparkles, Trash2 } from "lucide-react";
+import { Copy, Loader2, Maximize2, Sparkles, Trash2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { SectionTitle } from "@/cut/components/SectionTitle";
@@ -15,10 +15,12 @@ import {
type ImageResolution,
} from "@/cut/lib/imageGen";
import { useLightbox } from "@/cut/lib/lightbox";
+import { refsFromDroppedFiles } from "@/cut/lib/refMedia";
import { useEditor } from "@/cut/lib/store";
import type { MediaAsset } from "@/cut/lib/types";
import { cn } from "@/lib/utils";
import { MentionTextarea, RefChips, RefHandlePill } from "./AssetRefs";
+import { PillSelect } from "./PillSelect";
import { GeneratedAssetMenu } from "./GeneratedAssetMenu";
// The generate-image panel: an always-on column in the Image tab, sitting left
@@ -63,9 +65,17 @@ export function ImageGenPanel({ projectId }: { projectId: string }) {
() => assets.filter((a) => a.origin === "generated" && a.type === "image").reverse(),
[assets]
);
- const { active: dropActive, attachTarget, targetProps } = useAssetDrop((ref) => {
- if (ref.kind !== "audio") useImageGen.getState().addRef(ref);
- });
+ const { active: dropActive, attachTarget, targetProps } = useAssetDrop(
+ (ref) => {
+ if (ref.kind !== "audio") useImageGen.getState().addRef(ref);
+ },
+ // OS files dropped on the panel attach as references (media files import
+ // into the project on the way; text files ride as-is).
+ (files) =>
+ void refsFromDroppedFiles(projectId, files).then((refs) => {
+ for (const r of refs) if (r.kind !== "audio") useImageGen.getState().addRef(r);
+ })
+ );
// Default the size to the project's own orientation when the panel opens, so
// a widescreen project generates landscape images by default (the user can
@@ -202,50 +212,6 @@ export function ImageGenPanel({ projectId }: { projectId: string }) {
);
}
-/** A rounded pill wrapping a native select — a compact `display` shows when closed,
- * while the dropdown lists the fuller option labels (an invisible select overlays the
- * pill, so it keeps native keyboard/OS behavior). Mirrors the audio language picker's
- * chrome so the generate controls read as one family. */
-function PillSelect<T extends string>({
- className,
- title,
- value,
- display,
- options,
- onChange,
-}: {
- className?: string;
- title: string;
- value: T;
- display: string;
- options: { value: T; label: string }[];
- onChange: (value: T) => void;
-}) {
- return (
- <label
- className={cn(
- "relative flex items-center rounded-full border border-input py-1.5 pr-2.5 pl-3.5 transition-colors focus-within:border-ring",
- className
- )}
- title={title}
- >
- <span className="min-w-0 flex-1 truncate text-[12.5px] text-foreground">{display}</span>
- <ChevronDown className="ml-1 size-3.5 shrink-0 text-muted-foreground" />
- <select
- className="absolute inset-0 w-full cursor-pointer appearance-none opacity-0"
- value={value}
- onChange={(e) => onChange(e.target.value as T)}
- >
- {options.map((o) => (
- <option key={o.value} value={o.value}>
- {o.label}
- </option>
- ))}
- </select>
- </label>
- );
-}
-
/** A generated image, shown big: reference it in a prompt by its @handle, drag
* it onto the timeline or into chat, click to reload its prompt, and reach
* everything else — expand, copy its @reference, send it to Media or the
diff --git a/site/src/cut/components/PillSelect.tsx b/site/src/cut/components/PillSelect.tsx
new file mode 100644
index 00000000..74c69da0
--- /dev/null
+++ b/site/src/cut/components/PillSelect.tsx
@@ -0,0 +1,48 @@
+"use client";
+
+import { ChevronDown } from "lucide-react";
+import { cn } from "@/lib/utils";
+
+/** A rounded pill wrapping a native select — a compact `display` shows when closed,
+ * while the dropdown lists the fuller option labels (an invisible select overlays the
+ * pill, so it keeps native keyboard/OS behavior). Mirrors the audio language picker's
+ * chrome so the generate controls read as one family. */
+export function PillSelect<T extends string>({
+ className,
+ title,
+ value,
+ display,
+ options,
+ onChange,
+}: {
+ className?: string;
+ title: string;
+ value: T;
+ display: string;
+ options: { value: T; label: string }[];
+ onChange: (value: T) => void;
+}) {
+ return (
+ <label
+ className={cn(
+ "relative flex items-center rounded-full border border-input py-1.5 pr-2.5 pl-3.5 transition-colors focus-within:border-ring",
+ className
+ )}
+ title={title}
+ >
+ <span className="min-w-0 flex-1 truncate text-[12.5px] text-foreground">{display}</span>
+ <ChevronDown className="ml-1 size-3.5 shrink-0 text-muted-foreground" />
+ <select
+ className="absolute inset-0 w-full cursor-pointer appearance-none opacity-0"
+ value={value}
+ onChange={(e) => onChange(e.target.value as T)}
+ >
+ {options.map((o) => (
+ <option key={o.value} value={o.value}>
+ {o.label}
+ </option>
+ ))}
+ </select>
+ </label>
+ );
+}
diff --git a/site/src/cut/lib/videoGen.ts b/site/src/cut/lib/videoGen.ts
index a2a2a306..fd4ae42e 100644
--- a/site/src/cut/lib/videoGen.ts
+++ b/site/src/cut/lib/videoGen.ts
@@ -8,8 +8,58 @@ import type { StockVideo } from "./stock";
// (which loads a stock clip's saved prompt into it on click) and the always-on
// generate panel that sits beside the browser in the Video tab.
+/** The shape the next generated clip is composed in — Veo renders landscape
+ * and portrait. */
+export type VideoAspect = "16:9" | "9:16";
+
+export const VIDEO_ASPECT_LABEL: Record<VideoAspect, string> = {
+ "16:9": "Landscape (16:9)",
+ "9:16": "Portrait (9:16)",
+};
+
+/** Output detail the next clip renders at. */
+export type VideoResolution = "720p" | "1080p";
+
+/** A selectable video model: the tier the backend resolves to a concrete
+ * model id (gemini-models.ts) plus the knobs that model supports. The
+ * generate panel renders its duration/aspect/resolution controls from the
+ * selected entry and clamps stored picks to it, so adding a model here is the
+ * whole client-side change. */
+export interface VideoModelOption {
+ tier: "fast" | "high";
+ /** Segment label ("Fast") and the model name shown beside it. */
+ word: string;
+ model: string;
+ durations: number[];
+ aspects: VideoAspect[];
+ resolutions: VideoResolution[];
+}
+
+export const VIDEO_MODELS: VideoModelOption[] = [
+ {
+ tier: "fast",
+ word: "Fast",
+ model: "Veo 3.1 Fast",
+ durations: [4, 6, 8],
+ aspects: ["16:9", "9:16"],
+ resolutions: ["720p", "1080p"],
+ },
+ {
+ tier: "high",
+ word: "Best",
+ model: "Veo 3.1",
+ durations: [4, 6, 8],
+ aspects: ["16:9", "9:16"],
+ resolutions: ["720p", "1080p"],
+ },
+];
+
interface VideoGenState {
prompt: string;
+ /** The shape the next generation is composed in. */
+ aspect: VideoAspect;
+ /** The output detail the next generation renders at. */
+ resolution: VideoResolution;
/** Visual references attached to the next generation (dragged in or picked
* via @name mentions resolved on send). */
refs: AssetRef[];
@@ -24,18 +74,24 @@ interface VideoGenState {
openCharacter: (character: StockVideo) => void;
clearCharacter: () => void;
setPrompt: (prompt: string) => void;
+ setAspect: (aspect: VideoAspect) => void;
+ setResolution: (resolution: VideoResolution) => void;
addRef: (ref: AssetRef) => void;
removeRef: (ref: AssetRef) => void;
}
export const useVideoGen = create<VideoGenState>((set) => ({
prompt: "",
+ aspect: "16:9",
+ resolution: "720p",
refs: [],
character: null,
openWith: (prompt) => set({ prompt, refs: [], character: null }),
openCharacter: (character) => set({ character, prompt: "", refs: [] }),
clearCharacter: () => set({ character: null }),
setPrompt: (prompt) => set({ prompt }),
+ setAspect: (aspect) => set({ aspect }),
+ setResolution: (resolution) => set({ resolution }),
addRef: (ref) => set((s) => ({ refs: addRefOnce(s.refs, ref) })),
removeRef: (ref) => set((s) => ({ refs: s.refs.filter((r) => !sameRef(r, ref)) })),
}));